@jasonshimmy/custom-elements-runtime 3.7.2 → 3.7.4
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.es.js +3 -3
- package/dist/custom-elements-runtime.jit-css.cjs.js +1 -1
- package/dist/custom-elements-runtime.jit-css.es.js +2 -2
- package/dist/custom-elements-runtime.router.cjs.js +1 -1
- package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.router.es.js +3 -3
- package/dist/custom-elements-runtime.router.es.js.map +1 -1
- package/dist/custom-elements-runtime.ssr-middleware.cjs.js +1 -1
- package/dist/custom-elements-runtime.ssr-middleware.es.js +1 -1
- package/dist/custom-elements-runtime.ssr.cjs.js +1 -1
- package/dist/custom-elements-runtime.ssr.es.js +2 -2
- package/dist/custom-elements-runtime.vite-plugin.cjs.js +1 -1
- package/dist/custom-elements-runtime.vite-plugin.es.js +1 -1
- package/dist/helpers-BQ37xfhc.cjs +5 -0
- package/dist/helpers-BQ37xfhc.cjs.map +1 -0
- package/dist/{helpers-BiGdX-3A.js → helpers-llht6g11.js} +5 -2
- package/dist/helpers-llht6g11.js.map +1 -0
- package/dist/{hooks-yP009oF9.js → hooks-BZwRvrjJ.js} +146 -131
- package/dist/hooks-BZwRvrjJ.js.map +1 -0
- package/dist/hooks-DTyLoDNI.cjs +2 -0
- package/dist/hooks-DTyLoDNI.cjs.map +1 -0
- package/dist/runtime/hooks.d.ts +0 -13
- package/dist/runtime/reactive.d.ts +1 -0
- package/dist/{ssr-CUT0FqUz.cjs → ssr-DkMl-vjb.cjs} +2 -2
- package/dist/{ssr-CUT0FqUz.cjs.map → ssr-DkMl-vjb.cjs.map} +1 -1
- package/dist/{ssr-COmrqY64.js → ssr-WD-KTNsB.js} +3 -3
- package/dist/{ssr-COmrqY64.js.map → ssr-WD-KTNsB.js.map} +1 -1
- package/dist/{tag-utils-CMy95A4Z.cjs → tag-utils-BiaxgxbY.cjs} +2 -2
- package/dist/{tag-utils-CMy95A4Z.cjs.map → tag-utils-BiaxgxbY.cjs.map} +1 -1
- package/dist/{tag-utils-DVutXfzj.js → tag-utils-DMHsC8t3.js} +2 -2
- package/dist/{tag-utils-DVutXfzj.js.map → tag-utils-DMHsC8t3.js.map} +1 -1
- package/dist/template-compiler-D3r3ajIB.cjs +19 -0
- package/dist/template-compiler-D3r3ajIB.cjs.map +1 -0
- package/dist/{template-compiler-BkR0G45f.js → template-compiler-D7BToKVe.js} +262 -252
- package/dist/template-compiler-D7BToKVe.js.map +1 -0
- package/package.json +1 -1
- package/dist/helpers-BiGdX-3A.js.map +0 -1
- package/dist/helpers-hGU9czPG.cjs +0 -5
- package/dist/helpers-hGU9czPG.cjs.map +0 -1
- package/dist/hooks-CACte2Ir.cjs +0 -2
- package/dist/hooks-CACte2Ir.cjs.map +0 -1
- package/dist/hooks-yP009oF9.js.map +0 -1
- package/dist/template-compiler-BkR0G45f.js.map +0 -1
- package/dist/template-compiler-EdgxOr6e.cjs +0 -19
- package/dist/template-compiler-EdgxOr6e.cjs.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { r as e, t } from "./logger-DIJ0UH3R.js";
|
|
2
|
-
import { _ as n, f as r,
|
|
3
|
-
import { d as
|
|
2
|
+
import { _ as n, f as r, h as i, p as a, v as o, w as s } from "./helpers-llht6g11.js";
|
|
3
|
+
import { d as c, f as l } from "./css-utils-Bn-dO44e.js";
|
|
4
4
|
//#region src/lib/runtime/ssr-context.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
if (
|
|
8
|
-
|
|
5
|
+
var u = null;
|
|
6
|
+
function d() {
|
|
7
|
+
if (u !== null) throw Error("[CER] Concurrent SSR render detected: beginSSRGlobalStyleCollection() called while a collection is already active. For concurrent request handling, use worker threads or multiple Node.js processes.");
|
|
8
|
+
u = [];
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
let e =
|
|
12
|
-
return
|
|
10
|
+
function f() {
|
|
11
|
+
let e = u ?? [];
|
|
12
|
+
return u = null, e;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
return
|
|
14
|
+
function p(e) {
|
|
15
|
+
return u === null ? !1 : (e && !u.includes(e) && u.push(e), !0);
|
|
16
16
|
}
|
|
17
|
-
var
|
|
18
|
-
function
|
|
17
|
+
var m = 0;
|
|
18
|
+
function h(t, n, i = "unknown", a) {
|
|
19
19
|
let o = {};
|
|
20
20
|
for (let [e, t] of Object.entries(n ?? {})) o[r(e)] = t;
|
|
21
21
|
let s = {
|
|
@@ -33,7 +33,7 @@ function p(t, n, i = "unknown", a) {
|
|
|
33
33
|
parentElement: null
|
|
34
34
|
}, c = {
|
|
35
35
|
...o,
|
|
36
|
-
_componentId: `cer-ssr-${Object.keys(o).join("-") || "root"}-${++
|
|
36
|
+
_componentId: `cer-ssr-${Object.keys(o).join("-") || "root"}-${++m}`,
|
|
37
37
|
requestRender: () => void 0,
|
|
38
38
|
_requestRender: () => void 0,
|
|
39
39
|
emit: () => !0,
|
|
@@ -49,7 +49,7 @@ function p(t, n, i = "unknown", a) {
|
|
|
49
49
|
writable: !1,
|
|
50
50
|
enumerable: !1,
|
|
51
51
|
configurable: !0
|
|
52
|
-
}),
|
|
52
|
+
}), y(c);
|
|
53
53
|
let l = null, u;
|
|
54
54
|
try {
|
|
55
55
|
let e = t.render(c);
|
|
@@ -57,7 +57,7 @@ function p(t, n, i = "unknown", a) {
|
|
|
57
57
|
} catch (t) {
|
|
58
58
|
e(`[SSR] Component "${i}" threw during SSR render. The shadow DOM will be empty. Error:`, t);
|
|
59
59
|
} finally {
|
|
60
|
-
|
|
60
|
+
b();
|
|
61
61
|
}
|
|
62
62
|
let d = String(c._computedStyle ?? "");
|
|
63
63
|
return {
|
|
@@ -68,28 +68,28 @@ function p(t, n, i = "unknown", a) {
|
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
70
|
//#region src/lib/runtime/hooks.ts
|
|
71
|
-
function
|
|
72
|
-
return
|
|
71
|
+
function g() {
|
|
72
|
+
return s();
|
|
73
73
|
}
|
|
74
|
-
var
|
|
75
|
-
function
|
|
76
|
-
|
|
74
|
+
var _ = null, v = Symbol("cer:provides");
|
|
75
|
+
function y(e) {
|
|
76
|
+
_ = e;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
78
|
+
function b() {
|
|
79
|
+
_ = null;
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
81
|
+
function x() {
|
|
82
|
+
return _;
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
if (!
|
|
86
|
-
if (
|
|
87
|
-
let e =
|
|
84
|
+
function S() {
|
|
85
|
+
if (!_) throw Error("useEmit must be called during component render");
|
|
86
|
+
if (s()) return () => !1;
|
|
87
|
+
let e = _.emit;
|
|
88
88
|
if (typeof e != "function") throw Error("useEmit requires an emit function on the component context");
|
|
89
89
|
let t = e;
|
|
90
90
|
return (e, n, r) => t(e, n, r);
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function C(e) {
|
|
93
93
|
e._hookCallbacks || Object.defineProperty(e, "_hookCallbacks", {
|
|
94
94
|
value: {},
|
|
95
95
|
writable: !0,
|
|
@@ -97,32 +97,32 @@ function x(e) {
|
|
|
97
97
|
configurable: !0
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
if (!
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
let t =
|
|
100
|
+
function w(e) {
|
|
101
|
+
if (!_) throw Error("useOnConnected must be called during component render");
|
|
102
|
+
if (s()) return;
|
|
103
|
+
C(_);
|
|
104
|
+
let t = _._hookCallbacks;
|
|
105
105
|
t.onConnected ||= [], t.onConnected.push(e);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
if (!
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
let t =
|
|
107
|
+
function T(e) {
|
|
108
|
+
if (!_) throw Error("useOnDisconnected must be called during component render");
|
|
109
|
+
if (s()) return;
|
|
110
|
+
C(_);
|
|
111
|
+
let t = _._hookCallbacks;
|
|
112
112
|
t.onDisconnected ||= [], t.onDisconnected.push(e);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
if (!
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
let t =
|
|
114
|
+
function E(e) {
|
|
115
|
+
if (!_) throw Error("useOnAttributeChanged must be called during component render");
|
|
116
|
+
if (s()) return;
|
|
117
|
+
C(_);
|
|
118
|
+
let t = _._hookCallbacks;
|
|
119
119
|
t.onAttributeChanged ||= [], t.onAttributeChanged.push(e);
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
if (!
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
let n =
|
|
121
|
+
function D(e) {
|
|
122
|
+
if (!_) throw Error("useOnError must be called during component render");
|
|
123
|
+
if (s()) return;
|
|
124
|
+
C(_);
|
|
125
|
+
let n = _._hookCallbacks;
|
|
126
126
|
n.onError ||= [], n.onError.push((n) => {
|
|
127
127
|
try {
|
|
128
128
|
n instanceof Error ? e(n) : e(Error(String(n)));
|
|
@@ -131,39 +131,49 @@ function T(e) {
|
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
var O = Symbol.for("@cer/usePropsState");
|
|
135
|
+
function k(e) {
|
|
136
|
+
let t = e[O];
|
|
137
|
+
return t || (t = /* @__PURE__ */ new Map(), Object.defineProperty(e, O, {
|
|
138
|
+
value: t,
|
|
139
|
+
writable: !1,
|
|
140
|
+
enumerable: !1,
|
|
141
|
+
configurable: !1
|
|
142
|
+
})), t;
|
|
143
|
+
}
|
|
144
|
+
function A(e) {
|
|
145
|
+
if (!_) throw Error("useProps must be called during component render");
|
|
146
|
+
C(_);
|
|
147
|
+
let t = _._hookCallbacks;
|
|
138
148
|
t.props = {
|
|
139
149
|
...t.props || {},
|
|
140
150
|
...e
|
|
141
151
|
};
|
|
142
|
-
let r =
|
|
152
|
+
let r = _;
|
|
143
153
|
try {
|
|
144
154
|
let t = Object.keys(e || {});
|
|
145
|
-
for (let
|
|
146
|
-
if (typeof
|
|
147
|
-
let t = Object.getOwnPropertyDescriptor(r,
|
|
155
|
+
for (let i of t) {
|
|
156
|
+
if (typeof i != "string" || i.startsWith("_")) continue;
|
|
157
|
+
let t = Object.getOwnPropertyDescriptor(r, i);
|
|
148
158
|
if (!(t && !t.configurable)) try {
|
|
149
|
-
let t = Object.prototype.hasOwnProperty.call(r,
|
|
150
|
-
Object.defineProperty(r,
|
|
159
|
+
let t = Object.prototype.hasOwnProperty.call(r, i) ? r[i] : void 0;
|
|
160
|
+
Object.defineProperty(r, i, {
|
|
151
161
|
configurable: !0,
|
|
152
162
|
enumerable: !0,
|
|
153
163
|
get() {
|
|
154
164
|
try {
|
|
155
165
|
let t = r && r._host;
|
|
156
166
|
if (t) {
|
|
157
|
-
let r = i
|
|
167
|
+
let r = a(i), o = t.getAttribute(r);
|
|
158
168
|
if (o !== null) {
|
|
159
|
-
let t = typeof e[
|
|
169
|
+
let t = typeof e[i];
|
|
160
170
|
return t === "boolean" ? o === "" || o === "true" : t === "number" ? Number(o) : o;
|
|
161
171
|
}
|
|
162
|
-
if (t[
|
|
163
|
-
let r = t[
|
|
172
|
+
if (t[i] !== void 0) {
|
|
173
|
+
let r = t[i];
|
|
164
174
|
if (n(r) || r && typeof r == "object" && "value" in r && !(typeof Node < "u" && r instanceof Node)) return r.value;
|
|
165
|
-
let
|
|
166
|
-
if (!(
|
|
175
|
+
let a = typeof e[i];
|
|
176
|
+
if (!(a === "string" && r && typeof r == "object")) return a === "boolean" && typeof r == "string" ? r === "" || r === "true" : r;
|
|
167
177
|
}
|
|
168
178
|
}
|
|
169
179
|
} catch {}
|
|
@@ -177,25 +187,30 @@ function E(e) {
|
|
|
177
187
|
}
|
|
178
188
|
} catch {}
|
|
179
189
|
return new Proxy({}, {
|
|
180
|
-
get(t,
|
|
181
|
-
if (typeof
|
|
182
|
-
let
|
|
190
|
+
get(t, a) {
|
|
191
|
+
if (typeof a != "string") return;
|
|
192
|
+
let s = e[a], c = k(r), l = c.get(a), u;
|
|
183
193
|
try {
|
|
184
194
|
let e = r && r._host;
|
|
185
195
|
if (e) {
|
|
186
196
|
if (typeof HTMLElement < "u" && e instanceof HTMLElement || typeof e.getAttribute == "function" && typeof e.hasAttribute == "function") {
|
|
187
|
-
let t =
|
|
188
|
-
|
|
197
|
+
let t = a.replace(/([A-Z])/g, "-$1").toLowerCase(), n = e.getAttribute(t);
|
|
198
|
+
n !== null && (u = typeof s == "boolean" ? n === "" || n === "true" : typeof s == "number" ? Number(n) : n);
|
|
189
199
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
200
|
+
if (u === void 0) {
|
|
201
|
+
let t = e[a];
|
|
202
|
+
if (t !== void 0 && t !== "") {
|
|
203
|
+
let e = t && typeof t == "object" && "value" in t && !(typeof Node < "u" && t instanceof Node);
|
|
204
|
+
typeof s == "string" && t && typeof t == "object" && !e && !n(t) || (u = typeof s == "boolean" && s === !1 && t === "" ? s : n(t) || e ? t.value : typeof s == "boolean" && typeof t == "string" ? t === "" || t === "true" : typeof s == "number" && typeof t == "string" && !Number.isNaN(Number(t)) ? Number(t) : t);
|
|
205
|
+
}
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
} catch {}
|
|
197
|
-
|
|
198
|
-
|
|
209
|
+
if (u === void 0) {
|
|
210
|
+
let e = r[a];
|
|
211
|
+
u = typeof s == "boolean" && e === "" ? s === !1 ? s : !0 : n(e) || e && typeof e == "object" && "value" in e && !(typeof Node < "u" && e instanceof Node) ? e.value : e != null && e !== "" ? typeof s == "boolean" && typeof e == "string" ? e === "true" : typeof s == "number" && typeof e == "string" && !Number.isNaN(Number(e)) ? Number(e) : e : s;
|
|
212
|
+
}
|
|
213
|
+
return l ? Object.is(l.peek(), u) || (o.isRenderingComponent() ? l.initSilent(u) : l.value = u) : (l = new i(u), c.set(a, l)), l.value;
|
|
199
214
|
},
|
|
200
215
|
has(t, n) {
|
|
201
216
|
return typeof n == "string" && (n in r || n in e);
|
|
@@ -211,20 +226,20 @@ function E(e) {
|
|
|
211
226
|
}
|
|
212
227
|
});
|
|
213
228
|
}
|
|
214
|
-
function
|
|
215
|
-
if (!
|
|
216
|
-
if (!
|
|
217
|
-
|
|
229
|
+
function j(t) {
|
|
230
|
+
if (!_) throw Error("useStyle must be called during component render");
|
|
231
|
+
if (!s()) {
|
|
232
|
+
C(_);
|
|
218
233
|
try {
|
|
219
234
|
let e = t();
|
|
220
|
-
Object.defineProperty(
|
|
235
|
+
Object.defineProperty(_, "_computedStyle", {
|
|
221
236
|
value: e,
|
|
222
237
|
writable: !0,
|
|
223
238
|
enumerable: !1,
|
|
224
239
|
configurable: !0
|
|
225
240
|
});
|
|
226
241
|
} catch (t) {
|
|
227
|
-
e("Error in useStyle callback:", t), Object.defineProperty(
|
|
242
|
+
e("Error in useStyle callback:", t), Object.defineProperty(_, "_computedStyle", {
|
|
228
243
|
value: "",
|
|
229
244
|
writable: !0,
|
|
230
245
|
enumerable: !1,
|
|
@@ -233,28 +248,28 @@ function D(t) {
|
|
|
233
248
|
}
|
|
234
249
|
}
|
|
235
250
|
}
|
|
236
|
-
var
|
|
237
|
-
function
|
|
251
|
+
var M = /* @__PURE__ */ new Map();
|
|
252
|
+
function N(t) {
|
|
238
253
|
let n;
|
|
239
254
|
try {
|
|
240
255
|
n = t();
|
|
241
256
|
} catch {
|
|
242
257
|
return;
|
|
243
258
|
}
|
|
244
|
-
if (
|
|
259
|
+
if (p(n) || typeof document > "u" || typeof CSSStyleSheet > "u") return;
|
|
245
260
|
e("[useGlobalStyle] Injecting global styles from a component. This escapes Shadow DOM encapsulation — use sparingly.");
|
|
246
|
-
let r =
|
|
247
|
-
if (!(!r ||
|
|
261
|
+
let r = c(l(n));
|
|
262
|
+
if (!(!r || M.has(r))) try {
|
|
248
263
|
let e = new CSSStyleSheet();
|
|
249
|
-
e.replaceSync(r), document.adoptedStyleSheets = [...document.adoptedStyleSheets, e],
|
|
264
|
+
e.replaceSync(r), document.adoptedStyleSheets = [...document.adoptedStyleSheets, e], M.set(r, e);
|
|
250
265
|
} catch {
|
|
251
266
|
let e = document.createElement("style");
|
|
252
267
|
e.textContent = r, (document.head ?? document.documentElement).appendChild(e);
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
|
-
function
|
|
256
|
-
if (!
|
|
257
|
-
if (
|
|
270
|
+
function P(e) {
|
|
271
|
+
if (!_) throw Error("useDesignTokens must be called during component render");
|
|
272
|
+
if (s()) return;
|
|
258
273
|
let t = [], n = {
|
|
259
274
|
primary: "--cer-color-primary-500",
|
|
260
275
|
secondary: "--cer-color-secondary-500",
|
|
@@ -270,30 +285,30 @@ function A(e) {
|
|
|
270
285
|
};
|
|
271
286
|
for (let [i, a] of Object.entries(e)) a !== void 0 && (i in n ? t.push(`${n[i]}:${a}`) : i in r ? t.push(`${r[i]}:${a}`) : i.startsWith("--") && t.push(`${i}:${a}`));
|
|
272
287
|
if (t.length === 0) return;
|
|
273
|
-
let i = `:host{${t.join(";")}}`,
|
|
274
|
-
Object.defineProperty(
|
|
275
|
-
value:
|
|
288
|
+
let i = `:host{${t.join(";")}}`, a = _._computedStyle ?? "", o = a ? `${a}\n${i}` : i;
|
|
289
|
+
Object.defineProperty(_, "_computedStyle", {
|
|
290
|
+
value: o,
|
|
276
291
|
writable: !0,
|
|
277
292
|
enumerable: !1,
|
|
278
293
|
configurable: !0
|
|
279
294
|
});
|
|
280
295
|
}
|
|
281
|
-
function
|
|
282
|
-
if (!
|
|
283
|
-
if (
|
|
284
|
-
let n =
|
|
285
|
-
n[
|
|
296
|
+
function F(e, t) {
|
|
297
|
+
if (!_) throw Error("provide must be called during component render");
|
|
298
|
+
if (s()) return;
|
|
299
|
+
let n = _;
|
|
300
|
+
n[v] || Object.defineProperty(n, v, {
|
|
286
301
|
value: /* @__PURE__ */ new Map(),
|
|
287
302
|
writable: !1,
|
|
288
303
|
enumerable: !1,
|
|
289
304
|
configurable: !0
|
|
290
|
-
}), n[
|
|
305
|
+
}), n[v].set(e, t);
|
|
291
306
|
}
|
|
292
|
-
function
|
|
293
|
-
if (!
|
|
294
|
-
if (
|
|
307
|
+
function I(e, t) {
|
|
308
|
+
if (!_) throw Error("inject must be called during component render");
|
|
309
|
+
if (s()) return t;
|
|
295
310
|
try {
|
|
296
|
-
let t =
|
|
311
|
+
let t = _._host;
|
|
297
312
|
if (t) {
|
|
298
313
|
let n = t.parentNode;
|
|
299
314
|
n ||= t.getRootNode();
|
|
@@ -301,7 +316,7 @@ function M(e, t) {
|
|
|
301
316
|
for (; n && r < 50;) if (r++, typeof ShadowRoot < "u" && n instanceof ShadowRoot) {
|
|
302
317
|
let t = n.host, r = t.context;
|
|
303
318
|
if (r) {
|
|
304
|
-
let t = r[
|
|
319
|
+
let t = r[v];
|
|
305
320
|
if (t?.has(e)) return t.get(e);
|
|
306
321
|
}
|
|
307
322
|
if (n = t.parentNode ?? t.getRootNode(), n === document || n === t) break;
|
|
@@ -309,7 +324,7 @@ function M(e, t) {
|
|
|
309
324
|
if (typeof Element < "u" && n instanceof Element) {
|
|
310
325
|
let t = n.context;
|
|
311
326
|
if (t) {
|
|
312
|
-
let n = t[
|
|
327
|
+
let n = t[v];
|
|
313
328
|
if (n?.has(e)) return n.get(e);
|
|
314
329
|
}
|
|
315
330
|
}
|
|
@@ -320,41 +335,41 @@ function M(e, t) {
|
|
|
320
335
|
} catch {}
|
|
321
336
|
return t;
|
|
322
337
|
}
|
|
323
|
-
function
|
|
338
|
+
function L(e) {
|
|
324
339
|
return (t) => {
|
|
325
|
-
let n = t ??
|
|
340
|
+
let n = t ?? _;
|
|
326
341
|
if (!n) throw Error("createComposable: no component context available. Pass a context explicitly or call inside a render function.");
|
|
327
|
-
let r =
|
|
328
|
-
|
|
342
|
+
let r = _;
|
|
343
|
+
y(n);
|
|
329
344
|
try {
|
|
330
345
|
return e();
|
|
331
346
|
} finally {
|
|
332
|
-
r ?
|
|
347
|
+
r ? y(r) : b();
|
|
333
348
|
}
|
|
334
349
|
};
|
|
335
350
|
}
|
|
336
|
-
function
|
|
337
|
-
if (!
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
let t =
|
|
351
|
+
function R(e) {
|
|
352
|
+
if (!_) throw Error("useExpose must be called during component render");
|
|
353
|
+
if (s()) return;
|
|
354
|
+
C(_);
|
|
355
|
+
let t = _._hookCallbacks;
|
|
341
356
|
t.expose = {
|
|
342
357
|
...t.expose ?? {},
|
|
343
358
|
...e
|
|
344
359
|
};
|
|
345
|
-
let n =
|
|
360
|
+
let n = _._host;
|
|
346
361
|
if (n) for (let [t, r] of Object.entries(e)) try {
|
|
347
362
|
n[t] = r;
|
|
348
363
|
} catch {}
|
|
349
364
|
}
|
|
350
|
-
function
|
|
351
|
-
if (!
|
|
352
|
-
if (
|
|
365
|
+
function z() {
|
|
366
|
+
if (!_) throw Error("useSlots must be called during component render");
|
|
367
|
+
if (s()) return {
|
|
353
368
|
has: () => !1,
|
|
354
369
|
getNodes: () => [],
|
|
355
370
|
names: () => []
|
|
356
371
|
};
|
|
357
|
-
let e =
|
|
372
|
+
let e = _._host, t = () => {
|
|
358
373
|
let t = /* @__PURE__ */ new Map();
|
|
359
374
|
if (!e) return t;
|
|
360
375
|
for (let n of e.children) {
|
|
@@ -379,12 +394,12 @@ function F() {
|
|
|
379
394
|
}
|
|
380
395
|
};
|
|
381
396
|
}
|
|
382
|
-
function
|
|
383
|
-
if (!
|
|
384
|
-
let t = e.length === 2 ? e[0] : "modelValue", n = e.length === 2 ? e[1] : e.length === 1 ? e[0] : void 0, r =
|
|
385
|
-
let e =
|
|
397
|
+
function B(...e) {
|
|
398
|
+
if (!_) throw Error("defineModel must be called during component render");
|
|
399
|
+
let t = e.length === 2 ? e[0] : "modelValue", n = e.length === 2 ? e[1] : e.length === 1 ? e[0] : void 0, r = A({ [t]: n }), i = s() ? null : (() => {
|
|
400
|
+
let e = _.emit;
|
|
386
401
|
return typeof e == "function" ? e : null;
|
|
387
|
-
})(),
|
|
402
|
+
})(), a = {
|
|
388
403
|
get value() {
|
|
389
404
|
return r[t];
|
|
390
405
|
},
|
|
@@ -393,15 +408,15 @@ function I(...e) {
|
|
|
393
408
|
}
|
|
394
409
|
};
|
|
395
410
|
try {
|
|
396
|
-
Object.defineProperty(
|
|
411
|
+
Object.defineProperty(a, Symbol.for("@cer/ReactiveState"), {
|
|
397
412
|
value: !0,
|
|
398
413
|
enumerable: !1,
|
|
399
414
|
configurable: !1
|
|
400
415
|
});
|
|
401
416
|
} catch {}
|
|
402
|
-
return
|
|
417
|
+
return a;
|
|
403
418
|
}
|
|
404
419
|
//#endregion
|
|
405
|
-
export {
|
|
420
|
+
export { h as S, A as _, I as a, d as b, y as c, R as d, N as f, D as g, T as h, x as i, P as l, w as m, L as n, g as o, E as p, B as r, F as s, b as t, S as u, z as v, f as x, j as y };
|
|
406
421
|
|
|
407
|
-
//# sourceMappingURL=hooks-
|
|
422
|
+
//# sourceMappingURL=hooks-BZwRvrjJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-BZwRvrjJ.js","names":[],"sources":["../src/lib/runtime/ssr-context.ts","../src/lib/runtime/hooks.ts"],"sourcesContent":["/**\n * SSR execution context for running component render functions server-side.\n *\n * When generating Declarative Shadow DOM (DSD) output, the SSR renderer must\n * call each custom element's render function to obtain its shadow DOM VNode\n * tree and capture any useStyle() / useGlobalStyle() output. This module\n * provides the minimal execution environment that makes that safe.\n *\n * Guarantees:\n * - useStyle() callbacks are executed and their output is captured.\n * - useGlobalStyle() callbacks are captured (not injected into document).\n * - Lifecycle hooks (useOnConnected, watch, …) register harmlessly to arrays\n * that are never invoked.\n * - The reactive system is never permanently mutated — component registration\n * is cleaned up by the render wrapper in factory.ts after each call.\n */\n\nimport type { ComponentConfig, ComponentContext, VNode } from './types';\nimport { toCamel } from './helpers';\nimport {\n setCurrentComponentContext,\n clearCurrentComponentContext,\n} from './hooks';\nimport { devWarn } from './logger';\n\n// ---------------------------------------------------------------------------\n// Global-style SSR collector\n// ---------------------------------------------------------------------------\n\n/**\n * When set, useGlobalStyle() factories write here instead of touching\n * document.adoptedStyleSheets (which doesn't exist in SSR environments).\n */\nlet _ssrGlobalStyleCollector: string[] | null = null;\n\n/** Start collecting useGlobalStyle() output from the current render pass. */\nexport function beginSSRGlobalStyleCollection(): void {\n if (_ssrGlobalStyleCollector !== null) {\n throw new Error(\n '[CER] Concurrent SSR render detected: beginSSRGlobalStyleCollection() called ' +\n 'while a collection is already active. For concurrent request handling, use ' +\n 'worker threads or multiple Node.js processes.',\n );\n }\n _ssrGlobalStyleCollector = [];\n}\n\n/** Stop collecting and return everything gathered so far. */\nexport function endSSRGlobalStyleCollection(): string[] {\n const collected = _ssrGlobalStyleCollector ?? [];\n _ssrGlobalStyleCollector = null;\n return collected;\n}\n\n/**\n * Called by useGlobalStyle() when an SSR collection pass is active.\n * Returns true if the CSS was captured (caller should skip DOM injection).\n */\nexport function captureGlobalStyleForSSR(css: string): boolean {\n if (_ssrGlobalStyleCollector !== null) {\n if (css && !_ssrGlobalStyleCollector.includes(css)) {\n _ssrGlobalStyleCollector.push(css);\n }\n return true;\n }\n return false;\n}\n\n// ---------------------------------------------------------------------------\n// SSR render pass\n// ---------------------------------------------------------------------------\n\nexport interface SSRRenderResult {\n /** VNode tree from the component's render function (shadow DOM content). */\n shadowVNode: VNode | VNode[] | null;\n /** CSS string captured from useStyle() calls during this render. */\n useStyleCSS: string;\n /** Present when the component's render function returned a Promise. */\n asyncPromise?: Promise<VNode | VNode[]>;\n}\n\n/**\n * Run a component's render function in a minimal SSR context to capture its\n * shadow DOM VNode tree and any useStyle() output.\n *\n * The component's render wrapper in factory.ts handles:\n * - setCurrentComponentContext / clearCurrentComponentContext\n * - _hookCallbacks reset\n * - _computedStyle reset\n * - reactiveSystem registration / cleanup\n *\n * We only need to build a context object that satisfies the hooks' expectations.\n */\n// Monotonic counter ensures each SSR render context gets a unique component ID,\n// preventing the reactive system's stateStorage from returning stale cached\n// ref/computed values from a previous request.\nlet _ssrRenderCounter = 0;\n\nexport function runComponentSSRRender(\n config: ComponentConfig<object, object, object, object>,\n attrs: Record<string, string | number | boolean | null | undefined>,\n tag = 'unknown',\n ssrRouter?: unknown,\n): SSRRenderResult {\n // Build camelCase prop map from serialised attribute names.\n const propsFromAttrs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(attrs ?? {})) {\n propsFromAttrs[toCamel(k)] = v;\n }\n\n // Fake host element: satisfies useProps()'s attribute reads without a real DOM node.\n const fakeHost = {\n getAttribute(name: string): string | null {\n const camel = toCamel(name);\n if (\n propsFromAttrs[camel] !== undefined &&\n propsFromAttrs[camel] !== null\n ) {\n return String(propsFromAttrs[camel]);\n }\n const raw = (attrs ?? {})[name];\n return raw !== undefined && raw !== null ? String(raw) : null;\n },\n hasAttribute(name: string): boolean {\n return this.getAttribute(name) !== null;\n },\n // shadowRoot must be null so useJITCSS() doesn't try to registerJITCSSComponent\n shadowRoot: null as null,\n tagName: '',\n parentElement: null as null,\n };\n\n // Minimal context object — the factory render wrapper will add _hookCallbacks\n // and _computedStyle via Object.defineProperty before calling renderFn().\n const ssrContext: Record<string, unknown> = {\n ...propsFromAttrs,\n // Unique ID per SSR render prevents the reactive system's stateStorage from\n // returning cached ref/computed values from a previous request. Using a\n // monotonic counter is cheaper than crypto.randomUUID() and avoids the\n // Node.js version compatibility concern noted in the original comment.\n _componentId: `cer-ssr-${Object.keys(propsFromAttrs).join('-') || 'root'}-${++_ssrRenderCounter}`,\n requestRender: () => undefined,\n _requestRender: () => undefined,\n emit: () => true,\n refs: {},\n };\n\n // Set _host as non-enumerable to avoid triggering the reactive proxy trap.\n Object.defineProperty(ssrContext, '_host', {\n value: fakeHost,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n\n // Thread the per-request router instance so router-view (and any component\n // that calls getCurrentComponentContext()._router) reads from the correct\n // router rather than the module-level activeRouterProxy singleton.\n // Non-enumerable keeps it out of prop serialisation / Object.keys iteration.\n if (ssrRouter !== undefined) {\n Object.defineProperty(ssrContext, '_router', {\n value: ssrRouter,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n }\n\n // Pre-set the component context so hooks (useStyle, useProps, etc.) work even\n // when config.render is a raw function rather than the factory.ts wrapper.\n // If config.render IS the factory wrapper, it will call setCurrentComponentContext\n // again with the same object — that is harmless.\n setCurrentComponentContext(ssrContext);\n\n let shadowVNode: VNode | VNode[] | null = null;\n let asyncPromise: Promise<VNode | VNode[]> | undefined;\n try {\n const result = config.render(\n ssrContext as ComponentContext<object, object, object, object>,\n );\n // Async render functions cannot be awaited in the synchronous SSR pass.\n // The DSD renderer will emit a streaming placeholder if active; otherwise\n // the shadow DOM will be empty. The caller emits the appropriate warning.\n if (result instanceof Promise) {\n asyncPromise = result;\n } else {\n shadowVNode = result as VNode | VNode[];\n }\n } catch (err) {\n // Best-effort — a render error during SSR should not crash the server.\n // The component will still get a DSD wrapper, just without shadow content.\n devWarn(\n `[SSR] Component \"${tag}\" threw during SSR render. ` +\n `The shadow DOM will be empty. Error:`,\n err,\n );\n } finally {\n // Clear context. The factory wrapper clears it too, but calling clearCurrentComponentContext()\n // twice (null → null) is harmless and ensures clean state if config.render was a raw function.\n clearCurrentComponentContext();\n }\n\n const useStyleCSS = String(\n (ssrContext as { _computedStyle?: string })._computedStyle ?? '',\n );\n\n return { shadowVNode, useStyleCSS, asyncPromise };\n}\n","/**\n * Context-based hooks for functional components\n * Provides React-like hooks with perfect TypeScript inference\n */\n\nimport { isReactiveState, ReactiveState, reactiveSystem } from './reactive';\nimport { toKebab } from './helpers';\nimport { devWarn, devError } from './logger';\nimport { isDiscoveryRender as _isDiscoveryRenderFn } from './discovery-state';\nimport { sanitizeCSS, minifyCSS } from './css-utils';\nimport type { JITCSSOptions } from './style';\nimport { captureGlobalStyleForSSR } from './ssr-context';\n\n// Re-export JITCSSOptions as a type-only re-export so consumers can still\n// import it from './runtime/hooks' without creating a runtime dependency on style.ts.\nexport type { JITCSSOptions };\n\n// Re-export discovery helpers so consumers continue to use the same import path.\nexport { beginDiscoveryRender, endDiscoveryRender } from './discovery-state';\n\n/**\n * Returns true while a discovery render is in progress.\n * Used by `html` and other primitives to short-circuit side effects.\n * @internal\n */\nexport function isDiscoveryRender(): boolean {\n return _isDiscoveryRenderFn();\n}\n\n// Global state to track current component context during render\n// Narrowed internal type for currentComponentContext to expose _hookCallbacks\ninterface InternalHookCallbacks {\n onConnected?: Array<(context?: unknown) => void>;\n onDisconnected?: Array<(context?: unknown) => void>;\n onAttributeChanged?: Array<\n (name: string, oldValue: string | null, newValue: string | null) => void\n >;\n onError?: Array<(err: unknown) => void>;\n props?: Record<string, unknown>;\n style?: () => string;\n expose?: Record<string, unknown>;\n}\n\ntype InternalComponentContext = Record<string, unknown> & {\n _hookCallbacks?: InternalHookCallbacks;\n _computedStyle?: string;\n};\n\nlet currentComponentContext: InternalComponentContext | null = null;\n\n/** Symbol key used to store provides map on a component's context object. */\nconst PROVIDES_KEY = Symbol('cer:provides');\n\n/**\n * Set the current component context (called internally during render)\n * @internal\n */\nexport function setCurrentComponentContext(\n context: Record<string, unknown>,\n): void {\n currentComponentContext = context;\n}\n\n/**\n * Clear the current component context (called internally after render)\n * @internal\n */\nexport function clearCurrentComponentContext(): void {\n currentComponentContext = null;\n}\n\n// ---------- Discovery render probe ----------\n// The actual state and helpers live in discovery-state.ts to avoid\n// circular dependencies with reactive.ts. The re-exports above forward\n// beginDiscoveryRender / endDiscoveryRender / isDiscoveryRender from that\n// module so all existing import sites remain unchanged.\n\n/**\n * Get the current component context. Useful for advanced composable patterns\n * that need to access or pass the context explicitly.\n * @internal\n */\nexport function getCurrentComponentContext(): Record<string, unknown> | null {\n return currentComponentContext;\n}\n\n/**\n * Get the emit function for the current component\n * Must be called during component render\n *\n * @example\n * ```ts\n * component('my-button', () => {\n * const { label } = useProps({ label: 'Click me' });\n * const emit = useEmit();\n *\n * return html`\n * <button @click=\"${() => emit('button-click', { label })}\">\n * ${label}\n * </button>\n * `;\n * });\n * ```\n */\nexport function useEmit(): (\n eventName: string,\n detail?: unknown,\n options?: CustomEventInit,\n) => boolean {\n if (!currentComponentContext) {\n throw new Error('useEmit must be called during component render');\n }\n\n // During discovery render, return a no-op function — no real host exists.\n if (_isDiscoveryRenderFn()) {\n return () => false;\n }\n\n // Capture and validate the emit function from the current context\n const emitCandidate = (currentComponentContext as { emit?: unknown }).emit;\n if (typeof emitCandidate !== 'function') {\n throw new Error(\n 'useEmit requires an emit function on the component context',\n );\n }\n const emitFn = emitCandidate as (\n eventName: string,\n detail?: unknown,\n options?: CustomEventInit,\n ) => boolean;\n\n return (eventName: string, detail?: unknown, options?: CustomEventInit) => {\n return emitFn(eventName, detail, options);\n };\n}\n\n/**\n * Initialize hook callbacks storage on context if not exists\n * Uses Object.defineProperty to avoid triggering reactive updates\n */\nfunction ensureHookCallbacks(context: Record<string, unknown>): void {\n if (!context._hookCallbacks) {\n Object.defineProperty(context, '_hookCallbacks', {\n value: {},\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n}\n\n/**\n * Register a callback to be called when component is connected to DOM\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * useOnConnected(() => {\n * console.log('Component mounted!');\n * });\n *\n * return html`<div>Hello World</div>`;\n * });\n * ```\n */\nexport function useOnConnected(callback: () => void): void {\n if (!currentComponentContext) {\n throw new Error('useOnConnected must be called during component render');\n }\n\n // During discovery render, skip registering lifecycle callbacks — the\n // discoveryContext is ephemeral and its hooks are never invoked.\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext as InternalComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n if (!hooks.onConnected) hooks.onConnected = [];\n hooks.onConnected.push(callback);\n}\n\n/**\n * Register a callback to be called when component is disconnected from DOM\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * useOnDisconnected(() => {\n * console.log('Component unmounted!');\n * });\n *\n * return html`<div>Goodbye World</div>`;\n * });\n * ```\n */\nexport function useOnDisconnected(callback: () => void): void {\n if (!currentComponentContext) {\n throw new Error('useOnDisconnected must be called during component render');\n }\n\n // During discovery render, skip registering lifecycle callbacks.\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext as InternalComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n if (!hooks.onDisconnected) hooks.onDisconnected = [];\n hooks.onDisconnected.push(callback);\n}\n\n/**\n * Register a callback to be called when an attribute changes\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * useOnAttributeChanged((name, oldValue, newValue) => {\n * console.log(`Attribute ${name} changed from ${oldValue} to ${newValue}`);\n * });\n *\n * return html`<div>Attribute watcher</div>`;\n * });\n * ```\n */\nexport function useOnAttributeChanged(\n callback: (\n name: string,\n oldValue: string | null,\n newValue: string | null,\n ) => void,\n): void {\n if (!currentComponentContext) {\n throw new Error(\n 'useOnAttributeChanged must be called during component render',\n );\n }\n\n // During discovery render, skip registering lifecycle callbacks.\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext as InternalComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n if (!hooks.onAttributeChanged) hooks.onAttributeChanged = [];\n hooks.onAttributeChanged.push(callback);\n}\n\n/**\n * Register a callback to be called when an error occurs\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * useOnError((error) => {\n * console.error('Component error:', error);\n * });\n *\n * return html`<div>Error handler</div>`;\n * });\n * ```\n */\nexport function useOnError(callback: (error: Error) => void): void {\n if (!currentComponentContext) {\n throw new Error('useOnError must be called during component render');\n }\n\n // During discovery render, skip registering lifecycle callbacks.\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext as InternalComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n if (!hooks.onError) hooks.onError = [];\n // Wrap to normalize to Error. If the user's handler itself throws, log it in\n // dev mode so it doesn't vanish silently — the original error is already handled.\n hooks.onError.push((err: unknown) => {\n try {\n if (err instanceof Error) callback(err);\n else callback(new Error(String(err)));\n } catch (handlerErr) {\n devError(\n '[useOnError] The error handler itself threw an exception:',\n handlerErr,\n );\n }\n });\n}\n\n/**\n * Register prop defaults for the component. Can be called during render.\n * Stores the prop defaults on `context._hookCallbacks.props` so the runtime\n * can pick them up when building the component config.\n *\n * Example:\n * ```ts\n * component('my-comp', () => {\n * useProps({ modelValue: false, label: 'Hello' });\n * return html`<div/>`;\n * });\n * ```\n */\nconst usePropsStateKey = Symbol.for('@cer/usePropsState');\n\nfunction getUsePropsStateMap(\n context: Record<string, unknown>,\n): Map<string, ReactiveState<unknown>> {\n const typedContext = context as unknown as Record<\n typeof usePropsStateKey,\n Map<string, ReactiveState<unknown>>\n >;\n let map = typedContext[usePropsStateKey] as\n | Map<string, ReactiveState<unknown>>\n | undefined;\n if (!map) {\n map = new Map();\n Object.defineProperty(context, usePropsStateKey, {\n value: map,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n }\n return map;\n}\n\nexport function useProps<T extends Record<string, unknown>>(defaults: T): T {\n if (!currentComponentContext) {\n throw new Error('useProps must be called during component render');\n }\n\n ensureHookCallbacks(currentComponentContext as InternalComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n hooks.props = {\n ...(hooks.props || {}),\n ...defaults,\n };\n\n const ctx = currentComponentContext;\n // Define dynamic getters for declared props so the context property\n // always reflects the host element's property (or reactive ref.value)\n try {\n const declaredKeys = Object.keys(defaults || {});\n for (const key of declaredKeys) {\n if (typeof key !== 'string' || key.startsWith('_')) continue;\n const existing = Object.getOwnPropertyDescriptor(ctx, key);\n // Only define if not present or configurable (allow overriding)\n if (existing && !existing.configurable) continue;\n try {\n // Preserve any existing concrete value on the context in a closure.\n // This avoids recursive getters when we later reference ctx[key].\n const hasOwn = Object.prototype.hasOwnProperty.call(ctx, key);\n let localValue: unknown = hasOwn\n ? (ctx as Record<string, unknown>)[key]\n : undefined;\n\n Object.defineProperty(ctx, key, {\n configurable: true,\n enumerable: true,\n get() {\n try {\n const host = (ctx && (ctx as { _host?: HTMLElement })._host) as\n | HTMLElement\n | undefined;\n if (host) {\n // First, check for attribute value (attributes should take precedence)\n const kebabKey = toKebab(key);\n const attrValue = host.getAttribute(kebabKey);\n if (attrValue !== null) {\n const defaultType = typeof defaults[key];\n if (defaultType === 'boolean') {\n // Standalone boolean attributes have empty string value\n return attrValue === '' || attrValue === 'true';\n }\n if (defaultType === 'number') {\n return Number(attrValue);\n }\n return attrValue;\n }\n\n // If no attribute, check if host has a property value set\n if (\n typeof (host as unknown as Record<string, unknown>)[key] !==\n 'undefined'\n ) {\n const fromHost = (host as unknown as Record<string, unknown>)[\n key\n ];\n // prefer host value when present\n // If the host provided a ReactiveState instance or a wrapper\n // with a .value, unwrap it here so destructured props and\n // useProps return the primitive/current value consistently.\n if (isReactiveState(fromHost)) {\n return (fromHost as { value: unknown }).value;\n }\n if (\n fromHost &&\n typeof fromHost === 'object' &&\n 'value' in fromHost &&\n !(typeof Node !== 'undefined' && fromHost instanceof Node)\n ) {\n return (fromHost as { value?: unknown }).value;\n }\n // For string-typed declared props, avoid returning host\n // object-like properties (for example `element.style` which\n // is a CSSStyleDeclaration). Prefer attribute value or the\n // local default instead of returning a non-primitive host\n // property into templates which expect primitives.\n const defaultType = typeof defaults[key];\n if (\n defaultType === 'string' &&\n fromHost &&\n typeof fromHost === 'object'\n ) {\n // fallthrough to localValue\n } else {\n // For boolean defaults, treat empty string (standalone attribute) or 'true' as true.\n if (\n defaultType === 'boolean' &&\n typeof fromHost === 'string'\n ) {\n return fromHost === '' || fromHost === 'true';\n }\n return fromHost;\n }\n }\n }\n } catch {\n // ignore host read failures and fall back to context\n }\n return localValue;\n },\n set(v: unknown) {\n // allow test/runtime code to set context props during render/init\n localValue = v;\n },\n });\n } catch {\n // ignore\n }\n }\n } catch {\n // ignore\n }\n // Return a Proxy that always reads the latest value from the component\n // context so accesses are reactive. Also unwrap functional refs ({ value })\n // and coerce string attribute values to boolean/number when defaults\n // indicate such types.\n const result = new Proxy({} as Record<string, unknown>, {\n get(_target, prop: string) {\n if (typeof prop !== 'string') return undefined;\n const def = (defaults as Record<string, unknown>)[prop];\n\n const propStateMap = getUsePropsStateMap(ctx);\n let state = propStateMap.get(prop);\n let currentValue: unknown;\n\n // If a host element is available, prefer reading from attributes first,\n // then from properties. This ensures that HTML attributes take precedence\n // over default property values (like the standard \"title\" attribute).\n try {\n const host = (ctx && (ctx as { _host?: HTMLElement })._host) as\n | HTMLElement\n | undefined;\n if (host) {\n // Check attribute first (only if host is an actual HTMLElement)\n if (\n (typeof HTMLElement !== 'undefined' &&\n host instanceof HTMLElement) ||\n (typeof (host as { getAttribute?: (name: string) => string | null })\n .getAttribute === 'function' &&\n typeof (host as { hasAttribute?: (name: string) => boolean })\n .hasAttribute === 'function')\n ) {\n const kebabKey = prop.replace(/([A-Z])/g, '-$1').toLowerCase();\n const attrValue = (\n host as { getAttribute: (name: string) => string | null }\n ).getAttribute(kebabKey);\n if (attrValue !== null) {\n if (typeof def === 'boolean') {\n currentValue = attrValue === '' || attrValue === 'true';\n } else if (typeof def === 'number') {\n currentValue = Number(attrValue);\n } else {\n currentValue = attrValue;\n }\n }\n }\n\n // No attribute - check property value\n if (currentValue === undefined) {\n const hostValue = (host as unknown as Record<string, unknown>)[\n prop\n ];\n if (typeof hostValue !== 'undefined' && hostValue !== '') {\n const isWrapperLike =\n hostValue &&\n typeof hostValue === 'object' &&\n 'value' in hostValue &&\n !(typeof Node !== 'undefined' && hostValue instanceof Node);\n if (\n !(\n typeof def === 'string' &&\n hostValue &&\n typeof hostValue === 'object' &&\n !isWrapperLike &&\n !isReactiveState(hostValue)\n )\n ) {\n if (\n typeof def === 'boolean' &&\n def === false &&\n hostValue === ''\n ) {\n currentValue = def;\n } else if (isReactiveState(hostValue)) {\n currentValue = (hostValue as { value: unknown }).value;\n } else if (isWrapperLike) {\n currentValue = (hostValue as { value: unknown }).value;\n } else if (\n typeof def === 'boolean' &&\n typeof hostValue === 'string'\n ) {\n currentValue = hostValue === '' || hostValue === 'true';\n } else if (\n typeof def === 'number' &&\n typeof hostValue === 'string' &&\n !Number.isNaN(Number(hostValue))\n ) {\n currentValue = Number(hostValue);\n } else {\n currentValue = hostValue;\n }\n }\n }\n }\n }\n } catch {\n // ignore host read failures and fall back to context\n }\n\n // Fall back to reading from the component context itself.\n if (currentValue === undefined) {\n const raw = ctx[prop];\n\n if (typeof def === 'boolean' && raw === '') {\n currentValue = def === false ? def : true;\n } else if (isReactiveState(raw)) {\n currentValue = (raw as { value: unknown }).value;\n } else if (\n raw &&\n typeof raw === 'object' &&\n 'value' in raw &&\n !(typeof Node !== 'undefined' && raw instanceof Node)\n ) {\n currentValue = (raw as { value: unknown }).value;\n } else if (raw != null && raw !== '') {\n if (typeof def === 'boolean' && typeof raw === 'string') {\n currentValue = raw === 'true';\n } else if (\n typeof def === 'number' &&\n typeof raw === 'string' &&\n !Number.isNaN(Number(raw))\n ) {\n currentValue = Number(raw);\n } else {\n currentValue = raw;\n }\n } else {\n currentValue = def;\n }\n }\n\n if (!state) {\n state = new ReactiveState(currentValue);\n propStateMap.set(prop, state);\n } else if (!Object.is(state.peek(), currentValue)) {\n if (reactiveSystem.isRenderingComponent()) {\n state.initSilent(currentValue);\n } else {\n state.value = currentValue;\n }\n }\n\n return state.value;\n },\n has(_target, prop: string) {\n return typeof prop === 'string' && (prop in ctx || prop in defaults);\n },\n ownKeys() {\n return Array.from(\n new Set([...Object.keys(defaults), ...Object.keys(ctx || {})]),\n );\n },\n getOwnPropertyDescriptor() {\n return { configurable: true, enumerable: true } as PropertyDescriptor;\n },\n });\n\n return result as T;\n}\n\n/**\n * Register prop defaults and return a stable props object for use inside render.\n * The returned object reads values from the current component context at render\n * time and falls back to the provided defaults. This keeps prop access stable\n * in production builds and avoids reliance on parsing the render function.\n *\n * Must be called during render. Example:\n * const props = useProps({ modelValue: false });\n */\n// (useProps now returns the props object directly)\n\n/**\n * Register a style function that will be called during each render\n * to provide reactive styles for the component\n *\n * @example\n * ```ts\n * import { css } from '@lib/style';\n *\n * component('my-component', () => {\n * const { theme } = useProps({ theme: 'light' });\n *\n * useStyle(() => css`\n * :host {\n * background: ${theme === 'light' ? 'white' : 'black'};\n * color: ${theme === 'light' ? 'black' : 'white'};\n * }\n * `);\n *\n * return html`<div>Styled component</div>`;\n * });\n * ```\n */\nexport function useStyle(callback: () => string): void {\n if (!currentComponentContext) {\n throw new Error('useStyle must be called during component render');\n }\n\n // During discovery render, skip style computation — no real DOM to style.\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext);\n\n // Execute the callback immediately during render to capture the current style\n // This ensures reactive state is read during the render phase, not during style application\n try {\n const computedStyle = callback();\n\n // Store the computed style using Object.defineProperty to avoid triggering reactive updates\n Object.defineProperty(currentComponentContext, '_computedStyle', {\n value: computedStyle,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n } catch (error) {\n devWarn('Error in useStyle callback:', error);\n Object.defineProperty(currentComponentContext, '_computedStyle', {\n value: '',\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n}\n\n/**\n * Cache of globally-injected stylesheets keyed by their CSS content.\n * Prevents duplicate `<style>` injections when the same `useGlobalStyle()`\n * factory runs across multiple component instances.\n */\nconst _globalStyleSheets = new Map<string, CSSStyleSheet>();\n\n/**\n * Inject CSS into `document.adoptedStyleSheets`, escaping the Shadow DOM\n * boundary. Suitable for `@font-face` declarations, `:root` variable overrides,\n * and global scroll/scroll-bar styling. Deduplicated by CSS content so calling\n * this in multiple component instances is safe.\n *\n * **Use sparingly** — this intentionally breaks Shadow DOM encapsulation.\n * A dev-mode warning is emitted to make the escape hatch visible.\n *\n * @example\n * ```ts\n * component('app-root', () => {\n * useGlobalStyle(() => css`\n * @font-face {\n * font-family: 'Inter';\n * src: url('/fonts/inter.woff2') format('woff2');\n * }\n * :root {\n * --app-font: 'Inter', sans-serif;\n * }\n * `);\n * return html`<slot></slot>`;\n * });\n * ```\n */\nexport function useGlobalStyle(styleFactory: () => string): void {\n let raw: string;\n try {\n raw = styleFactory();\n } catch {\n return;\n }\n\n // SSR collection pass: when an active collector exists (set up by\n // beginSSRGlobalStyleCollection in ssr.ts), capture here and skip DOM\n // injection regardless of whether document is available. This correctly\n // handles both Node.js SSR (no document) and test environments (document\n // present via happy-dom/jsdom) that call renderToStringWithJITCSS.\n if (captureGlobalStyleForSSR(raw)) return;\n\n if (typeof document === 'undefined' || typeof CSSStyleSheet === 'undefined') {\n // SSR without an active collector — nothing to do.\n return;\n }\n devWarn(\n '[useGlobalStyle] Injecting global styles from a component. ' +\n 'This escapes Shadow DOM encapsulation — use sparingly.',\n );\n const style = minifyCSS(sanitizeCSS(raw!));\n if (!style || _globalStyleSheets.has(style)) return;\n try {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(style);\n document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];\n _globalStyleSheets.set(style, sheet);\n } catch {\n // Fallback: inject a <style> element in <head>\n const el = document.createElement('style');\n el.textContent = style;\n (document.head ?? document.documentElement).appendChild(el);\n }\n}\n\n/**\n * Design token definitions accepted by `useDesignTokens()`.\n * Map high-level token names to CSS custom property overrides.\n */\nexport interface DesignTokens {\n /** Override the primary color scale root (sets --cer-color-primary-500) */\n primary?: string;\n /** Override the secondary color scale root */\n secondary?: string;\n /** Override the neutral color scale root */\n neutral?: string;\n /** Override the success color root */\n success?: string;\n /** Override the info color root */\n info?: string;\n /** Override the warning color root */\n warning?: string;\n /** Override the error color root */\n error?: string;\n /** Override the sans-serif font family */\n fontSans?: string;\n /** Override the serif font family */\n fontSerif?: string;\n /** Override the monospace font family */\n fontMono?: string;\n /** Additional arbitrary CSS custom property overrides */\n [key: string]: string | undefined;\n}\n\n/**\n * Apply design tokens to `:host` as CSS custom property overrides.\n * Must be called during component render. This is a typed, validated\n * alternative to writing `useStyle(() => css\\`:host { ... }\\`)` by hand.\n *\n * Semantic color tokens (e.g. `primary: '#6366f1'`) set the `*-500` shade\n * for that scale. Use arbitrary `'--cer-color-primary-500'` keys to override\n * individual shades.\n *\n * @example\n * ```ts\n * component('app-root', () => {\n * useDesignTokens({\n * primary: '#6366f1',\n * fontSans: '\"Inter\", sans-serif',\n * '--cer-color-neutral-900': '#0a0a0a',\n * });\n * return html`<slot></slot>`;\n * });\n * ```\n */\nexport function useDesignTokens(tokens: DesignTokens): void {\n if (!currentComponentContext) {\n throw new Error('useDesignTokens must be called during component render');\n }\n\n if (_isDiscoveryRenderFn()) return;\n\n const declarations: string[] = [];\n const semanticColorMap: Record<string, string> = {\n primary: '--cer-color-primary-500',\n secondary: '--cer-color-secondary-500',\n neutral: '--cer-color-neutral-500',\n success: '--cer-color-success-500',\n info: '--cer-color-info-500',\n warning: '--cer-color-warning-500',\n error: '--cer-color-error-500',\n };\n const fontMap: Record<string, string> = {\n fontSans: '--cer-font-sans',\n fontSerif: '--cer-font-serif',\n fontMono: '--cer-font-mono',\n };\n\n for (const [key, value] of Object.entries(tokens)) {\n if (value === undefined) continue;\n if (key in semanticColorMap) {\n declarations.push(`${semanticColorMap[key]}:${value}`);\n } else if (key in fontMap) {\n declarations.push(`${fontMap[key]}:${value}`);\n } else if (key.startsWith('--')) {\n declarations.push(`${key}:${value}`);\n }\n }\n\n if (declarations.length === 0) return;\n\n const cssText = `:host{${declarations.join(';')}}`;\n\n // Append to any existing computed style\n const ctx = currentComponentContext as { _computedStyle?: string };\n const existing = ctx._computedStyle ?? '';\n const combined = existing ? `${existing}\\n${cssText}` : cssText;\n\n Object.defineProperty(currentComponentContext, '_computedStyle', {\n value: combined,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n}\n\n// ---------- provide / inject ----------\n\n/**\n * Store a value under a key so that descendant components can retrieve it\n * with `inject()`. Must be called during component render.\n *\n * @example\n * ```ts\n * component('theme-provider', () => {\n * provide('theme', 'dark');\n * return html`<slot></slot>`;\n * });\n * ```\n */\nexport function provide<T>(key: string | symbol, value: T): void {\n if (!currentComponentContext) {\n throw new Error('provide must be called during component render');\n }\n\n // During discovery render, skip provide — the ephemeral context is discarded.\n if (_isDiscoveryRenderFn()) return;\n\n const ctx = currentComponentContext as Record<string | symbol, unknown>;\n if (!ctx[PROVIDES_KEY]) {\n Object.defineProperty(ctx, PROVIDES_KEY, {\n value: new Map<string | symbol, unknown>(),\n writable: false,\n enumerable: false,\n configurable: true,\n });\n }\n (ctx[PROVIDES_KEY] as Map<string | symbol, unknown>).set(key, value);\n}\n\n/**\n * Retrieve a value provided by an ancestor component. Traverses the shadow\n * DOM tree upward through ShadowRoot host elements looking for the nearest\n * `provide()` call with the matching key. Returns `defaultValue` (or\n * `undefined`) when no provider is found. Must be called during render.\n *\n * @example\n * ```ts\n * component('themed-button', () => {\n * const theme = inject<string>('theme', 'light');\n * return html`<button class=\"btn-${theme}\">Click</button>`;\n * });\n * ```\n */\nexport function inject<T>(\n key: string | symbol,\n defaultValue?: T,\n): T | undefined {\n if (!currentComponentContext) {\n throw new Error('inject must be called during component render');\n }\n\n // During discovery render, the host tree is not yet mounted — return the\n // default value to allow prop detection to continue without DOM traversal.\n if (_isDiscoveryRenderFn()) return defaultValue;\n\n try {\n const host = (currentComponentContext as { _host?: HTMLElement })._host;\n if (host) {\n let node: Node | null = host.parentNode as Node | null;\n if (!node) node = host.getRootNode() as Node | null;\n\n // Depth counter prevents infinite loops in detached subtrees where\n // getRootNode() may return a subtree root instead of `document`.\n let depth = 0;\n const MAX_DEPTH = 50;\n\n while (node && depth < MAX_DEPTH) {\n depth++;\n if (typeof ShadowRoot !== 'undefined' && node instanceof ShadowRoot) {\n const shadowHost = node.host;\n const hostCtx = (\n shadowHost as unknown as {\n context?: Record<string | symbol, unknown>;\n }\n ).context;\n if (hostCtx) {\n const provides = hostCtx[PROVIDES_KEY] as\n | Map<string | symbol, unknown>\n | undefined;\n if (provides?.has(key)) {\n return provides.get(key) as T;\n }\n }\n const next: Node | null = shadowHost.parentNode as Node | null;\n node = next ?? (shadowHost.getRootNode() as Node | null);\n if (node === document || node === shadowHost) break;\n } else {\n // Also check light-DOM ancestor elements that may be custom components\n // with provides (e.g. a consumer that is a slotted child of a provider).\n if (typeof Element !== 'undefined' && node instanceof Element) {\n const elCtx = (\n node as unknown as {\n context?: Record<string | symbol, unknown>;\n }\n ).context;\n if (elCtx) {\n const provides = elCtx[PROVIDES_KEY] as\n | Map<string | symbol, unknown>\n | undefined;\n if (provides?.has(key)) {\n return provides.get(key) as T;\n }\n }\n }\n const prevNode = node;\n const next: Node | null = (node as Node).parentNode as Node | null;\n node = next ?? ((node as Node).getRootNode?.() as Node | null);\n // Guard against infinite loops: if getRootNode() returns the same\n // node (disconnected element with no ancestors), stop traversal.\n if (node === document || node === prevNode) break;\n }\n }\n }\n } catch {\n // ignore traversal errors - fall through to default\n }\n\n return defaultValue;\n}\n\n// ---------- createComposable ----------\n\n/**\n * Execute a function that calls hooks (useOnConnected, useOnDisconnected, etc.)\n * using an explicit component context rather than requiring the call to happen\n * directly inside a render function. This enables composable utility functions\n * that register lifecycle callbacks from outside the render body.\n *\n * @example\n * ```ts\n * function useLogger(label: string) {\n * return createComposable(() => {\n * useOnConnected(() => console.log(`${label} connected`));\n * useOnDisconnected(() => console.log(`${label} disconnected`));\n * });\n * }\n *\n * component('my-comp', () => {\n * const stopLogger = useLogger('my-comp');\n * stopLogger(context); // pass the component context explicitly\n * return html`<div>Hello</div>`;\n * });\n * ```\n *\n * More commonly, use it as a direct wrapper inside render:\n * ```ts\n * component('my-comp', () => {\n * // Accepts context automatically from getCurrentComponentContext()\n * createComposable(() => {\n * useOnConnected(() => console.log('connected from composable'));\n * })();\n * return html`<div>Hello</div>`;\n * });\n * ```\n */\nexport function createComposable<T>(\n fn: () => T,\n): (ctx?: Record<string, unknown>) => T {\n return (ctx?: Record<string, unknown>) => {\n const targetCtx = ctx ?? currentComponentContext;\n if (!targetCtx) {\n throw new Error(\n 'createComposable: no component context available. Pass a context explicitly or call inside a render function.',\n );\n }\n\n const prev = currentComponentContext;\n setCurrentComponentContext(targetCtx);\n try {\n return fn();\n } finally {\n // Restore the previous context (supports nested composables)\n if (prev) {\n setCurrentComponentContext(prev);\n } else {\n clearCurrentComponentContext();\n }\n }\n };\n}\n\n/**\n * Expose a public interface from the current component so that parent\n * components holding a template ref to this element can call its methods\n * or read its properties. Must be called during component render.\n *\n * @example\n * ```ts\n * component('my-counter', () => {\n * const count = ref(0);\n * useExpose({ increment: () => count.value++, get count() { return count.value; } });\n * return html`<div>${count.value}</div>`;\n * });\n *\n * // Parent: counterRef.value.increment()\n * ```\n */\nexport function useExpose<T extends Record<string, unknown>>(exposed: T): void {\n if (!currentComponentContext) {\n throw new Error('useExpose must be called during component render');\n }\n\n // During discovery render, skip — no real host to expose properties on\n if (_isDiscoveryRenderFn()) return;\n\n ensureHookCallbacks(currentComponentContext);\n const hooks = currentComponentContext._hookCallbacks as InternalHookCallbacks;\n hooks.expose = { ...(hooks.expose ?? {}), ...exposed };\n\n // Apply exposed properties onto the host element immediately if available\n const host = (currentComponentContext as { _host?: HTMLElement })._host;\n if (host) {\n for (const [key, value] of Object.entries(exposed)) {\n try {\n (host as unknown as Record<string, unknown>)[key] = value;\n } catch {\n // ignore non-writable properties\n }\n }\n }\n}\n\n/**\n * Access named slots provided to the current component. Returns helpers to\n * check slot presence and retrieve slotted elements. Must be called during\n * component render.\n *\n * @example\n * ```ts\n * component('my-card', () => {\n * const slots = useSlots();\n * return html`\n * <div class=\"card\">\n * <slot></slot>\n * ${slots.has('footer') ? html`<footer><slot name=\"footer\"></slot></footer>` : ''}\n * </div>\n * `;\n * });\n * ```\n */\nexport function useSlots(): {\n has(name?: string): boolean;\n getNodes(name?: string): Element[];\n names(): string[];\n} {\n if (!currentComponentContext) {\n throw new Error('useSlots must be called during component render');\n }\n\n // During discovery render, return empty no-op slot object\n if (_isDiscoveryRenderFn()) {\n return { has: () => false, getNodes: () => [], names: () => [] };\n }\n\n const host = (currentComponentContext as { _host?: HTMLElement })._host;\n\n // Single-pass collection: group children by slot name once, reuse for all methods.\n const getSlotMap = (): Map<string, Element[]> => {\n const map = new Map<string, Element[]>();\n if (!host) return map;\n for (const child of host.children) {\n const key = child.getAttribute('slot') ?? 'default';\n const bucket = map.get(key);\n if (bucket) {\n bucket.push(child);\n } else {\n map.set(key, [child]);\n }\n }\n return map;\n };\n\n return {\n /**\n * Returns true if the named slot (or the default slot when name is\n * omitted) has at least one slotted child element.\n */\n has(name?: string): boolean {\n if (!host) return false;\n const slotName = !name || name === 'default' ? 'default' : name;\n const bucket = getSlotMap().get(slotName);\n return bucket !== undefined && bucket.length > 0;\n },\n /**\n * Returns all child elements assigned to the named slot (or the default\n * slot when name is omitted).\n */\n getNodes(name?: string): Element[] {\n if (!host) return [];\n const slotName = !name || name === 'default' ? 'default' : name;\n return getSlotMap().get(slotName) ?? [];\n },\n /** Returns the names of all slots that have content, including 'default'. */\n names(): string[] {\n if (!host) return [];\n return Array.from(getSlotMap().keys());\n },\n };\n}\n\n/**\n * A writable ref that reads from a component prop and emits `update:<propName>`\n * when its value is set, enabling two-way binding with a parent's `:model` or\n * `:model:<propName>` directive.\n *\n * Also recognised by the vdom `:model` directive as a reactive value so it can\n * be passed directly to native inputs inside the child template.\n */\nexport interface ModelRef<T> {\n /** The current prop value. Reactive — reads trigger re-renders. */\n value: T;\n}\n\n/**\n * Define a two-way binding model for a component prop, similar to Vue's\n * `defineModel()`. It combines `useProps` + `useEmit` into a single ergonomic\n * API so child components don't need to wire the plumbing manually.\n *\n * The returned `ModelRef` object:\n * - **reads** `.value` → returns the current prop value (reactive)\n * - **writes** `.value = x` → emits `update:<propName>` so the parent's\n * `:model` / `:model:<propName>` directive can update its reactive state\n *\n * The object is also recognised by the vdom `:model` directive, so you can\n * pass it directly to a native input's `:model` binding inside the child\n * template and the two-way sync is wired up automatically.\n *\n * @example\n * ```ts\n * // Default model — maps to the parent's :model=\"...\"\n * component('my-input', () => {\n * const model = defineModel('');\n *\n * return html`\n * <input :model=\"${model}\" />\n * `;\n * });\n *\n * // Named model — maps to the parent's :model:title=\"...\"\n * component('my-field', () => {\n * const title = defineModel('title', '');\n * const count = defineModel('count', 0);\n *\n * return html`\n * <input :model=\"${title}\" />\n * <input type=\"number\" :model=\"${count}\" />\n * `;\n * });\n * ```\n *\n * @param args - Either:\n * - No arguments → `modelValue` prop, no default.\n * - One argument → treated as the **default value** for the `modelValue` prop;\n * type is inferred from the value.\n * - Two arguments → first is the **prop name**, second is the **default value**;\n * type is inferred from the default value.\n */\nexport function defineModel<T = unknown>(): ModelRef<T | undefined>;\nexport function defineModel<T>(defaultValue: T): ModelRef<T>;\nexport function defineModel<T>(propName: string, defaultValue: T): ModelRef<T>;\nexport function defineModel<T = unknown>(\n ...args: [] | [T] | [string, T]\n): ModelRef<T | undefined> {\n if (!currentComponentContext) {\n throw new Error('defineModel must be called during component render');\n }\n\n const propName = args.length === 2 ? (args[0] as string) : 'modelValue';\n const initialDefault =\n args.length === 2\n ? (args[1] as T)\n : args.length === 1\n ? (args[0] as T)\n : undefined;\n\n // Register the prop so the runtime discovers it during the discovery render\n // and includes it in the component's observed attributes / prop definitions.\n const props = useProps({\n [propName]: initialDefault,\n } as Record<string, unknown>);\n\n // Capture the emit function once — during a discovery render this is a no-op.\n const isDiscovery = _isDiscoveryRenderFn();\n const emitFn = isDiscovery\n ? null\n : (() => {\n const candidate = (currentComponentContext as { emit?: unknown }).emit;\n if (typeof candidate !== 'function') return null;\n return candidate as (\n eventName: string,\n detail?: unknown,\n options?: CustomEventInit,\n ) => boolean;\n })();\n\n // The model ref is marked with the ReactiveState symbol so that\n // processModelDirective treats it as a reactive value and wires up\n // `:model` on native inputs inside the child template correctly.\n const modelRef: ModelRef<T> = {\n get value(): T {\n return props[propName] as T;\n },\n set value(newValue: T) {\n if (emitFn) {\n emitFn(`update:${propName}`, newValue);\n }\n },\n };\n\n try {\n const key = Symbol.for('@cer/ReactiveState');\n Object.defineProperty(modelRef, key, {\n value: true,\n enumerable: false,\n configurable: false,\n });\n } catch {\n // ignore exotic runtimes\n }\n\n return modelRef;\n}\n"],"mappings":";;;;AAiCA,IAAI,IAA4C;AAGhD,SAAgB,IAAsC;AACpD,KAAI,MAA6B,KAC/B,OAAU,MACR,wMAGD;AAEH,KAA2B,EAAE;;AAI/B,SAAgB,IAAwC;CACtD,IAAM,IAAY,KAA4B,EAAE;AAEhD,QADA,IAA2B,MACpB;;AAOT,SAAgB,EAAyB,GAAsB;AAO7D,QANI,MAA6B,OAM1B,MALD,KAAO,CAAC,EAAyB,SAAS,EAAI,IAChD,EAAyB,KAAK,EAAI,EAE7B;;AAiCX,IAAI,IAAoB;AAExB,SAAgB,EACd,GACA,GACA,IAAM,WACN,GACiB;CAEjB,IAAM,IAA0C,EAAE;AAClD,MAAK,IAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAS,EAAE,CAAC,CAC9C,GAAe,EAAQ,EAAE,IAAI;CAI/B,IAAM,IAAW;EACf,aAAa,GAA6B;GACxC,IAAM,IAAQ,EAAQ,EAAK;AAC3B,OACE,EAAe,OAAW,KAAA,KAC1B,EAAe,OAAW,KAE1B,QAAO,OAAO,EAAe,GAAO;GAEtC,IAAM,KAAO,KAAS,EAAE,EAAE;AAC1B,UAAO,KAA6B,OAAqB,OAAd,OAAO,EAAI;;EAExD,aAAa,GAAuB;AAClC,UAAO,KAAK,aAAa,EAAK,KAAK;;EAGrC,YAAY;EACZ,SAAS;EACT,eAAe;EAChB,EAIK,IAAsC;EAC1C,GAAG;EAKH,cAAc,WAAW,OAAO,KAAK,EAAe,CAAC,KAAK,IAAI,IAAI,OAAO,GAAG,EAAE;EAC9E,qBAAqB,KAAA;EACrB,sBAAsB,KAAA;EACtB,YAAY;EACZ,MAAM,EAAE;EACT;AA2BD,CAxBA,OAAO,eAAe,GAAY,SA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