@estjs/template 0.0.12 → 0.0.13-beta.2

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,28 +1,13 @@
1
- import * as csstype from 'csstype';
2
1
  import { Signal as Signal$1 } from '@estjs/signal';
3
-
4
- interface Output<T> {
5
- (value: T): void;
6
- type: 'output';
7
- }
2
+ import * as csstype from 'csstype';
8
3
 
9
4
  type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
10
- type Hook$1 = 'mounted' | 'destroy';
5
+ type Hook = 'mounted' | 'destroy';
11
6
 
12
- interface NodeTrack {
13
- cleanup: () => void;
14
- isRoot?: boolean;
15
- lastNodes?: Map<string, Node | JSX.Element>;
16
- }
17
- interface NodeTrack {
18
- cleanup: () => void;
19
- isRoot?: boolean;
20
- lastNodes?: Map<string, Node | JSX.Element>;
21
- }
7
+ type Props = Record<string, any>;
22
8
 
23
9
  interface EssorNode<T extends Record<string, any> = Record<string, any>> {
24
- props: T;
25
- id?: string;
10
+ props?: T;
26
11
  template: EssorComponent | HTMLTemplateElement;
27
12
 
28
13
  get firstChild(): Node | null;
@@ -2213,35 +2198,10 @@ declare global {
2213
2198
  }
2214
2199
  }
2215
2200
 
