@pixldocs/canvas-renderer 0.5.441 → 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) {
@@ -11875,6 +11887,7 @@ const PageCanvas = react.forwardRef(
11875
11887
  const selectAllTextOnEditingEnterRef = react.useRef(null);
11876
11888
  const suppressedTextEditObjectsRef = react.useRef([]);
11877
11889
  const suppressTextDoubleClickUntilRef = react.useRef(0);
11890
+ const cropGroupActivatedAtRef = react.useRef(/* @__PURE__ */ new WeakMap());
11878
11891
  const syncLockedRef = react.useRef(false);
11879
11892
  const editLockRef = react.useRef(false);
11880
11893
  const editLockCountRef = react.useRef(0);
@@ -15962,6 +15975,7 @@ const PageCanvas = react.forwardRef(
15962
15975
  }
15963
15976
  }
15964
15977
  const pendingCropGroupFrameBakes = [];
15978
+ const activeSelectionFlipRestores = [];
15965
15979
  for (const obj of activeObjects) {
15966
15980
  const objId = getObjectId(obj);
15967
15981
  if (!objId || objId === "__background__") continue;
@@ -16476,10 +16490,27 @@ const PageCanvas = react.forwardRef(
16476
16490
  const isLineObj = obj instanceof fabric__namespace.Line;
16477
16491
  const isAutoShrinkText = (sourceElement == null ? void 0 : sourceElement.type) === "text" && sourceElement.overflowPolicy === "auto-shrink";
16478
16492
  const autoShrinkStoredHeight = isAutoShrinkText ? sourceElement.height : void 0;
16479
- const persistedFlipX = (sourceElement == null ? void 0 : sourceElement.flipX) ?? obj.flipX ?? false;
16480
- const persistedFlipY = (sourceElement == null ? void 0 : sourceElement.flipY) ?? obj.flipY ?? false;
16481
- 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);
16482
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
+ }
16483
16514
  const elementUpdate = {
16484
16515
  left: storePos.left,
16485
16516
  top: storePos.top,
@@ -16495,7 +16526,7 @@ const PageCanvas = react.forwardRef(
16495
16526
  scaleY: finalScaleY,
16496
16527
  flipX: persistedFlipX,
16497
16528
  flipY: persistedFlipY,
16498
- transformMatrix: finalAbsoluteMatrix
16529
+ transformMatrix: cleanTransformMatrix
16499
16530
  };
16500
16531
  if (obj instanceof fabric__namespace.Textbox) {
16501
16532
  const bakedTextScaleUpdates = obj.__pixldocsBakedTextScaleUpdates;
@@ -16544,19 +16575,15 @@ const PageCanvas = react.forwardRef(
16544
16575
  elementUpdate.scaleY = 1;
16545
16576
  elementUpdate.skewX = 0;
16546
16577
  elementUpdate.skewY = 0;
16547
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16548
- fabric__namespace.util.composeMatrix({
16549
- translateX: cx,
16550
- translateY: cy,
16551
- angle: cleanAngle,
16552
- scaleX: 1,
16553
- scaleY: 1,
16554
- skewX: 0,
16555
- skewY: 0
16556
- }),
16557
- elementUpdate.flipX,
16558
- elementUpdate.flipY
16559
- );
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
+ });
16560
16587
  } catch {
16561
16588
  }
16562
16589
  }
@@ -16590,19 +16617,15 @@ const PageCanvas = react.forwardRef(
16590
16617
  elementUpdate.scaleY = 1;
16591
16618
  elementUpdate.skewX = 0;
16592
16619
  elementUpdate.skewY = 0;
16593
- elementUpdate.transformMatrix = toggleLogicalFlipInMatrix(
16594
- fabric__namespace.util.composeMatrix({
16595
- translateX: cx,
16596
- translateY: cy,
16597
- angle: cleanAngleI,
16598
- scaleX: 1,
16599
- scaleY: 1,
16600
- skewX: 0,
16601
- skewY: 0
16602
- }),
16603
- elementUpdate.flipX,
16604
- elementUpdate.flipY
16605
- );
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
+ });
16606
16629
  } catch {
16607
16630
  }
16608
16631
  }
@@ -16711,6 +16734,11 @@ const PageCanvas = react.forwardRef(
16711
16734
  skipSelectionClearOnDiscardRef.current = true;
16712
16735
  skipActiveSelectionBakeOnClearRef.current = true;
16713
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
+ }
16714
16742
  fabricCanvas.discardActiveObject();
16715
16743
  } finally {
16716
16744
  skipActiveSelectionBakeOnClearRef.current = false;
@@ -16833,6 +16861,14 @@ const PageCanvas = react.forwardRef(
16833
16861
  obj.setCoords();
16834
16862
  }
16835
16863
  });
16864
+ const recordCropGroupActivation = () => {
16865
+ const active = fabricCanvas.getActiveObject();
16866
+ if (active && active instanceof fabric__namespace.Group && active.__cropGroup) {
16867
+ cropGroupActivatedAtRef.current.set(active, Date.now());
16868
+ }
16869
+ };
16870
+ fabricCanvas.on("selection:created", recordCropGroupActivation);
16871
+ fabricCanvas.on("selection:updated", recordCropGroupActivation);
16836
16872
  fabricCanvas.on("mouse:dblclick", (e) => {
16837
16873
  var _a2, _b2, _c2;
16838
16874
  if (!isActiveRef.current || !allowEditing) return;
@@ -16862,6 +16898,10 @@ const PageCanvas = react.forwardRef(
16862
16898
  }
16863
16899
  return;
16864
16900
  }
16901
+ const activatedAt = cropGroupActivatedAtRef.current.get(target) ?? 0;
16902
+ if (Date.now() - activatedAt < 400) {
16903
+ return;
16904
+ }
16865
16905
  }
16866
16906
  if (innerImg && !isPlaceholder && !isCropGroupInCropMode(target)) {
16867
16907
  enterCropMode(target);
@@ -25889,9 +25929,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25889
25929
  }
25890
25930
  return svgString;
25891
25931
  }
25892
- const resolvedPackageVersion = "0.5.441";
25932
+ const resolvedPackageVersion = "0.5.443";
25893
25933
  const PACKAGE_VERSION = resolvedPackageVersion;
25894
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.441";
25934
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.443";
25895
25935
  const roundParityValue = (value) => {
25896
25936
  if (typeof value !== "number") return value;
25897
25937
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26705,7 +26745,7 @@ class PixldocsRenderer {
26705
26745
  await this.waitForCanvasScene(container, cloned, i);
26706
26746
  }
26707
26747
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26708
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-BKPFy7-t.cjs"));
26748
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-C6WM_grg.cjs"));
26709
26749
  const prepared = preparePagesForExport(
26710
26750
  cloned.pages,
26711
26751
  canvasWidth,
@@ -29025,7 +29065,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29025
29065
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29026
29066
  sanitizeSvgTreeForPdf(svgToDraw);
29027
29067
  try {
29028
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-BKPFy7-t.cjs"));
29068
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-C6WM_grg.cjs"));
29029
29069
  try {
29030
29070
  await logTextMeasurementDiagnostic(svgToDraw);
29031
29071
  } catch {
@@ -29422,4 +29462,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29422
29462
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29423
29463
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29424
29464
  exports.warmTemplateFromForm = warmTemplateFromForm;
29425
- //# sourceMappingURL=index-BPlFxSU1.cjs.map
29465
+ //# sourceMappingURL=index-BxmYD_or.cjs.map