@pixldocs/canvas-renderer 0.5.392 → 0.5.393

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.
@@ -13573,7 +13573,7 @@ const PageCanvas = react.forwardRef(
13573
13573
  return { left: minX, top: minY, right: maxX, bottom: maxY };
13574
13574
  };
13575
13575
  const groupFabricOrientedBBox = (g) => {
13576
- var _a2;
13576
+ var _a2, _b2;
13577
13577
  const memberIds = new Set(getAllElementIds(g.children ?? []));
13578
13578
  if (memberIds.size === 0) return null;
13579
13579
  const members = [];
@@ -13582,25 +13582,56 @@ const PageCanvas = react.forwardRef(
13582
13582
  if (oid && memberIds.has(oid)) members.push(o);
13583
13583
  }
13584
13584
  if (members.length === 0) return null;
13585
- const TOL = 0.5;
13585
+ const TOL = 2;
13586
+ const norm = (a) => {
13587
+ const n = (a % 360 + 360) % 360;
13588
+ return n > 180 ? n - 360 : n;
13589
+ };
13590
+ const angleDelta = (a, b) => {
13591
+ const d = Math.abs(norm(a) - norm(b));
13592
+ return Math.min(d, 360 - d);
13593
+ };
13594
+ const worldPoints = [];
13595
+ for (const m of members) {
13596
+ (_a2 = m.setCoords) == null ? void 0 : _a2.call(m);
13597
+ const aC = m.aCoords;
13598
+ if (!aC) continue;
13599
+ for (const k of ["tl", "tr", "br", "bl"]) {
13600
+ const p = aC[k];
13601
+ if (p) worldPoints.push({ x: p.x, y: p.y });
13602
+ }
13603
+ }
13604
+ const orientedAreaForAngle = (angle) => {
13605
+ if (worldPoints.length === 0) return Number.POSITIVE_INFINITY;
13606
+ const r = -angle * Math.PI / 180;
13607
+ const c = Math.cos(r), s = Math.sin(r);
13608
+ let nX = Infinity, nY = Infinity, xX = -Infinity, xY = -Infinity;
13609
+ for (const p of worldPoints) {
13610
+ const xr = p.x * c - p.y * s;
13611
+ const yr = p.x * s + p.y * c;
13612
+ if (xr < nX) nX = xr;
13613
+ if (yr < nY) nY = yr;
13614
+ if (xr > xX) xX = xr;
13615
+ if (yr > xY) xY = yr;
13616
+ }
13617
+ return Math.max(1, (xX - nX) * (xY - nY));
13618
+ };
13586
13619
  const buckets = [];
13587
13620
  for (const m of members) {
13588
- const a = ((m.angle ?? 0) % 360 + 360) % 360;
13589
- const b = buckets.find((x) => {
13590
- const d = Math.min(Math.abs(x.angle - a), 360 - Math.abs(x.angle - a));
13591
- return d <= TOL;
13592
- });
13621
+ const a = norm(m.angle ?? 0);
13622
+ const b = buckets.find((x) => angleDelta(x.angle, a) <= TOL);
13593
13623
  if (b) b.count++;
13594
- else buckets.push({ angle: a, count: 1 });
13624
+ else buckets.push({ angle: a, count: 1, area: Number.POSITIVE_INFINITY });
13595
13625
  }
13596
- buckets.sort((a, b) => b.count - a.count);
13626
+ for (const b of buckets) b.area = orientedAreaForAngle(b.angle);
13627
+ buckets.sort((a, b) => b.count - a.count || a.area - b.area || Math.abs(b.angle) - Math.abs(a.angle));
13597
13628
  const a0 = buckets[0].angle;
13598
13629
  const rad = -a0 * Math.PI / 180;
13599
13630
  const cos = Math.cos(rad), sin = Math.sin(rad);
13600
13631
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
13601
13632
  let found = false;
13602
13633
  for (const m of members) {
13603
- (_a2 = m.setCoords) == null ? void 0 : _a2.call(m);
13634
+ (_b2 = m.setCoords) == null ? void 0 : _b2.call(m);
13604
13635
  const aC = m.aCoords;
13605
13636
  if (!aC) continue;
13606
13637
  for (const k of ["tl", "tr", "br", "bl"]) {
@@ -25084,9 +25115,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25084
25115
  }
25085
25116
  return svgString;
25086
25117
  }
25087
- const resolvedPackageVersion = "0.5.392";
25118
+ const resolvedPackageVersion = "0.5.393";
25088
25119
  const PACKAGE_VERSION = resolvedPackageVersion;
25089
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.392";
25120
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.393";
25090
25121
  const roundParityValue = (value) => {
25091
25122
  if (typeof value !== "number") return value;
25092
25123
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -25900,7 +25931,7 @@ class PixldocsRenderer {
25900
25931
  await this.waitForCanvasScene(container, cloned, i);
25901
25932
  }
25902
25933
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
25903
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DhWvQzRg.cjs"));
25934
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-BWhYgu3c.cjs"));
25904
25935
  const prepared = preparePagesForExport(
25905
25936
  cloned.pages,
25906
25937
  canvasWidth,
@@ -28220,7 +28251,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
28220
28251
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
28221
28252
  sanitizeSvgTreeForPdf(svgToDraw);
28222
28253
  try {
28223
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DhWvQzRg.cjs"));
28254
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-BWhYgu3c.cjs"));
28224
28255
  try {
28225
28256
  await logTextMeasurementDiagnostic(svgToDraw);
28226
28257
  } catch {
@@ -28617,4 +28648,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
28617
28648
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
28618
28649
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
28619
28650
  exports.warmTemplateFromForm = warmTemplateFromForm;
28620
- //# sourceMappingURL=index-B0qSXTeJ.cjs.map
28651
+ //# sourceMappingURL=index-B0Ej1RxQ.cjs.map