pptx-viewer-core 1.2.4 → 1.2.5

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.js CHANGED
@@ -7175,6 +7175,32 @@ function findAinkInkPayload(graphicData) {
7175
7175
  }
7176
7176
  return void 0;
7177
7177
  }
7178
+ function findOleObjPayload(graphicData) {
7179
+ if (!graphicData) {
7180
+ return void 0;
7181
+ }
7182
+ const direct = graphicData["p:oleObj"];
7183
+ if (direct) {
7184
+ return direct;
7185
+ }
7186
+ const altContent = graphicData["mc:AlternateContent"];
7187
+ if (!altContent) {
7188
+ return void 0;
7189
+ }
7190
+ const fallback = altContent["mc:Fallback"];
7191
+ const fallbackOleObj = fallback?.["p:oleObj"];
7192
+ if (fallbackOleObj) {
7193
+ return fallbackOleObj;
7194
+ }
7195
+ const choices = ensureArrayLike(altContent["mc:Choice"]);
7196
+ for (const choice of choices) {
7197
+ const node = choice?.["p:oleObj"];
7198
+ if (node) {
7199
+ return node;
7200
+ }
7201
+ }
7202
+ return void 0;
7203
+ }
7178
7204
  function decodeAinkInk(inkRoot) {
7179
7205
  const inkPaths = [];
7180
7206
  const inkColors = [];
@@ -7287,7 +7313,7 @@ var PptxGraphicFrameParser = class {
7287
7313
  };
7288
7314
  }
