mutorjs 1.3.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +21 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/mutor.global.js +10 -6
- package/dist/mutor.global.js.map +1 -1
- package/dist/server.cjs +17 -10
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +6 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.js +17 -10
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import{readFileSync as be}from"fs";import{copyFile as Re,mkdir as Pe,readdir as de,readFile as
|
|
1
|
+
import{readFileSync as be}from"fs";import{copyFile as Re,mkdir as Pe,readdir as de,readFile as Se,writeFile as xe}from"fs/promises";import{extname as me,join as ee}from"path";function Z(e,r){return`${" ".repeat(e+r)}^`}var g=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},M=class e extends g{constructor(t,s,o,c,p){let m=s.toString().length+2,i=`${t}
|
|
2
2
|
|
|
3
|
-
`;
|
|
4
|
-
`,
|
|
5
|
-
`),
|
|
6
|
-
`,
|
|
3
|
+
`;i+=`at ${p}:${s}:${c+1}
|
|
4
|
+
`,s>1&&(i+=`${(s-1).toString().padStart(m-2)} | ...
|
|
5
|
+
`),i+=`${s} | ${o}
|
|
6
|
+
`,i+=Z(c,m+1);super(i);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ne=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),z=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var oe=new Set(["==","!="]),V=new Set([">","<",">=","<="]);var se=new Set(["+","-"]),ie=new Set(["*","/","%"]),ae=new Set([".","?.","[","::"]),ce=new Set(["-","+","!"]),pe={"&":"&","<":"<",">":">",'"':""","'":"'"},R={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,onIncludeFail:"throw",cache:{active:!0,maxSize:50*1024*1024}},le={JSON:{stringify(e){try{return JSON.stringify(e)}catch{throw new g("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new g("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new g("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new g("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new g("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new g("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new g("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new g("Object::fromEntries expects an array");return Object.fromEntries(e)}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)}},String:{fromCharCode(...e){return String.fromCharCode(...e)}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new g("Date::parse expects a string");return Date.parse(e)}},Boolean:{valueOf(e){return!!e}}};function F(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>pe[r]):e}import{dirname as Ee,isAbsolute as ye,resolve as ue}from"path";function A(e,...r){let t=ye(e)?e:ue(process.cwd(),e);if(r.length){let s=Ee(t);return ue(s,...r)}return t}function D(e,r,t){if(t.has(e)&&!r.has(e))throw new g(`Forbidden property access.
|
|
7
|
+
Access to this computed property '${e}' is forbidden.`);return e}var B="object",fe=Symbol("__mutor_safe_context");function L(e){if(!e||typeof e!==B||fe in e)return e;let r=new WeakSet;function t(o,c=""){if(!o||typeof o!==B||r.has(o))return o;r.add(o);let p=Object.getPrototypeOf(o);if(p&&p!==Object.prototype&&p!==Array.prototype)throw new g(`Unsafe prototype detected at ${c||"root"} in context.`);if(Array.isArray(o)){for(let i=0;i<o.length;i++)o[i]=t(o[i],`${c}[${i}]`);return o}if(o instanceof Map){for(let[i,l]of o.entries())typeof i===B&&t(i,`${c}.mapKey`),o.set(i,t(l,`${c}.mapValue`));return o}if(o instanceof Set){let i=new Set;for(let l of o.values())i.add(t(l,c));o.clear();for(let l of i)o.add(l);return o}let m=Object.getOwnPropertyDescriptors(o);for(let i of Object.keys(m)){let l=m[i];if(l.get||l.set)throw new g(`Getter/setter not allowed at '${c}.${i}' in context.`);let d=o[i];d&&typeof d===B&&(o[i]=t(d,`${c}.${i}`))}return o}let s=t(e);return s&&typeof s===B&&Object.defineProperty(s,fe,{value:!0,enumerable:!1,writable:!1,configurable:!1}),s}function $(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function U(e,r){let s=e.slice(0,r).split(`
|
|
7
8
|
`).length,o=e.lastIndexOf(`
|
|
8
|
-
`,r-1)+1;return[
|
|
9
|
-
`,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function
|
|
10
|
-
Expected end of expression
|
|
9
|
+
`,r-1)+1;return[s,o]}function W(e,r){let t=e.indexOf(`
|
|
10
|
+
`,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function j(e,r){let{scope:t,forbiddenProps:s,allowedProps:o}=r;function c(a){return t.includes(a)?a:`ctx.${a}`}function p(a){switch(a.type){case 17:return"}";case 5:return a.value;case 4:return`\`${/\$\\/.test(a.value)?$(a.value):a.value}\``;case 10:return a.true?"true":"false";case 12:return"null";case 11:return"undefined";case 7:return c(a.value);case 9:return`(${p(a.expr)})`;case 2:return`${a.operator}${p(a.expr)}`;case 0:return`${p(a.left)} ${a.operator} ${p(a.right)}`;case 1:return`${p(a.condition)} ? ${p(a.left)} : ${p(a.right)}`;case 8:return i(a);case 3:return l(a);case 6:return m(a);case 13:return d(a);case 16:return"} else {";case 14:return _(a);case 15:return E(a);default:throw new g(`Unsupported expression type '${a.type}'`)}}function m(a){if(a.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:a.pos};return`namespaces.${a.left.value}.${a.right.value}`}function i(a){let w=p(a.left);if(a.bracketNotation){let h=p(a.right),O=a.optional?"?.":"";return a.right.type===4||a.right.type===5?`${w}${O}[${h}]`:`${w}${O}[validateComputedProps(${h}, allowedProps, forbiddenProps)]`}else{let h=a.right.value,O=a.optional?"?.":".";if(s.has(h)&&!o.has(h))throw{message:"Forbidden property access.",pos:a.right.pos};return`${w}${O}${h}`}}function l(a){let w=p(a.expr),h=a.optional?"?.":"",O=a.args.map(P=>p(P)).join(", ");return`${w}${h}(${O})`}function d(a){let{iterable:w,loopType:h,variable:O}=a;return`for(const ${O} ${h===1?"in":"of"} ${j(w,r)}){`}function _(a){let{condition:w}=a;return`if(${j(w,r)}){`}function E(a){let{condition:w}=a;return`}else if(${j(w,r)}){`}return p(e)}function Y(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function H(e,r){let t=0,s=!1;function o(n,u){let f=e[t],x=e[e.length-1];if(!f)throw{message:`Unexpected end of expression. Expected ${u?`'${u}'`:`${n===0?"an":"a"} ${Y(n)}`}.`,pos:x.pos+x.value.length-1};if(f.type!==n)throw{message:`Unexpected token type. Expected ${u?`'${u}'`:Y(n)} but got ${Y(f.type)} instead.`,pos:f.pos};if(u!==void 0&&f.value!==u)throw{message:`Unexpected token '${f?.value}'. Expected ${n===0?"an":"a"} ${Y(n)} instead.`,pos:f.pos};return e[t++]}function c(){let n=e[t-1].pos,u=o(0).value,f;try{f=o(1,"in")}catch{f=o(1,"of")}let x=f.value==="in"?1:0,v=b();return{type:13,loopType:x,iterable:v,variable:u,pos:n}}function p(){let n=b();return{condition:n,pos:n.pos,type:14}}function m(){let n=e[t-1].pos;try{return o(1,"if"),{...p(),type:15,pos:n}}catch{return{type:16,pos:n}}}function i(){let n=[];if(e[t]?.type===4&&e[t]?.value===")")return n;for(n.push(b());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,n.push(b());return n}function l(){let n=e[t++];if(n?.type===2)return{type:5,value:n.value,pos:n.pos};if(n?.type===3)return{type:4,value:n.value,pos:n.pos};if(n?.type===1){if(n.value==="for"&&t===1)return c();if(n.value==="true"||n.value==="false")return{type:10,true:n.value==="true",pos:n.pos};if(n.value==="undefined")return{type:11,pos:n.pos};if(n.value==="null")return{type:12,pos:n.pos};if(n.value==="end"&&e.length===1)return{type:17,pos:n.pos};if(n.value==="if"&&t===1)return p();if(n.value==="else"&&t===1)return m()}if(n?.type===0)return{type:7,value:n.value,pos:n.pos};if(n?.type===4&&n.value==="("){let u=b();return o(4,")"),{type:9,expr:u,pos:n.pos}}if(n?.type===4&&ce.has(n.value)){let u=n.value,f=b();return{type:2,operator:u,expr:f,pos:n.pos}}throw t>e.length?{message:"Unexpected end of expression.",pos:e[e.length-1].pos}:{message:`Unexpected token '${n?.value}'.`,pos:n.pos}}function d(){let n=l();for(;e[t];){let u=e[t];if(u?.type===4&&u?.value==="("){if(t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let f=i();o(4,")"),n={type:3,expr:n,args:f,pos:e[t-1].pos}}else if(u?.type===4&&u?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let f=i();o(4,")"),n={type:3,expr:n,args:f,optional:!0,pos:e[t-1].pos}}else if(u?.type===4&&ae.has(u?.value)){let f=u?.value==="::",x=u?.value==="[",v=u?.value==="?.";if(t++,f&&(e[t-2]?.type!==0||e[t]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e[t-2]?.value}::${e[t]?.value??""}' instead.`,pos:e[t]?.pos??e[t-1].pos};if(f){s=!0;let S=l();n={type:6,left:n,right:S,pos:e[t-1].pos}}else if(x){let S=b();o(4,"]"),n={type:8,right:S,left:n,bracketNotation:!0,pos:e[t-1].pos}}else if(v)if(e[t]?.type===4&&e[t]?.value==="["){t++;let S=b();o(4,"]"),n={type:8,left:n,right:S,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let S=l();n={type:8,left:n,right:S,optional:!0,pos:e[t-1].pos}}else{let S=l();n={type:8,left:n,right:S,pos:e[t-1].pos}}}else break}return s=!1,n}function _(){let n=d();for(;e[t]?.type===4&&ie.has(e[t]?.value);){let u=e[t++].value,f=d();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function E(){let n=_();for(;e[t]?.type===4&&se.has(e[t]?.value);){let u=e[t++].value,f=_();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function a(){let n=E();for(;e[t]?.type===4&&V.has(e[t]?.value);){let u=e[t++].value,f=E();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function w(){let n=a();for(;e[t]?.type===4&&V.has(e[t]?.value);){let u=e[t++].value,f=a();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function h(){let n=w();for(;e[t]?.type===4&&oe.has(e[t]?.value);){let u=e[t++].value,f=w();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function O(){let n=P();for(;e[t]?.type===4&&e[t]?.value==="||";){let u=e[t++].value,f=P();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function P(){let n=I();for(;e[t]?.type===4&&e[t]?.value==="&&";){let u=e[t++].value,f=I();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function I(){let n=h();for(;e[t]?.type===4&&e[t]?.value==="??";){let u=e[t++].value,f=h();n={type:0,left:n,right:f,operator:u,pos:e[t-1].pos}}return n}function b(){let n=O();if(e[t]?.type!==4||e[t]?.value!=="?")return n;t++;let u=b();o(4,":");let f=b();return{type:1,left:u,right:f,condition:n,pos:e[t-1].pos}}let J=b();if(t!==e.length)throw{pos:e[t].pos,message:`Expected token '${e[t].value}'.
|
|
11
|
+
Expected an operator or the end of the expression.`};return J}function Q(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,s=`${r.whitespaceTrim}${r.closingTag}`,o=e.startsWith(t),c=e.endsWith(s),p=e.startsWith(o?t+r.commentTag:r.openingTag+r.commentTag);if(p)return{isComment:p,leftTrim:o,rightTrim:c};let m=e.slice(o?t.length:r.openingTag.length,e.length-(c?s.length:r.closingTag.length)),i=m.trim(),l=i.startsWith("for")||i.startsWith("if")||i.startsWith("else"),d=i.startsWith("for")||i.startsWith("if"),_=i==="end",E=i.startsWith("for");return{leftTrim:o,rightTrim:c,inner:m,isBlock:l,isBlockEnd:_,hasContext:E,requiresBlockClose:d}}function X(e){let r=0,t="",s=[];function o(){let i="";if(/[a-zA-Z$_]/.test(t)){let l=r;for(;/[a-zA-Z$_0-9]/.test(e[l])&&l<e.length;)i+=e[l],l++;s.push({type:ne.has(i)?1:0,value:i,pos:r}),r=l,t=e[r]}}function c(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let i=t,l=r,d=r+1,_="";for(;d<e.length;){let E=e[d];if(E==="\\"){if(d+1>=e.length)throw{pos:d,message:"Unexpected end of string after escape character."};_+=E,_+=e[d+1],d+=2;continue}if(E===i)break;_+=E,d++}if(d>=e.length||e[d]!==i)throw{pos:l,message:`String literal missing closing ${i}.`};s.push({type:3,value:_,pos:l}),r=d}function p(){if(/[0-9]/.test(t)){let i=r,l="";for(;/[0-9.oxe]/.test(e[i])&&i<e.length;)l+=e[i],i++;let d=Number(l);if(Number.isNaN(d))throw{pos:r,message:"Found invalid number literal."};s.push({type:2,value:`${d}`,pos:r}),r=i-1,t=e[r]}}function m(){let i=`${t}${e[r+1]}`;if(z.has(i)){s.push({type:4,value:i,pos:r}),r++;return}if(z.has(t)){s.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],p(),o(),c(),m(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!z.has(t)&&!z.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return s.length?s:[{type:3,value:"",pos:0}]}function k(e,r,t){let s=[],o=[],{delimiters:c,keepOpeningTagEscapeDelimiter:p,allowFnCalls:m,allowedProps:i,forbiddenProps:l,autoEscape:d}=r,_=!1,E=0,a='let acc="";';for(;E<e.length;){let O=function(){let y=h,N=0;for(;y>=c.openingTagEscape.length&&e.slice(y-c.openingTagEscape.length,y)===c.openingTagEscape;)N++,y-=c.openingTagEscape.length;return N%2===1};var w=O;let h=e.indexOf(c.openingTag,E);if(h===-1){let y=e.slice(E);_&&(y=y.trimStart()),y&&(a+=`acc+=\`${$(y)}\`;`);break}if(O()){let y=e.slice(E,p?h+c.openingTagEscape.length+1:h-c.openingTag.length+1);_&&(y=y.trimStart(),_=!1),a+=`acc+=\`${$(y)}\`;`,p||(a+=`acc+=\`${c.openingTag}\`;`),E=h+c.openingTag.length;continue}let P=e.indexOf(c.closingTag,h);if(P===-1){let[y,N]=U(e,h),C=W(e,N);throw new M("No closing tag found.",y,C,h,t.path)}let I=e.slice(h,P+c.closingTag.length),{inner:b,leftTrim:J,rightTrim:n,isBlock:u,isBlockEnd:f,hasContext:x,requiresBlockClose:v,isComment:S}=Q(I,{delimiters:c}),T=e.slice(E,h);T&&(_&&(T=T.trimStart()),J&&(T=T.trimEnd()),T&&(a+=`acc+=\`${$(T)}\`;`)),_=!1,E=P+c.closingTag.length;try{if(!S){let y=X(b),N=H(y,{allowFnCalls:m});if(u&&v&&x?(s.push(N.variable),o.push({type:0,pos:h})):u&&v&&!x&&o.push({type:1,pos:h}),f){let q=o.pop();if(q?.type===0&&s.pop(),q===void 0)throw{message:"Unexpected end of block",pos:h}}let C=j(N,{allowedProps:i,forbiddenProps:l,scope:s});u||f?a+=C:a+=d&&!C.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${C});`:`acc+=${C};`}n&&(_=!0)}catch(y){let{message:N,pos:C}=y,q=J?c.whitespaceTrim.length+c.openingTag.length:c.openingTag.length,te=h+C+q,[ge,re]=U(e,te),_e=W(e,re);throw new M(N,ge,_e,te-re,t.path)}}if(o.length){let h=o.pop()?.pos,[O,P]=U(e,h),I=W(e,P);throw new M("Unclosed block detected.",O,I,h-P,t.path)}return a+="return acc;",new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",a)}var G=class{constructor(r={}){this.__currentRenderedPath="";this.__includeStack=new Set;this.__cacheSize=0;this.__config={...R};this.__compiledTemplatesMap=new Map;this.__currentContext=null;this.__namespaces={...le,Mutor:{include:(r,t)=>{if(this.__includeStack.has(r))throw new g(`Circular include detected.
|
|
11
12
|
${Array.from(this.__includeStack).join(`
|
|
12
13
|
`)}
|
|
13
|
-
${r}`);
|
|
14
|
+
${r}`);let s=this.__currentRenderedPath,o=`[Mutor.js]
|
|
15
|
+
Component '${r}' not found.
|
|
16
|
+
The component was included from ${`'${s}'`||"an anonymous component"}.
|
|
17
|
+
`;try{return this.__includeStack.add(r),this.renderComponent(r,t??this.__currentContext)}catch(c){if(this.__config.onIncludeFail==="throw")throw new g(o);let p={from:s,path:r,absolutePath:void 0};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&console.log(o),this.__config.onIncludeError?.(p,c)??""}finally{this.__includeStack.delete(r),this.__currentRenderedPath=s}}}};this.addConfig(r),Object.defineProperty(this.__namespaces.Mutor,"$$context",{get:()=>this.__currentContext})}addConfig(r){let{autoEscape:t,delimiters:s,allowedProps:o,forbiddenProps:c,keepOpeningTagEscapeDelimiter:p,allowFnCalls:m,cache:i,build:l,onIncludeFail:d,onIncludeError:_}=r;return this.__config={build:{include:new Set([...l?.include||R.build.include]),exclude:new Set([...R.build.exclude,...l?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:o||R.allowedProps,allowFnCalls:!!m,onIncludeFail:d||R.onIncludeFail,onIncludeError:_||R.onIncludeError,cache:{...R.cache,...i||{}},forbiddenProps:new Set([...R.forbiddenProps,...c||[]]),keepOpeningTagEscapeDelimiter:p===!0?!0:p!==!1,delimiters:{...R.delimiters,...s||{}}},this.__config}restoreDefaultConfig(){this.__config={...R}}compile(r){return k(r,this.__config,{path:this.__currentRenderedPath||"anonymous"})}render(r,t){let s=this.__currentContext;s!==t&&(this.__currentContext=t);let o=this.compile(r)(L(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=s,o}renderComponent(r,t){if(!this.__compiledTemplatesMap.has(r))throw new g(`No template exists with the identifier '${r}'`);let s=this.__currentRenderedPath,o=this.__currentContext,c=this.__compiledTemplatesMap.get(r);this.__currentContext=t,this.__currentRenderedPath=r;let p=c.fn(L(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=o,this.__currentRenderedPath=s,p}registerComponent(r,t){let s=t.length*2+500;if(this.__cacheSize+s>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(s))throw new g(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t),size:s})}reset(){this.__config={...R},this.__compiledTemplatesMap.clear(),this.__currentContext=null,this.__cacheSize=0}createEntrySpaceForTemplate(r){if(this.__cacheSize+r<this.__config.cache.maxSize)return!0;if(r>this.__config.cache.maxSize)return!1;let t=this.__compiledTemplatesMap.entries().next().value;if(t){let[s,o]=t;this.__compiledTemplatesMap.delete(s),this.__cacheSize-=o.size}return this.createEntrySpaceForTemplate(r)}getDiagnostics(){let r=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:r,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(r/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:r>0?Math.min(100,Math.round(this.__cacheSize/r*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}};var K=class extends G{constructor(r={}){super(r),this.__namespaces.Mutor.include=(t,s)=>{let o=this.__currentRenderedPath,c=A(this.__currentRenderedPath,t),p=`[Mutor.js]
|
|
18
|
+
File '${c}' not found.
|
|
19
|
+
The file was included from ${`'${o}'`||"an anonymous template"}.
|
|
20
|
+
`;if(this.__includeStack.has(c))throw new g(`Circular include detected.
|
|
14
21
|
${Array.from(this.__includeStack).join(`
|
|
15
22
|
`)}
|
|
16
|
-
${
|
|
23
|
+
${c}`);try{return this.__includeStack.add(c),this.renderFile(c,s??this.__currentContext)}catch(m){if(this.__config.onIncludeFail==="throw")throw new g(p);return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&console.log(p),this.__config.onIncludeError?.({from:o,path:t,absolutePath:c},m)??""}finally{this.__includeStack.delete(c),this.__currentRenderedPath=o}}}renderFile(r,t){let s=A(r),o,c=this.__currentContext,p=this.__currentRenderedPath;if(this.__currentContext=t,this.__currentRenderedPath=r,this.__config.cache.active&&this.__compiledTemplatesMap.has(s))o=this.__compiledTemplatesMap.get(s).fn;else{let i=be(s,"utf-8");if(o=this.compile(i),this.__config.cache.active){let l=i.length*2+500;this.__cacheSize+l>this.__config.cache.maxSize?this.createEntrySpaceForTemplate(l)&&(this.__compiledTemplatesMap.set(s,{fn:o,size:l}),this.__cacheSize+=l):(this.__compiledTemplatesMap.set(s,{fn:o,size:l}),this.__cacheSize+=l)}}let m=o(L(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=c,this.__currentRenderedPath=p,m}async buildDir(r,t,s){let o=A(t),c=A(r);await Pe(o,{recursive:!0});let p=await de(c,{withFileTypes:!0});await Promise.all(p.map(async m=>{let i=ee(c,m.name),l=ee(o,m.name);if(this.__config.build.exclude.has(m.name))return;if(m.isDirectory())return this.buildDir(i,l,s);let d=me(i);if(this.__config.build.include.has(d)){let _=this.renderFile(i,s);await xe(l,_,"utf-8")}else return await Re(i,l)}))}async compileDir(r){let t=A(r),s=await de(t,{withFileTypes:!0});await Promise.all(s.map(async o=>{let c=ee(t,o.name);if(this.__config.build.exclude.has(o.name))return;if(o.isDirectory())return this.compileDir(c);let p=me(c);if(this.__config.build.include.has(p))try{let m=await Se(c,"utf-8");this.registerComponent(c,m)}catch{}}))}};var vt=K;export{vt as default};
|
|
17
24
|
//# sourceMappingURL=server.js.map
|