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.
@@ -495,8 +495,10 @@ var ImageMaskPanel = mobxReactLite.observer(function (_ref) {
495
495
  });
496
496
  ImageMaskPanel.displayName = 'ImageMaskPanel';
497
497
 
498
- // Cover-fit crop fractions (centered) for a box of given size over an image of natural size.
499
- // Mirrors the existing auto-crop calculation in canvas/image-element.js.
498
+ // Cover-fit SIZE (no cropping) for an image of natural size over a box of given size.
499
+ // The image is scaled to the smallest size that fully covers the box, preserving aspect
500
+ // ratio — one dimension matches the box, the other is larger and overflows the box
501
+ // (centered overflow on both sides).
500
502
 
501
503
  // Clamp an image page-space offset so the image still fully covers rect at the given scale.
502
504
  function clampImageOffset(offset, scale, rect, naturalWidth, naturalHeight) {
@@ -705,7 +707,15 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
705
707
  // Initialized on image load (cover-fit centered), then updated directionally on resize.
706
708
  var autoCropRef = React.useRef(null);
707
709
  var autoCropSrcRef = React.useRef(null); // tracks which image the crop was computed for
708
-
710
+ // Tracks the element size autoCropRef was last computed/updated for, so we can tell
711
+ // apart a size change made through the drag/transform handlers (which keep this in
712
+ // sync themselves via updateAutoCrop) from one made externally (e.g. a toolbar
713
+ // "Fit to page" action) — the latter needs a fresh cover-fit recompute, not a clamp
714
+ // of the now-unrelated old crop rect.
715
+ var autoCropSizeRef = React.useRef({
716
+ w: null,
717
+ h: null
718
+ });
709
719
  React.useEffect(function () {
710
720
  if (!element.src) {
711
721
  setImage(null);
@@ -810,6 +820,10 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
810
820
  w: cw,
811
821
  h: ch
812
822
  };
823
+ autoCropSizeRef.current = {
824
+ w: newW,
825
+ h: newH
826
+ };
813
827
  };
814
828
 
815
829
  // Live transform — reset scale, set node dimensions, update crop directionally
@@ -868,8 +882,11 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
868
882
  // Crop calculations
869
883
  var modelHasCrop = image && (element.cropX !== 0 || element.cropY !== 0 || element.cropWidth !== 1 || element.cropHeight !== 1);
870
884
 
871
- // Initialize auto-crop when image changes (cover-fit, centered)
872
- if (image && image !== autoCropSrcRef.current) {
885
+ // Initialize/refresh auto-crop when the image changes, or when width/height changed
886
+ // externally — i.e. NOT through the drag/transform handlers, which call
887
+ // updateAutoCrop themselves and keep autoCropSizeRef in sync as they go.
888
+ var sizeChangedExternally = autoCropSizeRef.current.w !== null && (Math.abs(element.width - autoCropSizeRef.current.w) > 0.5 || Math.abs(element.height - autoCropSizeRef.current.h) > 0.5);
889
+ if (image && (image !== autoCropSrcRef.current || !modelHasCrop && sizeChangedExternally)) {
873
890
  autoCropSrcRef.current = image;
874
891
  if (!modelHasCrop) {
875
892
  var natW = image.naturalWidth || image.width;
@@ -900,10 +917,18 @@ var ImageElementComponent = mobxReactLite.observer(function (_ref) {
900
917
  } else {
901
918
  autoCropRef.current = null;
902
919
  }
920
+ autoCropSizeRef.current = {
921
+ w: element.width,
922
+ h: element.height
923
+ };
903
924
  }
904
925
  if (!image) {
905
926
  autoCropSrcRef.current = null;
906
927
  autoCropRef.current = null;
928
+ autoCropSizeRef.current = {
929
+ w: null,
930
+ h: null
931
+ };
907
932
  }
908
933
  var cropProps = {};
909
934
  if (modelHasCrop) {