@pixldocs/canvas-renderer 0.5.407 → 0.5.409

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.
@@ -4965,7 +4965,7 @@ function getLocalDeltaStable(target, eventData) {
4965
4965
  target.__lastPointerForCrop = p;
4966
4966
  const dx = p.x - last.x;
4967
4967
  const dy = p.y - last.y;
4968
- const angle = fabric__namespace.util.degreesToRadians(target.angle || 0);
4968
+ const angle = fabric__namespace.util.degreesToRadians(getWorldAngleDeg(target));
4969
4969
  const cos = Math.cos(-angle);
4970
4970
  const sin = Math.sin(-angle);
4971
4971
  return {
@@ -4991,8 +4991,40 @@ function localDeltaToWorld(dx, dy, angleDeg) {
4991
4991
  y: dx * sin + dy * cos
4992
4992
  };
4993
4993
  }
4994
- function getOppositeAnchor(aCoords, corner) {
4995
- return corner === "br" ? aCoords.tl : corner === "bl" ? aCoords.tr : corner === "tr" ? aCoords.bl : aCoords.br;
4994
+ function getWorldAngleDeg(obj) {
4995
+ var _a2;
4996
+ try {
4997
+ if (typeof obj.getTotalAngle === "function") return obj.getTotalAngle() || 0;
4998
+ const matrix = (_a2 = obj.calcTransformMatrix) == null ? void 0 : _a2.call(obj);
4999
+ return matrix ? fabric__namespace.util.qrDecompose(matrix).angle || 0 : obj.angle || 0;
5000
+ } catch {
5001
+ return obj.angle || 0;
5002
+ }
5003
+ }
5004
+ function getWorldCenter(obj) {
5005
+ var _a2;
5006
+ try {
5007
+ const matrix = (_a2 = obj.calcTransformMatrix) == null ? void 0 : _a2.call(obj);
5008
+ if (matrix) {
5009
+ const decomposed = fabric__namespace.util.qrDecompose(matrix);
5010
+ return { x: decomposed.translateX || 0, y: decomposed.translateY || 0 };
5011
+ }
5012
+ } catch {
5013
+ }
5014
+ return { x: obj.left || 0, y: obj.top || 0 };
5015
+ }
5016
+ function setCenterFromWorld(obj, worldX, worldY) {
5017
+ const parent = obj.group;
5018
+ if (parent && typeof parent.calcTransformMatrix === "function") {
5019
+ try {
5020
+ const invParent = fabric__namespace.util.invertTransform(parent.calcTransformMatrix());
5021
+ const parentPoint = fabric__namespace.util.transformPoint({ x: worldX, y: worldY }, invParent);
5022
+ obj.set({ left: parentPoint.x, top: parentPoint.y, originX: "center", originY: "center" });
5023
+ return;
5024
+ } catch {
5025
+ }
5026
+ }
5027
+ obj.set({ left: worldX, top: worldY, originX: "center", originY: "center" });
4996
5028
  }
4997
5029
  function getCornerDefaultSigns(corner) {
4998
5030
  switch (corner) {
@@ -5036,44 +5068,50 @@ function resizeFrameFromCornerUniform(eventData, transform, _x, _y) {
5036
5068
  if (!canvas) return false;
5037
5069
  const e = getDomEvent(eventData);
5038
5070
  if (!e) return false;
5039
- const pointer = canvas.getPointer(e);
5040
- g.setCoords();
5041
- const a = g.aCoords;
5042
- if (!a) return false;
5043
5071
  const corner = transform.corner;
5044
- const anchor = getOppositeAnchor(a, corner);
5045
5072
  const defaultSigns = getCornerDefaultSigns(corner);
5046
5073
  const MIN_SIZE = 20;
5047
- const baseW = Math.max(MIN_SIZE, ct.frameW || g.width || 1);
5048
- const baseH = Math.max(MIN_SIZE, ct.frameH || g.height || 1);
5049
- const angle = g.angle || 0;
5050
- const deltaWorldX = pointer.x - anchor.x;
5051
- const deltaWorldY = pointer.y - anchor.y;
5052
- const localDelta = worldDeltaToLocal(deltaWorldX, deltaWorldY, angle);
5053
- const signX = Math.abs(localDelta.x) < 1e-3 ? defaultSigns.x : localDelta.x >= 0 ? 1 : -1;
5054
- const signY = Math.abs(localDelta.y) < 1e-3 ? defaultSigns.y : localDelta.y >= 0 ? 1 : -1;
5074
+ const pointer = canvas.getPointer(e);
5075
+ const angle = getWorldAngleDeg(g);
5076
+ const snapshot = g.__cornerResizeStart && g.__cornerResizeStart.corner === corner && g.__cornerResizeStart.transform === transform ? g.__cornerResizeStart : (() => {
5077
+ const center = getWorldCenter(g);
5078
+ const baseW = Math.max(MIN_SIZE, ct.frameW || g.width || 1);
5079
+ const baseH = Math.max(MIN_SIZE, ct.frameH || g.height || 1);
5080
+ const anchorLocal = { x: -defaultSigns.x * baseW / 2, y: -defaultSigns.y * baseH / 2 };
5081
+ const anchorWorld = localDeltaToWorld(anchorLocal.x, anchorLocal.y, angle);
5082
+ const snap = {
5083
+ corner,
5084
+ transform,
5085
+ angle,
5086
+ baseW,
5087
+ baseH,
5088
+ anchorX: center.x + anchorWorld.x,
5089
+ anchorY: center.y + anchorWorld.y,
5090
+ signX: defaultSigns.x,
5091
+ signY: defaultSigns.y
5092
+ };
5093
+ g.__cornerResizeStart = snap;
5094
+ return snap;
5095
+ })();
5096
+ const localDelta = worldDeltaToLocal(pointer.x - snapshot.anchorX, pointer.y - snapshot.anchorY, snapshot.angle);
5097
+ const signX = snapshot.signX;
5098
+ const signY = snapshot.signY;
5055
5099
  const rawW = Math.max(MIN_SIZE, Math.abs(localDelta.x));
5056
5100
  const rawH = Math.max(MIN_SIZE, Math.abs(localDelta.y));
5057
- const scaleFromW = rawW / baseW;
5058
- const scaleFromH = rawH / baseH;
5101
+ const scaleFromW = rawW / snapshot.baseW;
5102
+ const scaleFromH = rawH / snapshot.baseH;
5059
5103
  const s = Math.min(scaleFromW, scaleFromH);
5060
- const newW = Math.max(MIN_SIZE, baseW * s);
5061
- const newH = Math.max(MIN_SIZE, baseH * s);
5104
+ const newW = Math.max(MIN_SIZE, snapshot.baseW * s);
5105
+ const newH = Math.max(MIN_SIZE, snapshot.baseH * s);
5062
5106
  ct.frameW = newW;
5063
5107
  ct.frameH = newH;
5064
5108
  const centerLocal = {
5065
5109
  x: signX * (newW / 2),
5066
5110
  y: signY * (newH / 2)
5067
5111
  };
5068
- const centerWorld = localDeltaToWorld(centerLocal.x, centerLocal.y, angle);
5069
- g.set({
5070
- left: anchor.x + centerWorld.x,
5071
- top: anchor.y + centerWorld.y,
5072
- originX: "center",
5073
- originY: "center",
5074
- width: newW,
5075
- height: newH
5076
- });
5112
+ const centerWorld = localDeltaToWorld(centerLocal.x, centerLocal.y, snapshot.angle);
5113
+ setCenterFromWorld(g, snapshot.anchorX + centerWorld.x, snapshot.anchorY + centerWorld.y);
5114
+ g.set({ width: newW, height: newH });
5077
5115
  updateCoverLayout(g);
5078
5116
  canvas.requestRenderAll();
5079
5117
  return true;
@@ -5083,8 +5121,9 @@ function resizeFrameFromSide(g, side, localDx, localDy) {
5083
5121
  if (!ct) return;
5084
5122
  const minSize = 30;
5085
5123
  const moveCenterAlongLocalAxis = (obj, localX, localY) => {
5086
- const worldDelta = localDeltaToWorld(localX, localY, obj.angle || 0);
5087
- obj.set({ left: (obj.left || 0) + worldDelta.x, top: (obj.top || 0) + worldDelta.y });
5124
+ const center = getWorldCenter(obj);
5125
+ const worldDelta = localDeltaToWorld(localX, localY, getWorldAngleDeg(obj));
5126
+ setCenterFromWorld(obj, center.x + worldDelta.x, center.y + worldDelta.y);
5088
5127
  };
5089
5128
  if (side === "mr") {
5090
5129
  ct.frameW = Math.max(minSize, ct.frameW + localDx);
@@ -5119,6 +5158,7 @@ function installCanvaMaskControls(g) {
5119
5158
  };
5120
5159
  g.set(controlStyle);
5121
5160
  const notifyResizeSnap = (target, corner) => {
5161
+ if (target.group instanceof fabric__namespace.ActiveSelection) return;
5122
5162
  const handler = target.__resizeSnapHandler;
5123
5163
  if (typeof handler === "function") handler(target, corner);
5124
5164
  };
@@ -13269,19 +13309,13 @@ const PageCanvas = react.forwardRef(
13269
13309
  const liveDeltaY = Math.abs(rawScaleY / originalScaleY);
13270
13310
  const hasResidualOriginal = Math.abs(Math.abs(originalScaleX) - 1) > 1e-4 || Math.abs(Math.abs(originalScaleY) - 1) > 1e-4;
13271
13311
  const hasNoLiveDragDelta = Math.abs(liveDeltaX - 1) < 5e-4 && Math.abs(liveDeltaY - 1) < 5e-4;
13272
- const canBakeResidual = (ct == null ? void 0 : ct.target) === active ? hasResidualOriginal && hasNoLiveDragDelta : Math.abs(Math.abs(rawScaleX) - 1) > 1e-4 || Math.abs(Math.abs(rawScaleY) - 1) > 1e-4;
13273
- if (canBakeResidual) {
13274
- const asScaleX = Math.abs((ct == null ? void 0 : ct.target) === active ? originalScaleX : rawScaleX);
13275
- const asScaleY = Math.abs((ct == null ? void 0 : ct.target) === active ? originalScaleY : rawScaleY);
13276
- const newW = Math.max(1, (active.width ?? 0) * asScaleX);
13277
- const newH = Math.max(1, (active.height ?? 0) * asScaleY);
13278
- active.set({ width: newW, height: newH, scaleX: 1, scaleY: 1 });
13312
+ const canNormalize = (ct == null ? void 0 : ct.target) === active ? hasResidualOriginal && hasNoLiveDragDelta : Math.abs(Math.abs(rawScaleX) - 1) > 1e-4 || Math.abs(Math.abs(rawScaleY) - 1) > 1e-4;
13313
+ if (canNormalize) {
13314
+ active.set({ scaleX: 1, scaleY: 1 });
13279
13315
  active.setCoords();
13280
13316
  if (ct && ct.target === active && ct.original) {
13281
13317
  ct.original.scaleX = 1;
13282
13318
  ct.original.scaleY = 1;
13283
- ct.original.width = newW;
13284
- ct.original.height = newH;
13285
13319
  }
13286
13320
  }
13287
13321
  } catch {
@@ -14127,6 +14161,9 @@ const PageCanvas = react.forwardRef(
14127
14161
  if (activeObj.__lastPointerForCrop) {
14128
14162
  delete activeObj.__lastPointerForCrop;
14129
14163
  }
14164
+ if (activeObj.__cornerResizeStart) {
14165
+ delete activeObj.__cornerResizeStart;
14166
+ }
14130
14167
  }
14131
14168
  if (!didTransformRef.current) {
14132
14169
  editLockRef.current = false;
@@ -25185,9 +25222,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25185
25222
  }
25186
25223
  return svgString;
25187
25224
  }
25188
- const resolvedPackageVersion = "0.5.407";
25225
+ const resolvedPackageVersion = "0.5.409";
25189
25226
  const PACKAGE_VERSION = resolvedPackageVersion;
25190
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.407";
25227
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.409";
25191
25228
  const roundParityValue = (value) => {
25192
25229
  if (typeof value !== "number") return value;
25193
25230
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26001,7 +26038,7 @@ class PixldocsRenderer {
26001
26038
  await this.waitForCanvasScene(container, cloned, i);
26002
26039
  }
26003
26040
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26004
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DRPD9NOQ.cjs"));
26041
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-CI2YBgI3.cjs"));
26005
26042
  const prepared = preparePagesForExport(
26006
26043
  cloned.pages,
26007
26044
  canvasWidth,
@@ -28321,7 +28358,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
28321
28358
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
28322
28359
  sanitizeSvgTreeForPdf(svgToDraw);
28323
28360
  try {
28324
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DRPD9NOQ.cjs"));
28361
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-CI2YBgI3.cjs"));
28325
28362
  try {
28326
28363
  await logTextMeasurementDiagnostic(svgToDraw);
28327
28364
  } catch {
@@ -28718,4 +28755,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
28718
28755
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
28719
28756
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
28720
28757
  exports.warmTemplateFromForm = warmTemplateFromForm;
28721
- //# sourceMappingURL=index-DYykToy0.cjs.map
28758
+ //# sourceMappingURL=index-DaL8UMXJ.cjs.map