@semcore/ellipsis 2.39.4 → 2.40.0-prerelease.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.
@@ -0,0 +1,46 @@
1
+ export var setFontSettings = function setFontSettings(element, styleElement) {
2
+ element.style.fontFamily = styleElement.getPropertyValue('font-family');
3
+ element.style.fontSize = styleElement.getPropertyValue('font-size');
4
+ element.style.fontWeight = styleElement.getPropertyValue('font-weight');
5
+ element.style.lineHeight = styleElement.getPropertyValue('line-height');
6
+ element.style.fontFeatureSettings = styleElement.getPropertyValue('font-feature-settings');
7
+ element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');
8
+ };
9
+ export function isTextOverflowing(element, multiline, text) {
10
+ if (!element) return false;
11
+ var _element$getBoundingC = element.getBoundingClientRect(),
12
+ currentHeight = _element$getBoundingC.height,
13
+ currentWidth = _element$getBoundingC.width;
14
+ var measuringElement = createMeasurerElement(element, text);
15
+ var isOverflowing = false;
16
+ document.body.appendChild(measuringElement);
17
+ if (multiline) {
18
+ measuringElement.style.width = "".concat(currentWidth, "px");
19
+ var width = measuringElement.scrollWidth;
20
+ var height = measuringElement.getBoundingClientRect().height;
21
+ if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
22
+ isOverflowing = true;
23
+ }
24
+ } else {
25
+ measuringElement.style.whiteSpace = 'nowrap';
26
+ isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
27
+ }
28
+ document.body.removeChild(measuringElement);
29
+ return isOverflowing;
30
+ }
31
+ function createMeasurerElement(element, text) {
32
+ var styleElement = window.getComputedStyle(element, null);
33
+ var temporaryElement = document.createElement('temporary-block');
34
+ temporaryElement.style.display = styleElement.getPropertyValue('display');
35
+ temporaryElement.style.padding = styleElement.getPropertyValue('padding');
36
+ temporaryElement.style.position = 'absolute';
37
+ temporaryElement.style.right = '0%';
38
+ temporaryElement.style.bottom = '0%';
39
+ temporaryElement.style.visibility = 'hidden';
40
+ temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');
41
+ temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');
42
+ setFontSettings(temporaryElement, styleElement);
43
+ temporaryElement.textContent = text !== null && text !== void 0 ? text : element.textContent;
44
+ return temporaryElement;
45
+ }
46
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["setFontSettings","element","styleElement","style","fontFamily","getPropertyValue","fontSize","fontWeight","lineHeight","fontFeatureSettings","fontVariantNumeric","isTextOverflowing","multiline","text","_element$getBoundingC","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","createMeasurerElement","isOverflowing","document","body","appendChild","concat","scrollWidth","Math","ceil","whiteSpace","removeChild","window","getComputedStyle","temporaryElement","createElement","display","padding","position","right","bottom","visibility","wordWrap","textContent"],"sources":["../../src/utils.ts"],"sourcesContent":["export const setFontSettings = (element: HTMLElement, styleElement: CSSStyleDeclaration): void => {\n element.style.fontFamily = styleElement.getPropertyValue('font-family');\n element.style.fontSize = styleElement.getPropertyValue('font-size');\n element.style.fontWeight = styleElement.getPropertyValue('font-weight');\n element.style.lineHeight = styleElement.getPropertyValue('line-height');\n element.style.fontFeatureSettings =\n styleElement.getPropertyValue('font-feature-settings');\n element.style.fontVariantNumeric = styleElement.getPropertyValue('font-variant-numeric');\n};\n\nexport function isTextOverflowing(element: HTMLElement | null, multiline: boolean, text: string): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element, text);\n let isOverflowing = false;\n\n document.body.appendChild(measuringElement);\n if (multiline) {\n measuringElement.style.width = `${currentWidth}px`;\n\n const width = measuringElement.scrollWidth;\n const height = measuringElement.getBoundingClientRect().height;\n\n if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {\n isOverflowing = true;\n }\n } else {\n measuringElement.style.whiteSpace = 'nowrap';\n isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;\n }\n\n document.body.removeChild(measuringElement);\n\n return isOverflowing;\n}\n\nfunction createMeasurerElement(element: HTMLElement, text?: string) {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = styleElement.getPropertyValue('display');\n temporaryElement.style.padding = styleElement.getPropertyValue('padding');\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '0%';\n temporaryElement.style.bottom = '0%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.whiteSpace = styleElement.getPropertyValue('white-space');\n temporaryElement.style.wordWrap = styleElement.getPropertyValue('word-wrap');\n\n setFontSettings(temporaryElement, styleElement);\n\n temporaryElement.textContent = text ?? element.textContent;\n return temporaryElement;\n}\n"],"mappings":"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","ignoreList":[]}
@@ -3,112 +3,70 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
5
  import _createClass from "@babel/runtime/helpers/esm/createClass";
