# Template

Represents a parsed HTML template.

A `Template` instance contains the static structure of an HTML template (nodes)
and metadata about dynamic parts (interpolation points).

## Signatures

```ts
export declare class Template implements Inspectable {
    readonly _tag = "template";
    readonly nodes: ReadonlyArray<Node>;
    readonly hash: string;
    readonly parts: ReadonlyArray<readonly [
        part: PartNode | SparsePartNode,
        path: Array<number>
    ]>;
    constructor(nodes: ReadonlyArray<Node>, hash: string, parts: ReadonlyArray<readonly [
        part: PartNode | SparsePartNode,
        path: Array<number>
    ]>);
    toJSON(): {
        _tag: string;
        nodes: readonly Node[];
        hash: string;
        parts: readonly (readonly [
            part: PartNode | SparsePartNode,
            path: number[]
        ])[];
    };
    [NodeInspectSymbol](): {
        _tag: string;
        nodes: readonly Node[];
        hash: string;
        parts: readonly (readonly [
            part: PartNode | SparsePartNode,
            path: number[]
        ])[];
    };
}
```

## Why

The parsed AST is the shared contract for DOM compilation, streamed SSR, and
hydration hashes. Renderer authors can inspect every static node and dynamic
path instead of relying on hidden compiler machinery.

## Ownership and lifetime

A Template owns its arrays and scalar metadata but no DOM nodes, subscriptions,
listeners, or Scope. Render layers may cache compiled forms by literal identity.

## Constructor

Creates a parsed Template from explicit AST, hash, and part paths.

## Constructor: Why

Parser and renderer tooling can construct the complete public model directly.

## Constructor: Ownership and lifetime

The instance retains the supplied arrays and owns no renderer resource.

## Method: [[computed:[NodeInspectSymbol]]]

Supplies Effect's Node inspection protocol.

## Method: [[computed:[NodeInspectSymbol]]]: Why

Debug output uses the same public JSON structure.

## Method: [[computed:[NodeInspectSymbol]]]: Ownership and lifetime

Delegates to `toJSON` and acquires nothing.

## Property: _tag

AST discriminant used by inspectors and renderer tooling.

## Property: _tag: Why

Enables exhaustive structural inspection.

## Property: _tag: Ownership and lifetime

Immutable metadata for this parsed template.

## Property: hash

A unique hash representing the template content. Used for caching and hydration.

## Property: hash: Why

Matches compiled SSR ranges to the same authored literal during hydration.

## Property: hash: Ownership and lifetime

Immutable metadata for the Template lifetime.

## Property: nodes

The root nodes of the template.

## Property: nodes: Why

Defines the exact authored root structure shared by all renderers.

## Property: nodes: Ownership and lifetime

The Template retains this parsed array, not live DOM.

## Property: parts

A list of dynamic parts in the template.
Each part is associated with a path (array of indices) to locate the corresponding
node in the DOM tree.

## Property: parts: Why

Direct paths let compilers capture precise update targets once.

## Property: parts: Ownership and lifetime

The Template retains parsed paths; render Scopes own live part instances.

## Method: toJSON

Returns the stable inspectable representation of this AST.

## Method: toJSON: Why

Tooling can inspect compiler output without accessing private state.

## Method: toJSON: Ownership and lifetime

Returns references to immutable parsed data; no DOM is created.

## Examples

```ts
import { parse } from "@typed/template/Parser"

// Array boundaries describe interpolation positions; values are rendered later.
const template = parse(["<div>Hello ", "</div>"])

// Access template structure
console.log(template.nodes) // Array of parsed nodes
console.log(template.parts) // Array of dynamic parts
console.log(template.hash) // Unique hash for caching
```
