elements-kit 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/element-Cbzkm_B5.mjs +425 -0
  2. package/dist/for.d.mts +1 -1
  3. package/dist/for.mjs +1 -1
  4. package/dist/{infer-LDn1TquI.d.mts → infer-K2Te9gn1.d.mts} +5 -5
  5. package/dist/integrations/react.d.mts +1 -1
  6. package/dist/jsx-runtime/index.d.mts +1 -1
  7. package/dist/jsx-runtime/index.mjs +1 -1
  8. package/dist/signals/index.d.mts +1 -1
  9. package/dist/signals/index.mjs +5 -3
  10. package/dist/slot-B8y0aEoz.d.mts +71 -0
  11. package/dist/slot-Cne__au7.mjs +127 -0
  12. package/dist/slot.d.mts +2 -2
  13. package/dist/slot.mjs +2 -2
  14. package/dist/utilities/active-element.d.mts +1 -1
  15. package/dist/utilities/async.d.mts +1 -1
  16. package/dist/utilities/debounced.d.mts +1 -1
  17. package/dist/utilities/dom-lifecycle.test.mjs +1 -0
  18. package/dist/utilities/element-rect.d.mts +1 -1
  19. package/dist/utilities/element-scroll.d.mts +1 -1
  20. package/dist/utilities/event-driven.d.mts +1 -1
  21. package/dist/utilities/event-listener.d.mts +1 -1
  22. package/dist/utilities/focus-within.d.mts +1 -1
  23. package/dist/utilities/hover.d.mts +1 -1
  24. package/dist/utilities/interval.d.mts +1 -1
  25. package/dist/utilities/location.d.mts +1 -1
  26. package/dist/utilities/media-devices.d.mts +1 -1
  27. package/dist/utilities/media-player.d.mts +1 -1
  28. package/dist/utilities/media-query.d.mts +1 -1
  29. package/dist/utilities/network.d.mts +1 -1
  30. package/dist/utilities/orientation.d.mts +1 -1
  31. package/dist/utilities/previous.d.mts +1 -1
  32. package/dist/utilities/promise.d.mts +1 -1
  33. package/dist/utilities/routing.d.mts +1 -1
  34. package/dist/utilities/search-params.d.mts +1 -1
  35. package/dist/utilities/storage.d.mts +1 -1
  36. package/dist/utilities/throttled.d.mts +1 -1
  37. package/dist/utilities/timeout.d.mts +1 -1
  38. package/dist/utilities/window-focus.d.mts +1 -1
  39. package/dist/utilities/window-size.d.mts +1 -1
  40. package/package.json +1 -1
  41. package/dist/element-BjpyY6qv.mjs +0 -277
  42. package/dist/slot-BnzxFBfO.mjs +0 -198
  43. package/dist/slot-CfafCBOW.d.mts +0 -121
