@pixldocs/canvas-renderer 0.5.284 → 0.5.286

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.
@@ -10494,10 +10494,6 @@ const SELECTION_PRIMARY = "hsl(217, 91%, 60%)";
10494
10494
  const SELECTION_BORDER_SCALE = 2;
10495
10495
  let ensureCanvaControlRenders = () => {
10496
10496
  };
10497
- const shouldLogGroupMove = () => {
10498
- if (typeof window === "undefined") return false;
10499
- return window.__pixldocsDebugGroupMove === true;
10500
- };
10501
10497
  try {
10502
10498
  const InteractiveBase = fabric__namespace.InteractiveFabricObject ?? fabric__namespace.Object;
10503
10499
  if ((InteractiveBase == null ? void 0 : InteractiveBase.prototype) && !InteractiveBase.prototype.__pixldocsCenteredSelectionBorder) {
@@ -10947,31 +10943,20 @@ try {
10947
10943
  } catch (e) {
10948
10944
  }
10949
10945
  };
10950
- const tryPatchFactory = (target, key, bindTarget = target) => {
10951
- try {
10952
- if (!target || typeof target[key] !== "function") return;
10953
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
10954
- if (descriptor && descriptor.writable === false && !descriptor.set) return;
10955
- const original = target[key].bind(bindTarget);
10956
- target[key] = () => installPillRenders(original());
10957
- } catch {
10958
- }
10959
- };
10960
- tryPatchFactory(cu, "createObjectDefaultControls");
10961
- tryPatchFactory(cu, "createTextboxDefaultControls");
10946
+ const origObj = cu.createObjectDefaultControls.bind(cu);
10947
+ cu.createObjectDefaultControls = () => installPillRenders(origObj());
10948
+ if (typeof cu.createTextboxDefaultControls === "function") {
10949
+ const origTb = cu.createTextboxDefaultControls.bind(cu);
10950
+ cu.createTextboxDefaultControls = () => installPillRenders(origTb());
10951
+ }
10962
10952
  const wrapClassCreateControls = (Klass) => {
10963
- try {
10964
- if (!Klass || typeof Klass.createControls !== "function") return;
10965
- const descriptor = Object.getOwnPropertyDescriptor(Klass, "createControls");
10966
- if (descriptor && descriptor.writable === false && !descriptor.set) return;
10967
- const orig = Klass.createControls.bind(Klass);
10968
- Klass.createControls = () => {
10969
- const res = orig();
10970
- if (res && res.controls) installPillRenders(res.controls);
10971
- return res;
10972
- };
10973
- } catch {
10974
- }
10953
+ if (!Klass || typeof Klass.createControls !== "function") return;
10954
+ const orig = Klass.createControls.bind(Klass);
10955
+ Klass.createControls = () => {
10956
+ const res = orig();
10957
+ if (res && res.controls) installPillRenders(res.controls);
10958
+ return res;
10959
+ };
10975
10960
  };
10976
10961
  wrapClassCreateControls(fabric__namespace.InteractiveFabricObject);
10977
10962
  wrapClassCreateControls(fabric__namespace.FabricObject);
@@ -10994,7 +10979,8 @@ try {
10994
10979
  };
10995
10980
  }
10996
10981
  }
10997
- } catch {
10982
+ } catch (e) {
10983
+ console.warn("[PageCanvas] Failed to install Canva-style control handles:", e);
10998
10984
  }
