@mark1russell7/visuals 0.1.1 → 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.
@@ -0,0 +1,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,QAAQ,KAAK,QAAQ,QAAQ,KAAK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,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"}
@@ -1,8 +1,8 @@
1
- import { b as Place, d as StageView, l as StageExtent, r as Mark, t as StageTheme } from "./theme-CJ2SAcHX.js";
1
+ import { b as Place, d as StageView, l as StageExtent, r as Highlight, t as StageTheme } from "./theme-CKXd_emk.js";
2
2
  import { Object3D, PerspectiveCamera, Raycaster } from "three";
3
3
  /** The record under the pointer: its name, and the value that the content gives for it. */
4
4
  interface StagePick<P> {
5
- /** The name of the record. The marks of the stage use this name. */
5
+ /** The name of the record. The highlights of the stage use this name. */
6
6
  readonly record: string;
7
7
  /** The value of the record for the page, for example its kind and its source. */
8
8
  readonly value: P;
@@ -35,8 +35,8 @@ interface StageContent<P, T extends StageTheme = StageTheme> {
35
35
  has(record: string): boolean;
36
36
  /** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */
37
37
  pick(ray: Raycaster): StagePick<P> | undefined;
38
- /** This function gives each part its colors, from the theme and the mark of its record. */
39
- paint(theme: T, mark: (record: string) => Mark): void;
38
+ /** This function gives each part its colors, from the theme and the highlight of its record. */
39
+ paint(theme: T, highlight: (record: string) => Highlight): void;
40
40
  /**
41
41
  * This function changes the parts that depend on the camera or on the time, before each picture.
42
42
  * It gives true while a part continues to change. The stage then makes the next picture.
@@ -98,7 +98,7 @@ interface Stage<P, T extends StageTheme = StageTheme> {
98
98
  setView(view: string | StageView, animate?: boolean): void;
99
99
  /** This function gives the place of the camera. */
100
100
  place(): Place;
101
- /** This function marks records by their names, as the pointer does. An empty list removes the marks. */
101
+ /** This function highlights records by their names, as the pointer does. An empty list removes the highlights. */
102
102
  highlight(records: readonly string[]): void;
103
103
  /** This function selects one record by its name, or no record. It does not start `onSelect`. */
104
104
  select(record: string | undefined): void;
@@ -123,4 +123,4 @@ declare const STAGE_LIGHTS: StageLights;
123
123
  */
124
124
  declare function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined;
125
125
  export { StageFrame as a, StagePick as c, StageContent as i, createStage as l, STAGE_LIGHTS as n, StageLights as o, Stage as r, StageOptions as s, FIELD_OF_VIEW as t };
126
- //# sourceMappingURL=stage-C9NHD-6Q.d.ts.map
126
+ //# sourceMappingURL=stage-CtWLSoV-.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stage-C9NHD-6Q.d.ts","names":[],"sources":["../src/stage/stage.ts"],"mappings":";;;UAUiB,UAAU;;WAEhB;;WAEA,OAAO;;;UAID;WACN,QAAQ;;WAER;;;;;WAKA;;WAEA;;WAEA;;;;;;UAOM,aAAa,GAAG,UAAU,aAAa;;WAE7C,kBAAkB;;WAElB,QAAQ;;EAEjB,IAAI;;EAEJ,KAAK,KAAK,YAAY,UAAU;;EAEhC,MAAM,OAAO,GAAG,OAAO,mBAAmB;;;;;EAK1C,MAAM,OAAO;;EAEb;;;UAIe;;WAEN;;WAEA;;WAEA;aAAiB;aAAoB;aAAoB;;;;UAInD,aAAa,GAAG,UAAU,aAAa;;WAE7C,SAAS,aAAa,GAAG;WACzB,OAAO;;WAEP;;WAEA,OAAO,SAAS,eAAe;;WAE/B;;WAEA,OAAO,SAAS;;WAEhB;;WAEA;aAAmB;aAAmC;;;WAEtD;WACA,SAAS;;WAET,YAAY,MAAM;;WAElB,aAAa,MAAM;;;UAIb,MAAM,GAAG,UAAU,aAAa;;WAEtC,QAAQ;;EAEjB,WAAW,SAAS,aAAa,GAAG;;EAEpC,SAAS,OAAO;;EAEhB,QAAQ,eAAe,WAAW;;EAElC,SAAS;;EAET,UAAU;;EAEV,OAAO;;EAEP;;EAEA;;;cAIW;;cAGA,cAAc;;;;;;;;;;;iBA6BX,YAAY,GAAG,UAAU,aAAa,YAAY,WAAW,aAAa,SAAS,aAAa,GAAG,KAAK,MAAM,GAAG"}
1
+ {"version":3,"file":"stage-CtWLSoV-.d.ts","names":[],"sources":["../src/stage/stage.ts"],"mappings":";;;UAUiB,UAAU;;WAEhB;;WAEA,OAAO;;;UAID;WACN,QAAQ;;WAER;;;;;WAKA;;WAEA;;WAEA;;;;;;UAOM,aAAa,GAAG,UAAU,aAAa;;WAE7C,kBAAkB;;WAElB,QAAQ;;EAEjB,IAAI;;EAEJ,KAAK,KAAK,YAAY,UAAU;;EAEhC,MAAM,OAAO,GAAG,YAAY,mBAAmB;;;;;EAK/C,MAAM,OAAO;;EAEb;;;UAIe;;WAEN;;WAEA;;WAEA;aAAiB;aAAoB;aAAoB;;;;UAInD,aAAa,GAAG,UAAU,aAAa;;WAE7C,SAAS,aAAa,GAAG;WACzB,OAAO;;WAEP;;WAEA,OAAO,SAAS,eAAe;;WAE/B;;WAEA,OAAO,SAAS;;WAEhB;;WAEA;aAAmB;aAAmC;;;WAEtD;WACA,SAAS;;WAET,YAAY,MAAM;;WAElB,aAAa,MAAM;;;UAIb,MAAM,GAAG,UAAU,aAAa;;WAEtC,QAAQ;;EAEjB,WAAW,SAAS,aAAa,GAAG;;EAEpC,SAAS,OAAO;;EAEhB,QAAQ,eAAe,WAAW;;EAElC,SAAS;;EAET,UAAU;;EAEV,OAAO;;EAEP;;EAEA;;;cAIW;;cAGA,cAAc;;;;;;;;;;;iBA6BX,YAAY,GAAG,UAAU,aAAa,YAAY,WAAW,aAAa,SAAS,aAAa,GAAG,KAAK,MAAM,GAAG"}
@@ -151,21 +151,21 @@ declare function stageLimits(frame: ViewFrame, views: readonly StageView[], pola
151
151
  readonly min: number;
152
152
  readonly max: number;
153
153
  }): StageLimits;
154
- /** The mark of a record. 0 is no mark. 1 is a record under the pointer or in the marked list. 2 is the selected record. */
155
- type Mark = 0 | 1 | 2;
156
- /** The records of a stage that have a mark. Each record has a name. */
157
- interface Marks {
154
+ /** The highlight of a record. 0 is no highlight. 1 is a record under the pointer or in the highlighted list. 2 is the selected record. */
155
+ type Highlight = 0 | 1 | 2;
156
+ /** The records of a stage that have a highlight. Each record has a name. */
157
+ interface Highlights {
158
158
  /** The name of the record under the pointer. */
159
159
  readonly hovered: string | undefined;
160
160
  /** The name of the selected record. */
161
161
  readonly selected: string | undefined;
162
- /** The names of the records that the page marks. */
163
- readonly marked: ReadonlySet<string>;
162
+ /** The names of the records that the page highlights. */
163
+ readonly highlighted: ReadonlySet<string>;
164
164
  }
165
- /** The marks of a stage with no pointer on it and no selected record. */
166
- declare const NO_MARKS: Marks;
167
- /** This function gives the mark of a record. The selected record has the highest mark. */
168
- declare function markOf(marks: Marks, record: string): Mark;
165
+ /** The highlights of a stage with no pointer on it and no selected record. */
166
+ declare const NO_HIGHLIGHTS: Highlights;
167
+ /** This function gives the highlight of a record. The selected record has the highest highlight. */
168
+ declare function highlightOf(highlights: Highlights, record: string): Highlight;
169
169
  /** A pointer that moves this distance or less between down and up makes a click, in CSS pixels. */
170
170
  declare const CLICK_DISTANCE = 4;
171
171
  /**
@@ -189,5 +189,5 @@ interface StageTheme {
189
189
  /** The color of the light from below. */
190
190
  readonly ground: string;
191
191
  }
192
- export { turnBetween as A, ViewAxes as C, fitDistance as D, clampPlace as E, viewOf as M, placeBetween as O, ViewAngles as S, capDistance as T, reachOf as _, NO_MARKS as a, Place as b, FIT_MARGIN as c, StageView as d, ViewFrame as f, nearDepth as g, fitView as h, Marks as i, viewAxes as j, speedAt as k, StageExtent as l, capView as m, CLICK_DISTANCE as n, isClick as o, ballView as p, Mark as r, markOf as s, StageTheme as t, StageLimits as u, stageLimits as v, cameraPosition as w, PlaceLimits as x, surfaceOf as y };
193
- //# sourceMappingURL=theme-CJ2SAcHX.d.ts.map
192
+ export { turnBetween as A, ViewAxes as C, fitDistance as D, clampPlace as E, viewOf as M, placeBetween as O, ViewAngles as S, capDistance as T, reachOf as _, NO_HIGHLIGHTS as a, Place as b, FIT_MARGIN as c, StageView as d, ViewFrame as f, nearDepth as g, fitView as h, Highlights as i, viewAxes as j, speedAt as k, StageExtent as l, capView as m, CLICK_DISTANCE as n, highlightOf as o, ballView as p, Highlight as r, isClick as s, StageTheme as t, StageLimits as u, stageLimits as v, cameraPosition as w, PlaceLimits as x, surfaceOf as y };
193
+ //# sourceMappingURL=theme-CKXd_emk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-CKXd_emk.d.ts","names":[],"sources":["../src/view.ts","../src/extent.ts","../src/highlight.ts","../src/theme.ts"],"mappings":";;;;;UAMiB;;WAEN;;WAEA;;;UAIM,cAAc;WACpB,QAAQ;WACR;;;UAIM;;WAEN,MAAM;;WAEN,OAAO;;WAEP,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;WAEA;;;iBAIK,SAAS,MAAM,aAAa;;;;;;;;iBAwB5B,YAAY,iBAAiB,UAAU,QAAQ,QAAQ,MAAM,YAAY,aAAa;;;;;;;;;iBAsBtF,YAAY,gBAAgB,eAAe,aAAa;;iBAaxD,eAAe,QAAQ,QAAQ,MAAM,YAAY,mBAAmB;;iBAMpE,OAAO,QAAQ,QAAQ,QAAQ,SAAS;WAAwB;;;iBAUhE,YAAY,cAAc;;iBAO1B,WAAW,OAAO,OAAO,QAAQ,cAAc;;;;;;;;iBAgB/C,QAAQ,kBAAkB;;;;;;;iBAW1B,aAAa,MAAM,OAAO,IAAI,OAAO,cAAc,mBAAsB;;UCnJxE;;WAEN,kBAAkB;;WAElB,QAAQ;;;;;WAKR;;WAEA;;WAEA;;;UAIM;WACN,QAAQ;;WAER;;WAEA;;;KAIC,aAAa,OAAO,cAAc;;UAG7B,oBAAoB;WAC1B;WACA;;;cAIE;;iBAGG,UAAU,QAAQ;;;;;iBASlB,QAAQ,QAAQ,YAAY,kBAA8B;;;;;;;iBAa1D,QAAQ,QAAQ,YAAY,eAAe,kBAA8B;;;;;;;iBAczE,SAAS,iBAAiB,UAAU,kBAA8B;;iBA0ClE,QAAQ,QAAQ;;;;;;;iBAYhB,UAAU,QAAQ,aAAa,QAAQ,aAAa;;;;;;;iBAWpD,YAAY,OAAO,WAAW,gBAAgB,aAAa;WAAkB;WAAsB;IAAgB;;KC9IvH;;UAGK;;WAEN;;WAEA;;WAEA,aAAa;;;cAIX,eAAe;;iBAGZ,YAAY,YAAY,YAAY,iBAAiB;;cAMxD;;;;;iBAMG,QAAQ;WAAiB;WAAoB;GAAa;WAAe;WAAoB;GAAa;;;;;UCzBzG;;WAEN;;WAEA"}
package/build/three.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as StageFrame, c as StagePick, i as StageContent, l as createStage, n as STAGE_LIGHTS, o as StageLights, r as Stage, s as StageOptions, t as FIELD_OF_VIEW } from "./stage-C9NHD-6Q.js";
1
+ import { a as StageFrame, c as StagePick, i as StageContent, l as createStage, n as STAGE_LIGHTS, o as StageLights, r as Stage, s as StageOptions, t as FIELD_OF_VIEW } from "./stage-CtWLSoV-.js";
2
2
  export { FIELD_OF_VIEW, STAGE_LIGHTS, type Stage, type StageContent, type StageFrame, type StageLights, type StageOptions, type StagePick, createStage };