@@ -0,0 +1,425 @@
1
+ import { c as effectScope, g as untracked, p as onCleanup, s as effect } from "./lib-CVfOddra.mjs";
2
+ import "./polyfill-CdZVCxdo.mjs";
3
+ import { isReactive, resolveProps } from "./signals/index.mjs";
4
+ import { on } from "./utilities/event-listener.mjs";
5
+ import { n as Slot, r as resolveNode$1, t as SLOTS } from "./slot-Cne__au7.mjs";
6
+ //#region src/jsx-runtime/constants.ts
7
+ /**
8
+ * IDL properties that take precedence over the default `setAttribute` path.
9
+ *
10
+ * Includes camelCase boolean aliases (`readOnly`, `noValidate`, …) plus
11
+ * lowercase boolean attributes that should be set as properties for correct
12
+ * reflection. `defaultValue` is added on top — without it, `<input
13
+ * defaultValue="x" />` falls through to `setAttribute("defaultValue", "x")`
14
+ * which creates a useless `defaultvalue` content attribute (native
15
+ * `HTMLInputElement` has no such attribute; the IDL property reflects `value`).
16
+ */
17
+ const Properties = new Set([
18
+ "className",
19
+ "value",
20
+ "readOnly",
21
+ "noValidate",
22
+ "formNoValidate",
23
+ "isMap",
24
+ "noModule",
25
+ "playsInline",
26
+ "adAuctionHeaders",
27
+ "allowFullscreen",
28
+ "browsingTopics",
29
+ "defaultChecked",
30
+ "defaultMuted",
31
+ "defaultSelected",
32
+ "disablePictureInPicture",
33
+ "disableRemotePlayback",
34
+ "preservesPitch",
35
+ "shadowRootClonable",
36
+ "shadowRootCustomElementRegistry",
37
+ "shadowRootDelegatesFocus",
38
+ "shadowRootSerializable",
39
+ "sharedStorageWritable",
40
+ "allowfullscreen",
41
+ "async",
42
+ "alpha",
43
+ "autofocus",
44
+ "autoplay",
45
+ "checked",
46
+ "controls",
47
+ "default",
48
+ "disabled",
49
+ "formnovalidate",
50
+ "hidden",
51
+ "indeterminate",
52
+ "inert",
53
+ "ismap",
54
+ "loop",
55
+ "multiple",
56
+ "muted",
57
+ "nomodule",
58
+ "novalidate",
59
+ "open",
60
+ "playsinline",
61
+ "readonly",
62
+ "required",
63
+ "reversed",
64
+ "seamless",
65
+ "selected",
66
+ "adauctionheaders",
67
+ "browsingtopics",
68
+ "credentialless",
69
+ "defaultchecked",
70
+ "defaultmuted",
71
+ "defaultselected",
72
+ "defer",
73
+ "disablepictureinpicture",
74
+ "disableremoteplayback",
75
+ "preservespitch",
76
+ "shadowrootclonable",
77
+ "shadowrootcustomelementregistry",
78
+ "shadowrootdelegatesfocus",
79
+ "shadowrootserializable",
80
+ "sharedstoragewritable",
81
+ "defaultValue"
82
+ ]);
83
+ /** Properties whose assignment replaces the element's children. */
84
+ const ChildProperties = new Set([
85
+ "innerHTML",
86
+ "textContent",
87
+ "innerText",
88
+ "children"
89
+ ]);
90
+ /**
91
+ * Returns the XML namespace URI for an SVG-namespaced attribute prefix
92
+ * (`xlink:href`, `xml:lang`). Inlined as a function to avoid a 2-entry object
93
+ * allocation and the property lookup on every attribute write.
94
+ */
95
+ function svgNamespace(ns) {
96
+ if (ns === "xlink") return "http://www.w3.org/1999/xlink";
97
+ if (ns === "xml") return "http://www.w3.org/XML/1998/namespace";
98
+ }
99
+ const ReservedNameSpaces = new Set([
100
+ "class",
101
+ "on",
102
+ "style",
103
+ "prop"
104
+ ]);
105
+ //#endregion
106
+ //#region src/jsx-runtime/children.ts
107
+ function hasSlots(node) {
108
+ return SLOTS in node;
109
+ }
110
+ function isChildrenProperty(node, key) {
111
+ if (key === "children" && (node instanceof Element || node instanceof DocumentFragment)) return true;
112
+ if (hasSlots(node)) {
113
+ if (key.replace(/^slot:/, "") in node[SLOTS]) return true;
114
+ }
115
+ return key in node && node[key] instanceof Slot;
116
+ }
117
+ function applyChildren(node, key, value) {
118
+ if (hasSlots(node)) {
119
+ const slotName = key.replace(/^slot:/, "");
120
+ if (slotName in node[SLOTS]) {
121
+ applySlot(node[SLOTS][slotName], value);
122
+ return;
123
+ }
124
+ }
125
+ if (key === "children" && (node instanceof Element || node instanceof DocumentFragment)) {
126
+ mountChildren(node, value);
127
+ return;
128
+ }
129
+ if (key in node) {
130
+ const slot = node[key];
131
+ if (!(slot instanceof Slot)) return;
132
+ applySlot(slot, value);
133
+ }
134
+ }
135
+ function applySlot(slot, value) {
136
+ let dispose;
137
+ if (typeof value === "function") effect(() => slot.set(resolveChild(value())));
138
+ else {
139
+ const node = resolveChild(value);
140
+ dispose = node[Symbol.dispose];
141
+ slot.set(node);
142
+ }
143
+ onCleanup(() => {
144
+ dispose?.();
145
+ slot.clear();
146
+ });
147
+ }
148
+ const FRAGMENT_POOL_MAX = 4;
149
+ const fragmentPool = [];
150
+ function acquireFragment() {
151
+ return fragmentPool.pop() ?? document.createDocumentFragment();
152
+ }
153
+ function releaseFragment(frag) {
154
+ if (fragmentPool.length < FRAGMENT_POOL_MAX) fragmentPool.push(frag);
155
+ }
156
+ function mountChildren(el, value) {
157
+ const list = ensureFlatArray(value);
158
+ if (list.length === 0) return;
159
+ if (list.length === 1) {
160
+ mountChild(el, list[0]);
161
+ return;
162
+ }
163
+ const kind = classifyStatic(list);
164
+ if (kind !== 0) {
165
+ mountStatic(el, list, kind);
166
+ return;
167
+ }
168
+ const buffer = acquireFragment();
169
+ for (const child of list) mountChild(buffer, child);
170
+ el.appendChild(buffer);
171
+ releaseFragment(buffer);
172
+ }
173
+ function classifyStatic(list) {
174
+ let kind = 3;
175
+ for (const c of list) {
176
+ if (c == null || c === false || c === true) continue;
177
+ if (typeof c === "function") return 0;
178
+ if (c instanceof Node) kind &= 1;
179
+ else if (typeof c === "string" || typeof c === "number") kind &= 2;
180
+ else return 0;
181
+ if (kind === 0) return 3;
182
+ }
183
+ return kind === 3 ? 2 : kind;
184
+ }
185
+ function mountStatic(el, list, kind) {
186
+ const buffer = acquireFragment();
187
+ let disposers = null;
188
+ if (kind === 1) for (const c of list) {
189
+ const node = c;
190
+ const dispose = node[Symbol.dispose];
191
+ if (dispose) (disposers ??= []).push(dispose);
192
+ buffer.appendChild(node);
193
+ }
194
+ else if (kind === 2) for (const c of list) {
195
+ if (c == null || c === false || c === true) continue;
196
+ buffer.appendChild(document.createTextNode(String(c)));
197
+ }
198
+ else for (const c of list) {
199
+ if (c == null || c === false || c === true) continue;
200
+ if (c instanceof Node) {
201
+ const dispose = c[Symbol.dispose];
202
+ if (dispose) (disposers ??= []).push(dispose);
203
+ buffer.appendChild(c);
204
+ } else buffer.appendChild(document.createTextNode(String(c)));
205
+ }
206
+ el.appendChild(buffer);
207
+ releaseFragment(buffer);
208
+ if (disposers && disposers.length > 0) {
209
+ const ds = disposers;
210
+ onCleanup(() => ds.forEach((d) => d()));
211
+ }
212
+ }
213
+ /**
214
+ * Mounts a single child into `el`. Reactive functions become live slots; other
215
+ * values append as-is.
216
+ *
217
+ * Relies on the caller's effectScope (every JSX render sits inside one). The
218
+ * signals lib supports multiple onCleanup per scope, so siblings coexist.
219
+ *
220
+ * Also used by `createFunctionElement` when a component returns a reactive
221
+ * getter or primitive — keeps the component's `effectScope` alive for the
222
+ * lifetime of the fragment it mounts into.
223
+ */
224
+ function mountChild(el, child) {
225
+ if (typeof child === "function") {
226
+ const slot = new Slot();
227
+ el.appendChild(slot.render());
228
+ effect(() => slot.set(resolveChild(child())));
229
+ onCleanup(() => slot.clear());
230
+ return;
231
+ }
232
+ const node = resolveChild(child);
233
+ const dispose = node[Symbol.dispose];
234
+ el.appendChild(node);
235
+ if (dispose) onCleanup(dispose);
236
+ }
237
+ function resolveChild(value) {
238
+ if (value instanceof Node) return value;
239
+ if (typeof value === "string" || typeof value === "number") return document.createTextNode(String(value));
240
+ if (value == null || typeof value === "boolean") return document.createComment("");
241
+ if (typeof value === "function") return resolveChild(value());
242
+ if (Array.isArray(value)) {
243
+ const fragment = document.createDocumentFragment();
244
+ for (const item of value) fragment.appendChild(resolveChild(item));
245
+ return fragment;
246
+ }
247
+ return resolveNode$1(value);
248
+ }
249
+ /** Normalises the children prop into a flat array. */
250
+ function ensureFlatArray(raw) {
251
+ return (Array.isArray(raw) ? raw : [raw]).flat(Infinity);
252
+ }
253
+ //#endregion
254
+ //#region src/jsx-runtime/properties.ts
255
+ function applyProps(node, props) {
256
+ const entries = Object.entries(props);
257
+ if (entries.length === 0) return;
258
+ for (const [key, value] of entries) {
259
+ if (isChildrenProperty(node, key)) {
260
+ applyChildren(node, key, value);
261
+ continue;
262
+ }
263
+ const colonIdx = key.indexOf(":");
264
+ if ((colonIdx > 0 ? key.slice(0, colonIdx) : "") === "on") {
265
+ const evName = key.slice(colonIdx + 1);
266
+ if (isReactive(value)) effect(() => {
267
+ on(node, evName, value());
268
+ });
269
+ else on(node, evName, value);
270
+ continue;
271
+ }
272
+ if (isReactive(value)) {
273
+ effect(() => setProp(node, key, value()));
274
+ continue;
275
+ }
276
+ setProp(node, key, value);
277
+ }
278
+ }
279
+ function setProp(node, key, value) {
280
+ const colonIdx = key.indexOf(":");
281
+ if (colonIdx > -1) {
282
+ const ns = key.slice(0, colonIdx);
283
+ const name = key.slice(colonIdx + 1);
284
+ if (ReservedNameSpaces.has(ns)) {
285
+ if (ns === "prop") {
286
+ node[name] = value;
287
+ return;
288
+ }
289
+ if (ns === "class") {
290
+ node.classList.toggle(name, Boolean(value));
291
+ return;
292
+ }
293
+ if (ns === "style") {
294
+ if (value == null || value === false) node.style.removeProperty(name);
295
+ else node.style.setProperty(name, String(value));
296
+ return;
297
+ }
298
+ return;
299
+ }
300
+ const svgNs = svgNamespace(ns);
301
+ if (svgNs) {
302
+ node.setAttributeNS(svgNs, key, String(value ?? ""));
303
+ return;
304
+ }
305
+ }
306
+ if (key === "class") {
307
+ node.className = String(value ?? "");
308
+ return;
309
+ }
310
+ if (key === "style") {
311
+ applyStyle(node, value);
312
+ return;
313
+ }
314
+ if (ChildProperties.has(key)) {
315
+ node[key] = value ?? "";
316
+ return;
317
+ }
318
+ if (!(node instanceof SVGElement) && Properties.has(key)) {
319
+ node[key] = value;
320
+ return;
321
+ }
322
+ if (node instanceof Element && node.nodeName.includes("-") && key in node) {
323
+ try {
324
+ node[key] = value;
325
+ } catch {
326
+ setAttribute(node, key, value);
327
+ }
328
+ return;
329
+ }
330
+ if (!(node instanceof Element)) {
331
+ node[key] = value;
332
+ return;
333
+ }
334
+ setAttribute(node, key, value);
335
+ }
336
+ function applyStyle(el, value) {
337
+ const s = el.style;
338
+ if (!s) return;
339
+ if (typeof value === "string") s.cssText = value;
340
+ else if (value && typeof value === "object") Object.assign(s, value);
341
+ }
342
+ function setAttribute(el, key, value) {
343
+ if (value == null || value === false) {
344
+ if (el.hasAttribute(key)) el.removeAttribute(key);
345
+ return;
346
+ }
347
+ const next = value === true ? "" : String(value);
348
+ if (el.getAttribute(key) === next) return;
349
+ el.setAttribute(key, next);
350
+ }
351
+ //#endregion
352
+ //#region src/jsx-runtime/dispose.ts
353
+ const DISPOSABLES = /* @__PURE__ */ new WeakMap();
354
+ const sharedDispose = function() {
355
+ const set = DISPOSABLES.get(this);
356
+ if (!set) return;
357
+ DISPOSABLES.delete(this);
358
+ set.forEach((fn) => fn());
359
+ set.clear();
360
+ };
361
+ function attachDisposables(target, disposers) {
362
+ const existing = DISPOSABLES.get(target);
363
+ if (existing) {
364
+ disposers.forEach((d) => existing.add(d));
365
+ return;
366
+ }
367
+ DISPOSABLES.set(target, disposers);
368
+ Object.defineProperty(target, Symbol.dispose, {
369
+ value: sharedDispose.bind(target),
370
+ configurable: true
371
+ });
372
+ }
373
+ //#endregion
374
+ //#region src/jsx-runtime/element.ts
375
+ function createElement(type, { ref, ...props } = {}) {
376
+ if (typeof type === "function" && !type.prototype?.render) return createFunctionElement(type, props, ref);
377
+ return createNodeElement(type, props, ref);
378
+ }
379
+ /** Runs all cleanup functions registered by JSX props/effects on `el`. */
380
+ function disposeElement(el) {
381
+ el[Symbol.dispose]?.();
382
+ }
383
+ function createFunctionElement(type, props, ref) {
384
+ let el;
385
+ let dispose;
386
+ untracked(() => {
387
+ dispose = effectScope(() => {
388
+ el = type(resolveProps(props));
389
+ if (typeof ref === "function" && el instanceof Element) ref(el);
390
+ });
391
+ });
392
+ const result = el;
393
+ if (result instanceof Element || result instanceof DocumentFragment) attachDisposables(result, new Set([dispose]));
394
+ else dispose();
395
+ return result;
396
+ }
397
+ function createNodeElement(type, props, ref) {
398
+ const node = resolveNode(type);
399
+ if (!node) return null;
400
+ let el;
401
+ let dispose;
402
+ untracked(() => {
403
+ dispose = effectScope(() => {
404
+ applyProps(node, props);
405
+ el = renderNode(node);
406
+ if (typeof ref === "function" && el instanceof Element) ref(el);
407
+ });
408
+ });
409
+ const result = el;
410
+ if (result instanceof Element || result instanceof DocumentFragment) attachDisposables(result, new Set([dispose]));
411
+ else dispose();
412
+ return result;
413
+ }
414
+ function resolveNode(type) {
415
+ if (typeof type === "string") return document.createElement(type);
416
+ if (type instanceof Element || type instanceof DocumentFragment) return type;
417
+ return new type();
418
+ }
419
+ function renderNode(node) {
420
+ if (node instanceof Element || node instanceof DocumentFragment) return node;
421
+ if (!node || typeof node.render !== "function") return null;
422
+ return renderNode(node.render());
423
+ }
424
+ //#endregion
425
+ export { disposeElement as n, mountChild as r, createElement as t };
package/dist/for.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as Props, s as Require } from "./infer-LDn1TquI.mjs";
1
+ import { i as Props, s as Require } from "./infer-K2Te9gn1.mjs";
2
2
 
