@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.
@@ -14319,9 +14319,21 @@ const PageCanvas = react.forwardRef(
14319
14319
  const groupSelectionId = (isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.__pixldocsGroupSelection : void 0) ?? groupToMove.id;
14320
14320
  const targetObjects = isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection ? activeObj.getObjects() : activeObjects;
14321
14321
  if (groupSelectionId && activeObj instanceof fabric__namespace.ActiveSelection) {
14322
- restoreGroupSelectionVisualState(activeObj, groupSelectionId);
14323
- fabricCanvas.setActiveObject(activeObj);
14324
- activeObj.setCoords();
14322
+ try {
14323
+ skipSelectionClearOnDiscardRef.current = true;
14324
+ skipActiveSelectionBakeOnClearRef.current = true;
14325
+ try {
14326
+ fabricCanvas.discardActiveObject();
14327
+ } finally {
14328
+ skipActiveSelectionBakeOnClearRef.current = false;
14329
+ skipSelectionClearOnDiscardRef.current = false;
14330
+ }
14331
+ } catch {
14332
+ }
14333
+ const bakedSelection = targetObjects.length > 1 ? new fabric__namespace.ActiveSelection(targetObjects, { canvas: fabricCanvas }) : activeObj;
14334
+ restoreGroupSelectionVisualState(bakedSelection, groupSelectionId);
14335
+ fabricCanvas.setActiveObject(bakedSelection);
14336
+ bakedSelection.setCoords();
14325
14337
  }
14326
14338
  selectElements([groupSelectionId], false, false);
14327
14339
  fabricCanvas.requestRenderAll();
@@ -14917,13 +14929,14 @@ const PageCanvas = react.forwardRef(
14917
14929
  visibilityUpdateInProgressRef.current = false;
14918
14930
  }
14919
14931
  doSyncRef.current = () => {
14920
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
14932
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
14921
14933
  const shouldSkipUpdates2 = syncLockedRef.current || editLockRef.current;
14922
14934
  const state = useEditorStore.getState();
14923
- const elementsToSync = elements;
14935
+ const storePage = state.canvas.pages.find((p) => p.id === pageId);
14936
+ const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : (storePage == null ? void 0 : storePage.children) ?? [];
14937
+ const elementsToSync = isPreviewMode ? elements : pageTree.length ? flattenChildren(pageTree) : elements;
14924
14938
  elementsRef.current = elementsToSync;
14925
- const pageTree = isPreviewMode && (pageChildren == null ? void 0 : pageChildren.length) ? pageChildren ?? [] : ((_a2 = state.canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _a2.children) ?? [];
14926
- const selectedIdsFromStore = new Set(((_b2 = state.canvas) == null ? void 0 : _b2.selectedIds) ?? []);
14939
+ const selectedIdsFromStore = new Set(((_a2 = state.canvas) == null ? void 0 : _a2.selectedIds) ?? []);
14927
14940
  isRebuildingRef.current = true;
14928
14941
  const allElementIds = new Set(elementsToSync.map((el) => el.id));
14929
14942
  const sectionGroups = pageTree.filter(
@@ -14951,7 +14964,7 @@ const PageCanvas = react.forwardRef(
14951
14964
  const activeObjId = activeObj ? getObjectId(activeObj) : null;
14952
14965
  const isTextBeingEdited = activeObjId && editingTextIdRef.current === activeObjId;
14953
14966
  const isMultiSelect = activeObj instanceof fabric__namespace.ActiveSelection;
14954
- if (activeObj && isMultiSelect && !(((_c = activeObj._ct) == null ? void 0 : _c.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
14967
+ if (activeObj && isMultiSelect && !(((_b2 = activeObj._ct) == null ? void 0 : _b2.isCropGroup) || activeObj.__cropGroup) && !isTextBeingEdited) {
14955
14968
  fc.discardActiveObject();
14956
14969
  }
14957
14970
  }
@@ -14988,7 +15001,7 @@ const PageCanvas = react.forwardRef(
14988
15001
  fc.requestRenderAll();
14989
15002
  }
14990
15003
  } else if (!skipRestoreSelection && restoreTarget && !isActiveTextBeingEdited) {
14991
- const isCropGroup2 = ((_d = restoreTarget._ct) == null ? void 0 : _d.isCropGroup) || restoreTarget.__cropGroup;
15004
+ const isCropGroup2 = ((_c = restoreTarget._ct) == null ? void 0 : _c.isCropGroup) || restoreTarget.__cropGroup;
14992
15005
  const isSectionGroup = activeId && sectionGroupIds.has(activeId);
14993
15006
  if ((isCropGroup2 || !shouldSkipUpdates2) && !isSectionGroup) {
14994
15007
  fc.setActiveObject(restoreTarget);
@@ -15116,7 +15129,7 @@ const PageCanvas = react.forwardRef(
15116
15129
  const sourceUrlChanged = currentUrlNormalized !== storedUrlNormalized;
15117
15130
  const newFadeKey = edgeFadeKey(element);
15118
15131
  const oldFadeKey = isCropGroup2 ? existingObj.__edgeFadeInputKey || "" : existingObj.__edgeFadeKey || "";
15119
- const innerImg = (_e = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _e._img;
15132
+ const innerImg = (_d = existingObj == null ? void 0 : existingObj.__cropData) == null ? void 0 : _d._img;
15120
15133
  const innerOldKey = isCropGroup2 ? oldFadeKey : innerImg ? innerImg.__edgeFadeKey || "" : oldFadeKey;
15121
15134
  const cropFadeRendererMissing = isCropGroup2 && Boolean(newFadeKey) && !existingObj.__edgeFadeRenderConfig;
15122
15135
  const fadeKeyChanged = newFadeKey !== oldFadeKey || newFadeKey !== innerOldKey || cropFadeRendererMissing;
@@ -15124,14 +15137,14 @@ const PageCanvas = react.forwardRef(
15124
15137
  const needsCropGroupFadeUpdate = isCropGroup2 && fadeKeyChanged;
15125
15138
  const hadUrlBefore = storedImageUrl && String(storedImageUrl).trim() !== "";
15126
15139
  if (!hasUrl && hadUrlBefore) {
15127
- 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 };
15140
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15128
15141
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15129
15142
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15130
15143
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
15131
15144
  const nextHeight = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.height) || 50);
15132
- const storePosImg = pageChildren ? (() => {
15133
- const node = findNodeById(pageChildren, element.id);
15134
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15145
+ const storePosImg = pageTree.length ? (() => {
15146
+ const node = findNodeById(pageTree, element.id);
15147
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15135
15148
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15136
15149
  const elementForPlaceholder = { ...element, width: nextWidth, height: nextHeight };
15137
15150
  const placeholder = isCropGroup2 ? createImagePlaceholderForGroup(elementForPlaceholder) : createImagePlaceholder(elementForPlaceholder);
@@ -15154,8 +15167,8 @@ const PageCanvas = react.forwardRef(
15154
15167
  fc.requestRenderAll();
15155
15168
  continue;
15156
15169
  }
15157
- const imageFitForReplace = element.imageFit || ((_f = element.style) == null ? void 0 : _f.imageFit) || "cover";
15158
- const clipShapeForReplace = element.clipShape ?? ((_g = element.style) == null ? void 0 : _g.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15170
+ const imageFitForReplace = element.imageFit || ((_e = element.style) == null ? void 0 : _e.imageFit) || "cover";
15171
+ const clipShapeForReplace = element.clipShape ?? ((_f = element.style) == null ? void 0 : _f.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
15159
15172
  const needCropGroupForElement = imageFitForReplace !== "fill" || clipShapeForReplace && clipShapeForReplace !== "none";
15160
15173
  const plainImageNeedsCropGroup = hasUrl && !isCropGroup2 && existingObj instanceof fabric__namespace.FabricImage && needCropGroupForElement;
15161
15174
  if (hasUrl && (needsReload || isPlaceholder || plainImageNeedsCropGroup || needsCropGroupFadeUpdate)) {
@@ -15192,9 +15205,9 @@ const PageCanvas = react.forwardRef(
15192
15205
  }
15193
15206
  ct.rx = rxRatio;
15194
15207
  }
15195
- const cropPos = pageChildren ? (() => {
15196
- const node = findNodeById(pageChildren, element.id);
15197
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15208
+ const cropPos = pageTree.length ? (() => {
15209
+ const node = findNodeById(pageTree, element.id);
15210
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15198
15211
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15199
15212
  const cropCenterX = cropPos.left + (ct.frameW ?? 0) / 2;
15200
15213
  const cropCenterY = cropPos.top + (ct.frameH ?? 0) / 2;
@@ -15291,7 +15304,7 @@ const PageCanvas = react.forwardRef(
15291
15304
  continue;
15292
15305
  }
15293
15306
  } else if (!hasUrl && !isPlaceholder) {
15294
- 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 };
15307
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15295
15308
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15296
15309
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15297
15310
  const elementForPlaceholder = {
@@ -15321,11 +15334,11 @@ const PageCanvas = react.forwardRef(
15321
15334
  placeholder.__imageSrc = void 0;
15322
15335
  } else if (!isBeingTransformed && !isBeingTextEdited && !shouldSkipUpdates2) {
15323
15336
  if (isPlaceholderGroup) {
15324
- const storePosImg = pageChildren ? (() => {
15325
- const node = findNodeById(pageChildren, element.id);
15326
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15337
+ const storePosImg = pageTree.length ? (() => {
15338
+ const node = findNodeById(pageTree, element.id);
15339
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15327
15340
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15328
- 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 };
15341
+ const resolvedSizeImg = pageTree.length ? getNodeBounds(element, pageTree) : { width: typeof element.width === "number" ? element.width : 200, height: typeof element.height === "number" ? element.height : 50 };
15329
15342
  const hasExplicitSize = typeof element.width === "number" && Number.isFinite(element.width) && element.width > 0 && typeof element.height === "number" && Number.isFinite(element.height) && element.height > 0;
15330
15343
  const minVisiblePlaceholder = hasExplicitSize ? 1 : 20;
15331
15344
  const nextWidth = Math.max(minVisiblePlaceholder, Number(resolvedSizeImg.width) || 200);
@@ -15385,9 +15398,9 @@ const PageCanvas = react.forwardRef(
15385
15398
  const previousVisible = previousVisibilityRef.current.get(element.id) ?? true;
15386
15399
  const currentVisible = element.visible !== false;
15387
15400
  const visibilityChanged = previousVisible !== currentVisible;
15388
- const storePosForImg = pageChildren ? (() => {
15389
- const node = findNodeById(pageChildren, element.id);
15390
- return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15401
+ const storePosForImg = pageTree.length ? (() => {
15402
+ const node = findNodeById(pageTree, element.id);
15403
+ return node ? getAbsoluteBounds(node, pageTree) : { left: element.left ?? 0, top: element.top ?? 0 };
15391
15404
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15392
15405
  const positionChanged = Math.abs((existingObj.left ?? 0) - storePosForImg.left) > 0.1 || Math.abs((existingObj.top ?? 0) - storePosForImg.top) > 0.1;
15393
15406
  if (visibilityChanged && !positionChanged || visibilityUpdateInProgressRef.current) {
@@ -15585,7 +15598,7 @@ const PageCanvas = react.forwardRef(
15585
15598
  fc.add(placeholder);
15586
15599
  fc.bringObjectToFront(placeholder);
15587
15600
  const activeObj = fc.getActiveObject();
15588
- if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15601
+ if (activeObj && (((_g = activeObj._ct) == null ? void 0 : _g.isCropGroup) || activeObj.__cropGroup)) {
15589
15602
  fc.setActiveObject(activeObj);
15590
15603
  }
15591
15604
  placeholder.dirty = true;
@@ -15625,7 +15638,7 @@ const PageCanvas = react.forwardRef(
15625
15638
  fc.add(obj);
15626
15639
  fc.bringObjectToFront(obj);
15627
15640
  const activeObj = fc.getActiveObject();
15628
- if (activeObj && (((_i = activeObj._ct) == null ? void 0 : _i.isCropGroup) || activeObj.__cropGroup)) {
15641
+ if (activeObj && (((_h = activeObj._ct) == null ? void 0 : _h.isCropGroup) || activeObj.__cropGroup)) {
15629
15642
  fc.setActiveObject(activeObj);
15630
15643
  }
15631
15644
  obj.dirty = true;
@@ -15655,10 +15668,18 @@ const PageCanvas = react.forwardRef(
15655
15668
  });
15656
15669
  allFabricObjects.forEach((obj) => fc.bringObjectToFront(obj));
15657
15670
  }
15671
+ const activeAfterObjectSync = fc.getActiveObject();
15672
+ if (activeAfterObjectSync instanceof fabric__namespace.ActiveSelection) {
15673
+ const groupSelectionId = activeAfterObjectSync.__pixldocsGroupSelection;
15674
+ if (groupSelectionId) {
15675
+ applyLogicalGroupSelectionVisualState(activeAfterObjectSync, groupSelectionId);
15676
+ activeAfterObjectSync.setCoords();
15677
+ }
15678
+ }
15658
15679
  isRebuildingRef.current = false;
15659
15680
  fc.requestRenderAll();
15660
15681
  if (activeBeforeSync && fc.getObjects().includes(activeBeforeSync)) {
15661
- const isCropGroup2 = ((_j = activeBeforeSync._ct) == null ? void 0 : _j.isCropGroup) || activeBeforeSync.__cropGroup;
15682
+ const isCropGroup2 = ((_i = activeBeforeSync._ct) == null ? void 0 : _i.isCropGroup) || activeBeforeSync.__cropGroup;
15662
15683
  if (isCropGroup2) {
15663
15684
  fc.setActiveObject(activeBeforeSync);
15664
15685
  fc.requestRenderAll();
@@ -17152,7 +17173,7 @@ const PageCanvas = react.forwardRef(
17152
17173
  if (imageFit === "fill" && !needCropGroup2) {
17153
17174
  const finalScaleX = baseScaleX * (element.scaleX ?? 1);
17154
17175
  const finalScaleY = baseScaleY * (element.scaleY ?? 1);
17155
- const pageTreeForCreate = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_f = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _f.children) ?? [];
17176
+ 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) ?? [];
17156
17177
  const createPos = pageTreeForCreate.length > 0 ? (() => {
17157
17178
  const node = findNodeById(pageTreeForCreate, element.id);
17158
17179
  return node ? getAbsoluteBounds(node, pageTreeForCreate) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -17202,7 +17223,7 @@ const PageCanvas = react.forwardRef(
17202
17223
  const needCropGroup = imageFitFinal !== "fill" || clipShapeFinal && clipShapeFinal !== "none";
17203
17224
  let finalObject = img;
17204
17225
  if (needCropGroup) {
17205
- const pageTreeForCropResolve = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_i = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _i.children) ?? [];
17226
+ 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) ?? [];
17206
17227
  const nodeForSize = pageTreeForCropResolve.length ? findNodeById(pageTreeForCropResolve, element.id) : null;
17207
17228
  const w = nodeForSize && isElement(nodeForSize) ? nodeForSize.width : element.width;
17208
17229
  const h = nodeForSize && isElement(nodeForSize) ? nodeForSize.height : element.height;
@@ -17246,7 +17267,7 @@ const PageCanvas = react.forwardRef(
17246
17267
  }
17247
17268
  const isDynamicField = dynamicFieldIds.includes(element.id);
17248
17269
  const canBeEvented = isEditorMode || isPreviewMode && isDynamicField;
17249
- const pageTreeForCrop = ((pageChildren == null ? void 0 : pageChildren.length) ? pageChildren : (_n = useEditorStore.getState().canvas.pages.find((p) => p.id === pageId)) == null ? void 0 : _n.children) ?? [];
17270
+ 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) ?? [];
17250
17271
  const createPosForCrop = pageTreeForCrop.length > 0 ? (() => {
17251
17272
  const node = findNodeById(pageTreeForCrop, element.id);
17252
17273
  return node ? getAbsoluteBounds(node, pageTreeForCrop) : { left: element.left ?? 0, top: element.top ?? 0 };
@@ -23662,9 +23683,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
23662
23683
  }
23663
23684
  return svgString;
23664
23685
  }
23665
- const resolvedPackageVersion = "0.5.268";
23686
+ const resolvedPackageVersion = "0.5.269";
23666
23687
  const PACKAGE_VERSION = resolvedPackageVersion;
23667
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.268";
23688
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.269";
23668
23689
  const roundParityValue = (value) => {
23669
23690
  if (typeof value !== "number") return value;
23670
23691
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -24478,7 +24499,7 @@ class PixldocsRenderer {
24478
24499
  await this.waitForCanvasScene(container, cloned, i);
24479
24500
  }
24480
24501
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
24481
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-D2g8-LcJ.cjs"));
24502
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-xlycX5wM.cjs"));
24482
24503
  const prepared = preparePagesForExport(
24483
24504
  cloned.pages,
24484
24505
  canvasWidth,
@@ -26798,7 +26819,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
26798
26819
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
26799
26820
  sanitizeSvgTreeForPdf(svgToDraw);
26800
26821
  try {
26801
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-D2g8-LcJ.cjs"));
26822
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-xlycX5wM.cjs"));
26802
26823
  try {
26803
26824
  await logTextMeasurementDiagnostic(svgToDraw);
26804
26825
  } catch {
@@ -27195,4 +27216,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
27195
27216
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
27196
27217
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
27197
27218
  exports.warmTemplateFromForm = warmTemplateFromForm;
27198
- //# sourceMappingURL=index-DNGRsx4X.cjs.map
27219
+ //# sourceMappingURL=index-V3Oyi5GA.cjs.map