@008h/oxs-stitch-svg
v0.4.0
Published
Render @008h/oxs cross-stitch charts as SVG (pixel, stitch and pattern looks)
Downloads
430
Readme
@008h/oxs-stitch-svg
Render @008h/oxs cross-stitch charts as SVG strings. Pure TypeScript, no DOM.
import { parseOxs } from '@008h/oxs';
import { renderSvg } from '@008h/oxs-stitch-svg';
const svg = renderSvg(parseOxs(xml), { variant: 'stitch', cellSize: 20 });Variants
pixel: one filled square per stitch.stitch: two slanted, elongated hexagonal threads per stitch (with edge, sheen and shadow), backstitches on top. Every number lives inTHREAD_STYLE.pattern: tinted cells with symbols and a grid. PassgrayscaleResolverto choose the symbol for a color.
Options
| Option | Default | Meaning |
|---|---|---|
| cellSize | 10 | Pixels per cell |
| resolveColor | item color | (item) => hex6 \| undefined; return undefined or an invalid hex to use the item's color |
| thread | THREAD_STYLE | Overrides of the thread shape, jitter, sheen and shadow numbers for the stitch variant (clamped to a valid shape) |
| overThread | 'slash' | Which thread lies on top in the stitch variant |
| backThread | 'cells' | How a backstitch is threaded in the stitch variant: 'cells' splits it into one thread per cell, 'whole' draws one thread from its start to its end (the ends reach backOvershoot beyond the nodes) |
| pixelBackStitch | false | pixel variant only: true draws the backstitches as flat ink lines (one round-ended <line> from start to end, in the palette color, pixelLineWidth(cellSize) wide; pass a positive finite cellSize) on top of the cells |
| style | — | Deprecated and ignored; STITCH_STYLE remains only for the WebGL side |
| origin | detectOrigin(chart) | 0 or 1; coordinates are interpreted with @008h/oxs dialect helpers |
| background | true | false leaves out the cloth-colored background rectangle, so the background is transparent |
By default the background is the cloth color (palette index 0) when present, otherwise white; pass background: false for a transparent one. Palette colors that are not bare 6-digit hex are never written into the markup.
Not rendered: part stitches, ornaments and comment boxes. Backstitches are drawn in the stitch variant, and in the pixel variant when pixelBackStitch is true. detectOrigin looks at cell stitches only, so for a chart with backstitches alone, pass origin explicitly.
Invalid numeric input (cellSize, style fields) falls back to the defaults.
backThreadPieces(style, segment, cellSize, { whole: true }) returns a single thread for the whole segment instead of one per cell. ThreadStyle.backOvershoot (default 0.04) sets how far its ends reach beyond the nodes; backMargin is used only in the default per-cell mode. backOvershoot is a new required field of ThreadStyle, so code that builds a full ThreadStyle by hand needs to add it.
@008h/oxs is a peer dependency.
Disclaimer
OXS is a file format published by Ursa Software. This project is an independent implementation and is not affiliated with or endorsed by Ursa Software.
License
MIT
