labellife-design-tool 2.0.8 → 2.1.0

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.
@@ -912,6 +912,24 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
912
912
  });
913
913
  if (onDragEnd) onDragEnd(e);
914
914
  };
915
+
916
+ // Live text reflow during resize: convert scale to width on every frame
917
+ var handleTransform = function handleTransform(e) {
918
+ var node = e.target;
919
+ var scaleX = node.scaleX();
920
+ node.scaleY();
921
+ // Use element.width as the base since Group.width() can return 0
922
+ var baseWidth = node.width() || element.width || 100;
923
+ var newWidth = Math.max(20, baseWidth * Math.abs(scaleX));
924
+ node.scaleX(1);
925
+ node.scaleY(1);
926
+ node.width(newWidth);
927
+ element.set({
928
+ x: node.x(),
929
+ y: node.y(),
930
+ width: newWidth
931
+ });
932
+ };
915
933
  var handleTransformEnd = function handleTransformEnd(e) {
916
934
  var node = e.target;
917
935
  var scaleX = node.scaleX();
@@ -1076,6 +1094,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1076
1094
  onDblClick: handleDblClick,
1077
1095
  onDblTap: handleDblClick,
1078
1096
  onDragEnd: handleDragEnd,
1097
+ onTransform: handleTransform,
1079
1098
  onTransformEnd: handleTransformEnd,
1080
1099
  children: [element.backgroundEnabled && /*#__PURE__*/jsxRuntime.jsx(reactKonva.Rect, {
1081
1100
  x: -pad,
@@ -1887,6 +1906,8 @@ var PageOverlayFrame = mobxReactLite.observer(function (_ref4) {
1887
1906
  });
1888
1907
  });
1889
1908
  var ALL_ANCHORS = ['top-left', 'top-center', 'top-right', 'middle-left', 'middle-right', 'bottom-left', 'bottom-center', 'bottom-right'];
1909
+ var TEXT_ANCHORS = ['top-left', 'top-right', 'middle-left', 'middle-right', 'bottom-left', 'bottom-right'];
1910
+ var CORNER_ANCHORS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];
1890
1911
  var SelectionTransformer = mobxReactLite.observer(function (_ref5) {
1891
1912
  var store = _ref5.store,
1892
1913
  stageRef = _ref5.stageRef;
@@ -1898,8 +1919,16 @@ var SelectionTransformer = mobxReactLite.observer(function (_ref5) {
1898
1919
  var el = store.getElementById(id);
1899
1920
  return el && el.type !== 'line';
1900
1921
  });
1922
+ var allText = nonLineIds.length === 1 && function () {
1923
+ var el = store.getElementById(nonLineIds[0]);
1924
+ return el && el.type === 'text';
1925
+ }();
1926
+ var useCorners = nonLineIds.length > 1 || nonLineIds.length === 1 && function () {
1927
+ var el = store.getElementById(nonLineIds[0]);
1928
+ return el && el.type === 'group';
1929
+ }();
1930
+ var targetAnchors = useCorners ? CORNER_ANCHORS : allText ? TEXT_ANCHORS : ALL_ANCHORS;
1901
1931
  react.useEffect(function () {
1902
- // Defer by one frame so react-konva has committed new nodes to the stage
1903
1932
  var frame = requestAnimationFrame(function () {
1904
1933
  var _transformerRef$curre;
1905
1934
  if (!transformerRef.current || !stageRef.current) return;
@@ -1907,17 +1936,16 @@ var SelectionTransformer = mobxReactLite.observer(function (_ref5) {
1907
1936
  var nodes = [];
1908
1937
  nonLineIds.forEach(function (id) {
1909
1938
  var node = stage.findOne("#".concat(id));
1910
- if (node) {
1911
- nodes.push(node);
1912
- }
1939
+ if (node) nodes.push(node);
1913
1940
  });
1941
+ transformerRef.current.enabledAnchors(targetAnchors);
1914
1942
  transformerRef.current.nodes(nodes);
1915
1943
  (_transformerRef$curre = transformerRef.current.getLayer()) === null || _transformerRef$curre === void 0 || _transformerRef$curre.batchDraw();
1916
1944
  });
1917
1945
  return function () {
1918
1946
  return cancelAnimationFrame(frame);
1919
1947
  };
1920
- }, [nonLineIds.length, nonLineIds.join(',')]);
1948
+ }, [nonLineIds.length, nonLineIds.join(','), targetAnchors]);
1921
1949
  return /*#__PURE__*/jsxRuntime.jsx(reactKonva.Transformer, {
1922
1950
  ref: transformerRef,
1923
1951
  rotateEnabled: true,
@@ -1965,15 +1993,21 @@ var Workspace = mobxReactLite.observer(function (_ref6) {
1965
1993
  height: height
1966
1994
  });
1967
1995
 
1968
- // Auto-fit the canvas
1969
- if (store.width > 0 && store.height > 0) {
1996
+ // Auto-fit the canvas.
1997
+ // Guard: if the container hasn't been laid out yet (width/height === 0)
1998
+ // the arithmetic produces a negative scale which mirrors the entire canvas.
1999
+ // Skip the update in that case — the ResizeObserver will fire again once
2000
+ // the container has real dimensions.
2001
+ if (store.width > 0 && store.height > 0 && width > 0 && height > 0) {
1970
2002
  var padding = 40;
1971
2003
  var scaleX = (width - padding * 2) / store.width;
1972
2004
  var scaleY = (height - padding * 2) / store.height;
1973
2005
  var _scale = Math.min(scaleX, scaleY, 1);
1974
- store._setScaleToFit(_scale);
1975
- if (store.scale === 1) {
1976
- store.setScale(_scale);
2006
+ if (_scale > 0) {
2007
+ store._setScaleToFit(_scale);
2008
+ if (store.scale === 1) {
2009
+ store.setScale(_scale);
2010
+ }
1977
2011
  }
1978
2012
  }
1979
2013
  };