@bigpixelrocket/uiok 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/CHANGELOG.md +95 -1
  2. package/README.md +1 -1
  3. package/dist/activity/ActivityBar.d.ts +21 -8
  4. package/dist/activity/ActivityBar.js +15 -5
  5. package/dist/activity/activity.css +53 -6
  6. package/dist/button/Button.d.ts +10 -6
  7. package/dist/button/Button.js +6 -1
  8. package/dist/button/button.css +201 -33
  9. package/dist/charts/Line.logic.d.ts +6 -0
  10. package/dist/charts/Line.logic.js +9 -0
  11. package/dist/charts/LineChart.js +11 -4
  12. package/dist/charts/Pie.logic.d.ts +89 -1
  13. package/dist/charts/Pie.logic.js +272 -2
  14. package/dist/charts/PieChart.d.ts +2 -1
  15. package/dist/charts/PieChart.js +12 -5
  16. package/dist/charts/PieFill.d.ts +15 -0
  17. package/dist/charts/PieFill.js +33 -0
  18. package/dist/charts/ResultChart.d.ts +2 -2
  19. package/dist/charts/ResultChart.js +173 -47
  20. package/dist/charts/ResultChart.logic.d.ts +60 -4
  21. package/dist/charts/ResultChart.logic.js +105 -6
  22. package/dist/charts/Scatter.logic.d.ts +18 -4
  23. package/dist/charts/Scatter.logic.js +98 -22
  24. package/dist/charts/ScatterChart.js +19 -5
  25. package/dist/charts/charts.css +233 -116
  26. package/dist/charts/seriesColour.d.ts +2 -0
  27. package/dist/charts/seriesColour.js +1 -1
  28. package/dist/datetime/DateTimePicker.d.ts +12 -2
  29. package/dist/datetime/DateTimePicker.js +61 -16
  30. package/dist/datetime/DateTimePicker.logic.d.ts +29 -0
  31. package/dist/datetime/DateTimePicker.logic.js +25 -0
  32. package/dist/datetime/datetime.css +89 -49
  33. package/dist/dialog/ConfirmDialog.d.ts +69 -20
  34. package/dist/dialog/ConfirmDialog.js +39 -12
  35. package/dist/dialog/DialogLayer.d.ts +25 -0
  36. package/dist/dialog/DialogLayer.js +24 -0
  37. package/dist/dialog/DialogLegend.d.ts +2 -1
  38. package/dist/dialog/DialogLegend.js +10 -5
  39. package/dist/dialog/DialogLegend.logic.d.ts +15 -3
  40. package/dist/dialog/DialogLegend.logic.js +8 -4
  41. package/dist/dialog/DialogLists.d.ts +157 -0
  42. package/dist/dialog/DialogLists.js +137 -0
  43. package/dist/dialog/ModalDialog.d.ts +20 -15
  44. package/dist/dialog/ModalDialog.js +22 -7
  45. package/dist/dialog/dialog.css +570 -127
  46. package/dist/dialog/index.d.ts +7 -1
  47. package/dist/dialog/index.js +7 -1
  48. package/dist/field/Check.d.ts +15 -0
  49. package/dist/field/Check.js +23 -0
  50. package/dist/field/field.css +812 -0
  51. package/dist/field/index.d.ts +10 -0
  52. package/dist/field/index.js +10 -0
  53. package/dist/field/labelHelp.d.ts +33 -0
  54. package/dist/field/labelHelp.js +22 -0
  55. package/dist/filter/FilterIcon.js +2 -1
  56. package/dist/filter/filter.css +72 -20
  57. package/dist/grid/DataGrid.d.ts +8 -1
  58. package/dist/grid/DataGrid.js +115 -40
  59. package/dist/grid/DataGrid.logic.d.ts +15 -3
  60. package/dist/grid/DataGrid.logic.js +18 -5
  61. package/dist/grid/grid.css +481 -56
  62. package/dist/icon/Spinner.d.ts +16 -0
  63. package/dist/icon/Spinner.js +13 -0
  64. package/dist/icon/index.d.ts +5 -0
  65. package/dist/icon/index.js +5 -0
  66. package/dist/icon/sizes.d.ts +19 -0
  67. package/dist/icon/sizes.js +19 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +2 -0
  70. package/dist/keychord/KeyChord.d.ts +12 -1
  71. package/dist/keychord/KeyChord.js +2 -2
  72. package/dist/keychord/index.d.ts +1 -1
  73. package/dist/keychord/keychord.css +87 -9
  74. package/dist/labels/dialog.d.ts +12 -1
  75. package/dist/labels/dialog.js +3 -1
  76. package/dist/labels/selectAll.d.ts +4 -4
  77. package/dist/labels/selectAll.js +1 -1
  78. package/dist/legend/KeyLegendStrip.js +1 -1
  79. package/dist/legend/legend.css +82 -57
  80. package/dist/listing/Listing.d.ts +17 -10
  81. package/dist/listing/Listing.js +33 -26
  82. package/dist/listing/listing.css +1665 -237
  83. package/dist/menu/menu.css +227 -67
  84. package/dist/menu/useBellBeat.js +2 -2
  85. package/dist/namecut/NameCut.d.ts +3 -1
  86. package/dist/namecut/NameCut.js +152 -5
  87. package/dist/namecut/NameCut.logic.d.ts +5 -3
  88. package/dist/namecut/NameCut.logic.js +20 -5
  89. package/dist/namecut/namecut.css +27 -7
  90. package/dist/pager/Pager.d.ts +12 -4
  91. package/dist/pager/Pager.js +21 -7
  92. package/dist/pager/pager.css +41 -30
  93. package/dist/palette/Palette.js +2 -1
  94. package/dist/palette/palette.css +121 -60
  95. package/dist/pane/PaneActions.d.ts +56 -14
  96. package/dist/pane/PaneActions.js +64 -16
  97. package/dist/pane/PaneFrame.d.ts +37 -5
  98. package/dist/pane/PaneFrame.js +246 -11
  99. package/dist/pane/index.d.ts +4 -2
  100. package/dist/pane/index.js +4 -2
  101. package/dist/pane/toolWords.d.ts +14 -0
  102. package/dist/pane/toolWords.js +26 -0
  103. package/dist/pane/useToolbarFit.d.ts +25 -0
  104. package/dist/pane/useToolbarFit.js +95 -0
  105. package/dist/run/RunHeader.d.ts +5 -3
  106. package/dist/run/RunHeader.js +11 -8
  107. package/dist/run/run.css +64 -79
  108. package/dist/segmented/SegmentedChoice.d.ts +18 -2
  109. package/dist/segmented/SegmentedChoice.js +18 -7
  110. package/dist/segmented/segmented.css +62 -22
  111. package/dist/selectall/SelectAllBar.d.ts +4 -3
  112. package/dist/selectall/SelectAllBar.js +4 -3
  113. package/dist/selectall/selectall.css +17 -12
  114. package/dist/shell/shell.css +1073 -0
  115. package/dist/styles.css +620 -22
  116. package/dist/surface/surface.css +154 -0
  117. package/dist/tabs/PageTabs.d.ts +10 -5
  118. package/dist/tabs/PageTabs.js +126 -37
  119. package/dist/tabs/tabs.css +131 -51
  120. package/dist/terminal/Terminal.js +3 -1
  121. package/dist/terminal/Terminal.logic.d.ts +5 -4
  122. package/dist/terminal/Terminal.logic.js +9 -4
  123. package/dist/terminal/TerminalMenu.d.ts +4 -1
  124. package/dist/terminal/TerminalMenu.js +12 -5
  125. package/dist/terminal/ghostty/contrast.logic.d.ts +45 -0
  126. package/dist/terminal/ghostty/contrast.logic.js +130 -0
  127. package/dist/terminal/ghostty/core.d.ts +6 -0
  128. package/dist/terminal/ghostty/renderer.d.ts +9 -2
  129. package/dist/terminal/ghostty/renderer.js +91 -14
  130. package/dist/terminal/ghostty/surface.d.ts +8 -0
  131. package/dist/terminal/ghostty/surface.js +27 -1
  132. package/dist/terminal/terminal.css +87 -61
  133. package/dist/text/text.css +16 -7
  134. package/dist/themes/catalog.js +4 -3
  135. package/dist/themes/themes.generated.css +1307 -264
  136. package/dist/themes/tokens.d.ts +69 -14
  137. package/dist/themes/tokens.js +920 -97
  138. package/dist/tokens.css +239 -0
  139. package/dist/tooltip/Tooltip.d.ts +6 -0
  140. package/dist/tooltip/Tooltip.js +48 -6
  141. package/dist/tooltip/Tooltip.logic.d.ts +89 -12
  142. package/dist/tooltip/Tooltip.logic.js +142 -20
  143. package/dist/tooltip/index.d.ts +1 -1
  144. package/dist/tooltip/index.js +1 -1
  145. package/dist/tooltip/tooltip.css +39 -9
  146. package/package.json +9 -3
