elements-kit 0.0.2 → 0.0.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.
@@ -1,7 +1,6 @@
1
- import { effect, isReactive } from "./signals.mjs";
1
+ import { a as effect, t as isReactive } from "./signals-Cr7xgAJH.mjs";
2
2
  import { $slots, Slot, Slots } from "./slot.mjs";
3
- import { t as resolveNode } from "./polyfill-DAalJpCO.mjs";
4
-
3
+ import { t as resolveNode } from "./lib-B2drrxlV.mjs";
5
4
  //#region \0rolldown/runtime.js
6
5
  var __defProp = Object.defineProperty;
7
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -9,45 +8,35 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
9
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
9
  var __exportAll = (all, no_symbols) => {
11
10
  let target = {};
12
- for (var name in all) {
13
- __defProp(target, name, {
14
- get: all[name],
15
- enumerable: true
16
- });
17
- }
18
- if (!no_symbols) {
19
- __defProp(target, Symbol.toStringTag, { value: "Module" });
20
- }
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
21
16
  return target;
22
17
  };
23
18
  var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
26
- key = keys[i];
27
- if (!__hasOwnProp.call(to, key) && key !== except) {
28
- __defProp(to, key, {
29
- get: ((k) => from[k]).bind(null, key),
30
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
31
- });
32
- }
33
- }
19
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
20
+ key = keys[i];
21
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
22
+ get: ((k) => from[k]).bind(null, key),
23
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
24
+ });
34
25
  }
35
26
  return to;
36
27
  };
37
28
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
38
-
39
29
  //#endregion
40
30
  //#region src/jsx-runtime/constants.ts
41
31
  var constants_exports = /* @__PURE__ */ __exportAll({ ReservedNameSpaces: () => ReservedNameSpaces });
42
- import * as import_dom_expressions_src_constants from "dom-expressions/src/constants";
43
- __reExport(constants_exports, import_dom_expressions_src_constants);
32
+ import * as import_dom_expressions_src_constants_js from "dom-expressions/src/constants.js";
33
+ __reExport(constants_exports, import_dom_expressions_src_constants_js);
44
34
  const ReservedNameSpaces = new Set([
45
35
  "class",
46
36
  "on",
47
37
  "style",
48
38
  "prop"
49
39
  ]);
50
-
51
40
  //#endregion
52
41
  //#region src/jsx-runtime/children.ts
