@pixldocs/canvas-renderer 0.5.493 → 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 {
@@ -12292,6 +12297,36 @@ const PageCanvas = forwardRef(
12292
12297
  useEffect(() => {
12293
12298
  selectedIdsRef.current = selectedIds;
12294
12299
  }, [selectedIds]);
12300
+ useEffect(() => {
12301
+ const fc = fabricRef.current;
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]);
12295
12330
  useEffect(() => {
12296
12331
  const fc = fabricRef.current;
12297
12332
  if (!fc || !currentPage) return;
@@ -13757,7 +13792,7 @@ const PageCanvas = forwardRef(
13757
13792
  syncLockedRef.current = false;
13758
13793
  }
13759
13794
  const preservedGroupSelection = preserveActiveSelectionAfterTransformRef.current;
13760
- 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()));
13761
13796
  if (skipSelectionClearOnDiscardRef.current) {
13762
13797
  skipSelectionClearOnDiscardRef.current = false;
13763
13798
  return;
@@ -14011,9 +14046,13 @@ const PageCanvas = forwardRef(
14011
14046
  suppressBordersForObjects(memberObjects);
14012
14047
  };
14013
14048
  const restorePreservedGroupSelectionSoon = (snapshot = preserveActiveSelectionAfterTransformRef.current) => {
14014
- if (!(snapshot == null ? void 0 : snapshot.groupSelectionId) || snapshot.memberIds.length < 2) return;
14049
+ if (!snapshot || snapshot.memberIds.length < 2) return;
14015
14050
  const groupId = snapshot.groupSelectionId;
14016
- selectElements([groupId], false, false);
14051
+ if (groupId) {
14052
+ selectElements([groupId], false, false);
14053
+ } else {
14054
+ selectElements(snapshot.memberIds, false, false);
14055
+ }
14017
14056
  requestAnimationFrame(() => {
14018
14057
  setTimeout(() => {
14019
14058
  if (!isActiveRef.current) return;
@@ -14023,7 +14062,7 @@ const PageCanvas = forwardRef(
14023
14062
  const sameMembers = activeIds.length === snapshot.memberIds.length && snapshot.memberIds.every((id) => activeIds.includes(id));
14024
14063
  const sameGroup = active.__pixldocsGroupSelection === snapshot.groupSelectionId;
14025
14064
  const alreadyAligned = active.__pixldocsAlignedAngle != null;
14026
- if (sameMembers && sameGroup && alreadyAligned) {
14065
+ if (sameMembers && (!groupId || sameGroup && alreadyAligned)) {
14027
14066
  ensureCanvaControlRenders(active);
14028
14067
  return;
14029
14068
  }
@@ -17421,7 +17460,8 @@ const PageCanvas = forwardRef(
17421
17460
  }
17422
17461
  return memberIds.length > 0 ? { ...rawActiveSelectionSnapshot, memberIds, groupSelectionId } : null;
17423
17462
  })() : null;
17424
- 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) {
17425
17465
  const activeObj = fc.getActiveObject();
17426
17466
  const activeObjId = activeObj ? getObjectId(activeObj) : null;
17427
17467
  const isTextBeingEdited = activeObjId && editingTextIdRef.current === activeObjId;
@@ -17437,7 +17477,7 @@ const PageCanvas = forwardRef(
17437
17477
  currentFabricObjects.set(id, obj);
17438
17478
  }
17439
17479
  });
17440
- const skipRestoreSelection = syncTriggeredByPanelRef.current && !transformSelectionId;
17480
+ const skipRestoreSelection = syncTriggeredByPanelRef.current && !transformSelectionId && !hasFreshPreservedActiveSelection;
17441
17481
  const activeId = transformSelectionId || (activeBeforeSync ? getObjectId(activeBeforeSync) : null);
17442
17482
  const activeStillOnCanvas = activeBeforeSync && fc.getObjects().includes(activeBeforeSync);
17443
17483
  const replacementById = !activeStillOnCanvas && activeId ? fc.getObjects().find((o) => getObjectId(o) === activeId) ?? null : null;
@@ -18280,6 +18320,11 @@ const PageCanvas = forwardRef(
18280
18320
  const recentGroupRestore = recentGroupSelectionRestoreRef.current;
18281
18321
  if ((recentGroupRestore == null ? void 0 : recentGroupRestore.groupSelectionId) && recentGroupRestore.expiresAt > Date.now()) {
18282
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
+ }
18283
18328
  }
18284
18329
  preserveSelectionAfterTransformIdRef.current = null;
18285
18330
  preserveActiveSelectionAfterTransformRef.current = null;
@@ -26518,9 +26563,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
26518
26563
  }
26519
26564
  return svgString;
26520
26565
  }
26521
- const resolvedPackageVersion = "0.5.493";
26566
+ const resolvedPackageVersion = "0.5.494";
26522
26567
  const PACKAGE_VERSION = resolvedPackageVersion;
26523
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.493";
26568
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.494";
26524
26569
  const roundParityValue = (value) => {
26525
26570
  if (typeof value !== "number") return value;
26526
26571
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -27334,7 +27379,7 @@ class PixldocsRenderer {
27334
27379
  await this.waitForCanvasScene(container, cloned, i);
27335
27380
  }
27336
27381
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
27337
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CouKfyYT.js");
27382
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-Bazeq3bN.js");
27338
27383
  const prepared = preparePagesForExport(
27339
27384
  cloned.pages,
27340
27385
  canvasWidth,
@@ -29654,7 +29699,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29654
29699
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29655
29700
  sanitizeSvgTreeForPdf(svgToDraw);
29656
29701
  try {
29657
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CouKfyYT.js");
29702
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-Bazeq3bN.js");
29658
29703
  try {
29659
29704
  await logTextMeasurementDiagnostic(svgToDraw);
29660
29705
  } catch {
@@ -29971,4 +30016,4 @@ export {
29971
30016
  buildTeaserBlurFlatKeys as y,
29972
30017
  collectFontDescriptorsFromConfig as z
29973
30018
  };
29974
- //# sourceMappingURL=index-yWZhNUVq.js.map
30019
+ //# sourceMappingURL=index-dxfsI5E1.js.map