@aixa-transformation/pptx-viewer 2.0.15 → 2.0.24

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.
@@ -17151,6 +17151,11 @@ var PptxSlideLoaderService = class {
17151
17151
  id: path,
17152
17152
  rId,
17153
17153
  slideNumber: slideIndex + 1,
17154
+ // Preserve the authoritative slide -> slideLayout relationship on the
17155
+ // loaded model. The editor uses this identity to mark the current
17156
+ // layout in the gallery and to scope layout choices to the slide's
17157
+ // master. Without it, the gallery cannot reliably reflect PowerPoint.
17158
+ layoutPath: layoutPathForOverride,
17154
17159
  hidden,
17155
17160
  sectionId: sectionMeta?.sectionId,
17156
17161
  sectionName: sectionMeta?.sectionName,
@@ -52741,6 +52746,37 @@ function parseShowProperties(showPr) {
52741
52746
  }
52742
52747
  return props;
52743
52748
  }
52749
+ function asArray2(value) {
52750
+ if (value === void 0 || value === null) return [];
52751
+ return Array.isArray(value) ? value : [value];
52752
+ }
52753
+ function resolveSlideLayoutOrder(sldMaster, relationships, resolveTarget) {
52754
+ const layoutRelationships = relationships.filter(
52755
+ (relationship) => String(relationship["@_Type"] ?? "").includes("/slideLayout")
52756
+ );
52757
+ const targetById = new Map(
52758
+ layoutRelationships.map((relationship) => [
52759
+ String(relationship["@_Id"] ?? ""),
52760
+ String(relationship["@_Target"] ?? "")
52761
+ ])
52762
+ );
52763
+ const orderedIds = asArray2(xmlChild(sldMaster, "p:sldLayoutIdLst")?.["p:sldLayoutId"]).map((layoutId) => xmlAttr(layoutId, "r:id")).filter((id) => Boolean(id));
52764
+ const orderedTargets = [];
52765
+ const usedIds = /* @__PURE__ */ new Set();
52766
+ for (const id of orderedIds) {
52767
+ const target = targetById.get(id);
52768
+ if (target) {
52769
+ orderedTargets.push(resolveTarget(target));
52770
+ usedIds.add(id);
52771
+ }
52772
+ }
52773
+ for (const relationship of layoutRelationships) {
52774
+ const id = String(relationship["@_Id"] ?? "");
52775
+ const target = String(relationship["@_Target"] ?? "");
52776
+ if (target && !usedIds.has(id)) orderedTargets.push(resolveTarget(target));
52777
+ }
52778
+ return orderedTargets;
52779
+ }
52744
52780
  function parseMasterColorMap(node) {
52745
52781
  if (!node) {
52746
52782
  return void 0;
@@ -55006,7 +55042,22 @@ var PptxHandlerRuntime9 = class _PptxHandlerRuntime extends PptxHandlerRuntime8
55006
55042
  }
55007
55043
  const type = (xmlAttr(ph, "type") ?? "body").trim();
55008
55044
  const idx = xmlAttr(ph, "idx");
55009
- result.push({ type, idx });
55045
+ const xfrm = xmlPath(sp, "p:spPr", "a:xfrm");
55046
+ const off = xmlChild(xfrm, "a:off");
55047
+ const ext = xmlChild(xfrm, "a:ext");
55048
+ const emu = _PptxHandlerRuntime.EMU_PER_PX;
55049
+ const x = off ? Number(xmlAttr(off, "x")) / emu : void 0;
55050
+ const y = off ? Number(xmlAttr(off, "y")) / emu : void 0;
55051
+ const width = ext ? Number(xmlAttr(ext, "cx")) / emu : void 0;
55052
+ const height = ext ? Number(xmlAttr(ext, "cy")) / emu : void 0;
55053
+ result.push({
55054
+ type,
55055
+ idx,
55056
+ ...Number.isFinite(x) ? { x } : {},
55057
+ ...Number.isFinite(y) ? { y } : {},
55058
+ ...Number.isFinite(width) ? { width } : {},
55059
+ ...Number.isFinite(height) ? { height } : {}
55060
+ });
55010
55061
  }
55011
55062
  return result;
55012
55063
  }
