Module / v1.0.0-beta.13

@typed/template

149 unique exports available through this public import path, including their members and aliases.

import * as template from "@typed/template";

Attribute bindings

  • AttrPartNode

    class

    Represents a dynamic attribute (e.g. src="${url}").

Attribute syntax

  • Attribute

    type-alias

    Represents every static or dynamic attribute-like AST node.

  • AttributeNode

    class

    Represents a static attribute (e.g. class="foo").

Boolean attributes

  • BooleanNode

    class

    Represents a boolean attribute (e.g. disabled).

  • BooleanPartNode

    class

    Represents a dynamic boolean attribute (e.g. ?disabled="${isDisabled}").

Buffered HTML

  • renderToHtmlString

    function

    Renders a stream of RenderEvents into a single HTML string.

    This is a convenience function that collects all events from renderToHtml and joins them into a single string. It is an Effect that resolves when the stream completes.

Class contributions

Comment bindings

Comment content

  • Comment

    type-alias

    Represents static, dynamic, or sparse comment content.

  • CommentNode

    class

    Represents a static comment.

Component construction

  • component

    namespace

    Type-level contracts used by the component constructor.

DOM adoption

  • attemptHydration

    function

    Locates a compatible SSR template range for an advanced render context.

DOM document selection

  • CurrentRenderDocument

    variable

    A service that provides the Document interface for rendering.

    Defaults to the global document object. This can be overridden for testing or environments where the global document is not available or desired.

DOM mounting

  • render

    variable

    Mounts any Renderable to a specific DOM element.

    This function lifts primitives, arrays, Effects, Streams, and Fx values into a render stream and keeps the target DOM element updated. It handles:

    • Mounting the initial content.
    • Updating the content as new events are emitted.
    • Hydrating the content if hydration context is provided.

DOM output inference

  • ToRendered

    type-alias

    Computes the DOM value represented by a nullable RenderEvent.

DOM serialization

  • toHtml

    function

    Converts a Rendered value to an HTML string.

DOM template interpretation

  • DomRenderTemplate

    variable

    A Layer that provides the RenderTemplate service implemented for DOM rendering.

    This layer enables templates to be rendered as actual DOM nodes. It handles:

    • Parsing templates into DOM fragments.
    • Caching parsed templates.
    • Hydrating from existing DOM (if applicable).
    • Setting up event listeners.
    • Managing fine-grained updates to DOM nodes via Fx streams.

Dataset contributions

  • DataPartNode

    class

    Represents a data attribute part (e.g. data-foo="${value}").

Default action control

Delegated event sources

  • EventSource

    interface

    An interface for managing event listeners on DOM nodes.

    It abstracts the process of adding and removing event listeners, ensuring that they are properly cleaned up when the scope is closed or the element is removed.

  • makeEventSource

    function

    Creates a new EventSource.

    The created EventSource can efficiently manage multiple event listeners, grouping them by event type and handling setup/teardown lifecycles.

Document structure

  • DocType

    class

    Represents a parsed DOCTYPE declaration.

Dynamic HTML chunks

  • HtmlPartChunk

    interface

    A chunk representing a dynamic part (interpolation).

Dynamic child positions

  • NodePart

    class

    Represents a dynamic insertion point within the node structure (e.g. <div>${content}</div>).

Dynamic positions

  • PartNode

    type-alias

    Represents a single dynamic interpolation part in the template AST.

Element references

  • RefPartNode

    class

    Represents a reference capture (e.g. ref="${ref}").

Element structure

  • ElementNode

    class

    Represents an HTML, SVG, MathML, or foreign-content element with children.

  • ParentNode

    type-alias

    Represents an AST node that can structurally contain template children.

  • SelfClosingElementNode

    class

    Represents a self-closing HTML element (e.g. <br />, <img />).

Event handler creation

Event handler protocol

Event handlers

  • EventHandler.EventHandler

    interface · Re-export

    Represents a DOM event handler that returns an Effect.

    It encapsulates the event handler logic and any options (like preventDefault, once, etc.) that should be applied when the event is triggered.

