solely 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -458,16 +458,54 @@ Solely 框架内置了多层安全防护机制,有效防止常见的 XSS(跨
458
458
  | 对用户输入进行验证和清理 | 直接操作 DOM 插入不可信内容 |
459
459
  | 使用 CSP (Content Security Policy) | 信任未经检验的第三方 API 数据 |
460
460
  | 富文本使用白名单过滤 | 动态构造模板字符串 |
461
+ | 对 `:href` 进行协议白名单过滤 | 将用户输入直接绑定到 `:href` |
462
+ | 对 `:src` 也建议进行过滤 | - |
463
+ | 使用 `@click` 框架事件绑定 | - |
461
464
 
462
465
  ### 注意事项
463
466
 
464
- ⚠️ **如果框架支持 `:innerHTML` 指令**:
467
+ ⚠️ **`:innerHTML` 指令(高危)**:
465
468
 
466
- - 永远不要将用户输入绑定到 `:innerHTML`
467
- - 永远不要将第三方 API 数据直接绑定到 `:innerHTML`
469
+ - **永远不要**将用户输入绑定到 `:innerHTML`
470
+ - **永远不要**将第三方 API 数据直接绑定到 `:innerHTML`
468
471
  - 仅对完全可信的静态内容使用 `:innerHTML`
469
472
  - 如需渲染富文本,请使用专门的富文本组件并进行白名单过滤
470
473
 
474
+ ⚠️ **`:href` 属性绑定(高危)**:
475
+
476
+ - **永远不要**将用户输入直接绑定到 `:href`
477
+ - 恶意 URL 如 `javascript:alert('XSS')` 会在点击时执行代码
478
+ - 建议对 URL 进行协议白名单过滤(只允许 `http://`, `https://`)
479
+ - 示例:
480
+
481
+ ```typescript
482
+ function sanitizeUrl(url: string): string {
483
+ if (!url) return '#';
484
+ // 只允许 http/https 协议
485
+ if (/^(https?:)?\/\//i.test(url)) {
486
+ return url;
487
+ }
488
+ return '#';
489
+ }
490
+ // 使用过滤后的 URL
491
+ <a :href="sanitizeUrl($data.userWebsite)">链接</a>
492
+ ```
493
+
494
+ ℹ️ **`:src` 属性绑定(低风险)**:
495
+
496
+ - 虽然现代浏览器不会执行 `javascript:` 协议,但仍建议进行过滤
497
+ - Solely 框架不支持 IE,因此不存在旧版浏览器的风险
498
+
499
+ ℹ️ **`:onclick` 属性绑定(无风险)**:
500
+
501
+ - Solely 通过设置 DOM property 实现绑定,字符串值不会被执行
502
+ - 但仍建议使用 `@click` 框架事件绑定语法,语义更清晰
503
+
504
+ ℹ️ **`:style` 属性绑定(无风险)**:
505
+
506
+ - 通过 CSS `url('javascript:...')` 执行代码仅在旧版 IE 中有效
507
+ - Solely 框架不支持 IE,且现代浏览器已修复此漏洞
508
+
471
509
  查看 [安全演示示例](./examples/security-demo/) 了解框架如何防护 XSS 攻击。
472
510
 
473
511
  ## � API 参考
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/core.cjs"),r=require("./router/router-view.cjs"),s=require("./router/router-link.cjs"),t=require("./shared/templateError.cjs"),o=require("./shared/gen-function.cjs"),p=require("./shared/functions.cjs"),i=require("./shared/event-listeners.cjs"),u=require("./shared/is-object.cjs"),c=require("./shared/url.cjs"),x=require("./shared/env.cjs"),n=require("./types/ast.cjs"),j=require("./types/lifecycle.cjs"),q=require("./runtime/component/base-element.cjs"),a=require("./compiler/ir/buildIR.cjs"),l=require("./compiler/parser/parser.cjs"),d=require("./runtime/reactivity/observe.cjs"),m=require("./runtime/component/decorators.cjs"),h=require("./runtime/renderer/renderIR.cjs");exports.Router=e.Router,exports.createRouter=e.createRouter,exports.getRouter=e.getRouter,exports.routerReady=e.routerReady,exports.RouterView=r.default,exports.RouterLink=s.default,exports.showTemplateError=t.showTemplateError,exports.genFunction=o.genFunction,exports.createFunction=p.createFunction,exports.listeners=i.default,exports.isObject=u.isObject,exports.parseHashUrl=c.parseHashUrl,exports.IS_DEV=x.IS_DEV,exports.IS_PROD=x.IS_PROD,exports.ASTType=n.ASTType,exports.LIFECYCLE_ATTRS_MAP=j.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=j.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=j.mapAttrKeyToLifecycleKind,exports.BaseElement=q.default,exports.buildIR=a.buildIR,exports.clearIRCache=a.clearIRCache,exports.transformModel=a.transformModel,exports.parseHtml=l.parseHtml,exports.isProxy=d.isProxy,exports.observe=d.observe,exports.toRaw=d.toRaw,exports.CustomElement=m.CustomElement,exports.IRRenderer=h.IRRenderer,exports.createRender=h.createRender;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./router/index.cjs"),r=require("./shared/templateError.cjs"),s=require("./shared/gen-function.cjs"),t=require("./shared/functions.cjs"),o=require("./shared/event-listeners.cjs"),i=require("./shared/is-object.cjs"),u=require("./shared/url.cjs"),p=require("./shared/env.cjs"),c=require("./types/ast.cjs"),x=require("./types/lifecycle.cjs"),n=require("./router/router-view.cjs"),j=require("./router/router-link.cjs"),q=require("./runtime/component/base-element.cjs"),a=require("./compiler/ir/buildIR.cjs"),l=require("./compiler/parser/parser.cjs"),d=require("./router/core.cjs"),m=require("./runtime/reactivity/observe.cjs"),b=require("./runtime/component/decorators.cjs"),h=require("./runtime/renderer/renderIR.cjs");exports.createRouter=e.createRouter,exports.showTemplateError=r.showTemplateError,exports.genFunction=s.genFunction,exports.createFunction=t.createFunction,exports.listeners=o.default,exports.isObject=i.isObject,exports.parseHashUrl=u.parseHashUrl,exports.IS_DEV=p.IS_DEV,exports.IS_PROD=p.IS_PROD,exports.ASTType=c.ASTType,exports.LIFECYCLE_ATTRS_MAP=x.LIFECYCLE_ATTRS_MAP,exports.isLifecycleKind=x.isLifecycleKind,exports.mapAttrKeyToLifecycleKind=x.mapAttrKeyToLifecycleKind,Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>n.default}),Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>j.default}),exports.BaseElement=q.default,exports.buildIR=a.buildIR,exports.clearIRCache=a.clearIRCache,exports.transformModel=a.transformModel,exports.parseHtml=l.parseHtml,exports.Router=d.Router,exports.getRouter=d.getRouter,exports.routerReady=d.routerReady,exports.isProxy=m.isProxy,exports.observe=m.observe,exports.toRaw=m.toRaw,exports.CustomElement=b.CustomElement,exports.IRRenderer=h.IRRenderer,exports.createRender=h.createRender;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{Router as r,createRouter as e,getRouter as o,routerReady as t}from"./router/core.js";import{default as s}from"./router/router-view.js";import{default as m}from"./router/router-link.js";import{showTemplateError as i}from"./shared/templateError.js";import{genFunction as p}from"./shared/gen-function.js";import{createFunction as a}from"./shared/functions.js";import{default as f}from"./shared/event-listeners.js";import{isObject as n}from"./shared/is-object.js";import{parseHashUrl as j}from"./shared/url.js";import{IS_DEV as u,IS_PROD as l}from"./shared/env.js";import{ASTType as d}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as c,isLifecycleKind as h,mapAttrKeyToLifecycleKind as v}from"./types/lifecycle.js";import{default as b}from"./runtime/component/base-element.js";import{buildIR as y,clearIRCache as R,transformModel as k}from"./compiler/ir/buildIR.js";import{parseHtml as w}from"./compiler/parser/parser.js";import{isProxy as E,observe as I,toRaw as g}from"./runtime/reactivity/observe.js";import{CustomElement as x}from"./runtime/component/decorators.js";import{IRRenderer as B,createRender as L}from"./runtime/renderer/renderIR.js";export{d as ASTType,b as BaseElement,x as CustomElement,B as IRRenderer,u as IS_DEV,l as IS_PROD,c as LIFECYCLE_ATTRS_MAP,r as Router,m as RouterLink,s as RouterView,y as buildIR,R as clearIRCache,a as createFunction,L as createRender,e as createRouter,p as genFunction,o as getRouter,h as isLifecycleKind,n as isObject,E as isProxy,f as listeners,v as mapAttrKeyToLifecycleKind,I as observe,j as parseHashUrl,w as parseHtml,t as routerReady,i as showTemplateError,g as toRaw,k as transformModel};
1
+ import{createRouter as r}from"./router/index.js";import{showTemplateError as e}from"./shared/templateError.js";import{genFunction as o}from"./shared/gen-function.js";import{createFunction as t}from"./shared/functions.js";import{default as m}from"./shared/event-listeners.js";import{isObject as s}from"./shared/is-object.js";import{parseHashUrl as i}from"./shared/url.js";import{IS_DEV as p,IS_PROD as a}from"./shared/env.js";import{ASTType as f}from"./types/ast.js";import{LIFECYCLE_ATTRS_MAP as n,isLifecycleKind as j,mapAttrKeyToLifecycleKind as u}from"./types/lifecycle.js";import{default as d}from"./router/router-view.js";import{default as l}from"./router/router-link.js";import{default as c}from"./runtime/component/base-element.js";import{buildIR as h,clearIRCache as v,transformModel as b}from"./compiler/ir/buildIR.js";import{parseHtml as y}from"./compiler/parser/parser.js";import{Router as R,getRouter as k,routerReady as w}from"./router/core.js";import{isProxy as x,observe as E,toRaw as I}from"./runtime/reactivity/observe.js";import{CustomElement as g}from"./runtime/component/decorators.js";import{IRRenderer as B,createRender as L}from"./runtime/renderer/renderIR.js";export{f as ASTType,c as BaseElement,g as CustomElement,B as IRRenderer,p as IS_DEV,a as IS_PROD,n as LIFECYCLE_ATTRS_MAP,R as Router,l as RouterLink,d as RouterView,h as buildIR,v as clearIRCache,t as createFunction,L as createRender,r as createRouter,o as genFunction,k as getRouter,j as isLifecycleKind,s as isObject,x as isProxy,m as listeners,u as mapAttrKeyToLifecycleKind,E as observe,i as parseHashUrl,y as parseHtml,w as routerReady,e as showTemplateError,I as toRaw,b as transformModel};
@@ -1 +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;
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.s&&(e.s=n.s),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;
@@ -1 +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};
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.s&&(e.s=n.s),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};
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core.cjs"),r=require("./router-view.cjs"),t=require("./router-link.cjs");exports.Router=e.Router,exports.getRouter=e.getRouter,exports.routerReady=e.routerReady,Object.defineProperty(exports,"RouterView",{enumerable:!0,get:()=>r.default}),Object.defineProperty(exports,"RouterLink",{enumerable:!0,get:()=>t.default}),exports.createRouter=function(o){if(void 0===r.default||void 0===t.default)throw new Error("RouterView or RouterLink is not defined");return e.createRouter(o)};
@@ -1,6 +1,12 @@
1
- import { Router, createRouter, getRouter, routerReady } from './core';
1
+ import { Router, getRouter, routerReady } from './core';
2
2
  import { default as RouterView } from './router-view';