53
42
  function hasSlots(node) {
@@ -107,7 +96,6 @@ function resolveChild(value) {
107
96
  function ensureFlatArray(raw) {
108
97
  return (Array.isArray(raw) ? raw : [raw]).flat(Infinity);
109
98
  }
110
-
111
99
  //#endregion
112
100
  //#region src/jsx-runtime/properties.ts
113
101
  function applyProps(node, props) {
@@ -217,11 +205,9 @@ function setEvent(el, key, handler) {
217
205
  el.addEventListener(event, handler);
218
206
  return () => el.removeEventListener(event, handler);
219
207
  }
220
-
221
208
  //#endregion
222
209
  //#region src/jsx-runtime/ref.ts
223
210
  const $ref = Symbol("ref");
224
-
225
211
  //#endregion
226
212
  //#region src/jsx-runtime/element.ts
227
213
  function createElement(type, { [$ref]: ref, ...props } = {}) {
@@ -272,6 +258,5 @@ function attachDisposables(el, disposables) {
272
258
  function disposeElement(el) {
273
259
  el[Symbol.dispose]?.();
274
260
  }
275
-
276
261
  //#endregion
277
- export { disposeElement as n, createElement as t };
262
+ export { disposeElement as n, createElement as t };
@@ -0,0 +1,263 @@
1
+ import { u as ValueOrReactive } from "./index-DJejH8Ff.mjs";
2
+
3
+ //#region src/signals/lib.d.ts
4
+ /**
5
+ * Returns `true` if `fn` is a signal handle created by {@link signal}.
6
+ *
7
+ * Relies on `Function.name` matching the internal `signalOper` function name.
8
+ */
9
+ declare function isSignal(fn: () => void): boolean;
10
+ /**
11
+ * Returns `true` if `fn` is a computed handle created by {@link computed}.
12
+ *
13
+ * Relies on `Function.name` matching the internal `computedOper` function name.
14
+ */
15
+ declare function isComputed(fn: () => void): boolean;
16
+ /**
17
+ * Returns `true` if `fn` is an effect cleanup handle created by {@link effect}.
18
+ *
19
+ * Relies on `Function.name` matching the internal `effectOper` function name.
20
+ */
21
+ declare function isEffect(fn: () => void): boolean;
22
+ /**
23
+ * Returns `true` if `fn` is an effectScope cleanup handle created by
24
+ * {@link effectScope}.
25
+ *
26
+ * Relies on `Function.name` matching the internal `effectScopeOper` function name.
27
+ */
28
+ declare function isEffectScope(fn: () => void): boolean;
29
+ /**
30
+ * Creates a mutable reactive signal.
31
+ *
32
+ * - **Read**: call with no arguments → returns the current value and
33
+ * subscribes the active tracking context.
34
+ * - **Write**: call with a value → updates the signal and schedules
35
+ * downstream effects if the value changed.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const count = signal(0);
40
+ * count(); // → 0 (read)
41
+ * count(1); // write – effects depending on count will re-run
42
+ * count(); // → 1
43
+ * ```
44
+ */
45
+ declare function signal<T>(): {
46
+ (): T | undefined;
47
+ (value: T | undefined): void;
48
+ };
49
+ declare function signal<T>(initialValue: T): {
50
+ (): T;
51
+ (value: T): void;
52
+ };
53
+ /**
54
+ * Creates a lazily-evaluated computed value.
55
+ *
56
+ * The `getter` is only called when the computed value is read **and** one of
57
+ * its dependencies has changed since the last evaluation. If nothing has
58
+ * changed the cached `value` is returned without re-running `getter`.
59
+ *
60
+ * Computed values are read-only; they cannot be set directly.
61
+ *
62
+ * @param getter - Pure function deriving a value from other reactive sources.
63
+ * Receives the previous value as an optional optimisation hint.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * const a = signal(1);
68
+ * const b = signal(2);
69
+ * const sum = computed(() => a() + b());
70
+ *
71
+ * sum(); // → 3
72
+ * a(10);
73
+ * sum(); // → 12 (re-evaluated lazily)
74
+ * ```
75
+ */
76
+ declare function computed<T>(getter: (previousValue?: T) => T): () => T;
77
+ /**
78
+ * Creates a reactive side-effect that runs immediately and re-runs whenever
79
+ * any signal or computed it read during its last execution changes.
80
+ *
81
+ * Use {@link onCleanup} inside `fn` to register teardown logic that runs
82
+ * before each re-execution and on final disposal.
83
+ *
84
+ * If `effect` is called inside an `effectScope` or another `effect`, the
85
+ * new effect is automatically owned by the outer scope and will be disposed
86
+ * when the scope is disposed.
87
+ *
88
+ * @param fn - The side-effect body. Reactive reads inside this function
89
+ * establish dependency links.
90
+ * @returns A disposal function. Call it to stop the effect and run any
91
+ * registered cleanup.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const url = signal('/api/data');
96
+ *
97
+ * const stop = effect(() => {
98
+ * const controller = new AbortController();
99
+ * fetch(url(), { signal: controller.signal });
100
+ * onCleanup(() => controller.abort());
101
+ * });
102
+ *
103
+ * url('/api/other'); // previous fetch is aborted, new one starts
104
+ * stop(); // final cleanup: abort the last fetch
105
+ * ```
106
+ */
107
+ declare function effect(fn: () => void): () => void;
108
+ /**
109
+ * Creates an ownership scope that groups reactive effects so they can all be
110
+ * disposed at once.
111
+ *
112
+ * Effects and nested scopes created inside `fn` are linked to this scope.
113
+ * When the returned disposal function is called, all owned effects are stopped
114
+ * in cascade – triggering their registered {@link onCleanup} callbacks – and
115
+ * the scope itself is removed from any parent scope that owns it.
116
+ *
117
+ * @param fn - Synchronous setup function. Create effects and nested scopes
118
+ * here.
119
+ * @returns A disposal function that tears down all owned effects and the scope
120
+ * itself.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * const stopAll = effectScope(() => {
125
+ * effect(() => console.log('a:', a()));
126
+ * effect(() => console.log('b:', b()));
127
+ * });
128
+ *
129
+ * stopAll(); // both effects stopped simultaneously
130
+ * ```
131
+ */
132
+ declare function effectScope(fn: () => void): () => void;
133
+ /**
134
+ * Registers a cleanup callback for the currently executing effect or scope.
135
+ *
136
+ * The callback will be called:
137
+ * 1. **Before the next re-run** of the enclosing effect (so resources from
138
+ * the previous run are released before the new run sets them up again).
139
+ * 2. **On final disposal** of the effect, whether triggered explicitly by
140
+ * calling the effect's cleanup handle or implicitly by an owning
141
+ * `effectScope` being disposed.
142
+ *
143
+ * Calling `onCleanup` outside of a tracking context (no active effect) is a
144
+ * no-op; it does **not** throw.
145
+ *
146
+ * Only one cleanup function per effect run is supported. Calling `onCleanup`
147
+ * multiple times within the same run overwrites the previous registration.
148
+ *
149
+ * @param fn - The teardown callback.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * effect(() => {
154
+ * const id = setInterval(() => tick(), 1000);
155
+ * onCleanup(() => clearInterval(id));
156
+ * });
157
+ * ```
158
+ *
159
+ * @example Composable helper – no prop-drilling needed:
160
+ * ```ts
161
+ * function useEventListener(target: EventTarget, type: string, handler: EventListener) {
162
+ * target.addEventListener(type, handler);
163
+ * onCleanup(() => target.removeEventListener(type, handler));
164
+ * }
165
+ *
166
+ * effect(() => {
167
+ * useEventListener(window, 'resize', onResize);
168
+ * });
169
+ * ```
170
+ */
171
+ declare function onCleanup(fn: () => void): void;
172
+ /**
173
+ * Runs `fn` as a single atomic update: all signal writes inside `fn` are
174
+ * collected and effects are flushed only once after `fn` returns, rather than
175
+ * after each individual write.
176
+ *
177
+ * Batches can be nested; the flush only occurs when the outermost batch
178
+ * completes.
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * batch(() => {
183
+ * x(1);
184
+ * y(2);
185
+ * z(3);
186
+ * }); // effects that depend on x, y, or z run once here
187
+ * ```
188
+ */
189
+ declare function batch(fn: () => void): void;
190
+ /**
191
+ * Executes `fn` in a non-tracking context: any signals read inside `fn` do
192
+ * **not** create dependency links on the currently active subscriber.
193
+ *
194
+ * Useful when you need to read a signal's current value without subscribing to
195
+ * future changes.
196
+ *
197
+ * @returns The value returned by `fn`.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const logCount = effect(() => {
202
+ * console.log('triggered by a:', a());
203
+ * // read b without subscribing – effect won't re-run when b changes
204
+ * console.log('current b:', untracked(() => b()));
205
+ * });
206
+ * ```
207
+ */
208
+ declare function untracked<T>(fn: () => T): T;
209
+ /**
210
+ * Manually triggers all subscribers of every signal read inside `fn`.
211
+ *
212
+ * Unlike writing to a signal, `trigger` does not change the signal's value; it
213
+ * only forces downstream effects and computeds to re-evaluate.
214
+ *
215
+ * @param fn - Function whose reactive reads identify the signals to trigger.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * const items = signal([1, 2, 3]);
220
+ *
221
+ * // Mutate in place (referential equality won't detect the change):
222
+ * items().push(4);
223
+ * trigger(() => items()); // manually notify subscribers
224
+ * ```
225
+ */
226
+ declare function trigger(fn: () => void): void;
227
+ //#endregion
228
+ //#region src/signals/index.d.ts
229
+ declare function isReactive<T>(value: ValueOrReactive<T>): value is () => T;
230
+ type Updater<T> = (value: T) => void;
231
+ type Computed<T> = () => T;
232
+ type Signal<T> = Updater<T> & Computed<T>;
233
+ /**
234
+ * A decorator that makes a class field reactive by automatically wrapping its value in a signal.
235
+ *
236
+ * The field behaves like a normal property (get/set) but reactivity is tracked under the hood.
237
+ * Any reads will subscribe to the signal and any writes will trigger updates.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * class Counter {
242
+ * @reactive()
243
+ * count: number = 0;
244
+ * }
245
+ *
246
+ * const counter = new Counter();
247
+ * counter.count++; // Triggers reactivity
248
+ * console.log(counter.count); // Subscribes to changes
249
+ * ```
250
+ *
251
+ * @remarks
252
+ * Equivalent to manually creating a private signal and getter/setter:
253
+ * ```ts
254
+ * class Counter {
255
+ * #count = signal(0);
256
+ * get count() { return this.#count(); }
257
+ * set count(value) { this.#count(value); }
258
+ * }
259
+ * ```
260
+ */
261
+ declare function reactive<This extends object, Value>(source?: (self: This) => Signal<Value>): (_target: unknown, context: ClassFieldDecoratorContext<This, Value>) => (this: This, initialValue: Value) => Value;
262
+ //#endregion
263
+ export { untracked as _, reactive as a, effect as c, isEffect as d, isEffectScope as f, trigger as g, signal as h, isReactive as i, effectScope as l, onCleanup as m, Signal as n, batch as o, isSignal as p, Updater as r, computed as s, Computed as t, isComputed as u };
@@ -0,0 +1,89 @@
1
+ import { t as PrimitiveNodeType } from "./polyfill-BEL-HWkO.mjs";
2
+
3
+ //#region src/builder/index.d.ts
4
+ declare const DISPOSABLES: unique symbol;
5
+ declare const DISPOSE: symbol;
6
+ declare const VALUE: unique symbol;
7
+ declare const EFFECT: unique symbol;
8
+ declare class ElementBuilder<T extends Element = Element> {
9
+ /** Dispose the reactive element and run all cleanup functions */
10
+ [DISPOSE]: () => void;
11
+ /** The underlying DOM element */
12
+ private [VALUE];
13
+ /** A set of cleanup functions to run when disposing the element */
14
+ private [DISPOSABLES];
15
+ [EFFECT](fn: () => void): this;
16
+ private constructor();
17
+ static create<T extends Element>(el: T): ReactiveElement<T>;
18
+ children(...children: ValueOrReactive<ElementBuilder | Node | string | number>[]): T;
19
+ ref(): T;
20
+ ref(apply: (ref: T) => void | (() => void)): this;
21
+ on<K extends keyof HTMLElementEventMap>(eventType: K, listener: (ev: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): this;
22
+ }
23
+ declare function toNode(c: ElementBuilder | PrimitiveNodeType): Node;
24
+ declare function builder<T extends Element>(el: T): ReactiveElementOf<T>;
25
+ /**
26
+ * Callable overloads matching the Proxy apply trap → ref() behavior.
27
+ * Calling a reactive element as a function delegates to ref():
28
+ * el() → returns the raw DOM element
29
+ * el((ref) => {}) → applies a side-effect, returns the builder for chaining
30
+ */
31
+ interface RefCallable<T extends Element> {
32
+ (): T;
33
+ (apply: (ref: T) => void | (() => void)): this;
34
+ }
35
+ type ReactiveElement<T extends Element> = ElementBuilder<T> & RefCallable<T>;
36
+ type ValueOrReactive<T> = (() => T) | T;
37
+ type ValueOrReactiveArray<T extends any[]> = { [K in keyof T]: ValueOrReactive<T[K]> | T[K] };
38
+ /**
39
+ * Filter keys that are writable (exclude readonly and getter-only).
40
+ */
41
+ type WritableKeys<T> = { [K in keyof T]: (<U>() => U extends { [Q in K]: T[K] } ? 1 : 2) extends (<U>() => U extends { readonly [Q in K]: T[K] } ? 1 : 2) ? never : K }[keyof T];
42
+ /**
43
+ * Extracts the object chaining part of ReactiveBuilder.
44
+ * Used for properties like `style` where you can do both:
45
+ * .style("padding: 20px;") // setter
46
+ * .style.padding("20px") // sub-property chaining
47
+ */
48
+ type Chain<R, T> = T extends object ? { [K in WritableKeys<T>]: Builder<R, T[K]> } : {};
49
+ type Builder<R, T = R> = T extends ((...args: infer U) => unknown) ? (...value: ValueOrReactiveArray<U>) => R : (value?: ValueOrReactive<T>) => R;
50
+ /**
51
+ * Types eligible for sub-property chaining (e.g., `.style.padding("20px")`).
52
+ */
53
+ type ChainableType = CSSStyleDeclaration | DOMTokenList | DOMStringMap | StylePropertyMap;
54
+ /**
55
+ * Filters keys to only writable data properties.
56
+ * Excludes methods (function-valued properties) and event handlers (`on*`).
57
+ */
58
+ type DataPropertyKeys<T> = { [K in keyof T]: K extends `on${string}` ? never : T[K] extends ((...args: any[]) => any) ? never : K }[keyof T];
59
+ /**
60
+ * Reactive setter for a single property.
61
+ * Chainable types (CSSStyleDeclaration, DOMTokenList, etc.) get both
62
+ * sub-property chaining and direct setter support.
63
+ */
64
+ type ReactiveSetter<R, T> = T extends ChainableType ? Chain<R, T> & ((value: ValueOrReactive<T>) => R) : (value: ValueOrReactive<T>) => R;
65
+ /**
66
+ * A fully-typed reactive element builder for any Element type.
67
+ * Automatically maps all writable data properties into reactive setters.
68
+ *
69
+ * Use this for custom elements instead of needing generated builder interfaces.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { reactive, type ReactiveElementOf } from "elements-kit";
74
+ *
75
+ * class MyElement extends HTMLElement {
76
+ * greeting = "hello";
77
+ * }
78
+ * customElements.define("my-element", MyElement);
79
+ *
80
+ * const myEl = () =>
81
+ * reactive(document.createElement("my-element") as MyElement);
82
+ *
83
+ * // Full type support for both own and inherited properties:
84
+ * myEl().greeting("world").style.padding("20px").id("main");
85
+ * ```
86
+ */
87
+ type ReactiveElementOf<T extends Element> = ElementBuilder<T> & { [K in WritableKeys<T> & DataPropertyKeys<T> & keyof T]: ReactiveSetter<ReactiveElementOf<T>, T[K]> };
88
+ //#endregion
89
+ export { EFFECT as a, ReactiveElementOf as c, builder as d, toNode as f, DISPOSE as i, VALUE as l, Chain as n, ElementBuilder as o, DISPOSABLES as r, ReactiveElement as s, Builder as t, ValueOrReactive as u };
package/dist/index.mjs CHANGED
@@ -1,7 +1,5 @@
1
- import { n as disposeElement } from "./element-B3gwJmBr.mjs";
2
- import { effect, signal, untracked } from "./signals.mjs";
3
- import "./polyfill-DAalJpCO.mjs";
4
-
1
+ import { n as disposeElement } from "./element-CCHXkEsj.mjs";
2
+ import { a as effect, f as signal, m as untracked } from "./signals-Cr7xgAJH.mjs";
5
3
  //#region src/components/for.ts
6
4
  /**
7
5
  * Keyed list renderer. Reconciles a reactive array into the DOM using a key
@@ -125,6 +123,5 @@ function moveEntry(parent, entry, before) {
125
123
  range.setEndAfter(entry.end);
126
124
  parent.insertBefore(range.extractContents(), before);
127
125
  }
128
-
129
126
  //#endregion
130
- export { For };
127
+ export { For };
@@ -1,4 +1,4 @@
1
- import { t as PrimitiveNodeType } from "../polyfill-Bvo2e52W.mjs";
1
+ import { t as PrimitiveNodeType } from "../polyfill-BEL-HWkO.mjs";
2
2
  import { JSX as JSX$1 } from "dom-expressions/src/jsx-h";
3
3
 
4
4
  //#region src/jsx-runtime/types.d.ts
@@ -1,4 +1,2 @@
1
- import { t as createElement } from "../element-B3gwJmBr.mjs";
2
- import "../polyfill-DAalJpCO.mjs";
3
-
4
- export { createElement as h, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
1
+ import { t as createElement } from "../element-CCHXkEsj.mjs";
2
+ export { createElement as h, createElement as jsx, createElement as jsxDEV, createElement as jsxs };
@@ -11,10 +11,5 @@ function resolveNode(c) {
11
11
  if (typeof c === "string" || typeof c === "number" || typeof c === "bigint" || typeof c === "symbol" || c instanceof Date || c instanceof RegExp) return document.createTextNode(String(c));
12
12
  throw new UnsupportedChildError(c);
13
13
  }
14
-
15
14
  //#endregion
16
- //#region src/polyfill.ts
17
- if (!Symbol.dispose) Object.defineProperty(Symbol, "dispose", { value: Symbol("dispose") });
18
-
19
- //#endregion
20
- export { resolveNode as t };
15
+ export { resolveNode as t };
@@ -0,0 +1,2 @@
1
+ import { _ as untracked, a as reactive, c as effect, d as isEffect, f as isEffectScope, g as trigger, h as signal, i as isReactive, l as effectScope, m as onCleanup, n as Signal, o as batch, p as isSignal, r as Updater, s as computed, t as Computed, u as isComputed } from "../index-C6xwOPCO.mjs";
2
+ export { Computed, Signal, Updater, batch, computed, effect, effectScope, isComputed, isEffect, isEffectScope, isReactive, isSignal, onCleanup, reactive, signal, trigger, untracked };
@@ -0,0 +1,2 @@
1
+ import { a as effect, c as isEffect, d as onCleanup, f as signal, i as computed, l as isEffectScope, m as untracked, n as reactive, o as effectScope, p as trigger, r as batch, s as isComputed, t as isReactive, u as isSignal } from "../signals-Cr7xgAJH.mjs";
2
+ export { batch, computed, effect, effectScope, isComputed, isEffect, isEffectScope, isReactive, isSignal, onCleanup, reactive, signal, trigger, untracked };
@@ -0,0 +1,14 @@
1
+ import { t as Computed } from "../../index-C6xwOPCO.mjs";
2
+
3
+ //#region src/signals/lib/media.d.ts
4
+ declare const isBrowser: boolean;
5
+ /**
6
+ * Creates a signal that tracks a CSS media query.
7
+ *
8
+ * @param query The media query string (e.g. '(max-width: 600px)')
9
+ * @param defaultState The default value (for SSR/hydration)
10
+ * @returns Computed<boolean> that is true if the query matches
11
+ */
12
+ declare function createMediaSignal(query: string, defaultState?: boolean): Computed<boolean>;
13
+ //#endregion
14
+ export { createMediaSignal, isBrowser };
@@ -0,0 +1,26 @@
1
+ import { d as onCleanup, f as signal } from "../../signals-Cr7xgAJH.mjs";
2
+ //#region src/signals/lib/media.ts
3
+ const isBrowser = typeof window !== "undefined";
4
+ /**
5
+ * Creates a signal that tracks a CSS media query.
6
+ *
7
+ * @param query The media query string (e.g. '(max-width: 600px)')
8
+ * @param defaultState The default value (for SSR/hydration)
9
+ * @returns Computed<boolean> that is true if the query matches
10
+ */
11
+ function createMediaSignal(query, defaultState) {
12
+ if (!isBrowser) return signal(defaultState ?? false);
13
+ const mql = window.matchMedia(query);
14
+ const state = signal(mql.matches);
15
+ const handler = () => {
16
+ state(mql.matches);
17
+ };
18
+ mql.addEventListener("change", handler);
19
+ const cleanup = () => {
20
+ mql.removeEventListener("change", handler);
21
+ };
22
+ onCleanup(cleanup);
23
+ return Object.assign(state, { [Symbol.dispose]: cleanup });
24
+ }
25
+ //#endregion
26
+ export { createMediaSignal, isBrowser };
@@ -0,0 +1,62 @@
1
+ import { t as Computed } from "../../index-C6xwOPCO.mjs";
2
+
3
+ //#region src/signals/lib/react.d.ts
4
+ /**
5
+ * Subscribe to any readable signal — writable or computed — returning its current value.
6
+ *
7
+ * Accepts any zero-argument callable `() => T`, which includes both `Signal<T>` and
8
+ * `Computed<T>`. Using `() => T` instead of `Computed<T>` prevents TypeScript from
9
+ * picking the write overload of `Signal<T>` during type inference.
10
+ *
11
+ * @template T - The type of the signal value.
12
+ * @param value - A writable `Signal<T>` or a derived `Computed<T>`.
13
+ * @returns The current value, updated on every signal change.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const count = signal(0);
18
+ * const double = computed(() => count() * 2);
19
+ *
20
+ * function Display() {
21
+ * const countValue = useSignal(count);
22
+ * const doubleValue = useSignal(double);
23
+ * return <div>{countValue} × 2 = {doubleValue}</div>;
24
+ * }
25
+ * ```
26
+ */
27
+ declare function useSignal<T>(value: () => T): T;
28
+ /**
29
+ * Create a signal effect scope tied to a React component's lifetime.
30
+ *
31
+ * All effects registered inside `callback` are grouped into a single scope. The scope — and every effect within it — is automatically stopped when the component unmounts.
32
+ *
33
+ * If your callback returns a `Computed<T>` signal, the hook will always return its current value, updating reactively as dependencies change. If your callback returns `void`, the value will be `undefined`.
34
+ *
35
+ * Returns the current value of the computed signal (or `undefined`).
36
+ *
37
+ * Use this when you want to create multiple related effects at once without individually managing each one's lifecycle. All effects and cleanups inside the callback are automatically cleaned up on unmount.
38
+ *
39
+ * @template T - The type of the computed value (if any).
40
+ * @param callback - A function that registers one or more signal effects, optionally returning a `Computed<T>`.
41
+ * @returns `value` — the current value of the computed signal (or `undefined`).
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * function Analytics() {
46
+ * useScope(() => {
47
+ * effect(() => console.log("page:", currentPage()));
48
+ * effect(() => console.log("user:", currentUser()));
49
+ * });
50
+ * return null;
51
+ * }
52
+ *
53
+ * // With computed value:
54
+ * function DoubleCounter() {
55
+ * const double = useScope(() => computed(() => count() * 2));
56
+ * return <div>{double}</div>;
57
+ * }
58
+ * ```
59
+ */
60
+ declare function useScope<T>(callback: () => Computed<T> | void): T | void;
61
+ //#endregion
62
+ export { useScope, useSignal };