@fusion.dev/helix-core 0.246.0 → 0.247.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/custom-elements.json +1 -1
  2. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.d.ts +20 -0
  3. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.js +23 -3
  4. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.d.ts +170 -0
  5. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.js +215 -0
  6. package/dist/controllers/focus-mark-controller/focus-mark-controller.d.ts +58 -0
  7. package/dist/controllers/focus-mark-controller/focus-mark-controller.js +76 -0
  8. package/dist/controllers/hover-mark-controller/hover-mark-controller.d.ts +21 -3
  9. package/dist/controllers/hover-mark-controller/hover-mark-controller.js +31 -15
  10. package/dist/controllers/indicator-controller/indicator-controller.js +1 -1
  11. package/dist/controllers/layout-motion-controller/layout-motion-controller.d.ts +6 -0
  12. package/dist/controllers/layout-motion-controller/layout-motion-controller.js +1 -1
  13. package/dist/controllers/source-controller/source-controller.d.ts +7 -0
  14. package/dist/controllers/source-controller/source-controller.js +2 -0
  15. package/dist/controllers/swipe-controller/swipe-controller.d.ts +19 -3
  16. package/dist/controllers/swipe-controller/swipe-controller.js +32 -10
  17. package/dist/helix-element/mark-rules.d.ts +14 -0
  18. package/dist/helix-element/mark-rules.js +1 -0
  19. package/dist/index.d.ts +7 -1
  20. package/dist/index.js +7 -1
  21. package/dist/utils/burst-confetti/burst-confetti.d.ts +39 -0
  22. package/dist/utils/burst-confetti/burst-confetti.js +251 -0
  23. package/dist/utils/draw-value-axis/draw-value-axis.d.ts +8 -1
  24. package/dist/utils/draw-value-axis/draw-value-axis.js +11 -5
  25. package/dist/utils/flash-change/flash-change.d.ts +55 -0
  26. package/dist/utils/flash-change/flash-change.js +85 -0
  27. package/dist/utils/resize-from/resize-from.d.ts +36 -0
  28. package/dist/utils/resize-from/resize-from.js +37 -0
  29. package/dist/utils/scale/levels.d.ts +57 -0
  30. package/dist/utils/scale/levels.js +19 -0
  31. package/dist/utils/swipe/swipe.d.ts +52 -0
  32. package/dist/utils/swipe/swipe.js +78 -0
  33. package/dist/version.d.ts +1 -1
  34. package/dist/version.js +1 -1
  35. package/package.json +4 -4
