@pixldocs/canvas-renderer 0.5.452 → 0.5.454

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.
@@ -11711,6 +11711,28 @@ const angleDistanceDeg = (a, b) => {
11711
11711
  const delta = Math.abs(((a - b) % 360 + 540) % 360 - 180);
11712
11712
  return Number.isFinite(delta) ? delta : Number.POSITIVE_INFINITY;
11713
11713
  };
11714
+ const normalizeSignedAngleDeg = (angle) => {
11715
+ if (!Number.isFinite(angle)) return 0;
11716
+ const normalized = (angle % 360 + 540) % 360 - 180;
11717
+ return Math.abs(normalized) < 1e-9 ? 0 : normalized;
11718
+ };
11719
+ const resolveActiveSelectionLocalAngle = (obj, sourceElement, activeSelection) => {
11720
+ var _a2;
11721
+ const objectAngle = Number.isFinite(obj.angle) ? obj.angle ?? 0 : 0;
11722
+ const isImageLike = obj instanceof fabric__namespace.FabricImage || obj instanceof fabric__namespace.Group && (obj.__cropGroup || ((_a2 = obj._ct) == null ? void 0 : _a2.isCropGroup));
11723
+ const hasPersistedFlip = !!((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY) || obj.flipX || obj.flipY);
11724
+ if (!isImageLike || !hasPersistedFlip || !Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle)) {
11725
+ return normalizeSignedAngleDeg(objectAngle);
11726
+ }
11727
+ return normalizeSignedAngleDeg((sourceElement.angle ?? 0) - ((activeSelection == null ? void 0 : activeSelection.angle) ?? 0));
11728
+ };
11729
+ const resolveStableFlippedAngle = (fabricAngle, sourceAngle, hasFlip, isRotationGesture = false) => {
11730
+ const current = Number.isFinite(fabricAngle) ? fabricAngle : sourceAngle ?? 0;
11731
+ if (!hasFlip || isRotationGesture || !Number.isFinite(sourceAngle)) return current;
11732
+ const src = sourceAngle;
11733
+ const isFabricFlipEncoding = angleDistanceDeg(current, src + 180) < 2 && angleDistanceDeg(current, src) > 90;
11734
+ return isFabricFlipEncoding ? src : current;
11735
+ };
11714
11736
  const stripPersistedFlipForStableAngle = (matrix, persistedFlipX, persistedFlipY, expectedCleanAngle) => {
11715
11737
  if (!persistedFlipX && !persistedFlipY) return matrix;
11716
11738
  const toggled = toggleLogicalFlipInMatrix(matrix, persistedFlipX, persistedFlipY);
@@ -14662,7 +14684,7 @@ const PageCanvas = react.forwardRef(
14662
14684
  fabricCanvas.on("selection:cleared", () => {
14663
14685
  });
14664
14686
  fabricCanvas.on("object:scaling", (e) => {
14665
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
14687
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
14666
14688
  if (!isActiveRef.current) return;
14667
14689
  const t = e.target;
14668
14690
  if (t) lastResizeScaleTargetRef.current = t;
@@ -14959,15 +14981,18 @@ const PageCanvas = react.forwardRef(
14959
14981
  const sourceChildForAngle = childIdForAngle ? elementsRef.current.find((el) => el.id === childIdForAngle) : null;
14960
14982
  const persistedChildFlipX = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipX) ?? child.flipX ?? false;
14961
14983
  const persistedChildFlipY = (sourceChildForAngle == null ? void 0 : sourceChildForAngle.flipY) ?? child.flipY ?? false;
14962
- const isFlippedImageLikeChild = (child instanceof fabric__namespace.FabricImage || child instanceof fabric__namespace.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) && !!(persistedChildFlipX || persistedChildFlipY) && Number.isFinite(sourceChildForAngle == null ? void 0 : sourceChildForAngle.angle);
14963
- if (child instanceof fabric__namespace.FabricImage || child instanceof fabric__namespace.Group && (child.__cropGroup || ((_n = child._ct) == null ? void 0 : _n.isCropGroup))) {
14984
+ if (child instanceof fabric__namespace.FabricImage || child instanceof fabric__namespace.Group && (child.__cropGroup || ((_m = child._ct) == null ? void 0 : _m.isCropGroup))) {
14964
14985
  child.set({ flipX: persistedChildFlipX, flipY: persistedChildFlipY });
14965
14986
  child.__asLivePersistedFlipX = persistedChildFlipX;
14966
14987
  child.__asLivePersistedFlipY = persistedChildFlipY;
14967
14988
  }
14968
- child.__asLiveOrigAngle = isFlippedImageLikeChild ? sourceChildForAngle.angle ?? 0 : Number.isFinite(child.angle) ? child.angle ?? 0 : 0;
14989
+ child.__asLiveOrigAngle = resolveActiveSelectionLocalAngle(
14990
+ child,
14991
+ sourceChildForAngle,
14992
+ obj
14993
+ );
14969
14994
  }
14970
- if (child instanceof fabric__namespace.Group && (child.__cropGroup || ((_o = child._ct) == null ? void 0 : _o.isCropGroup))) {
14995
+ if (child instanceof fabric__namespace.Group && (child.__cropGroup || ((_n = child._ct) == null ? void 0 : _n.isCropGroup))) {
14971
14996
  const ct = child.__cropData;
14972
14997
  if (!ct) continue;
14973
14998
  if (child.__asLiveOrigAngle == null) {
@@ -15140,7 +15165,7 @@ const PageCanvas = react.forwardRef(
15140
15165
  child.dirty = true;
15141
15166
  didReflowTextChild = true;
15142
15167
  }
15143
- if (isXSide && ((_p = groupShiftReflowSnapshotRef.current) == null ? void 0 : _p.selection) === obj) {
15168
+ if (isXSide && ((_o = groupShiftReflowSnapshotRef.current) == null ? void 0 : _o.selection) === obj) {
15144
15169
  const snap = groupShiftReflowSnapshotRef.current;
15145
15170
  const anchorEntry = snap.children[0];
15146
15171
  const anchorTopLive = anchorEntry.obj.top ?? 0;
@@ -15302,7 +15327,7 @@ const PageCanvas = react.forwardRef(
15302
15327
  setGuides(gridGuidesForScale.length ? [...scaleGuides, ...gridGuidesForScale] : scaleGuides);
15303
15328
  if (drilledGroupIdRef.current) {
15304
15329
  try {
15305
- (_q = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _q.call(fabricCanvas);
15330
+ (_p = fabricCanvas.__updateDrilledGroupOutline) == null ? void 0 : _p.call(fabricCanvas);
15306
15331
  } catch {
15307
15332
  }
15308
15333
  }
@@ -16103,7 +16128,7 @@ const PageCanvas = react.forwardRef(
16103
16128
  if (obj instanceof fabric__namespace.Group && obj.__cropGroup) {
16104
16129
  const ct = obj.__cropData;
16105
16130
  if (ct) {
16106
- const cropChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : obj.angle ?? 0;
16131
+ const cropChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric__namespace.ActiveSelection ? activeObj : null);
16107
16132
  const cropChildNormAngle = (cropChildLocalAngle % 360 + 360) % 360;
16108
16133
  const cropChildIsRotated = Math.abs(cropChildNormAngle) > 0.5 && Math.abs(cropChildNormAngle - 360) > 0.5;
16109
16134
  const cropHandle = activeSelectionResizeHandle;
@@ -16222,7 +16247,7 @@ const PageCanvas = react.forwardRef(
16222
16247
  useEditorStore.getState().updateElement(objId, { src: newSrc }, { recordHistory: false, skipLayoutRecalc: true });
16223
16248
  }
16224
16249
  } else if (isActiveSelection && (Math.abs((decomposed.scaleX ?? 1) - 1) > 1e-3 || Math.abs((decomposed.scaleY ?? 1) - 1) > 1e-3)) {
16225
- const imgChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : ((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY)) && Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : obj.angle ?? 0;
16250
+ const imgChildLocalAngle = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric__namespace.ActiveSelection ? activeObj : null);
16226
16251
  const imgChildNormAngle = (imgChildLocalAngle % 360 + 360) % 360;
16227
16252
  const imgChildIsRotated = Math.abs(imgChildNormAngle) > 0.5 && Math.abs(imgChildNormAngle - 360) > 0.5;
16228
16253
  const imgHandle = activeSelectionResizeHandle;
@@ -16553,6 +16578,18 @@ const PageCanvas = react.forwardRef(
16553
16578
  expectedCleanAngle
16554
16579
  );
16555
16580
  const persistedDecomposed = fabric__namespace.util.qrDecompose(cleanTransformMatrix);
16581
+ const hasPersistedFlipForAngle = !!(persistedFlipX || persistedFlipY);
16582
+ const isRotationGestureForStableAngle = isActiveSelection && activeObj instanceof fabric__namespace.ActiveSelection ? (() => {
16583
+ var _a3;
16584
+ const startAngle = ((_a3 = groupSelectionTransformStartRef.current) == null ? void 0 : _a3.selection) === activeObj ? groupSelectionTransformStartRef.current.selectionAngle ?? activeObj.angle ?? 0 : activeObj.angle ?? 0;
16585
+ return angleDistanceDeg(activeObj.angle ?? 0, startAngle) > 0.01;
16586
+ })() : !isActiveSelection && modifiedTarget === obj && angleDistanceDeg(obj.angle ?? 0, (sourceElement == null ? void 0 : sourceElement.angle) ?? obj.angle ?? 0) > 0.01;
16587
+ const stablePersistedAngle = resolveStableFlippedAngle(
16588
+ persistedDecomposed.angle,
16589
+ sourceElement == null ? void 0 : sourceElement.angle,
16590
+ hasPersistedFlipForAngle,
16591
+ isRotationGestureForStableAngle
16592
+ );
16556
16593
  const elementUpdate = {
16557
16594
  left: storePos.left,
16558
16595
  top: storePos.top,
@@ -16561,7 +16598,7 @@ const PageCanvas = react.forwardRef(
16561
16598
  // so finalWidth already reflects the new width chosen by the user.
16562
16599
  width: finalWidth,
16563
16600
  height: isLineObj ? 0 : isAutoShrinkText ? typeof autoShrinkStoredHeight === "number" ? autoShrinkStoredHeight : finalHeight : finalHeight,
16564
- angle: persistedDecomposed.angle,
16601
+ angle: stablePersistedAngle,
16565
16602
  skewX: isLineObj ? 0 : persistedDecomposed.skewX,
16566
16603
  skewY: isLineObj ? 0 : persistedDecomposed.skewY,
16567
16604
  scaleX: finalScaleX,
@@ -16633,7 +16670,7 @@ const PageCanvas = react.forwardRef(
16633
16670
  const isCropGroupObj = obj instanceof fabric__namespace.Group && obj.__cropGroup;
16634
16671
  const isPlainImageObj = obj instanceof fabric__namespace.FabricImage && !obj.__cropGroup && !obj.smartElementType;
16635
16672
  if (isActiveSelection && isActiveSelectionSideHandle && (isCropGroupObj || isPlainImageObj)) {
16636
- const childLocalAngleSrc = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : ((sourceElement == null ? void 0 : sourceElement.flipX) || (sourceElement == null ? void 0 : sourceElement.flipY)) && Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : Number.isFinite(sourceElement == null ? void 0 : sourceElement.angle) ? sourceElement.angle ?? 0 : obj.angle ?? 0;
16673
+ const childLocalAngleSrc = obj.__asLiveOrigAngle != null ? obj.__asLiveOrigAngle : resolveActiveSelectionLocalAngle(obj, sourceElement, activeObj instanceof fabric__namespace.ActiveSelection ? activeObj : null);
16637
16674
  const normAng = (childLocalAngleSrc % 360 + 360) % 360;
16638
16675
  const isRotatedImg = Math.min(normAng, 360 - normAng) > 0.5;
16639
16676
  if (isRotatedImg && activeObj instanceof fabric__namespace.ActiveSelection) {
@@ -20954,6 +20991,20 @@ function flattenSectionStateToFormData(sectionState, sections) {
20954
20991
  }
20955
20992
  return flat;
20956
20993
  }
20994
+ function gradientSiblingForTarget(targetProperty) {
20995
+ switch (targetProperty) {
20996
+ case "fill":
20997
+ return "fillGradient";
20998
+ case "stroke":
20999
+ return "strokeGradient";
21000
+ case "textBgColor":
21001
+ return "textBgGradient";
21002
+ case "backgroundColor":
21003
+ return "backgroundGradient";
21004
+ default:
21005
+ return null;
21006
+ }
21007
+ }
20957
21008
  const CLONE_SUFFIX = /_\d+$/;
20958
21009
  function baseId(id) {
20959
21010
  let s = id;
@@ -21054,7 +21105,18 @@ function setInTree(nodes, elementId, targetProperty, value) {
21054
21105
  delete node.cropZoom;
21055
21106
  }
21056
21107
  } else {
21057
- node[targetProperty] = value;
21108
+ const gradSibling = gradientSiblingForTarget(targetProperty);
21109
+ if (gradSibling) {
21110
+ if (isGradientConfig(value)) {
21111
+ node[gradSibling] = value;
21112
+ node[targetProperty] = targetProperty === "textBgColor" ? "transparent" : "";
21113
+ } else {
21114
+ if (gradSibling in node) delete node[gradSibling];
21115
+ node[targetProperty] = value;
21116
+ }
21117
+ } else {
21118
+ node[targetProperty] = value;
21119
+ }
21058
21120
  }
21059
21121
  if (targetProperty === "text" && node.type === "text") {
21060
21122
  const overflowPolicy = String(node.overflowPolicy ?? "grow-and-push");
@@ -21726,10 +21788,19 @@ function applyFormDataToConfig(config, mappings, formValues, repeatableSectionsF
21726
21788
  effectiveValue = formatTimeForDisplay(effectiveValue);
21727
21789
  }
21728
21790
  }
21729
- if (elementId === PAGE_BACKGROUND_ELEMENT_ID && targetProperty === "backgroundColor" && typeof effectiveValue === "string") {
21791
+ if (elementId === PAGE_BACKGROUND_ELEMENT_ID && targetProperty === "backgroundColor") {
21730
21792
  if ((_a3 = pages[0]) == null ? void 0 : _a3.settings) {
21731
- pages[0].settings.backgroundColor = effectiveValue;
21732
- return true;
21793
+ const settings = pages[0].settings;
21794
+ if (isGradientConfig(effectiveValue)) {
21795
+ settings.backgroundGradient = effectiveValue;
21796
+ settings.backgroundColor = "";
21797
+ return true;
21798
+ }
21799
+ if (typeof effectiveValue === "string") {
21800
+ if ("backgroundGradient" in settings) delete settings.backgroundGradient;
21801
+ settings.backgroundColor = effectiveValue;
21802
+ return true;
21803
+ }
21733
21804
  }
21734
21805
  }
21735
21806
  for (const page of pages) {
@@ -25977,9 +26048,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
25977
26048
  }
25978
26049
  return svgString;
25979
26050
  }
25980
- const resolvedPackageVersion = "0.5.452";
26051
+ const resolvedPackageVersion = "0.5.454";
25981
26052
  const PACKAGE_VERSION = resolvedPackageVersion;
25982
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.452";
26053
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.454";
25983
26054
  const roundParityValue = (value) => {
25984
26055
  if (typeof value !== "number") return value;
25985
26056
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -26793,7 +26864,7 @@ class PixldocsRenderer {
26793
26864
  await this.waitForCanvasScene(container, cloned, i);
26794
26865
  }
26795
26866
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
26796
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DLdSAaBB.cjs"));
26867
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-1e96-5qI.cjs"));
26797
26868
  const prepared = preparePagesForExport(
26798
26869
  cloned.pages,
26799
26870
  canvasWidth,
@@ -29113,7 +29184,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29113
29184
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29114
29185
  sanitizeSvgTreeForPdf(svgToDraw);
29115
29186
  try {
29116
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-DLdSAaBB.cjs"));
29187
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-1e96-5qI.cjs"));
29117
29188
  try {
29118
29189
  await logTextMeasurementDiagnostic(svgToDraw);
29119
29190
  } catch {
@@ -29510,4 +29581,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29510
29581
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29511
29582
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29512
29583
  exports.warmTemplateFromForm = warmTemplateFromForm;
29513
- //# sourceMappingURL=index-L5Rj-oYv.cjs.map
29584
+ //# sourceMappingURL=index-DCWaFt-_.cjs.map