@geektech/tsone 0.2.1 → 0.3.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-zh.md +24 -10
- package/README.md +26 -10
- package/dist/core/reactive/scheduler.d.ts +32 -0
- package/dist/core/reactive.d.ts +12 -0
- package/dist/dom/index.d.ts +1 -1
- package/dist/dom/index.js +2 -2179
- package/dist/dom/index.js.map +3 -3
- package/dist/index-939sv8vt.js +26 -0
- package/dist/{index-ffzday7h.js.map → index-939sv8vt.js.map} +2 -2
- package/dist/index-p55hs6x8.js +12 -0
- package/dist/{index-1x4ectvr.js.map → index-p55hs6x8.js.map} +7 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -267
- package/dist/index.js.map +3 -3
- package/dist/router/index.js +2 -16
- package/dist/router/index.js.map +1 -1
- package/dist/style/index.js +2 -9
- package/dist/style/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-1x4ectvr.js +0 -2453
- package/dist/index-ffzday7h.js +0 -91
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"export interface StyleOptions {\n selector: string;\n properties: Record<string, string | number>;\n hover?: Record<string, string | number>;\n media?: Record<string, Record<string, string | number>>;\n}\n\nexport class StyleManager {\n public styleElement: HTMLStyleElement;\n public styles: Map<string, StyleOptions> = new Map();\n\n constructor() {\n this.styleElement = document.createElement('style');\n document.head.appendChild(this.styleElement);\n }\n\n public addStyle(name: string, options: StyleOptions): void {\n this.styles.set(name, options);\n this.updateStyles();\n }\n\n public removeStyle(name: string): void {\n this.styles.delete(name);\n this.updateStyles();\n }\n\n public clearStyles(): void {\n this.styles.clear();\n this.styleElement.textContent = '';\n }\n\n public destroy(): void {\n this.clearStyles();\n this.styleElement.remove();\n }\n\n private convertToCSS(properties: Record<string, string | number>): string {\n return Object.entries(properties)\n .map(([key, value]) => {\n const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();\n return `${cssKey}: ${value};`;\n })\n .join('\\n');\n }\n\n private updateStyles(): void {\n let cssText = '';\n\n this.styles.forEach((style) => {\n // 基础样式\n cssText += `${style.selector} {\\n${this.convertToCSS(style.properties)}\\n}\\n`;\n\n // hover 样式\n if (style.hover) {\n cssText += `${style.selector}:hover {\\n${this.convertToCSS(style.hover)}\\n}\\n`;\n }\n\n // media 查询\n if (style.media) {\n Object.entries(style.media).forEach(([query, properties]) => {\n cssText += `@media ${query} {\\n${style.selector} {\\n${this.convertToCSS(properties)}\\n}\\n}\\n`;\n });\n }\n });\n\n this.styleElement.textContent = cssText;\n }\n}\n",
|
|
6
6
|
"export type StyleValue = string | number;\n\nexport type StyleProperties = Record<string, StyleValue>;\n\nexport interface StyleRule {\n selector: string;\n properties: StyleProperties;\n}\n\nexport interface StyleAtRule {\n atRule: string;\n rules: StyleRule[];\n}\n\nexport type StyleSheetEntry = StyleRule | StyleAtRule;\n\nexport type StyleSheet = StyleSheetEntry[];\n\nexport function renderStyleSheet(styles: StyleSheet): string {\n return styles.map((entry) => renderStyleEntry(entry)).join('\\n\\n');\n}\n\nfunction renderStyleEntry(entry: StyleSheetEntry, indent = ''): string {\n if ('atRule' in entry) {\n const rules = entry.rules\n .map((rule) => renderStyleEntry(rule, `${indent} `))\n .join('\\n\\n');\n\n return `${indent}${entry.atRule} {\\n${rules}\\n${indent}}`;\n }\n\n const declarations = Object.entries(entry.properties)\n .map(\n ([property, value]) =>\n `${indent} ${toCssProperty(property)}: ${String(value)};`\n )\n .join('\\n');\n\n return `${indent}${entry.selector} {\\n${declarations}\\n${indent}}`;\n}\n\nfunction toCssProperty(property: string): string {\n if (property.startsWith('--') || property.includes('-')) {\n return property;\n }\n\n return property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": "AAOO,MAAM,CAAa,CACjB,aACA,OAAoC,IAAI,IAE/C,WAAW,EAAG,CACZ,KAAK,aAAe,SAAS,cAAc,OAAO,EAClD,SAAS,KAAK,YAAY,KAAK,YAAY,EAGtC,QAAQ,CAAC,EAAc,EAA6B,CACzD,KAAK,OAAO,IAAI,EAAM,CAAO,EAC7B,KAAK,aAAa,EAGb,WAAW,CAAC,EAAoB,CACrC,KAAK,OAAO,OAAO,CAAI,EACvB,KAAK,aAAa,EAGb,WAAW,EAAS,CACzB,KAAK,OAAO,MAAM,EAClB,KAAK,aAAa,YAAc,GAG3B,OAAO,EAAS,CACrB,KAAK,YAAY,EACjB,KAAK,aAAa,OAAO,EAGnB,YAAY,CAAC,EAAqD,CACxE,OAAO,OAAO,QAAQ,CAAU,EAC7B,IAAI,EAAE,EAAK,KAEH,GADQ,EAAI,QAAQ,WAAY,KAAK,EAAE,YAAY,MACrC,IACtB,EACA,KAAK;AAAA,CAAI,EAGN,YAAY,EAAS,CAC3B,IAAI,EAAU,GAEd,KAAK,OAAO,QAAQ,CAAC,IAAU,CAK7B,GAHA,GAAW,GAAG,EAAM;AAAA,EAAe,KAAK,aAAa,EAAM,UAAU;AAAA;AAAA,EAGjE,EAAM,MACR,GAAW,GAAG,EAAM;AAAA,EAAqB,KAAK,aAAa,EAAM,KAAK;AAAA;AAAA,EAIxE,GAAI,EAAM,MACR,OAAO,QAAQ,EAAM,KAAK,EAAE,QAAQ,EAAE,EAAO,KAAgB,CAC3D,GAAW,UAAU;AAAA,EAAY,EAAM;AAAA,EAAe,KAAK,aAAa,CAAU;AAAA;AAAA;AAAA,EACnF,EAEJ,EAED,KAAK,aAAa,YAAc,EAEpC,CCjDO,SAAS,CAAgB,CAAC,EAA4B,CAC3D,OAAO,EAAO,IAAI,CAAC,IAAU,EAAiB,CAAK,CAAC,EAAE,KAAK;AAAA;AAAA,CAAM,EAGnE,SAAS,CAAgB,CAAC,EAAwB,EAAS,GAAY,CACrE,GAAI,WAAY,EAAO,CACrB,IAAM,EAAQ,EAAM,MACjB,IAAI,CAAC,IAAS,EAAiB,EAAM,GAAG,KAAU,CAAC,EACnD,KAAK;AAAA;AAAA,CAAM,EAEd,MAAO,GAAG,IAAS,EAAM;AAAA,EAAa;AAAA,EAAU,KAGlD,IAAM,EAAe,OAAO,QAAQ,EAAM,UAAU,EACjD,IACC,EAAE,EAAU,KACV,GAAG,MAAW,EAAc,CAAQ,MAAM,OAAO,CAAK,IAC1D,EACC,KAAK;AAAA,CAAI,EAEZ,MAAO,GAAG,IAAS,EAAM;AAAA,EAAe;AAAA,EAAiB,KAG3D,SAAS,CAAa,CAAC,EAA0B,CAC/C,GAAI,EAAS,WAAW,IAAI,GAAK,EAAS,SAAS,GAAG,EACpD,OAAO,EAGT,OAAO,EAAS,QAAQ,SAAU,CAAC,IAAU,IAAI,EAAM,YAAY,GAAG",
|
|
9
|
+
"debugId": "E95DD9BDDD5C24A364756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{Ca as se,Da as U}from"./index-939sv8vt.js";var R=Symbol("is_reactive"),d=Symbol("is_readonly"),H=Symbol("is_ref"),W=["push","pop","shift","unshift","splice","sort","reverse"];function f(e,t){return Boolean(Reflect.get(e,t))}function h(e){return e!==null&&typeof e==="object"}class I{pending=new Set;flushing=!1;flushPromise=null;flushResolve=null;enqueue(e){if(this.pending.has(e))return;if(this.pending.add(e),!this.flushing)queueMicrotask(()=>this.flush())}flush(){if(this.flushing)return;this.flushing=!0;try{while(this.pending.size>0){let e=Array.from(this.pending);this.pending.clear();for(let t of e)if(t.active)t()}}finally{this.flushing=!1;let e=this.flushResolve;this.flushResolve=null,this.flushPromise=null,e?.()}}nextTick(){if(!this.flushing&&this.pending.size===0)return Promise.resolve();if(this.flushPromise)return this.flushPromise;return this.flushPromise=new Promise((e)=>{this.flushResolve=e}),this.flushPromise}}var me=0,L=new I;function Ue(){return L.nextTick()}function Fe(){L.flush()}class m{static instance;activeEffect=null;effectStack=[];targetMap=new WeakMap;reactiveMap=new WeakMap;readonlyMap=new WeakMap;constructor(){}static getInstance(){if(!m.instance)m.instance=new m;return m.instance}reactive(e){if(!h(e))return console.warn("reactive: target must be an object"),e;if(ve(e))return e;if(this.reactiveMap.has(e))return this.reactiveMap.get(e);if(Array.isArray(e))return this.createReactiveArray(e);let t=new Proxy(e,{get:(n,o)=>{if(o===R)return!0;if(o===d)return!1;this.track(n,o);let r=Reflect.get(n,o);if(h(r)&&!f(r,d))return this.reactive(r);return r},set:(n,o,r)=>{if(f(n,d))return console.warn(`Cannot set property ${String(o)} on readonly object`),!1;let i=Reflect.get(n,o);if(h(r)&&!f(r,R)&&!f(r,d))r=this.reactive(r);let s=Reflect.set(n,o,r);if(i!==r)this.trigger(n,o);return s},deleteProperty:(n,o)=>{if(f(n,d))return console.warn(`Cannot delete property ${String(o)} on readonly object`),!1;let r=o in n,i=Reflect.deleteProperty(n,o);if(r)this.trigger(n,o);return i}});return this.reactiveMap.set(e,t),t}createReactiveArray(e){if(this.reactiveMap.has(e))return this.reactiveMap.get(e);let t=new Proxy(e,{get:(n,o)=>{if(o===R)return!0;if(o===d)return!1;this.track(n,o);let r=Reflect.get(n,o);if(typeof o==="string"&&W.includes(o))return(...i)=>{let a=r.apply(n,i);return this.trigger(n,"length"),this.trigger(n,o),a};if(h(r)&&!f(r,d))return this.reactive(r);return r},set:(n,o,r)=>{if(f(n,d))return console.warn(`Cannot set property ${String(o)} on readonly object`),!1;let i=Reflect.get(n,o);if(h(r)&&!f(r,R)&&!f(r,d))r=this.reactive(r);let s=Reflect.set(n,o,r);if(i!==r){if(this.trigger(n,o),typeof o==="string"&&!isNaN(Number(o)))this.trigger(n,"length")}return s},deleteProperty:(n,o)=>{if(f(n,d))return console.warn(`Cannot delete property ${String(o)} on readonly object`),!1;let r=o in n,i=Reflect.deleteProperty(n,o);if(r)this.trigger(n,o),this.trigger(n,"length");return i}});return this.reactiveMap.set(e,t),t}readonly(e){if(!h(e))return console.warn("readonly: target must be an object"),e;if(f(e,d))return e;if(this.readonlyMap.has(e))return this.readonlyMap.get(e);let t=new Proxy(e,{get:(n,o)=>{if(o===R)return!1;if(o===d)return!0;let r=Reflect.get(n,o);if(h(r))return this.readonly(r);return r},set:()=>(console.warn("Cannot set property on readonly object"),!1),deleteProperty:()=>(console.warn("Cannot delete property on readonly object"),!1)});return this.readonlyMap.set(e,t),t}effect(e,t){let{lazy:n=!1,scheduler:o,throwOnError:r=!1}=t||{},i=()=>{if(!i.active)return e();try{return this.cleanup(i),this.effectStack.push(i),this.activeEffect=i,e()}catch(s){if(r)throw s;console.error("Effect error:",s);return}finally{this.effectStack.pop(),this.activeEffect=this.effectStack[this.effectStack.length-1]??null}};if(i.id=me++,i.deps=[],i.active=!0,i.scheduler=o,!n)i();return i}computed(e){let t=!0,n,o={},r=()=>{this.track(o,"value")},i=this.effect(()=>{n=e(),t=!1},{lazy:!0,scheduler:()=>{if(!t)t=!0,this.trigger(o,"value")}});return{get value(){if(t)i();return r(),n}}}cleanup(e){e.deps.forEach((t)=>{t.delete(e)}),e.deps.length=0}track(e,t){if(!this.activeEffect||!this.activeEffect.active)return;let n=this.targetMap.get(e);if(!n)n=new Map,this.targetMap.set(e,n);let o=n.get(t);if(!o)o=new Set,n.set(t,o);if(!o.has(this.activeEffect))o.add(this.activeEffect),this.activeEffect.deps.push(o)}trigger(e,t){let n=this.targetMap.get(e);if(!n)return;let o=n.get(t);if(!o)return;new Set(o).forEach((i)=>{if(i.active)if(i.scheduler)i.scheduler(i);else i()})}stop(e){if(e.active)this.cleanup(e),e.active=!1}}function j(e){return m.getInstance().reactive(e)}function We(e){return m.getInstance().readonly(e)}function g(e,t){return m.getInstance().effect(e,t)}function ze(e){return m.getInstance().computed(e)}function qe(e){let t={value:e};return Object.defineProperty(t,H,{configurable:!1,enumerable:!1,value:!0}),j(t)}function ge(e){return h(e)&&Boolean(Reflect.get(e,H))}function Ye(e){return ge(e)?e.value:e}function v(e){m.getInstance().stop(e)}function ve(e){return h(e)&&f(e,R)}function Xe(e){return h(e)&&f(e,d)}function z(e){return typeof e==="object"&&e!==null&&"component"in e}function N(e){return typeof e==="object"&&e!==null&&"tag"in e&&e.tag!=="slot"}function q(e){return typeof e==="object"&&e!==null&&"tag"in e&&e.tag==="slot"}function Ze(e,t,n,o,r,i){return{tag:e,props:t,children:n,listeners:o,key:r,directions:i}}function ye(e,t={}){return{tag:e,...t}}function p(e){return(t={})=>ye(e,t)}var S=p("div"),Je=p("span"),et=p("p"),tt=p("button"),nt=p("input"),ot=p("section"),rt=p("main"),it=p("header"),st=p("footer"),at=p("nav"),pt=p("article"),ut=p("aside"),ct=p("h1"),lt=p("h2"),dt=p("h3"),ft=p("h4"),ht=p("h5"),mt=p("h6"),gt=p("strong"),vt=p("em"),yt=p("small"),Rt=p("pre"),Tt=p("code"),Ct=p("blockquote"),Et=p("ul"),bt=p("ol"),xt=p("li"),St=p("a"),wt=p("img"),Mt=p("form"),Lt=p("label"),Nt=p("textarea"),At=p("select"),Pt=p("option"),kt=p("table"),Ht=p("thead"),It=p("tbody"),jt=p("tr"),Ot=p("th"),Bt=p("td");function _t(e,t,n,o,r){return{component:e,props:t,children:n,key:o,directions:r}}function Vt(e,t,n){return{tag:"slot",props:{name:e},key:t,directions:n}}function Dt(e,t,n){return e.map((o,r)=>{let i=t(o,r);if(typeof i==="string")throw Error("each render callback must return a VNode");return{...i,key:n(o,r)}})}function X(e){let t=e.split(".");if(e.length===0||t.some((n)=>n.length===0||n==="__proto__"||n==="prototype"||n==="constructor"))throw Error(`Invalid model path "${e}"`);return t}function B(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Q(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Re(e){return typeof e==="string"?e:e.path}function Y(e,t){let n=e;for(let o of X(t)){if(!B(n))throw Error(`Invalid model path "${t}"`);if(!Q(n,o)){if(o in n)throw Error(`Invalid model path "${t}"`);return}n=n[o]}return n}function Te(e,t,n){let o=X(t),r=e;for(let s of o.slice(0,-1)){if(!Q(r,s)){if(s in r)throw Error(`Invalid model path "${t}"`);r[s]={}}else if(!B(r[s]))throw Error(`Invalid model path "${t}"`);let a=r[s];if(!B(a))throw Error(`Invalid model path "${t}"`);r=a}let i=o[o.length-1];r[i]=n}function O(e,t){if(typeof e!=="string"&&e.format)return e.format(t);return t===void 0||t===null?"":String(t)}function Ce(e,t){if(typeof e!=="string"&&e.parse)return e.parse(t);return t}function Ee(e,t,n){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){e.checked=Array.isArray(n)?n.some((o)=>String(o)===e.value):Boolean(n);return}if(e.type==="radio"){e.checked=n===e.value;return}e.value=O(t,n);return}if(e instanceof HTMLTextAreaElement){e.value=O(t,n);return}if(e instanceof HTMLSelectElement){if(e.multiple){let o=Array.isArray(n)?new Set(n.map(String)):new Set;for(let r=0;r<e.options.length;r+=1){let i=e.options.item(r);if(!i)continue;i.selected=o.has(i.value)}return}e.value=O(t,n)}}function be(e,t){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){if(Array.isArray(t)){let n=t.filter((o)=>String(o)!==e.value);return e.checked?[...n,e.value]:n}return e.checked}if(e.type==="radio")return e.checked?e.value:t;return e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement){if(!e.multiple)return e.value;let n=[];for(let o=0;o<e.selectedOptions.length;o+=1){let r=e.selectedOptions.item(o);if(r)n.push(r.value)}return n}return}class _{bindings=new WeakMap;bind(e,t,n){if(!this.isSupportedControl(e))return;let o=this.bindings.get(e);if(o&&this.sameBinding(o,t))return;this.cleanup(e);let r=Re(t),i=()=>Ee(e,t,Y(n,r)),s=e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement&&!["checkbox","radio"].includes(e.type)?"input":"change",a=()=>{let l=Y(n,r);Te(n,r,Ce(t,be(e,l)))};e.addEventListener(s,a);let u=g(i);this.bindings.set(e,{binding:t,path:r,parse:typeof t==="string"?void 0:t.parse,format:typeof t==="string"?void 0:t.format,eventName:s,listener:a,effect:u})}cleanup(e){let t=this.bindings.get(e);if(!t)return;e.removeEventListener(t.eventName,t.listener),v(t.effect),this.bindings.delete(e)}isSupportedControl(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}sameBinding(e,t){if(typeof e.binding==="string"||typeof t==="string")return e.binding===t;return e.path===t.path&&e.parse===t.parse&&e.format===t.format}}function A(e){return/^on[A-Z]/.test(e)||/^on[a-z]/.test(e)}function Z(e){return e.slice(2).toLowerCase()}function J(e){let[t,...n]=e.split(".");return{eventName:t,modifiers:new Set(n)}}function ee(e,t){let n=(o)=>{if(t.has("stop"))o.stopPropagation();if(t.has("prevent"))o.preventDefault();if(t.has("self")&&o.currentTarget!==o.target)return;if(t.has("once"))o.currentTarget.removeEventListener(o.type,n);e(o)};return n}function te(e,t,n){let o=t.includes("-")?t:t.replace(/[A-Z]/g,(r)=>`-${r.toLowerCase()}`);e.setProperty(o,String(n))}class E{listeners=new WeakMap;effects=new WeakMap;modelBindings=new _;matches(e){return typeof e==="object"&&e!==null&&N(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=document.createElement(e.tag);return this.applyProps(n,{},e.props??{},t),this.updateListeners(n,{},this.collectListeners(e)),this.mountChildren(n,e,t),this.applyDirections(n,void 0,e.directions,t),n}patch(e,t,n,o){if(e.tag!==t.tag||n.nodeType===Node.COMMENT_NODE){let r=this.mount(t,o);return n.parentNode?.replaceChild(r,n),this.unmount(e,n,o),r}if(!(n instanceof HTMLElement))return n;if(t.directions?.if===!1){let r=document.createComment("if");return n.parentNode?.replaceChild(r,n),this.unmount(e,n,o),r}return this.applyProps(n,e.props??{},t.props??{},o),this.updateListeners(n,this.collectListeners(e),this.collectListeners(t)),this.updateChildren(n,e,t,o),this.applyDirections(n,e.directions,t.directions,o),n}unmount(e,t,n){if(!(t instanceof HTMLElement))return;this.effects.get(t)?.forEach((o)=>v(o)),this.effects.delete(t),this.listeners.get(t)?.forEach(({eventName:o,listener:r})=>{t.removeEventListener(o,r)}),this.listeners.delete(t),this.modelBindings.cleanup(t),this.unmountChildren(t,e,n)}mountChildren(e,t,n){(t.children??[]).forEach((o)=>{e.appendChild(n.renderer.mount(o,n))})}updateChildren(e,t,n,o){this.updateOrdinaryChildren(e,t.children??[],n.children??[],o)}unmountChildren(e,t,n){(t.children??[]).forEach((o,r)=>{let i=e.childNodes[r];if(i)n.renderer.unmount(o,i,n)})}applyProps(e,t,n,o){Object.keys(t).forEach((r)=>{if(A(r)||r in n)return;if(r==="className"||r==="class")e.removeAttribute("class");else if(r==="style")e.removeAttribute("style");else e.removeAttribute(r)}),Object.entries(n).forEach(([r,i])=>{if(A(r))return;if(r==="className"||r==="class"){e.className=String(i??"");return}if(r==="style"&&typeof i==="object"&&i!==null){e.removeAttribute("style"),Object.entries(i).forEach(([s,a])=>{te(e.style,s,a)});return}if(i===!1||i===void 0||i===null){e.removeAttribute(r);return}if(i===!0){e.setAttribute(r,"");return}if(typeof i==="string"&&o.templateEngine.hasExpressions(i)){this.setupReactiveAttribute(e,r,i,o);return}e.setAttribute(r,String(i))})}applyDirections(e,t,n,o){if(n&&"show"in n)e.style.display=n.show?"":"none";else if(t&&"show"in t)e.style.display="";if(!n?.model){this.modelBindings.cleanup(e);return}this.modelBindings.bind(e,n.model,o.templateEngine.state)}updateOrdinaryChildren(e,t,n,o){if(this.assertNoDuplicateKeys(t),this.assertNoDuplicateKeys(n),this.hasOnlyKeyedChildren(t,n)){this.updateKeyedChildren(e,t,n,o);return}let r=Math.min(t.length,n.length);for(let i=0;i<r;i+=1){let s=e.childNodes[i];if(!s){e.appendChild(o.renderer.mount(n[i],o));continue}o.renderer.patch(t[i],n[i],s,o)}for(let i=r;i<n.length;i+=1)e.appendChild(o.renderer.mount(n[i],o));for(let i=t.length-1;i>=n.length;i-=1){let s=e.childNodes[i];if(s){if(o.renderer.unmount(t[i],s,o),s.parentNode===e)e.removeChild(s)}}}updateKeyedChildren(e,t,n,o){let r=t.map((a,u)=>({vnode:a,node:e.childNodes[u],index:u})),i=new Map,s=new Set;r.forEach((a)=>{let u=this.getVNodeKey(a.vnode);if(u!==void 0&&a.node)i.set(u,{vnode:a.vnode,node:a.node,index:a.index})}),n.forEach((a,u)=>{let l=this.getVNodeKey(a),c=l===void 0?void 0:i.get(l),y;if(c)y=o.renderer.patch(c.vnode,a,c.node,o),s.add(c.index);else y=o.renderer.mount(a,o);let C=e.childNodes[u]??null;if(y!==C)e.insertBefore(y,C)}),r.forEach((a)=>{if(!a.node||s.has(a.index))return;if(o.renderer.unmount(a.vnode,a.node,o),a.node.parentNode===e)e.removeChild(a.node)})}hasOnlyKeyedChildren(e,t){return[...e,...t].every((n)=>this.getVNodeKey(n)!==void 0)}assertNoDuplicateKeys(e){let t=new Set;e.forEach((n)=>{let o=this.getVNodeKey(n);if(o===void 0)return;if(t.has(o))throw Error(`Duplicate key "${o}"`);t.add(o)})}getVNodeKey(e){if(typeof e==="string")return;return e.key}collectListeners(e){let t={};return Object.entries(e.props??{}).forEach(([n,o])=>{if(A(n)&&typeof o==="function")t[Z(n)]=o}),{...t,...e.listeners??{}}}updateListeners(e,t,n){let o=this.listeners.get(e)??new Map,r=new Set(Object.keys(t)),i=new Set(Object.keys(n));r.forEach((s)=>{if(!i.has(s)||t[s]!==n[s]){let a=o.get(s);if(a)e.removeEventListener(a.eventName,a.listener),o.delete(s)}}),i.forEach((s)=>{if(!r.has(s)||t[s]!==n[s]){let{eventName:a,modifiers:u}=J(s),l=ee(n[s],u);e.addEventListener(a,l),o.set(s,{eventName:a,listener:l})}}),this.listeners.set(e,o)}setupReactiveAttribute(e,t,n,o){let r=g(()=>{e.setAttribute(t,o.templateEngine.evaluateTemplateValue(n))});this.trackEffect(e,r)}trackEffect(e,t){let n=this.effects.get(e)??new Set;n.add(t),this.effects.set(e,n)}}var xe={fade:[{opacity:0},{opacity:1}],"slide-up":[{opacity:0,transform:"translateY(12px)"},{opacity:1,transform:"translateY(0)"}],"slide-down":[{opacity:0,transform:"translateY(-12px)"},{opacity:1,transform:"translateY(0)"}],"slide-left":[{opacity:0,transform:"translateX(12px)"},{opacity:1,transform:"translateX(0)"}],"slide-right":[{opacity:0,transform:"translateX(-12px)"},{opacity:1,transform:"translateX(0)"}],scale:[{opacity:0,transform:"scale(0.95)"},{opacity:1,transform:"scale(1)"}]};class V{runs=new WeakMap;playEnter(e,t){return this.play(e,t,"enter")}playExit(e,t){return this.play(e,t,"exit")}cancel(e){let t=this.runs.get(e);if(!t)return;this.runs.delete(e),t.animation.cancel()}play(e,t,n){if(this.cancel(e),!this.canAnimate(e))return null;let o=xe[t.type],r=n==="enter"?[...o]:[...o].reverse(),i={duration:t.duration,easing:"ease",fill:"both"},s=e.animate(r,i),a=Symbol("list-animation"),u=s.finished.then(()=>"finished",()=>"cancelled"),l={animation:s,token:a,keyframes:r,options:i,finished:u};return this.runs.set(e,l),u.then((c)=>{if(this.runs.get(e)?.token!==a)return;if(this.runs.delete(e),n==="enter"&&c==="finished")s.cancel()}),l}canAnimate(e){return!(typeof window<"u"&&typeof window.matchMedia==="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches)&&typeof e.animate==="function"}}var Se=["fade","slide-up","slide-down","slide-left","slide-right","scale"];function on(e){let t=(e.tag??"div").trim(),n=e.type??"fade",o=e.duration??300;if(!t)throw Error("TransitionGroup tag must not be empty");if(!Se.includes(n))throw Error(`Unknown TransitionGroup animation type "${n}"`);if(!Number.isFinite(o)||o<0)throw Error("TransitionGroup duration must be a non-negative finite number");return{tag:t,type:n,duration:o}}function D(e){let t=new Set;return e.map((n)=>{if(typeof n==="string"||n.key===void 0||t.has(n.key))throw Error("TransitionGroup children must have unique keys");return t.add(n.key),n})}function ne(e){return typeof e==="object"&&e!==null&&"transitionGroup"in e&&N(e)}class K extends E{entries=new WeakMap;animations=new V;matches(e){return ne(e)}mountChildren(e,t,n){let o=D(t.children??[]),r=new Map;o.forEach((i)=>{let s=n.renderer.mount(i,n);e.appendChild(s);let a={key:i.key,vnode:i,node:s,status:"active"};r.set(a.key,a),this.playEnter(a,s,t.transitionGroup)}),this.entries.set(e,r)}updateChildren(e,t,n,o){let r=this.entries.get(e)??new Map,i=D(n.children??[]),s=new Set(i.map((u)=>u.key)),a=[];i.forEach((u)=>{let l=u.key,c=r.get(l);if(c){let F=c.status==="exiting";if(F&&c.node instanceof HTMLElement)this.animations.cancel(c.node);if(c.status="active",c.animationToken=void 0,c.node=o.renderer.patch(c.vnode,u,c.node,o),c.vnode=u,a.push(c),F)this.playEnter(c,c.node,n.transitionGroup);return}let y=o.renderer.mount(u,o),C={key:l,vnode:u,node:y,status:"active"};r.set(l,C),a.push(C),this.playEnter(C,y,n.transitionGroup)}),r.forEach((u,l)=>{if(s.has(l)||u.status!=="active")return;this.startExit(e,u,n.transitionGroup,o)}),this.placeActiveEntries(e,a),this.entries.set(e,r)}unmountChildren(e,t,n){let o=this.entries.get(e);if(!o){super.unmountChildren(e,t,n);return}o.forEach((r)=>{if(r.node instanceof HTMLElement)this.animations.cancel(r.node);if(n.renderer.unmount(r.vnode,r.node,n),r.node.parentNode===e)e.removeChild(r.node)}),o.clear(),this.entries.delete(e)}playEnter(e,t,n){if(!(t instanceof HTMLElement))return;let o=this.animations.playEnter(t,n);e.animationToken=o?.token}startExit(e,t,n,o){t.status="exiting";let r=t.node instanceof HTMLElement?this.animations.playExit(t.node,n):null;if(!r){this.finishExit(e,t,o);return}t.animationToken=r.token,r.finished.then((i)=>{if(i==="finished"&&t.status==="exiting"&&t.animationToken===r.token)this.finishExit(e,t,o)})}finishExit(e,t,n){let o=this.entries.get(e);if(o?.get(t.key)!==t)return;if(n.renderer.unmount(t.vnode,t.node,n),t.node.parentNode===e)e.removeChild(t.node);o.delete(t.key)}placeActiveEntries(e,t){let n=null;for(let o=t.length-1;o>=0;o-=1)e.insertBefore(t[o].node,n),n=t[o].node}}class w{strategies;constructor(){this.strategies=[new oe,new re,new ie,new K,new E]}mount(e,t){return this.findStrategy(e).mount(e,t)}patch(e,t,n,o){let r=this.findStrategy(e),i=this.findStrategy(t);if(r!==i){let s=i.mount(t,o);return n.parentNode?.replaceChild(s,n),r.unmount(e,n,o),s}return r.patch(e,t,n,o)}unmount(e,t,n){this.findStrategy(e).unmount(e,t,n)}findStrategy(e){let t=this.strategies.find((n)=>n.matches(e));if(!t)throw Error("No render strategy found for vnode");return t}}class oe{matches(e){return typeof e==="string"}mount(e,t){return t.templateEngine.parseTemplate(e)}patch(e,t,n,o){if(e===t)return n;let r=this.mount(t,o);return n.parentNode?.replaceChild(r,n),r}unmount(){}}class re{instances=new WeakMap;instanceNodes=new Map;emitterUnsubscribers=new WeakMap;matches(e){return typeof e==="object"&&e!==null&&z(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let o=new e.component(this.createProps(e));if(t.appContext&&o.setAppContext)o.setAppContext(t.appContext);this.syncEmitters(o,e.emitters??{}),t.registerChild(o);let r=o.mountToNode();return this.trackInstanceNode(o,r),o.setElementChangeListener?.((i,s)=>{this.trackInstanceNode(o,i),this.trackInstanceNode(o,s)}),r}patch(e,t,n,o){if(n.nodeType===Node.COMMENT_NODE){let s=this.mount(t,o);return n.parentNode?.replaceChild(s,n),s}if(t.directions?.if===!1){let s=document.createComment("if");return n.parentNode?.replaceChild(s,n),this.unmount(e,n,o),s}let r=this.instances.get(n);if(r&&e.component===t.component){this.syncEmitters(r,t.emitters??{}),r.setProps(this.createProps(t));let s=r.getElement()??n;return this.trackInstanceNode(r,s),s}let i=this.mount(t,o);return n.parentNode?.replaceChild(i,n),this.unmount(e,n,o),i}unmount(e,t,n){let o=this.instances.get(t);if(o)this.clearEmitters(o),o.unmount(),this.clearInstanceNodes(o),n.unregisterChild(o)}createProps(e){return{...e.props??{},children:e.children??[]}}syncEmitters(e,t){let n=this.emitterUnsubscribers.get(e)??new Map;n.forEach(({listener:o,unsubscribe:r},i)=>{let s=t[i];if(!s||s!==o)r(),n.delete(i)}),Object.entries(t).forEach(([o,r])=>{if(n.get(o)?.listener===r)return;n.set(o,{listener:r,unsubscribe:e.on(o,r)})}),this.emitterUnsubscribers.set(e,n)}clearEmitters(e){this.emitterUnsubscribers.get(e)?.forEach(({unsubscribe:t})=>{t()}),this.emitterUnsubscribers.delete(e)}trackInstanceNode(e,t){this.instances.set(t,e);let n=this.instanceNodes.get(e)??new Set;n.add(t),this.instanceNodes.set(e,n)}clearInstanceNodes(e){this.instanceNodes.get(e)?.forEach((t)=>{this.instances.delete(t)}),this.instanceNodes.delete(e)}}class ie{renderedChildren=new WeakMap;matches(e){return typeof e==="object"&&e!==null&&q(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=document.createElement("div");return n.setAttribute("data-slot",e.props.name),this.mountSlotChildren(n,this.resolveChildren(e,t),t),n}patch(e,t,n,o){if(n.nodeType===Node.COMMENT_NODE){let r=this.mount(t,o);return n.parentNode?.replaceChild(r,n),r}if(t.directions?.if===!1){let r=document.createComment("if");return n.parentNode?.replaceChild(r,n),this.unmount(e,n,o),r}if(n instanceof HTMLElement)n.setAttribute("data-slot",t.props.name),this.replaceSlotChildren(n,e,t,o);return n}unmount(e,t,n){if(!(t instanceof HTMLElement))return;this.unmountSlotChildren(t,n),this.renderedChildren.delete(t)}resolveChildren(e,t){return t.slots[e.props.name]??e.children??[]}replaceSlotChildren(e,t,n,o){this.unmountSlotChildren(e,o),e.textContent="",this.mountSlotChildren(e,this.resolveChildren(n,o),o)}mountSlotChildren(e,t,n){t.forEach((o)=>{e.appendChild(n.renderer.mount(o,n))}),this.renderedChildren.set(e,t)}unmountSlotChildren(e,t){(this.renderedChildren.get(e)??[]).forEach((o,r)=>{let i=e.childNodes[r];if(i)t.renderer.unmount(o,i,t)})}}class T{state;bindings=[];templateRegex=/{{(.*?)}}/g;constructor(e){this.state=e;if(!e||typeof e!=="object")throw Error("TemplateEngine requires a valid state object")}parseTemplate(e){if(typeof e!=="string")e=String(e);let t=document.createTextNode("");this.templateRegex.lastIndex=0;let n=Array.from(e.matchAll(this.templateRegex));if(n&&n.length>0)this.setupReactiveBindings(t,e,n);else t.textContent=e;return t}setupReactiveBindings(e,t,n){let o=new Set,r=this.evaluateTemplate(t,n,o);e.textContent=r;let i=g(()=>{try{let s=this.evaluateTemplate(t,n,o);if(e.textContent!==s)e.textContent=s}catch(s){console.error("Template update error:",s),e.textContent=`Error: ${s instanceof Error?s.message:"Unknown error"}`}});this.bindings.push({node:e,originalText:t,effect:i})}evaluateTemplate(e,t,n){let o=e;return t.forEach((r)=>{let i=r[1]?.trim();if(i){n.add(i);let s=this.getValueFromState(i),a=s===void 0||s===null?"":String(s);o=o.replace(r[0],a)}}),o}getValueFromState(e){if(!e)return;let t=e.split("."),n=this.state;for(let o of t){if(!n||typeof n!=="object")return;n=n[o]}return n}clearBindings(){this.bindings.forEach((e)=>{v(e.effect)}),this.bindings=[]}getBindingCount(){return this.bindings.length}hasExpressions(e){return this.templateRegex.lastIndex=0,this.templateRegex.test(e)}extractKeys(e){let t=[],n,o=new RegExp(this.templateRegex,"g");while((n=o.exec(e))!==null){let r=n[1]?.trim();if(r)t.push(r)}return t}evaluateTemplateValue(e){this.templateRegex.lastIndex=0;let t=Array.from(e.matchAll(this.templateRegex));if(!t||t.length===0)return e;let n=new Set;return this.evaluateTemplate(e,t,n)}}class M{props;vnode=null;el=null;renderer=new w;templateEngine;childComponents=new Set;eventListeners={};providers=new Map;updateEffect;appContext=null;parentComponent=null;elementChangeListener=null;styleManager;state;mounted=!1;constructor(e={}){this.props=e;this.styleManager=new se,this.state=j(this.initState()??{}),this.templateEngine=new T(this.state),this.initStyles(),this.updateEffect=g(()=>{if(this.trackStateProperties(),this.mounted)this.update()},{throwOnError:!0,scheduler:(t)=>{L.enqueue(t)}})}mount(e){if(!e||!(e instanceof HTMLElement))throw Error("Invalid container element");try{e.appendChild(this.mountToNode())}catch(t){throw console.error("组件渲染错误:",t),t}}mountToNode(){if(this.mounted&&this.el)return this.el;return this.beforeMount(),this.vnode=this.render(),this.el=this.renderer.mount(this.vnode,this.createRenderContext()),this.mounted=!0,this.onMounted(),this.el}update(){if(!this.el||!this.vnode)return;this.beforeUpdate();let e=this.render(),t=this.el;if(this.el=this.renderer.patch(this.vnode,e,this.el,this.createRenderContext()),t!==this.el)this.elementChangeListener?.(t,this.el);this.vnode=e,this.onUpdated()}unmount(){if(!this.mounted)return;if(this.beforeUnmount(),this.vnode&&this.el)this.renderer.unmount(this.vnode,this.el,this.createRenderContext());if(this.childComponents.clear(),Object.keys(this.eventListeners).forEach((e)=>{this.eventListeners[e].clear(),delete this.eventListeners[e]}),this.providers.clear(),this.parentComponent=null,this.elementChangeListener=null,this.templateEngine.clearBindings(),this.styleManager.destroy(),v(this.updateEffect),this.el?.parentNode)this.el.parentNode.removeChild(this.el);this.el=null,this.vnode=null,this.mounted=!1,this.onUnmounted()}setProps(e){if(this.props={...this.props,...e},this.mounted)this.update()}setState(e){Object.assign(this.state,e)}setAppContext(e){this.appContext=e,this.childComponents.forEach((t)=>{t.setAppContext?.(e)})}setParentComponent(e){this.parentComponent=e}setElementChangeListener(e){this.elementChangeListener=e}provide(e,t){this.providers.set(e,t)}inject(e,t){let n=this.resolveInjection(e);return n.found?n.value:t}resolveInjection(e){if(this.providers.has(e))return{found:!0,value:this.providers.get(e)};if(this.parentComponent?.resolveInjection)return this.parentComponent.resolveInjection(e);return this.resolveAppInjection(e)}getElement(){return this.el}beforeMount(){}onMounted(){}beforeUpdate(){}onUpdated(){}beforeUnmount(){}onUnmounted(){}getContext(){return this.appContext}get router(){return this.getRouterFrom(this.appContext)??this.getRouterFromGlobalApp()}emit(e,...t){this.eventListeners[e]?.forEach((n)=>{n(...t)})}on(e,t){if(!this.eventListeners[e])this.eventListeners[e]=new Set;return this.eventListeners[e].add(t),()=>this.off(e,t)}off(e,t){this.eventListeners[e]?.delete(t)}createRenderContext(){return{appContext:this.appContext,templateEngine:this.templateEngine,renderer:this.renderer,slots:this.collectSlots(),registerChild:(e)=>{this.childComponents.add(e),e.setParentComponent?.(this),e.setAppContext?.(this.appContext)},unregisterChild:(e)=>{this.childComponents.delete(e),e.setParentComponent?.(null)}}}collectSlots(){let e={default:[]};return(this.props.children??[]).forEach((n)=>{let o=this.getSlotName(n);if(!e[o])e[o]=[];e[o].push(this.normalizeSlotChild(n))}),e}getSlotName(e){if(typeof e==="string")return"default";return"slot"in e&&typeof e.slot==="string"?e.slot:"default"}normalizeSlotChild(e){if(typeof e==="string"||!("slot"in e))return e;let t={...e};return delete t.slot,t}trackStateProperties(){this.trackReactiveValue(this.state,new Set)}getRouterFrom(e){if(!e||typeof e!=="object"||!("router"in e))return;return e.router}getRouterFromGlobalApp(){let e=globalThis.__APP__;return this.getRouterFrom(e)}resolveAppInjection(e){if(!this.appContext||typeof this.appContext!=="object")return{found:!1,value:void 0};return this.appContext.app?.resolveInjection?.(e)??{found:!1,value:void 0}}trackReactiveValue(e,t){if(!e||typeof e!=="object"||t.has(e))return;if(t.add(e),Array.isArray(e))e.length;Object.keys(e).forEach((n)=>{let o=e[n];this.trackReactiveValue(o,t)})}}var G=null;function ae(e){if(!e||!(e instanceof P))throw Error("Invalid router instance");G=e}function we(){if(!G)throw Error("Router is not initialized. Please make sure you have installed the router plugin.");return G}function b(e){if(!e.startsWith("/"))return`/${e}`;return e||"/"}function ue(e,t){let n=b(t.split("?")[0]);for(let r of e){let i=Me(r.path,n);if(i)return{route:r,params:i}}let o=e.find((r)=>r.path==="/");return o?{route:o,params:{}}:null}function Me(e,t){let n=pe(e),o=pe(t);if(n.length!==o.length)return null;let r={};for(let i=0;i<n.length;i+=1){let s=n[i],a=o[i];if(s.startsWith(":")){let u=s.slice(1);if(!u)return null;r[decodeURIComponent(u)]=decodeURIComponent(a);continue}if(s!==a)return null}return r}function pe(e){let t=b(e);if(t==="/")return[];return t.split("/").filter(Boolean)}function ce(e,t,n){let o=b(e),r=n==="/"?o:n+o;return t==="hash"?`#${r}`:r}function le(e,t){let n,o,r;if(e==="history")o=window.location.pathname+window.location.search,n=window.location.pathname,r=window.location.search;else{o=window.location.hash||"#/",n=o.startsWith("#")?o.slice(1):o;let s=n.indexOf("?");r=s>=0?n.slice(s+1):"",n=s>=0?n.slice(0,s):n}if(n.startsWith(t)&&t!=="/"&&n!=="/")n=n.slice(t.length);return n=b(n),{path:n,fullPath:o,query:Le(r),params:{}}}function de(e,t,n,o){let r=b(e),i=o==="/"?r:o+r;if(n==="history"){if(t)window.history.replaceState({},"",i);else window.history.pushState({},"",i);return}if(t){let s=window.location.href.split("#")[0];window.location.replace(`${s}#${i}`);return}window.location.hash=i}function Le(e){let t={},n=e.startsWith("?")?e.slice(1):e;if(!n)return t;return n.split("&").forEach((o)=>{let[r,i]=o.split("=");if(r)t[decodeURIComponent(r)]=i?decodeURIComponent(i):""}),t}class P{currentRoute=null;currentLocation=null;routes=[];app=null;mode;base;routeChangeListeners=[];removeWindowListener;constructor(e){let t=Array.isArray(e)?{routes:e}:e;this.routes=t.routes||[],this.mode=t.mode||"history",this.base=t.base||"/",this.validateRoutes(),this.initEvents(),this.resolveCurrentRoute()}install(e){this.app=e,e.router=this,ae(this);let t=e.getContext();t.router=this,this.resolveCurrentRoute()}push(e){this.navigate(e,!1)}replace(e){this.navigate(e,!0)}forward(){window.history.forward()}back(){window.history.back()}go(e){window.history.go(e)}getCurrentRoute(){if(!this.currentLocation)this.resolveCurrentRoute();return this.currentLocation}getCurrentRouteRecord(){if(!this.currentRoute)this.resolveCurrentRoute();return this.currentRoute}onRouteChange(e){return this.routeChangeListeners.push(e),()=>{let t=this.routeChangeListeners.indexOf(e);if(t>-1)this.routeChangeListeners.splice(t,1)}}getRoutes(){return[...this.routes]}addRoute(e){if(this.routes.some((n)=>n.path===e.path))throw Error(`Route already exists: ${e.path}`);if(this.routes.push(e),this.getCurrentLocation().path===e.path)this.handleRouteChange()}createHref(e){return ce(e,this.mode,this.base)}destroy(){if(this.removeWindowListener?.(),this.removeWindowListener=void 0,this.app?.router===this)this.app.router=void 0;this.app=null}navigate(e,t){if(!e||typeof e!=="string")throw Error("Path must be a non-empty string");de(e,t,this.mode,this.base),this.handleRouteChange()}validateRoutes(){if(!Array.isArray(this.routes))throw Error("Router routes must be an array");let e=new Set;this.routes.forEach((t)=>{if(e.has(t.path))throw Error(`Duplicate route path: ${t.path}`);e.add(t.path)})}initEvents(){if(typeof window>"u")return;let e=this.mode==="history"?"popstate":"hashchange",t=()=>{this.handleRouteChange()};window.addEventListener(e,t),this.removeWindowListener=()=>{window.removeEventListener(e,t)}}handleRouteChange(){let e=this.currentLocation,t=this.resolveCurrentRoute();if(!this.isSameLocation(e,t))this.triggerRouteChangeListeners(t,e)}resolveCurrentRoute(){let e=this.getCurrentLocation(),t=ue(this.routes,e.path),n=t?.route??null;return this.currentRoute=n,this.currentLocation={...e,params:t?.params??{},name:n?.name,meta:n?.meta},this.currentLocation}getCurrentLocation(){return le(this.mode,this.base)}isSameLocation(e,t){return e?.fullPath===t?.fullPath&&e?.name===t?.name}triggerRouteChangeListeners(e,t){this.routeChangeListeners.forEach((n)=>{try{n(e,t)}catch(o){console.error("Route change listener error:",o)}})}}class Ne extends M{unsubscribe;initState(){return{currentPath:this.router?.getCurrentRoute()?.path??window.location.pathname}}initStyles(){}onMounted(){let e=this.router;this.unsubscribe=e?.onRouteChange((t)=>{this.state.currentPath=t.path})}onUnmounted(){this.unsubscribe?.()}render(){let e=this.router,t=this.props.activeClass??"active",n=this.state.currentPath===this.props.to,o=[this.props.className,n?t:void 0].filter(Boolean).join(" ");return{tag:"a",props:{href:e?.createHref(this.props.to)??this.props.to,className:o},listeners:{click:(r)=>{if(r.preventDefault(),this.props.replace)e?.replace(this.props.to);else e?.push(this.props.to)}},children:this.props.children&&this.props.children.length>0?this.props.children:[this.props.to]}}}class Ae extends M{unsubscribe;initState(){let e=this.router;return{route:e?.getCurrentRoute()??null,record:e?.getCurrentRouteRecord()??null}}initStyles(){}onMounted(){let e=this.router;this.unsubscribe=e?.onRouteChange((t)=>{this.state.route=t,this.state.record=e.getCurrentRouteRecord()})}onUnmounted(){this.unsubscribe?.()}render(){let e=this.state.record??this.router?.getCurrentRouteRecord();return{tag:"div",props:{"data-router-view":""},children:e?[{component:e.component}]:[]}}}function $n(e){return new P(e)}var Pe=new Set(["base","link","meta"]);function fe(e){let t=e.lang??"en",n=e.charset??"utf-8",o=e.viewport??"width=device-width, initial-scale=1",r=k({lang:t,...e.htmlAttributes??{}}),i=k(e.bodyAttributes),s=ke(e.body);return["<!doctype html>",`<html${r}>`,"<head>",` <meta charset="${x(n)}">`,` <meta name="viewport" content="${x(o)}">`,` <title>${x(e.title)}</title>`,e.description?` <meta name="description" content="${x(e.description)}">`:"",...(e.head??[]).map((a)=>` ${He(a)}`),e.styles&&e.styles.length>0?` <style>${U(e.styles)}</style>`:"","</head>",`<body${i}>`,s,...(e.scripts??[]).map((a)=>` ${Ie(a)}`),"</body>","</html>"].filter((a)=>a!=="").join(`
|
|
2
|
+
`)}function ke(e){if(typeof document>"u")throw Error("renderHtmlDocument requires a DOM-like document");let t=document.createElement("div"),n=new w,o=new Set,r=Array.isArray(e)?e:[e],i={templateEngine:new T({}),renderer:n,slots:{default:[]},registerChild:(a)=>{o.add(a)},unregisterChild:(a)=>{o.delete(a)}};r.forEach((a)=>{t.appendChild(n.mount(a,i))});let s=t.innerHTML;return o.forEach((a)=>{a.unmount()}),s}function He(e){let t=k(e.attributes);if(Pe.has(e.tag)&&!e.text)return`<${e.tag}${t}>`;return`<${e.tag}${t}>${x(e.text??"")}</${e.tag}>`}function Ie(e){return`<script${k({type:e.type,src:e.src,async:e.async,defer:e.defer,...e.attributes??{}})}></script>`}function k(e={}){let t=Object.entries(e).flatMap(([n,o])=>{if(o===!1||o===null||o===void 0)return[];return o===!0?[n]:[`${n}="${x(String(o))}"`]}).join(" ");return t?` ${t}`:""}function x(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}var he="#app";class je{options;container=null;rootInstance=null;mounted=!1;templateEngine=null;appContext;providers=new Map;plugins=[];unmountedCallback;router;constructor(e={}){this.options=e;this.appContext={app:this,version:"0.3.0",config:e.config||{}}}handleError(e){console.error("应用错误:",e),this.renderErrorUI(e)}renderErrorUI(e){if(!this.container)return;this.container.innerHTML=`
|
|
3
|
+
<div style="padding: 20px; background-color: #ffebee; color: #c62828; font-family: Arial, sans-serif;">
|
|
4
|
+
<h3>应用错误</h3>
|
|
5
|
+
<p>${e.message}</p>
|
|
6
|
+
<pre style="background-color: #fff; padding: 10px; border-radius: 4px; overflow: auto;">${e.stack}</pre>
|
|
7
|
+
</div>
|
|
8
|
+
`}use(e,...t){if(typeof e.install!=="function")throw Error("插件必须提供 install 方法");return e.install(this,...t),this.plugins.push({plugin:e,args:t}),this}mount(){if(this.mounted){console.warn("应用已经处于运行状态");return}let e=this.resolveMountContainer();if(!e)return;try{if(this.container=e,globalThis.__APP__=this,this.options.root){if(this.rootInstance=new this.options.root(this.options.rootProps),"setAppContext"in this.rootInstance)this.rootInstance.setAppContext(this.appContext);if(this.options.state&&"setState"in this.rootInstance)this.rootInstance.setState(this.options.state);this.rootInstance.mount(this.container),this.templateEngine=new T(this.options.state||{})}this.mounted=!0,this.onMounted()}catch(t){this.handleError(t)}}unmount(){if(!this.mounted){console.warn("应用未处于运行状态");return}try{if(this.onBeforeUnmount(),this.rootInstance){if("unmount"in this.rootInstance)this.rootInstance.unmount();this.rootInstance=null,this.mounted=!1,delete globalThis.__APP__}if(this.templateEngine)this.templateEngine.clearBindings(),this.templateEngine=null;if(this.container)this.container.innerHTML="";if(this.unmountedCallback)this.unmountedCallback()}catch(e){console.error("Failed to unmount app:",e)}}isRunning(){return this.mounted}updateRootComponent(e){if(this.mounted)this.unmount();this.options.root=e,this.mount()}update(e){if(!this.mounted)return console.warn("Cannot update unmounted app"),this;try{if(e&&this.options.state){if(this.options.state={...this.options.state,...e},this.rootInstance&&"setState"in this.rootInstance)this.rootInstance.setState(e);if(this.templateEngine)this.templateEngine.state=this.options.state}this.onUpdated()}catch(t){console.error("Failed to update app:",t)}return this}getContext(){return this.appContext}provide(e,t){return this.providers.set(e,t),this}inject(e,t){let n=this.resolveInjection(e);return n.found?n.value:t}resolveInjection(e){if(!this.providers.has(e))return{found:!1,value:void 0};return{found:!0,value:this.providers.get(e)}}getState(){return this.options.state}setState(e){if(this.options.state=e,this.mounted)this.update();return this}onUnmounted(e){return this.unmountedCallback=e,this}renderHtmlDocument(e={}){let t=this.options.document??{},n=this.mergeDocumentScripts(t.scripts,e.scripts);return fe({...t,...e,title:e.title??t.title??"TSone App",body:e.body??t.body??this.createMountDocumentBody(),scripts:n})}resolveRootElement(e){if(!e)return null;if(typeof e==="string"){if(typeof document>"u")return null;return document.querySelector(e)}return typeof Element<"u"&&e instanceof Element?e:null}resolveMountContainer(){if(typeof document>"u")return null;let e=this.resolveRootElement(this.options.rootElement??he);return e instanceof HTMLElement?e:null}createMountDocumentBody(){let e=this.options.rootElement??he;if(typeof e==="string")return this.createMountElementFromSelector(e);if(typeof Element<"u"&&e instanceof Element){let t={};if(e.id)t.id=e.id;if(e.className)t.className=e.className;return{tag:e.tagName.toLowerCase(),props:t}}return S({props:{id:"app"}})}createMountElementFromSelector(e){if(e.startsWith("#")&&e.length>1)return S({props:{id:e.slice(1)}});if(e.startsWith(".")&&e.length>1)return S({props:{className:e.slice(1)}});return S({props:{"data-tsone-root":e}})}mergeDocumentScripts(e,t){if(!e&&!t)return;return[...e??[],...t??[]]}onMounted(){this.plugins.forEach(({plugin:e})=>{if(e&&typeof e.onMounted==="function")e.onMounted(this)})}onUpdated(){this.plugins.forEach(({plugin:e})=>{if(e&&typeof e.onUpdated==="function")e.onUpdated(this)})}onBeforeUnmount(){this.plugins.forEach(({plugin:e})=>{if(e&&typeof e.onBeforeUnmount==="function")e.onBeforeUnmount(this)})}}
|
|
9
|
+
export{L as a,Ue as b,Fe as c,m as d,j as e,We as f,g,ze as h,qe as i,ge as j,Ye as k,v as l,ve as m,Xe as n,z as o,N as p,q,Ze as r,ye as s,S as t,Je as u,et as v,tt as w,nt as x,ot as y,rt as z,it as A,st as B,at as C,pt as D,ut as E,ct as F,lt as G,dt as H,ft as I,ht as J,mt as K,gt as L,vt as M,yt as N,Rt as O,Tt as P,Ct as Q,Et as R,bt as S,xt as T,St as U,wt as V,Mt as W,Lt as X,Nt as Y,At as Z,Pt as _,kt as $,Ht as aa,It as ba,jt as ca,Ot as da,Bt as ea,_t as fa,Vt as ga,Dt as ha,Re as ia,Y as ja,Te as ka,_ as la,E as ma,on as na,D as oa,w as pa,oe as qa,re as ra,ie as sa,T as ta,M as ua,fe as va,je as wa,we as xa,P as ya,Ne as za,Ae as Aa,$n as Ba};
|
|
10
|
+
|
|
11
|
+
//# debugId=4C5AC6EC8FCFBAC664756E2164756E21
|
|
12
|
+
//# sourceMappingURL=index-p55hs6x8.js.map
|