6
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
+ import _callSuper from "@babel/runtime/helpers/esm/callSuper";
7
7
  import _inherits from "@babel/runtime/helpers/esm/inherits";
8
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
9
8
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
10
- import { sstyled } from "@semcore/utils/lib/core/index";
11
- import createComponent, { sstyled as sstyled$1, Component, assignProps } from "@semcore/core";
12
- import React from "react";
9
+ import { sstyled, Component, assignProps, createComponent } from "@semcore/core";
10
+ import { Box } from "@semcore/base-components";
11
+ import { callAllEventHandlers } from "@semcore/core/lib/utils/assignProps";
12
+ import findComponent, { isAdvanceMode } from "@semcore/core/lib/utils/findComponent";
13
+ import getOriginChildren from "@semcore/core/lib/utils/getOriginChildren";
14
+ import pick from "@semcore/core/lib/utils/pick";
15
+ import reactToText from "@semcore/core/lib/utils/reactToText";
16
+ import { forkRef } from "@semcore/core/lib/utils/ref";
17
+ import useEnhancedEffect from "@semcore/core/lib/utils/use/useEnhancedEffect";
13
18
  import Tooltip from "@semcore/tooltip";
14
- import { Box } from "@semcore/flex-box";
19
+ import React from "react";
15
20
  import { useResizeObserver } from "./useResizeObserver.mjs";
16
- import useEnhancedEffect from "@semcore/utils/lib/use/useEnhancedEffect";
17
- import findComponent, { isAdvanceMode } from "@semcore/utils/lib/findComponent";
18
- import reactToText from "@semcore/utils/lib/reactToText";
19
- import getOriginChildren from "@semcore/utils/lib/getOriginChildren";
20
- import pick from "@semcore/utils/lib/pick";
21
- import { forkRef } from "@semcore/utils/lib/ref";
22
- import { callAllEventHandlers } from "@semcore/utils/lib/assignProps";
23
- var _excluded = ["styles", "Children", "maxLine", "tooltip", "trim", "containerRect", "containerRef", "includeTooltipProps", "children"], _excluded2 = ["styles", "text", "tooltip", "containerRect", "containerRef", "textRef", "tooltipProps", "children", "advanceMode"];
21
+ import { isTextOverflowing, setFontSettings } from "./utils.mjs";
22
+ var _excluded = ["styles", "Children", "maxLine", "tooltip", "trim", "containerRect", "containerRef", "includeTooltipProps", "children"];
24
23
  /*!__reshadow-styles__:"./style/ellipsis.shadow.css"*/
