@fusion.dev/helix-core 0.245.0 → 0.247.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) 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/readings-motion-controller/readings-motion-controller.d.ts +167 -0
  14. package/dist/controllers/readings-motion-controller/readings-motion-controller.js +306 -0
  15. package/dist/controllers/source-controller/source-controller.d.ts +7 -0
  16. package/dist/controllers/source-controller/source-controller.js +2 -0
  17. package/dist/controllers/swipe-controller/swipe-controller.d.ts +19 -3
  18. package/dist/controllers/swipe-controller/swipe-controller.js +32 -10
  19. package/dist/events/details.d.ts +6 -2
  20. package/dist/helix-element/mark-rules.d.ts +14 -0
  21. package/dist/helix-element/mark-rules.js +1 -0
  22. package/dist/index.d.ts +9 -1
  23. package/dist/index.js +9 -1
  24. package/dist/utils/burst-confetti/burst-confetti.d.ts +39 -0
  25. package/dist/utils/burst-confetti/burst-confetti.js +251 -0
  26. package/dist/utils/draw-value-axis/draw-value-axis.d.ts +8 -1
  27. package/dist/utils/draw-value-axis/draw-value-axis.js +11 -5
  28. package/dist/utils/flash-change/flash-change.d.ts +55 -0
  29. package/dist/utils/flash-change/flash-change.js +85 -0
  30. package/dist/utils/readings-motion/readings-motion.d.ts +45 -0
  31. package/dist/utils/readings-motion/readings-motion.js +40 -0
  32. package/dist/utils/resize-from/resize-from.d.ts +36 -0
  33. package/dist/utils/resize-from/resize-from.js +37 -0
  34. package/dist/utils/scale/levels.d.ts +57 -0
  35. package/dist/utils/scale/levels.js +19 -0
  36. package/dist/utils/swipe/swipe.d.ts +52 -0
  37. package/dist/utils/swipe/swipe.js +78 -0
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +4 -4
@@ -7,7 +7,7 @@ export class HoverMarkController {
7
7
  return;
8
8
  }
9
9
  const under = event.composedPath();
10
- const item = this.options.item(under);
10
+ const item = this.options.item?.(under);
11
11
  if (item === this.hovered) {
12
12
  return;
13
13
  }
@@ -18,18 +18,7 @@ export class HoverMarkController {
18
18
  }
19
19
  return;
20
20
  }
21
- const arriving = this.hovered === undefined;
22
- this.hovered = item;
23
- this.placer.place();
24
- if (!arriving) {
25
- return;
26
- }
27
- this.options.gliding(true);
28
- cancelAnimationFrame(this.frame);
29
- this.frame = requestAnimationFrame(() => {
30
- this.frame = 0;
31
- this.options.mark()?.toggleAttribute('data-gliding', this.hovered !== undefined);
32
- });
21
+ this.move(item);
33
22
  };
34
23
  this.leave = () => {
35
24
  cancelAnimationFrame(this.frame);
@@ -53,12 +42,39 @@ export class HoverMarkController {
53
42
  host.addController(this);
54
43
  }
55
44
  hostConnected() {
56
- this.host.addEventListener('pointerover', this.over);
57
- this.host.addEventListener('pointerleave', this.leave);
45
+ if (this.options.item) {
46
+ this.host.addEventListener('pointerover', this.over);
47
+ this.host.addEventListener('pointerleave', this.leave);
48
+ }
58
49
  }
59
50
  hostDisconnected() {
60
51
  this.host.removeEventListener('pointerover', this.over);
61
52
  this.host.removeEventListener('pointerleave', this.leave);
62
53
  this.leave();
63
54
  }
55
+ show(item) {
56
+ if (item) {
57
+ this.move(item);
58
+ }
59
+ else {
60
+ this.leave();
61
+ }
62
+ }
63
+ move(item) {
64
+ if (item === this.hovered) {
65
+ return;
66
+ }
67
+ const arriving = this.hovered === undefined;
68
+ this.hovered = item;
69
+ this.placer.place();
70
+ if (!arriving) {
71
+ return;
72
+ }
73
+ this.options.gliding(true);
74
+ cancelAnimationFrame(this.frame);
75
+ this.frame = requestAnimationFrame(() => {
76
+ this.frame = 0;
77
+ this.options.mark()?.toggleAttribute('data-gliding', this.hovered !== undefined);
78
+ });
79
+ }
64
80
  }
