@jasonshimmy/custom-elements-runtime 2.7.0 → 2.8.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.
- package/dist/custom-elements-runtime.cjs.js +1 -1
- package/dist/custom-elements-runtime.directive-enhancements.cjs.js +1 -1
- package/dist/custom-elements-runtime.directive-enhancements.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.directive-enhancements.es.js +88 -80
- package/dist/custom-elements-runtime.directive-enhancements.es.js.map +1 -1
- package/dist/custom-elements-runtime.directives.cjs.js +1 -1
- package/dist/custom-elements-runtime.directives.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.directives.es.js +53 -23
- package/dist/custom-elements-runtime.directives.es.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +2 -2
- package/dist/custom-elements-runtime.router.cjs.js +1 -1
- package/dist/custom-elements-runtime.router.es.js +1 -1
- package/dist/directives.d.ts +15 -2
- package/dist/{template-compiler-D0LrTkNv.js → template-compiler-CVBKYu3j.js} +541 -540
- package/dist/{template-compiler-D0LrTkNv.js.map → template-compiler-CVBKYu3j.js.map} +1 -1
- package/dist/template-compiler-G8h2OJbA.cjs +23 -0
- package/dist/{template-compiler-C-jyYSkk.cjs.map → template-compiler-G8h2OJbA.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/template-compiler-C-jyYSkk.cjs +0 -23
|
@@ -1,14 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
let u = "", i = 0;
|
|
2
|
+
const s = [];
|
|
3
|
+
function y() {
|
|
4
|
+
u = "", i = 0, s.length = 0;
|
|
5
|
+
}
|
|
6
|
+
function d() {
|
|
7
|
+
return i++;
|
|
8
|
+
}
|
|
9
|
+
function h(n) {
|
|
10
|
+
const t = i++;
|
|
11
|
+
return n !== void 0 ? n : u ? `${u}.${t}` : `when-block-${t}`;
|
|
12
|
+
}
|
|
13
|
+
function a(n) {
|
|
14
|
+
s.push([u, i]), u = n, i = 0;
|
|
15
|
+
}
|
|
16
|
+
function p() {
|
|
17
|
+
const n = s[s.length - 1];
|
|
18
|
+
n && (s.length--, [u, i] = n);
|
|
4
19
|
}
|
|
5
|
-
function
|
|
20
|
+
function $(n, t, e) {
|
|
21
|
+
const r = h(e);
|
|
22
|
+
if (typeof t != "function")
|
|
23
|
+
return c(n ? t : [], r);
|
|
24
|
+
if (!n)
|
|
25
|
+
return c([], r);
|
|
26
|
+
a(r);
|
|
27
|
+
const o = t();
|
|
28
|
+
return p(), c(o, r);
|
|
29
|
+
}
|
|
30
|
+
function x(n, t) {
|
|
6
31
|
return n.map((e, r) => {
|
|
7
|
-
const
|
|
8
|
-
return
|
|
32
|
+
const o = typeof e == "object" ? e?.key ?? e?.id ?? `idx-${r}` : String(e);
|
|
33
|
+
return c(t(e, r), `each-${o}`);
|
|
9
34
|
});
|
|
10
35
|
}
|
|
11
|
-
function
|
|
36
|
+
function g() {
|
|
12
37
|
const n = [];
|
|
13
38
|
return {
|
|
14
39
|
when(t, e) {
|
|
@@ -18,21 +43,24 @@ function a() {
|
|
|
18
43
|
return n.push([!0, t]), this;
|
|
19
44
|
},
|
|
20
45
|
done() {
|
|
21
|
-
|
|
46
|
+
const t = `match-${h()}`;
|
|
47
|
+
for (let e = 0; e < n.length; e++) {
|
|
48
|
+
const [r, o] = n[e];
|
|
49
|
+
if (r) {
|
|
50
|
+
const f = `${t}-branch-${e}`;
|
|
51
|
+
if (typeof o == "function") {
|
|
52
|
+
a(f);
|
|
53
|
+
const l = o();
|
|
54
|
+
return p(), [c(l, f)];
|
|
55
|
+
}
|
|
56
|
+
return [c(o, f)];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return [c([], `${t}-empty`)];
|
|
22
60
|
}
|
|
23
61
|
};
|
|
24
62
|
}
|
|
25
|
-
function
|
|
26
|
-
for (let t = 0; t < n.length; t++) {
|
|
27
|
-
const [e, r] = n[t];
|
|
28
|
-
if (e) {
|
|
29
|
-
const u = typeof r == "function" ? r() : r;
|
|
30
|
-
return [o(u, `whenChain-branch-${t}`)];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return [o([], "whenChain-empty")];
|
|
34
|
-
}
|
|
35
|
-
function o(n, t) {
|
|
63
|
+
function c(n, t) {
|
|
36
64
|
const e = n ? Array.isArray(n) ? n.filter((r) => r != null) : [n].filter((r) => r != null) : [];
|
|
37
65
|
return {
|
|
38
66
|
tag: "#anchor",
|
|
@@ -41,9 +69,11 @@ function o(n, t) {
|
|
|
41
69
|
};
|
|
42
70
|
}
|
|
43
71
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
c as anchorBlock,
|
|
73
|
+
x as each,
|
|
74
|
+
g as match,
|
|
75
|
+
d as nextDirectiveIndex,
|
|
76
|
+
y as resetWhenCounter,
|
|
77
|
+
$ as when
|
|
48
78
|
};
|
|
49
79
|
//# sourceMappingURL=custom-elements-runtime.directives.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-elements-runtime.directives.es.js","sources":["../src/lib/directives.ts"],"sourcesContent":["import type { VNode } from './runtime/types';\n\n/* --- When --- */\nexport function when(cond: boolean
|
|
1
|
+
{"version":3,"file":"custom-elements-runtime.directives.es.js","sources":["../src/lib/directives.ts"],"sourcesContent":["import type { VNode } from './runtime/types';\n\n// ── Per-render directive scope tracking ─────────────────────────────────────\n//\n// A FLAT counter (index++) breaks when a when() factory itself contains more\n// when() calls: those inner calls consume counter slots, causing SUBSEQUENT\n// SIBLING when() calls to get a different index depending on whether the factory\n// ran. For example:\n//\n// when(A, () => { when(B); when(C); }) // ← factory may or may not run\n// when(D) // ← index shifts when factory runs\n//\n// The fix: each when() call claims its own slot (stable regardless of whether\n// the factory runs), then ENTERS a new child scope for the factory. Inner\n// when() calls consume indices in that child scope, never bleeding into the\n// sibling counter of the outer scope.\n//\n// Key format: root sibling 0 → \"when-block-0\"\n// child of \"when-block-0\" at pos 1 → \"when-block-0.1\"\n// grandchild → \"when-block-0.1.0\" etc.\n\n/** Current scope's parent prefix (empty string = root scope). */\nlet _scopeParent = '';\n/** Next sibling index inside the current scope. */\nlet _scopeIndex = 0;\n/** Stack of [parentPrefix, siblingIndex] for nested scopes. */\nconst _scopeStack: Array<readonly [string, number]> = [];\n\n/**\n * Reset all scope state at the start of each component render pass.\n * Called automatically by the component renderer — not needed in user code.\n * @internal\n */\nexport function resetWhenCounter(): void {\n _scopeParent = '';\n _scopeIndex = 0;\n _scopeStack.length = 0;\n}\n\n/**\n * Claim the next directive call index within the current scope.\n * Used by directive-enhancements.ts for non-when() directives (switchOnLength,\n * switchOnPromise, etc.) that need a stable unique number per call site.\n * @internal\n */\nexport function nextDirectiveIndex(): number {\n return _scopeIndex++;\n}\n\n/** Claim the next slot in the current scope and return its anchor key. */\nfunction claimKey(explicitKey?: string): string {\n const idx = _scopeIndex++;\n if (explicitKey !== undefined) return explicitKey;\n return _scopeParent ? `${_scopeParent}.${idx}` : `when-block-${idx}`;\n}\n\n/** Push a new child scope keyed under `anchorKey`. */\nfunction enterScope(anchorKey: string): void {\n _scopeStack.push([_scopeParent, _scopeIndex] as const);\n _scopeParent = anchorKey;\n _scopeIndex = 0;\n}\n\n/** Pop back to the parent scope. */\nfunction exitScope(): void {\n const top = _scopeStack[_scopeStack.length - 1];\n if (top) {\n _scopeStack.length--;\n [_scopeParent, _scopeIndex] = top;\n }\n}\n\n/* --- When --- */\nexport function when(\n cond: boolean,\n children: VNode | VNode[],\n key?: string,\n): VNode;\nexport function when(\n cond: boolean,\n factory: () => VNode | VNode[],\n key?: string,\n): VNode;\nexport function when(\n cond: boolean,\n childrenOrFactory: VNode | VNode[] | (() => VNode | VNode[]),\n key?: string,\n): VNode {\n // Claim this call's position BEFORE potentially entering a child scope.\n // This guarantees sibling when() calls always get the same index regardless\n // of whether a factory executes and how many when() calls it contains.\n const anchorKey = claimKey(key);\n\n if (typeof childrenOrFactory !== 'function') {\n return anchorBlock(cond ? childrenOrFactory : [], anchorKey);\n }\n\n if (!cond) {\n return anchorBlock([], anchorKey);\n }\n\n // Run the factory in a child scope so its inner when() calls don't\n // affect the sibling counter of the outer scope.\n enterScope(anchorKey);\n const children = childrenOrFactory();\n exitScope();\n return anchorBlock(children, anchorKey);\n}\n\n/* --- Each --- */\nexport function each<\n T extends string | number | boolean | { id?: string | number; key?: string },\n>(list: T[], render: (item: T, index: number) => VNode | VNode[]): VNode[] {\n return list.map((item, i) => {\n // For primitives, use value as key; for objects, prefer key/id\n const itemKey =\n typeof item === 'object'\n ? ((item as Record<string, unknown>)?.key ??\n (item as Record<string, unknown>)?.id ??\n `idx-${i}`)\n : String(item);\n return anchorBlock(render(item, i), `each-${itemKey}`);\n });\n}\n\n/* --- match --- */\ntype Branch = [\n condition: unknown,\n content: VNode | VNode[] | (() => VNode | VNode[]),\n];\n\nexport function match() {\n const branches: Branch[] = [];\n return {\n when(cond: unknown, content: VNode | VNode[] | (() => VNode | VNode[])) {\n branches.push([cond, content]);\n return this;\n },\n otherwise(content: VNode | VNode[]) {\n branches.push([true, content]);\n return this;\n },\n done() {\n const matchKey = `match-${claimKey()}`;\n for (let idx = 0; idx < branches.length; idx++) {\n const [cond, content] = branches[idx];\n if (cond) {\n const branchKey = `${matchKey}-branch-${idx}`;\n if (typeof content === 'function') {\n enterScope(branchKey);\n const payload = (content as () => VNode | VNode[])();\n exitScope();\n return [anchorBlock(payload, branchKey)];\n }\n return [anchorBlock(content, branchKey)];\n }\n }\n return [anchorBlock([], `${matchKey}-empty`)];\n },\n };\n}\n\n/**\n * Create a stable anchor block with consistent boundaries.\n * Always has start/end boundaries.\n */\nexport function anchorBlock(\n children: VNode | VNode[] | null | undefined,\n anchorKey: string,\n): VNode {\n // Normalize children to array, filtering out only null/undefined values.\n // Preserve meaningful falsy values such as 0, false, and empty string.\n const childArray = !children\n ? []\n : Array.isArray(children)\n ? children.filter((c) => c !== null && c !== undefined)\n : [children].filter((c) => c !== null && c !== undefined);\n\n return {\n tag: '#anchor',\n key: anchorKey,\n children: childArray,\n };\n}\n"],"names":["_scopeParent","_scopeIndex","_scopeStack","resetWhenCounter","nextDirectiveIndex","claimKey","explicitKey","idx","enterScope","anchorKey","exitScope","top","when","cond","childrenOrFactory","key","anchorBlock","children","each","list","render","item","i","itemKey","match","branches","content","matchKey","branchKey","payload","childArray","c"],"mappings":"AAsBA,IAAIA,IAAe,IAEfC,IAAc;AAElB,MAAMC,IAAgD,CAAA;AAO/C,SAASC,IAAyB;AACvC,EAAAH,IAAe,IACfC,IAAc,GACdC,EAAY,SAAS;AACvB;AAQO,SAASE,IAA6B;AAC3C,SAAOH;AACT;AAGA,SAASI,EAASC,GAA8B;AAC9C,QAAMC,IAAMN;AACZ,SAAIK,MAAgB,SAAkBA,IAC/BN,IAAe,GAAGA,CAAY,IAAIO,CAAG,KAAK,cAAcA,CAAG;AACpE;AAGA,SAASC,EAAWC,GAAyB;AAC3C,EAAAP,EAAY,KAAK,CAACF,GAAcC,CAAW,CAAU,GACrDD,IAAeS,GACfR,IAAc;AAChB;AAGA,SAASS,IAAkB;AACzB,QAAMC,IAAMT,EAAYA,EAAY,SAAS,CAAC;AAC9C,EAAIS,MACFT,EAAY,UACZ,CAACF,GAAcC,CAAW,IAAIU;AAElC;AAaO,SAASC,EACdC,GACAC,GACAC,GACO;AAIP,QAAMN,IAAYJ,EAASU,CAAG;AAE9B,MAAI,OAAOD,KAAsB;AAC/B,WAAOE,EAAYH,IAAOC,IAAoB,CAAA,GAAIL,CAAS;AAG7D,MAAI,CAACI;AACH,WAAOG,EAAY,CAAA,GAAIP,CAAS;AAKlC,EAAAD,EAAWC,CAAS;AACpB,QAAMQ,IAAWH,EAAA;AACjB,SAAAJ,EAAA,GACOM,EAAYC,GAAUR,CAAS;AACxC;AAGO,SAASS,EAEdC,GAAWC,GAA8D;AACzE,SAAOD,EAAK,IAAI,CAACE,GAAMC,MAAM;AAE3B,UAAMC,IACJ,OAAOF,KAAS,WACVA,GAAkC,OACnCA,GAAkC,MACnC,OAAOC,CAAC,KACR,OAAOD,CAAI;AACjB,WAAOL,EAAYI,EAAOC,GAAMC,CAAC,GAAG,QAAQC,CAAO,EAAE;AAAA,EACvD,CAAC;AACH;AAQO,SAASC,IAAQ;AACtB,QAAMC,IAAqB,CAAA;AAC3B,SAAO;AAAA,IACL,KAAKZ,GAAea,GAAoD;AACtE,aAAAD,EAAS,KAAK,CAACZ,GAAMa,CAAO,CAAC,GACtB;AAAA,IACT;AAAA,IACA,UAAUA,GAA0B;AAClC,aAAAD,EAAS,KAAK,CAAC,IAAMC,CAAO,CAAC,GACtB;AAAA,IACT;AAAA,IACA,OAAO;AACL,YAAMC,IAAW,SAAStB,EAAA,CAAU;AACpC,eAASE,IAAM,GAAGA,IAAMkB,EAAS,QAAQlB,KAAO;AAC9C,cAAM,CAACM,GAAMa,CAAO,IAAID,EAASlB,CAAG;AACpC,YAAIM,GAAM;AACR,gBAAMe,IAAY,GAAGD,CAAQ,WAAWpB,CAAG;AAC3C,cAAI,OAAOmB,KAAY,YAAY;AACjC,YAAAlB,EAAWoB,CAAS;AACpB,kBAAMC,IAAWH,EAAA;AACjB,mBAAAhB,EAAA,GACO,CAACM,EAAYa,GAASD,CAAS,CAAC;AAAA,UACzC;AACA,iBAAO,CAACZ,EAAYU,GAASE,CAAS,CAAC;AAAA,QACzC;AAAA,MACF;AACA,aAAO,CAACZ,EAAY,CAAA,GAAI,GAAGW,CAAQ,QAAQ,CAAC;AAAA,IAC9C;AAAA,EAAA;AAEJ;AAMO,SAASX,EACdC,GACAR,GACO;AAGP,QAAMqB,IAAcb,IAEhB,MAAM,QAAQA,CAAQ,IACpBA,EAAS,OAAO,CAACc,MAAMA,KAAM,IAAuB,IACpD,CAACd,CAAQ,EAAE,OAAO,CAACc,MAAMA,KAAM,IAAuB,IAHxD,CAAA;AAKJ,SAAO;AAAA,IACL,KAAK;AAAA,IACL,KAAKtB;AAAA,IACL,UAAUqB;AAAA,EAAA;AAEd;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as v, u as b, a as T, h as l, b as x, g as k, v as m, i as A } from "./template-compiler-
|
|
2
|
-
import { d as ee, e as te, f as ne, p as oe, j as re, k as se, l as ie, m as ae, n as ce, o as le } from "./template-compiler-
|
|
1
|
+
import { c as v, u as b, a as T, h as l, b as x, g as k, v as m, i as A } from "./template-compiler-CVBKYu3j.js";
|
|
2
|
+
import { d as ee, e as te, f as ne, p as oe, j as re, k as se, l as ie, m as ae, n as ce, o as le } from "./template-compiler-CVBKYu3j.js";
|
|
3
3
|
import { r as p, a as I } from "./namespace-helpers-DhLBqt-7.js";
|
|
4
4
|
import { R as he, c as de, d as fe, f as me, i as pe, n as ye, s as ge, u as ve, w as Ce, b as we } from "./namespace-helpers-DhLBqt-7.js";
|
|
5
5
|
import { c as _e } from "./transitions-DMJXs_tY.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./logger-CSALKaYm.cjs"),$=require("./namespace-helpers-Ctd_h7j2.cjs"),x=require("./template-compiler-C-jyYSkk.cjs"),ot=require("./custom-elements-runtime.store.cjs.js"),bt=require("./custom-elements-runtime.directives.cjs.js"),rt={enabled:!0,offset:0,timeoutMs:2e3},tt=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},ft=t=>{if(!t||Object.keys(t).length===0)return"";try{return"?"+new URLSearchParams(t).toString()}catch{return""}},nt=t=>t?/^\s*javascript\s*:/i.test(t):!1,U=t=>/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t)||t.startsWith("//"),dt=t=>{try{return decodeURIComponent(t)}catch{return t}};function A(t){if(!t)return"/";let r=t.replace(/\/+/g,"/");return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r}const ht=t=>{if(!t)return"";const r=A(t);return r==="/"?"":r},st=new WeakMap;function wt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function St(t){const r=t.path||"/",v=A(r),a=v==="/"?[]:v.split("/").filter(Boolean),l=[],o=[];for(let u=0;u<a.length;u++){const f=a[u];if(f==="*"){if(u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const W=`splat${l.length}`;l.push(W),o.push("__SPLAT__");continue}const y=f.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(y){const W=y[1],k=!!y[2];if(k&&u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a splat param ':${W}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};l.push(W),o.push(k?"__SPLAT__":"([^/]+)");continue}o.push(wt(f))}let b;if(o.length===0)b="^/$";else if(o[o.length-1]==="__SPLAT__"){const f=o.slice(0,-1).join("/");f?b=`^/${f}(?:/(.*))?(?:/)?$`:b="^(?:/(.*))?(?:/)?$"}else b=`^/${o.join("/")}(?:/)?$`;try{return{regex:new RegExp(b),paramNames:l}}catch(u){return c.devWarn(`Failed to compile route regex for '${t.path}': ${String(u)}`),{invalid:!0}}}const F=(t,r)=>{const v=A(r);for(const a of t){let l=st.get(a);if(l||(l=St(a),st.set(a,l)),l.invalid)continue;const{regex:o,paramNames:b}=l,u=o.exec(v);if(u){const f={};for(let y=0;y<b.length;y++){const W=u[y+1]||"";f[b[y]]=W?dt(W):""}return{route:a,params:f}}}return{route:null,params:{}}};function Z(t,r){for(const v of t)if(F([v],r).route!==null)return v;return null}function Rt(t,r){return F(t,r)}const ct=50;let G={},L={};function pt(){G={},L={}}function Et(){const t=Object.entries(G);if(t.length<=ct)return;const v=t.sort(([,a],[,l])=>a.lastAccessed-l.lastAccessed).slice(0,t.length-ct);for(const[a]of v)delete G[a]}async function yt(t){if(t.component)return t.component;if(t.load){const r=G[t.path];if(r)return r.lastAccessed=Date.now(),r.component;if(L[t.path]!==void 0)return L[t.path];const v=typeof window>"u";try{const a=t.load().then(l=>{Et();const o=l.default;return G[t.path]={component:o,lastAccessed:Date.now()},delete L[t.path],o}).catch(l=>{delete L[t.path];const o=l instanceof Error?l.message:String(l);throw v&&c.devError(`SSR component load failed for route: ${t.path}. ${o}`),new Error(`Failed to load component for route: ${t.path}. ${o}`)});return L[t.path]=a,await a}catch(a){const l=a instanceof Error?a.message:String(a);throw new Error(`Failed to load component for route: ${t.path}. ${l}`,{cause:a})}}throw new Error(`No component or loader defined for route: ${t.path}`)}let g=null;function $t(t){g=t}function it(){return g}const j=new Set;let N=null;function mt(){if(N){try{N()}catch{}N=null}if(g)try{let t=!1;N=g.subscribe(r=>{t=!0;for(const v of j)try{v(r)}catch{}});try{C.base=g.base}catch{}if(t){const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}else{const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}try{typeof window<"u"&&$.flushDOMUpdates()}catch{}}catch{N=null}}function Ct(){mt()}const C={store:{subscribe(t){if(g)return g.store.subscribe(t);try{t({path:"/",params:{},query:{}})}catch{}return()=>{}},getState(){return g?g.getCurrent():{path:"/",params:{},query:{}}},setState(t){if(g)try{g.store.setState(t)}catch{}}},subscribe(t){if(typeof t!="function")return c.devWarn("activeRouterProxy.subscribe: listener must be a function"),()=>{};if(j.add(t),g)if(!N)mt();else try{const r=g.getCurrent();r&&t(r)}catch(r){c.devWarn("activeRouterProxy subscription failed",r)}else try{t({path:"/",params:{},query:{}})}catch(r){c.devWarn("activeRouterProxy fallback state delivery failed",r)}return()=>{try{if(j.delete(t),j.size===0&&N){try{N()}catch(r){c.devWarn("activeRouterProxy inner unsubscribe failed",r)}N=null}}catch(r){c.devWarn("activeRouterProxy unsubscribe failed",r)}}},getCurrent(){return g?g.getCurrent():{path:"/",params:{},query:{}}},async push(t){return g?g.push(t):Promise.resolve()},async replace(t){return g?g.replace(t):Promise.resolve()},back(){if(g)return g.back()},matchRoute(t){return g?g.matchRoute(t):{route:null,params:{}}},resolveRouteComponent(t){return g?g.resolveRouteComponent(t):Promise.reject(new Error("No active router"))},base:"",scrollToFragment(t){return g?g.scrollToFragment(t):Promise.resolve(!1)}};function vt(t){const{routes:r,base:v="",initialUrl:a,scrollToFragment:l=!0}=t,o=ht(v),b=typeof l=="boolean"?{...rt,enabled:l}:{...rt,...l};let u,f,y,W,k,z,B;const _=new Set,K=10;let q=0;const J=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.beforeEnter)return!0;try{const n=await e.beforeEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("beforeEnter error",n);try{y.setState(i)}catch{}throw n}},X=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.onEnter)return!0;try{const n=await e.onEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("onEnter error",n);try{y.setState(i)}catch{}throw n}},et=(s,i)=>{const e=Z(r,s.path);if(!(!e||!e.afterEnter))try{e.afterEnter(s,i)}catch(n){c.devError("afterEnter error",n)}},I=new Map,M=100,T=s=>{if(I.has(s))return I.get(s);const i=F(r,s);if(I.size>=M){const e=Math.floor(M*.25),n=Array.from(I.keys());for(let p=0;p<e&&p<n.length;p++)I.delete(n[p])}return I.set(s,i),i},Y=()=>{};async function V(s,i=0){try{const e=document.getElementById(s);if(!e)return!1;if(i>0)try{const n=e.getBoundingClientRect(),p=Math.max(0,window.scrollY+n.top-i);typeof window.scrollTo=="function"&&window.scrollTo({top:p,behavior:"auto"})}catch{try{e.scrollIntoView()}catch{return!1}}else if(typeof e.scrollIntoView=="function")try{e.scrollIntoView({behavior:"auto",block:"start",inline:"nearest"})}catch{try{e.scrollIntoView()}catch{return!1}}return!0}catch{return!1}}function h(s,i=0,e=2e3){return new Promise(n=>{let p=!1,m=null;const w=Date.now(),S=P=>{p||(p=!0,m&&clearTimeout(m),n(P))},E=async()=>{if(!p)try{if(await V(s,i))return S(!0);const P=async()=>{if(p)return;if(Date.now()-w>=e)return S(!1);try{if(await V(s,i))return S(!0);requestAnimationFrame(P)}catch(gt){c.devWarn("Scroll retry attempt failed:",gt),requestAnimationFrame(P)}};requestAnimationFrame(P)}catch(P){c.devWarn("Initial scroll attempt failed:",P),S(!1)}};m=setTimeout(()=>{S(!1)},e),E().catch(P=>{c.devWarn("Scroll attempt failed:",P),S(!1)})})}let R=!1;const d=async(s,i=!1)=>{if(R){c.devWarn(`Navigation to ${s} blocked - navigation already in progress`);return}R=!0,q=0,_.clear();try{await D(s,i)}finally{R=!1,q=0,_.clear()}},O=s=>{const i=s.indexOf("#"),e=i>=0?s.slice(i+1):"",n=i>=0?s.slice(0,i):s,p=n.indexOf("?"),m=p>=0?n.slice(0,p):n,w=p>=0?tt(n.slice(p)):{},S=m.startsWith(o)?m.slice(o.length):m;return{path:A(S||"/"),query:w,fragment:e}},D=async(s,i=!1)=>{try{const e=O(s),n=T(e.path);if(!n.route)throw new Error(`No route found for ${e.path}`);const p=y.getState(),m={path:e.path,params:n.params,query:e.query,fragment:e.fragment},w=await J(m,p);if(w===!1)return;if(typeof w=="string"){q++;const E=`${m.path}->${w}`;_.add(E),await D(w,!0);return}const S=await X(m,p);if(S===!1)return;if(typeof S=="string"){q++;const E=`${m.path}->${S}`;_.add(E),await D(S,!0);return}if(typeof window<"u"&&typeof document<"u"){const E=ft(e.query),P=o+e.path+(E||"")+(e.fragment?"#"+e.fragment:"");i?window.history.replaceState({},"",P):window.history.pushState({},"",P)}if(y.setState(m),et(m,p),typeof window<"u"&&typeof document<"u")try{const E=m.fragment;b.enabled&&E&&h(String(E),b.offset,b.timeoutMs).catch(()=>{})}catch{}}catch(e){if(c.devError("Navigation error:",e),e instanceof Error&&(e.stack?.includes("runBeforeEnter")||e.stack?.includes("runOnEnter")))throw e;try{const n=y.getState();if(!F(r,n.path).route){let m=r.find(w=>w.path==="/");if(m||(m=r.find(w=>!w.path.includes(":")&&!w.path.includes("*"))),!m&&r.length>0&&(m=r[0]),m){const w=F(r,m.path);y.setState({path:m.path,params:w.params,query:{}})}else c.devError("No fallback route available for error recovery")}}catch(n){c.devWarn("State recovery failed during navigation error:",n)}}};if((s=>{if(!s||s.length===0)return c.devError("Router configuration error: No routes provided"),!1;const i=new Set;for(const e of s){if(!e.path)return c.devError("Router configuration error: Route missing path",e),!1;i.has(e.path)&&c.devWarn(`Duplicate route path detected: ${e.path}`),i.add(e.path),!e.component&&!e.load&&c.devWarn(`Route '${e.path}' has no component or load function`)}return!0})(r),typeof window>"u"||typeof a<"u"){for(const s of r)T(s.path);c.devWarn(`Pre-compiled ${r.length} routes for SSR`)}if(typeof window<"u"&&typeof document<"u"&&typeof a>"u"){u=()=>{try{const e=new URL(window.location.href),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async(e=!1)=>{const n=u();await d(n.path,e)};const i=()=>W(!0);window.addEventListener("popstate",i),k=e=>d(e,!1),z=e=>d(e,!0),B=()=>window.history.back()}else{u=()=>{try{const e=new URL(a||"/","http://localhost"),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid SSR URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async()=>{const e=u();await i(e.path)};const i=async e=>{if(q++,q>K){c.devError(`SSR redirect depth exceeded for path: ${e}`);return}try{const n=O(e),p=T(n.path);if(!p.route)throw new Error(`No route found for ${n.path}`);const m=y.getState(),w={path:n.path,params:p.params,query:n.query,fragment:n.fragment},S=Z(r,w.path);if(S?.beforeEnter){const E=await S.beforeEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}if(S?.onEnter){const E=await S.onEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}y.setState(w),S?.afterEnter&&S.afterEnter(w,m)}catch(n){throw c.devError("SSR navigation error:",n),n}};k=async e=>(q=0,_.clear(),i(e)),z=async e=>(q=0,_.clear(),i(e)),B=()=>{}}return{_cleanupScrollState:Y,store:y,push:k,replace:z,back:B,subscribe:y.subscribe,matchRoute:s=>T(s),getCurrent:()=>y.getState(),resolveRouteComponent:yt,base:o,scrollToFragment:s=>{const i=s||y.getState().fragment;return!i||typeof window>"u"||typeof document>"u"?Promise.resolve(!1):h(i,b.offset,b.timeoutMs)}}}function At(t){pt();const r=vt(t),v=it();if(v)try{v._cleanupScrollState?.()}catch{}$t(r);try{Ct();try{typeof window<"u"&&$.flushDOMUpdates()}catch{}try{typeof window<"u"&&queueMicrotask(()=>{try{$.flushDOMUpdates()}catch{}})}catch{}}catch{}return x.component("router-view",async()=>{if(!it())return x.html`<div>Router not initialized.</div>`;const a=$.ref(C.getCurrent()),l=typeof window>"u";let o;l||(x.useOnConnected(()=>{try{typeof C.subscribe=="function"&&(o=C.subscribe(u=>{try{u&&typeof u=="object"&&typeof u.path=="string"?a.value=u:(c.devWarn("router-view received invalid state",u),a.value={path:"/",params:{},query:{}})}catch(f){c.devWarn("router-view subscription update failed",f);try{a.value={path:"/",params:{},query:{}}}catch{}}}))}catch(u){c.devWarn("router-view subscribe failed",u)}}),x.useOnDisconnected(()=>{if(typeof o=="function"){try{o()}catch(u){c.devWarn("router-view unsubscribe failed",u)}o=void 0}}));const b=C.matchRoute(a.value.path);if(!b||!b.route)return x.html`<div>Not found</div>`;try{const f=await C.resolveRouteComponent(b.route);if(typeof f=="string")return{tag:f,props:{},children:[]};if(typeof f=="function"){const y=f();return(y instanceof Promise?y:Promise.resolve(y)).then(k=>typeof k=="string"?{tag:k,props:{},children:[]}:k)}return x.html`<div>Invalid route component</div>`}catch{return x.html`<div>Invalid route component</div>`}}),x.component("router-link",()=>{const a=x.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),l=typeof window>"u",o=$.ref(C.getCurrent()),b=o.value?.path||"/",u=String(a.to||""),f=l?{isExactActive:lt(b,u,C.base),isActive:ut(b,u,C.base),isExternal:U(u)||!!a.external}:null;let y;x.useStyle(()=>"a,button{display:inline-block;}");const W=$.ref(a.class||""),k=$.ref(a.style||"");if(!l){let h=null;x.useOnConnected(R=>{try{if(typeof C.subscribe=="function"){y=C.subscribe(d=>{try{d&&typeof d=="object"&&typeof d.path=="string"?o.value=d:(c.devWarn("router-link received invalid state",d),o.value={path:"/",params:{},query:{}})}catch(O){c.devWarn("router-link subscription update failed",O);try{o.value={path:"/",params:{},query:{}}}catch{}}});try{const d=C.getCurrent();d&&typeof d.path=="string"&&(o.value=d)}catch(d){c.devWarn("router-link initial state sync failed",d)}h=setInterval(()=>{try{const d=C.getCurrent();d&&typeof d.path=="string"&&JSON.stringify(o.value)!==JSON.stringify(d)&&(o.value=d)}catch{}},100)}}catch(d){c.devWarn("router-link subscribe failed",d)}try{const d=R?._host;if(d instanceof HTMLElement){const O=d.getAttribute("class"),D=d.getAttribute("style");O&&(W.value=O),D&&(k.value=D),O!==null&&d.removeAttribute("class"),D!==null&&d.removeAttribute("style");try{R?._requestRender?.();try{$.flushDOMUpdates()}catch{}}catch{}}}catch(d){c.devWarn("router-link host migration failed",d)}}),x.useOnDisconnected(()=>{if(typeof y=="function")try{y()}catch(R){c.devWarn("router-link unsubscribe failed",R)}finally{y=void 0}if(h)try{clearInterval(h)}catch(R){c.devWarn("router-link sync interval cleanup failed",R)}finally{h=null}})}const z=$.computed(()=>{if(l&&f)return f.isExactActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:lt(o.value.path,R,h)}catch(h){return c.devWarn("isExactActive computation error",h),!1}}),B=$.computed(()=>{if(l&&f)return f.isActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:a.exact?z.value:ut(o.value.path,R,h)}catch(h){return c.devWarn("isActive computation error",h),!1}}),_=$.computed(()=>{const h=String(a.to||"");if(nt(h))return null;if(U(h))return h;const[R,d]=h.split("#"),[O,D]=(R||"").split("?"),H=C.base??"";let Q=O||"/";if(H&&H!=="/"){const s=A(H),i=A(Q);i.startsWith(s)?Q=i.slice(s.length)||"/":Q=i}const at=A(Q||"/");return H+at+(D?"?"+D:"")+(d?"#"+d:"")}),K=$.computed(()=>{const R=(W&&W.value||a.class||"").split(/\s+/).filter(Boolean),d={};for(const O of R)d[O]=!0;return d}),q=$.computed(()=>({...K.value,[a.activeClass||"active"]:B.value,[a.exactActiveClass||"exact-active"]:z.value})),J=$.computed(()=>Object.keys(q.value).filter(h=>q.value[h]).join(" ")),X=$.computed(()=>a.tag||"a"),et=$.computed(()=>X.value==="button"),I=$.computed(()=>z.value?a.ariaCurrentValue:null),M=$.computed(()=>!!a.disabled),T=$.computed(()=>{const h=String(a.to||"");return(U(h)||!!a.external)&&X.value==="a"}),Y=$.computed(()=>k&&k.value||a.style||""),V=h=>{if(h.defaultPrevented||h.button!==0||h.metaKey||h.altKey||h.ctrlKey||h.shiftKey)return;if(M.value){h.preventDefault();return}const R=String(a.to||"");if(nt(R)){try{h.preventDefault()}catch{}c.devWarn("Blocked unsafe javascript: URI in router-link.to");return}T.value||(h.preventDefault(),a.replace?C.replace(a.to):C.push(a.to))};return x.html`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./logger-CSALKaYm.cjs"),$=require("./namespace-helpers-Ctd_h7j2.cjs"),x=require("./template-compiler-G8h2OJbA.cjs"),ot=require("./custom-elements-runtime.store.cjs.js"),bt=require("./custom-elements-runtime.directives.cjs.js"),rt={enabled:!0,offset:0,timeoutMs:2e3},tt=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},ft=t=>{if(!t||Object.keys(t).length===0)return"";try{return"?"+new URLSearchParams(t).toString()}catch{return""}},nt=t=>t?/^\s*javascript\s*:/i.test(t):!1,U=t=>/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t)||t.startsWith("//"),dt=t=>{try{return decodeURIComponent(t)}catch{return t}};function A(t){if(!t)return"/";let r=t.replace(/\/+/g,"/");return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r}const ht=t=>{if(!t)return"";const r=A(t);return r==="/"?"":r},st=new WeakMap;function wt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function St(t){const r=t.path||"/",v=A(r),a=v==="/"?[]:v.split("/").filter(Boolean),l=[],o=[];for(let u=0;u<a.length;u++){const f=a[u];if(f==="*"){if(u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const W=`splat${l.length}`;l.push(W),o.push("__SPLAT__");continue}const y=f.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(y){const W=y[1],k=!!y[2];if(k&&u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a splat param ':${W}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};l.push(W),o.push(k?"__SPLAT__":"([^/]+)");continue}o.push(wt(f))}let b;if(o.length===0)b="^/$";else if(o[o.length-1]==="__SPLAT__"){const f=o.slice(0,-1).join("/");f?b=`^/${f}(?:/(.*))?(?:/)?$`:b="^(?:/(.*))?(?:/)?$"}else b=`^/${o.join("/")}(?:/)?$`;try{return{regex:new RegExp(b),paramNames:l}}catch(u){return c.devWarn(`Failed to compile route regex for '${t.path}': ${String(u)}`),{invalid:!0}}}const F=(t,r)=>{const v=A(r);for(const a of t){let l=st.get(a);if(l||(l=St(a),st.set(a,l)),l.invalid)continue;const{regex:o,paramNames:b}=l,u=o.exec(v);if(u){const f={};for(let y=0;y<b.length;y++){const W=u[y+1]||"";f[b[y]]=W?dt(W):""}return{route:a,params:f}}}return{route:null,params:{}}};function Z(t,r){for(const v of t)if(F([v],r).route!==null)return v;return null}function Rt(t,r){return F(t,r)}const ct=50;let G={},L={};function pt(){G={},L={}}function Et(){const t=Object.entries(G);if(t.length<=ct)return;const v=t.sort(([,a],[,l])=>a.lastAccessed-l.lastAccessed).slice(0,t.length-ct);for(const[a]of v)delete G[a]}async function yt(t){if(t.component)return t.component;if(t.load){const r=G[t.path];if(r)return r.lastAccessed=Date.now(),r.component;if(L[t.path]!==void 0)return L[t.path];const v=typeof window>"u";try{const a=t.load().then(l=>{Et();const o=l.default;return G[t.path]={component:o,lastAccessed:Date.now()},delete L[t.path],o}).catch(l=>{delete L[t.path];const o=l instanceof Error?l.message:String(l);throw v&&c.devError(`SSR component load failed for route: ${t.path}. ${o}`),new Error(`Failed to load component for route: ${t.path}. ${o}`)});return L[t.path]=a,await a}catch(a){const l=a instanceof Error?a.message:String(a);throw new Error(`Failed to load component for route: ${t.path}. ${l}`,{cause:a})}}throw new Error(`No component or loader defined for route: ${t.path}`)}let g=null;function $t(t){g=t}function it(){return g}const j=new Set;let N=null;function mt(){if(N){try{N()}catch{}N=null}if(g)try{let t=!1;N=g.subscribe(r=>{t=!0;for(const v of j)try{v(r)}catch{}});try{C.base=g.base}catch{}if(t){const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}else{const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}try{typeof window<"u"&&$.flushDOMUpdates()}catch{}}catch{N=null}}function Ct(){mt()}const C={store:{subscribe(t){if(g)return g.store.subscribe(t);try{t({path:"/",params:{},query:{}})}catch{}return()=>{}},getState(){return g?g.getCurrent():{path:"/",params:{},query:{}}},setState(t){if(g)try{g.store.setState(t)}catch{}}},subscribe(t){if(typeof t!="function")return c.devWarn("activeRouterProxy.subscribe: listener must be a function"),()=>{};if(j.add(t),g)if(!N)mt();else try{const r=g.getCurrent();r&&t(r)}catch(r){c.devWarn("activeRouterProxy subscription failed",r)}else try{t({path:"/",params:{},query:{}})}catch(r){c.devWarn("activeRouterProxy fallback state delivery failed",r)}return()=>{try{if(j.delete(t),j.size===0&&N){try{N()}catch(r){c.devWarn("activeRouterProxy inner unsubscribe failed",r)}N=null}}catch(r){c.devWarn("activeRouterProxy unsubscribe failed",r)}}},getCurrent(){return g?g.getCurrent():{path:"/",params:{},query:{}}},async push(t){return g?g.push(t):Promise.resolve()},async replace(t){return g?g.replace(t):Promise.resolve()},back(){if(g)return g.back()},matchRoute(t){return g?g.matchRoute(t):{route:null,params:{}}},resolveRouteComponent(t){return g?g.resolveRouteComponent(t):Promise.reject(new Error("No active router"))},base:"",scrollToFragment(t){return g?g.scrollToFragment(t):Promise.resolve(!1)}};function vt(t){const{routes:r,base:v="",initialUrl:a,scrollToFragment:l=!0}=t,o=ht(v),b=typeof l=="boolean"?{...rt,enabled:l}:{...rt,...l};let u,f,y,W,k,z,B;const _=new Set,K=10;let q=0;const J=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.beforeEnter)return!0;try{const n=await e.beforeEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("beforeEnter error",n);try{y.setState(i)}catch{}throw n}},X=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.onEnter)return!0;try{const n=await e.onEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("onEnter error",n);try{y.setState(i)}catch{}throw n}},et=(s,i)=>{const e=Z(r,s.path);if(!(!e||!e.afterEnter))try{e.afterEnter(s,i)}catch(n){c.devError("afterEnter error",n)}},I=new Map,M=100,T=s=>{if(I.has(s))return I.get(s);const i=F(r,s);if(I.size>=M){const e=Math.floor(M*.25),n=Array.from(I.keys());for(let p=0;p<e&&p<n.length;p++)I.delete(n[p])}return I.set(s,i),i},Y=()=>{};async function V(s,i=0){try{const e=document.getElementById(s);if(!e)return!1;if(i>0)try{const n=e.getBoundingClientRect(),p=Math.max(0,window.scrollY+n.top-i);typeof window.scrollTo=="function"&&window.scrollTo({top:p,behavior:"auto"})}catch{try{e.scrollIntoView()}catch{return!1}}else if(typeof e.scrollIntoView=="function")try{e.scrollIntoView({behavior:"auto",block:"start",inline:"nearest"})}catch{try{e.scrollIntoView()}catch{return!1}}return!0}catch{return!1}}function h(s,i=0,e=2e3){return new Promise(n=>{let p=!1,m=null;const w=Date.now(),S=P=>{p||(p=!0,m&&clearTimeout(m),n(P))},E=async()=>{if(!p)try{if(await V(s,i))return S(!0);const P=async()=>{if(p)return;if(Date.now()-w>=e)return S(!1);try{if(await V(s,i))return S(!0);requestAnimationFrame(P)}catch(gt){c.devWarn("Scroll retry attempt failed:",gt),requestAnimationFrame(P)}};requestAnimationFrame(P)}catch(P){c.devWarn("Initial scroll attempt failed:",P),S(!1)}};m=setTimeout(()=>{S(!1)},e),E().catch(P=>{c.devWarn("Scroll attempt failed:",P),S(!1)})})}let R=!1;const d=async(s,i=!1)=>{if(R){c.devWarn(`Navigation to ${s} blocked - navigation already in progress`);return}R=!0,q=0,_.clear();try{await D(s,i)}finally{R=!1,q=0,_.clear()}},O=s=>{const i=s.indexOf("#"),e=i>=0?s.slice(i+1):"",n=i>=0?s.slice(0,i):s,p=n.indexOf("?"),m=p>=0?n.slice(0,p):n,w=p>=0?tt(n.slice(p)):{},S=m.startsWith(o)?m.slice(o.length):m;return{path:A(S||"/"),query:w,fragment:e}},D=async(s,i=!1)=>{try{const e=O(s),n=T(e.path);if(!n.route)throw new Error(`No route found for ${e.path}`);const p=y.getState(),m={path:e.path,params:n.params,query:e.query,fragment:e.fragment},w=await J(m,p);if(w===!1)return;if(typeof w=="string"){q++;const E=`${m.path}->${w}`;_.add(E),await D(w,!0);return}const S=await X(m,p);if(S===!1)return;if(typeof S=="string"){q++;const E=`${m.path}->${S}`;_.add(E),await D(S,!0);return}if(typeof window<"u"&&typeof document<"u"){const E=ft(e.query),P=o+e.path+(E||"")+(e.fragment?"#"+e.fragment:"");i?window.history.replaceState({},"",P):window.history.pushState({},"",P)}if(y.setState(m),et(m,p),typeof window<"u"&&typeof document<"u")try{const E=m.fragment;b.enabled&&E&&h(String(E),b.offset,b.timeoutMs).catch(()=>{})}catch{}}catch(e){if(c.devError("Navigation error:",e),e instanceof Error&&(e.stack?.includes("runBeforeEnter")||e.stack?.includes("runOnEnter")))throw e;try{const n=y.getState();if(!F(r,n.path).route){let m=r.find(w=>w.path==="/");if(m||(m=r.find(w=>!w.path.includes(":")&&!w.path.includes("*"))),!m&&r.length>0&&(m=r[0]),m){const w=F(r,m.path);y.setState({path:m.path,params:w.params,query:{}})}else c.devError("No fallback route available for error recovery")}}catch(n){c.devWarn("State recovery failed during navigation error:",n)}}};if((s=>{if(!s||s.length===0)return c.devError("Router configuration error: No routes provided"),!1;const i=new Set;for(const e of s){if(!e.path)return c.devError("Router configuration error: Route missing path",e),!1;i.has(e.path)&&c.devWarn(`Duplicate route path detected: ${e.path}`),i.add(e.path),!e.component&&!e.load&&c.devWarn(`Route '${e.path}' has no component or load function`)}return!0})(r),typeof window>"u"||typeof a<"u"){for(const s of r)T(s.path);c.devWarn(`Pre-compiled ${r.length} routes for SSR`)}if(typeof window<"u"&&typeof document<"u"&&typeof a>"u"){u=()=>{try{const e=new URL(window.location.href),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async(e=!1)=>{const n=u();await d(n.path,e)};const i=()=>W(!0);window.addEventListener("popstate",i),k=e=>d(e,!1),z=e=>d(e,!0),B=()=>window.history.back()}else{u=()=>{try{const e=new URL(a||"/","http://localhost"),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid SSR URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async()=>{const e=u();await i(e.path)};const i=async e=>{if(q++,q>K){c.devError(`SSR redirect depth exceeded for path: ${e}`);return}try{const n=O(e),p=T(n.path);if(!p.route)throw new Error(`No route found for ${n.path}`);const m=y.getState(),w={path:n.path,params:p.params,query:n.query,fragment:n.fragment},S=Z(r,w.path);if(S?.beforeEnter){const E=await S.beforeEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}if(S?.onEnter){const E=await S.onEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}y.setState(w),S?.afterEnter&&S.afterEnter(w,m)}catch(n){throw c.devError("SSR navigation error:",n),n}};k=async e=>(q=0,_.clear(),i(e)),z=async e=>(q=0,_.clear(),i(e)),B=()=>{}}return{_cleanupScrollState:Y,store:y,push:k,replace:z,back:B,subscribe:y.subscribe,matchRoute:s=>T(s),getCurrent:()=>y.getState(),resolveRouteComponent:yt,base:o,scrollToFragment:s=>{const i=s||y.getState().fragment;return!i||typeof window>"u"||typeof document>"u"?Promise.resolve(!1):h(i,b.offset,b.timeoutMs)}}}function At(t){pt();const r=vt(t),v=it();if(v)try{v._cleanupScrollState?.()}catch{}$t(r);try{Ct();try{typeof window<"u"&&$.flushDOMUpdates()}catch{}try{typeof window<"u"&&queueMicrotask(()=>{try{$.flushDOMUpdates()}catch{}})}catch{}}catch{}return x.component("router-view",async()=>{if(!it())return x.html`<div>Router not initialized.</div>`;const a=$.ref(C.getCurrent()),l=typeof window>"u";let o;l||(x.useOnConnected(()=>{try{typeof C.subscribe=="function"&&(o=C.subscribe(u=>{try{u&&typeof u=="object"&&typeof u.path=="string"?a.value=u:(c.devWarn("router-view received invalid state",u),a.value={path:"/",params:{},query:{}})}catch(f){c.devWarn("router-view subscription update failed",f);try{a.value={path:"/",params:{},query:{}}}catch{}}}))}catch(u){c.devWarn("router-view subscribe failed",u)}}),x.useOnDisconnected(()=>{if(typeof o=="function"){try{o()}catch(u){c.devWarn("router-view unsubscribe failed",u)}o=void 0}}));const b=C.matchRoute(a.value.path);if(!b||!b.route)return x.html`<div>Not found</div>`;try{const f=await C.resolveRouteComponent(b.route);if(typeof f=="string")return{tag:f,props:{},children:[]};if(typeof f=="function"){const y=f();return(y instanceof Promise?y:Promise.resolve(y)).then(k=>typeof k=="string"?{tag:k,props:{},children:[]}:k)}return x.html`<div>Invalid route component</div>`}catch{return x.html`<div>Invalid route component</div>`}}),x.component("router-link",()=>{const a=x.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),l=typeof window>"u",o=$.ref(C.getCurrent()),b=o.value?.path||"/",u=String(a.to||""),f=l?{isExactActive:lt(b,u,C.base),isActive:ut(b,u,C.base),isExternal:U(u)||!!a.external}:null;let y;x.useStyle(()=>"a,button{display:inline-block;}");const W=$.ref(a.class||""),k=$.ref(a.style||"");if(!l){let h=null;x.useOnConnected(R=>{try{if(typeof C.subscribe=="function"){y=C.subscribe(d=>{try{d&&typeof d=="object"&&typeof d.path=="string"?o.value=d:(c.devWarn("router-link received invalid state",d),o.value={path:"/",params:{},query:{}})}catch(O){c.devWarn("router-link subscription update failed",O);try{o.value={path:"/",params:{},query:{}}}catch{}}});try{const d=C.getCurrent();d&&typeof d.path=="string"&&(o.value=d)}catch(d){c.devWarn("router-link initial state sync failed",d)}h=setInterval(()=>{try{const d=C.getCurrent();d&&typeof d.path=="string"&&JSON.stringify(o.value)!==JSON.stringify(d)&&(o.value=d)}catch{}},100)}}catch(d){c.devWarn("router-link subscribe failed",d)}try{const d=R?._host;if(d instanceof HTMLElement){const O=d.getAttribute("class"),D=d.getAttribute("style");O&&(W.value=O),D&&(k.value=D),O!==null&&d.removeAttribute("class"),D!==null&&d.removeAttribute("style");try{R?._requestRender?.();try{$.flushDOMUpdates()}catch{}}catch{}}}catch(d){c.devWarn("router-link host migration failed",d)}}),x.useOnDisconnected(()=>{if(typeof y=="function")try{y()}catch(R){c.devWarn("router-link unsubscribe failed",R)}finally{y=void 0}if(h)try{clearInterval(h)}catch(R){c.devWarn("router-link sync interval cleanup failed",R)}finally{h=null}})}const z=$.computed(()=>{if(l&&f)return f.isExactActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:lt(o.value.path,R,h)}catch(h){return c.devWarn("isExactActive computation error",h),!1}}),B=$.computed(()=>{if(l&&f)return f.isActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:a.exact?z.value:ut(o.value.path,R,h)}catch(h){return c.devWarn("isActive computation error",h),!1}}),_=$.computed(()=>{const h=String(a.to||"");if(nt(h))return null;if(U(h))return h;const[R,d]=h.split("#"),[O,D]=(R||"").split("?"),H=C.base??"";let Q=O||"/";if(H&&H!=="/"){const s=A(H),i=A(Q);i.startsWith(s)?Q=i.slice(s.length)||"/":Q=i}const at=A(Q||"/");return H+at+(D?"?"+D:"")+(d?"#"+d:"")}),K=$.computed(()=>{const R=(W&&W.value||a.class||"").split(/\s+/).filter(Boolean),d={};for(const O of R)d[O]=!0;return d}),q=$.computed(()=>({...K.value,[a.activeClass||"active"]:B.value,[a.exactActiveClass||"exact-active"]:z.value})),J=$.computed(()=>Object.keys(q.value).filter(h=>q.value[h]).join(" ")),X=$.computed(()=>a.tag||"a"),et=$.computed(()=>X.value==="button"),I=$.computed(()=>z.value?a.ariaCurrentValue:null),M=$.computed(()=>!!a.disabled),T=$.computed(()=>{const h=String(a.to||"");return(U(h)||!!a.external)&&X.value==="a"}),Y=$.computed(()=>k&&k.value||a.style||""),V=h=>{if(h.defaultPrevented||h.button!==0||h.metaKey||h.altKey||h.ctrlKey||h.shiftKey)return;if(M.value){h.preventDefault();return}const R=String(a.to||"");if(nt(R)){try{h.preventDefault()}catch{}c.devWarn("Blocked unsafe javascript: URI in router-link.to");return}T.value||(h.preventDefault(),a.replace?C.replace(a.to):C.push(a.to))};return x.html`
|
|
2
2
|
${bt.match().when(et.value,x.html`
|
|
3
3
|
<button
|
|
4
4
|
part="button"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as y, d as I } from "./logger-BvkEbVM4.js";
|
|
2
2
|
import { f as rt, r as tt, c as T } from "./namespace-helpers-DhLBqt-7.js";
|
|
3
|
-
import { c as st, h as F, l as ct, m as it, b as bt, o as wt } from "./template-compiler-
|
|
3
|
+
import { c as st, h as F, l as ct, m as it, b as bt, o as wt } from "./template-compiler-CVBKYu3j.js";
|
|
4
4
|
import { createStore as lt } from "./custom-elements-runtime.store.es.js";
|
|
5
5
|
import { match as St } from "./custom-elements-runtime.directives.es.js";
|
|
6
6
|
const ut = {
|
package/dist/directives.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { VNode } from './runtime/types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Reset all scope state at the start of each component render pass.
|
|
4
|
+
* Called automatically by the component renderer — not needed in user code.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function resetWhenCounter(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Claim the next directive call index within the current scope.
|
|
10
|
+
* Used by directive-enhancements.ts for non-when() directives (switchOnLength,
|
|
11
|
+
* switchOnPromise, etc.) that need a stable unique number per call site.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function nextDirectiveIndex(): number;
|
|
15
|
+
export declare function when(cond: boolean, children: VNode | VNode[], key?: string): VNode;
|
|
16
|
+
export declare function when(cond: boolean, factory: () => VNode | VNode[], key?: string): VNode;
|
|
4
17
|
export declare function each<T extends string | number | boolean | {
|
|
5
18
|
id?: string | number;
|
|
6
19
|
key?: string;
|