elements-kit 0.0.17 → 0.0.19

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 (103) hide show
  1. package/README.md +97 -19
  2. package/dist/attributes.d.mts +1 -1
  3. package/dist/{define-CjbTZ3VG.d.mts → custom-elements-bVYOkHKt.d.mts} +2 -2
  4. package/dist/custom-elements.d.mts +2 -74
  5. package/dist/custom-elements.mjs +2 -91
  6. package/dist/{element-CGVy_8TW.mjs → element-DxmInKJw.mjs} +32 -20
  7. package/dist/for.d.mts +1 -1
  8. package/dist/for.mjs +3 -2
  9. package/dist/infer-Dv5Wk-7E.d.mts +618 -0
  10. package/dist/integrations/react.d.mts +1 -1
  11. package/dist/integrations/react.mjs +6 -4
  12. package/dist/jsx-runtime/index.d.mts +2 -73
  13. package/dist/jsx-runtime/index.mjs +8 -14
  14. package/dist/{signals-J8dK_rA4.mjs → lib-D6duEs38.mjs} +1 -105
  15. package/dist/render.d.mts +21 -0
  16. package/dist/render.mjs +32 -0
  17. package/dist/scope-DM2gzOkb.mjs +45 -0
  18. package/dist/signals/index.d.mts +1 -1
  19. package/dist/signals/index.mjs +115 -1
  20. package/dist/{slot-C7GQZe-r.d.mts → slot-B5_VHB7E.d.mts} +10 -0
  21. package/dist/slot.d.mts +1 -1
  22. package/dist/{test.BmQO5GaM-DfGStnii.mjs → test.BmQO5GaM-BeO5pvCo.mjs} +1 -1
  23. package/dist/utilities/_observe.mjs +2 -1
  24. package/dist/utilities/active-element.d.mts +1 -1
  25. package/dist/utilities/active-element.mjs +2 -1
  26. package/dist/utilities/active-element.test.mjs +1 -1
  27. package/dist/utilities/async.d.mts +1 -1
  28. package/dist/utilities/async.mjs +2 -1
  29. package/dist/utilities/async.test.mjs +3 -2
  30. package/dist/utilities/debounced.d.mts +1 -1
  31. package/dist/utilities/debounced.mjs +2 -1
  32. package/dist/utilities/debounced.test.mjs +3 -2
  33. package/dist/utilities/element-rect.d.mts +1 -1
  34. package/dist/utilities/element-rect.mjs +2 -1
  35. package/dist/utilities/element-rect.test.mjs +3 -2
  36. package/dist/utilities/element-scroll.d.mts +1 -1
  37. package/dist/utilities/element-scroll.test.mjs +3 -2
  38. package/dist/utilities/event-driven.d.mts +1 -1
  39. package/dist/utilities/event-driven.mjs +2 -1
  40. package/dist/utilities/event-listener.d.mts +1 -1
  41. package/dist/utilities/event-listener.mjs +2 -1
  42. package/dist/utilities/event-listener.test.mjs +3 -2
  43. package/dist/utilities/focus-within.d.mts +1 -1
  44. package/dist/utilities/focus-within.mjs +2 -1
  45. package/dist/utilities/focus-within.test.mjs +3 -2
  46. package/dist/utilities/hover.d.mts +1 -1
  47. package/dist/utilities/hover.mjs +2 -1
  48. package/dist/utilities/hover.test.mjs +3 -2
  49. package/dist/utilities/intersection-observer.test.mjs +3 -2
  50. package/dist/utilities/interval.d.mts +1 -1
  51. package/dist/utilities/interval.mjs +2 -1
  52. package/dist/utilities/interval.test.mjs +3 -2
  53. package/dist/utilities/location.d.mts +1 -1
  54. package/dist/utilities/location.mjs +2 -1
  55. package/dist/utilities/location.test.mjs +1 -1
  56. package/dist/utilities/long-press.test.mjs +3 -2
  57. package/dist/utilities/media-devices.d.mts +1 -1
  58. package/dist/utilities/media-devices.mjs +2 -1
  59. package/dist/utilities/media-devices.test.mjs +3 -2
  60. package/dist/utilities/media-player.d.mts +1 -1
  61. package/dist/utilities/media-player.test.mjs +3 -2
  62. package/dist/utilities/media-query.d.mts +1 -1
  63. package/dist/utilities/media-query.mjs +2 -1
  64. package/dist/utilities/mutation-observer.test.mjs +3 -2
  65. package/dist/utilities/network.d.mts +1 -1
  66. package/dist/utilities/network.mjs +2 -1
  67. package/dist/utilities/network.test.mjs +1 -1
  68. package/dist/utilities/on-click-outside.test.mjs +3 -2
  69. package/dist/utilities/orientation.d.mts +1 -1
  70. package/dist/utilities/orientation.mjs +2 -1
  71. package/dist/utilities/previous.d.mts +1 -1
  72. package/dist/utilities/previous.mjs +2 -1
  73. package/dist/utilities/previous.test.mjs +3 -2
  74. package/dist/utilities/promise.d.mts +1 -1
  75. package/dist/utilities/promise.mjs +2 -1
  76. package/dist/utilities/promise.test.mjs +3 -2
  77. package/dist/utilities/retry.mjs +2 -1
  78. package/dist/utilities/retry.test.mjs +3 -2
  79. package/dist/utilities/routing.d.mts +1 -1
  80. package/dist/utilities/routing.mjs +2 -1
  81. package/dist/utilities/routing.test.mjs +1 -1
  82. package/dist/utilities/search-params.d.mts +1 -1
  83. package/dist/utilities/search-params.test.mjs +3 -2
  84. package/dist/utilities/ssr.test.mjs +1 -1
  85. package/dist/utilities/storage.d.mts +1 -1
  86. package/dist/utilities/storage.test.mjs +3 -2
  87. package/dist/utilities/throttled.d.mts +1 -1
  88. package/dist/utilities/throttled.mjs +2 -1
  89. package/dist/utilities/throttled.test.mjs +3 -2
  90. package/dist/utilities/timeout.d.mts +1 -1
  91. package/dist/utilities/timeout.mjs +2 -1
  92. package/dist/utilities/timeout.test.mjs +3 -2
  93. package/dist/utilities/window-focus.d.mts +1 -1
  94. package/dist/utilities/window-focus.mjs +2 -1
  95. package/dist/utilities/window-size.d.mts +1 -1
  96. package/dist/utilities/window-size.mjs +2 -1
  97. package/dist/utilities/window-size.test.mjs +1 -1
  98. package/package.json +6 -1
  99. package/dist/index-DydGTqZU.d.mts +0 -315
  100. package/dist/infer-BfzRJoCn.d.mts +0 -203
  101. package/dist/polyfill-BVNd6ogU.d.mts +0 -9
  102. /package/dist/{attributes-Dtn68R1u.d.mts → attributes-aiRoArZz.d.mts} +0 -0
  103. /package/dist/{magic-string.es-i62WTP6J.mjs → magic-string.es-cTgJnTCj.mjs} +0 -0
