@pixldocs/canvas-renderer 0.5.450 → 0.5.452

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.
@@ -5104,7 +5104,13 @@ function localDeltaToWorld(dx, dy, angleDeg) {
5104
5104
  function getWorldAngleDeg(obj) {
5105
5105
  var _a2;
5106
5106
  try {
5107
- if (typeof obj.getTotalAngle === "function") return obj.getTotalAngle() || 0;
5107
+ let total = 0;
5108
+ let cur = obj;
5109
+ while (cur) {
5110
+ total += Number(cur.angle ?? 0) || 0;
5111
+ cur = cur.group;
5112
+ }
5113
+ if (Number.isFinite(total)) return total;
5108
5114
  const matrix = (_a2 = obj.calcTransformMatrix) == null ? void 0 : _a2.call(obj);
5109
5115
  return matrix ? fabric.util.qrDecompose(matrix).angle || 0 : obj.angle || 0;
5110
5116
  } catch {
@@ -11687,13 +11693,13 @@ const angleDistanceDeg = (a, b) => {
11687
11693
  const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11688
11694
  return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11689
11695
  };
11690
- const normalizeMatrixForPersistedFlip = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11696
+ const stripPersistedFlipForStableAngle = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11691
11697
  if (!persistedFlipX && !persistedFlipY) return matrix;
11692
- if (!Number.isFinite(expectedCleanAngle)) return matrix;
11693
- const toggledVisual = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11694
- const cleanIfMatrixAlreadyHasFlip = fabric.util.qrDecompose(toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY)).angle ?? 0;
11695
- const cleanIfMatrixLostFlip = fabric.util.qrDecompose(matrix).angle ?? 0;
11696
- return angleDistanceDeg(cleanIfMatrixLostFlip, expectedCleanAngle) + 0.1 < angleDistanceDeg(cleanIfMatrixAlreadyHasFlip, expectedCleanAngle) ? toggledVisual : matrix;
11698
+ const toggled = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
11699
+ if (!Number.isFinite(expectedCleanAngle)) return toggled;
11700
+ const asIsAngle = fabric.util.qrDecompose(matrix).angle ?? 0;
11701
+ const toggledAngle = fabric.util.qrDecompose(toggled).angle ?? 0;
11702
+ return angleDistanceDeg(toggledAngle, expectedCleanAngle) <= angleDistanceDeg(asIsAngle, expectedCleanAngle) ? toggled : matrix;
11697
11703
  };
11698
11704
  function applyWarpAwareSelectionBorders(selection) {
11699
11705
  var _a2;
@@ -14638,7 +14644,7 @@ const PageCanvas = forwardRef(
14638
14644
  fabricCanvas.on("selection:cleared", () => {
14639
14645
  });
14640
14646
  fabricCanvas.on("object:scaling", (e) => {
14641
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
14647
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
14642
14648
  if (!isActiveRef.current) return;
14643
14649
  const t = e.target;
14644
14650
  if (t) lastResizeScaleTargetRef.current = t;
@@ -14931,9 +14937,19 @@ const PageCanvas = forwardRef(
14931
14937
  const liveGestureKey = `${obj.__pixldocsGroupSelection ?? "selection"}:${corner}:${((_k = groupSelectionTransformStartRef.current) == null ? void 0 : _k.selectionLeft) ?? obj.left ?? 0}:${((_l = groupSelectionTransformStartRef.current) == null ? void 0 : _l.selectionTop) ?? obj.top ?? 0}`;
14932
14938
  if (child.__asLiveGestureKey !== liveGestureKey) {
14933
14939
  child.__asLiveGestureKey = liveGestureKey;
14934
- child.__asLiveOrigAngle = Number.isFinite(child.angle) ? child.angle ?? 0 : 0;
14940
+ const childIdForAngle = getObjectId(child);
14941
+ const sourceChildForAngle = childIdForAngle ? elementsRef.current.find((el) => el.id === childIdForAngle) : null;
14942
+ const persistedChildFlipX = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipX) ?? child.flipX ?? false;
14943
+ const persistedChildFlipY = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipY) ?? child.flipY ?? false;
14944
+ const isFlippedImageLikeChild = (child instanceof fabric.FabricImage || child instanceof fabric.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) && !!(persistedChildFlipX || persistedChildFlipY) && Number.isFinite(sourceChildForAngle == null ? void 0 : sourceChildForAngle.angle);
14945
+ if (child instanceof fabric.FabricImage || child instanceof fabric.Group && (child.__cropGroup || ((_n = child._ct) == null ? void 0 : _n.isCropGroup))) {
14946
+ child.set({ flipX: persistedChildFlipX, flipY: persistedChildFlipY });
14947
+ child.__asLivePersistedFlipX = persistedChildFlipX;
14948
+ child.__asLivePersistedFlipY = persistedChildFlipY;
14949
+ }
14950
+ child.__asLiveOrigAngle = isFlippedImageLikeChild ? sourceChildForAngle.angle ?? 0 : Number.isFinite(child.angle) ? child.angle ?? 0 : 0;
14935
14951
  }
14936
- if (child instanceof fabric.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) {
14952
+ if (child instanceof fabric.Group && (child.__cropGroup || ((_o = child._ct) == null ? void 0 : _o.isCropGroup))) {
14937
14953
  const ct = child.__cropData;
14938
14954
  if (!ct) continue;
14939
14955
  if (child.__asLiveOrigAngle == null) {
@@ -14985,6 +15001,8 @@ const PageCanvas = forwardRef(
14985
15001
  child._set("scaleY", decC.scaleY);
14986
15002
  child._set("skewX", decC.skewX);
14987
15003
  child._set("skewY", decC.skewY);
15004
+ child._set("flipX", child.__asLivePersistedFlipX ?? child.flipX ?? false);
15005
+ child._set("flipY", child.__asLivePersistedFlipY ?? child.flipY ?? false);
14988
15006
  } catch {
14989
15007
  }
14990
15008
  try {
@@ -15042,6 +15060,8 @@ const PageCanvas = forwardRef(
15042
15060
  child._set("scaleY", decI.scaleY);
15043
15061
  child._set("skewX", decI.skewX);
15044
15062
  child._set("skewY", decI.skewY);
15063
+ child._set("flipX", child.__asLivePersistedFlipX ?? child.flipX ?? false);
15064
+ child._set("flipY", child.__asLivePersistedFlipY ?? child.flipY ?? false);
15045
15065
  } catch {
15046
15066
  }
15047
15067
  child.setCoords();
@@ -15102,7 +15122,7 @@ const PageCanvas = forwardRef(
15102
15122
  child.dirty = true;
15103
15123
  didReflowTextChild = true;
15104
15124
  }
15105
- if (isXSide && ((_n = groupShiftReflowSnapshotRef.current) == null ? void 0 : _n.selection) === obj) {
15125
+ if (isXSide && ((_p = groupShiftReflowSnapshotRef.current) == null ? void 0 : _p.selection) === obj) {
15106
15126
  const snap = groupShiftReflowSnapshotRef.current;
15107
15127
  const anchorEntry = snap.children[0];
15108
15128
  const anchorTopLive = anchorEntry.obj.top ?? 0;
@@ -15264,7 +15284,7 @@ const PageCanvas = forwardRef(
15264
15284
  setGuides(gridGuidesForScale.length ? [...scaleGuides, ...gridGuidesForScale] : scaleGuides);
15265
15285
  if (drilledGroupIdRef.current) {
15266
15286
  try {
15267
- (_o = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _o.call(fabricCanvas);
15287
+ (_q = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _q.call(fabricCanvas);
15268
15288
  } catch {
15269
15289
  }
15270
15290
  }
@@ -15671,12 +15691,18 @@ const PageCanvas = forwardRef(
15671
15691
  const absLeft = (active.left ?? 0) - ct.frameW / 2;
15672
15692
  const absTop = (active.top ?? 0) - ct.frameH / 2;
15673
15693
  const storePosCrop = absoluteToStorePosition(absLeft, absTop, objId, pageChildrenCrop);
15694
+ const sourceCropElement = pageChildrenCrop.length ? findNodeById(pageChildrenCrop, objId) : null;
15695
+ const cropAngle = sourceCropElement && isElement(sourceCropElement) && (sourceCropElement.flipX || sourceCropElement.flipY) && Number.isFinite(sourceCropElement.angle) ? sourceCropElement.angle ?? 0 : active.angle ?? 0;
15696
+ if ((sourceCropElement == null ? void 0 : sourceCropElement.flipX) || (sourceCropElement == null ? void 0 : sourceCropElement.flipY)) {
15697
+ active.set({ angle: cropAngle, flipX: sourceCropElement.flipX ?? false, flipY: sourceCropElement.flipY ?? false });
15698
+ active.setCoords();
15699
+ }
15674
15700
  updateElement2(objId, {
15675
15701
  width: ct.frameW,
15676
15702
  height: ct.frameH,
15677
15703
  left: storePosCrop.left,
15678
15704
  top: storePosCrop.top,
15679
- angle: active.angle ?? 0,
15705
+ angle: cropAngle,
15680
15706
  cropPanX: panX,
15681
15707
  cropPanY: panY,
15682
15708
  cropZoom: zoom3
@@ -15931,12 +15957,15 @@ const PageCanvas = forwardRef(
15931
15957
  360 - Math.abs(currentSelAngle - startSelAngle)
15932
15958
  );
15933
15959
  const hadRotation = isActiveSelection && activeObj && angleDelta > 0.01;
15934
- if (!hadScale && !hadRotation && (Math.abs(deltaX) > 0.1 || Math.abs(deltaY) > 0.1)) {
15960
+ const isMoveOnlyLogicalGroupGesture = !hadScale && !hadRotation && (Math.abs(deltaX) > 0.1 || Math.abs(deltaY) > 0.1);
15961
+ if (isMoveOnlyLogicalGroupGesture || !hadScale && !hadRotation && activeGroupSelectionId === groupToMove.id) {
15935
15962
  const { updateNode: updateNodeStore, commitHistory: commitHistoryStore, getCurrentElements } = useEditorStore.getState();
15936
- const newLeft = (groupToMove.left ?? 0) + deltaX;
15937
- const newTop = (groupToMove.top ?? 0) + deltaY;
15938
- updateNodeStore(groupToMove.id, { left: newLeft, top: newTop }, { recordHistory: false, skipLayoutRecalc: true });
15939
- commitHistoryStore();
15963
+ if (isMoveOnlyLogicalGroupGesture) {
15964
+ const newLeft = (groupToMove.left ?? 0) + deltaX;
15965
+ const newTop = (groupToMove.top ?? 0) + deltaY;
15966
+ updateNodeStore(groupToMove.id, { left: newLeft, top: newTop }, { recordHistory: false, skipLayoutRecalc: true });
15967
+ commitHistoryStore();
15968
+ }
15940
15969
  pendingGroupDrillInRef.current = null;
15941
15970
  fabricCanvas.__activeEditingGroupId = null;
15942
15971
  setDrilledGroupBounds(null);
@@ -16175,7 +16204,7 @@ const PageCanvas = forwardRef(
16175
16204
  useEditorStore.getState().updateElement(objId, { src: newSrc }, { recordHistory: false, skipLayoutRecalc: true });
16176
16205
  }
16177
16206
  } else if (isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
16178
- const imgChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : obj.angle ?? 0;
16207
+ 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;
16179
16208
  const imgChildNormAngle = (imgChildLocalAngle % 360 + 360) % 360;
16180
16209
  const imgChildIsRotated = Math.abs(imgChildNormAngle) > 0.5 && Math.abs(imgChildNormAngle - 360) > 0.5;
16181
16210
  const imgHandle = activeSelectionResizeHandle;
@@ -16494,17 +16523,17 @@ const PageCanvas = forwardRef(
16494
16523
  const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? objectFlipY;
16495
16524
  const isActiveSelectionResizeGesture = activeSelectionResizeHandle === "ml" || activeSelectionResizeHandle === "mr" || activeSelectionResizeHandle === "mt" || activeSelectionResizeHandle === "mb" || activeSelectionResizeHandle === "tl" || activeSelectionResizeHandle === "tr" || activeSelectionResizeHandle === "bl" || activeSelectionResizeHandle === "br";
16496
16525
  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;
16497
- const normalizedFinalAbsoluteMatrix = normalizeMatrixForPersistedFlip(
16498
- toggleLogicalFlipInMatrix(
16499
- finalAbsoluteMatrix,
16500
- objectFlipX !== persistedFlipX,
16501
- objectFlipY !== persistedFlipY
16502
- ),
16526
+ const matrixWithPersistedFlipState = toggleLogicalFlipInMatrix(
16527
+ finalAbsoluteMatrix,
16528
+ objectFlipX !== persistedFlipX,
16529
+ objectFlipY !== persistedFlipY
16530
+ );
16531
+ const cleanTransformMatrix = stripPersistedFlipForStableAngle(
16532
+ matrixWithPersistedFlipState,
16503
16533
  persistedFlipX,
16504
16534
  persistedFlipY,
16505
16535
  expectedCleanAngle
16506
16536
  );
16507
- const cleanTransformMatrix = toggleLogicalFlipInMatrix(normalizedFinalAbsoluteMatrix, persistedFlipX, persistedFlipY);
16508
16537
  const persistedDecomposed = fabric.util.qrDecompose(cleanTransformMatrix);
16509
16538
  const elementUpdate = {
16510
16539
  left: storePos.left,
@@ -16586,7 +16615,7 @@ const PageCanvas = forwardRef(
16586
16615
  const isCropGroupObj = obj instanceof fabric.Group && obj.__cropGroup;
16587
16616
  const isPlainImageObj = obj instanceof fabric.FabricImage && !obj.__cropGroup && !obj.smartElementType;
16588
16617
  if (isActiveSelection && isActiveSelectionSideHandle && (isCropGroupObj || isPlainImageObj)) {
16589
- const childLocalAngleSrc = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : obj.angle ?? 0;
16618
+ 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;
16590
16619
  const normAng = (childLocalAngleSrc % 360 + 360) % 360;
16591
16620
  const isRotatedImg = Math.min(normAng, 360 - normAng) > 0.5;
16592
16621
  if (isRotatedImg && activeObj instanceof fabric.ActiveSelection) {
@@ -16825,6 +16854,8 @@ const PageCanvas = forwardRef(
16825
16854
  delete child.__asLiveParentWorldAngle;
16826
16855
  delete child.__asLiveFinalW;
16827
16856
  delete child.__asLiveFinalH;
16857
+ delete child.__asLivePersistedFlipX;
16858
+ delete child.__asLivePersistedFlipY;
16828
16859
  }
16829
16860
  }
16830
16861
  } catch {
@@ -25928,9 +25959,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25928
25959
  }
25929
25960
  return svgString;
25930
25961
  }
25931
- const resolvedPackageVersion = "0.5.450";
25962
+ const resolvedPackageVersion = "0.5.452";
25932
25963
  const PACKAGE_VERSION = resolvedPackageVersion;
25933
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.450";
25964
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.452";
25934
25965
  const roundParityValue = (value) => {
25935
25966
  if (typeof value !== "number") return value;
25936
25967
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26744,7 +26775,7 @@ class PixldocsRenderer {
26744
26775
  await this.waitForCanvasScene(container, cloned, i);
26745
26776
  }
26746
26777
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26747
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-Ds3M_wlL.js");
26778
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-IArzJ4nC.js");
26748
26779
  const prepared = preparePagesForExport(
26749
26780
  cloned.pages,
26750
26781
  canvasWidth,
@@ -29064,7 +29095,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29064
29095
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29065
29096
  sanitizeSvgTreeForPdf(svgToDraw);
29066
29097
  try {
29067
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-Ds3M_wlL.js");
29098
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-IArzJ4nC.js");
29068
29099
  try {
29069
29100
  await logTextMeasurementDiagnostic(svgToDraw);
29070
29101
  } catch {
@@ -29464,4 +29495,4 @@ export {
29464
29495
  buildTeaserBlurFlatKeys as y,
29465
29496
  collectFontDescriptorsFromConfig as z
29466
29497
  };
29467
- //# sourceMappingURL=index-BIyCaEvT.js.map
29498
+ //# sourceMappingURL=index-B4jCHYd5.js.map