transone 0.1.2 → 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/dist/core/vnode.d.ts +1 -0
- package/dist/index-49z4707x.js +12 -0
- package/dist/{index-2h18qzcx.js.map → index-49z4707x.js.map} +9 -9
- package/dist/index-d5wsetxf.js +27 -0
- package/dist/index-d5wsetxf.js.map +12 -0
- package/dist/index-xp7y2crt.js +5 -0
- package/dist/index-xp7y2crt.js.map +18 -0
- package/dist/index.d.ts +2 -1
- 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 +5 -1
- package/dist/index-2e39fr05.js +0 -26
- package/dist/index-2e39fr05.js.map +0 -11
- package/dist/index-2h18qzcx.js +0 -12
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* request 模块公共类型:跨端(Web / 微信 / 阿里 / 字节小程序)统一请求模型。
|
|
3
|
+
*/
|
|
4
|
+
/** 支持的 HTTP 方法 */
|
|
5
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
6
|
+
/**
|
|
7
|
+
* 目标端。'auto' 表示运行时按环境自动探测(默认)。
|
|
8
|
+
* 各端对应请求 API:Web fetch / 微信 wx.request / 阿里 my.request / 字节 tt.request。
|
|
9
|
+
*/
|
|
10
|
+
export type RequestPlatform = 'auto' | 'web' | 'weixin' | 'alipay' | 'bytedance';
|
|
11
|
+
/** 运行时探测结果;探测不到任何受支持环境时为 'unknown' */
|
|
12
|
+
export type DetectedPlatform = Exclude<RequestPlatform, 'auto'> | 'unknown';
|
|
13
|
+
/** 响应数据解析方式:json 自动解析(失败回退原文),text 返回原始字符串 */
|
|
14
|
+
export type RequestDataType = 'json' | 'text';
|
|
15
|
+
/** 响应数据类型(小程序端 responseType 语义) */
|
|
16
|
+
export type RequestResponseType = 'text' | 'arraybuffer';
|
|
17
|
+
export type HeaderValue = string | number | boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 单次请求配置。
|
|
20
|
+
* 未填写的字段回退到实例级默认值(RequestOptions);实例级也没有的字段使用平台默认。
|
|
21
|
+
*/
|
|
22
|
+
export interface RequestConfig<T = unknown> {
|
|
23
|
+
/** 请求地址;以协议(http:// / https:// 等)开头时忽略 baseURL */
|
|
24
|
+
url: string;
|
|
25
|
+
/** HTTP 方法,默认 GET */
|
|
26
|
+
method?: HttpMethod | Lowercase<HttpMethod>;
|
|
27
|
+
/** 基础地址,与 url 拼接;仅对相对地址生效 */
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
/** 请求头,合并到实例级默认请求头之上(大小写不敏感,后者覆盖前者) */
|
|
30
|
+
headers?: Record<string, HeaderValue>;
|
|
31
|
+
/** URL query 参数,序列化追加到地址后 */
|
|
32
|
+
params?: Record<string, unknown>;
|
|
33
|
+
/** 请求体:普通对象 / 数组自动 JSON 序列化并设置 Content-Type */
|
|
34
|
+
data?: T;
|
|
35
|
+
/** 超时(毫秒);0 / 缺省表示不超时 */
|
|
36
|
+
timeout?: number;
|
|
37
|
+
/** 响应解析方式,默认 json */
|
|
38
|
+
dataType?: RequestDataType;
|
|
39
|
+
/** 响应数据类型,默认 text */
|
|
40
|
+
responseType?: RequestResponseType;
|
|
41
|
+
/** 取消信号(AbortSignal);小程序端通过 abort 底层请求任务实现 */
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
/** 本次请求的目标端覆盖;缺省继承实例级配置,默认 auto 自动探测 */
|
|
44
|
+
platform?: RequestPlatform;
|
|
45
|
+
/** Web 端:跨域请求携带凭证(等价 credentials: 'include') */
|
|
46
|
+
withCredentials?: boolean;
|
|
47
|
+
/** Web 端:fetch credentials,显式设置时优先于 withCredentials */
|
|
48
|
+
credentials?: RequestCredentials;
|
|
49
|
+
/** 透传平台特有选项(如 wx.request 的 enableHttp2 / enableChunked 等) */
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 统一响应:各端原始响应(fetch Response / wx success 等)归一化后的形状。
|
|
54
|
+
* HTTP 4xx/5xx 不视为异常(与小程序端 success 语义一致),由调用方按 statusCode 处理。
|
|
55
|
+
*/
|
|
56
|
+
export interface RequestResponse<T = unknown> {
|
|
57
|
+
/** 响应体:dataType json 时已尝试 JSON.parse */
|
|
58
|
+
data: T;
|
|
59
|
+
/** HTTP 状态码 */
|
|
60
|
+
statusCode: number;
|
|
61
|
+
/** 状态文本(Web 端有,小程序端为空) */
|
|
62
|
+
statusText?: string;
|
|
63
|
+
/** 响应头(键名保持平台原始大小写) */
|
|
64
|
+
headers: Record<string, string>;
|
|
65
|
+
/** 请求最终使用的配置(含实例级默认值合并结果) */
|
|
66
|
+
config: RequestConfig;
|
|
67
|
+
/** 小程序端返回的 cookie(微信 / 字节) */
|
|
68
|
+
cookies?: string[];
|
|
69
|
+
/** 平台原始 errMsg(如有) */
|
|
70
|
+
errMsg?: string;
|
|
71
|
+
}
|
|
72
|
+
/** 拦截器成功回调:可返回原值 / 新值 / Promise */
|
|
73
|
+
export type InterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
|
74
|
+
/** 拦截器失败回调:处理后可返回一个值恢复流程,或再次抛出 */
|
|
75
|
+
export type InterceptorRejected = (error: unknown) => unknown;
|
|
76
|
+
export interface InterceptorHandler<T> {
|
|
77
|
+
onFulfilled?: InterceptorFulfilled<T>;
|
|
78
|
+
onRejected?: InterceptorRejected;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 平台适配器(策略):每种目标端一个实现。
|
|
82
|
+
* 统一输入 RequestConfig,输出归一化 RequestResponse;失败抛出 RequestError。
|
|
83
|
+
*/
|
|
84
|
+
export interface RequestAdapter {
|
|
85
|
+
readonly platform: Exclude<RequestPlatform, 'auto'>;
|
|
86
|
+
request<T>(config: RequestConfig<T>): Promise<RequestResponse<T>>;
|
|
87
|
+
}
|
|
88
|
+
/** 自定义适配器解析函数:根据请求配置返回适配器 */
|
|
89
|
+
export type RequestAdapterResolver = (config: RequestConfig) => RequestAdapter | Promise<RequestAdapter>;
|
|
90
|
+
/**
|
|
91
|
+
* 实例级默认配置:字段语义与 RequestConfig 一致,作为默认值合并到每次请求。
|
|
92
|
+
*/
|
|
93
|
+
export interface RequestOptions {
|
|
94
|
+
baseURL?: string;
|
|
95
|
+
headers?: Record<string, HeaderValue>;
|
|
96
|
+
params?: Record<string, unknown>;
|
|
97
|
+
timeout?: number;
|
|
98
|
+
dataType?: RequestDataType;
|
|
99
|
+
responseType?: RequestResponseType;
|
|
100
|
+
/** 默认目标端,默认 auto(运行时探测) */
|
|
101
|
+
platform?: RequestPlatform;
|
|
102
|
+
/** 自定义适配器(对象或解析函数),优先级高于 platform */
|
|
103
|
+
adapter?: RequestAdapter | RequestAdapterResolver;
|
|
104
|
+
}
|
package/dist/router/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{oa as a,pa as b,qa as c,ra as d,sa as e}from"../index-49z4707x.js";import"../index-d5wsetxf.js";export{a as Router,b as RouterLink,c as RouterView,d as createRouter,e as useRouter};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=C414913A2B2EE6FA64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/router/index.js.map
CHANGED
package/dist/style/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Da as f,Ea as m}from"../index-d5wsetxf.js";export{f as StyleManager,m as renderStyleSheet};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=17CBBF4901184E9464756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/style/index.js.map
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** 跨端尺寸单位换算:rpx(微信 750 设计宽)在 H5 端转换为视口相对值。
|
|
2
|
+
*
|
|
3
|
+
* 1rpx = 视口宽度 / 750,且视口宽度上限 750px(桌面端不再放大,页面按
|
|
4
|
+
* 750px 基准居中显示,与小程序设计宽一致)。
|
|
5
|
+
*/
|
|
6
|
+
/** 根 CSS 变量:--cyy-rpx 为 1rpx 的等效长度 */
|
|
7
|
+
export declare const ROOT_RPX_RULE = ":root{--cyy-rpx:calc(min(100vw, 750px) / 750);}";
|
|
8
|
+
/** 把字符串/数值中的 `N rpx` 替换为 `calc(N * var(--cyy-rpx))` */
|
|
9
|
+
export declare function convertRpx(value: string | number): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TransOne 是跨端前端框架:一份 TypeScript 源码,编译期静态转换为 Web 与多端小程序原生产物,产物不携带框架运行时",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"./dom": {
|
|
23
23
|
"import": "./dist/dom/index.js",
|
|
24
24
|
"types": "./dist/dom/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./request": {
|
|
27
|
+
"import": "./dist/request/index.js",
|
|
28
|
+
"types": "./dist/request/index.d.ts"
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
"scripts": {
|
package/dist/index-2e39fr05.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
class i{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()}: ${r};`).join(`
|
|
2
|
-
`)}updateStyles(){if(this.styles.size===0){if(this.styleElement)this.styleElement.textContent="";return}let e=this.ensureStyleElement(),t="";this.styles.forEach((r)=>{if(t+=`${r.selector} {
|
|
3
|
-
${this.convertToCSS(r.properties)}
|
|
4
|
-
}
|
|
5
|
-
`,r.hover)t+=`${r.selector}:hover {
|
|
6
|
-
${this.convertToCSS(r.hover)}
|
|
7
|
-
}
|
|
8
|
-
`;if(r.media)Object.entries(r.media).forEach(([n,s])=>{t+=`@media ${n} {
|
|
9
|
-
${r.selector} {
|
|
10
|
-
${this.convertToCSS(s)}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
`})}),e.textContent=t}}function u(e){return e.map((t)=>l(t)).join(`
|
|
14
|
-
|
|
15
|
-
`)}function l(e,t=""){if("atRule"in e){let n=e.rules.map((s)=>l(s,`${t} `)).join(`
|
|
16
|
-
|
|
17
|
-
`);return`${t}${e.atRule} {
|
|
18
|
-
${n}
|
|
19
|
-
${t}}`}let r=Object.entries(e.properties).map(([n,s])=>`${t} ${o(n)}: ${String(s)};`).join(`
|
|
20
|
-
`);return`${t}${e.selector} {
|
|
21
|
-
${r}
|
|
22
|
-
${t}}`}function o(e){if(e.startsWith("--")||e.includes("-"))return e;return e.replace(/[A-Z]/g,(t)=>`-${t.toLowerCase()}`)}
|
|
23
|
-
export{i as Ca,u as Da};
|
|
24
|
-
|
|
25
|
-
//# debugId=F58C708B069121FF64756E2164756E21
|
|
26
|
-
//# sourceMappingURL=index-2e39fr05.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../lib/style/StyleManager.ts", "../lib/style/sheet.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
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 | 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}: ${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 = '';\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",
|
|
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
|
-
],
|
|
8
|
-
"mappings": "AAOO,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,IACtB,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,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,EAAQ,YAAc,EAE1B,CCtEO,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": "F58C708B069121FF64756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
package/dist/index-2h18qzcx.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{Ca as pe,Da as W}from"./index-2e39fr05.js";var R=Symbol("is_reactive"),l=Symbol("is_readonly"),H=Symbol("is_ref"),G=["push","pop","shift","unshift","splice","sort","reverse"];function d(e,t){return Boolean(Reflect.get(e,t))}function h(e){return e!==null&&typeof e==="object"}class j{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,E=new j;function Ke(){return E.nextTick()}function We(){E.flush()}class f{static instance;activeEffect=null;effectStack=[];targetMap=new WeakMap;reactiveMap=new WeakMap;readonlyMap=new WeakMap;proxyMap=new WeakMap;constructor(){}static getInstance(){if(!f.instance)f.instance=new f;return f.instance}reactive(e){if(!h(e))return console.warn("reactive: target must be an object"),e;if(ge(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===l)return!1;this.track(n,r);let o=Reflect.get(n,r);if(h(o)&&!d(o,l))return this.reactive(o);return o},set:(n,r,o)=>{if(d(n,l))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(h(o)&&!d(o,R)&&!d(o,l))o=this.reactive(o);let s=Reflect.set(n,r,o);if(i!==o)this.trigger(n,r);return s},deleteProperty:(n,r)=>{if(d(n,l))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(h(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===l)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((u)=>this.toRawValue(u));return c[r].apply(c,s.map((u)=>this.toRawValue(u)))}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(h(o)&&!d(o,l))return this.reactive(o);return o},set:(n,r,o)=>{if(d(n,l))return console.warn(`Cannot set property ${String(r)} on readonly object`),!1;let i=Reflect.get(n,r);if(h(o)&&!d(o,R)&&!d(o,l))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(d(n,l))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(!h(e))return console.warn("readonly: target must be an object"),e;if(d(e,l))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===l)return!0;let o=Reflect.get(n,r);if(h(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=me++,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 V(e){return f.getInstance().reactive(e)}function Fe(e){return f.getInstance().readonly(e)}function g(e,t){return f.getInstance().effect(e,t)}function Ge(e){return f.getInstance().computed(e)}function qe(e){let t={value:e};return Object.defineProperty(t,H,{configurable:!1,enumerable:!1,value:!0}),V(t)}function q(e){return h(e)&&Boolean(Reflect.get(e,H))}function ze(e){return q(e)?e.value:e}function y(e){f.getInstance().stop(e)}function O(e,t){if(!h(e)||t.has(e))return;if(t.add(e),Array.isArray(e)){e.forEach((n)=>O(n,t));return}Object.keys(e).forEach((n)=>{O(e[n],t)})}function Ye(e,t,n={}){let r=f.getInstance(),o=q(e)?()=>e.value:e,i,s=null,a=()=>{if(!m.active)return;s?.(),s=null;let u=c();t(u,i,(b)=>{s=b}),i=u},c=g(()=>{let u=o();if(n.deep&&h(u))O(u,new Set);return u},{lazy:!0,scheduler:()=>{if(n.sync)a();else E.enqueue(m)}}),m=g(()=>{a()},{lazy:!0});if(n.immediate)a();else i=c();return()=>{r.stop(c),r.stop(m)}}function ge(e){return h(e)&&d(e,R)}function Qe(e){return h(e)&&d(e,l)}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 Je(e,t,n,r,o,i){return{tag:e,props:t,children:n,listeners:r,key:o,directions:i}}function ve(e,t={}){return{tag:e,...t}}function p(e){return(t={})=>ve(e,t)}var w=p("div"),Xe=p("span"),et=p("p"),tt=p("button"),nt=p("input"),rt=p("section"),ot=p("main"),it=p("header"),st=p("footer"),at=p("nav"),pt=p("article"),ct=p("aside"),ut=p("h1"),lt=p("h2"),dt=p("h3"),ht=p("h4"),ft=p("h5"),mt=p("h6"),gt=p("strong"),vt=p("em"),yt=p("small"),Rt=p("pre"),Ct=p("code"),bt=p("blockquote"),Et=p("ul"),xt=p("ol"),Tt=p("li"),wt=p("a"),St=p("img"),Mt=p("form"),Lt=p("label"),Pt=p("textarea"),Nt=p("select"),At=p("option"),It=p("table"),kt=p("thead"),Ht=p("tbody"),jt=p("tr"),Ot=p("th"),Vt=p("td");function Bt(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}}function _t(e,t,n){return{tag:"slot",props:{name:e},key:t,directions:n}}function Dt(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 _(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function X(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ye(e){return typeof e==="string"?e:e.path}function Z(e,t){let n=e;for(let r of J(t)){if(!_(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 Re(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(!_(o[s]))throw Error(`Invalid model path "${t}"`);let a=o[s];if(!_(a))throw Error(`Invalid model path "${t}"`);o=a}let i=r[r.length-1];o[i]=n}function B(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 be(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=B(t,n);return}if(e instanceof HTMLTextAreaElement){e.value=B(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=B(t,n)}}function Ee(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 D{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=ye(t),i=()=>be(e,t,Z(n,o)),s=e instanceof HTMLTextAreaElement||e instanceof HTMLInputElement&&!["checkbox","radio"].includes(e.type)?"input":"change",a=()=>{let m=Z(n,o);Re(n,o,Ce(t,Ee(e,m)))};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 ee(e){return e.slice(2).toLowerCase()}function te(e){let[t,...n]=e.split(".");return{eventName:t,modifiers:new Set(n)}}function ne(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 re(e,t,n){let r=t.includes("-")?t:t.replace(/[A-Z]/g,(o)=>`-${o.toLowerCase()}`);e.setProperty(r,String(n))}var oe="http://www.w3.org/2000/svg",xe=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 N{listeners=new WeakMap;effects=new WeakMap;modelBindings=new D;matches(e){return typeof e==="object"&&e!==null&&Y(e)}mount(e,t){if(e.directions?.if===!1)return document.createComment("if");let n=xe.has(e.tag)?document.createElementNS(oe,e.tag):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,r){if(e.tag!==t.tag||n.nodeType===Node.COMMENT_NODE){let o=this.mount(t,r);return n.parentNode?.replaceChild(o,n),this.unmount(e,n,r),o}if(!(n instanceof Element))return n;if(t.directions?.if===!1){let o=document.createComment("if");return n.parentNode?.replaceChild(o,n),this.unmount(e,n,r),o}return this.applyProps(n,e.props??{},t.props??{},r),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(P(o))}),Object.entries(n).forEach(([o,i])=>{if(L(o))return;if(t[o]===i)return;if(o==="className"||o==="class"){if(e.namespaceURI===oe)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])=>{re(s,a,c)});return}if(i===!1||i===void 0||i===null){e.removeAttribute(P(o));return}if(i===!0){e.setAttribute(P(o),"");return}if(typeof i==="string"&&r.templateEngine.hasExpressions(i)){this.setupReactiveAttribute(e,o,i,r);return}e.setAttribute(P(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 m=this.getVNodeKey(a),u=m===void 0?void 0:i.get(m),b;if(u)b=r.renderer.patch(u.vnode,a,u.node,r),s.add(u.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[ee(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}=te(s),m=ne(n[s],c);e.addEventListener(a,m),r.set(s,{eventName:a,listener:m})}}),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 P(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 ie,new se,new ae,new N]}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 ie{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 se{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 ae{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 M{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 pe,this.state=V(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=f.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=f.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}}}var U=null;function ce(e){if(!e||!(e instanceof A))throw Error("Invalid router instance");U=e}function Te(){if(!U)throw Error("Router is not initialized. Please make sure you have installed the router plugin.");return U}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=we(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 we(e,t){let n=ue(e),r=ue(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 ue(e){let t=x(e);if(t==="/")return[];return t.split("/").filter(Boolean)}function le(e,t,n){let r=x(e),o=n==="/"?r:n+r;return t==="hash"?`#${o}`:o}function de(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:Se(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 Se(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 A{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,ce(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 le(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);return this.currentRoute=r,this.currentLocation={...e,params:n?.params??t?.params??{},name:r?.name,meta:r?.meta},this.currentLocation}getCurrentLocation(){return de(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 Le 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,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 Pe 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?[{component:e.component}]:[]}}}function On(e){return new A(e)}var Ne=new Set(["base","link","meta"]);function he(e){let t=e.lang??"en",n=e.charset??"utf-8",r=e.viewport??"width=device-width, initial-scale=1",o=k({lang:t,...e.htmlAttributes??{}}),i=k(e.bodyAttributes),s=Ae(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)=>` ${Ie(a)}`),e.styles&&e.styles.length>0?` <style>${W(e.styles)}</style>`:"","</head>",`<body${i}>`,s,...(e.scripts??[]).map((a)=>` ${ke(a)}`),"</body>","</html>"].filter((a)=>a!=="").join(`
|
|
2
|
-
`)}function Ae(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 Ie(e){let t=k(e.attributes);if(Ne.has(e.tag)&&!e.text)return`<${e.tag}${t}>`;return`<${e.tag}${t}>${T(e.text??"")}</${e.tag}>`}function ke(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,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 fe="#app";class He{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.1.2",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 he({...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??fe);return e instanceof HTMLElement?e:null}createMountDocumentBody(){let e=this.options.rootElement??fe;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,Ke as b,We as c,f as d,V as e,Fe as f,g,Ge as h,qe as i,q as j,ze as k,y as l,Ye as m,ge as n,Qe as o,v as p,z as q,Y as r,Q as s,Je as t,ve as u,w as v,Xe as w,et as x,tt as y,nt as z,rt as A,ot as B,it as C,st as D,at as E,pt as F,ct as G,ut as H,lt as I,dt as J,ht as K,ft as L,mt as M,gt as N,vt as O,yt as P,Rt as Q,Ct as R,bt as S,Et as T,xt as U,Tt as V,wt as W,St as X,Mt as Y,Lt as Z,Pt as _,Nt as $,At as aa,It as ba,kt as ca,Ht as da,jt as ea,Ot as fa,Vt as ga,Bt as ha,_t as ia,Dt as ja,ye as ka,Z as la,Re as ma,D as na,N as oa,S as pa,ie as qa,se as ra,ae as sa,C as ta,M as ua,he as va,He as wa,Te as xa,A as ya,Le as za,Pe as Aa,On as Ba};
|
|
10
|
-
|
|
11
|
-
//# debugId=844BDC187ADAE76D64756E2164756E21
|
|
12
|
-
//# sourceMappingURL=index-2h18qzcx.js.map
|