@@ -81,7 +81,7 @@ export class IndicatorController {
81
81
  ? (own.right - box.right) / sx - surface.clientLeft
82
82
  : (box.left - own.left) / sx - surface.clientLeft;
83
83
  const x = `${rtl ? -inline : inline}px`;
84
- const y = `${(box.top - own.top) / sy - surface.clientTop}px`;
84
+ const y = `${(box.top - own.top) / sy - surface.clientTop + surface.scrollTop}px`;
85
85
  const moved = this.last !== undefined && (this.last.x !== x || this.last.y !== y);
86
86
  this.last = { x, y };
87
87
  indicator.style.setProperty('--indicator-x', x);
@@ -50,6 +50,12 @@ export interface LayoutMotionOptions {
50
50
  */
51
51
  arriveIntoEmpty?: boolean;
52
52
  }
53
+ /**
54
+ * The boxes an element is drawn in: the element itself, or where it is
55
+ * `display: contents`, as a table's row is, the boxes of what it draws, through
56
+ * its shadow root and its slots. A row of cells moves as its cells.
57
+ */
58
+ export declare const boxesOf: (element: Element) => HTMLElement[];
53
59
  /**
54
60
  * Moves each item from where it was drawn to where it is drawn after a change,
55
61
  * so a row that is added, sorted, hidden or closed up slides into its place
@@ -11,7 +11,7 @@ const scaleOf = (host, box) => {
11
11
  const along = (drawn, laid) => laid > 0 && Math.abs(drawn - laid) > 1 ? drawn / laid : 1;
12
12
  return { x: along(box.width, host.offsetWidth), y: along(box.height, host.offsetHeight) };
13
13
  };
14
- const boxesOf = (element) => {
14
+ export const boxesOf = (element) => {
15
15
  if (getComputedStyle(element).display !== 'contents') {
16
16
  return element instanceof HTMLElement ? [element] : [];
17
17
  }
@@ -0,0 +1,167 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ /** One item of a chart's readings, as a `ReadingsMotionController` knows it. */
3
+ export interface MotionItem {
4
+ /** What the item is known by from one table to the next, such as its category and its series. */
5
+ key: string;
6
+ /** Its place in the order the chart grows in, such as its category's: items of one step grow together. */
7
+ step: number;
8
+ }
9
+ /** How far each item has come, which a chart's `between` draws its readings at. */
10
+ export interface MotionShares {
11
+ /** How far the axes have come from where they were, from 0 to 1. */
12
+ axes: number;
13
+ /**
14
+ * Whether the item grows from the floor, whatever `from` holds for it: it
15
+ * is growing in, and a change that came while it grew leaves it growing.
16
+ */
17
+ floor(key: string): boolean;
18
+ /**
19
+ * How far the item has come, from 0 to 1: from its reading in `from`, or
20
+ * from the floor, to its reading in `to`. For an item that `to` no longer
21
+ * holds, how far it has gone from its reading in `from` to the floor.
22
+ */
23
+ share(key: string): number;
24
+ }
25
+ /** What a `ReadingsMotionController` reads of its host. */
26
+ export interface ReadingsMotionOptions<F> {
27
+ /**
28
+ * The field `share` of the way between `from` and `to`, which the chart
29
+ * draws this frame. `from` is `undefined` while the chart grows in, when
30
+ * every item rises from the floor. **An item in both moves** from its old
31
+ * reading to its new one, **an item only in `to` grows** from the floor,
32
+ * and **an item only in `from` shrinks** to the floor, and is left out once
33
+ * its share reaches 1. An item that cannot be matched, such as a cell of a
34
+ * grid that changed shape, is drawn at its reading in `to`.
35
+ */
36
+ between: (from: F | undefined, to: F, at: MotionShares) => F;
37
+ /** Whether the chart grows in the first time it is seen: its `grow`. Read at every change. */
38
+ grow: () => boolean;
39
+ /** Whether the chart grows in again each time it comes back into view: its `grow-again`. */
40
+ growAgain: () => boolean;
41
+ /** Every item of a field, in the order the chart reads them. */
42
+ items: (field: F) => readonly MotionItem[];
43
+ /**
44
+ * How long a change of readings takes and its curve, as the host's family
45
+ * hooks hold them, such as `--spatial-bar-chart-move-duration` and
46
+ * `--spatial-bar-chart-move-easing`. Read when a change starts. A duration
47
+ * that is empty, or under a millisecond, moves nothing.
48
+ */
49
+ timing: () => {
50
+ duration: string;
51
+ easing: string;
52
+ };
53
+ }
54
+ /**
55
+ * Moves a chart's drawing from one set of readings to the next, so a chart
56
+ * grows in the first time it is seen and follows new readings where they
57
+ * would jump. Serves the spatial charts and `Heatmap`.
58
+ *
59
+ * **Growing in is a change from the floor.** Each item is known by a key,
60
+ * such as its category and its series, and a new table is matched against
61
+ * the readings drawn: an item in both moves from its old reading to its new
62
+ * one, an item only in the new table grows from the floor, and an item that
63
+ * left shrinks to the floor and then goes. The chart says how to draw a
64
+ * field between two, in `between`, and draws what `drawn` gives it.
65
+ *
66
+ * **Two clocks.** Under `grow`, the chart's items wait flat on the floor
67
+ * until 40% of the chart is in view, then grow in reading order, a step at
68
+ * a time, on a curve of their own, whatever the stylesheet says, since the
69
+ * page asked for the growth by name. A later table grows the items it adds
70
+ * the same way. Every other change moves on the timing the host's family
71
+ * hooks hold, which the styled tier sets from the tokens, so the headless
72
+ * tier draws a new table at once until the page sets them. An animation
73
+ * with no keyframes runs that curve, as `CountController`'s does.
74
+ *
75
+ * **A change that comes mid-move starts from what is drawn**, so a chart
76
+ * fed a reading every second never jumps back to its last table first.
77
+ *
78
+ * **Nothing moves under `prefers-reduced-motion`**, or once the page has
79
+ * paused its motion through `pauseMotion` or `Motion Toggle`, which also
80
+ * ends a move in flight where it was heading. A server draws the readings
81
+ * as they are.
82
+ *
83
+ * The host asks for an update on every frame through `requestUpdate`, and
84
+ * calls `follow` with its readings before each render, or `relayout` where
85
+ * only their layout changed, such as the columns a strip has room for.
86
+ */
87
+ export declare class ReadingsMotionController<F> implements ReactiveController {
88
+ private readonly host;
89
+ private readonly options;
90
+ /** The readings the host holds, the last given to `follow`. */
91
+ private settled;
92
+ /** Whether the readings the host held before had anything to draw. */
93
+ private readable;
94
+ /** Where the move in flight started: the readings drawn when it began, or `undefined` from the floor. */
95
+ private from;
96
+ /** What is drawn this frame, while the readings move or wait on the floor. */
97
+ private current;
98
+ /** Whether the readings wait on the floor to be seen before they grow. */
99
+ private waiting;
100
+ /** Whether the first readings have been drawn, so a later table is not grown in again. */
101
+ private grew;
102
+ /** Whether the move in flight is the chart growing in, after which `grow-again` waits for it to leave the view. */
103
+ private entering;
104
+ /** The items growing in on the growth's own curve, by key. */
105
+ private rising;
106
+ /** The items a new layout brought in during a move, which stand at their readings. */
107
+ private standing;
108
+ /** The change in flight on the family's timing. */
109
+ private clock;
110
+ /** Whether a frame is asked for. */
111
+ private pending;
112
+ /** Whether the host is on the page, where an observer can watch it. */
113
+ private connected;
114
+ /** Whether the chart has grown in under `grow-again`, so it waits to leave the view, on the page or once it comes back to it. */
115
+ private exitWanted;
116
+ /** Whether a move was ended off the page, so the drawing stands partway until the host draws again. */
117
+ private stale;
118
+ /** Watches for the chart to come into view, which starts it growing. */
119
+ private seen;
120
+ /** Watches for the chart to leave the view, after which `grow-again` grows it in once more. */
121
+ private gone;
122
+ private stopListening;
123
+ constructor(host: ReactiveControllerHost & HTMLElement, options: ReadingsMotionOptions<F>);
124
+ /** What the chart draws this frame: the readings between two tables, or its readings as they are. */
125
+ get drawn(): F | undefined;
126
+ /** Whether the readings drawn are not the ones the chart holds: moving, or waiting on the floor. */
127
+ get moving(): boolean;
128
+ hostConnected(): void;
129
+ hostDisconnected(): void;
130
+ /**
131
+ * Takes the host's readings, and `readable`, whether they hold anything to
132
+ * draw. Call it before each render: readings the same as the last do
133
+ * nothing, so the field is best read once for each table.
134
+ */
135
+ follow(field: F, readable: boolean): void;
136
+ /**
137
+ * Takes the host's readings laid out anew, such as at another width, where
138
+ * the table itself has not changed: **a new layout is not a new reading**,
139
+ * so nothing starts to move, and nothing grows in. A move in flight goes on
140
+ * to the new layout, and an item the layout brings in that the move did not
141
+ * start from stands at its reading. Readings that had nothing to draw before
142
+ * are taken as `follow` takes them, so a chart laid out for the first time
143
+ * still grows in.
144
+ */
145
+ relayout(field: F, readable: boolean): void;
146
+ /** Whether anything may move: a browser that draws frames, a reader who has not asked for less movement, and a page that has not paused its motion. */
147
+ private moves;
148
+ /** The field with every item on the floor. */
149
+ private floorOf;
150
+ /** The change's clock, on the family's timing, or `undefined` where the timing moves nothing. */
151
+ private startClock;
152
+ /** How far the change's clock has come, from 0 to 1, or `undefined` with no clock. */
153
+ private progress;
154
+ /** Puts every item on the floor and waits for the chart to be seen. */
155
+ private wait;
156
+ /** Starts the growth once 40% of the chart is in view. */
157
+ private watchSight;
158
+ /** Under `grow-again`, waits for the chart to leave the view, then puts its items on the floor to grow in again. */
159
+ private watchExit;
160
+ /** Draws the frame at `now`, and asks for the next until every item stands. */
161
+ private frame;
162
+ /**
163
+ * Ends any move and draws the readings as they are, asking for an update
164
+ * unless `update` is false, as within `follow`, which runs before one.
165
+ */
166
+ private rest;
167
+ }
@@ -0,0 +1,306 @@
1
+ import { motionPaused, onMotionChange, reducedMotion } from '../../utils/page-motion/page-motion.js';
2
+ import { grownAt, growTime } from '../../utils/readings-motion/readings-motion.js';
3
+ const milliseconds = (value) => {
4
+ const amount = Number.parseFloat(value);
5
+ if (!Number.isFinite(amount)) {
6
+ return 0;
7
+ }
8
+ return value.trim().endsWith('ms') ? amount : amount * 1000;
9
+ };
10
+ const risingOf = (items, since) => {
11
+ const ranks = new Map();
12
+ for (const item of items) {
13
+ if (!ranks.has(item.step)) {
14
+ ranks.set(item.step, ranks.size);
15
+ }
16
+ }
17
+ return new Map(items.map((item) => [item.key, { since, step: ranks.get(item.step) ?? 0, steps: ranks.size }]));
18
+ };
19
+ export class ReadingsMotionController {
20
+ constructor(host, options) {
21
+ this.readable = false;
22
+ this.waiting = false;
23
+ this.grew = false;
24
+ this.entering = false;
25
+ this.rising = new Map();
26
+ this.standing = new Set();
27
+ this.pending = false;
28
+ this.connected = false;
29
+ this.exitWanted = false;
30
+ this.stale = false;
31
+ this.host = host;
32
+ this.options = options;
33
+ host.addController(this);
34
+ }
35
+ get drawn() {
36
+ return this.current ?? this.settled;
37
+ }
38
+ get moving() {
39
+ return this.current !== undefined;
40
+ }
41
+ hostConnected() {
42
+ this.connected = true;
43
+ this.stopListening = onMotionChange((paused) => {
44
+ if (paused) {
45
+ this.rest();
46
+ }
47
+ });
48
+ if (this.waiting) {
49
+ this.watchSight();
50
+ }
51
+ else if (this.exitWanted) {
52
+ this.watchExit();
53
+ }
54
+ if (this.stale) {
55
+ this.stale = false;
56
+ this.host.requestUpdate();
57
+ }
58
+ }
59
+ hostDisconnected() {
60
+ this.connected = false;
61
+ this.stopListening?.();
62
+ this.stopListening = undefined;
63
+ this.seen?.disconnect();
64
+ this.seen = undefined;
65
+ this.gone?.disconnect();
66
+ this.gone = undefined;
67
+ if (!this.waiting) {
68
+ this.stale = this.current !== undefined || this.stale;
69
+ this.rest(false);
70
+ }
71
+ }
72
+ follow(field, readable) {
73
+ if (field === this.settled) {
74
+ return;
75
+ }
76
+ const before = this.drawn;
77
+ const wasReadable = this.readable;
78
+ this.settled = field;
79
+ this.readable = readable;
80
+ if (!readable) {
81
+ this.rest(false);
82
+ return;
83
+ }
84
+ if (this.options.grow() && !this.grew) {
85
+ this.grew = true;
86
+ if (this.moves() && typeof IntersectionObserver === 'function') {
87
+ this.wait();
88
+ }
89
+ else {
90
+ this.rest(false);
91
+ }
92
+ return;
93
+ }
94
+ if (this.waiting) {
95
+ this.current = this.floorOf(field);
96
+ return;
97
+ }
98
+ if (!this.moves() || before === undefined || !wasReadable) {
99
+ this.rest(false);
100
+ return;
101
+ }
102
+ const now = performance.now();
103
+ const items = this.options.items(field);
104
+ const kept = new Set(items.map((item) => item.key));
105
+ for (const [key, one] of [...this.rising]) {
106
+ if (!kept.has(key) || now - one.since >= growTime(one.steps)) {
107
+ this.rising.delete(key);
108
+ }
109
+ }
110
+ if (this.options.grow()) {
111
+ const had = new Set(this.options.items(before).map((item) => item.key));
112
+ const added = items.filter((item) => !had.has(item.key) && !this.rising.has(item.key));
113
+ for (const [key, one] of risingOf(added, now)) {
114
+ this.rising.set(key, one);
115
+ }
116
+ }
117
+ this.standing.clear();
118
+ this.clock?.cancel();
119
+ this.clock = this.startClock();
120
+ if (!this.clock && this.rising.size === 0) {
121
+ this.rest(false);
122
+ return;
123
+ }
124
+ this.from = before;
125
+ this.frame(now);
126
+ }
127
+ relayout(field, readable) {
128
+ if (field === this.settled) {
129
+ return;
130
+ }
131
+ if (!this.readable || !readable) {
132
+ this.follow(field, readable);
133
+ return;
134
+ }
135
+ this.settled = field;
136
+ if (this.waiting) {
137
+ this.current = this.floorOf(field);
138
+ }
139
+ else if (this.current !== undefined) {
140
+ const had = new Set(this.from === undefined ? [] : this.options.items(this.from).map((item) => item.key));
141
+ for (const item of this.options.items(field)) {
142
+ if (!had.has(item.key) && !this.rising.has(item.key)) {
143
+ this.standing.add(item.key);
144
+ }
145
+ }
146
+ this.frame(performance.now());
147
+ }
148
+ }
149
+ moves() {
150
+ return typeof requestAnimationFrame === 'function' && !reducedMotion() && !motionPaused();
151
+ }
152
+ floorOf(field) {
153
+ return this.options.between(undefined, field, {
154
+ axes: 1,
155
+ floor: () => true,
156
+ share: () => 0,
157
+ });
158
+ }
159
+ startClock() {
160
+ const timing = this.options.timing();
161
+ const duration = milliseconds(timing.duration);
162
+ if (duration < 1 || typeof this.host.animate !== 'function') {
163
+ return undefined;
164
+ }
165
+ return this.host.animate([], { duration, easing: timing.easing.trim() || 'ease' });
166
+ }
167
+ progress() {
168
+ const clock = this.clock;
169
+ if (!clock) {
170
+ return undefined;
171
+ }
172
+ if (clock.playState === 'finished') {
173
+ return 1;
174
+ }
175
+ const progress = clock.effect?.getComputedTiming().progress;
176
+ return typeof progress === 'number' ? progress : 0;
177
+ }
178
+ wait() {
179
+ const field = this.settled;
180
+ if (field === undefined) {
181
+ return;
182
+ }
183
+ this.clock?.cancel();
184
+ this.clock = undefined;
185
+ this.rising.clear();
186
+ this.standing.clear();
187
+ this.from = undefined;
188
+ this.waiting = true;
189
+ this.current = this.floorOf(field);
190
+ this.watchSight();
191
+ }
192
+ watchSight() {
193
+ if (this.seen || typeof IntersectionObserver !== 'function') {
194
+ return;
195
+ }
196
+ this.seen = new IntersectionObserver(([entry]) => {
197
+ if (!entry?.isIntersecting || !this.waiting) {
198
+ return;
199
+ }
200
+ this.seen?.disconnect();
201
+ this.seen = undefined;
202
+ const field = this.settled;
203
+ if (field === undefined || motionPaused()) {
204
+ this.rest();
205
+ return;
206
+ }
207
+ this.waiting = false;
208
+ this.entering = true;
209
+ const now = performance.now();
210
+ this.rising = risingOf(this.options.items(field), now);
211
+ this.from = undefined;
212
+ this.frame(now);
213
+ }, { threshold: 0.4 });
214
+ this.seen.observe(this.host);
215
+ }
216
+ watchExit() {
217
+ if (!this.options.growAgain() || typeof IntersectionObserver !== 'function') {
218
+ this.exitWanted = false;
219
+ return;
220
+ }
221
+ this.exitWanted = true;
222
+ if (this.gone || !this.connected) {
223
+ return;
224
+ }
225
+ this.gone = new IntersectionObserver(([entry]) => {
226
+ if (!entry || entry.isIntersecting) {
227
+ return;
228
+ }
229
+ this.gone?.disconnect();
230
+ this.gone = undefined;
231
+ this.exitWanted = false;
232
+ if (this.moves() && this.readable) {
233
+ this.wait();
234
+ this.host.requestUpdate();
235
+ }
236
+ });
237
+ this.gone.observe(this.host);
238
+ }
239
+ frame(now) {
240
+ const field = this.settled;
241
+ if (field === undefined) {
242
+ return;
243
+ }
244
+ const progress = this.progress();
245
+ let rising = false;
246
+ for (const one of this.rising.values()) {
247
+ if (now - one.since < growTime(one.steps)) {
248
+ rising = true;
249
+ break;
250
+ }
251
+ }
252
+ if (!rising && (progress === undefined || progress >= 1)) {
253
+ this.rest();
254
+ return;
255
+ }
256
+ const clocked = progress ?? 1;
257
+ const current = this.options.between(this.from, field, {
258
+ axes: clocked,
259
+ floor: (key) => this.rising.has(key),
260
+ share: (key) => {
261
+ const one = this.rising.get(key);
262
+ if (one) {
263
+ return grownAt(one.step, one.steps, now - one.since);
264
+ }
265
+ return this.standing.has(key) ? 1 : clocked;
266
+ },
267
+ });
268
+ if (current === field) {
269
+ this.rest();
270
+ return;
271
+ }
272
+ this.current = current;
273
+ this.host.requestUpdate();
274
+ if (!this.pending) {
275
+ this.pending = true;
276
+ requestAnimationFrame(() => {
277
+ this.pending = false;
278
+ if (this.current !== undefined && !this.waiting) {
279
+ this.frame(performance.now());
280
+ }
281
+ });
282
+ }
283
+ }
284
+ rest(update = true) {
285
+ const was = this.current !== undefined;
286
+ const entered = this.entering;
287
+ this.clock?.cancel();
288
+ this.clock = undefined;
289
+ this.rising.clear();
290
+ this.standing.clear();
291
+ this.from = undefined;
292
+ this.current = undefined;
293
+ this.entering = false;
294
+ if (this.waiting) {
295
+ this.waiting = false;
296
+ this.seen?.disconnect();
297
+ this.seen = undefined;
298
+ }
299
+ if (entered) {
300
+ this.watchExit();
301
+ }
302
+ if (was && update) {
303
+ this.host.requestUpdate();
304
+ }
305
+ }
306
+ }
@@ -36,6 +36,13 @@ export interface SourceHost extends ReactiveControllerHost, HTMLElement {
36
36
  * renaming a series edits a text node in place rather than replacing a cell,
37
37
  * and nothing in a page has reason to know a chart is reading it.
38
38
  *
39
+ * **And for the attributes the readers take a reading from**, which are
40
+ * `READ_ATTRIBUTES`. A cell's `data-value` is its number wherever it is set,
41
+ * and its text is only the words a reader sees, so an edit that changes the
42
+ * number changes the attribute. Watched for text alone, every chart kept
43
+ * drawing the old number after an edit to `data-value`, and a heatmap kept the
44
+ * old tone after an edit to `data-tone`.
45
+ *
39
46
  * **The tree around it is watched as well, for the table that is not there
40
47
  * yet.** A framework page renders a chart first and its table once the data
41
48
  * loads, or re-keys the table and so replaces it under the same id. Watching
@@ -6,6 +6,7 @@ import { wordsLocale } from '../../words/words-locale.js';
6
6
  const HIDDEN = new WeakMap();
7
7
  const READERS = new WeakMap();
8
8
  const NONE = new Set();
9
+ const READ_ATTRIBUTES = ['data-tone', 'data-value', 'datetime', 'label', 'role'];
9
10
  export class SourceController {
10
11
  constructor(host) {
11
12
  this.watched = null;
@@ -158,6 +159,7 @@ export class SourceController {
158
159
  this.host.requestUpdate();
159
160
  });
160
161
  this.observer.observe(element, {
162
+ attributeFilter: READ_ATTRIBUTES,
161
163
  characterData: true,
162
164
  childList: true,
163
165
  subtree: true,
@@ -3,9 +3,23 @@ import type { SwipeAxis } from '../../utils/swipe/swipe.js';
3
3
  export interface SwipeOptions {
4
4
  /** The axis a swipe is read along, or `undefined` while swiping is off. */
5
5
  axis: () => SwipeAxis | undefined;
6
+ /**
7
+ * Called when the browser takes a swipe over for a scroll of its own. Where
8
+ * it is not given, `end` is called with nothing moved, which puts a host that
9
+ * reads distance back where it began.
10
+ */
11
+ cancel?: () => void;
12
+ /**
13
+ * Whether the surface takes the pointer once a press becomes a swipe, so
14
+ * every move and the release come to it wherever the pointer goes. The
15
+ * capture is let go at the release and on a cancel.
16
+ */
17
+ capture?: boolean;
6
18
  /**
7
19
  * Called on the release, with how far the pointer went and how fast it was
8
- * going, in pixels per millisecond, on each axis.
20
+ * going, in pixels per millisecond, on each axis, over its last 100
21
+ * milliseconds. A pointer that stood still for that long before it lifted
22
+ * was going nowhere.
9
23
  */
10
24
  end: (dx: number, dy: number, vx: number, vy: number) => void;
11
25
  /** Called as the pointer moves, with how far it has gone from the press. */
@@ -51,8 +65,10 @@ export declare class SwipeController implements ReactiveController {
51
65
  private readonly options;
52
66
  /** Where the press began, while one is down. */
53
67
  private origin;
54
- /** The last two readings, for the speed. */
68
+ /** The readings of the last `RECENT` milliseconds, for the speed. */
55
69
  private samples;
70
+ /** The surface holding the pointer, where `capture` asked it to take it. */
71
+ private captured;
56
72
  /** Whether the press has become a swipe. */
57
73
  private swiping;
58
74
  /** The pointer being followed. */
@@ -65,6 +81,6 @@ export declare class SwipeController implements ReactiveController {
65
81
  private readonly handleUp;
66
82
  /** A swipe the browser took over, for a scroll of its own, goes back to where it began. */
67
83
  private readonly handleCancel;
68
- /** Forgets the press and stops listening for it. */
84
+ /** Forgets the press, lets go of the pointer, and stops listening for it. */
69
85
  private stop;
70
86
  }