@@ -1,315 +0,0 @@
1
- //#region src/signals/lib.d.ts
2
- declare const SIGNAL: unique symbol;
3
- declare const COMPUTED: unique symbol;
4
- declare const EFFECT: unique symbol;
5
- declare const EFFECT_SCOPE: unique symbol;
6
- /**
7
- * Returns `true` if `fn` is a signal handle created by {@link signal}.
8
- *
9
- * Relies on the SIGNAL symbol.
10
- */
11
- declare function isSignal(fn: unknown): boolean;
12
- /**
13
- * Returns `true` if `fn` is a computed handle created by {@link computed}.
14
- *
15
- * Relies on the COMPUTED symbol.
16
- */
17
- declare function isComputed(fn: unknown): boolean;
18
- /**
19
- * Returns `true` if `fn` is an effect cleanup handle created by {@link effect}.
20
- *
21
- * Relies on the EFFECT symbol.
22
- */
23
- declare function isEffect(fn: unknown): boolean;
24
- /**
25
- * Returns `true` if `fn` is an effectScope cleanup handle created by
26
- * {@link effectScope}.
27
- *
28
- * Relies on `Function.name` matching the internal `effectScopeOper` function name.
29
- */
30
- declare function isEffectScope(fn: () => void): boolean;
31
- /**
32
- * Creates a mutable reactive signal.
33
- *
34
- * - **Read**: call with no arguments → returns the current value and
35
- * subscribes the active tracking context.
36
- * - **Write**: call with a value → updates the signal and schedules
37
- * downstream effects if the value changed.
38
- *
39
- * @example
40
- * ```ts
41
- * const count = signal(0);
42
- * count(); // → 0 (read)
43
- * count(1); // write – effects depending on count will re-run
44
- * count(); // → 1
45
- * ```
46
- */
47
- declare function signal<T>(): Updater<T> & Computed<T>;
48
- declare function signal<T>(initialValue: T): Updater<T> & Computed<T>;
49
- /**
50
- * Creates a lazily-evaluated computed value.
51
- *
52
- * The `getter` is only called when the computed value is read **and** one of
53
- * its dependencies has changed since the last evaluation. If nothing has
54
- * changed the cached `value` is returned without re-running `getter`.
55
- *
56
- * Computed values are read-only; they cannot be set directly.
57
- *
58
- * @param getter - Pure function deriving a value from other reactive sources.
59
- * Receives the previous value as an optional optimisation hint.
60
- *
61
- * @example
62
- * ```ts
63
- * const a = signal(1);
64
- * const b = signal(2);
65
- * const sum = computed(() => a() + b());
66
- *
67
- * sum(); // → 3
68
- * a(10);
69
- * sum(); // → 12 (re-evaluated lazily)
70
- * ```
71
- */
72
- declare function computed<T>(getter: (previousValue?: T) => T): () => T;
73
- /**
74
- * Creates a reactive side-effect that runs immediately and re-runs whenever
75
- * any signal or computed it read during its last execution changes.
76
- *
77
- * Use {@link onCleanup} inside `fn` to register teardown logic that runs
78
- * before each re-execution and on final disposal.
79
- *
80
- * If `effect` is called inside an `effectScope` or another `effect`, the
81
- * new effect is automatically owned by the outer scope and will be disposed
82
- * when the scope is disposed.
83
- *
84
- * @param fn - The side-effect body. Reactive reads inside this function
85
- * establish dependency links.
86
- * @returns A disposal function. Call it to stop the effect and run any
87
- * registered cleanup.
88
- *
89
- * @example
90
- * ```ts
91
- * const url = signal('/api/data');
92
- *
93
- * const stop = effect(() => {
94
- * const controller = new AbortController();
95
- * fetch(url(), { signal: controller.signal });
96
- * onCleanup(() => controller.abort());
97
- * });
98
- *
99
- * url('/api/other'); // previous fetch is aborted, new one starts
100
- * stop(); // final cleanup: abort the last fetch
101
- * ```
102
- */
103
- declare function effect(fn: () => void): () => void;
104
- /**
105
- * Creates an ownership scope that groups reactive effects so they can all be
106
- * disposed at once.
107
- *
108
- * Effects and nested scopes created inside `fn` are linked to this scope.
109
- * When the returned disposal function is called, all owned effects are stopped
110
- * in cascade – triggering their registered {@link onCleanup} callbacks – and
111
- * the scope itself is removed from any parent scope that owns it.
112
- *
113
- * @param fn - Synchronous setup function. Create effects and nested scopes
114
- * here.
115
- * @returns A disposal function that tears down all owned effects and the scope
116
- * itself.
117
- *
118
- * @example
119
- * ```ts
120
- * const stopAll = effectScope(() => {
121
- * effect(() => console.log('a:', a()));
122
- * effect(() => console.log('b:', b()));
123
- * });
124
- *
125
- * stopAll(); // both effects stopped simultaneously
126
- * ```
127
- */
128
- declare function effectScope(fn: () => void): () => void;
129
- /**
130
- * Registers a cleanup callback for the currently executing effect or scope.
131
- *
132
- * The callback will be called:
133
- * 1. **Before the next re-run** of the enclosing effect (so resources from
134
- * the previous run are released before the new run sets them up again).
135
- * 2. **On final disposal** of the effect, whether triggered explicitly by
136
- * calling the effect's cleanup handle or implicitly by an owning
137
- * `effectScope` being disposed.
138
- *
139
- * Calling `onCleanup` outside of a tracking context (no active effect) is a
140
- * no-op; it does **not** throw.
141
- *
142
- * Only one cleanup function per effect run is supported. Calling `onCleanup`
143
- * multiple times within the same run overwrites the previous registration.
144
- *
145
- * @param fn - The teardown callback.
146
- *
147
- * @example
148
- * ```ts
149
- * effect(() => {
150
- * const id = setInterval(() => tick(), 1000);
151
- * onCleanup(() => clearInterval(id));
152
- * });
153
- * ```
154
- *
155
- * @example Composable helper – no prop-drilling needed:
156
- * ```ts
157
- * function useEventListener(target: EventTarget, type: string, handler: EventListener) {
158
- * target.addEventListener(type, handler);
159
- * onCleanup(() => target.removeEventListener(type, handler));
160
- * }
161
- *
162
- * effect(() => {
163
- * useEventListener(window, 'resize', onResize);
164
- * });
165
- * ```
166
- */
167
- declare function onCleanup(fn: () => void): void;
168
- /**
169
- * Runs `fn` as a single atomic update: all signal writes inside `fn` are
170
- * collected and effects are flushed only once after `fn` returns, rather than
171
- * after each individual write.
172
- *
173
- * Batches can be nested; the flush only occurs when the outermost batch
174
- * completes.
175
- *
176
- * @example
177
- * ```ts
178
- * batch(() => {
179
- * x(1);
180
- * y(2);
181
- * z(3);
182
- * }); // effects that depend on x, y, or z run once here
183
- * ```
184
- */
185
- declare function batch(fn: () => void): void;
186
- /**
187
- * Executes `fn` in a non-tracking context: any signals read inside `fn` do
188
- * **not** create dependency links on the currently active subscriber.
189
- *
190
- * Useful when you need to read a signal's current value without subscribing to
191
- * future changes.
192
- *
193
- * @returns The value returned by `fn`.
194
- *
195
- * @example
196
- * ```ts
197
- * const logCount = effect(() => {
198
- * console.log('triggered by a:', a());
199
- * // read b without subscribing – effect won't re-run when b changes
200
- * console.log('current b:', untracked(b));
201
- * });
202
- * ```
203
- */
204
- declare function untracked<T>(fn: Computed<T>): T;
205
- /**
206
- * Manually triggers all subscribers of every signal read inside `fn`.
207
- *
208
- * Unlike writing to a signal, `trigger` does not change the signal's value; it
209
- * only forces downstream effects and computeds to re-evaluate.
210
- *
211
- * @param fn - Function whose reactive reads identify the signals to trigger.
212
- *
213
- * @example
214
- * ```ts
215
- * const items = signal([1, 2, 3]);
216
- *
217
- * // Mutate in place (referential equality won't detect the change):
218
- * items().push(4);
219
- * trigger(items); // manually notify subscribers
220
- * ```
221
- */
222
- declare function trigger<T = void>(fn: Computed<T>): void;
223
- //#endregion
224
- //#region src/signals/index.d.ts
225
- declare function isReactive<T>(value: MaybeReactive<T>): value is () => T;
226
- type Updater<T> = (value: T) => void;
227
- type Computed<T> = () => T;
228
- type Signal<T> = Updater<T> & Computed<T>;
229
- /**
230
- * A decorator that makes a class field reactive by automatically wrapping its value in a signal.
231
- *
232
- * The field behaves like a normal property (get/set) but reactivity is tracked under the hood.
233
- * Any reads will subscribe to the signal and any writes will trigger updates.
234
- *
235
- * @example
236
- * ```ts
237
- * class Counter {
238
- * @reactive()
239
- * count: number = 0;
240
- * }
241
- *
242
- * const counter = new Counter();
243
- * counter.count++; // Triggers reactivity
244
- * console.log(counter.count); // Subscribes to changes
245
- * ```
246
- *
247
- * @remarks
248
- * Equivalent to manually creating a private signal and getter/setter:
249
- * ```ts
250
- * class Counter {
251
- * #count = signal(0);
252
- * get count() { return this.#count(); }
253
- * set count(value) { this.#count(value); }
254
- * }
255
- * ```
256
- */
257
- declare function reactive<This extends object, Value>(source?: (self: This) => Signal<Value>): (_target: unknown, context: ClassFieldDecoratorContext<This, Value>) => (this: This, initialValue: Value) => Value;
258
- /**
259
- * A value that may be static or reactive. Accepts a plain `T` or a
260
- * zero-arg getter (`() => T`) — typically a `signal` or `computed`.
261
- *
262
- * Used across the library anywhere a prop or attribute may be bound to
263
- * reactive state. Resolve with {@link resolve}, detect with {@link isReactive}.
264
- *
265
- * @template T — the value type.
266
- *
267
- * @example
268
- * ```ts
269
- * import { signal, computed } from "elements-kit/signals";
270
- *
271
- * const count = signal(0);
272
- * const double = computed(() => count() * 2);
273
- *
274
- * const a: MaybeReactive<number> = 5; // static
275
- * const b: MaybeReactive<number> = count; // signal (getter)
276
- * const c: MaybeReactive<number> = double; // computed (getter)
277
- * ```
278
- */
279
- type MaybeReactive<T> = T | Computed<T>;
280
- /**
281
- * Resolve a {@link MaybeReactive} to its current value. Calls the getter
282
- * when reactive; returns the value as-is when static.
283
- *
284
- * @example
285
- * ```ts
286
- * resolve(5); // 5
287
- * resolve(() => count()); // current count value
288
- * ```
289
- */
290
- declare function resolve<T>(value: MaybeReactive<T>): T;
291
- /**
292
- * Turn a reactive-props object into a bag of per-key getters. Callers may
293
- * pass values or reactive sources (`signal`, `computed`); reading
294
- * `props.name()` inside an effect or JSX getter subscribes to whatever
295
- * drives it. Static values become stable thunks, signals and computed pass
296
- * through unchanged — so identity is preserved (`props.name === props.name`).
297
- *
298
- * @example
299
- * ```tsx
300
- * import { resolveProps } from "elements-kit/signals";
301
- *
302
- * function Greeting(raw: MaybeReactiveProps<{ name: string; excited?: boolean }>) {
303
- * const props = resolveProps(raw);
304
- * return (
305
- * <p>
306
- * Hello, {props.name}
307
- * {() => (props.excited() ? "!" : ".")}
308
- * </p>
309
- * );
310
- * }
311
- * ```
312
- */
313
- declare function resolveProps<P extends object>(raw: { [K in keyof P]: MaybeReactive<P[K]> }): { readonly [K in keyof P]: Computed<P[K]> };
314
- //#endregion
315
- export { trigger as C, signal as S, isComputed as _, isReactive as a, isSignal as b, resolveProps as c, EFFECT_SCOPE as d, SIGNAL as f, effectScope as g, effect as h, Updater as i, COMPUTED as l, computed as m, MaybeReactive as n, reactive as o, batch as p, Signal as r, resolve as s, Computed as t, EFFECT as u, isEffect as v, untracked as w, onCleanup as x, isEffectScope as y };
@@ -1,203 +0,0 @@
1
- import { n as AttrChangeHandler, t as ATTRIBUTES } from "./attributes-Dtn68R1u.mjs";
2
- import { a as PrimitiveNodeType, i as Slots, t as SLOTS } from "./slot-C7GQZe-r.mjs";
3
- import { n as MaybeReactive } from "./index-DydGTqZU.mjs";
4
- import { JSX } from "dom-expressions/src/jsx-h";
5
-
6
- //#region src/jsx-runtime/types.d.ts
7
- /** An instance created by a component class — must expose `render()`. */
8
- interface ComponentInstance {
9
- render(): Element | DocumentFragment | null;
10
- }
11
- /** A class whose constructor returns a ComponentInstance. */
12
- type ComponentClass<P = any> = new (props: P) => ComponentInstance;
13
- type ComponentFn = (props: Record<string | symbol, unknown>) => null | Element | DocumentFragment;
14
- /** Anything that can appear as a JSX child. */
15
- type Child = PrimitiveNodeType | AnyFn | Child[];
16
- /** A function that renders props into an element or fragment. */
17
- type AnyFn = (...args: any[]) => any;
18
- //#endregion
19
- //#region src/jsx-runtime/infer.d.ts
20
- type AnyElementCtor = abstract new (...args: any[]) => HTMLElement;
21
- type Inst<C> = C extends (abstract new (...args: any[]) => infer I) ? I : never;
22
- /**
23
- * When the instance extends `HTMLElement`, drop the DOM surface so only the
24
- * user's own fields remain. Plain classes keep all their keys.
25
- */
26
- type PublicPropKeys<I> = I extends HTMLElement ? Exclude<keyof I, keyof HTMLElement | symbol> : Exclude<keyof I, symbol>;
27
- /**
28
- * Public instance fields of `I` — all optional. For `HTMLElement` subclasses
29
- * the DOM surface is excluded; for plain classes, all own keys are kept.
30
- */
31
- type PropsOfInstance<I> = { [K in PublicPropKeys<I> & string]?: I[K] };
32
- /**
33
- * Promote keys `K` of `P` to required; leave the rest unchanged.
34
- *
35
- * @template P — the prop object type.
36
- * @template K — the keys to make required.
37
- *
38
- * @example
39
- * ```ts
40
- * type Optional = { a?: number; b?: string; c?: boolean };
41
- * type AB = Require<Optional, "a" | "b">;
42
- * // { a: number; b: string; c?: boolean }
43
- * ```
44
- */
45
- type Require<P, K extends keyof P> = { [X in K]-?: P[X] } & Omit<P, K>;
46
- /**
47
- * Wrap every prop in {@link MaybeReactive} so callers may pass either a
48
- * plain value or a reactive getter. Function-typed props (event handlers,
49
- * render callbacks) are wrapped too — the JSX runtime detects branded
50
- * signals/computed and re-binds on change. Optionality is preserved at the
51
- * key level — the `| undefined` stays at the prop, not inside the reactive.
52
- *
53
- * @template P — source prop object type.
54
- *
55
- * @example
56
- * ```ts
57
- * type Raw = { count: number; label?: string; onClick: (e: Event) => void };
58
- * type Wrapped = MaybeReactiveProps<Raw>;
59
- * // {
60
- * // count: MaybeReactive<number>;
61
- * // label?: MaybeReactive<string>;
62
- * // onClick: MaybeReactive<(e: Event) => void>; // computed handlers OK
63
- * // }
64
- * ```
65
- *
66
- * @see {@link MaybeReactive}
67
- * @see {@link Props}
68
- */
69
- type MaybeReactiveProps<P> = { [K in keyof P]: undefined extends P[K] ? MaybeReactive<Exclude<P[K], undefined>> | undefined : MaybeReactive<P[K]> };
70
- type InstancePropsOf<C> = Inst<C> extends infer I ? PropsOfInstance<I> : {};
71
- type PropKeysOf<C> = keyof InstancePropsOf<C> & string;
72
- type AttrMap<C> = C extends {
73
- [ATTRIBUTES]: infer M;
74
- } ? M : never;
75
- type HandlerValue<H> = H extends AttrChangeHandler<any> ? string | null : H;
76
- type AttrsOf<C> = AttrMap<C> extends infer M ? M extends Record<string, unknown> ? { [K in Exclude<keyof M & string, PropKeysOf<C>>]?: MaybeReactive<HandlerValue<M[K]>> } : {} : {};
77
- type FlatPropsOf<C> = MaybeReactiveProps<InstancePropsOf<C>>;
78
- type PropNamespacedOf<C> = { [K in PropKeysOf<C> as `prop:${K}`]?: NonNullable<InstancePropsOf<C>[K]> };
79
- type EventMapOf<C> = C extends {
80
- events: infer E;
81
- } ? E : {};
82
- type Capitalize1<S extends string> = S extends `${infer H}${infer R}` ? `${Uppercase<H>}${R}` : S;
83
- type EventsOf<C> = EventMapOf<C> extends infer E ? E extends Record<string, Event> ? { [K in keyof E & string as `on:${K}`]?: MaybeReactive<(ev: E[K]) => void> } & { [K in keyof E & string as `on${Capitalize1<K>}`]?: MaybeReactive<(ev: E[K]) => void> } : {} : {};
84
- type SlotKeys<I> = I extends {
85
- [SLOTS]: Slots<infer K>;
86
- } ? K : never;
87
- type SlotsOf<C> = SlotKeys<Inst<C>> extends infer K ? [K] extends [string] ? { [P in K as `slot:${P}`]?: Child } : {} : {};
88
- type ChildrenOf<C> = C extends {
89
- children: never;
90
- } ? {} : {
91
- children?: Child;
92
- };
93
- type BaseDOMAttrs = JSX.DOMAttributes<HTMLElement>;
94
- type Namespaces = {
95
- ref?: (el: Element) => void;
96
- [cls: `class:${string}`]: MaybeReactive<boolean>;
97
- [sty: `style:${string}`]: MaybeReactive<string | null>;
98
- [prop: `prop:${string}`]: unknown;
99
- };
100
- /**
101
- * Full JSX prop type for a custom-element class (extends `HTMLElement`).
102
- *
103
- * Composes every surface the element can receive from JSX:
104
- * - **Attributes** — keys from `static [ATTRIBUTES]` (typed `MaybeReactive<string | null>`).
105
- * Keys also present on the instance are dropped here so the flat key carries the property type.
106
- * - **Flat properties** — public instance fields, wrapped in `MaybeReactive`.
107
- * - **`prop:*`** — explicit property assignment for every field.
108
- * - **Events** — keys from `declare static events: { ... }` produce both
109
- * `on:${K}` and `on${Capitalize<K>}` typed handlers.
110
- * - **Slots** — keys from `[SLOTS] = Slots.new([...] as const)` produce `slot:${K}`.
111
- * - **Children** — `children?: Child` unless `static children: never`.
112
- * - **DOM attrs** — the standard dom-expressions surface (`class`, `style`, `ref`, …).
113
- *
114
- * @template C — the custom-element class (constructor type).
115
- *
116
- * @example
117
- * ```ts
118
- * @attributes
119
- * class XRange extends HTMLElement {
120
- * static [ATTRIBUTES]: Attributes<XRange> = { min(v) { this.min = +v! } };
121
- * declare static events: { commit: CustomEvent<number> };
122
- * [SLOTS] = Slots.new(["label"] as const);
123
- * @reactive() min = 0;
124
- * }
125
- *
126
- * type Props = ElementProps<typeof XRange>;
127
- * // {
128
- * // min?: MaybeReactive<number>;
129
- * // "prop:min"?: number;
130
- * // "on:commit"?: (e: CustomEvent<number>) => void;
131
- * // onCommit?: (e: CustomEvent<number>) => void;
132
- * // "slot:label"?: Child;
133
- * // children?: Child;
134
- * // // …plus ref, class, class:*, style, style:*, standard DOM events
135
- * // }
136
- * ```
137
- *
138
- * @see {@link Props} for class-components / function components (no attr/event/slot synthesis).
139
- */
140
- type ElementProps<C extends AnyElementCtor> = BaseDOMAttrs & AttrsOf<C> & FlatPropsOf<C> & PropNamespacedOf<C> & EventsOf<C> & SlotsOf<C> & ChildrenOf<C> & Namespaces;
141
- /**
142
- * Props of a class component that receives them via its constructor:
143
- * `class Comp { constructor(props: P) }`. Reads `ConstructorParameters[0]`.
144
- *
145
- * Use this when the component's props live on a constructor parameter rather
146
- * than on public instance fields. For instance-field components, use {@link Props}.
147
- *
148
- * @template C — the class constructor type (e.g. `typeof Card`).
149
- *
150
- * @example
151
- * ```ts
152
- * class Card {
153
- * constructor(public props: { title: string; children?: Child }) {}
154
- * render() { return <div>{this.props.title}</div>; }
155
- * }
156
- *
157
- * type P = ComponentProps<typeof Card>;
158
- * // { title: string; children?: Child }
159
- * ```
160
- *
161
- * @see {@link Props}
162
- */
163
- type ComponentProps<C extends ComponentClass<any>> = C extends ComponentClass<infer P> ? (P extends object ? P : {}) : {};
164
- /**
165
- * Props for any component — class or function. Wraps every non-function
166
- * prop in {@link MaybeReactive} so callers may pass values or reactive getters.
167
- *
168
- * Branches by input shape:
169
- * - **Class constructor** (`typeof Cls`) → uses `PropsOfInstance<InstanceType<Cls>>`.
170
- * - **Function component** (`(props: P) => ...`) → uses the first parameter.
171
- * - **Class instance** (`Cls<T>`) → uses `PropsOfInstance<Cls<T>>` (useful when
172
- * generics need to flow through — see the `For` example below).
173
- *
174
- * Does **not** synthesize `on:*`, `slot:*`, or attribute surface. For custom
175
- * elements that need those, use {@link ElementProps}.
176
- *
177
- * @template C — constructor, function, or instance.
178
- *
179
- * @example
180
- * ```ts
181
- * // 1. Class instance (lets a generic flow)
182
- * class For<T> { each: T[] = []; render() { return null } }
183
- * type ForProps<T> = Props<For<T>>;
184
- * // ↑ { each?: MaybeReactive<T[]> }
185
- *
186
- * // 2. Function component
187
- * const Greeting = (_p: { name: string; excited?: boolean }) => null;
188
- * type GreetingProps = Props<typeof Greeting>;
189
- * // ↑ { name: MaybeReactive<string>; excited?: MaybeReactive<boolean> }
190
- *
191
- * // 3. Class constructor
192
- * class Counter { count = 0; render() { return null } }
193
- * type CounterProps = Props<typeof Counter>;
194
- * // ↑ { count?: MaybeReactive<number> }
195
- * ```
196
- *
197
- * @see {@link ElementProps} — custom elements (`HTMLElement` subclasses).
198
- * @see {@link ComponentProps} — constructor-param-based class components.
199
- * @see {@link MaybeReactiveProps}
200
- */
201
- type Props<C> = C extends (abstract new (...args: any[]) => infer I) ? MaybeReactiveProps<PropsOfInstance<I>> : C extends ((props: infer P, ...rest: any[]) => any) ? P extends object ? MaybeReactiveProps<P> : {} : MaybeReactiveProps<PropsOfInstance<C>>;
202
- //#endregion
203
- export { Props as a, ComponentClass as c, MaybeReactiveProps as i, ComponentFn as l, ComponentProps as n, Require as o, ElementProps as r, Child as s, AnyElementCtor as t };
@@ -1,9 +0,0 @@
1
- //#region src/polyfill.d.ts
2
- declare global {
3
- interface SymbolConstructor {
4
- readonly dispose: symbol;
5
- }
6
- interface Disposable {
7
- [Symbol.dispose](): void;
8
- }
9
- }