@mce/svg 0.11.4 → 0.12.0
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 +42 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
import { definePlugin } from "mce";
|
|
2
2
|
import { docToSvgString } from "modern-idoc-svg";
|
|
3
|
+
import { svgToPath2DSet } from "modern-path2d";
|
|
3
4
|
function plugin() {
|
|
4
5
|
return definePlugin((editor) => {
|
|
5
6
|
const {
|
|
6
7
|
to,
|
|
7
8
|
fonts
|
|
8
9
|
} = editor;
|
|
10
|
+
const RE = /\.svg$/i;
|
|
9
11
|
return {
|
|
10
12
|
name: "mce:svg",
|
|
13
|
+
loaders: [
|
|
14
|
+
{
|
|
15
|
+
name: "svg",
|
|
16
|
+
accept: ".svg",
|
|
17
|
+
test: (source) => {
|
|
18
|
+
if (source instanceof Blob) {
|
|
19
|
+
if (source.type.startsWith("image/svg+xml")) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (source instanceof File) {
|
|
24
|
+
if (RE.test(source.name)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
},
|
|
30
|
+
load: async (source) => {
|
|
31
|
+
const svg = await source.text();
|
|
32
|
+
const set = svgToPath2DSet(svg);
|
|
33
|
+
const box = set.getBoundingBox();
|
|
34
|
+
return {
|
|
35
|
+
style: {
|
|
36
|
+
width: box?.width ?? 0,
|
|
37
|
+
height: box?.height ?? 0
|
|
38
|
+
},
|
|
39
|
+
shape: {
|
|
40
|
+
viewBox: set.viewBox,
|
|
41
|
+
paths: set.paths.map((p) => {
|
|
42
|
+
return {
|
|
43
|
+
...p.style,
|
|
44
|
+
data: p.toData()
|
|
45
|
+
};
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
fill: "#000"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
],
|
|
11
53
|
exporters: [
|
|
12
54
|
{
|
|
13
55
|
name: "svg",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/svg",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "SVG plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,10 +46,11 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"modern-idoc-svg": "^0.2.0"
|
|
49
|
+
"modern-idoc-svg": "^0.2.0",
|
|
50
|
+
"modern-path2d": "^1.4.11"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"mce": "0.
|
|
53
|
+
"mce": "0.12.0"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"mce": "^0"
|