@stackone/malachite 2.107.0 → 2.108.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ShadowRootWrapper.js +43 -36
- package/dist/ShadowRootWrapper.js.map +1 -1
- package/dist/components/CodeBlock.js +2 -2
- package/dist/components/CodeBlock.js.map +1 -1
- package/dist/components/CommandPalette.js +64 -62
- package/dist/components/CommandPalette.js.map +1 -1
- package/dist/components/MalachiteContext.js +11 -9
- package/dist/components/MalachiteContext.js.map +1 -1
- package/dist/components/Surface.js +2 -2
- package/dist/components/Surface.js.map +1 -1
- package/dist/components/Toolbar.js +2 -2
- package/dist/components/Toolbar.js.map +1 -1
- package/dist/components/Tooltip.js +130 -129
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/components/Typography/Text.js +21 -19
- package/dist/components/Typography/Text.js.map +1 -1
- package/dist/fontInjection.js +21 -0
- package/dist/fontInjection.js.map +1 -0
- package/dist/geist-font.js +10 -16
- package/dist/geist-font.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/inter-font.js +21 -27
- package/dist/inter-font.js.map +1 -1
- package/dist/stack-sans-font.js +5 -11
- package/dist/stack-sans-font.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
|
@@ -1,89 +1,90 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { createPortal as
|
|
4
|
-
import { FOCUS_RING as
|
|
5
|
-
import { ensureOverlayStyles as
|
|
6
|
-
import { useTopLayer as
|
|
7
|
-
import { useFollowTrigger as
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
/* @__PURE__ */
|
|
11
|
-
] },
|
|
1
|
+
import { jsx as p, jsxs as D, Fragment as dt } from "react/jsx-runtime";
|
|
2
|
+
import B, { useState as v, useRef as m, useCallback as K, useId as ut, useEffect as w, useInsertionEffect as mt } from "react";
|
|
3
|
+
import { createPortal as pt } from "react-dom";
|
|
4
|
+
import { FOCUS_RING as ht } from "./focusRing.js";
|
|
5
|
+
import { ensureOverlayStyles as gt, overlayIdentity as bt } from "./portalOverlay.js";
|
|
6
|
+
import { useTopLayer as yt } from "./topLayer.js";
|
|
7
|
+
import { useFollowTrigger as vt } from "./useFollowTrigger.js";
|
|
8
|
+
const wt = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), xt = (o) => o.split(wt).map((s, R) => /* @__PURE__ */ D(B.Fragment, { children: [
|
|
9
|
+
s,
|
|
10
|
+
/* @__PURE__ */ p("wbr", {})
|
|
11
|
+
] }, R)), Rt = {
|
|
12
12
|
minWidth: 0,
|
|
13
13
|
overflow: "hidden"
|
|
14
|
-
},
|
|
14
|
+
}, X = {
|
|
15
15
|
flex: 1,
|
|
16
16
|
minWidth: 0
|
|
17
|
-
},
|
|
18
|
-
text:
|
|
19
|
-
children:
|
|
20
|
-
delay:
|
|
21
|
-
wrapChildren:
|
|
22
|
-
triggerAs:
|
|
23
|
-
inline:
|
|
24
|
-
placement:
|
|
25
|
-
isShrinkable:
|
|
26
|
-
maxWidth:
|
|
27
|
-
fill:
|
|
28
|
-
shouldShow:
|
|
29
|
-
suppressed:
|
|
30
|
-
describesTrigger:
|
|
31
|
-
showOnFocus:
|
|
32
|
-
focusableTrigger:
|
|
17
|
+
}, x = 8, It = '"Inter", ui-sans-serif, system-ui, sans-serif', Mt = ({
|
|
18
|
+
text: o,
|
|
19
|
+
children: s,
|
|
20
|
+
delay: R = 1,
|
|
21
|
+
wrapChildren: J = !1,
|
|
22
|
+
triggerAs: Q = "div",
|
|
23
|
+
inline: M = !1,
|
|
24
|
+
placement: I = "top",
|
|
25
|
+
isShrinkable: W = !1,
|
|
26
|
+
maxWidth: E = "320px",
|
|
27
|
+
fill: S = !1,
|
|
28
|
+
shouldShow: h,
|
|
29
|
+
suppressed: i = !1,
|
|
30
|
+
describesTrigger: $ = !0,
|
|
31
|
+
showOnFocus: f = !0,
|
|
32
|
+
focusableTrigger: g = !1
|
|
33
33
|
}) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
}, []),
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const Z = W || S ? { ...W ? Rt : {}, ...S ? X : {} } : void 0, [e, d] = v(!1), [tt, et] = v(!1), b = tt || g, y = m(null), a = m(null), n = K(() => {
|
|
35
|
+
y.current && (clearTimeout(y.current), y.current = null), a.current !== null && (cancelAnimationFrame(a.current), a.current = null);
|
|
36
|
+
}, []), P = () => {
|
|
37
|
+
et(!0), a.current !== null && cancelAnimationFrame(a.current), a.current = requestAnimationFrame(() => {
|
|
38
|
+
a.current = null, d(!0);
|
|
39
39
|
});
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
!
|
|
50
|
-
},
|
|
51
|
-
n(),
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
const
|
|
56
|
-
|
|
40
|
+
}, L = m(null), u = m(null);
|
|
41
|
+
yt(L, e);
|
|
42
|
+
const C = ut(), l = o != null && o !== "" && o !== !1, nt = (t) => {
|
|
43
|
+
t.stopPropagation(), !(!l || i || h && !h()) && (n(), y.current = setTimeout(() => {
|
|
44
|
+
P();
|
|
45
|
+
}, R * 1e3));
|
|
46
|
+
}, ot = (t) => {
|
|
47
|
+
t.stopPropagation(), n(), d(!1);
|
|
48
|
+
}, H = () => {
|
|
49
|
+
!f || !l || i || h && !h() || (n(), P());
|
|
50
|
+
}, it = () => {
|
|
51
|
+
n(), d(!1);
|
|
52
|
+
}, N = m(f);
|
|
53
|
+
w(() => {
|
|
54
|
+
var r;
|
|
55
|
+
const t = f && !N.current;
|
|
56
|
+
N.current = f, t && ((r = u.current) != null && r.matches(":focus-within")) && H();
|
|
57
57
|
});
|
|
58
|
-
const [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [
|
|
62
|
-
const [,
|
|
63
|
-
n(),
|
|
58
|
+
const [rt, st] = v(i);
|
|
59
|
+
i !== rt && (st(i), i && d(!1)), w(() => {
|
|
60
|
+
i && n();
|
|
61
|
+
}, [i, n]);
|
|
62
|
+
const [, T] = v({}), at = K(() => {
|
|
63
|
+
n(), d(!1);
|
|
64
64
|
}, [n]);
|
|
65
|
-
|
|
66
|
-
if (!
|
|
65
|
+
vt(e, u, () => T({}), at), w(() => {
|
|
66
|
+
if (!e)
|
|
67
67
|
return () => {
|
|
68
68
|
n();
|
|
69
69
|
};
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const t = () => {
|
|
71
|
+
T({});
|
|
72
72
|
};
|
|
73
|
-
return window.addEventListener("resize",
|
|
74
|
-
n(), window.removeEventListener("resize",
|
|
73
|
+
return window.addEventListener("resize", t), () => {
|
|
74
|
+
n(), window.removeEventListener("resize", t);
|
|
75
75
|
};
|
|
76
|
-
}, [
|
|
77
|
-
|
|
78
|
-
}, [
|
|
79
|
-
const
|
|
80
|
-
|
|
76
|
+
}, [e, n]), w(() => {
|
|
77
|
+
e && T({});
|
|
78
|
+
}, [e]);
|
|
79
|
+
const lt = () => {
|
|
80
|
+
var z;
|
|
81
|
+
if (!u.current)
|
|
81
82
|
return { display: "none" };
|
|
82
|
-
const
|
|
83
|
+
const t = u.current.getBoundingClientRect(), r = {
|
|
83
84
|
position: "fixed",
|
|
84
85
|
display: "flex",
|
|
85
86
|
width: "max-content",
|
|
86
|
-
maxWidth: typeof
|
|
87
|
+
maxWidth: typeof E == "number" ? `${E}px` : E,
|
|
87
88
|
minWidth: "32px",
|
|
88
89
|
minHeight: "32px",
|
|
89
90
|
padding: "8px 12px",
|
|
@@ -93,100 +94,100 @@ const ge = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ve = (r) => r.split(ge).map((a
|
|
|
93
94
|
backgroundColor: "var(--malachite-tooltip-background, rgb(59, 59, 59))",
|
|
94
95
|
color: "var(--malachite-tooltip-foreground, rgb(255, 255, 255))",
|
|
95
96
|
boxShadow: "var(--malachite-tooltip-shadow, 0px 0px 10px 0px rgba(0, 0, 0, 0.20))",
|
|
97
|
+
fontFamily: It,
|
|
96
98
|
fontSize: "14px",
|
|
97
99
|
lineHeight: "1.4",
|
|
98
100
|
whiteSpace: "normal",
|
|
99
101
|
textAlign: "left",
|
|
100
102
|
pointerEvents: "none",
|
|
101
|
-
opacity:
|
|
102
|
-
visibility:
|
|
103
|
+
opacity: e ? 1 : 0,
|
|
104
|
+
visibility: e ? "visible" : "hidden",
|
|
103
105
|
transition: "opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out"
|
|
104
|
-
}, L = () => {
|
|
105
|
-
|
|
106
|
-
const T = e.left + e.width / 2, V = ((k = E.current) == null ? void 0 : k.getBoundingClientRect().width) ?? 0;
|
|
106
|
+
}, c = (z = L.current) == null ? void 0 : z.getBoundingClientRect(), V = (c == null ? void 0 : c.width) ?? 0, Y = (c == null ? void 0 : c.height) ?? 0, A = () => {
|
|
107
|
+
const _ = t.left + t.width / 2;
|
|
107
108
|
if (V === 0)
|
|
108
|
-
return
|
|
109
|
-
const
|
|
110
|
-
return
|
|
111
|
-
};
|
|
112
|
-
switch (
|
|
109
|
+
return _;
|
|
110
|
+
const U = V / 2, G = x + U, q = window.innerWidth - x - U;
|
|
111
|
+
return G > q ? _ : Math.min(Math.max(_, G), q);
|
|
112
|
+
}, j = t.top - 8 - Y >= x, k = t.bottom + 8 + Y <= window.innerHeight - x;
|
|
113
|
+
switch (I === "top" && !j && k ? "bottom" : I === "bottom" && !k && j ? "top" : I) {
|
|
113
114
|
case "top":
|
|
114
115
|
return {
|
|
115
|
-
...
|
|
116
|
-
top:
|
|
117
|
-
left:
|
|
118
|
-
transform: `translate(-50%, -100%) ${
|
|
116
|
+
...r,
|
|
117
|
+
top: t.top - 8,
|
|
118
|
+
left: A(),
|
|
119
|
+
transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
119
120
|
};
|
|
120
121
|
case "bottom":
|
|
121
122
|
return {
|
|
122
|
-
...
|
|
123
|
-
top:
|
|
124
|
-
left:
|
|
125
|
-
transform: `translateX(-50%) ${
|
|
123
|
+
...r,
|
|
124
|
+
top: t.bottom + 8,
|
|
125
|
+
left: A(),
|
|
126
|
+
transform: `translateX(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
126
127
|
};
|
|
127
128
|
case "left":
|
|
128
129
|
return {
|
|
129
|
-
...
|
|
130
|
-
top:
|
|
131
|
-
left:
|
|
132
|
-
transform: `translate(-100%, -50%) ${
|
|
130
|
+
...r,
|
|
131
|
+
top: t.top + t.height / 2,
|
|
132
|
+
left: t.left - 8,
|
|
133
|
+
transform: `translate(-100%, -50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
133
134
|
};
|
|
134
135
|
case "right":
|
|
135
136
|
return {
|
|
136
|
-
...
|
|
137
|
-
top:
|
|
138
|
-
left:
|
|
139
|
-
transform: `translateY(-50%) ${
|
|
137
|
+
...r,
|
|
138
|
+
top: t.top + t.height / 2,
|
|
139
|
+
left: t.right + 8,
|
|
140
|
+
transform: `translateY(-50%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
140
141
|
};
|
|
141
142
|
default:
|
|
142
143
|
return {
|
|
143
|
-
...
|
|
144
|
-
top:
|
|
145
|
-
left:
|
|
146
|
-
transform: `translate(-50%, -100%) ${
|
|
144
|
+
...r,
|
|
145
|
+
top: t.top - 8,
|
|
146
|
+
left: A(),
|
|
147
|
+
transform: `translate(-50%, -100%) ${e ? "scale(1)" : "scale(0.95)"}`
|
|
147
148
|
};
|
|
148
149
|
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
l &&
|
|
152
|
-
}, [l,
|
|
153
|
-
const
|
|
154
|
-
"aria-describedby": [
|
|
155
|
-
}),
|
|
156
|
-
return /* @__PURE__ */
|
|
157
|
-
/* @__PURE__ */
|
|
158
|
-
|
|
150
|
+
}, F = l && b && $ ? C : void 0;
|
|
151
|
+
mt(() => {
|
|
152
|
+
l && b && gt();
|
|
153
|
+
}, [l, b]);
|
|
154
|
+
const ct = g ? s : J || !B.isValidElement(s) ? /* @__PURE__ */ p("span", { "aria-describedby": F, style: S ? X : void 0, children: s }) : B.cloneElement(s, {
|
|
155
|
+
"aria-describedby": [s.props["aria-describedby"], F].filter(Boolean).join(" ") || void 0
|
|
156
|
+
}), ft = M ? "span" : Q, O = g && l && !i && f;
|
|
157
|
+
return /* @__PURE__ */ D(dt, { children: [
|
|
158
|
+
/* @__PURE__ */ p(
|
|
159
|
+
ft,
|
|
159
160
|
{
|
|
160
|
-
ref:
|
|
161
|
-
className: `relative ${
|
|
162
|
-
style:
|
|
163
|
-
tabIndex:
|
|
164
|
-
"aria-describedby":
|
|
165
|
-
onMouseEnter:
|
|
166
|
-
onMouseLeave:
|
|
167
|
-
onFocus:
|
|
168
|
-
onBlur:
|
|
169
|
-
children:
|
|
161
|
+
ref: u,
|
|
162
|
+
className: `relative ${M ? "inline-flex max-w-full align-middle" : "flex"} items-center${O ? ` ${ht}` : ""}`,
|
|
163
|
+
style: Z,
|
|
164
|
+
tabIndex: O ? 0 : void 0,
|
|
165
|
+
"aria-describedby": g ? F : void 0,
|
|
166
|
+
onMouseEnter: nt,
|
|
167
|
+
onMouseLeave: ot,
|
|
168
|
+
onFocus: H,
|
|
169
|
+
onBlur: it,
|
|
170
|
+
children: ct
|
|
170
171
|
}
|
|
171
172
|
),
|
|
172
|
-
l &&
|
|
173
|
-
/* @__PURE__ */
|
|
173
|
+
l && b && pt(
|
|
174
|
+
/* @__PURE__ */ p(
|
|
174
175
|
"div",
|
|
175
176
|
{
|
|
176
|
-
ref:
|
|
177
|
-
id:
|
|
177
|
+
ref: L,
|
|
178
|
+
id: C,
|
|
178
179
|
role: "tooltip",
|
|
179
|
-
"aria-hidden":
|
|
180
|
-
...
|
|
181
|
-
style:
|
|
182
|
-
children: /* @__PURE__ */
|
|
180
|
+
"aria-hidden": $ ? void 0 : !0,
|
|
181
|
+
...bt("tooltip"),
|
|
182
|
+
style: lt(),
|
|
183
|
+
children: /* @__PURE__ */ p(
|
|
183
184
|
"span",
|
|
184
185
|
{
|
|
185
186
|
style: {
|
|
186
187
|
minWidth: 0,
|
|
187
188
|
overflowWrap: "anywhere"
|
|
188
189
|
},
|
|
189
|
-
children: typeof
|
|
190
|
+
children: typeof o == "string" ? xt(o) : o
|
|
190
191
|
}
|
|
191
192
|
)
|
|
192
193
|
}
|
|
@@ -196,6 +197,6 @@ const ge = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ve = (r) => r.split(ge).map((a
|
|
|
196
197
|
] });
|
|
197
198
|
};
|
|
198
199
|
export {
|
|
199
|
-
|
|
200
|
+
Mt as default
|
|
200
201
|
};
|
|
201
202
|
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sources":["../../src/components/Tooltip.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId, useInsertionEffect, useCallback } from 'react';\nimport { createPortal } from 'react-dom';\nimport { FOCUS_RING } from './focusRing';\nimport { ensureOverlayStyles, overlayIdentity } from './portalOverlay';\nimport { useTopLayer } from './topLayer';\nimport { useFollowTrigger } from './useFollowTrigger';\n\n// Split after each delimiter so long values (URLs, dotted paths) wrap at \"/\" or \".\"\n// instead of mid-token. <wbr> is copy-safe (a zero-width space would corrupt a copied\n// URL); overflow-wrap still handles a single run too long to fit.\nconst WRAP_AFTER = /(?<=[/\\\\.\\-_?&#=:@])/;\nconst withBreakOpportunities = (value: string): React.ReactNode =>\n value.split(WRAP_AFTER).map((chunk, i) => (\n <React.Fragment key={i}>\n {chunk}\n <wbr />\n </React.Fragment>\n ));\n\ninterface TooltipProps {\n text: React.ReactNode | string;\n children: React.ReactNode;\n delay?: number;\n wrapChildren?: boolean;\n placement?: 'top' | 'bottom' | 'left' | 'right';\n isShrinkable?: boolean;\n fill?: boolean;\n /** Max width of tooltip. Default: 320px */\n maxWidth?: number | string;\n /** Called synchronously when the trigger is hovered/focused; return false to\n * suppress the tooltip for this interaction. Lets wrappers defer expensive\n * checks (e.g. truncation measurement) to interaction time instead of mount. */\n shouldShow?: () => boolean;\n suppressed?: boolean;\n triggerAs?: 'div' | 'span';\n inline?: boolean;\n /** Whether the tooltip acts as the trigger's accessible description. False where the\n * trigger already points at the same sentence on screen, so it is not announced twice. */\n describesTrigger?: boolean;\n /** False to open on hover only, e.g. where script moves focus onto the trigger. */\n showOnFocus?: boolean;\n /** Makes a trigger that cannot take focus a tab stop. Not for focusable children. */\n focusableTrigger?: boolean;\n}\n\nconst SHRINKABLE_STYLE: React.CSSProperties = {\n minWidth: 0,\n overflow: 'hidden',\n};\n\nconst FILL_STYLE: React.CSSProperties = {\n flex: 1,\n minWidth: 0,\n};\n\n/** Kept clear of the viewport edge so a clamped tooltip does not sit flush against it. */\nconst VIEWPORT_MARGIN = 8;\n\nconst Tooltip: React.FC<TooltipProps> = ({\n text,\n children,\n delay = 1,\n wrapChildren = false,\n triggerAs = 'div',\n inline = false,\n placement = 'top',\n isShrinkable = false,\n maxWidth = '320px',\n fill = false,\n shouldShow,\n suppressed = false,\n describesTrigger = true,\n showOnFocus = true,\n focusableTrigger = false,\n}) => {\n const triggerStyle =\n isShrinkable || fill\n ? { ...(isShrinkable ? SHRINKABLE_STYLE : {}), ...(fill ? FILL_STYLE : {}) }\n : undefined;\n\n const [isVisible, setIsVisible] = useState(false);\n // Portal mounts on first show, not on mount: an at-rest tooltip otherwise\n // costs a hidden document.body node plus a getBoundingClientRect per render —\n // multiplied by every row in a large table.\n // Mounted up front so a focusable trigger is described on first focus.\n const [hasShown, setHasShown] = useState(false);\n const isMounted = hasShown || focusableTrigger;\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const showFrameRef = useRef<number | null>(null);\n\n const cancelPendingShow = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n showFrameRef.current = null;\n }\n }, []);\n\n const scheduleVisible = () => {\n // Two steps so the portal mounts hidden first and the fade-in transition\n // still runs on the very first show. The frame is tracked so leave/blur/\n // unmount can cancel a show that is already past its delay.\n setHasShown(true);\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n }\n showFrameRef.current = requestAnimationFrame(() => {\n showFrameRef.current = null;\n setIsVisible(true);\n });\n };\n const tooltipRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n\n // Tied to visibility, not mount: the node is latched into the DOM after its first show, and\n // re-entering on each show keeps a tooltip above the panel it is annotating.\n useTopLayer(tooltipRef, isVisible);\n\n const tooltipId = useId();\n\n const hasText = text !== null && text !== undefined && text !== '' && text !== false;\n\n const handleMouseEnter = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (!hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n\n timeoutRef.current = setTimeout(() => {\n scheduleVisible();\n }, delay * 1000);\n };\n\n const handleMouseLeave = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n cancelPendingShow();\n setIsVisible(false);\n };\n\n const handleFocus = () => {\n if (!showOnFocus || !hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n scheduleVisible();\n };\n\n const handleBlur = () => {\n cancelPendingShow();\n setIsVisible(false);\n };\n\n // Turning on while the trigger already holds focus fires no focus event to open on.\n const showOnFocusRef = useRef(showOnFocus);\n useEffect(() => {\n const switchedOn = showOnFocus && !showOnFocusRef.current;\n showOnFocusRef.current = showOnFocus;\n if (switchedOn && triggerRef.current?.matches(':focus-within')) {\n handleFocus();\n }\n });\n\n const [wasSuppressed, setWasSuppressed] = useState(suppressed);\n if (suppressed !== wasSuppressed) {\n setWasSuppressed(suppressed);\n if (suppressed) {\n setIsVisible(false);\n }\n }\n\n useEffect(() => {\n if (suppressed) {\n cancelPendingShow();\n }\n }, [suppressed, cancelPendingShow]);\n\n const [, forceUpdate] = useState({});\n\n const hideWithTrigger = useCallback(() => {\n cancelPendingShow();\n setIsVisible(false);\n }, [cancelPendingShow]);\n\n useFollowTrigger(isVisible, triggerRef, () => forceUpdate({}), hideWithTrigger);\n\n useEffect(() => {\n // Only a VISIBLE tooltip needs to track resize; keeping global listeners per mounted\n // instance made every event fan out across every tooltip on the page. Scrolling is\n // followed by useFollowTrigger.\n if (!isVisible) {\n return () => {\n cancelPendingShow();\n };\n }\n const handleUpdate = () => {\n forceUpdate({});\n };\n\n window.addEventListener('resize', handleUpdate);\n\n return () => {\n cancelPendingShow();\n window.removeEventListener('resize', handleUpdate);\n };\n }, [isVisible, cancelPendingShow]);\n\n // The first render that mounts the tooltip has no measured width yet, so the clamp below\n // cannot run on it. One extra pass once it is in the DOM gives the clamp its measurement\n // — before the opacity transition finishes, so nothing is seen sliding into place.\n useEffect(() => {\n if (isVisible) {\n forceUpdate({});\n }\n }, [isVisible]);\n\n const getTooltipStyles = (): React.CSSProperties => {\n if (!triggerRef.current) {\n return { display: 'none' };\n }\n\n const rect = triggerRef.current.getBoundingClientRect();\n\n const baseStyles: React.CSSProperties = {\n position: 'fixed',\n display: 'flex',\n width: 'max-content',\n maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,\n minWidth: '32px',\n minHeight: '32px',\n padding: '8px 12px',\n alignItems: 'center',\n gap: '8px',\n borderRadius: '12px',\n backgroundColor: 'var(--malachite-tooltip-background, rgb(59, 59, 59))',\n color: 'var(--malachite-tooltip-foreground, rgb(255, 255, 255))',\n boxShadow: 'var(--malachite-tooltip-shadow, 0px 0px 10px 0px rgba(0, 0, 0, 0.20))',\n fontSize: '14px',\n lineHeight: '1.4',\n whiteSpace: 'normal',\n textAlign: 'left',\n pointerEvents: 'none',\n opacity: isVisible ? 1 : 0,\n visibility: isVisible ? 'visible' : 'hidden',\n transition:\n 'opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out',\n };\n\n // A trigger near the viewport edge would otherwise centre a wide tooltip half off\n // screen, where the panel or the window crops it. Clamping the CENTRE keeps the\n // `translateX(-50%)` placement honest: the box stays put, it just stops short.\n const centeredLeft = (): number => {\n const desired = rect.left + rect.width / 2;\n const width = tooltipRef.current?.getBoundingClientRect().width ?? 0;\n\n if (width === 0) {\n return desired;\n }\n\n const half = width / 2;\n const min = VIEWPORT_MARGIN + half;\n const max = window.innerWidth - VIEWPORT_MARGIN - half;\n\n // A tooltip wider than the viewport has no in-bounds centre; leave it centred\n // rather than pinning it to a nonsensical one.\n return min > max ? desired : Math.min(Math.max(desired, min), max);\n };\n\n switch (placement) {\n case 'top':\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'bottom':\n return {\n ...baseStyles,\n top: rect.bottom + 8,\n left: centeredLeft(),\n transform: `translateX(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'left':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.left - 8,\n transform: `translate(-100%, -50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'right':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.right + 8,\n transform: `translateY(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n default:\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n }\n };\n\n // Only reference the tooltip id once the portal can exist — a dangling\n // aria-describedby (text set, never shown) confuses assistive tech.\n const describedBy = hasText && isMounted && describesTrigger ? tooltipId : undefined;\n useInsertionEffect(() => {\n if (hasText && isMounted) {\n ensureOverlayStyles();\n }\n }, [hasText, isMounted]);\n const renderedChildren = focusableTrigger ? (\n children\n ) : wrapChildren || !React.isValidElement(children) ? (\n <span aria-describedby={describedBy} style={fill ? FILL_STYLE : undefined}>\n {children}\n </span>\n ) : (\n React.cloneElement(children as React.ReactElement, {\n 'aria-describedby':\n [(children as React.ReactElement).props['aria-describedby'], describedBy]\n .filter(Boolean)\n .join(' ') || undefined,\n })\n );\n\n const Trigger = inline ? 'span' : triggerAs;\n const isTabStop = focusableTrigger && hasText && !suppressed && showOnFocus;\n\n // Create the tooltip content without its own shadow root\n return (\n <>\n <Trigger\n ref={triggerRef}\n className={`relative ${inline ? 'inline-flex max-w-full align-middle' : 'flex'} items-center${isTabStop ? ` ${FOCUS_RING}` : ''}`}\n style={triggerStyle}\n tabIndex={isTabStop ? 0 : undefined}\n aria-describedby={focusableTrigger ? describedBy : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {renderedChildren}\n </Trigger>\n\n {hasText &&\n isMounted &&\n createPortal(\n <div\n ref={tooltipRef}\n id={tooltipId}\n role=\"tooltip\"\n // Nothing references it, and the sentence is already on screen and\n // described: left in the tree it is a second copy to read past.\n aria-hidden={describesTrigger ? undefined : true}\n {...overlayIdentity('tooltip')}\n style={getTooltipStyles()}\n >\n {/* min-w-0 + overflow-wrap let long values wrap within maxWidth. */}\n <span\n style={{\n minWidth: 0,\n overflowWrap: 'anywhere',\n }}\n >\n {typeof text === 'string' ? withBreakOpportunities(text) : text}\n </span>\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default Tooltip;\n"],"names":["WRAP_AFTER","withBreakOpportunities","value","chunk","i","jsxs","React","SHRINKABLE_STYLE","FILL_STYLE","VIEWPORT_MARGIN","Tooltip","text","children","delay","wrapChildren","triggerAs","inline","placement","isShrinkable","maxWidth","fill","shouldShow","suppressed","describesTrigger","showOnFocus","focusableTrigger","triggerStyle","isVisible","setIsVisible","useState","hasShown","setHasShown","isMounted","timeoutRef","useRef","showFrameRef","cancelPendingShow","useCallback","scheduleVisible","tooltipRef","triggerRef","useTopLayer","tooltipId","useId","hasText","handleMouseEnter","handleMouseLeave","handleFocus","handleBlur","showOnFocusRef","useEffect","switchedOn","_a","wasSuppressed","setWasSuppressed","forceUpdate","hideWithTrigger","useFollowTrigger","handleUpdate","getTooltipStyles","rect","baseStyles","centeredLeft","desired","width","half","min","max","describedBy","useInsertionEffect","ensureOverlayStyles","renderedChildren","jsx","Trigger","isTabStop","Fragment","FOCUS_RING","createPortal","overlayIdentity"],"mappings":";;;;;;;AAUA,MAAMA,KAAa,WAAA,yBAAA,GACbC,KAAyB,CAACC,MAC5BA,EAAM,MAAMF,EAAU,EAAE,IAAI,CAACG,GAAOC,MAChC,gBAAAC,EAACC,EAAM,UAAN,EACI,UAAA;AAAA,EAAAH;AAAA,oBACA,OAAA,CAAA,CAAI;AAAA,EAAA,GAFYC,CAGrB,CACH,GA4BCG,KAAwC;AAAA,EAC1C,UAAU;AAAA,EACV,UAAU;AACd,GAEMC,IAAkC;AAAA,EACpC,MAAM;AAAA,EACN,UAAU;AACd,GAGMC,IAAkB,GAElBC,KAAkC,CAAC;AAAA,EACrC,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,cAAAC,IAAe;AAAA,EACf,WAAAC,IAAY;AAAA,EACZ,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAAA,EACZ,cAAAC,IAAe;AAAA,EACf,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,kBAAAC,IAAmB;AAAA,EACnB,aAAAC,IAAc;AAAA,EACd,kBAAAC,IAAmB;AACvB,MAAM;AACF,QAAMC,IACFR,KAAgBE,IACV,EAAE,GAAIF,IAAeX,KAAmB,CAAA,GAAK,GAAIa,IAAOZ,IAAa,CAAA,MACrE,QAEJ,CAACmB,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAK1C,CAACC,GAAUC,CAAW,IAAIF,EAAS,EA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AA,QACd,SAASC;AAAA,QACT,QAAQC;AAAA,QAEP,UAAAuB;AAAA,MAAA;AAAA,IAAA;AAAA,IAGJ3B,KACGZ,KACA6C;AAAA,MACI,gBAAAL;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,KAAKjC;AAAA,UACL,IAAIG;AAAA,UACJ,MAAK;AAAA,UAGL,eAAanB,IAAmB,SAAY;AAAA,UAC3C,GAAGuD,GAAgB,SAAS;AAAA,UAC7B,OAAOnB,GAAA;AAAA,UAGP,UAAA,gBAAAa;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,OAAO;AAAA,gBACH,UAAU;AAAA,gBACV,cAAc;AAAA,cAAA;AAAA,cAGjB,UAAA,OAAO7D,KAAS,WAAWV,GAAuBU,CAAI,IAAIA;AAAA,YAAA;AAAA,UAAA;AAAA,QAC/D;AAAA,MAAA;AAAA,MAEJ,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sources":["../../src/components/Tooltip.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId, useInsertionEffect, useCallback } from 'react';\nimport { createPortal } from 'react-dom';\nimport { FOCUS_RING } from './focusRing';\nimport { ensureOverlayStyles, overlayIdentity } from './portalOverlay';\nimport { useTopLayer } from './topLayer';\nimport { useFollowTrigger } from './useFollowTrigger';\n\n// Split after each delimiter so long values (URLs, dotted paths) wrap at \"/\" or \".\"\n// instead of mid-token. <wbr> is copy-safe (a zero-width space would corrupt a copied\n// URL); overflow-wrap still handles a single run too long to fit.\nconst WRAP_AFTER = /(?<=[/\\\\.\\-_?&#=:@])/;\nconst withBreakOpportunities = (value: string): React.ReactNode =>\n value.split(WRAP_AFTER).map((chunk, i) => (\n <React.Fragment key={i}>\n {chunk}\n <wbr />\n </React.Fragment>\n ));\n\ninterface TooltipProps {\n text: React.ReactNode | string;\n children: React.ReactNode;\n delay?: number;\n wrapChildren?: boolean;\n placement?: 'top' | 'bottom' | 'left' | 'right';\n isShrinkable?: boolean;\n fill?: boolean;\n /** Max width of tooltip. Default: 320px */\n maxWidth?: number | string;\n /** Called synchronously when the trigger is hovered/focused; return false to\n * suppress the tooltip for this interaction. Lets wrappers defer expensive\n * checks (e.g. truncation measurement) to interaction time instead of mount. */\n shouldShow?: () => boolean;\n suppressed?: boolean;\n triggerAs?: 'div' | 'span';\n inline?: boolean;\n /** Whether the tooltip acts as the trigger's accessible description. False where the\n * trigger already points at the same sentence on screen, so it is not announced twice. */\n describesTrigger?: boolean;\n /** False to open on hover only, e.g. where script moves focus onto the trigger. */\n showOnFocus?: boolean;\n /** Makes a trigger that cannot take focus a tab stop. Not for focusable children. */\n focusableTrigger?: boolean;\n}\n\nconst SHRINKABLE_STYLE: React.CSSProperties = {\n minWidth: 0,\n overflow: 'hidden',\n};\n\nconst FILL_STYLE: React.CSSProperties = {\n flex: 1,\n minWidth: 0,\n};\n\n/** Kept clear of the viewport edge so a clamped tooltip does not sit flush against it. */\nconst VIEWPORT_MARGIN = 8;\n\n// The tooltip portals to document.body, outside the shadow root's `--font-sans`, so it names the\n// stack itself rather than inheriting the host page's font (a serif in an MCP card's iframe).\nconst TOOLTIP_FONT_FAMILY = '\"Inter\", ui-sans-serif, system-ui, sans-serif';\n\nconst Tooltip: React.FC<TooltipProps> = ({\n text,\n children,\n delay = 1,\n wrapChildren = false,\n triggerAs = 'div',\n inline = false,\n placement = 'top',\n isShrinkable = false,\n maxWidth = '320px',\n fill = false,\n shouldShow,\n suppressed = false,\n describesTrigger = true,\n showOnFocus = true,\n focusableTrigger = false,\n}) => {\n const triggerStyle =\n isShrinkable || fill\n ? { ...(isShrinkable ? SHRINKABLE_STYLE : {}), ...(fill ? FILL_STYLE : {}) }\n : undefined;\n\n const [isVisible, setIsVisible] = useState(false);\n // Portal mounts on first show, not on mount: an at-rest tooltip otherwise\n // costs a hidden document.body node plus a getBoundingClientRect per render —\n // multiplied by every row in a large table.\n // Mounted up front so a focusable trigger is described on first focus.\n const [hasShown, setHasShown] = useState(false);\n const isMounted = hasShown || focusableTrigger;\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const showFrameRef = useRef<number | null>(null);\n\n const cancelPendingShow = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n showFrameRef.current = null;\n }\n }, []);\n\n const scheduleVisible = () => {\n // Two steps so the portal mounts hidden first and the fade-in transition\n // still runs on the very first show. The frame is tracked so leave/blur/\n // unmount can cancel a show that is already past its delay.\n setHasShown(true);\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n }\n showFrameRef.current = requestAnimationFrame(() => {\n showFrameRef.current = null;\n setIsVisible(true);\n });\n };\n const tooltipRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n\n // Tied to visibility, not mount: the node is latched into the DOM after its first show, and\n // re-entering on each show keeps a tooltip above the panel it is annotating.\n useTopLayer(tooltipRef, isVisible);\n\n const tooltipId = useId();\n\n const hasText = text !== null && text !== undefined && text !== '' && text !== false;\n\n const handleMouseEnter = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (!hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n\n timeoutRef.current = setTimeout(() => {\n scheduleVisible();\n }, delay * 1000);\n };\n\n const handleMouseLeave = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n cancelPendingShow();\n setIsVisible(false);\n };\n\n const handleFocus = () => {\n if (!showOnFocus || !hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n scheduleVisible();\n };\n\n const handleBlur = () => {\n cancelPendingShow();\n setIsVisible(false);\n };\n\n // Turning on while the trigger already holds focus fires no focus event to open on.\n const showOnFocusRef = useRef(showOnFocus);\n useEffect(() => {\n const switchedOn = showOnFocus && !showOnFocusRef.current;\n showOnFocusRef.current = showOnFocus;\n if (switchedOn && triggerRef.current?.matches(':focus-within')) {\n handleFocus();\n }\n });\n\n const [wasSuppressed, setWasSuppressed] = useState(suppressed);\n if (suppressed !== wasSuppressed) {\n setWasSuppressed(suppressed);\n if (suppressed) {\n setIsVisible(false);\n }\n }\n\n useEffect(() => {\n if (suppressed) {\n cancelPendingShow();\n }\n }, [suppressed, cancelPendingShow]);\n\n const [, forceUpdate] = useState({});\n\n const hideWithTrigger = useCallback(() => {\n cancelPendingShow();\n setIsVisible(false);\n }, [cancelPendingShow]);\n\n useFollowTrigger(isVisible, triggerRef, () => forceUpdate({}), hideWithTrigger);\n\n useEffect(() => {\n // Only a VISIBLE tooltip needs to track resize; keeping global listeners per mounted\n // instance made every event fan out across every tooltip on the page. Scrolling is\n // followed by useFollowTrigger.\n if (!isVisible) {\n return () => {\n cancelPendingShow();\n };\n }\n const handleUpdate = () => {\n forceUpdate({});\n };\n\n window.addEventListener('resize', handleUpdate);\n\n return () => {\n cancelPendingShow();\n window.removeEventListener('resize', handleUpdate);\n };\n }, [isVisible, cancelPendingShow]);\n\n // The first render that mounts the tooltip has no measured width yet, so the clamp below\n // cannot run on it. One extra pass once it is in the DOM gives the clamp its measurement\n // — before the opacity transition finishes, so nothing is seen sliding into place.\n useEffect(() => {\n if (isVisible) {\n forceUpdate({});\n }\n }, [isVisible]);\n\n const getTooltipStyles = (): React.CSSProperties => {\n if (!triggerRef.current) {\n return { display: 'none' };\n }\n\n const rect = triggerRef.current.getBoundingClientRect();\n\n const baseStyles: React.CSSProperties = {\n position: 'fixed',\n display: 'flex',\n width: 'max-content',\n maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,\n minWidth: '32px',\n minHeight: '32px',\n padding: '8px 12px',\n alignItems: 'center',\n gap: '8px',\n borderRadius: '12px',\n backgroundColor: 'var(--malachite-tooltip-background, rgb(59, 59, 59))',\n color: 'var(--malachite-tooltip-foreground, rgb(255, 255, 255))',\n boxShadow: 'var(--malachite-tooltip-shadow, 0px 0px 10px 0px rgba(0, 0, 0, 0.20))',\n fontFamily: TOOLTIP_FONT_FAMILY,\n fontSize: '14px',\n lineHeight: '1.4',\n whiteSpace: 'normal',\n textAlign: 'left',\n pointerEvents: 'none',\n opacity: isVisible ? 1 : 0,\n visibility: isVisible ? 'visible' : 'hidden',\n transition:\n 'opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out',\n };\n\n // A trigger near the viewport edge would otherwise centre a wide tooltip half off\n // screen, where the panel or the window crops it. Clamping the CENTRE keeps the\n // `translateX(-50%)` placement honest: the box stays put, it just stops short.\n const measured = tooltipRef.current?.getBoundingClientRect();\n const width = measured?.width ?? 0;\n const height = measured?.height ?? 0;\n\n const centeredLeft = (): number => {\n const desired = rect.left + rect.width / 2;\n\n if (width === 0) {\n return desired;\n }\n\n const half = width / 2;\n const min = VIEWPORT_MARGIN + half;\n const max = window.innerWidth - VIEWPORT_MARGIN - half;\n\n // A tooltip wider than the viewport has no in-bounds centre; leave it centred\n // rather than pinning it to a nonsensical one.\n return min > max ? desired : Math.min(Math.max(desired, min), max);\n };\n\n // At the viewport's top or bottom edge the tooltip would land where the window or an\n // embedding iframe crops it, so it flips to the side that has room.\n const fitsAbove = rect.top - 8 - height >= VIEWPORT_MARGIN;\n const fitsBelow = rect.bottom + 8 + height <= window.innerHeight - VIEWPORT_MARGIN;\n const side =\n placement === 'top' && !fitsAbove && fitsBelow\n ? 'bottom'\n : placement === 'bottom' && !fitsBelow && fitsAbove\n ? 'top'\n : placement;\n\n switch (side) {\n case 'top':\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'bottom':\n return {\n ...baseStyles,\n top: rect.bottom + 8,\n left: centeredLeft(),\n transform: `translateX(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'left':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.left - 8,\n transform: `translate(-100%, -50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'right':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.right + 8,\n transform: `translateY(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n default:\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n }\n };\n\n // Only reference the tooltip id once the portal can exist — a dangling\n // aria-describedby (text set, never shown) confuses assistive tech.\n const describedBy = hasText && isMounted && describesTrigger ? tooltipId : undefined;\n useInsertionEffect(() => {\n if (hasText && isMounted) {\n ensureOverlayStyles();\n }\n }, [hasText, isMounted]);\n const renderedChildren = focusableTrigger ? (\n children\n ) : wrapChildren || !React.isValidElement(children) ? (\n <span aria-describedby={describedBy} style={fill ? FILL_STYLE : undefined}>\n {children}\n </span>\n ) : (\n React.cloneElement(children as React.ReactElement, {\n 'aria-describedby':\n [(children as React.ReactElement).props['aria-describedby'], describedBy]\n .filter(Boolean)\n .join(' ') || undefined,\n })\n );\n\n const Trigger = inline ? 'span' : triggerAs;\n const isTabStop = focusableTrigger && hasText && !suppressed && showOnFocus;\n\n // Create the tooltip content without its own shadow root\n return (\n <>\n <Trigger\n ref={triggerRef}\n className={`relative ${inline ? 'inline-flex max-w-full align-middle' : 'flex'} items-center${isTabStop ? ` ${FOCUS_RING}` : ''}`}\n style={triggerStyle}\n tabIndex={isTabStop ? 0 : undefined}\n aria-describedby={focusableTrigger ? describedBy : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {renderedChildren}\n </Trigger>\n\n {hasText &&\n isMounted &&\n createPortal(\n <div\n ref={tooltipRef}\n id={tooltipId}\n role=\"tooltip\"\n // Nothing references it, and the sentence is already on screen and\n // described: left in the tree it is a second copy to read past.\n aria-hidden={describesTrigger ? undefined : true}\n {...overlayIdentity('tooltip')}\n style={getTooltipStyles()}\n >\n {/* min-w-0 + overflow-wrap let long values wrap within maxWidth. */}\n <span\n style={{\n minWidth: 0,\n overflowWrap: 'anywhere',\n }}\n >\n {typeof text === 'string' ? withBreakOpportunities(text) : text}\n </span>\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default Tooltip;\n"],"names":["WRAP_AFTER","withBreakOpportunities","value","chunk","i","jsxs","React","SHRINKABLE_STYLE","FILL_STYLE","VIEWPORT_MARGIN","TOOLTIP_FONT_FAMILY","Tooltip","text","children","delay","wrapChildren","triggerAs","inline","placement","isShrinkable","maxWidth","fill","shouldShow","suppressed","describesTrigger","showOnFocus","focusableTrigger","triggerStyle","isVisible","setIsVisible","useState","hasShown","setHasShown","isMounted","timeoutRef","useRef","showFrameRef","cancelPendingShow","useCallback","scheduleVisible","tooltipRef","triggerRef","useTopLayer","tooltipId","useId","hasText","handleMouseEnter","e","handleMouseLeave","handleFocus","handleBlur","showOnFocusRef","useEffect","switchedOn","_a","wasSuppressed","setWasSuppressed","forceUpdate","hideWithTrigger","useFollowTrigger","handleUpdate","getTooltipStyles","rect","baseStyles","measured","width","height","centeredLeft","desired","half","min","max","fitsAbove","fitsBelow","describedBy","useInsertionEffect","ensureOverlayStyles","renderedChildren","jsx","Trigger","isTabStop","Fragment","FOCUS_RING","createPortal","overlayIdentity"],"mappings":";;;;;;;AAUA,MAAMA,KAAa,WAAA,yBAAA,GACbC,KAAyB,CAACC,MAC5BA,EAAM,MAAMF,EAAU,EAAE,IAAI,CAACG,GAAOC,MAChC,gBAAAC,EAACC,EAAM,UAAN,EACI,UAAA;AAAA,EAAAH;AAAA,oBACA,OAAA,CAAA,CAAI;AAAA,EAAA,GAFYC,CAGrB,CACH,GA4BCG,KAAwC;AAAA,EAC1C,UAAU;AAAA,EACV,UAAU;AACd,GAEMC,IAAkC;AAAA,EACpC,MAAM;AAAA,EACN,UAAU;AACd,GAGMC,IAAkB,GAIlB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;AAAA,gBACH,UAAU;AAAA,gBACV,cAAc;AAAA,cAAA;AAAA,cAGjB,UAAA,OAAOlE,KAAS,WAAWX,GAAuBW,CAAI,IAAIA;AAAA,YAAA;AAAA,UAAA;AAAA,QAC/D;AAAA,MAAA;AAAA,MAEJ,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
|
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import { useFontFace as y } from "../../fontInjection.js";
|
|
3
|
+
import { getFontWeight as F, getFontFamily as f, getFontSize as u, getTextColor as x } from "./textStyles.js";
|
|
4
|
+
const b = ({
|
|
4
5
|
underline: o = !1,
|
|
5
6
|
children: i,
|
|
6
|
-
color:
|
|
7
|
-
size:
|
|
7
|
+
color: a = "primary",
|
|
8
|
+
size: r = "small",
|
|
8
9
|
font: t,
|
|
9
|
-
fontWeight:
|
|
10
|
-
tooltip:
|
|
10
|
+
fontWeight: n = "normal",
|
|
11
|
+
tooltip: s,
|
|
11
12
|
textAlign: e,
|
|
12
|
-
wrap:
|
|
13
|
+
wrap: l = !0,
|
|
13
14
|
as: m = "span",
|
|
14
|
-
className:
|
|
15
|
-
style:
|
|
15
|
+
className: d = "",
|
|
16
|
+
style: p = {}
|
|
16
17
|
}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
y(t === "heading" ? "stack-sans" : t === "body" ? "geist" : void 0);
|
|
19
|
+
const c = {
|
|
20
|
+
color: x(a),
|
|
21
|
+
fontSize: u(r),
|
|
20
22
|
// Left unset when not asked for, so Text keeps inheriting whatever the surrounding context…
|
|
21
|
-
fontFamily: t ?
|
|
22
|
-
fontWeight:
|
|
23
|
+
fontFamily: t ? f(t) : void 0,
|
|
24
|
+
fontWeight: F(n),
|
|
23
25
|
textAlign: e,
|
|
24
26
|
textDecoration: o ? "underline" : "none",
|
|
25
27
|
display: e ? "block" : void 0,
|
|
26
|
-
whiteSpace:
|
|
27
|
-
...
|
|
28
|
+
whiteSpace: l ? void 0 : "nowrap",
|
|
29
|
+
...p
|
|
28
30
|
};
|
|
29
|
-
return /* @__PURE__ */
|
|
31
|
+
return /* @__PURE__ */ g(m, { className: d, style: c, title: s, children: i });
|
|
30
32
|
};
|
|
31
33
|
export {
|
|
32
|
-
|
|
34
|
+
b as default
|
|
33
35
|
};
|
|
34
36
|
//# sourceMappingURL=Text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.js","sources":["../../../src/components/Typography/Text.tsx"],"sourcesContent":["import React from 'react';\nimport type { FontFamily, FontSize, FontWeight, TextColor, TextElement } from './textStyles';\nimport { getFontFamily, getFontSize, getFontWeight, getTextColor } from './textStyles';\n\n// Types only: a value re-export would put the non-component exports back in this file.\nexport type { FontSize, FontFamily, FontWeight, TextColor, TextElement } from './textStyles';\n\nexport interface TextProps {\n color?: TextColor;\n size?: FontSize;\n /**\n * Typeface. Defaults to `sans` (Inter), the library's body face. `heading` is Stack Sans\n * Text and `body` is Geist
|
|
1
|
+
{"version":3,"file":"Text.js","sources":["../../../src/components/Typography/Text.tsx"],"sourcesContent":["import React from 'react';\nimport { useFontFace } from '../../fontInjection';\nimport type { FontFamily, FontSize, FontWeight, TextColor, TextElement } from './textStyles';\nimport { getFontFamily, getFontSize, getFontWeight, getTextColor } from './textStyles';\n\n// Types only: a value re-export would put the non-component exports back in this file.\nexport type { FontSize, FontFamily, FontWeight, TextColor, TextElement } from './textStyles';\n\nexport interface TextProps {\n color?: TextColor;\n size?: FontSize;\n /**\n * Typeface. Defaults to `sans` (Inter), the library's body face. `heading` is Stack Sans\n * Text and `body` is Geist. Each is injected only when a `Text` asks for it, and declared\n * in the theme.\n */\n font?: FontFamily;\n underline?: boolean;\n fontWeight?: FontWeight;\n children: React.ReactNode;\n tooltip?: string;\n textAlign?: 'left' | 'center' | 'right' | 'justify';\n wrap?: boolean;\n /** The element it renders, for a heading or paragraph that keeps Text's look. */\n as?: TextElement;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst Text: React.FC<TextProps> = ({\n underline = false,\n children,\n color = 'primary',\n size = 'small',\n font,\n fontWeight = 'normal',\n tooltip,\n textAlign,\n wrap = true,\n as: Element = 'span',\n className = '',\n style = {},\n}) => {\n useFontFace(font === 'heading' ? 'stack-sans' : font === 'body' ? 'geist' : undefined);\n const textStyles: React.CSSProperties = {\n color: getTextColor(color),\n fontSize: getFontSize(size),\n // Left unset when not asked for, so Text keeps inheriting whatever the surrounding context…\n fontFamily: font ? getFontFamily(font) : undefined,\n fontWeight: getFontWeight(fontWeight),\n textAlign,\n textDecoration: underline ? 'underline' : 'none',\n display: textAlign ? 'block' : undefined,\n whiteSpace: wrap ? undefined : 'nowrap',\n ...style,\n };\n\n return (\n <Element className={className} style={textStyles} title={tooltip}>\n {children}\n </Element>\n );\n};\n\nexport default Text;\n"],"names":["Text","underline","children","color","size","font","fontWeight","tooltip","textAlign","wrap","Element","className","style","useFontFace","textStyles","getTextColor","getFontSize","getFontFamily","getFontWeight"],"mappings":";;;AA6BA,MAAMA,IAA4B,CAAC;AAAA,EAC/B,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,MAAAC,IAAO;AAAA,EACP,MAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,SAAAC;AAAA,EACA,WAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,IAAIC,IAAU;AAAA,EACd,WAAAC,IAAY;AAAA,EACZ,OAAAC,IAAQ,CAAA;AACZ,MAAM;AACF,EAAAC,EAAYR,MAAS,YAAY,eAAeA,MAAS,SAAS,UAAU,MAAS;AACrF,QAAMS,IAAkC;AAAA,IACpC,OAAOC,EAAaZ,CAAK;AAAA,IACzB,UAAUa,EAAYZ,CAAI;AAAA;AAAA,IAE1B,YAAYC,IAAOY,EAAcZ,CAAI,IAAI;AAAA,IACzC,YAAYa,EAAcZ,CAAU;AAAA,IACpC,WAAAE;AAAA,IACA,gBAAgBP,IAAY,cAAc;AAAA,IAC1C,SAASO,IAAY,UAAU;AAAA,IAC/B,YAAYC,IAAO,SAAY;AAAA,IAC/B,GAAGG;AAAA,EAAA;AAGP,2BACKF,GAAA,EAAQ,WAAAC,GAAsB,OAAOG,GAAY,OAAOP,GACpD,UAAAL,GACL;AAER;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import s, { useEffect as r, useContext as a } from "react";
|
|
3
|
+
const n = s.createContext(!0), p = ({
|
|
4
|
+
enabled: t,
|
|
5
|
+
children: e
|
|
6
|
+
}) => /* @__PURE__ */ c(n.Provider, { value: t, children: e }), i = () => a(n), u = {
|
|
7
|
+
geist: () => import("./geist-font.js").then((t) => t.ensureGeistFontFace),
|
|
8
|
+
"stack-sans": () => import("./stack-sans-font.js").then((t) => t.ensureStackSansFontFace)
|
|
9
|
+
}, x = (t) => {
|
|
10
|
+
const e = i();
|
|
11
|
+
r(() => {
|
|
12
|
+
!e || !t || u[t]().then((o) => o()).catch(() => {
|
|
13
|
+
});
|
|
14
|
+
}, [e, t]);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
p as FontInjectionProvider,
|
|
18
|
+
x as useFontFace,
|
|
19
|
+
i as useFontInjection
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=fontInjection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fontInjection.js","sources":["../src/fontInjection.tsx"],"sourcesContent":["import React, { useContext, useEffect } from 'react';\n\nconst FontInjectionContext = React.createContext<boolean>(true);\n\nexport const FontInjectionProvider: React.FC<{ enabled: boolean; children: React.ReactNode }> = ({\n enabled,\n children,\n}) => <FontInjectionContext.Provider value={enabled}>{children}</FontInjectionContext.Provider>;\n\n/** False when an enclosing `ShadowRootWrapper` or `MalachiteContext` set `injectFonts={false}`. */\nexport const useFontInjection = (): boolean => useContext(FontInjectionContext);\n\ntype OptionalFamily = 'geist' | 'stack-sans';\n\n// Dynamic imports keep each family's base64 data in its own chunk, so a bundle that never\n// renders a component needing it never loads (or, for a bundler that splits, never ships) it.\nconst LOADERS: Record<OptionalFamily, () => Promise<() => void>> = {\n geist: () => import('./geist-font').then((m) => m.ensureGeistFontFace),\n 'stack-sans': () => import('./stack-sans-font').then((m) => m.ensureStackSansFontFace),\n};\n\n/** Injects a non-theme font family into the document when the caller renders and needs it. */\nexport const useFontFace = (family: OptionalFamily | undefined): void => {\n const enabled = useFontInjection();\n useEffect(() => {\n if (!enabled || !family) {\n return;\n }\n LOADERS[family]()\n .then((ensure) => ensure())\n // A font that fails to load falls back to the stack in the theme token.\n .catch(() => undefined);\n }, [enabled, family]);\n};\n"],"names":["FontInjectionContext","React","FontInjectionProvider","enabled","children","useFontInjection","useContext","LOADERS","m","useFontFace","family","useEffect","ensure"],"mappings":";;AAEA,MAAMA,IAAuBC,EAAM,cAAuB,EAAI,GAEjDC,IAAmF,CAAC;AAAA,EAC7F,SAAAC;AAAA,EACA,UAAAC;AACJ,wBAAOJ,EAAqB,UAArB,EAA8B,OAAOG,GAAU,UAAAC,EAAA,CAAS,GAGlDC,IAAmB,MAAeC,EAAWN,CAAoB,GAMxEO,IAA6D;AAAA,EAC/D,OAAO,MAAM,OAAO,iBAAc,EAAE,KAAK,CAACC,MAAMA,EAAE,mBAAmB;AAAA,EACrE,cAAc,MAAM,OAAO,sBAAmB,EAAE,KAAK,CAACA,MAAMA,EAAE,uBAAuB;AACzF,GAGaC,IAAc,CAACC,MAA6C;AACrE,QAAMP,IAAUE,EAAA;AAChB,EAAAM,EAAU,MAAM;AACZ,IAAI,CAACR,KAAW,CAACO,KAGjBH,EAAQG,CAAM,EAAA,EACT,KAAK,CAACE,MAAWA,GAAQ,EAEzB,MAAM,MAAA;AAAA,KAAe;AAAA,EAC9B,GAAG,CAACT,GAASO,CAAM,CAAC;AACxB;"}
|
package/dist/geist-font.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import a from "./vendor/@fontsource/geist-sans/files/geist-sans-latin-400-normal.woff2.js";
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
{ weight: 400, src: a, range:
|
|
5
|
-
{ weight: 500, src:
|
|
6
|
-
],
|
|
7
|
-
|
|
8
|
-
const l = () => {
|
|
9
|
-
if (e || typeof document > "u" || !document.head)
|
|
2
|
+
import U from "./vendor/@fontsource/geist-sans/files/geist-sans-latin-500-normal.woff2.js";
|
|
3
|
+
const e = "U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD", r = [
|
|
4
|
+
{ weight: 400, src: a, range: e },
|
|
5
|
+
{ weight: 500, src: U, range: e }
|
|
6
|
+
], n = "malachite-geist-font-face", d = () => {
|
|
7
|
+
if (typeof document > "u" || !document.head || document.getElementById(n))
|
|
10
8
|
return;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const i = U.map(
|
|
16
|
-
({ weight: s, src: c, range: r }) => `@font-face{font-family:'Geist';font-style:normal;font-weight:${s};font-display:swap;src:url('${c}') format('woff2');unicode-range:${r};}`
|
|
9
|
+
const o = r.map(
|
|
10
|
+
({ weight: s, src: c, range: i }) => `@font-face{font-family:'Geist';font-style:normal;font-weight:${s};font-display:swap;src:url('${c}') format('woff2');unicode-range:${i};}`
|
|
17
11
|
).join(""), t = document.createElement("style");
|
|
18
|
-
t.id =
|
|
12
|
+
t.id = n, t.textContent = o, document.head.appendChild(t);
|
|
19
13
|
};
|
|
20
14
|
export {
|
|
21
|
-
|
|
15
|
+
d as ensureGeistFontFace
|
|
22
16
|
};
|
|
23
17
|
//# sourceMappingURL=geist-font.js.map
|
package/dist/geist-font.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geist-font.js","sources":["../src/geist-font.ts"],"sourcesContent":["// Self-hosted Geist webfont for Malachite — the body typeface of the new type system.\n//\n// Same constraint as Inter (see inter-font.ts): Malachite renders inside a shadow root and\n// @font-face rules don't load fonts from inside a shadow root, so the declarations are\n// injected into document.head once, the first time a
|
|
1
|
+
{"version":3,"file":"geist-font.js","sources":["../src/geist-font.ts"],"sourcesContent":["// Self-hosted Geist webfont for Malachite — the body typeface of the new type system.\n//\n// Same constraint as Inter (see inter-font.ts): Malachite renders inside a shadow root and\n// @font-face rules don't load fonts from inside a shadow root, so the declarations are\n// injected into document.head once, the first time a component that uses it renders. The\n// --font-body theme token (see tailwind.css) then resolves to it.\nimport geistLatin400 from '@fontsource/geist-sans/files/geist-sans-latin-400-normal.woff2';\nimport geistLatin500 from '@fontsource/geist-sans/files/geist-sans-latin-500-normal.woff2';\n\nconst LATIN_RANGE =\n 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD';\n\nconst FACES: ReadonlyArray<{ weight: number; src: string; range: string }> = [\n { weight: 400, src: geistLatin400, range: LATIN_RANGE },\n { weight: 500, src: geistLatin500, range: LATIN_RANGE },\n];\n\nconst STYLE_ID = 'malachite-geist-font-face';\n\nexport const ensureGeistFontFace = (): void => {\n if (typeof document === 'undefined' || !document.head || document.getElementById(STYLE_ID)) {\n return;\n }\n const css = FACES.map(\n ({ weight, src, range }) =>\n `@font-face{font-family:'Geist';font-style:normal;font-weight:${weight};font-display:swap;src:url('${src}') format('woff2');unicode-range:${range};}`,\n ).join('');\n const style = document.createElement('style');\n style.id = STYLE_ID;\n style.textContent = css;\n document.head.appendChild(style);\n};\n"],"names":["LATIN_RANGE","FACES","geistLatin400","geistLatin500","STYLE_ID","ensureGeistFontFace","css","weight","src","range","style"],"mappings":";;AASA,MAAMA,IACF,4JAEEC,IAAuE;AAAA,EACzE,EAAE,QAAQ,KAAK,KAAKC,GAAe,OAAOF,EAAA;AAAA,EAC1C,EAAE,QAAQ,KAAK,KAAKG,GAAe,OAAOH,EAAA;AAC9C,GAEMI,IAAW,6BAEJC,IAAsB,MAAY;AAC3C,MAAI,OAAO,WAAa,OAAe,CAAC,SAAS,QAAQ,SAAS,eAAeD,CAAQ;AACrF;AAEJ,QAAME,IAAML,EAAM;AAAA,IACd,CAAC,EAAE,QAAAM,GAAQ,KAAAC,GAAK,OAAAC,EAAA,MACZ,gEAAgEF,CAAM,+BAA+BC,CAAG,oCAAoCC,CAAK;AAAA,EAAA,EACvJ,KAAK,EAAE,GACHC,IAAQ,SAAS,cAAc,OAAO;AAC5C,EAAAA,EAAM,KAAKN,GACXM,EAAM,cAAcJ,GACpB,SAAS,KAAK,YAAYI,CAAK;AACnC;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3517,6 +3517,11 @@ declare interface MalachiteContextProps {
|
|
|
3517
3517
|
* page paints over its edge toggle and anything else that overhangs it.
|
|
3518
3518
|
*/
|
|
3519
3519
|
layer?: MalachiteLayer;
|
|
3520
|
+
/**
|
|
3521
|
+
* Set `false` to skip Malachite's font injection entirely, for a consumer that loads Inter
|
|
3522
|
+
* (and any other family it uses) itself. Defaults to on.
|
|
3523
|
+
*/
|
|
3524
|
+
injectFonts?: boolean;
|
|
3520
3525
|
}
|
|
3521
3526
|
|
|
3522
3527
|
declare type MalachiteLayer = 'page' | 'sidebar';
|
|
@@ -6071,7 +6076,8 @@ export declare interface TextProps {
|
|
|
6071
6076
|
size?: FontSize;
|
|
6072
6077
|
/**
|
|
6073
6078
|
* Typeface. Defaults to `sans` (Inter), the library's body face. `heading` is Stack Sans
|
|
6074
|
-
* Text and `body` is Geist
|
|
6079
|
+
* Text and `body` is Geist. Each is injected only when a `Text` asks for it, and declared
|
|
6080
|
+
* in the theme.
|
|
6075
6081
|
*/
|
|
6076
6082
|
font?: FontFamily;
|
|
6077
6083
|
underline?: boolean;
|