@office-open/pptx 0.3.0 → 0.3.1
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.mts +89 -28
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +498 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __reExport, r as __require, t as __exportAll } from "./_chunks/chunk-C8fdooHg.mjs";
|
|
2
|
-
import { AppProperties, BaseXmlComponent, BuilderElement, Formatter, ImportedXmlComponent, NextAttributeComponent, Relationships, StringContainer, XmlComponent, chartAttr, convertEmuToInches as emusToInches, convertEmuToPixels as emusToPixels, convertEmuToPoints as emusToPoints, convertInchesToEmu as inchesToEmus, convertPixelsToEmu as pixelsToEmus, convertPointsToEmu as pointsToEmus, getImageType, hashedId, parseCoreProperties, parseRels, readXmlFromZip, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, unzipToMap, wrapEl } from "@office-open/core";
|
|
2
|
+
import { AppProperties, BaseXmlComponent, BuilderElement, Formatter, ImportedXmlComponent, NextAttributeComponent, RawPassthrough, Relationships, StringContainer, XmlComponent, chartAttr, convertEmuToInches as emusToInches, convertEmuToPixels as emusToPixels, convertEmuToPoints as emusToPoints, convertInchesToEmu as inchesToEmus, convertPixelsToEmu as pixelsToEmus, convertPointsToEmu as pointsToEmus, getImageType, hashedId, isRaw, parseCoreProperties, parseRels, readAllXmlParts, readXmlFromZip, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, unzipToMap, wrapEl } from "@office-open/core";
|
|
3
3
|
import { ChartCollection, ChartTitle, createChartType } from "@office-open/core/chart";
|
|
4
4
|
import { BevelPresetType, CompoundLine, LineCap, LineJoin, PathShadeType, PenAlignment, PresetDash, PresetMaterialType, TileFlipMode, buildFill, createBevel, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createGradientFill, createGradientStop, createOutline, createOutline as createOutline$1, createScene3D, createShape3D, extractBlipFillMedia } from "@office-open/core/drawingml";
|
|
5
5
|
import { COLOR_CATEGORIES, LAYOUT_CATEGORIES, STYLE_CATEGORIES, SmartArtCollection, createDataModel } from "@office-open/core/smartart";
|
|
@@ -492,7 +492,7 @@ function buildRunProperties(options, hyperlinkKey, fillObject) {
|
|
|
492
492
|
if (options.lang) attrs.lang = options.lang;
|
|
493
493
|
if (options.strike) attrs.strike = StrikeStyle[options.strike];
|
|
494
494
|
if (options.baseline !== void 0) attrs.baseline = options.baseline;
|
|
495
|
-
if (options.capitalization) attrs.cap = TextCapitalization[options.capitalization];
|
|
495
|
+
if (options.capitalization) attrs.cap = TextCapitalization[options.capitalization] ?? options.capitalization;
|
|
496
496
|
if (options.spacing !== void 0) attrs.spc = options.spacing;
|
|
497
497
|
if (options.noProof !== void 0) attrs.noProof = options.noProof;
|
|
498
498
|
if (options.dirty !== void 0) attrs.dirty = options.dirty;
|
|
@@ -4749,7 +4749,10 @@ function resolveSlideMediaPath(relsTarget) {
|
|
|
4749
4749
|
if (relsTarget.startsWith("../")) return `ppt/${relsTarget.replace("../", "")}`;
|
|
4750
4750
|
return `ppt/${relsTarget}`;
|
|
4751
4751
|
}
|
|
4752
|
+
const relsCache = /* @__PURE__ */ new Map();
|
|
4752
4753
|
function getSlideRels(ctx, slidePath) {
|
|
4754
|
+
const cached = relsCache.get(slidePath);
|
|
4755
|
+
if (cached) return cached;
|
|
4753
4756
|
const relsMap = /* @__PURE__ */ new Map();
|
|
4754
4757
|
const relsPath = slidePath.replace("ppt/slides/", "ppt/slides/_rels/") + ".rels";
|
|
4755
4758
|
const rels = parseRels(ctx.zip, relsPath);
|
|
@@ -4757,6 +4760,7 @@ function getSlideRels(ctx, slidePath) {
|
|
|
4757
4760
|
target: rel.target,
|
|
4758
4761
|
type: rel.type
|
|
4759
4762
|
});
|
|
4763
|
+
relsCache.set(slidePath, relsMap);
|
|
4760
4764
|
return relsMap;
|
|
4761
4765
|
}
|
|
4762
4766
|
//#endregion
|
|
@@ -4814,16 +4818,72 @@ function parseFill(spPr) {
|
|
|
4814
4818
|
color
|
|
4815
4819
|
});
|
|
4816
4820
|
}
|
|
4817
|
-
const
|
|
4818
|
-
return {
|
|
4821
|
+
const result = {
|
|
4819
4822
|
type: "gradient",
|
|
4820
|
-
stops
|
|
4821
|
-
...angle !== void 0 && { angle }
|
|
4823
|
+
stops
|
|
4822
4824
|
};
|
|
4825
|
+
const lin = findChild(gradFill, "a:lin");
|
|
4826
|
+
if (lin) {
|
|
4827
|
+
const angle = attrNum(lin, "ang");
|
|
4828
|
+
const scaled = attr(lin, "scaled");
|
|
4829
|
+
if (angle !== void 0) result.angle = angle;
|
|
4830
|
+
if (scaled !== void 0) result.scaled = scaled === "1";
|
|
4831
|
+
}
|
|
4832
|
+
const path = findChild(gradFill, "a:path");
|
|
4833
|
+
if (path) {
|
|
4834
|
+
result.path = attr(path, "path") ?? "circle";
|
|
4835
|
+
const fillToRect = findChild(path, "a:fillToRect");
|
|
4836
|
+
if (fillToRect) result.fillToRect = {
|
|
4837
|
+
l: attr(fillToRect, "l"),
|
|
4838
|
+
t: attr(fillToRect, "t"),
|
|
4839
|
+
r: attr(fillToRect, "r"),
|
|
4840
|
+
b: attr(fillToRect, "b")
|
|
4841
|
+
};
|
|
4842
|
+
}
|
|
4843
|
+
return result;
|
|
4823
4844
|
}
|
|
4824
4845
|
if (findChild(spPr, "a:noFill")) return { type: "none" };
|
|
4825
|
-
|
|
4826
|
-
if (
|
|
4846
|
+
const pattFill = findChild(spPr, "a:pattFill");
|
|
4847
|
+
if (pattFill) {
|
|
4848
|
+
const prst = attr(pattFill, "prst");
|
|
4849
|
+
const fgClr = findChild(pattFill, "a:fgClr");
|
|
4850
|
+
const bgClr = findChild(pattFill, "a:bgClr");
|
|
4851
|
+
const fg = fgClr ? findChild(fgClr, "a:srgbClr") ? attr(findChild(fgClr, "a:srgbClr"), "val") : findChild(fgClr, "a:schemeClr") ? attr(findChild(fgClr, "a:schemeClr"), "val") : void 0 : void 0;
|
|
4852
|
+
const bg = bgClr ? findChild(bgClr, "a:srgbClr") ? attr(findChild(bgClr, "a:srgbClr"), "val") : findChild(bgClr, "a:schemeClr") ? attr(findChild(bgClr, "a:schemeClr"), "val") : void 0 : void 0;
|
|
4853
|
+
return {
|
|
4854
|
+
type: "pattern",
|
|
4855
|
+
pattern: prst,
|
|
4856
|
+
...fg && { fg },
|
|
4857
|
+
...bg && { bg }
|
|
4858
|
+
};
|
|
4859
|
+
}
|
|
4860
|
+
const blipFill = findChild(spPr, "a:blipFill");
|
|
4861
|
+
if (blipFill) {
|
|
4862
|
+
const result = { type: "blip" };
|
|
4863
|
+
const blip = findChild(blipFill, "a:blip");
|
|
4864
|
+
if (blip) {
|
|
4865
|
+
const embed = attr(blip, "r:embed");
|
|
4866
|
+
const link = attr(blip, "r:link");
|
|
4867
|
+
if (embed) result.embed = embed;
|
|
4868
|
+
if (link) result.link = link;
|
|
4869
|
+
}
|
|
4870
|
+
const stretch = findChild(blipFill, "a:stretch");
|
|
4871
|
+
if (stretch) {
|
|
4872
|
+
result.stretch = true;
|
|
4873
|
+
const fillRect = findChild(stretch, "a:fillRect");
|
|
4874
|
+
if (fillRect) result.fillRect = {
|
|
4875
|
+
l: attr(fillRect, "l"),
|
|
4876
|
+
t: attr(fillRect, "t"),
|
|
4877
|
+
r: attr(fillRect, "r"),
|
|
4878
|
+
b: attr(fillRect, "b")
|
|
4879
|
+
};
|
|
4880
|
+
}
|
|
4881
|
+
if (findChild(blipFill, "a:tile")) {
|
|
4882
|
+
delete result.stretch;
|
|
4883
|
+
result.tile = true;
|
|
4884
|
+
}
|
|
4885
|
+
return result;
|
|
4886
|
+
}
|
|
4827
4887
|
}
|
|
4828
4888
|
function parseOutline(spPr) {
|
|
4829
4889
|
const ln = findChild(spPr, "a:ln");
|
|
@@ -4851,6 +4911,33 @@ function parseOutline(spPr) {
|
|
|
4851
4911
|
}
|
|
4852
4912
|
if (findChild(ln, "a:round")) result.round = true;
|
|
4853
4913
|
if (findChild(ln, "a:bevel")) result.bevel = true;
|
|
4914
|
+
const headEnd = findChild(ln, "a:headEnd");
|
|
4915
|
+
if (headEnd) {
|
|
4916
|
+
const he = {};
|
|
4917
|
+
const type = attr(headEnd, "type");
|
|
4918
|
+
const w = attrNum(headEnd, "w");
|
|
4919
|
+
const len = attrNum(headEnd, "len");
|
|
4920
|
+
if (type) he.type = type;
|
|
4921
|
+
if (w !== void 0) he.width = w;
|
|
4922
|
+
if (len !== void 0) he.length = len;
|
|
4923
|
+
if (Object.keys(he).length > 0) result.headEnd = he;
|
|
4924
|
+
}
|
|
4925
|
+
const tailEnd = findChild(ln, "a:tailEnd");
|
|
4926
|
+
if (tailEnd) {
|
|
4927
|
+
const te = {};
|
|
4928
|
+
const type = attr(tailEnd, "type");
|
|
4929
|
+
const w = attrNum(tailEnd, "w");
|
|
4930
|
+
const len = attrNum(tailEnd, "len");
|
|
4931
|
+
if (type) te.type = type;
|
|
4932
|
+
if (w !== void 0) te.width = w;
|
|
4933
|
+
if (len !== void 0) te.length = len;
|
|
4934
|
+
if (Object.keys(te).length > 0) result.tailEnd = te;
|
|
4935
|
+
}
|
|
4936
|
+
const join = findChild(ln, "a:join");
|
|
4937
|
+
if (join) {
|
|
4938
|
+
const type = attr(join, "type");
|
|
4939
|
+
if (type) result.join = type;
|
|
4940
|
+
}
|
|
4854
4941
|
if (findChild(ln, "a:noFill")) result.width = 0;
|
|
4855
4942
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
4856
4943
|
}
|
|
@@ -4878,13 +4965,55 @@ function parseEffects(spPr) {
|
|
|
4878
4965
|
}
|
|
4879
4966
|
result.outerShadow = shadow;
|
|
4880
4967
|
}
|
|
4881
|
-
|
|
4968
|
+
const innerShdw = findChild(effectLst, "a:innerShdw");
|
|
4969
|
+
if (innerShdw) {
|
|
4970
|
+
const shadow = {};
|
|
4971
|
+
const blurRad = attrNum(innerShdw, "blurRad");
|
|
4972
|
+
const dist = attrNum(innerShdw, "dist");
|
|
4973
|
+
const dir = attrNum(innerShdw, "dir");
|
|
4974
|
+
const rotWithShape = attr(innerShdw, "rotWithShape");
|
|
4975
|
+
if (blurRad !== void 0) shadow.blurRadius = blurRad;
|
|
4976
|
+
if (dist !== void 0) shadow.distance = dist;
|
|
4977
|
+
if (dir !== void 0) shadow.direction = dir;
|
|
4978
|
+
if (rotWithShape !== void 0) shadow.rotateWithShape = rotWithShape === "1";
|
|
4979
|
+
const solidFill = findChild(innerShdw, "a:solidFill");
|
|
4980
|
+
if (solidFill) {
|
|
4981
|
+
const srgbClr = findChild(solidFill, "a:srgbClr");
|
|
4982
|
+
if (srgbClr) shadow.color = attr(srgbClr, "val");
|
|
4983
|
+
}
|
|
4984
|
+
result.innerShadow = shadow;
|
|
4985
|
+
}
|
|
4882
4986
|
const glow = findChild(effectLst, "a:glow");
|
|
4883
4987
|
if (glow) {
|
|
4884
4988
|
const radius = attrNum(glow, "rad");
|
|
4885
|
-
|
|
4989
|
+
const glowObj = {};
|
|
4990
|
+
if (radius !== void 0) glowObj.radius = radius;
|
|
4991
|
+
const solidFill = findChild(glow, "a:solidFill");
|
|
4992
|
+
if (solidFill) {
|
|
4993
|
+
const srgbClr = findChild(solidFill, "a:srgbClr");
|
|
4994
|
+
if (srgbClr) glowObj.color = attr(srgbClr, "val");
|
|
4995
|
+
}
|
|
4996
|
+
if (Object.keys(glowObj).length > 0) result.glow = glowObj;
|
|
4997
|
+
}
|
|
4998
|
+
const reflection = findChild(effectLst, "a:reflection");
|
|
4999
|
+
if (reflection) {
|
|
5000
|
+
const refObj = {};
|
|
5001
|
+
const blurRad = attrNum(reflection, "blurRad");
|
|
5002
|
+
const dist = attrNum(reflection, "dist");
|
|
5003
|
+
const dir = attrNum(reflection, "dir");
|
|
5004
|
+
const fadeDir = attrNum(reflection, "fadeDir");
|
|
5005
|
+
const stA = attrNum(reflection, "stA");
|
|
5006
|
+
const stB = attrNum(reflection, "stB");
|
|
5007
|
+
const rotWithShape = attr(reflection, "rotWithShape");
|
|
5008
|
+
if (blurRad !== void 0) refObj.blurRadius = blurRad;
|
|
5009
|
+
if (dist !== void 0) refObj.distance = dist;
|
|
5010
|
+
if (dir !== void 0) refObj.direction = dir;
|
|
5011
|
+
if (fadeDir !== void 0) refObj.fadeDirection = fadeDir;
|
|
5012
|
+
if (stA !== void 0) refObj.startAlpha = stA;
|
|
5013
|
+
if (stB !== void 0) refObj.endAlpha = stB;
|
|
5014
|
+
if (rotWithShape !== void 0) refObj.rotateWithShape = rotWithShape === "1";
|
|
5015
|
+
if (Object.keys(refObj).length > 0) result.reflection = refObj;
|
|
4886
5016
|
}
|
|
4887
|
-
if (findChild(effectLst, "a:reflection")) result.reflection = {};
|
|
4888
5017
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
4889
5018
|
}
|
|
4890
5019
|
//#endregion
|
|
@@ -5209,6 +5338,23 @@ function parsePptxTable(graphicFrame, ctx) {
|
|
|
5209
5338
|
}
|
|
5210
5339
|
const tbl = findDeep(graphicFrame, "a:tbl")[0];
|
|
5211
5340
|
if (!tbl) return void 0;
|
|
5341
|
+
const tblPr = findChild(tbl, "a:tblPr");
|
|
5342
|
+
if (tblPr) {
|
|
5343
|
+
const bandRow = attr(tblPr, "bandRow");
|
|
5344
|
+
const bandCol = attr(tblPr, "bandCol");
|
|
5345
|
+
const firstRow = attr(tblPr, "firstRow");
|
|
5346
|
+
const firstCol = attr(tblPr, "firstCol");
|
|
5347
|
+
const lastRow = attr(tblPr, "lastRow");
|
|
5348
|
+
const lastCol = attr(tblPr, "lastCol");
|
|
5349
|
+
if (bandRow || bandCol || firstRow || firstCol || lastRow || lastCol) result.tableStyle = {
|
|
5350
|
+
...bandRow === "1" && { bandRow: true },
|
|
5351
|
+
...bandCol === "1" && { bandCol: true },
|
|
5352
|
+
...firstRow === "1" && { firstRow: true },
|
|
5353
|
+
...firstCol === "1" && { firstCol: true },
|
|
5354
|
+
...lastRow === "1" && { lastRow: true },
|
|
5355
|
+
...lastCol === "1" && { lastCol: true }
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5212
5358
|
for (const tr of tbl.elements ?? []) {
|
|
5213
5359
|
if (tr.name !== "a:tr") continue;
|
|
5214
5360
|
const row = { cells: [] };
|
|
@@ -5250,6 +5396,32 @@ function parsePptxTable(graphicFrame, ctx) {
|
|
|
5250
5396
|
}
|
|
5251
5397
|
const tcW = attrNum(tcPr, "w");
|
|
5252
5398
|
if (tcW !== void 0) cell.width = tcW;
|
|
5399
|
+
const tcBorders = findChild(tcPr, "a:tcBorders");
|
|
5400
|
+
if (tcBorders) {
|
|
5401
|
+
const borders = {};
|
|
5402
|
+
for (const border of tcBorders.elements ?? []) if (border.name?.startsWith("a:")) {
|
|
5403
|
+
const borderName = border.name.replace("a:", "");
|
|
5404
|
+
const w = attrNum(border, "w");
|
|
5405
|
+
if (w !== void 0) {
|
|
5406
|
+
const borderDef = { width: w };
|
|
5407
|
+
const solidFill = findChild(border, "a:solidFill");
|
|
5408
|
+
if (solidFill) {
|
|
5409
|
+
const srgbClr = findChild(solidFill, "a:srgbClr");
|
|
5410
|
+
if (srgbClr) {
|
|
5411
|
+
const color = attr(srgbClr, "val");
|
|
5412
|
+
if (color) borderDef.color = color;
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
const prstDash = findChild(border, "a:prstDash");
|
|
5416
|
+
if (prstDash) {
|
|
5417
|
+
const dashVal = attr(prstDash, "val");
|
|
5418
|
+
if (dashVal) borderDef.dashStyle = dashVal;
|
|
5419
|
+
}
|
|
5420
|
+
borders[borderName] = borderDef;
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
if (Object.keys(borders).length > 0) cell.borders = borders;
|
|
5424
|
+
}
|
|
5253
5425
|
}
|
|
5254
5426
|
const txBody = findChild(tc, "a:txBody");
|
|
5255
5427
|
if (txBody) {
|
|
@@ -5273,11 +5445,25 @@ function parseSlide(slideXml, ctx, slidePath) {
|
|
|
5273
5445
|
if (bg) result.background = parseSlideBackground(bg);
|
|
5274
5446
|
const spTree = findChild(cSld, "p:spTree");
|
|
5275
5447
|
if (spTree) for (const child of spTree.elements ?? []) {
|
|
5448
|
+
if (child.name === "p:nvGrpSpPr" || child.name === "p:grpSpPr") continue;
|
|
5276
5449
|
const parsed = parseShapeTreeElement(child, ctx, slideRels);
|
|
5277
5450
|
if (parsed) result.children.push(parsed);
|
|
5278
5451
|
}
|
|
5279
5452
|
const transition = findChild(slideXml, "p:transition");
|
|
5280
5453
|
if (transition) result.transition = parseTransition(transition);
|
|
5454
|
+
let notesTarget;
|
|
5455
|
+
for (const [, rel] of slideRels) if (rel.type.includes("notesSlide")) {
|
|
5456
|
+
notesTarget = rel.target;
|
|
5457
|
+
break;
|
|
5458
|
+
}
|
|
5459
|
+
if (notesTarget) {
|
|
5460
|
+
const notesPath = notesTarget.startsWith("../") ? notesTarget.replace("../", "ppt/") : `ppt/${notesTarget}`;
|
|
5461
|
+
const notesXml = readXmlFromZip(ctx.zip, notesPath);
|
|
5462
|
+
if (notesXml) {
|
|
5463
|
+
const notesContent = parseSlideNotes(notesXml, ctx);
|
|
5464
|
+
if (notesContent) result.notes = notesContent;
|
|
5465
|
+
}
|
|
5466
|
+
}
|
|
5281
5467
|
return result;
|
|
5282
5468
|
}
|
|
5283
5469
|
function parseShapeTreeElement(el, ctx, slideRels) {
|
|
@@ -5285,9 +5471,80 @@ function parseShapeTreeElement(el, ctx, slideRels) {
|
|
|
5285
5471
|
case "p:sp": return parseShape(el, ctx, slideRels);
|
|
5286
5472
|
case "p:pic": return parsePicture(el, ctx, slideRels);
|
|
5287
5473
|
case "p:cxnSp": return parseConnector(el, ctx);
|
|
5288
|
-
case "p:graphicFrame": return parsePptxTable(el, ctx)
|
|
5289
|
-
|
|
5290
|
-
|
|
5474
|
+
case "p:graphicFrame": return parsePptxTable(el, ctx) ?? {
|
|
5475
|
+
$raw: true,
|
|
5476
|
+
element: el
|
|
5477
|
+
};
|
|
5478
|
+
case "p:grpSp": return parseGroupShape(el, ctx, slideRels);
|
|
5479
|
+
default: return {
|
|
5480
|
+
$raw: true,
|
|
5481
|
+
element: el
|
|
5482
|
+
};
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
5485
|
+
/** Recursively parse group shapes */
|
|
5486
|
+
function parseGroupShape(grpSp, ctx, slideRels) {
|
|
5487
|
+
const result = { $type: "groupShape" };
|
|
5488
|
+
const nvSpPr = findChild(grpSp, "p:nvGrpSpPr");
|
|
5489
|
+
const cNvPr = findChild(nvSpPr, "p:cNvPr") ?? findChild(nvSpPr, "p:nvPr");
|
|
5490
|
+
if (cNvPr) {
|
|
5491
|
+
const id = attrNum(cNvPr, "id");
|
|
5492
|
+
const name = attr(cNvPr, "name");
|
|
5493
|
+
if (id !== void 0) result.id = id;
|
|
5494
|
+
if (name) result.name = name;
|
|
5495
|
+
}
|
|
5496
|
+
const grpSpPr = findChild(grpSp, "p:grpSpPr");
|
|
5497
|
+
if (grpSpPr) {
|
|
5498
|
+
const xfrm = findChild(grpSpPr, "a:xfrm");
|
|
5499
|
+
if (xfrm) {
|
|
5500
|
+
const off = findChild(xfrm, "a:off");
|
|
5501
|
+
const ext = findChild(xfrm, "a:ext");
|
|
5502
|
+
if (off) {
|
|
5503
|
+
result.x = attrNum(off, "x");
|
|
5504
|
+
result.y = attrNum(off, "y");
|
|
5505
|
+
}
|
|
5506
|
+
if (ext) {
|
|
5507
|
+
result.width = attrNum(ext, "cx");
|
|
5508
|
+
result.height = attrNum(ext, "cy");
|
|
5509
|
+
}
|
|
5510
|
+
const rot = attrNum(xfrm, "rot");
|
|
5511
|
+
if (rot !== void 0 && rot !== 0) result.rotation = rot / 6e4;
|
|
5512
|
+
const flipH = attr(xfrm, "flipH");
|
|
5513
|
+
const flipV = attr(xfrm, "flipV");
|
|
5514
|
+
if (flipH === "1") result.flipH = true;
|
|
5515
|
+
if (flipV === "1") result.flipV = true;
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
const spTree = findChild(grpSp, "p:spTree");
|
|
5519
|
+
if (spTree) {
|
|
5520
|
+
const children = [];
|
|
5521
|
+
for (const child of spTree.elements ?? []) {
|
|
5522
|
+
if (child.name === "p:nvGrpSpPr" || child.name === "p:grpSpPr") continue;
|
|
5523
|
+
const parsed = parseShapeTreeElement(child, ctx, slideRels);
|
|
5524
|
+
if (parsed) children.push(parsed);
|
|
5525
|
+
}
|
|
5526
|
+
if (children.length > 0) result.children = children;
|
|
5527
|
+
}
|
|
5528
|
+
return result;
|
|
5529
|
+
}
|
|
5530
|
+
/** Parse slide notes content */
|
|
5531
|
+
function parseSlideNotes(notesXml, ctx) {
|
|
5532
|
+
const cSld = findChild(notesXml, "p:cSld");
|
|
5533
|
+
if (!cSld) return void 0;
|
|
5534
|
+
const spTree = findChild(cSld, "p:spTree");
|
|
5535
|
+
if (!spTree) return void 0;
|
|
5536
|
+
for (const child of spTree.elements ?? []) if (child.name === "p:sp") {
|
|
5537
|
+
const nvPr = findChild(findChild(child, "p:nvSpPr"), "p:nvPr");
|
|
5538
|
+
if (nvPr) {
|
|
5539
|
+
const ph = findChild(nvPr, "p:ph");
|
|
5540
|
+
if (ph && (attr(ph, "type") === "body" || attr(ph, "type") === void 0)) {
|
|
5541
|
+
const txBody = findChild(child, "p:txBody");
|
|
5542
|
+
if (txBody) {
|
|
5543
|
+
const parsed = parseTextBody(txBody, ctx);
|
|
5544
|
+
if (parsed.paragraphs && parsed.paragraphs.length > 0) return parsed.paragraphs;
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5291
5548
|
}
|
|
5292
5549
|
}
|
|
5293
5550
|
function parseSlideBackground(bg) {
|
|
@@ -5304,22 +5561,31 @@ function parseSlideBackground(bg) {
|
|
|
5304
5561
|
}
|
|
5305
5562
|
function parseTransition(transition) {
|
|
5306
5563
|
const result = {};
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5564
|
+
const spd = attr(transition, "spd");
|
|
5565
|
+
const advClick = attr(transition, "advClick");
|
|
5566
|
+
const advTm = attrNum(transition, "advTm");
|
|
5567
|
+
const p14Dur = attrNum(transition, "p14:dur");
|
|
5568
|
+
if (spd) result.speed = spd;
|
|
5569
|
+
if (advClick !== void 0) result.advanceOnClick = advClick === "1";
|
|
5570
|
+
if (advTm !== void 0) result.advanceAfterMs = advTm;
|
|
5571
|
+
if (p14Dur !== void 0) result.durationMs = p14Dur;
|
|
5572
|
+
for (const child of transition.elements ?? []) if (child.name?.startsWith("p:") && child.name !== "p:transition") {
|
|
5573
|
+
result.type = child.name.replace("p:", "");
|
|
5574
|
+
const p14Prst = findChild(child, "p14:prst");
|
|
5575
|
+
if (p14Prst) {
|
|
5576
|
+
const prstVal = attr(p14Prst, "val");
|
|
5577
|
+
if (prstVal) result.preset = prstVal;
|
|
5578
|
+
}
|
|
5314
5579
|
break;
|
|
5315
5580
|
}
|
|
5316
5581
|
return result;
|
|
5317
5582
|
}
|
|
5318
5583
|
//#endregion
|
|
5319
5584
|
//#region src/parse/document.ts
|
|
5320
|
-
async function parsePptx(data) {
|
|
5585
|
+
async function parsePptx(data, options) {
|
|
5321
5586
|
const zip = unzipToMap(data);
|
|
5322
5587
|
const ctx = createPptxParseContext(zip);
|
|
5588
|
+
const includeRawParts = options?.includeRawParts !== false;
|
|
5323
5589
|
const coreProps = parseCoreProperties(zip);
|
|
5324
5590
|
const slides = [];
|
|
5325
5591
|
for (const slidePath of ctx.slidePaths) {
|
|
@@ -5328,8 +5594,11 @@ async function parsePptx(data) {
|
|
|
5328
5594
|
const slide = parseSlide(slideXml, ctx, slidePath);
|
|
5329
5595
|
slides.push(slide);
|
|
5330
5596
|
}
|
|
5597
|
+
let $parts;
|
|
5598
|
+
if (includeRawParts) $parts = readAllXmlParts(zip, { skipPaths: ctx.slidePaths });
|
|
5331
5599
|
return {
|
|
5332
5600
|
slides,
|
|
5601
|
+
...$parts && { $parts },
|
|
5333
5602
|
...ctx.slideWidth !== void 0 && { slideWidth: ctx.slideWidth },
|
|
5334
5603
|
...ctx.slideHeight !== void 0 && { slideHeight: ctx.slideHeight },
|
|
5335
5604
|
...coreProps.title && { title: coreProps.title },
|
|
@@ -5340,6 +5609,210 @@ async function parsePptx(data) {
|
|
|
5340
5609
|
...coreProps.lastModifiedBy && { lastModifiedBy: coreProps.lastModifiedBy }
|
|
5341
5610
|
};
|
|
5342
5611
|
}
|
|
5612
|
+
//#endregion
|
|
5613
|
+
//#region src/parse/convert.ts
|
|
5614
|
+
const EMU_PER_PIXEL = 9525;
|
|
5615
|
+
/**
|
|
5616
|
+
* Convert parsed slide children to constructor-ready BaseXmlComponent[].
|
|
5617
|
+
*/
|
|
5618
|
+
function toSlideChildren(children) {
|
|
5619
|
+
return children.map(convertSlideChild);
|
|
5620
|
+
}
|
|
5621
|
+
function convertSlideChild(child) {
|
|
5622
|
+
if (isRaw(child)) return new RawPassthrough(child.element);
|
|
5623
|
+
switch (child.$type) {
|
|
5624
|
+
case "shape": return convertShape(child);
|
|
5625
|
+
case "picture": return convertPicture(child);
|
|
5626
|
+
case "connectorShape": return convertConnectorShape(child);
|
|
5627
|
+
case "table": return convertTable(child);
|
|
5628
|
+
case "groupShape": return convertGroupShape(child);
|
|
5629
|
+
default: return new RawPassthrough(child.element);
|
|
5630
|
+
}
|
|
5631
|
+
}
|
|
5632
|
+
function convertShape(json) {
|
|
5633
|
+
const { paragraphs, fill, outline, x, y, width, height, rotation, ...rest } = json;
|
|
5634
|
+
return new Shape({
|
|
5635
|
+
...rest,
|
|
5636
|
+
x: x != null ? Math.round(x / EMU_PER_PIXEL) : void 0,
|
|
5637
|
+
y: y != null ? Math.round(y / EMU_PER_PIXEL) : void 0,
|
|
5638
|
+
width: width != null ? Math.round(width / EMU_PER_PIXEL) : void 0,
|
|
5639
|
+
height: height != null ? Math.round(height / EMU_PER_PIXEL) : void 0,
|
|
5640
|
+
rotation: rotation != null ? rotation * 6e4 : void 0,
|
|
5641
|
+
fill: convertFill(fill),
|
|
5642
|
+
outline: convertOutline(outline),
|
|
5643
|
+
paragraphs: paragraphs?.map(convertParagraph)
|
|
5644
|
+
});
|
|
5645
|
+
}
|
|
5646
|
+
function convertPicture(json) {
|
|
5647
|
+
const { data, type, x, y, width, height, ...rest } = json;
|
|
5648
|
+
return new Picture({
|
|
5649
|
+
...rest,
|
|
5650
|
+
data: base64ToUint8Array(data),
|
|
5651
|
+
type,
|
|
5652
|
+
x: x != null ? Math.round(x / EMU_PER_PIXEL) : void 0,
|
|
5653
|
+
y: y != null ? Math.round(y / EMU_PER_PIXEL) : void 0,
|
|
5654
|
+
width: width != null ? Math.round(width / EMU_PER_PIXEL) : void 0,
|
|
5655
|
+
height: height != null ? Math.round(height / EMU_PER_PIXEL) : void 0
|
|
5656
|
+
});
|
|
5657
|
+
}
|
|
5658
|
+
function convertConnectorShape(json) {
|
|
5659
|
+
const { outline, x, y, width, height, ...rest } = json;
|
|
5660
|
+
const x1 = x != null ? Math.round(x / EMU_PER_PIXEL) : 0;
|
|
5661
|
+
const y1 = y != null ? Math.round(y / EMU_PER_PIXEL) : 0;
|
|
5662
|
+
const x2 = x != null && width != null ? Math.round((x + width) / EMU_PER_PIXEL) : x1 + 100;
|
|
5663
|
+
const y2 = y != null && height != null ? Math.round((y + height) / EMU_PER_PIXEL) : y1 + 100;
|
|
5664
|
+
return new ConnectorShape({
|
|
5665
|
+
...rest,
|
|
5666
|
+
x1,
|
|
5667
|
+
y1,
|
|
5668
|
+
x2,
|
|
5669
|
+
y2,
|
|
5670
|
+
outline: convertOutline(outline)
|
|
5671
|
+
});
|
|
5672
|
+
}
|
|
5673
|
+
function convertTable(json) {
|
|
5674
|
+
const { rows, ...rest } = json;
|
|
5675
|
+
return new Table({
|
|
5676
|
+
...rest,
|
|
5677
|
+
rows: rows.map(convertTableRow)
|
|
5678
|
+
});
|
|
5679
|
+
}
|
|
5680
|
+
function convertGroupShape(json) {
|
|
5681
|
+
const { children, x, y, width, height, rotation, ...rest } = json;
|
|
5682
|
+
return new GroupShape({
|
|
5683
|
+
...rest,
|
|
5684
|
+
x: x != null ? Math.round(x / EMU_PER_PIXEL) : void 0,
|
|
5685
|
+
y: y != null ? Math.round(y / EMU_PER_PIXEL) : void 0,
|
|
5686
|
+
width: width != null ? Math.round(width / EMU_PER_PIXEL) : void 0,
|
|
5687
|
+
height: height != null ? Math.round(height / EMU_PER_PIXEL) : void 0,
|
|
5688
|
+
rotation: rotation != null ? rotation * 6e4 : void 0,
|
|
5689
|
+
children: children ? toSlideChildren(children) : []
|
|
5690
|
+
});
|
|
5691
|
+
}
|
|
5692
|
+
function convertTableRow(row) {
|
|
5693
|
+
return {
|
|
5694
|
+
cells: (row.cells ?? []).map(convertTableCell),
|
|
5695
|
+
height: row.height
|
|
5696
|
+
};
|
|
5697
|
+
}
|
|
5698
|
+
function convertTableCell(cell) {
|
|
5699
|
+
return {
|
|
5700
|
+
paragraphs: cell.paragraphs?.map(convertParagraph),
|
|
5701
|
+
columnSpan: cell.columnSpan,
|
|
5702
|
+
rowSpan: cell.rowSpan,
|
|
5703
|
+
fill: convertFill(cell.fill),
|
|
5704
|
+
borders: convertCellBorders(cell.borders),
|
|
5705
|
+
verticalAlign: cell.verticalAlign,
|
|
5706
|
+
width: cell.width
|
|
5707
|
+
};
|
|
5708
|
+
}
|
|
5709
|
+
function convertParagraph(json) {
|
|
5710
|
+
const { children, text, ...rest } = json;
|
|
5711
|
+
const runs = children?.map(convertRun) ?? (text ? [new Run({ text })] : void 0);
|
|
5712
|
+
return new Paragraph({
|
|
5713
|
+
...rest,
|
|
5714
|
+
children: runs
|
|
5715
|
+
});
|
|
5716
|
+
}
|
|
5717
|
+
function convertRun(json) {
|
|
5718
|
+
const { fill, underline, strike, capitalization, fontSize, ...rest } = json;
|
|
5719
|
+
return new Run({
|
|
5720
|
+
...rest,
|
|
5721
|
+
fontSize: fontSize != null ? Math.round(fontSize / 100) : void 0,
|
|
5722
|
+
fill: convertFill(fill),
|
|
5723
|
+
underline: mapUnderline(underline),
|
|
5724
|
+
strike: mapStrike(strike),
|
|
5725
|
+
capitalization: mapCapitalization(capitalization)
|
|
5726
|
+
});
|
|
5727
|
+
}
|
|
5728
|
+
const BORDER_KEY_MAP = {
|
|
5729
|
+
lnT: "top",
|
|
5730
|
+
lnB: "bottom",
|
|
5731
|
+
lnL: "left",
|
|
5732
|
+
lnR: "right",
|
|
5733
|
+
lnH: "insideHorizontal",
|
|
5734
|
+
lnV: "insideVertical"
|
|
5735
|
+
};
|
|
5736
|
+
function convertCellBorders(borders) {
|
|
5737
|
+
if (!borders) return void 0;
|
|
5738
|
+
const result = {};
|
|
5739
|
+
for (const [key, value] of Object.entries(borders)) {
|
|
5740
|
+
const mappedKey = BORDER_KEY_MAP[key] ?? key;
|
|
5741
|
+
result[mappedKey] = value;
|
|
5742
|
+
}
|
|
5743
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
5744
|
+
}
|
|
5745
|
+
function convertFill(fill) {
|
|
5746
|
+
if (!fill || typeof fill === "string") return fill;
|
|
5747
|
+
return fill;
|
|
5748
|
+
}
|
|
5749
|
+
function convertOutline(outline) {
|
|
5750
|
+
if (!outline) return void 0;
|
|
5751
|
+
const result = {};
|
|
5752
|
+
if (outline.width != null) result.width = outline.width;
|
|
5753
|
+
if (outline.color != null) result.color = outline.color;
|
|
5754
|
+
if (outline.dashStyle != null) result.dashStyle = mapDash(outline.dashStyle);
|
|
5755
|
+
if (outline.cap != null) result.cap = outline.cap;
|
|
5756
|
+
if (outline.compound != null) result.compound = outline.compound;
|
|
5757
|
+
if (outline.headEnd) result.headEnd = outline.headEnd;
|
|
5758
|
+
if (outline.tailEnd) result.tailEnd = outline.tailEnd;
|
|
5759
|
+
if (outline.join != null) result.join = outline.join;
|
|
5760
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
5761
|
+
}
|
|
5762
|
+
function base64ToUint8Array(base64) {
|
|
5763
|
+
const binary = atob(base64);
|
|
5764
|
+
const bytes = new Uint8Array(binary.length);
|
|
5765
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
5766
|
+
return bytes;
|
|
5767
|
+
}
|
|
5768
|
+
const UNDERLINE_MAP = {
|
|
5769
|
+
sng: "SINGLE",
|
|
5770
|
+
dbl: "DOUBLE",
|
|
5771
|
+
heavy: "HEAVY",
|
|
5772
|
+
dotted: "DOTTED",
|
|
5773
|
+
dash: "DASH",
|
|
5774
|
+
dashDot: "DASH_DOT",
|
|
5775
|
+
dashDotDot: "DASH_DOT_DOT",
|
|
5776
|
+
sysDash: "SYS_DASH",
|
|
5777
|
+
sysDotDash: "SYS_DOT_DASH"
|
|
5778
|
+
};
|
|
5779
|
+
const STRIKE_MAP = {
|
|
5780
|
+
noStrike: "NONE",
|
|
5781
|
+
sngStrike: "SINGLE",
|
|
5782
|
+
dblStrike: "DOUBLE",
|
|
5783
|
+
heavyStrike: "DOUBLE"
|
|
5784
|
+
};
|
|
5785
|
+
const CAPITALIZATION_MAP = {
|
|
5786
|
+
none: "NONE",
|
|
5787
|
+
small: "SMALL",
|
|
5788
|
+
all: "ALL"
|
|
5789
|
+
};
|
|
5790
|
+
const DASH_MAP = {
|
|
5791
|
+
solid: "SOLID",
|
|
5792
|
+
dash: "DASH",
|
|
5793
|
+
dashDot: "DASH_DOT",
|
|
5794
|
+
dashDotDot: "LG_DASH_DOT",
|
|
5795
|
+
dot: "DOT",
|
|
5796
|
+
lgDash: "LARGE_DASH",
|
|
5797
|
+
sysDash: "SYS_DASH",
|
|
5798
|
+
sysDotDash: "SYS_DOT_DASH"
|
|
5799
|
+
};
|
|
5800
|
+
function mapUnderline(value) {
|
|
5801
|
+
if (!value) return void 0;
|
|
5802
|
+
return UNDERLINE_MAP[value] ?? value;
|
|
5803
|
+
}
|
|
5804
|
+
function mapStrike(value) {
|
|
5805
|
+
if (!value) return void 0;
|
|
5806
|
+
return STRIKE_MAP[value] ?? value;
|
|
5807
|
+
}
|
|
5808
|
+
function mapCapitalization(value) {
|
|
5809
|
+
if (!value) return void 0;
|
|
5810
|
+
return CAPITALIZATION_MAP[value] ?? value;
|
|
5811
|
+
}
|
|
5812
|
+
function mapDash(value) {
|
|
5813
|
+
if (!value) return void 0;
|
|
5814
|
+
return DASH_MAP[value] ?? value;
|
|
5815
|
+
}
|
|
5343
5816
|
__reExport(/* @__PURE__ */ __exportAll({
|
|
5344
5817
|
AppProperties: () => AppProperties,
|
|
5345
5818
|
AudioFrame: () => AudioFrame,
|
|
@@ -5434,15 +5907,17 @@ __reExport(/* @__PURE__ */ __exportAll({
|
|
|
5434
5907
|
extractBlipFillMedia: () => extractBlipFillMedia,
|
|
5435
5908
|
hashedId: () => hashedId,
|
|
5436
5909
|
inchesToEmus: () => inchesToEmus,
|
|
5910
|
+
isRaw: () => isRaw,
|
|
5437
5911
|
parsePptx: () => parsePptx,
|
|
5438
5912
|
percentToTHousandths: () => percentToTHousandths,
|
|
5439
5913
|
pixelsToEmus: () => pixelsToEmus,
|
|
5440
5914
|
pointsToEmus: () => pointsToEmus,
|
|
5915
|
+
toSlideChildren: () => toSlideChildren,
|
|
5441
5916
|
uniqueId: () => uniqueId,
|
|
5442
5917
|
uniqueNumericIdCreator: () => uniqueNumericIdCreator,
|
|
5443
5918
|
uniqueUuid: () => uniqueUuid
|
|
5444
5919
|
}), util_exports);
|
|
5445
5920
|
//#endregion
|
|
5446
|
-
export { AppProperties, AudioFrame, Background, BevelPresetType, BlipFill, ChartCollection, ChartFrame, ChartSpace, CompoundLine, ConnectorShape, ContentTypes, CoreProperties, DateTimeField, DefaultNotesMaster, DefaultSlideLayout, DefaultSlideMaster, DefaultTheme, EffectList, EndParagraphRunProperties, Field, File, File as Presentation, GroupShape, GroupShapeProperties, GroupTransform2D, HeaderFooter, LineCap, LineJoin, LineShape, Media, NonVisualDrawingProperties, NonVisualPictureProperties, NonVisualShapeProperties, NotesSlide, Packer, Paragraph, ParagraphProperties, PathShadeType, PenAlignment, Picture, PresentationWrapper, PresetDash, PresetGeometry, PresetMaterialType, PrettifyType, ReflectionAlignment, Relationships, Run, RunProperties, Shape, ShapeProperties, ShapeTree, Slide, SlideNumberField, SlideSizePreset, SmartArtFrame, StrikeStyle, Table, TableCell, TableCellProperties, TableFrame, TableProperties, TableRow, Text, TextAlignment, TextBody, TextCapitalization, TileFlipMode, Transform2D, Transition, UnderlineStyle, VerticalAlignment, VideoFrame, buildFill, convertOutput, createBevel, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createGradientFill, createGradientStop, createOutline, createOutlineCompat, createScene3D, createShape3D, createTransformation, emusToInches, emusToPixels, emusToPoints, extractBlipFillMedia, hashedId, inchesToEmus, parsePptx, percentToTHousandths, pixelsToEmus, pointsToEmus, uniqueId, uniqueNumericIdCreator, uniqueUuid };
|
|
5921
|
+
export { AppProperties, AudioFrame, Background, BevelPresetType, BlipFill, ChartCollection, ChartFrame, ChartSpace, CompoundLine, ConnectorShape, ContentTypes, CoreProperties, DateTimeField, DefaultNotesMaster, DefaultSlideLayout, DefaultSlideMaster, DefaultTheme, EffectList, EndParagraphRunProperties, Field, File, File as Presentation, GroupShape, GroupShapeProperties, GroupTransform2D, HeaderFooter, LineCap, LineJoin, LineShape, Media, NonVisualDrawingProperties, NonVisualPictureProperties, NonVisualShapeProperties, NotesSlide, Packer, Paragraph, ParagraphProperties, PathShadeType, PenAlignment, Picture, PresentationWrapper, PresetDash, PresetGeometry, PresetMaterialType, PrettifyType, ReflectionAlignment, Relationships, Run, RunProperties, Shape, ShapeProperties, ShapeTree, Slide, SlideNumberField, SlideSizePreset, SmartArtFrame, StrikeStyle, Table, TableCell, TableCellProperties, TableFrame, TableProperties, TableRow, Text, TextAlignment, TextBody, TextCapitalization, TileFlipMode, Transform2D, Transition, UnderlineStyle, VerticalAlignment, VideoFrame, buildFill, convertOutput, createBevel, createBottomBevel, createColorElement, createColorTransforms, createEffectList, createGradientFill, createGradientStop, createOutline, createOutlineCompat, createScene3D, createShape3D, createTransformation, emusToInches, emusToPixels, emusToPoints, extractBlipFillMedia, hashedId, inchesToEmus, isRaw, parsePptx, percentToTHousandths, pixelsToEmus, pointsToEmus, toSlideChildren, uniqueId, uniqueNumericIdCreator, uniqueUuid };
|
|
5447
5922
|
|
|
5448
5923
|
//# sourceMappingURL=index.mjs.map
|