elements-kit 0.0.14 → 0.0.16
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 +138 -31
- package/dist/attributes-Dtn68R1u.d.mts +94 -0
- package/dist/attributes.d.mts +1 -93
- package/dist/custom-elements.d.mts +74 -0
- package/dist/custom-elements.mjs +100 -0
- package/dist/define-CjbTZ3VG.d.mts +23 -0
- package/dist/{element-C_4VbkvQ.mjs → element-CGVy_8TW.mjs} +12 -18
- package/dist/for.d.mts +45 -0
- package/dist/for.mjs +136 -0
- package/dist/{index-DUshSQ_6.d.mts → index-DydGTqZU.d.mts} +60 -10
- package/dist/index.d.mts +1 -36
- package/dist/index.mjs +1 -144
- package/dist/infer-BfzRJoCn.d.mts +203 -0
- package/dist/integrations/react.d.mts +1 -1
- package/dist/integrations/react.mjs +1 -1
- package/dist/jsx-runtime/index.d.mts +18 -25
- package/dist/jsx-runtime/index.mjs +2 -2
- package/dist/signals/index.d.mts +2 -2
- package/dist/signals/index.mjs +2 -2
- package/dist/{signals-BHmWX6ox.mjs → signals-J8dK_rA4.mjs} +57 -17
- package/dist/slot-C7GQZe-r.d.mts +104 -0
- package/dist/{slot-Cydy7-0L.mjs → slot-Kb61AcgW.mjs} +21 -2
- package/dist/slot.d.mts +2 -84
- package/dist/slot.mjs +2 -2
- package/dist/{test.BmQO5GaM-ANkhHvbr.mjs → test.BmQO5GaM-DfGStnii.mjs} +1 -1
- package/dist/utilities/_observe.d.mts +11 -0
- package/dist/utilities/_observe.mjs +15 -0
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.mjs +6 -2
- package/dist/utilities/active-element.test.mjs +1 -1
- package/dist/utilities/async.d.mts +1 -1
- package/dist/utilities/async.mjs +1 -1
- package/dist/utilities/async.test.mjs +2 -2
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.mjs +1 -1
- package/dist/utilities/debounced.test.mjs +2 -2
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-rect.mjs +1 -1
- package/dist/utilities/element-rect.test.mjs +2 -2
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/element-scroll.mjs +7 -34
- package/dist/utilities/element-scroll.test.mjs +2 -2
- package/dist/utilities/environment.d.mts +5 -0
- package/dist/utilities/environment.mjs +5 -0
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-driven.mjs +2 -2
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/event-listener.mjs +1 -1
- package/dist/utilities/event-listener.test.mjs +2 -2
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/focus-within.mjs +1 -1
- package/dist/utilities/focus-within.test.mjs +2 -2
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.mjs +1 -1
- package/dist/utilities/hover.test.mjs +2 -2
- package/dist/utilities/intersection-observer.mjs +4 -6
- package/dist/utilities/intersection-observer.test.mjs +2 -2
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/interval.mjs +1 -1
- package/dist/utilities/interval.test.mjs +18 -2
- package/dist/utilities/location.d.mts +2 -14
- package/dist/utilities/location.mjs +12 -3
- package/dist/utilities/location.test.mjs +5 -5
- package/dist/utilities/long-press.mjs +1 -1
- package/dist/utilities/long-press.test.mjs +2 -2
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-devices.mjs +1 -1
- package/dist/utilities/media-devices.test.mjs +2 -2
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-player.test.mjs +2 -2
- package/dist/utilities/media-query.d.mts +2 -3
- package/dist/utilities/media-query.mjs +3 -3
- package/dist/utilities/mutation-observer.mjs +4 -7
- package/dist/utilities/mutation-observer.test.mjs +2 -2
- package/dist/utilities/network.d.mts +2 -2
- package/dist/utilities/network.mjs +5 -3
- package/dist/utilities/network.test.mjs +1 -1
- package/dist/utilities/on-click-outside.test.mjs +2 -2
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/orientation.mjs +9 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.mjs +1 -1
- package/dist/utilities/previous.test.mjs +2 -2
- package/dist/utilities/promise.d.mts +1 -1
- package/dist/utilities/promise.mjs +1 -1
- package/dist/utilities/promise.test.mjs +2 -2
- package/dist/utilities/resize-observer.mjs +4 -6
- package/dist/utilities/retry.mjs +1 -1
- package/dist/utilities/retry.test.mjs +2 -2
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/routing.mjs +1 -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 +2 -2
- package/dist/utilities/ssr.test.d.mts +1 -0
- package/dist/utilities/ssr.test.mjs +64 -0
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/storage.test.mjs +2 -2
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/throttled.mjs +1 -1
- package/dist/utilities/throttled.test.mjs +2 -2
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.mjs +1 -1
- package/dist/utilities/timeout.test.mjs +57 -2
- package/dist/utilities/window-focus.d.mts +2 -2
- package/dist/utilities/window-focus.mjs +5 -3
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.mjs +10 -5
- package/dist/utilities/window-size.test.mjs +1 -1
- package/package.json +11 -1
- package/dist/lib-JA05lzCN.d.mts +0 -4
- /package/dist/{polyfill-DR5XVnh_.d.mts → polyfill-BVNd6ogU.d.mts} +0 -0
|
@@ -0,0 +1,203 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as effect, f as effectScope, v as signal } from "../signals-J8dK_rA4.mjs";
|
|
2
2
|
import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
3
|
//#region src/integrations/react.ts
|
|
4
4
|
/**
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as CustomElementRegistry } from "../define-CjbTZ3VG.mjs";
|
|
2
|
+
import { a as Props, c as ComponentClass, i as MaybeReactiveProps, l as ComponentFn, n as ComponentProps, o as Require, r as ElementProps, s as Child, t as AnyElementCtor } from "../infer-BfzRJoCn.mjs";
|
|
3
|
+
import { n as MaybeReactive } from "../index-DydGTqZU.mjs";
|
|
2
4
|
import { JSX as JSX$1 } from "dom-expressions/src/jsx-h";
|
|
3
5
|
|
|
4
|
-
//#region src/jsx-runtime/types.d.ts
|
|
5
|
-
/** An instance created by a component class — must expose `render()`. */
|
|
6
|
-
interface ComponentInstance {
|
|
7
|
-
render(): Element | DocumentFragment | null;
|
|
8
|
-
}
|
|
9
|
-
/** A class whose constructor returns a ComponentInstance. */
|
|
10
|
-
type ComponentClass = new (...args: any[]) => ComponentInstance;
|
|
11
|
-
type ComponentFn = (props: Record<string | symbol, unknown>) => null | Element | DocumentFragment;
|
|
12
|
-
/** Anything that can appear as a JSX child. */
|
|
13
|
-
type Child = PrimitiveNodeType | AnyFn | Child[];
|
|
14
|
-
/** A function that renders props into an element or fragment. */
|
|
15
|
-
type AnyFn = (...args: any[]) => any;
|
|
16
|
-
//#endregion
|
|
17
6
|
//#region src/jsx-runtime/element.d.ts
|
|
18
|
-
declare function createElement(type: string | Element | DocumentFragment | ComponentClass | ComponentFn,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
declare function createElement(type: string | Element | DocumentFragment | ComponentClass | ComponentFn, {
|
|
8
|
+
ref,
|
|
9
|
+
...props
|
|
10
|
+
}?: Record<string | symbol, unknown> & {
|
|
11
|
+
ref?: (el: Element) => void;
|
|
12
|
+
}): Element | DocumentFragment | null;
|
|
22
13
|
//#endregion
|
|
23
14
|
//#region src/jsx-runtime/fragment.d.ts
|
|
24
15
|
/**
|
|
@@ -59,7 +50,7 @@ type SlotProps<K extends string> = { [P in K as `slot:${P}`]?: Child };
|
|
|
59
50
|
type Attrs<K extends keyof JSX.IntrinsicElements> = JSX.IntrinsicElements[K];
|
|
60
51
|
/** Extra props injected into every intrinsic element beyond dom-expressions defaults. */
|
|
61
52
|
type OurProps = {
|
|
62
|
-
|
|
53
|
+
ref?: (el: Element) => void;
|
|
63
54
|
[slot: `slot:${string}`]: Child;
|
|
64
55
|
[cls: `class:${string}`]: FunctionMaybe<boolean>;
|
|
65
56
|
[sty: `style:${string}`]: FunctionMaybe<string | null>;
|
|
@@ -67,14 +58,16 @@ type OurProps = {
|
|
|
67
58
|
};
|
|
68
59
|
type WithOurProps<T> = T & OurProps;
|
|
69
60
|
declare namespace JSX {
|
|
70
|
-
type Element = globalThis.Element | globalThis.DocumentFragment | null;
|
|
71
|
-
type ElementType = Child | ComponentClass;
|
|
72
|
-
interface ElementChildrenAttribute {
|
|
61
|
+
export type Element = globalThis.Element | globalThis.DocumentFragment | null;
|
|
62
|
+
export type ElementType = Child | ComponentClass;
|
|
63
|
+
export interface ElementChildrenAttribute {
|
|
73
64
|
children: {};
|
|
74
65
|
}
|
|
75
|
-
type
|
|
76
|
-
|
|
66
|
+
type RegisteredElements = { [K in keyof CustomElementRegistry]: CustomElementRegistry[K] extends AnyElementCtor ? ElementProps<CustomElementRegistry[K]> : never };
|
|
67
|
+
export type IntrinsicElements = { [K in keyof JSX$1.IntrinsicElements]: WithOurProps<JSX$1.IntrinsicElements[K]> } & RegisteredElements & {
|
|
68
|
+
/** Unregistered custom elements (`x-foo`, `my-component`, …) — loose fallback. */[customElement: `${string}-${string}`]: WithOurProps<JSX$1.DOMAttributes<HTMLElement>> & Record<string, unknown>;
|
|
77
69
|
};
|
|
70
|
+
export {};
|
|
78
71
|
}
|
|
79
72
|
//#endregion
|
|
80
|
-
export { Attrs, Fragment, FunctionMaybe, JSX, SlotProps, createElement as h, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|
|
73
|
+
export { Attrs, type ComponentProps, type ElementProps, Fragment, FunctionMaybe, JSX, type MaybeReactive, type MaybeReactiveProps, type Props, type Require, SlotProps, createElement as h, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createElement } from "../element-
|
|
2
|
-
import {
|
|
1
|
+
import { t as createElement } from "../element-CGVy_8TW.mjs";
|
|
2
|
+
import { _ as onCleanup } from "../signals-J8dK_rA4.mjs";
|
|
3
3
|
//#region src/jsx-runtime/fragment.ts
|
|
4
4
|
/**
|
|
5
5
|
* Used by the JSX transform for `<>...</>` fragments.
|
package/dist/signals/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
export {
|
|
1
|
+
import { C as trigger, S as signal, _ as isComputed, a as isReactive, b as isSignal, c as resolveProps, d as EFFECT_SCOPE, f as SIGNAL, g as effectScope, h as effect, i as Updater, l as COMPUTED, m as computed, n as MaybeReactive, o as reactive, p as batch, r as Signal, s as resolve, t as Computed, u as EFFECT, v as isEffect, w as untracked, x as onCleanup, y as isEffectScope } from "../index-DydGTqZU.mjs";
|
|
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 };
|
package/dist/signals/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export {
|
|
1
|
+
import { _ as onCleanup, a as COMPUTED, b as untracked, c as SIGNAL, d as effect, f as effectScope, g as isSignal, h as isEffectScope, i as resolveProps, l as batch, m as isEffect, n as reactive, o as EFFECT, p as isComputed, r as resolve, s as EFFECT_SCOPE, t as isReactive, u as computed, v as signal, y as trigger } from "../signals-J8dK_rA4.mjs";
|
|
2
|
+
export { COMPUTED, EFFECT, EFFECT_SCOPE, SIGNAL, batch, computed, effect, effectScope, isComputed, isEffect, isEffectScope, isReactive, isSignal, onCleanup, reactive, resolve, resolveProps, signal, trigger, untracked };
|
|
@@ -275,10 +275,10 @@ let activeSub;
|
|
|
275
275
|
let activeOwner;
|
|
276
276
|
/** Ring-buffer of effects waiting to be flushed. */
|
|
277
277
|
const queued = [];
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
const
|
|
278
|
+
const SIGNAL = Symbol("signal");
|
|
279
|
+
const COMPUTED = Symbol("computed");
|
|
280
|
+
const EFFECT = Symbol("effect");
|
|
281
|
+
const EFFECT_SCOPE = Symbol("effectScope");
|
|
282
282
|
const { link, unlink, propagate, checkDirty, shallowPropagate } = createReactiveSystem({
|
|
283
283
|
update(node) {
|
|
284
284
|
if (node.depsTail !== void 0) return updateComputed(node);
|
|
@@ -353,26 +353,26 @@ function endBatch() {
|
|
|
353
353
|
/**
|
|
354
354
|
* Returns `true` if `fn` is a signal handle created by {@link signal}.
|
|
355
355
|
*
|
|
356
|
-
* Relies on
|
|
356
|
+
* Relies on the SIGNAL symbol.
|
|
357
357
|
*/
|
|
358
358
|
function isSignal(fn) {
|
|
359
|
-
return fn != null && fn[
|
|
359
|
+
return fn != null && fn[SIGNAL] === true;
|
|
360
360
|
}
|
|
361
361
|
/**
|
|
362
362
|
* Returns `true` if `fn` is a computed handle created by {@link computed}.
|
|
363
363
|
*
|
|
364
|
-
* Relies on
|
|
364
|
+
* Relies on the COMPUTED symbol.
|
|
365
365
|
*/
|
|
366
366
|
function isComputed(fn) {
|
|
367
|
-
return fn != null && fn[
|
|
367
|
+
return fn != null && fn[COMPUTED] === true;
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Returns `true` if `fn` is an effect cleanup handle created by {@link effect}.
|
|
371
371
|
*
|
|
372
|
-
* Relies on the
|
|
372
|
+
* Relies on the EFFECT symbol.
|
|
373
373
|
*/
|
|
374
374
|
function isEffect(fn) {
|
|
375
|
-
return fn != null && fn[
|
|
375
|
+
return fn != null && fn[EFFECT] === true;
|
|
376
376
|
}
|
|
377
377
|
/**
|
|
378
378
|
* Returns `true` if `fn` is an effectScope cleanup handle created by
|
|
@@ -391,7 +391,7 @@ function signal(initialValue) {
|
|
|
391
391
|
subsTail: void 0,
|
|
392
392
|
flags: 1
|
|
393
393
|
});
|
|
394
|
-
Object.defineProperty(handle,
|
|
394
|
+
Object.defineProperty(handle, SIGNAL, { value: true });
|
|
395
395
|
return handle;
|
|
396
396
|
}
|
|
397
397
|
/**
|
|
@@ -427,7 +427,7 @@ function computed(getter) {
|
|
|
427
427
|
flags: 0,
|
|
428
428
|
getter
|
|
429
429
|
});
|
|
430
|
-
Object.defineProperty(handle,
|
|
430
|
+
Object.defineProperty(handle, COMPUTED, { value: true });
|
|
431
431
|
return handle;
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
@@ -481,7 +481,7 @@ function effect(fn) {
|
|
|
481
481
|
e.flags &= -5;
|
|
482
482
|
}
|
|
483
483
|
const handle = effectOper.bind(e);
|
|
484
|
-
Object.defineProperty(handle,
|
|
484
|
+
Object.defineProperty(handle, EFFECT, { value: true });
|
|
485
485
|
return handle;
|
|
486
486
|
}
|
|
487
487
|
/**
|
|
@@ -527,7 +527,7 @@ function effectScope(fn) {
|
|
|
527
527
|
activeOwner = prevOwner;
|
|
528
528
|
}
|
|
529
529
|
const handle = effectScopeOper.bind(e);
|
|
530
|
-
Object.defineProperty(handle,
|
|
530
|
+
Object.defineProperty(handle, EFFECT_SCOPE, { value: true });
|
|
531
531
|
return handle;
|
|
532
532
|
}
|
|
533
533
|
/**
|
|
@@ -964,11 +964,51 @@ function reactive(source) {
|
|
|
964
964
|
};
|
|
965
965
|
}
|
|
966
966
|
/**
|
|
967
|
-
*
|
|
968
|
-
*
|
|
967
|
+
* Resolve a {@link MaybeReactive} to its current value. Calls the getter
|
|
968
|
+
* when reactive; returns the value as-is when static.
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```ts
|
|
972
|
+
* resolve(5); // 5
|
|
973
|
+
* resolve(() => count()); // current count value
|
|
974
|
+
* ```
|
|
969
975
|
*/
|
|
970
976
|
function resolve(value) {
|
|
971
977
|
return isReactive(value) ? value() : value;
|
|
972
978
|
}
|
|
979
|
+
/**
|
|
980
|
+
* Turn a reactive-props object into a bag of per-key getters. Callers may
|
|
981
|
+
* pass values or reactive sources (`signal`, `computed`); reading
|
|
982
|
+
* `props.name()` inside an effect or JSX getter subscribes to whatever
|
|
983
|
+
* drives it. Static values become stable thunks, signals and computed pass
|
|
984
|
+
* through unchanged — so identity is preserved (`props.name === props.name`).
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```tsx
|
|
988
|
+
* import { resolveProps } from "elements-kit/signals";
|
|
989
|
+
*
|
|
990
|
+
* function Greeting(raw: MaybeReactiveProps<{ name: string; excited?: boolean }>) {
|
|
991
|
+
* const props = resolveProps(raw);
|
|
992
|
+
* return (
|
|
993
|
+
* <p>
|
|
994
|
+
* Hello, {props.name}
|
|
995
|
+
* {() => (props.excited() ? "!" : ".")}
|
|
996
|
+
* </p>
|
|
997
|
+
* );
|
|
998
|
+
* }
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
function resolveProps(raw) {
|
|
1002
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1003
|
+
return new Proxy(raw, { get(target, key) {
|
|
1004
|
+
let getter = cache.get(key);
|
|
1005
|
+
if (!getter) {
|
|
1006
|
+
const v = target[key];
|
|
1007
|
+
getter = isReactive(v) ? v : () => v;
|
|
1008
|
+
cache.set(key, getter);
|
|
1009
|
+
}
|
|
1010
|
+
return getter;
|
|
1011
|
+
} });
|
|
1012
|
+
}
|
|
973
1013
|
//#endregion
|
|
974
|
-
export {
|
|
1014
|
+
export { onCleanup as _, COMPUTED as a, untracked as b, SIGNAL as c, effect as d, effectScope as f, isSignal as g, isEffectScope as h, resolveProps as i, batch as l, isEffect as m, reactive as n, EFFECT as o, isComputed as p, resolve as r, EFFECT_SCOPE as s, isReactive as t, computed as u, signal as v, trigger as y };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//#region src/lib.d.ts
|
|
2
|
+
type PrimitiveNodeType = Node | string | boolean | number | bigint | symbol | Date | RegExp | null | undefined;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/slot.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A lightweight slot that reserves a region in the DOM using comment markers.
|
|
7
|
+
* Content between the markers can be replaced dynamically without wrapper elements.
|
|
8
|
+
*/
|
|
9
|
+
declare class Slot {
|
|
10
|
+
#private;
|
|
11
|
+
private readonly start;
|
|
12
|
+
private readonly end;
|
|
13
|
+
/**
|
|
14
|
+
* Render the slot as a DocumentFragment.
|
|
15
|
+
* If not yet mounted, inserts the comment markers and optional default content.
|
|
16
|
+
* If already mounted, extracts and returns the current content WITHOUT disposing
|
|
17
|
+
* it — the caller takes ownership of the returned nodes and is responsible for
|
|
18
|
+
* their disposal.
|
|
19
|
+
*/
|
|
20
|
+
slot(defaultContent?: PrimitiveNodeType): DocumentFragment;
|
|
21
|
+
/** Dispose reactive children and remove all content between the markers. */
|
|
22
|
+
clear(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Replace the slot's content with the given element.
|
|
25
|
+
* No-op if the slot is not mounted or the content is identical.
|
|
26
|
+
*/
|
|
27
|
+
set(element: Node): void;
|
|
28
|
+
/**
|
|
29
|
+
* Extract and return the current slot content as a DocumentFragment.
|
|
30
|
+
* Returns `null` if the slot is not mounted.
|
|
31
|
+
* Content is NOT disposed — the caller takes ownership and is responsible
|
|
32
|
+
* for disposal.
|
|
33
|
+
*/
|
|
34
|
+
get(): DocumentFragment | null;
|
|
35
|
+
/** Returns the parent node if the slot is mounted, otherwise `null`. */
|
|
36
|
+
parent(): ParentNode | null;
|
|
37
|
+
/** Whether the slot's comment markers are attached to the DOM. */
|
|
38
|
+
isMounted(): boolean;
|
|
39
|
+
private isSame;
|
|
40
|
+
/**
|
|
41
|
+
* Create a callable slot instance.
|
|
42
|
+
*
|
|
43
|
+
* The returned value is both a function and an object:
|
|
44
|
+
* - Call it to render the slot with optional default content.
|
|
45
|
+
* - Access `.set()`, `.parent()`, `.isMounted()` for slot management.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const slot = createSlot();
|
|
50
|
+
* el.append(slot("default text")); // mount with default
|
|
51
|
+
* slot.set(newElement); // replace content
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
static new(): Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment);
|
|
55
|
+
}
|
|
56
|
+
type SlotInstance = ReturnType<typeof Slot.new>;
|
|
57
|
+
/** A callable slot — invoke to render, or access `.set()` / `.isMounted()` / `.parent()` for management. */
|
|
58
|
+
/**
|
|
59
|
+
* Symbol key for attaching a `Slots` instance to a custom element instance.
|
|
60
|
+
* This prevent collisions with Element properties and are not meant to be treated as JSX children.
|
|
61
|
+
*/
|
|
62
|
+
declare const SLOTS: unique symbol;
|
|
63
|
+
declare const $map: unique symbol;
|
|
64
|
+
declare const $keys: unique symbol;
|
|
65
|
+
declare const $has: unique symbol;
|
|
66
|
+
/**
|
|
67
|
+
* A keyed collection of slot instances.
|
|
68
|
+
* Slots are pre-created from the provided keys and lazily created on first access for unknown keys.
|
|
69
|
+
*/
|
|
70
|
+
declare class Slots<K extends string> implements Iterable<[K, SlotInstance]> {
|
|
71
|
+
readonly [$map]: Map<K, Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment)>;
|
|
72
|
+
private constructor();
|
|
73
|
+
[Symbol.iterator](): MapIterator<[K, Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment)]>;
|
|
74
|
+
[Symbol.toStringTag](): string;
|
|
75
|
+
[Symbol.hasInstance](instance: unknown): instance is Slots<any>;
|
|
76
|
+
[$has](key: K): boolean;
|
|
77
|
+
/** Check whether a slot with the given key exists. */
|
|
78
|
+
static has<K extends string>(slots: Slots<K>, key: K): boolean;
|
|
79
|
+
[$keys](): MapIterator<K>;
|
|
80
|
+
/** Iterate over all registered slot keys. */
|
|
81
|
+
static keys<K extends string>(slots: Slots<K>): MapIterator<K>;
|
|
82
|
+
/**
|
|
83
|
+
* Create a typed `Slots` collection from a list of key names.
|
|
84
|
+
*
|
|
85
|
+
* Pass the keys with `as const` so TS narrows them to a literal union —
|
|
86
|
+
* this is what lets `ElementProps<typeof Cls>` synthesize `slot:${K}`
|
|
87
|
+
* entries. Without `as const`, the array type widens to `string[]` and
|
|
88
|
+
* the slot keys are lost.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* class Card extends HTMLElement {
|
|
93
|
+
* // ✅ literal keys flow through — "header" | "footer"
|
|
94
|
+
* [SLOTS] = Slots.new(["header", "footer"] as const);
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* // ❌ widens to string; no typed slot:* props
|
|
98
|
+
* // [SLOTS] = Slots.new(["header", "footer"]);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
static new<K extends string>(keys: K[]): Slots<K> & { readonly [P in K]: SlotInstance };
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { PrimitiveNodeType as a, Slots as i, Slot as n, SlotInstance as r, SLOTS as t };
|
|
@@ -132,7 +132,7 @@ var Slot = class Slot {
|
|
|
132
132
|
* Symbol key for attaching a `Slots` instance to a custom element instance.
|
|
133
133
|
* This prevent collisions with Element properties and are not meant to be treated as JSX children.
|
|
134
134
|
*/
|
|
135
|
-
const
|
|
135
|
+
const SLOTS = Symbol("slots");
|
|
136
136
|
const $map = Symbol("map");
|
|
137
137
|
const $keys = Symbol("keys");
|
|
138
138
|
const $has = Symbol("has");
|
|
@@ -168,6 +168,25 @@ var Slots = class Slots {
|
|
|
168
168
|
static keys(slots) {
|
|
169
169
|
return slots[$keys]();
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a typed `Slots` collection from a list of key names.
|
|
173
|
+
*
|
|
174
|
+
* Pass the keys with `as const` so TS narrows them to a literal union —
|
|
175
|
+
* this is what lets `ElementProps<typeof Cls>` synthesize `slot:${K}`
|
|
176
|
+
* entries. Without `as const`, the array type widens to `string[]` and
|
|
177
|
+
* the slot keys are lost.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* class Card extends HTMLElement {
|
|
182
|
+
* // ✅ literal keys flow through — "header" | "footer"
|
|
183
|
+
* [SLOTS] = Slots.new(["header", "footer"] as const);
|
|
184
|
+
* }
|
|
185
|
+
*
|
|
186
|
+
* // ❌ widens to string; no typed slot:* props
|
|
187
|
+
* // [SLOTS] = Slots.new(["header", "footer"]);
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
171
190
|
static new(keys) {
|
|
172
191
|
const instance = new Slots(keys);
|
|
173
192
|
return new Proxy(instance, { get(target, prop, receiver) {
|
|
@@ -177,4 +196,4 @@ var Slots = class Slots {
|
|
|
177
196
|
}
|
|
178
197
|
};
|
|
179
198
|
//#endregion
|
|
180
|
-
export { resolveNode as i, Slot as n, Slots as r,
|
|
199
|
+
export { resolveNode as i, Slot as n, Slots as r, SLOTS as t };
|