@@ -0,0 +1,239 @@
1
+ /* The tokens no theme changes: every size, space, corner, line, timing,
2
+ height, layer, and focus geometry the library draws with. Themes change
3
+ colour only (themes.generated.css); everything here holds in every theme.
4
+ Component sheets read these instead of writing a number, and
5
+ test/tokenValues.test.ts fails on a raw value where a token exists.
6
+ docs/tokens.md says what each step is for and how they relate. */
7
+
8
+ :root {
9
+ /* Faces. Monospace for what a user could type or copy (names, paths,
10
+ values, commands, field contents, key caps, listing rows, title-strip
11
+ titles, the terminal); the interface face for sentences and for labels
12
+ that head data (column labels, group headings, button and form labels). */
13
+ --font-mono: 'SF Mono', ui-monospace, Menlo, monospace;
14
+ --font-ui: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
15
+
16
+ /* Type sizes, one per role:
17
+ - key: a letter or a word inside a key cap;
18
+ - caption: column and group labels, counts, pill tabs, chart labels,
19
+ uppercase headings;
20
+ - small: compact control labels, status lines, help text, dialog
21
+ titles, grid cells, tooltips;
22
+ - body: listing rows, regular Button labels, body text, the terminal;
23
+ - heading: a run headline and its clock, a Settings page title, a
24
+ card title, an empty or failed pane's heading;
25
+ - display: a startup or splash title. */
26
+ --font-size-key: 10px;
27
+ --font-size-caption: 11px;
28
+ --font-size-small: 12px;
29
+ --font-size-body: 13px;
30
+ --font-size-heading: 14px;
31
+ --font-size-display: 20px;
32
+
33
+ /* Line heights. compact sets 11 and 12 px text in one-line chrome; body
34
+ sets 13 and 14 px lines; prose is wrapped sentences; heading is titles.
35
+ A single-line control whose height the control sets uses 1. */
36
+ --line-height-compact: 16px;
37
+ --line-height-body: 20px;
38
+ --line-height-prose: 1.5;
39
+ --line-height-heading: 1.25;
40
+
41
+ /* Weights. medium heads data (column labels, strip links, tooltips);
42
+ strong marks control labels, titles, and the current item. */
43
+ --font-weight-regular: 400;
44
+ --font-weight-medium: 500;
45
+ --font-weight-strong: 600;
46
+
47
+ /* Letter-spacing of small uppercase headings. Key glyphs keep their own
48
+ spacing, which belongs to the glyph, not to a heading. */
49
+ --tracking-caps: 0.04em;
50
+
51
+ /* Spacing on a 2px grid: the step number times 2 is the pixel value.
52
+ Relationships: icon to label 6px (4px in 20px-high inline controls);
53
+ control to control 8px (2px inside one cluster); label or help to its
54
+ field 4px; form row to row 8px; section to section 16px; surface inset
55
+ 12px (4px for a menu, 16px for a page block). A 1px line or nudge stays
56
+ a literal: it is a line, not a space. Listing columns space in ch. */
57
+ --space-1: 2px;
58
+ --space-2: 4px;
59
+ --space-3: 6px;
60
+ --space-4: 8px;
61
+ --space-5: 10px;
62
+ --space-6: 12px;
63
+ --space-8: 16px;
64
+ --space-10: 20px;
65
+ --space-12: 24px;
66
+ --space-16: 32px;
67
+
68
+ /* Corners follow height: xs for marks and highlights; sm for parts and
69
+ controls up to 22px high and rows inside a menu; md for controls from
70
+ 24px, panes, cards, tooltips; lg for overlays (menus, dialogs, palettes,
71
+ popover panels); pill for pills, dots, and switch tracks. A corner
72
+ nested inside another is calc(var(--radius-x) - inset), so the two
73
+ stay concentric. */
74
+ --radius-xs: 2px;
75
+ --radius-sm: 4px;
76
+ --radius-md: 6px;
77
+ --radius-lg: 8px;
78
+ --radius-pill: 999px;
79
+
80
+ /* Line weights. line for every hairline, divider, and outline;
81
+ line-strong for state marks: the current tab's underline, a key cap's
82
+ foot, status bars, drop marks, and the focus ring. */
83
+ --line: 1px;
84
+ --line-strong: 2px;
85
+
86
+ /* Motion. Nothing animates in: a dialog, menu, palette, tooltip, or pill
87
+ appears at once, and a state change stays under 150ms. fast: hover,
88
+ focus, and press feedback, progress fills. base: a state change that
89
+ moves something (a width, a split), the longest a state change takes.
90
+ slow: a signal only, never a state change: a refusal's shake and red, a
91
+ bell. spin: one turn of a spinner, a cursor blink. ease-out eases a
92
+ signal; ease-in-out shakes; progress and spinners run linear. Under
93
+ reduced motion the one-shot durations are zero (the rule below), so a
94
+ transition written with them needs no query of its own; a loop still stops itself with animation: none. signal: a
95
+ change that carries meaning by colour alone (a refusal's red without its
96
+ shake); reduced motion keeps it, since nothing moves. loop: one sweep
97
+ of a slow loop that shows work without a figure (a loading shimmer).
98
+ notice: one beat of a flash that must be seen before it ends (a key
99
+ that just changed). */
100
+ --duration-fast: 120ms;
101
+ --duration-base: 120ms;
102
+ --duration-slow: 280ms;
103
+ --duration-signal: 280ms;
104
+ --duration-spin: 1s;
105
+ --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
106
+ --ease-in-out: ease-in-out;
107
+
108
+ /* The feedback transition of every control (Button, quiet actions, tabs,
109
+ segments, fields): its fills, outlines, rings, and words change at the
110
+ fast step together. */
111
+ --transition-control:
112
+ background-color var(--duration-fast), border-color var(--duration-fast),
113
+ box-shadow var(--duration-fast), color var(--duration-fast), filter var(--duration-fast);
114
+
115
+ /* Heights. Controls that share a row share a height:
116
+ - control-height: Button, IconButton, text field, select;
117
+ - control-height-sm: small Button, a dense form's field and select,
118
+ the segmented choice, legend slots, day cells, page tabs;
119
+ - control-height-xs: inline controls in a 24 to 26 px row or bar
120
+ (crumbs, quiet actions, row icon actions, pager steps, in-row
121
+ editors, the second strip's page tabs).
122
+ Rows and bars: row-height for a listing row or menu option;
123
+ row-height-dense for a grid row or column strip; bar-height for a path
124
+ bar, status line, or query row; bar-height-lg for a title
125
+ strip, key legend, or dialog legend. hit-target is the smallest pointer
126
+ target, whatever the drawn size (the .hit-target utility). */
127
+ --control-height: 28px;
128
+ --control-height-sm: 24px;
129
+ --control-height-xs: 20px;
130
+ --row-height: 24px;
131
+ --row-height-dense: 22px;
132
+ --bar-height: 26px;
133
+ --bar-height-lg: 34px;
134
+ --hit-target: 24px;
135
+
136
+ /* Focus. One ring for everything focusable: a 2px accent line outside the
137
+ control at focus-offset, so it follows the control's corner one pixel
138
+ out. focus-offset-flush puts it on the control's edge, for a compact
139
+ control in a bar with room around it, which keeps its corners;
140
+ focus-offset-inset draws it inside, only where a parent clips (a tab in
141
+ a scrolling strip, a segment in its track, a grid, a well). A text
142
+ field draws the same 2px edge without growing: its border plus a 1px
143
+ ring at flush offset. The ring's colour is always var(--accent), written
144
+ where the outline is drawn: a token holding it would resolve the accent
145
+ on :root and miss a theme preview scope's own. */
146
+ --focus-ring-width: var(--line-strong);
147
+ --focus-offset: 1px;
148
+ --focus-offset-flush: 0px;
149
+ --focus-offset-inset: -2px;
150
+
151
+ /* Icon sizes (lucide's size prop, and icons sized in CSS): sm beside 11
152
+ and 12 px text and in 20px inline controls; md beside 13px text in rows,
153
+ tabs, and buttons; lg for a dialog's title icon, empty-state actions,
154
+ and a row's product mark; xl for a picture-sized mark (an About
155
+ window, a splash), never over an empty state or a failure.
156
+ icon-column is the leading icon column of a row or menu
157
+ option. */
158
+ --icon-sm: 12px;
159
+ --icon-md: 14px;
160
+ --icon-lg: 16px;
161
+ --icon-xl: 28px;
162
+ --icon-column: var(--space-10);
163
+
164
+ /* A status or presence dot beside a name (a state mark, a running
165
+ marker): one diameter everywhere. A group's colour swatch, which must
166
+ read as a colour rather than a state, is larger: --space-4. */
167
+ --dot: 6px;
168
+
169
+ /* Layers. Overlay layering is decided here once, not with per-component
170
+ numbers. Inside a pane (its own stacking context):
171
+ - z-below: a backdrop drawn under its own box's content;
172
+ - z-raised: a sticky strip, a part lifted over its siblings;
173
+ - z-local-overlay: an overlay inside a pane;
174
+ - z-menu: a menu or popover anchored in a pane;
175
+ - z-drag: an item in the hand.
176
+ On the page:
177
+ - z-panel: floating panels inside a page;
178
+ - z-overlay: a page-level surface (a drop target, a full-screen page),
179
+ under dialogs and tooltips;
180
+ - z-dialog: modal dialogs and their backdrops, above every panel;
181
+ - z-dialog-popover: a popover opened from inside a dialog (the grid's
182
+ inline editor, a menu in a dialog);
183
+ - z-tooltip: the hover tooltip, above a dialog whose controls it names. */
184
+ --z-below: -1;
185
+ --z-raised: 1;
186
+ --z-local-overlay: 2;
187
+ --z-menu: 3;
188
+ --z-drag: 4;
189
+ --z-panel: 10;
190
+ --z-overlay: 15;
191
+ --z-dialog: 20;
192
+ --z-dialog-popover: 25;
193
+ --z-tooltip: 30;
194
+
195
+ /* Surfaces that float over other content (sticky headers, cards,
196
+ overlays) add --frost as a backdrop-filter so what scrolls under a
197
+ translucent layer blurs; the .frost utility in styles.css applies it.
198
+ One recipe for every frosted layer, the full-window backdrop of a
199
+ dialog included; its wash is --scrim. */
200
+ --frost: blur(24px) saturate(160%);
201
+ }
202
+
203
+ /* Reduced motion: every one-shot transition and animation written with the
204
+ duration tokens ends at once, except --duration-signal, which moves
205
+ nothing. Loops (spinners, stripes, blinks)
206
+ stop in their own component's query with animation: none. */
207
+ @media (prefers-reduced-motion: reduce) {
208
+ :root {
209
+ --duration-fast: 0ms;
210
+ --duration-base: 0ms;
211
+ --duration-slow: 0ms;
212
+ }
213
+ }
214
+
215
+ /* The edges .scroll-fade (styles.css) fades, typed so they animate along
216
+ the scroll position: lengths, 0 when nothing lies past an edge. */
217
+ @property --scroll-fade-start {
218
+ syntax: '<length>';
219
+ inherits: false;
220
+ initial-value: 0px;
221
+ }
222
+
223
+ @property --scroll-fade-end {
224
+ syntax: '<length>';
225
+ inherits: false;
226
+ initial-value: 0px;
227
+ }
228
+
229
+ @property --scroll-fade-inline-start {
230
+ syntax: '<length>';
231
+ inherits: false;
232
+ initial-value: 0px;
233
+ }
234
+
235
+ @property --scroll-fade-inline-end {
236
+ syntax: '<length>';
237
+ inherits: false;
238
+ initial-value: 0px;
239
+ }
@@ -14,6 +14,12 @@ import { type ReactElement } from 'react';
14
14
  * there is one: nothing outside that element is drawn, so a tooltip left on
