buildCanvasElement

Builds a vocabulary element from values a reader supplied, for an environment that lets the reader add elements without a compiler in the loop.

@internote/canvas-sdkFunction
On this page
import { buildCanvasElement } from '@internote/canvas-sdk';

Values arrive per attribute, as { 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, so the surface renders one code path. Keyframe chains are refused.

#Signature

(
    identifier: string,
    values: Record<string, string>,
    instanceId: string,
): BuiltElementOk | BuiltElementError

#Parameters

identifier
The element's identifier, which must be a registered vocabulary element.
values
The attribute values as text, by name or alias.
instanceId
The instance id to give the element, unique among the reader's elements.

#Returns

The element, or the message to show the reader.

#Example

const built = buildCanvasElement('point', { x: draft.x, y: draft.y, colour: 'blue' }, `reader-${Date.now()}`);
if (built.ok) addElement(ctx, built.data);
else setError(built.error);

Declared in packages/canvas-sdk/src/refine/authored-elements.ts:117.

Last updated