Skip to content
Shapemetry

Model - Styles

API reference for src/lanes/styles/styles, src/document/styles on @huukhanhnguyen/model, reachable from ..

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

clearStyleArg

function

Clear an optional arg when the author leaves it empty.

clearStyleArg(node: Operation, key: string): void

collectStyleNodes

function

Evaluate every styles[] node on the scope into resolved Style records (the ONE entry consumers should use — Model.evaluateStyles wraps this in a SnapshotLaneNode). Never throws (fail-soft per node).

collectStyleNodes(scope: ModelScope): Style[]

evaluateStyleNode

function

Evaluate one style node into a resolved Style. Null when the name cannot be resolved (skip — fail-soft).

evaluateStyleNode(node: Operation, context: EvalContext, namespaces?: Record<string, unknown>): Style | null

isStyleNode

function

True when node is a non-container operation with method "style".

isStyleNode(node: (Operation | Container)): node is Operation

setStyleArg

function

Set or replace one arg input on a style node (mutates args array).

setStyleArg(node: Operation, key: string, input: string): void

STYLE_CAPABILITIES

const

What each shading mode can show — the SSOT both the model's validation (which style fields a shading permits) and packages/three's Viewport read, instead of scattered shading === "realistic" string comparisons.

const STYLE_CAPABILITIES: Record<NonNullable<Style["shading"]>, StyleCapabilities>

STYLE_METHOD

const

Styles lane — evaluation of style nodes into resolved Style records.

Authored shape (ModelJSON.styles / ModelScope.styles): (Operation | Container)[] where each operation has method "style" and expression args for every Style field (name/background/shading/exposure). Consumers (viewStyle step name, the 3D viewport) read resolved Style records via Model.evaluateStyles().value / collectStyleNodes(scope) — by evaluated name, never re-implementing evaluation.

Expression fields resolve against the live parameter scope (same laneParameterContext as materials/layers/references) so a background/exposure formula tracking a param dirty-cascades through the SnapshotLaneNode pull.

Fail-soft per node: a broken arg falls back (omit optional fields; skip a node with no resolvable name) — a broken style never breaks the render. STYLE_CAPABILITIES gating (exposure requires shading "realistic") is enforced HERE too (defense in depth alongside validate.ts's literal-only static check) — a field that violates its shading's capability is simply dropped from the resolved record.

const STYLE_METHOD: "style"

styleArgInput

function

Arg input of a style (or any) operation node.

styleArgInput(node: Operation, key: string): string | undefined

styleLiteralName

function

Static literal name of a style node (quoted string only). Undefined when the name is an expression or missing — validation can only check literals.

styleLiteralName(node: (Operation | Container)): string | undefined

styleNodeFromRecord

function

Build a style node from a resolved Style-shaped record (migration boundary: the old inline View.display object → a styles[] node).

styleNodeFromRecord(record: Partial<Style> & { name: string; key?: string; }): Operation
Last updated: 📖 2 min readEdit on GitHub