@pixldocs/canvas-renderer 0.5.315 → 0.5.317

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.
@@ -11184,8 +11184,23 @@ function applyWarpAwareSelectionBorders(selection) {
11184
11184
  ));
11185
11185
  const worldAngles = worldMatrices.map((m) => norm(fabric.util.qrDecompose(m).angle ?? 0));
11186
11186
  const first = worldAngles[0] ?? 0;
11187
- const allSame = Math.abs(first) > 0.5 && worldAngles.every((a) => angleDelta(a, first) <= 0.5);
11187
+ const ALL_SAME_TOL_DEG = 2;
11188
+ const allSame = Math.abs(first) > 0.5 && worldAngles.every((a) => angleDelta(a, first) <= ALL_SAME_TOL_DEG);
11189
+ const anyRotated = worldAngles.some((a) => Math.abs(a) > 0.5);
11190
+ let targetAngle = null;
11188
11191
  if (allSame) {
11192
+ targetAngle = first;
11193
+ } else if (anyRotated) {
11194
+ const rad = (d) => d * Math.PI / 180;
11195
+ const deg = (r) => r * 180 / Math.PI;
11196
+ let sx = 0, sy = 0;
11197
+ for (const a of worldAngles) {
11198
+ sx += Math.cos(rad(a));
11199
+ sy += Math.sin(rad(a));
11200
+ }
11201
+ targetAngle = norm(deg(Math.atan2(sy, sx)));
11202
+ }
11203
+ if (targetAngle != null) {
11189
11204
  const restoreKidsFromWorld = () => {
11190
11205
  const invSelection = fabric.util.invertTransform(
11191
11206
  selection.calcTransformMatrix()
@@ -11200,7 +11215,7 @@ function applyWarpAwareSelectionBorders(selection) {
11200
11215
  k.dirty = true;
11201
11216
  });
11202
11217
  };
11203
- selection.set({ angle: first, scaleX: 1, scaleY: 1, skewX: 0, skewY: 0 });
11218
+ selection.set({ angle: targetAngle, scaleX: 1, scaleY: 1, skewX: 0, skewY: 0 });
11204
11219
  restoreKidsFromWorld();
11205
11220
  try {
11206
11221
  (_a2 = selection.triggerLayout) == null ? void 0 : _a2.call(selection);
@@ -11209,12 +11224,8 @@ function applyWarpAwareSelectionBorders(selection) {
11209
11224
  restoreKidsFromWorld();
11210
11225
  selection.setCoords();
11211
11226
  selection.dirty = true;
11212
- selection.__pixldocsAlignedAngle = first;
11213
- } else {
11214
- const anyRotated = worldAngles.some((a) => Math.abs(a) > 0.5);
11215
- if (anyRotated) {
11216
- selection.__pixldocsMixedRotation = true;
11217
- }
11227
+ selection.__pixldocsAlignedAngle = targetAngle;
11228
+ if (!allSame) selection.__pixldocsMixedRotation = true;
11218
11229
  }
11219
11230
  }
11220
11231
  }
@@ -13564,12 +13575,15 @@ const PageCanvas = forwardRef(
13564
13575
  const t = e.target;
13565
13576
  if (t) lastResizeScaleTargetRef.current = t;
13566
13577
  try {
13567
- if (t instanceof fabric.ActiveSelection && t.__pixldocsMixedRotation) {
13568
- const corner2 = (_a2 = e.transform) == null ? void 0 : _a2.corner;
13569
- if (corner2 === "ml" || corner2 === "mr") {
13570
- t.scaleY = t.scaleX;
13571
- } else if (corner2 === "mt" || corner2 === "mb") {
13572
- t.scaleX = t.scaleY;
13578
+ if (t instanceof fabric.ActiveSelection) {
13579
+ const isRotated = !!t.__pixldocsMixedRotation || Math.abs(((t.angle ?? 0) % 360 + 360) % 360) > 0.5;
13580
+ if (isRotated) {
13581
+ const corner2 = (_a2 = e.transform) == null ? void 0 : _a2.corner;
13582
+ if (corner2 === "ml" || corner2 === "mr") {
13583
+ t.scaleY = t.scaleX;
13584
+ } else if (corner2 === "mt" || corner2 === "mb") {
13585
+ t.scaleX = t.scaleY;
13586
+ }
13573
13587
  }
13574
13588
  }
13575
13589
  } catch {
@@ -13743,7 +13757,8 @@ const PageCanvas = forwardRef(
13743
13757
  };
13744
13758
  }
13745
13759
  }
13746
- if (obj instanceof fabric.ActiveSelection && (corner === "ml" || corner === "mr" || corner === "mt" || corner === "mb")) {
13760
+ const _asRotatedForReflow = obj instanceof fabric.ActiveSelection && (!!obj.__pixldocsMixedRotation || Math.abs(((obj.angle ?? 0) % 360 + 360) % 360) > 0.5);
13761
+ if (obj instanceof fabric.ActiveSelection && !_asRotatedForReflow && (corner === "ml" || corner === "mr" || corner === "mt" || corner === "mb")) {
13747
13762
  const isXSide = corner === "ml" || corner === "mr";
13748
13763
  const sAxis = isXSide ? Math.abs(obj.scaleX ?? 1) : Math.abs(obj.scaleY ?? 1);
13749
13764
  if (sAxis > 1e-3) {
@@ -24274,9 +24289,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
24274
24289
  }
24275
24290
  return svgString;
24276
24291
  }
24277
- const resolvedPackageVersion = "0.5.315";
24292
+ const resolvedPackageVersion = "0.5.317";
24278
24293
  const PACKAGE_VERSION = resolvedPackageVersion;
24279
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.315";
24294
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.317";
24280
24295
  const roundParityValue = (value) => {
24281
24296
  if (typeof value !== "number") return value;
24282
24297
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -25090,7 +25105,7 @@ class PixldocsRenderer {
25090
25105
  await this.waitForCanvasScene(container, cloned, i);
25091
25106
  }
25092
25107
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
25093
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BrYF2E8L.js");
25108
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CM-HtbmR.js");
25094
25109
  const prepared = preparePagesForExport(
25095
25110
  cloned.pages,
25096
25111
  canvasWidth,
@@ -27410,7 +27425,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
27410
27425
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
27411
27426
  sanitizeSvgTreeForPdf(svgToDraw);
27412
27427
  try {
27413
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BrYF2E8L.js");
27428
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CM-HtbmR.js");
27414
27429
  try {
27415
27430
  await logTextMeasurementDiagnostic(svgToDraw);
27416
27431
  } catch {
@@ -27810,4 +27825,4 @@ export {
27810
27825
  buildTeaserBlurFlatKeys as y,
27811
27826
  collectFontDescriptorsFromConfig as z
27812
27827
  };
27813
- //# sourceMappingURL=index-BVj3Aj4_.js.map
27828
+ //# sourceMappingURL=index-CXbCTms2.js.map