25
24
  var style = (
26
25
  /*__reshadow_css_start__*/
27
26
  (sstyled.insert(
28
27
  /*__inner_css_start__*/
29
- ".___SContainerMiddle_1lbz9_gg_,.___SContainer_1lbz9_gg_,.___SEllipsis_1lbz9_gg_.__middle-mod_1lbz9_gg_,.___SNoTooltipContainer_1lbz9_gg_{display:flex;overflow:hidden}.___SBeginning_1lbz9_gg_,.___SEllipsis_1lbz9_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:pre}.___SEllipsis_1lbz9_gg_.__maxLine_1lbz9_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_1lbz9);-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-wrap:break-word}.___SContainerMiddle_1lbz9_gg_>:has(.___SBeginning_1lbz9_gg_),.___SContainerMiddle_1lbz9_gg_>:has(.___STail_1lbz9_gg_){display:flex;width:100%}.___STail_1lbz9_gg_{white-space:pre}",
28
+ ".___SBeginning_hyasj_gg_,.___SEllipsis_hyasj_gg_{overflow:hidden;display:inline-block;text-overflow:ellipsis;white-space:pre}.___SEllipsis_hyasj_gg_.__maxLine_hyasj_gg_{display:-webkit-box;-webkit-line-clamp:var(--maxLine_hyasj);-webkit-box-orient:vertical;overflow:hidden;white-space:normal;word-wrap:break-word}.___SContainerMiddle_hyasj_gg_,.___SContainer_hyasj_gg_,.___SEllipsis_hyasj_gg_.__middle-mod_hyasj_gg_,.___SNoTooltipContainer_hyasj_gg_{display:flex;overflow:hidden}.___SContainerMiddle_hyasj_gg_>:has(.___SBeginning_hyasj_gg_),.___SContainerMiddle_hyasj_gg_>:has(.___STail_hyasj_gg_){display:flex;width:100%}.___STail_hyasj_gg_{white-space:pre}",
30
29
  /*__inner_css_end__*/
31
- "1lbz9_gg_"
30
+ "hyasj_gg_"
32
31
  ), /*__reshadow_css_end__*/
33
32
  {
34
- "__SContainer": "___SContainer_1lbz9_gg_",
35
- "__SNoTooltipContainer": "___SNoTooltipContainer_1lbz9_gg_",
36
- "__SContainerMiddle": "___SContainerMiddle_1lbz9_gg_",
37
- "__SBeginning": "___SBeginning_1lbz9_gg_",
38
- "__SEllipsis": "___SEllipsis_1lbz9_gg_",
39
- "_middle-mod": "__middle-mod_1lbz9_gg_",
40
- "_maxLine": "__maxLine_1lbz9_gg_",
41
- "--maxLine": "--maxLine_1lbz9",
42
- "__STail": "___STail_1lbz9_gg_"
33
+ "__SBeginning": "___SBeginning_hyasj_gg_",
34
+ "__SEllipsis": "___SEllipsis_hyasj_gg_",
35
+ "__SContainer": "___SContainer_hyasj_gg_",
36
+ "__SNoTooltipContainer": "___SNoTooltipContainer_hyasj_gg_",
37
+ "__SContainerMiddle": "___SContainerMiddle_hyasj_gg_",
38
+ "_maxLine": "__maxLine_hyasj_gg_",
39
+ "--maxLine": "--maxLine_hyasj",
40
+ "_middle-mod": "__middle-mod_hyasj_gg_",
41
+ "__STail": "___STail_hyasj_gg_"
43
42
  })
44
43
  );
45
44
  var defaultTooltipProps = ["title", "theme", "strategy", "modifiers", "placement", "interaction", "timeout", "visible", "defaultVisible", "onVisibleChange", "offset", "preventOverflow", "arrow", "flip", "computeStyles", "eventListeners", "onFirstUpdate", "cursorAnchoring"];
46
- var createMeasurerElement = function createMeasurerElement2(element, text) {
47
- var styleElement = window.getComputedStyle(element, null);
48
- var temporaryElement = document.createElement("temporary-block");
49
- temporaryElement.style.display = styleElement.getPropertyValue("display");
50
- temporaryElement.style.padding = styleElement.getPropertyValue("padding");
51
- temporaryElement.style.position = "absolute";
52
- temporaryElement.style.right = "0%";
53
- temporaryElement.style.bottom = "0%";
54
- temporaryElement.style.visibility = "hidden";
55
- temporaryElement.style.fontFamily = styleElement.getPropertyValue("font-family");
56
- temporaryElement.style.fontSize = styleElement.getPropertyValue("font-size");
57
- temporaryElement.style.fontWeight = styleElement.getPropertyValue("font-weight");
58
- temporaryElement.style.lineHeight = styleElement.getPropertyValue("line-height");
59
- temporaryElement.style.whiteSpace = styleElement.getPropertyValue("white-space");
60
- temporaryElement.style.wordWrap = styleElement.getPropertyValue("word-wrap");
61
- temporaryElement.style.fontFeatureSettings = styleElement.getPropertyValue("font-feature-settings");
62
- temporaryElement.style.fontVariantNumeric = styleElement.getPropertyValue("font-variant-numeric");
63
- temporaryElement.innerHTML = text !== null && text !== void 0 ? text : element.innerHTML;
64
- return temporaryElement;
65
- };
66
- function isTextOverflowing(element, multiline, text) {
67
- if (!element) return false;
68
- var _element$getBoundingC = element.getBoundingClientRect(), currentHeight = _element$getBoundingC.height, currentWidth = _element$getBoundingC.width;
69
- var measuringElement = createMeasurerElement(element, text);
70
- var isOverflowing = false;
71
- document.body.appendChild(measuringElement);
72
- if (multiline) {
73
- measuringElement.style.width = "".concat(currentWidth, "px");
74
- var width = measuringElement.scrollWidth;
75
- var height = measuringElement.getBoundingClientRect().height;
76
- if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
77
- isOverflowing = true;
78
- }
79
- } else {
80
- measuringElement.style.whiteSpace = "nowrap";
81
- isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
82
- }
83
- document.body.removeChild(measuringElement);
84
- return isOverflowing;
85
- }
86
45
  var forcedAdvancedMode = {
87
46
  forcedAdvancedMode: true
88
47
  };
