Skip to content

Canvas2D public entries ​

Use the task contracts below to check inputs, ownership, errors and lifecycle. Follow Examples for complete application inputs.

EntryWorkspaceRelease configuration
@barocss/canvas2dsrc/index.tsdist/index.js and declaration
@barocss/canvas2d/documentsrc/document.tsdist/document.js and declaration

Renderer and editable scene ​

MethodResult and ownershipError boundary
createCanvas2D(canvas, options): Canvas2DRendererOwn GL resources; host owns canvas. Options include logicalSize, dpr, optional maxDeviationDevicePx and backgroundColor.Invalid size/options or unavailable WebGL2 refuse.
renderer.updateScene(value: unknown): voidAdmit copied scene; no implicit paint.Scene/assets/budget refusal retains accepted renderer data.
renderer.render(): voidPaint accepted scene using current view.Context/lifecycle refusal reaches host.
renderer.hitTest(point): Hit | nullLogical viewport point, top eligible semantic node.Current accepted scene only.
renderer.hitTestAll(point, limit=16): Hit[]Fresh topmost-first unique semantic nodes; limit 1–16.Invalid limit refuses.
createDisplayTree(contextId): DisplayTreeStable stage, constructors, snapshot, current handle lookup and semantic input routing.Bad IDs, cycles, foreign handles and budgets refuse.
createDisplayTreeFromScene(scene): DisplayTreeNew validated tree and new handles; assets stay host-owned.Unsupported old profiles refuse.
createPathBuilder(): PathBuilderChainable path commands; build() copies them.Invalid operation retains earlier commands.
createCanvas2DApplication(canvas, options): Canvas2DApplicationRenderer/tree/ticker ownership, start, stop, render, onUpdate, dispose.Foreign context ID or malformed options refuse.

Renderer also exposes asset set/get/remove, background set/get, view set, resize, viewport/world conversion, path/fill observations, capabilities and captureImageAsset. Asset removal refuses when referenced. Capture returns owned top-to-bottom straight RGBA8 pixels; it is derived output.

Asset, text and animation tools ​

The root exports decodeImageBlob, loadImageURL, createImageAssetCache, blurImageAsset, shadowImageAsset, createSpriteAtlas, packSpriteAtlas, createSpriteAnimation, createTicker, rasterizeBrowserText, rasterizeBrowserMultilineText, rasterizeBrowserWrappedText, importSVGElement, exportSceneSVG, booleanOrthogonalPolygons, parseSceneJSON, stringifySceneJSON and Canvas2DError. Each is bounded; an image/text helper is not an unrestricted design-tool pipeline.

See retained scene edits, path construction and complete examples for application use.

Copied CPU geometry ​

Intersect two convex polygons with intersectConvexPolygons(left, right): PolygonBooleanResult: copied bounded integer inputs, canonical binary64 output, empty disjoint result and explicit contact refusals. The guide states its newer local source profile; this does not repin older renderer examples.

Split an authored L/Q/C segment with public splitPathSegment: an exact cubic midpoint fixture, copied-command ownership and bounded refusals. Scene replacement and paint remain the application's responsibility.

Document entry ​

serializeCanvasDocument(acceptedScene, getAsset): Promise<string> copies referenced assets and canonical scene data. parseCanvasDocument(text): Promise<ParsedCanvasDocument> verifies and returns copied scene/assets. stageCanvasDocument(text,freshCanvas,options): Promise<StagedCanvasDocument> adds a rendered candidate. exportCanvasDocumentPNG(text,options,createCanvas): Promise<CanvasPNGExport> renders an owned candidate, returns a Blob and size metadata, and disposes its renderer.

Follow Save and reopen owned assets for a complete document lifecycle.

Versioned public data ​

The root exports Scene/Node profile types through SceneV29, paint/transform/color/view types, image asset types, display handles/events, path observations, ticker/atlas/animation/text types and image preparation options. Scene versions are independent of package and document versions. Use the complete retained-scene example for matching fields; do not combine fields from different Scene versions.

packages/barocss-canvas2d/package.json (Manifest and version; local source) · packages/barocss-canvas2d/README.md (Package task notes; local source)

Local manual snapshot. Availability is stated on each package page.