package/build/three.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as viewOf, a as nearDepth, c as surfaceOf, d as clampPlace, l as cameraPosition, m as speedAt, s as stageLimits } from "./extent-CALhBZU-.js";
2
- import { a as NO_MARKS, o as isClick, r as moveAt, s as markOf, u as keyAction } from "./motion-BwDDtx3D.js";
2
+ import { a as NO_HIGHLIGHTS, o as highlightOf, r as moveAt, s as isClick, u as keyAction } from "./motion-0tsT6sY4.js";
3
3
  import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene, Vector2, WebGLRenderer } from "three";
4
4
  import { OrbitControls } from "three/addons/controls/OrbitControls.js";
5
5
  // src/stage/stage.ts
@@ -84,7 +84,7 @@ function createStage(container, options) {
84
84
  let content = options.content;
85
85
  let theme = options.theme;
86
86
  for (const object of content.objects) world.add(object);
87
- let marks = NO_MARKS;
87
+ let highlights = NO_HIGHLIGHTS;
88
88
  let view = options.home;
89
89
  let move;
90
90
  /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */
@@ -115,8 +115,8 @@ function createStage(container, options) {
115
115
  });
116
116
  let limits = stageLimits(viewFrame(), Object.values(options.views), polar);
117
117
  const paint = () => {
118
- const now = marks;
119
- content.paint(theme, (record) => markOf(now, record));
118
+ const now = highlights;
119
+ content.paint(theme, (record) => highlightOf(now, record));
120
120
  invalidate();
121
121
  };
