@aixa-transformation/pptx-viewer 2.0.31 → 2.0.33

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.
@@ -8630,7 +8630,7 @@ var PptxPresentationSlidesReconciler = class {
8630
8630
  if (typeof relationshipId2 === "string" && relationshipId2.length > 0) {
8631
8631
  usedRIds.add(relationshipId2);
8632
8632
  }
8633
- if (relationshipType === input.slideRelationshipType && typeof relationshipId2 === "string" && typeof relationshipTarget2 === "string") {
8633
+ if (this.isSlideRelationshipType(relationshipType, input.slideRelationshipType) && typeof relationshipId2 === "string" && typeof relationshipTarget2 === "string") {
8634
8634
  slideTargetByRid.set(relationshipId2, relationshipTarget2);
8635
8635
  continue;
8636
8636
  }
@@ -8845,6 +8845,13 @@ var PptxPresentationSlidesReconciler = class {
8845
8845
  }
8846
8846
  return [value];
8847
8847
  }
8848
+ /** Match equivalent Strict and Transitional slide relationship URIs. */
8849
+ isSlideRelationshipType(value, expected) {
8850
+ if (typeof value !== "string") {
8851
+ return false;
8852
+ }
8853
+ return value === expected || value.endsWith("/relationships/slide");
8854
+ }
8848
8855
  };
