@mce/openxml 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 +115 -151
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,162 +1,126 @@
|
|
|
1
1
|
import { definePlugin } from "mce";
|
|
2
2
|
import { docToPptx, pptxToDoc } from "modern-openxml";
|
|
3
|
+
//#region src/plugin.ts
|
|
3
4
|
function plugin() {
|
|
4
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
saveAs: true,
|
|
74
|
-
handle: async (options) => {
|
|
75
|
-
const { pptx: pptxOptions, ...jsonOptions } = options;
|
|
76
|
-
const doc = await to("json", jsonOptions);
|
|
77
|
-
doc.children?.reverse();
|
|
78
|
-
const pptx = await docToPptx({
|
|
79
|
-
...doc,
|
|
80
|
-
fonts,
|
|
81
|
-
meta: {
|
|
82
|
-
...doc.meta,
|
|
83
|
-
...pptxOptions
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return new Blob([pptx], {
|
|
87
|
-
type: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
};
|
|
93
|
-
});
|
|
5
|
+
return definePlugin((editor) => {
|
|
6
|
+
const { log, upload, to, fonts } = editor;
|
|
7
|
+
const RE = /\.pptx$/i;
|
|
8
|
+
return {
|
|
9
|
+
name: "mce:openxml",
|
|
10
|
+
loaders: [{
|
|
11
|
+
name: "pptx",
|
|
12
|
+
accept: ".pptx",
|
|
13
|
+
test: (source) => {
|
|
14
|
+
if (source instanceof Blob) {
|
|
15
|
+
if (source.type.startsWith("application/vnd.openxmlformats-officedocument.presentationml.presentation")) return true;
|
|
16
|
+
}
|
|
17
|
+
if (source instanceof File) {
|
|
18
|
+
if (RE.test(source.name)) return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
},
|
|
22
|
+
load: async (source) => {
|
|
23
|
+
const presetShapeDefinitions = await import("modern-openxml/presetShapeDefinitions").then((rep) => rep.default);
|
|
24
|
+
const doc = await pptxToDoc(await source.arrayBuffer(), {
|
|
25
|
+
presetShapeDefinitions,
|
|
26
|
+
upload: async (input, meta) => {
|
|
27
|
+
const filename = meta.image;
|
|
28
|
+
let mimeType = getMimeType(meta.image);
|
|
29
|
+
const arrayBuffer = base64ToArrayBuffer(input);
|
|
30
|
+
if (!mimeType) {
|
|
31
|
+
const ext = detectImageExt(arrayBuffer);
|
|
32
|
+
if (ext) mimeType = getMimeType(ext);
|
|
33
|
+
}
|
|
34
|
+
return await upload(new File([arrayBuffer], filename, { type: mimeType ?? void 0 }));
|
|
35
|
+
},
|
|
36
|
+
progress: (current, total, cached) => {
|
|
37
|
+
log("load pptx progress", `${current}/${total}`, cached ? "cached" : "");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
doc.children?.forEach((child, index) => {
|
|
41
|
+
child.name = `Slide ${index + 1}`;
|
|
42
|
+
child.style ??= {};
|
|
43
|
+
child.style.left = 0;
|
|
44
|
+
child.style.top = Number(child.style.top);
|
|
45
|
+
child.style.overflow = "hidden";
|
|
46
|
+
child.meta.inEditorIs = "Frame";
|
|
47
|
+
});
|
|
48
|
+
doc.children.reverse();
|
|
49
|
+
doc.name = source.name;
|
|
50
|
+
doc.meta.inEditorIs = "Doc";
|
|
51
|
+
return doc;
|
|
52
|
+
}
|
|
53
|
+
}],
|
|
54
|
+
exporters: [{
|
|
55
|
+
name: "pptx",
|
|
56
|
+
saveAs: true,
|
|
57
|
+
handle: async (options) => {
|
|
58
|
+
const { pptx: pptxOptions, ...jsonOptions } = options;
|
|
59
|
+
const doc = await to("json", jsonOptions);
|
|
60
|
+
doc.children?.reverse();
|
|
61
|
+
const pptx = await docToPptx({
|
|
62
|
+
...doc,
|
|
63
|
+
fonts,
|
|
64
|
+
meta: {
|
|
65
|
+
...doc.meta,
|
|
66
|
+
...pptxOptions
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return new Blob([pptx], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" });
|
|
70
|
+
}
|
|
71
|
+
}]
|
|
72
|
+
};
|
|
73
|
+
});
|
|
94
74
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
75
|
+
var EXT_TO_MIMES = {
|
|
76
|
+
jpeg: "image/jpeg",
|
|
77
|
+
jpg: "image/jpeg",
|
|
78
|
+
png: "image/png",
|
|
79
|
+
webp: "image/webp",
|
|
80
|
+
svg: "image/svg+xml",
|
|
81
|
+
gif: "image/gif",
|
|
82
|
+
bmp: "image/bmp",
|
|
83
|
+
emf: "image/emf",
|
|
84
|
+
wmf: "image/wmf"
|
|
105
85
|
};
|
|
106
86
|
function getMimeType(filename) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
87
|
+
const arr = filename.split(".");
|
|
88
|
+
const ext = arr[arr.length - 1].toLowerCase();
|
|
89
|
+
return ext in EXT_TO_MIMES ? EXT_TO_MIMES[ext] : null;
|
|
110
90
|
}
|
|
111
91
|
function base64ToArrayBuffer(base64) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
return buffer;
|
|
92
|
+
const binaryString = atob(base64);
|
|
93
|
+
const length = binaryString.length;
|
|
94
|
+
const buffer = new ArrayBuffer(length);
|
|
95
|
+
const uint8Array = new Uint8Array(buffer);
|
|
96
|
+
for (let i = 0; i < length; i++) uint8Array[i] = binaryString.charCodeAt(i);
|
|
97
|
+
return buffer;
|
|
120
98
|
}
|
|
121
99
|
function detectImageExt(buffer) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
if (view.getUint8(0) === 255 && view.getUint8(1) === 216 && view.getUint8(2) === 255) {
|
|
145
|
-
return "jpeg";
|
|
146
|
-
}
|
|
147
|
-
if (view.getUint8(0) === 66 && view.getUint8(1) === 77) {
|
|
148
|
-
return "bmp";
|
|
149
|
-
}
|
|
150
|
-
if (len >= 22) {
|
|
151
|
-
if (view.getUint32(0, true) === 1179469088) {
|
|
152
|
-
return "emf";
|
|
153
|
-
} else if (view.getUint16(0, true) === 55245 || view.getUint16(6, true) === 55245) {
|
|
154
|
-
return "wmf";
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return void 0;
|
|
100
|
+
const view = new DataView(buffer);
|
|
101
|
+
const len = view.byteLength;
|
|
102
|
+
if (len < 4) return void 0;
|
|
103
|
+
switch (view.getUint32(0, false)) {
|
|
104
|
+
case 2303741511: return "png";
|
|
105
|
+
case 1195984440:
|
|
106
|
+
if (len >= 6) {
|
|
107
|
+
const version = view.getUint16(4, false);
|
|
108
|
+
if (version === 14177 || version === 14689) return "gif";
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case 1380533830:
|
|
112
|
+
if (len >= 12 && view.getUint32(8, false) === 1464156752) return "webp";
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (view.getUint8(0) === 255 && view.getUint8(1) === 216 && view.getUint8(2) === 255) return "jpeg";
|
|
116
|
+
if (view.getUint8(0) === 66 && view.getUint8(1) === 77) return "bmp";
|
|
117
|
+
if (len >= 22) {
|
|
118
|
+
if (view.getUint32(0, true) === 1179469088) return "emf";
|
|
119
|
+
else if (view.getUint16(0, true) === 55245 || view.getUint16(6, true) === 55245) return "wmf";
|
|
120
|
+
}
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/index.ts
|
|
124
|
+
var src_default = plugin;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { src_default as default, plugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mce/openxml",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.17.
|
|
4
|
+
"version": "0.17.12",
|
|
5
5
|
"description": "Openxml plugin for mce",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"modern-openxml": "^1.10.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"mce": "0.17.
|
|
52
|
+
"mce": "0.17.12"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"mce": "^0"
|