@vvfx/svg2ir 0.0.1-beta.11 → 0.0.1-beta.12
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 +26 -17
- package/dist/{svg2ge-adapter → adapter/svg2ge}/assemble.d.ts +2 -2
- package/dist/adapter/svg2ge/convert.d.ts +7 -0
- package/dist/{svg2ge-adapter → adapter/svg2ge}/normalize-shape-animation.d.ts +1 -1
- package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/apply-shape-geometry-animation.d.ts +1 -1
- package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/apply-shape-paint-animation.d.ts +1 -1
- package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/rewrite-text-components.d.ts +1 -1
- package/dist/{svg2ge-adapter → adapter/svg2ge}/pre-process.d.ts +1 -1
- package/dist/{svg2ge-adapter → adapter/svg2ge}/types.d.ts +2 -2
- package/dist/{svg2layers-adapter → adapter/svg2layers}/assemble.d.ts +9 -7
- package/dist/{svg2layers-adapter → adapter/svg2layers}/baking/build-baked-layers.d.ts +1 -1
- package/dist/{svg2layers-adapter → adapter/svg2layers}/baking/plan-graphic-baking.d.ts +1 -1
- package/dist/adapter/svg2layers/convert.d.ts +4 -0
- package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/diagnostics/collect-warnings.d.ts +1 -1
- package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/layers/conversion-session.d.ts +2 -2
- package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/text/parse-text-runs.d.ts +1 -1
- package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/text/text-layout.d.ts +2 -2
- package/dist/{svg2layers-adapter → adapter/svg2layers}/matrix.d.ts +1 -1
- package/dist/{svg2layers-adapter → adapter/svg2layers}/types.d.ts +8 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.js +124 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -92
- package/dist/index.mjs.map +1 -1
- package/dist/node.js +124 -92
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +124 -92
- package/dist/node.mjs.map +1 -1
- package/dist/svg2ir/convert.d.ts +2 -1
- package/package.json +5 -5
- package/dist/convert.d.ts +0 -21
- package/dist/svg2ge-adapter/convert.d.ts +0 -5
- package/dist/svg2layers-adapter/convert.d.ts +0 -4
- /package/dist/{svg2ge-adapter → adapter/svg2ge}/converter/animation.d.ts +0 -0
- /package/dist/{svg2ge-adapter → adapter/svg2ge}/converter/data-path.d.ts +0 -0
- /package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/apply-fonts.d.ts +0 -0
- /package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/paint-animation-sampling.d.ts +0 -0
- /package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/restore-gradient-uv.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/baking/normalize-layer-blending.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/baking/resolve-baking-warnings.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/image/convert-image-layer.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/image/inspect-mask.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/layers/build-layers.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/layers/registry.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/layers/resolve-visual-state.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/text/convert-text-layer.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/transform/build-transform.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/post-process/inline-image-resources.d.ts +0 -0
- /package/dist/{svg2layers-adapter → adapter/svg2layers}/strip-layer-animation.d.ts +0 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Convert SVG into source-neutral Animation IR, with optional SVG-to-GE and SVG-to
|
|
|
21
21
|
pnpm add @vvfx/svg2ir @vvfx/ge-ir
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Node.js
|
|
24
|
+
Node.js 24 or later and pnpm 10 or later are required. Browser and Node callers use the same root import; the Node
|
|
25
25
|
conditional entry automatically supplies the `svgdom` parsing base.
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
@@ -58,28 +58,31 @@ import { convertSVGToGE, splitSVG } from '@vvfx/svg2ir';
|
|
|
58
58
|
|
|
59
59
|
const split = splitSVG(svgSource);
|
|
60
60
|
const { data, warnings } = convertSVGToGE(
|
|
61
|
-
|
|
61
|
+
split,
|
|
62
62
|
{ fonts: [{ fontFamily: 'Custom Sans', fontURL: 'https://example.com/fonts/custom-sans.woff2' }] },
|
|
63
|
-
split.preservedData,
|
|
64
63
|
);
|
|
65
64
|
```
|
|
66
65
|
|
|
67
66
|
`convertSVGToGE` uses `@vvfx/ge-ir` to build the base scene. Passing the sidecar enables SVG-specific rich-text,
|
|
68
|
-
paint-animation, and gradient-UV post-processing.
|
|
67
|
+
paint-animation, and gradient-UV post-processing. Passing the `SVGConversionContext` returned by `splitSVG` reuses its
|
|
68
|
+
parsed IR and preserved data without parsing the SVG again. Passing an SVG string keeps source-specific post-processing
|
|
69
|
+
disabled unless `preservedData` is supplied separately. Pass parse options such as `frameRate`, `durationSeconds`, and
|
|
70
|
+
`measureText` to `splitSVG`; options passed to `convertSVGToGE` apply to GE output and diagnostics. Font definitions are
|
|
71
|
+
supplied independently through `fonts`.
|
|
69
72
|
|
|
70
73
|
### SVG to static layers
|
|
71
74
|
|
|
72
75
|
```ts
|
|
73
|
-
import {
|
|
76
|
+
import { convertSVGToLayers } from '@vvfx/svg2ir';
|
|
74
77
|
|
|
75
78
|
const svgSource = '<svg width="400" height="300"><text x="20" y="40" font-size="24">Hello</text></svg>';
|
|
76
|
-
const { size: canvasSize, data: layers, warnings } = await
|
|
79
|
+
const { size: canvasSize, data: layers, warnings } = await convertSVGToLayers(svgSource);
|
|
77
80
|
const json = JSON.stringify(layers);
|
|
78
81
|
|
|
79
82
|
console.info(canvasSize, json, warnings);
|
|
80
83
|
```
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
`convertSVGToLayers` converts Animation IR and SVG preserved text data directly into
|
|
83
86
|
static layers and asynchronously returns `{ size, data, warnings }`.
|
|
84
87
|
`data` is a flat array of image and text layers; `size` is the separate canvas width and height in pixels.
|
|
85
88
|
SVG images become image layers, and native text becomes editable text layers. Text inside images is not recognized.
|
|
@@ -98,14 +101,20 @@ and `foreignObject` are not baked.
|
|
|
98
101
|
Layer format:
|
|
99
102
|
|
|
100
103
|
- Common fields: `id` is generated automatically; `bbox` uses canvas-pixel coordinates
|
|
101
|
-
`[left, top, right, bottom]`.
|
|
104
|
+
`[left, top, right, bottom]`.
|
|
102
105
|
- Image layers: `type: 'image'`, `role: 'content'`, and a Base64 data URL in `url`.
|
|
103
106
|
`size` holds display dimensions before rotation; `rotation` holds XYZ Euler angles in degrees (positive Z is
|
|
104
107
|
clockwise). `width` and `height` are the bbox dimensions.
|
|
105
|
-
|
|
108
|
+
Native image geometry is rounded to two decimal places. Baked geometry follows raster resolution;
|
|
109
|
+
transforms are included in the pixels, with `rotation: [0, 0, 0]`.
|
|
106
110
|
- Text layers: `type: 'text'`, `state: 'active'`, full text in `content`, and `fragments` containing text runs,
|
|
107
111
|
fonts, sizes, colors, and spacing. Fragment `bbox` and `polygon` are relative to the text layer's top-left corner;
|
|
108
112
|
polygon contains the layout corners. Rotation uses degrees and colors use `#RRGGBB`.
|
|
113
|
+
`font_family` contains the family name without enclosing CSS quotes.
|
|
114
|
+
Preserve `font_size` and `letter_spacing` on import.
|
|
115
|
+
Text positions, font sizes, spacing, and rotation retain precision.
|
|
116
|
+
Frame widths use per-code-point measurements at the transformed font size, with spacing only between characters.
|
|
117
|
+
No width padding is added; consumers should preserve this precision when saving and restoring text.
|
|
109
118
|
Native text requires no image erasure, so `erase_operations` is empty.
|
|
110
119
|
|
|
111
120
|
External images are fetched and inlined; browser fetch requires CORS. Supply `loadImage` for local files or
|
|
@@ -117,21 +126,20 @@ authenticated resources and `resourceBaseUrl` for relative image references. Fai
|
|
|
117
126
|
|
|
118
127
|
- `convertSVGToIR(source, options?)` returns `{ ir, warnings }`.
|
|
119
128
|
- `splitSVG(source, options?)` returns `{ ir, warnings, preservedData }`.
|
|
120
|
-
- `convertSVGToGE(
|
|
121
|
-
- `
|
|
122
|
-
`Promise<SVGToLayersResult>` for layers.
|
|
129
|
+
- `convertSVGToGE(sourceOrContext, options?, preservedData?)` returns `{ data, warnings }`.
|
|
130
|
+
- `convertSVGToLayers(source, options?, preservedData?)` returns `Promise<SVGToLayersResult>`.
|
|
123
131
|
- `inferNumericWeightFromFamily(fontFamily)` infers a numeric font weight, or returns `null`.
|
|
124
132
|
|
|
125
133
|
Important options include `frameRate` (default `30`), `durationSeconds` (default `5` for static SVG),
|
|
126
134
|
`backgroundColor`, `resourceBaseUrl`, `imageNaturalSizes`, `measureText`, `strict`, `onWarning`, and the GE-only
|
|
127
135
|
`fonts` list. `resourceBaseUrl` must be absolute when used to resolve relative image references.
|
|
128
|
-
`
|
|
136
|
+
`convertSVGToLayers` accepts a `loadImage` callback:
|
|
129
137
|
`(url) => Promise<{ data: Uint8Array; mimeType: string }>`; `data` contains the original image bytes.
|
|
130
138
|
|
|
131
139
|
The layers-only `rasterScale` option controls PNG resolution without changing display size; it defaults to `2`
|
|
132
140
|
and must be finite and positive. The working raster is limited to 16 megapixels.
|
|
133
141
|
|
|
134
|
-
All public types, including `SVGPreservedData`, `ConvertOptions`, `SVGToGEOptions`, `SVGToLayersOptions`, `SVGStaticLayer`,
|
|
142
|
+
All public types, including `SVGConversionContext`, `SVGPreservedData`, `ConvertOptions`, `SVGToGEOptions`, `SVGToLayersOptions`, `SVGStaticLayer`,
|
|
135
143
|
`SVG2IRWarning`, and result types, are exported from `@vvfx/svg2ir`.
|
|
136
144
|
|
|
137
145
|
## Output
|
|
@@ -143,10 +151,10 @@ convertSVGToIR(source, options?);
|
|
|
143
151
|
splitSVG(source, options?);
|
|
144
152
|
// { ir: IRScene; warnings: SVG2IRWarning[]; preservedData: SVGPreservedData }
|
|
145
153
|
|
|
146
|
-
convertSVGToGE(
|
|
154
|
+
convertSVGToGE(sourceOrContext, options?, preservedData?);
|
|
147
155
|
// { data: JSONScene; warnings: SVG2IRWarning[] }
|
|
148
156
|
|
|
149
|
-
await
|
|
157
|
+
await convertSVGToLayers(source, options?, preservedData?);
|
|
150
158
|
// { size: [number, number]; data: SVGStaticLayer[]; warnings: SVG2IRWarning[] }
|
|
151
159
|
```
|
|
152
160
|
|
|
@@ -199,7 +207,8 @@ Invalid SVG and failed layer image loads throw errors. An empty warning list is
|
|
|
199
207
|
Static layers export supports images and text only. SMIL animation elements are removed with a warning; unsupported animated channels, unbaked shapes, solid backgrounds,
|
|
200
208
|
image skew/reflection/cropping, masks, opacity, nonuniform text scaling, and text paths are skipped with warnings.
|
|
201
209
|
Bold and italic styles are downgraded with warnings; vertical text is split into character layers with horizontal fragments.
|
|
202
|
-
|
|
210
|
+
Load the fonts used by `measureText` before conversion; the callback is synchronous and does not load fonts.
|
|
211
|
+
Incomplete metrics produce estimated bounds and warnings.
|
|
203
212
|
`strict: true` turns unsupported content and style downgrades into errors; estimated bounds still produce warnings.
|
|
204
213
|
|
|
205
214
|
Images are retained when a straight rectangular mask covers the full image without inversion or subtraction.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ConvertResult } from '
|
|
2
|
-
import type { SVGPreservedData } from '
|
|
1
|
+
import { type ConvertResult } from '../../common/types';
|
|
2
|
+
import type { SVGPreservedData } from '../../svg-preserved-data';
|
|
3
3
|
import type { SVGToGEOptions, SVGToGEResult } from './types';
|
|
4
4
|
/** 从已解析的 IR 和 SVG 保留数据生成 GE 场景。 */
|
|
5
5
|
export declare function assembleSVGGE(parsed: ConvertResult, options?: SVGToGEOptions, preservedData?: SVGPreservedData): SVGToGEResult;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SVGSource } from '../../common/types';
|
|
2
|
+
import type { SVGConversionContext } from '../../svg2ir/convert';
|
|
3
|
+
import type { SVGPreservedData } from '../../svg-preserved-data';
|
|
4
|
+
import type { SVGToGEOptions, SVGToGEResult } from './types';
|
|
5
|
+
/** SVG→GE 显式入口。传入 preservedData 时应用 SVG 专属后处理。 */
|
|
6
|
+
export declare function convertSVGToGE(source: SVGSource, options?: SVGToGEOptions, preservedData?: SVGPreservedData): SVGToGEResult;
|
|
7
|
+
export declare function convertSVGToGE(context: SVGConversionContext, options?: SVGToGEOptions, preservedData?: SVGPreservedData): SVGToGEResult;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SVGPreservedShapeAnimation } from '
|
|
1
|
+
import type { SVGPreservedShapeAnimation } from '../../svg-preserved-data';
|
|
2
2
|
export declare function normalizeShapeAnimationForGE(animation: SVGPreservedShapeAnimation): SVGPreservedShapeAnimation | undefined;
|
package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/apply-shape-geometry-animation.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
2
|
import { type JSONScene } from '@galacean/effects-specification';
|
|
3
|
-
import type { SVGPreservedShapeAnimation } from '
|
|
3
|
+
import type { SVGPreservedShapeAnimation } from '../../../svg-preserved-data';
|
|
4
4
|
export declare function applyShapeGeometryAnimations(scene: JSONScene, ir: IRScene, animationsByLayerId: ReadonlyMap<string, SVGPreservedShapeAnimation> | undefined): void;
|
package/dist/{svg2ge-adapter → adapter/svg2ge}/post-process/apply-shape-paint-animation.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
2
|
import { type JSONScene } from '@galacean/effects-specification';
|
|
3
|
-
import type { SVGPreservedPaintAnimation } from '
|
|
3
|
+
import type { SVGPreservedPaintAnimation } from '../../../svg-preserved-data';
|
|
4
4
|
export declare function applyShapePaintAnimation(scene: JSONScene, ir: IRScene, paintAnimationByLayerIndex: ReadonlyMap<string, readonly SVGPreservedPaintAnimation[]>): void;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 文本尺寸字段和 textPath 标记保留在 Effects 场景中。
|
|
4
4
|
*/
|
|
5
5
|
import { type JSONScene } from '@galacean/effects-specification';
|
|
6
|
-
import type { SVGPreservedTextData } from '
|
|
6
|
+
import type { SVGPreservedTextData } from '../../../svg-preserved-data';
|
|
7
7
|
interface RewriteTextComponentsToRichTextInput {
|
|
8
8
|
textDataByLayerId: ReadonlyMap<string, SVGPreservedTextData>;
|
|
9
9
|
itemLayerIds: Readonly<Record<string, string>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
|
-
import type { SVGPreservedPaintAnimation, SVGPreservedShapeAnimation } from '
|
|
2
|
+
import type { SVGPreservedPaintAnimation, SVGPreservedShapeAnimation } from '../../svg-preserved-data';
|
|
3
3
|
export declare function applyShapeAnimationBasePaths(ir: IRScene, animationsByLayerId: ReadonlyMap<string, SVGPreservedShapeAnimation> | undefined): void;
|
|
4
4
|
/** convertIRToGE 用 IR 副本展开 hold 过渡点,result.ir 仍保留解析原始关键帧。 */
|
|
5
5
|
export declare function expandIRHoldTransitions(ir: IRScene): IRScene;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JSONScene } from '@galacean/effects-specification';
|
|
2
|
-
import type { ConvertOptions, SVG2IRWarning } from '
|
|
3
|
-
import type { SVGFontDefinition } from '
|
|
2
|
+
import type { ConvertOptions, SVG2IRWarning } from '../../common/types';
|
|
3
|
+
import type { SVGFontDefinition } from '../../svg-preserved-data';
|
|
4
4
|
export interface SVGToGEOptions extends ConvertOptions {
|
|
5
5
|
fonts?: readonly SVGFontDefinition[];
|
|
6
6
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
|
-
import { type ConvertOptions, type SVG2IRWarning } from '
|
|
3
|
-
import type { SVGPreservedData } from '
|
|
2
|
+
import { type ConvertOptions, type SVG2IRWarning } from '../../common/types';
|
|
3
|
+
import type { SVGPreservedData } from '../../svg-preserved-data';
|
|
4
|
+
import type { SVGConversionContext } from '../../svg2ir/convert';
|
|
4
5
|
import type { BakedLayersResult } from './baking/build-baked-layers';
|
|
5
6
|
import type { SVGStaticLayer, SVGToLayersResult } from './types';
|
|
6
7
|
export declare function assembleSVGStaticLayers(scene: IRScene, options: ConvertOptions, warnings: SVG2IRWarning[], preservedData?: SVGPreservedData, sourceIds?: Map<SVGStaticLayer, string>): {
|
|
7
8
|
size: [number, number];
|
|
8
9
|
data: SVGStaticLayer[];
|
|
9
10
|
};
|
|
10
|
-
interface
|
|
11
|
-
|
|
12
|
-
options: ConvertOptions;
|
|
13
|
-
warnings: SVG2IRWarning[];
|
|
14
|
-
preservedData: SVGPreservedData;
|
|
11
|
+
export interface SVGStaticLayerConversionContext extends SVGConversionContext {
|
|
12
|
+
source: string;
|
|
15
13
|
layerSources: ReadonlyMap<string, string>;
|
|
16
14
|
warningSources: ReadonlyMap<SVG2IRWarning, string>;
|
|
15
|
+
}
|
|
16
|
+
interface SVGLayerAssemblyInput {
|
|
17
|
+
context: SVGStaticLayerConversionContext;
|
|
18
|
+
options: ConvertOptions;
|
|
17
19
|
baking: BakedLayersResult;
|
|
18
20
|
}
|
|
19
21
|
/** Replace baked sources, combine native and raster layers in painter order, then report final diagnostics. */
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SVGSource } from '../../common/types';
|
|
2
|
+
import type { SVGPreservedData } from '../../svg-preserved-data';
|
|
3
|
+
import type { SVGToLayersOptions, SVGToLayersResult } from './types';
|
|
4
|
+
export declare function convertSVGToLayers(source: SVGSource, options?: SVGToLayersOptions, preservedData?: SVGPreservedData): Promise<SVGToLayersResult>;
|
package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/diagnostics/collect-warnings.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRLayer } from '@vvfx/animation-ir';
|
|
2
|
-
import { type ConvertOptions, type SVG2IRWarning, type SVG2IRWarningCode } from '
|
|
2
|
+
import { type ConvertOptions, type SVG2IRWarning, type SVG2IRWarningCode } from '../../../../common/types';
|
|
3
3
|
export declare class LayerConversionError extends Error {
|
|
4
4
|
readonly code: SVG2IRWarningCode;
|
|
5
5
|
constructor(code: SVG2IRWarningCode, message: string);
|
package/dist/{svg2layers-adapter → adapter/svg2layers}/converter/layers/conversion-session.d.ts
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IRAsset, IRComposition, IRLayer, IRScene } from '@vvfx/animation-ir';
|
|
2
|
-
import type { ConvertOptions, SVG2IRWarning } from '
|
|
3
|
-
import type { SVGPreservedData } from '
|
|
2
|
+
import type { ConvertOptions, SVG2IRWarning } from '../../../../common/types';
|
|
3
|
+
import type { SVGPreservedData } from '../../../../svg-preserved-data';
|
|
4
4
|
import { type StaticLayerState } from '../transform/build-transform';
|
|
5
5
|
export interface LayerConversionSession {
|
|
6
6
|
readonly composition: IRComposition;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IRFontAsset, IRTextLayer } from '@vvfx/animation-ir';
|
|
2
|
-
import type { SVGPreservedTextData } from '
|
|
2
|
+
import type { SVGPreservedTextData } from '../../../../svg-preserved-data';
|
|
3
3
|
export interface TextRun {
|
|
4
4
|
text: string;
|
|
5
5
|
fontSize: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IRTextContent } from '@vvfx/animation-ir';
|
|
2
|
-
import { type ConvertOptions, type SVG2IRWarning } from '
|
|
2
|
+
import { type ConvertOptions, type SVG2IRWarning } from '../../../../common/types';
|
|
3
3
|
import type { SVGLayerBBox } from '../../types';
|
|
4
4
|
import type { TextRun } from './parse-text-runs';
|
|
5
5
|
export interface PositionedTextRun {
|
|
6
6
|
run: TextRun;
|
|
7
7
|
box: SVGLayerBBox;
|
|
8
8
|
}
|
|
9
|
-
export declare function buildTextRunLayout(runs: TextRun[], family: string, spacing: number, content: IRTextContent, size: [number, number], conversionOptions: ConvertOptions, warnings: SVG2IRWarning[], id: string, segmented?: boolean): PositionedTextRun[];
|
|
9
|
+
export declare function buildTextRunLayout(runs: TextRun[], family: string, spacing: number, content: IRTextContent, size: [number, number], conversionOptions: ConvertOptions, warnings: SVG2IRWarning[], id: string, segmented?: boolean, renderScale?: readonly [number, number]): PositionedTextRun[];
|
|
@@ -12,5 +12,5 @@ export declare const IDENTITY_MATRIX: LayerMatrix;
|
|
|
12
12
|
export declare function multiplyMatrices(parent: LayerMatrix, local: LayerMatrix): LayerMatrix;
|
|
13
13
|
export declare function transformPoint(matrix: LayerMatrix, x: number, y: number): LayerPoint;
|
|
14
14
|
export declare function transformBoxCorners(matrix: LayerMatrix, box: SVGLayerBBox): LayerPoint[];
|
|
15
|
-
export declare function mapPointsToBBox(points: readonly LayerPoint[]): SVGLayerBBox;
|
|
15
|
+
export declare function mapPointsToBBox(points: readonly LayerPoint[], roundCoordinates?: boolean): SVGLayerBBox;
|
|
16
16
|
export declare function roundPixel(value: number): number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SVG2IRWarning } from '
|
|
1
|
+
import type { ConvertOptions, SVG2IRWarning } from '../../common/types';
|
|
2
2
|
/** 图片读取结果;data 为原始文件字节,不是 Base64 字符串。 */
|
|
3
3
|
export interface SVGImageResource {
|
|
4
4
|
data: Uint8Array;
|
|
@@ -6,6 +6,12 @@ export interface SVGImageResource {
|
|
|
6
6
|
}
|
|
7
7
|
/** 读取外链、本地文件或需要鉴权的图片资源。 */
|
|
8
8
|
export type SVGImageResourceLoader = (url: string) => Promise<SVGImageResource>;
|
|
9
|
+
export interface SVGToLayersOptions extends ConvertOptions {
|
|
10
|
+
/** 外链图片读取回调,默认使用 fetch。 */
|
|
11
|
+
loadImage?: SVGImageResourceLoader;
|
|
12
|
+
/** 烘焙分辨率倍数,默认 2,不改变显示尺寸。 */
|
|
13
|
+
rasterScale?: number;
|
|
14
|
+
}
|
|
9
15
|
/** 像素边界:[左、上、右、下]。 */
|
|
10
16
|
export type SVGLayerBBox = [number, number, number, number];
|
|
11
17
|
export interface SVGImageLayer {
|
|
@@ -30,6 +36,7 @@ export interface SVGTextFragment {
|
|
|
30
36
|
bbox: SVGLayerBBox;
|
|
31
37
|
/** 相对文字层的布局四边形,依次为变换前的左上、右上、右下、左下角;不是字形轮廓。 */
|
|
32
38
|
polygon: Array<[number, number]> | null;
|
|
39
|
+
/** 字体名,不含 CSS 外层引号。 */
|
|
33
40
|
font_family: string;
|
|
34
41
|
font_size: number;
|
|
35
42
|
color: string;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface ConvertOptions {
|
|
|
13
13
|
strict?: boolean;
|
|
14
14
|
/** warning 回调:每条 warning 会先进入 ConvertResult.warnings,再通知调用方。 */
|
|
15
15
|
onWarning?: (warning: SVG2IRWarning) => void;
|
|
16
|
-
/**
|
|
16
|
+
/** 同步文本测量回调,用于计算文字边界;调用转换前需加载测量使用的字体。 */
|
|
17
17
|
measureText?: (fontDesc: string, text: string) => {
|
|
18
18
|
width: number;
|
|
19
19
|
fontBoundingBoxAscent?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
* 根入口提供 SVG→IR、SVG 保留数据拆分及 GE/静态分层输出。
|
|
5
5
|
*/
|
|
6
6
|
export { convertSVGToIR, splitSVG } from './svg2ir/convert';
|
|
7
|
-
export {
|
|
8
|
-
export { convertSVGToGE } from './
|
|
7
|
+
export { convertSVGToLayers } from './adapter/svg2layers/convert';
|
|
8
|
+
export { convertSVGToGE } from './adapter/svg2ge/convert';
|
|
9
9
|
export type { ConvertOptions, ConvertResult, SVG2IRWarning, SVG2IRWarningCode, SVGSource, } from './common/types';
|
|
10
|
-
export type { SplitSVGOptions, SplitSVGResult } from './svg2ir/convert';
|
|
11
|
-
export type { SVGToGEOptions, SVGToGEResult } from './
|
|
12
|
-
export type { SVGConversionOptions, SVGToLayersOptions } from './convert';
|
|
10
|
+
export type { SplitSVGOptions, SplitSVGResult, SVGConversionContext } from './svg2ir/convert';
|
|
11
|
+
export type { SVGToGEOptions, SVGToGEResult } from './adapter/svg2ge/types';
|
|
13
12
|
export type { SVGPreservedData, SVGFontDefinition, SVGPreservedPaintAnimation, SVGPreservedShapeAnimation, SVGPreservedTextData, SVGPreservedTextSpan, } from './svg-preserved-data';
|
|
14
|
-
export type { SVGStaticLayer, SVGImageLayer, SVGTextLayer, SVGTextFragment, SVGLayerBBox, SVGToLayersResult, SVGLayerEraseOperation, SVGImageResource, SVGImageResourceLoader, } from './
|
|
13
|
+
export type { SVGStaticLayer, SVGImageLayer, SVGTextLayer, SVGTextFragment, SVGLayerBBox, SVGToLayersOptions, SVGToLayersResult, SVGLayerEraseOperation, SVGImageResource, SVGImageResourceLoader, } from './adapter/svg2layers/types';
|
|
15
14
|
export { inferNumericWeightFromFamily } from './svg2ir/converter/text/font-metrics';
|