/** * SSR Manifest Types and Hydration * * Tree-shaped structure mirroring the controller tree. * - Discriminator: 'type' in child → TC entry, otherwise → scope * - `nodeCount` present for containerless scopes (TC views, containerless CEs) * * Recording functions live in @aurelia-ls/build (cross-package awareness). * Types, type guards, and hydration utilities remain here for the client. */ import { BindingMode, type IInstruction, itPropertyBinding, itTextBinding, itInterpolation, itListenerBinding, itRefBinding, itSetProperty, itSetAttribute, itHydrateElement, itHydrateAttribute, itHydrateTemplateController, itHydrateLetElement, itIteratorBinding } from '@aurelia/template-compiler'; import { IRenderLocation } from '../dom'; import { IPlatform } from '../platform'; import type { IViewFactory } from './view'; import type { ICustomAttributeController, ISyntheticView } from './controller'; /** Root SSR manifest structure. */ export interface ISSRManifest { root: string; manifest: ISSRScope; } /** * A scope in the SSR manifest (CE scope or TC view scope). * `nodeCount` is present for containerless scopes (TC views, containerless CEs). */ export interface ISSRScope { /** CE name (absent for synthetic view scopes) */ name?: string; /** Node count for containerless scopes (absent when host element defines boundary) */ nodeCount?: number; /** Children in controller tree order */ children: ISSRScopeChild[]; } /** Either a TC entry (has `type`) or a nested scope (no `type`). */ export type ISSRScopeChild = ISSRTemplateController | ISSRScope; /** Template controller entry recording which views were rendered during SSR. */ export interface ISSRTemplateController { /** TC type: 'repeat' | 'if' | 'else' | 'with' | 'switch' | 'promise' */ type: string; /** TC-specific state (e.g., `if`: which branch; `switch`: which case) */ state?: unknown; /** Views rendered by this TC (each with `nodeCount` since TC views are containerless) */ views: ISSRScope[]; } /** Check if a scope child is a template controller entry. */ export declare function isSSRTemplateController(child: ISSRScopeChild): child is ISSRTemplateController; /** Check if a scope child is a nested scope (CE or view). */ export declare function isSSRScope(child: ISSRScopeChild): child is ISSRScope; export interface ISSRContext { /** When true, preserve `` markers in DOM for hydration. */ readonly preserveMarkers: boolean; } /** DI token for SSR context. Register with `preserveMarkers: true` on server. */ export declare const ISSRContext: import("@aurelia/kernel").InterfaceSymbol; export interface AdoptedViewResult { view: ISyntheticView; viewScope: ISSRScope; } export interface AdoptedViewsResult { views: ISyntheticView[]; viewScopes: ISSRScope[]; } /** Adopt a single view from SSR manifest. For TCs with at most one view (if, with). */ export declare function adoptSSRView(ssrScope: ISSRTemplateController, factory: IViewFactory, controller: ICustomAttributeController, location: IRenderLocation, platform: IPlatform): AdoptedViewResult | null; /** Adopt multiple views from SSR manifest. For TCs with multiple views (repeat). */ export declare function adoptSSRViews(ssrScope: ISSRTemplateController, factory: IViewFactory, controller: ICustomAttributeController, location: IRenderLocation, platform: IPlatform): AdoptedViewsResult; /** Expression ID (opaque string) */ type ExprId = string; /** Any expression AST */ type AnyBindingExpression = { $kind: string; } & Record; /** Serialized expression entry */ interface SerializedExpression { id: ExprId; ast: AnyBindingExpression; } /** Serialized definition (root or nested) */ interface SerializedDefinition { name: string; instructions: SerializedInstruction[][]; nestedTemplates: SerializedDefinition[]; targetCount: number; } /** Nested template HTML node */ interface NestedTemplateHtmlNode { html: string; nested: NestedTemplateHtmlNode[]; } /** Binding mode (numeric, matches BindingMode enum) */ type BindingModeValue = typeof BindingMode[keyof typeof BindingMode]; /** Union of all serialized instruction types (numeric type discriminants) */ type SerializedInstruction = { type: typeof itPropertyBinding; exprId: ExprId; to: string; mode: BindingModeValue; } | { type: typeof itTextBinding; exprIds: ExprId[]; parts: string[]; } | { type: typeof itInterpolation; exprIds: ExprId[]; parts: string[]; to: string; } | { type: typeof itListenerBinding; exprId: ExprId; to: string; capture: boolean; modifier?: string | null; } | { type: typeof itRefBinding; exprId: ExprId; to: string; } | { type: typeof itSetProperty; value: unknown; to: string; } | { type: typeof itSetAttribute; value: string; to: string; } | { type: typeof itHydrateElement; res: string; instructions: SerializedInstruction[]; containerless?: boolean; } | { type: typeof itHydrateAttribute; res: string; alias?: string; instructions: SerializedInstruction[]; } | { type: typeof itHydrateTemplateController; res: string; templateIndex: number; instructions: SerializedInstruction[]; } | { type: typeof itHydrateLetElement; bindings: { exprId: ExprId; to: string; }[]; toBindingContext: boolean; } | { type: typeof itIteratorBinding; exprId: ExprId; to: string; aux?: { exprId: ExprId; name: string; }[]; }; /** SSR definition in expression table format (wire format) */ export interface ISSRDefinition { /** Root template HTML with markers */ template: string; /** Expression table */ expressions: SerializedExpression[]; /** Root definition with ExprId references */ definition: SerializedDefinition; /** Nested template HTML tree */ nestedHtmlTree: NestedTemplateHtmlNode[]; } /** Hydrated definition ready for Aurelia */ export interface IHydratedDefinition { /** Root template HTML with markers */ template: string; /** Translated Aurelia instructions */ instructions: IInstruction[][]; /** Whether compilation is needed (always false for AOT) */ needsCompile: false; } /** * Hydrate an SSR definition to Aurelia's instruction format. * * Resolves ExprId references to actual ASTs and builds instruction objects. * This is the client-side counterpart to the SSR middleware's wire format. * * @param ssrDef - The SSR definition from window.__AU_DEF__ * @returns Hydrated definition ready for Aurelia.app() */ export declare function hydrateSSRDefinition(ssrDef: ISSRDefinition): IHydratedDefinition; export {}; //# sourceMappingURL=ssr.d.ts.map