pptx-viewer-mcp 2.5.9 → 2.6.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/CHANGELOG.md +6 -0
- package/LICENSE +202 -0
- package/README.md +8 -0
- package/dist/codec/index.d.ts +4 -49
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +7 -357
- package/dist/codec/index.mjs +7 -357
- package/dist/index.d.ts +192 -1277
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -3204
- package/dist/index.mjs +89 -3204
- package/dist/mcp/cli.d.ts +1 -0
- package/dist/mcp/cli.js +2288 -0
- package/dist/mcp/cli.mjs +2286 -0
- package/dist/mcp/index.d.ts +18 -1
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +240 -3313
- package/dist/mcp/index.mjs +239 -3313
- package/dist/types-BUuwyzY-.d.ts +11 -0
- package/dist/types-BUuwyzY-.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/codec/index.mjs
CHANGED
|
@@ -1,361 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Array as Array$1, Map, Text } from 'yjs';
|
|
1
|
+
import { apiCodecPptxCodec } from 'ooxml-core/pptx/automation';
|
|
3
2
|
|
|
4
3
|
// src/codec/pptx-codec.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (style && typeof style === "object" && Object.keys(style).length > 0) {
|
|
12
|
-
a.s = JSON.stringify(style);
|
|
13
|
-
}
|
|
14
|
-
if (seg.isParagraphBreak) {
|
|
15
|
-
a.pb = "1";
|
|
16
|
-
}
|
|
17
|
-
if (seg.isLineBreak) {
|
|
18
|
-
a.lb = "1";
|
|
19
|
-
}
|
|
20
|
-
if (seg.ep === true) {
|
|
21
|
-
a.ep = "1";
|
|
22
|
-
}
|
|
23
|
-
if (seg.bulletInfo) {
|
|
24
|
-
a.bi = JSON.stringify(seg.bulletInfo);
|
|
25
|
-
}
|
|
26
|
-
if (seg.paragraphLevel !== void 0) {
|
|
27
|
-
a.pl = String(seg.paragraphLevel);
|
|
28
|
-
}
|
|
29
|
-
if (seg.endParaRunProperties) {
|
|
30
|
-
a.pr = JSON.stringify(seg.endParaRunProperties);
|
|
31
|
-
}
|
|
32
|
-
if (seg.paragraphProperties) {
|
|
33
|
-
a.pp = JSON.stringify(seg.paragraphProperties);
|
|
34
|
-
}
|
|
35
|
-
if (typeof seg.fieldType === "string") {
|
|
36
|
-
a.ft = seg.fieldType;
|
|
37
|
-
}
|
|
38
|
-
if (typeof seg.fieldGuid === "string") {
|
|
39
|
-
a.fg = seg.fieldGuid;
|
|
40
|
-
}
|
|
41
|
-
if (seg.fieldGuidAttr === "uuid" || seg.fieldGuidAttr === "id") {
|
|
42
|
-
a.fga = seg.fieldGuidAttr;
|
|
43
|
-
}
|
|
44
|
-
if (seg.fieldParagraphPropertiesXml) {
|
|
45
|
-
a.fp = JSON.stringify(seg.fieldParagraphPropertiesXml);
|
|
46
|
-
}
|
|
47
|
-
if (seg.equationXml) {
|
|
48
|
-
a.eq = JSON.stringify(seg.equationXml);
|
|
49
|
-
}
|
|
50
|
-
if (typeof seg.equationNumber === "string") {
|
|
51
|
-
a.en = seg.equationNumber;
|
|
52
|
-
}
|
|
53
|
-
if (seg.breakRunProperties) {
|
|
54
|
-
a.br = JSON.stringify(seg.breakRunProperties);
|
|
55
|
-
}
|
|
56
|
-
if (typeof seg.rubyText === "string") {
|
|
57
|
-
a.rt = seg.rubyText;
|
|
58
|
-
}
|
|
59
|
-
if (typeof seg.rubyAlignment === "string") {
|
|
60
|
-
a.ra = seg.rubyAlignment;
|
|
61
|
-
}
|
|
62
|
-
if (seg.rubyFontSize !== void 0) {
|
|
63
|
-
a.rfs = String(seg.rubyFontSize);
|
|
64
|
-
}
|
|
65
|
-
if (seg.rubyStyle) {
|
|
66
|
-
a.rs = JSON.stringify(seg.rubyStyle);
|
|
67
|
-
}
|
|
68
|
-
return Object.keys(a).length > 0 ? a : void 0;
|
|
69
|
-
}
|
|
70
|
-
function encodeTextBodyToYText(segments, ytext) {
|
|
71
|
-
let offset = 0;
|
|
72
|
-
for (const raw of segments) {
|
|
73
|
-
const seg = raw;
|
|
74
|
-
const attrs = buildAttrs(seg) ?? {};
|
|
75
|
-
if (seg.isParagraphBreak === true || seg.isLineBreak === true) {
|
|
76
|
-
ytext.insert(offset, "\n", attrs);
|
|
77
|
-
offset += 1;
|
|
78
|
-
} else if (typeof seg.text === "string" && seg.text.length > 0) {
|
|
79
|
-
ytext.insert(offset, seg.text, attrs);
|
|
80
|
-
offset += seg.text.length;
|
|
81
|
-
} else {
|
|
82
|
-
const epAttrs = { ep: "1", ...attrs ?? {} };
|
|
83
|
-
ytext.insert(offset, EMPTY_PLACEHOLDER, epAttrs);
|
|
84
|
-
offset += 1;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function decodeTextBodyFromYText(ytext) {
|
|
89
|
-
const delta = ytext.toDelta();
|
|
90
|
-
const segments = [];
|
|
91
|
-
for (const op of delta) {
|
|
92
|
-
if (typeof op.insert !== "string" || op.insert === "") {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const a = op.attributes ?? {};
|
|
96
|
-
const seg = { text: "", style: {} };
|
|
97
|
-
if (a.s) {
|
|
98
|
-
try {
|
|
99
|
-
seg.style = JSON.parse(a.s);
|
|
100
|
-
} catch {
|
|
101
|
-
seg.style = {};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (a.pb === "1") {
|
|
105
|
-
seg.isParagraphBreak = true;
|
|
106
|
-
}
|
|
107
|
-
if (a.lb === "1") {
|
|
108
|
-
seg.isLineBreak = true;
|
|
109
|
-
}
|
|
110
|
-
if (a.bi) {
|
|
111
|
-
try {
|
|
112
|
-
seg.bulletInfo = JSON.parse(a.bi);
|
|
113
|
-
} catch {
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (a.pl !== void 0) {
|
|
117
|
-
seg.paragraphLevel = Number(a.pl);
|
|
118
|
-
}
|
|
119
|
-
if (a.pr) {
|
|
120
|
-
try {
|
|
121
|
-
seg.endParaRunProperties = JSON.parse(a.pr);
|
|
122
|
-
} catch {
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (a.pp) {
|
|
126
|
-
try {
|
|
127
|
-
seg.paragraphProperties = JSON.parse(a.pp);
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (a.ft) {
|
|
132
|
-
seg.fieldType = a.ft;
|
|
133
|
-
}
|
|
134
|
-
if (a.fg) {
|
|
135
|
-
seg.fieldGuid = a.fg;
|
|
136
|
-
}
|
|
137
|
-
if (a.fga === "uuid" || a.fga === "id") {
|
|
138
|
-
seg.fieldGuidAttr = a.fga;
|
|
139
|
-
}
|
|
140
|
-
if (a.fp) {
|
|
141
|
-
try {
|
|
142
|
-
seg.fieldParagraphPropertiesXml = JSON.parse(a.fp);
|
|
143
|
-
} catch {
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (a.eq) {
|
|
147
|
-
try {
|
|
148
|
-
seg.equationXml = JSON.parse(a.eq);
|
|
149
|
-
} catch {
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (a.en) {
|
|
153
|
-
seg.equationNumber = a.en;
|
|
154
|
-
}
|
|
155
|
-
if (a.br) {
|
|
156
|
-
try {
|
|
157
|
-
seg.breakRunProperties = JSON.parse(a.br);
|
|
158
|
-
} catch {
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (a.rt) {
|
|
162
|
-
seg.rubyText = a.rt;
|
|
163
|
-
}
|
|
164
|
-
if (a.ra) {
|
|
165
|
-
seg.rubyAlignment = a.ra;
|
|
166
|
-
}
|
|
167
|
-
if (a.rfs !== void 0) {
|
|
168
|
-
seg.rubyFontSize = Number(a.rfs);
|
|
169
|
-
}
|
|
170
|
-
if (a.rs) {
|
|
171
|
-
try {
|
|
172
|
-
seg.rubyStyle = JSON.parse(a.rs);
|
|
173
|
-
} catch {
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const isBreakMarker = /^\n+$/u.test(op.insert) && (a.pb === "1" || a.lb === "1");
|
|
177
|
-
if (isBreakMarker) {
|
|
178
|
-
for (let index = 0; index < op.insert.length; index++) {
|
|
179
|
-
segments.push(structuredClone(seg));
|
|
180
|
-
}
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (op.insert !== EMPTY_PLACEHOLDER) {
|
|
184
|
-
seg.text = op.insert;
|
|
185
|
-
}
|
|
186
|
-
segments.push(seg);
|
|
187
|
-
}
|
|
188
|
-
return segments;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/codec/pptx-codec.ts
|
|
192
|
-
var ORIGIN_FILE_LOAD = "file-load";
|
|
193
|
-
var SCALAR_ELEMENT_KEYS = new Set(
|
|
194
|
-
Object.entries(ELEMENT_FIELD_KIND).filter(([, kind]) => kind === "scalar" || kind === "asset").map(([field]) => field)
|
|
195
|
-
);
|
|
196
|
-
var COMPLEX_FIELD_MAP = Object.fromEntries(
|
|
197
|
-
Object.entries(ELEMENT_FIELD_KIND).filter(([, kind]) => kind === "complex").map(([field]) => [field, `_${field}`])
|
|
198
|
-
);
|
|
199
|
-
var REVERSE_COMPLEX_MAP = {};
|
|
200
|
-
for (const [original, prefixed] of Object.entries(COMPLEX_FIELD_MAP)) {
|
|
201
|
-
REVERSE_COMPLEX_MAP[prefixed] = original;
|
|
202
|
-
}
|
|
203
|
-
var SCALAR_SLIDE_KEYS = new Set(
|
|
204
|
-
Object.entries(SLIDE_FIELD_KIND).filter(([, kind]) => kind === "scalar").map(([field]) => field)
|
|
205
|
-
);
|
|
206
|
-
var COMPLEX_SLIDE_FIELD_MAP = Object.fromEntries(
|
|
207
|
-
Object.entries(SLIDE_FIELD_KIND).filter(([, kind]) => kind === "complex").map(([field]) => [field, `_${field}`])
|
|
208
|
-
);
|
|
209
|
-
var REVERSE_COMPLEX_SLIDE_MAP = {};
|
|
210
|
-
for (const [original, prefixed] of Object.entries(COMPLEX_SLIDE_FIELD_MAP)) {
|
|
211
|
-
REVERSE_COMPLEX_SLIDE_MAP[prefixed] = original;
|
|
212
|
-
}
|
|
213
|
-
var PptxCodec = class {
|
|
214
|
-
formatId = "pptx";
|
|
215
|
-
extensions = [".pptx", ".ppt"];
|
|
216
|
-
async hydrate(ydoc, bytes, origin) {
|
|
217
|
-
const effectiveOrigin = origin ?? ORIGIN_FILE_LOAD;
|
|
218
|
-
const handler = new PptxHandler();
|
|
219
|
-
const pptxData = await handler.load(bytes.buffer);
|
|
220
|
-
ydoc.transact(() => {
|
|
221
|
-
const meta = ydoc.getMap("pptx:meta");
|
|
222
|
-
meta.set("width", pptxData.width);
|
|
223
|
-
meta.set("height", pptxData.height);
|
|
224
|
-
if (pptxData.widthEmu !== void 0) {
|
|
225
|
-
meta.set("widthEmu", pptxData.widthEmu);
|
|
226
|
-
}
|
|
227
|
-
if (pptxData.heightEmu !== void 0) {
|
|
228
|
-
meta.set("heightEmu", pptxData.heightEmu);
|
|
229
|
-
}
|
|
230
|
-
const sourceBytesArr = new Array$1();
|
|
231
|
-
sourceBytesArr.insert(0, Array.from(bytes));
|
|
232
|
-
meta.set("sourceBytes", sourceBytesArr);
|
|
233
|
-
const slidesArray = ydoc.getArray("pptx:slides");
|
|
234
|
-
if (slidesArray.length > 0) {
|
|
235
|
-
slidesArray.delete(0, slidesArray.length);
|
|
236
|
-
}
|
|
237
|
-
for (const slide of pptxData.slides) {
|
|
238
|
-
slidesArray.push([this._slideToYMap(slide)]);
|
|
239
|
-
}
|
|
240
|
-
}, effectiveOrigin);
|
|
241
|
-
}
|
|
242
|
-
async dehydrate(ydoc, _dirtyPaths) {
|
|
243
|
-
const meta = ydoc.getMap("pptx:meta");
|
|
244
|
-
const slidesArray = ydoc.getArray("pptx:slides");
|
|
245
|
-
const slides = [];
|
|
246
|
-
for (let i = 0; i < slidesArray.length; i++) {
|
|
247
|
-
slides.push(this._yMapToSlide(slidesArray.get(i)));
|
|
248
|
-
}
|
|
249
|
-
const sourceBytesArr = meta.get("sourceBytes");
|
|
250
|
-
try {
|
|
251
|
-
if (!sourceBytesArr || sourceBytesArr.length === 0) {
|
|
252
|
-
throw new Error("No source bytes for PptxHandler");
|
|
253
|
-
}
|
|
254
|
-
const sourceBytes = new Uint8Array(sourceBytesArr.toArray());
|
|
255
|
-
const handler = new PptxHandler();
|
|
256
|
-
await handler.load(sourceBytes.buffer);
|
|
257
|
-
return await handler.save(slides);
|
|
258
|
-
} catch {
|
|
259
|
-
if (sourceBytesArr && sourceBytesArr.length > 0) {
|
|
260
|
-
return new Uint8Array(sourceBytesArr.toArray());
|
|
261
|
-
}
|
|
262
|
-
throw new Error("No PPTX bytes available for dehydration");
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
observe(ydoc, onChange) {
|
|
266
|
-
const slidesArray = ydoc.getArray("pptx:slides");
|
|
267
|
-
const meta = ydoc.getMap("pptx:meta");
|
|
268
|
-
slidesArray.observeDeep(onChange);
|
|
269
|
-
meta.observeDeep(onChange);
|
|
270
|
-
return () => {
|
|
271
|
-
slidesArray.unobserveDeep(onChange);
|
|
272
|
-
meta.unobserveDeep(onChange);
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
_slideToYMap(slide) {
|
|
276
|
-
const slideMap = new Map();
|
|
277
|
-
const rec = slide;
|
|
278
|
-
for (const key of SCALAR_SLIDE_KEYS) {
|
|
279
|
-
if (rec[key] !== void 0) {
|
|
280
|
-
slideMap.set(key, rec[key]);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
for (const [original, prefixed] of Object.entries(COMPLEX_SLIDE_FIELD_MAP)) {
|
|
284
|
-
if (rec[original] !== void 0) {
|
|
285
|
-
slideMap.set(prefixed, JSON.stringify(rec[original]));
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
const elementsArray = new Array$1();
|
|
289
|
-
for (const element of slide.elements) {
|
|
290
|
-
elementsArray.push([this._elementToYMap(element)]);
|
|
291
|
-
}
|
|
292
|
-
slideMap.set("elements", elementsArray);
|
|
293
|
-
return slideMap;
|
|
294
|
-
}
|
|
295
|
-
_yMapToSlide(slideMap) {
|
|
296
|
-
const slide = {};
|
|
297
|
-
for (const key of SCALAR_SLIDE_KEYS) {
|
|
298
|
-
const value = slideMap.get(key);
|
|
299
|
-
if (value !== void 0) {
|
|
300
|
-
slide[key] = value;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
for (const [prefixed, original] of Object.entries(REVERSE_COMPLEX_SLIDE_MAP)) {
|
|
304
|
-
const value = slideMap.get(prefixed);
|
|
305
|
-
if (value !== void 0) {
|
|
306
|
-
try {
|
|
307
|
-
slide[original] = JSON.parse(value);
|
|
308
|
-
} catch {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
const elementsArray = slideMap.get("elements");
|
|
313
|
-
const elements = [];
|
|
314
|
-
if (elementsArray) {
|
|
315
|
-
for (let i = 0; i < elementsArray.length; i++) {
|
|
316
|
-
elements.push(this._yMapToElement(elementsArray.get(i)));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
slide.elements = elements;
|
|
320
|
-
return slide;
|
|
321
|
-
}
|
|
322
|
-
_elementToYMap(element) {
|
|
323
|
-
const elemMap = new Map();
|
|
324
|
-
const record = element;
|
|
325
|
-
for (const [key, value] of Object.entries(record)) {
|
|
326
|
-
if (value === void 0) {
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
if (key === "textSegments") {
|
|
330
|
-
if (Array.isArray(value)) {
|
|
331
|
-
const ytext = new Text();
|
|
332
|
-
encodeTextBodyToYText(value, ytext);
|
|
333
|
-
elemMap.set("textBody", ytext);
|
|
334
|
-
}
|
|
335
|
-
} else if (SCALAR_ELEMENT_KEYS.has(key)) {
|
|
336
|
-
elemMap.set(key, value);
|
|
337
|
-
} else if (COMPLEX_FIELD_MAP[key]) {
|
|
338
|
-
elemMap.set(COMPLEX_FIELD_MAP[key], JSON.stringify(value));
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return elemMap;
|
|
342
|
-
}
|
|
343
|
-
_yMapToElement(elemMap) {
|
|
344
|
-
const element = {};
|
|
345
|
-
elemMap.forEach((value, key) => {
|
|
346
|
-
if (key === "textBody" && value instanceof Text) {
|
|
347
|
-
element.textSegments = decodeTextBodyFromYText(value);
|
|
348
|
-
} else if (REVERSE_COMPLEX_MAP[key]) {
|
|
349
|
-
try {
|
|
350
|
-
element[REVERSE_COMPLEX_MAP[key]] = JSON.parse(value);
|
|
351
|
-
} catch {
|
|
352
|
-
}
|
|
353
|
-
} else {
|
|
354
|
-
element[key] = value;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
return element;
|
|
358
|
-
}
|
|
359
|
-
};
|
|
4
|
+
var ORIGIN_FILE_LOAD = apiCodecPptxCodec.ORIGIN_FILE_LOAD;
|
|
5
|
+
var SCALAR_ELEMENT_KEYS = apiCodecPptxCodec.SCALAR_ELEMENT_KEYS;
|
|
6
|
+
var COMPLEX_FIELD_MAP = apiCodecPptxCodec.COMPLEX_FIELD_MAP;
|
|
7
|
+
var SCALAR_SLIDE_KEYS = apiCodecPptxCodec.SCALAR_SLIDE_KEYS;
|
|
8
|
+
var COMPLEX_SLIDE_FIELD_MAP = apiCodecPptxCodec.COMPLEX_SLIDE_FIELD_MAP;
|
|
9
|
+
var PptxCodec = apiCodecPptxCodec.PptxCodec;
|
|
360
10
|
|
|
361
11
|
export { COMPLEX_FIELD_MAP, COMPLEX_SLIDE_FIELD_MAP, ORIGIN_FILE_LOAD, PptxCodec, SCALAR_ELEMENT_KEYS, SCALAR_SLIDE_KEYS };
|