@fusion.dev/helix-core 0.244.2 → 0.246.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.
- package/custom-elements.json +1 -1
- package/dist/controllers/readings-motion-controller/readings-motion-controller.d.ts +167 -0
- package/dist/controllers/readings-motion-controller/readings-motion-controller.js +306 -0
- package/dist/events/details.d.ts +6 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/utils/count-to/count-to.d.ts +41 -0
- package/dist/utils/count-to/count-to.js +63 -0
- package/dist/utils/follow-pointer/follow-pointer.d.ts +35 -0
- package/dist/utils/follow-pointer/follow-pointer.js +19 -0
- package/dist/utils/move-items/move-items.d.ts +55 -0
- package/dist/utils/move-items/move-items.js +19 -0
- package/dist/utils/plain-host/plain-host.d.ts +44 -0
- package/dist/utils/plain-host/plain-host.js +110 -0
- package/dist/utils/readings-motion/readings-motion.d.ts +45 -0
- package/dist/utils/readings-motion/readings-motion.js +40 -0
- package/dist/utils/track-indicator/track-indicator.d.ts +68 -0
- package/dist/utils/track-indicator/track-indicator.js +27 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -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
|
+
}
|
package/dist/events/details.d.ts
CHANGED
|
@@ -143,8 +143,12 @@ export interface ActivateDetail extends ChangeDetail {
|
|
|
143
143
|
}
|
|
144
144
|
/** Detail carried by `helix-plot-change`. */
|
|
145
145
|
export interface PlotChangeDetail {
|
|
146
|
-
/**
|
|
147
|
-
|
|
146
|
+
/**
|
|
147
|
+
* `data` for the points or the axes, which are drawn again; `move` for a
|
|
148
|
+
* frame of the points moving to new readings, drawn again in the colors
|
|
149
|
+
* last read; `focus` for the point the keys rest on.
|
|
150
|
+
*/
|
|
151
|
+
kind: 'data' | 'focus' | 'move';
|
|
148
152
|
}
|
|
149
153
|
/** Detail carried by `helix-plot-turn`. */
|
|
150
154
|
export interface PlotTurnDetail {
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export { MAX_FRAME_STEP, PaintGateController, type PaintGateOptions, } from './c
|
|
|
35
35
|
export { PlacementController } from './controllers/placement-controller/placement-controller.js';
|
|
36
36
|
export { PointerFollowController, type PointerFollowOptions, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
|
|
37
37
|
export { hintInside, hintMayShow, onPanelOpen, PopoverController, type PopoverOptions, } from './controllers/popover-controller/popover-controller.js';
|
|
38
|
+
export { type MotionItem, type MotionShares, ReadingsMotionController, type ReadingsMotionOptions, } from './controllers/readings-motion-controller/readings-motion-controller.js';
|
|
38
39
|
export { RelativeClockController, type RelativeClockOptions, } from './controllers/relative-clock-controller/relative-clock-controller.js';
|
|
39
40
|
export { RemotePlaybackController, type RemoteReport, } from './controllers/remote-playback-controller/remote-playback-controller.js';
|
|
40
41
|
export { ReorderController, type ReorderMove, type ReorderOptions, type ReorderWords, requestReorder, } from './controllers/reorder-controller/reorder-controller.js';
|
|
@@ -94,6 +95,7 @@ export { columnStep } from './utils/column-step/column-step.js';
|
|
|
94
95
|
export { contextBudget, type Holder, LIVE, pageBudget, } from './utils/context-budget/context-budget.js';
|
|
95
96
|
export { type ControlEntry, type ControlKind, chordOfAria, controlName, controlReachable, type ListedControl, listControls, listShortcuts, registerControl, registerShortcut, runControl, type ShortcutEntry, unregisterControl, } from './utils/controls/controls.js';
|
|
96
97
|
export { countLabel } from './utils/count-label/count-label.js';
|
|
98
|
+
export { type CountToOptions, countTo } from './utils/count-to/count-to.js';
|
|
97
99
|
export { createSheet } from './utils/create-sheet/create-sheet.js';
|
|
98
100
|
export { type Color, type ColorFormat, formatColor, parseColor, toCss, toHsl, toOklch, toRgb, } from './utils/css-color/css-color.js';
|
|
99
101
|
export { customElement, definedTags, duplicateRegistrations, } from './utils/custom-element/custom-element.js';
|
|
@@ -114,6 +116,7 @@ export { FIND_CURRENT, FIND_MATCH, type FindDirection, type Finder, type FindQue
|
|
|
114
116
|
export { focusTarget } from './utils/focus-target/focus-target.js';
|
|
115
117
|
export { autofocusTarget, deepActiveElement, deepContains, focusAs, focusableElements, openingFocus, PRESSABLE, pressedOwnControl, refocusWithin, } from './utils/focusable-elements/focusable-elements.js';
|
|
116
118
|
export { afterLinkFollowed, followLink, type LinkModifiers, type LinkTarget, } from './utils/follow-link/follow-link.js';
|
|
119
|
+
export { type FollowPointerOptions, followPointer } from './utils/follow-pointer/follow-pointer.js';
|
|
117
120
|
export { formatNumbers } from './utils/format-numbers/format-numbers.js';
|
|
118
121
|
export { glyphPath } from './utils/glyph-path/glyph-path.js';
|
|
119
122
|
export { type GridBounds, type GridKeys, type GridPlace, gridMove, pageRows, } from './utils/grid-move/grid-move.js';
|
|
@@ -133,6 +136,7 @@ export { type EndInSight, endInSight } from './utils/load-more/load-more.js';
|
|
|
133
136
|
export { localeOf, runtimeLocale } from './utils/locale-of/locale-of.js';
|
|
134
137
|
export { markRegion, type RegionOptions } from './utils/mark-region/mark-region.js';
|
|
135
138
|
export { copiesOf, type MediaCopy, sameCopies, } from './utils/media-copy/media-copy.js';
|
|
139
|
+
export { type MoveItemsOptions, moveItems } from './utils/move-items/move-items.js';
|
|
136
140
|
export { nameText } from './utils/name-text/name-text.js';
|
|
137
141
|
export { nearest } from './utils/nearest/nearest.js';
|
|
138
142
|
export { numberConverter, timeConverter } from './utils/number-converter/number-converter.js';
|
|
@@ -149,6 +153,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
|
|
|
149
153
|
export { type ColorBytes, type ColorBytesAlpha, readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
|
|
150
154
|
export { type ChartData, type ChartDatum, rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
|
|
151
155
|
export { byRow, type Extremes, extremesOf, type Row, type RowCell, readRows, readSeries, type Series, type SeriesPoint, seriesKey, unbroken, } from './utils/read-series/read-series.js';
|
|
156
|
+
export { grownAt, growTime, keysOf, type MovingAxis, mix, mixAxis, } from './utils/readings-motion/readings-motion.js';
|
|
152
157
|
export { type ElementsProperty, linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
|
|
153
158
|
export { type Relative, type RelativeOptions, relativeTime, } from './utils/relative-time/relative-time.js';
|
|
154
159
|
export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, type ReorderAxis, type ReorderHold, type ReorderInput, type ReorderState, reorderKey, reorderStep, } from './utils/reorder/reorder.js';
|
|
@@ -179,6 +184,7 @@ export { tellDisclosure } from './utils/tell-disclosure/tell-disclosure.js';
|
|
|
179
184
|
export { subscribe } from './utils/ticker/ticker.js';
|
|
180
185
|
export { type HelixStatusTone, TONE_MARKS, type ToneMark, toneMark, } from './utils/tone-marks/tone-marks.js';
|
|
181
186
|
export { toolbarAround, toolbarAxis } from './utils/toolbar-around/toolbar-around.js';
|
|
187
|
+
export { type TrackedIndicator, type TrackIndicatorOptions, trackIndicator, } from './utils/track-indicator/track-indicator.js';
|
|
182
188
|
export { type TreeArrow, type TreeArrowRow, treeArrow } from './utils/tree-arrow/tree-arrow.js';
|
|
183
189
|
export { Typeahead, type TypeaheadBy, typeaheadBy, typeaheadByWords, typesCharacter, } from './utils/typeahead/typeahead.js';
|
|
184
190
|
export { dateAsValue, isClockValue, isDateValue, isTimeValue, minutesAsValue, numberAsValue, secondsAsValue, timeAsValue, valueAsDate, valueAsMinutes, valueAsNumber, valueAsSeconds, valueAsTime, } from './utils/value-as/value-as.js';
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export { MAX_FRAME_STEP, PaintGateController, } from './controllers/paint-gate-c
|
|
|
35
35
|
export { PlacementController } from './controllers/placement-controller/placement-controller.js';
|
|
36
36
|
export { PointerFollowController, } from './controllers/pointer-follow-controller/pointer-follow-controller.js';
|
|
37
37
|
export { hintInside, hintMayShow, onPanelOpen, PopoverController, } from './controllers/popover-controller/popover-controller.js';
|
|
38
|
+
export { ReadingsMotionController, } from './controllers/readings-motion-controller/readings-motion-controller.js';
|
|
38
39
|
export { RelativeClockController, } from './controllers/relative-clock-controller/relative-clock-controller.js';
|
|
39
40
|
export { RemotePlaybackController, } from './controllers/remote-playback-controller/remote-playback-controller.js';
|
|
40
41
|
export { ReorderController, requestReorder, } from './controllers/reorder-controller/reorder-controller.js';
|
|
@@ -94,6 +95,7 @@ export { columnStep } from './utils/column-step/column-step.js';
|
|
|
94
95
|
export { contextBudget, LIVE, pageBudget, } from './utils/context-budget/context-budget.js';
|
|
95
96
|
export { chordOfAria, controlName, controlReachable, listControls, listShortcuts, registerControl, registerShortcut, runControl, unregisterControl, } from './utils/controls/controls.js';
|
|
96
97
|
export { countLabel } from './utils/count-label/count-label.js';
|
|
98
|
+
export { countTo } from './utils/count-to/count-to.js';
|
|
97
99
|
export { createSheet } from './utils/create-sheet/create-sheet.js';
|
|
98
100
|
export { formatColor, parseColor, toCss, toHsl, toOklch, toRgb, } from './utils/css-color/css-color.js';
|
|
99
101
|
export { customElement, definedTags, duplicateRegistrations, } from './utils/custom-element/custom-element.js';
|
|
@@ -114,6 +116,7 @@ export { FIND_CURRENT, FIND_MATCH, findPattern, findRanges, findTextRanges, text
|
|
|
114
116
|
export { focusTarget } from './utils/focus-target/focus-target.js';
|
|
115
117
|
export { autofocusTarget, deepActiveElement, deepContains, focusAs, focusableElements, openingFocus, PRESSABLE, pressedOwnControl, refocusWithin, } from './utils/focusable-elements/focusable-elements.js';
|
|
116
118
|
export { afterLinkFollowed, followLink, } from './utils/follow-link/follow-link.js';
|
|
119
|
+
export { followPointer } from './utils/follow-pointer/follow-pointer.js';
|
|
117
120
|
export { formatNumbers } from './utils/format-numbers/format-numbers.js';
|
|
118
121
|
export { glyphPath } from './utils/glyph-path/glyph-path.js';
|
|
119
122
|
export { gridMove, pageRows, } from './utils/grid-move/grid-move.js';
|
|
@@ -133,6 +136,7 @@ export { endInSight } from './utils/load-more/load-more.js';
|
|
|
133
136
|
export { localeOf, runtimeLocale } from './utils/locale-of/locale-of.js';
|
|
134
137
|
export { markRegion } from './utils/mark-region/mark-region.js';
|
|
135
138
|
export { copiesOf, sameCopies, } from './utils/media-copy/media-copy.js';
|
|
139
|
+
export { moveItems } from './utils/move-items/move-items.js';
|
|
136
140
|
export { nameText } from './utils/name-text/name-text.js';
|
|
137
141
|
export { nearest } from './utils/nearest/nearest.js';
|
|
138
142
|
export { numberConverter, timeConverter } from './utils/number-converter/number-converter.js';
|
|
@@ -149,6 +153,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
|
|
|
149
153
|
export { readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
|
|
150
154
|
export { rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
|
|
151
155
|
export { byRow, extremesOf, readRows, readSeries, seriesKey, unbroken, } from './utils/read-series/read-series.js';
|
|
156
|
+
export { grownAt, growTime, keysOf, mix, mixAxis, } from './utils/readings-motion/readings-motion.js';
|
|
152
157
|
export { linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
|
|
153
158
|
export { relativeTime, } from './utils/relative-time/relative-time.js';
|
|
154
159
|
export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, reorderKey, reorderStep, } from './utils/reorder/reorder.js';
|
|
@@ -179,6 +184,7 @@ export { tellDisclosure } from './utils/tell-disclosure/tell-disclosure.js';
|
|
|
179
184
|
export { subscribe } from './utils/ticker/ticker.js';
|
|
180
185
|
export { TONE_MARKS, toneMark, } from './utils/tone-marks/tone-marks.js';
|
|
181
186
|
export { toolbarAround, toolbarAxis } from './utils/toolbar-around/toolbar-around.js';
|
|
187
|
+
export { trackIndicator, } from './utils/track-indicator/track-indicator.js';
|
|
182
188
|
export { treeArrow } from './utils/tree-arrow/tree-arrow.js';
|
|
183
189
|
export { Typeahead, typeaheadBy, typeaheadByWords, typesCharacter, } from './utils/typeahead/typeahead.js';
|
|
184
190
|
export { dateAsValue, isClockValue, isDateValue, isTimeValue, minutesAsValue, numberAsValue, secondsAsValue, timeAsValue, valueAsDate, valueAsMinutes, valueAsNumber, valueAsSeconds, valueAsTime, } from './utils/value-as/value-as.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** How `countTo` counts. */
|
|
2
|
+
export interface CountToOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The number to count from. Defaults to the number the element was last
|
|
5
|
+
* counted to, or else the number its text reads as, which a figure written
|
|
6
|
+
* with grouping in another language may not: pass it the first time there.
|
|
7
|
+
*/
|
|
8
|
+
from?: number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* How long the count takes: milliseconds, a time such as `800ms`, or a
|
|
11
|
+
* custom property. Defaults to `--helix-duration-slow`. `0` writes the new
|
|
12
|
+
* figure at once.
|
|
13
|
+
*/
|
|
14
|
+
duration?: number | string | undefined;
|
|
15
|
+
/** The curve the count follows, or a custom property. Defaults to `--helix-easing-decelerate`, which slows as it arrives. */
|
|
16
|
+
easing?: string | undefined;
|
|
17
|
+
/** Writes a figure as text. Defaults to the number written in the element's language. */
|
|
18
|
+
format?: ((value: number) => string) | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Counts the figure an element shows to a new number, once a frame, as a
|
|
22
|
+
* Helix `Stat` counts, and resolves once the new figure is written.
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* import { countTo } from '@fusion.dev/helix-core'
|
|
26
|
+
*
|
|
27
|
+
* await countTo(document.querySelector('#revenue'), 1284)
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* **The element's text is the figure**, so it holds nothing else. Each frame
|
|
31
|
+
* is rounded to as many decimals as the two numbers have, so a count to 1,284
|
|
32
|
+
* shows no fractions. A count started while another runs carries on from the
|
|
33
|
+
* figure drawn, and the first one resolves then.
|
|
34
|
+
*
|
|
35
|
+
* **Not in a live region.** The text changes every frame, which a live region
|
|
36
|
+
* would read out each time; announce the new number some other way.
|
|
37
|
+
*
|
|
38
|
+
* Under reduced motion, or with no time to take, the new figure is written at
|
|
39
|
+
* once.
|
|
40
|
+
*/
|
|
41
|
+
export declare const countTo: (element: HTMLElement, to: number, options?: CountToOptions) => Promise<void>;
|