@@ -246,6 +246,26 @@ export declare class ChartPointerController implements ReactiveController {
246
246
  * position until the render that follows.
247
247
  */
248
248
  hostUpdated(): void;
249
+ /** The bubble last drawn, which glides between readings once it has arrived. */
250
+ private bubble;
251
+ /** The frames that let a new bubble glide. */
252
+ private glide;
253
+ /**
254
+ * Marks the bubble `data-gliding` once it has been placed and painted, so a
255
+ * stylesheet that moves it only under `data-gliding` never slides it in.
256
+ *
257
+ * **A bubble is drawn new each time a reading is shown from none**, as the
258
+ * pointer arrives or a key reaches the plot, and the chart takes it away
259
+ * again as the reading is put away. So a new bubble is an arrival, and it is
260
+ * placed where its reading is at once.
261
+ *
262
+ * **Two frames, where a hover mark waits one.** `Tooltip` places its bubble
263
+ * a microtask after it opens, having measured it first, so the style the
264
+ * browser resolved last still has the bubble unplaced. Marked in the next
265
+ * frame, the bubble would glide in from the window's corner to its first
266
+ * place. The second frame comes after a frame drawn with it in place.
267
+ */
268
+ private glideFrom;
249
269
  /**
250
270
  * Tells `onReading` the reading moved, once for each move.
251
271
  *
@@ -14,6 +14,8 @@ export class ChartPointerController {
14
14
  this.by = 'mouse';
15
15
  this.said = { at: -1, series: -1 };
16
16
  this.tapped = false;
17
+ this.bubble = null;
18
+ this.glide = 0;
17
19
  this.away = (event) => {
18
20
  if (!event.composedPath().includes(this.host)) {
19
21
  this.clear();
@@ -180,6 +182,7 @@ export class ChartPointerController {
180
182
  this.series = -1;
181
183
  this.keyed = false;
182
184
  this.said = { at: -1, series: -1 };
185
+ this.glideFrom(null);
183
186
  }
184
187
  get column() {
185
188
  return this.series < 0 ? undefined : this.columns()[this.series];
@@ -219,9 +222,26 @@ export class ChartPointerController {
219
222
  return;
220
223
  }
221
224
  this.moved = false;
222
- this.host.renderRoot
223
- .querySelector('[part="tooltip-anchor"]')
224
- ?.reposition?.();
225
+ const bubble = this.host.renderRoot.querySelector('[part="tooltip-anchor"]');
226
+ bubble?.reposition?.();
227
+ this.glideFrom(bubble);
228
+ }
229
+ glideFrom(bubble) {
230
+ if (bubble === this.bubble) {
231
+ return;
232
+ }
233
+ this.bubble = bubble;
234
+ cancelAnimationFrame(this.glide);
235
+ this.glide = 0;
236
+ if (!bubble || typeof requestAnimationFrame !== 'function') {
237
+ return;
238
+ }
239
+ this.glide = requestAnimationFrame(() => {
240
+ this.glide = requestAnimationFrame(() => {
241
+ this.glide = 0;
242
+ bubble.toggleAttribute('data-gliding', bubble.isConnected);
243
+ });
244
+ });
225
245
  }
226
246
  announce() {
227
247
  if (!this.onReading || (this.at === this.said.at && this.series === this.said.series)) {
@@ -0,0 +1,170 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import { type SwipeEdge } from '../../utils/swipe/swipe.js';
3
+ /**
4
+ * Where a drag moves the surface freely, as travel toward its edge in pixels.
5
+ * Past either end it meets resistance.
6
+ */
7
+ export interface DragBounds {
8
+ /** The most travel before resistance, such as the resting point of a drawer that refuses to close. */
9
+ max: number;
10
+ /** The least travel before resistance: `0` is the surface fully shown. */
11
+ min: number;
12
+ }
13
+ /** What a release tells the host that decides what it means. */
14
+ export interface DragRelease {
15
+ /** The surface's size along the drag, in pixels. */
16
+ size: number;
17
+ /** How far toward its edge the surface is drawn, in pixels, from fully shown. */
18
+ travel: number;
19
+ /** How fast it was moving toward its edge, in pixels per millisecond, negative away from it. */
20
+ velocity: number;
21
+ }
22
+ /** What a `DragDismissController` reads of its host, and what it tells it. */
23
+ export interface DragDismissOptions {
24
+ /**
25
+ * Where the surface moves freely, given its size along the drag. The surface
26
+ * fully shown to anywhere off its edge where this is not given.
27
+ */
28
+ bounds?: (size: number) => DragBounds;
29
+ /**
30
+ * Whether a release dismisses. A host with resting points of its own moves
31
+ * its rest here before it answers no, as a drawer settles on a snap point.
32
+ * Where this is not given, a release dismisses past half the surface's size
33
+ * or at a fling, as `settleSwipe` reads one.
34
+ */
35
+ decide?: (release: DragRelease) => boolean;
36
+ /**
37
+ * The host's own way out, called once a release dismisses, which returns
38
+ * whether it went ahead. A host whose page refused it, by canceling its
39
+ * before-close event, answers false and the surface goes back to rest.
40
+ */
41
+ dismiss: () => boolean;
42
+ /** The edge the surface leaves through, or `undefined` while it cannot be dragged. */
43
+ edge: () => SwipeEdge | undefined;
44
+ /**
45
+ * Called once a release has come to rest, on or off the screen, with
46
+ * whether it dismissed. A host that holds back part of its close until the
47
+ * glide has gone, such as taking a dialog out of the top layer, does it
48
+ * here. The dragging state is still on while it runs.
49
+ */
50
+ landed?: (dismissed: boolean) => void;
51
+ /** Records the dragging state on the host, from the drag's start until its release lands. */
52
+ mark?: (dragging: boolean) => void;
53
+ /**
54
+ * Called each time a drag or a release moves the surface, with how far toward
55
+ * its edge it is drawn and its size, for a host that publishes the distance,
56
+ * such as a drawer fading its backdrop.
57
+ */
58
+ moved?: (travel: number, size: number) => void;
59
+ /**
60
+ * How far toward its edge the host's own stylesheet already rests the
61
+ * surface, in pixels, such as a drawer at a snap point. The surface is moved
62
+ * by the difference. `0` where this is not given.
63
+ */
64
+ rest?: () => number;
65
+ /** Whether a press, on the element it landed on, may start a drag. */
66
+ start?: (target: Element, event: PointerEvent) => boolean;
67
+ /** The element a drag starts on: a handle, or the whole surface. */
68
+ surface: () => HTMLElement | null | undefined;
69
+ /** The element that moves, where it is not the surface. */
70
+ target?: () => HTMLElement | null | undefined;
71
+ /**
72
+ * How long a release takes and the curve it settles back on, as the host's
73
+ * family hooks hold them, such as `--drawer-release-duration` and
74
+ * `--drawer-release-easing`. Read at each release. A duration that is empty,
75
+ * or under a millisecond, glides nothing.
76
+ */
77
+ timing: () => {
78
+ duration: string;
79
+ easing: string;
80
+ };
81
+ }
82
+ /**
83
+ * Drags a surface along one axis toward the edge it leaves through, and on the
84
+ * release dismisses it or puts it back, at the speed it was let go: a toast
85
+ * swiped away, a drawer dragged closed.
86
+ *
87
+ * **The surface follows the finger.** `SwipeController` decides that a press is
88
+ * a drag, once it has gone 8 pixels mostly along the axis, so a tap on a
89
+ * button inside is still a tap and a drag across is the page's scroll. Then
90
+ * the surface takes the pointer and moves with it one to one, through an
91
+ * inline `translate` on top of whatever its stylesheet does, and past the open
92
+ * end, or past `bounds`, it meets resistance and moves less and less. The
93
+ * `translate` is there only while a drag and its release run: at rest the
94
+ * surface carries none.
95
+ *
96
+ * **The release keeps the speed.** A fling dismisses from any distance, a slow
97
+ * drag past half the surface dismisses, and anything else goes back. Going,
98
+ * the surface leaves at the speed it was let go, gathering pace where that was
99
+ * slow, off the edge of the window. Going back, it follows the host's curve,
100
+ * `--helix-easing-spring` on the styled tier, with the release's speed carried
101
+ * in, so neither stalls nor jumps at the moment the finger lifts. A drag that
102
+ * starts while it goes back catches it where it is.
103
+ *
104
+ * **The host's own way out decides.** `dismiss` is the host's close, so its
105
+ * events fire as they do for every other way out, a cancelable one included.
106
+ * A refusal puts the surface back.
107
+ *
108
+ * **Under reduced motion the drag still follows the finger**, since moving
109
+ * something with your hand is not motion that starts by itself, and the
110
+ * release does not glide: the surface goes or goes back at once. The headless
111
+ * tier sets no timing, so a release lands at once there too.
112
+ *
113
+ * While it can be dragged, the surface carries `data-drags` with its axis,
114
+ * which `DRAGS_RULE` turns into a `touch-action` that leaves the page only the
115
+ * other pan. Name `DRAGS_RULE` in the host's `markRules`.
116
+ */
117
+ export declare class DragDismissController implements ReactiveController {
118
+ private readonly options;
119
+ /** The edge, held from the start of a drag to its landing. */
120
+ private edge;
121
+ /** The surface's size along the drag, measured as it starts. */
122
+ private size;
123
+ /** The travel the finger's distance is counted from. */
124
+ private base;
125
+ /** Where the drag has taken the surface, before resistance. */
126
+ private raw;
127
+ /** Whether a finger is dragging the surface now. */
128
+ private held;
129
+ /** Whether a drag or its release is under way, from the first move to the landing. */
130
+ private active;
131
+ /** The release in flight. */
132
+ private flight;
133
+ /** Whether a dismissed surface still carries the `translate` it left on. */
134
+ private left;
135
+ constructor(host: ReactiveControllerHost & HTMLElement, options: DragDismissOptions);
136
+ /** Whether a drag or its release is under way. */
137
+ get dragging(): boolean;
138
+ hostUpdated(): void;
139
+ hostDisconnected(): void;
140
+ private get target();
141
+ private get rest();
142
+ /** Where the surface is drawn, with resistance past its bounds. */
143
+ private get travel();
144
+ private drag;
145
+ /** Moves the surface to where the drag has taken it. */
146
+ private draw;
147
+ /** A release, or with nothing a cancel, which goes back to rest. */
148
+ private release;
149
+ /** How far toward its edge the surface has to go to be off the window. */
150
+ private exit;
151
+ /**
152
+ * Glides the surface from where it is to its end: off the window when it was
153
+ * dismissed, and back to rest along the host's curve when not.
154
+ *
155
+ * **Timed from the release, each frame**, so the first frame after it has
156
+ * already moved on at the release's speed, where an animation left to play
157
+ * would hold still until the frame it started on.
158
+ */
159
+ private glideTo;
160
+ /** Stops a release in flight where it is. */
161
+ private halt;
162
+ /**
163
+ * Brings a release to rest: the host finishes its part first, with the
164
+ * dragging state still on, so nothing it does is caught by a transition.
165
+ * A surface that went back loses its `translate`. One that went keeps it
166
+ * until it can be dragged again, so a message still fading does not jump
167
+ * back into its place.
168
+ */
169
+ private land;
170
+ }
@@ -0,0 +1,215 @@
1
+ import { reducedMotion } from '../../utils/page-motion/page-motion.js';
2
+ import { edgeOffset, exitGlide, resisted, settleGlide, settleSwipe, swipeAxis, towardEdge, } from '../../utils/swipe/swipe.js';
3
+ import { SwipeController } from '../swipe-controller/swipe-controller.js';
4
+ const STEPS = 48;
5
+ const readCurve = (element, easing) => {
6
+ let clock;
7
+ try {
8
+ clock = element.animate([], { duration: 1000, easing, fill: 'both' });
9
+ }
10
+ catch {
11
+ return [0, 1];
12
+ }
13
+ clock.pause();
14
+ const curve = [];
15
+ for (let step = 0; step <= STEPS; step += 1) {
16
+ clock.currentTime = (step / STEPS) * 1000;
17
+ const progress = clock.effect?.getComputedTiming().progress;
18
+ curve.push(typeof progress === 'number' ? progress : step / STEPS);
19
+ }
20
+ clock.cancel();
21
+ return curve;
22
+ };
23
+ const milliseconds = (value) => {
24
+ const amount = Number.parseFloat(value);
25
+ if (!Number.isFinite(amount)) {
26
+ return 0;
27
+ }
28
+ return value.trim().endsWith('ms') ? amount : amount * 1000;
29
+ };
30
+ const px = (value) => `${Math.round(value * 100) / 100 || 0}px`;
31
+ export class DragDismissController {
32
+ constructor(host, options) {
33
+ this.edge = 'right';
34
+ this.size = 0;
35
+ this.base = 0;
36
+ this.raw = 0;
37
+ this.held = false;
38
+ this.active = false;
39
+ this.left = false;
40
+ this.options = options;
41
+ new SwipeController(host, {
42
+ axis: () => {
43
+ const edge = this.options.edge();
44
+ return edge && !this.flight?.dismissed ? swipeAxis(edge) : undefined;
45
+ },
46
+ cancel: () => this.release(undefined),
47
+ capture: true,
48
+ end: (dx, dy, vx, vy) => this.release({ dx, dy, vx, vy }),
49
+ move: (dx, dy) => this.drag(dx, dy),
50
+ ...(options.start ? { start: options.start } : {}),
51
+ surface: options.surface,
52
+ });
53
+ host.addController(this);
54
+ }
55
+ get dragging() {
56
+ return this.active;
57
+ }
58
+ hostUpdated() {
59
+ const surface = this.options.surface();
60
+ if (!surface) {
61
+ return;
62
+ }
63
+ const edge = this.options.edge();
64
+ const axis = edge ? swipeAxis(edge) : undefined;
65
+ if (axis === undefined) {
66
+ surface.removeAttribute('data-drags');
67
+ }
68
+ else if (surface.getAttribute('data-drags') !== axis) {
69
+ surface.setAttribute('data-drags', axis);
70
+ }
71
+ if (axis !== undefined && this.left && !this.active) {
72
+ this.left = false;
73
+ this.target?.style.removeProperty('translate');
74
+ }
75
+ }
76
+ hostDisconnected() {
77
+ this.held = false;
78
+ if (this.active) {
79
+ this.land(this.flight?.dismissed ?? false);
80
+ }
81
+ }
82
+ get target() {
83
+ return this.options.target?.() ?? this.options.surface();
84
+ }
85
+ get rest() {
86
+ return this.options.rest?.() ?? 0;
87
+ }
88
+ get travel() {
89
+ const bounds = this.options.bounds?.(this.size) ?? { max: Number.POSITIVE_INFINITY, min: 0 };
90
+ return resisted(this.raw, bounds.min, bounds.max, this.size);
91
+ }
92
+ drag(dx, dy) {
93
+ const edge = this.options.edge();
94
+ if (!edge) {
95
+ return;
96
+ }
97
+ if (!this.held) {
98
+ const caught = this.flight ? this.raw : undefined;
99
+ this.halt();
100
+ this.held = true;
101
+ this.edge = edge;
102
+ const box = this.target?.getBoundingClientRect();
103
+ this.size = (swipeAxis(edge) === 'x' ? box?.width : box?.height) ?? 0;
104
+ this.base = caught === undefined ? this.rest : caught - towardEdge(edge, dx, dy);
105
+ if (!this.active) {
106
+ this.active = true;
107
+ this.options.mark?.(true);
108
+ }
109
+ }
110
+ this.raw = this.base + towardEdge(this.edge, dx, dy);
111
+ this.draw();
112
+ }
113
+ draw() {
114
+ const travel = this.travel;
115
+ const target = this.target;
116
+ if (target) {
117
+ const { x, y } = edgeOffset(this.edge, travel - this.rest);
118
+ target.style.translate = `${px(x)} ${px(y)}`;
119
+ }
120
+ this.options.moved?.(travel, this.size);
121
+ }
122
+ release(moved) {
123
+ if (!this.held) {
124
+ return;
125
+ }
126
+ this.held = false;
127
+ if (!moved) {
128
+ this.glideTo(false, 0);
129
+ return;
130
+ }
131
+ this.raw = this.base + towardEdge(this.edge, moved.dx, moved.dy);
132
+ const velocity = towardEdge(this.edge, moved.vx, moved.vy);
133
+ const release = { size: this.size, travel: this.travel, velocity };
134
+ const decided = this.options.decide
135
+ ? this.options.decide(release)
136
+ : settleSwipe({ points: [1], ...release }) === 0;
137
+ this.glideTo(decided && this.options.dismiss(), velocity);
138
+ }
139
+ exit() {
140
+ const travel = this.travel;
141
+ const box = this.target?.getBoundingClientRect();
142
+ const room = box && typeof window !== 'undefined'
143
+ ? {
144
+ bottom: window.innerHeight - box.top,
145
+ left: box.right,
146
+ right: window.innerWidth - box.left,
147
+ top: box.bottom,
148
+ }[this.edge]
149
+ : undefined;
150
+ return room !== undefined && Number.isFinite(room)
151
+ ? travel + Math.max(0, room)
152
+ : Math.max(travel, this.size);
153
+ }
154
+ glideTo(dismissed, velocity) {
155
+ this.draw();
156
+ const target = this.target;
157
+ const from = this.raw;
158
+ const to = dismissed ? this.exit() : this.rest;
159
+ const timing = this.options.timing();
160
+ const longest = milliseconds(timing.duration);
161
+ if (longest < 1 ||
162
+ reducedMotion() ||
163
+ !target ||
164
+ typeof target.animate !== 'function' ||
165
+ typeof requestAnimationFrame !== 'function') {
166
+ this.land(dismissed);
167
+ return;
168
+ }
169
+ const course = dismissed
170
+ ? exitGlide(from, to, velocity, longest)
171
+ : settleGlide(from, to, velocity, longest, readCurve(target, timing.easing.trim() || 'ease'));
172
+ const flight = { course, dismissed, frame: 0, start: performance.now() };
173
+ this.flight = flight;
174
+ const step = () => {
175
+ if (this.flight !== flight) {
176
+ return;
177
+ }
178
+ const elapsed = performance.now() - flight.start;
179
+ if (elapsed >= course.duration) {
180
+ this.raw = to;
181
+ this.draw();
182
+ this.land(dismissed);
183
+ return;
184
+ }
185
+ this.raw = course.at(elapsed);
186
+ this.draw();
187
+ flight.frame = requestAnimationFrame(step);
188
+ };
189
+ flight.frame = requestAnimationFrame(step);
190
+ }
191
+ halt() {
192
+ const flight = this.flight;
193
+ this.flight = undefined;
194
+ if (flight) {
195
+ cancelAnimationFrame(flight.frame);
196
+ }
197
+ }
198
+ land(dismissed) {
199
+ this.halt();
200
+ if (!dismissed) {
201
+ this.raw = this.rest;
202
+ }
203
+ this.options.landed?.(dismissed);
204
+ const target = this.target;
205
+ if (target) {
206
+ void getComputedStyle(target).translate;
207
+ if (!dismissed) {
208
+ target.style.removeProperty('translate');
209
+ }
210
+ }
211
+ this.left = dismissed;
212
+ this.active = false;
213
+ this.options.mark?.(false);
214
+ }
215
+ }
@@ -0,0 +1,58 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ /** What a `FocusMarkController` needs of its host. */
3
+ export interface FocusMarkOptions {
4
+ /**
5
+ * Told when the ring arrives on an item and when it leaves, so the host can
6
+ * hold a state its stylesheet reads to take each item's own ring away while
7
+ * this one draws it.
8
+ */
9
+ gliding: (on: boolean) => void;
10
+ /** The items focus moves among, whose own focus the ring follows. */
11
+ items: () => readonly HTMLElement[];
12
+ /** The ring that travels to the control with focus. */
13
+ mark: () => HTMLElement | null | undefined;
14
+ /** The box the ring is positioned against, as `IndicatorController` takes it. */
15
+ surface: () => HTMLElement | null | undefined;
16
+ /** Whether the ring is drawn at all, such as for a toolbar inside another that draws it. Always, left out. */
17
+ enabled?: () => boolean;
18
+ }
19
+ /**
20
+ * Moves one focus ring to whichever item has visible focus, so a reader moving
21
+ * along a strip with the arrow keys sees the ring travel from item to item,
22
+ * and does not have to find where it went. Serves `Toolbar`, `Tabs`, and
23
+ * `Toggle Group`.
24
+ *
25
+ * **The ring is the item's own, copied.** As it lands, it takes the focused
26
+ * control's corners, its outline's width, and its offset, so it draws exactly
27
+ * the ring the control would have, one inside a tab and one outside a button.
28
+ * The host takes each item's own ring away while this one is placed, through
29
+ * `gliding`.
30
+ *
31
+ * **Placed at once and seen at once.** Arriving from outside the strip, the
32
+ * ring is placed where focus lands and is drawn at full strength in that
33
+ * frame, since a focus ring that fades in is a moment with no focus shown;
34
+ * `data-gliding` comes a frame later, so a stylesheet that moves it only
35
+ * under `data-gliding` never slides it in. Only focus that shows, as
36
+ * `:focus-visible` says, is followed: a click that focuses a control draws no
37
+ * ring here either.
38
+ *
39
+ * **Within the strip only.** Focus inside an item that has left the strip's
40
+ * box, such as a menu a toolbar button opened, takes the ring away, and the
41
+ * items draw their own rings again.
42
+ */
43
+ export declare class FocusMarkController implements ReactiveController {
44
+ private readonly host;
45
+ private readonly options;
46
+ private readonly glide;
47
+ /** The frame the ring is next placed in. */
48
+ private frame;
49
+ constructor(host: ReactiveControllerHost & HTMLElement, options: FocusMarkOptions);
50
+ hostConnected(): void;
51
+ hostDisconnected(): void;
52
+ /** Places the ring a frame from now, once focus and each item's own update have settled. */
53
+ private readonly queue;
54
+ /** Moves the ring to the control with visible focus, or takes it away. */
55
+ place(): void;
56
+ /** The control inside one of the items that shows focus, inside the strip's box. */
57
+ private focused;
58
+ }
@@ -0,0 +1,76 @@
1
+ import { deepActiveElement, deepContains, } from '../../utils/focusable-elements/focusable-elements.js';
2
+ import { HoverMarkController } from '../hover-mark-controller/hover-mark-controller.js';
3
+ export class FocusMarkController {
4
+ constructor(host, options) {
5
+ this.frame = 0;
6
+ this.queue = () => {
7
+ if (typeof requestAnimationFrame !== 'function') {
8
+ return;
9
+ }
10
+ cancelAnimationFrame(this.frame);
11
+ this.frame = requestAnimationFrame(() => {
12
+ this.frame = 0;
13
+ this.place();
14
+ });
15
+ };
16
+ this.host = host;
17
+ this.options = options;
18
+ this.glide = new HoverMarkController(host, {
19
+ gliding: options.gliding,
20
+ mark: options.mark,
21
+ observe: options.items,
22
+ surface: options.surface,
23
+ });
24
+ host.addController(this);
25
+ }
26
+ hostConnected() {
27
+ for (const type of EVENTS) {
28
+ this.host.addEventListener(type, this.queue);
29
+ }
30
+ }
31
+ hostDisconnected() {
32
+ for (const type of EVENTS) {
33
+ this.host.removeEventListener(type, this.queue);
34
+ }
35
+ if (this.frame) {
36
+ cancelAnimationFrame(this.frame);
37
+ this.frame = 0;
38
+ }
39
+ }
40
+ place() {
41
+ const control = this.focused();
42
+ const mark = this.options.mark();
43
+ if (control && mark) {
44
+ const style = getComputedStyle(control);
45
+ mark.style.setProperty('border-radius', style.borderRadius);
46
+ mark.style.setProperty('outline-offset', style.outlineOffset);
47
+ mark.style.setProperty('outline-width', style.outlineWidth);
48
+ }
49
+ this.glide.show(control);
50
+ }
51
+ focused() {
52
+ if (this.options.enabled && !this.options.enabled()) {
53
+ return undefined;
54
+ }
55
+ const active = deepActiveElement();
56
+ if (!(active instanceof HTMLElement) || !active.matches(':focus-visible')) {
57
+ return undefined;
58
+ }
59
+ if (!this.options.items().some((item) => deepContains(item, active))) {
60
+ return undefined;
61
+ }
62
+ const surface = this.options.surface();
63
+ if (!surface) {
64
+ return undefined;
65
+ }
66
+ const own = surface.getBoundingClientRect();
67
+ const box = active.getBoundingClientRect();
68
+ const slack = 8;
69
+ const inside = box.left >= own.left - slack &&
70
+ box.right <= own.right + slack &&
71
+ box.top >= own.top - slack &&
72
+ box.bottom <= own.bottom + slack;
73
+ return inside ? active : undefined;
74
+ }
75
+ }
76
+ const EVENTS = ['focusin', 'focusout', 'keydown'];
@@ -6,8 +6,12 @@ export interface HoverMarkOptions {
6
6
  * host can hold `:state(gliding)` for its stylesheet.
7
7
  */
8
8
  gliding: (on: boolean) => void;
9
- /** The item a pointer is over, from what is under it, or nothing where it is between items. */
10
- item: (under: readonly EventTarget[]) => HTMLElement | undefined;
9
+ /**
10
+ * The item a pointer is over, from what is under it, or nothing where it is
11
+ * between items. Left out, the controller follows no pointer, and the host
12
+ * says where the mark goes with `show`.
13
+ */
14
+ item?: (under: readonly EventTarget[]) => HTMLElement | undefined;
11
15
  /** The mark that travels to the item under the pointer. */
12
16
  mark: () => HTMLElement | null | undefined;
13
17
  /** Elements whose size moves the mark, beyond the host, as `IndicatorController` takes them. */
@@ -18,7 +22,7 @@ export interface HoverMarkOptions {
18
22
  /**
19
23
  * Moves one mark to whichever item a mouse or pen is over, so the wash under
20
24
  * the pointer glides from item to item instead of going out on one and coming
21
- * on at the next. Serves `Navigation` and `Tabs`.
25
+ * on at the next. Serves `Navigation`, `Tabs`, `Toggle Group` and `Menu`.
22
26
  *
23
27
  * **Placed by `IndicatorController`**, so the mark carries the same four
24
28
  * properties a selection mark does, `--indicator-x`, `--indicator-y`,
@@ -34,6 +38,11 @@ export interface HoverMarkOptions {
34
38
  * to take each item's own hover wash away while the mark draws it.
35
39
  *
36
40
  * **A touch is not followed**, since a finger leaves no hover to draw.
41
+ *
42
+ * **A host whose wash marks something besides the pointer drives it itself.**
43
+ * Without `item` it listens for nothing, and `show` moves the mark with the
44
+ * same arrival and glide, as `Menu` does for the row with focus, which the
45
+ * keys move as well as the pointer.
37
46
  */
38
47
  export declare class HoverMarkController implements ReactiveController {
39
48
  private readonly host;
@@ -46,6 +55,15 @@ export declare class HoverMarkController implements ReactiveController {
46
55
  constructor(host: ReactiveControllerHost & HTMLElement, options: HoverMarkOptions);
47
56
  hostConnected(): void;
48
57
  hostDisconnected(): void;
58
+ /**
59
+ * Moves the mark to `item`, gliding from the item it was over, or takes it
60
+ * away with nothing.
61
+ *
62
+ * @param item The element the mark covers, or nothing for none.
63
+ */
64
+ show(item: HTMLElement | undefined): void;
49
65
  private readonly over;
66
+ /** Places the mark over `item`, letting it glide once it has arrived. */
67
+ private move;
50
68
  private readonly leave;
51
69
  }