@mce/svg 0.17.9 → 0.17.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/dist/index.js +57 -68
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,73 +1,62 @@
|
|
|
1
1
|
import { definePlugin } from "mce";
|
|
2
2
|
import { docToSvgString } from "modern-idoc-svg";
|
|
3
3
|
import { svgToPath2DSet } from "modern-path2d";
|
|
4
|
+
//#region src/plugin.ts
|
|
4
5
|
function plugin() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
copyAs: (svgString) => [
|
|
57
|
-
new Blob([svgString], { type: "text/plain" }),
|
|
58
|
-
new Blob([svgString], { type: "image/svg+xml" })
|
|
59
|
-
],
|
|
60
|
-
saveAs: (svgString) => new Blob([svgString], { type: "image/svg+xml" }),
|
|
61
|
-
handle: async (options) => {
|
|
62
|
-
const doc = await to("json", options);
|
|
63
|
-
return await docToSvgString({ ...doc, fonts });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
|
-
});
|
|
6
|
+
return definePlugin((editor) => {
|
|
7
|
+
const { to, fonts } = editor;
|
|
8
|
+
const RE = /\.svg$/i;
|
|
9
|
+
return {
|
|
10
|
+
name: "mce:svg",
|
|
11
|
+
loaders: [{
|
|
12
|
+
name: "svg",
|
|
13
|
+
accept: ".svg",
|
|
14
|
+
test: (source) => {
|
|
15
|
+
if (source instanceof Blob) {
|
|
16
|
+
if (source.type.startsWith("image/svg+xml")) return true;
|
|
17
|
+
}
|
|
18
|
+
if (source instanceof File) {
|
|
19
|
+
if (RE.test(source.name)) return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
},
|
|
23
|
+
load: async (source) => {
|
|
24
|
+
const set = svgToPath2DSet(await source.text());
|
|
25
|
+
const box = set.getBoundingBox();
|
|
26
|
+
return {
|
|
27
|
+
style: {
|
|
28
|
+
width: box?.width ?? 0,
|
|
29
|
+
height: box?.height ?? 0
|
|
30
|
+
},
|
|
31
|
+
shape: {
|
|
32
|
+
viewBox: set.viewBox,
|
|
33
|
+
paths: set.paths.map((p) => {
|
|
34
|
+
return {
|
|
35
|
+
...p.style,
|
|
36
|
+
data: p.toData()
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
fill: "#000"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}],
|
|
44
|
+
exporters: [{
|
|
45
|
+
name: "svg",
|
|
46
|
+
copyAs: (svgString) => [new Blob([svgString], { type: "text/plain" }), new Blob([svgString], { type: "image/svg+xml" })],
|
|
47
|
+
saveAs: (svgString) => new Blob([svgString], { type: "image/svg+xml" }),
|
|
48
|
+
handle: async (options) => {
|
|
49
|
+
return await docToSvgString({
|
|
50
|
+
...await to("json", options),
|
|
51
|
+
fonts
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}]
|
|
55
|
+
};
|
|
56
|
+
});
|
|
69
57
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/index.ts
|
|
60
|
+
var src_default = plugin;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { src_default as default, plugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/svg",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.12",
|
|
5
5
|
"description": "SVG plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"modern-path2d": "^1.4.16"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"mce": "0.17.
|
|
53
|
+
"mce": "0.17.12"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"mce": "^0"
|