Repository navigation
Expand file tree
/
Copy pathunar.0.0.3.min.js
More file actions
1 lines (1 loc) · 10 KB
/
Copy pathunar.0.0.3.min.js
File metadata and controls
1 lines (1 loc) · 10 KB
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Unar=e()}(this,function(){"use strict";var t="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},e=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},n=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),i=function t(e,n,i){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,n);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,n,i)}if("value"in r)return r.value;var s=r.get;return void 0!==s?s.call(i):void 0},r=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},o=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},s=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var s,u=t[Symbol.iterator]();!(i=(s=u.next()).done)&&(n.push(s.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&u.return&&u.return()}finally{if(r)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),u=function(t,e){try{return new Function("vm","with(vm){return "+t+"}")(e)}catch(e){console.error(t+" has a unresolved error")}},c={listener:null};window.listener=c;var a={actionPrefix:"u-",attrPrefix:":",evtPrefix:"@"},l=0,f=function(){function t(n,i,r){e(this,t),this.id=++l,this.exp=i,this.vm=n,this.oldVal=u(this.exp,this.vm),this.cb=r}return n(t,[{key:"update",value:function(){var t=u(this.exp,this.vm);t!==this.oldVal&&(this.cb.call(this.vm,t,this.oldVal),this.oldVal=t)}}]),t}(),h=function(e){var n;return("object"==(n=void 0===e?"undefined":t(e))?Object.prototype.toString.call(e).slice(8,-1):n).toLowerCase()},p=[];window.hubs=p;var d=function(){function t(n){e(this,t),this.key=n,this.listeners={}}return n(t,[{key:"addListener",value:function(t){var e=t.id;e in this.listeners||(this.listeners[e]=t)}},{key:"notify",value:function(){for(var t in this.listeners)this.listeners[t].update()}}]),t}(),v=function(t,e){!function t(e,n){Object.keys(e).forEach(function(i){var r=new d(i);p.push(r);var o=e[i];Object.defineProperty(e,i,{get:function(){return c.listener&&r.addListener(c.listener),console.log("accessor->get:"+i),o},set:function(e){o=e,"object"===h(e)&&t(e,n,path),r.notify()}}),"object"===h(o)&&t(o,n,path)})}(t,e),function(t,e){Object.keys(t).forEach(function(n){Object.defineProperty(e,n,{get:function(){return console.log("hijack->get:"+n),t[n]},set:function(e){t[n]=e}})})}(t,e)},y=function(){function t(){e(this,t)}return n(t,null,[{key:"isExpression",value:function(t){return/\{\{.*\}\}/.test(t)}},{key:"expressionKey",value:function(t){return t.match(/(.*)\{\{(.*)\}\}(.*)/)}},{key:"checkDirective",value:function(t,e){var n={prefix:"",directive:""};for(var i in e){var r=e[i];if(t.startsWith(r)){n.prefix=t.substring(0,r.length),n.directive=t.substring(r.length);break}}return n}}]),t}(),m=function(){function t(){e(this,t)}return n(t,null,[{key:"registDomListener4Hubs",value:function(t,e,n){c.listener=new f(n,e,t),t(function(t,e){try{return new Function("vm","with(vm){return "+t+"}")(e)}catch(e){console.error(t+" has a unresolved error")}}(e,n)),c.listener=null}}]),t}(),b=function(){function t(){e(this,t)}return n(t,null,[{key:"bind",value:function(t,e,n){t[e]=n}},{key:"lasyCompile",value:function(t,e,n,i,r){"if"===e&&(n?r.parentNode.insertBefore(t,r):r.parentNode.removeChild(t))}},{key:"addEvt",value:function(t,e,n){t.addEventListener(e,n,!1)}}]),t}(),x={model:"value",html:"innerHTML",text:"textContent",class:"className"},O=function(){function t(n){e(this,t),this.name=n.name,this.expOrFn=n.expOrFn,this.domPropOrEvt=x[n.name]?x[n.name]:n.name,this.vm=n.vm,this.compiler=n.compiler,this.node=n.node,this.preTxt=n.preTxt||"",this.nxtTxt=n.nxtTxt||""}return n(t,[{key:"bind",value:function(){var t=this;if(m.registDomListener4Hubs(function(e,n){b.bind(t.node,t.domPropOrEvt,t.preTxt+e+t.nxtTxt,t.preTxt+n+t.nxtTxt)},this.expOrFn,this.vm),"value"===this.domPropOrEvt){this.addEvt(function(e){return t.vm[t.expOrFn]=e.target.value},"input")}}},{key:"addEvt",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.expOrFn,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.name;t="function"==typeof t?t:this.vm.methods[t].bind(this.vm);b.addEvt(this.node,e,t)}},{key:"lasyCompile",value:function(){var t=this;this.compiler.compileChild(this.node);var e=document.createTextNode("");this.node.parentNode.insertBefore(e,this.node),this.node.parentNode.removeChild(this.node);m.registDomListener4Hubs(function(n,i){b.lasyCompile(t.node,t.domPropOrEvt,n,i,e)},this.expOrFn,this.vm)}}]),t}(),g=function(t){function n(){return e(this,n),o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this))}return r(n,O),n}(),_=function(t){function n(){return e(this,n),o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this))}return r(n,O),n}(),k=function(){function t(n){e(this,t),this.name=n.name,this.vm=n.vm,this.node=n.node}return n(t,[{key:"bind",value:function(t){m.registDomListener4Hubs(t,this.exp,this.vm)}}]),t}(),w=function(t){function s(t){e(this,s);var n=o(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t));return n.exp=t.expOrFn,n.prop="value",n}return r(s,k),n(s,[{key:"bind",value:function(){var t=this;i(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"bind",this).call(this,function(e){t.node[t.prop]=e}),this.addEvt()}},{key:"addEvt",value:function(){var t=this;this.node.addEventListener("input",function(e){return t.vm[t.exp]=e.target.value},!1)}}]),s}(),j=function(t){function s(t){e(this,s);var n=o(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t));return n.exp=t.expOrFn,n.compiler=t.compiler,n}return r(s,k),n(s,[{key:"bind",value:function(){var t=this;this.compiler.compileChild(this.node);var e=document.createTextNode(""),n=this.node.parentNode;n.insertBefore(e,this.node),n.removeChild(this.node);i(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"bind",this).call(this,function(i){i?n.insertBefore(t.node,e):n.removeChild(t.node)})}}]),s}(),P=function(t){function n(){return e(this,n),o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this))}return r(n,O),n}(),T=function(t){function n(){return e(this,n),o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this))}return r(n,O),n}(),E=function(t){function s(t){e(this,s);var n=o(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t));return n.exp=t.expOrFn,n.prop="innerHTML",n}return r(s,k),n(s,[{key:"bind",value:function(){var t=this;i(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"bind",this).call(this,function(e){t.node[t.prop]=e})}}]),s}(),C=function(t){function n(){return e(this,n),o(this,(n.__proto__||Object.getPrototypeOf(n)).call(this))}return r(n,O),n}();var F=function(){function t(n,i){e(this,t),this.vm=i,this.el=document.querySelector(n),this.el.appendChild(this.init())}return n(t,[{key:"init",value:function(){var t=document.createDocumentFragment(),e=this.fillFrag(t);return this.compileChild(e),t}},{key:"fillFrag",value:function(t){for(var e=0;e<this.el.childNodes.length;e++){var n=this.el.childNodes[e];this.isValidType(n)&&(t.appendChild(n),--e)}return t}},{key:"compileChild",value:function(t){var e=this;t.childNodes.forEach(function(t){e.compileNode(t)})}},{key:"compileNode",value:function(t){1===t.nodeType?this.compileElement(t):3===t.nodeType&&this.compileText(t)}},{key:"compileElement",value:function(t){var e,n=this,i={isLasy:!1,type:"",exp:""};Array.from(t.attributes).forEach(function(r){var o=r.nodeName,s=y.checkDirective(o,n.vm.configs),u=s.prefix,c=s.directive,a=r.nodeValue;if(c){t.removeAttribute(o);var l=function(t,e){var n;switch(t){case":":n=new g(e);break;case"@":n=new _(e);break;case"model":n=new w(e);break;case"if":n=new j(e);break;case"for":n=new P(e);break;case"text":n=new T(e);break;case"html":n=new E(e);break;case"show":n=new C(e)}return n}(c,{name:c,expOrFn:a,node:t,vm:n.vm,compiler:n});u===n.vm.configs.evtPrefix?l.addEvt():"if"===c||"for"===c?(i={isLasy:!0,type:c,exp:a},e=l):l.bind()}}),i.isLasy?e.bind():this.compileChild(t)}},{key:"compileText",value:function(t){if(y.isExpression(t.data)){var e=y.expressionKey(t.data),n=s(e,4),i=n[1],r=n[2],o=n[3];new Directive({name:"text",expOrFn:r,node:t,preTxt:i,nxtTxt:o,vm:this.vm}).bind()}}},{key:"isValidType",value:function(t){return 1===t.nodeType||8===t.nodeType||3===t.nodeType&&!this.isPureBlankNode(t)}},{key:"isPureBlankNode",value:function(t){return!/[^\t\n\r ]/.test(t.data)}}]),t}();return function t(n){var i=n.el,r=void 0===i?"":i,o=n.data,l=void 0===o?{}:o,p=n.computeds,d=void 0===p?{}:p,y=n.methods,m=void 0===y?{}:y,b=n.watchers,x=void 0===b?{}:b,O=n.configs;e(this,t),this.methods=m,function(t,e){e.configs=Object.assign(a,t)}(O,this),v(l,this),this.computeds=d,function(t,e){var n=!0,i=!1,r=void 0;try{for(var o,u=Object.entries(t)[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var c=o.value,a=s(c,2),l=a[0],f=a[1];Object.defineProperty(e,l,{configurable:!1,enumerable:!0,get:"function"===h(f)?f:"object"===h(f)?f.get:function(){},set:"object"===h(f)?f.set:function(){}})}}catch(t){i=!0,r=t}finally{try{!n&&u.return&&u.return()}finally{if(i)throw r}}}(d,this),this.watchers=x,function(t,e){var n=!0,i=!1,r=void 0;try{for(var o,a=Object.entries(t)[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var l=o.value,h=s(l,2),p=h[0],d=h[1];c.listener=new f(e,p,d),u(p,e),c.listener=null}}catch(t){i=!0,r=t}finally{try{!n&&a.return&&a.return()}finally{if(i)throw r}}}(x,this),new F(r,this)}});