transone 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/core/vnode.d.ts +18 -6
- package/dist/index-d5wsetxf.js +27 -0
- package/dist/index-d5wsetxf.js.map +12 -0
- package/dist/index-sf0hkgh3.js +12 -0
- package/dist/index-sf0hkgh3.js.map +25 -0
- package/dist/index-xp7y2crt.js +5 -0
- package/dist/index-xp7y2crt.js.map +18 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/request/adapters/fetch.d.ts +12 -0
- package/dist/request/adapters/index.d.ts +15 -0
- package/dist/request/adapters/mp.d.ts +34 -0
- package/dist/request/adapters/platform.d.ts +18 -0
- package/dist/request/errors.d.ts +33 -0
- package/dist/request/helpers.d.ts +30 -0
- package/dist/request/index.d.ts +19 -0
- package/dist/request/index.js +4 -0
- package/dist/request/index.js.map +9 -0
- package/dist/request/interceptors.d.ts +13 -0
- package/dist/request/request.d.ts +43 -0
- package/dist/request/types.d.ts +104 -0
- package/dist/router/index.js +2 -2
- package/dist/router/index.js.map +1 -1
- package/dist/style/index.js +2 -2
- package/dist/style/index.js.map +1 -1
- package/dist/style/units.d.ts +9 -0
- package/package.json +6 -1
- package/dist/index-3t506ckz.js +0 -12
- package/dist/index-3t506ckz.js.map +0 -25
- package/dist/index-mbmajrpr.js +0 -26
- package/dist/index-mbmajrpr.js.map +0 -11
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# transone
|
|
2
2
|
|
|
3
3
|
TransOne 核心框架包:一份 TypeScript 源码,跨端框架的核心运行时模型。
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ TransOne 核心框架包:一份 TypeScript 源码,跨端框架的核心运
|
|
|
9
9
|
- 样式管理:`StyleManager`
|
|
10
10
|
|
|
11
11
|
与 TSone 同源:核心公开 API 复用 TSone,Web 产物可直接复用 TSone 渲染策略。
|
|
12
|
-
编译器见 [
|
|
12
|
+
编译器见 [transone-cli](../transone-cli)。
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
bun test # 测试
|
package/dist/core/vnode.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface ComponentType {
|
|
|
8
8
|
type VNodeComponentProps = ComponentProps;
|
|
9
9
|
export type VNodeComponentConstructor<P extends VNodeComponentProps = VNodeComponentProps> = ComponentConstructor<P> | AnyComponentConstructor;
|
|
10
10
|
export type HTMLPropValue = string | number | boolean | null | undefined | Record<string, string | number> | EventListener;
|
|
11
|
+
export type Children = VNode | string | Array<VNode | string>;
|
|
12
|
+
/** 归一化 children 为数组(运行时渲染使用;h() 允许直接传单个节点或数组)。 */
|
|
13
|
+
export declare function toChildren(children?: Children): Array<VNode | string>;
|
|
11
14
|
export interface HTMLProps {
|
|
12
15
|
[key: string]: HTMLPropValue;
|
|
13
16
|
class?: string;
|
|
@@ -30,13 +33,13 @@ export interface VNodeBase {
|
|
|
30
33
|
export interface HTMLNode extends VNodeBase {
|
|
31
34
|
tag: string;
|
|
32
35
|
props?: HTMLProps;
|
|
33
|
-
children?:
|
|
36
|
+
children?: Children;
|
|
34
37
|
listeners?: EventListeners;
|
|
35
38
|
}
|
|
36
39
|
export interface ComponentNode<P extends VNodeComponentProps = VNodeComponentProps> extends VNodeBase {
|
|
37
40
|
component: VNodeComponentConstructor<P>;
|
|
38
41
|
props?: P;
|
|
39
|
-
children?:
|
|
42
|
+
children?: Children;
|
|
40
43
|
emitters?: Record<string, ComponentEventListener>;
|
|
41
44
|
}
|
|
42
45
|
export interface SlotProvider extends VNodeBase {
|
|
@@ -50,13 +53,13 @@ export interface SlotInjector extends VNodeBase {
|
|
|
50
53
|
tag: string;
|
|
51
54
|
slot: string;
|
|
52
55
|
}
|
|
53
|
-
export type VNode = HTMLNode | ComponentNode | SlotProvider | SlotInjector;
|
|
56
|
+
export type VNode = HTMLNode | ComponentNode<any> | SlotProvider | SlotInjector;
|
|
54
57
|
export type ElementShortcutOptions = Omit<HTMLNode, 'tag'>;
|
|
55
58
|
export type ElementShortcut = (options?: ElementShortcutOptions) => HTMLNode;
|
|
56
59
|
export declare function isComponentNode(vnode: VNode): vnode is ComponentNode;
|
|
57
60
|
export declare function isHTMLNode(vnode: VNode): vnode is HTMLNode;
|
|
58
61
|
export declare function isSlotProvider(vnode: VNode): vnode is SlotProvider;
|
|
59
|
-
export declare function h(tag: string, props?: HTMLProps, children?:
|
|
62
|
+
export declare function h(tag: string, props?: HTMLProps, children?: Children, listeners?: EventListeners, key?: string | number, directions?: Directions): HTMLNode;
|
|
60
63
|
export declare function Tag(tag: string, options?: ElementShortcutOptions): HTMLNode;
|
|
61
64
|
export declare const Div: ElementShortcut;
|
|
62
65
|
export declare const Span: ElementShortcut;
|
|
@@ -98,7 +101,16 @@ export declare const Tbody: ElementShortcut;
|
|
|
98
101
|
export declare const Tr: ElementShortcut;
|
|
99
102
|
export declare const Th: ElementShortcut;
|
|
100
103
|
export declare const Td: ElementShortcut;
|
|
101
|
-
export
|
|
104
|
+
export interface ComponentDescriptor<P extends VNodeComponentProps> {
|
|
105
|
+
component: ComponentConstructor<P>;
|
|
106
|
+
props?: P;
|
|
107
|
+
children?: Children;
|
|
108
|
+
key?: string | number;
|
|
109
|
+
directions?: Directions;
|
|
110
|
+
emitters?: Record<string, ComponentEventListener>;
|
|
111
|
+
}
|
|
112
|
+
export declare function createComponent<P extends VNodeComponentProps>(options: ComponentDescriptor<P>): ComponentNode<P>;
|
|
113
|
+
export declare function createComponent<P extends VNodeComponentProps>(componentClass: ComponentConstructor<P>, props?: P, children?: Children, key?: string | number, directions?: Directions): ComponentNode<P>;
|
|
102
114
|
export declare function slot(name: string, key?: string | number, directions?: Directions): SlotProvider;
|
|
103
|
-
export declare function each<T>(items: readonly T[], render: (item: T, index: number) => VNode | string, key
|
|
115
|
+
export declare function each<T>(items: readonly T[], render: (item: T, index: number) => VNode | string, key?: (item: T, index: number) => string | number): VNode[];
|
|
104
116
|
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var l=":root{--cyy-rpx:calc(min(100vw, 750px) / 750);}",c=/(-?\d+(?:\.\d+)?)rpx/g;function i(e){return String(e).replace(c,(t,r)=>`calc(${r} * var(--cyy-rpx))`)}class p{styleElement=null;styles=new Map;constructor(){}addStyle(e,t){this.styles.set(e,t),this.updateStyles()}removeStyle(e){this.styles.delete(e),this.updateStyles()}clearStyles(){if(this.styles.clear(),this.styleElement)this.styleElement.textContent=""}destroy(){if(this.clearStyles(),this.styleElement)this.styleElement.remove(),this.styleElement=null}ensureStyleElement(){if(!this.styleElement){let e=document.createElement("style");document.head.appendChild(e),this.styleElement=e}return this.styleElement}convertToCSS(e){return Object.entries(e).map(([t,r])=>`${t.replace(/([A-Z])/g,"-$1").toLowerCase()}: ${i(r)};`).join(`
|
|
2
|
+
`)}updateStyles(){if(this.styles.size===0){if(this.styleElement)this.styleElement.textContent="";return}let e=this.ensureStyleElement(),t=l+`
|
|
3
|
+
`;this.styles.forEach((r)=>{if(t+=`${r.selector} {
|
|
4
|
+
${this.convertToCSS(r.properties)}
|
|
5
|
+
}
|
|
6
|
+
`,r.hover)t+=`${r.selector}:hover {
|
|
7
|
+
${this.convertToCSS(r.hover)}
|
|
8
|
+
}
|
|
9
|
+
`;if(r.media)Object.entries(r.media).forEach(([n,s])=>{t+=`@media ${n} {
|
|
10
|
+
${r.selector} {
|
|
11
|
+
${this.convertToCSS(s)}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`})}),e.textContent=t}}function m(e){return e.map((t)=>o(t)).join(`
|
|
15
|
+
|
|
16
|
+
`)}function o(e,t=""){if("atRule"in e){let n=e.rules.map((s)=>o(s,`${t} `)).join(`
|
|
17
|
+
|
|
18
|
+
`);return`${t}${e.atRule} {
|
|
19
|
+
${n}
|
|
20
|
+
${t}}`}let r=Object.entries(e.properties).map(([n,s])=>`${t} ${u(n)}: ${String(s)};`).join(`
|
|
21
|
+
`);return`${t}${e.selector} {
|
|
22
|
+
${r}
|
|
23
|
+
${t}}`}function u(e){if(e.startsWith("--")||e.includes("-"))return e;return e.replace(/[A-Z]/g,(t)=>`-${t.toLowerCase()}`)}
|
|
24
|
+
export{i as Ca,p as Da,m as Ea};
|
|
25
|
+
|
|
26
|
+
//# debugId=C326383C7F39C8EB64756E2164756E21
|
|
27
|
+
//# sourceMappingURL=index-d5wsetxf.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/style/units.ts", "../lib/style/StyleManager.ts", "../lib/style/sheet.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** 跨端尺寸单位换算:rpx(微信 750 设计宽)在 H5 端转换为视口相对值。\n *\n * 1rpx = 视口宽度 / 750,且视口宽度上限 750px(桌面端不再放大,页面按\n * 750px 基准居中显示,与小程序设计宽一致)。\n */\n\n/** 根 CSS 变量:--cyy-rpx 为 1rpx 的等效长度 */\nexport const ROOT_RPX_RULE =\n ':root{--cyy-rpx:calc(min(100vw, 750px) / 750);}';\n\nconst RPX_PATTERN = /(-?\\d+(?:\\.\\d+)?)rpx/g;\n\n/** 把字符串/数值中的 `N rpx` 替换为 `calc(N * var(--cyy-rpx))` */\nexport function convertRpx(value: string | number): string {\n return String(value).replace(\n RPX_PATTERN,\n (_match, number: string) => `calc(${number} * var(--cyy-rpx))`\n );\n}\n",
|
|
6
|
+
"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\nimport { convertRpx, ROOT_RPX_RULE } from './units';\n\nexport class StyleManager {\n public styleElement: HTMLStyleElement | null = null;\n public styles: Map<string, StyleOptions> = new Map();\n\n constructor() {\n // style 元素延迟到首次 addStyle 时创建,避免无样式组件产生空 <style> 节点\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 if (this.styleElement) {\n this.styleElement.textContent = '';\n }\n }\n\n public destroy(): void {\n this.clearStyles();\n if (this.styleElement) {\n this.styleElement.remove();\n this.styleElement = null;\n }\n }\n\n private ensureStyleElement(): HTMLStyleElement {\n if (!this.styleElement) {\n const element = document.createElement('style');\n document.head.appendChild(element);\n this.styleElement = element;\n }\n return this.styleElement;\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}: ${convertRpx(value)};`;\n })\n .join('\\n');\n }\n\n private updateStyles(): void {\n if (this.styles.size === 0) {\n if (this.styleElement) {\n this.styleElement.textContent = '';\n }\n return;\n }\n\n const element = this.ensureStyleElement();\n let cssText = ROOT_RPX_RULE + '\\n';\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 element.textContent = cssText;\n }\n}\n",
|
|
7
|
+
"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"
|
|
8
|
+
],
|
|
9
|
+
"mappings": "AAOO,IAAM,EACX,kDAEI,EAAc,wBAGb,SAAS,CAAU,CAAC,EAAgC,CACzD,OAAO,OAAO,CAAK,EAAE,QACnB,EACA,CAAC,EAAQ,IAAmB,QAAQ,qBACtC,ECRK,MAAM,CAAa,CACjB,aAAwC,KACxC,OAAoC,IAAI,IAE/C,WAAW,EAAG,EAIP,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,CAEzB,GADA,KAAK,OAAO,MAAM,EACd,KAAK,aACP,KAAK,aAAa,YAAc,GAI7B,OAAO,EAAS,CAErB,GADA,KAAK,YAAY,EACb,KAAK,aACP,KAAK,aAAa,OAAO,EACzB,KAAK,aAAe,KAIhB,kBAAkB,EAAqB,CAC7C,GAAI,CAAC,KAAK,aAAc,CACtB,IAAM,EAAU,SAAS,cAAc,OAAO,EAC9C,SAAS,KAAK,YAAY,CAAO,EACjC,KAAK,aAAe,EAEtB,OAAO,KAAK,aAGN,YAAY,CAAC,EAAqD,CACxE,OAAO,OAAO,QAAQ,CAAU,EAC7B,IAAI,EAAE,EAAK,KAEH,GADQ,EAAI,QAAQ,WAAY,KAAK,EAAE,YAAY,MACrC,EAAW,CAAK,IACtC,EACA,KAAK;AAAA,CAAI,EAGN,YAAY,EAAS,CAC3B,GAAI,KAAK,OAAO,OAAS,EAAG,CAC1B,GAAI,KAAK,aACP,KAAK,aAAa,YAAc,GAElC,OAGF,IAAM,EAAU,KAAK,mBAAmB,EACpC,EAAU,EAAgB;AAAA,EAE9B,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,EAAQ,YAAc,EAE1B,CCxEO,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",
|
|
10
|
+
"debugId": "C326383C7F39C8EB64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{Ca as ee,Da as le,Ea as W}from"./index-d5wsetxf.js";var R=Symbol("is_reactive"),d=Symbol("is_readonly"),j=Symbol("is_ref"),G=["push","pop","shift","unshift","splice","sort","reverse"];function h(e,t){return Boolean(Reflect.get(e,t))}function f(e){return e!==null&&typeof e==="object"}class O{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 ve=0,E=new O;function Fe(){return E.nextTick()}function Ge(){E.flush()}class m{static instance;activeEffect=null;effectStack=[];targetMap=new WeakMap;reactiveMap=new WeakMap;readonlyMap=new WeakMap;proxyMap=new WeakMap;constructor(){}static getInstance(){if(!m.instance)m.instance=new m;return m.instance}reactive(e){if(!f(e))return console.warn("reactive: target must be an object"),e;if(ye(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,r)=>{if(r===R)return!0;if(r===d)return!1;this.track(n,r);let o=Reflect.get(n,r);if(f(o)&&!h(o,d))return this.reactive(o);return o},set:(n,r,o)=>{if(h(n,d))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(f(o)&&!h(o,R)&&!h(o,d))o=this.reactive(o);let s=Reflect.set(n,r,o);if(i!==o)this.trigger(n,r);return s},deleteProperty:(n,r)=>{if(h(n,d))return console.warn(`Cannot delete property ${String(r)} on readonly object`),!1;let o=r in n,i=Reflect.deleteProperty(n,r);if(o)this.trigger(n,r);return i}});return this.reactiveMap.set(e,t),this.proxyMap.set(t,e),t}toRawValue(e){if(f(e)&&this.proxyMap.has(e))return this.proxyMap.get(e);return e}createReactiveArray(e){if(this.reactiveMap.has(e))return this.reactiveMap.get(e);let t=new Proxy(e,{get:(n,r)=>{if(r===R)return!0;if(r===d)return!1;this.track(n,r);let o=Reflect.get(n,r);if(typeof r==="string"&&(r==="includes"||r==="indexOf"||r==="lastIndexOf")){this.track(n,"length");for(let s=0;s<n.length;s++)this.track(n,String(s));let i=o;return(...s)=>{let a=i.apply(n,s);if(a===!1||a===-1){let c=n.map((l)=>this.toRawValue(l));return c[r].apply(c,s.map((l)=>this.toRawValue(l)))}return a}}if(typeof r==="string"&&G.includes(r))return(...i)=>{let a=o.apply(n,i);return this.trigger(n,"length"),this.trigger(n,r),a};if(f(o)&&!h(o,d))return this.reactive(o);return o},set:(n,r,o)=>{if(h(n,d))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(f(o)&&!h(o,R)&&!h(o,d))o=this.reactive(o);let s=Reflect.set(n,r,o);if(i!==o){if(this.trigger(n,r),typeof r==="string"&&!isNaN(Number(r)))this.trigger(n,"length")}return s},deleteProperty:(n,r)=>{if(h(n,d))return console.warn(`Cannot delete property ${String(r)} on readonly object`),!1;let o=r in n,i=Reflect.deleteProperty(n,r);if(o)this.trigger(n,r),this.trigger(n,"length");return i}});return this.reactiveMap.set(e,t),this.proxyMap.set(t,e),t}readonly(e){if(!f(e))return console.warn("readonly: target must be an object"),e;if(h(e,d))return e;if(this.readonlyMap.has(e))return this.readonlyMap.get(e);let t=new Proxy(e,{get:(n,r)=>{if(r===R)return!1;if(r===d)return!0;let o=Reflect.get(n,r);if(f(o))return this.readonly(o);return o},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:r,throwOnError:o=!1}=t||{},i=()=>{if(!i.active)return e();try{return this.cleanup(i),this.effectStack.push(i),this.activeEffect=i,e()}catch(s){if(o)throw s;console.error("Effect error:",s);return}finally{this.effectStack.pop(),this.activeEffect=this.effectStack[this.effectStack.length-1]??null}};if(i.id=ve++,i.deps=[],i.active=!0,i.scheduler=r,!n)i();return i}runWithEffect(e,t){this.effectStack.push(e),this.activeEffect=e;try{return t()}finally{this.effectStack.pop(),this.activeEffect=this.effectStack[this.effectStack.length-1]??null}}computed(e){let t=!0,n,r={},o=()=>{this.track(r,"value")},i=this.effect(()=>{n=e(),t=!1},{lazy:!0,scheduler:()=>{if(!t)t=!0,this.trigger(r,"value")}});return{get value(){if(t)i();return o(),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 r=n.get(t);if(!r)r=new Set,n.set(t,r);if(!r.has(this.activeEffect))r.add(this.activeEffect),this.activeEffect.deps.push(r)}trigger(e,t){let n=this.targetMap.get(e);if(!n)return;let r=n.get(t);if(!r)return;new Set(r).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 B(e){return m.getInstance().reactive(e)}function qe(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 Ye(e){let t={value:e};return Object.defineProperty(t,j,{configurable:!1,enumerable:!1,value:!0}),B(t)}function q(e){return f(e)&&Boolean(Reflect.get(e,j))}function Qe(e){return q(e)?e.value:e}function y(e){m.getInstance().stop(e)}function V(e,t){if(!f(e)||t.has(e))return;if(t.add(e),Array.isArray(e)){e.forEach((n)=>V(n,t));return}Object.keys(e).forEach((n)=>{V(e[n],t)})}function Ze(e,t,n={}){let r=m.getInstance(),o=q(e)?()=>e.value:e,i,s=null,a=()=>{if(!u.active)return;s?.(),s=null;let l=c();t(l,i,(b)=>{s=b}),i=l},c=g(()=>{let l=o();if(n.deep&&f(l))V(l,new Set);return l},{lazy:!0,scheduler:()=>{if(n.sync)a();else E.enqueue(u)}}),u=g(()=>{a()},{lazy:!0});if(n.immediate)a();else i=c();return()=>{r.stop(c),r.stop(u)}}function ye(e){return f(e)&&h(e,R)}function Je(e){return f(e)&&h(e,d)}function v(e){if(e===void 0||e===null)return[];return Array.isArray(e)?e:[e]}function z(e){return typeof e==="object"&&e!==null&&"component"in e}function Y(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 et(e,t,n,r,o,i){return{tag:e,props:t,children:n,listeners:r,key:o,directions:i}}function Re(e,t={}){return{tag:e,...t}}function p(e){return(t={})=>Re(e,t)}var w=p("div"),tt=p("span"),nt=p("p"),rt=p("button"),ot=p("input"),it=p("section"),st=p("main"),at=p("header"),pt=p("footer"),ct=p("nav"),ut=p("article"),lt=p("aside"),dt=p("h1"),ht=p("h2"),ft=p("h3"),mt=p("h4"),gt=p("h5"),vt=p("h6"),yt=p("strong"),Rt=p("em"),Ct=p("small"),bt=p("pre"),Et=p("code"),xt=p("blockquote"),Tt=p("ul"),wt=p("ol"),St=p("li"),Pt=p("a"),Lt=p("img"),Mt=p("form"),Nt=p("label"),At=p("textarea"),kt=p("select"),It=p("option"),Ht=p("table"),jt=p("thead"),Ot=p("tbody"),Vt=p("tr"),Bt=p("th"),_t=p("td");function Dt(e,t,n,r,o){if(typeof e==="function")return{component:e,props:t,children:n,key:r,directions:o};return{component:e.component,props:e.props,children:e.children,key:e.key,directions:e.directions,emitters:e.emitters}}function Ut(e,t,n){return{tag:"slot",props:{name:e},key:t,directions:n}}function $t(e,t,n){return e.map((r,o)=>{let i=t(r,o);if(typeof i==="string")throw Error("each render callback must return a VNode");if(!n)return i;return{...i,key:n(r,o)}})}function J(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 D(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function X(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ce(e){return typeof e==="string"?e:e.path}function Z(e,t){let n=e;for(let r of J(t)){if(!D(n))throw Error(`Invalid model path "${t}"`);if(!X(n,r)){if(r in n)throw Error(`Invalid model path "${t}"`);return}n=n[r]}return n}function be(e,t,n){let r=J(t),o=e;for(let s of r.slice(0,-1)){if(!X(o,s)){if(s in o)throw Error(`Invalid model path "${t}"`);o[s]={}}else if(!D(o[s]))throw Error(`Invalid model path "${t}"`);let a=o[s];if(!D(a))throw Error(`Invalid model path "${t}"`);o=a}let i=r[r.length-1];o[i]=n}function _(e,t){if(typeof e!=="string"&&e.format)return e.format(t);return t===void 0||t===null?"":String(t)}function Ee(e,t){if(typeof e!=="string"&&e.parse)return e.parse(t);return t}function xe(e,t,n){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){e.checked=Array.isArray(n)?n.some((r)=>String(r)===e.value):Boolean(n);return}if(e.type==="radio"){e.checked=n===e.value;return}e.value=_(t,n);return}if(e instanceof HTMLTextAreaElement){e.value=_(t,n);return}if(e instanceof HTMLSelectElement){if(e.multiple){let r=Array.isArray(n)?new Set(n.map(String)):new Set;for(let o=0;o<e.options.length;o+=1){let i=e.options.item(o);if(!i)continue;i.selected=r.has(i.value)}return}e.value=_(t,n)}}function Te(e,t){if(e instanceof HTMLInputElement){if(e.type==="checkbox"){if(Array.isArray(t)){let n=t.filter((r)=>String(r)!==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 r=0;r<e.selectedOptions.length;r+=1){let o=e.selectedOptions.item(r);if(o)n.push(o.value)}return n}return}class U{bindings=new WeakMap;bind(e,t,n){if(!this.isSupportedControl(e))return;let r=this.bindings.get(e);if(r&&this.sameBinding(r,t))return;this.cleanup(e);let o=Ce(t),i=()=>xe(e,t,Z(n,o)),s=e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement&&!["checkbox","radio"].includes(e.type)?"input":"change",a=()=>{let u=Z(n,o);be(n,o,Ee(t,Te(e,u)))};e.addEventListener(s,a);let c=g(i);this.bindings.set(e,{binding:t,path:o,parse:typeof t==="string"?void 0:t.parse,format:typeof t==="string"?void 0:t.format,eventName:s,listener:a,effect:c})}cleanup(e){let t=this.bindings.get(e);if(!t)return;e.removeEventListener(t.eventName,t.listener),y(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 L(e){return/^on[A-Z]/.test(e)||/^on[a-z]/.test(e)}function te(e){return e.slice(2).toLowerCase()}function ne(e){let[t,...n]=e.split(".");return{eventName:t,modifiers:new Set(n)}}function re(e,t){let n=(r)=>{if(t.has("stop"))r.stopPropagation();if(t.has("prevent"))r.preventDefault();if(t.has("self")&&r.currentTarget!==r.target)return;if(t.has("once"))r.currentTarget.removeEventListener(r.type,n);e(r)};return n}function oe(e,t,n){let r=t.includes("-")?t:t.replace(/[A-Z]/g,(o)=>`-${o.toLowerCase()}`);e.setProperty(r,ee(n))}var M=null;function ie(e){if(!e||!(e instanceof N))throw Error("Invalid router instance");M=e}function we(){if(!M)throw Error("Router is not initialized. Please make sure you have installed the router plugin.");return M}function se(){return M}var ae="http://www.w3.org/2000/svg",Se=new Set(["svg","g","defs","rect","circle","ellipse","line","polyline","polygon","path","text","tspan","textPath","use","symbol","marker","linearGradient","radialGradient","stop","pattern","mask","clipPath","foreignObject"]);class k{listeners=new WeakMap;effects=new WeakMap;modelBindings=new U;matches(e){return typeof e==="object"&&e!==null&&Y(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=e.tag==="navigator",r=n?document.createElement("a"):Se.has(e.tag)?document.createElementNS(ae,e.tag):document.createElement(e.tag),o=e.props??{};if(n){let{url:i,openType:s,...a}=o,c=typeof i==="string"?i:"#";r.setAttribute("href",c),r.addEventListener("click",(u)=>{let l=se();if(l)u.preventDefault(),l.push(r.getAttribute("href")??"#")}),this.applyProps(r,{},a,t)}else this.applyProps(r,{},o,t);return this.updateListeners(r,{},this.collectListeners(e)),this.mountChildren(r,e,t),this.applyDirections(r,void 0,e.directions,t),r}patch(e,t,n,r){if(e.tag!==t.tag||n.nodeType===Node.COMMENT_NODE){let i=this.mount(t,r);return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}if(!(n instanceof Element))return n;if(t.directions?.if===!1){let i=document.createComment("if");return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}if(t.tag==="navigator"||e.tag==="navigator"){let i=e.props??{},s=t.props??{},a=typeof i.url==="string"?i.url:"",c=typeof s.url==="string"?s.url:"";if(a!==c)n.setAttribute("href",c);let u={...s};delete u.url,delete u.openType,this.applyProps(n,i,u,r)}else this.applyProps(n,e.props??{},t.props??{},r);return this.updateListeners(n,this.collectListeners(e),this.collectListeners(t)),this.updateChildren(n,e,t,r),this.applyDirections(n,e.directions,t.directions,r),n}unmount(e,t,n){if(!(t instanceof Element))return;this.effects.get(t)?.forEach((r)=>y(r)),this.effects.delete(t),this.listeners.get(t)?.forEach(({eventName:r,listener:o})=>{t.removeEventListener(r,o)}),this.listeners.delete(t),this.modelBindings.cleanup(t),this.unmountChildren(t,e,n)}mountChildren(e,t,n){v(t.children).forEach((r)=>{e.appendChild(n.renderer.mount(r,n))})}updateChildren(e,t,n,r){this.updateOrdinaryChildren(e,v(t.children),v(n.children),r)}unmountChildren(e,t,n){v(t.children).forEach((r,o)=>{let i=e.childNodes[o];if(i)n.renderer.unmount(r,i,n)})}applyProps(e,t,n,r){Object.keys(t).forEach((o)=>{if(L(o)||o in n)return;if(o==="className"||o==="class")e.removeAttribute("class");else if(o==="style")e.removeAttribute("style");else if(o==="value"&&typeof e==="object"&&e!==null&&"value"in e)e.value="";else e.removeAttribute(A(o))}),Object.entries(n).forEach(([o,i])=>{if(L(o))return;if(t[o]===i)return;if(o==="className"||o==="class"){if(e.namespaceURI===ae)e.setAttribute("class",String(i??""));else e.className=String(i??"");return}if(o==="value"&&typeof e==="object"&&e!==null&&"value"in e){e.value=String(i??"");return}if(o==="style"&&typeof i==="object"&&i!==null){e.removeAttribute("style");let s=e.style;Object.entries(i).forEach(([a,c])=>{oe(s,a,c)});return}if(i===!1||i===void 0||i===null){e.removeAttribute(A(o));return}if(i===!0){e.setAttribute(A(o),"");return}if(typeof i==="string"&&r.templateEngine.hasExpressions(i)){this.setupReactiveAttribute(e,o,i,r);return}e.setAttribute(A(o),String(i))})}applyDirections(e,t,n,r){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,r.templateEngine.state)}updateOrdinaryChildren(e,t,n,r){if(this.assertNoDuplicateKeys(t),this.assertNoDuplicateKeys(n),this.hasOnlyKeyedChildren(t,n)){this.updateKeyedChildren(e,t,n,r);return}let o=Math.min(t.length,n.length);for(let i=0;i<o;i+=1){let s=e.childNodes[i];if(!s){e.appendChild(r.renderer.mount(n[i],r));continue}r.renderer.patch(t[i],n[i],s,r)}for(let i=o;i<n.length;i+=1)e.appendChild(r.renderer.mount(n[i],r));for(let i=t.length-1;i>=n.length;i-=1){let s=e.childNodes[i];if(s){if(r.renderer.unmount(t[i],s,r),s.parentNode===e)e.removeChild(s)}}}updateKeyedChildren(e,t,n,r){let o=t.map((a,c)=>({vnode:a,node:e.childNodes[c],index:c})),i=new Map,s=new Set;o.forEach((a)=>{let c=this.getVNodeKey(a.vnode);if(c!==void 0&&a.node)i.set(c,{vnode:a.vnode,node:a.node,index:a.index})}),n.forEach((a,c)=>{let u=this.getVNodeKey(a),l=u===void 0?void 0:i.get(u),b;if(l)b=r.renderer.patch(l.vnode,a,l.node,r),s.add(l.index);else b=r.renderer.mount(a,r);let F=e.childNodes[c]??null;if(b!==F)e.insertBefore(b,F)}),o.forEach((a)=>{if(!a.node||s.has(a.index))return;if(r.renderer.unmount(a.vnode,a.node,r),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 r=this.getVNodeKey(n);if(r===void 0)return;if(t.has(r))throw Error(`Duplicate key "${r}"`);t.add(r)})}getVNodeKey(e){if(typeof e==="string")return;return e.key}collectListeners(e){let t={};return Object.entries(e.props??{}).forEach(([n,r])=>{if(L(n)&&typeof r==="function")t[te(n)]=r}),{...t,...e.listeners??{}}}updateListeners(e,t,n){let r=this.listeners.get(e)??new Map,o=new Set(Object.keys(t)),i=new Set(Object.keys(n));o.forEach((s)=>{if(!i.has(s)||t[s]!==n[s]){let a=r.get(s);if(a)e.removeEventListener(a.eventName,a.listener),r.delete(s)}}),i.forEach((s)=>{if(!o.has(s)||t[s]!==n[s]){let{eventName:a,modifiers:c}=ne(s),u=re(n[s],c);e.addEventListener(a,u),r.set(s,{eventName:a,listener:u})}}),this.listeners.set(e,r)}setupReactiveAttribute(e,t,n,r){let o=g(()=>{e.setAttribute(t,r.templateEngine.evaluateTemplateValue(n))});this.trackEffect(e,o)}trackEffect(e,t){let n=this.effects.get(e)??new Set;n.add(t),this.effects.set(e,n)}}function A(e){if(e.startsWith("data")&&e.length>4)return`data${e.slice(4).replace(/[A-Z]/g,(t)=>`-${t.toLowerCase()}`)}`;if(e==="tabIndex"||e==="colSpan"||e==="htmlFor")return e.toLowerCase();return e}class S{strategies;constructor(){this.strategies=[new pe,new ce,new ue,new k]}mount(e,t){return this.findStrategy(e).mount(e,t)}patch(e,t,n,r){let o=this.findStrategy(e),i=this.findStrategy(t);if(o!==i){let s=i.mount(t,r);return n.parentNode?.replaceChild(s,n),o.unmount(e,n,r),s}return o.patch(e,t,n,r)}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 pe{matches(e){return typeof e==="string"}mount(e,t){return t.templateEngine.parseTemplate(e)}patch(e,t,n,r){if(e===t)return n;let o=this.mount(t,r);return n.parentNode?.replaceChild(o,n),o}unmount(){}}class ce{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 r=new e.component(this.createProps(e));if(t.appContext&&r.setAppContext)r.setAppContext(t.appContext);this.syncEmitters(r,e.emitters??{}),t.registerChild(r);let o=r.mountToNode();return this.trackInstanceNode(r,o),r.setElementChangeListener?.((i,s)=>{this.trackInstanceNode(r,i),this.trackInstanceNode(r,s)}),o}patch(e,t,n,r){if(n.nodeType===Node.COMMENT_NODE){let s=this.mount(t,r);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,r),s}let o=this.instances.get(n);if(o&&e.component===t.component){this.syncEmitters(o,t.emitters??{}),o.setProps(this.createProps(t));let s=o.getElement()??n;return this.trackInstanceNode(o,s),s}let i=this.mount(t,r);return n.parentNode?.replaceChild(i,n),this.unmount(e,n,r),i}unmount(e,t,n){let r=this.instances.get(t);if(r)this.clearEmitters(r),r.unmount(),this.clearInstanceNodes(r),n.unregisterChild(r)}createProps(e){return{...e.props??{},children:v(e.children)}}syncEmitters(e,t){let n=this.emitterUnsubscribers.get(e)??new Map;n.forEach(({listener:r,unsubscribe:o},i)=>{let s=t[i];if(!s||s!==r)o(),n.delete(i)}),Object.entries(t).forEach(([r,o])=>{if(n.get(r)?.listener===o)return;n.set(r,{listener:o,unsubscribe:e.on(r,o)})}),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 ue{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,r){if(n.nodeType===Node.COMMENT_NODE){let o=this.mount(t,r);return n.parentNode?.replaceChild(o,n),o}if(t.directions?.if===!1){let o=document.createComment("if");return n.parentNode?.replaceChild(o,n),this.unmount(e,n,r),o}if(n instanceof HTMLElement)n.setAttribute("data-slot",t.props.name),this.replaceSlotChildren(n,e,t,r);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]??v(e.children)}replaceSlotChildren(e,t,n,r){let o=this.renderedChildren.get(e)??[],i=this.resolveChildren(n,r),s=Math.min(o.length,i.length);for(let a=0;a<s;a+=1){let c=e.childNodes[a];if(!c){e.appendChild(r.renderer.mount(i[a],r));continue}r.renderer.patch(o[a],i[a],c,r)}for(let a=s;a<i.length;a+=1)e.appendChild(r.renderer.mount(i[a],r));for(let a=o.length-1;a>=i.length;a-=1){let c=e.childNodes[a];if(c){if(r.renderer.unmount(o[a],c,r),c.parentNode===e)e.removeChild(c)}}this.renderedChildren.set(e,i)}mountSlotChildren(e,t,n){t.forEach((r)=>{e.appendChild(n.renderer.mount(r,n))}),this.renderedChildren.set(e,t)}unmountSlotChildren(e,t){(this.renderedChildren.get(e)??[]).forEach((r,o)=>{let i=e.childNodes[o];if(i)t.renderer.unmount(r,i,t)})}}class C{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 r=new Set,o=this.evaluateTemplate(t,n,r);e.textContent=o;let i=g(()=>{try{let s=this.evaluateTemplate(t,n,r);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 r=e;return t.forEach((o)=>{let i=o[1]?.trim();if(i){n.add(i);let s=this.getValueFromState(i),a=s===void 0||s===null?"":String(s);r=r.replace(o[0],a)}}),r}getValueFromState(e){if(!e)return;let t=e.split("."),n=this.state;for(let r of t){if(!n||typeof n!=="object")return;n=n[r]}return n}clearBindings(){this.bindings.forEach((e)=>{y(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,r=new RegExp(this.templateRegex,"g");while((n=r.exec(e))!==null){let o=n[1]?.trim();if(o)t.push(o)}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 P{props;vnode=null;el=null;renderer=new S;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 le,this.state=B(this.initState()??{}),this.templateEngine=new C(this.state),this.initStyles(),this.updateEffect=g(()=>{if(this.mounted)try{this.update()}catch(t){if(!this.dispatchError(t))throw t}},{throwOnError:!0,scheduler:(t)=>{E.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.el=m.getInstance().runWithEffect(this.updateEffect,()=>{try{return this.vnode=this.render(),this.renderer.mount(this.vnode,this.createRenderContext())}catch(e){if(this.dispatchError(e))return document.createComment("error-boundary");throw e}}),this.mounted=!0,this.onMounted(),this.el}update(){if(!this.el||!this.vnode)return;this.beforeUpdate();let e=this.vnode,t=this.el;if(this.el=m.getInstance().runWithEffect(this.updateEffect,()=>{let n=this.render(),r=this.renderer.patch(e,n,t,this.createRenderContext());return this.vnode=n,r}),t!==this.el)this.elementChangeListener?.(t,this.el);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(),y(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)E.enqueue(this.updateEffect)}setState(e){Object.assign(this.state,e)}setAppContext(e){this.appContext=e,this.childComponents.forEach((t)=>{t.setAppContext?.(e)})}setParentComponent(e){this.parentComponent=e}getParentComponent(){return this.parentComponent}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(){}dispatchError(e){let t=this.getParentComponent();while(t){let n=t;if(typeof n.onErrorCaptured==="function"){if(n.onErrorCaptured(e,this)===!1)return!0}t=t.getParentComponent?.()??null}return!1}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 v(this.props.children).forEach((n)=>{let r=this.getSlotName(n);if(!e[r])e[r]=[];e[r].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}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}}}function x(e){if(!e.startsWith("/"))return`/${e}`;return e||"/"}function I(e,t){let n=x(t.split("?")[0]);for(let i of e){if(i.path==="*")continue;let s=Pe(i.path,n);if(s)return{route:i,params:s}}let r=e.find((i)=>i.path==="*");if(r)return{route:r,params:{pathMatch:n}};let o=e.find((i)=>i.path==="/");return o?{route:o,params:{}}:null}function Pe(e,t){let n=de(e),r=de(t);if(n.length!==r.length)return null;let o={};for(let i=0;i<n.length;i+=1){let s=n[i],a=r[i];if(s.startsWith(":")){let c=s.slice(1);if(!c)return null;o[decodeURIComponent(c)]=decodeURIComponent(a);continue}if(s!==a)return null}return o}function de(e){let t=x(e);if(t==="/")return[];return t.split("/").filter(Boolean)}function he(e,t,n){let r=x(e),o=n==="/"?r:n+r;return t==="hash"?`#${o}`:o}function fe(e,t){let n,r,o;if(e==="history")r=window.location.pathname+window.location.search,n=window.location.pathname,o=window.location.search;else{r=window.location.hash||"#/",n=r.startsWith("#")?r.slice(1):r;let s=n.indexOf("?");o=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=x(n),{path:n,fullPath:r,query:Le(o),params:{}}}function K(e,t,n,r){let o=x(e),i=r==="/"?o:r+o;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((r)=>{let[o,i]=r.split("=");if(o)t[decodeURIComponent(o)]=i?decodeURIComponent(i):""}),t}function Me(e){let t=e.indexOf("?");if(t<0)return{};let n=e.slice(t+1),r={};if(!n)return r;return n.split("&").forEach((o)=>{let[i,s]=o.split("=");if(i)r[decodeURIComponent(i)]=s?decodeURIComponent(s):""}),r}class N{currentRoute=null;currentLocation=null;routes=[];app=null;mode;base;routeChangeListeners=[];beforeGuards=[];afterHooks=[];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,ie(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)}}beforeEach(e){return this.beforeGuards.push(e),()=>{let t=this.beforeGuards.indexOf(e);if(t>-1)this.beforeGuards.splice(t,1)}}afterEach(e){return this.afterHooks.push(e),()=>{let t=this.afterHooks.indexOf(e);if(t>-1)this.afterHooks.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 he(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");let n=this.currentLocation,r=this.resolveTarget(e);if(!r)return;let o=r.location;for(let i of this.beforeGuards){let s=i(o,n);if(s===!1)return;if(typeof s==="string"&&s!==e){this.navigate(s,t);return}}if(n&&this.isSameLocation(n,o))return;K(r.path,t,this.mode,this.base),this.currentRoute=r.route,this.currentLocation=o,this.triggerRouteChangeListeners(o,n),this.afterHooks.forEach((i)=>{try{i(o,n)}catch(s){console.error("Route afterEach error:",s)}})}resolveTarget(e){let t=I(this.routes,e.split("?")[0]);if(!t)return null;let n=this.applyRedirect(t),r=n?.path??e,o=n?.route??t.route;return{path:r,route:o,location:{path:r.split("?")[0],query:Me(r),params:n?.params??t.params,fullPath:r,name:o?.name,meta:o?.meta}}}applyRedirect(e){let t=new Set,n=e,r="";while(n.route.redirect){if(t.has(n.route.path))throw Error(`Redirect loop detected for route: ${n.route.path}`);t.add(n.route.path),r=n.route.redirect;let o=I(this.routes,r.split("?")[0]);if(!o)return null;n=o}return r?{route:n.route,params:n.params,path:r}:null}validateRoutes(){if(!Array.isArray(this.routes))throw Error("Router routes must be an array");let e=new Set;this.routes.forEach((t)=>{if(!t.component&&!t.redirect)throw Error(`Route ${t.path} must define a component or redirect`);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=I(this.routes,e.path),n=t?this.applyRedirect(t):null,r=n?.route??t?.route??null;if(n&&n.path!==e.path)K(n.path,!0,this.mode,this.base);if(this.currentRoute=r,this.currentLocation={...e,params:n?.params??t?.params??{},name:r?.name,meta:r?.meta},this.afterHooks.length>0){let o=this.currentLocation;this.afterHooks.forEach((i)=>{try{i(o,null)}catch(s){console.error("Route afterEach error:",s)}})}return this.currentLocation}getCurrentLocation(){return fe(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(r){console.error("Route change listener error:",r)}})}}class Ne extends P{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,r=[this.props.className,n?t:void 0].filter(Boolean).join(" ");return{tag:"a",props:{href:e?.createHref(this.props.to)??this.props.to,className:r},listeners:{click:(o)=>{if(o.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 P{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?[{component:e.component}]:[]}}}function Dn(e){return new N(e)}var ke=new Set(["base","link","meta"]);function me(e){let t=e.lang??"en",n=e.charset??"utf-8",r=e.viewport??"width=device-width, initial-scale=1",o=H({lang:t,...e.htmlAttributes??{}}),i=H(e.bodyAttributes),s=Ie(e.body);return["<!doctype html>",`<html${o}>`,"<head>",` <meta charset="${T(n)}">`,` <meta name="viewport" content="${T(r)}">`,` <title>${T(e.title)}</title>`,e.description?` <meta name="description" content="${T(e.description)}">`:"",...(e.head??[]).map((a)=>` ${He(a)}`),e.styles&&e.styles.length>0?` <style>${W(e.styles)}</style>`:"","</head>",`<body${i}>`,s,...(e.scripts??[]).map((a)=>` ${je(a)}`),"</body>","</html>"].filter((a)=>a!=="").join(`
|
|
2
|
+
`)}function Ie(e){if(typeof document>"u")throw Error("renderHtmlDocument requires a DOM-like document");let t=document.createElement("div"),n=new S,r=new Set,o=Array.isArray(e)?e:[e],i={templateEngine:new C({}),renderer:n,slots:{default:[]},registerChild:(a)=>{r.add(a)},unregisterChild:(a)=>{r.delete(a)}};o.forEach((a)=>{t.appendChild(n.mount(a,i))});let s=t.innerHTML;return r.forEach((a)=>{a.unmount()}),s}function He(e){let t=H(e.attributes);if(ke.has(e.tag)&&!e.text)return`<${e.tag}${t}>`;return`<${e.tag}${t}>${T(e.text??"")}</${e.tag}>`}function je(e){return`<script${H({type:e.type,src:e.src,async:e.async,defer:e.defer,...e.attributes??{}})}></script>`}function H(e={}){let t=Object.entries(e).flatMap(([n,r])=>{if(r===!1||r===null||r===void 0)return[];return r===!0?[n]:[`${n}="${T(String(r))}"`]}).join(" ");return t?` ${t}`:""}function T(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}var ge="#app";class Oe{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.2.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 C(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 me({...t,...e,title:e.title??t.title??"TransOne 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??ge);return e instanceof HTMLElement?e:null}createMountDocumentBody(){let e=this.options.rootElement??ge;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 w({props:{id:"app"}})}createMountElementFromSelector(e){if(e.startsWith("#")&&e.length>1)return w({props:{id:e.slice(1)}});if(e.startsWith(".")&&e.length>1)return w({props:{className:e.slice(1)}});return w({props:{"data-transone-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{E as a,Fe as b,Ge as c,m as d,B as e,qe as f,g,ze as h,Ye as i,q as j,Qe as k,y as l,Ze as m,ye as n,Je as o,v as p,z as q,Y as r,Q as s,et as t,Re as u,w as v,tt as w,nt as x,rt as y,ot as z,it as A,st as B,at as C,pt as D,ct as E,ut as F,lt as G,dt as H,ht as I,ft as J,mt as K,gt as L,vt as M,yt as N,Rt as O,Ct as P,bt as Q,Et as R,xt as S,Tt as T,wt as U,St as V,Pt as W,Lt as X,Mt as Y,Nt as Z,At as _,kt as $,It as aa,Ht as ba,jt as ca,Ot as da,Vt as ea,Bt as fa,_t as ga,Dt as ha,Ut as ia,$t as ja,Ce as ka,Z as la,be as ma,U as na,N as oa,Ne as pa,Ae as qa,Dn as ra,we as sa,k as ta,S as ua,pe as va,ce as wa,ue as xa,C as ya,P as za,me as Aa,Oe as Ba};
|
|
10
|
+
|
|
11
|
+
//# debugId=F4C2EFB04D92A5B664756E2164756E21
|
|
12
|
+
//# sourceMappingURL=index-sf0hkgh3.js.map
|