89
48
  var noAdvancedMode = {};
90
- var RootEllipsis = /* @__PURE__ */ function(_Component) {
91
- _inherits(RootEllipsis2, _Component);
92
- var _super = _createSuper(RootEllipsis2);
49
+ var RootEllipsis = /* @__PURE__ */ (function(_Component) {
93
50
  function RootEllipsis2() {
94
51
  var _this;
95
52
  _classCallCheck(this, RootEllipsis2);
96
53
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
97
54
  args[_key] = arguments[_key];
98
55
  }
99
- _this = _super.call.apply(_super, [this].concat(args));
100
- _defineProperty(_assertThisInitialized(_this), "state", {
56
+ _this = _callSuper(this, RootEllipsis2, [].concat(args));
57
+ _defineProperty(_this, "state", {
101
58
  visible: false
102
59
  });
103
- _defineProperty(_assertThisInitialized(_this), "textRef", /* @__PURE__ */ React.createRef());
104
- _defineProperty(_assertThisInitialized(_this), "handlerVisibleChange", function(visible) {
60
+ _defineProperty(_this, "textRef", /* @__PURE__ */ React.createRef());
61
+ _defineProperty(_this, "handlerVisibleChange", function(visible) {
105
62
  _this.setState({
106
63
  visible: visible && _this.showTooltip()
107
64
  });
108
65
  });
109
66
  return _this;
110
67
  }
111
- _createClass(RootEllipsis2, [{
68
+ _inherits(RootEllipsis2, _Component);
69
+ return _createClass(RootEllipsis2, [{
112
70
  key: "showTooltip",
113
71
  value: function showTooltip() {
114
72
  var _this$asProps = this.asProps, _this$asProps$maxLine = _this$asProps.maxLine, maxLine = _this$asProps$maxLine === void 0 ? 1 : _this$asProps$maxLine, Children = _this$asProps.Children;
@@ -136,13 +94,10 @@ var RootEllipsis = /* @__PURE__ */ function(_Component) {
136
94
  }, {
137
95
  key: "render",
138
96
  value: function render() {
139
- var _ref4, _tooltipProps$visible;
97
+ var _ref3, _tooltipProps$visible;
140
98
  var SEllipsis = this.Root;
141
99
  var SContainer = Tooltip;
142
- var SNoTooltipContainer = Box;
143
- var _this$asProps3 = this.asProps, styles = _this$asProps3.styles, Children = _this$asProps3.Children, maxLine = _this$asProps3.maxLine, tooltip = _this$asProps3.tooltip, trim = _this$asProps3.trim, containerRect = _this$asProps3.containerRect, containerRef = _this$asProps3.containerRef, includeTooltipProps = _this$asProps3.includeTooltipProps;
144
- _this$asProps3.children;
145
- var other = _objectWithoutProperties(_this$asProps3, _excluded);
100
+ var _this$asProps3 = this.asProps, styles = _this$asProps3.styles, Children = _this$asProps3.Children, maxLine = _this$asProps3.maxLine, tooltip = _this$asProps3.tooltip, trim = _this$asProps3.trim, containerRect = _this$asProps3.containerRect, containerRef = _this$asProps3.containerRef, includeTooltipProps = _this$asProps3.includeTooltipProps, _children = _this$asProps3.children, other = _objectWithoutProperties(_this$asProps3, _excluded);
146
101
  var visible = this.state.visible;
147
102
  var advancedContent = findComponent(Children, [Ellipsis.Content.displayName]);
148
103
  var text = reactToText(advancedContent || getOriginChildren(Children));
@@ -152,7 +107,7 @@ var RootEllipsis = /* @__PURE__ */ function(_Component) {
152
107
  tooltipProps.onVisibleChange = tooltipProps.onVisibleChange ? callAllEventHandlers(tooltipProps.onVisibleChange, this.handlerVisibleChange) : this.handlerVisibleChange;
153
108
  if (trim === "middle") {
154
109
  var _ref2;
155
- return _ref2 = sstyled$1(styles), /* @__PURE__ */ React.createElement(EllipsisMiddle, _ref2.cn("EllipsisMiddle", _objectSpread({
110
+ return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(EllipsisMiddle, _ref2.cn("EllipsisMiddle", _objectSpread({
156
111
  "text": text,
157
112
  "styles": styles,
158
113
  "tooltip": tooltip,
@@ -163,26 +118,17 @@ var RootEllipsis = /* @__PURE__ */ function(_Component) {
163
118
  "advanceMode": advanceMode
164
119
  }, other)), /* @__PURE__ */ React.createElement(Children, _ref2.cn("Children", {})));
165
120
  }
166
- if (tooltip) {
167
- var _ref3;
168
- return _ref3 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SContainer, _ref3.cn("SContainer", _objectSpread(_objectSpread({
169
- "interaction": "hover",
170
- "title": !advanceMode ? text : void 0
171
- }, tooltipProps), advanceMode ? forcedAdvancedMode : noAdvancedMode)), advanceMode ? /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {})) : /* @__PURE__ */ React.createElement(SEllipsis, _ref3.cn("SEllipsis", _objectSpread({
172
- "render": Box,
173
- "ref": this.textRef,
174
- "maxLine": maxLine
175
- }, other)), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))));
176
- }
177
- return _ref4 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SNoTooltipContainer, _ref4.cn("SNoTooltipContainer", {}), advanceMode ? /* @__PURE__ */ React.createElement(Children, _ref4.cn("Children", {})) : /* @__PURE__ */ React.createElement(SEllipsis, _ref4.cn("SEllipsis", _objectSpread({
121
+ return _ref3 = sstyled(styles), /* @__PURE__ */ React.createElement(SContainer, _ref3.cn("SContainer", _objectSpread(_objectSpread({
122
+ "interaction": tooltip ? "hover" : "none",
123
+ "title": !advanceMode ? text : void 0
124
+ }, tooltipProps), advanceMode ? forcedAdvancedMode : noAdvancedMode)), advanceMode ? /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {})) : /* @__PURE__ */ React.createElement(SEllipsis, _ref3.cn("SEllipsis", _objectSpread({
178
125
  "render": Box,
179
126
  "ref": this.textRef,
180
127
  "maxLine": maxLine
181
- }, other)), /* @__PURE__ */ React.createElement(Children, _ref4.cn("Children", {}))));
128
+ }, other)), /* @__PURE__ */ React.createElement(Children, _ref3.cn("Children", {}))));
182
129
  }
183
130
  }]);
184
- return RootEllipsis2;
185
- }(Component);
131
+ })(Component);
186
132
  _defineProperty(RootEllipsis, "displayName", "Ellipsis");
187
133
  _defineProperty(RootEllipsis, "style", style);
188
134
  _defineProperty(RootEllipsis, "defaultProps", {
@@ -192,36 +138,32 @@ _defineProperty(RootEllipsis, "defaultProps", {
192
138
  __excludeProps: ["title"]
193
139
  });
194
140
  var EllipsisMiddleContext = /* @__PURE__ */ React.createContext(null);
195
- var EllipsisMiddle = function EllipsisMiddle2(props) {
196
- var _ref7;
197
- var styles = props.styles, text = props.text, tooltip = props.tooltip, containerRect = props.containerRect, containerRef = props.containerRef, textRef = props.textRef, tooltipProps = props.tooltipProps, children = props.children, advanceMode = props.advanceMode, otherProps = _objectWithoutProperties(props, _excluded2);
141
+ function EllipsisMiddle(props) {
142
+ var _ref5;
143
+ var styles = props.styles, text = props.text, tooltip = props.tooltip, containerRect = props.containerRect, containerRef = props.containerRef, textRef = props.textRef, tooltipProps = props.tooltipProps, children = props.children, advanceMode = props.advanceMode, tag = props.tag;
198
144
  var resizeElement = React.useRef(null);
199
- var _React$useState = React.useState({
200
- fontSize: "14",
201
- symbolWidth: 0
202
- }), _React$useState2 = _slicedToArray(_React$useState, 2), dimension = _React$useState2[0], setDimension = _React$useState2[1];
145
+ var _React$useState = React.useState(0), _React$useState2 = _slicedToArray(_React$useState, 2), symbolWidth = _React$useState2[0], setSymbolWidth = _React$useState2[1];
203
146
  var blockWidth = useResizeObserver(resizeElement, containerRect).width;
204
147
  useEnhancedEffect(function() {
205
148
  var node = (containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) || (resizeElement === null || resizeElement === void 0 ? void 0 : resizeElement.current);
206
149
  if (!node) return;
150
+ var styleElement = window.getComputedStyle(node);
207
151
  var dateSpan = document.createElement("temporary-block");
208
- dateSpan.setAttribute("style", "fontSize: ".concat(dimension.fontSize, "px"));
209
- dateSpan.innerHTML = "a";
152
+ setFontSettings(dateSpan, styleElement);
153
+ dateSpan.textContent = "a";
210
154
  document.body.appendChild(dateSpan);
211
155
  var rect = dateSpan.getBoundingClientRect();
212
- setDimension({
213
- fontSize: window.getComputedStyle(node, null).getPropertyValue("font-size"),
214
- symbolWidth: rect.width
215
- });
156
+ setSymbolWidth(rect.width);
216
157
  document.body.removeChild(dateSpan);
217
158
  }, []);
218
159
  var STail = "span";
219
160
  var SBeginning = "span";
220
- var SContainerMiddle = props.tag || Box;
161
+ var SContainerMiddle = Tooltip;
221
162
  var SAdvancedModeContainerMiddle = Tooltip;
222
163
  var displayedSymbols = React.useMemo(function() {
223
- return Math.round(blockWidth / dimension.symbolWidth);
224
- }, [blockWidth, dimension.symbolWidth]);
164
+ var displayedSymbols2 = Math.round(blockWidth / symbolWidth);
165
+ return displayedSymbols2 % 2 === 0 ? displayedSymbols2 : displayedSymbols2 - 1;
166
+ }, [blockWidth, symbolWidth]);
225
167
  var interaction = text.length > displayedSymbols ? "hover" : "none";
226
168
  var ref = containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement;
227
169
  var contextValue = React.useMemo(function() {
@@ -232,44 +174,37 @@ var EllipsisMiddle = function EllipsisMiddle2(props) {
232
174
  };
233
175
  }, [text, displayedSymbols]);
234
176
  if (advanceMode) {
235
- var _ref5;
236
- return _ref5 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SAdvancedModeContainerMiddle, _ref5.cn("SAdvancedModeContainerMiddle", _objectSpread(_objectSpread({
237
- "interaction": interaction
177
+ var _ref4;
178
+ return _ref4 = sstyled(styles), /* @__PURE__ */ React.createElement(SAdvancedModeContainerMiddle, _ref4.cn("SAdvancedModeContainerMiddle", _objectSpread(_objectSpread({
179
+ "interaction": tooltip ? interaction : "none"
238
180
  }, tooltipProps), forcedAdvancedMode)), /* @__PURE__ */ React.createElement(EllipsisMiddleContext.Provider, {
239
181
  value: contextValue
240
182
  }, children));
241
183
  }
242
- if (tooltip) {
243
- var _ref6;
244
- return _ref6 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SContainerMiddle, _ref6.cn("SContainerMiddle", _objectSpread({
245
- "interaction": interaction,
246
- "title": text,
247
- "ref": forkRef(ref, textRef),
248
- "tag": Tooltip,
249
- "__excludeProps": ["title"]
250
- }, tooltipProps)), /* @__PURE__ */ React.createElement(SBeginning, _ref6.cn("SBeginning", {}), contextValue.begining), /* @__PURE__ */ React.createElement(STail, _ref6.cn("STail", {}), contextValue.tail));
251
- }
252
- return _ref7 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SContainerMiddle, _ref7.cn("SContainerMiddle", _objectSpread(_objectSpread({}, otherProps), {}, {
253
- "ref": containerRef !== null && containerRef !== void 0 ? containerRef : resizeElement
254
- })), /* @__PURE__ */ React.createElement(SBeginning, _ref7.cn("SBeginning", {}), contextValue.begining), /* @__PURE__ */ React.createElement(STail, _ref7.cn("STail", {}), contextValue.tail));
255
- };
256
- var Content = function Content2(_ref10) {
257
- var _ref = arguments[0], _ref9;
258
- var styles = _ref10.styles, Children = _ref10.Children;
184
+ return _ref5 = sstyled(styles), /* @__PURE__ */ React.createElement(SContainerMiddle, _ref5.cn("SContainerMiddle", _objectSpread({
185
+ "interaction": tooltip ? interaction : "none",
186
+ "title": text,
187
+ "ref": forkRef(ref, textRef),
188
+ "tag": tag
189
+ }, tooltipProps)), /* @__PURE__ */ React.createElement(SBeginning, _ref5.cn("SBeginning", {}), contextValue.begining), /* @__PURE__ */ React.createElement(STail, _ref5.cn("STail", {}), contextValue.tail));
190
+ }
191
+ function Content(_ref8) {
192
+ var _ref = arguments[0], _ref7;
193
+ var styles = _ref8.styles, Children = _ref8.Children;
259
194
  var SEllipsis = Tooltip.Trigger;
260
195
  var ellipsisMiddleContext = React.useContext(EllipsisMiddleContext);
261
196
  var STail = "span";
262
197
  var SBeginning = "span";
263
198
  if (ellipsisMiddleContext) {
264
- var _ref8;
199
+ var _ref6;
265
200
  var begining = ellipsisMiddleContext.begining, tail = ellipsisMiddleContext.tail, ref = ellipsisMiddleContext.ref;
266
- return _ref8 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref8.cn("SEllipsis", _objectSpread({}, assignProps({
201
+ return _ref6 = sstyled(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref6.cn("SEllipsis", _objectSpread({}, assignProps({
267
202
  "middle-mod": true,
268
203
  "ref": ref
269
- }, _ref))), /* @__PURE__ */ React.createElement(SBeginning, _ref8.cn("SBeginning", {}), begining), /* @__PURE__ */ React.createElement(STail, _ref8.cn("STail", {}), tail));
204
+ }, _ref))), /* @__PURE__ */ React.createElement(SBeginning, _ref6.cn("SBeginning", {}), begining), /* @__PURE__ */ React.createElement(STail, _ref6.cn("STail", {}), tail));
270
205
  }
271
- return _ref9 = sstyled$1(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref9.cn("SEllipsis", _objectSpread({}, assignProps({}, _ref))), /* @__PURE__ */ React.createElement(Children, _ref9.cn("Children", {})));
272
- };
206
+ return _ref7 = sstyled(styles), /* @__PURE__ */ React.createElement(SEllipsis, _ref7.cn("SEllipsis", _objectSpread({}, assignProps({}, _ref))), /* @__PURE__ */ React.createElement(Children, _ref7.cn("Children", {})));
207
+ }
273
208
  var Ellipsis = createComponent(RootEllipsis, {
274
209
  Content,
275
210
  Popper: Tooltip.Popper
@@ -1,10 +1,3 @@
1
- SContainer,
2
- SNoTooltipContainer,
3
- SContainerMiddle {
4
- display: flex;
5
- overflow: hidden;
6
- }
7
-
8
1
  SBeginning,
9
2
  SEllipsis {
10
3
  overflow: hidden;
@@ -13,7 +6,9 @@ SEllipsis {
13
6
  white-space: pre;
14
7
  }
15
8
 
16
- SEllipsis[middle-mod] {
9
+ SContainer,
10
+ SNoTooltipContainer,
11
+ SContainerMiddle {
17
12
  display: flex;
18
13
  overflow: hidden;
19
14
  }
@@ -27,6 +22,11 @@ SEllipsis[maxLine] {
27
22
  overflow-wrap: break-word;
28
23
  }
29
24
 
25
+ SEllipsis[middle-mod] {
26
+ display: flex;
27
+ overflow: hidden;
28
+ }
29
+
30
30
  SContainerMiddle> :has(SBeginning),
31
31
  SContainerMiddle> :has(STail) {
32
32
  display: flex;
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import canUseDOM from "@semcore/core/lib/utils/canUseDOM";
3
+ import useEnhancedEffect from "@semcore/core/lib/utils/use/useEnhancedEffect";
2
4
  import React from "react";
3
- import useEnhancedEffect from "@semcore/utils/lib/use/useEnhancedEffect";
4
- import canUseDOM from "@semcore/utils/lib/canUseDOM";
5
5
  var useResizeObserver = function useResizeObserver2(ref, hookOverride) {
6
6
  var _React$useState = React.useState(0), _React$useState2 = _slicedToArray(_React$useState, 2), width = _React$useState2[0], setWidth = _React$useState2[1];
7
7
  var handleResize = React.useCallback(function(entries) {
@@ -0,0 +1,47 @@
1
+ var setFontSettings = function setFontSettings2(element, styleElement) {
2
+ element.style.fontFamily = styleElement.getPropertyValue("font-family");
3
+ element.style.fontSize = styleElement.getPropertyValue("font-size");
4
+ element.style.fontWeight = styleElement.getPropertyValue("font-weight");
5
+ element.style.lineHeight = styleElement.getPropertyValue("line-height");
6
+ element.style.fontFeatureSettings = styleElement.getPropertyValue("font-feature-settings");
7
+ element.style.fontVariantNumeric = styleElement.getPropertyValue("font-variant-numeric");
8
+ };
9
+ function isTextOverflowing(element, multiline, text) {
10
+ if (!element) return false;
11
+ var _element$getBoundingC = element.getBoundingClientRect(), currentHeight = _element$getBoundingC.height, currentWidth = _element$getBoundingC.width;
12
+ var measuringElement = createMeasurerElement(element, text);
13
+ var isOverflowing = false;
14
+ document.body.appendChild(measuringElement);
15
+ if (multiline) {
16
+ measuringElement.style.width = "".concat(currentWidth, "px");
17
+ var width = measuringElement.scrollWidth;
18
+ var height = measuringElement.getBoundingClientRect().height;
19
+ if (Math.ceil(currentHeight) < height || Math.ceil(currentWidth) < width) {
20
+ isOverflowing = true;
21
+ }
22
+ } else {
23
+ measuringElement.style.whiteSpace = "nowrap";
24
+ isOverflowing = Math.ceil(currentWidth) < measuringElement.getBoundingClientRect().width;
25
+ }
26
+ document.body.removeChild(measuringElement);
27
+ return isOverflowing;
28
+ }
29
+ function createMeasurerElement(element, text) {
30
+ var styleElement = window.getComputedStyle(element, null);
31
+ var temporaryElement = document.createElement("temporary-block");
32
+ temporaryElement.style.display = styleElement.getPropertyValue("display");
33
+ temporaryElement.style.padding = styleElement.getPropertyValue("padding");
34
+ temporaryElement.style.position = "absolute";
35
+ temporaryElement.style.right = "0%";
36
+ temporaryElement.style.bottom = "0%";
37
+ temporaryElement.style.visibility = "hidden";
38
+ temporaryElement.style.whiteSpace = styleElement.getPropertyValue("white-space");
39
+ temporaryElement.style.wordWrap = styleElement.getPropertyValue("word-wrap");
40
+ setFontSettings(temporaryElement, styleElement);
41
+ temporaryElement.textContent = text !== null && text !== void 0 ? text : element.textContent;
42
+ return temporaryElement;
43
+ }
44
+ export {
45
+ isTextOverflowing,
46
+ setFontSettings
47
+ };
@@ -1,14 +1,14 @@
1
- import { UnknownProperties, Intergalactic } from '@semcore/core';
2
- import { RefObject } from 'react';
3
- import { Box, BoxProps } from '@semcore/flex-box';
4
- import Tooltip, { TooltipProps } from '@semcore/tooltip';
1
+ import type { Box, BoxProps } from '@semcore/base-components';
2
+ import type { UnknownProperties, Intergalactic } from '@semcore/core';
3
+ import type { TooltipProps } from '@semcore/tooltip';
4
+ import type Tooltip from '@semcore/tooltip';
5
+ import type { RefObject } from 'react';
5
6
 
6
- /** @deprecated */
7
- export interface IEllipsisProps extends EllipsisProps, UnknownProperties {}
8
7
  export type EllipsisProps = BoxProps &
9
8
  Partial<TooltipProps> & {
10
9
  /**
11
- * Rows count in multiline Ellipsis
10
+ * Rows count in multiline Ellipsis.
11
+ * Applies only for `trim = end`
12
12
  * @default 1
13
13
  */
14
14
  maxLine?: number;
@@ -40,11 +40,14 @@ declare const useResizeObserver: (
40
40
  ref: RefObject<HTMLElement>,
41
41
  hookOverride?: { width: number },
42
42
  ) => { width: number };
43
-
43
+ /**
44
+ * @deprecated. Use Text with ellipsis property for @semcore/typography.
45
+ */
44
46
  declare const Ellipsis: Intergalactic.Component<'div', EllipsisProps> & {
45
47
  Content: typeof Box;
46
48
  Popper: typeof Tooltip.Popper;
47
49
  };
48
50
 
49
- export { useResizeObserver };
50
51
  export default Ellipsis;
52
+
53
+ export { useResizeObserver };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/ellipsis",
3
3
  "description": "Semrush Ellipsis Component",
4
- "version": "2.39.4",
4
+ "version": "2.40.0-prerelease.0",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -14,12 +14,12 @@
14
14
  "types": "./lib/types/index.d.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@semcore/utils": "4.48.5",
18
- "@semcore/flex-box": "5.41.4",
19
- "@semcore/tooltip": "6.49.4"
17
+ "@semcore/utils": "4.49.0-prerelease.0",
18
+ "@semcore/flex-box": "5.42.0-prerelease.0",
19
+ "@semcore/tooltip": "6.50.0-prerelease.0"
20
20
  },
21
21
  "peerDependencies": {
22
- "@semcore/core": "^2.17.5",
22
+ "@semcore/core": "^2.40.0-prerelease.0",
23
23
  "react": "16.8 - 18",
24
24
  "react-dom": "16.8 - 18"
25
25
  },