15
15
  * the body would open behind a full-screen video.
16
16
  *
17
+ * A chord given as data is drawn with the key glyphs every legend uses, set
18
+ * without a frame; a chord given as text is printed as given. A tooltip
19
+ * from `cutTooltip` opens only while its element cuts its own text, in its
20
+ * element's face: monospace for a name or a status line. A tooltip marked as
21
+ * a value is set in monospace; one given a side opens beside its element.
22
+ *
17
23
  * The pointer alone opens it. A control keeps its own accessible name, and a
18
24
  * tooltip that says more than its element is also the element's description
19
25
  * (`describedTooltip`), so a screen reader misses nothing.
@@ -1,12 +1,48 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useRef, useState } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
- import { placeTooltip, TOOLTIP_DELAY_MS } from './Tooltip.logic.js';
4
+ import { KeyChord } from '../keychord/KeyChord.js';
5
+ import { cutsItsText, isMonospaceFamily, placeTooltip, TOOLTIP_DELAY_MS, tooltipChord } from './Tooltip.logic.js';
6
+ // A glyph button is told by what it is, a control, and then by its box (no
7
+ // wider than tall): a short label in a dialog's label column is as square
8
+ // as a glyph button but keeps its tooltip at its leading edge.
9
+ const GLYPH_CONTROL = "button, a[href], [role='button'], [role='tab'], [role='radio'], input";
10
+ const isGlyphButton = (anchor) => {
11
+ if (!anchor.matches(GLYPH_CONTROL)) {
12
+ return false;
13
+ }
14
+ const box = anchor.getBoundingClientRect();
15
+ return box.width <= box.height;
16
+ };
17
+ // The physical side a `data-tooltip-side` names, by the element's own direction.
18
+ const besideOf = (anchor, rtl) => {
19
+ const side = anchor.getAttribute('data-tooltip-side');
20
+ if (side !== 'start' && side !== 'end') {
21
+ return null;
22
+ }
23
+ return (side === 'end') !== rtl ? 'right' : 'left';
24
+ };
5
25
  const read = (anchor, pointerX) => {
6
26
  const label = anchor.getAttribute('data-tooltip');
7
- return label
8
- ? { anchor, label, shortcut: anchor.getAttribute('data-tooltip-shortcut'), pointerX }
9
- : null;
27
+ // A tooltip of the element's own text says nothing while that text is whole.
28
+ const cut = anchor.hasAttribute('data-tooltip-cut');
29
+ if (!label || (cut && !cutsItsText(anchor))) {
30
+ return null;
31
+ }
32
+ const style = getComputedStyle(anchor);
33
+ const rtl = style.direction === 'rtl';
34
+ return {
35
+ anchor,
36
+ label,
37
+ shortcut: anchor.getAttribute('data-tooltip-shortcut'),
38
+ chord: tooltipChord(anchor.getAttribute('data-tooltip-chord')),
39
+ pointerX,
40
+ // A cut text completes its own element, so it keeps that element's face.
41
+ value: anchor.hasAttribute('data-tooltip-value') || (cut && isMonospaceFamily(style.fontFamily)),
42
+ beside: besideOf(anchor, rtl),
43
+ above: anchor.getAttribute('data-tooltip-side') === 'above',
44
+ rtl
45
+ };
10
46
  };
