/*
    *
    * Wijmo Library 5.20183.550
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
"use strict";function WjValueAccessorFactory(e){return new WjValueAccessor(e)}Object.defineProperty(exports,"__esModule",{value:!0});const wjcCore=require("wijmo/wijmo");var __glob="undefined"!=typeof window?window:self;const core_1=require("@angular/core");class WjOptions{}WjOptions.asyncBindings=!0,exports.WjOptions=WjOptions;class WjComponentResolvedMetadata{constructor(e){this.changeEventMap=[],this.allImplEvents=[],this.resolveChangeEventMap(e)}resolveChangeEventMap(e){let t=this.changeEventMap,i=e.outputs,r=e.changeEvents||{};if(t.splice(0,t.length),this.allImplEvents=[],!i||!i.length)return;let n=i.map(e=>e.split(":")).map(e=>({implName:e[0].trim(),exposeName:e[1]&&e[1].trim()}));this.allImplEvents=n.map(e=>e.implName);let s=n.filter(e=>e.implName&&e.exposeName);for(let e of s)if(Ng2Utils.getWjEventName(e.implName)){let i={eventImpl:e.implName,event:e.exposeName},n=r[e.exposeName];n&&n.length&&(i.props=n.map(e=>({prop:e,evExposed:Ng2Utils.getChangeEventNameExposed(e),evImpl:Ng2Utils.getChangeEventNameImplemented(e)}))),t.push(i)}for(let e in r)if(e.indexOf(".")>-1){let i={eventImpl:null,event:e,props:r[e].map(e=>({prop:e,evExposed:Ng2Utils.getChangeEventNameExposed(e),evImpl:Ng2Utils.getChangeEventNameImplemented(e)}))};t.push(i)}}}exports.WjComponentResolvedMetadata=WjComponentResolvedMetadata;class WjDirectiveBehavior{constructor(e,t,i,r){this._pendingEvents=[],this.isInitialized=!1,this.isDestroyed=!1,this.directive=e,this.elementRef=t,this.injector=i,this.injectedParent=r;let n=this.typeData=e.constructor[WjDirectiveBehavior.directiveTypeDataProp];null==n.siblingId&&(n.siblingId=++WjDirectiveBehavior.siblingDirId+"");let s=e.constructor[WjDirectiveBehavior.directiveResolvedTypeDataProp];s?this.resolvedTypeData=s:e.constructor[WjDirectiveBehavior.directiveResolvedTypeDataProp]=s=this.resolvedTypeData=new WjComponentResolvedMetadata(n),e[WjDirectiveBehavior.BehaviourRefProp]=this,i[WjDirectiveBehavior.BehaviourRefProp]=this,e[WjDirectiveBehavior.isInitializedPropAttr]=!1,this._createEvents(),this._setupAsChild(),this._isHostElement()&&t.nativeElement.setAttribute(WjDirectiveBehavior.siblingDirIdAttr,n.siblingId),this.subscribeToEvents(!1)}static getHostElement(e,t){return WjDirectiveBehavior.ngZone||(WjDirectiveBehavior.ngZone=t.get(core_1.NgZone)),e.nativeElement}static attach(e,t,i,r){return new WjDirectiveBehavior(e,t,i,r)}ngOnInit(){this.isInitialized=!0,this._initParent(),this.subscribeToEvents(!0)}ngAfterViewInit(){this.directive[WjDirectiveBehavior.isInitializedPropAttr]=!0,setTimeout(()=>{this.isDestroyed||this.directive[WjDirectiveBehavior.initializedEventAttr].emit(void 0)})}ngOnDestroy(){if(!this.isDestroyed){this.isDestroyed=!0;var e=this.directive;if(this._siblingInsertedEH&&this.elementRef.nativeElement.removeEventListener("DOMNodeInserted",this._siblingInsertedEH),this._isChild()&&this.parentBehavior){let i=this.parentBehavior.directive,r=this._getParentProp();if(!this.parentBehavior.isDestroyed&&i&&r&&e){let n=i[r];if(wjcCore.isArray(n)&&n){var t=n.indexOf(e);t>=0&&n.splice(t,1)}}}if(e instanceof wjcCore.Control&&e.hostElement){let t=this.elementRef.nativeElement,i=t&&t.parentNode,r=i?Array.prototype.indexOf.call(i.childNodes,t):-1;e.dispose(),r>-1&&Array.prototype.indexOf.call(i.childNodes,t)<0&&(t.textContent="",r<i.childNodes.length&&i.replaceChild(t,i.childNodes[r]))}this.injector[WjDirectiveBehavior.BehaviourRefProp]=null}}static instantiateTemplate(e,t,i,r,n=!1,s={}){var o,a=t.createEmbeddedView(i,s,t.length),l=a.rootNodes;if(n&&1===l.length)o=l[0];else{o=document.createElement("div");for(let e of l)o.appendChild(e)}return e&&e.appendChild(o),{viewRef:a,rootElement:o}}getPropChangeEvent(e){let t=this.typeData.changeEvents;if(t)for(let i in t)if(t[i].indexOf(e)>-1)return i;return null}_createEvents(){let e=this.resolvedTypeData.allImplEvents;for(let t of e)this.directive[t]=new core_1.EventEmitter(!1)}subscribeToEvents(e){var t=this.resolvedTypeData.changeEventMap;e=!!e;for(let i of t)e!==i.event.indexOf(".")<0&&this.addHandlers(i);if(e)for(let e of t)this.triggerPropChangeEvents(e,!0)}addHandlers(e){let t=this.directive;WjDirectiveBehavior.evaluatePath(t,e.event).addHandler((i,r)=>{this._runInsideNgZone(()=>{this.isInitialized&&this.triggerPropChangeEvents(e),e.eventImpl&&this._triggerEvent(t[e.eventImpl],r,e.props&&e.props.length>0)})})}triggerPropChangeEvents(e,t=!0){let i=this.directive;if(e.props&&e.props.length)for(let r of e.props)this._triggerEvent(i[r.evImpl],i[r.prop],t)}_setupAsChild(){this._isChild()&&(this._isHostElement()&&(this.elementRef.nativeElement.style.display="none"),this.parentBehavior=WjDirectiveBehavior.getBehavior(this.injectedParent))}_isAsyncBinding(){let e=this.directive[WjDirectiveBehavior.asyncBindingUpdatePropAttr];return null==e?WjOptions.asyncBindings:e}_isChild(){return this._isParentInitializer()||this._isParentReferencer()}_isParentInitializer(){return null!=this.directive[WjDirectiveBehavior.parPropAttr]}_isParentReferencer(){return!!this.typeData.parentRefProperty}_getParentProp(){return this.directive[WjDirectiveBehavior.parPropAttr]}_getParentReferenceProperty(){return this.typeData.parentRefProperty}_useParentObj(){return!1}_parentInCtor(){return this._isParentReferencer()&&""==this._getParentReferenceProperty()}_initParent(){if(this.parentBehavior&&!this._useParentObj()){var e=this.parentBehavior.directive,t=this._getParentProp(),i=this.directive;if(this._isParentInitializer()){this._getParentProp();let r=e[t];if(wjcCore.isArray(r)){let e=this._isHostElement(),t=e?this._getSiblingIndex():-1;(t<0||t>=r.length)&&(t=r.length),r.splice(t,0,i),e&&(this._siblingInsertedEH=this._siblingInserted.bind(this),this.elementRef.nativeElement.addEventListener("DOMNodeInserted",this._siblingInsertedEH))}else e[t]=i}this._isParentReferencer()&&!this._parentInCtor()&&(i[this._getParentReferenceProperty()]=e)}}_getSiblingIndex(){var e=this.elementRef.nativeElement,t=e.parentElement;if(!t)return-1;for(var i=t.childNodes,r=-1,n=this.typeData.siblingId,s=0;s<i.length;s++){var o=i[s];if(1==o.nodeType&&o.getAttribute(WjDirectiveBehavior.siblingDirIdAttr)==n&&(++r,o===e))return r}return-1}_siblingInserted(e){if(e.target===this.elementRef.nativeElement){var t=this._getSiblingIndex(),i=this.parentBehavior.directive[this._getParentProp()],r=this.directive,n=i.indexOf(r);t>=0&&n>=0&&t!==n&&(i.splice(n,1),t=Math.min(t,i.length),i.splice(t,0,r))}}_isHostElement(){return this.elementRef.nativeElement.nodeType===Node.ELEMENT_NODE}_runInsideNgZone(e){let t=WjDirectiveBehavior;return t.ngZone&&!t._ngZoneRun&&(t._ngZoneRun=t.ngZone.run.bind(t.ngZone)),(t._ngZoneRun||(e=>e()))(e)}_triggerEvent(e,t,i){if(i&&this._isAsyncBinding()){let i={event:e,args:t};this._pendingEvents.push(i),null==this._pendingEventsTO&&(this._pendingEventsTO=setTimeout(()=>{this._triggerPendingEvents(!1)},0))}else e.emit(t)}_triggerPendingEvents(e){if(null!=this._pendingEventsTO&&(clearTimeout(this._pendingEventsTO),this._pendingEventsTO=null),this.isDestroyed)return;let t=[].concat(this._pendingEvents);this._pendingEvents.splice(0,this._pendingEvents.length);for(let e of t)e.event.emit(e.args);e&&this._pendingEvents.length&&this._triggerPendingEvents(!0)}flushPendingEvents(){this._triggerPendingEvents(!0)}static evaluatePath(e,t){return this._pathBinding.path=t,this._pathBinding.getValue(e)}static getBehavior(e){return e?e[WjDirectiveBehavior.BehaviourRefProp]:null}}WjDirectiveBehavior.directiveTypeDataProp="meta",WjDirectiveBehavior.directiveResolvedTypeDataProp="_wjResolvedMeta",WjDirectiveBehavior.BehaviourRefProp="_wjBehaviour",WjDirectiveBehavior.parPropAttr="wjProperty",WjDirectiveBehavior.wjModelPropAttr="wjModelProperty",WjDirectiveBehavior.initializedEventAttr="initialized",WjDirectiveBehavior.isInitializedPropAttr="isInitialized",WjDirectiveBehavior.siblingDirIdAttr="wj-directive-id",WjDirectiveBehavior.asyncBindingUpdatePropAttr="asyncBindings",WjDirectiveBehavior.siblingDirId=0,WjDirectiveBehavior.wijmoComponentProviderId="WjComponent",WjDirectiveBehavior.outsideZoneEvents={pointermove:!0,pointerover:!0,mousemove:!0,wheel:!0,touchmove:!0,pointerenter:!0,pointerleave:!0,pointerout:!0,mouseover:!0,mouseenter:!0,mouseleave:!0,mouseout:!0},WjDirectiveBehavior._pathBinding=new wjcCore.Binding(""),exports.WjDirectiveBehavior=WjDirectiveBehavior;class Ng2Utils{static initEvents(e,t){var i=[];for(let e of t){let t=e.props;if(e.event&&e.eventImpl&&i.push(e.eventImpl+":"+e.event),t&&t.length)for(let e of t)i.push(e.evImpl+":"+e.evExposed)}return i}static getChangeEventNameImplemented(e){return Ng2Utils.getChangeEventNameExposed(e)+Ng2Utils.changeEventImplementSuffix}static getChangeEventNameExposed(e){return e+"Change"}static getWjEventNameImplemented(e){return e+Ng2Utils.wjEventImplementSuffix}static getWjEventName(e){if(e){const t=Ng2Utils.wjEventImplementSuffix;let i=e.length-t.length;if(i>0&&e.substr(i)===t)return e.substr(0,i)}return null}static getBaseType(e){let t;return e&&(t=Object.getPrototypeOf(e.prototype))&&t.constructor}static getAnnotations(e){return Reflect.getMetadata("annotations",e)}static getAnnotation(e,t){if(t&&e)for(let i of e)if(i instanceof t)return i;return null}static getTypeAnnotation(e,t,i){for(let r=e;r;r=i?null:Ng2Utils.getBaseType(r)){let e=Ng2Utils.getAnnotation(Ng2Utils.getAnnotations(r),t);if(e)return e}return null}static equals(e,t){return e!=e&&t!=t||wjcCore.DateTime.equals(e,t)||e===t}static _copy(e,t,i,r,n){if(e&&t)for(let s in t)if(r||"_"!==s[0]){let r=t[s];if(!n||n(s,r)){let t=e[s];wjcCore.isArray(r)?e[s]=(!wjcCore.isArray(t)||i?[]:t).concat(r):void 0!==r&&(e[s]=r)}}}}Ng2Utils.changeEventImplementSuffix="PC",Ng2Utils.wjEventImplementSuffix="Ng",exports.Ng2Utils=Ng2Utils;class WjValueAccessor{constructor(e){this._writeQnt=0,this._isSubscribed=!1,this._onChange=(e=>{}),this._onTouched=(()=>{}),this._directive=e,this._behavior=WjDirectiveBehavior.getBehavior(e)}writeValue(e){if(this._modelValue=e,++this._writeQnt,this._directive.isInitialized)this._ensureInitEhUnsubscribed(),this._updateDirective();else if(!this._dirInitEh){let e=this._directive.initialized;this._dirInitEh=e.subscribe(()=>{this._updateDirective(),this._ensureInitEhUnsubscribed()})}}registerOnChange(e){this._onChange=e}registerOnTouched(e){this._onTouched=e}setDisabledState(e){let t=this._directive;t instanceof wjcCore.Control&&(t.isDisabled=e)}_updateDirective(){if(!this._isFirstChange()||null!=this._modelValue){if(this._ensureNgModelProp(),this._directive&&this._ngModelProp){let e=this._modelValue;""===e&&(e=null),this._directive[this._ngModelProp]=e}this._ensureSubscribed()}}_ensureSubscribed(){if(this._isSubscribed)return;let e=this._directive;if(e){this._ensureNgModelProp();let t=this._ngModelProp=e[WjDirectiveBehavior.wjModelPropAttr];if(t){let i=this._behavior.getPropChangeEvent(t);i&&e[i].addHandler(this._dirValChgEh,this)}e instanceof wjcCore.Control&&e.lostFocus.addHandler(this._dirLostFocusEh,this),this._isSubscribed=!0}}_ensureNgModelProp(){!this._ngModelProp&&this._directive&&(this._ngModelProp=this._directive[WjDirectiveBehavior.wjModelPropAttr])}_ensureInitEhUnsubscribed(){this._dirInitEh&&(this._dirInitEh.unsubscribe(),this._dirInitEh=null)}_isFirstChange(){return this._writeQnt<2}_dirValChgEh(e,t){if(this._onChange&&this._directive&&this._ngModelProp){let e=this._directive[this._ngModelProp];Ng2Utils.equals(this._modelValue,e)||(this._modelValue=e,this._onChange(e))}}_dirLostFocusEh(e,t){this._onTouched&&this._onTouched()}}exports.WjValueAccessor=WjValueAccessor,exports.WjValueAccessorFactory=WjValueAccessorFactory;let moduleExports=[];class WjDirectiveBaseModule{}WjDirectiveBaseModule.decorators=[{type:core_1.NgModule,args:[{}]}],WjDirectiveBaseModule.ctorParameters=(()=>[]),exports.WjDirectiveBaseModule=WjDirectiveBaseModule;