//#region src/signals/lib.d.ts declare const SIGNAL: unique symbol; declare const COMPUTED: unique symbol; declare const EFFECT: unique symbol; declare const EFFECT_SCOPE: unique symbol; /** * Returns `true` if `fn` is a signal handle created by {@link signal}. * * Relies on the SIGNAL symbol. */ declare function isSignal(fn: unknown): boolean; /** * Returns `true` if `fn` is a computed handle created by {@link computed}. * * Relies on the COMPUTED symbol. */ declare function isComputed(fn: unknown): boolean; /** * Returns `true` if `fn` is an effect cleanup handle created by {@link effect}. * * Relies on the EFFECT symbol. */ declare function isEffect(fn: unknown): boolean; /** * Returns `true` if `fn` is an effectScope cleanup handle created by * {@link effectScope}. * * Relies on `Function.name` matching the internal `effectScopeOper` function name. */ declare function isEffectScope(fn: () => void): boolean; /** * Creates a mutable reactive signal. * * - **Read**: call with no arguments → returns the current value and * subscribes the active tracking context. * - **Write**: call with a value → updates the signal and schedules * downstream effects if the value changed. * * @example * ```ts * const count = signal(0); * count(); // → 0 (read) * count(1); // write – effects depending on count will re-run * count(); // → 1 * ``` */ declare function signal(): Updater & Computed; declare function signal(initialValue: T): Updater & Computed; /** * Creates a lazily-evaluated computed value. * * The `getter` is only called when the computed value is read **and** one of * its dependencies has changed since the last evaluation. If nothing has * changed the cached `value` is returned without re-running `getter`. * * Computed values are read-only; they cannot be set directly. * * @param getter - Pure function deriving a value from other reactive sources. * Receives the previous value as an optional optimisation hint. * * @example * ```ts * const a = signal(1); * const b = signal(2); * const sum = computed(() => a() + b()); * * sum(); // → 3 * a(10); * sum(); // → 12 (re-evaluated lazily) * ``` */ declare function computed(getter: (previousValue?: T) => T): () => T; /** * Creates a reactive side-effect that runs immediately and re-runs whenever * any signal or computed it read during its last execution changes. * * Use {@link onCleanup} inside `fn` to register teardown logic that runs * before each re-execution and on final disposal. * * If `effect` is called inside an `effectScope` or another `effect`, the * new effect is automatically owned by the outer scope and will be disposed * when the scope is disposed. * * @param fn - The side-effect body. Reactive reads inside this function * establish dependency links. * @returns A disposal function. Call it to stop the effect and run any * registered cleanup. * * @example * ```ts * const url = signal('/api/data'); * * const stop = effect(() => { * const controller = new AbortController(); * fetch(url(), { signal: controller.signal }); * onCleanup(() => controller.abort()); * }); * * url('/api/other'); // previous fetch is aborted, new one starts * stop(); // final cleanup: abort the last fetch * ``` */ /** * @internal Method key for settling a reactive async wrapper from a * serialized server snapshot (hydration seeding). Lives here so * `utilities/promise`, `utilities/async` and `hydrate` can share it without * a utility-to-utility dependency. */ declare const SEED: unique symbol; /** * @internal Method key for the hydrate claim protocol: the claim walk hands * each async wrapper its ek-data record (or undefined). The wrapper decides — * seed and discard any deferred run, or execute the deferred run now. */ declare const CLAIM: unique symbol; declare function effect(fn: () => void): () => void; /** * Creates an ownership scope that groups reactive effects so they can all be * disposed at once. * * Effects and nested scopes created inside `fn` are linked to this scope. * When the returned disposal function is called, all owned effects are stopped * in cascade – triggering their registered {@link onCleanup} callbacks – and * the scope itself is removed from any parent scope that owns it. * * @param fn - Synchronous setup function. Create effects and nested scopes * here. * @returns A disposal function that tears down all owned effects and the scope * itself. * * @example * ```ts * const stopAll = effectScope(() => { * effect(() => console.log('a:', a())); * effect(() => console.log('b:', b())); * }); * * stopAll(); // both effects stopped simultaneously * ``` */ declare function effectScope(fn: () => void): () => void; /** * Registers a cleanup callback for the currently executing effect or scope. * * The callback will be called: * 1. **Before the next re-run** of the enclosing effect (so resources from * the previous run are released before the new run sets them up again). * 2. **On final disposal** of the effect, whether triggered explicitly by * calling the effect's cleanup handle or implicitly by an owning * `effectScope` being disposed. * * Calling `onCleanup` outside of a tracking context (no active effect) is a * no-op; it does **not** throw. * * Only one cleanup function per effect run is supported. Calling `onCleanup` * multiple times within the same run overwrites the previous registration. * * @param fn - The teardown callback. * * @example * ```ts * effect(() => { * const id = setInterval(() => tick(), 1000); * onCleanup(() => clearInterval(id)); * }); * ``` * * @example Composable helper – no prop-drilling needed: * ```ts * function useEventListener(target: EventTarget, type: string, handler: EventListener) { * target.addEventListener(type, handler); * onCleanup(() => target.removeEventListener(type, handler)); * } * * effect(() => { * useEventListener(window, 'resize', onResize); * }); * ``` */ declare function onCleanup(fn: () => void): void; /** * Runs `fn` as a single atomic update: all signal writes inside `fn` are * collected and effects are flushed only once after `fn` returns, rather than * after each individual write. * * Batches can be nested; the flush only occurs when the outermost batch * completes. * * @example * ```ts * batch(() => { * x(1); * y(2); * z(3); * }); // effects that depend on x, y, or z run once here * ``` */ declare function batch(fn: () => void): void; /** * Executes `fn` in a non-tracking context: any signals read inside `fn` do * **not** create dependency links on the currently active subscriber. * * Useful when you need to read a signal's current value without subscribing to * future changes. * * @returns The value returned by `fn`. * * @example * ```ts * const logCount = effect(() => { * console.log('triggered by a:', a()); * // read b without subscribing – effect won't re-run when b changes * console.log('current b:', untracked(b)); * }); * ``` */ declare function untracked(fn: Computed): T; /** * Manually triggers all subscribers of every signal read inside `fn`. * * Unlike writing to a signal, `trigger` does not change the signal's value; it * only forces downstream effects and computeds to re-evaluate. * * @param fn - Function whose reactive reads identify the signals to trigger. * * @example * ```ts * const items = signal([1, 2, 3]); * * // Mutate in place (referential equality won't detect the change): * items().push(4); * trigger(items); // manually notify subscribers * ``` */ declare function trigger(fn: Computed): void; //#endregion //#region src/signals/index.d.ts /** * Type-guard: `true` when `value` is a reactive source (`signal` or `computed`), * `false` when it is a plain value. * * Use this when you accept {@link MaybeReactive} and need to branch on whether * the caller passed a live source or a static value. * * @example * ```ts * import { signal, isReactive } from "elements-kit/signals"; * * const a: MaybeReactive = 5; * const b: MaybeReactive = signal(0); * const c: () => number = () => 5; * * isReactive(a); // false * isReactive(b); // true * isReactive(c); // false * ``` */ declare function isReactive(value: MaybeReactive): value is () => T; /** Writer half of a {@link Signal}: `sig(next)` assigns a new value. */ type Updater = (value: T) => void; /** Zero-arg getter that subscribes the current tracking scope on call. */ type Computed = () => T; /** * A reactive read/write cell — callable as both a getter (no args) and a * setter (one arg). * * @example * ```ts * import { signal } from "elements-kit/signals"; * * const count: Signal = signal(0); * count(); // read → 0 (subscribes the active scope) * count(5); // write → notifies subscribers * ``` */ type Signal = Updater & Computed; /** * A decorator that makes a class field reactive by automatically wrapping its value in a signal. * * The field behaves like a normal property (get/set) but reactivity is tracked under the hood. * Any reads will subscribe to the signal and any writes will trigger updates. * * @example * ```ts * class Counter { * \@reactive() count: number = 0; * } * * const counter = new Counter(); * counter.count++; // Triggers reactivity * console.log(counter.count); // Subscribes to changes * ``` * * @remarks * Equivalent to manually creating a private signal and getter/setter: * ```ts * class Counter { * #count = signal(0); * get count() { return this.#count(); } * set count(value) { this.#count(value); } * } * ``` */ declare function reactive(source?: (self: This) => Signal): (_target: unknown, context: ClassFieldDecoratorContext) => (this: This, initialValue: Value) => Value; /** * A value that may be static or reactive. Accepts a plain `T` or a * zero-arg getter (`() => T`) — typically a `signal` or `computed`. * * Used across the library anywhere a prop or attribute may be bound to * reactive state. Resolve with {@link resolve}, detect with {@link isReactive}. * * @template T — the value type. * * @example * ```ts * import { signal, computed } from "elements-kit/signals"; * * const count = signal(0); * const double = computed(() => count() * 2); * * const a: MaybeReactive = 5; // static * const b: MaybeReactive = count; // signal (getter) * const c: MaybeReactive = double; // computed (getter) * ``` */ type MaybeReactive = T | Computed; /** * Resolve a {@link MaybeReactive} to its current value. Calls the getter when * reactive (a `signal` or `computed`); returns the value as-is otherwise — an * unbranded function is a value, not a source, so a callback survives intact. * * This is how a function component reads a prop it declared `MaybeReactive`: * the runtime hands props over exactly as the caller wrote them, so the value * may be either form. Reading inside an effect or a JSX getter subscribes. * * @example * ```ts * resolve(5); // 5 * resolve(count); // current count value — signal * resolve(props.label); // current value, whichever form the caller passed * resolve(() => 5); // the function itself — unbranded, so not a source * ``` */ declare function resolve(value: MaybeReactive): T; /** * A props bag where every key is a getter — what {@link computedProps} produces. * The counterpart to `Props