11
47
  /**
12
48
  * The hover tooltip, drawn by the page instead of left to the system's
@@ -23,6 +59,12 @@ const read = (anchor, pointerX) => {
23
59
  * there is one: nothing outside that element is drawn, so a tooltip left on
24
60
  * the body would open behind a full-screen video.
25
61
  *
62
+ * A chord given as data is drawn with the key glyphs every legend uses, set
63
+ * without a frame; a chord given as text is printed as given. A tooltip
64
+ * from `cutTooltip` opens only while its element cuts its own text, in its
65
+ * element's face: monospace for a name or a status line. A tooltip marked as
66
+ * a value is set in monospace; one given a side opens beside its element.
67
+ *
26
68
  * The pointer alone opens it. A control keeps its own accessible name, and a
27
69
  * tooltip that says more than its element is also the element's description
28
70
  * (`describedTooltip`), so a screen reader misses nothing.
@@ -94,12 +136,12 @@ export function TooltipLayer() {
94
136
  if (!shown || !tip) {
95
137
  return;
96
138
  }
97
- const { left, top } = placeTooltip(shown.anchor.getBoundingClientRect(), { width: tip.offsetWidth, height: tip.offsetHeight }, { width: window.innerWidth, height: window.innerHeight }, shown.pointerX);
139
+ const { left, top } = placeTooltip(shown.anchor.getBoundingClientRect(), { width: tip.offsetWidth, height: tip.offsetHeight }, { width: window.innerWidth, height: window.innerHeight }, shown.pointerX, shown.beside, shown.rtl, isGlyphButton(shown.anchor), shown.above);
98
140
  tip.style.left = `${left}px`;
99
141
  tip.style.top = `${top}px`;
100
142
  }, [shown]);
101
143
  if (!shown) {
102
144
  return null;
103
145
  }
104
- return createPortal(_jsxs("div", { className: "tooltip", ref: tipRef, role: "tooltip", children: [_jsx("span", { className: "tooltip-label", children: shown.label }), shown.shortcut !== null && _jsx("span", { className: "tooltip-shortcut", children: shown.shortcut })] }), document.fullscreenElement ?? document.body);
146
+ return createPortal(_jsxs("div", { className: shown.value ? 'tooltip tooltip-value' : 'tooltip', ref: tipRef, role: "tooltip", children: [_jsx("span", { className: "tooltip-label", children: shown.label }), shown.chord !== null ? (_jsx("span", { className: "tooltip-shortcut tooltip-chord", children: _jsx(KeyChord, { chord: shown.chord }) })) : (shown.shortcut !== null && _jsx("span", { className: "tooltip-shortcut", children: shown.shortcut }))] }), document.fullscreenElement ?? document.body);
105
147
  }
@@ -1,23 +1,82 @@
1
+ import type { Chord } from '../keyboard/Keyboard.logic.js';
1
2
  /** The attributes that give an element a tooltip; `TooltipLayer` reads them on hover. */