Existing range boundaries

  • fromComments

    variable

    Creates a published advanced Wire from a fragment and exact boundary comments.

Frame scheduling

  • RequestAnimationFrameRenderQueue

    class

    A RenderQueue that schedules tasks using requestAnimationFrame. Good for visual updates that should happen before the next repaint.

Generator overloads

  • component.Gen

    type-alias

    The overloaded callable type of component.

HTML chunk assembly

  • HtmlChunksBuilder

    class

    Advanced mutable builder used by the published template-to-chunk compiler.

HTML chunk protocol

  • HtmlChunk

    type-alias

    Represents a piece of a pre-compiled HTML template.

    Chunks allow the renderer to stream static parts of the HTML immediately while waiting for dynamic parts to be resolved.

HTML compilation

  • templateToHtmlChunks

    function

    Converts a parsed Template into a sequence of HtmlChunks. This optimization pre-calculates the static HTML strings to minimize work at render time.

HTML rendering policy

  • StaticRendering

    variable

    A boolean service that indicates whether the current rendering context is static.

    If true, the HTML renderer will optimize for static output, potentially skipping dynamic placeholder generation or other interactive features not needed for static HTML.

HTML transport recognition

HTML transport trust

Handler failure recovery

Handler failures

  • EventHandler.Error

    type-alias · Re-export

    Extracts the typed error channel of an EventHandler.

Handler normalization

  • EventHandler.fromEffectOrEventHandler

    function · Re-export

    Helper to ensure a value is an EventHandler.

    If the input is already an EventHandler, it is returned as is. If it is an Effect, it is wrapped in an EventHandler that ignores the event argument.

Handler requirements

Handler service provision

  • EventHandler.provide

    variable · Re-export

    Provides services to the EventHandler.

    This allows you to inject dependencies into the effect returned by the event handler.

Hydratable HTML rendering

  • HtmlRenderTemplate

    variable

    A Layer that provides the RenderTemplate service implemented for HTML string generation.

    Using this layer enables templates to be rendered as HTML strings (e.g., for SSR) rather than DOM nodes. It sets the RefSubject.CurrentComputedBehavior to "one", indicating a single-pass render approach typical for HTML generation.

Hydration context

  • HydrateContext

    type-alias

    Advanced renderer state describing the current hydration range.

  • makeHydrateContext

    variable

    Creates a hydration context starting from a root element.

    This context allows the renderer to “attach” to existing DOM nodes (SSR output) instead of creating new ones.

Hydration markers

  • addTemplateHash

    function

    Wraps the HTML chunks with comments containing the template hash. This is crucial for hydration to identify which template rendered a section of HTML.

Idle scheduling

Immediate scheduling

  • SyncRenderQueue

    class

    A RenderQueue that executes tasks synchronously and immediately.

Keyed collection protocol

  • ManyTypeId

    variable

    Identifies a keyed collection descriptor without starting its source.

  • isMany

    function

    Recognizes a descriptor before a target chooses its keyed rendering path. This guard does not subscribe to the collection or validate its current keys; key uniqueness is checked when the target receives an array.

Keyed collection rendering

  • Many

    interface

    A collection source, stable key function, and per-item view supplied to a renderer. Describing the collection acquires nothing; the active target owns subscription and child lifetimes.

    The DOM target retains each key’s subject and scope across moves. The HTML target consumes an initial collection for finite response output. Construct descriptors with many rather than assembling this protocol by hand.

  • many

    function

    Efficiently renders a reactive list of items by using keys to minimize DOM operations and maintain component state.

    many returns a renderer descriptor rather than an Fx. The active renderer consumes its source directly and can therefore retain keyed entries without flattening each child back through a generic collection stream.

Keyed hydration markers

  • MANY_HOLE

    variable

    Produces the closing hydration marker for a keyed-list item.

Listener lifetime

Mixed scheduling

  • MixedRenderQueue

    class

    A composite RenderQueue that directs tasks to different queues based on their priority.

    • High priority: Sync
    • Medium priority: RAF (or setTimeout fallback)
    • Low priority: IdleCallback (or setTimeout fallback)

Native DOM output

