elements-kit 0.3.1 → 0.3.3
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/{benchmark.CX_oY03V-COK1VBpH.mjs → benchmark.CX_oY03V-CsUg-gW0.mjs} +2 -2
- package/dist/custom-elements-D5CgfNKc.d.mts +55 -0
- package/dist/custom-elements.d.mts +1 -1
- package/dist/custom-elements.mjs +6 -4
- package/dist/{element-BjpyY6qv.mjs → element-DvqBlRly.mjs} +195 -47
- package/dist/for.d.mts +1 -1
- package/dist/for.mjs +1 -1
- package/dist/{infer-BUUWMoG9.d.mts → infer-K2Te9gn1.d.mts} +50 -38
- 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-DLjSL6t1.mjs +124 -0
- package/dist/slot.d.mts +2 -2
- package/dist/slot.mjs +2 -2
- package/dist/{test.BmQO5GaM-C8YqghE0.mjs → test.BmQO5GaM-ZC2MPXQb.mjs} +4 -4
- package/dist/utilities/active-element.d.mts +1 -1
- package/dist/utilities/active-element.test.mjs +2 -2
- package/dist/utilities/async.d.mts +7 -1
- package/dist/utilities/async.mjs +6 -0
- package/dist/utilities/async.test.mjs +2 -2
- package/dist/utilities/context.test.mjs +2 -2
- package/dist/utilities/debounced.d.mts +1 -1
- package/dist/utilities/debounced.test.mjs +2 -2
- package/dist/utilities/dom-lifecycle.bench.mjs +1 -1
- package/dist/utilities/dom-lifecycle.d.mts +19 -21
- package/dist/utilities/dom-lifecycle.mjs +16 -13
- package/dist/utilities/dom-lifecycle.test.mjs +3 -2
- package/dist/utilities/element-rect.d.mts +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.test.mjs +2 -2
- package/dist/utilities/event-driven.d.mts +1 -1
- package/dist/utilities/event-listener.d.mts +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.test.mjs +2 -2
- package/dist/utilities/hover.d.mts +1 -1
- package/dist/utilities/hover.test.mjs +2 -2
- package/dist/utilities/intersection-observer.d.mts +17 -0
- package/dist/utilities/intersection-observer.mjs +17 -0
- package/dist/utilities/intersection-observer.test.mjs +2 -2
- package/dist/utilities/interval.d.mts +1 -1
- package/dist/utilities/interval.test.mjs +2 -2
- package/dist/utilities/location.d.mts +1 -1
- package/dist/utilities/location.test.mjs +2 -2
- package/dist/utilities/long-press.test.mjs +2 -2
- package/dist/utilities/media-devices.d.mts +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 +1 -1
- package/dist/utilities/mutation-observer.test.mjs +2 -2
- package/dist/utilities/network.d.mts +1 -1
- package/dist/utilities/network.test.mjs +2 -2
- package/dist/utilities/on-click-outside.test.mjs +2 -2
- package/dist/utilities/orientation.d.mts +1 -1
- package/dist/utilities/previous.d.mts +1 -1
- package/dist/utilities/previous.test.mjs +2 -2
- package/dist/utilities/promise.d.mts +1 -1
- package/dist/utilities/promise.test.mjs +2 -2
- package/dist/utilities/retry.test.mjs +2 -2
- package/dist/utilities/routing.d.mts +1 -1
- package/dist/utilities/routing.test.mjs +2 -2
- package/dist/utilities/search-params.d.mts +1 -1
- package/dist/utilities/search-params.test.mjs +2 -2
- package/dist/utilities/ssr.test.mjs +2 -2
- 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.test.mjs +2 -2
- package/dist/utilities/timeout.d.mts +1 -1
- package/dist/utilities/timeout.test.mjs +2 -2
- package/dist/utilities/window-focus.d.mts +1 -1
- package/dist/utilities/window-size.d.mts +1 -1
- package/dist/utilities/window-size.test.mjs +2 -2
- package/package.json +1 -1
- package/dist/custom-elements-CBuenqVD.d.mts +0 -41
- package/dist/slot-BnzxFBfO.mjs +0 -198
- package/dist/slot-CfafCBOW.d.mts +0 -121
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { async } from "./async.mjs";
|
|
6
6
|
import { createInterval } from "./interval.mjs";
|
|
7
7
|
//#region src/utilities/interval.test.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
2
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
2
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
3
3
|
import { currentLocation } from "./location.mjs";
|
|
4
4
|
//#region src/utilities/location.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createLongPress } from "./long-press.mjs";
|
|
6
6
|
//#region src/utilities/long-press.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createMediaDevices } from "./media-devices.mjs";
|
|
6
6
|
//#region src/utilities/media-devices.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createMediaPlayer } from "./media-player.mjs";
|
|
6
6
|
//#region src/utilities/media-player.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createMutationObserver } from "./mutation-observer.mjs";
|
|
6
6
|
//#region src/utilities/mutation-observer.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
2
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
2
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
3
3
|
import { online } from "./network.mjs";
|
|
4
4
|
//#region src/utilities/network.test.ts
|
|
5
5
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { onClickOutside } from "./on-click-outside.mjs";
|
|
6
6
|
//#region src/utilities/on-click-outside.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope, m as signal } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createPrevious } from "./previous.mjs";
|
|
6
6
|
//#region src/utilities/previous.test.ts
|
|
7
7
|
describe("createPrevious", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as effect } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { ReactivePromise, promise } from "./promise.mjs";
|
|
6
6
|
//#region src/utilities/promise.test.ts
|
|
7
7
|
describe("ReactivePromise", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { p as onCleanup } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { retry } from "./retry.mjs";
|
|
6
6
|
//#region src/utilities/retry.test.ts
|
|
7
7
|
describe("retry", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as it, l as describe, o as afterEach, s as beforeAll } from "../benchmark.CX_oY03V-
|
|
2
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as it, l as describe, o as afterEach, s as beforeAll } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
2
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
3
3
|
import { isLocalNavigationEvent, match, matches, navigate, patchHistory } from "./routing.mjs";
|
|
4
4
|
//#region src/utilities/routing.test.ts
|
|
5
5
|
beforeAll(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createSearchParam } from "./search-params.mjs";
|
|
6
6
|
//#region src/utilities/search-params.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { p as test } from "../benchmark.CX_oY03V-
|
|
2
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { p as test } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
2
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
3
3
|
//#region src/utilities/ssr.test.ts
|
|
4
4
|
// @vitest-environment node
|
|
5
5
|
test.each([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createLocalStorage, createSessionStorage } from "./storage.mjs";
|
|
6
6
|
//#region src/utilities/storage.test.ts
|
|
7
7
|
describe("createLocalStorage", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope, m as signal } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { c as beforeEach, f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { c as beforeEach, f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createThrottled } from "./throttled.mjs";
|
|
6
6
|
//#region src/utilities/throttled.test.ts
|
|
7
7
|
beforeEach(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as effectScope } from "../lib-CVfOddra.mjs";
|
|
2
2
|
import "../signals/index.mjs";
|
|
3
|
-
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-
|
|
4
|
-
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-
|
|
3
|
+
import { f as it, l as describe, o as afterEach } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
4
|
+
import { n as vi, t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
5
5
|
import { createTimeout } from "./timeout.mjs";
|
|
6
6
|
//#region src/utilities/timeout.test.ts
|
|
7
7
|
afterEach(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as it, l as describe } from "../benchmark.CX_oY03V-
|
|
2
|
-
import { t as globalExpect } from "../test.BmQO5GaM-
|
|
1
|
+
import { f as it, l as describe } from "../benchmark.CX_oY03V-CsUg-gW0.mjs";
|
|
2
|
+
import { t as globalExpect } from "../test.BmQO5GaM-ZC2MPXQb.mjs";
|
|
3
3
|
import { windowSize } from "./window-size.mjs";
|
|
4
4
|
//#region src/utilities/window-size.test.ts
|
|
5
5
|
describe("windowSize (singleton)", () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elements-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"description": "A lightweight reactive UI library that transforms native HTMLElements into reactive components with signals. Ideal for framework-agnostic applications and web components.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"webcomponents",
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/custom-elements.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Registry of custom-element tags to their constructors.
|
|
4
|
-
* Users augment this interface to add typed JSX support for their elements:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* declare module "elements-kit/custom-elements" {
|
|
9
|
-
* interface CustomElementRegistry {
|
|
10
|
-
* "x-range": typeof XRange;
|
|
11
|
-
* }
|
|
12
|
-
* }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
interface CustomElementRegistry {}
|
|
16
|
-
type AnyCtor = CustomElementConstructor;
|
|
17
|
-
/**
|
|
18
|
-
* Register a custom element with the browser and return its class.
|
|
19
|
-
* Pair with a module augmentation of `CustomElementRegistry` to get typed JSX.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* import { defineElement } from "elements-kit/custom-elements";
|
|
24
|
-
*
|
|
25
|
-
* class XCounter extends HTMLElement {}
|
|
26
|
-
*
|
|
27
|
-
* defineElement("x-counter", XCounter);
|
|
28
|
-
*
|
|
29
|
-
* declare module "elements-kit/custom-elements" {
|
|
30
|
-
* interface CustomElementRegistry {
|
|
31
|
-
* "x-counter": typeof XCounter;
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* // JSX now gets typed props + typed ref
|
|
36
|
-
* // <x-counter />
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare function defineElement<Tag extends `${string}-${string}`, C extends AnyCtor>(tag: Tag, cls: C, options?: ElementDefinitionOptions): C;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { defineElement as n, CustomElementRegistry as t };
|
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 };
|