solely 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +92 -27
  2. package/dist/compiler/ir/buildIR.cjs +1 -1
  3. package/dist/compiler/ir/buildIR.js +1 -1
  4. package/dist/compiler/parser/parser.cjs +1 -1
  5. package/dist/compiler/parser/parser.js +1 -1
  6. package/dist/components/commands/message/index.cjs +1 -1
  7. package/dist/components/commands/message/index.js +1 -1
  8. package/dist/components/elements/alert/index.html.cjs +1 -1
  9. package/dist/components/elements/alert/index.html.js +1 -1
  10. package/dist/components/elements/badge/index.html.cjs +1 -1
  11. package/dist/components/elements/badge/index.html.js +1 -1
  12. package/dist/components/elements/breadcrumb/index.html.cjs +1 -1
  13. package/dist/components/elements/breadcrumb/index.html.js +1 -1
  14. package/dist/components/elements/button/index.html.cjs +1 -1
  15. package/dist/components/elements/button/index.html.js +1 -1
  16. package/dist/components/elements/card/index.html.cjs +1 -1
  17. package/dist/components/elements/card/index.html.js +1 -1
  18. package/dist/components/elements/checkbox/index.html.cjs +1 -1
  19. package/dist/components/elements/checkbox/index.html.js +1 -1
  20. package/dist/components/elements/coordinate-input/index.html.cjs +1 -1
  21. package/dist/components/elements/coordinate-input/index.html.js +1 -1
  22. package/dist/components/elements/fab/index.html.cjs +1 -1
  23. package/dist/components/elements/fab/index.html.js +1 -1
  24. package/dist/components/elements/input/index.html.cjs +1 -1
  25. package/dist/components/elements/input/index.html.js +1 -1
  26. package/dist/components/elements/not-found/index.html.cjs +1 -1
  27. package/dist/components/elements/not-found/index.html.js +1 -1
  28. package/dist/components/elements/pagination/index.html.cjs +1 -1
  29. package/dist/components/elements/pagination/index.html.js +1 -1
  30. package/dist/components/elements/progress/index.html.cjs +1 -1
  31. package/dist/components/elements/progress/index.html.js +1 -1
  32. package/dist/components/elements/radio/index.html.cjs +1 -1
  33. package/dist/components/elements/radio/index.html.js +1 -1
  34. package/dist/components/elements/select/index.html.cjs +1 -1
  35. package/dist/components/elements/select/index.html.js +1 -1
  36. package/dist/components/elements/skeleton/index.html.cjs +1 -1
  37. package/dist/components/elements/skeleton/index.html.js +1 -1
  38. package/dist/components/elements/slider/index.html.cjs +1 -1
  39. package/dist/components/elements/slider/index.html.js +1 -1
  40. package/dist/components/elements/steps/index.html.cjs +1 -1
  41. package/dist/components/elements/steps/index.html.js +1 -1
  42. package/dist/components/elements/switch/index.html.cjs +1 -1
  43. package/dist/components/elements/switch/index.html.js +1 -1
  44. package/dist/components/elements/table/index.html.cjs +1 -1
  45. package/dist/components/elements/table/index.html.js +1 -1
  46. package/dist/components/elements/tabs/index.html.cjs +1 -1
  47. package/dist/components/elements/tabs/index.html.js +1 -1
  48. package/dist/components/elements/tag/index.html.cjs +1 -1
  49. package/dist/components/elements/tag/index.html.js +1 -1
  50. package/dist/components/elements/timeline/index.html.cjs +1 -1
  51. package/dist/components/elements/timeline/index.html.js +1 -1
  52. package/dist/components/elements/tooltip/index.html.cjs +1 -1
  53. package/dist/components/elements/tooltip/index.html.js +1 -1
  54. package/dist/components/elements/tree/index.html.cjs +1 -1
  55. package/dist/components/elements/tree/index.html.js +1 -1
  56. package/dist/components/elements/upload/index.html.cjs +1 -1
  57. package/dist/components/elements/upload/index.html.js +1 -1
  58. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  59. package/dist/plugins/solely-vite-plugin.d.ts +10 -1
  60. package/dist/plugins/solely-vite-plugin.js +1 -1
  61. package/dist/router/core.cjs +1 -1
  62. package/dist/router/core.d.ts +30 -0
  63. package/dist/router/core.js +1 -1
  64. package/dist/router/router-view.cjs +1 -1
  65. package/dist/router/router-view.d.ts +10 -0
  66. package/dist/router/router-view.js +1 -1
  67. package/dist/router/types.d.ts +3 -1
  68. package/dist/runtime/component/base-element.cjs +1 -1
  69. package/dist/runtime/component/base-element.d.ts +8 -1
  70. package/dist/runtime/component/base-element.js +1 -1
  71. package/dist/runtime/component/decorators.d.ts +7 -0
  72. package/dist/runtime/reactivity/observe.cjs +1 -1
  73. package/dist/runtime/reactivity/observe.d.ts +1 -0
  74. package/dist/runtime/reactivity/observe.js +1 -1
  75. package/dist/runtime/renderer/html-decode.cjs +1 -1
  76. package/dist/runtime/renderer/html-decode.js +1 -1
  77. package/dist/runtime/renderer/renderIR.cjs +1 -1
  78. package/dist/runtime/renderer/renderIR.js +1 -1
  79. package/dist/shared/env.cjs +1 -1
  80. package/dist/shared/env.js +1 -1
  81. package/dist/shared/svg-sanitize.cjs +1 -1
  82. package/dist/shared/svg-sanitize.js +1 -1
  83. package/dist/types/ir.d.ts +2 -2
  84. package/package.json +6 -3
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../shared/env.cjs");let t=null,s=null,i=null;function r(){return t?Promise.resolve(t):(i||(i=new Promise(e=>{s=e})),i)}const a=(()=>{const e=()=>r();return Object.defineProperties(e,{then:{value:(e,t)=>r().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>r().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>r().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})();class n{routes;base;mode;beforeEachGuard;afterEachGuard;currentRoute=null;listeners=new Set;componentCache=new Map;keepAliveCache=new Map;keepAliveKeys=[];navigationId=0;maxKeepAlive;constructor(e){this.routes=e.routes,this.base=this.normalizeBase(e.base),this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}normalizeBase(e){let t=e||"/";return t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}static MAX_REDIRECTS=20;matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,s,i){if(i>=n.MAX_REDIRECTS)return e.IS_DEV&&console.error(`[Router] Too many redirects (max ${n.MAX_REDIRECTS}), last path: ${t}`),null;const r=this.normalizePath(t);if(s.has(r))return e.IS_DEV&&console.error(`[Router] Circular redirect detected: ${r}`),null;s.add(r);const[a,h]=r.split("?"),o=a.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,s,i+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 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}Object.defineProperty(s,a.slice(1),{value:n,writable:!0,enumerable:!0,configurable:!0})}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)=>{Object.defineProperty(t,s,{value:e,writable:!0,enumerable:!0,configurable:!0})}),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!==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())}isStarted=!1;handleRouteChange=null;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,t=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(!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))}}exports.Router=n,exports.createRouter=function(e){return t||(t=new n(e),s&&s(t),s=null,i=null,t)},exports.getRouter=function(){return t},exports.routerReady=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../shared/env.cjs");let t=null,i=null,s=null;function r(){return t?Promise.resolve(t):(s||(s=new Promise(e=>{i=e})),s)}const a=(()=>{const e=()=>r();return Object.defineProperties(e,{then:{value:(e,t)=>r().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>r().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>r().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})();class n{routes;base;mode;beforeEachGuard;afterEachGuard;currentRoute=null;listeners=new Set;componentCache=new Map;keepAliveCache=new Map;keepAliveKeys=[];navigationId=0;maxKeepAlive;navigated=!1;pendingNavId=null;readyDeferred=null;constructor(e){this.routes=e.routes,this.base=this.normalizeBase(e.base),this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}normalizeBase(e){let t=e||"/";return t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}static MAX_REDIRECTS=20;matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,i,s){if(s>=n.MAX_REDIRECTS)return e.IS_DEV&&console.error(`[Router] Too many redirects (max ${n.MAX_REDIRECTS}), last path: ${t}`),null;const r=this.normalizePath(t);if(i.has(r))return e.IS_DEV&&console.error(`[Router] Circular redirect detected: ${r}`),null;i.add(r);const[a,h]=r.split("?"),o=a.split("/").filter(Boolean),l=this.parseQuery(h),c=this.recursiveMatch(this.routes,o);if(c){const e=c.matched[c.matched.length-1];return e.config.redirect?this.matchRouteInternal(e.config.redirect,i,s+1):{matched:c.matched,params:c.params,query:l,fullPath:r,meta:c.matched.reduce((e,t)=>({...e,...t.config.meta||{}}),{})}}return null}recursiveMatch(e,t){const i=[...e].sort((e,t)=>this.calculateScore(t.path)-this.calculateScore(e.path));for(const s of i){const e=s.path.split("/").filter(Boolean),i={};let r=!0;if(0===e.length&&0===t.length)return{matched:[{config:s,params:{}}],params:{}};for(let s=0;s<e.length;s++){const a=e[s],n=t[s];if(a.startsWith(":")){if(!n){r=!1;break}Object.defineProperty(i,a.slice(1),{value:n,writable:!0,enumerable:!0,configurable:!0})}else{if("*"===a){r=!0;break}if(a!==n){r=!1;break}}}if(r){const r=e.length,a=t.slice(r),n={config:s,params:i};if(a.length>0&&s.children){const e=this.recursiveMatch(s.children,a);if(e)return{matched:[n,...e.matched],params:{...i,...e.params}}}else if(0===a.length||e.includes("*"))return{matched:[n],params:i}}}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,i)=>{Object.defineProperty(t,i,{value:e,writable:!0,enumerable:!0,configurable:!0})}),t):t}normalizePath(e="/"){const t=e&&"string"==typeof e?e:"/",i=t.indexOf("?"),s=-1===i?t:t.slice(0,i),r=-1===i?"":t.slice(i+1);let a=s;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!==t&&!e.startsWith(t+"/")||(e=e.slice(t.length)||"/"),this.normalizePath(e)}updateBrowserHistory(e="/",t){const i=this.normalizePath(e),s=this.base||"/";if("hash"===this.mode)t?window.location.replace(`#${i}`):window.location.hash=i;else{const e=s.endsWith("/")?s.slice(0,-1):s,r="/"===e?i:e+i;t?window.history.replaceState({path:r},"",r):window.history.pushState({path:r},"",r)}}async navigate(e="/",t=!1,i=!1){const s=++this.navigationId;this.pendingNavId=s;try{const a=this.normalizePath(e),n=this.currentRoute,h=this.matchRoute(a);if(!h)return{success:!1,error:`No route matched: ${a}`};if(n&&n.fullPath===h.fullPath)return{success:!0};if(this.beforeEachGuard)try{const e=await this.beforeEachGuard(h,n);if(s!==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(r){return s!==this.navigationId?{success:!1,cancelled:!0}:{success:!1,error:r instanceof Error?r.message:"Guard Error"}}return s!==this.navigationId?{success:!1,cancelled:!0}:(this.currentRoute=h,i||this.updateBrowserHistory(a,t),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(h,n),{success:!0})}finally{this.pendingNavId===s&&(this.pendingNavId=null,s===this.navigationId&&this.markReady())}}resolve(e="/"){const t=this.normalizePath(e);if("hash"===this.mode)return`#${t}`;const i=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===i?t:i+t}get modeType(){return this.mode}pushWithQuery(e="/",t){const i=new URLSearchParams(t).toString(),s=e.includes("?")?"&":"?";return this.push(e+(i?s+i:""))}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())}isStarted=!1;handleRouteChange=null;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).catch(t=>{e.IS_DEV&&console.error("[Router] 首导航异常:",t)}))}destroy(){this.navigationId++,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();for(const e of this.keepAliveCache.values())e.dispose?.();this.keepAliveCache.clear(),this.keepAliveKeys=[],this.currentRoute=null,this.navigated=!1,this.pendingNavId=null,this.readyDeferred?.resolve(),this.readyDeferred=null,t=null}getCurrentRoute(){return this.currentRoute}get hasNavigated(){return this.navigated}get isNavigating(){return null!==this.pendingNavId}isReady(){if(this.navigated&&null===this.pendingNavId)return Promise.resolve();if(!this.readyDeferred){let e;const t=new Promise(t=>{e=t});this.readyDeferred={promise:t,resolve:e}}return this.readyDeferred.promise}markReady(){this.navigated=!0,this.readyDeferred?.resolve(),this.readyDeferred=null}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)){const i=this.keepAliveCache.get(e);i&&i!==t&&i.dispose?.(),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();if(e){const t=this.keepAliveCache.get(e);t?.dispose?.(),this.keepAliveCache.delete(e)}}}cacheKey(e){return this.normalizePath(e)}prefetch(e){const t=this.matchRoute(e);if(!t)return;const i=this.cacheKey(t.fullPath),s=t.matched[t.matched.length-1];if(!s?.config.component)return;const r=s.config.component;if("function"!=typeof r)return;if(this.componentCache.has(i))return;const a=r();this.componentCache.set(i,a),a.catch(()=>{this.componentCache.delete(i)})}getComponentFromCache(e){return this.componentCache.get(this.cacheKey(e))}}exports.Router=n,exports.createRouter=function(e){return t||(t=new n(e),i&&i(t),i=null,s=null,t)},exports.getRouter=function(){return t},exports.routerReady=a;
@@ -32,6 +32,11 @@ export declare class Router {
32
32
  private keepAliveKeys;
33
33
  private navigationId;
34
34
  private maxKeepAlive;
35
+ /** 首次导航(含守卫与重定向)是否已 settled */
36
+ private navigated;
37
+ /** 尚未完成的「最新一次」导航的 navId;null 表示当前没有导航在飞 */
38
+ private pendingNavId;
39
+ private readyDeferred;
35
40
  constructor(options: RouterOptions);
36
41
  private normalizeBase;
37
42
  private static readonly MAX_REDIRECTS;
@@ -58,6 +63,31 @@ export declare class Router {
58
63
  setupListeners(): void;
59
64
  destroy(): void;
60
65
  getCurrentRoute(): RouteMatch | null;
66
+ /**
67
+ * 首次导航是否已完成(成功或失败均算完成)。
68
+ *
69
+ * 用于区分「启动中」与「真的没有匹配路由」:`currentRoute === null` 在启动阶段
70
+ * 是正常状态,不应被上层当成 404。
71
+ */
72
+ get hasNavigated(): boolean;
73
+ /**
74
+ * 是否有导航正在进行(含卡在异步守卫里的那次)。
75
+ *
76
+ * `isReady()` 在仍有导航在飞时保持 pending —— 否则调用方会在两次导航之间醒来,
77
+ * 读到 `currentRoute === null` 而把「还在导航」当成「无匹配」。
78
+ */
79
+ get isNavigating(): boolean;
80
+ /**
81
+ * 等待首次导航 settled。
82
+ *
83
+ * 语义与 `routerReady` 对齐:`setupListeners()` 之前调用会保持 pending,
84
+ * 需配合「先 setupListeners 再 await」的启动顺序;`destroy()` 后重置,
85
+ * 且销毁时仍 pending 的等待会被立即 resolve(不 reject),调用方据此结束等待;
86
+ * 销毁**之后**再调用会一直 pending —— 该实例已作废,不应继续使用。
87
+ */
88
+ isReady(): Promise<void>;
89
+ /** 唯一调用点(`navigate()` 的 finally)已保证 `pendingNavId` 为 null */
90
+ private markReady;
61
91
  getKeepAlive(key: string): HTMLElement | undefined;
62
92
  setKeepAlive(key: string, el: HTMLElement): void;
63
93
  hasKeepAlive(key: string): boolean;
@@ -1 +1 @@
1
- import{IS_DEV as e}from"../shared/env.js";let t=null,s=null,i=null;function a(){return t?Promise.resolve(t):(i||(i=new Promise(e=>{s=e})),i)}const r=(()=>{const e=()=>a();return Object.defineProperties(e,{then:{value:(e,t)=>a().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>a().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>a().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})();function n(e){return t||(t=new o(e),s&&s(t),s=null,i=null,t)}function h(){return t}class o{routes;base;mode;beforeEachGuard;afterEachGuard;currentRoute=null;listeners=new Set;componentCache=new Map;keepAliveCache=new Map;keepAliveKeys=[];navigationId=0;maxKeepAlive;constructor(e){this.routes=e.routes,this.base=this.normalizeBase(e.base),this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}normalizeBase(e){let t=e||"/";return t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}static MAX_REDIRECTS=20;matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,s,i){if(i>=o.MAX_REDIRECTS)return e&&console.error(`[Router] Too many redirects (max ${o.MAX_REDIRECTS}), last path: ${t}`),null;const a=this.normalizePath(t);if(s.has(a))return e&&console.error(`[Router] Circular redirect detected: ${a}`),null;s.add(a);const[r,n]=a.split("?"),h=r.split("/").filter(Boolean),c=this.parseQuery(n),l=this.recursiveMatch(this.routes,h);if(l){const e=l.matched[l.matched.length-1];return e.config.redirect?this.matchRouteInternal(e.config.redirect,s,i+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 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}Object.defineProperty(s,r.slice(1),{value:n,writable:!0,enumerable:!0,configurable:!0})}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)=>{Object.defineProperty(t,s,{value:e,writable:!0,enumerable:!0,configurable:!0})}),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!==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())}isStarted=!1;handleRouteChange=null;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,t=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(!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))}}export{o as Router,n as createRouter,h as getRouter,r as routerReady};
1
+ import{IS_DEV as e}from"../shared/env.js";let t=null,i=null,s=null;function a(){return t?Promise.resolve(t):(s||(s=new Promise(e=>{i=e})),s)}const r=(()=>{const e=()=>a();return Object.defineProperties(e,{then:{value:(e,t)=>a().then(e,t),writable:!1,enumerable:!1,configurable:!0},catch:{value:e=>a().catch(e),writable:!1,enumerable:!1,configurable:!0},finally:{value:e=>a().finally(e),writable:!1,enumerable:!1,configurable:!0},[Symbol.toStringTag]:{value:"Promise",writable:!1,enumerable:!1,configurable:!0}}),e})();function n(e){return t||(t=new o(e),i&&i(t),i=null,s=null,t)}function h(){return t}class o{routes;base;mode;beforeEachGuard;afterEachGuard;currentRoute=null;listeners=new Set;componentCache=new Map;keepAliveCache=new Map;keepAliveKeys=[];navigationId=0;maxKeepAlive;navigated=!1;pendingNavId=null;readyDeferred=null;constructor(e){this.routes=e.routes,this.base=this.normalizeBase(e.base),this.mode=e.mode||"history",this.beforeEachGuard=e.beforeEach,this.afterEachGuard=e.afterEach,this.maxKeepAlive=e.maxKeepAlive}normalizeBase(e){let t=e||"/";return t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}static MAX_REDIRECTS=20;matchRoute(e="/"){return this.matchRouteInternal(e,new Set,0)}matchRouteInternal(t,i,s){if(s>=o.MAX_REDIRECTS)return e&&console.error(`[Router] Too many redirects (max ${o.MAX_REDIRECTS}), last path: ${t}`),null;const a=this.normalizePath(t);if(i.has(a))return e&&console.error(`[Router] Circular redirect detected: ${a}`),null;i.add(a);const[r,n]=a.split("?"),h=r.split("/").filter(Boolean),l=this.parseQuery(n),c=this.recursiveMatch(this.routes,h);if(c){const e=c.matched[c.matched.length-1];return e.config.redirect?this.matchRouteInternal(e.config.redirect,i,s+1):{matched:c.matched,params:c.params,query:l,fullPath:a,meta:c.matched.reduce((e,t)=>({...e,...t.config.meta||{}}),{})}}return null}recursiveMatch(e,t){const i=[...e].sort((e,t)=>this.calculateScore(t.path)-this.calculateScore(e.path));for(const s of i){const e=s.path.split("/").filter(Boolean),i={};let a=!0;if(0===e.length&&0===t.length)return{matched:[{config:s,params:{}}],params:{}};for(let s=0;s<e.length;s++){const r=e[s],n=t[s];if(r.startsWith(":")){if(!n){a=!1;break}Object.defineProperty(i,r.slice(1),{value:n,writable:!0,enumerable:!0,configurable:!0})}else{if("*"===r){a=!0;break}if(r!==n){a=!1;break}}}if(a){const a=e.length,r=t.slice(a),n={config:s,params:i};if(r.length>0&&s.children){const e=this.recursiveMatch(s.children,r);if(e)return{matched:[n,...e.matched],params:{...i,...e.params}}}else if(0===r.length||e.includes("*"))return{matched:[n],params:i}}}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,i)=>{Object.defineProperty(t,i,{value:e,writable:!0,enumerable:!0,configurable:!0})}),t):t}normalizePath(e="/"){const t=e&&"string"==typeof e?e:"/",i=t.indexOf("?"),s=-1===i?t:t.slice(0,i),a=-1===i?"":t.slice(i+1);let r=s;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!==t&&!e.startsWith(t+"/")||(e=e.slice(t.length)||"/"),this.normalizePath(e)}updateBrowserHistory(e="/",t){const i=this.normalizePath(e),s=this.base||"/";if("hash"===this.mode)t?window.location.replace(`#${i}`):window.location.hash=i;else{const e=s.endsWith("/")?s.slice(0,-1):s,a="/"===e?i:e+i;t?window.history.replaceState({path:a},"",a):window.history.pushState({path:a},"",a)}}async navigate(e="/",t=!1,i=!1){const s=++this.navigationId;this.pendingNavId=s;try{const r=this.normalizePath(e),n=this.currentRoute,h=this.matchRoute(r);if(!h)return{success:!1,error:`No route matched: ${r}`};if(n&&n.fullPath===h.fullPath)return{success:!0};if(this.beforeEachGuard)try{const e=await this.beforeEachGuard(h,n);if(s!==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(a){return s!==this.navigationId?{success:!1,cancelled:!0}:{success:!1,error:a instanceof Error?a.message:"Guard Error"}}return s!==this.navigationId?{success:!1,cancelled:!0}:(this.currentRoute=h,i||this.updateBrowserHistory(r,t),this.notifyListeners(),this.afterEachGuard&&this.afterEachGuard(h,n),{success:!0})}finally{this.pendingNavId===s&&(this.pendingNavId=null,s===this.navigationId&&this.markReady())}}resolve(e="/"){const t=this.normalizePath(e);if("hash"===this.mode)return`#${t}`;const i=this.base.endsWith("/")?this.base.slice(0,-1):this.base;return"/"===i?t:i+t}get modeType(){return this.mode}pushWithQuery(e="/",t){const i=new URLSearchParams(t).toString(),s=e.includes("?")?"&":"?";return this.push(e+(i?s+i:""))}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())}isStarted=!1;handleRouteChange=null;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).catch(t=>{e&&console.error("[Router] 首导航异常:",t)}))}destroy(){this.navigationId++,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();for(const e of this.keepAliveCache.values())e.dispose?.();this.keepAliveCache.clear(),this.keepAliveKeys=[],this.currentRoute=null,this.navigated=!1,this.pendingNavId=null,this.readyDeferred?.resolve(),this.readyDeferred=null,t=null}getCurrentRoute(){return this.currentRoute}get hasNavigated(){return this.navigated}get isNavigating(){return null!==this.pendingNavId}isReady(){if(this.navigated&&null===this.pendingNavId)return Promise.resolve();if(!this.readyDeferred){let e;const t=new Promise(t=>{e=t});this.readyDeferred={promise:t,resolve:e}}return this.readyDeferred.promise}markReady(){this.navigated=!0,this.readyDeferred?.resolve(),this.readyDeferred=null}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)){const i=this.keepAliveCache.get(e);i&&i!==t&&i.dispose?.(),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();if(e){const t=this.keepAliveCache.get(e);t?.dispose?.(),this.keepAliveCache.delete(e)}}}cacheKey(e){return this.normalizePath(e)}prefetch(e){const t=this.matchRoute(e);if(!t)return;const i=this.cacheKey(t.fullPath),s=t.matched[t.matched.length-1];if(!s?.config.component)return;const a=s.config.component;if("function"!=typeof a)return;if(this.componentCache.has(i))return;const r=a();this.componentCache.set(i,r),r.catch(()=>{this.componentCache.delete(i)})}getComponentFromCache(e){return this.componentCache.get(this.cacheKey(e))}}export{o as Router,n as createRouter,h as getRouter,r as routerReady};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core.cjs"),t=require("../runtime/component/base-element.cjs"),r=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const o=new WeakMap;exports.default=class extends t.default{unsubscribe;level=0;currentElement=null;currentTagName=null;managedNodes=new Set;scheduled=!1;latestLoadId=0;abortController=null;disposed=!1;router=null;async mounted(){this.disposed=!1,this.detectLevel(),this.router=await e.routerReady(),this.disposed||(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),this.loadRoute(this.router.getCurrentRoute()))}unmounted(){this.disposed=!0,this.abortController?.abort(),this.abortController=null,this.unsubscribe?.(),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){this.abortController&&(this.abortController.abort(),this.abortController=null);const t=++this.latestLoadId,r=e?.matched[this.level];if(!r)return void this.handleEmptyRoute(e);const{config:o}=r;let s=o.tagName;if(!s&&"function"==typeof o.component){this.renderLoading();const r=new AbortController;this.abortController=r;try{const n=this.router?.getComponentFromCache?.(e?.fullPath),i=n?await n:await o.component();if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;s="string"==typeof i?i:i.tagName}catch(n){if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${n}`)}finally{this.abortController===r&&(this.abortController=null)}}if(t===this.latestLoadId&&!this.disposed)if(s)if(!o.forceReload&&this.currentElement&&this.currentTagName===s.toLowerCase())this.syncState(this.currentElement,e?.params||{},e?.query||{},o.props);else{this.clear();const t=this.getOrCreateComponent(s,o,e);this.syncState(t,e?.params||{},e?.query||{},o.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else this.clear()}syncState(e,t,r,s={}){const n=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),i=function(e){let t=o.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},o.set(e,t)),t}(e),a=new Map;Object.entries(t).forEach(([e,t])=>a.set(n(e),String(t))),Object.entries(r).forEach(([e,t])=>a.set(`query-${n(e)}`,String(t))),i.routerAttrs.forEach(t=>{a.has(t)||(e.removeAttribute(t),i.routerAttrs.delete(t))}),a.forEach((t,r)=>{e.getAttribute(r)!==t&&e.setAttribute(r,t),i.routerAttrs.add(r)});const l=new Set(Object.keys(s)),d=e;i.propKeys.forEach(e=>{l.has(e)||(d[e]=void 0)}),Object.entries(s).forEach(([e,t])=>{d[e]!==t&&(d[e]=t)}),i.propKeys=l}getOrCreateComponent(e,t,r){if(!r)throw new Error("Route is required to create or retrieve component");const o=t.keepAliveKey?t.keepAliveKey(r,this.level):this.buildKeepAliveKey(e,r),s=t.keepAlive&&this.router?.getKeepAlive(o);if(s)return s;const n=document.createElement(e);return t.keepAlive&&this.router?.setKeepAlive(o,n),n}buildKeepAliveKey(e,t){const r=t.matched[this.level],o=r?.config.path??e.toLowerCase(),s=Object.values(r?.params??{});return s.length?`${this.level}:${o}:${s.join("|")}`:`${this.level}:${o}`}handleEmptyRoute(e){if(0===this.level){this.clear();const t=e?.matched?.[0],r=t?.config?.notFoundComponent||this.$data.notFound;if(r){const e=document.createElement(r);this.appendManagedNode(e),this.currentElement=e,this.currentTagName=r.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})([r.CustomElement({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],exports.default);
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./core.cjs"),t=require("../shared/env.cjs"),r=require("../runtime/component/base-element.cjs"),s=require("../runtime/component/decorators.cjs");Object.getOwnPropertyDescriptor;const o=new WeakMap;exports.default=class extends r.default{unsubscribe;level=0;currentElement=null;currentTagName=null;managedNodes=new Set;scheduled=!1;latestLoadId=0;abortController=null;disposed=!1;router=null;warnTimer;async mounted(){if(this.disposed=!1,this.detectLevel(),this.router=await e.routerReady(),!this.disposed){if(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),null===this.router.getCurrentRoute()){const r=this.latestLoadId;for(this.router.hasNavigated&&!this.router.isNavigating||(this.renderPending(),t.IS_DEV&&!this.router.hasNavigated&&this.warnIfNeverStarted()),await this.router.isReady();!this.disposed&&null===this.router.getCurrentRoute()&&this.router.isNavigating;)await this.router.isReady();if(this.disposed)return;if(e.getRouter()!==this.router)return;if(this.latestLoadId!==r)return}this.loadRoute(this.router.getCurrentRoute())}}unmounted(){this.disposed=!0,void 0!==this.warnTimer&&(window.clearTimeout(this.warnTimer),this.warnTimer=void 0),this.abortController?.abort(),this.abortController=null,this.unsubscribe?.(),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())}))}warnIfNeverStarted(){this.warnTimer=window.setTimeout(()=>{this.warnTimer=void 0,!this.disposed&&this.router&&!1===this.router.hasNavigated&&console.warn("[router-view] 首次导航 3s 内仍未完成,router-view 会保持占位状态:若尚未调用 router.setupListeners() 请补上;若守卫确实耗时较长,可忽略此提示")},3e3)}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){this.abortController&&(this.abortController.abort(),this.abortController=null);const t=++this.latestLoadId,r=e?.matched[this.level];if(!r)return void this.handleEmptyRoute();const{config:s}=r;let o=s.tagName;if(!o&&"function"==typeof s.component){this.renderLoading();const r=new AbortController;this.abortController=r;try{const i=this.router?.getComponentFromCache?.(e?.fullPath),n=i?await i:await s.component();if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;o="string"==typeof n?n:n.tagName}catch(i){if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${i}`)}finally{this.abortController===r&&(this.abortController=null)}}if(t===this.latestLoadId&&!this.disposed)if(o)if(!s.forceReload&&this.currentElement&&this.currentTagName===o.toLowerCase())this.syncState(this.currentElement,e?.params||{},e?.query||{},s.props);else{this.clear();const t=this.getOrCreateComponent(o,s,e);this.syncState(t,e?.params||{},e?.query||{},s.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=o.toLowerCase()}else this.clear()}syncState(e,t,r,s={}){const i=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=function(e){let t=o.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},o.set(e,t)),t}(e),a=new Map;Object.entries(t).forEach(([e,t])=>a.set(i(e),String(t))),Object.entries(r).forEach(([e,t])=>a.set(`query-${i(e)}`,String(t))),n.routerAttrs.forEach(t=>{a.has(t)||(e.removeAttribute(t),n.routerAttrs.delete(t))}),a.forEach((t,r)=>{e.getAttribute(r)!==t&&e.setAttribute(r,t),n.routerAttrs.add(r)});const d=new Set(Object.keys(s)),l=e;n.propKeys.forEach(e=>{d.has(e)||(l[e]=void 0)}),Object.entries(s).forEach(([e,t])=>{l[e]!==t&&(l[e]=t)}),n.propKeys=d}getOrCreateComponent(e,t,r){if(!r)throw new Error("Route is required to create or retrieve component");const s=t.keepAliveKey?t.keepAliveKey(r,this.level):this.buildKeepAliveKey(e,r),o=t.keepAlive&&this.router?.getKeepAlive(s);if(o)return o;const i=document.createElement(e);return t.keepAlive&&this.router?.setKeepAlive(s,i),i}buildKeepAliveKey(e,t){const r=t.matched[this.level],s=r?.config.path??e.toLowerCase(),o=Object.values(r?.params??{});return o.length?`${this.level}:${s}:${o.join("|")}`:`${this.level}:${s}`}handleEmptyRoute(){if(0===this.level){this.clear();const e=this.$data.notFound;if(e){const t=document.createElement(e);this.appendManagedNode(t),this.currentElement=t,this.currentTagName=e.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}renderPlaceholder(e){this.clear();const t=this.$data.loading;if(t)return void this.appendManagedNode(document.createElement(t));if(!e)return;const r=document.createElement("div");r.style.cssText="padding:20px; color:#999;",r.textContent=e,this.appendManagedNode(r)}renderLoading(){this.renderPlaceholder("Loading...")}renderPending(){this.renderPlaceholder()}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,s=t,o=e.length-1;o>=0;o--)(r=e[o])&&(s=r(s)||s);return s})([s.CustomElement({tagName:"router-view",props:[{name:"notFound",type:"string",default:""},{name:"loading",type:"string",default:""}]})],exports.default);
@@ -2,6 +2,7 @@ import { BaseElement } from '../runtime/component';
2
2
  import { RouteMatch } from './types';
