@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.
@@ -17157,6 +17157,11 @@ var PptxSlideLoaderService = class {
17157
17157
  id: path,
17158
17158
  rId,
17159
17159
  slideNumber: slideIndex + 1,
17160
+ // Preserve the authoritative slide -> slideLayout relationship on the
17161
+ // loaded model. The editor uses this identity to mark the current
17162
+ // layout in the gallery and to scope layout choices to the slide's
17163
+ // master. Without it, the gallery cannot reliably reflect PowerPoint.
17164
+ layoutPath: layoutPathForOverride,
17160
17165
  hidden,
17161
17166
  sectionId: sectionMeta?.sectionId,
17162
17167
  sectionName: sectionMeta?.sectionName,
@@ -52747,6 +52752,37 @@ function parseShowProperties(showPr) {
52747
52752
  }
52748
52753
  return props;
52749
52754
  }
52755
+ function asArray2(value) {
52756
+ if (value === void 0 || value === null) return [];
52757
+ return Array.isArray(value) ? value : [value];
52758
+ }
52759
+ function resolveSlideLayoutOrder(sldMaster, relationships, resolveTarget) {
52760
+ const layoutRelationships = relationships.filter(
52761
+ (relationship) => String(relationship["@_Type"] ?? "").includes("/slideLayout")
52762
+ );
52763
+ const targetById = new Map(
52764
+ layoutRelationships.map((relationship) => [
52765
+ String(relationship["@_Id"] ?? ""),
52766
+ String(relationship["@_Target"] ?? "")
52767
+ ])
52768
+ );
52769
+ const orderedIds = asArray2(xmlChild(sldMaster, "p:sldLayoutIdLst")?.["p:sldLayoutId"]).map((layoutId) => xmlAttr(layoutId, "r:id")).filter((id) => Boolean(id));
52770
+ const orderedTargets = [];
52771
+ const usedIds = /* @__PURE__ */ new Set();
52772
+ for (const id of orderedIds) {
52773
+ const target = targetById.get(id);
52774
+ if (target) {
52775
+ orderedTargets.push(resolveTarget(target));
52776
+ usedIds.add(id);
52777
+ }
52778
+ }
52779
+ for (const relationship of layoutRelationships) {
52780
+ const id = String(relationship["@_Id"] ?? "");
52781
+ const target = String(relationship["@_Target"] ?? "");
52782
+ if (target && !usedIds.has(id)) orderedTargets.push(resolveTarget(target));
52783
+ }
52784
+ return orderedTargets;
52785
+ }
52750
52786
  function parseMasterColorMap(node) {
52751
52787
  if (!node) {
52752
52788
  return void 0;
@@ -55012,7 +55048,22 @@ var PptxHandlerRuntime9 = class _PptxHandlerRuntime extends PptxHandlerRuntime8
55012
55048
  }
55013
55049
  const type = (xmlAttr(ph, "type") ?? "body").trim();
55014
55050
  const idx = xmlAttr(ph, "idx");
55015
- result.push({ type, idx });
55051
+ const xfrm = xmlPath(sp, "p:spPr", "a:xfrm");
55052
+ const off = xmlChild(xfrm, "a:off");
55053
+ const ext = xmlChild(xfrm, "a:ext");
55054
+ const emu = _PptxHandlerRuntime.EMU_PER_PX;
55055
+ const x = off ? Number(xmlAttr(off, "x")) / emu : void 0;
55056
+ const y = off ? Number(xmlAttr(off, "y")) / emu : void 0;
55057
+ const width = ext ? Number(xmlAttr(ext, "cx")) / emu : void 0;
55058
+ const height = ext ? Number(xmlAttr(ext, "cy")) / emu : void 0;
55059
+ result.push({
55060
+ type,
55061
+ idx,
55062
+ ...Number.isFinite(x) ? { x } : {},
55063
+ ...Number.isFinite(y) ? { y } : {},
55064
+ ...Number.isFinite(width) ? { width } : {},
55065
+ ...Number.isFinite(height) ? { height } : {}
55066
+ });
55016
55067
  }
55017
55068
  return result;
55018
55069
  }