`: that one is what a caller may pass, this is * what a body reads. Optional keys lose their `?`, so `props.excited()` needs * no `?.` — the getter is always there, only its result may be undefined. * * @template P — the raw prop shape. */ type ComputedProps

= { readonly [K in keyof P]-?: Computed }; /** * Reactive keys become the value they yield. `computedProps` infers its shape * verbatim and unwraps here, because inferring through `T | Computed` picks * the `Computed` branch for any function prop and yields its return type. */ type Unwrap

= { [K in keyof P]: UnwrapValue }; /** Naked parameter so it distributes: `T | Computed` collapses to `T`. */ type UnwrapValue = V extends Computed ? T : V; /** Arity of a call signature; `0` for anything that is not callable. */ type ArgCount = F extends ((...args: infer A) => unknown) ? A["length"] : 0; type ArgFnPropError = "computedProps: a prop that takes arguments cannot be inferred here — read it off the raw props instead"; /** * Reject props that take arguments — inference cannot tell them from a getter. * Zero-arg ones stay: `Signal` and `Computed` are zero-arg callables too. */ type NoArgFnProps

= { [K in keyof P]: ArgCount extends 0 ? P[K] : ArgFnPropError }; /** * Turn props into a bag of per-key getters, so a body reads one shape no matter * which form the caller passed. Opt-in: the JSX runtime hands function * components their props untouched. * * Every key is callable, including one the caller omitted. A getter is always * truthy, so defaults go on the call: `props.excited() ?? "…"`. Keys are * branded sources, so they keep working when forwarded to a child component. * * Function props are the limit: a prop taking arguments is rejected, and a * zero-arg one types as its return value. Read those off the raw props. * * @example * ```ts * const count = signal(0); * const props = computedProps({ count, label: "n" }); * props.count(); // 0 — subscribes to count * props.label(); // "n" * ``` */ declare function computedProps

(raw: P & NoArgFnProps

): ComputedProps>; //#endregion export { isSignal as C, untracked as D, trigger as E, isEffectScope as S, signal as T, computed as _, Updater as a, isComputed as b, reactive as c, COMPUTED as d, EFFECT as f, batch as g, SIGNAL as h, Signal as i, resolve as l, SEED as m, ComputedProps as n, computedProps as o, EFFECT_SCOPE as p, MaybeReactive as r, isReactive as s, Computed as t, CLAIM as u, effect as v, onCleanup as w, isEffect as x, effectScope as y };