2
3
  export interface TooltipAttributes {
3
4
  readonly 'data-tooltip'?: string;
5
+ /** The chord as text ("⌘T"), for a reader that does not draw key glyphs. */
4
6
  readonly 'data-tooltip-shortcut'?: string;
7
+ /** The chord as data, which `TooltipLayer` draws with the key glyphs of every legend. */
8
+ readonly 'data-tooltip-chord'?: string;
9
+ /** Present when the tooltip only shows while the element cuts its own text. */
10
+ readonly 'data-tooltip-cut'?: string;
11
+ /** Present when the text is a value (a path, a name), set in monospace. */
12
+ readonly 'data-tooltip-value'?: string;
13
+ /** The side the tooltip opens on, when not below its element. */
14
+ readonly 'data-tooltip-side'?: TooltipSide;
15
+ /** Present on a label that has help, which draws the help cue (a dashed underline). */
16
+ readonly 'data-label-help'?: string;
17
+ }
18
+ /**
19
+ * A side a tooltip may open on instead of below: `end` is the inline end of
20
+ * the element (right in a left-to-right page), `start` the other. A tool
21
+ * rail on a window's edge opens its tooltips toward the content so they
22
+ * never cover the next tool. `above` opens it over the element, or at its
23
+ * end where the window has no room above, so a label's help never covers
24
+ * the control under it.
25
+ */
26
+ export type TooltipSide = 'start' | 'end' | 'above';
27
+ /** How a tooltip is drawn and placed, beyond what it says. */
28
+ export interface TooltipOptions {
29
+ /**
30
+ * The text is a value the user could type or copy (a path, a name, a
31
+ * command): it is set in monospace, as the value is everywhere else.
32
+ */
33
+ readonly value?: boolean;
34
+ /** Open beside or above the element instead of below it. */
35
+ readonly side?: TooltipSide;
5
36
  }
