@pixldocs/canvas-renderer 0.5.492 → 0.5.494

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.
@@ -2041,12 +2041,17 @@ const useEditorStore = create((set, get) => ({
2041
2041
  toggleElementLock: (id) => set((state) => {
2042
2042
  const currentPage = getCurrentPageFromCanvas(state.canvas);
2043
2043
  const node = findNodeById(currentPage.children, id);
2044
- if (!node || isGroup(node)) return {};
2044
+ if (!node) return {};
2045
+ const wasLocked = !!node.locked || node.selectable === false;
2046
+ const nextLocked = !wasLocked;
2045
2047
  const nextCanvas = updateCurrentPageChildren(
2046
2048
  state.canvas,
2047
2049
  (children) => updateNodeInTree(children, id, {
2048
- selectable: !node.selectable,
2049
- evented: !node.evented
2050
+ locked: nextLocked,
2051
+ // Keep legacy selectable/evented in sync with the canonical flag so
2052
+ // fabricObjectCreators (which also honors selectable === false)
2053
+ // stays consistent for elements loaded from older configs.
2054
+ ...isGroup(node) ? {} : { selectable: !nextLocked, evented: !nextLocked }
2050
2055
  })
2051
2056
  );
2052
2057
  const committed = commitFromState(state, nextCanvas);
@@ -12229,7 +12234,7 @@ const PageCanvas = forwardRef(
12229
12234
  var _a2;
12230
12235
  const fc = fabricRef.current;
12231
12236
  const groupId = snapshot == null ? void 0 : snapshot.groupSelectionId;
12232
- if (!fc || !groupId || snapshot.memberIds.length < 2 || editingTextIdRef.current) return;
12237
+ if (!fc || !snapshot || snapshot.memberIds.length < 2 || editingTextIdRef.current) return;
12233
12238
  const members = snapshot.memberIds.map((id) => fc.getObjects().find((o) => getObjectId(o) === id)).filter((o) => !!o);
12234
12239
  if (members.length < 2) return;
12235
12240
  const activeBeforeRestore = fc.getActiveObject();
@@ -12238,7 +12243,7 @@ const PageCanvas = forwardRef(
12238
12243
  const sameMembers = activeMembers.length === members.length && members.every((member) => activeMembers.includes(member));
12239
12244
  const sameGroup = activeBeforeRestore.__pixldocsGroupSelection === groupId;
12240
12245
  const alreadyAligned = activeBeforeRestore.__pixldocsAlignedAngle != null;
12241
- if (sameMembers && sameGroup && alreadyAligned) {
12246
+ if (sameMembers && (!groupId || sameGroup && alreadyAligned)) {
12242
12247
  ensureCanvaControlRenders(activeBeforeRestore);
12243
12248
  return;
12244
12249
  }
@@ -12247,7 +12252,7 @@ const PageCanvas = forwardRef(
12247
12252
  try {
12248
12253
  const active = activeBeforeRestore;
12249
12254
  const selection = active instanceof fabric.ActiveSelection && members.every((member) => active.getObjects().includes(member)) ? active : new fabric.ActiveSelection(members, { canvas: fc });
12250
- applyLogicalGroupSelectionVisualState(selection, groupId);
12255
+ if (groupId) applyLogicalGroupSelectionVisualState(selection, groupId);
12251
12256
  ensureCanvaControlRenders(selection);
12252
12257
  fc.setActiveObject(selection);
12253
12258
  try {
@@ -12294,7 +12299,53 @@ const PageCanvas = forwardRef(
12294
12299
  }, [selectedIds]);
12295
12300
  useEffect(() => {
12296
12301
  const fc = fabricRef.current;
12297
- if (!fc || !isActive || !currentPage) return;
12302
+ if (!fc || !isEditorMode || !currentPage) return;
12303
+ const lockedIds = /* @__PURE__ */ new Set();
12304
+ const walk = (nodes, parentLocked) => {
12305
+ for (const n of nodes) {
12306
+ const nodeLocked = !!n.locked || n.selectable === false;
12307
+ const eff = parentLocked || nodeLocked;
12308
+ if (eff) lockedIds.add(n.id);
12309
+ if (isGroup(n)) walk(n.children ?? [], eff);
12310
+ }
12311
+ };
12312
+ walk(currentPage.children ?? [], false);
12313
+ fc.getObjects().forEach((o) => {
12314
+ const id = getObjectId(o);
12315
+ if (!id || id === "__background__") return;
12316
+ const locked = lockedIds.has(id);
12317
+ o.set({
12318
+ lockMovementX: locked,
12319
+ lockMovementY: locked,
12320
+ lockScalingX: locked,
12321
+ lockScalingY: locked,
12322
+ lockRotation: locked,
12323
+ lockSkewingX: locked,
12324
+ lockSkewingY: locked,
12325
+ hoverCursor: locked ? "not-allowed" : void 0
12326
+ });
12327
+ });
12328
+ fc.requestRenderAll();
12329
+ }, [currentPage == null ? void 0 : currentPage.children, isEditorMode, elements]);
12330
+ useEffect(() => {
12331
+ const fc = fabricRef.current;
12332
+ if (!fc || !currentPage) return;
12333
+ if (!isActive) {
12334
+ try {
12335
+ fc.__activeEditingGroupId = null;
12336
+ drilledGroupIdRef.current = null;
12337
+ setDrilledGroupBounds(null);
12338
+ preserveActiveSelectionAfterTransformRef.current = null;
12339
+ recentGroupSelectionRestoreRef.current = null;
12340
+ if (fc.getActiveObject()) {
12341
+ fc.discardActiveObject();
12342
+ }
12343
+ clearCanvasActiveVisuals(fc);
12344
+ fc.requestRenderAll();
12345
+ } catch {
12346
+ }
12347
+ return;
12348
+ }
12298
12349
  const pageChildren2 = currentPage.children ?? [];
12299
12350
  const hasMissingSelection = selectedIds.some((id) => !findNodeById(pageChildren2, id));
12300
12351
  const activeEditingGroupId = fc.__activeEditingGroupId ?? null;
@@ -13741,7 +13792,7 @@ const PageCanvas = forwardRef(
13741
13792
  syncLockedRef.current = false;
13742
13793
  }
13743
13794
  const preservedGroupSelection = preserveActiveSelectionAfterTransformRef.current;
13744
- const shouldRestoreGroupSelection = !!((preservedGroupSelection == null ? void 0 : preservedGroupSelection.groupSelectionId) && (!preservedGroupSelection.expiresAt || preservedGroupSelection.expiresAt > Date.now()));
13795
+ const shouldRestoreGroupSelection = !!(preservedGroupSelection && preservedGroupSelection.memberIds.length >= 2 && (!preservedGroupSelection.expiresAt || preservedGroupSelection.expiresAt > Date.now()));
13745
13796
  if (skipSelectionClearOnDiscardRef.current) {
13746
13797
  skipSelectionClearOnDiscardRef.current = false;
13747
13798
  return;
@@ -13995,9 +14046,13 @@ const PageCanvas = forwardRef(
13995
14046
  suppressBordersForObjects(memberObjects);
13996
14047
  };
13997
14048
  const restorePreservedGroupSelectionSoon = (snapshot = preserveActiveSelectionAfterTransformRef.current) => {
13998
- if (!(snapshot == null ? void 0 : snapshot.groupSelectionId) || snapshot.memberIds.length < 2) return;
14049
+ if (!snapshot || snapshot.memberIds.length < 2) return;
13999
14050
  const groupId = snapshot.groupSelectionId;
14000
- selectElements([groupId], false, false);
14051
+ if (groupId) {
14052
+ selectElements([groupId], false, false);
14053
+ } else {
14054
+ selectElements(snapshot.memberIds, false, false);
14055
+ }
14001
14056
  requestAnimationFrame(() => {
14002
14057
  setTimeout(() => {
14003
14058
  if (!isActiveRef.current) return;
@@ -14007,7 +14062,7 @@ const PageCanvas = forwardRef(
14007
14062
  const sameMembers = activeIds.length === snapshot.memberIds.length && snapshot.memberIds.every((id) => activeIds.includes(id));
14008
14063
  const sameGroup = active.__pixldocsGroupSelection === snapshot.groupSelectionId;
14009
14064
  const alreadyAligned = active.__pixldocsAlignedAngle != null;
14010
- if (sameMembers && sameGroup && alreadyAligned) {
14065
+ if (sameMembers && (!groupId || sameGroup && alreadyAligned)) {
14011
14066
  ensureCanvaControlRenders(active);
14012
14067
  return;
14013
14068
  }
@@ -17120,6 +17175,10 @@ const PageCanvas = forwardRef(
17120
17175
  const innerImg = ct == null ? void 0 : ct._img;
17121
17176
  const innerSrc = ((_a2 = innerImg == null ? void 0 : innerImg.getSrc) == null ? void 0 : _a2.call(innerImg)) || ((_b2 = innerImg == null ? void 0 : innerImg._originalElement) == null ? void 0 : _b2.src) || (innerImg == null ? void 0 : innerImg.src) || "";
17122
17177
  const isPlaceholder = !innerSrc || innerSrc === EMPTY_IMAGE_PLACEHOLDER_DATA_URL;
17178
+ const activatedAt = cropGroupActivatedAtRef.current.get(target) ?? 0;
17179
+ if (Date.now() - activatedAt < 400) {
17180
+ return;
17181
+ }
17123
17182
  const targetId = getObjectId(target);
17124
17183
  const pageChildrenForCrop = ((_c2 = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _c2.children) ?? [];
17125
17184
  const parentForCrop = targetId ? findParentGroup(pageChildrenForCrop, targetId) : null;
@@ -17136,10 +17195,6 @@ const PageCanvas = forwardRef(
17136
17195
  }
17137
17196
  return;
17138
17197
  }
17139
- const activatedAt = cropGroupActivatedAtRef.current.get(target) ?? 0;
17140
- if (Date.now() - activatedAt < 400) {
17141
- return;
17142
- }
17143
17198
  }
17144
17199
  if (innerImg && !isPlaceholder && !isCropGroupInCropMode(target)) {
17145
17200
  enterCropMode(target);
@@ -17405,7 +17460,8 @@ const PageCanvas = forwardRef(
17405
17460
  }
17406
17461
  return memberIds.length > 0 ? { ...rawActiveSelectionSnapshot, memberIds, groupSelectionId } : null;
17407
17462
  })() : null;
17408
- if (syncTriggeredByPanelRef.current && !transformSelectionId && !shouldSkipUpdates2 && !isTransforming2) {
17463
+ const hasFreshPreservedActiveSelection = !!(activeSelectionSnapshot && activeSelectionSnapshot.memberIds.length >= 2 && preserveActiveSelectionAfterTransformRef.current && (!preserveActiveSelectionAfterTransformRef.current.expiresAt || preserveActiveSelectionAfterTransformRef.current.expiresAt > Date.now()));
17464
+ if (syncTriggeredByPanelRef.current && !transformSelectionId && !hasFreshPreservedActiveSelection && !shouldSkipUpdates2 && !isTransforming2) {
17409
17465
  const activeObj = fc.getActiveObject();
17410
17466
  const activeObjId = activeObj ? getObjectId(activeObj) : null;
17411
17467
  const isTextBeingEdited = activeObjId && editingTextIdRef.current === activeObjId;
@@ -17421,7 +17477,7 @@ const PageCanvas = forwardRef(
17421
17477
  currentFabricObjects.set(id, obj);
17422
17478
  }
17423
17479
  });
17424
- const skipRestoreSelection = syncTriggeredByPanelRef.current && !transformSelectionId;
17480
+ const skipRestoreSelection = syncTriggeredByPanelRef.current && !transformSelectionId && !hasFreshPreservedActiveSelection;
17425
17481
  const activeId = transformSelectionId || (activeBeforeSync ? getObjectId(activeBeforeSync) : null);
17426
17482
  const activeStillOnCanvas = activeBeforeSync && fc.getObjects().includes(activeBeforeSync);
17427
17483
  const replacementById = !activeStillOnCanvas && activeId ? fc.getObjects().find((o) => getObjectId(o) === activeId) ?? null : null;
@@ -18264,6 +18320,11 @@ const PageCanvas = forwardRef(
18264
18320
  const recentGroupRestore = recentGroupSelectionRestoreRef.current;
18265
18321
  if ((recentGroupRestore == null ? void 0 : recentGroupRestore.groupSelectionId) && recentGroupRestore.expiresAt > Date.now()) {
18266
18322
  restoreGroupSelectionSnapshot(recentGroupRestore);
18323
+ } else {
18324
+ const preservedActiveSelectionRestore = preserveActiveSelectionAfterTransformRef.current;
18325
+ if (preservedActiveSelectionRestore && preservedActiveSelectionRestore.memberIds.length >= 2 && (!preservedActiveSelectionRestore.expiresAt || preservedActiveSelectionRestore.expiresAt > Date.now())) {
18326
+ restoreGroupSelectionSnapshot(preservedActiveSelectionRestore);
18327
+ }
18267
18328
  }
18268
18329
  preserveSelectionAfterTransformIdRef.current = null;
18269
18330
  preserveActiveSelectionAfterTransformRef.current = null;
@@ -26502,9 +26563,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
26502
26563
  }
26503
26564
  return svgString;
26504
26565
  }
26505
- const resolvedPackageVersion = "0.5.492";
26566
+ const resolvedPackageVersion = "0.5.494";
26506
26567
  const PACKAGE_VERSION = resolvedPackageVersion;
26507
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.492";
26568
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.494";
26508
26569
  const roundParityValue = (value) => {
26509
26570
  if (typeof value !== "number") return value;
26510
26571
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -27318,7 +27379,7 @@ class PixldocsRenderer {
27318
27379
  await this.waitForCanvasScene(container, cloned, i);
27319
27380
  }
27320
27381
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
27321
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-rz4LyyuM.js");
27382
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-Bazeq3bN.js");
27322
27383
  const prepared = preparePagesForExport(
27323
27384
  cloned.pages,
27324
27385
  canvasWidth,
@@ -29638,7 +29699,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29638
29699
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29639
29700
  sanitizeSvgTreeForPdf(svgToDraw);
29640
29701
  try {
29641
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-rz4LyyuM.js");
29702
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-Bazeq3bN.js");
29642
29703
  try {
29643
29704
  await logTextMeasurementDiagnostic(svgToDraw);
29644
29705
  } catch {
@@ -29955,4 +30016,4 @@ export {
29955
30016
  buildTeaserBlurFlatKeys as y,
29956
30017
  collectFontDescriptorsFromConfig as z
29957
30018
  };
29958
- //# sourceMappingURL=index-DHzIvJSN.js.map
30019
+ //# sourceMappingURL=index-dxfsI5E1.js.map