pptx-react-viewer 3.21.0 → 4.0.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 (140) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{AiChatPanel-UD756KAU.mjs → AiChatPanel-MHURGN6G.mjs} +3 -3
  3. package/dist/AiChatPanel-MHURGN6G.mjs.br +0 -0
  4. package/dist/AiChatPanel-MHURGN6G.mjs.gz +0 -0
  5. package/dist/{AiChatPanel-B3QM7MIC.js → AiChatPanel-WMVQFNDC.js} +24 -24
  6. package/dist/AiChatPanel-WMVQFNDC.js.br +0 -0
  7. package/dist/AiChatPanel-WMVQFNDC.js.gz +0 -0
  8. package/dist/{Area3DChartScene-435BFPLY.js → Area3DChartScene-IMGZEZNU.js} +2 -2
  9. package/dist/Area3DChartScene-IMGZEZNU.js.br +0 -0
  10. package/dist/Area3DChartScene-IMGZEZNU.js.gz +0 -0
  11. package/dist/{Area3DChartScene-MQKUWVMS.mjs → Area3DChartScene-LKOWSMAU.mjs} +1 -1
  12. package/dist/Area3DChartScene-LKOWSMAU.mjs.br +0 -0
  13. package/dist/Area3DChartScene-LKOWSMAU.mjs.gz +0 -0
  14. package/dist/{Bar3DChartScene-D4GMQGPN.mjs → Bar3DChartScene-NQNSIMUL.mjs} +1 -1
  15. package/dist/Bar3DChartScene-NQNSIMUL.mjs.br +0 -0
  16. package/dist/Bar3DChartScene-NQNSIMUL.mjs.gz +0 -0
  17. package/dist/{Bar3DChartScene-KEYLVYJA.js → Bar3DChartScene-VLSYVFRT.js} +2 -2
  18. package/dist/Bar3DChartScene-VLSYVFRT.js.br +0 -0
  19. package/dist/Bar3DChartScene-VLSYVFRT.js.gz +0 -0
  20. package/dist/{Line3DChartScene-B3AWFXE4.mjs → Line3DChartScene-ANZBJYQI.mjs} +1 -1
  21. package/dist/Line3DChartScene-ANZBJYQI.mjs.br +0 -0
  22. package/dist/Line3DChartScene-ANZBJYQI.mjs.gz +0 -0
  23. package/dist/{Line3DChartScene-JYGXLE56.js → Line3DChartScene-IWZHA563.js} +2 -2
  24. package/dist/Line3DChartScene-IWZHA563.js.br +0 -0
  25. package/dist/Line3DChartScene-IWZHA563.js.gz +0 -0
  26. package/dist/{Model3DScene-JF5J6N6W.js → Model3DScene-2L3YRAMR.js} +2 -2
  27. package/dist/Model3DScene-2L3YRAMR.js.br +0 -0
  28. package/dist/Model3DScene-2L3YRAMR.js.gz +0 -0
  29. package/dist/{Model3DScene-4TG4YRVM.mjs → Model3DScene-Y34HTZXK.mjs} +1 -1
  30. package/dist/Model3DScene-Y34HTZXK.mjs.br +0 -0
  31. package/dist/Model3DScene-Y34HTZXK.mjs.gz +0 -0
  32. package/dist/{PieChart3DScene-4BQ6PR7P.mjs → PieChart3DScene-FBRPLHLG.mjs} +1 -1
  33. package/dist/PieChart3DScene-FBRPLHLG.mjs.br +0 -0
  34. package/dist/PieChart3DScene-FBRPLHLG.mjs.gz +0 -0
  35. package/dist/{PieChart3DScene-CCQWSH3W.js → PieChart3DScene-NE3GN5VG.js} +2 -2
  36. package/dist/PieChart3DScene-NE3GN5VG.js.br +0 -0
  37. package/dist/PieChart3DScene-NE3GN5VG.js.gz +0 -0
  38. package/dist/{SurfaceChart3DScene-FRQC5HBG.mjs → SurfaceChart3DScene-7HE5DA3X.mjs} +1 -1
  39. package/dist/SurfaceChart3DScene-7HE5DA3X.mjs.br +0 -0
  40. package/dist/SurfaceChart3DScene-7HE5DA3X.mjs.gz +0 -0
  41. package/dist/{SurfaceChart3DScene-UVZPT6OD.js → SurfaceChart3DScene-OSMAVZJC.js} +2 -2
  42. package/dist/SurfaceChart3DScene-OSMAVZJC.js.br +0 -0
  43. package/dist/SurfaceChart3DScene-OSMAVZJC.js.gz +0 -0
  44. package/dist/{chunk-TMTQJAGK.mjs → chunk-33YE6E2O.mjs} +162 -82
  45. package/dist/chunk-33YE6E2O.mjs.br +0 -0
  46. package/dist/chunk-33YE6E2O.mjs.gz +0 -0
  47. package/dist/{chunk-TOOKJUPG.mjs → chunk-5F426BCZ.mjs} +1 -1
  48. package/dist/chunk-5F426BCZ.mjs.br +0 -0
  49. package/dist/chunk-5F426BCZ.mjs.gz +0 -0
  50. package/dist/{chunk-HZEOZUUH.mjs → chunk-GITM3RKP.mjs} +1 -1
  51. package/dist/chunk-GITM3RKP.mjs.br +0 -0
  52. package/dist/chunk-GITM3RKP.mjs.gz +0 -0
  53. package/dist/{chunk-EJMDD4VV.mjs → chunk-H7J4EYXS.mjs} +6 -6
  54. package/dist/chunk-H7J4EYXS.mjs.br +0 -0
  55. package/dist/chunk-H7J4EYXS.mjs.gz +0 -0
  56. package/dist/{chunk-M6QJKPU2.js → chunk-I5F3XLVR.js} +1052 -1052
  57. package/dist/chunk-I5F3XLVR.js.br +0 -0
  58. package/dist/chunk-I5F3XLVR.js.gz +0 -0
  59. package/dist/{chunk-BXMPXKV5.mjs → chunk-IWHZ2DUD.mjs} +8 -8
  60. package/dist/chunk-IWHZ2DUD.mjs.br +0 -0
  61. package/dist/chunk-IWHZ2DUD.mjs.gz +0 -0
  62. package/dist/{chunk-BFPIMU6Q.js → chunk-L6I73WMO.js} +790 -790
  63. package/dist/chunk-L6I73WMO.js.br +0 -0
  64. package/dist/chunk-L6I73WMO.js.gz +0 -0
  65. package/dist/{chunk-T6V342NP.js → chunk-LAAXFMRE.js} +162 -82
  66. package/dist/chunk-LAAXFMRE.js.br +0 -0
  67. package/dist/chunk-LAAXFMRE.js.gz +0 -0
  68. package/dist/{chunk-SUZIFHXI.js → chunk-NKACTGK5.js} +173 -173
  69. package/dist/chunk-NKACTGK5.js.br +0 -0
  70. package/dist/chunk-NKACTGK5.js.gz +0 -0
  71. package/dist/{chunk-H7QPQ4OR.js → chunk-ZOB6ITIM.js} +5 -5
  72. package/dist/chunk-ZOB6ITIM.js.br +0 -0
  73. package/dist/chunk-ZOB6ITIM.js.gz +0 -0
  74. package/dist/index.js +46 -46
  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 +104 -104
  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 +2 -2
  93. package/dist/AiChatPanel-B3QM7MIC.js.br +0 -0
  94. package/dist/AiChatPanel-B3QM7MIC.js.gz +0 -0
  95. package/dist/AiChatPanel-UD756KAU.mjs.br +0 -0
  96. package/dist/AiChatPanel-UD756KAU.mjs.gz +0 -0
  97. package/dist/Area3DChartScene-435BFPLY.js.br +0 -0
  98. package/dist/Area3DChartScene-435BFPLY.js.gz +0 -0
  99. package/dist/Area3DChartScene-MQKUWVMS.mjs.br +0 -0
  100. package/dist/Area3DChartScene-MQKUWVMS.mjs.gz +0 -0
  101. package/dist/Bar3DChartScene-D4GMQGPN.mjs.br +0 -0
  102. package/dist/Bar3DChartScene-D4GMQGPN.mjs.gz +0 -0
  103. package/dist/Bar3DChartScene-KEYLVYJA.js.br +0 -0
  104. package/dist/Bar3DChartScene-KEYLVYJA.js.gz +0 -0
  105. package/dist/Line3DChartScene-B3AWFXE4.mjs.br +0 -0
  106. package/dist/Line3DChartScene-B3AWFXE4.mjs.gz +0 -0
  107. package/dist/Line3DChartScene-JYGXLE56.js.br +0 -0
  108. package/dist/Line3DChartScene-JYGXLE56.js.gz +0 -0
  109. package/dist/Model3DScene-4TG4YRVM.mjs.br +0 -0
  110. package/dist/Model3DScene-4TG4YRVM.mjs.gz +0 -0
  111. package/dist/Model3DScene-JF5J6N6W.js.br +0 -0
  112. package/dist/Model3DScene-JF5J6N6W.js.gz +0 -0
  113. package/dist/PieChart3DScene-4BQ6PR7P.mjs.br +0 -0
  114. package/dist/PieChart3DScene-4BQ6PR7P.mjs.gz +0 -0
  115. package/dist/PieChart3DScene-CCQWSH3W.js.br +0 -0
  116. package/dist/PieChart3DScene-CCQWSH3W.js.gz +0 -0
  117. package/dist/SurfaceChart3DScene-FRQC5HBG.mjs.br +0 -0
  118. package/dist/SurfaceChart3DScene-FRQC5HBG.mjs.gz +0 -0
  119. package/dist/SurfaceChart3DScene-UVZPT6OD.js.br +0 -0
  120. package/dist/SurfaceChart3DScene-UVZPT6OD.js.gz +0 -0
  121. package/dist/chunk-BFPIMU6Q.js.br +0 -0
  122. package/dist/chunk-BFPIMU6Q.js.gz +0 -0
  123. package/dist/chunk-BXMPXKV5.mjs.br +0 -0
  124. package/dist/chunk-BXMPXKV5.mjs.gz +0 -0
  125. package/dist/chunk-EJMDD4VV.mjs.br +0 -0
  126. package/dist/chunk-EJMDD4VV.mjs.gz +0 -0
  127. package/dist/chunk-H7QPQ4OR.js.br +0 -0
  128. package/dist/chunk-H7QPQ4OR.js.gz +0 -0
  129. package/dist/chunk-HZEOZUUH.mjs.br +0 -0
  130. package/dist/chunk-HZEOZUUH.mjs.gz +0 -0
  131. package/dist/chunk-M6QJKPU2.js.br +0 -0
  132. package/dist/chunk-M6QJKPU2.js.gz +0 -0
  133. package/dist/chunk-SUZIFHXI.js.br +0 -0
  134. package/dist/chunk-SUZIFHXI.js.gz +0 -0
  135. package/dist/chunk-T6V342NP.js.br +0 -0
  136. package/dist/chunk-T6V342NP.js.gz +0 -0
  137. package/dist/chunk-TMTQJAGK.mjs.br +0 -0
  138. package/dist/chunk-TMTQJAGK.mjs.gz +0 -0
  139. package/dist/chunk-TOOKJUPG.mjs.br +0 -0
  140. package/dist/chunk-TOOKJUPG.mjs.gz +0 -0