10999
10985
  const scaleTextPathConfig = (textPath, sx, sy, uniform) => {
11000
10986
  if (!textPath || typeof textPath !== "object") return textPath;
@@ -11027,9 +11013,9 @@ const scaleUpdateNumber = (updates, source, key, factor) => {
11027
11013
  const value = Number(source == null ? void 0 : source[key]);
11028
11014
  if (Number.isFinite(value)) updates[key] = value * factor;
11029
11015
  };
11030
- const bakeTextboxScaleIntoTypography = (obj, sourceElement, scaleOverride) => {
11031
- const sx = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleX) ?? obj.scaleX ?? 1) || 1;
11032
- const sy = Math.abs((scaleOverride == null ? void 0 : scaleOverride.scaleY) ?? obj.scaleY ?? 1) || 1;
11016
+ const bakeTextboxScaleIntoTypography = (obj, sourceElement) => {
11017
+ const sx = Math.abs(obj.scaleX ?? 1) || 1;
11018
+ const sy = Math.abs(obj.scaleY ?? 1) || 1;
11033
11019
  if (Math.abs(sx - 1) < 1e-3 && Math.abs(sy - 1) < 1e-3) return null;
11034
11020
  const isUniform = Math.abs(sx - sy) < 0.01;
11035
11021
  const fontScale = isUniform ? (sx + sy) / 2 : Math.abs(sy - 1) > 1e-3 ? sy : 1;
@@ -11225,6 +11211,7 @@ const PageCanvas = react.forwardRef(
11225
11211
  const skipActiveSelectionBakeOnClearRef = react.useRef(false);
11226
11212
  const preserveEditingScopeOnSelectionClearRef = react.useRef(false);
11227
11213
  const preserveActiveSelectionAfterTransformRef = react.useRef(null);
11214
+ const recentGroupSelectionRestoreRef = react.useRef(null);
11228
11215
  const pendingGroupPromotionRef = react.useRef(null);
11229
11216
  const pendingGroupDrillInRef = react.useRef(null);
11230
11217
  const imageReloadRequestSeqRef = react.useRef(/* @__PURE__ */ new Map());
@@ -11245,7 +11232,6 @@ const PageCanvas = react.forwardRef(
11245
11232
  react.useRef(null);
11246
11233
  const lastTextEditDimensionsRef = react.useRef(null);
11247
11234
  const lastResizeScaleTargetRef = react.useRef(null);
11248
- const lastResizeScaleCornerRef = react.useRef(null);
11249
11235
  const preserveSelectionAfterTransformIdRef = react.useRef(null);
11250
11236
  const groupSelectionTransformStartRef = react.useRef(null);
11251
11237
  const activeSelectionMoveStartRef = react.useRef(null);
@@ -11262,6 +11248,26 @@ const PageCanvas = react.forwardRef(
11262
11248
  hoveredGroupId
11263
11249
  } = useEditorStore();
11264
11250
  const storeSelectedIds = canvas.selectedIds ?? [];
11251
+ const restoreGroupSelectionSnapshot = react.useCallback((snapshot) => {
11252
+ const fc = fabricRef.current;
11253
+ const groupId = snapshot == null ? void 0 : snapshot.groupSelectionId;
11254
+ if (!fc || !groupId || snapshot.memberIds.length < 2 || editingTextIdRef.current) return;
11255
+ const members = snapshot.memberIds.map((id) => fc.getObjects().find((o) => getObjectId(o) === id)).filter((o) => !!o);
11256
+ if (members.length < 2) return;
11257
+ isSyncingSelectionToFabricRef.current = true;
11258
+ try {
11259
+ const active = fc.getActiveObject();
11260
+ const selection = active instanceof fabric__namespace.ActiveSelection && members.every((member) => active.getObjects().includes(member)) ? active : new fabric__namespace.ActiveSelection(members, { canvas: fc });
11261
+ applyLogicalGroupSelectionVisualState(selection, groupId);
11262
+ fc.setActiveObject(selection);
11263
+ selection.setCoords();
11264
+ fc.requestRenderAll();
11265
+ } finally {
11266
+ requestAnimationFrame(() => {
11267
+ isSyncingSelectionToFabricRef.current = false;
11268
+ });
11269
+ }
11270
+ }, [applyLogicalGroupSelectionVisualState]);
11265
11271
  const currentPage = react.useMemo(() => (canvas.pages ?? []).find((p) => p.id === pageId), [canvas.pages, pageId]);
11266
11272
  react.useMemo(() => {
11267
11273
  const ids = storeSelectedIds ?? [];
@@ -11573,7 +11579,6 @@ const PageCanvas = react.forwardRef(
11573
11579
  fc.__isUserTransforming = true;
11574
11580
  didTransformRef.current = true;
11575
11581
  lastResizeScaleTargetRef.current = target;
11576
- lastResizeScaleCornerRef.current = corner;
11577
11582
  const targetId = getObjectId(target);
11578
11583
  if (targetId && targetId !== "__background__") {
11579
11584
  preserveSelectionAfterTransformIdRef.current = targetId;
@@ -12057,9 +12062,6 @@ const PageCanvas = react.forwardRef(
12057
12062
  selectionLeft: rect.left,
12058
12063
  selectionTop: rect.top
12059
12064
  };
12060
- if (active.__pixldocsGroupSelection) {
12061
- prepareGroupSelectionTransformStart(active);
12062
- }
12063
12065
  }
12064
12066
  if (fabricCanvas._currentTransform) {
12065
12067
  fabricCanvas.__isUserTransforming = true;
@@ -12500,8 +12502,11 @@ const PageCanvas = react.forwardRef(
12500
12502
  if (shouldRestoreGroupSelection) restorePreservedGroupSelectionSoon(preservedGroupSelection);
12501
12503
  return;
12502
12504
  }
12503
- if (editLockRef.current || syncLockedRef.current || didTransformRef.current || preserveSelectionAfterTransformIdRef.current || shouldRestoreGroupSelection) {
12505
+ const recentGroupSelectionRestore = recentGroupSelectionRestoreRef.current;
12506
+ const shouldReassertRecentGroupSelection = !!((recentGroupSelectionRestore == null ? void 0 : recentGroupSelectionRestore.groupSelectionId) && recentGroupSelectionRestore.expiresAt > Date.now());
12507
+ if (editLockRef.current || syncLockedRef.current || didTransformRef.current || preserveSelectionAfterTransformIdRef.current || shouldRestoreGroupSelection || shouldReassertRecentGroupSelection) {
12504
12508
  if (shouldRestoreGroupSelection) restorePreservedGroupSelectionSoon(preservedGroupSelection);
12509
+ else if (shouldReassertRecentGroupSelection) restorePreservedGroupSelectionSoon(recentGroupSelectionRestore);
12505
12510
  return;
12506
12511
  }
12507
12512
  restoreSuppressedGroupBorders();
@@ -12717,34 +12722,11 @@ const PageCanvas = react.forwardRef(
12717
12722
  const restorePreservedGroupSelectionSoon = (snapshot = preserveActiveSelectionAfterTransformRef.current) => {
12718
12723
  if (!(snapshot == null ? void 0 : snapshot.groupSelectionId) || snapshot.memberIds.length < 2) return;
12719
12724
  const groupId = snapshot.groupSelectionId;
12720
- const memberIds = [...snapshot.memberIds];
12721
12725
  selectElements([groupId], false, false);
12722
12726
  requestAnimationFrame(() => {
12723
12727
  setTimeout(() => {
12724
- const fc = fabricRef.current;
12725
- if (!fc || !isActiveRef.current || editingTextIdRef.current) return;
12726
- const active = fc.getActiveObject();
12727
- if (active instanceof fabric__namespace.ActiveSelection && active.__pixldocsGroupSelection === groupId) {
12728
- restoreGroupSelectionVisualState(active, groupId);
12729
- fc.requestRenderAll();
12730
- return;
12731
- }
12732
- const members = memberIds.map((id) => fc.getObjects().find((o) => getObjectId(o) === id)).filter((o) => !!o);
12733
- if (members.length < 2) return;
12734
- isSyncingSelectionToFabricRef.current = true;
12735
- try {
12736
- const selection = new fabric__namespace.ActiveSelection(members, { canvas: fc });
12737
- restoreGroupSelectionVisualState(selection, groupId);
12738
- fc.setActiveObject(selection);
12739
- if (!selection.getObjects().every((obj) => !(obj instanceof fabric__namespace.Group))) {
12740
- selection.setCoords();
12741
- }
12742
- fc.requestRenderAll();
12743
- } finally {
12744
- requestAnimationFrame(() => {
12745
- isSyncingSelectionToFabricRef.current = false;
12746
- });
12747
- }
12728
+ if (!isActiveRef.current) return;
12729
+ restoreGroupSelectionSnapshot(snapshot);
12748
12730
  }, 0);
12749
12731
  });
12750
12732
  };
@@ -12927,9 +12909,6 @@ const PageCanvas = react.forwardRef(
12927
12909
  fabricCanvas.on("mouse:down:before", (opt) => {
12928
12910
  var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
12929
12911
  const activeBeforeMouseDown = fabricCanvas.getActiveObject();
12930
- if (activeBeforeMouseDown instanceof fabric__namespace.ActiveSelection && activeBeforeMouseDown.__pixldocsGroupSelection) {
12931
- prepareGroupSelectionTransformStart(activeBeforeMouseDown);
12932
- }
12933
12912
  if (editLockRef.current) {
12934
12913
  const active = fabricCanvas.getActiveObject();
12935
12914
  if (active && (((_a2 = active._ct) == null ? void 0 : _a2.isCropGroup) || active.__cropGroup)) {
@@ -13044,14 +13023,7 @@ const PageCanvas = react.forwardRef(
13044
13023
  pendingGroupDrillInRef.current = null;
13045
13024
  } else if (drillGroup && !drillGroup.backgroundColor && !targetIsInCrop && alreadyThisGroup && !isMultiSelectKey && effectiveTarget !== activeNow) {
13046
13025
  pendingGroupPromotionRef.current = null;
13047
- const pointer = fabricCanvas.getPointer(opt.e);
13048
- pendingGroupDrillInRef.current = {
13049
- groupId: drillGroup.id,
13050
- childId: effectiveTargetId,
13051
- target: effectiveTarget,
13052
- startX: pointer.x,
13053
- startY: pointer.y
13054
- };
13026
+ pendingGroupDrillInRef.current = { groupId: drillGroup.id, childId: effectiveTargetId, target: effectiveTarget };
13055
13027
  if (effectiveTarget instanceof fabric__namespace.Textbox) {
13056
13028
  suppressTextEditForClick(effectiveTarget);
13057
13029
  }
@@ -13198,7 +13170,7 @@ const PageCanvas = react.forwardRef(
13198
13170
  o.__lockScaleDuringCrop = false;
13199
13171
  });
13200
13172
  fabricCanvas.on("mouse:up", (e) => {
13201
- var _a2, _b2, _c, _d;
13173
+ var _a2, _b2, _c;
13202
13174
  clearTransforming();
13203
13175
  setGuides([]);
13204
13176
  setRotationLabel(null);
@@ -13208,21 +13180,7 @@ const PageCanvas = react.forwardRef(
13208
13180
  dragStarted = false;
13209
13181
  const pendingDrillIn = pendingGroupDrillInRef.current;
13210
13182
  pendingGroupDrillInRef.current = null;
13211
- let movedPendingDrillPointer = false;
13212
- if (pendingDrillIn && pendingDrillIn.startX !== void 0 && pendingDrillIn.startY !== void 0) {
13213
- try {
13214
- const pointer = fabricCanvas.getPointer(e == null ? void 0 : e.e);
13215
- const zoom3 = ((_a2 = fabricCanvas.getZoom) == null ? void 0 : _a2.call(fabricCanvas)) || 1;
13216
- const dragThreshold = Math.max(2, 4 / zoom3);
13217
- movedPendingDrillPointer = Math.hypot(pointer.x - pendingDrillIn.startX, pointer.y - pendingDrillIn.startY) > dragThreshold;
13218
- } catch {
13219
- movedPendingDrillPointer = false;
13220
- }
13221
- }
13222
- if (movedPendingDrillPointer) {
13223
- didTransformRef.current = true;
13224
- }
13225
- if (pendingDrillIn && (didTransformRef.current || movedPendingDrillPointer)) {
13183
+ if (pendingDrillIn && didTransformRef.current) {
13226
13184
  const activeNow = fabricCanvas.getActiveObject();
13227
13185
  fabricCanvas.__activeEditingGroupId = null;
13228
13186
  setDrilledGroupBounds(null);
@@ -13238,7 +13196,8 @@ const PageCanvas = react.forwardRef(
13238
13196
  if (memberIds.length > 1) {
13239
13197
  restorePreservedGroupSelectionSoon({
13240
13198
  memberIds,
13241
- groupSelectionId: pendingDrillIn.groupId
13199
+ groupSelectionId: pendingDrillIn.groupId,
13200
+ expiresAt: Date.now() + 1200
13242
13201
  });
13243
13202
  } else {
13244
13203
  selectElements([pendingDrillIn.groupId], false, false);
@@ -13252,7 +13211,7 @@ const PageCanvas = react.forwardRef(
13252
13211
  fabricCanvas.__activeEditingGroupId = pendingDrillIn.groupId;
13253
13212
  delete pendingDrillIn.target.__pixldocsGroupSelection;
13254
13213
  delete pendingDrillIn.target.__pixldocsLogicalGroupIds;
13255
- (_c = (_b2 = pendingDrillIn.target).set) == null ? void 0 : _c.call(_b2, { selectable: true, evented: true, hasBorders: true, hasControls: true });
13214
+ (_b2 = (_a2 = pendingDrillIn.target).set) == null ? void 0 : _b2.call(_a2, { selectable: true, evented: true, hasBorders: true, hasControls: true });
13256
13215
  fabricCanvas.setActiveObject(pendingDrillIn.target);
13257
13216
  pendingDrillIn.target.setCoords();
13258
13217
  if (pendingDrillIn.target instanceof fabric__namespace.Textbox) {
@@ -13305,7 +13264,7 @@ const PageCanvas = react.forwardRef(
13305
13264
  }
13306
13265
  }
13307
13266
  const activeObj = fabricCanvas.getActiveObject();
13308
- if (activeObj && (activeObj.__cropGroup || ((_d = activeObj._ct) == null ? void 0 : _d.isCropGroup))) {
13267
+ if (activeObj && (activeObj.__cropGroup || ((_c = activeObj._ct) == null ? void 0 : _c.isCropGroup))) {
13309
13268
  activeObj.__lockScaleDuringCrop = false;
13310
13269
  if (activeObj.__cropDrag) {
13311
13270
  delete activeObj.__cropDrag;
@@ -13323,9 +13282,7 @@ const PageCanvas = react.forwardRef(
13323
13282
  syncLockedRef.current = false;
13324
13283
  }, 50);
13325
13284
  }
13326
- requestAnimationFrame(() => {
13327
- didTransformRef.current = false;
13328
- });
13285
+ didTransformRef.current = false;
13329
13286
  setTimeout(() => {
13330
13287
  if (!fabricCanvas._currentTransform) {
13331
13288
  editLockRef.current = false;
@@ -13403,11 +13360,10 @@ const PageCanvas = react.forwardRef(
13403
13360
  fabricCanvas.on("selection:cleared", () => {
13404
13361
  });
13405
13362
  fabricCanvas.on("object:scaling", (e) => {
13406
- var _a2, _b2;
13363
+ var _a2;
13407
13364
  if (!isActiveRef.current) return;
13408
13365
  const t = e.target;
13409
13366
  if (t) lastResizeScaleTargetRef.current = t;
13410
- lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13411
13367
  prepareGroupSelectionTransformStart(t);
13412
13368
  markTransforming(t);
13413
13369
  didTransformRef.current = true;
@@ -13725,17 +13681,16 @@ const PageCanvas = react.forwardRef(
13725
13681
  setGuides(gridGuidesForScale.length ? [...scaleGuides, ...gridGuidesForScale] : scaleGuides);
13726
13682
  if (drilledGroupIdRef.current) {
13727
13683
  try {
13728
- (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13684
+ (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13729
13685
  } catch {
13730
13686
  }
13731
13687
  }
13732
13688
  });
13733
13689
  fabricCanvas.on("object:resizing", (e) => {
13734
- var _a2, _b2;
13690
+ var _a2;
13735
13691
  if (!isActiveRef.current) return;
13736
13692
  const t = e.target;
13737
13693
  if (t) lastResizeScaleTargetRef.current = t;
13738
- lastResizeScaleCornerRef.current = ((_a2 = e.transform) == null ? void 0 : _a2.corner) ?? null;
13739
13694
  markTransforming(t);
13740
13695
  didTransformRef.current = true;
13741
13696
  const transformTargetId = t ? getObjectId(t) : null;
@@ -13811,7 +13766,7 @@ const PageCanvas = react.forwardRef(
13811
13766
  setGuides(gridGuidesForTextResize.length ? [...scaleGuides, ...gridGuidesForTextResize] : scaleGuides);
13812
13767
  if (drilledGroupIdRef.current) {
13813
13768
  try {
13814
- (_b2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _b2.call(fabricCanvas);
13769
+ (_a2 = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _a2.call(fabricCanvas);
13815
13770
  } catch {
13816
13771
  }
13817
13772
  }
@@ -13855,26 +13810,19 @@ const PageCanvas = react.forwardRef(
13855
13810
  const activeDuringMove = fabricCanvas.getActiveObject();
13856
13811
  const movingLogicalGroupId = activeDuringMove instanceof fabric__namespace.ActiveSelection ? activeDuringMove.__pixldocsGroupSelection : void 0;
13857
13812
  const pendingMoveDrill = pendingGroupDrillInRef.current;
13858
- const groupIdToKeep = movingLogicalGroupId ?? (pendingMoveDrill == null ? void 0 : pendingMoveDrill.groupId);
13859
13813
  if (movingLogicalGroupId || pendingMoveDrill) {
13814
+ const groupIdToKeep = movingLogicalGroupId ?? (pendingMoveDrill == null ? void 0 : pendingMoveDrill.groupId);
13860
13815
  pendingGroupDrillInRef.current = null;
13861
13816
  fabricCanvas.__activeEditingGroupId = null;
13862
13817
  setDrilledGroupBounds(null);
13863
13818
  drilledGroupIdRef.current = null;
13864
13819
  if (activeDuringMove instanceof fabric__namespace.ActiveSelection && groupIdToKeep) {
13865
13820
  restoreGroupSelectionVisualState(activeDuringMove, groupIdToKeep);
13866
- const memberIds = activeDuringMove.getObjects().map((obj2) => getObjectId(obj2)).filter((id) => !!id && id !== "__background__");
13867
- if (memberIds.length > 1) {
13868
- preserveActiveSelectionAfterTransformRef.current = { memberIds, groupSelectionId: groupIdToKeep, expiresAt: Date.now() + 1200 };
13869
- }
13870
- preserveSelectionAfterTransformIdRef.current = groupIdToKeep;
13871
13821
  }
13872
13822
  }
13873
13823
  if (e.target) e.target.__pixldocsDragMoved = true;
13874
13824
  const moveTargetId = e.target ? getObjectId(e.target) : null;
13875
- if (groupIdToKeep) {
13876
- preserveSelectionAfterTransformIdRef.current = groupIdToKeep;
13877
- } else if (moveTargetId && moveTargetId !== "__background__") {
13825
+ if (moveTargetId && moveTargetId !== "__background__") {
13878
13826
  preserveSelectionAfterTransformIdRef.current = moveTargetId;
13879
13827
  }
13880
13828
  if (!dragStarted) {
@@ -13921,34 +13869,10 @@ const PageCanvas = react.forwardRef(
13921
13869
  }
13922
13870
  });
13923
13871
  let cropGroupSaveTimer = null;
13924
- let objectModifiedInFlight = false;
13925
13872
  fabricCanvas.on("object:modified", (e) => {
13926
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
13927
- if (objectModifiedInFlight) {
13928
- if (shouldLogGroupMove()) {
13929
- console.log("[GRP-MOVE] object:modified re-entry skipped", {
13930
- targetType: (_b2 = (_a2 = e.target) == null ? void 0 : _a2.constructor) == null ? void 0 : _b2.name
13931
- });
13932
- }
13933
- return;
13934
- }
13935
- objectModifiedInFlight = true;
13873
+ var _a2, _b2, _c, _d, _e, _f, _g;
13936
13874
  try {
13937
13875
  dragStarted = false;
13938
- if (shouldLogGroupMove()) {
13939
- const t = e.target;
13940
- console.log("[GRP-MOVE] object:modified fired", {
13941
- targetType: (_c = t == null ? void 0 : t.constructor) == null ? void 0 : _c.name,
13942
- isActiveSelection: t instanceof fabric__namespace.ActiveSelection,
13943
- groupSelectionId: t ? t.__pixldocsGroupSelection : null,
13944
- memberIds: t instanceof fabric__namespace.ActiveSelection ? t.getObjects().map((o) => getObjectId(o)) : [getObjectId(t)],
13945
- targetLeft: t == null ? void 0 : t.left,
13946
- targetTop: t == null ? void 0 : t.top,
13947
- scaleX: t == null ? void 0 : t.scaleX,
13948
- scaleY: t == null ? void 0 : t.scaleY,
13949
- angle: t == null ? void 0 : t.angle
13950
- });
13951
- }
13952
13876
  setGuides([]);
13953
13877
  setGroupOverlayLiveBoundsRef.current(null);
13954
13878
  objectResizeActiveSnapRef.current = null;
@@ -13990,7 +13914,7 @@ const PageCanvas = react.forwardRef(
13990
13914
  const active = fabricCanvas.getActiveObject();
13991
13915
  const activeId = active ? getObjectId(active) : null;
13992
13916
  if (active && activeId && activeId !== "__background__" && !(active instanceof fabric__namespace.Group)) {
13993
- const pageChildrenForParent = ((_d = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _d.children) ?? [];
13917
+ const pageChildrenForParent = ((_a2 = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
13994
13918
  const parentGroup = findParentGroup(pageChildrenForParent, activeId);
13995
13919
  if (parentGroup && isGroup(parentGroup) && parentGroup.backgroundColor) {
13996
13920
  let fabricSectionGroup = active.group && active.group instanceof fabric__namespace.Group ? active.group : null;
@@ -14072,7 +13996,7 @@ const PageCanvas = react.forwardRef(
14072
13996
  useEditorStore.getState().reflowStackGroupInPage(pageId, groupId);
14073
13997
  }
14074
13998
  const stateAfter = useEditorStore.getState();
14075
- const pageAfter = ((_e = stateAfter.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _e.children) ?? [];
13999
+ const pageAfter = ((_b2 = stateAfter.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _b2.children) ?? [];
14076
14000
  const groupNodeAfter = findNodeById(pageAfter, groupId);
14077
14001
  if (groupNodeAfter) {
14078
14002
  const abs = getAbsoluteBounds(groupNodeAfter, pageAfter);
@@ -14134,7 +14058,7 @@ const PageCanvas = react.forwardRef(
14134
14058
  }
14135
14059
  if (active && active instanceof fabric__namespace.Group && active.__docuforgeSectionGroup && getObjectId(active)) {
14136
14060
  const groupId = getObjectId(active);
14137
- const pageChildrenSec = ((_f = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _f.children) ?? [];
14061
+ const pageChildrenSec = ((_c = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _c.children) ?? [];
14138
14062
  const modifiedTarget2 = e == null ? void 0 : e.target;
14139
14063
  const resizeScaleTarget = lastResizeScaleTargetRef.current;
14140
14064
  lastResizeScaleTargetRef.current = null;
@@ -14165,7 +14089,7 @@ const PageCanvas = react.forwardRef(
14165
14089
  const node = findNodeById(pageChildrenSec, groupId);
14166
14090
  if (isChildModified && node && !groupMoved) {
14167
14091
  const stateAfter = useEditorStore.getState();
14168
- const pageAfter = ((_g = stateAfter.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14092
+ const pageAfter = ((_d = stateAfter.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _d.children) ?? [];
14169
14093
  const groupNodeAfter = findNodeById(pageAfter, groupId);
14170
14094
  if (groupNodeAfter) {
14171
14095
  const abs = getAbsoluteBounds(groupNodeAfter, pageAfter);
@@ -14181,7 +14105,7 @@ const PageCanvas = react.forwardRef(
14181
14105
  }
14182
14106
  if (active && active instanceof fabric__namespace.Group && !(active instanceof fabric__namespace.ActiveSelection) && getObjectId(active)) {
14183
14107
  const groupId = getObjectId(active);
14184
- const pageChildren3 = ((_h = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _h.children) ?? [];
14108
+ const pageChildren3 = ((_e = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _e.children) ?? [];
14185
14109
  const w = (active.width ?? 0) * (active.scaleX ?? 1);
14186
14110
  const h = (active.height ?? 0) * (active.scaleY ?? 1);
14187
14111
  const centerX = active.left ?? 0;
@@ -14203,7 +14127,7 @@ const PageCanvas = react.forwardRef(
14203
14127
  }
14204
14128
  const activeObj = fabricCanvas.getActiveObject();
14205
14129
  let activeObjects = fabricCanvas.getActiveObjects();
14206
- const activeSelectionMoveStart = activeObj instanceof fabric__namespace.ActiveSelection && ((_i = activeSelectionMoveStartRef.current) == null ? void 0 : _i.selection) === activeObj ? activeSelectionMoveStartRef.current : null;
14130
+ const activeSelectionMoveStart = activeObj instanceof fabric__namespace.ActiveSelection && ((_f = activeSelectionMoveStartRef.current) == null ? void 0 : _f.selection) === activeObj ? activeSelectionMoveStartRef.current : null;
14207
14131
  const activeSelectionDelta = activeObj instanceof fabric__namespace.ActiveSelection && activeSelectionMoveStart ? (() => {
14208
14132
  const rect = activeObj.getBoundingRect();
14209
14133
  return {
@@ -14294,22 +14218,6 @@ const PageCanvas = react.forwardRef(
14294
14218
  return memberIds.every((mid) => selectedSet.has(mid));
14295
14219
  })();
14296
14220
  const groupToMove = candidateIsStack || allMembersSelected ? candidateGroup : null;
14297
- if (shouldLogGroupMove()) {
14298
- console.log("[GRP-MOVE] entry", {
14299
- selectedElementIds,
14300
- isActiveSelection,
14301
- activeSelectionGroupId: activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.__pixldocsGroupSelection : null,
14302
- parentGroupIds: parentGroups.map((g) => g.id),
14303
- sameDirectParent,
14304
- commonAncestorId: commonAncestor == null ? void 0 : commonAncestor.id,
14305
- candidateGroupId: candidateGroup == null ? void 0 : candidateGroup.id,
14306
- candidateIsStack,
14307
- allMembersSelected,
14308
- groupToMoveId: (groupToMove == null ? void 0 : groupToMove.id) ?? null,
14309
- activeSelectionHadTransform,
14310
- selectedLogicalGroupIds
14311
- });
14312
- }
14313
14221
  if (groupToMove) {
14314
14222
  const activeGroupSelectionId = activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.__pixldocsGroupSelection : void 0;
14315
14223
  const transformStart = activeGroupSelectionId === groupToMove.id ? groupSelectionTransformStartRef.current : null;
@@ -14367,18 +14275,6 @@ const PageCanvas = react.forwardRef(
14367
14275
  const { updateNode: updateNodeStore, commitHistory: commitHistoryStore, getCurrentElements } = useEditorStore.getState();
14368
14276
  const newLeft = (groupToMove.left ?? 0) + deltaX;
14369
14277
  const newTop = (groupToMove.top ?? 0) + deltaY;
14370
- const __dbg = shouldLogGroupMove();
14371
- if (__dbg) {
14372
- console.log("[GRP-MOVE] commit", {
14373
- groupId: groupToMove.id,
14374
- groupAbs,
14375
- movedGroup: { left: movedGroupLeft, top: movedGroupTop },
14376
- delta: { x: deltaX, y: deltaY },
14377
- newStored: { left: newLeft, top: newTop },
14378
- activeSelectionAngle: isActiveSelection && activeObj ? activeObj.angle : null,
14379
- hasGroupSelectionId: !!(isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection && activeObj.__pixldocsGroupSelection)
14380
- });
14381
- }
14382
14278
  updateNodeStore(groupToMove.id, { left: newLeft, top: newTop }, { recordHistory: false, skipLayoutRecalc: true });
14383
14279
  commitHistoryStore();
14384
14280
  pendingGroupDrillInRef.current = null;
@@ -14404,11 +14300,13 @@ const PageCanvas = react.forwardRef(
14404
14300
  }
14405
14301
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14406
14302
  groupSelectionTransformStartRef.current = null;
14407
- activeSelectionMoveStartRef.current = null;
14408
- restorePreservedGroupSelectionSoon({
14303
+ const restoreSnapshot = {
14409
14304
  memberIds: targetObjects.map((obj) => getObjectId(obj)).filter((id) => !!id && id !== "__background__"),
14410
- groupSelectionId
14411
- });
14305
+ groupSelectionId,
14306
+ expiresAt: Date.now() + 1200
14307
+ };
14308
+ recentGroupSelectionRestoreRef.current = restoreSnapshot;
14309
+ restorePreservedGroupSelectionSoon(restoreSnapshot);
14412
14310
  unlockEditsSoon();
14413
14311
  return;
14414
14312
  }
@@ -14576,8 +14474,6 @@ const PageCanvas = react.forwardRef(
14576
14474
  } else if (obj instanceof fabric__namespace.Textbox && isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
14577
14475
  const sx = Math.abs(decomposed.scaleX || 1);
14578
14476
  const sy = Math.abs(decomposed.scaleY || 1);
14579
- const lastCorner = lastResizeScaleCornerRef.current ?? "";
14580
- const isCornerGroupScale = lastCorner === "tl" || lastCorner === "tr" || lastCorner === "bl" || lastCorner === "br";
14581
14477
  const bakedWidth = Math.max(20, intrinsicWidth * sx);
14582
14478
  const bakedHeight = Math.max(1, intrinsicHeight * sy);
14583
14479
  finalWidth = bakedWidth;
@@ -14585,13 +14481,8 @@ const PageCanvas = react.forwardRef(
14585
14481
  finalScaleX = 1;
14586
14482
  finalScaleY = 1;
14587
14483
  try {
14588
- if (isCornerGroupScale) {
14589
- bakeTextboxScaleIntoTypography(obj, sourceElement, { scaleX: sx, scaleY: sy });
14590
- } else {
14591
- obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14592
- obj.minBoxHeight = bakedHeight;
14593
- obj.initDimensions();
14594
- }
14484
+ obj.set({ width: bakedWidth, scaleX: 1, scaleY: 1 });
14485
+ obj.initDimensions();
14595
14486
  obj.setCoords();
14596
14487
  } catch {
14597
14488
  }
@@ -14670,7 +14561,7 @@ const PageCanvas = react.forwardRef(
14670
14561
  updateElement(objId, elementUpdate, { recordHistory: false, skipLayoutRecalc: true });
14671
14562
  obj.setCoords();
14672
14563
  }
14673
- const pageChildrenForReflow = ((_j = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _j.children) ?? [];
14564
+ const pageChildrenForReflow = ((_g = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _g.children) ?? [];
14674
14565
  const stackGroupsToReflow = /* @__PURE__ */ new Set();
14675
14566
  for (const id of modifiedIdsThisRound) {
14676
14567
  const parent = findParentGroup(pageChildrenForReflow, id);
@@ -14732,15 +14623,11 @@ const PageCanvas = react.forwardRef(
14732
14623
  }
14733
14624
  groupSelectionTransformStartRef.current = null;
14734
14625
  activeSelectionMoveStartRef.current = null;
14735
- lastResizeScaleCornerRef.current = null;
14736
14626
  setTimeout(() => modifiedIdsThisRound.forEach((id) => justModifiedIdsRef.current.delete(id)), 150);
14737
14627
  commitHistory();
14738
14628
  unlockEditsSoon();
14739
14629
  } catch (e2) {
14740
- lastResizeScaleCornerRef.current = null;
14741
14630
  unlockEditsSoon();
14742
- } finally {
14743
- objectModifiedInFlight = false;
14744
14631
  }
14745
14632
  });
14746
14633
  fabricCanvas.on("before:selection:cleared", (e) => {
@@ -14998,14 +14885,13 @@ const PageCanvas = react.forwardRef(
14998
14885
  visibilityUpdateInProgressRef.current = false;
14999
14886
  }
15000
14887
  doSyncRef.current = () => {
15001
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
14888
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
15002
14889
  const shouldSkipUpdates2 = syncLockedRef.current || editLockRef.current;
15003
14890
  const state = useEditorStore.getState();
15004
- const storePage = state.canvas.pages.find((p) => p.id === pageId);
15005
- const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : (storePage == null ? void 0 : storePage.children) ?? [];
15006
- const elementsToSync = isPreviewMode ? elements : pageTree.length ? flattenChildren(pageTree) : elements;
14891
+ const elementsToSync = elements;
15007
14892
  elementsRef.current = elementsToSync;
15008
- const selectedIdsFromStore = new Set(((_a2 = state.canvas) == null ? void 0 : _a2.selectedIds) ?? []);
14893
+ const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : ((_a2 = state.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
14894
+ const selectedIdsFromStore = new Set(((_b2 = state.canvas) == null ? void 0 : _b2.selectedIds) ?? []);
15009
14895
  isRebuildingRef.current = true;
15010
14896
  const allElementIds = new Set(elementsToSync.map((el) => el.id));
15011
14897
  const sectionGroups = pageTree.filter(
@@ -15033,7 +14919,7 @@ const PageCanvas = react.forwardRef(
15033
14919
  const activeObjId = activeObj ? getObjectId(activeObj) : null;
15034
14920
  const isTextBeingEdited = activeObjId && editingTextIdRef.current === activeObjId;
15035
14921
  const isMultiSelect = activeObj instanceof fabric__namespace.ActiveSelection;
15036
- if (activeObj && isMultiSelect && !(((_b2 = activeObj._ct) == null ? void 0 : _b2.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
14922
+ if (activeObj && isMultiSelect && !(((_c = activeObj._ct) == null ? void 0 : _c.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
15037
14923
  fc.discardActiveObject();
15038
14924
  }
15039
14925
  }
@@ -15070,7 +14956,7 @@ const PageCanvas = react.forwardRef(
15070
14956
  fc.requestRenderAll();
15071
14957
  }
15072
14958
  } else if (!skipRestoreSelection && restoreTarget && !isActiveTextBeingEdited) {
15073
- const isCropGroup2 = ((_c = restoreTarget._ct) == null ? void 0 : _c.isCropGroup) || restoreTarget.__cropGroup;
14959
+ const isCropGroup2 = ((_d = restoreTarget._ct) == null ? void 0 : _d.isCropGroup) || restoreTarget.__cropGroup;
15074
14960
  const isSectionGroup = activeId && sectionGroupIds.has(activeId);
15075
14961
  if ((isCropGroup2 || !shouldSkipUpdates2) && !isSectionGroup) {
15076
14962
  fc.setActiveObject(restoreTarget);
@@ -15175,42 +15061,9 @@ const PageCanvas = react.forwardRef(
15175
15061
  };
15176
15062
  fc.add(sectionGroup);
15177
15063
  }
15178
- const getActiveSelectionContainingObject = (obj) => {
15179
- const active = fc.getActiveObject();
15180
- return active instanceof fabric__namespace.ActiveSelection && active.getObjects().includes(obj) ? active : null;
15181
- };
15182
- const shouldPreserveActiveSelectionMemberPosition = (obj) => {
15183
- if (syncTriggeredByPanelRef.current) return false;
15184
- const activeSelection = getActiveSelectionContainingObject(obj);
15185
- if (!activeSelection) return false;
15186
- const logicalActiveSelection = activeSelection;
15187
- const logicalGroupId = logicalActiveSelection.__pixldocsGroupSelection;
15188
- const logicalGroupIds = logicalActiveSelection.__pixldocsLogicalGroupIds;
15189
- if (logicalGroupId || Array.isArray(logicalGroupIds)) return true;
15190
- const id = getObjectId(obj);
15191
- const preserved = preserveActiveSelectionAfterTransformRef.current;
15192
- return !!(id && (preserved == null ? void 0 : preserved.memberIds.includes(id)) && (!preserved.expiresAt || preserved.expiresAt > Date.now()));
15193
- };
15194
- const getObjectSyncComparePosition = (obj) => {
15195
- const activeSelection = getActiveSelectionContainingObject(obj);
15196
- if (!activeSelection) return { left: obj.left ?? 0, top: obj.top ?? 0 };
15197
- const point = fabric__namespace.util.transformPoint({ x: obj.left ?? 0, y: obj.top ?? 0 }, activeSelection.calcTransformMatrix());
15198
- let left = point.x;
15199
- let top = point.y;
15200
- const cropObj = obj;
15201
- if (obj instanceof fabric__namespace.Group && cropObj.__cropGroup) {
15202
- const ct = cropObj.__cropData;
15203
- left -= ((ct == null ? void 0 : ct.frameW) ?? obj.width ?? 0) * Math.abs(obj.scaleX ?? 1) / 2;
15204
- top -= ((ct == null ? void 0 : ct.frameH) ?? obj.height ?? 0) * Math.abs(obj.scaleY ?? 1) / 2;
15205
- } else if (obj instanceof fabric__namespace.FabricImage && (obj.originX === "center" || obj.originY === "center")) {
15206
- left -= (obj.width ?? 0) * Math.abs(obj.scaleX ?? 1) / 2;
15207
- top -= (obj.height ?? 0) * Math.abs(obj.scaleY ?? 1) / 2;
15208
- }
15209
- return { left, top };
15210
- };
15211
15064
  for (const element of elementsToSync) {
15212
15065
  if (sectionDescendantIds.has(element.id)) continue;
15213
- const existingObj = currentFabricObjects.get(element.id);
15066
+ let existingObj = currentFabricObjects.get(element.id);
15214
15067
  const isHidden = !element.visible;
15215
15068
  if (existingObj) {
15216
15069
  const isBeingTransformed = transformingIdsRef.current.has(element.id);
@@ -15231,7 +15084,7 @@ const PageCanvas = react.forwardRef(
15231
15084
  const sourceUrlChanged = currentUrlNormalized !== storedUrlNormalized;
15232
15085
  const newFadeKey = edgeFadeKey(element);
15233
15086
  const oldFadeKey = isCropGroup2 ? existingObj.__edgeFadeInputKey || "" : existingObj.__edgeFadeKey || "";
15234
- const innerImg = (_d = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _d._img;
15087
+ const innerImg = (_e = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _e._img;
15235
15088
  const innerOldKey = isCropGroup2 ? oldFadeKey : innerImg ? innerImg.__edgeFadeKey || "" : oldFadeKey;
15236
15089
  const cropFadeRendererMissing = isCropGroup2 && Boolean(newFadeKey) && !existingObj.__edgeFadeRenderConfig;
15237
15090
  const fadeKeyChanged = newFadeKey !== oldFadeKey || newFadeKey !== innerOldKey || cropFadeRendererMissing;
@@ -15239,14 +15092,14 @@ const PageCanvas = react.forwardRef(
15239
15092
  const needsCropGroupFadeUpdate = isCropGroup2 && fadeKeyChanged;
15240
15093
  const hadUrlBefore = storedImageUrl && String(storedImageUrl).trim() !== "";
15241
15094
  if (!hasUrl && hadUrlBefore) {
15242
- const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15095
+ const resolvedSizeImg = (pageChildren == null ? void 0 : pageChildren.length) ? getNodeBounds(element, pageChildren) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15243
15096
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15244
15097
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15245
15098
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
15246
15099
  const nextHeight = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.height) || 50);
15247
- const storePosImg = pageTree.length ? (() => {
15248
- const node = findNodeById(pageTree, element.id);
15249
- return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15100
+ const storePosImg = pageChildren ? (() => {
15101
+ const node = findNodeById(pageChildren, element.id);
15102
+ return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15250
15103
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15251
15104
  const elementForPlaceholder = { ...element, width: nextWidth, height: nextHeight };
15252
15105
  const placeholder = isCropGroup2 ? createImagePlaceholderForGroup(elementForPlaceholder) : createImagePlaceholder(elementForPlaceholder);
@@ -15269,8 +15122,8 @@ const PageCanvas = react.forwardRef(
15269
15122
  fc.requestRenderAll();
15270
15123
  continue;
15271
15124
  }
15272
- const imageFitForReplace = element.imageFit || ((_e = element.style) == null ? void 0 : _e.imageFit) || "cover";
15273
- const clipShapeForReplace = element.clipShape ?? ((_f = element.style) == null ? void 0 : _f.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15125
+ const imageFitForReplace = element.imageFit || ((_f = element.style) == null ? void 0 : _f.imageFit) || "cover";
15126
+ const clipShapeForReplace = element.clipShape ?? ((_g = element.style) == null ? void 0 : _g.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15274
15127
  const needCropGroupForElement = imageFitForReplace !== "fill" || clipShapeForReplace && clipShapeForReplace !== "none";
15275
15128
  const plainImageNeedsCropGroup = hasUrl && !isCropGroup2 && existingObj instanceof fabric__namespace.FabricImage && needCropGroupForElement;
15276
15129
  if (hasUrl && (needsReload || isPlaceholder || plainImageNeedsCropGroup || needsCropGroupFadeUpdate)) {
@@ -15307,9 +15160,9 @@ const PageCanvas = react.forwardRef(
15307
15160
  }
15308
15161
  ct.rx = rxRatio;
15309
15162
  }
15310
- const cropPos = pageTree.length ? (() => {
15311
- const node = findNodeById(pageTree, element.id);
15312
- return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15163
+ const cropPos = pageChildren ? (() => {
15164
+ const node = findNodeById(pageChildren, element.id);
15165
+ return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15313
15166
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15314
15167
  const cropCenterX = cropPos.left + (ct.frameW ?? 0) / 2;
15315
15168
  const cropCenterY = cropPos.top + (ct.frameH ?? 0) / 2;
@@ -15406,7 +15259,7 @@ const PageCanvas = react.forwardRef(
15406
15259
  continue;
15407
15260
  }
15408
15261
  } else if (!hasUrl && !isPlaceholder) {
15409
- const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15262
+ const resolvedSizeImg = (pageChildren == null ? void 0 : pageChildren.length) ? getNodeBounds(element, pageChildren) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15410
15263
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15411
15264
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15412
15265
  const elementForPlaceholder = {
@@ -15436,11 +15289,11 @@ const PageCanvas = react.forwardRef(
15436
15289
  placeholder.__imageSrc = void 0;
15437
15290
  } else if (!isBeingTransformed && !isBeingTextEdited && !shouldSkipUpdates2) {
15438
15291
  if (isPlaceholderGroup) {
15439
- const storePosImg = pageTree.length ? (() => {
15440
- const node = findNodeById(pageTree, element.id);
15441
- return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15292
+ const storePosImg = pageChildren ? (() => {
15293
+ const node = findNodeById(pageChildren, element.id);
15294
+ return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15442
15295
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15443
- const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15296
+ const resolvedSizeImg = (pageChildren == null ? void 0 : pageChildren.length) ? getNodeBounds(element, pageChildren) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15444
15297
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15445
15298
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15446
15299
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
@@ -15500,13 +15353,11 @@ const PageCanvas = react.forwardRef(
15500
15353
  const previousVisible = previousVisibilityRef.current.get(element.id) ?? true;
15501
15354
  const currentVisible = element.visible !== false;
15502
15355
  const visibilityChanged = previousVisible !== currentVisible;
15503
- const storePosForImg = pageTree.length ? (() => {
15504
- const node = findNodeById(pageTree, element.id);
15505
- return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15356
+ const storePosForImg = pageChildren ? (() => {
15357
+ const node = findNodeById(pageChildren, element.id);
15358
+ return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15506
15359
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15507
- const comparePosForImg = getObjectSyncComparePosition(existingObj);
15508
- const preserveSelectionMemberPosition = shouldPreserveActiveSelectionMemberPosition(existingObj);
15509
- const positionChanged = !preserveSelectionMemberPosition && (Math.abs(comparePosForImg.left - storePosForImg.left) > 0.1 || Math.abs(comparePosForImg.top - storePosForImg.top) > 0.1);
15360
+ const positionChanged = Math.abs((existingObj.left ?? 0) - storePosForImg.left) > 0.1 || Math.abs((existingObj.top ?? 0) - storePosForImg.top) > 0.1;
15510
15361
  if (visibilityChanged && !positionChanged || visibilityUpdateInProgressRef.current) {
15511
15362
  const isDynamicField = dynamicFieldIds.includes(element.id);
15512
15363
  const canBeEvented = isEditorMode || isPreviewMode && isDynamicField;
@@ -15521,7 +15372,7 @@ const PageCanvas = react.forwardRef(
15521
15372
  previousVisibilityRef.current.set(element.id, currentVisible);
15522
15373
  } else {
15523
15374
  if (!visibilityUpdateInProgressRef.current) {
15524
- updateFabricObject(existingObj, element, wasJustModified || preserveSelectionMemberPosition);
15375
+ updateFabricObject(existingObj, element, wasJustModified);
15525
15376
  }
15526
15377
  const isDynamicField = dynamicFieldIds.includes(element.id);
15527
15378
  const canBeEvented = isEditorMode || isPreviewMode && isDynamicField;
@@ -15543,19 +15394,17 @@ const PageCanvas = react.forwardRef(
15543
15394
  if (!isBeingTransformed && !isBeingTextEdited && !shouldSkipUpdates2) {
15544
15395
  previousVisibilityRef.current.get(element.id) ?? true;
15545
15396
  const currentVisible = element.visible !== false;
15546
- const comparePos = getObjectSyncComparePosition(existingObj);
15547
- const fabricLeft = comparePos.left;
15548
- const fabricTop = comparePos.top;
15549
- const storePos = pageTree.length ? (() => {
15550
- const node = findNodeById(pageTree, element.id);
15551
- return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15397
+ const fabricLeft = existingObj.left ?? 0;
15398
+ const fabricTop = existingObj.top ?? 0;
15399
+ const storePos = pageChildren ? (() => {
15400
+ const node = findNodeById(pageChildren, element.id);
15401
+ return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15552
15402
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15553
15403
  const storeLeft = storePos.left;
15554
15404
  const storeTop = storePos.top;
15555
15405
  const deltaX = Math.abs(fabricLeft - storeLeft);
15556
15406
  const deltaY = Math.abs(fabricTop - storeTop);
15557
- const preserveSelectionMemberPosition = shouldPreserveActiveSelectionMemberPosition(existingObj);
15558
- let positionChanged = !preserveSelectionMemberPosition && (deltaX > 0.1 || deltaY > 0.1);
15407
+ let positionChanged = deltaX > 0.1 || deltaY > 0.1;
15559
15408
  const activeObj = fc.getActiveObject();
15560
15409
  const isInActiveSelection = activeObj && (activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.getObjects().includes(existingObj) : activeObj === existingObj);
15561
15410
  const isInSelectedIds = selectedIdsFromStore.has(element.id);
@@ -15563,7 +15412,7 @@ const PageCanvas = react.forwardRef(
15563
15412
  if (positionChanged && isSelected && (wasJustModified || isBeingTransformed)) {
15564
15413
  positionChanged = false;
15565
15414
  }
15566
- const resolvedSizeForCompare = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 0, height: typeof element.height === "number" ? element.height : 0 };
15415
+ const resolvedSizeForCompare = (pageChildren == null ? void 0 : pageChildren.length) ? getNodeBounds(element, pageChildren) : { width: typeof element.width === "number" ? element.width : 0, height: typeof element.height === "number" ? element.height : 0 };
15567
15416
  const fabricText = existingObj.text ?? "";
15568
15417
  const storeText = element.text ?? "";
15569
15418
  const otherPropsChanged = Math.abs((existingObj.width ?? 0) - resolvedSizeForCompare.width) > 0.1 || Math.abs((existingObj.height ?? 0) - resolvedSizeForCompare.height) > 0.1 || Math.abs((existingObj.angle ?? 0) - (element.angle ?? 0)) > 0.1 || Math.abs((existingObj.scaleX ?? 1) - (element.scaleX ?? 1)) > 0.01 || Math.abs((existingObj.scaleY ?? 1) - (element.scaleY ?? 1)) > 0.01 || (existingObj.flipX ?? false) !== (element.flipX ?? false) || (existingObj.flipY ?? false) !== (element.flipY ?? false) || fabricText !== storeText || existingObj.fill !== (element.fill ?? "") || existingObj.stroke !== (element.stroke ?? "") || Math.abs((existingObj.strokeWidth ?? 0) - (element.strokeWidth ?? 0)) > 0.01 || Math.abs((existingObj.opacity ?? 1) - (element.opacity ?? 1)) > 0.01 || (existingObj.fontSize ?? 0) !== (element.fontSize ?? 0) || (existingObj.fontFamily ?? "") !== (element.fontFamily ?? "") || // Vertical alignment & min box height: panel-driven changes must trigger a re-apply
@@ -15607,28 +15456,8 @@ const PageCanvas = react.forwardRef(
15607
15456
  });
15608
15457
  previousVisibilityRef.current.set(element.id, currentVisible);
15609
15458
  } else {
15610
- const skipPositionBecauseSelection = preserveSelectionMemberPosition || isSelected && (deltaX > 0.1 || deltaY > 0.1) && (wasJustModified || isBeingTransformed);
15459
+ const skipPositionBecauseSelection = isSelected && (deltaX > 0.1 || deltaY > 0.1) && (wasJustModified || isBeingTransformed);
15611
15460
  const anyChange = positionChanged || otherPropsChanged || forceApplyFromPanel;
15612
- if (shouldLogGroupMove() && (preserveSelectionMemberPosition || (deltaX > 0.1 || deltaY > 0.1))) {
15613
- console.log("[GRP-MOVE] doSync-member", {
15614
- id: element.id,
15615
- type: element.type,
15616
- fabric: { left: fabricLeft, top: fabricTop },
15617
- store: { left: storeLeft, top: storeTop },
15618
- delta: { x: deltaX, y: deltaY },
15619
- flags: {
15620
- preserveSelectionMemberPosition,
15621
- isSelected,
15622
- wasJustModified,
15623
- isBeingTransformed,
15624
- positionChanged,
15625
- otherPropsChanged,
15626
- skipPositionBecauseSelection,
15627
- anyChange,
15628
- syncTriggeredByPanel: syncTriggeredByPanelRef.current
15629
- }
15630
- });
15631
- }
15632
15461
  if (!visibilityUpdateInProgressRef.current) {
15633
15462
  if (anyChange && !skipPositionBecauseSelection) {
15634
15463
  updateFabricObject(existingObj, element, wasJustModified);
@@ -15724,7 +15553,7 @@ const PageCanvas = react.forwardRef(
15724
15553
  fc.add(placeholder);
15725
15554
  fc.bringObjectToFront(placeholder);
15726
15555
  const activeObj = fc.getActiveObject();
15727
- if (activeObj && (((_g = activeObj._ct) == null ? void 0 : _g.isCropGroup) || activeObj.__cropGroup)) {
15556
+ if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15728
15557
  fc.setActiveObject(activeObj);
15729
15558
  }
15730
15559
  placeholder.dirty = true;
@@ -15764,7 +15593,7 @@ const PageCanvas = react.forwardRef(
15764
15593
  fc.add(obj);
15765
15594
  fc.bringObjectToFront(obj);
15766
15595
  const activeObj = fc.getActiveObject();
15767
- if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15596
+ if (activeObj && (((_i = activeObj._ct) == null ? void 0 : _i.isCropGroup) || activeObj.__cropGroup)) {
15768
15597
  fc.setActiveObject(activeObj);
15769
15598
  }
15770
15599
  obj.dirty = true;
@@ -15794,20 +15623,10 @@ const PageCanvas = react.forwardRef(
15794
15623
  });
15795
15624
  allFabricObjects.forEach((obj) => fc.bringObjectToFront(obj));
15796
15625
  }
15797
- const activeAfterObjectSync = fc.getActiveObject();
15798
- if (activeAfterObjectSync instanceof fabric__namespace.ActiveSelection) {
15799
- const groupSelectionId = activeAfterObjectSync.__pixldocsGroupSelection;
15800
- if (groupSelectionId) {
15801
- applyLogicalGroupSelectionVisualState(activeAfterObjectSync, groupSelectionId);
15802
- if (!activeAfterObjectSync.getObjects().every((obj) => !(obj instanceof fabric__namespace.Group))) {
15803
- activeAfterObjectSync.setCoords();
15804
- }
15805
- }
15806
- }
15807
15626
  isRebuildingRef.current = false;
15808
15627
  fc.requestRenderAll();
15809
15628
  if (activeBeforeSync && fc.getObjects().includes(activeBeforeSync)) {
15810
- const isCropGroup2 = ((_i = activeBeforeSync._ct) == null ? void 0 : _i.isCropGroup) || activeBeforeSync.__cropGroup;
15629
+ const isCropGroup2 = ((_j = activeBeforeSync._ct) == null ? void 0 : _j.isCropGroup) || activeBeforeSync.__cropGroup;
15811
15630
  if (isCropGroup2) {
15812
15631
  fc.setActiveObject(activeBeforeSync);
15813
15632
  fc.requestRenderAll();
@@ -15860,9 +15679,7 @@ const PageCanvas = react.forwardRef(
15860
15679
  applyLogicalGroupSelectionVisualState(newSel, activeSelectionSnapshot.groupSelectionId);
15861
15680
  }
15862
15681
  fc.setActiveObject(newSel);
15863
- if (!(activeSelectionSnapshot.groupSelectionId && newSel.getObjects().every((obj) => !(obj instanceof fabric__namespace.Group)))) {
15864
- newSel.setCoords();
15865
- }
15682
+ newSel.setCoords();
15866
15683
  fc.requestRenderAll();
15867
15684
  } finally {
15868
15685
  isSyncingSelectionToFabricRef.current = false;
@@ -15890,6 +15707,10 @@ const PageCanvas = react.forwardRef(
15890
15707
  }
15891
15708
  }
15892
15709
  }
15710
+ const recentGroupRestore = recentGroupSelectionRestoreRef.current;
15711
+ if ((recentGroupRestore == null ? void 0 : recentGroupRestore.groupSelectionId) && recentGroupRestore.expiresAt > Date.now()) {
15712
+ restoreGroupSelectionSnapshot(recentGroupRestore);
15713
+ }
15893
15714
  preserveSelectionAfterTransformIdRef.current = null;
15894
15715
  preserveActiveSelectionAfterTransformRef.current = null;
15895
15716
  syncTriggeredByPanelRef.current = false;
@@ -16166,6 +15987,7 @@ const PageCanvas = react.forwardRef(
16166
15987
  });
16167
15988
  if (isPureSingleGroupSelection) {
16168
15989
  active.hasBorders = true;
15990
+ active.setCoords();
16169
15991
  applyWarpAwareSelectionBorders(active);
16170
15992
  }
16171
15993
  }
@@ -16234,7 +16056,7 @@ const PageCanvas = react.forwardRef(
16234
16056
  if (fc && isTransforming(fc)) {
16235
16057
  return;
16236
16058
  }
16237
- const currentPageTree = (isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_a2 = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
16059
+ const currentPageTree = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_a2 = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
16238
16060
  const fabricPos = currentPageTree.length > 0 ? (() => {
16239
16061
  const node = findNodeById(currentPageTree, element.id);
16240
16062
  return node ? getAbsoluteBounds(node, currentPageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -17302,7 +17124,7 @@ const PageCanvas = react.forwardRef(
17302
17124
  if (imageFit === "fill" && !needCropGroup2) {
17303
17125
  const finalScaleX = baseScaleX * (element.scaleX ?? 1);
17304
17126
  const finalScaleY = baseScaleY * (element.scaleY ?? 1);
17305
- const pageTreeForCreate = ((isPreviewMode || isExportMode) && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_f = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _f.children) ?? [];
17127
+ const pageTreeForCreate = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_f = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _f.children) ?? [];
17306
17128
  const createPos = pageTreeForCreate.length > 0 ? (() => {
17307
17129
  const node = findNodeById(pageTreeForCreate, element.id);
17308
17130
  return node ? getAbsoluteBounds(node, pageTreeForCreate) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -17352,7 +17174,7 @@ const PageCanvas = react.forwardRef(
17352
17174
  const needCropGroup = imageFitFinal !== "fill" || clipShapeFinal && clipShapeFinal !== "none";
17353
17175
  let finalObject = img;
17354
17176
  if (needCropGroup) {
17355
- const pageTreeForCropResolve = ((isPreviewMode || isExportMode) && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_i = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _i.children) ?? [];
17177
+ const pageTreeForCropResolve = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_i = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _i.children) ?? [];
17356
17178
  const nodeForSize = pageTreeForCropResolve.length ? findNodeById(pageTreeForCropResolve, element.id) : null;
17357
17179
  const w = nodeForSize && isElement(nodeForSize) ? nodeForSize.width : element.width;
17358
17180
  const h = nodeForSize && isElement(nodeForSize) ? nodeForSize.height : element.height;
@@ -17396,7 +17218,7 @@ const PageCanvas = react.forwardRef(
17396
17218
  }
17397
17219
  const isDynamicField = dynamicFieldIds.includes(element.id);
17398
17220
  const canBeEvented = isEditorMode || isPreviewMode && isDynamicField;
17399
- const pageTreeForCrop = ((isPreviewMode || isExportMode) && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_n = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _n.children) ?? [];
17221
+ const pageTreeForCrop = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_n = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _n.children) ?? [];
17400
17222
  const createPosForCrop = pageTreeForCrop.length > 0 ? (() => {
17401
17223
  const node = findNodeById(pageTreeForCrop, element.id);
17402
17224
  return node ? getAbsoluteBounds(node, pageTreeForCrop) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -23812,9 +23634,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23812
23634
  }
23813
23635
  return svgString;
23814
23636
  }
23815
- const resolvedPackageVersion = "0.5.284";
23637
+ const resolvedPackageVersion = "0.5.286";
23816
23638
  const PACKAGE_VERSION = resolvedPackageVersion;
23817
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.284";
23639
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.286";
23818
23640
  const roundParityValue = (value) => {
23819
23641
  if (typeof value !== "number") return value;
23820
23642
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24628,7 +24450,7 @@ class PixldocsRenderer {
24628
24450
  await this.waitForCanvasScene(container, cloned, i);
24629
24451
  }
24630
24452
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24631
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-C28yMJ_a.cjs"));
24453
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DqdRBbl_.cjs"));
24632
24454
  const prepared = preparePagesForExport(
24633
24455
  cloned.pages,
24634
24456
  canvasWidth,
@@ -26948,7 +26770,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26948
26770
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26949
26771
  sanitizeSvgTreeForPdf(svgToDraw);
26950
26772
  try {
26951
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-C28yMJ_a.cjs"));
26773
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DqdRBbl_.cjs"));
26952
26774
  try {
26953
26775
  await logTextMeasurementDiagnostic(svgToDraw);
26954
26776
  } catch {
@@ -27345,4 +27167,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
27345
27167
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
27346
27168
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
27347
27169
  exports.warmTemplateFromForm = warmTemplateFromForm;
27348
- //# sourceMappingURL=index-n9HBI3ow.cjs.map
27170
+ //# sourceMappingURL=index-4L9uZ78v.cjs.map