# zerolith/internal

Import from `zerolith/internal`. Generated from the source; every signature below is what the published types declare.

## Functions

### prepared

```ts
function prepared(strings: readonly string[], markup: string, parts: readonly PreparedPart[]): TemplateStringsArray
```

Registers the scan a build tool made of a template's strings, so the
runtime binds the template without scanning it, and returns the strings
for use as the tag's first argument:
`html(prepared(strings, markup, parts), ...values)`. The prepare pass in
`@zerolith/vite` emits these calls from what `scan` produced.

Source: `packages/zerolith/src/template.ts:72`

### scan

```ts
function scan(strings: readonly string[]): Scanned
```

Scans the static strings of a template literal. Pure; usable without a DOM.

Source: `packages/zerolith/src/scan.ts:80`

### styleFile

```ts
function styleFile(path: string, rules: string): Styles
```

The styles of a stylesheet file imported with `?scoped`, as in
`import card from "./card.css?scoped"`. The dev server, the build, and
the Vite plugin turn that import into a call to this function with the
file's path in the project and its rules, which are scoped as a `css`
literal's are. The scope class holds the file's name and a hash of its
path rather than of its text, so the server and the browser agree on it
however each processed the file, and a second call for the same path,
made when the file changed in development, replaces the rules of the
stylesheet the document adopted while every element keeps its class.
A constructable stylesheet resolves references against the page, so the
tools hand over rules whose references are already URLs the page can use.

Source: `packages/zerolith/src/css.ts:143`

### devtoolsInternal

```ts
function devtoolsInternal<T>(fn: () => T): T
```

Runs `fn` with everything it creates marked as belonging to the inspector, including what the effects and owners it creates make when they run later.

Source: `packages/zerolith/src/devtools.ts:292`

### devtoolsSaveRestore

```ts
function devtoolsSaveRestore(state: Record<string, unknown>): void
```

Queues values for named state signals created from now on, each taken
once. The dev server's client writes them to sessionStorage before a
reload; the Vite plugin's runtime calls this between a module's disposal
and the re-render that follows. An empty record drops what is left.

Source: `packages/zerolith/src/devtools.ts:217`

## Interfaces

### PartSpec

```ts
interface PartSpec
```

Where and how one or more expressions bind into the template.

- `kind: number`: How the part binds: `CHILD` for content; for an attribute, `BOOLEAN`, `PROPERTY`, or `EVENT` after a `?`, `.`, or `@` prefix, `REF` for `ref`, and `ATTRIBUTE` otherwise.
- `index: number`: Position of the bound node in a tree walk of the template content.
- `name: string`: Attribute, property, or event name as written in the source.
- `strings: readonly string[]`: Static text around the expressions of an attribute value; always one longer than `count`.
- `count: number`: Number of expressions the part consumes.

Source: `packages/zerolith/src/parts.ts:18`

### Scanned

```ts
interface Scanned
```

The scanner's output: markup with markers, and the parts in source order.

- `markup: string`: The static strings as one markup string, with each bound attribute replaced by an attribute named `zl$N`, N being its index in `parts`, and each child expression by a `<!--zl$-->` comment.
- `parts: PartSpec[]`: One part per child expression and per bound attribute, in source order; `index` is -1 here, and `prepare` sets it on its own copies.

Source: `packages/zerolith/src/parts.ts:33`

### DevtoolsHook

```ts
interface DevtoolsHook
```

The object published as `globalThis.__ZEROLITH_DEVTOOLS__` in development builds.

- `readonly version: number`: The version of the hook's shape, which a tool reading the hook can check before it relies on the other members.
- `nodes(): NodeSnapshot[]`: Live reactive nodes, oldest first.
- `roots(): RootSnapshot[]`: Mounted roots.
- `diagnostics(): Diagnostic[]`: The most recent diagnostics, oldest first.
- `subscribe(listener: (event: DevtoolsEvent) => void): () => void`: Subscribes to changes; returns an unsubscribe function.

Source: `packages/zerolith/src/devtools.ts:42`

### NodeSnapshot

```ts
interface NodeSnapshot
```

What a reactive node looks like to an inspector.

- `id: number`: Unique across nodes and roots, assigned when the node is created; a `node` event names the node by this number.
- `kind: "state" | "computed" | "effect"`: `state` for a `signal`, `computed` for a `computed` value, and `effect` for an effect, including those the renderer starts for its bindings.
- `name: string | undefined`: The signal's or computed value's `name` option, or else the name of the computed's or effect's function; `undefined` when there is neither. A named state node keeps its value across an edit in development.
- `value?: unknown`: The current value for state and computed nodes; absent for effects and when reading threw.
- `observers: number`: How many nodes currently depend on this one.
- `internal: boolean`: Created while the inspector itself was rendering.

Source: `packages/zerolith/src/devtools.ts:5`

### RootSnapshot

```ts
interface RootSnapshot
```

A mounted root as the inspector sees it.

- `id: number`: Unique across roots and nodes, assigned at mount; a `root` event names the root by this number.
- `kind: "render" | "hydrate"`: The call that mounted the root: `render` or `hydrate`, the latter also when hydration found no server markup and rendered instead.
- `container: Node`: The element or fragment the root was mounted into, with a selector target already resolved to its element.
- `internal: boolean`: Mounted while the inspector itself was rendering, as its own dock is; no subscriber hears of such a root, and the Roots tab leaves it out.

Source: `packages/zerolith/src/devtools.ts:22`

## Types

### PreparedPart

```ts
type PreparedPart = readonly [number, string, readonly string[]]
```

A part as a build tool emits it: the kind, the name, and the static strings; `count` and `index` follow from them.

Source: `packages/zerolith/src/parts.ts:42`

### DevtoolsEvent

```ts
type DevtoolsEvent = { type: "node"; id: number } | { type: "root"; id: number; removed: boolean } | { type: "diagnostic"; diagnostic: Diagnostic } | { type: "flush"; effects: number }
```

Something the hook announces to subscribers.

Source: `packages/zerolith/src/devtools.ts:35`

## Constants

### SCOPE_MARKER

```ts
const SCOPE_MARKER: string
```

The class every scoped root carries, used as the lower bound of enclosing scopes.

Source: `packages/zerolith/src/css.ts:12`

### version

```ts
const version: string
```

The version of this zerolith, which the packages released with it compare with their own.

Source: `packages/zerolith/src/version.ts:1`

