elements-kit 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/element-Cbzkm_B5.mjs +425 -0
- package/dist/for.d.mts +1 -1
- package/dist/for.mjs +1 -1
- package/dist/{infer-LDn1TquI.d.mts → infer-K2Te9gn1.d.mts} +5 -5
- package/dist/integrations/react.d.mts +1 -1
- package/dist/jsx-runtime/index.d.mts +1 -1
- package/dist/jsx-runtime/index.mjs +1 -1
- package/dist/signals/index.d.mts +1 -1
- package/dist/signals/index.mjs +5 -3
- package/dist/slot-B8y0aEoz.d.mts +71 -0
- package/dist/slot-Cne__au7.mjs +127 -0
- package/dist/slot.d.mts +2 -2
- package/dist/slot.mjs +2 -2
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/async.d.mts +1 -1
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/dom-lifecycle.test.mjs +1 -0
- package/dist/utilities/element-rect.d.mts +1 -1
- package/dist/utilities/element-scroll.d.mts +1 -1
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-listener.d.mts +1 -1
- package/dist/utilities/focus-within.d.mts +1 -1
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/media-devices.d.mts +1 -1
- package/dist/utilities/media-player.d.mts +1 -1
- package/dist/utilities/media-query.d.mts +1 -1
- package/dist/utilities/network.d.mts +1 -1
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/promise.d.mts +1 -1
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/storage.d.mts +1 -1
- package/dist/utilities/throttled.d.mts +1 -1
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/window-focus.d.mts +1 -1
- package/dist/utilities/window-size.d.mts +1 -1
- package/package.json +1 -1
- package/dist/element-BjpyY6qv.mjs +0 -277
- package/dist/slot-BnzxFBfO.mjs +0 -198
- package/dist/slot-CfafCBOW.d.mts +0 -121
package/dist/slot-BnzxFBfO.mjs
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import "./polyfill-CdZVCxdo.mjs";
|
|
2
|
-
//#region src/lib.ts
|
|
3
|
-
var UnsupportedChildError = class extends Error {
|
|
4
|
-
constructor(value) {
|
|
5
|
-
super(`Unsupported child type: ${typeof value}`);
|
|
6
|
-
this.name = "UnsupportedChildError";
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
function resolveNode(c) {
|
|
10
|
-
if (c instanceof Node) return c;
|
|
11
|
-
if (c === null || c === void 0 || typeof c === "boolean") return document.createComment("");
|
|
12
|
-
if (typeof c === "string" || typeof c === "number" || typeof c === "bigint" || typeof c === "symbol" || c instanceof Date || c instanceof RegExp) return document.createTextNode(String(c));
|
|
13
|
-
throw new UnsupportedChildError(c);
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/slot.ts
|
|
17
|
-
/**
|
|
18
|
-
* A lightweight slot that reserves a region in the DOM using comment markers.
|
|
19
|
-
* Content between the markers can be replaced dynamically without wrapper elements.
|
|
20
|
-
*/
|
|
21
|
-
var Slot = class Slot {
|
|
22
|
-
start = document.createComment("{");
|
|
23
|
-
end = document.createComment("}");
|
|
24
|
-
#pending;
|
|
25
|
-
/**
|
|
26
|
-
* Render the slot as a DocumentFragment.
|
|
27
|
-
* If not yet mounted, inserts the comment markers and optional default content.
|
|
28
|
-
* If already mounted, extracts and returns the current content WITHOUT disposing
|
|
29
|
-
* it — the caller takes ownership of the returned nodes and is responsible for
|
|
30
|
-
* their disposal.
|
|
31
|
-
*/
|
|
32
|
-
slot(defaultContent) {
|
|
33
|
-
const fragment = document.createDocumentFragment();
|
|
34
|
-
if (this.isMounted()) {
|
|
35
|
-
const range = document.createRange();
|
|
36
|
-
range.setStartAfter(this.start);
|
|
37
|
-
range.setEndBefore(this.end);
|
|
38
|
-
fragment.appendChild(range.extractContents());
|
|
39
|
-
return fragment;
|
|
40
|
-
}
|
|
41
|
-
fragment.appendChild(this.start);
|
|
42
|
-
fragment.appendChild(this.end);
|
|
43
|
-
const initialContent = this.#pending ?? resolveNode(defaultContent);
|
|
44
|
-
if (initialContent) fragment.insertBefore(initialContent, this.end);
|
|
45
|
-
this.#pending = void 0;
|
|
46
|
-
return fragment;
|
|
47
|
-
}
|
|
48
|
-
/** Dispose reactive children and remove all content between the markers. */
|
|
49
|
-
clear() {
|
|
50
|
-
let node = this.start.nextSibling;
|
|
51
|
-
while (node && node !== this.end) {
|
|
52
|
-
const next = node.nextSibling;
|
|
53
|
-
if (node instanceof Element) node[Symbol.dispose]?.();
|
|
54
|
-
node = next;
|
|
55
|
-
}
|
|
56
|
-
const range = document.createRange();
|
|
57
|
-
range.setStartAfter(this.start);
|
|
58
|
-
range.setEndBefore(this.end);
|
|
59
|
-
range.deleteContents();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Replace the slot's content with the given element.
|
|
63
|
-
* No-op if the slot is not mounted or the content is identical.
|
|
64
|
-
*/
|
|
65
|
-
set(element) {
|
|
66
|
-
const parent = this.parent();
|
|
67
|
-
if (!parent) {
|
|
68
|
-
this.#pending = element;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (this.isSame(element)) return;
|
|
72
|
-
this.clear();
|
|
73
|
-
parent.insertBefore(element, this.end);
|
|
74
|
-
this.#pending = void 0;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Extract and return the current slot content as a DocumentFragment.
|
|
78
|
-
* Returns `null` if the slot is not mounted.
|
|
79
|
-
* Content is NOT disposed — the caller takes ownership and is responsible
|
|
80
|
-
* for disposal.
|
|
81
|
-
*/
|
|
82
|
-
get() {
|
|
83
|
-
if (!this.isMounted()) return null;
|
|
84
|
-
const range = document.createRange();
|
|
85
|
-
range.setStartAfter(this.start);
|
|
86
|
-
range.setEndBefore(this.end);
|
|
87
|
-
return range.extractContents();
|
|
88
|
-
}
|
|
89
|
-
/** Returns the parent node if the slot is mounted, otherwise `null`. */
|
|
90
|
-
parent() {
|
|
91
|
-
return this.isMounted() ? this.start.parentNode : null;
|
|
92
|
-
}
|
|
93
|
-
/** Whether the slot's comment markers are attached to the DOM. */
|
|
94
|
-
isMounted() {
|
|
95
|
-
return this.start.parentNode === this.end.parentNode && !!this.start.parentNode;
|
|
96
|
-
}
|
|
97
|
-
isSame(element) {
|
|
98
|
-
return this.start.nextSibling === element && this.end === element.nextSibling;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Create a callable slot instance.
|
|
102
|
-
*
|
|
103
|
-
* The returned value is both a function and an object:
|
|
104
|
-
* - Call it to render the slot with optional default content.
|
|
105
|
-
* - Access `.set()`, `.parent()`, `.isMounted()` for slot management.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```ts
|
|
109
|
-
* const slot = createSlot();
|
|
110
|
-
* el.append(slot("default text")); // mount with default
|
|
111
|
-
* slot.set(newElement); // replace content
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
static new() {
|
|
115
|
-
const instance = new Slot();
|
|
116
|
-
return new Proxy(instance.slot.bind(instance), {
|
|
117
|
-
apply(target, _thisArg, argArray) {
|
|
118
|
-
return target(...argArray);
|
|
119
|
-
},
|
|
120
|
-
get(_target, prop) {
|
|
121
|
-
const value = instance[prop];
|
|
122
|
-
return typeof value === "function" ? value.bind(instance) : value;
|
|
123
|
-
},
|
|
124
|
-
getPrototypeOf() {
|
|
125
|
-
return Slot.prototype;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Symbol key for attaching a `Slots` instance to a custom element instance.
|
|
132
|
-
* This prevent collisions with Element properties and are not meant to be treated as JSX children.
|
|
133
|
-
*/
|
|
134
|
-
const SLOTS = Symbol("slots");
|
|
135
|
-
const $map = Symbol("map");
|
|
136
|
-
const $keys = Symbol("keys");
|
|
137
|
-
const $has = Symbol("has");
|
|
138
|
-
/**
|
|
139
|
-
* A keyed collection of slot instances.
|
|
140
|
-
* Slots are pre-created from the provided keys and lazily created on first access for unknown keys.
|
|
141
|
-
*/
|
|
142
|
-
var Slots = class Slots {
|
|
143
|
-
[$map] = /* @__PURE__ */ new Map();
|
|
144
|
-
constructor(keys = []) {
|
|
145
|
-
for (const key of keys) this[$map].set(key, Slot.new());
|
|
146
|
-
}
|
|
147
|
-
[Symbol.iterator]() {
|
|
148
|
-
return this[$map][Symbol.iterator]();
|
|
149
|
-
}
|
|
150
|
-
[Symbol.toStringTag]() {
|
|
151
|
-
return "Slots";
|
|
152
|
-
}
|
|
153
|
-
[Symbol.hasInstance](instance) {
|
|
154
|
-
return instance instanceof Slots;
|
|
155
|
-
}
|
|
156
|
-
[$has](key) {
|
|
157
|
-
return this[$map].has(key);
|
|
158
|
-
}
|
|
159
|
-
/** Check whether a slot with the given key exists. */
|
|
160
|
-
static has(slots, key) {
|
|
161
|
-
return slots[$has](key);
|
|
162
|
-
}
|
|
163
|
-
[$keys]() {
|
|
164
|
-
return this[$map].keys();
|
|
165
|
-
}
|
|
166
|
-
/** Iterate over all registered slot keys. */
|
|
167
|
-
static keys(slots) {
|
|
168
|
-
return slots[$keys]();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Create a typed `Slots` collection from a list of key names.
|
|
172
|
-
*
|
|
173
|
-
* Pass the keys with `as const` so TS narrows them to a literal union —
|
|
174
|
-
* this is what lets `ElementProps<typeof Cls>` synthesize `slot:${K}`
|
|
175
|
-
* entries. Without `as const`, the array type widens to `string[]` and
|
|
176
|
-
* the slot keys are lost.
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* class Card extends HTMLElement {
|
|
181
|
-
* // ✅ literal keys flow through — "header" | "footer"
|
|
182
|
-
* [SLOTS] = Slots.new(["header", "footer"] as const);
|
|
183
|
-
* }
|
|
184
|
-
*
|
|
185
|
-
* // ❌ widens to string; no typed slot:* props
|
|
186
|
-
* // [SLOTS] = Slots.new(["header", "footer"]);
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
static new(keys) {
|
|
190
|
-
const instance = new Slots(keys);
|
|
191
|
-
return new Proxy(instance, { get(target, prop, receiver) {
|
|
192
|
-
if (typeof prop === "string" && target[$map].has(prop)) return target[$map].get(prop);
|
|
193
|
-
return Reflect.get(target, prop, receiver);
|
|
194
|
-
} });
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
//#endregion
|
|
198
|
-
export { resolveNode as i, Slot as n, Slots as r, SLOTS as t };
|
package/dist/slot-CfafCBOW.d.mts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
//#region src/lib.d.ts
|
|
2
|
-
type PrimitiveNodeType = Node | string | boolean | number | bigint | symbol | Date | RegExp | null | undefined;
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/polyfill.d.ts
|
|
5
|
-
declare global {
|
|
6
|
-
interface SymbolConstructor {
|
|
7
|
-
readonly dispose: symbol;
|
|
8
|
-
}
|
|
9
|
-
interface Disposable {
|
|
10
|
-
[Symbol.dispose](): void;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/slot.d.ts
|
|
15
|
-
/**
|
|
16
|
-
* A lightweight slot that reserves a region in the DOM using comment markers.
|
|
17
|
-
* Content between the markers can be replaced dynamically without wrapper elements.
|
|
18
|
-
*/
|
|
19
|
-
declare class Slot {
|
|
20
|
-
#private;
|
|
21
|
-
private readonly start;
|
|
22
|
-
private readonly end;
|
|
23
|
-
/**
|
|
24
|
-
* Render the slot as a DocumentFragment.
|
|
25
|
-
* If not yet mounted, inserts the comment markers and optional default content.
|
|
26
|
-
* If already mounted, extracts and returns the current content WITHOUT disposing
|
|
27
|
-
* it — the caller takes ownership of the returned nodes and is responsible for
|
|
28
|
-
* their disposal.
|
|
29
|
-
*/
|
|
30
|
-
slot(defaultContent?: PrimitiveNodeType): DocumentFragment;
|
|
31
|
-
/** Dispose reactive children and remove all content between the markers. */
|
|
32
|
-
clear(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Replace the slot's content with the given element.
|
|
35
|
-
* No-op if the slot is not mounted or the content is identical.
|
|
36
|
-
*/
|
|
37
|
-
set(element: Node): void;
|
|
38
|
-
/**
|
|
39
|
-
* Extract and return the current slot content as a DocumentFragment.
|
|
40
|
-
* Returns `null` if the slot is not mounted.
|
|
41
|
-
* Content is NOT disposed — the caller takes ownership and is responsible
|
|
42
|
-
* for disposal.
|
|
43
|
-
*/
|
|
44
|
-
get(): DocumentFragment | null;
|
|
45
|
-
/** Returns the parent node if the slot is mounted, otherwise `null`. */
|
|
46
|
-
parent(): ParentNode | null;
|
|
47
|
-
/** Whether the slot's comment markers are attached to the DOM. */
|
|
48
|
-
isMounted(): boolean;
|
|
49
|
-
private isSame;
|
|
50
|
-
/**
|
|
51
|
-
* Create a callable slot instance.
|
|
52
|
-
*
|
|
53
|
-
* The returned value is both a function and an object:
|
|
54
|
-
* - Call it to render the slot with optional default content.
|
|
55
|
-
* - Access `.set()`, `.parent()`, `.isMounted()` for slot management.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* const slot = createSlot();
|
|
60
|
-
* el.append(slot("default text")); // mount with default
|
|
61
|
-
* slot.set(newElement); // replace content
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
static new(): Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* A callable slot returned by {@link Slot.new}.
|
|
68
|
-
*
|
|
69
|
-
* - Invoke it (`slot()`) to render the slot region as a `DocumentFragment`,
|
|
70
|
-
* optionally with default content on first mount.
|
|
71
|
-
* - Call `.set()` to replace current content, `.clear()` to empty it, and
|
|
72
|
-
* `.isMounted()` / `.parent()` to inspect mount state.
|
|
73
|
-
*/
|
|
74
|
-
type SlotInstance = ReturnType<typeof Slot.new>;
|
|
75
|
-
/**
|
|
76
|
-
* Symbol key for attaching a `Slots` instance to a custom element instance.
|
|
77
|
-
* This prevent collisions with Element properties and are not meant to be treated as JSX children.
|
|
78
|
-
*/
|
|
79
|
-
declare const SLOTS: unique symbol;
|
|
80
|
-
declare const $map: unique symbol;
|
|
81
|
-
declare const $keys: unique symbol;
|
|
82
|
-
declare const $has: unique symbol;
|
|
83
|
-
/**
|
|
84
|
-
* A keyed collection of slot instances.
|
|
85
|
-
* Slots are pre-created from the provided keys and lazily created on first access for unknown keys.
|
|
86
|
-
*/
|
|
87
|
-
declare class Slots<K extends string> implements Iterable<[K, SlotInstance]> {
|
|
88
|
-
readonly [$map]: Map<K, Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment)>;
|
|
89
|
-
private constructor();
|
|
90
|
-
[Symbol.iterator](): MapIterator<[K, Slot & ((defaultContent?: PrimitiveNodeType) => DocumentFragment)]>;
|
|
91
|
-
[Symbol.toStringTag](): string;
|
|
92
|
-
[Symbol.hasInstance](instance: unknown): instance is Slots<any>;
|
|
93
|
-
[$has](key: K): boolean;
|
|
94
|
-
/** Check whether a slot with the given key exists. */
|
|
95
|
-
static has<K extends string>(slots: Slots<K>, key: K): boolean;
|
|
96
|
-
[$keys](): MapIterator<K>;
|
|
97
|
-
/** Iterate over all registered slot keys. */
|
|
98
|
-
static keys<K extends string>(slots: Slots<K>): MapIterator<K>;
|
|
99
|
-
/**
|
|
100
|
-
* Create a typed `Slots` collection from a list of key names.
|
|
101
|
-
*
|
|
102
|
-
* Pass the keys with `as const` so TS narrows them to a literal union —
|
|
103
|
-
* this is what lets `ElementProps<typeof Cls>` synthesize `slot:${K}`
|
|
104
|
-
* entries. Without `as const`, the array type widens to `string[]` and
|
|
105
|
-
* the slot keys are lost.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```ts
|
|
109
|
-
* class Card extends HTMLElement {
|
|
110
|
-
* // ✅ literal keys flow through — "header" | "footer"
|
|
111
|
-
* [SLOTS] = Slots.new(["header", "footer"] as const);
|
|
112
|
-
* }
|
|
113
|
-
*
|
|
114
|
-
* // ❌ widens to string; no typed slot:* props
|
|
115
|
-
* // [SLOTS] = Slots.new(["header", "footer"]);
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
static new<K extends string>(keys: K[]): Slots<K> & { readonly [P in K]: SlotInstance };
|
|
119
|
-
}
|
|
120
|
-
//#endregion
|
|
121
|
-
export { PrimitiveNodeType as a, Slots as i, Slot as n, SlotInstance as r, SLOTS as t };
|