Native DOM recognition

Native element recognition

  • isElement

    function

    Checks if a rendered node is an Element.

  • isHtmlElement

    function

    Checks if a rendered node is an HTMLElement.

  • isSvgElement

    function

    Checks if a rendered node is an SVGElement.

Native event bindings

  • EventPartNode

    class

    Represents an event listener part (e.g. @click="${handler}").

Native event control

Native event types

  • EventHandler.EventOf

    type-alias · Re-export

    Extracts the native event type accepted by an EventHandler.

Native listener policy

  • EventHandler.EventOptions

    type-alias · Re-export

    Options for applying native event behavior before an Effect handler runs.

  • EventHandler.passive

    function · Re-export

    Modifies an EventHandler to be passive (improves scrolling performance).

Native node recognition

  • isAttr

    function

    Checks if a rendered node is an Attr node.

  • isComment

    function

    Checks if a rendered node is a Comment node.

  • isDocumentFragment

    function

    Checks if a rendered node is a DocumentFragment.

  • isNode

    function

    Checks if a rendered node is a standard DOM Node.

  • isText

    function

    Checks if a rendered node is a Text node.

Native output shapes

  • Rendered

    type-alias

    A union type representing all possible rendered values. Can be a single Node, a DocumentFragment, a Wire, or an array of these.

  • Rendered.Elements

    type-alias

    Extract the elements from a Rendered type

  • Rendered.Value

    type-alias

    Single rendered value type.

  • Rendered.Values

    type-alias

    Extract the values from a Rendered type

Output collection recognition

  • isArray

    function

    Checks if a rendered value is an array of nodes.

Persistent DOM ranges

  • Wire

    interface

    Wire is a data type that serves as a persistent, reusable DocumentFragment.

    Unlike a standard DocumentFragment, which empties itself when appended to the DOM, a Wire retains references to its child nodes. This allows it to be moved around the DOM or updated without losing track of its content.

    It is used internally to manage the lifecycle of template instances.

  • persistent

    variable

    Creates a Wire from a DocumentFragment.

    If the fragment has only one child, that child is returned directly. If it has multiple children, they are wrapped in a Wire structure (bounded by comments) to allow them to be treated as a single unit.

Propagation control

Property bindings

Range recognition

  • isWire

    function

    Checks if a rendered node is a Wire.

Range reconciliation

  • diffable

    variable

    Creates the advanced node adapter used by local DOM reconciliation.

Range traversal

  • getAllSiblingsBetween

    function

    Gets all sibling nodes between exact range boundaries, excluding both markers.

Render priorities

Render scheduling

  • CurrentRenderPriority

    variable

    A service that provides the default priority for rendering tasks.

    The default value is RenderPriority.Raf(10), which typically schedules updates to occur before the next repaint.

  • CurrentRenderQueue

    variable

    A service that manages the queue of DOM updates.

    It ensures that DOM updates are batched and executed efficiently, often coordinating with browser painting cycles (e.g., via requestAnimationFrame).

Renderable failures

  • Renderable.Error

    type-alias

    Extracts the error type from a Renderable type.

  • Renderable.ErrorFromObject

    type-alias

    Traverse all keys in an object and extract the error from each value. If the value is a function, extract the error from the return type of the function.

Renderable inputs

  • Renderable

    type-alias

    Represents any value that can be rendered into a template.

    This includes:

    • Primitives (string, number, boolean, null, undefined)
    • Arrays of Renderables
    • Effects that produce a Renderable
    • Streams (Fx or Stream) that emit Renderables
    • Objects (typically for setting properties or attributes)
  • Renderable.Any

    type-alias

    A type alias for any Renderable value with any error/context.

Renderable normalization

  • liftRenderableToFx

    function

    Converts any Renderable into an Fx while preserving its nested errors and service requirements.

Renderable output inference

  • Renderable.Success

    type-alias

    Recursively computes the terminal value emitted by a Renderable.

Renderable producers

  • Renderable.Effects

    type-alias

    The Effect ecosystem producers recognized as reactive Renderables.