6
37
  /**
7
38
  * Gives an element a tooltip: a short title and, for a verb the keyboard also
8
- * runs, its chord as text ("⌘T"). Spread the result onto the element; without
9
- * a label the element gets no tooltip. Every hover tooltip goes through
10
- * here, never the `title` attribute.
39
+ * runs, its chord. Pass the chord itself (`{ key: 't', meta: true }`) and the
40
+ * tooltip draws it with the same key glyphs as a legend's caps; a chord
41
+ * already written as text ("⌘T") is printed as given. Spread the result onto
42
+ * the element; without a label the element gets no tooltip. Every hover
43
+ * tooltip goes through here, never the `title` attribute. `options` may set
44
+ * the text in monospace (`value`) or open it beside the element (`side`).
45
+ */
46
+ export declare function tooltip(label: string | null | undefined, shortcut?: string | Chord | null, options?: TooltipOptions): TooltipAttributes;
47
+ /**
48
+ * Reads back a chord `tooltip()` wrote as data, or null when the attribute
49
+ * is missing or is not a chord, in which case the text form is shown.
50
+ */
51
+ export declare function tooltipChord(data: string | null): Chord | null;
52
+ /**
53
+ * An element's own text as its tooltip, shown only while the element cuts
54
+ * that text (an ellipsis on a name too long for its column), so a tooltip
55
+ * never repeats words that are already in full view. The element itself
56
+ * must be the box that clips (`overflow: hidden` with an ellipsis):
57
+ * `TooltipLayer` opens it only while the element's content is wider or
58
+ * taller than its box. Without a label the element gets no tooltip. The
59
+ * tooltip takes the element's face: an element set in monospace (a name, a
60
+ * status line) gets a monospace tooltip.
61
+ */
62
+ export declare function cutTooltip(label: string | null | undefined): TooltipAttributes;
63
+ /**
64
+ * Whether a computed `font-family` list is a monospace stack (its generic
65
+ * family is `monospace`), so a tooltip completing that text keeps its face.
11
66
  */
12
- export declare function tooltip(label: string | null | undefined, shortcut?: string | null): TooltipAttributes;
67
+ export declare function isMonospaceFamily(fontFamily: string): boolean;
68
+ /** Whether an element marked with `cutTooltip` cuts its text now, and so may show it. */
69
+ export declare function cutsItsText(element: Element): boolean;
13
70
  /**
14
71
  * A tooltip that tells more than its element already says: more than a
15
72
  * control's name (a whole path, what a press will do), or more than a label's
16
73
  * text (what a pill stands for, a failure's raw detail). The pointer alone
17
74
  * opens a tooltip, so the same text is the element's accessible description
18
- * and reaches a screen reader too.
75
+ * and reaches a screen reader too. Pass `{ value: true }` when the text is a
76
+ * path or a name, so it is set in monospace; `side` opens it beside the
77
+ * element.
19
78
  */
