grablab.svg · declarations 001
ICON_MODES
module-attribute
ICON_MODES
INDEX_SCHEMA
module-attribute
INDEX_SCHEMA
SVG
module-attribute
SVG
XLINK
module-attribute
XLINK
build_raster_index
build_raster_index(manifest: str | Path, source_dirs: list[str | Path] = ()) -> dict
Index exported PNG variants and exact-pixel authoritative source aliases.
Authoritative source PNGs may associate by unique original asset_name (only @2x suffix is normalized). The mapping records source-name provenance, which is not a pixel-equivalence claim for the exported vector. Errors fail loudly.
compose
compose(panels: list[tuple[str | Path, float, float]], *, width: float, height: float, output: str | Path | None = None) -> Element
Assemble in paint order; pass output to rebase relative image URLs.
deduplicate_paths
deduplicate_paths(root: Element) -> dict
Remove only identical consecutive opaque fill-only paths in safe groups.
shortcut: antialiased edges may differ even for opaque fills, inspect the processed render before use; disable this opt-in cleanup for exact pixels.
inline_images
inline_images(root: Element, mapping: dict) -> dict
Replace uniquely matched rasters in place with nested SVG viewports.
The outer group retains image transforms/clipping/opacity; the nested SVG retains exported viewBox, drawing/defs and image placement/aspect ratio.
map_images
map_images(root: Element, index: dict) -> dict
Return a JSON-serializable data-URI mapping with all candidate paths.
pixel_key
pixel_key(data: bytes) -> str
Hash exact 8-bit premultiplied pixels, including dimensions and alpha.
process_images
process_images(root: Element, mapping: dict | None = None, *, icon_mode: str = 'inline-svg', output: str | Path | None = None) -> dict
Keep, link or inline mapped icons; URL modes require the output SVG path.
PNG links prefer a pixel-exact exported candidate (sorted path tie-break), then the manifest's standard PNG for source-name associations. No copying or renaming occurs. Receipts describe selection, not browser load success.
read_svg
read_svg(path: str | Path) -> Element
Read trusted local capture/export XML without touching the source.
restyle
restyle(root: Element, *, stroke: str | None = None, fill: str | None = None, stroke_width: float | None = None, background: str | None = None, font: str = 'system-ui', wireframe: bool = False, monochrome: bool = False) -> dict
Restyle presentation/inline CSS; retain opacity and none paints.
Resolve author CSS cascade/inheritance first to preserve effective no-paint. Mask-bearing documents and unsupported/contextual CSS fail before edits. Wireframe explicitly changes paints to dark outlines/text with opaque light surfaces, retaining no-paint. Monochrome filters the full drawing, preserving luminance hierarchy and existing filters. Wireframe wraps retained images with grayscale filtering. Resource definitions retain their geometry and paint.
tag_widgets
tag_widgets(root: Element, record: dict) -> dict
Tag original paint shapes by smallest containing root-logical widget rect.
svgelements computes actual path/shape bounds with inherited transforms and viewports. Text metrics, clipping and use-instance ownership are not inferred. Existing IDs remain intact to preserve references; data-widget is always set.
write_svg
write_svg(root: Element, output: str | Path) -> Path
Publish a new processed artifact; refuse raw/existing destinations.