@fusion.dev/helix-core 0.245.0 → 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 +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/readings-motion/readings-motion.d.ts +45 -0
- package/dist/utils/readings-motion/readings-motion.js +40 -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';
|
|
@@ -152,6 +153,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
|
|
|
152
153
|
export { type ColorBytes, type ColorBytesAlpha, readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
|
|
153
154
|
export { type ChartData, type ChartDatum, rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
|
|
154
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';
|
|
155
157
|
export { type ElementsProperty, linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
|
|
156
158
|
export { type Relative, type RelativeOptions, relativeTime, } from './utils/relative-time/relative-time.js';
|
|
157
159
|
export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, type ReorderAxis, type ReorderHold, type ReorderInput, type ReorderState, reorderKey, reorderStep, } from './utils/reorder/reorder.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';
|
|
@@ -152,6 +153,7 @@ export { rangeAdd } from './utils/range-add/range-add.js';
|
|
|
152
153
|
export { readColor, readColorAlpha, rgbOf, } from './utils/read-color/read-color.js';
|
|
153
154
|
export { rowsFromData, seriesFromData, } from './utils/read-data/read-data.js';
|
|
154
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';
|
|
155
157
|
export { linkDescription, reflectElements, unlinkDescription, } from './utils/reflect-elements/reflect-elements.js';
|
|
156
158
|
export { relativeTime, } from './utils/relative-time/relative-time.js';
|
|
157
159
|
export { centersOf, dropMark, edgeSpeed, passedCount, placeKey, reorderKey, reorderStep, } from './utils/reorder/reorder.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic a chart's readings move by: a number between two, an axis
|
|
3
|
+
* between two ranges, the keys a chart knows its items by, and the curve a
|
|
4
|
+
* chart grows in along.
|
|
5
|
+
*
|
|
6
|
+
* Kept apart from `ReadingsMotionController` because a frame between two
|
|
7
|
+
* tables is arithmetic a picture hides: a tick drawn past the end of its axis,
|
|
8
|
+
* or a name written at another category's place, shows for a frame and is
|
|
9
|
+
* gone before anyone can point at it.
|
|
10
|
+
*/
|
|
11
|
+
/** A number `share` of the way from `from` to `to`, where `share` runs from 0 to 1. */
|
|
12
|
+
export declare const mix: (from: number, to: number, share: number) => number;
|
|
13
|
+
/**
|
|
14
|
+
* The key each item is known by from one table to the next, from its name:
|
|
15
|
+
* the name itself, and where the same name comes again, the name and how
|
|
16
|
+
* many times it came before. A chart matches its items across two tables by
|
|
17
|
+
* these keys.
|
|
18
|
+
*/
|
|
19
|
+
export declare const keysOf: (names: readonly string[]) => string[];
|
|
20
|
+
/** An axis as a chart publishes it: its range, the ticks on it, and the words and grid lines that go with them. */
|
|
21
|
+
export interface MovingAxis {
|
|
22
|
+
labels?: readonly string[] | undefined;
|
|
23
|
+
range: readonly [number, number];
|
|
24
|
+
rules?: readonly number[] | undefined;
|
|
25
|
+
ticks: readonly number[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The axis `share` of the way from `from` to `to`.
|
|
29
|
+
*
|
|
30
|
+
* **The range moves, and the ticks are the new axis's from the start**, each
|
|
31
|
+
* at its own number, so they slide with the range as it eases to its new
|
|
32
|
+
* ends. A tick, and its word, outside the range drawn this frame is left out
|
|
33
|
+
* until the range reaches it, so nothing is written past the end of the axis.
|
|
34
|
+
* The grid's lines are kept inside the range the same way.
|
|
35
|
+
*/
|
|
36
|
+
export declare const mixAxis: <A extends MovingAxis>(from: A, to: A, share: number) => A;
|
|
37
|
+
/**
|
|
38
|
+
* How much of its reading an item at `step` of `steps` has reached `elapsed`
|
|
39
|
+
* milliseconds after a chart began to grow in, from 0 to 1. **In reading
|
|
40
|
+
* order**, each step a little after the one before it, fast at first and slow
|
|
41
|
+
* to rest, and never past its reading.
|
|
42
|
+
*/
|
|
43
|
+
export declare const grownAt: (step: number, steps: number, elapsed: number) => number;
|
|
44
|
+
/** How long the items of `steps` steps take to grow in, the last one included, in milliseconds. */
|
|
45
|
+
export declare const growTime: (steps: number) => number;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const mix = (from, to, share) => share >= 1 ? to : share <= 0 ? from : from + (to - from) * share;
|
|
2
|
+
export const keysOf = (names) => {
|
|
3
|
+
const seen = new Map();
|
|
4
|
+
return names.map((name) => {
|
|
5
|
+
const count = seen.get(name) ?? 0;
|
|
6
|
+
seen.set(name, count + 1);
|
|
7
|
+
return count === 0 ? name : `${name}\u0000${count}`;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const mixAxis = (from, to, share) => {
|
|
11
|
+
if (share >= 1) {
|
|
12
|
+
return to;
|
|
13
|
+
}
|
|
14
|
+
const range = [
|
|
15
|
+
mix(from.range[0], to.range[0], share),
|
|
16
|
+
mix(from.range[1], to.range[1], share),
|
|
17
|
+
];
|
|
18
|
+
const [low, high] = [Math.min(...range), Math.max(...range)];
|
|
19
|
+
const inside = (value) => value >= low - 1e-9 * (high - low || 1) && value <= high + 1e-9 * (high - low || 1);
|
|
20
|
+
const kept = to.ticks.flatMap((tick, at) => (inside(tick) ? [at] : []));
|
|
21
|
+
return {
|
|
22
|
+
...to,
|
|
23
|
+
range,
|
|
24
|
+
ticks: kept.map((at) => to.ticks[at]),
|
|
25
|
+
...(to.labels ? { labels: kept.map((at) => to.labels?.[at] ?? '') } : {}),
|
|
26
|
+
...(to.rules ? { rules: to.rules.filter(inside) } : {}),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const GROW = 1000;
|
|
30
|
+
const STAGGER = 110;
|
|
31
|
+
const SPREAD = 660;
|
|
32
|
+
const stepOf = (steps) => (steps > 1 ? Math.min(STAGGER, SPREAD / (steps - 1)) : 0);
|
|
33
|
+
export const grownAt = (step, steps, elapsed) => {
|
|
34
|
+
const t = (elapsed - step * stepOf(steps)) / GROW;
|
|
35
|
+
if (t <= 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return t >= 1 ? 1 : 1 - (1 - t) ** 3;
|
|
39
|
+
};
|
|
40
|
+
export const growTime = (steps) => GROW + stepOf(steps) * Math.max(0, steps - 1);
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.246.0';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-core",
|
|
3
3
|
"description": "Helix element primitives: base classes, mixins, decorators, utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.246.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fusion Development Group",
|
|
7
7
|
"repository": {
|
|
@@ -87,12 +87,12 @@
|
|
|
87
87
|
"bugs": "https://github.com/project-fusion/fusion/issues",
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@floating-ui/dom": "^1.8.0",
|
|
90
|
-
"@fusion.dev/helix-icons": "0.
|
|
90
|
+
"@fusion.dev/helix-icons": "0.246.0",
|
|
91
91
|
"tslib": "^2.9.1"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@fusion.dev/helix-cem": "0.
|
|
95
|
-
"@fusion.dev/helix-testing": "0.
|
|
94
|
+
"@fusion.dev/helix-cem": "0.246.0",
|
|
95
|
+
"@fusion.dev/helix-testing": "0.246.0",
|
|
96
96
|
"@lit-labs/ssr": "^4.1.0",
|
|
97
97
|
"lit": "^3.2.1"
|
|
98
98
|
},
|