canvas_core_runtime library

Classes

CanvasAppearance
Authored appearance shared by path, text, and icon sources.
CanvasAssetRef
CanvasBlobUrlAssetRef
Browser blob URL reference.
CanvasDataUriAssetRef
Inline data URI reference.
CanvasFieldKey
Stable identity for a runtime-editable canvas field.
CanvasFieldKeyConverter
Serializes CanvasFieldKey as its stable string value.
CanvasFields
Built-in field keys for properties that exist in the base canvas_core runtime scene model.
CanvasFileAssetRef
Local file reference.
CanvasFill
Single source-of-truth fill for runtime. No backward-compat: only accepts the new {type: ...} JSON shape.
CanvasFillGradient
CanvasFillNone
CanvasFillSolid
CanvasIconData
CanvasImageAsset
Backing source and optional natural dimensions for a document image.
CanvasImageAssetResolver
Resolves logical canvas image source references for the current host.
CanvasRawAssetRef
Bare/raw source reference with no recognized syntax.
CanvasSceneDocument
CanvasSchemeAssetRef
Opaque custom-scheme reference, such as:
CanvasSourceUnderlay
Ordered paint that derives independently from the original source silhouette and is painted before the authored foreground.
CanvasStroke
Authored stroke settings, including configurations that paint no pixels.
CanvasUrlAssetRef
Network URL reference.
CanvasViewportTransform
Renderer-neutral contain-fit transform.
CircleSource
CommandPathSource
Normalized, absolute geometry in source coordinates, with no paint data.
ComputedIcon
Evaluated icon geometry and its centered, uniform viewBox fit. Commands stay in source coordinates; appearance is authored in node-local coordinates and is applied after fitting the source.
ComputedScene
Computed document/render geometry in document units; these maps are not serialized.
ContentBoundsPolicy
Generic runtime policy for content-bounds calculations.
ContentBoundsSpec
Runtime-owned spec for custom content-bounds computation.
CoreServices
DrawItem
EllipseSource
GradientStop
One color sample along a gradient line.
GroupBehaviorRef
Generic runtime-owned behavior envelope for optional group semantics.
IconResolver
Synchronous lookup into the host's selected resource session. Downloads and source normalization happen before scene evaluation.
ImageData
ImageIntrinsics
Synchronous intrinsic-image lookup used by core scene computation.
LinearGradientSpec
A linear gradient in the local coordinate space of its painted target.
Node
Runtime scene-graph node (hierarchical TRS).
NodeGeometry
NullableSize2DConverter
NullableVec2Converter
PathCmd
PathData
PathIR
Immutable compiled geometry. Paint belongs to the authored node.
PathSource
PillSource
PolylineSource
Rect2D
RectSource
RegularPolygonSource
ResolvedIcon
A filled, recolorable vector symbol in its declared source viewBox.
RoundRectSource
SceneEvaluation
An already-prepared scene and its derived geometry for painting and export.
SceneTreeOps
Size2D
2D size (width/height).
Size2DConverter
---- Size2D ----
StarSource
TextData
TextMeasurer
Synchronous text measurement used by core scene computation.
Transform2D
UnderlineSource
Vec2
2D point/vector.
Vec2Converter
---- Vec2 ----

Extensions

CanvasImageAssetPatterns on CanvasImageAsset
Adds pattern-matching-related methods to CanvasImageAsset.
CanvasSceneDocumentPatterns on CanvasSceneDocument
Adds pattern-matching-related methods to CanvasSceneDocument.
NodeEditingX on Node
Common immutable edits that preserve node identity and tree structure.
NodeFields on Node
Rect2DX on Rect2D

Constants

currentCanvasSceneFormatVersion → const int
Current persisted Canvas scene format; independent of package version.
shadowBlurExtentInSigmas → const double
Practical Gaussian-tail estimate, not a hard pixel-enclosure guarantee. Raster padding remains a separate export policy.

Functions

