labellife-design-tool 2.4.5 → 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.
package/dist/esm/index.js CHANGED
@@ -11322,6 +11322,18 @@ function computeCurvedCacheBounds(element) {
11322
11322
  height: declaredHeight + maxSagitta * 2
11323
11323
  };
11324
11324
  }
11325
+
11326
+ // Sync a newly measured/computed height onto the element while keeping its
11327
+ // vertical center fixed — grows/shrinks equally above and below the original
11328
+ // position, instead of anchoring the top edge and only ever expanding downward.
11329
+ function syncHeightKeepingCenter(element, newHeight) {
11330
+ if (Math.abs(newHeight - element.height) <= 1) return;
11331
+ var deltaY = (newHeight - element.height) / 2;
11332
+ element.set({
11333
+ height: newHeight,
11334
+ y: element.y - deltaY
11335
+ });
11336
+ }
11325
11337
  var TextElementComponent = observer(function (_ref) {
11326
11338
  var _element$backgroundOp;
11327
11339
  var element = _ref.element;
@@ -11332,6 +11344,7 @@ var TextElementComponent = observer(function (_ref) {
11332
11344
  groupChild = _ref.groupChild;
11333
11345
  var groupRef = useRef(null);
11334
11346
  var textRef = useRef(null);
11347
+ var textareaRef = useRef(null);
11335
11348
  var _useState = useState(element.height || 50),
11336
11349
  _useState2 = _slicedToArray(_useState, 2),
11337
11350
  textHeight = _useState2[0],
@@ -11360,9 +11373,7 @@ var TextElementComponent = observer(function (_ref) {
11360
11373
  var h = node.height();
11361
11374
  if (h > 0) {
11362
11375
  setTextHeight(h);
11363
- if (Math.abs(h - element.height) > 1) element.set({
11364
- height: h
11365
- });
11376
+ syncHeightKeepingCenter(element, h);
11366
11377
  }
11367
11378
  // Re-cache if blur is active
11368
11379
  if (element.blurEnabled && node) {
@@ -11387,9 +11398,7 @@ var TextElementComponent = observer(function (_ref) {
11387
11398
  var h = node.height();
11388
11399
  if (h > 0) {
11389
11400
  setTextHeight(h);
11390
- if (Math.abs(h - element.height) > 1) element.set({
11391
- height: h
11392
- });
11401
+ syncHeightKeepingCenter(element, h);
11393
11402
  }
11394
11403
  });
11395
11404
  return function () {
@@ -11405,11 +11414,24 @@ var TextElementComponent = observer(function (_ref) {
11405
11414
  var lineHeightMultiplier = typeof element.lineHeight === 'number' ? element.lineHeight : parseFloat(element.lineHeight) || 1.2;
11406
11415
  var h = lineCount * element.fontSize * lineHeightMultiplier;
11407
11416
  setTextHeight(h);
11408
- if (Math.abs(h - element.height) > 1) element.set({
11409
- height: h
11410
- });
11417
+ syncHeightKeepingCenter(element, h);
11411
11418
  }, [element.text, element.placeholder, element.fontSize, element.lineHeight, element.curveEnabled, element.curvePower]);
11412
11419
 
11420
+ // While the live-typing textarea overlay is open, keep it aligned with the
11421
+ // Konva text node as syncHeightKeepingCenter adjusts element.y/height during
11422
+ // auto-grow — otherwise the invisible textarea (and its caret) stays at its
11423
+ // original position while the visible Konva text re-centers around it.
11424
+ useEffect(function () {
11425
+ if (!element._editModeEnabled) return;
11426
+ var node = textRef.current;
11427
+ var textarea = textareaRef.current;
11428
+ if (!node || !textarea) return;
11429
+ var pos = node.absolutePosition();
11430
+ var scaleY = node.getAbsoluteScale().y;
11431
+ textarea.style.top = "".concat(pos.y, "px");
11432
+ textarea.style.height = "".concat(element.height * scaleY, "px");
11433
+ }, [element._editModeEnabled, element.y, element.height]);
11434
+
11413
11435
  // Apply blur filter: cache the text node when blur is enabled
11414
11436
  useEffect(function () {
11415
11437
  var _node$getLayer3;
@@ -11529,6 +11551,7 @@ var TextElementComponent = observer(function (_ref) {
11529
11551
  textarea.style.minHeight = '0';
11530
11552
  textarea.style.minWidth = '0';
11531
11553
  stageContainer.appendChild(textarea);
11554
+ textareaRef.current = textarea;
11532
11555
  textarea.focus();
11533
11556
  var caretPos = textarea.value.length;
11534
11557
  textarea.setSelectionRange(caretPos, caretPos);
@@ -11546,6 +11569,7 @@ var TextElementComponent = observer(function (_ref) {
11546
11569
  text: cancel ? originalText : textarea.value
11547
11570
  });
11548
11571
  element.toggleEditMode(false);
11572
+ if (textareaRef.current === textarea) textareaRef.current = null;
11549
11573
  if (textarea.parentNode) {
11550
11574
  textarea.parentNode.removeChild(textarea);
11551
11575
  }