elements-kit 0.0.18 → 0.0.20

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 (110) hide show
  1. package/README.md +65 -118
  2. package/dist/{attributes-Dtn68R1u.d.mts → attributes-DILeh3-s.d.mts} +42 -9
  3. package/dist/attributes.d.mts +1 -1
  4. package/dist/attributes.mjs +32 -0
  5. package/dist/{define-CjbTZ3VG.d.mts → custom-elements-D5_NMNyD.d.mts} +20 -2
  6. package/dist/custom-elements.d.mts +2 -74
  7. package/dist/custom-elements.mjs +15 -86
  8. package/dist/{element-CGVy_8TW.mjs → element-w1GCIMVp.mjs} +33 -21
  9. package/dist/for.d.mts +31 -2
  10. package/dist/for.mjs +18 -2
  11. package/dist/infer-DuFY-y2b.d.mts +657 -0
  12. package/dist/integrations/react.d.mts +1 -1
  13. package/dist/integrations/react.mjs +6 -4
  14. package/dist/jsx-runtime/index.d.mts +2 -73
  15. package/dist/jsx-runtime/index.mjs +8 -14
  16. package/dist/{signals-J8dK_rA4.mjs → lib-D6duEs38.mjs} +1 -105
  17. package/dist/render.d.mts +21 -0
  18. package/dist/render.mjs +32 -0
  19. package/dist/scope-DM2gzOkb.mjs +45 -0
  20. package/dist/signals/index.d.mts +1 -1
  21. package/dist/signals/index.mjs +134 -1
  22. package/dist/{slot-Kb61AcgW.mjs → slot-CKtUoy2X.mjs} +0 -1
  23. package/dist/{slot-C7GQZe-r.d.mts → slot-D5iBUSAm.d.mts} +18 -1
  24. package/dist/slot.d.mts +1 -1
  25. package/dist/slot.mjs +1 -1
  26. package/dist/{test.BmQO5GaM-DfGStnii.mjs → test.BmQO5GaM-BeO5pvCo.mjs} +1 -1
  27. package/dist/utilities/_observe.mjs +2 -1
  28. package/dist/utilities/active-element.d.mts +1 -1
  29. package/dist/utilities/active-element.mjs +2 -1
  30. package/dist/utilities/active-element.test.mjs +1 -1
  31. package/dist/utilities/async.d.mts +39 -1
  32. package/dist/utilities/async.mjs +39 -1
  33. package/dist/utilities/async.test.mjs +3 -2
  34. package/dist/utilities/debounced.d.mts +12 -1
  35. package/dist/utilities/debounced.mjs +13 -1
  36. package/dist/utilities/debounced.test.mjs +3 -2
  37. package/dist/utilities/element-rect.d.mts +1 -1
  38. package/dist/utilities/element-rect.mjs +2 -1
  39. package/dist/utilities/element-rect.test.mjs +3 -2
  40. package/dist/utilities/element-scroll.d.mts +1 -1
  41. package/dist/utilities/element-scroll.test.mjs +3 -2
  42. package/dist/utilities/environment.d.mts +2 -0
  43. package/dist/utilities/environment.mjs +2 -0
  44. package/dist/utilities/event-driven.d.mts +1 -1
  45. package/dist/utilities/event-driven.mjs +2 -1
  46. package/dist/utilities/event-listener.d.mts +12 -1
  47. package/dist/utilities/event-listener.mjs +2 -1
  48. package/dist/utilities/event-listener.test.mjs +3 -2
  49. package/dist/utilities/focus-within.d.mts +1 -1
  50. package/dist/utilities/focus-within.mjs +2 -1
  51. package/dist/utilities/focus-within.test.mjs +3 -2
  52. package/dist/utilities/hover.d.mts +1 -1
  53. package/dist/utilities/hover.mjs +2 -1
  54. package/dist/utilities/hover.test.mjs +3 -2
  55. package/dist/utilities/intersection-observer.test.mjs +3 -2
  56. package/dist/utilities/interval.d.mts +14 -1
  57. package/dist/utilities/interval.mjs +2 -1
  58. package/dist/utilities/interval.test.mjs +3 -2
  59. package/dist/utilities/location.d.mts +1 -1
  60. package/dist/utilities/location.mjs +2 -1
  61. package/dist/utilities/location.test.mjs +1 -1
  62. package/dist/utilities/long-press.test.mjs +3 -2
  63. package/dist/utilities/media-devices.d.mts +1 -1
  64. package/dist/utilities/media-devices.mjs +2 -1
  65. package/dist/utilities/media-devices.test.mjs +3 -2
  66. package/dist/utilities/media-player.d.mts +1 -1
  67. package/dist/utilities/media-player.test.mjs +3 -2
  68. package/dist/utilities/media-query.d.mts +1 -1
  69. package/dist/utilities/media-query.mjs +2 -1
  70. package/dist/utilities/mutation-observer.test.mjs +3 -2
  71. package/dist/utilities/network.d.mts +1 -1
  72. package/dist/utilities/network.mjs +2 -1
  73. package/dist/utilities/network.test.mjs +1 -1
  74. package/dist/utilities/on-click-outside.test.mjs +3 -2
  75. package/dist/utilities/orientation.d.mts +1 -1
  76. package/dist/utilities/orientation.mjs +2 -1
  77. package/dist/utilities/previous.d.mts +13 -1
  78. package/dist/utilities/previous.mjs +14 -1
  79. package/dist/utilities/previous.test.mjs +3 -2
  80. package/dist/utilities/promise.d.mts +7 -1
  81. package/dist/utilities/promise.mjs +2 -1
  82. package/dist/utilities/promise.test.mjs +3 -2
  83. package/dist/utilities/retry.d.mts +15 -0
  84. package/dist/utilities/retry.mjs +17 -1
  85. package/dist/utilities/retry.test.mjs +3 -2
  86. package/dist/utilities/routing.d.mts +12 -1
  87. package/dist/utilities/routing.mjs +13 -1
  88. package/dist/utilities/routing.test.mjs +1 -1
  89. package/dist/utilities/search-params.d.mts +1 -1
  90. package/dist/utilities/search-params.test.mjs +3 -2
  91. package/dist/utilities/ssr.test.mjs +1 -1
  92. package/dist/utilities/storage.d.mts +18 -1
  93. package/dist/utilities/storage.mjs +17 -0
  94. package/dist/utilities/storage.test.mjs +3 -2
  95. package/dist/utilities/throttled.d.mts +12 -1
  96. package/dist/utilities/throttled.mjs +13 -1
  97. package/dist/utilities/throttled.test.mjs +3 -2
  98. package/dist/utilities/timeout.d.mts +1 -1
  99. package/dist/utilities/timeout.mjs +2 -1
  100. package/dist/utilities/timeout.test.mjs +3 -2
  101. package/dist/utilities/window-focus.d.mts +1 -1
  102. package/dist/utilities/window-focus.mjs +2 -1
  103. package/dist/utilities/window-size.d.mts +1 -1
  104. package/dist/utilities/window-size.mjs +2 -1
  105. package/dist/utilities/window-size.test.mjs +1 -1
  106. package/package.json +1 -1
  107. package/dist/index-DydGTqZU.d.mts +0 -315
  108. package/dist/infer-BfzRJoCn.d.mts +0 -203
  109. package/dist/polyfill-BVNd6ogU.d.mts +0 -9
  110. /package/dist/{magic-string.es-i62WTP6J.mjs → magic-string.es-cTgJnTCj.mjs} +0 -0
