Skip to main content

Declarative rendering pipeline: JSON in, SVG/PNG/WebP out

Project description

predraw

Declarative rendering pipeline: JSON in, SVG/PNG/WebP out.

The missing link between your AI and the SVGs you want to make.

Install

From PyPI:

uv tool install predraw

From npm (requires Python 3.11+):

npm i -g predraw

Quick start

Create a project directory:

my-asset/
  main.json
  config.json

main.json -- the scene:

{
  "width": 400,
  "height": 200,
  "styles": {
    "bg": {"light": "#ffffff", "dark": "#1a1a1a"},
    "fg": {"light": "#000000", "dark": "#ffffff"}
  },
  "elements": [
    {"type": "background", "fill": "$bg"},
    {
      "type": "text",
      "id": "title",
      "content": "hello world",
      "x": 200,
      "y": 110,
      "anchor": "middle",
      "fill": "$fg",
      "font": {"family": "Liberation Sans", "size": 48, "weight": 700}
    }
  ],
  "pipeline": [
    {"action": "text-to-paths", "target": "title"}
  ]
}

config.json -- output targets:

{
  "outputs": [
    {"format": "svg", "path": "hello-dark.svg", "mode": "dark"},
    {"format": "png", "path": "hello-light.png", "mode": "light"},
    {"format": "webp", "path": "hello-dark.webp", "mode": "dark", "quality": 90}
  ]
}

Build:

predraw build my-asset/

Commands

init [path]

Create a starter project with main.json and config.json.

predraw init                     # current directory
predraw init my-asset/           # create in new directory

build [path] [--dry-run]

Render all outputs defined in config.json. Path can be a directory (looks for main.json) or a file.

predraw build                    # current directory
predraw build path/to/project    # explicit path
predraw build --dry-run          # preview without rendering

watch [path]

Auto-rebuild when project files change. Polls for changes every 0.5s with 0.3s debounce.

predraw watch                    # watch current directory
predraw watch my-asset/          # watch specific project

pack [path] [-o file]

Convert a directory project into a single portable JSON file. Imports are resolved and inlined as defs.

predraw pack my-asset/ -o packed.json

unpack <file> [-o dir]

Convert a packed JSON file back into a directory project with separate component files.

predraw unpack packed.json -o my-asset/

validate <file> [--schema scene|config]

Validate a scene or config file against the JSON Schema. Auto-detects file type (presence of "outputs" key = config, otherwise = scene).

predraw validate main.json
predraw validate config.json --schema config

Format

Element types

Type Purpose Key properties
background Full-canvas fill fill
rect Rectangle x, y, width, height, fill, stroke
path SVG path d, fill, opacity, transform, stroke
text Text (can convert to paths) content, font, anchor, charStyles, stroke
group Container elements, transform

Stroke

All visible elements support stroke properties:

{"type": "rect", "width": 100, "height": 50, "stroke": "#ff0000", "strokeWidth": 2, "strokeDasharray": "5 3"}

Properties: stroke, strokeWidth, strokeDasharray, strokeLinecap (butt/round/square), strokeLinejoin (miter/round/bevel), strokeOpacity.

Gradients

Fill and stroke accept gradient objects:

{"fill": {"type": "linear-gradient", "angle": 90, "stops": [
  {"offset": 0, "color": "#ff0000"},
  {"offset": 1, "color": "#0000ff"}
]}}

{"fill": {"type": "radial-gradient", "cx": 0.5, "cy": 0.5, "r": 0.5, "stops": [
  {"offset": 0, "color": "#ffffff"},
  {"offset": 1, "color": "#000000", "opacity": 0.5}
]}}

Use (component instantiation)

Reference a component from imports or defs:

{"use": "logo", "transform": {"translate": [100, 50], "scale": [2, 2]}}

Property overrides cascade to children:

{"use": "logo", "fill": "#ff0000", "opacity": 0.5}

Styles

Define color tokens with light/dark variants:

{
  "styles": {
    "primary": {"light": "#000000", "dark": "#ffffff"},
    "muted": {"light": "#666666", "dark": "#999999"}
  }
}

Reference with $ prefix: "fill": "$primary". Mode is selected per-output in config.json.

charStyles

Style individual characters differently:

{
  "type": "text",
  "content": "releasable",
  "fill": "#ffffff",
  "charStyles": [
    {"chars": "rlsbl", "opacity": 1.0},
    {"chars": "eeaa", "opacity": 0.12}
  ]
}

Pipeline

Ordered postprocessing steps:

Action Fields Description
text-to-paths target Convert text to path outlines via font glyphs
center target, axis (x/y/both) Center element on canvas
place target, below/above/left/right, gap Position element relative to another
group targets, id Wrap elements into a group

Components

Split reusable parts into separate files:

project/
  main.json
  config.json
  components/
    logo.json

main.json:

{
  "imports": {"logo": "./components/logo.json"},
  "elements": [
    {"use": "logo", "transform": {"translate": [10, 10]}}
  ]
}

Packed format

predraw pack inlines imports as defs:

{
  "defs": {
    "logo": {"type": "group", "elements": [...]}
  },
  "elements": [
    {"use": "logo"}
  ]
}

Config

config.json defines output targets:

{
  "outputs": [
    {"format": "svg", "path": "out.svg"},
    {"format": "png", "path": "out-dark.png", "mode": "dark"},
    {"format": "webp", "path": "out.webp", "mode": "dark", "quality": 90}
  ]
}
Field Required Description
format Yes svg, png, or webp
path Yes Output file path (relative to project dir)
mode No light or dark (default: dark)
quality No WebP quality 1-100 (default: 90)

JSON Schema

Formal schemas for editor validation and LLM structured output:

  • schema/scene.schema.json -- scene format
  • schema/config.schema.json -- config format

Requirements

  • Python 3.11+
  • System fonts for text-to-paths (searches standard font directories)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predraw-0.2.0.tar.gz (72.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

predraw-0.2.0-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file predraw-0.2.0.tar.gz.

File metadata

  • Download URL: predraw-0.2.0.tar.gz
  • Upload date:
  • Size: 72.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for predraw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 91952f02a6eae4a17bbbd82c4bd4df02b6ebd72e089cf0bb3baeebd7b801f89c
MD5 21dd834b884a510b2024144086c90c75
BLAKE2b-256 ad51e42cfd498699e67d10d5bd5d22be9a480dfd52ce79adfa1f295bc07be41d

See more details on using hashes here.

Provenance

The following attestation bundles were made for predraw-0.2.0.tar.gz:

Publisher: publish.yml on smm-h/predraw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file predraw-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: predraw-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for predraw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10f31feddd2d2199712f14332455ab2eff80b7d04f1f98ecb5c3f9da00f2e459
MD5 e846bdf5f1348f03f00b047cef71b3e4
BLAKE2b-256 ed209ebfe213594200e10604171bfc54f622eea3ce9b62c10f3c02b881359601

See more details on using hashes here.

Provenance

The following attestation bundles were made for predraw-0.2.0-py3-none-any.whl:

Publisher: publish.yml on smm-h/predraw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page