@mark1russell7/visuals 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -3
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/replay-DvGYPe7T.d.ts +95 -0
- package/build/replay-DvGYPe7T.d.ts.map +1 -0
- package/build/replay-YdWMyFko.js +172 -0
- package/build/replay-YdWMyFko.js.map +1 -0
- package/build/scrubber.d.ts +93 -0
- package/build/scrubber.d.ts.map +1 -0
- package/build/scrubber.js +265 -0
- package/build/scrubber.js.map +1 -0
- package/package.json +12 -3
- package/styles/scrubber.css +289 -0
package/README.md
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
3D stages for data. A stage is one canvas of three.js with a camera that a person moves. The content of the stage is your data.
|
|
4
4
|
|
|
5
|
-
The package has
|
|
5
|
+
The package has five entries and one style sheet:
|
|
6
6
|
|
|
7
|
-
- The entry `.` has the camera maths
|
|
7
|
+
- The entry `.` has the camera maths and the model of a replay. It needs no browser, and it does not need `three`.
|
|
8
8
|
- The entry `/marks` has the marks that a viewer draws, as plain data. It needs no browser, and it does not need `three`.
|
|
9
9
|
- The entry `/three` has the stage. It needs the package `three`, version 0.187.0 or later.
|
|
10
10
|
- The entry `/globe` has a content that shows the Earth as a globe, with areas and points on it. It also needs `three`.
|
|
11
|
+
- The entry `/scrubber` has a control that sets the time of a picture. It needs a browser, and it does not need `three`.
|
|
12
|
+
- The file `/scrubber.css` is the style sheet of the scrubber.
|
|
11
13
|
|
|
12
14
|
## Install
|
|
13
15
|
|
|
@@ -15,7 +17,7 @@ The package has four entries:
|
|
|
15
17
|
npm install @mark1russell7/visuals three
|
|
16
18
|
```
|
|
17
19
|
|
|
18
|
-
A package that uses only the entries
|
|
20
|
+
A package that uses only the entries `.`, `/marks` and `/scrubber` does not install `three`.
|
|
19
21
|
|
|
20
22
|
## A stage
|
|
21
23
|
|
|
@@ -205,6 +207,88 @@ surface.corners.length / 2; // => 43: the corners of the outline with a step of
|
|
|
205
207
|
surface.triangles.length / 3; // => 70
|
|
206
208
|
```
|
|
207
209
|
|
|
210
|
+
## A scrubber
|
|
211
|
+
|
|
212
|
+
The entry `/scrubber` has a control with which a person sets the time of a picture, and replays its changes.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { changeTimes, isLive, replayOf, type Lifetime } from "@mark1russell7/visuals";
|
|
216
|
+
import { createScrubber } from "@mark1russell7/visuals/scrubber";
|
|
217
|
+
import "@mark1russell7/visuals/scrubber.css";
|
|
218
|
+
|
|
219
|
+
// The value of each part of a globe is its lifetime, in hours.
|
|
220
|
+
const lives: readonly Lifetime[] = [{ from: 6, to: 18 }, { from: 12 }];
|
|
221
|
+
|
|
222
|
+
const scrubber = createScrubber(document.body, {
|
|
223
|
+
label: "Time of the picture",
|
|
224
|
+
replay: replayOf({ from: 0, to: 24 }),
|
|
225
|
+
times: changeTimes(lives), // => [6, 12, 18]
|
|
226
|
+
labels: [
|
|
227
|
+
{ at: 0, text: "00:00" },
|
|
228
|
+
{ at: 12, text: "12:00" },
|
|
229
|
+
],
|
|
230
|
+
format: (at) => `${String(Math.floor(at)).padStart(2, "0")}:00`,
|
|
231
|
+
onChange: ({ at }) => {
|
|
232
|
+
globe.show((part) => isLive(part.value, at));
|
|
233
|
+
stage.refresh();
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
- The control has a button for the replay, the text of the time, a slider on an axis and a button for the speed.
|
|
239
|
+
- The axis has a tick at each time of `times`. The ticks of the time that passed have the color of the ink.
|
|
240
|
+
- The slider is an `input` of the type `range`. A pointer, a touch screen, a keyboard and a screen reader use it.
|
|
241
|
+
- The arrow keys go from one change to the next change. The keys `PageUp` and `PageDown` go a tenth of the range.
|
|
242
|
+
- The keys `Home` and `End` go to the ends of the range. The key Space starts and stops the replay.
|
|
243
|
+
- A replay at the end of its range starts again from the start. A replay stops at the end.
|
|
244
|
+
- `onChange` gets each new state. The control knows nothing about the picture, so it works with each stage and each page.
|
|
245
|
+
- `setReplay`, `setTimes` and `setLabels` change the control from the page, for example after new data.
|
|
246
|
+
- The control writes no inline style and no inline script, so it works under a strict content security policy.
|
|
247
|
+
|
|
248
|
+
The style sheet is plain CSS. A bundler takes it from the import. A page with no bundler links to the file of the package.
|
|
249
|
+
The control takes its font and the color of its text from the page.
|
|
250
|
+
|
|
251
|
+
| Variable | What it sets | Default |
|
|
252
|
+
| --- | --- | --- |
|
|
253
|
+
| `--scrubber-ink` | The color of the handle, the ticks of the time that passed, and the button of the replay. | The color of the text |
|
|
254
|
+
| `--scrubber-quiet` | The color of the labels of the axis. | 68% of the color of the text |
|
|
255
|
+
| `--scrubber-line` | The color of the ticks of the time to come, and of the border of the button of the speed. | 45% of the color of the text |
|
|
256
|
+
| `--scrubber-surface` | The color in the ring of the handle. Give it the color behind the control. | `Canvas` |
|
|
257
|
+
| `--scrubber-focus` | The color of the focus ring. | `Highlight` |
|
|
258
|
+
| `--scrubber-time-width` | The width of the text of the time in a control with one row. Thus the axis does not move. | `11rem` |
|
|
259
|
+
|
|
260
|
+
A narrow control has two rows. A control that is 44 rem wide or more has one row. The width is the width of its container.
|
|
261
|
+
|
|
262
|
+
## The replay
|
|
263
|
+
|
|
264
|
+
A replay is a value: a range of time, the time of the picture, the speed, and if the time goes. Each function gives a new value.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { changeIndex, changeTimes, isLive, replayAdvance, replayKey, replayOf, replayPlay } from "@mark1russell7/visuals";
|
|
268
|
+
|
|
269
|
+
const times = changeTimes([{ from: 6, to: 18 }, { from: 12 }]); // => [6, 12, 18]
|
|
270
|
+
isLive({ from: 6, to: 18 }, 18); // => false: a part is not in the picture at its end
|
|
271
|
+
|
|
272
|
+
const replay = replayOf({ from: 0, to: 24 }); // The picture is at the end of the range, and the time does not go.
|
|
273
|
+
const start = replayPlay(replay); // The replay starts again from the start of the range.
|
|
274
|
+
replayAdvance(start, 5000, 20_000).at; // => 6: a quarter of the duration is a quarter of the range
|
|
275
|
+
replayKey("ArrowLeft", replay, times)?.at; // => 18: the last change before the time
|
|
276
|
+
changeIndex(times, 13); // => 2: draw the picture again only when this count changes
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
| Function | What it gives |
|
|
280
|
+
| --- | --- |
|
|
281
|
+
| `isLive` | If a part with a lifetime is in the picture at a time. |
|
|
282
|
+
| `changeTimes`, `spanOfTimes` | The sorted times at which a picture changes, and the range from the first time to the last time. |
|
|
283
|
+
| `changeAfter`, `changeBefore`, `changeIndex` | The next change, the change before, and the count of the changes that are not after a time. |
|
|
284
|
+
| `spanPart`, `spanTime` | The place of a time in a range from 0 to 1, and the time at a place. |
|
|
285
|
+
| `replayOf`, `replaySeek`, `replaySpan` | A replay of a range, a replay at a time, and a replay with a new range. |
|
|
286
|
+
| `replayPlay`, `replayPause`, `replayToggle` | A replay that goes, and a replay that does not go. |
|
|
287
|
+
| `replayAdvance` | The replay after a time of the clock. |
|
|
288
|
+
| `replayNextSpeed`, `replayKey` | The replay with the next speed, and the replay after a key. |
|
|
289
|
+
|
|
290
|
+
A time is a number in a unit that the page chooses. `replaySpan` keeps a picture of the present at the present when the range becomes longer.
|
|
291
|
+
|
|
208
292
|
## The marks
|
|
209
293
|
|
|
210
294
|
A mark is a record that a viewer draws. A mark is plain data with no topic, so each viewer draws the marks of each producer.
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { A as turnBetween, C as ViewAxes, D as fitDistance, E as clampPlace, M as viewOf, O as placeBetween, S as ViewAngles, T as capDistance, _ as reachOf, a as NO_HIGHLIGHTS, b as Place, c as FIT_MARGIN, d as StageView, f as ViewFrame, g as nearDepth, h as fitView, i as Highlights, j as viewAxes, k as speedAt, l as StageExtent, m as capView, n as CLICK_DISTANCE, o as highlightOf, p as ballView, r as Highlight, s as isClick, t as StageTheme, u as StageLimits, v as stageLimits, w as cameraPosition, x as PlaceLimits, y as surfaceOf } from "./theme-CKXd_emk.js";
|
|
2
|
+
import { C as spanPart, S as spanOfTimes, _ as replayPause, a as REPLAY_STEP, b as replaySpan, c as changeAfter, d as changeTimes, f as isLive, g as replayOf, h as replayNextSpeed, i as REPLAY_SPEEDS, l as changeBefore, m as replayKey, n as REPLAY_DURATION, o as Replay, p as replayAdvance, r as REPLAY_PAGE, s as TimeSpan, t as Lifetime, u as changeIndex, v as replayPlay, w as spanTime, x as replayToggle, y as replaySeek } from "./replay-DvGYPe7T.js";
|
|
2
3
|
/** The angle of one step of an arrow key, in radians, for a camera far from the surface. */
|
|
3
4
|
export declare const KEY_TURN: number;
|
|
4
5
|
/** The factor of the height of a camera above the surface for one step of the key `+`. */
|
|
@@ -60,5 +61,5 @@ export declare function moveAt(move: Move, now: number, surface?: number): MoveS
|
|
|
60
61
|
* A step with no time gives the goal. A value nearer to the goal than `snap` becomes the goal, so the steps have an end.
|
|
61
62
|
*/
|
|
62
63
|
export declare function approach(value: number, goal: number, seconds: number, time: number, snap?: number): number;
|
|
63
|
-
export { CLICK_DISTANCE, FIT_MARGIN, type Highlight, type Highlights, type KeyAction, type KeyOptions, type Move, type MoveStep, NO_HIGHLIGHTS, type Place, type PlaceLimits, type StageExtent, type StageLimits, type StageTheme, type StageView, type ViewAngles, type ViewAxes, type ViewFrame, ballView, cameraPosition, capDistance, capView, clampPlace, fitDistance, fitView, highlightOf, isClick, nearDepth, placeBetween, reachOf, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
|
|
64
|
+
export { CLICK_DISTANCE, FIT_MARGIN, type Highlight, type Highlights, type KeyAction, type KeyOptions, type Lifetime, type Move, type MoveStep, NO_HIGHLIGHTS, type Place, type PlaceLimits, REPLAY_DURATION, REPLAY_PAGE, REPLAY_SPEEDS, REPLAY_STEP, type Replay, type StageExtent, type StageLimits, type StageTheme, type StageView, type TimeSpan, type ViewAngles, type ViewAxes, type ViewFrame, ballView, cameraPosition, capDistance, capView, changeAfter, changeBefore, changeIndex, changeTimes, clampPlace, fitDistance, fitView, highlightOf, isClick, isLive, nearDepth, placeBetween, reachOf, replayAdvance, replayKey, replayNextSpeed, replayOf, replayPause, replayPlay, replaySeek, replaySpan, replayToggle, spanOfTimes, spanPart, spanTime, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
|
|
64
65
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/keys.ts","../src/motion.ts"],"mappings":";;;qBAGa;;qBAGA;;KAGD;WAAuB;WAAwB,OAAO;;WAAqB;WAAuB;;;UAG7F;;WAEN;;WAEA,QAAQ,SAAS;;WAEjB;;;;;;;;;wBAUK,UAAU,aAAa,KAAK,OAAO,SAAS,aAAa;;UCzBxD;WACN,MAAM;WACN,IAAI;;WAEJ;;WAEA;;;UAIM;WACN,OAAO;;WAEP;;;;;;wBAOK,UAAU;;;;;wBASV,OAAO,MAAM,MAAM,aAAa,mBAAsB;;;;;;;wBAYtD,SAAS,eAAe,cAAc,iBAAiB,cAAc"}
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { _ as viewOf, a as nearDepth, c as surfaceOf, d as clampPlace, f as fitDistance, g as viewAxes, h as turnBetween, i as fitView, l as cameraPosition, m as speedAt, n as ballView, o as reachOf, p as placeBetween, r as capView, s as stageLimits, t as FIT_MARGIN, u as capDistance } from "./extent-CALhBZU-.js";
|
|
2
2
|
import { a as NO_HIGHLIGHTS, c as KEY_TURN, i as CLICK_DISTANCE, l as KEY_ZOOM, n as easeInOut, o as highlightOf, r as moveAt, s as isClick, t as approach, u as keyAction } from "./motion-0tsT6sY4.js";
|
|
3
|
-
|
|
3
|
+
import { _ as replaySpan, a as changeAfter, b as spanPart, c as changeTimes, d as replayKey, f as replayNextSpeed, g as replaySeek, h as replayPlay, i as REPLAY_STEP, l as isLive, m as replayPause, n as REPLAY_PAGE, o as changeBefore, p as replayOf, r as REPLAY_SPEEDS, s as changeIndex, t as REPLAY_DURATION, u as replayAdvance, v as replayToggle, x as spanTime, y as spanOfTimes } from "./replay-YdWMyFko.js";
|
|
4
|
+
export { CLICK_DISTANCE, FIT_MARGIN, KEY_TURN, KEY_ZOOM, NO_HIGHLIGHTS, REPLAY_DURATION, REPLAY_PAGE, REPLAY_SPEEDS, REPLAY_STEP, approach, ballView, cameraPosition, capDistance, capView, changeAfter, changeBefore, changeIndex, changeTimes, clampPlace, easeInOut, fitDistance, fitView, highlightOf, isClick, isLive, keyAction, moveAt, nearDepth, placeBetween, reachOf, replayAdvance, replayKey, replayNextSpeed, replayOf, replayPause, replayPlay, replaySeek, replaySpan, replayToggle, spanOfTimes, spanPart, spanTime, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A range of time, with its two ends. Each time of this file is a number in one unit that the page chooses, for example milliseconds.
|
|
3
|
+
* A range is also a lifetime that has an end.
|
|
4
|
+
*/
|
|
5
|
+
interface TimeSpan {
|
|
6
|
+
readonly from: number;
|
|
7
|
+
/** The end of the range. It is not before `from`. */
|
|
8
|
+
readonly to: number;
|
|
9
|
+
}
|
|
10
|
+
/** The time in which a part of a content is in the picture. */
|
|
11
|
+
interface Lifetime {
|
|
12
|
+
/** The first time of the part. */
|
|
13
|
+
readonly from: number;
|
|
14
|
+
/** The first time after the part. A part with no `to` has no end. */
|
|
15
|
+
readonly to?: number | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */
|
|
18
|
+
declare function isLive(life: Lifetime, at: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* This function gives the times at which a picture changes: each start and each end of a lifetime.
|
|
21
|
+
* The result has each time once, from the first time to the last time. A time that is not finite is not in the result.
|
|
22
|
+
*/
|
|
23
|
+
declare function changeTimes(lives: Iterable<Lifetime>): readonly number[];
|
|
24
|
+
/** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */
|
|
25
|
+
declare function spanOfTimes(times: readonly number[]): TimeSpan | undefined;
|
|
26
|
+
/** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */
|
|
27
|
+
declare function changeAfter(times: readonly number[], at: number): number | undefined;
|
|
28
|
+
/** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */
|
|
29
|
+
declare function changeBefore(times: readonly number[], at: number): number | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* This function gives the count of the times of a sorted list that are not after `at`.
|
|
32
|
+
* The picture of two times with the same count is the same picture, so a page draws again only after a new count.
|
|
33
|
+
*/
|
|
34
|
+
declare function changeIndex(times: readonly number[], at: number): number;
|
|
35
|
+
/** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */
|
|
36
|
+
declare function spanPart(span: TimeSpan, at: number): number;
|
|
37
|
+
/** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */
|
|
38
|
+
declare function spanTime(span: TimeSpan, part: number): number;
|
|
39
|
+
/** The state of a replay: a control shows the picture of one time of a range, and it can go through the range. */
|
|
40
|
+
interface Replay {
|
|
41
|
+
readonly span: TimeSpan;
|
|
42
|
+
/** The time of the picture. It is in the range. */
|
|
43
|
+
readonly at: number;
|
|
44
|
+
/** This value is true while the time goes forward. */
|
|
45
|
+
readonly playing: boolean;
|
|
46
|
+
/** The speed, as a factor. A replay with the speed 1 goes through the range in the duration that `replayAdvance` gets. */
|
|
47
|
+
readonly speed: number;
|
|
48
|
+
}
|
|
49
|
+
/** The time in which a replay with the speed 1 goes through its range, in milliseconds. */
|
|
50
|
+
declare const REPLAY_DURATION = 2e4;
|
|
51
|
+
/** The speeds of a replay that a control offers, from the slowest to the fastest. */
|
|
52
|
+
declare const REPLAY_SPEEDS: readonly number[];
|
|
53
|
+
/** The part of a range that the keys `PageUp` and `PageDown` go. */
|
|
54
|
+
declare const REPLAY_PAGE = .1;
|
|
55
|
+
/** The part of a range that an arrow key goes when the replay has no times of change. */
|
|
56
|
+
declare const REPLAY_STEP = .01;
|
|
57
|
+
/**
|
|
58
|
+
* This function gives a replay that does not go. With no time, the picture is at the end of the range.
|
|
59
|
+
* The end of a range is the present for a content that shows live data.
|
|
60
|
+
*/
|
|
61
|
+
declare function replayOf(span: TimeSpan, at?: number): Replay;
|
|
62
|
+
/** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */
|
|
63
|
+
declare function replaySeek(replay: Replay, at: number): Replay;
|
|
64
|
+
/** This function starts a replay. A replay at the end of its range starts again from the start of the range. */
|
|
65
|
+
declare function replayPlay(replay: Replay): Replay;
|
|
66
|
+
/** This function stops a replay at its time. */
|
|
67
|
+
declare function replayPause(replay: Replay): Replay;
|
|
68
|
+
/** This function starts a replay that does not go, and it stops a replay that goes. */
|
|
69
|
+
declare function replayToggle(replay: Replay): Replay;
|
|
70
|
+
/**
|
|
71
|
+
* This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.
|
|
72
|
+
* The replay stops at the end of its range. A replay that does not go stays the same value.
|
|
73
|
+
*/
|
|
74
|
+
declare function replayAdvance(replay: Replay, elapsed: number, duration?: number): Replay;
|
|
75
|
+
/**
|
|
76
|
+
* This function gives a replay with the next speed of a list. After the last speed comes the first speed.
|
|
77
|
+
* A speed that is not in the list gets the first speed that is higher, or the first speed of the list.
|
|
78
|
+
*/
|
|
79
|
+
declare function replayNextSpeed(replay: Replay, speeds?: readonly number[]): Replay;
|
|
80
|
+
/**
|
|
81
|
+
* This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.
|
|
82
|
+
* Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.
|
|
83
|
+
*/
|
|
84
|
+
declare function replaySpan(replay: Replay, span: TimeSpan): Replay;
|
|
85
|
+
/**
|
|
86
|
+
* This function gives the replay after a key of a slider, or `undefined` for a key with no action.
|
|
87
|
+
*
|
|
88
|
+
* The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.
|
|
89
|
+
* The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.
|
|
90
|
+
* Each of these keys stops a replay that goes, because the person sets the time.
|
|
91
|
+
* The key Space starts a replay that does not go, and it stops a replay that goes.
|
|
92
|
+
*/
|
|
93
|
+
declare function replayKey(key: string, replay: Replay, times?: readonly number[]): Replay | undefined;
|
|
94
|
+
export { spanPart as C, spanOfTimes as S, replayPause as _, REPLAY_STEP as a, replaySpan as b, changeAfter as c, changeTimes as d, isLive as f, replayOf as g, replayNextSpeed as h, REPLAY_SPEEDS as i, changeBefore as l, replayKey as m, REPLAY_DURATION as n, Replay as o, replayAdvance as p, REPLAY_PAGE as r, TimeSpan as s, Lifetime as t, changeIndex as u, replayPlay as v, spanTime as w, replayToggle as x, replaySeek as y };
|
|
95
|
+
//# sourceMappingURL=replay-DvGYPe7T.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-DvGYPe7T.d.ts","names":[],"sources":["../src/replay.ts"],"mappings":";;;;UAIiB;WACN;;WAEA;;;UAIM;;WAEN;;WAEA;;;iBAIK,OAAO,MAAM,UAAU;;;;;iBAQvB,YAAY,OAAO,SAAS;;iBAU5B,YAAY,2BAA2B;;iBAOvC,YAAY,0BAA0B;;iBAKtC,aAAa,0BAA0B;;;;;iBAQvC,YAAY,0BAA0B;;iBAKtC,SAAS,MAAM,UAAU;;iBAMzB,SAAS,MAAM,UAAU;;UAKxB;WACN,MAAM;;WAEN;;WAEA;;WAEA;;;cAIE;;cAGA;;cAGA;;cAGA;;;;;iBAMG,SAAS,MAAM,UAAU,cAAuB;;iBAKhD,WAAW,QAAQ,QAAQ,aAAa;;iBAMxC,WAAW,QAAQ,SAAS;;iBAM5B,YAAY,QAAQ,SAAS;;iBAK7B,aAAa,QAAQ,SAAS;;;;;iBAQ9B,cAAc,QAAQ,QAAQ,iBAAiB,oBAAqC;;;;;iBAWpF,gBAAgB,QAAQ,QAAQ,6BAA4C;;;;;iBAS5E,WAAW,QAAQ,QAAQ,MAAM,WAAW;;;;;;;;;iBAc5C,UAAU,aAAa,QAAQ,QAAQ,4BAAgC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// src/replay.ts
|
|
2
|
+
/** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */
|
|
3
|
+
function isLive(life, at) {
|
|
4
|
+
return life.from <= at && (life.to === void 0 || at < life.to);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This function gives the times at which a picture changes: each start and each end of a lifetime.
|
|
8
|
+
* The result has each time once, from the first time to the last time. A time that is not finite is not in the result.
|
|
9
|
+
*/
|
|
10
|
+
function changeTimes(lives) {
|
|
11
|
+
const times = /* @__PURE__ */ new Set();
|
|
12
|
+
for (const life of lives) {
|
|
13
|
+
if (Number.isFinite(life.from)) times.add(life.from);
|
|
14
|
+
if (life.to !== void 0 && Number.isFinite(life.to)) times.add(life.to);
|
|
15
|
+
}
|
|
16
|
+
return [...times].sort((a, b) => a - b);
|
|
17
|
+
}
|
|
18
|
+
/** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */
|
|
19
|
+
function spanOfTimes(times) {
|
|
20
|
+
const from = times[0];
|
|
21
|
+
const to = times[times.length - 1];
|
|
22
|
+
return from === void 0 || to === void 0 ? void 0 : {
|
|
23
|
+
from,
|
|
24
|
+
to
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */
|
|
28
|
+
function changeAfter(times, at) {
|
|
29
|
+
return times.find((time) => time > at);
|
|
30
|
+
}
|
|
31
|
+
/** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */
|
|
32
|
+
function changeBefore(times, at) {
|
|
33
|
+
return times.findLast((time) => time < at);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This function gives the count of the times of a sorted list that are not after `at`.
|
|
37
|
+
* The picture of two times with the same count is the same picture, so a page draws again only after a new count.
|
|
38
|
+
*/
|
|
39
|
+
function changeIndex(times, at) {
|
|
40
|
+
return times.findLastIndex((time) => time <= at) + 1;
|
|
41
|
+
}
|
|
42
|
+
/** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */
|
|
43
|
+
function spanPart(span, at) {
|
|
44
|
+
const length = span.to - span.from;
|
|
45
|
+
return length > 0 ? Math.min(Math.max((at - span.from) / length, 0), 1) : 0;
|
|
46
|
+
}
|
|
47
|
+
/** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */
|
|
48
|
+
function spanTime(span, part) {
|
|
49
|
+
return span.from + (span.to - span.from) * Math.min(Math.max(part, 0), 1);
|
|
50
|
+
}
|
|
51
|
+
/** The time in which a replay with the speed 1 goes through its range, in milliseconds. */
|
|
52
|
+
const REPLAY_DURATION = 2e4;
|
|
53
|
+
/** The speeds of a replay that a control offers, from the slowest to the fastest. */
|
|
54
|
+
const REPLAY_SPEEDS = [
|
|
55
|
+
.5,
|
|
56
|
+
1,
|
|
57
|
+
2,
|
|
58
|
+
4
|
|
59
|
+
];
|
|
60
|
+
/** The part of a range that the keys `PageUp` and `PageDown` go. */
|
|
61
|
+
const REPLAY_PAGE = .1;
|
|
62
|
+
/** The part of a range that an arrow key goes when the replay has no times of change. */
|
|
63
|
+
const REPLAY_STEP = .01;
|
|
64
|
+
/**
|
|
65
|
+
* This function gives a replay that does not go. With no time, the picture is at the end of the range.
|
|
66
|
+
* The end of a range is the present for a content that shows live data.
|
|
67
|
+
*/
|
|
68
|
+
function replayOf(span, at = span.to) {
|
|
69
|
+
return {
|
|
70
|
+
span,
|
|
71
|
+
at: Math.min(Math.max(at, span.from), span.to),
|
|
72
|
+
playing: false,
|
|
73
|
+
speed: 1
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */
|
|
77
|
+
function replaySeek(replay, at) {
|
|
78
|
+
const next = Math.min(Math.max(at, replay.span.from), replay.span.to);
|
|
79
|
+
return next === replay.at ? replay : {
|
|
80
|
+
...replay,
|
|
81
|
+
at: next
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** This function starts a replay. A replay at the end of its range starts again from the start of the range. */
|
|
85
|
+
function replayPlay(replay) {
|
|
86
|
+
if (replay.playing || !(replay.span.to > replay.span.from)) return replay;
|
|
87
|
+
return {
|
|
88
|
+
...replay,
|
|
89
|
+
at: replay.at >= replay.span.to ? replay.span.from : replay.at,
|
|
90
|
+
playing: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** This function stops a replay at its time. */
|
|
94
|
+
function replayPause(replay) {
|
|
95
|
+
return replay.playing ? {
|
|
96
|
+
...replay,
|
|
97
|
+
playing: false
|
|
98
|
+
} : replay;
|
|
99
|
+
}
|
|
100
|
+
/** This function starts a replay that does not go, and it stops a replay that goes. */
|
|
101
|
+
function replayToggle(replay) {
|
|
102
|
+
return replay.playing ? replayPause(replay) : replayPlay(replay);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.
|
|
106
|
+
* The replay stops at the end of its range. A replay that does not go stays the same value.
|
|
107
|
+
*/
|
|
108
|
+
function replayAdvance(replay, elapsed, duration = REPLAY_DURATION) {
|
|
109
|
+
if (!replay.playing || !(elapsed > 0)) return replay;
|
|
110
|
+
const length = replay.span.to - replay.span.from;
|
|
111
|
+
const next = duration > 0 ? replay.at + elapsed / duration * length * replay.speed : replay.span.to;
|
|
112
|
+
return next >= replay.span.to ? {
|
|
113
|
+
...replay,
|
|
114
|
+
at: replay.span.to,
|
|
115
|
+
playing: false
|
|
116
|
+
} : {
|
|
117
|
+
...replay,
|
|
118
|
+
at: next
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* This function gives a replay with the next speed of a list. After the last speed comes the first speed.
|
|
123
|
+
* A speed that is not in the list gets the first speed that is higher, or the first speed of the list.
|
|
124
|
+
*/
|
|
125
|
+
function replayNextSpeed(replay, speeds = REPLAY_SPEEDS) {
|
|
126
|
+
const next = speeds.find((speed) => speed > replay.speed) ?? speeds[0];
|
|
127
|
+
return next === void 0 || next === replay.speed ? replay : {
|
|
128
|
+
...replay,
|
|
129
|
+
speed: next
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.
|
|
134
|
+
* Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.
|
|
135
|
+
*/
|
|
136
|
+
function replaySpan(replay, span) {
|
|
137
|
+
const at = replay.at >= replay.span.to ? span.to : Math.min(Math.max(replay.at, span.from), span.to);
|
|
138
|
+
return {
|
|
139
|
+
...replay,
|
|
140
|
+
span,
|
|
141
|
+
at,
|
|
142
|
+
playing: replay.playing && span.to > span.from
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* This function gives the replay after a key of a slider, or `undefined` for a key with no action.
|
|
147
|
+
*
|
|
148
|
+
* The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.
|
|
149
|
+
* The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.
|
|
150
|
+
* Each of these keys stops a replay that goes, because the person sets the time.
|
|
151
|
+
* The key Space starts a replay that does not go, and it stops a replay that goes.
|
|
152
|
+
*/
|
|
153
|
+
function replayKey(key, replay, times = []) {
|
|
154
|
+
const { span } = replay;
|
|
155
|
+
const length = span.to - span.from;
|
|
156
|
+
const to = (at) => replaySeek(replayPause(replay), at);
|
|
157
|
+
switch (key) {
|
|
158
|
+
case "ArrowRight":
|
|
159
|
+
case "ArrowUp": return to(times.length > 0 ? changeAfter(times, replay.at) ?? span.to : replay.at + length * REPLAY_STEP);
|
|
160
|
+
case "ArrowLeft":
|
|
161
|
+
case "ArrowDown": return to(times.length > 0 ? changeBefore(times, replay.at) ?? span.from : replay.at - length * REPLAY_STEP);
|
|
162
|
+
case "PageUp": return to(replay.at + length * REPLAY_PAGE);
|
|
163
|
+
case "PageDown": return to(replay.at - length * REPLAY_PAGE);
|
|
164
|
+
case "Home": return to(span.from);
|
|
165
|
+
case "End": return to(span.to);
|
|
166
|
+
case " ": return replayToggle(replay);
|
|
167
|
+
default: return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export { replaySpan as _, changeAfter as a, spanPart as b, changeTimes as c, replayKey as d, replayNextSpeed as f, replaySeek as g, replayPlay as h, REPLAY_STEP as i, isLive as l, replayPause as m, REPLAY_PAGE as n, changeBefore as o, replayOf as p, REPLAY_SPEEDS as r, changeIndex as s, REPLAY_DURATION as t, replayAdvance as u, replayToggle as v, spanTime as x, spanOfTimes as y };
|
|
171
|
+
|
|
172
|
+
//# sourceMappingURL=replay-YdWMyFko.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-YdWMyFko.js","names":[],"sources":["../src/replay.ts"],"sourcesContent":["/**\n * A range of time, with its two ends. Each time of this file is a number in one unit that the page chooses, for example milliseconds.\n * A range is also a lifetime that has an end.\n */\nexport interface TimeSpan {\n readonly from: number;\n /** The end of the range. It is not before `from`. */\n readonly to: number;\n}\n\n/** The time in which a part of a content is in the picture. */\nexport interface Lifetime {\n /** The first time of the part. */\n readonly from: number;\n /** The first time after the part. A part with no `to` has no end. */\n readonly to?: number | undefined;\n}\n\n/** This function tells if a part is in the picture at a time. A part is in the picture at `from`, and it is not in the picture at `to`. */\nexport function isLive(life: Lifetime, at: number): boolean {\n return life.from <= at && (life.to === undefined || at < life.to);\n}\n\n/**\n * This function gives the times at which a picture changes: each start and each end of a lifetime.\n * The result has each time once, from the first time to the last time. A time that is not finite is not in the result.\n */\nexport function changeTimes(lives: Iterable<Lifetime>): readonly number[] {\n const times = new Set<number>();\n for (const life of lives) {\n if (Number.isFinite(life.from)) times.add(life.from);\n if (life.to !== undefined && Number.isFinite(life.to)) times.add(life.to);\n }\n return [...times].sort((a, b) => a - b);\n}\n\n/** This function gives the range from the first change to the last change of a sorted list of times. A list with no time gives `undefined`. */\nexport function spanOfTimes(times: readonly number[]): TimeSpan | undefined {\n const from = times[0];\n const to = times[times.length - 1];\n return from === undefined || to === undefined ? undefined : { from, to };\n}\n\n/** This function gives the first time after `at` in a sorted list of times, or `undefined` when no time is after it. */\nexport function changeAfter(times: readonly number[], at: number): number | undefined {\n return times.find((time) => time > at);\n}\n\n/** This function gives the last time before `at` in a sorted list of times, or `undefined` when no time is before it. */\nexport function changeBefore(times: readonly number[], at: number): number | undefined {\n return times.findLast((time) => time < at);\n}\n\n/**\n * This function gives the count of the times of a sorted list that are not after `at`.\n * The picture of two times with the same count is the same picture, so a page draws again only after a new count.\n */\nexport function changeIndex(times: readonly number[], at: number): number {\n return times.findLastIndex((time) => time <= at) + 1;\n}\n\n/** This function gives the place of a time in a range, from 0 at the start to 1 at the end. A range with no length gives 0. */\nexport function spanPart(span: TimeSpan, at: number): number {\n const length = span.to - span.from;\n return length > 0 ? Math.min(Math.max((at - span.from) / length, 0), 1) : 0;\n}\n\n/** This function gives the time at a place of a range. `part` goes from 0 at the start to 1 at the end. */\nexport function spanTime(span: TimeSpan, part: number): number {\n return span.from + (span.to - span.from) * Math.min(Math.max(part, 0), 1);\n}\n\n/** The state of a replay: a control shows the picture of one time of a range, and it can go through the range. */\nexport interface Replay {\n readonly span: TimeSpan;\n /** The time of the picture. It is in the range. */\n readonly at: number;\n /** This value is true while the time goes forward. */\n readonly playing: boolean;\n /** The speed, as a factor. A replay with the speed 1 goes through the range in the duration that `replayAdvance` gets. */\n readonly speed: number;\n}\n\n/** The time in which a replay with the speed 1 goes through its range, in milliseconds. */\nexport const REPLAY_DURATION = 20_000;\n\n/** The speeds of a replay that a control offers, from the slowest to the fastest. */\nexport const REPLAY_SPEEDS: readonly number[] = [0.5, 1, 2, 4];\n\n/** The part of a range that the keys `PageUp` and `PageDown` go. */\nexport const REPLAY_PAGE = 0.1;\n\n/** The part of a range that an arrow key goes when the replay has no times of change. */\nexport const REPLAY_STEP = 0.01;\n\n/**\n * This function gives a replay that does not go. With no time, the picture is at the end of the range.\n * The end of a range is the present for a content that shows live data.\n */\nexport function replayOf(span: TimeSpan, at: number = span.to): Replay {\n return { span, at: Math.min(Math.max(at, span.from), span.to), playing: false, speed: 1 };\n}\n\n/** This function puts the picture of a replay at a time. A time out of the range becomes the nearest end of the range. */\nexport function replaySeek(replay: Replay, at: number): Replay {\n const next = Math.min(Math.max(at, replay.span.from), replay.span.to);\n return next === replay.at ? replay : { ...replay, at: next };\n}\n\n/** This function starts a replay. A replay at the end of its range starts again from the start of the range. */\nexport function replayPlay(replay: Replay): Replay {\n if (replay.playing || !(replay.span.to > replay.span.from)) return replay;\n return { ...replay, at: replay.at >= replay.span.to ? replay.span.from : replay.at, playing: true };\n}\n\n/** This function stops a replay at its time. */\nexport function replayPause(replay: Replay): Replay {\n return replay.playing ? { ...replay, playing: false } : replay;\n}\n\n/** This function starts a replay that does not go, and it stops a replay that goes. */\nexport function replayToggle(replay: Replay): Replay {\n return replay.playing ? replayPause(replay) : replayPlay(replay);\n}\n\n/**\n * This function moves a replay that goes by a time of the clock. `elapsed` and `duration` are in milliseconds.\n * The replay stops at the end of its range. A replay that does not go stays the same value.\n */\nexport function replayAdvance(replay: Replay, elapsed: number, duration: number = REPLAY_DURATION): Replay {\n if (!replay.playing || !(elapsed > 0)) return replay;\n const length = replay.span.to - replay.span.from;\n const next = duration > 0 ? replay.at + (elapsed / duration) * length * replay.speed : replay.span.to;\n return next >= replay.span.to ? { ...replay, at: replay.span.to, playing: false } : { ...replay, at: next };\n}\n\n/**\n * This function gives a replay with the next speed of a list. After the last speed comes the first speed.\n * A speed that is not in the list gets the first speed that is higher, or the first speed of the list.\n */\nexport function replayNextSpeed(replay: Replay, speeds: readonly number[] = REPLAY_SPEEDS): Replay {\n const next = speeds.find((speed) => speed > replay.speed) ?? speeds[0];\n return next === undefined || next === replay.speed ? replay : { ...replay, speed: next };\n}\n\n/**\n * This function gives a replay a new range, for example after new data. A replay at the end of the old range stays at the end.\n * Thus a picture of the present stays the picture of the present. A different time stays the same, in the new range.\n */\nexport function replaySpan(replay: Replay, span: TimeSpan): Replay {\n const atEnd = replay.at >= replay.span.to;\n const at = atEnd ? span.to : Math.min(Math.max(replay.at, span.from), span.to);\n return { ...replay, span, at, playing: replay.playing && span.to > span.from };\n}\n\n/**\n * This function gives the replay after a key of a slider, or `undefined` for a key with no action.\n *\n * The keys `ArrowRight` and `ArrowUp` go to the next change of `times`, and `ArrowLeft` and `ArrowDown` go to the change before.\n * The keys `PageUp` and `PageDown` go a tenth of the range. The keys `Home` and `End` go to the ends.\n * Each of these keys stops a replay that goes, because the person sets the time.\n * The key Space starts a replay that does not go, and it stops a replay that goes.\n */\nexport function replayKey(key: string, replay: Replay, times: readonly number[] = []): Replay | undefined {\n const { span } = replay;\n const length = span.to - span.from;\n const to = (at: number): Replay => replaySeek(replayPause(replay), at);\n switch (key) {\n case \"ArrowRight\":\n case \"ArrowUp\":\n return to(times.length > 0 ? (changeAfter(times, replay.at) ?? span.to) : replay.at + length * REPLAY_STEP);\n case \"ArrowLeft\":\n case \"ArrowDown\":\n return to(times.length > 0 ? (changeBefore(times, replay.at) ?? span.from) : replay.at - length * REPLAY_STEP);\n case \"PageUp\":\n return to(replay.at + length * REPLAY_PAGE);\n case \"PageDown\":\n return to(replay.at - length * REPLAY_PAGE);\n case \"Home\":\n return to(span.from);\n case \"End\":\n return to(span.to);\n case \" \":\n return replayToggle(replay);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93 @@
|
|
|
1
|
+
import { o as Replay, s as TimeSpan } from "./replay-DvGYPe7T.js";
|
|
2
|
+
/** The width of the picture of the ticks of a scrubber, in the units of its `viewBox`. */
|
|
3
|
+
export declare const TICK_BOX = 1e3;
|
|
4
|
+
/** A label of the axis of a scrubber: a text at a time. */
|
|
5
|
+
interface ScrubberLabel {
|
|
6
|
+
readonly at: number;
|
|
7
|
+
/** The text, for example "12:00" or "1 day". Keep it short: the axis of a phone is narrow. */
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}
|
|
10
|
+
/** The place of a label on the axis of a scrubber. */
|
|
11
|
+
interface LabelPlace {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
/** The place of the tick of the label, from 0 at the start of the axis to 1 at its end. */
|
|
14
|
+
readonly part: number;
|
|
15
|
+
/** The side of the text that is at the tick. A label near an end of the axis stays in the axis. */
|
|
16
|
+
readonly align: "start" | "center" | "end";
|
|
17
|
+
}
|
|
18
|
+
/** The part of the axis at each end in which a label does not have its middle at its tick. */
|
|
19
|
+
export declare const LABEL_EDGE = .08;
|
|
20
|
+
/**
|
|
21
|
+
* This function gives the places of the ticks of a list of times on an axis, in the units of `TICK_BOX`.
|
|
22
|
+
* A time out of the range has no tick. Two times with less than 0.1 unit between them have one tick.
|
|
23
|
+
*/
|
|
24
|
+
export declare function tickPlaces(span: TimeSpan, times: readonly number[]): readonly number[];
|
|
25
|
+
/** This function gives the path of the ticks of an SVG picture: one vertical line from `top` to `bottom` at each place. */
|
|
26
|
+
export declare function tickPath(places: readonly number[], top: number, bottom: number): string;
|
|
27
|
+
/** This function gives the place of each label of an axis. A label out of the range is not in the result. */
|
|
28
|
+
export declare function labelPlaces(span: TimeSpan, labels: readonly ScrubberLabel[]): readonly LabelPlace[];
|
|
29
|
+
/** The words of a scrubber. A page in a different language gives its own words. */
|
|
30
|
+
interface ScrubberWords {
|
|
31
|
+
/** The name of the button that starts the replay. */
|
|
32
|
+
readonly play: string;
|
|
33
|
+
/** The name of the button that stops the replay. */
|
|
34
|
+
readonly pause: string;
|
|
35
|
+
/** The text on the button of the speed, for example "2×". */
|
|
36
|
+
readonly speed: (speed: number) => string;
|
|
37
|
+
/** The name of the button of the speed for a person who does not see it. */
|
|
38
|
+
readonly speedName: (speed: number) => string;
|
|
39
|
+
}
|
|
40
|
+
/** The English words of a scrubber. */
|
|
41
|
+
export declare const SCRUBBER_WORDS: ScrubberWords;
|
|
42
|
+
/** The options of a scrubber. */
|
|
43
|
+
interface ScrubberOptions {
|
|
44
|
+
/** The name of the control for a person who does not see it, for example "The time of the map". */
|
|
45
|
+
readonly label: string;
|
|
46
|
+
/** The first state: the range, the time of the picture and the speed. */
|
|
47
|
+
readonly replay: Replay;
|
|
48
|
+
/** This function gives the text of a time, for example "14:05" or "Now". The control shows it, and a screen reader says it. */
|
|
49
|
+
readonly format: (at: number, replay: Replay) => string;
|
|
50
|
+
/** This function starts after each change that a person or the replay makes. Draw the picture of `replay.at` in it. */
|
|
51
|
+
readonly onChange: (replay: Replay) => void;
|
|
52
|
+
/** The sorted times at which the picture changes. The control shows a tick at each time, and the arrow keys go to them. */
|
|
53
|
+
readonly times?: readonly number[] | undefined;
|
|
54
|
+
/** The labels of the axis. */
|
|
55
|
+
readonly labels?: readonly ScrubberLabel[] | undefined;
|
|
56
|
+
/** The time in which a replay with the speed 1 goes through the range, in milliseconds. The default is `REPLAY_DURATION`. */
|
|
57
|
+
readonly duration?: number | undefined;
|
|
58
|
+
/** The speeds that the button of the speed goes through. The default is `REPLAY_SPEEDS`. */
|
|
59
|
+
readonly speeds?: readonly number[] | undefined;
|
|
60
|
+
/** The words of the control. The default is `SCRUBBER_WORDS`. */
|
|
61
|
+
readonly words?: Partial<ScrubberWords> | undefined;
|
|
62
|
+
}
|
|
63
|
+
/** A scrubber: a control with which a person sets the time of a picture, and replays how the picture changes. */
|
|
64
|
+
interface Scrubber {
|
|
65
|
+
/** The element of the control. It is in the container. */
|
|
66
|
+
readonly element: HTMLElement;
|
|
67
|
+
/** This function gives the state. */
|
|
68
|
+
replay(): Replay;
|
|
69
|
+
/** This function sets the state from the page, for example a new range after new data. It does not start `onChange`. */
|
|
70
|
+
setReplay(replay: Replay): void;
|
|
71
|
+
/** This function sets the times at which the picture changes. */
|
|
72
|
+
setTimes(times: readonly number[]): void;
|
|
73
|
+
/** This function sets the labels of the axis. */
|
|
74
|
+
setLabels(labels: readonly ScrubberLabel[]): void;
|
|
75
|
+
/** This function stops the replay and removes the control from the page. */
|
|
76
|
+
dispose(): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The longest time of one step of a replay, in milliseconds.
|
|
80
|
+
* A browser makes no picture for a page that is not in view. With this limit, the replay continues from its time when the page comes back.
|
|
81
|
+
*/
|
|
82
|
+
export declare const FRAME_LIMIT = 250;
|
|
83
|
+
/**
|
|
84
|
+
* This function makes a scrubber in a container of a page. The style sheet `@mark1russell7/visuals/scrubber.css` draws it.
|
|
85
|
+
*
|
|
86
|
+
* The control has a button for the replay, the text of the time, a slider on an axis and a button for the speed.
|
|
87
|
+
* The slider is an `input` of the type `range`, so a pointer, a touch screen, a keyboard and a screen reader use it.
|
|
88
|
+
* The arrow keys go from one change to the next change. The key Space starts and stops the replay.
|
|
89
|
+
* The control knows nothing about the picture: `onChange` gets each new state.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createScrubber(container: HTMLElement, options: ScrubberOptions): Scrubber;
|
|
92
|
+
export type { LabelPlace, Scrubber, ScrubberLabel, ScrubberOptions, ScrubberWords };
|
|
93
|
+
//# sourceMappingURL=scrubber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrubber.d.ts","names":[],"sources":["../src/scrubber/ticks.ts","../src/scrubber/scrubber.ts"],"mappings":";;qBAGa;;UAGI;WACN;;WAEA;;;UAIM;WACN;;WAEA;;WAEA;;;qBAIE;;;;;wBAMG,WAAW,MAAM,UAAU;;wBAU3B,SAAS,2BAA2B,aAAa;;wBAKjD,YAAY,MAAM,UAAU,iBAAiB,2BAA2B;;UCvCvE;;WAEN;;WAEA;;WAEA,QAAQ;;WAER,YAAY;;;qBAIV,gBAAgB;;UAQZ;;WAEN;;WAEA,QAAQ;;WAER,SAAS,YAAY,QAAQ;;WAE7B,WAAW,QAAQ;;WAEnB;;WAEA,kBAAkB;;WAElB;;WAEA;;WAEA,QAAQ,QAAQ;;;UAIV;;WAEN,SAAS;;EAElB,UAAU;;EAEV,UAAU,QAAQ;;EAElB,SAAS;;EAET,UAAU,iBAAiB;;EAE3B;;;;;;qBAOW;;;;;;;;;wBA4BG,eAAe,WAAW,aAAa,SAAS,kBAAkB"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { b as spanPart, d as replayKey, f as replayNextSpeed, g as replaySeek, m as replayPause, r as REPLAY_SPEEDS, u as replayAdvance, v as replayToggle, x as spanTime } from "./replay-YdWMyFko.js";
|
|
2
|
+
// src/scrubber/ticks.ts
|
|
3
|
+
/** The width of the picture of the ticks of a scrubber, in the units of its `viewBox`. */
|
|
4
|
+
const TICK_BOX = 1e3;
|
|
5
|
+
/** The part of the axis at each end in which a label does not have its middle at its tick. */
|
|
6
|
+
const LABEL_EDGE = .08;
|
|
7
|
+
/**
|
|
8
|
+
* This function gives the places of the ticks of a list of times on an axis, in the units of `TICK_BOX`.
|
|
9
|
+
* A time out of the range has no tick. Two times with less than 0.1 unit between them have one tick.
|
|
10
|
+
*/
|
|
11
|
+
function tickPlaces(span, times) {
|
|
12
|
+
if (!(span.to > span.from)) return [];
|
|
13
|
+
const places = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const time of times) if (time >= span.from && time <= span.to) places.add(Math.round(spanPart(span, time) * TICK_BOX * 10) / 10);
|
|
15
|
+
return [...places].sort((a, b) => a - b);
|
|
16
|
+
}
|
|
17
|
+
/** This function gives the path of the ticks of an SVG picture: one vertical line from `top` to `bottom` at each place. */
|
|
18
|
+
function tickPath(places, top, bottom) {
|
|
19
|
+
return places.map((place) => `M${String(place)} ${String(top)}V${String(bottom)}`).join("");
|
|
20
|
+
}
|
|
21
|
+
/** This function gives the place of each label of an axis. A label out of the range is not in the result. */
|
|
22
|
+
function labelPlaces(span, labels) {
|
|
23
|
+
if (!(span.to > span.from)) return [];
|
|
24
|
+
return labels.filter((label) => label.at >= span.from && label.at <= span.to).map((label) => {
|
|
25
|
+
const part = spanPart(span, label.at);
|
|
26
|
+
return {
|
|
27
|
+
text: label.text,
|
|
28
|
+
part,
|
|
29
|
+
align: part < .08 ? "start" : part > .92 ? "end" : "center"
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// src/scrubber/scrubber.ts
|
|
34
|
+
/** The English words of a scrubber. */
|
|
35
|
+
const SCRUBBER_WORDS = {
|
|
36
|
+
play: "Play",
|
|
37
|
+
pause: "Pause",
|
|
38
|
+
speed: (speed) => `${String(speed)}×`,
|
|
39
|
+
speedName: (speed) => `Change the speed. The speed is ${String(speed)}.`
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The longest time of one step of a replay, in milliseconds.
|
|
43
|
+
* A browser makes no picture for a page that is not in view. With this limit, the replay continues from its time when the page comes back.
|
|
44
|
+
*/
|
|
45
|
+
const FRAME_LIMIT = 250;
|
|
46
|
+
const SVG = "http://www.w3.org/2000/svg";
|
|
47
|
+
/** The outlines of the signs of the first button, in a box of 16 units. */
|
|
48
|
+
const PLAY_SIGN = "M5 2.5v11l9-5.5z";
|
|
49
|
+
const PAUSE_SIGN = "M3.5 2.5h3.25v11H3.5zM9.25 2.5h3.25v11H9.25z";
|
|
50
|
+
/** The height of the picture of the ticks, in the units of its `viewBox`. One unit is one sixteenth of the font size of the page. */
|
|
51
|
+
const TICK_HEIGHT = 28;
|
|
52
|
+
/** The height of the line of the axis in the picture. The ticks of the changes are above it, and the ticks of the labels are below it. */
|
|
53
|
+
const AXIS = 20;
|
|
54
|
+
/** The height of the top of a tick of a change in the picture. */
|
|
55
|
+
const TICK_TOP = 6;
|
|
56
|
+
/** The height of the bottom of a tick of a label in the picture. */
|
|
57
|
+
const STEP_BOTTOM = 26;
|
|
58
|
+
/**
|
|
59
|
+
* This function makes a scrubber in a container of a page. The style sheet `@mark1russell7/visuals/scrubber.css` draws it.
|
|
60
|
+
*
|
|
61
|
+
* The control has a button for the replay, the text of the time, a slider on an axis and a button for the speed.
|
|
62
|
+
* The slider is an `input` of the type `range`, so a pointer, a touch screen, a keyboard and a screen reader use it.
|
|
63
|
+
* The arrow keys go from one change to the next change. The key Space starts and stops the replay.
|
|
64
|
+
* The control knows nothing about the picture: `onChange` gets each new state.
|
|
65
|
+
*/
|
|
66
|
+
function createScrubber(container, options) {
|
|
67
|
+
const page = container.ownerDocument;
|
|
68
|
+
const view = page.defaultView;
|
|
69
|
+
const words = {
|
|
70
|
+
...SCRUBBER_WORDS,
|
|
71
|
+
...options.words
|
|
72
|
+
};
|
|
73
|
+
const duration = options.duration ?? 2e4;
|
|
74
|
+
const speeds = options.speeds ?? REPLAY_SPEEDS;
|
|
75
|
+
let state = options.replay;
|
|
76
|
+
let times = options.times ?? [];
|
|
77
|
+
let labels = options.labels ?? [];
|
|
78
|
+
let frame = 0;
|
|
79
|
+
let last = 0;
|
|
80
|
+
let disposed = false;
|
|
81
|
+
const make = (tag, name) => {
|
|
82
|
+
const element = page.createElement(tag);
|
|
83
|
+
element.className = `visuals-scrubber-${name}`;
|
|
84
|
+
return element;
|
|
85
|
+
};
|
|
86
|
+
const draw = (name, box) => {
|
|
87
|
+
const picture = page.createElementNS(SVG, "svg");
|
|
88
|
+
picture.setAttribute("class", `visuals-scrubber-${name}`);
|
|
89
|
+
picture.setAttribute("viewBox", box);
|
|
90
|
+
picture.setAttribute("aria-hidden", "true");
|
|
91
|
+
picture.setAttribute("focusable", "false");
|
|
92
|
+
return {
|
|
93
|
+
picture,
|
|
94
|
+
path: (part) => {
|
|
95
|
+
const path = page.createElementNS(SVG, "path");
|
|
96
|
+
path.setAttribute("class", `visuals-scrubber-${part}`);
|
|
97
|
+
picture.append(path);
|
|
98
|
+
return path;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const element = page.createElement("div");
|
|
103
|
+
element.className = "visuals-scrubber";
|
|
104
|
+
element.setAttribute("role", "group");
|
|
105
|
+
element.setAttribute("aria-label", options.label);
|
|
106
|
+
const row = make("div", "row");
|
|
107
|
+
const play = make("button", "play");
|
|
108
|
+
play.type = "button";
|
|
109
|
+
const sign = draw("sign", "0 0 16 16");
|
|
110
|
+
const signPath = sign.path("sign-shape");
|
|
111
|
+
play.append(sign.picture);
|
|
112
|
+
const time = make("span", "time");
|
|
113
|
+
const rule = make("div", "rule");
|
|
114
|
+
const box = `0 0 ${String(TICK_BOX)} ${String(TICK_HEIGHT)}`;
|
|
115
|
+
const ticks = draw("ticks", box);
|
|
116
|
+
ticks.picture.setAttribute("preserveAspectRatio", "none");
|
|
117
|
+
const ahead = ticks.path("ahead");
|
|
118
|
+
const steps = ticks.path("steps");
|
|
119
|
+
const passed = draw("ticks", box);
|
|
120
|
+
passed.picture.classList.add("visuals-scrubber-passed");
|
|
121
|
+
passed.picture.setAttribute("preserveAspectRatio", "none");
|
|
122
|
+
const past = passed.path("past");
|
|
123
|
+
const range = make("input", "range");
|
|
124
|
+
range.type = "range";
|
|
125
|
+
range.min = "0";
|
|
126
|
+
range.max = "1";
|
|
127
|
+
range.step = "any";
|
|
128
|
+
range.setAttribute("aria-label", options.label);
|
|
129
|
+
const head = make("span", "head");
|
|
130
|
+
head.setAttribute("aria-hidden", "true");
|
|
131
|
+
const axis = make("div", "labels");
|
|
132
|
+
axis.setAttribute("aria-hidden", "true");
|
|
133
|
+
rule.append(ticks.picture, passed.picture, range, head, axis);
|
|
134
|
+
const speed = make("button", "speed");
|
|
135
|
+
speed.type = "button";
|
|
136
|
+
row.append(play, time, rule, speed);
|
|
137
|
+
element.append(row);
|
|
138
|
+
/** This function draws the ticks and the labels again, after a change of the range, of the times or of the labels. */
|
|
139
|
+
function drawAxis() {
|
|
140
|
+
const places = labelPlaces(state.span, labels);
|
|
141
|
+
const line = `M0 ${String(AXIS)}H${String(TICK_BOX)}`;
|
|
142
|
+
const changes = tickPath(tickPlaces(state.span, times), TICK_TOP, AXIS);
|
|
143
|
+
ahead.setAttribute("d", line + changes);
|
|
144
|
+
past.setAttribute("d", line + changes);
|
|
145
|
+
steps.setAttribute("d", tickPath([.../* @__PURE__ */ new Set([
|
|
146
|
+
0,
|
|
147
|
+
TICK_BOX,
|
|
148
|
+
...places.map((place) => Math.round(place.part * TICK_BOX * 10) / 10)
|
|
149
|
+
])], AXIS, STEP_BOTTOM));
|
|
150
|
+
axis.replaceChildren(...places.map((place) => {
|
|
151
|
+
const label = make("span", "label");
|
|
152
|
+
label.dataset["align"] = place.align;
|
|
153
|
+
label.style.setProperty("--scrubber-at", place.part.toFixed(5));
|
|
154
|
+
label.textContent = place.text;
|
|
155
|
+
return label;
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
/** This function sets an attribute only when its value changes. A replay shows its state before each picture of the browser. */
|
|
159
|
+
const set = (target, name, value) => {
|
|
160
|
+
if (target.getAttribute(name) !== value) target.setAttribute(name, value);
|
|
161
|
+
};
|
|
162
|
+
const write = (target, text) => {
|
|
163
|
+
if (target.textContent !== text) target.textContent = text;
|
|
164
|
+
};
|
|
165
|
+
/** This function shows the state in the control. */
|
|
166
|
+
function show() {
|
|
167
|
+
const part = spanPart(state.span, state.at);
|
|
168
|
+
const text = options.format(state.at, state);
|
|
169
|
+
const still = !(state.span.to > state.span.from);
|
|
170
|
+
element.style.setProperty("--scrubber-part", part.toFixed(5));
|
|
171
|
+
set(element, "data-playing", String(state.playing));
|
|
172
|
+
if (Number(range.value) !== part) range.value = String(part);
|
|
173
|
+
set(range, "aria-valuetext", text);
|
|
174
|
+
range.disabled = still;
|
|
175
|
+
write(time, text);
|
|
176
|
+
play.disabled = still;
|
|
177
|
+
set(play, "aria-label", state.playing ? words.pause : words.play);
|
|
178
|
+
set(signPath, "d", state.playing ? PAUSE_SIGN : PLAY_SIGN);
|
|
179
|
+
write(speed, words.speed(state.speed));
|
|
180
|
+
set(speed, "aria-label", words.speedName(state.speed));
|
|
181
|
+
}
|
|
182
|
+
function step(now) {
|
|
183
|
+
frame = 0;
|
|
184
|
+
const elapsed = Math.min(now - last, 250);
|
|
185
|
+
last = now;
|
|
186
|
+
change(replayAdvance(state, elapsed, duration), true);
|
|
187
|
+
}
|
|
188
|
+
/** This function asks for the next step of a replay that goes, and stops the steps of a replay that does not go. */
|
|
189
|
+
function run() {
|
|
190
|
+
if (view === null || disposed) return;
|
|
191
|
+
if (state.playing && frame === 0) frame = view.requestAnimationFrame(step);
|
|
192
|
+
else if (!state.playing && frame !== 0) {
|
|
193
|
+
view.cancelAnimationFrame(frame);
|
|
194
|
+
frame = 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** This function sets a new state. `tell` is true for a change that the page did not make. */
|
|
198
|
+
function change(next, tell) {
|
|
199
|
+
if (next === state) {
|
|
200
|
+
run();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const newSpan = next.span !== state.span;
|
|
204
|
+
if (next.playing && !state.playing && view !== null) last = view.performance.now();
|
|
205
|
+
state = next;
|
|
206
|
+
if (newSpan) drawAxis();
|
|
207
|
+
show();
|
|
208
|
+
run();
|
|
209
|
+
if (tell) options.onChange(state);
|
|
210
|
+
}
|
|
211
|
+
const onPlay = () => {
|
|
212
|
+
change(replayToggle(state), true);
|
|
213
|
+
};
|
|
214
|
+
const onSpeed = () => {
|
|
215
|
+
change(replayNextSpeed(state, speeds), true);
|
|
216
|
+
};
|
|
217
|
+
const onInput = () => {
|
|
218
|
+
change(replaySeek(replayPause(state), spanTime(state.span, Number(range.value))), true);
|
|
219
|
+
};
|
|
220
|
+
const onKey = (event) => {
|
|
221
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
222
|
+
const next = replayKey(event.key, state, times);
|
|
223
|
+
if (next === void 0) return;
|
|
224
|
+
event.preventDefault();
|
|
225
|
+
change(next, true);
|
|
226
|
+
};
|
|
227
|
+
play.addEventListener("click", onPlay);
|
|
228
|
+
speed.addEventListener("click", onSpeed);
|
|
229
|
+
range.addEventListener("input", onInput);
|
|
230
|
+
range.addEventListener("keydown", onKey);
|
|
231
|
+
drawAxis();
|
|
232
|
+
show();
|
|
233
|
+
container.append(element);
|
|
234
|
+
if (state.playing && view !== null) last = view.performance.now();
|
|
235
|
+
run();
|
|
236
|
+
return {
|
|
237
|
+
element,
|
|
238
|
+
replay: () => state,
|
|
239
|
+
setReplay(replay) {
|
|
240
|
+
change(replay, false);
|
|
241
|
+
},
|
|
242
|
+
setTimes(next) {
|
|
243
|
+
times = next;
|
|
244
|
+
drawAxis();
|
|
245
|
+
},
|
|
246
|
+
setLabels(next) {
|
|
247
|
+
labels = next;
|
|
248
|
+
drawAxis();
|
|
249
|
+
},
|
|
250
|
+
dispose() {
|
|
251
|
+
if (disposed) return;
|
|
252
|
+
if (frame !== 0) view?.cancelAnimationFrame(frame);
|
|
253
|
+
frame = 0;
|
|
254
|
+
disposed = true;
|
|
255
|
+
play.removeEventListener("click", onPlay);
|
|
256
|
+
speed.removeEventListener("click", onSpeed);
|
|
257
|
+
range.removeEventListener("input", onInput);
|
|
258
|
+
range.removeEventListener("keydown", onKey);
|
|
259
|
+
element.remove();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export { FRAME_LIMIT, LABEL_EDGE, SCRUBBER_WORDS, TICK_BOX, createScrubber, labelPlaces, tickPath, tickPlaces };
|
|
264
|
+
|
|
265
|
+
//# sourceMappingURL=scrubber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrubber.js","names":[],"sources":["../src/scrubber/ticks.ts","../src/scrubber/scrubber.ts"],"sourcesContent":["import { spanPart, type TimeSpan } from \"../replay.ts\";\n\n/** The width of the picture of the ticks of a scrubber, in the units of its `viewBox`. */\nexport const TICK_BOX = 1000;\n\n/** A label of the axis of a scrubber: a text at a time. */\nexport interface ScrubberLabel {\n readonly at: number;\n /** The text, for example \"12:00\" or \"1 day\". Keep it short: the axis of a phone is narrow. */\n readonly text: string;\n}\n\n/** The place of a label on the axis of a scrubber. */\nexport interface LabelPlace {\n readonly text: string;\n /** The place of the tick of the label, from 0 at the start of the axis to 1 at its end. */\n readonly part: number;\n /** The side of the text that is at the tick. A label near an end of the axis stays in the axis. */\n readonly align: \"start\" | \"center\" | \"end\";\n}\n\n/** The part of the axis at each end in which a label does not have its middle at its tick. */\nexport const LABEL_EDGE = 0.08;\n\n/**\n * This function gives the places of the ticks of a list of times on an axis, in the units of `TICK_BOX`.\n * A time out of the range has no tick. Two times with less than 0.1 unit between them have one tick.\n */\nexport function tickPlaces(span: TimeSpan, times: readonly number[]): readonly number[] {\n if (!(span.to > span.from)) return [];\n const places = new Set<number>();\n for (const time of times) {\n if (time >= span.from && time <= span.to) places.add(Math.round(spanPart(span, time) * TICK_BOX * 10) / 10);\n }\n return [...places].sort((a, b) => a - b);\n}\n\n/** This function gives the path of the ticks of an SVG picture: one vertical line from `top` to `bottom` at each place. */\nexport function tickPath(places: readonly number[], top: number, bottom: number): string {\n return places.map((place) => `M${String(place)} ${String(top)}V${String(bottom)}`).join(\"\");\n}\n\n/** This function gives the place of each label of an axis. A label out of the range is not in the result. */\nexport function labelPlaces(span: TimeSpan, labels: readonly ScrubberLabel[]): readonly LabelPlace[] {\n if (!(span.to > span.from)) return [];\n return labels\n .filter((label) => label.at >= span.from && label.at <= span.to)\n .map((label) => {\n const part = spanPart(span, label.at);\n return { text: label.text, part, align: part < LABEL_EDGE ? \"start\" : part > 1 - LABEL_EDGE ? \"end\" : \"center\" };\n });\n}\n","import { REPLAY_DURATION, REPLAY_SPEEDS, replayAdvance, replayKey, replayNextSpeed, replayPause, replaySeek, replayToggle, spanPart, spanTime, type Replay } from \"../replay.ts\";\nimport { TICK_BOX, labelPlaces, tickPath, tickPlaces, type ScrubberLabel } from \"./ticks.ts\";\n\n/** The words of a scrubber. A page in a different language gives its own words. */\nexport interface ScrubberWords {\n /** The name of the button that starts the replay. */\n readonly play: string;\n /** The name of the button that stops the replay. */\n readonly pause: string;\n /** The text on the button of the speed, for example \"2×\". */\n readonly speed: (speed: number) => string;\n /** The name of the button of the speed for a person who does not see it. */\n readonly speedName: (speed: number) => string;\n}\n\n/** The English words of a scrubber. */\nexport const SCRUBBER_WORDS: ScrubberWords = {\n play: \"Play\",\n pause: \"Pause\",\n speed: (speed) => `${String(speed)}×`,\n speedName: (speed) => `Change the speed. The speed is ${String(speed)}.`,\n};\n\n/** The options of a scrubber. */\nexport interface ScrubberOptions {\n /** The name of the control for a person who does not see it, for example \"The time of the map\". */\n readonly label: string;\n /** The first state: the range, the time of the picture and the speed. */\n readonly replay: Replay;\n /** This function gives the text of a time, for example \"14:05\" or \"Now\". The control shows it, and a screen reader says it. */\n readonly format: (at: number, replay: Replay) => string;\n /** This function starts after each change that a person or the replay makes. Draw the picture of `replay.at` in it. */\n readonly onChange: (replay: Replay) => void;\n /** The sorted times at which the picture changes. The control shows a tick at each time, and the arrow keys go to them. */\n readonly times?: readonly number[] | undefined;\n /** The labels of the axis. */\n readonly labels?: readonly ScrubberLabel[] | undefined;\n /** The time in which a replay with the speed 1 goes through the range, in milliseconds. The default is `REPLAY_DURATION`. */\n readonly duration?: number | undefined;\n /** The speeds that the button of the speed goes through. The default is `REPLAY_SPEEDS`. */\n readonly speeds?: readonly number[] | undefined;\n /** The words of the control. The default is `SCRUBBER_WORDS`. */\n readonly words?: Partial<ScrubberWords> | undefined;\n}\n\n/** A scrubber: a control with which a person sets the time of a picture, and replays how the picture changes. */\nexport interface Scrubber {\n /** The element of the control. It is in the container. */\n readonly element: HTMLElement;\n /** This function gives the state. */\n replay(): Replay;\n /** This function sets the state from the page, for example a new range after new data. It does not start `onChange`. */\n setReplay(replay: Replay): void;\n /** This function sets the times at which the picture changes. */\n setTimes(times: readonly number[]): void;\n /** This function sets the labels of the axis. */\n setLabels(labels: readonly ScrubberLabel[]): void;\n /** This function stops the replay and removes the control from the page. */\n dispose(): void;\n}\n\n/**\n * The longest time of one step of a replay, in milliseconds.\n * A browser makes no picture for a page that is not in view. With this limit, the replay continues from its time when the page comes back.\n */\nexport const FRAME_LIMIT = 250;\n\nconst SVG = \"http://www.w3.org/2000/svg\";\n\n/** The outlines of the signs of the first button, in a box of 16 units. */\nconst PLAY_SIGN = \"M5 2.5v11l9-5.5z\";\nconst PAUSE_SIGN = \"M3.5 2.5h3.25v11H3.5zM9.25 2.5h3.25v11H9.25z\";\n\n/** The height of the picture of the ticks, in the units of its `viewBox`. One unit is one sixteenth of the font size of the page. */\nconst TICK_HEIGHT = 28;\n\n/** The height of the line of the axis in the picture. The ticks of the changes are above it, and the ticks of the labels are below it. */\nconst AXIS = 20;\n\n/** The height of the top of a tick of a change in the picture. */\nconst TICK_TOP = 6;\n\n/** The height of the bottom of a tick of a label in the picture. */\nconst STEP_BOTTOM = 26;\n\n/**\n * This function makes a scrubber in a container of a page. The style sheet `@mark1russell7/visuals/scrubber.css` draws it.\n *\n * The control has a button for the replay, the text of the time, a slider on an axis and a button for the speed.\n * The slider is an `input` of the type `range`, so a pointer, a touch screen, a keyboard and a screen reader use it.\n * The arrow keys go from one change to the next change. The key Space starts and stops the replay.\n * The control knows nothing about the picture: `onChange` gets each new state.\n */\nexport function createScrubber(container: HTMLElement, options: ScrubberOptions): Scrubber {\n const page = container.ownerDocument;\n const view = page.defaultView;\n const words: ScrubberWords = { ...SCRUBBER_WORDS, ...options.words };\n const duration = options.duration ?? REPLAY_DURATION;\n const speeds = options.speeds ?? REPLAY_SPEEDS;\n let state = options.replay;\n let times = options.times ?? [];\n let labels = options.labels ?? [];\n let frame = 0;\n let last = 0;\n let disposed = false;\n\n const make = <K extends keyof HTMLElementTagNameMap>(tag: K, name: string): HTMLElementTagNameMap[K] => {\n const element = page.createElement(tag);\n element.className = `visuals-scrubber-${name}`;\n return element;\n };\n const draw = (name: string, box: string): { readonly picture: SVGSVGElement; readonly path: (name: string) => SVGPathElement } => {\n const picture = page.createElementNS(SVG, \"svg\");\n picture.setAttribute(\"class\", `visuals-scrubber-${name}`);\n picture.setAttribute(\"viewBox\", box);\n picture.setAttribute(\"aria-hidden\", \"true\");\n picture.setAttribute(\"focusable\", \"false\");\n return {\n picture,\n path: (part) => {\n const path = page.createElementNS(SVG, \"path\");\n path.setAttribute(\"class\", `visuals-scrubber-${part}`);\n picture.append(path);\n return path;\n },\n };\n };\n\n const element = page.createElement(\"div\");\n element.className = \"visuals-scrubber\";\n element.setAttribute(\"role\", \"group\");\n element.setAttribute(\"aria-label\", options.label);\n const row = make(\"div\", \"row\");\n\n const play = make(\"button\", \"play\");\n play.type = \"button\";\n const sign = draw(\"sign\", \"0 0 16 16\");\n const signPath = sign.path(\"sign-shape\");\n play.append(sign.picture);\n\n const time = make(\"span\", \"time\");\n\n const rule = make(\"div\", \"rule\");\n // The axis has two pictures with the same lines: the time to come, and above it the time that passed.\n // The style sheet cuts the second picture at the time of the handle.\n const box = `0 0 ${String(TICK_BOX)} ${String(TICK_HEIGHT)}`;\n const ticks = draw(\"ticks\", box);\n ticks.picture.setAttribute(\"preserveAspectRatio\", \"none\");\n const ahead = ticks.path(\"ahead\");\n const steps = ticks.path(\"steps\");\n const passed = draw(\"ticks\", box);\n passed.picture.classList.add(\"visuals-scrubber-passed\");\n passed.picture.setAttribute(\"preserveAspectRatio\", \"none\");\n const past = passed.path(\"past\");\n const range = make(\"input\", \"range\");\n range.type = \"range\";\n range.min = \"0\";\n range.max = \"1\";\n range.step = \"any\";\n range.setAttribute(\"aria-label\", options.label);\n const head = make(\"span\", \"head\");\n head.setAttribute(\"aria-hidden\", \"true\");\n const axis = make(\"div\", \"labels\");\n axis.setAttribute(\"aria-hidden\", \"true\");\n rule.append(ticks.picture, passed.picture, range, head, axis);\n\n const speed = make(\"button\", \"speed\");\n speed.type = \"button\";\n\n row.append(play, time, rule, speed);\n element.append(row);\n\n /** This function draws the ticks and the labels again, after a change of the range, of the times or of the labels. */\n function drawAxis(): void {\n const places = labelPlaces(state.span, labels);\n const line = `M0 ${String(AXIS)}H${String(TICK_BOX)}`;\n const changes = tickPath(tickPlaces(state.span, times), TICK_TOP, AXIS);\n ahead.setAttribute(\"d\", line + changes);\n past.setAttribute(\"d\", line + changes);\n steps.setAttribute(\"d\", tickPath([...new Set([0, TICK_BOX, ...places.map((place) => Math.round(place.part * TICK_BOX * 10) / 10)])], AXIS, STEP_BOTTOM));\n axis.replaceChildren(\n ...places.map((place) => {\n const label = make(\"span\", \"label\");\n label.dataset[\"align\"] = place.align;\n label.style.setProperty(\"--scrubber-at\", place.part.toFixed(5));\n label.textContent = place.text;\n return label;\n }),\n );\n }\n\n /** This function sets an attribute only when its value changes. A replay shows its state before each picture of the browser. */\n const set = (target: Element, name: string, value: string): void => {\n if (target.getAttribute(name) !== value) target.setAttribute(name, value);\n };\n const write = (target: Element, text: string): void => {\n if (target.textContent !== text) target.textContent = text;\n };\n\n /** This function shows the state in the control. */\n function show(): void {\n const part = spanPart(state.span, state.at);\n const text = options.format(state.at, state);\n const still = !(state.span.to > state.span.from);\n element.style.setProperty(\"--scrubber-part\", part.toFixed(5));\n set(element, \"data-playing\", String(state.playing));\n if (Number(range.value) !== part) range.value = String(part);\n set(range, \"aria-valuetext\", text);\n range.disabled = still;\n write(time, text);\n play.disabled = still;\n set(play, \"aria-label\", state.playing ? words.pause : words.play);\n set(signPath, \"d\", state.playing ? PAUSE_SIGN : PLAY_SIGN);\n write(speed, words.speed(state.speed));\n set(speed, \"aria-label\", words.speedName(state.speed));\n }\n\n function step(now: number): void {\n frame = 0;\n const elapsed = Math.min(now - last, FRAME_LIMIT);\n last = now;\n change(replayAdvance(state, elapsed, duration), true);\n }\n\n /** This function asks for the next step of a replay that goes, and stops the steps of a replay that does not go. */\n function run(): void {\n if (view === null || disposed) return;\n if (state.playing && frame === 0) {\n frame = view.requestAnimationFrame(step);\n } else if (!state.playing && frame !== 0) {\n view.cancelAnimationFrame(frame);\n frame = 0;\n }\n }\n\n /** This function sets a new state. `tell` is true for a change that the page did not make. */\n function change(next: Replay, tell: boolean): void {\n if (next === state) {\n run();\n return;\n }\n const newSpan = next.span !== state.span;\n if (next.playing && !state.playing && view !== null) last = view.performance.now();\n state = next;\n if (newSpan) drawAxis();\n show();\n run();\n if (tell) options.onChange(state);\n }\n\n const onPlay = (): void => {\n change(replayToggle(state), true);\n };\n const onSpeed = (): void => {\n change(replayNextSpeed(state, speeds), true);\n };\n const onInput = (): void => {\n // The person sets the time, so the replay stops.\n change(replaySeek(replayPause(state), spanTime(state.span, Number(range.value))), true);\n };\n const onKey = (event: KeyboardEvent): void => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const next = replayKey(event.key, state, times);\n if (next === undefined) return;\n event.preventDefault();\n change(next, true);\n };\n play.addEventListener(\"click\", onPlay);\n speed.addEventListener(\"click\", onSpeed);\n range.addEventListener(\"input\", onInput);\n range.addEventListener(\"keydown\", onKey);\n\n drawAxis();\n show();\n container.append(element);\n if (state.playing && view !== null) last = view.performance.now();\n run();\n\n return {\n element,\n replay: () => state,\n setReplay(replay): void {\n change(replay, false);\n },\n setTimes(next): void {\n times = next;\n drawAxis();\n },\n setLabels(next): void {\n labels = next;\n drawAxis();\n },\n dispose(): void {\n if (disposed) return;\n if (frame !== 0) view?.cancelAnimationFrame(frame);\n frame = 0;\n disposed = true;\n play.removeEventListener(\"click\", onPlay);\n speed.removeEventListener(\"click\", onSpeed);\n range.removeEventListener(\"input\", onInput);\n range.removeEventListener(\"keydown\", onKey);\n element.remove();\n },\n };\n}\n"],"mappings":";;;AAGA,MAAa,WAAW;;AAmBxB,MAAa,aAAa;;;;;AAM1B,SAAgB,WAAW,MAAgB,OAA6C;CACtF,IAAI,EAAE,KAAK,KAAK,KAAK,OAAO,OAAO,CAAC;CACpC,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,QAAQ,OACjB,IAAI,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;GACpB,SAAS;GACT,SAAS;EACX;EACA,UAAgB;GACd,IAAI,UAAU;GACd,IAAI,UAAU,GAAG,MAAM,qBAAqB,KAAK;GACjD,QAAQ;GACR,WAAW;GACX,KAAK,oBAAoB,SAAS,MAAM;GACxC,MAAM,oBAAoB,SAAS,OAAO;GAC1C,MAAM,oBAAoB,SAAS,OAAO;GAC1C,MAAM,oBAAoB,WAAW,KAAK;GAC1C,QAAQ,OAAO;EACjB;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/visuals",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "3D stages for data on three.js: a camera that a person moves, views by name, picking, highlights and themes, a globe of the Earth, and the shared marks of the viewers as data.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"marks"
|
|
26
26
|
],
|
|
27
27
|
"type": "module",
|
|
28
|
-
"sideEffects":
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"*.css"
|
|
30
|
+
],
|
|
29
31
|
"main": "./build/index.js",
|
|
30
32
|
"exports": {
|
|
31
33
|
".": {
|
|
@@ -48,10 +50,17 @@
|
|
|
48
50
|
"import": "./build/marks.js",
|
|
49
51
|
"default": "./build/marks.js"
|
|
50
52
|
},
|
|
53
|
+
"./scrubber": {
|
|
54
|
+
"types": "./build/scrubber.d.ts",
|
|
55
|
+
"import": "./build/scrubber.js",
|
|
56
|
+
"default": "./build/scrubber.js"
|
|
57
|
+
},
|
|
58
|
+
"./scrubber.css": "./styles/scrubber.css",
|
|
51
59
|
"./package.json": "./package.json"
|
|
52
60
|
},
|
|
53
61
|
"files": [
|
|
54
|
-
"build"
|
|
62
|
+
"build",
|
|
63
|
+
"styles"
|
|
55
64
|
],
|
|
56
65
|
"dependencies": {
|
|
57
66
|
"@mark1russell7/geo": "^0.5.0",
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The style sheet of the scrubber of @mark1russell7/visuals.
|
|
3
|
+
*
|
|
4
|
+
* The scrubber takes its font and its color from the page. A page changes a color with these custom properties,
|
|
5
|
+
* on the scrubber or on an element around it:
|
|
6
|
+
*
|
|
7
|
+
* --scrubber-ink the axis, the ticks and the handle of the time that passed
|
|
8
|
+
* --scrubber-quiet the labels of the axis
|
|
9
|
+
* --scrubber-line the axis and the ticks of the time to come, and the outline of the button of the speed
|
|
10
|
+
* --scrubber-surface the color behind the scrubber: the inner part of the handle
|
|
11
|
+
* --scrubber-focus the outline of the part that has the keyboard
|
|
12
|
+
* --scrubber-time-width the width of the text of the time, when the scrubber is one row
|
|
13
|
+
*/
|
|
14
|
+
.visuals-scrubber {
|
|
15
|
+
--_ink: var(--scrubber-ink, currentColor);
|
|
16
|
+
--_quiet: var(--scrubber-quiet, color-mix(in srgb, currentColor 68%, transparent));
|
|
17
|
+
--_line: var(--scrubber-line, color-mix(in srgb, currentColor 45%, transparent));
|
|
18
|
+
--_surface: var(--scrubber-surface, Canvas);
|
|
19
|
+
--_focus: var(--scrubber-focus, Highlight);
|
|
20
|
+
--_thumb: 1.25rem;
|
|
21
|
+
--scrubber-part: 0;
|
|
22
|
+
container-type: inline-size;
|
|
23
|
+
text-align: start;
|
|
24
|
+
/* A time axis goes from the left to the right in each language. */
|
|
25
|
+
direction: ltr;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* A narrow scrubber has two rows: the buttons and the text of the time, then the axis. */
|
|
29
|
+
.visuals-scrubber-row {
|
|
30
|
+
display: grid;
|
|
31
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
32
|
+
grid-template-areas:
|
|
33
|
+
"play time speed"
|
|
34
|
+
"rule rule rule";
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 0.375rem 0.75rem;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* A wide scrubber is one row. The middle of each button is on the line of the axis. */
|
|
40
|
+
@container (min-width: 44rem) {
|
|
41
|
+
.visuals-scrubber-row {
|
|
42
|
+
grid-template-columns: auto var(--scrubber-time-width, 11rem) minmax(0, 1fr) auto;
|
|
43
|
+
grid-template-areas: "play time rule speed";
|
|
44
|
+
align-items: start;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.visuals-scrubber-time {
|
|
48
|
+
line-height: 2.5rem;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.visuals-scrubber-speed {
|
|
52
|
+
margin-top: 0.125rem;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.visuals-scrubber-play,
|
|
57
|
+
.visuals-scrubber-speed {
|
|
58
|
+
min-height: 0;
|
|
59
|
+
margin: 0;
|
|
60
|
+
background: none;
|
|
61
|
+
color: inherit;
|
|
62
|
+
font: inherit;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.visuals-scrubber-play {
|
|
67
|
+
display: grid;
|
|
68
|
+
grid-area: play;
|
|
69
|
+
place-items: center;
|
|
70
|
+
width: 2.5rem;
|
|
71
|
+
height: 2.5rem;
|
|
72
|
+
padding: 0;
|
|
73
|
+
border: 1.5px solid var(--_ink);
|
|
74
|
+
border-radius: 50%;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.visuals-scrubber-sign {
|
|
78
|
+
display: block;
|
|
79
|
+
width: 1rem;
|
|
80
|
+
height: 1rem;
|
|
81
|
+
fill: var(--_ink);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.visuals-scrubber-speed {
|
|
85
|
+
grid-area: speed;
|
|
86
|
+
min-width: 3rem;
|
|
87
|
+
height: 2.25rem;
|
|
88
|
+
padding: 0 0.625rem;
|
|
89
|
+
border: 1px solid var(--_line);
|
|
90
|
+
border-radius: 1.125rem;
|
|
91
|
+
font-variant-numeric: tabular-nums;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.visuals-scrubber-play:hover:not(:disabled),
|
|
95
|
+
.visuals-scrubber-speed:hover:not(:disabled) {
|
|
96
|
+
background: color-mix(in srgb, currentColor 9%, transparent);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.visuals-scrubber-play:focus-visible,
|
|
100
|
+
.visuals-scrubber-speed:focus-visible {
|
|
101
|
+
outline: 2px solid var(--_focus);
|
|
102
|
+
outline-offset: 2px;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.visuals-scrubber-play:disabled,
|
|
106
|
+
.visuals-scrubber-speed:disabled {
|
|
107
|
+
opacity: 0.45;
|
|
108
|
+
cursor: default;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.visuals-scrubber-time {
|
|
112
|
+
grid-area: time;
|
|
113
|
+
min-width: 0;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
font-weight: 600;
|
|
116
|
+
font-variant-numeric: tabular-nums;
|
|
117
|
+
text-overflow: ellipsis;
|
|
118
|
+
white-space: nowrap;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
* The rule: the axis with its ticks, the handle and the labels. The slider of the browser is above them, and it is not visible.
|
|
123
|
+
* The middle of the handle of the slider goes from half of its width to the full width less that half.
|
|
124
|
+
* So the axis has that half as its space at each end, and a tick is exactly below the handle at its time.
|
|
125
|
+
*/
|
|
126
|
+
.visuals-scrubber-rule {
|
|
127
|
+
position: relative;
|
|
128
|
+
grid-area: rule;
|
|
129
|
+
height: 3rem;
|
|
130
|
+
padding-inline: calc(var(--_thumb) / 2);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.visuals-scrubber-ticks {
|
|
134
|
+
display: block;
|
|
135
|
+
width: 100%;
|
|
136
|
+
height: 1.75rem;
|
|
137
|
+
overflow: visible;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.visuals-scrubber-ticks path {
|
|
141
|
+
fill: none;
|
|
142
|
+
vector-effect: non-scaling-stroke;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.visuals-scrubber-ahead {
|
|
146
|
+
stroke: var(--_line);
|
|
147
|
+
stroke-width: 1.5px;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.visuals-scrubber-steps {
|
|
151
|
+
stroke: var(--_quiet);
|
|
152
|
+
stroke-width: 1px;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* The picture of the time that passed has the same lines as the picture below it. It ends at the time of the handle. */
|
|
156
|
+
.visuals-scrubber-passed {
|
|
157
|
+
position: absolute;
|
|
158
|
+
top: 0;
|
|
159
|
+
left: calc(var(--_thumb) / 2);
|
|
160
|
+
width: calc(100% - var(--_thumb));
|
|
161
|
+
clip-path: inset(-0.25rem calc((1 - var(--scrubber-part)) * 100%) -0.25rem -0.25rem);
|
|
162
|
+
pointer-events: none;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.visuals-scrubber-past {
|
|
166
|
+
stroke: var(--_ink);
|
|
167
|
+
stroke-width: 1.5px;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.visuals-scrubber-range {
|
|
171
|
+
position: absolute;
|
|
172
|
+
inset: 0;
|
|
173
|
+
width: 100%;
|
|
174
|
+
height: 100%;
|
|
175
|
+
margin: 0;
|
|
176
|
+
padding: 0;
|
|
177
|
+
border: 0;
|
|
178
|
+
background: none;
|
|
179
|
+
opacity: 0;
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
touch-action: pan-y;
|
|
182
|
+
-webkit-appearance: none;
|
|
183
|
+
appearance: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.visuals-scrubber-range:disabled {
|
|
187
|
+
cursor: default;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.visuals-scrubber-range::-webkit-slider-thumb {
|
|
191
|
+
width: var(--_thumb);
|
|
192
|
+
height: 3rem;
|
|
193
|
+
-webkit-appearance: none;
|
|
194
|
+
appearance: none;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.visuals-scrubber-range::-moz-range-thumb {
|
|
198
|
+
width: var(--_thumb);
|
|
199
|
+
height: 3rem;
|
|
200
|
+
border: 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* The handle: a thin line through the ticks, and a ring on the line of the axis. */
|
|
204
|
+
.visuals-scrubber-head {
|
|
205
|
+
position: absolute;
|
|
206
|
+
top: 0;
|
|
207
|
+
left: calc(var(--_thumb) / 2 + var(--scrubber-part) * (100% - var(--_thumb)));
|
|
208
|
+
width: 0;
|
|
209
|
+
height: 1.25rem;
|
|
210
|
+
pointer-events: none;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.visuals-scrubber-head::before {
|
|
214
|
+
position: absolute;
|
|
215
|
+
top: 0.125rem;
|
|
216
|
+
bottom: 0;
|
|
217
|
+
left: -0.75px;
|
|
218
|
+
border-left: 1.5px solid var(--_ink);
|
|
219
|
+
content: "";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.visuals-scrubber-head::after {
|
|
223
|
+
position: absolute;
|
|
224
|
+
top: 100%;
|
|
225
|
+
left: 0;
|
|
226
|
+
width: 0.875rem;
|
|
227
|
+
height: 0.875rem;
|
|
228
|
+
border: 2px solid var(--_ink);
|
|
229
|
+
border-radius: 50%;
|
|
230
|
+
background: var(--_surface);
|
|
231
|
+
content: "";
|
|
232
|
+
translate: -50% -50%;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.visuals-scrubber-range:hover:not(:disabled) + .visuals-scrubber-head::after {
|
|
236
|
+
width: 1rem;
|
|
237
|
+
height: 1rem;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.visuals-scrubber-range:active:not(:disabled) + .visuals-scrubber-head::after {
|
|
241
|
+
background: var(--_ink);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.visuals-scrubber-range:focus-visible + .visuals-scrubber-head::after {
|
|
245
|
+
outline: 2px solid var(--_focus);
|
|
246
|
+
outline-offset: 2px;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.visuals-scrubber-range:disabled + .visuals-scrubber-head {
|
|
250
|
+
opacity: 0.45;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.visuals-scrubber-labels {
|
|
254
|
+
position: relative;
|
|
255
|
+
height: 1.25rem;
|
|
256
|
+
color: var(--_quiet);
|
|
257
|
+
font-size: 0.8125rem;
|
|
258
|
+
line-height: 1.25rem;
|
|
259
|
+
white-space: nowrap;
|
|
260
|
+
pointer-events: none;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.visuals-scrubber-label {
|
|
264
|
+
position: absolute;
|
|
265
|
+
top: 0;
|
|
266
|
+
left: calc(var(--scrubber-at) * 100%);
|
|
267
|
+
translate: -50% 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.visuals-scrubber-label[data-align="start"] {
|
|
271
|
+
translate: 0 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.visuals-scrubber-label[data-align="end"] {
|
|
275
|
+
translate: -100% 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* With the colors of the system, a background has no color. The ring of the handle keeps its inner part. */
|
|
279
|
+
@media (forced-colors: active) {
|
|
280
|
+
.visuals-scrubber-head::after {
|
|
281
|
+
forced-color-adjust: none;
|
|
282
|
+
border-color: CanvasText;
|
|
283
|
+
background: Canvas;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.visuals-scrubber-range:active:not(:disabled) + .visuals-scrubber-head::after {
|
|
287
|
+
background: CanvasText;
|
|
288
|
+
}
|
|
289
|
+
}
|