yzms/umeditor/third-party/template.min.js

9 lines
12 KiB
JavaScript
Raw Normal View History

2024-04-01 15:54:27 +08:00
/**
* ETPL (Enterprise Template)
* Copyright 2013 Baidu Inc. All rights reserved.
*
* @file 模板引擎
* @author errorrik(errorrik@gmail.com)
* otakustay(otakustay@gmail.com)
*/
!function(t){function e(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function n(){this.raw=[],this.length=0}function r(){return"___"+I++}function i(t,n){var r=t.prototype,i=new Function;i.prototype=n.prototype,t.prototype=new i,t.prototype.constructor=t,e(t.prototype,r)}function o(t){return D[t]}function s(t){return'"'+t.replace(/\x5C/g,"\\\\").replace(/"/g,'\\"').replace(/\x0A/g,"\\n").replace(/\x09/g,"\\t").replace(/\x0D/g,"\\r")+'"'}function a(t){return t.replace(/[\^\[\]\$\(\)\{\}\?\*\.\+]/g,function(t){return"\\"+t})}function p(t){var e=arguments;return t.replace(/\{([0-9]+)\}/g,function(t,n){return e[n-0+1]})}function h(t){return t=t.replace(/^\s*\*/,""),p('gv({0},["{1}"])',s(t),t.replace(/\[['"]?([^'"]+)['"]?\]/g,function(t,e){return"."+e}).split(".").join('","'))}function c(t,e,n,r,i,o){for(var s=n.length,a=t.split(e),p=0,h=[],c=0,l=a.length;l>c;c++){var u=a[c];if(c){var f=1;for(p++;;){var d=u.indexOf(n);if(0>d){h.push(p>1&&f?e:"",u);break}if(p=r?p-1:0,h.push(p>0&&f?e:"",u.slice(0,d),p>0?n:""),u=u.slice(d+s),f=0,0===p)break}0===p&&(i(h.join("")),o(u),h=[])}else u&&o(u)}p>0&&h.length>0&&(o(e),o(h.join("")))}function l(t,e,n){var r,i=[],o=e.options,a="",p="",u="",f="";return n&&(a="ts(",p=")",u=S,f=z,r=o.defaultFilter),c(t,o.variableOpen,o.variableClose,1,function(t){n&&t.indexOf("|")<0&&r&&(t+="|"+r);var o=t.indexOf("|"),s=(o>0?t.slice(0,o):t).replace(/^\s+/,"").replace(/\s+$/,""),c=o>0?t.slice(o+1):"",d=0===s.indexOf("*"),g=[d?"":a,h(s),d?"":p];if(c){c=l(c,e);for(var y=c.split("|"),v=0,m=y.length;m>v;v++){var w=y[v],R=w.match(/^\s*([a-z0-9_-]+)(\((.*)\))?\s*$/i);R&&(g.unshift('fs["'+R[1]+'"]('),R[3]&&g.push(",",R[3]),g.push(")"))}}i.push(u,g.join(""),f)},function(t){i.push(u,n?s(t):t,f)}),i.join("")}function u(t,e){this.value=t,this.engine=e}function f(t,e){this.value=t,this.engine=e,this.children=[],this.cloneProps=[]}function d(t,e){var n=t.stack,r=e?n.find(function(t){return t instanceof e}):n.bottom();if(r){for(var i;(i=n.top())!==r;){if(!i.autoClose)throw new Error(i.type+" must be closed manually: "+i.value);i.autoClose(t)}r.close(t)}return r}function g(t,e){var n=t.match(/^\s*([a-z0-9\/\._-]+)\s*(\(\s*master\s*=\s*([a-z0-9\/\._-]+)\s*\))?\s*/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.master=n[3],this.name=n[1],f.call(this,t,e),this.blocks={}}function y(t,e){var n=t.match(/^\s*([a-z0-9\/\._-]+)\s*$/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.name=n[1],f.call(this,t,e),this.cloneProps=["name"]}function v(t,e){var n=t.match(/^\s*([a-z0-9\/\._-]+)\s*$/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.name=n[1],f.call(this,t,e),this.cloneProps=["name","state","blocks","target"],this.blocks={}}function m(t,e){var n=t.match(/^\s*([a-z0-9_]+)\s*=([\s\S]*)$/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.name=n[1],this.expr=n[2],f.call(this,t,e),this.cloneProps=["name","expr"]}function w(t,e){var n=t.match(/^\s*([a-z0-9_-]+)\s*(\(([\s\S]*)\))?\s*$/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.name=n[1],this.args=n[3],f.call(this,t,e),this.cloneProps=["name","args"]}function R(t,e){var n=t.match(/^\s*([a-z0-9\/\._-]+)\s*(\(([\s\S]*)\))?\s*$/i);if(!n)throw new Error("Invalid "+this.type+" syntax: "+t);this.name=n[1],this.args=n[3],f.call(this,t,e),this.cloneProps=["name","args"]}function E(t,e){var n=new RegExp(p("^\\s*({0}[\\s\\S]+{1})\\s+as\\s+{0}([0-9a-z_]+){1}\\s*(,\\s*{0}([0-9a-z_]+){1})?\\s*$",a(e.options.variableOpen),a(e.options.variableClose)),"i"),r=t.match(n);if(!r)throw new Error("Invalid "+this.type+" syntax: "+t);this.list=r[1],this.item=r[2],this.index=r[4],f.call(this,t,e),this.cloneProps=["list","item","index"]}function b(t,e){f.call(this,t,e)}function x(t,e){b.call(this,t,e)}function k(t,e){f.call(this,t,e)}function A(t,e){e.target=t;var n=e.engine,r=t.name;if(n.targets[r])switch(n.options.namingConflict){case"override":n.targets[r]=t,e.targets.push(r);case"ignore":break;default:throw new Error("[ETPL_TARGET_EXISTS]"+r)}else n.targets[r]=t,e.targets.push(r)}function C(t,e,n){t.command