solely 0.1.8 → 0.1.10

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.
Files changed (72) hide show
  1. package/README.md +117 -1
  2. package/dist/compiler/index.cjs +1 -0
  3. package/dist/compiler/index.js +1 -0
  4. package/dist/compiler/ir/buildIR.cjs +1 -0
  5. package/dist/compiler/ir/buildIR.js +1 -0
  6. package/dist/compiler/parser/parser.cjs +1 -0
  7. package/dist/compiler/parser/parser.js +1 -0
  8. package/dist/index.cjs +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -1948
  11. package/dist/plugin.cjs +1 -0
  12. package/dist/plugin.d.ts +39 -1
  13. package/dist/plugin.js +1 -0
  14. package/dist/plugins/index.d.ts +7 -1
  15. package/dist/plugins/solely-vite-plugin.cjs +1 -0
  16. package/dist/plugins/solely-vite-plugin.d.ts +28 -0
  17. package/dist/plugins/solely-vite-plugin.js +1 -0
  18. package/dist/router/core.cjs +1 -0
  19. package/dist/{runtime/router → router}/core.d.ts +1 -0
  20. package/dist/router/core.js +1 -0
  21. package/dist/router/index.cjs +1 -0
  22. package/dist/router/index.js +1 -0
  23. package/dist/router/router-link.cjs +1 -0
  24. package/dist/{runtime/router → router}/router-link.d.ts +1 -1
  25. package/dist/router/router-link.js +1 -0
  26. package/dist/router/router-view.cjs +1 -0
  27. package/dist/{runtime/router → router}/router-view.d.ts +1 -1
  28. package/dist/router/router-view.js +1 -0
  29. package/dist/router/routes copy.d.ts +6 -0
  30. package/dist/runtime/component/base-element.cjs +1 -0
  31. package/dist/runtime/component/base-element.js +1 -0
  32. package/dist/runtime/component/decorators.cjs +1 -0
  33. package/dist/runtime/component/decorators.d.ts +1 -1
  34. package/dist/runtime/component/decorators.js +1 -0
  35. package/dist/runtime/index.cjs +1 -0
  36. package/dist/runtime/index.d.ts +0 -1
  37. package/dist/runtime/index.js +1 -0
  38. package/dist/runtime/reactivity/observe.cjs +1 -0
  39. package/dist/runtime/reactivity/observe.js +1 -0
  40. package/dist/runtime/renderer/renderIR.cjs +1 -0
  41. package/dist/runtime/renderer/renderIR.js +1 -0
  42. package/dist/shared/env.cjs +1 -0
  43. package/dist/shared/env.js +1 -0
  44. package/dist/shared/event-listeners.cjs +1 -0
  45. package/dist/shared/event-listeners.js +1 -0
  46. package/dist/shared/functions.cjs +1 -0
  47. package/dist/shared/functions.js +1 -0
  48. package/dist/shared/gen-function copy.d.ts +6 -0
  49. package/dist/shared/gen-function.cjs +1 -0
  50. package/dist/shared/gen-function.d.ts +1 -0
  51. package/dist/shared/gen-function.js +1 -0
  52. package/dist/shared/index.cjs +1 -0
  53. package/dist/shared/index.js +1 -0
  54. package/dist/shared/is-object.cjs +1 -0
  55. package/dist/shared/is-object.js +1 -0
  56. package/dist/shared/templateError.cjs +1 -0
  57. package/dist/shared/templateError.js +1 -0
  58. package/dist/shared/url.cjs +1 -0
  59. package/dist/shared/url.js +1 -0
  60. package/dist/types/ast.cjs +1 -0
  61. package/dist/types/ast.js +1 -0
  62. package/dist/types/index.cjs +1 -0
  63. package/dist/types/index.js +1 -0
  64. package/dist/types/ir.d.ts +73 -61
  65. package/dist/types/lifecycle.cjs +1 -0
  66. package/dist/types/lifecycle.js +1 -0
  67. package/package.json +211 -58
  68. package/dist/index.umd.cjs +0 -47
  69. package/dist/plugins/html-parse-precompile.d.ts +0 -1
  70. package/dist/plugins/html-precompile.d.ts +0 -1
  71. /package/dist/{runtime/router → router}/index.d.ts +0 -0
  72. /package/dist/{runtime/router → router}/types.d.ts +0 -0
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{o:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./plugins/solely-vite-plugin.cjs");"undefined"!=typeof window&&(window.__SOLELY_PLUGIN_LOADED__=!0),exports.default=e.solelyVitePlugin,exports.solelyVitePlugin=e.solelyVitePlugin;
package/dist/plugin.d.ts CHANGED
@@ -1 +1,39 @@
1
- export {};
1
+ /**
2
+ * Solely Vite Plugin
3
+ *
4
+ * 提供构建时模板预编译功能,将 HTML 模板转换为优化的 IR(中间表示)
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * // vite.config.ts
9
+ * import { defineConfig } from 'vite';
10
+ * import { solelyVitePlugin } from 'solely/plugin';
11
+ *
12
+ * export default defineConfig({
13
+ * plugins: [
14
+ * solelyVitePlugin({
15
+ * precompile: true, // 启用预编译
16
+ * sourceMap: true, // 生成源码映射
17
+ * minify: false, // 不压缩(开发模式)
18
+ * })
19
+ * ]
20
+ * });
21
+ * ```
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // 组件中使用
26
+ * import { BaseElement, CustomElement } from 'solely';
27
+ * import template from './template.html'; // 导入预编译的模板
28
+ *
29
+ * @CustomElement({
30
+ * tagName: 'my-component',
31
+ * template, // 直接使用预编译的 IR
32
+ * })
33
+ * class MyComponent extends BaseElement {
34
+ * // ...
35
+ * }
36
+ * ```
37
+ */
38
+ export { solelyVitePlugin, type SolelyVitePluginOptions } from './plugins/solely-vite-plugin';
39
+ export { solelyVitePlugin as default } from './plugins/solely-vite-plugin';
package/dist/plugin.js ADDED
@@ -0,0 +1 @@
1
+ import{solelyVitePlugin as e,solelyVitePlugin as i}from"./plugins/solely-vite-plugin.js";"undefined"!=typeof window&&(window.__SOLELY_PLUGIN_LOADED__=!0);export{e as default,i as solelyVitePlugin};
@@ -1 +1,7 @@
1
- export {};
1
+ /**
2
+ * Solely 插件系统
3
+ *
4
+ * 提供构建时和运行时的扩展能力
5
+ */
6
+ export { solelyVitePlugin, type SolelyVitePluginOptions } from './solely-vite-plugin';
7
+ export { solelyVitePlugin as default } from './solely-vite-plugin';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{o:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("magic-string"),e=require("../compiler/parser/parser.cjs"),o=require("../compiler/ir/buildIR.cjs"),r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(n,r="anonymous"){const t=e.parseHtml(n);return o.buildIR(t,{filename:r,source:n})}function u(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function l(e,o,r){const t=new n.default(e),u=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${u}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function c(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug},transform(e,r){if(!u(r,o.include)||u(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug,o.precompile){const u=function(e,o,r,t){const u=new n.default(o);u.remove(0,o.length),t||(u.append("\n// ============================================\n"),u.append("// Solely Precompiled Template\n"),u.append(`// Compiled at: ${(new Date).toISOString()}\n`),u.append("// ============================================\n\n")),u.append("const __SOLELY_IR__ = {\n"),u.append(" t: 'root',\n"),u.append(` v: '${e.v}',\n\n`),t||u.append(" // 编译后的函数数组\n"),u.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),l=o===e.fns.length-1;t||u.append(` // Function ${o+1}\n`),u.append(` ${r}${l?"":","}\n`)}),u.append(" ],\n\n");const l=n=>{const e={t:n.t,d:n.d};return void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!t&&n.u&&(e.u={...n.u}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r}))),n.c&&(e.c=n.c.map(l)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(l),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...!t&&n.u&&{u:{...n.u}}}})),e},c=e.n.map(l);return t||u.append(" // IR 节点树\n"),u.append(` n: ${JSON.stringify(c,null,t?0:2)},\n\n`),t||u.append(" // 编译统计\n"),u.append(` s: ${JSON.stringify(e.s)},\n\n`),t||(u.append(" // 元数据\n"),u.append(` m: ${JSON.stringify(e.m)}\n`)),u.append("};\n\n"),t||u.append("// 导出 IR 对象\n"),u.append("export default __SOLELY_IR__;\n"),u.append("export { __SOLELY_IR__ };\n\n"),t||u.append("// 同时导出模板字符串(向后兼容)\n"),u.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:u.toString(),map:u.generateMap({source:r,includeContent:!t,hires:!t})}}(t(e,r),e,r,!!o.minify);return o.debug,{code:u.code,map:o.sourceMap?u.map:null}}{const n=l(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(c){c instanceof Error?c.message:String(c);const n=l(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(u(n,o.include)&&!u(n,o.exclude))return o.debug,e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=c),exports.compileTemplate=t,exports.default=c,exports.solelyVitePlugin=c;
@@ -0,0 +1,28 @@
1
+ import { Plugin } from 'vite';
2
+ import { IRRoot } from '../types';
3
+ export interface SolelyVitePluginOptions {
4
+ /** 是否启用模板预编译,默认 true */
5
+ precompile?: boolean;
6
+ /** 是否生成源码映射,默认 true */
7
+ sourceMap?: boolean;
8
+ /** 是否压缩生成的代码,默认 false */
9
+ minify?: boolean;
10
+ /** 自定义文件匹配模式 */
11
+ include?: string | RegExp | Array<string | RegExp>;
12
+ /** 排除的文件模式 */
13
+ exclude?: string | RegExp | Array<string | RegExp>;
14
+ /** 调试模式 */
15
+ debug?: boolean;
16
+ }
17
+ /**
18
+ * 编译 HTML 模板为 IR(中间表示)
19
+ * * @param html HTML 模板字符串
20
+ * @param filename 文件名(用于错误报告)
21
+ * @returns IR 根节点
22
+ */
23
+ export declare function compileTemplate(html: string, filename?: string): IRRoot;
24
+ /**
25
+ * Solely Vite 插件
26
+ */
27
+ export declare function solelyVitePlugin(options?: SolelyVitePluginOptions): Plugin;
28
+ export default solelyVitePlugin;
@@ -0,0 +1 @@
1
+ import n from"magic-string";import{parseHtml as e}from"../compiler/parser/parser.js";import{buildIR as o}from"../compiler/ir/buildIR.js";const r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function t(n,r="anonymous"){const t=e(n);return o(t,{filename:r,source:n})}function i(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function l(e,o,r){const t=new n(e),i=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return t.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${i}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:t.toString(),map:t.generateMap({source:o,includeContent:!r})}}function u(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug},transform(e,r){if(!i(r,o.include)||i(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug,o.precompile){const i=function(e,o,r,t){const i=new n(o);i.remove(0,o.length),t||(i.append("\n// ============================================\n"),i.append("// Solely Precompiled Template\n"),i.append(`// Compiled at: ${(new Date).toISOString()}\n`),i.append("// ============================================\n\n")),i.append("const __SOLELY_IR__ = {\n"),i.append(" t: 'root',\n"),i.append(` v: '${e.v}',\n\n`),t||i.append(" // 编译后的函数数组\n"),i.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),l=o===e.fns.length-1;t||i.append(` // Function ${o+1}\n`),i.append(` ${r}${l?"":","}\n`)}),i.append(" ],\n\n");const l=n=>{const e={t:n.t,d:n.d};return void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!t&&n.o&&(e.o={...n.o}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r}))),n.c&&(e.c=n.c.map(l)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(l),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...!t&&n.o&&{o:{...n.o}}}})),e},u=e.n.map(l);return t||i.append(" // IR 节点树\n"),i.append(` n: ${JSON.stringify(u,null,t?0:2)},\n\n`),t||i.append(" // 编译统计\n"),i.append(` s: ${JSON.stringify(e.s)},\n\n`),t||(i.append(" // 元数据\n"),i.append(` m: ${JSON.stringify(e.m)}\n`)),i.append("};\n\n"),t||i.append("// 导出 IR 对象\n"),i.append("export default __SOLELY_IR__;\n"),i.append("export { __SOLELY_IR__ };\n\n"),t||i.append("// 同时导出模板字符串(向后兼容)\n"),i.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:i.toString(),map:i.generateMap({source:r,includeContent:!t,hires:!t})}}(t(e,r),e,r,!!o.minify);return o.debug,{code:i.code,map:o.sourceMap?i.map:null}}{const n=l(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(u){u instanceof Error?u.message:String(u);const n=l(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(i(n,o.include)&&!i(n,o.exclude))return o.debug,e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=u);export{t as compileTemplate,u as default,u as solelyVitePlugin};
@@ -0,0 +1 @@
1
+ "use strict";var t=Object.defineProperty,s=(s,e,r)=>((s,e,r)=>e in s?t(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r)(s,"symbol"!=typeof e?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let e,r=null;const i=new Promise(t=>{e=t});class n{constructor(t){s(this,"routes"),s(this,"base"),s(this,"mode"),s(this,"beforeEachGuard"),s(this,"afterEachGuard"),s(this,"currentRoute",null),s(this,"listeners",new Set),s(this,"isStarted",!1),this.routes=t.routes,this.base=t.base??"/",this.mode=t.mode||"history",this.beforeEachGuard=t.beforeEach,this.afterEachGuard=t.afterEach}matchRoute(t="/"){const s=t.startsWith("/")?t:"/"+t,[e,r]=s.split("?"),i=e.split("/").filter(Boolean),n=this.parseQuery(r),h=this.recursiveMatch(this.routes,i);if(h){const t=h.matched[h.matched.length-1];return t.config.redirect?this.matchRoute(t.config.redirect):{matched:h.matched,params:h.params,query:n,fullPath:s,meta:h.matched.reduce((t,s)=>({...t,...s.config.meta||{}}),{})}}return null}recursiveMatch(t,s){const e=[...t].sort((t,s)=>this.calculateScore(s.path)-this.calculateScore(t.path));for(const r of e){const t=r.path.split("/").filter(Boolean),e={};let i=!0;if(0===t.length&&0===s.length)return{matched:[{config:r,params:{}}],params:{}};for(let r=0;r<t.length;r++){const n=t[r],h=s[r];if(n.startsWith(":")){if(!h){i=!1;break}e[n.slice(1)]=h}else{if("*"===n){i=!0;break}if(n!==h){i=!1;break}}}if(i){const i=t.length,n=s.slice(i),h={config:r,params:e};if(n.length>0&&r.children){const t=this.recursiveMatch(r.children,n);if(t)return{matched:[h,...t.matched],params:{...e,...t.params}}}else if(0===n.length||t.includes("*"))return{matched:[h],params:e}}}return null}calculateScore(t="/"){const s=t.split("/").filter(Boolean);return 0===s.length?1:s.reduce((t,s)=>s.startsWith(":")?t+5:"*"===s?t+0:t+10,0)}parseQuery(t){const s={};return t?(new URLSearchParams(t).forEach((t,e)=>{s[e]=t}),s):s}normalizePath(t="/"){let s=t&&"string"==typeof t?t:"/";return s.startsWith("/")||(s="/"+s),s.length>1&&s.endsWith("/")&&(s=s.slice(0,-1)),s}getPath(){let t;try{t="hash"===this.mode?window.location.hash.slice(1)||"/":window.location.pathname||"/"}catch{t="/"}const s=this.base||"/";return"/"!==s&&t.startsWith(s)&&(t=t.slice(s.length)||"/"),this.normalizePath(t)}updateBrowserHistory(t="/",s){const e=this.normalizePath(t),r=this.base||"/";if("hash"===this.mode)s?window.location.replace(`#${e}`):window.location.hash=e;else{const t=r.endsWith("/")?r.slice(0,-1):r,i="/"===t?e:t+e;s?window.history.replaceState({path:i},"",i):window.history.pushState({path:i},"",i)}}async navigate(t="/",s=!1,e=!1){const r=this.normalizePath(t),i=this.currentRoute,n=this.matchRoute(r);if(!n)return{success:!1,error:`No route matched: ${r}`};if(i&&i.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const t=await this.beforeEachGuard(n,i);if(!1===t)return{success:!1,cancelled:!0};if("string"==typeof t)return this.navigate(t,s)}catch(h){return{success:!1,error:h instanceof Error?h.message:"Guard Error"}}return this.currentRoute=n,e||this.updateBrowserHistory(r,s),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,i),{success:!0}}resolve(t="/"){const s=this.normalizePath(t);if("hash"===this.mode)return`#${s}`;const e=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===e?s:e+s}get modeType(){return this.mode}pushWithQuery(t="/",s){const e=new URLSearchParams(s).toString(),r=t.includes("?")?"&":"?";return this.push(t+(e?r+e:""))}push(t="/"){return this.navigate(t,!1)}replace(t="/"){return this.navigate(t,!0)}back(){window.history.back()}forward(){window.history.forward()}listen(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notifyListeners(){this.listeners.forEach(t=>t())}setupListeners(){this.isStarted||(window.addEventListener("popstate",()=>{this.navigate(this.getPath(),!0,!0)}),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}getCurrentRoute(){return this.currentRoute}}exports.Router=n,exports.createRouter=function(t){return r||(r=new n(t),e(r),r)},exports.getRouter=function(){return r},exports.routerReady=i;
@@ -48,6 +48,7 @@ export declare class Router {
48
48
  push(path?: string): Promise<NavigationResult>;
49
49
  replace(path?: string): Promise<NavigationResult>;
50
50
  back(): void;
51
+ forward(): void;
51
52
  listen(cb: () => void): () => boolean;
52
53
  private notifyListeners;
53
54
  private isStarted;
@@ -0,0 +1 @@
1
+ var t=Object.defineProperty,s=(s,e,r)=>((s,e,r)=>e in s?t(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r)(s,"symbol"!=typeof e?e+"":e,r);let e,r=null;const i=new Promise(t=>{e=t});function n(t){return r||(r=new o(t),e(r),r)}function h(){return r}class o{constructor(t){s(this,"routes"),s(this,"base"),s(this,"mode"),s(this,"beforeEachGuard"),s(this,"afterEachGuard"),s(this,"currentRoute",null),s(this,"listeners",new Set),s(this,"isStarted",!1),this.routes=t.routes,this.base=t.base??"/",this.mode=t.mode||"history",this.beforeEachGuard=t.beforeEach,this.afterEachGuard=t.afterEach}matchRoute(t="/"){const s=t.startsWith("/")?t:"/"+t,[e,r]=s.split("?"),i=e.split("/").filter(Boolean),n=this.parseQuery(r),h=this.recursiveMatch(this.routes,i);if(h){const t=h.matched[h.matched.length-1];return t.config.redirect?this.matchRoute(t.config.redirect):{matched:h.matched,params:h.params,query:n,fullPath:s,meta:h.matched.reduce((t,s)=>({...t,...s.config.meta||{}}),{})}}return null}recursiveMatch(t,s){const e=[...t].sort((t,s)=>this.calculateScore(s.path)-this.calculateScore(t.path));for(const r of e){const t=r.path.split("/").filter(Boolean),e={};let i=!0;if(0===t.length&&0===s.length)return{matched:[{config:r,params:{}}],params:{}};for(let r=0;r<t.length;r++){const n=t[r],h=s[r];if(n.startsWith(":")){if(!h){i=!1;break}e[n.slice(1)]=h}else{if("*"===n){i=!0;break}if(n!==h){i=!1;break}}}if(i){const i=t.length,n=s.slice(i),h={config:r,params:e};if(n.length>0&&r.children){const t=this.recursiveMatch(r.children,n);if(t)return{matched:[h,...t.matched],params:{...e,...t.params}}}else if(0===n.length||t.includes("*"))return{matched:[h],params:e}}}return null}calculateScore(t="/"){const s=t.split("/").filter(Boolean);return 0===s.length?1:s.reduce((t,s)=>s.startsWith(":")?t+5:"*"===s?t+0:t+10,0)}parseQuery(t){const s={};return t?(new URLSearchParams(t).forEach((t,e)=>{s[e]=t}),s):s}normalizePath(t="/"){let s=t&&"string"==typeof t?t:"/";return s.startsWith("/")||(s="/"+s),s.length>1&&s.endsWith("/")&&(s=s.slice(0,-1)),s}getPath(){let t;try{t="hash"===this.mode?window.location.hash.slice(1)||"/":window.location.pathname||"/"}catch{t="/"}const s=this.base||"/";return"/"!==s&&t.startsWith(s)&&(t=t.slice(s.length)||"/"),this.normalizePath(t)}updateBrowserHistory(t="/",s){const e=this.normalizePath(t),r=this.base||"/";if("hash"===this.mode)s?window.location.replace(`#${e}`):window.location.hash=e;else{const t=r.endsWith("/")?r.slice(0,-1):r,i="/"===t?e:t+e;s?window.history.replaceState({path:i},"",i):window.history.pushState({path:i},"",i)}}async navigate(t="/",s=!1,e=!1){const r=this.normalizePath(t),i=this.currentRoute,n=this.matchRoute(r);if(!n)return{success:!1,error:`No route matched: ${r}`};if(i&&i.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const t=await this.beforeEachGuard(n,i);if(!1===t)return{success:!1,cancelled:!0};if("string"==typeof t)return this.navigate(t,s)}catch(h){return{success:!1,error:h instanceof Error?h.message:"Guard Error"}}return this.currentRoute=n,e||this.updateBrowserHistory(r,s),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,i),{success:!0}}resolve(t="/"){const s=this.normalizePath(t);if("hash"===this.mode)return`#${s}`;const e=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===e?s:e+s}get modeType(){return this.mode}pushWithQuery(t="/",s){const e=new URLSearchParams(s).toString(),r=t.includes("?")?"&":"?";return this.push(t+(e?r+e:""))}push(t="/"){return this.navigate(t,!1)}replace(t="/"){return this.navigate(t,!0)}back(){window.history.back()}forward(){window.history.forward()}listen(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notifyListeners(){this.listeners.forEach(t=>t())}setupListeners(){this.isStarted||(window.addEventListener("popstate",()=>{this.navigate(this.getPath(),!0,!0)}),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}getCurrentRoute(){return this.currentRoute}}export{o as Router,n as createRouter,h as getRouter,i as routerReady};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core.cjs"),r=require("./router-view.cjs"),o=require("./router-link.cjs");exports.Router=e.Router,exports.createRouter=e.createRouter,exports.getRouter=e.getRouter,exports.routerReady=e.routerReady,exports.RouterView=r.default,exports.RouterLink=o.default;
@@ -0,0 +1 @@
1
+ import{Router as r,createRouter as o,getRouter as e,routerReady as t}from"./core.js";import{default as i}from"./router-view.js";import{default as s}from"./router-link.js";export{r as Router,s as RouterLink,i as RouterView,o as createRouter,e as getRouter,t as routerReady};
@@ -0,0 +1 @@
1
+ "use strict";var t=Object.defineProperty;Object.defineProperties(exports,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core.cjs"),s=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;let o=class extends s.default{constructor(){var e;super(...arguments),((e,s,n)=>{s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n})(this,"symbol"!=typeof(e="_prefetched")?e+"":e,!1)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await e.routerReady).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",t=>{var s,n;t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||0===t.button&&((null==(s=t.target.closest("a"))?void 0:s.getAttribute("target"))||(t.preventDefault(),null==(n=e.getRouter())||n.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const t=e.getRouter();if(!t)return;this.$data.href=t.resolve(this.$data.to);let s=!1;if(this.$data.active)s=!0;else{const e=t.getCurrentRoute();if(e){const t=e.fullPath;s=this.hasAttribute("exact")?t===this.$data.to:t===this.$data.to||t.startsWith(this.$data.to+"/")}}this.$data.isActive=s;const n=this.$data.activeClass||"active";this.classList.toggle(n,s)}prefetchRoute(){if(this.o||!this.hasAttribute("prefetch"))return;const t=e.getRouter();t&&"function"==typeof t.prefetch&&(t.prefetch(this.$data.to),this.o=!0)}};o=((t,e)=>{for(var s,n=e,o=t.length-1;o>=0;o--)(s=t[o])&&(n=s(n)||n);return n})([n.CustomElement({tagName:"router-link",template:'\n <a part="link" :href="$data.href" :class="{active: $data.isActive}">\n <slot>{{$data.label || \'\'}}</slot>\n </a>\n ',styles:"\n :host {\n }\n\n a {\n text-decoration: none;\n color: inherit;\n cursor: pointer;\n }\n\n /* 内部 <a> 标签的默认高亮 */\n a.active {\n font-weight: 600;\n }\n\n /* custom 模式:消除包裹 a 标签的视觉/布局影响,由 slot 内部元素接管 */\n :host([custom]) a {\n display: contents;\n }\n ",shadowDOM:{use:!0,mode:"open"},props:["to","active","exact","label","custom","activeClass","prefetch"]})],o);const i=o;exports.default=i;
@@ -1,4 +1,4 @@
1
- import { BaseElement } from '../component';
1
+ import { BaseElement } from '../runtime/component';
2
2
  declare class RouterLink extends BaseElement<{
3
3
  active: boolean;
4
4
  to: string;
@@ -0,0 +1 @@
1
+ var t=Object.defineProperty;import{routerReady as e,getRouter as s}from"./core.js";import n from"../runtime/component/base-element.js";import{CustomElement as o}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;let i=class extends n{constructor(){var e;super(...arguments),((e,s,n)=>{s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n})(this,"symbol"!=typeof(e="_prefetched")?e+"":e,!1)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await e).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",t=>{var e,n;t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||0===t.button&&((null==(e=t.target.closest("a"))?void 0:e.getAttribute("target"))||(t.preventDefault(),null==(n=s())||n.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const t=s();if(!t)return;this.$data.href=t.resolve(this.$data.to);let e=!1;if(this.$data.active)e=!0;else{const s=t.getCurrentRoute();if(s){const t=s.fullPath;e=this.hasAttribute("exact")?t===this.$data.to:t===this.$data.to||t.startsWith(this.$data.to+"/")}}this.$data.isActive=e;const n=this.$data.activeClass||"active";this.classList.toggle(n,e)}prefetchRoute(){if(this.t||!this.hasAttribute("prefetch"))return;const t=s();t&&"function"==typeof t.prefetch&&(t.prefetch(this.$data.to),this.t=!0)}};i=((t,e)=>{for(var s,n=e,o=t.length-1;o>=0;o--)(s=t[o])&&(n=s(n)||n);return n})([o({tagName:"router-link",template:'\n <a part="link" :href="$data.href" :class="{active: $data.isActive}">\n <slot>{{$data.label || \'\'}}</slot>\n </a>\n ',styles:"\n :host {\n }\n\n a {\n text-decoration: none;\n color: inherit;\n cursor: pointer;\n }\n\n /* 内部 <a> 标签的默认高亮 */\n a.active {\n font-weight: 600;\n }\n\n /* custom 模式:消除包裹 a 标签的视觉/布局影响,由 slot 内部元素接管 */\n :host([custom]) a {\n display: contents;\n }\n ",shadowDOM:{use:!0,mode:"open"},props:["to","active","exact","label","custom","activeClass","prefetch"]})],i);const a=i;export{a as default};
@@ -0,0 +1 @@
1
+ "use strict";var t=Object.defineProperty,e=(e,i,s)=>((e,i,s)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s)(e,"symbol"!=typeof i?i+"":i,s);Object.defineProperties(exports,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./core.cjs"),s=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;let r=class extends s.default{constructor(){super(...arguments),e(this,"unsubscribe"),e(this,"level",0),e(this,"currentElement",null),e(this,"currentTagName",null),e(this,"routerAttrs",new Set),e(this,"prevPropKeys",new Set),e(this,"scheduled",!1),e(this,"cache",new Map),e(this,"latestLoadId",0)}async mounted(){this.detectLevel();const t=await i.routerReady;this.unsubscribe=t.listen(()=>{this.scheduleLoad(t.getCurrentRoute())}),this.loadRoute(t.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this),this.cache.forEach(t=>t.remove()),this.cache.clear()}scheduleLoad(t){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t)}))}detectLevel(){let t=0,e=this.parentElement;for(;e;)e instanceof r&&t++,e=e.parentElement;this.level=t}async loadRoute(t){const e=++this.latestLoadId,i=null==t?void 0:t.matched[this.level];if(!i)return void this.handleEmptyRoute();const{config:s}=i;let n=s.tagName;if(!n&&"function"==typeof s.component){this.renderLoading();try{const t=await s.component();n="string"==typeof t?t:t.tagName}catch(o){return void this.renderError(`Load Error: ${o}`)}}if(e!==this.latestLoadId)return;if(!n)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===n.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear(s.keepAlive);const r=this.getOrCreateComponent(n,s);this.syncState(r,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(r),this.currentElement=r,this.currentTagName=n.toLowerCase()}getOrCreateComponent(t,e){const i=t.toLowerCase();if(e.keepAlive&&this.cache.has(i))return this.cache.get(i);const s=document.createElement(t);return e.keepAlive&&this.cache.set(i,s),s}syncState(t,e,i,s={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=new Map;Object.entries(e).forEach(([t,e])=>r.set(n(t),String(e))),Object.entries(i).forEach(([t,e])=>r.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{r.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),r.forEach((e,i)=>{t.getAttribute(i)!==e&&t.setAttribute(i,e),this.routerAttrs.add(i)});const o=new Set(Object.keys(s));this.prevPropKeys.forEach(e=>{o.has(e)||(t[e]=void 0)}),Object.entries(s).forEach(([e,i])=>{t[e]!==i&&(t[e]=i)}),this.prevPropKeys=o}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.innerHTML='<div style="padding:20px; color:#999;">Loading...</div>'}renderError(t){this.innerHTML=`<div style="padding:20px; color:#ff4d4f;">${t}</div>`}clear(t=!1){this.currentElement?this.contains(this.currentElement)&&this.removeChild(this.currentElement):t||(this.innerHTML=""),this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};r=((t,e)=>{for(var i,s=e,n=t.length-1;n>=0;n--)(i=t[n])&&(s=i(s)||s);return s})([n.CustomElement({tagName:"router-view"})],r);const o=r;exports.default=o;
@@ -1,4 +1,4 @@
1
- import { BaseElement } from '../component';
1
+ import { BaseElement } from '../runtime/component';
2
2
  import { RouteMatch } from './types';
3
3
  declare class RouterView extends BaseElement {
4
4
  private unsubscribe?;
@@ -0,0 +1 @@
1
+ var t=Object.defineProperty,i=(i,s,e)=>((i,s,e)=>s in i?t(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e)(i,"symbol"!=typeof s?s+"":s,e);import{routerReady as s}from"./core.js";import e from"../runtime/component/base-element.js";import{CustomElement as n}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;let r=class extends e{constructor(){super(...arguments),i(this,"unsubscribe"),i(this,"level",0),i(this,"currentElement",null),i(this,"currentTagName",null),i(this,"routerAttrs",new Set),i(this,"prevPropKeys",new Set),i(this,"scheduled",!1),i(this,"cache",new Map),i(this,"latestLoadId",0)}async mounted(){this.detectLevel();const t=await s;this.unsubscribe=t.listen(()=>{this.scheduleLoad(t.getCurrentRoute())}),this.loadRoute(t.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this),this.cache.forEach(t=>t.remove()),this.cache.clear()}scheduleLoad(t){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t)}))}detectLevel(){let t=0,i=this.parentElement;for(;i;)i instanceof r&&t++,i=i.parentElement;this.level=t}async loadRoute(t){const i=++this.latestLoadId,s=null==t?void 0:t.matched[this.level];if(!s)return void this.handleEmptyRoute();const{config:e}=s;let n=e.tagName;if(!n&&"function"==typeof e.component){this.renderLoading();try{const t=await e.component();n="string"==typeof t?t:t.tagName}catch(o){return void this.renderError(`Load Error: ${o}`)}}if(i!==this.latestLoadId)return;if(!n)return void this.clear();if(!e.forceReload&&this.currentElement&&this.currentTagName===n.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},e.props);this.clear(e.keepAlive);const r=this.getOrCreateComponent(n,e);this.syncState(r,null==t?void 0:t.params,(null==t?void 0:t.query)||{},e.props),this.appendChild(r),this.currentElement=r,this.currentTagName=n.toLowerCase()}getOrCreateComponent(t,i){const s=t.toLowerCase();if(i.keepAlive&&this.cache.has(s))return this.cache.get(s);const e=document.createElement(t);return i.keepAlive&&this.cache.set(s,e),e}syncState(t,i,s,e={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),r=new Map;Object.entries(i).forEach(([t,i])=>r.set(n(t),String(i))),Object.entries(s).forEach(([t,i])=>r.set(`query-${n(t)}`,String(i))),this.routerAttrs.forEach(i=>{r.has(i)||(t.removeAttribute(i),this.routerAttrs.delete(i))}),r.forEach((i,s)=>{t.getAttribute(s)!==i&&t.setAttribute(s,i),this.routerAttrs.add(s)});const o=new Set(Object.keys(e));this.prevPropKeys.forEach(i=>{o.has(i)||(t[i]=void 0)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&(t[i]=s)}),this.prevPropKeys=o}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.innerHTML='<div style="padding:20px; color:#999;">Loading...</div>'}renderError(t){this.innerHTML=`<div style="padding:20px; color:#ff4d4f;">${t}</div>`}clear(t=!1){this.currentElement?this.contains(this.currentElement)&&this.removeChild(this.currentElement):t||(this.innerHTML=""),this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};r=((t,i)=>{for(var s,e=i,n=t.length-1;n>=0;n--)(s=t[n])&&(e=s(e)||e);return e})([n({tagName:"router-view"})],r);const o=r;export{o as default};
@@ -0,0 +1,6 @@
1
+ import { RouteConfig } from './types';
2
+ /**
3
+ * 最终完整路由配置表
4
+ */
5
+ export declare const routes: RouteConfig[];
6
+ export default routes;
@@ -0,0 +1 @@
1
+ "use strict";var t,e,s,i,n,h,a,o,r,c,u,l,d,f,b,p,v,m,k,w,y=Object.defineProperty,M=t=>{throw TypeError(t)},g=(t,e,s)=>e.has(t)||M("Cannot "+s),S=(t,e,s)=>(g(t,e,"read from private field"),s?s.call(t):e.get(t)),W=(t,e,s)=>e.has(t)?M("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),C=(t,e,s,i)=>(g(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),$=(t,e,s)=>(g(t,e,"access private method"),s);Object.defineProperties(exports,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const j=require("../../shared/is-object.cjs"),A=require("../../shared/env.cjs"),q=require("../reactivity/observe.cjs"),N=require("../renderer/renderIR.cjs"),E=Symbol.for("solely.manifest"),x=class extends HTMLElement{constructor(l={}){var f;super(),W(this,u),W(this,t),W(this,e),W(this,s),W(this,i),W(this,n),W(this,h),W(this,a,!1),W(this,o,!1),W(this,r,!1),W(this,c,!1);const p=this.constructor;C(this,t,p[E]||{tagName:"base-element"});const v=S(this,t);C(this,n,(null==(f=v.shadowDOM)?void 0:f.use)?this.attachShadow({mode:v.shadowDOM.mode||"open"}):this),$(this,u,d).call(this,l),$(this,u,b).call(this,v),queueMicrotask(()=>$(this,u,w).call(this))}static get observedAttributes(){const t=this[E];return(null==t?void 0:t.propMap)?Array.from(t.propMap.keys()):[]}get $data(){return S(this,i)}set $data(t){var e;j.isObject(t)||(t={}),null==(e=S(this,h))||e.call(this),$(this,u,d).call(this,t),$(this,u,v).call(this)}refresh(){$(this,u,v).call(this)}connectedCallback(){var i;const h=this.constructor.upgradeProps;let a;a=Array.isArray(h)?h.includes("$data")?h:[...h,"$data"]:["$data"],$(this,u,l).call(this,a),$(this,u,w).call(this);const o=S(this,t);if((o.className||o.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),$(this,u,k).call(this),o.propMap&&j.isObject(this.$data))for(const[t,e]of o.propMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),n=$(this,u,p).call(this,i,e.default,e.type);this.$data[s]=n}else"default"in e&&(this.$data[s]=e.default)}S(this,s)&&C(this,e,N.createRender(S(this,s),S(this,n),this)),this.mounted(),null==(i=this.onInit)||i.call(this)}disconnectedCallback(){var t,s,i;this.unmounted(),null==(t=S(this,h))||t.call(this),C(this,h,void 0),null==(i=null==(s=S(this,e))?void 0:s.destroy)||i.call(s),C(this,e,null)}attributeChangedCallback(e,s,i){var n;if(s===i||!j.isObject(this.$data))return;const h=null==(n=S(this,t).propMap)?void 0:n.get(e);if(!h)return;const a=h.name,o=this.$data[a],c=$(this,u,p).call(this,i,h.default??o,h.type);this.$data[a]=c,C(this,r,!0),this.attributeChanged(e,o,c)}emit(t,e,s){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};var O;t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,n=new WeakMap,h=new WeakMap,a=new WeakMap,o=new WeakMap,r=new WeakMap,c=new WeakMap,u=new WeakSet,l=function(t){for(const e of t)if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this[e]=t}},d=function(e){const{proxy:s,dispose:n}=q.observe(e,e=>{var s,i;if("set"===e.type){const{key:n,newValue:h}=e,a=S(this,t),o=String(n),r=(null==(s=a.propMap)?void 0:s.get(o.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()))||Array.from((null==(i=a.propMap)?void 0:i.values())||[]).find(t=>t.name===o);(null==r?void 0:r.reflect)&&$(this,u,f).call(this,r,h)}this.emit("change",{source:"state",...e}),$(this,u,v).call(this)});C(this,i,s),C(this,h,n)},f=function(t,e){const s=t.name.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}},b=function(t){t.ir&&C(this,s,t.ir)},p=function(t,e,s){if(null===t)return"boolean"===s?e??!1:e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch{return e}default:return t}},v=function(){!S(this,o)&&S(this,e)&&(C(this,o,!0),queueMicrotask(()=>{C(this,o,!1),$(this,u,m).call(this)}))},m=function(){!S(this,a)&&this.isConnected&&(C(this,a,!0),S(this,r)&&this.beforeAttributesUpdate(),this.beforeUpdate(),S(this,e).update(),this.updated(),S(this,r)&&(this.afterAttributesUpdate(),C(this,r,!1)),C(this,a,!1))},k=function(){const e=S(this,t);if(!e.styles)return;const s=S(this,n);if(e.sheet&&s instanceof ShadowRoot&&"adoptedStyleSheets"in s)return void(s.adoptedStyleSheets.includes(e.sheet)||(s.adoptedStyleSheets=[...s.adoptedStyleSheets,e.sheet]));const i=s instanceof ShadowRoot?s:document.head,h=`solely-style-${e.tagName}`;if(!i.querySelector(`#${h}`)){const t=document.createElement("style");t.id=h,t.textContent=e.styles,i.appendChild(t)}},w=function(){S(this,c)||(C(this,c,!0),this.created())},((t,e,s)=>{e in t?y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(x,"symbol"!=typeof(O="upgradeProps")?O+"":O,undefined),(()=>{if(A.IS_DEV){const t=customElements.define,e=new WeakSet;customElements.define=function(s,i,n){if(x.isPrototypeOf(i)&&!e.has(i)){e.add(i);const t=i.prototype,s=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const e of s)t[e],x.prototype[e]}return t.call(this,s,i,n)}}})();let R=x;exports.default=R;
@@ -0,0 +1 @@
1
+ var t,s,e,i,n,h,o,a,r,c,l,u,d,f,b,m,p,v,k,w,y=Object.defineProperty,g=t=>{throw TypeError(t)},M=(t,s,e)=>s.has(t)||g("Cannot "+e),W=(t,s,e)=>(M(t,s,"read from private field"),e?e.call(t):s.get(t)),C=(t,s,e)=>s.has(t)?g("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,e),S=(t,s,e,i)=>(M(t,s,"write to private field"),i?i.call(t,e):s.set(t,e),e),$=(t,s,e)=>(M(t,s,"access private method"),e);import{isObject as j}from"../../shared/is-object.js";import{IS_DEV as A}from"../../shared/env.js";import{observe as N}from"../reactivity/observe.js";import{createRender as E}from"../renderer/renderIR.js";const x=Symbol.for("solely.manifest"),O=class extends HTMLElement{constructor(u={}){var f;super(),C(this,l),C(this,t),C(this,s),C(this,e),C(this,i),C(this,n),C(this,h),C(this,o,!1),C(this,a,!1),C(this,r,!1),C(this,c,!1);const m=this.constructor;S(this,t,m[x]||{tagName:"base-element"});const p=W(this,t);S(this,n,(null==(f=p.shadowDOM)?void 0:f.use)?this.attachShadow({mode:p.shadowDOM.mode||"open"}):this),$(this,l,d).call(this,u),$(this,l,b).call(this,p),queueMicrotask(()=>$(this,l,w).call(this))}static get observedAttributes(){const t=this[x];return(null==t?void 0:t.propMap)?Array.from(t.propMap.keys()):[]}get $data(){return W(this,i)}set $data(t){var s;j(t)||(t={}),null==(s=W(this,h))||s.call(this),$(this,l,d).call(this,t),$(this,l,p).call(this)}refresh(){$(this,l,p).call(this)}connectedCallback(){var i;const h=this.constructor.upgradeProps;let o;o=Array.isArray(h)?h.includes("$data")?h:[...h,"$data"]:["$data"],$(this,l,u).call(this,o),$(this,l,w).call(this);const a=W(this,t);if((a.className||a.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),$(this,l,k).call(this),a.propMap&&j(this.$data))for(const[t,s]of a.propMap){const e=s.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),n=$(this,l,m).call(this,i,s.default,s.type);this.$data[e]=n}else"default"in s&&(this.$data[e]=s.default)}W(this,e)&&S(this,s,E(W(this,e),W(this,n),this)),this.mounted(),null==(i=this.onInit)||i.call(this)}disconnectedCallback(){var t,e,i;this.unmounted(),null==(t=W(this,h))||t.call(this),S(this,h,void 0),null==(i=null==(e=W(this,s))?void 0:e.destroy)||i.call(e),S(this,s,null)}attributeChangedCallback(s,e,i){var n;if(e===i||!j(this.$data))return;const h=null==(n=W(this,t).propMap)?void 0:n.get(s);if(!h)return;const o=h.name,a=this.$data[o],c=$(this,l,m).call(this,i,h.default??a,h.type);this.$data[o]=c,S(this,r,!0),this.attributeChanged(s,a,c)}emit(t,s,e){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:s,...e}))}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,s,e){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};var R;t=new WeakMap,s=new WeakMap,e=new WeakMap,i=new WeakMap,n=new WeakMap,h=new WeakMap,o=new WeakMap,a=new WeakMap,r=new WeakMap,c=new WeakMap,l=new WeakSet,u=function(t){for(const s of t)if(this.hasOwnProperty(s)){const t=this[s];delete this[s],this[s]=t}},d=function(s){const{proxy:e,dispose:n}=N(s,s=>{var e,i;if("set"===s.type){const{key:n,newValue:h}=s,o=W(this,t),a=String(n),r=(null==(e=o.propMap)?void 0:e.get(a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()))||Array.from((null==(i=o.propMap)?void 0:i.values())||[]).find(t=>t.name===a);(null==r?void 0:r.reflect)&&$(this,l,f).call(this,r,h)}this.emit("change",{source:"state",...s}),$(this,l,p).call(this)});S(this,i,e),S(this,h,n)},f=function(t,s){const e=t.name.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();if("boolean"===t.type)s?this.setAttribute(e,""):this.removeAttribute(e);else{const t="object"==typeof s?JSON.stringify(s):String(s);this.setAttribute(e,t)}},b=function(t){t.ir&&S(this,e,t.ir)},m=function(t,s,e){if(null===t)return"boolean"===e?s??!1:s;switch(e){case"boolean":return!0;case"number":{const e=Number(t);return isNaN(e)?s:e}case"object":try{return JSON.parse(t)}catch{return s}default:return t}},p=function(){!W(this,a)&&W(this,s)&&(S(this,a,!0),queueMicrotask(()=>{S(this,a,!1),$(this,l,v).call(this)}))},v=function(){!W(this,o)&&this.isConnected&&(S(this,o,!0),W(this,r)&&this.beforeAttributesUpdate(),this.beforeUpdate(),W(this,s).update(),this.updated(),W(this,r)&&(this.afterAttributesUpdate(),S(this,r,!1)),S(this,o,!1))},k=function(){const s=W(this,t);if(!s.styles)return;const e=W(this,n);if(s.sheet&&e instanceof ShadowRoot&&"adoptedStyleSheets"in e)return void(e.adoptedStyleSheets.includes(s.sheet)||(e.adoptedStyleSheets=[...e.adoptedStyleSheets,s.sheet]));const i=e instanceof ShadowRoot?e:document.head,h=`solely-style-${s.tagName}`;if(!i.querySelector(`#${h}`)){const t=document.createElement("style");t.id=h,t.textContent=s.styles,i.appendChild(t)}},w=function(){W(this,c)||(S(this,c,!0),this.created())},((t,s,e)=>{s in t?y(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e})(O,"symbol"!=typeof(R="upgradeProps")?R+"":R,undefined),(()=>{if(A){const t=customElements.define,s=new WeakSet;customElements.define=function(e,i,n){if(O.isPrototypeOf(i)&&!s.has(i)){s.add(i);const t=i.prototype,e=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const s of e)t[s],O.prototype[s]}return t.call(this,e,i,n)}}})();let U=O;export{U as default};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/env.cjs"),t=require("../../compiler/parser/parser.cjs"),r=require("../../compiler/ir/buildIR.cjs"),s=Symbol.for("solely.manifest");exports.CustomElement=n=>{const o=n;return n=>{const{tagName:c}=o;if(customElements.get(c))return e.IS_DEV,n;if("string"!=typeof o.template||o.ir){if(o.template&&!o.ir&&"object"==typeof o.template&&null!==o.template){const t=o.template;"root"===t.t&&Array.isArray(t.fns)&&Array.isArray(t.n)&&(o.ir=t,e.IS_DEV)}}else if(o.template.trim())try{const e=t.parseHtml(o.template);o.ir=r.buildIR(e,{source:o.template,filename:c})}catch(a){a instanceof Error||new Error(String(a))}else e.IS_DEV;if(o.styles&&!o.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(o.styles),o.sheet=e)}catch(a){e.IS_DEV}if(o.props&&!o.propMap){const e=new Map;o.props.forEach(t=>{const r="string"==typeof t?{name:t}:t,s=r.name.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());e.set(s,{...r,name:n})}),o.propMap=e}class i extends n{}return i[s]=o,customElements.define(c,i),i}};
@@ -19,7 +19,7 @@ export interface PropDescriptor {
19
19
  */
20
20
  export interface Manifest {
21
21
  /** HTML 模板字符串 */
22
- template?: string | Function;
22
+ template?: string | IRRoot;
23
23
  /** 组件样式(CSS 字符串) */
24
24
  styles?: string;
25
25
  /** 支持字符串或对象形式 */
@@ -0,0 +1 @@
1
+ import{IS_DEV as e}from"../../shared/env.js";import{parseHtml as t}from"../../compiler/parser/parser.js";import{buildIR as r}from"../../compiler/ir/buildIR.js";const o=Symbol.for("solely.manifest"),n=e=>{const n=e;return e=>{const{tagName:s}=n;if(customElements.get(s))return e;if("string"!=typeof n.template||n.ir){if(n.template&&!n.ir&&"object"==typeof n.template&&null!==n.template){const e=n.template;"root"===e.t&&Array.isArray(e.fns)&&Array.isArray(e.n)&&(n.ir=e)}}else if(n.template.trim())try{const e=t(n.template);n.ir=r(e,{source:n.template,filename:s})}catch(c){c instanceof Error||new Error(String(c))}if(n.styles&&!n.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(n.styles),n.sheet=e)}catch(c){}if(n.props&&!n.propMap){const e=new Map;n.props.forEach(t=>{const r="string"==typeof t?{name:t}:t,o=r.name.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=o.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());e.set(o,{...r,name:n})}),n.propMap=e}class i extends e{}return i[o]=n,customElements.define(s,i),i}};export{n as CustomElement};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./component/base-element.cjs"),r=require("./reactivity/observe.cjs"),o=require("./component/decorators.cjs"),s=require("./renderer/renderIR.cjs");exports.BaseElement=e.default,exports.isProxy=r.isProxy,exports.observe=r.observe,exports.toRaw=r.toRaw,exports.CustomElement=o.CustomElement,exports.IRRenderer=s.IRRenderer,exports.createRender=s.createRender;
@@ -1,4 +1,3 @@
1
1
  export * from './reactivity';
2
2
  export * from './component';
3
3
  export * from './renderer';
4
- export * from './router';
@@ -0,0 +1 @@
1
+ import{default as e}from"./component/base-element.js";import{isProxy as r,observe as o,toRaw as t}from"./reactivity/observe.js";import{CustomElement as m}from"./component/decorators.js";import{IRRenderer as s,createRender as n}from"./renderer/renderIR.js";export{e as BaseElement,m as CustomElement,s as IRRenderer,n as createRender,r as isProxy,o as observe,t as toRaw};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/is-object.cjs"),t=Symbol("solely.raw"),r=new WeakMap,n=new WeakMap,o=new WeakMap,u=new WeakMap,s=new WeakMap;function i(e){if(e&&"object"==typeof e){const r=e[t];if(r)return r}return e}const l=e=>!(!e||"object"!=typeof e)&&(e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request);function c(e){return!(!e||!e[t])}const f=(e,t,r=new WeakMap)=>{if(e===t)return!0;if(null==e||null==t)return e===t;if("object"!=typeof e||"object"!=typeof t)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;if(r.has(e))return r.get(e)===t;if(r.set(e,t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!f(e[n],t[n],r))return!1;return!0}const n=Reflect.ownKeys(e);if(n.length!==Reflect.ownKeys(t).length)return!1;for(const o of n){if(!Reflect.has(t,o))return!1;const n=e[o],u=t[o];if(!f(n,u,r))return!1}return!0},a=e=>{const t=[];let r=e;for(;r;){const e=o.get(r);if(!e||null==e.key)break;t.unshift(e.key),r=e.parent}return t},p=(e,t)=>{if(0===t.length)return!0;const r=e.map(String).join(".");return t.some(e=>e.test(r))},y=(e,t)=>{const n=a(e);let u=e;for(;u;){const e=r.get(u);e&&e.forEach(e=>{var r;if(!e.active)return;const o=a(u),s=[...o,...n.slice(o.length)];if(!p(s,e.filterRegexes))return;const i={...t,path:s};e.throttle>0?(e.pending.push(i),e.timer||(e.timer=setTimeout(()=>{var t;if(!e.active)return;const r=[...e.pending];e.pending=[],e.timer=null,r.length>0&&(null==(t=e.onBatch)||t.call(e,r),r.forEach(t=>e.callback(t)))},e.throttle))):(null==(r=e.onBatch)||r.call(e,[i]),e.callback(i))});const s=o.get(u);u=(null==s?void 0:s.parent)||null}};exports.isProxy=c,exports.observe=function(a,p,d={}){const{throttle:h=0,onBatch:b,immediate:w=!1,deepCompare:x=!1}=d,k={callback:p,onBatch:b,throttle:h,filterRegexes:(Array.isArray(d.filter)?d.filter:d.filter?[d.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=e.replace(/\./g,"\\.").replace(/\*\*/g,"(.+)").replace(/\*/g,"[^.]+").replace(/\[\d+\]/g,"\\[\\d+\\]");return new RegExp(`^${t}$`)}),pending:[],timer:null,active:!0},m=(r,a,p)=>{if(!Object.isExtensible(r))return r;if(l(r))return r;if(r[t])return r;const d=n.get(r);if(d)return d;const h=new Proxy(r,{get(r,n,o){if(n===t)return r;if(Array.isArray(r)){const e=u.get(h);if(e&&Object.prototype.hasOwnProperty.call(e,n))return Reflect.get(e,n,o)}const s=Reflect.get(r,n,o);return"symbol"==typeof n?s:e.isObject(s)&&!l(s)?m(s,h,n):s},set(e,t,r,n){const o=e[t];if(x?f(o,r):o===r)return!0;const u=Reflect.set(e,t,r,n);return 0===(s.get(h)||0)&&(Array.isArray(o)&&Array.isArray(r)?y(h,{type:"array-replace",oldValue:o,newValue:r}):y(h,{type:"set",key:t,newValue:r,oldValue:o})),u},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=e[t],n=Reflect.deleteProperty(e,t),o=s.get(h)||0;return n&&0===o&&y(h,{type:"delete",key:t,oldValue:r}),n}});return n.set(r,h),o.set(h,{parent:a,key:p}),Array.isArray(r)&&u.set(h,((e,t)=>{const r={};return["push","pop","shift","unshift","splice"].forEach(n=>{r[n]=function(...r){if(!t)return;const o=s.get(t)||0;s.set(t,o+1);const u=e[n].apply(e,r);if(s.set(t,o),"push"===n)y(t,{type:"array-push",index:e.length-r.length,values:r});else if("unshift"===n)y(t,{type:"array-push",index:0,values:r});else if("pop"===n)y(t,{type:"array-splice",index:e.length,deleteCount:1,insert:[]});else if("shift"===n)y(t,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===n){const[e,n,...o]=r;y(t,{type:"array-splice",index:e,deleteCount:n,insert:o})}return u}}),["sort","reverse","fill","copyWithin"].forEach(n=>{r[n]=function(...r){if(!t)return;const o=s.get(t)||0;s.set(t,o+1);const u=e[n].apply(e,r);return s.set(t,o),y(t,{type:"array-reset",method:n}),u}}),["indexOf","lastIndexOf","includes"].forEach(t=>{r[t]=function(r,...n){let o=e[t].apply(e,[r,...n]);return-1!==o&&!1!==o||!c(r)||(o=e[t].apply(e,[i(r),...n])),o}}),r})(r,h)),h},R=m(a,null,null);let v=r.get(R);if(v||(v=new Set,r.set(R,v)),v.add(k),w){const t=(r,n,o=new WeakSet)=>{e.isObject(r)&&!o.has(r)&&(o.add(r),Reflect.ownKeys(r).forEach(u=>{const s=r[u];e.isObject(s)&&o.has(s)||(y(n,{type:"set",key:u,newValue:s,oldValue:void 0}),e.isObject(s)&&t(s,m(s,n,u),o))}))};t(a,R)}return{proxy:R,unobserve:()=>{k.active=!1,k.pending=[],k.timer&&(clearTimeout(k.timer),k.timer=null);const e=r.get(R);e&&e.delete(k)},resume:()=>{if(k.active)return;k.active=!0;let e=r.get(R);e||(e=new Set,r.set(R,e)),e.has(k)||e.add(k)},dispose:()=>{k.active=!1,k.pending=[],k.timer&&(clearTimeout(k.timer),k.timer=null);const e=r.get(R);e&&e.delete(k),k.callback=()=>{},k.onBatch=void 0}}},exports.toRaw=i;
@@ -0,0 +1 @@
1
+ import{isObject as e}from"../../shared/is-object.js";const t=Symbol("solely.raw"),r=new WeakMap,n=new WeakMap,o=new WeakMap,i=new WeakMap,u=new WeakMap;function l(e){if(e&&"object"==typeof e){const r=e[t];if(r)return r}return e}const s=e=>!(!e||"object"!=typeof e)&&(e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request);function f(e){return!(!e||!e[t])}const c=(e,t,r=new WeakMap)=>{if(e===t)return!0;if(null==e||null==t)return e===t;if("object"!=typeof e||"object"!=typeof t)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;if(r.has(e))return r.get(e)===t;if(r.set(e,t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!c(e[n],t[n],r))return!1;return!0}const n=Reflect.ownKeys(e);if(n.length!==Reflect.ownKeys(t).length)return!1;for(const o of n){if(!Reflect.has(t,o))return!1;const n=e[o],i=t[o];if(!c(n,i,r))return!1}return!0},a=e=>{const t=[];let r=e;for(;r;){const e=o.get(r);if(!e||null==e.key)break;t.unshift(e.key),r=e.parent}return t},p=(e,t)=>{if(0===t.length)return!0;const r=e.map(String).join(".");return t.some(e=>e.test(r))},y=(e,t)=>{const n=a(e);let i=e;for(;i;){const e=r.get(i);e&&e.forEach(e=>{var r;if(!e.active)return;const o=a(i),u=[...o,...n.slice(o.length)];if(!p(u,e.filterRegexes))return;const l={...t,path:u};e.throttle>0?(e.pending.push(l),e.timer||(e.timer=setTimeout(()=>{var t;if(!e.active)return;const r=[...e.pending];e.pending=[],e.timer=null,r.length>0&&(null==(t=e.onBatch)||t.call(e,r),r.forEach(t=>e.callback(t)))},e.throttle))):(null==(r=e.onBatch)||r.call(e,[l]),e.callback(l))});const u=o.get(i);i=(null==u?void 0:u.parent)||null}};function d(a,p,d={}){const{throttle:h=0,onBatch:w,immediate:m=!1,deepCompare:b=!1}=d,k={callback:p,onBatch:w,throttle:h,filterRegexes:(Array.isArray(d.filter)?d.filter:d.filter?[d.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=e.replace(/\./g,"\\.").replace(/\*\*/g,"(.+)").replace(/\*/g,"[^.]+").replace(/\[\d+\]/g,"\\[\\d+\\]");return new RegExp(`^${t}$`)}),pending:[],timer:null,active:!0},R=(r,a,p)=>{if(!Object.isExtensible(r))return r;if(s(r))return r;if(r[t])return r;const d=n.get(r);if(d)return d;const h=new Proxy(r,{get(r,n,o){if(n===t)return r;if(Array.isArray(r)){const e=i.get(h);if(e&&Object.prototype.hasOwnProperty.call(e,n))return Reflect.get(e,n,o)}const u=Reflect.get(r,n,o);return"symbol"==typeof n?u:e(u)&&!s(u)?R(u,h,n):u},set(e,t,r,n){const o=e[t];if(b?c(o,r):o===r)return!0;const i=Reflect.set(e,t,r,n);return 0===(u.get(h)||0)&&(Array.isArray(o)&&Array.isArray(r)?y(h,{type:"array-replace",oldValue:o,newValue:r}):y(h,{type:"set",key:t,newValue:r,oldValue:o})),i},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=e[t],n=Reflect.deleteProperty(e,t),o=u.get(h)||0;return n&&0===o&&y(h,{type:"delete",key:t,oldValue:r}),n}});return n.set(r,h),o.set(h,{parent:a,key:p}),Array.isArray(r)&&i.set(h,((e,t)=>{const r={};return["push","pop","shift","unshift","splice"].forEach(n=>{r[n]=function(...r){if(!t)return;const o=u.get(t)||0;u.set(t,o+1);const i=e[n].apply(e,r);if(u.set(t,o),"push"===n)y(t,{type:"array-push",index:e.length-r.length,values:r});else if("unshift"===n)y(t,{type:"array-push",index:0,values:r});else if("pop"===n)y(t,{type:"array-splice",index:e.length,deleteCount:1,insert:[]});else if("shift"===n)y(t,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===n){const[e,n,...o]=r;y(t,{type:"array-splice",index:e,deleteCount:n,insert:o})}return i}}),["sort","reverse","fill","copyWithin"].forEach(n=>{r[n]=function(...r){if(!t)return;const o=u.get(t)||0;u.set(t,o+1);const i=e[n].apply(e,r);return u.set(t,o),y(t,{type:"array-reset",method:n}),i}}),["indexOf","lastIndexOf","includes"].forEach(t=>{r[t]=function(r,...n){let o=e[t].apply(e,[r,...n]);return-1!==o&&!1!==o||!f(r)||(o=e[t].apply(e,[l(r),...n])),o}}),r})(r,h)),h},x=R(a,null,null);let v=r.get(x);if(v||(v=new Set,r.set(x,v)),v.add(k),m){const t=(r,n,o=new WeakSet)=>{e(r)&&!o.has(r)&&(o.add(r),Reflect.ownKeys(r).forEach(i=>{const u=r[i];e(u)&&o.has(u)||(y(n,{type:"set",key:i,newValue:u,oldValue:void 0}),e(u)&&t(u,R(u,n,i),o))}))};t(a,x)}return{proxy:x,unobserve:()=>{k.active=!1,k.pending=[],k.timer&&(clearTimeout(k.timer),k.timer=null);const e=r.get(x);e&&e.delete(k)},resume:()=>{if(k.active)return;k.active=!0;let e=r.get(x);e||(e=new Set,r.set(x,e)),e.has(k)||e.add(k)},dispose:()=>{k.active=!1,k.pending=[],k.timer&&(clearTimeout(k.timer),k.timer=null);const e=r.get(x);e&&e.delete(k),k.callback=()=>{},k.onBatch=void 0}}}export{f as isProxy,d as observe,l as toRaw};
@@ -0,0 +1 @@
1
+ "use strict";var t=Object.defineProperty,e=(e,o,s)=>((e,o,s)=>o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[o]=s)(e,"symbol"!=typeof o?o+"":o,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../types/ast.cjs"),s=require("../../shared/templateError.cjs"),n=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),l=Symbol("solely.prevStyleObj"),c={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},f={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]);function u(t){const e={},o=[[t]];for(;o.length;){const[t,s]=o.pop();if(t){if("string"==typeof t){const o=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let s;for(;null!==(s=o.exec(t));){const t=s[1].trim(),o=s[2].trim();t&&o&&(e[t]=o)}continue}if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)o.push([t[e]]);else if("object"==typeof t)for(const n in t){const i=t[n];if(null==i)continue;const r=s?`${s}-${n}`:n;"object"!=typeof i||Array.isArray(i)?e[r]=String(i):o.push([i,r])}}}return e}function d(t,e,o){const s=null==o?"":String(o),n=e.indexOf(":");if(n>0){const o=e.slice(0,n),i=c[o];if(i)return void(t.getAttributeNS(i,e)!==s&&t.setAttributeNS(i,e,s))}t.getAttribute(e)!==s&&t.setAttribute(e,s)}function m(t,e,o){const s=f[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||a.has(e))return void d(t,e,o);const n=t,i=n.tagName;if(null!=o){if("src"===s||"href"===s){const e=String(o);if(n[s]===e||t.getAttribute(s)===e)return}if("value"!==s||"INPUT"!==i&&"TEXTAREA"!==i||n.value!==o)if("boolean"!=typeof o)(t instanceof SVGElement||void 0!==n.ownerSVGElement)&&!f[e]?d(t,e,o):n[s]!==o&&(n[s]=o);else{if(n[s]===o)return;n[s]=o}}else if("boolean"==typeof n[s])!1!==n[s]&&(n[s]=!1);else{const o=n[s];""!==o&&void 0!==o&&(n[s]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class p{constructor(t,o,s={}){e(this,"nodeMap",new Map),e(this,"marker",!1),this.ir=t,this.container=o,this.scope=s}evalIR(t,e,o){var n;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,e):""}catch(r){return s.showTemplateError(r.message||r.toString(),(null==(n=this.ir.m)?void 0:n.src)||"",o,this.scope.tagName),""}}createElement(t,e){const o=t.g;return e instanceof SVGElement||"svg"===o?document.createElementNS("http://www.w3.org/2000/svg",o):document.createElement(o)}createText(t,e){const o=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createTextNode(o)}createComment(t,e){const o=t.d?this.evalIR(t.f,[e],t.o):t.x||"";return document.createComment(o)}applyAttrs(t,e,o,s=!1){const c=[],f=t;let a;f[n]||(f[n]={loops:null}),f[n].loops=o,f[i]||(f[i]=Object.create(null));let p,y=!1,b=!1;for(const r of e){const{k:e,f:l,d:u,v:v}=r;if(":class"===e){a=this.evalIR(l,[o],r.o),y=!0;continue}if(":style"===e){p=this.evalIR(l,[o],r.o),b=!0;continue}if("class"===e||"style"===e)continue;const w=e[0];if("@"===w){const o=e.slice(1),c=r.r??"user";let a=f[i][o];if(a||(a=f[i][o]={model:[],user:[]},t.addEventListener(o,t=>{for(const e of a.model)e(t);for(const e of a.user)e(t)})),!s){const t=t=>this.evalIR(l,[t,f[n].loops],r.o);a[c].push(t)}continue}if("mounted"===e){s||requestAnimationFrame(()=>this.evalIR(l,[t,o],r.o));continue}if("updated"===e){s&&requestAnimationFrame(()=>this.evalIR(l,[t,o],r.o));continue}if("ref"===e&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=t;continue}const g=u?this.evalIR(l,[o],r.o):v??"";if(":"===w){const o=e.slice(1);"SELECT"===t.tagName&&h.has(o)?c.push(()=>m(t,o,g)):m(t,o,g)}else s||d(t,e,String(g))}return y&&((t,e)=>{const o=t,s=o[r],n=function(t){const e={},o=[t];for(;o.length;){const t=o.pop();if(t)if("string"==typeof t){const o=t.split(" ");for(let t=0;t<o.length;t++){const s=o[t].trim();s&&(e[s]=!0)}}else if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)o.push(t[e]);else if("object"==typeof t)for(const o in t)t[o]&&(e[o]=!0)}return e}(e);if(!s){for(const e in n)t.classList.add(e);return void(o[r]=n)}let i=!1;for(const r in s)n[r]||(t.classList.remove(r),i=!0);for(const r in n)s[r]||(t.classList.add(r),i=!0);i&&(o[r]=n)})(t,a),b&&((t,e)=>{const o=t,s=u(e),n=o[l];if(!n){for(const e in s){const o=s[e];e.startsWith("--")?t.style.setProperty(e,o):t.style[e]=o}return void(o[l]=s)}let i=!1;for(const r in n)r in s||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in s){const e=s[r];e!==n[r]&&(r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e,i=!0)}i&&(o[l]=s)})(t,p),c}updateNode(t,e,o){const s=e.d?this.evalIR(e.f,[o],e.o):e.x||"";e.d&&t.textContent!==s&&(t.textContent=s)}irToNode(t,e,s,n,i){var r,l,c,f;const a=s+"-"+e,h=this.nodeMap.get(a);let d;if(h){d=h.node,h.marker=this.marker;let e=[];t.d&&(t.t===o.ASTType.Element?e=this.applyAttrs(d,t.a??[],i,!0):this.updateNode(d,t,i)),null==(r=t.c)||r.forEach((t,e)=>{this.irToNode(t,e,a,d,i)}),e.forEach(t=>t())}else switch(t.t){case o.ASTType.Element:d=this.createElement(t,n),function(t,e){var o;const s=null==(o=e.a)?void 0:o.find(t=>"class"===t.k&&!t.d);(null==s?void 0:s.v)&&t.setAttribute("class",s.v)}(d,t),function(t,e){var o;if(!t.style)return;const s=null==(o=e.a)?void 0:o.find(t=>"style"===t.k&&!t.d),n=s?u(s.v):{};for(const i in n){const e=n[i];i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e}}(d,t);const e=this.applyAttrs(d,t.a??[],i);n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker}),null==(l=t.c)||l.forEach((t,e)=>{this.irToNode(t,e,a,d,i)}),e.forEach(t=>t());break;case o.ASTType.Text:d=this.createText(t,i),n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case o.ASTType.Comment:d=this.createComment(t,i),n.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case o.ASTType.For:{const e=`${a}-end`;let s=null==(c=this.nodeMap.get(e))?void 0:c.node;s?this.nodeMap.get(e).marker=this.marker:(s=document.createComment(`for:${a}`),n.appendChild(s),this.nodeMap.set(e,{irNode:{t:o.ASTType.Comment},node:s,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],l=document.createDocumentFragment();r.forEach((e,o)=>{var s;const n=[...i,{itmVal:e,idxVal:o}];null==(s=t.c)||s.forEach((t,e)=>{this.irToNode(t,e,`${a}-for-${o}`,l,n)})}),s.parentNode.insertBefore(l,s);break}case o.ASTType.Conditional:{const e=`${a}-end`;let o=null==(f=this.nodeMap.get(e))?void 0:f.node;o?this.nodeMap.get(e).marker=this.marker:(o=document.createComment(`if:${a}`),n.appendChild(o),this.nodeMap.set(e,{irNode:{},node:o,loops:i,marker:this.marker}));for(let s=0;s<(t.b||[]).length;s++){const e=t.b[s];if(null===e.f||this.evalIR(e.f,[i],e.o)){const t=document.createDocumentFragment();e.c.forEach((e,o)=>{this.irToNode(e,o,`${a}-if-${s}`,t,i)}),o.parentNode.insertBefore(t,o);break}}break}}}cleanupOldNodes(){for(const[t,e]of this.nodeMap.entries())if(e.marker!==this.marker){const{irNode:o,node:s,loops:n}=e;if(o.a){const t=o.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[s,n],t.o)});const e=o.a.find(t=>"ref"===t.k);e&&e.v&&delete this.scope.$refs[e.v]}null==s||s.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear()}}exports.IRRenderer=p,exports.createRender=(t,e,o={})=>{const s=new p(t,e,o);return s.mount(),{update:()=>s.update(),destroy:()=>s.destroy()}};
@@ -0,0 +1 @@
1
+ var t=Object.defineProperty,o=(o,e,n)=>((o,e,n)=>e in o?t(o,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[e]=n)(o,"symbol"!=typeof e?e+"":e,n);import{ASTType as e}from"../../types/ast.js";import{showTemplateError as n}from"../../shared/templateError.js";const s=Symbol("solely.irCtx"),i=Symbol("solely.irEvents"),r=Symbol("solely.prevClassObj"),l=Symbol("solely.prevStyleObj"),c={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},f={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]);function u(t){const o={},e=[[t]];for(;e.length;){const[t,n]=e.pop();if(t){if("string"==typeof t){const e=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let n;for(;null!==(n=e.exec(t));){const t=n[1].trim(),e=n[2].trim();t&&e&&(o[t]=e)}continue}if(Array.isArray(t))for(let o=t.length-1;o>=0;o--)e.push([t[o]]);else if("object"==typeof t)for(const s in t){const i=t[s];if(null==i)continue;const r=n?`${n}-${s}`:s;"object"!=typeof i||Array.isArray(i)?o[r]=String(i):e.push([i,r])}}}return o}function d(t,o,e){const n=null==e?"":String(e),s=o.indexOf(":");if(s>0){const e=o.slice(0,s),i=c[e];if(i)return void(t.getAttributeNS(i,o)!==n&&t.setAttributeNS(i,o,n))}t.getAttribute(o)!==n&&t.setAttribute(o,n)}function m(t,o,e){const n=f[o]||o;if(o.startsWith("data-")||o.startsWith("aria-")||a.has(o))return void d(t,o,e);const s=t,i=s.tagName;if(null!=e){if("src"===n||"href"===n){const o=String(e);if(s[n]===o||t.getAttribute(n)===o)return}if("value"!==n||"INPUT"!==i&&"TEXTAREA"!==i||s.value!==e)if("boolean"!=typeof e)(t instanceof SVGElement||void 0!==s.ownerSVGElement)&&!f[o]?d(t,o,e):s[n]!==e&&(s[n]=e);else{if(s[n]===e)return;s[n]=e}}else if("boolean"==typeof s[n])!1!==s[n]&&(s[n]=!1);else{const e=s[n];""!==e&&void 0!==e&&(s[n]=""),t.hasAttribute(o)&&t.removeAttribute(o)}}class p{constructor(t,e,n={}){o(this,"nodeMap",new Map),o(this,"marker",!1),this.ir=t,this.container=e,this.scope=n}evalIR(t,o,e){var s;const i=this.ir.fns[t-1];try{return i?i.apply(this.scope,o):""}catch(r){return n(r.message||r.toString(),(null==(s=this.ir.m)?void 0:s.src)||"",e,this.scope.tagName),""}}createElement(t,o){const e=t.g;return o instanceof SVGElement||"svg"===e?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)}createText(t,o){const e=t.d?this.evalIR(t.f,[o],t.o):t.x||"";return document.createTextNode(e)}createComment(t,o){const e=t.d?this.evalIR(t.f,[o],t.o):t.x||"";return document.createComment(e)}applyAttrs(t,o,e,n=!1){const c=[],f=t;let a;f[s]||(f[s]={loops:null}),f[s].loops=e,f[i]||(f[i]=Object.create(null));let p,y=!1,v=!1;for(const r of o){const{k:o,f:l,d:u,v:b}=r;if(":class"===o){a=this.evalIR(l,[e],r.o),y=!0;continue}if(":style"===o){p=this.evalIR(l,[e],r.o),v=!0;continue}if("class"===o||"style"===o)continue;const w=o[0];if("@"===w){const e=o.slice(1),c=r.r??"user";let a=f[i][e];if(a||(a=f[i][e]={model:[],user:[]},t.addEventListener(e,t=>{for(const o of a.model)o(t);for(const o of a.user)o(t)})),!n){const t=t=>this.evalIR(l,[t,f[s].loops],r.o);a[c].push(t)}continue}if("mounted"===o){n||requestAnimationFrame(()=>this.evalIR(l,[t,e],r.o));continue}if("updated"===o){n&&requestAnimationFrame(()=>this.evalIR(l,[t,e],r.o));continue}if("ref"===o&&b){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[b]=t;continue}const g=u?this.evalIR(l,[e],r.o):b??"";if(":"===w){const e=o.slice(1);"SELECT"===t.tagName&&h.has(e)?c.push(()=>m(t,e,g)):m(t,e,g)}else n||d(t,o,String(g))}return y&&((t,o)=>{const e=t,n=e[r],s=function(t){const o={},e=[t];for(;e.length;){const t=e.pop();if(t)if("string"==typeof t){const e=t.split(" ");for(let t=0;t<e.length;t++){const n=e[t].trim();n&&(o[n]=!0)}}else if(Array.isArray(t))for(let o=t.length-1;o>=0;o--)e.push(t[o]);else if("object"==typeof t)for(const e in t)t[e]&&(o[e]=!0)}return o}(o);if(!n){for(const o in s)t.classList.add(o);return void(e[r]=s)}let i=!1;for(const r in n)s[r]||(t.classList.remove(r),i=!0);for(const r in s)n[r]||(t.classList.add(r),i=!0);i&&(e[r]=s)})(t,a),v&&((t,o)=>{const e=t,n=u(o),s=e[l];if(!s){for(const o in n){const e=n[o];o.startsWith("--")?t.style.setProperty(o,e):t.style[o]=e}return void(e[l]=n)}let i=!1;for(const r in s)r in n||(r.startsWith("--")?t.style.removeProperty(r):t.style[r]="",i=!0);for(const r in n){const o=n[r];o!==s[r]&&(r.startsWith("--")?t.style.setProperty(r,o):t.style[r]=o,i=!0)}i&&(e[l]=n)})(t,p),c}updateNode(t,o,e){const n=o.d?this.evalIR(o.f,[e],o.o):o.x||"";o.d&&t.textContent!==n&&(t.textContent=n)}irToNode(t,o,n,s,i){var r,l,c,f;const a=n+"-"+o,h=this.nodeMap.get(a);let d;if(h){d=h.node,h.marker=this.marker;let o=[];t.d&&(t.t===e.Element?o=this.applyAttrs(d,t.a??[],i,!0):this.updateNode(d,t,i)),null==(r=t.c)||r.forEach((t,o)=>{this.irToNode(t,o,a,d,i)}),o.forEach(t=>t())}else switch(t.t){case e.Element:d=this.createElement(t,s),function(t,o){var e;const n=null==(e=o.a)?void 0:e.find(t=>"class"===t.k&&!t.d);(null==n?void 0:n.v)&&t.setAttribute("class",n.v)}(d,t),function(t,o){var e;if(!t.style)return;const n=null==(e=o.a)?void 0:e.find(t=>"style"===t.k&&!t.d),s=n?u(n.v):{};for(const i in s){const o=s[i];i.startsWith("--")?t.style.setProperty(i,o):t.style[i]=o}}(d,t);const o=this.applyAttrs(d,t.a??[],i);s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker}),null==(l=t.c)||l.forEach((t,o)=>{this.irToNode(t,o,a,d,i)}),o.forEach(t=>t());break;case e.Text:d=this.createText(t,i),s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case e.Comment:d=this.createComment(t,i),s.appendChild(d),this.nodeMap.set(a,{irNode:t,node:d,loops:i,marker:this.marker});break;case e.For:{const o=`${a}-end`;let n=null==(c=this.nodeMap.get(o))?void 0:c.node;n?this.nodeMap.get(o).marker=this.marker:(n=document.createComment(`for:${a}`),s.appendChild(n),this.nodeMap.set(o,{irNode:{t:e.Comment},node:n,loops:i,marker:this.marker}));const r=this.evalIR(t.f,[i],t.o)||[],l=document.createDocumentFragment();r.forEach((o,e)=>{var n;const s=[...i,{itmVal:o,idxVal:e}];null==(n=t.c)||n.forEach((t,o)=>{this.irToNode(t,o,`${a}-for-${e}`,l,s)})}),n.parentNode.insertBefore(l,n);break}case e.Conditional:{const o=`${a}-end`;let e=null==(f=this.nodeMap.get(o))?void 0:f.node;e?this.nodeMap.get(o).marker=this.marker:(e=document.createComment(`if:${a}`),s.appendChild(e),this.nodeMap.set(o,{irNode:{},node:e,loops:i,marker:this.marker}));for(let n=0;n<(t.b||[]).length;n++){const o=t.b[n];if(null===o.f||this.evalIR(o.f,[i],o.o)){const t=document.createDocumentFragment();o.c.forEach((o,e)=>{this.irToNode(o,e,`${a}-if-${n}`,t,i)}),e.parentNode.insertBefore(t,e);break}}break}}}cleanupOldNodes(){for(const[t,o]of this.nodeMap.entries())if(o.marker!==this.marker){const{irNode:e,node:n,loops:s}=o;if(e.a){const t=e.a.find(t=>"unmounted"===t.k);t&&requestAnimationFrame(()=>{this.evalIR(t.f,[n,s],t.o)});const o=e.a.find(t=>"ref"===t.k);o&&o.v&&delete this.scope.$refs[o.v]}null==n||n.remove(),this.nodeMap.delete(t)}}mount(){this.marker=!this.marker,this.ir.n.forEach((t,o)=>{this.irToNode(t,o,"root",this.container,[])}),this.cleanupOldNodes()}update(){this.marker=!this.marker,this.ir.n.forEach((t,o)=>{this.irToNode(t,o,"root",this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear()}}const y=(t,o,e={})=>{const n=new p(t,o,e);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{p as IRRenderer,y as createRender};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(()=>{var o,e;if("undefined"!=typeof window){if(null==(o=window.location)?void 0:o.search.includes("debug"))return!0;if(!0===globalThis.__DEBUG__||!0===globalThis.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(e=window.location)?void 0:e.hostname)||""))})(),e=!o;exports.IS_DEV=o,exports.IS_PROD=e;
@@ -0,0 +1 @@
1
+ const n=(()=>{var n,o;if("undefined"!=typeof window){if(null==(n=window.location)?void 0:n.search.includes("debug"))return!0;if(!0===globalThis.__DEBUG__||!0===globalThis.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(o=window.location)?void 0:o.hostname)||""))})(),o=!n;export{n as IS_DEV,o as IS_PROD};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{o:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=new Set(["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"]);exports.default=o;
@@ -0,0 +1 @@
1
+ const o=new Set(["onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragexit","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onwheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting"]);export{o as default};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.createFunction=function(t){if(""===t[t.length-1].trim())throw new Error("Function body cannot be empty");return new Function(...t)};
@@ -0,0 +1 @@
1
+ function n(n){if(""===n[n.length-1].trim())throw new Error("Function body cannot be empty");return new Function(...n)}export{n as createFunction};
@@ -0,0 +1,6 @@
1
+ import { IRLocal } from '../types';
2
+ export type GenType = "template" | "handler" | "expression" | "lifecycle";
3
+ /**
4
+ * 主入口:生成可执行的函数(支持上层捕获异常)
5
+ */
6
+ export declare function genFunction(code: string, type: GenType, locals: IRLocal[]): Function;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./functions.cjs"),e=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;exports.genFunction=function(o,t,s){if(!(null==o?void 0:o.trim()))return()=>"";const{processed:l,error:c}=function(r,o){if(!(null==r?void 0:r.trim()))return{processed:""};if(e.test(r))return{processed:r,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===o)try{return{processed:r.replace(n,(r,e)=>`\${${e.trim()}}`)}}catch(t){return{processed:r,error:`Template parse error: ${t instanceof Error?t.message:String(t)}`}}return{processed:r}}(o,t);if(c)return function(){throw new Error(`[Compile Error] ${c} Original: ${o}`)};try{const e=function(r,e){switch(e){case"template":return`return \`${r}\`;`;case"expression":return`return (${r});`;case"handler":case"lifecycle":return(n=r).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(l,t),{loopValues:n,loopIndices:o}=function(r){return r.length?{loopValues:`var [${r.map(r=>r.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${r.map(r=>r.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),c=function(r,e,n,o){const t="lifecycle"===r?["el","loops"]:"handler"===r?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===r?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${o}\n ${e}\n `.replace(/^\s+|\s+$/gm,"");return t.push(s),t}(t,e,n,o);return r.createFunction(c)}catch(i){const r=i instanceof Error?i.message:String(i);return function(){throw new Error(`[Parse Error] ${r} Original: ${o}`)}}};
@@ -2,5 +2,6 @@ import { IRLocal } from '../types';
2
2
  export type GenType = "template" | "handler" | "expression" | "lifecycle";
3
3
  /**
4
4
  * 主入口:生成可执行的函数(支持上层捕获异常)
5
+ * 注意:缓存逻辑由上层 FunctionCompiler 统一管理,此处不做重复缓存
5
6
  */
6
7
  export declare function genFunction(code: string, type: GenType, locals: IRLocal[]): Function;
@@ -0,0 +1 @@
1
+ import{createFunction as r}from"./functions.js";const e=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;function o(o,t,s){if(!(null==o?void 0:o.trim()))return()=>"";const{processed:l,error:c}=function(r,o){if(!(null==r?void 0:r.trim()))return{processed:""};if(e.test(r))return{processed:r,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===o)try{return{processed:r.replace(n,(r,e)=>`\${${e.trim()}}`)}}catch(t){return{processed:r,error:`Template parse error: ${t instanceof Error?t.message:String(t)}`}}return{processed:r}}(o,t);if(c)return function(){throw new Error(`[Compile Error] ${c} Original: ${o}`)};try{const e=function(r,e){switch(e){case"template":return`return \`${r}\`;`;case"expression":return`return (${r});`;case"handler":case"lifecycle":return(n=r).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(l,t),{loopValues:n,loopIndices:o}=function(r){return r.length?{loopValues:`var [${r.map(r=>r.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${r.map(r=>r.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),c=function(r,e,n,o){const t="lifecycle"===r?["el","loops"]:"handler"===r?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===r?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${o}\n ${e}\n `.replace(/^\s+|\s+$/gm,"");return t.push(s),t}(t,e,n,o);return r(c)}catch(i){const r=i instanceof Error?i.message:String(i);return function(){throw new Error(`[Parse Error] ${r} Original: ${o}`)}}}export{o as genFunction};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./templateError.cjs"),r=require("./gen-function.cjs"),s=require("./functions.cjs"),t=require("./event-listeners.cjs"),o=require("./is-object.cjs"),c=require("./url.cjs"),u=require("./env.cjs");exports.showTemplateError=e.showTemplateError,exports.genFunction=r.genFunction,exports.createFunction=s.createFunction,exports.listeners=t.default,exports.isObject=o.isObject,exports.parseHashUrl=c.parseHashUrl,exports.IS_DEV=u.IS_DEV,exports.IS_PROD=u.IS_PROD;
@@ -0,0 +1 @@
1
+ import{showTemplateError as r}from"./templateError.js";import{genFunction as o}from"./gen-function.js";import{createFunction as t}from"./functions.js";import{default as m}from"./event-listeners.js";import{isObject as s}from"./is-object.js";import{parseHashUrl as e}from"./url.js";import{IS_DEV as i,IS_PROD as f}from"./env.js";export{i as IS_DEV,f as IS_PROD,t as createFunction,o as genFunction,s as isObject,m as listeners,e as parseHashUrl,r as showTemplateError};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.isObject=e=>{if(null===e)return!1;if("object"!=typeof e)return!1;const t=Object.prototype.toString.call(e);return!["[object Function]","[object Date]","[object RegExp]","[object Map]","[object Set]","[object WeakMap]","[object WeakSet]"].includes(t)};
@@ -0,0 +1 @@
1
+ const e=e=>{if(null===e)return!1;if("object"!=typeof e)return!1;const t=Object.prototype.toString.call(e);return!["[object Function]","[object Date]","[object RegExp]","[object Map]","[object Set]","[object WeakMap]","[object WeakSet]"].includes(t)};export{e as isObject};
@@ -0,0 +1 @@
1
+ "use strict";function t(t){let n=0;for(let e=0;e<t.length;){const o=t.codePointAt(e);"\t"!==t[e]?(n+=o>=9472&&o<=9599||o>255?2:1,e+=o>65535?2:1):(n+=4,e++)}return n}function n(t,n={}){const{lineIndex:e=0,totalLines:o=1}=n,i=Math.max(1,Math.floor(t));return(o<=1||0===e?"^":"~").repeat(i)}Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.showTemplateError=function(e,o="",i,l="component"){var r;if((null==e?void 0:e.message)??String(e),!o||!(null==i?void 0:i.loc)||i.loc.length<2)return void(null==i||i.expr);const s=i.loc;let c=s[0]||0,u=s[1]||0;c|=0,u|=0,c<1&&(c=1),u<1&&(u=1);const f=o.split("\n");if(c>f.length)return;const a=c-1,M=Math.max(0,a-3),d=Math.min(f.length-1,a+3),h=String(d+1).length,v=(null==(r=i.expr)?void 0:r.trim())??"",S=v?v.split("\n"):[],g=v?Math.max(...S.map(t)):0,x=S.length>1;for(let p=M;p<=d;p++){const e=f[p],o=String(p+1).padStart(h," ");if(p!==a)continue;const i=t(e.slice(0,Math.max(0,u-1)));if(" ".repeat(h+3),o.padEnd(h," "),x)for(let l=0;l<S.length;l++){const e=S[l],o=a+l;let r=0;if(0===l)r=i;else if(o<f.length){const n=f[o],e=n.search(/\S/);r=t(-1===e?n:n.slice(0,e))}n(Math.max(1,t(e.trim())),{lineIndex:l,totalLines:S.length})," ".repeat(r),0===l||o<f.length&&(String(o+1).padEnd(h," "),f[o])}else" ".repeat(i),n(g||1)}};
@@ -0,0 +1 @@
1
+ function t(t){let n=0;for(let o=0;o<t.length;){const e=t.codePointAt(o);"\t"!==t[o]?(n+=e>=9472&&e<=9599||e>255?2:1,o+=e>65535?2:1):(n+=4,o++)}return n}function n(t,n={}){const{lineIndex:o=0,totalLines:e=1}=n,i=Math.max(1,Math.floor(t));return(e<=1||0===o?"^":"~").repeat(i)}function o(o,e="",i,l="component"){var r;if((null==o?void 0:o.message)??String(o),!e||!(null==i?void 0:i.loc)||i.loc.length<2)return void(null==i||i.expr);const c=i.loc;let s=c[0]||0,f=c[1]||0;s|=0,f|=0,s<1&&(s=1),f<1&&(f=1);const u=e.split("\n");if(s>u.length)return;const a=s-1,h=Math.max(0,a-3),M=Math.min(u.length-1,a+3),d=String(M+1).length,v=(null==(r=i.expr)?void 0:r.trim())??"",S=v?v.split("\n"):[],g=v?Math.max(...S.map(t)):0,x=S.length>1;for(let p=h;p<=M;p++){const o=u[p],e=String(p+1).padStart(d," ");if(p!==a)continue;const i=t(o.slice(0,Math.max(0,f-1)));" ".repeat(d+3);if(e.padEnd(d," "),x)for(let l=0;l<S.length;l++){const o=S[l],e=a+l;let r=0;if(0===l)r=i;else if(e<u.length){const n=u[e],o=n.search(/\S/);r=t(-1===o?n:n.slice(0,o))}n(Math.max(1,t(o.trim())),{lineIndex:l,totalLines:S.length})," ".repeat(r),0===l||e<u.length&&(String(e+1).padEnd(d," "),u[e])}else" ".repeat(i),n(g||1)}}export{o as showTemplateError};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),exports.parseHashUrl=function(e=window.location){let o;o="string"==typeof e?new URL(e).hash:e.hash;const t=o.split("?");let n=t[0];const c=t[1],s={};return n=n.replace(/^#\/?/,""),c&&c.split("&").forEach(e=>{const[o,t]=e.split("=");o&&t&&(s[decodeURIComponent(o)]=decodeURIComponent(t))}),{path:n.split("/").filter(Boolean),query:s}};
@@ -0,0 +1 @@
1
+ function o(o=window.location){let e;e="string"==typeof o?new URL(o).hash:o.hash;const n=e.split("?");let t=n[0];const c=n[1],d={};return t=t.replace(/^#\/?/,""),c&&c.split("&").forEach(o=>{const[e,n]=o.split("=");e&&n&&(d[decodeURIComponent(e)]=decodeURIComponent(n))}),{path:t.split("/").filter(Boolean),query:d}}export{o as parseHashUrl};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Other=99]="Other",e))(e||{});exports.ASTType=e;
@@ -0,0 +1 @@
1
+ var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Other=99]="Other",e))(e||{});export{e as ASTType};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./ast.cjs"),s=require("./lifecycle.cjs");exports.ASTType=e.ASTType,exports.LIFECYCLE_ATTRS_MAP=s.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=s.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=s.mapAttrKeyToLifecycleKind;
@@ -0,0 +1 @@
1
+ import{ASTType as o}from"./ast.js";import{LIFECYCLE_ATTRS_MAP as r,isLifecycleKind as m,mapAttrKeyToLifecycleKind as t}from"./lifecycle.js";export{o as ASTType,r as LIFECYCLE_ATTRS_MAP,m as isLifecycleKind,t as mapAttrKeyToLifecycleKind};