@fulate/import 1.0.15 → 2.0.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 +31 -23
- package/dist/fulate/codec.d.ts +32 -0
- package/dist/fulate/index.d.ts +13 -13
- package/dist/fulate/upgrade.d.ts +3 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +373 -174
- package/dist/sketch/converter.d.ts +1 -1
- package/dist/sketch/index.d.ts +3 -2
- package/dist/util/index.d.ts +2 -2
- package/package.json +28 -28
package/README.md
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
# `@fulate/import`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
owner。
|
|
3
|
+
当前文件与剪贴板共用 v2 canonical payload 和同一张 codec map。Scene codec 递归装配 children,
|
|
4
|
+
element codec 只编码和创建自身。长期合同见 [Path/Line 规范](../../docs/specs/path-line-core.md#71-file-与-clipboard-v2)。
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## 文件与自定义类型
|
|
8
7
|
|
|
9
8
|
```ts
|
|
10
9
|
import {
|
|
11
|
-
serializeSceneToJSON,
|
|
12
|
-
parseFileData,
|
|
13
|
-
restoreScene
|
|
10
|
+
elementV2Codecs, serializeSceneToJSON, parseFileData, restoreScene
|
|
14
11
|
} from "@fulate/import";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
import { vueShapeV2Codec } from "@fulate/vue";
|
|
13
|
+
import { eChartsV2Codec } from "@fulate/echart";
|
|
14
|
+
import { Select } from "@fulate/tools";
|
|
15
|
+
|
|
16
|
+
const codecs = new Map([
|
|
17
|
+
...elementV2Codecs,
|
|
18
|
+
["vue-component", vueShapeV2Codec],
|
|
19
|
+
["echarts", eChartsV2Codec]
|
|
20
|
+
]);
|
|
21
|
+
const select = new Select({ codecs });
|
|
22
|
+
const json = serializeSceneToJSON(root, codecs);
|
|
23
|
+
restoreScene(root, parseFileData(json), codecs);
|
|
19
24
|
```
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
`
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`parseFileData()` 只执行 JSON parse;声明格式错误和 restore 错误直接传播。History 属于应用组合层,
|
|
26
|
-
成功恢复场景后由拥有 Select 的应用决定是否清空。
|
|
26
|
+
Map key 必须精确等于 DTO `type`。扩展提供 `ElementV2Codec.encode(element)` 与
|
|
27
|
+
`decode(payload)`;codec 不递归 children。按需要覆写 `getPersistentChildren()`,例如不保存组件运行时子树。
|
|
28
|
+
`encodeElement(element, codecs)` 返回独立递归 DTO;`decodeElement(data, codecs)` 按引用采用 canonical
|
|
29
|
+
payload、保留 key 与局部 IDs。Line 保存 `geometry` union;Polygon/VectorPath 保存 canonical records。
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
`serializeScene()` 保存 Root 配置及元素树;文件 marker 为 `__fulate_file__`,`version` 为 `2.1`。
|
|
32
|
+
`exportToFile(root, codecs, filename?, filter?)` 与 `importFromFile(root, codecs, filter?)` 提供浏览器文件入口。
|
|
33
|
+
取消选择文件或等待读取期间 Root 卸载时返回 `false`;未激活的 Root 仍可恢复。
|
|
34
|
+
`parseFileData()` 只执行 JSON parse,错误原样传播;`restoreScene()` 在版本不是 `2.1` 时先转换旧字段,
|
|
35
|
+
再使用同一 codec 恢复。输入文件数据按引用移交,转换会原位更新字段和版本;再次保存得到 `2.1`。
|
|
36
|
+
具体转换范围见上述格式规范;History 的清理由应用组合层决定。
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
`vectorPath` 的内建 v2 codec 创建 UI `EditorVectorPath`,恢复后可继续选择、Point 编辑与缩放。
|
|
39
|
+
`polygon` 创建 UI `Polygon`;两者的 `path` 都保存 Core `VectorPathGeometry`,按原局部 ID 恢复。
|
|
32
40
|
|
|
33
41
|
## Sketch
|
|
34
42
|
|
|
35
|
-
`importSketch(file)`
|
|
36
|
-
`importSketchFile(root,
|
|
37
|
-
|
|
43
|
+
`importSketch(file)` 返回 `{ fileData, images, warnings }`;
|
|
44
|
+
`importSketchFile(root, codecs, filter?)` 选择文件并恢复。Adapter 一次生成 canonical v2 geometry,
|
|
45
|
+
保留 compound Bézier/winding、two-point curve、mask chain 与 warnings;不需要另一套 Fulate reader。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Element, type ElementPayload } from "@fulate/core";
|
|
2
|
+
import { type LineGeometry, type LineEndpointRelationPatch } from "@fulate/ui";
|
|
3
|
+
/** Persisted data contains canonical authored values, never creation intents. */
|
|
4
|
+
export interface ElementV2 extends ElementPayload {
|
|
5
|
+
children?: ElementV2[];
|
|
6
|
+
}
|
|
7
|
+
export interface LineV2 extends ElementPayload {
|
|
8
|
+
readonly type: "line";
|
|
9
|
+
geometry: LineGeometry;
|
|
10
|
+
/** Horizontal label fixed at half the effective route length. */
|
|
11
|
+
text?: string;
|
|
12
|
+
relations?: LineEndpointRelationPatch;
|
|
13
|
+
}
|
|
14
|
+
export interface EncodeContext {
|
|
15
|
+
/** Present for copying a subgraph: external relations become free endpoints. */
|
|
16
|
+
readonly sourceKeys: ReadonlySet<string>;
|
|
17
|
+
}
|
|
18
|
+
export interface ElementV2Codec {
|
|
19
|
+
encode(element: Element, context?: EncodeContext): ElementPayload;
|
|
20
|
+
decode(data: ElementPayload, keyMap?: ReadonlyMap<string, string>): Element;
|
|
21
|
+
}
|
|
22
|
+
export type ElementV2Codecs = ReadonlyMap<string, ElementV2Codec>;
|
|
23
|
+
/** Compose extensions with this map at the application boundary; keys are exact DTO types. */
|
|
24
|
+
export declare const elementV2Codecs: ElementV2Codecs;
|
|
25
|
+
/** The sole owner of persistent child recursion. */
|
|
26
|
+
export declare function encodeElement(element: Element, codecs: ElementV2Codecs, context?: EncodeContext): ElementV2;
|
|
27
|
+
export declare function decodeElement(data: ElementV2, codecs: ElementV2Codecs, keyMap?: ReadonlyMap<string, string>): Element;
|
|
28
|
+
/** Adopt a copied DTO graph, generate new element keys, and preserve owner-local IDs. */
|
|
29
|
+
export declare function decodeCopiedElements(data: readonly ElementV2[], codecs: ElementV2Codecs): {
|
|
30
|
+
elements: Element<import("@fulate/core").ElementProperties, import("@fulate/core").BaseElementOption<any>, Partial<Omit<import("@fulate/core").BaseElementOption<any>, "children" | "key">>, Partial<Omit<import("@fulate/core").BaseElementOption<any>, "children" | "key">>>[];
|
|
31
|
+
keyMap: Map<string, string>;
|
|
32
|
+
};
|
package/dist/fulate/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
1
|
+
import type { Root, SkinOptions } from "@fulate/core";
|
|
2
|
+
import { type ElementFilter } from "../util";
|
|
3
|
+
import { type ElementV2, type ElementV2Codecs } from "./codec";
|
|
4
|
+
export * from "./codec";
|
|
3
5
|
export type { ElementFilter };
|
|
4
|
-
export
|
|
5
|
-
export type DeserializeFactories = ReadonlyMap<string, DeserializeFactory> | Readonly<Record<string, DeserializeFactory>>;
|
|
6
|
+
export declare const FULATE_FILE_VERSION = 2.1;
|
|
6
7
|
export interface FileData {
|
|
7
|
-
[key: string]: any;
|
|
8
8
|
__fulate_file__: true;
|
|
9
|
-
|
|
9
|
+
/** Read versions at the file boundary; all current writers emit FULATE_FILE_VERSION. */
|
|
10
|
+
version: number;
|
|
10
11
|
root?: {
|
|
11
12
|
viewport?: {
|
|
12
13
|
x?: number;
|
|
@@ -19,12 +20,11 @@ export interface FileData {
|
|
|
19
20
|
width?: number;
|
|
20
21
|
height?: number;
|
|
21
22
|
};
|
|
22
|
-
children:
|
|
23
|
+
children: ElementV2[];
|
|
23
24
|
}
|
|
24
|
-
export declare function serializeScene(root: Root, filter?: ElementFilter): FileData;
|
|
25
|
-
export declare function serializeSceneToJSON(root: Root, filter?: ElementFilter): string;
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function restoreScene(root: Root, fileData: FileData, filter?: ElementFilter, factories?: DeserializeFactories): void;
|
|
25
|
+
export declare function serializeScene(root: Root, codecs: ElementV2Codecs, filter?: ElementFilter): FileData;
|
|
26
|
+
export declare function serializeSceneToJSON(root: Root, codecs: ElementV2Codecs, filter?: ElementFilter): string;
|
|
27
|
+
export declare function restoreScene(root: Root, data: FileData, codecs: ElementV2Codecs, filter?: ElementFilter): void;
|
|
28
28
|
export declare function parseFileData(json: string): FileData;
|
|
29
|
-
export declare function exportToFile(root: Root, filename?: string, filter?: ElementFilter): void;
|
|
30
|
-
export declare function importFromFile(root: Root,
|
|
29
|
+
export declare function exportToFile(root: Root, codecs: ElementV2Codecs, filename?: string, filter?: ElementFilter): void;
|
|
30
|
+
export declare function importFromFile(root: Root, codecs: ElementV2Codecs, filter?: ElementFilter): Promise<boolean>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type { ImportResult, Importer } from "./types";
|
|
2
2
|
export { importSketch, importSketchFile, SketchImporter } from "./sketch";
|
|
3
|
-
export
|
|
4
|
-
export type {
|
|
5
|
-
export type { ElementFilter, DeserializeFn, RestoreOptions } from "./util";
|
|
3
|
+
export * from "./fulate";
|
|
4
|
+
export type { RestoreOptions } from "./util";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Element, Layer, Shape } from "@fulate/core";
|
|
2
|
-
import { Circle, Group, Image, Line, LineTree, Polygon, Rectangle, RippleOverlay, ScrollView, Text, Triangle,
|
|
1
|
+
import { Element, Layer, Shape, createAuthoredLineSubpath, createVectorPathGeometry, generateNodeKey } from "@fulate/core";
|
|
2
|
+
import { Circle, EditorVectorPath, Group, Image, Line, LineTree, Polygon, Rectangle, RippleOverlay, ScrollView, Text, Triangle, Workspace, createManualLineGeometry, materializeEffectiveEndpointPoints, remapLineTreeRelations } from "@fulate/ui";
|
|
3
3
|
import { loadAsync } from "jszip";
|
|
4
|
-
import {
|
|
4
|
+
import { isNil, isUndefined } from "lodash-es";
|
|
5
5
|
//#region packages/import/src/sketch/parser.ts
|
|
6
6
|
async function parseSketchFile(data) {
|
|
7
7
|
const zip = await loadAsync(data instanceof File ? await data.arrayBuffer() : data);
|
|
@@ -38,6 +38,361 @@ async function readJSON(zip, path) {
|
|
|
38
38
|
return JSON.parse(text);
|
|
39
39
|
}
|
|
40
40
|
//#endregion
|
|
41
|
+
//#region packages/import/src/fulate/codec.ts
|
|
42
|
+
function codec(Constructor) {
|
|
43
|
+
return {
|
|
44
|
+
encode: (element) => element.toJSON(),
|
|
45
|
+
decode: ({ type, ...properties }) => new Constructor(properties)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function encodeLine(element, context) {
|
|
49
|
+
const line = element;
|
|
50
|
+
const data = line.toJSON();
|
|
51
|
+
if (!context || !line.headRelation && !line.tailRelation) return data;
|
|
52
|
+
const vertices = line.getEffectiveLineVerticesView();
|
|
53
|
+
let headPoint, tailPoint;
|
|
54
|
+
const relations = { ...data.relations };
|
|
55
|
+
for (const end of ["head", "tail"]) {
|
|
56
|
+
const relation = line[end === "head" ? "headRelation" : "tailRelation"];
|
|
57
|
+
if (!relation || context.sourceKeys.has(relation.target.elementKey)) continue;
|
|
58
|
+
const point = end === "head" ? vertices[0].point : vertices[vertices.length - 1].point;
|
|
59
|
+
const copied = {
|
|
60
|
+
x: point.x,
|
|
61
|
+
y: point.y
|
|
62
|
+
};
|
|
63
|
+
if (end === "head") headPoint = copied;
|
|
64
|
+
else tailPoint = copied;
|
|
65
|
+
delete relations[end];
|
|
66
|
+
}
|
|
67
|
+
const geometry = materializeEffectiveEndpointPoints(data.geometry, headPoint, tailPoint);
|
|
68
|
+
if (geometry !== data.geometry) Object.assign(data, line.resolvePointGeometryPatch(geometry));
|
|
69
|
+
if (relations.head || relations.tail) data.relations = relations;
|
|
70
|
+
else delete data.relations;
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
var lineCodec = {
|
|
74
|
+
encode: encodeLine,
|
|
75
|
+
decode(data, keyMap) {
|
|
76
|
+
const { type, ...properties } = data;
|
|
77
|
+
if (keyMap && properties.relations) {
|
|
78
|
+
const remap = (relation) => relation && {
|
|
79
|
+
...relation,
|
|
80
|
+
target: {
|
|
81
|
+
...relation.target,
|
|
82
|
+
elementKey: keyMap.get(relation.target.elementKey)
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
properties.relations = {
|
|
86
|
+
head: remap(properties.relations.head),
|
|
87
|
+
tail: remap(properties.relations.tail)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return new Line(properties);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/** Compose extensions with this map at the application boundary; keys are exact DTO types. */
|
|
94
|
+
var elementV2Codecs = new Map([
|
|
95
|
+
["element", codec(Element)],
|
|
96
|
+
["shape", codec(Shape)],
|
|
97
|
+
["layer", codec(Layer)],
|
|
98
|
+
["rectangle", codec(Rectangle)],
|
|
99
|
+
["circle", codec(Circle)],
|
|
100
|
+
["triangle", codec(Triangle)],
|
|
101
|
+
["polygon", codec(Polygon)],
|
|
102
|
+
["vectorPath", codec(EditorVectorPath)],
|
|
103
|
+
["text", codec(Text)],
|
|
104
|
+
["image", codec(Image)],
|
|
105
|
+
["workspace", codec(Workspace)],
|
|
106
|
+
["group", codec(Group)],
|
|
107
|
+
["scrollview", codec(ScrollView)],
|
|
108
|
+
["line", lineCodec],
|
|
109
|
+
["lineTree", {
|
|
110
|
+
encode(element, context) {
|
|
111
|
+
const tree = element;
|
|
112
|
+
const data = tree.toJSON();
|
|
113
|
+
if (context) {
|
|
114
|
+
const topology = data.topology;
|
|
115
|
+
let changed = false;
|
|
116
|
+
const points = topology.points.map((point) => {
|
|
117
|
+
if (!point.relation || context.sourceKeys.has(point.relation.target.elementKey)) return point;
|
|
118
|
+
changed = true;
|
|
119
|
+
const { relation, ...anchor } = point;
|
|
120
|
+
const effective = tree.transform.getResolvedPoint(point.anchorId).point;
|
|
121
|
+
return {
|
|
122
|
+
...anchor,
|
|
123
|
+
point: {
|
|
124
|
+
x: effective.x,
|
|
125
|
+
y: effective.y
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
if (changed) Object.assign(data, tree.resolvePointTopologyPatch({
|
|
130
|
+
...topology,
|
|
131
|
+
points
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
return data;
|
|
135
|
+
},
|
|
136
|
+
decode({ type, ...properties }, keyMap) {
|
|
137
|
+
if (keyMap) properties.topology = remapLineTreeRelations(properties.topology, keyMap);
|
|
138
|
+
return new LineTree(properties);
|
|
139
|
+
}
|
|
140
|
+
}],
|
|
141
|
+
["ripple", codec(RippleOverlay)]
|
|
142
|
+
]);
|
|
143
|
+
/** The sole owner of persistent child recursion. */
|
|
144
|
+
function encodeElement(element, codecs, context) {
|
|
145
|
+
const data = codecs.get(element.type).encode(element, context);
|
|
146
|
+
const children = element.getPersistentChildren();
|
|
147
|
+
if (children.length) data.children = children.map((child) => encodeElement(child, codecs, context));
|
|
148
|
+
return data;
|
|
149
|
+
}
|
|
150
|
+
function decodeElement(data, codecs, keyMap) {
|
|
151
|
+
const { children, ...payload } = data;
|
|
152
|
+
if (keyMap) payload.key = keyMap.get(data.key);
|
|
153
|
+
const element = codecs.get(payload.type).decode(payload, keyMap);
|
|
154
|
+
if (children) element.replaceChildren(...children.map((child) => decodeElement(child, codecs, keyMap)));
|
|
155
|
+
return element;
|
|
156
|
+
}
|
|
157
|
+
/** Adopt a copied DTO graph, generate new element keys, and preserve owner-local IDs. */
|
|
158
|
+
function decodeCopiedElements(data, codecs) {
|
|
159
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
160
|
+
const allocate = (entry) => {
|
|
161
|
+
keyMap.set(entry.key, generateNodeKey());
|
|
162
|
+
entry.children?.forEach(allocate);
|
|
163
|
+
};
|
|
164
|
+
data.forEach(allocate);
|
|
165
|
+
return {
|
|
166
|
+
elements: data.map((entry) => decodeElement(entry, codecs, keyMap)),
|
|
167
|
+
keyMap
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region packages/import/src/util/index.ts
|
|
172
|
+
function defaultAppend(els, root) {
|
|
173
|
+
root.append(...els);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 通用场景恢复模板:
|
|
177
|
+
* 1. 应用 root 配置(resize、viewport、Skin)
|
|
178
|
+
* 2. reset viewport
|
|
179
|
+
* 3. 移除旧元素(由 filter 决定)
|
|
180
|
+
* 4. 反序列化并添加 children(由 append 决定)
|
|
181
|
+
* 5. requestRender
|
|
182
|
+
*/
|
|
183
|
+
function restoreScene$1(options) {
|
|
184
|
+
const { root, fileData, codecs, append, filter } = options;
|
|
185
|
+
const toRemove = filter ? root.children.filter((child) => filter(child)) : [];
|
|
186
|
+
if (fileData.root) {
|
|
187
|
+
const { viewport, skin, width, height } = fileData.root;
|
|
188
|
+
if (skin) {
|
|
189
|
+
const { text, ...paint } = skin;
|
|
190
|
+
Object.assign(root.skin, paint);
|
|
191
|
+
if (text) Object.assign(root.skin.text, text);
|
|
192
|
+
}
|
|
193
|
+
if (!isNil(width) && !isNil(height)) root.resize(width, height);
|
|
194
|
+
if (viewport) root.viewport.restore({
|
|
195
|
+
x: viewport.x ?? 0,
|
|
196
|
+
y: viewport.y ?? 0,
|
|
197
|
+
scale: viewport.scale ?? 1
|
|
198
|
+
});
|
|
199
|
+
else root.viewport.reset();
|
|
200
|
+
} else root.viewport.reset();
|
|
201
|
+
if (toRemove.length) root.removeChild(...toRemove);
|
|
202
|
+
const els = fileData.children.map((data) => decodeElement(data, codecs));
|
|
203
|
+
if (els.length) (append ?? defaultAppend)(els, root);
|
|
204
|
+
root.invalidateAll();
|
|
205
|
+
}
|
|
206
|
+
function pickFile(accept) {
|
|
207
|
+
return new Promise((resolve) => {
|
|
208
|
+
const input = document.createElement("input");
|
|
209
|
+
input.type = "file";
|
|
210
|
+
input.accept = accept;
|
|
211
|
+
input.onchange = () => resolve(input.files?.[0] ?? null);
|
|
212
|
+
input.oncancel = () => resolve(null);
|
|
213
|
+
input.click();
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function arrayBufferToDataURL(buf, mime) {
|
|
217
|
+
const bytes = new Uint8Array(buf);
|
|
218
|
+
let binary = "";
|
|
219
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
220
|
+
return `data:${mime};base64,${btoa(binary)}`;
|
|
221
|
+
}
|
|
222
|
+
function guessMimeType(path) {
|
|
223
|
+
switch (path.split(".").pop()?.toLowerCase()) {
|
|
224
|
+
case "jpg":
|
|
225
|
+
case "jpeg": return "image/jpeg";
|
|
226
|
+
case "png": return "image/png";
|
|
227
|
+
case "gif": return "image/gif";
|
|
228
|
+
case "webp": return "image/webp";
|
|
229
|
+
case "svg": return "image/svg+xml";
|
|
230
|
+
default: return "image/png";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region packages/import/src/fulate/upgrade.ts
|
|
235
|
+
/** Consume the previous file payload before the current codecs create scene owners. */
|
|
236
|
+
function upgradeFileData(data) {
|
|
237
|
+
const elements = /* @__PURE__ */ new Map();
|
|
238
|
+
const previousPortTargets = /* @__PURE__ */ new Set();
|
|
239
|
+
const relation = (target) => {
|
|
240
|
+
previousPortTargets.add(target.elementKey);
|
|
241
|
+
return {
|
|
242
|
+
kind: "endpoint-binding",
|
|
243
|
+
target: {
|
|
244
|
+
elementKey: target.elementKey,
|
|
245
|
+
portId: target.anchorType
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
const relations = (head, tail) => ({
|
|
250
|
+
...head ? { head: relation(head) } : {},
|
|
251
|
+
...tail ? { tail: relation(tail) } : {}
|
|
252
|
+
});
|
|
253
|
+
const visit = (element) => {
|
|
254
|
+
elements.set(element.key, element);
|
|
255
|
+
if (element.anchors !== void 0) {
|
|
256
|
+
const totals = /* @__PURE__ */ new Map();
|
|
257
|
+
const positions = /* @__PURE__ */ new Map();
|
|
258
|
+
for (const { edge } of element.anchors) totals.set(edge, (totals.get(edge) ?? 0) + 1);
|
|
259
|
+
element.ports = element.anchors.length === 0 ? true : element.anchors.map(({ edge, ...port }) => {
|
|
260
|
+
const index = (positions.get(edge) ?? 0) + 1;
|
|
261
|
+
positions.set(edge, index);
|
|
262
|
+
return {
|
|
263
|
+
...port,
|
|
264
|
+
position: {
|
|
265
|
+
edge,
|
|
266
|
+
ratio: index / (totals.get(edge) + 1)
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
delete element.anchors;
|
|
271
|
+
}
|
|
272
|
+
switch (element.type) {
|
|
273
|
+
case "line":
|
|
274
|
+
if (element.linePoints !== void 0) {
|
|
275
|
+
const points = element.linePoints;
|
|
276
|
+
element.geometry = {
|
|
277
|
+
mode: "manual",
|
|
278
|
+
path: createAuthoredLineSubpath(points.map(({ x, y }) => ({
|
|
279
|
+
x,
|
|
280
|
+
y
|
|
281
|
+
})), false)
|
|
282
|
+
};
|
|
283
|
+
const head = points[0]?.anchor;
|
|
284
|
+
const tail = points.length > 1 ? points[points.length - 1].anchor : void 0;
|
|
285
|
+
if (head || tail) element.relations = relations(head, tail);
|
|
286
|
+
delete element.linePoints;
|
|
287
|
+
} else if (element.path !== void 0) {
|
|
288
|
+
element.geometry = {
|
|
289
|
+
mode: "manual",
|
|
290
|
+
path: element.path
|
|
291
|
+
};
|
|
292
|
+
delete element.path;
|
|
293
|
+
}
|
|
294
|
+
if (element.endpoints !== void 0) {
|
|
295
|
+
element.relations = relations(element.endpoints.head, element.endpoints.tail);
|
|
296
|
+
delete element.endpoints;
|
|
297
|
+
}
|
|
298
|
+
if (data.version === 1) {
|
|
299
|
+
element.tailDecoration ??= "arrow";
|
|
300
|
+
element.strokeColor ??= "#333333";
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case "polygon":
|
|
304
|
+
if (element.contour !== void 0) {
|
|
305
|
+
element.path = { subpaths: [element.contour] };
|
|
306
|
+
delete element.contour;
|
|
307
|
+
} else if (element.points !== void 0) {
|
|
308
|
+
element.path = { subpaths: [createAuthoredLineSubpath(element.points, true)] };
|
|
309
|
+
delete element.points;
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
case "vectorPath":
|
|
313
|
+
if (element.commands !== void 0) {
|
|
314
|
+
element.path = createVectorPathGeometry(element.commands);
|
|
315
|
+
delete element.commands;
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
element.children?.forEach(visit);
|
|
320
|
+
};
|
|
321
|
+
data.children.forEach(visit);
|
|
322
|
+
for (const key of previousPortTargets) {
|
|
323
|
+
const target = elements.get(key);
|
|
324
|
+
if (target && target.ports === void 0) target.ports = true;
|
|
325
|
+
}
|
|
326
|
+
const root = data.root;
|
|
327
|
+
if (root?.textDefaults !== void 0) {
|
|
328
|
+
root.skin = {
|
|
329
|
+
...root.skin,
|
|
330
|
+
text: root.textDefaults
|
|
331
|
+
};
|
|
332
|
+
delete root.textDefaults;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region packages/import/src/fulate/index.ts
|
|
337
|
+
var FULATE_FILE_VERSION = 2.1;
|
|
338
|
+
function serializeScene(root, codecs, filter) {
|
|
339
|
+
return {
|
|
340
|
+
__fulate_file__: true,
|
|
341
|
+
version: FULATE_FILE_VERSION,
|
|
342
|
+
root: root.toJSON(),
|
|
343
|
+
children: root.children.filter((child) => !filter || filter(child)).map((child) => encodeElement(child, codecs))
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function serializeSceneToJSON(root, codecs, filter) {
|
|
347
|
+
return JSON.stringify(serializeScene(root, codecs, filter));
|
|
348
|
+
}
|
|
349
|
+
function restoreScene(root, data, codecs, filter) {
|
|
350
|
+
if (data.version !== 2.1) {
|
|
351
|
+
upgradeFileData(data);
|
|
352
|
+
data.version = FULATE_FILE_VERSION;
|
|
353
|
+
}
|
|
354
|
+
restoreScene$1({
|
|
355
|
+
root,
|
|
356
|
+
fileData: data,
|
|
357
|
+
codecs,
|
|
358
|
+
filter
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function parseFileData(json) {
|
|
362
|
+
return JSON.parse(json);
|
|
363
|
+
}
|
|
364
|
+
function exportToFile(root, codecs, filename = "fulate-design.json", filter) {
|
|
365
|
+
const blob = new Blob([serializeSceneToJSON(root, codecs, filter)], { type: "application/json" });
|
|
366
|
+
const url = URL.createObjectURL(blob);
|
|
367
|
+
const anchor = document.createElement("a");
|
|
368
|
+
anchor.href = url;
|
|
369
|
+
anchor.download = filename;
|
|
370
|
+
anchor.click();
|
|
371
|
+
URL.revokeObjectURL(url);
|
|
372
|
+
}
|
|
373
|
+
async function importFromFile(root, codecs, filter) {
|
|
374
|
+
const file = await pickFile(".json");
|
|
375
|
+
if (!file) return false;
|
|
376
|
+
const data = parseFileData(await file.text());
|
|
377
|
+
if (root.isUnmounted) return false;
|
|
378
|
+
restoreScene(root, data, codecs, filter);
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region packages/import/src/sketch/image.ts
|
|
383
|
+
/**
|
|
384
|
+
* Extract the image ref path from a bitmap layer and resolve it
|
|
385
|
+
* to a data URL using the images extracted from the zip.
|
|
386
|
+
*/
|
|
387
|
+
function resolveImageSrc(layer, images) {
|
|
388
|
+
const ref = layer.image;
|
|
389
|
+
if (!ref) return void 0;
|
|
390
|
+
const refPath = ref._ref;
|
|
391
|
+
const buf = images.get(refPath);
|
|
392
|
+
if (!buf) return void 0;
|
|
393
|
+
return arrayBufferToDataURL(buf, guessMimeType(refPath));
|
|
394
|
+
}
|
|
395
|
+
//#endregion
|
|
41
396
|
//#region packages/import/src/sketch/style.ts
|
|
42
397
|
function sketchColorToCSS(c) {
|
|
43
398
|
const r = Math.round(c.red * 255);
|
|
@@ -190,82 +545,6 @@ function isItalicFont(name) {
|
|
|
190
545
|
return /italic|oblique/i.test(name);
|
|
191
546
|
}
|
|
192
547
|
//#endregion
|
|
193
|
-
//#region packages/import/src/util/index.ts
|
|
194
|
-
function defaultAppend(els, root) {
|
|
195
|
-
root.append(...els);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 通用场景恢复模板:
|
|
199
|
-
* 1. 应用 root 配置(resize、viewport、Skin)
|
|
200
|
-
* 2. reset viewport
|
|
201
|
-
* 3. 移除旧元素(由 filter 决定)
|
|
202
|
-
* 4. 反序列化并添加 children(由 append 决定)
|
|
203
|
-
* 5. requestRender
|
|
204
|
-
*/
|
|
205
|
-
function restoreScene$1(options) {
|
|
206
|
-
const { root, fileData, deserialize, append, filter } = options;
|
|
207
|
-
const toRemove = filter ? root.children.filter((child) => filter(child)) : [];
|
|
208
|
-
if (fileData.root) {
|
|
209
|
-
const { viewport, skin, width, height } = fileData.root;
|
|
210
|
-
if (skin) {
|
|
211
|
-
const { text, ...paint } = skin;
|
|
212
|
-
Object.assign(root.skin, paint);
|
|
213
|
-
if (text) Object.assign(root.skin.text, text);
|
|
214
|
-
}
|
|
215
|
-
if (!isNil(width) && !isNil(height)) root.resize(width, height);
|
|
216
|
-
if (viewport) root.viewport.restore({
|
|
217
|
-
x: viewport.x ?? 0,
|
|
218
|
-
y: viewport.y ?? 0,
|
|
219
|
-
scale: viewport.scale ?? 1
|
|
220
|
-
});
|
|
221
|
-
else root.viewport.reset();
|
|
222
|
-
} else root.viewport.reset();
|
|
223
|
-
if (toRemove.length) root.removeChild(...toRemove);
|
|
224
|
-
const els = fileData.children.map((data) => deserialize(data));
|
|
225
|
-
if (els.length) (append ?? defaultAppend)(els, root);
|
|
226
|
-
root.invalidateAll();
|
|
227
|
-
}
|
|
228
|
-
function pickFile(accept) {
|
|
229
|
-
return new Promise((resolve) => {
|
|
230
|
-
const input = document.createElement("input");
|
|
231
|
-
input.type = "file";
|
|
232
|
-
input.accept = accept;
|
|
233
|
-
input.onchange = () => resolve(input.files?.[0] ?? null);
|
|
234
|
-
input.click();
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
function arrayBufferToDataURL(buf, mime) {
|
|
238
|
-
const bytes = new Uint8Array(buf);
|
|
239
|
-
let binary = "";
|
|
240
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
241
|
-
return `data:${mime};base64,${btoa(binary)}`;
|
|
242
|
-
}
|
|
243
|
-
function guessMimeType(path) {
|
|
244
|
-
switch (path.split(".").pop()?.toLowerCase()) {
|
|
245
|
-
case "jpg":
|
|
246
|
-
case "jpeg": return "image/jpeg";
|
|
247
|
-
case "png": return "image/png";
|
|
248
|
-
case "gif": return "image/gif";
|
|
249
|
-
case "webp": return "image/webp";
|
|
250
|
-
case "svg": return "image/svg+xml";
|
|
251
|
-
default: return "image/png";
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region packages/import/src/sketch/image.ts
|
|
256
|
-
/**
|
|
257
|
-
* Extract the image ref path from a bitmap layer and resolve it
|
|
258
|
-
* to a data URL using the images extracted from the zip.
|
|
259
|
-
*/
|
|
260
|
-
function resolveImageSrc(layer, images) {
|
|
261
|
-
const ref = layer.image;
|
|
262
|
-
if (!ref) return void 0;
|
|
263
|
-
const refPath = ref._ref;
|
|
264
|
-
const buf = images.get(refPath);
|
|
265
|
-
if (!buf) return void 0;
|
|
266
|
-
return arrayBufferToDataURL(buf, guessMimeType(refPath));
|
|
267
|
-
}
|
|
268
|
-
//#endregion
|
|
269
548
|
//#region packages/import/src/sketch/converter.ts
|
|
270
549
|
function convertSketchToFileData(sketch) {
|
|
271
550
|
const warnings = [];
|
|
@@ -287,7 +566,7 @@ function convertSketchToFileData(sketch) {
|
|
|
287
566
|
return {
|
|
288
567
|
fileData: {
|
|
289
568
|
__fulate_file__: true,
|
|
290
|
-
version:
|
|
569
|
+
version: FULATE_FILE_VERSION,
|
|
291
570
|
children
|
|
292
571
|
},
|
|
293
572
|
images: imageDataURLs,
|
|
@@ -407,7 +686,7 @@ function flattenLayer(layer, ctx) {
|
|
|
407
686
|
assignLinePath(base, layer);
|
|
408
687
|
break;
|
|
409
688
|
case "polygon":
|
|
410
|
-
|
|
689
|
+
assignPolygonPath(base, layer);
|
|
411
690
|
break;
|
|
412
691
|
case "vectorPath":
|
|
413
692
|
assignVectorPath(base, layer);
|
|
@@ -429,6 +708,7 @@ function buildBase(layer, type, ctx) {
|
|
|
429
708
|
if (ctx.flipV) top = ctx.offsetY + (ctx.groupH - layer.frame.y - layer.frame.height);
|
|
430
709
|
const base = {
|
|
431
710
|
type,
|
|
711
|
+
key: generateNodeKey(),
|
|
432
712
|
left,
|
|
433
713
|
top,
|
|
434
714
|
width: layer.frame.width,
|
|
@@ -512,13 +792,13 @@ function convertShapeGroup(layer, ctx) {
|
|
|
512
792
|
return null;
|
|
513
793
|
}
|
|
514
794
|
const base = buildBase(layer, "vectorPath", ctx);
|
|
515
|
-
base.path = paths.flatMap((path) => createVectorPathCommands(path, (point) => parseShapeGroupPoint(point, path)));
|
|
795
|
+
base.path = createVectorPathGeometry(paths.flatMap((path) => createVectorPathCommands(path, (point) => parseShapeGroupPoint(point, path))));
|
|
516
796
|
applyInheritedFlips(base, ctx);
|
|
517
797
|
return base;
|
|
518
798
|
}
|
|
519
799
|
function assignVectorPath(base, layer) {
|
|
520
800
|
const { width, height } = layer.frame;
|
|
521
|
-
base.path = createVectorPathCommands(layer, (point) => parseSketchPoint(point, width, height));
|
|
801
|
+
base.path = createVectorPathGeometry(createVectorPathCommands(layer, (point) => parseSketchPoint(point, width, height)));
|
|
522
802
|
}
|
|
523
803
|
function createVectorPathCommands(layer, resolvePoint) {
|
|
524
804
|
const points = layer.points;
|
|
@@ -568,11 +848,11 @@ function parseShapeGroupPoint(point, path) {
|
|
|
568
848
|
y: top + y
|
|
569
849
|
};
|
|
570
850
|
}
|
|
571
|
-
function
|
|
851
|
+
function assignPolygonPath(base, layer) {
|
|
572
852
|
const points = layer.points;
|
|
573
853
|
if (!points?.length) return;
|
|
574
854
|
const { width, height } = layer.frame;
|
|
575
|
-
base.
|
|
855
|
+
base.path = { subpaths: [createAuthoredLineSubpath(points.map((p) => parseSketchPoint(p.point, width, height)), true)] };
|
|
576
856
|
}
|
|
577
857
|
function assignLinePath(base, layer) {
|
|
578
858
|
const points = layer.points;
|
|
@@ -594,10 +874,10 @@ function assignLinePath(base, layer) {
|
|
|
594
874
|
const origin = parsed[0];
|
|
595
875
|
base.left += origin.x;
|
|
596
876
|
base.top += origin.y;
|
|
597
|
-
base.
|
|
877
|
+
base.geometry = createManualLineGeometry(parsed.map((p) => ({
|
|
598
878
|
x: p.x - origin.x,
|
|
599
879
|
y: p.y - origin.y
|
|
600
|
-
}));
|
|
880
|
+
})));
|
|
601
881
|
delete base.width;
|
|
602
882
|
delete base.height;
|
|
603
883
|
if (base.borderColor) {
|
|
@@ -612,20 +892,18 @@ function assignLinePath(base, layer) {
|
|
|
612
892
|
}
|
|
613
893
|
function parseSketchPoint(str, frameW, frameH) {
|
|
614
894
|
const match = str.match(/\{([^,]+),\s*([^}]+)\}/);
|
|
615
|
-
if (!match) throw new Error(`Invalid Sketch point: ${str}`);
|
|
616
895
|
const x = parseFloat(match[1]);
|
|
617
896
|
const y = parseFloat(match[2]);
|
|
618
|
-
if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error(`Invalid Sketch point: ${str}`);
|
|
619
897
|
return {
|
|
620
898
|
x: x * frameW,
|
|
621
899
|
y: y * frameH
|
|
622
900
|
};
|
|
623
901
|
}
|
|
624
902
|
function assignImageSrc(base, layer, ctx) {
|
|
625
|
-
const
|
|
903
|
+
const ref = layer.image?._ref;
|
|
904
|
+
const src = (ref && ctx.imageDataURLs.get(ref)) ?? resolveImageSrc(layer, ctx.zipImages);
|
|
626
905
|
if (src) {
|
|
627
906
|
base.src = src;
|
|
628
|
-
const ref = layer.image?._ref;
|
|
629
907
|
if (ref) ctx.imageDataURLs.set(ref, src);
|
|
630
908
|
} else ctx.warnings.push(`[${layer.name}] image resource not found`);
|
|
631
909
|
}
|
|
@@ -639,20 +917,20 @@ var SketchImporter = class {
|
|
|
639
917
|
async function importSketch(file) {
|
|
640
918
|
return convertSketchToFileData(await parseSketchFile(file));
|
|
641
919
|
}
|
|
642
|
-
async function importSketchFile(root,
|
|
920
|
+
async function importSketchFile(root, codecs, filter) {
|
|
643
921
|
const file = await pickFile(".sketch");
|
|
644
922
|
if (!file) return false;
|
|
645
923
|
const result = await importSketch(file);
|
|
924
|
+
if (root.isUnmounted) return false;
|
|
646
925
|
if (result.warnings.length) console.warn("[Sketch Import]", result.warnings);
|
|
647
926
|
restoreScene$1({
|
|
648
927
|
root,
|
|
649
928
|
fileData: result.fileData,
|
|
650
|
-
|
|
929
|
+
codecs,
|
|
651
930
|
filter,
|
|
652
931
|
append: (els, root) => {
|
|
653
932
|
const layer = new Layer();
|
|
654
933
|
const workspace = new Workspace({
|
|
655
|
-
key: "workspace",
|
|
656
934
|
width: 1920,
|
|
657
935
|
height: 1080
|
|
658
936
|
});
|
|
@@ -663,83 +941,4 @@ async function importSketchFile(root, deserialize, filter) {
|
|
|
663
941
|
return true;
|
|
664
942
|
}
|
|
665
943
|
//#endregion
|
|
666
|
-
|
|
667
|
-
var FILE_MARKER = "__fulate_file__";
|
|
668
|
-
var FILE_VERSION = 2;
|
|
669
|
-
var builtInConstructors = {
|
|
670
|
-
element: Element,
|
|
671
|
-
shape: Shape,
|
|
672
|
-
layer: Layer,
|
|
673
|
-
rectangle: Rectangle,
|
|
674
|
-
circle: Circle,
|
|
675
|
-
triangle: Triangle,
|
|
676
|
-
polygon: Polygon,
|
|
677
|
-
vectorPath: VectorPath,
|
|
678
|
-
text: Text,
|
|
679
|
-
image: Image,
|
|
680
|
-
workspace: Workspace,
|
|
681
|
-
group: Group,
|
|
682
|
-
scrollview: ScrollView,
|
|
683
|
-
line: Line,
|
|
684
|
-
lineTree: LineTree,
|
|
685
|
-
ripple: RippleOverlay
|
|
686
|
-
};
|
|
687
|
-
function normalizeType(type) {
|
|
688
|
-
return type.startsWith("f-") ? type.slice(2) : type;
|
|
689
|
-
}
|
|
690
|
-
var builtInFactories = Object.fromEntries(Object.entries(builtInConstructors).map(([type, Constructor]) => [type, (data) => {
|
|
691
|
-
const { type, children, ...options } = data;
|
|
692
|
-
return new Constructor(options);
|
|
693
|
-
}]));
|
|
694
|
-
function resolveFactory(type, factories) {
|
|
695
|
-
const normalized = normalizeType(type);
|
|
696
|
-
let custom;
|
|
697
|
-
if (factories instanceof Map) custom = factories.get(normalized);
|
|
698
|
-
else if (factories && has(factories, [normalized])) custom = factories[normalized];
|
|
699
|
-
return custom ?? builtInFactories[normalized];
|
|
700
|
-
}
|
|
701
|
-
function serializeScene(root, filter) {
|
|
702
|
-
return {
|
|
703
|
-
[FILE_MARKER]: true,
|
|
704
|
-
version: FILE_VERSION,
|
|
705
|
-
root: root.toJSON(),
|
|
706
|
-
children: root.children.filter((child) => !filter || filter(child)).map((child) => child.toJSON())
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
function serializeSceneToJSON(root, filter) {
|
|
710
|
-
return JSON.stringify(serializeScene(root, filter));
|
|
711
|
-
}
|
|
712
|
-
function deserializeElement(data, factories) {
|
|
713
|
-
const element = resolveFactory(data.type, factories)(data);
|
|
714
|
-
if (data.children) element.replaceChildren(...data.children.map((child) => deserializeElement(child, factories)));
|
|
715
|
-
return element;
|
|
716
|
-
}
|
|
717
|
-
function restoreScene(root, fileData, filter, factories) {
|
|
718
|
-
restoreScene$1({
|
|
719
|
-
root,
|
|
720
|
-
fileData,
|
|
721
|
-
deserialize: (data) => deserializeElement(data, factories),
|
|
722
|
-
filter
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
function parseFileData(json) {
|
|
726
|
-
return JSON.parse(json);
|
|
727
|
-
}
|
|
728
|
-
function exportToFile(root, filename = "fulate-design.json", filter) {
|
|
729
|
-
const json = serializeSceneToJSON(root, filter);
|
|
730
|
-
const blob = new Blob([json], { type: "application/json" });
|
|
731
|
-
const url = URL.createObjectURL(blob);
|
|
732
|
-
const anchor = document.createElement("a");
|
|
733
|
-
anchor.href = url;
|
|
734
|
-
anchor.download = filename;
|
|
735
|
-
anchor.click();
|
|
736
|
-
URL.revokeObjectURL(url);
|
|
737
|
-
}
|
|
738
|
-
async function importFromFile(root, filter, factories) {
|
|
739
|
-
const file = await pickFile(".json");
|
|
740
|
-
if (!file) return false;
|
|
741
|
-
restoreScene(root, parseFileData(await file.text()), filter, factories);
|
|
742
|
-
return true;
|
|
743
|
-
}
|
|
744
|
-
//#endregion
|
|
745
|
-
export { SketchImporter, deserializeElement, exportToFile, importFromFile, importSketch, importSketchFile, parseFileData, restoreScene, serializeScene, serializeSceneToJSON };
|
|
944
|
+
export { FULATE_FILE_VERSION, SketchImporter, decodeCopiedElements, decodeElement, elementV2Codecs, encodeElement, exportToFile, importFromFile, importSketch, importSketchFile, parseFileData, restoreScene, serializeScene, serializeSceneToJSON };
|
package/dist/sketch/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Root } from "@fulate/core";
|
|
2
2
|
import type { Importer, ImportResult } from "../types";
|
|
3
|
-
import type { ElementFilter
|
|
3
|
+
import type { ElementFilter } from "../util";
|
|
4
|
+
import type { ElementV2Codecs } from "../fulate/codec";
|
|
4
5
|
export declare class SketchImporter implements Importer {
|
|
5
6
|
import(file: File | ArrayBuffer): Promise<ImportResult>;
|
|
6
7
|
}
|
|
7
8
|
export declare function importSketch(file: File | ArrayBuffer): Promise<ImportResult>;
|
|
8
|
-
export declare function importSketchFile(root: Root,
|
|
9
|
+
export declare function importSketchFile(root: Root, codecs: ElementV2Codecs, filter?: ElementFilter): Promise<boolean>;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Root, Element } from "@fulate/core";
|
|
2
2
|
import type { FileData } from "../fulate";
|
|
3
|
+
import { type ElementV2Codecs } from "../fulate/codec";
|
|
3
4
|
export type ElementFilter = (element: Element) => boolean;
|
|
4
|
-
export type DeserializeFn = (data: any) => Element;
|
|
5
5
|
export interface RestoreOptions {
|
|
6
6
|
root: Root;
|
|
7
7
|
fileData: FileData;
|
|
8
|
-
|
|
8
|
+
codecs: ElementV2Codecs;
|
|
9
9
|
/** 决定把反序列化后的元素添加到哪里、怎么添加 */
|
|
10
10
|
append?: (els: Element[], root: Root) => void;
|
|
11
11
|
/** 决定清除哪些旧元素,不传则不清除 */
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fulate/import",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"import": "./dist/index.js"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
],
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"scripts": {
|
|
18
|
-
"test": "vitest run --config vitest.config.ts",
|
|
19
|
-
"test:watch": "vitest --config vitest.config.ts"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@fulate/share": "
|
|
23
|
-
"@fulate/core": "
|
|
24
|
-
"@fulate/ui": "
|
|
25
|
-
"jszip": "^3.10.1",
|
|
26
|
-
"lodash-es": "^4.17.22"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fulate/import",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "vitest run --config vitest.config.ts",
|
|
19
|
+
"test:watch": "vitest --config vitest.config.ts"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@fulate/share": "2.0.11",
|
|
23
|
+
"@fulate/core": "2.0.11",
|
|
24
|
+
"@fulate/ui": "2.0.11",
|
|
25
|
+
"jszip": "^3.10.1",
|
|
26
|
+
"lodash-es": "^4.17.22"
|
|
27
|
+
}
|
|
28
|
+
}
|