@fusion.dev/helix-core 0.246.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 (35) hide show
  1. package/custom-elements.json +1 -1
  2. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.d.ts +20 -0
  3. package/dist/controllers/chart-pointer-controller/chart-pointer-controller.js +23 -3
  4. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.d.ts +170 -0
  5. package/dist/controllers/drag-dismiss-controller/drag-dismiss-controller.js +215 -0
  6. package/dist/controllers/focus-mark-controller/focus-mark-controller.d.ts +58 -0
  7. package/dist/controllers/focus-mark-controller/focus-mark-controller.js +76 -0
  8. package/dist/controllers/hover-mark-controller/hover-mark-controller.d.ts +21 -3
  9. package/dist/controllers/hover-mark-controller/hover-mark-controller.js +31 -15
  10. package/dist/controllers/indicator-controller/indicator-controller.js +1 -1
  11. package/dist/controllers/layout-motion-controller/layout-motion-controller.d.ts +6 -0
  12. package/dist/controllers/layout-motion-controller/layout-motion-controller.js +1 -1
  13. package/dist/controllers/source-controller/source-controller.d.ts +7 -0
  14. package/dist/controllers/source-controller/source-controller.js +2 -0
  15. package/dist/controllers/swipe-controller/swipe-controller.d.ts +19 -3
  16. package/dist/controllers/swipe-controller/swipe-controller.js +32 -10
  17. package/dist/helix-element/mark-rules.d.ts +14 -0
  18. package/dist/helix-element/mark-rules.js +1 -0
  19. package/dist/index.d.ts +7 -1
  20. package/dist/index.js +7 -1
  21. package/dist/utils/burst-confetti/burst-confetti.d.ts +39 -0
  22. package/dist/utils/burst-confetti/burst-confetti.js +251 -0
  23. package/dist/utils/draw-value-axis/draw-value-axis.d.ts +8 -1
  24. package/dist/utils/draw-value-axis/draw-value-axis.js +11 -5
  25. package/dist/utils/flash-change/flash-change.d.ts +55 -0
  26. package/dist/utils/flash-change/flash-change.js +85 -0
  27. package/dist/utils/resize-from/resize-from.d.ts +36 -0
  28. package/dist/utils/resize-from/resize-from.js +37 -0
  29. package/dist/utils/scale/levels.d.ts +57 -0
  30. package/dist/utils/scale/levels.js +19 -0
  31. package/dist/utils/swipe/swipe.d.ts +52 -0
  32. package/dist/utils/swipe/swipe.js +78 -0
  33. package/dist/version.d.ts +1 -1
  34. package/dist/version.js +1 -1
  35. package/package.json +4 -4
