omni-viewer-core 0.7.0 → 0.9.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/README.md +32 -0
- package/dist/i18n/catalog.de.js +6 -1
- package/dist/i18n/catalog.en.js +30 -6
- package/dist/i18n/catalog.fr.js +6 -1
- package/dist/i18n/catalog.it.js +6 -1
- package/dist/i18n/catalog.ja.js +30 -6
- package/dist/i18n/catalog.ko.js +30 -6
- package/dist/i18n/catalog.th.js +6 -1
- package/dist/i18n/catalog.zh-cn.js +29 -5
- package/dist/parsers/archive/index.d.ts +2 -0
- package/dist/parsers/archive/index.js +6 -5
- package/dist/parsers/archive/model.d.ts +36 -11
- package/dist/parsers/archive/worker.d.ts +8 -1
- package/dist/parsers/doc-binary/index.d.ts +23 -1
- package/dist/parsers/doc-binary/index.js +175 -7
- package/dist/parsers/parquet/index.d.ts +14 -0
- package/dist/parsers/parquet/index.js +23 -8
- package/dist/parsers/pptx/index.d.ts +2 -0
- package/dist/parsers/pptx/index.js +1 -1
- package/dist/parsers/pptx/limits.d.ts +26 -0
- package/dist/parsers/pptx/limits.js +154 -0
- package/dist/parsers/pptx/vscode-parser.d.ts +49 -3
- package/dist/parsers/pptx/vscode-parser.js +517 -63
- package/dist/parsers/pptx/vscode.d.ts +6 -2
- package/dist/parsers/pptx/vscode.js +95 -10
- package/dist/parsers/slide-model.d.ts +89 -6
- package/dist/parsers/types.d.ts +2 -0
- package/dist/parsers/zip-scan.d.ts +7 -0
- package/dist/parsers/zip-scan.js +22 -0
- package/dist/registry/index.js +2 -2
- package/dist/styles/archive.css +3 -1
- package/dist/styles/hdf5.css +1 -1
- package/dist/styles/jsonl.css +1 -1
- package/dist/styles/markdown.css +2 -2
- package/dist/styles/mermaid.css +10 -1
- package/dist/styles/parquet.css +1 -1
- package/dist/styles/pdf.css +6 -1
- package/dist/styles/plantuml.css +10 -1
- package/dist/styles/proto.css +1 -1
- package/dist/styles/safetensors.css +1 -1
- package/dist/styles/toml.css +1 -1
- package/dist/styles/word.css +2 -2
- package/dist/styles/yaml.css +1 -1
- package/dist/viewers/archive/controller.d.ts +4 -0
- package/dist/viewers/archive/controller.js +22 -0
- package/dist/viewers/archive/index.d.ts +38 -1
- package/dist/viewers/archive/index.js +176 -41
- package/dist/viewers/archive/styles.d.ts +1 -1
- package/dist/viewers/archive/styles.js +3 -1
- package/dist/viewers/diagram-controller.d.ts +42 -0
- package/dist/viewers/diagram-controller.js +47 -0
- package/dist/viewers/diagram-styles.d.ts +1 -0
- package/dist/viewers/diagram-styles.js +11 -0
- package/dist/viewers/diagram.d.ts +16 -6
- package/dist/viewers/diagram.js +321 -75
- package/dist/viewers/hdf5/styles.d.ts +1 -1
- package/dist/viewers/hdf5/styles.js +1 -1
- package/dist/viewers/hwp/self-loading.d.ts +2 -0
- package/dist/viewers/hwp/self-loading.js +6 -0
- package/dist/viewers/jsonl/controller.d.ts +2 -0
- package/dist/viewers/jsonl/controller.js +4 -0
- package/dist/viewers/jsonl/index.d.ts +1 -0
- package/dist/viewers/jsonl/index.js +97 -51
- package/dist/viewers/jsonl/popup.d.ts +16 -0
- package/dist/viewers/jsonl/popup.js +20 -0
- package/dist/viewers/jsonl/styles.d.ts +1 -1
- package/dist/viewers/jsonl/styles.js +1 -1
- package/dist/viewers/markdown/index.js +79 -14
- package/dist/viewers/markdown/styles.d.ts +1 -1
- package/dist/viewers/markdown/styles.js +2 -2
- package/dist/viewers/mermaid/index.d.ts +3 -4
- package/dist/viewers/mermaid/index.js +1 -1
- package/dist/viewers/mermaid/self-loading.js +4 -1
- package/dist/viewers/parquet/index.d.ts +9 -1
- package/dist/viewers/parquet/index.js +20 -10
- package/dist/viewers/parquet/styles.d.ts +1 -1
- package/dist/viewers/parquet/styles.js +1 -1
- package/dist/viewers/pdf/controller.d.ts +9 -0
- package/dist/viewers/pdf/controller.js +17 -0
- package/dist/viewers/pdf/index.js +90 -22
- package/dist/viewers/pdf/styles.d.ts +1 -1
- package/dist/viewers/pdf/styles.js +6 -1
- package/dist/viewers/plantuml/index.d.ts +3 -4
- package/dist/viewers/plantuml/index.js +1 -1
- package/dist/viewers/plantuml/self-loading.js +1 -1
- package/dist/viewers/ppt/chart.js +58 -18
- package/dist/viewers/ppt/index.d.ts +33 -2
- package/dist/viewers/ppt/index.js +245 -61
- package/dist/viewers/ppt/render.js +85 -40
- package/dist/viewers/ppt/self-loading.d.ts +2 -0
- package/dist/viewers/ppt/self-loading.js +4 -1
- package/dist/viewers/proto/index.js +77 -2
- package/dist/viewers/proto/styles.d.ts +1 -1
- package/dist/viewers/proto/styles.js +1 -1
- package/dist/viewers/safetensors/styles.d.ts +1 -1
- package/dist/viewers/safetensors/styles.js +1 -1
- package/dist/viewers/structured-styles.d.ts +1 -1
- package/dist/viewers/structured-styles.js +1 -1
- package/dist/viewers/structured.js +28 -1
- package/dist/viewers/word/docx-preprocess.d.ts +18 -2
- package/dist/viewers/word/docx-preprocess.js +248 -47
- package/dist/viewers/word/index.d.ts +108 -1
- package/dist/viewers/word/index.js +772 -85
- package/dist/viewers/word/self-loading.d.ts +5 -1
- package/dist/viewers/word/self-loading.js +17 -4
- package/dist/viewers/word/styles.d.ts +1 -1
- package/dist/viewers/word/styles.js +2 -2
- package/package.json +6 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @ts-nocheck -- upstream VS Code parser predates exactOptionalPropertyTypes.
|
|
2
2
|
import JSZip from 'jszip';
|
|
3
|
+
import { installBoundedZipReaders, pptxLimits, PptxLimitError, PptxParseGuard, preflightPptxZip } from './limits.js';
|
|
3
4
|
// Browser-safe subset of node:path used by the original VS Code parser.
|
|
4
5
|
const normalizePath = (value) => {
|
|
5
6
|
const output = [];
|
|
@@ -29,22 +30,39 @@ const ZERO_TX = {
|
|
|
29
30
|
rotDeg: 0
|
|
30
31
|
};
|
|
31
32
|
export class PptxXmlParser {
|
|
32
|
-
static async parse(input) {
|
|
33
|
+
static async parse(input, options = {}, deps = {}) {
|
|
33
34
|
const buffer = input;
|
|
35
|
+
const limits = pptxLimits(options);
|
|
36
|
+
preflightPptxZip(buffer, limits);
|
|
37
|
+
const guard = new PptxParseGuard(options, limits);
|
|
38
|
+
guard.checkpoint('input');
|
|
34
39
|
const zip = await JSZip.loadAsync(buffer);
|
|
40
|
+
const actualEntryCount = Object.keys(zip.files).length;
|
|
41
|
+
if (limits.maxEntries !== undefined &&
|
|
42
|
+
actualEntryCount > limits.maxEntries) {
|
|
43
|
+
throw new PptxLimitError({
|
|
44
|
+
kind: 'entries',
|
|
45
|
+
count: actualEntryCount
|
|
46
|
+
}, 'central-directory');
|
|
47
|
+
}
|
|
48
|
+
installBoundedZipReaders(zip, guard);
|
|
49
|
+
guard.checkpoint('central-directory');
|
|
35
50
|
const size = await this.getSlideSize(zip);
|
|
36
51
|
const slidePaths = await this.getOrderedSlidePaths(zip);
|
|
52
|
+
const diagnostics = [];
|
|
37
53
|
const slides = [];
|
|
38
54
|
for (let i = 0; i < slidePaths.length; i++) {
|
|
39
|
-
|
|
55
|
+
guard.checkpoint(slidePaths[i]);
|
|
56
|
+
const parsed = await this.parseSingleSlide(zip, slidePaths[i], i + 1, size, { guard, diagnostics, deps, slideNumber: i + 1, sourcePath: slidePaths[i] });
|
|
40
57
|
slides.push(parsed);
|
|
41
58
|
}
|
|
42
59
|
return {
|
|
43
60
|
slides,
|
|
44
|
-
totalSlides: slides.length
|
|
61
|
+
totalSlides: slides.length,
|
|
62
|
+
diagnostics
|
|
45
63
|
};
|
|
46
64
|
}
|
|
47
|
-
static async parseSingleSlide(zip, slidePath, slideNumber, size) {
|
|
65
|
+
static async parseSingleSlide(zip, slidePath, slideNumber, size, context) {
|
|
48
66
|
const slideXml = await this.readZipText(zip, slidePath);
|
|
49
67
|
const slideRels = await this.getRelationships(zip, slidePath);
|
|
50
68
|
const layoutPath = slideRels.find((r) => r.type.includes('/slideLayout'))?.target;
|
|
@@ -61,9 +79,10 @@ export class PptxXmlParser {
|
|
|
61
79
|
|| this.extractBackgroundColor(layoutXml, colorCtx)
|
|
62
80
|
|| this.extractBackgroundColor(masterXml, colorCtx)
|
|
63
81
|
|| '#ffffff';
|
|
64
|
-
const masterElements = await this.extractElementsFromPart(zip, masterXml, masterRels, colorCtx, 1);
|
|
65
|
-
const layoutElements = await this.extractElementsFromPart(zip, layoutXml, layoutRels, colorCtx, 2);
|
|
66
|
-
const slideElements = await this.extractElementsFromPart(zip, slideXml, slideRels, colorCtx, 3);
|
|
82
|
+
const masterElements = await this.extractElementsFromPart(zip, masterXml, masterRels, colorCtx, 1, { ...context, sourcePath: masterPath || slidePath });
|
|
83
|
+
const layoutElements = await this.extractElementsFromPart(zip, layoutXml, layoutRels, colorCtx, 2, { ...context, sourcePath: layoutPath || slidePath });
|
|
84
|
+
const slideElements = await this.extractElementsFromPart(zip, slideXml, slideRels, colorCtx, 3, context);
|
|
85
|
+
this.collectPartDiagnostics(slideXml, slideRels, context);
|
|
67
86
|
const merged = this.mergeWithPlaceholderInheritance([
|
|
68
87
|
...masterElements,
|
|
69
88
|
...layoutElements,
|
|
@@ -127,12 +146,17 @@ export class PptxXmlParser {
|
|
|
127
146
|
paragraphs: mergedParagraphs,
|
|
128
147
|
src: incoming.src || base.src,
|
|
129
148
|
tableRows: incoming.tableRows && incoming.tableRows.length > 0 ? incoming.tableRows : base.tableRows,
|
|
149
|
+
table: incoming.table || base.table,
|
|
130
150
|
chartKind: incoming.chartKind || base.chartKind,
|
|
131
151
|
chartTitle: incoming.chartTitle || base.chartTitle,
|
|
152
|
+
chartData: incoming.chartData || base.chartData,
|
|
132
153
|
fillColor: incoming.fillColor || base.fillColor,
|
|
133
154
|
borderColor: incoming.borderColor || base.borderColor,
|
|
134
155
|
customSvgPath: incoming.customSvgPath || base.customSvgPath,
|
|
135
156
|
isTitle: incoming.isTitle || base.isTitle,
|
|
157
|
+
textMargins: incoming.textMargins || base.textMargins,
|
|
158
|
+
verticalAlign: incoming.verticalAlign || base.verticalAlign,
|
|
159
|
+
autofit: incoming.autofit || base.autofit,
|
|
136
160
|
hiddenPromptText: incomingHasVisibleParagraphs ? false : !!(incoming.hiddenPromptText ?? base.hiddenPromptText)
|
|
137
161
|
};
|
|
138
162
|
}
|
|
@@ -162,8 +186,15 @@ export class PptxXmlParser {
|
|
|
162
186
|
...fallbackRun,
|
|
163
187
|
...run,
|
|
164
188
|
fontSizePx: run.fontSizePx || fallbackRun?.fontSizePx,
|
|
189
|
+
fontFamily: run.fontFamily || fallbackRun?.fontFamily,
|
|
165
190
|
bold: run.bold ?? fallbackRun?.bold,
|
|
166
191
|
italic: run.italic ?? fallbackRun?.italic,
|
|
192
|
+
underline: run.underline ?? fallbackRun?.underline,
|
|
193
|
+
strike: run.strike ?? fallbackRun?.strike,
|
|
194
|
+
characterSpacingPx: run.characterSpacingPx ?? fallbackRun?.characterSpacingPx,
|
|
195
|
+
rtl: run.rtl ?? fallbackRun?.rtl,
|
|
196
|
+
hyperlink: run.hyperlink || fallbackRun?.hyperlink,
|
|
197
|
+
action: run.action || fallbackRun?.action,
|
|
167
198
|
color: run.color || fallbackRun?.color
|
|
168
199
|
};
|
|
169
200
|
})
|
|
@@ -174,16 +205,29 @@ export class PptxXmlParser {
|
|
|
174
205
|
text: paragraph.text,
|
|
175
206
|
level: Number.isFinite(paragraph.level) ? paragraph.level : fallback.level,
|
|
176
207
|
bullet: paragraph.bullet ?? fallback.bullet,
|
|
208
|
+
bulletChar: paragraph.bulletChar || fallback.bulletChar,
|
|
209
|
+
numbered: paragraph.numbered ?? fallback.numbered,
|
|
210
|
+
numberingFormat: paragraph.numberingFormat || fallback.numberingFormat,
|
|
211
|
+
numberingStartAt: paragraph.numberingStartAt ?? fallback.numberingStartAt,
|
|
177
212
|
align: paragraph.align || fallback.align,
|
|
178
213
|
fontSizePx: paragraph.fontSizePx || fallback.fontSizePx,
|
|
214
|
+
fontFamily: paragraph.fontFamily || fallback.fontFamily,
|
|
179
215
|
bold: paragraph.bold ?? fallback.bold,
|
|
180
216
|
italic: paragraph.italic ?? fallback.italic,
|
|
217
|
+
underline: paragraph.underline ?? fallback.underline,
|
|
218
|
+
strike: paragraph.strike ?? fallback.strike,
|
|
219
|
+
characterSpacingPx: paragraph.characterSpacingPx ?? fallback.characterSpacingPx,
|
|
181
220
|
color: paragraph.color || fallback.color,
|
|
221
|
+
lineSpacingPx: paragraph.lineSpacingPx ?? fallback.lineSpacingPx,
|
|
222
|
+
lineSpacingPercent: paragraph.lineSpacingPercent ?? fallback.lineSpacingPercent,
|
|
223
|
+
spaceBeforePx: paragraph.spaceBeforePx ?? fallback.spaceBeforePx,
|
|
224
|
+
spaceAfterPx: paragraph.spaceAfterPx ?? fallback.spaceAfterPx,
|
|
225
|
+
rtl: paragraph.rtl ?? fallback.rtl,
|
|
182
226
|
runs: mergedRuns.length > 0 ? mergedRuns : undefined
|
|
183
227
|
};
|
|
184
228
|
});
|
|
185
229
|
}
|
|
186
|
-
static async extractElementsFromPart(zip, partXml, rels, colors, sourcePriority) {
|
|
230
|
+
static async extractElementsFromPart(zip, partXml, rels, colors, sourcePriority, context) {
|
|
187
231
|
if (!partXml) {
|
|
188
232
|
return [];
|
|
189
233
|
}
|
|
@@ -192,13 +236,14 @@ export class PptxXmlParser {
|
|
|
192
236
|
return [];
|
|
193
237
|
}
|
|
194
238
|
const result = [];
|
|
195
|
-
await this.collectBlocks(zip, tree, rels, colors, sourcePriority, ZERO_TX, result, { value: 0 });
|
|
239
|
+
await this.collectBlocks(zip, tree, rels, colors, sourcePriority, ZERO_TX, result, { value: 0 }, context);
|
|
196
240
|
return result;
|
|
197
241
|
}
|
|
198
|
-
static async collectBlocks(zip, xml, rels, colors, sourcePriority, parentTx, out, zCounter) {
|
|
242
|
+
static async collectBlocks(zip, xml, rels, colors, sourcePriority, parentTx, out, zCounter, context) {
|
|
199
243
|
const tagNames = ['p:sp', 'p:pic', 'p:graphicFrame', 'p:grpSp', 'p:cxnSp'];
|
|
200
244
|
let cursor = 0;
|
|
201
245
|
while (cursor < xml.length) {
|
|
246
|
+
context.guard.checkpoint(context.sourcePath);
|
|
202
247
|
let nextIdx = -1;
|
|
203
248
|
let foundTag = '';
|
|
204
249
|
for (const tag of tagNames) {
|
|
@@ -218,24 +263,24 @@ export class PptxXmlParser {
|
|
|
218
263
|
}
|
|
219
264
|
if (foundTag === 'p:grpSp') {
|
|
220
265
|
const grpTx = this.combineTransforms(parentTx, this.parseGroupTransform(block.content));
|
|
221
|
-
await this.collectBlocks(zip, block.innerContent, rels, colors, sourcePriority, grpTx, out, zCounter);
|
|
266
|
+
await this.collectBlocks(zip, block.innerContent, rels, colors, sourcePriority, grpTx, out, zCounter, context);
|
|
222
267
|
}
|
|
223
268
|
else if (foundTag === 'p:sp' || foundTag === 'p:cxnSp') {
|
|
224
|
-
const element = await this.parseShapeBlock(zip, block.content, rels, colors, sourcePriority, parentTx, zCounter.value);
|
|
269
|
+
const element = await this.parseShapeBlock(zip, block.content, rels, colors, sourcePriority, parentTx, zCounter.value, context);
|
|
225
270
|
if (element) {
|
|
226
271
|
out.push(element);
|
|
227
272
|
zCounter.value += 1;
|
|
228
273
|
}
|
|
229
274
|
}
|
|
230
275
|
else if (foundTag === 'p:pic') {
|
|
231
|
-
const element = await this.parsePictureBlock(zip, block.content, rels, sourcePriority, parentTx, zCounter.value);
|
|
276
|
+
const element = await this.parsePictureBlock(zip, block.content, rels, sourcePriority, parentTx, zCounter.value, context);
|
|
232
277
|
if (element) {
|
|
233
278
|
out.push(element);
|
|
234
279
|
zCounter.value += 1;
|
|
235
280
|
}
|
|
236
281
|
}
|
|
237
282
|
else if (foundTag === 'p:graphicFrame') {
|
|
238
|
-
const element = await this.parseGraphicFrameBlock(zip, block.content, rels, colors, sourcePriority, parentTx, zCounter.value);
|
|
283
|
+
const element = await this.parseGraphicFrameBlock(zip, block.content, rels, colors, sourcePriority, parentTx, zCounter.value, context);
|
|
239
284
|
if (element) {
|
|
240
285
|
out.push(element);
|
|
241
286
|
zCounter.value += 1;
|
|
@@ -251,7 +296,7 @@ export class PptxXmlParser {
|
|
|
251
296
|
const m = re.exec(xml);
|
|
252
297
|
return m ? m.index : -1;
|
|
253
298
|
}
|
|
254
|
-
static async parseShapeBlock(zip, shapeXml, rels, colors, sourcePriority, parentTx, zIndex) {
|
|
299
|
+
static async parseShapeBlock(zip, shapeXml, rels, colors, sourcePriority, parentTx, zIndex, context) {
|
|
255
300
|
const placeholderType = this.getPlaceholderType(shapeXml);
|
|
256
301
|
// Footer/date/slide-number placeholders in master/layout should not render unless slide overrides them.
|
|
257
302
|
if (sourcePriority < 3 && (placeholderType === 'dt' || placeholderType === 'ftr' || placeholderType === 'sldnum')) {
|
|
@@ -262,6 +307,7 @@ export class PptxXmlParser {
|
|
|
262
307
|
const placeholderKey = this.getPlaceholderKey(shapeXml);
|
|
263
308
|
const isTitle = this.isTitleShape(shapeXml);
|
|
264
309
|
const paragraphs = this.extractTextParagraphs(shapeXml, colors);
|
|
310
|
+
const textBox = this.extractTextBoxProperties(shapeXml);
|
|
265
311
|
if (paragraphs.length > 0 && sourcePriority < 3) {
|
|
266
312
|
const hasOnlyPromptText = paragraphs.every((p) => this.isPlaceholderPromptText(p.text));
|
|
267
313
|
if (hasOnlyPromptText) {
|
|
@@ -288,6 +334,13 @@ export class PptxXmlParser {
|
|
|
288
334
|
const borderColor = this.extractLineColor(shapeXml, colors);
|
|
289
335
|
const presetGeom = shapeXml.match(/<a:prstGeom\b[^>]*prst="([^"]+)"/)?.[1];
|
|
290
336
|
const customSvgPath = geom ? this.parseCustomGeometryPath(shapeXml, geom.width, geom.height) : undefined;
|
|
337
|
+
if (presetGeom &&
|
|
338
|
+
!customSvgPath &&
|
|
339
|
+
!this.isSupportedPresetGeometry(presetGeom)) {
|
|
340
|
+
this.addObjectDiagnostic(context, 'shape', 'simplified', geom ?? undefined, {
|
|
341
|
+
preset: presetGeom
|
|
342
|
+
});
|
|
343
|
+
}
|
|
291
344
|
// Connector line arrow endpoints.
|
|
292
345
|
const headEndType = shapeXml.match(/<a:headEnd\b[^>]*type="([^"]+)"/)?.[1];
|
|
293
346
|
const tailEndType = shapeXml.match(/<a:tailEnd\b[^>]*type="([^"]+)"/)?.[1];
|
|
@@ -304,6 +357,7 @@ export class PptxXmlParser {
|
|
|
304
357
|
placeholderKey,
|
|
305
358
|
isTitle,
|
|
306
359
|
paragraphs,
|
|
360
|
+
...textBox,
|
|
307
361
|
fillColor,
|
|
308
362
|
borderColor,
|
|
309
363
|
customSvgPath,
|
|
@@ -315,11 +369,8 @@ export class PptxXmlParser {
|
|
|
315
369
|
if (blipEmbedId && geom) {
|
|
316
370
|
const target = rels.find((r) => r.id === blipEmbedId)?.target;
|
|
317
371
|
if (target) {
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
if (media) {
|
|
321
|
-
const base64 = await media.async('base64');
|
|
322
|
-
const mime = this.getMimeTypeByExtension(selectedTarget);
|
|
372
|
+
const image = await this.resolveImageSource(zip, target, context, geom);
|
|
373
|
+
if (image) {
|
|
323
374
|
return {
|
|
324
375
|
type: 'image',
|
|
325
376
|
x: geom.x,
|
|
@@ -330,7 +381,8 @@ export class PptxXmlParser {
|
|
|
330
381
|
zIndex,
|
|
331
382
|
sourcePriority,
|
|
332
383
|
placeholderKey,
|
|
333
|
-
src:
|
|
384
|
+
src: image.src,
|
|
385
|
+
vectorFallback: image.vectorFallback,
|
|
334
386
|
hasGeometry: true
|
|
335
387
|
};
|
|
336
388
|
}
|
|
@@ -361,7 +413,7 @@ export class PptxXmlParser {
|
|
|
361
413
|
}
|
|
362
414
|
return null;
|
|
363
415
|
}
|
|
364
|
-
static async parsePictureBlock(zip, picXml, rels, sourcePriority, parentTx, zIndex) {
|
|
416
|
+
static async parsePictureBlock(zip, picXml, rels, sourcePriority, parentTx, zIndex, context) {
|
|
365
417
|
const localGeom = this.parseGeometry(picXml);
|
|
366
418
|
const geom = localGeom ? this.applyTransform(localGeom, parentTx) : null;
|
|
367
419
|
const placeholderKey = this.getPlaceholderKey(picXml);
|
|
@@ -372,6 +424,9 @@ export class PptxXmlParser {
|
|
|
372
424
|
}
|
|
373
425
|
const embedId = picXml.match(/<a:blip[^>]*r:embed="([^"]+)"/)?.[1];
|
|
374
426
|
if (!embedId) {
|
|
427
|
+
this.addObjectDiagnostic(context, 'image', 'placeholder', geom ?? undefined, {
|
|
428
|
+
reason: 'missing-relationship-id'
|
|
429
|
+
});
|
|
375
430
|
if (!geom && !placeholderKey) {
|
|
376
431
|
return null;
|
|
377
432
|
}
|
|
@@ -390,6 +445,9 @@ export class PptxXmlParser {
|
|
|
390
445
|
}
|
|
391
446
|
const target = rels.find((r) => r.id === embedId)?.target;
|
|
392
447
|
if (!target) {
|
|
448
|
+
this.addObjectDiagnostic(context, 'image', 'placeholder', geom ?? undefined, {
|
|
449
|
+
reason: 'missing-relationship-target'
|
|
450
|
+
});
|
|
393
451
|
return geom || placeholderKey ? {
|
|
394
452
|
type: 'shape',
|
|
395
453
|
x: geom ? geom.x : 0,
|
|
@@ -403,18 +461,23 @@ export class PptxXmlParser {
|
|
|
403
461
|
hasGeometry: !!geom
|
|
404
462
|
} : null;
|
|
405
463
|
}
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
464
|
+
const image = await this.resolveImageSource(zip, target, context, geom ?? undefined);
|
|
465
|
+
if (!image) {
|
|
466
|
+
return geom || placeholderKey ? {
|
|
467
|
+
type: 'shape',
|
|
468
|
+
x: geom ? geom.x : 0,
|
|
469
|
+
y: geom ? geom.y : 0,
|
|
470
|
+
width: geom ? geom.width : 0,
|
|
471
|
+
height: geom ? geom.height : 0,
|
|
472
|
+
rotateDeg: geom?.rotateDeg,
|
|
473
|
+
zIndex,
|
|
474
|
+
sourcePriority,
|
|
475
|
+
placeholderKey,
|
|
476
|
+
fillColor: '#f7f7f7',
|
|
477
|
+
borderColor: '#c9c9c9',
|
|
478
|
+
hasGeometry: !!geom
|
|
479
|
+
} : null;
|
|
410
480
|
}
|
|
411
|
-
const base64 = await media.async('base64');
|
|
412
|
-
const mime = this.getMimeTypeByExtension(selectedTarget);
|
|
413
|
-
const sourceExt = path.extname(target).toLowerCase();
|
|
414
|
-
const selectedExt = path.extname(selectedTarget).toLowerCase();
|
|
415
|
-
const vectorFallback = (sourceExt === '.emf' || sourceExt === '.wmf')
|
|
416
|
-
&& selectedTarget !== target
|
|
417
|
-
&& (selectedExt === '.png' || selectedExt === '.jpg' || selectedExt === '.jpeg' || selectedExt === '.webp' || selectedExt === '.gif');
|
|
418
481
|
// Parse <a:srcRect l="" t="" r="" b=""/> — values are in 1/1000th percent.
|
|
419
482
|
const srcRectTag = picXml.match(/<a:srcRect\b[^>]*\/?>/)?.[0] || '';
|
|
420
483
|
let srcRect;
|
|
@@ -441,13 +504,13 @@ export class PptxXmlParser {
|
|
|
441
504
|
zIndex,
|
|
442
505
|
sourcePriority,
|
|
443
506
|
placeholderKey,
|
|
444
|
-
src:
|
|
507
|
+
src: image.src,
|
|
445
508
|
srcRect,
|
|
446
|
-
vectorFallback,
|
|
509
|
+
vectorFallback: image.vectorFallback,
|
|
447
510
|
hasGeometry: !!geom
|
|
448
511
|
};
|
|
449
512
|
}
|
|
450
|
-
static async parseGraphicFrameBlock(zip, frameXml, rels, colors, sourcePriority, parentTx, zIndex) {
|
|
513
|
+
static async parseGraphicFrameBlock(zip, frameXml, rels, colors, sourcePriority, parentTx, zIndex, context) {
|
|
451
514
|
const localGeom = this.parseGeometry(frameXml);
|
|
452
515
|
if (!localGeom) {
|
|
453
516
|
return null;
|
|
@@ -455,7 +518,8 @@ export class PptxXmlParser {
|
|
|
455
518
|
const geom = this.applyTransform(localGeom, parentTx);
|
|
456
519
|
const uri = frameXml.match(/<a:graphicData[^>]*uri="([^"]+)"/)?.[1] || '';
|
|
457
520
|
if (uri.includes('/table')) {
|
|
458
|
-
const
|
|
521
|
+
const table = this.extractTable(frameXml, colors);
|
|
522
|
+
const tableRows = table.rows.map((row) => row.cells.filter((cell) => !cell.merged).map((cell) => cell.paragraphs.map((paragraph) => paragraph.text).join('\n')));
|
|
459
523
|
if (tableRows.length === 0) {
|
|
460
524
|
return null;
|
|
461
525
|
}
|
|
@@ -469,6 +533,7 @@ export class PptxXmlParser {
|
|
|
469
533
|
zIndex,
|
|
470
534
|
sourcePriority,
|
|
471
535
|
placeholderKey: this.getPlaceholderKey(frameXml),
|
|
536
|
+
table,
|
|
472
537
|
tableRows
|
|
473
538
|
};
|
|
474
539
|
}
|
|
@@ -487,6 +552,11 @@ export class PptxXmlParser {
|
|
|
487
552
|
chartData = this.parseChartData(chartXml, colors);
|
|
488
553
|
}
|
|
489
554
|
}
|
|
555
|
+
if (!chartData) {
|
|
556
|
+
this.addObjectDiagnostic(context, 'chart', 'placeholder', geom, {
|
|
557
|
+
chartTitle
|
|
558
|
+
});
|
|
559
|
+
}
|
|
490
560
|
return {
|
|
491
561
|
type: 'chart',
|
|
492
562
|
x: geom.x,
|
|
@@ -503,6 +573,46 @@ export class PptxXmlParser {
|
|
|
503
573
|
};
|
|
504
574
|
}
|
|
505
575
|
if (uri.includes('/diagram')) {
|
|
576
|
+
const referencedRelIds = Array.from(frameXml.matchAll(/\br:[A-Za-z0-9_]+="([^"]+)"/g), (match) => match[1]);
|
|
577
|
+
const imageRelationship = rels.find((relationship) => referencedRelIds.includes(relationship.id) &&
|
|
578
|
+
/\/image$/.test(relationship.type));
|
|
579
|
+
const imageTarget = imageRelationship?.target;
|
|
580
|
+
if (imageTarget) {
|
|
581
|
+
const image = await this.resolveImageSource(zip, imageTarget, context, geom);
|
|
582
|
+
if (image) {
|
|
583
|
+
this.addObjectDiagnostic(context, 'smartart', 'simplified', geom, {
|
|
584
|
+
fallback: 'image'
|
|
585
|
+
});
|
|
586
|
+
return {
|
|
587
|
+
type: 'image',
|
|
588
|
+
x: geom.x,
|
|
589
|
+
y: geom.y,
|
|
590
|
+
width: geom.width,
|
|
591
|
+
height: geom.height,
|
|
592
|
+
rotateDeg: geom.rotateDeg,
|
|
593
|
+
zIndex,
|
|
594
|
+
sourcePriority,
|
|
595
|
+
placeholderKey: this.getPlaceholderKey(frameXml),
|
|
596
|
+
src: image.src,
|
|
597
|
+
vectorFallback: image.vectorFallback
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const smartArtText = [];
|
|
602
|
+
const diagramRelIds = Array.from(frameXml.matchAll(/\br:(?:dm|lo|qs|cs)="([^"]+)"/g), (match) => match[1]);
|
|
603
|
+
for (const relId of diagramRelIds) {
|
|
604
|
+
context.guard.checkpoint(context.sourcePath);
|
|
605
|
+
const target = rels.find((relationship) => relationship.id === relId)?.target;
|
|
606
|
+
if (!target)
|
|
607
|
+
continue;
|
|
608
|
+
const dataXml = await this.readZipText(zip, target);
|
|
609
|
+
for (const match of dataXml.matchAll(/<a:t(?=[\s>])[^>]*>([\s\S]*?)<\/a:t>/g)) {
|
|
610
|
+
const text = this.decodeXmlEntities(match[1] ?? '').trim();
|
|
611
|
+
if (text && !smartArtText.includes(text))
|
|
612
|
+
smartArtText.push(text);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
this.addObjectDiagnostic(context, 'smartart', smartArtText.length ? 'simplified' : 'placeholder', geom, { fallback: smartArtText.length ? 'text' : 'none' });
|
|
506
616
|
return {
|
|
507
617
|
type: 'chart',
|
|
508
618
|
x: geom.x,
|
|
@@ -514,10 +624,20 @@ export class PptxXmlParser {
|
|
|
514
624
|
sourcePriority,
|
|
515
625
|
placeholderKey: this.getPlaceholderKey(frameXml),
|
|
516
626
|
chartKind: 'smartart',
|
|
517
|
-
chartTitle: 'SmartArt'
|
|
627
|
+
chartTitle: 'SmartArt',
|
|
628
|
+
...(smartArtText.length
|
|
629
|
+
? {
|
|
630
|
+
paragraphs: smartArtText.map((text) => ({
|
|
631
|
+
text,
|
|
632
|
+
level: 0
|
|
633
|
+
}))
|
|
634
|
+
}
|
|
635
|
+
: {})
|
|
518
636
|
};
|
|
519
637
|
}
|
|
520
638
|
// Other embedded objects fallback as shape frame
|
|
639
|
+
const objectKind = /ole|package/i.test(uri) ? 'ole' : 'shape';
|
|
640
|
+
this.addObjectDiagnostic(context, objectKind, 'placeholder', geom, { uri });
|
|
521
641
|
return {
|
|
522
642
|
type: 'shape',
|
|
523
643
|
x: geom.x,
|
|
@@ -532,26 +652,44 @@ export class PptxXmlParser {
|
|
|
532
652
|
borderColor: '#c9c9c9'
|
|
533
653
|
};
|
|
534
654
|
}
|
|
535
|
-
static
|
|
655
|
+
static extractTable(xml, colors) {
|
|
536
656
|
const rows = [];
|
|
657
|
+
const columnWidths = (xml.match(/<a:gridCol\b[^>]*\/?>/g) || []).map((tag) => this.emuToPx(Number(this.getAttr(tag, 'w') || 0)));
|
|
537
658
|
const trMatches = xml.match(/<a:tr\b[\s\S]*?<\/a:tr>/g) || [];
|
|
538
659
|
for (const tr of trMatches) {
|
|
539
|
-
const
|
|
660
|
+
const cells = [];
|
|
540
661
|
const tcMatches = tr.match(/<a:tc\b[\s\S]*?<\/a:tc>/g) || [];
|
|
541
662
|
for (const tc of tcMatches) {
|
|
542
|
-
const
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
663
|
+
const open = tc.match(/^<a:tc\b[^>]*>/)?.[0] || '';
|
|
664
|
+
const tcPr = this.extractTagBlock(tc, 'a:tcPr') || '';
|
|
665
|
+
const cell = {
|
|
666
|
+
paragraphs: this.extractTextParagraphs(tc, colors),
|
|
667
|
+
rowSpan: this.parseNumber(this.getAttr(open, 'rowSpan')),
|
|
668
|
+
colSpan: this.parseNumber(this.getAttr(open, 'gridSpan')),
|
|
669
|
+
merged: this.getAttr(open, 'hMerge') === '1' || this.getAttr(open, 'vMerge') === '1',
|
|
670
|
+
fillColor: this.extractFillColor(tcPr, colors),
|
|
671
|
+
borders: this.extractTableBorders(tcPr, colors),
|
|
672
|
+
verticalAlign: this.getAttr(tcPr.match(/<a:tcPr\b[^>]*>/)?.[0] || '', 'anchor'),
|
|
673
|
+
margins: this.extractTableMargins(tcPr)
|
|
674
|
+
};
|
|
675
|
+
cells.push(cell);
|
|
676
|
+
}
|
|
677
|
+
if (cells.length > 0) {
|
|
678
|
+
rows.push({
|
|
679
|
+
height: this.emuToPx(Number(this.getAttr(tr.match(/^<a:tr\b[^>]*>/)?.[0] || '', 'h') || 0)),
|
|
680
|
+
cells
|
|
681
|
+
});
|
|
550
682
|
}
|
|
551
|
-
if (row.length > 0)
|
|
552
|
-
rows.push(row);
|
|
553
683
|
}
|
|
554
|
-
|
|
684
|
+
const tblPr = xml.match(/<a:tblPr\b[^>]*\/?>/)?.[0] || '';
|
|
685
|
+
return {
|
|
686
|
+
rows,
|
|
687
|
+
columnWidths: columnWidths.length ? columnWidths : undefined,
|
|
688
|
+
firstRow: this.getAttr(tblPr, 'firstRow') === '1',
|
|
689
|
+
firstColumn: this.getAttr(tblPr, 'firstCol') === '1',
|
|
690
|
+
bandedRows: this.getAttr(tblPr, 'bandRow') === '1',
|
|
691
|
+
bandedColumns: this.getAttr(tblPr, 'bandCol') === '1'
|
|
692
|
+
};
|
|
555
693
|
}
|
|
556
694
|
static extractTextParagraphs(shapeXml, colors) {
|
|
557
695
|
const paragraphs = [];
|
|
@@ -572,12 +710,25 @@ export class PptxXmlParser {
|
|
|
572
710
|
const text = this.decodeXmlEntities(t);
|
|
573
711
|
textParts.push(text);
|
|
574
712
|
const runRPr = run.match(/<a:rPr[^>]*\/?>/)?.[0] || '';
|
|
713
|
+
const runRPrXml = this.extractTagBlock(run, 'a:rPr') || runRPr;
|
|
575
714
|
const runSz = Number(this.getAttr(runRPr, 'sz') || 0);
|
|
715
|
+
const underline = this.getAttr(runRPr, 'u');
|
|
716
|
+
const strike = this.getAttr(runRPr, 'strike');
|
|
717
|
+
const spacing = Number(this.getAttr(runRPr, 'spc') || 0);
|
|
718
|
+
const hyperlink = runRPrXml.match(/<a:hlinkClick\b[^>]*r:id="([^"]+)"/)?.[1];
|
|
719
|
+
const action = runRPrXml.match(/<a:hlinkClick\b[^>]*action="([^"]+)"/)?.[1];
|
|
576
720
|
runs.push({
|
|
577
721
|
text,
|
|
578
722
|
fontSizePx: runSz > 0 ? Math.round((runSz / 100) * 1.333) : undefined,
|
|
723
|
+
fontFamily: this.extractFontFamily(runRPrXml, colors),
|
|
579
724
|
bold: this.parseOptionalBoolAttr(runRPr, 'b'),
|
|
580
725
|
italic: this.parseOptionalBoolAttr(runRPr, 'i'),
|
|
726
|
+
underline: underline ? underline !== 'none' : undefined,
|
|
727
|
+
strike: strike ? strike !== 'noStrike' : undefined,
|
|
728
|
+
characterSpacingPx: spacing ? (spacing / 100) * 1.333 : undefined,
|
|
729
|
+
rtl: this.parseOptionalBoolAttr(runRPr, 'rtl'),
|
|
730
|
+
hyperlink,
|
|
731
|
+
action,
|
|
581
732
|
color: this.extractColorFromXml(runRPr + run, colors)
|
|
582
733
|
});
|
|
583
734
|
}
|
|
@@ -594,12 +745,13 @@ export class PptxXmlParser {
|
|
|
594
745
|
const text = textParts.join('').trim();
|
|
595
746
|
if (!text)
|
|
596
747
|
continue;
|
|
597
|
-
const
|
|
598
|
-
const
|
|
748
|
+
const inlinePPrTag = pXml.match(/<a:pPr[^>]*\/?>/)?.[0] || '';
|
|
749
|
+
const inlinePPr = this.extractTagBlock(pXml, 'a:pPr') || inlinePPrTag;
|
|
750
|
+
const inlineLevel = Number(this.getAttr(inlinePPrTag, 'lvl') || 0);
|
|
599
751
|
const level = Number.isFinite(inlineLevel) ? inlineLevel : 0;
|
|
600
752
|
const levelStyle = this.extractParagraphLevelStyle(lstStyle, level);
|
|
601
753
|
const levelPPr = levelStyle.match(/<a:lvl\d+pPr[^>]*>/)?.[0] || '';
|
|
602
|
-
const pPr = inlinePPr ||
|
|
754
|
+
const pPr = inlinePPr || levelStyle;
|
|
603
755
|
const levelRPr = levelStyle.match(/<a:defRPr[^>]*\/?>/)?.[0] || '';
|
|
604
756
|
const bodyDefaultRPr = txBody.match(/<a:defRPr[^>]*\/?>/)?.[0]
|
|
605
757
|
|| bodyPr.match(/<a:defRPr[^>]*\/?>/)?.[0]
|
|
@@ -614,20 +766,114 @@ export class PptxXmlParser {
|
|
|
614
766
|
const color = this.extractColorFromXml(rPr, colors);
|
|
615
767
|
const hasBullet = /<a:buChar\b|<a:buAutoNum\b|<a:buBlip\b/.test(pXml) || /<a:buChar\b|<a:buAutoNum\b|<a:buBlip\b/.test(levelStyle);
|
|
616
768
|
const hasBuNone = /<a:buNone\b/.test(pXml) || /<a:buNone\b/.test(levelStyle);
|
|
769
|
+
const bulletXml = inlinePPr || levelStyle;
|
|
770
|
+
const bulletCharRaw = bulletXml.match(/<a:buChar\b[^>]*char="([^"]+)"/)?.[1];
|
|
771
|
+
const autoNum = bulletXml.match(/<a:buAutoNum\b[^>]*\/?>/)?.[0] || '';
|
|
772
|
+
const underline = this.getAttr(rPr, 'u');
|
|
773
|
+
const strike = this.getAttr(rPr, 'strike');
|
|
774
|
+
const characterSpacing = Number(this.getAttr(rPr, 'spc') || 0);
|
|
775
|
+
const lineSpacing = this.extractParagraphSpacing(pPr, 'lnSpc');
|
|
776
|
+
const beforeSpacing = this.extractParagraphSpacing(pPr, 'spcBef');
|
|
777
|
+
const afterSpacing = this.extractParagraphSpacing(pPr, 'spcAft');
|
|
617
778
|
paragraphs.push({
|
|
618
779
|
text,
|
|
619
780
|
level: Number.isFinite(level) ? level : 0,
|
|
620
781
|
bullet: hasBullet && !hasBuNone,
|
|
782
|
+
bulletChar: bulletCharRaw ? this.decodeXmlEntities(bulletCharRaw) : undefined,
|
|
783
|
+
numbered: !!autoNum && !hasBuNone,
|
|
784
|
+
numberingFormat: this.getAttr(autoNum, 'type'),
|
|
785
|
+
numberingStartAt: this.parseNumber(this.getAttr(autoNum, 'startAt')),
|
|
621
786
|
align,
|
|
622
787
|
fontSizePx: size > 0 ? Math.round((size / 100) * 1.333) : undefined,
|
|
788
|
+
fontFamily: this.extractFontFamily(rPr, colors),
|
|
623
789
|
bold: this.parseOptionalBoolAttr(rPr, 'b'),
|
|
624
790
|
italic: this.parseOptionalBoolAttr(rPr, 'i'),
|
|
791
|
+
underline: underline ? underline !== 'none' : undefined,
|
|
792
|
+
strike: strike ? strike !== 'noStrike' : undefined,
|
|
793
|
+
characterSpacingPx: characterSpacing ? (characterSpacing / 100) * 1.333 : undefined,
|
|
625
794
|
color,
|
|
795
|
+
lineSpacingPx: lineSpacing.px,
|
|
796
|
+
lineSpacingPercent: lineSpacing.percent,
|
|
797
|
+
spaceBeforePx: beforeSpacing.px,
|
|
798
|
+
spaceAfterPx: afterSpacing.px,
|
|
799
|
+
rtl: this.parseOptionalBoolAttr(inlinePPrTag, 'rtl'),
|
|
626
800
|
runs: runs.length > 0 ? runs : undefined
|
|
627
801
|
});
|
|
628
802
|
}
|
|
629
803
|
return paragraphs;
|
|
630
804
|
}
|
|
805
|
+
static extractTextBoxProperties(shapeXml) {
|
|
806
|
+
const bodyPr = shapeXml.match(/<a:bodyPr\b[^>]*\/?>/)?.[0] || '';
|
|
807
|
+
if (!bodyPr)
|
|
808
|
+
return {};
|
|
809
|
+
const inset = (name) => {
|
|
810
|
+
const raw = this.getAttr(bodyPr, name);
|
|
811
|
+
return raw === undefined ? undefined : this.emuToPx(Number(raw));
|
|
812
|
+
};
|
|
813
|
+
let autofit;
|
|
814
|
+
const body = this.extractTagBlock(shapeXml, 'a:bodyPr') || bodyPr;
|
|
815
|
+
if (/<a:normAutofit\b/.test(body))
|
|
816
|
+
autofit = 'normal';
|
|
817
|
+
else if (/<a:spAutoFit\b/.test(body))
|
|
818
|
+
autofit = 'shape';
|
|
819
|
+
else if (/<a:noAutofit\b/.test(body))
|
|
820
|
+
autofit = 'none';
|
|
821
|
+
const margins = {
|
|
822
|
+
left: inset('lIns'),
|
|
823
|
+
right: inset('rIns'),
|
|
824
|
+
top: inset('tIns'),
|
|
825
|
+
bottom: inset('bIns')
|
|
826
|
+
};
|
|
827
|
+
// Only emit textMargins when the shape actually declares an inset, so an
|
|
828
|
+
// empty <a:bodyPr/> does not mask insets inherited from layout/master
|
|
829
|
+
// through mergeElements' `incoming.textMargins || base.textMargins`.
|
|
830
|
+
const hasMargin = Object.values(margins).some((item) => item !== undefined);
|
|
831
|
+
return {
|
|
832
|
+
...(hasMargin ? { textMargins: margins } : {}),
|
|
833
|
+
verticalAlign: this.getAttr(bodyPr, 'anchor'),
|
|
834
|
+
autofit
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
static extractFontFamily(xml, colors) {
|
|
838
|
+
const tag = xml.match(/<a:(?:latin|ea|cs)\b[^>]*typeface="([^"]+)"/)?.[1];
|
|
839
|
+
if (!tag)
|
|
840
|
+
return undefined;
|
|
841
|
+
const decoded = this.decodeXmlEntities(tag);
|
|
842
|
+
return colors.themeFonts[decoded] || decoded;
|
|
843
|
+
}
|
|
844
|
+
static extractParagraphSpacing(xml, tag) {
|
|
845
|
+
const block = this.extractTagBlock(xml, `a:${tag}`) || '';
|
|
846
|
+
const points = this.parseNumber(block.match(/<a:spcPts\b[^>]*val="([^"]+)"/)?.[1]);
|
|
847
|
+
const percent = this.parseNumber(block.match(/<a:spcPct\b[^>]*val="([^"]+)"/)?.[1]);
|
|
848
|
+
return {
|
|
849
|
+
px: points === undefined ? undefined : (points / 100) * 1.333,
|
|
850
|
+
percent: percent === undefined ? undefined : percent / 1000
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
static extractTableMargins(xml) {
|
|
854
|
+
const tcPr = xml.match(/<a:tcPr\b[^>]*>/)?.[0] || '';
|
|
855
|
+
const value = (name) => {
|
|
856
|
+
const raw = this.getAttr(tcPr, name);
|
|
857
|
+
return raw === undefined ? undefined : this.emuToPx(Number(raw));
|
|
858
|
+
};
|
|
859
|
+
const margins = {
|
|
860
|
+
left: value('marL'),
|
|
861
|
+
right: value('marR'),
|
|
862
|
+
top: value('marT'),
|
|
863
|
+
bottom: value('marB')
|
|
864
|
+
};
|
|
865
|
+
return Object.values(margins).some((item) => item !== undefined) ? margins : undefined;
|
|
866
|
+
}
|
|
867
|
+
static extractTableBorders(xml, colors) {
|
|
868
|
+
const side = (tag) => this.extractColorFromXml(this.extractTagBlock(xml, tag) || '', colors);
|
|
869
|
+
const borders = {
|
|
870
|
+
left: side('a:lnL'),
|
|
871
|
+
right: side('a:lnR'),
|
|
872
|
+
top: side('a:lnT'),
|
|
873
|
+
bottom: side('a:lnB')
|
|
874
|
+
};
|
|
875
|
+
return Object.values(borders).some(Boolean) ? borders : undefined;
|
|
876
|
+
}
|
|
631
877
|
static parseGeometry(xml) {
|
|
632
878
|
const xfrm = this.extractTagBlock(xml, 'a:xfrm') || this.extractTagBlock(xml, 'p:xfrm');
|
|
633
879
|
if (!xfrm)
|
|
@@ -716,8 +962,9 @@ export class PptxXmlParser {
|
|
|
716
962
|
accent5: '#5b9bd5',
|
|
717
963
|
accent6: '#70ad47'
|
|
718
964
|
};
|
|
965
|
+
const fonts = {};
|
|
719
966
|
if (!themeXml)
|
|
720
|
-
return { colors };
|
|
967
|
+
return { colors, fonts };
|
|
721
968
|
const clrScheme = this.extractTagBlock(themeXml, 'a:clrScheme') || '';
|
|
722
969
|
const keys = ['lt1', 'dk1', 'lt2', 'dk2', 'accent1', 'accent2', 'accent3', 'accent4', 'accent5', 'accent6'];
|
|
723
970
|
for (const key of keys) {
|
|
@@ -729,7 +976,22 @@ export class PptxXmlParser {
|
|
|
729
976
|
else if (sys)
|
|
730
977
|
colors[key] = `#${sys}`;
|
|
731
978
|
}
|
|
732
|
-
|
|
979
|
+
const majorFont = this.extractTagBlock(themeXml, 'a:majorFont') || '';
|
|
980
|
+
const minorFont = this.extractTagBlock(themeXml, 'a:minorFont') || '';
|
|
981
|
+
const family = (xml, tag) => xml.match(new RegExp(`<a:${tag}\\b[^>]*typeface="([^"]*)"`))?.[1] || undefined;
|
|
982
|
+
const majorLatin = family(majorFont, 'latin');
|
|
983
|
+
const majorEa = family(majorFont, 'ea');
|
|
984
|
+
const minorLatin = family(minorFont, 'latin');
|
|
985
|
+
const minorEa = family(minorFont, 'ea');
|
|
986
|
+
if (majorLatin)
|
|
987
|
+
fonts['+mj-lt'] = this.decodeXmlEntities(majorLatin);
|
|
988
|
+
if (majorEa)
|
|
989
|
+
fonts['+mj-ea'] = this.decodeXmlEntities(majorEa);
|
|
990
|
+
if (minorLatin)
|
|
991
|
+
fonts['+mn-lt'] = this.decodeXmlEntities(minorLatin);
|
|
992
|
+
if (minorEa)
|
|
993
|
+
fonts['+mn-ea'] = this.decodeXmlEntities(minorEa);
|
|
994
|
+
return { colors, fonts };
|
|
733
995
|
}
|
|
734
996
|
static extractBackgroundColor(xml, colors) {
|
|
735
997
|
if (!xml)
|
|
@@ -1038,6 +1300,7 @@ export class PptxXmlParser {
|
|
|
1038
1300
|
}
|
|
1039
1301
|
return {
|
|
1040
1302
|
themeColors: theme.colors,
|
|
1303
|
+
themeFonts: theme.fonts,
|
|
1041
1304
|
clrMap
|
|
1042
1305
|
};
|
|
1043
1306
|
}
|
|
@@ -1099,12 +1362,29 @@ export class PptxXmlParser {
|
|
|
1099
1362
|
if (parsedLineChart)
|
|
1100
1363
|
return parsedLineChart;
|
|
1101
1364
|
}
|
|
1365
|
+
const pieChart = this.extractTagBlock(xml, 'c:pieChart')
|
|
1366
|
+
|| this.extractTagBlock(xml, 'c:pie3DChart');
|
|
1367
|
+
if (pieChart) {
|
|
1368
|
+
const parsedPieChart = this.parsePieChartData(xml, pieChart, colors);
|
|
1369
|
+
if (parsedPieChart)
|
|
1370
|
+
return parsedPieChart;
|
|
1371
|
+
}
|
|
1102
1372
|
const barChart = this.extractTagBlock(xml, 'c:barChart');
|
|
1103
1373
|
if (!barChart)
|
|
1104
1374
|
return undefined;
|
|
1105
1375
|
const grouping = barChart.match(/<c:grouping[^>]*val="([^"]+)"/)?.[1] || '';
|
|
1106
1376
|
const barDir = barChart.match(/<c:barDir[^>]*val="([^"]+)"/)?.[1] || '';
|
|
1107
|
-
|
|
1377
|
+
const normalizedGrouping = grouping || 'clustered';
|
|
1378
|
+
const kindBySemantics = {
|
|
1379
|
+
'col:clustered': 'clusteredColumn',
|
|
1380
|
+
'col:stacked': 'stackedColumn',
|
|
1381
|
+
'col:percentStacked': 'percentStackedColumn',
|
|
1382
|
+
'bar:clustered': 'clusteredBar',
|
|
1383
|
+
'bar:stacked': 'stackedBar',
|
|
1384
|
+
'bar:percentStacked': 'percentStackedBar'
|
|
1385
|
+
};
|
|
1386
|
+
const kind = kindBySemantics[`${barDir || 'col'}:${normalizedGrouping}`];
|
|
1387
|
+
if (!kind)
|
|
1108
1388
|
return undefined;
|
|
1109
1389
|
const serBlocks = barChart.match(/<c:ser\b[\s\S]*?<\/c:ser>/g) || [];
|
|
1110
1390
|
if (serBlocks.length === 0)
|
|
@@ -1146,7 +1426,9 @@ export class PptxXmlParser {
|
|
|
1146
1426
|
const valueAxis = this.parseValueAxis(xml, colors);
|
|
1147
1427
|
const legend = this.parseLegend(xml, colors);
|
|
1148
1428
|
return {
|
|
1149
|
-
kind
|
|
1429
|
+
kind,
|
|
1430
|
+
grouping: normalizedGrouping,
|
|
1431
|
+
barDir: barDir || 'col',
|
|
1150
1432
|
categories,
|
|
1151
1433
|
series: normalizedSeries,
|
|
1152
1434
|
gapWidth,
|
|
@@ -1156,6 +1438,46 @@ export class PptxXmlParser {
|
|
|
1156
1438
|
legend
|
|
1157
1439
|
};
|
|
1158
1440
|
}
|
|
1441
|
+
static parsePieChartData(chartXml, pieChart, colors) {
|
|
1442
|
+
const serXml = pieChart.match(/<c:ser\b[\s\S]*?<\/c:ser>/)?.[0] || '';
|
|
1443
|
+
if (!serXml)
|
|
1444
|
+
return undefined;
|
|
1445
|
+
const categories = this.extractChartPoints(serXml.match(/<c:cat[\s\S]*?<\/c:cat>/)?.[0] || '');
|
|
1446
|
+
const values = this.extractChartNumericPoints(serXml.match(/<c:val[\s\S]*?<\/c:val>/)?.[0] || '', categories.length || undefined);
|
|
1447
|
+
const pointColors = new Map();
|
|
1448
|
+
for (const point of serXml.match(/<c:dPt\b[\s\S]*?<\/c:dPt>/g) || []) {
|
|
1449
|
+
const index = Number(point.match(/<c:idx\b[^>]*val="(\d+)"/)?.[1] || -1);
|
|
1450
|
+
const color = this.extractColorFromXml(point, colors);
|
|
1451
|
+
if (index >= 0 && color)
|
|
1452
|
+
pointColors.set(index, color);
|
|
1453
|
+
}
|
|
1454
|
+
const palette = ['#4472c4', '#ed7d31', '#a5a5a5', '#ffc000', '#5b9bd5', '#70ad47'];
|
|
1455
|
+
const dataLabel = this.parseSeriesDataLabel(serXml, colors)
|
|
1456
|
+
|| this.parseSeriesDataLabel(pieChart, colors);
|
|
1457
|
+
const series = categories.map((category, index) => ({
|
|
1458
|
+
name: category || `Point ${index + 1}`,
|
|
1459
|
+
color: pointColors.get(index) || palette[index % palette.length],
|
|
1460
|
+
values: [values[index] ?? 0],
|
|
1461
|
+
dataLabel
|
|
1462
|
+
}));
|
|
1463
|
+
if (!series.length && values.length) {
|
|
1464
|
+
values.forEach((value, index) => {
|
|
1465
|
+
categories.push(`${index + 1}`);
|
|
1466
|
+
series.push({
|
|
1467
|
+
name: `${index + 1}`,
|
|
1468
|
+
color: palette[index % palette.length],
|
|
1469
|
+
values: [value],
|
|
1470
|
+
dataLabel
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
return {
|
|
1475
|
+
kind: 'pie',
|
|
1476
|
+
categories,
|
|
1477
|
+
series,
|
|
1478
|
+
legend: this.parseLegend(chartXml, colors)
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1159
1481
|
static parseLineChartData(chartXml, lineChart, colors) {
|
|
1160
1482
|
const serBlocks = lineChart.match(/<c:ser\b[\s\S]*?<\/c:ser>/g) || [];
|
|
1161
1483
|
if (serBlocks.length === 0)
|
|
@@ -1468,6 +1790,140 @@ export class PptxXmlParser {
|
|
|
1468
1790
|
];
|
|
1469
1791
|
return promptPatterns.some((re) => re.test(normalized));
|
|
1470
1792
|
}
|
|
1793
|
+
static collectPartDiagnostics(slideXml, rels, context) {
|
|
1794
|
+
if (/<p:transition\b/.test(slideXml)) {
|
|
1795
|
+
this.addObjectDiagnostic(context, 'transition', 'omitted');
|
|
1796
|
+
}
|
|
1797
|
+
if (/<p:timing\b/.test(slideXml)) {
|
|
1798
|
+
this.addObjectDiagnostic(context, 'animation', 'omitted');
|
|
1799
|
+
}
|
|
1800
|
+
const hyperlinkCount = (slideXml.match(/<a:hlink(?:Click|MouseOver)\b|\baction="ppaction:/g) || []).length;
|
|
1801
|
+
for (let i = 0; i < hyperlinkCount; i++) {
|
|
1802
|
+
this.addObjectDiagnostic(context, 'hyperlink', 'simplified');
|
|
1803
|
+
}
|
|
1804
|
+
if (/<p:oleObj\b|<p:embeddedFont\b/.test(slideXml)) {
|
|
1805
|
+
this.addObjectDiagnostic(context, 'ole', 'placeholder');
|
|
1806
|
+
}
|
|
1807
|
+
if (/<p:contentPart\b|<p14:media\b/.test(slideXml)) {
|
|
1808
|
+
this.addObjectDiagnostic(context, 'media', 'omitted');
|
|
1809
|
+
}
|
|
1810
|
+
for (const relationship of rels) {
|
|
1811
|
+
if (/\/(?:audio|video|media)$/.test(relationship.type)) {
|
|
1812
|
+
this.addObjectDiagnostic(context, 'media', 'omitted', undefined, {
|
|
1813
|
+
target: relationship.target
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
else if (/\/notesSlide$/.test(relationship.type)) {
|
|
1817
|
+
this.addObjectDiagnostic(context, 'notes', 'omitted', undefined, {
|
|
1818
|
+
target: relationship.target
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
static addObjectDiagnostic(context, objectKind, handling, frame, args = {}) {
|
|
1824
|
+
const diagnostic = {
|
|
1825
|
+
severity: 'warning',
|
|
1826
|
+
code: `pptx.${objectKind}.${handling}`,
|
|
1827
|
+
messageKey: 'diag.ppt.unsupported-object',
|
|
1828
|
+
args: {
|
|
1829
|
+
objectKind,
|
|
1830
|
+
handling,
|
|
1831
|
+
...args
|
|
1832
|
+
},
|
|
1833
|
+
location: `slide:${context.slideNumber}`,
|
|
1834
|
+
slideNumber: context.slideNumber,
|
|
1835
|
+
objectKind,
|
|
1836
|
+
handling,
|
|
1837
|
+
...(frame
|
|
1838
|
+
? {
|
|
1839
|
+
frame: {
|
|
1840
|
+
x: frame.x,
|
|
1841
|
+
y: frame.y,
|
|
1842
|
+
width: frame.width,
|
|
1843
|
+
height: frame.height
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
: {}),
|
|
1847
|
+
sourcePath: context.sourcePath
|
|
1848
|
+
};
|
|
1849
|
+
context.diagnostics.push(diagnostic);
|
|
1850
|
+
}
|
|
1851
|
+
static isSupportedPresetGeometry(preset) {
|
|
1852
|
+
return new Set([
|
|
1853
|
+
'rect',
|
|
1854
|
+
'roundRect',
|
|
1855
|
+
'ellipse',
|
|
1856
|
+
'oval',
|
|
1857
|
+
'triangle',
|
|
1858
|
+
'rightArrow',
|
|
1859
|
+
'leftArrow',
|
|
1860
|
+
'upArrow',
|
|
1861
|
+
'downArrow',
|
|
1862
|
+
'line',
|
|
1863
|
+
'straightConnector1'
|
|
1864
|
+
]).has(preset);
|
|
1865
|
+
}
|
|
1866
|
+
static async resolveImageSource(zip, target, context, frame) {
|
|
1867
|
+
const selectedTarget = this.resolveImageTarget(zip, target);
|
|
1868
|
+
const sourceExt = path.extname(target).toLowerCase();
|
|
1869
|
+
const selectedExt = path.extname(selectedTarget).toLowerCase();
|
|
1870
|
+
const metafile = sourceExt === '.emf' || sourceExt === '.wmf';
|
|
1871
|
+
const media = zip.file(selectedTarget);
|
|
1872
|
+
if (!media) {
|
|
1873
|
+
this.addObjectDiagnostic(context, 'image', 'placeholder', frame, {
|
|
1874
|
+
reason: 'missing-entry',
|
|
1875
|
+
target
|
|
1876
|
+
});
|
|
1877
|
+
return undefined;
|
|
1878
|
+
}
|
|
1879
|
+
if (!metafile || selectedTarget !== target) {
|
|
1880
|
+
const base64 = await media.async('base64');
|
|
1881
|
+
return {
|
|
1882
|
+
src: `data:${this.getMimeTypeByExtension(selectedTarget)};base64,${base64}`,
|
|
1883
|
+
vectorFallback: metafile && selectedTarget !== target
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
// Preferred: convert the actual metafile to a raster/vector via the injected renderer.
|
|
1887
|
+
if (context.deps.renderMetafile) {
|
|
1888
|
+
try {
|
|
1889
|
+
context.guard.checkpoint(target);
|
|
1890
|
+
const bytes = await media.async('uint8array');
|
|
1891
|
+
const converted = await context.deps.renderMetafile(bytes, sourceExt.slice(1), context.guard.options.signal);
|
|
1892
|
+
context.guard.checkpoint(target);
|
|
1893
|
+
if (typeof converted === 'string' && converted) {
|
|
1894
|
+
if (/^(?:data:|blob:|https?:)/i.test(converted)) {
|
|
1895
|
+
return { src: converted };
|
|
1896
|
+
}
|
|
1897
|
+
if (converted.trimStart().startsWith('<svg')) {
|
|
1898
|
+
return {
|
|
1899
|
+
src: `data:image/svg+xml;charset=utf-8,${encodeURIComponent(converted)}`
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
else if (converted instanceof Uint8Array && converted.byteLength > 0) {
|
|
1904
|
+
let binary = '';
|
|
1905
|
+
for (let i = 0; i < converted.length; i += 0x8000) {
|
|
1906
|
+
binary += String.fromCharCode(...converted.subarray(i, i + 0x8000));
|
|
1907
|
+
}
|
|
1908
|
+
return { src: `data:image/png;base64,${btoa(binary)}` };
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
catch (error) {
|
|
1912
|
+
if (error?.name === 'PptxLimitError')
|
|
1913
|
+
throw error;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
// No conversion available/successful: a clean placeholder is safer than
|
|
1917
|
+
// substituting an unrelated same-directory raster (in PPTX every image lives
|
|
1918
|
+
// in ppt/media/, so a name-mismatched raster is almost certainly a different asset).
|
|
1919
|
+
this.addObjectDiagnostic(context, 'image', 'placeholder', frame, {
|
|
1920
|
+
reason: context.deps.renderMetafile
|
|
1921
|
+
? 'metafile-conversion-failed'
|
|
1922
|
+
: 'metafile-converter-missing',
|
|
1923
|
+
type: sourceExt.slice(1)
|
|
1924
|
+
});
|
|
1925
|
+
return undefined;
|
|
1926
|
+
}
|
|
1471
1927
|
static resolveImageTarget(zip, target) {
|
|
1472
1928
|
const ext = path.extname(target).toLowerCase();
|
|
1473
1929
|
if (ext !== '.emf' && ext !== '.wmf') {
|
|
@@ -1475,15 +1931,13 @@ export class PptxXmlParser {
|
|
|
1475
1931
|
}
|
|
1476
1932
|
const dir = path.posix.dirname(target);
|
|
1477
1933
|
const base = path.posix.basename(target, ext);
|
|
1478
|
-
const exactCandidates = ['.png', '.jpg', '.jpeg', '.webp', '.gif'
|
|
1934
|
+
const exactCandidates = ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.svg']
|
|
1935
|
+
.map((e) => path.posix.join(dir, `${base}${e}`));
|
|
1479
1936
|
for (const candidate of exactCandidates) {
|
|
1480
1937
|
if (zip.file(candidate))
|
|
1481
1938
|
return candidate;
|
|
1482
1939
|
}
|
|
1483
|
-
|
|
1484
|
-
.filter((name) => name.startsWith(`${dir}/`) && /\.(png|jpe?g|webp|gif)$/i.test(name))
|
|
1485
|
-
.sort();
|
|
1486
|
-
return anyRaster[0] || target;
|
|
1940
|
+
return target;
|
|
1487
1941
|
}
|
|
1488
1942
|
static getMimeTypeByExtension(filePath) {
|
|
1489
1943
|
const ext = path.extname(filePath).toLowerCase();
|