3
3
  declare class RouterView extends BaseElement<{
4
4
  notFound: string;
5
+ loading: string;
5
6
  }> {
6
7
  private unsubscribe?;
7
8
  private level;
@@ -13,9 +14,12 @@ declare class RouterView extends BaseElement<{
13
14
  private abortController;
14
15
  private disposed;
15
16
  private router;
17
+ private warnTimer?;
16
18
  mounted(): Promise<void>;
17
19
  unmounted(): void;
18
20
  private scheduleLoad;
21
+ /** DEV 提示:首导航 3s 内未 settle —— 可能是忘了 setupListeners(),也可能是守卫本身很慢 */
22
+ private warnIfNeverStarted;
19
23
  private detectLevel;
20
24
  loadRoute(route: RouteMatch | null): Promise<void>;
21
25
  private syncState;
@@ -24,7 +28,13 @@ declare class RouterView extends BaseElement<{
24
28
  private handleEmptyRoute;
25
29
  private appendManagedNode;
26
30
  private clear;
31
+ /**
32
+ * 渲染占位内容:优先使用 `loading` 指定的占位组件,未配置时按需渲染兜底文本。
33
+ * 启动阶段(首导航未完成)不传 fallbackText,保持空白。
34
+ */
35
+ private renderPlaceholder;
27
36
  private renderLoading;
37
+ private renderPending;
28
38
  private renderError;
29
39
  }
30
40
  export default RouterView;
@@ -1 +1 @@
1
- import{routerReady as e}from"./core.js";import t from"../runtime/component/base-element.js";import{CustomElement as r}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const o=new WeakMap;let s=class extends t{unsubscribe;level=0;currentElement=null;currentTagName=null;managedNodes=new Set;scheduled=!1;latestLoadId=0;abortController=null;disposed=!1;router=null;async mounted(){this.disposed=!1,this.detectLevel(),this.router=await e(),this.disposed||(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),this.loadRoute(this.router.getCurrentRoute()))}unmounted(){this.disposed=!0,this.abortController?.abort(),this.abortController=null,this.unsubscribe?.(),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){this.abortController&&(this.abortController.abort(),this.abortController=null);const t=++this.latestLoadId,r=e?.matched[this.level];if(!r)return void this.handleEmptyRoute(e);const{config:o}=r;let s=o.tagName;if(!s&&"function"==typeof o.component){this.renderLoading();const r=new AbortController;this.abortController=r;try{const n=this.router?.getComponentFromCache?.(e?.fullPath),i=n?await n:await o.component();if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;s="string"==typeof i?i:i.tagName}catch(n){if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${n}`)}finally{this.abortController===r&&(this.abortController=null)}}if(t===this.latestLoadId&&!this.disposed)if(s)if(!o.forceReload&&this.currentElement&&this.currentTagName===s.toLowerCase())this.syncState(this.currentElement,e?.params||{},e?.query||{},o.props);else{this.clear();const t=this.getOrCreateComponent(s,o,e);this.syncState(t,e?.params||{},e?.query||{},o.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else this.clear()}syncState(e,t,r,s={}){const n=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),i=function(e){let t=o.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},o.set(e,t)),t}(e),a=new Map;Object.entries(t).forEach(([e,t])=>a.set(n(e),String(t))),Object.entries(r).forEach(([e,t])=>a.set(`query-${n(e)}`,String(t))),i.routerAttrs.forEach(t=>{a.has(t)||(e.removeAttribute(t),i.routerAttrs.delete(t))}),a.forEach((t,r)=>{e.getAttribute(r)!==t&&e.setAttribute(r,t),i.routerAttrs.add(r)});const l=new Set(Object.keys(s)),d=e;i.propKeys.forEach(e=>{l.has(e)||(d[e]=void 0)}),Object.entries(s).forEach(([e,t])=>{d[e]!==t&&(d[e]=t)}),i.propKeys=l}getOrCreateComponent(e,t,r){if(!r)throw new Error("Route is required to create or retrieve component");const o=t.keepAliveKey?t.keepAliveKey(r,this.level):this.buildKeepAliveKey(e,r),s=t.keepAlive&&this.router?.getKeepAlive(o);if(s)return s;const n=document.createElement(e);return t.keepAlive&&this.router?.setKeepAlive(o,n),n}buildKeepAliveKey(e,t){const r=t.matched[this.level],o=r?.config.path??e.toLowerCase(),s=Object.values(r?.params??{});return s.length?`${this.level}:${o}:${s.join("|")}`:`${this.level}:${o}`}handleEmptyRoute(e){if(0===this.level){this.clear();const t=e?.matched?.[0],r=t?.config?.notFoundComponent||this.$data.notFound;if(r){const e=document.createElement(r);this.appendManagedNode(e),this.currentElement=e,this.currentTagName=r.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)}};s=((e,t)=>{for(var r,o=t,s=e.length-1;s>=0;s--)(r=e[s])&&(o=r(o)||o);return o})([r({tagName:"router-view",props:[{name:"notFound",type:"string",default:""}]})],s);export{s as default};
1
+ import{routerReady as e,getRouter as t}from"./core.js";import{IS_DEV as r}from"../shared/env.js";import o from"../runtime/component/base-element.js";import{CustomElement as s}from"../runtime/component/decorators.js";Object.getOwnPropertyDescriptor;const i=new WeakMap;let n=class extends o{unsubscribe;level=0;currentElement=null;currentTagName=null;managedNodes=new Set;scheduled=!1;latestLoadId=0;abortController=null;disposed=!1;router=null;warnTimer;async mounted(){if(this.disposed=!1,this.detectLevel(),this.router=await e(),!this.disposed){if(this.unsubscribe=this.router.listen(()=>this.scheduleLoad()),null===this.router.getCurrentRoute()){const e=this.latestLoadId;for(this.router.hasNavigated&&!this.router.isNavigating||(this.renderPending(),r&&!this.router.hasNavigated&&this.warnIfNeverStarted()),await this.router.isReady();!this.disposed&&null===this.router.getCurrentRoute()&&this.router.isNavigating;)await this.router.isReady();if(this.disposed)return;if(t()!==this.router)return;if(this.latestLoadId!==e)return}this.loadRoute(this.router.getCurrentRoute())}}unmounted(){this.disposed=!0,void 0!==this.warnTimer&&(window.clearTimeout(this.warnTimer),this.warnTimer=void 0),this.abortController?.abort(),this.abortController=null,this.unsubscribe?.(),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())}))}warnIfNeverStarted(){this.warnTimer=window.setTimeout(()=>{this.warnTimer=void 0,!this.disposed&&this.router&&!1===this.router.hasNavigated&&console.warn("[router-view] 首次导航 3s 内仍未完成,router-view 会保持占位状态:若尚未调用 router.setupListeners() 请补上;若守卫确实耗时较长,可忽略此提示")},3e3)}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){this.abortController&&(this.abortController.abort(),this.abortController=null);const t=++this.latestLoadId,r=e?.matched[this.level];if(!r)return void this.handleEmptyRoute();const{config:o}=r;let s=o.tagName;if(!s&&"function"==typeof o.component){this.renderLoading();const r=new AbortController;this.abortController=r;try{const i=this.router?.getComponentFromCache?.(e?.fullPath),n=i?await i:await o.component();if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;s="string"==typeof n?n:n.tagName}catch(i){if(r.signal.aborted||t!==this.latestLoadId||this.disposed)return;return void this.renderError(`Load Error: ${i}`)}finally{this.abortController===r&&(this.abortController=null)}}if(t===this.latestLoadId&&!this.disposed)if(s)if(!o.forceReload&&this.currentElement&&this.currentTagName===s.toLowerCase())this.syncState(this.currentElement,e?.params||{},e?.query||{},o.props);else{this.clear();const t=this.getOrCreateComponent(s,o,e);this.syncState(t,e?.params||{},e?.query||{},o.props),this.appendManagedNode(t),this.currentElement=t,this.currentTagName=s.toLowerCase()}else this.clear()}syncState(e,t,r,o={}){const s=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),n=function(e){let t=i.get(e);return t||(t={routerAttrs:new Set,propKeys:new Set},i.set(e,t)),t}(e),a=new Map;Object.entries(t).forEach(([e,t])=>a.set(s(e),String(t))),Object.entries(r).forEach(([e,t])=>a.set(`query-${s(e)}`,String(t))),n.routerAttrs.forEach(t=>{a.has(t)||(e.removeAttribute(t),n.routerAttrs.delete(t))}),a.forEach((t,r)=>{e.getAttribute(r)!==t&&e.setAttribute(r,t),n.routerAttrs.add(r)});const d=new Set(Object.keys(o)),l=e;n.propKeys.forEach(e=>{d.has(e)||(l[e]=void 0)}),Object.entries(o).forEach(([e,t])=>{l[e]!==t&&(l[e]=t)}),n.propKeys=d}getOrCreateComponent(e,t,r){if(!r)throw new Error("Route is required to create or retrieve component");const o=t.keepAliveKey?t.keepAliveKey(r,this.level):this.buildKeepAliveKey(e,r),s=t.keepAlive&&this.router?.getKeepAlive(o);if(s)return s;const i=document.createElement(e);return t.keepAlive&&this.router?.setKeepAlive(o,i),i}buildKeepAliveKey(e,t){const r=t.matched[this.level],o=r?.config.path??e.toLowerCase(),s=Object.values(r?.params??{});return s.length?`${this.level}:${o}:${s.join("|")}`:`${this.level}:${o}`}handleEmptyRoute(){if(0===this.level){this.clear();const e=this.$data.notFound;if(e){const t=document.createElement(e);this.appendManagedNode(t),this.currentElement=t,this.currentTagName=e.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}renderPlaceholder(e){this.clear();const t=this.$data.loading;if(t)return void this.appendManagedNode(document.createElement(t));if(!e)return;const r=document.createElement("div");r.style.cssText="padding:20px; color:#999;",r.textContent=e,this.appendManagedNode(r)}renderLoading(){this.renderPlaceholder("Loading...")}renderPending(){this.renderPlaceholder()}renderError(e){this.clear();const t=document.createElement("div");t.style.cssText="padding:20px; color:#ff4d4f;",t.textContent=e,this.appendManagedNode(t)}};n=((e,t)=>{for(var r,o=t,s=e.length-1;s>=0;s--)(r=e[s])&&(o=r(o)||o);return o})([s({tagName:"router-view",props:[{name:"notFound",type:"string",default:""},{name:"loading",type:"string",default:""}]})],n);export{n as default};
@@ -41,7 +41,9 @@ export interface RouteConfig {
41
41
  */
42
42
  async?: boolean;
43
43
  /** * 404 页面组件标签名。
44
- * 当没有匹配到路由时显示的组件,优先级高于 RouterView 的 not-found 属性。
44
+ * @deprecated 该字段从未生效:路径不匹配时 `matchRoute()` 直接返回 null,
45
+ * 不存在可读取的 config,因此无法取到本字段。
46
+ * 请改用 `{ path: '*', tagName: 'xxx' }` 兜底路由,或 RouterView 的 `not-found` 属性。
45
47
  */
46
48
  notFoundComponent?: string;
47
49
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../../shared/is-object.cjs"),t=require("../../shared/env.cjs"),s=require("../../shared/case-convert.cjs"),i=require("../reactivity/observe.cjs"),r=require("../renderer/renderIR.cjs"),a=Symbol.for("solely.manifest");class o extends HTMLElement{$refs={};#e;#t;#s;#i;#r;#a;#o=!1;#n=!1;#d=!1;#h=!1;#c=!1;#l=!1;#u=!1;#p=new Set;#f=!1;#b=!1;static#y=new Map;static#m=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const e=this[a];return e?.attributeMap?Array.from(e.attributeMap.keys()):[]}constructor(e={}){super();const t=this.constructor;this.#e=t[a]||{tagName:"base-element"};const s=this.#e;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#S(e),this.#g(s),queueMicrotask(()=>this.#v())}#A(){const e=Object.getOwnPropertyNames(this),t=["#","_"],s=o.#m,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==HTMLElement.prototype;){const e=Object.getOwnPropertyDescriptors(r);for(const[t,s]of Object.entries(e))s.set&&!i.has(t)&&i.set(t,s);r=Object.getPrototypeOf(r)}for(const a of e){if(s.has(a))continue;if(t.some(e=>a.startsWith(e)))continue;const e=Object.getOwnPropertyDescriptor(this,a);if(!e||!("value"in e))continue;const r=e.value,o=i.get(a);o?.set&&(delete this[a],this[a]=r)}}#S(e){const{proxy:t,dispose:s}=i.observe(e,e=>{if("set"===e.type){const{key:t,newValue:s}=e,i=this.#e,r=String(t),a=i.propMap?.get(r);a?.reflect&&this.#O(a,s)}this.emit("dataChange",{...e}),this.#R()});this.#i=t,this.#a=s}#O(e,t){const i=s.camelToKebab(e.name);this.#p.add(i);try{if(null==t)return void this.removeAttribute(i);if("boolean"===e.type)t?this.setAttribute(i,""):this.removeAttribute(i);else{const e="object"==typeof t?JSON.stringify(t):String(t);this.setAttribute(i,e)}}finally{this.#p.delete(i)}}#g(e){e.ir&&(this.#s=e.ir)}#C(){const e=this.#e;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(!e?.get&&!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})}}}#$(){this.#u||(this.#u=!0,this.#C())}get $data(){return this.#i}set $data(t){e.isObject(t)||(t={}),t!==this.#i&&(this.#a?.(),this.#S(t),this.#$(),this.#R())}#w(e,t,s){if(null===e)return"boolean"!==s&&t;switch(s){case"boolean":return!0;case"number":{const s=Number(e);return isNaN(s)?t:s}case"object":try{return JSON.parse(e)}catch(i){return console.error(`[Solely] Failed to parse object value: "${e}", using default value.`,i),t}case"array":try{const s=JSON.parse(e);return Array.isArray(s)?s:t}catch(i){return console.error(`[Solely] Failed to parse array value: "${e}", using default value.`,i),t}default:return e}}#R(){this.#f||(this.#c?!this.#n&&this.#t&&(this.#n=!0,queueMicrotask(()=>{this.#f||(this.#n=!1,this.#j())})):this.#l=!0)}#j(){if(!this.#f&&!this.#o&&this.#c){this.#o=!0;try{this.#d&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#t?.update(),this.updated(),this.#d&&(this.afterAttributesUpdate(),this.#d=!1)}finally{this.#o=!1}}}refresh(){this.#R()}#M(){const e=this.#e;if(!e.styles)return;const s=this.#r;if(e.sheet&&s instanceof ShadowRoot&&"adoptedStyleSheets"in s){if(!s.adoptedStyleSheets.includes(e.sheet)){const t=Array.from(s.adoptedStyleSheets);t.push(e.sheet),s.adoptedStyleSheets=t}return void(this.#b=!0)}const i=s instanceof ShadowRoot?s:document.head,r=`solely-style-${t.SOLELY_VERSION}-${e.tagName}`,a=!e.shadowDOM?.use,n="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${n}`)){const t=document.createElement("style");t.id=r,t.textContent=e.styles,i.appendChild(t)}if(a){const e=o.#y.get(r)||0;o.#y.set(r,e+1),this.#b=!0}}#N(){if(!this.#b)return;this.#b=!1;const e=this.#e;if(!e.shadowDOM?.use&&e.styles){const s=`solely-style-${t.SOLELY_VERSION}-${e.tagName}`,i=o.#y.get(s)||0;if(i<=1){const e="undefined"!=typeof CSS&&CSS.escape?CSS.escape(s):s.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${e}`)?.remove(),o.#y.delete(s)}else o.#y.set(s,i-1)}}connectedCallback(){if(this.#f)throw this.remove(),new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);this.#c=!0;const t=this.#e;if(this.#v(),(t.className||t.tagName||"").split(" ").forEach(e=>e&&this.classList.add(e)),this.#M(),t.attributeMap&&e.isObject(this.$data)){this.#$();for(const[e,s]of t.attributeMap){const t=s.name;if(this.hasAttribute(e)){const i=this.getAttribute(e),r=this.#w(i,s.default,s.type);this.$data[t]=r}else"default"in s&&void 0===this.$data[t]&&(this.$data[t]=s.default,"boolean"===s.type&&!0===s.default&&this.setAttribute(e,""))}}this.#A(),this.#s&&!this.#t&&(this.#t=r.createRender(this.#s,this.#r,this)),this.#l&&(this.#l=!1,this.#R()),this.mounted()}disconnectedCallback(){this.#c=!1,this.#f||this.#N(),this.unmounted()}attributeChangedCallback(t,s,i){if(this.#f||s===i||!e.isObject(this.$data))return;if(this.#p.has(t))return;const r=this.#e,a=r.attributeMap?.get(t);if(!a)return;const o=a.name,n=this.$data[o],d=this.#w(i,a.default??n,a.type);n!==d&&(this.#d=!0,this.$data[o]=d,this.attributeChanged(t,n,d))}#v(){this.#h||(this.#h=!0,this.created())}emit(e,t,s){this.#f||this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t,...s}))}emitNative(e,t){this.#f||this.dispatchEvent(new Event(e,{bubbles:!0,composed:!0,...t}))}warn(e,s){if(t.IS_DEV&&e){const e=this.tagName.toLowerCase();console.warn(`[${e}] ${s}`)}}error(e,s){if(t.IS_DEV&&e){const e=this.tagName.toLowerCase();console.error(`[${e}] ${s}`)}}dispose(){this.#f||(this.#f=!0,this.#c=!1,this.#N(),this.#t?.destroy(),this.#t=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(e,t,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}exports.default=o;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../../shared/is-object.cjs"),t=require("../../shared/env.cjs"),s=require("../../shared/case-convert.cjs"),i=require("../reactivity/observe.cjs"),r=require("../renderer/renderIR.cjs"),a=Symbol.for("solely.manifest"),o="undefined"!=typeof HTMLElement?HTMLElement:class{};function n(e){if(null===e||"object"!=typeof e)return e;const t=globalThis.structuredClone;if("function"==typeof t)try{return t(e)}catch{}try{return JSON.parse(JSON.stringify(e))}catch{return e}}class c extends o{$refs={};#e;#t;#s;#i;#r;#a;#o=!1;#n=!1;#c=!1;#d=!1;#h=!1;#l=!1;#u=!1;#p=new Set;#f=!1;#b=!1;static#y=new Map;static#m=new WeakSet;#g=new Map;static#S=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const e=this[a];return e?.attributeMap?Array.from(e.attributeMap.keys()):[]}constructor(e={}){super();const t=this.constructor;this.#e=t[a]||{tagName:"base-element"};const s=this.#e;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#v(e),this.#A(s),queueMicrotask(()=>this.#O())}#C(){const e=Object.getOwnPropertyNames(this),t=["#","_"],s=c.#S,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==o.prototype;){const e=Object.getOwnPropertyDescriptors(r);for(const[t,s]of Object.entries(e))s.set&&!i.has(t)&&i.set(t,s);r=Object.getPrototypeOf(r)}for(const a of e){if(s.has(a))continue;if(t.some(e=>a.startsWith(e)))continue;const e=Object.getOwnPropertyDescriptor(this,a);if(!e||!("value"in e))continue;const r=e.value,o=i.get(a);o?.set&&(delete this[a],this[a]=r)}}#v(e){t.IS_DEV&&e&&"object"==typeof e&&(c.#m.has(e)&&console.warn(`[Solely] <${this.#e.tagName}>: 该初始数据对象已被其他实例使用,$data 会共享同一响应式代理(改一个实例会同时触发另一个实例刷新)。如需实例隔离,请为每个实例传入新对象。`),c.#m.add(e));const{proxy:s,dispose:r}=i.observe(e,e=>{if("set"===e.type||"array-replace"===e.type){const{key:t,newValue:s}=e,i=this.#e,r=String(t),a=i.propMap?.get(r);a?.reflect&&this.#R(a,s)}!1!==this.#e.dataChangeEvent&&this.emit("dataChange",{...e}),this.#w()});this.#i=s,this.#a=r}#R(e,t){const i=s.camelToKebab(e.name);this.#p.add(i);try{if(null==t)return void this.removeAttribute(i);if("boolean"===e.type)t?this.setAttribute(i,""):this.removeAttribute(i);else{const e="object"==typeof t?JSON.stringify(t):String(t);this.setAttribute(i,e)}}finally{this.#p.delete(i)}}#A(e){e.ir&&(this.#s=e.ir)}#j(e){const t=this.#g.get(e);if(void 0!==t)return t;let s=null,i=Object.getPrototypeOf(this);for(;i&&i!==o.prototype;){const t=Object.getOwnPropertyDescriptor(i,e);if(t){s=t.get||t.set?t:null;break}i=Object.getPrototypeOf(i)}return this.#g.set(e,s),s}#$(e,t){const s=this.#j(e.name);s?.set?this[e.name]=t:this.$data[e.name]=t}#N(){const e=this.#e;if(e.attributeMap)for(const[,t]of e.attributeMap)if(!1!==t.reactive&&!this.#j(t.name)){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})}}#P(){this.#u||(this.#u=!0,this.#N())}get $data(){return this.#i}set $data(t){e.isObject(t)||(t={}),t!==this.#i&&(this.#a?.(),this.#v(t),this.#P(),this.#w())}#M(e,t,s){if(null===e)return"boolean"!==s&&t;switch(s){case"boolean":return!0;case"number":{const s=Number(e);return isNaN(s)?t:s}case"object":try{return JSON.parse(e)}catch(i){return console.error(`[Solely] Failed to parse object value: "${e}", using default value.`,i),t}case"array":try{const s=JSON.parse(e);return Array.isArray(s)?s:t}catch(i){return console.error(`[Solely] Failed to parse array value: "${e}", using default value.`,i),t}default:return e}}#w(){this.#f||(this.#h?!this.#n&&this.#t&&(this.#n=!0,queueMicrotask(()=>{this.#f||(this.#n=!1,this.#D())})):this.#l=!0)}#D(){if(!this.#f&&!this.#o&&this.#h){this.#o=!0;try{this.#c&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#t?.update(),this.updated(),this.#c&&(this.afterAttributesUpdate(),this.#c=!1)}finally{this.#o=!1}}}refresh(){this.#w()}#E(){const e=this.#e;if(!e.styles)return;const s=this.#r;if(e.sheet&&s instanceof ShadowRoot&&"adoptedStyleSheets"in s){if(!s.adoptedStyleSheets.includes(e.sheet)){const t=Array.from(s.adoptedStyleSheets);t.push(e.sheet),s.adoptedStyleSheets=t}return void(this.#b=!0)}const i=s instanceof ShadowRoot?s:document.head,r=`solely-style-${t.SOLELY_VERSION}-${e.tagName}`,a=!e.shadowDOM?.use,o="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${o}`)){const t=document.createElement("style");t.id=r,t.textContent=e.styles,i.appendChild(t)}if(a){const e=c.#y.get(r)||0;c.#y.set(r,e+1),this.#b=!0}}#U(){if(!this.#b)return;this.#b=!1;const e=this.#e;if(!e.shadowDOM?.use&&e.styles){const s=`solely-style-${t.SOLELY_VERSION}-${e.tagName}`,i=c.#y.get(s)||0;if(i<=1){const e="undefined"!=typeof CSS&&CSS.escape?CSS.escape(s):s.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${e}`)?.remove(),c.#y.delete(s)}else c.#y.set(s,i-1)}}connectedCallback(){if(this.#f)return t.IS_DEV&&console.error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`),void this.remove();this.#h=!0;const s=this.#e;if(this.#O(),(s.className||s.tagName||"").split(" ").forEach(e=>e&&this.classList.add(e)),this.#E(),s.attributeMap&&e.isObject(this.$data)){this.#P();for(const[e,t]of s.attributeMap){const s=t.name;if(this.hasAttribute(e)){const s=this.getAttribute(e),i=this.#M(s,n(t.default),t.type);this.#$(t,i)}else"default"in t&&void 0===this.$data[s]&&(this.#$(t,n(t.default)),"boolean"===t.type&&!0===t.default&&this.setAttribute(e,""))}}this.#C(),this.#s&&!this.#t&&(this.#t=r.createRender(this.#s,this.#r,this)),this.#l&&(this.#l=!1,this.#w()),this.mounted()}disconnectedCallback(){this.#h=!1,this.#f||this.#U(),this.unmounted()}attributeChangedCallback(t,s,i){if(this.#f||s===i||!e.isObject(this.$data))return;if(this.#p.has(t))return;const r=this.#e,a=r.attributeMap?.get(t);if(!a)return;const o=a.name,c=this.$data[o],d=void 0!==a.default?n(a.default):c,h=this.#M(i,d,a.type);c!==h&&(this.#c=!0,this.#$(a,h),this.$data[o]===c&&(this.#c=!1),this.attributeChanged(t,c,h))}#O(){this.#d||(this.#d=!0,this.created())}emit(e,t,s){this.#f||this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t,...s}))}emitNative(e,t){this.#f||this.dispatchEvent(new Event(e,{bubbles:!0,composed:!0,...t}))}warn(e,s){if(t.IS_DEV&&e){const e=this.tagName.toLowerCase();console.warn(`[${e}] ${s}`)}}error(e,s){if(t.IS_DEV&&e){const e=this.tagName.toLowerCase();console.error(`[${e}] ${s}`)}}dispose(){this.#f||(this.#f=!0,this.#h=!1,this.#U(),this.#t?.destroy(),this.#t=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(e,t,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}exports.default=c;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Node/SSR 环境没有 HTMLElement。若模块顶层直接 `extends HTMLElement`,
3
+ * `import 'solely'` 会在求值阶段抛 `ReferenceError: HTMLElement is not defined`。
4
+ * 这里退化为空基类:浏览器环境仍是原生 HTMLElement(行为不变),
5
+ * Node 环境仅保证「可导入」,实例化与渲染仍需 DOM。
6
+ */
7
+ declare const HTMLElementBase: typeof HTMLElement;
1
8
  declare interface BaseElement<TData extends object = Record<string, unknown>, TRefs extends Record<string, Element> = Record<string, Element>> {
2
9
  /**
3
10
  * 通过 ref 属性获取的 DOM 元素引用集合
@@ -6,7 +13,7 @@ declare interface BaseElement<TData extends object = Record<string, unknown>, TR
6
13
  */
7
14
  $refs: TRefs;
8
15
  }
9
- declare class BaseElement<TData extends object = Record<string, unknown>, TRefs extends Record<string, Element> = Record<string, Element>> extends HTMLElement implements BaseElement<TData, TRefs> {
16
+ declare class BaseElement<TData extends object = Record<string, unknown>, TRefs extends Record<string, Element> = Record<string, Element>> extends HTMLElementBase implements BaseElement<TData, TRefs> {
10
17
  #private;
11
18
  $refs: TRefs;
12
19
  static get observedAttributes(): string[];
@@ -1 +1 @@
1
- import{isObject as t}from"../../shared/is-object.js";import{SOLELY_VERSION as e,IS_DEV as s}from"../../shared/env.js";import{camelToKebab as i}from"../../shared/case-convert.js";import{observe as r}from"../reactivity/observe.js";import{createRender as a}from"../renderer/renderIR.js";const o=Symbol.for("solely.manifest");class n extends HTMLElement{$refs={};#t;#e;#s;#i;#r;#a;#o=!1;#n=!1;#d=!1;#h=!1;#c=!1;#l=!1;#u=!1;#p=new Set;#f=!1;#m=!1;static#b=new Map;static#y=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const t=this[o];return t?.attributeMap?Array.from(t.attributeMap.keys()):[]}constructor(t={}){super();const e=this.constructor;this.#t=e[o]||{tagName:"base-element"};const s=this.#t;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#g(t),this.#v(s),queueMicrotask(()=>this.#S())}#A(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=n.#y,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(r);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);r=Object.getPrototypeOf(r)}for(const a of t){if(s.has(a))continue;if(e.some(t=>a.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,a);if(!t||!("value"in t))continue;const r=t.value,o=i.get(a);o?.set&&(delete this[a],this[a]=r)}}#g(t){const{proxy:e,dispose:s}=r(t,t=>{if("set"===t.type){const{key:e,newValue:s}=t,i=this.#t,r=String(e),a=i.propMap?.get(r);a?.reflect&&this.#O(a,s)}this.emit("dataChange",{...t}),this.#C()});this.#i=e,this.#a=s}#O(t,e){const s=i(t.name);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{this.#p.delete(s)}}#v(t){t.ir&&(this.#s=t.ir)}#R(){const t=this.#t;if(t.attributeMap)for(const[,e]of t.attributeMap){if(!1===e.reactive)continue;let t,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(t=Object.getOwnPropertyDescriptor(s,e.name),!t);)s=Object.getPrototypeOf(s);if(!t?.get&&!t?.set){const t=Object.getOwnPropertyDescriptor(this,e.name);t&&"value"in t&&(this.$data[e.name]=t.value,delete this[e.name]),Object.defineProperty(this,e.name,{get:()=>this.$data[e.name],set:t=>{this.$data[e.name]=t},configurable:!0,enumerable:!0})}}}#$(){this.#u||(this.#u=!0,this.#R())}get $data(){return this.#i}set $data(e){t(e)||(e={}),e!==this.#i&&(this.#a?.(),this.#g(e),this.#$(),this.#C())}#w(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}}#C(){this.#f||(this.#c?!this.#n&&this.#e&&(this.#n=!0,queueMicrotask(()=>{this.#f||(this.#n=!1,this.#j())})):this.#l=!0)}#j(){if(!this.#f&&!this.#o&&this.#c){this.#o=!0;try{this.#d&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#e?.update(),this.updated(),this.#d&&(this.afterAttributesUpdate(),this.#d=!1)}finally{this.#o=!1}}}refresh(){this.#C()}#M(){const t=this.#t;if(!t.styles)return;const s=this.#r;if(t.sheet&&s instanceof ShadowRoot&&"adoptedStyleSheets"in s){if(!s.adoptedStyleSheets.includes(t.sheet)){const e=Array.from(s.adoptedStyleSheets);e.push(t.sheet),s.adoptedStyleSheets=e}return void(this.#m=!0)}const i=s instanceof ShadowRoot?s:document.head,r=`solely-style-${e}-${t.tagName}`,a=!t.shadowDOM?.use,o="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${o}`)){const e=document.createElement("style");e.id=r,e.textContent=t.styles,i.appendChild(e)}if(a){const t=n.#b.get(r)||0;n.#b.set(r,t+1),this.#m=!0}}#N(){if(!this.#m)return;this.#m=!1;const t=this.#t;if(!t.shadowDOM?.use&&t.styles){const s=`solely-style-${e}-${t.tagName}`,i=n.#b.get(s)||0;if(i<=1){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(s):s.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${t}`)?.remove(),n.#b.delete(s)}else n.#b.set(s,i-1)}}connectedCallback(){if(this.#f)throw this.remove(),new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);this.#c=!0;const e=this.#t;if(this.#S(),(e.className||e.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),this.#M(),e.attributeMap&&t(this.$data)){this.#$();for(const[t,s]of e.attributeMap){const e=s.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),r=this.#w(i,s.default,s.type);this.$data[e]=r}else"default"in s&&void 0===this.$data[e]&&(this.$data[e]=s.default,"boolean"===s.type&&!0===s.default&&this.setAttribute(t,""))}}this.#A(),this.#s&&!this.#e&&(this.#e=a(this.#s,this.#r,this)),this.#l&&(this.#l=!1,this.#C()),this.mounted()}disconnectedCallback(){this.#c=!1,this.#f||this.#N(),this.unmounted()}attributeChangedCallback(e,s,i){if(this.#f||s===i||!t(this.$data))return;if(this.#p.has(e))return;const r=this.#t,a=r.attributeMap?.get(e);if(!a)return;const o=a.name,n=this.$data[o],d=this.#w(i,a.default??n,a.type);n!==d&&(this.#d=!0,this.$data[o]=d,this.attributeChanged(e,n,d))}#S(){this.#h||(this.#h=!0,this.created())}emit(t,e,s){this.#f||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.#f||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(s&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(s&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){this.#f||(this.#f=!0,this.#c=!1,this.#N(),this.#e?.destroy(),this.#e=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}export{n as default};
1
+ import{isObject as t}from"../../shared/is-object.js";import{IS_DEV as e,SOLELY_VERSION as s}from"../../shared/env.js";import{camelToKebab as i}from"../../shared/case-convert.js";import{observe as r}from"../reactivity/observe.js";import{createRender as a}from"../renderer/renderIR.js";const o=Symbol.for("solely.manifest"),n="undefined"!=typeof HTMLElement?HTMLElement:class{};function d(t){if(null===t||"object"!=typeof t)return t;const e=globalThis.structuredClone;if("function"==typeof e)try{return e(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return t}}class h extends n{$refs={};#t;#e;#s;#i;#r;#a;#o=!1;#n=!1;#d=!1;#h=!1;#c=!1;#l=!1;#u=!1;#p=new Set;#f=!1;#m=!1;static#b=new Map;static#y=new WeakSet;#g=new Map;static#v=new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]);static get observedAttributes(){const t=this[o];return t?.attributeMap?Array.from(t.attributeMap.keys()):[]}constructor(t={}){super();const e=this.constructor;this.#t=e[o]||{tagName:"base-element"};const s=this.#t;this.#r=s.shadowDOM?.use?this.attachShadow({mode:s.shadowDOM.mode||"open"}):this,this.#A(t),this.#S(s),queueMicrotask(()=>this.#O())}#C(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=h.#v,i=new Map;let r=Object.getPrototypeOf(this);for(;r&&r!==n.prototype;){const t=Object.getOwnPropertyDescriptors(r);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);r=Object.getPrototypeOf(r)}for(const a of t){if(s.has(a))continue;if(e.some(t=>a.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,a);if(!t||!("value"in t))continue;const r=t.value,o=i.get(a);o?.set&&(delete this[a],this[a]=r)}}#A(t){e&&t&&"object"==typeof t&&(h.#y.has(t)&&console.warn(`[Solely] <${this.#t.tagName}>: 该初始数据对象已被其他实例使用,$data 会共享同一响应式代理(改一个实例会同时触发另一个实例刷新)。如需实例隔离,请为每个实例传入新对象。`),h.#y.add(t));const{proxy:s,dispose:i}=r(t,t=>{if("set"===t.type||"array-replace"===t.type){const{key:e,newValue:s}=t,i=this.#t,r=String(e),a=i.propMap?.get(r);a?.reflect&&this.#w(a,s)}!1!==this.#t.dataChangeEvent&&this.emit("dataChange",{...t}),this.#R()});this.#i=s,this.#a=i}#w(t,e){const s=i(t.name);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{this.#p.delete(s)}}#S(t){t.ir&&(this.#s=t.ir)}#$(t){const e=this.#g.get(t);if(void 0!==e)return e;let s=null,i=Object.getPrototypeOf(this);for(;i&&i!==n.prototype;){const e=Object.getOwnPropertyDescriptor(i,t);if(e){s=e.get||e.set?e:null;break}i=Object.getPrototypeOf(i)}return this.#g.set(t,s),s}#j(t,e){const s=this.#$(t.name);s?.set?this[t.name]=e:this.$data[t.name]=e}#P(){const t=this.#t;if(t.attributeMap)for(const[,e]of t.attributeMap)if(!1!==e.reactive&&!this.#$(e.name)){const t=Object.getOwnPropertyDescriptor(this,e.name);t&&"value"in t&&(this.$data[e.name]=t.value,delete this[e.name]),Object.defineProperty(this,e.name,{get:()=>this.$data[e.name],set:t=>{this.$data[e.name]=t},configurable:!0,enumerable:!0})}}#N(){this.#u||(this.#u=!0,this.#P())}get $data(){return this.#i}set $data(e){t(e)||(e={}),e!==this.#i&&(this.#a?.(),this.#A(e),this.#N(),this.#R())}#M(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}}#R(){this.#f||(this.#c?!this.#n&&this.#e&&(this.#n=!0,queueMicrotask(()=>{this.#f||(this.#n=!1,this.#U())})):this.#l=!0)}#U(){if(!this.#f&&!this.#o&&this.#c){this.#o=!0;try{this.#d&&this.beforeAttributesUpdate(),this.beforeUpdate(),this.#e?.update(),this.updated(),this.#d&&(this.afterAttributesUpdate(),this.#d=!1)}finally{this.#o=!1}}}refresh(){this.#R()}#D(){const t=this.#t;if(!t.styles)return;const e=this.#r;if(t.sheet&&e instanceof ShadowRoot&&"adoptedStyleSheets"in e){if(!e.adoptedStyleSheets.includes(t.sheet)){const s=Array.from(e.adoptedStyleSheets);s.push(t.sheet),e.adoptedStyleSheets=s}return void(this.#m=!0)}const i=e instanceof ShadowRoot?e:document.head,r=`solely-style-${s}-${t.tagName}`,a=!t.shadowDOM?.use,o="undefined"!=typeof CSS&&CSS.escape?CSS.escape(r):r.replace(/([.#:[\]()!])/g,"\\$1");if(!i.querySelector(`#${o}`)){const e=document.createElement("style");e.id=r,e.textContent=t.styles,i.appendChild(e)}if(a){const t=h.#b.get(r)||0;h.#b.set(r,t+1),this.#m=!0}}#k(){if(!this.#m)return;this.#m=!1;const t=this.#t;if(!t.shadowDOM?.use&&t.styles){const e=`solely-style-${s}-${t.tagName}`,i=h.#b.get(e)||0;if(i<=1){const t="undefined"!=typeof CSS&&CSS.escape?CSS.escape(e):e.replace(/([.#:[\]()!])/g,"\\$1");document.head.querySelector(`#${t}`)?.remove(),h.#b.delete(e)}else h.#b.set(e,i-1)}}connectedCallback(){if(this.#f)return e&&console.error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`),void this.remove();this.#c=!0;const s=this.#t;if(this.#O(),(s.className||s.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),this.#D(),s.attributeMap&&t(this.$data)){this.#N();for(const[t,e]of s.attributeMap){const s=e.name;if(this.hasAttribute(t)){const s=this.getAttribute(t),i=this.#M(s,d(e.default),e.type);this.#j(e,i)}else"default"in e&&void 0===this.$data[s]&&(this.#j(e,d(e.default)),"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}this.#C(),this.#s&&!this.#e&&(this.#e=a(this.#s,this.#r,this)),this.#l&&(this.#l=!1,this.#R()),this.mounted()}disconnectedCallback(){this.#c=!1,this.#f||this.#k(),this.unmounted()}attributeChangedCallback(e,s,i){if(this.#f||s===i||!t(this.$data))return;if(this.#p.has(e))return;const r=this.#t,a=r.attributeMap?.get(e);if(!a)return;const o=a.name,n=this.$data[o],h=void 0!==a.default?d(a.default):n,c=this.#M(i,h,a.type);n!==c&&(this.#d=!0,this.#j(a,c),this.$data[o]===n&&(this.#d=!1),this.attributeChanged(e,n,c))}#O(){this.#h||(this.#h=!0,this.created())}emit(t,e,s){this.#f||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.#f||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${s}`)}}error(t,s){if(e&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${s}`)}}dispose(){this.#f||(this.#f=!0,this.#c=!1,this.#k(),this.#e?.destroy(),this.#e=void 0,this.#a?.(),this.#a=void 0,this.remove())}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}}export{h as default};
@@ -51,6 +51,13 @@ export interface Manifest {
51
51
  tagName: string;
52
52
  /** s-model 双向绑定配置 */
53
53
  model?: ModelConfig;
54
+ /**
55
+ * 是否在每次数据变更时派发 `dataChange` 事件(冒泡 + composed)
56
+ * - 默认 true,便于外部监听
57
+ * - 高频更新场景(输入框、拖拽)可设为 false 以省去事件构造与派发开销
58
+ * @default true
59
+ */
60
+ dataChangeEvent?: boolean;
54
61
  }
55
62
  /** 框架内部使用的运行时版本 */
56
63
  export interface InternalManifest extends Manifest {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/is-object.cjs"),t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,o=new WeakMap,i=new WeakMap,s=new WeakMap;function c(e,t,n){l(e,t);let r=i.get(e);r||(r=new Map,i.set(e,r)),r.set(t,n);let o=s.get(n);o||(o=[],s.set(n,o)),o.some(n=>n.parentRef.deref()===e&&n.key===t)||o.push({parentRef:new WeakRef(e),key:t})}function l(e,t){const n=i.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const o=s.get(r);if(o){const n=o.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function a(t,n){const r=i.get(n);if(r)for(const e of r.keys())l(n,e);for(let o=0;o<t.length;o++){const r=t[o];e.isObject(r)&&!p(r)&&c(n,String(o),w(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof FormData&&e instanceof FormData||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Response&&e instanceof Response||"undefined"!=typeof Request&&e instanceof Request};function y(e){return!(!e||!e[t])}const h=new Map,d=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},g=(e,t)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!g(e[n],t[n]))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(const o of n){if(!Reflect.has(t,o))return!1;const n=e[o],r=t[o];if(!g(n,r))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&"set"===t.type&&g(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},R=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let o=0;for(;o<n.length;){const{node:e,relativePath:i,visited:c}=n[o++],l=r.get(e);l&&l.forEach(e=>{if(!e.active)return;let n=i;if("set"===t.type||"delete"===t.type?n=[...i,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...i,String(t.index)]),!d(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const a=s.get(e);if(a)for(let t=a.length-1;t>=0;t--){const e=a[t],r=e.parentRef.deref();if(!r){a.splice(t,1);continue}if(c.has(r))continue;const o=new Set(c);o.add(r),n.push({node:r,relativePath:[e.key,...i],visited:o})}}},v={},j=(e,t)=>e[t];["push","pop","shift","unshift","splice"].forEach(t=>{v[t]=function(...n){const r=this,i=f(r),s=o.get(r)||0;o.set(r,s+1);try{const o=i.length,s=j(i,t).apply(i,n);if("push"===t){const t=i.length-n.length;for(let o=0;o<n.length;o++){const n=i[t+o];e.isObject(n)&&!p(n)&&c(r,String(t+o),w(n))}R(r,{type:"array-push",index:t,values:n})}else if("pop"===t)l(r,String(o-1)),R(r,{type:"array-splice",index:o-1,deleteCount:1,insert:[]});else if(a(i,r),"unshift"===t)R(r,{type:"array-push",index:0,values:n});else if("shift"===t)R(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...o]=n;R(r,{type:"array-splice",index:e,deleteCount:t,insert:o})}return s}finally{o.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{v[e]=function(...t){const n=this,r=f(n),i=o.get(n)||0;o.set(n,i+1);try{const o=j(r,e).apply(r,t);return a(r,n),R(n,{type:"array-reset",method:e}),o}finally{o.set(n,i)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{v[e]=function(t,...n){const r=f(this),o=j(r,e);let i=o.apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=o.apply(r,[f(t),...n])),i}});const m={get(n,r,o){if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(v,r))return Reflect.get(v,r,o);const s=Reflect.get(n,r,o);if("symbol"==typeof r)return s;if(e.isObject(s)&&!p(s)){const e=w(s),t=i.get(o)?.get(r);return t!==e&&c(o,r,e),e}return s},set(t,n,r,i){const s=Reflect.get(t,n,i),a=f(r);if(Object.is(s,a))return!0;const u=Reflect.set(t,n,a,i);return!!u&&(e.isObject(a)&&!p(a)?c(i,n,w(a)):l(i,n),0===(o.get(i)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(a)?R(i,{type:"array-replace",oldValue:s,newValue:a}):R(i,{type:"set",key:n,newValue:a,oldValue:s})),u)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),i=Reflect.deleteProperty(e,t);if(i){const i=n.get(e);i&&(l(i,t),0===(o.get(i)||0)&&R(i,{type:"delete",key:t,oldValue:r}))}return i}};function w(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const o=new Proxy(e,m);return n.set(e,o),o}exports.isProxy=y,exports.observe=function(t,n,o={}){const{throttle:i=0,onBatch:s,immediate:c=!1,deepCompare:l}=o,a={callback:n,onBatch:s,throttle:i,filterRegexes:(Array.isArray(o.filter)?o.filter:o.filter?[o.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=h.get(e);if(t)return t;let n="";for(let c=0;c<e.length;c++){const t=e[c];"*"===t&&"*"===e[c+1]?(n+="**",c++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),o=[];for(let c=0;c<r.length;c++){const e=r[c];"**"===e?1===r.length?o.push(".*"):0===c?o.push("(?:[^.]+\\.)*"):o.push("(?:\\.[^.]+)*"):"*"===e?o.push("[^.]+"):o.push(e)}let i="^";for(let c=0;c<o.length;c++)if(i+=o[c],c<o.length-1){const e=o[c],t=o[c+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;i+="\\."}i+="$";const s=new RegExp(i);return h.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:l},u=w(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(a),c){const n=[...y],r=(t,o,i=[],s=new WeakSet)=>{e.isObject(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(c=>{const l=Reflect.get(t,c);if(e.isObject(l)&&s.has(l))return;const a=Reflect.get(o,c),f=[...i,c];n.forEach(e=>{d(f,e.filterRegexes)&&b(e,{type:"set",key:c,newValue:l,oldValue:void 0,path:f})}),e.isObject(l)&&!p(l)&&r(l,a,f,s)}))};r(f(t),u)}const g=()=>{const e=r.get(u);e&&(e.delete(a),0===e.size&&r.delete(u)),a.pending=[],a.timer&&(clearTimeout(a.timer),a.timer=null)};return{proxy:u,unobserve:()=>{a.active&&(a.active=!1,g())},resume:()=>{a.active||(a.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(a)})())},dispose:()=>{if(!a.active)return a.callback=()=>{},void(a.onBatch=void 0);a.active=!1,g(),a.callback=()=>{},a.onBatch=void 0}}},exports.toProxy=function(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e},exports.toRaw=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/is-object.cjs"),t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,o=new WeakMap,i=new WeakMap,s=new WeakMap;function a(e,t,n){c(e,t);let r=i.get(e);r||(r=new Map,i.set(e,r)),r.set(t,n);let o=s.get(n);o||(o=[],s.set(n,o)),o.some(n=>n.parentRef.deref()===e&&n.key===t)||o.push({parentRef:new WeakRef(e),key:t})}function c(e,t){const n=i.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const o=s.get(r);if(o){const n=o.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function l(t,n){const r=i.get(n);if(r)for(const e of r.keys())c(n,e);for(let o=0;o<t.length;o++){const r=t[o];e.isObject(r)&&!p(r)&&a(n,String(o),m(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof FormData&&e instanceof FormData||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Response&&e instanceof Response||"undefined"!=typeof Request&&e instanceof Request};function y(e){return!(!e||!e[t])}const h=new Map,d=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},g=(e,t,n=new WeakMap)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;let r=n.get(e);if(r?.has(t))return!0;if(r||(r=new WeakSet,n.set(e,r)),r.add(t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!g(e[r],t[r],n))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const o=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(o.length!==i.length)return!1;for(const s of o){if(!Reflect.has(t,s))return!1;const r=e[s],o=t[s];if(!g(r,o,n))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&("set"===t.type||"array-replace"===t.type)&&g(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},R=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let o=0;for(;o<n.length;){const{node:e,relativePath:i,visited:a}=n[o++],c=r.get(e);c&&c.forEach(e=>{if(!e.active)return;let n=i;if("set"===t.type||"delete"===t.type||"array-replace"===t.type?n=[...i,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...i,String(t.index)]),!d(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const l=s.get(e);if(l)for(let t=l.length-1;t>=0;t--){const e=l[t],r=e.parentRef.deref();if(!r){l.splice(t,1);continue}if(a.has(r))continue;const o=new Set(a);o.add(r),n.push({node:r,relativePath:[e.key,...i],visited:o})}}},v={},w=(e,t)=>e[t];["push","pop","shift","unshift","splice"].forEach(t=>{v[t]=function(...n){const r=this,i=f(r),s=o.get(r)||0;o.set(r,s+1);try{const o=i.length,s=w(i,t).apply(i,n);if("push"===t){const t=i.length-n.length;for(let o=0;o<n.length;o++){const n=i[t+o];e.isObject(n)&&!p(n)&&a(r,String(t+o),m(n))}R(r,{type:"array-push",index:t,values:n})}else if("pop"===t)c(r,String(o-1)),R(r,{type:"array-splice",index:o-1,deleteCount:1,insert:[]});else if(l(i,r),"unshift"===t)R(r,{type:"array-push",index:0,values:n});else if("shift"===t)R(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...o]=n;R(r,{type:"array-splice",index:e,deleteCount:t,insert:o})}return s}finally{o.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{v[e]=function(...t){const n=this,r=f(n),i=o.get(n)||0;o.set(n,i+1);try{const o=w(r,e).apply(r,t);return l(r,n),R(n,{type:"array-reset",method:e}),o}finally{o.set(n,i)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{v[e]=function(t,...n){const r=f(this),o=w(r,e);let i=o.apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=o.apply(r,[f(t),...n])),i}});const j={get(n,r,o){if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(v,r))return Reflect.get(v,r,o);const s=Reflect.get(n,r,o);if("symbol"==typeof r)return s;if(e.isObject(s)&&!p(s)){const e=m(s),t=i.get(o)?.get(r);return t!==e&&a(o,r,e),e}return s},set(t,n,r,i){const s=Reflect.get(t,n,i),l=f(r);if(Object.is(s,l))return!0;const u=Reflect.set(t,n,l,i);return!!u&&(e.isObject(l)&&!p(l)?a(i,n,m(l)):c(i,n),0===(o.get(i)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(l)?R(i,{type:"array-replace",key:n,oldValue:s,newValue:l}):R(i,{type:"set",key:n,newValue:l,oldValue:s})),u)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),i=Reflect.deleteProperty(e,t);if(i){const i=n.get(e);i&&(c(i,t),0===(o.get(i)||0)&&R(i,{type:"delete",key:t,oldValue:r}))}return i}};function m(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const o=new Proxy(e,j);return n.set(e,o),o}exports.isProxy=y,exports.observe=function(t,n,o={}){const{throttle:i=0,onBatch:s,immediate:a=!1,deepCompare:c}=o,l={callback:n,onBatch:s,throttle:i,filterRegexes:(Array.isArray(o.filter)?o.filter:o.filter?[o.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=h.get(e);if(t)return t;let n="";for(let a=0;a<e.length;a++){const t=e[a];"*"===t&&"*"===e[a+1]?(n+="**",a++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),o=[];for(let a=0;a<r.length;a++){const e=r[a];"**"===e?1===r.length?o.push(".*"):0===a?o.push("(?:[^.]+\\.)*"):o.push("(?:\\.[^.]+)*"):"*"===e?o.push("[^.]+"):o.push(e)}let i="^";for(let a=0;a<o.length;a++)if(i+=o[a],a<o.length-1){const e=o[a],t=o[a+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;i+="\\."}i+="$";const s=new RegExp(i);return h.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:c},u=m(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(l),a){const n=[...y],r=(t,o,i=[],s=new WeakSet)=>{e.isObject(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(a=>{const c=Reflect.get(t,a);if(e.isObject(c)&&s.has(c))return;const l=Reflect.get(o,a),f=[...i,a];n.forEach(e=>{d(f,e.filterRegexes)&&b(e,{type:"set",key:a,newValue:c,oldValue:void 0,path:f})}),e.isObject(c)&&!p(c)&&r(c,l,f,s)}))};r(f(t),u)}const g=()=>{const e=r.get(u);e&&(e.delete(l),0===e.size&&r.delete(u)),l.pending=[],l.timer&&(clearTimeout(l.timer),l.timer=null)};return{proxy:u,unobserve:()=>{l.active&&(l.active=!1,g())},resume:()=>{l.active||(l.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(l)})())},dispose:()=>{if(!l.active)return l.callback=()=>{},void(l.onBatch=void 0);l.active=!1,g(),l.callback=()=>{},l.onBatch=void 0}}},exports.toProxy=function(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e},exports.toRaw=f;
@@ -19,6 +19,7 @@ export type ChangePayload = {
19
19
  insert: unknown[];
20
20
  } | {
21
21
  type: 'array-replace';
22
+ key: PathKey;
22
23
  oldValue: unknown[];
23
24
  newValue: unknown[];
24
25
  } | {
@@ -1 +1 @@
1
- import{isObject as e}from"../../shared/is-object.js";const t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,o=new WeakMap,i=new WeakMap,s=new WeakMap;function l(e,t,n){a(e,t);let r=i.get(e);r||(r=new Map,i.set(e,r)),r.set(t,n);let o=s.get(n);o||(o=[],s.set(n,o)),o.some(n=>n.parentRef.deref()===e&&n.key===t)||o.push({parentRef:new WeakRef(e),key:t})}function a(e,t){const n=i.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const o=s.get(r);if(o){const n=o.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function c(t,n){const r=i.get(n);if(r)for(const e of r.keys())a(n,e);for(let o=0;o<t.length;o++){const r=t[o];e(r)&&!p(r)&&l(n,String(o),A(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof FormData&&e instanceof FormData||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Response&&e instanceof Response||"undefined"!=typeof Request&&e instanceof Request};function y(e){return!(!e||!e[t])}function h(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e}const d=new Map,g=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},R=(e,t)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!R(e[n],t[n]))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(const o of n){if(!Reflect.has(t,o))return!1;const n=e[o],r=t[o];if(!R(n,r))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&"set"===t.type&&R(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},m=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let o=0;for(;o<n.length;){const{node:e,relativePath:i,visited:l}=n[o++],a=r.get(e);a&&a.forEach(e=>{if(!e.active)return;let n=i;if("set"===t.type||"delete"===t.type?n=[...i,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...i,String(t.index)]),!g(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const c=s.get(e);if(c)for(let t=c.length-1;t>=0;t--){const e=c[t],r=e.parentRef.deref();if(!r){c.splice(t,1);continue}if(l.has(r))continue;const o=new Set(l);o.add(r),n.push({node:r,relativePath:[e.key,...i],visited:o})}}},v={},w=(e,t)=>e[t];["push","pop","shift","unshift","splice"].forEach(t=>{v[t]=function(...n){const r=this,i=f(r),s=o.get(r)||0;o.set(r,s+1);try{const o=i.length,s=w(i,t).apply(i,n);if("push"===t){const t=i.length-n.length;for(let o=0;o<n.length;o++){const n=i[t+o];e(n)&&!p(n)&&l(r,String(t+o),A(n))}m(r,{type:"array-push",index:t,values:n})}else if("pop"===t)a(r,String(o-1)),m(r,{type:"array-splice",index:o-1,deleteCount:1,insert:[]});else if(c(i,r),"unshift"===t)m(r,{type:"array-push",index:0,values:n});else if("shift"===t)m(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...o]=n;m(r,{type:"array-splice",index:e,deleteCount:t,insert:o})}return s}finally{o.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{v[e]=function(...t){const n=this,r=f(n),i=o.get(n)||0;o.set(n,i+1);try{const o=w(r,e).apply(r,t);return c(r,n),m(n,{type:"array-reset",method:e}),o}finally{o.set(n,i)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{v[e]=function(t,...n){const r=f(this),o=w(r,e);let i=o.apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=o.apply(r,[f(t),...n])),i}});const k={get(n,r,o){if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(v,r))return Reflect.get(v,r,o);const s=Reflect.get(n,r,o);if("symbol"==typeof r)return s;if(e(s)&&!p(s)){const e=A(s),t=i.get(o)?.get(r);return t!==e&&l(o,r,e),e}return s},set(t,n,r,i){const s=Reflect.get(t,n,i),c=f(r);if(Object.is(s,c))return!0;const u=Reflect.set(t,n,c,i);return!!u&&(e(c)&&!p(c)?l(i,n,A(c)):a(i,n),0===(o.get(i)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(c)?m(i,{type:"array-replace",oldValue:s,newValue:c}):m(i,{type:"set",key:n,newValue:c,oldValue:s})),u)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),i=Reflect.deleteProperty(e,t);if(i){const i=n.get(e);i&&(a(i,t),0===(o.get(i)||0)&&m(i,{type:"delete",key:t,oldValue:r}))}return i}};function A(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const o=new Proxy(e,k);return n.set(e,o),o}function x(t,n,o={}){const{throttle:i=0,onBatch:s,immediate:l=!1,deepCompare:a}=o,c={callback:n,onBatch:s,throttle:i,filterRegexes:(Array.isArray(o.filter)?o.filter:o.filter?[o.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=d.get(e);if(t)return t;let n="";for(let l=0;l<e.length;l++){const t=e[l];"*"===t&&"*"===e[l+1]?(n+="**",l++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),o=[];for(let l=0;l<r.length;l++){const e=r[l];"**"===e?1===r.length?o.push(".*"):0===l?o.push("(?:[^.]+\\.)*"):o.push("(?:\\.[^.]+)*"):"*"===e?o.push("[^.]+"):o.push(e)}let i="^";for(let l=0;l<o.length;l++)if(i+=o[l],l<o.length-1){const e=o[l],t=o[l+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;i+="\\."}i+="$";const s=new RegExp(i);return d.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:a},u=A(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(c),l){const n=[...y],r=(t,o,i=[],s=new WeakSet)=>{e(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(l=>{const a=Reflect.get(t,l);if(e(a)&&s.has(a))return;const c=Reflect.get(o,l),f=[...i,l];n.forEach(e=>{g(f,e.filterRegexes)&&b(e,{type:"set",key:l,newValue:a,oldValue:void 0,path:f})}),e(a)&&!p(a)&&r(a,c,f,s)}))};r(f(t),u)}const h=()=>{const e=r.get(u);e&&(e.delete(c),0===e.size&&r.delete(u)),c.pending=[],c.timer&&(clearTimeout(c.timer),c.timer=null)};return{proxy:u,unobserve:()=>{c.active&&(c.active=!1,h())},resume:()=>{c.active||(c.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(c)})())},dispose:()=>{if(!c.active)return c.callback=()=>{},void(c.onBatch=void 0);c.active=!1,h(),c.callback=()=>{},c.onBatch=void 0}}}export{y as isProxy,x as observe,h as toProxy,f as toRaw};
1
+ import{isObject as e}from"../../shared/is-object.js";const t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,o=new WeakMap,i=new WeakMap,s=new WeakMap;function a(e,t,n){l(e,t);let r=i.get(e);r||(r=new Map,i.set(e,r)),r.set(t,n);let o=s.get(n);o||(o=[],s.set(n,o)),o.some(n=>n.parentRef.deref()===e&&n.key===t)||o.push({parentRef:new WeakRef(e),key:t})}function l(e,t){const n=i.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const o=s.get(r);if(o){const n=o.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function c(t,n){const r=i.get(n);if(r)for(const e of r.keys())l(n,e);for(let o=0;o<t.length;o++){const r=t[o];e(r)&&!p(r)&&a(n,String(o),A(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob||"undefined"!=typeof FormData&&e instanceof FormData||"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Response&&e instanceof Response||"undefined"!=typeof Request&&e instanceof Request};function y(e){return!(!e||!e[t])}function h(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e}const d=new Map,g=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},R=(e,t,n=new WeakMap)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;let r=n.get(e);if(r?.has(t))return!0;if(r||(r=new WeakSet,n.set(e,r)),r.add(t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!R(e[r],t[r],n))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const o=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(o.length!==i.length)return!1;for(const s of o){if(!Reflect.has(t,s))return!1;const r=e[s],o=t[s];if(!R(r,o,n))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&("set"===t.type||"array-replace"===t.type)&&R(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},m=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let o=0;for(;o<n.length;){const{node:e,relativePath:i,visited:a}=n[o++],l=r.get(e);l&&l.forEach(e=>{if(!e.active)return;let n=i;if("set"===t.type||"delete"===t.type||"array-replace"===t.type?n=[...i,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...i,String(t.index)]),!g(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const c=s.get(e);if(c)for(let t=c.length-1;t>=0;t--){const e=c[t],r=e.parentRef.deref();if(!r){c.splice(t,1);continue}if(a.has(r))continue;const o=new Set(a);o.add(r),n.push({node:r,relativePath:[e.key,...i],visited:o})}}},w={},v=(e,t)=>e[t];["push","pop","shift","unshift","splice"].forEach(t=>{w[t]=function(...n){const r=this,i=f(r),s=o.get(r)||0;o.set(r,s+1);try{const o=i.length,s=v(i,t).apply(i,n);if("push"===t){const t=i.length-n.length;for(let o=0;o<n.length;o++){const n=i[t+o];e(n)&&!p(n)&&a(r,String(t+o),A(n))}m(r,{type:"array-push",index:t,values:n})}else if("pop"===t)l(r,String(o-1)),m(r,{type:"array-splice",index:o-1,deleteCount:1,insert:[]});else if(c(i,r),"unshift"===t)m(r,{type:"array-push",index:0,values:n});else if("shift"===t)m(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...o]=n;m(r,{type:"array-splice",index:e,deleteCount:t,insert:o})}return s}finally{o.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{w[e]=function(...t){const n=this,r=f(n),i=o.get(n)||0;o.set(n,i+1);try{const o=v(r,e).apply(r,t);return c(r,n),m(n,{type:"array-reset",method:e}),o}finally{o.set(n,i)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{w[e]=function(t,...n){const r=f(this),o=v(r,e);let i=o.apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=o.apply(r,[f(t),...n])),i}});const k={get(n,r,o){if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(w,r))return Reflect.get(w,r,o);const s=Reflect.get(n,r,o);if("symbol"==typeof r)return s;if(e(s)&&!p(s)){const e=A(s),t=i.get(o)?.get(r);return t!==e&&a(o,r,e),e}return s},set(t,n,r,i){const s=Reflect.get(t,n,i),c=f(r);if(Object.is(s,c))return!0;const u=Reflect.set(t,n,c,i);return!!u&&(e(c)&&!p(c)?a(i,n,A(c)):l(i,n),0===(o.get(i)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(c)?m(i,{type:"array-replace",key:n,oldValue:s,newValue:c}):m(i,{type:"set",key:n,newValue:c,oldValue:s})),u)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),i=Reflect.deleteProperty(e,t);if(i){const i=n.get(e);i&&(l(i,t),0===(o.get(i)||0)&&m(i,{type:"delete",key:t,oldValue:r}))}return i}};function A(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const o=new Proxy(e,k);return n.set(e,o),o}function x(t,n,o={}){const{throttle:i=0,onBatch:s,immediate:a=!1,deepCompare:l}=o,c={callback:n,onBatch:s,throttle:i,filterRegexes:(Array.isArray(o.filter)?o.filter:o.filter?[o.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=d.get(e);if(t)return t;let n="";for(let a=0;a<e.length;a++){const t=e[a];"*"===t&&"*"===e[a+1]?(n+="**",a++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),o=[];for(let a=0;a<r.length;a++){const e=r[a];"**"===e?1===r.length?o.push(".*"):0===a?o.push("(?:[^.]+\\.)*"):o.push("(?:\\.[^.]+)*"):"*"===e?o.push("[^.]+"):o.push(e)}let i="^";for(let a=0;a<o.length;a++)if(i+=o[a],a<o.length-1){const e=o[a],t=o[a+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;i+="\\."}i+="$";const s=new RegExp(i);return d.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:l},u=A(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(c),a){const n=[...y],r=(t,o,i=[],s=new WeakSet)=>{e(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(a=>{const l=Reflect.get(t,a);if(e(l)&&s.has(l))return;const c=Reflect.get(o,a),f=[...i,a];n.forEach(e=>{g(f,e.filterRegexes)&&b(e,{type:"set",key:a,newValue:l,oldValue:void 0,path:f})}),e(l)&&!p(l)&&r(l,c,f,s)}))};r(f(t),u)}const h=()=>{const e=r.get(u);e&&(e.delete(c),0===e.size&&r.delete(u)),c.pending=[],c.timer&&(clearTimeout(c.timer),c.timer=null)};return{proxy:u,unobserve:()=>{c.active&&(c.active=!1,h())},resume:()=>{c.active||(c.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(c)})())},dispose:()=>{if(!c.active)return c.callback=()=>{},void(c.onBatch=void 0);c.active=!1,h(),c.callback=()=>{},c.onBatch=void 0}}}export{y as isProxy,x as observe,h as toProxy,f as toRaw};
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",copy:"©",reg:"®",trade:"™",hellip:"…",middot:"·",euro:"€"},t={128:8364,130:8218,131:402,132:8222,133:8230,134:8224,135:8225,136:710,137:8240,138:352,139:8249,140:338,142:381,145:8216,146:8217,147:8220,148:8221,149:8226,150:8211,151:8212,152:732,153:8482,154:353,155:8250,156:339,158:382,159:376},r=/&(?:#([xX][0-9a-fA-F]+|\d+)|([a-zA-Z0-9]+));/g;exports.default=function(o){return o&&"string"==typeof o&&o.includes("&")?o.replace(r,(r,o,n)=>{if(n)return e[n.toLowerCase()]||r;if(o){const e="x"===o[0]||"X"===o[0];let n=parseInt(e?o.slice(1):o,e?16:10);return isNaN(n)?r:(n>=128&&n<=159&&(n=t[n]||n),0===n||n>=55296&&n<=57343||n>1114111?"�":String.fromCodePoint(n))}return r}):o};
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",ensp:" ",emsp:" ",thinsp:" ",shy:"­",zwj:"‍",zwnj:"‌",hellip:"…",middot:"·",bull:"•",ndash:"–",mdash:"—",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",laquo:"«",raquo:"»",lsaquo:"‹",rsaquo:"›",dagger:"†",Dagger:"‡",prime:"′",Prime:"″",permil:"‰",cent:"¢",pound:"£",yen:"¥",euro:"€",curren:"¤",copy:"©",reg:"®",trade:"™",deg:"°",plusmn:"±",times:"×",divide:"÷",frac12:"½",frac14:"¼",frac34:"¾",sup1:"¹",sup2:"²",sup3:"³",micro:"µ",para:"¶",sect:"§",iexcl:"¡",iquest:"¿",minus:"−",le:"≤",ge:"≥",ne:"≠",asymp:"≈",equiv:"≡",infin:"∞",sum:"∑",radic:"√",larr:"←",uarr:"↑",rarr:"→",darr:"↓",harr:"↔"},r={128:8364,130:8218,131:402,132:8222,133:8230,134:8224,135:8225,136:710,137:8240,138:352,139:8249,140:338,142:381,145:8216,146:8217,147:8220,148:8221,149:8226,150:8211,151:8212,152:732,153:8482,154:353,155:8250,156:339,158:382,159:376},t=/&(?:#([xX][0-9a-fA-F]+|\d+)|([a-zA-Z0-9]+));/g;exports.default=function(s){return s&&"string"==typeof s&&s.includes("&")?s.replace(t,(t,s,o)=>{if(o){if(Object.prototype.hasOwnProperty.call(e,o))return e[o];const r=o.toLowerCase();return Object.prototype.hasOwnProperty.call(e,r)?e[r]:t}if(s){const e="x"===s[0]||"X"===s[0];let o=parseInt(e?s.slice(1):s,e?16:10);return isNaN(o)?t:(o>=128&&o<=159&&(o=r[o]||o),0===o||o>=55296&&o<=57343||o>1114111?"�":String.fromCodePoint(o))}return t}):s};
@@ -1 +1 @@
1
- const t={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",copy:"©",reg:"®",trade:"™",hellip:"…",middot:"·",euro:"€"},e={128:8364,130:8218,131:402,132:8222,133:8230,134:8224,135:8225,136:710,137:8240,138:352,139:8249,140:338,142:381,145:8216,146:8217,147:8220,148:8221,149:8226,150:8211,151:8212,152:732,153:8482,154:353,155:8250,156:339,158:382,159:376},r=/&(?:#([xX][0-9a-fA-F]+|\d+)|([a-zA-Z0-9]+));/g;function o(o){return o&&"string"==typeof o&&o.includes("&")?o.replace(r,(r,o,n)=>{if(n)return t[n.toLowerCase()]||r;if(o){const t="x"===o[0]||"X"===o[0];let n=parseInt(t?o.slice(1):o,t?16:10);return isNaN(n)?r:(n>=128&&n<=159&&(n=e[n]||n),0===n||n>=55296&&n<=57343||n>1114111?"�":String.fromCodePoint(n))}return r}):o}export{o as default};
1
+ const r={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",ensp:" ",emsp:" ",thinsp:" ",shy:"­",zwj:"‍",zwnj:"‌",hellip:"…",middot:"·",bull:"•",ndash:"–",mdash:"—",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",laquo:"«",raquo:"»",lsaquo:"‹",rsaquo:"›",dagger:"†",Dagger:"‡",prime:"′",Prime:"″",permil:"‰",cent:"¢",pound:"£",yen:"¥",euro:"€",curren:"¤",copy:"©",reg:"®",trade:"™",deg:"°",plusmn:"±",times:"×",divide:"÷",frac12:"½",frac14:"¼",frac34:"¾",sup1:"¹",sup2:"²",sup3:"³",micro:"µ",para:"¶",sect:"§",iexcl:"¡",iquest:"¿",minus:"−",le:"≤",ge:"≥",ne:"≠",asymp:"≈",equiv:"≡",infin:"∞",sum:"∑",radic:"√",larr:"←",uarr:"↑",rarr:"→",darr:"↓",harr:"↔"},e={128:8364,130:8218,131:402,132:8222,133:8230,134:8224,135:8225,136:710,137:8240,138:352,139:8249,140:338,142:381,145:8216,146:8217,147:8220,148:8221,149:8226,150:8211,151:8212,152:732,153:8482,154:353,155:8250,156:339,158:382,159:376},t=/&(?:#([xX][0-9a-fA-F]+|\d+)|([a-zA-Z0-9]+));/g;function a(a){return a&&"string"==typeof a&&a.includes("&")?a.replace(t,(t,a,s)=>{if(s){if(Object.prototype.hasOwnProperty.call(r,s))return r[s];const e=s.toLowerCase();return Object.prototype.hasOwnProperty.call(r,e)?r[e]:t}if(a){const r="x"===a[0]||"X"===a[0];let s=parseInt(r?a.slice(1):a,r?16:10);return isNaN(s)?t:(s>=128&&s<=159&&(s=e[s]||s),0===s||s>=55296&&s<=57343||s>1114111?"�":String.fromCodePoint(s))}return t}):a}export{a as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../types/ast.cjs"),t=require("../../shared/templateError.cjs"),s=require("../../shared/env.cjs"),n=require("./html-decode.cjs"),i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]),c=new WeakMap;function p(e){let t=c.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},c.set(e,t)),t}function l(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function d(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?u(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const f=e=>!(!e||0===e.length||/\s/.test(e)&&(s.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function u(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function m(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function v(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void m(e,t,s);const o=e,h=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==h&&"TEXTAREA"!==h||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?m(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class y{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const o=this.ir.fns[e-1];if(s.IS_DEV)try{return o?o.apply(this.scope,n):""}catch(r){return t.showTemplateError(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n.default(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=c.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=p(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let c;r.loops=s;let l,d=!1,y=!1;for(const p of t){const{k:t,f:f,d:u,v:g}=p;if(":class"===t){c=this.evalIR(f??-1,[s],p.__m),d=!0;continue}if(":style"===t){l=this.evalIR(f??-1,[s],p.__m),y=!0;continue}if("class"===t||"style"===t)continue;const N=t[0];if("@"===N){const s=t.slice(1),i=p.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(f??-1,[e,r.loops],p.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("ref"===t&&g){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[g]=e;continue}const S=u?this.evalIR(f??-1,[s],p.__m):g??"";if(":"===N){const s=t.slice(1);"SELECT"===e.tagName&&h.has(s)?o.push(()=>v(e,s,S,a)):v(e,s,S,a)}else n||m(e,t,String(S))}return d&&((e,t)=>{const s=p(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const h in i)f(h)&&(o[h]=i[h]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const h in n)o[h]||a.push(h);for(const h in o)n[h]||r.push(h);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,c),y&&((e,t)=>{const s=p(e),n=u(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,l),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.ASTType.Element:{const e=this.createElement(t,s);l(e,t),d(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.ASTType.Text:return this.createText(t,n);case e.ASTType.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.ASTType.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.ASTType.Element:a=this.createElement(t,n),l(a,t),d(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.ASTType.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.ASTType.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.ASTType.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const h=this.isKaRestoring;this.isKaRestoring=!0;const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=c,this.isKaRestoring=h}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const c=t+".0";if(this.prevNodeMap.get(c))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=h}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}exports.IRRenderer=y,exports.createRender=(e,t,s={})=>{const n=new y(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../types/ast.cjs"),t=require("../../shared/templateError.cjs"),s=require("../../shared/env.cjs"),n=require("./html-decode.cjs"),i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),c=new Set(["value","selectedIndex"]),h=new Set(["href","src","srcset","action","formaction","xlink:href","poster"]),l=new Set(["srcdoc"]),p=/^\s*(?:javascript|vbscript)\s*:|^\s*data:text\/html(?:[;,]|$)/i,d=new WeakMap;function f(e,t,n){if(!s.IS_DEV)return;let i=d.get(e);i||(i=new Set,d.set(e,i)),i.has(t)||(i.add(t),console.warn(n))}const u=new WeakMap;function m(e){let t=u.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},u.set(e,t)),t}function v(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function y(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?S(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const g=e=>!(!e||0===e.length||/\s/.test(e)&&(s.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function S(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function k(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function N(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void k(e,t,s);if(l.has(t)&&null!=s)return void function(e,t){f(e,`srcdoc:${String(t)}`,'[Solely] Blocked "srcdoc" binding (HTML injection risk). Use a sandboxed iframe with "src" instead.')}(e,s);if((h.has(t)||h.has(i))&&function(e){return"string"==typeof e&&p.test(e.replace(/\s+/g,""))}(s))return void function(e,t,s){f(e,`${t}:${String(s)}`,`[Solely] Blocked unsafe URL for "${t}": ${String(s).slice(0,80)}. Use a http(s)/relative URL instead.`)}(e,t,s);const o=e,c=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==c&&"TEXTAREA"!==c||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?k(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class K{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,n,i){const o=this.ir.fns[e-1];if(s.IS_DEV)try{return o?o.apply(this.scope,n):""}catch(r){return t.showTemplateError(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):n.default(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=u.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=m(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;r.loops=s;let l,p=!1,d=!1;for(const f of t){const{k:t,f:u,d:m,v:v}=f;if(":class"===t){h=this.evalIR(u??-1,[s],f.__m),p=!0;continue}if(":style"===t){l=this.evalIR(u??-1,[s],f.__m),d=!0;continue}if("class"===t||"style"===t)continue;const y=t[0];if("@"===y){const s=t.slice(1),i=f.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(u??-1,[e,r.loops],f.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],f.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const g=m?this.evalIR(u??-1,[s],f.__m):v??"";if(":"===y){const s=t.slice(1);"SELECT"===e.tagName&&c.has(s)?o.push(()=>N(e,s,g,a)):N(e,s,g,a)}else n||k(e,t,String(g))}return p&&((e,t)=>{const s=m(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const c in i)g(c)&&(o[c]=i[c]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const c in n)o[c]||a.push(c);for(const c in o)n[c]||r.push(c);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,h),d&&((e,t)=>{const s=m(e),n=S(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,l),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(t,s,n){switch(t.t){case e.ASTType.Element:{const e=this.createElement(t,s);v(e,t),y(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.ASTType.Text:return this.createText(t,n);case e.ASTType.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.ASTType.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.ASTType.Element:a=this.createElement(t,n),v(a,t),y(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.ASTType.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.ASTType.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.ASTType.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const c=this.isKaRestoring;this.isKaRestoring=!0;const h=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=h,this.isKaRestoring=c}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const c=this.currentKaKey;this.currentKaKey=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const h=t+".0";if(this.prevNodeMap.get(h))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=c}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),i?.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}exports.IRRenderer=K,exports.createRender=(e,t,s={})=>{const n=new K(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};