3
3
  import { default as RouterLink } from './router-link';
4
4
  import { RouteConfig, RouteMatch, NavigationGuard, RouterOptions, NavigationResult } from './types';
5
- export { Router, RouterView, RouterLink, createRouter, getRouter, routerReady };
5
+ /**
6
+ * 创建路由器实例(自动注册 RouterView 和 RouterLink 组件)
7
+ * @param options 路由器配置选项
8
+ * @returns 路由器实例
9
+ */
10
+ export declare function createRouter(options: RouterOptions): Router;
11
+ export { Router, RouterView, RouterLink, getRouter, routerReady };
6
12
  export type { RouteConfig, RouteMatch, NavigationGuard, RouterOptions, NavigationResult };
@@ -1 +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};
1
+ import{createRouter as r}from"./core.js";import{Router as o,getRouter as e,routerReady as t}from"./core.js";import i from"./router-view.js";import m from"./router-link.js";function n(o){if(void 0===i||void 0===m)throw new Error("RouterView or RouterLink is not defined");return r(o)}export{o as Router,m as RouterLink,i as RouterView,n as createRouter,e as getRouter,t as routerReady};
@@ -1 +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
+ "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;exports.default=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)}},exports.default=((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"]})],exports.default);
@@ -1 +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};
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);export{i as default};
@@ -1 +1 @@
1
- "use strict";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);Object.defineProperties(exports,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./core.cjs"),e=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const r=new Map;let h=class extends e.default{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,"latestLoadId",0),i(this,"abortController",null),i(this,"router",null)}async mounted(){this.detectLevel(),this.router=await s.routerReady,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let t=0,i=this.parentElement;for(;i;)i instanceof h&&t++,i=i.parentElement;this.level=t}async loadRoute(t){this.abortController&&(this.abortController.abort(),this.abortController=null);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.clear(),this.renderLoading(),this.abortController=new AbortController;const t=this.abortController.signal;try{const s=await e.component();if(t.aborted||i!==this.latestLoadId)return;n="string"==typeof s?s:s.tagName}catch(h){if(t.aborted||i!==this.latestLoadId)return;return this.renderError(`Load Error: ${h}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!t.aborted&&(this.abortController=null)}}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();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=`${this.level}-${t.toLowerCase()}`;if(i.keepAlive&&r.has(s))return r.get(s);const e=document.createElement(t);return i.keepAlive&&r.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 h=new Set(Object.keys(e));this.prevPropKeys.forEach(i=>{h.has(i)||(t[i]=void 0)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&(t[i]=s)}),this.prevPropKeys=h}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const i=document.createElement("div");i.style.cssText="padding:20px; color:#ff4d4f;",i.textContent=String(t),this.appendChild(i)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};h=((t,i)=>{for(var s,e=i,n=t.length-1;n>=0;n--)(s=t[n])&&(e=s(e)||e);return e})([n.CustomElement({tagName:"router-view"})],h);const o=h;exports.default=o;
1
+ "use strict";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);Object.defineProperties(exports,{t:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./core.cjs"),e=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const r=new Map;exports.default=class extends e.default{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,"latestLoadId",0),i(this,"abortController",null),i(this,"router",null)}async mounted(){this.detectLevel(),this.router=await s.routerReady,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let t=0,i=this.parentElement;for(;i;)i instanceof exports.default&&t++,i=i.parentElement;this.level=t}async loadRoute(t){this.abortController&&(this.abortController.abort(),this.abortController=null);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.clear(),this.renderLoading(),this.abortController=new AbortController;const t=this.abortController.signal;try{const s=await e.component();if(t.aborted||i!==this.latestLoadId)return;n="string"==typeof s?s:s.tagName}catch(o){if(t.aborted||i!==this.latestLoadId)return;return this.renderError(`Load Error: ${o}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!t.aborted&&(this.abortController=null)}}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();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=`${this.level}-${t.toLowerCase()}`;if(i.keepAlive&&r.has(s))return r.get(s);const e=document.createElement(t);return i.keepAlive&&r.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.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const i=document.createElement("div");i.style.cssText="padding:20px; color:#ff4d4f;",i.textContent=String(t),this.appendChild(i)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}},exports.default=((t,i)=>{for(var s,e=i,n=t.length-1;n>=0;n--)(s=t[n])&&(e=s(e)||e);return e})([n.CustomElement({tagName:"router-view"})],exports.default);
@@ -1 +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;const r=new Map;let o=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,"latestLoadId",0),i(this,"abortController",null),i(this,"router",null)}async mounted(){this.detectLevel(),this.router=await s,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let t=0,i=this.parentElement;for(;i;)i instanceof o&&t++,i=i.parentElement;this.level=t}async loadRoute(t){this.abortController&&(this.abortController.abort(),this.abortController=null);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.clear(),this.renderLoading(),this.abortController=new AbortController;const t=this.abortController.signal;try{const s=await e.component();if(t.aborted||i!==this.latestLoadId)return;n="string"==typeof s?s:s.tagName}catch(o){if(t.aborted||i!==this.latestLoadId)return;return this.renderError(`Load Error: ${o}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!t.aborted&&(this.abortController=null)}}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();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=`${this.level}-${t.toLowerCase()}`;if(i.keepAlive&&r.has(s))return r.get(s);const e=document.createElement(t);return i.keepAlive&&r.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.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const i=document.createElement("div");i.style.cssText="padding:20px; color:#ff4d4f;",i.textContent=String(t),this.appendChild(i)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};o=((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"})],o);const h=o;export{h as default};
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;const r=new Map;let h=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,"latestLoadId",0),i(this,"abortController",null),i(this,"router",null)}async mounted(){this.detectLevel(),this.router=await s,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let t=0,i=this.parentElement;for(;i;)i instanceof h&&t++,i=i.parentElement;this.level=t}async loadRoute(t){this.abortController&&(this.abortController.abort(),this.abortController=null);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.clear(),this.renderLoading(),this.abortController=new AbortController;const t=this.abortController.signal;try{const s=await e.component();if(t.aborted||i!==this.latestLoadId)return;n="string"==typeof s?s:s.tagName}catch(h){if(t.aborted||i!==this.latestLoadId)return;return this.renderError(`Load Error: ${h}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!t.aborted&&(this.abortController=null)}}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();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=`${this.level}-${t.toLowerCase()}`;if(i.keepAlive&&r.has(s))return r.get(s);const e=document.createElement(t);return i.keepAlive&&r.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 h=new Set(Object.keys(e));this.prevPropKeys.forEach(i=>{h.has(i)||(t[i]=void 0)}),Object.entries(e).forEach(([i,s])=>{t[i]!==s&&(t[i]=s)}),this.prevPropKeys=h}handleEmptyRoute(){this.clear(),0===this.level&&this.renderError("404 Not Found")}renderLoading(){this.textContent="";const t=document.createElement("div");t.style.cssText="padding:20px; color:#999;",t.textContent="Loading...",this.appendChild(t)}renderError(t){this.textContent="";const i=document.createElement("div");i.style.cssText="padding:20px; color:#ff4d4f;",i.textContent=String(t),this.appendChild(i)}clear(){this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement),this.innerHTML="",this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};h=((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"})],h);export{h as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.2.4",
4
+ "version": "0.2.6",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -39,16 +39,6 @@
39
39
  "default": "./dist/compiler/index.cjs"
40
40
  }
41
41
  },
