@pixldocs/canvas-renderer 0.5.330 → 0.5.331

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.
@@ -11178,6 +11178,15 @@ const bakeTextboxScaleIntoTypography = (obj, sourceElement) => {
11178
11178
  };
11179
11179
  return updates;
11180
11180
  };
11181
+ const rotatedTopLeftToCenter = (left, top, width, height, angleDeg = 0) => {
11182
+ const angle = angleDeg * Math.PI / 180;
11183
+ const cos = Math.cos(angle);
11184
+ const sin = Math.sin(angle);
11185
+ return {
11186
+ x: left + width / 2 * cos - height / 2 * sin,
11187
+ y: top + width / 2 * sin + height / 2 * cos
11188
+ };
11189
+ };
11181
11190
  function applyWarpAwareSelectionBorders(selection) {
11182
11191
  var _a2;
11183
11192
  if (selection.__pixldocsOrigASHasBorders !== void 0) {
@@ -13540,29 +13549,23 @@ const PageCanvas = react.forwardRef(
13540
13549
  const getObjectFrameBoundsInSelection = (selection, obj, frameWidth, frameHeight) => {
13541
13550
  const w = Math.max(1, frameWidth ?? obj.width ?? 1);
13542
13551
  const h = Math.max(1, frameHeight ?? obj.height ?? 1);
13543
- const originX = obj.originX ?? "left";
13544
- const originY = obj.originY ?? "top";
13545
- const localLeft = originX === "center" ? -w / 2 : originX === "right" ? -w : 0;
13546
- const localTop = originY === "center" ? -h / 2 : originY === "bottom" ? -h : 0;
13547
13552
  const matrix = fabric__namespace.util.multiplyTransformMatrices(
13548
13553
  selection.calcTransformMatrix(),
13549
13554
  obj.calcOwnMatrix()
13550
13555
  );
13551
- const points = [
13552
- new fabric__namespace.Point(localLeft, localTop),
13553
- new fabric__namespace.Point(localLeft + w, localTop),
13554
- new fabric__namespace.Point(localLeft + w, localTop + h),
13555
- new fabric__namespace.Point(localLeft, localTop + h)
13556
- ].map((point) => fabric__namespace.util.transformPoint(point, matrix));
13557
- const xs = points.map((p) => p.x);
13558
- const ys = points.map((p) => p.y);
13559
- const left = Math.min(...xs);
13560
- const top = Math.min(...ys);
13556
+ const decomposed = fabric__namespace.util.qrDecompose(matrix);
13557
+ const scaledW = Math.max(1, w * Math.abs(decomposed.scaleX || 1));
13558
+ const scaledH = Math.max(1, h * Math.abs(decomposed.scaleY || 1));
13559
+ const angleRad = (decomposed.angle ?? 0) * Math.PI / 180;
13560
+ const cos = Math.cos(angleRad);
13561
+ const sin = Math.sin(angleRad);
13562
+ const left = decomposed.translateX - scaledW / 2 * cos + scaledH / 2 * sin;
13563
+ const top = decomposed.translateY - scaledW / 2 * sin - scaledH / 2 * cos;
13561
13564
  return {
13562
13565
  left,
13563
13566
  top,
13564
- width: Math.max(1, Math.max(...xs) - left),
13565
- height: Math.max(1, Math.max(...ys) - top)
13567
+ width: scaledW,
13568
+ height: scaledH
13566
13569
  };
13567
13570
  };
13568
13571
  fabricCanvas.on("object:added", (e) => {
@@ -13834,17 +13837,54 @@ const PageCanvas = react.forwardRef(
13834
13837
  };
13835
13838
  for (const child of obj.getObjects()) {
13836
13839
  if (child instanceof fabric__namespace.Group && (child.__cropGroup || ((_d = child._ct) == null ? void 0 : _d.isCropGroup))) {
13840
+ const ct = child.__cropData;
13841
+ if (ct) {
13842
+ if (child.__asLiveOrigW == null) {
13843
+ child.__asLiveOrigW = ct.frameW ?? child.width ?? 1;
13844
+ }
13845
+ if (child.__asLiveOrigH == null) {
13846
+ child.__asLiveOrigH = ct.frameH ?? child.height ?? 1;
13847
+ }
13848
+ if (isXSide) {
13849
+ const newW = Math.max(1, Number(child.__asLiveOrigW) * sAxis);
13850
+ ct.frameW = newW;
13851
+ child._set("width", newW);
13852
+ } else {
13853
+ const newH = Math.max(1, Number(child.__asLiveOrigH) * sAxis);
13854
+ ct.frameH = newH;
13855
+ child._set("height", newH);
13856
+ }
13857
+ try {
13858
+ updateCoverLayout(child);
13859
+ } catch {
13860
+ }
13861
+ }
13837
13862
  if (isXSide) child._set("scaleX", childCounterScale);
13838
13863
  else child._set("scaleY", childCounterScale);
13839
13864
  child.setCoords();
13840
13865
  child.dirty = true;
13866
+ didReflowTextChild = true;
13841
13867
  continue;
13842
13868
  }
13843
13869
  if (child instanceof fabric__namespace.FabricImage && !child.__cropGroup && !child.smartElementType) {
13870
+ if (isXSide) {
13871
+ if (child.__asLiveOrigW == null) {
13872
+ child.__asLiveOrigW = (child.width ?? 0) * Math.abs(child.scaleX ?? 1);
13873
+ }
13874
+ const newW = Math.max(1, Number(child.__asLiveOrigW) * sAxis);
13875
+ child._set("width", newW);
13876
+ } else {
13877
+ if (child.__asLiveOrigH == null) {
13878
+ child.__asLiveOrigH = (child.height ?? 0) * Math.abs(child.scaleY ?? 1);
13879
+ }
13880
+ const newH = Math.max(1, Number(child.__asLiveOrigH) * sAxis);
13881
+ child._set("height", newH);
13882
+ }
13844
13883
  if (isXSide) child._set("scaleX", childCounterScale);
13845
13884
  else child._set("scaleY", childCounterScale);
13846
13885
  child.setCoords();
13847
13886
  child.dirty = true;
13887
+ didReflowTextChild = true;
13848
13888
  continue;
13849
13889
  }
13850
13890
  if (!(child instanceof fabric__namespace.Textbox)) continue;
@@ -14403,8 +14443,9 @@ const PageCanvas = react.forwardRef(
14403
14443
  const stateCrop = useEditorStore.getState();
14404
14444
  const pageCrop = stateCrop.canvas.pages.find((p) => p.id === pageId);
14405
14445
  const pageChildrenCrop = (pageCrop == null ? void 0 : pageCrop.children) ?? [];
14406
- const absLeft = (active.left ?? 0) - ct.frameW / 2;
14407
- const absTop = (active.top ?? 0) - ct.frameH / 2;
14446
+ const angleRad = (active.angle ?? 0) * Math.PI / 180;
14447
+ const absLeft = (active.left ?? 0) - ct.frameW / 2 * Math.cos(angleRad) + ct.frameH / 2 * Math.sin(angleRad);
14448
+ const absTop = (active.top ?? 0) - ct.frameW / 2 * Math.sin(angleRad) - ct.frameH / 2 * Math.cos(angleRad);
14408
14449
  const storePosCrop = absoluteToStorePosition(absLeft, absTop, objId, pageChildrenCrop);
14409
14450
  updateElement2(objId, {
14410
14451
  width: ct.frameW,
@@ -14765,14 +14806,16 @@ const PageCanvas = react.forwardRef(
14765
14806
  } else {
14766
14807
  const w = ((ct == null ? void 0 : ct.frameW) ?? obj.width ?? 0) * Math.abs(obj.scaleX ?? 1);
14767
14808
  const h = ((ct == null ? void 0 : ct.frameH) ?? obj.height ?? 0) * Math.abs(obj.scaleY ?? 1);
14768
- absoluteLeft = (absoluteLeft ?? 0) - w / 2;
14769
- absoluteTop = (absoluteTop ?? 0) - h / 2;
14809
+ const angleRad = (decomposed.angle ?? obj.angle ?? 0) * Math.PI / 180;
14810
+ absoluteLeft = (decomposed.translateX ?? absoluteLeft ?? 0) - w / 2 * Math.cos(angleRad) + h / 2 * Math.sin(angleRad);
14811
+ absoluteTop = (decomposed.translateY ?? absoluteTop ?? 0) - w / 2 * Math.sin(angleRad) - h / 2 * Math.cos(angleRad);
14770
14812
  }
14771
14813
  } else if (obj instanceof fabric__namespace.FabricImage && (obj.originX === "center" || obj.originY === "center")) {
14772
14814
  const w = (obj.width ?? 0) * (obj.scaleX ?? 1);
14773
14815
  const h = (obj.height ?? 0) * (obj.scaleY ?? 1);
14774
- absoluteLeft = (absoluteLeft ?? 0) - w / 2;
14775
- absoluteTop = (absoluteTop ?? 0) - h / 2;
14816
+ const angleRad = (decomposed.angle ?? obj.angle ?? 0) * Math.PI / 180;
14817
+ absoluteLeft = (decomposed.translateX ?? absoluteLeft ?? 0) - w / 2 * Math.cos(angleRad) + h / 2 * Math.sin(angleRad);
14818
+ absoluteTop = (decomposed.translateY ?? absoluteTop ?? 0) - w / 2 * Math.sin(angleRad) - h / 2 * Math.cos(angleRad);
14776
14819
  }
14777
14820
  const preserveCornerGeometry = (sourceElement == null ? void 0 : sourceElement.type) === "shape" && (sourceElement.shapeType === "circle" || sourceElement.shapeType === "rounded-rect" || sourceElement.shapeType === "triangle");
14778
14821
  let finalWidth = intrinsicWidth;
@@ -14799,12 +14842,14 @@ const PageCanvas = react.forwardRef(
14799
14842
  absoluteLeft = frameBounds.left;
14800
14843
  absoluteTop = frameBounds.top;
14801
14844
  } else {
14802
- absoluteLeft = (decomposed.translateX ?? absoluteLeft) - finalWidth / 2;
14803
- absoluteTop = (decomposed.translateY ?? absoluteTop) - finalHeight / 2;
14845
+ const angleRad = (decomposed.angle ?? obj.angle ?? 0) * Math.PI / 180;
14846
+ absoluteLeft = (decomposed.translateX ?? absoluteLeft) - finalWidth / 2 * Math.cos(angleRad) + finalHeight / 2 * Math.sin(angleRad);
14847
+ absoluteTop = (decomposed.translateY ?? absoluteTop) - finalWidth / 2 * Math.sin(angleRad) - finalHeight / 2 * Math.cos(angleRad);
14804
14848
  }
14849
+ const finalCenter = rotatedTopLeftToCenter(absoluteLeft, absoluteTop, finalWidth, finalHeight, decomposed.angle ?? (obj.angle ?? 0));
14805
14850
  finalAbsoluteMatrix = fabric__namespace.util.composeMatrix({
14806
- translateX: absoluteLeft + finalWidth / 2,
14807
- translateY: absoluteTop + finalHeight / 2,
14851
+ translateX: finalCenter.x,
14852
+ translateY: finalCenter.y,
14808
14853
  angle: decomposed.angle ?? (obj.angle ?? 0),
14809
14854
  scaleX: 1,
14810
14855
  scaleY: 1,
@@ -15190,9 +15235,10 @@ const PageCanvas = react.forwardRef(
15190
15235
  if (!ct) continue;
15191
15236
  ct.frameW = bake.width;
15192
15237
  ct.frameH = bake.height;
15238
+ const bakeCenter = rotatedTopLeftToCenter(bake.left, bake.top, bake.width, bake.height, bake.angle);
15193
15239
  bake.obj.set({
15194
- left: bake.left + bake.width / 2,
15195
- top: bake.top + bake.height / 2,
15240
+ left: bakeCenter.x,
15241
+ top: bakeCenter.y,
15196
15242
  width: bake.width,
15197
15243
  height: bake.height,
15198
15244
  scaleX: 1,
@@ -15789,8 +15835,9 @@ const PageCanvas = react.forwardRef(
15789
15835
  const node = findNodeById(pageChildren, element.id);
15790
15836
  return node ? getAbsoluteBounds(node, pageChildren) : { left: element.left ?? 0, top: element.top ?? 0 };
15791
15837
  })() : { left: element.left ?? 0, top: element.top ?? 0 };
15792
- const cropCenterX = cropPos.left + (ct.frameW ?? 0) / 2;
15793
- const cropCenterY = cropPos.top + (ct.frameH ?? 0) / 2;
15838
+ const cropCenter = rotatedTopLeftToCenter(cropPos.left, cropPos.top, ct.frameW ?? 0, ct.frameH ?? 0, element.angle ?? 0);
15839
+ const cropCenterX = cropCenter.x;
15840
+ const cropCenterY = cropCenter.y;
15794
15841
  if (element.left !== void 0) existingObj.set({ left: cropCenterX });
15795
15842
  if (element.top !== void 0) existingObj.set({ top: cropCenterY });
15796
15843
  if (element.angle !== void 0) existingObj.set({ angle: element.angle });
@@ -16726,8 +16773,9 @@ const PageCanvas = react.forwardRef(
16726
16773
  ct.shape = clipShape === "circle" ? "circle" : clipShape === "rounded" ? "roundRect" : "rect";
16727
16774
  ct.rx = rxRatio;
16728
16775
  obj.__maintainResolution = element.maintainResolution !== false;
16729
- const centerX = fabricPos.left + elementWidth / 2;
16730
- const centerY = fabricPos.top + elementHeight / 2;
16776
+ const center = rotatedTopLeftToCenter(fabricPos.left, fabricPos.top, elementWidth, elementHeight, element.angle ?? 0);
16777
+ const centerX = center.x;
16778
+ const centerY = center.y;
16731
16779
  const cropSetProps = {
16732
16780
  width: elementWidth,
16733
16781
  height: elementHeight,
@@ -16967,7 +17015,8 @@ const PageCanvas = react.forwardRef(
16967
17015
  if (!skipPositionUpdate && (obj instanceof fabric__namespace.FabricImage && obj.originX === "center" || obj instanceof fabric__namespace.Group && obj.__cropGroup)) {
16968
17016
  const vW = rW * effectiveScaleX;
16969
17017
  const vH = rH * effectiveScaleY;
16970
- posIfNotSkipped = { left: fabricPos.left + vW / 2, top: fabricPos.top + vH / 2 };
17018
+ const center = rotatedTopLeftToCenter(fabricPos.left, fabricPos.top, vW, vH, element.angle ?? 0);
17019
+ posIfNotSkipped = { left: center.x, top: center.y };
16971
17020
  }
16972
17021
  if (element.transformMatrix && element.transformMatrix.length === 6) {
16973
17022
  if (isTextbox) {
@@ -24265,9 +24314,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
24265
24314
  }
24266
24315
  return svgString;
24267
24316
  }
24268
- const resolvedPackageVersion = "0.5.330";
24317
+ const resolvedPackageVersion = "0.5.331";
24269
24318
  const PACKAGE_VERSION = resolvedPackageVersion;
24270
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.330";
24319
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.331";
24271
24320
  const roundParityValue = (value) => {
24272
24321
  if (typeof value !== "number") return value;
24273
24322
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -25081,7 +25130,7 @@ class PixldocsRenderer {
25081
25130
  await this.waitForCanvasScene(container, cloned, i);
25082
25131
  }
25083
25132
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
25084
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-CJBVK7bd.cjs"));
25133
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-07IeD7w3.cjs"));
25085
25134
  const prepared = preparePagesForExport(
25086
25135
  cloned.pages,
25087
25136
  canvasWidth,
@@ -27401,7 +27450,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
27401
27450
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
27402
27451
  sanitizeSvgTreeForPdf(svgToDraw);
27403
27452
  try {
27404
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-CJBVK7bd.cjs"));
27453
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-07IeD7w3.cjs"));
27405
27454
  try {
27406
27455
  await logTextMeasurementDiagnostic(svgToDraw);
27407
27456
  } catch {
@@ -27798,4 +27847,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
27798
27847
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
27799
27848
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
27800
27849
  exports.warmTemplateFromForm = warmTemplateFromForm;
27801
- //# sourceMappingURL=index-DyarJoo_.cjs.map
27850
+ //# sourceMappingURL=index-COZR9zOa.cjs.map