Renderable requirements

  • Renderable.Services

    type-alias

    Extracts the required services from a Renderable type.

  • Renderable.ServicesFromObject

    type-alias

    Traverse all keys in an object and extract the services from each value. If the value is a function, extract the services from the return type of the function.

Rendered element traversal

  • getElements

    function

    Extracts all Elements from a Rendered value.

Renderer output protocol

  • RenderEvent

    type-alias

    Represents the result of a rendering operation. Can be either a DOM-based event (containing actual Nodes) or an HTML-based event (containing strings).

  • RenderEventTypeId

    variable

    The global discriminant key shared by DOM and HTML render events.

Renderer output recognition

Root event propagation

  • CurrentRootEvents

    variable

    Default event propagation policy for integration roots. Defaults to false. Override through Effect services; no global browser listeners are installed.

  • RootEventOptions

    type-alias

    Selects native event names whose bubbling stops at an integration root. false disables every boundary listener. Within a record, true stops that event and false allows it, overriding an inherited setting for that name.

  • RootEvents.CurrentRootEvents

    variable · Re-export

    Default event propagation policy for integration roots. Defaults to false. Override through Effect services; no global browser listeners are installed.

  • RootEvents.RootEventOptions

    type-alias · Re-export

    Selects native event names whose bubbling stops at an integration root. false disables every boundary listener. Within a record, true stops that event and false allows it, overriding an inherited setting for that name.

  • RootEvents.rootEvents

    variable · Re-export

    Installs scoped native bubbling listeners on a root. Undefined options inherit CurrentRootEvents, records override inherited event names individually, and false disables the inherited policy entirely.

    Only stopPropagation is called. Target handlers, other listeners on this same root, and browser default actions remain available. Ancestor capture handlers have already run; events that do not bubble to the root are not intercepted. This is an event bubbling policy, not a security or complete event-isolation boundary. Each listener is removed when the calling Scope closes.

  • rootEvents

    variable

    Installs scoped native bubbling listeners on a root. Undefined options inherit CurrentRootEvents, records override inherited event names individually, and false disables the inherited policy entirely.

    Only stopPropagation is called. Target handlers, other listeners on this same root, and browser default actions remain available. Ancestor capture handlers have already run; events that do not bubble to the root are not intercepted. This is an event bubbling policy, not a security or complete event-isolation boundary. Each listener is removed when the calling Scope closes.

Scheduled render work

  • RenderQueue

    class

    An abstract base class for managing the execution of rendering tasks. It allows prioritizing updates and scheduling them using different strategies (e.g., requestAnimationFrame, requestIdleCallback, setTimeout, or synchronous execution).

Scheduling protocol

Serialized HTML output

Sparse HTML chunks

Sparse attributes

  • SparseAttrNode

    class

    Represents a sparse attribute (e.g. class="foo ${bar}").

Sparse comments

Sparse expressions

  • SparsePartNode

    type-alias

    Represents a “sparse” part, which is a text or attribute value composed of mix of static text and dynamic parts (e.g. id="prefix-${id}").

Sparse text

  • SparseTextNode

    class

    Represents sparse text content (e.g. Hello ${name}!).

Spread bindings

Spread serialization

Static HTML chunks

Static HTML rendering

  • StaticHtmlRenderTemplate

    variable

    A variant of HtmlRenderTemplate that enables static rendering optimizations.

    This layer provides the RenderTemplate service for HTML generation but also sets StaticRendering to true, enabling optimizations for static content.

Streaming HTML

  • renderToHtml

    function

    Renders a stream of RenderEvents into a stream of HTML strings.

    This function transforms the output of a template rendering process (which produces RenderEvents) into a stream of strings suitable for HTML output (e.g., for Server-Side Rendering).

Template authoring

  • html

    function

    The main template tag function.

    It creates a reactive Fx stream that renders the template. The actual rendering logic depends on the provided RenderTemplate service.

Template interpretation

  • RenderTemplate

    class

    A service that defines how templates are rendered.

    Different implementations can be provided for different environments (e.g., DomRenderTemplate for browsers, HtmlRenderTemplate for SSR).

