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.
- package/README.md +65 -118
- package/dist/{attributes-Dtn68R1u.d.mts → attributes-DILeh3-s.d.mts} +42 -9
- package/dist/attributes.d.mts +1 -1
- package/dist/attributes.mjs +32 -0
- package/dist/{define-CjbTZ3VG.d.mts → custom-elements-D5_NMNyD.d.mts} +20 -2
- package/dist/custom-elements.d.mts +2 -74
- package/dist/custom-elements.mjs +15 -86
- package/dist/{element-CGVy_8TW.mjs → element-w1GCIMVp.mjs} +33 -21
- package/dist/for.d.mts +31 -2
- package/dist/for.mjs +18 -2
- package/dist/infer-DuFY-y2b.d.mts +657 -0
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +6 -4
- package/dist/jsx-runtime/index.d.mts +2 -73
- package/dist/jsx-runtime/index.mjs +8 -14
- package/dist/{signals-J8dK_rA4.mjs → lib-D6duEs38.mjs} +1 -105
- package/dist/render.d.mts +21 -0
- package/dist/render.mjs +32 -0
- package/dist/scope-DM2gzOkb.mjs +45 -0
- package/dist/signals/index.d.mts +1 -1
- package/dist/signals/index.mjs +134 -1
- package/dist/{slot-Kb61AcgW.mjs → slot-CKtUoy2X.mjs} +0 -1
- package/dist/{slot-C7GQZe-r.d.mts → slot-D5iBUSAm.d.mts} +18 -1
- package/dist/slot.d.mts +1 -1
- package/dist/slot.mjs +1 -1
- package/dist/{test.BmQO5GaM-DfGStnii.mjs → test.BmQO5GaM-BeO5pvCo.mjs} +1 -1
- package/dist/utilities/_observe.mjs +2 -1
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.mjs +2 -1
- package/dist/utilities/active-element.test.mjs +1 -1
- package/dist/utilities/async.d.mts +39 -1
- package/dist/utilities/async.mjs +39 -1
- package/dist/utilities/async.test.mjs +3 -2
- package/dist/utilities/debounced.d.mts +12 -1
- package/dist/utilities/debounced.mjs +13 -1
- package/dist/utilities/debounced.test.mjs +3 -2
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +2 -1
- package/dist/utilities/element-rect.test.mjs +3 -2
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/element-scroll.test.mjs +3 -2
- package/dist/utilities/environment.d.mts +2 -0
- package/dist/utilities/environment.mjs +2 -0
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +2 -1
- package/dist/utilities/event-listener.d.mts +12 -1
- package/dist/utilities/event-listener.mjs +2 -1
- package/dist/utilities/event-listener.test.mjs +3 -2
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +2 -1
- package/dist/utilities/focus-within.test.mjs +3 -2
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +2 -1
- package/dist/utilities/hover.test.mjs +3 -2
- package/dist/utilities/intersection-observer.test.mjs +3 -2
- package/dist/utilities/interval.d.mts +14 -1
- package/dist/utilities/interval.mjs +2 -1
- package/dist/utilities/interval.test.mjs +3 -2
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/location.mjs +2 -1
- package/dist/utilities/location.test.mjs +1 -1
- package/dist/utilities/long-press.test.mjs +3 -2
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +2 -1
- package/dist/utilities/media-devices.test.mjs +3 -2
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-player.test.mjs +3 -2
- package/dist/utilities/media-query.d.mts +1 -1
- package/dist/utilities/media-query.mjs +2 -1
- package/dist/utilities/mutation-observer.test.mjs +3 -2
- package/dist/utilities/network.d.mts +1 -1
- package/dist/utilities/network.mjs +2 -1
- package/dist/utilities/network.test.mjs +1 -1
- package/dist/utilities/on-click-outside.test.mjs +3 -2
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/orientation.mjs +2 -1
- package/dist/utilities/previous.d.mts +13 -1
- package/dist/utilities/previous.mjs +14 -1
- package/dist/utilities/previous.test.mjs +3 -2
- package/dist/utilities/promise.d.mts +7 -1
- package/dist/utilities/promise.mjs +2 -1
- package/dist/utilities/promise.test.mjs +3 -2
- package/dist/utilities/retry.d.mts +15 -0
- package/dist/utilities/retry.mjs +17 -1
- package/dist/utilities/retry.test.mjs +3 -2
- package/dist/utilities/routing.d.mts +12 -1
- package/dist/utilities/routing.mjs +13 -1
- package/dist/utilities/routing.test.mjs +1 -1
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/search-params.test.mjs +3 -2
- package/dist/utilities/ssr.test.mjs +1 -1
- package/dist/utilities/storage.d.mts +18 -1
- package/dist/utilities/storage.mjs +17 -0
- package/dist/utilities/storage.test.mjs +3 -2
- package/dist/utilities/throttled.d.mts +12 -1
- package/dist/utilities/throttled.mjs +13 -1
- package/dist/utilities/throttled.test.mjs +3 -2
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.mjs +2 -1
- package/dist/utilities/timeout.test.mjs +3 -2
- package/dist/utilities/window-focus.d.mts +1 -1
- package/dist/utilities/window-focus.mjs +2 -1
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +2 -1
- package/dist/utilities/window-size.test.mjs +1 -1
- package/package.json +1 -1
- package/dist/index-DydGTqZU.d.mts +0 -315
- package/dist/infer-BfzRJoCn.d.mts +0 -203
- package/dist/polyfill-BVNd6ogU.d.mts +0 -9
- /package/dist/{magic-string.es-i62WTP6J.mjs → magic-string.es-cTgJnTCj.mjs} +0 -0
|
@@ -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 };
|
|
File without changes
|