sibujs 4.13.1 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +15 -2
  3. package/dist/browser.js +9 -7
  4. package/dist/build.cjs +880 -281
  5. package/dist/build.d.cts +68 -3
  6. package/dist/build.d.ts +68 -3
  7. package/dist/build.js +88 -30
  8. package/dist/cdn.dev.global.js +12 -12
  9. package/dist/cdn.full.dev.global.js +13 -13
  10. package/dist/cdn.full.global.js +12 -12
  11. package/dist/cdn.global.js +12 -12
  12. package/dist/{chunk-5RIBLY2N.js → chunk-2TTRW2TE.js} +6 -6
  13. package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
  14. package/dist/chunk-3HZOSMPX.js +90 -0
  15. package/dist/{chunk-QKFVMIAV.js → chunk-4FJSAUKB.js} +11 -3
  16. package/dist/{chunk-OIKD7YDY.js → chunk-4TQDTWWN.js} +6 -5
  17. package/dist/{chunk-5XUGJM3J.js → chunk-7ILEHTVX.js} +1 -1
  18. package/dist/{chunk-EU7T7EB3.js → chunk-A454RAEK.js} +4 -4
  19. package/dist/{chunk-QC3NP47A.js → chunk-AE32RGWX.js} +10 -6
  20. package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
  21. package/dist/{chunk-QZ47OZ25.js → chunk-BKZ5N6NK.js} +8 -6
  22. package/dist/{chunk-2O6JJCUR.js → chunk-BNXRWZZV.js} +49 -8
  23. package/dist/chunk-BOYKGGVD.js +2015 -0
  24. package/dist/{chunk-22OPSWMF.js → chunk-CCKUNHVU.js} +2 -2
  25. package/dist/{chunk-CPQKWCJ2.js → chunk-CJ7KS3DF.js} +16 -10
  26. package/dist/chunk-CNPT6NKV.js +1859 -0
  27. package/dist/{chunk-2NC56RGY.js → chunk-F67F77IA.js} +2 -2
  28. package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
  29. package/dist/chunk-GVAMIU6K.js +195 -0
  30. package/dist/{chunk-K4LNUT5L.js → chunk-HQIAL7F2.js} +8 -6
  31. package/dist/{chunk-C73VBPEF.js → chunk-JTFQ7IL4.js} +8 -8
  32. package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
  33. package/dist/{chunk-4UTGDVSA.js → chunk-MIRKTVH4.js} +7 -14
  34. package/dist/{chunk-YFTBCCVH.js → chunk-N7A6FKWW.js} +5 -3
  35. package/dist/chunk-NT3ZYB5S.js +167 -0
  36. package/dist/{chunk-VFPLWUT7.js → chunk-QS6GMWDD.js} +151 -86
  37. package/dist/chunk-R5U7XKVJ.js +16 -0
  38. package/dist/{chunk-ADZHPN2B.js → chunk-RVR5NPFL.js} +3 -3
  39. package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
  40. package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
  41. package/dist/{chunk-G3Z2FEBR.js → chunk-SVULV7O4.js} +119 -26
  42. package/dist/{chunk-PBJYCE2Z.js → chunk-TLS4NVIB.js} +5 -5
  43. package/dist/{chunk-KC62VURU.js → chunk-UUIKJJIK.js} +10 -8
  44. package/dist/chunk-UYTYNCMZ.js +199 -0
  45. package/dist/chunk-VM2U5LEL.js +2596 -0
  46. package/dist/{chunk-J4X7ICH4.js → chunk-Y4LUM2XS.js} +8 -6
  47. package/dist/data.cjs +265 -35
  48. package/dist/data.d.cts +31 -1
  49. package/dist/data.d.ts +31 -1
  50. package/dist/data.js +16 -10
  51. package/dist/devtools.cjs +15 -2
  52. package/dist/devtools.js +9 -7
  53. package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
  54. package/dist/ecosystem.cjs +62 -23
  55. package/dist/ecosystem.js +14 -12
  56. package/dist/extras.cjs +3520 -270
  57. package/dist/extras.d.cts +3 -3
  58. package/dist/extras.d.ts +3 -3
  59. package/dist/extras.js +39 -29
  60. package/dist/index.cjs +442 -253
  61. package/dist/index.d.cts +93 -283
  62. package/dist/index.d.ts +93 -283
  63. package/dist/index.js +26 -16
  64. package/dist/motion.cjs +12 -1
  65. package/dist/motion.js +6 -4
  66. package/dist/patterns.cjs +15 -2
  67. package/dist/patterns.js +10 -8
  68. package/dist/performance.cjs +36 -2
  69. package/dist/performance.d.cts +2 -2
  70. package/dist/performance.d.ts +2 -2
  71. package/dist/performance.js +14 -10
  72. package/dist/plugins.cjs +5225 -1807
  73. package/dist/plugins.d.cts +8 -834
  74. package/dist/plugins.d.ts +8 -834
  75. package/dist/plugins.js +64 -2329
  76. package/dist/prerenderServer-MXJEVWA3.js +350 -0
  77. package/dist/renderRoute-DP20XwMS.d.cts +86 -0
  78. package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
  79. package/dist/routeHead-CE9SV-cH.d.cts +995 -0
  80. package/dist/routeHead-DzVxPviY.d.ts +995 -0
  81. package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
  82. package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
  83. package/dist/ssr-JpGpHnpC.d.cts +841 -0
  84. package/dist/ssr-JpGpHnpC.d.ts +841 -0
  85. package/dist/{ssr-VBM6J5SJ.js → ssr-NECEU4X4.js} +15 -6
  86. package/dist/ssr-dom.cjs +1862 -0
  87. package/dist/ssr-dom.d.cts +341 -0
  88. package/dist/ssr-dom.d.ts +341 -0
  89. package/dist/ssr-dom.js +19 -0
  90. package/dist/ssr.cjs +7630 -2064
  91. package/dist/ssr.d.cts +63 -5
  92. package/dist/ssr.d.ts +63 -5
  93. package/dist/ssr.js +136 -14
  94. package/dist/testing.cjs +6543 -87
  95. package/dist/testing.d.cts +80 -1
  96. package/dist/testing.d.ts +80 -1
  97. package/dist/testing.js +117 -4
  98. package/dist/ui.cjs +36 -2
  99. package/dist/ui.js +17 -14
  100. package/dist/widgets.cjs +14 -1
  101. package/dist/widgets.js +11 -9
  102. package/package.json +9 -2
  103. package/dist/chunk-2F4PSJ5Z.js +0 -765
  104. package/dist/chunk-7XHATCIH.js +0 -121
  105. package/dist/chunk-B36ADEIR.js +0 -21
  106. package/dist/ssr-Db0Sgdu3.d.cts +0 -245
  107. package/dist/ssr-Db0Sgdu3.d.ts +0 -245
