pptx-react-viewer 3.12.0 → 3.13.0

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.
Files changed (135) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{AiChatPanel-TXCDQDHD.js → AiChatPanel-E53JJRZX.js} +24 -24
  3. package/dist/AiChatPanel-E53JJRZX.js.br +0 -0
  4. package/dist/AiChatPanel-E53JJRZX.js.gz +0 -0
  5. package/dist/{AiChatPanel-SCA4RLFI.mjs → AiChatPanel-JTXC5WWH.mjs} +3 -3
  6. package/dist/AiChatPanel-JTXC5WWH.mjs.br +0 -0
  7. package/dist/AiChatPanel-JTXC5WWH.mjs.gz +0 -0
  8. package/dist/{Area3DChartScene-YAK6W2J5.js → Area3DChartScene-J7G54OH4.js} +2 -2
  9. package/dist/{Area3DChartScene-YAK6W2J5.js.br → Area3DChartScene-J7G54OH4.js.br} +0 -0
  10. package/dist/Area3DChartScene-J7G54OH4.js.gz +0 -0
  11. package/dist/{Area3DChartScene-NSV5AIMM.mjs → Area3DChartScene-JQ2VU73H.mjs} +1 -1
  12. package/dist/Area3DChartScene-JQ2VU73H.mjs.br +0 -0
  13. package/dist/Area3DChartScene-JQ2VU73H.mjs.gz +0 -0
  14. package/dist/{Bar3DChartScene-DFJ7XK3Q.mjs → Bar3DChartScene-5HC7LYBH.mjs} +1 -1
  15. package/dist/Bar3DChartScene-5HC7LYBH.mjs.br +0 -0
  16. package/dist/Bar3DChartScene-5HC7LYBH.mjs.gz +0 -0
  17. package/dist/{Bar3DChartScene-WNBEX3TN.js → Bar3DChartScene-JV3A2P6O.js} +2 -2
  18. package/dist/{Bar3DChartScene-WNBEX3TN.js.br → Bar3DChartScene-JV3A2P6O.js.br} +0 -0
  19. package/dist/Bar3DChartScene-JV3A2P6O.js.gz +0 -0
  20. package/dist/{Line3DChartScene-TK6RPGET.mjs → Line3DChartScene-4ZAOOU7U.mjs} +1 -1
  21. package/dist/Line3DChartScene-4ZAOOU7U.mjs.br +0 -0
  22. package/dist/Line3DChartScene-4ZAOOU7U.mjs.gz +0 -0
  23. package/dist/{Line3DChartScene-PXA6WAQG.js → Line3DChartScene-7SN7TVKQ.js} +2 -2
  24. package/dist/{Line3DChartScene-PXA6WAQG.js.br → Line3DChartScene-7SN7TVKQ.js.br} +0 -0
  25. package/dist/Line3DChartScene-7SN7TVKQ.js.gz +0 -0
  26. package/dist/{Model3DScene-FJQOUWCV.js → Model3DScene-GQANXXQD.js} +2 -2
  27. package/dist/Model3DScene-GQANXXQD.js.br +0 -0
  28. package/dist/Model3DScene-GQANXXQD.js.gz +0 -0
  29. package/dist/{Model3DScene-7FZSQ3SP.mjs → Model3DScene-GWIBUQ2U.mjs} +1 -1
  30. package/dist/Model3DScene-GWIBUQ2U.mjs.br +0 -0
  31. package/dist/Model3DScene-GWIBUQ2U.mjs.gz +0 -0
  32. package/dist/{PieChart3DScene-P25IGVT6.js → PieChart3DScene-QPFDRMEA.js} +2 -2
  33. package/dist/{PieChart3DScene-P25IGVT6.js.br → PieChart3DScene-QPFDRMEA.js.br} +0 -0
  34. package/dist/PieChart3DScene-QPFDRMEA.js.gz +0 -0
  35. package/dist/{PieChart3DScene-KKZTAIFB.mjs → PieChart3DScene-RDTOLFTD.mjs} +1 -1
  36. package/dist/PieChart3DScene-RDTOLFTD.mjs.br +0 -0
  37. package/dist/PieChart3DScene-RDTOLFTD.mjs.gz +0 -0
  38. package/dist/{SurfaceChart3DScene-LWJCERTR.mjs → SurfaceChart3DScene-5JQCRWA5.mjs} +1 -1
  39. package/dist/SurfaceChart3DScene-5JQCRWA5.mjs.br +0 -0
  40. package/dist/SurfaceChart3DScene-5JQCRWA5.mjs.gz +0 -0
  41. package/dist/{SurfaceChart3DScene-36MT6QAK.js → SurfaceChart3DScene-JLYGC7QU.js} +2 -2
  42. package/dist/{SurfaceChart3DScene-36MT6QAK.js.br → SurfaceChart3DScene-JLYGC7QU.js.br} +0 -0
  43. package/dist/SurfaceChart3DScene-JLYGC7QU.js.gz +0 -0
  44. package/dist/{chunk-45AVHO7M.js → chunk-G2Z7QULX.js} +5 -5
  45. package/dist/chunk-G2Z7QULX.js.br +0 -0
  46. package/dist/chunk-G2Z7QULX.js.gz +0 -0
  47. package/dist/{chunk-AARQTIMN.js → chunk-H3GHGSGW.js} +533 -483
  48. package/dist/chunk-H3GHGSGW.js.br +0 -0
  49. package/dist/chunk-H3GHGSGW.js.gz +0 -0
  50. package/dist/{chunk-2FSNTJVI.mjs → chunk-HB7DJENT.mjs} +1 -1
  51. package/dist/chunk-HB7DJENT.mjs.br +0 -0
  52. package/dist/chunk-HB7DJENT.mjs.gz +0 -0
  53. package/dist/{chunk-O27KNZLJ.js → chunk-IVCYND7A.js} +169 -169
  54. package/dist/chunk-IVCYND7A.js.br +0 -0
  55. package/dist/chunk-IVCYND7A.js.gz +0 -0
  56. package/dist/{chunk-WRHPPTYF.mjs → chunk-M7SNS3DQ.mjs} +103 -53
  57. package/dist/chunk-M7SNS3DQ.mjs.br +0 -0
  58. package/dist/chunk-M7SNS3DQ.mjs.gz +0 -0
  59. package/dist/{chunk-ZOEKVSSU.mjs → chunk-PKHTTHA2.mjs} +12 -12
  60. package/dist/chunk-PKHTTHA2.mjs.br +0 -0
  61. package/dist/chunk-PKHTTHA2.mjs.gz +0 -0
  62. package/dist/{chunk-C2BDHCL2.mjs → chunk-TS2DHMBS.mjs} +3443 -403
  63. package/dist/chunk-TS2DHMBS.mjs.br +0 -0
  64. package/dist/chunk-TS2DHMBS.mjs.gz +0 -0
  65. package/dist/{chunk-3WK4AE52.js → chunk-TWUAZRCG.js} +3450 -403
  66. package/dist/chunk-TWUAZRCG.js.br +0 -0
  67. package/dist/chunk-TWUAZRCG.js.gz +0 -0
  68. package/dist/{chunk-T7MY5L3O.js → chunk-UGVPKJSU.js} +1260 -1260
  69. package/dist/chunk-UGVPKJSU.js.br +0 -0
  70. package/dist/chunk-UGVPKJSU.js.gz +0 -0
  71. package/dist/{chunk-HXDNYDRJ.mjs → chunk-Y3SA5H5H.mjs} +4 -4
  72. package/dist/chunk-Y3SA5H5H.mjs.br +0 -0
  73. package/dist/chunk-Y3SA5H5H.mjs.gz +0 -0
  74. package/dist/index.js +45 -45
  75. package/dist/index.js.br +0 -0
  76. package/dist/index.js.gz +0 -0
  77. package/dist/index.mjs +5 -5
  78. package/dist/index.mjs.br +0 -0
  79. package/dist/index.mjs.gz +0 -0
  80. package/dist/internals.js +78 -78
  81. package/dist/internals.js.br +0 -0
  82. package/dist/internals.js.gz +0 -0
  83. package/dist/internals.mjs +3 -3
  84. package/dist/internals.mjs.br +0 -0
  85. package/dist/internals.mjs.gz +0 -0
  86. package/dist/viewer/index.js +26 -26
  87. package/dist/viewer/index.js.br +0 -0
  88. package/dist/viewer/index.js.gz +0 -0
  89. package/dist/viewer/index.mjs +5 -5
  90. package/dist/viewer/index.mjs.br +0 -0
  91. package/dist/viewer/index.mjs.gz +0 -0
  92. package/package.json +1 -1
  93. package/dist/AiChatPanel-SCA4RLFI.mjs.br +0 -0
  94. package/dist/AiChatPanel-SCA4RLFI.mjs.gz +0 -0
  95. package/dist/AiChatPanel-TXCDQDHD.js.br +0 -0
  96. package/dist/AiChatPanel-TXCDQDHD.js.gz +0 -0
  97. package/dist/Area3DChartScene-NSV5AIMM.mjs.br +0 -0
  98. package/dist/Area3DChartScene-NSV5AIMM.mjs.gz +0 -0
  99. package/dist/Area3DChartScene-YAK6W2J5.js.gz +0 -0
  100. package/dist/Bar3DChartScene-DFJ7XK3Q.mjs.br +0 -0
  101. package/dist/Bar3DChartScene-DFJ7XK3Q.mjs.gz +0 -0
  102. package/dist/Bar3DChartScene-WNBEX3TN.js.gz +0 -0
  103. package/dist/Line3DChartScene-PXA6WAQG.js.gz +0 -0
  104. package/dist/Line3DChartScene-TK6RPGET.mjs.br +0 -0
  105. package/dist/Line3DChartScene-TK6RPGET.mjs.gz +0 -0
  106. package/dist/Model3DScene-7FZSQ3SP.mjs.br +0 -0
  107. package/dist/Model3DScene-7FZSQ3SP.mjs.gz +0 -0
  108. package/dist/Model3DScene-FJQOUWCV.js.br +0 -0
  109. package/dist/Model3DScene-FJQOUWCV.js.gz +0 -0
  110. package/dist/PieChart3DScene-KKZTAIFB.mjs.br +0 -0
  111. package/dist/PieChart3DScene-KKZTAIFB.mjs.gz +0 -0
  112. package/dist/PieChart3DScene-P25IGVT6.js.gz +0 -0
  113. package/dist/SurfaceChart3DScene-36MT6QAK.js.gz +0 -0
  114. package/dist/SurfaceChart3DScene-LWJCERTR.mjs.br +0 -0
  115. package/dist/SurfaceChart3DScene-LWJCERTR.mjs.gz +0 -0
  116. package/dist/chunk-2FSNTJVI.mjs.br +0 -0
  117. package/dist/chunk-2FSNTJVI.mjs.gz +0 -0
  118. package/dist/chunk-3WK4AE52.js.br +0 -0
  119. package/dist/chunk-3WK4AE52.js.gz +0 -0
  120. package/dist/chunk-45AVHO7M.js.br +0 -0
  121. package/dist/chunk-45AVHO7M.js.gz +0 -0
  122. package/dist/chunk-AARQTIMN.js.br +0 -0
  123. package/dist/chunk-AARQTIMN.js.gz +0 -0
  124. package/dist/chunk-C2BDHCL2.mjs.br +0 -0
  125. package/dist/chunk-C2BDHCL2.mjs.gz +0 -0
  126. package/dist/chunk-HXDNYDRJ.mjs.br +0 -0
  127. package/dist/chunk-HXDNYDRJ.mjs.gz +0 -0
  128. package/dist/chunk-O27KNZLJ.js.br +0 -0
  129. package/dist/chunk-O27KNZLJ.js.gz +0 -0
  130. package/dist/chunk-T7MY5L3O.js.br +0 -0
  131. package/dist/chunk-T7MY5L3O.js.gz +0 -0
  132. package/dist/chunk-WRHPPTYF.mjs.br +0 -0
  133. package/dist/chunk-WRHPPTYF.mjs.gz +0 -0
  134. package/dist/chunk-ZOEKVSSU.mjs.br +0 -0
  135. package/dist/chunk-ZOEKVSSU.mjs.gz +0 -0
@@ -5503,8 +5503,8 @@ function read255Short(s) {
5503
5503
  }
5504
5504
  return value * sign;
5505
5505
  }
