@pixldocs/canvas-renderer 0.5.387 → 0.5.389

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.
@@ -13530,6 +13530,55 @@ const PageCanvas = react.forwardRef(
13530
13530
  if (!found) return null;
13531
13531
  return { left: minX, top: minY, right: maxX, bottom: maxY };
13532
13532
  };
13533
+ const groupFabricOrientedBBox = (g) => {
13534
+ var _a2;
13535
+ const memberIds = new Set(getAllElementIds(g.children ?? []));
13536
+ if (memberIds.size === 0) return null;
13537
+ const members = [];
13538
+ for (const o of fabricCanvas.getObjects()) {
13539
+ const oid = getObjectId(o);
13540
+ if (oid && memberIds.has(oid)) members.push(o);
13541
+ }
13542
+ if (members.length === 0) return null;
13543
+ const a0 = ((members[0].angle ?? 0) % 360 + 360) % 360;
13544
+ const TOL = 0.5;
13545
+ for (const m of members) {
13546
+ const a = ((m.angle ?? 0) % 360 + 360) % 360;
13547
+ const diff = Math.min(Math.abs(a - a0), 360 - Math.abs(a - a0));
13548
+ if (diff > TOL) return null;
13549
+ }
13550
+ const rad = -a0 * Math.PI / 180;
13551
+ const cos = Math.cos(rad), sin = Math.sin(rad);
13552
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
13553
+ let found = false;
13554
+ for (const m of members) {
13555
+ (_a2 = m.setCoords) == null ? void 0 : _a2.call(m);
13556
+ const aC = m.aCoords;
13557
+ if (!aC) continue;
13558
+ for (const k of ["tl", "tr", "br", "bl"]) {
13559
+ const p = aC[k];
13560
+ if (!p) continue;
13561
+ const xr = p.x * cos - p.y * sin;
13562
+ const yr = p.x * sin + p.y * cos;
13563
+ if (xr < minX) minX = xr;
13564
+ if (yr < minY) minY = yr;
13565
+ if (xr > maxX) maxX = xr;
13566
+ if (yr > maxY) maxY = yr;
13567
+ found = true;
13568
+ }
13569
+ }
13570
+ if (!found) return null;
13571
+ const radBack = a0 * Math.PI / 180;
13572
+ const cb = Math.cos(radBack), sb = Math.sin(radBack);
13573
+ const toCanvas = (x, y) => ({ x: x * cb - y * sb, y: x * sb + y * cb });
13574
+ const corners = [
13575
+ toCanvas(minX, minY),
13576
+ toCanvas(maxX, minY),
13577
+ toCanvas(maxX, maxY),
13578
+ toCanvas(minX, maxY)
13579
+ ];
13580
+ return { corners, angle: a0 };
13581
+ };
13533
13582
  const pickGroupAtPointer = (px, py, children, activeEditingGroupId) => {
13534
13583
  let pick = null;
13535
13584
  for (const node of children) {
@@ -13776,6 +13825,21 @@ const PageCanvas = react.forwardRef(
13776
13825
  const activeEditingGroupId = fabricCanvas.__activeEditingGroupId ?? null;
13777
13826
  const groupPick = pickGroupAtPointer(pointer.x, pointer.y, childrenNow, activeEditingGroupId);
13778
13827
  if (groupPick && !activeIds.has(groupPick.group.id)) {
13828
+ const oriented = groupFabricOrientedBBox(groupPick.group);
13829
+ if (oriented) {
13830
+ const pts = oriented.corners.map((p) => `${p.x},${p.y}`).join(" ");
13831
+ const xs = oriented.corners.map((p) => p.x);
13832
+ const ys = oriented.corners.map((p) => p.y);
13833
+ setHoverBounds({
13834
+ left: Math.min(...xs),
13835
+ top: Math.min(...ys),
13836
+ width: Math.max(...xs) - Math.min(...xs),
13837
+ height: Math.max(...ys) - Math.min(...ys),
13838
+ angle: oriented.angle,
13839
+ points: pts
13840
+ });
13841
+ return;
13842
+ }
13779
13843
  const b = groupFabricUnionBBox(groupPick.group);
13780
13844
  if (b) {
13781
13845
  setHoverBounds({
@@ -13791,14 +13855,31 @@ const PageCanvas = react.forwardRef(
13791
13855
  const isHoveringSelected = !!(tid && activeIds.has(tid));
13792
13856
  if (t && tid && tid !== "__background__" && !isHoveringSelected) {
13793
13857
  t.setCoords();
13794
- const br = t.getBoundingRect();
13795
- setHoverBounds({
13796
- left: br.left,
13797
- top: br.top,
13798
- width: br.width,
13799
- height: br.height,
13800
- angle: 0
13801
- });
13858
+ const ang = ((t.angle ?? 0) % 360 + 360) % 360;
13859
+ const aC = t.aCoords;
13860
+ if (ang > 0.5 && (aC == null ? void 0 : aC.tl) && (aC == null ? void 0 : aC.tr) && (aC == null ? void 0 : aC.br) && (aC == null ? void 0 : aC.bl)) {
13861
+ const corners = [aC.tl, aC.tr, aC.br, aC.bl];
13862
+ const pts = corners.map((p) => `${p.x},${p.y}`).join(" ");
13863
+ const xs = corners.map((p) => p.x);
13864
+ const ys = corners.map((p) => p.y);
13865
+ setHoverBounds({
13866
+ left: Math.min(...xs),
13867
+ top: Math.min(...ys),
13868
+ width: Math.max(...xs) - Math.min(...xs),
13869
+ height: Math.max(...ys) - Math.min(...ys),
13870
+ angle: ang,
13871
+ points: pts
13872
+ });
13873
+ } else {
13874
+ const br = t.getBoundingRect();
13875
+ setHoverBounds({
13876
+ left: br.left,
13877
+ top: br.top,
13878
+ width: br.width,
13879
+ height: br.height,
13880
+ angle: 0
13881
+ });
13882
+ }
13802
13883
  } else {
13803
13884
  setHoverBounds(null);
13804
13885
  }
@@ -14249,23 +14330,26 @@ const PageCanvas = react.forwardRef(
14249
14330
  if (child instanceof fabric__namespace.Group && (child.__cropGroup || ((_f = child._ct) == null ? void 0 : _f.isCropGroup))) {
14250
14331
  const ct = child.__cropData;
14251
14332
  if (!ct) continue;
14333
+ if (child.__asLiveOrigAngle == null) {
14334
+ child.__asLiveOrigAngle = child.angle ?? 0;
14335
+ }
14336
+ const childAngleDegC = child.__asLiveOrigAngle;
14337
+ const asSxC = isXSide ? sAxis : 1;
14338
+ const asSyC = isXSide ? 1 : sAxis;
14339
+ const thetaC = fabric__namespace.util.degreesToRadians(childAngleDegC);
14340
+ const cosTC = Math.cos(thetaC);
14341
+ const sinTC = Math.sin(thetaC);
14342
+ const sLocalC = isXSide ? asSxC * cosTC * cosTC + sinTC * sinTC : asSyC * cosTC * cosTC + sinTC * sinTC;
14252
14343
  if (isXSide) {
14253
14344
  if (child.__asLiveOrigW == null) {
14254
14345
  const baseW = child.width ?? ct.frameW ?? 0;
14255
14346
  child.__asLiveOrigW = baseW * (child.scaleX ?? 1);
14256
14347
  }
14257
14348
  const origW = child.__asLiveOrigW;
14258
- const newW = Math.max(20, origW * sAxis);
14349
+ const newW = Math.max(20, origW * sLocalC);
14259
14350
  if (Math.abs((child.width ?? 0) - newW) > 0.5) {
14260
14351
  ct.frameW = newW;
14261
14352
  child._set("width", newW);
14262
- child._set("scaleX", 1 / sAxis);
14263
- try {
14264
- updateCoverLayout(child);
14265
- } catch {
14266
- }
14267
- child.setCoords();
14268
- child.dirty = true;
14269
14353
  }
14270
14354
  } else {
14271
14355
  if (child.__asLiveOrigH == null) {
@@ -14273,47 +14357,88 @@ const PageCanvas = react.forwardRef(
14273
14357
  child.__asLiveOrigH = baseH * (child.scaleY ?? 1);
14274
14358
  }
14275
14359
  const origH = child.__asLiveOrigH;
14276
- const newH = Math.max(20, origH * sAxis);
14360
+ const newH = Math.max(20, origH * sLocalC);
14277
14361
  if (Math.abs((child.height ?? 0) - newH) > 0.5) {
14278
14362
  ct.frameH = newH;
14279
14363
  child._set("height", newH);
14280
- child._set("scaleY", 1 / sAxis);
14281
- try {
14282
- updateCoverLayout(child);
14283
- } catch {
14284
- }
14285
- child.setCoords();
14286
- child.dirty = true;
14287
14364
  }
14288
14365
  }
14366
+ try {
14367
+ const invC = [1 / asSxC, 0, 0, 1 / asSyC, 0, 0];
14368
+ const RthetaC = fabric__namespace.util.composeMatrix({
14369
+ angle: childAngleDegC,
14370
+ scaleX: 1,
14371
+ scaleY: 1,
14372
+ translateX: 0,
14373
+ translateY: 0
14374
+ });
14375
+ const MC = fabric__namespace.util.multiplyTransformMatrices(invC, RthetaC);
14376
+ const decC = fabric__namespace.util.qrDecompose(MC);
14377
+ child._set("angle", decC.angle);
14378
+ child._set("scaleX", decC.scaleX);
14379
+ child._set("scaleY", decC.scaleY);
14380
+ child._set("skewX", decC.skewX);
14381
+ child._set("skewY", decC.skewY);
14382
+ } catch {
14383
+ }
14384
+ try {
14385
+ updateCoverLayout(child);
14386
+ } catch {
14387
+ }
14388
+ child.setCoords();
14389
+ child.dirty = true;
14289
14390
  continue;
14290
14391
  }
14291
14392
  if (child instanceof fabric__namespace.FabricImage && !child.__cropGroup && !child.smartElementType) {
14393
+ if (child.__asLiveOrigAngle == null) {
14394
+ child.__asLiveOrigAngle = child.angle ?? 0;
14395
+ }
14396
+ const childAngleDegI = child.__asLiveOrigAngle;
14397
+ const asSxI = isXSide ? sAxis : 1;
14398
+ const asSyI = isXSide ? 1 : sAxis;
14399
+ const thetaI = fabric__namespace.util.degreesToRadians(childAngleDegI);
14400
+ const cosTI = Math.cos(thetaI);
14401
+ const sinTI = Math.sin(thetaI);
14402
+ const sLocalI = isXSide ? asSxI * cosTI * cosTI + sinTI * sinTI : asSyI * cosTI * cosTI + sinTI * sinTI;
14292
14403
  if (isXSide) {
14293
14404
  if (child.__asLiveOrigW == null) {
14294
14405
  child.__asLiveOrigW = (child.width ?? 0) * (child.scaleX ?? 1);
14295
14406
  }
14296
14407
  const origW = child.__asLiveOrigW;
14297
- const newW = Math.max(1, origW * sAxis);
14408
+ const newW = Math.max(1, origW * sLocalI);
14298
14409
  if (Math.abs((child.width ?? 0) - newW) > 0.5) {
14299
14410
  child._set("width", newW);
14300
- child._set("scaleX", 1 / sAxis);
14301
- child.setCoords();
14302
- child.dirty = true;
14303
14411
  }
14304
14412
  } else {
14305
14413
  if (child.__asLiveOrigH == null) {
14306
14414
  child.__asLiveOrigH = (child.height ?? 0) * (child.scaleY ?? 1);
14307
14415
  }
14308
14416
  const origH = child.__asLiveOrigH;
14309
- const newH = Math.max(1, origH * sAxis);
14417
+ const newH = Math.max(1, origH * sLocalI);
14310
14418
  if (Math.abs((child.height ?? 0) - newH) > 0.5) {
14311
14419
  child._set("height", newH);
14312
- child._set("scaleY", 1 / sAxis);
14313
- child.setCoords();
14314
- child.dirty = true;
14315
14420
  }
14316
14421
  }
14422
+ try {
14423
+ const invI = [1 / asSxI, 0, 0, 1 / asSyI, 0, 0];
14424
+ const RthetaI = fabric__namespace.util.composeMatrix({
14425
+ angle: childAngleDegI,
14426
+ scaleX: 1,
14427
+ scaleY: 1,
14428
+ translateX: 0,
14429
+ translateY: 0
14430
+ });
14431
+ const MI = fabric__namespace.util.multiplyTransformMatrices(invI, RthetaI);
14432
+ const decI = fabric__namespace.util.qrDecompose(MI);
14433
+ child._set("angle", decI.angle);
14434
+ child._set("scaleX", decI.scaleX);
14435
+ child._set("scaleY", decI.scaleY);
14436
+ child._set("skewX", decI.skewX);
14437
+ child._set("skewY", decI.skewY);
14438
+ } catch {
14439
+ }
14440
+ child.setCoords();
14441
+ child.dirty = true;
14317
14442
  continue;
14318
14443
  }
14319
14444
  if (!(child instanceof fabric__namespace.Textbox)) continue;
@@ -18750,7 +18875,18 @@ const PageCanvas = react.forwardRef(
18750
18875
  className: "absolute inset-0 pointer-events-none",
18751
18876
  style: { width: scaledWidth, height: scaledHeight },
18752
18877
  viewBox: `0 0 ${canvasWidth} ${canvasHeight}`,
18753
- children: /* @__PURE__ */ jsxRuntime.jsx(
18878
+ children: hoverBounds.points ? /* @__PURE__ */ jsxRuntime.jsx(
18879
+ "polygon",
18880
+ {
18881
+ points: hoverBounds.points,
18882
+ fill: "none",
18883
+ stroke: SELECTION_PRIMARY,
18884
+ strokeWidth: 2,
18885
+ vectorEffect: "non-scaling-stroke",
18886
+ strokeDasharray: "0",
18887
+ opacity: 1
18888
+ }
18889
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
18754
18890
  "rect",
18755
18891
  {
18756
18892
  x: hoverBounds.left,
@@ -24900,9 +25036,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
24900
25036
  }
24901
25037
  return svgString;
24902
25038
  }
24903
- const resolvedPackageVersion = "0.5.387";
25039
+ const resolvedPackageVersion = "0.5.389";
24904
25040
  const PACKAGE_VERSION = resolvedPackageVersion;
24905
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.387";
25041
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.389";
24906
25042
  const roundParityValue = (value) => {
24907
25043
  if (typeof value !== "number") return value;
24908
25044
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -25716,7 +25852,7 @@ class PixldocsRenderer {
25716
25852
  await this.waitForCanvasScene(container, cloned, i);
25717
25853
  }
25718
25854
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
25719
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-C_LKrBRO.cjs"));
25855
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-BRGM-p11.cjs"));
25720
25856
  const prepared = preparePagesForExport(
25721
25857
  cloned.pages,
25722
25858
  canvasWidth,
@@ -28036,7 +28172,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
28036
28172
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
28037
28173
  sanitizeSvgTreeForPdf(svgToDraw);
28038
28174
  try {
28039
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-C_LKrBRO.cjs"));
28175
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-BRGM-p11.cjs"));
28040
28176
  try {
28041
28177
  await logTextMeasurementDiagnostic(svgToDraw);
28042
28178
  } catch {
@@ -28433,4 +28569,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
28433
28569
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
28434
28570
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
28435
28571
  exports.warmTemplateFromForm = warmTemplateFromForm;
28436
- //# sourceMappingURL=index-C76ELpPn.cjs.map
28572
+ //# sourceMappingURL=index-Z4UNgyZW.cjs.map