@vvfx/svg2ir 0.0.1-beta.0 → 0.0.1-beta.11
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 +62 -33
- package/dist/common/types.d.ts +6 -2
- package/dist/convert.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1226 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1226 -38
- package/dist/index.mjs.map +1 -1
- package/dist/node.js +1228 -39
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +1228 -40
- package/dist/node.mjs.map +1 -1
- package/dist/parse-svg/build-element-tree-path.d.ts +2 -0
- package/dist/svg-rasterizer/prepare-snapshot.d.ts +9 -0
- package/dist/svg-rasterizer/rasterize-svg.d.ts +11 -0
- package/dist/svg2ir/assemble.d.ts +3 -1
- package/dist/svg2ir/convert.d.ts +3 -1
- package/dist/svg2ir/converter/layers/conversion-session.d.ts +2 -0
- package/dist/svg2ir/converter/text/font-metrics.d.ts +2 -0
- package/dist/svg2layers-adapter/assemble.d.ts +15 -2
- package/dist/svg2layers-adapter/baking/build-baked-layers.d.ts +13 -0
- package/dist/svg2layers-adapter/baking/normalize-layer-blending.d.ts +10 -0
- package/dist/svg2layers-adapter/baking/plan-graphic-baking.d.ts +18 -0
- package/dist/svg2layers-adapter/baking/resolve-baking-warnings.d.ts +4 -0
- package/dist/svg2layers-adapter/convert.d.ts +2 -2
- package/dist/svg2layers-adapter/converter/image/inspect-mask.d.ts +3 -0
- package/dist/svg2layers-adapter/converter/layers/build-layers.d.ts +1 -1
- package/dist/svg2layers-adapter/strip-layer-animation.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,21 +7,13 @@ Convert SVG into source-neutral Animation IR, with optional SVG-to-GE and SVG-to
|
|
|
7
7
|
|
|
8
8
|
## Contents
|
|
9
9
|
|
|
10
|
-
- [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- [SVG to static layers](#svg-to-static-layers)
|
|
18
|
-
- [API](#api)
|
|
19
|
-
- [Package API](#package-api)
|
|
20
|
-
- [Output](#output)
|
|
21
|
-
- [Support](#support)
|
|
22
|
-
- [Limitations](#limitations)
|
|
23
|
-
- [Contributing](#contributing)
|
|
24
|
-
- [License](#license)
|
|
10
|
+
- [Install](#install)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [API](#api)
|
|
13
|
+
- [Output](#output)
|
|
14
|
+
- [Input capabilities](#input-capabilities)
|
|
15
|
+
- [Limitations](#limitations)
|
|
16
|
+
- [License](#license)
|
|
25
17
|
|
|
26
18
|
## Install
|
|
27
19
|
|
|
@@ -92,13 +84,25 @@ static layers and asynchronously returns `{ size, data, warnings }`.
|
|
|
92
84
|
`data` is a flat array of image and text layers; `size` is the separate canvas width and height in pixels.
|
|
93
85
|
SVG images become image layers, and native text becomes editable text layers. Text inside images is not recognized.
|
|
94
86
|
|
|
87
|
+
Self-contained static graphics are baked into transparent PNG layers, preserving fills, gradients,
|
|
88
|
+
patterns, strokes, markers, transforms, filters, clipping, masks, and opacity. Ordinary graphics stay separate;
|
|
89
|
+
group-wide effects may merge child graphics into one PNG. Native text and images are never baked.
|
|
90
|
+
Consumers must create layers in array order to retain SVG painter order.
|
|
91
|
+
|
|
92
|
+
Non-normal blend modes (such as multiply, screen, and overlay) are downgraded to normal alpha compositing.
|
|
93
|
+
Baking and downgrades produce warnings; successful baking remains advisory in strict mode.
|
|
94
|
+
Baking requires browser SVG, Canvas, and DOM support; Node converts native layers and warns for unbaked graphics.
|
|
95
|
+
Mixed native effect groups, dependencies containing text/images, external paint resources, animations, scripts,
|
|
96
|
+
and `foreignObject` are not baked.
|
|
97
|
+
|
|
95
98
|
Layer format:
|
|
96
99
|
|
|
97
100
|
- Common fields: `id` is generated automatically; `bbox` uses canvas-pixel coordinates
|
|
98
|
-
`[left, top, right, bottom]`.
|
|
101
|
+
`[left, top, right, bottom]`. Native geometry is rounded to two decimal places.
|
|
99
102
|
- Image layers: `type: 'image'`, `role: 'content'`, and a Base64 data URL in `url`.
|
|
100
103
|
`size` holds display dimensions before rotation; `rotation` holds XYZ Euler angles in degrees (positive Z is
|
|
101
104
|
clockwise). `width` and `height` are the bbox dimensions.
|
|
105
|
+
Baked geometry follows raster resolution; transforms are included in the pixels, with `rotation: [0, 0, 0]`.
|
|
102
106
|
- Text layers: `type: 'text'`, `state: 'active'`, full text in `content`, and `fragments` containing text runs,
|
|
103
107
|
fonts, sizes, colors, and spacing. Fragment `bbox` and `polygon` are relative to the text layer's top-left corner;
|
|
104
108
|
polygon contains the layout corners. Rotation uses degrees and colors use `#RRGGBB`.
|
|
@@ -116,6 +120,7 @@ authenticated resources and `resourceBaseUrl` for relative image references. Fai
|
|
|
116
120
|
- `convertSVGToGE(source, options?, preservedData?)` returns `{ data, warnings }`.
|
|
117
121
|
- `convertSVG(source, options?, preservedData?)` returns `{ data, warnings }` synchronously for GE, or
|
|
118
122
|
`Promise<SVGToLayersResult>` for layers.
|
|
123
|
+
- `inferNumericWeightFromFamily(fontFamily)` infers a numeric font weight, or returns `null`.
|
|
119
124
|
|
|
120
125
|
Important options include `frameRate` (default `30`), `durationSeconds` (default `5` for static SVG),
|
|
121
126
|
`backgroundColor`, `resourceBaseUrl`, `imageNaturalSizes`, `measureText`, `strict`, `onWarning`, and the GE-only
|
|
@@ -123,6 +128,9 @@ Important options include `frameRate` (default `30`), `durationSeconds` (default
|
|
|
123
128
|
`convertSVG` also accepts `outputFormat` (`'ge'` by default or `'layers'`) and a layers-only `loadImage` callback:
|
|
124
129
|
`(url) => Promise<{ data: Uint8Array; mimeType: string }>`; `data` contains the original image bytes.
|
|
125
130
|
|
|
131
|
+
The layers-only `rasterScale` option controls PNG resolution without changing display size; it defaults to `2`
|
|
132
|
+
and must be finite and positive. The working raster is limited to 16 megapixels.
|
|
133
|
+
|
|
126
134
|
All public types, including `SVGPreservedData`, `ConvertOptions`, `SVGToGEOptions`, `SVGToLayersOptions`, `SVGStaticLayer`,
|
|
127
135
|
`SVG2IRWarning`, and result types, are exported from `@vvfx/svg2ir`.
|
|
128
136
|
|
|
@@ -142,13 +150,41 @@ await convertSVG(source, { outputFormat: 'layers' });
|
|
|
142
150
|
// { size: [number, number]; data: SVGStaticLayer[]; warnings: SVG2IRWarning[] }
|
|
143
151
|
```
|
|
144
152
|
|
|
145
|
-
##
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
## Input capabilities
|
|
154
|
+
|
|
155
|
+
Supported refers to the listed subset; partial means some attributes are approximated or omitted. Output format
|
|
156
|
+
matters: static layers support a smaller subset than IR and GE.
|
|
157
|
+
|
|
158
|
+
### IR and GE
|
|
159
|
+
|
|
160
|
+
| Capability | Status | Behavior |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| SVG string and shapes | Supported | `rect`, `circle`, `ellipse`, `path`, `polygon`, `polyline`, and `line`. |
|
|
163
|
+
| Groups and references | Supported | Hierarchy, transforms, opacity, and expanded `use` / `symbol` instances. |
|
|
164
|
+
| Images | Partial | URL assets and aspect ratio; supply natural sizes to avoid fitted-geometry fallback. |
|
|
165
|
+
| Text | Partial | Text/tspan, text paths, multiline and vertical text; GE rich text needs the sidecar. |
|
|
166
|
+
| Paints | Partial | Solid and supported gradients; gradient text is flattened, some gradient attributes lost. |
|
|
167
|
+
| Masks and clip paths | Partial | Element clip paths and element/group masks; unit and region limits below. |
|
|
168
|
+
| Group `clip-path` | Unsupported | Omitted with `svg2ir_group_clip_path_dropped`. |
|
|
169
|
+
| SMIL | Partial | Transform, motion, opacity, visibility, selected geometry and paint; GE paint uses sidecar. |
|
|
170
|
+
| Filters / patterns / markers | Unsupported | Effects omitted with warnings; supported content remains. |
|
|
171
|
+
| Skew and text decoration | Unsupported | Dropped with warnings; text stroke is also omitted. |
|
|
172
|
+
| Other elements | Unsupported | Unmapped content such as `foreignObject` is omitted with warnings. |
|
|
173
|
+
|
|
174
|
+
### Static layers
|
|
175
|
+
|
|
176
|
+
| Capability | Status | Behavior |
|
|
177
|
+
| --- | --- | --- |
|
|
178
|
+
| Images and native text | Supported | Flat image/text layers; text inside images is not recognized. |
|
|
179
|
+
| Image resources | Supported | Fetches and inlines bytes; use `loadImage` for local or authenticated resources. |
|
|
180
|
+
| Text layout and styles | Partial | Metrics may be estimated; bold/italic are downgraded; vertical text is split. |
|
|
181
|
+
| Shapes and animation | Unsupported | Skipped with warnings; layers export does not rasterize vector shapes. |
|
|
182
|
+
| Masks and visual transforms | Partial | Basic rotation/scale; unsupported opacity, crop, skew, etc. skip layers. |
|
|
183
|
+
|
|
184
|
+
Read `warnings` and optionally `onWarning`. Examples include `svg2ir_filter_dropped`,
|
|
185
|
+
`svg2ir_text_gradient_fill_flattened`, and `svg2ge_layers_unsupported_feature`.
|
|
186
|
+
`strict: true` rejects reported unsupported features and style downgrades; estimated layer text bounds still warn.
|
|
187
|
+
Invalid SVG and failed layer image loads throw errors. An empty warning list is not a complete rendering-fidelity check.
|
|
152
188
|
|
|
153
189
|
## Limitations
|
|
154
190
|
|
|
@@ -160,20 +196,13 @@ paths are supported; group-level `clip-path` is currently a limitation.
|
|
|
160
196
|
- IR and GE conversion do not download external resources. Callers own URL resolution, font loading, and runtime
|
|
161
197
|
resource access. Layers export reads and inlines image resources as described above.
|
|
162
198
|
|
|
163
|
-
Static layers export supports images and text only.
|
|
164
|
-
image skew/reflection/cropping, masks,
|
|
199
|
+
Static layers export supports images and text only. SMIL animation elements are removed with a warning; unsupported animated channels, unbaked shapes, solid backgrounds,
|
|
200
|
+
image skew/reflection/cropping, masks, opacity, nonuniform text scaling, and text paths are skipped with warnings.
|
|
165
201
|
Bold and italic styles are downgraded with warnings; vertical text is split into character layers with horizontal fragments.
|
|
166
202
|
Supply `measureText` for font metrics; incomplete metrics produce estimated bounds and warnings.
|
|
167
203
|
`strict: true` turns unsupported content and style downgrades into errors; estimated bounds still produce warnings.
|
|
168
204
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
From the monorepo root:
|
|
172
|
-
|
|
173
|
-
```bash
|
|
174
|
-
pnpm --filter @vvfx/svg2ir test
|
|
175
|
-
pnpm --filter @vvfx/svg2ir build
|
|
176
|
-
```
|
|
205
|
+
Images are retained when a straight rectangular mask covers the full image without inversion or subtraction.
|
|
177
206
|
|
|
178
207
|
## License
|
|
179
208
|
|
package/dist/common/types.d.ts
CHANGED
|
@@ -39,15 +39,19 @@ export interface ConvertResult {
|
|
|
39
39
|
/** 转换过程丢弃/降级的特性列表。 */
|
|
40
40
|
warnings: SVG2IRWarning[];
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/** 转换过程中产生的烘焙、降级或内容损失诊断。 */
|
|
43
43
|
export interface SVG2IRWarning {
|
|
44
44
|
code: SVG2IRWarningCode;
|
|
45
45
|
message: string;
|
|
46
46
|
/** 触发元素在 SVG 里的定位提示(id/tag/索引等)。 */
|
|
47
47
|
elementSelector?: string;
|
|
48
48
|
}
|
|
49
|
-
/** SVG
|
|
49
|
+
/** SVG 转换诊断码;用于报告烘焙、降级和不支持的特性。 */
|
|
50
50
|
export declare const SVG2IR_WARNING_CODES: {
|
|
51
|
+
/** 图形或图形组已栅格化,矢量编辑能力变化通过 warning 报告。 */
|
|
52
|
+
readonly LAYERS_GRAPHIC_BAKED: "svg2ge_layers_graphic_baked";
|
|
53
|
+
readonly LAYERS_BLEND_MODE_DOWNGRADED: "svg2ge_layers_blend_mode_downgraded";
|
|
54
|
+
readonly LAYERS_ANIMATION_STRIPPED: "svg2ge_layers_animation_stripped";
|
|
51
55
|
readonly LAYERS_UNSUPPORTED_TYPE: "svg2ge_layers_unsupported_type";
|
|
52
56
|
readonly LAYERS_UNSUPPORTED_FEATURE: "svg2ge_layers_unsupported_feature";
|
|
53
57
|
readonly LAYERS_INVALID_DATA: "svg2ge_layers_invalid_data";
|
package/dist/convert.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface SVGConversionOptions extends ConvertOptions {
|
|
|
7
7
|
fonts?: SVGToGEOptions['fonts'];
|
|
8
8
|
/** layers 图片读取回调;默认使用 fetch,已有 data URL 无需读取。 */
|
|
9
9
|
loadImage?: SVGImageResourceLoader;
|
|
10
|
+
/** Graphic baking resolution; logical layer dimensions remain unchanged. Default: 2. */
|
|
11
|
+
rasterScale?: number;
|
|
10
12
|
}
|
|
11
13
|
export interface SVGToLayersOptions extends SVGConversionOptions {
|
|
12
14
|
outputFormat: 'layers';
|
package/dist/index.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export type { SVGToGEOptions, SVGToGEResult } from './svg2ge-adapter/types';
|
|
|
12
12
|
export type { SVGConversionOptions, SVGToLayersOptions } from './convert';
|
|
13
13
|
export type { SVGPreservedData, SVGFontDefinition, SVGPreservedPaintAnimation, SVGPreservedShapeAnimation, SVGPreservedTextData, SVGPreservedTextSpan, } from './svg-preserved-data';
|
|
14
14
|
export type { SVGStaticLayer, SVGImageLayer, SVGTextLayer, SVGTextFragment, SVGLayerBBox, SVGToLayersResult, SVGLayerEraseOperation, SVGImageResource, SVGImageResourceLoader, } from './svg2layers-adapter/types';
|
|
15
|
+
export { inferNumericWeightFromFamily } from './svg2ir/converter/text/font-metrics';
|