labellife-design-tool 2.4.4 → 2.4.6

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) {
@@ -1213,6 +1238,18 @@ function computeCurvedCacheBounds(element) {
1213
1238
  height: declaredHeight + maxSagitta * 2
1214
1239
  };
1215
1240
  }
1241
+
1242
+ // Sync a newly measured/computed height onto the element while keeping its
1243
+ // vertical center fixed — grows/shrinks equally above and below the original
1244
+ // position, instead of anchoring the top edge and only ever expanding downward.
1245
+ function syncHeightKeepingCenter(element, newHeight) {
1246
+ if (Math.abs(newHeight - element.height) <= 1) return;
1247
+ var deltaY = (newHeight - element.height) / 2;
1248
+ element.set({
1249
+ height: newHeight,
1250
+ y: element.y - deltaY
1251
+ });
1252
+ }
1216
1253
  var TextElementComponent = observer(function (_ref) {
1217
1254
  var _element$backgroundOp;
1218
1255
  var element = _ref.element;
@@ -1223,6 +1260,7 @@ var TextElementComponent = observer(function (_ref) {
1223
1260
  groupChild = _ref.groupChild;
1224
1261
  var groupRef = useRef(null);
1225
1262
  var textRef = useRef(null);
1263
+ var textareaRef = useRef(null);
1226
1264
  var _useState = useState(element.height || 50),
1227
1265
  _useState2 = _slicedToArray(_useState, 2),
1228
1266
  textHeight = _useState2[0],
@@ -1251,9 +1289,7 @@ var TextElementComponent = observer(function (_ref) {
1251
1289
  var h = node.height();
1252
1290
  if (h > 0) {
1253
1291
  setTextHeight(h);
1254
- if (Math.abs(h - element.height) > 1) element.set({
1255
- height: h
1256
- });
1292
+ syncHeightKeepingCenter(element, h);
1257
1293
  }
1258
1294
  // Re-cache if blur is active
1259
1295
  if (element.blurEnabled && node) {
@@ -1278,9 +1314,7 @@ var TextElementComponent = observer(function (_ref) {
1278
1314
  var h = node.height();
1279
1315
  if (h > 0) {
1280
1316
  setTextHeight(h);
1281
- if (Math.abs(h - element.height) > 1) element.set({
1282
- height: h
1283
- });
1317
+ syncHeightKeepingCenter(element, h);
1284
1318
  }
1285
1319
  });
1286
1320
  return function () {
@@ -1296,11 +1330,24 @@ var TextElementComponent = observer(function (_ref) {
1296
1330
  var lineHeightMultiplier = typeof element.lineHeight === 'number' ? element.lineHeight : parseFloat(element.lineHeight) || 1.2;
1297
1331
  var h = lineCount * element.fontSize * lineHeightMultiplier;
1298
1332
  setTextHeight(h);
1299
- if (Math.abs(h - element.height) > 1) element.set({
1300
- height: h
1301
- });
1333
+ syncHeightKeepingCenter(element, h);
1302
1334
  }, [element.text, element.placeholder, element.fontSize, element.lineHeight, element.curveEnabled, element.curvePower]);
1303
1335
 
1336
+ // While the live-typing textarea overlay is open, keep it aligned with the
1337
+ // Konva text node as syncHeightKeepingCenter adjusts element.y/height during
1338
+ // auto-grow — otherwise the invisible textarea (and its caret) stays at its
1339
+ // original position while the visible Konva text re-centers around it.
1340
+ useEffect(function () {
1341
+ if (!element._editModeEnabled) return;
1342
+ var node = textRef.current;
1343
+ var textarea = textareaRef.current;
1344
+ if (!node || !textarea) return;
1345
+ var pos = node.absolutePosition();
1346
+ var scaleY = node.getAbsoluteScale().y;
1347
+ textarea.style.top = "".concat(pos.y, "px");
1348
+ textarea.style.height = "".concat(element.height * scaleY, "px");
1349
+ }, [element._editModeEnabled, element.y, element.height]);
1350
+
1304
1351
  // Apply blur filter: cache the text node when blur is enabled
1305
1352
  useEffect(function () {
1306
1353
  var _node$getLayer3;
@@ -1420,6 +1467,7 @@ var TextElementComponent = observer(function (_ref) {
1420
1467
  textarea.style.minHeight = '0';
1421
1468
  textarea.style.minWidth = '0';
1422
1469
  stageContainer.appendChild(textarea);
1470
+ textareaRef.current = textarea;
1423
1471
  textarea.focus();
1424
1472
  var caretPos = textarea.value.length;
1425
1473
  textarea.setSelectionRange(caretPos, caretPos);
@@ -1437,6 +1485,7 @@ var TextElementComponent = observer(function (_ref) {
1437
1485
  text: cancel ? originalText : textarea.value
1438
1486
  });
1439
1487
  element.toggleEditMode(false);
1488
+ if (textareaRef.current === textarea) textareaRef.current = null;
1440
1489
  if (textarea.parentNode) {
1441
1490
  textarea.parentNode.removeChild(textarea);
1442
1491
  }