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