42
- "./compiler/*": {
43
- "import": {
44
- "types": "./dist/compiler/*.d.ts",
45
- "default": "./dist/compiler/*.js"
46
- },
47
- "require": {
48
- "types": "./dist/compiler/*.d.ts",
49
- "default": "./dist/compiler/*.cjs"
50
- }
51
- },
52
42
  "./runtime": {
53
43
  "import": {
54
44
  "types": "./dist/runtime/index.d.ts",
@@ -59,16 +49,6 @@
59
49
  "default": "./dist/runtime/index.cjs"
60
50
  }
61
51
  },
62
- "./runtime/*": {
63
- "import": {
64
- "types": "./dist/runtime/*.d.ts",
65
- "default": "./dist/runtime/*.js"
66
- },
67
- "require": {
68
- "types": "./dist/runtime/*.d.ts",
69
- "default": "./dist/runtime/*.cjs"
70
- }
71
- },
72
52
  "./router": {
73
53
  "import": {
74
54
  "types": "./dist/router/index.d.ts",
@@ -79,16 +59,6 @@
79
59
  "default": "./dist/router/index.cjs"
80
60
  }
81
61
  },
82
- "./router/*": {
83
- "import": {
84
- "types": "./dist/router/*.d.ts",
85
- "default": "./dist/router/*.js"
86
- },
87
- "require": {
88
- "types": "./dist/router/*.d.ts",
89
- "default": "./dist/router/*.cjs"
90
- }
91
- },
92
62
  "./shared": {
93
63
  "import": {
94
64
  "types": "./dist/shared/index.d.ts",
@@ -99,16 +69,6 @@
99
69
  "default": "./dist/shared/index.cjs"
100
70
  }
101
71
  },
