Model - Layers
API reference for src/lanes/layers/layers 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.
clearLayerArg
function
Clear an optional arg when the author leaves it empty.
clearLayerArg(node: Operation, key: string): voidcollectLayers
function
Evaluate every layers[] node on the scope into resolved Layer records (the ONE entry consumers should use — Model.evaluateLayers wraps this in a SnapshotLaneNode). Never throws (fail-soft per node).
collectLayers(scope: ModelScope): Layer[]evaluateLayerNode
function
Evaluate one layer node into a resolved Layer. Null when the name cannot be resolved (skip — fail-soft).
evaluateLayerNode(node: Operation, context: EvalContext, namespaces?: Record<string, unknown>): Layer | nullisLayerNode
function
True when node is a non-container operation with method "layer".
isLayerNode(node: (Operation | Container)): node is OperationLAYER_METHOD
const
Layers lane — evaluation of layer nodes into resolved Layer records.
Authored shape (ModelJSON.layers / ModelScope.layers): (Operation | Container)[] where each operation has method "layer" and expression args for name / color / lineWidth / lineStyle. Consumers (applyLayer, views, SVG/DXF, references) still read resolved {name, color?, lineWidth?, lineStyle?} via Model.evaluateLayers().value / collectLayers(scope) — by evaluated name, never re-implementing evaluation.
Expression fields resolve against the live parameter scope (same laneParameterContext as references) so a color/lineWidth 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 layer never breaks the render.
const LAYER_METHOD: "layer"layerArgInput
function
Arg input of a layer (or any) operation node.
layerArgInput(node: Operation, key: string): string | undefinedlayerLiteralName
function
Static literal name of a layer node (quoted string only). Undefined when the name is an expression or missing — validation can only check literals.
layerLiteralName(node: (Operation | Container)): string | undefinedlayerNodeFromRecord
function
Build a layer node from a plain { name, color, … } record — the import boundary, and the ergonomic way to state a layer in a fixture.
layerNodeFromRecord(record: { name: string; color?: Color | number[]; lineWidth?: number; lineStyle?: string; key?: string; }): OperationquotedLiteral
function
Quoted string literal from an expression input — validate/share only. Delegates to the shared quotedStringLiteral helper (schema hygiene).
quotedLiteral(input: string | undefined): string | undefinedquoteStringLiteral
function
quoteStringLiteral(value: string): stringsetLayerArg
function
Set or replace one arg input on a layer node (mutates args array).
setLayerArg(node: Operation, key: string, input: string): void