labellife-design-tool 2.4.3 → 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) {
@@ -1369,13 +1394,8 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1369
1394
  element.toggleEditMode(true);
1370
1395
  var textNode = textRef.current;
1371
1396
  if (!textNode) return;
1372
- var grp = groupRef.current;
1373
1397
  var stage = textNode.getStage();
1374
1398
  if (!stage) return;
1375
-
1376
- // Hide the group so the textarea appears as in-place editing
1377
- if (grp) grp.hide();
1378
- stage.batchDraw();
1379
1399
  var stageContainer = stage.container();
1380
1400
  var textPosition = textNode.absolutePosition();
1381
1401
  var absScale = textNode.getAbsoluteScale();
@@ -1384,11 +1404,17 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1384
1404
  var cssFontStyle = element.fontStyle === 'italic' ? 'italic' : 'normal';
1385
1405
  var cssFontWeight = String(element.fontWeight || 'normal');
1386
1406
  var originalText = element.text;
1407
+
1408
+ // The Group stays visible and mirrors the textarea's value live (via the
1409
+ // 'input' listener below), so what's on screen while typing is the real
1410
+ // Konva render — stroke, shadow, background, curve all included — not a
1411
+ // CSS approximation of it (CSS can't reproduce Canvas 2D's stroke/shadow
1412
+ // rendering faithfully; see e.g. -webkit-text-stroke looking bolder and
1413
+ // "welding" adjacent glyphs together vs. Canvas's per-glyph vector stroke).
1414
+ // The textarea itself is fully transparent — it only captures input and
1415
+ // shows a caret positioned over the real text.
1387
1416
  var textarea = document.createElement('textarea');
1388
1417
  textarea.value = originalText;
1389
- // Only show the dimmed placeholder hint when there's no real text yet
1390
- // (e.g. a freshly-added text element) — not when editing existing text.
1391
- textarea.placeholder = originalText ? '' : element.placeholder;
1392
1418
  textarea.style.position = 'absolute';
1393
1419
  textarea.style.top = "".concat(textPosition.y, "px");
1394
1420
  textarea.style.left = "".concat(textPosition.x, "px");
@@ -1399,7 +1425,8 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1399
1425
  textarea.style.fontStyle = cssFontStyle;
1400
1426
  textarea.style.fontWeight = cssFontWeight;
1401
1427
  textarea.style.textAlign = element.align;
1402
- textarea.style.color = element.fill;
1428
+ textarea.style.color = 'transparent';
1429
+ textarea.style.caretColor = element.stroke || element.fill || '#000000';
1403
1430
  textarea.style.border = '0';
1404
1431
  textarea.style.borderWidth = '0';
1405
1432
  textarea.style.padding = '0';
@@ -1421,33 +1448,27 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1421
1448
  textarea.style.wordBreak = 'break-word';
1422
1449
  textarea.style.minHeight = '0';
1423
1450
  textarea.style.minWidth = '0';
1424
-
1425
- // Placeholder inherits the element's text color at 40% opacity
1426
- var placeholderStyle = document.createElement('style');
1427
- placeholderStyle.textContent = "\n textarea:placeholder-shown { opacity: 1; }\n textarea::placeholder { color: ".concat(element.fill, "; opacity: 0.4; }\n ");
1428
- stageContainer.appendChild(placeholderStyle);
1429
1451
  stageContainer.appendChild(textarea);
1430
1452
  textarea.focus();
1431
1453
  var caretPos = textarea.value.length;
1432
1454
  textarea.setSelectionRange(caretPos, caretPos);
1455
+ textarea.addEventListener('input', function () {
1456
+ element.set({
1457
+ text: textarea.value
1458
+ });
1459
+ });
1433
1460
  var removed = false;
1434
1461
  var removeTextarea = function removeTextarea() {
1435
1462
  var cancel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1436
1463
  if (removed) return;
1437
1464
  removed = true;
1438
- var newText = cancel ? originalText : textarea.value;
1439
1465
  element.set({
1440
- text: newText
1466
+ text: cancel ? originalText : textarea.value
1441
1467
  });
1442
1468
  element.toggleEditMode(false);
1443
- if (grp) grp.show();
1444
- stage.batchDraw();
1445
1469
  if (textarea.parentNode) {
1446
1470
  textarea.parentNode.removeChild(textarea);
1447
1471
  }
1448
- if (placeholderStyle.parentNode) {
1449
- placeholderStyle.parentNode.removeChild(placeholderStyle);
1450
- }
1451
1472
  };
1452
1473
  textarea.addEventListener('blur', function () {
1453
1474
  return removeTextarea(false);