@pixldocs/canvas-renderer 0.5.442 → 0.5.444

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.
@@ -11679,12 +11679,31 @@ const applyTransformPreservingFlip = (obj, matrix) => {
11679
11679
  }
11680
11680
  obj.set({ scaleX: sx, scaleY: sy, flipX, flipY });
11681
11681
  };
11682
+ const restorePersistedFlipState = (obj, flipX, flipY) => {
11683
+ const sx = Math.abs(Number(obj.scaleX ?? 1)) || 1;
11684
+ const sy = Math.abs(Number(obj.scaleY ?? 1)) || 1;
11685
+ obj.set({ scaleX: sx, scaleY: sy, flipX, flipY });
11686
+ obj.setCoords();
11687
+ obj.dirty = true;
11688
+ };
11682
11689
  const toggleLogicalFlipInMatrix = (matrix, flipX, flipY) => {
11683
11690
  if (!flipX && !flipY) return matrix;
11684
11691
  const sx = flipX ? -1 : 1;
11685
11692
  const sy = flipY ? -1 : 1;
11686
11693
  return [matrix[0] * sx, matrix[1] * sx, matrix[2] * sy, matrix[3] * sy, matrix[4], matrix[5]];
11687
11694
  };
11695
+ const angleDistanceDeg = (a, b) => {
11696
+ const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11697
+ return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11698
+ };
11699
+ const normalizeMatrixForPersistedFlip = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11700
+ if (!persistedFlipX && !persistedFlipY) return matrix;
11701
+ if (!Number.isFinite(expectedCleanAngle)) return matrix;
11702
+ const toggledVisual = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11703
+ const cleanIfMatrixAlreadyHasFlip = fabric__namespace.util.qrDecompose(toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY)).angle ?? 0;
11704
+ const cleanIfMatrixLostFlip = fabric__namespace.util.qrDecompose(matrix).angle ?? 0;
11705
+ return angleDistanceDeg(cleanIfMatrixLostFlip, expectedCleanAngle) + 0.1 < angleDistanceDeg(cleanIfMatrixAlreadyHasFlip, expectedCleanAngle) ? toggledVisual : matrix;
11706
+ };
11688
11707
  function applyWarpAwareSelectionBorders(selection) {
11689
11708
  var _a2;
11690
11709
  if (selection.__pixldocsOrigASHasBorders !== void 0) {
@@ -15963,6 +15982,7 @@ const PageCanvas = react.forwardRef(
15963
15982
  }
15964
15983
  }
15965
15984
  const pendingCropGroupFrameBakes = [];
15985
+ const activeSelectionFlipRestores = [];
15966
15986
  for (const obj of activeObjects) {
15967
15987
  const objId = getObjectId(obj);
15968
15988
  if (!objId || objId === "__background__") continue;
@@ -16477,10 +16497,27 @@ const PageCanvas = react.forwardRef(
16477
16497
  const isLineObj = obj instanceof fabric__namespace.Line;
16478
16498
  const isAutoShrinkText = (sourceElement == null ? void 0 : sourceElement.type) === "text" && sourceElement.overflowPolicy === "auto-shrink";
16479
16499
  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);
16500
+ const objectFlipX = obj.flipX ?? false;
16501
+ const objectFlipY = obj.flipY ?? false;
16502
+ const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? objectFlipX;
16503
+ const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? objectFlipY;
16504
+ const isActiveSelectionResizeGesture = activeSelectionResizeHandle === "ml" || activeSelectionResizeHandle === "mr" || activeSelectionResizeHandle === "mt" || activeSelectionResizeHandle === "mb" || activeSelectionResizeHandle === "tl" || activeSelectionResizeHandle === "tr" || activeSelectionResizeHandle === "bl" || activeSelectionResizeHandle === "br";
16505
+ 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;
16506
+ const normalizedFinalAbsoluteMatrix = normalizeMatrixForPersistedFlip(
16507
+ toggleLogicalFlipInMatrix(
16508
+ finalAbsoluteMatrix,
16509
+ objectFlipX !== persistedFlipX,
16510
+ objectFlipY !== persistedFlipY
16511
+ ),
16512
+ persistedFlipX,
16513
+ persistedFlipY,
16514
+ expectedCleanAngle
16515
+ );
16516
+ const cleanTransformMatrix = toggleLogicalFlipInMatrix(normalizedFinalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16483
16517
  const persistedDecomposed = fabric__namespace.util.qrDecompose(cleanTransformMatrix);
16518
+ if (isActiveSelection && (obj instanceof fabric__namespace.FabricImage || obj instanceof fabric__namespace.Group && obj.__cropGroup)) {
16519
+ activeSelectionFlipRestores.push({ obj, flipX: persistedFlipX, flipY: persistedFlipY });
16520
+ }
16484
16521
  const elementUpdate = {
16485
16522
  left: storePos.left,
16486
16523
  top: storePos.top,
@@ -16496,7 +16533,7 @@ const PageCanvas = react.forwardRef(
16496
16533
  scaleY: finalScaleY,
16497
16534
  flipX: persistedFlipX,
16498
16535
  flipY: persistedFlipY,
16499
- transformMatrix: finalAbsoluteMatrix
16536
+ transformMatrix: cleanTransformMatrix
16500
16537
  };
16501
16538
  if (obj instanceof fabric__namespace.Textbox) {
16502
16539
  const bakedTextScaleUpdates = obj.__pixldocsBakedTextScaleUpdates;
@@ -16545,19 +16582,15 @@ const PageCanvas = react.forwardRef(
16545
16582
  elementUpdate.scaleY = 1;
16546
16583
  elementUpdate.skewX = 0;
16547
16584
  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
- );
16585
+ elementUpdate.transformMatrix = fabric__namespace.util.composeMatrix({
16586
+ translateX: cx,
16587
+ translateY: cy,
16588
+ angle: cleanAngle,
16589
+ scaleX: 1,
16590
+ scaleY: 1,
16591
+ skewX: 0,
16592
+ skewY: 0
16593
+ });
16561
16594
  } catch {
16562
16595
  }
16563
16596
  }
@@ -16591,19 +16624,15 @@ const PageCanvas = react.forwardRef(
16591
16624
  elementUpdate.scaleY = 1;
16592
16625
  elementUpdate.skewX = 0;
16593
16626
  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
- );
16627
+ elementUpdate.transformMatrix = fabric__namespace.util.composeMatrix({
16628
+ translateX: cx,
16629
+ translateY: cy,
16630
+ angle: cleanAngleI,
16631
+ scaleX: 1,
16632
+ scaleY: 1,
16633
+ skewX: 0,
16634
+ skewY: 0
16635
+ });
16607
16636
  } catch {
16608
16637
  }
16609
16638
  }
@@ -16712,10 +16741,16 @@ const PageCanvas = react.forwardRef(
16712
16741
  skipSelectionClearOnDiscardRef.current = true;
16713
16742
  skipActiveSelectionBakeOnClearRef.current = true;
16714
16743
  try {
16744
+ for (const restore of activeSelectionFlipRestores) {
16745
+ restorePersistedFlipState(restore.obj, restore.flipX, restore.flipY);
16746
+ }
16715
16747
  fabricCanvas.discardActiveObject();
16716
16748
  } finally {
16717
16749
  skipActiveSelectionBakeOnClearRef.current = false;
16718
16750
  }
16751
+ for (const restore of activeSelectionFlipRestores) {
16752
+ restorePersistedFlipState(restore.obj, restore.flipX, restore.flipY);
16753
+ }
16719
16754
  for (const bake of pendingCropGroupFrameBakes) {
16720
16755
  const ct = bake.obj.__cropData;
16721
16756
  if (!ct) continue;
@@ -25902,9 +25937,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25902
25937
  }
25903
25938
  return svgString;
25904
25939
  }
25905
- const resolvedPackageVersion = "0.5.442";
25940
+ const resolvedPackageVersion = "0.5.444";
25906
25941
  const PACKAGE_VERSION = resolvedPackageVersion;
25907
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.442";
25942
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.444";
25908
25943
  const roundParityValue = (value) => {
25909
25944
  if (typeof value !== "number") return value;
25910
25945
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26718,7 +26753,7 @@ class PixldocsRenderer {
26718
26753
  await this.waitForCanvasScene(container, cloned, i);
26719
26754
  }
26720
26755
  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"));
26756
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-Cy6iRFYd.cjs"));
26722
26757
  const prepared = preparePagesForExport(
26723
26758
  cloned.pages,
26724
26759
  canvasWidth,
@@ -29038,7 +29073,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29038
29073
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29039
29074
  sanitizeSvgTreeForPdf(svgToDraw);
29040
29075
  try {
29041
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-m9l318xa.cjs"));
29076
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-Cy6iRFYd.cjs"));
29042
29077
  try {
29043
29078
  await logTextMeasurementDiagnostic(svgToDraw);
29044
29079
  } catch {
@@ -29435,4 +29470,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29435
29470
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29436
29471
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29437
29472
  exports.warmTemplateFromForm = warmTemplateFromForm;
29438
- //# sourceMappingURL=index-SGFlXODe.cjs.map
29473
+ //# sourceMappingURL=index-DTJ_wDD-.cjs.map