5506
- function unpackCVT(table, sIn) {
5507
- sIn.seekAbsolute(table.offset);
5506
+ function unpackCVT(table2, sIn) {
5507
+ sIn.seekAbsolute(table2.offset);
5508
5508
  const numEntries = sIn.readU16();
5509
5509
  const out = new Stream(null, 0);
5510
5510
  out.reserve(numEntries * 2);
@@ -5524,8 +5524,8 @@ function unpackCVT(table, sIn) {
5524
5524
  lastValue = toInt16(lastValue + val2);
5525
5525
  out.writeS16(lastValue);
5526
5526
  }
5527
- table.buf = out.toUint8Array();
5528
- table.bufSize = table.buf.length;
5527
+ table2.buf = out.toUint8Array();
5528
+ table2.bufSize = table2.buf.length;
5529
5529
  }
5530
5530
  function decodePushInstructions(sIn, sOut, pushCount) {
5531
5531
  if (pushCount === 0) {
@@ -5863,13 +5863,13 @@ function populateGlyfAndLoca(glyf, loca, headData, maxpData, streams) {
5863
5863
  loca.buf = locaStream.toUint8Array();
5864
5864
  loca.bufSize = loca.buf.length;
5865
5865
  }
5866
- function parseHead(table) {
5867
- const s = new Stream(table.buf, table.bufSize);
5866
+ function parseHead(table2) {
5867
+ const s = new Stream(table2.buf, table2.bufSize);
5868
5868
  s.seekAbsolute(50);
5869
5869
  return { indexToLocFormat: s.readS16() };
5870
5870
  }
5871
- function parseMaxp(table) {
5872
- const s = new Stream(table.buf, table.bufSize);
5871
+ function parseMaxp(table2) {
5872
+ const s = new Stream(table2.buf, table2.bufSize);
5873
5873
  const version = s.readU32();
5874
5874
  const numGlyphs = s.readU16();
5875
5875
  let maxPoints = 0;
@@ -5923,7 +5923,7 @@ function parseCTF(streams, options) {
5923
5923
  s0.seekRelative(4);
5924
5924
  const offset = s0.readU32();
5925
5925
  const size = s0.readU32();
5926
- const table = {
5926
+ const table2 = {
5927
5927
  tag,
5928
5928
  offset,
5929
5929
  bufSize: size,
@@ -5931,7 +5931,7 @@ function parseCTF(streams, options) {
5931
5931
  checksum: 0
5932
5932
  };
5933
5933
  const idx = tables.length;
5934
- tables.push(table);
5934
+ tables.push(table2);
5935
5935
  if (tag === "glyf") {
5936
5936
  glyfIdx = idx;
5937
5937
  } else if (tag === "loca") {
@@ -5945,31 +5945,31 @@ function parseCTF(streams, options) {
5945
5945
  } else ;
5946
5946
  }
5947
5947
  for (let i2 = 0; i2 < tables.length; i2++) {
5948
- const table = tables[i2];
5949
- if (table.tag === "glyf" || table.tag === "loca") {
5948
+ const table2 = tables[i2];
5949
+ if (table2.tag === "glyf" || table2.tag === "loca") {
5950
5950
  continue;
5951
5951
  }
5952
- if (table.tag === "cvt ") {
5953
- unpackCVT(table, s0);
5952
+ if (table2.tag === "cvt ") {
5953
+ unpackCVT(table2, s0);
5954
5954
  continue;
5955
5955
  }
5956
- s0.seekAbsolute(table.offset);
5957
- const buf = new Uint8Array(table.bufSize);
5958
- for (let b = 0; b < table.bufSize; b++) {
5956
+ s0.seekAbsolute(table2.offset);
5957
+ const buf = new Uint8Array(table2.bufSize);
5958
+ for (let b = 0; b < table2.bufSize; b++) {
5959
5959
  buf[b] = s0.readU8();
5960
5960
  }
5961
- table.buf = buf;
5962
- if (table.tag === "head") {
5963
- if (table.bufSize < 12) {
5961
+ table2.buf = buf;
5962
+ if (table2.tag === "head") {
5963
+ if (table2.bufSize < 12) {
5964
5964
  throw new EotError(
5965
5965
  "MALFORMED_HEAD_TABLE",
5966
- `head table too small: ${table.bufSize} bytes (need at least 12)`
5966
+ `head table too small: ${table2.bufSize} bytes (need at least 12)`
5967
5967
  );
5968
5968
  }
5969
- table.buf[8] = 0;
5970
- table.buf[9] = 0;
5971
- table.buf[10] = 0;
5972
- table.buf[11] = 0;
5969
+ table2.buf[8] = 0;
5970
+ table2.buf[9] = 0;
5971
+ table2.buf[10] = 0;
5972
+ table2.buf[11] = 0;
5973
5973
  }
5974
5974
  }
5975
5975
  if (maxpIdx < 0) {
@@ -6485,21 +6485,21 @@ function writeOffsetTable(ctr, out) {
6485
6485
  out.writeU16(rangeShift);
6486
6486
  }
6487
6487
  function writeTableDirectory(ctr, out) {
6488
- for (const table of ctr.tables) {
6489
- out.writeU8(table.tag.charCodeAt(0));
6490
- out.writeU8(table.tag.charCodeAt(1));
6491
- out.writeU8(table.tag.charCodeAt(2));
6492
- out.writeU8(table.tag.charCodeAt(3));
6493
- out.writeU32(table.checksum);
6494
- out.writeU32(table.offset);
6495
- out.writeU32(table.bufSize);
6496
- }
6497
- }
6498
- function writeTableCheckingSum(table, out) {
6499
- table.offset = out.pos;
6488
+ for (const table2 of ctr.tables) {
6489
+ out.writeU8(table2.tag.charCodeAt(0));
6490
+ out.writeU8(table2.tag.charCodeAt(1));
6491
+ out.writeU8(table2.tag.charCodeAt(2));
6492
+ out.writeU8(table2.tag.charCodeAt(3));
6493
+ out.writeU32(table2.checksum);
6494
+ out.writeU32(table2.offset);
6495
+ out.writeU32(table2.bufSize);
6496
+ }
6497
+ }
6498
+ function writeTableCheckingSum(table2, out) {
6499
+ table2.offset = out.pos;
6500
6500
  let checksum = 0;
6501
- const data = table.buf;
6502
- const len = table.bufSize;
6501
+ const data = table2.buf;
6502
+ const len = table2.bufSize;
6503
6503
  const fullWords = Math.floor(len / 4);
6504
6504
  const remainder = len % 4;
6505
6505
  for (let i2 = 0; i2 < fullWords; i2++) {
@@ -6517,7 +6517,7 @@ function writeTableCheckingSum(table, out) {
6517
6517
  checksum = checksum + word >>> 0;
6518
6518
  out.writeU32(word);
6519
6519
  }
6520
- table.checksum = checksum;
6520
+ table2.checksum = checksum;
6521
6521
  }
6522
6522
  function getTableDirectorySize(ctr) {
6523
6523
  return 16 * ctr.tables.length;
@@ -6526,8 +6526,8 @@ function getRequiredSize(ctr) {
6526
6526
  const offsetTableSize = 12;
6527
6527
  const dirSize = getTableDirectorySize(ctr);
6528
6528
  let tableDataSize = 0;
6529
- for (const table of ctr.tables) {
6530
- tableDataSize += Math.ceil(table.bufSize / 4) * 4;
6529
+ for (const table2 of ctr.tables) {
6530
+ tableDataSize += Math.ceil(table2.bufSize / 4) * 4;
6531
6531
  }
6532
6532
  return offsetTableSize + dirSize + tableDataSize;
6533
6533
  }
@@ -6539,14 +6539,14 @@ function dumpContainer(ctr) {
6539
6539
  const dirSize = getTableDirectorySize(ctr);
6540
6540
  out.pos += dirSize;
6541
6541
  let totalChecksum = 0;
6542
- for (const table of ctr.tables) {
6543
- writeTableCheckingSum(table, out);
6544
- totalChecksum = totalChecksum + table.checksum >>> 0;
6542
+ for (const table2 of ctr.tables) {
6543
+ writeTableCheckingSum(table2, out);
6544
+ totalChecksum = totalChecksum + table2.checksum >>> 0;
6545
6545
  }
6546
6546
  let headTable;
6547
- for (const table of ctr.tables) {
6548
- if (table.tag === "head") {
6549
- headTable = table;
6547
+ for (const table2 of ctr.tables) {
6548
+ if (table2.tag === "head") {
6549
+ headTable = table2;
6550
6550
  break;
6551
6551
  }
6552
6552
  }
@@ -16546,8 +16546,8 @@ function gd14(name, formula) {
16546
16546
  const parts = formula.trim().split(/\s+/);
16547
16547
  return { name, formula, args: parts.slice(1) };
16548
16548
  }
16549
- function parseGdTable(table) {
16550
- return table.trim().split(/[\n;]/).filter((entry2) => entry2.length > 0).map((entry2) => {
16549
+ function parseGdTable(table2) {
16550
+ return table2.trim().split(/[\n;]/).filter((entry2) => entry2.length > 0).map((entry2) => {
16551
16551
  const sep = entry2.indexOf("|");
16552
16552
  return gd14(entry2.slice(0, sep), entry2.slice(sep + 1));
16553
16553
  });
@@ -28579,21 +28579,21 @@ function parseBteTable(tableStream, at) {
28579
28579
  }
28580
28580
  return { fcs, pns };
28581
28581
  }
28582
- function buildBteTableBytes(table) {
28583
- const n = table.pns.length;
28582
+ function buildBteTableBytes(table2) {
28583
+ const n = table2.pns.length;
28584
28584
  const bytes = new Uint8Array((n + 1) * 4 + n * 4);
28585
28585
  const view = new DataView(bytes.buffer);
28586
28586
  for (let i2 = 0; i2 <= n; i2++) {
28587
- view.setInt32(i2 * 4, table.fcs[i2], true);
28587
+ view.setInt32(i2 * 4, table2.fcs[i2], true);
28588
28588
  }
28589
28589
  for (let i2 = 0; i2 < n; i2++) {
28590
- view.setUint32((n + 1) * 4 + i2 * 4, table.pns[i2], true);
28590
+ view.setUint32((n + 1) * 4 + i2 * 4, table2.pns[i2], true);
28591
28591
  }
28592
28592
  return bytes;
28593
28593
  }
28594
- function findBteRangeIndex(table, fc) {
28595
- for (let i2 = 0; i2 < table.pns.length; i2++) {
28596
- if (fc >= table.fcs[i2] && fc < table.fcs[i2 + 1]) {
28594
+ function findBteRangeIndex(table2, fc) {
28595
+ for (let i2 = 0; i2 < table2.pns.length; i2++) {
28596
+ if (fc >= table2.fcs[i2] && fc < table2.fcs[i2 + 1]) {
28597
28597
  return i2;
28598
28598
  }
28599
28599
  }
@@ -29264,15 +29264,15 @@ var PNG_SIGNATURE;
29264
29264
  var init_png_encoder = __esm({
29265
29265
  "src/core/utils/png-encoder.ts"() {
29266
29266
  CRC_TABLE = (() => {
29267
- const table = new Uint32Array(256);
29267
+ const table2 = new Uint32Array(256);
29268
29268
  for (let n = 0; n < 256; n++) {
29269
29269
  let c = n;
29270
29270
  for (let k = 0; k < 8; k++) {
29271
29271
  c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
29272
29272
  }
29273
- table[n] = c >>> 0;
29273
+ table2[n] = c >>> 0;
29274
29274
  }
29275
- return table;
29275
+ return table2;
29276
29276
  })();
29277
29277
  PNG_SIGNATURE = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
29278
29278
  }
@@ -32943,6 +32943,63 @@ var init_smartart_layout_interpreter_axis_count = __esm({
32943
32943
  init_smartart_layout_interpreter_axis_hop();
32944
32944
  }
32945
32945
  });
32946
+ function depthFromAnchor(node, anchorId, byId) {
32947
+ let depth = 0;
32948
+ let current = node;
32949
+ const seen = /* @__PURE__ */ new Set();
32950
+ while (current) {
32951
+ if (current.id === anchorId) {
32952
+ return depth;
32953
+ }
32954
+ if (seen.has(current.id)) {
32955
+ return void 0;
32956
+ }
32957
+ seen.add(current.id);
32958
+ current = current.parentId ? byId.get(current.parentId) : void 0;
32959
+ depth += 1;
32960
+ }
32961
+ return void 0;
32962
+ }
32963
+ function resolveAxisMaxDepth(nodes, axis, pointTypes, start, count, anchor) {
32964
+ if (anchor.length === 0) {
32965
+ return void 0;
32966
+ }
32967
+ const byId = new Map(nodes.map((n) => [n.id, n]));
32968
+ let max = 0;
32969
+ for (const anchorPoint of anchor) {
32970
+ const resolved = resolveAxisNodes(nodes, axis, pointTypes, start, count, [anchorPoint]);
32971
+ if (resolved === void 0) {
32972
+ return void 0;
32973
+ }
32974
+ for (const point of resolved) {
32975
+ const depth = depthFromAnchor(point, anchorPoint.id, byId);
32976
+ if (depth !== void 0 && depth > max) {
32977
+ max = depth;
32978
+ }
32979
+ }
32980
+ }
32981
+ return max;
32982
+ }
32983
+ var init_smartart_layout_interpreter_axis_depth = __esm({
32984
+ "src/core/utils/smartart-layout-interpreter-axis-depth.ts"() {
32985
+ init_smartart_layout_interpreter_axis_count();
32986
+ }
32987
+ });
32988
+ function resolvePresentationOf(node, flat) {
32989
+ const candidates = node.presentationOfCandidates;
32990
+ if (!candidates || candidates.length === 0) {
32991
+ return node.presentationOf;
32992
+ }
32993
+ const winner = candidates.find(
32994
+ (candidate) => candidate.guard.every((guard) => evaluateWhen(guard, flat.length, { nodes: flat }) !== false)
32995
+ );
32996
+ return winner?.presentationOf ?? node.presentationOf;
32997
+ }
32998
+ var init_smartart_layout_interpreter_presof_choose = __esm({
32999
+ "src/core/utils/smartart-layout-interpreter-presof-choose.ts"() {
33000
+ init_smartart_layout_interpreter_when();
33001
+ }
33002
+ });
32946
33003
  function toNumber(value) {
32947
33004
  const parsed = Number(value);
32948
33005
  return Number.isFinite(parsed) ? parsed : void 0;
@@ -33045,11 +33102,24 @@ function evaluateWhen(when, nodeCount, context) {
33045
33102
  return threshold === void 0 ? void 0 : compareNumeric(context.depth, when.operator, threshold);
33046
33103
  }
33047
33104
  case "maxDepth": {
33048
- if (context.maxDepth === void 0) {
33105
+ const threshold = toNumber(when.value);
33106
+ if (threshold === void 0) {
33049
33107
  return void 0;
33050
33108
  }
33051
- const threshold = toNumber(when.value);
33052
- return threshold === void 0 ? void 0 : compareNumeric(context.maxDepth, when.operator, threshold);
33109
+ if (when.axis !== void 0 && context.anchor && context.nodes) {
33110
+ const axisDepth = resolveAxisMaxDepth(
33111
+ context.nodes,
33112
+ when.axis,
33113
+ when.pointTypes,
33114
+ when.start,
33115
+ when.count,
33116
+ context.anchor
33117
+ );
33118
+ if (axisDepth !== void 0) {
33119
+ return compareNumeric(axisDepth, when.operator, threshold);
33120
+ }
33121
+ }
33122
+ return context.maxDepth === void 0 ? void 0 : compareNumeric(context.maxDepth, when.operator, threshold);
33053
33123
  }
33054
33124
  case "var":
33055
33125
  return context.presLayoutVars ? evaluateVar(when, context.presLayoutVars) : void 0;
@@ -33057,21 +33127,13 @@ function evaluateWhen(when, nodeCount, context) {
33057
33127
  return void 0;
33058
33128
  }
33059
33129
  }
33060
- function resolvePresentationOf(node, flat) {
33061
- const candidates = node.presentationOfCandidates;
33062
- if (!candidates || candidates.length === 0) {
33063
- return node.presentationOf;
33064
- }
33065
- const winner = candidates.find(
33066
- (candidate) => candidate.guard.every((guard) => evaluateWhen(guard, flat.length, { nodes: flat }) !== false)
33067
- );
33068
- return winner?.presentationOf ?? node.presentationOf;
33069
- }
33070
33130
  var VAR_LOOKUP;
33071
33131
  var VAR_DEFAULT;
33072
33132
  var init_smartart_layout_interpreter_when = __esm({
33073
33133
  "src/core/utils/smartart-layout-interpreter-when.ts"() {
33074
33134
  init_smartart_layout_interpreter_axis_count();
33135
+ init_smartart_layout_interpreter_axis_depth();
33136
+ init_smartart_layout_interpreter_presof_choose();
33075
33137
  VAR_LOOKUP = {
33076
33138
  dir: (v) => v.direction,
33077
33139
  hierBranch: (v) => v.hierarchyBranch,
@@ -33161,6 +33223,23 @@ function hasStructuralDescendant(node) {
33161
33223
  (child262) => STRUCTURAL_ALG_TYPES.has(child262.algorithm?.type ?? "") && !isContinuationForEach(child262) || hasStructuralDescendant(child262)
33162
33224
  );
33163
33225
  }
33226
+ function hasRepeatedTemplateStructuralDescendant(node) {
33227
+ return (node.children ?? []).some((child262) => {
33228
+ if (STRUCTURAL_ALG_TYPES.has(child262.algorithm?.type ?? "") && !isContinuationForEach(child262) && child262.forEachOrigin?.axis?.includes("ch") && child262.forEachOrigin?.pointTypes?.includes("node")) {
33229
+ return true;
33230
+ }
33231
+ return hasRepeatedTemplateStructuralDescendant(child262);
33232
+ });
33233
+ }
33234
+ function distinctMappedSlotCount(node) {
33235
+ const names = /* @__PURE__ */ new Set();
33236
+ for (const constraint of node.allConstraints ?? node.constraints ?? []) {
33237
+ if (constraint.for === "ch" && constraint.forName) {
33238
+ names.add(constraint.forName);
33239
+ }
33240
+ }
33241
+ return names.size;
33242
+ }
33164
33243
  function mapsSlots(node) {
33165
33244
  const declaredByArranger = (node.allConstraints ?? node.constraints ?? []).some(
33166
33245
  (constraint) => constraint.for === "ch" && SLOT_CONSTRAINTS.has(constraint.type)
@@ -33195,7 +33274,14 @@ var STRUCTURAL_ALG_TYPES;
33195
33274
  var init_smartart_layout_interpreter_composite_detect = __esm({
33196
33275
  "src/core/utils/smartart-layout-interpreter-composite-detect.ts"() {
33197
33276
  SLOT_CONSTRAINTS = /* @__PURE__ */ new Set(["l", "t", "w", "h", "ctrX", "ctrY"]);
33198
- STRUCTURAL_ALG_TYPES = /* @__PURE__ */ new Set(["lin", "cycle", "pyra", "snake", "hierRoot", "hierChild"]);
33277
+ STRUCTURAL_ALG_TYPES = /* @__PURE__ */ new Set([
33278
+ "lin",
33279
+ "cycle",
33280
+ "pyra",
33281
+ "snake",
33282
+ "hierRoot",
33283
+ "hierChild"
33284
+ ]);
33199
33285
  }
33200
33286
  });
33201
33287
  function findStructuralAlgDepth(raw, crossedNames, nodeCount, context) {
@@ -33728,8 +33814,13 @@ function discoverArrangement(definition, nodeCount, presLayoutVars, flatNodes) {
33728
33814
  return;
33729
33815
  }
33730
33816
  if (kind === "composite") {
33731
- if (!compositeSlot && !itemTemplates.has(node) && !hasStructuralDescendant(node) && mapsSlots(node)) {
33817
+ const multiSlot = distinctMappedSlotCount(node) >= 2;
33818
+ const repeatedTemplateDescendant = hasRepeatedTemplateStructuralDescendant(node);
33819
+ if (!compositeSlot && !itemTemplates.has(node) && (!hasStructuralDescendant(node) || multiSlot && repeatedTemplateDescendant) && mapsSlots(node)) {
33732
33820
  compositeSlot = node;
33821
+ if (multiSlot && repeatedTemplateDescendant) {
33822
+ blockedSubtreeRoots.push(node);
33823
+ }
33733
33824
  }
33734
33825
  return;
33735
33826
  }
@@ -35222,21 +35313,21 @@ var init_smartart_layout_item_font_role = __esm({
35222
35313
  DECORATIVE_FONT_ALGORITHM_TYPES = /* @__PURE__ */ new Set(["sp", "composite", "conn"]);
35223
35314
  }
35224
35315
  });
35225
- function measureTextWidth(text22, fontSize, table) {
35316
+ function measureTextWidth(text22, fontSize, table2) {
35226
35317
  let widthPx = 0;
35227
35318
  for (const ch of text22) {
35228
35319
  const code = ch.codePointAt(0) ?? 0;
35229
- const unitsPerEm = table.advances[code] ?? table.averageAdvance;
35320
+ const unitsPerEm = table2.advances[code] ?? table2.averageAdvance;
35230
35321
  const rawPx = unitsPerEm / 1e3 * fontSize;
35231
35322
  widthPx += Math.round(rawPx * ADVANCE_STEPS_PER_PX) / ADVANCE_STEPS_PER_PX;
35232
35323
  }
35233
35324
  return widthPx;
35234
35325
  }
35235
- function greedyWrap(text22, maxWidth, fontSize, table) {
35326
+ function greedyWrap(text22, maxWidth, fontSize, table2) {
35236
35327
  if (maxWidth <= 0) {
35237
35328
  return { lines: Number.POSITIVE_INFINITY, widestLineWidth: 0 };
35238
35329
  }
35239
- const spaceWidth = measureTextWidth(" ", fontSize, table);
35330
+ const spaceWidth = measureTextWidth(" ", fontSize, table2);
35240
35331
  let lines = 0;
35241
35332
  let widestLineWidth = 0;
35242
35333
  for (const paragraph of text22.split("\n")) {
@@ -35248,7 +35339,7 @@ function greedyWrap(text22, maxWidth, fontSize, table) {
35248
35339
  let lineWidth = 0;
35249
35340
  let paragraphLines = 1;
35250
35341
  for (const word of words) {
35251
- const wordWidth = measureTextWidth(word, fontSize, table);
35342
+ const wordWidth = measureTextWidth(word, fontSize, table2);
35252
35343
  const extended = lineWidth === 0 ? wordWidth : lineWidth + spaceWidth + wordWidth;
35253
35344
  if (extended > maxWidth && lineWidth > 0) {
35254
35345
  widestLineWidth = Math.max(widestLineWidth, lineWidth);
@@ -35263,30 +35354,30 @@ function greedyWrap(text22, maxWidth, fontSize, table) {
35263
35354
  }
35264
35355
  return { lines: Math.max(1, lines), widestLineWidth };
35265
35356
  }
35266
- function wrappedLineCount(text22, maxWidth, fontSize, table) {
35267
- return greedyWrap(text22, maxWidth, fontSize, table).lines;
35357
+ function wrappedLineCount(text22, maxWidth, fontSize, table2) {
35358
+ return greedyWrap(text22, maxWidth, fontSize, table2).lines;
35268
35359
  }
35269
- function wrappedWidestLineWidth(text22, maxWidth, fontSize, table) {
35270
- return greedyWrap(text22, maxWidth, fontSize, table).widestLineWidth;
35360
+ function wrappedWidestLineWidth(text22, maxWidth, fontSize, table2) {
35361
+ return greedyWrap(text22, maxWidth, fontSize, table2).widestLineWidth;
35271
35362
  }
35272
- function fitsAt(text22, maxWidth, maxHeight, size, table, lineSpacingFactor) {
35273
- return wrappedLineCount(text22, maxWidth, size, table) * size * table.lineHeightRatio * lineSpacingFactor <= maxHeight;
35363
+ function fitsAt(text22, maxWidth, maxHeight, size, table2, lineSpacingFactor) {
35364
+ return wrappedLineCount(text22, maxWidth, size, table2) * size * table2.lineHeightRatio * lineSpacingFactor <= maxHeight;
35274
35365
  }
35275
- function fitWrappedFontSize(text22, maxWidth, maxHeight, ceiling, floor, table = DEFAULT_FONT_ADVANCE_TABLE, lineSpacingFactor = SMARTART_LINE_SPACING_FACTOR) {
35366
+ function fitWrappedFontSize(text22, maxWidth, maxHeight, ceiling, floor, table2 = DEFAULT_FONT_ADVANCE_TABLE, lineSpacingFactor = SMARTART_LINE_SPACING_FACTOR) {
35276
35367
  if (text22.trim().length === 0 || maxWidth <= 0 || maxHeight <= 0) {
35277
35368
  return ceiling;
35278
35369
  }
35279
- if (fitsAt(text22, maxWidth, maxHeight, ceiling, table, lineSpacingFactor)) {
35370
+ if (fitsAt(text22, maxWidth, maxHeight, ceiling, table2, lineSpacingFactor)) {
35280
35371
  return ceiling;
35281
35372
  }
35282
- if (!fitsAt(text22, maxWidth, maxHeight, floor, table, lineSpacingFactor)) {
35373
+ if (!fitsAt(text22, maxWidth, maxHeight, floor, table2, lineSpacingFactor)) {
35283
35374
  return floor;
35284
35375
  }
35285
35376
  let lo = floor;
35286
35377
  let hi = ceiling;
35287
35378
  for (let i2 = 0; i2 < BINARY_SEARCH_ITERATIONS; i2++) {
35288
35379
  const mid = (lo + hi) / 2;
35289
- if (fitsAt(text22, maxWidth, maxHeight, mid, table, lineSpacingFactor)) {
35380
+ if (fitsAt(text22, maxWidth, maxHeight, mid, table2, lineSpacingFactor)) {
35290
35381
  lo = mid;
35291
35382
  } else {
35292
35383
  hi = mid;
@@ -35308,15 +35399,15 @@ var init_smartart_text_wrap_fit = __esm({
35308
35399
  function resolveFontTable(fontName) {
35309
35400
  return FONT_ADVANCE_TABLES[fontName ?? "Calibri"] ?? DEFAULT_FONT_ADVANCE_TABLE;
35310
35401
  }
35311
- function itemMarginsPx(index, role, table) {
35402
+ function itemMarginsPx(index, role, table2) {
35312
35403
  const left = resolveConstraint(index, role, "lMarg");
35313
35404
  const right = resolveConstraint(index, role, "rMarg");
35314
35405
  const top = resolveConstraint(index, role, "tMarg");
35315
35406
  const bottom = resolveConstraint(index, role, "bMarg");
35316
- const leftPt = typeof left === "number" ? left : table.marginLeftPt;
35317
- const rightPt = typeof right === "number" ? right : table.marginRightPt;
35318
- const topPt = typeof top === "number" ? top : table.marginTopPt;
35319
- const bottomPt = typeof bottom === "number" ? bottom : table.marginBottomPt;
35407
+ const leftPt = typeof left === "number" ? left : table2.marginLeftPt;
35408
+ const rightPt = typeof right === "number" ? right : table2.marginRightPt;
35409
+ const topPt = typeof top === "number" ? top : table2.marginTopPt;
35410
+ const bottomPt = typeof bottom === "number" ? bottom : table2.marginBottomPt;
35320
35411
  return {
35321
35412
  horizontal: (leftPt + rightPt) * POINTS_TO_PIXELS3,
35322
35413
  vertical: (topPt + bottomPt) * POINTS_TO_PIXELS3
@@ -35360,8 +35451,8 @@ function fitSharedFontSize(bounds, index, items, fontName, naturalAspect) {
35360
35451
  if (items.length === 0) {
35361
35452
  return snapToWholePoint(ceilingPx);
35362
35453
  }
35363
- const table = resolveFontTable(fontName);
35364
- const fixedMargins = itemMarginsPx(index, role, table);
35454
+ const table2 = resolveFontTable(fontName);
35455
+ const fixedMargins = itemMarginsPx(index, role, table2);
35365
35456
  const proportional = proportionalMarginFraction(index, role);
35366
35457
  const lineSpacingFactor = SMARTART_LINE_SPACING_FACTOR;
35367
35458
  const fitAtMarginBasis = (marginBasisPx) => {
@@ -35380,7 +35471,7 @@ function fitSharedFontSize(bounds, index, items, fontName, naturalAspect) {
35380
35471
  availableHeight,
35381
35472
  ceilingPx,
35382
35473
  floorPx,
35383
- table,
35474
+ table2,
35384
35475
  lineSpacingFactor
35385
35476
  );
35386
35477
  shared2 = Math.min(shared2, fit);
@@ -35417,15 +35508,15 @@ function isMainAxisContentSized(index, arrangerRole, itemRole, mainAxisType) {
35417
35508
  const raw = firstConstraintDeclaredBy(index, itemRole, mainAxisType, arrangerRole);
35418
35509
  return raw !== void 0 && raw.value === Number.POSITIVE_INFINITY && !hasReference(raw);
35419
35510
  }
35420
- function resolveContentSizedExtents(texts, crossExtentPx, fontSizePx2, table, lineSpacingFactor, fontRole, index, cornerInsetPx, usableMain, gap) {
35511
+ function resolveContentSizedExtents(texts, crossExtentPx, fontSizePx2, table2, lineSpacingFactor, fontRole, index, cornerInsetPx, usableMain, gap) {
35421
35512
  const margins = proportionalMarginFraction(index, fontRole);
35422
- const marginVerticalPx = margins ? margins.vertical * fontSizePx2 : itemMarginsPx(index, fontRole, table).vertical;
35513
+ const marginVerticalPx = margins ? margins.vertical * fontSizePx2 : itemMarginsPx(index, fontRole, table2).vertical;
35423
35514
  const availWidthPx = Math.max(1, crossExtentPx - 2 * cornerInsetPx);
35424
35515
  const natural = texts.map((text22) => {
35425
- const lines = Math.max(1, wrappedLineCount(text22, availWidthPx, fontSizePx2, table));
35516
+ const lines = Math.max(1, wrappedLineCount(text22, availWidthPx, fontSizePx2, table2));
35426
35517
  return Math.max(
35427
35518
  12,
35428
- lines * fontSizePx2 * table.lineHeightRatio * lineSpacingFactor + marginVerticalPx + 2 * cornerInsetPx
35519
+ lines * fontSizePx2 * table2.lineHeightRatio * lineSpacingFactor + marginVerticalPx + 2 * cornerInsetPx
35429
35520
  );
35430
35521
  });
35431
35522
  const n = natural.length;
@@ -36174,16 +36265,16 @@ function paragraphBlockPx(lines, sizePx2, ratio, lineSpacingFactor, spcAftFactor
36174
36265
  const content = lines * sizePx2 * ratio * lineSpacingFactor;
36175
36266
  return isLastParagraph ? content : content + spcAftFactor * sizePx2 * ratio;
36176
36267
  }
36177
- function itemFits(item, availWidthPx, availHeightPx, rootPx, descendantPx, table, lineSpacingFactor) {
36268
+ function itemFits(item, availWidthPx, availHeightPx, rootPx, descendantPx, table2, lineSpacingFactor) {
36178
36269
  const hasDescendants = item.descendantTexts.length > 0;
36179
- if (wrappedWidestLineWidth(item.rootText, availWidthPx, rootPx, table) > availWidthPx) {
36270
+ if (wrappedWidestLineWidth(item.rootText, availWidthPx, rootPx, table2) > availWidthPx) {
36180
36271
  return false;
36181
36272
  }
36182
- const rootLines = wrappedLineCount(item.rootText, availWidthPx, rootPx, table);
36273
+ const rootLines = wrappedLineCount(item.rootText, availWidthPx, rootPx, table2);
36183
36274
  let totalPx = paragraphBlockPx(
36184
36275
  rootLines,
36185
36276
  rootPx,
36186
- table.lineHeightRatio,
36277
+ table2.lineHeightRatio,
36187
36278
  lineSpacingFactor,
36188
36279
  ROOT_SPCAFT_FACTOR,
36189
36280
  !hasDescendants || item.separateDescendantBox === true
@@ -36193,14 +36284,14 @@ function itemFits(item, availWidthPx, availHeightPx, rootPx, descendantPx, table
36193
36284
  for (let i2 = 0; i2 < item.descendantTexts.length; i2++) {
36194
36285
  const isLast = i2 === item.descendantTexts.length - 1;
36195
36286
  const text22 = item.descendantTexts[i2];
36196
- if (wrappedWidestLineWidth(text22, descendantWidthPx, descendantPx, table) > descendantWidthPx) {
36287
+ if (wrappedWidestLineWidth(text22, descendantWidthPx, descendantPx, table2) > descendantWidthPx) {
36197
36288
  return false;
36198
36289
  }
36199
- const lines = wrappedLineCount(text22, descendantWidthPx, descendantPx, table);
36290
+ const lines = wrappedLineCount(text22, descendantWidthPx, descendantPx, table2);
36200
36291
  totalPx += paragraphBlockPx(
36201
36292
  lines,
36202
36293
  descendantPx,
36203
- table.lineHeightRatio,
36294
+ table2.lineHeightRatio,
36204
36295
  lineSpacingFactor,
36205
36296
  DESCENDANT_SPCAFT_FACTOR,
36206
36297
  isLast
@@ -36232,8 +36323,8 @@ function resolveTieredItemFontSize(plan, index, items, fontName, naturalAspect,
36232
36323
  if (items.length === 0) {
36233
36324
  return { rootSizePx: ceilingPx, descendantSizePx: ceilingPx * SMARTART_DESCENDANT_FONT_SCALE };
36234
36325
  }
36235
- const table = resolveFontTable(fontName);
36236
- const fixedMargins = itemMarginsPx(index, role, table);
36326
+ const table2 = resolveFontTable(fontName);
36327
+ const fixedMargins = itemMarginsPx(index, role, table2);
36237
36328
  const proportional = proportionalMarginFraction(index, role);
36238
36329
  const lineSpacingFactor = SMARTART_LINE_SPACING_FACTOR;
36239
36330
  const fitsAtMarginBasis = (rootPx2, marginBasisPx) => {
@@ -36253,7 +36344,7 @@ function resolveTieredItemFontSize(plan, index, items, fontName, naturalAspect,
36253
36344
  availHeightPx,
36254
36345
  rootPx2,
36255
36346
  descendantPx,
36256
- table,
36347
+ table2,
36257
36348
  lineSpacingFactor
36258
36349
  );
36259
36350
  if (!fits) {
@@ -36311,6 +36402,152 @@ var init_smartart_layout_item_font_tier = __esm({
36311
36402
  PX_PER_PT2 = 96 / 72;
36312
36403
  }
36313
36404
  });
36405
+ function algTypeOf(node, nodeCount, presLayoutVars) {
36406
+ return node.algorithm?.type ?? chooseAlgType(node, nodeCount, { presLayoutVars: presLayoutVars ?? {} });
36407
+ }
36408
+ function findRowChild(node, presLayoutVars) {
36409
+ return (node.children ?? []).find((child262) => {
36410
+ if (child262.algorithm?.type === "sp") {
36411
+ return false;
36412
+ }
36413
+ if (algTypeOf(child262, 2, presLayoutVars) !== "lin") {
36414
+ return false;
36415
+ }
36416
+ return (child262.children ?? []).some(
36417
+ (grandchild) => grandchild.forEachOrigin?.axis?.includes("ch") && grandchild.forEachOrigin?.pointTypes?.includes("node")
36418
+ );
36419
+ });
36420
+ }
36421
+ function isRecursiveTableItemTemplate(node, presLayoutVars) {
36422
+ if (!node.forEachOrigin?.axis?.includes("ch") || !node.forEachOrigin?.pointTypes?.includes("node")) {
36423
+ return false;
36424
+ }
36425
+ if (algTypeOf(node, 2, presLayoutVars) !== "lin") {
36426
+ return false;
36427
+ }
36428
+ const hasLabel = (node.children ?? []).some(
36429
+ (child262) => child262.algorithm?.type === "tx" && child262.presentationOf?.axis?.includes("self")
36430
+ );
36431
+ return hasLabel && findRowChild(node, presLayoutVars) !== void 0;
36432
+ }
36433
+ function resolvedLinDir(node, nodeCount, presLayoutVars, fallback) {
36434
+ const alg = node.algorithm ?? chooseAlgorithm(node, nodeCount, { presLayoutVars: presLayoutVars ?? {} });
36435
+ return alg?.parameters?.find((p) => p.type === "linDir")?.value ?? fallback;
36436
+ }
36437
+ function arrangeRecursiveTable(plan, nodes, box, palette, style, elementId, index, childrenOf, fontName, presLayoutVars) {
36438
+ const ctx = styleContext(style);
36439
+ const { width: w, height: h2 } = box;
36440
+ const reversed = resolvedLinDir(plan.node, nodes.length, presLayoutVars, "fromT") === "fromB";
36441
+ const rowChild = findRowChild(plan.node, presLayoutVars);
36442
+ const colReversed = rowChild ? resolvedLinDir(rowChild, nodes.length, presLayoutVars, "fromL") === "fromR" : false;
36443
+ const byId = new Map(nodes.map((n) => [n.id, n]));
36444
+ const childrenIn = (n) => (childrenOf.get(n.id) ?? []).filter((c) => byId.has(c.id));
36445
+ const childIds = /* @__PURE__ */ new Set();
36446
+ for (const n of nodes) {
36447
+ for (const c of childrenIn(n)) {
36448
+ childIds.add(c.id);
36449
+ }
36450
+ }
36451
+ const roots = nodes.filter((n) => !childIds.has(n.id));
36452
+ const depthOf = /* @__PURE__ */ new Map();
36453
+ let maxDepth = 0;
36454
+ const depthStack = roots.map((r) => ({
36455
+ node: r,
36456
+ depth: 0
36457
+ }));
36458
+ while (depthStack.length > 0) {
36459
+ const { node, depth } = depthStack.pop();
36460
+ depthOf.set(node.id, depth);
36461
+ maxDepth = Math.max(maxDepth, depth);
36462
+ for (const c of childrenIn(node)) {
36463
+ depthStack.push({ node: c, depth: depth + 1 });
36464
+ }
36465
+ }
36466
+ const generations = maxDepth + 1;
36467
+ const rowDenom = generations + Math.max(0, generations - 1) * DEFAULT_GAP_RATIO;
36468
+ const rowHeight = h2 / rowDenom;
36469
+ const rowGap = DEFAULT_GAP_RATIO * rowHeight;
36470
+ const rowY = (depth) => (reversed ? generations - 1 - depth : depth) * (rowHeight + rowGap);
36471
+ const splitAcross = (items, x, width) => {
36472
+ const n = items.length;
36473
+ if (n === 0) {
36474
+ return [];
36475
+ }
36476
+ const denom = n + Math.max(0, n - 1) * DEFAULT_GAP_RATIO;
36477
+ const colWidth = width / denom;
36478
+ const colGap = DEFAULT_GAP_RATIO * colWidth;
36479
+ const ordered4 = colReversed ? [...items].reverse() : items;
36480
+ const out = [];
36481
+ let cursor = x;
36482
+ for (const item of ordered4) {
36483
+ out.push([item, cursor, colWidth]);
36484
+ cursor += colWidth + colGap;
36485
+ }
36486
+ return out;
36487
+ };
36488
+ const placed = [];
36489
+ const place = (node, x, width) => {
36490
+ placed.push({ node, x, width });
36491
+ const kids = childrenIn(node);
36492
+ for (const [child262, childX, childWidth] of splitAcross(kids, x, width)) {
36493
+ place(child262, childX, childWidth);
36494
+ }
36495
+ };
36496
+ for (const [root, rootX, rootWidth] of splitAcross(roots, 0, w)) {
36497
+ place(root, rootX, rootWidth);
36498
+ }
36499
+ const itemShape = findCompositeItemShape(plan.node);
36500
+ const { rootSizePx: fontSizeOverride, descendantSizePx } = resolveTieredItemFontSize(
36501
+ plan,
36502
+ index,
36503
+ placed.map(({ node, width }) => ({
36504
+ rootText: node.text,
36505
+ descendantTexts: [],
36506
+ width,
36507
+ height: rowHeight,
36508
+ separateDescendantBox: false
36509
+ })),
36510
+ fontName,
36511
+ void 0
36512
+ );
36513
+ const renderedNodes = placed.map(
36514
+ ({ node, x, width }, i2) => presetBoxNode({
36515
+ key: `${elementId}-lintbl-${node.id}-${i2}`,
36516
+ x,
36517
+ y: rowY(depthOf.get(node.id) ?? 0),
36518
+ width,
36519
+ height: rowHeight,
36520
+ node,
36521
+ index: i2,
36522
+ total: placed.length,
36523
+ palette,
36524
+ style,
36525
+ ctx,
36526
+ shape: itemShape,
36527
+ fallbackKind: "rect",
36528
+ fontSizeOverride,
36529
+ descendantFontSize: descendantSizePx
36530
+ })
36531
+ );
36532
+ return {
36533
+ nodes: renderedNodes,
36534
+ connectors: [],
36535
+ shadowFilter: ctx.shadow,
36536
+ viewBox: `0 0 ${w} ${h2}`,
36537
+ family: "list"
36538
+ };
36539
+ }
36540
+ var DEFAULT_GAP_RATIO;
36541
+ var init_smartart_layout_interpreter_linear_table = __esm({
36542
+ "src/core/utils/smartart-layout-interpreter-linear-table.ts"() {
36543
+ init_smartart_layout_interpreter_choose_algorithm();
36544
+ init_smartart_layout_interpreter_preset_node();
36545
+ init_smartart_layout_interpreter_render();
36546
+ init_smartart_layout_item_font_tier();
36547
+ init_smartart_layout_shape_preset();
36548
+ DEFAULT_GAP_RATIO = 0.25;
36549
+ }
36550
+ });
36314
36551
  function snakeGridDims(plan, n, w, h2, flowDir) {
36315
36552
  const bkpt = algorithmParam(plan.node, "bkpt");
36316
36553
  const fixedVal = findConstraint(plan.node.constraints, "bkPtFixedVal")?.value;
@@ -36467,6 +36704,20 @@ var init_smartart_layout_interpreter_snake = __esm({
36467
36704
  }
36468
36705
  });
36469
36706
  function arrangeLinear(plan, flow, nodes, box, palette, style, elementId, index = EMPTY_CONSTRAINT_INDEX, childrenOf, fontName, presLayoutVars) {
36707
+ if (childrenOf && isRecursiveTableItemTemplate(plan.node, presLayoutVars)) {
36708
+ return arrangeRecursiveTable(
36709
+ plan,
36710
+ nodes,
36711
+ box,
36712
+ palette,
36713
+ style,
36714
+ elementId,
36715
+ index,
36716
+ childrenOf,
36717
+ fontName,
36718
+ presLayoutVars
36719
+ );
36720
+ }
36470
36721
  const { width: w, height: h2 } = box;
36471
36722
  const ctx = styleContext(style);
36472
36723
  const constraints = plan.node.constraints;
@@ -36577,6 +36828,7 @@ var init_smartart_layout_interpreter_linear = __esm({
36577
36828
  init_smartart_layout_interpreter_linear_item_aspect();
36578
36829
  init_smartart_layout_interpreter_linear_main_axis();
36579
36830
  init_smartart_layout_interpreter_linear_shared();
36831
+ init_smartart_layout_interpreter_linear_table();
36580
36832
  init_smartart_layout_interpreter_model();
36581
36833
  init_smartart_layout_interpreter_preset_node();
36582
36834
  init_smartart_layout_interpreter_render();
@@ -36697,20 +36949,23 @@ function isCrossRoleReference(constraint) {
36697
36949
  return (constraint.referenceFor === "ch" || constraint.referenceFor === "des") && Boolean(constraint.referenceForName);
36698
36950
  }
36699
36951
  function dimDeclaredBy(role, type, declaringRole, box, index) {
36700
- const declared = firstConstraintDeclaredBy(index, role, type, declaringRole);
36701
- if (!declared) {
36702
- return void 0;
36703
- }
36704
- const resolved = resolveConstraintDeclaredBy(index, role, type, declaringRole);
36705
- if (typeof resolved !== "number" || !Number.isFinite(resolved)) {
36706
- return void 0;
36707
- }
36708
- const extent = axisExtent(declared.referenceType, box, defaultExtent(type, box));
36709
- if (resolved >= 0 && resolved <= 1) {
36710
- return { px: resolved * extent };
36711
- }
36712
- if (resolved > 1) {
36713
- return { abs: resolved };
36952
+ const chain = typeof declaringRole === "string" ? [declaringRole] : declaringRole;
36953
+ for (const candidateRole of chain) {
36954
+ const declared = firstConstraintDeclaredBy(index, role, type, candidateRole);
36955
+ if (!declared) {
36956
+ continue;
36957
+ }
36958
+ const resolved = resolveConstraintDeclaredBy(index, role, type, candidateRole);
36959
+ if (typeof resolved !== "number" || !Number.isFinite(resolved)) {
36960
+ continue;
36961
+ }
36962
+ const extent = axisExtent(declared.referenceType, box, defaultExtent(type, box));
36963
+ if (resolved >= 0 && resolved <= 1) {
36964
+ return { px: resolved * extent };
36965
+ }
36966
+ if (resolved > 1) {
36967
+ return { abs: resolved };
36968
+ }
36714
36969
  }
36715
36970
  return void 0;
36716
36971
  }
@@ -36742,6 +36997,13 @@ function dimOf(constraints, type, box, index, role, declaringRole) {
36742
36997
  }
36743
36998
  return void 0;
36744
36999
  }
37000
+ var init_smartart_layout_interpreter_composite_slot_dim = __esm({
37001
+ "src/core/utils/smartart-layout-interpreter-composite-slot-dim.ts"() {
37002
+ init_smartart_constraint_declared_by();
37003
+ init_smartart_constraint_solver();
37004
+ init_smartart_layout_interpreter_model();
37005
+ }
37006
+ });
36745
37007
  function isPositioned(dims) {
36746
37008
  return dims.l !== void 0 || dims.t !== void 0 || dims.w !== void 0 || dims.h !== void 0 || dims.ctrX !== void 0 || dims.ctrY !== void 0;
36747
37009
  }
@@ -36830,9 +37092,8 @@ function resolveSlot(dims, box, absX, absY) {
36830
37092
  }
36831
37093
  var init_smartart_layout_interpreter_composite_slots = __esm({
36832
37094
  "src/core/utils/smartart-layout-interpreter-composite-slots.ts"() {
36833
- init_smartart_constraint_declared_by();
36834
37095
  init_smartart_constraint_solver();
36835
- init_smartart_layout_interpreter_model();
37096
+ init_smartart_layout_interpreter_composite_slot_dim();
36836
37097
  }
36837
37098
  });
36838
37099
  function childAxisSpec(template, childCount) {
@@ -36953,6 +37214,23 @@ function resolveAnchoredContentPerAnchor(node, flat) {
36953
37214
  }
36954
37215
  return groups;
36955
37216
  }
37217
+ function resolveAnchoredContentPerAnchorFrom(node, flat, origin) {
37218
+ const presOf = resolvePresentationOf(node, flat);
37219
+ if (!presOf?.axis || presOf.axis.length === 0 || !origin.axis || origin.axis.length === 0) {
37220
+ return [];
37221
+ }
37222
+ const anchors = resolveAxisNodes(flat, origin.axis, origin.pointTypes, origin.start, origin.count) ?? [];
37223
+ const anchorCount = anchors.length;
37224
+ const presOfAxis = presOf.axis;
37225
+ const groups = [];
37226
+ anchors.forEach((anchor, anchorIndex) => {
37227
+ const content = resolveAxisNodes(flat, presOfAxis, presOf.pointTypes, presOf.start, presOf.count, [anchor]) ?? [];
37228
+ if (content.length > 0) {
37229
+ groups.push({ content, anchorIndex, anchorCount });
37230
+ }
37231
+ });
37232
+ return groups;
37233
+ }
36956
37234
  var init_smartart_layout_interpreter_composite_anchor = __esm({
36957
37235
  "src/core/utils/smartart-layout-interpreter-composite-anchor.ts"() {
36958
37236
  init_smartart_layout_interpreter_axis_count();
@@ -36962,8 +37240,10 @@ var init_smartart_layout_interpreter_composite_anchor = __esm({
36962
37240
  function winningOrdinalFor(guardsByOrdinal, nodeCount, flat) {
36963
37241
  const ordinals = [...guardsByOrdinal.keys()].sort((a, b) => a - b);
36964
37242
  for (const ordinal of ordinals) {
36965
- const guard = guardsByOrdinal.get(ordinal);
36966
- const allows = !guard || evaluateWhen(guard, nodeCount, { nodes: flat }) !== false;
37243
+ const entry2 = guardsByOrdinal.get(ordinal);
37244
+ const origin = entry2?.forEachOrigin;
37245
+ const anchor = origin?.axis && origin.axis.length > 0 ? resolveAxisNodes(flat, origin.axis, origin.pointTypes, origin.start, origin.count) : void 0;
37246
+ const allows = !entry2?.guard || evaluateWhen(entry2.guard, nodeCount, { nodes: flat, anchor }) !== false;
36967
37247
  if (allows) {
36968
37248
  return ordinal;
36969
37249
  }
@@ -36983,7 +37263,7 @@ function selectFirstMatchChildren(children12, flat) {
36983
37263
  guardsByGroup.set(entry2.id, byOrdinal);
36984
37264
  }
36985
37265
  if (!byOrdinal.has(entry2.ordinal)) {
36986
- byOrdinal.set(entry2.ordinal, entry2.guard);
37266
+ byOrdinal.set(entry2.ordinal, { guard: entry2.guard, forEachOrigin: child262.forEachOrigin });
36987
37267
  }
36988
37268
  }
36989
37269
  }
@@ -37001,9 +37281,149 @@ function selectFirstMatchChildren(children12, flat) {
37001
37281
  }
37002
37282
  var init_smartart_layout_interpreter_composite_choose_groups = __esm({
37003
37283
  "src/core/utils/smartart-layout-interpreter-composite-choose-groups.ts"() {
37284
+ init_smartart_layout_interpreter_axis_count();
37004
37285
  init_smartart_layout_interpreter_when();
37005
37286
  }
37006
37287
  });
37288
+ function resolveOwnAnchor(node, flat) {
37289
+ const origin = node.forEachOrigin;
37290
+ if (!origin?.axis || origin.axis.length === 0) {
37291
+ return void 0;
37292
+ }
37293
+ return resolveAxisNodes(flat, origin.axis, origin.pointTypes, origin.start, origin.count);
37294
+ }
37295
+ function guardAllows(node, flat, iterationPosition) {
37296
+ if (!node.chooseGuard) {
37297
+ return true;
37298
+ }
37299
+ const anchor = resolveOwnAnchor(node, flat);
37300
+ return node.chooseGuard.every(
37301
+ (guard) => evaluateWhen(guard, flat.length, {
37302
+ nodes: flat,
37303
+ anchor,
37304
+ position: iterationPosition?.position,
37305
+ total: iterationPosition?.total
37306
+ }) !== false
37307
+ );
37308
+ }
37309
+ function collectRawCandidates(node, flat, declaringRole, out = [], inheritedOrigin, ancestorChain = []) {
37310
+ const hasPresOf = (node.presentationOf?.axis?.length ?? 0) > 0 || (node.presentationOfCandidates?.length ?? 0) > 0;
37311
+ if (hasPresOf) {
37312
+ const ownOrigin = (node.forEachOrigin?.axis?.length ?? 0) > 0 ? node.forEachOrigin : void 0;
37313
+ if (!ownOrigin && inheritedOrigin) {
37314
+ const declaringRoleChain = ancestorChain.length > 0 ? [declaringRole, ...ancestorChain] : void 0;
37315
+ for (const { content, anchorIndex, anchorCount } of resolveAnchoredContentPerAnchorFrom(
37316
+ node,
37317
+ flat,
37318
+ inheritedOrigin
37319
+ )) {
37320
+ const iterationPosition2 = anchorCount > 1 ? { position: anchorIndex + 1, total: anchorCount } : void 0;
37321
+ if (!guardAllows(node, flat, iterationPosition2)) {
37322
+ continue;
37323
+ }
37324
+ out.push({
37325
+ node,
37326
+ declaringRole,
37327
+ declaringRoleChain,
37328
+ content,
37329
+ iteration: anchorIndex,
37330
+ iterationCount: anchorCount
37331
+ });
37332
+ }
37333
+ return out;
37334
+ }
37335
+ const groups = resolveAnchoredContentPerAnchor(node, flat);
37336
+ const iterationPosition = (iteration) => groups.length > 1 ? { position: iteration + 1, total: groups.length } : void 0;
37337
+ groups.forEach((content, iteration) => {
37338
+ if (!guardAllows(node, flat, iterationPosition(iteration))) {
37339
+ return;
37340
+ }
37341
+ out.push({ node, declaringRole, content, iteration, iterationCount: groups.length });
37342
+ });
37343
+ return out;
37344
+ }
37345
+ if (!guardAllows(node, flat, void 0)) {
37346
+ return out;
37347
+ }
37348
+ const nextRole = roleOf(node);
37349
+ const nextAncestorChain = nextRole === declaringRole ? ancestorChain : [declaringRole, ...ancestorChain];
37350
+ const ownTemplateOrigin = node.algorithm?.type && STRUCTURAL_ALG_TYPES.has(node.algorithm.type) && node.forEachOrigin?.axis?.includes("ch") && node.forEachOrigin?.pointTypes?.includes("node") ? node.forEachOrigin : void 0;
37351
+ const effectiveOrigin = ownTemplateOrigin ?? inheritedOrigin;
37352
+ for (const child262 of selectFirstMatchChildren(node.children ?? [], flat)) {
37353
+ collectRawCandidates(child262, flat, nextRole, out, effectiveOrigin, nextAncestorChain);
37354
+ }
37355
+ return out;
37356
+ }
37357
+ var init_smartart_layout_interpreter_composite_candidates = __esm({
37358
+ "src/core/utils/smartart-layout-interpreter-composite-candidates.ts"() {
37359
+ init_smartart_constraint_solver();
37360
+ init_smartart_layout_interpreter_axis_count();
37361
+ init_smartart_layout_interpreter_composite_anchor();
37362
+ init_smartart_layout_interpreter_composite_choose_groups();
37363
+ init_smartart_layout_interpreter_composite_detect();
37364
+ init_smartart_layout_interpreter_when();
37365
+ }
37366
+ });
37367
+ function resolveSharedFontFit(fontCtx, fontRoleNode, items) {
37368
+ if (items.length === 0) {
37369
+ return void 0;
37370
+ }
37371
+ return resolveTieredItemFontSize(
37372
+ fontCtx.plan,
37373
+ fontCtx.index,
37374
+ items,
37375
+ fontCtx.fontName,
37376
+ void 0,
37377
+ 0,
37378
+ fontRoleNode
37379
+ );
37380
+ }
37381
+ function resolveFontFitFromPairs(fontCtx, fontRoleNode, pairs3) {
37382
+ if (!fontCtx) {
37383
+ return void 0;
37384
+ }
37385
+ return resolveSharedFontFit(
37386
+ fontCtx,
37387
+ fontRoleNode,
37388
+ pairs3.map((pair) => ({
37389
+ rootText: pair.node.text,
37390
+ descendantTexts: pair.desSlot?.content.map((entry2) => entry2.text) ?? [],
37391
+ width: pair.selfRect.width,
37392
+ height: pair.selfRect.height
37393
+ }))
37394
+ );
37395
+ }
37396
+ function resolveFitByDeclaringRole(fontCtx, slots) {
37397
+ const byRole = /* @__PURE__ */ new Map();
37398
+ for (const slot of slots) {
37399
+ const group2 = byRole.get(slot.declaringRole);
37400
+ if (group2) {
37401
+ group2.push(slot);
37402
+ } else {
37403
+ byRole.set(slot.declaringRole, [slot]);
37404
+ }
37405
+ }
37406
+ const fitByRole = /* @__PURE__ */ new Map();
37407
+ for (const [role, group2] of byRole) {
37408
+ const fit = resolveSharedFontFit(
37409
+ fontCtx,
37410
+ group2[0]?.node,
37411
+ group2.map(({ content, rect: rect22 }) => ({
37412
+ rootText: content[0]?.text ?? "",
37413
+ descendantTexts: content.slice(1).map((entry2) => entry2.text),
37414
+ width: rect22.width,
37415
+ height: rect22.height
37416
+ }))
37417
+ );
37418
+ fitByRole.set(role, fit);
37419
+ }
37420
+ return fitByRole;
37421
+ }
37422
+ var init_smartart_layout_interpreter_composite_fontfit = __esm({
37423
+ "src/core/utils/smartart-layout-interpreter-composite-fontfit.ts"() {
37424
+ init_smartart_layout_item_font_tier();
37425
+ }
37426
+ });
37007
37427
  function resolveIterationRect(dims, box, iteration, iterationCount) {
37008
37428
  const container = resolveSlot(dims, box, 1, 1);
37009
37429
  if (iterationCount <= 1) {
@@ -37043,7 +37463,12 @@ function resolveGroupedSlots(candidates, box, index) {
37043
37463
  return aIsSp - bIsSp;
37044
37464
  });
37045
37465
  for (const candidate of ordered4) {
37046
- const [slotted] = readSlots([candidate.node], box, index, candidate.declaringRole);
37466
+ const [slotted] = readSlots(
37467
+ [candidate.node],
37468
+ box,
37469
+ index,
37470
+ candidate.declaringRoleChain ?? candidate.declaringRole
37471
+ );
37047
37472
  if (slotted) {
37048
37473
  const rect22 = resolveIterationRect(
37049
37474
  slotted.dims,
@@ -37051,7 +37476,12 @@ function resolveGroupedSlots(candidates, box, index) {
37051
37476
  candidate.iteration,
37052
37477
  candidate.iterationCount
37053
37478
  );
37054
- out.push({ rect: rect22, content: candidate.content, node: candidate.node });
37479
+ out.push({
37480
+ rect: rect22,
37481
+ content: candidate.content,
37482
+ node: candidate.node,
37483
+ declaringRole: candidate.declaringRole
37484
+ });
37055
37485
  break;
37056
37486
  }
37057
37487
  }
@@ -37064,51 +37494,19 @@ var init_smartart_layout_interpreter_composite_group_slots = __esm({
37064
37494
  init_smartart_layout_interpreter_composite_slots();
37065
37495
  }
37066
37496
  });
37067
- function guardAllows(node, flat, iterationPosition) {
37068
- if (!node.chooseGuard) {
37069
- return true;
37070
- }
37071
- return node.chooseGuard.every(
37072
- (guard) => evaluateWhen(guard, flat.length, {
37073
- nodes: flat,
37074
- position: iterationPosition?.position,
37075
- total: iterationPosition?.total
37076
- }) !== false
37077
- );
37078
- }
37079
- function collectRawCandidates(node, flat, declaringRole, out = []) {
37080
- const hasPresOf = (node.presentationOf?.axis?.length ?? 0) > 0 || (node.presentationOfCandidates?.length ?? 0) > 0;
37081
- if (hasPresOf) {
37082
- const groups = resolveAnchoredContentPerAnchor(node, flat);
37083
- const iterationPosition = (iteration) => groups.length > 1 ? { position: iteration + 1, total: groups.length } : void 0;
37084
- groups.forEach((content, iteration) => {
37085
- if (!guardAllows(node, flat, iterationPosition(iteration))) {
37086
- return;
37087
- }
37088
- out.push({ node, declaringRole, content, iteration, iterationCount: groups.length });
37089
- });
37090
- return out;
37091
- }
37092
- if (!guardAllows(node, flat, void 0)) {
37093
- return out;
37094
- }
37095
- const nextRole = roleOf(node);
37096
- for (const child262 of selectFirstMatchChildren(node.children ?? [], flat)) {
37097
- collectRawCandidates(child262, flat, nextRole, out);
37098
- }
37099
- return out;
37100
- }
37101
37497
  function collectChooseAwareSlots(node, flat, box, index, declaringRole) {
37102
37498
  const candidates = collectRawCandidates(node, flat, declaringRole);
37103
37499
  return resolveGroupedSlots(candidates, box, index);
37104
37500
  }
37105
- function arrangeByChooseAwareSlots(root, flat, box, index, ctx) {
37501
+ function arrangeByChooseAwareSlots(root, flat, box, index, ctx, fontCtx) {
37106
37502
  const slots = collectChooseAwareSlots(root, flat, box, index, roleOf(root));
37107
37503
  if (slots.length === 0) {
37108
37504
  return void 0;
37109
37505
  }
37110
- return slots.map(({ rect: rect22, content, node: layoutNode }, i2) => {
37506
+ const fitByRole = fontCtx ? resolveFitByDeclaringRole(fontCtx, slots) : /* @__PURE__ */ new Map();
37507
+ return slots.map(({ rect: rect22, content, node: layoutNode, declaringRole }, i2) => {
37111
37508
  const first = content[0];
37509
+ const fit = fitByRole.get(declaringRole);
37112
37510
  const rendered = {
37113
37511
  ...presetBoxNode({
37114
37512
  key: `${ctx.elementId}-comp-choose-${first.id}-${i2}`,
@@ -37121,6 +37519,8 @@ function arrangeByChooseAwareSlots(root, flat, box, index, ctx) {
37121
37519
  total: slots.length,
37122
37520
  palette: ctx.palette,
37123
37521
  style: ctx.style,
37522
+ fontSizeOverride: fit?.rootSizePx,
37523
+ descendantFontSize: fit?.descendantSizePx,
37124
37524
  ctx: ctx.ctx,
37125
37525
  shape: findCompositeItemShape(layoutNode),
37126
37526
  fallbackKind: "rect"
@@ -37133,48 +37533,13 @@ function arrangeByChooseAwareSlots(root, flat, box, index, ctx) {
37133
37533
  var init_smartart_layout_interpreter_composite_choose = __esm({
37134
37534
  "src/core/utils/smartart-layout-interpreter-composite-choose.ts"() {
37135
37535
  init_smartart_constraint_solver();
37136
- init_smartart_layout_interpreter_composite_anchor();
37137
- init_smartart_layout_interpreter_composite_choose_groups();
37536
+ init_smartart_layout_interpreter_composite_candidates();
37537
+ init_smartart_layout_interpreter_composite_fontfit();
37138
37538
  init_smartart_layout_interpreter_composite_group_slots();
37139
37539
  init_smartart_layout_interpreter_preset_node();
37140
- init_smartart_layout_interpreter_when();
37141
37540
  init_smartart_layout_shape_preset();
37142
37541
  }
37143
37542
  });
37144
- function resolveSharedFontFit(fontCtx, fontRoleNode, items) {
37145
- if (items.length === 0) {
37146
- return void 0;
37147
- }
37148
- return resolveTieredItemFontSize(
37149
- fontCtx.plan,
37150
- fontCtx.index,
37151
- items,
37152
- fontCtx.fontName,
37153
- void 0,
37154
- 0,
37155
- fontRoleNode
37156
- );
37157
- }
37158
- function resolveFontFitFromPairs(fontCtx, fontRoleNode, pairs3) {
37159
- if (!fontCtx) {
37160
- return void 0;
37161
- }
37162
- return resolveSharedFontFit(
37163
- fontCtx,
37164
- fontRoleNode,
37165
- pairs3.map((pair) => ({
37166
- rootText: pair.node.text,
37167
- descendantTexts: pair.desSlot?.content.map((entry2) => entry2.text) ?? [],
37168
- width: pair.selfRect.width,
37169
- height: pair.selfRect.height
37170
- }))
37171
- );
37172
- }
37173
- var init_smartart_layout_interpreter_composite_fontfit = __esm({
37174
- "src/core/utils/smartart-layout-interpreter-composite-fontfit.ts"() {
37175
- init_smartart_layout_item_font_tier();
37176
- }
37177
- });
37178
37543
  function forEachBoundSlots(slotted) {
37179
37544
  return slotted.filter((slot) => {
37180
37545
  const axis = slot.node.presentationOf?.axis;
@@ -37459,7 +37824,7 @@ function arrangeComposite(plan, nodes, box, palette, style, elementId, index = E
37459
37824
  childrenOf,
37460
37825
  ctx,
37461
37826
  fontCtx
37462
- ) ?? arrangeByChooseAwareSlots(plan.node, flat, box, index, ctx) ?? arrangeByOrder(slotted, nodes, box, absX, absY, ctx, fontCtx);
37827
+ ) ?? arrangeByChooseAwareSlots(plan.node, flat, box, index, ctx, fontCtx) ?? arrangeByOrder(slotted, nodes, box, absX, absY, ctx, fontCtx);
37463
37828
  return {
37464
37829
  nodes: renderedNodes,
37465
37830
  connectors: [],
@@ -37979,7 +38344,7 @@ function arrangePyramid(plan, nodes, box, palette, style, elementId, index = EMP
37979
38344
  index,
37980
38345
  roleOf(plan.node),
37981
38346
  ["sibSp", "sp"],
37982
- DEFAULT_GAP_RATIO
38347
+ DEFAULT_GAP_RATIO2
37983
38348
  );
37984
38349
  const usableH = h2 - DEFAULT_INSET * 2;
37985
38350
  const bandH = n > 0 ? usableH / (n + Math.max(0, n - 1) * gapRatio) : usableH;
@@ -38051,7 +38416,7 @@ function arrangePyramid(plan, nodes, box, palette, style, elementId, index = EMP
38051
38416
  family: "pyramid"
38052
38417
  };
38053
38418
  }
38054
- var DEFAULT_GAP_RATIO;
38419
+ var DEFAULT_GAP_RATIO2;
38055
38420
  var DEFAULT_INSET;
38056
38421
  var init_smartart_layout_interpreter_pyramid = __esm({
38057
38422
  "src/core/utils/smartart-layout-interpreter-pyramid.ts"() {
@@ -38061,7 +38426,7 @@ var init_smartart_layout_interpreter_pyramid = __esm({
38061
38426
  init_smartart_layout_interpreter_model();
38062
38427
  init_smartart_layout_interpreter_render();
38063
38428
  init_smartart_layout_item_font_tier();
38064
- DEFAULT_GAP_RATIO = 0;
38429
+ DEFAULT_GAP_RATIO2 = 0;
38065
38430
  DEFAULT_INSET = 0;
38066
38431
  }
38067
38432
  });
@@ -38243,26 +38608,67 @@ var init_smartart_hierarchy_pitch = __esm({
38243
38608
  GENERATION_MARGIN_RATIO = 0.1675;
38244
38609
  }
38245
38610
  });
38246
- function findHierarchyItemNode(node) {
38611
+ function collectTxShapeNodes(node, out, seen) {
38247
38612
  if (!node) {
38248
- return void 0;
38613
+ return;
38249
38614
  }
38250
38615
  if (node.algorithm?.type === "tx" && node.shape) {
38251
- return node;
38616
+ const key2 = node.name ?? `#${out.length}`;
38617
+ if (!seen.has(key2)) {
38618
+ seen.add(key2);
38619
+ out.push(node);
38620
+ }
38252
38621
  }
38253
38622
  for (const child262 of node.children ?? []) {
38254
- const found = findHierarchyItemNode(child262);
38255
- if (found) {
38256
- return found;
38623
+ collectTxShapeNodes(child262, out, seen);
38624
+ }
38625
+ }
38626
+ function crossReferencesAnotherCandidate(candidate, otherNames, constraints) {
38627
+ const candidateName = candidate.name;
38628
+ if (!candidateName) {
38629
+ return false;
38630
+ }
38631
+ return (constraints ?? []).some(
38632
+ (c) => (c.type === "h" || c.type === "w") && c.for === "des" && c.forName === candidateName && c.referenceForName !== void 0 && c.referenceForName !== candidateName && otherNames.has(c.referenceForName)
38633
+ );
38634
+ }
38635
+ function resolveHierarchyItemNode(algorithmNode) {
38636
+ if (!algorithmNode) {
38637
+ return void 0;
38638
+ }
38639
+ const candidates = [];
38640
+ collectTxShapeNodes(algorithmNode, candidates, /* @__PURE__ */ new Set());
38641
+ if (candidates.length === 0) {
38642
+ return void 0;
38643
+ }
38644
+ const first = candidates[0];
38645
+ if (candidates.length < 2 || !first) {
38646
+ return first;
38647
+ }
38648
+ const allNames = new Set(
38649
+ candidates.map((c) => c.name).filter((n) => n !== void 0)
38650
+ );
38651
+ const constraints = algorithmNode.allConstraints ?? algorithmNode.constraints ?? [];
38652
+ for (const candidate of candidates) {
38653
+ const otherNames = new Set(allNames);
38654
+ if (candidate.name) {
38655
+ otherNames.delete(candidate.name);
38656
+ }
38657
+ if (crossReferencesAnotherCandidate(candidate, otherNames, constraints)) {
38658
+ return candidate;
38257
38659
  }
38258
38660
  }
38259
- return void 0;
38661
+ return first;
38260
38662
  }
38663
+ var init_smartart_hierarchy_item_template = __esm({
38664
+ "src/core/utils/smartart-hierarchy-item-template.ts"() {
38665
+ }
38666
+ });
38261
38667
  function findHierarchyItemShape(node) {
38262
- return findHierarchyItemNode(node)?.shape;
38668
+ return resolveHierarchyItemNode(node)?.shape;
38263
38669
  }
38264
38670
  function findHierarchyItemName(node) {
38265
- return findHierarchyItemNode(node)?.name;
38671
+ return resolveHierarchyItemNode(node)?.name;
38266
38672
  }
38267
38673
  function baseContext(nodeCount, elementId, palette, style, boxW, boxH, connectorLabels, itemShape, itemFontSizePx) {
38268
38674
  return {
@@ -38323,6 +38729,7 @@ var HIER_TAIL_OFFSET_RATIO;
38323
38729
  var HANG_HEIGHT_RATIO;
38324
38730
  var init_smartart_hierarchy_shared = __esm({
38325
38731
  "src/core/utils/smartart-hierarchy-shared.ts"() {
38732
+ init_smartart_hierarchy_item_template();
38326
38733
  init_smartart_layout_interpreter_preset_node();
38327
38734
  init_smartart_layout_interpreter_render();
38328
38735
  HIER_TAIL_OFFSET_RATIO = 0.25;
@@ -38330,9 +38737,11 @@ var init_smartart_hierarchy_shared = __esm({
38330
38737
  }
38331
38738
  });
38332
38739
  function computeHierarchyAxisPitches(effectiveBox, orientation, boxW, boxH, totalLeaves, depth, hangShape, tailedPitch) {
38740
+ const generationItemSize = tailedPitch && orientation.compositeHeightFactor ? boxH / orientation.compositeHeightFactor : boxH;
38333
38741
  const generationMargin = orientation.transposed ? 0 : boxH * GENERATION_MARGIN_RATIO;
38334
38742
  const fanWidth = tailedPitch ? effectiveBox.width - hangShape.maxHangDepth * HIER_TAIL_OFFSET_RATIO * boxW : effectiveBox.width;
38335
- const fanHeight = tailedPitch ? effectiveBox.height - hangShape.maxHangRows * (1 + HANG_HEIGHT_RATIO) * boxH : effectiveBox.height;
38743
+ const hangHeightRatio = orientation.transposed ? orientation.generationGapRatio : HANG_HEIGHT_RATIO;
38744
+ const fanHeight = tailedPitch ? effectiveBox.height - hangShape.maxHangRows * (1 + hangHeightRatio) * boxH : effectiveBox.height;
38336
38745
  const xPitch = compositeFanPitch(
38337
38746
  fanWidth,
38338
38747
  boxW,
@@ -38345,7 +38754,7 @@ function computeHierarchyAxisPitches(effectiveBox, orientation, boxW, boxH, tota
38345
38754
  const yPitch = computeAxisPitch(
38346
38755
  fanHeight,
38347
38756
  generationMargin,
38348
- boxH,
38757
+ generationItemSize,
38349
38758
  depth,
38350
38759
  fixedGenerationGapRatio
38351
38760
  );
@@ -38391,6 +38800,27 @@ var init_smartart_hierarchy_branch_mode = __esm({
38391
38800
  "src/core/utils/smartart-hierarchy-branch-mode.ts"() {
38392
38801
  }
38393
38802
  });
38803
+ function resolveCascadePlan(mode, orientation, depth, hangShape, boxW) {
38804
+ const active = mode === "tailed" && orientation.compositeHeightFactor !== void 0;
38805
+ if (!active) {
38806
+ return { active, pitchDepth: depth, pitchHangShape: hangShape };
38807
+ }
38808
+ return {
38809
+ active,
38810
+ pitchDepth: depth + hangShape.maxHangRows,
38811
+ pitchHangShape: { ...hangShape, maxHangRows: 0 },
38812
+ cascadeOffsetX: {
38813
+ fromLevel: depth,
38814
+ offsetPx: boxW / (orientation.compositeWidthFactor ?? 1) * CASCADE_ALIGN_OFF_RATIO
38815
+ }
38816
+ };
38817
+ }
38818
+ var CASCADE_ALIGN_OFF_RATIO;
38819
+ var init_smartart_hierarchy_cascade = __esm({
38820
+ "src/core/utils/smartart-hierarchy-cascade.ts"() {
38821
+ CASCADE_ALIGN_OFF_RATIO = 0.65;
38822
+ }
38823
+ });
38394
38824
  function isAssistant(node) {
38395
38825
  return node.nodeType === "asst";
38396
38826
  }
@@ -38588,6 +39018,36 @@ var init_smartart_hierarchy_fold_depth = __esm({
38588
39018
  "src/core/utils/smartart-hierarchy-fold-depth.ts"() {
38589
39019
  }
38590
39020
  });
39021
+ function resolveHierarchyItemFontSizePx(nodes, algorithmNode, index, boxW, boxH, fontName) {
39022
+ if (!algorithmNode) {
39023
+ return void 0;
39024
+ }
39025
+ const textNodes = nodes.filter((node) => node.text && node.text.trim().length > 0);
39026
+ if (textNodes.length === 0) {
39027
+ return void 0;
39028
+ }
39029
+ const plan = { node: algorithmNode };
39030
+ const { rootSizePx } = resolveTieredItemFontSize(
39031
+ plan,
39032
+ index,
39033
+ textNodes.map((node) => ({
39034
+ rootText: node.text,
39035
+ descendantTexts: [],
39036
+ width: boxW,
39037
+ height: boxH
39038
+ })),
39039
+ fontName,
39040
+ void 0,
39041
+ 0,
39042
+ algorithmNode
39043
+ );
39044
+ return rootSizePx;
39045
+ }
39046
+ var init_smartart_layout_interpreter_hierarchy_fontfit = __esm({
39047
+ "src/core/utils/smartart-layout-interpreter-hierarchy-fontfit.ts"() {
39048
+ init_smartart_layout_item_font_tier();
39049
+ }
39050
+ });
38591
39051
  function placeAssistants(hc, x, parentBottom, assistants, options, cursor) {
38592
39052
  for (const assistant of assistants) {
38593
39053
  const y = cursor.y;
@@ -38628,10 +39088,45 @@ function placeHangingForest(hc, roots, startX2, startY, options) {
38628
39088
  placeHangingTree(hc, root, startX2, options, cursor);
38629
39089
  }
38630
39090
  }
39091
+ function arrangeFullyHangingTree(nodes, box, palette, style, elementId, roots, itemShape, connectorLabels, algorithmNode, index, fontName, linDir, orgChart) {
39092
+ const { width: w, height: h2 } = box;
39093
+ const boxW = Math.min(w * 0.42, 160);
39094
+ const boxH = Math.min(h2 * 0.16, 30);
39095
+ const indent = boxW * 0.35;
39096
+ const vGap = boxH * 0.55;
39097
+ const hc = baseContext(
39098
+ nodes.length,
39099
+ elementId,
39100
+ palette,
39101
+ style,
39102
+ boxW,
39103
+ boxH,
39104
+ connectorLabels,
39105
+ itemShape,
39106
+ resolveHierarchyItemFontSizePx(nodes, algorithmNode, index, boxW, boxH, fontName)
39107
+ );
39108
+ placeHangingForest(hc, roots, HANGING_MODE_INSET + indent, HANGING_MODE_INSET, {
39109
+ orgChart,
39110
+ direction: linDirHangDirection(linDir),
39111
+ indent,
39112
+ vGap
39113
+ });
39114
+ return {
39115
+ nodes: hc.nodes,
39116
+ connectors: hc.connectors,
39117
+ shadowFilter: hc.ctx.shadow,
39118
+ viewBox: `0 0 ${w} ${h2}`,
39119
+ family: "hierarchy"
39120
+ };
39121
+ }
39122
+ var HANGING_MODE_INSET;
38631
39123
  var init_smartart_hierarchy_hanging = __esm({
38632
39124
  "src/core/utils/smartart-hierarchy-hanging.ts"() {
39125
+ init_smartart_hierarchy_branch_mode();
38633
39126
  init_smartart_hierarchy_orgchart_tree();
38634
39127
  init_smartart_hierarchy_shared();
39128
+ init_smartart_layout_interpreter_hierarchy_fontfit();
39129
+ HANGING_MODE_INSET = 6;
38635
39130
  }
38636
39131
  });
38637
39132
  function findCompositeDescendant(node) {
@@ -38654,7 +39149,7 @@ function findTextBearingChild(compositeNode) {
38654
39149
  (child262) => (child262.presentationOf?.axis ?? []).includes("self")
38655
39150
  );
38656
39151
  }
38657
- function resolveCompositeChildGeometry(algorithmNode, wrapperAspect) {
39152
+ function resolveCompositeChildGeometry(algorithmNode, wrapperAspect, allowOmittedWidthFactor = false) {
38658
39153
  const compositeNode = findCompositeDescendant(algorithmNode);
38659
39154
  if (!compositeNode) {
38660
39155
  return void 0;
@@ -38665,12 +39160,15 @@ function resolveCompositeChildGeometry(algorithmNode, wrapperAspect) {
38665
39160
  }
38666
39161
  const constraints = compositeNode.allConstraints ?? compositeNode.constraints ?? [];
38667
39162
  const widthConstr = constraints.find(
38668
- (c) => c.type === "w" && c.for === "ch" && c.forName === child262.name && c.referenceType === "w" && c.referenceForName === void 0 && typeof c.factor === "number"
39163
+ (c) => c.type === "w" && c.for === "ch" && c.forName === child262.name && c.referenceType === "w" && c.referenceForName === void 0 && (typeof c.factor === "number" || allowOmittedWidthFactor && c.factor === void 0)
38669
39164
  );
38670
- if (!widthConstr || widthConstr.factor === void 0 || widthConstr.factor <= 0) {
39165
+ if (!widthConstr) {
39166
+ return void 0;
39167
+ }
39168
+ const widthFactor = widthConstr.factor ?? 1;
39169
+ if (widthFactor <= 0) {
38671
39170
  return void 0;
38672
39171
  }
38673
- const widthFactor = widthConstr.factor;
38674
39172
  const selfHeightConstr = constraints.find(
38675
39173
  (c) => c.type === "h" && c.for === "ch" && c.forName === child262.name && c.referenceType === "w" && c.referenceFor === "ch" && c.referenceForName === child262.name && typeof c.factor === "number"
38676
39174
  );
@@ -38688,11 +39186,15 @@ function resolveCompositeChildGeometry(algorithmNode, wrapperAspect) {
38688
39186
  const parentRelativeHeightConstr = constraints.find(
38689
39187
  (c) => c.type === "h" && c.for === "ch" && c.forName === child262.name && c.referenceType === "h" && c.referenceFor === void 0 && c.referenceForName === void 0 && typeof c.factor === "number"
38690
39188
  );
38691
- if (parentRelativeHeightConstr && typeof wrapperAspect === "number" && wrapperAspect > 0 && typeof parentRelativeHeightConstr.factor === "number") {
39189
+ const hasCompoundTextRole = constraints.some(
39190
+ (c) => c.type === "primFontSz" && c.referenceForName === child262.name
39191
+ );
39192
+ if (parentRelativeHeightConstr && !hasCompoundTextRole && typeof wrapperAspect === "number" && wrapperAspect > 0 && typeof parentRelativeHeightConstr.factor === "number") {
38692
39193
  return {
38693
39194
  aspectRatio: parentRelativeHeightConstr.factor * wrapperAspect / widthFactor,
38694
39195
  widthFactor,
38695
- offsetXRatio
39196
+ offsetXRatio,
39197
+ heightFactor: parentRelativeHeightConstr.factor
38696
39198
  };
38697
39199
  }
38698
39200
  return void 0;
@@ -38701,18 +39203,23 @@ var init_smartart_hierarchy_composite_child = __esm({
38701
39203
  "src/core/utils/smartart-hierarchy-composite-child.ts"() {
38702
39204
  }
38703
39205
  });
38704
- function findByReference(constraints, type, referenceType) {
38705
- const match = (constraints ?? []).find(
38706
- (c) => c.type === type && c.referenceType === referenceType && typeof c.factor === "number"
38707
- );
38708
- return match?.factor;
39206
+ function findByReference(constraints, type, referenceType, preferredName) {
39207
+ const list = constraints ?? [];
39208
+ const matches = (c) => c.type === type && c.referenceType === referenceType && typeof c.factor === "number";
39209
+ if (preferredName !== void 0) {
39210
+ const named = list.find((c) => matches(c) && c.forName === preferredName);
39211
+ if (named) {
39212
+ return named.factor;
39213
+ }
39214
+ }
39215
+ return list.find(matches)?.factor;
38709
39216
  }
38710
- function resolveAspectRatio(constraints) {
38711
- const hRefW = findByReference(constraints, "h", "w");
39217
+ function resolveAspectRatio(constraints, preferredName) {
39218
+ const hRefW = findByReference(constraints, "h", "w", preferredName);
38712
39219
  if (hRefW !== void 0 && hRefW > 0) {
38713
39220
  return hRefW;
38714
39221
  }
38715
- const wRefH = findByReference(constraints, "w", "h");
39222
+ const wRefH = findByReference(constraints, "w", "h", preferredName);
38716
39223
  if (wRefH !== void 0 && wRefH > 0) {
38717
39224
  return 1 / wRefH;
38718
39225
  }
@@ -38877,14 +39384,14 @@ var init_smartart_hierarchy_transpose = __esm({
38877
39384
  "src/core/utils/smartart-hierarchy-transpose.ts"() {
38878
39385
  }
38879
39386
  });
38880
- function fitItemBox(box, columns, levels, sibSpRatio, aspectRatio, generationGapRatio, marginXRatio, marginYRatio, maxHangDepth = 0, clampToNaturalAspect = true, maxHangRows = maxHangDepth, allChildrenHang = false) {
39387
+ function fitItemBox(box, columns, levels, sibSpRatio, aspectRatio, generationGapRatio, marginXRatio, marginYRatio, maxHangDepth = 0, clampToNaturalAspect = true, maxHangRows = maxHangDepth, allChildrenHang = false, hangHeightRatio = HANG_HEIGHT_RATIO) {
38881
39388
  const n = Math.max(1, columns);
38882
39389
  const usableW = box.width - 2 * box.width * marginXRatio;
38883
39390
  const allHangExtra = allChildrenHang ? ALL_CHILDREN_HANG_EXTRA_RATIO : 0;
38884
39391
  const widthFit = usableW / (n + Math.max(0, n - 1) * sibSpRatio + maxHangDepth * HIER_TAIL_OFFSET_RATIO + allHangExtra);
38885
39392
  const generations = Math.max(1, levels);
38886
39393
  const usableH = box.height - 2 * box.height * marginYRatio;
38887
- const heightFit = usableH / (generations + maxHangRows + Math.max(0, generations - 1) * generationGapRatio + maxHangRows * HANG_HEIGHT_RATIO);
39394
+ const heightFit = usableH / (generations + maxHangRows + Math.max(0, generations - 1) * generationGapRatio + maxHangRows * hangHeightRatio);
38888
39395
  const naturalHeight = widthFit * aspectRatio;
38889
39396
  const boxH = clampToNaturalAspect ? Math.min(naturalHeight, heightFit) : heightFit;
38890
39397
  const boxW = clampToNaturalAspect ? boxH / aspectRatio : widthFit;
@@ -38912,7 +39419,7 @@ function resolveHierarchyOrientation(algorithmNode, index, mode = "std", itemSha
38912
39419
  algorithmNode?.rules
38913
39420
  );
38914
39421
  if (sibSpReferencesHeight || tailedTransposed) {
38915
- const hToW = resolveAspectRatio(constraints);
39422
+ const hToW = resolveAspectRatio(constraints, itemShapeName);
38916
39423
  return {
38917
39424
  transposed: true,
38918
39425
  sibSpRatio,
@@ -38934,8 +39441,12 @@ function resolveHierarchyOrientation(algorithmNode, index, mode = "std", itemSha
38934
39441
  cardOffsetXRatio: 0
38935
39442
  };
38936
39443
  }
38937
- const compositeAspect = resolveAspectRatio(constraints);
38938
- const compositeChild = resolveCompositeChildGeometry(algorithmNode, compositeAspect);
39444
+ const compositeAspect = resolveAspectRatio(constraints, itemShapeName);
39445
+ const compositeChild = resolveCompositeChildGeometry(
39446
+ algorithmNode,
39447
+ compositeAspect,
39448
+ mode === "tailed"
39449
+ );
38939
39450
  const aspectRatio = compositeChild?.aspectRatio ?? compositeAspect;
38940
39451
  const tailedMargin = mode === "tailed";
38941
39452
  return {
@@ -38972,6 +39483,7 @@ function resolveHierarchyOrientation(algorithmNode, index, mode = "std", itemSha
38972
39483
  marginXRatio: tailedMargin ? 0 : OUTER_MARGIN_X_RATIO,
38973
39484
  marginYRatio: tailedMargin ? 0 : OUTER_MARGIN_Y_RATIO,
38974
39485
  compositeWidthFactor: compositeChild?.widthFactor,
39486
+ compositeHeightFactor: compositeChild?.heightFactor,
38975
39487
  cardOffsetXRatio: compositeChild?.offsetXRatio ?? 0
38976
39488
  };
38977
39489
  }
@@ -39076,10 +39588,11 @@ function placeFlatChildren(hc, parentId, normal, cx, cy, xOffset, level, cellW,
39076
39588
  offset += childW;
39077
39589
  }
39078
39590
  }
39591
+ const cascadeShift = options.cascadeOffsetX && level + 1 >= options.cascadeOffsetX.fromLevel ? options.cascadeOffsetX.offsetPx : 0;
39079
39592
  let childOffset = xOffset;
39080
39593
  for (const child262 of normal) {
39081
39594
  const childW = spanOf(child262, options);
39082
- const childCx = (childOffset + childW / 2) * cellW;
39595
+ const childCx = (childOffset + childW / 2) * cellW + cascadeShift;
39083
39596
  const childCy = (level + 1) * cellH + cellH / 2;
39084
39597
  elbowConnector(
39085
39598
  hc,
@@ -39260,7 +39773,7 @@ function placeAt(hc, t, cx, cy, xOffset, spanW, level, cellW, cellH, options, si
39260
39773
  placeFlatChildren2(hc, t.node.id, normal, cx, cy, xOffset, level, cellW, cellH, options);
39261
39774
  return;
39262
39775
  }
39263
- const anchorY = cy + hc.boxH / 2 + HANG_HEIGHT_RATIO * hc.boxH;
39776
+ const anchorY = cy + hc.boxH / 2 + (options.hangHeightRatio ?? HANG_HEIGHT_RATIO) * hc.boxH;
39264
39777
  const columnOffset = hc.boxW * HIER_TAIL_OFFSET_RATIO;
39265
39778
  for (const child262 of normal) {
39266
39779
  elbowConnector(
@@ -39296,7 +39809,8 @@ function placeAt(hc, t, cx, cy, xOffset, spanW, level, cellW, cellH, options, si
39296
39809
  }
39297
39810
  function placeStandardTree(hc, t, xOffset, level, cellW, cellH, options) {
39298
39811
  const spanW = spanOf(t, options);
39299
- const cx = (xOffset + spanW / 2) * cellW;
39812
+ const cascadeShift = options.cascadeOffsetX && level >= options.cascadeOffsetX.fromLevel ? options.cascadeOffsetX.offsetPx : 0;
39813
+ const cx = (xOffset + spanW / 2) * cellW + cascadeShift;
39300
39814
  const cy = level * cellH + cellH / 2;
39301
39815
  placeAt(hc, t, cx, cy, xOffset, spanW, level, cellW, cellH, options);
39302
39816
  }
@@ -39310,36 +39824,6 @@ var init_smartart_hierarchy_standard = __esm({
39310
39824
  init_smartart_hierarchy_wrapped_groups();
39311
39825
  }
39312
39826
  });
39313
- function resolveHierarchyItemFontSizePx(nodes, algorithmNode, index, boxW, boxH, fontName) {
39314
- if (!algorithmNode) {
39315
- return void 0;
39316
- }
39317
- const textNodes = nodes.filter((node) => node.text && node.text.trim().length > 0);
39318
- if (textNodes.length === 0) {
39319
- return void 0;
39320
- }
39321
- const plan = { node: algorithmNode };
39322
- const { rootSizePx } = resolveTieredItemFontSize(
39323
- plan,
39324
- index,
39325
- textNodes.map((node) => ({
39326
- rootText: node.text,
39327
- descendantTexts: [],
39328
- width: boxW,
39329
- height: boxH
39330
- })),
39331
- fontName,
39332
- void 0,
39333
- 0,
39334
- algorithmNode
39335
- );
39336
- return rootSizePx;
39337
- }
39338
- var init_smartart_layout_interpreter_hierarchy_fontfit = __esm({
39339
- "src/core/utils/smartart-layout-interpreter-hierarchy-fontfit.ts"() {
39340
- init_smartart_layout_item_font_tier();
39341
- }
39342
- });
39343
39827
  function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars, connectorLabels, algorithmNode, index = EMPTY_CONSTRAINT_INDEX, childOrder3, fontName) {
39344
39828
  const { width: w, height: h2 } = box;
39345
39829
  const orgChart = presLayoutVars?.orgChart === true;
@@ -39349,28 +39833,21 @@ function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars,
39349
39833
  const mode = branchMode(presLayoutVars, linDir);
39350
39834
  const itemShape = algorithmNode ? findHierarchyItemShape(algorithmNode) : void 0;
39351
39835
  if (mode === "hanging") {
39352
- const boxW2 = Math.min(w * 0.42, 160);
39353
- const boxH2 = Math.min(h2 * 0.16, 30);
39354
- const indent = boxW2 * 0.35;
39355
- const vGap = boxH2 * 0.55;
39356
- const hc2 = baseContext(
39357
- nodes.length,
39358
- elementId,
39836
+ return arrangeFullyHangingTree(
39837
+ nodes,
39838
+ box,
39359
39839
  palette,
39360
39840
  style,
39361
- boxW2,
39362
- boxH2,
39363
- connectorLabels,
39841
+ elementId,
39842
+ roots,
39364
39843
  itemShape,
39365
- resolveHierarchyItemFontSizePx(nodes, algorithmNode, index, boxW2, boxH2, fontName)
39844
+ connectorLabels,
39845
+ algorithmNode,
39846
+ index,
39847
+ fontName,
39848
+ linDir,
39849
+ orgChart
39366
39850
  );
39367
- placeHangingForest(hc2, roots, INSET3 + indent, INSET3, {
39368
- orgChart,
39369
- direction: linDirHangDirection(linDir),
39370
- indent,
39371
- vGap
39372
- });
39373
- return finish(hc2.nodes, hc2.connectors, hc2.ctx.shadow, w, h2);
39374
39851
  }
39375
39852
  const orientation = resolveHierarchyOrientation(
39376
39853
  algorithmNode,
@@ -39398,8 +39875,10 @@ function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars,
39398
39875
  hangShape.maxHangDepth,
39399
39876
  void 0,
39400
39877
  hangShape.maxHangRows,
39401
- hangShape.allChildrenHang
39878
+ hangShape.allChildrenHang,
39879
+ orientation.transposed ? orientation.generationGapRatio : void 0
39402
39880
  );
39881
+ const cascadePlan = resolveCascadePlan(mode, orientation, depth, hangShape, boxW);
39403
39882
  const tailedPitch = mode === "tailed";
39404
39883
  const { xPitch, yPitch } = computeHierarchyAxisPitches(
39405
39884
  effectiveBox,
@@ -39407,8 +39886,8 @@ function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars,
39407
39886
  boxW,
39408
39887
  boxH,
39409
39888
  totalLeaves,
39410
- depth,
39411
- hangShape,
39889
+ cascadePlan.pitchDepth,
39890
+ cascadePlan.pitchHangShape,
39412
39891
  tailedPitch
39413
39892
  );
39414
39893
  const cellW = xPitch.pitch;
@@ -39428,9 +39907,11 @@ function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars,
39428
39907
  orgChart,
39429
39908
  perRow: rowSize,
39430
39909
  foldDeeperGenerations: algorithmNode ? hierarchyLeafFoldsDescendants(algorithmNode) : false,
39431
- resolveSpan: fanAwareWidthMap ? (t) => resolveSpanWidth(fanAwareWidthMap, t, orgChart) : void 0
39910
+ resolveSpan: fanAwareWidthMap ? (t) => resolveSpanWidth(fanAwareWidthMap, t, orgChart) : void 0,
39911
+ hangHeightRatio: orientation.transposed ? orientation.generationGapRatio : void 0,
39912
+ cascadeOffsetX: cascadePlan.cascadeOffsetX
39432
39913
  };
39433
- if (mode === "tailed") {
39914
+ if (mode === "tailed" && !cascadePlan.active) {
39434
39915
  const indent = boxW * HIER_TAIL_OFFSET_RATIO;
39435
39916
  const vGap = boxH * 0.55;
39436
39917
  const direction = tailDirection();
@@ -39458,13 +39939,13 @@ function arrangeHierarchy(nodes, box, palette, style, elementId, presLayoutVars,
39458
39939
  function finish(nodes, connectors, shadowFilter, w, h2) {
39459
39940
  return { nodes, connectors, shadowFilter, viewBox: `0 0 ${w} ${h2}`, family: "hierarchy" };
39460
39941
  }
39461
- var INSET3;
39462
39942
  var init_smartart_layout_interpreter_hierarchy = __esm({
39463
39943
  "src/core/utils/smartart-layout-interpreter-hierarchy.ts"() {
39464
39944
  init_smartart_constraint_solver();
39465
39945
  init_smartart_helpers();
39466
39946
  init_smartart_hierarchy_axis_pitch();
39467
39947
  init_smartart_hierarchy_branch_mode();
39948
+ init_smartart_hierarchy_cascade();
39468
39949
  init_smartart_hierarchy_fan_aware_width();
39469
39950
  init_smartart_hierarchy_fold_depth();
39470
39951
  init_smartart_hierarchy_hang_depth();
@@ -39476,7 +39957,6 @@ var init_smartart_layout_interpreter_hierarchy = __esm({
39476
39957
  init_smartart_hierarchy_standard();
39477
39958
  init_smartart_layout_interpreter_hierarchy_fontfit();
39478
39959
  init_smartart_layout_interpreter_model();
39479
- INSET3 = 6;
39480
39960
  }
39481
39961
  });
39482
39962
  function isChildNodeForEach(entry2) {
@@ -40209,7 +40689,7 @@ function repositionPyramidBands(result, box, planNode, topLevelIds, flatNodes, h
40209
40689
  index,
40210
40690
  roleOf(planNode),
40211
40691
  ["sibSp", "sp"],
40212
- DEFAULT_GAP_RATIO
40692
+ DEFAULT_GAP_RATIO2
40213
40693
  );
40214
40694
  const inverted = algorithmParam(planNode, "linDir") === "fromT";
40215
40695
  const nodes = result.nodes.map((rendered) => {
@@ -40334,7 +40814,8 @@ function runArrangement(input) {
40334
40814
  resolveNamedRuleOverride(collectNamedRules(layoutDefinition), itemNode(plan.node)?.name),
40335
40815
  box
40336
40816
  ) : result;
40337
- const withItemRoles = STRUCTURAL_ARRANGEMENT_KINDS.has(plan.kind) ? expandResultItemRoles(
40817
+ const isTableTemplate = isRecursiveTableItemTemplate(plan.node, presLayoutVars);
40818
+ const withItemRoles = STRUCTURAL_ARRANGEMENT_KINDS.has(plan.kind) && !isTableTemplate ? expandResultItemRoles(
40338
40819
  plan.node,
40339
40820
  withNamedRule,
40340
40821
  nodes,
@@ -40395,6 +40876,7 @@ var init_smartart_layout_interpreter = __esm({
40395
40876
  init_smartart_layout_interpreter_hierarchy();
40396
40877
  init_smartart_layout_interpreter_hub();
40397
40878
  init_smartart_layout_interpreter_item_roles();
40879
+ init_smartart_layout_interpreter_linear_table();
40398
40880
  init_smartart_layout_interpreter_model();
40399
40881
  init_smartart_layout_interpreter_named_rules();
40400
40882
  init_smartart_layout_interpreter_pyramid_bands();
@@ -45482,8 +45964,8 @@ function parseDataLabelFieldTable(group2, xmlLookup) {
45482
45964
  return void 0;
45483
45965
  }
45484
45966
  const points4 = [];
45485
- for (const table of tables) {
45486
- collectByLocalName2(table, "pt", points4);
45967
+ for (const table2 of tables) {
45968
+ collectByLocalName2(table2, "pt", points4);
45487
45969
  }
45488
45970
  const map = /* @__PURE__ */ new Map();
45489
45971
  for (const pt2 of points4) {
@@ -56158,16 +56640,327 @@ var init_slide_title = __esm({
56158
56640
  TITLE_PLACEHOLDER_TYPES = /* @__PURE__ */ new Set(["title", "ctrtitle"]);
56159
56641
  }
56160
56642
  });
56643
+ function readMaskChannel(value, mask) {
56644
+ if (mask === 0) {
56645
+ return 0;
56646
+ }
56647
+ let m = mask;
56648
+ let shift = 0;
56649
+ while ((m & 1) === 0) {
56650
+ m >>>= 1;
56651
+ shift++;
56652
+ }
56653
+ const bits = 32 - Math.clz32(m);
56654
+ const raw = (value & mask) >>> shift;
56655
+ const maxVal = (1 << bits) - 1;
56656
+ return maxVal === 0 ? 0 : Math.round(raw / maxVal * 255);
56657
+ }
56658
+ function decodeBmpFirstPixel(bytes) {
56659
+ if (bytes.length < 54 || bytes[0] !== 66 || bytes[1] !== 77) {
56660
+ return void 0;
56661
+ }
56662
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
56663
+ const pixelDataOffset = view.getUint32(10, true);
56664
+ const headerSize = view.getUint32(14, true);
56665
+ if (headerSize < 40) {
56666
+ return void 0;
56667
+ }
56668
+ const width = view.getInt32(18, true);
56669
+ const rawHeight = view.getInt32(22, true);
56670
+ const bitCount = view.getUint16(28, true);
56671
+ const compression = view.getUint32(30, true);
56672
+ if (width <= 0 || rawHeight === 0) {
56673
+ return void 0;
56674
+ }
56675
+ const topDown = rawHeight < 0;
56676
+ const height = Math.abs(rawHeight);
56677
+ let redMask = 16711680;
56678
+ let greenMask = 65280;
56679
+ let blueMask = 255;
56680
+ let paletteOffset = 14 + headerSize;
56681
+ if (compression === 3) {
56682
+ redMask = view.getUint32(54, true);
56683
+ greenMask = view.getUint32(58, true);
56684
+ blueMask = view.getUint32(62, true);
56685
+ paletteOffset = 54 + 12;
56686
+ } else if (compression !== 0) {
56687
+ return void 0;
56688
+ }
56689
+ const rowStride = Math.ceil(width * bitCount / 32) * 4;
56690
+ const rowIndexFromTop = 0;
56691
+ const storedRowIndex = topDown ? rowIndexFromTop : height - 1 - rowIndexFromTop;
56692
+ const rowStart = pixelDataOffset + storedRowIndex * rowStride;
56693
+ if (rowStart < 0 || rowStart + Math.ceil(bitCount / 8) > bytes.length) {
56694
+ return void 0;
56695
+ }
56696
+ if (bitCount <= 8) {
56697
+ const paletteCount = 1 << bitCount;
56698
+ if (paletteOffset + paletteCount * 4 > bytes.length) {
56699
+ return void 0;
56700
+ }
56701
+ let index;
56702
+ if (bitCount === 8) {
56703
+ index = bytes[rowStart];
56704
+ } else {
56705
+ const byte = bytes[rowStart];
56706
+ index = byte >> 8 - bitCount;
56707
+ }
56708
+ const entry2 = paletteOffset + index * 4;
56709
+ return { r: bytes[entry2 + 2], g: bytes[entry2 + 1], b: bytes[entry2], a: 255 };
56710
+ }
56711
+ if (bitCount === 24) {
56712
+ return { r: bytes[rowStart + 2], g: bytes[rowStart + 1], b: bytes[rowStart], a: 255 };
56713
+ }
56714
+ if (bitCount === 32) {
56715
+ const value = bytes[rowStart] | bytes[rowStart + 1] << 8 | bytes[rowStart + 2] << 16 | bytes[rowStart + 3] << 24;
56716
+ return {
56717
+ r: readMaskChannel(value, redMask),
56718
+ g: readMaskChannel(value, greenMask),
56719
+ b: readMaskChannel(value, blueMask),
56720
+ a: 255
56721
+ };
56722
+ }
56723
+ if (bitCount === 16) {
56724
+ const value = bytes[rowStart] | bytes[rowStart + 1] << 8;
56725
+ if (compression === 3) {
56726
+ return {
56727
+ r: readMaskChannel(value, redMask),
56728
+ g: readMaskChannel(value, greenMask),
56729
+ b: readMaskChannel(value, blueMask),
56730
+ a: 255
56731
+ };
56732
+ }
56733
+ const r5 = value >> 10 & 31;
56734
+ const g5 = value >> 5 & 31;
56735
+ const b5 = value & 31;
56736
+ const scale2 = (v) => Math.round(v / 31 * 255);
56737
+ return { r: scale2(r5), g: scale2(g5), b: scale2(b5), a: 255 };
56738
+ }
56739
+ return void 0;
56740
+ }
56161
56741
  var init_image_first_pixel_bmp = __esm({
56162
56742
  "src/core/utils/image-first-pixel-bmp.ts"() {
56163
56743
  }
56164
56744
  });
56745
+ function readFirstColorIndex(data, subBlocksStart, minCodeSize) {
56746
+ const clearCode = 1 << minCodeSize;
56747
+ const endCode = clearCode + 1;
56748
+ let codeSize = minCodeSize + 1;
56749
+ const reader = new GifSubBlockBitReader(data, subBlocksStart);
56750
+ for (let guard = 0; guard < 8; guard++) {
56751
+ const code = reader.bits(codeSize);
56752
+ if (code === void 0 || code === endCode) {
56753
+ return void 0;
56754
+ }
56755
+ if (code === clearCode) {
56756
+ codeSize = minCodeSize + 1;
56757
+ continue;
56758
+ }
56759
+ return code < clearCode ? code : void 0;
56760
+ }
56761
+ return void 0;
56762
+ }
56763
+ function locateFirstImage(data, start) {
56764
+ let pos2 = start;
56765
+ let transparentIndex;
56766
+ while (pos2 < data.length) {
56767
+ const marker = data[pos2];
56768
+ if (marker === 33) {
56769
+ const label = data[pos2 + 1];
56770
+ pos2 += 2;
56771
+ if (label === 249 && data[pos2] === 4) {
56772
+ const packed = data[pos2 + 1];
56773
+ const hasTransparency = (packed & 1) !== 0;
56774
+ if (hasTransparency) {
56775
+ transparentIndex = data[pos2 + 4];
56776
+ }
56777
+ }
56778
+ for (; ; ) {
56779
+ const len = data[pos2];
56780
+ pos2 += 1 + len;
56781
+ if (len === 0 || pos2 >= data.length) {
56782
+ break;
56783
+ }
56784
+ }
56785
+ } else if (marker === 44) {
56786
+ const packed = data[pos2 + 9];
56787
+ let cursor = pos2 + 10;
56788
+ let localColorTable;
56789
+ if (packed & 128) {
56790
+ const size = 2 << (packed & 7);
56791
+ localColorTable = data.subarray(cursor, cursor + size * 3);
56792
+ cursor += size * 3;
56793
+ }
56794
+ const minCodeSize = data[cursor];
56795
+ cursor += 1;
56796
+ return { image: { subBlocksStart: cursor, minCodeSize, localColorTable }, transparentIndex };
56797
+ } else {
56798
+ return void 0;
56799
+ }
56800
+ }
56801
+ return void 0;
56802
+ }
56803
+ function decodeGifFirstPixel(bytes) {
56804
+ if (bytes.length < 13) {
56805
+ return void 0;
56806
+ }
56807
+ const sig = String.fromCharCode(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
56808
+ if (sig !== "GIF87a" && sig !== "GIF89a") {
56809
+ return void 0;
56810
+ }
56811
+ const packed = bytes[10];
56812
+ let pos2 = 13;
56813
+ let globalColorTable;
56814
+ if (packed & 128) {
56815
+ const size = 2 << (packed & 7);
56816
+ globalColorTable = bytes.subarray(pos2, pos2 + size * 3);
56817
+ pos2 += size * 3;
56818
+ }
56819
+ const located = locateFirstImage(bytes, pos2);
56820
+ if (!located) {
56821
+ return void 0;
56822
+ }
56823
+ const { image, transparentIndex } = located;
56824
+ const index = readFirstColorIndex(bytes, image.subBlocksStart, image.minCodeSize);
56825
+ if (index === void 0) {
56826
+ return void 0;
56827
+ }
56828
+ const table2 = image.localColorTable ?? globalColorTable;
56829
+ if (!table2 || table2.length < (index + 1) * 3) {
56830
+ return void 0;
56831
+ }
56832
+ if (transparentIndex === index) {
56833
+ return void 0;
56834
+ }
56835
+ return { r: table2[index * 3], g: table2[index * 3 + 1], b: table2[index * 3 + 2], a: 255 };
56836
+ }
56837
+ var GifSubBlockBitReader;
56165
56838
  var init_image_first_pixel_gif = __esm({
56166
56839
  "src/core/utils/image-first-pixel-gif.ts"() {
56840
+ GifSubBlockBitReader = class {
56841
+ constructor(data, pos2) {
56842
+ this.data = data;
56843
+ this.pos = pos2;
56844
+ }
56845
+ data;
56846
+ pos;
56847
+ blockBytes = new Uint8Array(0);
56848
+ blockPos = 0;
56849
+ bitBuf = 0;
56850
+ bitCount = 0;
56851
+ ended = false;
56852
+ nextByte() {
56853
+ if (this.blockPos >= this.blockBytes.length) {
56854
+ if (this.ended || this.pos >= this.data.length) {
56855
+ this.ended = true;
56856
+ return void 0;
56857
+ }
56858
+ const len = this.data[this.pos];
56859
+ this.pos += 1;
56860
+ if (len === 0) {
56861
+ this.ended = true;
56862
+ return void 0;
56863
+ }
56864
+ this.blockBytes = this.data.subarray(this.pos, this.pos + len);
56865
+ this.blockPos = 0;
56866
+ this.pos += len;
56867
+ }
56868
+ return this.blockBytes[this.blockPos++];
56869
+ }
56870
+ /** Read `count` bits, LSB-first. Returns `undefined` at end of data. */
56871
+ bits(count) {
56872
+ while (this.bitCount < count) {
56873
+ const byte = this.nextByte();
56874
+ if (byte === void 0) {
56875
+ return void 0;
56876
+ }
56877
+ this.bitBuf |= byte << this.bitCount;
56878
+ this.bitCount += 8;
56879
+ }
56880
+ const value = this.bitBuf & (1 << count) - 1;
56881
+ this.bitBuf >>>= count;
56882
+ this.bitCount -= count;
56883
+ return value;
56884
+ }
56885
+ };
56167
56886
  }
56168
56887
  });
56888
+ function buildJpegHuffmanTable(bits, huffval) {
56889
+ const counts = new Uint16Array(17);
56890
+ for (let len = 1; len <= 16; len++) {
56891
+ counts[len] = bits[len - 1];
56892
+ }
56893
+ return { counts, symbols: huffval };
56894
+ }
56895
+ function decodeJpegHuffmanSymbol(reader, table2) {
56896
+ let code = 0;
56897
+ let first = 0;
56898
+ let index = 0;
56899
+ for (let len = 1; len <= 16; len++) {
56900
+ code = code << 1 | reader.bits(1);
56901
+ const count = table2.counts[len];
56902
+ if (count > 0 && code - first < count) {
56903
+ return table2.symbols[index + (code - first)];
56904
+ }
56905
+ index += count;
56906
+ first += count;
56907
+ first <<= 1;
56908
+ }
56909
+ throw new Error("jpeg: invalid Huffman code");
56910
+ }
56911
+ function extendSigned(value, size) {
56912
+ if (size === 0) {
56913
+ return 0;
56914
+ }
56915
+ const half = 1 << size - 1;
56916
+ return value < half ? value - (1 << size) + 1 : value;
56917
+ }
56918
+ var JpegBitReader;
56169
56919
  var init_image_first_pixel_jpeg_bitstream = __esm({
56170
56920
  "src/core/utils/image-first-pixel-jpeg-bitstream.ts"() {
56921
+ JpegBitReader = class {
56922
+ constructor(data, startOffset) {
56923
+ this.data = data;
56924
+ this.pos = startOffset;
56925
+ }
56926
+ data;
56927
+ pos;
56928
+ currentByte = 0;
56929
+ bitsLeftInByte = 0;
56930
+ /** Set once a raw (non-stuffed) 0xFF marker byte is encountered: end of this scan's data. */
56931
+ hitMarker = false;
56932
+ nextBit() {
56933
+ if (this.bitsLeftInByte === 0) {
56934
+ if (this.hitMarker || this.pos >= this.data.length) {
56935
+ return 0;
56936
+ }
56937
+ const byte = this.data[this.pos];
56938
+ if (byte === 255) {
56939
+ const next = this.data[this.pos + 1];
56940
+ if (next === 0) {
56941
+ this.pos += 2;
56942
+ } else {
56943
+ this.hitMarker = true;
56944
+ return 0;
56945
+ }
56946
+ } else {
56947
+ this.pos += 1;
56948
+ }
56949
+ this.currentByte = byte;
56950
+ this.bitsLeftInByte = 8;
56951
+ }
56952
+ this.bitsLeftInByte -= 1;
56953
+ return this.currentByte >> this.bitsLeftInByte & 1;
56954
+ }
56955
+ /** Read `count` (0-16) bits MSB-first as an unsigned integer. */
56956
+ bits(count) {
56957
+ let value = 0;
56958
+ for (let i2 = 0; i2 < count; i2++) {
56959
+ value = value << 1 | this.nextBit();
56960
+ }
56961
+ return value >>> 0;
56962
+ }
56963
+ };
56171
56964
  }
56172
56965
  });
56173
56966
  function cornerIdctWeight(u, v) {
@@ -56175,10 +56968,238 @@ function cornerIdctWeight(u, v) {
56175
56968
  const cv = v === 0 ? 1 / Math.SQRT2 : 1;
56176
56969
  return 0.25 * cu * cv * Math.cos(u * Math.PI / 16) * Math.cos(v * Math.PI / 16);
56177
56970
  }
56971
+ function decodeBlockCornerSample(reader, dcTable, acTable, quantTable) {
56972
+ const coeffs = new Float64Array(64);
56973
+ const dcSize = decodeJpegHuffmanSymbol(reader, dcTable);
56974
+ const dcBits = reader.bits(dcSize);
56975
+ const dc = extendSigned(dcBits, dcSize);
56976
+ coeffs[0] = dc * quantTable[0];
56977
+ let k = 1;
56978
+ while (k < 64) {
56979
+ const rs = decodeJpegHuffmanSymbol(reader, acTable);
56980
+ const run = rs >> 4;
56981
+ const size = rs & 15;
56982
+ if (size === 0) {
56983
+ if (run === 15) {
56984
+ k += 16;
56985
+ continue;
56986
+ }
56987
+ break;
56988
+ }
56989
+ k += run;
56990
+ if (k >= 64) {
56991
+ break;
56992
+ }
56993
+ const bits = reader.bits(size);
56994
+ const value = extendSigned(bits, size);
56995
+ const naturalIndex = ZIGZAG[k];
56996
+ coeffs[naturalIndex] = value * quantTable[k];
56997
+ k += 1;
56998
+ }
56999
+ let sum = 0;
57000
+ for (let i2 = 0; i2 < 64; i2++) {
57001
+ sum += coeffs[i2] * CORNER_WEIGHTS[i2];
57002
+ }
57003
+ return sum;
57004
+ }
57005
+ function clamp8(value) {
57006
+ return Math.max(0, Math.min(255, Math.round(value)));
57007
+ }
57008
+ function decodeJpegFirstPixel(bytes) {
57009
+ if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) {
57010
+ return void 0;
57011
+ }
57012
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
57013
+ const quantTables = /* @__PURE__ */ new Map();
57014
+ const dcTables = /* @__PURE__ */ new Map();
57015
+ const acTables = /* @__PURE__ */ new Map();
57016
+ let components;
57017
+ let pos2 = 2;
57018
+ try {
57019
+ while (pos2 + 4 <= bytes.length) {
57020
+ if (bytes[pos2] !== 255) {
57021
+ pos2 += 1;
57022
+ continue;
57023
+ }
57024
+ const marker = bytes[pos2 + 1];
57025
+ if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) {
57026
+ pos2 += 2;
57027
+ continue;
57028
+ }
57029
+ if (marker === 217) {
57030
+ return void 0;
57031
+ }
57032
+ const length = view.getUint16(pos2 + 2, false);
57033
+ const segStart = pos2 + 4;
57034
+ if (marker === 219) {
57035
+ let off = segStart;
57036
+ const segEnd = pos2 + 2 + length;
57037
+ while (off < segEnd) {
57038
+ const pq = bytes[off] >> 4;
57039
+ const tq = bytes[off] & 15;
57040
+ off += 1;
57041
+ const table2 = new Uint16Array(64);
57042
+ for (let i2 = 0; i2 < 64; i2++) {
57043
+ table2[i2] = pq === 0 ? bytes[off + i2] : view.getUint16(off + i2 * 2, false);
57044
+ }
57045
+ off += pq === 0 ? 64 : 128;
57046
+ quantTables.set(tq, table2);
57047
+ }
57048
+ } else if (marker === 192 || marker === 193) {
57049
+ const numComponents = bytes[segStart + 5];
57050
+ components = [];
57051
+ for (let i2 = 0; i2 < numComponents; i2++) {
57052
+ const base = segStart + 6 + i2 * 3;
57053
+ components.push({
57054
+ id: bytes[base],
57055
+ hSampling: bytes[base + 1] >> 4,
57056
+ vSampling: bytes[base + 1] & 15,
57057
+ quantTableId: bytes[base + 2]
57058
+ });
57059
+ }
57060
+ } else if (marker === 194) {
57061
+ return void 0;
57062
+ } else if (marker === 196) {
57063
+ let off = segStart;
57064
+ const segEnd = pos2 + 2 + length;
57065
+ while (off < segEnd) {
57066
+ const tc = bytes[off] >> 4;
57067
+ const th = bytes[off] & 15;
57068
+ off += 1;
57069
+ const bits = bytes.subarray(off, off + 16);
57070
+ off += 16;
57071
+ const total = bits.reduce((s, b) => s + b, 0);
57072
+ const huffval = bytes.subarray(off, off + total);
57073
+ off += total;
57074
+ const table2 = buildJpegHuffmanTable(bits, huffval);
57075
+ (tc === 0 ? dcTables : acTables).set(th, table2);
57076
+ }
57077
+ } else if (marker === 218) {
57078
+ if (!components) {
57079
+ return void 0;
57080
+ }
57081
+ const scanCount = bytes[segStart];
57082
+ const scanComponents = [];
57083
+ for (let i2 = 0; i2 < scanCount; i2++) {
57084
+ const base = segStart + 1 + i2 * 2;
57085
+ const compId = bytes[base];
57086
+ const comp = components.find((c) => c.id === compId);
57087
+ if (!comp) {
57088
+ return void 0;
57089
+ }
57090
+ scanComponents.push({ comp, dcId: bytes[base + 1] >> 4, acId: bytes[base + 1] & 15 });
57091
+ }
57092
+ const reader = new JpegBitReader(bytes, segStart + 1 + scanCount * 2 + 3);
57093
+ const cornerSamples = [];
57094
+ for (const sc of scanComponents) {
57095
+ const dcTable = dcTables.get(sc.dcId);
57096
+ const acTable = acTables.get(sc.acId);
57097
+ const quantTable = quantTables.get(sc.comp.quantTableId);
57098
+ if (!dcTable || !acTable || !quantTable) {
57099
+ return void 0;
57100
+ }
57101
+ const blockCount = sc.comp.hSampling * sc.comp.vSampling;
57102
+ let first;
57103
+ for (let b = 0; b < blockCount; b++) {
57104
+ const sample = decodeBlockCornerSample(reader, dcTable, acTable, quantTable);
57105
+ if (b === 0) {
57106
+ first = sample;
57107
+ }
57108
+ }
57109
+ cornerSamples.push(clamp8(first + 128));
57110
+ }
57111
+ return combineComponentsToRgb(cornerSamples);
57112
+ }
57113
+ pos2 += 2 + length;
57114
+ }
57115
+ } catch {
57116
+ return void 0;
57117
+ }
57118
+ return void 0;
57119
+ }
57120
+ function combineComponentsToRgb(samples) {
57121
+ if (samples.length === 1) {
57122
+ const y2 = samples[0];
57123
+ return { r: y2, g: y2, b: y2, a: 255 };
57124
+ }
57125
+ const [y, cb, cr] = samples;
57126
+ const r = clamp8(y + 1.402 * (cr - 128));
57127
+ const g2 = clamp8(y - 0.344136 * (cb - 128) - 0.714136 * (cr - 128));
57128
+ const b = clamp8(y + 1.772 * (cb - 128));
57129
+ return { r, g: g2, b, a: 255 };
57130
+ }
57131
+ var ZIGZAG;
57132
+ var CORNER_WEIGHTS;
56178
57133
  var init_image_first_pixel_jpeg = __esm({
56179
57134
  "src/core/utils/image-first-pixel-jpeg.ts"() {
56180
57135
  init_image_first_pixel_jpeg_bitstream();
56181
- (() => {
57136
+ ZIGZAG = [
57137
+ 0,
57138
+ 1,
57139
+ 8,
57140
+ 16,
57141
+ 9,
57142
+ 2,
57143
+ 3,
57144
+ 10,
57145
+ 17,
57146
+ 24,
57147
+ 32,
57148
+ 25,
57149
+ 18,
57150
+ 11,
57151
+ 4,
57152
+ 5,
57153
+ 12,
57154
+ 19,
57155
+ 26,
57156
+ 33,
57157
+ 40,
57158
+ 48,
57159
+ 41,
57160
+ 34,
57161
+ 27,
57162
+ 20,
57163
+ 13,
57164
+ 6,
57165
+ 7,
57166
+ 14,
57167
+ 21,
57168
+ 28,
57169
+ 35,
57170
+ 42,
57171
+ 49,
57172
+ 56,
57173
+ 57,
57174
+ 50,
57175
+ 43,
57176
+ 36,
57177
+ 29,
57178
+ 22,
57179
+ 15,
57180
+ 23,
57181
+ 30,
57182
+ 37,
57183
+ 44,
57184
+ 51,
57185
+ 58,
57186
+ 59,
57187
+ 52,
57188
+ 45,
57189
+ 38,
57190
+ 31,
57191
+ 39,
57192
+ 46,
57193
+ 53,
57194
+ 60,
57195
+ 61,
57196
+ 54,
57197
+ 47,
57198
+ 55,
57199
+ 62,
57200
+ 63
57201
+ ];
57202
+ CORNER_WEIGHTS = (() => {
56182
57203
  const weights = [];
56183
57204
  for (let naturalIndex = 0; naturalIndex < 64; naturalIndex++) {
56184
57205
  const row = Math.floor(naturalIndex / 8);
@@ -56189,9 +57210,327 @@ var init_image_first_pixel_jpeg = __esm({
56189
57210
  })();
56190
57211
  }
56191
57212
  });
57213
+ function buildHuffmanTable(lengths) {
57214
+ const maxBits = Math.max(0, ...lengths);
57215
+ const counts = new Uint16Array(maxBits + 1);
57216
+ for (const len of lengths) {
57217
+ if (len > 0) {
57218
+ counts[len]++;
57219
+ }
57220
+ }
57221
+ const offsets = new Uint16Array(maxBits + 2);
57222
+ for (let bits = 1; bits <= maxBits; bits++) {
57223
+ offsets[bits + 1] = offsets[bits] + counts[bits];
57224
+ }
57225
+ const symbols = new Uint16Array(lengths.filter((l) => l > 0).length);
57226
+ for (let symbol = 0; symbol < lengths.length; symbol++) {
57227
+ const len = lengths[symbol];
57228
+ if (len > 0) {
57229
+ symbols[offsets[len]] = symbol;
57230
+ offsets[len]++;
57231
+ }
57232
+ }
57233
+ return { counts, symbols };
57234
+ }
57235
+ function decodeSymbol(reader, table2) {
57236
+ let code = 0;
57237
+ let first = 0;
57238
+ let index = 0;
57239
+ for (let len = 1; len < table2.counts.length; len++) {
57240
+ code |= reader.bits(1);
57241
+ const count = table2.counts[len];
57242
+ if (code - first < count) {
57243
+ return table2.symbols[index + (code - first)];
57244
+ }
57245
+ index += count;
57246
+ first += count;
57247
+ first <<= 1;
57248
+ code <<= 1;
57249
+ }
57250
+ throw new Error("inflate: invalid Huffman code");
57251
+ }
57252
+ function inflateBlock(reader, out, litTable, distTable) {
57253
+ for (; ; ) {
57254
+ if (out.full) {
57255
+ return;
57256
+ }
57257
+ const symbol = decodeSymbol(reader, litTable);
57258
+ if (symbol === 256) {
57259
+ return;
57260
+ }
57261
+ if (symbol < 256) {
57262
+ out.push(symbol);
57263
+ continue;
57264
+ }
57265
+ const lengthIndex = symbol - 257;
57266
+ if (lengthIndex >= LENGTH_BASE.length) {
57267
+ throw new Error("inflate: invalid length symbol");
57268
+ }
57269
+ const length = LENGTH_BASE[lengthIndex] + reader.bits(LENGTH_EXTRA_BITS[lengthIndex]);
57270
+ const distSymbol = decodeSymbol(reader, distTable);
57271
+ if (distSymbol >= DIST_BASE.length) {
57272
+ throw new Error("inflate: invalid distance symbol");
57273
+ }
57274
+ const distance2 = DIST_BASE[distSymbol] + reader.bits(DIST_EXTRA_BITS[distSymbol]);
57275
+ for (let i2 = 0; i2 < length; i2++) {
57276
+ if (out.full) {
57277
+ return;
57278
+ }
57279
+ out.push(out.at(distance2));
57280
+ }
57281
+ }
57282
+ }
57283
+ function readDynamicTables(reader) {
57284
+ const hlit = reader.bits(5) + 257;
57285
+ const hdist = reader.bits(5) + 1;
57286
+ const hclen = reader.bits(4) + 4;
57287
+ const codeLengthLengths = new Array(19).fill(0);
57288
+ for (let i2 = 0; i2 < hclen; i2++) {
57289
+ codeLengthLengths[CODE_LENGTH_ORDER[i2]] = reader.bits(3);
57290
+ }
57291
+ const codeLengthTable = buildHuffmanTable(codeLengthLengths);
57292
+ const allLengths = [];
57293
+ while (allLengths.length < hlit + hdist) {
57294
+ const symbol = decodeSymbol(reader, codeLengthTable);
57295
+ if (symbol < 16) {
57296
+ allLengths.push(symbol);
57297
+ } else if (symbol === 16) {
57298
+ const prev = allLengths[allLengths.length - 1] ?? 0;
57299
+ const repeat = reader.bits(2) + 3;
57300
+ for (let i2 = 0; i2 < repeat; i2++) {
57301
+ allLengths.push(prev);
57302
+ }
57303
+ } else if (symbol === 17) {
57304
+ const repeat = reader.bits(3) + 3;
57305
+ for (let i2 = 0; i2 < repeat; i2++) {
57306
+ allLengths.push(0);
57307
+ }
57308
+ } else {
57309
+ const repeat = reader.bits(7) + 11;
57310
+ for (let i2 = 0; i2 < repeat; i2++) {
57311
+ allLengths.push(0);
57312
+ }
57313
+ }
57314
+ }
57315
+ const litLengths = allLengths.slice(0, hlit);
57316
+ const distLengths = allLengths.slice(hlit, hlit + hdist);
57317
+ return { lit: buildHuffmanTable(litLengths), dist: buildHuffmanTable(distLengths) };
57318
+ }
57319
+ function inflateRaw(data, maxOutputBytes = Infinity) {
57320
+ const reader = new BitReader(data);
57321
+ const out = new OutputSink(maxOutputBytes === Infinity ? 1 << 20 : maxOutputBytes);
57322
+ let final = 0;
57323
+ do {
57324
+ final = reader.bits(1);
57325
+ const type = reader.bits(2);
57326
+ if (out.full) {
57327
+ break;
57328
+ }
57329
+ if (type === 0) {
57330
+ reader.alignToByte();
57331
+ const len = reader.readByte() | reader.readByte() << 8;
57332
+ reader.readByte();
57333
+ reader.readByte();
57334
+ for (let i2 = 0; i2 < len; i2++) {
57335
+ if (out.full) {
57336
+ break;
57337
+ }
57338
+ out.push(reader.readByte());
57339
+ }
57340
+ } else if (type === 1) {
57341
+ const lit = buildHuffmanTable(FIXED_LITERAL_LENGTHS);
57342
+ const dist2 = buildHuffmanTable(FIXED_DIST_LENGTHS);
57343
+ inflateBlock(reader, out, lit, dist2);
57344
+ } else if (type === 2) {
57345
+ const { lit, dist: dist2 } = readDynamicTables(reader);
57346
+ inflateBlock(reader, out, lit, dist2);
57347
+ } else {
57348
+ throw new Error("inflate: invalid block type");
57349
+ }
57350
+ } while (!final && !out.full);
57351
+ return out.toBytes();
57352
+ }
57353
+ function zlibInflate(data, maxOutputBytes = Infinity) {
57354
+ if (data.length < 2) {
57355
+ throw new Error("inflate: truncated zlib stream");
57356
+ }
57357
+ return inflateRaw(data.subarray(2), maxOutputBytes);
57358
+ }
57359
+ var LENGTH_BASE;
57360
+ var LENGTH_EXTRA_BITS;
57361
+ var DIST_BASE;
57362
+ var DIST_EXTRA_BITS;
57363
+ var CODE_LENGTH_ORDER;
57364
+ var BitReader;
57365
+ var FIXED_LITERAL_LENGTHS;
57366
+ var FIXED_DIST_LENGTHS;
57367
+ var OutputSink;
56192
57368
  var init_inflate = __esm({
56193
57369
  "src/core/utils/inflate.ts"() {
56194
- (() => {
57370
+ LENGTH_BASE = [
57371
+ 3,
57372
+ 4,
57373
+ 5,
57374
+ 6,
57375
+ 7,
57376
+ 8,
57377
+ 9,
57378
+ 10,
57379
+ 11,
57380
+ 13,
57381
+ 15,
57382
+ 17,
57383
+ 19,
57384
+ 23,
57385
+ 27,
57386
+ 31,
57387
+ 35,
57388
+ 43,
57389
+ 51,
57390
+ 59,
57391
+ 67,
57392
+ 83,
57393
+ 99,
57394
+ 115,
57395
+ 131,
57396
+ 163,
57397
+ 195,
57398
+ 227,
57399
+ 258
57400
+ ];
57401
+ LENGTH_EXTRA_BITS = [
57402
+ 0,
57403
+ 0,
57404
+ 0,
57405
+ 0,
57406
+ 0,
57407
+ 0,
57408
+ 0,
57409
+ 0,
57410
+ 1,
57411
+ 1,
57412
+ 1,
57413
+ 1,
57414
+ 2,
57415
+ 2,
57416
+ 2,
57417
+ 2,
57418
+ 3,
57419
+ 3,
57420
+ 3,
57421
+ 3,
57422
+ 4,
57423
+ 4,
57424
+ 4,
57425
+ 4,
57426
+ 5,
57427
+ 5,
57428
+ 5,
57429
+ 5,
57430
+ 0
57431
+ ];
57432
+ DIST_BASE = [
57433
+ 1,
57434
+ 2,
57435
+ 3,
57436
+ 4,
57437
+ 5,
57438
+ 7,
57439
+ 9,
57440
+ 13,
57441
+ 17,
57442
+ 25,
57443
+ 33,
57444
+ 49,
57445
+ 65,
57446
+ 97,
57447
+ 129,
57448
+ 193,
57449
+ 257,
57450
+ 385,
57451
+ 513,
57452
+ 769,
57453
+ 1025,
57454
+ 1537,
57455
+ 2049,
57456
+ 3073,
57457
+ 4097,
57458
+ 6145,
57459
+ 8193,
57460
+ 12289,
57461
+ 16385,
57462
+ 24577
57463
+ ];
57464
+ DIST_EXTRA_BITS = [
57465
+ 0,
57466
+ 0,
57467
+ 0,
57468
+ 0,
57469
+ 1,
57470
+ 1,
57471
+ 2,
57472
+ 2,
57473
+ 3,
57474
+ 3,
57475
+ 4,
57476
+ 4,
57477
+ 5,
57478
+ 5,
57479
+ 6,
57480
+ 6,
57481
+ 7,
57482
+ 7,
57483
+ 8,
57484
+ 8,
57485
+ 9,
57486
+ 9,
57487
+ 10,
57488
+ 10,
57489
+ 11,
57490
+ 11,
57491
+ 12,
57492
+ 12,
57493
+ 13,
57494
+ 13
57495
+ ];
57496
+ CODE_LENGTH_ORDER = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
57497
+ BitReader = class {
57498
+ constructor(data) {
57499
+ this.data = data;
57500
+ }
57501
+ data;
57502
+ pos = 0;
57503
+ bitBuf = 0;
57504
+ bitCount = 0;
57505
+ get bytePos() {
57506
+ return this.pos;
57507
+ }
57508
+ bits(count) {
57509
+ while (this.bitCount < count) {
57510
+ if (this.pos >= this.data.length) {
57511
+ throw new Error("inflate: unexpected end of stream");
57512
+ }
57513
+ this.bitBuf |= this.data[this.pos] << this.bitCount;
57514
+ this.pos++;
57515
+ this.bitCount += 8;
57516
+ }
57517
+ const value = this.bitBuf & (1 << count) - 1;
57518
+ this.bitBuf >>>= count;
57519
+ this.bitCount -= count;
57520
+ return value;
57521
+ }
57522
+ alignToByte() {
57523
+ this.bitBuf = 0;
57524
+ this.bitCount = 0;
57525
+ }
57526
+ readByte() {
57527
+ if (this.pos >= this.data.length) {
57528
+ throw new Error("inflate: unexpected end of stream");
57529
+ }
57530
+ return this.data[this.pos++];
57531
+ }
57532
+ };
57533
+ FIXED_LITERAL_LENGTHS = (() => {
56195
57534
  const lengths = new Array(288);
56196
57535
  for (let i2 = 0; i2 < 144; i2++) {
56197
57536
  lengths[i2] = 8;
@@ -56207,14 +57546,251 @@ var init_inflate = __esm({
56207
57546
  }
56208
57547
  return lengths;
56209
57548
  })();
56210
- new Array(30).fill(5);
57549
+ FIXED_DIST_LENGTHS = new Array(30).fill(5);
57550
+ OutputSink = class {
57551
+ constructor(limit) {
57552
+ this.limit = limit;
57553
+ this.buf = new Uint8Array(Math.min(limit, 4096) || 64);
57554
+ }
57555
+ limit;
57556
+ buf;
57557
+ len = 0;
57558
+ get length() {
57559
+ return this.len;
57560
+ }
57561
+ get full() {
57562
+ return this.len >= this.limit;
57563
+ }
57564
+ push(byte) {
57565
+ if (this.len >= this.buf.length) {
57566
+ const next = new Uint8Array(Math.min(this.limit, this.buf.length * 2));
57567
+ next.set(this.buf);
57568
+ this.buf = next;
57569
+ }
57570
+ this.buf[this.len++] = byte;
57571
+ }
57572
+ at(offsetFromEnd) {
57573
+ return this.buf[this.len - offsetFromEnd];
57574
+ }
57575
+ toBytes() {
57576
+ return this.buf.subarray(0, this.len);
57577
+ }
57578
+ };
56211
57579
  }
56212
57580
  });
57581
+ function channelsForColorType(colorType) {
57582
+ switch (colorType) {
57583
+ case 0:
57584
+ return 1;
57585
+ // grayscale
57586
+ case 2:
57587
+ return 3;
57588
+ // truecolor
57589
+ case 3:
57590
+ return 1;
57591
+ // indexed
57592
+ case 4:
57593
+ return 2;
57594
+ // grayscale + alpha
57595
+ case 6:
57596
+ return 4;
57597
+ // truecolor + alpha
57598
+ default:
57599
+ return void 0;
57600
+ }
57601
+ }
57602
+ function hasPngSignature(bytes) {
57603
+ if (bytes.length < 8) {
57604
+ return false;
57605
+ }
57606
+ for (let i2 = 0; i2 < PNG_SIGNATURE2.length; i2++) {
57607
+ if (bytes[i2] !== PNG_SIGNATURE2[i2]) {
57608
+ return false;
57609
+ }
57610
+ }
57611
+ return true;
57612
+ }
57613
+ function readChunks(bytes) {
57614
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
57615
+ let offset = 8;
57616
+ let header;
57617
+ let palette;
57618
+ let transparency;
57619
+ const idatParts = [];
57620
+ let idatTotal = 0;
57621
+ while (offset + 8 <= bytes.length) {
57622
+ const length = view.getUint32(offset, false);
57623
+ const type = String.fromCharCode(
57624
+ bytes[offset + 4],
57625
+ bytes[offset + 5],
57626
+ bytes[offset + 6],
57627
+ bytes[offset + 7]
57628
+ );
57629
+ const dataStart = offset + 8;
57630
+ if (dataStart + length > bytes.length) {
57631
+ break;
57632
+ }
57633
+ const data = bytes.subarray(dataStart, dataStart + length);
57634
+ if (type === "IHDR" && length >= 13) {
57635
+ header = {
57636
+ width: view.getUint32(dataStart, false),
57637
+ height: view.getUint32(dataStart + 4, false),
57638
+ bitDepth: data[8],
57639
+ colorType: data[9]
57640
+ };
57641
+ } else if (type === "PLTE") {
57642
+ palette = data;
57643
+ } else if (type === "tRNS") {
57644
+ transparency = data;
57645
+ } else if (type === "IDAT") {
57646
+ idatParts.push(data);
57647
+ idatTotal += data.length;
57648
+ if (idatTotal > 4096) {
57649
+ break;
57650
+ }
57651
+ } else if (type === "IEND") {
57652
+ break;
57653
+ }
57654
+ offset = dataStart + length + 4;
57655
+ }
57656
+ const idat = new Uint8Array(idatTotal);
57657
+ let pos2 = 0;
57658
+ for (const part of idatParts) {
57659
+ idat.set(part, pos2);
57660
+ pos2 += part.length;
57661
+ }
57662
+ return { header, palette, transparency, idat };
57663
+ }
57664
+ function firstSample(byte, bitDepth) {
57665
+ if (bitDepth >= 8) {
57666
+ return byte;
57667
+ }
57668
+ return byte >> 8 - bitDepth;
57669
+ }
57670
+ function scaleTo8Bit(value, bitDepth) {
57671
+ if (bitDepth === 8) {
57672
+ return value;
57673
+ }
57674
+ if (bitDepth === 16) {
57675
+ return value;
57676
+ }
57677
+ const maxVal = (1 << bitDepth) - 1;
57678
+ return Math.round(value / maxVal * 255);
57679
+ }
57680
+ function decodePngFirstPixel(bytes) {
57681
+ if (!hasPngSignature(bytes)) {
57682
+ return void 0;
57683
+ }
57684
+ const { header, palette, transparency, idat } = readChunks(bytes);
57685
+ if (!header || idat.length === 0) {
57686
+ return void 0;
57687
+ }
57688
+ const channels = channelsForColorType(header.colorType);
57689
+ if (channels === void 0) {
57690
+ return void 0;
57691
+ }
57692
+ const bytesPerSample = header.bitDepth === 16 ? 2 : 1;
57693
+ const neededDataBytes = header.bitDepth < 8 ? 1 : channels * bytesPerSample;
57694
+ let raw;
57695
+ try {
57696
+ raw = zlibInflate(idat, 1 + neededDataBytes);
57697
+ } catch {
57698
+ return void 0;
57699
+ }
57700
+ if (raw.length < 1 + neededDataBytes) {
57701
+ return void 0;
57702
+ }
57703
+ const data = raw.subarray(1);
57704
+ const readSample = (index) => {
57705
+ if (header.bitDepth < 8) {
57706
+ return firstSample(data[0], header.bitDepth);
57707
+ }
57708
+ if (header.bitDepth === 16) {
57709
+ return data[index * 2];
57710
+ }
57711
+ return data[index];
57712
+ };
57713
+ switch (header.colorType) {
57714
+ case 0: {
57715
+ const gray = scaleTo8Bit(readSample(0), header.bitDepth);
57716
+ const isTransparent = transparency && transparency.length >= 2 && readSample(0) === (transparency[1] ?? -1);
57717
+ return { r: gray, g: gray, b: gray, a: isTransparent ? 0 : 255 };
57718
+ }
57719
+ case 2: {
57720
+ const r = scaleTo8Bit(readSample(0), header.bitDepth);
57721
+ const g2 = scaleTo8Bit(readSample(1), header.bitDepth);
57722
+ const b = scaleTo8Bit(readSample(2), header.bitDepth);
57723
+ return { r, g: g2, b, a: 255 };
57724
+ }
57725
+ case 3: {
57726
+ const index = readSample(0);
57727
+ if (!palette || palette.length < (index + 1) * 3) {
57728
+ return void 0;
57729
+ }
57730
+ const alpha = transparency && transparency.length > index ? transparency[index] : 255;
57731
+ return {
57732
+ r: palette[index * 3],
57733
+ g: palette[index * 3 + 1],
57734
+ b: palette[index * 3 + 2],
57735
+ a: alpha
57736
+ };
57737
+ }
57738
+ case 4: {
57739
+ const gray = scaleTo8Bit(readSample(0), header.bitDepth);
57740
+ const alpha = scaleTo8Bit(readSample(1), header.bitDepth);
57741
+ return { r: gray, g: gray, b: gray, a: alpha };
57742
+ }
57743
+ case 6: {
57744
+ const r = scaleTo8Bit(readSample(0), header.bitDepth);
57745
+ const g2 = scaleTo8Bit(readSample(1), header.bitDepth);
57746
+ const b = scaleTo8Bit(readSample(2), header.bitDepth);
57747
+ const a = scaleTo8Bit(readSample(3), header.bitDepth);
57748
+ return { r, g: g2, b, a };
57749
+ }
57750
+ default:
57751
+ return void 0;
57752
+ }
57753
+ }
57754
+ var PNG_SIGNATURE2;
56213
57755
  var init_image_first_pixel_png = __esm({
56214
57756
  "src/core/utils/image-first-pixel-png.ts"() {
56215
57757
  init_inflate();
57758
+ PNG_SIGNATURE2 = [137, 80, 78, 71, 13, 10, 26, 10];
56216
57759
  }
56217
57760
  });
57761
+ function hexChannel(value) {
57762
+ return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
57763
+ }
57764
+ function sniffAndDecode(bytes) {
57765
+ if (bytes.length < 4) {
57766
+ return void 0;
57767
+ }
57768
+ if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71) {
57769
+ return decodePngFirstPixel(bytes);
57770
+ }
57771
+ if (bytes[0] === 255 && bytes[1] === 216) {
57772
+ return decodeJpegFirstPixel(bytes);
57773
+ }
57774
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70) {
57775
+ return decodeGifFirstPixel(bytes);
57776
+ }
57777
+ if (bytes[0] === 66 && bytes[1] === 77) {
57778
+ return decodeBmpFirstPixel(bytes);
57779
+ }
57780
+ return void 0;
57781
+ }
57782
+ function sampleFirstPixelColorFromBytes(bytes) {
57783
+ let pixel;
57784
+ try {
57785
+ pixel = sniffAndDecode(bytes);
57786
+ } catch {
57787
+ return void 0;
57788
+ }
57789
+ if (!pixel || pixel.a === 0) {
57790
+ return void 0;
57791
+ }
57792
+ return `#${hexChannel(pixel.r)}${hexChannel(pixel.g)}${hexChannel(pixel.b)}`;
57793
+ }
56218
57794
  var init_image_first_pixel = __esm({
56219
57795
  "src/core/utils/image-first-pixel.ts"() {
56220
57796
  init_image_first_pixel_bmp();
@@ -56223,30 +57799,532 @@ var init_image_first_pixel = __esm({
56223
57799
  init_image_first_pixel_png();
56224
57800
  }
56225
57801
  });
57802
+ function readFrameAt(bytes, offset) {
57803
+ if (offset + 7 > bytes.length) {
57804
+ return void 0;
57805
+ }
57806
+ if (bytes[offset] !== 255 || (bytes[offset + 1] & 240) !== 240) {
57807
+ return void 0;
57808
+ }
57809
+ const freqIndex = bytes[offset + 2] >> 2 & 15;
57810
+ const sampleRate = SAMPLE_RATES[freqIndex];
57811
+ if (!sampleRate) {
57812
+ return void 0;
57813
+ }
57814
+ const length = (bytes[offset + 3] & 3) << 11 | bytes[offset + 4] << 3 | bytes[offset + 5] >> 5 & 7;
57815
+ if (length < 7) {
57816
+ return void 0;
57817
+ }
57818
+ return { length, sampleRate };
57819
+ }
57820
+ function estimateAdtsDurationMs(bytes) {
57821
+ const first = readFrameAt(bytes, 0);
57822
+ if (!first) {
57823
+ return void 0;
57824
+ }
57825
+ let offset = 0;
57826
+ let frameCount = 0;
57827
+ while (offset < bytes.length) {
57828
+ const frame2 = readFrameAt(bytes, offset);
57829
+ if (!frame2) {
57830
+ break;
57831
+ }
57832
+ frameCount++;
57833
+ offset += frame2.length;
57834
+ }
57835
+ if (frameCount === 0) {
57836
+ return void 0;
57837
+ }
57838
+ return frameCount * 1024 / first.sampleRate * 1e3;
57839
+ }
57840
+ var SAMPLE_RATES;
56226
57841
  var init_media_duration_adts = __esm({
56227
57842
  "src/core/utils/media-duration-adts.ts"() {
57843
+ SAMPLE_RATES = [
57844
+ 96e3,
57845
+ 88200,
57846
+ 64e3,
57847
+ 48e3,
57848
+ 44100,
57849
+ 32e3,
57850
+ 24e3,
57851
+ 22050,
57852
+ 16e3,
57853
+ 12e3,
57854
+ 11025,
57855
+ 8e3,
57856
+ 7350
57857
+ ];
56228
57858
  }
56229
57859
  });
57860
+ function readVInt(bytes, offset, keepMarker) {
57861
+ if (offset >= bytes.length) {
57862
+ return void 0;
57863
+ }
57864
+ const first = bytes[offset];
57865
+ if (first === 0) {
57866
+ return void 0;
57867
+ }
57868
+ let length = 1;
57869
+ let mask = 128;
57870
+ while (length <= 8 && (first & mask) === 0) {
57871
+ mask >>= 1;
57872
+ length++;
57873
+ }
57874
+ if (length > 8 || offset + length > bytes.length) {
57875
+ return void 0;
57876
+ }
57877
+ let value = keepMarker ? first : first & mask - 1;
57878
+ for (let i2 = 1; i2 < length; i2++) {
57879
+ value = value * 256 + bytes[offset + i2];
57880
+ }
57881
+ return { value, length };
57882
+ }
57883
+ function readElementAt(bytes, offset) {
57884
+ const idVint = readVInt(bytes, offset, true);
57885
+ if (!idVint) {
57886
+ return void 0;
57887
+ }
57888
+ const sizeVint = readVInt(bytes, offset + idVint.length, false);
57889
+ if (!sizeVint) {
57890
+ return void 0;
57891
+ }
57892
+ const dataStart = offset + idVint.length + sizeVint.length;
57893
+ const allOnes = 2 ** (7 * sizeVint.length) - 1;
57894
+ const dataEnd = sizeVint.value === allOnes ? bytes.length : dataStart + sizeVint.value;
57895
+ return { id: idVint.value, dataStart, dataEnd: Math.min(dataEnd, bytes.length) };
57896
+ }
57897
+ function findChild2(bytes, start, end, id) {
57898
+ let offset = start;
57899
+ while (offset < end) {
57900
+ const element = readElementAt(bytes, offset);
57901
+ if (!element || element.dataEnd > end || element.dataEnd <= offset) {
57902
+ return void 0;
57903
+ }
57904
+ if (element.id === id) {
57905
+ return element;
57906
+ }
57907
+ offset = element.dataEnd;
57908
+ }
57909
+ return void 0;
57910
+ }
57911
+ function readUint(bytes, start, end) {
57912
+ let value = 0;
57913
+ for (let i2 = start; i2 < end; i2++) {
57914
+ value = value * 256 + bytes[i2];
57915
+ }
57916
+ return value;
57917
+ }
57918
+ function readFloat(bytes, start, end) {
57919
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
57920
+ const length = end - start;
57921
+ if (length === 4) {
57922
+ return view.getFloat32(start, false);
57923
+ }
57924
+ if (length === 8) {
57925
+ return view.getFloat64(start, false);
57926
+ }
57927
+ return void 0;
57928
+ }
57929
+ function estimateEbmlDurationMs(bytes) {
57930
+ const ebml = readElementAt(bytes, 0);
57931
+ if (!ebml || ebml.id !== EBML_ID) {
57932
+ return void 0;
57933
+ }
57934
+ const segment = findChild2(bytes, ebml.dataEnd, bytes.length, SEGMENT_ID);
57935
+ if (!segment) {
57936
+ return void 0;
57937
+ }
57938
+ const info = findChild2(bytes, segment.dataStart, segment.dataEnd, INFO_ID);
57939
+ if (!info) {
57940
+ return void 0;
57941
+ }
57942
+ const durationEl = findChild2(bytes, info.dataStart, info.dataEnd, DURATION_ID);
57943
+ if (!durationEl) {
57944
+ return void 0;
57945
+ }
57946
+ const duration = readFloat(bytes, durationEl.dataStart, durationEl.dataEnd);
57947
+ if (duration === void 0) {
57948
+ return void 0;
57949
+ }
57950
+ const scaleEl = findChild2(bytes, info.dataStart, info.dataEnd, TIMECODE_SCALE_ID);
57951
+ const timecodeScaleNs = scaleEl ? readUint(bytes, scaleEl.dataStart, scaleEl.dataEnd) : 1e6;
57952
+ return duration * timecodeScaleNs / 1e6;
57953
+ }
57954
+ var EBML_ID;
57955
+ var SEGMENT_ID;
57956
+ var INFO_ID;
57957
+ var TIMECODE_SCALE_ID;
57958
+ var DURATION_ID;
56230
57959
  var init_media_duration_ebml = __esm({
56231
57960
  "src/core/utils/media-duration-ebml.ts"() {
57961
+ EBML_ID = 440786851;
57962
+ SEGMENT_ID = 408125543;
57963
+ INFO_ID = 357149030;
57964
+ TIMECODE_SCALE_ID = 2807729;
57965
+ DURATION_ID = 17545;
56232
57966
  }
56233
57967
  });
57968
+ function readBoxes(bytes, rangeStart, rangeEnd) {
57969
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
57970
+ const boxes = [];
57971
+ let offset = rangeStart;
57972
+ while (offset + 8 <= rangeEnd) {
57973
+ const size32 = view.getUint32(offset, false);
57974
+ const type = String.fromCharCode(
57975
+ bytes[offset + 4],
57976
+ bytes[offset + 5],
57977
+ bytes[offset + 6],
57978
+ bytes[offset + 7]
57979
+ );
57980
+ let payloadStart = offset + 8;
57981
+ let boxEnd;
57982
+ if (size32 === 1) {
57983
+ if (offset + 16 > rangeEnd) {
57984
+ break;
57985
+ }
57986
+ const hi = view.getUint32(offset + 8, false);
57987
+ const lo = view.getUint32(offset + 12, false);
57988
+ boxEnd = offset + hi * 2 ** 32 + lo;
57989
+ payloadStart = offset + 16;
57990
+ } else if (size32 === 0) {
57991
+ boxEnd = rangeEnd;
57992
+ } else {
57993
+ boxEnd = offset + size32;
57994
+ }
57995
+ if (boxEnd <= offset || boxEnd > rangeEnd) {
57996
+ break;
57997
+ }
57998
+ boxes.push({ type, start: payloadStart, end: boxEnd });
57999
+ offset = boxEnd;
58000
+ }
58001
+ return boxes;
58002
+ }
58003
+ function findBox(boxes, type) {
58004
+ return boxes.find((b) => b.type === type);
58005
+ }
58006
+ function looksLikeIsoBmff(bytes) {
58007
+ if (bytes.length < 12) {
58008
+ return false;
58009
+ }
58010
+ return bytes[4] === 102 && bytes[5] === 116 && bytes[6] === 121 && bytes[7] === 112;
58011
+ }
58012
+ function estimateIsoBmffDurationMs(bytes) {
58013
+ if (!looksLikeIsoBmff(bytes)) {
58014
+ return void 0;
58015
+ }
58016
+ const top = readBoxes(bytes, 0, bytes.length);
58017
+ const moov = findBox(top, "moov");
58018
+ if (!moov) {
58019
+ return void 0;
58020
+ }
58021
+ const moovChildren = readBoxes(bytes, moov.start, moov.end);
58022
+ const mvhd = findBox(moovChildren, "mvhd");
58023
+ if (!mvhd || mvhd.end - mvhd.start < 1) {
58024
+ return void 0;
58025
+ }
58026
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58027
+ const version = bytes[mvhd.start];
58028
+ let timescale;
58029
+ let duration;
58030
+ if (version === 1) {
58031
+ if (mvhd.start + 32 > mvhd.end) {
58032
+ return void 0;
58033
+ }
58034
+ timescale = view.getUint32(mvhd.start + 20, false);
58035
+ const hi = view.getUint32(mvhd.start + 24, false);
58036
+ const lo = view.getUint32(mvhd.start + 28, false);
58037
+ duration = hi * 2 ** 32 + lo;
58038
+ } else {
58039
+ if (mvhd.start + 20 > mvhd.end) {
58040
+ return void 0;
58041
+ }
58042
+ timescale = view.getUint32(mvhd.start + 12, false);
58043
+ duration = view.getUint32(mvhd.start + 16, false);
58044
+ }
58045
+ if (!timescale) {
58046
+ return void 0;
58047
+ }
58048
+ return duration / timescale * 1e3;
58049
+ }
56234
58050
  var init_media_duration_isobmff = __esm({
56235
58051
  "src/core/utils/media-duration-isobmff.ts"() {
56236
58052
  }
56237
58053
  });
58054
+ function skipId3v2(bytes) {
58055
+ if (bytes.length < 10 || bytes[0] !== 73 || bytes[1] !== 68 || bytes[2] !== 51) {
58056
+ return 0;
58057
+ }
58058
+ const size = (bytes[6] & 127) * 2097152 + (bytes[7] & 127) * 16384 + (bytes[8] & 127) * 128 + (bytes[9] & 127);
58059
+ return 10 + size;
58060
+ }
58061
+ function findFirstFrame(bytes, start) {
58062
+ for (let i2 = start; i2 + 4 <= bytes.length; i2++) {
58063
+ if (bytes[i2] !== 255 || (bytes[i2 + 1] & 224) !== 224) {
58064
+ continue;
58065
+ }
58066
+ const b1 = bytes[i2 + 1];
58067
+ const b2 = bytes[i2 + 2];
58068
+ const b3 = bytes[i2 + 3];
58069
+ const versionId = b1 >> 3 & 3;
58070
+ const layerId = b1 >> 1 & 3;
58071
+ if (versionId === 1 || layerId !== 1) {
58072
+ continue;
58073
+ }
58074
+ const bitrateIndex = b2 >> 4 & 15;
58075
+ const sampleRateIndex = b2 >> 2 & 3;
58076
+ if (bitrateIndex === 0 || bitrateIndex === 15 || sampleRateIndex === 3) {
58077
+ continue;
58078
+ }
58079
+ const table2 = versionId === 3 ? BITRATE_TABLE["1-3"] : BITRATE_TABLE["2-3"];
58080
+ const bitrateKbps = table2[bitrateIndex];
58081
+ const sampleRate = SAMPLE_RATE_TABLE[versionId]?.[sampleRateIndex];
58082
+ if (!sampleRate) {
58083
+ continue;
58084
+ }
58085
+ const padding = b2 >> 1 & 1;
58086
+ const channelMode = b3 >> 6 & 3;
58087
+ const samplesPerFrame = versionId === 3 ? 1152 : 576;
58088
+ const frameLength = Math.floor(samplesPerFrame / 8 * (bitrateKbps * 1e3)) / sampleRate + padding;
58089
+ return {
58090
+ offset: i2,
58091
+ versionId,
58092
+ bitrateKbps,
58093
+ sampleRate,
58094
+ channelMode,
58095
+ padding,
58096
+ frameLength: Math.floor(frameLength)
58097
+ };
58098
+ }
58099
+ return void 0;
58100
+ }
58101
+ function readXingFrameCount(bytes, frame2) {
58102
+ const sideInfoSize = frame2.versionId === 3 ? frame2.channelMode === 3 ? 17 : 32 : frame2.channelMode === 3 ? 9 : 17;
58103
+ const tagStart = frame2.offset + 4 + sideInfoSize;
58104
+ if (tagStart + 8 > bytes.length) {
58105
+ return void 0;
58106
+ }
58107
+ const tag = String.fromCharCode(
58108
+ bytes[tagStart],
58109
+ bytes[tagStart + 1],
58110
+ bytes[tagStart + 2],
58111
+ bytes[tagStart + 3]
58112
+ );
58113
+ if (tag !== "Xing" && tag !== "Info") {
58114
+ return void 0;
58115
+ }
58116
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58117
+ const flags = view.getUint32(tagStart + 4, false);
58118
+ if ((flags & 1) === 0) {
58119
+ return void 0;
58120
+ }
58121
+ return view.getUint32(tagStart + 8, false);
58122
+ }
58123
+ function readVbriFrameCount(bytes, frame2) {
58124
+ const tagStart = frame2.offset + 4 + 32;
58125
+ if (tagStart + 14 > bytes.length) {
58126
+ return void 0;
58127
+ }
58128
+ const tag = String.fromCharCode(
58129
+ bytes[tagStart],
58130
+ bytes[tagStart + 1],
58131
+ bytes[tagStart + 2],
58132
+ bytes[tagStart + 3]
58133
+ );
58134
+ if (tag !== "VBRI") {
58135
+ return void 0;
58136
+ }
58137
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58138
+ return view.getUint32(tagStart + 14, false);
58139
+ }
58140
+ function estimateMp3DurationMs(bytes) {
58141
+ const start = skipId3v2(bytes);
58142
+ const frame2 = findFirstFrame(bytes, start);
58143
+ if (!frame2) {
58144
+ return void 0;
58145
+ }
58146
+ const samplesPerFrame = frame2.versionId === 3 ? 1152 : 576;
58147
+ const xingFrames = readXingFrameCount(bytes, frame2);
58148
+ if (xingFrames !== void 0) {
58149
+ return xingFrames * samplesPerFrame / frame2.sampleRate * 1e3;
58150
+ }
58151
+ const vbriFrames = readVbriFrameCount(bytes, frame2);
58152
+ if (vbriFrames !== void 0) {
58153
+ return vbriFrames * samplesPerFrame / frame2.sampleRate * 1e3;
58154
+ }
58155
+ const audioBytes = bytes.length - frame2.offset;
58156
+ if (frame2.bitrateKbps <= 0) {
58157
+ return void 0;
58158
+ }
58159
+ return audioBytes * 8 / (frame2.bitrateKbps * 1e3) * 1e3;
58160
+ }
58161
+ var BITRATE_TABLE;
58162
+ var SAMPLE_RATE_TABLE;
56238
58163
  var init_media_duration_mp3 = __esm({
56239
58164
  "src/core/utils/media-duration-mp3.ts"() {
58165
+ BITRATE_TABLE = {
58166
+ // MPEG version 1, Layer III (kbps), index 0 = "free", 15 = "bad".
58167
+ "1-3": [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0],
58168
+ // MPEG version 2/2.5, Layer III.
58169
+ "2-3": [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0]
58170
+ };
58171
+ SAMPLE_RATE_TABLE = {
58172
+ 0: [11025, 12e3, 8e3],
58173
+ // MPEG 2.5
58174
+ 2: [22050, 24e3, 16e3],
58175
+ // MPEG 2
58176
+ 3: [44100, 48e3, 32e3]
58177
+ // MPEG 1
58178
+ };
56240
58179
  }
56241
58180
  });
58181
+ function matchesAt(bytes, offset, pattern) {
58182
+ if (offset + pattern.length > bytes.length) {
58183
+ return false;
58184
+ }
58185
+ for (let i2 = 0; i2 < pattern.length; i2++) {
58186
+ if (bytes[offset + i2] !== pattern[i2]) {
58187
+ return false;
58188
+ }
58189
+ }
58190
+ return true;
58191
+ }
58192
+ function readPageAt(bytes, offset) {
58193
+ if (!matchesAt(bytes, offset, OGG_CAPTURE)) {
58194
+ return void 0;
58195
+ }
58196
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58197
+ const lo = view.getUint32(offset + 6, true);
58198
+ const hi = view.getUint32(offset + 10, true);
58199
+ const granulePosition = hi * 2 ** 32 + lo;
58200
+ const pageSegments = bytes[offset + 26];
58201
+ const segmentTableStart = offset + 27;
58202
+ let dataLength = 0;
58203
+ for (let i2 = 0; i2 < pageSegments; i2++) {
58204
+ dataLength += bytes[segmentTableStart + i2];
58205
+ }
58206
+ const dataStart = segmentTableStart + pageSegments;
58207
+ return { granulePosition, dataStart, dataEnd: dataStart + dataLength };
58208
+ }
58209
+ function detectCodecSampleRate(bytes, page) {
58210
+ const start = page.dataStart;
58211
+ if (matchesAt(bytes, start, [79, 112, 117, 115, 72, 101, 97, 100])) {
58212
+ return { opus: true, sampleRate: 48e3 };
58213
+ }
58214
+ if (matchesAt(bytes, start + 1, [118, 111, 114, 98, 105, 115])) {
58215
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58216
+ const sampleRate = view.getUint32(start + 1 + 6 + 4 + 1, true);
58217
+ return { opus: false, sampleRate };
58218
+ }
58219
+ return void 0;
58220
+ }
58221
+ function estimateOggDurationMs(bytes) {
58222
+ if (!matchesAt(bytes, 0, OGG_CAPTURE)) {
58223
+ return void 0;
58224
+ }
58225
+ const firstPage = readPageAt(bytes, 0);
58226
+ if (!firstPage) {
58227
+ return void 0;
58228
+ }
58229
+ const codec = detectCodecSampleRate(bytes, firstPage);
58230
+ if (!codec || !codec.sampleRate) {
58231
+ return void 0;
58232
+ }
58233
+ let lastPageOffset;
58234
+ for (let i2 = bytes.length - OGG_CAPTURE.length; i2 >= 0; i2--) {
58235
+ if (matchesAt(bytes, i2, OGG_CAPTURE)) {
58236
+ lastPageOffset = i2;
58237
+ break;
58238
+ }
58239
+ }
58240
+ if (lastPageOffset === void 0) {
58241
+ return void 0;
58242
+ }
58243
+ const lastPage = readPageAt(bytes, lastPageOffset);
58244
+ if (!lastPage || lastPage.granulePosition <= 0) {
58245
+ return void 0;
58246
+ }
58247
+ return lastPage.granulePosition / codec.sampleRate * 1e3;
58248
+ }
58249
+ var OGG_CAPTURE;
56242
58250
  var init_media_duration_ogg = __esm({
56243
58251
  "src/core/utils/media-duration-ogg.ts"() {
58252
+ OGG_CAPTURE = [79, 103, 103, 83];
56244
58253
  }
56245
58254
  });
58255
+ function estimateWavDurationMs(bytes) {
58256
+ if (bytes.length < 12) {
58257
+ return void 0;
58258
+ }
58259
+ const isRiff = bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70;
58260
+ const isWave = bytes[8] === 87 && bytes[9] === 65 && bytes[10] === 86 && bytes[11] === 69;
58261
+ if (!isRiff || !isWave) {
58262
+ return void 0;
58263
+ }
58264
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
58265
+ let offset = 12;
58266
+ let byteRate;
58267
+ let dataSize;
58268
+ while (offset + 8 <= bytes.length) {
58269
+ const id = String.fromCharCode(
58270
+ bytes[offset],
58271
+ bytes[offset + 1],
58272
+ bytes[offset + 2],
58273
+ bytes[offset + 3]
58274
+ );
58275
+ const size = view.getUint32(offset + 4, true);
58276
+ const dataStart = offset + 8;
58277
+ if (id === "fmt " && dataStart + 16 <= bytes.length) {
58278
+ byteRate = view.getUint32(dataStart + 8, true);
58279
+ } else if (id === "data") {
58280
+ dataSize = size;
58281
+ }
58282
+ if (byteRate !== void 0 && dataSize !== void 0) {
58283
+ break;
58284
+ }
58285
+ offset = dataStart + size + size % 2;
58286
+ }
58287
+ if (!byteRate || dataSize === void 0) {
58288
+ return void 0;
58289
+ }
58290
+ return dataSize / byteRate * 1e3;
58291
+ }
56246
58292
  var init_media_duration_wav = __esm({
56247
58293
  "src/core/utils/media-duration-wav.ts"() {
56248
58294
  }
56249
58295
  });
58296
+ function estimateMediaDurationMs(bytes) {
58297
+ if (bytes.length < 4) {
58298
+ return void 0;
58299
+ }
58300
+ try {
58301
+ if (bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70) {
58302
+ return estimateWavDurationMs(bytes);
58303
+ }
58304
+ if (bytes[0] === 79 && bytes[1] === 103 && bytes[2] === 103 && bytes[3] === 83) {
58305
+ return estimateOggDurationMs(bytes);
58306
+ }
58307
+ if (bytes[0] === 26 && bytes[1] === 69 && bytes[2] === 223 && bytes[3] === 163) {
58308
+ return estimateEbmlDurationMs(bytes);
58309
+ }
58310
+ if (looksLikeIsoBmff(bytes)) {
58311
+ return estimateIsoBmffDurationMs(bytes);
58312
+ }
58313
+ if (bytes[0] === 73 && bytes[1] === 68 && bytes[2] === 51) {
58314
+ return estimateMp3DurationMs(bytes);
58315
+ }
58316
+ if (bytes[0] === 255 && (bytes[1] & 224) === 224) {
58317
+ const mp3 = estimateMp3DurationMs(bytes);
58318
+ if (mp3 !== void 0) {
58319
+ return mp3;
58320
+ }
58321
+ return estimateAdtsDurationMs(bytes);
58322
+ }
58323
+ return void 0;
58324
+ } catch {
58325
+ return void 0;
58326
+ }
58327
+ }
56250
58328
  var init_media_duration = __esm({
56251
58329
  "src/core/utils/media-duration.ts"() {
56252
58330
  init_media_duration_adts();
@@ -64639,7 +66717,7 @@ var init_PptxTableDataParser = __esm({
64639
66717
  const xmlRows = this.context.ensureArray(tableNode["a:tr"]);
64640
66718
  const rows = xmlRows.map((rowNode) => {
64641
66719
  const rowHeightEmu = parseInt(String(rowNode?.["@_h"] || "0"), 10) || 0;
64642
- const rowHeight = Math.round(rowHeightEmu / this.context.emuPerPx);
66720
+ const rowHeight = rowHeightEmu / this.context.emuPerPx;
64643
66721
  const xmlCells = this.context.ensureArray(rowNode["a:tc"]);
64644
66722
  return {
64645
66723
  height: rowHeight,
@@ -65449,15 +67527,15 @@ function readPositiveInteger(value) {
65449
67527
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
65450
67528
  }
65451
67529
  function getTableGridExtent(graphicData) {
65452
- const table = graphicData?.["a:tbl"];
65453
- if (!table) {
67530
+ const table2 = graphicData?.["a:tbl"];
67531
+ if (!table2) {
65454
67532
  return void 0;
65455
67533
  }
65456
- const grid = table["a:tblGrid"];
67534
+ const grid = table2["a:tblGrid"];
65457
67535
  const widthEmu = ensureArrayLike2(
65458
67536
  grid?.["a:gridCol"]
65459
67537
  ).reduce((sum, column) => sum + readPositiveInteger(column?.["@_w"]), 0);
65460
- const heightEmu = ensureArrayLike2(table["a:tr"]).reduce(
67538
+ const heightEmu = ensureArrayLike2(table2["a:tr"]).reduce(
65461
67539
  (sum, row) => sum + readPositiveInteger(row?.["@_h"]),
65462
67540
  0
65463
67541
  );
@@ -69808,6 +71886,139 @@ var init_animation_timeline_anchors = __esm({
69808
71886
  init_animation_timing_ownership();
69809
71887
  }
69810
71888
  });
71889
+ function patchMediaCallDuration(animations, rawShapeId, realMs, remap) {
71890
+ const roundedReal = Math.round(realMs);
71891
+ for (const anim of animations) {
71892
+ if (anim.kind === "media" || anim.targetId !== rawShapeId) {
71893
+ continue;
71894
+ }
71895
+ const oldMs = anim.durationMs;
71896
+ if (oldMs === void 0 || oldMs <= 0 || oldMs === roundedReal) {
71897
+ continue;
71898
+ }
71899
+ anim.durationMs = roundedReal;
71900
+ const existing = remap.get(oldMs);
71901
+ if (existing === void 0) {
71902
+ remap.set(oldMs, roundedReal);
71903
+ } else if (existing !== roundedReal) {
71904
+ remap.delete(oldMs);
71905
+ }
71906
+ }
71907
+ }
71908
+ function applyPlainDelayRemap(animations, remap) {
71909
+ if (remap.size === 0) {
71910
+ return;
71911
+ }
71912
+ for (const anim of animations) {
71913
+ if (anim.parGroupDelayMs !== void 0) {
71914
+ const real = remap.get(anim.parGroupDelayMs);
71915
+ if (real !== void 0) {
71916
+ anim.parGroupDelayMs = real;
71917
+ }
71918
+ }
71919
+ for (const conditions of [anim.startConditions, anim.endConditions]) {
71920
+ if (!conditions) {
71921
+ continue;
71922
+ }
71923
+ for (const cond of conditions) {
71924
+ if (cond.event !== void 0 || cond.targetTimeNodeId !== void 0 || cond.targetShapeId !== void 0 || typeof cond.delay !== "number" || cond.delay <= 0) {
71925
+ continue;
71926
+ }
71927
+ const real = remap.get(cond.delay);
71928
+ if (real !== void 0) {
71929
+ cond.delay = real;
71930
+ }
71931
+ }
71932
+ }
71933
+ }
71934
+ }
71935
+ var init_native_animation_media_duration_plain_delay = __esm({
71936
+ "src/core/services/native-animation-media-duration-plain-delay.ts"() {
71937
+ }
71938
+ });
71939
+ function isMediaElement(el) {
71940
+ return el.type === "media";
71941
+ }
71942
+ function collectMediaElementsByRawId(elements2) {
71943
+ const map = /* @__PURE__ */ new Map();
71944
+ const walk2 = (els) => {
71945
+ for (const el of els) {
71946
+ if (isMediaElement(el) && el.mediaPath) {
71947
+ const rawId = readCnvPrId(el.rawXml);
71948
+ if (rawId) {
71949
+ map.set(rawId, el);
71950
+ }
71951
+ }
71952
+ if (el.type === "group" && Array.isArray(el.children)) {
71953
+ walk2(el.children);
71954
+ }
71955
+ }
71956
+ };
71957
+ walk2(elements2);
71958
+ return map;
71959
+ }
71960
+ function patchOnStopAudioConditions(animations, nodeId, rawShapeId, realMs) {
71961
+ for (const anim of animations) {
71962
+ for (const conditions of [anim.startConditions, anim.endConditions]) {
71963
+ if (!conditions) {
71964
+ continue;
71965
+ }
71966
+ for (const cond of conditions) {
71967
+ if (cond.event !== "onStopAudio") {
71968
+ continue;
71969
+ }
71970
+ const namesThisNode = nodeId !== void 0 && cond.targetTimeNodeId === nodeId || cond.targetShapeId === rawShapeId;
71971
+ if (namesThisNode) {
71972
+ cond.delay = Math.round(realMs);
71973
+ }
71974
+ }
71975
+ }
71976
+ }
71977
+ }
71978
+ async function attachRealMediaDurations(elements2, nativeAnimations, readBytes) {
71979
+ if (!nativeAnimations || nativeAnimations.length === 0) {
71980
+ return;
71981
+ }
71982
+ const mediaByRawId = collectMediaElementsByRawId(elements2);
71983
+ if (mediaByRawId.size === 0) {
71984
+ return;
71985
+ }
71986
+ const plainDelayRemap = /* @__PURE__ */ new Map();
71987
+ for (const anim of nativeAnimations) {
71988
+ if (anim.kind !== "media" || anim.targetId === void 0) {
71989
+ continue;
71990
+ }
71991
+ const element = mediaByRawId.get(anim.targetId);
71992
+ if (!element?.mediaPath) {
71993
+ continue;
71994
+ }
71995
+ let bytes;
71996
+ try {
71997
+ bytes = await readBytes(element.mediaPath);
71998
+ } catch {
71999
+ continue;
72000
+ }
72001
+ if (!bytes) {
72002
+ continue;
72003
+ }
72004
+ const realMs = estimateMediaDurationMs(bytes);
72005
+ if (realMs === void 0 || !Number.isFinite(realMs) || realMs <= 0) {
72006
+ continue;
72007
+ }
72008
+ anim.durationMs = Math.round(realMs);
72009
+ element.metadata = { ...element.metadata, duration: realMs / 1e3 };
72010
+ patchOnStopAudioConditions(nativeAnimations, anim.nodeId, anim.targetId, realMs);
72011
+ patchMediaCallDuration(nativeAnimations, anim.targetId, realMs, plainDelayRemap);
72012
+ }
72013
+ applyPlainDelayRemap(nativeAnimations, plainDelayRemap);
72014
+ }
72015
+ var init_native_animation_media_duration = __esm({
72016
+ "src/core/services/native-animation-media-duration.ts"() {
72017
+ init_media_duration();
72018
+ init_animation_target_reconcile();
72019
+ init_native_animation_media_duration_plain_delay();
72020
+ }
72021
+ });
69811
72022
  function asNode3(value) {
69812
72023
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
69813
72024
  }
@@ -69848,6 +72059,7 @@ var init_PptxSlideLoaderService = __esm({
69848
72059
  init_animation_sound_merge();
69849
72060
  init_animation_target_reconcile();
69850
72061
  init_animation_timeline_anchors();
72062
+ init_native_animation_media_duration();
69851
72063
  init_slide_name();
69852
72064
  PptxSlideLoaderService = class {
69853
72065
  /**
@@ -70039,6 +72251,17 @@ var init_PptxSlideLoaderService = __esm({
70039
72251
  animations = timeline.animations;
70040
72252
  animationTimelineAnchors = timeline.anchors.length > 0 ? timeline.anchors : void 0;
70041
72253
  }
72254
+ await attachRealMediaDurations(elements2, nativeAnimations, async (mediaPath) => {
72255
+ const file = params.zip.file(mediaPath);
72256
+ if (!file) {
72257
+ return void 0;
72258
+ }
72259
+ try {
72260
+ return await file.async("uint8array");
72261
+ } catch {
72262
+ return void 0;
72263
+ }
72264
+ });
70042
72265
  reconcileAnimationTargets(elements2, nativeAnimations, animations, animationTimelineAnchors);
70043
72266
  mergeNativeSoundIntoEditorAnimations(nativeAnimations, animations);
70044
72267
  mergeNativeBuildTemplatesIntoEditorAnimations(nativeAnimations, animations);
@@ -83078,28 +85301,28 @@ function applyChartDataTable(plotArea, dataTable, localName28, resolveColor2) {
83078
85301
  }
83079
85302
  return;
83080
85303
  }
83081
- const table = {
85304
+ const table2 = {
83082
85305
  ...tableKey ? plotArea[tableKey] : void 0
83083
85306
  };
83084
85307
  for (const flag of FLAGS2) {
83085
85308
  const value = dataTable[flag];
83086
85309
  if (value !== void 0) {
83087
- setOrdered4(table, flag, { "@_val": value ? "1" : "0" }, TABLE_ORDER, localName28);
85310
+ setOrdered4(table2, flag, { "@_val": value ? "1" : "0" }, TABLE_ORDER, localName28);
83088
85311
  }
83089
85312
  }
83090
85313
  if (dataTable.spPr) {
83091
- const spPrKey = findKey14(table, "spPr", localName28);
85314
+ const spPrKey = findKey14(table2, "spPr", localName28);
83092
85315
  const spPr = writeChartShapeProps(
83093
- spPrKey ? table[spPrKey] : void 0,
85316
+ spPrKey ? table2[spPrKey] : void 0,
83094
85317
  dataTable.spPr,
83095
85318
  localName28,
83096
85319
  resolveColor2
83097
85320
  );
83098
- setOrdered4(table, "spPr", spPr, TABLE_ORDER, localName28);
85321
+ setOrdered4(table2, "spPr", spPr, TABLE_ORDER, localName28);
83099
85322
  }
83100
85323
  if (dataTable.txPr) {
83101
- const txPrKey = findKey14(table, "txPr", localName28);
83102
- const authoredDefRPr = resolveTxPrDefRPr(txPrKey ? table[txPrKey] : void 0, {
85324
+ const txPrKey = findKey14(table2, "txPr", localName28);
85325
+ const authoredDefRPr = resolveTxPrDefRPr(txPrKey ? table2[txPrKey] : void 0, {
83103
85326
  getChildByLocalName: (parent, name) => {
83104
85327
  if (!parent) {
83105
85328
  return void 0;
@@ -83110,13 +85333,13 @@ function applyChartDataTable(plotArea, dataTable, localName28, resolveColor2) {
83110
85333
  });
83111
85334
  const txPr = buildDefRPrTextProperties(dataTable.txPr, authoredDefRPr, resolveColor2);
83112
85335
  if (txPr) {
83113
- setOrdered4(table, "txPr", txPr, TABLE_ORDER, localName28);
85336
+ setOrdered4(table2, "txPr", txPr, TABLE_ORDER, localName28);
83114
85337
  }
83115
85338
  }
83116
85339
  if (tableKey) {
83117
- plotArea[tableKey] = table;
85340
+ plotArea[tableKey] = table2;
83118
85341
  } else {
83119
- setOrdered4(plotArea, "dTable", table, PLOT_AREA_ORDER, localName28);
85342
+ setOrdered4(plotArea, "dTable", table2, PLOT_AREA_ORDER, localName28);
83120
85343
  }
83121
85344
  }
83122
85345
  var TABLE_ORDER;
@@ -89103,10 +91326,10 @@ function buildImageEffectsFilter(effects, idSuffix) {
89103
91326
  }
89104
91327
  if (typeof effects.biLevel === "number") {
89105
91328
  next("p6a", `<feColorMatrix in="__IN__" type="saturate" values="0" result="__OUT__"/>`);
89106
- const table = biLevelTable(effects.biLevel);
91329
+ const table2 = biLevelTable(effects.biLevel);
89107
91330
  next(
89108
91331
  "p6b",
89109
- `<feComponentTransfer in="__IN__" result="__OUT__"><feFuncR type="discrete" tableValues="${table}"/><feFuncG type="discrete" tableValues="${table}"/><feFuncB type="discrete" tableValues="${table}"/></feComponentTransfer>`
91332
+ `<feComponentTransfer in="__IN__" result="__OUT__"><feFuncR type="discrete" tableValues="${table2}"/><feFuncG type="discrete" tableValues="${table2}"/><feFuncB type="discrete" tableValues="${table2}"/></feComponentTransfer>`
89110
91333
  );
89111
91334
  }
89112
91335
  if (effects.duotone) {
@@ -96978,11 +99201,11 @@ function updateCellTextInRawXml(element, rowIndex, colIndex, text22) {
96978
99201
  return void 0;
96979
99202
  }
96980
99203
  const newRawXml = structuredClone(element.rawXml);
96981
- const table = getTblFromRawXml(newRawXml);
96982
- if (!table) {
99204
+ const table2 = getTblFromRawXml(newRawXml);
99205
+ if (!table2) {
96983
99206
  return void 0;
96984
99207
  }
96985
- const rows = ensureArray19(table["a:tr"]);
99208
+ const rows = ensureArray19(table2["a:tr"]);
96986
99209
  if (rowIndex < 0 || rowIndex >= rows.length) {
96987
99210
  return void 0;
96988
99211
  }
@@ -97028,11 +99251,11 @@ function updateCellTextStyleInRawXml(element, rowIndex, colIndex, styleUpdates)
97028
99251
  return void 0;
97029
99252
  }
97030
99253
  const newRawXml = structuredClone(element.rawXml);
97031
- const table = getTblFromRawXml(newRawXml);
97032
- if (!table) {
99254
+ const table2 = getTblFromRawXml(newRawXml);
99255
+ if (!table2) {
97033
99256
  return void 0;
97034
99257
  }
97035
- const rows = ensureArray19(table["a:tr"]);
99258
+ const rows = ensureArray19(table2["a:tr"]);
97036
99259
  if (rowIndex < 0 || rowIndex >= rows.length) {
97037
99260
  return void 0;
97038
99261
  }
@@ -97130,11 +99353,11 @@ function updateMergeAttrsInRawXml(element, tableData) {
97130
99353
  return void 0;
97131
99354
  }
97132
99355
  const newRawXml = structuredClone(element.rawXml);
97133
- const table = getTblFromRawXml(newRawXml);
97134
- if (!table) {
99356
+ const table2 = getTblFromRawXml(newRawXml);
99357
+ if (!table2) {
97135
99358
  return void 0;
97136
99359
  }
97137
- const xmlRows = ensureArray19(table["a:tr"]);
99360
+ const xmlRows = ensureArray19(table2["a:tr"]);
97138
99361
  for (let rIdx = 0; rIdx < Math.min(tableData.rows.length, xmlRows.length); rIdx++) {
97139
99362
  const dataRow = tableData.rows[rIdx];
97140
99363
  const xmlCells = ensureArray19(xmlRows[rIdx]["a:tc"]);
@@ -97188,12 +99411,12 @@ function rebuildTableStructureInRawXml(element, tableData) {
97188
99411
  return void 0;
97189
99412
  }
97190
99413
  const newRawXml = structuredClone(element.rawXml);
97191
- const table = getTblFromRawXml(newRawXml);
97192
- if (!table) {
99414
+ const table2 = getTblFromRawXml(newRawXml);
99415
+ if (!table2) {
97193
99416
  return void 0;
97194
99417
  }
97195
99418
  const existingGridCols = ensureArray19(
97196
- table["a:tblGrid"]?.["a:gridCol"]
99419
+ table2["a:tblGrid"]?.["a:gridCol"]
97197
99420
  );
97198
99421
  const totalWidthEmu = existingGridCols.reduce((sum, col) => {
97199
99422
  return sum + (parseInt(String(col?.["@_w"] || "0"), 10) || 0);
@@ -97201,11 +99424,11 @@ function rebuildTableStructureInRawXml(element, tableData) {
97201
99424
  const newGridCols = tableData.columnWidths.map((w) => ({
97202
99425
  "@_w": String(Math.round(w * totalWidthEmu))
97203
99426
  }));
97204
- if (!table["a:tblGrid"]) {
97205
- table["a:tblGrid"] = {};
99427
+ if (!table2["a:tblGrid"]) {
99428
+ table2["a:tblGrid"] = {};
97206
99429
  }
97207
- table["a:tblGrid"]["a:gridCol"] = newGridCols.length === 1 ? newGridCols[0] : newGridCols;
97208
- const existingXmlRows = ensureArray19(table["a:tr"]);
99430
+ table2["a:tblGrid"]["a:gridCol"] = newGridCols.length === 1 ? newGridCols[0] : newGridCols;
99431
+ const existingXmlRows = ensureArray19(table2["a:tr"]);
97209
99432
  const newXmlRows = tableData.rows.map((dataRow, ri) => {
97210
99433
  const existingRow = ri < existingXmlRows.length ? existingXmlRows[ri] : void 0;
97211
99434
  const existingCells = existingRow ? ensureArray19(existingRow["a:tc"]) : [];
@@ -97244,7 +99467,7 @@ function rebuildTableStructureInRawXml(element, tableData) {
97244
99467
  "a:tc": newXmlCells.length === 1 ? newXmlCells[0] : newXmlCells
97245
99468
  };
97246
99469
  });
97247
- table["a:tr"] = newXmlRows.length === 1 ? newXmlRows[0] : newXmlRows;
99470
+ table2["a:tr"] = newXmlRows.length === 1 ? newXmlRows[0] : newXmlRows;
97248
99471
  return newRawXml;
97249
99472
  }
97250
99473
  var init_table_cell_rawxml_ops = __esm({
@@ -136085,8 +138308,8 @@ function applyTableCellImagePatches(elements, resolvedMap, refs) {
136085
138308
  if (!cellPatches || el.type !== "table") {
136086
138309
  return el;
136087
138310
  }
136088
- const table = el;
136089
- const tableData = table.tableData;
138311
+ const table2 = el;
138312
+ const tableData = table2.tableData;
136090
138313
  if (!tableData) {
136091
138314
  return el;
136092
138315
  }
@@ -136107,7 +138330,7 @@ function applyTableCellImagePatches(elements, resolvedMap, refs) {
136107
138330
  });
136108
138331
  return { ...row, cells: newCells };
136109
138332
  });
136110
- return { ...table, tableData: { ...tableData, rows: newRows } };
138333
+ return { ...table2, tableData: { ...tableData, rows: newRows } };
136111
138334
  });
136112
138335
  }
136113
138336
  function buildInitialGuides(presentationGuides, firstSlideGuides) {
@@ -139332,9 +141555,9 @@ function buildImageAlphaFilterMarkup(effects) {
139332
141555
  }
139333
141556
  if (typeof effects.alphaBiLevel === "number") {
139334
141557
  const t = clamp32(effects.alphaBiLevel / 100, 0, 1);
139335
- const table = Array.from({ length: 10 }, (_, i2) => i2 / 10 >= t ? "1" : "0").join(" ");
141558
+ const table2 = Array.from({ length: 10 }, (_, i2) => i2 / 10 >= t ? "1" : "0").join(" ");
139336
141559
  next(
139337
- (inp, out) => `<feComponentTransfer in="${inp}" result="${out}"><feFuncA type="discrete" tableValues="${table}"/></feComponentTransfer>`
141560
+ (inp, out) => `<feComponentTransfer in="${inp}" result="${out}"><feFuncA type="discrete" tableValues="${table2}"/></feComponentTransfer>`
139338
141561
  );
139339
141562
  }
139340
141563
  if (typeof effects.biLevel === "number") {
@@ -143448,7 +145671,7 @@ function notifyBarFacePicturePixelListeners() {
143448
145671
  function getBarFacePicturePixelSampleVersion() {
143449
145672
  return sampleVersion;
143450
145673
  }
143451
- function hexChannel(value) {
145674
+ function hexChannel2(value) {
143452
145675
  return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
143453
145676
  }
143454
145677
  function decodeFirstPixelColor(imageUrl) {
@@ -143470,7 +145693,7 @@ function decodeFirstPixelColor(imageUrl) {
143470
145693
  }
143471
145694
  ctx.drawImage(img, 0, 0, 1, 1, 0, 0, 1, 1);
143472
145695
  const [r, g2, b, a] = ctx.getImageData(0, 0, 1, 1).data;
143473
- resolve2(a === 0 ? void 0 : `#${hexChannel(r)}${hexChannel(g2)}${hexChannel(b)}`);
145696
+ resolve2(a === 0 ? void 0 : `#${hexChannel2(r)}${hexChannel2(g2)}${hexChannel2(b)}`);
143474
145697
  } catch {
143475
145698
  resolve2(void 0);
143476
145699
  }
@@ -143494,6 +145717,33 @@ function ensureBarFacePicturePixelSampled(imageUrl, sampler = decodeFirstPixelCo
143494
145717
  });
143495
145718
  inFlight.set(imageUrl, pending);
143496
145719
  }
145720
+ function trySampleFirstPixelColorSync(imageUrl) {
145721
+ const parsed = parseDataUrlToBytes(imageUrl);
145722
+ if (!parsed) {
145723
+ return void 0;
145724
+ }
145725
+ try {
145726
+ return sampleFirstPixelColorFromBytes(parsed.bytes);
145727
+ } catch {
145728
+ return void 0;
145729
+ }
145730
+ }
145731
+ function resolveBarFacePicturePixelColor(imageUrl) {
145732
+ const cached = getCachedBarFacePicturePixelColor(imageUrl);
145733
+ if (cached !== void 0) {
145734
+ return cached;
145735
+ }
145736
+ if (sampleCache.has(imageUrl) || inFlight.has(imageUrl)) {
145737
+ return void 0;
145738
+ }
145739
+ const sync = trySampleFirstPixelColorSync(imageUrl);
145740
+ if (sync !== void 0) {
145741
+ sampleCache.set(imageUrl, sync);
145742
+ return sync;
145743
+ }
145744
+ ensureBarFacePicturePixelSampled(imageUrl);
145745
+ return void 0;
145746
+ }
143497
145747
  function resolveUntargetedBarFaceFill(face, baseColor) {
143498
145748
  return face === "end" ? tint2(baseColor, 0.22) : shade2(baseColor, 0.25);
143499
145749
  }
@@ -143529,11 +145779,10 @@ function resolveExtrusionFaceFill(facePoints, face, resolvedColor, rect22, pictu
143529
145779
  if (!activePicture?.imageUrl) {
143530
145780
  return fallback;
143531
145781
  }
143532
- const sampled = getCachedBarFacePicturePixelColor(activePicture.imageUrl);
145782
+ const sampled = resolveBarFacePicturePixelColor(activePicture.imageUrl);
143533
145783
  if (sampled !== void 0) {
143534
145784
  return resolveUntargetedBarFaceFill(face, sampled);
143535
145785
  }
143536
- ensureBarFacePicturePixelSampled(activePicture.imageUrl);
143537
145786
  return fallback;
143538
145787
  }
143539
145788
  var LEGEND_ITEM_WIDTH = 80;
@@ -145356,8 +147605,8 @@ var DEFAULT_CELL_FONT_PX = 8;
145356
147605
  var DEFAULT_BORDER_COLOR = "#cbd5e1";
145357
147606
  var DEFAULT_TEXT_COLOR22 = "#334155";
145358
147607
  function computeDataTablePrimitives(chartData, layout, colorPalette) {
145359
- const table = chartData.dataTable;
145360
- if (!table) {
147608
+ const table2 = chartData.dataTable;
147609
+ if (!table2) {
145361
147610
  return [];
145362
147611
  }
145363
147612
  const categories = chartData.categories;
@@ -145366,18 +147615,18 @@ function computeDataTablePrimitives(chartData, layout, colorPalette) {
145366
147615
  return [];
145367
147616
  }
145368
147617
  const out = [];
145369
- const showH = table.showHorzBorder !== false;
145370
- const showV = table.showVertBorder !== false;
145371
- const showO = table.showOutline !== false;
145372
- const showK = table.showKeys !== false;
145373
- const borderColor = table.spPr?.strokeColor ?? DEFAULT_BORDER_COLOR;
145374
- const borderWidth = table.spPr?.strokeWidth ?? 1;
145375
- const textColor = table.txPr?.color ?? DEFAULT_TEXT_COLOR22;
145376
- const fontFamily = table.txPr?.fontFamily;
145377
- const fontSize = table.txPr?.fontSize !== void 0 ? chartFontPx(table.txPr.fontSize) : DEFAULT_CELL_FONT_PX;
145378
- const headerWeight = table.txPr?.bold === false ? "normal" : "bold";
145379
- const cellWeight = table.txPr?.bold ? "bold" : "normal";
145380
- const fontStyle = table.txPr?.italic ? "italic" : "normal";
147618
+ const showH = table2.showHorzBorder !== false;
147619
+ const showV = table2.showVertBorder !== false;
147620
+ const showO = table2.showOutline !== false;
147621
+ const showK = table2.showKeys !== false;
147622
+ const borderColor = table2.spPr?.strokeColor ?? DEFAULT_BORDER_COLOR;
147623
+ const borderWidth = table2.spPr?.strokeWidth ?? 1;
147624
+ const textColor = table2.txPr?.color ?? DEFAULT_TEXT_COLOR22;
147625
+ const fontFamily = table2.txPr?.fontFamily;
147626
+ const fontSize = table2.txPr?.fontSize !== void 0 ? chartFontPx(table2.txPr.fontSize) : DEFAULT_CELL_FONT_PX;
147627
+ const headerWeight = table2.txPr?.bold === false ? "normal" : "bold";
147628
+ const cellWeight = table2.txPr?.bold ? "bold" : "normal";
147629
+ const fontStyle = table2.txPr?.italic ? "italic" : "normal";
145381
147630
  const catCount = categories.length;
145382
147631
  const seriesCount = series.length;
145383
147632
  const keyColW = showK ? DATA_TABLE_KEY_W : 0;
@@ -145385,14 +147634,14 @@ function computeDataTablePrimitives(chartData, layout, colorPalette) {
145385
147634
  const cellW = catCount > 0 ? (totalW - keyColW) / catCount : totalW - keyColW;
145386
147635
  const tableTop = layout.plotBottom + DATA_TABLE_PADDING;
145387
147636
  const tableH = DATA_TABLE_HEADER_H + seriesCount * DATA_TABLE_ROW_H;
145388
- if (table.spPr?.fillColor) {
147637
+ if (table2.spPr?.fillColor) {
145389
147638
  out.push({
145390
147639
  kind: "rect",
145391
147640
  x: layout.plotLeft,
145392
147641
  y: tableTop,
145393
147642
  w: totalW,
145394
147643
  h: tableH,
145395
- fill: table.spPr.fillColor
147644
+ fill: table2.spPr.fillColor
145396
147645
  });
145397
147646
  }
145398
147647
  if (showO) {
@@ -188201,8 +190450,8 @@ var LABEL_KEYS = {
188201
190450
  function entry(id, extra = {}) {
188202
190451
  return { id, labelKey: LABEL_KEYS[id], ...extra };
188203
190452
  }
188204
- function tableEntries(table) {
188205
- if (!table) {
190453
+ function tableEntries(table2) {
190454
+ if (!table2) {
188206
190455
  return [];
188207
190456
  }
188208
190457
  const rowsAndColumns = [
@@ -188213,10 +190462,10 @@ function tableEntries(table) {
188213
190462
  entry("table-insert-col-right"),
188214
190463
  entry("table-delete-col")
188215
190464
  ];
188216
- if (table.hasMultiCellSelection) {
190465
+ if (table2.hasMultiCellSelection) {
188217
190466
  return [...rowsAndColumns, entry("table-merge-selected", { separatorBefore: true })];
188218
190467
  }
188219
- if (table.isMergedCell) {
190468
+ if (table2.isMergedCell) {
188220
190469
  return [...rowsAndColumns, entry("table-split", { separatorBefore: true })];
188221
190470
  }
188222
190471
  return [
@@ -188226,7 +190475,7 @@ function tableEntries(table) {
188226
190475
  ];
188227
190476
  }
188228
190477
  function buildContextMenuEntries(context = {}) {
188229
- const { elementType, table, hasMultiSelection, aiEnabled, hasClipboard, selectionGroupable } = context;
190478
+ const { elementType, table: table2, hasMultiSelection, aiEnabled, hasClipboard, selectionGroupable } = context;
188230
190479
  const lockedOut = selectionGroupable === false;
188231
190480
  const entries = [
188232
190481
  entry("copy"),
@@ -188242,7 +190491,7 @@ function buildContextMenuEntries(context = {}) {
188242
190491
  entries.push(entry("ai-ask", { separatorBefore: true }), entry("ai-fix"));
188243
190492
  }
188244
190493
  entries.push(entry("comment", { separatorBefore: true }), entry("hyperlink"));
188245
- entries.push(...tableEntries(table));
190494
+ entries.push(...tableEntries(table2));
188246
190495
  if (hasMultiSelection) {
188247
190496
  entries.push(
188248
190497
  entry("group", { separatorBefore: true, ...lockedOut ? { disabled: true } : {} })
@@ -195643,6 +197892,262 @@ function applyBackgroundEdit(entry2, edit) {
195643
197892
  payload: { styleId: entry2.styleId, section: "background" }
195644
197893
  };
195645
197894
  }
197895
+ var MIN_TILE_DIM = 256;
197896
+ function computeExportTilePlan(fullWidth, fullHeight, maxDim) {
197897
+ const safeMax = Math.max(MIN_TILE_DIM, Math.floor(maxDim));
197898
+ const fw = Math.max(1, Math.round(fullWidth));
197899
+ const fh = Math.max(1, Math.round(fullHeight));
197900
+ if (fw <= safeMax && fh <= safeMax) {
197901
+ return {
197902
+ fullWidth: fw,
197903
+ fullHeight: fh,
197904
+ tiled: false,
197905
+ cols: 1,
197906
+ rows: 1,
197907
+ tiles: [{ col: 0, row: 0, x: 0, y: 0, width: fw, height: fh }]
197908
+ };
197909
+ }
197910
+ const cols = Math.ceil(fw / safeMax);
197911
+ const rows = Math.ceil(fh / safeMax);
197912
+ const baseTileW = Math.ceil(fw / cols);
197913
+ const baseTileH = Math.ceil(fh / rows);
197914
+ const tiles = [];
197915
+ for (let row = 0; row < rows; row++) {
197916
+ const y = row * baseTileH;
197917
+ const height = Math.min(baseTileH, fh - y);
197918
+ for (let col = 0; col < cols; col++) {
197919
+ const x = col * baseTileW;
197920
+ const width = Math.min(baseTileW, fw - x);
197921
+ tiles.push({ col, row, x, y, width, height });
197922
+ }
197923
+ }
197924
+ return { fullWidth: fw, fullHeight: fh, tiled: true, cols, rows, tiles };
197925
+ }
197926
+ function tileRectToSourceRect(tile, scale2) {
197927
+ const s = scale2 > 0 ? scale2 : 1;
197928
+ return {
197929
+ x: tile.x / s,
197930
+ y: tile.y / s,
197931
+ width: tile.width / s,
197932
+ height: tile.height / s
197933
+ };
197934
+ }
197935
+ var EXCLUDED_STYLE_PROPERTIES = /* @__PURE__ */ new Set([
197936
+ "cursor",
197937
+ "caret-color",
197938
+ "user-select",
197939
+ "-webkit-user-select",
197940
+ "all"
197941
+ ]);
197942
+ function buildInlineStyleText(computed) {
197943
+ const parts = [];
197944
+ for (let i2 = 0; i2 < computed.length; i2++) {
197945
+ const prop = computed.item(i2);
197946
+ if (EXCLUDED_STYLE_PROPERTIES.has(prop)) {
197947
+ continue;
197948
+ }
197949
+ const value = computed.getPropertyValue(prop);
197950
+ if (!value) {
197951
+ continue;
197952
+ }
197953
+ parts.push(`${prop}:${value}`);
197954
+ }
197955
+ return parts.join(";");
197956
+ }
197957
+ function inlineComputedStylesOnClone(liveRoot, cloneRoot, readComputedStyle) {
197958
+ const liveEl = liveRoot;
197959
+ const cloneEl = cloneRoot;
197960
+ cloneEl.setAttribute("style", buildInlineStyleText(readComputedStyle(liveEl)));
197961
+ const liveChildren = liveRoot.children;
197962
+ const cloneChildren = cloneRoot.children;
197963
+ const count = Math.min(liveChildren.length, cloneChildren.length);
197964
+ for (let i2 = 0; i2 < count; i2++) {
197965
+ inlineComputedStylesOnClone(liveChildren[i2], cloneChildren[i2], readComputedStyle);
197966
+ }
197967
+ }
197968
+ function collectFontFaceCss(doc) {
197969
+ const blocks = [];
197970
+ const styles = doc.querySelectorAll("style");
197971
+ for (let i2 = 0; i2 < styles.length; i2++) {
197972
+ const text22 = styles[i2].textContent ?? "";
197973
+ if (text22.includes("@font-face")) {
197974
+ blocks.push(text22);
197975
+ }
197976
+ }
197977
+ return blocks.join("\n\n");
197978
+ }
197979
+ async function fetchTextIfCrossOriginSafe(url) {
197980
+ try {
197981
+ const response = await fetch(url, { mode: "cors" });
197982
+ if (!response.ok) {
197983
+ return null;
197984
+ }
197985
+ return await response.text();
197986
+ } catch {
197987
+ return null;
197988
+ }
197989
+ }
197990
+ var FONT_FACE_URL_PATTERN = /url\(\s*["']?([^"')]+)["']?\s*\)/gu;
197991
+ async function inlineFontFaceUrls(css, fetchDataUrl) {
197992
+ const urls = /* @__PURE__ */ new Set();
197993
+ for (const match of css.matchAll(FONT_FACE_URL_PATTERN)) {
197994
+ const raw = match[1];
197995
+ if (raw.startsWith("http:") || raw.startsWith("https:")) {
197996
+ urls.add(raw);
197997
+ }
197998
+ }
197999
+ if (urls.size === 0) {
198000
+ return { css, allEmbedded: true };
198001
+ }
198002
+ const resolved = await Promise.all(
198003
+ Array.from(urls, async (url) => [url, await fetchDataUrl(url)])
198004
+ );
198005
+ let inlined = css;
198006
+ let allEmbedded = true;
198007
+ for (const [url, dataUrl] of resolved) {
198008
+ if (dataUrl) {
198009
+ inlined = inlined.split(url).join(dataUrl);
198010
+ } else {
198011
+ allEmbedded = false;
198012
+ }
198013
+ }
198014
+ return { css: inlined, allEmbedded };
198015
+ }
198016
+ async function collectExternalFontFaceCss(doc, fetchDataUrl) {
198017
+ const links = doc.querySelectorAll('link[rel="stylesheet"]');
198018
+ const blocks = [];
198019
+ let allEmbedded = true;
198020
+ for (let i2 = 0; i2 < links.length; i2++) {
198021
+ const href = links[i2].getAttribute("href");
198022
+ if (!href || !(href.startsWith("http:") || href.startsWith("https:"))) {
198023
+ continue;
198024
+ }
198025
+ const css = await fetchTextIfCrossOriginSafe(href);
198026
+ if (!css) {
198027
+ allEmbedded = false;
198028
+ continue;
198029
+ }
198030
+ const inlined = await inlineFontFaceUrls(css, fetchDataUrl);
198031
+ blocks.push(inlined.css);
198032
+ if (!inlined.allEmbedded) {
198033
+ allEmbedded = false;
198034
+ }
198035
+ }
198036
+ return { css: blocks.join("\n\n"), allEmbedded };
198037
+ }
198038
+ async function fetchAsDataUrl(url) {
198039
+ try {
198040
+ const response = await fetch(url, { mode: url.startsWith("blob:") ? "same-origin" : "cors" });
198041
+ if (!response.ok) {
198042
+ return null;
198043
+ }
198044
+ const blob = await response.blob();
198045
+ return await new Promise((resolve2, reject) => {
198046
+ const reader = new FileReader();
198047
+ reader.onloadend = () => resolve2(reader.result);
198048
+ reader.onerror = reject;
198049
+ reader.readAsDataURL(blob);
198050
+ });
198051
+ } catch {
198052
+ return null;
198053
+ }
198054
+ }
198055
+ function extractCssUrl(value) {
198056
+ const match = /url\(\s*["']?([^"')]+)["']?\s*\)/u.exec(value);
198057
+ return match ? match[1] : null;
198058
+ }
198059
+ function needsEmbedding(url) {
198060
+ return url.startsWith("blob:") || url.startsWith("http:") || url.startsWith("https:");
198061
+ }
198062
+ async function runImgTask(img, src) {
198063
+ const dataUrl = await fetchAsDataUrl(src);
198064
+ if (!dataUrl) {
198065
+ return false;
198066
+ }
198067
+ img.setAttribute("src", dataUrl);
198068
+ return true;
198069
+ }
198070
+ async function runSvgImageTask(svgImg, href) {
198071
+ const dataUrl = await fetchAsDataUrl(href);
198072
+ if (!dataUrl) {
198073
+ return false;
198074
+ }
198075
+ svgImg.setAttribute("href", dataUrl);
198076
+ svgImg.removeAttribute("xlink:href");
198077
+ return true;
198078
+ }
198079
+ async function runBackgroundTask(el, bg, url) {
198080
+ const dataUrl = await fetchAsDataUrl(url);
198081
+ if (!dataUrl) {
198082
+ return false;
198083
+ }
198084
+ el.style.backgroundImage = bg.replace(url, dataUrl);
198085
+ return true;
198086
+ }
198087
+ async function embedImagesOnClone(root) {
198088
+ const tasks = [];
198089
+ for (const img of root.querySelectorAll("img")) {
198090
+ const src = img.getAttribute("src") ?? "";
198091
+ if (needsEmbedding(src)) {
198092
+ tasks.push(() => runImgTask(img, src));
198093
+ }
198094
+ }
198095
+ for (const svgImg of root.querySelectorAll("image")) {
198096
+ const href = svgImg.getAttribute("href") ?? svgImg.getAttribute("xlink:href") ?? "";
198097
+ if (needsEmbedding(href)) {
198098
+ tasks.push(() => runSvgImageTask(svgImg, href));
198099
+ }
198100
+ }
198101
+ const withBackground = [root, ...Array.from(root.querySelectorAll("*"))];
198102
+ for (const el of withBackground) {
198103
+ const bg = el.style.backgroundImage;
198104
+ if (!bg || bg === "none") {
198105
+ continue;
198106
+ }
198107
+ const url = extractCssUrl(bg);
198108
+ if (url && needsEmbedding(url)) {
198109
+ tasks.push(() => runBackgroundTask(el, bg, url));
198110
+ }
198111
+ }
198112
+ const results = await Promise.all(tasks.map((task) => task()));
198113
+ const unembeddableCount = results.filter((embedded) => !embedded).length;
198114
+ return { allEmbedded: unembeddableCount === 0, unembeddableCount };
198115
+ }
198116
+ function escapeAttr(value) {
198117
+ return value.replace(/&/gu, "&amp;").replace(/"/gu, "&quot;");
198118
+ }
198119
+ async function buildForeignObjectSvgBody(element, doc, options) {
198120
+ const {
198121
+ width,
198122
+ height,
198123
+ backgroundColor,
198124
+ readComputedStyle = (el) => window.getComputedStyle(el)
198125
+ } = options;
198126
+ const clone3 = element.cloneNode(true);
198127
+ inlineComputedStylesOnClone(element, clone3, readComputedStyle);
198128
+ const [{ allEmbedded: imagesEmbedded }, externalFonts] = await Promise.all([
198129
+ embedImagesOnClone(clone3),
198130
+ collectExternalFontFaceCss(doc, fetchAsDataUrl)
198131
+ ]);
198132
+ const allEmbedded = imagesEmbedded && externalFonts.allEmbedded;
198133
+ const fontFaceCss = [collectFontFaceCss(doc), externalFonts.css].filter(Boolean).join("\n\n");
198134
+ const defs = fontFaceCss ? `<defs><style type="text/css"><![CDATA[${fontFaceCss}]]></style></defs>` : "";
198135
+ const bgRect = backgroundColor ? `<rect width="${width}" height="${height}" fill="${escapeAttr(backgroundColor)}" />` : "";
198136
+ const bodyMarkup = [
198137
+ defs,
198138
+ bgRect,
198139
+ `<foreignObject x="0" y="0" width="${width}" height="${height}">`,
198140
+ `<div xmlns="http://www.w3.org/1999/xhtml" style="width:${width}px;height:${height}px;overflow:hidden;">`,
198141
+ clone3.outerHTML,
198142
+ "</div>",
198143
+ "</foreignObject>"
198144
+ ].join("");
198145
+ return { bodyMarkup, allEmbedded, naturalWidth: width, naturalHeight: height };
198146
+ }
198147
+ function wrapForeignObjectSvg(bodyMarkup, tile) {
198148
+ const { viewBoxX, viewBoxY, viewBoxWidth, viewBoxHeight, outputWidth, outputHeight } = tile;
198149
+ return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${outputWidth}" height="${outputHeight}" viewBox="${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}">${bodyMarkup}</svg>`;
198150
+ }
195646
198151
  var FALLBACK_DOWNLOAD_NAME = "presentation.pptx";
195647
198152
  var REVOKE_DELAY_MS = 200;
195648
198153
  var OPEN_REVOKE_DELAY_MS = 6e4;
@@ -195905,11 +198410,11 @@ function lzwEncode(indexed, minCodeSize) {
195905
198410
  let codeSize = minCodeSize + 1;
195906
198411
  let nextCode = eoiCode + 1;
195907
198412
  const maxTableSize = 4096;
195908
- const table = /* @__PURE__ */ new Map();
198413
+ const table2 = /* @__PURE__ */ new Map();
195909
198414
  const initTable = () => {
195910
- table.clear();
198415
+ table2.clear();
195911
198416
  for (let i2 = 0; i2 < clearCode; i2++) {
195912
- table.set(String(i2), i2);
198417
+ table2.set(String(i2), i2);
195913
198418
  }
195914
198419
  codeSize = minCodeSize + 1;
195915
198420
  nextCode = eoiCode + 1;
@@ -195930,15 +198435,15 @@ function lzwEncode(indexed, minCodeSize) {
195930
198435
  let current = String(indexed[0]);
195931
198436
  for (let i2 = 1; i2 < indexed.length; i2++) {
195932
198437
  const next = `${current},${String(indexed[i2])}`;
195933
- if (table.has(next)) {
198438
+ if (table2.has(next)) {
195934
198439
  current = next;
195935
198440
  } else {
195936
- const currentCode = table.get(current);
198441
+ const currentCode = table2.get(current);
195937
198442
  if (currentCode !== void 0) {
195938
198443
  writeBits(currentCode, codeSize);
195939
198444
  }
195940
198445
  if (nextCode < maxTableSize) {
195941
- table.set(next, nextCode++);
198446
+ table2.set(next, nextCode++);
195942
198447
  if (nextCode > 1 << codeSize && codeSize < 12) {
195943
198448
  codeSize++;
195944
198449
  }
@@ -195949,7 +198454,7 @@ function lzwEncode(indexed, minCodeSize) {
195949
198454
  current = String(indexed[i2]);
195950
198455
  }
195951
198456
  }
195952
- const finalCode = table.get(current);
198457
+ const finalCode = table2.get(current);
195953
198458
  if (finalCode !== void 0) {
195954
198459
  writeBits(finalCode, codeSize);
195955
198460
  }
@@ -196916,13 +199421,13 @@ async function normalizeColorsForCapture(doc, clonedEl) {
196916
199421
  resolveRootCustomProperties(doc);
196917
199422
  resolveUnsupportedColours(clonedEl);
196918
199423
  }
196919
- function buildSlidesPdfBytes(images) {
196920
- const PAGE_W = 842;
196921
- const PAGE_H = 595;
199424
+ var PDF_SLIDES_PAGE_WIDTH_PT = 842;
199425
+ var PDF_SLIDES_PAGE_HEIGHT_PT = 595;
199426
+ function buildTiledSlidesPdfBytes(pages) {
199427
+ const PAGE_W = PDF_SLIDES_PAGE_WIDTH_PT;
199428
+ const PAGE_H = PDF_SLIDES_PAGE_HEIGHT_PT;
196922
199429
  const offsets = [];
196923
199430
  let pos2 = 0;
196924
- const objCount = 2 + images.length * 3;
196925
- const pageObjIds = [];
196926
199431
  const segments = [];
196927
199432
  const emitStr = (s) => {
196928
199433
  segments.push(s);
@@ -196938,33 +199443,42 @@ function buildSlidesPdfBytes(images) {
196938
199443
  emitStr("%PDF-1.4\n%\xE2\xE3\xCF\xD3\n");
196939
199444
  markObj();
196940
199445
  emitStr("1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n");
196941
- for (let i2 = 0; i2 < images.length; i2++) {
196942
- const img = images[i2];
196943
- const imgObjId = 3 + i2 * 3;
196944
- const pageObjId = 3 + i2 * 3 + 1;
196945
- const contObjId = 3 + i2 * 3 + 2;
199446
+ let nextObjId = 3;
199447
+ const pageObjIds = [];
199448
+ for (const pageImages of pages) {
199449
+ const imgObjIds = [];
199450
+ for (let i2 = 0; i2 < pageImages.length; i2++) {
199451
+ imgObjIds.push(nextObjId);
199452
+ nextObjId++;
199453
+ }
199454
+ const pageObjId = nextObjId++;
199455
+ const contObjId = nextObjId++;
196946
199456
  pageObjIds.push(pageObjId);
196947
- const scale2 = Math.min(PAGE_W / img.w, PAGE_H / img.h);
196948
- const dw = img.w * scale2;
196949
- const dh = img.h * scale2;
196950
- const dx = (PAGE_W - dw) / 2;
196951
- const dy = (PAGE_H - dh) / 2;
196952
- markObj();
196953
- const imgHeader = `${imgObjId} 0 obj
196954
- << /Type /XObject /Subtype /Image /Width ${img.w} /Height ${img.h} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${img.bytes.length} >>
199457
+ for (let idx = 0; idx < pageImages.length; idx++) {
199458
+ markObj();
199459
+ const { image } = pageImages[idx];
199460
+ emitStr(
199461
+ `${imgObjIds[idx]} 0 obj
199462
+ << /Type /XObject /Subtype /Image /Width ${image.w} /Height ${image.h} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${image.bytes.length} >>
196955
199463
  stream
196956
- `;
196957
- emitStr(imgHeader);
196958
- emitBin(img.bytes);
196959
- emitStr("\nendstream\nendobj\n");
199464
+ `
199465
+ );
199466
+ emitBin(image.bytes);
199467
+ emitStr("\nendstream\nendobj\n");
199468
+ }
196960
199469
  markObj();
199470
+ const xobjectDict = pageImages.map((_, idx) => `/Img${idx} ${imgObjIds[idx]} 0 R`).join(" ");
196961
199471
  emitStr(
196962
199472
  `${pageObjId} 0 obj
196963
- << /Type /Page /Parent 2 0 R /MediaBox [0 0 ${PAGE_W} ${PAGE_H}] /Contents ${contObjId} 0 R /Resources << /XObject << /Img${i2} ${imgObjId} 0 R >> >> >>
199473
+ << /Type /Page /Parent 2 0 R /MediaBox [0 0 ${PAGE_W} ${PAGE_H}] /Contents ${contObjId} 0 R /Resources << /XObject << ${xobjectDict} >> >> >>
196964
199474
  endobj
196965
199475
  `
196966
199476
  );
196967
- const contentStream = `q ${dw.toFixed(2)} 0 0 ${dh.toFixed(2)} ${dx.toFixed(2)} ${dy.toFixed(2)} cm /Img${i2} Do Q`;
199477
+ const contentStream = pageImages.map((entry2, idx) => {
199478
+ const { x, y, width, height } = entry2.placement;
199479
+ const rawY = PAGE_H - y - height;
199480
+ return `q ${width.toFixed(2)} 0 0 ${height.toFixed(2)} ${x.toFixed(2)} ${rawY.toFixed(2)} cm /Img${idx} Do Q`;
199481
+ }).join(" ");
196968
199482
  markObj();
196969
199483
  emitStr(
196970
199484
  `${contObjId} 0 obj
@@ -196979,9 +199493,10 @@ endobj
196979
199493
  const pagesKids = pageObjIds.map((id) => `${id} 0 R`).join(" ");
196980
199494
  offsets.splice(1, 0, pos2);
196981
199495
  emitStr(`2 0 obj
196982
- << /Type /Pages /Kids [${pagesKids}] /Count ${images.length} >>
199496
+ << /Type /Pages /Kids [${pagesKids}] /Count ${pages.length} >>
196983
199497
  endobj
196984
199498
  `);
199499
+ const objCount = nextObjId - 1;
196985
199500
  const xrefPos = pos2;
196986
199501
  const totalObjs = objCount + 1;
196987
199502
  emitStr(`xref
@@ -197435,6 +199950,531 @@ function segmentFrameCount(durationMs, fps) {
197435
199950
  }
197436
199951
  return Math.max(1, Math.ceil(durationMs / (1e3 / fps)));
197437
199952
  }
199953
+ var table;
199954
+ function getTable() {
199955
+ if (table) {
199956
+ return table;
199957
+ }
199958
+ const t = new Uint32Array(256);
199959
+ for (let n = 0; n < 256; n++) {
199960
+ let c = n;
199961
+ for (let k = 0; k < 8; k++) {
199962
+ c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
199963
+ }
199964
+ t[n] = c >>> 0;
199965
+ }
199966
+ table = t;
199967
+ return t;
199968
+ }
199969
+ function crc322(bytes) {
199970
+ const t = getTable();
199971
+ let crc = 4294967295;
199972
+ for (let i2 = 0; i2 < bytes.length; i2++) {
199973
+ crc = t[(crc ^ bytes[i2]) & 255] ^ crc >>> 8;
199974
+ }
199975
+ return (crc ^ 4294967295) >>> 0;
199976
+ }
199977
+ var PNG_SIGNATURE3 = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
199978
+ function u32be(value) {
199979
+ return new Uint8Array([
199980
+ value >>> 24 & 255,
199981
+ value >>> 16 & 255,
199982
+ value >>> 8 & 255,
199983
+ value & 255
199984
+ ]);
199985
+ }
199986
+ function asciiBytes(type) {
199987
+ const out = new Uint8Array(type.length);
199988
+ for (let i2 = 0; i2 < type.length; i2++) {
199989
+ out[i2] = type.charCodeAt(i2);
199990
+ }
199991
+ return out;
199992
+ }
199993
+ function concatBytes2(parts) {
199994
+ const total = parts.reduce((sum, p) => sum + p.length, 0);
199995
+ const out = new Uint8Array(total);
199996
+ let offset = 0;
199997
+ for (const part of parts) {
199998
+ out.set(part, offset);
199999
+ offset += part.length;
200000
+ }
200001
+ return out;
200002
+ }
200003
+ function buildPngChunk(type, data) {
200004
+ const typeBytes = asciiBytes(type);
200005
+ const crc = crc322(concatBytes2([typeBytes, data]));
200006
+ return concatBytes2([u32be(data.length), typeBytes, data, u32be(crc)]);
200007
+ }
200008
+ var PNG_COLOR_TYPE_RGBA = 6;
200009
+ function buildIhdrChunk(width, height) {
200010
+ const data = new Uint8Array(13);
200011
+ data.set(u32be(width), 0);
200012
+ data.set(u32be(height), 4);
200013
+ data[8] = 8;
200014
+ data[9] = PNG_COLOR_TYPE_RGBA;
200015
+ data[10] = 0;
200016
+ data[11] = 0;
200017
+ data[12] = 0;
200018
+ return buildPngChunk("IHDR", data);
200019
+ }
200020
+ function buildIendChunk() {
200021
+ return buildPngChunk("IEND", new Uint8Array(0));
200022
+ }
200023
+ function assemblePng(width, height, idatChunks) {
200024
+ return concatBytes2([
200025
+ PNG_SIGNATURE3,
200026
+ buildIhdrChunk(width, height),
200027
+ ...idatChunks,
200028
+ buildIendChunk()
200029
+ ]);
200030
+ }
200031
+ function buildIdatChunk(zlibBytes) {
200032
+ return buildPngChunk("IDAT", zlibBytes);
200033
+ }
200034
+ var RGBA_BYTES_PER_PIXEL = 4;
200035
+ function filterPixelBlock(pixels, width, height) {
200036
+ const rowBytes = width * RGBA_BYTES_PER_PIXEL;
200037
+ if (pixels.length !== rowBytes * height) {
200038
+ throw new Error(
200039
+ `filterPixelBlock: expected ${rowBytes * height} bytes for ${width}x${height} RGBA, got ${pixels.length}`
200040
+ );
200041
+ }
200042
+ const out = new Uint8Array((rowBytes + 1) * height);
200043
+ for (let row = 0; row < height; row++) {
200044
+ const srcStart = row * rowBytes;
200045
+ out[row * (rowBytes + 1)] = 0;
200046
+ out.set(pixels.subarray(srcStart, srcStart + rowBytes), row * (rowBytes + 1) + 1);
200047
+ }
200048
+ return out;
200049
+ }
200050
+ async function concatChunks(parts) {
200051
+ const total = parts.reduce((sum, p) => sum + p.length, 0);
200052
+ const out = new Uint8Array(total);
200053
+ let offset = 0;
200054
+ for (const part of parts) {
200055
+ out.set(part, offset);
200056
+ offset += part.length;
200057
+ }
200058
+ return out;
200059
+ }
200060
+ async function deflateBlocks(blocks) {
200061
+ const cs = new CompressionStream("deflate");
200062
+ const writer = cs.writable.getWriter();
200063
+ const reader = cs.readable.getReader();
200064
+ const outChunks = [];
200065
+ const readLoop = (async () => {
200066
+ for (; ; ) {
200067
+ const { value, done } = await reader.read();
200068
+ if (done) {
200069
+ break;
200070
+ }
200071
+ outChunks.push(value);
200072
+ }
200073
+ })();
200074
+ for await (const block of blocks) {
200075
+ await writer.write(new Uint8Array(block));
200076
+ }
200077
+ await writer.close();
200078
+ await readLoop;
200079
+ return concatChunks(outChunks);
200080
+ }
200081
+ async function encodePngFromRowBands(width, height, rowBands) {
200082
+ let coveredRows = 0;
200083
+ async function* filteredBlocks() {
200084
+ for await (const band of rowBands) {
200085
+ coveredRows += band.bandHeight;
200086
+ yield filterPixelBlock(band.pixels, width, band.bandHeight);
200087
+ }
200088
+ }
200089
+ const zlibBytes = await deflateBlocks(filteredBlocks());
200090
+ if (coveredRows !== height) {
200091
+ throw new Error(
200092
+ `encodePngFromRowBands: row-bands covered ${coveredRows} rows, expected ${height}`
200093
+ );
200094
+ }
200095
+ return assemblePng(width, height, [buildIdatChunk(zlibBytes)]);
200096
+ }
200097
+ var ForeignObjectRasterError = class extends Error {
200098
+ constructor(message, cause) {
200099
+ super(message);
200100
+ this.cause = cause;
200101
+ this.name = "ForeignObjectRasterError";
200102
+ }
200103
+ cause;
200104
+ };
200105
+ function loadImage(src) {
200106
+ return new Promise((resolve2, reject) => {
200107
+ const img = new Image();
200108
+ img.onload = () => resolve2(img);
200109
+ img.onerror = (event) => reject(new ForeignObjectRasterError("SVG image failed to load", event));
200110
+ img.src = src;
200111
+ });
200112
+ }
200113
+ var FOREIGN_OBJECT_SVG_DATA_URL_PREFIX = "data:image/svg+xml;charset=utf-8,";
200114
+ function foreignObjectSvgToDataUrl(svg) {
200115
+ return `${FOREIGN_OBJECT_SVG_DATA_URL_PREFIX}${encodeURIComponent(svg)}`;
200116
+ }
200117
+ async function rasterizeForeignObjectSvg(svg, outputWidth, outputHeight, backgroundColor) {
200118
+ const img = await loadImage(foreignObjectSvgToDataUrl(svg));
200119
+ const canvas = document.createElement("canvas");
200120
+ canvas.width = outputWidth;
200121
+ canvas.height = outputHeight;
200122
+ const ctx = canvas.getContext("2d");
200123
+ if (!ctx) {
200124
+ throw new ForeignObjectRasterError("2D canvas context unavailable");
200125
+ }
200126
+ if (backgroundColor) {
200127
+ ctx.fillStyle = backgroundColor;
200128
+ ctx.fillRect(0, 0, outputWidth, outputHeight);
200129
+ }
200130
+ ctx.drawImage(img, 0, 0, outputWidth, outputHeight);
200131
+ try {
200132
+ ctx.getImageData(0, 0, 1, 1);
200133
+ } catch (cause) {
200134
+ throw new ForeignObjectRasterError(
200135
+ "Canvas tainted by an un-embedded cross-origin resource",
200136
+ cause
200137
+ );
200138
+ }
200139
+ return canvas;
200140
+ }
200141
+ var CANVAS_DIMENSION_CANDIDATES = [
200142
+ 16384,
200143
+ 14188,
200144
+ 11180,
200145
+ 8192,
200146
+ 4096,
200147
+ 2048
200148
+ ];
200149
+ var MARKER = { r: 17, g: 187, b: 221, a: 255 };
200150
+ function canvasReportsMarker(factory, dim) {
200151
+ try {
200152
+ const canvas = factory(dim, 1);
200153
+ const ctx = canvas.getContext("2d");
200154
+ if (!ctx) {
200155
+ return { ok: false, probeFailed: true };
200156
+ }
200157
+ ctx.fillStyle = `rgba(${MARKER.r},${MARKER.g},${MARKER.b},1)`;
200158
+ ctx.fillRect(dim - 1, 0, 1, 1);
200159
+ const pixel = ctx.getImageData(dim - 1, 0, 1, 1).data;
200160
+ const ok = pixel[0] === MARKER.r && pixel[1] === MARKER.g && pixel[2] === MARKER.b;
200161
+ return { ok, probeFailed: false };
200162
+ } catch {
200163
+ return { ok: false, probeFailed: false };
200164
+ }
200165
+ }
200166
+ function probeMaxCanvasDimension(factory = (w, h2) => {
200167
+ const el = document.createElement("canvas");
200168
+ el.width = w;
200169
+ el.height = h2;
200170
+ return el;
200171
+ }) {
200172
+ for (const dim of CANVAS_DIMENSION_CANDIDATES) {
200173
+ const { ok, probeFailed } = canvasReportsMarker(factory, dim);
200174
+ if (ok) {
200175
+ return dim;
200176
+ }
200177
+ if (probeFailed) {
200178
+ break;
200179
+ }
200180
+ }
200181
+ return CANVAS_DIMENSION_CANDIDATES[CANVAS_DIMENSION_CANDIDATES.length - 1];
200182
+ }
200183
+ function ensureExactSize(canvas, outputSize) {
200184
+ if (canvas.width === outputSize.width && canvas.height === outputSize.height) {
200185
+ return canvas;
200186
+ }
200187
+ const exact = document.createElement("canvas");
200188
+ exact.width = outputSize.width;
200189
+ exact.height = outputSize.height;
200190
+ const ctx = exact.getContext("2d");
200191
+ if (!ctx) {
200192
+ return canvas;
200193
+ }
200194
+ ctx.drawImage(
200195
+ canvas,
200196
+ 0,
200197
+ 0,
200198
+ canvas.width,
200199
+ canvas.height,
200200
+ 0,
200201
+ 0,
200202
+ outputSize.width,
200203
+ outputSize.height
200204
+ );
200205
+ return exact;
200206
+ }
200207
+ async function rasterizeWindow(body, sourceRect, outputSize, backgroundColor, options) {
200208
+ const { mode = "auto", vectorSvgFallback, html2canvasFallback, onStrategyFailed } = options;
200209
+ if (mode !== "html2canvas" && body && body.allEmbedded) {
200210
+ try {
200211
+ const svg = wrapForeignObjectSvg(body.bodyMarkup, {
200212
+ viewBoxX: sourceRect.x,
200213
+ viewBoxY: sourceRect.y,
200214
+ viewBoxWidth: sourceRect.width,
200215
+ viewBoxHeight: sourceRect.height,
200216
+ outputWidth: outputSize.width,
200217
+ outputHeight: outputSize.height
200218
+ });
200219
+ const canvas2 = await rasterizeForeignObjectSvg(
200220
+ svg,
200221
+ outputSize.width,
200222
+ outputSize.height,
200223
+ backgroundColor
200224
+ );
200225
+ return { canvas: ensureExactSize(canvas2, outputSize), strategy: "foreignObject" };
200226
+ } catch (error) {
200227
+ onStrategyFailed?.(
200228
+ "foreignObject",
200229
+ error instanceof ForeignObjectRasterError ? error : error
200230
+ );
200231
+ }
200232
+ }
200233
+ if (mode !== "html2canvas" && vectorSvgFallback) {
200234
+ try {
200235
+ const canvas2 = await vectorSvgFallback(sourceRect, outputSize);
200236
+ return { canvas: ensureExactSize(canvas2, outputSize), strategy: "vectorSvg" };
200237
+ } catch (error) {
200238
+ onStrategyFailed?.("vectorSvg", error);
200239
+ }
200240
+ }
200241
+ const canvas = await html2canvasFallback(sourceRect, outputSize);
200242
+ return { canvas: ensureExactSize(canvas, outputSize), strategy: "html2canvas" };
200243
+ }
200244
+ var RASTER_STRATEGY_FALLBACK_WARNING = "[pptx-viewer] raster export:";
200245
+ function warnStrategyFailed(strategy, error) {
200246
+ const detail = error instanceof Error ? error.message : String(error);
200247
+ console.warn(
200248
+ `${RASTER_STRATEGY_FALLBACK_WARNING} ${strategy} strategy failed, falling back to the next one (${detail})`
200249
+ );
200250
+ }
200251
+ async function rasterizeElementTiles(element, naturalWidth, naturalHeight, doc, options) {
200252
+ const scale2 = options.scale && options.scale > 0 ? options.scale : 1;
200253
+ const maxDim = options.maxCanvasDim ?? probeMaxCanvasDimension();
200254
+ const plan = computeExportTilePlan(naturalWidth * scale2, naturalHeight * scale2, maxDim);
200255
+ const body = options.mode === "html2canvas" ? void 0 : await buildForeignObjectSvgBody(
200256
+ element,
200257
+ doc,
200258
+ {
200259
+ width: naturalWidth,
200260
+ height: naturalHeight,
200261
+ backgroundColor: options.backgroundColor
200262
+ }
200263
+ );
200264
+ const strategyOptions = {
200265
+ mode: options.mode,
200266
+ vectorSvgFallback: options.vectorSvgFallback,
200267
+ html2canvasFallback: options.html2canvasFallback,
200268
+ onStrategyFailed: options.onStrategyFailed ?? warnStrategyFailed
200269
+ };
200270
+ const tiles = [];
200271
+ let done = 0;
200272
+ for (const tile of plan.tiles) {
200273
+ const { canvas, strategy } = await rasterizeWindow(
200274
+ body,
200275
+ tileRectToSourceRect(tile, scale2),
200276
+ { width: tile.width, height: tile.height },
200277
+ options.backgroundColor,
200278
+ strategyOptions
200279
+ );
200280
+ tiles.push({
200281
+ col: tile.col,
200282
+ row: tile.row,
200283
+ x: tile.x,
200284
+ y: tile.y,
200285
+ width: tile.width,
200286
+ height: tile.height,
200287
+ canvas,
200288
+ strategy
200289
+ });
200290
+ done++;
200291
+ options.onTileProgress?.(done, plan.tiles.length);
200292
+ }
200293
+ return { fullWidth: plan.fullWidth, fullHeight: plan.fullHeight, tiled: plan.tiled, tiles };
200294
+ }
200295
+ function combineTileRowPixels(tiles, fullWidth) {
200296
+ if (tiles.length === 0) {
200297
+ throw new Error("combineTileRowPixels: at least one tile is required");
200298
+ }
200299
+ const bandHeight = tiles[0].height;
200300
+ const totalWidth = tiles.reduce((sum, t) => sum + t.width, 0);
200301
+ if (totalWidth !== fullWidth) {
200302
+ throw new Error(
200303
+ `combineTileRowPixels: tile widths sum to ${totalWidth}, expected ${fullWidth}`
200304
+ );
200305
+ }
200306
+ for (const tile of tiles) {
200307
+ if (tile.height !== bandHeight) {
200308
+ throw new Error("combineTileRowPixels: every tile in a row must share the same height");
200309
+ }
200310
+ }
200311
+ const out = new Uint8Array(fullWidth * 4 * bandHeight);
200312
+ for (let y = 0; y < bandHeight; y++) {
200313
+ let xOffset = 0;
200314
+ for (const tile of tiles) {
200315
+ const rowBytes = tile.width * 4;
200316
+ const srcStart = y * rowBytes;
200317
+ const destStart = y * fullWidth * 4 + xOffset * 4;
200318
+ out.set(tile.pixels.subarray(srcStart, srcStart + rowBytes), destStart);
200319
+ xOffset += tile.width;
200320
+ }
200321
+ }
200322
+ return out;
200323
+ }
200324
+ function groupTilesByRow(tiles) {
200325
+ const rowCount = tiles.reduce((max, t) => Math.max(max, t.row), 0) + 1;
200326
+ const rows = Array.from({ length: rowCount }, () => []);
200327
+ for (const tile of tiles) {
200328
+ rows[tile.row][tile.col] = tile;
200329
+ }
200330
+ return rows;
200331
+ }
200332
+ async function stitchTilesToPng(fullWidth, fullHeight, tiles) {
200333
+ const rows = groupTilesByRow(tiles);
200334
+ async function* rowBands() {
200335
+ for (const rowTiles of rows) {
200336
+ const pixelTiles = rowTiles.map((tile) => {
200337
+ const ctx = tile.canvas.getContext("2d");
200338
+ if (!ctx) {
200339
+ throw new Error("rasterizeElement: 2D canvas context unavailable while stitching tiles");
200340
+ }
200341
+ return {
200342
+ pixels: ctx.getImageData(0, 0, tile.canvas.width, tile.canvas.height).data,
200343
+ width: tile.canvas.width,
200344
+ height: tile.canvas.height
200345
+ };
200346
+ });
200347
+ yield {
200348
+ pixels: combineTileRowPixels(pixelTiles, fullWidth),
200349
+ bandHeight: pixelTiles[0].height
200350
+ };
200351
+ }
200352
+ }
200353
+ return encodePngFromRowBands(fullWidth, fullHeight, rowBands());
200354
+ }
200355
+ async function rasterizeElement(element, naturalWidth, naturalHeight, doc, options) {
200356
+ const { fullWidth, fullHeight, tiled, tiles } = await rasterizeElementTiles(
200357
+ element,
200358
+ naturalWidth,
200359
+ naturalHeight,
200360
+ doc,
200361
+ options
200362
+ );
200363
+ if (!tiled) {
200364
+ const only = tiles[0];
200365
+ return {
200366
+ kind: "canvas",
200367
+ canvas: only.canvas,
200368
+ strategy: only.strategy,
200369
+ width: only.width,
200370
+ height: only.height
200371
+ };
200372
+ }
200373
+ const bytes = await stitchTilesToPng(fullWidth, fullHeight, tiles);
200374
+ return {
200375
+ kind: "png-bytes",
200376
+ bytes,
200377
+ width: fullWidth,
200378
+ height: fullHeight,
200379
+ strategies: tiles.map((t) => t.strategy)
200380
+ };
200381
+ }
200382
+ function placeTileOnPage(tile, fullWidth, fullHeight, pageWidth, pageHeight) {
200383
+ const fitScale = fullWidth > 0 && fullHeight > 0 ? Math.min(pageWidth / fullWidth, pageHeight / fullHeight) : 0;
200384
+ const fittedWidth = fullWidth * fitScale;
200385
+ const fittedHeight = fullHeight * fitScale;
200386
+ const offsetX = (pageWidth - fittedWidth) / 2;
200387
+ const offsetY = (pageHeight - fittedHeight) / 2;
200388
+ return {
200389
+ x: offsetX + tile.x * fitScale,
200390
+ y: offsetY + tile.y * fitScale,
200391
+ width: tile.width * fitScale,
200392
+ height: tile.height * fitScale
200393
+ };
200394
+ }
200395
+ var CANVAS_DIMENSION_CANDIDATES2 = [
200396
+ 16384,
200397
+ 14188,
200398
+ 11180,
200399
+ 8192,
200400
+ 4096,
200401
+ 2048
200402
+ ];
200403
+ var MARKER2 = { r: 17, g: 187, b: 221, a: 255 };
200404
+ function canvasReportsMarker2(factory, dim) {
200405
+ try {
200406
+ const canvas = factory(dim, 1);
200407
+ const ctx = canvas.getContext("2d");
200408
+ if (!ctx) {
200409
+ return { ok: false, probeFailed: true };
200410
+ }
200411
+ ctx.fillStyle = `rgba(${MARKER2.r},${MARKER2.g},${MARKER2.b},1)`;
200412
+ ctx.fillRect(dim - 1, 0, 1, 1);
200413
+ const pixel = ctx.getImageData(dim - 1, 0, 1, 1).data;
200414
+ const ok = pixel[0] === MARKER2.r && pixel[1] === MARKER2.g && pixel[2] === MARKER2.b;
200415
+ return { ok, probeFailed: false };
200416
+ } catch {
200417
+ return { ok: false, probeFailed: false };
200418
+ }
200419
+ }
200420
+ function probeMaxCanvasDimension2(factory = (w, h2) => {
200421
+ const el = document.createElement("canvas");
200422
+ el.width = w;
200423
+ el.height = h2;
200424
+ return el;
200425
+ }) {
200426
+ for (const dim of CANVAS_DIMENSION_CANDIDATES2) {
200427
+ const { ok, probeFailed } = canvasReportsMarker2(factory, dim);
200428
+ if (ok) {
200429
+ return dim;
200430
+ }
200431
+ if (probeFailed) {
200432
+ break;
200433
+ }
200434
+ }
200435
+ return CANVAS_DIMENSION_CANDIDATES2[CANVAS_DIMENSION_CANDIDATES2.length - 1];
200436
+ }
200437
+ var cachedMaxDim2;
200438
+ function getMaxCanvasDimension2(factory) {
200439
+ if (cachedMaxDim2 === void 0) {
200440
+ cachedMaxDim2 = probeMaxCanvasDimension2(factory);
200441
+ }
200442
+ return cachedMaxDim2;
200443
+ }
200444
+ async function rasterizeElementClampedToCanvas(element, naturalWidth, naturalHeight, doc, options) {
200445
+ const requestedScale = options.scale && options.scale > 0 ? options.scale : 1;
200446
+ const maxDim = options.maxCanvasDim ?? getMaxCanvasDimension2();
200447
+ const fullWidth = naturalWidth * requestedScale;
200448
+ const fullHeight = naturalHeight * requestedScale;
200449
+ const largestEdge = Math.max(fullWidth, fullHeight);
200450
+ const clampFactor = largestEdge > maxDim ? maxDim / largestEdge : 1;
200451
+ const effectiveScale = requestedScale * clampFactor;
200452
+ const result = await rasterizeElement(element, naturalWidth, naturalHeight, doc, {
200453
+ ...options,
200454
+ scale: effectiveScale,
200455
+ maxCanvasDim: maxDim
200456
+ });
200457
+ if (result.kind !== "canvas") {
200458
+ throw new Error(
200459
+ "rasterizeElementClampedToCanvas: rasterizeElement still tiled after clamping the scale"
200460
+ );
200461
+ }
200462
+ return { ...result, clamped: clampFactor < 1, effectiveScale };
200463
+ }
200464
+ async function rasterResultToPngBlob(result) {
200465
+ if (result.kind === "png-bytes") {
200466
+ return new Blob([result.bytes.slice()], { type: "image/png" });
200467
+ }
200468
+ return new Promise((resolve2, reject) => {
200469
+ result.canvas.toBlob((blob) => {
200470
+ if (blob) {
200471
+ resolve2(blob);
200472
+ } else {
200473
+ reject(new Error("Canvas toBlob returned null"));
200474
+ }
200475
+ }, "image/png");
200476
+ });
200477
+ }
197438
200478
  // `@preserve` (CT_SlideMaster, ECMA-376 §19.3.1.38): mirrors the
197439
200479
  /**
197440
200480
  * @fileoverview Save-side writer for slide-master parts (`p:sldMaster`).
@@ -197573,6 +200613,8 @@ exports.OUTLINE_SLIDE_ATTR = OUTLINE_SLIDE_ATTR;
197573
200613
  exports.OUTLINE_VIEW_ATTR = OUTLINE_VIEW_ATTR;
197574
200614
  exports.PATTERN_OPTIONS = PATTERN_OPTIONS;
197575
200615
  exports.PATTERN_PRESET_OPTIONS = PATTERN_PRESET_OPTIONS;
200616
+ exports.PDF_SLIDES_PAGE_HEIGHT_PT = PDF_SLIDES_PAGE_HEIGHT_PT;
200617
+ exports.PDF_SLIDES_PAGE_WIDTH_PT = PDF_SLIDES_PAGE_WIDTH_PT;
197576
200618
  exports.PEN_COLORS = PEN_COLORS;
197577
200619
  exports.PPTX_OPEN_ACCEPT = PPTX_OPEN_ACCEPT;
197578
200620
  exports.PRESENTATION_CHANNEL_NAME = PRESENTATION_CHANNEL_NAME;
@@ -197771,7 +200813,6 @@ exports.buildSaveSlides = buildSaveSlides;
197771
200813
  exports.buildSlideTemplateContent = buildSlideTemplateContent;
197772
200814
  exports.buildSlideTemplateSlide = buildSlideTemplateSlide;
197773
200815
  exports.buildSlidesHtml = buildSlidesHtml;
197774
- exports.buildSlidesPdfBytes = buildSlidesPdfBytes;
197775
200816
  exports.buildSmartArt3DModel = buildSmartArt3DModel;
197776
200817
  exports.buildSmartArtA11y = buildSmartArtA11y;
197777
200818
  exports.buildSmartArtPresetData = buildSmartArtPresetData;
@@ -197793,6 +200834,7 @@ exports.buildTextStyleOverrideCss = buildTextStyleOverrideCss;
197793
200834
  exports.buildThemeColorGrid = buildThemeColorGrid;
197794
200835
  exports.buildThemeColorMap = buildThemeColorMap;
197795
200836
  exports.buildThemeColorSwatchGrid = buildThemeColorSwatchGrid;
200837
+ exports.buildTiledSlidesPdfBytes = buildTiledSlidesPdfBytes;
197796
200838
  exports.buildUserFontFaceStyles = buildUserFontFaceStyles;
197797
200839
  exports.canAddTopLevelNode = canAddTopLevelNode;
197798
200840
  exports.canCommitActionType = canCommitActionType;
@@ -198182,6 +201224,7 @@ exports.pickSupportedMimeType = pickSupportedMimeType;
198182
201224
  exports.pieceLetterSpacing = pieceLetterSpacing;
198183
201225
  exports.placeAudienceWindow = placeAudienceWindow;
198184
201226
  exports.placeCaretAtEnd = placeCaretAtEnd;
201227
+ exports.placeTileOnPage = placeTileOnPage;
198185
201228
  exports.placeholderPromptDescriptor = placeholderPromptDescriptor;
198186
201229
  exports.playFeedbackSound = playFeedbackSound;
198187
201230
  exports.playGroup = playGroup;
@@ -198208,6 +201251,10 @@ exports.publishLiveInlineText = publishLiveInlineText;
198208
201251
  exports.pushRecentColor = pushRecentColor;
198209
201252
  exports.quickStyleSwatchCss = quickStyleSwatchCss;
198210
201253
  exports.radarStylePatch = radarStylePatch;
201254
+ exports.rasterResultToPngBlob = rasterResultToPngBlob;
201255
+ exports.rasterizeElement = rasterizeElement;
201256
+ exports.rasterizeElementClampedToCanvas = rasterizeElementClampedToCanvas;
201257
+ exports.rasterizeElementTiles = rasterizeElementTiles;
198211
201258
  exports.reResolveElementColors = reResolveElementColors;
198212
201259
  exports.reResolveSlideColors = reResolveSlideColors;
198213
201260
  exports.readBackstageRecentFile = readBackstageRecentFile;