@pixldocs/canvas-renderer 0.5.464 → 0.5.466

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.
@@ -5261,6 +5261,53 @@ function updateCoverLayout(g) {
5261
5261
  g.canvas.requestRenderAll();
5262
5262
  }
5263
5263
  }
5264
+ function shrinkContainGroupToImageBounds(g) {
5265
+ const ct = g.__cropData;
5266
+ if (!ct || ct.fit !== "contain") return;
5267
+ const img = ct._img;
5268
+ if (!img) return;
5269
+ const clip = g.clipPath;
5270
+ if (clip && (isSvgMaskClipPath(clip) || isLuminanceMaskClipPath(clip) || clip.__svgMask || clip.__edgeFadeMask)) return;
5271
+ const iw = img.width || 0;
5272
+ const ih = img.height || 0;
5273
+ const sx = Math.abs(img.scaleX || 1);
5274
+ const sy = Math.abs(img.scaleY || 1);
5275
+ const dispW = iw * sx;
5276
+ const dispH = ih * sy;
5277
+ if (dispW <= 0 || dispH <= 0) return;
5278
+ const frameW = Number(ct.frameW) || g.width || dispW;
5279
+ const frameH = Number(ct.frameH) || g.height || dispH;
5280
+ const alignH = ct.alignH ?? "center";
5281
+ const alignV = ct.alignV ?? "middle";
5282
+ const slackX = frameW - dispW;
5283
+ const slackY = frameH - dispH;
5284
+ const offsetX = alignH === "left" ? -slackX / 2 : alignH === "right" ? slackX / 2 : 0;
5285
+ const offsetY = alignV === "top" ? -slackY / 2 : alignV === "bottom" ? slackY / 2 : 0;
5286
+ const angleRad = fabric__namespace.util.degreesToRadians(g.angle || 0);
5287
+ const cos = Math.cos(angleRad);
5288
+ const sin = Math.sin(angleRad);
5289
+ const worldDx = offsetX * cos - offsetY * sin;
5290
+ const worldDy = offsetX * sin + offsetY * cos;
5291
+ g.set({
5292
+ left: (g.left || 0) + worldDx,
5293
+ top: (g.top || 0) + worldDy,
5294
+ width: dispW,
5295
+ height: dispH
5296
+ });
5297
+ img.set({ left: 0, top: 0 });
5298
+ if (clip) {
5299
+ if (clip instanceof fabric__namespace.Rect) {
5300
+ const rxRatio = Number(ct.rx) || 0;
5301
+ const rxPx = rxRatio > 0.5 ? Math.min(rxRatio, dispW / 2, dispH / 2) : Math.max(0, Math.min(rxRatio * Math.min(dispW, dispH), dispW / 2, dispH / 2));
5302
+ clip.set({ width: dispW, height: dispH, rx: rxPx, ry: rxPx });
5303
+ } else if (clip instanceof fabric__namespace.Ellipse) {
5304
+ clip.set({ rx: dispW / 2, ry: dispH / 2 });
5305
+ }
5306
+ clip.dirty = true;
5307
+ }
5308
+ g.dirty = true;
5309
+ g.setCoords();
5310
+ }
5264
5311
  function getDomEvent(eventData) {
5265
5312
  return (eventData == null ? void 0 : eventData.e) ?? eventData ?? null;
5266
5313
  }
