/** * SSR rendering utilities. * * Server-side renders bQuery templates to HTML strings by evaluating * directive attributes against a plain data context. Uses a lightweight * DOM implementation to process templates without a browser. * * @module bquery/ssr */ import type { BindingContext } from '../view/types'; import type { RenderOptions, SSRResult } from './types'; /** * Server-side renders a bQuery template to an HTML string. * * Takes an HTML template with bQuery directives (bq-text, bq-if, bq-for, etc.) * and a data context, then evaluates the directives to produce a static HTML string. * This HTML can be sent to the client and later hydrated with `mount()` using * `{ hydrate: true }`. * * Supported directives: * - `bq-text` — Sets text content * - `bq-html` — Sets innerHTML * - `bq-if` — Conditional rendering (removes element if falsy) * - `bq-show` — Toggle visibility via `display: none` * - `bq-class` — Dynamic class binding (object or expression syntax) * - `bq-style` — Dynamic inline styles * - `bq-for` — List rendering * - `bq-bind:attr` — Dynamic attribute binding * * @param template - HTML template string with bq-* directives * @param data - Plain data object (signals will be unwrapped automatically) * @param options - Rendering options * @returns SSR result with HTML string and optional store state * * @example * ```ts * import { renderToString } from '@bquery/bquery/ssr'; * import { signal } from '@bquery/bquery/reactive'; * * const result = renderToString( * '
Hello!
Hello!