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