@@ -17485,6 +17532,17 @@ const PageCanvas = react.forwardRef(
17485
17532
  const fadeKeyChanged = newFadeKey !== oldFadeKey || newFadeKey !== innerOldKey || cropFadeRendererMissing;
17486
17533
  const needsReload = sourceUrlChanged || colorMapChanged || fadeKeyChanged && !isCropGroup2;
17487
17534
  const needsCropGroupFadeUpdate = isCropGroup2 && fadeKeyChanged;
17535
+ let cropFrameSizeChanged = false;
17536
+ if (isCropGroup2) {
17537
+ const liveCt = existingObj.__cropData;
17538
+ const liveW = Number(liveCt == null ? void 0 : liveCt.frameW) || 0;
17539
+ const liveH = Number(liveCt == null ? void 0 : liveCt.frameH) || 0;
17540
+ const schemaW = (Number(element.width) || 0) * (Number(element.scaleX) || 1);
17541
+ const schemaH = (Number(element.height) || 0) * (Number(element.scaleY) || 1);
17542
+ if (schemaW > 0 && schemaH > 0 && (Math.abs(schemaW - liveW) > 0.5 || Math.abs(schemaH - liveH) > 0.5)) {
17543
+ cropFrameSizeChanged = true;
17544
+ }
17545
+ }
17488
17546
  const hadUrlBefore = storedImageUrl && String(storedImageUrl).trim() !== "";
17489
17547
  if (!hasUrl && hadUrlBefore) {
17490
17548
  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 };
@@ -17521,7 +17579,7 @@ const PageCanvas = react.forwardRef(
17521
17579
  const clipShapeForReplace = element.clipShape ?? ((_g = element.style) == null ? void 0 : _g.imageFrameShape) ?? (isPreviewMode ? "rectangle" : "none");
17522
17580
  const needCropGroupForElement = imageFitForReplace !== "fill" || clipShapeForReplace && clipShapeForReplace !== "none";
17523
17581
  const plainImageNeedsCropGroup = hasUrl && !isCropGroup2 && existingObj instanceof fabric__namespace.FabricImage && needCropGroupForElement;
17524
- if (hasUrl && (needsReload || isPlaceholder || plainImageNeedsCropGroup || needsCropGroupFadeUpdate)) {
17582
+ if (hasUrl && (needsReload || isPlaceholder || plainImageNeedsCropGroup || needsCropGroupFadeUpdate || cropFrameSizeChanged)) {
17525
17583
  if (needsReload && !isBeingTransformed && (!wasJustModified || sourceUrlChanged)) {
17526
17584
  loadImageAsync2(element, existingObj, fc);
17527
17585
  } else if (plainImageNeedsCropGroup) {
@@ -17641,6 +17699,7 @@ const PageCanvas = react.forwardRef(
17641
17699
  ct.fit = elFit;
17642
17700
  }
17643
17701
  updateCoverLayout(existingObj);
17702
+ shrinkContainGroupToImageBounds(existingObj);
17644
17703
  applyEdgeFadeFrameClipPath(existingObj, element, ct.frameW, ct.frameH, ct.shape || "rect", ct.rx || 0);
17645
17704
  if (allowEditing) {
17646
17705
  installImageResizeControlsWithSnap(existingObj);
@@ -17748,6 +17807,7 @@ const PageCanvas = react.forwardRef(
17748
17807
  ctSync.alignV = element.imageAlignV ?? "middle";
17749
17808
  ctSync.containScale = Math.max(1, Math.min(3, Number(element.containScale ?? 1)));
17750
17809
  updateCoverLayout(existingObj);
17810
+ shrinkContainGroupToImageBounds(existingObj);
17751
17811
  existingObj.dirty = true;
17752
17812
  }
17753
17813
  }
@@ -19714,6 +19774,7 @@ const PageCanvas = react.forwardRef(
19714
19774
  updateCoverLayout(cropGroup);
19715
19775
  }
19716
19776
  applyEdgeFadeFrameClipPath(cropGroup, element, frameW, frameH, shape, rxRatio);
19777
+ shrinkContainGroupToImageBounds(cropGroup);
19717
19778
  setObjectData(cropGroup, element.id);
19718
19779
  cropGroup.__imageElement = cropImg;
19719
19780
  cropGroup.__imageSrc = imageUrl;
@@ -26297,9 +26358,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
26297
26358
  }
26298
26359
  return svgString;
26299
26360
  }
26300
- const resolvedPackageVersion = "0.5.464";
26361
+ const resolvedPackageVersion = "0.5.466";
26301
26362
  const PACKAGE_VERSION = resolvedPackageVersion;
26302
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.464";
26363
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.466";
26303
26364
  const roundParityValue = (value) => {
26304
26365
  if (typeof value !== "number") return value;
26305
26366
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -27113,7 +27174,7 @@ class PixldocsRenderer {
27113
27174
  await this.waitForCanvasScene(container, cloned, i);
27114
27175
  }
27115
27176
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
27116
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-BlaglUx4.cjs"));
27177
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DldoIDUl.cjs"));
27117
27178
  const prepared = preparePagesForExport(
27118
27179
  cloned.pages,
27119
27180
  canvasWidth,
@@ -29433,7 +29494,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29433
29494
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29434
29495
  sanitizeSvgTreeForPdf(svgToDraw);
29435
29496
  try {
29436
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-BlaglUx4.cjs"));
29497
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DldoIDUl.cjs"));
29437
29498
  try {
29438
29499
  await logTextMeasurementDiagnostic(svgToDraw);
29439
29500
  } catch {
@@ -29747,4 +29808,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29747
29808
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29748
29809
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29749
29810
  exports.warmTemplateFromForm = warmTemplateFromForm;
29750
- //# sourceMappingURL=index-BFIEinvR.cjs.map
29811
+ //# sourceMappingURL=index-CJitUO8J.cjs.map