102
- "./shared/*": {
103
- "import": {
104
- "types": "./dist/shared/*.d.ts",
105
- "default": "./dist/shared/*.js"
106
- },
107
- "require": {
108
- "types": "./dist/shared/*.d.ts",
109
- "default": "./dist/shared/*.cjs"
110
- }
111
- },
112
72
  "./types": {
113
73
  "import": {
114
74
  "types": "./dist/types/index.d.ts",
@@ -119,16 +79,6 @@
119
79
  "default": "./dist/types/index.cjs"
120
80
  }
121
81
  },
122
- "./types/*": {
123
- "import": {
124
- "types": "./dist/types/*.d.ts",
125
- "default": "./dist/types/*.js"
126
- },
127
- "require": {
128
- "types": "./dist/types/*.d.ts",
129
- "default": "./dist/types/*.cjs"
130
- }
131
- },
132
82
  "./package.json": "./package.json"
133
83
  },
134
84
  "typesVersions": {
@@ -204,6 +154,9 @@
204
154
  "dev:debug": "node --inspect-brk ./node_modules/vite/bin/vite.js",
205
155
  "prepare": "husky"
206
156
  },
157
+ "dependencies": {
158
+ "magic-string": "^0.30.21"
159
+ },
207
160
  "devDependencies": {
208
161
  "@rollup/plugin-strip": "^3.0.4",
209
162
  "@testing-library/dom": "^10.4.1",
@@ -219,7 +172,6 @@
219
172
  "husky": "^9.0.0",
220
173
  "jsdom": "27.0.0",
221
174
  "lint-staged": "^15.0.0",
222
- "magic-string": "^0.30.21",
223
175
  "prettier": "^3.0.0",
224
176
  "rimraf": "^5.0.10",
225
177
  "sass": "^1.83.0",