solely 0.5.0 → 0.5.2

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.
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,s,r)=>((e,s,r)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[s]=r)(e,"symbol"!=typeof s?s+"":s,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let s,r=null;const a=new Promise(t=>{s=t});class n{constructor(t){e(this,"routes"),e(this,"base"),e(this,"mode"),e(this,"beforeEachGuard"),e(this,"afterEachGuard"),e(this,"currentRoute",null),e(this,"listeners",new Set),e(this,"componentCache",new Map),e(this,"loadingComponents",new Set),e(this,"isStarted",!1),e(this,"handleRouteChange",null),this.routes=t.routes,this.base=t.base??"/",this.mode=t.mode||"history",this.beforeEachGuard=t.beforeEach,this.afterEachGuard=t.afterEach}matchRoute(t="/"){const e=t.startsWith("/")?t:"/"+t,[s,r]=e.split("?"),a=s.split("/").filter(Boolean),n=this.parseQuery(r),i=this.recursiveMatch(this.routes,a);if(i){const t=i.matched[i.matched.length-1];return t.config.redirect?this.matchRoute(t.config.redirect):{matched:i.matched,params:i.params,query:n,fullPath:e,meta:i.matched.reduce((t,e)=>({...t,...e.config.meta||{}}),{})}}return null}recursiveMatch(t,e){const s=[...t].sort((t,e)=>this.calculateScore(e.path)-this.calculateScore(t.path));for(const r of s){const t=r.path.split("/").filter(Boolean),s={};let a=!0;if(0===t.length&&0===e.length)return{matched:[{config:r,params:{}}],params:{}};for(let r=0;r<t.length;r++){const n=t[r],i=e[r];if(n.startsWith(":")){if(!i){a=!1;break}s[n.slice(1)]=i}else{if("*"===n){a=!0;break}if(n!==i){a=!1;break}}}if(a){const a=t.length,n=e.slice(a),i={config:r,params:s};if(n.length>0&&r.children){const t=this.recursiveMatch(r.children,n);if(t)return{matched:[i,...t.matched],params:{...s,...t.params}}}else if(0===n.length||t.includes("*"))return{matched:[i],params:s}}}return null}calculateScore(t="/"){const e=t.split("/").filter(Boolean);return 0===e.length?1:e.reduce((t,e)=>e.startsWith(":")?t+5:"*"===e?t+0:t+10,0)}parseQuery(t){const e={};return t?(new URLSearchParams(t).forEach((t,s)=>{e[s]=t}),e):e}normalizePath(t="/"){let e=t&&"string"==typeof t?t:"/";return e.startsWith("/")||(e="/"+e),e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e}getPath(){let t;try{t="hash"===this.mode?window.location.hash.slice(1)||"/":window.location.pathname||"/"}catch{t="/"}const e=this.base||"/";return"/"!==e&&t.startsWith(e)&&(t=t.slice(e.length)||"/"),this.normalizePath(t)}updateBrowserHistory(t="/",e){const s=this.normalizePath(t),r=this.base||"/";if("hash"===this.mode)e?window.location.replace(`#${s}`):window.location.hash=s;else{const t=r.endsWith("/")?r.slice(0,-1):r,a="/"===t?s:t+s;e?window.history.replaceState({path:a},"",a):window.history.pushState({path:a},"",a)}}async navigate(t="/",e=!1,s=!1){const r=this.normalizePath(t),a=this.currentRoute,n=this.matchRoute(r);if(!n)return{success:!1,error:`No route matched: ${r}`};if(a&&a.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const t=await this.beforeEachGuard(n,a);if(!1===t)return{success:!1,cancelled:!0};if("string"==typeof t)return this.navigate(t,e)}catch(i){return{success:!1,error:i instanceof Error?i.message:"Guard Error"}}return this.currentRoute=n,s||this.updateBrowserHistory(r,e),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,a),{success:!0}}resolve(t="/"){const e=this.normalizePath(t);if("hash"===this.mode)return`#${e}`;const s=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===s?e:s+e}get modeType(){return this.mode}pushWithQuery(t="/",e){const s=new URLSearchParams(e).toString(),r=t.includes("?")?"&":"?";return this.push(t+(s?r+s:""))}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||(this.isStarted=!0,this.handleRouteChange=()=>{this.navigate(this.getPath(),!0,!0)},"hash"===this.mode?window.addEventListener("hashchange",this.handleRouteChange):window.addEventListener("popstate",this.handleRouteChange),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}destroy(){this.handleRouteChange&&("hash"===this.mode?window.removeEventListener("hashchange",this.handleRouteChange):window.removeEventListener("popstate",this.handleRouteChange),this.handleRouteChange=null),this.isStarted=!1,this.listeners.clear(),this.componentCache.clear(),this.loadingComponents.clear(),this.currentRoute=null,r=null}getCurrentRoute(){return this.currentRoute}prefetch(t){const e=this.matchRoute(t);if(!e)return;const s=e.matched[e.matched.length-1];if(!(null==s?void 0:s.config.component))return;const r=s.config.component;"function"==typeof r&&(this.loadingComponents.has(t)||this.componentCache.has(t)||(this.loadingComponents.add(t),r().then(e=>{this.componentCache.set(t,Promise.resolve(e))}).catch(()=>{}).finally(()=>{this.loadingComponents.delete(t)})))}getComponentFromCache(t){return this.componentCache.get(t)}}exports.Router=n,exports.createRouter=function(t){return r||(r=new n(t),s(r),r)},exports.getRouter=function(){return r},exports.routerReady=a;
1
+ "use strict";var e=Object.defineProperty,t=(t,s,i)=>((t,s,i)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i)(t,"symbol"!=typeof s?s+"":s,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../shared/env.cjs");let i=null,r=null,a=null;function n(){return i?Promise.resolve(i):(a||(a=new Promise(e=>{r=e})),a)}const h=(()=>{const e=()=>n();return Object.defineProperties(e,{then:{value:(e,t)=>n().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>n().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>n().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})(),o=class e{constructor(e){t(this,"routes"),t(this,"base"),t(this,"mode"),t(this,"beforeEachGuard"),t(this,"afterEachGuard"),t(this,"currentRoute",null),t(this,"listeners",new Set),t(this,"componentCache",new Map),t(this,"keepAliveCache",new Map),t(this,"keepAliveKeys",[]),t(this,"navigationId",0),t(this,"maxKeepAlive"),t(this,"isStarted",!1),t(this,"handleRouteChange",null),this.routes=e.routes,this.base=e.base??"/",this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,i,r){if(r>=e.MAX_REDIRECTS)return s.IS_DEV&&console.error(`[Router] Too many redirects (max ${e.MAX_REDIRECTS}), last path: ${t}`),null;const a=this.normalizePath(t);if(i.has(a))return s.IS_DEV&&console.error(`[Router] Circular redirect detected: ${a}`),null;i.add(a);const[n,h]=a.split("?"),o=n.split("/").filter(Boolean),c=this.parseQuery(h),l=this.recursiveMatch(this.routes,o);if(l){const e=l.matched[l.matched.length-1];return e.config.redirect?this.matchRouteInternal(e.config.redirect,i,r+1):{matched:l.matched,params:l.params,query:c,fullPath:a,meta:l.matched.reduce((e,t)=>({...e,...t.config.meta||{}}),{})}}return null}recursiveMatch(e,t){const s=[...e].sort((e,t)=>this.calculateScore(t.path)-this.calculateScore(e.path));for(const i of s){const e=i.path.split("/").filter(Boolean),s={};let r=!0;if(0===e.length&&0===t.length)return{matched:[{config:i,params:{}}],params:{}};for(let i=0;i<e.length;i++){const a=e[i],n=t[i];if(a.startsWith(":")){if(!n){r=!1;break}s[a.slice(1)]=n}else{if("*"===a){r=!0;break}if(a!==n){r=!1;break}}}if(r){const r=e.length,a=t.slice(r),n={config:i,params:s};if(a.length>0&&i.children){const e=this.recursiveMatch(i.children,a);if(e)return{matched:[n,...e.matched],params:{...s,...e.params}}}else if(0===a.length||e.includes("*"))return{matched:[n],params:s}}}return null}calculateScore(e="/"){const t=e.split("/").filter(Boolean);return 0===t.length?1:t.reduce((e,t)=>t.startsWith(":")?e+5:"*"===t?e+0:e+10,0)}parseQuery(e){const t={};return e?(new URLSearchParams(e).forEach((e,s)=>{t[s]=e}),t):t}normalizePath(e="/"){const t=e&&"string"==typeof e?e:"/",s=t.indexOf("?"),i=-1===s?t:t.slice(0,s),r=-1===s?"":t.slice(s+1);let a=i;return a.startsWith("/")||(a="/"+a),a.length>1&&a.endsWith("/")&&(a=a.slice(0,-1)),r?`${a}?${r}`:a}getPath(){let e;try{e="hash"===this.mode?window.location.hash.slice(1)||"/":`${window.location.pathname}${window.location.search}`}catch{e="/"}const t=this.base||"/";return"/"!==t&&e.startsWith(t)&&(e=e.slice(t.length)||"/"),this.normalizePath(e)}updateBrowserHistory(e="/",t){const s=this.normalizePath(e),i=this.base||"/";if("hash"===this.mode)t?window.location.replace(`#${s}`):window.location.hash=s;else{const e=i.endsWith("/")?i.slice(0,-1):i,r="/"===e?s:e+s;t?window.history.replaceState({path:r},"",r):window.history.pushState({path:r},"",r)}}async navigate(e="/",t=!1,s=!1){const i=++this.navigationId,r=this.normalizePath(e),a=this.currentRoute,n=this.matchRoute(r);if(!n)return{success:!1,error:`No route matched: ${r}`};if(a&&a.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const e=await this.beforeEachGuard(n,a);if(i!==this.navigationId)return{success:!1,cancelled:!0};if(!1===e)return{success:!1,cancelled:!0};if("string"==typeof e)return this.navigate(e,t)}catch(h){return i!==this.navigationId?{success:!1,cancelled:!0}:{success:!1,error:h instanceof Error?h.message:"Guard Error"}}return i!==this.navigationId?{success:!1,cancelled:!0}:(this.currentRoute=n,s||this.updateBrowserHistory(r,t),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,a),{success:!0})}resolve(e="/"){const t=this.normalizePath(e);if("hash"===this.mode)return`#${t}`;const s=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===s?t:s+t}get modeType(){return this.mode}pushWithQuery(e="/",t){const s=new URLSearchParams(t).toString(),i=e.includes("?")?"&":"?";return this.push(e+(s?i+s:""))}push(e="/"){return this.navigate(e,!1)}replace(e="/"){return this.navigate(e,!0)}back(){window.history.back()}forward(){window.history.forward()}listen(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e())}setupListeners(){this.isStarted||(this.isStarted=!0,this.handleRouteChange=()=>{this.navigate(this.getPath(),!0,!0)},"hash"===this.mode?window.addEventListener("hashchange",this.handleRouteChange):window.addEventListener("popstate",this.handleRouteChange),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}destroy(){this.handleRouteChange&&("hash"===this.mode?window.removeEventListener("hashchange",this.handleRouteChange):window.removeEventListener("popstate",this.handleRouteChange),this.handleRouteChange=null),this.isStarted=!1,this.listeners.clear(),this.componentCache.clear(),this.keepAliveCache.clear(),this.keepAliveKeys=[],this.currentRoute=null,i=null}getCurrentRoute(){return this.currentRoute}getKeepAlive(e){const t=this.keepAliveCache.get(e);if(t){const t=this.keepAliveKeys.indexOf(e);-1!==t&&(this.keepAliveKeys.splice(t,1),this.keepAliveKeys.push(e))}return t}setKeepAlive(e,t){if(this.keepAliveCache.has(e)){this.keepAliveCache.set(e,t);const s=this.keepAliveKeys.indexOf(e);-1!==s&&(this.keepAliveKeys.splice(s,1),this.keepAliveKeys.push(e))}else this.keepAliveCache.set(e,t),this.keepAliveKeys.push(e),this.evictKeepAlive()}hasKeepAlive(e){return this.keepAliveCache.has(e)}evictKeepAlive(){if(this.maxKeepAlive)for(;this.keepAliveKeys.length>this.maxKeepAlive;){const e=this.keepAliveKeys.shift();e&&this.keepAliveCache.delete(e)}}cacheKey(e){return this.normalizePath(e)}prefetch(e){const t=this.matchRoute(e);if(!t)return;const s=this.cacheKey(t.fullPath),i=t.matched[t.matched.length-1];if(!(null==i?void 0:i.config.component))return;const r=i.config.component;if("function"!=typeof r)return;if(this.componentCache.has(s))return;const a=r();this.componentCache.set(s,a),a.catch(()=>{this.componentCache.delete(s)})}getComponentFromCache(e){return this.componentCache.get(this.cacheKey(e))}};t(o,"MAX_REDIRECTS",20);let c=o;exports.Router=c,exports.createRouter=function(e){return i||(i=new c(e),r&&r(i),r=null,a=null,i)},exports.getRouter=function(){return i},exports.routerReady=h;
@@ -1,15 +1,19 @@
1
1
  import { RouteMatch, RouterOptions, NavigationResult } from './types';
2
- /** 路由器就绪 Promise,在 createRouter 调用后 resolve */
3
- export declare const routerReady: Promise<Router>;
2
+ /**
3
+ * 路由器就绪 Promise(向后兼容)
4
+ *
5
+ * 支持两种用法:
6
+ * - await routerReady // 旧版用法,直接 await 常量
7
+ * - await routerReady() // 新版用法,函数调用
8
+ * - routerReady.then(...) // Promise 链式调用
9
+ */
10
+ export declare const routerReady: Promise<Router> & (() => Promise<Router>);
4
11
  /**
5
12
  * 创建路由器实例(单例)
6
- * @param options 路由器配置选项
7
- * @returns 路由器实例
8
13
  */
9
14
  export declare function createRouter(options: RouterOptions): Router;
10
15
  /**
11
16
  * 获取路由器实例
12
- * @returns 路由器实例,如果未创建则返回 null
13
17
  */
14
18
  export declare function getRouter(): Router | null;
15
19
  /**
@@ -24,27 +28,22 @@ export declare class Router {
24
28
  private currentRoute;
25
29
  private listeners;
26
30
  private componentCache;
27
- private loadingComponents;
31
+ private keepAliveCache;
32
+ private keepAliveKeys;
33
+ private navigationId;
34
+ private maxKeepAlive;
28
35
  constructor(options: RouterOptions);
36
+ private static readonly MAX_REDIRECTS;
29
37
  matchRoute(path?: string): RouteMatch | null;
38
+ private matchRouteInternal;
30
39
  private recursiveMatch;
31
40
  private calculateScore;
32
41
  private parseQuery;
33
42
  private normalizePath;
34
43
  getPath(): string;
35
44
  private updateBrowserHistory;
36
- /**
37
- * @param fromEvent 标志位:是否由浏览器 popstate 事件触发
38
- */
39
45
  navigate(path?: string, replace?: boolean, fromEvent?: boolean): Promise<NavigationResult>;
40
- /**
41
- * 将逻辑路径解析为浏览器真实的 URL 路径
42
- * 供 RouterLink 等组件生成 href 使用
43
- */
44
46
  resolve(path?: string): string;
45
- /**
46
- * 获取当前模式(供外部组件判断,如 RouterLink)
47
- */
48
47
  get modeType(): 'hash' | 'history';
49
48
  pushWithQuery(path: string | undefined, query: Record<string, string>): Promise<NavigationResult>;
50
49
  push(path?: string): Promise<NavigationResult>;
@@ -56,21 +55,14 @@ export declare class Router {
56
55
  private isStarted;
57
56
  private handleRouteChange;
58
57
  setupListeners(): void;
59
- /**
60
- * 销毁路由器,清理事件监听和缓存
61
- */
62
58
  destroy(): void;
63
59
  getCurrentRoute(): RouteMatch | null;
64
- /**
65
- * 预加载路由组件
66
- * @param path 要预加载的路径
67
- */
60
+ getKeepAlive(key: string): HTMLElement | undefined;
61
+ setKeepAlive(key: string, el: HTMLElement): void;
62
+ hasKeepAlive(key: string): boolean;
63
+ private evictKeepAlive;
64
+ private cacheKey;
68
65
  prefetch(path: string): void;
69
- /**
70
- * 从缓存中获取已加载的组件
71
- * @param path 路径
72
- * @returns 缓存的组件 Promise 或 undefined
73
- */
74
66
  getComponentFromCache(path: string): Promise<string | {
75
67
  tagName: string;
76
68
  }> | undefined;
@@ -1 +1 @@
1
- var t=Object.defineProperty,e=(e,s,r)=>((e,s,r)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[s]=r)(e,"symbol"!=typeof s?s+"":s,r);let s,r=null;const a=new Promise(t=>{s=t});function n(t){return r||(r=new i(t),s(r),r)}function h(){return r}class i{constructor(t){e(this,"routes"),e(this,"base"),e(this,"mode"),e(this,"beforeEachGuard"),e(this,"afterEachGuard"),e(this,"currentRoute",null),e(this,"listeners",new Set),e(this,"componentCache",new Map),e(this,"loadingComponents",new Set),e(this,"isStarted",!1),e(this,"handleRouteChange",null),this.routes=t.routes,this.base=t.base??"/",this.mode=t.mode||"history",this.beforeEachGuard=t.beforeEach,this.afterEachGuard=t.afterEach}matchRoute(t="/"){const e=t.startsWith("/")?t:"/"+t,[s,r]=e.split("?"),a=s.split("/").filter(Boolean),n=this.parseQuery(r),h=this.recursiveMatch(this.routes,a);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:e,meta:h.matched.reduce((t,e)=>({...t,...e.config.meta||{}}),{})}}return null}recursiveMatch(t,e){const s=[...t].sort((t,e)=>this.calculateScore(e.path)-this.calculateScore(t.path));for(const r of s){const t=r.path.split("/").filter(Boolean),s={};let a=!0;if(0===t.length&&0===e.length)return{matched:[{config:r,params:{}}],params:{}};for(let r=0;r<t.length;r++){const n=t[r],h=e[r];if(n.startsWith(":")){if(!h){a=!1;break}s[n.slice(1)]=h}else{if("*"===n){a=!0;break}if(n!==h){a=!1;break}}}if(a){const a=t.length,n=e.slice(a),h={config:r,params:s};if(n.length>0&&r.children){const t=this.recursiveMatch(r.children,n);if(t)return{matched:[h,...t.matched],params:{...s,...t.params}}}else if(0===n.length||t.includes("*"))return{matched:[h],params:s}}}return null}calculateScore(t="/"){const e=t.split("/").filter(Boolean);return 0===e.length?1:e.reduce((t,e)=>e.startsWith(":")?t+5:"*"===e?t+0:t+10,0)}parseQuery(t){const e={};return t?(new URLSearchParams(t).forEach((t,s)=>{e[s]=t}),e):e}normalizePath(t="/"){let e=t&&"string"==typeof t?t:"/";return e.startsWith("/")||(e="/"+e),e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e}getPath(){let t;try{t="hash"===this.mode?window.location.hash.slice(1)||"/":window.location.pathname||"/"}catch{t="/"}const e=this.base||"/";return"/"!==e&&t.startsWith(e)&&(t=t.slice(e.length)||"/"),this.normalizePath(t)}updateBrowserHistory(t="/",e){const s=this.normalizePath(t),r=this.base||"/";if("hash"===this.mode)e?window.location.replace(`#${s}`):window.location.hash=s;else{const t=r.endsWith("/")?r.slice(0,-1):r,a="/"===t?s:t+s;e?window.history.replaceState({path:a},"",a):window.history.pushState({path:a},"",a)}}async navigate(t="/",e=!1,s=!1){const r=this.normalizePath(t),a=this.currentRoute,n=this.matchRoute(r);if(!n)return{success:!1,error:`No route matched: ${r}`};if(a&&a.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const t=await this.beforeEachGuard(n,a);if(!1===t)return{success:!1,cancelled:!0};if("string"==typeof t)return this.navigate(t,e)}catch(h){return{success:!1,error:h instanceof Error?h.message:"Guard Error"}}return this.currentRoute=n,s||this.updateBrowserHistory(r,e),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,a),{success:!0}}resolve(t="/"){const e=this.normalizePath(t);if("hash"===this.mode)return`#${e}`;const s=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===s?e:s+e}get modeType(){return this.mode}pushWithQuery(t="/",e){const s=new URLSearchParams(e).toString(),r=t.includes("?")?"&":"?";return this.push(t+(s?r+s:""))}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||(this.isStarted=!0,this.handleRouteChange=()=>{this.navigate(this.getPath(),!0,!0)},"hash"===this.mode?window.addEventListener("hashchange",this.handleRouteChange):window.addEventListener("popstate",this.handleRouteChange),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}destroy(){this.handleRouteChange&&("hash"===this.mode?window.removeEventListener("hashchange",this.handleRouteChange):window.removeEventListener("popstate",this.handleRouteChange),this.handleRouteChange=null),this.isStarted=!1,this.listeners.clear(),this.componentCache.clear(),this.loadingComponents.clear(),this.currentRoute=null,r=null}getCurrentRoute(){return this.currentRoute}prefetch(t){const e=this.matchRoute(t);if(!e)return;const s=e.matched[e.matched.length-1];if(!(null==s?void 0:s.config.component))return;const r=s.config.component;"function"==typeof r&&(this.loadingComponents.has(t)||this.componentCache.has(t)||(this.loadingComponents.add(t),r().then(e=>{this.componentCache.set(t,Promise.resolve(e))}).catch(()=>{}).finally(()=>{this.loadingComponents.delete(t)})))}getComponentFromCache(t){return this.componentCache.get(t)}}export{i as Router,n as createRouter,h as getRouter,a as routerReady};
1
+ var e=Object.defineProperty,t=(t,s,i)=>((t,s,i)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i)(t,"symbol"!=typeof s?s+"":s,i);import{IS_DEV as s}from"../shared/env.js";let i=null,a=null,r=null;function n(){return i?Promise.resolve(i):(r||(r=new Promise(e=>{a=e})),r)}const h=(()=>{const e=()=>n();return Object.defineProperties(e,{then:{value:(e,t)=>n().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>n().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>n().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})();function o(e){return i||(i=new u(e),a&&a(i),a=null,r=null,i)}function c(){return i}const l=class e{constructor(e){t(this,"routes"),t(this,"base"),t(this,"mode"),t(this,"beforeEachGuard"),t(this,"afterEachGuard"),t(this,"currentRoute",null),t(this,"listeners",new Set),t(this,"componentCache",new Map),t(this,"keepAliveCache",new Map),t(this,"keepAliveKeys",[]),t(this,"navigationId",0),t(this,"maxKeepAlive"),t(this,"isStarted",!1),t(this,"handleRouteChange",null),this.routes=e.routes,this.base=e.base??"/",this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,i,a){if(a>=e.MAX_REDIRECTS)return s&&console.error(`[Router] Too many redirects (max ${e.MAX_REDIRECTS}), last path: ${t}`),null;const r=this.normalizePath(t);if(i.has(r))return s&&console.error(`[Router] Circular redirect detected: ${r}`),null;i.add(r);const[n,h]=r.split("?"),o=n.split("/").filter(Boolean),c=this.parseQuery(h),l=this.recursiveMatch(this.routes,o);if(l){const e=l.matched[l.matched.length-1];return e.config.redirect?this.matchRouteInternal(e.config.redirect,i,a+1):{matched:l.matched,params:l.params,query:c,fullPath:r,meta:l.matched.reduce((e,t)=>({...e,...t.config.meta||{}}),{})}}return null}recursiveMatch(e,t){const s=[...e].sort((e,t)=>this.calculateScore(t.path)-this.calculateScore(e.path));for(const i of s){const e=i.path.split("/").filter(Boolean),s={};let a=!0;if(0===e.length&&0===t.length)return{matched:[{config:i,params:{}}],params:{}};for(let i=0;i<e.length;i++){const r=e[i],n=t[i];if(r.startsWith(":")){if(!n){a=!1;break}s[r.slice(1)]=n}else{if("*"===r){a=!0;break}if(r!==n){a=!1;break}}}if(a){const a=e.length,r=t.slice(a),n={config:i,params:s};if(r.length>0&&i.children){const e=this.recursiveMatch(i.children,r);if(e)return{matched:[n,...e.matched],params:{...s,...e.params}}}else if(0===r.length||e.includes("*"))return{matched:[n],params:s}}}return null}calculateScore(e="/"){const t=e.split("/").filter(Boolean);return 0===t.length?1:t.reduce((e,t)=>t.startsWith(":")?e+5:"*"===t?e+0:e+10,0)}parseQuery(e){const t={};return e?(new URLSearchParams(e).forEach((e,s)=>{t[s]=e}),t):t}normalizePath(e="/"){const t=e&&"string"==typeof e?e:"/",s=t.indexOf("?"),i=-1===s?t:t.slice(0,s),a=-1===s?"":t.slice(s+1);let r=i;return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),a?`${r}?${a}`:r}getPath(){let e;try{e="hash"===this.mode?window.location.hash.slice(1)||"/":`${window.location.pathname}${window.location.search}`}catch{e="/"}const t=this.base||"/";return"/"!==t&&e.startsWith(t)&&(e=e.slice(t.length)||"/"),this.normalizePath(e)}updateBrowserHistory(e="/",t){const s=this.normalizePath(e),i=this.base||"/";if("hash"===this.mode)t?window.location.replace(`#${s}`):window.location.hash=s;else{const e=i.endsWith("/")?i.slice(0,-1):i,a="/"===e?s:e+s;t?window.history.replaceState({path:a},"",a):window.history.pushState({path:a},"",a)}}async navigate(e="/",t=!1,s=!1){const i=++this.navigationId,a=this.normalizePath(e),r=this.currentRoute,n=this.matchRoute(a);if(!n)return{success:!1,error:`No route matched: ${a}`};if(r&&r.fullPath===n.fullPath)return{success:!0};if(this.beforeEachGuard)try{const e=await this.beforeEachGuard(n,r);if(i!==this.navigationId)return{success:!1,cancelled:!0};if(!1===e)return{success:!1,cancelled:!0};if("string"==typeof e)return this.navigate(e,t)}catch(h){return i!==this.navigationId?{success:!1,cancelled:!0}:{success:!1,error:h instanceof Error?h.message:"Guard Error"}}return i!==this.navigationId?{success:!1,cancelled:!0}:(this.currentRoute=n,s||this.updateBrowserHistory(a,t),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(n,r),{success:!0})}resolve(e="/"){const t=this.normalizePath(e);if("hash"===this.mode)return`#${t}`;const s=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===s?t:s+t}get modeType(){return this.mode}pushWithQuery(e="/",t){const s=new URLSearchParams(t).toString(),i=e.includes("?")?"&":"?";return this.push(e+(s?i+s:""))}push(e="/"){return this.navigate(e,!1)}replace(e="/"){return this.navigate(e,!0)}back(){window.history.back()}forward(){window.history.forward()}listen(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(){this.listeners.forEach(e=>e())}setupListeners(){this.isStarted||(this.isStarted=!0,this.handleRouteChange=()=>{this.navigate(this.getPath(),!0,!0)},"hash"===this.mode?window.addEventListener("hashchange",this.handleRouteChange):window.addEventListener("popstate",this.handleRouteChange),"hash"!==this.mode||window.location.hash||(window.location.hash="/"),this.navigate(this.getPath(),!0))}destroy(){this.handleRouteChange&&("hash"===this.mode?window.removeEventListener("hashchange",this.handleRouteChange):window.removeEventListener("popstate",this.handleRouteChange),this.handleRouteChange=null),this.isStarted=!1,this.listeners.clear(),this.componentCache.clear(),this.keepAliveCache.clear(),this.keepAliveKeys=[],this.currentRoute=null,i=null}getCurrentRoute(){return this.currentRoute}getKeepAlive(e){const t=this.keepAliveCache.get(e);if(t){const t=this.keepAliveKeys.indexOf(e);-1!==t&&(this.keepAliveKeys.splice(t,1),this.keepAliveKeys.push(e))}return t}setKeepAlive(e,t){if(this.keepAliveCache.has(e)){this.keepAliveCache.set(e,t);const s=this.keepAliveKeys.indexOf(e);-1!==s&&(this.keepAliveKeys.splice(s,1),this.keepAliveKeys.push(e))}else this.keepAliveCache.set(e,t),this.keepAliveKeys.push(e),this.evictKeepAlive()}hasKeepAlive(e){return this.keepAliveCache.has(e)}evictKeepAlive(){if(this.maxKeepAlive)for(;this.keepAliveKeys.length>this.maxKeepAlive;){const e=this.keepAliveKeys.shift();e&&this.keepAliveCache.delete(e)}}cacheKey(e){return this.normalizePath(e)}prefetch(e){const t=this.matchRoute(e);if(!t)return;const s=this.cacheKey(t.fullPath),i=t.matched[t.matched.length-1];if(!(null==i?void 0:i.config.component))return;const a=i.config.component;if("function"!=typeof a)return;if(this.componentCache.has(s))return;const r=a();this.componentCache.set(s,r),r.catch(()=>{this.componentCache.delete(s)})}getComponentFromCache(e){return this.componentCache.get(this.cacheKey(e))}};t(l,"MAX_REDIRECTS",20);let u=l;export{u as Router,o as createRouter,c as getRouter,h as routerReady};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("./core.cjs"),e=require("./router-link.html.cjs"),a=require("../runtime/component/base-element.cjs"),s=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;var r,o=t=>{throw TypeError(t)},n=(t,e,a)=>e.has(t)||o("Cannot "+a);exports.default=class extends a.default{constructor(){var t,e;super(...arguments),t=this,(e=r).has(t)?o("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,false)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await t.routerReady).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",e=>{var a,s;e.defaultPrevented||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||0===e.button&&((null==(a=e.target.closest("a"))?void 0:a.getAttribute("target"))||(e.preventDefault(),null==(s=t.getRouter())||s.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const e=t.getRouter();if(!e)return;this.$data.href=e.resolve(this.$data.to);let a=!1;if(this.$data.active)a=!0;else{const t=e.getCurrentRoute();if(t){const e=t.fullPath;a=this.hasAttribute("exact")?e===this.$data.to:e===this.$data.to||e.startsWith(this.$data.to+"/")}}this.$data.isActive=a;const s=this.$data.activeClass||"active";this.classList.toggle(s,a)}prefetchRoute(){if(n(this,e=r,"read from private field"),e.get(this)||!this.hasAttribute("prefetch"))return;var e;const a=t.getRouter();a&&(a.prefetch(this.$data.to),((t,e)=>{n(t,e,"write to private field"),e.set(t,!0)})(this,r))}},r=new WeakMap,exports.default=((t,e)=>{for(var a,s=e,r=t.length-1;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s})([s.CustomElement({tagName:"router-link",template:e.__SOLELY_IR__,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
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("./core.cjs"),e=require("./router-link.html.cjs"),a=require("../runtime/component/base-element.cjs"),s=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;var r,o=t=>{throw TypeError(t)},n=(t,e,a)=>e.has(t)||o("Cannot "+a);exports.default=class extends a.default{constructor(){var t,e;super(...arguments),t=this,(e=r).has(t)?o("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,false)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await t.routerReady()).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",e=>{var a,s;e.defaultPrevented||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||0===e.button&&((null==(a=e.target.closest("a"))?void 0:a.getAttribute("target"))||(e.preventDefault(),null==(s=t.getRouter())||s.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const e=t.getRouter();if(!e)return;this.$data.href=e.resolve(this.$data.to);let a=!1;if(this.$data.active)a=!0;else{const t=e.getCurrentRoute();if(t){const e=t.fullPath;a=this.hasAttribute("exact")?e===this.$data.to:e===this.$data.to||e.startsWith(this.$data.to+"/")}}this.$data.isActive=a;const s=this.$data.activeClass||"active";this.classList.toggle(s,a)}prefetchRoute(){if(n(this,e=r,"read from private field"),e.get(this)||!this.hasAttribute("prefetch"))return;var e;const a=t.getRouter();a&&(a.prefetch(this.$data.to),((t,e)=>{n(t,e,"write to private field"),e.set(t,!0)})(this,r))}},r=new WeakMap,exports.default=((t,e)=>{for(var a,s=e,r=t.length-1;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s})([s.CustomElement({tagName:"router-link",template:e.__SOLELY_IR__,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
- import{routerReady as t,getRouter as e}from"./core.js";import{__SOLELY_IR__ as a}from"./router-link.html.js";import s from"../runtime/component/base-element.js";import{CustomElement as r}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;var o,n=t=>{throw TypeError(t)},i=(t,e,a)=>e.has(t)||n("Cannot "+a);let h=class extends s{constructor(){var t,e;super(...arguments),t=this,(e=o).has(t)?n("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,false)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await t).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",t=>{var a,s;t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||0===t.button&&((null==(a=t.target.closest("a"))?void 0:a.getAttribute("target"))||(t.preventDefault(),null==(s=e())||s.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const t=e();if(!t)return;this.$data.href=t.resolve(this.$data.to);let a=!1;if(this.$data.active)a=!0;else{const e=t.getCurrentRoute();if(e){const t=e.fullPath;a=this.hasAttribute("exact")?t===this.$data.to:t===this.$data.to||t.startsWith(this.$data.to+"/")}}this.$data.isActive=a;const s=this.$data.activeClass||"active";this.classList.toggle(s,a)}prefetchRoute(){if(i(this,t=o,"read from private field"),t.get(this)||!this.hasAttribute("prefetch"))return;var t;const a=e();a&&(a.prefetch(this.$data.to),((t,e)=>{i(t,e,"write to private field"),e.set(t,!0)})(this,o))}};o=new WeakMap,h=((t,e)=>{for(var a,s=e,r=t.length-1;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s})([r({tagName:"router-link",template:a,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"]})],h);export{h as default};
1
+ import{routerReady as t,getRouter as e}from"./core.js";import{__SOLELY_IR__ as a}from"./router-link.html.js";import s from"../runtime/component/base-element.js";import{CustomElement as r}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;var o,n=t=>{throw TypeError(t)},i=(t,e,a)=>e.has(t)||n("Cannot "+a);let h=class extends s{constructor(){var t,e;super(...arguments),t=this,(e=o).has(t)?n("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,false)}set to(t){this.$data.to=t,this.updateState()}get to(){return this.$data.to}async mounted(){(await t()).listen(()=>this.updateState()),this.updateState(),this.addEventListener("click",t=>{var a,s;t.defaultPrevented||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey||0===t.button&&((null==(a=t.target.closest("a"))?void 0:a.getAttribute("target"))||(t.preventDefault(),null==(s=e())||s.push(this.$data.to)))}),this.addEventListener("mouseenter",()=>{this.prefetchRoute()},{once:!0})}updateState(){const t=e();if(!t)return;this.$data.href=t.resolve(this.$data.to);let a=!1;if(this.$data.active)a=!0;else{const e=t.getCurrentRoute();if(e){const t=e.fullPath;a=this.hasAttribute("exact")?t===this.$data.to:t===this.$data.to||t.startsWith(this.$data.to+"/")}}this.$data.isActive=a;const s=this.$data.activeClass||"active";this.classList.toggle(s,a)}prefetchRoute(){if(i(this,t=o,"read from private field"),t.get(this)||!this.hasAttribute("prefetch"))return;var t;const a=e();a&&(a.prefetch(this.$data.to),((t,e)=>{i(t,e,"write to private field"),e.set(t,!0)})(this,o))}};o=new WeakMap,h=((t,e)=>{for(var a,s=e,r=t.length-1;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s})([r({tagName:"router-link",template:a,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"]})],h);export{h as default};
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./core.cjs"),o=require("../runtime/component/base-element.cjs"),n=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const s=new Map;exports.default=class extends o.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,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r.routerReady,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,n=null==t?void 0:t.matched[this.level];if(!n)return void this.handleEmptyRoute();const{config:s}=n;let i=s.tagName;if(!i&&"function"==typeof s.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const n=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await s.component(),n.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(n.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!n.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear();const l=this.getOrCreateComponent(i,s);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&s.has(r)){const t=s.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&s.set(r,o),o}syncState(t,e,r,o={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),s=new Map;Object.entries(e).forEach(([t,e])=>s.set(n(t),String(e))),Object.entries(r).forEach(([t,e])=>s.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{s.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),s.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){var t,e,r;if(this.clear(),0===this.level){const o=null==(t=this.router)?void 0:t.getCurrentRoute(),n=null==(e=null==o?void 0:o.matched)?void 0:e[0],s=null==(r=null==n?void 0:n.config)?void 0:r.notFoundComponent;if(s){const t=document.createElement(s);this.appendChild(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else if(this.$data.notFound){const t=document.createElement(this.$data.notFound);this.appendChild(t),this.currentElement=t,this.currentTagName=this.$data.notFound.toLowerCase()}else 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 e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){for(this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement);this.firstChild;)this.removeChild(this.firstChild);this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}},exports.default=((t,e)=>{for(var r,o=e,n=t.length-1;n>=0;n--)(r=t[n])&&(o=r(o)||o);return o})([n.CustomElement({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],exports.default);
1
+ "use strict";var e=Object.defineProperty,t=(t,r,o)=>((t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o)(t,"symbol"!=typeof r?r+"":r,o);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./core.cjs"),o=require("../runtime/component/base-element.cjs"),s=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const n=new WeakMap;exports.default=class extends o.default{constructor(){super(...arguments),t(this,"unsubscribe"),t(this,"level",0),t(this,"currentElement",null),t(this,"currentTagName",null),t(this,"managedNodes",new Set),t(this,"scheduled",!1),t(this,"latestLoadId",0),t(this,"abortController",null),t(this,"disposed",!1),t(this,"router",null)}async mounted(){this.disposed=!1,this.detectLevel(),this.router=await r.routerReady(),this.disposed||(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),this.loadRoute(this.router.getCurrentRoute()))}unmounted(){var e,t;this.disposed=!0,null==(e=this.abortController)||e.abort(),this.abortController=null,null==(t=this.unsubscribe)||t.call(this),this.clear()}scheduleLoad(){!this.router||this.scheduled||this.disposed||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,!this.disposed&&this.router&&this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let e=0,t=this.parentElement;for(;t;){const r=t.closest("router-view");if(r){if(e++,t=r.parentElement,!t){const e=r.getRootNode();t=e instanceof ShadowRoot?e.host:null}}else{const e=t.getRootNode();t=e instanceof ShadowRoot?e.host:null}}this.level=e}async loadRoute(e){var t,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,s=null==e?void 0:e.matched[this.level];if(!s)return void this.handleEmptyRoute(e);const{config:n}=s;let i=n.tagName;if(!i&&"function"==typeof n.component){this.renderLoading();const s=new AbortController;this.abortController=s;try{const l=null==(r=null==(t=this.router)?void 0:t.getComponentFromCache)?void 0:r.call(t,null==e?void 0:e.fullPath),a=l?await l:await n.component();if(s.signal.aborted||o!==this.latestLoadId||this.disposed)return;i="string"==typeof a?a:a.tagName}catch(l){if(s.signal.aborted||o!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${l}`)}finally{this.abortController===s&&(this.abortController=null)}}if(o===this.latestLoadId&&!this.disposed)if(i)if(!n.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())this.syncState(this.currentElement,(null==e?void 0:e.params)||{},(null==e?void 0:e.query)||{},n.props);else{this.clear();const t=this.getOrCreateComponent(i,n,e);this.syncState(t,(null==e?void 0:e.params)||{},(null==e?void 0:e.query)||{},n.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=i.toLowerCase()}else this.clear()}syncState(e,t,r,o={}){const s=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),i=function(e){let t=n.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},n.set(e,t)),t}(e),l=new Map;Object.entries(t).forEach(([e,t])=>l.set(s(e),String(t))),Object.entries(r).forEach(([e,t])=>l.set(`query-${s(e)}`,String(t))),i.routerAttrs.forEach(t=>{l.has(t)||(e.removeAttribute(t),i.routerAttrs.delete(t))}),l.forEach((t,r)=>{e.getAttribute(r)!==t&&e.setAttribute(r,t),i.routerAttrs.add(r)});const a=new Set(Object.keys(o)),d=e;i.propKeys.forEach(e=>{a.has(e)||(d[e]=void 0)}),Object.entries(o).forEach(([e,t])=>{d[e]!==t&&(d[e]=t)}),i.propKeys=a}getOrCreateComponent(e,t,r){var o,s;if(!r)throw new Error("Route is required to create or retrieve component");const n=t.keepAliveKey?t.keepAliveKey(r,this.level):this.buildKeepAliveKey(e,r),i=t.keepAlive&&(null==(o=this.router)?void 0:o.getKeepAlive(n));if(i)return i;const l=document.createElement(e);return t.keepAlive&&(null==(s=this.router)||s.setKeepAlive(n,l)),l}buildKeepAliveKey(e,t){const r=t.matched[this.level],o=(null==r?void 0:r.config.path)??e.toLowerCase(),s=Object.values((null==r?void 0:r.params)??{});return s.length?`${this.level}:${o}:${s.join("|")}`:`${this.level}:${o}`}handleEmptyRoute(e){var t,r;if(0===this.level){this.clear();const o=null==(t=null==e?void 0:e.matched)?void 0:t[0],s=(null==(r=null==o?void 0:o.config)?void 0:r.notFoundComponent)||this.$data.notFound;if(s){const e=document.createElement(s);this.appendManagedNode(e),this.currentElement=e,this.currentTagName=s.toLowerCase()}else this.renderError("404 Not Found")}else this.clear()}appendManagedNode(e){e.parentNode!==this&&this.appendChild(e),this.managedNodes.add(e)}clear(){this.managedNodes.forEach(e=>{e.parentNode===this&&this.removeChild(e)}),this.managedNodes.clear(),this.currentElement=null,this.currentTagName=null}renderLoading(){this.clear();const e=document.createElement("div");e.style.cssText="padding:20px; color:#999;",e.textContent="Loading...",this.appendManagedNode(e)}renderError(e){this.clear();const t=document.createElement("div");t.style.cssText="padding:20px; color:#ff4d4f;",t.textContent=e,this.appendManagedNode(t)}},exports.default=((e,t)=>{for(var r,o=t,s=e.length-1;s>=0;s--)(r=e[s])&&(o=r(o)||o);return o})([s.CustomElement({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],exports.default);
@@ -7,22 +7,24 @@ declare class RouterView extends BaseElement<{
7
7
  private level;
8
8
  private currentElement;
9
9
  private currentTagName;
10
- private routerAttrs;
11
- private prevPropKeys;
10
+ private managedNodes;
12
11
  private scheduled;
13
12
  private latestLoadId;
14
13
  private abortController;
14
+ private disposed;
15
15
  private router;
16
16
  mounted(): Promise<void>;
17
17
  unmounted(): void;
18
18
  private scheduleLoad;
19
19
  private detectLevel;
20
20
  loadRoute(route: RouteMatch | null): Promise<void>;
21
- private getOrCreateComponent;
22
21
  private syncState;
22
+ private getOrCreateComponent;
23
+ private buildKeepAliveKey;
23
24
  private handleEmptyRoute;
25
+ private appendManagedNode;
26
+ private clear;
24
27
  private renderLoading;
25
28
  private renderError;
26
- private clear;
27
29
  }
28
30
  export default RouterView;
@@ -1 +1 @@
1
- var t=Object.defineProperty,e=(e,r,o)=>((e,r,o)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o)(e,"symbol"!=typeof r?r+"":r,o);import{routerReady as r}from"./core.js";import o from"../runtime/component/base-element.js";import{CustomElement as n}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const s=new Map;let i=class extends o{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,"latestLoadId",0),e(this,"abortController",null),e(this,"router",null)}async mounted(){this.detectLevel(),this.router=await r,this.unsubscribe=this.router.listen(()=>{this.scheduleLoad()}),this.loadRoute(this.router.getCurrentRoute())}unmounted(){var t;null==(t=this.unsubscribe)||t.call(this)}scheduleLoad(){if(!this.router)return;const t=this.router;this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.loadRoute(t.getCurrentRoute())}))}detectLevel(){let t=0,e=this.parentElement;for(;e;){const r=e.closest("router-view");if(r){if(t++,e=r.parentElement,!e){const t=r.getRootNode();e=t instanceof ShadowRoot?t.host:null}}else{const t=e.getRootNode();e=t instanceof ShadowRoot?t.host:null}}this.level=t}async loadRoute(t){var e,r;this.abortController&&(this.abortController.abort(),this.abortController=null);const o=++this.latestLoadId,n=null==t?void 0:t.matched[this.level];if(!n)return void this.handleEmptyRoute();const{config:s}=n;let i=s.tagName;if(!i&&"function"==typeof s.component){this.clear(),this.renderLoading(),this.abortController=new AbortController;const n=this.abortController.signal;try{let l;const a=null==(r=null==(e=this.router)?void 0:e.getComponentFromCache)?void 0:r.call(e,null==t?void 0:t.fullPath);if(l=a?await a:await s.component(),n.aborted||o!==this.latestLoadId)return;i="string"==typeof l?l:l.tagName}catch(a){if(n.aborted||o!==this.latestLoadId)return;return this.renderError(`Load Error: ${a}`),this.currentElement=null,void(this.currentTagName=null)}finally{this.abortController&&!n.aborted&&(this.abortController=null)}}if(o!==this.latestLoadId)return;if(!i)return void this.clear();if(!s.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())return void this.syncState(this.currentElement,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props);this.clear();const l=this.getOrCreateComponent(i,s);this.syncState(l,null==t?void 0:t.params,(null==t?void 0:t.query)||{},s.props),this.appendChild(l),this.currentElement=l,this.currentTagName=i.toLowerCase()}getOrCreateComponent(t,e){const r=`${this.level}-${t.toLowerCase()}`;if(e.keepAlive&&s.has(r)){const t=s.get(r);if(t)return t}const o=document.createElement(t);return e.keepAlive&&s.set(r,o),o}syncState(t,e,r,o={}){const n=t=>t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),s=new Map;Object.entries(e).forEach(([t,e])=>s.set(n(t),String(e))),Object.entries(r).forEach(([t,e])=>s.set(`query-${n(t)}`,String(e))),this.routerAttrs.forEach(e=>{s.has(e)||(t.removeAttribute(e),this.routerAttrs.delete(e))}),s.forEach((e,r)=>{t.getAttribute(r)!==e&&t.setAttribute(r,e),this.routerAttrs.add(r)});const i=new Set(Object.keys(o));this.prevPropKeys.forEach(e=>{i.has(e)||(t[e]=void 0)}),Object.entries(o).forEach(([e,r])=>{t[e]!==r&&(t[e]=r)}),this.prevPropKeys=i}handleEmptyRoute(){var t,e,r;if(this.clear(),0===this.level){const o=null==(t=this.router)?void 0:t.getCurrentRoute(),n=null==(e=null==o?void 0:o.matched)?void 0:e[0],s=null==(r=null==n?void 0:n.config)?void 0:r.notFoundComponent;if(s){const t=document.createElement(s);this.appendChild(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else if(this.$data.notFound){const t=document.createElement(this.$data.notFound);this.appendChild(t),this.currentElement=t,this.currentTagName=this.$data.notFound.toLowerCase()}else 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 e=document.createElement("div");e.style.cssText="padding:20px; color:#ff4d4f;",e.textContent=String(t),this.appendChild(e)}clear(){for(this.currentElement&&this.contains(this.currentElement)&&this.removeChild(this.currentElement);this.firstChild;)this.removeChild(this.firstChild);this.currentElement=null,this.currentTagName=null,this.routerAttrs.clear(),this.prevPropKeys.clear()}};i=((t,e)=>{for(var r,o=e,n=t.length-1;n>=0;n--)(r=t[n])&&(o=r(o)||o);return o})([n({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],i);export{i as default};
1
+ var e=Object.defineProperty,t=(t,o,r)=>((t,o,r)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[o]=r)(t,"symbol"!=typeof o?o+"":o,r);import{routerReady as o}from"./core.js";import r from"../runtime/component/base-element.js";import{CustomElement as s}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const n=new WeakMap;let i=class extends r{constructor(){super(...arguments),t(this,"unsubscribe"),t(this,"level",0),t(this,"currentElement",null),t(this,"currentTagName",null),t(this,"managedNodes",new Set),t(this,"scheduled",!1),t(this,"latestLoadId",0),t(this,"abortController",null),t(this,"disposed",!1),t(this,"router",null)}async mounted(){this.disposed=!1,this.detectLevel(),this.router=await o(),this.disposed||(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),this.loadRoute(this.router.getCurrentRoute()))}unmounted(){var e,t;this.disposed=!0,null==(e=this.abortController)||e.abort(),this.abortController=null,null==(t=this.unsubscribe)||t.call(this),this.clear()}scheduleLoad(){!this.router||this.scheduled||this.disposed||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,!this.disposed&&this.router&&this.loadRoute(this.router.getCurrentRoute())}))}detectLevel(){let e=0,t=this.parentElement;for(;t;){const o=t.closest("router-view");if(o){if(e++,t=o.parentElement,!t){const e=o.getRootNode();t=e instanceof ShadowRoot?e.host:null}}else{const e=t.getRootNode();t=e instanceof ShadowRoot?e.host:null}}this.level=e}async loadRoute(e){var t,o;this.abortController&&(this.abortController.abort(),this.abortController=null);const r=++this.latestLoadId,s=null==e?void 0:e.matched[this.level];if(!s)return void this.handleEmptyRoute(e);const{config:n}=s;let i=n.tagName;if(!i&&"function"==typeof n.component){this.renderLoading();const s=new AbortController;this.abortController=s;try{const l=null==(o=null==(t=this.router)?void 0:t.getComponentFromCache)?void 0:o.call(t,null==e?void 0:e.fullPath),a=l?await l:await n.component();if(s.signal.aborted||r!==this.latestLoadId||this.disposed)return;i="string"==typeof a?a:a.tagName}catch(l){if(s.signal.aborted||r!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${l}`)}finally{this.abortController===s&&(this.abortController=null)}}if(r===this.latestLoadId&&!this.disposed)if(i)if(!n.forceReload&&this.currentElement&&this.currentTagName===i.toLowerCase())this.syncState(this.currentElement,(null==e?void 0:e.params)||{},(null==e?void 0:e.query)||{},n.props);else{this.clear();const t=this.getOrCreateComponent(i,n,e);this.syncState(t,(null==e?void 0:e.params)||{},(null==e?void 0:e.query)||{},n.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=i.toLowerCase()}else this.clear()}syncState(e,t,o,r={}){const s=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),i=function(e){let t=n.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},n.set(e,t)),t}(e),l=new Map;Object.entries(t).forEach(([e,t])=>l.set(s(e),String(t))),Object.entries(o).forEach(([e,t])=>l.set(`query-${s(e)}`,String(t))),i.routerAttrs.forEach(t=>{l.has(t)||(e.removeAttribute(t),i.routerAttrs.delete(t))}),l.forEach((t,o)=>{e.getAttribute(o)!==t&&e.setAttribute(o,t),i.routerAttrs.add(o)});const a=new Set(Object.keys(r)),d=e;i.propKeys.forEach(e=>{a.has(e)||(d[e]=void 0)}),Object.entries(r).forEach(([e,t])=>{d[e]!==t&&(d[e]=t)}),i.propKeys=a}getOrCreateComponent(e,t,o){var r,s;if(!o)throw new Error("Route is required to create or retrieve component");const n=t.keepAliveKey?t.keepAliveKey(o,this.level):this.buildKeepAliveKey(e,o),i=t.keepAlive&&(null==(r=this.router)?void 0:r.getKeepAlive(n));if(i)return i;const l=document.createElement(e);return t.keepAlive&&(null==(s=this.router)||s.setKeepAlive(n,l)),l}buildKeepAliveKey(e,t){const o=t.matched[this.level],r=(null==o?void 0:o.config.path)??e.toLowerCase(),s=Object.values((null==o?void 0:o.params)??{});return s.length?`${this.level}:${r}:${s.join("|")}`:`${this.level}:${r}`}handleEmptyRoute(e){var t,o;if(0===this.level){this.clear();const r=null==(t=null==e?void 0:e.matched)?void 0:t[0],s=(null==(o=null==r?void 0:r.config)?void 0:o.notFoundComponent)||this.$data.notFound;if(s){const e=document.createElement(s);this.appendManagedNode(e),this.currentElement=e,this.currentTagName=s.toLowerCase()}else this.renderError("404 Not Found")}else this.clear()}appendManagedNode(e){e.parentNode!==this&&this.appendChild(e),this.managedNodes.add(e)}clear(){this.managedNodes.forEach(e=>{e.parentNode===this&&this.removeChild(e)}),this.managedNodes.clear(),this.currentElement=null,this.currentTagName=null}renderLoading(){this.clear();const e=document.createElement("div");e.style.cssText="padding:20px; color:#999;",e.textContent="Loading...",this.appendManagedNode(e)}renderError(e){this.clear();const t=document.createElement("div");t.style.cssText="padding:20px; color:#ff4d4f;",t.textContent=e,this.appendManagedNode(t)}};i=((e,t)=>{for(var o,r=t,s=e.length-1;s>=0;s--)(o=e[s])&&(r=o(r)||r);return r})([s({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],i);export{i as default};
@@ -17,6 +17,11 @@ export interface RouteConfig {
17
17
  * 开启后,切换路由时组件不会被销毁,而是保存在 RouterView 的缓存池中。
18
18
  */
19
19
  keepAlive?: boolean;
20
+ /** * 自定义 keepAlive 缓存 key。
21
+ * 默认使用 route.fullPath,动态路由如 /article/:id 会按不同 id 分别缓存。
22
+ * 如果希望同一路由模板共享缓存,可设为 (route) => route.matched[level].config.path
23
+ */
24
+ keepAliveKey?: (route: RouteMatch, level: number) => string;
20
25
  /** * 是否强制重新加载。
21
26
  * 即使 tagName 相同,如果为 true,也会销毁重建组件而不是复用。
22
27
  */
@@ -60,6 +65,8 @@ export interface RouterOptions {
60
65
  mode?: 'hash' | 'history';
61
66
  beforeEach?: NavigationGuard;
62
67
  afterEach?: (to: RouteMatch, from: RouteMatch | null) => void;
68
+ /** keepAlive 最大缓存数量,超出后淘汰最久未访问的实例。默认不限制 */
69
+ maxKeepAlive?: number;
63
70
  }
64
71
  export interface NavigationResult {
65
72
  success: boolean;
@@ -1 +1 @@
1
- "use strict";var t,e,s,i,a,r,n,o,h,l,c,u,d,p,f,b,m,y,v,w,g,S,M,O,$,k,j,W,C,N,A,E=Object.defineProperty,P=t=>{throw TypeError(t)},L=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(L(t,e,"read from private field"),s?s.call(t):e.get(t)),q=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),U=(t,e,s,i)=>(L(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),_=(t,e,s)=>(L(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("../../shared/is-object.cjs"),T=require("../../shared/env.cjs"),x=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),V=require("../renderer/renderIR.cjs"),H=Symbol.for("solely.manifest"),J=class extends HTMLElement{constructor(m={}){var y,w;super(),q(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),q(this,t),q(this,e),q(this,s),q(this,i),q(this,a),q(this,r),q(this,n,!1),q(this,o,!1),q(this,h,!1),q(this,l,!1),q(this,c,!1),q(this,u,!1),q(this,d,!1),q(this,p,new Set),q(this,f,!1),q(this,b,!1);const S=this.constructor;U(this,t,S[H]||{tagName:"base-element"});const O=D(this,t);U(this,a,(null==(y=O.shadowDOM)?void 0:y.use)?this.attachShadow({mode:O.shadowDOM.mode||"open"}):this),_(this,v,g).call(this,m),_(this,v,M).call(this,O),queueMicrotask(()=>_(this,v,A).call(this))}static get observedAttributes(){const t=this[H];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;R.isObject(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),_(this,v,g).call(this,t),_(this,v,$).call(this),_(this,v,j).call(this))}refresh(){_(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);U(this,c,!0);const i=D(this,t);if(_(this,v,A).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),_(this,v,C).call(this),i.attributeMap&&R.isObject(this.$data)){_(this,v,$).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=_(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}_(this,v,w).call(this),D(this,s)&&!D(this,e)&&U(this,e,V.createRender(D(this,s),D(this,a),this)),D(this,u)&&(U(this,u,!1),_(this,v,j).call(this)),this.mounted()}disconnectedCallback(){U(this,c,!1),D(this,f)||_(this,v,N).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!R.isObject(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const n=r.name,o=this.$data[n],l=_(this,v,k).call(this,i,r.default??o,r.type);o!==l&&(U(this,h,!0),this.$data[n]=l,this.attributeChanged(e,o,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(U(this,f,!0),U(this,c,!1),_(this,v,N).call(this),null==(t=D(this,e))||t.destroy(),U(this,e,void 0),null==(s=D(this,r))||s.call(this),U(this,r,void 0))}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(J,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,n=i.get(r);(null==n?void 0:n.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),n=String(i),o=null==(s=r.propMap)?void 0:s.get(n);(null==o?void 0:o.reflect)&&_(this,v,S).call(this,o,a)}this.emit("dataChange",{...e}),_(this,v,j).call(this)});U(this,i,s),U(this,r,a)},S=function(t,e){const s=x.camelToKebab(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);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)}}finally{D(this,p).delete(s)}},M=function(t){t.ir&&U(this,s,t.ir)},O=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},$=function(){D(this,d)||(U(this,d,!0),_(this,v,O).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&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(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,o)&&D(this,e)&&(U(this,o,!0),queueMicrotask(()=>{D(this,f)||(U(this,o,!1),_(this,v,W).call(this))})):U(this,u,!0))},W=function(){var t;if(!D(this,f)&&!D(this,n)&&D(this,c)){U(this,n,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),U(this,h,!1))}finally{U(this,n,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void U(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,n=`solely-style-${T.SOLELY_VERSION}-${s.tagName}`,o=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(n):n.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=n,t.textContent=s.styles,r.appendChild(t)}if(o){const t=D(J,m).get(n)||0;D(J,m).set(n,t+1),U(this,b,!0)}},N=function(){var e,s;if(!D(this,b))return;U(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${T.SOLELY_VERSION}-${i.tagName}`,e=D(J,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(J,m).delete(t)}else D(J,m).set(t,e-1)}},A=function(){D(this,l)||(U(this,l,!0),this.created())},q(J,m,new Map),q(J,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let F=J;exports.default=F;
1
+ "use strict";var t,e,s,i,a,r,n,o,h,l,c,u,d,p,f,b,m,y,v,w,g,S,M,O,$,k,j,W,C,N,A,E=Object.defineProperty,P=t=>{throw TypeError(t)},L=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(L(t,e,"read from private field"),s?s.call(t):e.get(t)),q=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),U=(t,e,s,i)=>(L(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),_=(t,e,s)=>(L(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("../../shared/is-object.cjs"),T=require("../../shared/env.cjs"),x=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),V=require("../renderer/renderIR.cjs"),H=Symbol.for("solely.manifest"),J=class extends HTMLElement{constructor(m={}){var y,w;super(),q(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),q(this,t),q(this,e),q(this,s),q(this,i),q(this,a),q(this,r),q(this,n,!1),q(this,o,!1),q(this,h,!1),q(this,l,!1),q(this,c,!1),q(this,u,!1),q(this,d,!1),q(this,p,new Set),q(this,f,!1),q(this,b,!1);const S=this.constructor;U(this,t,S[H]||{tagName:"base-element"});const O=D(this,t);U(this,a,(null==(y=O.shadowDOM)?void 0:y.use)?this.attachShadow({mode:O.shadowDOM.mode||"open"}):this),_(this,v,g).call(this,m),_(this,v,M).call(this,O),queueMicrotask(()=>_(this,v,A).call(this))}static get observedAttributes(){const t=this[H];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;R.isObject(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),_(this,v,g).call(this,t),_(this,v,$).call(this),_(this,v,j).call(this))}refresh(){_(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw this.remove(),new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);U(this,c,!0);const i=D(this,t);if(_(this,v,A).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),_(this,v,C).call(this),i.attributeMap&&R.isObject(this.$data)){_(this,v,$).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=_(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}_(this,v,w).call(this),D(this,s)&&!D(this,e)&&U(this,e,V.createRender(D(this,s),D(this,a),this)),D(this,u)&&(U(this,u,!1),_(this,v,j).call(this)),this.mounted()}disconnectedCallback(){U(this,c,!1),D(this,f)||_(this,v,N).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!R.isObject(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const n=r.name,o=this.$data[n],l=_(this,v,k).call(this,i,r.default??o,r.type);o!==l&&(U(this,h,!0),this.$data[n]=l,this.attributeChanged(e,o,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(U(this,f,!0),U(this,c,!1),_(this,v,N).call(this),null==(t=D(this,e))||t.destroy(),U(this,e,void 0),null==(s=D(this,r))||s.call(this),U(this,r,void 0),this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(J,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,n=i.get(r);(null==n?void 0:n.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),n=String(i),o=null==(s=r.propMap)?void 0:s.get(n);(null==o?void 0:o.reflect)&&_(this,v,S).call(this,o,a)}this.emit("dataChange",{...e}),_(this,v,j).call(this)});U(this,i,s),U(this,r,a)},S=function(t,e){const s=x.camelToKebab(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);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)}}finally{D(this,p).delete(s)}},M=function(t){t.ir&&U(this,s,t.ir)},O=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},$=function(){D(this,d)||(U(this,d,!0),_(this,v,O).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&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(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,o)&&D(this,e)&&(U(this,o,!0),queueMicrotask(()=>{D(this,f)||(U(this,o,!1),_(this,v,W).call(this))})):U(this,u,!0))},W=function(){var t;if(!D(this,f)&&!D(this,n)&&D(this,c)){U(this,n,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),U(this,h,!1))}finally{U(this,n,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void U(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,n=`solely-style-${T.SOLELY_VERSION}-${s.tagName}`,o=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(n):n.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=n,t.textContent=s.styles,r.appendChild(t)}if(o){const t=D(J,m).get(n)||0;D(J,m).set(n,t+1),U(this,b,!0)}},N=function(){var e,s;if(!D(this,b))return;U(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${T.SOLELY_VERSION}-${i.tagName}`,e=D(J,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(J,m).delete(t)}else D(J,m).set(t,e-1)}},A=function(){D(this,l)||(U(this,l,!0),this.created())},q(J,m,new Map),q(J,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let F=J;exports.default=F;
@@ -32,7 +32,7 @@ declare class BaseElement<TData extends object = Record<string, unknown>, TRefs
32
32
  */
33
33
  protected error(condition: boolean, message: string): void;
34
34
  /**
35
- * 显式销毁组件,清理 renderer 等资源。
35
+ * 显式销毁组件,清理 renderer 等资源,并从 DOM 中移除。
36
36
  * 适用于确认组件不再 reconnect 的场景。
37
37
  * 调用后如需重新使用组件,需重新创建实例。
38
38
  */
@@ -1 +1 @@
1
- var t,e,s,i,a,r,o,n,h,l,c,d,u,p,f,b,m,y,v,w,g,M,S,$,O,k,j,W,C,A,N,E=Object.defineProperty,P=t=>{throw TypeError(t)},U=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(U(t,e,"read from private field"),s?s.call(t):e.get(t)),L=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),q=(t,e,s,i)=>(U(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),x=(t,e,s)=>(U(t,e,"access private method"),s);import{isObject as T}from"../../shared/is-object.js";import{SOLELY_VERSION as H,IS_DEV as J}from"../../shared/env.js";import{camelToKebab as R}from"../../shared/case-convert.js";import{observe as F}from"../reactivity/observe.js";import{createRender as I}from"../renderer/renderIR.js";const V=Symbol.for("solely.manifest"),_=class extends HTMLElement{constructor(m={}){var y,w;super(),L(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),L(this,t),L(this,e),L(this,s),L(this,i),L(this,a),L(this,r),L(this,o,!1),L(this,n,!1),L(this,h,!1),L(this,l,!1),L(this,c,!1),L(this,d,!1),L(this,u,!1),L(this,p,new Set),L(this,f,!1),L(this,b,!1);const M=this.constructor;q(this,t,M[V]||{tagName:"base-element"});const $=D(this,t);q(this,a,(null==(y=$.shadowDOM)?void 0:y.use)?this.attachShadow({mode:$.shadowDOM.mode||"open"}):this),x(this,v,g).call(this,m),x(this,v,S).call(this,$),queueMicrotask(()=>x(this,v,N).call(this))}static get observedAttributes(){const t=this[V];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;T(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),x(this,v,g).call(this,t),x(this,v,O).call(this),x(this,v,j).call(this))}refresh(){x(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);q(this,c,!0);const i=D(this,t);if(x(this,v,N).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),x(this,v,C).call(this),i.attributeMap&&T(this.$data)){x(this,v,O).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=x(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}x(this,v,w).call(this),D(this,s)&&!D(this,e)&&q(this,e,I(D(this,s),D(this,a),this)),D(this,d)&&(q(this,d,!1),x(this,v,j).call(this)),this.mounted()}disconnectedCallback(){q(this,c,!1),D(this,f)||x(this,v,A).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!T(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const o=r.name,n=this.$data[o],l=x(this,v,k).call(this,i,r.default??n,r.type);n!==l&&(q(this,h,!0),this.$data[o]=l,this.attributeChanged(e,n,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(q(this,f,!0),q(this,c,!1),x(this,v,A).call(this),null==(t=D(this,e))||t.destroy(),q(this,e,void 0),null==(s=D(this,r))||s.call(this),q(this,r,void 0))}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,o=new WeakMap,n=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(_,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,o=i.get(r);(null==o?void 0:o.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=F(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),o=String(i),n=null==(s=r.propMap)?void 0:s.get(o);(null==n?void 0:n.reflect)&&x(this,v,M).call(this,n,a)}this.emit("dataChange",{...e}),x(this,v,j).call(this)});q(this,i,s),q(this,r,a)},M=function(t,e){const s=R(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);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)}}finally{D(this,p).delete(s)}},S=function(t){t.ir&&q(this,s,t.ir)},$=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},O=function(){D(this,u)||(q(this,u,!0),x(this,v,$).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&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(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,n)&&D(this,e)&&(q(this,n,!0),queueMicrotask(()=>{D(this,f)||(q(this,n,!1),x(this,v,W).call(this))})):q(this,d,!0))},W=function(){var t;if(!D(this,f)&&!D(this,o)&&D(this,c)){q(this,o,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),q(this,h,!1))}finally{q(this,o,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void q(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,o=`solely-style-${H}-${s.tagName}`,n=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(o):o.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=o,t.textContent=s.styles,r.appendChild(t)}if(n){const t=D(_,m).get(o)||0;D(_,m).set(o,t+1),q(this,b,!0)}},A=function(){var e,s;if(!D(this,b))return;q(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${H}-${i.tagName}`,e=D(_,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(_,m).delete(t)}else D(_,m).set(t,e-1)}},N=function(){D(this,l)||(q(this,l,!0),this.created())},L(_,m,new Map),L(_,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let z=_;export{z as default};
1
+ var t,e,s,i,a,r,o,n,h,l,c,d,u,p,f,b,m,y,v,w,g,M,S,$,O,k,j,W,C,A,N,E=Object.defineProperty,P=t=>{throw TypeError(t)},U=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(U(t,e,"read from private field"),s?s.call(t):e.get(t)),L=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),q=(t,e,s,i)=>(U(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),x=(t,e,s)=>(U(t,e,"access private method"),s);import{isObject as T}from"../../shared/is-object.js";import{SOLELY_VERSION as H,IS_DEV as J}from"../../shared/env.js";import{camelToKebab as R}from"../../shared/case-convert.js";import{observe as F}from"../reactivity/observe.js";import{createRender as I}from"../renderer/renderIR.js";const V=Symbol.for("solely.manifest"),_=class extends HTMLElement{constructor(m={}){var y,w;super(),L(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),L(this,t),L(this,e),L(this,s),L(this,i),L(this,a),L(this,r),L(this,o,!1),L(this,n,!1),L(this,h,!1),L(this,l,!1),L(this,c,!1),L(this,d,!1),L(this,u,!1),L(this,p,new Set),L(this,f,!1),L(this,b,!1);const M=this.constructor;q(this,t,M[V]||{tagName:"base-element"});const $=D(this,t);q(this,a,(null==(y=$.shadowDOM)?void 0:y.use)?this.attachShadow({mode:$.shadowDOM.mode||"open"}):this),x(this,v,g).call(this,m),x(this,v,S).call(this,$),queueMicrotask(()=>x(this,v,N).call(this))}static get observedAttributes(){const t=this[V];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;T(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),x(this,v,g).call(this,t),x(this,v,O).call(this),x(this,v,j).call(this))}refresh(){x(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw this.remove(),new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);q(this,c,!0);const i=D(this,t);if(x(this,v,N).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),x(this,v,C).call(this),i.attributeMap&&T(this.$data)){x(this,v,O).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=x(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}x(this,v,w).call(this),D(this,s)&&!D(this,e)&&q(this,e,I(D(this,s),D(this,a),this)),D(this,d)&&(q(this,d,!1),x(this,v,j).call(this)),this.mounted()}disconnectedCallback(){q(this,c,!1),D(this,f)||x(this,v,A).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!T(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const o=r.name,n=this.$data[o],l=x(this,v,k).call(this,i,r.default??n,r.type);n!==l&&(q(this,h,!0),this.$data[o]=l,this.attributeChanged(e,n,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(q(this,f,!0),q(this,c,!1),x(this,v,A).call(this),null==(t=D(this,e))||t.destroy(),q(this,e,void 0),null==(s=D(this,r))||s.call(this),q(this,r,void 0),this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,o=new WeakMap,n=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(_,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,o=i.get(r);(null==o?void 0:o.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=F(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),o=String(i),n=null==(s=r.propMap)?void 0:s.get(o);(null==n?void 0:n.reflect)&&x(this,v,M).call(this,n,a)}this.emit("dataChange",{...e}),x(this,v,j).call(this)});q(this,i,s),q(this,r,a)},M=function(t,e){const s=R(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);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)}}finally{D(this,p).delete(s)}},S=function(t){t.ir&&q(this,s,t.ir)},$=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},O=function(){D(this,u)||(q(this,u,!0),x(this,v,$).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&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(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,n)&&D(this,e)&&(q(this,n,!0),queueMicrotask(()=>{D(this,f)||(q(this,n,!1),x(this,v,W).call(this))})):q(this,d,!0))},W=function(){var t;if(!D(this,f)&&!D(this,o)&&D(this,c)){q(this,o,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),q(this,h,!1))}finally{q(this,o,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void q(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,o=`solely-style-${H}-${s.tagName}`,n=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(o):o.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=o,t.textContent=s.styles,r.appendChild(t)}if(n){const t=D(_,m).get(o)||0;D(_,m).set(o,t+1),q(this,b,!0)}},A=function(){var e,s;if(!D(this,b))return;q(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${H}-${i.tagName}`,e=D(_,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(_,m).delete(t)}else D(_,m).set(t,e-1)}},N=function(){D(this,l)||(q(this,l,!0),this.created())},L(_,m,new Map),L(_,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let z=_;export{z as default};
@@ -1 +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;const e=globalThis;if(!0===e.__DEBUG__||!0===e.__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,exports.SOLELY_VERSION="0.5.0";
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;const e=globalThis;if(!0===e.__DEBUG__||!0===e.__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,exports.SOLELY_VERSION="0.5.2";
@@ -1 +1 @@
1
- const n=(()=>{var n,o;if("undefined"!=typeof window){if(null==(n=window.location)?void 0:n.search.includes("debug"))return!0;const o=globalThis;if(!0===o.__DEBUG__||!0===o.__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,i="0.5.0";export{n as IS_DEV,o as IS_PROD,i as SOLELY_VERSION};
1
+ const n=(()=>{var n,o;if("undefined"!=typeof window){if(null==(n=window.location)?void 0:n.search.includes("debug"))return!0;const o=globalThis;if(!0===o.__DEBUG__||!0===o.__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,i="0.5.2";export{n as IS_DEV,o as IS_PROD,i as SOLELY_VERSION};
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
- "sideEffects": false,
7
+ "sideEffects": [
8
+ "*.css",
9
+ "**/*.css?inline",
10
+ "**/*.css?raw",
11
+ "src/components/elements/*/index.ts",
12
+ "dist/components/elements/*/index.js",
13
+ "dist/components/elements/*/index.cjs",
14
+ "src/components/commands/*/index.ts",
15
+ "dist/components/commands/*/index.js",
16
+ "dist/components/commands/*/index.cjs"
17
+ ],
8
18
  "main": "./dist/index.cjs",
9
19
  "module": "./dist/index.js",
10
20
  "types": "./dist/index.d.ts",
@@ -99,6 +109,16 @@
99
109
  "default": "./dist/components/elements/index.cjs"
100
110
  }
101
111
  },
112
+ "./components/elements/*": {
113
+ "import": {
114
+ "types": "./dist/components/elements/*/index.d.ts",
115
+ "default": "./dist/components/elements/*/index.js"
116
+ },
117
+ "require": {
118
+ "types": "./dist/components/elements/*/index.d.ts",
119
+ "default": "./dist/components/elements/*/index.cjs"
120
+ }
121
+ },
102
122
  "./components/commands": {
103
123
  "import": {
104
124
  "types": "./dist/components/commands/index.d.ts",
@@ -109,6 +129,16 @@
109
129
  "default": "./dist/components/commands/index.cjs"
110
130
  }
111
131
  },
132
+ "./components/commands/*": {
133
+ "import": {
134
+ "types": "./dist/components/commands/*/index.d.ts",
135
+ "default": "./dist/components/commands/*/index.js"
136
+ },
137
+ "require": {
138
+ "types": "./dist/components/commands/*/index.d.ts",
139
+ "default": "./dist/components/commands/*/index.cjs"
140
+ }
141
+ },
112
142
  "./components/theme": {
113
143
  "import": {
114
144
  "types": "./dist/components/theme/index.d.ts",