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,401 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Hover Card, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`) and overlay.ts (`npx ochreui add overlay`).
|
|
5
|
+
*
|
|
6
|
+
* <a href="/people/maya" [uiHoverCard]="person">Maya Okafor</a> <ng-template #person>…</ng-template>
|
|
7
|
+
* A preview of what a link or name points to, opened by hover or keyboard focus (never on touch).
|
|
8
|
+
* It stays open while the pointer moves into it, and flips and shifts to stay on screen.
|
|
9
|
+
*
|
|
10
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
11
|
+
* --ui-hover-card-bg fill (default: the Popover's, the overlay surface)
|
|
12
|
+
* --ui-hover-card-fg text
|
|
13
|
+
* --ui-hover-card-radius corners (default 12px; Classic 16px)
|
|
14
|
+
* --ui-hover-card-padding inner space (default 14px; Classic and touch 16px)
|
|
15
|
+
* --ui-hover-card-shadow ring and drop shadow
|
|
16
|
+
* --ui-hover-card-width width when the width input is not set (default: fits the content)
|
|
17
|
+
* --ui-hover-card-max-width widest it grows on its own (default 320px)
|
|
18
|
+
* --ui-hover-card-drift how far it glides in from the trigger (default 4px)
|
|
19
|
+
* --ui-hover-card-from starting scale (default 0.97)
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
ComponentRef,
|
|
24
|
+
DOCUMENT,
|
|
25
|
+
DestroyRef,
|
|
26
|
+
Directive,
|
|
27
|
+
ElementRef,
|
|
28
|
+
PLATFORM_ID,
|
|
29
|
+
TemplateRef,
|
|
30
|
+
ViewContainerRef,
|
|
31
|
+
afterNextRender,
|
|
32
|
+
afterRenderEffect,
|
|
33
|
+
booleanAttribute,
|
|
34
|
+
computed,
|
|
35
|
+
inject,
|
|
36
|
+
input,
|
|
37
|
+
isDevMode,
|
|
38
|
+
model,
|
|
39
|
+
numberAttribute,
|
|
40
|
+
output,
|
|
41
|
+
untracked,
|
|
42
|
+
} from '@angular/core';
|
|
43
|
+
import { NgTemplateOutlet, isPlatformBrowser } from '@angular/common';
|
|
44
|
+
import { OverlayAlign, OverlayDismiss, OverlayRect, OverlayRef, OverlaySide, TABBABLE, overlayStack } from './overlay';
|
|
45
|
+
|
|
46
|
+
export type HoverCardSide = OverlaySide;
|
|
47
|
+
export type HoverCardAlign = OverlayAlign;
|
|
48
|
+
|
|
49
|
+
export interface HoverCardLabels {
|
|
50
|
+
/** The card's accessible name, built from the trigger's name. */
|
|
51
|
+
card: (name: string) => string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const LABELS: HoverCardLabels = { card: (name) => name || 'Preview' };
|
|
55
|
+
|
|
56
|
+
/** Open hover cards per document (Symbol.for, so copies share it); they are passive in the overlay stack, so they close each other here. */
|
|
57
|
+
interface OpenCard {
|
|
58
|
+
panel(): Element | undefined;
|
|
59
|
+
close(): void;
|
|
60
|
+
}
|
|
61
|
+
const CARDS = Symbol.for('ochre.hover-cards');
|
|
62
|
+
const openCards = (doc: Document) => ((doc as unknown as Record<symbol, OpenCard[]>)[CARDS] ??= []);
|
|
63
|
+
|
|
64
|
+
type Point = [number, number];
|
|
65
|
+
|
|
66
|
+
/** Whether a point lies on the trigger, the card, or the gap and corridor between them (their convex hull). */
|
|
67
|
+
export function inHoverCorridor(x: number, y: number, trigger: OverlayRect, card: OverlayRect): boolean {
|
|
68
|
+
const points = [trigger, card]
|
|
69
|
+
.flatMap((r): Point[] => [[r.left, r.top], [r.right, r.top], [r.right, r.bottom], [r.left, r.bottom]])
|
|
70
|
+
.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
71
|
+
const turn = (o: Point, a: Point, b: Point) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
72
|
+
const chain = (list: Point[]) =>
|
|
73
|
+
list.reduce<Point[]>((h, p) => {
|
|
74
|
+
while (h.length > 1 && turn(h.at(-2)!, h.at(-1)!, p) <= 0) h.pop();
|
|
75
|
+
h.push(p);
|
|
76
|
+
return h;
|
|
77
|
+
}, []);
|
|
78
|
+
const hull = [...chain(points).slice(0, -1), ...chain([...points].reverse()).slice(0, -1)];
|
|
79
|
+
return hull.length > 2 && hull.every((p, i) => turn(p, hull[(i + 1) % hull.length], [x, y]) >= 0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The card. Created right after its trigger while open, and promoted to the top layer. */
|
|
83
|
+
@Component({
|
|
84
|
+
selector: 'ui-hover-card-panel',
|
|
85
|
+
imports: [NgTemplateOutlet],
|
|
86
|
+
host: {
|
|
87
|
+
popover: 'manual',
|
|
88
|
+
role: 'group',
|
|
89
|
+
'[attr.aria-label]': 'label()',
|
|
90
|
+
'[class]': 'extraClass()',
|
|
91
|
+
'[style.--ui-hover-card-width]': 'width()',
|
|
92
|
+
'[style.max-inline-size]': 'width() ? "calc(100vw - 16px)" : null',
|
|
93
|
+
'(pointerenter)': 'hover.emit($event)',
|
|
94
|
+
'(pointerleave)': 'hover.emit($event)',
|
|
95
|
+
},
|
|
96
|
+
template: '<ng-container [ngTemplateOutlet]="template()" [ngTemplateOutletContext]="context()" />',
|
|
97
|
+
styles: `
|
|
98
|
+
:host {
|
|
99
|
+
--_t: var(--ui-look-tray, 0);
|
|
100
|
+
--_d: var(--ui-hover-card-drift, 4px);
|
|
101
|
+
--_x: 0;
|
|
102
|
+
--_y: 0;
|
|
103
|
+
position: fixed;
|
|
104
|
+
inset: auto;
|
|
105
|
+
z-index: var(--ui-z-popover);
|
|
106
|
+
box-sizing: border-box;
|
|
107
|
+
inline-size: var(--ui-hover-card-width, max-content);
|
|
108
|
+
max-inline-size: min(var(--ui-hover-card-max-width, 320px), 100vw - 16px);
|
|
109
|
+
max-block-size: calc(100dvh - 16px);
|
|
110
|
+
margin: 0;
|
|
111
|
+
padding: var(--ui-hover-card-padding, var(--ui-popover-padding, calc(var(--ui-space-3) + 2px + 2px * var(--_t))));
|
|
112
|
+
overflow: hidden auto;
|
|
113
|
+
overscroll-behavior: contain;
|
|
114
|
+
border: 0;
|
|
115
|
+
outline: 1px solid transparent;
|
|
116
|
+
outline-offset: -1px;
|
|
117
|
+
border-radius: var(--ui-hover-card-radius, var(--ui-popover-radius, calc(var(--ui-radius-lg) + 4px * var(--_t))));
|
|
118
|
+
background: var(--ui-hover-card-bg, var(--ui-popover-bg, var(--ui-bg-overlay)));
|
|
119
|
+
box-shadow: var(--ui-hover-card-shadow, var(--ui-popover-shadow, var(--ui-shadow-md)));
|
|
120
|
+
color: var(--ui-hover-card-fg, var(--ui-popover-fg, var(--ui-text)));
|
|
121
|
+
font: calc(var(--ui-text-base) + 0.5px * var(--_t)) / var(--ui-leading-base) var(--ui-font-sans);
|
|
122
|
+
text-align: start;
|
|
123
|
+
overflow-wrap: break-word;
|
|
124
|
+
transition: var(--ui-duration-3) var(--ui-ease-out);
|
|
125
|
+
transition-property: opacity, scale, translate;
|
|
126
|
+
}
|
|
127
|
+
:host(:not([data-open])) { display: none !important; }
|
|
128
|
+
:host([data-side='top']) { --_y: var(--_d); }
|
|
129
|
+
:host([data-side='bottom']) { --_y: calc(var(--_d) * -1); }
|
|
130
|
+
:host([data-side='left']) { --_x: var(--_d); }
|
|
131
|
+
:host([data-side='right']) { --_x: calc(var(--_d) * -1); }
|
|
132
|
+
:host([data-enter]) { opacity: 0; scale: var(--ui-hover-card-from, 0.97); translate: var(--_x) var(--_y); transition: none; }
|
|
133
|
+
@media (pointer: coarse) {
|
|
134
|
+
:host { padding: var(--ui-hover-card-padding, var(--ui-space-4)); font-size: calc(var(--ui-text-md) + 1px); line-height: var(--ui-leading-md); }
|
|
135
|
+
}
|
|
136
|
+
`,
|
|
137
|
+
})
|
|
138
|
+
export class UiHoverCardPanel {
|
|
139
|
+
readonly template = input<TemplateRef<unknown> | null>(null);
|
|
140
|
+
readonly context = input<{ $implicit: unknown }>({ $implicit: undefined });
|
|
141
|
+
readonly label = input('');
|
|
142
|
+
readonly width = input<string | null>(null);
|
|
143
|
+
readonly extraClass = input<string>();
|
|
144
|
+
readonly hover = output<PointerEvent>();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Shows a preview card for the link or name it sits on; the trigger keeps its own role, name and behavior. */
|
|
148
|
+
@Directive({
|
|
149
|
+
selector: '[uiHoverCard]',
|
|
150
|
+
exportAs: 'uiHoverCard',
|
|
151
|
+
host: {
|
|
152
|
+
'(pointerenter)': 'enter($event)',
|
|
153
|
+
'(pointerleave)': 'leave($event)',
|
|
154
|
+
'(focusin)': 'focus($event)',
|
|
155
|
+
'(focusout)': 'blur()',
|
|
156
|
+
'(click)': 'press($event)',
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
export class UiHoverCard {
|
|
160
|
+
/** What the card shows. Null or undefined means no card at all. */
|
|
161
|
+
readonly uiHoverCard = input<TemplateRef<unknown> | null | undefined>();
|
|
162
|
+
/** Passed to the template as `let-item`, so one template can serve every row of a list. */
|
|
163
|
+
readonly uiHoverCardContext = input<unknown>();
|
|
164
|
+
/** The preferred side. It flips when the other side has more room. */
|
|
165
|
+
readonly uiHoverCardSide = input<HoverCardSide>('bottom');
|
|
166
|
+
/** Which edges line up. Start is the left edge, or the right one in right-to-left pages. Switches when it would stick out. */
|
|
167
|
+
readonly uiHoverCardAlign = input<HoverCardAlign>('start');
|
|
168
|
+
/** Gap to the trigger, in px. */
|
|
169
|
+
readonly uiHoverCardOffset = input(8, { transform: numberAttribute });
|
|
170
|
+
/** How long the pointer rests, or keyboard focus stays, before it opens, in ms. */
|
|
171
|
+
readonly uiHoverCardOpenDelay = input(600, { transform: numberAttribute });
|
|
172
|
+
/** How long it stays after the pointer has left the trigger and the card, in ms. */
|
|
173
|
+
readonly uiHoverCardCloseDelay = input(300, { transform: numberAttribute });
|
|
174
|
+
/** Card width: a number of px or any CSS length. Default: fits the content, up to 320px. */
|
|
175
|
+
readonly uiHoverCardWidth = input<number | string>();
|
|
176
|
+
/** Never opens. */
|
|
177
|
+
readonly uiHoverCardDisabled = input(false, { transform: booleanAttribute });
|
|
178
|
+
/** Open state. Bind `[(uiHoverCardOpen)]`; true from code opens it at once. */
|
|
179
|
+
readonly uiHoverCardOpen = model(false);
|
|
180
|
+
/** A class on the card. */
|
|
181
|
+
readonly uiHoverCardClass = input<string>();
|
|
182
|
+
/** Words for screen readers, for translation. */
|
|
183
|
+
readonly uiHoverCardLabels = input<Partial<HoverCardLabels>>({});
|
|
184
|
+
|
|
185
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
186
|
+
private readonly doc = inject(DOCUMENT);
|
|
187
|
+
private readonly vcr = inject(ViewContainerRef);
|
|
188
|
+
private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
189
|
+
private readonly t = computed(() => ({ ...LABELS, ...this.uiHoverCardLabels() }));
|
|
190
|
+
private readonly size = computed(() => {
|
|
191
|
+
const w = this.uiHoverCardWidth();
|
|
192
|
+
return typeof w === 'number' ? `${w}px` : w || null;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
private ref?: ComponentRef<UiHoverCardPanel>;
|
|
196
|
+
private overlay?: OverlayRef;
|
|
197
|
+
private openTimer?: ReturnType<typeof setTimeout>;
|
|
198
|
+
private closeTimer?: ReturnType<typeof setTimeout>;
|
|
199
|
+
private quiet = false;
|
|
200
|
+
private over = false;
|
|
201
|
+
private engaged = false;
|
|
202
|
+
private restore = true;
|
|
203
|
+
private fresh = true;
|
|
204
|
+
private hint = false;
|
|
205
|
+
private readonly card: OpenCard = {
|
|
206
|
+
panel: () => this.ref?.location.nativeElement,
|
|
207
|
+
close: () => this.dismiss('outside'),
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
constructor() {
|
|
211
|
+
afterRenderEffect(() => {
|
|
212
|
+
const on = this.uiHoverCardOpen() && !!this.uiHoverCard() && !this.uiHoverCardDisabled();
|
|
213
|
+
this.uiHoverCardContext();
|
|
214
|
+
this.uiHoverCardClass();
|
|
215
|
+
this.uiHoverCardSide();
|
|
216
|
+
this.uiHoverCardAlign();
|
|
217
|
+
this.uiHoverCardOffset();
|
|
218
|
+
this.size();
|
|
219
|
+
this.t();
|
|
220
|
+
untracked(() => {
|
|
221
|
+
if (this.fresh) this.hint = on;
|
|
222
|
+
this.fresh = false;
|
|
223
|
+
if (on) this.mount();
|
|
224
|
+
else this.unmount();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
if (isDevMode()) afterNextRender(() => this.check());
|
|
228
|
+
inject(DestroyRef).onDestroy(() => {
|
|
229
|
+
this.clear();
|
|
230
|
+
this.unmount();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Opens it now, without the delay. */
|
|
235
|
+
show() {
|
|
236
|
+
this.clear();
|
|
237
|
+
this.uiHoverCardOpen.set(true);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Closes it now; focus goes back to the trigger if it was inside. */
|
|
241
|
+
hide() {
|
|
242
|
+
this.clear();
|
|
243
|
+
this.restore = true;
|
|
244
|
+
this.uiHoverCardOpen.set(false);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
protected enter(event: PointerEvent) {
|
|
248
|
+
if (event.pointerType === 'touch' || event.defaultPrevented) return;
|
|
249
|
+
this.over = this.engaged = true;
|
|
250
|
+
this.stopClosing();
|
|
251
|
+
if (this.quiet || !this.able() || this.uiHoverCardOpen()) return;
|
|
252
|
+
this.later();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
protected leave(event: PointerEvent) {
|
|
256
|
+
this.over = this.quiet = false;
|
|
257
|
+
if (!this.uiHoverCardOpen()) {
|
|
258
|
+
this.engaged = false;
|
|
259
|
+
clearTimeout(this.openTimer);
|
|
260
|
+
} else this.track(event);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
protected focus(event: FocusEvent) {
|
|
264
|
+
if (
|
|
265
|
+
event.target !== this.el ||
|
|
266
|
+
event.defaultPrevented ||
|
|
267
|
+
this.quiet ||
|
|
268
|
+
this.uiHoverCardOpen() ||
|
|
269
|
+
!this.able() ||
|
|
270
|
+
!this.el.matches(':focus-visible') ||
|
|
271
|
+
overlayStack(this.doc).returning === this.el
|
|
272
|
+
) return;
|
|
273
|
+
this.later();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected blur() {
|
|
277
|
+
this.quiet = false;
|
|
278
|
+
if (!this.over) clearTimeout(this.openTimer);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
protected press(event: MouseEvent) {
|
|
282
|
+
if (event.defaultPrevented) return;
|
|
283
|
+
this.quiet = true;
|
|
284
|
+
this.clear();
|
|
285
|
+
this.restore = false;
|
|
286
|
+
this.uiHoverCardOpen.set(false);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private able() {
|
|
290
|
+
return !!this.uiHoverCard() && !this.uiHoverCardDisabled();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private later() {
|
|
294
|
+
clearTimeout(this.openTimer);
|
|
295
|
+
this.openTimer = setTimeout(() => this.uiHoverCardOpen.set(true), this.uiHoverCardOpenDelay());
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private clear() {
|
|
299
|
+
clearTimeout(this.openTimer);
|
|
300
|
+
this.stopClosing();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private stopClosing() {
|
|
304
|
+
clearTimeout(this.closeTimer);
|
|
305
|
+
this.closeTimer = undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Keeps it open while the pointer is on the trigger, the card or the corridor between them; a card open from the first render closes once the pointer leaves both. */
|
|
309
|
+
private track(event: PointerEvent) {
|
|
310
|
+
const panel = this.ref?.location.nativeElement as HTMLElement | undefined;
|
|
311
|
+
if (!panel || event.pointerType === 'touch') return;
|
|
312
|
+
if (!this.engaged) {
|
|
313
|
+
const on = (r: DOMRect) => event.clientX >= r.left && event.clientX <= r.right && event.clientY >= r.top && event.clientY <= r.bottom;
|
|
314
|
+
if (this.hint && !on(this.el.getBoundingClientRect()) && !on(panel.getBoundingClientRect())) this.drift();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (inHoverCorridor(event.clientX, event.clientY, this.el.getBoundingClientRect(), panel.getBoundingClientRect())) this.stopClosing();
|
|
318
|
+
else this.closeTimer ??= setTimeout(() => this.drift(), this.uiHoverCardCloseDelay());
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private drift() {
|
|
322
|
+
this.closeTimer = undefined;
|
|
323
|
+
const active = this.doc.activeElement;
|
|
324
|
+
const panel = this.ref?.location.nativeElement as HTMLElement | undefined;
|
|
325
|
+
if (panel?.contains(active) || (active === this.el && this.el.matches(':focus-visible'))) return;
|
|
326
|
+
this.restore = false;
|
|
327
|
+
this.uiHoverCardOpen.set(false);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private readonly move = (event: PointerEvent) => this.track(event);
|
|
331
|
+
|
|
332
|
+
private dismiss(reason: OverlayDismiss) {
|
|
333
|
+
const panel = this.ref?.location.nativeElement as HTMLElement | undefined;
|
|
334
|
+
const active = this.doc.activeElement;
|
|
335
|
+
if (reason === 'escape' && (this.over || active === this.el || panel?.contains(active))) this.quiet = true;
|
|
336
|
+
this.clear();
|
|
337
|
+
this.restore = reason === 'escape' || reason === 'trigger';
|
|
338
|
+
this.uiHoverCardOpen.set(false);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private name() {
|
|
342
|
+
const by = this.el.getAttribute('aria-labelledby');
|
|
343
|
+
const text = by
|
|
344
|
+
? by.split(/\s+/).map((id) => this.doc.getElementById(id)?.textContent ?? '').join(' ')
|
|
345
|
+
: (this.el.getAttribute('aria-label') ?? this.el.textContent);
|
|
346
|
+
return (text ?? '').replace(/\s+/g, ' ').trim();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private mount() {
|
|
350
|
+
if (!this.browser) return;
|
|
351
|
+
if (!this.ref) {
|
|
352
|
+
this.ref = this.vcr.createComponent(UiHoverCardPanel);
|
|
353
|
+
this.ref.instance.hover.subscribe((event) => {
|
|
354
|
+
if (event.type === 'pointerenter' && event.pointerType !== 'touch') {
|
|
355
|
+
this.engaged = true;
|
|
356
|
+
this.stopClosing();
|
|
357
|
+
} else this.track(event);
|
|
358
|
+
});
|
|
359
|
+
this.overlay = new OverlayRef(this.ref.location.nativeElement, this.doc, {
|
|
360
|
+
anchor: () => this.el,
|
|
361
|
+
trigger: () => this.el,
|
|
362
|
+
side: () => this.uiHoverCardSide(),
|
|
363
|
+
align: () => this.uiHoverCardAlign(),
|
|
364
|
+
offset: () => this.uiHoverCardOffset(),
|
|
365
|
+
dismiss: (reason) => this.dismiss(reason),
|
|
366
|
+
});
|
|
367
|
+
this.doc.addEventListener('pointermove', this.move, { passive: true });
|
|
368
|
+
const cards = openCards(this.doc);
|
|
369
|
+
for (const other of cards.slice().reverse()) if (!other.panel()?.contains(this.el)) other.close();
|
|
370
|
+
cards.push(this.card);
|
|
371
|
+
}
|
|
372
|
+
const ref = this.ref;
|
|
373
|
+
ref.setInput('template', this.uiHoverCard());
|
|
374
|
+
ref.setInput('context', { $implicit: this.uiHoverCardContext() });
|
|
375
|
+
ref.setInput('label', this.t().card(this.name()));
|
|
376
|
+
ref.setInput('width', this.size());
|
|
377
|
+
ref.setInput('extraClass', this.uiHoverCardClass());
|
|
378
|
+
ref.changeDetectorRef.detectChanges();
|
|
379
|
+
this.overlay!.show(false, false);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private unmount() {
|
|
383
|
+
if (!this.ref) return;
|
|
384
|
+
this.doc.removeEventListener('pointermove', this.move);
|
|
385
|
+
const cards = openCards(this.doc);
|
|
386
|
+
if (cards.includes(this.card)) cards.splice(cards.indexOf(this.card), 1);
|
|
387
|
+
this.stopClosing();
|
|
388
|
+
this.overlay?.hide(this.restore);
|
|
389
|
+
this.ref.destroy();
|
|
390
|
+
this.ref = this.overlay = undefined;
|
|
391
|
+
this.restore = true;
|
|
392
|
+
this.hint = false;
|
|
393
|
+
this.engaged = this.over;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private check() {
|
|
397
|
+
if (!this.el.matches(TABBABLE) || this.el.tabIndex < 0)
|
|
398
|
+
console.warn('uiHoverCard: the trigger cannot take keyboard focus, so keyboard users never see the card. Use a link or a button.', this.el);
|
|
399
|
+
if (!this.name()) console.warn('uiHoverCard: the trigger has no accessible name. Give it text, an aria-label or an aria-labelledby.', this.el);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Icon Button, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`).
|
|
5
|
+
*
|
|
6
|
+
* <button uiIconButton label="…"><svg uiIconButtonIcon …/></button>
|
|
7
|
+
* A square native button holding one icon. The label is its accessible name and tooltip; bind [(pressed)] for a toggle.
|
|
8
|
+
*
|
|
9
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
10
|
+
* --ui-icon-button-press scale while held (default 0.94; Classic 0.95)
|
|
11
|
+
*/
|
|
12
|
+
import { Component, Directive, input, model } from '@angular/core';
|
|
13
|
+
|
|
14
|
+
export type IconButtonVariant = 'ghost' | 'secondary' | 'primary';
|
|
15
|
+
export type IconButtonSize = 'sm' | 'md';
|
|
16
|
+
|
|
17
|
+
@Component({
|
|
18
|
+
selector: 'button[uiIconButton]',
|
|
19
|
+
host: {
|
|
20
|
+
'[attr.aria-label]': 'label()',
|
|
21
|
+
'[attr.title]': 'title() === "" ? null : (title() ?? label())',
|
|
22
|
+
'[attr.aria-pressed]': 'pressed() ?? null',
|
|
23
|
+
'[attr.data-variant]': 'variant()',
|
|
24
|
+
'[attr.data-size]': 'size()',
|
|
25
|
+
'(click)': 'toggle()',
|
|
26
|
+
},
|
|
27
|
+
template: '<ng-content />',
|
|
28
|
+
styles: `
|
|
29
|
+
:host {
|
|
30
|
+
--_t: var(--ui-look-tray, 0);
|
|
31
|
+
--_s: calc(var(--ui-space-6) + var(--ui-space-1) + var(--ui-space-3) * var(--_t));
|
|
32
|
+
--_i: calc(var(--ui-icon-md) - 1px + 3px * var(--_t));
|
|
33
|
+
--_rx: var(--ui-space-1-5);
|
|
34
|
+
--_hit: calc(var(--ui-space-8) + var(--ui-space-1) + var(--ui-space-1-5) * var(--_t));
|
|
35
|
+
--_f0: var(--ui-icon);
|
|
36
|
+
--_f1: var(--ui-icon-active);
|
|
37
|
+
--_b0: transparent;
|
|
38
|
+
--_b1: color-mix(in srgb, var(--ui-text) 5%, transparent);
|
|
39
|
+
--_on: color-mix(in srgb, var(--ui-text) 8%, transparent);
|
|
40
|
+
--_f: var(--_f0);
|
|
41
|
+
--_b: var(--_b0);
|
|
42
|
+
--_edge: transparent;
|
|
43
|
+
--_img: none;
|
|
44
|
+
--_sh: none;
|
|
45
|
+
position: relative;
|
|
46
|
+
display: inline-grid;
|
|
47
|
+
place-items: center;
|
|
48
|
+
flex: none;
|
|
49
|
+
box-sizing: border-box;
|
|
50
|
+
inline-size: var(--_s);
|
|
51
|
+
block-size: var(--_s);
|
|
52
|
+
margin: 0;
|
|
53
|
+
padding: 0;
|
|
54
|
+
border: 1px solid var(--_edge);
|
|
55
|
+
border-radius: calc(var(--ui-radius-sm) + var(--_rx) * var(--_t));
|
|
56
|
+
background: var(--_img) var(--_b);
|
|
57
|
+
box-shadow: var(--_sh);
|
|
58
|
+
color: var(--_f);
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
transition: var(--ui-duration-2) var(--ui-ease-out);
|
|
61
|
+
transition-property: background, color, box-shadow, opacity, transform;
|
|
62
|
+
}
|
|
63
|
+
:host([data-size='sm']) {
|
|
64
|
+
--_s: calc(var(--ui-space-6) + var(--ui-space-2) * var(--_t));
|
|
65
|
+
--_i: calc(var(--ui-icon-sm) + var(--ui-space-0-5) * var(--_t));
|
|
66
|
+
--_rx: var(--ui-space-1);
|
|
67
|
+
}
|
|
68
|
+
:host([data-variant='secondary']) {
|
|
69
|
+
--_b0: var(--ui-bg-surface);
|
|
70
|
+
--_b1: color-mix(in srgb, var(--ui-bg-subtle) calc(var(--_t) * 100%), var(--ui-bg-surface));
|
|
71
|
+
--_edge: color-mix(in srgb, var(--ui-border) calc(var(--_t) * 100%), transparent);
|
|
72
|
+
--_sh: var(--ui-shadow-sm);
|
|
73
|
+
}
|
|
74
|
+
:host([data-variant='primary']) {
|
|
75
|
+
--_f0: var(--ui-text-on-neutral);
|
|
76
|
+
--_f1: var(--_f0);
|
|
77
|
+
--_b0: color-mix(in srgb, var(--ui-bg-neutral-solid) calc(96% + 4% * var(--_t)), transparent);
|
|
78
|
+
--_b1: color-mix(in srgb, var(--ui-bg-neutral-solid) calc(88% + 12% * var(--_t)), transparent);
|
|
79
|
+
--_on: var(--_b1);
|
|
80
|
+
--_sh: 0 calc(2px * var(--_t)) calc(4px * var(--_t)) color-mix(in srgb, var(--ui-gray-1000) calc(16% * var(--_t)), transparent);
|
|
81
|
+
--_img: linear-gradient(color-mix(in srgb, var(--ui-gray-0) calc(14% * var(--_t)), transparent), transparent);
|
|
82
|
+
}
|
|
83
|
+
:host([aria-pressed='true']) { --_f: var(--_f1); --_b: var(--_on); }
|
|
84
|
+
:host([data-variant='secondary'][aria-pressed='true']) { --_sh: inset 0 0 0 0.5px var(--ui-hairline); }
|
|
85
|
+
@media (hover: hover) {
|
|
86
|
+
:host(:hover:not(:disabled)) { --_f: var(--_f1); --_b: var(--_b1); }
|
|
87
|
+
:host([aria-pressed='true']:not([data-variant='primary'], :disabled):hover) { --_b: color-mix(in srgb, var(--ui-text) 11%, transparent); }
|
|
88
|
+
}
|
|
89
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
90
|
+
:host(:active:not(:disabled)) { transform: scale(var(--ui-icon-button-press, calc(0.94 + 0.01 * var(--_t)))); }
|
|
91
|
+
}
|
|
92
|
+
@container style(--ui-motion-scale: 0) {
|
|
93
|
+
:host(:active) { transform: none; }
|
|
94
|
+
}
|
|
95
|
+
@media (pointer: coarse) {
|
|
96
|
+
:host::after { content: ''; position: absolute; inset: min(0px, (var(--_s) - var(--_hit)) / 2 - 1px); }
|
|
97
|
+
}
|
|
98
|
+
:host(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
99
|
+
:host(:disabled) { opacity: var(--ui-disabled-opacity); cursor: default; }
|
|
100
|
+
@media (forced-colors: active) {
|
|
101
|
+
:host([aria-pressed='true']:not(:disabled)) { forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
|
102
|
+
:host(:disabled) { color: GrayText; border-color: GrayText; }
|
|
103
|
+
}
|
|
104
|
+
`,
|
|
105
|
+
})
|
|
106
|
+
export class UiIconButton {
|
|
107
|
+
/** What it does. Its accessible name, and its tooltip unless `title` says otherwise. */
|
|
108
|
+
readonly label = input.required<string>();
|
|
109
|
+
/** Ghost for quiet actions, secondary for toolbars, primary for the main one. */
|
|
110
|
+
readonly variant = input<IconButtonVariant>('ghost');
|
|
111
|
+
/** 24 or 28px square; Classic 32 or 40px. */
|
|
112
|
+
readonly size = input<IconButtonSize>('md');
|
|
113
|
+
/** Makes it a toggle: `aria-pressed`, a gray fill while on, flipped on click. Bind it two-way, `[(pressed)]`; leave it unset for a plain button. */
|
|
114
|
+
readonly pressed = model<boolean | undefined>(undefined);
|
|
115
|
+
/** The tooltip. Defaults to the label; `""` leaves it out, for example under a custom tooltip. */
|
|
116
|
+
readonly title = input<string>();
|
|
117
|
+
|
|
118
|
+
protected toggle() {
|
|
119
|
+
const on = this.pressed();
|
|
120
|
+
if (on !== undefined) this.pressed.set(!on);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Marks the icon inside an icon button: `<svg uiIconButtonIcon>`. Sized to the button and hidden from screen readers. */
|
|
125
|
+
@Directive({
|
|
126
|
+
selector: '[uiIconButtonIcon]',
|
|
127
|
+
host: {
|
|
128
|
+
'aria-hidden': 'true',
|
|
129
|
+
'[style.width]': '"var(--_i)"',
|
|
130
|
+
'[style.height]': '"var(--_i)"',
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
export class UiIconButtonIcon {}
|