@pixldocs/canvas-renderer 0.5.393 → 0.5.394

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.
@@ -10502,6 +10502,10 @@ function bakeEdgeFade(source, fade) {
10502
10502
  }
10503
10503
  const SELECTION_PRIMARY = "hsl(217, 91%, 60%)";
10504
10504
  const SELECTION_BORDER_SCALE = 2;
10505
+ const normalizeAngle180 = (angle) => {
10506
+ const n = (angle % 360 + 360) % 360;
10507
+ return n > 180 ? n - 360 : n;
10508
+ };
10505
10509
  let ensureCanvaControlRenders = () => {
10506
10510
  };
10507
10511
  try {
@@ -11432,7 +11436,7 @@ const bakeTextboxScaleIntoTypography = (obj, sourceElement) => {
11432
11436
  };
11433
11437
  return updates;
11434
11438
  };
11435
- function applyWarpAwareSelectionBorders(selection) {
11439
+ function applyWarpAwareSelectionBorders(selection, preferredGroupAngle) {
11436
11440
  var _a2;
11437
11441
  if (selection.__pixldocsOrigASHasBorders !== void 0) {
11438
11442
  selection.hasBorders = selection.__pixldocsOrigASHasBorders;
@@ -11444,17 +11448,13 @@ function applyWarpAwareSelectionBorders(selection) {
11444
11448
  if (selection.__pixldocsAlignedAngle == null) {
11445
11449
  const kids = selection.getObjects();
11446
11450
  if (kids.length >= 1) {
11447
- const norm = (a) => {
11448
- const n = (a % 360 + 360) % 360;
11449
- return n > 180 ? n - 360 : n;
11450
- };
11451
- const angleDelta = (a, b) => Math.abs(norm(a - b));
11451
+ const angleDelta = (a, b) => Math.abs(normalizeAngle180(a - b));
11452
11452
  const selectionMatrix = selection.calcTransformMatrix();
11453
11453
  const worldMatrices = kids.map((k) => fabric.util.multiplyTransformMatrices(
11454
11454
  selectionMatrix,
11455
11455
  k.calcOwnMatrix()
11456
11456
  ));
11457
- const worldAngles = worldMatrices.map((m) => norm(fabric.util.qrDecompose(m).angle ?? 0));
11457
+ const worldAngles = worldMatrices.map((m) => normalizeAngle180(fabric.util.qrDecompose(m).angle ?? 0));
11458
11458
  const worldPoints = [];
11459
11459
  for (const k of kids) {
11460
11460
  try {
@@ -11499,9 +11499,10 @@ function applyWarpAwareSelectionBorders(selection) {
11499
11499
  for (const b of buckets) b.area = orientedAreaForAngle(b.angle);
11500
11500
  buckets.sort((a, b) => b.count - a.count || a.area - b.area || Math.abs(b.angle) - Math.abs(a.angle));
11501
11501
  const dominant = buckets[0];
11502
- let targetAngle = null;
11502
+ const preferredAngle = typeof preferredGroupAngle === "number" && Number.isFinite(preferredGroupAngle) ? normalizeAngle180(preferredGroupAngle) : null;
11503
+ let targetAngle = preferredAngle;
11503
11504
  const isLogicalGroupSelection = !!selection.__pixldocsGroupSelection;
11504
- if (dominant && Math.abs(dominant.angle) > 0.5 && (isLogicalGroupSelection || kids.length === 1 || dominant.count >= 2 || dominant.count === kids.length)) {
11505
+ if (targetAngle == null && dominant && Math.abs(dominant.angle) > 0.5 && (isLogicalGroupSelection || kids.length === 1 || dominant.count >= 2 || dominant.count === kids.length)) {
11505
11506
  targetAngle = dominant.angle;
11506
11507
  }
11507
11508
  if (targetAngle != null) {
@@ -11638,6 +11639,11 @@ const PageCanvas = forwardRef(
11638
11639
  var _a2;
11639
11640
  selection.__pixldocsGroupSelection = groupId;
11640
11641
  delete selection.__pixldocsLogicalGroupIds;
11642
+ const pageNow = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId);
11643
+ const groupNode = pageNow ? findNodeById(pageNow.children ?? [], groupId) : null;
11644
+ const groupAngle = groupNode && isGroup(groupNode) && typeof groupNode.angle === "number" ? groupNode.angle : void 0;
11645
+ if (groupAngle !== void 0) selection.__pixldocsGroupAngle = groupAngle;
11646
+ else delete selection.__pixldocsGroupAngle;
11641
11647
  selection.hasBorders = true;
11642
11648
  const members = selection.getObjects();
11643
11649
  for (const prev of suppressGroupMemberBordersRef.current) {
@@ -11671,8 +11677,8 @@ const PageCanvas = forwardRef(
11671
11677
  m.lockScalingY = false;
11672
11678
  }
11673
11679
  }
11674
- applyWarpAwareSelectionBorders(selection);
11675
- }, []);
11680
+ applyWarpAwareSelectionBorders(selection, groupAngle);
11681
+ }, [pageId]);
11676
11682
  const pageBoundsOptions = useMemo(
11677
11683
  () => ({ pageContentWidth: canvasWidth, pageContentHeight: canvasHeight }),
11678
11684
  [canvasWidth, canvasHeight]
@@ -13564,15 +13570,7 @@ const PageCanvas = forwardRef(
13564
13570
  if (oid && memberIds.has(oid)) members.push(o);
13565
13571
  }
13566
13572
  if (members.length === 0) return null;
13567
- const TOL = 2;
13568
- const norm = (a) => {
13569
- const n = (a % 360 + 360) % 360;
13570
- return n > 180 ? n - 360 : n;
13571
- };
13572
- const angleDelta = (a, b) => {
13573
- const d = Math.abs(norm(a) - norm(b));
13574
- return Math.min(d, 360 - d);
13575
- };
13573
+ const savedGroupAngle = typeof g.angle === "number" && Number.isFinite(g.angle) ? normalizeAngle180(g.angle) : null;
13576
13574
  const worldPoints = [];
13577
13575
  for (const m of members) {
13578
13576
  (_a2 = m.setCoords) == null ? void 0 : _a2.call(m);
@@ -13583,31 +13581,35 @@ const PageCanvas = forwardRef(
13583
13581
  if (p) worldPoints.push({ x: p.x, y: p.y });
13584
13582
  }
13585
13583
  }
13586
- const orientedAreaForAngle = (angle) => {
13587
- if (worldPoints.length === 0) return Number.POSITIVE_INFINITY;
13588
- const r = -angle * Math.PI / 180;
13589
- const c = Math.cos(r), s = Math.sin(r);
13590
- let nX = Infinity, nY = Infinity, xX = -Infinity, xY = -Infinity;
13591
- for (const p of worldPoints) {
13592
- const xr = p.x * c - p.y * s;
13593
- const yr = p.x * s + p.y * c;
13594
- if (xr < nX) nX = xr;
13595
- if (yr < nY) nY = yr;
13596
- if (xr > xX) xX = xr;
13597
- if (yr > xY) xY = yr;
13584
+ const getLegacyDominantAngle = () => {
13585
+ var _a3;
13586
+ const areaFor = (angle) => {
13587
+ if (worldPoints.length === 0) return Number.POSITIVE_INFINITY;
13588
+ const r = -angle * Math.PI / 180;
13589
+ const c = Math.cos(r), s = Math.sin(r);
13590
+ let nX = Infinity, nY = Infinity, xX = -Infinity, xY = -Infinity;
13591
+ for (const p of worldPoints) {
13592
+ const xr = p.x * c - p.y * s;
13593
+ const yr = p.x * s + p.y * c;
13594
+ if (xr < nX) nX = xr;
13595
+ if (yr < nY) nY = yr;
13596
+ if (xr > xX) xX = xr;
13597
+ if (yr > xY) xY = yr;
13598
+ }
13599
+ return Math.max(1, (xX - nX) * (xY - nY));
13600
+ };
13601
+ const buckets = [];
13602
+ for (const m of members) {
13603
+ const a = normalizeAngle180(m.angle ?? 0);
13604
+ const b = buckets.find((x) => Math.abs(normalizeAngle180(x.angle - a)) <= 2);
13605
+ if (b) b.count++;
13606
+ else buckets.push({ angle: a, count: 1, area: Number.POSITIVE_INFINITY });
13598
13607
  }
13599
- return Math.max(1, (xX - nX) * (xY - nY));
13608
+ for (const b of buckets) b.area = areaFor(b.angle);
13609
+ buckets.sort((a, b) => b.count - a.count || a.area - b.area || Math.abs(b.angle) - Math.abs(a.angle));
13610
+ return ((_a3 = buckets[0]) == null ? void 0 : _a3.angle) ?? 0;
13600
13611
  };
13601
- const buckets = [];
13602
- for (const m of members) {
13603
- const a = norm(m.angle ?? 0);
13604
- const b = buckets.find((x) => angleDelta(x.angle, a) <= TOL);
13605
- if (b) b.count++;
13606
- else buckets.push({ angle: a, count: 1, area: Number.POSITIVE_INFINITY });
13607
- }
13608
- for (const b of buckets) b.area = orientedAreaForAngle(b.angle);
13609
- buckets.sort((a, b) => b.count - a.count || a.area - b.area || Math.abs(b.angle) - Math.abs(a.angle));
13610
- const a0 = buckets[0].angle;
13612
+ const a0 = savedGroupAngle ?? getLegacyDominantAngle();
13611
13613
  const rad = -a0 * Math.PI / 180;
13612
13614
  const cos = Math.cos(rad), sin = Math.sin(rad);
13613
13615
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
@@ -15351,6 +15353,14 @@ const PageCanvas = forwardRef(
15351
15353
  360 - Math.abs(currentSelAngle - startSelAngle)
15352
15354
  );
15353
15355
  const hadRotation = isActiveSelection && activeObj && angleDelta > 0.01;
15356
+ if (hadRotation && activeObj instanceof fabric.ActiveSelection && activeGroupSelectionId === groupToMove.id) {
15357
+ useEditorStore.getState().updateNode(
15358
+ groupToMove.id,
15359
+ { angle: currentSelAngle },
15360
+ { recordHistory: false, skipLayoutRecalc: true }
15361
+ );
15362
+ activeObj.__pixldocsGroupAngle = currentSelAngle;
15363
+ }
15354
15364
  if (!hadScale && !hadRotation && (Math.abs(deltaX) > 0.1 || Math.abs(deltaY) > 0.1)) {
15355
15365
  const { updateNode: updateNodeStore, commitHistory: commitHistoryStore, getCurrentElements } = useEditorStore.getState();
15356
15366
  const newLeft = (groupToMove.left ?? 0) + deltaX;
@@ -25097,9 +25107,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25097
25107
  }
25098
25108
  return svgString;
25099
25109
  }
25100
- const resolvedPackageVersion = "0.5.393";
25110
+ const resolvedPackageVersion = "0.5.394";
25101
25111
  const PACKAGE_VERSION = resolvedPackageVersion;
25102
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.393";
25112
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.394";
25103
25113
  const roundParityValue = (value) => {
25104
25114
  if (typeof value !== "number") return value;
25105
25115
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -25913,7 +25923,7 @@ class PixldocsRenderer {
25913
25923
  await this.waitForCanvasScene(container, cloned, i);
25914
25924
  }
25915
25925
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
25916
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-DBJQBWsb.js");
25926
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BUj20FDX.js");
25917
25927
  const prepared = preparePagesForExport(
25918
25928
  cloned.pages,
25919
25929
  canvasWidth,
@@ -28233,7 +28243,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
28233
28243
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
28234
28244
  sanitizeSvgTreeForPdf(svgToDraw);
28235
28245
  try {
28236
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-DBJQBWsb.js");
28246
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BUj20FDX.js");
28237
28247
  try {
28238
28248
  await logTextMeasurementDiagnostic(svgToDraw);
28239
28249
  } catch {
@@ -28633,4 +28643,4 @@ export {
28633
28643
  buildTeaserBlurFlatKeys as y,
28634
28644
  collectFontDescriptorsFromConfig as z
28635
28645
  };
28636
- //# sourceMappingURL=index-CaUhUYZP.js.map
28646
+ //# sourceMappingURL=index-CgnT1WJ6.js.map