@pixldocs/canvas-renderer 0.5.268 → 0.5.269

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.
@@ -14301,9 +14301,21 @@ const PageCanvas = forwardRef(
14301
14301
  const groupSelectionId = (isActiveSelection && activeObj instanceof fabric.ActiveSelection ? activeObj.__pixldocsGroupSelection : void 0) ?? groupToMove.id;
14302
14302
  const targetObjects = isActiveSelection && activeObj instanceof fabric.ActiveSelection ? activeObj.getObjects() : activeObjects;
14303
14303
  if (groupSelectionId && activeObj instanceof fabric.ActiveSelection) {
14304
- restoreGroupSelectionVisualState(activeObj, groupSelectionId);
14305
- fabricCanvas.setActiveObject(activeObj);
14306
- activeObj.setCoords();
14304
+ try {
14305
+ skipSelectionClearOnDiscardRef.current = true;
14306
+ skipActiveSelectionBakeOnClearRef.current = true;
14307
+ try {
14308
+ fabricCanvas.discardActiveObject();
14309
+ } finally {
14310
+ skipActiveSelectionBakeOnClearRef.current = false;
14311
+ skipSelectionClearOnDiscardRef.current = false;
14312
+ }
14313
+ } catch {
14314
+ }
14315
+ const bakedSelection = targetObjects.length > 1 ? new fabric.ActiveSelection(targetObjects, { canvas: fabricCanvas }) : activeObj;
14316
+ restoreGroupSelectionVisualState(bakedSelection, groupSelectionId);
14317
+ fabricCanvas.setActiveObject(bakedSelection);
14318
+ bakedSelection.setCoords();
14307
14319
  }
14308
14320
  selectElements([groupSelectionId], false, false);
14309
14321
  fabricCanvas.requestRenderAll();
@@ -14899,13 +14911,14 @@ const PageCanvas = forwardRef(
14899
14911
  visibilityUpdateInProgressRef.current = false;
14900
14912
  }
14901
14913
  doSyncRef.current = () => {
14902
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
14914
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
14903
14915
  const shouldSkipUpdates2 = syncLockedRef.current || editLockRef.current;
14904
14916
  const state = useEditorStore.getState();
14905
- const elementsToSync = elements;
14917
+ const storePage = state.canvas.pages.find((p) => p.id === pageId);
14918
+ const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : (storePage == null ? void 0 : storePage.children) ?? [];
14919
+ const elementsToSync = isPreviewMode ? elements : pageTree.length ? flattenChildren(pageTree) : elements;
14906
14920
  elementsRef.current = elementsToSync;
14907
- const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : ((_a2 = state.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
14908
- const selectedIdsFromStore = new Set(((_b2 = state.canvas) == null ? void 0 : _b2.selectedIds) ?? []);
14921
+ const selectedIdsFromStore = new Set(((_a2 = state.canvas) == null ? void 0 : _a2.selectedIds) ?? []);
14909
14922
  isRebuildingRef.current = true;
14910
14923
  const allElementIds = new Set(elementsToSync.map((el) => el.id));
14911
14924
  const sectionGroups = pageTree.filter(
@@ -14933,7 +14946,7 @@ const PageCanvas = forwardRef(
14933
14946
  const activeObjId = activeObj ? getObjectId(activeObj) : null;
14934
14947
  const isTextBeingEdited = activeObjId && editingTextIdRef.current === activeObjId;
14935
14948
  const isMultiSelect = activeObj instanceof fabric.ActiveSelection;
14936
- if (activeObj && isMultiSelect && !(((_c = activeObj._ct) == null ? void 0 : _c.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
14949
+ if (activeObj && isMultiSelect && !(((_b2 = activeObj._ct) == null ? void 0 : _b2.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
14937
14950
  fc.discardActiveObject();
14938
14951
  }
14939
14952
  }
@@ -14970,7 +14983,7 @@ const PageCanvas = forwardRef(
14970
14983
  fc.requestRenderAll();
14971
14984
  }
14972
14985
  } else if (!skipRestoreSelection && restoreTarget && !isActiveTextBeingEdited) {
14973
- const isCropGroup2 = ((_d = restoreTarget._ct) == null ? void 0 : _d.isCropGroup) || restoreTarget.__cropGroup;
14986
+ const isCropGroup2 = ((_c = restoreTarget._ct) == null ? void 0 : _c.isCropGroup) || restoreTarget.__cropGroup;
14974
14987
  const isSectionGroup = activeId && sectionGroupIds.has(activeId);
14975
14988
  if ((isCropGroup2 || !shouldSkipUpdates2) && !isSectionGroup) {
14976
14989
  fc.setActiveObject(restoreTarget);
@@ -15098,7 +15111,7 @@ const PageCanvas = forwardRef(
15098
15111
  const sourceUrlChanged = currentUrlNormalized !== storedUrlNormalized;
15099
15112
  const newFadeKey = edgeFadeKey(element);
15100
15113
  const oldFadeKey = isCropGroup2 ? existingObj.__edgeFadeInputKey || "" : existingObj.__edgeFadeKey || "";
15101
- const innerImg = (_e = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _e._img;
15114
+ const innerImg = (_d = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _d._img;
15102
15115
  const innerOldKey = isCropGroup2 ? oldFadeKey : innerImg ? innerImg.__edgeFadeKey || "" : oldFadeKey;
15103
15116
  const cropFadeRendererMissing = isCropGroup2 && Boolean(newFadeKey) && !existingObj.__edgeFadeRenderConfig;
15104
15117
  const fadeKeyChanged = newFadeKey !== oldFadeKey || newFadeKey !== innerOldKey || cropFadeRendererMissing;
@@ -15106,14 +15119,14 @@ const PageCanvas = forwardRef(
15106
15119
  const needsCropGroupFadeUpdate = isCropGroup2 && fadeKeyChanged;
15107
15120
  const hadUrlBefore = storedImageUrl && String(storedImageUrl).trim() !== "";
15108
15121
  if (!hasUrl && hadUrlBefore) {
15109
- 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 };
15122
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15110
15123
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15111
15124
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15112
15125
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
15113
15126
  const nextHeight = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.height) || 50);
15114
- const storePosImg = pageChildren ? (() => {
15115
- const node = findNodeById(pageChildren, element.id);
15116
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15127
+ const storePosImg = pageTree.length ? (() => {
15128
+ const node = findNodeById(pageTree, element.id);
15129
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15117
15130
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15118
15131
  const elementForPlaceholder = { ...element, width: nextWidth, height: nextHeight };
15119
15132
  const placeholder = isCropGroup2 ? createImagePlaceholderForGroup(elementForPlaceholder) : createImagePlaceholder(elementForPlaceholder);
@@ -15136,8 +15149,8 @@ const PageCanvas = forwardRef(
15136
15149
  fc.requestRenderAll();
15137
15150
  continue;
15138
15151
  }
15139
- const imageFitForReplace = element.imageFit || ((_f = element.style) == null ? void 0 : _f.imageFit) || "cover";
15140
- const clipShapeForReplace = element.clipShape ?? ((_g = element.style) == null ? void 0 : _g.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15152
+ const imageFitForReplace = element.imageFit || ((_e = element.style) == null ? void 0 : _e.imageFit) || "cover";
15153
+ const clipShapeForReplace = element.clipShape ?? ((_f = element.style) == null ? void 0 : _f.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15141
15154
  const needCropGroupForElement = imageFitForReplace !== "fill" || clipShapeForReplace && clipShapeForReplace !== "none";
15142
15155
  const plainImageNeedsCropGroup = hasUrl && !isCropGroup2 && existingObj instanceof fabric.FabricImage && needCropGroupForElement;
15143
15156
  if (hasUrl && (needsReload || isPlaceholder || plainImageNeedsCropGroup || needsCropGroupFadeUpdate)) {
@@ -15174,9 +15187,9 @@ const PageCanvas = forwardRef(
15174
15187
  }
15175
15188
  ct.rx = rxRatio;
15176
15189
  }
15177
- const cropPos = pageChildren ? (() => {
15178
- const node = findNodeById(pageChildren, element.id);
15179
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15190
+ const cropPos = pageTree.length ? (() => {
15191
+ const node = findNodeById(pageTree, element.id);
15192
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15180
15193
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15181
15194
  const cropCenterX = cropPos.left + (ct.frameW ?? 0) / 2;
15182
15195
  const cropCenterY = cropPos.top + (ct.frameH ?? 0) / 2;
@@ -15273,7 +15286,7 @@ const PageCanvas = forwardRef(
15273
15286
  continue;
15274
15287
  }
15275
15288
  } else if (!hasUrl && !isPlaceholder) {
15276
- 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 };
15289
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15277
15290
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15278
15291
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15279
15292
  const elementForPlaceholder = {
@@ -15303,11 +15316,11 @@ const PageCanvas = forwardRef(
15303
15316
  placeholder.__imageSrc = void 0;
15304
15317
  } else if (!isBeingTransformed && !isBeingTextEdited && !shouldSkipUpdates2) {
15305
15318
  if (isPlaceholderGroup) {
15306
- const storePosImg = pageChildren ? (() => {
15307
- const node = findNodeById(pageChildren, element.id);
15308
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15319
+ const storePosImg = pageTree.length ? (() => {
15320
+ const node = findNodeById(pageTree, element.id);
15321
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15309
15322
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15310
- 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 };
15323
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15311
15324
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15312
15325
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15313
15326
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
@@ -15367,9 +15380,9 @@ const PageCanvas = forwardRef(
15367
15380
  const previousVisible = previousVisibilityRef.current.get(element.id) ?? true;
15368
15381
  const currentVisible = element.visible !== false;
15369
15382
  const visibilityChanged = previousVisible !== currentVisible;
15370
- const storePosForImg = pageChildren ? (() => {
15371
- const node = findNodeById(pageChildren, element.id);
15372
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15383
+ const storePosForImg = pageTree.length ? (() => {
15384
+ const node = findNodeById(pageTree, element.id);
15385
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15373
15386
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15374
15387
  const positionChanged = Math.abs((existingObj.left ?? 0) - storePosForImg.left) > 0.1 || Math.abs((existingObj.top ?? 0) - storePosForImg.top) > 0.1;
15375
15388
  if (visibilityChanged && !positionChanged || visibilityUpdateInProgressRef.current) {
@@ -15567,7 +15580,7 @@ const PageCanvas = forwardRef(
15567
15580
  fc.add(placeholder);
15568
15581
  fc.bringObjectToFront(placeholder);
15569
15582
  const activeObj = fc.getActiveObject();
15570
- if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15583
+ if (activeObj && (((_g = activeObj._ct) == null ? void 0 : _g.isCropGroup) || activeObj.__cropGroup)) {
15571
15584
  fc.setActiveObject(activeObj);
15572
15585
  }
15573
15586
  placeholder.dirty = true;
@@ -15607,7 +15620,7 @@ const PageCanvas = forwardRef(
15607
15620
  fc.add(obj);
15608
15621
  fc.bringObjectToFront(obj);
15609
15622
  const activeObj = fc.getActiveObject();
15610
- if (activeObj && (((_i = activeObj._ct) == null ? void 0 : _i.isCropGroup) || activeObj.__cropGroup)) {
15623
+ if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15611
15624
  fc.setActiveObject(activeObj);
15612
15625
  }
15613
15626
  obj.dirty = true;
@@ -15637,10 +15650,18 @@ const PageCanvas = forwardRef(
15637
15650
  });
15638
15651
  allFabricObjects.forEach((obj) => fc.bringObjectToFront(obj));
15639
15652
  }
15653
+ const activeAfterObjectSync = fc.getActiveObject();
15654
+ if (activeAfterObjectSync instanceof fabric.ActiveSelection) {
15655
+ const groupSelectionId = activeAfterObjectSync.__pixldocsGroupSelection;
15656
+ if (groupSelectionId) {
15657
+ applyLogicalGroupSelectionVisualState(activeAfterObjectSync, groupSelectionId);
15658
+ activeAfterObjectSync.setCoords();
15659
+ }
15660
+ }
15640
15661
  isRebuildingRef.current = false;
15641
15662
  fc.requestRenderAll();
15642
15663
  if (activeBeforeSync && fc.getObjects().includes(activeBeforeSync)) {
15643
- const isCropGroup2 = ((_j = activeBeforeSync._ct) == null ? void 0 : _j.isCropGroup) || activeBeforeSync.__cropGroup;
15664
+ const isCropGroup2 = ((_i = activeBeforeSync._ct) == null ? void 0 : _i.isCropGroup) || activeBeforeSync.__cropGroup;
15644
15665
  if (isCropGroup2) {
15645
15666
  fc.setActiveObject(activeBeforeSync);
15646
15667
  fc.requestRenderAll();
@@ -17134,7 +17155,7 @@ const PageCanvas = forwardRef(
17134
17155
  if (imageFit === "fill" && !needCropGroup2) {
17135
17156
  const finalScaleX = baseScaleX * (element.scaleX ?? 1);
17136
17157
  const finalScaleY = baseScaleY * (element.scaleY ?? 1);
17137
- const pageTreeForCreate = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_f = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _f.children) ?? [];
17158
+ 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) ?? [];
17138
17159
  const createPos = pageTreeForCreate.length > 0 ? (() => {
17139
17160
  const node = findNodeById(pageTreeForCreate, element.id);
17140
17161
  return node ? getAbsoluteBounds(node, pageTreeForCreate) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -17184,7 +17205,7 @@ const PageCanvas = forwardRef(
17184
17205
  const needCropGroup = imageFitFinal !== "fill" || clipShapeFinal && clipShapeFinal !== "none";
17185
17206
  let finalObject = img;
17186
17207
  if (needCropGroup) {
17187
- const pageTreeForCropResolve = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_i = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _i.children) ?? [];
17208
+ 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) ?? [];
17188
17209
  const nodeForSize = pageTreeForCropResolve.length ? findNodeById(pageTreeForCropResolve, element.id) : null;
17189
17210
  const w = nodeForSize && isElement(nodeForSize) ? nodeForSize.width : element.width;
17190
17211
  const h = nodeForSize && isElement(nodeForSize) ? nodeForSize.height : element.height;
@@ -17228,7 +17249,7 @@ const PageCanvas = forwardRef(
17228
17249
  }
17229
17250
  const isDynamicField = dynamicFieldIds.includes(element.id);
17230
17251
  const canBeEvented = isEditorMode || isPreviewMode && isDynamicField;
17231
- const pageTreeForCrop = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_n = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _n.children) ?? [];
17252
+ 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) ?? [];
17232
17253
  const createPosForCrop = pageTreeForCrop.length > 0 ? (() => {
17233
17254
  const node = findNodeById(pageTreeForCrop, element.id);
17234
17255
  return node ? getAbsoluteBounds(node, pageTreeForCrop) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -23644,9 +23665,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23644
23665
  }
23645
23666
  return svgString;
23646
23667
  }
23647
- const resolvedPackageVersion = "0.5.268";
23668
+ const resolvedPackageVersion = "0.5.269";
23648
23669
  const PACKAGE_VERSION = resolvedPackageVersion;
23649
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.268";
23670
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.269";
23650
23671
  const roundParityValue = (value) => {
23651
23672
  if (typeof value !== "number") return value;
23652
23673
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24460,7 +24481,7 @@ class PixldocsRenderer {
24460
24481
  await this.waitForCanvasScene(container, cloned, i);
24461
24482
  }
24462
24483
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24463
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CO7vD_-C.js");
24484
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BrPmmgsF.js");
24464
24485
  const prepared = preparePagesForExport(
24465
24486
  cloned.pages,
24466
24487
  canvasWidth,
@@ -26780,7 +26801,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26780
26801
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26781
26802
  sanitizeSvgTreeForPdf(svgToDraw);
26782
26803
  try {
26783
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CO7vD_-C.js");
26804
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BrPmmgsF.js");
26784
26805
  try {
26785
26806
  await logTextMeasurementDiagnostic(svgToDraw);
26786
26807
  } catch {
@@ -27180,4 +27201,4 @@ export {
27180
27201
  buildTeaserBlurFlatKeys as y,
27181
27202
  collectFontDescriptorsFromConfig as z
27182
27203
  };
27183
- //# sourceMappingURL=index-D4jC3E0x.js.map
27204
+ //# sourceMappingURL=index-CrV6Qgb-.js.map