solely 0.0.30 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +817 -507
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/ir/buildIR.d.ts +12 -0
- package/dist/compiler/ir/index.d.ts +1 -0
- package/dist/compiler/parser/index.d.ts +1 -0
- package/dist/compiler/parser/parser.d.ts +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1756 -0
- package/dist/index.umd.cjs +47 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugins/html-parse-precompile.d.ts +1 -0
- package/dist/plugins/html-precompile.d.ts +1 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/runtime/component/base-element.d.ts +24 -0
- package/dist/{base → runtime/component}/decorators.d.ts +6 -4
- package/dist/runtime/component/index.d.ts +2 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/reactivity/index.d.ts +2 -0
- package/dist/runtime/reactivity/observe.d.ts +47 -0
- package/dist/{utils/observe.d.ts → runtime/reactivity/types.d.ts} +0 -8
- package/dist/runtime/renderer/index.d.ts +1 -0
- package/dist/runtime/renderer/renderIR.d.ts +25 -0
- package/dist/runtime/router/core.d.ts +42 -0
- package/dist/runtime/router/index.d.ts +6 -0
- package/dist/runtime/router/router-link.d.ts +17 -0
- package/dist/runtime/router/router-view.d.ts +25 -0
- package/dist/runtime/router/types.d.ts +65 -0
- package/dist/shared/event-listeners.d.ts +2 -0
- package/dist/shared/gen-function.d.ts +3 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/templateError.d.ts +9 -0
- package/dist/types/ast.d.ts +38 -0
- package/dist/types/component.d.ts +66 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/ir.d.ts +67 -0
- package/dist/types/lifecycle.d.ts +4 -0
- package/dist/types/loop.d.ts +4 -0
- package/package.json +24 -6
- package/dist/base/base-element.d.ts +0 -56
- package/dist/base/index.d.ts +0 -5
- package/dist/base/router-view.d.ts +0 -43
- package/dist/solely.d.ts +0 -2
- package/dist/solely.js +0 -941
- package/dist/solely.umd.cjs +0 -3
- package/dist/utils/ast-processor.d.ts +0 -2
- package/dist/utils/async-queue.d.ts +0 -1
- package/dist/utils/event-listeners.d.ts +0 -2
- package/dist/utils/html-parse.d.ts +0 -45
- package/dist/utils/index.d.ts +0 -8
- /package/dist/{utils → shared}/functions.d.ts +0 -0
- /package/dist/{utils → shared}/is-object.d.ts +0 -0
- /package/dist/{utils → shared}/url.d.ts +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
(function(f,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(f=typeof globalThis<"u"?globalThis:f||self,S(f.solely={}))})(this,function(f){"use strict";var en=Object.defineProperty;var ue=f=>{throw TypeError(f)};var nn=(f,S,T)=>S in f?en(f,S,{enumerable:!0,configurable:!0,writable:!0,value:T}):f[S]=T;var M=(f,S,T)=>nn(f,typeof S!="symbol"?S+"":S,T),Pt=(f,S,T)=>S.has(f)||ue("Cannot "+T);var R=(f,S,T)=>(Pt(f,S,"read from private field"),T?T.call(f):S.get(f)),N=(f,S,T)=>S.has(f)?ue("Cannot add the same private member more than once"):S instanceof WeakSet?S.add(f):S.set(f,T),W=(f,S,T,vt)=>(Pt(f,S,"write to private field"),vt?vt.call(f,T):S.set(f,T),T),F=(f,S,T)=>(Pt(f,S,"access private method"),T);var Y,X,tt,ot,et,G,nt,st,z,at,ct,Z,L,_t,he,Tt,Nt,Et,fe,de,Wt,It;const D={dark:{gutter:"#858585",errorLineBg:"#3c1e1e",errorLineFg:"#f8f8f2",arrow:"#ff6b6b",badgeBg:"#ff6b6b",badgeFg:"#ffffff",exprLabel:"#a0a0a0",exprCode:"#5ddcff"}}.dark;function ht(n){let t=0;for(let e=0;e<n.length;){const s=n.codePointAt(e);if(n[e]===" "){t+=4,e++;continue}s>=9472&&s<=9599||s>255?t+=2:t+=1,e+=s>65535?2:1}return t}function Ft(n,t){return(t?"~":"^").repeat(Math.max(1,n))}function jt(n,t="",e,s="component"){var O;const r=(n==null?void 0:n.message)??String(n),i=`%cTemplate Error%c in <${s}> → ${r}`,o=[`color:${D.badgeFg};background:${D.badgeBg};padding:4px 10px;border-radius:6px;font-weight:bold;`,`color:${D.arrow};font-weight:bold;`];if(!t||!(e!=null&&e.loc)||e.loc.length<2){console.error(i,...o),e!=null&&e.expr&&console.log(`Expression: ${e.expr.trim()}`);return}const c=e.loc;let a=c[0]||0,l=c[1]||0;a|=0,l|=0,a<1&&(a=1),l<1&&(l=1);const u=t.split(`
|
|
2
|
+
`);if(a>u.length){console.error(`[Template Error] 行号 ${a} 超出范围`);return}const h=a-1,y=Math.max(0,h-3),v=Math.min(u.length-1,h+3),g=String(v+1).length,p=((O=e.expr)==null?void 0:O.trim())??"",A=p?p.split(`
|
|
3
|
+
`):[],w=p?Math.max(...A.map(ht)):0,k=A.length>1,C=`color:${D.gutter};`,I=`color:${D.arrow};font-weight:bold;`,d=`color:${D.gutter};`,E=`color:${D.errorLineFg};background:${D.errorLineBg};padding:0 4px;`,$=`color:${D.gutter};`,b=`color:${D.arrow};font-weight:bold;padding:0 4px;`;console.groupCollapsed(`${i} %c(Line:${a}, Col:${l})`,...o,`color:${D.gutter};font-weight:normal;`);for(let x=y;x<=v;x++){const P=u[x],_=String(x+1).padStart(g," ");if(!(x===h)){console.log(`%c${_} │%c ${P}`,C,d);continue}const K=P.slice(0,Math.max(0,l-1)),V=ht(K),bt=" ".repeat(g+3),Qe=_.padEnd(g," ");if(console.log(`%c${Qe} │%c ${P}`,I,E),k)for(let U=0;U<A.length;U++){const Mt=A[U],lt=h+U;let Ot=0;if(U===0)Ot=V;else if(lt<u.length){const ut=u[lt],wt=ut.search(/\S/),tn=wt===-1?ut:ut.slice(0,wt);Ot=ht(tn)}const Xe=Math.max(1,ht(Mt)),ce=Ft(Xe,!0),le=bt+" ".repeat(Ot);if(U===0)console.log(`%c${le}%c${ce}`,$,b);else if(lt<u.length){const ut=String(lt+1).padEnd(g," "),wt=u[lt];console.log(`%c${ut} │%c ${wt}`,I,E),console.log(`%c${le}%c${ce}`,$,b)}}else{const U=bt+" ".repeat(V),Mt=Ft(w||1,!1);console.log(`%c${U}%c${Mt}`,$,b)}}p&&console.log(`%cExpression:%c ${p}`,`color:${D.exprLabel};font-weight:bold;`,`color:${D.exprCode};font-family:monospace;`),console.groupEnd()}const $t={};function Dt(n){const t=n.map(e=>e.replace(/[',"]/g,"")).join(",");if(!$t[t]){const e=n[n.length-1];if(e.trim()==="")throw new Error("Function body cannot be empty");if(me(e))throw new Error("Input contains potentially dangerous code: "+e);$t[t]=new Function(...n)}return $t[t]}const pe=["eval","Function","process","require"];function me(n){return pe.some(t=>new RegExp(`\\b${t}\\b`,"g").test(n))}function ye(n,t){if(!(n!=null&&n.trim()))return"";if(/\{\{\{\s*.*?\s*\}\}\}/.test(n))throw new Error("Illegal interpolation syntax: use {{ }} instead of {{{ }}}");return t==="template"?n.replace(/\{\{\s*(.*?)\s*\}\}/g,(e,s)=>`\${${s.trim()}}`):n}function ge(n,t){const e=s=>s.endsWith(";")?s:s+";";switch(t){case"template":return`return \`${n}\`;`;case"expression":return`return (${n});`;case"handler":case"lifecycle":return e(n)}}function be(n){if(!n.length)return{loopValues:"",loopIndices:""};const t=n.map(s=>s.item).join(", "),e=n.map(s=>s.index).join(", ");return{loopValues:`var [${t}] = loops.map(l => l.itmVal);`,loopIndices:`var [${e}] = loops.map(l => l.idxVal);`}}function we(n,t,e,s){const r=n==="lifecycle"?["el","loops"]:n==="handler"?["event","loops"]:["loops"],o=`
|
|
4
|
+
const { $data } = this;
|
|
5
|
+
${n==="handler"?"const { value, checked } = event?.target || {};":""}
|
|
6
|
+
${e}
|
|
7
|
+
${s}
|
|
8
|
+
${t}
|
|
9
|
+
`.replace(/^\s+|\s+$/gm,"");return r.push(o),r}function Vt(n,t,e){if(!(n!=null&&n.trim()))return()=>"";const s=ye(n,t),r=ge(s,t),{loopValues:i,loopIndices:o}=be(e),c=we(t,r,i,o);return Dt(c)}const Bt=new Set(["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"]),H=n=>{if(n===null||typeof n!="object")return!1;const t=Object.prototype.toString.call(n);return!["[object Function]","[object Date]","[object RegExp]","[object Map]","[object Set]","[object WeakMap]","[object WeakSet]"].includes(t)};function Ee(n=window.location){let t;typeof n=="string"?t=new URL(n).hash:t=n.hash;const e=t.split("?");let s=e[0];const r=e[1],i={};return s=s.replace(/^#\/?/,""),r&&r.split("&").forEach(o=>{const[c,a]=o.split("=");c&&a&&(i[decodeURIComponent(c)]=decodeURIComponent(a))}),{path:s.split("/").filter(Boolean),query:i}}var m=(n=>(n[n.Element=0]="Element",n[n.Text=1]="Text",n[n.Comment=2]="Comment",n[n.If=3]="If",n[n.ElseIf=4]="ElseIf",n[n.Else=5]="Else",n[n.For=6]="For",n[n.Conditional=7]="Conditional",n[n.Other=99]="Other",n))(m||{});const Kt={onMounted:"mounted",onUpdated:"updated",onUnmounted:"unmounted"};function qt(n){return Kt[n]??null}function Yt(n){return n==="mounted"||n==="updated"||n==="unmounted"}const xt=Symbol.for("solely.irMeta"),J=process.env.NODE_ENV!=="production",ve=/\{\{.*?\}\}/;class $e{constructor(){M(this,"compilers",new Map)}get(t="anonymous"){let e=this.compilers.get(t);return e||(e=new xe,this.compilers.set(t,e)),e}clear(t){var e;if(t)(e=this.compilers.get(t))==null||e.clear(),this.compilers.delete(t);else{for(const s of this.compilers.values())s.clear();this.compilers.clear()}}}const Ut=new $e;class xe{constructor(){M(this,"cache",new Map);M(this,"functions",[])}makeCacheKey(t,e,s){if(s.length===0)return`${t}:${e}`;const r=s.map(i=>Object.keys(i).sort().join(",")).join(";");return`${t}:${e}:${r}`}compile(t,e,s){const r=e==null?void 0:e.trim();if(!r)return 0;const i=this.makeCacheKey(t,r,s),o=this.cache.get(i);if(o!==void 0)return o;let c;try{c=Vt(r,t,s)}catch(l){J&&console.error(`[IR Compile Error] Type: ${t}, Expr: "${r}"`,l),c=()=>""}const a=this.functions.push(c);return this.cache.set(i,a),a}getFunctions(){return this.functions}getStats(){return{total:this.functions.length,cached:this.cache.size}}clear(){this.cache.clear(),this.functions=[]}}function Ht(n){const t=n[0];return t===":"?{isDynamic:!0,type:"expression"}:t==="@"?{isDynamic:!0,type:"handler"}:Yt(n)?{isDynamic:!0,type:"lifecycle"}:{isDynamic:!1,type:null}}function Se(n){return n?ve.test(n):!1}function St(n,t,e){J&&(n[xt]={expr:t??"",loc:e??null})}function Gt(n){if(!n.attrs)return;const t=n.attrs.find(a=>a.key==="s-model");if(!t)return;const e="$data."+t.value.replace("this.","").replace("$data.",""),s=t.loc,r=(n.tag||"").toLowerCase(),i=n.attrs.find(a=>a.key==="type"),o=(i==null?void 0:i.value)??"text";n.attrs=n.attrs.filter(a=>a!==t);const c=(a,l,u)=>{var h;(h=n.attrs)==null||h.push({key:a,value:l,role:u,loc:s})};if(r==="input"){if(o==="checkbox"){const a=n.attrs.find(y=>y.key==="value"),l=a?JSON.stringify(a.value):'"on"',u=`Array.isArray(${e}) ? ${e}.includes(${l}) : ${e}`;c(":checked",u);const h=`
|
|
10
|
+
const _v = ${l};
|
|
11
|
+
if(Array.isArray(${e})) {
|
|
12
|
+
const _i = ${e}.indexOf(_v);
|
|
13
|
+
if(checked && _i === -1) ${e}.push(_v);
|
|
14
|
+
else if(!checked && _i > -1) ${e}.splice(_i,1);
|
|
15
|
+
} else {
|
|
16
|
+
${e} = checked;
|
|
17
|
+
}`;c("@change",h,"model");return}if(o==="radio"){const a=n.attrs.find(u=>u.key==="value"),l=(a==null?void 0:a.value)??"null";c(":checked",`${e} == ${JSON.stringify(l)}`),c("@change",`if (checked) ${e} = ${JSON.stringify(l)}`,"model");return}c(":value",e),c("@input",`${e} = value`,"model");return}if(r==="textarea"){c(":value",e),c("@input",`${e} = value`,"model");return}if(r==="select"){n.attrs.some(l=>l.key==="multiple")?(c("updated",`
|
|
18
|
+
const values = Array.isArray(${e}) ? ${e} : ${e} != null ? [${e}] : [];
|
|
19
|
+
for (const opt of el.options) {
|
|
20
|
+
opt.selected = values.includes(opt.value);
|
|
21
|
+
}`),c("@change",`${e} = Array.from(event.target.selectedOptions).map(o => o.value)`,"model")):(c(":value",e),c("@change",`${e} = value`,"model"));return}c(":value",e),c("@input",`${e} = $event`,"model")}function ft(n,t,e,s=null){if(!n.attrs||n.attrs.length===0)return[];const r=[];for(const i of n.attrs){if(s&&s.has(i.key))continue;const{key:o,value:c,role:a}=i,{isDynamic:l,type:u}=Ht(o);if(l&&u){const h=e.compile(u,c??"",t),y={key:o,fid:h,dynamic:1,role:a};St(y,c,i.loc??n.loc),r.push(y)}else r.push({key:o,value:c,dynamic:0,role:a})}return r}function ke(n,t,e){var i,o,c,a,l,u;const s={type:n.type,dynamic:0};let r=!1;switch(n.type===m.Text?Se(n.content)&&(r=!0):((i=n.attrs)!=null&&i.some(h=>h.key==="s-model"||Ht(h.key).isDynamic)&&(r=!0),n.type===m.For&&(r=!0)),s.dynamic=r?1:0,n.type){case m.Text:{const h=n.content??"";r?(s.fid=e.compile("template",h,t),St(s,h,n.loc)):s.txt=h;break}case m.Element:{s.tag=n.tag,Gt(n),s.attrs=ft(n,t,e),n.children&&(s.children=rt(n.children,t,e));break}case m.For:{const h=(o=n.attrs)==null?void 0:o.find(p=>p.key==="each"),y=(h==null?void 0:h.value)??"";s.fid=e.compile("expression",y,t),s.item=((a=(c=n.attrs)==null?void 0:c.find(p=>p.key==="item"))==null?void 0:a.value)??"item",s.index=((u=(l=n.attrs)==null?void 0:l.find(p=>p.key==="index"))==null?void 0:u.value)??"index",St(s,y,(h==null?void 0:h.loc)??n.loc);const v=new Set(["each","item","index"]);s.attrs=ft(n,t,e,v);const g=[...t,{item:s.item,index:s.index}];n.children&&(s.children=rt(n.children,g,e));break}case m.If:case m.ElseIf:case m.Else:{J&&console.warn(`[IR] Orphaned conditional node found: ${m[n.type]}`),s.attrs=ft(n,t,e),n.children&&(s.children=rt(n.children,t,e));break}case m.Comment:{s.txt=n.content??"";break}}return s}function rt(n,t,e){var i;const s=[];let r=0;for(;r<n.length;){const o=n[r];if(o.type===m.If){const c=[];let a=r;for(;a<n.length;){const l=n[a],u=l.type;if(u!==m.If&&u!==m.ElseIf&&u!==m.Else)break;let h=null,y="";if(u!==m.Else){const A=(i=l.attrs)==null?void 0:i.find(w=>w.key==="test"||w.key==="condition");y=(A==null?void 0:A.value)??"false",h=e.compile("expression",y,t)}const v=l.children?rt(l.children,t,e):[],p=ft(l,t,e,new Set(["test","condition"]));if(c.push({condFid:h,children:v,attrs:p.length>0?p:void 0,[xt]:J?{expr:y,loc:l.loc}:void 0}),a++,u===m.Else)break}s.push({type:m.Conditional,dynamic:1,branches:c,...J&&{[xt]:{loc:o.loc}}}),r=a}else s.push(ke(o,t,e)),r++}return s}function zt(n,t={}){const{filename:e="anonymous",source:s}=t,r=Ut.get(e);r.clear();const i=performance.now(),o=rt(n,[],r),c=performance.now(),a=r.getStats(),l=o.filter(h=>h.dynamic===1).length,u={type:"root",version:"1.1.0",functions:r.getFunctions(),nodes:o,stats:{totalFunctions:a.total,cachedFunctions:a.cached,dynamicNodes:l,totalNodes:o.length},metadata:{compiledAt:new Date().toISOString(),astSize:n.length,filename:e,...s&&{source:s}}};return J&&console.log(`[IRBuilder] ${e} | ${(c-i).toFixed(2)}ms | Nodes: ${o.length} | Fns: ${a.total}`),u}function Ce(n){Ut.clear(n)}const Re=/<\/?([A-Za-z][A-Za-z0-9\-\:]*)[>\s\/]/,Le=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Ae=/\s*([^\s"'/>=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gs;function Ie(n,t){const e=[];let s;const r=n.replace(/^\s*[^\s"'/>]+/,""),i=n.length-r.length;for(;(s=Ae.exec(r))!==null;){const o=s[1];if(!o)continue;const c=s[2]??s[3]??s[4]??"";let a=o;Bt.has(o)&&(a=a.replace(/^on/,"@")),a!=="s-model"&&(a=a.replace(/^on-/,"@").replace(/^s-/,":")),a=qt(a)||a;const l=s[0],u=l.indexOf("=");let h;if(u===-1)h=l.indexOf(o)+o.length;else{let w=u+1;for(;w<l.length&&/\s/.test(l[w]);)w++;if(l[w]==='"'||l[w]==="'"){let k=w+1;for(;k<l.length&&/\s/.test(l[k]);)k++;h=k}else{let k=w;for(;k<l.length&&/\s/.test(l[k]);)k++;h=k}}let y=s.index+h+i;const g=n.slice(0,y).split(`
|
|
22
|
+
`),p=t[0]+g.length-1,A=g.length>1?g[g.length-1].length+1:t[1]+y;e.push({key:a,value:c,loc:[p,A]})}return e}function Me(n,t){var o;const e=((o=(n.match(Re)||[])[1])==null?void 0:o.toLowerCase())??"",s=Ie(n,t);return{type:{for:m.For,if:m.If,elseif:m.ElseIf,else:m.Else}[e]??m.Element,tag:e,loc:t,children:[],attrs:s}}function Oe(n,t){const e=n.length;if(n.startsWith("!--",t)){const o=n.indexOf("-->",t+3);return o===-1?-1:o+2}if(n.startsWith("![CDATA[",t)){const o=n.indexOf("]]>",t+8);return o===-1?-1:o+2}if(n[t]==="!")return n.indexOf(">",t+1);if(n[t]==="?"){const o=n.indexOf("?>",t+1);return o===-1?-1:o+1}let s=!1,r=!1,i=t;for(;i<e;){const o=n[i];if(o==="'"&&!r)s=!s;else if(o==='"'&&!s)r=!r;else if(o===">"&&!s&&!r)return i;i++}return-1}function Zt(n){const t=[];if(!n)return[];const e=[],s=[],r=()=>{var l;return e.length===0?t:(l=e[e.length-1]).children||(l.children=[])};let i=0;const o=n.length,c=[0];for(let l=0;l<o;l++)n[l]===`
|
|
23
|
+
`&&c.push(l+1);function a(l){let u=0;for(let h=1;h<c.length&&!(c[h]>l);h++)u=h;return[u+1,l-c[u]+1]}for(;i<o;){const l=n.indexOf("<",i);if(l===-1||l>i){const C=n.substring(i,l===-1?void 0:l),I=C.trim();if(I){const d=C.indexOf(I),E=i+d,$=a(E);r().push({type:m.Text,tag:"text",content:I,loc:$,children:[]})}if(l===-1)break;i=l}const u=Oe(n,i+1);if(u===-1){const C=n.substring(i);C.trim()&&r().push({type:m.Text,tag:"text",content:C.trim(),children:[],loc:a(i)});break}const h=n.substring(i,u+1),y=r(),v=a(i);if(h.startsWith("<!--")){y.push({type:m.Comment,tag:"comment",content:h.slice(4,-3),loc:v,children:[]}),i=u+1;continue}if(h.startsWith("<![CDATA[")){y.push({type:m.Text,tag:"text",content:h.slice(9,-3),loc:v,children:[]}),i=u+1;continue}if(h.startsWith("<!")&&!h.startsWith("<!--")){y.push({type:m.Comment,tag:"comment",content:h.slice(2,-1),loc:v,children:[]}),i=u+1;continue}if(h.startsWith("<?")){y.push({type:m.Comment,tag:"comment",content:h.slice(2,-2),loc:v,children:[]}),i=u+1;continue}if(h.startsWith("</")){const C=s.pop();for(;e.length>0;){if((e[e.length-1].tag||"").toLowerCase()===(C==null?void 0:C.toLowerCase())){e.pop();break}e.pop()}i=u+1;continue}const g=Me(h,v);y.push(g);const p=g.tag||"",A=p.toLowerCase().startsWith("script"),w=p.toLowerCase().startsWith("style"),k=h.endsWith("/>")||Le.has(p.toLowerCase());if((A||w)&&!k){const C=`</${p}>`,I=n.toLowerCase().indexOf(C,u+1);if(I!==-1){const d=n.substring(u+1,I);d.length&&g.children.push({type:m.Text,tag:"text",content:d,loc:a(u+1),children:[]}),i=I+C.length;continue}else{const d=n.substring(u+1);d.length&&g.children.push({type:m.Text,tag:"text",content:d,loc:a(u+1),children:[]}),i=o;continue}}!k&&g.type!==m.Text&&g.type!==m.Comment&&(e.push(g),s.push(p)),i=u+1}return t}const dt=Symbol("solely.raw");function Jt(n){const t=n&&n[dt];return t?Jt(t):n}function Pe(n){return!!(n&&n[dt])}const kt=(n,t,e=new WeakMap)=>{if(n===t)return!0;if(n==null||t==null||typeof n!="object"||typeof t!="object")return n===t;if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return!1;if(e.has(n))return e.get(n)===t;e.set(n,t);for(let r=0;r<n.length;r++)if(!kt(n[r],t[r],e))return!1;return!0}if(Array.isArray(n)!==Array.isArray(t))return!1;if(e.has(n))return e.get(n)===t;e.set(n,t);const s=Reflect.ownKeys(n);if(s.length!==Reflect.ownKeys(t).length)return!1;for(const r of s)if(!Reflect.has(t,r)||!kt(n[r],t[r],e))return!1;return!0};function Qt(n,t,e={}){const{throttle:s=0,onBatch:r,immediate:i=!1,deepCompare:o=!1}=e;let c=!0,a=null,l=[],u=0;const h=new WeakMap,y=new WeakMap,v=new WeakMap,g=Array.isArray(e.filter)?e.filter:e.filter?[e.filter]:[],p=d=>{if(g.length===0)return!0;const E=d.map(String).join(".");return g.some($=>{if($==="")return!0;const b=$.replace(/\./g,"\\.").replace(/\*\*/g,"(.+)").replace(/\*/g,"[^.]+").replace(/\[\d+\]/g,"\\[\\d+\\]");return new RegExp(`^${b}$`).test(E)})},A=d=>{const E=[];let $=d;for(;$;){const b=y.get($);if(!b||b.key==null)break;E.unshift(b.key),$=b.parent}return E},w=(d,E)=>{if(!c)return;const $=A(d);if(!p($))return;const b={...E,path:$};s>0?(l.push(b),a||(a=setTimeout(()=>{const O=[...l];l=[],a=null,c&&(r==null||r(O),O.forEach(t))},s))):(r==null||r([b]),t(b))},k=(d,E)=>{const $={};return["push","pop","shift","unshift","splice"].forEach(b=>{$[b]=function(...O){u++;const x=d[b].apply(d,O);if(u--,b==="push")w(E,{type:"array-push",index:d.length-O.length,values:O});else if(b==="unshift")w(E,{type:"array-push",index:0,values:O});else if(b==="pop")w(E,{type:"array-splice",index:d.length,deleteCount:1,insert:[]});else if(b==="shift")w(E,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if(b==="splice"){const[P,_,...j]=O;w(E,{type:"array-splice",index:P,deleteCount:_,insert:j})}return x}}),["sort","reverse","fill","copyWithin"].forEach(b=>{$[b]=function(...O){u++;const x=d[b].apply(d,O);return u--,w(E,{type:"array-reset",method:b}),x}}),["indexOf","lastIndexOf","includes"].forEach(b=>{$[b]=function(O,...x){let P=d[b].apply(d,[O,...x]);return(P===-1||P===!1)&&Pe(O)&&(P=d[b].apply(d,[Jt(O),...x])),P}}),$},C=(d,E,$)=>{if(!Object.isExtensible(d)||d[dt])return d;const b=h.get(d);if(b)return y.set(b,{parent:E,key:$}),b;const O={get(P,_,j){if(_===dt)return P;if(Array.isArray(P)){const V=v.get(x);if(V&&Object.prototype.hasOwnProperty.call(V,_))return Reflect.get(V,_,j)}const K=Reflect.get(P,_,j);return typeof _=="symbol"?K:H(K)?C(K,x,_):K},set(P,_,j,K){const V=P[_];if(o?kt(V,j):V===j)return!0;const bt=Reflect.set(P,_,j,K);return u===0&&(Array.isArray(V)&&Array.isArray(j)?w(x,{type:"array-replace",oldValue:V,newValue:j}):w(x,{type:"set",key:_,newValue:j,oldValue:V})),bt},deleteProperty(P,_){if(!Reflect.has(P,_))return!1;const j=P[_],K=Reflect.deleteProperty(P,_);return K&&u===0&&w(x,{type:"delete",key:_,oldValue:j}),K}},x=new Proxy(d,O);return h.set(d,x),y.set(x,{parent:E,key:$}),Array.isArray(d)&&v.set(x,k(d,x)),x},I=C(n,null,null);if(i){const d=(E,$,b=new WeakSet)=>{!H(E)||b.has(E)||(b.add(E),Reflect.ownKeys(E).forEach(O=>{const x=E[O];w($,{type:"set",key:O,newValue:x,oldValue:void 0}),H(x)&&d(x,C(x,$,O),b)}))};d(n,I)}return{proxy:I,unobserve:()=>{c=!1,l=[],a&&clearTimeout(a)},resume:()=>{c=!0}}}const Xt=Symbol.for("solely.manifest"),B=class B extends HTMLElement{constructor(e={}){var r;super();N(this,L);N(this,Y);N(this,X);N(this,tt);N(this,ot);N(this,et);N(this,G);N(this,nt,!1);N(this,st,!1);N(this,z,!1);N(this,at,!1);W(this,Y,this.constructor[Xt]||{});const s=R(this,Y);W(this,et,(r=s.shadowDOM)!=null&&r.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this),F(this,L,_t).call(this,e),F(this,L,he).call(this,s),queueMicrotask(()=>F(this,L,Wt).call(this))}static get observedAttributes(){if(R(B,Z).has(this))return R(B,Z).get(this);const e=this[Xt];if(!(e!=null&&e.props))return R(B,Z).set(this,[]),[];const s=e.props.map(r=>(typeof r=="string"?r:r.name).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase());return R(B,Z).set(this,s),s}get $data(){return R(this,ot)}set $data(e){var s;H(e)||(e={}),(s=R(this,G))==null||s.call(this),F(this,L,_t).call(this,e),F(this,L,Et).call(this)}refresh(){F(this,L,Et).call(this)}connectedCallback(){var r;F(this,L,Wt).call(this);const e=R(this,Y);if((e.className||e.tagName||"").split(" ").forEach(i=>i&&this.classList.add(i)),F(this,L,de).call(this),e.props&&H(this.$data))for(const i of e.props){const o=typeof i=="string"?i:i.name,c=F(this,L,Tt).call(this,o),a=o.replace(/-([a-z])/g,(l,u)=>u.toUpperCase());if(this.hasAttribute(o)){const l=this.getAttribute(o),u=F(this,L,Nt).call(this,l,c==null?void 0:c.default,c==null?void 0:c.type);this.$data[a]=u}else c&&"default"in c&&(this.$data[a]=c.default)}R(this,tt)&&W(this,X,re(R(this,tt),R(this,et),this)),this.mounted(),(r=this.onInit)==null||r.call(this)}disconnectedCallback(){var e;this.unmounted(),(e=R(this,G))==null||e.call(this),W(this,G,void 0)}attributeChangedCallback(e,s,r){if(s===r||!H(this.$data))return;const i=F(this,L,Tt).call(this,e),o=e.replace(/-([a-z])/g,(l,u)=>u.toUpperCase()),c=this.$data[o],a=F(this,L,Nt).call(this,r,(i==null?void 0:i.default)??c,i==null?void 0:i.type);this.$data[o]=a,W(this,z,!0),this.attributeChanged(e,c,a),this.emit("change",{source:"attribute",name:e,oldValue:c,newValue:a})}emit(e,s,r){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:s,...r}))}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(e,s,r){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};Y=new WeakMap,X=new WeakMap,tt=new WeakMap,ot=new WeakMap,et=new WeakMap,G=new WeakMap,nt=new WeakMap,st=new WeakMap,z=new WeakMap,at=new WeakMap,ct=new WeakMap,Z=new WeakMap,L=new WeakSet,_t=function(e){const{proxy:s,unobserve:r}=Qt(e,i=>{this.emit("change",{source:"state",...i}),F(this,L,Et).call(this)});W(this,ot,s),W(this,G,r)},he=function(e){const s=e.template;if(typeof s=="string"){const r=Zt(s);W(this,tt,zt(r,{source:s,filename:e.tagName}))}},Tt=function(e){const s=R(this,Y).props;if(!s)return;const r=e.replace(/-([a-z])/g,(o,c)=>c.toUpperCase()),i=s.find(o=>typeof o=="string"?o===r:o.name===r);if(i)return typeof i=="string"?{name:i}:i},Nt=function(e,s,r){if(e===null)return s;switch(r){case"number":{const i=Number(e);return isNaN(i)?s:i}case"boolean":return e!==null&&e!=="false";case"object":try{return JSON.parse(e)}catch{return s}default:return e}},Et=function(){R(this,st)||!R(this,X)||(W(this,st,!0),queueMicrotask(()=>{W(this,st,!1),F(this,L,fe).call(this)}))},fe=function(){R(this,nt)||!this.isConnected||(W(this,nt,!0),R(this,z)&&this.beforeAttributesUpdate(),this.beforeUpdate(),R(this,X).update(),this.updated(),R(this,z)&&(this.afterAttributesUpdate(),W(this,z,!1)),W(this,nt,!1))},de=function(){const s=R(this,Y).styles;if(!s)return;const r=R(this,et);if("adoptedStyleSheets"in r){if(r._styleInjected)return;let o=R(B,ct).get(s);o||(o=new CSSStyleSheet,o.replaceSync(s),R(B,ct).set(s,o)),r.adoptedStyleSheets=[...r.adoptedStyleSheets,o],r._styleInjected=!0;return}if(r.querySelector("style[data-manifest-style]"))return;const i=document.createElement("style");i.dataset.manifestStyle="true",i.textContent=s,r.appendChild(i)},Wt=function(){R(this,at)||(W(this,at,!0),this.created())},It=new WeakMap,N(B,ct,new Map),N(B,Z,new WeakMap),N(B,It,!1);let it=B;const _e=Symbol.for("solely.manifest"),Ct=n=>t=>{if(customElements.get(n.tagName))return console.warn(`标签名称 "${n.tagName}" 已经被注册`),t;class e extends t{}return e[_e]=n,customElements.define(n.tagName,e),e},pt=Symbol("solely.irCtx"),mt=Symbol("solely.irEvents"),q=Symbol.for("solely.irMeta"),Rt=Symbol("solely.staticClass"),Lt=Symbol("solely.staticStyle"),te=Symbol("solely.dynamicStyle"),Te={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},Ne={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},We=new Set(["data-","aria-","role","form"]),Fe=new Set(["value","selectedIndex"]);function je(n,t){var s;const e=n;if(e[Rt]===void 0){const r=(s=t.attrs)==null?void 0:s.find(i=>i.key==="class"&&!i.dynamic);e[Rt]=r?r.value:""}}function De(n,t){var s;const e=n;if(e[Lt]===void 0){const r=(s=t.attrs)==null?void 0:s.find(i=>i.key==="style"&&!i.dynamic);e[Lt]=r?ee(r.value):{}}}const Ve=(n,t)=>{const e=n,s=e[Lt]||{},r=ee(t),i={...s};for(const c in r){const a=r[c];a===""||a==null?delete i[c]:i[c]=a}const o=e[te]||{};for(const c in o)c in i||(c.startsWith("--")?n.style.removeProperty(c):n.style[c]="");for(const c in i){const a=i[c];c.startsWith("--")?n.style.getPropertyValue(c)!==a&&n.style.setProperty(c,a):n.style[c]!==a&&(n.style[c]=a)}e[te]=r},Be=(n,t)=>{const s=n[Rt]||"",r=Ke(t),i=new Set;s&&s.split(/\s+/).forEach(c=>{(!r.hasOwnProperty(c)||r[c])&&i.add(c)});for(const[c,a]of Object.entries(r))a&&i.add(c);const o=[...i].join(" ");n.className!==o&&(n.className=o)};function ee(n){const t={},e=[[n]];for(;e.length;){const[s,r]=e.pop();if(typeof s=="string"){s.split(";").forEach(i=>{const[o,c]=i.split(":").map(a=>a.trim());o&&c&&(t[o]=c)});continue}if(Array.isArray(s)){s.forEach(i=>e.push([i]));continue}if(s&&typeof s=="object")for(const[i,o]of Object.entries(s)){const c=r?`${r}-${i}`:i;o&&typeof o=="object"&&!Array.isArray(o)?e.push([o,c]):t[c]=String(o??"")}}return t}function Ke(n){const t={},e=[n];for(;e.length;){const s=e.pop();if(s){if(typeof s=="string")s.split(/\s+/).forEach(r=>r&&(t[r]=!0));else if(Array.isArray(s))e.push(...s);else if(typeof s=="object")for(const[r,i]of Object.entries(s))t[r]=!!i}}return t}function qe(n,t,e){const s=t.indexOf(":");if(s>0){const r=t.slice(0,s),i=Te[r];if(i)return n.setAttributeNS(i,t,e)}n.setAttribute(t,e)}function ne(n,t,e){if(t.startsWith("data-")||t.startsWith("aria-")||We.has(t)){n.setAttribute(t,e);return}const s=Ne[t]||t;n[s]=e}class se{constructor(t,e,s={}){M(this,"nodeMap",new Map);M(this,"marker",!1);this.ir=t,this.container=e,this.scope=s}evalIR(t,e,s){var i;const r=this.ir.functions[t-1];try{return r?r.apply(this.scope,e):""}catch(o){return jt(o.message||o.toString(),((i=this.ir.metadata)==null?void 0:i.source)||"",s,this.scope.tagName),""}}createElement(t){const e=t.tag;return e==="svg"?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}createText(t,e){const s=t.dynamic?this.evalIR(t.fid,[e],t[q]):t.txt||"";return document.createTextNode(s)}createComment(t,e){const s=t.dynamic?this.evalIR(t.fid,[e],t[q]):t.txt||"";return document.createComment(s)}applyAttrs(t,e,s,r=!1){const i=[],o=t;o[pt]||(o[pt]={loops:null}),o[pt].loops=s,o[mt]||(o[mt]=Object.create(null));let c,a=!1,l,u=!1;for(const h of e){const{key:y,fid:v,dynamic:g,value:p}=h;if(y===":class"){c=this.evalIR(v,[s]),a=!0;continue}if(y===":style"){l=this.evalIR(v,[s]),u=!0;continue}if(y==="class"||y==="style")continue;const A=y[0];if(A==="@"){const k=y.slice(1),C=h.role??"user";let I=o[mt][k];if(I||(I=o[mt][k]={model:[],user:[]},t.addEventListener(k,d=>{for(const E of I.model)E(d);for(const E of I.user)E(d)})),!r){const d=E=>this.evalIR(v,[E,o[pt].loops],h[q]);I[C].push(d)}continue}if(y==="mounted"){r||requestAnimationFrame(()=>this.evalIR(v,[t,s],h[q]));continue}if(y==="updated"){r&&requestAnimationFrame(()=>this.evalIR(v,[t,s],h[q]));continue}if(y==="ref"&&p){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[p]=t;continue}const w=g?this.evalIR(v,[s],h[q]):p??"";if(A===":"){const k=y.slice(1);t.tagName==="SELECT"&&Fe.has(k)?i.push(()=>ne(t,k,w)):ne(t,k,w)}else qe(t,y,String(w))}return(a||!r)&&Be(t,c),(u||!r)&&Ve(t,l),i}updateNode(t,e,s){const r=e.dynamic?this.evalIR(e.fid,[s],e[q]):e.txt||"";e.dynamic&&t.textContent!==r&&(t.textContent=r)}irToNode(t,e,s,r,i){var l,u,h,y;const o=s+"-"+e,c=this.nodeMap.get(o);let a;if(c){a=c.node,c.marker=this.marker;let v=[];t.dynamic&&(t.type===m.Element?v=this.applyAttrs(a,t.attrs??[],i,!0):this.updateNode(a,t,i)),(l=t.children)==null||l.forEach((g,p)=>{this.irToNode(g,p,o,a,i)}),v.forEach(g=>g())}else switch(t.type){case m.Element:a=this.createElement(t),je(a,t),De(a,t);const v=this.applyAttrs(a,t.attrs??[],i);r.appendChild(a),this.nodeMap.set(o,{irNode:t,node:a,loops:i,marker:this.marker}),(u=t.children)==null||u.forEach((g,p)=>{this.irToNode(g,p,o,a,i)}),v.forEach(g=>g());break;case m.Text:a=this.createText(t,i),r.appendChild(a),this.nodeMap.set(o,{irNode:t,node:a,loops:i,marker:this.marker});break;case m.Comment:a=this.createComment(t,i),r.appendChild(a),this.nodeMap.set(o,{irNode:t,node:a,loops:i,marker:this.marker});break;case m.For:{const g=`${o}-end`;let p=(h=this.nodeMap.get(g))==null?void 0:h.node;p?this.nodeMap.get(g).marker=this.marker:(p=document.createComment(`for:${o}`),r.appendChild(p),this.nodeMap.set(g,{irNode:{type:m.Comment},node:p,loops:i,marker:this.marker}));const A=this.evalIR(t.fid,[i],t[q])||[],w=document.createDocumentFragment();A.forEach((k,C)=>{var d;const I=[...i,{itmVal:k,idxVal:C}];(d=t.children)==null||d.forEach((E,$)=>{this.irToNode(E,$,`${o}-for-${C}`,w,I)})}),p.parentNode.insertBefore(w,p);break}case m.Conditional:{const g=`${o}-end`;let p=(y=this.nodeMap.get(g))==null?void 0:y.node;p?this.nodeMap.get(g).marker=this.marker:(p=document.createComment(`if:${o}`),r.appendChild(p),this.nodeMap.set(g,{irNode:{},node:p,loops:i,marker:this.marker}));for(let A=0;A<(t.branches||[]).length;A++){const w=t.branches[A];if(w.condFid===null||this.evalIR(w.condFid,[i],w[q])){const C=document.createDocumentFragment();w.children.forEach((I,d)=>{this.irToNode(I,d,`${o}-if-${A}`,C,i)}),p.parentNode.insertBefore(C,p);break}}break}}}cleanupOldNodes(){for(const[t,e]of this.nodeMap.entries())if(e.marker!==this.marker){const{irNode:s,node:r,loops:i}=e;if(s.attrs){const o=s.attrs.find(a=>a.key==="unmounted");o&&requestAnimationFrame(()=>{this.evalIR(o.fid,[r,i],o[q])});const c=s.attrs.find(a=>a.key==="ref");c&&c.value&&delete this.scope.$refs[c.value]}r==null||r.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.nodes.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.nodes.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear()}}const re=(n,t,e={})=>{const s=new se(n,t,e);return s.mount(),{update:()=>s.update(),destroy:()=>s.destroy()}};let Q=null,ie;const oe=new Promise(n=>{ie=n});function Ye(n){return Q||(Q=new ae(n),ie(Q),Q)}function yt(){return Q}class ae{constructor(t){M(this,"routes");M(this,"base");M(this,"mode");M(this,"beforeEachGuard");M(this,"afterEachGuard");M(this,"currentRoute",null);M(this,"listeners",new Set);M(this,"isStarted",!1);this.routes=t.routes,this.base=t.base||"/",this.mode=t.mode||"history",this.beforeEachGuard=t.beforeEach,this.afterEachGuard=t.afterEach}matchRoute(t){const e=t.startsWith("/")?t:"/"+t,[s,r]=e.split("?"),i=s.split("/").filter(Boolean),o=this.parseQuery(r),c=this.recursiveMatch(this.routes,i);if(c){const a=c.matched[c.matched.length-1];return a.config.redirect?this.matchRoute(a.config.redirect):{matched:c.matched,params:c.params,query:o,fullPath:e,meta:c.matched.reduce((l,u)=>({...l,...u.config.meta||{}}),{})}}return null}recursiveMatch(t,e){const s=[...t].sort((r,i)=>this.calculateScore(i.path)-this.calculateScore(r.path));for(const r of s){const i=r.path.split("/").filter(Boolean),o={};let c=!0;if(i.length===0&&e.length===0)return{matched:[{config:r,params:{}}],params:{}};for(let a=0;a<i.length;a++){const l=i[a],u=e[a];if(l.startsWith(":")){if(!u){c=!1;break}o[l.slice(1)]=u}else if(l==="*"){c=!0;break}else if(l!==u){c=!1;break}}if(c){const a=i.length,l=e.slice(a),u={config:r,params:o};if(l.length>0&&r.children){const h=this.recursiveMatch(r.children,l);if(h)return{matched:[u,...h.matched],params:{...o,...h.params}}}else if(l.length===0||i.includes("*"))return{matched:[u],params:o}}}return null}calculateScore(t){const e=t.split("/").filter(Boolean);return e.length===0?1:e.reduce((s,r)=>r.startsWith(":")?s+5:r==="*"?s+0:s+10,0)}parseQuery(t){const e={};return t&&new URLSearchParams(t).forEach((r,i)=>{e[i]=r}),e}getPath(){let t=this.mode==="hash"?window.location.hash.slice(1)||"/":window.location.pathname;return this.base&&this.base!=="/"&&t.startsWith(this.base)&&(t=t.slice(this.base.length)||"/"),t.startsWith("/")?t:"/"+t}updateBrowserHistory(t,e){if(this.mode==="hash"){const s=t.startsWith("/")?t:"/"+t;e?window.location.replace(`#${s}`):window.location.hash=s}else{const s=this.base&&this.base!=="/"?(this.base.endsWith("/")?this.base.slice(0,-1):this.base)+t:t;e?window.history.replaceState({path:s},"",s):window.history.pushState({path:s},"",s)}}async navigate(t,e=!1,s=!1){const r=this.currentRoute,i=this.matchRoute(t);if(!i)return{success:!1,error:`No route matched: ${t}`};if(r&&r.fullPath===i.fullPath)return{success:!0};if(this.beforeEachGuard)try{const o=await this.beforeEachGuard(i,r);if(o===!1)return{success:!1,cancelled:!0};if(typeof o=="string")return this.navigate(o,e)}catch(o){return{success:!1,error:o instanceof Error?o.message:"Guard Error"}}return this.currentRoute=i,s||this.updateBrowserHistory(t,e),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(i,r),{success:!0}}resolve(t){const e=t.startsWith("/")?t:"/"+t;return this.mode==="hash"?`#${e}`:(this.base.endsWith("/")?this.base.slice(0,-1):this.base)+e}get modeType(){return this.mode}pushWithQuery(t,e){const s=new URLSearchParams(e).toString(),r=t.includes("?")?"&":"?";return this.push(t+(s?r+s:""))}push(t){return this.navigate(t,!1)}replace(t){return this.navigate(t,!0)}back(){window.history.back()}listen(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notifyListeners(){this.listeners.forEach(t=>t())}setupListeners(){if(this.isStarted)return;const t=()=>{this.navigate(this.getPath(),!0,!0)};window.addEventListener("popstate",t),this.mode==="hash"&&!window.location.hash&&(window.location.hash="/"),this.navigate(this.getPath(),!0)}getCurrentRoute(){return this.currentRoute}}var Ue=Object.getOwnPropertyDescriptor,He=(n,t,e,s)=>{for(var r=s>1?void 0:s?Ue(t,e):t,i=n.length-1,o;i>=0;i--)(o=n[i])&&(r=o(r)||r);return r};let gt=class extends it{constructor(){super(...arguments);M(this,"unsubscribe");M(this,"level",0);M(this,"currentElement",null);M(this,"currentTagName",null);M(this,"routerAttrs",new Set);M(this,"prevPropKeys",new Set);M(this,"scheduled",!1);M(this,"cache",new Map);M(this,"latestLoadId",0)}async mounted(){this.detectLevel();const t=await oe;this.unsubscribe=t.listen(()=>{this.scheduleLoad(t.getCurrentRoute())}),this.loadRoute(t.getCurrentRoute())}unmounted(){var t;(t=this.unsubscribe)==null||t.call(this),this.cache.forEach(e=>e.remove()),this.cache.clear()}scheduleLoad(t){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t)}))}detectLevel(){let t=0,e=this.parentElement;for(;e;)e instanceof gt&&t++,e=e.parentElement;this.level=t}async loadRoute(t){const e=++this.latestLoadId,s=t==null?void 0:t.matched[this.level];if(!s){this.handleEmptyRoute();return}const{config:r,params:i}=s;let o=r.tagName;if(!o&&typeof r.component=="function"){this.renderLoading();try{const a=await r.component();o=typeof a=="string"?a:a.tagName}catch(a){this.renderError(`Load Error: ${a}`);return}}if(e!==this.latestLoadId)return;if(!o){this.clear();return}if(!r.forceReload&&this.currentElement&&this.currentTagName===o.toLowerCase()){this.syncState(this.currentElement,i,(t==null?void 0:t.query)||{},r.props);return}this.clear(r.keepAlive);const c=this.getOrCreateComponent(o,r);this.syncState(c,i,(t==null?void 0:t.query)||{},r.props),this.appendChild(c),this.currentElement=c,this.currentTagName=o.toLowerCase()}getOrCreateComponent(t,e){const s=t.toLowerCase();if(e.keepAlive&&this.cache.has(s))return this.cache.get(s);const r=document.createElement(t);return e.keepAlive&&this.cache.set(s,r),r}syncState(t,e,s,r={}){const i=a=>a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),o=new Map;Object.entries(e).forEach(([a,l])=>o.set(i(a),String(l))),Object.entries(s).forEach(([a,l])=>o.set(`query-${i(a)}`,String(l))),this.routerAttrs.forEach(a=>{o.has(a)||(t.removeAttribute(a),this.routerAttrs.delete(a))}),o.forEach((a,l)=>{t.getAttribute(l)!==a&&t.setAttribute(l,a),this.routerAttrs.add(l)});const c=new Set(Object.keys(r));this.prevPropKeys.forEach(a=>{c.has(a)||(t[a]=void 0)}),Object.entries(r).forEach(([a,l])=>{t[a]!==l&&(t[a]=l)}),this.prevPropKeys=c}handleEmptyRoute(){this.clear(),this.level===0&&this.renderError("404 Not Found")}renderLoading(){this.innerHTML='<div style="padding:20px; color:#999;">Loading...</div>'}renderError(t){this.innerHTML=`<div style="padding:20px; color:#ff4d4f;">${t}</div>`}clear(t=!1){this.currentElement?this.contains(this.currentElement)&&this.removeChild(this.currentElement):t||(this.innerHTML=""),this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};gt=He([Ct({tagName:"router-view"})],gt);const Ge=gt;var ze=Object.getOwnPropertyDescriptor,Ze=(n,t,e,s)=>{for(var r=s>1?void 0:s?ze(t,e):t,i=n.length-1,o;i>=0;i--)(o=n[i])&&(r=o(r)||r);return r};let At=class extends it{constructor(){super(...arguments);M(this,"_prefetched",!1)}async mounted(){(await oe).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",e=>{var r,i;e.defaultPrevented||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||e.button!==0||(r=e.target.closest("a"))!=null&&r.getAttribute("target")||(e.preventDefault(),(i=yt())==null||i.push(this.$data.to))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const t=yt();if(!t)return;this.$data.href=t.resolve(this.$data.to);let e=!1;if(this.$data.active)e=!0;else{const r=t.getCurrentRoute();if(r){const i=r.fullPath;this.hasAttribute("exact")?e=i===this.$data.to:e=i===this.$data.to||i.startsWith(this.$data.to+"/")}}this.$data.isActive=e;const s=this.$data.activeClass||"active";this.classList.toggle(s,e)}prefetchRoute(){if(this._prefetched||!this.hasAttribute("prefetch"))return;const t=yt();t&&typeof t.prefetch=="function"&&(t.prefetch(this.$data.to),this._prefetched=!0)}};At=Ze([Ct({tagName:"router-link",template:`
|
|
24
|
+
<a part="link" :href="$data.href" :class="{active: $data.isActive}">
|
|
25
|
+
<slot>{{$data.label || ''}}</slot>
|
|
26
|
+
</a>
|
|
27
|
+
`,styles:`
|
|
28
|
+
:host {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
a {
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
color: inherit;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* 内部 <a> 标签的默认高亮 */
|
|
39
|
+
a.active {
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* custom 模式:消除包裹 a 标签的视觉/布局影响,由 slot 内部元素接管 */
|
|
44
|
+
:host([custom]) a {
|
|
45
|
+
display: contents;
|
|
46
|
+
}
|
|
47
|
+
`,shadowDOM:{use:!0,mode:"open"},props:["to","active","exact","label","custom","activeClass","prefetch"]})],At);const Je=At;f.ASTType=m,f.BaseElement=it,f.CustomElement=Ct,f.IRRenderer=se,f.LIFECYCLE_ATTRS_MAP=Kt,f.Router=ae,f.RouterLink=Je,f.RouterView=Ge,f.buildIR=zt,f.clearIRCache=Ce,f.createFunction=Dt,f.createRender=re,f.createRouter=Ye,f.genFunction=Vt,f.getRouter=yt,f.isLifecycleKind=Yt,f.isObject=H,f.listeners=Bt,f.mapAttrKeyToLifecycleKind=qt,f.observe=Qt,f.parseHashUrl=Ee,f.parseHtml=Zt,f.showTemplateError=jt,f.transformModel=Gt,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare interface BaseElement<TData = any> {
|
|
2
|
+
}
|
|
3
|
+
declare class BaseElement<TData extends object = any> extends HTMLElement {
|
|
4
|
+
#private;
|
|
5
|
+
static get observedAttributes(): string[];
|
|
6
|
+
constructor(initialData?: TData);
|
|
7
|
+
get $data(): TData;
|
|
8
|
+
set $data(value: TData);
|
|
9
|
+
refresh(): void;
|
|
10
|
+
connectedCallback(): void;
|
|
11
|
+
disconnectedCallback(): void;
|
|
12
|
+
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
13
|
+
emit(eventName: string, detail?: any, options?: Partial<CustomEventInit>): void;
|
|
14
|
+
onInit(): void | Promise<void>;
|
|
15
|
+
created(): void;
|
|
16
|
+
mounted(): void;
|
|
17
|
+
beforeUpdate(): void;
|
|
18
|
+
updated(): void;
|
|
19
|
+
unmounted(): void;
|
|
20
|
+
attributeChanged(_name: string, _oldValue: any, _newValue: any): void;
|
|
21
|
+
beforeAttributesUpdate(): void;
|
|
22
|
+
afterAttributesUpdate(): void;
|
|
23
|
+
}
|
|
24
|
+
export default BaseElement;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Prop 配置,支持类型声明 */
|
|
2
|
-
export
|
|
2
|
+
export type PropType = "string" | "number" | "boolean" | "object";
|
|
3
|
+
export interface PropDescriptor {
|
|
3
4
|
name: string;
|
|
4
|
-
type?:
|
|
5
|
+
type?: PropType;
|
|
6
|
+
default?: any;
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
9
|
* Manifest:组件声明配置
|
|
@@ -9,9 +11,9 @@ export interface PropOption {
|
|
|
9
11
|
* 用于描述组件模板、样式、属性监听和 Shadow DOM 行为。
|
|
10
12
|
*/
|
|
11
13
|
export interface Manifest {
|
|
12
|
-
template?: string;
|
|
14
|
+
template?: string | Function;
|
|
13
15
|
styles?: string;
|
|
14
|
-
props?: Array<string |
|
|
16
|
+
props?: Array<string | PropDescriptor>;
|
|
15
17
|
shadowDOM?: {
|
|
16
18
|
use: boolean;
|
|
17
19
|
mode?: "open" | "closed";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type PathKey = string | symbol;
|
|
2
|
+
/** 变更项的原始载荷 */
|
|
3
|
+
export type ChangePayload = {
|
|
4
|
+
type: "set";
|
|
5
|
+
key: PathKey;
|
|
6
|
+
newValue: unknown;
|
|
7
|
+
oldValue: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
type: "delete";
|
|
10
|
+
key: PathKey;
|
|
11
|
+
oldValue: unknown;
|
|
12
|
+
} | {
|
|
13
|
+
type: "array-push";
|
|
14
|
+
index: number;
|
|
15
|
+
values: unknown[];
|
|
16
|
+
} | {
|
|
17
|
+
type: "array-splice";
|
|
18
|
+
index: number;
|
|
19
|
+
deleteCount: number;
|
|
20
|
+
insert: unknown[];
|
|
21
|
+
} | {
|
|
22
|
+
type: "array-replace";
|
|
23
|
+
oldValue: unknown[];
|
|
24
|
+
newValue: unknown[];
|
|
25
|
+
} | {
|
|
26
|
+
type: "array-reset";
|
|
27
|
+
method: string;
|
|
28
|
+
};
|
|
29
|
+
/** 完整的变更对象 */
|
|
30
|
+
export type ChangeItem = ChangePayload & {
|
|
31
|
+
path: PathKey[];
|
|
32
|
+
};
|
|
33
|
+
export interface ObserveOptions {
|
|
34
|
+
throttle?: number;
|
|
35
|
+
onBatch?: (changes: ChangeItem[]) => void;
|
|
36
|
+
immediate?: boolean;
|
|
37
|
+
filter?: string | string[];
|
|
38
|
+
deepCompare?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface ObserveReturn<T> {
|
|
41
|
+
proxy: T;
|
|
42
|
+
unobserve: () => void;
|
|
43
|
+
resume: () => void;
|
|
44
|
+
}
|
|
45
|
+
/** 将 Proxy 还原为原始对象 */
|
|
46
|
+
export declare function toRaw<T>(observed: T): T;
|
|
47
|
+
export declare function observe<T extends object>(value: T, callback: (change: ChangeItem) => void, options?: ObserveOptions): ObserveReturn<T>;
|
|
@@ -49,11 +49,3 @@ export interface ObserveReturn<T> {
|
|
|
49
49
|
/** 恢复监听 */
|
|
50
50
|
resume: () => void;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
* 对任意对象或数组进行深度监听
|
|
54
|
-
* @param value 要监听的对象
|
|
55
|
-
* @param callback 当对象变化时触发的回调,返回变化路径、新值、旧值
|
|
56
|
-
* @param options 配置项,可选
|
|
57
|
-
* @returns ObserveReturn 包含代理对象和控制方法
|
|
58
|
-
*/
|
|
59
|
-
export declare function observe<T extends object>(value: T, callback: (path: (string | symbol)[], newValue: any, oldValue: any) => void, options?: ObserveOptions): ObserveReturn<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './renderIR';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IRRoot, Meta } from '../../types';
|
|
2
|
+
export declare class IRRenderer {
|
|
3
|
+
private ir;
|
|
4
|
+
private container;
|
|
5
|
+
private scope;
|
|
6
|
+
private nodeMap;
|
|
7
|
+
private marker;
|
|
8
|
+
constructor(ir: IRRoot, container: HTMLElement, scope?: any);
|
|
9
|
+
evalIR(fid: number, args: any[], meta?: Meta): any;
|
|
10
|
+
private createElement;
|
|
11
|
+
private createText;
|
|
12
|
+
private createComment;
|
|
13
|
+
private applyAttrs;
|
|
14
|
+
private updateNode;
|
|
15
|
+
private irToNode;
|
|
16
|
+
private cleanupOldNodes;
|
|
17
|
+
mount(): void;
|
|
18
|
+
update(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
export interface IRRenderInstance {
|
|
22
|
+
update: () => void;
|
|
23
|
+
destroy: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare const createRender: (ir: IRRoot, el: HTMLElement, ctx?: any) => IRRenderInstance;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RouteMatch, RouterOptions, NavigationResult } from './types';
|
|
2
|
+
export declare const routerReady: Promise<Router>;
|
|
3
|
+
export declare function createRouter(options: RouterOptions): Router;
|
|
4
|
+
export declare function getRouter(): Router | null;
|
|
5
|
+
export declare class Router {
|
|
6
|
+
private routes;
|
|
7
|
+
private base;
|
|
8
|
+
private mode;
|
|
9
|
+
private beforeEachGuard?;
|
|
10
|
+
private afterEachGuard?;
|
|
11
|
+
private currentRoute;
|
|
12
|
+
private listeners;
|
|
13
|
+
constructor(options: RouterOptions);
|
|
14
|
+
matchRoute(path: string): RouteMatch | null;
|
|
15
|
+
private recursiveMatch;
|
|
16
|
+
private calculateScore;
|
|
17
|
+
private parseQuery;
|
|
18
|
+
getPath(): string;
|
|
19
|
+
private updateBrowserHistory;
|
|
20
|
+
/**
|
|
21
|
+
* @param fromEvent 标志位:是否由浏览器 popstate 事件触发
|
|
22
|
+
*/
|
|
23
|
+
navigate(path: string, replace?: boolean, fromEvent?: boolean): Promise<NavigationResult>;
|
|
24
|
+
/**
|
|
25
|
+
* 将逻辑路径解析为浏览器真实的 URL 路径
|
|
26
|
+
* 供 RouterLink 等组件生成 href 使用
|
|
27
|
+
*/
|
|
28
|
+
resolve(path: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 获取当前模式(供外部组件判断,如 RouterLink)
|
|
31
|
+
*/
|
|
32
|
+
get modeType(): 'hash' | 'history';
|
|
33
|
+
pushWithQuery(path: string, query: Record<string, string>): Promise<NavigationResult>;
|
|
34
|
+
push(path: string): Promise<NavigationResult>;
|
|
35
|
+
replace(path: string): Promise<NavigationResult>;
|
|
36
|
+
back(): void;
|
|
37
|
+
listen(cb: () => void): () => boolean;
|
|
38
|
+
private notifyListeners;
|
|
39
|
+
private isStarted;
|
|
40
|
+
setupListeners(): void;
|
|
41
|
+
getCurrentRoute(): RouteMatch | null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Router, createRouter, getRouter } from './core';
|
|
2
|
+
import { default as RouterView } from './router-view';
|
|
3
|
+
import { default as RouterLink } from './router-link';
|
|
4
|
+
import { RouteConfig, RouteMatch, NavigationGuard, RouterOptions, NavigationResult } from './types';
|
|
5
|
+
export { Router, RouterView, RouterLink, createRouter, getRouter, };
|
|
6
|
+
export type { RouteConfig, RouteMatch, NavigationGuard, RouterOptions, NavigationResult };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseElement } from '../component';
|
|
2
|
+
declare class RouterLink extends BaseElement<{
|
|
3
|
+
active: boolean;
|
|
4
|
+
to: string;
|
|
5
|
+
label: string;
|
|
6
|
+
href: string;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
custom: boolean;
|
|
9
|
+
activeClass: string;
|
|
10
|
+
prefetch: boolean;
|
|
11
|
+
}> {
|
|
12
|
+
private _prefetched;
|
|
13
|
+
mounted(): Promise<void>;
|
|
14
|
+
updateState(): void;
|
|
15
|
+
private prefetchRoute;
|
|
16
|
+
}
|
|
17
|
+
export default RouterLink;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseElement } from '../component';
|
|
2
|
+
import { RouteMatch } from './types';
|
|
3
|
+
declare class RouterView extends BaseElement {
|
|
4
|
+
private unsubscribe?;
|
|
5
|
+
private level;
|
|
6
|
+
private currentElement;
|
|
7
|
+
private currentTagName;
|
|
8
|
+
private routerAttrs;
|
|
9
|
+
private prevPropKeys;
|
|
10
|
+
private scheduled;
|
|
11
|
+
private cache;
|
|
12
|
+
private latestLoadId;
|
|
13
|
+
mounted(): Promise<void>;
|
|
14
|
+
unmounted(): void;
|
|
15
|
+
private scheduleLoad;
|
|
16
|
+
private detectLevel;
|
|
17
|
+
loadRoute(route: RouteMatch | null): Promise<void>;
|
|
18
|
+
private getOrCreateComponent;
|
|
19
|
+
private syncState;
|
|
20
|
+
private handleEmptyRoute;
|
|
21
|
+
private renderLoading;
|
|
22
|
+
private renderError;
|
|
23
|
+
private clear;
|
|
24
|
+
}
|
|
25
|
+
export default RouterView;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface RouteConfig {
|
|
2
|
+
/** 路由路径,例如 '/user/:id' */
|
|
3
|
+
path: string;
|
|
4
|
+
/** * 组件标签名。
|
|
5
|
+
* 如果是同步路由,直接提供 tagName;如果是异步,可在加载后确定。
|
|
6
|
+
*/
|
|
7
|
+
tagName?: string;
|
|
8
|
+
/** * 异步组件加载函数。
|
|
9
|
+
* 支持返回标签名字符串,或者一个包含 tagName 的对象(例如 import 的模块)。
|
|
10
|
+
*/
|
|
11
|
+
component?: () => Promise<string | {
|
|
12
|
+
tagName: string;
|
|
13
|
+
} | any>;
|
|
14
|
+
/** 路由名称,用于命名路由跳转 */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** * 是否缓存组件实例。
|
|
17
|
+
* 开启后,切换路由时组件不会被销毁,而是保存在 RouterView 的缓存池中。
|
|
18
|
+
*/
|
|
19
|
+
keepAlive?: boolean;
|
|
20
|
+
/** * 是否强制重新加载。
|
|
21
|
+
* 即使 tagName 相同,如果为 true,也会销毁重建组件而不是复用。
|
|
22
|
+
*/
|
|
23
|
+
forceReload?: boolean;
|
|
24
|
+
/** 重定向路径 */
|
|
25
|
+
redirect?: string;
|
|
26
|
+
/** * 传递给组件的属性。
|
|
27
|
+
* 可以是静态对象,也可以是更复杂的配置。
|
|
28
|
+
*/
|
|
29
|
+
props?: Record<string, any>;
|
|
30
|
+
/** 路由元信息,用于存放权限、标题等自定义数据 */
|
|
31
|
+
meta?: Record<string, any>;
|
|
32
|
+
/** 嵌套子路由 */
|
|
33
|
+
children?: RouteConfig[];
|
|
34
|
+
/** * 标识是否为异步路由(可选)。
|
|
35
|
+
* 实际上通常可以通过判断 component 属性是否存在来推断。
|
|
36
|
+
*/
|
|
37
|
+
async?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface MatchedRoute {
|
|
40
|
+
config: RouteConfig;
|
|
41
|
+
params: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
export interface RouteMatch {
|
|
44
|
+
fullPath: string;
|
|
45
|
+
params: Record<string, string>;
|
|
46
|
+
query: Record<string, string>;
|
|
47
|
+
matched: MatchedRoute[];
|
|
48
|
+
meta: Record<string, any>;
|
|
49
|
+
}
|
|
50
|
+
export interface NavigationGuard {
|
|
51
|
+
(to: RouteMatch, from: RouteMatch): boolean | Promise<boolean> | string;
|
|
52
|
+
}
|
|
53
|
+
export interface RouterOptions {
|
|
54
|
+
routes: RouteConfig[];
|
|
55
|
+
base?: string;
|
|
56
|
+
mode?: 'hash' | 'history';
|
|
57
|
+
beforeEach?: NavigationGuard;
|
|
58
|
+
afterEach?: (to: RouteMatch, from: RouteMatch) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface NavigationResult {
|
|
61
|
+
success: boolean;
|
|
62
|
+
cancelled?: boolean;
|
|
63
|
+
redirect?: string;
|
|
64
|
+
error?: string;
|
|
65
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Meta } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 显示模板错误信息,提供友好的错误提示和代码定位
|
|
4
|
+
* @param error 错误对象
|
|
5
|
+
* @param source 源代码字符串
|
|
6
|
+
* @param meta 错误元数据,包含位置信息和表达式
|
|
7
|
+
* @param componentName 组件名称
|
|
8
|
+
*/
|
|
9
|
+
export declare function showTemplateError(error: unknown, source?: string, meta?: Meta, componentName?: string): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type SourceLocation = [number, number];
|
|
2
|
+
export interface Attribute {
|
|
3
|
+
key: string;
|
|
4
|
+
value: string;
|
|
5
|
+
loc: SourceLocation;
|
|
6
|
+
/**
|
|
7
|
+
* 执行语义角色(Execution Role)
|
|
8
|
+
*
|
|
9
|
+
* - model:
|
|
10
|
+
* 数据同步语义(如 s-model / v-model 展开)
|
|
11
|
+
* 必须在同一事件中最先执行,
|
|
12
|
+
* 以保证用户事件观察到的是最新数据状态
|
|
13
|
+
*
|
|
14
|
+
* - user:
|
|
15
|
+
* 用户显式声明的事件处理逻辑(@click / @input 等)
|
|
16
|
+
* 在 model 同步完成后执行
|
|
17
|
+
*/
|
|
18
|
+
role?: 'model' | 'user';
|
|
19
|
+
}
|
|
20
|
+
export declare enum ASTType {
|
|
21
|
+
Element = 0,
|
|
22
|
+
Text = 1,
|
|
23
|
+
Comment = 2,
|
|
24
|
+
If = 3,
|
|
25
|
+
ElseIf = 4,
|
|
26
|
+
Else = 5,
|
|
27
|
+
For = 6,
|
|
28
|
+
Conditional = 7,// if-elseif-else 结构
|
|
29
|
+
Other = 99
|
|
30
|
+
}
|
|
31
|
+
export interface ASTNode {
|
|
32
|
+
type: ASTType;
|
|
33
|
+
tag: string;
|
|
34
|
+
loc: SourceLocation;
|
|
35
|
+
children?: ASTNode[];
|
|
36
|
+
attrs?: Attribute[];
|
|
37
|
+
content?: string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 组件属性配置选项
|
|
3
|
+
*/
|
|
4
|
+
export interface PropOption {
|
|
5
|
+
/** 属性名,对应 HTML attribute */
|
|
6
|
+
name: string;
|
|
7
|
+
/** 属性类型 */
|
|
8
|
+
type?: 'string' | 'number' | 'boolean' | 'object';
|
|
9
|
+
/** 是否必填 */
|
|
10
|
+
required?: boolean;
|
|
11
|
+
/** 默认值 */
|
|
12
|
+
default?: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 组件声明配置
|
|
16
|
+
* 用于描述组件模板、样式、属性监听和 Shadow DOM 行为
|
|
17
|
+
*/
|
|
18
|
+
export interface ComponentManifest {
|
|
19
|
+
/** HTML 模板字符串或模板函数 */
|
|
20
|
+
template?: string | Function;
|
|
21
|
+
/** 组件样式(CSS 字符串) */
|
|
22
|
+
styles?: string;
|
|
23
|
+
/** 支持的属性列表 */
|
|
24
|
+
props?: Array<string | PropOption>;
|
|
25
|
+
/** Shadow DOM 配置 */
|
|
26
|
+
shadowDOM?: {
|
|
27
|
+
/** 是否使用 Shadow DOM */
|
|
28
|
+
use: boolean;
|
|
29
|
+
/** Shadow DOM 模式 */
|
|
30
|
+
mode?: "open" | "closed";
|
|
31
|
+
};
|
|
32
|
+
/** 组件根元素类名 */
|
|
33
|
+
className?: string;
|
|
34
|
+
/** 注册的自定义元素标签名 */
|
|
35
|
+
tagName: string;
|
|
36
|
+
/** 内部使用的配置标记 */
|
|
37
|
+
hasConfig?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 组件生命周期钩子接口
|
|
41
|
+
*/
|
|
42
|
+
export interface ComponentLifecycle {
|
|
43
|
+
/** 组件创建完成(构造函数结束时调用) */
|
|
44
|
+
created?(): void;
|
|
45
|
+
/** 组件首次挂载到 DOM 后调用 */
|
|
46
|
+
mounted?(): void;
|
|
47
|
+
/** 每次更新前调用 */
|
|
48
|
+
beforeUpdate?(): void;
|
|
49
|
+
/** 每次更新完成后调用 */
|
|
50
|
+
updated?(): void;
|
|
51
|
+
/** 组件从 DOM 中卸载时调用 */
|
|
52
|
+
unmounted?(): void;
|
|
53
|
+
/** 兼容旧组件的初始化钩子(首次 mounted 后调用) */
|
|
54
|
+
onInit?(): void | Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* BaseElement 泛型接口
|
|
58
|
+
*/
|
|
59
|
+
export interface IBaseElement<TData = any> extends HTMLElement, ComponentLifecycle {
|
|
60
|
+
/** 组件配置 */
|
|
61
|
+
_manifest: ComponentManifest;
|
|
62
|
+
/** 组件数据 */
|
|
63
|
+
$data: TData;
|
|
64
|
+
/** 手动刷新组件 */
|
|
65
|
+
refresh(): void;
|
|
66
|
+
}
|