Template parsing

  • parse

    function

    Parses a template string array (from a tagged template literal) into a reusable Template object.

    This parser handles:

    • Standard HTML structure (elements, attributes, text, comments).
    • Custom part syntax for interpolation (e.g., ${value}).
    • Special attributes like .property, @event, ?boolean.
    • Self-closing tags and text-only elements (script, style).

    Each call returns a new Template instance containing the static AST and dynamic part locations. Render targets cache their compiled DOM fragments or HTML chunks independently by template-literal identity.

Template run context

  • TemplateContext

    type-alias

    Advanced per-template DOM rendering state used by renderer extensions.

Template structure

  • Node

    type-alias

    Represents any root or child node in the renderer-neutral template AST.

  • Template

    class

    Represents a parsed HTML template.

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

Terminal renderable values

Text bindings

  • TextPartNode

    class

    Represents a dynamic text part (e.g. ${text}).

Text content

  • Text

    type-alias

    Represents static, dynamic, or sparse text content.

  • TextNode

    class

    Represents a static text node.

Text contexts

  • TextOnlyElement

    class

    Represents an element that contains only text (e.g. <script>, <style>).

Timer scheduling

Web Components

  • WebComponent.CurrentShadowRoot

    variable · Re-export

    Selects an open shadow root by default. Provide false for light DOM. The selection is captured when the registration layer or server view runs.

  • WebComponent.Definition

    interface · Re-export

    An inert definition shared by browser registration and server rendering. Schemas supply optionality and defaults. Inputs are parent-owned; local writable state can be created in an Effect returned by render.

  • WebComponent.Element

    interface · Re-export

    A registered element accepts typed input through its props property. Assign a new object to update; nested mutation is not observed.

  • WebComponent.Fields

    type-alias · Re-export

    Schema fields for attributes and dot-prefixed DOM properties. Attribute schemas encode strings; property schemas accept decoded values.

  • WebComponent.Input

    type-alias · Re-export

    Typed initial values; only schema-optional or defaulted inputs may be omitted.

  • WebComponent.Props

    type-alias · Re-export

    Decoded inputs, with the dot removed from property names.

  • WebComponent.RegistrationError

    class · Re-export

    A browser registry could not accept a definition.

  • WebComponent.RenderProps

    type-alias · Re-export

    Each field is a read-only computed value, including optional fields.

  • WebComponent.ShadowRootOptions

    type-alias · Re-export

    Shadow settings supported by both attachShadow and declarative shadow DOM.

  • WebComponent.make

    function · Re-export

    Defines a custom element without reading any browser globals. Custom-element names use a conservative ASCII subset of the HTML grammar.

  • WebComponent.register

    function · Re-export

    Registers in CurrentRenderDocument’s registry and captures the layer’s services. Provides no services; use the custom element through ordinary HTML templates. The layer’s Scope owns every connected instance. Closing it stops rendering and deactivates this class; browsers cannot unregister a custom element. Disconnect interrupts subscriptions/listeners; reconnect waits for cleanup before starting a fresh view. Failures dispatch typed:error with a Cause in CustomEvent.detail. Native template event handlers work without an adapter. Shadow roots retain slotted light children. Light mode owns all host children.

  • WebComponent.server

    function · Re-export

    Produces a server Renderable with a custom-element host and hydratable content. Shadow mode emits declarative shadow DOM followed by optional slot content. Light mode owns all host children and rejects supplied slot content. Only properties declared in the attribute schema are serialized; match CurrentShadowRoot on the client. Body and slot chunks retain their order, errors, services, and calling Scope. Use Typed’s renderToHtml to stream or renderToHtmlString to collect the result.

namespace

  • EventHandler

    namespace · Re-export

    Public namespace exposed as EventHandler from @typed/template.

  • RootEvents

    namespace · Re-export

    Public namespace exposed as RootEvents from @typed/template.

  • WebComponent

    namespace · Re-export

    Public namespace exposed as WebComponent from @typed/template.

variable

  • rootIdentity

    variable

    Allocate an island identity per execution and restore it through native hydration. Requires the caller’s Scope and RandomValues service; no entropy provider is installed here.