@pixldocs/canvas-renderer 0.5.442 → 0.5.443

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.
@@ -11667,6 +11667,18 @@ const toggleLogicalFlipInMatrix = (matrix, flipX, flipY) => {
11667
11667
  const sy = flipY ? -1 : 1;
11668
11668
  return [matrix[0] * sx, matrix[1] * sx, matrix[2] * sy, matrix[3] * sy, matrix[4], matrix[5]];
11669
11669
  };
11670
+ const angleDistanceDeg = (a, b) => {
11671
+ const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11672
+ return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11673
+ };
11674
+ const normalizeMatrixForPersistedFlip = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11675
+ if (!persistedFlipX && !persistedFlipY) return matrix;
11676
+ if (!Number.isFinite(expectedCleanAngle)) return matrix;
11677
+ const toggledVisual = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11678
+ const cleanIfMatrixAlreadyHasFlip = fabric.util.qrDecompose(toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY)).angle ?? 0;
11679
+ const cleanIfMatrixLostFlip = fabric.util.qrDecompose(matrix).angle ?? 0;
11680
+ return angleDistanceDeg(cleanIfMatrixLostFlip, expectedCleanAngle) + 0.1 < angleDistanceDeg(cleanIfMatrixAlreadyHasFlip, expectedCleanAngle) ? toggledVisual : matrix;
11681
+ };
11670
11682
  function applyWarpAwareSelectionBorders(selection) {
11671
11683
  var _a2;
11672
11684
  if (selection.__pixldocsOrigASHasBorders !== void 0) {
@@ -15945,6 +15957,7 @@ const PageCanvas = forwardRef(
15945
15957
  }
15946
15958
  }
15947
15959
  const pendingCropGroupFrameBakes = [];
15960
+ const activeSelectionFlipRestores = [];
15948
15961
  for (const obj of activeObjects) {
15949
15962
  const objId = getObjectId(obj);
15950
15963
  if (!objId || objId === "__background__") continue;
@@ -16459,10 +16472,27 @@ const PageCanvas = forwardRef(
16459
16472
  const isLineObj = obj instanceof fabric.Line;
16460
16473
  const isAutoShrinkText = (sourceElement == null ? void 0 : sourceElement.type) === "text" && sourceElement.overflowPolicy === "auto-shrink";
16461
16474
  const autoShrinkStoredHeight = isAutoShrinkText ? sourceElement.height : void 0;
16462
- const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? obj.flipX ?? false;
16463
- const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? obj.flipY ?? false;
16464
- const cleanTransformMatrix = toggleLogicalFlipInMatrix(finalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16475
+ const objectFlipX = obj.flipX ?? false;
16476
+ const objectFlipY = obj.flipY ?? false;
16477
+ const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? objectFlipX;
16478
+ const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? objectFlipY;
16479
+ const isActiveSelectionResizeGesture = activeSelectionResizeHandle === "ml" || activeSelectionResizeHandle === "mr" || activeSelectionResizeHandle === "mt" || activeSelectionResizeHandle === "mb" || activeSelectionResizeHandle === "tl" || activeSelectionResizeHandle === "tr" || activeSelectionResizeHandle === "bl" || activeSelectionResizeHandle === "br";
16480
+ const expectedCleanAngle = isActiveSelection && isActiveSelectionResizeGesture ? Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? (sourceElement == null ? void 0 : sourceElement.angle) ?? 0 : Number.isFinite(obj.angle) ? obj.angle ?? 0 : void 0 : void 0;
16481
+ const normalizedFinalAbsoluteMatrix = normalizeMatrixForPersistedFlip(
16482
+ toggleLogicalFlipInMatrix(
16483
+ finalAbsoluteMatrix,
16484
+ objectFlipX !== persistedFlipX,
16485
+ objectFlipY !== persistedFlipY
16486
+ ),
16487
+ persistedFlipX,
16488
+ persistedFlipY,
16489
+ expectedCleanAngle
16490
+ );
16491
+ const cleanTransformMatrix = toggleLogicalFlipInMatrix(normalizedFinalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16465
16492
  const persistedDecomposed = fabric.util.qrDecompose(cleanTransformMatrix);
16493
+ if (isActiveSelection && (obj instanceof fabric.FabricImage || obj instanceof fabric.Group && obj.__cropGroup)) {
16494
+ activeSelectionFlipRestores.push({ obj, flipX: persistedFlipX, flipY: persistedFlipY });
16495
+ }
16466
16496
  const elementUpdate = {
16467
16497
  left: storePos.left,
16468
16498
  top: storePos.top,
@@ -16478,7 +16508,7 @@ const PageCanvas = forwardRef(
16478
16508
  scaleY: finalScaleY,
16479
16509
  flipX: persistedFlipX,
16480
16510
  flipY: persistedFlipY,
16481
- transformMatrix: finalAbsoluteMatrix
16511
+ transformMatrix: cleanTransformMatrix
16482
16512
  };
16483
16513
  if (obj instanceof fabric.Textbox) {
16484
16514
  const bakedTextScaleUpdates = obj.__pixldocsBakedTextScaleUpdates;
@@ -16527,19 +16557,15 @@ const PageCanvas = forwardRef(
16527
16557
  elementUpdate.scaleY = 1;
16528
16558
  elementUpdate.skewX = 0;
16529
16559
  elementUpdate.skewY = 0;
16530
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16531
- fabric.util.composeMatrix({
16532
- translateX: cx,
16533
- translateY: cy,
16534
- angle: cleanAngle,
16535
- scaleX: 1,
16536
- scaleY: 1,
16537
- skewX: 0,
16538
- skewY: 0
16539
- }),
16540
- elementUpdate.flipX,
16541
- elementUpdate.flipY
16542
- );
16560
+ elementUpdate.transformMatrix = fabric.util.composeMatrix({
16561
+ translateX: cx,
16562
+ translateY: cy,
16563
+ angle: cleanAngle,
16564
+ scaleX: 1,
16565
+ scaleY: 1,
16566
+ skewX: 0,
16567
+ skewY: 0
16568
+ });
16543
16569
  } catch {
16544
16570
  }
16545
16571
  }
@@ -16573,19 +16599,15 @@ const PageCanvas = forwardRef(
16573
16599
  elementUpdate.scaleY = 1;
16574
16600
  elementUpdate.skewX = 0;
16575
16601
  elementUpdate.skewY = 0;
16576
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16577
- fabric.util.composeMatrix({
16578
- translateX: cx,
16579
- translateY: cy,
16580
- angle: cleanAngleI,
16581
- scaleX: 1,
16582
- scaleY: 1,
16583
- skewX: 0,
16584
- skewY: 0
16585
- }),
16586
- elementUpdate.flipX,
16587
- elementUpdate.flipY
16588
- );
16602
+ elementUpdate.transformMatrix = fabric.util.composeMatrix({
16603
+ translateX: cx,
16604
+ translateY: cy,
16605
+ angle: cleanAngleI,
16606
+ scaleX: 1,
16607
+ scaleY: 1,
16608
+ skewX: 0,
16609
+ skewY: 0
16610
+ });
16589
16611
  } catch {
16590
16612
  }
16591
16613
  }
@@ -16694,6 +16716,11 @@ const PageCanvas = forwardRef(
16694
16716
  skipSelectionClearOnDiscardRef.current = true;
16695
16717
  skipActiveSelectionBakeOnClearRef.current = true;
16696
16718
  try {
16719
+ for (const restore of activeSelectionFlipRestores) {
16720
+ restore.obj.set({ flipX: restore.flipX, flipY: restore.flipY });
16721
+ restore.obj.setCoords();
16722
+ restore.obj.dirty = true;
16723
+ }
16697
16724
  fabricCanvas.discardActiveObject();
16698
16725
  } finally {
16699
16726
  skipActiveSelectionBakeOnClearRef.current = false;
@@ -25884,9 +25911,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25884
25911
  }
25885
25912
  return svgString;
25886
25913
  }
25887
- const resolvedPackageVersion = "0.5.442";
25914
+ const resolvedPackageVersion = "0.5.443";
25888
25915
  const PACKAGE_VERSION = resolvedPackageVersion;
25889
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.442";
25916
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.443";
25890
25917
  const roundParityValue = (value) => {
25891
25918
  if (typeof value !== "number") return value;
25892
25919
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26700,7 +26727,7 @@ class PixldocsRenderer {
26700
26727
  await this.waitForCanvasScene(container, cloned, i);
26701
26728
  }
26702
26729
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26703
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-Hv54w3Cm.js");
26730
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-Chx_7ffv.js");
26704
26731
  const prepared = preparePagesForExport(
26705
26732
  cloned.pages,
26706
26733
  canvasWidth,
@@ -29020,7 +29047,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29020
29047
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29021
29048
  sanitizeSvgTreeForPdf(svgToDraw);
29022
29049
  try {
29023
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-Hv54w3Cm.js");
29050
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-Chx_7ffv.js");
29024
29051
  try {
29025
29052
  await logTextMeasurementDiagnostic(svgToDraw);
29026
29053
  } catch {
@@ -29420,4 +29447,4 @@ export {
29420
29447
  buildTeaserBlurFlatKeys as y,
29421
29448
  collectFontDescriptorsFromConfig as z
29422
29449
  };
29423
- //# sourceMappingURL=index-DFHTSlHV.js.map
29450
+ //# sourceMappingURL=index-mfdztOqY.js.map