@@ -1,100 +1,29 @@
1
- import { b as untracked, f as effectScope } from "./signals-J8dK_rA4.mjs";
2
- //#region src/define.ts
1
+ //#region src/custom-elements.ts
3
2
  /**
4
3
  * Register a custom element with the browser and return its class.
5
4
  * Pair with a module augmentation of `CustomElementRegistry` to get typed JSX.
6
- */
7
- function defineElement(tag, cls, options) {
8
- customElements.define(tag, cls, options);
9
- return cls;
10
- }
11
- //#endregion
12
- //#region src/custom-elements.ts
13
- /**
14
- * Runs `setup` inside a fresh `effectScope` and returns both its result and
15
- * the scope's dispose handle.
16
- *
17
- * Use this wherever you need to run reactive code with an explicit lifetime
18
- * outside the JSX element flow — most commonly inside a custom element's
19
- * `connectedCallback`. `onCleanup`, nested `effect`s and any other
20
- * scope-bound registrations made in `setup` are owned by the returned
21
- * `dispose`.
22
- *
23
- * `untracked` detaches the new scope from any enclosing effect so it isn't
24
- * torn down when that effect re-runs — its lifetime is solely the caller's
25
- * responsibility.
26
5
  *
27
6
  * @example
28
- * ```ts
29
- * class Clock extends HTMLElement {
30
- * #dispose?: () => void;
7
+ * ```tsx
8
+ * import { defineElement } from "elements-kit/custom-elements";
31
9
  *
32
- * connectedCallback() {
33
- * const { dispose } = renderScope(() => {
34
- * const id = setInterval(() => (this.textContent = String(Date.now())), 1000);
35
- * onCleanup(() => clearInterval(id));
36
- * });
37
- * this.#dispose = dispose;
38
- * }
10
+ * class XCounter extends HTMLElement {}
39
11
  *
40
- * disconnectedCallback() {
41
- * this.#dispose?.();
42
- * this.#dispose = undefined;
43
- * }
44
- * }
45
- * ```
46
- */
47
- function renderScope(setup) {
48
- let result;
49
- let dispose;
50
- untracked(() => {
51
- dispose = effectScope(() => {
52
- result = setup();
53
- });
54
- });
55
- return {
56
- result,
57
- dispose
58
- };
59
- }
60
- const scopes = /* @__PURE__ */ new WeakMap();
61
- /**
62
- * Runs `setup` inside an `effectScope` tied to `el`'s connected lifetime.
63
- *
64
- * Call from `connectedCallback`. Effects, `onCleanup` registrations, and
65
- * reactive reads inside `setup` belong to this scope. Pair with
66
- * {@link disconnectedScope} from `disconnectedCallback` to dispose.
12
+ * defineElement("x-counter", XCounter);
67
13
  *
68
- * Safe to call more than once (e.g. if the element is reconnected after
69
- * disconnection): the previous scope is disposed first.
70
- *
71
- * @example
72
- * ```ts
73
- * class Clock extends HTMLElement {
74
- * connectedCallback() {
75
- * connectedScope(this, () => {
76
- * const id = setInterval(() => this.textContent = String(Date.now()), 1000);
77
- * onCleanup(() => clearInterval(id));
78
- * });
79
- * }
80
- * disconnectedCallback() {
81
- * disconnectedScope(this);
14
+ * declare module "elements-kit/custom-elements" {
15
+ * interface CustomElementRegistry {
16
+ * "x-counter": typeof XCounter;
82
17
  * }
83
18
  * }
19
+ *
20
+ * // JSX now gets typed props + typed ref
21
+ * // <x-counter />
84
22
  * ```
85
23
  */