3
3
  //#region src/for.d.ts
4
4
  type KeyFn<T> = (item: T, index: number) => string | number;
package/dist/for.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { c as effectScope, g as untracked, h as trigger, m as signal, p as onCleanup, s as effect } from "./lib-CVfOddra.mjs";
2
2
  import "./signals/index.mjs";
3
- import { n as disposeElement } from "./element-BjpyY6qv.mjs";
3
+ import { n as disposeElement } from "./element-Cbzkm_B5.mjs";
4
4
  //#region src/for.ts
5
5
  /**
6
6
  * Keyed list renderer. See {@link ForProps} for prop details.
@@ -1,6 +1,6 @@
1
1
  import { n as AttrChangeHandler, t as ATTRIBUTES } from "./attributes-3r7Diua4.mjs";
2
2
  import { t as CustomElementRegistry } from "./custom-elements-D5CgfNKc.mjs";
3
- import { a as PrimitiveNodeType, i as Slots, n as Slot, t as SLOTS } from "./slot-CfafCBOW.mjs";
3
+ import { n as Slot, r as PrimitiveNodeType, t as SLOTS } from "./slot-B8y0aEoz.mjs";
4
4
  import { JSX } from "dom-expressions/src/jsx-h";
5
5
 
6
6
  //#region src/jsx-runtime/element.d.ts
@@ -553,8 +553,8 @@ type EventMapOf<C> = C extends {
553
553
  type Capitalize1<S extends string> = S extends `${infer H}${infer R}` ? `${Uppercase<H>}${R}` : S;
554
554
  type EventsOf<C> = EventMapOf<C> extends infer E ? E extends Record<string, Event> ? { [K in keyof E & string as `on:${K}`]?: (ev: E[K]) => void } & { [K in keyof E & string as `on${Capitalize1<K>}`]?: (ev: E[K]) => void } : {} : {};
555
555
  type SlotKeys<I> = I extends {
556
- [SLOTS]: Slots<infer K>;
557
- } ? K : never;
556
+ [SLOTS]: infer S;
557
+ } ? Extract<keyof S, string> : never;
558
558
  type InstanceOf<C> = C extends (abstract new (...args: any[]) => infer I) ? I : C;
559
559
  type SlotsOf<C> = SlotKeys<InstanceOf<C>> extends infer K ? [K] extends [string] ? { [P in K as `slot:${P}`]?: Child } : {} : {};
560
560
  type ChildrenOf<C> = C extends {
@@ -573,7 +573,7 @@ type BaseDOMAttrs = JSX.DOMAttributes<HTMLElement>;
573
573
  * - **`prop:*`** — explicit property assignment for every field.
574
574
  * - **Events** — keys from `declare static events: { ... }` produce both
575
575
  * `on:${K}` and `on${Capitalize<K>}` typed handlers.
576
- * - **Slots** — keys from `[SLOTS] = Slots.new([...] as const)` produce `slot:${K}`.
576
+ * - **Slots** — keys from `[SLOTS] = { ... } as const` produce `slot:${K}`.
577
577
  * - **Children** — `children?: Child` unless `static children: never`.
578
578
  * - **DOM attrs** — the standard dom-expressions surface (`class`, `style`, `ref`, …).
579
579
  *
@@ -585,7 +585,7 @@ type BaseDOMAttrs = JSX.DOMAttributes<HTMLElement>;
585
585
  * class XRange extends HTMLElement {
586
586
  * static [ATTRIBUTES]: Attributes<XRange> = { min(v) { this.min = +v! } };
587
587
  * declare static events: { commit: CustomEvent<number> };
588
- * [SLOTS] = Slots.new(["label"] as const);
588
+ * [SLOTS] = { label: new Slot() } as const;
589
589
  * \@reactive() min = 0;
590
590
  * }
591
591
  *
@@ -1,4 +1,4 @@
1
- import { y as Computed } from "../infer-LDn1TquI.mjs";
1
+ import { y as Computed } from "../infer-K2Te9gn1.mjs";
2
2
 
3
3
  //#region src/integrations/react.d.ts
4
4
  /**
@@ -1,2 +1,2 @@
1
- import { U as createElement, _ as SlotProps, a as RawProps, b as MaybeReactive, c as ResolveProps, d as ComponentClass, f as ComponentFn, g as JSX, h as Attrs, i as Props, l as Child, m as PropsTarget, n as ElementProps, o as ReactiveProps, p as ComponentInstance, r as MaybeReactiveProps, s as Require, t as ComponentProps, u as Component, v as Fragment } from "../infer-LDn1TquI.mjs";
1
+ import { U as createElement, _ as SlotProps, a as RawProps, b as MaybeReactive, c as ResolveProps, d as ComponentClass, f as ComponentFn, g as JSX, h as Attrs, i as Props, l as Child, m as PropsTarget, n as ElementProps, o as ReactiveProps, p as ComponentInstance, r as MaybeReactiveProps, s as Require, t as ComponentProps, u as Component, v as Fragment } from "../infer-K2Te9gn1.mjs";
2
2
  export { Attrs, Child, Component, ComponentClass, ComponentFn, ComponentInstance, ComponentProps, ElementProps, Fragment, JSX, MaybeReactive, MaybeReactiveProps, Props, PropsTarget, RawProps, ReactiveProps, Require, ResolveProps, SlotProps, createElement as h, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
@@ -1,4 +1,4 @@
1
- import { r as mountChild, t as createElement } from "../element-BjpyY6qv.mjs";
1
+ import { r as mountChild, t as createElement } from "../element-Cbzkm_B5.mjs";
2
2
  //#region src/jsx-runtime/fragment.ts
3
3
  /**
4
4
  * Used by the JSX transform for `<>...</>` fragments.
@@ -1,2 +1,2 @@
1
- import { A as SIGNAL, B as signal, C as isReactive, D as COMPUTED, E as resolveProps, F as isComputed, H as untracked, I as isEffect, L as isEffectScope, M as computed, N as effect, O as EFFECT, P as effectScope, R as isSignal, S as Updater, T as resolve, V as trigger, b as MaybeReactive, j as batch, k as EFFECT_SCOPE, w as reactive, x as Signal, y as Computed, z as onCleanup } from "../infer-LDn1TquI.mjs";
1
+ import { A as SIGNAL, B as signal, C as isReactive, D as COMPUTED, E as resolveProps, F as isComputed, H as untracked, I as isEffect, L as isEffectScope, M as computed, N as effect, O as EFFECT, P as effectScope, R as isSignal, S as Updater, T as resolve, V as trigger, b as MaybeReactive, j as batch, k as EFFECT_SCOPE, w as reactive, x as Signal, y as Computed, z as onCleanup } from "../infer-K2Te9gn1.mjs";
2
2
  export { COMPUTED, Computed, EFFECT, EFFECT_SCOPE, MaybeReactive, SIGNAL, Signal, Updater, batch, computed, effect, effectScope, isComputed, isEffect, isEffectScope, isReactive, isSignal, onCleanup, reactive, resolve, resolveProps, signal, trigger, untracked };
@@ -109,6 +109,8 @@ function resolve(value) {
109
109
  * ```
110
110
  */