@@ -0,0 +1,1862 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ssr-dom.ts
21
+ var ssr_dom_exports = {};
22
+ __export(ssr_dom_exports, {
23
+ ServerDocument: () => ServerDocument,
24
+ ServerElement: () => ServerElement,
25
+ ServerNode: () => ServerNode,
26
+ createServerDocument: () => createServerDocument,
27
+ installServerDom: () => installServerDom,
28
+ isServerDom: () => isServerDom
29
+ });
30
+ module.exports = __toCommonJS(ssr_dom_exports);
31
+
32
+ // src/core/dev.ts
33
+ var DEV = typeof __SIBU_DEV__ !== "undefined" ? !!__SIBU_DEV__ : typeof globalThis.__SIBU_DEV__ !== "undefined" ? !!globalThis.__SIBU_DEV__ : (
34
+ // safe default: off in browser, on in test/dev Node
35
+ typeof process !== "undefined" && process.env?.NODE_ENV !== "production"
36
+ );
37
+
38
+ // src/core/ssr-context.ts
39
+ var SSR_KEY = /* @__PURE__ */ Symbol.for("sibujs.ssr.v1");
40
+ function detectSSRShared() {
41
+ let detected = null;
42
+ try {
43
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
44
+ let mod = null;
45
+ const getBuiltin = process.getBuiltinModule;
46
+ if (typeof getBuiltin === "function") {
47
+ mod = getBuiltin("node:async_hooks");
48
+ } else if (typeof require === "function") {
49
+ mod = require("async_hooks");
50
+ }
51
+ if (mod) detected = new mod.AsyncLocalStorage();
52
+ }
53
+ const globalAls = globalThis.AsyncLocalStorage;
54
+ if (!detected && typeof globalAls === "function") detected = new globalAls();
55
+ } catch {
56
+ detected = null;
57
+ }
58
+ return {
59
+ als: detected,
60
+ fallbackStore: { ssr: false, suspenseIdCounter: 0, locale: void 0 },
61
+ fallbackDepth: 0
62
+ };
63
+ }
64
+ var _shared = globalThis[SSR_KEY] ?? (globalThis[SSR_KEY] = detectSSRShared());
65
+ var als = _shared.als;
66
+ var fallbackStore = _shared.fallbackStore;
67
+ _shared.fallbackDepth ?? (_shared.fallbackDepth = 0);
68
+ function getRequestStore() {
69
+ if (als) return als.getStore() ?? null;
70
+ return _shared.fallbackDepth > 0 ? fallbackStore : null;
71
+ }
72
+ function requestSlot(name, create) {
73
+ const store = getRequestStore();
74
+ if (!store) return void 0;
75
+ const slots = store.slots ?? (store.slots = /* @__PURE__ */ new Map());
76
+ if (!slots.has(name) && create) slots.set(name, create());
77
+ return slots.get(name);
78
+ }
79
+
80
+ // src/platform/serverDom.ts
81
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
82
+ var SVG_NS = "http://www.w3.org/2000/svg";
83
+ var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
84
+ var ELEMENT_NODE = 1;
85
+ var ATTRIBUTE_NODE = 2;
86
+ var TEXT_NODE = 3;
87
+ var COMMENT_NODE = 8;
88
+ var DOCUMENT_NODE = 9;
89
+ var DOCUMENT_FRAGMENT_NODE = 11;
90
+ function callerFrame() {
91
+ const stack = new Error().stack ?? "";
92
+ const lines = stack.split("\n").slice(1);
93
+ for (const line of lines) {
94
+ if (line.includes("serverDom")) continue;
95
+ const trimmed = line.trim();
96
+ if (trimmed) return trimmed.replace(/^at\s+/, "");
97
+ }
98
+ return "(unknown caller)";
99
+ }
100
+ var warnedSites = /* @__PURE__ */ new Set();
101
+ function reportBrowserApi(api) {
102
+ const frame = callerFrame();
103
+ const entry = `${api} at ${frame}`;
104
+ requestSlot("browserApis", () => /* @__PURE__ */ new Set())?.add(entry);
105
+ if (DEV && !warnedSites.has(entry) && warnedSites.size < 200) {
106
+ warnedSites.add(entry);
107
+ console.warn(
108
+ `[SibuJS SSR] ${api} was used during a server render (${frame}). It only exists in a browser: move the code into onMount() or an effect, or render it with ClientOnly().`
109
+ );
110
+ }
111
+ return frame;
112
+ }
113
+ function unavailable(api) {
114
+ const frame = reportBrowserApi(api);
115
+ throw new Error(
116
+ `[SibuJS SSR] ${api} is not available in the SibuJS server DOM (called from ${frame}). It needs a browser: call it from onMount() or an effect, or render the component with ClientOnly().`
117
+ );
118
+ }
119
+ function invalidCharacter(name) {
120
+ const Ctor = globalThis.DOMException;
121
+ const message = `"${name}" did not match the Name production`;
122
+ throw Ctor ? new Ctor(message, "InvalidCharacterError") : new Error(message);
123
+ }
124
+ var NAME_RE = /^[A-Za-z_:][-A-Za-z0-9_.:·À-￿]*$/;
125
+ var ServerNodeList = class extends Array {
126
+ static get [Symbol.species]() {
127
+ return Array;
128
+ }
129
+ item(index) {
130
+ return this[index] ?? null;
131
+ }
132
+ };
133
+ var observations = [];
134
+ function queueRecord(record) {
135
+ if (observations.length === 0) return;
136
+ for (const obs of observations) {
137
+ const o = obs.options;
138
+ const wants = record.type === "childList" ? o.childList : record.type === "attributes" ? o.attributes : o.characterData;
139
+ if (!wants) continue;
140
+ if (obs.target !== record.target && !(o.subtree && obs.target.contains(record.target))) continue;
141
+ obs.observer._enqueue(record);
142
+ }
143
+ }
144
+ var ServerMutationObserver = class {
145
+ constructor(callback) {
146
+ this.callback = callback;
147
+ this.records = [];
148
+ this.scheduled = false;
149
+ }
150
+ observe(target, options = {}) {
151
+ const opts = { ...options };
152
+ if (opts.attributeFilter || opts.attributeOldValue) opts.attributes ?? (opts.attributes = true);
153
+ if (opts.characterDataOldValue) opts.characterData ?? (opts.characterData = true);
154
+ const existing = observations.find((o) => o.observer === this && o.target === target);
155
+ if (existing) existing.options = opts;
156
+ else observations.push({ observer: this, target, options: opts });
157
+ }
158
+ disconnect() {
159
+ for (let i = observations.length - 1; i >= 0; i--) if (observations[i].observer === this) observations.splice(i, 1);
160
+ this.records = [];
161
+ }
162
+ takeRecords() {
163
+ const out = this.records;
164
+ this.records = [];
165
+ return out;
166
+ }
167
+ /** @internal */
168
+ _enqueue(record) {
169
+ this.records.push(record);
170
+ if (this.scheduled) return;
171
+ this.scheduled = true;
172
+ queueMicrotask(() => {
173
+ this.scheduled = false;
174
+ const records = this.takeRecords();
175
+ if (records.length > 0) this.callback(records, this);
176
+ });
177
+ }
178
+ };
179
+ var _ServerNode = class _ServerNode {
180
+ constructor(ownerDocument) {
181
+ this.ownerDocument = ownerDocument;
182
+ /** @internal */
183
+ this._parent = null;
184
+ /** @internal */
185
+ this._prev = null;
186
+ /** @internal */
187
+ this._next = null;
188
+ /** @internal */
189
+ this._first = null;
190
+ /** @internal */
191
+ this._last = null;
192
+ /** @internal */
193
+ this._count = 0;
194
+ /** @internal */
195
+ this._list = null;
196
+ /** @internal */
197
+ this._listeners = null;
198
+ }
199
+ get nodeType() {
200
+ return 0;
201
+ }
202
+ get nodeName() {
203
+ return "";
204
+ }
205
+ get nodeValue() {
206
+ return null;
207
+ }
208
+ set nodeValue(_value) {
209
+ }
210
+ get parentNode() {
211
+ return this._parent;
212
+ }
213
+ get parentElement() {
214
+ return this._parent instanceof ServerElement ? this._parent : null;
215
+ }
216
+ get firstChild() {
217
+ return this._first;
218
+ }
219
+ get lastChild() {
220
+ return this._last;
221
+ }
222
+ get nextSibling() {
223
+ return this._next;
224
+ }
225
+ get previousSibling() {
226
+ return this._prev;
227
+ }
228
+ get childNodes() {
229
+ if (!this._list) {
230
+ const list = new ServerNodeList();
231
+ for (let n = this._first; n; n = n._next) list.push(n);
232
+ this._list = list;
233
+ }
234
+ return this._list;
235
+ }
236
+ hasChildNodes() {
237
+ return this._first !== null;
238
+ }
239
+ get isConnected() {
240
+ let n = this;
241
+ while (n) {
242
+ if (n.nodeType === DOCUMENT_NODE) return true;
243
+ n = n._parent;
244
+ }
245
+ return false;
246
+ }
247
+ getRootNode() {
248
+ let n = this;
249
+ while (n._parent) n = n._parent;
250
+ return n;
251
+ }
252
+ get textContent() {
253
+ let out = "";
254
+ for (let n = this._first; n; n = n._next) {
255
+ if (n.nodeType === TEXT_NODE) out += n.data;
256
+ else if (n.nodeType === ELEMENT_NODE || n.nodeType === DOCUMENT_FRAGMENT_NODE) out += n.textContent ?? "";
257
+ }
258
+ return out;
259
+ }
260
+ set textContent(value) {
261
+ while (this._first) this.removeChild(this._first);
262
+ const text = value == null ? "" : String(value);
263
+ if (text !== "") this.appendChild(new ServerText(this.ownerDocument, text));
264
+ }
265
+ contains(other) {
266
+ for (let n = other; n; n = n._parent) if (n === this) return true;
267
+ return false;
268
+ }
269
+ compareDocumentPosition(other) {
270
+ if (other === this) return 0;
271
+ if (this.getRootNode() !== other.getRootNode()) return 1 | 32;
272
+ if (this.contains(other)) return 16 | 4;
273
+ if (other.contains(this)) return 8 | 2;
274
+ const chain = (n) => {
275
+ const out = [];
276
+ for (let c = n; c; c = c._parent) out.unshift(c);
277
+ return out;
278
+ };
279
+ const a = chain(this);
280
+ const b = chain(other);
281
+ let i = 0;
282
+ while (a[i] === b[i]) i++;
283
+ for (let n = a[i]._next; n; n = n._next) if (n === b[i]) return 4;
284
+ return 2;
285
+ }
286
+ // ── Mutation ──
287
+ /** @internal */
288
+ _assertParentOf(node) {
289
+ if (!(node instanceof _ServerNode))
290
+ throw new TypeError("Failed to execute on Node: parameter is not of type 'Node'.");
291
+ if (node.contains(this)) {
292
+ const Ctor = globalThis.DOMException;
293
+ const message = "The new child element contains the parent.";
294
+ throw Ctor ? new Ctor(message, "HierarchyRequestError") : new Error(message);
295
+ }
296
+ }
297
+ insertBefore(node, ref) {
298
+ if (ref && ref._parent !== this) {
299
+ const Ctor = globalThis.DOMException;
300
+ const message = "The node before which the new node is to be inserted is not a child of this node.";
301
+ throw Ctor ? new Ctor(message, "NotFoundError") : new Error(message);
302
+ }
303
+ if (node.nodeType === DOCUMENT_FRAGMENT_NODE) {
304
+ const moved = [];
305
+ while (node._first) {
306
+ const child = node._first;
307
+ node._unlink(child, true);
308
+ moved.push(child);
309
+ }
310
+ for (const child of moved) this._link(child, ref, true);
311
+ if (moved.length > 0) this._recordChildList(moved, [], moved[0]._prev, ref);
312
+ return node;
313
+ }
314
+ this._assertParentOf(node);
315
+ if (ref === node) ref = node._next;
316
+ if (node._parent) node._parent.removeChild(node);
317
+ this._link(node, ref, false);
318
+ this._recordChildList([node], [], node._prev, node._next);
319
+ return node;
320
+ }
321
+ appendChild(node) {
322
+ return this.insertBefore(node, null);
323
+ }
324
+ removeChild(node) {
325
+ if (node._parent !== this) {
326
+ const Ctor = globalThis.DOMException;
327
+ const message = "The node to be removed is not a child of this node.";
328
+ throw Ctor ? new Ctor(message, "NotFoundError") : new Error(message);
329
+ }
330
+ const prev = node._prev;
331
+ const next = node._next;
332
+ this._unlink(node, false);
333
+ this._recordChildList([], [node], prev, next);
334
+ return node;
335
+ }
336
+ replaceChild(node, old) {
337
+ if (node === old) return old;
338
+ const next = old._next === node ? node._next : old._next;
339
+ this.removeChild(old);
340
+ this.insertBefore(node, next);
341
+ return old;
342
+ }
343
+ /** @internal */
344
+ _link(node, ref, quiet) {
345
+ node._parent = this;
346
+ if (ref) {
347
+ node._prev = ref._prev;
348
+ node._next = ref;
349
+ if (ref._prev) ref._prev._next = node;
350
+ else this._first = node;
351
+ ref._prev = node;
352
+ } else {
353
+ node._prev = this._last;
354
+ node._next = null;
355
+ if (this._last) this._last._next = node;
356
+ else this._first = node;
357
+ this._last = node;
358
+ }
359
+ this._count++;
360
+ this._list = null;
361
+ void quiet;
362
+ }
363
+ /** @internal */
364
+ _unlink(node, quiet) {
365
+ if (node._prev) node._prev._next = node._next;
366
+ else this._first = node._next;
367
+ if (node._next) node._next._prev = node._prev;
368
+ else this._last = node._prev;
369
+ node._parent = null;
370
+ node._prev = null;
371
+ node._next = null;
372
+ this._count--;
373
+ this._list = null;
374
+ void quiet;
375
+ }
376
+ /** @internal */
377
+ _recordChildList(added, removed, prev, next) {
378
+ if (observations.length === 0) return;
379
+ queueRecord({
380
+ type: "childList",
381
+ target: this,
382
+ addedNodes: added,
383
+ removedNodes: removed,
384
+ previousSibling: prev,
385
+ nextSibling: next,
386
+ attributeName: null,
387
+ attributeNamespace: null,
388
+ oldValue: null
389
+ });
390
+ }
391
+ // ── ChildNode / ParentNode ──
392
+ remove() {
393
+ this._parent?.removeChild(this);
394
+ }
395
+ replaceWith(...nodes) {
396
+ const parent = this._parent;
397
+ if (!parent) return;
398
+ const next = this._next;
399
+ parent.removeChild(this);
400
+ for (const n of nodes) parent.insertBefore(toNode(this.ownerDocument, n), next);
401
+ }
402
+ before(...nodes) {
403
+ const parent = this._parent;
404
+ if (!parent) return;
405
+ for (const n of nodes) parent.insertBefore(toNode(this.ownerDocument, n), this);
406
+ }
407
+ after(...nodes) {
408
+ const parent = this._parent;
409
+ if (!parent) return;
410
+ const next = this._next;
411
+ for (const n of nodes) parent.insertBefore(toNode(this.ownerDocument, n), next);
412
+ }
413
+ append(...nodes) {
414
+ for (const n of nodes) this.appendChild(toNode(this.ownerDocument, n));
415
+ }
416
+ prepend(...nodes) {
417
+ const first = this._first;
418
+ for (const n of nodes) this.insertBefore(toNode(this.ownerDocument, n), first);
419
+ }
420
+ replaceChildren(...nodes) {
421
+ while (this._first) this.removeChild(this._first);
422
+ this.append(...nodes);
423
+ }
424
+ get children() {
425
+ const list = new ServerNodeList();
426
+ for (let n = this._first; n; n = n._next) if (n.nodeType === ELEMENT_NODE) list.push(n);
427
+ return list;
428
+ }
429
+ get childElementCount() {
430
+ let c = 0;
431
+ for (let n = this._first; n; n = n._next) if (n.nodeType === ELEMENT_NODE) c++;
432
+ return c;
433
+ }
434
+ get firstElementChild() {
435
+ for (let n = this._first; n; n = n._next) if (n.nodeType === ELEMENT_NODE) return n;
436
+ return null;
437
+ }
438
+ get lastElementChild() {
439
+ for (let n = this._last; n; n = n._prev) if (n.nodeType === ELEMENT_NODE) return n;
440
+ return null;
441
+ }
442
+ get nextElementSibling() {
443
+ for (let n = this._next; n; n = n._next) if (n.nodeType === ELEMENT_NODE) return n;
444
+ return null;
445
+ }
446
+ get previousElementSibling() {
447
+ for (let n = this._prev; n; n = n._prev) if (n.nodeType === ELEMENT_NODE) return n;
448
+ return null;
449
+ }
450
+ querySelector(selector) {
451
+ const sel = compileSelector(selector);
452
+ let found = null;
453
+ walkElements(this, (el) => {
454
+ if (matchesCompiled(el, sel, this)) {
455
+ found = el;
456
+ return true;
457
+ }
458
+ return false;
459
+ });
460
+ return found;
461
+ }
462
+ querySelectorAll(selector) {
463
+ const sel = compileSelector(selector);
464
+ const out = new ServerNodeList();
465
+ walkElements(this, (el) => {
466
+ if (matchesCompiled(el, sel, this)) out.push(el);
467
+ return false;
468
+ });
469
+ return out;
470
+ }
471
+ getElementsByTagName(name) {
472
+ return this.querySelectorAll(name === "*" ? "*" : name);
473
+ }
474
+ getElementsByClassName(names) {
475
+ const selector = names.trim().split(/\s+/).filter(Boolean).map((n) => `.${n}`).join("");
476
+ return selector ? this.querySelectorAll(selector) : new ServerNodeList();
477
+ }
478
+ cloneNode(deep = false) {
479
+ const copy = this._shallowClone();
480
+ if (deep) for (let n = this._first; n; n = n._next) copy.appendChild(n.cloneNode(true));
481
+ return copy;
482
+ }
483
+ /** @internal */
484
+ _shallowClone() {
485
+ return new _ServerNode(this.ownerDocument);
486
+ }
487
+ isEqualNode(other) {
488
+ return !!other && serializeForDebug(this) === serializeForDebug(other);
489
+ }
490
+ isSameNode(other) {
491
+ return other === this;
492
+ }
493
+ normalize() {
494
+ for (let n = this._first; n; ) {
495
+ const next = n._next;
496
+ if (n.nodeType === TEXT_NODE) {
497
+ const text = n;
498
+ if (text.data === "") this.removeChild(n);
499
+ else
500
+ while (text._next && text._next.nodeType === TEXT_NODE) {
501
+ text.data += text._next.data;
502
+ this.removeChild(text._next);
503
+ }
504
+ } else n.normalize();
505
+ n = n._parent === this ? n._next : next;
506
+ }
507
+ }
508
+ // ── EventTarget ──
509
+ addEventListener(type, fn, options) {
510
+ if (!fn) return;
511
+ const capture = typeof options === "boolean" ? options : !!options?.capture;
512
+ const once = typeof options === "object" && !!options?.once;
513
+ const map = this._listeners ?? (this._listeners = /* @__PURE__ */ new Map());
514
+ const list = map.get(type) ?? [];
515
+ if (list.some((l) => l.fn === fn && l.capture === capture)) return;
516
+ list.push({ fn, capture, once });
517
+ map.set(type, list);
518
+ const signal = typeof options === "object" ? options?.signal : void 0;
519
+ signal?.addEventListener("abort", () => this.removeEventListener(type, fn, options), { once: true });
520
+ }
521
+ removeEventListener(type, fn, options) {
522
+ const list = this._listeners?.get(type);
523
+ if (!list || !fn) return;
524
+ const capture = typeof options === "boolean" ? options : !!options?.capture;
525
+ const i = list.findIndex((l) => l.fn === fn && l.capture === capture);
526
+ if (i !== -1) list.splice(i, 1);
527
+ }
528
+ dispatchEvent(event) {
529
+ const ev = event;
530
+ let stopped = false;
531
+ let stoppedNow = false;
532
+ const ownStop = ev.stopPropagation.bind(ev);
533
+ const ownStopNow = ev.stopImmediatePropagation.bind(ev);
534
+ defineOwn(ev, "stopPropagation", () => {
535
+ stopped = true;
536
+ ownStop();
537
+ });
538
+ defineOwn(ev, "stopImmediatePropagation", () => {
539
+ stopped = true;
540
+ stoppedNow = true;
541
+ ownStopNow();
542
+ });
543
+ defineOwn(ev, "target", this);
544
+ const path = [];
545
+ for (let n = this; n; n = n._parent) path.push(n);
546
+ const phase = (node, capture) => {
547
+ const list = node._listeners?.get(ev.type);
548
+ if (!list) return;
549
+ defineOwn(ev, "currentTarget", node);
550
+ for (const l of list.slice()) {
551
+ if (capture !== null && l.capture !== capture) continue;
552
+ if (l.once) node.removeEventListener(ev.type, l.fn, l.capture);
553
+ if (typeof l.fn === "function") l.fn.call(node, event);
554
+ else l.fn.handleEvent(event);
555
+ if (stoppedNow) return;
556
+ }
557
+ };
558
+ for (let i = path.length - 1; i > 0 && !stopped; i--) phase(path[i], true);
559
+ if (!stopped) phase(this, null);
560
+ if (ev.bubbles) for (let i = 1; i < path.length && !stopped; i++) phase(path[i], false);
561
+ defineOwn(ev, "currentTarget", null);
562
+ return !ev.defaultPrevented;
563
+ }
564
+ };
565
+ _ServerNode.ELEMENT_NODE = ELEMENT_NODE;
566
+ _ServerNode.ATTRIBUTE_NODE = ATTRIBUTE_NODE;
567
+ _ServerNode.TEXT_NODE = TEXT_NODE;
568
+ _ServerNode.COMMENT_NODE = COMMENT_NODE;
569
+ _ServerNode.DOCUMENT_NODE = DOCUMENT_NODE;
570
+ _ServerNode.DOCUMENT_FRAGMENT_NODE = DOCUMENT_FRAGMENT_NODE;
571
+ _ServerNode.DOCUMENT_POSITION_DISCONNECTED = 1;
572
+ _ServerNode.DOCUMENT_POSITION_PRECEDING = 2;
573
+ _ServerNode.DOCUMENT_POSITION_FOLLOWING = 4;
574
+ _ServerNode.DOCUMENT_POSITION_CONTAINS = 8;
575
+ _ServerNode.DOCUMENT_POSITION_CONTAINED_BY = 16;
576
+ var ServerNode = _ServerNode;
577
+ function defineOwn(obj, key, value) {
578
+ Object.defineProperty(obj, key, { value, configurable: true, writable: true });
579
+ }
580
+ function toNode(doc, n) {
581
+ return typeof n === "string" ? new ServerText(doc, n) : n;
582
+ }
583
+ function walkElements(root, visit) {
584
+ for (let n = root._first; n; n = n._next) {
585
+ if (n.nodeType === ELEMENT_NODE) {
586
+ if (visit(n)) return true;
587
+ if (walkElements(n, visit)) return true;
588
+ } else if (n.nodeType === DOCUMENT_FRAGMENT_NODE && walkElements(n, visit)) return true;
589
+ }
590
+ return false;
591
+ }
592
+ var ServerCharacterData = class extends ServerNode {
593
+ constructor(doc, data) {
594
+ super(doc);
595
+ this._data = data;
596
+ }
597
+ get data() {
598
+ return this._data;
599
+ }
600
+ set data(value) {
601
+ const old = this._data;
602
+ this._data = value == null ? "" : String(value);
603
+ if (observations.length > 0) {
604
+ queueRecord({
605
+ type: "characterData",
606
+ target: this,
607
+ addedNodes: [],
608
+ removedNodes: [],
609
+ previousSibling: null,
610
+ nextSibling: null,
611
+ attributeName: null,
612
+ attributeNamespace: null,
613
+ oldValue: old
614
+ });
615
+ }
616
+ }
617
+ get length() {
618
+ return this._data.length;
619
+ }
620
+ get nodeValue() {
621
+ return this._data;
622
+ }
623
+ set nodeValue(value) {
624
+ this.data = value ?? "";
625
+ }
626
+ get textContent() {
627
+ return this._data;
628
+ }
629
+ set textContent(value) {
630
+ this.data = value ?? "";
631
+ }
632
+ appendChild(_node) {
633
+ throw new TypeError("This node type does not support this method.");
634
+ }
635
+ insertBefore(_node, _ref) {
636
+ throw new TypeError("This node type does not support this method.");
637
+ }
638
+ };
639
+ var ServerText = class _ServerText extends ServerCharacterData {
640
+ get nodeType() {
641
+ return TEXT_NODE;
642
+ }
643
+ get nodeName() {
644
+ return "#text";
645
+ }
646
+ get wholeText() {
647
+ return this._data;
648
+ }
649
+ splitText(offset) {
650
+ const rest = new _ServerText(this.ownerDocument, this._data.slice(offset));
651
+ this.data = this._data.slice(0, offset);
652
+ this._parent?.insertBefore(rest, this._next);
653
+ return rest;
654
+ }
655
+ _shallowClone() {
656
+ return new _ServerText(this.ownerDocument, this._data);
657
+ }
658
+ };
659
+ var ServerComment = class _ServerComment extends ServerCharacterData {
660
+ get nodeType() {
661
+ return COMMENT_NODE;
662
+ }
663
+ get nodeName() {
664
+ return "#comment";
665
+ }
666
+ _shallowClone() {
667
+ return new _ServerComment(this.ownerDocument, this._data);
668
+ }
669
+ };
670
+ var ServerDocumentFragment = class _ServerDocumentFragment extends ServerNode {
671
+ get nodeType() {
672
+ return DOCUMENT_FRAGMENT_NODE;
673
+ }
674
+ get nodeName() {
675
+ return "#document-fragment";
676
+ }
677
+ getElementById(id) {
678
+ return this.querySelector(`#${cssEscapeIdent(id)}`);
679
+ }
680
+ _shallowClone() {
681
+ return new _ServerDocumentFragment(this.ownerDocument);
682
+ }
683
+ };
684
+ var ServerAttr = class {
685
+ constructor(ownerElement, namespaceURI, prefix, localName, value) {
686
+ this.ownerElement = ownerElement;
687
+ this.namespaceURI = namespaceURI;
688
+ this.prefix = prefix;
689
+ this.localName = localName;
690
+ this.nodeType = ATTRIBUTE_NODE;
691
+ this.specified = true;
692
+ this._value = value;
693
+ }
694
+ get name() {
695
+ return this.prefix ? `${this.prefix}:${this.localName}` : this.localName;
696
+ }
697
+ get nodeName() {
698
+ return this.name;
699
+ }
700
+ get value() {
701
+ return this._value;
702
+ }
703
+ set value(v) {
704
+ if (this.ownerElement) this.ownerElement.setAttributeNS(this.namespaceURI, this.name, v);
705
+ else this._value = String(v);
706
+ }
707
+ get nodeValue() {
708
+ return this._value;
709
+ }
710
+ get textContent() {
711
+ return this._value;
712
+ }
713
+ };
714
+ var ServerNamedNodeMap = class extends Array {
715
+ static get [Symbol.species]() {
716
+ return Array;
717
+ }
718
+ item(index) {
719
+ return this[index] ?? null;
720
+ }
721
+ getNamedItem(name) {
722
+ return this.find((a) => a.name === name) ?? null;
723
+ }
724
+ getNamedItemNS(ns, localName) {
725
+ return this.find((a) => a.namespaceURI === (ns || null) && a.localName === localName) ?? null;
726
+ }
727
+ };
728
+ function splitDeclarations(text) {
729
+ const out = [];
730
+ let depth = 0;
731
+ let quote = "";
732
+ let start = 0;
733
+ for (let i = 0; i < text.length; i++) {
734
+ const c = text[i];
735
+ if (quote) {
736
+ if (c === "\\") i++;
737
+ else if (c === quote) quote = "";
738
+ } else if (c === '"' || c === "'") quote = c;
739
+ else if (c === "(") depth++;
740
+ else if (c === ")") depth = Math.max(0, depth - 1);
741
+ else if (c === ";" && depth === 0) {
742
+ out.push(text.slice(start, i));
743
+ start = i + 1;
744
+ }
745
+ }
746
+ out.push(text.slice(start));
747
+ return out;
748
+ }
749
+ var CAMEL_EXCEPTIONS = { cssFloat: "float" };
750
+ function toKebab(prop) {
751
+ if (prop.startsWith("--")) return prop;
752
+ if (Object.hasOwn(CAMEL_EXCEPTIONS, prop)) return CAMEL_EXCEPTIONS[prop];
753
+ return prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).replace(/^(webkit|moz|ms)-/, "-$1-");
754
+ }
755
+ var ServerStyle = class {
756
+ constructor(el) {
757
+ this.el = el;
758
+ /** @internal */
759
+ this._decls = /* @__PURE__ */ new Map();
760
+ /** @internal */
761
+ this._parsedFrom = null;
762
+ }
763
+ /** @internal */
764
+ _sync() {
765
+ const attr = this.el.getAttribute("style");
766
+ if (attr === this._parsedFrom) return;
767
+ this._decls = /* @__PURE__ */ new Map();
768
+ this._parsedFrom = attr;
769
+ if (!attr) return;
770
+ for (const decl of splitDeclarations(attr)) {
771
+ const colon = decl.indexOf(":");
772
+ if (colon === -1) continue;
773
+ const name = decl.slice(0, colon).trim();
774
+ let value = decl.slice(colon + 1).trim();
775
+ if (!name || !value) continue;
776
+ let priority = "";
777
+ const bang = value.lastIndexOf("!");
778
+ if (bang !== -1 && /^!\s*important$/i.test(value.slice(bang))) {
779
+ priority = "important";
780
+ value = value.slice(0, bang).trim();
781
+ }
782
+ this._decls.set(name.startsWith("--") ? name : name.toLowerCase(), { value, priority });
783
+ }
784
+ }
785
+ /** @internal */
786
+ _commit() {
787
+ const text = this.cssText;
788
+ this._parsedFrom = text === "" ? null : text;
789
+ if (text === "") this.el.removeAttribute("style");
790
+ else this.el.setAttribute("style", text);
791
+ this._parsedFrom = this.el.getAttribute("style");
792
+ }
793
+ get cssText() {
794
+ this._sync();
795
+ const parts = [];
796
+ for (const [name, d] of this._decls) parts.push(`${name}: ${d.value}${d.priority ? " !important" : ""};`);
797
+ return parts.join(" ");
798
+ }
799
+ set cssText(text) {
800
+ this.el.setAttribute("style", String(text ?? ""));
801
+ this._sync();
802
+ if (this._decls.size === 0) this.el.removeAttribute("style");
803
+ else this._commit();
804
+ }
805
+ get length() {
806
+ this._sync();
807
+ return this._decls.size;
808
+ }
809
+ item(index) {
810
+ this._sync();
811
+ return Array.from(this._decls.keys())[index] ?? "";
812
+ }
813
+ getPropertyValue(name) {
814
+ this._sync();
815
+ return this._decls.get(name.startsWith("--") ? name : name.toLowerCase())?.value ?? "";
816
+ }
817
+ getPropertyPriority(name) {
818
+ this._sync();
819
+ return this._decls.get(name.startsWith("--") ? name : name.toLowerCase())?.priority ?? "";
820
+ }
821
+ setProperty(name, value, priority = "") {
822
+ this._sync();
823
+ const key = name.startsWith("--") ? name : name.toLowerCase();
824
+ const v = value == null ? "" : String(value).trim();
825
+ if (v === "") {
826
+ this.removeProperty(key);
827
+ return;
828
+ }
829
+ this._decls.set(key, { value: v, priority: priority === "important" ? "important" : "" });
830
+ this._commit();
831
+ }
832
+ removeProperty(name) {
833
+ this._sync();
834
+ const key = name.startsWith("--") ? name : name.toLowerCase();
835
+ const old = this._decls.get(key)?.value ?? "";
836
+ if (this._decls.delete(key)) this._commit();
837
+ return old;
838
+ }
839
+ *[Symbol.iterator]() {
840
+ this._sync();
841
+ yield* this._decls.keys();
842
+ }
843
+ };
844
+ function styleProxy(style) {
845
+ return new Proxy(style, {
846
+ get(target, key, receiver) {
847
+ if (typeof key === "string" && !(key in target)) {
848
+ if (/^\d+$/.test(key)) return target.item(Number(key));
849
+ return target.getPropertyValue(toKebab(key));
850
+ }
851
+ return Reflect.get(target, key, receiver);
852
+ },
853
+ set(target, key, value, receiver) {
854
+ if (typeof key === "string" && !(key in target)) {
855
+ target.setProperty(toKebab(key), value == null ? "" : String(value));
856
+ return true;
857
+ }
858
+ return Reflect.set(target, key, value, receiver);
859
+ }
860
+ });
861
+ }
862
+ var ServerTokenList = class {
863
+ constructor(el, attr) {
864
+ this.el = el;
865
+ this.attr = attr;
866
+ }
867
+ tokens() {
868
+ return (this.el.getAttribute(this.attr) ?? "").split(/\s+/).filter(Boolean);
869
+ }
870
+ write(tokens) {
871
+ this.el.setAttribute(this.attr, Array.from(new Set(tokens)).join(" "));
872
+ }
873
+ get length() {
874
+ return new Set(this.tokens()).size;
875
+ }
876
+ get value() {
877
+ return this.el.getAttribute(this.attr) ?? "";
878
+ }
879
+ set value(v) {
880
+ this.el.setAttribute(this.attr, v);
881
+ }
882
+ item(i) {
883
+ return Array.from(new Set(this.tokens()))[i] ?? null;
884
+ }
885
+ contains(token) {
886
+ return this.tokens().includes(token);
887
+ }
888
+ add(...tokens) {
889
+ this.write([...this.tokens(), ...tokens]);
890
+ }
891
+ remove(...tokens) {
892
+ this.write(this.tokens().filter((t) => !tokens.includes(t)));
893
+ }
894
+ toggle(token, force) {
895
+ const has = this.contains(token);
896
+ const want = force === void 0 ? !has : force;
897
+ if (want && !has) this.add(token);
898
+ else if (!want && has) this.remove(token);
899
+ return want;
900
+ }
901
+ replace(oldToken, newToken) {
902
+ const tokens = this.tokens();
903
+ const i = tokens.indexOf(oldToken);
904
+ if (i === -1) return false;
905
+ tokens[i] = newToken;
906
+ this.write(tokens);
907
+ return true;
908
+ }
909
+ forEach(fn) {
910
+ Array.from(new Set(this.tokens())).forEach(fn);
911
+ }
912
+ [Symbol.iterator]() {
913
+ return new Set(this.tokens()).values();
914
+ }
915
+ toString() {
916
+ return this.value;
917
+ }
918
+ };
919
+ function datasetKeyToAttr(key) {
920
+ return `data-${key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}`;
921
+ }
922
+ var ServerElement = class _ServerElement extends ServerNode {
923
+ constructor(doc, localName, namespaceURI, prefix = null) {
924
+ super(doc);
925
+ this.localName = localName;
926
+ this.namespaceURI = namespaceURI;
927
+ this.prefix = prefix;
928
+ /** @internal */
929
+ this._attrs = new ServerNamedNodeMap();
930
+ /** @internal */
931
+ this._style = null;
932
+ /** @internal */
933
+ this._classList = null;
934
+ this.scrollTop = 0;
935
+ this.scrollLeft = 0;
936
+ }
937
+ get nodeType() {
938
+ return ELEMENT_NODE;
939
+ }
940
+ get isHtml() {
941
+ return this.namespaceURI === HTML_NS;
942
+ }
943
+ get tagName() {
944
+ const q = this.prefix ? `${this.prefix}:${this.localName}` : this.localName;
945
+ return this.isHtml ? q.toUpperCase() : q;
946
+ }
947
+ get nodeName() {
948
+ return this.tagName;
949
+ }
950
+ get attributes() {
951
+ return this._attrs;
952
+ }
953
+ findAttr(name) {
954
+ const n = this.isHtml ? name.toLowerCase() : name;
955
+ return this._attrs.find((a) => a.name === n);
956
+ }
957
+ getAttribute(name) {
958
+ return this.findAttr(String(name))?.value ?? null;
959
+ }
960
+ getAttributeNames() {
961
+ return this._attrs.map((a) => a.name);
962
+ }
963
+ hasAttribute(name) {
964
+ return this.findAttr(String(name)) !== void 0;
965
+ }
966
+ hasAttributes() {
967
+ return this._attrs.length > 0;
968
+ }
969
+ setAttribute(name, value) {
970
+ name = String(name);
971
+ if (!NAME_RE.test(name)) invalidCharacter(name);
972
+ const v = String(value);
973
+ const existing = this.findAttr(name);
974
+ const old = existing ? existing._value : null;
975
+ if (existing) existing._value = v;
976
+ else this._attrs.push(new ServerAttr(this, null, null, this.isHtml ? name.toLowerCase() : name, v));
977
+ this._recordAttr(this.isHtml ? name.toLowerCase() : name, null, old);
978
+ }
979
+ removeAttribute(name) {
980
+ const attr = this.findAttr(String(name));
981
+ if (!attr) return;
982
+ this._attrs.splice(this._attrs.indexOf(attr), 1);
983
+ this._recordAttr(attr.name, attr.namespaceURI, attr._value);
984
+ }
985
+ toggleAttribute(name, force) {
986
+ const has = this.hasAttribute(name);
987
+ const want = force === void 0 ? !has : force;
988
+ if (want && !has) this.setAttribute(name, "");
989
+ else if (!want && has) this.removeAttribute(name);
990
+ return want;
991
+ }
992
+ getAttributeNS(ns, localName) {
993
+ return this._attrs.getNamedItemNS(ns, localName)?.value ?? null;
994
+ }
995
+ hasAttributeNS(ns, localName) {
996
+ return this._attrs.getNamedItemNS(ns, localName) !== null;
997
+ }
998
+ setAttributeNS(ns, qualifiedName, value) {
999
+ if (!NAME_RE.test(qualifiedName)) invalidCharacter(qualifiedName);
1000
+ const colon = qualifiedName.indexOf(":");
1001
+ const prefix = colon === -1 ? null : qualifiedName.slice(0, colon);
1002
+ const localName = colon === -1 ? qualifiedName : qualifiedName.slice(colon + 1);
1003
+ const namespace = ns || null;
1004
+ if (namespace === null) {
1005
+ this.setAttribute(qualifiedName, value);
1006
+ return;
1007
+ }
1008
+ const existing = this._attrs.getNamedItemNS(namespace, localName);
1009
+ const old = existing ? existing._value : null;
1010
+ if (existing) existing._value = String(value);
1011
+ else this._attrs.push(new ServerAttr(this, namespace, prefix, localName, String(value)));
1012
+ this._recordAttr(localName, namespace, old);
1013
+ }
1014
+ removeAttributeNS(ns, localName) {
1015
+ const attr = this._attrs.getNamedItemNS(ns, localName);
1016
+ if (!attr) return;
1017
+ this._attrs.splice(this._attrs.indexOf(attr), 1);
1018
+ this._recordAttr(localName, attr.namespaceURI, attr._value);
1019
+ }
1020
+ getAttributeNode(name) {
1021
+ return this.findAttr(name) ?? null;
1022
+ }
1023
+ /** @internal */
1024
+ _recordAttr(name, ns, oldValue) {
1025
+ if (observations.length === 0) return;
1026
+ queueRecord({
1027
+ type: "attributes",
1028
+ target: this,
1029
+ addedNodes: [],
1030
+ removedNodes: [],
1031
+ previousSibling: null,
1032
+ nextSibling: null,
1033
+ attributeName: name,
1034
+ attributeNamespace: ns,
1035
+ oldValue
1036
+ });
1037
+ }
1038
+ get id() {
1039
+ return this.getAttribute("id") ?? "";
1040
+ }
1041
+ set id(v) {
1042
+ this.setAttribute("id", v);
1043
+ }
1044
+ get className() {
1045
+ return this.getAttribute("class") ?? "";
1046
+ }
1047
+ set className(v) {
1048
+ this.setAttribute("class", v);
1049
+ }
1050
+ get classList() {
1051
+ this._classList ?? (this._classList = new ServerTokenList(this, "class"));
1052
+ return this._classList;
1053
+ }
1054
+ get style() {
1055
+ this._style ?? (this._style = styleProxy(new ServerStyle(this)));
1056
+ return this._style;
1057
+ }
1058
+ set style(v) {
1059
+ this.style.cssText = v;
1060
+ }
1061
+ get dataset() {
1062
+ return new Proxy(
1063
+ {},
1064
+ {
1065
+ get: (_t, key) => typeof key === "string" ? this.getAttribute(datasetKeyToAttr(key)) ?? void 0 : void 0,
1066
+ set: (_t, key, value) => {
1067
+ if (typeof key === "string") this.setAttribute(datasetKeyToAttr(key), String(value));
1068
+ return true;
1069
+ },
1070
+ deleteProperty: (_t, key) => {
1071
+ if (typeof key === "string") this.removeAttribute(datasetKeyToAttr(key));
1072
+ return true;
1073
+ },
1074
+ has: (_t, key) => typeof key === "string" && this.hasAttribute(datasetKeyToAttr(key)),
1075
+ ownKeys: () => this._attrs.filter((a) => a.name.startsWith("data-")).map((a) => a.name.slice(5).replace(/-([a-z])/g, (_m, c) => c.toUpperCase())),
1076
+ getOwnPropertyDescriptor: (_t, key) => typeof key === "string" && this.hasAttribute(datasetKeyToAttr(key)) ? { enumerable: true, configurable: true, value: this.getAttribute(datasetKeyToAttr(key)) } : void 0
1077
+ }
1078
+ );
1079
+ }
1080
+ get innerHTML() {
1081
+ let out = "";
1082
+ for (let n = this._first; n; n = n._next) out += serializeForDebug(n);
1083
+ return out;
1084
+ }
1085
+ set innerHTML(_value) {
1086
+ unavailable("Element.innerHTML assignment (the server DOM has no HTML parser)");
1087
+ }
1088
+ get outerHTML() {
1089
+ return serializeForDebug(this);
1090
+ }
1091
+ insertAdjacentHTML() {
1092
+ unavailable("Element.insertAdjacentHTML()");
1093
+ }
1094
+ matches(selector) {
1095
+ return matchesCompiled(this, compileSelector(selector), null);
1096
+ }
1097
+ closest(selector) {
1098
+ const sel = compileSelector(selector);
1099
+ for (let n = this; n; n = n._parent) {
1100
+ if (n instanceof _ServerElement && matchesCompiled(n, sel, null)) return n;
1101
+ }
1102
+ return null;
1103
+ }
1104
+ // ── Layout and focus: no-ops on a server ──
1105
+ focus() {
1106
+ }
1107
+ blur() {
1108
+ }
1109
+ click() {
1110
+ const Ctor = globalThis.Event;
1111
+ if (Ctor) this.dispatchEvent(new Ctor("click", { bubbles: true, cancelable: true }));
1112
+ }
1113
+ scrollIntoView() {
1114
+ }
1115
+ scrollTo() {
1116
+ }
1117
+ scrollBy() {
1118
+ }
1119
+ getBoundingClientRect() {
1120
+ return { x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0, toJSON: () => ({}) };
1121
+ }
1122
+ getClientRects() {
1123
+ return [];
1124
+ }
1125
+ get offsetWidth() {
1126
+ return 0;
1127
+ }
1128
+ get offsetHeight() {
1129
+ return 0;
1130
+ }
1131
+ get offsetTop() {
1132
+ return 0;
1133
+ }
1134
+ get offsetLeft() {
1135
+ return 0;
1136
+ }
1137
+ get offsetParent() {
1138
+ return null;
1139
+ }
1140
+ get clientWidth() {
1141
+ return 0;
1142
+ }
1143
+ get clientHeight() {
1144
+ return 0;
1145
+ }
1146
+ get scrollWidth() {
1147
+ return 0;
1148
+ }
1149
+ get scrollHeight() {
1150
+ return 0;
1151
+ }
1152
+ // ── Browser-only APIs: a clear error instead of "is not a function" ──
1153
+ animate() {
1154
+ return unavailable("Element.animate()");
1155
+ }
1156
+ getAnimations() {
1157
+ return unavailable("Element.getAnimations()");
1158
+ }
1159
+ attachShadow() {
1160
+ return unavailable("Element.attachShadow()");
1161
+ }
1162
+ requestFullscreen() {
1163
+ return unavailable("Element.requestFullscreen()");
1164
+ }
1165
+ requestPointerLock() {
1166
+ return unavailable("Element.requestPointerLock()");
1167
+ }
1168
+ setPointerCapture() {
1169
+ return unavailable("Element.setPointerCapture()");
1170
+ }
1171
+ _shallowClone() {
1172
+ const copy = this.ownerDocument ? this.ownerDocument.createElementNS(
1173
+ this.namespaceURI,
1174
+ this.prefix ? `${this.prefix}:${this.localName}` : this.localName
1175
+ ) : new _ServerElement(null, this.localName, this.namespaceURI, this.prefix);
1176
+ for (const a of this._attrs)
1177
+ copy._attrs.push(new ServerAttr(copy, a.namespaceURI, a.prefix, a.localName, a._value));
1178
+ return copy;
1179
+ }
1180
+ };
1181
+ var ServerHTMLElement = class extends ServerElement {
1182
+ get hidden() {
1183
+ return this.hasAttribute("hidden");
1184
+ }
1185
+ set hidden(v) {
1186
+ this.toggleAttribute("hidden", !!v);
1187
+ }
1188
+ get title() {
1189
+ return this.getAttribute("title") ?? "";
1190
+ }
1191
+ set title(v) {
1192
+ this.setAttribute("title", v);
1193
+ }
1194
+ get lang() {
1195
+ return this.getAttribute("lang") ?? "";
1196
+ }
1197
+ set lang(v) {
1198
+ this.setAttribute("lang", v);
1199
+ }
1200
+ get dir() {
1201
+ return this.getAttribute("dir") ?? "";
1202
+ }
1203
+ set dir(v) {
1204
+ this.setAttribute("dir", v);
1205
+ }
1206
+ get tabIndex() {
1207
+ const v = Number.parseInt(this.getAttribute("tabindex") ?? "", 10);
1208
+ return Number.isNaN(v) ? -1 : v;
1209
+ }
1210
+ set tabIndex(v) {
1211
+ this.setAttribute("tabindex", String(v));
1212
+ }
1213
+ get innerText() {
1214
+ return this.textContent ?? "";
1215
+ }
1216
+ set innerText(v) {
1217
+ this.textContent = v;
1218
+ }
1219
+ };
1220
+ function reflectDisabled(proto) {
1221
+ Object.defineProperty(proto, "disabled", {
1222
+ get() {
1223
+ return this.hasAttribute("disabled");
1224
+ },
1225
+ set(v) {
1226
+ this.toggleAttribute("disabled", !!v);
1227
+ },
1228
+ configurable: true
1229
+ });
1230
+ }
1231
+ var ServerInputElement = class extends ServerHTMLElement {
1232
+ constructor() {
1233
+ super(...arguments);
1234
+ /** @internal */
1235
+ this._value = null;
1236
+ /** @internal */
1237
+ this._checked = null;
1238
+ }
1239
+ get value() {
1240
+ return this._value ?? this.getAttribute("value") ?? "";
1241
+ }
1242
+ set value(v) {
1243
+ this._value = v == null ? "" : String(v);
1244
+ }
1245
+ get defaultValue() {
1246
+ return this.getAttribute("value") ?? "";
1247
+ }
1248
+ set defaultValue(v) {
1249
+ this.setAttribute("value", v);
1250
+ }
1251
+ get checked() {
1252
+ return this._checked ?? this.hasAttribute("checked");
1253
+ }
1254
+ set checked(v) {
1255
+ this._checked = !!v;
1256
+ }
1257
+ get defaultChecked() {
1258
+ return this.hasAttribute("checked");
1259
+ }
1260
+ get type() {
1261
+ return (this.getAttribute("type") ?? "text").toLowerCase();
1262
+ }
1263
+ set type(v) {
1264
+ this.setAttribute("type", v);
1265
+ }
1266
+ get name() {
1267
+ return this.getAttribute("name") ?? "";
1268
+ }
1269
+ set name(v) {
1270
+ this.setAttribute("name", v);
1271
+ }
1272
+ select() {
1273
+ }
1274
+ setSelectionRange() {
1275
+ }
1276
+ checkValidity() {
1277
+ return true;
1278
+ }
1279
+ reportValidity() {
1280
+ return true;
1281
+ }
1282
+ };
1283
+ reflectDisabled(ServerInputElement.prototype);
1284
+ var ServerTextAreaElement = class extends ServerHTMLElement {
1285
+ constructor() {
1286
+ super(...arguments);
1287
+ /** @internal */
1288
+ this._value = null;
1289
+ }
1290
+ get value() {
1291
+ return this._value ?? this.textContent ?? "";
1292
+ }
1293
+ set value(v) {
1294
+ this._value = v == null ? "" : String(v);
1295
+ }
1296
+ get defaultValue() {
1297
+ return this.textContent ?? "";
1298
+ }
1299
+ set defaultValue(v) {
1300
+ this.textContent = v;
1301
+ }
1302
+ get name() {
1303
+ return this.getAttribute("name") ?? "";
1304
+ }
1305
+ set name(v) {
1306
+ this.setAttribute("name", v);
1307
+ }
1308
+ select() {
1309
+ }
1310
+ setSelectionRange() {
1311
+ }
1312
+ };
1313
+ reflectDisabled(ServerTextAreaElement.prototype);
1314
+ var ServerOptionElement = class extends ServerHTMLElement {
1315
+ constructor() {
1316
+ super(...arguments);
1317
+ /** @internal */
1318
+ this._selected = null;
1319
+ }
1320
+ get value() {
1321
+ return this.getAttribute("value") ?? this.text;
1322
+ }
1323
+ set value(v) {
1324
+ this.setAttribute("value", v);
1325
+ }
1326
+ get text() {
1327
+ return (this.textContent ?? "").replace(/\s+/g, " ").trim();
1328
+ }
1329
+ set text(v) {
1330
+ this.textContent = v;
1331
+ }
1332
+ get label() {
1333
+ return this.getAttribute("label") ?? this.text;
1334
+ }
1335
+ get selected() {
1336
+ return this._selected ?? this.hasAttribute("selected");
1337
+ }
1338
+ set selected(v) {
1339
+ this._selected = !!v;
1340
+ }
1341
+ get defaultSelected() {
1342
+ return this.hasAttribute("selected");
1343
+ }
1344
+ };
1345
+ reflectDisabled(ServerOptionElement.prototype);
1346
+ var ServerSelectElement = class extends ServerHTMLElement {
1347
+ get options() {
1348
+ return this.querySelectorAll("option");
1349
+ }
1350
+ get selectedIndex() {
1351
+ const opts = this.options;
1352
+ for (let i = 0; i < opts.length; i++) if (opts[i].selected) return i;
1353
+ return opts.length > 0 && !this.hasAttribute("multiple") ? 0 : -1;
1354
+ }
1355
+ set selectedIndex(i) {
1356
+ this.options.forEach((o, j) => {
1357
+ o.selected = j === i;
1358
+ });
1359
+ }
1360
+ get value() {
1361
+ const i = this.selectedIndex;
1362
+ return i === -1 ? "" : this.options[i].value;
1363
+ }
1364
+ set value(v) {
1365
+ this.options.forEach((o) => {
1366
+ o.selected = o.value === String(v);
1367
+ });
1368
+ }
1369
+ get name() {
1370
+ return this.getAttribute("name") ?? "";
1371
+ }
1372
+ set name(v) {
1373
+ this.setAttribute("name", v);
1374
+ }
1375
+ };
1376
+ reflectDisabled(ServerSelectElement.prototype);
1377
+ var ServerButtonElement = class extends ServerHTMLElement {
1378
+ get type() {
1379
+ return (this.getAttribute("type") ?? "submit").toLowerCase();
1380
+ }
1381
+ set type(v) {
1382
+ this.setAttribute("type", v);
1383
+ }
1384
+ get value() {
1385
+ return this.getAttribute("value") ?? "";
1386
+ }
1387
+ set value(v) {
1388
+ this.setAttribute("value", v);
1389
+ }
1390
+ };
1391
+ reflectDisabled(ServerButtonElement.prototype);
1392
+ var ServerDisableableElement = class extends ServerHTMLElement {
1393
+ };
1394
+ reflectDisabled(ServerDisableableElement.prototype);
1395
+ var ServerCanvasElement = class extends ServerHTMLElement {
1396
+ get width() {
1397
+ return Number(this.getAttribute("width") ?? 300);
1398
+ }
1399
+ set width(v) {
1400
+ this.setAttribute("width", String(v));
1401
+ }
1402
+ get height() {
1403
+ return Number(this.getAttribute("height") ?? 150);
1404
+ }
1405
+ set height(v) {
1406
+ this.setAttribute("height", String(v));
1407
+ }
1408
+ /** No drawing context on a server: warns and returns `null`, as a browser does for an unsupported context. */
1409
+ getContext() {
1410
+ reportBrowserApi("HTMLCanvasElement.getContext()");
1411
+ return null;
1412
+ }
1413
+ toDataURL() {
1414
+ return unavailable("HTMLCanvasElement.toDataURL()");
1415
+ }
1416
+ toBlob() {
1417
+ return unavailable("HTMLCanvasElement.toBlob()");
1418
+ }
1419
+ };
1420
+ var ServerDialogElement = class extends ServerHTMLElement {
1421
+ get open() {
1422
+ return this.hasAttribute("open");
1423
+ }
1424
+ set open(v) {
1425
+ this.toggleAttribute("open", !!v);
1426
+ }
1427
+ showModal() {
1428
+ return unavailable("HTMLDialogElement.showModal()");
1429
+ }
1430
+ show() {
1431
+ this.open = true;
1432
+ }
1433
+ close() {
1434
+ this.open = false;
1435
+ }
1436
+ };
1437
+ var ServerMediaElement = class extends ServerHTMLElement {
1438
+ play() {
1439
+ return unavailable("HTMLMediaElement.play()");
1440
+ }
1441
+ pause() {
1442
+ }
1443
+ load() {
1444
+ }
1445
+ };
1446
+ var ServerTemplateElement = class extends ServerHTMLElement {
1447
+ constructor() {
1448
+ super(...arguments);
1449
+ /** @internal */
1450
+ this._content = null;
1451
+ }
1452
+ get content() {
1453
+ this._content ?? (this._content = new ServerDocumentFragment(this.ownerDocument));
1454
+ return this._content;
1455
+ }
1456
+ };
1457
+ var ServerSVGElement = class extends ServerElement {
1458
+ };
1459
+ var ServerMathMLElement = class extends ServerElement {
1460
+ };
1461
+ var HTML_CLASSES = {
1462
+ input: ServerInputElement,
1463
+ textarea: ServerTextAreaElement,
1464
+ select: ServerSelectElement,
1465
+ option: ServerOptionElement,
1466
+ button: ServerButtonElement,
1467
+ fieldset: ServerDisableableElement,
1468
+ optgroup: ServerDisableableElement,
1469
+ canvas: ServerCanvasElement,
1470
+ dialog: ServerDialogElement,
1471
+ video: ServerMediaElement,
1472
+ audio: ServerMediaElement,
1473
+ template: ServerTemplateElement
1474
+ };
1475
+ var NODE_FILTER = {
1476
+ FILTER_ACCEPT: 1,
1477
+ FILTER_REJECT: 2,
1478
+ FILTER_SKIP: 3,
1479
+ SHOW_ALL: 4294967295,
1480
+ SHOW_ELEMENT: 1,
1481
+ SHOW_ATTRIBUTE: 2,
1482
+ SHOW_TEXT: 4,
1483
+ SHOW_COMMENT: 128,
1484
+ SHOW_DOCUMENT: 256,
1485
+ SHOW_DOCUMENT_FRAGMENT: 1024
1486
+ };
1487
+ var ServerTreeWalker = class {
1488
+ constructor(root, whatToShow, filter) {
1489
+ this.root = root;
1490
+ this.whatToShow = whatToShow;
1491
+ this.filter = filter;
1492
+ this.currentNode = root;
1493
+ }
1494
+ accept(node) {
1495
+ if (!(1 << node.nodeType - 1 & this.whatToShow)) return NODE_FILTER.FILTER_SKIP;
1496
+ if (!this.filter) return NODE_FILTER.FILTER_ACCEPT;
1497
+ return typeof this.filter === "function" ? this.filter(node) : this.filter.acceptNode(node);
1498
+ }
1499
+ nextNode() {
1500
+ let node = this.currentNode;
1501
+ for (; ; ) {
1502
+ let next = null;
1503
+ if (node._first) next = node._first;
1504
+ else {
1505
+ let n = node;
1506
+ while (n && n !== this.root && !n._next) n = n._parent;
1507
+ next = n && n !== this.root ? n._next : null;
1508
+ }
1509
+ if (!next) return null;
1510
+ node = next;
1511
+ if (this.accept(node) === NODE_FILTER.FILTER_ACCEPT) {
1512
+ this.currentNode = node;
1513
+ return node;
1514
+ }
1515
+ }
1516
+ }
1517
+ firstChild() {
1518
+ for (let n = this.currentNode._first; n; n = n._next) {
1519
+ if (this.accept(n) === NODE_FILTER.FILTER_ACCEPT) {
1520
+ this.currentNode = n;
1521
+ return n;
1522
+ }
1523
+ }
1524
+ return null;
1525
+ }
1526
+ nextSibling() {
1527
+ for (let n = this.currentNode._next; n; n = n._next) {
1528
+ if (this.accept(n) === NODE_FILTER.FILTER_ACCEPT) {
1529
+ this.currentNode = n;
1530
+ return n;
1531
+ }
1532
+ }
1533
+ return null;
1534
+ }
1535
+ parentNode() {
1536
+ const p = this.currentNode === this.root ? null : this.currentNode._parent;
1537
+ if (p) this.currentNode = p;
1538
+ return p;
1539
+ }
1540
+ };
1541
+ var ServerDocument = class extends ServerNode {
1542
+ constructor() {
1543
+ super(null);
1544
+ this.defaultView = null;
1545
+ this.readyState = "complete";
1546
+ this.contentType = "text/html";
1547
+ this.characterSet = "UTF-8";
1548
+ this.compatMode = "CSS1Compat";
1549
+ this.visibilityState = "visible";
1550
+ this.hidden = false;
1551
+ this.cookie = "";
1552
+ this.ownerDocument = null;
1553
+ this.documentElement = this.createElement("html");
1554
+ this.head = this.createElement("head");
1555
+ this.body = this.createElement("body");
1556
+ this.documentElement.appendChild(this.head);
1557
+ this.documentElement.appendChild(this.body);
1558
+ this.appendChild(this.documentElement);
1559
+ }
1560
+ get nodeType() {
1561
+ return DOCUMENT_NODE;
1562
+ }
1563
+ get nodeName() {
1564
+ return "#document";
1565
+ }
1566
+ get activeElement() {
1567
+ return this.body;
1568
+ }
1569
+ get title() {
1570
+ return this.head.querySelector("title")?.textContent ?? "";
1571
+ }
1572
+ set title(v) {
1573
+ let el = this.head.querySelector("title");
1574
+ if (!el) {
1575
+ el = this.createElement("title");
1576
+ this.head.appendChild(el);
1577
+ }
1578
+ el.textContent = v;
1579
+ }
1580
+ /** Font loading does not exist on a server: recorded as a browser-only read, answers `undefined`. */
1581
+ get fonts() {
1582
+ reportBrowserApi("document.fonts");
1583
+ return void 0;
1584
+ }
1585
+ createElement(name) {
1586
+ name = String(name);
1587
+ if (!NAME_RE.test(name)) invalidCharacter(name);
1588
+ const local = name.toLowerCase();
1589
+ const Ctor = Object.hasOwn(HTML_CLASSES, local) ? HTML_CLASSES[local] : ServerHTMLElement;
1590
+ return new Ctor(this, local, HTML_NS);
1591
+ }
1592
+ createElementNS(ns, qualifiedName) {
1593
+ if (!NAME_RE.test(qualifiedName)) invalidCharacter(qualifiedName);
1594
+ const namespace = ns || null;
1595
+ if (namespace === HTML_NS) return this.createElement(qualifiedName);
1596
+ const colon = qualifiedName.indexOf(":");
1597
+ const prefix = colon === -1 ? null : qualifiedName.slice(0, colon);
1598
+ const local = colon === -1 ? qualifiedName : qualifiedName.slice(colon + 1);
1599
+ if (namespace === SVG_NS) return new ServerSVGElement(this, local, namespace, prefix);
1600
+ if (namespace === MATHML_NS) return new ServerMathMLElement(this, local, namespace, prefix);
1601
+ return new ServerElement(this, local, namespace, prefix);
1602
+ }
1603
+ createTextNode(data) {
1604
+ return new ServerText(this, String(data));
1605
+ }
1606
+ createComment(data) {
1607
+ return new ServerComment(this, String(data));
1608
+ }
1609
+ createDocumentFragment() {
1610
+ return new ServerDocumentFragment(this);
1611
+ }
1612
+ createTreeWalker(root, whatToShow = NODE_FILTER.SHOW_ALL, filter = null) {
1613
+ return new ServerTreeWalker(root, whatToShow, filter);
1614
+ }
1615
+ createEvent() {
1616
+ return unavailable("document.createEvent() (construct `new Event(type)` instead)");
1617
+ }
1618
+ getElementById(id) {
1619
+ return this.querySelector(`#${cssEscapeIdent(id)}`);
1620
+ }
1621
+ hasFocus() {
1622
+ return false;
1623
+ }
1624
+ getSelection() {
1625
+ return null;
1626
+ }
1627
+ elementFromPoint() {
1628
+ return null;
1629
+ }
1630
+ execCommand() {
1631
+ return unavailable("document.execCommand()");
1632
+ }
1633
+ };
1634
+ var selectorCache = /* @__PURE__ */ new Map();
1635
+ function cssEscapeIdent(value) {
1636
+ return value.replace(/([^A-Za-z0-9_-])/g, "\\$1");
1637
+ }
1638
+ function unescapeIdent(value) {
1639
+ return value.replace(/\\(.)/g, "$1");
1640
+ }
1641
+ function compileSelector(selector) {
1642
+ const cached = selectorCache.get(selector);
1643
+ if (cached) return cached;
1644
+ const groups = [];
1645
+ for (const part of splitTopLevel(selector, ",")) {
1646
+ const text = part.trim();
1647
+ if (!text) throw syntaxError(selector);
1648
+ const tokens = text.match(/(?:\\.|\[[^\]]*\]|[^\s>])+|>/g) ?? [];
1649
+ const compounds = [];
1650
+ const combinators = [];
1651
+ let pending = " ";
1652
+ let scoped = false;
1653
+ for (const token of tokens) {
1654
+ if (token === ">") {
1655
+ pending = ">";
1656
+ continue;
1657
+ }
1658
+ if (token === ":scope") {
1659
+ scoped = true;
1660
+ pending = " ";
1661
+ continue;
1662
+ }
1663
+ if (compounds.length > 0) combinators.unshift(pending);
1664
+ compounds.unshift(parseCompound(token, selector));
1665
+ pending = " ";
1666
+ }
1667
+ if (compounds.length === 0) throw syntaxError(selector);
1668
+ groups.push({ compounds, combinators, scoped });
1669
+ }
1670
+ if (selectorCache.size > 500) selectorCache.clear();
1671
+ selectorCache.set(selector, groups);
1672
+ return groups;
1673
+ }
1674
+ function splitTopLevel(text, sep) {
1675
+ const out = [];
1676
+ let depth = 0;
1677
+ let quote = "";
1678
+ let start = 0;
1679
+ for (let i = 0; i < text.length; i++) {
1680
+ const c = text[i];
1681
+ if (quote) {
1682
+ if (c === "\\") i++;
1683
+ else if (c === quote) quote = "";
1684
+ } else if (c === '"' || c === "'") quote = c;
1685
+ else if (c === "\\") i++;
1686
+ else if (c === "[" || c === "(") depth++;
1687
+ else if (c === "]" || c === ")") depth--;
1688
+ else if (c === sep && depth === 0) {
1689
+ out.push(text.slice(start, i));
1690
+ start = i + 1;
1691
+ }
1692
+ }
1693
+ out.push(text.slice(start));
1694
+ return out;
1695
+ }
1696
+ function syntaxError(selector) {
1697
+ const Ctor = globalThis.DOMException;
1698
+ const message = `'${selector}' is not a valid selector (the SibuJS server DOM supports tag, #id, .class, [attr], [attr=value], descendant and > combinators)`;
1699
+ return Ctor ? new Ctor(message, "SyntaxError") : new Error(message);
1700
+ }
1701
+ function parseCompound(token, selector) {
1702
+ const c = { tag: null, id: null, classes: [], attrs: [] };
1703
+ const re = /(\\.|[^#.[\\])+|#((?:\\.|[^#.[\\])+)|\.((?:\\.|[^#.[\\])+)|\[([^\]]*)\]/gy;
1704
+ let consumed = 0;
1705
+ for (let m = re.exec(token); m; m = re.exec(token)) {
1706
+ consumed = re.lastIndex;
1707
+ if (m[2] !== void 0) c.id = unescapeIdent(m[2]);
1708
+ else if (m[3] !== void 0) c.classes.push(unescapeIdent(m[3]));
1709
+ else if (m[4] !== void 0) {
1710
+ const am = /^\s*([^\s~|^$*=]+)\s*(?:([~|^$*]?=)\s*(?:"((?:\\.|[^"])*)"|'((?:\\.|[^'])*)'|([^\s"']+)))?\s*$/.exec(
1711
+ m[4]
1712
+ );
1713
+ if (!am) throw syntaxError(selector);
1714
+ c.attrs.push({
1715
+ name: am[1].toLowerCase(),
1716
+ op: am[2] ?? null,
1717
+ value: unescapeIdent(am[3] ?? am[4] ?? am[5] ?? "")
1718
+ });
1719
+ } else {
1720
+ const t = m[0];
1721
+ if (t.startsWith(":")) throw syntaxError(selector);
1722
+ c.tag = t === "*" ? null : unescapeIdent(t);
1723
+ }
1724
+ if (re.lastIndex === token.length) break;
1725
+ }
1726
+ if (consumed !== token.length) throw syntaxError(selector);
1727
+ return c;
1728
+ }
1729
+ function matchesCompound(el, c) {
1730
+ if (c.tag !== null) {
1731
+ const isHtml = el.namespaceURI === HTML_NS;
1732
+ if (isHtml ? el.localName !== c.tag.toLowerCase() : el.localName !== c.tag) return false;
1733
+ }
1734
+ if (c.id !== null && el.getAttribute("id") !== c.id) return false;
1735
+ if (c.classes.length > 0) {
1736
+ const tokens = (el.getAttribute("class") ?? "").split(/\s+/);
1737
+ for (const cls of c.classes) if (!tokens.includes(cls)) return false;
1738
+ }
1739
+ for (const a of c.attrs) {
1740
+ const v = el.getAttribute(a.name);
1741
+ if (v === null) return false;
1742
+ if (a.op === null) continue;
1743
+ if (a.op === "=" && v !== a.value) return false;
1744
+ if (a.op === "~=" && !v.split(/\s+/).includes(a.value)) return false;
1745
+ if (a.op === "|=" && v !== a.value && !v.startsWith(`${a.value}-`)) return false;
1746
+ if (a.op === "^=" && (!a.value || !v.startsWith(a.value))) return false;
1747
+ if (a.op === "$=" && (!a.value || !v.endsWith(a.value))) return false;
1748
+ if (a.op === "*=" && (!a.value || !v.includes(a.value))) return false;
1749
+ }
1750
+ return true;
1751
+ }
1752
+ function matchesCompiled(el, groups, scope) {
1753
+ for (const g of groups) if (matchesComplex(el, g, 0, scope)) return true;
1754
+ return false;
1755
+ }
1756
+ function matchesComplex(el, g, i, scope) {
1757
+ if (!matchesCompound(el, g.compounds[i])) return false;
1758
+ if (i === g.compounds.length - 1) {
1759
+ if (!g.scoped || !scope) return true;
1760
+ return el._parent === scope || (g.combinators.length === 0 ? false : scope.contains(el));
1761
+ }
1762
+ const comb = g.combinators[i];
1763
+ for (let p = el._parent; p && p instanceof ServerElement; p = p._parent) {
1764
+ if (scope && p === scope && g.scoped) return false;
1765
+ if (matchesComplex(p, g, i + 1, scope)) return true;
1766
+ if (comb === ">") return false;
1767
+ }
1768
+ return false;
1769
+ }
1770
+ var VOID = /* @__PURE__ */ new Set([
1771
+ "area",
1772
+ "base",
1773
+ "br",
1774
+ "col",
1775
+ "embed",
1776
+ "hr",
1777
+ "img",
1778
+ "input",
1779
+ "link",
1780
+ "meta",
1781
+ "source",
1782
+ "track",
1783
+ "wbr"
1784
+ ]);
1785
+ function escapeText(s) {
1786
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1787
+ }
1788
+ function serializeForDebug(node) {
1789
+ if (node.nodeType === TEXT_NODE) return escapeText(node.data);
1790
+ if (node.nodeType === COMMENT_NODE) return `<!--${node.data}-->`;
1791
+ if (node.nodeType !== ELEMENT_NODE) {
1792
+ let out2 = "";
1793
+ for (let n = node._first; n; n = n._next) out2 += serializeForDebug(n);
1794
+ return out2;
1795
+ }
1796
+ const el = node;
1797
+ const tag = el.prefix ? `${el.prefix}:${el.localName}` : el.localName;
1798
+ let out = `<${tag}`;
1799
+ for (const a of el._attrs) out += ` ${a.name}="${escapeText(a._value).replace(/"/g, "&quot;")}"`;
1800
+ out += ">";
1801
+ if (el.namespaceURI === HTML_NS && VOID.has(el.localName)) return out;
1802
+ for (let n = el._first; n; n = n._next) out += serializeForDebug(n);
1803
+ return `${out}</${tag}>`;
1804
+ }
1805
+ function createServerDocument() {
1806
+ return new ServerDocument();
1807
+ }
1808
+ var INSTALLED = /* @__PURE__ */ Symbol.for("sibujs.serverDom.v1");
1809
+ function isServerDom() {
1810
+ return typeof document !== "undefined" && document instanceof ServerDocument;
1811
+ }
1812
+ function installServerDom(options = {}) {
1813
+ const g = globalThis;
1814
+ if (typeof g.document !== "undefined" && !options.force) return () => {
1815
+ };
1816
+ const globals = {
1817
+ document: new ServerDocument(),
1818
+ Node: ServerNode,
1819
+ Element: ServerElement,
1820
+ HTMLElement: ServerHTMLElement,
1821
+ SVGElement: ServerSVGElement,
1822
+ MathMLElement: ServerMathMLElement,
1823
+ HTMLInputElement: ServerInputElement,
1824
+ HTMLTextAreaElement: ServerTextAreaElement,
1825
+ HTMLSelectElement: ServerSelectElement,
1826
+ HTMLOptionElement: ServerOptionElement,
1827
+ HTMLButtonElement: ServerButtonElement,
1828
+ HTMLCanvasElement: ServerCanvasElement,
1829
+ HTMLDialogElement: ServerDialogElement,
1830
+ HTMLTemplateElement: ServerTemplateElement,
1831
+ Text: ServerText,
1832
+ Comment: ServerComment,
1833
+ CharacterData: ServerCharacterData,
1834
+ DocumentFragment: ServerDocumentFragment,
1835
+ Document: ServerDocument,
1836
+ Attr: ServerAttr,
1837
+ MutationObserver: ServerMutationObserver,
1838
+ NodeFilter: NODE_FILTER
1839
+ };
1840
+ const previous = /* @__PURE__ */ new Map();
1841
+ for (const [key, value] of Object.entries(globals)) {
1842
+ previous.set(key, Object.getOwnPropertyDescriptor(g, key));
1843
+ Object.defineProperty(g, key, { value, configurable: true, writable: true, enumerable: false });
1844
+ }
1845
+ g[INSTALLED] = true;
1846
+ return () => {
1847
+ for (const [key, desc] of previous) {
1848
+ if (desc) Object.defineProperty(g, key, desc);
1849
+ else delete g[key];
1850
+ }
1851
+ delete g[INSTALLED];
1852
+ };
1853
+ }
1854
+ // Annotate the CommonJS export names for ESM import in node:
1855
+ 0 && (module.exports = {
1856
+ ServerDocument,
1857
+ ServerElement,
1858
+ ServerNode,
1859
+ createServerDocument,
1860
+ installServerDom,
1861
+ isServerDom
1862
+ });