ئەم وەرگێڕانە بە یارمەتیی AI نووسراوە و پێویستی بە پێداچوونەوەی کەسێکی زمانزان هەیە.
Writing an exporter
ئەم ناوەڕۆکە هێشتا بە زمانەکەت بەردەست نییە.
@0xdolan/deq-exporters turns shapes into files (ADR 0009, API reference). Every format goes through one entry point:
exportShapes(format, items, options): Promise<ExportFile[]> // { name, mediaType, data }Steps
- Add the format id to
FORMATSinpackages/exporters/src/index.ts. - Write the writer in a module of its own, or next to similar formats (
svg.tsfor SVG text formats,components.tsfor framework components,pdf.ts,eps.ts,raster.ts,psd.ts,favicon.ts,spec.ts). - Add a
casetoperIteminindex.ts. A format that writes one file for many items (like the sprite, CSS or favicon) is handled inexportShapesitself. - If it needs new options, add them to
OptionsSchema, the valibot schemacheckOptionsvalidates against. - Add the format to the
EXPECTEDtable insrc/index.test.ts(file names and media type), to the README table and to the user guide. - If the format cannot hold a scene (a Leet text or a pattern), add it to
SCENE_UNSUPPORTEDinsrc/input.tsand toapps/site/src/studio/formats.ts; a test keeps the two lists equal. - If the website should offer it, check
apps/site/src/studio/formats.tsand the Studio export dialog.
The contract
- Build on core. Never re-implement expansion or option handling. Start from core’s
prepare()(validated options and flat geometry) andsvgDocument(). Vector writers go throughbuildDrawing()insrc/drawing.ts, which follows core’s paint rules. - Validate options with valibot
strictObjects. Every failure is aDeqError(INVALID_OPTIONSand so on). Parse colours withparseColorand write them back withtoHex, never as given. - Be deterministic. No dates, random ids or anything from the environment in the output.
- Write nothing active. No scripts,
hrefs or external references. Escape strings for their context: XML, JavaScript, PDF UTF-16BE, ASCII-only EPS comments. - Keep the limits: 512 items, raster width up to 8192 px, scales from 1 to 8. File names must be unique even when case is ignored.
- Keep the layers where the format has them: one group, OCG or pixel layer per shape layer, with
backgroundfirst. - Browsers: raster formats need
initRaster({ resvg })first, and the page’s CSP needs'wasm-unsafe-eval'.
Items can be a catalog id, a shape with options, a composition, a shape spec as data (DataItem), or a scene (LeetItem, PatternItem, SceneItem). Read src/input.ts for how each one is checked.
Tests
Every format needs a round trip: read the file back and compare it with core’s output.
| Kind | How it is checked |
|---|---|
| Components | Compile with TypeScript, @vue/compiler-sfc or svelte/compiler, render and compare with core |
| Raster | Decode the file and compare pixels with rasterize |
| PDF and EPS | Render with Ghostscript and compare with resvg (test/tools.ts) |
| Layers | Inkscape must list the layer names of layered SVG, PDF and AI; PSD is read back with ag-psd |
| Spec JSON | Validate against spec/schema/shape.schema.json; renderShapeData must equal render |
Tests that need Ghostscript or Inkscape 1.4+ are skipped when the tools are missing. just test-tools and the exporter-tools CI job run them with DEQ_REQUIRE_TOOLS=1, which fails instead of skipping. Illustrator and Photoshop files are checked by hand.
Ports
The Python and Rust ports write svg, svg-layered, svg-sprite, pdf, png, jpg, webp and ico, and exit with code 4 for other formats. A change to one of these formats lands in the ports in the same pull request, and SVG and PDF must stay byte-identical (ADR 0011).
وەشانێکی نوێی ئەم ماڵپەڕە بەردەستە.