@pixldocs/canvas-renderer 0.5.451 → 0.5.453

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.
@@ -11693,13 +11693,35 @@ const angleDistanceDeg = (a, b) => {
11693
11693
  const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11694
11694
  return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11695
11695
  };
11696
- const normalizeMatrixForPersistedFlip = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11696
+ const normalizeSignedAngleDeg = (angle) => {
11697
+ if (!Number.isFinite(angle)) return 0;
11698
+ const normalized = (angle % 360 + 540) % 360 - 180;
11699
+ return Math.abs(normalized) < 1e-9 ? 0 : normalized;
11700
+ };
11701
+ const resolveActiveSelectionLocalAngle = (obj, sourceElement, activeSelection) => {
11702
+ var _a2;
11703
+ const objectAngle = Number.isFinite(obj.angle) ? obj.angle ?? 0 : 0;
11704
+ const isImageLike = obj instanceof fabric.FabricImage || obj instanceof fabric.Group && (obj.__cropGroup || ((_a2 = obj._ct) == null ? void 0 : _a2.isCropGroup));
11705
+ const hasPersistedFlip = !!((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY) || obj.flipX || obj.flipY);
11706
+ if (!isImageLike || !hasPersistedFlip || !Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle)) {
11707
+ return normalizeSignedAngleDeg(objectAngle);
11708
+ }
11709
+ return normalizeSignedAngleDeg((sourceElement.angle ?? 0) - ((activeSelection == null ? void 0 : activeSelection.angle) ?? 0));
11710
+ };
11711
+ const resolveStableFlippedAngle = (fabricAngle, sourceAngle, hasFlip, isRotationGesture = false) => {
11712
+ const current = Number.isFinite(fabricAngle) ? fabricAngle : sourceAngle ?? 0;
11713
+ if (!hasFlip || isRotationGesture || !Number.isFinite(sourceAngle)) return current;
11714
+ const src = sourceAngle;
11715
+ const isFabricFlipEncoding = angleDistanceDeg(current, src + 180) < 2 && angleDistanceDeg(current, src) > 90;
11716
+ return isFabricFlipEncoding ? src : current;
11717
+ };
11718
+ const stripPersistedFlipForStableAngle = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11697
11719
  if (!persistedFlipX && !persistedFlipY) return matrix;
11698
- if (!Number.isFinite(expectedCleanAngle)) return matrix;
11699
- const toggledVisual = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11700
- const cleanIfMatrixAlreadyHasFlip = fabric.util.qrDecompose(toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY)).angle ?? 0;
11701
- const cleanIfMatrixLostFlip = fabric.util.qrDecompose(matrix).angle ?? 0;
11702
- return angleDistanceDeg(cleanIfMatrixLostFlip, expectedCleanAngle) + 0.1 < angleDistanceDeg(cleanIfMatrixAlreadyHasFlip, expectedCleanAngle) ? toggledVisual : matrix;
11720
+ const toggled = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11721
+ if (!Number.isFinite(expectedCleanAngle)) return toggled;
11722
+ const asIsAngle = fabric.util.qrDecompose(matrix).angle ?? 0;
11723
+ const toggledAngle = fabric.util.qrDecompose(toggled).angle ?? 0;
11724
+ return angleDistanceDeg(toggledAngle, expectedCleanAngle) <= angleDistanceDeg(asIsAngle, expectedCleanAngle) ? toggled : matrix;
11703
11725
  };
