@json-to-office/core-docx 0.38.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2677,6 +2677,7 @@ import { ImageRun } from "docx";
2677
2677
  var SVG_RASTER_SCALE = 3;
2678
2678
  var SVG_MAX_EDGE_PX = 4096;
2679
2679
  var SVG_MIN_EDGE_PX = 16;
2680
+ var SVG_MAX_TOTAL_PX = 1e6;
2680
2681
  var resvgModule;
2681
2682
  function loadResvg() {
2682
2683
  resvgModule ??= import("@resvg/resvg-js");
@@ -2688,6 +2689,13 @@ function toRasterPx(px) {
2688
2689
  Math.max(SVG_MIN_EDGE_PX, Math.round(px * SVG_RASTER_SCALE))
2689
2690
  );
2690
2691
  }
2692
+ function capToPixelBudget(edge, aspect) {
2693
+ if (!Number.isFinite(aspect) || aspect <= 0) return void 0;
2694
+ const total = edge * edge * aspect;
2695
+ if (total <= SVG_MAX_TOTAL_PX) return edge;
2696
+ const scaled = Math.floor(edge * Math.sqrt(SVG_MAX_TOTAL_PX / total));
2697
+ return scaled >= SVG_MIN_EDGE_PX ? scaled : void 0;
2698
+ }
2691
2699
  async function rasterizeSvgFallback(svg, transformation) {
2692
2700
  let Resvg;
2693
2701
  try {
@@ -2704,8 +2712,22 @@ async function rasterizeSvgFallback(svg, transformation) {
2704
2712
  const markup = svg.toString("utf-8");
2705
2713
  const probeImage = new Resvg(markup);
2706
2714
  const wide = probeImage.width / probeImage.height > transformation.width / transformation.height;
2707
- const fitTo = wide ? { mode: "height", value: toRasterPx(transformation.height) } : { mode: "width", value: toRasterPx(transformation.width) };
2708
- return Buffer.from(new Resvg(markup, { fitTo }).render().asPng());
2715
+ const mode = wide ? "height" : "width";
2716
+ const value = capToPixelBudget(
2717
+ toRasterPx(wide ? transformation.height : transformation.width),
2718
+ wide ? probeImage.width / probeImage.height : probeImage.height / probeImage.width
2719
+ );
2720
+ if (value === void 0) {
2721
+ reportWarning(
2722
+ "image",
2723
+ "IMAGE_SVG_RASTER_SKIPPED",
2724
+ "Inline SVG is too far from square to rasterize within the fallback pixel budget, so its fallback only renders in Word 2016+."
2725
+ );
2726
+ return void 0;
2727
+ }
2728
+ return Buffer.from(
2729
+ new Resvg(markup, { fitTo: { mode, value } }).render().asPng()
2730
+ );
2709
2731
  } catch (error) {
2710
2732
  reportWarning(
2711
2733
  "image",