7289
7315
  if (type === "ole" && graphicData) {
7290
- const oleObject = graphicData["p:oleObj"];
7316
+ const oleObject = findOleObjPayload(graphicData);
7291
7317
  const oleProgId = String(oleObject?.["@_progId"] || "").trim() || void 0;
7292
7318
  const oleName = String(oleObject?.["@_name"] || "").trim() || void 0;
7293
7319
  const oleClsId = String(oleObject?.["@_classid"] || "").trim() || void 0;
@@ -7378,7 +7404,7 @@ var PptxGraphicFrameParser = class {
7378
7404
  if (graphicData["dgm:relIds"] || uri.includes("/drawingml/2006/diagram")) {
7379
7405
  return "smartArt";
7380
7406
  }
7381
- if (graphicData["p:oleObj"] || uri.includes("/drawingml/2006/ole")) {
7407
+ if (uri.includes("/presentationml/2006/ole") || uri.includes("/drawingml/2006/ole") || findOleObjPayload(graphicData)) {
7382
7408
  return "ole";
7383
7409
  }
7384
7410
  if (graphicData["a:videoFile"] || graphicData["a:audioFile"] || uri.includes("/drawingml/2006/media")) {
@@ -8679,6 +8705,87 @@ function parseGuideNode(node) {
8679
8705
  return { id, orientation, positionEmu, color };
8680
8706
  }
8681
8707
 
8708
+ // src/core/services/animation-target-reconcile.ts
8709
+ var NV_CONTAINERS = [
8710
+ "p:nvSpPr",
8711
+ "p:nvPicPr",
8712
+ "p:nvCxnSpPr",
8713
+ "p:nvGraphicFramePr",
8714
+ "p:nvGrpSpPr"
8715
+ ];
8716
+ function readCnvPrId(rawXml) {
8717
+ if (!rawXml) {
8718
+ return void 0;
8719
+ }
8720
+ for (const nvKey of NV_CONTAINERS) {
8721
+ const nv = rawXml[nvKey];
8722
+ const cNvPr = nv?.["p:cNvPr"];
8723
+ const id = cNvPr?.["@_id"];
8724
+ if (id !== void 0 && id !== null && String(id).length > 0) {
8725
+ return String(id);
8726
+ }
8727
+ }
8728
+ return void 0;
8729
+ }
8730
+ function isTemplateElementId(elementId) {
8731
+ return elementId.startsWith("layout-") || elementId.startsWith("master-");
8732
+ }
8733
+ function collectShapeIdMap(elements) {
8734
+ const map = /* @__PURE__ */ new Map();
8735
+ const walk = (els) => {
8736
+ for (const el of els) {
8737
+ const cnvId = readCnvPrId(el.rawXml);
8738
+ if (cnvId) {
8739
+ el.shapeId = cnvId;
8740
+ if (!isTemplateElementId(el.id)) {
8741
+ map.set(cnvId, el.id);
8742
+ }
8743
+ }
8744
+ if (el.type === "group" && Array.isArray(el.children)) {
8745
+ walk(el.children);
8746
+ }
8747
+ }
8748
+ };
8749
+ walk(elements);
8750
+ return map;
8751
+ }
8752
+ function reconcileAnimationTargets(elements, nativeAnimations, editorAnimations) {
8753
+ const map = collectShapeIdMap(elements);
8754
+ if (map.size === 0) {
8755
+ return;
8756
+ }
8757
+ if (nativeAnimations) {
8758
+ for (const anim of nativeAnimations) {
8759
+ if (anim.targetId !== void 0) {
8760
+ const resolved = map.get(anim.targetId);
8761
+ if (resolved) {
8762
+ anim.targetId = resolved;
8763
+ }
8764
+ }
8765
+ if (anim.triggerShapeId !== void 0) {
8766
+ const resolved = map.get(anim.triggerShapeId);
8767
+ if (resolved) {
8768
+ anim.triggerShapeId = resolved;
8769
+ }
8770
+ }
8771
+ }
8772
+ }
8773
+ if (editorAnimations) {
8774
+ for (const anim of editorAnimations) {
8775
+ const resolvedElement = map.get(anim.elementId);
8776
+ if (resolvedElement) {
8777
+ anim.elementId = resolvedElement;
8778
+ }
8779
+ if (anim.triggerShapeId !== void 0) {
8780
+ const resolvedTrigger = map.get(anim.triggerShapeId);
8781
+ if (resolvedTrigger) {
8782
+ anim.triggerShapeId = resolvedTrigger;
8783
+ }
8784
+ }
8785
+ }
8786
+ }
8787
+ }
8788
+
8682
8789
  // src/core/services/PptxSlideLoaderService.ts
8683
8790
  var PptxSlideLoaderService = class {
8684
8791
  /**
@@ -8819,6 +8926,7 @@ var PptxSlideLoaderService = class {
8819
8926
  const transition = params.parseSlideTransition(slideXmlObj, path);
8820
8927
  const animations = params.parseEditorAnimations(slideXmlObj);
8821
8928
  const nativeAnimations = params.parseNativeAnimations(slideXmlObj);
8929
+ reconcileAnimationTargets(elements, nativeAnimations, animations);
8822
8930
  const rawTiming = slideXmlObj["p:sld"]?.["p:timing"];
8823
8931
  const drawingGuides = parseSlideDrawingGuides(slideXmlObj);
8824
8932
  const customerData = await params.parseSlideCustomerData(slideXmlObj, path);
@@ -9318,6 +9426,60 @@ var PptxEditorAnimationService = class {
9318
9426
  }
9319
9427
  };
9320
9428
 
9429
+ // src/core/services/animation-shape-id-assign.ts
9430
+ function flattenElements(elements, out) {
9431
+ for (const el of elements) {
9432
+ out.push(el);
9433
+ if (el.type === "group" && Array.isArray(el.children)) {
9434
+ flattenElements(el.children, out);
9435
+ }
9436
+ }
9437
+ }
9438
+ function maxShapeId(elements) {
9439
+ let max = 0;
9440
+ for (const el of elements) {
9441
+ if (el.shapeId !== void 0) {
9442
+ const n = Number.parseInt(el.shapeId, 10);
9443
+ if (Number.isFinite(n) && n > max) {
9444
+ max = n;
9445
+ }
9446
+ }
9447
+ }
9448
+ return max;
9449
+ }
9450
+ function remapEditorAnimationsToShapeIds(elements, animations, reservedMaxId = 0) {
9451
+ const flat = [];
9452
+ flattenElements(elements, flat);
9453
+ const byId = /* @__PURE__ */ new Map();
9454
+ for (const el of flat) {
9455
+ byId.set(el.id, el);
9456
+ }
9457
+ let nextId2 = Math.max(maxShapeId(flat), reservedMaxId) + 1;
9458
+ const resolve = (elementId) => {
9459
+ const el = byId.get(elementId);
9460
+ if (!el) {
9461
+ return void 0;
9462
+ }
9463
+ if (el.shapeId === void 0) {
9464
+ el.shapeId = String(nextId2);
9465
+ nextId2 += 1;
9466
+ }
9467
+ return el.shapeId;
9468
+ };
9469
+ return animations.map((anim) => {
9470
+ const resolvedElement = resolve(anim.elementId);
9471
+ const resolvedTrigger = anim.triggerShapeId !== void 0 ? resolve(anim.triggerShapeId) : void 0;
9472
+ if (resolvedElement === void 0 && resolvedTrigger === void 0) {
9473
+ return anim;
9474
+ }
9475
+ return {
9476
+ ...anim,
9477
+ elementId: resolvedElement ?? anim.elementId,
9478
+ triggerShapeId: resolvedTrigger ?? anim.triggerShapeId
9479
+ };
9480
+ });
9481
+ }
9482
+
9321
9483
  // src/core/services/native-animation-helpers.ts
9322
9484
  function extractSoundAction(cTn) {
9323
9485
  const stSnd = cTn["p:stSnd"];
@@ -10540,7 +10702,7 @@ var PptxSlideTransitionService = class {
10540
10702
  }
10541
10703
  parseSlideTransition(slideXml2) {
10542
10704
  const slideRoot = this.xmlLookupService.getChildByLocalName(slideXml2, "sld");
10543
- const transitionNode = this.xmlLookupService.getChildByLocalName(slideRoot, "transition");
10705
+ const transitionNode = this.xmlLookupService.getChildByLocalName(slideRoot, "transition") || this.findTransitionInAlternateContent(slideRoot);
10544
10706
  if (!transitionNode) {
10545
10707
  return void 0;
10546
10708
  }
@@ -10612,7 +10774,8 @@ var PptxSlideTransitionService = class {
10612
10774
  transitionType = "morph";
10613
10775
  }
10614
10776
  }
10615
- const parsedDuration = Number.parseInt(String(transitionNode["@_dur"] || ""), 10);
10777
+ const rawDuration = transitionNode["@_dur"] ?? transitionNode["@_p14:dur"];
10778
+ const parsedDuration = Number.parseInt(String(rawDuration || ""), 10);
10616
10779
  const durationMs = Number.isFinite(parsedDuration) && parsedDuration > 0 ? parsedDuration : void 0;
10617
10780
  const advanceOnClickToken = String(transitionNode["@_advClick"] || "").trim();
10618
10781
  const advanceOnClick = advanceOnClickToken.length > 0 ? !["0", "false", "off"].includes(advanceOnClickToken.toLowerCase()) : void 0;
@@ -10661,6 +10824,35 @@ var PptxSlideTransitionService = class {
10661
10824
  rawExtLst
10662
10825
  };
10663
10826
  }
10827
+ /**
10828
+ * Locate a `<p:transition>` wrapped in a slide-root `mc:AlternateContent`
10829
+ * envelope.
10830
+ *
10831
+ * Real PowerPoint (verified via COM-authored fixtures) wraps the
10832
+ * transition in `mc:AlternateContent` whenever it carries an Office
10833
+ * 2010+ attribute such as `p14:dur` (sub-second transition duration):
10834
+ * an `mc:Choice Requires="p14"` branch carries the richer transition,
10835
+ * and `mc:Fallback` carries a plain one for older readers. Without this
10836
+ * unwrap, `p:sld`'s direct-child lookup for `transition` finds nothing
10837
+ * and the whole transition (including plain ones falling back with no
10838
+ * p14 data) is silently dropped, even though `mc:Choice` is otherwise a
10839
+ * complete, directly usable `p:transition` node.
10840
+ */
10841
+ findTransitionInAlternateContent(slideRoot) {
10842
+ const altContent = this.xmlLookupService.getChildByLocalName(slideRoot, "AlternateContent");
10843
+ if (!altContent) {
10844
+ return void 0;
10845
+ }
10846
+ const choices = this.xmlLookupService.getChildrenArrayByLocalName(altContent, "Choice");
10847
+ for (const choice of choices) {
10848
+ const transitionNode = this.xmlLookupService.getChildByLocalName(choice, "transition");
10849
+ if (transitionNode) {
10850
+ return transitionNode;
10851
+ }
10852
+ }
10853
+ const fallback = this.xmlLookupService.getChildByLocalName(altContent, "Fallback");
10854
+ return this.xmlLookupService.getChildByLocalName(fallback, "transition");
10855
+ }
10664
10856
  /**
10665
10857
  * Detects the PowerPoint 2016+ `morph` transition stored as a p159 extension
10666
10858
  * inside the transition's extLst.
@@ -36615,6 +36807,22 @@ var PptxHandlerRuntime32 = class _PptxHandlerRuntime extends PptxHandlerRuntime3
36615
36807
 
36616
36808
  // src/core/core/runtime/PptxHandlerRuntimeSaveElementWriter.ts
36617
36809
  var PptxHandlerRuntime33 = class _PptxHandlerRuntime extends PptxHandlerRuntime32 {
36810
+ /**
36811
+ * Whether a shape XML represents a `<p:pic>` (picture-shaped) node.
36812
+ *
36813
+ * Real PowerPoint (verified via COM-authored fixtures) represents video
36814
+ * *and* audio media as `<p:pic>` (poster-frame blip + `p:nvPr/a:videoFile`
36815
+ * or `a:audioFile` + a `p14:media` extension) rather than the older
36816
+ * `<p:graphicFrame>` form. A `media`-typed element's `rawXml` is
36817
+ * therefore frequently `p:pic`-shaped, not a graphic frame; without this
36818
+ * check it falls into the generic `shapes` bucket, which the slide
36819
+ * writer serializes under `<p:sp>` -- corrupting the picture markup
36820
+ * (`p:nvPicPr`/`p:blipFill`) into an invalid shape and permanently
36821
+ * losing the media relationship on save.
36822
+ */
36823
+ isPictureShape(shape) {
36824
+ return Boolean(shape["p:nvPicPr"]);
36825
+ }
36618
36826
  /** Whether a shape XML represents a graphic frame. */
36619
36827
  isGraphicFrameShape(shape) {
36620
36828
  return Boolean(shape["p:nvGraphicFramePr"] || shape["a:graphic"] && shape["p:xfrm"]);
@@ -36730,6 +36938,34 @@ var PptxHandlerRuntime33 = class _PptxHandlerRuntime extends PptxHandlerRuntime3
36730
36938
  isTemplateElementId(elementId) {
36731
36939
  return elementId.startsWith("layout-") || elementId.startsWith("master-");
36732
36940
  }
36941
+ /** Non-visual property containers that hold a `p:cNvPr`. */
36942
+ static NV_CONTAINERS = [
36943
+ "p:nvSpPr",
36944
+ "p:nvPicPr",
36945
+ "p:nvCxnSpPr",
36946
+ "p:nvGraphicFramePr",
36947
+ "p:nvGrpSpPr"
36948
+ ];
36949
+ /**
36950
+ * Write an element's native shape id (`element.shapeId`) into the serialized
36951
+ * shape's `p:cNvPr/@id`. Animation targets (`p:spTgt/@spid`) reference this
36952
+ * id, so the two must agree for PowerPoint to bind an animation to its shape.
36953
+ * A no-op when the element carries no `shapeId` (nothing to reconcile) or the
36954
+ * shape XML has no cNvPr container.
36955
+ */
36956
+ applyShapeIdToCnvPr(shape, el) {
36957
+ if (el.shapeId === void 0) {
36958
+ return;
36959
+ }
36960
+ for (const nvKey of _PptxHandlerRuntime.NV_CONTAINERS) {
36961
+ const nv = shape[nvKey];
36962
+ const cNvPr = nv?.["p:cNvPr"];
36963
+ if (cNvPr) {
36964
+ cNvPr["@_id"] = el.shapeId;
36965
+ return;
36966
+ }
36967
+ }
36968
+ }
36733
36969
  /**
36734
36970
  * Process a single slide element during save. Handles embedding,
36735
36971
  * transforms, geometry, styles, text, and sorts into collectors.
@@ -36839,12 +37075,15 @@ var PptxHandlerRuntime33 = class _PptxHandlerRuntime extends PptxHandlerRuntime3
36839
37075
  }
36840
37076
  return;
36841
37077
  }
37078
+ this.applyShapeIdToCnvPr(shape, el);
36842
37079
  if (el.type === "picture" || el.type === "image") {
36843
37080
  collectors.pics.push(shape);
36844
37081
  } else if (el.type === "connector") {
36845
37082
  collectors.connectors.push(shape);
36846
37083
  } else if (el.type === "model3d") {
36847
37084
  collectors.model3ds.push(shape);
37085
+ } else if (el.type === "media" && this.isPictureShape(shape)) {
37086
+ collectors.pics.push(shape);
36848
37087
  } else if (this.isGraphicFrameShape(shape)) {
36849
37088
  collectors.graphicFrames.push(shape);
36850
37089
  } else {
@@ -36883,12 +37122,17 @@ var PptxHandlerRuntime34 = class extends PptxHandlerRuntime33 {
36883
37122
  delete slideNode["p:transition"];
36884
37123
  }
36885
37124
  }
36886
- if (slide.animations !== void 0) {
36887
- this.applyEditorAnimations(slideNode, slide.animations);
37125
+ const shapeIdAnimations = slide.animations !== void 0 ? remapEditorAnimationsToShapeIds(
37126
+ slide.elements,
37127
+ slide.animations,
37128
+ this.maxCnvPrId(this.ensureSlideTree(xmlObj))
37129
+ ) : void 0;
37130
+ if (shapeIdAnimations !== void 0) {
37131
+ this.applyEditorAnimations(slideNode, shapeIdAnimations);
36888
37132
  }
36889
- if (slide.animations && slide.animations.length > 0) {
37133
+ if (shapeIdAnimations && shapeIdAnimations.length > 0) {
36890
37134
  const generatedTiming = this.animationWriteService.buildTimingXml(
36891
- slide.animations,
37135
+ shapeIdAnimations,
36892
37136
  slide.rawTiming
36893
37137
  );
36894
37138
  if (generatedTiming) {
@@ -37041,6 +37285,40 @@ var PptxHandlerRuntime34 = class extends PptxHandlerRuntime33 {
37041
37285
  }
37042
37286
  this.zip.file(slide.id, this.builder.build(xmlObj));
37043
37287
  }
37288
+ /**
37289
+ * Largest `p:cNvPr/@id` already present anywhere in a shape tree, including
37290
+ * the implicit `<p:spTree>` group's own reserved id. Used to seed minting of
37291
+ * fresh animation-target shape ids so they never collide with a reserved id.
37292
+ */
37293
+ maxCnvPrId(spTree) {
37294
+ let max = 0;
37295
+ const nvContainers = [
37296
+ "p:nvSpPr",
37297
+ "p:nvPicPr",
37298
+ "p:nvCxnSpPr",
37299
+ "p:nvGraphicFramePr",
37300
+ "p:nvGrpSpPr"
37301
+ ];
37302
+ const visit = (node) => {
37303
+ for (const nvKey of nvContainers) {
37304
+ const nv = node[nvKey];
37305
+ const cNvPr = nv?.["p:cNvPr"];
37306
+ if (cNvPr?.["@_id"] !== void 0) {
37307
+ const n = Number.parseInt(String(cNvPr["@_id"]), 10);
37308
+ if (Number.isFinite(n) && n > max) {
37309
+ max = n;
37310
+ }
37311
+ }
37312
+ }
37313
+ for (const listKey of ["p:sp", "p:pic", "p:cxnSp", "p:graphicFrame", "p:grpSp"]) {
37314
+ for (const child of this.ensureArray(node[listKey])) {
37315
+ visit(child);
37316
+ }
37317
+ }
37318
+ };
37319
+ visit(spTree);
37320
+ return max;
37321
+ }
37044
37322
  /**
37045
37323
  * Re-wrap selected children with their original `<mc:AlternateContent>`
37046
37324
  * envelope (CC-4).
@@ -46759,7 +47037,22 @@ var PptxHandlerRuntime79 = class _PptxHandlerRuntime extends PptxHandlerRuntime7
46759
47037
  await this.enrichOleElementsWithEmbeddedData(el.children, slidePath, depth + 1);
46760
47038
  continue;
46761
47039
  }
46762
- if (el.type !== "ole" || el.isLinked || !el.oleTarget) {
47040
+ if (el.type !== "ole") {
47041
+ continue;
47042
+ }
47043
+ if (el.previewImage && !el.previewImageData) {
47044
+ try {
47045
+ const previewPath = this.resolveImagePath(slidePath, el.previewImage);
47046
+ if (previewPath) {
47047
+ const previewData = await this.getImageData(previewPath);
47048
+ if (previewData) {
47049
+ el.previewImageData = previewData;
47050
+ }
47051
+ }
47052
+ } catch {
47053
+ }
47054
+ }
47055
+ if (el.isLinked || !el.oleTarget) {
46763
47056
  continue;
46764
47057
  }
46765
47058
  try {
@@ -65439,9 +65732,11 @@ exports.pt = pt;
65439
65732
  exports.reResolveSlideColors = reResolveSlideColors;
65440
65733
  exports.readFileAsDataUrl = readFileAsDataUrl;
65441
65734
  exports.rebuildTableStructureInRawXml = rebuildTableStructureInRawXml;
65735
+ exports.reconcileAnimationTargets = reconcileAnimationTargets;
65442
65736
  exports.reflowSmartArtLayout = reflowSmartArtLayout;
65443
65737
  exports.relativeLuminance = relativeLuminance;
65444
65738
  exports.relayoutSmartArt = relayoutSmartArt;
65739
+ exports.remapEditorAnimationsToShapeIds = remapEditorAnimationsToShapeIds;
65445
65740
  exports.removeChartCategory = removeChartCategory;
65446
65741
  exports.removeChartSeries = removeChartSeries;
65447
65742
  exports.removeSection = removeSection;