@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.
@@ -11685,6 +11685,18 @@ const toggleLogicalFlipInMatrix = (matrix, flipX, flipY) => {
11685
11685
  const sy = flipY ? -1 : 1;
11686
11686
  return [matrix[0] * sx, matrix[1] * sx, matrix[2] * sy, matrix[3] * sy, matrix[4], matrix[5]];
11687
11687
  };
11688
+ const angleDistanceDeg = (a, b) => {
11689
+ const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11690
+ return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11691
+ };
11692
+ const normalizeMatrixForPersistedFlip = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11693
+ if (!persistedFlipX && !persistedFlipY) return matrix;
11694
+ if (!Number.isFinite(expectedCleanAngle)) return matrix;
11695
+ const toggledVisual = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11696
+ const cleanIfMatrixAlreadyHasFlip = fabric__namespace.util.qrDecompose(toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY)).angle ?? 0;
11697
+ const cleanIfMatrixLostFlip = fabric__namespace.util.qrDecompose(matrix).angle ?? 0;
11698
+ return angleDistanceDeg(cleanIfMatrixLostFlip, expectedCleanAngle) + 0.1 < angleDistanceDeg(cleanIfMatrixAlreadyHasFlip, expectedCleanAngle) ? toggledVisual : matrix;
11699
+ };
11688
11700
  function applyWarpAwareSelectionBorders(selection) {
11689
11701
  var _a2;
11690
11702
  if (selection.__pixldocsOrigASHasBorders !== void 0) {
@@ -15963,6 +15975,7 @@ const PageCanvas = react.forwardRef(
15963
15975
  }
15964
15976
  }
15965
15977
  const pendingCropGroupFrameBakes = [];
15978
+ const activeSelectionFlipRestores = [];
15966
15979
  for (const obj of activeObjects) {
15967
15980
  const objId = getObjectId(obj);
15968
15981
  if (!objId || objId === "__background__") continue;
@@ -16477,10 +16490,27 @@ const PageCanvas = react.forwardRef(
16477
16490
  const isLineObj = obj instanceof fabric__namespace.Line;
16478
16491
  const isAutoShrinkText = (sourceElement == null ? void 0 : sourceElement.type) === "text" && sourceElement.overflowPolicy === "auto-shrink";
16479
16492
  const autoShrinkStoredHeight = isAutoShrinkText ? sourceElement.height : void 0;
16480
- const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? obj.flipX ?? false;
16481
- const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? obj.flipY ?? false;
16482
- const cleanTransformMatrix = toggleLogicalFlipInMatrix(finalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16493
+ const objectFlipX = obj.flipX ?? false;
16494
+ const objectFlipY = obj.flipY ?? false;
16495
+ const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? objectFlipX;
16496
+ const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? objectFlipY;
16497
+ const isActiveSelectionResizeGesture = activeSelectionResizeHandle === "ml" || activeSelectionResizeHandle === "mr" || activeSelectionResizeHandle === "mt" || activeSelectionResizeHandle === "mb" || activeSelectionResizeHandle === "tl" || activeSelectionResizeHandle === "tr" || activeSelectionResizeHandle === "bl" || activeSelectionResizeHandle === "br";
16498
+ 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;
16499
+ const normalizedFinalAbsoluteMatrix = normalizeMatrixForPersistedFlip(
16500
+ toggleLogicalFlipInMatrix(
16501
+ finalAbsoluteMatrix,
16502
+ objectFlipX !== persistedFlipX,
16503
+ objectFlipY !== persistedFlipY
16504
+ ),
16505
+ persistedFlipX,
16506
+ persistedFlipY,
16507
+ expectedCleanAngle
16508
+ );
16509
+ const cleanTransformMatrix = toggleLogicalFlipInMatrix(normalizedFinalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16483
16510
  const persistedDecomposed = fabric__namespace.util.qrDecompose(cleanTransformMatrix);
16511
+ if (isActiveSelection && (obj instanceof fabric__namespace.FabricImage || obj instanceof fabric__namespace.Group && obj.__cropGroup)) {
16512
+ activeSelectionFlipRestores.push({ obj, flipX: persistedFlipX, flipY: persistedFlipY });
16513
+ }
16484
16514
  const elementUpdate = {
16485
16515
  left: storePos.left,
16486
16516
  top: storePos.top,
@@ -16496,7 +16526,7 @@ const PageCanvas = react.forwardRef(
16496
16526
  scaleY: finalScaleY,
16497
16527
  flipX: persistedFlipX,
16498
16528
  flipY: persistedFlipY,
16499
- transformMatrix: finalAbsoluteMatrix
16529
+ transformMatrix: cleanTransformMatrix
16500
16530
  };
16501
16531
  if (obj instanceof fabric__namespace.Textbox) {
16502
16532
  const bakedTextScaleUpdates = obj.__pixldocsBakedTextScaleUpdates;
@@ -16545,19 +16575,15 @@ const PageCanvas = react.forwardRef(
16545
16575
  elementUpdate.scaleY = 1;
16546
16576
  elementUpdate.skewX = 0;
16547
16577
  elementUpdate.skewY = 0;
16548
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16549
- fabric__namespace.util.composeMatrix({
16550
- translateX: cx,
16551
- translateY: cy,
16552
- angle: cleanAngle,
16553
- scaleX: 1,
16554
- scaleY: 1,
16555
- skewX: 0,
16556
- skewY: 0
16557
- }),
16558
- elementUpdate.flipX,
16559
- elementUpdate.flipY
16560
- );
16578
+ elementUpdate.transformMatrix = fabric__namespace.util.composeMatrix({
16579
+ translateX: cx,
16580
+ translateY: cy,
16581
+ angle: cleanAngle,
16582
+ scaleX: 1,
16583
+ scaleY: 1,
16584
+ skewX: 0,
16585
+ skewY: 0
16586
+ });
16561
16587
  } catch {
16562
16588
  }
16563
16589
  }
@@ -16591,19 +16617,15 @@ const PageCanvas = react.forwardRef(
16591
16617
  elementUpdate.scaleY = 1;
16592
16618
  elementUpdate.skewX = 0;
16593
16619
  elementUpdate.skewY = 0;
16594
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16595
- fabric__namespace.util.composeMatrix({
16596
- translateX: cx,
16597
- translateY: cy,
16598
- angle: cleanAngleI,
16599
- scaleX: 1,
16600
- scaleY: 1,
16601
- skewX: 0,
16602
- skewY: 0
16603
- }),
16604
- elementUpdate.flipX,
16605
- elementUpdate.flipY
16606
- );
16620
+ elementUpdate.transformMatrix = fabric__namespace.util.composeMatrix({
16621
+ translateX: cx,
16622
+ translateY: cy,
16623
+ angle: cleanAngleI,
16624
+ scaleX: 1,
16625
+ scaleY: 1,
16626
+ skewX: 0,
16627
+ skewY: 0
16628
+ });
16607
16629
  } catch {
16608
16630
  }
16609
16631
  }
@@ -16712,6 +16734,11 @@ const PageCanvas = react.forwardRef(
16712
16734
  skipSelectionClearOnDiscardRef.current = true;
16713
16735
  skipActiveSelectionBakeOnClearRef.current = true;
16714
16736
  try {
16737
+ for (const restore of activeSelectionFlipRestores) {
16738
+ restore.obj.set({ flipX: restore.flipX, flipY: restore.flipY });
16739
+ restore.obj.setCoords();
16740
+ restore.obj.dirty = true;
16741
+ }
16715
16742
  fabricCanvas.discardActiveObject();
16716
16743
  } finally {
16717
16744
  skipActiveSelectionBakeOnClearRef.current = false;
@@ -25902,9 +25929,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25902
25929
  }
25903
25930
  return svgString;
25904
25931
  }
25905
- const resolvedPackageVersion = "0.5.442";
25932
+ const resolvedPackageVersion = "0.5.443";
25906
25933
  const PACKAGE_VERSION = resolvedPackageVersion;
25907
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.442";
25934
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.443";
25908
25935
  const roundParityValue = (value) => {
25909
25936
  if (typeof value !== "number") return value;
25910
25937
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26718,7 +26745,7 @@ class PixldocsRenderer {
26718
26745
  await this.waitForCanvasScene(container, cloned, i);
26719
26746
  }
26720
26747
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26721
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-m9l318xa.cjs"));
26748
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-C6WM_grg.cjs"));
26722
26749
  const prepared = preparePagesForExport(
26723
26750
  cloned.pages,
26724
26751
  canvasWidth,
@@ -29038,7 +29065,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29038
29065
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29039
29066
  sanitizeSvgTreeForPdf(svgToDraw);
29040
29067
  try {
29041
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-m9l318xa.cjs"));
29068
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-C6WM_grg.cjs"));
29042
29069
  try {
29043
29070
  await logTextMeasurementDiagnostic(svgToDraw);
29044
29071
  } catch {
@@ -29435,4 +29462,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29435
29462
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29436
29463
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29437
29464
  exports.warmTemplateFromForm = warmTemplateFromForm;
29438
- //# sourceMappingURL=index-SGFlXODe.cjs.map
29465
+ //# sourceMappingURL=index-BxmYD_or.cjs.map