2216
- declare class TemplateNode$1 implements JSX.Element {
2217
- template: HTMLTemplateElement;
2218
- props: Record<string, unknown>;
2219
- key?: string | undefined;
2220
- constructor(template: HTMLTemplateElement, props: Record<string, unknown>, key?: string | undefined);
2221
- treeMap: Map<number, Node>;
2222
- mounted: boolean;
2223
- nodes: Node[];
2224
- provides: Record<string, unknown>;
2225
- trackMap: Map<string, NodeTrack>;
2226
- parent: Node | null;
2227
- get firstChild(): Node | null;
2228
- get isConnected(): boolean;
2201
+ declare class LifecycleContext {
2229
2202
  addEventListener(): void;
2230
2203
  removeEventListener(): void;
2231
- mount(parent: Node, before?: Node | null): Node[];
2232
- unmount(): void;
2233
- mapNodeTree(parent: Node, tree: Node): void;
2234
- patchNodes(props: any): void;
2235
- getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2236
- inheritNode(node: TemplateNode$1): void;
2237
- patchNode(key: any, node: any, props: any, isRoot: any): void;
2238
- }
2239
-
2240
- type Hook = 'mounted' | 'destroy';
2241
- declare class Hooks {
2242
- addEventListener(): void;
2243
- removeEventListener(): void;
2244
- static ref: Hooks | null;
2204
+ static ref: LifecycleContext | null;
2245
2205
  static context: Record<symbol, Signal$1<any>>;
2246
2206
  hooks: Record<Hook, Set<() => void>>;
2247
2207
  addHook(hook: Hook, cb: () => void): void;
@@ -2249,42 +2209,139 @@ declare class Hooks {
2249
2209
  setContext<T>(context: symbol | string | number, value: T): void;
2250
2210
  initRef(): void;
2251
2211
  removeRef(): void;
2212
+ clearHooks(): void;
2252
2213
  }
2253
- declare class ComponentNode$1 extends Hooks implements JSX.Element {
2214
+
2215
+ declare class ComponentNode$1 extends LifecycleContext implements JSX.Element {
2254
2216
  template: EssorComponent;
2255
- props: Record<string, any>;
2217
+ props?: Props | undefined;
2256
2218
  key?: string | undefined;
2257
- constructor(template: EssorComponent, props: Record<string, any>, key?: string | undefined);
2258
2219
  private proxyProps;
2259
- emitter: Set<Function>;
2260
- mounted: boolean;
2261
- rootNode: TemplateNode$1 | null;
2262
- context: Record<symbol | string | number, any>;
2220
+ private emitter;
2221
+ private rootNode;
2263
2222
  private trackMap;
2223
+ constructor(template: EssorComponent, props?: Props | undefined, key?: string | undefined);
2264
2224
  get firstChild(): Node | null;
2265
2225
  get isConnected(): boolean;
2266
- inheritNode(node: ComponentNode$1): void;
2267
2226
  mount(parent: Node, before?: Node | null): Node[];
2268
2227
  unmount(): void;
2228
+ /**
2229
+ * Inherit props and state from another ComponentNode.
2230
+ * It will:
2231
+ * 1. Copy props from the node to this proxyProps.
2232
+ * 2. Copy the rootNode, trackMap and hooks from the node.
2233
+ * 3. Copy the props from the node to this.
2234
+ * 4. Patch props from the props passed in the constructor.
2235
+ * @param node The node to inherit from.
2236
+ */
2237
+ inheritNode(node: ComponentNode$1): void;
2238
+ /**
2239
+ * Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
2240
+ * Then, call the cleanup function to remove any previously registered hooks.
2241
+ * @param trackKey the key of the node track to get.
2242
+ * @returns the NodeTrack, cleaned up and ready to use.
2243
+ */
2269
2244
  private getNodeTrack;
2270
- patchProps(props: Record<string, any>): void;
2245
+ /**
2246
+ * Patch the props of this node.
2247
+ * It will:
2248
+ * 1. Iterate the props and patch it.
2249
+ * 2. If the prop is a event handler, add a event listener to the first child of the node.
2250
+ * 3. If the prop is a ref, set the first child of the node to the ref.
2251
+ * 4. If the prop is a update handler, update the prop in the node's props.
2252
+ * 5. If the prop is a normal prop, create a signal for it and then patch it.
2253
+ * @param props The props to patch.
2254
+ */
2255
+ patchProps(props: Record<string, any> | undefined): void;
2271
2256
  }
2272
2257
 
2273
- declare function h<K extends keyof HTMLElementTagNameMap>(_template: EssorComponent | HTMLTemplateElement | K | '', props: Record<string, unknown>, key?: string): JSX.Element;
2258
+ /**
2259
+ * Creates a JSX element from a given template.
2260
+ *
2261
+ * @param template - The template to render. Can be a string representing an HTML
2262
+ * element, a function representing a component, or an `HTMLTemplateElement`.
2263
+ * @param props - Properties to pass to the component or element.
2264
+ * @param key - The key of the element.
2265
+ * @returns The created JSX element.
2266
+ */
2267
+ declare function h<K extends keyof HTMLElementTagNameMap>(template: EssorComponent | HTMLTemplateElement | K | '', props?: Props, key?: string): JSX.Element;
2268
+ /**
2269
+ * Checks if the given node is an instance of `ComponentNode`.
2270
+ *
2271
+ * @param node The node to check.
2272
+ * @returns `true` if the node is an instance of `ComponentNode`, otherwise `false`.
2273
+ */
2274
2274
  declare function isComponent(node: unknown): node is ComponentNode$1;
2275
+ /**
2276
+ * Checks if the given node is a JSX element. A JSX element is either an instance
2277
+ * of `ComponentNode` or an instance of `TemplateNode`.
2278
+ *
2279
+ * @param node The node to check.
2280
+ * @returns `true` if the node is a JSX element, otherwise `false`.
2281
+ */
2275
2282
  declare function isJsxElement(node: unknown): node is EssorNode;
2276
- declare function template(html: string): HTMLTemplateElement;
2283
+ /**
2284
+ * Creates an HTML template element from a given HTML string.
2285
+ *
2286
+ * @param html The HTML string to create a template from.
2287
+ * @returns A new HTML template element.
2288
+ */
2289
+ declare function createTemplate(html: string): HTMLTemplateElement;
2290
+ /**
2291
+ * A built-in component for grouping JSX elements without adding a new node to the DOM.
2292
+ *
2293
+ * The `Fragment` component takes a single prop, `children`, which should be a JSX element.
2294
+ * It returns the `children` prop, which is the JSX element passed to it.
2295
+ *
2296
+ * It is used to group JSX elements without adding a new node to the DOM.
2297
+ *
2298
+ */
2277
2299
  declare function Fragment(props: {
2278
2300
  children: JSX.Element;
2279
2301
  }): JSX.Element;
2280
2302
 
2281
- declare function nextTick(fn?: () => void): Promise<void>;
2282
-
2303
+ /**
2304
+ * Registers a hook to be called when the component is mounted.
2305
+ *
2306
+ * @remarks
2307
+ * This function can only be called in the component function body.
2308
+ * It cannot be used in asynchronous or deferred calls.
2309
+ * @param cb - The function to call when the component is mounted.
2310
+ */
2283
2311
  declare function onMount(cb: () => void): void;
2312
+ /**
2313
+ * Registers a hook to be called when the component is about to be unmounted.
2314
+ *
2315
+ * @remarks
2316
+ * This function can only be called in the component function body.
2317
+ * It cannot be used in asynchronous or deferred calls.
2318
+ * @param cb - The function to call when the component is about to be unmounted.
2319
+ */
2284
2320
  declare function onDestroy(cb: () => void): void;
2285
2321
  interface InjectionKey<T> extends Symbol {
2286
2322
  }
2323
+ /**
2324
+ * Provides a value to be used in the component tree.
2325
+ *
2326
+ * @remarks
2327
+ * This function can only be called in the component function body.
2328
+ * It cannot be used in asynchronous or deferred calls.
2329
+ * @param key - The key to store the value in the LifecycleContext with.
2330
+ * @param value - The value to store in the LifecycleContext with the given key.
2331
+ */
2287
2332
  declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2333
+ /**
2334
+ * Injects a value from the current component LifecycleContext.
2335
+ *
2336
+ * @remarks
2337
+ * This function can only be called in the component function body.
2338
+ * It cannot be used in asynchronous or deferred calls.
2339
+ * @param key - The key to retrieve the value from the LifecycleContext with.
2340
+ * @param defaultValue - The default value to return if the key is not present
2341
+ * in the LifecycleContext.
2342
+ * @returns The value stored in the LifecycleContext with the given key, or the default
2343
+ * value if the key is not present in the LifecycleContext.
2344
+ */
2288
2345
  declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2289
2346
  /**
2290
2347
  * Creates a reactive ref that can be used to reference a DOM node
@@ -2301,39 +2358,44 @@ declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, def
2301
2358
  */
2302
2359
  declare function useRef<T>(): Signal$1<T | null>;
2303
2360
 
2304
- type Props = Record<string, any>;
2305
- declare class ServerNode extends Hooks {
2361
+ declare class SSGNode extends LifecycleContext {
2306
2362
  private template;
2307
2363
  private props;
2308
2364
  key?: string | undefined;
2309
- private childNodesMap;
2310
- private processedTemplates;
2311
- constructor(template: string[] | EssorNode | Function, props?: Props, key?: string | undefined);
2312
- /**
2313
- * Mount and render the component
2314
- */
2365
+ templates: string;
2366
+ constructor(template: string[] | SSGNode | ((props: Props) => SSGNode), props?: Props, key?: string | undefined);
2315
2367
  mount(): string;
2316
- /**
2317
- * Initialize template entries and props
2318
- */
2319
- private initTemplates;
2320
- /**
2321
- * Render component and its children into a string
2322
- */
2323
2368
  render(): string;
2324
- /**
2325
- * Render child nodes into a string
2326
- */
2327
- private renderChildren;
2328
2369
  }
2329
- type ServerNodeType = (props: Props) => ServerNode;
2370
+
2330
2371
  /**
2331
- * Create ServerNode for server-side generation (SSG)
2372
+ * Render a component to a string.
2373
+ *
2374
+ * This function renders a component to an HTML string. It is used for server-side rendering (SSR) and static site generation (SSG).
2375
+ *
2376
+ * @param component The component to render.
2377
+ * @param props Optional props to pass to the component.
2378
+ * @returns The rendered HTML string.
2332
2379
  */
2333
- declare function ssg(component: string[] | ServerNodeType, props?: Props): ServerNode;
2380
+ declare function renderToString(component: EssorComponent, props?: Record<string, unknown>): string;
2334
2381
  /**
2335
- * Render a component to string for SSR
2382
+ * Hydrate a component in a container.
2383
+ *
2384
+ * This function hydrates a component in a container element. It is used for server-side rendering (SSR) and client-side rendering (CSR).
2385
+ *
2386
+ * @param component The component to hydrate.
2387
+ * @param container The container element to hydrate in. Can be a string selector or an Element.
2388
+ */
2389
+ declare function hydrate(component: EssorComponent, container: string | Element): void;
2390
+ /**
2391
+ * Create a server-side generation (SSG) node from a component.
2392
+ *
2393
+ * If the render context is set to SSG, this function will create a new SSGNode from the component. Otherwise, it will create a new JSX element using the h function.
2394
+ *
2395
+ * @param component The component to create the SSGNode from.
2396
+ * @param props Optional props to pass to the component.
2397
+ * @returns The SSGNode or JSX element.
2336
2398
  */
2337
- declare function renderToString(component: any, props?: Props): string;
2399
+ declare function ssg(component: any, props?: Props): SSGNode | JSX.Element;
2338
2400
 
2339
- export { ComponentNode$1 as ComponentNode, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, TemplateNode$1 as TemplateNode, h, isComponent, isJsxElement, nextTick, onDestroy, onMount, renderToString, ssg, template, useInject, useProvide, useRef };
2401
+ export { Fragment, type InjectionKey, h, hydrate, isComponent, isJsxElement, onDestroy, onMount, renderToString, ssg, createTemplate as template, useInject, useProvide, useRef };
@@ -1,28 +1,13 @@
1
- import * as csstype from 'csstype';
2
1
  import { Signal as Signal$1 } from '@estjs/signal';
3
-
4
- interface Output<T> {
5
- (value: T): void;
6
- type: 'output';
7
- }
2
+ import * as csstype from 'csstype';
8
3
 
9
4
  type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
10
- type Hook$1 = 'mounted' | 'destroy';
5
+ type Hook = 'mounted' | 'destroy';
11
6
 
12
- interface NodeTrack {
13
- cleanup: () => void;
14
- isRoot?: boolean;
15
- lastNodes?: Map<string, Node | JSX.Element>;
16
- }
17
- interface NodeTrack {
18
- cleanup: () => void;
19
- isRoot?: boolean;
20
- lastNodes?: Map<string, Node | JSX.Element>;
21
- }
7
+ type Props = Record<string, any>;
22
8
 
23
9
  interface EssorNode<T extends Record<string, any> = Record<string, any>> {
24
- props: T;
25
- id?: string;
10
+ props?: T;
26
11
  template: EssorComponent | HTMLTemplateElement;
27
12
 
28
13
  get firstChild(): Node | null;
@@ -2213,35 +2198,10 @@ declare global {
2213
2198
  }
2214
2199
  }
2215
2200
 
2216
- declare class TemplateNode$1 implements JSX.Element {
2217
- template: HTMLTemplateElement;
2218
- props: Record<string, unknown>;
2219
- key?: string | undefined;
2220
- constructor(template: HTMLTemplateElement, props: Record<string, unknown>, key?: string | undefined);
2221
- treeMap: Map<number, Node>;
2222
- mounted: boolean;
2223
- nodes: Node[];
2224
- provides: Record<string, unknown>;
2225
- trackMap: Map<string, NodeTrack>;
2226
- parent: Node | null;
2227
- get firstChild(): Node | null;
2228
- get isConnected(): boolean;
2201
+ declare class LifecycleContext {
2229
2202
  addEventListener(): void;
2230
2203
  removeEventListener(): void;
2231
- mount(parent: Node, before?: Node | null): Node[];
2232
- unmount(): void;
2233
- mapNodeTree(parent: Node, tree: Node): void;
2234
- patchNodes(props: any): void;
2235
- getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2236
- inheritNode(node: TemplateNode$1): void;
2237
- patchNode(key: any, node: any, props: any, isRoot: any): void;
2238
- }
2239
-
2240
- type Hook = 'mounted' | 'destroy';
2241
- declare class Hooks {
2242
- addEventListener(): void;
2243
- removeEventListener(): void;
2244
- static ref: Hooks | null;
2204
+ static ref: LifecycleContext | null;
2245
2205
  static context: Record<symbol, Signal$1<any>>;
2246
2206
  hooks: Record<Hook, Set<() => void>>;
2247
2207
  addHook(hook: Hook, cb: () => void): void;
@@ -2249,42 +2209,139 @@ declare class Hooks {
2249
2209
  setContext<T>(context: symbol | string | number, value: T): void;
2250
2210
  initRef(): void;
2251
2211
  removeRef(): void;
2212
+ clearHooks(): void;
2252
2213
  }
2253
- declare class ComponentNode$1 extends Hooks implements JSX.Element {
2214
+
2215
+ declare class ComponentNode$1 extends LifecycleContext implements JSX.Element {
2254
2216
  template: EssorComponent;
2255
- props: Record<string, any>;
2217
+ props?: Props | undefined;
2256
2218
  key?: string | undefined;
2257
- constructor(template: EssorComponent, props: Record<string, any>, key?: string | undefined);
2258
2219
  private proxyProps;
2259
- emitter: Set<Function>;
2260
- mounted: boolean;
2261
- rootNode: TemplateNode$1 | null;
2262
- context: Record<symbol | string | number, any>;
2220
+ private emitter;
2221
+ private rootNode;
2263
2222
  private trackMap;
2223
+ constructor(template: EssorComponent, props?: Props | undefined, key?: string | undefined);
2264
2224
  get firstChild(): Node | null;
2265
2225
  get isConnected(): boolean;
2266
- inheritNode(node: ComponentNode$1): void;
2267
2226
  mount(parent: Node, before?: Node | null): Node[];
2268
2227
  unmount(): void;
2228
+ /**
2229
+ * Inherit props and state from another ComponentNode.
2230
+ * It will:
2231
+ * 1. Copy props from the node to this proxyProps.
2232
+ * 2. Copy the rootNode, trackMap and hooks from the node.
2233
+ * 3. Copy the props from the node to this.
2234
+ * 4. Patch props from the props passed in the constructor.
2235
+ * @param node The node to inherit from.
2236
+ */
2237
+ inheritNode(node: ComponentNode$1): void;
2238
+ /**
2239
+ * Get a NodeTrack from the trackMap. If the track is not in the trackMap, create a new one.
2240
+ * Then, call the cleanup function to remove any previously registered hooks.
2241
+ * @param trackKey the key of the node track to get.
2242
+ * @returns the NodeTrack, cleaned up and ready to use.
2243
+ */
2269
2244
  private getNodeTrack;
2270
- patchProps(props: Record<string, any>): void;
2245
+ /**
2246
+ * Patch the props of this node.
2247
+ * It will:
2248
+ * 1. Iterate the props and patch it.
2249
+ * 2. If the prop is a event handler, add a event listener to the first child of the node.
2250
+ * 3. If the prop is a ref, set the first child of the node to the ref.
2251
+ * 4. If the prop is a update handler, update the prop in the node's props.
2252
+ * 5. If the prop is a normal prop, create a signal for it and then patch it.
2253
+ * @param props The props to patch.
2254
+ */
2255
+ patchProps(props: Record<string, any> | undefined): void;
2271
2256
  }
2272
2257
 
2273
- declare function h<K extends keyof HTMLElementTagNameMap>(_template: EssorComponent | HTMLTemplateElement | K | '', props: Record<string, unknown>, key?: string): JSX.Element;
2258
+ /**
2259
+ * Creates a JSX element from a given template.
2260
+ *
2261
+ * @param template - The template to render. Can be a string representing an HTML
2262
+ * element, a function representing a component, or an `HTMLTemplateElement`.
2263
+ * @param props - Properties to pass to the component or element.
2264
+ * @param key - The key of the element.
2265
+ * @returns The created JSX element.
2266
+ */
2267
+ declare function h<K extends keyof HTMLElementTagNameMap>(template: EssorComponent | HTMLTemplateElement | K | '', props?: Props, key?: string): JSX.Element;
2268
+ /**
2269
+ * Checks if the given node is an instance of `ComponentNode`.
2270
+ *
2271
+ * @param node The node to check.
2272
+ * @returns `true` if the node is an instance of `ComponentNode`, otherwise `false`.
2273
+ */
2274
2274
  declare function isComponent(node: unknown): node is ComponentNode$1;
2275
+ /**
2276
+ * Checks if the given node is a JSX element. A JSX element is either an instance
2277
+ * of `ComponentNode` or an instance of `TemplateNode`.
2278
+ *
2279
+ * @param node The node to check.
2280
+ * @returns `true` if the node is a JSX element, otherwise `false`.
2281
+ */
2275
2282
  declare function isJsxElement(node: unknown): node is EssorNode;
2276
- declare function template(html: string): HTMLTemplateElement;
2283
+ /**
2284
+ * Creates an HTML template element from a given HTML string.
2285
+ *
2286
+ * @param html The HTML string to create a template from.
2287
+ * @returns A new HTML template element.
2288
+ */
2289
+ declare function createTemplate(html: string): HTMLTemplateElement;
2290
+ /**
2291
+ * A built-in component for grouping JSX elements without adding a new node to the DOM.
2292
+ *
2293
+ * The `Fragment` component takes a single prop, `children`, which should be a JSX element.
2294
+ * It returns the `children` prop, which is the JSX element passed to it.
2295
+ *
2296
+ * It is used to group JSX elements without adding a new node to the DOM.
2297
+ *
2298
+ */
2277
2299
  declare function Fragment(props: {
2278
2300
  children: JSX.Element;
2279
2301
  }): JSX.Element;
2280
2302
 
2281
- declare function nextTick(fn?: () => void): Promise<void>;
2282
-
2303
+ /**
2304
+ * Registers a hook to be called when the component is mounted.
2305
+ *
2306
+ * @remarks
2307
+ * This function can only be called in the component function body.
2308
+ * It cannot be used in asynchronous or deferred calls.
2309
+ * @param cb - The function to call when the component is mounted.
2310
+ */
2283
2311
  declare function onMount(cb: () => void): void;
2312
+ /**
2313
+ * Registers a hook to be called when the component is about to be unmounted.
2314
+ *
2315
+ * @remarks
2316
+ * This function can only be called in the component function body.
2317
+ * It cannot be used in asynchronous or deferred calls.
2318
+ * @param cb - The function to call when the component is about to be unmounted.
2319
+ */
2284
2320
  declare function onDestroy(cb: () => void): void;
2285
2321
  interface InjectionKey<T> extends Symbol {
2286
2322
  }
2323
+ /**
2324
+ * Provides a value to be used in the component tree.
2325
+ *
2326
+ * @remarks
2327
+ * This function can only be called in the component function body.
2328
+ * It cannot be used in asynchronous or deferred calls.
2329
+ * @param key - The key to store the value in the LifecycleContext with.
2330
+ * @param value - The value to store in the LifecycleContext with the given key.
2331
+ */
2287
2332
  declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2333
+ /**
2334
+ * Injects a value from the current component LifecycleContext.
2335
+ *
2336
+ * @remarks
2337
+ * This function can only be called in the component function body.
2338
+ * It cannot be used in asynchronous or deferred calls.
2339
+ * @param key - The key to retrieve the value from the LifecycleContext with.
2340
+ * @param defaultValue - The default value to return if the key is not present
2341
+ * in the LifecycleContext.
2342
+ * @returns The value stored in the LifecycleContext with the given key, or the default
2343
+ * value if the key is not present in the LifecycleContext.
2344
+ */
2288
2345
  declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2289
2346
  /**
2290
2347
  * Creates a reactive ref that can be used to reference a DOM node
@@ -2301,39 +2358,44 @@ declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, def
2301
2358
  */
2302
2359
  declare function useRef<T>(): Signal$1<T | null>;
2303
2360
 
2304
- type Props = Record<string, any>;
2305
- declare class ServerNode extends Hooks {
2361
+ declare class SSGNode extends LifecycleContext {
2306
2362
  private template;
2307
2363
  private props;
2308
2364
  key?: string | undefined;
2309
- private childNodesMap;
2310
- private processedTemplates;
2311
- constructor(template: string[] | EssorNode | Function, props?: Props, key?: string | undefined);
2312
- /**
2313
- * Mount and render the component
2314
- */
2365
+ templates: string;
2366
+ constructor(template: string[] | SSGNode | ((props: Props) => SSGNode), props?: Props, key?: string | undefined);
2315
2367
  mount(): string;
2316
- /**
2317
- * Initialize template entries and props
2318
- */
2319
- private initTemplates;
2320
- /**
2321
- * Render component and its children into a string
2322
- */
2323
2368
  render(): string;
2324
- /**
2325
- * Render child nodes into a string
2326
- */
2327
- private renderChildren;
2328
2369
  }
2329
- type ServerNodeType = (props: Props) => ServerNode;
2370
+
2330
2371
  /**
2331
- * Create ServerNode for server-side generation (SSG)
2372
+ * Render a component to a string.
2373
+ *
2374
+ * This function renders a component to an HTML string. It is used for server-side rendering (SSR) and static site generation (SSG).
2375
+ *
2376
+ * @param component The component to render.
2377
+ * @param props Optional props to pass to the component.
2378
+ * @returns The rendered HTML string.
2332
2379
  */
2333
- declare function ssg(component: string[] | ServerNodeType, props?: Props): ServerNode;
2380
+ declare function renderToString(component: EssorComponent, props?: Record<string, unknown>): string;
2334
2381
  /**
2335
- * Render a component to string for SSR
2382
+ * Hydrate a component in a container.
2383
+ *
2384
+ * This function hydrates a component in a container element. It is used for server-side rendering (SSR) and client-side rendering (CSR).
2385
+ *
2386
+ * @param component The component to hydrate.
2387
+ * @param container The container element to hydrate in. Can be a string selector or an Element.
2388
+ */
2389
+ declare function hydrate(component: EssorComponent, container: string | Element): void;
2390
+ /**
2391
+ * Create a server-side generation (SSG) node from a component.
2392
+ *
2393
+ * If the render context is set to SSG, this function will create a new SSGNode from the component. Otherwise, it will create a new JSX element using the h function.
2394
+ *
2395
+ * @param component The component to create the SSGNode from.
2396
+ * @param props Optional props to pass to the component.
2397
+ * @returns The SSGNode or JSX element.
2336
2398
  */
2337
- declare function renderToString(component: any, props?: Props): string;
2399
+ declare function ssg(component: any, props?: Props): SSGNode | JSX.Element;
2338
2400
 
2339
- export { ComponentNode$1 as ComponentNode, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, TemplateNode$1 as TemplateNode, h, isComponent, isJsxElement, nextTick, onDestroy, onMount, renderToString, ssg, template, useInject, useProvide, useRef };
2401
+ export { Fragment, type InjectionKey, h, hydrate, isComponent, isJsxElement, onDestroy, onMount, renderToString, ssg, createTemplate as template, useInject, useProvide, useRef };