@mce/openxml 0.11.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.d.ts +3 -0
- package/dist/index.js +120 -0
- package/dist/plugin.d.ts +8 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { definePlugin as b } from "mce";
|
|
2
|
+
import { pptxToDoc as x, docToPptx as U } from "modern-openxml";
|
|
3
|
+
function j() {
|
|
4
|
+
return b((r) => {
|
|
5
|
+
const {
|
|
6
|
+
log: e,
|
|
7
|
+
upload: t,
|
|
8
|
+
config: f,
|
|
9
|
+
to: o,
|
|
10
|
+
fonts: s
|
|
11
|
+
} = r, y = /\.pptx$/i;
|
|
12
|
+
return {
|
|
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
|
+
loaders: [
|
|
32
|
+
{
|
|
33
|
+
name: "pptx",
|
|
34
|
+
accept: ".pptx",
|
|
35
|
+
test: (i) => !!(i instanceof Blob && i.type.startsWith("application/vnd.openxmlformats-officedocument.presentationml.presentation") || i instanceof File && y.test(i.name)),
|
|
36
|
+
load: async (i) => {
|
|
37
|
+
const m = await import("modern-openxml/presetShapeDefinitions").then((n) => n.default), p = await x(await i.arrayBuffer(), {
|
|
38
|
+
presetShapeDefinitions: m,
|
|
39
|
+
upload: async (n, a) => {
|
|
40
|
+
const g = a.image;
|
|
41
|
+
let c = d(a.image);
|
|
42
|
+
const u = v(n);
|
|
43
|
+
if (!c) {
|
|
44
|
+
const l = h(u);
|
|
45
|
+
l && (c = d(l));
|
|
46
|
+
}
|
|
47
|
+
return await t(
|
|
48
|
+
new File([u], g, {
|
|
49
|
+
type: c ?? void 0
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
progress: (n, a, g) => {
|
|
54
|
+
e("load pptx progress", `${n}/${a}`, g ? "cached" : "");
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return p.children?.forEach((n, a) => {
|
|
58
|
+
n.name = `Slide ${a + 1}`, n.style ??= {}, n.style.left = 0, n.style.top = Number(n.style.top) + a * f.value.frameGap, n.meta.inEditorIs = "Frame";
|
|
59
|
+
}), p.name = i.name, p.meta.inEditorIs = "Doc", p;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const w = {
|
|
67
|
+
jpeg: "image/jpeg",
|
|
68
|
+
jpg: "image/jpeg",
|
|
69
|
+
png: "image/png",
|
|
70
|
+
webp: "image/webp",
|
|
71
|
+
svg: "image/svg+xml",
|
|
72
|
+
gif: "image/gif",
|
|
73
|
+
bmp: "image/bmp",
|
|
74
|
+
emf: "image/emf",
|
|
75
|
+
wmf: "image/wmf"
|
|
76
|
+
};
|
|
77
|
+
function d(r) {
|
|
78
|
+
const e = r.split("."), t = e[e.length - 1].toLowerCase();
|
|
79
|
+
return t in w ? w[t] : null;
|
|
80
|
+
}
|
|
81
|
+
function v(r) {
|
|
82
|
+
const e = atob(r), t = e.length, f = new ArrayBuffer(t), o = new Uint8Array(f);
|
|
83
|
+
for (let s = 0; s < t; s++)
|
|
84
|
+
o[s] = e.charCodeAt(s);
|
|
85
|
+
return f;
|
|
86
|
+
}
|
|
87
|
+
function h(r) {
|
|
88
|
+
const e = new DataView(r), t = e.byteLength;
|
|
89
|
+
if (t < 4)
|
|
90
|
+
return;
|
|
91
|
+
switch (e.getUint32(0, !1)) {
|
|
92
|
+
case 2303741511:
|
|
93
|
+
return "png";
|
|
94
|
+
case 1195984440:
|
|
95
|
+
if (t >= 6) {
|
|
96
|
+
const o = e.getUint16(4, !1);
|
|
97
|
+
if (o === 14177 || o === 14689)
|
|
98
|
+
return "gif";
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case 1380533830:
|
|
102
|
+
if (t >= 12 && e.getUint32(8, !1) === 1464156752)
|
|
103
|
+
return "webp";
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (e.getUint8(0) === 255 && e.getUint8(1) === 216 && e.getUint8(2) === 255)
|
|
107
|
+
return "jpeg";
|
|
108
|
+
if (e.getUint8(0) === 66 && e.getUint8(1) === 77)
|
|
109
|
+
return "bmp";
|
|
110
|
+
if (t >= 22) {
|
|
111
|
+
if (e.getUint32(0, !0) === 1179469088)
|
|
112
|
+
return "emf";
|
|
113
|
+
if (e.getUint16(0, !0) === 55245 || e.getUint16(6, !0) === 55245)
|
|
114
|
+
return "wmf";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
j as default,
|
|
119
|
+
j as plugin
|
|
120
|
+
};
|
package/dist/plugin.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mce/openxml",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.11.0",
|
|
5
|
+
"description": "Openxml plugin for mce",
|
|
6
|
+
"author": "wxm",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/qq15725/mce",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/qq15725/mce.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/qq15725/mce/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mce",
|
|
18
|
+
"openxml",
|
|
19
|
+
"plugin"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": true,
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*.mjs": "./*.js",
|
|
29
|
+
"./*": "./*"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"browser": "./dist/index.js",
|
|
34
|
+
"typings": "dist/index.d.ts",
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"*": [
|
|
39
|
+
"*",
|
|
40
|
+
"dist/*",
|
|
41
|
+
"dist/*.d.ts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"modern-openxml": "^1.10.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"mce": "0.11.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"mce": "^0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build:code": "vite build",
|
|
59
|
+
"build:tsc": "NODE_ENV=production tsc --emitDeclarationOnly --project tsconfig.json",
|
|
60
|
+
"build": "pnpm build:code && pnpm build:tsc",
|
|
61
|
+
"lint": "eslint src"
|
|
62
|
+
}
|
|
63
|
+
}
|