solely 0.1.10 → 0.2.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.
@@ -1 +1 @@
1
- "use strict";var e=Object.defineProperty,n=(n,t,o)=>((n,t,o)=>t in n?e(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o)(n,"symbol"!=typeof t?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),i=require("../../types/ast.cjs"),s=require("../../types/lifecycle.cjs"),c=/\{\{[\s\S]*?\}\}/,l=new class{constructor(){n(this,"compilers",new Map)}get(e="anonymous"){let n=this.compilers.get(e);return n||(n=new r,this.compilers.set(e,n)),n}clear(e){var n;if(e)null==(n=this.compilers.get(e))||n.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class r{constructor(){n(this,"cache",new Map),n(this,"functions",[])}makeCacheKey(e,n,t){return 0===t.length?`${e}:${n}`:`${e}:${n}:${t.map(e=>Object.keys(e).sort().join(",")).join(";")}`}compile(e,n,i){const s=null==n?void 0:n.trim();if(!s)return 0;const c=this.makeCacheKey(e,s,i),l=this.cache.get(c);if(void 0!==l)return l;let r;try{r=t.genFunction(s,e,i)}catch(u){o.IS_DEV,r=()=>""}const a=this.functions.push(r);return this.cache.set(c,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function a(e){const n=e[0];return":"===n?{isDynamic:!0,type:"expression"}:"@"===n?{isDynamic:!0,type:"handler"}:s.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function u(e,n,t){o.IS_DEV&&(e.o={expr:n??"",loc:t??null})}function d(e){if(!e.attrs)return;const n=e.attrs.find(e=>"s-model"===e.key);if(!n)return;const t="$data."+n.value.replace("this.","").replace("$data.",""),o=n.loc,i=(e.tag||"").toLowerCase(),s=e.attrs.find(e=>"type"===e.key),c=(null==s?void 0:s.value)??"text";e.attrs=e.attrs.filter(e=>e!==n);const l=(n,t,i)=>{var s;null==(s=e.attrs)||s.push({key:n,value:t,role:i,loc:o})};if("input"===i){if("checkbox"===c){const n=e.attrs.find(e=>"value"===e.key),o=n?JSON.stringify(n.value):'"on"';return l(":checked",`Array.isArray(${t}) ? ${t}.includes(${o}) : ${t}`),void l("@change",`\n const _v = ${o};\n if(Array.isArray(${t})) {\n const _i = ${t}.indexOf(_v);\n if(checked && _i === -1) ${t}.push(_v);\n else if(!checked && _i > -1) ${t}.splice(_i,1);\n } else {\n ${t} = checked;\n }`,"model")}if("radio"===c){const n=e.attrs.find(e=>"value"===e.key),o=(null==n?void 0:n.value)??"null";return l(":checked",`${t} == ${JSON.stringify(o)}`),void l("@change",`if (checked) ${t} = ${JSON.stringify(o)}`,"model")}return l(":value",t),void l("@input",`${t} = value`,"model")}if("textarea"===i)return l(":value",t),void l("@input",`${t} = value`,"model");"select"!==i?(l(":value",t),l("@input",`${t} = $event`,"model")):e.attrs.some(e=>"multiple"===e.key)?(l("updated",`\n const values = Array.isArray(${t}) ? ${t} : ${t} != null ? [${t}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),l("@change",`${t} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(l(":value",t),l("@change",`${t} = value`,"model"))}function f(e,n,t,o=null){if(!e.attrs||0===e.attrs.length)return[];const i=[];for(const s of e.attrs){if(o&&o.has(s.key))continue;const{key:c,value:l,role:r}=s,{isDynamic:d,type:f}=a(c);if(d&&f){const o={k:c,f:t.compile(f,l??"",n),d:1,r:r};u(o,l,s.loc??e.loc),i.push(o)}else i.push({k:c,v:l,d:0,r:r})}return i}function v(e,n,t){var s,l,r,v,p,m;const y={t:e.type,d:0};let $=!1;var k;switch(e.type===i.ASTType.Text?(k=e.content)&&c.test(k)&&($=!0):((null==(s=e.attrs)?void 0:s.some(e=>"s-model"===e.key||a(e.key).isDynamic))&&($=!0),e.type===i.ASTType.For&&($=!0)),y.d=$?1:0,e.type){case i.ASTType.Text:{const o=e.content??"";$?(y.f=t.compile("template",o,n),u(y,o,e.loc)):y.x=o;break}case i.ASTType.Element:y.g=e.tag,d(e),y.a=f(e,n,t),e.children&&(y.c=h(e.children,n,t));break;case i.ASTType.For:{const o=null==(l=e.attrs)?void 0:l.find(e=>"each"===e.key),i=(null==o?void 0:o.value)??"";y.f=t.compile("expression",i,n),y.i=(null==(v=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:v.value)??"item",y.n=(null==(m=null==(p=e.attrs)?void 0:p.find(e=>"index"===e.key))?void 0:m.value)??"index",u(y,i,(null==o?void 0:o.loc)??e.loc);const s=new Set(["each","item","index"]);y.a=f(e,n,t,s);const c=[...n,{i:y.i,x:y.n}];e.children&&(y.c=h(e.children,c,t));break}case i.ASTType.If:case i.ASTType.ElseIf:case i.ASTType.Else:o.IS_DEV,y.a=f(e,n,t),e.children&&(y.c=h(e.children,n,t));break;case i.ASTType.Comment:y.x=e.content??""}return y}function h(e,n,t){var s;const c=[];let l=0;for(;l<e.length;){const r=e[l];if(r.type===i.ASTType.If){const a=[];let u=l;for(;u<e.length;){const c=e[u],l=c.type;if(l!==i.ASTType.If&&l!==i.ASTType.ElseIf&&l!==i.ASTType.Else)break;if(l===i.ASTType.If&&a.length>0)break;let r,d=null,v="";if(l!==i.ASTType.Else){const e=null==(s=c.attrs)?void 0:s.find(e=>"test"===e.key||"condition"===e.key);v=(null==e?void 0:e.value)??"false",d=t.compile("expression",v,n),r=(null==e?void 0:e.loc)??c.loc}const p=c.children?h(c.children,n,t):[],m=f(c,n,t,new Set(["test","condition"]));if(a.push({f:d,c:p,a:m.length>0?m:void 0,...o.IS_DEV&&{o:{expr:v,loc:r}}}),u++,l===i.ASTType.Else)break}c.push({t:i.ASTType.Conditional,d:1,b:a,...o.IS_DEV&&{o:{loc:r.loc}}}),l=u}else c.push(v(r,n,t)),l++}return c}exports.buildIR=function(e,n={}){const{filename:t="anonymous",source:i}=n,s=l.get(t);s.clear(),performance.now();const c=h(e,[],s),r=(performance.now(),s.getStats()),a=c.filter(e=>1===e.d).length,u={t:"root",v:"1.1.0",fns:s.getFunctions(),n:c,s:{tf:r.total,cf:r.cached,dn:a,tn:c.length},m:{t:(new Date).toISOString(),as:e.length,fn:t,...i&&{src:i}}};return o.IS_DEV,u},exports.clearIRCache=function(e){l.clear(e)},exports.transformModel=d;
1
+ "use strict";var e=Object.defineProperty,n=(n,t,o)=>((n,t,o)=>t in n?e(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o)(n,"symbol"!=typeof t?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/gen-function.cjs"),o=require("../../shared/env.cjs"),i=require("../../types/ast.cjs"),s=require("../../types/lifecycle.cjs"),c=/\{\{[\s\S]*?\}\}/,r=new class{constructor(){n(this,"compilers",new Map)}get(e="anonymous"){let n=this.compilers.get(e);return n||(n=new l,this.compilers.set(e,n)),n}clear(e){var n;if(e)null==(n=this.compilers.get(e))||n.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class l{constructor(){n(this,"cache",new Map),n(this,"functions",[])}makeCacheKey(e,n,t){return 0===t.length?`${e}:${n}`:`${e}:${n}:${t.map(e=>Object.keys(e).sort().join(",")).join(";")}`}compile(e,n,i){const s=null==n?void 0:n.trim();if(!s)return 0;const c=this.makeCacheKey(e,s,i),r=this.cache.get(c);if(void 0!==r)return r;let l;try{l=t.genFunction(s,e,i)}catch(a){o.IS_DEV,l=()=>""}const u=this.functions.push(l);return this.cache.set(c,u),u}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function u(e){const n=e[0];return":"===n?{isDynamic:!0,type:"expression"}:"@"===n?{isDynamic:!0,type:"handler"}:s.isLifecycleKind(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function a(e,n,t){o.IS_DEV&&(e.o={expr:n??"",loc:t??null})}function f(e){if(!e.attrs)return;const n=e.attrs.find(e=>"s-model"===e.key);if(!n)return;const t="$data."+n.value.replace("this.","").replace("$data.",""),o=n.loc,i=(e.tag||"").toLowerCase(),s=e.attrs.find(e=>"type"===e.key),c=(null==s?void 0:s.value)??"text";e.attrs=e.attrs.filter(e=>e!==n);const r=(n,t,i)=>{var s;null==(s=e.attrs)||s.push({key:n,value:t,role:i,loc:o})};if("input"===i){if("checkbox"===c){const n=e.attrs.find(e=>"value"===e.key),o=n?JSON.stringify(n.value):'"on"';return r(":checked",`Array.isArray(${t}) ? ${t}.includes(${o}) : ${t}`),void r("@change",`\n const _v = ${o};\n if(Array.isArray(${t})) {\n const _i = ${t}.indexOf(_v);\n if(checked && _i === -1) ${t}.push(_v);\n else if(!checked && _i > -1) ${t}.splice(_i,1);\n } else {\n ${t} = checked;\n }`,"model")}if("radio"===c){const n=e.attrs.find(e=>"value"===e.key),o=(null==n?void 0:n.value)??"null";return r(":checked",`${t} == ${JSON.stringify(o)}`),void r("@change",`if (checked) ${t} = ${JSON.stringify(o)}`,"model")}return r(":value",t),void r("@input",`${t} = value`,"model")}if("textarea"===i)return r(":value",t),void r("@input",`${t} = value`,"model");"select"!==i?(r(":value",t),r("@input",`${t} = $event`,"model")):e.attrs.some(e=>"multiple"===e.key)?(r("updated",`\n const values = Array.isArray(${t}) ? ${t} : ${t} != null ? [${t}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),r("@change",`${t} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(r(":value",t),r("@change",`${t} = value`,"model"))}function d(e,n,t,o=null){if(!e.attrs||0===e.attrs.length)return[];const i=[];for(const s of e.attrs){if(o&&o.has(s.key))continue;const{key:c,value:r,role:l}=s,{isDynamic:f,type:d}=u(c);if(f&&d){const o={k:c,f:t.compile(d,r??"",n),d:1,r:l};a(o,r,s.loc??e.loc),i.push(o)}else i.push({k:c,v:r,d:0,r:l})}return i}function v(e){if(1===e.d)return!1;if(e.c&&e.c.length>0)for(const n of e.c)if(!v(n))return!1;if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)if(!v(e))return!1;return!0}function h(e){if(e.c&&e.c.length>0)for(const n of e.c)h(n);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)h(e);e.t!==i.ASTType.Element&&e.t!==i.ASTType.Text||0===e.d&&v(e)&&(e.s=1)}function p(e,n,t){var s,r,l,v,h,p;const y={t:e.type,d:0};let $=!1;var k;switch(e.type===i.ASTType.Text?(k=e.content)&&c.test(k)&&($=!0):((null==(s=e.attrs)?void 0:s.some(e=>"s-model"===e.key||u(e.key).isDynamic))&&($=!0),e.type===i.ASTType.For&&($=!0)),y.d=$?1:0,e.type){case i.ASTType.Text:{const o=e.content??"";$?(y.f=t.compile("template",o,n),a(y,o,e.loc)):y.x=o;break}case i.ASTType.Element:y.g=e.tag,f(e),y.a=d(e,n,t),e.children&&(y.c=m(e.children,n,t));break;case i.ASTType.For:{const o=null==(r=e.attrs)?void 0:r.find(e=>"each"===e.key),i=(null==o?void 0:o.value)??"";y.f=t.compile("expression",i,n),y.i=(null==(v=null==(l=e.attrs)?void 0:l.find(e=>"item"===e.key))?void 0:v.value)??"item",y.n=(null==(p=null==(h=e.attrs)?void 0:h.find(e=>"index"===e.key))?void 0:p.value)??"index",a(y,i,(null==o?void 0:o.loc)??e.loc);const s=new Set(["each","item","index"]);y.a=d(e,n,t,s);const c=[...n,{i:y.i,x:y.n}];e.children&&(y.c=m(e.children,c,t));break}case i.ASTType.If:case i.ASTType.ElseIf:case i.ASTType.Else:o.IS_DEV,y.a=d(e,n,t),e.children&&(y.c=m(e.children,n,t));break;case i.ASTType.Comment:y.x=e.content??""}return y}function m(e,n,t){var s;const c=[];let r=0;for(;r<e.length;){const l=e[r];if(l.type===i.ASTType.If){const u=[];let a=r;for(;a<e.length;){const c=e[a],r=c.type;if(r!==i.ASTType.If&&r!==i.ASTType.ElseIf&&r!==i.ASTType.Else)break;if(r===i.ASTType.If&&u.length>0)break;let l,f=null,v="";if(r!==i.ASTType.Else){const e=null==(s=c.attrs)?void 0:s.find(e=>"test"===e.key||"condition"===e.key);v=(null==e?void 0:e.value)??"false",f=t.compile("expression",v,n),l=(null==e?void 0:e.loc)??c.loc}const h=c.children?m(c.children,n,t):[],p=d(c,n,t,new Set(["test","condition"]));if(u.push({f:f,c:h,a:p.length>0?p:void 0,...o.IS_DEV&&{o:{expr:v,loc:l}}}),a++,r===i.ASTType.Else)break}c.push({t:i.ASTType.Conditional,d:1,b:u,...o.IS_DEV&&{o:{loc:l.loc}}}),r=a}else c.push(p(l,n,t)),r++}return c}exports.buildIR=function(e,n={}){const{filename:t="anonymous",source:i}=n,s=r.get(t);s.clear(),performance.now();const c=m(e,[],s);for(const o of c)h(o);performance.now();const l=s.getStats(),u=c.filter(e=>1===e.d).length,a=c.filter(e=>1===e.s).length,f={t:"root",v:"1.2.0",fns:s.getFunctions(),n:c,s:{tf:l.total,cf:l.cached,dn:u,tn:c.length,sn:a},m:{t:(new Date).toISOString(),as:e.length,fn:t,...i&&{src:i}}};return o.IS_DEV,f},exports.clearIRCache=function(e){r.clear(e)},exports.transformModel=f;
@@ -1 +1 @@
1
- var e=Object.defineProperty,n=(n,t,o)=>((n,t,o)=>t in n?e(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o)(n,"symbol"!=typeof t?t+"":t,o);import{genFunction as t}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as i}from"../../types/ast.js";import{isLifecycleKind as s}from"../../types/lifecycle.js";const c=/\{\{[\s\S]*?\}\}/,l=new class{constructor(){n(this,"compilers",new Map)}get(e="anonymous"){let n=this.compilers.get(e);return n||(n=new r,this.compilers.set(e,n)),n}clear(e){var n;if(e)null==(n=this.compilers.get(e))||n.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class r{constructor(){n(this,"cache",new Map),n(this,"functions",[])}makeCacheKey(e,n,t){return 0===t.length?`${e}:${n}`:`${e}:${n}:${t.map(e=>Object.keys(e).sort().join(",")).join(";")}`}compile(e,n,o){const i=null==n?void 0:n.trim();if(!i)return 0;const s=this.makeCacheKey(e,i,o),c=this.cache.get(s);if(void 0!==c)return c;let l;try{l=t(i,e,o)}catch(a){l=()=>""}const r=this.functions.push(l);return this.cache.set(s,r),r}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function a(e){const n=e[0];return":"===n?{isDynamic:!0,type:"expression"}:"@"===n?{isDynamic:!0,type:"handler"}:s(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function u(e,n,t){o&&(e.o={expr:n??"",loc:t??null})}function d(e){if(!e.attrs)return;const n=e.attrs.find(e=>"s-model"===e.key);if(!n)return;const t="$data."+n.value.replace("this.","").replace("$data.",""),o=n.loc,i=(e.tag||"").toLowerCase(),s=e.attrs.find(e=>"type"===e.key),c=(null==s?void 0:s.value)??"text";e.attrs=e.attrs.filter(e=>e!==n);const l=(n,t,i)=>{var s;null==(s=e.attrs)||s.push({key:n,value:t,role:i,loc:o})};if("input"===i){if("checkbox"===c){const n=e.attrs.find(e=>"value"===e.key),o=n?JSON.stringify(n.value):'"on"';return l(":checked",`Array.isArray(${t}) ? ${t}.includes(${o}) : ${t}`),void l("@change",`\n const _v = ${o};\n if(Array.isArray(${t})) {\n const _i = ${t}.indexOf(_v);\n if(checked && _i === -1) ${t}.push(_v);\n else if(!checked && _i > -1) ${t}.splice(_i,1);\n } else {\n ${t} = checked;\n }`,"model")}if("radio"===c){const n=e.attrs.find(e=>"value"===e.key),o=(null==n?void 0:n.value)??"null";return l(":checked",`${t} == ${JSON.stringify(o)}`),void l("@change",`if (checked) ${t} = ${JSON.stringify(o)}`,"model")}return l(":value",t),void l("@input",`${t} = value`,"model")}if("textarea"===i)return l(":value",t),void l("@input",`${t} = value`,"model");"select"!==i?(l(":value",t),l("@input",`${t} = $event`,"model")):e.attrs.some(e=>"multiple"===e.key)?(l("updated",`\n const values = Array.isArray(${t}) ? ${t} : ${t} != null ? [${t}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),l("@change",`${t} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(l(":value",t),l("@change",`${t} = value`,"model"))}function f(e,n,t,o=null){if(!e.attrs||0===e.attrs.length)return[];const i=[];for(const s of e.attrs){if(o&&o.has(s.key))continue;const{key:c,value:l,role:r}=s,{isDynamic:d,type:f}=a(c);if(d&&f){const o={k:c,f:t.compile(f,l??"",n),d:1,r:r};u(o,l,s.loc??e.loc),i.push(o)}else i.push({k:c,v:l,d:0,r:r})}return i}function v(e,n,t){var o,s,l,r,v,h;const p={t:e.type,d:0};let $=!1;var y;switch(e.type===i.Text?(y=e.content)&&c.test(y)&&($=!0):((null==(o=e.attrs)?void 0:o.some(e=>"s-model"===e.key||a(e.key).isDynamic))&&($=!0),e.type===i.For&&($=!0)),p.d=$?1:0,e.type){case i.Text:{const o=e.content??"";$?(p.f=t.compile("template",o,n),u(p,o,e.loc)):p.x=o;break}case i.Element:p.g=e.tag,d(e),p.a=f(e,n,t),e.children&&(p.c=m(e.children,n,t));break;case i.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),i=(null==o?void 0:o.value)??"";p.f=t.compile("expression",i,n),p.i=(null==(r=null==(l=e.attrs)?void 0:l.find(e=>"item"===e.key))?void 0:r.value)??"item",p.n=(null==(h=null==(v=e.attrs)?void 0:v.find(e=>"index"===e.key))?void 0:h.value)??"index",u(p,i,(null==o?void 0:o.loc)??e.loc);const c=new Set(["each","item","index"]);p.a=f(e,n,t,c);const a=[...n,{i:p.i,x:p.n}];e.children&&(p.c=m(e.children,a,t));break}case i.If:case i.ElseIf:case i.Else:p.a=f(e,n,t),e.children&&(p.c=m(e.children,n,t));break;case i.Comment:p.x=e.content??""}return p}function m(e,n,t){var s;const c=[];let l=0;for(;l<e.length;){const r=e[l];if(r.type===i.If){const a=[];let u=l;for(;u<e.length;){const c=e[u],l=c.type;if(l!==i.If&&l!==i.ElseIf&&l!==i.Else)break;if(l===i.If&&a.length>0)break;let r,d=null,v="";if(l!==i.Else){const e=null==(s=c.attrs)?void 0:s.find(e=>"test"===e.key||"condition"===e.key);v=(null==e?void 0:e.value)??"false",d=t.compile("expression",v,n),r=(null==e?void 0:e.loc)??c.loc}const h=c.children?m(c.children,n,t):[],p=f(c,n,t,new Set(["test","condition"]));if(a.push({f:d,c:h,a:p.length>0?p:void 0,...o&&{o:{expr:v,loc:r}}}),u++,l===i.Else)break}c.push({t:i.Conditional,d:1,b:a,...o&&{o:{loc:r.loc}}}),l=u}else c.push(v(r,n,t)),l++}return c}function h(e,n={}){const{filename:t="anonymous",source:o}=n,i=l.get(t);i.clear(),performance.now();const s=m(e,[],i),c=(performance.now(),i.getStats()),r=s.filter(e=>1===e.d).length;return{t:"root",v:"1.1.0",fns:i.getFunctions(),n:s,s:{tf:c.total,cf:c.cached,dn:r,tn:s.length},m:{t:(new Date).toISOString(),as:e.length,fn:t,...o&&{src:o}}}}function p(e){l.clear(e)}export{h as buildIR,p as clearIRCache,d as transformModel};
1
+ var e=Object.defineProperty,n=(n,t,o)=>((n,t,o)=>t in n?e(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o)(n,"symbol"!=typeof t?t+"":t,o);import{genFunction as t}from"../../shared/gen-function.js";import{IS_DEV as o}from"../../shared/env.js";import{ASTType as i}from"../../types/ast.js";import{isLifecycleKind as s}from"../../types/lifecycle.js";const c=/\{\{[\s\S]*?\}\}/,r=new class{constructor(){n(this,"compilers",new Map)}get(e="anonymous"){let n=this.compilers.get(e);return n||(n=new l,this.compilers.set(e,n)),n}clear(e){var n;if(e)null==(n=this.compilers.get(e))||n.clear(),this.compilers.delete(e);else{for(const e of this.compilers.values())e.clear();this.compilers.clear()}}};class l{constructor(){n(this,"cache",new Map),n(this,"functions",[])}makeCacheKey(e,n,t){return 0===t.length?`${e}:${n}`:`${e}:${n}:${t.map(e=>Object.keys(e).sort().join(",")).join(";")}`}compile(e,n,o){const i=null==n?void 0:n.trim();if(!i)return 0;const s=this.makeCacheKey(e,i,o),c=this.cache.get(s);if(void 0!==c)return c;let r;try{r=t(i,e,o)}catch(a){r=()=>""}const l=this.functions.push(r);return this.cache.set(s,l),l}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function a(e){const n=e[0];return":"===n?{isDynamic:!0,type:"expression"}:"@"===n?{isDynamic:!0,type:"handler"}:s(e)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function u(e,n,t){o&&(e.o={expr:n??"",loc:t??null})}function f(e){if(!e.attrs)return;const n=e.attrs.find(e=>"s-model"===e.key);if(!n)return;const t="$data."+n.value.replace("this.","").replace("$data.",""),o=n.loc,i=(e.tag||"").toLowerCase(),s=e.attrs.find(e=>"type"===e.key),c=(null==s?void 0:s.value)??"text";e.attrs=e.attrs.filter(e=>e!==n);const r=(n,t,i)=>{var s;null==(s=e.attrs)||s.push({key:n,value:t,role:i,loc:o})};if("input"===i){if("checkbox"===c){const n=e.attrs.find(e=>"value"===e.key),o=n?JSON.stringify(n.value):'"on"';return r(":checked",`Array.isArray(${t}) ? ${t}.includes(${o}) : ${t}`),void r("@change",`\n const _v = ${o};\n if(Array.isArray(${t})) {\n const _i = ${t}.indexOf(_v);\n if(checked && _i === -1) ${t}.push(_v);\n else if(!checked && _i > -1) ${t}.splice(_i,1);\n } else {\n ${t} = checked;\n }`,"model")}if("radio"===c){const n=e.attrs.find(e=>"value"===e.key),o=(null==n?void 0:n.value)??"null";return r(":checked",`${t} == ${JSON.stringify(o)}`),void r("@change",`if (checked) ${t} = ${JSON.stringify(o)}`,"model")}return r(":value",t),void r("@input",`${t} = value`,"model")}if("textarea"===i)return r(":value",t),void r("@input",`${t} = value`,"model");"select"!==i?(r(":value",t),r("@input",`${t} = $event`,"model")):e.attrs.some(e=>"multiple"===e.key)?(r("updated",`\n const values = Array.isArray(${t}) ? ${t} : ${t} != null ? [${t}] : [];\n for (const opt of el.options) {\n opt.selected = values.includes(opt.value);\n }`),r("@change",`${t} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(r(":value",t),r("@change",`${t} = value`,"model"))}function d(e,n,t,o=null){if(!e.attrs||0===e.attrs.length)return[];const i=[];for(const s of e.attrs){if(o&&o.has(s.key))continue;const{key:c,value:r,role:l}=s,{isDynamic:f,type:d}=a(c);if(f&&d){const o={k:c,f:t.compile(d,r??"",n),d:1,r:l};u(o,r,s.loc??e.loc),i.push(o)}else i.push({k:c,v:r,d:0,r:l})}return i}function v(e){if(1===e.d)return!1;if(e.c&&e.c.length>0)for(const n of e.c)if(!v(n))return!1;if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)if(!v(e))return!1;return!0}function m(e){if(e.c&&e.c.length>0)for(const n of e.c)m(n);if(e.b&&e.b.length>0)for(const n of e.b)if(n.c&&n.c.length>0)for(const e of n.c)m(e);e.t!==i.Element&&e.t!==i.Text||0===e.d&&v(e)&&(e.s=1)}function h(e,n,t){var o,s,r,l,v,m;const h={t:e.type,d:0};let $=!1;var y;switch(e.type===i.Text?(y=e.content)&&c.test(y)&&($=!0):((null==(o=e.attrs)?void 0:o.some(e=>"s-model"===e.key||a(e.key).isDynamic))&&($=!0),e.type===i.For&&($=!0)),h.d=$?1:0,e.type){case i.Text:{const o=e.content??"";$?(h.f=t.compile("template",o,n),u(h,o,e.loc)):h.x=o;break}case i.Element:h.g=e.tag,f(e),h.a=d(e,n,t),e.children&&(h.c=p(e.children,n,t));break;case i.For:{const o=null==(s=e.attrs)?void 0:s.find(e=>"each"===e.key),i=(null==o?void 0:o.value)??"";h.f=t.compile("expression",i,n),h.i=(null==(l=null==(r=e.attrs)?void 0:r.find(e=>"item"===e.key))?void 0:l.value)??"item",h.n=(null==(m=null==(v=e.attrs)?void 0:v.find(e=>"index"===e.key))?void 0:m.value)??"index",u(h,i,(null==o?void 0:o.loc)??e.loc);const c=new Set(["each","item","index"]);h.a=d(e,n,t,c);const a=[...n,{i:h.i,x:h.n}];e.children&&(h.c=p(e.children,a,t));break}case i.If:case i.ElseIf:case i.Else:h.a=d(e,n,t),e.children&&(h.c=p(e.children,n,t));break;case i.Comment:h.x=e.content??""}return h}function p(e,n,t){var s;const c=[];let r=0;for(;r<e.length;){const l=e[r];if(l.type===i.If){const a=[];let u=r;for(;u<e.length;){const c=e[u],r=c.type;if(r!==i.If&&r!==i.ElseIf&&r!==i.Else)break;if(r===i.If&&a.length>0)break;let l,f=null,v="";if(r!==i.Else){const e=null==(s=c.attrs)?void 0:s.find(e=>"test"===e.key||"condition"===e.key);v=(null==e?void 0:e.value)??"false",f=t.compile("expression",v,n),l=(null==e?void 0:e.loc)??c.loc}const m=c.children?p(c.children,n,t):[],h=d(c,n,t,new Set(["test","condition"]));if(a.push({f:f,c:m,a:h.length>0?h:void 0,...o&&{o:{expr:v,loc:l}}}),u++,r===i.Else)break}c.push({t:i.Conditional,d:1,b:a,...o&&{o:{loc:l.loc}}}),r=u}else c.push(h(l,n,t)),r++}return c}function $(e,n={}){const{filename:t="anonymous",source:o}=n,i=r.get(t);i.clear(),performance.now();const s=p(e,[],i);for(const r of s)m(r);performance.now();const c=i.getStats(),l=s.filter(e=>1===e.d).length,a=s.filter(e=>1===e.s).length;return{t:"root",v:"1.2.0",fns:i.getFunctions(),n:s,s:{tf:c.total,cf:c.cached,dn:l,tn:s.length,sn:a},m:{t:(new Date).toISOString(),as:e.length,fn:t,...o&&{src:o}}}}function y(e){r.clear(e)}export{$ as buildIR,y as clearIRCache,f as transformModel};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),c=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function s(o,s){var i;const l=(null==(i=(o.match(c)||[])[1])?void 0:i.toLowerCase())??"",f=function(e,c){const o=[];let s;const i=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-i.length;for(;null!==(s=r.exec(i));){const r=s[1];if(!r)continue;const i=s[2]??s[3]??s[4]??"";let f=r;t.default.has(r)&&(f=f.replace(/^on/,"@")),"s-model"!==f&&(f=f.replace(/^on-/,"@").replace(/^s-/,":")),f=n.mapAttrKeyToLifecycleKind(f)||f;const u=s[0],a=u.indexOf("=");let d;if(-1===a)d=u.indexOf(r)+r.length;else{let t=a+1;for(;t<u.length&&/\s/.test(u[t]);)t++;if('"'===u[t]||"'"===u[t]){let e=t+1;for(;e<u.length&&/\s/.test(u[e]);)e++;d=e}else{let e=t;for(;e<u.length&&/\s/.test(u[e]);)e++;d=e}}let p=s.index+d+l;const y=e.slice(0,p).split("\n"),m=c[0]+y.length-1,g=y.length>1?y[y.length-1].length+1:c[1]+p;o.push({key:f,value:i,loc:[m,g]})}return o}(o,s);return{type:{for:e.ASTType.For,if:e.ASTType.If,elseif:e.ASTType.ElseIf,else:e.ASTType.Else}[l]??e.ASTType.Element,tag:l,loc:s,children:[],attrs:f}}function i(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let c=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||c){if(">"===e&&!c&&!o)return r}else o=!o;else c=!c;r++}return-1}exports.parseHtml=function(t){const n=[];if(!t)return[];const c=[],r=[],l=()=>{var t;return 0===c.length?n:(t=c[c.length-1]).children||(t.children=[])};let f=0;const u=t.length,a=[0];for(let e=0;e<u;e++)"\n"===t[e]&&a.push(e+1);function d(t){let e=0;for(let n=1;n<a.length&&!(a[n]>t);n++)e=n;return[e+1,t-a[e]+1]}for(;f<u;){const n=t.indexOf("<",f);if(-1===n||n>f){const c=t.substring(f,-1===n?void 0:n),o=c.trim();if(o){const t=d(f+c.indexOf(o));l().push({type:e.ASTType.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===n)break;f=n}const a=i(t,f+1);if(-1===a){const n=t.substring(f);n.trim()&&l().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,a+1),y=l(),m=d(f);if(p.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(4,-3),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<![CDATA[")){y.push({type:e.ASTType.Text,tag:"text",content:p.slice(9,-3),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(2,-1),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<?")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(2,-2),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("</")){const t=r.pop();for(;c.length>0;){if((c[c.length-1].tag||"").toLowerCase()===(null==t?void 0:t.toLowerCase())){c.pop();break}c.pop()}f=a+1;continue}const g=s(p,m);y.push(g);const h=g.tag||"",x=h.toLowerCase().startsWith("script"),b=h.toLowerCase().startsWith("style"),v=p.endsWith("/>")||o.has(h.toLowerCase());if((x||b)&&!v){const n=`</${h}>`,c=t.toLowerCase().indexOf(n,a+1);if(-1!==c){const o=t.substring(a+1,c);o.length&&g.children.push({type:e.ASTType.Text,tag:"text",content:o,loc:d(a+1),children:[]}),f=c+n.length;continue}{const n=t.substring(a+1);n.length&&g.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:d(a+1),children:[]}),f=u;continue}}v||g.type===e.ASTType.Text||g.type===e.ASTType.Comment||(c.push(g),r.push(h)),f=a+1}return n};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../shared/event-listeners.cjs"),e=require("../../types/ast.cjs"),n=require("../../types/lifecycle.cjs"),c=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,o=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function s(o,s){var i;const l=(null==(i=(o.match(c)||[])[1])?void 0:i.toLowerCase())??"",f=function(e,c){const o=[];let s;const i=e.replace(/^\s*[^\s"'/>]+/,""),l=e.length-i.length;for(;null!==(s=r.exec(i));){const r=s[1];if(!r)continue;const i=s[2]??s[3]??s[4]??"";let f=r;t.default.has(r)&&(f=f.replace(/^on/,"@")),"s-model"!==f&&(f=f.replace(/^on-/,"@").replace(/^s-/,":")),f=n.mapAttrKeyToLifecycleKind(f)||f;const u=s[0],a=u.indexOf("=");let d;if(-1===a)d=u.indexOf(r)+r.length;else{let t=a+1;for(;t<u.length&&/\s/.test(u[t]);)t++;if('"'===u[t]||"'"===u[t]){let e=t+1;for(;e<u.length&&/\s/.test(u[e]);)e++;d=e}else{let e=t;for(;e<u.length&&/\s/.test(u[e]);)e++;d=e}}const p=s.index+d+l,y=e.slice(0,p).split("\n"),m=c[0]+y.length-1,g=y.length>1?y[y.length-1].length+1:c[1]+p;o.push({key:f,value:i,loc:[m,g]})}return o}(o,s);return{type:{for:e.ASTType.For,if:e.ASTType.If,elseif:e.ASTType.ElseIf,else:e.ASTType.Else}[l]??e.ASTType.Element,tag:l,loc:s,children:[],attrs:f}}function i(t,e){const n=t.length;if(t.startsWith("!--",e)){const n=t.indexOf("--\x3e",e+3);return-1===n?-1:n+2}if(t.startsWith("![CDATA[",e)){const n=t.indexOf("]]>",e+8);return-1===n?-1:n+2}if("!"===t[e])return t.indexOf(">",e+1);if("?"===t[e]){const n=t.indexOf("?>",e+1);return-1===n?-1:n+1}let c=!1,o=!1,r=e;for(;r<n;){const e=t[r];if("'"!==e||o)if('"'!==e||c){if(">"===e&&!c&&!o)return r}else o=!o;else c=!c;r++}return-1}exports.parseHtml=function(t){const n=[];if(!t)return[];const c=[],r=[],l=()=>{var t;return 0===c.length?n:(t=c[c.length-1]).children||(t.children=[])};let f=0;const u=t.length,a=[0];for(let e=0;e<u;e++)"\n"===t[e]&&a.push(e+1);function d(t){let e=0;for(let n=1;n<a.length&&!(a[n]>t);n++)e=n;return[e+1,t-a[e]+1]}for(;f<u;){const n=t.indexOf("<",f);if(-1===n||n>f){const c=t.substring(f,-1===n?void 0:n),o=c.trim();if(o){const t=d(f+c.indexOf(o));l().push({type:e.ASTType.Text,tag:"text",content:o,loc:t,children:[]})}if(-1===n)break;f=n}const a=i(t,f+1);if(-1===a){const n=t.substring(f);n.trim()&&l().push({type:e.ASTType.Text,tag:"text",content:n.trim(),children:[],loc:d(f)});break}const p=t.substring(f,a+1),y=l(),m=d(f);if(p.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(4,-3),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<![CDATA[")){y.push({type:e.ASTType.Text,tag:"text",content:p.slice(9,-3),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<!")&&!p.startsWith("\x3c!--")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(2,-1),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("<?")){y.push({type:e.ASTType.Comment,tag:"comment",content:p.slice(2,-2),loc:m,children:[]}),f=a+1;continue}if(p.startsWith("</")){const t=r.pop();for(;c.length>0;){if((c[c.length-1].tag||"").toLowerCase()===(null==t?void 0:t.toLowerCase())){c.pop();break}c.pop()}f=a+1;continue}const g=s(p,m);y.push(g);const h=g.tag||"",x=h.toLowerCase().startsWith("script"),b=h.toLowerCase().startsWith("style"),v=p.endsWith("/>")||o.has(h.toLowerCase());if((x||b)&&!v){const n=`</${h}>`,c=t.toLowerCase().indexOf(n,a+1);if(-1!==c){const o=t.substring(a+1,c);o.length&&g.children.push({type:e.ASTType.Text,tag:"text",content:o,loc:d(a+1),children:[]}),f=c+n.length;continue}{const n=t.substring(a+1);n.length&&g.children.push({type:e.ASTType.Text,tag:"text",content:n,loc:d(a+1),children:[]}),f=u;continue}}v||g.type===e.ASTType.Text||g.type===e.ASTType.Comment||(c.push(g),r.push(h)),f=a+1}return n};
@@ -1 +1 @@
1
- import t from"../../shared/event-listeners.js";import{ASTType as n}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as e}from"../../types/lifecycle.js";const o=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,c=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function s(c,s){var i;const l=(null==(i=(c.match(o)||[])[1])?void 0:i.toLowerCase())??"",f=function(n,o){const c=[];let s;const i=n.replace(/^\s*[^\s"'/>]+/,""),l=n.length-i.length;for(;null!==(s=r.exec(i));){const r=s[1];if(!r)continue;const i=s[2]??s[3]??s[4]??"";let f=r;t.has(r)&&(f=f.replace(/^on/,"@")),"s-model"!==f&&(f=f.replace(/^on-/,"@").replace(/^s-/,":")),f=e(f)||f;const u=s[0],a=u.indexOf("=");let p;if(-1===a)p=u.indexOf(r)+r.length;else{let t=a+1;for(;t<u.length&&/\s/.test(u[t]);)t++;if('"'===u[t]||"'"===u[t]){let n=t+1;for(;n<u.length&&/\s/.test(u[n]);)n++;p=n}else{let n=t;for(;n<u.length&&/\s/.test(u[n]);)n++;p=n}}let m=s.index+p+l;const d=n.slice(0,m).split("\n"),y=o[0]+d.length-1,g=d.length>1?d[d.length-1].length+1:o[1]+m;c.push({key:f,value:i,loc:[y,g]})}return c}(c,s);return{type:{for:n.For,if:n.If,elseif:n.ElseIf,else:n.Else}[l]??n.Element,tag:l,loc:s,children:[],attrs:f}}function i(t,n){const e=t.length;if(t.startsWith("!--",n)){const e=t.indexOf("--\x3e",n+3);return-1===e?-1:e+2}if(t.startsWith("![CDATA[",n)){const e=t.indexOf("]]>",n+8);return-1===e?-1:e+2}if("!"===t[n])return t.indexOf(">",n+1);if("?"===t[n]){const e=t.indexOf("?>",n+1);return-1===e?-1:e+1}let o=!1,c=!1,r=n;for(;r<e;){const n=t[r];if("'"!==n||c)if('"'!==n||o){if(">"===n&&!o&&!c)return r}else c=!c;else o=!o;r++}return-1}function l(t){const e=[];if(!t)return[];const o=[],r=[],l=()=>{var t;return 0===o.length?e:(t=o[o.length-1]).children||(t.children=[])};let f=0;const u=t.length,a=[0];for(let n=0;n<u;n++)"\n"===t[n]&&a.push(n+1);function p(t){let n=0;for(let e=1;e<a.length&&!(a[e]>t);e++)n=e;return[n+1,t-a[n]+1]}for(;f<u;){const e=t.indexOf("<",f);if(-1===e||e>f){const o=t.substring(f,-1===e?void 0:e),c=o.trim();if(c){const t=p(f+o.indexOf(c));l().push({type:n.Text,tag:"text",content:c,loc:t,children:[]})}if(-1===e)break;f=e}const a=i(t,f+1);if(-1===a){const e=t.substring(f);e.trim()&&l().push({type:n.Text,tag:"text",content:e.trim(),children:[],loc:p(f)});break}const m=t.substring(f,a+1),d=l(),y=p(f);if(m.startsWith("\x3c!--")){d.push({type:n.Comment,tag:"comment",content:m.slice(4,-3),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<![CDATA[")){d.push({type:n.Text,tag:"text",content:m.slice(9,-3),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<!")&&!m.startsWith("\x3c!--")){d.push({type:n.Comment,tag:"comment",content:m.slice(2,-1),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<?")){d.push({type:n.Comment,tag:"comment",content:m.slice(2,-2),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("</")){const t=r.pop();for(;o.length>0;){if((o[o.length-1].tag||"").toLowerCase()===(null==t?void 0:t.toLowerCase())){o.pop();break}o.pop()}f=a+1;continue}const g=s(m,y);d.push(g);const h=g.tag||"",x=h.toLowerCase().startsWith("script"),b=h.toLowerCase().startsWith("style"),v=m.endsWith("/>")||c.has(h.toLowerCase());if((x||b)&&!v){const e=`</${h}>`,o=t.toLowerCase().indexOf(e,a+1);if(-1!==o){const c=t.substring(a+1,o);c.length&&g.children.push({type:n.Text,tag:"text",content:c,loc:p(a+1),children:[]}),f=o+e.length;continue}{const e=t.substring(a+1);e.length&&g.children.push({type:n.Text,tag:"text",content:e,loc:p(a+1),children:[]}),f=u;continue}}v||g.type===n.Text||g.type===n.Comment||(o.push(g),r.push(h)),f=a+1}return e}export{l as parseHtml};
1
+ import t from"../../shared/event-listeners.js";import{ASTType as n}from"../../types/ast.js";import{mapAttrKeyToLifecycleKind as e}from"../../types/lifecycle.js";const o=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,c=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),r=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function s(c,s){var i;const l=(null==(i=(c.match(o)||[])[1])?void 0:i.toLowerCase())??"",f=function(n,o){const c=[];let s;const i=n.replace(/^\s*[^\s"'/>]+/,""),l=n.length-i.length;for(;null!==(s=r.exec(i));){const r=s[1];if(!r)continue;const i=s[2]??s[3]??s[4]??"";let f=r;t.has(r)&&(f=f.replace(/^on/,"@")),"s-model"!==f&&(f=f.replace(/^on-/,"@").replace(/^s-/,":")),f=e(f)||f;const u=s[0],a=u.indexOf("=");let p;if(-1===a)p=u.indexOf(r)+r.length;else{let t=a+1;for(;t<u.length&&/\s/.test(u[t]);)t++;if('"'===u[t]||"'"===u[t]){let n=t+1;for(;n<u.length&&/\s/.test(u[n]);)n++;p=n}else{let n=t;for(;n<u.length&&/\s/.test(u[n]);)n++;p=n}}const m=s.index+p+l,d=n.slice(0,m).split("\n"),y=o[0]+d.length-1,g=d.length>1?d[d.length-1].length+1:o[1]+m;c.push({key:f,value:i,loc:[y,g]})}return c}(c,s);return{type:{for:n.For,if:n.If,elseif:n.ElseIf,else:n.Else}[l]??n.Element,tag:l,loc:s,children:[],attrs:f}}function i(t,n){const e=t.length;if(t.startsWith("!--",n)){const e=t.indexOf("--\x3e",n+3);return-1===e?-1:e+2}if(t.startsWith("![CDATA[",n)){const e=t.indexOf("]]>",n+8);return-1===e?-1:e+2}if("!"===t[n])return t.indexOf(">",n+1);if("?"===t[n]){const e=t.indexOf("?>",n+1);return-1===e?-1:e+1}let o=!1,c=!1,r=n;for(;r<e;){const n=t[r];if("'"!==n||c)if('"'!==n||o){if(">"===n&&!o&&!c)return r}else c=!c;else o=!o;r++}return-1}function l(t){const e=[];if(!t)return[];const o=[],r=[],l=()=>{var t;return 0===o.length?e:(t=o[o.length-1]).children||(t.children=[])};let f=0;const u=t.length,a=[0];for(let n=0;n<u;n++)"\n"===t[n]&&a.push(n+1);function p(t){let n=0;for(let e=1;e<a.length&&!(a[e]>t);e++)n=e;return[n+1,t-a[n]+1]}for(;f<u;){const e=t.indexOf("<",f);if(-1===e||e>f){const o=t.substring(f,-1===e?void 0:e),c=o.trim();if(c){const t=p(f+o.indexOf(c));l().push({type:n.Text,tag:"text",content:c,loc:t,children:[]})}if(-1===e)break;f=e}const a=i(t,f+1);if(-1===a){const e=t.substring(f);e.trim()&&l().push({type:n.Text,tag:"text",content:e.trim(),children:[],loc:p(f)});break}const m=t.substring(f,a+1),d=l(),y=p(f);if(m.startsWith("\x3c!--")){d.push({type:n.Comment,tag:"comment",content:m.slice(4,-3),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<![CDATA[")){d.push({type:n.Text,tag:"text",content:m.slice(9,-3),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<!")&&!m.startsWith("\x3c!--")){d.push({type:n.Comment,tag:"comment",content:m.slice(2,-1),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("<?")){d.push({type:n.Comment,tag:"comment",content:m.slice(2,-2),loc:y,children:[]}),f=a+1;continue}if(m.startsWith("</")){const t=r.pop();for(;o.length>0;){if((o[o.length-1].tag||"").toLowerCase()===(null==t?void 0:t.toLowerCase())){o.pop();break}o.pop()}f=a+1;continue}const g=s(m,y);d.push(g);const h=g.tag||"",x=h.toLowerCase().startsWith("script"),b=h.toLowerCase().startsWith("style"),v=m.endsWith("/>")||c.has(h.toLowerCase());if((x||b)&&!v){const e=`</${h}>`,o=t.toLowerCase().indexOf(e,a+1);if(-1!==o){const c=t.substring(a+1,o);c.length&&g.children.push({type:n.Text,tag:"text",content:c,loc:p(a+1),children:[]}),f=o+e.length;continue}{const e=t.substring(a+1);e.length&&g.children.push({type:n.Text,tag:"text",content:e,loc:p(a+1),children:[]}),f=u;continue}}v||g.type===n.Text||g.type===n.Comment||(o.push(g),r.push(h)),f=a+1}return e}export{l as parseHtml};
@@ -1,9 +1,9 @@
1
1
  declare interface BaseElement<TData = any> {
2
2
  /**
3
- * 通过 ref 属性获取的 DOM 元素引用集合
4
- * - 键:模板中写的 ref="xxx" 的名字
5
- * - 值:对应的 DOM 元素(通常是 HTMLElement 或 SVGElement)
6
- */
3
+ * 通过 ref 属性获取的 DOM 元素引用集合
4
+ * - 键:模板中写的 ref="xxx" 的名字
5
+ * - 值:对应的 DOM 元素(通常是 HTMLElement 或 SVGElement)
6
+ */
7
7
  $refs: Record<string, HTMLElement | SVGElement | any>;
8
8
  }
9
9
  declare class BaseElement<TData extends object = any> extends HTMLElement {
@@ -1,6 +1,6 @@
1
1
  import { IRRoot } from '../../types';
2
2
  /** Prop 配置,支持类型声明 */
3
- export type PropType = "string" | "number" | "boolean" | "object";
3
+ export type PropType = 'string' | 'number' | 'boolean' | 'object';
4
4
  /** 属性描述符 */
5
5
  export interface PropDescriptor {
6
6
  /** HTML attribute 名 */
@@ -27,7 +27,7 @@ export interface Manifest {
27
27
  /** 是否启用 Shadow DOM */
28
28
  shadowDOM?: {
29
29
  use: boolean;
30
- mode?: "open" | "closed";
30
+ mode?: 'open' | 'closed';
31
31
  };
32
32
  /** 组件根元素类名 */
33
33
  className?: string;
@@ -2,29 +2,29 @@
2
2
  export type PathKey = string | symbol;
3
3
  /** 变更项的原始载荷 */
4
4
  export type ChangePayload = {
5
- type: "set";
5
+ type: 'set';
6
6
  key: PathKey;
7
7
  newValue: unknown;
8
8
  oldValue: unknown;
9
9
  } | {
10
- type: "delete";
10
+ type: 'delete';
11
11
  key: PathKey;
12
12
  oldValue: unknown;
13
13
  } | {
14
- type: "array-push";
14
+ type: 'array-push';
15
15
  index: number;
16
16
  values: unknown[];
17
17
  } | {
18
- type: "array-splice";
18
+ type: 'array-splice';
19
19
  index: number;
20
20
  deleteCount: number;
21
21
  insert: unknown[];
22
22
  } | {
23
- type: "array-replace";
23
+ type: 'array-replace';
24
24
  oldValue: unknown[];
25
25
  newValue: unknown[];
26
26
  } | {
27
- type: "array-reset";
27
+ type: 'array-reset';
28
28
  method: string;
29
29
  };
30
30
  /** 完整的变更对象 */
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,o,s)=>((e,o,s)=>o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[o]=s)(e,"symbol"!=typeof o?o+"":o,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../types/ast.cjs"),s=require("../../shared/templateError.cjs"),n=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),l=Symbol("solely.prevStyleObj"),c={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},f={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]);function u(t){const e={},o=[[t]];for(;o.length;){const[t,s]=o.pop();if(t){if("string"==typeof t){const o=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let s;for(;null!==(s=o.exec(t));){const t=s[1].trim(),o=s[2].trim();t&&o&&(e[t]=o)}continue}if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)o.push([t[e]]);else if("object"==typeof t)for(const n in t){const i=t[n];if(null==i)continue;const r=s?`${s}-${n}`:n;"object"!=typeof i||Array.isArray(i)?e[r]=String(i):o.push([i,r])}}}return e}function d(t,e,o){const s=null==o?"":String(o),n=e.indexOf(":");if(n>0){const o=e.slice(0,n),i=c[o];if(i)return void(t.getAttributeNS(i,e)!==s&&t.setAttributeNS(i,e,s))}t.getAttribute(e)!==s&&t.setAttribute(e,s)}function m(t,e,o){const s=f[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||a.has(e))return void d(t,e,o);const n=t,i=n.tagName;if(null!=o){if("src"===s||"href"===s){const e=String(o);if(n[s]===e||t.getAttribute(s)===e)return}if("value"!==s||"INPUT"!==i&&"TEXTAREA"!==i||n.value!==o)if("boolean"!=typeof o)(t instanceof SVGElement||void 0!==n.ownerSVGElement)&&!f[e]?d(t,e,o):n[s]!==o&&(n[s]=o);else{if(n[s]===o)return;n[s]=o}}else if("boolean"==typeof n[s])!1!==n[s]&&(n[s]=!1);else{const o=n[s];""!==o&&void 0!==o&&(n[s]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class p{constructor(t,o,s={}){e(this,"nodeMap",new Map),e(this,"marker",!1),this.ir=t,this.container=o,this.scope=s}evalIR(t,e,o){var n;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,e):""}catch(r){return s.showTemplateError(r.message||r.toString(),(null==(n=this.ir.m)?void 0:n.src)||"",o,this.scope.tagName),""}}createElement(t,e){const o=t.g;return e instanceof SVGElement||"svg"===o?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o)}createText(t,e){const o=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createTextNode(o)}createComment(t,e){const o=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createComment(o)}applyAttrs(t,e,o,s=!1){const c=[],f=t;let a;f[n]||(f[n]={loops:null}),f[n].loops=o,f[i]||(f[i]=Object.create(null));let p,y=!1,b=!1;for(const r of e){const{k:e,f:l,d:u,v:v}=r;if(":class"===e){a=this.evalIR(l,[o],r.o),y=!0;continue}if(":style"===e){p=this.evalIR(l,[o],r.o),b=!0;continue}if("class"===e||"style"===e)continue;const w=e[0];if("@"===w){const o=e.slice(1),c=r.r??"user";let a=f[i][o];if(a||(a=f[i][o]={model:[],user:[]},t.addEventListener(o,t=>{for(const e of a.model)e(t);for(const e of a.user)e(t)})),!s){const t=t=>this.evalIR(l,[t,f[n].loops],r.o);a[c].push(t)}continue}if("mounted"===e){s||requestAnimationFrame(()=>this.evalIR(l,[t,o],r.o));continue}if("updated"===e){s&&requestAnimationFrame(()=>this.evalIR(l,[t,o],r.o));continue}if("ref"===e&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=t;continue}const g=u?this.evalIR(l,[o],r.o):v??"";if(":"===w){const o=e.slice(1);"SELECT"===t.tagName&&h.has(o)?c.push(()=>m(t,o,g)):m(t,o,g)}else s||d(t,e,String(g))}return y&&((t,e)=>{const o=t,s=o[r],n=function(t){const e={},o=[t];for(;o.length;){const t=o.pop();if(t)if("string"==typeof t){const o=t.split(" ");for(let t=0;t<o.length;t++){const s=o[t].trim();s&&(e[s]=!0)}}else if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)o.push(t[e]);else if("object"==typeof t)for(const o in t)t[o]&&(e[o]=!0)}return e}(e);if(!s){for(const e in n)t.classList.add(e);return void(o[r]=n)}let i=!1;for(const r in s)n[r]||(t.classList.remove(r),i=!0);for(const r in n)s[r]||(t.classList.add(r),i=!0);i&&(o[r]=n)})(t,a),b&&((t,e)=>{const o=t,s=u(e),n=o[l];if(!n){for(const e in s){const o=s[e];e.startsWith("--")?t.style.setProperty(e,o):t.style[e]=o}return void(o[l]=s)}let i=!1;for(const r in n)r in s||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in s){const e=s[r];e!==n[r]&&(r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e,i=!0)}i&&(o[l]=s)})(t,p),c}updateNode(t,e,o){const s=e.d?this.evalIR(e.f,[o],e.o):e.x||"";e.d&&t.textContent!==s&&(t.textContent=s)}irToNode(t,e,s,n,i){var r,l,c,f;const a=s+"-"+e,h=this.nodeMap.get(a);let d;if(h){d=h.node,h.marker=this.marker;let e=[];t.d&&(t.t===o.ASTType.Element?e=this.applyAttrs(d,t.a??[],i,!0):this.updateNode(d,t,i)),null==(r=t.c)||r.forEach((t,e)=>{this.irToNode(t,e,a,d,i)}),e.forEach(t=>t())}else switch(t.t){case o.ASTType.Element:d=this.createElement(t,n),function(t,e){var o;const s=null==(o=e.a)?void 0:o.find(t=>"class"===t.k&&!t.d);(null==s?void 0:s.v)&&t.setAttribute("class",s.v)}(d,t),function(t,e){var o;if(!t.style)return;const s=null==(o=e.a)?void 0:o.find(t=>"style"===t.k&&!t.d),n=s?u(s.v):{};for(const i in n){const e=n[i];i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e}}(d,t);const e=this.applyAttrs(d,t.a??[],i);n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker}),null==(l=t.c)||l.forEach((t,e)=>{this.irToNode(t,e,a,d,i)}),e.forEach(t=>t());break;case o.ASTType.Text:d=this.createText(t,i),n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case o.ASTType.Comment:d=this.createComment(t,i),n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case o.ASTType.For:{const e=`${a}-end`;let s=null==(c=this.nodeMap.get(e))?void 0:c.node;s?this.nodeMap.get(e).marker=this.marker:(s=document.createComment(`for:${a}`),n.appendChild(s),this.nodeMap.set(e,{irNode:{t:o.ASTType.Comment},node:s,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],l=document.createDocumentFragment();r.forEach((e,o)=>{var s;const n=[...i,{itmVal:e,idxVal:o}];null==(s=t.c)||s.forEach((t,e)=>{this.irToNode(t,e,`${a}-for-${o}`,l,n)})}),s.parentNode.insertBefore(l,s);break}case o.ASTType.Conditional:{const e=`${a}-end`;let o=null==(f=this.nodeMap.get(e))?void 0:f.node;o?this.nodeMap.get(e).marker=this.marker:(o=document.createComment(`if:${a}`),n.appendChild(o),this.nodeMap.set(e,{irNode:{},node:o,loops:i,marker:this.marker}));for(let s=0;s<(t.b||[]).length;s++){const e=t.b[s];if(null===e.f||this.evalIR(e.f,[i],e.o)){const t=document.createDocumentFragment();e.c.forEach((e,o)=>{this.irToNode(e,o,`${a}-if-${s}`,t,i)}),o.parentNode.insertBefore(t,o);break}}break}}}cleanupOldNodes(){for(const[t,e]of this.nodeMap.entries())if(e.marker!==this.marker){const{irNode:o,node:s,loops:n}=e;if(o.a){const t=o.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[s,n],t.o)});const e=o.a.find(t=>"ref"===t.k);e&&e.v&&delete this.scope.$refs[e.v]}null==s||s.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear()}}exports.IRRenderer=p,exports.createRender=(t,e,o={})=>{const s=new p(t,e,o);return s.mount(),{update:()=>s.update(),destroy:()=>s.destroy()}};
1
+ "use strict";var t=Object.defineProperty,e=(e,s,o)=>((e,s,o)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o)(e,"symbol"!=typeof s?s+"":s,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../types/ast.cjs"),o=require("../../shared/templateError.cjs"),n=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),c=Symbol("solely.prevStyleObj"),l={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},a={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},h=new Set(["data-","aria-","role","form"]),u=new Set(["value","selectedIndex"]);function f(t,e){var s;const o=null==(s=e.a)?void 0:s.find(t=>"class"===t.k&&!t.d);(null==o?void 0:o.v)&&t.setAttribute("class",o.v)}function d(t,e){var s;if(!t.style)return;const o=null==(s=e.a)?void 0:s.find(t=>"style"===t.k&&!t.d),n=o?m(o.v):{};for(const i in n){const e=n[i];i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e}}function m(t){const e={},s=[[t]];for(;s.length;){const[t,o]=s.pop();if(t){if("string"==typeof t){const s=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let o;for(;null!==(o=s.exec(t));){const t=o[1].trim(),s=o[2].trim();t&&s&&(e[t]=s)}continue}if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push([t[e]]);else if("object"==typeof t)for(const n in t){const i=t[n];if(null==i)continue;const r=o?`${o}-${n}`:n;"object"!=typeof i||Array.isArray(i)?e[r]=String(i):s.push([i,r])}}}return e}function p(t,e,s){const o=null==s?"":String(s),n=e.indexOf(":");if(n>0){const s=e.slice(0,n),i=l[s];if(i)return void(t.getAttributeNS(i,e)!==o&&t.setAttributeNS(i,e,o))}t.getAttribute(e)!==o&&t.setAttribute(e,o)}function b(t,e,s){const o=a[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||h.has(e))return void p(t,e,s);const n=t,i=n.tagName;if(null!=s){if("src"===o||"href"===o){const e=String(s);if(n[o]===e||t.getAttribute(o)===e)return}if("value"!==o||"INPUT"!==i&&"TEXTAREA"!==i||n.value!==s)if("boolean"!=typeof s)(t instanceof SVGElement||void 0!==n.ownerSVGElement)&&!a[e]?p(t,e,s):n[o]!==s&&(n[o]=s);else{if(n[o]===s)return;n[o]=s}}else if("boolean"==typeof n[o])!1!==n[o]&&(n[o]=!1);else{const s=n[o];""!==s&&void 0!==s&&(n[o]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class y{constructor(t,s,o={}){e(this,"nodeMap",new Map),e(this,"marker",!1),e(this,"staticSubtreeCache",new Map),this.ir=t,this.container=s,this.scope=o}evalIR(t,e,s){var n;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,e):""}catch(r){return o.showTemplateError(r.message||r.toString(),(null==(n=this.ir.m)?void 0:n.src)||"",s,this.scope.tagName),""}}createElement(t,e){const s=t.g;return e instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(t,e){const s=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createTextNode(s)}createComment(t,e){const s=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createComment(s)}applyAttrs(t,e,s,o=!1){const l=[],a=t;let h;a[n]||(a[n]={loops:null}),a[n].loops=s,a[i]||(a[i]=Object.create(null));let f,d=!1,y=!1;for(const r of e){const{k:e,f:c,d:m,v:v}=r;if(":class"===e){h=this.evalIR(c,[s],r.o),d=!0;continue}if(":style"===e){f=this.evalIR(c,[s],r.o),y=!0;continue}if("class"===e||"style"===e)continue;const w=e[0];if("@"===w){const s=e.slice(1),l=r.r??"user";let h=a[i][s];if(h||(h=a[i][s]={model:[],user:[]},t.addEventListener(s,t=>{for(const e of h.model)e(t);for(const e of h.user)e(t)})),!o){const t=t=>this.evalIR(c,[t,a[n].loops],r.o);h[l].push(t)}continue}if("mounted"===e){o||requestAnimationFrame(()=>this.evalIR(c,[t,s],r.o));continue}if("updated"===e){o&&requestAnimationFrame(()=>this.evalIR(c,[t,s],r.o));continue}if("ref"===e&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=t;continue}const S=m?this.evalIR(c,[s],r.o):v??"";if(":"===w){const s=e.slice(1);"SELECT"===t.tagName&&u.has(s)?l.push(()=>b(t,s,S)):b(t,s,S)}else o||p(t,e,String(S))}return d&&((t,e)=>{const s=t,o=s[r],n=function(t){const e={},s=[t];for(;s.length;){const t=s.pop();if(t)if("string"==typeof t){const s=t.split(" ");for(let t=0;t<s.length;t++){const o=s[t].trim();o&&(e[o]=!0)}}else if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push(t[e]);else if("object"==typeof t)for(const s in t)t[s]&&(e[s]=!0)}return e}(e);if(!o){for(const e in n)t.classList.add(e);return void(s[r]=n)}let i=!1;for(const r in o)n[r]||(t.classList.remove(r),i=!0);for(const r in n)o[r]||(t.classList.add(r),i=!0);i&&(s[r]=n)})(t,h),y&&((t,e)=>{const s=t,o=m(e),n=s[c];if(!n){for(const e in o){const s=o[e];e.startsWith("--")?t.style.setProperty(e,s):t.style[e]=s}return void(s[c]=o)}let i=!1;for(const r in n)r in o||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in o){const e=o[r];e!==n[r]&&(r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e,i=!0)}i&&(s[c]=o)})(t,f),l}updateNode(t,e,s){const o=e.d?this.evalIR(e.f,[s],e.o):e.x||"";e.d&&t.textContent!==o&&(t.textContent=o)}createStaticSubtree(t,e,o){var n;switch(t.t){case s.ASTType.Element:{const s=this.createElement(t,e);f(s,t),d(s,t);const i=this.applyAttrs(s,t.a??[],o);return null==(n=t.c)||n.forEach(t=>{const e=this.createStaticSubtree(t,s,o);s.appendChild(e)}),i.forEach(t=>t()),s}case s.ASTType.Text:return this.createText(t,o);case s.ASTType.Comment:return this.createComment(t,o);default:return document.createComment("unknown")}}handleStaticSubtree(t,e,s,o){const n=this.staticSubtreeCache.get(e);if(n){const t=n.cloneNode(!0);return s.appendChild(t),t}const i=this.createStaticSubtree(t,s,o);return s.appendChild(i),this.staticSubtreeCache.set(e,i.cloneNode(!0)),i}irToNode(t,e,o,n,i){var r,c,l,a;const h=o+"-"+e,u=this.nodeMap.get(h);let m;if(1!==t.s)if(u){m=u.node,u.marker=this.marker;let e=[];t.d&&(t.t===s.ASTType.Element?e=this.applyAttrs(m,t.a??[],i,!0):this.updateNode(m,t,i)),null==(r=t.c)||r.forEach((t,e)=>{this.irToNode(t,e,h,m,i)}),e.forEach(t=>t())}else switch(t.t){case s.ASTType.Element:m=this.createElement(t,n),f(m,t),d(m,t);const e=this.applyAttrs(m,t.a??[],i);n.appendChild(m),this.nodeMap.set(h,{irNode:t,node:m,loops:i,marker:this.marker}),null==(c=t.c)||c.forEach((t,e)=>{this.irToNode(t,e,h,m,i)}),e.forEach(t=>t());break;case s.ASTType.Text:m=this.createText(t,i),n.appendChild(m),this.nodeMap.set(h,{irNode:t,node:m,loops:i,marker:this.marker});break;case s.ASTType.Comment:m=this.createComment(t,i),n.appendChild(m),this.nodeMap.set(h,{irNode:t,node:m,loops:i,marker:this.marker});break;case s.ASTType.For:{const e=`${h}-end`;let o=null==(l=this.nodeMap.get(e))?void 0:l.node;o?this.nodeMap.get(e).marker=this.marker:(o=document.createComment(`for:${h}`),n.appendChild(o),this.nodeMap.set(e,{irNode:{t:s.ASTType.Comment},node:o,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],c=document.createDocumentFragment();r.forEach((e,s)=>{var o;const n=[...i,{itmVal:e,idxVal:s}];null==(o=t.c)||o.forEach((t,e)=>{this.irToNode(t,e,`${h}-for-${s}`,c,n)})}),o.parentNode.insertBefore(c,o);break}case s.ASTType.Conditional:{const e=`${h}-end`;let s=null==(a=this.nodeMap.get(e))?void 0:a.node;s?this.nodeMap.get(e).marker=this.marker:(s=document.createComment(`if:${h}`),n.appendChild(s),this.nodeMap.set(e,{irNode:{},node:s,loops:i,marker:this.marker}));for(let o=0;o<(t.b||[]).length;o++){const e=t.b[o];if(null===e.f||this.evalIR(e.f,[i],e.o)){const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.irToNode(e,s,`${h}-if-${o}`,t,i)}),s.parentNode.insertBefore(t,s);break}}break}}else u?(u.marker=this.marker,m=u.node):(m=this.handleStaticSubtree(t,h,n,i),this.nodeMap.set(h,{irNode:t,node:m,loops:i,marker:this.marker}))}cleanupOldNodes(){for(const[t,e]of this.nodeMap.entries())if(e.marker!==this.marker){const{irNode:s,node:o,loops:n}=e;if(s.a){const t=s.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[o,n],t.o)});const e=s.a.find(t=>"ref"===t.k);e&&e.v&&delete this.scope.$refs[e.v]}null==o||o.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear(),this.staticSubtreeCache.clear()}}exports.IRRenderer=y,exports.createRender=(t,e,s={})=>{const o=new y(t,e,s);return o.mount(),{update:()=>o.update(),destroy:()=>o.destroy()}};
@@ -8,6 +8,8 @@ export declare class IRRenderer {
8
8
  private scope;
9
9
  private nodeMap;
10
10
  private marker;
11
+ /** 静态子树缓存:key -> DOM节点模板 */
12
+ private staticSubtreeCache;
11
13
  constructor(ir: IRRoot, container: HTMLElement, scope?: any);
12
14
  evalIR(fid: number, args: any[], meta?: Meta): any;
13
15
  private createElement;
@@ -15,6 +17,16 @@ export declare class IRRenderer {
15
17
  private createComment;
16
18
  private applyAttrs;
17
19
  private updateNode;
20
+ /**
21
+ * 创建静态子树(首次渲染)
22
+ * 内部节点不进入 nodeMap,只返回根节点
23
+ */
24
+ private createStaticSubtree;
25
+ /**
26
+ * 处理静态子树
27
+ * 首次渲染创建并缓存,后续直接克隆
28
+ */
29
+ private handleStaticSubtree;
18
30
  private irToNode;
19
31
  private cleanupOldNodes;
20
32
  mount(): void;
@@ -1 +1 @@
1
- var t=Object.defineProperty,o=(o,e,n)=>((o,e,n)=>e in o?t(o,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[e]=n)(o,"symbol"!=typeof e?e+"":e,n);import{ASTType as e}from"../../types/ast.js";import{showTemplateError as n}from"../../shared/templateError.js";const s=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),l=Symbol("solely.prevStyleObj"),c={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},f={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]);function u(t){const o={},e=[[t]];for(;e.length;){const[t,n]=e.pop();if(t){if("string"==typeof t){const e=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let n;for(;null!==(n=e.exec(t));){const t=n[1].trim(),e=n[2].trim();t&&e&&(o[t]=e)}continue}if(Array.isArray(t))for(let o=t.length-1;o>=0;o--)e.push([t[o]]);else if("object"==typeof t)for(const s in t){const i=t[s];if(null==i)continue;const r=n?`${n}-${s}`:s;"object"!=typeof i||Array.isArray(i)?o[r]=String(i):e.push([i,r])}}}return o}function d(t,o,e){const n=null==e?"":String(e),s=o.indexOf(":");if(s>0){const e=o.slice(0,s),i=c[e];if(i)return void(t.getAttributeNS(i,o)!==n&&t.setAttributeNS(i,o,n))}t.getAttribute(o)!==n&&t.setAttribute(o,n)}function m(t,o,e){const n=f[o]||o;if(o.startsWith("data-")||o.startsWith("aria-")||a.has(o))return void d(t,o,e);const s=t,i=s.tagName;if(null!=e){if("src"===n||"href"===n){const o=String(e);if(s[n]===o||t.getAttribute(n)===o)return}if("value"!==n||"INPUT"!==i&&"TEXTAREA"!==i||s.value!==e)if("boolean"!=typeof e)(t instanceof SVGElement||void 0!==s.ownerSVGElement)&&!f[o]?d(t,o,e):s[n]!==e&&(s[n]=e);else{if(s[n]===e)return;s[n]=e}}else if("boolean"==typeof s[n])!1!==s[n]&&(s[n]=!1);else{const e=s[n];""!==e&&void 0!==e&&(s[n]=""),t.hasAttribute(o)&&t.removeAttribute(o)}}class p{constructor(t,e,n={}){o(this,"nodeMap",new Map),o(this,"marker",!1),this.ir=t,this.container=e,this.scope=n}evalIR(t,o,e){var s;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,o):""}catch(r){return n(r.message||r.toString(),(null==(s=this.ir.m)?void 0:s.src)||"",e,this.scope.tagName),""}}createElement(t,o){const e=t.g;return o instanceof SVGElement||"svg"===e?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}createText(t,o){const e=t.d?this.evalIR(t.f,[o],t.o):t.x||"";return document.createTextNode(e)}createComment(t,o){const e=t.d?this.evalIR(t.f,[o],t.o):t.x||"";return document.createComment(e)}applyAttrs(t,o,e,n=!1){const c=[],f=t;let a;f[s]||(f[s]={loops:null}),f[s].loops=e,f[i]||(f[i]=Object.create(null));let p,y=!1,v=!1;for(const r of o){const{k:o,f:l,d:u,v:b}=r;if(":class"===o){a=this.evalIR(l,[e],r.o),y=!0;continue}if(":style"===o){p=this.evalIR(l,[e],r.o),v=!0;continue}if("class"===o||"style"===o)continue;const w=o[0];if("@"===w){const e=o.slice(1),c=r.r??"user";let a=f[i][e];if(a||(a=f[i][e]={model:[],user:[]},t.addEventListener(e,t=>{for(const o of a.model)o(t);for(const o of a.user)o(t)})),!n){const t=t=>this.evalIR(l,[t,f[s].loops],r.o);a[c].push(t)}continue}if("mounted"===o){n||requestAnimationFrame(()=>this.evalIR(l,[t,e],r.o));continue}if("updated"===o){n&&requestAnimationFrame(()=>this.evalIR(l,[t,e],r.o));continue}if("ref"===o&&b){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[b]=t;continue}const g=u?this.evalIR(l,[e],r.o):b??"";if(":"===w){const e=o.slice(1);"SELECT"===t.tagName&&h.has(e)?c.push(()=>m(t,e,g)):m(t,e,g)}else n||d(t,o,String(g))}return y&&((t,o)=>{const e=t,n=e[r],s=function(t){const o={},e=[t];for(;e.length;){const t=e.pop();if(t)if("string"==typeof t){const e=t.split(" ");for(let t=0;t<e.length;t++){const n=e[t].trim();n&&(o[n]=!0)}}else if(Array.isArray(t))for(let o=t.length-1;o>=0;o--)e.push(t[o]);else if("object"==typeof t)for(const e in t)t[e]&&(o[e]=!0)}return o}(o);if(!n){for(const o in s)t.classList.add(o);return void(e[r]=s)}let i=!1;for(const r in n)s[r]||(t.classList.remove(r),i=!0);for(const r in s)n[r]||(t.classList.add(r),i=!0);i&&(e[r]=s)})(t,a),v&&((t,o)=>{const e=t,n=u(o),s=e[l];if(!s){for(const o in n){const e=n[o];o.startsWith("--")?t.style.setProperty(o,e):t.style[o]=e}return void(e[l]=n)}let i=!1;for(const r in s)r in n||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in n){const o=n[r];o!==s[r]&&(r.startsWith("--")?t.style.setProperty(r,o):t.style[r]=o,i=!0)}i&&(e[l]=n)})(t,p),c}updateNode(t,o,e){const n=o.d?this.evalIR(o.f,[e],o.o):o.x||"";o.d&&t.textContent!==n&&(t.textContent=n)}irToNode(t,o,n,s,i){var r,l,c,f;const a=n+"-"+o,h=this.nodeMap.get(a);let d;if(h){d=h.node,h.marker=this.marker;let o=[];t.d&&(t.t===e.Element?o=this.applyAttrs(d,t.a??[],i,!0):this.updateNode(d,t,i)),null==(r=t.c)||r.forEach((t,o)=>{this.irToNode(t,o,a,d,i)}),o.forEach(t=>t())}else switch(t.t){case e.Element:d=this.createElement(t,s),function(t,o){var e;const n=null==(e=o.a)?void 0:e.find(t=>"class"===t.k&&!t.d);(null==n?void 0:n.v)&&t.setAttribute("class",n.v)}(d,t),function(t,o){var e;if(!t.style)return;const n=null==(e=o.a)?void 0:e.find(t=>"style"===t.k&&!t.d),s=n?u(n.v):{};for(const i in s){const o=s[i];i.startsWith("--")?t.style.setProperty(i,o):t.style[i]=o}}(d,t);const o=this.applyAttrs(d,t.a??[],i);s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker}),null==(l=t.c)||l.forEach((t,o)=>{this.irToNode(t,o,a,d,i)}),o.forEach(t=>t());break;case e.Text:d=this.createText(t,i),s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case e.Comment:d=this.createComment(t,i),s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case e.For:{const o=`${a}-end`;let n=null==(c=this.nodeMap.get(o))?void 0:c.node;n?this.nodeMap.get(o).marker=this.marker:(n=document.createComment(`for:${a}`),s.appendChild(n),this.nodeMap.set(o,{irNode:{t:e.Comment},node:n,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],l=document.createDocumentFragment();r.forEach((o,e)=>{var n;const s=[...i,{itmVal:o,idxVal:e}];null==(n=t.c)||n.forEach((t,o)=>{this.irToNode(t,o,`${a}-for-${e}`,l,s)})}),n.parentNode.insertBefore(l,n);break}case e.Conditional:{const o=`${a}-end`;let e=null==(f=this.nodeMap.get(o))?void 0:f.node;e?this.nodeMap.get(o).marker=this.marker:(e=document.createComment(`if:${a}`),s.appendChild(e),this.nodeMap.set(o,{irNode:{},node:e,loops:i,marker:this.marker}));for(let n=0;n<(t.b||[]).length;n++){const o=t.b[n];if(null===o.f||this.evalIR(o.f,[i],o.o)){const t=document.createDocumentFragment();o.c.forEach((o,e)=>{this.irToNode(o,e,`${a}-if-${n}`,t,i)}),e.parentNode.insertBefore(t,e);break}}break}}}cleanupOldNodes(){for(const[t,o]of this.nodeMap.entries())if(o.marker!==this.marker){const{irNode:e,node:n,loops:s}=o;if(e.a){const t=e.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[n,s],t.o)});const o=e.a.find(t=>"ref"===t.k);o&&o.v&&delete this.scope.$refs[o.v]}null==n||n.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,o)=>{this.irToNode(t,o,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,o)=>{this.irToNode(t,o,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear()}}const y=(t,o,e={})=>{const n=new p(t,o,e);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{p as IRRenderer,y as createRender};
1
+ var t=Object.defineProperty,e=(e,s,o)=>((e,s,o)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o)(e,"symbol"!=typeof s?s+"":s,o);import{ASTType as s}from"../../types/ast.js";import{showTemplateError as o}from"../../shared/templateError.js";const n=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),c=Symbol("solely.prevStyleObj"),l={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},h={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),f=new Set(["value","selectedIndex"]);function u(t,e){var s;const o=null==(s=e.a)?void 0:s.find(t=>"class"===t.k&&!t.d);(null==o?void 0:o.v)&&t.setAttribute("class",o.v)}function d(t,e){var s;if(!t.style)return;const o=null==(s=e.a)?void 0:s.find(t=>"style"===t.k&&!t.d),n=o?m(o.v):{};for(const i in n){const e=n[i];i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e}}function m(t){const e={},s=[[t]];for(;s.length;){const[t,o]=s.pop();if(t){if("string"==typeof t){const s=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let o;for(;null!==(o=s.exec(t));){const t=o[1].trim(),s=o[2].trim();t&&s&&(e[t]=s)}continue}if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push([t[e]]);else if("object"==typeof t)for(const n in t){const i=t[n];if(null==i)continue;const r=o?`${o}-${n}`:n;"object"!=typeof i||Array.isArray(i)?e[r]=String(i):s.push([i,r])}}}return e}function p(t,e,s){const o=null==s?"":String(s),n=e.indexOf(":");if(n>0){const s=e.slice(0,n),i=l[s];if(i)return void(t.getAttributeNS(i,e)!==o&&t.setAttributeNS(i,e,o))}t.getAttribute(e)!==o&&t.setAttribute(e,o)}function y(t,e,s){const o=h[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||a.has(e))return void p(t,e,s);const n=t,i=n.tagName;if(null!=s){if("src"===o||"href"===o){const e=String(s);if(n[o]===e||t.getAttribute(o)===e)return}if("value"!==o||"INPUT"!==i&&"TEXTAREA"!==i||n.value!==s)if("boolean"!=typeof s)(t instanceof SVGElement||void 0!==n.ownerSVGElement)&&!h[e]?p(t,e,s):n[o]!==s&&(n[o]=s);else{if(n[o]===s)return;n[o]=s}}else if("boolean"==typeof n[o])!1!==n[o]&&(n[o]=!1);else{const s=n[o];""!==s&&void 0!==s&&(n[o]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class b{constructor(t,s,o={}){e(this,"nodeMap",new Map),e(this,"marker",!1),e(this,"staticSubtreeCache",new Map),this.ir=t,this.container=s,this.scope=o}evalIR(t,e,s){var n;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,e):""}catch(r){return o(r.message||r.toString(),(null==(n=this.ir.m)?void 0:n.src)||"",s,this.scope.tagName),""}}createElement(t,e){const s=t.g;return e instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(t,e){const s=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createTextNode(s)}createComment(t,e){const s=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createComment(s)}applyAttrs(t,e,s,o=!1){const l=[],h=t;let a;h[n]||(h[n]={loops:null}),h[n].loops=s,h[i]||(h[i]=Object.create(null));let u,d=!1,b=!1;for(const r of e){const{k:e,f:c,d:m,v:v}=r;if(":class"===e){a=this.evalIR(c,[s],r.o),d=!0;continue}if(":style"===e){u=this.evalIR(c,[s],r.o),b=!0;continue}if("class"===e||"style"===e)continue;const w=e[0];if("@"===w){const s=e.slice(1),l=r.r??"user";let a=h[i][s];if(a||(a=h[i][s]={model:[],user:[]},t.addEventListener(s,t=>{for(const e of a.model)e(t);for(const e of a.user)e(t)})),!o){const t=t=>this.evalIR(c,[t,h[n].loops],r.o);a[l].push(t)}continue}if("mounted"===e){o||requestAnimationFrame(()=>this.evalIR(c,[t,s],r.o));continue}if("updated"===e){o&&requestAnimationFrame(()=>this.evalIR(c,[t,s],r.o));continue}if("ref"===e&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=t;continue}const S=m?this.evalIR(c,[s],r.o):v??"";if(":"===w){const s=e.slice(1);"SELECT"===t.tagName&&f.has(s)?l.push(()=>y(t,s,S)):y(t,s,S)}else o||p(t,e,String(S))}return d&&((t,e)=>{const s=t,o=s[r],n=function(t){const e={},s=[t];for(;s.length;){const t=s.pop();if(t)if("string"==typeof t){const s=t.split(" ");for(let t=0;t<s.length;t++){const o=s[t].trim();o&&(e[o]=!0)}}else if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push(t[e]);else if("object"==typeof t)for(const s in t)t[s]&&(e[s]=!0)}return e}(e);if(!o){for(const e in n)t.classList.add(e);return void(s[r]=n)}let i=!1;for(const r in o)n[r]||(t.classList.remove(r),i=!0);for(const r in n)o[r]||(t.classList.add(r),i=!0);i&&(s[r]=n)})(t,a),b&&((t,e)=>{const s=t,o=m(e),n=s[c];if(!n){for(const e in o){const s=o[e];e.startsWith("--")?t.style.setProperty(e,s):t.style[e]=s}return void(s[c]=o)}let i=!1;for(const r in n)r in o||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in o){const e=o[r];e!==n[r]&&(r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e,i=!0)}i&&(s[c]=o)})(t,u),l}updateNode(t,e,s){const o=e.d?this.evalIR(e.f,[s],e.o):e.x||"";e.d&&t.textContent!==o&&(t.textContent=o)}createStaticSubtree(t,e,o){var n;switch(t.t){case s.Element:{const s=this.createElement(t,e);u(s,t),d(s,t);const i=this.applyAttrs(s,t.a??[],o);return null==(n=t.c)||n.forEach(t=>{const e=this.createStaticSubtree(t,s,o);s.appendChild(e)}),i.forEach(t=>t()),s}case s.Text:return this.createText(t,o);case s.Comment:return this.createComment(t,o);default:return document.createComment("unknown")}}handleStaticSubtree(t,e,s,o){const n=this.staticSubtreeCache.get(e);if(n){const t=n.cloneNode(!0);return s.appendChild(t),t}const i=this.createStaticSubtree(t,s,o);return s.appendChild(i),this.staticSubtreeCache.set(e,i.cloneNode(!0)),i}irToNode(t,e,o,n,i){var r,c,l,h;const a=o+"-"+e,f=this.nodeMap.get(a);let m;if(1!==t.s)if(f){m=f.node,f.marker=this.marker;let e=[];t.d&&(t.t===s.Element?e=this.applyAttrs(m,t.a??[],i,!0):this.updateNode(m,t,i)),null==(r=t.c)||r.forEach((t,e)=>{this.irToNode(t,e,a,m,i)}),e.forEach(t=>t())}else switch(t.t){case s.Element:m=this.createElement(t,n),u(m,t),d(m,t);const e=this.applyAttrs(m,t.a??[],i);n.appendChild(m),this.nodeMap.set(a,{irNode:t,node:m,loops:i,marker:this.marker}),null==(c=t.c)||c.forEach((t,e)=>{this.irToNode(t,e,a,m,i)}),e.forEach(t=>t());break;case s.Text:m=this.createText(t,i),n.appendChild(m),this.nodeMap.set(a,{irNode:t,node:m,loops:i,marker:this.marker});break;case s.Comment:m=this.createComment(t,i),n.appendChild(m),this.nodeMap.set(a,{irNode:t,node:m,loops:i,marker:this.marker});break;case s.For:{const e=`${a}-end`;let o=null==(l=this.nodeMap.get(e))?void 0:l.node;o?this.nodeMap.get(e).marker=this.marker:(o=document.createComment(`for:${a}`),n.appendChild(o),this.nodeMap.set(e,{irNode:{t:s.Comment},node:o,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],c=document.createDocumentFragment();r.forEach((e,s)=>{var o;const n=[...i,{itmVal:e,idxVal:s}];null==(o=t.c)||o.forEach((t,e)=>{this.irToNode(t,e,`${a}-for-${s}`,c,n)})}),o.parentNode.insertBefore(c,o);break}case s.Conditional:{const e=`${a}-end`;let s=null==(h=this.nodeMap.get(e))?void 0:h.node;s?this.nodeMap.get(e).marker=this.marker:(s=document.createComment(`if:${a}`),n.appendChild(s),this.nodeMap.set(e,{irNode:{},node:s,loops:i,marker:this.marker}));for(let o=0;o<(t.b||[]).length;o++){const e=t.b[o];if(null===e.f||this.evalIR(e.f,[i],e.o)){const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.irToNode(e,s,`${a}-if-${o}`,t,i)}),s.parentNode.insertBefore(t,s);break}}break}}else f?(f.marker=this.marker,m=f.node):(m=this.handleStaticSubtree(t,a,n,i),this.nodeMap.set(a,{irNode:t,node:m,loops:i,marker:this.marker}))}cleanupOldNodes(){for(const[t,e]of this.nodeMap.entries())if(e.marker!==this.marker){const{irNode:s,node:o,loops:n}=e;if(s.a){const t=s.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[o,n],t.o)});const e=s.a.find(t=>"ref"===t.k);e&&e.v&&delete this.scope.$refs[e.v]}null==o||o.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear(),this.staticSubtreeCache.clear()}}const v=(t,e,s={})=>{const o=new b(t,e,s);return o.mount(),{update:()=>o.update(),destroy:()=>o.destroy()}};export{b as IRRenderer,v as createRender};
@@ -1,5 +1,5 @@
1
1
  import { IRLocal } from '../types';
2
- export type GenType = "template" | "handler" | "expression" | "lifecycle";
2
+ export type GenType = 'template' | 'handler' | 'expression' | 'lifecycle';
3
3
  /**
4
4
  * 主入口:生成可执行的函数(支持上层捕获异常)
5
5
  * 注意:缓存逻辑由上层 FunctionCompiler 统一管理,此处不做重复缓存
@@ -49,6 +49,12 @@ export interface IRNode {
49
49
  t: ASTType;
50
50
  /** dynamicFlag (0=静态, 1=动态) 不包含子节点状态 */
51
51
  d: 0 | 1;
52
+ /**
53
+ * staticSubtreeFlag (0=非静态子树, 1=完全静态子树)
54
+ * 当 s=1 时,表示该节点及其所有后代都是静态的
55
+ * 运行时可以直接 cloneNode 而无需递归创建
56
+ */
57
+ s?: 0 | 1;
52
58
  /** tagName 标签名(Element 使用) */
53
59
  g?: string;
54
60
  /** attributes 属性数组(Element 使用) */
@@ -88,6 +94,8 @@ export interface IRRoot {
88
94
  dn: number;
89
95
  /** 总节点数 */
90
96
  tn: number;
97
+ /** 静态子树数量 */
98
+ sn?: number;
91
99
  };
92
100
  /** meta 编译元数据 */
93
101
  m?: {
package/package.json CHANGED
@@ -1,212 +1,233 @@
1
- {
2
- "name": "solely",
3
- "private": false,
4
- "version": "0.1.10",
5
- "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
- "type": "module",
7
- "sideEffects": false,
8
- "main": "./dist/index.cjs",
9
- "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./dist/index.js"
16
- },
17
- "require": {
18
- "types": "./dist/index.d.ts",
19
- "default": "./dist/index.cjs"
20
- }
21
- },
22
- "./plugin": {
23
- "import": {
24
- "types": "./dist/plugin.d.ts",
25
- "default": "./dist/plugin.js"
26
- },
27
- "require": {
28
- "types": "./dist/plugin.d.ts",
29
- "default": "./dist/plugin.cjs"
30
- }
31
- },
32
- "./compiler": {
33
- "import": {
34
- "types": "./dist/compiler/index.d.ts",
35
- "default": "./dist/compiler/index.js"
36
- },
37
- "require": {
38
- "types": "./dist/compiler/index.d.ts",
39
- "default": "./dist/compiler/index.cjs"
40
- }
41
- },
42
- "./compiler/*": {
43
- "import": {
44
- "types": "./dist/compiler/*.d.ts",
45
- "default": "./dist/compiler/*.js"
46
- },
47
- "require": {
48
- "types": "./dist/compiler/*.d.ts",
49
- "default": "./dist/compiler/*.cjs"
50
- }
51
- },
52
- "./runtime": {
53
- "import": {
54
- "types": "./dist/runtime/index.d.ts",
55
- "default": "./dist/runtime/index.js"
56
- },
57
- "require": {
58
- "types": "./dist/runtime/index.d.ts",
59
- "default": "./dist/runtime/index.cjs"
60
- }
61
- },
62
- "./runtime/*": {
63
- "import": {
64
- "types": "./dist/runtime/*.d.ts",
65
- "default": "./dist/runtime/*.js"
66
- },
67
- "require": {
68
- "types": "./dist/runtime/*.d.ts",
69
- "default": "./dist/runtime/*.cjs"
70
- }
71
- },
72
- "./router": {
73
- "import": {
74
- "types": "./dist/router/index.d.ts",
75
- "default": "./dist/router/index.js"
76
- },
77
- "require": {
78
- "types": "./dist/router/index.d.ts",
79
- "default": "./dist/router/index.cjs"
80
- }
81
- },
82
- "./router/*": {
83
- "import": {
84
- "types": "./dist/router/*.d.ts",
85
- "default": "./dist/router/*.js"
86
- },
87
- "require": {
88
- "types": "./dist/router/*.d.ts",
89
- "default": "./dist/router/*.cjs"
90
- }
91
- },
92
- "./shared": {
93
- "import": {
94
- "types": "./dist/shared/index.d.ts",
95
- "default": "./dist/shared/index.js"
96
- },
97
- "require": {
98
- "types": "./dist/shared/index.d.ts",
99
- "default": "./dist/shared/index.cjs"
100
- }
101
- },
102
- "./shared/*": {
103
- "import": {
104
- "types": "./dist/shared/*.d.ts",
105
- "default": "./dist/shared/*.js"
106
- },
107
- "require": {
108
- "types": "./dist/shared/*.d.ts",
109
- "default": "./dist/shared/*.cjs"
110
- }
111
- },
112
- "./types": {
113
- "import": {
114
- "types": "./dist/types/index.d.ts",
115
- "default": "./dist/types/index.js"
116
- },
117
- "require": {
118
- "types": "./dist/types/index.d.ts",
119
- "default": "./dist/types/index.cjs"
120
- }
121
- },
122
- "./types/*": {
123
- "import": {
124
- "types": "./dist/types/*.d.ts",
125
- "default": "./dist/types/*.js"
126
- },
127
- "require": {
128
- "types": "./dist/types/*.d.ts",
129
- "default": "./dist/types/*.cjs"
130
- }
131
- },
132
- "./package.json": "./package.json"
133
- },
134
- "typesVersions": {
135
- "*": {
136
- "*": [
137
- "./dist/*"
138
- ]
139
- }
140
- },
141
- "files": [
142
- "dist",
143
- "README.md",
144
- "LICENSE"
145
- ],
146
- "keywords": [
147
- "ast",
148
- "vnode",
149
- "template",
150
- "custom-element",
151
- "web-component",
152
- "framework",
153
- "library",
154
- "ui",
155
- "component",
156
- "design",
157
- "development",
158
- "esm",
159
- "tree-shaking"
160
- ],
161
- "author": "Sun Yue",
162
- "license": "MIT",
163
- "repository": {
164
- "type": "git",
165
- "url": "git+https://github.com/yourusername/solely.git"
166
- },
167
- "bugs": {
168
- "url": "https://github.com/yourusername/solely/issues"
169
- },
170
- "homepage": "https://github.com/yourusername/solely#readme",
171
- "engines": {
172
- "node": ">=16.0.0"
173
- },
174
- "scripts": {
175
- "dev": "vite",
176
- "build": "vite build",
177
- "build:watch": "vite build --watch",
178
- "build:examples": "vite build --mode examples",
179
- "preview": "vite preview",
180
- "preview:examples": "vite preview --outDir dist-examples",
181
- "link": "npm link && echo '✅ 全局链接成功,可在其他项目中使用 npm link solely'",
182
- "unlink": "npm unlink -g solely && echo '✅ 已取消全局链接'",
183
- "test": "vitest",
184
- "test:ui": "vitest --ui",
185
- "test:coverage": "vitest --coverage",
186
- "typecheck": "tsc --noEmit",
187
- "lint": "echo '请添加 ESLint 配置'",
188
- "clean": "rimraf dist",
189
- "prebuild": "npm run clean",
190
- "prepublishOnly": "npm run build && npm run test",
191
- "pack:local": "npm pack && echo '✅ 打包完成,可在其他项目中使用 file: 引用'",
192
- "dev:debug": "node --inspect-brk ./node_modules/vite/bin/vite.js"
193
- },
194
- "devDependencies": {
195
- "@rollup/plugin-strip": "^3.0.4",
196
- "@testing-library/dom": "^10.4.1",
197
- "@testing-library/user-event": "^14.6.1",
198
- "@types/node": "^22.10.2",
199
- "@vitest/coverage-v8": "^3.2.4",
200
- "@vitest/ui": "^3.2.4",
201
- "jsdom": "27.0.0",
202
- "magic-string": "^0.30.21",
203
- "rimraf": "^5.0.10",
204
- "sass": "^1.83.0",
205
- "terser": "^5.44.0",
206
- "tsup": "^8.5.1",
207
- "typescript": "~5.6.2",
208
- "vite": "^5.4.10",
209
- "vite-plugin-dts": "^4.4.0",
210
- "vitest": "^3.2.4"
211
- }
212
- }
1
+ {
2
+ "name": "solely",
3
+ "private": false,
4
+ "version": "0.2.0",
5
+ "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "./plugin": {
23
+ "import": {
24
+ "types": "./dist/plugin.d.ts",
25
+ "default": "./dist/plugin.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/plugin.d.ts",
29
+ "default": "./dist/plugin.cjs"
30
+ }
31
+ },
32
+ "./compiler": {
33
+ "import": {
34
+ "types": "./dist/compiler/index.d.ts",
35
+ "default": "./dist/compiler/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/compiler/index.d.ts",
39
+ "default": "./dist/compiler/index.cjs"
40
+ }
41
+ },
42
+ "./compiler/*": {
43
+ "import": {
44
+ "types": "./dist/compiler/*.d.ts",
45
+ "default": "./dist/compiler/*.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/compiler/*.d.ts",
49
+ "default": "./dist/compiler/*.cjs"
50
+ }
51
+ },
52
+ "./runtime": {
53
+ "import": {
54
+ "types": "./dist/runtime/index.d.ts",
55
+ "default": "./dist/runtime/index.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/runtime/index.d.ts",
59
+ "default": "./dist/runtime/index.cjs"
60
+ }
61
+ },
62
+ "./runtime/*": {
63
+ "import": {
64
+ "types": "./dist/runtime/*.d.ts",
65
+ "default": "./dist/runtime/*.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/runtime/*.d.ts",
69
+ "default": "./dist/runtime/*.cjs"
70
+ }
71
+ },
72
+ "./router": {
73
+ "import": {
74
+ "types": "./dist/router/index.d.ts",
75
+ "default": "./dist/router/index.js"
76
+ },
77
+ "require": {
78
+ "types": "./dist/router/index.d.ts",
79
+ "default": "./dist/router/index.cjs"
80
+ }
81
+ },
82
+ "./router/*": {
83
+ "import": {
84
+ "types": "./dist/router/*.d.ts",
85
+ "default": "./dist/router/*.js"
86
+ },
87
+ "require": {
88
+ "types": "./dist/router/*.d.ts",
89
+ "default": "./dist/router/*.cjs"
90
+ }
91
+ },
92
+ "./shared": {
93
+ "import": {
94
+ "types": "./dist/shared/index.d.ts",
95
+ "default": "./dist/shared/index.js"
96
+ },
97
+ "require": {
98
+ "types": "./dist/shared/index.d.ts",
99
+ "default": "./dist/shared/index.cjs"
100
+ }
101
+ },
102
+ "./shared/*": {
103
+ "import": {
104
+ "types": "./dist/shared/*.d.ts",
105
+ "default": "./dist/shared/*.js"
106
+ },
107
+ "require": {
108
+ "types": "./dist/shared/*.d.ts",
109
+ "default": "./dist/shared/*.cjs"
110
+ }
111
+ },
112
+ "./types": {
113
+ "import": {
114
+ "types": "./dist/types/index.d.ts",
115
+ "default": "./dist/types/index.js"
116
+ },
117
+ "require": {
118
+ "types": "./dist/types/index.d.ts",
119
+ "default": "./dist/types/index.cjs"
120
+ }
121
+ },
122
+ "./types/*": {
123
+ "import": {
124
+ "types": "./dist/types/*.d.ts",
125
+ "default": "./dist/types/*.js"
126
+ },
127
+ "require": {
128
+ "types": "./dist/types/*.d.ts",
129
+ "default": "./dist/types/*.cjs"
130
+ }
131
+ },
132
+ "./package.json": "./package.json"
133
+ },
134
+ "typesVersions": {
135
+ "*": {
136
+ "*": [
137
+ "./dist/*"
138
+ ]
139
+ }
140
+ },
141
+ "files": [
142
+ "dist",
143
+ "README.md",
144
+ "LICENSE"
145
+ ],
146
+ "keywords": [
147
+ "ast",
148
+ "vnode",
149
+ "template",
150
+ "custom-element",
151
+ "web-component",
152
+ "framework",
153
+ "library",
154
+ "ui",
155
+ "component",
156
+ "design",
157
+ "development",
158
+ "esm",
159
+ "tree-shaking"
160
+ ],
161
+ "lint-staged": {
162
+ "*.{ts,tsx}": [
163
+ "eslint --fix",
164
+ "prettier --write"
165
+ ],
166
+ "*.{json,md}": [
167
+ "prettier --write"
168
+ ]
169
+ },
170
+ "author": "Sun Yue",
171
+ "license": "MIT",
172
+ "repository": {
173
+ "type": "git",
174
+ "url": "git+https://github.com/solelyjs/solely.git"
175
+ },
176
+ "bugs": {
177
+ "url": "https://github.com/solelyjs/solely/issues"
178
+ },
179
+ "homepage": "https://github.com/solelyjs/solely#readme",
180
+ "engines": {
181
+ "node": ">=16.0.0"
182
+ },
183
+ "scripts": {
184
+ "dev": "vite",
185
+ "build": "vite build",
186
+ "build:watch": "vite build --watch",
187
+ "build:examples": "vite build --mode examples",
188
+ "preview": "vite preview",
189
+ "preview:examples": "vite preview --outDir dist-examples",
190
+ "link": "npm link && echo '✅ 全局链接成功,可在其他项目中使用 npm link solely'",
191
+ "unlink": "npm unlink -g solely && echo '✅ 已取消全局链接'",
192
+ "test": "vitest",
193
+ "test:ui": "vitest --ui",
194
+ "test:coverage": "vitest --coverage",
195
+ "typecheck": "tsc --noEmit",
196
+ "lint": "eslint . --ext .ts,.tsx",
197
+ "lint:fix": "eslint . --ext .ts,.tsx --fix",
198
+ "format": "prettier --write \"src/**/*.{ts,tsx,js,json,md}\"",
199
+ "format:check": "prettier --check \"src/**/*.{ts,tsx,js,json,md}\"",
200
+ "clean": "rimraf dist",
201
+ "prebuild": "npm run clean",
202
+ "prepublishOnly": "npm run build && npm run test",
203
+ "pack:local": "npm pack && echo '✅ 打包完成,可在其他项目中使用 file: 引用'",
204
+ "dev:debug": "node --inspect-brk ./node_modules/vite/bin/vite.js",
205
+ "prepare": "husky"
206
+ },
207
+ "devDependencies": {
208
+ "@rollup/plugin-strip": "^3.0.4",
209
+ "@testing-library/dom": "^10.4.1",
210
+ "@testing-library/user-event": "^14.6.1",
211
+ "@types/node": "^22.10.2",
212
+ "@commitlint/cli": "^19.0.0",
213
+ "@commitlint/config-conventional": "^19.0.0",
214
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
215
+ "@typescript-eslint/parser": "^8.0.0",
216
+ "@vitest/coverage-v8": "^3.2.4",
217
+ "@vitest/ui": "^3.2.4",
218
+ "eslint": "^8.57.0",
219
+ "husky": "^9.0.0",
220
+ "jsdom": "27.0.0",
221
+ "lint-staged": "^15.0.0",
222
+ "magic-string": "^0.30.21",
223
+ "prettier": "^3.0.0",
224
+ "rimraf": "^5.0.10",
225
+ "sass": "^1.83.0",
226
+ "terser": "^5.44.0",
227
+ "tsup": "^8.5.1",
228
+ "typescript": "~5.6.2",
229
+ "vite": "^5.4.10",
230
+ "vite-plugin-dts": "^4.4.0",
231
+ "vitest": "^3.2.4"
232
+ }
233
+ }