@pixldocs/canvas-renderer 0.5.269 → 0.5.271

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.
@@ -10995,9 +10995,9 @@ const scaleUpdateNumber = (updates, source, key, factor) => {
10995
10995
  const value = Number(source == null ? void 0 : source[key]);
10996
10996
  if (Number.isFinite(value)) updates[key] = value * factor;
10997
10997
  };
10998
- const bakeTextboxScaleIntoTypography = (obj, sourceElement) => {
10999
- const sx = Math.abs(obj.scaleX ?? 1) || 1;
11000
- const sy = Math.abs(obj.scaleY ?? 1) || 1;
10998
+ const bakeTextboxScaleIntoTypography = (obj, sourceElement, scaleOverride) => {
10999
+ const sx = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleX) ?? obj.scaleX ?? 1) || 1;
11000
+ const sy = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleY) ?? obj.scaleY ?? 1) || 1;
11001
11001
  if (Math.abs(sx - 1) < 1e-3 && Math.abs(sy - 1) < 1e-3) return null;
11002
11002
  const isUniform = Math.abs(sx - sy) < 0.01;
11003
11003
  const fontScale = isUniform ? (sx + sy) / 2 : Math.abs(sy - 1) > 1e-3 ? sy : 1;
@@ -11213,6 +11213,7 @@ const PageCanvas = forwardRef(
11213
11213
  useRef(null);
11214
11214
  const lastTextEditDimensionsRef = useRef(null);
11215
11215
  const lastResizeScaleTargetRef = useRef(null);
11216
+ const lastResizeScaleCornerRef = useRef(null);
11216
11217
  const preserveSelectionAfterTransformIdRef = useRef(null);
11217
11218
  const groupSelectionTransformStartRef = useRef(null);
11218
11219
  const activeSelectionMoveStartRef = useRef(null);
@@ -11540,6 +11541,7 @@ const PageCanvas = forwardRef(
11540
11541
  fc.__isUserTransforming = true;
11541
11542
  didTransformRef.current = true;
11542
11543
  lastResizeScaleTargetRef.current = target;
11544
+ lastResizeScaleCornerRef.current = corner;
11543
11545
  const targetId = getObjectId(target);
11544
11546
  if (targetId && targetId !== "__background__") {
11545
11547
  preserveSelectionAfterTransformIdRef.current = targetId;
@@ -13367,10 +13369,11 @@ const PageCanvas = forwardRef(
13367
13369
  fabricCanvas.on("selection:cleared", () => {
13368
13370
  });
13369
13371
  fabricCanvas.on("object:scaling", (e) => {
13370
- var _a2;
13372
+ var _a2, _b2;
13371
13373
  if (!isActiveRef.current) return;
13372
13374
  const t = e.target;
13373
13375
  if (t) lastResizeScaleTargetRef.current = t;
13376
+ lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13374
13377
  prepareGroupSelectionTransformStart(t);
13375
13378
  markTransforming(t);
13376
13379
  didTransformRef.current = true;
@@ -13688,16 +13691,17 @@ const PageCanvas = forwardRef(
13688
13691
  setGuides(gridGuidesForScale.length ? [...scaleGuides, ...gridGuidesForScale] : scaleGuides);
13689
13692
  if (drilledGroupIdRef.current) {
13690
13693
  try {
13691
- (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13694
+ (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13692
13695
  } catch {
13693
13696
  }
13694
13697
  }
13695
13698
  });
13696
13699
  fabricCanvas.on("object:resizing", (e) => {
13697
- var _a2;
13700
+ var _a2, _b2;
13698
13701
  if (!isActiveRef.current) return;
13699
13702
  const t = e.target;
13700
13703
  if (t) lastResizeScaleTargetRef.current = t;
13704
+ lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13701
13705
  markTransforming(t);
13702
13706
  didTransformRef.current = true;
13703
13707
  const transformTargetId = t ? getObjectId(t) : null;
@@ -13773,7 +13777,7 @@ const PageCanvas = forwardRef(
13773
13777
  setGuides(gridGuidesForTextResize.length ? [...scaleGuides, ...gridGuidesForTextResize] : scaleGuides);
13774
13778
  if (drilledGroupIdRef.current) {
13775
13779
  try {
13776
- (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13780
+ (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13777
13781
  } catch {
13778
13782
  }
13779
13783
  }
@@ -13884,7 +13888,7 @@ const PageCanvas = forwardRef(
13884
13888
  });
13885
13889
  let cropGroupSaveTimer = null;
13886
13890
  fabricCanvas.on("object:modified", (e) => {
13887
- var _a2, _b2, _c, _d, _e, _f, _g;
13891
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
13888
13892
  try {
13889
13893
  dragStarted = false;
13890
13894
  setGuides([]);
@@ -14300,6 +14304,7 @@ const PageCanvas = forwardRef(
14300
14304
  drilledGroupIdRef.current = null;
14301
14305
  const groupSelectionId = (isActiveSelection && activeObj instanceof fabric.ActiveSelection ? activeObj.__pixldocsGroupSelection : void 0) ?? groupToMove.id;
14302
14306
  const targetObjects = isActiveSelection && activeObj instanceof fabric.ActiveSelection ? activeObj.getObjects() : activeObjects;
14307
+ let preservedGroupMemberIds = targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__");
14303
14308
  if (groupSelectionId && activeObj instanceof fabric.ActiveSelection) {
14304
14309
  try {
14305
14310
  skipSelectionClearOnDiscardRef.current = true;
@@ -14312,7 +14317,25 @@ const PageCanvas = forwardRef(
14312
14317
  }
14313
14318
  } catch {
14314
14319
  }
14315
- const bakedSelection = targetObjects.length > 1 ? new fabric.ActiveSelection(targetObjects, { canvas: fabricCanvas }) : activeObj;
14320
+ const pageAfterMove = ((_g = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14321
+ const groupAfterMove = findNodeById(pageAfterMove, groupToMove.id);
14322
+ const memberIdsAfterMove = groupAfterMove && isGroup(groupAfterMove) ? getAllElementIds(groupAfterMove.children ?? []) : targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__");
14323
+ preservedGroupMemberIds = memberIdsAfterMove;
14324
+ const reselectionObjects = memberIdsAfterMove.map((id) => targetObjects.find((obj) => getObjectId(obj) === id) ?? fabricCanvas.getObjects().find((obj) => getObjectId(obj) === id)).filter((obj) => !!obj);
14325
+ for (const obj of reselectionObjects) {
14326
+ const id = getObjectId(obj);
14327
+ const node = id ? findNodeById(pageAfterMove, id) : null;
14328
+ if (!node) continue;
14329
+ const abs = getAbsoluteBounds(node, pageAfterMove, pageBoundsOptions);
14330
+ const bounds = getNodeBounds(node, pageAfterMove, pageBoundsOptions);
14331
+ if (obj instanceof fabric.Group && obj.__cropGroup || obj instanceof fabric.FabricImage && (obj.originX === "center" || obj.originY === "center")) {
14332
+ obj.set({ left: abs.left + Math.max(1, bounds.width) / 2, top: abs.top + Math.max(1, bounds.height) / 2 });
14333
+ } else {
14334
+ obj.set({ left: abs.left, top: abs.top });
14335
+ }
14336
+ obj.setCoords();
14337
+ }
14338
+ const bakedSelection = reselectionObjects.length > 1 ? new fabric.ActiveSelection(reselectionObjects, { canvas: fabricCanvas }) : activeObj;
14316
14339
  restoreGroupSelectionVisualState(bakedSelection, groupSelectionId);
14317
14340
  fabricCanvas.setActiveObject(bakedSelection);
14318
14341
  bakedSelection.setCoords();
@@ -14320,7 +14343,7 @@ const PageCanvas = forwardRef(
14320
14343
  selectElements([groupSelectionId], false, false);
14321
14344
  fabricCanvas.requestRenderAll();
14322
14345
  elementsRef.current = getCurrentElements();
14323
- for (const obj of targetObjects) {
14346
+ for (const obj of targetObjects.length ? targetObjects : activeObjects) {
14324
14347
  const objId = getObjectId(obj);
14325
14348
  if (objId && objId !== "__background__") {
14326
14349
  justModifiedIdsRef.current.add(objId);
@@ -14330,7 +14353,7 @@ const PageCanvas = forwardRef(
14330
14353
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14331
14354
  groupSelectionTransformStartRef.current = null;
14332
14355
  restorePreservedGroupSelectionSoon({
14333
- memberIds: targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__"),
14356
+ memberIds: preservedGroupMemberIds,
14334
14357
  groupSelectionId
14335
14358
  });
14336
14359
  unlockEditsSoon();
@@ -14500,6 +14523,8 @@ const PageCanvas = forwardRef(
14500
14523
  } else if (obj instanceof fabric.Textbox && isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
14501
14524
  const sx = Math.abs(decomposed.scaleX || 1);
14502
14525
  const sy = Math.abs(decomposed.scaleY || 1);
14526
+ const lastCorner = lastResizeScaleCornerRef.current ?? "";
14527
+ const isCornerGroupScale = lastCorner === "tl" || lastCorner === "tr" || lastCorner === "bl" || lastCorner === "br";
14503
14528
  const bakedWidth = Math.max(20, intrinsicWidth * sx);
14504
14529
  const bakedHeight = Math.max(1, intrinsicHeight * sy);
14505
14530
  finalWidth = bakedWidth;
@@ -14507,8 +14532,13 @@ const PageCanvas = forwardRef(
14507
14532
  finalScaleX = 1;
14508
14533
  finalScaleY = 1;
14509
14534
  try {
14510
- obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14511
- obj.initDimensions();
14535
+ if (isCornerGroupScale) {
14536
+ bakeTextboxScaleIntoTypography(obj, sourceElement, { scaleX: sx, scaleY: sy });
14537
+ } else {
14538
+ obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14539
+ obj.minBoxHeight = bakedHeight;
14540
+ obj.initDimensions();
14541
+ }
14512
14542
  obj.setCoords();
14513
14543
  } catch {
14514
14544
  }
@@ -14587,7 +14617,7 @@ const PageCanvas = forwardRef(
14587
14617
  updateElement(objId, elementUpdate, { recordHistory: false, skipLayoutRecalc: true });
14588
14618
  obj.setCoords();
14589
14619
  }
14590
- const pageChildrenForReflow = ((_g = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14620
+ const pageChildrenForReflow = ((_h = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _h.children) ?? [];
14591
14621
  const stackGroupsToReflow = /* @__PURE__ */ new Set();
14592
14622
  for (const id of modifiedIdsThisRound) {
14593
14623
  const parent = findParentGroup(pageChildrenForReflow, id);
@@ -14649,10 +14679,12 @@ const PageCanvas = forwardRef(
14649
14679
  }
14650
14680
  groupSelectionTransformStartRef.current = null;
14651
14681
  activeSelectionMoveStartRef.current = null;
14682
+ lastResizeScaleCornerRef.current = null;
14652
14683
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14653
14684
  commitHistory();
14654
14685
  unlockEditsSoon();
14655
14686
  } catch (e2) {
14687
+ lastResizeScaleCornerRef.current = null;
14656
14688
  unlockEditsSoon();
14657
14689
  }
14658
14690
  });
@@ -23665,9 +23697,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23665
23697
  }
23666
23698
  return svgString;
23667
23699
  }
23668
- const resolvedPackageVersion = "0.5.269";
23700
+ const resolvedPackageVersion = "0.5.271";
23669
23701
  const PACKAGE_VERSION = resolvedPackageVersion;
23670
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.269";
23702
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.271";
23671
23703
  const roundParityValue = (value) => {
23672
23704
  if (typeof value !== "number") return value;
23673
23705
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24481,7 +24513,7 @@ class PixldocsRenderer {
24481
24513
  await this.waitForCanvasScene(container, cloned, i);
24482
24514
  }
24483
24515
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24484
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BrPmmgsF.js");
24516
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-0BizqdiS.js");
24485
24517
  const prepared = preparePagesForExport(
24486
24518
  cloned.pages,
24487
24519
  canvasWidth,
@@ -26801,7 +26833,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26801
26833
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26802
26834
  sanitizeSvgTreeForPdf(svgToDraw);
26803
26835
  try {
26804
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BrPmmgsF.js");
26836
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-0BizqdiS.js");
26805
26837
  try {
26806
26838
  await logTextMeasurementDiagnostic(svgToDraw);
26807
26839
  } catch {
@@ -27201,4 +27233,4 @@ export {
27201
27233
  buildTeaserBlurFlatKeys as y,
27202
27234
  collectFontDescriptorsFromConfig as z
27203
27235
  };
27204
- //# sourceMappingURL=index-CrV6Qgb-.js.map
27236
+ //# sourceMappingURL=index-BpY8sZ_v.js.map