86
- function connectedScope(el, setup) {
87
- scopes.get(el)?.();
88
- const { dispose } = renderScope(setup);
89
- scopes.set(el, dispose);
90
- }
91
- /**
92
- * Disposes the scope previously created by {@link connectedScope} for `el`.
93
- * No-op if there is no active scope.
94
- */
95
- function disconnectedScope(el) {
96
- scopes.get(el)?.();
97
- scopes.delete(el);
24
+ function defineElement(tag, cls, options) {
25
+ customElements.define(tag, cls, options);
26
+ return cls;
98
27
  }
99
28
  //#endregion
100
- export { connectedScope, defineElement, disconnectedScope, renderScope };
29
+ export { defineElement };
@@ -1,7 +1,8 @@
1
- import { _ as onCleanup, b as untracked, d as effect, f as effectScope, t as isReactive } from "./signals-J8dK_rA4.mjs";
1
+ import { c as effectScope, g as untracked, p as onCleanup, s as effect } from "./lib-D6duEs38.mjs";
2
2
  import "./polyfill-B1lNNcum.mjs";
3
+ import { isReactive, resolveProps } from "./signals/index.mjs";
3
4
  import { on } from "./utilities/event-listener.mjs";
4
- import { i as resolveNode$1, n as Slot, r as Slots, t as SLOTS } from "./slot-Kb61AcgW.mjs";
5
+ import { i as resolveNode$1, n as Slot, r as Slots, t as SLOTS } from "./slot-CKtUoy2X.mjs";
5
6
  //#region \0rolldown/runtime.js
6
7
  var __defProp = Object.defineProperty;
7
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -85,23 +86,34 @@ function applySlot(slot, value) {
85
86
  });
86
87
  }
