@estjs/template 0.0.15-beta.13 → 0.0.15-beta.17

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,224 +1,235 @@
1
1
  import { Signal, Computed } from '@estjs/signals';
2
+ import { S as Scope } from './internal-Bz6h0aPa.js';
3
+ export { I as InjectionKey, i as inject, p as provide } from './internal-Bz6h0aPa.js';
4
+ import { normalizeClassName } from '@estjs/shared';
2
5
 
3
- /**
4
- * InjectionKey is a unique identifier for provided values.
5
- * Using Symbol ensures type safety and prevents key collisions.
6
- */
7
- interface InjectionKey<T> extends Symbol {
6
+ declare enum COMPONENT_STATE {
7
+ /** Initial state */
8
+ INITIAL = 0,
9
+ /** Mounting */
10
+ MOUNTING = 1,
11
+ /** MOUNTED */
12
+ MOUNTED = 2,
13
+ /** Updating */
14
+ UPDATING = 3,
15
+ /** Destroying */
16
+ DESTROYING = 4,
17
+ /** destroy */
18
+ DESTROYED = 5
8
19
  }
9
- /**
10
- * Provide a value in the current scope.
11
- * The value can be injected by this scope or any descendant scope.
12
- *
13
- * @param key - The injection key
14
- * @param value - The value to provide
15
- */
16
- declare function provide<T>(key: InjectionKey<T> | string | number, value: T): void;
17
- /**
18
- * Inject a value from the scope hierarchy.
19
- * Traverses up the parent chain until finding a matching key.
20
- *
21
- * @param key - The injection key
22
- * @param defaultValue - Default value if key is not found
23
- * @returns The injected value or default value
24
- */
25
- declare function inject<T>(key: InjectionKey<T> | string | number, defaultValue?: T): T;
26
-
27
- /**
28
- * Scope represents an execution context in the component tree.
29
- * It manages provides, cleanup functions, and lifecycle hooks.
30
- */
31
- interface Scope {
32
- /** Unique identifier for debugging */
33
- readonly id: number;
34
- /** Parent scope in the hierarchy */
35
- parent: Scope | null;
36
- /** Child scopes (lazy initialized) */
37
- children: Set<Scope> | null;
38
- /** Provided values (lazy initialized) */
39
- provides: Map<InjectionKey<unknown> | string | number | symbol, unknown> | null;
40
- /** Cleanup functions (lazy initialized) */
41
- cleanup: Set<() => void> | null;
42
- /** Mount lifecycle hooks (lazy initialized) */
43
- onMount: Set<() => void | Promise<void>> | null;
44
- /** Update lifecycle hooks (lazy initialized) */
45
- onUpdate: Set<() => void | Promise<void>> | null;
46
- /** Destroy lifecycle hooks (lazy initialized) */
47
- onDestroy: Set<() => void | Promise<void>> | null;
48
- /** Whether the scope has been mounted */
49
- isMounted: boolean;
50
- /** Whether the scope has been destroyed */
51
- isDestroyed: boolean;
20
+ declare enum COMPONENT_TYPE {
21
+ NORMAL = "normal",
22
+ FRAGMENT = "fragment",
23
+ PORTAL = "portal",
24
+ SUSPENSE = "suspense",
25
+ FOR = "for"
52
26
  }
53
- /**
54
- * Get the currently active scope.
55
- * @returns The active scope or null if none is active
56
- */
57
- declare function getActiveScope(): Scope | null;
58
- /**
59
- * Set the active scope (internal use).
60
- * @param scope - The scope to set as active
61
- */
62
- declare function setActiveScope(scope: Scope | null): void;
63
- /**
64
- * Create a new scope with optional parent.
65
- * If no parent is provided, uses the current active scope as parent.
66
- *
67
- * @param parent - Optional parent scope (defaults to active scope)
68
- * @returns A new scope instance
69
- */
70
- declare function createScope(parent?: Scope | null): Scope;
71
- /**
72
- * Run a function within a scope, ensuring proper cleanup.
73
- * The previous active scope is restored even if the function throws.
74
- *
75
- * @param scope - The scope to run within
76
- * @param fn - The function to execute
77
- * @returns The return value of the function
78
- */
79
- declare function runWithScope<T>(scope: Scope, fn: () => T): T;
80
- /**
81
- * Dispose a scope and all its children.
82
- * Children are disposed first (depth-first), then the scope itself.
83
- *
84
- * @param scope - The scope to dispose
85
- */
86
- declare function disposeScope(scope: Scope): void;
87
- /**
88
- * Register a cleanup function in the current scope.
89
- * The function will be called when the scope is disposed.
90
- *
91
- * @param fn - The cleanup function
92
- */
93
- declare function onCleanup(fn: () => void): void;
94
-
95
- declare const NORMAL_COMPONENT: unique symbol;
96
27
 
97
28
  type AnyNode = Node | Component<any> | Element | string | number | boolean | null | undefined | AnyNode[] | (() => AnyNode) | Signal<AnyNode> | Computed<AnyNode>;
98
29
  type ComponentProps = Record<string, unknown>;
99
30
  type ComponentFn<P = ComponentProps> = (props: P) => AnyNode;
100
31
 
101
- declare class Component<P extends ComponentProps = ComponentProps> {
102
- component: ComponentFn<P>;
32
+ declare class Component<P extends ComponentProps = {}> {
33
+ readonly component: ComponentFn<P>;
103
34
  props: P;
104
- protected renderedNodes: AnyNode[];
105
- protected scope: Scope | null;
106
- protected parentNode: Node | undefined;
35
+ readonly [COMPONENT_TYPE.NORMAL] = true;
36
+ scope: Scope | null;
37
+ state: COMPONENT_STATE;
107
38
  beforeNode: Node | undefined;
108
- private reactiveProps;
109
- private _propSnapshots;
110
- readonly key: string | undefined;
111
- protected state: number;
112
- protected parentScope: Scope | null;
113
- readonly [NORMAL_COMPONENT] = true;
114
- get isConnected(): boolean;
115
- get firstChild(): Node | undefined;
39
+ renderedNodes: Node[];
40
+ firstChild: Node | undefined;
41
+ protected parentNode: Node | undefined;
42
+ private readonly parentScope;
43
+ private readonly reactiveProps;
44
+ private rootEventCleanups;
45
+ private rootRefCleanup?;
116
46
  constructor(component: ComponentFn<P>, props?: P);
47
+ /**
48
+ * Mount the component into `parentNode` (optionally before `beforeNode`).
49
+ * If already rendered, the existing DOM is re-inserted without re-running
50
+ * the component function.
51
+ */
117
52
  mount(parentNode: Node, beforeNode?: Node): AnyNode[];
118
- update<T extends ComponentProps>(prevNode: Component<T>): Component<T>;
119
53
  /**
120
- * Update reactive props by comparing with current values
54
+ * Re-install props into the same `reactiveProps` container (preserving
55
+ * any closures already holding a reference to it) and re-apply
56
+ * refs/events against the current root element.
121
57
  */
122
- private _updateReactiveProps;
123
- private unwrapRenderResult;
124
- forceUpdate(): void;
58
+ update(props: P): void;
125
59
  /**
126
- * Get anchor node for insertion
60
+ * Tear down and re-mount the component at its current insertion point.
61
+ * No-op if the component has never been mounted.
127
62
  */
128
- private _getAnchorNode;
63
+ forceUpdate(): void;
129
64
  /**
130
- * Destroy component
65
+ * Dispose the scope, remove all rendered nodes, and clear bookkeeping.
66
+ * Idempotent: subsequent calls are no-ops.
131
67
  */
132
68
  destroy(): void;
133
- applyProps(props: P): void;
69
+ /**
70
+ * Apply props that bind to the root DOM element rather than flowing into
71
+ * the component body: `ref` (signal/function) and `onXxx` event handlers.
72
+ * The render-facing `reactiveProps` already has those keys; here we just
73
+ * wire them to the actual DOM node.
74
+ */
75
+ private syncSpecialProps;
76
+ /**
77
+ * Remove all listeners/ref bindings currently attached to the root element.
78
+ */
79
+ private releaseSpecialProps;
80
+ /**
81
+ * Bind the root ref prop and return a cleanup that restores the previous ref state.
82
+ */
83
+ private bindRootRef;
134
84
  }
135
85
  /**
136
- * check if a node is a component
137
- * @param {unknown} node - the node to check
138
- * @returns {boolean} true if the node is a component, false otherwise
86
+ * Check if a value is a Component instance.
139
87
  */
140
88
  declare function isComponent(node: unknown): node is Component;
141
89
  /**
142
- * create a component
143
- * @param {Function} componentFn - the component function
144
- * @param {ComponentProps} props - the component props
145
- * @returns {Component} the component
90
+ * Wrap a component function in a Component instance, or pass an existing
91
+ * Component instance through unchanged.
146
92
  */
147
93
  declare function createComponent<P extends ComponentProps>(componentFn: ComponentFn<P>, props?: P): Component<P>;
148
94
 
149
95
  /**
150
- * Create a template factory function from HTML string
96
+ * Create a template factory function from HTML string.
151
97
  *
152
98
  * This function creates a reusable template factory that efficiently clones
153
- * DOM nodes from the provided HTML string. The template is parsed once and
99
+ * DOM nodes from the provided HTML string. The template is parsed once.
154
100
  *
155
- * @param html - The HTML string to create template from
156
- * @returns Factory function that returns a cloned node of the template
157
- * @throws {Error} When template content is empty or invalid
158
-
101
+ * Security note: `template(html)` is a raw HTML entrypoint. The caller is
102
+ * responsible for ensuring `html` is trusted and not derived from unsanitized
103
+ * user input.
104
+ *
105
+ * @param html - The HTML string to create template from.
106
+ * @returns Factory function that returns a cloned node of the template.
107
+ * @throws {Error} When template content is empty or invalid.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const buttonTemplate = template('<button>Click me</button>');
112
+ * const button1 = buttonTemplate(); // Creates first button instance
113
+ * const button2 = buttonTemplate(); // Creates second button instance
114
+ * ```
159
115
  */
160
116
  declare function template(html: string): () => Node;
161
117
  /**
162
- * Create and mount an application with the specified component
118
+ * Create and mount an application with the specified component.
163
119
  *
164
120
  * This function initializes an application by mounting a root component
165
121
  * to a target DOM element. It handles target validation and cleanup.
166
122
  *
167
- * @param component - The root component function to mount
168
- * @param target - CSS selector string or DOM element to mount to
169
- * @returns The mount root component instance, or undefined if target not found
123
+ * @param component - The root component function to mount.
124
+ * @param target - CSS selector string or DOM element to mount to.
125
+ * @returns Object with root component and unmount function.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const App = () => template('<div>Hello World</div>')
130
+ * const app = createApp(App, '#root');
131
+ *
132
+ * // Or with DOM element
133
+ * const container = document.getElementById('app');
134
+ * const app = createApp(App, container);
135
+ * ```
170
136
  */
171
- declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P> | Component<P>, target: string | Element): Component<P> | undefined;
137
+ declare function createApp<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): {
138
+ root: Component<{}> | undefined;
139
+ unmount: () => void;
140
+ } | undefined;
141
+ declare function hydrate<P extends ComponentProps = {}>(component: ComponentFn<P>, target: string | Element): {
142
+ root: Component<{}> | undefined;
143
+ unmount: () => void;
144
+ } | undefined;
172
145
 
173
146
  type LifecycleHook = () => void | Promise<void>;
174
147
  /**
175
148
  * Register a mount lifecycle hook.
176
- * Called after the component is mounted to the DOM.
149
+ * If the scope is already mounted, the hook is executed immediately.
177
150
  *
178
- * @param hook - The hook function to execute on mount
151
+ * @param hook - The hook function to register.
152
+ * @returns {void}
179
153
  */
180
154
  declare function onMount(hook: LifecycleHook): void;
155
+ /**
156
+ * Register an update lifecycle hook.
157
+ *
158
+ * @param hook - The hook function to register.
159
+ * @returns {void}
160
+ */
161
+ declare function onUpdate(hook: LifecycleHook): void;
181
162
  /**
182
163
  * Register a destroy lifecycle hook.
183
- * Called before the component is removed from the DOM.
184
164
  *
185
- * @param hook - The hook function to execute on destroy
165
+ * @param hook - The hook function to register.
166
+ * @returns {void}
186
167
  */
187
168
  declare function onDestroy(hook: LifecycleHook): void;
169
+
188
170
  /**
189
- * Register an update lifecycle hook.
190
- * Called after the component updates.
171
+ * Modifiers supported by `bind:*` two-way bindings.
191
172
  *
192
- * @param hook - The hook function to execute on update
173
+ * - `trim` strip surrounding whitespace from string values
174
+ * - `number` coerce numeric strings to numbers (no-op on `NaN`)
175
+ * - `lazy` commit on `change` instead of `input`
193
176
  */
194
- declare function onUpdate(hook: LifecycleHook): void;
177
+ interface BindModifiers {
178
+ trim?: boolean;
179
+ number?: boolean;
180
+ lazy?: boolean;
181
+ [key: string]: boolean | undefined;
182
+ }
183
+ /**
184
+ * Synchronizes a DOM element property with a model getter and setter.
185
+ *
186
+ * @param node The element to bind. `null` is tolerated (no-op).
187
+ * @param prop Bound property: `value` / `checked` / `files` / arbitrary.
188
+ * @param getter Reactive getter or static initial value.
189
+ * @param setter Receives the new value when the user edits the DOM.
190
+ * @param modifiers Optional `BindModifiers`.
191
+ */
192
+ declare function bindElement(node: Element | null, prop: 'value' | 'checked' | 'files' | string, getter: (() => unknown) | unknown, setter: (value: unknown) => void, modifiers?: BindModifiers): void;
195
193
 
196
194
  /**
197
- * Add event listener with automatic cleanup on scope destruction
195
+ * Set up event delegation for specified event types.
196
+ *
197
+ * @param eventNames - Array of event names to delegate.
198
+ * @param document - Document to attach events to (defaults to window.document).
199
+ */
200
+ declare function delegateEvents(eventNames: string[], document?: Document): void;
201
+ /**
202
+ * Clear all delegated events from document.
198
203
  *
199
- * @param element - Element to attach listener to
200
- * @param event - Event name
201
- * @param handler - Event handler function
202
- * @param options - Event listener options
204
+ * @param document - Document to clear events from (defaults to window.document).
205
+ */
206
+ declare function clearDelegatedEvents(document?: Document): void;
207
+ /**
208
+ * Registers an event listener and scopes its cleanup when needed.
209
+ *
210
+ * @param element - The element to add the listener to.
211
+ * @param event - The event name.
212
+ * @param handler - The event handler.
213
+ * @param options - Optional event listener options.
214
+ * @returns {void}
203
215
  */
204
216
  declare function addEventListener(element: Element, event: string, handler: EventListener, options?: AddEventListenerOptions): void;
217
+
205
218
  /**
206
- * Bind an element to a setter function for two-way data binding
219
+ * Omits props from a target object using a proxy.
207
220
  *
208
- * @param node - The element to bind
209
- * @param key - The property key (unused, kept for API compatibility)
210
- * @param defaultValue - Default value (unused, kept for API compatibility)
211
- * @param setter - The setter function to call when the element's value changes
221
+ * @param target - The target object.
222
+ * @param keys - The keys to omit.
223
+ * @returns A proxy that omits specified keys.
212
224
  */
213
- declare function bindElement(node: Element, key: string, defaultValue: unknown, setter: (value: unknown) => void): void;
225
+ declare function omitProps<T extends object, K extends keyof T>(target: T, keys: K[]): Omit<T, K>;
226
+
214
227
  /**
215
228
  * Reactive node insertion with binding support
216
229
  *
217
230
  * @param parent Parent node
218
231
  * @param nodeFactory Node factory function or static node
219
232
  * @param before Reference node for insertion position
220
- * @param options Insertion options
221
- *
222
233
  * @example
223
234
  * ```typescript
224
235
  * insert(container, () => message.value, null);
@@ -226,212 +237,203 @@ declare function bindElement(node: Element, key: string, defaultValue: unknown,
226
237
  * insert(container, "Hello World", null); // Direct string support
227
238
  * ```
228
239
  */
229
- declare function insert(parent: Node, nodeFactory: AnyNode, before?: Node): AnyNode[] | undefined;
240
+ declare function insert(parent: Node, nodeFactory: AnyNode, before?: Node): Node[] | undefined;
230
241
  /**
231
- * Map nodes from template by indexes
242
+ * Returns the first child of a node.
232
243
  *
233
- * @param template - Template node to traverse
234
- * @param indexes - Array of indexes to map
235
- * @returns Array of mapped nodes
244
+ * @param node - The node to get the child from.
245
+ * @returns The first child node or null.
236
246
  */
237
- declare function mapNodes(template: Node, indexes: number[]): Node[];
238
-
239
- /**
240
- * Set up event delegation for specified event types
241
- * @param {string[]} eventNames - Array of event names to delegate
242
- * @param {Document} document - Document to attach events to (defaults to window.document)
243
- */
244
- declare function delegateEvents(eventNames: string[], document?: Document): void;
245
-
247
+ declare function child(node: Node | null): Node | null;
246
248
  /**
247
- * Create a reactive proxy that excludes specified properties
249
+ * Returns the next sibling after advancing by `step`.
248
250
  *
249
- * @param target - The original reactive object
250
- * @param keys - List of property names to exclude
251
- * @returns A reactive proxy with specified properties excluded
251
+ * @param node - The starting node.
252
+ * @param step - Number of steps to advance.
253
+ * @returns The resulting sibling node or null.
252
254
  */
253
- declare function omitProps<T extends object, K extends keyof T>(target: T, keys: K[]): Omit<T, K>;
254
-
255
+ declare function next(node: Node | null, step?: number): Node | null;
255
256
  /**
256
- * DOM manipulation utilities
257
+ * Returns the child node at the requested index.
258
+ *
259
+ * @param node - The parent node.
260
+ * @param index - The child index.
261
+ * @returns The child node at index or null.
257
262
  */
263
+ declare function nthChild(node: Node | null, index: number): Node | null;
258
264
 
259
265
  /**
260
- * Remove node from its parent
266
+ * Returns a new hydration key.
261
267
  *
262
- * @param node - Node to remove
268
+ * @returns The new hydration key as a string.
263
269
  */
264
- declare function removeNode(node: AnyNode): void;
270
+ declare function getHydrationKey(): string;
265
271
  /**
266
- * Insert child node into parent
267
- * Handles both component nodes and DOM nodes
272
+ * Resets the client-side hydration key counter.
268
273
  *
269
- * @param parent - Parent node
270
- * @param child - Child node to insert
271
- * @param before - Reference node for insertion position
274
+ * @returns {void}
272
275
  */
273
- declare function insertNode(parent: Node, child: AnyNode, before?: AnyNode): void;
276
+ declare function resetHydrationKey(): void;
274
277
  /**
275
- * Replace child node with a new node
276
- * Handles both component nodes and DOM nodes
278
+ * Returns whether the runtime is currently in the hydration first-pass.
277
279
  *
278
- * @param parent - Parent node
279
- * @param newNode - New node to insert
280
- * @param oldNode - Old node to be replaced
280
+ * @returns True while hydrating, false otherwise.
281
281
  */
282
- declare function replaceNode(parent: Node, newNode: AnyNode, oldNode: AnyNode): void;
282
+ declare function isHydrating(): boolean;
283
+ /** Pop the next call-site anchor comment, or `null` if exhausted. */
284
+ declare function consumeTeleportAnchor(): Comment | null;
285
+ /** Pop the next teleport block from `target`, returning start/end markers and inner nodes. */
286
+ declare function consumeTeleportBlock(target: Element): {
287
+ start: Comment;
288
+ end: Comment;
289
+ nodes: Node[];
290
+ } | null;
283
291
  /**
284
- * Get the first DOM node from a node or component
292
+ * Begins hydration.
285
293
  *
286
- * @param node - Node or component
287
- * @returns The first DOM node or undefined
288
- */
289
- declare function getFirstDOMNode(node: AnyNode): Node | undefined;
290
-
291
- /**
292
- * Node normalization and comparison utilities
294
+ * @param root - The root element to hydrate.
293
295
  */
294
-
296
+ declare function beginHydration(root: Element): void;
295
297
  /**
296
- * Normalize node for reconciliation
297
- * Converts primitives to text nodes
298
+ * Ends hydration.
298
299
  *
299
- * @param node - Node to normalize
300
- * @returns Normalized DOM node
300
+ * @returns {void}
301
301
  */
302
- declare function normalizeNode(node: unknown): Node;
302
+ declare function endHydration(): void;
303
303
  /**
304
- * Check if two nodes are the same (for reconciliation)
305
- * Combines key check and type check
304
+ * Returns a factory function that, when called at component render time:
305
+ * - During hydration: increments the key, looks up the pre-built registry,
306
+ * and returns the ACTUAL SSR DOM node (no cloneNode).
307
+ * - During CSR: clones the parsed template as usual.
306
308
  *
307
- * @param a - First node
308
- * @param b - Second node
309
- * @returns true if nodes are considered the same
309
+ * @param html - The HTML template string.
310
+ * @returns A factory function that returns a DOM element.
310
311
  */
311
- declare function isSameNode(a: AnyNode, b: AnyNode): boolean;
312
+ declare function getRenderedElement(html: string): () => Element;
312
313
  /**
313
- * Shallow compare two objects or arrays
314
- * Performs strict equality check on top-level properties
314
+ * Patches class while considering hydration state.
315
315
  *
316
- * @param a - First value to compare
317
- * @param b - Second value to compare
318
- * @returns true if values are shallowly equal
319
- */
320
- declare function shallowCompare(a: unknown, b: unknown): boolean;
321
-
322
- /**
323
- * Get rendered element by hydration key or create from template
324
- * @param {string} temp - the template string
325
- * @returns {Function} a function that returns the element
316
+ * @param el - The element to patch.
317
+ * @param prev - Previous class value.
318
+ * @param next - Next class value.
319
+ * @param isSVG - Whether the element is an SVG element.
326
320
  */
327
- declare function getRenderedElement(temp: string): () => Node | null;
321
+ declare function patchClassHydrate(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
328
322
  /**
329
- * Maps server-side rendered nodes during hydration
330
- * @param {HTMLElement} templateEl - The root template element
331
- * @param {number[]} idx - Array of indices to map
332
- * @returns {Node[]} Array of mapped nodes
323
+ * Patches attribute while considering hydration state.
324
+ *
325
+ * @param el - The element to patch.
326
+ * @param key - The attribute key.
327
+ * @param prev - Previous attribute value.
328
+ * @param next - Next attribute value.
333
329
  */
334
- declare function mapSSRNodes(templateEl: HTMLElement, idx: number[]): Node[];
330
+ declare function patchAttrHydrate(el: Element, key: string, prev: unknown, next: unknown): void;
335
331
  /**
336
- * Hydrate a server-rendered component
337
- * @param {ComponentFn} component - Component function to hydrate
338
- * @param {HTMLElement | string} container - Container element or selector
339
- * @returns {any} Component instance or undefined if hydration fails
332
+ * Patches style while considering hydration state.
333
+ *
334
+ * @param el - The element to patch.
335
+ * @param prev - Previous style value.
336
+ * @param next - Next style value.
340
337
  */
341
- declare function hydrate(component: ComponentFn, container: HTMLElement | string): any;
338
+ declare function patchStyleHydrate(el: HTMLElement, prev: unknown, next?: unknown): void;
342
339
 
343
340
  /**
344
- * Start hydration mode
345
- * Called when beginning client-side hydration of server-rendered content
346
- */
347
- declare function startHydration(): void;
348
- /**
349
- * End hydration mode
350
- * Called when hydration is complete
351
- */
352
- declare function endHydration(): void;
353
- /**
354
- * Check if hydration is currently active
355
- * @returns true if hydration is in progress
356
- */
357
- declare function isHydrating(): boolean;
358
- /**
359
- * Get the hydration key
360
- * @returns the hydration key string
341
+ * Applies a minimal class update to an element.
342
+ *
343
+ * Class values are normalized into a string first, then written through
344
+ * `className` or `setAttribute('class')` depending on the element type.
345
+ * Hydration stays silent and reuses the server-rendered result by default.
346
+ *
347
+ * @param el - The element to patch.
348
+ * @param prev - Previous class value.
349
+ * @param next - Next class value.
350
+ * @param isSVG - Whether the element is an SVG element.
351
+ * @returns {void}
361
352
  */
362
- declare function getHydrationKey(): string;
353
+ declare function patchClass(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
363
354
  /**
364
- * Reset the hydration key counter
355
+ * Normalizes supported class inputs into a single string.
365
356
  */
366
- declare function resetHydrationKey(): void;
357
+ declare const normalizeClass: typeof normalizeClassName;
367
358
 
368
359
  /**
369
- * Patches the class attribute of an element
370
- * Supports silent hydration (skips DOM updates during hydration phase)
360
+ * Applies a minimal style update to an element.
371
361
  *
372
- * @param el - The element to patch classes on
373
- * @param prev - Previous class value for diffing
374
- * @param next - New class value to apply
375
- * @param isSVG - Whether the element is an SVG element
376
- * @public
362
+ * Supports both string-based and object-based styles, while staying silent
363
+ * during hydration so the server-rendered DOM can be reused.
364
+ *
365
+ * @param el - The element to patch.
366
+ * @param prev - Previous style value.
367
+ * @param next - Next style value.
368
+ * @returns {void}
377
369
  */
378
- declare function patchClass(el: Element, prev: unknown, next: unknown, isSVG?: boolean): void;
370
+ declare function patchStyle(el: HTMLElement, prev: unknown, next?: unknown): void;
379
371
  /**
380
- * Normalizes different class value formats into a single string
381
- * Re-exports normalizeClassName from shared as normalizeClass for backward compatibility
372
+ * Sets a single style property.
373
+ *
374
+ * Centralizes array-value expansion, CSS variable writes, vendor-prefix
375
+ * resolution, and `!important` handling in one place.
382
376
  *
383
- * @param value - The class value to normalize
384
- * @returns A normalized class string
385
- * @public
377
+ * @param style - Target style object.
378
+ * @param name - Style property name.
379
+ * @param val - Style value.
380
+ * @private
386
381
  */
387
- declare function normalizeClass(value: unknown): string;
382
+ declare function setStyle(style: CSSStyleDeclaration, name: string, val: string | string[]): void;
388
383
 
389
384
  /**
390
- * Patches the style of an element, optimized for different style formats
391
- * Supports silent hydration (skips DOM updates during hydration phase)
385
+ * Supported value types for the attribute patch layer.
392
386
  *
393
- * @param el - The element to patch styles on
394
- * @public
387
+ * In addition to primitive values, spread objects are also accepted, so the
388
+ * type keeps `Record<string, unknown>`.
395
389
  */
396
- declare function patchStyle(el: HTMLElement, prev: unknown, next: unknown): void;
390
+ type AttrValue = string | boolean | number | null | undefined | Record<string, unknown>;
397
391
  /**
398
- * Sets an individual style property with various optimizations
392
+ * Applies a minimal attribute update to an element.
399
393
  *
400
- * @param style - The style object to modify
401
- * @param name - The style property name
402
- * @param val - The style property value
403
- * @private
394
+ * This is the most general-purpose attribute updater in the template runtime.
395
+ * It is responsible for:
396
+ * - skipping internal reserved fields;
397
+ * - expanding spread attribute objects;
398
+ * - handling boolean attributes and SVG / xlink / xmlns namespaces;
399
+ * - applying basic dangerous-URL protection;
400
+ * - refusing raw HTML sinks such as `innerHTML` / `srcdoc`;
401
+ * - staying silent during hydration to avoid overwriting SSR DOM.
402
+ *
403
+ * @param el - The element to patch.
404
+ * @param key - The attribute key.
405
+ * @param prev - Previous attribute value.
406
+ * @param next - Next attribute value.
404
407
  */
405
- declare function setStyle(style: CSSStyleDeclaration, name: string, val: string | string[]): void;
406
-
407
- type AttrValue = string | boolean | number | null | undefined | Record<string, unknown>;
408
408
  declare function patchAttr(el: Element, key: string, prev: AttrValue, next: AttrValue): void;
409
409
 
410
410
  /**
411
- * Extended event options with delegation support
412
- * @public
411
+ * Extended listener options with optional event delegation support.
413
412
  */
414
413
  interface EventOptions extends AddEventListenerOptions {
415
414
  /**
416
- * CSS selector for event delegation
417
- * When provided, the event will only trigger if the target matches this selector
415
+ * Selector used for event delegation.
416
+ *
417
+ * When provided, the handler only runs if the event target matches the selector.
418
418
  */
419
419
  delegate?: string;
420
420
  }
421
421
  /**
422
- * Event handler cleanup function
423
- * @public
422
+ * Cleanup function signature for event listeners.
424
423
  */
425
424
  type EventCleanup = () => void;
426
425
  /**
427
- * Adds an event listener to an element with optional delegation
426
+ * Adds an event listener to an element with optional simple delegation.
427
+ *
428
+ * Without `delegate`, this is a thin wrapper around native `addEventListener()`.
429
+ * When `delegate` is provided, the runtime first checks the selector match before
430
+ * dispatching the real handler to the caller.
428
431
  *
429
- * @param el - The element to attach the event to
430
- * @param event - The event name (e.g., 'click', 'input')
431
- * @param handler - The event handler function
432
- * @param options - Additional event options including delegation
433
- * @returns A cleanup function to remove the event listener
434
- * @public
432
+ * @param el - The element to add the listener to.
433
+ * @param event - The name of the event to listen for.
434
+ * @param handler - The event handler function.
435
+ * @param options - Optional event listener options.
436
+ * @returns A cleanup function that removes the listener.
435
437
  */
436
438
  declare function addEvent(el: Element, event: string, handler: EventListener, options?: EventOptions): EventCleanup;
437
439
 
@@ -439,15 +441,15 @@ interface FragmentProps extends ComponentProps {
439
441
  children?: AnyNode | AnyNode[];
440
442
  }
441
443
  /**
442
- * Fragment component - renders multiple children without wrapper elements (Client-side only)
444
+ * Fragment component - renders multiple children without wrapper elements (Client-side only).
443
445
  *
444
446
  * **Client-side behavior:**
445
- * - Returns children directly for rendering
446
- * - Hydration system matches children using hydration keys
447
- * - The template system handles array children automatically
447
+ * - Returns children directly for rendering.
448
+ * - Hydration system matches children using hydration keys.
449
+ * - The template system handles array children automatically.
448
450
  *
449
- * @param props - Component props with children
450
- * @returns Children directly without wrapper
451
+ * @param props - Component props with children.
452
+ * @returns {AnyNode} Children directly without wrapper.
451
453
  *
452
454
  * @example
453
455
  * ```tsx
@@ -473,51 +475,66 @@ interface FragmentProps extends ComponentProps {
473
475
  declare function Fragment(props?: FragmentProps): AnyNode;
474
476
  declare namespace Fragment { }
475
477
  /**
476
- * Check if a node is a Fragment component
477
- * @param node - Node to check
478
- * @returns true if node is a Fragment
478
+ * Check if a node is a Fragment component.
479
+ *
480
+ * @param node - Node to check.
481
+ * @returns {boolean} True if node is a Fragment.
479
482
  */
480
483
  declare function isFragment(node: unknown): boolean;
481
484
 
482
485
  interface PortalProps {
486
+ /** Children to render at the target location. */
483
487
  children?: AnyNode | AnyNode[];
484
- target: string | HTMLElement;
485
- key?: string;
488
+ /**
489
+ * Mount target — CSS selector string, `Element`, or reactive getter.
490
+ * When the getter result changes, the Portal re-mounts at the new target.
491
+ */
492
+ target?: string | Element | (() => string | Element | null | undefined);
493
+ /**
494
+ * When truthy, children render inline at the call site instead of being teleported.
495
+ * May be a static value or a reactive getter.
496
+ */
497
+ disabled?: boolean | (() => boolean);
486
498
  }
487
499
  /**
488
- * Portal component - renders children into a different DOM node
500
+ * Portal teleports children into a different DOM node.
501
+ *
502
+ * - `disabled=true` renders children inline at the call site.
503
+ * - Otherwise children are teleported into `target`.
504
+ * - Both `target` and `disabled` may be reactive; changes trigger re-mount.
489
505
  *
490
- * @param props - Component props with children and target
491
- * @returns Comment node as placeholder in parent tree
506
+ * @returns A placeholder comment node that marks the call site.
492
507
  *
493
508
  * @example
494
509
  * ```tsx
495
- * <Portal target="#modal-root">
510
+ * <Portal target="#modal-root" disabled={isMobile}>
496
511
  * <div>Modal content</div>
497
512
  * </Portal>
513
+ * ```
498
514
  */
499
- declare function Portal(props: PortalProps): Comment | string;
515
+ declare function Portal(props: PortalProps): Comment;
500
516
  declare namespace Portal { }
501
517
  /**
502
- * Check if a node is a Portal component
503
- * @param node - Node to check
504
- * @returns true if node is a Portal
518
+ * Check if a node is a Portal component.
519
+ *
520
+ * @param node - Node to check.
521
+ * @returns True if node is a Portal.
505
522
  */
506
523
  declare function isPortal(node: unknown): boolean;
507
524
 
508
525
  interface SuspenseProps {
509
526
  /** The content to render. Can be a Promise for async loading. */
510
- children?: AnyNode | AnyNode[] | Promise<AnyNode | AnyNode[]>;
527
+ children?: Node | Node[] | Promise<Node | Node[]>;
511
528
  /** Fallback content to display while children is loading (Promise pending). */
512
- fallback?: AnyNode;
529
+ fallback?: Node;
513
530
  /** Optional key for reconciliation. */
514
531
  key?: string;
515
532
  }
516
533
  /**
517
- * Suspense component - handles async content with a fallback UI
534
+ * Suspense component - handles async content with a fallback UI.
518
535
  *
519
- * @param props - Component props with children, fallback, and optional key
520
- * @returns Placeholder node or fallback content
536
+ * @param props - Component props with children, fallback, and optional key.
537
+ * @returns {AnyNode} Placeholder node or fallback content.
521
538
  *
522
539
  * @example
523
540
  * ```tsx
@@ -526,12 +543,13 @@ interface SuspenseProps {
526
543
  * </Suspense>
527
544
  * ```
528
545
  */
529
- declare function Suspense(props: SuspenseProps): AnyNode;
546
+ declare function Suspense(props: SuspenseProps): Node;
530
547
  declare namespace Suspense { }
531
548
  /**
532
- * Check if a node is a Suspense component
533
- * @param node - Node to check
534
- * @returns true if node is a Suspense
549
+ * Check if a node is a Suspense component.
550
+ *
551
+ * @param node - Node to check.
552
+ * @returns {boolean} True if node is a Suspense.
535
553
  */
536
554
  declare function isSuspense(node: unknown): boolean;
537
555
 
@@ -550,38 +568,102 @@ interface ResourceOptions<T> {
550
568
  initialValue?: T;
551
569
  }
552
570
  /**
553
- * Create a resource for async data fetching
554
- * Inspired by SolidJS createResource
571
+ * Create a resource for async data fetching.
572
+ * Inspired by SolidJS createResource.
573
+ *
574
+ * @param fetcher - Function that returns a Promise with the data.
575
+ * @param options - Optional configuration.
576
+ * @returns {[Resource<T>, ResourceActions<T>]} Tuple of [resource, actions].
577
+ */
578
+ declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
579
+
580
+ interface AsyncComponentOptions {
581
+ /**
582
+ * Component to render while the async component is loading.
583
+ * Only shown after `delay` ms has elapsed (prevents flash of loading state).
584
+ */
585
+ loading?: ComponentFn;
586
+ /**
587
+ * Component to render when the async component fails to load.
588
+ * Receives `{ error, retry }` as props.
589
+ */
590
+ error?: ComponentFn<{
591
+ error: Error;
592
+ retry: () => void;
593
+ }>;
594
+ /**
595
+ * Delay in ms before showing the `loading` component (default: 200).
596
+ */
597
+ delay?: number;
598
+ /**
599
+ * Timeout in ms. If loading exceeds this, the error component is shown.
600
+ */
601
+ timeout?: number;
602
+ /**
603
+ * SSR rendering strategy (default: `'blocking'`).
604
+ *
605
+ * - `'blocking'` — Pre-calls the loader at definition time. If the module
606
+ * resolves before the component body runs (e.g. pre-loaded via
607
+ * `renderToStringAsync`), the real component is inlined in the HTML.
608
+ * - `'client-only'` — Renders `null` on the server; loads only in browser.
609
+ */
610
+ ssr?: 'blocking' | 'client-only';
611
+ /**
612
+ * Called when loading fails. Useful for logging or error tracking.
613
+ */
614
+ onError?: (error: Error, retry: () => void) => void;
615
+ }
616
+ type LoaderResult<P> = {
617
+ default: ComponentFn<P>;
618
+ } | ComponentFn<P>;
619
+ /**
620
+ * Define an async (lazy-loaded) component.
555
621
  *
556
- * @param fetcher - Function that returns a Promise with the data
557
- * @param options - Optional configuration
558
- * @returns Tuple of [resource, actions]
622
+ * Compatible with client, SSR, and SSG. Integrates with `<Suspense>` via
623
+ * `SuspenseContext` when rendered inside a Suspense boundary.
559
624
  *
560
- * @example
561
- * ```typescript
562
- * const [data, { refetch, mutate }] = createResource(
563
- * () => fetch('/api/user').then(r => r.json()),
564
- * { initialValue: null }
565
- * );
566
625
  *
567
- * // Access data
568
- * console.log(data());
569
- * console.log(data.loading.value);
570
- * console.log(data.state.value);
626
+ * @param loader - The async loader function.
627
+ * @param options - Configuration options.
628
+ * @returns {ComponentFn<P>} The async component wrapper function.
571
629
  *
572
- * // Refetch data
573
- * await refetch();
630
+ * @example
631
+ * ```tsx
632
+ * // Simple
633
+ * const Chart = defineAsyncComponent(() => import('./Chart'));
634
+ *
635
+ * // With options
636
+ * const Chart = defineAsyncComponent(
637
+ * () => import('./Chart'),
638
+ * {
639
+ * loading: () => <Spinner />,
640
+ * error: ({ error, retry }) => (
641
+ * <div>
642
+ * <p>{error.message}</p>
643
+ * <button onClick={retry}>Retry</button>
644
+ * </div>
645
+ * ),
646
+ * delay: 200,
647
+ * timeout: 10_000,
648
+ * }
649
+ * );
574
650
  *
575
- * // Update data directly
576
- * mutate({ name: 'John' });
651
+ * // Works standalone or inside Suspense
652
+ * function App() {
653
+ * return (
654
+ * <Suspense fallback={<div>Loading…</div>}>
655
+ * <Chart data={data} />
656
+ * </Suspense>
657
+ * );
658
+ * }
577
659
  * ```
578
660
  */
579
- declare function createResource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
661
+ declare function defineAsyncComponent<P extends ComponentProps = ComponentProps>(loader: () => Promise<LoaderResult<P>>, options?: AsyncComponentOptions): ComponentFn<P>;
580
662
 
581
663
  interface ForProps<T> {
582
664
  each: T[] | Signal<T[]> | (() => T[]);
583
665
  children: (item: T, index: number) => AnyNode;
584
- keyFn?: (item: T) => unknown;
666
+ key?: (item: T) => unknown;
585
667
  fallback?: () => AnyNode;
586
668
  }
587
669
  /**
@@ -593,4 +675,4 @@ interface ForProps<T> {
593
675
  declare function For<T>(props: ForProps<T>): Node;
594
676
  declare namespace For { }
595
677
 
596
- export { Component, type ComponentFn, type ComponentProps, For, type ForProps, Fragment, type FragmentProps, type InjectionKey, Portal, type PortalProps, type Scope, Suspense, type SuspenseProps, addEvent, addEventListener, bindElement, createApp, createComponent, createResource, createScope, delegateEvents, disposeScope, endHydration, getActiveScope, getFirstDOMNode, getHydrationKey, getRenderedElement, hydrate, inject, insert, insertNode, isComponent, isFragment, isHydrating, isPortal, isSameNode, isSuspense, mapNodes, mapSSRNodes, normalizeClass, normalizeNode, omitProps, onCleanup, onDestroy, onMount, onUpdate, patchAttr, patchClass, patchStyle, provide, removeNode, replaceNode, resetHydrationKey, runWithScope, setActiveScope, setStyle, shallowCompare, startHydration, template };
678
+ export { type AsyncComponentOptions, Component, type ComponentFn, type ComponentProps, For, Fragment, Portal, Suspense, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, resetHydrationKey, setStyle, template };