@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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface SVGSnapshotContext {
|
|
2
|
+
root: Element;
|
|
3
|
+
target: Element;
|
|
4
|
+
elements: readonly Element[];
|
|
5
|
+
dependencies: ReadonlySet<Element>;
|
|
6
|
+
readStyle: (element: Element) => CSSStyleDeclaration;
|
|
7
|
+
}
|
|
8
|
+
/** Preserve selector context until styles are frozen, then isolate the requested paint subtree. */
|
|
9
|
+
export declare function prepareSVGSnapshot(source: string, path: string, size: [number, number], inspect?: (context: SVGSnapshotContext) => void): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SVGSnapshotContext } from './prepare-snapshot';
|
|
2
|
+
interface RasterizedSVG {
|
|
3
|
+
url: string;
|
|
4
|
+
/** Logical viewport pixels, independent of raster resolution. */
|
|
5
|
+
bbox: [number, number, number, number];
|
|
6
|
+
}
|
|
7
|
+
/** Render an SVG subtree as a cropped PNG, or return null if it has no visible pixels. */
|
|
8
|
+
export declare function rasterizeSVG(source: string, path: string, size: [number, number], scale?: number, inspect?: (context: SVGSnapshotContext) => void): Promise<RasterizedSVG | null>;
|
|
9
|
+
/** No DOM access at module initialization: the Node entry also imports this module. */
|
|
10
|
+
export declare function canRasterizeSVG(): boolean;
|
|
11
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type IRScene } from '@vvfx/animation-ir';
|
|
2
|
-
import type { ConvertOptions } from '../common/types';
|
|
2
|
+
import type { ConvertOptions, SVG2IRWarning } from '../common/types';
|
|
3
3
|
import type { SVGPreservedPaintAnimation, SVGPreservedShapeAnimation, SVGPreservedTextData } from '../svg-preserved-data';
|
|
4
4
|
export interface ParseSVGToIROptions extends ConvertOptions {
|
|
5
|
+
layerSourceCollector?: Map<string, string>;
|
|
6
|
+
warningSourceCollector?: Map<SVG2IRWarning, string>;
|
|
5
7
|
textDataCollector?: Map<string, SVGPreservedTextData>;
|
|
6
8
|
paintAnimationsCollector?: Map<string, SVGPreservedPaintAnimation[]>;
|
|
7
9
|
shapeAnimationCollector?: Map<string, SVGPreservedShapeAnimation>;
|
package/dist/svg2ir/convert.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { ConvertOptions, ConvertResult, SVGSource } from '../common/types';
|
|
1
|
+
import type { ConvertOptions, ConvertResult, SVG2IRWarning, SVGSource } from '../common/types';
|
|
2
2
|
import type { SVGPreservedData, SVGPreservedPaintAnimation, SVGPreservedShapeAnimation, SVGPreservedTextData } from '../svg-preserved-data';
|
|
3
3
|
interface SVGPreservedDataCollectors {
|
|
4
|
+
layerSourceCollector?: Map<string, string>;
|
|
5
|
+
warningSourceCollector?: Map<SVG2IRWarning, string>;
|
|
4
6
|
textDataByLayerId: Map<string, SVGPreservedTextData>;
|
|
5
7
|
paintAnimationsByLayerId: Map<string, SVGPreservedPaintAnimation[]>;
|
|
6
8
|
shapeAnimationsByLayerId: Map<string, SVGPreservedShapeAnimation>;
|
|
@@ -5,6 +5,8 @@ import type { SVG2IRWarning } from '../../../common/types';
|
|
|
5
5
|
import type { SVGPreservedPaintAnimation, SVGPreservedShapeAnimation, SVGPreservedTextData } from '../../../svg-preserved-data';
|
|
6
6
|
/** 构造 layer 转换会话所需的输入。 */
|
|
7
7
|
export interface SVGLayerBuildOptions {
|
|
8
|
+
layerSourceCollector?: Map<string, string>;
|
|
9
|
+
warningSourceCollector?: Map<SVG2IRWarning, string>;
|
|
8
10
|
frameRate: number;
|
|
9
11
|
durationSeconds: number;
|
|
10
12
|
emit: (warning: SVG2IRWarning) => void;
|
|
@@ -44,6 +44,8 @@ export declare function greedySpaceForDx(target: number, table: Array<{
|
|
|
44
44
|
ch: string;
|
|
45
45
|
w: number;
|
|
46
46
|
}>): string;
|
|
47
|
+
/** 去除单个字体族名的 CSS 字符串引号。 */
|
|
48
|
+
export declare function normalizeFontFamilyName(fontFamily: string): string;
|
|
47
49
|
/** 构造与 Effects Runtime getFontDesc 一致的 CSS font 简写字符串,用于 Canvas measureText。 */
|
|
48
50
|
export declare function buildCanvasFontDesc(fontSize: number, fontFamily: string, fontWeight: IRFontWeight, fontStyle: string): string;
|
|
49
51
|
/** 文本宽度估算。优先使用调用方提供的 Canvas measureText,否则使用字符级启发式系数。 */
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import type { IRScene } from '@vvfx/animation-ir';
|
|
2
2
|
import { type ConvertOptions, type SVG2IRWarning } from '../common/types';
|
|
3
3
|
import type { SVGPreservedData } from '../svg-preserved-data';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
4
|
+
import type { BakedLayersResult } from './baking/build-baked-layers';
|
|
5
|
+
import type { SVGStaticLayer, SVGToLayersResult } from './types';
|
|
6
|
+
export declare function assembleSVGStaticLayers(scene: IRScene, options: ConvertOptions, warnings: SVG2IRWarning[], preservedData?: SVGPreservedData, sourceIds?: Map<SVGStaticLayer, string>): {
|
|
6
7
|
size: [number, number];
|
|
7
8
|
data: SVGStaticLayer[];
|
|
8
9
|
};
|
|
10
|
+
interface SVGLayerAssemblyInput {
|
|
11
|
+
scene: IRScene;
|
|
12
|
+
options: ConvertOptions;
|
|
13
|
+
warnings: SVG2IRWarning[];
|
|
14
|
+
preservedData: SVGPreservedData;
|
|
15
|
+
layerSources: ReadonlyMap<string, string>;
|
|
16
|
+
warningSources: ReadonlyMap<SVG2IRWarning, string>;
|
|
17
|
+
baking: BakedLayersResult;
|
|
18
|
+
}
|
|
19
|
+
/** Replace baked sources, combine native and raster layers in painter order, then report final diagnostics. */
|
|
20
|
+
export declare function assembleSVGLayers(input: SVGLayerAssemblyInput): SVGToLayersResult;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ConvertOptions, type SVG2IRWarning } from '../../common/types';
|
|
2
|
+
import type { SVGImageLayer } from '../types';
|
|
3
|
+
export interface BakedLayersResult {
|
|
4
|
+
layers: Array<{
|
|
5
|
+
path: string;
|
|
6
|
+
layer: SVGImageLayer;
|
|
7
|
+
}>;
|
|
8
|
+
warnings: SVG2IRWarning[];
|
|
9
|
+
replacesSource: (path: string | undefined) => boolean;
|
|
10
|
+
resolvesWarning: (warning: SVG2IRWarning, path: string | undefined) => boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Rasterize graphics and track the source layers and warnings they replace. */
|
|
13
|
+
export declare function buildBakedLayers(source: string, size: [number, number], options: ConvertOptions, rasterScale: number): Promise<BakedLayersResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface BlendDowngrade {
|
|
2
|
+
mode: string;
|
|
3
|
+
selector: string;
|
|
4
|
+
}
|
|
5
|
+
/** Replace non-normal mix-blend-mode declarations with normal and report each downgrade. */
|
|
6
|
+
export declare function normalizeLayerBlending(source: string): {
|
|
7
|
+
source: string;
|
|
8
|
+
downgrades: BlendDowngrade[];
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SVGSnapshotContext } from '../../svg-rasterizer/prepare-snapshot';
|
|
2
|
+
interface GraphicBakeScope {
|
|
3
|
+
path: string;
|
|
4
|
+
selector: string;
|
|
5
|
+
isGroup: boolean;
|
|
6
|
+
}
|
|
7
|
+
interface GraphicBakingPlan {
|
|
8
|
+
scopes: GraphicBakeScope[];
|
|
9
|
+
warnings: Array<{
|
|
10
|
+
message: string;
|
|
11
|
+
selector: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
/** Select graphic-only subtrees; keep native text and images as separate layers. */
|
|
15
|
+
export declare function planGraphicBaking(source: string): GraphicBakingPlan;
|
|
16
|
+
/** Reject text/image dependencies and effects that cannot be rendered independently. */
|
|
17
|
+
export declare function validateGraphicSnapshot(context: SVGSnapshotContext): void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Mask and clipPath definitions do not produce visible layers. */
|
|
2
|
+
export declare function collectNonRenderingDeclarationPaths(source: string): Set<string>;
|
|
3
|
+
/** A stylesheet diagnostic is resolved only when every element it can affect was baked. */
|
|
4
|
+
export declare function collectBakedStylesheetPaths(source: string, isBaked: (path: string) => boolean): Set<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ConvertOptions, type SVGSource } from '../common/types';
|
|
2
2
|
import type { SVGPreservedData } from '../svg-preserved-data';
|
|
3
3
|
import type { SVGImageResourceLoader, SVGToLayersResult } from './types';
|
|
4
|
-
export declare function convertSVGToLayers(source: SVGSource, options: ConvertOptions, loadImage?: SVGImageResourceLoader, preservedData?: SVGPreservedData): Promise<SVGToLayersResult>;
|
|
4
|
+
export declare function convertSVGToLayers(source: SVGSource, options: ConvertOptions, loadImage?: SVGImageResourceLoader, preservedData?: SVGPreservedData, rasterScale?: number): Promise<SVGToLayersResult>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SVGStaticLayer } from '../../types';
|
|
2
2
|
import type { LayerConversionSession } from './conversion-session';
|
|
3
|
-
export declare function buildIRStaticLayers(session: LayerConversionSession): SVGStaticLayer[];
|
|
3
|
+
export declare function buildIRStaticLayers(session: LayerConversionSession, sourceIds?: Map<SVGStaticLayer, string>): SVGStaticLayer[];
|