//#region src/index.d.ts /** * Represents a node created by Luna's reactive system. * This is an opaque type - the actual structure is managed by MoonBit. */ type LunaNode = unknown; type Accessor = () => T; type Setter = (value: T | ((prev: T) => T)) => void; type Signal = [Accessor, Setter]; interface ForProps { each: Accessor | T[]; fallback?: LunaNode; children: (item: T, index: Accessor) => LunaNode; } interface ShowProps { when: T | Accessor; fallback?: LunaNode; /** * Children receives an accessor function (SolidJS-style). * Use: {(item) =>

{item()}

} */ children: (() => LunaNode) | ((item: Accessor>) => LunaNode); } interface IndexProps { each: Accessor | T[]; fallback?: LunaNode; children: (item: Accessor, index: number) => LunaNode; } interface Context { id: number; default_value: () => T; providers: unknown[]; } interface ProviderProps { context: Context; value: T; /** * Must be a function. JSX evaluates plain children *before* `Provider` runs, * so a `useContext()` inside them would read the enclosing value instead of * this one. Passing a non-function throws rather than reading it silently. */ children: () => LunaNode; } interface MatchProps { when: T | Accessor; /** * Children receives an accessor function (SolidJS-style). * Use: {(item) =>

{item()}

} */ children: (() => LunaNode) | ((item: Accessor>) => LunaNode); } interface SwitchProps { fallback?: LunaNode; children: LunaNode[]; } interface PortalProps { mount?: Element | string; useShadow?: boolean; /** * A node, or a thunk returning one. Unlike `Provider`, a portal only * relocates its children, so nothing depends on when they are built. */ children: LunaNode | (() => LunaNode); } interface ResourceAccessor { (): T | undefined; loading: boolean; error: string | undefined; state: 'pending' | 'ready' | 'errored' | 'unresolved'; latest: T | undefined; /** Reactive accessor for pending state - tracks dependencies unlike `loading` */ pending: Accessor; } type SetStoreFunction = (...args: any[]) => void; /** * Creates a reactive signal (SolidJS-style) */ declare function createSignal(initialValue: T): Signal; /** * Creates a reactive effect (SolidJS-style) * Deferred execution via microtask - runs after rendering completes */ declare function createEffect(fn: () => void): () => void; /** * Creates a render effect (SolidJS-style) * Immediate/synchronous execution - runs during rendering */ declare function createRenderEffect(fn: () => void): () => void; /** * Creates a memoized computed value (SolidJS-style) */ declare function createMemo(fn: () => T): Accessor; /** * Explicit dependency tracking helper (SolidJS-style) * Wraps a function to explicitly specify which signals to track * * @template T * @template U * @param {(() => T) | Array<() => any>} deps - Signal accessor(s) to track * @param {(input: T, prevInput?: T, prevValue?: U) => U} fn - Function to run with dependency values * @param {{ defer?: boolean }} [options] - Options (defer: don't run on initial) * @returns {(prevValue?: U) => U | undefined} */ declare function on(deps: any, fn: any, options?: {}): (injectedPrevValue: any) => any; /** * Merge multiple props objects, with later objects taking precedence (SolidJS-style) * Event handlers and refs are merged, other props are overwritten * * @template T * @param {...T} sources - Props objects to merge * @returns {T} */ declare function mergeProps(...sources: any[]): {}; /** * Split props into multiple objects based on key lists (SolidJS-style) * * @template T * @template K * @param {T} props - Props object to split * @param {...K[]} keys - Arrays of keys to extract * @returns {[Pick, Omit]} */ declare function splitProps(props: any, ...keys: any[]): any[]; /** * Creates a resource for async data (SolidJS-style) */ declare function createResource(fetcher: (resolve: (v: T) => void, reject: (e: string) => void) => void): [ResourceAccessor, { refetch: () => void; }]; /** * Creates a deferred resource (SolidJS-style) */ declare function createDeferred(): [ResourceAccessor, (value: T) => void, (error: string) => void]; /** * Debounces a signal (returns SolidJS-style signal) */ declare function debounced(signal: Signal, delayMs: number): Signal; /** * Replaces `container`'s content with `node`. * * `node` is either an already-built node or a thunk that returns one, so both * `render(el, )` and `render(el, () => )` work. The thunk form * has to be accepted at runtime: SolidJS's `render` takes one, so it is the * shape most JSX call sites reach for, and TypeScript cannot flag the mistake * because `LunaNode` is `unknown`. * * Note the argument order — the container comes first, unlike SolidJS's * `render(code, element)`. The thunk must return a single node; wrap several * in `<>...` or `fragment([...])`. Resolving arrays here instead would pull * `fragment` into every bundle that renders, for ~440 B. */ declare function render(container: Element, node: LunaNode | (() => LunaNode)): void; /** * Appends `node` to `container`, leaving the existing content in place. * Accepts a thunk in the node position, exactly like `render`. */ declare function mount(container: Element, node: LunaNode | (() => LunaNode)): void; /** * JSX-compatible Fragment component. * Wraps children in a LunaNode fragment for use in JSX. * Also supports direct array call for backwards compatibility: Fragment([...]) */ declare function Fragment(propsOrChildren: { children?: any; } | any[]): any; /** * For component for list rendering (SolidJS-style) */ declare function For(props: ForProps): any; /** * Show component for conditional rendering (SolidJS-style) * * The children function receives an accessor (getter function), not the raw value. * This matches SolidJS behavior where you use: {(item) =>

{item()}

} */ declare function Show(props: ShowProps): any; /** * Loading component (SolidJS v2-style) * * Shows fallback during initial load, then maintains stale content during refetch. * Unlike Show, after content has been rendered once, it won't flash back to fallback * during background refetch. */ interface LoadingProps { when: Accessor | boolean; fallback?: LunaNode | (() => LunaNode); children: (() => LunaNode); } declare function Loading(props: LoadingProps): any; /** * Index component for index-based list rendering (SolidJS-style) */ declare function Index(props: IndexProps): any; /** * Provider component for Context (SolidJS-style) * Children must be a function: {() => } */ declare function Provider(props: ProviderProps): any; /** * Switch component for conditional rendering with multiple branches (SolidJS-style) * Reactively updates when conditions change. */ declare function Switch(props: SwitchProps): any; /** * Match component for use inside Switch (SolidJS-style) * * The children function receives an accessor (getter function), matching SolidJS. */ declare function Match(props: MatchProps): { __isMatch: true; when: () => boolean; condition: () => T; children: () => any; }; /** * Portal component for rendering outside the component tree (SolidJS-style) * Children may be a node or a thunk: {} and {() => } both work. */ declare function Portal(props: PortalProps): any; /** * Creates a reactive store with nested property tracking (SolidJS-style) */ declare function createStore(initialValue: T): [T, SetStoreFunction]; /** * Produce helper for immer-style mutations (SolidJS-style) * @template T * @param {(draft: T) => void} fn - Mutation function * @returns {(state: T) => T} - Function that applies mutations to a copy */ declare function produce(fn: any): (state: any) => any; /** * Reconcile helper for efficient array/object updates (SolidJS-style) * @template T * @param {T} value - New value to reconcile * @returns {(state: T) => T} - Function that returns the new value */ declare function reconcile(value: any): () => any; //#endregion export { createSignal as A, Switch as C, createMemo as D, createEffect as E, on as F, produce as I, reconcile as L, debounced as M, mergeProps as N, createRenderEffect as O, mount as P, render as R, Signal as S, createDeferred as T, ResourceAccessor as _, Fragment as a, Show as b, Loading as c, Match as d, MatchProps as f, ProviderProps as g, Provider as h, ForProps as i, createStore as j, createResource as k, LoadingProps as l, PortalProps as m, Context as n, Index as o, Portal as p, For as r, IndexProps as s, Accessor as t, LunaNode as u, SetStoreFunction as v, SwitchProps as w, ShowProps as x, Setter as y, splitProps as z };