@purtuga/dom-data-bind
Version:
DOM Data Bind utility. Bind data to DOM
2 lines • 32.8 kB
JavaScript
!function(t,e,n,r,i,o,a,u,s,l,c,h,f,d,v,p,y,_,g,m,b,k,w,E,x){!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.DomDataBind=e():t.DomDataBind=e()}(t,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||l.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&l.defineProperty(t,Symbol.toStringTag,{value:"Module"}),l.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=l.create(null);if(n.r(r),l.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return l.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t){return(i="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}n.d(e,"a",function(){return i})},function(e,n,r){"use strict";(function(e){r.d(n,"a",function(){return o});var i=r(0),o="undefined"!==(void 0===t?"undefined":l(i.a)(t))?t:"undefined"!==(void 0===e?"undefined":l(i.a)(e))?e:"undefined"!==("undefined"==typeof self?"undefined":l(i.a)(self))?self:c("return this;")()}).call(this,r(2))},function(e,n){var r;r=function(){return this}();try{r=r||new c("return this")()}catch(e){"object"==typeof t&&(r=t)}e.exports=r},function(n,i,u){"use strict";u.r(i);var h={};function f(t,e){return(f=l.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function v(t,e,n){return(v=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return o.prototype.toString.call(Reflect.construct(o,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(c.bind.apply(t,r));return n&&f(i,n.prototype),i}).apply(null,arguments)}function _(t,e){if(!(t instanceof e))throw new p("Cannot call a class as a function")}u.r(h),u.d(h,"AttrDirective",function(){return xe}),u.d(h,"ClassDirective",function(){return Te}),u.d(h,"EachDirective",function(){return He}),u.d(h,"HtmlDirective",function(){return Le}),u.d(h,"IfDirective",function(){return je}),u.d(h,"OnDirective",function(){return Ue}),u.d(h,"PropDirective",function(){return Je}),u.d(h,"ShowDirective",function(){return Qe}),u.d(h,"StyleDirective",function(){return Ye});var g=u(0);function m(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function b(t,e){return!e||"object"!==l(g.a)(e)&&"function"!=typeof e?m(t):e}function k(t){return(k=l.setPrototypeOf?l.getPrototypeOf:function(t){return t.__proto__||l.getPrototypeOf(t)})(t)}function w(t,e){if("function"!=typeof e&&null!==e)throw new p("Super expression must either be null or a function");t.prototype=l.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}var D=c.bind.call.bind(c.bind),N=D(c.call.bind,c.call),S=N(l.prototype.toString),C=function(t){return"[object Object]"===S(t)},T=function(t){return"[object String]"===S(t)},A=l.defineProperty,P=l.defineProperties,I=l.keys,B=[],M=s.isArray,$=N(B.forEach),H=N(B.indexOf),O=N(B.splice),V=N(B.slice),L=E.log,j=E.error||L,K=(E.warn,"undefined"!=typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator");var R=HTMLElement.prototype,W=e,G=(W.head,function(t){return W.createElement(t)}),F=function(t){return W.createTextNode(t||"")},z=(N(R.appendChild),N(R.insertBefore),N(R.hasAttribute)),U=N(R.getAttribute),q=N(R.setAttribute),J=N(R.removeAttribute),Q=function(t){return"[object DocumentFragment]"===S(t)};var X,Y=function t(e){for(var n=e||{},r=arguments.length,i=new s(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];var a,u,l=i.length,c=!1;for("boolean"==typeof e&&(c=e,n=i.shift()||{},l=i.length),a=0;a<l;a++)if(i[a])for(u in i[a])i[a].hasOwnProperty(u)&&(c&&C(n[u])&&C(i[a][u])?n[u]=t(!0,n[u],i[a][u]):n[u]=i[a][u]);return n};"undefined"==typeof WeakMap?function(){var e=l.defineProperty,n=o.now()%1e9,r=X=function(){this.name="__st"+(1e9*d.random()>>>0)+n+++"__"};r.prototype={set:function(t,n){var r=t[this.name];return r&&r[0]===t?r[1]=n:e(t,this.name,{value:[t,n],writable:!0}),this},get:function(t){var e;return(e=t[this.name])&&e[0]===t?e[1]:x},delete:function(t){var e=t[this.name];return!(!e||e[0]!==t)&&(e[0]=e[1]=x,!0)},has:function(t){var e=t[this.name];return!!e&&e[0]===t}},t.WeakMap=r}():X=WeakMap;var Z={stash:new X,create:function(){return new X}};function tt(t){return function(t){if(s.isArray(t)){for(var e=0,n=new s(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in l(t)||"[object Arguments]"===l.prototype.toString.call(t))return s.from(t)}(t)||function(){throw new p("Invalid attempt to spread non-iterable instance")}()}function et(t,e,n){return e in t?l.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var nt=u(1);function rt(t,e){A(this,"_",{value:{keys:t.slice(0),values:e?e.slice(0):null,idx:0,total:t.length}})}P(rt.prototype,{constructor:{value:rt},next:{enumerable:!0,configurable:!0,value:function(){var t={done:this._.idx===this._.total};if(t.done)return t.value=x,t;var e=this._.idx++;return t.value=this._.keys[e],this._.values&&(t.value=[t.value,this._.values[e]]),t}}}),A(rt.prototype,K,{value:function(){return this}});var it=nt.a.Set&&nt.a.Set.prototype[K]?nt.a.Set:ot;function ot(){}P(ot.prototype,et({constructor:{value:ot,configurable:!0},_:{get:function(){var t=[];return A(this,"_",{value:t}),t}},add:{value:function(t){return-1===H(this._,t)&&this._.push(t),this}},has:{value:function(t){return-1!==H(this._,t)}},size:{get:function(){return this._.length}},clear:{value:function(){this._.splice(0)}},delete:{value:function(t){var e=H(this._,t);return-1!==e&&(this._.splice(e,1),!0)}},values:{value:function(){return new rt(this._)}},entries:{value:function(){return new rt(this._,this._)}},forEach:{value:function(t,e){this._.forEach(function(n){return t.call(e,n,n)})}}},K,{value:function(){return this.values()}}));var at,ut=new it;var st=function(t){"function"==typeof t&&(ut.add(t),at||(at=r(lt,0)))};function lt(){var t,e=tt(ut);for(ut.clear(),at=null;t=e.shift();)t(),t=null}var ct=Z.create(),ht=["destroy","remove","off"];function ft(t){var e,n=[];for(e in t)n.push(e);return n}var dt={isDestroyed:!1,init:function(){},destroy:function(t){if(ct.has(this)){var e=ct.get(this);ct.delete(this),t?e.forEach(pt):st(function(){return e.forEach(pt)})}"boolean"==typeof this.isDestroyed&&(this.isDestroyed=!0)},onDestroy:function(t){(function(t){ct.has(t)||ct.set(t,[]);return ct.get(t)})(this).push(t)},getFactory:function(){if(this.constructor)return this.constructor}},vt={extend:function(){for(var t=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,t),e}(this),e=arguments.length,n=new s(e),r=0;r<e;r++)n[r]=arguments[r];return Y(t.prototype,n.reduce(function(t,e){if(e){var n=e.prototype||e;ft(n).forEach(function(e){t[e]=n[e]})}return t},{})),t},isInstanceOf:function(t){return!!t&&!ft(this.prototype).some(function(e){return void 0===t[e]})},create:function(){return v(this,s.prototype.slice.call(arguments))},getDestroyCallback:function(t,e){return function(){t&&l.keys(t).forEach(function(e){t[e]&&(ht.some(function(n){if(t[e][n]&&("remove"!==n||!(t[e]instanceof Node)))return t[e][n](),!0}),t[e]=x)}),e&&e.has&&e.has(t)&&e.delete(t)}}};function pt(t){"function"==typeof t&&t()}var yt=function(){function t(){for(var e=arguments.length,n=new s(e),r=0;r<e;r++)n[r]=arguments[r];return this&&this.constructor&&this instanceof this.constructor?this.init.apply(this,n):v(t,n)}return t.prototype.constructor=t,t}();Y(yt.prototype,dt),Y(yt,vt);var _t=yt,gt=nt.a.Map&&nt.a.Map.prototype[K]?nt.a.Map:mt;function mt(){}P(mt.prototype,et({constructor:{value:mt,configurable:!0},_:{get:function(){return A(this,"_",{value:{keys:[],values:[]}}),this._}},get:{value:function(t){return this._.values[H(this._.keys,t)]}},set:{value:function(t,e){return-1===H(this._.keys,t)&&(this._.keys.push(t),this._.values.push(e)),this}},has:{value:function(t){return-1!==H(this._.keys,t)}},size:{get:function(){return this._.keys.length}},clear:{value:function(){O(this._.keys,0),O(this._.values,0)}},delete:{value:function(t){var e=H(this._.keys,t);return-1!==e&&(O(this._.keys,e,1),O(this._.values,e,1),!0)}},keys:{value:function(){return new rt(this._.keys)}},values:{value:function(){return new rt(this._.values)}},entries:{value:function(){return new rt(this._.keys,this._.values)}},forEach:{value:function(t,e){var n=this;this._.keys.forEach(function(r,i){return t.call(e,n._.values[i],r)})}}},K,{value:function(){return this.entries()}}));var bt=e,kt=c,wt=Element.prototype,Et=new gt,xt=1,Dt="DomDataBind",Nt=Z.create(),St="D-".concat(o.now(),"-").concat(d.random().toString(36).replace(/[^a-z0-9]+/g,"")),Ct=N,Tt=C,At=N(wt.removeChild),Pt=D(bt.createComment,bt),It=function(t){var e=S(t);return"[object HTMLTemplateElement]"===e||"[object HTMLUnknownElement]"===e&&!!t.content},Bt=j;function Mt(t){var e=arguments.length>1&&arguments[1]!==x?arguments[1]:"runtime";if(t=t.trim(),Et.has(t))return Et.get(t);var n=new kt("$DATA","\nwith ($DATA) {\n if ($DATA.$data) {\n with ($DATA.$data) {\n return (".concat(t,");\n }\n } \n return (").concat(t,");\n}\n//# sourceURL=valueGetter:").concat(e,".").concat(xt++,".js"));return Et.set(t,n),n}function $t(t){for(var e=[],n=t.attributes.length,r=0;r<n;r++)e.push(t.attributes.item(r).name);return e}var Ht=function(t,e){return s.prototype.slice.call(t.querySelectorAll(e))},Ot=1,Vt=function(t,e){var n="000000000"+t;return n.substr(n.length-e)},Lt=function(){var e,n=0;for(e in t)n++;return n}(),jt=Vt((navigator.mimeTypes.length+navigator.userAgent.length).toString(36)+Lt.toString(36),4),Kt=l.create({generate:function(){var t=(new o).getTime().toString(36),e=Vt((Ot++).toString(36),4),n="xxxxxxxx".replace(/[x]/g,function(){return(16*d.random()|0).toString(16)});return"c"+t+e+jt+n}});function Rt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),l.defineProperty(t,r.key,r)}}function Wt(t,e,n){return e&&Rt(t.prototype,e),n&&Rt(t,n),t}function Gt(t,e,n){return(Gt="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!l.prototype.hasOwnProperty.call(t,e)&&null!==(t=k(t)););return t}(t,e);if(r){var i=l.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(n):i.value}})(t,e,n||t)}function Ft(t,e){return e&&e.parentNode&&e.parentNode.insertBefore&&e.parentNode.insertBefore(t,e),t}function zt(t){return t&&t.parentNode&&t.parentNode.removeChild(t),t}var Ut=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,_t),Wt(e,[{key:"init",value:function(t,e,n){this._directives=n,this._d=this._directive=t,this._n=this._node=e}},{key:"destroy",value:function(){var t=Nt.get(this);t&&(t.tracker&&t.tracker.stopWatchingAll&&t.tracker.stopWatchingAll(),t.data&&(t.data=null)),Gt(k(e.prototype),"destroy",this).call(this),Nt.delete(this)}},{key:"render",value:function(t){this._d.render(this,this._n,t)}},{key:"update",value:function(){}}]),e}(),qt=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,_t),Wt(e,[{key:"render",value:function(t,e,n){var r=this,i=Nt.get(t);i||(i={data:null,value:"",isQueued:!1,tracker:function(){return r.render(t,e,i.data)}},Nt.set(t,i)),i.data!==n&&(i.tracker.stopWatchingAll&&i.tracker.stopWatchingAll(),i.data=n),this.update(t)}},{key:"update",value:function(t){if(!t.isDestroyed){var e=Nt.get(t);if(e){var n="";try{n=this._tokenValueGetter(e.data||{}),t.update&&t.update(n)}catch(t){Bt(t)}e.value!==n&&(e.value=n)}}}},{key:"cleanNode",value:function(t){this._attr&&8!==t.nodeType&&J(t,this._attr)}},{key:"getNodeHandler",value:function(t,e){return this.cleanNode(t),new this.constructor.NodeHandlerConstructor(this,t,e)}}],[{key:"has",value:function(){return""}},{key:"manages",value:function(){return!1}}]),e}();et(qt,"NodeHandlerConstructor",Ut);var Jt=qt,Qt=new gt;function Xt(t){var e=arguments.length>1&&arguments[1]!==x?arguments[1]:Xt.directives||[],n=T(t)?t:t.innerHTML;return Yt(n)||Qt.set(n,new ve(t,e)),Qt.get(n)}function Yt(t){return Qt.has(t)}Xt.directives=null,Xt.has=Yt;var Zt=function(){function t(e,n){var r=arguments.length>2&&arguments[2]!==x?arguments[2]:"";_(this,t),this._frag=e,this._bindings=n,this._childNodes=V(e.childNodes,0),this.fromTemplateId=r}return Wt(t,[{key:"recover",value:function(){var t=this;this._childNodes.forEach(function(e){return t._frag.appendChild(e)})}},{key:"destroy",value:function(){if(this.recover(),this._bindings){for(var t=0,e=this._bindings.length;t<e;t++)this._bindings[t].destroy();this._bindings.length=0}}},{key:"setData",value:function(t){for(var e=0,n=this._bindings.length;e<n;e++)this._bindings[e].render(t)}}]),t}();function te(t,n,r){var i=t instanceof de?t:Xt(t,r),o=e.importNode(i.ele.content,!0);return o[Dt]=new Zt(o,ye(o,i._bindings,i._directives),i.id),o[Dt].setData(n),o}var ee="text.binding",ne=function(t){return!!t.parentNode},re=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"init",value:function(){for(var t,n=arguments.length,r=new s(n),i=0;i<n;i++)r[i]=arguments[i];(t=Gt(k(e.prototype),"init",this)).call.apply(t,[this].concat(r));var o=this._node;8===o.nodeType&&o.nodeValue===St&&(this._placeholderEle=o,this._placeholderEle.data=ee,this._node=Ft(F(""),this._placeholderEle),zt(this._placeholderEle)),this._placeholderEle||(this._placeholderEle=Pt(ee)),this._externalNodes=null,this._template=null,this._templateInst=null}},{key:"update",value:function(t){if(function(t){return"[object Null]"===S(t)}(t)||function(t){return"[object Undefined]"===S(t)}(t))return this.clear(),void this.setPlaceholder();if(t instanceof de){var e=Nt.get(this).data;return this._template&&this._template.id===t.id?void this._templateInst.DomDataBind.setData(e):(this.clear(),this.setPlaceholder(),this._template=t,this._templateInst=te(t,e,this._directives),void Ft(this._templateInst,this._placeholderEle))}if(t instanceof Node){if(this.isCurrentExternal(t))return;return this.clear(),this.setPlaceholder(),this.storeExternals(t),void Ft(t,this._placeholderEle)}ne(this._node)||(this.clear(),Ft(this._node,this._placeholderEle),zt(this._placeholderEle)),t!==this._node.nodeValue&&(this._node.nodeValue=t)}},{key:"storeExternals",value:function(t){this._externalNodes&&this.removeExternals(),this._externalNodes=Q(t)?V(t.childNodes,0):[t]}},{key:"removeExternals",value:function(){if(this._externalNodes){for(var t=0,e=this._externalNodes.length;t<e;t++)zt(this._externalNodes[t]);this._externalNodes=null}}},{key:"isCurrentExternal",value:function(t){var e=this;return this._externalNodes&&(!Q(t)&&1===this._externalNodes.length&&this._externalNodes[0]===t||V(t).every(function(t,n){return t===e._externalNodes[n]}))}},{key:"destroyTemplateView",value:function(){this._templateInst&&(this._templateInst.DomDataBind.destroy(),this._templateInst=this._template=null)}},{key:"clear",value:function(){this.removeExternals(),this.destroyTemplateView(),this._node.nodeValue=""}},{key:"setPlaceholder",value:function(){ne(this._placeholderEle)||(Ft(this._placeholderEle,this._node),zt(this._node))}},{key:"destroy",value:function(){Gt(k(e.prototype),"destroy",this).call(this),this.clear()}}]),e}(),ie=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t){this._tokenText=t,this._tokenValueGetter=Mt(t,ee)}}]),e}();et(ie,"NodeHandlerConstructor",re);var oe=ie,ae=function(){var t=W.createDocumentFragment();return t.appendChild(F("test")),t.appendChild(F("")),1===t.cloneNode(!0).childNodes.length}(),ue=function(){var t=G("div"),e=F("test");return t.appendChild(e),!t.contains(e)}(),se=Ct(Text.prototype.splitText),le=new RegExp("{{(.*?)}}"),ce=new RegExp("{{(.*?)}}","g"),he=function(t){return t?t.nodeValue:""},fe=function(t){return le.test(he(t))},de=function t(e){var n=arguments.length>1&&arguments[1]!==x?arguments[1]:[];_(this,t),this.id=Kt.generate(),It(e)?this.ele=e:(this.ele=G("template"),this.ele.innerHTML=e),this._directives=n,this._bindings=pe(this.ele.content,n)},ve=de;function pe(t,e){var n,r=new Map,i=new Map,o=new Set,a=function(t){for(var e,r,a,u=n;e=t.has(n);)if(r=U(n,e),(a=t.manages())&&(u=Pt("")),_e(i,u).push(me(t,e,r)),J(n,e),a){o.add(n),n.parentNode.insertBefore(u,n);var s=G("div");s.appendChild(n),u.data=s.innerHTML}return a};return function(t){return[t].concat(Ht(t,"*")).reduce(ke,[]).filter(be)}(t).forEach(function(t){var r=!1;if(o.size){var u=!0,s=!1,l=x;try{for(var c,h=o.values()[Symbol.iterator]();!(u=(c=h.next()).done);u=!0){var f=c.value;if(ue&&3===t.nodeType?16&f.compareDocumentPosition(t)&&(r=!0):f.contains(t)&&(r=!0),r)break}}catch(t){s=!0,l=t}finally{try{u||null==h.return||h.return()}finally{if(s)throw l}}}n=t,r||(1===t.nodeType?e.some(a):3===t.nodeType&&function(t){if(fe(t)){ce.lastIndex=0;for(var e=he(t),n=ce.exec(e);n;)if(e==="{{"+n[1]+"}}")_e(i,t).push(ge(oe,n[1])),n=null;else{var r=se(t,n.index);ae&&we(t),t=se(r,n[0].length);var o=r.parentNode.insertBefore(Pt(St),r);r.parentNode.removeChild(r),_e(i,o).push(ge(oe,n[1])),ce.lastIndex=0,!(n=ce.exec(he(t)))&&ae&&we(t)}}}(t))}),n=null,i.forEach(function(e,n){if(t!==n){for(var i=[],o=n,a=o.parentNode;o!==t;)i.unshift(i.indexOf.call(a.childNodes,o)),a=(o=o.parentNode).parentNode;r.set(i,e)}else r.set([],e)}),i.clear(),o.clear(),r}function ye(t,e,n){var r=[];return e.forEach(function(e,i){var o=function(t,e){if(!e.length)return t;return $(e,function(e){return t=t.childNodes[e]}),t}(t,i);if(o)for(var a=0,u=e.length;a<u;a++)r.push(e[a].getNodeHandler(o,n));else Bt(new y("dom-data-bind#render(): Unable to find node!"))}),r}function _e(t,e){return t.has(e)||t.set(e,[]),t.get(e)}function ge(t,e){e=e.trim();var n=Nt.get(t);return n||(n={},Nt.set(t,n)),n[e]||(n[e]=new t(e)),n[e]}function me(t,e,n){n=n.trim();var r="".concat(e,"-").concat(St,"-").concat(n),i=Nt.get(t);return i||(i={},Nt.set(t,i)),i[r]||(i[r]=new t(e,n)),i[r]}function be(t){return 1!==t.nodeType||1===t.nodeType&&t.attributes.length>0}function ke(t,e){if(t.push(e),e.hasChildNodes())for(e=e.firstChild;e;){var n=e.nextSibling;3===e.nodeType&&e.nodeValue&&le.test(he(e))&&t.push(e),ae&&we(e),e=n}return t}function we(t){3===t.nodeType&&ae&&!t.nodeValue&&(t.parentNode.insertBefore(Pt(""),t),t.parentNode.removeChild(t))}var Ee=_t.extend({$ele:null,init:function(t,e){var n=this.getFactory(),r={html:t,data:e,directives:n.directives.slice(0)};Nt.set(this,r),T(t)?(this.$ele=te(t,e,r.directives),r.bindings=this.$ele._bindings):(this.$ele=t,r.bindings=ye(t,pe(t,r.directives),r.directives),e&&this.setData(e)),this.onDestroy(function(){$(r.bindings,function(t){return t.destroy()}),delete r.data,delete r.directives,delete r.bindings,n.getDestroyCallback(r,Nt)()})},setData:function(t){var e=Nt.get(this).bindings;$(e,function(e){return e.render(t)})}});Ee.directives=[];var xe=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","attr"),this._htmlAttr=new RegExp(this.constructor._matches).exec(t)[1]}}],[{key:"has",value:function(t){var e=this,n="";return $t(t).some(function(t){return e._matches.test(t)&&(n=t)}),n}}]),e}();et(xe,"NodeHandlerConstructor",function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"update",value:function(t){var e=Nt.get(this),n=this._directive._htmlAttr;this._directive.constructor._isProp?t!==e.value&&(this._node[n]=t):t&&e.value!==t?q(this._node,n,t):e.value&&!t&&J(this._node,n)}}]),e}()),et(xe,"_matches",/^_attr\.(.*)/),et(xe,"_isProp",!1);var De=xe;var Ne=function(t,e){return!(!t||!e)&&t.classList.contains(e)};var Se=function(t,e){var n=a(e).trim().split(/\s+/).map(function(t){return t.trim()});t&&n.length&&n.forEach(function(e){return t.classList.add(e)})};var Ce=function(t,e){return t.classList.remove(e)},Te=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","class")}}],[{key:"has",value:function(t){return z(t,"_class")?"_class":""}}]),e}();et(Te,"NodeHandlerConstructor",function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"update",value:function(t){var e=this._node,n=Nt.get(this).value||{};l.keys(t).concat(l.keys(n)).forEach(function(n){t[n]&&!Ne(e,n)?Se(e,n):!t[n]&&Ne(e,n)&&Ce(e,n)})}}]),e}());function Ae(t,e){return function(t){if(s.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,i=!1,o=x;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return n}(t,e)||function(){throw new p("Invalid attempt to destructure non-iterable instance")}()}var Pe=Symbol("directive.each.setup"),Ie="_key",Be=function(t){return t&&t._destroy()},Me=function(t){return t},$e=function(t){function e(){var t,n;_(this,e);for(var r=arguments.length,i=new s(r),o=0;o<r;o++)i[o]=arguments[o];return et(m(m(n=b(this,(t=k(e)).call.apply(t,[this].concat(i))))),"binders",[]),et(m(m(n)),"bindersByKey",new gt),et(m(m(n)),"listIterator",function(){return n._directive.iterateOverList(m(m(n)),Nt.get(m(m(n))).value)}),n}return w(e,Ut),Wt(e,[{key:"init",value:function(t,n,r){Gt(k(e.prototype),"init",this).call(this,t,n,r),this._placeholderEle=Pt("directive.each"),this._isSoleChild=function(t){return s.prototype.every.call(t.parentNode.childNodes,function(e){return e===t||3===e.nodeType&&!e.textContent.trim()})}(this._node),this._viewTemplate=Xt(n.data,r),this._viewTemplate[Pe]||function(t){if(!t[Pe]){t[Pe]={usesKey:!1,getKey:Me};var e=t.ele.content.firstChild;e&&e.hasAttribute&&z(e,Ie)&&(t[Pe].usesKey=!0,t[Pe].getKey=Mt(U(e,Ie),"each.key"),J(e,Ie))}}(this._viewTemplate),Ft(this._placeholderEle,n),At(n.parentNode,n)}},{key:"update",value:function(t){var e=Nt.get(this);t!==e.value&&(e.value=null,this.listIterator.stopWatchingAll&&this.listIterator.stopWatchingAll()),t?(e.value=t,function(t){return M(t)&&!t.length||Tt(t)&&!I(t).length}(t)&&this.binders?this._directive.destroyChildBinders(this.binders,this):this.listIterator()):this._directive.destroyChildBinders(this.binders,this)}},{key:"destroy",value:function(){this.listIterator.stopWatchingAll&&this.listIterator.stopWatchingAll(),this.bindersByKey.clear(),this._directive.destroyChildBinders(this.binders,this),Gt(k(e.prototype),"destroy",this).call(this)}}]),e}(),He=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){var n=Ae(function(t){var e=/\(?(.+?)\)?\W?(?:of|in)\W(.*)/.exec(t);if(e)return(e=e.slice(1))[0]=e[0].split(/,/).map(function(t){return a(t).trim()}),e;return[]}((e||"").trim()),2),r=n[0],i=n[1];this._attr=t,this._iteratorArgs=r,this._tokenValueGetter=Mt(i||"","each")}},{key:"destroyChildBinders",value:function(t,e){if(t&&t.length)if(t=t.splice(0),e._isSoleChild){var n=e._placeholderEle.parentNode;n.textContent="",n.appendChild(e._placeholderEle),r(function(){$(t,function(t){return t._destroy()})})}else $(t,function(t){return t._destroy()})}},{key:"getDataForIteration",value:function(t,e){return this._iteratorArgs.reduce(function(e,n){return e[n]=t.shift(),e},e||{})}},{key:"iterateOverList",value:function(t,e){var n,r=Nt.get(t),i=M(e);if(i)i=!0,n=e;else{if(!Tt(e))return;n=I(e)}for(var o=t.binders,a=new gt,u=n.length,s=t._viewTemplate[Pe],l=s.usesKey,c=s.getKey,h=0;h<u;h++){var f={$root:r.data.$root||r.data,$parent:r.data,$data:r.data.$data||r.data};i?this.getDataForIteration([n[h],h],f):this.getDataForIteration([e[n[h]],n[h],h],f);var d=c(l?f:i?n[h]:e[n[h]]);if(o[h]&&o[h]._loop.rowKey===d)o[h][Dt].setData(f);else{o[h]&&(o[h][Dt].recover(),a.set(o[h]._loop.rowKey,o[h]),o[h]=null);var v=t.bindersByKey.get(d);if(v?null!==v._loop.pos&&o[v._loop.pos]===v&&(o[v._loop.pos]=null):(v=a.get(d))&&a.delete(d),v)o[h]=v,v._loop.pos=h,o[h][Dt].recover(),Oe(o,h,t._placeholderEle),o[h][Dt].setData(f);else{if(a.size){var p=Ae(a.entries().next().value,2),y=p[0];(v=p[1])[Dt].setData(f),a.delete(y),v._loop.rowKey=d,v._loop.pos=h}else(v=te(t._viewTemplate,f,t._directives))._destroy=Ve,v._handler=t,v._loop={rowKey:d,pos:h};o[h]=v,t.bindersByKey.set(d,v),Oe(o,h,t._placeholderEle)}}}a.size&&($(a.values(),Be),a.clear()),u<o.length&&$(O(o,u),Be)}}],[{key:"has",value:function(t){return z(t,"_each")?"_each":""}},{key:"manages",value:function(){return!0}}]),e}();function Oe(t,e,n){var r=t[e];r[Dt].recover(),t[e+1]?Ft(r,t[e+1][Dt]._childNodes[0]):Ft(r,n)}function Ve(){this[Dt].recover(),this._loop.rowKey&&this._handler.bindersByKey.delete(this._loop.rowKey),this[Dt].destroy()}et(He,"NodeHandlerConstructor",$e);var Le=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","html")}}],[{key:"has",value:function(t){return z(t,"_html")?"_html":""}}]),e}();et(Le,"NodeHandlerConstructor",function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"update",value:function(t){t!==Nt.get(this).value&&(this._node.innerHTML=t)}}]),e}());var je=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","if")}}],[{key:"has",value:function(t){return z(t,"_if")?"_if":""}},{key:"manages",value:function(){return!0}}]),e}();et(je,"NodeHandlerConstructor",function(t){function e(){var t,n;_(this,e);for(var r=arguments.length,i=new s(r),o=0;o<r;o++)i[o]=arguments[o];return et(m(m(n=b(this,(t=k(e)).call.apply(t,[this].concat(i))))),"_renderedEle",null),et(m(m(n)),"_renderTemplate",n._node.data),n}return w(e,Ut),Wt(e,[{key:"init",value:function(){for(var t,n=arguments.length,r=new s(n),i=0;i<n;i++)r[i]=arguments[i];(t=Gt(k(e.prototype),"init",this)).call.apply(t,[this].concat(r)),this._placeholderEle=Pt("directive.if"),Ft(this._placeholderEle,this._node),At(this._node.parentNode,this._node)}},{key:"update",value:function(t){var e=Nt.get(this);e.value!==t?t&&!this._renderedEle?(this._renderedEle=te(this._renderTemplate,e.data,this._directives),Ft(this._renderedEle,this._placeholderEle)):t||this.teardown():this._renderedEle&&this._renderedEle[Dt].setData(e.data)}},{key:"teardown",value:function(){this._renderedEle&&(this._renderedEle[Dt].recover(),this._renderedEle[Dt].destroy(),this._renderedEle=null)}},{key:"destroy",value:function(){this.teardown(),Gt(k(e.prototype),"destroy",this).call(this)}}]),e}());var Ke=function(t,e,n,r){var i=e.split(/\s+/),o={};return i.forEach(function(e){t.addEventListener(e,n,r),o[e]={remove:function(){return t.removeEventListener(e,n,r)}}}),l.create({listeners:o,remove:function(){i.forEach(function(t){return o[t].remove()})}})},Re=new RegExp("^".concat(function(t){return a(t).replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}("_on."),"(.*)")),We=/^\d+$/,Ge={13:"enter",27:"esc",9:"tab",46:"delete",32:"space",38:"up",40:"down",37:"left",39:"right"},Fe=l.values(Ge),ze=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"init",value:function(){for(var t,n=arguments.length,r=new s(n),i=0;i<n;i++)r[i]=arguments[i];(t=Gt(k(e.prototype),"init",this)).call.apply(t,[this].concat(r)),this.setup()}},{key:"handleEvent",value:function(t){var e=this._directive._info,n=e.hasModifiers,r=e.modifiers,i=t.which;if(!(this._directive._filter&&t instanceof KeyboardEvent)||r[i]||r[Ge[i]]){var o,a,u=Nt.get(this);u.data.$ev=t;try{o=this._directive._tokenValueGetter.call(this._node,u.data)}catch(t){return void Bt(t)}return delete u.data.$ev,"function"==typeof o?a=o.call(this._node,t):o&&"function"===o.handleEvent&&(a=o.handleEvent(t)),n&&(r.once&&this.teardown(),r.stop&&t.stopPropagation(),r.prevent&&t.preventDefault()),a}}},{key:"setup",value:function(){this._evListener=Ke(this._node,this._directive._eventName,this)}},{key:"teardown",value:function(){this._evListener&&(this._evListener.remove(),this._evListener=null)}},{key:"destroy",value:function(){this.teardown(),Gt(k(e.prototype),"destroy",this).call(this)}}]),e}(),Ue=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._info=function(t){var e={value:"",hasModifiers:!0,modifiers:t.split(/\./)};return e.value=e.modifiers.shift(),e.hasModifiers=Boolean(e.modifiers.length),e.modifiers=e.modifiers.reduce(function(t,e){return t[e]=!0,t},{}),e}(new RegExp(Re).exec(t)[1]),this._eventName=this._info.value,this._tokenValueGetter=Mt(e||"","on");var n=this._info.modifiers;this._filter=I(n).some(function(t){return-1!==Fe.indexOf(t)||We.test(t)})}},{key:"render",value:function(t,e,n){var r=this,i=Nt.get(t);i||(i={data:{$data:{}},tracker:function(){return r.render(t,e,i.data)}},Nt.set(t,i)),n&&(n.$data?i.data=n:i.data.$data=n)}}],[{key:"has",value:function(t){var e="";return $t(t).some(function(t){return Re.test(t)&&(e=t)}),e}}]),e}();et(Ue,"NodeHandlerConstructor",ze);var qe=/^_prop\.(.*)/,Je=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,De),Wt(e,null,[{key:"_isProp",value:function(){return!0}},{key:"_matches",get:function(){return qe}}]),e}(),Qe=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","show")}}],[{key:"has",value:function(t){return z(t,"_show")?"_show":""}}]),e}();et(Qe,"NodeHandlerConstructor",function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"init",value:function(){for(var t,n=arguments.length,r=new s(n),i=0;i<n;i++)r[i]=arguments[i];(t=Gt(k(e.prototype),"init",this)).call.apply(t,[this].concat(r)),this._origDisplayStyle=this._node.style.display||""}},{key:"update",value:function(t){var e=this._node.style;t?e.display=this._origDisplayStyle:"none"!==e.display&&(e.display="none")}}]),e}());function Xe(t,e){t&&"object"===l(g.a)(e)&&l.keys(e).forEach(function(n){t.style[n]=e[n]})}var Ye=function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Jt),Wt(e,[{key:"init",value:function(t,e){this._attr=t,this._tokenValueGetter=Mt(e||"","style")}}],[{key:"has",value:function(t){return z(t,"_style")?"_style":""}}]),e}();et(Ye,"NodeHandlerConstructor",function(t){function e(){return _(this,e),b(this,k(e).apply(this,arguments))}return w(e,Ut),Wt(e,[{key:"update",value:function(t){Xe(this._node,t)}}]),e}());u.d(i,"DomDataBindAll",function(){return Ze}),u.d(i,"allDirectives",function(){return tn}),u.d(i,"AttrDirective",function(){return xe}),u.d(i,"ClassDirective",function(){return Te}),u.d(i,"EachDirective",function(){return He}),u.d(i,"HtmlDirective",function(){return Le}),u.d(i,"IfDirective",function(){return je}),u.d(i,"OnDirective",function(){return Ue}),u.d(i,"PropDirective",function(){return Je}),u.d(i,"ShowDirective",function(){return Qe}),u.d(i,"StyleDirective",function(){return Ye}),u.d(i,"DomDataBind",function(){return Ee}),u.d(i,"render",function(){return te}),u.d(i,"view",function(){return Xt}),u.d(i,"directives",function(){return h}),u.d(i,"Directive",function(){return qt});var Ze=Ee.extend(),tn=[He,je];l.keys(h).forEach(function(t){-1===tn.indexOf(h[t])&&tn.push(h[t])}),Ze.directives=tn;i.default=Ze}])})}(window,document,location,setTimeout,setInterval,Date,String,Number,Array,Object,Function,atob,btoa,Math,JSON,TypeError,Error,encodeURIComponent,decodeURIComponent,requestAnimationFrame,CustomEvent,clearInterval,clearTimeout,console);
//# sourceMappingURL=dom-data-bind.legacy.umd.min.js.map