122
122
  /** This function sets the turn speed and the zoom speed from the height of the camera above the surface. */
@@ -250,9 +250,9 @@ function createStage(container, options) {
250
250
  };
251
251
  const setHover = (pick) => {
252
252
  const record = pick?.record;
253
- if (record === marks.hovered) return;
254
- marks = {
255
- ...marks,
253
+ if (record === highlights.hovered) return;
254
+ highlights = {
255
+ ...highlights,
256
256
  hovered: record
257
257
  };
258
258
  canvas.style.cursor = record === void 0 ? "grab" : "pointer";
@@ -286,8 +286,8 @@ function createStage(container, options) {
286
286
  y: event.clientY
287
287
  })) return;
288
288
  const pick = pickAt(event);
289
- marks = {
290
- ...marks,
289
+ highlights = {
290
+ ...highlights,
291
291
  selected: pick?.record
292
292
  };
293
293
  paint();
@@ -330,7 +330,7 @@ function createStage(container, options) {
330
330
  invalidate();
331
331
  });
332
332
  controls.addEventListener("end", () => {
333
- canvas.style.cursor = marks.hovered === void 0 ? "grab" : "pointer";
333
+ canvas.style.cursor = highlights.hovered === void 0 ? "grab" : "pointer";
334
334
  });
335
335
  controls.addEventListener("change", invalidate);
336
336
  const applyTheme = () => {
@@ -357,9 +357,9 @@ function createStage(container, options) {
357
357
  content.dispose();
358
358
  content = next;
359
359
  for (const object of content.objects) world.add(object);
360
- const selected = marks.selected !== void 0 && content.has(marks.selected) ? marks.selected : void 0;
361
- marks = {
362
- ...marks,
360
+ const selected = highlights.selected !== void 0 && content.has(highlights.selected) ? highlights.selected : void 0;
361
+ highlights = {
362
+ ...highlights,
363
363
  hovered: void 0,
364
364
  selected
365
365
  };
@@ -377,15 +377,15 @@ function createStage(container, options) {
377
377
  },
378
378
  place: placeNow,
379
379
  highlight(records) {
380
- marks = {
381
- ...marks,
382
- marked: new Set(records)
380
+ highlights = {
381
+ ...highlights,
382
+ highlighted: new Set(records)
383
383
  };
384
384
  paint();
385
385
  },
386
386
  select(record) {
387
- marks = {
388
- ...marks,
387
+ highlights = {
388
+ ...highlights,
389
389
  selected: record
390
390
  };
391
391
  paint();