8849
8856
  function isExternalTarget(target) {
8850
8857
  const normalized = target.trim();
@@ -16387,8 +16394,16 @@ var PptxDocumentPropertiesUpdater = class {
16387
16394
  const relationships = relsData["Relationships"];
16388
16395
  if (relationships) {
16389
16396
  const rels = Array.isArray(relationships["Relationship"]) ? relationships["Relationship"] : relationships["Relationship"] ? [relationships["Relationship"]] : [];
16390
- const hasCustomRel = rels.some((r) => String(r?.["@_Type"] || "") === customRelType);
16391
- if (!hasCustomRel) {
16397
+ const customRelationships = rels.filter(
16398
+ (relationship) => this.isCustomPropertiesRelationship(relationship)
16399
+ );
16400
+ if (customRelationships.length > 0) {
16401
+ const retained = customRelationships[0];
16402
+ relationships["Relationship"] = rels.filter(
16403
+ (relationship) => !this.isCustomPropertiesRelationship(relationship) || relationship === retained
16404
+ );
16405
+ this.context.zip.file("_rels/.rels", this.context.builder.build(relsData));
16406
+ } else {
16392
16407
  let maxId = 0;
16393
16408
  for (const rel of rels) {
16394
16409
  const id = String(rel?.["@_Id"] || "");
@@ -16417,7 +16432,6 @@ var PptxDocumentPropertiesUpdater = class {
16417
16432
  * orphan content-type entry referencing a deleted part.
16418
16433
  */
16419
16434
  async removeCustomPropertiesPackagingArtifacts() {
16420
- const customRelType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
16421
16435
  const ctFile = this.context.zip.file("[Content_Types].xml");
16422
16436
  if (ctFile) {
16423
16437
  try {
@@ -16445,7 +16459,9 @@ var PptxDocumentPropertiesUpdater = class {
16445
16459
  const relationships = relsData["Relationships"];
16446
16460
  if (relationships) {
16447
16461
  const rels = Array.isArray(relationships["Relationship"]) ? relationships["Relationship"] : relationships["Relationship"] ? [relationships["Relationship"]] : [];
16448
- const filtered = rels.filter((r) => String(r?.["@_Type"] || "") !== customRelType);
16462
+ const filtered = rels.filter(
16463
+ (relationship) => !this.isCustomPropertiesRelationship(relationship)
16464
+ );
16449
16465
  if (filtered.length !== rels.length) {
16450
16466
  relationships["Relationship"] = filtered;
16451
16467
  this.context.zip.file("_rels/.rels", this.context.builder.build(relsData));
@@ -16455,6 +16471,11 @@ var PptxDocumentPropertiesUpdater = class {
16455
16471
  }
16456
16472
  }
16457
16473
  }
16474
+ isCustomPropertiesRelationship(relationship) {
16475
+ const type = String(relationship?.["@_Type"] || "");
16476
+ const target = String(relationship?.["@_Target"] || "").replace(/\\/gu, "/").replace(/^\.\//u, "");
16477
+ return target === "docProps/custom.xml" || type.endsWith("/relationships/custom-properties") || type.endsWith("/relationships/customProperties");
16478
+ }
16458
16479
  normalizeCustomPropertyType(type) {
16459
16480
  const supportedTypes = /* @__PURE__ */ new Set([
16460
16481
  "lpwstr",
@@ -31693,6 +31714,45 @@ function isEotFormat(data) {
31693
31714
  const magic = readUint16LE(data, EOT_MAGIC_OFFSET);
31694
31715
  return magic === EOT_MAGIC;
31695
31716
  }
31717
+ function createEotFromSfnt(fontData, options) {
31718
+ const encodeName2 = (value) => {
31719
+ const bytes = new Uint8Array((value.length + 1) * 2);
31720
+ const view2 = new DataView(bytes.buffer);
31721
+ for (let i = 0; i < value.length; i++) {
31722
+ view2.setUint16(i * 2, value.charCodeAt(i), true);
31723
+ }
31724
+ return bytes;
31725
+ };
31726
+ const names = [
31727
+ encodeName2(options.familyName),
31728
+ encodeName2(options.styleName ?? ""),
31729
+ encodeName2(""),
31730
+ encodeName2(options.fullName ?? options.familyName)
31731
+ ];
31732
+ const headerSize = 80 + names.reduce((sum, name) => sum + 4 + name.length, 0);
31733
+ const result = new Uint8Array(headerSize + fontData.length);
31734
+ const view = new DataView(result.buffer);
31735
+ view.setUint32(0, result.length, true);
31736
+ view.setUint32(4, fontData.length, true);
31737
+ view.setUint32(8, 131073, true);
31738
+ view.setUint32(12, 0, true);
31739
+ result[26] = 1;
31740
+ result[27] = options.italic ? 1 : 0;
31741
+ view.setUint32(28, options.weight ?? 400, true);
31742
+ view.setUint16(32, 0, true);
31743
+ view.setUint16(34, EOT_MAGIC, true);
31744
+ let offset = 80;
31745
+ for (const name of names) {
31746
+ view.setUint16(offset, 0, true);
31747
+ offset += 2;
31748
+ view.setUint16(offset, name.length, true);
31749
+ offset += 2;
31750
+ result.set(name, offset);
31751
+ offset += name.length;
31752
+ }
31753
+ result.set(fontData, offset);
31754
+ return result;
31755
+ }
31696
31756
  function parseEotHeader(data) {
31697
31757
  if (!isEotFormat(data)) {
31698
31758
  return null;
@@ -31795,7 +31855,8 @@ function guidToKey(guid) {
31795
31855
  }
31796
31856
  const key = new Uint8Array(KEY_LENGTH);
31797
31857
  for (let i = 0; i < KEY_LENGTH; i++) {
31798
- key[i] = parseInt(stripped.substring(i * 2, i * 2 + 2), 16);
31858
+ const sourceIndex = KEY_LENGTH - i - 1;
31859
+ key[i] = parseInt(stripped.substring(sourceIndex * 2, sourceIndex * 2 + 2), 16);
31799
31860
  }
31800
31861
  return key;
31801
31862
  }
@@ -41647,9 +41708,13 @@ var NAMESPACE_PAIRS = [
41647
41708
  "http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
41648
41709
  ],
41649
41710
  [
41650
- "http://purl.oclc.org/ooxml/officeDocument/custom-properties",
41711
+ "http://purl.oclc.org/ooxml/officeDocument/customProperties",
41651
41712
  "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
41652
41713
  ],
41714
+ [
41715
+ "http://purl.oclc.org/ooxml/officeDocument/relationships/customProperties",
41716
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
41717
+ ],
41653
41718
  [
41654
41719
  "http://purl.oclc.org/ooxml/officeDocument/extended-properties",
41655
41720
  "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
@@ -62291,6 +62356,13 @@ var PptxHandlerRuntime24 = class _PptxHandlerRuntime7 extends PptxHandlerRuntime
62291
62356
  };
62292
62357
  for (const variant of variants) {
62293
62358
  const fontData = variant.rawFontData;
62359
+ const isWebFont = variant.format === "woff" || variant.format === "woff2";
62360
+ const hasSfntSignature = fontData.length >= 4 && (fontData[0] === 0 && fontData[1] === 1 && fontData[2] === 0 && fontData[3] === 0 || String.fromCharCode(fontData[0], fontData[1], fontData[2], fontData[3]) === "OTTO" || String.fromCharCode(fontData[0], fontData[1], fontData[2], fontData[3]) === "true" || String.fromCharCode(fontData[0], fontData[1], fontData[2], fontData[3]) === "ttcf");
62361
+ if (!variant.originalRId && (isWebFont || !hasSfntSignature)) {
62362
+ throw new Error(
62363
+ `Cannot embed custom font "${variant.name}" in PowerPoint: use a valid .ttf or .otf font file, not WOFF/WOFF2 browser data.`
62364
+ );
62365
+ }
62294
62366
  const hasOriginal = Boolean(variant.originalRId && variant.partPath);
62295
62367
  const reuseObfuscation = hasOriginal && Boolean(variant.fontGuid);
62296
62368
  const reuseVerbatim = hasOriginal && !variant.fontGuid && Boolean(variant.originalPartBytes);
@@ -62313,10 +62385,16 @@ var PptxHandlerRuntime24 = class _PptxHandlerRuntime7 extends PptxHandlerRuntime
62313
62385
  bytesToWrite = variant.originalPartBytes;
62314
62386
  } else {
62315
62387
  guid = variant.fontGuid ?? generateFontGuid();
62316
- const fileName = `{${guid}}.fntdata`;
62388
+ const usedFontNumbers = relationships.map((relationship) => /fonts\/font(?<number>\d+)\.fntdata$/iu.exec(String(relationship?.["@_Target"] || ""))?.groups?.number).map((number) => Number(number)).filter((number) => Number.isFinite(number));
62389
+ const fileName = `font${Math.max(0, ...usedFontNumbers) + 1}.fntdata`;
62317
62390
  fontPartPath = `ppt/fonts/${fileName}`;
62318
62391
  relativeTarget4 = `fonts/${fileName}`;
62319
- bytesToWrite = obfuscateFont(fontData, guid);
62392
+ bytesToWrite = createEotFromSfnt(fontData, {
62393
+ familyName: variant.name,
62394
+ styleName: variant.bold ? variant.italic ? "Bold Italic" : "Bold" : variant.italic ? "Italic" : "Regular",
62395
+ weight: variant.bold ? 700 : 400,
62396
+ italic: variant.italic
62397
+ });
62320
62398
  const existingRel = relationships.find(
62321
62399
  (r) => String(r?.["@_Target"] || "") === relativeTarget4
62322
62400
  );