87
88
  function mountChildren(el, value) {
88
- for (const child of ensureFlatArray(value)) {
89
- if (typeof child === "function") {
90
- const slot = Slot.new();
91
- el.appendChild(slot());
92
- effectScope(() => {
93
- effect(() => slot.set(resolveChild(child())));
94
- onCleanup(() => slot.clear());
95
- });
96
- continue;
97
- }
98
- const node = resolveChild(child);
99
- const dispose = node[Symbol.dispose];
100
- el.appendChild(node);
101
- if (dispose) effectScope(() => {
102
- onCleanup(dispose);
89
+ for (const child of ensureFlatArray(value)) mountChild(el, child);
90
+ }
91
+ /**
92
+ * Mounts a single child into `el`. Reactive functions become live slots; other
93
+ * values append as-is. Each child owns its own `effectScope` so sibling
94
+ * `onCleanup` registrations don't overwrite each other (the signals lib
95
+ * supports only one onCleanup per subscriber).
96
+ *
97
+ * Also used by `createFunctionElement` when a component returns a reactive
98
+ * getter or primitive — keeps the component's `effectScope` alive for the
99
+ * lifetime of the fragment it mounts into.
100
+ */
101
+ function mountChild(el, child) {
102
+ if (typeof child === "function") {
103
+ const slot = Slot.new();
104
+ el.appendChild(slot());
105
+ effectScope(() => {
106
+ effect(() => slot.set(resolveChild(child())));
107
+ onCleanup(() => slot.clear());
103
108
  });
109
+ return;
104
110
  }
111
+ const node = resolveChild(child);
112
+ const dispose = node[Symbol.dispose];
113
+ el.appendChild(node);
114
+ if (dispose) effectScope(() => {
115
+ onCleanup(dispose);
116
+ });
105
117
  }
106
118
  function resolveChild(value) {
107
119
  if (Array.isArray(value)) {
@@ -209,10 +221,10 @@ function setAttribute(el, key, value) {
209
221
  else el.setAttribute(key, value === true ? "" : String(value));
210
222
  }
211
223
  function isEventKey(key) {
212
- return key.startsWith("on:") || key.length > 2 && key.startsWith("on") && key[2] >= "A" && key[2] <= "Z";
224
+ return key.startsWith("on:");
213
225
  }
214
226
  function eventName(key) {
215
- return key.startsWith("on:") ? key.slice(3) : key[2].toLowerCase() + key.slice(3);
227
+ return key.slice(3);
216
228
  }
217
229
  //#endregion
218
230
  //#region src/jsx-runtime/element.ts
@@ -229,7 +241,7 @@ function createFunctionElement(type, props, ref) {
229
241
  let dispose;
230
242
  untracked(() => {
231
243
  dispose = effectScope(() => {
232
- el = type(props);
244
+ el = type(resolveProps(props));
233
245
  if (typeof ref === "function" && el instanceof Element) ref(el);
234
246
  });
235
247
  });
@@ -280,4 +292,4 @@ function attachDisposables(el, disposables) {
280
292
  });
281
293
  }
282
294
  //#endregion
283
- export { disposeElement as n, createElement as t };
295
+ export { disposeElement as n, mountChild as r, createElement as t };
package/dist/for.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Props, o as Require } from "./infer-BfzRJoCn.mjs";
1
+ import { i as Props, s as Require } from "./infer-DuFY-y2b.mjs";
2
2
 
3
3
  //#region src/for.d.ts
4
4
  type KeyFn<T> = (item: T, index: number) => string | number;
@@ -30,8 +30,37 @@ type RenderFn<T> = (item: T, index: number) => Element | DocumentFragment | null
30
30
  * Props for `<For>`, derived from its public instance fields.
31
31
  * All props are optional — the class initializes sane defaults at runtime.
32
32
  * Non-function props also accept a reactive getter.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * import { signal } from "elements-kit/signals";
37
+ * import { For } from "elements-kit";
38
+ *
39
+ * const todos = signal([{ id: 1, text: "write docs" }]);
40
+ *
41
+ * const props: ForProps<{ id: number; text: string }> = {
42
+ * each: todos,
43
+ * by: (t) => t.id,
44
+ * children: (t) => <li>{t.text}</li>,
45
+ * };
46
+ * ```
33
47
  */
34
48
  type ForProps<T> = Require<Props<For<T>>, "each" | "children">;
49
+ /**
50
+ * Keyed list renderer. See {@link ForProps} for prop details.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * import { signal } from "elements-kit/signals";
55
+ * import { For } from "elements-kit";
56
+ *
57
+ * const todos = signal([{ id: 1, text: "write docs" }]);
58
+ *
59
+ * <For each={todos} by={(t) => t.id}>
60
+ * {(t) => <li>{t.text}</li>}
61
+ * </For>
62
+ * ```
63
+ */
35
64
  declare class For<T = unknown> {
36
65
  #private;
37
66
  constructor(_props?: ForProps<T>);
@@ -42,4 +71,4 @@ declare class For<T = unknown> {
42
71
  render(): DocumentFragment;
43
72
  }
44
73
  //#endregion
45
- export { For, ForProps };
74
+ export { For };
package/dist/for.mjs CHANGED
@@ -1,6 +1,22 @@
1
- import { n as disposeElement } from "./element-CGVy_8TW.mjs";
2
- import { _ as onCleanup, b as untracked, d as effect, f as effectScope, v as signal, y as trigger } from "./signals-J8dK_rA4.mjs";
1
+ import { n as disposeElement } from "./element-w1GCIMVp.mjs";
2
+ import { c as effectScope, g as untracked, h as trigger, m as signal, p as onCleanup, s as effect } from "./lib-D6duEs38.mjs";
3
+ import "./signals/index.mjs";
3
4
  //#region src/for.ts
5
+ /**
6
+ * Keyed list renderer. See {@link ForProps} for prop details.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { signal } from "elements-kit/signals";
11
+ * import { For } from "elements-kit";
12
+ *
13
+ * const todos = signal([{ id: 1, text: "write docs" }]);
14
+ *
15
+ * <For each={todos} by={(t) => t.id}>
16
+ * {(t) => <li>{t.text}</li>}
17
+ * </For>
18
+ * ```
19
+ */
4
20
  var For = class {
5
21
  constructor(_props) {}
6
22
  #each = signal([]);