Binary file
Binary file
@@ -12,7 +12,7 @@ var DOMPurify__default = /*#__PURE__*/_interopDefault(DOMPurify);
12
12
 
13
13
  // ../core/dist/index.mjs
14
14
 
15
- // ../../node_modules/.bun/emf-converter@2.0.2/node_modules/emf-converter/dist/index.mjs
15
+ // ../../node_modules/.bun/emf-converter@3.0.1/node_modules/emf-converter/dist/index.mjs
16
16
  function colorRefToHex(r, g2, b) {
17
17
  const toHex4 = (v) => v.toString(16).padStart(2, "0");
18
18
  return `#${toHex4(r & 255)}${toHex4(g2 & 255)}${toHex4(b & 255)}`;
@@ -238,6 +238,26 @@ var emfLog = (...args) => {
238
238
  };
239
239
  var emfWarn = (...args) => {
240
240
  };
241
+ var nodeCanvasModule;
242
+ async function ensureNodeCanvasModule() {
243
+ if (nodeCanvasModule !== void 0) {
244
+ return nodeCanvasModule;
245
+ }
246
+ if (typeof OffscreenCanvas !== "undefined" || typeof document !== "undefined") {
247
+ nodeCanvasModule = null;
248
+ return nodeCanvasModule;
249
+ }
250
+ if (typeof process === "undefined" || !process.versions?.node) {
251
+ nodeCanvasModule = null;
252
+ return nodeCanvasModule;
253
+ }
254
+ try {
255
+ nodeCanvasModule = await import('@napi-rs/canvas');
256
+ } catch {
257
+ nodeCanvasModule = null;
258
+ }
259
+ return nodeCanvasModule;
260
+ }
241
261
  var DEFAULT_DPI_SCALE = 1;
242
262
  function createCanvas(width, height, maxWidth, maxHeight, dpiScale = DEFAULT_DPI_SCALE, maxCanvasDimension = MAX_CANVAS_DIMENSION) {
243
263
  const effectiveScale = Math.max(1, Math.min(dpiScale, 4));
@@ -274,30 +294,44 @@ function createCanvas(width, height, maxWidth, maxHeight, dpiScale = DEFAULT_DPI
274
294
  emfLog(
275
295
  `createCanvas: using OffscreenCanvas ${w}\xD7${h2}, scale=(${scaleX.toFixed(3)},${scaleY.toFixed(3)})`
276
296
  );
277
- const canvas2 = new OffscreenCanvas(w, h2);
278
- const ctx2 = canvas2.getContext("2d");
279
- if (!ctx2) {
297
+ const canvas = new OffscreenCanvas(w, h2);
298
+ const ctx = canvas.getContext("2d");
299
+ if (!ctx) {
280
300
  emfWarn('createCanvas: OffscreenCanvas.getContext("2d") returned null');
281
301
  return null;
282
302
  }
283
- return { canvas: canvas2, ctx: ctx2, scaleX, scaleY };
303
+ return { canvas, ctx, scaleX, scaleY };
284
304
  }
285
- if (typeof document === "undefined") {
286
- emfWarn("createCanvas: no OffscreenCanvas and no document \u2014 cannot create canvas");
287
- return null;
305
+ if (typeof document !== "undefined") {
306
+ emfLog(
307
+ `createCanvas: using HTMLCanvasElement ${w}\xD7${h2}, scale=(${scaleX.toFixed(3)},${scaleY.toFixed(3)})`
308
+ );
309
+ const canvas = document.createElement("canvas");
310
+ canvas.width = w;
311
+ canvas.height = h2;
312
+ const ctx = canvas.getContext("2d");
313
+ if (!ctx) {
314
+ emfWarn('createCanvas: HTMLCanvasElement.getContext("2d") returned null');
315
+ return null;
316
+ }
317
+ return { canvas, ctx, scaleX, scaleY };
288
318
  }
289
- emfLog(
290
- `createCanvas: using HTMLCanvasElement ${w}\xD7${h2}, scale=(${scaleX.toFixed(3)},${scaleY.toFixed(3)})`
291
- );
292
- const canvas = document.createElement("canvas");
293
- canvas.width = w;
294
- canvas.height = h2;
295
- const ctx = canvas.getContext("2d");
296
- if (!ctx) {
297
- emfWarn('createCanvas: HTMLCanvasElement.getContext("2d") returned null');
298
- return null;
319
+ if (nodeCanvasModule) {
320
+ emfLog(
321
+ `createCanvas: using @napi-rs/canvas ${w}\xD7${h2}, scale=(${scaleX.toFixed(3)},${scaleY.toFixed(3)})`
322
+ );
323
+ const canvas = nodeCanvasModule.createCanvas(w, h2);
324
+ const ctx = canvas.getContext("2d");
325
+ if (!ctx) {
326
+ emfWarn('createCanvas: @napi-rs/canvas getContext("2d") returned null');
327
+ return null;
328
+ }
329
+ return { canvas, ctx, scaleX, scaleY };
299
330
  }
300
- return { canvas, ctx, scaleX, scaleY };
331
+ emfWarn(
332
+ "createCanvas: no OffscreenCanvas, no document, and no @napi-rs/canvas, cannot create canvas"
333
+ );
334
+ return null;
301
335
  } catch (err) {
302
336
  return null;
303
337
  }
@@ -326,6 +360,14 @@ function createTempCanvas(width, height) {
326
360
  }
327
361
  return { canvas, ctx };
328
362
  }
363
+ if (nodeCanvasModule) {
364
+ const canvas = nodeCanvasModule.createCanvas(width, height);
365
+ const ctx = canvas.getContext("2d");
366
+ if (!ctx) {
367
+ return null;
368
+ }
369
+ return { canvas, ctx };
370
+ }
329
371
  return null;
330
372
  }
331
373
  function rop2Paint(rop2) {
@@ -559,8 +601,31 @@ async function exportCanvasToPngDataUrl(canvas) {
559
601
  );
560
602
  return canvas.toDataURL("image/png");
561
603
  }
604
+ if (nodeCanvasModule && canvas instanceof nodeCanvasModule.Canvas) {
605
+ emfLog(
606
+ `exportCanvasToPngDataUrl: using @napi-rs/canvas toDataURLAsync (${canvas.width}\xD7${canvas.height})`
607
+ );
608
+ return canvas.toDataURLAsync();
609
+ }
562
610
  return null;
563
611
  }
612
+ async function decodeDeferredImageBytes(bytes, mime) {
613
+ if (nodeCanvasModule) {
614
+ const image = await nodeCanvasModule.loadImage(new Uint8Array(bytes));
615
+ return { drawable: image, width: image.width, height: image.height, close: () => {
616
+ } };
617
+ }
618
+ if (typeof createImageBitmap !== "function") {
619
+ return null;
620
+ }
621
+ const blob = mime !== void 0 ? new Blob([bytes], { type: mime }) : new Blob([bytes]);
622
+ const bitmap = await createImageBitmap(blob);
623
+ return { drawable: bitmap, width: bitmap.width, height: bitmap.height, close: () => bitmap.close() };
624
+ }
625
+ function canvasDrawImage(ctx, image, dx, dy, dw, dh) {
626
+ const draw = ctx.drawImage;
627
+ draw.call(ctx, image, dx, dy, dw, dh);
628
+ }
564
629
  function parseEmfHeader(view) {
565
630
  emfLog("parseEmfHeader: byteLength =", view.byteLength);
566
631
  if (view.byteLength < 88) {
@@ -1462,7 +1527,8 @@ function handleBitBlt(rCtx, offset, dataOff, recSize) {
1462
1527
  const temp = createTempCanvas(imageData.width, imageData.height);
1463
1528
  if (temp) {
1464
1529
  temp.ctx.putImageData(imageData, 0, 0);
1465
- ctx.drawImage(
1530
+ canvasDrawImage(
1531
+ ctx,
1466
1532
  temp.canvas,
1467
1533
  gmx(rCtx, dstX),
1468
1534
  gmy(rCtx, dstY),
@@ -1497,7 +1563,8 @@ function handleStretchDibits(rCtx, offset, dataOff, recSize) {
1497
1563
  const temp = createTempCanvas(imageData.width, imageData.height);
1498
1564
  if (temp) {
1499
1565
  temp.ctx.putImageData(imageData, 0, 0);
1500
- ctx.drawImage(
1566
+ canvasDrawImage(
1567
+ ctx,
1501
1568
  temp.canvas,
1502
1569
  gmx(rCtx, dstX),
1503
1570
  gmy(rCtx, dstY),
@@ -4814,12 +4881,16 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
4814
4881
  if (img.isMetafile) {
4815
4882
  if (recursionDepth >= MAX_METAFILE_RECURSION) {
4816
4883
  emfWarn(
4817
- ` Deferred image [${idx}]: skipping embedded metafile \u2014 recursion depth ${recursionDepth} >= ${MAX_METAFILE_RECURSION}`
4884
+ ` Deferred image [${idx}]: skipping embedded metafile, recursion depth ${recursionDepth} >= ${MAX_METAFILE_RECURSION}`
4818
4885
  );
4819
4886
  continue;
4820
4887
  }
4821
4888
  emfLog(` Deferred image [${idx}]: recursively converting embedded metafile...`);
4822
- const metafileDataUrl = await convertEmfToDataUrl(plainBuffer, void 0, recursionDepth + 1) ?? await convertWmfToDataUrl(plainBuffer, void 0, recursionDepth + 1);
4889
+ const metafileDataUrl = await convertMetafileToDataUrl(
4890
+ plainBuffer,
4891
+ void 0,
4892
+ recursionDepth + 1
4893
+ );
4823
4894
  if (metafileDataUrl) {
4824
4895
  emfLog(
4825
4896
  ` Deferred image [${idx}]: metafile converted, dataUrl length=${metafileDataUrl.length}`
@@ -4832,26 +4903,28 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
4832
4903
  for (let i2 = 0; i2 < byteString.length; i2++) {
4833
4904
  ia[i2] = byteString.charCodeAt(i2);
4834
4905
  }
4835
- const metaBlob = new Blob([ab], { type: mime });
4836
- emfLog(
4837
- ` Deferred image [${idx}]: creating ImageBitmap from ${metaBlob.size} byte blob (${mime})...`
4838
- );
4839
- const bitmap = await createImageBitmap(metaBlob);
4840
- emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
4841
- ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
4842
- bitmap.close();
4906
+ emfLog(` Deferred image [${idx}]: decoding ${ab.byteLength} byte image (${mime})...`);
4907
+ const decoded = await decodeDeferredImageBytes(ab, mime);
4908
+ if (decoded) {
4909
+ emfLog(` Deferred image [${idx}]: decoded ${decoded.width}\xD7${decoded.height}`);
4910
+ canvasDrawImage(ctx, decoded.drawable, img.dx, img.dy, img.dw, img.dh);
4911
+ decoded.close();
4912
+ } else {
4913
+ emfWarn(` Deferred image [${idx}]: no image decoder available`);
4914
+ }
4843
4915
  } else {
4844
4916
  emfWarn(` Deferred image [${idx}]: metafile conversion returned null`);
4845
4917
  }
4846
4918
  } else {
4847
- emfLog(
4848
- ` Deferred image [${idx}]: creating ImageBitmap from ${plainBuffer.byteLength} byte blob...`
4849
- );
4850
- const blob = new Blob([plainBuffer]);
4851
- const bitmap = await createImageBitmap(blob);
4852
- emfLog(` Deferred image [${idx}]: ImageBitmap created ${bitmap.width}\xD7${bitmap.height}`);
4853
- ctx.drawImage(bitmap, img.dx, img.dy, img.dw, img.dh);
4854
- bitmap.close();
4919
+ emfLog(` Deferred image [${idx}]: decoding ${plainBuffer.byteLength} byte image...`);
4920
+ const decoded = await decodeDeferredImageBytes(plainBuffer);
4921
+ if (decoded) {
4922
+ emfLog(` Deferred image [${idx}]: decoded ${decoded.width}\xD7${decoded.height}`);
4923
+ canvasDrawImage(ctx, decoded.drawable, img.dx, img.dy, img.dw, img.dh);
4924
+ decoded.close();
4925
+ } else {
4926
+ emfWarn(` Deferred image [${idx}]: no image decoder available`);
4927
+ }
4855
4928
  }
4856
4929
  } catch (imgErr) {
4857
4930
  imgErr instanceof Error ? imgErr.message : String(imgErr);
@@ -4864,10 +4937,35 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth = 0) {
4864
4937
  }
4865
4938
  ctx.setTransform(1, 0, 0, 1, 0, 0);
4866
4939
  }
4867
- async function convertEmfToDataUrl(buffer, options, recursionDepth = 0) {
4940
+ async function convertMetafileToDataUrl(buffer, options, recursionDepth = 0) {
4941
+ await ensureNodeCanvasModule();
4868
4942
  if (recursionDepth > MAX_METAFILE_RECURSION) {
4869
4943
  return null;
4870
4944
  }
4945
+ emfLog(`convertMetafileToDataUrl: input buffer ${buffer.byteLength} bytes`);
4946
+ if (buffer.byteLength >= 16) {
4947
+ const hdrBytes = new Uint8Array(buffer, 0, 16);
4948
+ emfLog(
4949
+ `convertMetafileToDataUrl: first 16 bytes: [${Array.from(hdrBytes).map((b) => b.toString(16).padStart(2, "0")).join(" ")}]`
4950
+ );
4951
+ }
4952
+ const view = new DataView(buffer);
4953
+ let emfHeader = null;
4954
+ try {
4955
+ emfHeader = parseEmfHeader(view);
4956
+ } catch (err) {
4957
+ emfWarn(
4958
+ "convertMetafileToDataUrl: parseEmfHeader threw during detection:",
4959
+ err instanceof Error ? err.message : err
4960
+ );
4961
+ emfHeader = null;
4962
+ }
4963
+ if (emfHeader) {
4964
+ return convertEmfInternal(buffer, view, emfHeader, options, recursionDepth);
4965
+ }
4966
+ return convertWmfInternal(buffer, view);
4967
+ }
4968
+ async function convertEmfInternal(buffer, view, header, options, recursionDepth) {
4871
4969
  const opts = {};
4872
4970
  const dpiScale = opts.dpiScale ?? DEFAULT_DPI_SCALE;
4873
4971
  const effectiveMaxWidth = opts.maxWidth;
@@ -4878,30 +4976,18 @@ async function convertEmfToDataUrl(buffer, options, recursionDepth = 0) {
4878
4976
  fontFamilyMap: opts.fontFamilyMap
4879
4977
  };
4880
4978
  try {
4881
- emfLog("=== convertEmfToDataUrl START ===");
4979
+ emfLog("=== convertEmfInternal START ===");
4882
4980
  emfLog(
4883
4981
  `Input buffer: ${buffer.byteLength} bytes, maxWidth=${effectiveMaxWidth}, maxHeight=${effectiveMaxHeight}, dpiScale=${dpiScale}`
4884
4982
  );
4885
- if (buffer.byteLength >= 16) {
4886
- const hdrBytes = new Uint8Array(buffer, 0, 16);
4887
- emfLog(
4888
- `First 16 bytes: [${Array.from(hdrBytes).map((b) => b.toString(16).padStart(2, "0")).join(" ")}]`
4889
- );
4890
- }
4891
- const view = new DataView(buffer);
4892
- const header = parseEmfHeader(view);
4893
- if (!header) {
4894
- emfLog("convertEmfToDataUrl: parseEmfHeader returned null \u2014 returning null");
4895
- return null;
4896
- }
4897
4983
  const renderBounds = getRenderableEmfBounds(header);
4898
4984
  if (!renderBounds) {
4899
- emfLog("convertEmfToDataUrl: getRenderableEmfBounds returned null \u2014 returning null");
4985
+ emfLog("convertEmfInternal: getRenderableEmfBounds returned null, returning null");
4900
4986
  return null;
4901
4987
  }
4902
4988
  const logicalW = renderBounds.right - renderBounds.left;
4903
4989
  const logicalH = renderBounds.bottom - renderBounds.top;
4904
- emfLog(`convertEmfToDataUrl: logicalSize=${logicalW}\xD7${logicalH}`);
4990
+ emfLog(`convertEmfInternal: logicalSize=${logicalW}\xD7${logicalH}`);
4905
4991
  const setup = createCanvas(
4906
4992
  logicalW,
4907
4993
  logicalH,
@@ -4911,15 +4997,15 @@ async function convertEmfToDataUrl(buffer, options, recursionDepth = 0) {
4911
4997
  opts.maxCanvasDimension
4912
4998
  );
4913
4999
  if (!setup) {
4914
- emfLog("convertEmfToDataUrl: createCanvas returned null \u2014 returning null");
5000
+ emfLog("convertEmfInternal: createCanvas returned null, returning null");
4915
5001
  return null;
4916
5002
  }
4917
5003
  const { canvas, ctx } = setup;
4918
5004
  emfLog(
4919
- `convertEmfToDataUrl: canvas created ${canvas.width}\xD7${canvas.height} (dpiScale=${dpiScale})`
5005
+ `convertEmfInternal: canvas created ${canvas.width}\xD7${canvas.height} (dpiScale=${dpiScale})`
4920
5006
  );
4921
5007
  ctx.save();
4922
- emfLog("convertEmfToDataUrl: starting replayEmfRecords...");
5008
+ emfLog("convertEmfInternal: starting replayEmfRecords...");
4923
5009
  const deferredImages = replayEmfRecords(
4924
5010
  view,
4925
5011
  ctx,
@@ -4929,30 +5015,25 @@ async function convertEmfToDataUrl(buffer, options, recursionDepth = 0) {
4929
5015
  dpiScale,
4930
5016
  replayOptions
4931
5017
  );
4932
- emfLog(
4933
- `convertEmfToDataUrl: replayEmfRecords returned ${deferredImages.length} deferred images`
4934
- );
5018
+ emfLog(`convertEmfInternal: replayEmfRecords returned ${deferredImages.length} deferred images`);
4935
5019
  ctx.restore();
4936
- await processDeferredImages(ctx, deferredImages);
4937
- emfLog("convertEmfToDataUrl: exporting canvas to PNG data URL...");
5020
+ await processDeferredImages(ctx, deferredImages, recursionDepth);
5021
+ emfLog("convertEmfInternal: exporting canvas to PNG data URL...");
4938
5022
  const result = await exportCanvasToPngDataUrl(canvas);
4939
5023
  if (result) {
4940
- emfLog(`convertEmfToDataUrl: SUCCESS \u2014 data URL length=${result.length}`);
5024
+ emfLog(`convertEmfInternal: SUCCESS, data URL length=${result.length}`);
4941
5025
  } else {
4942
- emfWarn("convertEmfToDataUrl: exportCanvasToPngDataUrl returned null");
5026
+ emfWarn("convertEmfInternal: exportCanvasToPngDataUrl returned null");
4943
5027
  }
4944
- emfLog("=== convertEmfToDataUrl END ===");
5028
+ emfLog("=== convertEmfInternal END ===");
4945
5029
  return result;
4946
5030
  } catch (err) {
4947
- emfWarn("convertEmfToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
4948
- console.warn("[pptx-editor] EMF conversion failed:", err instanceof Error ? err.message : err);
5031
+ emfWarn("convertEmfInternal: EXCEPTION:", err instanceof Error ? err.message : err);
5032
+ console.warn("[emf-converter] EMF conversion failed:", err instanceof Error ? err.message : err);
4949
5033
  return null;
4950
5034
  }
4951
5035
  }
4952
- async function convertWmfToDataUrl(buffer, options, recursionDepth = 0) {
4953
- if (recursionDepth > MAX_METAFILE_RECURSION) {
4954
- return null;
4955
- }
5036
+ async function convertWmfInternal(buffer, view, options, recursionDepth) {
4956
5037
  const opts = {};
4957
5038
  const dpiScale = opts.dpiScale ?? DEFAULT_DPI_SCALE;
4958
5039
  const effectiveMaxWidth = opts.maxWidth;
@@ -4963,20 +5044,19 @@ async function convertWmfToDataUrl(buffer, options, recursionDepth = 0) {
4963
5044
  };
4964
5045
  try {
4965
5046
  emfLog(
4966
- "=== convertWmfToDataUrl START ===",
5047
+ "=== convertWmfInternal START ===",
4967
5048
  `buffer=${buffer.byteLength} bytes, dpiScale=${dpiScale}`
4968
5049
  );
4969
- const view = new DataView(buffer);
4970
5050
  const header = parseWmfHeader(view);
4971
5051
  if (!header) {
4972
- emfLog("convertWmfToDataUrl: parseWmfHeader returned null");
5052
+ emfLog("convertWmfInternal: parseWmfHeader returned null");
4973
5053
  return null;
4974
5054
  }
4975
5055
  const logicalW = header.boundsRight - header.boundsLeft;
4976
5056
  const logicalH = header.boundsBottom - header.boundsTop;
4977
- emfLog(`convertWmfToDataUrl: logicalSize=${logicalW}\xD7${logicalH}`);
5057
+ emfLog(`convertWmfInternal: logicalSize=${logicalW}\xD7${logicalH}`);
4978
5058
  if (logicalW <= 0 || logicalH <= 0) {
4979
- emfLog("convertWmfToDataUrl: invalid dimensions \u2014 returning null");
5059
+ emfLog("convertWmfInternal: invalid dimensions, returning null");
4980
5060
  return null;
4981
5061
  }
4982
5062
  const setup = createCanvas(
@@ -4995,12 +5075,12 @@ async function convertWmfToDataUrl(buffer, options, recursionDepth = 0) {
4995
5075
  replayWmfRecords(view, ctx, header, canvas.width, canvas.height, replayOptions);
4996
5076
  ctx.restore();
4997
5077
  const result = await exportCanvasToPngDataUrl(canvas);
4998
- emfLog(`convertWmfToDataUrl: result=${result ? `dataUrl len=${result.length}` : "null"}`);
4999
- emfLog("=== convertWmfToDataUrl END ===");
5078
+ emfLog(`convertWmfInternal: result=${result ? `dataUrl len=${result.length}` : "null"}`);
5079
+ emfLog("=== convertWmfInternal END ===");
5000
5080
  return result;
5001
5081
  } catch (err) {
5002
- emfWarn("convertWmfToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
5003
- console.warn("[pptx-editor] WMF conversion failed:", err instanceof Error ? err.message : err);
5082
+ emfWarn("convertWmfInternal: EXCEPTION:", err instanceof Error ? err.message : err);
5083
+ console.warn("[emf-converter] WMF conversion failed:", err instanceof Error ? err.message : err);
5004
5084
  return null;
5005
5085
  }
5006
5086
  }
@@ -96143,7 +96223,7 @@ var init_PptxHandlerRuntimeMediaData = __esm({
96143
96223
  try {
96144
96224
  if (ext === "emf" || ext === "wmf") {
96145
96225
  const binaryBuffer = await imageFile2.async("arraybuffer");
96146
- const converted = ext === "emf" ? await convertEmfToDataUrl(binaryBuffer) : await convertWmfToDataUrl(binaryBuffer);
96226
+ const converted = await convertMetafileToDataUrl(binaryBuffer);
96147
96227
  if (converted) {
96148
96228
  this.imageDataCache.set(imagePath, converted);
96149
96229
  return converted;
Binary file
Binary file