@@ -55119,12 +55170,13 @@ var PptxHandlerRuntime9 = class _PptxHandlerRuntime extends PptxHandlerRuntime8
55119
55170
  const rels = this.ensureArray(
55120
55171
  xmlChild(relsData, "Relationships")?.["Relationship"]
55121
55172
  );
55122
- for (const rel of rels) {
55123
- const relType = String(rel["@_Type"] || "");
55124
- if (relType.includes("/slideLayout")) {
55125
- layoutPaths.push(this.resolveImagePath(path, String(rel["@_Target"] || "")));
55126
- }
55127
- }
55173
+ layoutPaths.push(
55174
+ ...resolveSlideLayoutOrder(
55175
+ sldMaster,
55176
+ rels,
55177
+ (target) => this.resolveImagePath(path, target)
55178
+ )
55179
+ );
55128
55180
  }
55129
55181
  const layouts = [];
55130
55182
  for (const lp of layoutPaths) {
@@ -58126,9 +58178,13 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58126
58178
  return [];
58127
58179
  }
58128
58180
  const result = [];
58129
- const shapes = this.ensureArray(spTree["p:sp"]);
58181
+ const shapes = [
58182
+ ...this.ensureArray(spTree["p:sp"]),
58183
+ ...this.ensureArray(spTree["p:pic"]),
58184
+ ...this.ensureArray(spTree["p:graphicFrame"])
58185
+ ];
58130
58186
  for (const shape of shapes) {
58131
- const nvPr = xmlPath(shape, "p:nvSpPr", "p:nvPr");
58187
+ const nvPr = xmlPath(shape, "p:nvSpPr", "p:nvPr") ?? xmlPath(shape, "p:nvPicPr", "p:nvPr") ?? xmlPath(shape, "p:nvGraphicFramePr", "p:nvPr");
58132
58188
  const phInfo = this.readPlaceholderInfoFromNvPr(nvPr);
58133
58189
  if (!phInfo) {
58134
58190
  continue;
@@ -58162,18 +58218,49 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58162
58218
  if (type === "title" || type === "ctrtitle") {
58163
58219
  return "title";
58164
58220
  }
58165
- if (type === "body" || type === "obj" || type === "subtitle") {
58221
+ if (type === "body" || type === "obj" || type === "subtitle" || type === "pic" || type === "chart" || type === "tbl" || type === "media") {
58166
58222
  return "content";
58167
58223
  }
58168
58224
  return type;
58169
58225
  }
58226
+ preferredPlaceholderTypes(element) {
58227
+ switch (element.type) {
58228
+ case "image":
58229
+ return ["pic", "obj"];
58230
+ case "chart":
58231
+ return ["chart", "obj"];
58232
+ case "table":
58233
+ return ["tbl", "obj"];
58234
+ case "video":
58235
+ case "audio":
58236
+ return ["media", "obj"];
58237
+ case "text":
58238
+ return ["body", "subtitle", "obj"];
58239
+ default:
58240
+ return ["obj", "body"];
58241
+ }
58242
+ }
58243
+ placeholderMatchScore(element, source, target) {
58244
+ const sourceType = source.type || "body";
58245
+ const targetType = target.type || "body";
58246
+ const sourceRole = this.placeholderRole(source);
58247
+ const targetRole = this.placeholderRole(target);
58248
+ if (sourceRole !== targetRole) return -1;
58249
+ let score = 0;
58250
+ if (source.idx !== void 0 && target.idx === source.idx) score += 100;
58251
+ if (targetType === sourceType) score += 50;
58252
+ const preferredIndex = this.preferredPlaceholderTypes(element).indexOf(targetType);
58253
+ if (preferredIndex >= 0) score += 30 - preferredIndex * 5;
58254
+ if (targetType === "obj") score += 10;
58255
+ return score;
58256
+ }
58170
58257
  // ── Core layout switching logic ─────────────────────────────────────
58171
58258
  /**
58172
58259
  * Re-map slide elements to a new layout's placeholders.
58173
58260
  *
58174
58261
  * - Placeholder elements whose type matches a new-layout placeholder
58175
58262
  * get their position/size updated to the new layout's values.
58176
- * - Placeholder elements with no match in the new layout are removed.
58263
+ * - Placeholder elements with no match in the new layout are preserved.
58177
58264
  * - New-layout placeholders with no matching slide element produce
58178
58265
  * empty text elements that are appended to the slide.
58179
58266
  * - Non-placeholder elements are left untouched.
@@ -58182,10 +58269,9 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58182
58269
  */
58183
58270
  remapElementsToNewLayout(elements2, newLayoutXml, newLayoutPath) {
58184
58271
  const layoutPlaceholders = this.extractLayoutPlaceholders(newLayoutXml);
58185
- const layoutPhMap = /* @__PURE__ */ new Map();
58272
+ const targetPlaceholders = [];
58186
58273
  for (const lp of layoutPlaceholders) {
58187
- const key = this.buildPlaceholderMatchKey(lp.phInfo);
58188
- layoutPhMap.set(key, { ...lp, matched: false });
58274
+ targetPlaceholders.push({ ...lp, matched: false });
58189
58275
  }
58190
58276
  const resultElements = [];
58191
58277
  for (const element of elements2) {
@@ -58194,29 +58280,22 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58194
58280
  resultElements.push(element);
58195
58281
  continue;
58196
58282
  }
58197
- const matchKey = this.buildPlaceholderMatchKey(phInfo);
58198
- const layoutPh = layoutPhMap.get(matchKey);
58199
- let resolvedLayoutPh = layoutPh;
58200
- if (!resolvedLayoutPh && phInfo.type) {
58201
- for (const [, lp] of layoutPhMap.entries()) {
58202
- if (!lp.matched && lp.phInfo.type === phInfo.type) {
58203
- resolvedLayoutPh = lp;
58204
- break;
58205
- }
58206
- }
58207
- }
58208
- if (!resolvedLayoutPh) {
58209
- const sourceRole = this.placeholderRole(phInfo);
58210
- for (const [, lp] of layoutPhMap.entries()) {
58211
- if (!lp.matched && this.placeholderRole(lp.phInfo) === sourceRole) {
58212
- resolvedLayoutPh = lp;
58213
- break;
58214
- }
58283
+ let resolvedLayoutPh;
58284
+ let bestScore = -1;
58285
+ for (const candidate of targetPlaceholders) {
58286
+ if (candidate.matched) continue;
58287
+ const score = this.placeholderMatchScore(element, phInfo, candidate.phInfo);
58288
+ if (score > bestScore) {
58289
+ bestScore = score;
58290
+ resolvedLayoutPh = candidate;
58215
58291
  }
58216
58292
  }
58217
58293
  if (resolvedLayoutPh) {
58218
58294
  resolvedLayoutPh.matched = true;
58219
- const updatedElement = { ...element };
58295
+ const updatedElement = {
58296
+ ...element,
58297
+ rawXml: element.rawXml ? cloneXmlObject(element.rawXml) : element.rawXml
58298
+ };
58220
58299
  if (resolvedLayoutPh.cxEmu > 0 && resolvedLayoutPh.cyEmu > 0) {
58221
58300
  updatedElement.x = Math.round(resolvedLayoutPh.xEmu / EMU_PER_PX);
58222
58301
  updatedElement.y = Math.round(resolvedLayoutPh.yEmu / EMU_PER_PX);
@@ -58232,10 +58311,15 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58232
58311
  resolvedLayoutPh.cyEmu
58233
58312
  );
58234
58313
  }
58314
+ if (updatedElement.rawXml) {
58315
+ this.updateElementRawXmlPlaceholder(updatedElement.rawXml, resolvedLayoutPh.phInfo);
58316
+ }
58235
58317
  resultElements.push(updatedElement);
58318
+ } else {
58319
+ resultElements.push(element);
58236
58320
  }
58237
58321
  }
58238
- for (const [, lp] of layoutPhMap) {
58322
+ for (const lp of targetPlaceholders) {
58239
58323
  if (lp.matched) {
58240
58324
  continue;
58241
58325
  }
@@ -58257,6 +58341,24 @@ var PptxHandlerRuntime21 = class extends PptxHandlerRuntime20 {
58257
58341
  }
58258
58342
  return resultElements;
58259
58343
  }
58344
+ updateElementRawXmlPlaceholder(rawXml, phInfo) {
58345
+ const nvPr = xmlPath(rawXml, "p:nvSpPr", "p:nvPr") ?? xmlPath(rawXml, "p:nvPicPr", "p:nvPr") ?? xmlPath(rawXml, "p:nvGraphicFramePr", "p:nvPr");
58346
+ if (!nvPr) {
58347
+ return;
58348
+ }
58349
+ const ph = nvPr["p:ph"] ?? {};
58350
+ nvPr["p:ph"] = ph;
58351
+ if (phInfo.type) {
58352
+ ph["@_type"] = phInfo.type;
58353
+ } else {
58354
+ delete ph["@_type"];
58355
+ }
58356
+ if (phInfo.idx !== void 0) {
58357
+ ph["@_idx"] = phInfo.idx;
58358
+ } else {
58359
+ delete ph["@_idx"];
58360
+ }
58361
+ }
58260
58362
  // ── rawXml transform update ─────────────────────────────────────────
58261
58363
  /**
58262
58364
  * Update the transform (`a:xfrm`) inside an element's rawXml to
@@ -66496,7 +66598,7 @@ function ensureChild2(parent, key) {
66496
66598
  return created;
66497
66599
  }
66498
66600
  var NOTES_MASTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml";
66499
- function asArray2(value) {
66601
+ function asArray3(value) {
66500
66602
  return Array.isArray(value) ? value : value ? [value] : [];
66501
66603
  }
66502
66604
  function relationshipBase(strict) {
@@ -66543,7 +66645,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66543
66645
  }
66544
66646
  const relsData = this.parser.parse(relsXml);
66545
66647
  const relsRoot = relsData["Relationships"] ?? {};
66546
- const relationships = asArray2(relsRoot["Relationship"]);
66648
+ const relationships = asArray3(relsRoot["Relationship"]);
66547
66649
  const usedIds = new Set(relationships.map((rel) => String(rel["@_Id"] ?? "")));
66548
66650
  let index = 1;
66549
66651
  while (usedIds.has(`rId${index}`)) {
@@ -66627,7 +66729,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66627
66729
  }
66628
66730
  const data = this.parser.parse(xml);
66629
66731
  const root = data["Types"] ?? {};
66630
- const overrides10 = asArray2(root["Override"]);
66732
+ const overrides10 = asArray3(root["Override"]);
66631
66733
  if (!overrides10.some((entry) => entry["@_PartName"] === partName)) {
66632
66734
  overrides10.push({ "@_PartName": partName, "@_ContentType": contentType });
66633
66735
  }
@@ -66637,7 +66739,7 @@ var PptxHandlerRuntime49 = class extends PptxHandlerRuntime48 {
66637
66739
  }
66638
66740
  };
66639
66741
  var HANDOUT_MASTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml";
66640
- function asArray3(value) {
66742
+ function asArray4(value) {
66641
66743
  return Array.isArray(value) ? value : value ? [value] : [];
66642
66744
  }
66643
66745
  function relationshipBase2(strict) {
@@ -66668,7 +66770,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66668
66770
  }
66669
66771
  const relsData = this.parser.parse(relsXml);
66670
66772
  const relsRoot = relsData["Relationships"] ?? {};
66671
- const relationships = asArray3(relsRoot["Relationship"]);
66773
+ const relationships = asArray4(relsRoot["Relationship"]);
66672
66774
  const target = masterPath.startsWith("ppt/") ? masterPath.slice(4) : masterPath;
66673
66775
  let relationship = relationships.find(
66674
66776
  (rel) => String(rel["@_Type"] ?? "").endsWith("/handoutMaster") && String(rel["@_Target"] ?? "").replace(/^\.\//u, "") === target
@@ -66701,7 +66803,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66701
66803
  if (existingXml) {
66702
66804
  const data = this.parser.parse(existingXml);
66703
66805
  const root = data["Relationships"] ?? {};
66704
- const relationships = asArray3(root["Relationship"]);
66806
+ const relationships = asArray4(root["Relationship"]);
66705
66807
  if (relationships.some((rel) => String(rel["@_Type"] ?? "").endsWith("/theme"))) {
66706
66808
  return;
66707
66809
  }
@@ -66812,7 +66914,7 @@ var PptxHandlerRuntime50 = class extends PptxHandlerRuntime49 {
66812
66914
  }
66813
66915
  const data = this.parser.parse(xml);
66814
66916
  const root = data["Types"] ?? {};
66815
- const overrides10 = asArray3(root["Override"]);
66917
+ const overrides10 = asArray4(root["Override"]);
66816
66918
  const partName = `/${masterPath}`;
66817
66919
  if (!overrides10.some((entry) => entry["@_PartName"] === partName)) {
66818
66920
  overrides10.push({ "@_PartName": partName, "@_ContentType": HANDOUT_MASTER_CONTENT_TYPE });
@@ -76709,12 +76811,47 @@ var PptxHandlerRuntime94 = class extends PptxHandlerRuntime93 {
76709
76811
  const kinsoku = this.extractKinsoku();
76710
76812
  const customerData = await this.parsePresentationCustomerData();
76711
76813
  this.thumbnailData = await this.parseThumbnail() ?? null;
76814
+ const previousEagerDecodeImages = this.eagerDecodeImages;
76815
+ this.eagerDecodeImages = true;
76816
+ try {
76817
+ for (const master of slideMasters) {
76818
+ for (const layout of master.layouts ?? []) {
76819
+ const previewSlidePath = `ppt/slides/__layout_preview_${layout.path.split("/").pop()}`;
76820
+ this.slideRelsMap.set(
76821
+ previewSlidePath,
76822
+ /* @__PURE__ */ new Map([["rIdLayoutPreview", `/${layout.path}`]])
76823
+ );
76824
+ this.layoutCache.delete(layout.path);
76825
+ layout.elements = await this.getLayoutElements(previewSlidePath);
76826
+ this.slideRelsMap.delete(previewSlidePath);
76827
+ layout.backgroundColor ??= master.backgroundColor;
76828
+ }
76829
+ }
76830
+ } finally {
76831
+ this.eagerDecodeImages = previousEagerDecodeImages;
76832
+ }
76833
+ const layoutPreviewMap = new Map(
76834
+ slideMasters.flatMap(
76835
+ (master) => (master.layouts ?? []).map((layout) => [layout.path, layout])
76836
+ )
76837
+ );
76838
+ const layoutOptions = this.getLayoutOptions().map((option) => {
76839
+ const preview = layoutPreviewMap.get(option.path);
76840
+ return preview ? {
76841
+ ...option,
76842
+ previewElements: preview.elements,
76843
+ previewBackgroundColor: preview.backgroundColor,
76844
+ previewWidth: presentationState.width,
76845
+ previewHeight: presentationState.height,
76846
+ previewPlaceholders: preview.placeholders
76847
+ } : option;
76848
+ });
76712
76849
  return new PptxLoadDataBuilder().withDimensions(
76713
76850
  presentationState.width,
76714
76851
  presentationState.height,
76715
76852
  this.rawSlideWidthEmu,
76716
76853
  this.rawSlideHeightEmu
76717
- ).withNotesDimensions(presentationState.notesWidthEmu, presentationState.notesHeightEmu).withSlides(slidesWithWarnings).withLayoutOptions(this.getLayoutOptions()).withHeaderFooter(headerFooter).withPresentationProperties(presentationProperties).withViewProperties(viewProperties).withCustomShows(customShows).withSections(
76854
+ ).withNotesDimensions(presentationState.notesWidthEmu, presentationState.notesHeightEmu).withSlides(slidesWithWarnings).withLayoutOptions(layoutOptions).withHeaderFooter(headerFooter).withPresentationProperties(presentationProperties).withViewProperties(viewProperties).withCustomShows(customShows).withSections(
76718
76855
  presentationState.orderedSections.length > 0 ? presentationState.orderedSections : void 0
76719
76856
  ).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(
76720
76857
  this.signatureDetection?.signatureCount && this.signatureDetection.signatureCount > 0 ? this.signatureDetection.signatureCount : void 0