Skip to content

SVG

An optional Python authoring plugin for inspecting vector artwork and turning its parts into ordinary animation entities. It uses the existing Video2D properties and renderer; it does not add a second rendering system.

Select the package and draw an asset

Add "SVG": "2.0.2" alongside a compatible Video2D 2.x release (DOM 1), and register an asset under the project's assets/ directory:

"assets": {"diagram": "assets/diagram.svg"}

Construct the document and instance inside the builder, where frame is the parent entity and Position is an ordinary core import:

from manifest import Position, assets
from manifest.svg import SvgDocument

def build(seq, frame):
    drawing = SvgDocument(assets['diagram'])
    diagram = drawing.instantiate(frame, Position(100, 80))
    wheel = diagram.by_id('wheel')
    # Use ordinary Move, Fade, AbsoluteTransition, etc. on wheel.

SvgInstance extends Group. Imported shapes are ordinary Path entities, and each instance is independent.

Check compatibility and normalize Illustrator class styles

SVG 2.0.1 adds a preflight report and a conservative conversion command. After changing package selection, compile a minimal scene to resolve and stage the selected packages before invoking the CLI.

python -m manifest.svg inspect --asset tennis --view compatibility
python -m manifest.svg normalize --asset tennis --output assets/tennis-inline.svg

Register the new file in project.json before using it. The original stays intact; existing output files are never overwritten. Only simple .class selectors (including comma-separated lists) and supported paint declarations are inlined. Stylesheet order and inline-style precedence are preserved. Complex selectors, !important, external stylesheets, and unsupported declarations are rejected. Definitions such as <defs> and IDs are preserved. Recheck compatibility after normalizing; this operation does not add support for gradients, clipping or text.

from manifest import assets
from manifest.svg import SvgDocument
report = SvgDocument(assets['tennis']).compatibility()
# report has compatible, diagnostics, total, next_offset

These APIs require SVG 2.0.1 or later. For a curved ball trajectory, use the core MotionPath and MoveAlong APIs.

All imported shapes become ordinary Path entities, and SVG groups retain their hierarchy. Moving, rotating, recoloring, and fading use normal props. Rotation, pivot, and visual_scale are initialized on imported entities. Imported transforms are composed into each shape's affine property, so animation offsets and pivots use viewport coordinates, not the original nested SVG coordinate system.

Inspect from Python or the agent shell

python -m manifest.svg inspect --asset diagram --view layers
python -m manifest.svg inspect --asset diagram --view elements --limit 50
python -m manifest.svg inspect --asset diagram --key n2 --offset 0 --limit 50

The command uses the selected plugin and manifest assets. It does not import main.py, edit project files, or fetch external resources. JSON output includes dimensions, element summaries, diagnostic count, up to 100 document diagnostics, and next_offset. Per-element diagnostics remain available through pagination. Default page size is 50; maximum is 100. Errors go to stderr with a nonzero exit code. Unsupported SVG content is a successful inspection with diagnostics. The asset must resolve inside the project's assets/ directory. If Python reports No module named manifest.svg, select the SVG package before running the command.

Equivalent Python calls:

drawing.inspect(view='elements', offset=0, limit=50)
drawing.layers(offset=0, limit=50)
part = drawing.by_id('wheel')
part.inspect()
parts = drawing.by_label('Wheel')
part = drawing.by_key('n2')

Summaries contain key, id, editor label, tag, parent, child_count, bounds, and diagnostics. Long IDs/labels are capped at 500 characters with truncated_fields; per-element diagnostics are capped at 100 entries, with a separate total count. Use element keys to select truncated identifiers. Bounds are [min_x, min_y, max_x, max_y] in viewport coordinates, exclude strokes/effects, and describe normalized supported geometry. Empty geometry has null bounds; diagnosed subtrees can have incomplete bounds. Curves use extrema, not control-point bounding boxes.

IDs select source elements. Duplicate IDs fail. Labels may match multiple source/expanded elements. Anonymous keys are stable for unchanged document structure; they are not persistent identifiers across arbitrary source edits. Local <use> copies get keys such as n5/n2. Instance ID lookup fails if several copies share the requested ID; use an expanded key to choose a particular copy.

Extract reusable components

part = drawing.by_id('wheel')
wheel = part.instantiate(parent, position, origin='bounds')

The default origin='canvas' preserves original viewport placement. origin='bounds' moves the supported selected geometry's top-left to the given position. Both retain ancestor styles and transforms. A component class can wrap this call; no generated Python source is necessary.

Supported subset and diagnostics

Supported: paths (including arcs), rectangles/rounded rectangles, circles, ellipses, lines, polylines, polygons, nested groups, affine transforms, root viewBox/viewport alignment, local <use> references, presentation attributes, and inline styles. Absolute length units use 96 CSS pixels per inch. Relative units, including percentages for geometry, are diagnosed. Missing viewport sizes use viewBox dimensions or 300 × 150 when no viewBox exists.

Solid paint includes CSS color names, hex, rgb(a), hsl(a), currentColor, fill/stroke opacity, fill rules, and the existing stroke options. Definitions are not drawn until referenced. display:none suppresses subtrees; inherited visibility may be overridden by children.

Unsupported: stylesheets, text, images, gradients/patterns, masks, clipping, filters, markers, SVG animation, nested SVG viewports, and unrecognized visual attributes/styles. Artwork needing viewport clipping is diagnosed using conservative stroke bounds. Group opacity and single-element fill/stroke compositing cannot be faithfully represented by the current property renderer and are diagnosed; use separate fill-opacity/stroke-opacity where appropriate. Later Fade animations follow normal Video2D opacity semantics.

Conversion is strict by default and validates before attaching entities. Unsupported content outside a selected subtree does not block it, but ancestor styles/effects still matter. For an intentionally incomplete import:

instance = drawing.instantiate(parent, position, unsupported='skip')
print(instance.diagnostics)

This skips unsupported elements and whole subtrees affected by unsupported inherited styles or effects. It never silently strips an effect and draws a misleading replacement. Embedded stylesheets affect the whole document, so partial import of such a document yields no drawable content.

Malformed XML, external references, scripts/event handlers, cycles, and hard limits are errors in either mode. Input must be UTF-8 without DTD/entity declarations. Limits: 5 MB, 10,000 source elements, depth 64, 20,000 expanded elements, 10,000 commands per shape, and 100,000 expanded path commands.

Attribution

The bundled CSS color table is from color-name 1.1.4; its MIT license is included in python/COLOR_NAMES_LICENSE. Coordinate and paint behavior follow the SVG coordinate specification and SVG painting specification.

Version 1.0.0 · Package API 1 · SVG API reference