Files
2026-05-27 23:29:53 +01:00

87 lines
3.8 KiB
Markdown

# Tasks: enterprise-compress-svg
**Change ID**: enterprise-compress-svg
**Package**: `@suaveplan/compress-svg`
**Target path**: `universal/compression/compress-svg`
**Prerequisite packages on Verdaccio**: `@suaveplan/error`, `@suaveplan/types`
---
## 1. Scaffold
- [x] Create directory `universal/compression/compress-svg/` with `src/`, `tests/`, `src/__benchmarks__/`, and all feature subdirectories per the layout in `proposal.md`.
- [x] Write `package.json` at version `0.1.0` with `"type": "module"`, `"sideEffects": false`, full `exports` map, deps: `@suaveplan/error workspace:^`, `@suaveplan/types workspace:^`, `zod catalog:forms`, `@opentelemetry/api catalog:observability`.
- [x] Write `tsconfig.json` extending `@suaveplan/typescript-config/library.json`.
- [x] Write `vitest.config.ts` using `createTestConfig()` from `@suaveplan/testing/config`.
- [x] Add `lint`, `typecheck`, `test`, `test:coverage`, `build`, `docs:check` scripts.
---
## 2. Types + errors
- [x] Write `src/types/common.ts` — `SvgNode`, `SvgPlugin`, `CompressOptions`, `CompressResult` interfaces.
- [x] Write `src/types/common.md`.
- [x] Write `src/error-codes.ts` — `SvgCompressErrorCode`, `SVG_COMPRESS_ERROR_METADATA`, `registerSvgCompressErrorCodes()`.
- [x] Write Zod schemas: `CompressOptionsSchema`, `CompressResultSchema`.
---
## 3. Parser
- [x] Implement `parseSvg(svg: string): SvgNode` — push-based SAX-like parser; no DOMParser dependency; handles element, text, comment, cdata, doctype nodes; throws `SvgCompressError(SVG_COMPRESS_PARSE_FAILED)` on malformed input.
- [x] Implement `serializeSvg(node: SvgNode): string` — compact serialiser.
- [x] Write `svg-parser.test.ts` (≤500 lines): round-trip for various SVG structures, malformed input throws.
- [x] Write `svg-parser.md`.
---
## 4. Plugins (one task each — each ≤300 lines)
- [x] `removeComments` — remove `type: 'comment'` nodes. Tests + md.
- [x] `removeMetadata` — remove `<metadata>` elements. Tests + md.
- [x] `removeDoctype` — remove `type: 'doctype'` nodes. Tests + md.
- [x] `collapseGroups` — merge single-child `<g>` elements, hoisting attrs. Tests + md.
- [x] `cleanupAttrs` — remove redundant/default attributes (e.g. `fill="black"` when it's the SVG default). Tests + md.
- [x] `convertPathData` — reduce decimal precision in `d` attribute to `floatPrecision` places. Tests + md.
- [x] `convertTransforms` — collapse and simplify `transform` attribute matrices. Tests + md.
- [x] `mangleIds` — replace `id` values with short sequential identifiers. Tests + md.
---
## 5. Presets
- [x] Write `src/presets/index.ts` — `PRESET_DEFAULT`, `PRESET_SAFE`, `PRESET_AGGRESSIVE`.
---
## 6. Main compressSvg function
- [x] Implement `compressSvg(svg, options): CompressResult` — parse → apply plugin pipeline → multipass loop until stable → serialize → return result with ratio.
- [x] Wire OTel: span `svg.compress`, counter `svg_compress_total`, histogram `svg_compress_duration_ms` + `svg_compress_ratio`.
- [x] Write `compress-svg.test.ts` (≤500 lines): each preset, multipass, custom plugin, parse error.
- [x] Write `compress-svg.md`.
---
## 7. Benchmarks
- [x] Write `src/__benchmarks__/compress-svg.bench.ts` — 10 kB SVG, 100 kB SVG, 1 MB SVG.
---
## 8. Tests
- [x] Write `tests/integration.test.ts` — PRESET_DEFAULT on real SVG files (inline fixtures).
- [x] Write `tests/property.test.ts` (fast-check) — idempotency, parse↔serialize round-trip, ratio ≤ 1.
---
## 9. Docs + verify + publish
- [x] All co-located `.md` files (≥200 words each).
- [x] Write `README.md` at package root.
- [x] `bunx turbo lint typecheck test --filter=@suaveplan/compress-svg` — green.
- [x] `bunx turbo test:coverage --filter=@suaveplan/compress-svg` — 100%.
- [x] `bun scripts/publish.ts --package @suaveplan/compress-svg`.
- [x] Archive to `openspec/archive/2026-04-24-enterprise-compress-svg/`.