@dynatrace/strato-components 0.84.21 → 0.84.42
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/core/components/app-root/AppRoot.d.ts +9 -4
- package/core/components/app-root/AppRoot.js +6 -2
- package/core/contexts/FocusContext.d.ts +1 -1
- package/core/hooks/useCurrentTheme.d.ts +4 -1
- package/core/hooks/useFontsUpdated.d.ts +9 -0
- package/core/hooks/useFontsUpdated.js +51 -0
- package/core/hooks/useMergeRefs.d.ts +7 -0
- package/core/hooks/useMergeRefs.js +34 -0
- package/core/index.d.ts +5 -0
- package/core/styles/focusRing.css +88 -0
- package/core/styles/focusRing.sty.d.ts +96 -0
- package/core/styles/focusRing.sty.js +27 -0
- package/core/styles/useFocusRing.d.ts +49 -0
- package/core/styles/useFocusRing.js +83 -0
- package/core/types/a11y-props.d.ts +19 -0
- package/core/types/a11y-props.js +15 -0
- package/core/types/data-props.d.ts +1 -0
- package/core/types/dom.d.ts +19 -0
- package/core/types/dom.js +15 -0
- package/core/types/focusable-element.d.ts +5 -0
- package/core/types/focusable-element.js +15 -0
- package/core/types/heading.d.ts +9 -0
- package/core/types/heading.js +15 -0
- package/core/types/masking-props.d.ts +9 -0
- package/core/types/masking-props.js +15 -0
- package/core/types/polymorph.d.ts +25 -0
- package/core/types/polymorph.js +15 -0
- package/core/types/styling-props.d.ts +3 -2
- package/core/types/with-children.d.ts +4 -1
- package/core/utils/colorUtils.css +80 -0
- package/core/utils/colorUtils.sty.d.ts +48 -0
- package/core/utils/colorUtils.sty.js +27 -0
- package/esm/core/components/app-root/AppRoot.js +6 -2
- package/esm/core/components/app-root/AppRoot.js.map +2 -2
- package/esm/core/contexts/FocusContext.js.map +1 -1
- package/esm/core/hooks/useCurrentTheme.js.map +2 -2
- package/esm/core/hooks/useFontsUpdated.js +33 -0
- package/esm/core/hooks/useFontsUpdated.js.map +7 -0
- package/esm/core/hooks/useMergeRefs.js +16 -0
- package/esm/core/hooks/useMergeRefs.js.map +7 -0
- package/esm/core/index.js.map +2 -2
- package/esm/core/styles/focusRing.css +88 -0
- package/esm/core/styles/focusRing.sty.js +9 -0
- package/esm/core/styles/focusRing.sty.js.map +7 -0
- package/esm/core/styles/useFocusRing.js +69 -0
- package/esm/core/styles/useFocusRing.js.map +7 -0
- package/esm/core/types/a11y-props.js +1 -0
- package/esm/core/types/a11y-props.js.map +7 -0
- package/esm/core/types/dom.js +1 -0
- package/esm/core/types/dom.js.map +7 -0
- package/esm/core/types/focusable-element.js +1 -0
- package/esm/core/types/focusable-element.js.map +7 -0
- package/esm/core/types/heading.js +1 -0
- package/esm/core/types/heading.js.map +7 -0
- package/esm/core/types/masking-props.js +1 -0
- package/esm/core/types/masking-props.js.map +7 -0
- package/esm/core/types/polymorph.js +1 -0
- package/esm/core/types/polymorph.js.map +7 -0
- package/esm/core/utils/colorUtils.css +80 -0
- package/esm/core/utils/colorUtils.sty.js +9 -0
- package/esm/core/utils/colorUtils.sty.js.map +7 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +2 -2
- package/esm/layouts/Divider/Divider.css +23 -0
- package/esm/layouts/Divider/Divider.js +39 -0
- package/esm/layouts/Divider/Divider.js.map +7 -0
- package/esm/layouts/Divider/Divider.sty.js +8 -0
- package/esm/layouts/Divider/Divider.sty.js.map +7 -0
- package/esm/layouts/index.js +5 -0
- package/esm/layouts/index.js.map +7 -0
- package/esm/styles/textStyle.css +64 -0
- package/esm/styles/textStyle.sty.js +7 -0
- package/esm/styles/textStyle.sty.js.map +7 -0
- package/esm/typography/BlockQuote/Blockquote.css +17 -0
- package/esm/typography/BlockQuote/Blockquote.js +34 -0
- package/esm/typography/BlockQuote/Blockquote.js.map +7 -0
- package/esm/typography/BlockQuote/Blockquote.sty.js +6 -0
- package/esm/typography/BlockQuote/Blockquote.sty.js.map +7 -0
- package/esm/typography/Code/Code.css +16 -0
- package/esm/typography/Code/Code.js +34 -0
- package/esm/typography/Code/Code.js.map +7 -0
- package/esm/typography/Code/Code.sty.js +6 -0
- package/esm/typography/Code/Code.sty.js.map +7 -0
- package/esm/typography/Emphasis/Emphasis.css +4 -0
- package/esm/typography/Emphasis/Emphasis.js +34 -0
- package/esm/typography/Emphasis/Emphasis.js.map +7 -0
- package/esm/typography/Emphasis/Emphasis.sty.js +6 -0
- package/esm/typography/Emphasis/Emphasis.sty.js.map +7 -0
- package/esm/typography/ExternalLink/ExternalLink.css +28 -0
- package/esm/typography/ExternalLink/ExternalLink.js +56 -0
- package/esm/typography/ExternalLink/ExternalLink.js.map +7 -0
- package/esm/typography/ExternalLink/ExternalLink.sty.js +6 -0
- package/esm/typography/ExternalLink/ExternalLink.sty.js.map +7 -0
- package/esm/typography/Heading/Heading.css +54 -0
- package/esm/typography/Heading/Heading.js +36 -0
- package/esm/typography/Heading/Heading.js.map +7 -0
- package/esm/typography/Heading/Heading.sty.js +7 -0
- package/esm/typography/Heading/Heading.sty.js.map +7 -0
- package/esm/typography/Highlight/Highlight.css +4 -0
- package/esm/typography/Highlight/Highlight.js +111 -0
- package/esm/typography/Highlight/Highlight.js.map +7 -0
- package/esm/typography/Highlight/Highlight.sty.js +6 -0
- package/esm/typography/Highlight/Highlight.sty.js.map +7 -0
- package/esm/typography/Link/Link.css +15 -0
- package/esm/typography/Link/Link.js +49 -0
- package/esm/typography/Link/Link.js.map +7 -0
- package/esm/typography/Link/Link.sty.js +6 -0
- package/esm/typography/Link/Link.sty.js.map +7 -0
- package/esm/typography/List/List.css +16 -0
- package/esm/typography/List/List.js +81 -0
- package/esm/typography/List/List.js.map +7 -0
- package/esm/typography/List/List.sty.js +8 -0
- package/esm/typography/List/List.sty.js.map +7 -0
- package/esm/typography/Paragraph/Paragraph.css +19 -0
- package/esm/typography/Paragraph/Paragraph.js +49 -0
- package/esm/typography/Paragraph/Paragraph.js.map +7 -0
- package/esm/typography/Paragraph/Paragraph.sty.js +7 -0
- package/esm/typography/Paragraph/Paragraph.sty.js.map +7 -0
- package/esm/typography/Strikethrough/Strikethrough.css +5 -0
- package/esm/typography/Strikethrough/Strikethrough.js +32 -0
- package/esm/typography/Strikethrough/Strikethrough.js.map +7 -0
- package/esm/typography/Strikethrough/Strikethrough.sty.js +6 -0
- package/esm/typography/Strikethrough/Strikethrough.sty.js.map +7 -0
- package/esm/typography/Strong/Strong.css +4 -0
- package/esm/typography/Strong/Strong.js +34 -0
- package/esm/typography/Strong/Strong.js.map +7 -0
- package/esm/typography/Strong/Strong.sty.js +6 -0
- package/esm/typography/Strong/Strong.sty.js.map +7 -0
- package/esm/typography/Text/Text.css +18 -0
- package/esm/typography/Text/Text.js +43 -0
- package/esm/typography/Text/Text.js.map +7 -0
- package/esm/typography/Text/Text.sty.js +7 -0
- package/esm/typography/Text/Text.sty.js.map +7 -0
- package/esm/typography/TextEllipsis/TextEllipsis.css +22 -0
- package/esm/typography/TextEllipsis/TextEllipsis.js +143 -0
- package/esm/typography/TextEllipsis/TextEllipsis.js.map +7 -0
- package/esm/typography/TextEllipsis/TextEllipsis.sty.js +7 -0
- package/esm/typography/TextEllipsis/TextEllipsis.sty.js.map +7 -0
- package/esm/typography/index.js +43 -0
- package/esm/typography/index.js.map +7 -0
- package/esm/typography/utils.js +101 -0
- package/esm/typography/utils.js.map +7 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/lang/en.json +6 -0
- package/lang/uncompiled/en.json +6 -1
- package/layouts/Divider/Divider.css +23 -0
- package/layouts/Divider/Divider.d.ts +39 -0
- package/layouts/Divider/Divider.js +67 -0
- package/layouts/Divider/Divider.sty.d.ts +16 -0
- package/layouts/Divider/Divider.sty.js +26 -0
- package/layouts/index.d.ts +2 -0
- package/layouts/index.js +23 -0
- package/package.json +17 -2
- package/styles/textStyle.css +64 -0
- package/styles/textStyle.sty.d.ts +12 -0
- package/styles/textStyle.sty.js +25 -0
- package/testing/custom-render.d.ts +1 -1
- package/testing/mocks/resize-observer-mock.d.ts +1 -1
- package/testing/mocks/text-ellipsis-mock.d.ts +1 -1
- package/testing/mocks/text-ellipsis-mock.js +8 -3
- package/typography/BlockQuote/Blockquote.css +17 -0
- package/typography/BlockQuote/Blockquote.d.ts +19 -0
- package/typography/BlockQuote/Blockquote.js +62 -0
- package/typography/BlockQuote/Blockquote.sty.d.ts +1 -0
- package/typography/BlockQuote/Blockquote.sty.js +24 -0
- package/typography/Code/Code.css +16 -0
- package/typography/Code/Code.d.ts +17 -0
- package/typography/Code/Code.js +62 -0
- package/typography/Code/Code.sty.d.ts +1 -0
- package/typography/Code/Code.sty.js +24 -0
- package/typography/Emphasis/Emphasis.css +4 -0
- package/typography/Emphasis/Emphasis.d.ts +14 -0
- package/typography/Emphasis/Emphasis.js +62 -0
- package/typography/Emphasis/Emphasis.sty.d.ts +1 -0
- package/typography/Emphasis/Emphasis.sty.js +24 -0
- package/typography/ExternalLink/ExternalLink.css +28 -0
- package/typography/ExternalLink/ExternalLink.d.ts +21 -0
- package/typography/ExternalLink/ExternalLink.js +82 -0
- package/typography/ExternalLink/ExternalLink.sty.d.ts +1 -0
- package/typography/ExternalLink/ExternalLink.sty.js +24 -0
- package/typography/Heading/Heading.css +54 -0
- package/typography/Heading/Heading.d.ts +24 -0
- package/typography/Heading/Heading.js +64 -0
- package/typography/Heading/Heading.sty.d.ts +52 -0
- package/typography/Heading/Heading.sty.js +25 -0
- package/typography/Highlight/Highlight.css +4 -0
- package/typography/Highlight/Highlight.d.ts +27 -0
- package/typography/Highlight/Highlight.js +139 -0
- package/typography/Highlight/Highlight.sty.d.ts +1 -0
- package/typography/Highlight/Highlight.sty.js +24 -0
- package/typography/Link/Link.css +15 -0
- package/typography/Link/Link.d.ts +17 -0
- package/typography/Link/Link.js +75 -0
- package/typography/Link/Link.sty.d.ts +1 -0
- package/typography/Link/Link.sty.js +24 -0
- package/typography/List/List.css +16 -0
- package/typography/List/List.d.ts +39 -0
- package/typography/List/List.js +109 -0
- package/typography/List/List.sty.d.ts +2 -0
- package/typography/List/List.sty.js +26 -0
- package/typography/Paragraph/Paragraph.css +19 -0
- package/typography/Paragraph/Paragraph.d.ts +19 -0
- package/typography/Paragraph/Paragraph.js +77 -0
- package/typography/Paragraph/Paragraph.sty.d.ts +16 -0
- package/typography/Paragraph/Paragraph.sty.js +25 -0
- package/typography/Strikethrough/Strikethrough.css +5 -0
- package/typography/Strikethrough/Strikethrough.d.ts +15 -0
- package/typography/Strikethrough/Strikethrough.js +60 -0
- package/typography/Strikethrough/Strikethrough.sty.d.ts +1 -0
- package/typography/Strikethrough/Strikethrough.sty.js +24 -0
- package/typography/Strong/Strong.css +4 -0
- package/typography/Strong/Strong.d.ts +14 -0
- package/typography/Strong/Strong.js +62 -0
- package/typography/Strong/Strong.sty.d.ts +1 -0
- package/typography/Strong/Strong.sty.js +24 -0
- package/typography/Text/Text.css +18 -0
- package/typography/Text/Text.d.ts +26 -0
- package/typography/Text/Text.js +71 -0
- package/typography/Text/Text.sty.d.ts +16 -0
- package/typography/Text/Text.sty.js +25 -0
- package/typography/TextEllipsis/TextEllipsis.css +22 -0
- package/typography/TextEllipsis/TextEllipsis.d.ts +32 -0
- package/typography/TextEllipsis/TextEllipsis.js +167 -0
- package/typography/TextEllipsis/TextEllipsis.sty.d.ts +15 -0
- package/typography/TextEllipsis/TextEllipsis.sty.js +25 -0
- package/typography/index.d.ts +28 -0
- package/typography/index.js +54 -0
- package/typography/utils.d.ts +52 -0
- package/typography/utils.js +119 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var TextEllipsis_exports = {};
|
|
29
|
+
__export(TextEllipsis_exports, {
|
|
30
|
+
TextEllipsis: () => TextEllipsis
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(TextEllipsis_exports);
|
|
33
|
+
var import_clsx = __toESM(require("clsx"));
|
|
34
|
+
var import_react = __toESM(require("react"));
|
|
35
|
+
var import_use_resize_observer = __toESM(require("use-resize-observer"));
|
|
36
|
+
var import_TextEllipsis_css = require("./TextEllipsis.sty.js");
|
|
37
|
+
var import_useFontsUpdated = require("../../core/hooks/useFontsUpdated.js");
|
|
38
|
+
var import_useMergeRefs = require("../../core/hooks/useMergeRefs.js");
|
|
39
|
+
var import_utils = require("../utils.js");
|
|
40
|
+
function getFontProps(textWrapper) {
|
|
41
|
+
const computedStyle = window.getComputedStyle(textWrapper, null);
|
|
42
|
+
return {
|
|
43
|
+
fontStyle: computedStyle.getPropertyValue("font-style"),
|
|
44
|
+
fontWeight: computedStyle.getPropertyValue("font-weight"),
|
|
45
|
+
fontSize: computedStyle.getPropertyValue("font-size"),
|
|
46
|
+
fontFamily: computedStyle.getPropertyValue("font-family")
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function isNativeEllipsisActive(textWrapper, containerWidth) {
|
|
50
|
+
const textWidth = Math.floor(textWrapper.getBoundingClientRect().width * 100) / 100;
|
|
51
|
+
return textWidth > containerWidth;
|
|
52
|
+
}
|
|
53
|
+
function renderEllipsizedText(originalText, truncationMode, containerRef, wasEllipsized, onTextOverflow) {
|
|
54
|
+
const containerElement = containerRef.current;
|
|
55
|
+
const textWrapper = containerElement?.firstElementChild || null;
|
|
56
|
+
if (containerElement !== null && textWrapper !== null) {
|
|
57
|
+
if (textWrapper.textContent !== originalText) {
|
|
58
|
+
textWrapper.textContent = originalText;
|
|
59
|
+
}
|
|
60
|
+
const containerWidth = Math.ceil(containerElement.getBoundingClientRect().width * 100) / 100;
|
|
61
|
+
if (truncationMode === "middle") {
|
|
62
|
+
if (isNativeEllipsisActive(textWrapper, containerWidth)) {
|
|
63
|
+
const ellipsizedText = (0, import_utils._centerEllipsizeText)(
|
|
64
|
+
originalText,
|
|
65
|
+
getFontProps(textWrapper),
|
|
66
|
+
containerWidth
|
|
67
|
+
);
|
|
68
|
+
textWrapper.textContent = ellipsizedText;
|
|
69
|
+
if (ellipsizedText !== originalText) {
|
|
70
|
+
if (onTextOverflow && !wasEllipsized) {
|
|
71
|
+
onTextOverflow(true);
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (onTextOverflow && wasEllipsized) {
|
|
77
|
+
onTextOverflow(false);
|
|
78
|
+
}
|
|
79
|
+
} else if (isNativeEllipsisActive(textWrapper, containerWidth)) {
|
|
80
|
+
if (onTextOverflow && !wasEllipsized) {
|
|
81
|
+
onTextOverflow(true);
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
} else if (onTextOverflow && wasEllipsized) {
|
|
85
|
+
onTextOverflow(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const ComputedTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
91
|
+
const {
|
|
92
|
+
children,
|
|
93
|
+
truncationMode = "end",
|
|
94
|
+
onTextOverflow,
|
|
95
|
+
className: consumerClassName,
|
|
96
|
+
style: consumerStyle,
|
|
97
|
+
"data-testid": dataTestId,
|
|
98
|
+
"data-dtrum-mask": dataDtrumMask,
|
|
99
|
+
"data-dtrum-allow": dataDtrumAllow,
|
|
100
|
+
...remainingProps
|
|
101
|
+
} = props;
|
|
102
|
+
const { ref: observerContainerRef } = (0, import_use_resize_observer.default)();
|
|
103
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
104
|
+
const ellipsisStateRef = (0, import_react.useRef)(false);
|
|
105
|
+
const mergedRef = (0, import_useMergeRefs.useMergeRefs)([
|
|
106
|
+
observerContainerRef,
|
|
107
|
+
(instance) => {
|
|
108
|
+
containerRef.current = instance;
|
|
109
|
+
},
|
|
110
|
+
forwardedRef
|
|
111
|
+
]);
|
|
112
|
+
const containerWidth = containerRef.current?.getBoundingClientRect().width;
|
|
113
|
+
const fontsUpdated = (0, import_useFontsUpdated._useFontsUpdated)();
|
|
114
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
115
|
+
ellipsisStateRef.current = renderEllipsizedText(
|
|
116
|
+
children,
|
|
117
|
+
truncationMode,
|
|
118
|
+
containerRef,
|
|
119
|
+
ellipsisStateRef.current,
|
|
120
|
+
onTextOverflow
|
|
121
|
+
);
|
|
122
|
+
}, [containerWidth, children, truncationMode, fontsUpdated, onTextOverflow]);
|
|
123
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
124
|
+
"span",
|
|
125
|
+
{
|
|
126
|
+
ref: mergedRef,
|
|
127
|
+
"aria-label": children,
|
|
128
|
+
"data-ellipsis": true,
|
|
129
|
+
"data-testid": dataTestId,
|
|
130
|
+
"data-dtrum-mask": dataDtrumMask,
|
|
131
|
+
"data-dtrum-allow": dataDtrumAllow,
|
|
132
|
+
className: (0, import_clsx.default)((0, import_TextEllipsis_css.textEllipsisCSS)({ truncationMode }), consumerClassName),
|
|
133
|
+
style: consumerStyle,
|
|
134
|
+
...remainingProps
|
|
135
|
+
},
|
|
136
|
+
/* @__PURE__ */ import_react.default.createElement("span", null, children)
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
const CssTextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
140
|
+
const {
|
|
141
|
+
children,
|
|
142
|
+
truncationMode = "end",
|
|
143
|
+
onTextOverflow,
|
|
144
|
+
className: consumerClassName,
|
|
145
|
+
style: consumerStyle,
|
|
146
|
+
"data-testid": dataTestId,
|
|
147
|
+
...remainingProps
|
|
148
|
+
} = props;
|
|
149
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
150
|
+
"span",
|
|
151
|
+
{
|
|
152
|
+
ref: forwardedRef,
|
|
153
|
+
"aria-label": children,
|
|
154
|
+
"data-ellipsis": true,
|
|
155
|
+
"data-testid": dataTestId,
|
|
156
|
+
className: (0, import_clsx.default)((0, import_TextEllipsis_css.textEllipsisCSS)({ truncationMode }), consumerClassName),
|
|
157
|
+
style: consumerStyle,
|
|
158
|
+
...remainingProps
|
|
159
|
+
},
|
|
160
|
+
/* @__PURE__ */ import_react.default.createElement("span", null, children)
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
const TextEllipsis = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
164
|
+
const cssOnlyEllipsis = !props.onTextOverflow && props.truncationMode !== "middle";
|
|
165
|
+
return cssOnlyEllipsis ? /* @__PURE__ */ import_react.default.createElement(CssTextEllipsis, { ref: forwardedRef, ...props }) : /* @__PURE__ */ import_react.default.createElement(ComputedTextEllipsis, { ref: forwardedRef, ...props });
|
|
166
|
+
});
|
|
167
|
+
TextEllipsis.displayName = "TextEllipsis";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const textEllipsisCSS: import("@vanilla-extract/recipes").RuntimeFn<{
|
|
2
|
+
truncationMode: {
|
|
3
|
+
start: {
|
|
4
|
+
textOverflow: "ellipsis";
|
|
5
|
+
direction: "rtl";
|
|
6
|
+
textAlign: "left";
|
|
7
|
+
};
|
|
8
|
+
middle: {
|
|
9
|
+
textOverflow: "clip";
|
|
10
|
+
};
|
|
11
|
+
end: {
|
|
12
|
+
textOverflow: "ellipsis";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var TextEllipsis_css_exports = {};
|
|
19
|
+
__export(TextEllipsis_css_exports, {
|
|
20
|
+
textEllipsisCSS: () => textEllipsisCSS
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(TextEllipsis_css_exports);
|
|
23
|
+
var import_TextEllipsis_css_ts_vanilla = require("./TextEllipsis.css");
|
|
24
|
+
var import_createRuntimeFn = require("@vanilla-extract/recipes/createRuntimeFn");
|
|
25
|
+
var textEllipsisCSS = (0, import_createRuntimeFn.createRuntimeFn)({ defaultClassName: "TextEllipsis_textEllipsisCSS__1n6xzhd0", variantClassNames: { truncationMode: { start: "TextEllipsis_textEllipsisCSS_truncationMode_start__1n6xzhd1", middle: "TextEllipsis_textEllipsisCSS_truncationMode_middle__1n6xzhd2", end: "TextEllipsis_textEllipsisCSS_truncationMode_end__1n6xzhd3" } }, defaultVariants: {}, compoundVariants: [] });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Blockquote } from './BlockQuote/Blockquote.js';
|
|
2
|
+
export type { BlockquoteProps } from './BlockQuote/Blockquote.js';
|
|
3
|
+
export { Code } from './Code/Code.js';
|
|
4
|
+
export type { CodeProps } from './Code/Code.js';
|
|
5
|
+
export { Emphasis } from './Emphasis/Emphasis.js';
|
|
6
|
+
export type { EmphasisProps } from './Emphasis/Emphasis.js';
|
|
7
|
+
export { ExternalLink } from './ExternalLink/ExternalLink.js';
|
|
8
|
+
export type { ExternalLinkProps } from './ExternalLink/ExternalLink.js';
|
|
9
|
+
export { Heading } from './Heading/Heading.js';
|
|
10
|
+
export type { HeadingProps } from './Heading/Heading.js';
|
|
11
|
+
export { Highlight } from './Highlight/Highlight.js';
|
|
12
|
+
export type { HighlightProps } from './Highlight/Highlight.js';
|
|
13
|
+
export { Link } from './Link/Link.js';
|
|
14
|
+
export type { LinkProps } from './Link/Link.js';
|
|
15
|
+
export { List } from './List/List.js';
|
|
16
|
+
export type { ListProps } from './List/List.js';
|
|
17
|
+
export { Paragraph } from './Paragraph/Paragraph.js';
|
|
18
|
+
export type { ParagraphProps } from './Paragraph/Paragraph.js';
|
|
19
|
+
export { Strikethrough } from './Strikethrough/Strikethrough.js';
|
|
20
|
+
export type { StrikethroughProps } from './Strikethrough/Strikethrough.js';
|
|
21
|
+
export { Strong } from './Strong/Strong.js';
|
|
22
|
+
export type { StrongProps } from './Strong/Strong.js';
|
|
23
|
+
export { Text } from './Text/Text.js';
|
|
24
|
+
export type { TextOwnProps, TextProps } from './Text/Text.js';
|
|
25
|
+
export { TextEllipsis } from './TextEllipsis/TextEllipsis.js';
|
|
26
|
+
export type { TextEllipsisProps, _TruncationMode, } from './TextEllipsis/TextEllipsis.js';
|
|
27
|
+
export { _calculateEllipsisInfo, _getTextHeight, _centerEllipsizeText, _getTextWidth, _ELLIPSIS_APPROXIMATION_THRESHOLD, _ELLIPSIS_CHARACTER, } from './utils.js';
|
|
28
|
+
export type { _Font } from './utils.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var typography_exports = {};
|
|
19
|
+
__export(typography_exports, {
|
|
20
|
+
Blockquote: () => import_Blockquote.Blockquote,
|
|
21
|
+
Code: () => import_Code.Code,
|
|
22
|
+
Emphasis: () => import_Emphasis.Emphasis,
|
|
23
|
+
ExternalLink: () => import_ExternalLink.ExternalLink,
|
|
24
|
+
Heading: () => import_Heading.Heading,
|
|
25
|
+
Highlight: () => import_Highlight.Highlight,
|
|
26
|
+
Link: () => import_Link.Link,
|
|
27
|
+
List: () => import_List.List,
|
|
28
|
+
Paragraph: () => import_Paragraph.Paragraph,
|
|
29
|
+
Strikethrough: () => import_Strikethrough.Strikethrough,
|
|
30
|
+
Strong: () => import_Strong.Strong,
|
|
31
|
+
Text: () => import_Text.Text,
|
|
32
|
+
TextEllipsis: () => import_TextEllipsis.TextEllipsis,
|
|
33
|
+
_ELLIPSIS_APPROXIMATION_THRESHOLD: () => import_utils._ELLIPSIS_APPROXIMATION_THRESHOLD,
|
|
34
|
+
_ELLIPSIS_CHARACTER: () => import_utils._ELLIPSIS_CHARACTER,
|
|
35
|
+
_calculateEllipsisInfo: () => import_utils._calculateEllipsisInfo,
|
|
36
|
+
_centerEllipsizeText: () => import_utils._centerEllipsizeText,
|
|
37
|
+
_getTextHeight: () => import_utils._getTextHeight,
|
|
38
|
+
_getTextWidth: () => import_utils._getTextWidth
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(typography_exports);
|
|
41
|
+
var import_Blockquote = require("./BlockQuote/Blockquote.js");
|
|
42
|
+
var import_Code = require("./Code/Code.js");
|
|
43
|
+
var import_Emphasis = require("./Emphasis/Emphasis.js");
|
|
44
|
+
var import_ExternalLink = require("./ExternalLink/ExternalLink.js");
|
|
45
|
+
var import_Heading = require("./Heading/Heading.js");
|
|
46
|
+
var import_Highlight = require("./Highlight/Highlight.js");
|
|
47
|
+
var import_Link = require("./Link/Link.js");
|
|
48
|
+
var import_List = require("./List/List.js");
|
|
49
|
+
var import_Paragraph = require("./Paragraph/Paragraph.js");
|
|
50
|
+
var import_Strikethrough = require("./Strikethrough/Strikethrough.js");
|
|
51
|
+
var import_Strong = require("./Strong/Strong.js");
|
|
52
|
+
var import_Text = require("./Text/Text.js");
|
|
53
|
+
var import_TextEllipsis = require("./TextEllipsis/TextEllipsis.js");
|
|
54
|
+
var import_utils = require("./utils.js");
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Properties describing how a piece of text is formatted. */
|
|
4
|
+
export type _Font = {
|
|
5
|
+
fontStyle?: string;
|
|
6
|
+
fontWeight?: string;
|
|
7
|
+
fontSize: string;
|
|
8
|
+
fontFamily: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* The Unicode character representing an ellipsis. */
|
|
13
|
+
export declare const _ELLIPSIS_CHARACTER = "\u2026";
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* Max iterations for finding the perfect truncated text for a given width */
|
|
17
|
+
export declare const _ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the width of formatted text in pixels.
|
|
20
|
+
*
|
|
21
|
+
* @param text - The text to calculate the width of
|
|
22
|
+
* @param textFont - The font settings for the text
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function _getTextWidth(text: string, textFont: _Font): number;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
* Calculates the height of formatted text in pixels.
|
|
29
|
+
* @param text - The text to calculate the height of
|
|
30
|
+
* @param textFont - The font settings for the text
|
|
31
|
+
*/
|
|
32
|
+
export declare function _getTextHeight(text: string, textFont: _Font): number;
|
|
33
|
+
/**
|
|
34
|
+
* Cuts off text that exceeds the maximum width in the center and
|
|
35
|
+
* concatenates both shortened ends of the text with an ellipsis.
|
|
36
|
+
*
|
|
37
|
+
* @param originalText - The text to be truncated if its width exceeds <code>maxWidthInPx</code>
|
|
38
|
+
* @param textFont - Different font settings to be considered when determining the width of the text
|
|
39
|
+
* @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
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export declare function _centerEllipsizeText(originalText: string, textFont: _Font, maxWidthInPx: number): string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns an object containing the width of a given formatted text and the
|
|
45
|
+
* width of an ellipsis character with the same text format or `null`
|
|
46
|
+
* if the text width does not exceed its maximum available width.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare function _calculateEllipsisInfo(originalText: string, textFont: _Font, maxWidthInPx: number): {
|
|
50
|
+
ellipsisWidth: number;
|
|
51
|
+
avgLetterWidth: number;
|
|
52
|
+
} | null;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var utils_exports = {};
|
|
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
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
const _ELLIPSIS_CHARACTER = "\u2026";
|
|
29
|
+
const _ELLIPSIS_APPROXIMATION_THRESHOLD = 15;
|
|
30
|
+
let inMemContext2d;
|
|
31
|
+
function _getTextWidth(text, textFont) {
|
|
32
|
+
const context = getCanvasContext2d();
|
|
33
|
+
context.font = getFontString(textFont);
|
|
34
|
+
const textMetrics = context.measureText(text);
|
|
35
|
+
if (textMetrics.width < 0) {
|
|
36
|
+
return textMetrics.width;
|
|
37
|
+
}
|
|
38
|
+
const actualTextWidth = Math.abs(textMetrics.actualBoundingBoxLeft) + Math.abs(textMetrics.actualBoundingBoxRight);
|
|
39
|
+
return Math.ceil(actualTextWidth);
|
|
40
|
+
}
|
|
41
|
+
function _getTextHeight(text, textFont) {
|
|
42
|
+
const context = getCanvasContext2d();
|
|
43
|
+
context.font = getFontString(textFont);
|
|
44
|
+
const textMetrics = context.measureText(text);
|
|
45
|
+
const actualTextHeight = Math.abs(textMetrics.actualBoundingBoxAscent) + Math.abs(textMetrics.actualBoundingBoxDescent);
|
|
46
|
+
return Math.ceil(actualTextHeight);
|
|
47
|
+
}
|
|
48
|
+
function _centerEllipsizeText(originalText, textFont, maxWidthInPx) {
|
|
49
|
+
const ellipsisInfo = _calculateEllipsisInfo(
|
|
50
|
+
originalText,
|
|
51
|
+
textFont,
|
|
52
|
+
maxWidthInPx
|
|
53
|
+
);
|
|
54
|
+
if (ellipsisInfo === null) {
|
|
55
|
+
return originalText;
|
|
56
|
+
}
|
|
57
|
+
const { ellipsisWidth, avgLetterWidth } = ellipsisInfo;
|
|
58
|
+
const availableTextWidth = maxWidthInPx - ellipsisWidth;
|
|
59
|
+
if (availableTextWidth <= ellipsisWidth) {
|
|
60
|
+
return _ELLIPSIS_CHARACTER;
|
|
61
|
+
}
|
|
62
|
+
const initialPrefixSuffixLength = Math.floor(availableTextWidth / avgLetterWidth / 2) + 1;
|
|
63
|
+
let prefix;
|
|
64
|
+
let suffix;
|
|
65
|
+
let ellipsizedText;
|
|
66
|
+
let approximatedTextWidth;
|
|
67
|
+
let attempt = 1;
|
|
68
|
+
let prefixLength = initialPrefixSuffixLength;
|
|
69
|
+
let suffixLength = initialPrefixSuffixLength;
|
|
70
|
+
do {
|
|
71
|
+
prefixLength -= attempt % 2 === 1 ? 1 : 0;
|
|
72
|
+
suffixLength -= attempt % 2 === 0 ? 1 : 0;
|
|
73
|
+
prefix = originalText.substring(0, prefixLength);
|
|
74
|
+
suffix = originalText.substring(originalText.length - suffixLength);
|
|
75
|
+
ellipsizedText = `${prefix}${_ELLIPSIS_CHARACTER}${suffix}`;
|
|
76
|
+
approximatedTextWidth = _getTextWidth(ellipsizedText, textFont);
|
|
77
|
+
attempt++;
|
|
78
|
+
} while (attempt <= _ELLIPSIS_APPROXIMATION_THRESHOLD && approximatedTextWidth >= maxWidthInPx);
|
|
79
|
+
return ellipsizedText;
|
|
80
|
+
}
|
|
81
|
+
function getFontString(textFont) {
|
|
82
|
+
const { fontStyle, fontWeight, fontSize, fontFamily } = textFont;
|
|
83
|
+
return [
|
|
84
|
+
fontStyle === "normal" ? "" : fontStyle,
|
|
85
|
+
fontWeight === "400" ? "" : fontWeight,
|
|
86
|
+
fontSize,
|
|
87
|
+
fontFamily
|
|
88
|
+
].filter((value) => value !== void 0 && value !== "").map(
|
|
89
|
+
(value) => (
|
|
90
|
+
// we need to resolve CSS variables manually because they are not supported by the canvas API
|
|
91
|
+
value?.trim().startsWith("var(") ? value.replace(/^\s*var\(--[0-9A-Za-z-]+,\s*([^)]+)\)\s*$/, "$1") : value
|
|
92
|
+
)
|
|
93
|
+
).join(" ");
|
|
94
|
+
}
|
|
95
|
+
function _calculateEllipsisInfo(originalText, textFont, maxWidthInPx) {
|
|
96
|
+
const originalTextLength = originalText.length;
|
|
97
|
+
if (originalTextLength <= 1) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const textWidth = _getTextWidth(originalText, textFont);
|
|
101
|
+
const avgLetterWidth = textWidth / originalTextLength;
|
|
102
|
+
return textWidth > maxWidthInPx ? {
|
|
103
|
+
ellipsisWidth: _getTextWidth(_ELLIPSIS_CHARACTER, textFont),
|
|
104
|
+
avgLetterWidth
|
|
105
|
+
} : null;
|
|
106
|
+
}
|
|
107
|
+
function getCanvasContext2d() {
|
|
108
|
+
if (!inMemContext2d) {
|
|
109
|
+
const context = document.createElement("canvas").getContext("2d");
|
|
110
|
+
if (context !== null) {
|
|
111
|
+
context.imageSmoothingEnabled = false;
|
|
112
|
+
context.imageSmoothingQuality = "low";
|
|
113
|
+
inMemContext2d = context;
|
|
114
|
+
} else {
|
|
115
|
+
throw new Error("Failed to create a Canvas 2D context");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return inMemContext2d;
|
|
119
|
+
}
|