@dynatrace/strato-components 0.85.110 → 0.85.120

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.
Files changed (190) hide show
  1. package/buttons/button/Button.css +17 -17
  2. package/buttons/button/Button.sty.js +4 -4
  3. package/content/progress/ProgressBar.css +71 -71
  4. package/content/progress/ProgressBar.sty.js +5 -5
  5. package/content/progress/ProgressBarIcon.css +2 -2
  6. package/content/progress/ProgressBarIcon.sty.js +1 -1
  7. package/content/progress/ProgressBarLabel.css +3 -3
  8. package/content/progress/ProgressBarLabel.js +1 -1
  9. package/content/progress/ProgressBarLabel.sty.js +1 -1
  10. package/content/progress/ProgressBarValue.css +5 -5
  11. package/content/progress/ProgressBarValue.js +1 -1
  12. package/content/progress/ProgressBarValue.sty.js +1 -1
  13. package/content/progress/ProgressCircle.css +40 -40
  14. package/content/progress/ProgressCircle.sty.js +5 -5
  15. package/content/progress/hooks/useProgressBarPropsContext.d.ts +5 -2
  16. package/content/progress/hooks/useProgressBarPropsContext.js +2 -2
  17. package/content/skeleton/Skeleton.css +6 -6
  18. package/content/skeleton/Skeleton.sty.js +1 -1
  19. package/core/hooks/useFontsUpdated.d.ts +1 -1
  20. package/core/hooks/useFontsUpdated.js +2 -2
  21. package/core/styles/focusRing.css +66 -66
  22. package/core/styles/focusRing.sty.js +2 -2
  23. package/core/utils/colorUtils.css +60 -60
  24. package/core/utils/colorUtils.sty.js +2 -2
  25. package/esm/buttons/button/Button.css +17 -17
  26. package/esm/buttons/button/Button.sty.js +4 -4
  27. package/esm/buttons/button/Button.sty.js.map +1 -1
  28. package/esm/content/progress/ProgressBar.css +71 -71
  29. package/esm/content/progress/ProgressBar.sty.js +5 -5
  30. package/esm/content/progress/ProgressBar.sty.js.map +1 -1
  31. package/esm/content/progress/ProgressBarIcon.css +2 -2
  32. package/esm/content/progress/ProgressBarIcon.sty.js +1 -1
  33. package/esm/content/progress/ProgressBarIcon.sty.js.map +1 -1
  34. package/esm/content/progress/ProgressBarLabel.css +3 -3
  35. package/esm/content/progress/ProgressBarLabel.js +2 -2
  36. package/esm/content/progress/ProgressBarLabel.js.map +2 -2
  37. package/esm/content/progress/ProgressBarLabel.sty.js +1 -1
  38. package/esm/content/progress/ProgressBarLabel.sty.js.map +1 -1
  39. package/esm/content/progress/ProgressBarValue.css +5 -5
  40. package/esm/content/progress/ProgressBarValue.js +2 -2
  41. package/esm/content/progress/ProgressBarValue.js.map +2 -2
  42. package/esm/content/progress/ProgressBarValue.sty.js +1 -1
  43. package/esm/content/progress/ProgressBarValue.sty.js.map +1 -1
  44. package/esm/content/progress/ProgressCircle.css +40 -40
  45. package/esm/content/progress/ProgressCircle.sty.js +5 -5
  46. package/esm/content/progress/ProgressCircle.sty.js.map +1 -1
  47. package/esm/content/progress/hooks/useProgressBarPropsContext.js +2 -2
  48. package/esm/content/progress/hooks/useProgressBarPropsContext.js.map +2 -2
  49. package/esm/content/skeleton/Skeleton.css +6 -6
  50. package/esm/content/skeleton/Skeleton.sty.js +1 -1
  51. package/esm/content/skeleton/Skeleton.sty.js.map +1 -1
  52. package/esm/core/hooks/useFontsUpdated.js +2 -2
  53. package/esm/core/hooks/useFontsUpdated.js.map +2 -2
  54. package/esm/core/styles/focusRing.css +66 -66
  55. package/esm/core/styles/focusRing.sty.js +2 -2
  56. package/esm/core/styles/focusRing.sty.js.map +1 -1
  57. package/esm/core/utils/colorUtils.css +60 -60
  58. package/esm/core/utils/colorUtils.sty.js +2 -2
  59. package/esm/core/utils/colorUtils.sty.js.map +1 -1
  60. package/esm/layouts/container/Container.css +4 -4
  61. package/esm/layouts/container/Container.sty.js +1 -1
  62. package/esm/layouts/container/Container.sty.js.map +1 -1
  63. package/esm/layouts/divider/Divider.css +6 -6
  64. package/esm/layouts/divider/Divider.sty.js +1 -1
  65. package/esm/layouts/divider/Divider.sty.js.map +1 -1
  66. package/esm/layouts/input-group/InputGroup.css +4 -4
  67. package/esm/layouts/input-group/InputGroup.sty.js +2 -2
  68. package/esm/layouts/input-group/InputGroup.sty.js.map +1 -1
  69. package/esm/layouts/surface/Surface.css +39 -39
  70. package/esm/layouts/surface/Surface.sty.js +2 -2
  71. package/esm/layouts/surface/Surface.sty.js.map +1 -1
  72. package/esm/layouts/surface/variables.sty.js +1 -1
  73. package/esm/layouts/surface/variables.sty.js.map +1 -1
  74. package/esm/styles/colorUtils.css +60 -60
  75. package/esm/styles/colorUtils.sty.js +2 -2
  76. package/esm/styles/colorUtils.sty.js.map +1 -1
  77. package/esm/styles/container.css +47 -47
  78. package/esm/styles/container.sty.js +2 -2
  79. package/esm/styles/container.sty.js.map +1 -1
  80. package/esm/styles/ellipsis.css +1 -1
  81. package/esm/styles/ellipsis.sty.js +1 -1
  82. package/esm/styles/ellipsis.sty.js.map +1 -1
  83. package/esm/styles/field.css +153 -153
  84. package/esm/styles/field.sty.js +2 -2
  85. package/esm/styles/field.sty.js.map +1 -1
  86. package/esm/styles/sprinkles.css +262 -262
  87. package/esm/styles/sprinkles.sty.js +1 -1
  88. package/esm/styles/sprinkles.sty.js.map +1 -1
  89. package/esm/styles/textStyle.css +8 -8
  90. package/esm/styles/textStyle.sty.js +1 -1
  91. package/esm/styles/textStyle.sty.js.map +1 -1
  92. package/esm/typography/block-quote/Blockquote.css +2 -2
  93. package/esm/typography/block-quote/Blockquote.sty.js +1 -1
  94. package/esm/typography/block-quote/Blockquote.sty.js.map +1 -1
  95. package/esm/typography/code/Code.css +1 -1
  96. package/esm/typography/code/Code.sty.js +1 -1
  97. package/esm/typography/code/Code.sty.js.map +1 -1
  98. package/esm/typography/emphasis/Emphasis.css +1 -1
  99. package/esm/typography/emphasis/Emphasis.sty.js +1 -1
  100. package/esm/typography/emphasis/Emphasis.sty.js.map +1 -1
  101. package/esm/typography/external-link/ExternalLink.css +6 -6
  102. package/esm/typography/external-link/ExternalLink.sty.js +1 -1
  103. package/esm/typography/external-link/ExternalLink.sty.js.map +1 -1
  104. package/esm/typography/heading/Heading.css +7 -7
  105. package/esm/typography/heading/Heading.sty.js +1 -1
  106. package/esm/typography/heading/Heading.sty.js.map +1 -1
  107. package/esm/typography/highlight/Highlight.css +1 -1
  108. package/esm/typography/highlight/Highlight.sty.js +1 -1
  109. package/esm/typography/highlight/Highlight.sty.js.map +1 -1
  110. package/esm/typography/index.js +12 -12
  111. package/esm/typography/index.js.map +2 -2
  112. package/esm/typography/link/Link.css +4 -4
  113. package/esm/typography/link/Link.sty.js +1 -1
  114. package/esm/typography/link/Link.sty.js.map +1 -1
  115. package/esm/typography/list/List.css +4 -4
  116. package/esm/typography/list/List.sty.js +2 -2
  117. package/esm/typography/list/List.sty.js.map +1 -1
  118. package/esm/typography/paragraph/Paragraph.css +3 -3
  119. package/esm/typography/paragraph/Paragraph.sty.js +1 -1
  120. package/esm/typography/paragraph/Paragraph.sty.js.map +1 -1
  121. package/esm/typography/strikethrough/Strikethrough.css +1 -1
  122. package/esm/typography/strikethrough/Strikethrough.sty.js +1 -1
  123. package/esm/typography/strikethrough/Strikethrough.sty.js.map +1 -1
  124. package/esm/typography/strong/Strong.css +1 -1
  125. package/esm/typography/strong/Strong.sty.js +1 -1
  126. package/esm/typography/strong/Strong.sty.js.map +1 -1
  127. package/esm/typography/text/Text.css +3 -3
  128. package/esm/typography/text/Text.sty.js +1 -1
  129. package/esm/typography/text/Text.sty.js.map +1 -1
  130. package/esm/typography/text-ellipsis/TextEllipsis.css +4 -4
  131. package/esm/typography/text-ellipsis/TextEllipsis.js +45 -45
  132. package/esm/typography/text-ellipsis/TextEllipsis.js.map +2 -2
  133. package/esm/typography/text-ellipsis/TextEllipsis.sty.js +1 -1
  134. package/esm/typography/text-ellipsis/TextEllipsis.sty.js.map +1 -1
  135. package/esm/typography/utils.js +19 -19
  136. package/esm/typography/utils.js.map +2 -2
  137. package/layouts/container/Container.css +4 -4
  138. package/layouts/container/Container.sty.js +1 -1
  139. package/layouts/divider/Divider.css +6 -6
  140. package/layouts/divider/Divider.sty.js +1 -1
  141. package/layouts/input-group/InputGroup.css +4 -4
  142. package/layouts/input-group/InputGroup.sty.js +2 -2
  143. package/layouts/surface/Surface.css +39 -39
  144. package/layouts/surface/Surface.sty.js +2 -2
  145. package/layouts/surface/variables.sty.js +1 -1
  146. package/package.json +1 -1
  147. package/styles/colorUtils.css +60 -60
  148. package/styles/colorUtils.sty.js +2 -2
  149. package/styles/container.css +47 -47
  150. package/styles/container.sty.js +2 -2
  151. package/styles/ellipsis.css +1 -1
  152. package/styles/ellipsis.sty.js +1 -1
  153. package/styles/field.css +153 -153
  154. package/styles/field.sty.js +2 -2
  155. package/styles/sprinkles.css +262 -262
  156. package/styles/sprinkles.sty.js +1 -1
  157. package/styles/textStyle.css +8 -8
  158. package/styles/textStyle.sty.js +1 -1
  159. package/typography/block-quote/Blockquote.css +2 -2
  160. package/typography/block-quote/Blockquote.sty.js +1 -1
  161. package/typography/code/Code.css +1 -1
  162. package/typography/code/Code.sty.js +1 -1
  163. package/typography/emphasis/Emphasis.css +1 -1
  164. package/typography/emphasis/Emphasis.sty.js +1 -1
  165. package/typography/external-link/ExternalLink.css +6 -6
  166. package/typography/external-link/ExternalLink.sty.js +1 -1
  167. package/typography/heading/Heading.css +7 -7
  168. package/typography/heading/Heading.sty.js +1 -1
  169. package/typography/highlight/Highlight.css +1 -1
  170. package/typography/highlight/Highlight.sty.js +1 -1
  171. package/typography/index.d.ts +3 -3
  172. package/typography/index.js +6 -6
  173. package/typography/link/Link.css +4 -4
  174. package/typography/link/Link.sty.js +1 -1
  175. package/typography/list/List.css +4 -4
  176. package/typography/list/List.sty.js +2 -2
  177. package/typography/paragraph/Paragraph.css +3 -3
  178. package/typography/paragraph/Paragraph.sty.js +1 -1
  179. package/typography/strikethrough/Strikethrough.css +1 -1
  180. package/typography/strikethrough/Strikethrough.sty.js +1 -1
  181. package/typography/strong/Strong.css +1 -1
  182. package/typography/strong/Strong.sty.js +1 -1
  183. package/typography/text/Text.css +3 -3
  184. package/typography/text/Text.sty.js +1 -1
  185. package/typography/text-ellipsis/TextEllipsis.css +4 -4
  186. package/typography/text-ellipsis/TextEllipsis.d.ts +2 -2
  187. package/typography/text-ellipsis/TextEllipsis.js +44 -44
  188. package/typography/text-ellipsis/TextEllipsis.sty.js +1 -1
  189. package/typography/utils.d.ts +14 -11
  190. package/typography/utils.js +19 -19
