@mce/svg 0.17.10 → 0.17.13

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.
Files changed (2) hide show
  1. package/dist/index.js +57 -68
  2. 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
- return definePlugin((editor) => {
6
- const {
7
- to,
8
- fonts
9
- } = editor;
10
- const RE = /\.svg$/i;
11
- return {
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
- ],
53
- exporters: [
54
- {
55
- name: "svg",
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
- export {
71
- plugin as default,
72
- plugin
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.10",
4
+ "version": "0.17.13",
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.10"
53
+ "mce": "0.17.13"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "mce": "^0"