11704
11726
  function applyWarpAwareSelectionBorders(selection) {
11705
11727
  var _a2;
@@ -14939,8 +14961,18 @@ const PageCanvas = forwardRef(
14939
14961
  child.__asLiveGestureKey = liveGestureKey;
14940
14962
  const childIdForAngle = getObjectId(child);
14941
14963
  const sourceChildForAngle = childIdForAngle ? elementsRef.current.find((el) => el.id === childIdForAngle) : null;
14942
- const isFlippedImageLikeChild = (child instanceof fabric.FabricImage || child instanceof fabric.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) && !!((sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipX) || (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipY)) && Number.isFinite(sourceChildForAngle == null ? void 0 : sourceChildForAngle.angle);
14943
- child.__asLiveOrigAngle = isFlippedImageLikeChild ? sourceChildForAngle.angle ?? 0 : Number.isFinite(child.angle) ? child.angle ?? 0 : 0;
14964
+ const persistedChildFlipX = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipX) ?? child.flipX ?? false;
14965
+ const persistedChildFlipY = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipY) ?? child.flipY ?? false;
14966
+ if (child instanceof fabric.FabricImage || child instanceof fabric.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) {
14967
+ child.set({ flipX: persistedChildFlipX, flipY: persistedChildFlipY });
14968
+ child.__asLivePersistedFlipX = persistedChildFlipX;
14969
+ child.__asLivePersistedFlipY = persistedChildFlipY;
14970
+ }
14971
+ child.__asLiveOrigAngle = resolveActiveSelectionLocalAngle(
14972
+ child,
14973
+ sourceChildForAngle,
14974
+ obj
14975
+ );
14944
14976
  }