@@ -0,0 +1,251 @@
1
+ import { motionPaused, reducedMotion } from '../page-motion/page-motion.js';
2
+ import { readColorAlpha } from '../read-color/read-color.js';
3
+ const COUNT = 80;
4
+ const MOST = 400;
5
+ const GRAVITY = 900;
6
+ const FALLBACK = [
7
+ [91, 124, 250],
8
+ [229, 103, 125],
9
+ [242, 169, 59],
10
+ [63, 182, 139],
11
+ [155, 123, 240],
12
+ [76, 184, 212],
13
+ ];
14
+ const BACK = 0.86;
15
+ let stage;
16
+ const between = (low, high) => low + Math.random() * (high - low);
17
+ const faces = ([red, green, blue], alpha = 1) => [
18
+ `rgb(${red} ${green} ${blue} / ${alpha})`,
19
+ `rgb(${Math.round(red * BACK)} ${Math.round(green * BACK)} ${Math.round(blue * BACK)} / ${alpha})`,
20
+ ];
21
+ const readFaces = (origin, colors) => {
22
+ const style = getComputedStyle(origin);
23
+ const values = colors ??
24
+ [1, 2, 3, 4, 5, 6]
25
+ .map((step) => style.getPropertyValue(`--helix-color-series-${step}`).trim())
26
+ .filter(Boolean);
27
+ const read = [];
28
+ if (values.length > 0) {
29
+ const probe = document.createElement('span');
30
+ probe.setAttribute('aria-hidden', 'true');
31
+ probe.style.cssText = 'position:fixed;visibility:hidden;pointer-events:none';
32
+ probe.style.colorScheme = style.colorScheme;
33
+ document.body.append(probe);
34
+ for (const value of values) {
35
+ probe.style.color = '';
36
+ probe.style.color = value.replace(/currentcolor/gi, style.color);
37
+ if (!probe.style.color) {
38
+ continue;
39
+ }
40
+ const bytes = readColorAlpha(getComputedStyle(probe).color);
41
+ if (bytes && bytes[3] > 0) {
42
+ read.push(faces([bytes[0], bytes[1], bytes[2]], bytes[3]));
43
+ }
44
+ }
45
+ probe.remove();
46
+ }
47
+ return read.length > 0 ? read : FALLBACK.map((bytes) => faces(bytes));
48
+ };
49
+ const fit = (open) => {
50
+ const width = open.canvas.clientWidth || innerWidth;
51
+ const height = open.canvas.clientHeight || innerHeight;
52
+ const ratio = Math.min(devicePixelRatio || 1, 3);
53
+ if (width === open.width && height === open.height && ratio === open.ratio) {
54
+ return;
55
+ }
56
+ Object.assign(open, { height, ratio, width });
57
+ open.canvas.width = Math.round(width * ratio);
58
+ open.canvas.height = Math.round(height * ratio);
59
+ };
60
+ const openStage = () => {
61
+ if (stage) {
62
+ if (stage.canvas.matches(':popover-open')) {
63
+ try {
64
+ stage.canvas.hidePopover();
65
+ stage.canvas.showPopover();
66
+ }
67
+ catch {
68
+ }
69
+ }
70
+ return stage;
71
+ }
72
+ const canvas = document.createElement('canvas');
73
+ const context = canvas.getContext('2d');
74
+ if (!context) {
75
+ return undefined;
76
+ }
77
+ canvas.setAttribute('aria-hidden', 'true');
78
+ canvas.style.cssText =
79
+ 'position:fixed;inset:0;display:block;width:100%;height:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;overflow:visible;background:transparent;pointer-events:none;z-index:2147483647';
80
+ const popover = typeof canvas.showPopover === 'function';
81
+ if (popover) {
82
+ canvas.setAttribute('popover', 'manual');
83
+ }
84
+ document.body.append(canvas);
85
+ if (popover) {
86
+ try {
87
+ canvas.showPopover();
88
+ }
89
+ catch {
90
+ }
91
+ }
92
+ stage = { canvas, context, height: 0, last: undefined, pieces: [], ratio: 0, width: 0 };
93
+ fit(stage);
94
+ return stage;
95
+ };
96
+ const closeStage = () => {
97
+ const open = stage;
98
+ if (!open) {
99
+ return;
100
+ }
101
+ stage = undefined;
102
+ open.canvas.remove();
103
+ for (const piece of open.pieces) {
104
+ piece.burst.done();
105
+ }
106
+ open.pieces = [];
107
+ };
108
+ const advance = (piece, dt) => {
109
+ piece.age += dt;
110
+ if (piece.age < piece.delay) {
111
+ return;
112
+ }
113
+ const slowed = Math.exp(-piece.drag * dt);
114
+ piece.vx *= slowed;
115
+ piece.vy = piece.vy * slowed + (GRAVITY / piece.drag) * (1 - slowed);
116
+ piece.x += piece.vx * dt;
117
+ piece.y += piece.vy * dt;
118
+ piece.angle += piece.spin * dt;
119
+ piece.flip += piece.flipRate * dt;
120
+ piece.wobble += piece.wobbleRate * dt;
121
+ };
122
+ const draw = (open, piece) => {
123
+ const flown = piece.age - piece.delay;
124
+ if (flown < 0) {
125
+ return;
126
+ }
127
+ const { context, ratio } = open;
128
+ const left = 1 - flown / piece.life;
129
+ context.globalAlpha = left > 0.35 ? 1 : (left / 0.35) ** 1.5;
130
+ const turned = Math.cos(piece.flip);
131
+ const across = Math.sign(turned || 1) * Math.max(Math.abs(turned), 0.08);
132
+ context.fillStyle = turned >= 0 ? piece.front : piece.back;
133
+ const x = piece.x + Math.sin(piece.wobble) * piece.sway * Math.min(1, flown / 0.4);
134
+ const cos = Math.cos(piece.angle);
135
+ const sin = Math.sin(piece.angle);
136
+ context.setTransform(ratio * cos, ratio * sin, -ratio * sin * across, ratio * cos * across, ratio * x, ratio * piece.y);
137
+ if (piece.round) {
138
+ context.beginPath();
139
+ context.arc(0, 0, piece.width / 2, 0, Math.PI * 2);
140
+ context.fill();
141
+ }
142
+ else {
143
+ context.fillRect(-piece.width / 2, -piece.height / 2, piece.width, piece.height);
144
+ }
145
+ };
146
+ const tick = (now) => {
147
+ const open = stage;
148
+ if (!open) {
149
+ return;
150
+ }
151
+ if (motionPaused()) {
152
+ closeStage();
153
+ return;
154
+ }
155
+ const dt = open.last === undefined ? 1 / 60 : Math.min(Math.max(now - open.last, 0) / 1000, 1 / 30);
156
+ open.last = now;
157
+ fit(open);
158
+ const { canvas, context } = open;
159
+ context.setTransform(1, 0, 0, 1, 0, 0);
160
+ context.clearRect(0, 0, canvas.width, canvas.height);
161
+ let kept = 0;
162
+ for (const piece of open.pieces) {
163
+ advance(piece, dt);
164
+ if (piece.age >= piece.delay + piece.life) {
165
+ piece.burst.left -= 1;
166
+ if (piece.burst.left === 0) {
167
+ piece.burst.done();
168
+ }
169
+ continue;
170
+ }
171
+ draw(open, piece);
172
+ open.pieces[kept] = piece;
173
+ kept += 1;
174
+ }
175
+ open.pieces.length = kept;
176
+ context.globalAlpha = 1;
177
+ if (kept === 0) {
178
+ closeStage();
179
+ return;
180
+ }
181
+ requestAnimationFrame(tick);
182
+ };
183
+ const makePieces = (box, count, colors, burst) => {
184
+ const centerX = box.left + box.width / 2;
185
+ const centerY = box.top + box.height * 0.3;
186
+ const spreadX = Math.min(box.width, 160) * 0.3;
187
+ const spreadY = Math.min(box.height, 48) * 0.15;
188
+ const cone = 0.88;
189
+ const offset = Math.floor(Math.random() * colors.length);
190
+ const pieces = [];
191
+ for (let index = 0; index < count; index++) {
192
+ const lean = between(-1, 1);
193
+ const heading = -Math.PI / 2 + lean * cone;
194
+ const speed = between(680, 1150) * (1 - 0.22 * Math.abs(lean));
195
+ const round = Math.random() < 0.2;
196
+ const width = round ? between(4.5, 6.5) : between(6, 10);
197
+ const [front, back] = colors[(index + offset) % colors.length] ?? ['gray', 'gray'];
198
+ pieces.push({
199
+ age: 0,
200
+ angle: between(0, Math.PI * 2),
201
+ back,
202
+ burst,
203
+ delay: between(0, 0.08),
204
+ drag: between(2.7, 3.7),
205
+ flip: between(0, Math.PI * 2),
206
+ flipRate: between(7, 15) * (Math.random() < 0.5 ? -1 : 1),
207
+ front,
208
+ height: round ? width : between(3.5, 5.5),
209
+ life: between(1.1, 1.45),
210
+ round,
211
+ spin: between(1, 5) * (Math.random() < 0.5 ? -1 : 1),
212
+ sway: between(3, 9),
213
+ vx: Math.cos(heading) * speed,
214
+ vy: Math.sin(heading) * speed,
215
+ width,
216
+ wobble: between(0, Math.PI * 2),
217
+ wobbleRate: between(5, 10),
218
+ x: centerX + between(-1, 1) * spreadX,
219
+ y: centerY + between(-1, 1) * spreadY,
220
+ });
221
+ }
222
+ return pieces;
223
+ };
224
+ export const burstConfetti = (origin, options = {}) => new Promise((resolve) => {
225
+ if (typeof document === 'undefined' ||
226
+ document.hidden ||
227
+ !origin.isConnected ||
228
+ reducedMotion() ||
229
+ motionPaused()) {
230
+ resolve();
231
+ return;
232
+ }
233
+ const asked = Math.round(options.count ?? COUNT);
234
+ const count = Number.isFinite(asked) ? Math.min(Math.max(asked, 0), MOST) : COUNT;
235
+ if (count === 0) {
236
+ resolve();
237
+ return;
238
+ }
239
+ const colors = readFaces(origin, options.colors);
240
+ const open = openStage();
241
+ if (!open) {
242
+ resolve();
243
+ return;
244
+ }
245
+ const burst = { done: resolve, left: count };
246
+ open.pieces.push(...makePieces(origin.getBoundingClientRect(), count, colors, burst));
247
+ if (open.pieces.length === count) {
248
+ open.last = undefined;
249
+ requestAnimationFrame(tick);
250
+ }
251
+ });
@@ -14,9 +14,16 @@ import { type TemplateResult } from 'lit';
14
14
  * their own, so each family writes its own custom property there, such as
