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.
@@ -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) {
@@ -1217,6 +1242,18 @@ function computeCurvedCacheBounds(element) {
1217
1242
  height: declaredHeight + maxSagitta * 2
1218
1243
  };
1219
1244
  }
1245
+
1246
+ // Sync a newly measured/computed height onto the element while keeping its
1247
+ // vertical center fixed — grows/shrinks equally above and below the original
1248
+ // position, instead of anchoring the top edge and only ever expanding downward.
1249
+ function syncHeightKeepingCenter(element, newHeight) {
1250
+ if (Math.abs(newHeight - element.height) <= 1) return;
1251
+ var deltaY = (newHeight - element.height) / 2;
1252
+ element.set({
1253
+ height: newHeight,
1254
+ y: element.y - deltaY
1255
+ });
1256
+ }
1220
1257
  var TextElementComponent = mobxReactLite.observer(function (_ref) {
1221
1258
  var _element$backgroundOp;
1222
1259
  var element = _ref.element;
@@ -1227,6 +1264,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1227
1264
  groupChild = _ref.groupChild;
1228
1265
  var groupRef = React.useRef(null);
1229
1266
  var textRef = React.useRef(null);
1267
+ var textareaRef = React.useRef(null);
1230
1268
  var _useState = React.useState(element.height || 50),
1231
1269
  _useState2 = _slicedToArray(_useState, 2),
1232
1270
  textHeight = _useState2[0],
@@ -1255,9 +1293,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1255
1293
  var h = node.height();
1256
1294
  if (h > 0) {
1257
1295
  setTextHeight(h);
1258
- if (Math.abs(h - element.height) > 1) element.set({
1259
- height: h
1260
- });
1296
+ syncHeightKeepingCenter(element, h);
1261
1297
  }
1262
1298
  // Re-cache if blur is active
1263
1299
  if (element.blurEnabled && node) {
@@ -1282,9 +1318,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1282
1318
  var h = node.height();
1283
1319
  if (h > 0) {
1284
1320
  setTextHeight(h);
1285
- if (Math.abs(h - element.height) > 1) element.set({
1286
- height: h
1287
- });
1321
+ syncHeightKeepingCenter(element, h);
1288
1322
  }
1289
1323
  });
1290
1324
  return function () {
@@ -1300,11 +1334,24 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1300
1334
  var lineHeightMultiplier = typeof element.lineHeight === 'number' ? element.lineHeight : parseFloat(element.lineHeight) || 1.2;
1301
1335
  var h = lineCount * element.fontSize * lineHeightMultiplier;
1302
1336
  setTextHeight(h);
1303
- if (Math.abs(h - element.height) > 1) element.set({
1304
- height: h
1305
- });
1337
+ syncHeightKeepingCenter(element, h);
1306
1338
  }, [element.text, element.placeholder, element.fontSize, element.lineHeight, element.curveEnabled, element.curvePower]);
1307
1339
 
1340
+ // While the live-typing textarea overlay is open, keep it aligned with the
1341
+ // Konva text node as syncHeightKeepingCenter adjusts element.y/height during
1342
+ // auto-grow — otherwise the invisible textarea (and its caret) stays at its
1343
+ // original position while the visible Konva text re-centers around it.
1344
+ React.useEffect(function () {
1345
+ if (!element._editModeEnabled) return;
1346
+ var node = textRef.current;
1347
+ var textarea = textareaRef.current;
1348
+ if (!node || !textarea) return;
1349
+ var pos = node.absolutePosition();
1350
+ var scaleY = node.getAbsoluteScale().y;
1351
+ textarea.style.top = "".concat(pos.y, "px");
1352
+ textarea.style.height = "".concat(element.height * scaleY, "px");
1353
+ }, [element._editModeEnabled, element.y, element.height]);
1354
+
1308
1355
  // Apply blur filter: cache the text node when blur is enabled
1309
1356
  React.useEffect(function () {
1310
1357
  var _node$getLayer3;
@@ -1424,6 +1471,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1424
1471
  textarea.style.minHeight = '0';
1425
1472
  textarea.style.minWidth = '0';
1426
1473
  stageContainer.appendChild(textarea);
1474
+ textareaRef.current = textarea;
1427
1475
  textarea.focus();
1428
1476
  var caretPos = textarea.value.length;
1429
1477
  textarea.setSelectionRange(caretPos, caretPos);
@@ -1441,6 +1489,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1441
1489
  text: cancel ? originalText : textarea.value
1442
1490
  });
1443
1491
  element.toggleEditMode(false);
1492
+ if (textareaRef.current === textarea) textareaRef.current = null;
1444
1493
  if (textarea.parentNode) {
1445
1494
  textarea.parentNode.removeChild(textarea);
1446
1495
  }