@@ -33,12 +33,12 @@ module.exports = __toCommonJS(TextEllipsis_exports);
33
33
  var import_clsx = __toESM(require("clsx"));
34
34
  var import_react = __toESM(require("react"));
35
35
  var import_use_resize_observer = __toESM(require("use-resize-observer"));
36
- var import_TextEllipsis_css = require("./TextEllipsis.sty.js");
37
36
  var import_useFontsUpdated = require("../../core/hooks/useFontsUpdated.js");
38
37
  var import_useMergeRefs = require("../../core/hooks/useMergeRefs.js");
39
- var import_utils2 = require("../utils.js");
40
- function getFontProps(textWrapper) {
41
- const computedStyle = window.getComputedStyle(textWrapper, null);
38
+ var import_utils = require("../utils.js");
39
+ var import_TextEllipsis_css = require("./TextEllipsis.sty.js");
40
+ function getFontProps(innerSpanElement) {
41
+ const computedStyle = window.getComputedStyle(innerSpanElement, null);
42
42
  return {
43
43
  fontStyle: computedStyle.getPropertyValue("font-style"),
44
44
  fontWeight: computedStyle.getPropertyValue("font-weight"),
@@ -46,50 +46,51 @@ function getFontProps(textWrapper) {
46
46
  fontFamily: computedStyle.getPropertyValue("font-family")
47
47
  };
48
48
  }
49
- function isNativeEllipsisActive(textWrapper, containerWidth) {
49
+ function isNativeEllipsisActive(innerSpanElement, containerWidth) {
50
50
  const originalTextWidth = Math.max(
51
- textWrapper.getBoundingClientRect().width,
52
- textWrapper.scrollWidth
51
+ innerSpanElement.getBoundingClientRect().width,
52
+ innerSpanElement.scrollWidth
53
53
  );
54
54
  const textWidth = Math.floor(originalTextWidth * 100) / 100;
55
55
  return textWidth > containerWidth;
56
56
  }
57
+ function resetFullText(innerSpanElement, originalText) {
58
+ if (innerSpanElement.textContent !== originalText) {
59
+ innerSpanElement.textContent = originalText;
60
+ }
61
+ }
62
+ function getWidth(element) {
63
+ return Math.max(element.getBoundingClientRect().width, element.clientWidth);
64
+ }
65
+ function getContainerWidth(containerElement) {
66
+ return Math.ceil(getWidth(containerElement) * 100) / 100;
67
+ }
68
+ function onTextOverflowCallback(current, wasEllipsized, onTextOverflow) {
69
+ if (onTextOverflow && current !== wasEllipsized) {
70
+ onTextOverflow(current);
71
+ }
72
+ }
57
73
  function renderEllipsizedText(originalText, truncationMode, containerRef, wasEllipsized, onTextOverflow) {
58
74
  const containerElement = containerRef.current;
59
- const textWrapper = containerElement?.firstElementChild || null;
60
- if (containerElement !== null && textWrapper !== null) {
61
- if (textWrapper.textContent !== originalText) {
62
- textWrapper.textContent = originalText;
63
- }
64
- const containerWidth = Math.ceil(containerElement.getBoundingClientRect().width * 100) / 100;
65
- if (truncationMode === "middle") {
66
- if (isNativeEllipsisActive(textWrapper, containerWidth)) {
67
- const ellipsizedText = (0, import_utils2._centerEllipsizeText)(
68
- originalText,
69
- getFontProps(textWrapper),
70
- containerWidth
71
- );
72
- textWrapper.textContent = ellipsizedText;
73
- if (ellipsizedText !== originalText) {
74
- if (onTextOverflow && !wasEllipsized) {
75
- onTextOverflow(true);
76
- }
77
- return true;
78
- }
79
- }
80
- if (onTextOverflow && wasEllipsized) {
81
- onTextOverflow(false);
82
- }
83
- } else if (isNativeEllipsisActive(textWrapper, containerWidth)) {
84
- if (onTextOverflow && !wasEllipsized) {
85
- onTextOverflow(true);
86
- }
87
- return true;
88
- } else if (onTextOverflow && wasEllipsized) {
89
- onTextOverflow(false);
90
- }
75
+ const innerSpanElement = containerElement?.firstElementChild || null;
76
+ if (containerElement === null || innerSpanElement === null) {
77
+ return false;
78
+ }
79
+ resetFullText(innerSpanElement, originalText);
80
+ const containerWidth = getContainerWidth(containerElement);
81
+ if (!isNativeEllipsisActive(innerSpanElement, containerWidth)) {
82
+ onTextOverflowCallback(false, wasEllipsized, onTextOverflow);
83
+ return false;
84
+ }
85
+ if (truncationMode === "middle") {
86
+ innerSpanElement.textContent = (0, import_utils.centerEllipsizeText)(
87
+ originalText,
88
+ getFontProps(innerSpanElement),
89
+ containerWidth
90
+ );
91
91
  }
92
- return false;
92
+ onTextOverflowCallback(true, wasEllipsized, onTextOverflow);
93
+ return true;
93
94
  }
94
95
  const ComputedTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
95
96
  const {
@@ -103,7 +104,7 @@ const ComputedTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props
103
104
  "data-dtrum-allow": dataDtrumAllow,
104
105
  ...remainingProps
105
106
  } = props;
106
- const { ref: observerContainerRef } = (0, import_use_resize_observer.default)();
107
+ const { ref: observerContainerRef, width } = (0, import_use_resize_observer.default)();
107
108
  const containerRef = (0, import_react.useRef)(null);
108
109
  const ellipsisStateRef = (0, import_react.useRef)(false);
109
110
  const mergedRef = (0, import_useMergeRefs.useMergeRefs)([
@@ -113,8 +114,7 @@ const ComputedTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props
113
114
  },
114
115
  forwardedRef
115
116
  ]);
116
- const containerWidth = containerRef.current?.getBoundingClientRect().width;
117
- const fontsUpdated = (0, import_useFontsUpdated._useFontsUpdated)();
117
+ const fontsUpdated = (0, import_useFontsUpdated.useFontsUpdated)();
118
118
  (0, import_react.useLayoutEffect)(() => {
119
119
  ellipsisStateRef.current = renderEllipsizedText(
120
120
  children,
@@ -123,7 +123,7 @@ const ComputedTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props
123
123
  ellipsisStateRef.current,
124
124
  onTextOverflow
125
125
  );
126
- }, [containerWidth, children, truncationMode, fontsUpdated, onTextOverflow]);
126
+ }, [width, children, truncationMode, fontsUpdated, onTextOverflow]);
127
127
  return /* @__PURE__ */ import_react.default.createElement(
128
128
  "span",
129
129
  {
@@ -22,4 +22,4 @@ __export(TextEllipsis_css_exports, {
22
22
  module.exports = __toCommonJS(TextEllipsis_css_exports);
23
23
  var import_TextEllipsis_css_ts_vanilla = require("./TextEllipsis.css");
24
24
  var import_createRuntimeFn = require("@vanilla-extract/recipes/createRuntimeFn");
25
- var textEllipsisCSS = (0, import_createRuntimeFn.createRuntimeFn)({ defaultClassName: "_1mnpbqs0-0-85-110", variantClassNames: { truncationMode: { start: "_1mnpbqs1-0-85-110", middle: "_1mnpbqs2-0-85-110", end: "_1mnpbqs3-0-85-110" } }, defaultVariants: {}, compoundVariants: [] });
25
+ var textEllipsisCSS = (0, import_createRuntimeFn.createRuntimeFn)({ defaultClassName: "_1mnpbqs0-0-85-120", variantClassNames: { truncationMode: { start: "_1mnpbqs1-0-85-120", middle: "_1mnpbqs2-0-85-120", end: "_1mnpbqs3-0-85-120" } }, defaultVariants: {}, compoundVariants: [] });
@@ -1,20 +1,23 @@
1
1
  /**
2
+ * Properties describing how a piece of text is formatted.
2
3
  * @internal
3
- * Properties describing how a piece of text is formatted. */
4
- export type _Font = {
4
+ */
5
+ export type Font = {
5
6
  fontStyle?: string;
6
7
  fontWeight?: string;
7
8
  fontSize: string;
8
9
  fontFamily: string;
9
10
  };
10
11
  /**
12
+ * The Unicode character representing an ellipsis.
11
13
  * @internal
12
- * The Unicode character representing an ellipsis. */
13
- export declare const _ELLIPSIS_CHARACTER = "\u2026";
14
+ */
15
+ export declare const ELLIPSIS_CHARACTER = "\u2026";
14
16
  /**
17
+ * Max iterations for finding the perfect truncated text for a given width
15
18
  * @internal
16
- * Max iterations for finding the perfect truncated text for a given width */
17
- export declare const _ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
19
+ */
20
+ export declare const ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
18
21
  /**
19
22
  * Calculates the width of formatted text in pixels.
20
23
  *
@@ -22,14 +25,14 @@ export declare const _ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
22
25
  * @param textFont - The font settings for the text
23
26
  * @internal
24
27
  */
25
- export declare function _getTextWidth(text: string, textFont: _Font): number;
28
+ export declare function getTextWidth(text: string, textFont: Font): number;
26
29
  /**
27
- * @internal
28
30
  * Calculates the height of formatted text in pixels.
29
31
  * @param text - The text to calculate the height of
30
32
  * @param textFont - The font settings for the text
33
+ * @internal
31
34
  */
32
- export declare function _getTextHeight(text: string, textFont: _Font): number;
35
+ export declare function getTextHeight(text: string, textFont: Font): number;
33
36
  /**
34
37
  * Cuts off text that exceeds the maximum width in the center and
35
38
  * concatenates both shortened ends of the text with an ellipsis.
@@ -39,14 +42,14 @@ export declare function _getTextHeight(text: string, textFont: _Font): number;
39
42
  * @param maxWidthInPx - If the text's width exceeds this value, the text will be truncated to a string whose width is guaranteed to be below it
40
43
  * @internal
41
44
  */
42
- export declare function _centerEllipsizeText(originalText: string, textFont: _Font, maxWidthInPx: number): string;
45
+ export declare function centerEllipsizeText(originalText: string, textFont: Font, maxWidthInPx: number): string;
43
46
  /**
44
47
  * Returns an object containing the width of a given formatted text and the
45
48
  * width of an ellipsis character with the same text format or `null`
46
49
  * if the text width does not exceed its maximum available width.
47
50
  * @internal
48
51
  */
49
- export declare function _calculateEllipsisInfo(originalText: string, textFont: _Font, maxWidthInPx: number): {
52
+ export declare function calculateEllipsisInfo(originalText: string, textFont: Font, maxWidthInPx: number): {
50
53
  ellipsisWidth: number;
51
54
  avgLetterWidth: number;
52
55
  } | null;
@@ -17,18 +17,18 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var utils_exports = {};
19
19
  __export(utils_exports, {
20
- _ELLIPSIS_APPROXIMATION_THRESHOLD: () => _ELLIPSIS_APPROXIMATION_THRESHOLD,
21
- _ELLIPSIS_CHARACTER: () => _ELLIPSIS_CHARACTER,
22
- _calculateEllipsisInfo: () => _calculateEllipsisInfo,
23
- _centerEllipsizeText: () => _centerEllipsizeText,
24
- _getTextHeight: () => _getTextHeight,
25
- _getTextWidth: () => _getTextWidth
20
+ ELLIPSIS_APPROXIMATION_THRESHOLD: () => ELLIPSIS_APPROXIMATION_THRESHOLD,
21
+ ELLIPSIS_CHARACTER: () => ELLIPSIS_CHARACTER,
22
+ calculateEllipsisInfo: () => calculateEllipsisInfo,
23
+ centerEllipsizeText: () => centerEllipsizeText,
24
+ getTextHeight: () => getTextHeight,
25
+ getTextWidth: () => getTextWidth
26
26
  });
27
27
  module.exports = __toCommonJS(utils_exports);
28
- const _ELLIPSIS_CHARACTER = "\u2026";
29
- const _ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
28
+ const ELLIPSIS_CHARACTER = "\u2026";
29
+ const ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
30
30
  let inMemContext2d;
31
- function _getTextWidth(text, textFont) {
31
+ function getTextWidth(text, textFont) {
32
32
  const context = getCanvasContext2d();
33
33
  context.font = getFontString(textFont);
34
34
  const textMetrics = context.measureText(text);
@@ -38,15 +38,15 @@ function _getTextWidth(text, textFont) {
38
38
  const actualTextWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
39
39
  return Math.ceil(actualTextWidth);
40
40
  }
41
- function _getTextHeight(text, textFont) {
41
+ function getTextHeight(text, textFont) {
42
42
  const context = getCanvasContext2d();
43
43
  context.font = getFontString(textFont);
44
44
  const textMetrics = context.measureText(text);
45
45
  const actualTextHeight = Math.abs(textMetrics.actualBoundingBoxAscent) + Math.abs(textMetrics.actualBoundingBoxDescent);
46
46
  return Math.ceil(actualTextHeight);
47
47
  }
48
- function _centerEllipsizeText(originalText, textFont, maxWidthInPx) {
49
- const ellipsisInfo = _calculateEllipsisInfo(
48
+ function centerEllipsizeText(originalText, textFont, maxWidthInPx) {
49
+ const ellipsisInfo = calculateEllipsisInfo(
50
50
  originalText,
51
51
  textFont,
52
52
  maxWidthInPx
@@ -57,7 +57,7 @@ function _centerEllipsizeText(originalText, textFont, maxWidthInPx) {
57
57
  const { ellipsisWidth, avgLetterWidth } = ellipsisInfo;
58
58
  const availableTextWidth = maxWidthInPx - ellipsisWidth;
59
59
  if (availableTextWidth <= ellipsisWidth) {
60
- return _ELLIPSIS_CHARACTER;
60
+ return ELLIPSIS_CHARACTER;
61
61
  }
62
62
  const initialPrefixSuffixLength = Math.floor(availableTextWidth / avgLetterWidth / 2) + 1;
63
63
  let prefix;
@@ -72,10 +72,10 @@ function _centerEllipsizeText(originalText, textFont, maxWidthInPx) {
72
72
  suffixLength -= attempt % 2 === 0 ? 1 : 0;
73
73
  prefix = originalText.substring(0, prefixLength);
74
74
  suffix = originalText.substring(originalText.length - suffixLength);
75
- ellipsizedText = `${prefix}${_ELLIPSIS_CHARACTER}${suffix}`;
76
- approximatedTextWidth = _getTextWidth(ellipsizedText, textFont);
75
+ ellipsizedText = `${prefix}${ELLIPSIS_CHARACTER}${suffix}`;
76
+ approximatedTextWidth = getTextWidth(ellipsizedText, textFont);
77
77
  attempt++;
78
- } while (attempt <= _ELLIPSIS_APPROXIMATION_THRESHOLD && approximatedTextWidth >= maxWidthInPx);
78
+ } while (attempt <= ELLIPSIS_APPROXIMATION_THRESHOLD && approximatedTextWidth >= maxWidthInPx);
79
79
  return ellipsizedText;
80
80
  }
81
81
  function getFontString(textFont) {
@@ -92,15 +92,15 @@ function getFontString(textFont) {
92
92
  )
93
93
  ).join(" ");
94
94
  }
95
- function _calculateEllipsisInfo(originalText, textFont, maxWidthInPx) {
95
+ function calculateEllipsisInfo(originalText, textFont, maxWidthInPx) {
96
96
  const originalTextLength = originalText.length;
97
97
  if (originalTextLength <= 1) {
98
98
  return null;
99
99
  }
100
- const textWidth = _getTextWidth(originalText, textFont);
100
+ const textWidth = getTextWidth(originalText, textFont);
101
101
  const avgLetterWidth = textWidth / originalTextLength;
102
102
  return textWidth > maxWidthInPx ? {
103
- ellipsisWidth: _getTextWidth(_ELLIPSIS_CHARACTER, textFont),
103
+ ellipsisWidth: getTextWidth(ELLIPSIS_CHARACTER, textFont),
104
104
  avgLetterWidth
105
105
  } : null;
106
106
  }