@@ -55113,12 +55164,13 @@ var PptxHandlerRuntime9 = class _PptxHandlerRuntime extends PptxHandlerRuntime8
55113
55164
  const rels = this.ensureArray(
55114
55165
  xmlChild(relsData, "Relationships")?.["Relationship"]
55115
55166
  );
55116
- for (const rel of rels) {
55117
- const relType = String(rel["@_Type"] || "");
55118
- if (relType.includes("/slideLayout")) {
55119
- layoutPaths.push(this.resolveImagePath(path, String(rel["@_Target"] || "")));
55120
- }
55121
- }
55167
+ layoutPaths.push(
55168
+ ...resolveSlideLayoutOrder(
55169
+ sldMaster,
55170
+ rels,
55171
+ (target) => this.resolveImagePath(path, target)
55172
+ )
55173
+ );
55122
55174
  }
55123
55175
  const layouts = [];
55124
55176
  for (const lp of layoutPaths) {
@@ -58120,9 +58172,13 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58120
58172
  return [];
58121
58173
  }
58122
58174
  const result = [];
58123
- const shapes = this.ensureArray(spTree["p:sp"]);
58175
+ const shapes = [
58176
+ ...this.ensureArray(spTree["p:sp"]),
58177
+ ...this.ensureArray(spTree["p:pic"]),
58178
+ ...this.ensureArray(spTree["p:graphicFrame"])
58179
+ ];
58124
58180
  for (const shape of shapes) {
58125
- const nvPr = xmlPath(shape, "p:nvSpPr", "p:nvPr");
58181
+ const nvPr = xmlPath(shape, "p:nvSpPr", "p:nvPr") ?? xmlPath(shape, "p:nvPicPr", "p:nvPr") ?? xmlPath(shape, "p:nvGraphicFramePr", "p:nvPr");
58126
58182
  const phInfo = this.readPlaceholderInfoFromNvPr(nvPr);
58127
58183
  if (!phInfo) {
58128
58184
  continue;
@@ -58156,18 +58212,49 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58156
58212
  if (type === "title" || type === "ctrtitle") {
58157
58213
  return "title";
58158
58214
  }
58159
- if (type === "body" || type === "obj" || type === "subtitle") {
58215
+ if (type === "body" || type === "obj" || type === "subtitle" || type === "pic" || type === "chart" || type === "tbl" || type === "media") {
58160
58216
  return "content";
58161
58217
  }
58162
58218
  return type;
58163
58219
  }
58220
+ preferredPlaceholderTypes(element) {
58221
+ switch (element.type) {
58222
+ case "image":
58223
+ return ["pic", "obj"];
58224
+ case "chart":
58225
+ return ["chart", "obj"];
58226
+ case "table":
58227
+ return ["tbl", "obj"];
58228
+ case "video":
58229
+ case "audio":
58230
+ return ["media", "obj"];
58231
+ case "text":
58232
+ return ["body", "subtitle", "obj"];
58233
+ default:
58234
+ return ["obj", "body"];
58235
+ }
58236
+ }
58237
+ placeholderMatchScore(element, source, target) {
58238
+ const sourceType = source.type || "body";
58239
+ const targetType = target.type || "body";
58240
+ const sourceRole = this.placeholderRole(source);
58241
+ const targetRole = this.placeholderRole(target);
58242
+ if (sourceRole !== targetRole) return -1;
58243
+ let score = 0;
58244
+ if (source.idx !== void 0 && target.idx === source.idx) score += 100;
58245
+ if (targetType === sourceType) score += 50;
58246
+ const preferredIndex = this.preferredPlaceholderTypes(element).indexOf(targetType);
58247
+ if (preferredIndex >= 0) score += 30 - preferredIndex * 5;
58248
+ if (targetType === "obj") score += 10;
58249
+ return score;
58250
+ }
58164
58251
  // ── Core layout switching logic ─────────────────────────────────────
58165
58252
  /**
58166
58253
  * Re-map slide elements to a new layout's placeholders.
58167
58254
  *
58168
58255
  * - Placeholder elements whose type matches a new-layout placeholder
58169
58256
  * get their position/size updated to the new layout's values.
58170
- * - Placeholder elements with no match in the new layout are removed.
58257
+ * - Placeholder elements with no match in the new layout are preserved.
58171
58258
  * - New-layout placeholders with no matching slide element produce
58172
58259
  * empty text elements that are appended to the slide.
58173
58260
  * - Non-placeholder elements are left untouched.
@@ -58176,10 +58263,9 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58176
58263
  */
58177
58264
  remapElementsToNewLayout(elements2, newLayoutXml, newLayoutPath) {
58178
58265
  const layoutPlaceholders = this.extractLayoutPlaceholders(newLayoutXml);
58179
- const layoutPhMap = /* @__PURE__ */ new Map();
58266
+ const targetPlaceholders = [];
58180
58267
  for (const lp of layoutPlaceholders) {
58181
- const key = this.buildPlaceholderMatchKey(lp.phInfo);
58182
- layoutPhMap.set(key, { ...lp, matched: false });
58268
+ targetPlaceholders.push({ ...lp, matched: false });
58183
58269
  }
58184
58270
  const resultElements = [];
58185
58271
  for (const element of elements2) {
@@ -58188,29 +58274,22 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58188
58274
  resultElements.push(element);
58189
58275
  continue;
58190
58276
  }
58191
- const matchKey = this.buildPlaceholderMatchKey(phInfo);
58192
- const layoutPh = layoutPhMap.get(matchKey);
58193
- let resolvedLayoutPh = layoutPh;
58194
- if (!resolvedLayoutPh && phInfo.type) {
58195
- for (const [, lp] of layoutPhMap.entries()) {
58196
- if (!lp.matched && lp.phInfo.type === phInfo.type) {
58197
- resolvedLayoutPh = lp;
58198
- break;
58199
- }
58200
- }
58201
- }
58202
- if (!resolvedLayoutPh) {
58203
- const sourceRole = this.placeholderRole(phInfo);
58204
- for (const [, lp] of layoutPhMap.entries()) {
58205
- if (!lp.matched && this.placeholderRole(lp.phInfo) === sourceRole) {
58206
- resolvedLayoutPh = lp;
58207
- break;
58208
- }
58277
+ let resolvedLayoutPh;
58278
+ let bestScore = -1;
58279
+ for (const candidate of targetPlaceholders) {
58280
+ if (candidate.matched) continue;
58281
+ const score = this.placeholderMatchScore(element, phInfo, candidate.phInfo);
58282
+ if (score > bestScore) {
58283
+ bestScore = score;
58284
+ resolvedLayoutPh = candidate;
58209
58285
  }
58210
58286
  }
58211
58287
  if (resolvedLayoutPh) {
58212
58288
  resolvedLayoutPh.matched = true;
58213
- const updatedElement = { ...element };
58289
+ const updatedElement = {
58290
+ ...element,
58291
+ rawXml: element.rawXml ? cloneXmlObject(element.rawXml) : element.rawXml
58292
+ };
58214
58293
  if (resolvedLayoutPh.cxEmu > 0 && resolvedLayoutPh.cyEmu > 0) {
58215
58294
  updatedElement.x = Math.round(resolvedLayoutPh.xEmu / EMU_PER_PX);
58216
58295
  updatedElement.y = Math.round(resolvedLayoutPh.yEmu / EMU_PER_PX);
@@ -58226,10 +58305,15 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58226
58305
  resolvedLayoutPh.cyEmu
58227
58306
  );
58228
58307
  }
58308
+ if (updatedElement.rawXml) {
58309
+ this.updateElementRawXmlPlaceholder(updatedElement.rawXml, resolvedLayoutPh.phInfo);
58310
+ }
58229
58311
  resultElements.push(updatedElement);
58312
+ } else {
58313
+ resultElements.push(element);
58230
58314
  }
58231
58315
  }
58232
- for (const [, lp] of layoutPhMap) {
58316
+ for (const lp of targetPlaceholders) {
58233
58317
  if (lp.matched) {
58234
58318
  continue;
58235
58319
  }
@@ -58251,6 +58335,24 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58251
58335
  }
58252
58336
  return resultElements;
58253
58337
  }
58338
+ updateElementRawXmlPlaceholder(rawXml, phInfo) {
58339
+ const nvPr = xmlPath(rawXml, "p:nvSpPr", "p:nvPr") ?? xmlPath(rawXml, "p:nvPicPr", "p:nvPr") ?? xmlPath(rawXml, "p:nvGraphicFramePr", "p:nvPr");
58340
+ if (!nvPr) {
58341
+ return;
58342
+ }
58343
+ const ph = nvPr["p:ph"] ?? {};
58344
+ nvPr["p:ph"] = ph;
58345
+ if (phInfo.type) {
58346
+ ph["@_type"] = phInfo.type;
58347
+ } else {
58348
+ delete ph["@_type"];
58349
+ }
58350
+ if (phInfo.idx !== void 0) {
58351
+ ph["@_idx"] = phInfo.idx;
58352
+ } else {
58353
+ delete ph["@_idx"];
58354
+ }
58355
+ }
58254
58356
  // ── rawXml transform update ─────────────────────────────────────────
58255
58357
  /**
58256
58358
  * Update the transform (`a:xfrm`) inside an element's rawXml to
@@ -66490,7 +66592,7 @@ function ensureChild2(parent, key) {
66490
66592
  return created;
66491
66593
  }
66492
66594
  var NOTES_MASTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml";
66493
- function asArray2(value) {
66595
+ function asArray3(value) {
66494
66596
  return Array.isArray(value) ? value : value ? [value] : [];
66495
66597
  }
66496
66598
  function relationshipBase(strict) {
@@ -66537,7 +66639,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66537
66639
  }
66538
66640
  const relsData = this.parser.parse(relsXml);
66539
66641
  const relsRoot = relsData["Relationships"] ?? {};
66540
- const relationships = asArray2(relsRoot["Relationship"]);
66642
+ const relationships = asArray3(relsRoot["Relationship"]);
66541
66643
  const usedIds = new Set(relationships.map((rel) => String(rel["@_Id"] ?? "")));
66542
66644
  let index = 1;
66543
66645
  while (usedIds.has(`rId${index}`)) {
@@ -66621,7 +66723,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66621
66723
  }
66622
66724
  const data = this.parser.parse(xml);
66623
66725
  const root = data["Types"] ?? {};
66624
- const overrides10 = asArray2(root["Override"]);
66726
+ const overrides10 = asArray3(root["Override"]);
66625
66727
  if (!overrides10.some((entry) => entry["@_PartName"] === partName)) {
66626
66728
  overrides10.push({ "@_PartName": partName, "@_ContentType": contentType });
66627
66729
  }
@@ -66631,7 +66733,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66631
66733
  }
66632
66734
  };
66633
66735
  var HANDOUT_MASTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml";
66634
- function asArray3(value) {
66736
+ function asArray4(value) {
66635
66737
  return Array.isArray(value) ? value : value ? [value] : [];
66636
66738
  }
66637
66739
  function relationshipBase2(strict) {
@@ -66662,7 +66764,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66662
66764
  }
66663
66765
  const relsData = this.parser.parse(relsXml);
66664
66766
  const relsRoot = relsData["Relationships"] ?? {};
66665
- const relationships = asArray3(relsRoot["Relationship"]);
66767
+ const relationships = asArray4(relsRoot["Relationship"]);
66666
66768
  const target = masterPath.startsWith("ppt/") ? masterPath.slice(4) : masterPath;
66667
66769
  let relationship = relationships.find(
66668
66770
  (rel) => String(rel["@_Type"] ?? "").endsWith("/handoutMaster") && String(rel["@_Target"] ?? "").replace(/^\.\//u, "") === target
@@ -66695,7 +66797,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66695
66797
  if (existingXml) {
66696
66798
  const data = this.parser.parse(existingXml);
66697
66799
  const root = data["Relationships"] ?? {};
66698
- const relationships = asArray3(root["Relationship"]);
66800
+ const relationships = asArray4(root["Relationship"]);
66699
66801
  if (relationships.some((rel) => String(rel["@_Type"] ?? "").endsWith("/theme"))) {
66700
66802
  return;
66701
66803
  }
@@ -66806,7 +66908,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66806
66908
  }
66807
66909
  const data = this.parser.parse(xml);
66808
66910
  const root = data["Types"] ?? {};
66809
- const overrides10 = asArray3(root["Override"]);
66911
+ const overrides10 = asArray4(root["Override"]);
66810
66912
  const partName = `/${masterPath}`;
66811
66913
  if (!overrides10.some((entry) => entry["@_PartName"] === partName)) {
66812
66914
  overrides10.push({ "@_PartName": partName, "@_ContentType": HANDOUT_MASTER_CONTENT_TYPE });
@@ -76703,12 +76805,47 @@ var PptxHandlerRuntime94 = class extends PptxHandlerRuntime93 {
76703
76805
  const kinsoku = this.extractKinsoku();
76704
76806
  const customerData = await this.parsePresentationCustomerData();
76705
76807
  this.thumbnailData = await this.parseThumbnail() ?? null;
76808
+ const previousEagerDecodeImages = this.eagerDecodeImages;
76809
+ this.eagerDecodeImages = true;
76810
+ try {
76811
+ for (const master of slideMasters) {
76812
+ for (const layout of master.layouts ?? []) {
76813
+ const previewSlidePath = `ppt/slides/__layout_preview_${layout.path.split("/").pop()}`;
76814
+ this.slideRelsMap.set(
76815
+ previewSlidePath,
76816
+ /* @__PURE__ */ new Map([["rIdLayoutPreview", `/${layout.path}`]])
76817
+ );
76818
+ this.layoutCache.delete(layout.path);
76819
+ layout.elements = await this.getLayoutElements(previewSlidePath);
76820
+ this.slideRelsMap.delete(previewSlidePath);
76821
+ layout.backgroundColor ??= master.backgroundColor;
76822
+ }
76823
+ }
76824
+ } finally {
76825
+ this.eagerDecodeImages = previousEagerDecodeImages;
76826
+ }
76827
+ const layoutPreviewMap = new Map(
76828
+ slideMasters.flatMap(
76829
+ (master) => (master.layouts ?? []).map((layout) => [layout.path, layout])
76830
+ )
76831
+ );
76832
+ const layoutOptions = this.getLayoutOptions().map((option) => {
76833
+ const preview = layoutPreviewMap.get(option.path);
76834
+ return preview ? {
76835
+ ...option,
76836
+ previewElements: preview.elements,
76837
+ previewBackgroundColor: preview.backgroundColor,
76838
+ previewWidth: presentationState.width,
76839
+ previewHeight: presentationState.height,
76840
+ previewPlaceholders: preview.placeholders
76841
+ } : option;
76842
+ });
76706
76843
  return new PptxLoadDataBuilder().withDimensions(
76707
76844
  presentationState.width,
76708
76845
  presentationState.height,
76709
76846
  this.rawSlideWidthEmu,
76710
76847
  this.rawSlideHeightEmu
76711
- ).withNotesDimensions(presentationState.notesWidthEmu, presentationState.notesHeightEmu).withSlides(slidesWithWarnings).withLayoutOptions(this.getLayoutOptions()).withHeaderFooter(headerFooter).withPresentationProperties(presentationProperties).withViewProperties(viewProperties).withCustomShows(customShows).withSections(
76848
+ ).withNotesDimensions(presentationState.notesWidthEmu, presentationState.notesHeightEmu).withSlides(slidesWithWarnings).withLayoutOptions(layoutOptions).withHeaderFooter(headerFooter).withPresentationProperties(presentationProperties).withViewProperties(viewProperties).withCustomShows(customShows).withSections(
76712
76849
  presentationState.orderedSections.length > 0 ? presentationState.orderedSections : void 0
76713
76850
  ).withWarnings(this.compatibilityService.getWarnings()).withThemeColorMap({ ...this.themeColorMap }).withTheme(this.buildThemeObject()).withThemeOptions(themeOptions.length > 0 ? themeOptions : void 0).withTableStyleMap(tableStyleMap).withEmbeddedFonts(embeddedFonts.length > 0 ? embeddedFonts : void 0).withEmbeddedFontList(embeddedFontList).withMruColors(presentationProperties?.mruColors).withNotesMaster(notesMaster).withHandoutMaster(handoutMaster).withSlideMasters(slideMasters.length > 0 ? slideMasters : void 0).withTags(tags.length > 0 ? tags : void 0).withCustomProperties(customProperties.length > 0 ? customProperties : void 0).withCoreProperties(coreProperties).withAppProperties(appProperties).withHasMacros(this.vbaProjectBin !== null ? true : void 0).withHasDigitalSignatures(this.signatureDetection?.hasSignatures || void 0).withDigitalSignatureCount(
76714
76851
  this.signatureDetection?.signatureCount && this.signatureDetection.signatureCount > 0 ? this.signatureDetection.signatureCount : void 0