@akashjs/compiler 0.1.12 → 0.1.14
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/index.cjs +16 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
import {createHash}from'crypto';function v(e){return {script:w(e,"script",(t,n,r,i)=>({content:t,lang:Z(n,"lang")??"ts",start:r,end:i})),template:w(e,"template",(t,n,r,i)=>({content:t,start:r,end:i})),style:w(e,"style",(t,n,r,i)=>({content:t,scoped:n.includes("scoped"),start:r,end:i}))}}function w(e,t,n){let r=new RegExp(`<${t}(\\b[^>]*)>`,"i"),i=new RegExp(`</${t}>`,"i"),s=r.exec(e);if(!s)return null;let o=s[1]??"",l=s.index+s[0].length,p=i.exec(e.slice(l));if(!p)return null;let u=l+p.index,c=e.slice(l,u);return n(c.trim(),o,l,u)}function Z(e,t){return new RegExp(`${t}=["']([^"']+)["']`).exec(e)?.[1]??null}function h(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="<"){if(e[n+1]==="/")break;let s=K(e,n);if(s){t.push(s.node),n=s.end;continue}}if(e[n]==="{"){let s=Q(e,n);if(s){t.push(s.node),n=s.end;continue}}let r=X(e,n),i=e.slice(n,r).trim();i&&t.push({type:"text",content:i}),n=r;}return t}function K(e,t){let n=/^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(e.slice(t));if(!n)return null;let r=n[1],i=t+n[0].length,s=[],o=[];for(;i<e.length;){let g=/^\s+/.exec(e.slice(i));if(g&&(i+=g[0].length),e[i]===">"||e.slice(i,i+2)==="/>")break;let
|
|
2
|
-
`);let{cleanScript:c,propsInterface:a}=ue(s),{userImports:
|
|
1
|
+
import {createHash}from'crypto';function v(e){return {script:w(e,"script",(t,n,r,i)=>({content:t,lang:Z(n,"lang")??"ts",start:r,end:i})),template:w(e,"template",(t,n,r,i)=>({content:t,start:r,end:i})),style:w(e,"style",(t,n,r,i)=>({content:t,scoped:n.includes("scoped"),start:r,end:i}))}}function w(e,t,n){let r=new RegExp(`<${t}(\\b[^>]*)>`,"i"),i=new RegExp(`</${t}>`,"i"),s=r.exec(e);if(!s)return null;let o=s[1]??"",l=s.index+s[0].length,p=i.exec(e.slice(l));if(!p)return null;let u=l+p.index,c=e.slice(l,u);return n(c.trim(),o,l,u)}function Z(e,t){return new RegExp(`${t}=["']([^"']+)["']`).exec(e)?.[1]??null}function h(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="<"){if(e[n+1]==="/")break;let s=K(e,n);if(s){t.push(s.node),n=s.end;continue}}if(e[n]==="{"){let s=Q(e,n);if(s){t.push(s.node),n=s.end;continue}}let r=X(e,n+1),i=e.slice(n,r).trim();i&&t.push({type:"text",content:i}),n=r;}return t}function K(e,t){let n=/^<([a-zA-Z][a-zA-Z0-9-]*)/.exec(e.slice(t));if(!n)return null;let r=n[1],i=t+n[0].length,s=[],o=[];for(;i<e.length;){let g=/^\s+/.exec(e.slice(i));if(g&&(i+=g[0].length),e[i]===">"||e.slice(i,i+2)==="/>")break;let m=q(e,i);m?(m.attr.name.startsWith("bind:")?o.push({name:"bind",arg:m.attr.name.slice(5),value:m.attr.value}):m.attr.name.startsWith(":")?o.push({name:m.attr.name.slice(1),value:m.attr.value}):s.push(m.attr),i=m.end):i++;}let l=r[0]===r[0].toUpperCase();if(e.slice(i,i+2)==="/>")return {node:{type:l?"component":"element",tag:r,attrs:s,directives:o.length>0?o:void 0,children:[]},end:i+2};i++;let p=h(e.slice(i));e.slice(i);let c=`</${r}>`,a=Y(e,i,r);if(a===-1)return {node:{type:l?"component":"element",tag:r,attrs:s,directives:o.length>0?o:void 0,children:p},end:e.length};let d=e.slice(i,a),f=h(d);return {node:{type:l?"component":"element",tag:r,attrs:s,directives:o.length>0?o:void 0,children:f},end:a+c.length}}function q(e,t){let n=/^(?:bind:|[:a-zA-Z_])[\w:.-]*/.exec(e.slice(t));if(!n)return null;let r=n[0],i=t+r.length;if(e[i]!=="=")return {attr:{name:r,value:"true",dynamic:false},end:i};if(i++,e[i]==="{"){let o=j(e,i);if(o)return {attr:{name:r,value:o.content,dynamic:true},end:o.end}}let s=e[i];if(s==='"'||s==="'"){let o=e.indexOf(s,i+1);return o===-1?null:{attr:{name:r,value:e.slice(i+1,o),dynamic:false},end:o+1}}return null}function Q(e,t){let n=j(e,t);return n?{node:{type:"expression",content:n.content},end:n.end}:null}function j(e,t){if(e[t]!=="{")return null;let n=1,r=t+1;for(;r<e.length&&n>0;){let i=e[r];if(i==='"'||i==="'"||i==="`"){r=G(e,r)+1;continue}i==="{"?n++:i==="}"&&n--,r++;}return {content:e.slice(t+1,r-1).trim(),end:r}}function G(e,t){let n=e[t],r=t+1;for(;r<e.length;){if(e[r]==="\\"){r+=2;continue}if(e[r]===n)return r;r++;}return r}function X(e,t){let n=t;for(;n<e.length;){if(e[n]==="<"||e[n]==="{")return n;n++;}return n}function Y(e,t,n){let r=`</${n}>`,i=1,s=t,o=e.length*2,l=0;for(;s<e.length&&l++<o;){let p=e.indexOf(`<${n}`,s),u=e.indexOf(r,s);if(u===-1)return -1;if(p!==-1&&p<u){let c=ee(e,p);c!==-1&&e[c-1]==="/"?s=c+1:c!==-1?(i++,s=c+1):s=p+1;}else {if(i--,i===0)return u;s=u+1;}}return -1}function ee(e,t){let n=t,r=0;for(;n<e.length;){let i=e[n];if(i==="{")r++;else if(i==="}")r--;else if(i===">"&&r===0)return n;n++;}return -1}function E(e){return `data-a-${createHash("md5").update(e).digest("hex").slice(0,6)}`}function N(e,t){return P(e,t)}function P(e,t,n){let r="",i=0;for(;i<e.length;){let s=/^\s+/.exec(e.slice(i));if(s&&(r+=s[0],i+=s[0].length,i>=e.length))break;if(e.slice(i,i+2)==="/*"){let d=e.indexOf("*/",i+2);if(d===-1){r+=e.slice(i);break}r+=e.slice(i,d+2),i=d+2;continue}if(e[i]==="}"){r+="}",i++;continue}let o=e.indexOf("{",i);if(o===-1){r+=e.slice(i);break}let l=e.slice(i,o),p=l.trim(),u=o+1,c=ne(e,o),a=e.slice(u,c);if(p.startsWith("@")){let d=p.split(/\s/)[0];d==="@keyframes"||d==="@-webkit-keyframes"||d==="@font-face"?r+=l+"{"+a+"}":r+=l+"{"+P(a,t)+"}";}else {let d=re(p,t);r+=l.replace(p,d)+"{"+a+"}";}i=c+1;}return r}function ne(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;)e[r]==="{"?n++:e[r]==="}"&&n--,n>0&&r++;return r}function re(e,t){return e.split(",").map(n=>{let r=n.trim();return !r||r===":root"||r===":host"||r.includes(t)?n:ie(r,t)}).join(",")}function ie(e,t){let n=e.split(/(\s*[>+~]\s*|\s+)/);for(let r=n.length-1;r>=0;r--){let i=n[r].trim();if(i&&!se(i)){if(i.includes("::")){let[s,o]=i.split("::");n[r]=n[r].replace(i,`${s}[${t}]::${o}`);}else if(i.includes(":")){let s=i.indexOf(":"),o=i.slice(0,s),l=i.slice(s);n[r]=n[r].replace(i,`${o}[${t}]${l}`);}else n[r]=n[r].replace(i,`${i}[${t}]`);break}}return n.join("")}function se(e){return e===">"||e==="+"||e==="~"}function L(e,t={}){let n=t.scopeId??(t.filename?E(t.filename):void 0),i=new Set;i.add("defineComponent");let s=e.script?.content??"",o=e.template?.content??"";le(s,o,i);let l=t.mode==="server",p="";if(e.template){let b=h(e.template.content);l?p=me(b,i,n):p=pe(b,i,n);}let u="";i.size>0&&(u+=`import { ${[...i].join(", ")} } from '@akashjs/runtime';
|
|
2
|
+
`);let{cleanScript:c,propsInterface:a}=ue(s),{userImports:d,bodyScript:f}=ce(c);d.length>0&&(u+=d.join(`
|
|
3
3
|
`)+`
|
|
4
4
|
`);let g=a?`<${a}>`:"";if(u+=`
|
|
5
5
|
`,u+=`export default defineComponent${g}((ctx) => {
|
|
6
6
|
`,s.includes("props")&&(u+=` const props = ctx.props;
|
|
7
|
-
`),
|
|
7
|
+
`),f.trim()){let b=f.trim().split(`
|
|
8
8
|
`).map(_=>` ${_}`).join(`
|
|
9
9
|
`);u+=`${b}
|
|
10
10
|
`;}u+=`
|
|
11
11
|
`,u+=` return () => {
|
|
12
12
|
`,u+=p,u+=` };
|
|
13
13
|
`,u+=`});
|
|
14
|
-
`;let
|
|
15
|
-
`),n=[],r=[],i=false;for(let
|
|
16
|
-
`+
|
|
14
|
+
`;let m;return e.style&&(m=e.style.scoped&&n?N(e.style.content,n):e.style.content),{code:u,css:m}}function oe(e){let t=e.trim();return !!(/^(?:\([^)]*\)|[a-zA-Z_$]\w*)\s*=>/.test(t)||/^function[\s(]/.test(t))}function ae(e){let t=e.trim();return /^\[/.test(t)&&!t.includes("(")||/^\{/.test(t)&&!t.includes("(")||/^["'`]/.test(t)||/^\d/.test(t)||t==="true"||t==="false"||t==="null"||t==="undefined"||t.startsWith("`")&&!t.includes("(")?false:/\w\(/.test(t)?true:!(/^[a-zA-Z_$][\w$.]*$/.test(t)||!t.includes("("))}function le(e,t,n){let r=["signal","computed","effect","batch","untrack","onMount","onUnmount","onError","ref","createContext","provide","inject","Show","For"];for(let s of r){let o=new RegExp(`\\b${s}\\b`),l=new RegExp(`import\\s+.*\\b${s}\\b.*from`);o.test(e)&&!l.test(e)&&n.add(s);}let i=["Show","For"];for(let s of i)new RegExp(`<${s}[\\s/>]`).test(t)&&!n.has(s)&&n.add(s);}function ce(e){let t=e.split(`
|
|
15
|
+
`),n=[],r=[],i=false,s=false;for(let o of t){if(i){n[n.length-1]+=`
|
|
16
|
+
`+o,(o.includes("from ")||o.trimEnd().endsWith(";"))&&(i=false);continue}if(s){n[n.length-1]+=`
|
|
17
|
+
`+o,(o.trimEnd().endsWith("}")||o.trimEnd().endsWith("};"))&&(s=false);continue}let l=o.trim();/^import\s/.test(l)?(n.push(o.trim()),!l.includes("from ")&&!l.endsWith(";")&&(i=true)):/^export\s+(interface|type|enum)\s/.test(l)?(n.push(o.trim()),!l.endsWith("}")&&!l.endsWith("};")&&!l.endsWith(";")&&(s=true)):/^export\s+(const|let|var|function|class)\s/.test(l)?r.push(o.replace(/\bexport\s+/,"")):/^declare\s/.test(l)?(n.push(o.trim()),!l.endsWith("}")&&!l.endsWith("};")&&!l.endsWith(";")&&(s=true)):r.push(o);}return {userImports:n,bodyScript:r.join(`
|
|
17
18
|
`)}}function ue(e){let t=/interface\s+Props\s*\{([^}]*)\}/s.exec(e);if(!t)return {cleanScript:e,propsInterface:null};let n=e.replace(t[0],"").trim(),r=`{${t[1].trim()}}`;return {cleanScript:n,propsInterface:r}}function pe(e,t,n){if(e.length===0)return ` return null;
|
|
18
19
|
`;if(e.length===1){let i=[];return $(e[0],i,t,4,"root",n),i.push(" return root;"),i.join(`
|
|
19
20
|
`)+`
|
|
20
21
|
`}t.add("createElement");let r=[];r.push(" const __fragment = document.createDocumentFragment();");for(let i=0;i<e.length;i++){let s=`__n${i}`;$(e[i],r,t,4,s,n),r.push(` __fragment.appendChild(${s});`);}return r.push(" return __fragment;"),r.join(`
|
|
21
22
|
`)+`
|
|
22
|
-
`}function $(e,t,n,r,i,s){let o=" ".repeat(r);switch(e.type){case "element":
|
|
23
|
+
`}function $(e,t,n,r,i,s){let o=" ".repeat(r);switch(e.type){case "element":R(e,t,n,r,i,s);break;case "component":de(e,t,n,r,i,s);break;case "text":t.push(`${o}const ${i} = document.createTextNode(${JSON.stringify(e.content??"")});`);break;case "expression":n.add("effect"),t.push(`${o}const ${i} = document.createTextNode('');`),t.push(`${o}effect(() => { ${i}.textContent = String(${e.content}); }, { render: true });`);break}}function R(e,t,n,r,i,s){let o=" ".repeat(r),l=e.tag,p=e.directives?.find(a=>a.name==="if");if(p){n.add("renderConditional"),t.push(`${o}const ${i}_anchor = document.createComment('if');`),t.push(`${o}const ${i} = document.createDocumentFragment();`),t.push(`${o}${i}.appendChild(${i}_anchor);`),t.push(`${o}renderConditional(${i}, ${i}_anchor, () => ${p.value}, () => {`);let a=[],d={...e,directives:e.directives?.filter(f=>f.name!=="if")};R(d,a,n,r+2,"__el",s),a.push(`${o} return __el;`),t.push(...a),t.push(`${o}});`);return}let u=e.directives?.find(a=>a.name==="for");if(u){n.add("renderList");let a=e.directives?.find(f=>f.name==="key"),d=/^(?:\(([^)]+)\)|(\w+))\s+of\s+(.+)$/.exec(u.value);if(d){let f=d[1]??d[2],g=d[3],m=a?.value??`${f}`;t.push(`${o}const ${i}_anchor = document.createComment('for');`),t.push(`${o}const ${i} = document.createDocumentFragment();`),t.push(`${o}${i}.appendChild(${i}_anchor);`),t.push(`${o}renderList(${i}, ${i}_anchor, () => ${g}, (${f}) => ${m}, (${f}) => {`);let b=[],_={...e,directives:e.directives?.filter(M=>M.name!=="for"&&M.name!=="key")};R(_,b,n,r+2,"__el",s),b.push(`${o} return __el;`),t.push(...b),t.push(`${o}});`);}return}let c=e.directives?.filter(a=>a.name==="bind")??[];if(c.length>0&&e.directives&&(e.directives=e.directives.filter(a=>a.name!=="bind")),t.push(`${o}const ${i} = document.createElement('${l}');`),s&&t.push(`${o}${i}.setAttribute('${s}', '');`),e.attrs)for(let a of e.attrs)a.dynamic?(n.add("effect"),a.name.startsWith("on")?t.push(`${o}${i}.addEventListener('${a.name.slice(2).toLowerCase()}', ${a.value});`):(t.push(`${o}effect(() => {`),a.name==="class"||a.name==="className"?t.push(`${o} ${i}.className = ${a.value};`):t.push(`${o} ${i}.setAttribute('${a.name}', String(${a.value}));`),t.push(`${o}}, { render: true });`))):a.name==="class"||a.name==="className"?t.push(`${o}${i}.className = ${JSON.stringify(a.value)};`):a.name.startsWith("on")?t.push(`${o}${i}.setAttribute('${a.name}', ${JSON.stringify(a.value)});`):t.push(`${o}${i}.setAttribute('${a.name}', ${JSON.stringify(a.value)});`);for(let a of c){let d=a.arg??"value",f=a.value;n.add("effect"),t.push(`${o}effect(() => { ${i}.${d} = ${f}(); }, { render: true });`);let g=d==="value"||d==="checked"?"input":"change",m=d==="checked"?"checked":"value";t.push(`${o}${i}.addEventListener('${g}', (e) => { ${f}.set(e.target.${m}); });`);}if(e.children&&e.children.length>0)for(let a=0;a<e.children.length;a++){let d=`${i}_c${a}`;$(e.children[a],t,n,r,d,s),t.push(`${o}${i}.appendChild(${d});`);}}function de(e,t,n,r,i,s){let o=" ".repeat(r),l=e.tag,p=l==="Show"||l==="For"||l==="Switch",u=[];if(e.attrs)for(let a of e.attrs)if(a.dynamic){let d=fe(a.value,n,r,s);d?u.push(`${a.name}: ${d}`):a.name.startsWith("on")||oe(a.value)?u.push(`${a.name}: ${a.value}`):p&&ae(a.value)?u.push(`${a.name}: () => ${a.value}`):u.push(`${a.name}: ${a.value}`);}else u.push(`${a.name}: ${JSON.stringify(a.value)}`);if(e.children&&e.children.length>0){let a=H(e.children,n,r+2,s);u.push(`children: ${a}`);}let c=u.length>0?`{ ${u.join(", ")} }`:"{}";t.push(`${o}const ${i} = ${l}(${c});`);}function H(e,t,n,r){if(e.length===1&&e[0].type==="expression"){let l=z(e[0].content??"",t,n,r);if(l)return l}let i=" ".repeat(n),s=[],o=e.filter(l=>!(l.type==="text"&&!(l.content??"").trim()));if(o.length===1)$(o[0],s,t,n,"__child",r),s.push(`${i}return __child;`);else {s.push(`${i}const __frag = document.createDocumentFragment();`);for(let l=0;l<o.length;l++){let p=`__child${l}`;$(o[l],s,t,n,p,r),s.push(`${i}__frag.appendChild(${p});`);}s.push(`${i}return __frag;`);}return `() => {
|
|
23
24
|
${s.join(`
|
|
24
25
|
`)}
|
|
25
|
-
${" ".repeat(n-2)}}`}function z(e,t,n,r){let i=e.trim(),s=/^(\(?[^)]*\)?)\s*=>\s*(<[a-zA-Z].*)$/s.exec(i);if(!s)return null;let o=s[1],l=s[2],p=h(l);if(p.length===0)return null;let u=" ".repeat(n),c=[];if(p.length===1)$(p[0],c,t,n,"__child",r),c.push(`${u}return __child;`);else {c.push(`${u}const __frag = document.createDocumentFragment();`);for(let a=0;a<p.length;a++){let
|
|
26
|
+
${" ".repeat(n-2)}}`}function z(e,t,n,r){let i=e.trim(),s=/^(\(?[^)]*\)?)\s*=>\s*(<[a-zA-Z].*)$/s.exec(i);if(!s)return null;let o=s[1],l=s[2],p=h(l);if(p.length===0)return null;let u=" ".repeat(n),c=[];if(p.length===1)$(p[0],c,t,n,"__child",r),c.push(`${u}return __child;`);else {c.push(`${u}const __frag = document.createDocumentFragment();`);for(let a=0;a<p.length;a++){let d=`__child${a}`;$(p[a],c,t,n,d,r),c.push(`${u}__frag.appendChild(${d});`);}c.push(`${u}return __frag;`);}return `${o} => {
|
|
26
27
|
${c.join(`
|
|
27
28
|
`)}
|
|
28
|
-
${" ".repeat(n-2)}}`}function
|
|
29
|
+
${" ".repeat(n-2)}}`}function fe(e,t,n,r){let i=e.trim(),s=z(i,t,n+2,r);if(s)return s;if(!/^<[a-zA-Z]/.test(i))return null;let o=h(i);return o.length===0?null:H(o,t,n+2,r)}function me(e,t,n){if(e.length===0)return ` return '';
|
|
29
30
|
`;let r=[];r.push(" let __html = '';");for(let i of e)B(i,r,t,4,n);return r.push(" return __html;"),r.join(`
|
|
30
31
|
`)+`
|
|
31
|
-
`}function B(e,t,n,r,i){let s=" ".repeat(r);switch(e.type){case "text":t.push(`${s}__html += ${JSON.stringify(e.content??"")};`);break;case "expression":n.add("escapeHtml"),t.push(`${s}__html += escapeHtml(String(${e.content}));`);break;case "element":D(e,t,n,r,i);break;case "component":t.push(`${s}// TODO: SSR component rendering for ${e.tag}`),t.push(`${s}__html += '';`);break}}var ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function D(e,t,n,r,i){let s=" ".repeat(r),o=e.tag,l=e.directives?.find(c=>c.name==="if");if(l){t.push(`${s}if (${l.value}) {`);let c={...e,directives:e.directives?.filter(a=>a.name!=="if")};D(c,t,n,r+2,i),t.push(`${s}}`);return}let p=e.directives?.find(c=>c.name==="for");if(p){let c=/^(?:\(([^)]+)\)|(\w+))\s+of\s+(.+)$/.exec(p.value);if(c){let a=c[1]??c[2],
|
|
32
|
+
`}function B(e,t,n,r,i){let s=" ".repeat(r);switch(e.type){case "text":t.push(`${s}__html += ${JSON.stringify(e.content??"")};`);break;case "expression":n.add("escapeHtml"),t.push(`${s}__html += escapeHtml(String(${e.content}));`);break;case "element":D(e,t,n,r,i);break;case "component":t.push(`${s}// TODO: SSR component rendering for ${e.tag}`),t.push(`${s}__html += '';`);break}}var ge=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function D(e,t,n,r,i){let s=" ".repeat(r),o=e.tag,l=e.directives?.find(c=>c.name==="if");if(l){t.push(`${s}if (${l.value}) {`);let c={...e,directives:e.directives?.filter(a=>a.name!=="if")};D(c,t,n,r+2,i),t.push(`${s}}`);return}let p=e.directives?.find(c=>c.name==="for");if(p){let c=/^(?:\(([^)]+)\)|(\w+))\s+of\s+(.+)$/.exec(p.value);if(c){let a=c[1]??c[2],d=c[3];t.push(`${s}for (const ${a} of ${d}) {`);let f={...e,directives:e.directives?.filter(g=>g.name!=="for"&&g.name!=="key")};D(f,t,n,r+2,i),t.push(`${s}}`);}return}let u=`'<${o}`;if(i&&(u+=` ${i}`),e.attrs)for(let c of e.attrs)c.name.startsWith("on")||(c.dynamic?(t.push(`${s}__html += ${u}';`),u="'",n.add("escapeHtml"),c.name==="class"||c.name==="className"?t.push(`${s}__html += ' class="' + escapeHtml(String(${c.value})) + '"';`):t.push(`${s}__html += ' ${c.name}="' + escapeHtml(String(${c.value})) + '"';`)):c.name==="class"||c.name==="className"?u+=` class="${c.value}"`:u+=` ${c.name}="${c.value}"`);if(ge.has(o)){t.push(`${s}__html += ${u} />';`);return}if(t.push(`${s}__html += ${u}>';`),e.children)for(let c of e.children)B(c,t,n,r,i);t.push(`${s}__html += '</${o}>';`);}function he(e){let t={signalReads:[],eventHandlers:[],hasDynamicContent:false,staticSubtrees:[],reactiveExpressions:[],componentRefs:[]};for(let n of e)O(n,t);return t}function O(e,t){switch(e.type){case "expression":t.hasDynamicContent=true,e.content&&(t.reactiveExpressions.push({expression:e.content,kind:"text"}),y(e.content,"text",t));break;case "element":be(e,t);break;case "component":if(e.tag&&t.componentRefs.push(e.tag),t.hasDynamicContent=true,W(e,t),e.children)for(let n of e.children)O(n,t);break;}}function be(e,t){let n=F(e);if(e.directives)for(let r of e.directives)t.hasDynamicContent=true,$e(r,e,t);if(W(e,t),!n&&!e.directives?.length&&t.staticSubtrees.push(e),e.children)for(let r of e.children)O(r,t);}function W(e,t){if(e.attrs){for(let n of e.attrs)if(n.dynamic)if(t.hasDynamicContent=true,n.name.startsWith("on")){let r=n.name.slice(2).toLowerCase();t.eventHandlers.push({event:r,handler:n.value,tag:e.tag??"unknown"});}else t.reactiveExpressions.push({expression:n.value,kind:"attribute",attributeName:n.name}),y(n.value,"attribute",t);}}function $e(e,t,n){switch(e.name){case "if":case "else-if":case "show":n.reactiveExpressions.push({expression:e.value,kind:"conditional"}),y(e.value,"directive",n);break;case "for":{let r=/\bof\s+(.+)$/.exec(e.value);r&&(n.reactiveExpressions.push({expression:r[1],kind:"list"}),y(r[1],"directive",n));break}case "bind":{n.reactiveExpressions.push({expression:e.value,kind:"attribute",attributeName:e.value}),y(e.value,"directive",n);break}}}function y(e,t,n){let r=new Set(["console","Math","JSON","Object","Array","String","Number","Boolean","Date","RegExp","Error","Promise","parseInt","parseFloat","setTimeout","setInterval","clearTimeout","clearInterval","document","window","navigator","fetch"]),i=/\b([a-zA-Z_$][\w$]*)\s*\(\s*\)/g,s;for(;(s=i.exec(e))!==null;){let o=s[1];r.has(o)||n.signalReads.push({expression:`${o}()`,context:t});}}function F(e){return !!(e.attrs?.some(t=>t.dynamic)||e.directives?.length||e.children?.some(t=>t.type==="expression"||t.type==="component")||e.children?.some(t=>F(t)))}function ve(e){let t=e.trim();return !!(/^['"`].*['"`]$/.test(t)||/^-?\d+(\.\d+)?$/.test(t)||t==="true"||t==="false"||t==="null"||t==="undefined")}var ye="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function x(e){let t="",n=e<0?-e<<1|1:e<<1;do{let r=n&31;n>>>=5,n>0&&(r|=32),t+=ye[r];}while(n>0);return t}var S=class{mappings=[];sources=[];sourcesContent=[];addSource(t,n){let r=this.sources.length;return this.sources.push(t),this.sourcesContent.push(n??null),r}addMapping(t){this.mappings.push(t);}addLineRange(t,n,r,i=0){for(let s=0;s<r;s++)this.addMapping({generatedLine:t+s,generatedColumn:0,originalLine:n+s,originalColumn:0,source:i});}build(t){let n=[...this.mappings].sort((r,i)=>r.generatedLine-i.generatedLine||r.generatedColumn-i.generatedColumn);return {version:3,file:t,sources:this.sources,sourcesContent:this.sourcesContent,names:[],mappings:xe(n)}}toJSON(t){return JSON.stringify(this.build(t))}toDataUrl(t){let n=this.toJSON(t);return `data:application/json;charset=utf-8;base64,${typeof btoa=="function"?btoa(n):Buffer.from(n).toString("base64")}`}};function xe(e){let t=[],n=0,r=0,i=0,s=0,o=0;for(let l of e){for(;t.length<=l.generatedLine;)t.push([]);l.generatedLine!==n&&(r=0,n=l.generatedLine);let p="";p+=x(l.generatedColumn-r),r=l.generatedColumn;let u=l.source??0;p+=x(u-o),o=u,p+=x(l.originalLine-i),i=l.originalLine,p+=x(l.originalColumn-s),s=l.originalColumn,t[l.generatedLine].push(p);}return t.map(l=>l.join(",")).join(";")}function Se(e,t,n,r,i){let s=new S;return s.addSource(e,t),s.addLineRange(i,n,r,0),s}function T(e){return e.type==="expression"||e.type==="component"?false:e.type==="text"?true:!(e.directives&&e.directives.length>0||e.attrs?.some(t=>t.dynamic)||e.children?.some(t=>!T(t)))}function A(e){switch(e.type){case "text":return e.content??"";case "element":{let t=`<${e.tag}`;if(e.attrs)for(let n of e.attrs)n.name==="class"||n.name==="className"?t+=` class="${n.value}"`:t+=` ${n.name}="${n.value}"`;if(t+=">",e.children)for(let n of e.children)t+=A(n);return t+=`</${e.tag}>`,t}default:return ""}}function V(e){let t=[],n=0;function r(i){if(i.type==="element"){if(T(i)&&i.children&&i.children.length>0){let s=`__hoisted_${n++}`;t.push({varName:s,html:A(i)}),i._hoisted=s;return}if(i.children)for(let s of i.children)r(s);}}for(let i of e)r(i);return t}function Te(e){if(e.length===0)return "";let t=`// Hoisted static templates (created once, cloned per instance)
|
|
32
33
|
`;for(let n of e)t+=`const ${n.varName} = /*#__PURE__*/ (() => {
|
|
33
34
|
`,t+=` const _t = document.createElement('template');
|
|
34
35
|
`,t+=` _t.innerHTML = ${JSON.stringify(n.html)};
|
|
35
36
|
`,t+=` return _t;
|
|
36
37
|
`,t+=`})();
|
|
37
|
-
`;return t}function ke(e){return e._hoisted??null}function Ce(e){let t=0,n=0;function r(s){if(t++,T(s)&&n++,s.children)for(let o of s.children)r(o);}for(let s of e)r(s);let i=
|
|
38
|
-
`)[t.line]??"").slice(0,t.character);return we(e,t)?[...I]:
|
|
39
|
-
`)[t.line]??"",r=
|
|
38
|
+
`;return t}function ke(e){return e._hoisted??null}function Ce(e){let t=0,n=0;function r(s){if(t++,T(s)&&n++,s.children)for(let o of s.children)r(o);}for(let s of e)r(s);let i=V(JSON.parse(JSON.stringify(e)));return {totalNodes:t,staticNodes:n,hoistedTemplates:i.length,staticRatio:t>0?n/t:0}}var I=[{label:"signal",kind:"property",detail:"signal<T>(initial: T): Signal<T>",documentation:"Create a reactive signal"},{label:"computed",kind:"property",detail:"computed<T>(fn: () => T): ReadonlySignal<T>",documentation:"Create a derived reactive value"},{label:"effect",kind:"property",detail:"effect(fn: () => void): () => void",documentation:"Run a side-effect when dependencies change"},{label:"batch",kind:"property",detail:"batch(fn: () => void): void",documentation:"Batch signal updates"},{label:"untrack",kind:"property",detail:"untrack<T>(fn: () => T): T",documentation:"Read signals without tracking"},{label:"onMount",kind:"property",detail:"onMount(fn: () => void | (() => void)): void",documentation:"Run after component mounts"},{label:"onUnmount",kind:"property",detail:"onUnmount(fn: () => void): void",documentation:"Run before component unmounts"},{label:"provide",kind:"property",detail:"provide<T>(key: InjectionKey<T>, value: T): void",documentation:"Provide a value to descendants"},{label:"inject",kind:"property",detail:"inject<T>(key: InjectionKey<T>): T",documentation:"Inject a value from ancestors"},{label:"defineStore",kind:"property",detail:"defineStore(id, config): () => Store",documentation:"Define a global store"},{label:"useHead",kind:"property",detail:"useHead(config: HeadConfig): void",documentation:"Manage document head tags"},{label:"cx",kind:"property",detail:"cx(...inputs): string",documentation:"Merge CSS class names"},{label:"pipe",kind:"property",detail:"pipe(value, transform, ...args): any",documentation:"Apply a pipe transform"}],k=[{label:"Show",kind:"component",detail:"<Show when={condition}>{value => ...}</Show>",documentation:"Conditional rendering with type narrowing"},{label:"For",kind:"component",detail:"<For each={items} key={fn}>{item => ...}</For>",documentation:"List rendering with keyed reconciliation"},{label:"Switch",kind:"component",detail:"<Switch on={value} cases={...} />",documentation:"Switch/case rendering"},{label:"Portal",kind:"component",detail:'<Portal target="selector">...</Portal>',documentation:"Render into different DOM node"},{label:"Transition",kind:"component",detail:'<Transition name="fade" when={show}>...</Transition>',documentation:"CSS enter/exit transitions"},{label:"ErrorBoundary",kind:"component",detail:"<ErrorBoundary fallback={fn}>...</ErrorBoundary>",documentation:"Catch errors from children"},{label:"Suspense",kind:"component",detail:"<Suspense fallback={fn}>...</Suspense>",documentation:"Show fallback during async loading"},{label:"VirtualFor",kind:"component",detail:"<VirtualFor each={items} itemHeight={40}>...</VirtualFor>",documentation:"Virtual scrolling for large lists"},{label:"Image",kind:"component",detail:'<Image src="..." alt="..." />',documentation:"Optimized image with lazy loading"}],C=[{label:":if",kind:"directive",detail:":if={condition}",documentation:"Conditional rendering"},{label:":for",kind:"directive",detail:":for={item of items()}",documentation:"List rendering"},{label:":show",kind:"directive",detail:":show={condition}",documentation:"Toggle visibility (display)"},{label:":key",kind:"directive",detail:":key={uniqueId}",documentation:"Reconciliation key for lists"},{label:"bind:value",kind:"directive",detail:"bind:value={signal}",documentation:"Two-way binding"},{label:"bind:checked",kind:"directive",detail:"bind:checked={signal}",documentation:"Two-way checkbox binding"}],J=["onClick","onInput","onChange","onSubmit","onKeyDown","onKeyUp","onFocus","onBlur","onMouseEnter","onMouseLeave","onScroll","onLoad","onError","onResize","onPointerDown","onPointerUp"].map(e=>({label:e,kind:"event",detail:`${e}={(e) => { ... }}`,documentation:`${e.slice(2)} event handler`}));function _e(){return {getDiagnostics(e,t){let n=[];try{let r=v(e);if(r.template||n.push({range:{start:{line:0,character:0},end:{line:0,character:0}},message:"Missing <template> block",severity:"warning"}),r.template){let i=h(r.template.content);U(i,n,r.template.start);}}catch(r){n.push({range:{start:{line:0,character:0},end:{line:0,character:0}},message:`Parse error: ${r instanceof Error?r.message:String(r)}`,severity:"error"});}return n},getCompletions(e,t){let r=(e.split(`
|
|
39
|
+
`)[t.line]??"").slice(0,t.character);return we(e,t)?[...I]:Ee(e,t)?r.endsWith("<")||/^<[A-Z]/.test(r.trimStart())?[...k]:r.endsWith(":")||r.includes(":")?[...C]:Ne(r)?[...C,...J]:[...k,...C]:[]},getHoverInfo(e,t){let n=e.split(`
|
|
40
|
+
`)[t.line]??"",r=Re(n,t.character),i=I.find(o=>o.label===r);if(i)return {contents:`**${i.label}**
|
|
40
41
|
|
|
41
42
|
${i.detail}
|
|
42
43
|
|
|
@@ -45,6 +46,6 @@ ${i.documentation}`};let s=k.find(o=>o.label===r);return s?{contents:`**${s.labe
|
|
|
45
46
|
${s.detail}
|
|
46
47
|
|
|
47
48
|
${s.documentation}`}:null},getAllCompletions(){return {apis:I,components:k,directives:C,events:J}}}}function U(e,t,n){for(let r of e)r.type==="element"&&r.tag==="img"&&(r.attrs?.some(s=>s.name==="alt")||t.push({range:{start:{line:0,character:0},end:{line:0,character:0}},message:"<img> element should have an alt attribute for accessibility",severity:"warning",code:"a11y-img-alt"})),r.type==="element"&&r.tag==="button"&&(r.attrs?.some(s=>s.name==="type")||t.push({range:{start:{line:0,character:0},end:{line:0,character:0}},message:'<button> should have an explicit type attribute (type="button" or type="submit")',severity:"hint",code:"a11y-button-type"})),r.children&&U(r.children,t);}function we(e,t){let n=e.split(`
|
|
48
|
-
`),r=false;for(let i=0;i<=t.line&&i<n.length;i++)n[i].includes("<script")&&(r=true),n[i].includes("</script>")&&(r=false);return r}function
|
|
49
|
-
`),r=false;for(let i=0;i<=t.line&&i<n.length;i++)n[i].includes("<template>")&&(r=true),n[i].includes("</template>")&&(r=false);return r}function
|
|
49
|
+
`),r=false;for(let i=0;i<=t.line&&i<n.length;i++)n[i].includes("<script")&&(r=true),n[i].includes("</script>")&&(r=false);return r}function Ee(e,t){let n=e.split(`
|
|
50
|
+
`),r=false;for(let i=0;i<=t.line&&i<n.length;i++)n[i].includes("<template>")&&(r=true),n[i].includes("</template>")&&(r=false);return r}function Ne(e){let t=e.lastIndexOf("<"),n=e.lastIndexOf(">");return t>n}function Re(e,t){let n=t,r=t;for(;n>0&&/\w/.test(e[n-1]);)n--;for(;r<e.length&&/\w/.test(e[r]);)r++;return e.slice(n,r)}function Ue(e,t={}){let n=v(e);return L(n,t)}export{S as SourceMapBuilder,he as analyzeTemplate,Ue as compile,Se as createAkashSourceMap,_e as createLanguageService,x as encodeVLQ,V as extractHoistedTemplates,Te as generateHoistedDeclarations,E as generateScopeId,ke as getHoistedVar,Ce as getOptimizationStats,ve as isStaticExpression,T as isStaticNode,v as parse,h as parseTemplate,N as scopeStyles,A as staticNodeToHtml,L as transform};//# sourceMappingURL=index.js.map
|
|
50
51
|
//# sourceMappingURL=index.js.map
|