15
15
  * `--line-chart-axis` in `ch`, and a stylesheet sizes the column from it.
16
16
  *
17
+ * **A number that stays on a new scale is the same tick**, keyed by its value,
18
+ * so a stylesheet moves it to its new level. Given `before`, the numbers that
19
+ * scale had and this one does not stay too, as `tick-leaving` beside `tick`,
20
+ * `hidden`, and at their place on the new scale held inside the plot, so a
21
+ * stylesheet can fade them out as they move.
22
+ *
17
23
  * @param domain The scale's lowest and highest values.
18
24
  * @param place Where a value sits down the plot, from 0 at the top to 100 at the bottom.
19
25
  * @param format How a value is written, such as a number in the chart's locale.
20
26
  * @param width The style the axis carries, from the number of characters in its widest number.
27
+ * @param before The scale drawn before this one, which `ScaleMemory` holds.
21
28
  */
22
- export declare const drawValueAxis: (domain: readonly [number, number], place: (value: number) => number, format: (value: number) => string, width: (widest: number) => string) => TemplateResult;
29
+ export declare const drawValueAxis: (domain: readonly [number, number], place: (value: number) => number, format: (value: number) => string, width: (widest: number) => string, before?: readonly [number, number]) => TemplateResult;
@@ -1,9 +1,15 @@
1
1
  import { html } from 'lit';
