pptx-viewer-core 1.1.37 → 1.1.39

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/cli/index.js CHANGED
Binary file
Binary file
package/dist/index.d.mts CHANGED
@@ -6380,6 +6380,14 @@ declare class PptxHandlerRuntime$11 extends PptxHandlerRuntime$12 {
6380
6380
  declare class PptxHandlerRuntime$10 extends PptxHandlerRuntime$11 {
6381
6381
  protected textStylesEqual(left: TextStyle | undefined, right: TextStyle | undefined): boolean;
6382
6382
  protected hasMixedTextStyles(textSegments: TextSegment[]): boolean;
6383
+ /**
6384
+ * Whether a segment carries run-level content that the flat `el.text` string
6385
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
6386
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
6387
+ * to the plain-text path silently downgrades a field to static text (e.g. a
6388
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
6389
+ */
6390
+ protected isStructuralTextSegment(segment: TextSegment): boolean;
6383
6391
  protected areTextSegmentsUniform(textSegments: TextSegment[] | undefined): boolean;
6384
6392
  protected parseBooleanAttr(value: unknown): boolean;
6385
6393
  protected parseOptionalBooleanAttr(value: unknown): boolean | undefined;
package/dist/index.d.ts CHANGED
@@ -6380,6 +6380,14 @@ declare class PptxHandlerRuntime$11 extends PptxHandlerRuntime$12 {
6380
6380
  declare class PptxHandlerRuntime$10 extends PptxHandlerRuntime$11 {
6381
6381
  protected textStylesEqual(left: TextStyle | undefined, right: TextStyle | undefined): boolean;
6382
6382
  protected hasMixedTextStyles(textSegments: TextSegment[]): boolean;
6383
+ /**
6384
+ * Whether a segment carries run-level content that the flat `el.text` string
6385
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
6386
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
6387
+ * to the plain-text path silently downgrades a field to static text (e.g. a
6388
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
6389
+ */
6390
+ protected isStructuralTextSegment(segment: TextSegment): boolean;
6383
6391
  protected areTextSegmentsUniform(textSegments: TextSegment[] | undefined): boolean;
6384
6392
  protected parseBooleanAttr(value: unknown): boolean;
6385
6393
  protected parseOptionalBooleanAttr(value: unknown): boolean | undefined;
package/dist/index.js CHANGED
@@ -2074,7 +2074,7 @@ var MediaGraphicFrameXmlFactory = class {
2074
2074
  const mediaType = element.mediaType === "audio" ? "audio" : "video";
2075
2075
  const mediaName = mediaType === "audio" ? "Audio" : "Video";
2076
2076
  const mediaTag = mediaType === "audio" ? "a:audioFile" : "a:videoFile";
2077
- const linkAttr = element.isLinked ? "@_r:link" : "@_r:embed";
2077
+ const linkAttr = "@_r:link";
2078
2078
  return {
2079
2079
  "p:nvGraphicFramePr": {
2080
2080
  "p:cNvPr": {
@@ -30523,8 +30523,24 @@ var PptxHandlerRuntime17 = class extends PptxHandlerRuntime16 {
30523
30523
  (segment, index) => index > 0 && !this.textStylesEqual(segment.style, baseStyle)
30524
30524
  );
30525
30525
  }
30526
+ /**
30527
+ * Whether a segment carries run-level content that the flat `el.text` string
30528
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
30529
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
30530
+ * to the plain-text path silently downgrades a field to static text (e.g. a
30531
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
30532
+ */
30533
+ isStructuralTextSegment(segment) {
30534
+ return Boolean(segment.fieldType || segment.equationXml || segment.rubyText);
30535
+ }
30526
30536
  areTextSegmentsUniform(textSegments) {
30527
- if (!textSegments || textSegments.length <= 1) {
30537
+ if (!textSegments || textSegments.length === 0) {
30538
+ return true;
30539
+ }
30540
+ if (textSegments.some((segment) => this.isStructuralTextSegment(segment))) {
30541
+ return false;
30542
+ }
30543
+ if (textSegments.length === 1) {
30528
30544
  return true;
30529
30545
  }
30530
30546
  return !this.hasMixedTextStyles(textSegments);
@@ -32030,12 +32046,43 @@ function ensureA16NamespaceOnSlideRoot(slideRoot) {
32030
32046
  slideRoot["@_mc:Ignorable"] = "a16";
32031
32047
  return;
32032
32048
  }
32033
- const tokens = existingIgnorable.split(/\s+/).filter((token) => token.length > 0);
32049
+ const tokens = existingIgnorable.split(/\s+/u).filter((token) => token.length > 0);
32034
32050
  if (!tokens.includes("a16")) {
32035
32051
  tokens.push("a16");
32036
32052
  slideRoot["@_mc:Ignorable"] = tokens.join(" ");
32037
32053
  }
32038
32054
  }
32055
+ var MATH_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/math";
32056
+ function ensureMathNamespaceOnSlideRoot(slideRoot) {
32057
+ if (!slideRoot["@_xmlns:m"]) {
32058
+ slideRoot["@_xmlns:m"] = MATH_NAMESPACE;
32059
+ }
32060
+ }
32061
+ function slideContainsMathElement(node) {
32062
+ if (node === null || node === void 0) {
32063
+ return false;
32064
+ }
32065
+ if (Array.isArray(node)) {
32066
+ for (const entry of node) {
32067
+ if (slideContainsMathElement(entry)) {
32068
+ return true;
32069
+ }
32070
+ }
32071
+ return false;
32072
+ }
32073
+ if (typeof node !== "object") {
32074
+ return false;
32075
+ }
32076
+ for (const [key, value] of Object.entries(node)) {
32077
+ if (key.startsWith("m:")) {
32078
+ return true;
32079
+ }
32080
+ if (slideContainsMathElement(value)) {
32081
+ return true;
32082
+ }
32083
+ }
32084
+ return false;
32085
+ }
32039
32086
  function slideContainsA16Element(node) {
32040
32087
  if (node === null || node === void 0) {
32041
32088
  return false;
@@ -35644,7 +35691,7 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35644
35691
  if (!targetImagePath) {
35645
35692
  targetImagePath = ctx.saveSession.nextMediaPath(parsedImage.extension);
35646
35693
  const relationshipId = ctx.slideRelationshipRegistry.nextRelationshipId();
35647
- const relativeMediaPath = targetImagePath.replace(/^ppt\//, "../");
35694
+ const relativeMediaPath = targetImagePath.replace(/^ppt\//u, "../");
35648
35695
  ctx.slideRelationships.push({
35649
35696
  "@_Id": relationshipId,
35650
35697
  "@_Type": ctx.slideImageRelationshipType,
@@ -35653,7 +35700,7 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35653
35700
  shape = this.createPictureXml(el, relationshipId);
35654
35701
  }
35655
35702
  if (targetImagePath) {
35656
- const targetExt = targetImagePath.toLowerCase().match(/\.([^./\\]+)$/)?.[1];
35703
+ const targetExt = targetImagePath.toLowerCase().match(/\.(?<ext>[^./\\]+)$/u)?.groups?.["ext"];
35657
35704
  const parsedExt = parsedImage.extension.toLowerCase();
35658
35705
  const extensionMismatch = targetExt !== void 0 && targetExt !== parsedExt && !(targetExt === "jpg" && parsedExt === "jpeg") && !(targetExt === "jpeg" && parsedExt === "jpg");
35659
35706
  if (!extensionMismatch) {
@@ -35688,13 +35735,13 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35688
35735
  targetMediaPath = ctx.saveSession.nextMediaPath(parsedMedia.extension, mediaType);
35689
35736
  }
35690
35737
  this.zip.file(targetMediaPath, parsedMedia.bytes);
35691
- const relationshipTarget = targetMediaPath.replace(/^ppt\//, "../");
35738
+ const relationshipTarget = targetMediaPath.replace(/^ppt\//u, "../");
35692
35739
  if (!mediaRelationshipId) {
35693
35740
  mediaRelationshipId = ctx.slideRelationshipRegistry.nextRelationshipId();
35694
35741
  }
35695
35742
  ctx.slideRelationshipRegistry.upsertRelationship(
35696
35743
  mediaRelationshipId,
35697
- this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes),
35744
+ relTypes.media,
35698
35745
  relationshipTarget
35699
35746
  );
35700
35747
  if (!shape) {
@@ -35718,11 +35765,12 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35718
35765
  });
35719
35766
  }
35720
35767
  } else if (!shape && typeof mediaElement.mediaPath === "string" && mediaElement.mediaPath.length > 0) {
35721
- const relationshipTarget = mediaElement.mediaPath.replace(/^ppt\//, "../");
35722
- mediaRelationshipId = mediaRelationshipId || ctx.slideRelationshipRegistry.nextRelationshipId();
35768
+ const relationshipTarget = mediaElement.mediaPath.replace(/^ppt\//u, "../");
35769
+ mediaRelationshipId ||= ctx.slideRelationshipRegistry.nextRelationshipId();
35770
+ const pathRelType = mediaElement.isLinked ? this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes) : relTypes.media;
35723
35771
  ctx.slideRelationshipRegistry.upsertRelationship(
35724
35772
  mediaRelationshipId,
35725
- this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes),
35773
+ pathRelType,
35726
35774
  relationshipTarget
35727
35775
  );
35728
35776
  shape = this.createMediaGraphicFrameXml(mediaElement, mediaRelationshipId);
@@ -36151,6 +36199,9 @@ var PptxHandlerRuntime33 = class extends PptxHandlerRuntime32 {
36151
36199
  if (slideContainsA16Element(slideNode)) {
36152
36200
  ensureA16NamespaceOnSlideRoot(slideNode);
36153
36201
  }
36202
+ if (slideContainsMathElement(slideNode)) {
36203
+ ensureMathNamespaceOnSlideRoot(slideNode);
36204
+ }
36154
36205
  this.zip.file(slide.id, this.builder.build(xmlObj));
36155
36206
  }
36156
36207
  /**
package/dist/index.mjs CHANGED
@@ -2069,7 +2069,7 @@ var MediaGraphicFrameXmlFactory = class {
2069
2069
  const mediaType = element.mediaType === "audio" ? "audio" : "video";
2070
2070
  const mediaName = mediaType === "audio" ? "Audio" : "Video";
2071
2071
  const mediaTag = mediaType === "audio" ? "a:audioFile" : "a:videoFile";
2072
- const linkAttr = element.isLinked ? "@_r:link" : "@_r:embed";
2072
+ const linkAttr = "@_r:link";
2073
2073
  return {
2074
2074
  "p:nvGraphicFramePr": {
2075
2075
  "p:cNvPr": {
@@ -30518,8 +30518,24 @@ var PptxHandlerRuntime17 = class extends PptxHandlerRuntime16 {
30518
30518
  (segment, index) => index > 0 && !this.textStylesEqual(segment.style, baseStyle)
30519
30519
  );
30520
30520
  }
30521
+ /**
30522
+ * Whether a segment carries run-level content that the flat `el.text` string
30523
+ * cannot represent: an OOXML field (`a:fld`), an inline equation, or a ruby
30524
+ * (phonetic) annotation. Such segments must survive a save: collapsing them
30525
+ * to the plain-text path silently downgrades a field to static text (e.g. a
30526
+ * slide-number field becomes a frozen number) or drops the equation/ruby.
30527
+ */
30528
+ isStructuralTextSegment(segment) {
30529
+ return Boolean(segment.fieldType || segment.equationXml || segment.rubyText);
30530
+ }
30521
30531
  areTextSegmentsUniform(textSegments) {
30522
- if (!textSegments || textSegments.length <= 1) {
30532
+ if (!textSegments || textSegments.length === 0) {
30533
+ return true;
30534
+ }
30535
+ if (textSegments.some((segment) => this.isStructuralTextSegment(segment))) {
30536
+ return false;
30537
+ }
30538
+ if (textSegments.length === 1) {
30523
30539
  return true;
30524
30540
  }
30525
30541
  return !this.hasMixedTextStyles(textSegments);
@@ -32025,12 +32041,43 @@ function ensureA16NamespaceOnSlideRoot(slideRoot) {
32025
32041
  slideRoot["@_mc:Ignorable"] = "a16";
32026
32042
  return;
32027
32043
  }
32028
- const tokens = existingIgnorable.split(/\s+/).filter((token) => token.length > 0);
32044
+ const tokens = existingIgnorable.split(/\s+/u).filter((token) => token.length > 0);
32029
32045
  if (!tokens.includes("a16")) {
32030
32046
  tokens.push("a16");
32031
32047
  slideRoot["@_mc:Ignorable"] = tokens.join(" ");
32032
32048
  }
32033
32049
  }
32050
+ var MATH_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/math";
32051
+ function ensureMathNamespaceOnSlideRoot(slideRoot) {
32052
+ if (!slideRoot["@_xmlns:m"]) {
32053
+ slideRoot["@_xmlns:m"] = MATH_NAMESPACE;
32054
+ }
32055
+ }
32056
+ function slideContainsMathElement(node) {
32057
+ if (node === null || node === void 0) {
32058
+ return false;
32059
+ }
32060
+ if (Array.isArray(node)) {
32061
+ for (const entry of node) {
32062
+ if (slideContainsMathElement(entry)) {
32063
+ return true;
32064
+ }
32065
+ }
32066
+ return false;
32067
+ }
32068
+ if (typeof node !== "object") {
32069
+ return false;
32070
+ }
32071
+ for (const [key, value] of Object.entries(node)) {
32072
+ if (key.startsWith("m:")) {
32073
+ return true;
32074
+ }
32075
+ if (slideContainsMathElement(value)) {
32076
+ return true;
32077
+ }
32078
+ }
32079
+ return false;
32080
+ }
32034
32081
  function slideContainsA16Element(node) {
32035
32082
  if (node === null || node === void 0) {
32036
32083
  return false;
@@ -35639,7 +35686,7 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35639
35686
  if (!targetImagePath) {
35640
35687
  targetImagePath = ctx.saveSession.nextMediaPath(parsedImage.extension);
35641
35688
  const relationshipId = ctx.slideRelationshipRegistry.nextRelationshipId();
35642
- const relativeMediaPath = targetImagePath.replace(/^ppt\//, "../");
35689
+ const relativeMediaPath = targetImagePath.replace(/^ppt\//u, "../");
35643
35690
  ctx.slideRelationships.push({
35644
35691
  "@_Id": relationshipId,
35645
35692
  "@_Type": ctx.slideImageRelationshipType,
@@ -35648,7 +35695,7 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35648
35695
  shape = this.createPictureXml(el, relationshipId);
35649
35696
  }
35650
35697
  if (targetImagePath) {
35651
- const targetExt = targetImagePath.toLowerCase().match(/\.([^./\\]+)$/)?.[1];
35698
+ const targetExt = targetImagePath.toLowerCase().match(/\.(?<ext>[^./\\]+)$/u)?.groups?.["ext"];
35652
35699
  const parsedExt = parsedImage.extension.toLowerCase();
35653
35700
  const extensionMismatch = targetExt !== void 0 && targetExt !== parsedExt && !(targetExt === "jpg" && parsedExt === "jpeg") && !(targetExt === "jpeg" && parsedExt === "jpg");
35654
35701
  if (!extensionMismatch) {
@@ -35683,13 +35730,13 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35683
35730
  targetMediaPath = ctx.saveSession.nextMediaPath(parsedMedia.extension, mediaType);
35684
35731
  }
35685
35732
  this.zip.file(targetMediaPath, parsedMedia.bytes);
35686
- const relationshipTarget = targetMediaPath.replace(/^ppt\//, "../");
35733
+ const relationshipTarget = targetMediaPath.replace(/^ppt\//u, "../");
35687
35734
  if (!mediaRelationshipId) {
35688
35735
  mediaRelationshipId = ctx.slideRelationshipRegistry.nextRelationshipId();
35689
35736
  }
35690
35737
  ctx.slideRelationshipRegistry.upsertRelationship(
35691
35738
  mediaRelationshipId,
35692
- this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes),
35739
+ relTypes.media,
35693
35740
  relationshipTarget
35694
35741
  );
35695
35742
  if (!shape) {
@@ -35713,11 +35760,12 @@ var PptxHandlerRuntime31 = class extends PptxHandlerRuntime30 {
35713
35760
  });
35714
35761
  }
35715
35762
  } else if (!shape && typeof mediaElement.mediaPath === "string" && mediaElement.mediaPath.length > 0) {
35716
- const relationshipTarget = mediaElement.mediaPath.replace(/^ppt\//, "../");
35717
- mediaRelationshipId = mediaRelationshipId || ctx.slideRelationshipRegistry.nextRelationshipId();
35763
+ const relationshipTarget = mediaElement.mediaPath.replace(/^ppt\//u, "../");
35764
+ mediaRelationshipId ||= ctx.slideRelationshipRegistry.nextRelationshipId();
35765
+ const pathRelType = mediaElement.isLinked ? this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes) : relTypes.media;
35718
35766
  ctx.slideRelationshipRegistry.upsertRelationship(
35719
35767
  mediaRelationshipId,
35720
- this.slideMediaRelationshipBuilder.resolveMediaRelationshipType(mediaType, relTypes),
35768
+ pathRelType,
35721
35769
  relationshipTarget
35722
35770
  );
35723
35771
  shape = this.createMediaGraphicFrameXml(mediaElement, mediaRelationshipId);
@@ -36146,6 +36194,9 @@ var PptxHandlerRuntime33 = class extends PptxHandlerRuntime32 {
36146
36194
  if (slideContainsA16Element(slideNode)) {
36147
36195
  ensureA16NamespaceOnSlideRoot(slideNode);
36148
36196
  }
36197
+ if (slideContainsMathElement(slideNode)) {
36198
+ ensureMathNamespaceOnSlideRoot(slideNode);
36199
+ }
36149
36200
  this.zip.file(slide.id, this.builder.build(xmlObj));
36150
36201
  }
36151
36202
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-viewer-core",
3
- "version": "1.1.37",
3
+ "version": "1.1.39",
4
4
  "description": "PowerPoint PPTX engine: parse, edit, serialize, and convert .pptx files. Framework-agnostic TypeScript SDK.",
5
5
  "keywords": [
6
6
  "converter",