14945
14977
  if (child instanceof fabric.Group && (child.__cropGroup || ((_n = child._ct) == null ? void 0 : _n.isCropGroup))) {
14946
14978
  const ct = child.__cropData;
@@ -14994,6 +15026,8 @@ const PageCanvas = forwardRef(
14994
15026
  child._set("scaleY", decC.scaleY);
14995
15027
  child._set("skewX", decC.skewX);
14996
15028
  child._set("skewY", decC.skewY);
15029
+ child._set("flipX", child.__asLivePersistedFlipX ?? child.flipX ?? false);
15030
+ child._set("flipY", child.__asLivePersistedFlipY ?? child.flipY ?? false);
14997
15031
  } catch {
14998
15032
  }
14999
15033
  try {
@@ -15051,6 +15085,8 @@ const PageCanvas = forwardRef(
15051
15085
  child._set("scaleY", decI.scaleY);
15052
15086
  child._set("skewX", decI.skewX);
15053
15087
  child._set("skewY", decI.skewY);
15088
+ child._set("flipX", child.__asLivePersistedFlipX ?? child.flipX ?? false);
15089
+ child._set("flipY", child.__asLivePersistedFlipY ?? child.flipY ?? false);
15054
15090
  } catch {
15055
15091
  }
15056
15092
  child.setCoords();
@@ -15946,12 +15982,15 @@ const PageCanvas = forwardRef(
15946
15982
  360 - Math.abs(currentSelAngle - startSelAngle)
15947
15983
  );
15948
15984
  const hadRotation = isActiveSelection && activeObj && angleDelta > 0.01;
15949
- if (!hadScale && !hadRotation && (Math.abs(deltaX) > 0.1 || Math.abs(deltaY) > 0.1)) {
15985
+ const isMoveOnlyLogicalGroupGesture = !hadScale && !hadRotation && (Math.abs(deltaX) > 0.1 || Math.abs(deltaY) > 0.1);
15986
+ if (isMoveOnlyLogicalGroupGesture || !hadScale && !hadRotation && activeGroupSelectionId === groupToMove.id) {
15950
15987
  const { updateNode: updateNodeStore, commitHistory: commitHistoryStore, getCurrentElements } = useEditorStore.getState();
15951
- const newLeft = (groupToMove.left ?? 0) + deltaX;
15952
- const newTop = (groupToMove.top ?? 0) + deltaY;
15953
- updateNodeStore(groupToMove.id, { left: newLeft, top: newTop }, { recordHistory: false, skipLayoutRecalc: true });
15954
- commitHistoryStore();
15988
+ if (isMoveOnlyLogicalGroupGesture) {
15989
+ const newLeft = (groupToMove.left ?? 0) + deltaX;
15990
+ const newTop = (groupToMove.top ?? 0) + deltaY;
15991
+ updateNodeStore(groupToMove.id, { left: newLeft, top: newTop }, { recordHistory: false, skipLayoutRecalc: true });
15992
+ commitHistoryStore();
15993
+ }
15955
15994
  pendingGroupDrillInRef.current = null;
15956
15995
  fabricCanvas.__activeEditingGroupId = null;
15957
15996
  setDrilledGroupBounds(null);
@@ -16071,7 +16110,7 @@ const PageCanvas = forwardRef(
16071
16110
  if (obj instanceof fabric.Group && obj.__cropGroup) {
16072
16111
  const ct = obj.__cropData;
16073
16112
  if (ct) {
16074
- const cropChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : obj.angle ?? 0;
16113
+ const cropChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric.ActiveSelection ? activeObj : null);
16075
16114
  const cropChildNormAngle = (cropChildLocalAngle % 360 + 360) % 360;
16076
16115
  const cropChildIsRotated = Math.abs(cropChildNormAngle) > 0.5 && Math.abs(cropChildNormAngle - 360) > 0.5;
16077
16116
  const cropHandle = activeSelectionResizeHandle;
@@ -16190,7 +16229,7 @@ const PageCanvas = forwardRef(
16190
16229
  useEditorStore.getState().updateElement(objId, { src: newSrc }, { recordHistory: false, skipLayoutRecalc: true });
16191
16230
  }
16192
16231
  } else if (isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
16193
- const imgChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : ((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY)) && Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : obj.angle ?? 0;
16232
+ const imgChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric.ActiveSelection ? activeObj : null);
16194
16233
  const imgChildNormAngle = (imgChildLocalAngle % 360 + 360) % 360;
16195
16234
  const imgChildIsRotated = Math.abs(imgChildNormAngle) > 0.5 && Math.abs(imgChildNormAngle - 360) > 0.5;
16196
16235
  const imgHandle = activeSelectionResizeHandle;
@@ -16509,18 +16548,30 @@ const PageCanvas = forwardRef(
16509
16548
  const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? objectFlipY;
16510
16549
  const isActiveSelectionResizeGesture = activeSelectionResizeHandle === "ml" || activeSelectionResizeHandle === "mr" || activeSelectionResizeHandle === "mt" || activeSelectionResizeHandle === "mb" || activeSelectionResizeHandle === "tl" || activeSelectionResizeHandle === "tr" || activeSelectionResizeHandle === "bl" || activeSelectionResizeHandle === "br";
16511
16550
  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;
16512
- const normalizedFinalAbsoluteMatrix = normalizeMatrixForPersistedFlip(
16513
- toggleLogicalFlipInMatrix(
16514
- finalAbsoluteMatrix,
16515
- objectFlipX !== persistedFlipX,
16516
- objectFlipY !== persistedFlipY
16517
- ),
16551
+ const matrixWithPersistedFlipState = toggleLogicalFlipInMatrix(
16552
+ finalAbsoluteMatrix,
16553
+ objectFlipX !== persistedFlipX,
16554
+ objectFlipY !== persistedFlipY
16555
+ );
16556
+ const cleanTransformMatrix = stripPersistedFlipForStableAngle(
16557
+ matrixWithPersistedFlipState,
16518
16558
  persistedFlipX,
16519
16559
  persistedFlipY,
16520
16560
  expectedCleanAngle
16521
16561
  );
16522
- const cleanTransformMatrix = toggleLogicalFlipInMatrix(normalizedFinalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16523
16562
  const persistedDecomposed = fabric.util.qrDecompose(cleanTransformMatrix);
16563
+ const hasPersistedFlipForAngle = !!(persistedFlipX || persistedFlipY);
16564
+ const isRotationGestureForStableAngle = isActiveSelection && activeObj instanceof fabric.ActiveSelection ? (() => {
16565
+ var _a3;
16566
+ const startAngle = ((_a3 = groupSelectionTransformStartRef.current) == null ? void 0 : _a3.selection) === activeObj ? groupSelectionTransformStartRef.current.selectionAngle ?? activeObj.angle ?? 0 : activeObj.angle ?? 0;
16567
+ return angleDistanceDeg(activeObj.angle ?? 0, startAngle) > 0.01;
16568
+ })() : !isActiveSelection && modifiedTarget === obj && angleDistanceDeg(obj.angle ?? 0, (sourceElement == null ? void 0 : sourceElement.angle) ?? obj.angle ?? 0) > 0.01;
16569
+ const stablePersistedAngle = resolveStableFlippedAngle(
16570
+ persistedDecomposed.angle,
16571
+ sourceElement == null ? void 0 : sourceElement.angle,
16572
+ hasPersistedFlipForAngle,
16573
+ isRotationGestureForStableAngle
16574
+ );
16524
16575
  const elementUpdate = {
16525
16576
  left: storePos.left,
16526
16577
  top: storePos.top,
@@ -16529,7 +16580,7 @@ const PageCanvas = forwardRef(
16529
16580
  // so finalWidth already reflects the new width chosen by the user.
16530
16581
  width: finalWidth,
16531
16582
  height: isLineObj ? 0 : isAutoShrinkText ? typeof autoShrinkStoredHeight === "number" ? autoShrinkStoredHeight : finalHeight : finalHeight,
16532
- angle: persistedDecomposed.angle,
16583
+ angle: stablePersistedAngle,
16533
16584
  skewX: isLineObj ? 0 : persistedDecomposed.skewX,
16534
16585
  skewY: isLineObj ? 0 : persistedDecomposed.skewY,
16535
16586
  scaleX: finalScaleX,
@@ -16601,7 +16652,7 @@ const PageCanvas = forwardRef(
16601
16652
  const isCropGroupObj = obj instanceof fabric.Group && obj.__cropGroup;
16602
16653
  const isPlainImageObj = obj instanceof fabric.FabricImage && !obj.__cropGroup && !obj.smartElementType;
16603
16654
  if (isActiveSelection && isActiveSelectionSideHandle && (isCropGroupObj || isPlainImageObj)) {
16604
- const childLocalAngleSrc = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : ((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY)) && Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : obj.angle ?? 0;
16655
+ const childLocalAngleSrc = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric.ActiveSelection ? activeObj : null);
16605
16656
  const normAng = (childLocalAngleSrc % 360 + 360) % 360;
16606
16657
  const isRotatedImg = Math.min(normAng, 360 - normAng) > 0.5;
16607
16658
  if (isRotatedImg && activeObj instanceof fabric.ActiveSelection) {
@@ -16840,6 +16891,8 @@ const PageCanvas = forwardRef(
16840
16891
  delete child.__asLiveParentWorldAngle;
16841
16892
  delete child.__asLiveFinalW;
16842
16893
  delete child.__asLiveFinalH;
16894
+ delete child.__asLivePersistedFlipX;
16895
+ delete child.__asLivePersistedFlipY;
16843
16896
  }
16844
16897
  }
16845
16898
  } catch {
@@ -25943,9 +25996,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25943
25996
  }
25944
25997
  return svgString;
25945
25998
  }
25946
- const resolvedPackageVersion = "0.5.451";
25999
+ const resolvedPackageVersion = "0.5.453";
25947
26000
  const PACKAGE_VERSION = resolvedPackageVersion;
25948
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.451";
26001
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.453";
25949
26002
  const roundParityValue = (value) => {
25950
26003
  if (typeof value !== "number") return value;
25951
26004
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26759,7 +26812,7 @@ class PixldocsRenderer {
26759
26812
  await this.waitForCanvasScene(container, cloned, i);
26760
26813
  }
26761
26814
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26762
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-hQLfUhri.js");
26815
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-DA8kyWb1.js");
26763
26816
  const prepared = preparePagesForExport(
26764
26817
  cloned.pages,
26765
26818
  canvasWidth,
@@ -29079,7 +29132,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29079
29132
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29080
29133
  sanitizeSvgTreeForPdf(svgToDraw);
29081
29134
  try {
29082
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-hQLfUhri.js");
29135
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-DA8kyWb1.js");
29083
29136
  try {
29084
29137
  await logTextMeasurementDiagnostic(svgToDraw);
29085
29138
  } catch {
@@ -29479,4 +29532,4 @@ export {
29479
29532
  buildTeaserBlurFlatKeys as y,
29480
29533
  collectFontDescriptorsFromConfig as z
29481
29534
  };
29482
- //# sourceMappingURL=index-CmdwL3tr.js.map
29535
+ //# sourceMappingURL=index-B4ZctiMj.js.map