20
- export declare function describedTooltip(text: string | null | undefined): TooltipAttributes & {
79
+ export declare function describedTooltip(text: string | null | undefined, options?: TooltipOptions): TooltipAttributes & {
21
80
  readonly 'aria-description'?: string;
22
81
  };
23
82
  /** How long the pointer rests on a control before its tooltip opens. */
@@ -39,11 +98,29 @@ export interface TooltipPosition {
39
98
  readonly left: number;
40
99
  readonly top: number;
41
100
  }
101
+ /** The physical side a tooltip opens on, once the page's direction is known. */
102
+ export type TooltipBeside = 'left' | 'right';
42
103
  /**
43
- * Places a tooltip under its control, centred on it. A control wider than
44
- * its tooltip (a strip of empty ground) centres the tooltip on the pointer
45
- * instead, without letting it run past the control's ends, so the tooltip
46
- * opens where the eye is. It opens above when the window ends too soon below
47
- * and there is room above, and it slides sideways to stay inside the window.
104
+ * Places a tooltip under its control. A tooltip wider than its control hangs
105
+ * from the control's leading edge (the left, or the right in a right-to-left
106
+ * page), as a desktop tooltip starts where the pointer is, so one on a short
107
+ * label at the start of a row does not spread back over the pane beside it.
108
+ * A glyph button keeps its tooltip centred under it: the caller says
109
+ * which anchors are one (`glyph`, by what the anchor is: a control no wider
110
+ * than it is tall), so a short label, a status line, or any other text
111
+ * keeps the leading edge whatever its box; without `glyph` a box no wider
112
+ * than it is tall is taken for one. A control wider than its tooltip (a strip of empty
113
+ * ground) centres the tooltip on the pointer instead, without letting it run
114
+ * past the control's ends, so the tooltip opens where the eye is. It opens
115
+ * above when the window ends too soon below and there is room above, and it
116
+ * slides sideways to stay inside the window.
117
+ *
118
+ * Given `beside`, it opens on that side of the control instead, centred on
119
+ * its height and kept inside the window; on the other side when the window
120
+ * ends too soon, and below as usual when neither side has room.
121
+ *
122
+ * Given `preferAbove` (a label's help), it opens over the control, at the same
123
+ * edge; where the window has no room above, beside the control at its
124
+ * inline end, and below only when neither has room.
48
125
  */
49
- export declare function placeTooltip(anchor: TooltipAnchorBox, tip: TooltipExtent, viewport: TooltipExtent, pointerX: number): TooltipPosition;
126
+ export declare function placeTooltip(anchor: TooltipAnchorBox, tip: TooltipExtent, viewport: TooltipExtent, pointerX: number, beside?: TooltipBeside | null, rtl?: boolean, glyph?: boolean, preferAbove?: boolean): TooltipPosition;
@@ -1,26 +1,91 @@
1
+ import { chordGlyphs } from '../keyboard/KeyChord.logic.js';
2
+ const optionAttributes = (options) => ({
3
+ ...(options?.value ? { 'data-tooltip-value': '' } : {}),
4
+ ...(options?.side ? { 'data-tooltip-side': options.side } : {})
5
+ });
1
6
  /**
2
7
  * Gives an element a tooltip: a short title and, for a verb the keyboard also
3
- * runs, its chord as text ("⌘T"). Spread the result onto the element; without
4
- * a label the element gets no tooltip. Every hover tooltip goes through
5
- * here, never the `title` attribute.
8
+ * runs, its chord. Pass the chord itself (`{ key: 't', meta: true }`) and the
9
+ * tooltip draws it with the same key glyphs as a legend's caps; a chord
10
+ * already written as text ("⌘T") is printed as given. Spread the result onto
11
+ * the element; without a label the element gets no tooltip. Every hover
12
+ * tooltip goes through here, never the `title` attribute. `options` may set
13
+ * the text in monospace (`value`) or open it beside the element (`side`).
6
14
  */
7
- export function tooltip(label, shortcut) {
15
+ export function tooltip(label, shortcut, options) {
8
16
  if (!label) {
9
17
  return {};
10
18
  }
11
- return shortcut
12
- ? { 'data-tooltip': label, 'data-tooltip-shortcut': shortcut }
13
- : { 'data-tooltip': label };
19
+ const shown = { 'data-tooltip': label, ...optionAttributes(options) };
20
+ if (!shortcut) {
21
+ return shown;
22
+ }
23
+ return typeof shortcut === 'string'
24
+ ? { ...shown, 'data-tooltip-shortcut': shortcut }
25
+ : {
26
+ ...shown,
27
+ 'data-tooltip-shortcut': chordGlyphs(shortcut),
28
+ 'data-tooltip-chord': JSON.stringify(shortcut)
29
+ };
30
+ }
31
+ /**
32
+ * Reads back a chord `tooltip()` wrote as data, or null when the attribute
33
+ * is missing or is not a chord, in which case the text form is shown.
34
+ */
35
+ export function tooltipChord(data) {
36
+ if (data === null) {
37
+ return null;
38
+ }
39
+ try {
40
+ const parsed = JSON.parse(data);
41
+ const chord = parsed;
42
+ return chord !== null &&
43
+ typeof chord === 'object' &&
44
+ typeof chord.key === 'string' &&
45
+ ['ctrl', 'alt', 'shift', 'meta'].every((mod) => chord[mod] === undefined || typeof chord[mod] === 'boolean')
46
+ ? chord
47
+ : null;
48
+ }
49
+ catch {
50
+ return null;
51
+ }
52
+ }
53
+ /**
54
+ * An element's own text as its tooltip, shown only while the element cuts
55
+ * that text (an ellipsis on a name too long for its column), so a tooltip
56
+ * never repeats words that are already in full view. The element itself
57
+ * must be the box that clips (`overflow: hidden` with an ellipsis):
58
+ * `TooltipLayer` opens it only while the element's content is wider or
59
+ * taller than its box. Without a label the element gets no tooltip. The
60
+ * tooltip takes the element's face: an element set in monospace (a name, a
61
+ * status line) gets a monospace tooltip.
62
+ */
63
+ export function cutTooltip(label) {
64
+ return label ? { 'data-tooltip': label, 'data-tooltip-cut': '' } : {};
65
+ }
66
+ /**
67
+ * Whether a computed `font-family` list is a monospace stack (its generic
68
+ * family is `monospace`), so a tooltip completing that text keeps its face.
69
+ */
70
+ export function isMonospaceFamily(fontFamily) {
71
+ const families = fontFamily.split(',');
72
+ return families[families.length - 1]?.trim().replace(/['"]/g, '') === 'monospace';
73
+ }
74
+ /** Whether an element marked with `cutTooltip` cuts its text now, and so may show it. */
75
+ export function cutsItsText(element) {
76
+ return element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight;
14
77
  }
15
78
  /**
16
79
  * A tooltip that tells more than its element already says: more than a
17
80
  * control's name (a whole path, what a press will do), or more than a label's
18
81
  * text (what a pill stands for, a failure's raw detail). The pointer alone
19
82
  * opens a tooltip, so the same text is the element's accessible description
20
- * and reaches a screen reader too.
83
+ * and reaches a screen reader too. Pass `{ value: true }` when the text is a
84
+ * path or a name, so it is set in monospace; `side` opens it beside the
85
+ * element.
21
86
  */
22
- export function describedTooltip(text) {
23
- return text ? { ...tooltip(text), 'aria-description': text } : {};
87
+ export function describedTooltip(text, options) {
88
+ return text ? { ...tooltip(text, null, options), 'aria-description': text } : {};
24
89
  }
25
90
  /** How long the pointer rests on a control before its tooltip opens. */
26
91
  export const TOOLTIP_DELAY_MS = 500;
@@ -29,22 +94,79 @@ const GAP = 6;
29
94
  /** The closest a tooltip comes to the window's edge. */
30
95
  const MARGIN = 6;
31
96
  /**
32
- * Places a tooltip under its control, centred on it. A control wider than
33
- * its tooltip (a strip of empty ground) centres the tooltip on the pointer
34
- * instead, without letting it run past the control's ends, so the tooltip
35
- * opens where the eye is. It opens above when the window ends too soon below
36
- * and there is room above, and it slides sideways to stay inside the window.
97
+ * Places a tooltip under its control. A tooltip wider than its control hangs
98
+ * from the control's leading edge (the left, or the right in a right-to-left
99
+ * page), as a desktop tooltip starts where the pointer is, so one on a short
100
+ * label at the start of a row does not spread back over the pane beside it.
101
+ * A glyph button keeps its tooltip centred under it: the caller says
102
+ * which anchors are one (`glyph`, by what the anchor is: a control no wider
103
+ * than it is tall), so a short label, a status line, or any other text
104
+ * keeps the leading edge whatever its box; without `glyph` a box no wider
105
+ * than it is tall is taken for one. A control wider than its tooltip (a strip of empty
106
+ * ground) centres the tooltip on the pointer instead, without letting it run
107
+ * past the control's ends, so the tooltip opens where the eye is. It opens
108
+ * above when the window ends too soon below and there is room above, and it
109
+ * slides sideways to stay inside the window.
110
+ *
111
+ * Given `beside`, it opens on that side of the control instead, centred on
112
+ * its height and kept inside the window; on the other side when the window
113
+ * ends too soon, and below as usual when neither side has room.
114
+ *
115
+ * Given `preferAbove` (a label's help), it opens over the control, at the same
116
+ * edge; where the window has no room above, beside the control at its
117
+ * inline end, and below only when neither has room.
37
118
  */
38
- export function placeTooltip(anchor, tip, viewport, pointerX) {
119
+ export function placeTooltip(anchor, tip, viewport, pointerX, beside, rtl = false, glyph = anchor.width <= anchor.height, preferAbove = false) {
120
+ if (preferAbove) {
121
+ const over = anchor.top - GAP - tip.height;
122
+ if (over >= MARGIN) {
123
+ const below = placeTooltip(anchor, tip, viewport, pointerX, null, rtl, glyph);
124
+ return { left: below.left, top: over };
125
+ }
126
+ const end = rtl ? 'left' : 'right';
127
+ const right = anchor.left + anchor.width + GAP;
128
+ const left = anchor.left - GAP - tip.width;
129
+ const fits = end === 'right' ? right + tip.width <= viewport.width - MARGIN : left >= MARGIN;
130
+ if (fits)
131
+ return placeTooltip(anchor, tip, viewport, pointerX, end, rtl, glyph);
132
+ }
133
+ if (beside) {
134
+ const right = anchor.left + anchor.width + GAP;
135
+ const left = anchor.left - GAP - tip.width;
136
+ const fitsRight = right + tip.width <= viewport.width - MARGIN;
137
+ const fitsLeft = left >= MARGIN;
138
+ const x = beside === 'right'
139
+ ? fitsRight
140
+ ? right
141
+ : fitsLeft
142
+ ? left
143
+ : null
144
+ : fitsLeft
145
+ ? left
146
+ : fitsRight
147
+ ? right
148
+ : null;
149
+ if (x !== null) {
150
+ const middle = anchor.top + anchor.height / 2 - tip.height / 2;
151
+ return {
152
+ left: x,
153
+ top: Math.max(MARGIN, Math.min(middle, viewport.height - tip.height - MARGIN))
154
+ };
155
+ }
156
+ }
39
157
  const below = anchor.top + anchor.height + GAP;
40
158
  const above = anchor.top - GAP - tip.height;
41
159
  const fitsBelow = below + tip.height <= viewport.height - MARGIN;
42
160
  const half = tip.width / 2;
43
- const centre = anchor.width > tip.width
44
- ? Math.max(anchor.left + half, Math.min(pointerX, anchor.left + anchor.width - half))
45
- : anchor.left + anchor.width / 2;
161
+ const x = anchor.width > tip.width
162
+ ? Math.max(anchor.left + half, Math.min(pointerX, anchor.left + anchor.width - half)) - half
163
+ : glyph
164
+ ? anchor.left + anchor.width / 2 - half
165
+ : rtl
166
+ ? anchor.left + anchor.width - tip.width
167
+ : anchor.left;
46
168
  return {
47
- left: Math.max(MARGIN, Math.min(centre - half, viewport.width - tip.width - MARGIN)),
169
+ left: Math.max(MARGIN, Math.min(x, viewport.width - tip.width - MARGIN)),
48
170
  top: fitsBelow || above < MARGIN ? below : above
49
171
  };
50
172
  }
@@ -1,3 +1,3 @@
1
1
  /** The hover tooltip: `TooltipLayer`, mounted once, and the `tooltip()` attributes it reads. */
2
2
  export { TooltipLayer } from './Tooltip.js';
3
- export { describedTooltip, placeTooltip, tooltip, TOOLTIP_DELAY_MS, type TooltipAnchorBox, type TooltipAttributes, type TooltipExtent, type TooltipPosition } from './Tooltip.logic.js';
3
+ export { cutsItsText, cutTooltip, describedTooltip, placeTooltip, tooltip, TOOLTIP_DELAY_MS, tooltipChord, type TooltipAnchorBox, type TooltipAttributes, type TooltipBeside, type TooltipExtent, type TooltipOptions, type TooltipPosition, type TooltipSide } from './Tooltip.logic.js';