Compiling

What runs before a reader sees anything: an attribute refined from the text it was written as, the semantic pass over the result, the manifest a plugin declares, and the service that compiles a document.

@internote/canvas-sdk@internote/canvas-sdk/compile30 exports

#Functions

attrString
packages/canvas-sdk/src/semantic/canvas-pass.ts:638
An attribute's value as a trimmed string, or null when it is absent, empty or not a string (a binding, a refined value, a keyframe track).
(node: ChalkElement, identifier: string): string | null
buildCanvasElement
packages/canvas-sdk/src/refine/authored-elements.ts:84
Build a graph element from values a READER supplied — the editing path for editable: graphs, where there is no compiler in the loop.
(
    identifier: string,
    values: Record<string, string>,
    instanceId: string,
): BuiltElementOk | BuiltElementError

Values arrive per attribute ({ x: '2', y: '3' }), as the controls in a footer produce them. This does what the compiler would have done with them: resolves aliases, fills declared defaults, and refines every value through its declared type. The product is indistinguishable from an authored element downstream, which is the point — the surface renders one code path, not two.

!cue.to chains are refused: a keyframe anchors to the narrative's steps, and the reader is not writing the narrative.

childElements
packages/canvas-sdk/src/semantic/canvas-pass.ts:569
The element children of a compiled section, skipping text runs and typed-body values.
(content: unknown): ChalkElement[]
colourValue
packages/canvas-sdk/src/refine/value-refiners.ts:526
Refines a colour attribute value, storing it in its canonical spelling or refusing it with a message listing the colours allowed.
(input: string): RefineResult
findAttr
packages/canvas-sdk/src/semantic/canvas-pass.ts:575
One of a node's attributes by its canonical identifier, or undefined where it carries none.
(node: ChalkElement, identifier: string): ChalkAttribute | undefined
formatSemanticDiagnostic
packages/canvas-sdk/src/semantic/canvas-pass.ts:98
Format a diagnostic the way the compile services format ChalkErrors.
(diagnostic: SemanticDiagnostic): string
hueValue
packages/canvas-sdk/src/refine/value-refiners.ts:536
Refines a heatmap, contour or choropleth colour: colourValue, but accepting only the plain hues and the hex(…) and rgb(…) literals.
(input: string): RefineResult
parametisedCoordinateList
packages/canvas-sdk/src/refine/value-refiners.ts:327
A run of coordinate pairs — (1, 2), (t, t^2) — each half a number or a parametised expression.
(input: string): RefineResult
referencedNodeId
packages/canvas-sdk/src/semantic/canvas-pass.ts:627
The node id a reference attribute names.
(value: unknown): string | null
referenceValue
packages/canvas-sdk/src/refine/value-refiners.ts:369
Refines a #id or #id.member reference written as text, such as #gdp.value inside a keyframe chain, into the binding object the renderer resolves.
(input: string): RefineResult
refineCanvasAttr
packages/canvas-sdk/src/refine/authored-elements.ts:30
One attribute's value, refined as its declared type — the path for a reader EDITING an element that was authored in chalk.
(identifier: string, name: string, text: string): {
    ok: true;
    value: unknown;
} | {
    ok: false;
    error: string;
}
refineInternoteDocument
packages/canvas-sdk/src/refine/refiners.ts:149
Refines a freshly compiled internote in place, re-parsing custom-typed attribute values into the shapes renderers read.
(document: ChalkDocument): RefineDocumentResult

In order: deduplicates the header's tags (more than seven is an error), refines every attribute in the body (including !cue.to keyframe chains), points bindings at pack-scoped datasets (name~n) where the name alone is unambiguous, and writes document.citations from the cite declarations. Idempotent: an already-refined document passes through unchanged. The compile service runs it before the canvas semantic pass.

runCanvasSemanticPass
packages/canvas-sdk/src/semantic/canvas-pass.ts:115
Checks a compiled, refined internote against the canvas rules the library schema cannot express.
(document: ChalkDocument): SemanticPassResult

Walks every scene, checking: unique ids and continue: targets, at most two environments per scene, cue anchors within the scene's steps, !cue.to only on animatable attributes, children within their environment's vocabulary, suspicious implicit products in expressions, and that each graph mark suits its plane and axes. Never modifies the document. The compile service fails on the first error and passes warnings through on success.

splitCoordinatePairs
packages/canvas-sdk/src/refine/value-refiners.ts:289
Splits a list of coordinates such as (1, 2), (t+1, 2t) into [x, y] text pairs, or returns an error if the brackets do not pair up.
(input: string): { pairs: Array<[string, string]>; } | { error: string; }
splitInterval
packages/canvas-sdk/src/refine/value-refiners.ts:73
Split interval notation into its two ends and whether each is included; see IntervalParts.
(input: string): IntervalParts | { error: string; }
splitTopLevelCommas
packages/canvas-sdk/src/refine/value-refiners.ts:259
The pieces between the commas that are not inside a function call's parentheses.
(input: string): string[]
validateCanvasManifest
packages/canvas-sdk/src/plugin/manifest.ts:59
Validate a manifest object; throws with a clear message on the first problem.
(m: unknown): asserts m is CanvasPluginManifest

#Classes

DotchalkCompilationService
packages/canvas-sdk/src/compile/index.ts:118
Compiles chalk source into an internote document, with the canvas environments' refinement and validation applied.
typeof DotchalkCompilationService

#Constants

