@svgsketch/core 8.0.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -3
- package/dist/index.d.mts +18516 -11920
- package/dist/index.d.ts +18516 -11920
- package/dist/index.js +107 -83
- package/dist/index.mjs +107 -83
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -25,6 +25,37 @@ const svg = doc.toSVG(); // rendered SVG string
|
|
|
25
25
|
const svgs = doc.toJSON(); // canonical `.svgs` document
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
## Inspect and recolor artwork
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { DocumentBuilder, Rectangle, cssColorKey } from '@svgsketch/core';
|
|
32
|
+
|
|
33
|
+
const doc = new DocumentBuilder().add(new Rectangle(0, 0, 80, 60).fill('#2563eb'));
|
|
34
|
+
const inventory = doc.collectColorInventory();
|
|
35
|
+
const blue = cssColorKey('#2563eb', { includeAlpha: false });
|
|
36
|
+
const group = inventory.groups.find((g) => g.kind === 'color' && g.originalColors.includes(blue!))!;
|
|
37
|
+
doc
|
|
38
|
+
.recolor({ replacements: { [group.id]: '#0f766e' } }, { inventory })
|
|
39
|
+
.tokenizeColors({ prefix: 'poster' });
|
|
40
|
+
const svg = doc.toSVG();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`recolor()` and `tokenizeColors()` are fluent and throw `RecolorError` on refusal without changing the builder.
|
|
44
|
+
Their `WithDiagnostics` variants return the existing `RecolorApplicationOutcome` with diagnostics, impact, and an optional refusal.
|
|
45
|
+
`SdkRecolorOptions` accepts an existing in-memory inventory, fresh `inventoryOptions`, and `planningOptions` such as an identity allocator.
|
|
46
|
+
An inventory belongs to its source snapshot and analysis context; recollect it after editing the document.
|
|
47
|
+
Inventories and returned outcomes remain detached from later mutable builder edits.
|
|
48
|
+
Selection scope defaults to forking, document scope to shared editing, and source alpha is preserved.
|
|
49
|
+
|
|
50
|
+
The pure `findSamePaintColorMatches(snapshot, request, options?)` query matches effective fill or stroke by canonical base color, independently of token identity and opacity.
|
|
51
|
+
Supply native seed and candidate IDs explicitly.
|
|
52
|
+
Its immutable result includes matches, color keys, skipped-site reasons, and serializable diagnostics.
|
|
53
|
+
Container seeds expand to paintable descendants; reusable instances match only when their paint is uniform.
|
|
54
|
+
Gradients, mixed paint, animation, and uncertain consumers are skipped rather than approximated.
|
|
55
|
+
|
|
56
|
+
The existing pure analysis, inventory, planning, and application APIs remain available for callers that manage snapshots directly.
|
|
57
|
+
Schema 39, collaboration protocol 16, and single-value tokens are unchanged.
|
|
58
|
+
|
|
28
59
|
## What it includes
|
|
29
60
|
|
|
30
61
|
| Module | Exports |
|
|
@@ -53,7 +84,7 @@ designed for:
|
|
|
53
84
|
{
|
|
54
85
|
"schemaVersion": 1,
|
|
55
86
|
"documentMetadata": {/* title, author, license, … */},
|
|
56
|
-
"templateVariables": [/* { name, type, defaultValue,
|
|
87
|
+
"templateVariables": [/* { id, name, type, defaultValue, ... } */],
|
|
57
88
|
"viewboxes": [/* { id, x, y, width, height } */],
|
|
58
89
|
"guides": [/* { id, orientation, position, … } */],
|
|
59
90
|
"measurements": [/* dimensioning annotations */],
|
|
@@ -139,6 +170,19 @@ Two complementary mechanisms for parameterizing documents:
|
|
|
139
170
|
|
|
140
171
|
### Round-trip fidelity
|
|
141
172
|
|
|
173
|
+
SVG token output uses a direct document-root stylesheet with `@layer svgsketch.tokens` and `:where(svg:root)`.
|
|
174
|
+
This default replaces the legacy `:root, svg` contract, preventing host-page declaration leaks.
|
|
175
|
+
Inline copies retain defaults through derived fallbacks and may inherit independently themed host values.
|
|
176
|
+
The live editor requests an explicit document-layer host target.
|
|
177
|
+
Recognized current, legacy, compatible, and merged SVGSketch blocks recover names, defaults, and inferred token types on SVG import; native metadata remains `.svgs` information.
|
|
178
|
+
|
|
179
|
+
`renderToSvg(snapshot, { colorOutput: 'compatible' | 'resolved', colorScheme: 'light' | 'dark' })` selects portable output; the defaults are authored/light.
|
|
180
|
+
`applyColorOutputWithDiagnostics(svg, { mode: 'resolved' })` exposes pure source conversion with warnings for preserved uncertain sites.
|
|
181
|
+
`applyTemplateVariableFallbacksWithDiagnostics`, `buildRenderPlanWithDiagnostics`, `analyzeTemplateVariables`, and shared validation helpers support deferred consumers and token editors.
|
|
182
|
+
Token names are decoded CSS identifiers without `--`; color defaults accept unresolved CSS color expressions and number defaults require finite unitless literals.
|
|
183
|
+
Free-form string stamping uses carrier-aware escaping, and executable/structural substitutions are refused.
|
|
184
|
+
See the [Phase 5 contract](../../docs/architecture/recolor-phase-5.md) for recovery, output boundaries, and compatibility details.
|
|
185
|
+
|
|
142
186
|
The format guarantees that for any valid snapshot `s`:
|
|
143
187
|
|
|
144
188
|
```ts
|
|
@@ -199,5 +243,6 @@ const svg = renderToSvg(resolved);
|
|
|
199
243
|
|
|
200
244
|
The companion `@svgsketch/cli` package exposes `svgsketch validate`,
|
|
201
245
|
`svgsketch render`, `svgsketch info`, `svgsketch vars`, and
|
|
202
|
-
`svgsketch codegen` commands that operate on `.svgs` files headlessly
|
|
203
|
-
|
|
246
|
+
`svgsketch codegen` commands that operate on `.svgs` files headlessly.
|
|
247
|
+
Its `colors`, `recolor`, and `tokenize` commands inspect and rewrite SVG, native, Illustrator, PDF, and EPS inputs through the same inventory and planner, with dry-run reports and atomic native/SVG output.
|
|
248
|
+
These commands are suitable for CI/CD pipelines.
|