This repository was archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrexjs-template-unhelper.min.js
1 lines (1 loc) · 12.1 KB
/
rexjs-template-unhelper.min.js
1
!function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e){(function(t){"use strict";var e=new t.ObjectDestructuringTarget(new function(e,i,r,s,o,a,c,u,l,p,h){this.Reference=function(e,n){return t.Class.create(void 0,[new t.ClassProperty("owner",null),new t.ClassProperty("name",""),new t.ClassProperty("value",null),new t.ClassProperty("constructor",function(t,e,n){this.bind(t,e,n)}),new t.StaticProperty("add",function(t){e.push(t)}),new t.StaticProperty("is",function(t){return!e.every(n,t)}),new t.ClassProperty("bind",function(t,e,n){return(t!==this.owner||e!==this.name||n!==this.value)&&(this.owner=t,this.name=e,this.value=n,!0)})],3)}(("function"==typeof $&&$.fn&&$.fn.constructor?[$.fn.constructor]:[]).concat([Node,Function]),function(t){return!(this instanceof t)}),this.Data=function(e,n,i,r){return t.Class.create(void 0,[new t.StaticProperty("STATUS_NONE",n),new t.StaticProperty("STATUS_OVERRIDE",i),new t.ClassProperty("origin",null),new t.ClassProperty("refs",null),new t.ClassProperty("refIndex",-1),new t.ClassProperty("status",n),new t.ClassProperty("string",""),new t.ClassProperty("constructor",function(t){null!==t&&"object"==typeof t||(t={}),this.refs=[],this.origin=t}),new t.ClassProperty("compare",function(){var t,e,r=this.refs;return this.refIndex=0,this.status=n,t=this.parse(this.origin),e=this.refIndex,e!==r.length&&(r.splice(e),this.status|=i),this.string!==t&&(this.string=t,this.status|=i),(this.status&i)===i}),new t.ClassProperty("parse",function(n){var s="",o=r(n);s+="{";for(var a=0,c=o.length;a<c;a++){var u=o[a],l=n[u];switch(s+='"'+u+'":',typeof l){case"object":if(e.is(l))break;s+=this.parse(l),s+=",";continue;case"function":break;default:s+='"'+l+'",';continue}var p=new t.ObjectDestructuringTarget(this),h=p.get("refs"),f=p.get("refIndex");this.refIndex++,f<h.length?h[f].bind(n,u,l)&&(this.status|=i):(h.push(new e(n,u,l)),this.status|=i),s+='"",'}return s+="}"})],7)}(this.Reference,parseInt("0",2),parseInt("1",2),Object.keys),this.DOMAction=e=function(e,n,i){return t.Class.create(void 0,[new t.ClassProperty("childIndexes",null),new t.ClassProperty("clones",null),new t.ClassProperty("count",0),new t.ClassProperty("index",-1),new t.ClassProperty("indexOf",-1),new t.ClassProperty("indexBy",-1),new t.ClassProperty("model",null),new t.ClassProperty("constructor",function(t){this.childIndexes=[],this.clones=[],this.model=t}),new t.ClassProperty("applyAppendTo",function(t,e){var r=this.clones,s=t[e];if(this.count>=r.length){var o=this.model.cloneNode();n(o,t,s),r.push(o)}else i(this,t,s);s.indexBy=this.indexOf,this.count++}),new t.ClassProperty("applyAttr",function(t,e){var n=this.dom.attributes[t];n.value!==e&&(n.value=e)}),new t.ClassProperty("applyEvent",function(t,e){var n=this.dom;n[t]!==e&&(n[t]=e)}),new t.ClassProperty("applyReplace",function(t){var n=this.dom;n!==t&&(!(t instanceof e)&&t.length>0&&(t=t[0]),this.clones.splice(this.count-1,1,t),n.parentNode.replaceChild(t,n))}),new t.ClassProperty("applyText",function(t){var e=this.dom;e.textContent!==t&&(e.textContent=t)}),new t.ClassProperty("dom",function(){return this.clones[this.count-1]},"get"),new t.ClassProperty("finish",function(){var t=this.clones,e=this.count;switch(t.length){case 0:case e:break;default:t.splice(e).forEach(l)}this.count=0,this.indexBy=-1})],7)}(Node,function(e,n,i){return function(){var r=new t.ObjectDestructuringTarget(i),s=r.get("dom"),o=r.get("indexBy");if(o>-1){var a=n[i.childIndexes[o]].dom.nextSibling;if(a)return void s.insertBefore(e,a)}s.appendChild(e)}.apply(this[0],this[1])}.bind([this,arguments]),function(e,n,i){return function(){var r=new t.ObjectDestructuringTarget(e),s=r.get("indexOf"),o=r.get("count"),a=r.get("clones");if(e.index>1&&!n[1].dom.contains(a[o]))return void a.splice(o,1);if(0!==s)for(var c=i.indexBy;s>++c;){var u=new t.ObjectDestructuringTarget(n[i.childIndexes[c]]),p=u.get("clones"),h=u.get("count");p.length&&l(p.splice(h,1)[0])}}.apply(this[0],this[1])}.bind([this,arguments])),this.FragmentAction=function(n){var r;return r=t.Class.create(e,[new t.ClassProperty("constructor",function(){return t.Super.callConstructor(r.prototype,this,[a.createDocumentFragment()])}),new t.ClassProperty("dom",function(){return this.model},"get"),new t.ClassProperty("count",function(){return 0},"get"),new t.ClassProperty("finish",function(){}),new t.ClassProperty("rootElement",function(){var t;return n.call(this.dom.childNodes,function(e){return function(){return e.nodeType!==i||(t=e,!1)}.apply(this[0],this[1])}.bind([this,arguments])),t},"get")],0)}(Array.prototype.every),this.ActionList=function(e,n){return t.Class.create(void 0,[new t.ClassProperty("length",0),new t.ClassProperty("finishAll",function(){this.forEach(function(t){return function(){t.finish()}.apply(this[0],this[1])}.bind([this,arguments]))}),new t.ClassProperty("forEach",function(){return u.apply(this,arguments)}),new t.ClassProperty("max",function(){return this.length-1},"get"),new t.ClassProperty("push",function(t,n){var i=this[n],r=this.length;if(t.index=r,i){var s=i.childIndexes;t.indexOf=s.length,s.push(r)}return e.call(this,t)}),new t.ClassProperty("splice",function(){return n.apply(this,arguments)}),new t.ClassProperty("constructor",function(){})],6)}(Array.prototype.push,Array.prototype.splice),this.ActionCompiler=function(e,n,r,s,o,a,c,l,f,d,y,w){return t.Class.create(void 0,[new t.ClassProperty("actionList",null),new t.ClassProperty("selectorMap",null),new t.ClassProperty("constructor",function(t,i,r){var s=new e;switch(r&&(this.selectorMap=r),this.actionList=s,c.innerHTML=this.format(t),c.children.length){case 0:return void p("模板中需要一个根元素",c);case 1:if(f(c,t))break;return;default:return void p("模板不应该存在多种(多个、循环、判断等)情况的根元素",t)}s.push(new n,-1),this.compile(c,i),c.innerHTML=""}),new t.ClassProperty("compile",function(t,e){var n=this.actionList,r=n.max;u.call(t.childNodes,function(t){return function(){if(t.nodeType!==i)return e.push(d(t.textContent)),void w(n,e,t,r);this.compileElement(t,e,r)}.apply(this[0],this[1])}.bind([this,arguments]))}),new t.ClassProperty("compileElement",function(t,e,n){var i=t.tagName;if("SCRIPT"===i&&"rexjs/template"===t.getAttribute("type"))return void this.compileScript(t.childNodes[0],e,t.getAttribute("data-modifier"),n);this.selectorMap&&(t.id&&(t.id=this.compileSelector(t.id)),t.className&&(t.className=this.compileSelectors(t.classList||t.className.match(o)))),w(this.actionList,e,t,n),e.push(d("<"+i.toLowerCase()+">")),u.call(t.attributes,function(n){return function(){this.compileAttr(t,n,e)}.apply(this[0],this[1])}.bind([this,arguments])),this.compile(t,e)}),new t.ClassProperty("compileAttr",function(t,e,n){var i,s,o=[];y(e.value,function(t,e,n){return function(){return"="===t&&(s=n,i=e,o.push(h(n),'" + valueOf('+e+') + "'),!0)}.apply(this[0],this[1])}.bind([this,arguments]),function(a){return function(){var c=e.name,u=this.actionList.max;if(r.test(c)&&2===o.length&&0===s.trim().length&&0===a.trim().length)return n.push("actionList["+u+'].applyEvent("'+c+'", '+i+");"),void t.removeAttribute(c);o.push(h(a)),n.push("actionList["+u+'].applyAttr("'+e.name+'", "'+o.join("")+'");')}.apply(this[0],this[1])}.bind([this,arguments]))}),new t.ClassProperty("compileSelector",function(t){var e,n=this.selectorMap;return e=t.replace(a,function(t){return t[1].toUpperCase()}),l.call(n,e)?n[e]:t}),new t.ClassProperty("compileSelectors",function(t){var e="";if(t){var n=t.length;if(n>0){e=this.compileSelector(t[0]);for(var i=1;i<n;i++)e+=" "+this.compileSelector(t[i])}}return e}),new t.ClassProperty("compileScript",function(t,e,n,i){var r=this.actionList,s=t.textContent;if(e.push(d(s)),n)return w(r,e,t,i),":"===n?void e.push("actionList["+r.max+"].applyReplace("+s+");"):void e.push("actionList["+r.max+"].applyText(valueOf("+s+"));");e.push(s)}),new t.ClassProperty("format",function(t){return t.replace(s,function(t,e,n){return void 0===n?t:n.trim()?'<script type="rexjs/template" data-modifier="'+e+'"}>'+n+"<\/script>":""})})],2)}(this.ActionList,this.FragmentAction,/^on[A-z]+$/,new RegExp([/<!--[\s\S]*?-->/,/<\/?[A-z:_](?:"(?:\\"|[^"]+)*"|'(?:\\'|[^']+)*'|[^>]+?)*>/,/<!doctype\s+\w+\s*>/,r].map(function(t){return function(){return t.source}.apply(this[0],this[1])}.bind([this,arguments])).join("|"),"g"),/\S+/g,/(?:-|_)\w/g,a.body,Object.prototype.hasOwnProperty,function(t,e){return function(){var n=t.firstElementChild;switch(!1){case t.textContent.trim()===n.textContent.trim():return p("根元素外层不应该出现非注释形式的其他文本",e),!1;case"SCRIPT"===n.tagName:case"rexjs/template"===n.getAttribute("type"):return!0}return p("语法标签不允许出现在最外层",e),!1}.apply(this[0],this[1])}.bind([this,arguments]),function(t){return function(){return 0===t.length?"/**/":"/* "+t.split("*/").join("*\\/")+" */"}.apply(this[0],this[1])}.bind([this,arguments]),function(t,e,n,i){return function(){var s,o=-1;for(r.lastIndex=0,s=r.exec(t);s;){var a=s.index;e(s[1],s[2],t.substring(o,a))&&(o=a+s[0].length),s=r.exec(t)}if(-1===o)return void(i&&i(t));n(t.substring(o))}.apply(this[0],this[1])}.bind([this,arguments]),function(t,n,i,r){return function(){t.push(new e(i),r),n.push("actionList["+t.max+"].applyAppendTo(actionList, "+r+");")}.apply(this[0],this[1])}.bind([this,arguments])),this.RexjsTemplate=window.RexjsTemplate=function(e,i,r,s,o,a,c,u,l,p){return t.Class.create(void 0,[new t.ClassProperty("actionList",null),new t.ClassProperty("data",null),new t.ClassProperty("renderer",null),new t.ClassProperty("constructor",function(t,e,n){var r;this.actionList=t,this.renderer=e,this.data=new i(n),this.render(),r=t[0].rootElement,r.rexjsTemplate=this,r.setAttribute("rex-template","")}),new t.StaticProperty("addRef",function(t){e.add(t)}),new t.StaticProperty("compile",function(t,e,i){var o=[],a=new r(t,o,i),c=a.actionList;return o.push("actionList.finishAll();"),new n(c,new s("actionList","valueOf",o.join("\n")),e),c[0].rootElement}),new t.StaticProperty("refresh",function(t){return l(!0,t)}),new t.StaticProperty("watch",function(){if(!a){var t=o.now();a=!0,t-c>50&&(l(!1),c=t),u(function(){return function(){a&&(this.unwatch(),this.watch())}.apply(this[0],this[1])}.bind([this,arguments]))}}),new t.StaticProperty("watching",function(){return a},"get"),new t.StaticProperty("unwatch",function(){a=!1}),new t.ClassProperty("render",function(t){var e=this.data;(t||e.compare())&&this.renderer.call(e.origin,this.actionList,p)})],3)}(this.Reference,this.Data,this.ActionCompiler,Function,Date,!1,-1,window.requestAnimationFrame||window.webkitRequestAnimationFrame||function(t){return function(){c(t,50)}.apply(this[0],this[1])}.bind([this,arguments]),function(e,n){return function(){var i=0;return u.call(s.querySelectorAll("[rex-template]"),function(r){return function(){var s=r.rexjsTemplate,a=!1;if(n)a=s.data.origin===n;else{var c=new t.ObjectDestructuringTarget(r.getBoundingClientRect()),u=c.get("top"),l=c.get("left"),p=c.get("height"),h=c.get("width");(u>=0?u<o.availHeight:u+p>0)&&(a=l>=0?l<o.availWidth:l+h>0)}a&&(s.render(e),i++)}.apply(this[0],this[1])}.bind([this,arguments])),i}.apply(this[0],this[1])}.bind([this,arguments]),function(t){return function(){return null==t?"":t.toString()}.apply(this[0],this[1])}.bind([this,arguments]))}(null,Node.ELEMENT_NODE,/<%([:=]?)([\s\S]*?)%>/g,document,screen,document.implementation.createHTMLDocument(""),setTimeout,Array.prototype.forEach,function(t){return function(){var e=t.parentNode;e&&e.removeChild(t),t.textCOntent=""}.apply(this[0],this[1])}.bind([this,arguments]),function(t,e){return function(){var n=e.split("\n").slice(0,5).join("\n");throw t+":\n`"+n+"\n"+(n===e?"":"...")+"`"}.apply(this[0],this[1])}.bind([this,arguments]),function(t){return function(){return t.split('"').join('\\"').split("\n").join("\\n")}.apply(this[0],this[1])}.bind([this,arguments]))),n=e.get("RexjsTemplate");t.Module.export("RexjsTemplate",n)}).call(this,Rexjs)}]);