@zeus-js/runtime-dom 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,891 @@
1
+ /**
2
+ * runtime-dom v0.0.2
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ import { effect, getCurrentScope, onScopeDispose, scope, state, stop } from "@zeus-js/signal";
7
+ //#region packages/runtime-dom/src/template.ts
8
+ function template(html, _isImportNode = false, _isSVG = false, _isMathML = false) {
9
+ const t = document.createElement("template");
10
+ t.innerHTML = html;
11
+ return function clone() {
12
+ return t.content.cloneNode(true);
13
+ };
14
+ }
15
+ //#endregion
16
+ //#region packages/runtime-dom/src/hostContext.ts
17
+ let currentHostContext;
18
+ function getCurrentHostContext() {
19
+ return currentHostContext;
20
+ }
21
+ function withHostContext(context, fn) {
22
+ const previous = currentHostContext;
23
+ currentHostContext = context;
24
+ try {
25
+ return fn();
26
+ } finally {
27
+ currentHostContext = previous;
28
+ }
29
+ }
30
+ function captureCurrentHostContext() {
31
+ return currentHostContext;
32
+ }
33
+ function withCapturedHostContext(fn) {
34
+ const context = captureCurrentHostContext();
35
+ return ((...args) => {
36
+ return withHostContext(context, () => fn(...args));
37
+ });
38
+ }
39
+ //#endregion
40
+ //#region packages/runtime-dom/src/range.ts
41
+ var DynamicRange = class {
42
+ constructor(parent, marker) {
43
+ this.parent = parent;
44
+ this.marker = marker;
45
+ this.nodes = [];
46
+ }
47
+ replace(value) {
48
+ this.clear();
49
+ this.nodes = insertTracked(this.parent, value, this.marker);
50
+ }
51
+ clear() {
52
+ for (const node of this.nodes) {
53
+ var _node$parentNode;
54
+ (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || _node$parentNode.removeChild(node);
55
+ }
56
+ this.nodes = [];
57
+ }
58
+ current() {
59
+ return this.nodes;
60
+ }
61
+ };
62
+ function insertTracked(parent, value, marker) {
63
+ if (value === void 0 || value == null || value === false || value === true) return [];
64
+ if (Array.isArray(value)) {
65
+ const nodes = [];
66
+ for (const item of value) nodes.push(...insertTracked(parent, item, marker));
67
+ return nodes;
68
+ }
69
+ const node = value instanceof Node ? value : document.createTextNode(String(value));
70
+ parent.insertBefore(node, marker);
71
+ return [node];
72
+ }
73
+ function removeNodes$1(nodes) {
74
+ for (const node of nodes) {
75
+ var _node$parentNode2;
76
+ (_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 || _node$parentNode2.removeChild(node);
77
+ }
78
+ }
79
+ function moveRangeBefore(nodes, parent, marker) {
80
+ for (const node of nodes) parent.insertBefore(node, marker);
81
+ }
82
+ //#endregion
83
+ //#region packages/runtime-dom/src/insert.ts
84
+ function insert(parent, value, marker = null) {
85
+ if (value === void 0) {
86
+ console.warn("[Zeus runtime] insert received `undefined`, which is ignored. Use `null` or a fallback value explicitly if you want to suppress this warning.");
87
+ return;
88
+ }
89
+ insertTracked(parent, value, marker);
90
+ }
91
+ function mountDynamic(parent, marker, value) {
92
+ const range = new DynamicRange(parent, marker);
93
+ const hostContext = captureCurrentHostContext();
94
+ const owner = getCurrentOwner();
95
+ const runner = effect(() => {
96
+ const next = runWithOwner(owner, () => withHostContext(hostContext, value));
97
+ range.replace(next);
98
+ });
99
+ onScopeDispose(() => {
100
+ stop(runner);
101
+ range.clear();
102
+ }, true);
103
+ }
104
+ //#endregion
105
+ //#region packages/runtime-dom/src/context.ts
106
+ let currentOwner;
107
+ function getCurrentOwner() {
108
+ return currentOwner;
109
+ }
110
+ function createOwner(parent = currentOwner) {
111
+ return {
112
+ parent,
113
+ provides: /* @__PURE__ */ new Map()
114
+ };
115
+ }
116
+ function runWithOwner(owner, fn) {
117
+ const previous = currentOwner;
118
+ currentOwner = owner;
119
+ try {
120
+ return fn();
121
+ } finally {
122
+ currentOwner = previous;
123
+ }
124
+ }
125
+ function createContext(defaultValue) {
126
+ const hasDefaultValue = arguments.length > 0;
127
+ const context = {
128
+ id: Symbol("ZeusContext"),
129
+ defaultValue,
130
+ hasDefaultValue,
131
+ Provider(props) {
132
+ const owner = createOwner(currentOwner);
133
+ owner.provides.set(context.id, props.value);
134
+ return runWithOwner(owner, () => {
135
+ const children = resolveValue$3(props.children);
136
+ if (props.bridge) return createDOMContextBoundary(context, props.value, children);
137
+ return children;
138
+ });
139
+ },
140
+ Bridge(props) {
141
+ return createDOMContextBoundary(context, props.value, resolveValue$3(props.children));
142
+ }
143
+ };
144
+ return context;
145
+ }
146
+ function provide(context, value) {
147
+ const owner = currentOwner;
148
+ if (!owner) {
149
+ console.warn("[Zeus context] provide() was called without an active component owner.");
150
+ return;
151
+ }
152
+ owner.provides.set(context.id, value);
153
+ }
154
+ function inject(context, fallback) {
155
+ let owner = currentOwner;
156
+ while (owner) {
157
+ if (owner.provides.has(context.id)) return owner.provides.get(context.id);
158
+ owner = owner.parent;
159
+ }
160
+ if (arguments.length >= 2) return fallback;
161
+ if (context.hasDefaultValue) return context.defaultValue;
162
+ throw new Error(`[Zeus context] No provider found for context.`);
163
+ }
164
+ function useContext(context, fallback) {
165
+ if (arguments.length >= 2) return inject(context, fallback);
166
+ return inject(context);
167
+ }
168
+ const ZEUS_CONTEXT_REQUEST = "zeus:context-request";
169
+ /**
170
+ * Creates a transparent DOM element that acts as a context boundary.
171
+ * Native custom elements inside it can use `requestDOMContext` to receive
172
+ * context values via the DOM event protocol.
173
+ */
174
+ function createDOMContextBoundary(context, value, children) {
175
+ const boundary = document.createElement("zeus-context");
176
+ boundary.style.cssText = "display:contents;position:unset;width:0;height:0;overflow:hidden";
177
+ provideDOMContext(boundary, context, value);
178
+ insert(boundary, children);
179
+ return boundary;
180
+ }
181
+ /**
182
+ * Registers a context value on a DOM target so that any descendant custom
183
+ * element can pick it up via `requestDOMContext`.
184
+ */
185
+ function provideDOMContext(target, context, value) {
186
+ const handler = (event) => {
187
+ const request = event;
188
+ if (request.type !== "zeus:context-request") return;
189
+ if (request.detail.id !== context.id) return;
190
+ request.stopPropagation();
191
+ request.detail.resolve(value);
192
+ };
193
+ target.addEventListener(ZEUS_CONTEXT_REQUEST, handler);
194
+ onScopeDispose(() => {
195
+ target.removeEventListener(ZEUS_CONTEXT_REQUEST, handler);
196
+ }, true);
197
+ }
198
+ /**
199
+ * Internal precise DOM context resolver.
200
+ *
201
+ * Unlike requestDOMContext(), this can distinguish:
202
+ * - found: false, value: undefined
203
+ * - found: true, value: undefined
204
+ */
205
+ function resolveDOMContext(host, context) {
206
+ let found = false;
207
+ let value;
208
+ const event = new CustomEvent(ZEUS_CONTEXT_REQUEST, {
209
+ bubbles: true,
210
+ composed: true,
211
+ cancelable: true,
212
+ detail: {
213
+ id: context.id,
214
+ resolved: false,
215
+ value: void 0,
216
+ resolve(nextValue) {
217
+ found = true;
218
+ value = nextValue;
219
+ this.resolved = true;
220
+ this.value = nextValue;
221
+ }
222
+ }
223
+ });
224
+ host.dispatchEvent(event);
225
+ return {
226
+ found,
227
+ value
228
+ };
229
+ }
230
+ /**
231
+ * Public compatibility API.
232
+ *
233
+ * Returns the resolved value if found, otherwise undefined.
234
+ * If you need to distinguish "not found" from "found undefined",
235
+ * use resolveDOMContext().
236
+ */
237
+ function requestDOMContext(host, context) {
238
+ return resolveDOMContext(host, context).value;
239
+ }
240
+ function resolveValue$3(value) {
241
+ return typeof value === "function" ? value() : value !== null && value !== void 0 ? value : null;
242
+ }
243
+ //#endregion
244
+ //#region packages/runtime-dom/src/devtools.ts
245
+ function emitDevtoolsEvent(event) {
246
+ var _window$__ZEUS_DEVTOO;
247
+ if (typeof window === "undefined") return;
248
+ (_window$__ZEUS_DEVTOO = window.__ZEUS_DEVTOOLS_HOOK__) === null || _window$__ZEUS_DEVTOO === void 0 || _window$__ZEUS_DEVTOO.emit(event);
249
+ }
250
+ //#endregion
251
+ //#region packages/runtime-dom/src/render.ts
252
+ function render(value, container, options = {}) {
253
+ var _options$owner;
254
+ const renderScope = scope();
255
+ const owner = (_options$owner = options.owner) !== null && _options$owner !== void 0 ? _options$owner : createOwner();
256
+ renderScope.run(() => {
257
+ container.textContent = "";
258
+ runWithOwner(owner, () => {
259
+ insert(container, resolveValue$2(value));
260
+ });
261
+ });
262
+ emitDevtoolsEvent({
263
+ type: "render",
264
+ target: container
265
+ });
266
+ let disposed = false;
267
+ return () => {
268
+ if (disposed) return;
269
+ disposed = true;
270
+ renderScope.stop();
271
+ container.textContent = "";
272
+ };
273
+ }
274
+ function resolveValue$2(value) {
275
+ return typeof value === "function" ? value() : value !== null && value !== void 0 ? value : null;
276
+ }
277
+ //#endregion
278
+ //#region packages/runtime-dom/src/dom.ts
279
+ function marker(parent, index) {
280
+ let seen = 0;
281
+ for (const node of parent.childNodes) {
282
+ if (node.nodeType !== Node.COMMENT_NODE) continue;
283
+ const comment = node;
284
+ if (comment.data !== "" && comment.data !== "!") continue;
285
+ if (seen === index) return comment;
286
+ seen++;
287
+ }
288
+ throw new Error(`[Zeus runtime] marker ${index} not found`);
289
+ }
290
+ function child(parent, index) {
291
+ const node = parent.childNodes.item(index);
292
+ if (!node) throw new Error(`[Zeus runtime] child ${index} not found`);
293
+ return node;
294
+ }
295
+ function removeNodes(nodes) {
296
+ for (const node of nodes) {
297
+ var _node$parentNode;
298
+ (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || _node$parentNode.removeChild(node);
299
+ }
300
+ }
301
+ //#endregion
302
+ //#region packages/runtime-dom/src/bindings.ts
303
+ function bindText(node, value) {
304
+ effect(() => {
305
+ node.data = stringifyText(value());
306
+ });
307
+ }
308
+ function bindTextContent(el, value) {
309
+ effect(() => {
310
+ el.textContent = stringifyText(value());
311
+ });
312
+ }
313
+ function stringifyText(value) {
314
+ if (Array.isArray(value)) return value.map(stringifyText).join("");
315
+ if (value == null || value === false || value === true) return "";
316
+ if (typeof Node !== "undefined" && value instanceof Node) {
317
+ var _value$textContent;
318
+ return (_value$textContent = value.textContent) !== null && _value$textContent !== void 0 ? _value$textContent : "";
319
+ }
320
+ return String(value);
321
+ }
322
+ function setAttr(el, name, value) {
323
+ if (value == null || value === false) {
324
+ el.removeAttribute(normalizeAttrName(name));
325
+ return;
326
+ }
327
+ const attrName = normalizeAttrName(name);
328
+ if (value === true) {
329
+ el.setAttribute(attrName, "");
330
+ return;
331
+ }
332
+ el.setAttribute(attrName, String(value));
333
+ }
334
+ function normalizeAttrName(name) {
335
+ return name === "className" ? "class" : name;
336
+ }
337
+ function bindAttr(el, name, value) {
338
+ effect(() => {
339
+ setAttr(el, name, value());
340
+ });
341
+ }
342
+ function bindProp(el, name, value) {
343
+ effect(() => {
344
+ el[name] = value();
345
+ });
346
+ }
347
+ function bindClass(el, value) {
348
+ effect(() => {
349
+ const next = normalizeClass(value());
350
+ if (next) el.setAttribute("class", next);
351
+ else el.removeAttribute("class");
352
+ });
353
+ }
354
+ function normalizeClass(value) {
355
+ if (!value) return "";
356
+ if (typeof value === "string") return value;
357
+ if (Array.isArray(value)) return value.map(normalizeClass).filter(Boolean).join(" ");
358
+ if (typeof value === "object") return Object.keys(value).filter((key) => value[key]).join(" ");
359
+ return "";
360
+ }
361
+ function bindStyle(el, value) {
362
+ let prev;
363
+ effect(() => {
364
+ const next = value();
365
+ if (next == null) {
366
+ el.removeAttribute("style");
367
+ prev = void 0;
368
+ return;
369
+ }
370
+ if (typeof next === "string") {
371
+ el.setAttribute("style", next);
372
+ prev = void 0;
373
+ return;
374
+ }
375
+ patchStyle(el, prev, next);
376
+ prev = next;
377
+ });
378
+ }
379
+ function patchStyle(el, prev, next) {
380
+ const style = el.style;
381
+ if (prev) {
382
+ for (const key in prev) if (!(key in next)) style.setProperty(toKebabCase$1(key), "");
383
+ }
384
+ for (const key in next) {
385
+ const value = next[key];
386
+ const name = toKebabCase$1(key);
387
+ if (value == null) style.setProperty(name, "");
388
+ else style.setProperty(name, normalizeStyleValue(key, value));
389
+ }
390
+ }
391
+ function normalizeStyleValue(key, value) {
392
+ if (typeof value === "number" && value !== 0 && !isUnitlessNumber(key)) return `${value}px`;
393
+ return String(value);
394
+ }
395
+ const unitlessNumbers = new Set([
396
+ "opacity",
397
+ "zIndex",
398
+ "fontWeight",
399
+ "lineHeight",
400
+ "flex",
401
+ "flexGrow",
402
+ "flexShrink",
403
+ "order"
404
+ ]);
405
+ function isUnitlessNumber(key) {
406
+ return unitlessNumbers.has(key);
407
+ }
408
+ function toKebabCase$1(value) {
409
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
410
+ }
411
+ //#endregion
412
+ //#region packages/runtime-dom/src/events.ts
413
+ const delegatedEvents = /* @__PURE__ */ new Set();
414
+ const delegatedListeners = [];
415
+ const nonBubblingEventMap = {
416
+ focus: "focusin",
417
+ blur: "focusout"
418
+ };
419
+ function bindEvent(el, name, handler) {
420
+ const target = el;
421
+ const events = target.__zeusEvents || (target.__zeusEvents = {});
422
+ events[name] = handler;
423
+ onScopeDispose(() => {
424
+ var _target$__zeusEvents;
425
+ if (((_target$__zeusEvents = target.__zeusEvents) === null || _target$__zeusEvents === void 0 ? void 0 : _target$__zeusEvents[name]) === handler) delete target.__zeusEvents[name];
426
+ }, true);
427
+ }
428
+ function delegateEvents(events) {
429
+ for (const event of events) {
430
+ const delegatedName = normalizeDelegatedEventName(event);
431
+ if (delegatedEvents.has(delegatedName)) continue;
432
+ delegatedEvents.add(delegatedName);
433
+ const handler = dispatchDelegatedEvent;
434
+ delegatedListeners.push(delegatedName);
435
+ document.addEventListener(delegatedName, handler);
436
+ emitDevtoolsEvent({
437
+ type: "delegate-event",
438
+ event: delegatedName
439
+ });
440
+ }
441
+ }
442
+ function normalizeDelegatedEventName(name) {
443
+ var _nonBubblingEventMap$;
444
+ return (_nonBubblingEventMap$ = nonBubblingEventMap[name]) !== null && _nonBubblingEventMap$ !== void 0 ? _nonBubblingEventMap$ : name;
445
+ }
446
+ function normalizeOriginalEventName(name) {
447
+ if (name === "focusin") return "focus";
448
+ if (name === "focusout") return "blur";
449
+ return name;
450
+ }
451
+ function dispatchDelegatedEvent(event) {
452
+ const eventName = normalizeOriginalEventName(event.type);
453
+ let node = event.target;
454
+ while (node && node !== document) {
455
+ if (node.nodeType === Node.ELEMENT_NODE) {
456
+ var _el$__zeusEvents;
457
+ const el = node;
458
+ const handler = (_el$__zeusEvents = el.__zeusEvents) === null || _el$__zeusEvents === void 0 ? void 0 : _el$__zeusEvents[eventName];
459
+ if (handler) {
460
+ callDelegatedHandler(el, handler, event);
461
+ if (event.cancelBubble) return;
462
+ }
463
+ }
464
+ node = node.parentNode;
465
+ }
466
+ }
467
+ function callDelegatedHandler(el, handler, event) {
468
+ const previousCurrentTarget = Object.prototype.hasOwnProperty.call(event, "currentTarget") ? Object.getOwnPropertyDescriptor(event, "currentTarget") : void 0;
469
+ try {
470
+ Object.defineProperty(event, "currentTarget", {
471
+ configurable: true,
472
+ get() {
473
+ return el;
474
+ }
475
+ });
476
+ } catch (_unused) {}
477
+ try {
478
+ handler.call(el, event);
479
+ } finally {
480
+ try {
481
+ if (previousCurrentTarget) Object.defineProperty(event, "currentTarget", previousCurrentTarget);
482
+ else delete event.currentTarget;
483
+ } catch (_unused2) {}
484
+ }
485
+ }
486
+ //#endregion
487
+ //#region packages/runtime-dom/src/refs.ts
488
+ function setRef(target, value) {
489
+ if (target == null) return;
490
+ if (typeof target === "function") {
491
+ target(value);
492
+ return;
493
+ }
494
+ if ("value" in target) {
495
+ target.value = value;
496
+ return;
497
+ }
498
+ if ("current" in target) {
499
+ target.current = value;
500
+ return;
501
+ }
502
+ console.warn("[Zeus runtime] Invalid ref target:", target);
503
+ }
504
+ function bindRef(el, target) {
505
+ setRef(target, el);
506
+ if (getCurrentScope()) onScopeDispose(() => {
507
+ setRef(target, null);
508
+ }, true);
509
+ }
510
+ //#endregion
511
+ //#region packages/runtime-dom/src/component.ts
512
+ function createComponent(component, props) {
513
+ return runWithOwner(createOwner(), () => component(props));
514
+ }
515
+ //#endregion
516
+ //#region packages/runtime-dom/src/list.ts
517
+ function mountFor$1(parent, marker, each, key, render) {
518
+ if (!key) {
519
+ mountIndexFor(parent, marker, each, render);
520
+ return;
521
+ }
522
+ mountKeyedFor(parent, marker, each, key, render);
523
+ }
524
+ function mountIndexFor(parent, marker, each, render) {
525
+ let current = [];
526
+ const owner = getCurrentOwner();
527
+ const runner = effect(() => {
528
+ var _each;
529
+ removeNodes$1(current);
530
+ current = [];
531
+ const list = (_each = each()) !== null && _each !== void 0 ? _each : [];
532
+ for (let i = 0; i < list.length; i++) current.push(...insertTracked(parent, runWithOwner(owner, () => render(list[i], i)), marker));
533
+ });
534
+ onScopeDispose(() => {
535
+ stop(runner);
536
+ removeNodes$1(current);
537
+ current = [];
538
+ }, true);
539
+ }
540
+ function mountKeyedFor(parent, marker, each, key, render) {
541
+ let records = [];
542
+ const owner = getCurrentOwner();
543
+ const runner = effect(() => {
544
+ var _each2;
545
+ const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
546
+ const oldMap = /* @__PURE__ */ new Map();
547
+ for (const record of records) oldMap.set(record.key, record);
548
+ const nextRecords = [];
549
+ for (let i = 0; i < nextItems.length; i++) {
550
+ const item = nextItems[i];
551
+ const itemKey = key(item, i);
552
+ const oldRecord = oldMap.get(itemKey);
553
+ if (oldRecord) {
554
+ oldMap.delete(itemKey);
555
+ oldRecord.item = item;
556
+ oldRecord.index = i;
557
+ nextRecords.push(oldRecord);
558
+ } else nextRecords.push({
559
+ key: itemKey,
560
+ item,
561
+ index: i,
562
+ nodes: insertTracked(parent, runWithOwner(owner, () => render(item, i)), marker)
563
+ });
564
+ }
565
+ for (const record of oldMap.values()) removeNodes$1(record.nodes);
566
+ for (let i = nextRecords.length - 1; i >= 0; i--) {
567
+ var _nextRecords$nodes$;
568
+ const record = nextRecords[i];
569
+ const anchor = i === nextRecords.length - 1 ? marker : (_nextRecords$nodes$ = nextRecords[i + 1].nodes[0]) !== null && _nextRecords$nodes$ !== void 0 ? _nextRecords$nodes$ : marker;
570
+ moveRangeBefore(record.nodes, parent, anchor);
571
+ }
572
+ emitDevtoolsEvent({
573
+ type: "mount-for",
574
+ length: records.length
575
+ });
576
+ records = nextRecords;
577
+ });
578
+ onScopeDispose(() => {
579
+ stop(runner);
580
+ for (const record of records) removeNodes$1(record.nodes);
581
+ records = [];
582
+ }, true);
583
+ }
584
+ //#endregion
585
+ //#region packages/runtime-dom/src/controlFlow.ts
586
+ function Show(props) {
587
+ return resolveValue(props.when ? props.children : props.fallback);
588
+ }
589
+ function resolveValue(value) {
590
+ if (typeof value === "function") return value();
591
+ return value !== null && value !== void 0 ? value : null;
592
+ }
593
+ function mountShow(parent, marker, when, children, fallback) {
594
+ mountDynamic(parent, marker, () => when() ? children() : fallback ? fallback() : null);
595
+ }
596
+ function For(props) {
597
+ var _props$each$map, _props$each;
598
+ return (_props$each$map = (_props$each = props.each) === null || _props$each === void 0 ? void 0 : _props$each.map((item, index) => props.children(item, index))) !== null && _props$each$map !== void 0 ? _props$each$map : null;
599
+ }
600
+ function mountFor(parent, marker, each, key, render) {
601
+ mountFor$1(parent, marker, each, key, render);
602
+ }
603
+ //#endregion
604
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
605
+ function _typeof(o) {
606
+ "@babel/helpers - typeof";
607
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
608
+ return typeof o;
609
+ } : function(o) {
610
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
611
+ }, _typeof(o);
612
+ }
613
+ //#endregion
614
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
615
+ function toPrimitive(t, r) {
616
+ if ("object" != _typeof(t) || !t) return t;
617
+ var e = t[Symbol.toPrimitive];
618
+ if (void 0 !== e) {
619
+ var i = e.call(t, r || "default");
620
+ if ("object" != _typeof(i)) return i;
621
+ throw new TypeError("@@toPrimitive must return a primitive value.");
622
+ }
623
+ return ("string" === r ? String : Number)(t);
624
+ }
625
+ //#endregion
626
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
627
+ function toPropertyKey(t) {
628
+ var i = toPrimitive(t, "string");
629
+ return "symbol" == _typeof(i) ? i : i + "";
630
+ }
631
+ //#endregion
632
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
633
+ function _defineProperty(e, r, t) {
634
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
635
+ value: t,
636
+ enumerable: !0,
637
+ configurable: !0,
638
+ writable: !0
639
+ }) : e[r] = t, e;
640
+ }
641
+ //#endregion
642
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
643
+ function ownKeys(e, r) {
644
+ var t = Object.keys(e);
645
+ if (Object.getOwnPropertySymbols) {
646
+ var o = Object.getOwnPropertySymbols(e);
647
+ r && (o = o.filter(function(r) {
648
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
649
+ })), t.push.apply(t, o);
650
+ }
651
+ return t;
652
+ }
653
+ function _objectSpread2(e) {
654
+ for (var r = 1; r < arguments.length; r++) {
655
+ var t = null != arguments[r] ? arguments[r] : {};
656
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
657
+ _defineProperty(e, r, t[r]);
658
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
659
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
660
+ });
661
+ }
662
+ return e;
663
+ }
664
+ //#endregion
665
+ //#region packages/runtime-dom/src/defineElement.ts
666
+ function defineElement(tagName, options, setup) {
667
+ var _options$props;
668
+ const propDefs = normalizePropDefinitions((_options$props = options.props) !== null && _options$props !== void 0 ? _options$props : {});
669
+ const observedAttributes = propDefs.filter((def) => def.attr !== false).map((def) => def.attr);
670
+ class ZeusElement extends HTMLElement {
671
+ static get observedAttributes() {
672
+ return observedAttributes;
673
+ }
674
+ constructor() {
675
+ super();
676
+ this.props = state({});
677
+ this.lightChildren = [];
678
+ this.capturedLightChildren = false;
679
+ this.reflecting = false;
680
+ applyPropDefaults(this.props, propDefs);
681
+ definePropAccessors(this, this.props, propDefs);
682
+ }
683
+ connectedCallback() {
684
+ var _options$shadow, _options$consumes;
685
+ if (this.dispose) return;
686
+ const shadow = (_options$shadow = options.shadow) !== null && _options$shadow !== void 0 ? _options$shadow : false;
687
+ const mode = shadow ? "shadow" : "light";
688
+ if (mode === "light" && !this.capturedLightChildren) {
689
+ this.lightChildren = Array.from(this.childNodes);
690
+ this.capturedLightChildren = true;
691
+ }
692
+ this.syncAttributesToProps(propDefs);
693
+ const owner = createOwner();
694
+ for (const context of (_options$consumes = options.consumes) !== null && _options$consumes !== void 0 ? _options$consumes : []) {
695
+ const resolved = resolveDOMContext(this, context);
696
+ if (resolved.found) owner.provides.set(context.id, resolved.value);
697
+ else if (context.hasDefaultValue) owner.provides.set(context.id, context.defaultValue);
698
+ }
699
+ const target = this.resolveRenderTarget(shadow);
700
+ const hostContext = {
701
+ host: this,
702
+ mode,
703
+ lightChildren: this.lightChildren
704
+ };
705
+ const setupContext = {
706
+ host: this,
707
+ emit: (name, detail, eventOptions) => {
708
+ return this.dispatchEvent(new CustomEvent(name, _objectSpread2(_objectSpread2({
709
+ bubbles: true,
710
+ composed: true,
711
+ cancelable: true
712
+ }, eventOptions), {}, { detail })));
713
+ }
714
+ };
715
+ this.dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => setup(this.props, setupContext))), target, { owner });
716
+ mountStyles(target, options.styles);
717
+ onScopeDispose(() => {
718
+ var _this$dispose;
719
+ (_this$dispose = this.dispose) === null || _this$dispose === void 0 || _this$dispose.call(this);
720
+ this.dispose = void 0;
721
+ }, true);
722
+ }
723
+ disconnectedCallback() {
724
+ var _this$dispose2;
725
+ (_this$dispose2 = this.dispose) === null || _this$dispose2 === void 0 || _this$dispose2.call(this);
726
+ this.dispose = void 0;
727
+ }
728
+ attributeChangedCallback(name, oldValue, newValue) {
729
+ if (oldValue === newValue || this.reflecting) return;
730
+ const def = propDefs.find((item) => item.attr === name);
731
+ if (!def) return;
732
+ this.props[def.key] = castAttributeValue(newValue, def);
733
+ }
734
+ resolveRenderTarget(shadow) {
735
+ if (this.target) return this.target;
736
+ if (!shadow) {
737
+ this.target = this;
738
+ return this.target;
739
+ }
740
+ this.target = this.attachShadow(typeof shadow === "object" ? shadow : { mode: "open" });
741
+ return this.target;
742
+ }
743
+ syncAttributesToProps(defs) {
744
+ for (const def of defs) {
745
+ if (def.attr === false) continue;
746
+ const value = this.getAttribute(def.attr);
747
+ if (value !== null || def.type === Boolean) this.props[def.key] = castAttributeValue(value, def);
748
+ }
749
+ }
750
+ _writePropFromProperty(key, value) {
751
+ const def = propDefs.find((item) => item.key === key);
752
+ this.props[key] = value;
753
+ if ((def === null || def === void 0 ? void 0 : def.reflect) && def.attr !== false) {
754
+ this.reflecting = true;
755
+ try {
756
+ reflectPropToAttribute(this, def, value);
757
+ } finally {
758
+ this.reflecting = false;
759
+ }
760
+ }
761
+ }
762
+ }
763
+ if (!customElements.get(tagName)) customElements.define(tagName, ZeusElement);
764
+ return ZeusElement;
765
+ }
766
+ function normalizePropDefinitions(props) {
767
+ return Object.keys(props).map((key) => {
768
+ const input = props[key];
769
+ if (typeof input === "function") return {
770
+ key,
771
+ attr: toKebabCase(key),
772
+ type: input,
773
+ reflect: false
774
+ };
775
+ return {
776
+ key,
777
+ attr: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? toKebabCase(key) : input.attr,
778
+ type: input === null || input === void 0 ? void 0 : input.type,
779
+ reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
780
+ default: input === null || input === void 0 ? void 0 : input.default
781
+ };
782
+ });
783
+ }
784
+ function applyPropDefaults(props, defs) {
785
+ for (const def of defs) {
786
+ if (!("default" in def)) continue;
787
+ const value = typeof def.default === "function" ? def.default() : def.default;
788
+ props[def.key] = value;
789
+ }
790
+ }
791
+ function definePropAccessors(element, props, defs) {
792
+ for (const def of defs) {
793
+ if (def.key in element) continue;
794
+ Object.defineProperty(element, def.key, {
795
+ configurable: true,
796
+ enumerable: true,
797
+ get() {
798
+ return props[def.key];
799
+ },
800
+ set(value) {
801
+ element._writePropFromProperty(def.key, value);
802
+ }
803
+ });
804
+ }
805
+ }
806
+ function castAttributeValue(value, def) {
807
+ if (def.type === Boolean) return value !== null;
808
+ if (value === null) return;
809
+ if (def.type === Number) return Number(value);
810
+ if (def.type === Object || def.type === Array) try {
811
+ return JSON.parse(value);
812
+ } catch (_unused) {
813
+ console.warn(`[Zeus custom-element] Failed to parse JSON attribute "${def.attr}".`);
814
+ return def.type === Array ? [] : {};
815
+ }
816
+ return value;
817
+ }
818
+ function reflectPropToAttribute(element, def, value) {
819
+ if (def.attr === false) return;
820
+ if (def.type === Boolean) {
821
+ if (value) element.setAttribute(def.attr, "");
822
+ else element.removeAttribute(def.attr);
823
+ return;
824
+ }
825
+ if (value == null) {
826
+ element.removeAttribute(def.attr);
827
+ return;
828
+ }
829
+ if (def.type === Object || def.type === Array) {
830
+ element.setAttribute(def.attr, JSON.stringify(value));
831
+ return;
832
+ }
833
+ element.setAttribute(def.attr, String(value));
834
+ }
835
+ function mountStyles(target, styles) {
836
+ if (!styles) return;
837
+ const list = Array.isArray(styles) ? styles : [styles];
838
+ for (const css of list) {
839
+ const style = document.createElement("style");
840
+ style.textContent = css;
841
+ target.appendChild(style);
842
+ }
843
+ }
844
+ function toKebabCase(value) {
845
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
846
+ }
847
+ //#endregion
848
+ //#region packages/runtime-dom/src/slot.ts
849
+ function createSlot(name, fallback) {
850
+ const context = getCurrentHostContext();
851
+ if (!context) return createNativeSlot(name, fallback);
852
+ if (context.mode === "shadow") return createNativeSlot(name, fallback);
853
+ const assigned = findLightSlotNodes(context.lightChildren, name);
854
+ if (assigned.length > 0) return Array.from(assigned);
855
+ return fallback ? fallback() : null;
856
+ }
857
+ function createNativeSlot(name, fallback) {
858
+ const slot = document.createElement("slot");
859
+ if (name) slot.setAttribute("name", name);
860
+ const fallbackValue = fallback === null || fallback === void 0 ? void 0 : fallback();
861
+ if (fallbackValue != null) insert(slot, fallbackValue);
862
+ return slot;
863
+ }
864
+ function findLightSlotNodes(nodes, name) {
865
+ if (name) return nodes.filter((node) => {
866
+ if (node.nodeType !== Node.ELEMENT_NODE) return false;
867
+ return node.getAttribute("slot") === name;
868
+ });
869
+ return nodes.filter((node) => {
870
+ if (node.nodeType === Node.ELEMENT_NODE) return !node.hasAttribute("slot");
871
+ return isMeaningfulTextNode(node);
872
+ });
873
+ }
874
+ function isMeaningfulTextNode(node) {
875
+ var _node$textContent;
876
+ if (node.nodeType !== Node.TEXT_NODE) return false;
877
+ return Boolean((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim());
878
+ }
879
+ //#endregion
880
+ //#region packages/runtime-dom/src/webComponents.ts
881
+ function Host(props) {
882
+ return resolveValue$1(props.children);
883
+ }
884
+ function Slot(props) {
885
+ return createSlot(props.name, () => resolveValue$1(props.children));
886
+ }
887
+ function resolveValue$1(value) {
888
+ return typeof value === "function" ? value() : value;
889
+ }
890
+ //#endregion
891
+ export { For, Host, Show, Slot, ZEUS_CONTEXT_REQUEST, bindAttr, bindClass, bindEvent, bindProp, bindRef, bindStyle, bindText, bindTextContent, captureCurrentHostContext, child, createComponent, createContext, createDOMContextBoundary, createOwner, createSlot, defineElement, delegateEvents, getCurrentHostContext, getCurrentOwner, inject, insert, marker, mountDynamic, mountFor, mountShow, normalizeClass, provide, provideDOMContext, removeNodes, render, requestDOMContext, resolveDOMContext, resolveValue, runWithOwner, setAttr, setRef, template, useContext, withCapturedHostContext, withHostContext };