aabbOfTransformedRect(Rect2D r, Matrix4 m) → Rect2D
collectAllNodeIds({CanvasSceneDocument? doc, Node? root}) → Set<ElementId>
Collect all node IDs from a document or a subtree root.
collectSceneFontFamilies(CanvasSceneDocument scene, {Iterable<String> fallbackFontFamilies = const <String>[]}) → Set<String>
Collects logical font-family dependencies referenced by a scene.
computePaddedContentBounds({required CanvasSceneDocument scene, required ComputedScene computed, ContentBoundsPolicy policy = const ContentBoundsPolicy(), double paddingPx = 0}) → Rect2D?
computeScene(CanvasSceneDocument doc, CoreServices services) → ComputedScene
computeViewport({required Rect2D sourceBounds, required double targetW, required double targetH, double? minUniformScale, double? maxUniformScale}) → CanvasViewportTransform
Contains sourceBounds inside the target dimensions.
decodeCanvasScene(Map<String, Object?> json) → CanvasSceneDocument
Decodes current persisted JSON: strict wire checks, decoding, then integrity.
encodeCanvasScene(CanvasSceneDocument scene) → Map<String, Object?>
Checks runtime integrity before recursive encoding to the current format.
estimateAppearancePaintBounds({required Rect2D? sourceBounds, required bool foregroundPresent, required Iterable<CanvasSourceUnderlay> underlays}) → Rect2D?
Estimates visible paint for a text/icon appearance.
estimateSourceUnderlayPaintBounds(Rect2D sourceBounds, CanvasSourceUnderlay underlay) → Rect2D?
Returns the paint estimate produced by one underlay from the ORIGINAL source bounds.
evaluateScene(CanvasSceneDocument preparedScene, CoreServices services, {ContentBoundsSpec? contentBounds}) → SceneEvaluation
Evaluate the prepared scene using the caller's stable service bundle.
fillContributesToPaint(CanvasFill fill) → bool
Whether a foreground has any visible color. Geometry and node visibility are evaluated separately; source underlays do not depend on this result.
findById(CanvasSceneDocument doc, ElementId id) → Node?
Find a node anywhere in the tree.
findParentOf(CanvasSceneDocument doc, ElementId id) → ParentRef?
Find parent + child-index of node id. If the node is a root child, returns (parent: null, index: i).
nodesInFrontToBackOrder(List<Node> children) → List<Node>
Layer panels typically show frontmost first.
nodesInPaintOrder(List<Node> children) → List<Node>
Sibling order is paint order:
parseCanvasAssetRef(String input) → CanvasAssetRef
replaceById(CanvasSceneDocument doc, ElementId id, Node updated) → CanvasSceneDocument
Replace node id with updated anywhere in the tree.
requireCanvasSceneIntegrity(CanvasSceneDocument document) → void
Rejects invalid generic scene data before recursive processing or resource work.
rewritePostOrder(Node n, Node fn(Node), {bool skip(Node)?, bool prune(Node)?}) → Node
Post-order tree rewrite:
rewriteSceneDocument(CanvasSceneDocument doc, Node rewriteRoot(Node)) → CanvasSceneDocument
Rewrite every root subtree in a scene document and preserve identity when no root changed.
shadowContributesToPaint(ShadowEffect shadow) → bool
Invalid numeric/color values are skipped defensively by bounds/rendering. The document validator still reports invalid authored data, including for disabled effects.
sourceUnderlayContributesToPaint(CanvasSourceUnderlay underlay) → bool
strokeContributesToPaint(CanvasStroke? stroke) → bool
Whether the configured stroke can paint pixels. Invalid colors and widths are skipped defensively; validation still reports them on invisible strokes.
upgradeCanvasScene(Map<String, Object?> json, {bool legacyUnversioned = false, bool? resolveLegacyIconWasGlyph(String iconRef)?}) → Map<String, Object?>
Brings persisted scene JSON to the current Canvas scene format.
visitSceneNodes(CanvasSceneDocument doc, {bool includeHidden = false, required void visit(Node node)}) → void
Pure traversal: iterate all nodes (optionally skipping hidden subtrees).

Typedefs

CanvasAssetId = String
Document-local identifier for an entry in a scene's asset registry.
Color32 = int
32-bit ARGB color. Same layout as Flutter's Color under the hood: 0xAARRGGBB (e.g., 0xFF112233).
ContentBoundsElementSelector = ElementId? Function(CanvasSceneDocument scene)
ContentBoundsFallbackSelector = Iterable<ElementId> Function(CanvasSceneDocument scene)
ElementId = String
FontWeightNum = int
Numeric font weight (100, 200, …, 900). Common values: 400 (normal), 700 (bold).
ImagePlacement = ({Rect2D dst, Rect2D src})
ScenePreparer = CanvasSceneDocument Function(CanvasSceneDocument scene, CoreServices services)
Pure, synchronous transformation from one runtime scene to another.