ochreui 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +153 -2
- package/cli/ochreui.mjs +601 -0
- package/mcp/core.mjs +126 -0
- package/mcp/docs.json +906 -0
- package/mcp/server.mjs +23 -0
- package/package.json +393 -3
- package/registry/agent-team.ts +350 -0
- package/registry/avatar.ts +300 -0
- package/registry/badge.ts +207 -0
- package/registry/breadcrumb.ts +435 -0
- package/registry/button.ts +238 -0
- package/registry/card.ts +221 -0
- package/registry/change-summary.ts +200 -0
- package/registry/checkbox.ts +204 -0
- package/registry/code-block.ts +332 -0
- package/registry/color-picker.ts +720 -0
- package/registry/comment-thread.ts +503 -0
- package/registry/context-menu.ts +281 -0
- package/registry/cover-flow.ts +623 -0
- package/registry/date-picker.ts +799 -0
- package/registry/decision-inbox.ts +340 -0
- package/registry/dialog.ts +577 -0
- package/registry/dropdown-menu.ts +864 -0
- package/registry/email-draft.ts +916 -0
- package/registry/empty-calendar.ts +199 -0
- package/registry/empty-state.ts +164 -0
- package/registry/enrichment-orbit.ts +164 -0
- package/registry/filter-menu.ts +541 -0
- package/registry/form-field.ts +308 -0
- package/registry/frost-cloud.ts +381 -0
- package/registry/ghosted-chat.ts +210 -0
- package/registry/glow-cloud.ts +402 -0
- package/registry/grid-background.ts +164 -0
- package/registry/hover-card.ts +401 -0
- package/registry/icon-button.ts +133 -0
- package/registry/index.json +2124 -0
- package/registry/integration-beam.ts +588 -0
- package/registry/integration-grid.ts +209 -0
- package/registry/kbd.ts +176 -0
- package/registry/layer-stack.ts +351 -0
- package/registry/lead-sourcing.ts +285 -0
- package/registry/logo-cluster.ts +239 -0
- package/registry/logo-marquee.ts +505 -0
- package/registry/message-actions.ts +833 -0
- package/registry/model-orbit.ts +583 -0
- package/registry/model-wheel.ts +372 -0
- package/registry/notification-stack.ts +301 -0
- package/registry/number-input.ts +552 -0
- package/registry/number-ticker.ts +261 -0
- package/registry/ochre.css +917 -0
- package/registry/otp-input.ts +704 -0
- package/registry/overlay.ts +312 -0
- package/registry/pagination.ts +362 -0
- package/registry/popover.ts +296 -0
- package/registry/profile-menu.ts +332 -0
- package/registry/progress-tracker.ts +291 -0
- package/registry/rating.ts +461 -0
- package/registry/reaction-bar.ts +322 -0
- package/registry/region-map.ts +537 -0
- package/registry/resizable.ts +489 -0
- package/registry/scroll-area.ts +271 -0
- package/registry/segmented-control.ts +433 -0
- package/registry/select.ts +769 -0
- package/registry/separator.ts +97 -0
- package/registry/shimmer-loader.ts +211 -0
- package/registry/side-folder.ts +152 -0
- package/registry/skeleton.ts +136 -0
- package/registry/skill/INSTRUCTIONS.md +11 -0
- package/registry/skill/SKILL.md +65 -0
- package/registry/skill/checklist.md +45 -0
- package/registry/skill/references/agent-team.md +105 -0
- package/registry/skill/references/avatar.md +88 -0
- package/registry/skill/references/badge.md +92 -0
- package/registry/skill/references/breadcrumb.md +99 -0
- package/registry/skill/references/button.md +82 -0
- package/registry/skill/references/card.md +111 -0
- package/registry/skill/references/catalog.md +114 -0
- package/registry/skill/references/change-summary.md +103 -0
- package/registry/skill/references/checkbox.md +105 -0
- package/registry/skill/references/code-block.md +109 -0
- package/registry/skill/references/color-picker.md +138 -0
- package/registry/skill/references/comment-thread.md +164 -0
- package/registry/skill/references/context-menu.md +205 -0
- package/registry/skill/references/cover-flow.md +128 -0
- package/registry/skill/references/date-picker.md +154 -0
- package/registry/skill/references/decision-inbox.md +126 -0
- package/registry/skill/references/dialog.md +155 -0
- package/registry/skill/references/dropdown-menu.md +144 -0
- package/registry/skill/references/email-draft.md +182 -0
- package/registry/skill/references/empty-calendar.md +74 -0
- package/registry/skill/references/empty-state.md +118 -0
- package/registry/skill/references/enrichment-orbit.md +71 -0
- package/registry/skill/references/filter-menu.md +143 -0
- package/registry/skill/references/form-field.md +118 -0
- package/registry/skill/references/frost-cloud.md +80 -0
- package/registry/skill/references/ghosted-chat.md +75 -0
- package/registry/skill/references/glow-cloud.md +84 -0
- package/registry/skill/references/grid-background.md +76 -0
- package/registry/skill/references/hover-card.md +125 -0
- package/registry/skill/references/icon-button.md +99 -0
- package/registry/skill/references/integration-beam.md +107 -0
- package/registry/skill/references/integration-grid.md +100 -0
- package/registry/skill/references/kbd.md +65 -0
- package/registry/skill/references/layer-stack.md +115 -0
- package/registry/skill/references/lead-sourcing.md +92 -0
- package/registry/skill/references/logo-cluster.md +92 -0
- package/registry/skill/references/logo-marquee.md +123 -0
- package/registry/skill/references/message-actions.md +146 -0
- package/registry/skill/references/model-orbit.md +106 -0
- package/registry/skill/references/model-wheel.md +84 -0
- package/registry/skill/references/notification-stack.md +138 -0
- package/registry/skill/references/number-input.md +117 -0
- package/registry/skill/references/number-ticker.md +73 -0
- package/registry/skill/references/otp-input.md +142 -0
- package/registry/skill/references/pagination.md +112 -0
- package/registry/skill/references/popover.md +143 -0
- package/registry/skill/references/profile-menu.md +123 -0
- package/registry/skill/references/progress-tracker.md +122 -0
- package/registry/skill/references/rating.md +111 -0
- package/registry/skill/references/reaction-bar.md +128 -0
- package/registry/skill/references/region-map.md +109 -0
- package/registry/skill/references/resizable.md +127 -0
- package/registry/skill/references/scroll-area.md +113 -0
- package/registry/skill/references/segmented-control.md +96 -0
- package/registry/skill/references/select.md +122 -0
- package/registry/skill/references/separator.md +69 -0
- package/registry/skill/references/shimmer-loader.md +83 -0
- package/registry/skill/references/side-folder.md +75 -0
- package/registry/skill/references/skeleton.md +95 -0
- package/registry/skill/references/smart-recommendation.md +132 -0
- package/registry/skill/references/spinner.md +84 -0
- package/registry/skill/references/switch.md +79 -0
- package/registry/skill/references/tab-overload.md +70 -0
- package/registry/skill/references/tag-input.md +126 -0
- package/registry/skill/references/team-invite.md +94 -0
- package/registry/skill/references/testimonial-wall.md +110 -0
- package/registry/skill/references/text-area.md +115 -0
- package/registry/skill/references/text-field.md +126 -0
- package/registry/skill/references/text-reveal.md +71 -0
- package/registry/skill/references/thinking-loader.md +87 -0
- package/registry/skill/references/time-picker.md +122 -0
- package/registry/skill/references/tips-panel.md +115 -0
- package/registry/skill/references/toggle-group.md +98 -0
- package/registry/skill/references/tool-call-card.md +151 -0
- package/registry/skill/references/tooltip.md +94 -0
- package/registry/skill/references/tree-view.md +172 -0
- package/registry/skill/theming.md +57 -0
- package/registry/smart-recommendation.ts +415 -0
- package/registry/spinner.ts +67 -0
- package/registry/switch.ts +146 -0
- package/registry/tab-overload.ts +211 -0
- package/registry/tag-input.ts +620 -0
- package/registry/team-invite.ts +248 -0
- package/registry/testimonial-wall.ts +521 -0
- package/registry/text-area.ts +432 -0
- package/registry/text-field.ts +415 -0
- package/registry/text-reveal.ts +175 -0
- package/registry/theme.ts +68 -0
- package/registry/thinking-loader.ts +302 -0
- package/registry/time-picker.ts +828 -0
- package/registry/tips-panel.ts +312 -0
- package/registry/toggle-group.ts +357 -0
- package/registry/tool-call-card.ts +578 -0
- package/registry/tooltip.ts +486 -0
- package/registry/tree-view.ts +454 -0
- package/styles/base.css +500 -0
- package/styles/tokens.css +415 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Tooltip, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens), added once by `npx ochreui init`.
|
|
5
|
+
*
|
|
6
|
+
* <button uiTooltip="Search" uiTooltipShortcut="⌘K"> shows a small label after a short pointer rest, and at
|
|
7
|
+
* once on keyboard focus. It stays on screen, Escape hides it, and touch screens never show it.
|
|
8
|
+
*
|
|
9
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
10
|
+
* --ui-tooltip-bg fill (default: the inverted neutral, dark on light pages)
|
|
11
|
+
* --ui-tooltip-fg text
|
|
12
|
+
* --ui-tooltip-max-width where text wraps (default 240px)
|
|
13
|
+
* --ui-tooltip-drift how far it glides in from the trigger (default 2px; Classic 3px)
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
Component,
|
|
17
|
+
ComponentRef,
|
|
18
|
+
DOCUMENT,
|
|
19
|
+
DestroyRef,
|
|
20
|
+
Directive,
|
|
21
|
+
ElementRef,
|
|
22
|
+
PLATFORM_ID,
|
|
23
|
+
Service,
|
|
24
|
+
ViewContainerRef,
|
|
25
|
+
booleanAttribute,
|
|
26
|
+
computed,
|
|
27
|
+
effect,
|
|
28
|
+
inject,
|
|
29
|
+
input,
|
|
30
|
+
isDevMode,
|
|
31
|
+
numberAttribute,
|
|
32
|
+
output,
|
|
33
|
+
signal,
|
|
34
|
+
untracked,
|
|
35
|
+
} from '@angular/core';
|
|
36
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
37
|
+
|
|
38
|
+
export type TooltipSide = 'top' | 'bottom' | 'left' | 'right';
|
|
39
|
+
export type TooltipAlign = 'start' | 'center' | 'end';
|
|
40
|
+
|
|
41
|
+
const MARGIN = 8;
|
|
42
|
+
const GRACE = 120;
|
|
43
|
+
const SKIP = 300;
|
|
44
|
+
|
|
45
|
+
const SPOKEN: Record<string, string> = {
|
|
46
|
+
'⌘': 'Command', '⌃': 'Control', '⌥': 'Option', '⇧': 'Shift', '↵': 'Return', '⏎': 'Return', '⇥': 'Tab',
|
|
47
|
+
'⌫': 'Backspace', '⌦': 'Delete', '⎋': 'Escape', '↑': 'Up arrow', '↓': 'Down arrow', '←': 'Left arrow', '→': 'Right arrow',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** "⇧⌘S" → "Shift Command S". Words such as "Ctrl+K" are read as written. */
|
|
51
|
+
export function spokenShortcut(keys: string): string {
|
|
52
|
+
return [...keys.trim()]
|
|
53
|
+
.map((c) => (SPOKEN[c] ? ` ${SPOKEN[c]} ` : c))
|
|
54
|
+
.join('')
|
|
55
|
+
.replace(/\s*\+\s*/g, ' ')
|
|
56
|
+
.replace(/\s+/g, ' ')
|
|
57
|
+
.trim();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Rect { top: number; left: number; right: number; bottom: number; width: number; height: number }
|
|
61
|
+
|
|
62
|
+
/** Where the label goes: the preferred side unless the other one has more room, then pushed inside the window. */
|
|
63
|
+
export function placeTooltip(
|
|
64
|
+
trigger: Rect,
|
|
65
|
+
size: { width: number; height: number },
|
|
66
|
+
view: { width: number; height: number },
|
|
67
|
+
side: TooltipSide,
|
|
68
|
+
align: TooltipAlign,
|
|
69
|
+
offset: number,
|
|
70
|
+
rtl = false,
|
|
71
|
+
): { side: TooltipSide; x: number; y: number } {
|
|
72
|
+
const room: Record<TooltipSide, number> = {
|
|
73
|
+
top: trigger.top - MARGIN,
|
|
74
|
+
bottom: view.height - trigger.bottom - MARGIN,
|
|
75
|
+
left: trigger.left - MARGIN,
|
|
76
|
+
right: view.width - trigger.right - MARGIN,
|
|
77
|
+
};
|
|
78
|
+
const across = (s: TooltipSide) => s === 'left' || s === 'right';
|
|
79
|
+
const need = (s: TooltipSide) => offset + (across(s) ? size.width : size.height);
|
|
80
|
+
const other: Record<TooltipSide, TooltipSide> = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' };
|
|
81
|
+
if (room[side] < need(side) && room[other[side]] > room[side]) side = other[side];
|
|
82
|
+
if (across(side) && room[side] < need(side)) side = room.top >= need('top') || room.top >= room.bottom ? 'top' : 'bottom';
|
|
83
|
+
|
|
84
|
+
const clamp = (v: number, span: number, total: number) => Math.min(Math.max(v, MARGIN), Math.max(MARGIN, total - MARGIN - span));
|
|
85
|
+
if (across(side)) {
|
|
86
|
+
const x = side === 'left' ? trigger.left - offset - size.width : trigger.right + offset;
|
|
87
|
+
const y = align === 'start' ? trigger.top : align === 'end' ? trigger.bottom - size.height : trigger.top + (trigger.height - size.height) / 2;
|
|
88
|
+
return { side, x, y: clamp(y, size.height, view.height) };
|
|
89
|
+
}
|
|
90
|
+
const first = rtl ? 'end' : 'start';
|
|
91
|
+
const x = align === 'center' ? trigger.left + (trigger.width - size.width) / 2 : align === first ? trigger.left : trigger.right - size.width;
|
|
92
|
+
const y = side === 'top' ? trigger.top - offset - size.height : trigger.bottom + offset;
|
|
93
|
+
return { side, x: clamp(x, size.width, view.width), y };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One tooltip at a time on the page, and the short window in which a neighbour shows without waiting. */
|
|
97
|
+
@Service()
|
|
98
|
+
export class UiTooltipStack {
|
|
99
|
+
current: UiTooltip | null = null;
|
|
100
|
+
closedAt = -Infinity;
|
|
101
|
+
|
|
102
|
+
warm(now: number) {
|
|
103
|
+
return this.current !== null || now - this.closedAt < SKIP;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let nextId = 0;
|
|
108
|
+
|
|
109
|
+
/** The label itself. Created next to the trigger while it shows, and promoted to the top layer. */
|
|
110
|
+
@Component({
|
|
111
|
+
selector: 'ui-tooltip',
|
|
112
|
+
host: {
|
|
113
|
+
role: 'tooltip',
|
|
114
|
+
popover: 'manual',
|
|
115
|
+
'[id]': 'id()',
|
|
116
|
+
'[attr.data-side]': 'side()',
|
|
117
|
+
'[class]': 'extraClass()',
|
|
118
|
+
'(pointerenter)': 'hover.emit(true)',
|
|
119
|
+
'(pointerleave)': 'hover.emit(false)',
|
|
120
|
+
},
|
|
121
|
+
template:
|
|
122
|
+
'<span dir="auto">{{ text() }}</span>@if (shortcut()) {<kbd [id]="id() + \'-keys\'"><span aria-hidden="true">{{ shortcut() }}</span><span class="sr">{{ spoken() }}</span></kbd>}',
|
|
123
|
+
styles: `
|
|
124
|
+
:host {
|
|
125
|
+
--_t: var(--ui-look-tray, 0);
|
|
126
|
+
--_d: calc(var(--ui-tooltip-drift, 2px) + 1px * var(--_t));
|
|
127
|
+
--_x: 0;
|
|
128
|
+
--_y: 0;
|
|
129
|
+
position: fixed;
|
|
130
|
+
inset: auto;
|
|
131
|
+
z-index: var(--ui-z-popover);
|
|
132
|
+
display: flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
gap: calc(var(--ui-space-1-5) + var(--ui-space-0-5) * var(--_t));
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
max-inline-size: min(var(--ui-tooltip-max-width, 240px), 100vw - 16px);
|
|
137
|
+
margin: 0;
|
|
138
|
+
padding: calc(var(--ui-space-1) - 1px + 1px * var(--_t)) calc(var(--ui-space-2) - 1px + 1px * var(--_t));
|
|
139
|
+
overflow: visible;
|
|
140
|
+
border: 1px solid transparent;
|
|
141
|
+
border-radius: calc(var(--ui-radius-sm) + 2px * var(--_t));
|
|
142
|
+
background: var(--ui-tooltip-bg, var(--ui-bg-neutral-solid));
|
|
143
|
+
box-shadow:
|
|
144
|
+
0 calc(4px + 4px * var(--_t)) calc(12px + 8px * var(--_t)) calc(-4px - 4px * var(--_t)) color-mix(in srgb, var(--ui-gray-1000) 30%, transparent),
|
|
145
|
+
0 2px 6px -2px color-mix(in srgb, var(--ui-gray-1000) calc(14% * var(--_t)), transparent);
|
|
146
|
+
color: var(--ui-tooltip-fg, var(--ui-text-on-neutral));
|
|
147
|
+
font: var(--ui-weight-medium) calc(var(--ui-text-sm) + 0.5px * var(--_t)) / calc(var(--ui-leading-xs) + 2px * var(--_t)) var(--ui-font-sans);
|
|
148
|
+
letter-spacing: calc(-0.005em * var(--_t));
|
|
149
|
+
overflow-wrap: anywhere;
|
|
150
|
+
transition: var(--ui-duration-2) var(--ui-ease-out);
|
|
151
|
+
transition-property: opacity, translate;
|
|
152
|
+
}
|
|
153
|
+
:host([data-side='top']) { --_y: var(--_d); }
|
|
154
|
+
:host([data-side='bottom']) { --_y: calc(var(--_d) * -1); }
|
|
155
|
+
:host([data-side='left']) { --_x: var(--_d); }
|
|
156
|
+
:host([data-side='right']) { --_x: calc(var(--_d) * -1); }
|
|
157
|
+
:host([data-enter]) { opacity: 0; translate: var(--_x) var(--_y); transition: none; }
|
|
158
|
+
kbd {
|
|
159
|
+
flex: none;
|
|
160
|
+
padding: 0 calc(5px * var(--_t));
|
|
161
|
+
border: 1px solid transparent;
|
|
162
|
+
border-width: 0 calc(1px * var(--_t));
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
background: color-mix(in srgb, currentColor calc(14% * var(--_t)), transparent);
|
|
165
|
+
color: color-mix(in srgb, currentColor 72%, transparent);
|
|
166
|
+
font: inherit;
|
|
167
|
+
font-size: calc(var(--ui-text-sm) - 1px * var(--_t));
|
|
168
|
+
line-height: var(--ui-leading-xs);
|
|
169
|
+
letter-spacing: 0.02em;
|
|
170
|
+
}
|
|
171
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
172
|
+
`,
|
|
173
|
+
})
|
|
174
|
+
export class UiTooltipPanel {
|
|
175
|
+
readonly id = input.required<string>();
|
|
176
|
+
readonly text = input('');
|
|
177
|
+
readonly shortcut = input<string>();
|
|
178
|
+
readonly side = input<TooltipSide>('top');
|
|
179
|
+
readonly extraClass = input<string>();
|
|
180
|
+
readonly hover = output<boolean>();
|
|
181
|
+
protected readonly spoken = computed(() => spokenShortcut(this.shortcut() ?? ''));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Puts a tooltip on any focusable element: `<button uiTooltip="Search runs" uiTooltipShortcut="⌘K">`.
|
|
186
|
+
* On an Icon Button, set `title=""` so the browser's own tooltip stays away.
|
|
187
|
+
*/
|
|
188
|
+
@Directive({
|
|
189
|
+
selector: '[uiTooltip]',
|
|
190
|
+
exportAs: 'uiTooltip',
|
|
191
|
+
host: {
|
|
192
|
+
'(pointerenter)': 'enter($event)',
|
|
193
|
+
'(pointerleave)': 'leave()',
|
|
194
|
+
'(focusin)': 'focus($event)',
|
|
195
|
+
'(focusout)': 'blur()',
|
|
196
|
+
'(click)': 'dismiss($event)',
|
|
197
|
+
'(keydown)': 'key($event)',
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
export class UiTooltip {
|
|
201
|
+
/** The label: a few words. Empty or null means no tooltip at all. */
|
|
202
|
+
readonly uiTooltip = input<string | null | undefined>();
|
|
203
|
+
/** A shortcut shown after the label, such as "⌘K" or "⇧⌘S". Screen readers hear it spelled out. */
|
|
204
|
+
readonly uiTooltipShortcut = input<string>();
|
|
205
|
+
/** The preferred side. It flips when the other side has more room. */
|
|
206
|
+
readonly uiTooltipSide = input<TooltipSide>('top');
|
|
207
|
+
/** Which edges line up. Start is the left edge, or the right one in right-to-left pages. */
|
|
208
|
+
readonly uiTooltipAlign = input<TooltipAlign>('center');
|
|
209
|
+
/** Gap to the trigger, in px. */
|
|
210
|
+
readonly uiTooltipOffset = input(6, { transform: numberAttribute });
|
|
211
|
+
/** How long the pointer rests before it shows, in ms. Keyboard focus and neighbours show it at once. */
|
|
212
|
+
readonly uiTooltipDelay = input(500, { transform: numberAttribute });
|
|
213
|
+
/** Never shows, for example while a label is not cut off. */
|
|
214
|
+
readonly uiTooltipDisabled = input(false, { transform: booleanAttribute });
|
|
215
|
+
/** Shows or hides it from your code: your value decides. Leave it unset and it opens on its own. */
|
|
216
|
+
readonly uiTooltipOpen = input<boolean | undefined>(undefined);
|
|
217
|
+
/** When it wants to open or close: hover, focus, Escape, a click. Bind `[(uiTooltipOpen)]` to follow it. */
|
|
218
|
+
readonly uiTooltipOpenChange = output<boolean>();
|
|
219
|
+
/** A class for the label, to style one tooltip. */
|
|
220
|
+
readonly uiTooltipClass = input<string>();
|
|
221
|
+
|
|
222
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
223
|
+
private readonly doc = inject(DOCUMENT);
|
|
224
|
+
private readonly vcr = inject(ViewContainerRef);
|
|
225
|
+
private readonly stack = inject(UiTooltipStack);
|
|
226
|
+
private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
227
|
+
private readonly id = `ui-tooltip-${nextId++}`;
|
|
228
|
+
|
|
229
|
+
private readonly self = signal(false);
|
|
230
|
+
private readonly shown = computed(() => {
|
|
231
|
+
const text = this.uiTooltip();
|
|
232
|
+
return !!text && !this.uiTooltipDisabled() && (this.uiTooltipOpen() ?? this.self());
|
|
233
|
+
});
|
|
234
|
+
private ref?: ComponentRef<UiTooltipPanel>;
|
|
235
|
+
private instant = false;
|
|
236
|
+
private via: 'pointer' | 'focus' | null = null;
|
|
237
|
+
private quiet = false;
|
|
238
|
+
private over = false;
|
|
239
|
+
private openTimer?: ReturnType<typeof setTimeout>;
|
|
240
|
+
private closeTimer?: ReturnType<typeof setTimeout>;
|
|
241
|
+
private frame = 0;
|
|
242
|
+
private described = '';
|
|
243
|
+
private warned = false;
|
|
244
|
+
private watch?: MutationObserver;
|
|
245
|
+
|
|
246
|
+
constructor() {
|
|
247
|
+
effect(() => {
|
|
248
|
+
const on = this.shown();
|
|
249
|
+
const off = !this.uiTooltip() || this.uiTooltipDisabled();
|
|
250
|
+
this.uiTooltipShortcut();
|
|
251
|
+
this.uiTooltipClass();
|
|
252
|
+
this.uiTooltipSide();
|
|
253
|
+
this.uiTooltipAlign();
|
|
254
|
+
this.uiTooltipOffset();
|
|
255
|
+
untracked(() => {
|
|
256
|
+
if (off) {
|
|
257
|
+
this.clear();
|
|
258
|
+
this.self.set(false);
|
|
259
|
+
}
|
|
260
|
+
if (on) this.mount();
|
|
261
|
+
else this.unmount();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
inject(DestroyRef).onDestroy(() => {
|
|
265
|
+
this.clear();
|
|
266
|
+
this.unmount();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Hides it now, as Escape does. */
|
|
271
|
+
hide() {
|
|
272
|
+
this.clear();
|
|
273
|
+
this.request(false);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected enter(event: PointerEvent) {
|
|
277
|
+
if (event.pointerType === 'touch') return;
|
|
278
|
+
this.over = true;
|
|
279
|
+
if (this.quiet || !this.uiTooltip() || this.uiTooltipDisabled()) return;
|
|
280
|
+
clearTimeout(this.closeTimer);
|
|
281
|
+
if (this.shown()) return;
|
|
282
|
+
this.via = 'pointer';
|
|
283
|
+
if (this.stack.warm(this.now())) {
|
|
284
|
+
this.instant = true;
|
|
285
|
+
this.request(true);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
clearTimeout(this.openTimer);
|
|
289
|
+
this.openTimer = setTimeout(() => {
|
|
290
|
+
this.instant = false;
|
|
291
|
+
this.request(true);
|
|
292
|
+
}, this.uiTooltipDelay());
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
protected leave() {
|
|
296
|
+
this.over = false;
|
|
297
|
+
this.quiet = false;
|
|
298
|
+
clearTimeout(this.openTimer);
|
|
299
|
+
if (this.shown() && this.via !== 'focus') this.closeSoon();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
protected focus(event: FocusEvent) {
|
|
303
|
+
const layers = (this.doc as unknown as Record<symbol, { returning?: Element | null } | undefined>)[Symbol.for('ochre.overlay')];
|
|
304
|
+
if (
|
|
305
|
+
event.target !== this.el ||
|
|
306
|
+
this.quiet ||
|
|
307
|
+
this.shown() ||
|
|
308
|
+
!this.el.matches(':focus-visible') ||
|
|
309
|
+
this.el.getAttribute('aria-expanded') === 'true' ||
|
|
310
|
+
layers?.returning === this.el
|
|
311
|
+
) return;
|
|
312
|
+
this.via = 'focus';
|
|
313
|
+
this.instant = this.stack.warm(this.now());
|
|
314
|
+
this.request(true);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
protected blur() {
|
|
318
|
+
this.quiet = false;
|
|
319
|
+
if (this.via === 'focus') this.hide();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
protected dismiss(event: Event) {
|
|
323
|
+
if (event.defaultPrevented) return;
|
|
324
|
+
this.quiet = true;
|
|
325
|
+
this.hide();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
protected key(event: KeyboardEvent) {
|
|
329
|
+
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
330
|
+
if (event.target === this.el && this.el.matches('button, a, summary, [role=button], [role=link]')) this.dismiss(event);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private now() {
|
|
334
|
+
return this.doc.defaultView?.performance.now() ?? 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private closeSoon() {
|
|
338
|
+
clearTimeout(this.closeTimer);
|
|
339
|
+
this.closeTimer = setTimeout(() => this.request(false), GRACE);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private clear() {
|
|
343
|
+
clearTimeout(this.openTimer);
|
|
344
|
+
clearTimeout(this.closeTimer);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private request(on: boolean) {
|
|
348
|
+
if (on === this.shown()) return;
|
|
349
|
+
this.self.set(on);
|
|
350
|
+
this.uiTooltipOpenChange.emit(on);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private readonly escape = (event: KeyboardEvent) => {
|
|
354
|
+
if (event.key !== 'Escape' || event.isComposing) return;
|
|
355
|
+
const here = this.el.contains(this.doc.activeElement);
|
|
356
|
+
if (here) {
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
event.stopPropagation();
|
|
359
|
+
}
|
|
360
|
+
if (here || this.over) this.quiet = true;
|
|
361
|
+
this.hide();
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
private readonly follow = () => {
|
|
365
|
+
this.doc.defaultView!.cancelAnimationFrame(this.frame);
|
|
366
|
+
this.frame = this.doc.defaultView!.requestAnimationFrame(() => this.place());
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
private mount() {
|
|
370
|
+
if (!this.browser) return;
|
|
371
|
+
const stack = this.stack;
|
|
372
|
+
if (stack.current && stack.current !== this) {
|
|
373
|
+
this.instant = true;
|
|
374
|
+
stack.current.hide();
|
|
375
|
+
}
|
|
376
|
+
stack.current = this;
|
|
377
|
+
|
|
378
|
+
const fresh = !this.ref;
|
|
379
|
+
const instant = this.instant;
|
|
380
|
+
this.instant = false;
|
|
381
|
+
if (!this.ref) {
|
|
382
|
+
this.ref = this.vcr.createComponent(UiTooltipPanel);
|
|
383
|
+
this.ref.instance.hover.subscribe((inside) => {
|
|
384
|
+
if (inside) clearTimeout(this.closeTimer);
|
|
385
|
+
else if (this.via !== 'focus') this.closeSoon();
|
|
386
|
+
});
|
|
387
|
+
const view = this.doc.defaultView!;
|
|
388
|
+
this.doc.addEventListener('keydown', this.escape, true);
|
|
389
|
+
view.addEventListener('scroll', this.follow, { capture: true, passive: true });
|
|
390
|
+
view.addEventListener('resize', this.follow, { passive: true });
|
|
391
|
+
this.watch = new view.MutationObserver(() => this.keepDescribed());
|
|
392
|
+
this.watch.observe(this.el, { attributes: true, attributeFilter: ['aria-describedby'] });
|
|
393
|
+
if (isDevMode() && !this.warned && this.el.getAttribute('title')) {
|
|
394
|
+
this.warned = true;
|
|
395
|
+
console.warn('uiTooltip: the trigger also has a title, so the browser shows its own tooltip too. Set title="".', this.el);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const ref = this.ref;
|
|
399
|
+
ref.setInput('id', this.id);
|
|
400
|
+
ref.setInput('text', this.uiTooltip() ?? '');
|
|
401
|
+
ref.setInput('shortcut', this.uiTooltipShortcut());
|
|
402
|
+
ref.setInput('extraClass', this.uiTooltipClass());
|
|
403
|
+
ref.changeDetectorRef.detectChanges();
|
|
404
|
+
const panel = ref.location.nativeElement as HTMLElement;
|
|
405
|
+
const enter = fresh && !instant;
|
|
406
|
+
if (enter) panel.setAttribute('data-enter', '');
|
|
407
|
+
if (panel.showPopover && !panel.matches(':popover-open')) panel.showPopover();
|
|
408
|
+
this.place();
|
|
409
|
+
if (enter) {
|
|
410
|
+
void panel.offsetWidth;
|
|
411
|
+
panel.removeAttribute('data-enter');
|
|
412
|
+
}
|
|
413
|
+
this.describe();
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private place() {
|
|
417
|
+
const ref = this.ref;
|
|
418
|
+
if (!ref) return;
|
|
419
|
+
const panel = ref.location.nativeElement as HTMLElement;
|
|
420
|
+
const root = this.doc.documentElement;
|
|
421
|
+
panel.style.left = panel.style.top = '0px';
|
|
422
|
+
const spot = placeTooltip(
|
|
423
|
+
this.el.getBoundingClientRect(),
|
|
424
|
+
{ width: panel.offsetWidth, height: panel.offsetHeight },
|
|
425
|
+
{ width: root.clientWidth, height: root.clientHeight },
|
|
426
|
+
this.uiTooltipSide(),
|
|
427
|
+
this.uiTooltipAlign(),
|
|
428
|
+
this.uiTooltipOffset(),
|
|
429
|
+
this.doc.defaultView!.getComputedStyle(this.el).direction === 'rtl',
|
|
430
|
+
);
|
|
431
|
+
panel.style.left = `${spot.x}px`;
|
|
432
|
+
panel.style.top = `${spot.y}px`;
|
|
433
|
+
ref.setInput('side', spot.side);
|
|
434
|
+
ref.changeDetectorRef.detectChanges();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Points the trigger at what the tooltip adds: nothing when it repeats the name, only the shortcut when that is all that is new. */
|
|
438
|
+
private describe() {
|
|
439
|
+
const flat = (text: string | null | undefined) => (text ?? '').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
440
|
+
const labelledBy = this.el.getAttribute('aria-labelledby');
|
|
441
|
+
const name = labelledBy
|
|
442
|
+
? labelledBy.split(/\s+/).map((id) => this.doc.getElementById(id)?.textContent ?? '').join(' ')
|
|
443
|
+
: (this.el.getAttribute('aria-label') ?? this.el.textContent);
|
|
444
|
+
const same = flat(name) === flat(this.uiTooltip());
|
|
445
|
+
const target = !same ? this.id : this.uiTooltipShortcut() ? `${this.id}-keys` : '';
|
|
446
|
+
if (target === this.described) return;
|
|
447
|
+
this.undescribe();
|
|
448
|
+
if (target) {
|
|
449
|
+
const ids = (this.el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
|
|
450
|
+
this.el.setAttribute('aria-describedby', [...ids, target].join(' '));
|
|
451
|
+
}
|
|
452
|
+
this.described = target;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
private keepDescribed() {
|
|
456
|
+
const ids = (this.el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
|
|
457
|
+
if (this.described && !ids.includes(this.described)) this.el.setAttribute('aria-describedby', [...ids, this.described].join(' '));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
private undescribe() {
|
|
461
|
+
if (!this.described) return;
|
|
462
|
+
const ids = (this.el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter((id) => id && id !== this.described);
|
|
463
|
+
if (ids.length) this.el.setAttribute('aria-describedby', ids.join(' '));
|
|
464
|
+
else this.el.removeAttribute('aria-describedby');
|
|
465
|
+
this.described = '';
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private unmount() {
|
|
469
|
+
if (this.stack.current === this) {
|
|
470
|
+
this.stack.current = null;
|
|
471
|
+
this.stack.closedAt = this.now();
|
|
472
|
+
}
|
|
473
|
+
this.via = null;
|
|
474
|
+
if (!this.ref) return;
|
|
475
|
+
const view = this.doc.defaultView!;
|
|
476
|
+
this.watch?.disconnect();
|
|
477
|
+
this.watch = undefined;
|
|
478
|
+
this.doc.removeEventListener('keydown', this.escape, true);
|
|
479
|
+
view.removeEventListener('scroll', this.follow, { capture: true });
|
|
480
|
+
view.removeEventListener('resize', this.follow);
|
|
481
|
+
view.cancelAnimationFrame(this.frame);
|
|
482
|
+
this.undescribe();
|
|
483
|
+
this.ref.destroy();
|
|
484
|
+
this.ref = undefined;
|
|
485
|
+
}
|
|
486
|
+
}
|