111
111
  function resolveProps(raw) {
112
+ const ownKeys = Reflect.ownKeys(raw);
113
+ const ownKeySet = new Set(ownKeys);
112
114
  const cache = /* @__PURE__ */ new Map();
113
115
  const get = (key) => {
114
116
  let getter = cache.get(key);
@@ -121,9 +123,9 @@ function resolveProps(raw) {
121
123
  };
122
124
  return new Proxy(raw, {
123
125
  get: (_target, key) => get(key),
124
- has: (_target, key) => key in raw,
125
- ownKeys: (_target) => Reflect.ownKeys(raw),
126
- getOwnPropertyDescriptor: (_target, key) => key in raw ? {
126
+ has: (_target, key) => ownKeySet.has(key),
127
+ ownKeys: () => ownKeys,
128
+ getOwnPropertyDescriptor: (_target, key) => ownKeySet.has(key) ? {
127
129
  enumerable: true,
128
130
  configurable: true,
129
131
  writable: false,
@@ -0,0 +1,71 @@
1
+ //#region src/lib.d.ts
2
+ type PrimitiveNodeType = Node | string | boolean | number | bigint | symbol | Date | RegExp | null | undefined;
3
+ //#endregion
4
+ //#region src/polyfill.d.ts
5
+ declare global {
6
+ interface SymbolConstructor {
7
+ readonly dispose: symbol;
8
+ }
9
+ interface Disposable {
10
+ [Symbol.dispose](): void;
11
+ }
12
+ }
13
+ //#endregion
14
+ //#region src/slot.d.ts
15
+ /**
16
+ * A lightweight slot that reserves a region in the DOM using comment markers.
17
+ * Content between the markers can be replaced dynamically without wrapper elements.
18
+ */
19
+ declare class Slot {
20
+ #private;
21
+ /**
22
+ * Render the slot as a DocumentFragment.
23
+ * If not yet mounted, inserts the comment markers and optional default content.
24
+ * If already mounted, extracts and returns the current content WITHOUT disposing
25
+ * it — the caller takes ownership of the returned nodes and is responsible for
26
+ * their disposal.
27
+ */
28
+ render(defaultContent?: PrimitiveNodeType): DocumentFragment;
29
+ /** Dispose reactive children and remove all content between the markers. */
30
+ clear(): void;
31
+ /**
32
+ * Replace the slot's content with the given element.
33
+ * No-op if the slot is not mounted or the content is identical.
34
+ */
35
+ set(element: Node): void;
36
+ /**
37
+ * Extract and return the current slot content as a DocumentFragment.
38
+ * Returns `null` if the slot is not mounted.
39
+ * Content is NOT disposed — the caller takes ownership and is responsible
40
+ * for disposal.
41
+ */
42
+ get(): DocumentFragment | null;
43
+ /** Returns the parent node if the slot is mounted, otherwise `null`. */
44
+ parent(): ParentNode | null;
45
+ /** Whether the slot's comment markers are attached to the DOM. */
46
+ isMounted(): boolean;
47
+ }
48
+ /**
49
+ * Symbol key for attaching a slot collection to a custom element instance.
50
+ * Prevents collisions with public Element properties and signals to the JSX
51
+ * runtime that this property holds slot wiring (not regular children).
52
+ *
53
+ * The value at `[SLOTS]` is a plain object whose keys are slot names and whose
54
+ * values are {@link Slot} instances. Declare with `as const` so TypeScript
55
+ * preserves the literal key union — this is what `ElementProps<typeof Cls>`
56
+ * uses to synthesize `slot:${K}` entries.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * class Card extends HTMLElement {
61
+ * // ✅ literal keys flow through — "header" | "footer"
62
+ * [SLOTS] = { header: new Slot(), footer: new Slot() } as const;
63
+ * }
64
+ *
65
+ * // ❌ widens — no typed slot:* props
66
+ * // [SLOTS] = { header: new Slot(), footer: new Slot() };
67
+ * ```
68
+ */
69
+ declare const SLOTS: unique symbol;
70
+ //#endregion
71
+ export { Slot as n, PrimitiveNodeType as r, SLOTS as t };