@svgsketch/core 1.8.0 → 1.9.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 +47 -31
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -11
- package/dist/index.mjs +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,19 +21,19 @@ const doc = new Document({ width: 400, height: 300 })
|
|
|
21
21
|
.add(new Circle(200, 150, 80).fill('#2563eb'))
|
|
22
22
|
.add(new Rectangle(10, 10, 100, 60).fill('#ef4444').cornerRadius(8));
|
|
23
23
|
|
|
24
|
-
const svg = doc.toSVG();
|
|
25
|
-
const svgs = doc.toJSON();
|
|
24
|
+
const svg = doc.toSVG(); // rendered SVG string
|
|
25
|
+
const svgs = doc.toJSON(); // canonical `.svgs` document
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## What it includes
|
|
29
29
|
|
|
30
|
-
| Module
|
|
31
|
-
|
|
|
32
|
-
| `types`
|
|
33
|
-
| `format`
|
|
34
|
-
| `renderer`
|
|
35
|
-
| `sdk`
|
|
36
|
-
| `codegen`
|
|
30
|
+
| Module | Exports |
|
|
31
|
+
| ---------- | -------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `types` | `HistorySnapshot`, `SerializedShape`, `SerializedSymbolDef`, … |
|
|
33
|
+
| `format` | `parseDocument`, `stringifyDocument`, `migrateSnapshot`, `validateSnapshot`, `substituteVariables` |
|
|
34
|
+
| `renderer` | `renderToSvg` |
|
|
35
|
+
| `sdk` | `Document`, `Circle`, `Rectangle`, …, `Timeline`, `Track` |
|
|
36
|
+
| `codegen` | `generateCode` — SVG / React / Vue / D3 / CSS output |
|
|
37
37
|
|
|
38
38
|
## The `.svgs` format
|
|
39
39
|
|
|
@@ -52,17 +52,39 @@ designed for:
|
|
|
52
52
|
```jsonc
|
|
53
53
|
{
|
|
54
54
|
"schemaVersion": 1,
|
|
55
|
-
"documentMetadata": {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
55
|
+
"documentMetadata": {
|
|
56
|
+
/* title, author, license, … */
|
|
57
|
+
},
|
|
58
|
+
"templateVariables": [
|
|
59
|
+
/* { name, type, defaultValue, … } */
|
|
60
|
+
],
|
|
61
|
+
"viewboxes": [
|
|
62
|
+
/* { id, x, y, width, height } */
|
|
63
|
+
],
|
|
64
|
+
"guides": [
|
|
65
|
+
/* { id, orientation, position, … } */
|
|
66
|
+
],
|
|
67
|
+
"measurements": [
|
|
68
|
+
/* dimensioning annotations */
|
|
69
|
+
],
|
|
70
|
+
"groups": [
|
|
71
|
+
/* { id, parentId, siblingIndex, … } */
|
|
72
|
+
],
|
|
73
|
+
"clipMaskGroups": [
|
|
74
|
+
/* <clipPath> / <mask> definitions */
|
|
75
|
+
],
|
|
76
|
+
"customPatterns": [
|
|
77
|
+
/* user-defined fill patterns */
|
|
78
|
+
],
|
|
79
|
+
"symbols": [
|
|
80
|
+
/* reusable component definitions */
|
|
81
|
+
],
|
|
82
|
+
"animationTimeline": {
|
|
83
|
+
/* tracks + keyframes */
|
|
84
|
+
},
|
|
85
|
+
"shapes": [
|
|
86
|
+
/* array — order IS z-order */
|
|
87
|
+
],
|
|
66
88
|
}
|
|
67
89
|
```
|
|
68
90
|
|
|
@@ -72,7 +94,7 @@ exhaustive schema.
|
|
|
72
94
|
### Ordering rules
|
|
73
95
|
|
|
74
96
|
- **`shapes` preserves array order** — the position of a shape in the
|
|
75
|
-
array
|
|
97
|
+
array _is_ its painter's-model z-order. Sorting would silently reorder
|
|
76
98
|
rendering and destroy user intent.
|
|
77
99
|
- **Id-keyed collections** (`groups`, `viewboxes`, `guides`,
|
|
78
100
|
`clipMaskGroups`, `customPatterns`, `symbols`) are sorted by `id`.
|
|
@@ -122,7 +144,7 @@ Two complementary mechanisms for parameterizing documents:
|
|
|
122
144
|
|
|
123
145
|
- **`state.bindings`** — a map from a geometry property name to a CSS
|
|
124
146
|
custom-property name (without the leading `--`). When a property is
|
|
125
|
-
bound, `state[property]` holds the
|
|
147
|
+
bound, `state[property]` holds the _resolved_ value (what the renderer
|
|
126
148
|
uses if no substitution runs), and `bindings` records the variable the
|
|
127
149
|
editor should re-bind to on the next edit. Example:
|
|
128
150
|
|
|
@@ -132,8 +154,8 @@ Two complementary mechanisms for parameterizing documents:
|
|
|
132
154
|
"type": "circle",
|
|
133
155
|
"state": {
|
|
134
156
|
"radius": 50,
|
|
135
|
-
"bindings": { "radius": "card-radius" }
|
|
136
|
-
}
|
|
157
|
+
"bindings": { "radius": "card-radius" },
|
|
158
|
+
},
|
|
137
159
|
}
|
|
138
160
|
```
|
|
139
161
|
|
|
@@ -173,13 +195,7 @@ Errors block loading; warnings are surfaced but do not.
|
|
|
173
195
|
## Minimal example
|
|
174
196
|
|
|
175
197
|
```ts
|
|
176
|
-
import {
|
|
177
|
-
Document,
|
|
178
|
-
Circle,
|
|
179
|
-
parseDocument,
|
|
180
|
-
substituteVariables,
|
|
181
|
-
renderToSvg,
|
|
182
|
-
} from '@svgsketch/core';
|
|
198
|
+
import { Document, Circle, parseDocument, substituteVariables, renderToSvg } from '@svgsketch/core';
|
|
183
199
|
|
|
184
200
|
// Build
|
|
185
201
|
const doc = new Document({ width: 200, height: 200 })
|
package/dist/index.d.mts
CHANGED
|
@@ -1611,6 +1611,12 @@ declare const COMMON_TRANSFORM_NODE_DEFAULTS: CommonTransformNodeProps;
|
|
|
1611
1611
|
|
|
1612
1612
|
type SerializedShapeState = ShapeTransformState & {
|
|
1613
1613
|
[key: string]: unknown;
|
|
1614
|
+
/**
|
|
1615
|
+
* Editor layer label shown in the Elements panel. This is intentionally
|
|
1616
|
+
* separate from ShapeMetadata.name / SVG id so it may contain arbitrary
|
|
1617
|
+
* user-facing text without changing exported element identifiers.
|
|
1618
|
+
*/
|
|
1619
|
+
layerName?: string;
|
|
1614
1620
|
x?: number;
|
|
1615
1621
|
y?: number;
|
|
1616
1622
|
width?: number;
|
|
@@ -2753,6 +2759,7 @@ type LibraryDefOfKind<K extends LibraryKind> = Extract<LibraryDef, {
|
|
|
2753
2759
|
*/
|
|
2754
2760
|
|
|
2755
2761
|
interface CommonNodeProps extends CommonTransformNodeProps {
|
|
2762
|
+
layerName: string | null;
|
|
2756
2763
|
fillColor: string;
|
|
2757
2764
|
borderColor: string;
|
|
2758
2765
|
borderWidth: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1611,6 +1611,12 @@ declare const COMMON_TRANSFORM_NODE_DEFAULTS: CommonTransformNodeProps;
|
|
|
1611
1611
|
|
|
1612
1612
|
type SerializedShapeState = ShapeTransformState & {
|
|
1613
1613
|
[key: string]: unknown;
|
|
1614
|
+
/**
|
|
1615
|
+
* Editor layer label shown in the Elements panel. This is intentionally
|
|
1616
|
+
* separate from ShapeMetadata.name / SVG id so it may contain arbitrary
|
|
1617
|
+
* user-facing text without changing exported element identifiers.
|
|
1618
|
+
*/
|
|
1619
|
+
layerName?: string;
|
|
1614
1620
|
x?: number;
|
|
1615
1621
|
y?: number;
|
|
1616
1622
|
width?: number;
|
|
@@ -2753,6 +2759,7 @@ type LibraryDefOfKind<K extends LibraryKind> = Extract<LibraryDef, {
|
|
|
2753
2759
|
*/
|
|
2754
2760
|
|
|
2755
2761
|
interface CommonNodeProps extends CommonTransformNodeProps {
|
|
2762
|
+
layerName: string | null;
|
|
2756
2763
|
fillColor: string;
|
|
2757
2764
|
borderColor: string;
|
|
2758
2765
|
borderWidth: number;
|