NODE_ID_RE
packages/canvas-sdk/src/refine/value-refiners.ts:238
A chalk node id as the compiler canonicalises it (D22) — lowercase, dots and dashes allowed.
RegExp
NUMBER_RE
packages/canvas-sdk/src/refine/value-refiners.ts:30
A bare numeric literal — what a refiner tests before reaching for the expression parser.
RegExp
dotchalkService
packages/canvas-sdk/src/compile/index.ts:280
A shared DotchalkCompilationService; the service holds no state, so one instance serves every caller.
DotchalkCompilationService

#Interfaces

BuiltElementError
packages/canvas-sdk/src/refine/authored-elements.ts:64
Why buildCanvasElement could not build an element.
errorRequired
A message naming the element or attribute at fault.
string
okRequired
Marks failure.
false
BuiltElementOk
packages/canvas-sdk/src/refine/authored-elements.ts:57
A graph element buildCanvasElement built.
dataRequired
The element, shaped as the compiler and refiners would have left it.
ChalkElement
okRequired
Marks success.
true
CanvasPluginChalkSpec
packages/canvas-sdk/src/plugin/manifest.ts:13
The chalk a plugin adds: its environment name, attributes and vocabulary.
attributes
Environment attributes, mirrored from the definition for pre-load validation.
Record<string, CanvasAttrSpec>
environmentRequired
The environment name this plugin provides (graph → canvas.graph).
string
vocabulary
Vocabulary identifiers the type declares (spec bodies live in code).
Record<string, CanvasNodeSpec>
CanvasPluginManifest
packages/canvas-sdk/src/plugin/manifest.ts:30
Describes a canvas-environment plugin so a host can validate it before running any of its code.

The plugin's code default-exports a defineEnvironment definition, loaded by loadEnvironmentFromManifest. Registration works today; plugin distribution does not exist yet, and runtime: 'worker' is reserved for a sandboxed runtime for untrusted plugins.

author
Who wrote the plugin.
string
chalkRequired
The environment the plugin provides; its name must match the loaded definition's.
CanvasPluginChalkSpec
description
What the plugin adds, in a sentence.
string
idRequired
The plugin's unique id; named in every load error.
string
nameRequired
The plugin's human-readable name.
string
permissions
Permissions the plugin requests (e.g. 'storage:db').
string[]
runtime
How the runtime loads the plugin's code: - 'module' — dynamic import of an ES module whose default is a defineEnvironment definition (trusted/reviewed). - 'worker' — future: sandboxed Web Worker runtime (untrusted).
moduleworker
src
URL/path to the plugin entry.
string
versionRequired
The plugin's version.
string
IntervalParts
packages/canvas-sdk/src/refine/value-refiners.ts:61
An interval's two ends, and whether each one is in it.

The brackets are decoration: [a, b] and (a, b) say the same thing, and either kind may be used as long as it balances — which is the whole reason this reads markers instead of brackets. [a, b) is the notation everyone knows and the compiler will not accept it: it counts brackets before it ever reaches an attribute value, and an unmatched [ ends the document.

So each END carries its own mark, and both combinations are writable:

  • [0, 8] is 0 ≤ x ≤ 8: an end with no mark is IN the interval.
  • [0, <8] is 0 ≤ x < 8: < is up to but not including.
  • [>0, 8] is 0 < x ≤ 8: > is from but not including.
  • [>0, <8] is 0 < x < 8.
  • [=0, 8] is 0 ≤ x ≤ 8: = says "and equal to", if you want it said.

An end left empty is unbounded, which is how a one-sided interval is written — the mark on the end that IS there still applies:

  • [, =4] is x ≤ 4: everything up to and including 4.
  • [, <4] is x < 4.
  • [=-5, ] is x ≥ -5.
  • [>-5, ] is x > -5.

Splitting is done by counting depth rather than by matching, so an endpoint may be any expression: [0, exp(1)] and [>k, <2 * k] both read.

endRequired
The upper end as written, or inf where it was left empty.
string
inclusiveEndRequired
Whether the upper end is in the interval — false for < and for an unbounded end.
boolean
inclusiveStartRequired
Whether the lower end is in the interval — false for > and for an unbounded end.
boolean
startRequired
The lower end as written, or -inf where it was left empty.
string
SemanticDiagnostic
packages/canvas-sdk/src/semantic/canvas-pass.ts:72
One problem the semantic pass found.
codeRequired
Stable machine code, e.g. 'canvas/environment-cap'.
string
file
The source file the offending node was written in, from its span.
string
line
The line the offending node starts on, from its span.
number
messageRequired
The explanation shown to the author.
string
severityRequired
Whether it fails the compilation (error) or rides along with a successful one (warning).
errorwarning
SemanticPassResult
packages/canvas-sdk/src/semantic/canvas-pass.ts:86
Everything the semantic pass found, split by severity.
errorsRequired
The diagnostics that fail the compilation.
SemanticDiagnostic[]
warningsRequired
The diagnostics that do not.
SemanticDiagnostic[]

#Types

RefineDocumentResult
packages/canvas-sdk/src/refine/refiners.ts:40
The outcome of refineInternoteDocument: success, or the first refinement error as a message.
{ ok: true } | { ok: false; error: string }
CompileResult
packages/canvas-sdk/src/compile/result.ts:32
What a compile returns: the document and any warnings when ok is true, or an error message when it is false.
{
    ok: true;
    data: ChalkDocument;
    warnings?: SemanticDiagnostic[];
} | {
    ok: false;
    error: string;
    details?: ChalkError;
}

Last updated