@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.
@@ -11013,9 +11013,9 @@ const scaleUpdateNumber = (updates, source, key, factor) => {
11013
11013
  const value = Number(source == null ? void 0 : source[key]);
11014
11014
  if (Number.isFinite(value)) updates[key] = value * factor;
11015
11015
  };
11016
- const bakeTextboxScaleIntoTypography = (obj, sourceElement) => {
11017
- const sx = Math.abs(obj.scaleX ?? 1) || 1;
11018
- const sy = Math.abs(obj.scaleY ?? 1) || 1;
11016
+ const bakeTextboxScaleIntoTypography = (obj, sourceElement, scaleOverride) => {
11017
+ const sx = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleX) ?? obj.scaleX ?? 1) || 1;
11018
+ const sy = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleY) ?? obj.scaleY ?? 1) || 1;
11019
11019
  if (Math.abs(sx - 1) < 1e-3 && Math.abs(sy - 1) < 1e-3) return null;
11020
11020
  const isUniform = Math.abs(sx - sy) < 0.01;
11021
11021
  const fontScale = isUniform ? (sx + sy) / 2 : Math.abs(sy - 1) > 1e-3 ? sy : 1;
@@ -11231,6 +11231,7 @@ const PageCanvas = react.forwardRef(
11231
11231
  react.useRef(null);
11232
11232
  const lastTextEditDimensionsRef = react.useRef(null);
11233
11233
  const lastResizeScaleTargetRef = react.useRef(null);
11234
+ const lastResizeScaleCornerRef = react.useRef(null);
11234
11235
  const preserveSelectionAfterTransformIdRef = react.useRef(null);
11235
11236
  const groupSelectionTransformStartRef = react.useRef(null);
11236
11237
  const activeSelectionMoveStartRef = react.useRef(null);
@@ -11558,6 +11559,7 @@ const PageCanvas = react.forwardRef(
11558
11559
  fc.__isUserTransforming = true;
11559
11560
  didTransformRef.current = true;
11560
11561
  lastResizeScaleTargetRef.current = target;
11562
+ lastResizeScaleCornerRef.current = corner;
11561
11563
  const targetId = getObjectId(target);
11562
11564
  if (targetId && targetId !== "__background__") {
11563
11565
  preserveSelectionAfterTransformIdRef.current = targetId;
@@ -13385,10 +13387,11 @@ const PageCanvas = react.forwardRef(
13385
13387
  fabricCanvas.on("selection:cleared", () => {
13386
13388
  });
13387
13389
  fabricCanvas.on("object:scaling", (e) => {
13388
- var _a2;
13390
+ var _a2, _b2;
13389
13391
  if (!isActiveRef.current) return;
13390
13392
  const t = e.target;
13391
13393
  if (t) lastResizeScaleTargetRef.current = t;
13394
+ lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13392
13395
  prepareGroupSelectionTransformStart(t);
13393
13396
  markTransforming(t);
13394
13397
  didTransformRef.current = true;
@@ -13706,16 +13709,17 @@ const PageCanvas = react.forwardRef(
13706
13709
  setGuides(gridGuidesForScale.length ? [...scaleGuides, ...gridGuidesForScale] : scaleGuides);
13707
13710
  if (drilledGroupIdRef.current) {
13708
13711
  try {
13709
- (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13712
+ (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13710
13713
  } catch {
13711
13714
  }
13712
13715
  }
13713
13716
  });
13714
13717
  fabricCanvas.on("object:resizing", (e) => {
13715
- var _a2;
13718
+ var _a2, _b2;
13716
13719
  if (!isActiveRef.current) return;
13717
13720
  const t = e.target;
13718
13721
  if (t) lastResizeScaleTargetRef.current = t;
13722
+ lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13719
13723
  markTransforming(t);
13720
13724
  didTransformRef.current = true;
13721
13725
  const transformTargetId = t ? getObjectId(t) : null;
@@ -13791,7 +13795,7 @@ const PageCanvas = react.forwardRef(
13791
13795
  setGuides(gridGuidesForTextResize.length ? [...scaleGuides, ...gridGuidesForTextResize] : scaleGuides);
13792
13796
  if (drilledGroupIdRef.current) {
13793
13797
  try {
13794
- (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13798
+ (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13795
13799
  } catch {
13796
13800
  }
13797
13801
  }
@@ -13902,7 +13906,7 @@ const PageCanvas = react.forwardRef(
13902
13906
  });
13903
13907
  let cropGroupSaveTimer = null;
13904
13908
  fabricCanvas.on("object:modified", (e) => {
13905
- var _a2, _b2, _c, _d, _e, _f, _g;
13909
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
13906
13910
  try {
13907
13911
  dragStarted = false;
13908
13912
  setGuides([]);
@@ -14318,6 +14322,7 @@ const PageCanvas = react.forwardRef(
14318
14322
  drilledGroupIdRef.current = null;
14319
14323
  const groupSelectionId = (isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.__pixldocsGroupSelection : void 0) ?? groupToMove.id;
14320
14324
  const targetObjects = isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.getObjects() : activeObjects;
14325
+ let preservedGroupMemberIds = targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__");
14321
14326
  if (groupSelectionId && activeObj instanceof fabric__namespace.ActiveSelection) {
14322
14327
  try {
14323
14328
  skipSelectionClearOnDiscardRef.current = true;
@@ -14330,7 +14335,25 @@ const PageCanvas = react.forwardRef(
14330
14335
  }
14331
14336
  } catch {
14332
14337
  }
14333
- const bakedSelection = targetObjects.length > 1 ? new fabric__namespace.ActiveSelection(targetObjects, { canvas: fabricCanvas }) : activeObj;
14338
+ const pageAfterMove = ((_g = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14339
+ const groupAfterMove = findNodeById(pageAfterMove, groupToMove.id);
14340
+ const memberIdsAfterMove = groupAfterMove && isGroup(groupAfterMove) ? getAllElementIds(groupAfterMove.children ?? []) : targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__");
14341
+ preservedGroupMemberIds = memberIdsAfterMove;
14342
+ const reselectionObjects = memberIdsAfterMove.map((id) => targetObjects.find((obj) => getObjectId(obj) === id) ?? fabricCanvas.getObjects().find((obj) => getObjectId(obj) === id)).filter((obj) => !!obj);
14343
+ for (const obj of reselectionObjects) {
14344
+ const id = getObjectId(obj);
14345
+ const node = id ? findNodeById(pageAfterMove, id) : null;
14346
+ if (!node) continue;
14347
+ const abs = getAbsoluteBounds(node, pageAfterMove, pageBoundsOptions);
14348
+ const bounds = getNodeBounds(node, pageAfterMove, pageBoundsOptions);
14349
+ if (obj instanceof fabric__namespace.Group && obj.__cropGroup || obj instanceof fabric__namespace.FabricImage && (obj.originX === "center" || obj.originY === "center")) {
14350
+ obj.set({ left: abs.left + Math.max(1, bounds.width) / 2, top: abs.top + Math.max(1, bounds.height) / 2 });
14351
+ } else {
14352
+ obj.set({ left: abs.left, top: abs.top });
14353
+ }
14354
+ obj.setCoords();
14355
+ }
14356
+ const bakedSelection = reselectionObjects.length > 1 ? new fabric__namespace.ActiveSelection(reselectionObjects, { canvas: fabricCanvas }) : activeObj;
14334
14357
  restoreGroupSelectionVisualState(bakedSelection, groupSelectionId);
14335
14358
  fabricCanvas.setActiveObject(bakedSelection);
14336
14359
  bakedSelection.setCoords();
@@ -14338,7 +14361,7 @@ const PageCanvas = react.forwardRef(
14338
14361
  selectElements([groupSelectionId], false, false);
14339
14362
  fabricCanvas.requestRenderAll();
14340
14363
  elementsRef.current = getCurrentElements();
14341
- for (const obj of targetObjects) {
14364
+ for (const obj of targetObjects.length ? targetObjects : activeObjects) {
14342
14365
  const objId = getObjectId(obj);
14343
14366
  if (objId && objId !== "__background__") {
14344
14367
  justModifiedIdsRef.current.add(objId);
@@ -14348,7 +14371,7 @@ const PageCanvas = react.forwardRef(
14348
14371
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14349
14372
  groupSelectionTransformStartRef.current = null;
14350
14373
  restorePreservedGroupSelectionSoon({
14351
- memberIds: targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__"),
14374
+ memberIds: preservedGroupMemberIds,
14352
14375
  groupSelectionId
14353
14376
  });
14354
14377
  unlockEditsSoon();
@@ -14518,6 +14541,8 @@ const PageCanvas = react.forwardRef(
14518
14541
  } else if (obj instanceof fabric__namespace.Textbox && isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
14519
14542
  const sx = Math.abs(decomposed.scaleX || 1);
14520
14543
  const sy = Math.abs(decomposed.scaleY || 1);
14544
+ const lastCorner = lastResizeScaleCornerRef.current ?? "";
14545
+ const isCornerGroupScale = lastCorner === "tl" || lastCorner === "tr" || lastCorner === "bl" || lastCorner === "br";
14521
14546
  const bakedWidth = Math.max(20, intrinsicWidth * sx);
14522
14547
  const bakedHeight = Math.max(1, intrinsicHeight * sy);
14523
14548
  finalWidth = bakedWidth;
@@ -14525,8 +14550,13 @@ const PageCanvas = react.forwardRef(
14525
14550
  finalScaleX = 1;
14526
14551
  finalScaleY = 1;
14527
14552
  try {
14528
- obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14529
- obj.initDimensions();
14553
+ if (isCornerGroupScale) {
14554
+ bakeTextboxScaleIntoTypography(obj, sourceElement, { scaleX: sx, scaleY: sy });
14555
+ } else {
14556
+ obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14557
+ obj.minBoxHeight = bakedHeight;
14558
+ obj.initDimensions();
14559
+ }
14530
14560
  obj.setCoords();
14531
14561
  } catch {
14532
14562
  }
@@ -14605,7 +14635,7 @@ const PageCanvas = react.forwardRef(
14605
14635
  updateElement(objId, elementUpdate, { recordHistory: false, skipLayoutRecalc: true });
14606
14636
  obj.setCoords();
14607
14637
  }
14608
- const pageChildrenForReflow = ((_g = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14638
+ const pageChildrenForReflow = ((_h = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _h.children) ?? [];
14609
14639
  const stackGroupsToReflow = /* @__PURE__ */ new Set();
14610
14640
  for (const id of modifiedIdsThisRound) {
14611
14641
  const parent = findParentGroup(pageChildrenForReflow, id);
@@ -14667,10 +14697,12 @@ const PageCanvas = react.forwardRef(
14667
14697
  }
14668
14698
  groupSelectionTransformStartRef.current = null;
14669
14699
  activeSelectionMoveStartRef.current = null;
14700
+ lastResizeScaleCornerRef.current = null;
14670
14701
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14671
14702
  commitHistory();
14672
14703
  unlockEditsSoon();
14673
14704
  } catch (e2) {
14705
+ lastResizeScaleCornerRef.current = null;
14674
14706
  unlockEditsSoon();
14675
14707
  }
14676
14708
  });
@@ -23683,9 +23715,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23683
23715
  }
23684
23716
  return svgString;
23685
23717
  }
23686
- const resolvedPackageVersion = "0.5.269";
23718
+ const resolvedPackageVersion = "0.5.271";
23687
23719
  const PACKAGE_VERSION = resolvedPackageVersion;
23688
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.269";
23720
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.271";
23689
23721
  const roundParityValue = (value) => {
23690
23722
  if (typeof value !== "number") return value;
23691
23723
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24499,7 +24531,7 @@ class PixldocsRenderer {
24499
24531
  await this.waitForCanvasScene(container, cloned, i);
24500
24532
  }
24501
24533
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24502
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-xlycX5wM.cjs"));
24534
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DjBUHamz.cjs"));
24503
24535
  const prepared = preparePagesForExport(
24504
24536
  cloned.pages,
24505
24537
  canvasWidth,
@@ -26819,7 +26851,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26819
26851
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26820
26852
  sanitizeSvgTreeForPdf(svgToDraw);
26821
26853
  try {
26822
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-xlycX5wM.cjs"));
26854
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DjBUHamz.cjs"));
26823
26855
  try {
26824
26856
  await logTextMeasurementDiagnostic(svgToDraw);
26825
26857
  } catch {
@@ -27216,4 +27248,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
27216
27248
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
27217
27249
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
27218
27250
  exports.warmTemplateFromForm = warmTemplateFromForm;
27219
- //# sourceMappingURL=index-V3Oyi5GA.cjs.map
27251
+ //# sourceMappingURL=index-6188mLJ2.cjs.map