pptx-viewer-core 1.2.5 → 1.2.7

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
@@ -12601,6 +12601,17 @@ function resolveLayoutDisplayName(input) {
12601
12601
  return fallbackFromPath(input.path);
12602
12602
  }
12603
12603
 
12604
+ // src/core/utils/strip-parent-dir-segments.ts
12605
+ function stripParentDirSegments(path) {
12606
+ let result = path;
12607
+ let previous;
12608
+ do {
12609
+ previous = result;
12610
+ result = previous.replace(/\.\.\//g, "");
12611
+ } while (result !== previous);
12612
+ return result;
12613
+ }
12614
+
12604
12615
  // src/core/utils/ole2-parser-types.ts
12605
12616
  var OLE_MAGIC = new Uint8Array([208, 207, 17, 224, 161, 27, 26, 225]);
12606
12617
  var ENDOFCHAIN = 4294967294;
@@ -42078,7 +42089,7 @@ var PptxHandlerRuntime57 = class extends PptxHandlerRuntime56 {
42078
42089
  for (const [, target] of layoutRels.entries()) {
42079
42090
  if (target.includes("slideMaster")) {
42080
42091
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
42081
- const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
42092
+ const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
42082
42093
  try {
42083
42094
  const masterXmlStr = await this.zip.file(masterPath)?.async("string");
42084
42095
  if (masterXmlStr) {
@@ -42102,7 +42113,7 @@ var PptxHandlerRuntime57 = class extends PptxHandlerRuntime56 {
42102
42113
  for (const [, target] of slideRels.entries()) {
42103
42114
  if (target.includes("slideLayout")) {
42104
42115
  const slideDir = slidePath.substring(0, slidePath.lastIndexOf("/") + 1);
42105
- const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${target.replace("../", "")}`;
42116
+ const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${stripParentDirSegments(target)}`;
42106
42117
  try {
42107
42118
  const layoutXmlStr = await this.zip.file(layoutPath)?.async("string");
42108
42119
  if (layoutXmlStr) {
@@ -42130,7 +42141,7 @@ var PptxHandlerRuntime57 = class extends PptxHandlerRuntime56 {
42130
42141
  for (const [, target] of slideRels.entries()) {
42131
42142
  if (target.includes("slideLayout")) {
42132
42143
  const slideDir = slidePath.substring(0, slidePath.lastIndexOf("/") + 1);
42133
- const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${target.replace("../", "")}`;
42144
+ const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${stripParentDirSegments(target)}`;
42134
42145
  try {
42135
42146
  const layoutXmlStr = await this.zip.file(layoutPath)?.async("string");
42136
42147
  if (layoutXmlStr) {
@@ -42159,7 +42170,7 @@ var PptxHandlerRuntime57 = class extends PptxHandlerRuntime56 {
42159
42170
  for (const [, target] of layoutRels.entries()) {
42160
42171
  if (target.includes("slideMaster")) {
42161
42172
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
42162
- const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
42173
+ const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
42163
42174
  try {
42164
42175
  const masterXmlStr = await this.zip.file(masterPath)?.async("string");
42165
42176
  if (masterXmlStr) {
@@ -42188,7 +42199,7 @@ var PptxHandlerRuntime58 = class extends PptxHandlerRuntime57 {
42188
42199
  for (const [, target] of slideRels.entries()) {
42189
42200
  if (target.includes("slideLayout")) {
42190
42201
  const slideDir = slidePath.substring(0, slidePath.lastIndexOf("/") + 1);
42191
- const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${target.replace("../", "")}`;
42202
+ const layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${stripParentDirSegments(target)}`;
42192
42203
  try {
42193
42204
  const layoutXmlStr = await this.zip.file(layoutPath)?.async("string");
42194
42205
  if (layoutXmlStr) {
@@ -42217,7 +42228,7 @@ var PptxHandlerRuntime58 = class extends PptxHandlerRuntime57 {
42217
42228
  for (const [, target] of layoutRels.entries()) {
42218
42229
  if (target.includes("slideMaster")) {
42219
42230
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
42220
- const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
42231
+ const masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
42221
42232
  try {
42222
42233
  const masterXmlStr = await this.zip.file(masterPath)?.async("string");
42223
42234
  if (masterXmlStr) {
@@ -42242,7 +42253,7 @@ var PptxHandlerRuntime58 = class extends PptxHandlerRuntime57 {
42242
42253
  for (const [, target] of slideRels.entries()) {
42243
42254
  if (target.includes("slideLayout")) {
42244
42255
  const slideDir = slidePath.substring(0, slidePath.lastIndexOf("/") + 1);
42245
- return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${target.replace("../", "")}`;
42256
+ return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${stripParentDirSegments(target)}`;
42246
42257
  }
42247
42258
  }
42248
42259
  return void 0;
@@ -42258,7 +42269,7 @@ var PptxHandlerRuntime58 = class extends PptxHandlerRuntime57 {
42258
42269
  for (const [, target] of layoutRels.entries()) {
42259
42270
  if (target.includes("slideMaster")) {
42260
42271
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
42261
- return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
42272
+ return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
42262
42273
  }
42263
42274
  }
42264
42275
  return void 0;
@@ -42902,7 +42913,7 @@ var PptxHandlerRuntime61 = class extends PptxHandlerRuntime60 {
42902
42913
  for (const [, target] of layoutRels.entries()) {
42903
42914
  if (target.includes("slideMaster")) {
42904
42915
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
42905
- masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
42916
+ masterPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
42906
42917
  break;
42907
42918
  }
42908
42919
  }
@@ -43036,7 +43047,7 @@ var PptxHandlerRuntime62 = class extends PptxHandlerRuntime61 {
43036
43047
  for (const [, target] of slideRels.entries()) {
43037
43048
  if (target.includes("slideLayout")) {
43038
43049
  const slideDir = slidePath.substring(0, slidePath.lastIndexOf("/") + 1);
43039
- layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${target.replace("../", "")}`;
43050
+ layoutPath = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(slideDir, target) : `ppt/${stripParentDirSegments(target)}`;
43040
43051
  break;
43041
43052
  }
43042
43053
  }
@@ -46788,7 +46799,7 @@ var PptxHandlerRuntime78 = class extends PptxHandlerRuntime77 {
46788
46799
  }
46789
46800
  return stack.join("/");
46790
46801
  }
46791
- return `ppt/${target.replace("../", "")}`;
46802
+ return `ppt/${stripParentDirSegments(target)}`;
46792
46803
  }
46793
46804
  }
46794
46805
  return void 0;
@@ -47348,7 +47359,7 @@ var PptxHandlerRuntime80 = class extends PptxHandlerRuntime79 {
47348
47359
  for (const [, target] of layoutRels.entries()) {
47349
47360
  if (target.includes("slideMaster")) {
47350
47361
  const layoutDir = layoutPath.substring(0, layoutPath.lastIndexOf("/") + 1);
47351
- return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${target.replace("../", "")}`;
47362
+ return target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(layoutDir, target) : `ppt/${stripParentDirSegments(target)}`;
47352
47363
  }
47353
47364
  }
47354
47365
  return void 0;
@@ -47417,7 +47428,7 @@ var PptxHandlerRuntime80 = class extends PptxHandlerRuntime79 {
47417
47428
  for (const [, target] of masterRels.entries()) {
47418
47429
  if (target.includes("slideLayout")) {
47419
47430
  const masterDir = masterPath.substring(0, masterPath.lastIndexOf("/") + 1);
47420
- const resolved = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(masterDir, target) : `ppt/${target.replace("../", "")}`;
47431
+ const resolved = target.startsWith("/") ? target.substring(1) : target.startsWith("..") ? this.resolvePath(masterDir, target) : `ppt/${stripParentDirSegments(target)}`;
47421
47432
  masterLayoutPaths.add(resolved);
47422
47433
  }
47423
47434
  }
@@ -56304,7 +56315,7 @@ function getShapeClipPathFromPreset(shapeType, width, height, adjustments) {
56304
56315
  if (!result || result.svgPath === "") {
56305
56316
  return void 0;
56306
56317
  }
56307
- const escaped = result.svgPath.replace(/'/g, "\\'");
56318
+ const escaped = result.svgPath.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
56308
56319
  return `path('${escaped}')`;
56309
56320
  }
56310
56321
  function getRoundRectRadiusPx(element) {
@@ -58235,7 +58246,7 @@ function moveSlidesToSection(data, slideIndices, targetSectionId) {
58235
58246
  }
58236
58247
 
58237
58248
  // src/core/builders/sdk/template-engine-helpers.ts
58238
- var PLACEHOLDER_RE = /\{\{([^}]+)\}\}/g;
58249
+ var PLACEHOLDER_RE = /\{\{([^{}]+)\}\}/g;
58239
58250
  var EACH_OPEN_RE = /^\s*#each\s+([\w.]+)\s*$/;
58240
58251
  var EACH_CLOSE_RE = /^\s*\/each\s*$/;
58241
58252
  var IF_OPEN_RE = /^\s*#if\s+(!?[\w.]+)\s*$/;
@@ -58299,7 +58310,7 @@ function processInlineConditionals(text, data) {
58299
58310
  let safety = 0;
58300
58311
  const MAX_ITERATIONS = 100;
58301
58312
  while (safety++ < MAX_ITERATIONS) {
58302
- const ifOpenPattern = /\{\{\s*#if\s+([^}]+)\s*\}\}((?:(?!\{\{\s*#if\s)(?!\{\{\s*\/if\s*\}\}).)*?)\{\{\s*\/if\s*\}\}/s;
58313
+ const ifOpenPattern = /\{\{\s*#if\s+(!?[\w.]+)\s*\}\}((?:(?!\{\{\s*#if\s)(?!\{\{\s*\/if\s*\}\}).)*?)\{\{\s*\/if\s*\}\}/s;
58303
58314
  const match = ifOpenPattern.exec(result);
58304
58315
  if (!match) {
58305
58316
  break;
@@ -58311,6 +58322,8 @@ function processInlineConditionals(text, data) {
58311
58322
  }
58312
58323
  return result;
58313
58324
  }
58325
+
58326
+ // src/core/builders/sdk/template-engine-segments.ts
58314
58327
  function replaceTokensAcrossSegments(segments, data) {
58315
58328
  if (segments.length === 0) {
58316
58329
  return;
@@ -58331,7 +58344,7 @@ function replaceTokensAcrossSegments(segments, data) {
58331
58344
  const fullText = textParts.join("");
58332
58345
  const afterConditionals = processInlineConditionals(fullText, data);
58333
58346
  if (afterConditionals !== fullText) {
58334
- redistributeText(segments, segmentMap, fullText, afterConditionals);
58347
+ redistributeText(segments, fullText, afterConditionals);
58335
58348
  replaceTokensAcrossSegments(segments, data);
58336
58349
  return;
58337
58350
  }
@@ -58389,7 +58402,7 @@ function replaceTokensAcrossSegments(segments, data) {
58389
58402
  }
58390
58403
  }
58391
58404
  }
58392
- function redistributeText(segments, _segmentMap, _originalFull, newFull, _data) {
58405
+ function redistributeText(segments, _originalFull, newFull) {
58393
58406
  let placed = false;
58394
58407
  for (const seg of segments) {
58395
58408
  if (seg.isParagraphBreak) {
@@ -58631,15 +58644,126 @@ async function mailMerge(handler, data, records) {
58631
58644
  }
58632
58645
 
58633
58646
  // src/core/builders/sdk/text-operations.ts
58634
- function toGlobalRegex(search) {
58647
+ function toSearchRegex(search) {
58635
58648
  if (typeof search === "string") {
58636
58649
  const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
58637
58650
  return new RegExp(escaped, "g");
58638
58651
  }
58639
- if (search.global) {
58640
- return search;
58652
+ return search;
58653
+ }
58654
+ function execAll(regex, text) {
58655
+ const results = [];
58656
+ if (regex.global || regex.sticky) {
58657
+ regex.lastIndex = 0;
58658
+ let match;
58659
+ while ((match = regex.exec(text)) !== null) {
58660
+ results.push(match);
58661
+ if (match[0].length === 0) {
58662
+ regex.lastIndex += 1;
58663
+ }
58664
+ }
58665
+ return results;
58666
+ }
58667
+ let offset = 0;
58668
+ let remaining = text;
58669
+ while (remaining.length > 0) {
58670
+ const match = regex.exec(remaining);
58671
+ if (!match) {
58672
+ break;
58673
+ }
58674
+ const adjusted = [...match];
58675
+ adjusted.index = offset + match.index;
58676
+ adjusted.input = text;
58677
+ adjusted.groups = match.groups;
58678
+ results.push(adjusted);
58679
+ const advance = match.index + (match[0].length || 1);
58680
+ offset += advance;
58681
+ remaining = remaining.slice(advance);
58682
+ }
58683
+ return results;
58684
+ }
58685
+ function expandReplacement(replacement, match, fullText) {
58686
+ const closeAngleIndices = [];
58687
+ for (let k = 0; k < replacement.length; k += 1) {
58688
+ if (replacement[k] === ">") {
58689
+ closeAngleIndices.push(k);
58690
+ }
58691
+ }
58692
+ let result = "";
58693
+ let i = 0;
58694
+ let gtPtr = 0;
58695
+ while (i < replacement.length) {
58696
+ if (replacement[i] !== "$" || i + 1 >= replacement.length) {
58697
+ result += replacement[i];
58698
+ i += 1;
58699
+ continue;
58700
+ }
58701
+ const next = replacement[i + 1];
58702
+ if (next === "$") {
58703
+ result += "$";
58704
+ i += 2;
58705
+ } else if (next === "&") {
58706
+ result += match[0];
58707
+ i += 2;
58708
+ } else if (next === "`") {
58709
+ result += fullText.slice(0, match.index);
58710
+ i += 2;
58711
+ } else if (next === "'") {
58712
+ result += fullText.slice(match.index + match[0].length);
58713
+ i += 2;
58714
+ } else if (next === "<") {
58715
+ while (gtPtr < closeAngleIndices.length && closeAngleIndices[gtPtr] < i + 2) {
58716
+ gtPtr += 1;
58717
+ }
58718
+ const closeIdx = gtPtr < closeAngleIndices.length ? closeAngleIndices[gtPtr] : -1;
58719
+ if (closeIdx === -1) {
58720
+ result += "$";
58721
+ i += 1;
58722
+ } else {
58723
+ const groupName = replacement.slice(i + 2, closeIdx);
58724
+ result += match.groups?.[groupName] ?? "";
58725
+ i = closeIdx + 1;
58726
+ }
58727
+ } else if (next >= "0" && next <= "9") {
58728
+ let digits = next;
58729
+ let digitsEnd = i + 2;
58730
+ if (digitsEnd < replacement.length && replacement[digitsEnd] >= "0" && replacement[digitsEnd] <= "9") {
58731
+ digits += replacement[digitsEnd];
58732
+ digitsEnd += 1;
58733
+ }
58734
+ let groupIndex = Number(digits);
58735
+ if (digits.length === 2 && !(groupIndex >= 1 && groupIndex < match.length)) {
58736
+ digits = digits.slice(0, 1);
58737
+ groupIndex = Number(digits);
58738
+ digitsEnd = i + 2;
58739
+ }
58740
+ if (groupIndex >= 1 && groupIndex < match.length) {
58741
+ result += match[groupIndex] ?? "";
58742
+ i = digitsEnd;
58743
+ } else {
58744
+ result += "$";
58745
+ i += 1;
58746
+ }
58747
+ } else {
58748
+ result += "$";
58749
+ i += 1;
58750
+ }
58641
58751
  }
58642
- return new RegExp(search.source, `${search.flags}g`);
58752
+ return result;
58753
+ }
58754
+ function applyReplacements(text, matches, replacement) {
58755
+ if (matches.length === 0) {
58756
+ return text;
58757
+ }
58758
+ let result = "";
58759
+ let cursor = 0;
58760
+ for (const match of matches) {
58761
+ result += text.slice(cursor, match.index);
58762
+ result += expandReplacement(replacement, match, text);
58763
+ cursor = match.index + match[0].length;
58764
+ }
58765
+ result += text.slice(cursor);
58766
+ return result;
58643
58767
  }
58644
58768
  function collectElements(elements) {
58645
58769
  const result = [];
@@ -58655,7 +58779,7 @@ function findText(slides, search) {
58655
58779
  if (typeof search === "string" && search === "") {
58656
58780
  return [];
58657
58781
  }
58658
- const regex = toGlobalRegex(search);
58782
+ const regex = toSearchRegex(search);
58659
58783
  const results = [];
58660
58784
  slides.forEach((slide, slideIndex) => {
58661
58785
  const allElements = collectElements(slide.elements ?? []);
@@ -58666,9 +58790,7 @@ function findText(slides, search) {
58666
58790
  const segments = element.textSegments ?? [];
58667
58791
  segments.forEach((seg, segIndex) => {
58668
58792
  const text = seg.text ?? "";
58669
- regex.lastIndex = 0;
58670
- let match;
58671
- while ((match = regex.exec(text)) !== null) {
58793
+ for (const match of execAll(regex, text)) {
58672
58794
  results.push({
58673
58795
  slideIndex,
58674
58796
  elementId: element.id,
@@ -58676,9 +58798,6 @@ function findText(slides, search) {
58676
58798
  text: match[0],
58677
58799
  matchIndex: match.index
58678
58800
  });
58679
- if (match[0].length === 0) {
58680
- regex.lastIndex += 1;
58681
- }
58682
58801
  }
58683
58802
  });
58684
58803
  }
@@ -58689,7 +58808,7 @@ function replaceTextInSlide(slide, search, replacement) {
58689
58808
  if (typeof search === "string" && search === "") {
58690
58809
  return 0;
58691
58810
  }
58692
- const regex = toGlobalRegex(search);
58811
+ const regex = toSearchRegex(search);
58693
58812
  let totalReplacements = 0;
58694
58813
  function processElements2(elements) {
58695
58814
  for (const element of elements) {
@@ -58701,23 +58820,12 @@ function replaceTextInSlide(slide, search, replacement) {
58701
58820
  }
58702
58821
  const segments = element.textSegments ?? [];
58703
58822
  let elementTextChanged = false;
58704
- for (let segIdx = 0; segIdx < segments.length; segIdx++) {
58705
- const seg = segments[segIdx];
58823
+ for (const seg of segments) {
58706
58824
  const originalText = seg.text ?? "";
58707
- regex.lastIndex = 0;
58708
- let matchCount = 0;
58709
- let m;
58710
- const countRegex = toGlobalRegex(search);
58711
- while ((m = countRegex.exec(originalText)) !== null) {
58712
- matchCount++;
58713
- if (m[0].length === 0) {
58714
- countRegex.lastIndex += 1;
58715
- }
58716
- }
58717
- if (matchCount > 0) {
58718
- const newText = originalText.replace(toGlobalRegex(search), replacement);
58719
- seg.text = newText;
58720
- totalReplacements += matchCount;
58825
+ const matches = execAll(regex, originalText);
58826
+ if (matches.length > 0) {
58827
+ seg.text = applyReplacements(originalText, matches, replacement);
58828
+ totalReplacements += matches.length;
58721
58829
  elementTextChanged = true;
58722
58830
  }
58723
58831
  }
@@ -62681,7 +62789,7 @@ ${htmlRows.join("\n")}
62681
62789
  return parts.join("").trim();
62682
62790
  }
62683
62791
  escapeMarkdownTableCell(text) {
62684
- return text.replace(/\|/g, "\\|").replace(/\n+/g, " ").trim();
62792
+ return text.replace(/\\/g, "\\\\").replace(/\|/g, "\\|").replace(/\n+/g, " ").trim();
62685
62793
  }
62686
62794
  };
62687
62795
 
@@ -65790,6 +65898,7 @@ exports.setElementLocked = setElementLocked;
65790
65898
  exports.setSmartArtNodeStyle = setSmartArtNodeStyle;
65791
65899
  exports.shouldRenderFallbackLabel = shouldRenderFallbackLabel;
65792
65900
  exports.shouldReturnToZoomSlide = shouldReturnToZoomSlide;
65901
+ exports.stripParentDirSegments = stripParentDirSegments;
65793
65902
  exports.subtractPolygons = subtractPolygons;
65794
65903
  exports.subtractShapes = subtractShapes;
65795
65904
  exports.subtractSvgPaths = subtractSvgPaths;