2
- import { ticks } from '../scale/ticks.js';
3
- export const drawValueAxis = (domain, place, format, width) => {
4
- const levels = ticks(domain);
5
- const widest = Math.max(1, ...levels.map((level) => format(level).length));
2
+ import { repeat } from 'lit/directives/repeat.js';
3
+ import { heldInside, levelsOf } from '../scale/levels.js';
4
+ export const drawValueAxis = (domain, place, format, width, before) => {
5
+ const levels = levelsOf(domain, before);
6
+ const widest = Math.max(1, ...levels.filter((one) => !one.leaving).map((one) => format(one.level).length));
6
7
  return html `<div aria-hidden="true" part="axis" style=${width(widest)}>
7
- ${levels.map((level) => html `<span part="tick" style=${`inset-block-start: ${place(level)}%`}>${format(level)}</span>`)}
8
+ ${repeat(levels, (one) => one.level, ({ leaving, level }) => html `<span
9
+ ?hidden=${leaving}
10
+ part="tick${leaving ? ' tick-leaving' : ''}"
11
+ style=${`inset-block-start: ${leaving ? heldInside(place(level)) : place(level)}%`}
12
+ >${format(level)}</span
13
+ >`)}
8
14
  </div>`;
9
15
  };
@@ -0,0 +1,55 @@
1
+ /** How `flashChange` lights an element. */
2
+ export interface FlashChangeOptions {
3
+ /**
4
+ * The wash at its strongest: a color, or a custom property that holds one.
5
+ * Defaults to `--helix-color-info` at 14 percent in light mode and 22 in
6
+ * dark. A translucent color lets the element's own background show through
7
+ * it; an opaque one covers it until it fades.
8
+ */
9
+ color?: string | undefined;
10
+ /**
11
+ * How long the wash takes to fade, evenly, once it has held: milliseconds,
12
+ * a time such as `640ms`, or a custom property. Defaults to twice
13
+ * `--helix-duration-slow`. `0` takes the wash off at once.
14
+ */
15
+ duration?: number | string | undefined;
16
+ /**
17
+ * How long the wash holds at its strongest before it fades: milliseconds, a
18
+ * time, or a custom property. Defaults to `--helix-duration-slow`.
19
+ */
20
+ hold?: number | string | undefined;
21
+ }
22
+ /**
23
+ * Lights an element up with a quiet wash and fades it out, so you see what
24
+ * changed when live data or an agent changes it, and resolves once the wash is
25
+ * gone.
26
+ *
27
+ * ```js
28
+ * import { flashChange } from '@fusion.dev/helix-core'
29
+ *
30
+ * cell.textContent = '1,284'
31
+ * flashChange(cell)
32
+ * ```
33
+ *
34
+ * **The wash is drawn over the element's background and under its content**,
35
+ * as an inset shadow added to the element's own shadows, so nothing moves and
36
+ * the element's own background, shadows, and focus ring are as they were once
37
+ * it ends. It works on a line of text that wraps, on a table cell, and on a
38
+ * row: a row that draws no box of its own, such as a `<tr>` or a
39
+ * `display: contents` row, is washed through its cells.
40
+ *
41
+ * **A second flash on the same element starts from the strength drawn**, rises
42
+ * back to full over `--helix-duration-fast`, and holds and fades again, so a
43
+ * value that keeps changing stays lit and never doubles up. The first call
44
+ * resolves then.
45
+ *
46
+ * **Under reduced motion the wash still shows**, since it shows what changed:
47
+ * it holds at full strength, with no rise, and goes over
48
+ * `--helix-duration-fade`, the crossfade Helix keeps for that setting. The
49
+ * hold keeps its usual length there, though the stylesheet shortens
50
+ * `--helix-duration-slow` to almost nothing.
51
+ *
52
+ * Announce the change some other way as well, such as in a live region, for a
53
+ * reader who does not see the wash.
54
+ */
55
+ export declare const flashChange: (element: Element, options?: FlashChangeOptions) => Promise<void>;
@@ -0,0 +1,85 @@
1
+ import { boxesOf } from '../../controllers/layout-motion-controller/layout-motion-controller.js';
2
+ import { reducedMotion } from '../page-motion/page-motion.js';
3
+ import { readTiming } from '../plain-host/plain-host.js';
4
+ const WASH = 'light-dark(color-mix(in oklab, var(--helix-color-info, oklch(0.48 0.12 245)) 14%, transparent), color-mix(in oklab, var(--helix-color-info, oklch(0.7 0.16 245)) 22%, transparent))';
5
+ const flashes = new WeakMap();
6
+ const millisecondsOf = (written, standing) => {
7
+ const amount = Number.parseFloat(written);
8
+ if (!Number.isFinite(amount)) {
9
+ return standing;
10
+ }
11
+ return written.trim().endsWith('ms') || !written.trim().endsWith('s') ? amount : amount * 1000;
12
+ };
13
+ const strengthOf = (flash) => {
14
+ const at = Number(flash.animation.currentTime ?? 0);
15
+ if (at < flash.ramped) {
16
+ return flash.from + (1 - flash.from) * (at / flash.ramped);
17
+ }
18
+ if (at < flash.held) {
19
+ return 1;
20
+ }
21
+ if (at >= flash.total) {
22
+ return 0;
23
+ }
24
+ return 1 - (at - flash.held) / (flash.total - flash.held);
25
+ };
26
+ const boxesToWash = (element) => boxesOf(element).flatMap((box) => getComputedStyle(box).display === 'table-row'
27
+ ? [...box.children].filter((cell) => cell instanceof HTMLElement)
28
+ : [box]);
29
+ const washAt = (color, strength) => `inset 0 0 0 100vmax color-mix(in oklab, ${color} ${Math.round(strength * 1000) / 10}%, transparent)`;
30
+ const flashBox = (box, color, timing, reduced) => new Promise((resolve) => {
31
+ const running = flashes.get(box);
32
+ const from = running && !reduced ? strengthOf(running) : 0;
33
+ if (running) {
34
+ running.animation.cancel();
35
+ running.done();
36
+ }
37
+ const ramped = from > 0 ? timing.ramp * (1 - from) : 0;
38
+ const held = ramped + timing.hold;
39
+ const total = held + timing.fade;
40
+ if (total < 1) {
41
+ flashes.delete(box);
42
+ resolve();
43
+ return;
44
+ }
45
+ const keyframes = [];
46
+ if (ramped > 0) {
47
+ keyframes.push({ boxShadow: washAt(color, from), offset: 0 });
48
+ }
49
+ keyframes.push({ boxShadow: washAt(color, 1), offset: ramped / total }, { boxShadow: washAt(color, 1), offset: held / total }, { boxShadow: washAt(color, 0), offset: 1 });
50
+ const animation = box.animate(keyframes, { composite: 'add', duration: total });
51
+ const flash = { animation, done: resolve, from, held, ramped, total };
52
+ flashes.set(box, flash);
53
+ const finish = () => {
54
+ if (flashes.get(box) === flash) {
55
+ flashes.delete(box);
56
+ resolve();
57
+ }
58
+ };
59
+ animation.finished.then(finish, finish);
60
+ });
61
+ export const flashChange = (element, options = {}) => {
62
+ if (!element.isConnected) {
63
+ return Promise.resolve();
64
+ }
65
+ const boxes = boxesToWash(element).filter((box) => typeof box.animate === 'function');
66
+ if (boxes.length === 0) {
67
+ return Promise.resolve();
68
+ }
69
+ const reduced = reducedMotion();
70
+ const written = options.color ?? WASH;
71
+ const color = written.startsWith('--') ? `var(${written})` : written;
72
+ const slow = millisecondsOf(readTiming(element, undefined, '--helix-duration-slow', '320ms'), 320);
73
+ const usual = reduced && slow < 1 ? 320 : slow;
74
+ const hold = options.hold === undefined
75
+ ? usual
76
+ : millisecondsOf(readTiming(element, options.hold, '--helix-duration-slow', '320ms'), usual);
77
+ const asked = options.duration === undefined
78
+ ? usual * 2
79
+ : millisecondsOf(readTiming(element, options.duration, '--helix-duration-slow', '320ms'), usual * 2);
80
+ const fade = reduced
81
+ ? Math.min(asked, millisecondsOf(readTiming(element, undefined, '--helix-duration-fade', '120ms'), 120))
82
+ : asked;
83
+ const ramp = millisecondsOf(readTiming(element, undefined, '--helix-duration-fast', '120ms'), 120);
84
+ return Promise.all(boxes.map((box) => flashBox(box, color, { fade, hold, ramp }, reduced))).then(() => undefined);
85
+ };
@@ -0,0 +1,36 @@
1
+ /** How `resizeFrom` times the move. */
2
+ export interface ResizeFromOptions {
3
+ /**
4
+ * The move in flight on the element, if any. It ends before the new height
5
+ * is measured, so a move started during another measures where the element
6
+ * comes to rest and starts from where it is drawn.
7
+ */
8
+ previous?: Animation | undefined;
9
+ /**
10
+ * The move's duration and curve, read once the new height is known. The
11
+ * duration is in milliseconds, or a CSS time such as `320ms` or `0.32s`. A
12
+ * duration under a millisecond, or one that does not read as a time, moves
13
+ * nothing.
14
+ */
15
+ timing: () => {
16
+ duration: number | string;
17
+ easing: string;
18
+ };
19
+ }
20
+ /**
21
+ * Moves an element's height from `from`, in pixels, to the height it lays out
22
+ * at next. Resolves with the move, or with `undefined` where nothing moves:
23
+ * the two heights are within a pixel, the duration is under a millisecond, or
24
+ * the reader asked for reduced motion.
25
+ *
26
+ * **A height is often a keyword**, such as `auto` or `fit-content`, which no
27
+ * transition can follow. So the move runs on the two measured heights, as a
28
+ * `block-size` animation, and the keyword is in place again once it ends.
29
+ *
30
+ * **Measured once the change has laid out.** Content that arrives in updates
31
+ * of its own lays out a frame after the change that asked for it, so a height
32
+ * read at once is short of where the element comes to rest. A new
33
+ * `ResizeObserver` reports once, after layout and before that frame is
34
+ * painted, and the move starts there, so no frame shows the new height first.
35
+ */
36
+ export declare const resizeFrom: (element: HTMLElement, from: number, options: ResizeFromOptions) => Promise<Animation | undefined>;
@@ -0,0 +1,37 @@
1
+ import { reducedMotion } from '../page-motion/page-motion.js';
2
+ const milliseconds = (value) => {
3
+ if (typeof value === 'number') {
4
+ return value;
5
+ }
6
+ const amount = Number.parseFloat(value);
7
+ if (!Number.isFinite(amount)) {
8
+ return 0;
9
+ }
10
+ return value.trim().endsWith('ms') ? amount : amount * 1000;
11
+ };
12
+ export const resizeFrom = (element, from, options) => {
13
+ if (typeof element.animate !== 'function' ||
14
+ typeof ResizeObserver === 'undefined' ||
15
+ reducedMotion()) {
16
+ options.previous?.cancel();
17
+ return Promise.resolve(undefined);
18
+ }
19
+ return new Promise((resolve) => {
20
+ const watcher = new ResizeObserver(() => {
21
+ watcher.disconnect();
22
+ options.previous?.cancel();
23
+ const to = element.getBoundingClientRect().height;
24
+ const { duration, easing } = options.timing();
25
+ const length = milliseconds(duration);
26
+ if (Math.abs(to - from) < 1 || !(length >= 1)) {
27
+ resolve(undefined);
28
+ return;
29
+ }
30
+ resolve(element.animate([{ blockSize: `${from}px` }, { blockSize: `${to}px` }], {
31
+ duration: length,
32
+ easing: easing.trim() || 'ease-out',
33
+ }));
34
+ });
35
+ watcher.observe(element);
36
+ });
37
+ };
@@ -0,0 +1,57 @@
1
+ /** One level a scale rules, as `levelsOf` gives it. */
2
+ export interface Level {
3
+ /**
4
+ * Whether the scale before this one ruled the level and this one does not.
5
+ * A chart draws such a level hidden, at its place on the new scale, so a
6
+ * stylesheet can fade it out as it moves there with the others.
7
+ */
8
+ leaving: boolean;
9
+ /** The value the level is at. */
10
+ level: number;
11
+ }
12
+ /**
13
+ * The levels a scale rules, followed by the levels the scale before it ruled
14
+ * that it does not.
15
+ *
16
+ * **A rule or a number that stays on the axis is the same element**, keyed by
17
+ * its value, so a stylesheet moves it from its place on the old scale to its
18
+ * place on the new one. A level the new scale adds is a new element, which a
19
+ * stylesheet fades in. A level the new scale drops says `leaving`, so the
20
+ * chart can keep it through its fade.
21
+ *
22
+ * **In order of value, the leaving among the rest.** Kept that way, a keyed
23
+ * list moves no element it keeps from one place in the list to another, and
24
+ * an element moved in the document starts its style afresh: it would fade in
25
+ * again and never travel.
26
+ *
27
+ * @param domain The scale's lowest and highest values.
28
+ * @param before The scale before this one, which `ScaleMemory` holds, or nothing.
29
+ */
30
+ export declare const levelsOf: (domain: readonly [number, number], before?: readonly [number, number]) => Level[];
31
+ /**
32
+ * The scale a chart drew before the one it draws now, for `levelsOf`.
33
+ *
34
+ * **Held until the scale changes again.** A chart draws again on every move
35
+ * of the pointer, so a scale held for one drawing would take the levels the
36
+ * last change dropped away in the middle of their fade. They stay, hidden, until the
37
+ * next change, which drops them for good.
38
+ */
39
+ export declare class ScaleMemory {
40
+ private now;
41
+ private was;
42
+ /**
43
+ * Records the scale drawn now and gives the one drawn before it, or nothing
44
+ * on the first drawing.
45
+ *
46
+ * @param domain The scale's lowest and highest values.
47
+ */
48
+ before(domain: readonly [number, number]): readonly [number, number] | undefined;
49
+ }
50
+ /**
51
+ * Where a leaving level stands on the new scale, held inside the plot, so a
52
+ * number the scale stretched far past its end fades out at the end it left
53
+ * from.
54
+ *
55
+ * @param place A level's place along the plot, from 0 to 100.
56
+ */
57
+ export declare const heldInside: (place: number) => number;
@@ -0,0 +1,19 @@
1
+ import { ticks } from './ticks.js';
2
+ export const levelsOf = (domain, before) => {
3
+ const now = ticks(domain);
4
+ const gone = before === undefined ? [] : ticks(before).filter((level) => !now.includes(level));
5
+ return [
6
+ ...now.map((level) => ({ leaving: false, level })),
7
+ ...gone.map((level) => ({ leaving: true, level })),
8
+ ].sort((one, other) => one.level - other.level);
9
+ };
10
+ export class ScaleMemory {
11
+ before(domain) {
12
+ if (this.now === undefined || this.now[0] !== domain[0] || this.now[1] !== domain[1]) {
13
+ this.was = this.now;
14
+ this.now = [domain[0], domain[1]];
15
+ }
16
+ return this.was;
17
+ }
18
+ }
19
+ export const heldInside = (place) => Math.min(100, Math.max(0, place));
@@ -61,3 +61,55 @@ export declare const snapTravel: (size: number, fraction: number) => number;
61
61
  * a right-to-left one. A quarter of the width, or a fling, is enough.
62
62
  */
63
63
  export declare const swipeStep: (dx: number, vx: number, width: number, rtl: boolean) => -1 | 0 | 1;
64
+ /**
65
+ * How far a surface is drawn past a bound, for a drag that went `over` pixels
66
+ * past it, on a surface `size` pixels long along the drag.
67
+ */
68
+ export declare const resist: (over: number, size: number) => number;
69
+ /**
70
+ * Where a surface dragged to `travel` is drawn: where the finger is between
71
+ * `min` and `max`, and with resistance past either.
72
+ */
73
+ export declare const resisted: (travel: number, min: number, max: number, size: number) => number;
74
+ /** A release on its way to rest: how long it takes, and where it is after `elapsed` milliseconds. */
75
+ export interface Glide {
76
+ /** The travel `elapsed` milliseconds after the release. */
77
+ at: (elapsed: number) => number;
78
+ /** How long the glide takes, in milliseconds. */
79
+ duration: number;
80
+ }
81
+ /**
82
+ * The glide off the edge after a release that dismisses: from `from` to `to`,
83
+ * starting at `velocity`, in pixels per millisecond, and taking at most
84
+ * `longest` milliseconds.
85
+ *
86
+ * **It leaves at the speed it was let go.** Thrown fast enough to cover the
87
+ * distance in `longest`, it keeps that speed to the edge. Let go slowly, or
88
+ * moving back, it starts at that speed and gathers pace evenly, so the speed
89
+ * never jumps at the release.
90
+ */
91
+ export declare const exitGlide: (from: number, to: number, velocity: number, longest: number) => Glide;
92
+ /**
93
+ * The glide back to rest after a release that does not dismiss: along the
94
+ * host's curve from `from` to `to`, in at most `duration` milliseconds, with
95
+ * the speed it was let go at carried in. `curve` is the curve's progress at
96
+ * evenly spaced points from its start to its end, the browser's reading of a
97
+ * timing function such as `--helix-easing-spring`.
98
+ *
99
+ * **A spring starts from standing, and a release usually does not.** Run from
100
+ * its start, `--helix-easing-spring` covers a tenth of the way in its first
101
+ * quarter and then half of it in the next twelfth, so a surface let go moving
102
+ * toward its rest slowed almost to a stop and then lurched: measured in
103
+ * Chromium on November 19, 2026, 16 pixels a frame before the release, then
104
+ * 8, 4, 1, 3, 5 and 29. Moving toward its rest, the glide enters the curve at
105
+ * the first point that moves as fast as the release, and fits its length so
106
+ * it starts at the release's speed, within half and the whole of `duration`.
107
+ *
108
+ * **What the curve cannot match is pushed and spent.** The difference between
109
+ * the release's speed and the curve's, all of it for a release moving away
110
+ * from rest or standing on it, is added as a push that starts at that speed
111
+ * and dies away, `v·t·e^(−t/τ)` with τ an eighth of the glide: a flick away
112
+ * from rest carries the surface on a little before the curve brings it back,
113
+ * and the push has spent all but a few ten-thousandths of itself by the end.
114
+ */
115
+ export declare const settleGlide: (from: number, to: number, velocity: number, duration: number, curve?: readonly number[]) => Glide;