labellife-design-tool 2.4.4 → 2.4.5

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.
@@ -491,8 +491,10 @@ var ImageMaskPanel = observer(function (_ref) {
491
491
  });
492
492
  ImageMaskPanel.displayName = 'ImageMaskPanel';
493
493
 
494
- // Cover-fit crop fractions (centered) for a box of given size over an image of natural size.
495
- // Mirrors the existing auto-crop calculation in canvas/image-element.js.
494
+ // Cover-fit SIZE (no cropping) for an image of natural size over a box of given size.
495
+ // The image is scaled to the smallest size that fully covers the box, preserving aspect
496
+ // ratio — one dimension matches the box, the other is larger and overflows the box
497
+ // (centered overflow on both sides).
496
498
 
497
499
  // Clamp an image page-space offset so the image still fully covers rect at the given scale.
498
500
  function clampImageOffset(offset, scale, rect, naturalWidth, naturalHeight) {
@@ -701,7 +703,15 @@ var ImageElementComponent = observer(function (_ref) {
701
703
  // Initialized on image load (cover-fit centered), then updated directionally on resize.
702
704
  var autoCropRef = useRef(null);
703
705
  var autoCropSrcRef = useRef(null); // tracks which image the crop was computed for
704
-
706
+ // Tracks the element size autoCropRef was last computed/updated for, so we can tell
707
+ // apart a size change made through the drag/transform handlers (which keep this in
708
+ // sync themselves via updateAutoCrop) from one made externally (e.g. a toolbar
709
+ // "Fit to page" action) — the latter needs a fresh cover-fit recompute, not a clamp
710
+ // of the now-unrelated old crop rect.
711
+ var autoCropSizeRef = useRef({
712
+ w: null,
713
+ h: null
714
+ });
705
715
  useEffect(function () {
706
716
  if (!element.src) {
707
717
  setImage(null);
@@ -806,6 +816,10 @@ var ImageElementComponent = observer(function (_ref) {
806
816
  w: cw,
807
817
  h: ch
808
818
  };
819
+ autoCropSizeRef.current = {
820
+ w: newW,
821
+ h: newH
822
+ };
809
823
  };
810
824
 
811
825
  // Live transform — reset scale, set node dimensions, update crop directionally
@@ -864,8 +878,11 @@ var ImageElementComponent = observer(function (_ref) {
864
878
  // Crop calculations
865
879
  var modelHasCrop = image && (element.cropX !== 0 || element.cropY !== 0 || element.cropWidth !== 1 || element.cropHeight !== 1);
866
880
 
867
- // Initialize auto-crop when image changes (cover-fit, centered)
868
- if (image && image !== autoCropSrcRef.current) {
881
+ // Initialize/refresh auto-crop when the image changes, or when width/height changed
882
+ // externally — i.e. NOT through the drag/transform handlers, which call
883
+ // updateAutoCrop themselves and keep autoCropSizeRef in sync as they go.
884
+ var sizeChangedExternally = autoCropSizeRef.current.w !== null && (Math.abs(element.width - autoCropSizeRef.current.w) > 0.5 || Math.abs(element.height - autoCropSizeRef.current.h) > 0.5);
885
+ if (image && (image !== autoCropSrcRef.current || !modelHasCrop && sizeChangedExternally)) {
869
886
  autoCropSrcRef.current = image;
870
887
  if (!modelHasCrop) {
871
888
  var natW = image.naturalWidth || image.width;
@@ -896,10 +913,18 @@ var ImageElementComponent = observer(function (_ref) {
896
913
  } else {
897
914
  autoCropRef.current = null;
898
915
  }
916
+ autoCropSizeRef.current = {
917
+ w: element.width,
918
+ h: element.height
919
+ };
899
920
  }
900
921
  if (!image) {
901
922
  autoCropSrcRef.current = null;
902
923
  autoCropRef.current = null;
924
+ autoCropSizeRef.current = {
925
+ w: null,
926
+ h: null
927
+ };
903
928
  }
904
929
  var cropProps = {};
905
930
  if (modelHasCrop) {