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