partforge 0.46.4 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/AUTHORING-PARTS.md +12 -4
- package/package.json +1 -1
- package/src/framework/animation-controls.js +265 -48
- package/src/framework/app.css +38 -7
package/docs/AUTHORING-PARTS.md
CHANGED
|
@@ -132,9 +132,17 @@ export default {
|
|
|
132
132
|
## Animations
|
|
133
133
|
|
|
134
134
|
A part may declare named animations — pure keyframe data that drives **existing
|
|
135
|
-
params** over time. The viewer shows a transport bar (play/scrub
|
|
136
|
-
drive the same engine via
|
|
137
|
-
stills at any position. The
|
|
135
|
+
params** over time. The viewer shows a transport bar (play/scrub, with ‹ ›
|
|
136
|
+
pagers between animations); hosts drive the same engine via
|
|
137
|
+
`runtime.animation`; `partforge render` can render stills at any position. The
|
|
138
|
+
reference part is `src/parts/hinged-box.js`.
|
|
139
|
+
|
|
140
|
+
Step labels surface on the scrubber rather than in a readout: hovering or
|
|
141
|
+
dragging along the timeline names the chapter under the pointer, and with the
|
|
142
|
+
scrubber focused **PageUp / PageDown jump whole chapters** (PageUp forward,
|
|
143
|
+
matching the key's native slider direction). Screen readers get the same
|
|
144
|
+
information from the scrubber's `aria-valuetext`, which reads
|
|
145
|
+
`"<step label> — <percent>"`.
|
|
138
146
|
|
|
139
147
|
```js
|
|
140
148
|
animations: {
|
|
@@ -149,7 +157,7 @@ animations: {
|
|
|
149
157
|
},
|
|
150
158
|
assemble: {
|
|
151
159
|
label: "Assemble",
|
|
152
|
-
steps: [ // steps play in order;
|
|
160
|
+
steps: [ // steps play in order; named on the scrubber as you hover/drag
|
|
153
161
|
{ label: "Lower the lid", camera: "left", duration: 1.0,
|
|
154
162
|
tracks: { lidLift: [[0, 40], [1, 0]] } },
|
|
155
163
|
{ label: "Open", camera: "iso", duration: 1.0,
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// through the mount-supplied applyValues hook — the same path as a slider
|
|
6
6
|
// edit, minus the regen debounce. Returns null when the part declares no
|
|
7
7
|
// (valid) animations, so mount can wire it unconditionally.
|
|
8
|
-
import { normalizeAnimations, createPlayback } from "./animation.js";
|
|
8
|
+
import { normalizeAnimations, createPlayback, stepIndexAt } from "./animation.js";
|
|
9
9
|
import { createInfoPopover, attachInfo } from "./controls.js";
|
|
10
10
|
|
|
11
11
|
function el(tag, className, text) {
|
|
@@ -14,11 +14,14 @@ function el(tag, className, text) {
|
|
|
14
14
|
if (text != null) node.textContent = text;
|
|
15
15
|
return node;
|
|
16
16
|
}
|
|
17
|
+
function setBtnLabel(b, label) {
|
|
18
|
+
b.setAttribute("aria-label", label);
|
|
19
|
+
b.title = label;
|
|
20
|
+
}
|
|
17
21
|
function btn(className, text, label) {
|
|
18
22
|
const b = el("button", className, text);
|
|
19
23
|
b.type = "button";
|
|
20
|
-
b
|
|
21
|
-
b.title = label;
|
|
24
|
+
setBtnLabel(b, label);
|
|
22
25
|
return b;
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -36,6 +39,41 @@ export function planAnimBarPlacement({ stageWidth, barWidth, viewbarLeft }, { ga
|
|
|
36
39
|
return barWidth > available ? { left, maxWidth: available } : { left };
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// The scrubber's resolution: `t` is reported to the user as one of this many
|
|
43
|
+
// steps, and read back the same way.
|
|
44
|
+
export const SCRUB_STEPS = 1000;
|
|
45
|
+
|
|
46
|
+
// Snap a seek target UP onto the scrubber's grid.
|
|
47
|
+
//
|
|
48
|
+
// syncUi rounds `t` onto that grid to position the thumb, but a chapter
|
|
49
|
+
// boundary rarely lands on it: with three equal chapters, 1/3 rounds DOWN to
|
|
50
|
+
// 0.333 — which is in the chapter BEFORE the one the playhead is really in. The
|
|
51
|
+
// bar then reports a chapter it is not at, and the next arrow-key nudge reads
|
|
52
|
+
// the rounded value back and "moves" the user a chapter without the position
|
|
53
|
+
// changing. Rounding up keeps the grid value on the same side of the boundary
|
|
54
|
+
// as `t`, so the playhead and what the scrubber shows always agree.
|
|
55
|
+
//
|
|
56
|
+
// A chapter shorter than one step can't be represented at all; nothing here can
|
|
57
|
+
// fix that, and lint's minimum step duration keeps it out of reach.
|
|
58
|
+
export function snapUpToScrubGrid(t) {
|
|
59
|
+
const stepped = Math.ceil(t * SCRUB_STEPS - 1e-9) / SCRUB_STEPS;
|
|
60
|
+
return Math.min(1, Math.max(0, stepped));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// "Close enough to a chapter's start to count as being ON it." One scrubber
|
|
64
|
+
// step, for the same reason: finer than the grid is finer than anything the
|
|
65
|
+
// user can see or land on.
|
|
66
|
+
const AT_BOUNDARY = 1 / SCRUB_STEPS;
|
|
67
|
+
|
|
68
|
+
// Center-x for the chapter bubble, in px within the scrub wrap: the bubble
|
|
69
|
+
// tracks `fraction` along the timeline but never hangs past either end. A
|
|
70
|
+
// wrap narrower than the bubble has no legal band — park it in the middle.
|
|
71
|
+
export function clampBubbleX(fraction, wrapWidth, bubbleWidth) {
|
|
72
|
+
if (wrapWidth <= bubbleWidth) return wrapWidth / 2;
|
|
73
|
+
const half = bubbleWidth / 2;
|
|
74
|
+
return Math.min(Math.max(fraction * wrapWidth, half), wrapWidth - half);
|
|
75
|
+
}
|
|
76
|
+
|
|
39
77
|
// A setter for an element's text that MUTATES its existing text node instead of
|
|
40
78
|
// replacing it. `el.textContent = x` always replaces the node, and WebKit will
|
|
41
79
|
// not dispatch a `click` on an element whose text node was replaced between
|
|
@@ -90,30 +128,133 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
90
128
|
pick.append(o);
|
|
91
129
|
}
|
|
92
130
|
const title = el("span", "pf-anim-title", "");
|
|
93
|
-
|
|
131
|
+
// Multi-animation parts page with ‹ › at the card's outer edges — whole
|
|
132
|
+
// animations only, never chapters (chapters are the bubble + PageUp/Down).
|
|
133
|
+
const paged = animations.length > 1;
|
|
134
|
+
const prevAnimBtn = paged ? btn("pf-anim-page", "‹", "Previous animation") : null;
|
|
135
|
+
const nextAnimBtn = paged ? btn("pf-anim-page", "›", "Next animation") : null;
|
|
136
|
+
if (prevAnimBtn) bar.append(prevAnimBtn);
|
|
137
|
+
bar.append(paged ? pick : title);
|
|
94
138
|
const infoSlot = el("span", "pf-anim-info");
|
|
95
139
|
const playBtn = btn("pf-anim-play", "▶", "Play animation");
|
|
96
|
-
const prevBtn = btn("pf-anim-step-btn", "‹", "Previous step");
|
|
97
|
-
const stepLabel = el("span", "pf-anim-step", "");
|
|
98
|
-
const nextBtn = btn("pf-anim-step-btn", "›", "Next step");
|
|
99
140
|
const scrubWrap = el("span", "pf-anim-scrub-wrap");
|
|
100
141
|
const scrub = document.createElement("input");
|
|
101
142
|
scrub.type = "range";
|
|
102
|
-
scrub.min = "0"; scrub.max =
|
|
143
|
+
scrub.min = "0"; scrub.max = String(SCRUB_STEPS); scrub.step = "1"; scrub.value = "0";
|
|
103
144
|
scrub.className = "pf-anim-scrub";
|
|
104
145
|
scrub.setAttribute("aria-label", "Animation position");
|
|
105
146
|
scrubWrap.append(scrub);
|
|
106
147
|
const resetBtn = btn("pf-anim-reset", "↺", "Reset animation");
|
|
107
|
-
bar.append(infoSlot, playBtn,
|
|
148
|
+
bar.append(infoSlot, playBtn, scrubWrap, resetBtn);
|
|
149
|
+
if (nextAnimBtn) bar.append(nextAnimBtn);
|
|
108
150
|
container.append(bar);
|
|
151
|
+
// Chapter bubble: floats above the scrubber naming the chapter under the
|
|
152
|
+
// pointer (hover) or playhead (scrub).
|
|
153
|
+
//
|
|
154
|
+
// It is a child of the STAGE, not of the bar, for the same reason the ⓘ
|
|
155
|
+
// popover is a child of document.body: when the bar runs out of room it caps
|
|
156
|
+
// its width and sets overflow:hidden (see applyPlacement), and anything
|
|
157
|
+
// inside it is clipped — the bubble sits above the bar's content box, so it
|
|
158
|
+
// was clipped away entirely in exactly the narrow layouts where a shrunken
|
|
159
|
+
// timeline needs its labels most. Living on the stage puts it out of that
|
|
160
|
+
// clip, and out of the placement ResizeObserver's subtree as well.
|
|
161
|
+
//
|
|
162
|
+
// Non-interactive and aria-hidden: the accessible chapter channel is the
|
|
163
|
+
// scrubber's aria-valuetext, not this flag.
|
|
164
|
+
const chapterBubble = el("span", "pf-anim-chapter");
|
|
165
|
+
chapterBubble.setAttribute("aria-hidden", "true");
|
|
166
|
+
container.append(chapterBubble);
|
|
109
167
|
|
|
110
|
-
//
|
|
168
|
+
// A reveal is either HOVER-owned or TRANSIENT. A hover reveal lives until the
|
|
169
|
+
// pointer leaves; a transient one (keyboard jump, scrub, touch) fades itself.
|
|
170
|
+
//
|
|
171
|
+
// `hoverInside` marks the pointer as the current owner, and while it is set a
|
|
172
|
+
// transient reveal deliberately arms no fade — a drag fires pointermove then
|
|
173
|
+
// an `input` on every step, so the transient timer would otherwise be the last
|
|
174
|
+
// one set and would blank the label under a finger that never left.
|
|
175
|
+
//
|
|
176
|
+
// Every path that hides the bubble clears the latch too, so it can never
|
|
177
|
+
// outlive the reveal it guards: an animation switch hides the bubble while the
|
|
178
|
+
// pointer sits still, and a gesture the browser steals for scrolling delivers
|
|
179
|
+
// pointercancel instead of pointerleave.
|
|
180
|
+
const BUBBLE_FADE_MS = 1000;
|
|
181
|
+
let bubbleFadeTimer = 0;
|
|
182
|
+
let hoverInside = false;
|
|
183
|
+
// The label's rendered width is re-measured only when the label itself
|
|
184
|
+
// changes: showChapterBubble runs on every pointermove, and offsetWidth
|
|
185
|
+
// forces a synchronous layout. Writing through textSetter keeps the text node
|
|
186
|
+
// stable per the WebKit rule above, rather than replacing it per move.
|
|
187
|
+
const setBubbleText = textSetter(chapterBubble);
|
|
188
|
+
let bubbleLabel = null;
|
|
189
|
+
let bubbleWidth = 0;
|
|
190
|
+
function showChapterBubble(fraction, { transient = false } = {}) {
|
|
191
|
+
if (current.steps.length <= 1) return;
|
|
192
|
+
const f = Math.min(1, Math.max(0, fraction));
|
|
193
|
+
const label = current.steps[stepIndexAt(current, f)].label;
|
|
194
|
+
if (label !== bubbleLabel) {
|
|
195
|
+
bubbleLabel = label;
|
|
196
|
+
setBubbleText(label);
|
|
197
|
+
bubbleWidth = chapterBubble.offsetWidth;
|
|
198
|
+
}
|
|
199
|
+
// Stage-relative, because the bubble lives on the stage rather than in the
|
|
200
|
+
// wrap: track the point along the timeline, then lift clear of the bar.
|
|
201
|
+
const wrapRect = scrubWrap.getBoundingClientRect();
|
|
202
|
+
const stageRect = container.getBoundingClientRect();
|
|
203
|
+
chapterBubble.style.left =
|
|
204
|
+
`${wrapRect.left - stageRect.left + clampBubbleX(f, wrapRect.width, bubbleWidth)}px`;
|
|
205
|
+
chapterBubble.style.bottom = `${stageRect.bottom - wrapRect.top + 8}px`;
|
|
206
|
+
chapterBubble.classList.add("pf-show");
|
|
207
|
+
clearTimeout(bubbleFadeTimer);
|
|
208
|
+
bubbleFadeTimer = 0;
|
|
209
|
+
if (transient && !hoverInside) bubbleFadeTimer = setTimeout(hideChapterBubble, BUBBLE_FADE_MS);
|
|
210
|
+
}
|
|
211
|
+
function fadeChapterBubble() {
|
|
212
|
+
if (!chapterBubble.classList.contains("pf-show")) return;
|
|
213
|
+
clearTimeout(bubbleFadeTimer);
|
|
214
|
+
bubbleFadeTimer = setTimeout(hideChapterBubble, BUBBLE_FADE_MS);
|
|
215
|
+
}
|
|
216
|
+
function hideChapterBubble() {
|
|
217
|
+
clearTimeout(bubbleFadeTimer);
|
|
218
|
+
bubbleFadeTimer = 0;
|
|
219
|
+
hoverInside = false;
|
|
220
|
+
chapterBubble.classList.remove("pf-show");
|
|
221
|
+
}
|
|
222
|
+
const onWrapPointerMove = (e) => {
|
|
223
|
+
if (current.steps.length <= 1) return; // no chapters: no bubble, and no layout read
|
|
224
|
+
const rect = scrubWrap.getBoundingClientRect();
|
|
225
|
+
if (!rect.width) return;
|
|
226
|
+
hoverInside = true;
|
|
227
|
+
showChapterBubble((e.clientX - rect.left) / rect.width);
|
|
228
|
+
};
|
|
229
|
+
// A touch pointer's leave arrives with the finger lift, so hiding outright
|
|
230
|
+
// would blank the label the tap just asked for — and touch has no hover to
|
|
231
|
+
// read it with afterwards. Let it fade like a keyboard reveal instead. A
|
|
232
|
+
// mouse leaving still hides at once: the pointer moving away IS the dismissal.
|
|
233
|
+
const onWrapPointerLeave = (e) => {
|
|
234
|
+
hoverInside = false;
|
|
235
|
+
if (e?.pointerType === "touch") fadeChapterBubble();
|
|
236
|
+
else hideChapterBubble();
|
|
237
|
+
};
|
|
238
|
+
scrubWrap.addEventListener("pointermove", onWrapPointerMove);
|
|
239
|
+
scrubWrap.addEventListener("pointerleave", onWrapPointerLeave);
|
|
240
|
+
scrubWrap.addEventListener("pointercancel", onWrapPointerLeave);
|
|
241
|
+
|
|
242
|
+
// Per-animation chrome: title, ⓘ description, pager labels, scrubber ticks.
|
|
111
243
|
function syncStructure() {
|
|
112
244
|
title.textContent = current.label;
|
|
245
|
+
hideChapterBubble();
|
|
246
|
+
if (paged) {
|
|
247
|
+
// Name the destination. Activating a pager keeps focus on it and leaves
|
|
248
|
+
// its glyph unchanged, so without this a screen reader re-announces the
|
|
249
|
+
// same generic "Next animation" and never says what is now selected.
|
|
250
|
+
const i = animations.indexOf(current);
|
|
251
|
+
const at = (d) => animations[(i + d + animations.length) % animations.length].label;
|
|
252
|
+
setBtnLabel(prevAnimBtn, `Previous animation: ${at(-1)}`);
|
|
253
|
+
setBtnLabel(nextAnimBtn, `Next animation: ${at(1)}`);
|
|
254
|
+
}
|
|
113
255
|
infoSlot.replaceChildren();
|
|
114
256
|
attachInfo(infoSlot, current.description ?? "", info);
|
|
115
257
|
const stepped = current.steps.length > 1;
|
|
116
|
-
prevBtn.hidden = nextBtn.hidden = stepLabel.hidden = !stepped;
|
|
117
258
|
for (const n of scrubWrap.querySelectorAll(".pf-anim-tick")) n.remove();
|
|
118
259
|
if (stepped) {
|
|
119
260
|
for (const t of current.stepStarts.slice(1)) {
|
|
@@ -130,12 +271,13 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
130
271
|
// 1. Text goes through textSetter (see above), so the button's text node is
|
|
131
272
|
// mutated and never replaced. This is the one that matters, because it
|
|
132
273
|
// holds even when the glyph legitimately changes under a held finger —
|
|
133
|
-
// playback ending
|
|
274
|
+
// playback ending mid-press.
|
|
134
275
|
// 2. Each element has its own renderer that leaves early when its own value
|
|
135
|
-
// is unchanged, so a playing transport
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
276
|
+
// is unchanged, so a playing transport touches only what actually moved:
|
|
277
|
+
// the scrubber's value, and aria-valuetext when it crosses a reporting
|
|
278
|
+
// step. Per ELEMENT, not per write: driving several elements off one
|
|
279
|
+
// shared state key means a step change also redraws the button, which was
|
|
280
|
+
// still enough to lose the click before rule 1 was in place.
|
|
139
281
|
//
|
|
140
282
|
// Without rule 1 this cost the pause click outright: press, release, no click
|
|
141
283
|
// event at all, and only ever while playing — the one moment the button is
|
|
@@ -143,9 +285,7 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
143
285
|
// ~100ms; a synthetic 0ms one survives, which is why automated clicking never
|
|
144
286
|
// saw it). Reset was never affected: nothing rewrites that button per frame.
|
|
145
287
|
const setPlayGlyph = textSetter(playBtn);
|
|
146
|
-
const setStepText = textSetter(stepLabel);
|
|
147
288
|
let shownActive = null;
|
|
148
|
-
let shownStep = null;
|
|
149
289
|
|
|
150
290
|
function renderPlayButton(active) {
|
|
151
291
|
if (active === shownActive) return;
|
|
@@ -156,26 +296,42 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
156
296
|
playBtn.title = label;
|
|
157
297
|
}
|
|
158
298
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
299
|
+
// aria-valuetext is the accessible chapter channel — the bubble is aria-hidden,
|
|
300
|
+
// so this is the only place the chapter name reaches assistive tech. An
|
|
301
|
+
// attribute write never eats clicks (see the WebKit note above), but a screen
|
|
302
|
+
// reader announces every CHANGE, and during playback the position moves on its
|
|
303
|
+
// own: an exact percentage would chatter ~100 times a run with the scrubber
|
|
304
|
+
// focused. So while playing the percentage is reported in 10% steps. A
|
|
305
|
+
// user-driven seek reports the exact position, which is when precision is the
|
|
306
|
+
// feedback the user asked for.
|
|
307
|
+
let shownValuetext = null;
|
|
308
|
+
function renderValuetext(t, stepIndex, playing) {
|
|
309
|
+
const pct = Math.round(t * 100);
|
|
310
|
+
const shown = playing ? Math.round(pct / 10) * 10 : pct;
|
|
311
|
+
const text = current.steps.length > 1
|
|
312
|
+
? `${current.steps[stepIndex].label} — ${shown}%`
|
|
313
|
+
: `${shown}%`;
|
|
314
|
+
if (text === shownValuetext) return;
|
|
315
|
+
shownValuetext = text;
|
|
316
|
+
scrub.setAttribute("aria-valuetext", text);
|
|
164
317
|
}
|
|
165
318
|
|
|
166
319
|
function syncUi() {
|
|
167
320
|
const { status, t, stepIndex } = playback.state();
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
renderPlayButton(status === "playing" || status === "intro");
|
|
173
|
-
renderStepLabel(stepIndex);
|
|
321
|
+
const playing = status === "playing" || status === "intro";
|
|
322
|
+
scrub.value = String(Math.round(t * SCRUB_STEPS));
|
|
323
|
+
renderPlayButton(playing);
|
|
324
|
+
renderValuetext(t, stepIndex, playing);
|
|
174
325
|
}
|
|
175
326
|
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
327
|
+
// Belt-and-braces for the animation swap. Both caches above key on the exact
|
|
328
|
+
// value written to the DOM, so today a stale one can only ever agree with what
|
|
329
|
+
// is already on screen — this reset is currently redundant, and no test can
|
|
330
|
+
// pin it. It is kept because the cache it replaced (the old step readout) keyed
|
|
331
|
+
// on a step INDEX, which genuinely collided across animations at index 0: any
|
|
332
|
+
// future renderer keyed on a proxy rather than on its rendered value needs
|
|
333
|
+
// this hook to already exist.
|
|
334
|
+
function invalidateUi() { shownActive = null; shownValuetext = null; }
|
|
179
335
|
|
|
180
336
|
// --- driver -----------------------------------------------------------------
|
|
181
337
|
// A frame that throws — a malformed cue or track that slipped past lint, a
|
|
@@ -234,8 +390,7 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
234
390
|
playback = createPlayback(current);
|
|
235
391
|
if (animations.length > 1) pick.value = name;
|
|
236
392
|
syncStructure();
|
|
237
|
-
invalidateUi();
|
|
238
|
-
// outgoing one may have been showing, but for another animation
|
|
393
|
+
invalidateUi();
|
|
239
394
|
syncUi();
|
|
240
395
|
}
|
|
241
396
|
|
|
@@ -259,15 +414,61 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
259
414
|
guarded(() => playback.play());
|
|
260
415
|
}
|
|
261
416
|
};
|
|
262
|
-
const onScrub = () => {
|
|
263
|
-
|
|
264
|
-
|
|
417
|
+
const onScrub = () => {
|
|
418
|
+
disarmAutoplay();
|
|
419
|
+
const f = Number(scrub.value) / SCRUB_STEPS;
|
|
420
|
+
showChapterBubble(f, { transient: true });
|
|
421
|
+
guarded(() => playback.seek(f));
|
|
422
|
+
};
|
|
423
|
+
// PageUp/PageDown jump whole chapters — the keyboard replacement for the
|
|
424
|
+
// removed step buttons. PageUp goes FORWARD, matching the key's native
|
|
425
|
+
// slider direction (it increases the value). Single-step animations keep
|
|
426
|
+
// the browser's native coarse seek instead.
|
|
427
|
+
//
|
|
428
|
+
// Targets are derived from the chapter the playhead is IN rather than by
|
|
429
|
+
// scanning stepStarts for the nearest boundary — same answers (verified
|
|
430
|
+
// equivalent across the whole 0..1 range), but it reads as the rule it
|
|
431
|
+
// implements and allocates nothing per keypress.
|
|
432
|
+
//
|
|
433
|
+
// AT_BOUNDARY decides "am I at this chapter's start or inside it", which is
|
|
434
|
+
// what makes PageDown step back rather than restart. It is one scrubber step
|
|
435
|
+
// because that is the finest position the user can see or reach: a tolerance
|
|
436
|
+
// finer than the grid would call a playhead that just landed on a boundary
|
|
437
|
+
// "inside" the chapter, and PageDown would restart it forever instead of
|
|
438
|
+
// walking back.
|
|
439
|
+
const onScrubKeydown = (e) => {
|
|
440
|
+
if (current.steps.length <= 1) return;
|
|
441
|
+
if (e.key !== "PageUp" && e.key !== "PageDown") return;
|
|
442
|
+
e.preventDefault();
|
|
443
|
+
disarmAutoplay();
|
|
444
|
+
const { t } = playback.state();
|
|
445
|
+
const starts = current.stepStarts;
|
|
446
|
+
const i = stepIndexAt(current, t);
|
|
447
|
+
const target = snapUpToScrubGrid(e.key === "PageUp"
|
|
448
|
+
? (starts[i + 1] ?? 1)
|
|
449
|
+
// Inside a chapter, back up to its own start (restart it); already at the
|
|
450
|
+
// start, step to the chapter before — the video-player convention.
|
|
451
|
+
: (t > starts[i] + AT_BOUNDARY ? starts[i] : (starts[i - 1] ?? 0)));
|
|
452
|
+
// seek() abandons a pending cue but cannot touch the viewer's camera, so an
|
|
453
|
+
// in-flight tween would keep travelling to the position we just left.
|
|
454
|
+
viewer.cancelCameraTween();
|
|
455
|
+
showChapterBubble(target, { transient: true });
|
|
456
|
+
guarded(() => playback.seek(target));
|
|
457
|
+
};
|
|
458
|
+
const cycleAnimation = (dir) => {
|
|
459
|
+
disarmAutoplay();
|
|
460
|
+
const i = animations.indexOf(current);
|
|
461
|
+
selectAnimation(animations[(i + dir + animations.length) % animations.length].name);
|
|
462
|
+
};
|
|
463
|
+
const onPrevAnim = () => cycleAnimation(-1);
|
|
464
|
+
const onNextAnim = () => cycleAnimation(1);
|
|
265
465
|
const onPick = () => { disarmAutoplay(); selectAnimation(pick.value); };
|
|
266
466
|
const onResetClick = () => { disarmAutoplay(); doReset(); };
|
|
467
|
+
prevAnimBtn?.addEventListener("click", onPrevAnim);
|
|
468
|
+
nextAnimBtn?.addEventListener("click", onNextAnim);
|
|
267
469
|
playBtn.addEventListener("click", onPlayClick);
|
|
268
470
|
scrub.addEventListener("input", onScrub);
|
|
269
|
-
|
|
270
|
-
nextBtn.addEventListener("click", onNext);
|
|
471
|
+
scrub.addEventListener("keydown", onScrubKeydown);
|
|
271
472
|
pick.addEventListener("change", onPick);
|
|
272
473
|
resetBtn.addEventListener("click", onResetClick);
|
|
273
474
|
|
|
@@ -295,6 +496,7 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
295
496
|
bar.style.transform = "";
|
|
296
497
|
bar.style.maxWidth = "";
|
|
297
498
|
bar.style.overflow = "";
|
|
499
|
+
bar.classList.remove("pf-squeezed");
|
|
298
500
|
const vb = viewbarEl?.getBoundingClientRect();
|
|
299
501
|
const barRect = bar.getBoundingClientRect();
|
|
300
502
|
if (!vb || barRect.top >= vb.bottom || barRect.bottom <= vb.top) return;
|
|
@@ -308,22 +510,31 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
308
510
|
bar.style.left = `${plan.left}px`;
|
|
309
511
|
bar.style.transform = "none";
|
|
310
512
|
// maxWidth is the last resort, only reached when even the margin can't
|
|
311
|
-
// hold the gap — and the bar's flex children have hard minimums
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
//
|
|
513
|
+
// hold the gap — and the bar's flex children have hard minimums that don't
|
|
514
|
+
// shrink to fit a tighter cap. overflow:hidden is applied here, inline,
|
|
515
|
+
// rather than as a static rule so it is scoped to the capped state and the
|
|
516
|
+
// (far more common) uncapped bar never clips anything.
|
|
517
|
+
//
|
|
518
|
+
// Nothing that floats above the bar may live inside it, or this clips it:
|
|
519
|
+
// the ⓘ popover is on document.body and the chapter bubble is on the stage,
|
|
520
|
+
// both for that reason.
|
|
315
521
|
if (plan.maxWidth != null) {
|
|
316
522
|
bar.style.maxWidth = `${plan.maxWidth}px`;
|
|
317
523
|
bar.style.overflow = "hidden";
|
|
524
|
+
// Under the cap the bar sheds the pagers (~40px with their gaps). They are
|
|
525
|
+
// pure convenience — the picker beside them reaches every animation — and
|
|
526
|
+
// spending that width on the timeline is what keeps the scrubber
|
|
527
|
+
// targetable instead of letting it collapse toward nothing.
|
|
528
|
+
bar.classList.add("pf-squeezed");
|
|
318
529
|
}
|
|
319
530
|
}
|
|
320
531
|
function schedulePlacement() {
|
|
321
532
|
if (typeof requestAnimationFrame !== "function") return applyPlacement();
|
|
322
533
|
if (!placementRaf) placementRaf = requestAnimationFrame(applyPlacement);
|
|
323
534
|
}
|
|
324
|
-
// Observing the bar itself catches content-driven width changes
|
|
325
|
-
//
|
|
326
|
-
// drags and window resizes.
|
|
535
|
+
// Observing the bar itself catches content-driven width changes — the ⓘ glyph
|
|
536
|
+
// appearing or disappearing when only some animations declare a description;
|
|
537
|
+
// the viewbar, cutaway's actions; the stage, rail drags and window resizes.
|
|
327
538
|
const placementObserver = typeof ResizeObserver === "function"
|
|
328
539
|
? new ResizeObserver(schedulePlacement) : null;
|
|
329
540
|
if (placementObserver) {
|
|
@@ -372,15 +583,21 @@ export function attachAnimationControls(viewer, part, { container, applyValues,
|
|
|
372
583
|
detach() {
|
|
373
584
|
offFrame();
|
|
374
585
|
offOrbit();
|
|
586
|
+
prevAnimBtn?.removeEventListener("click", onPrevAnim);
|
|
587
|
+
nextAnimBtn?.removeEventListener("click", onNextAnim);
|
|
375
588
|
playBtn.removeEventListener("click", onPlayClick);
|
|
376
589
|
scrub.removeEventListener("input", onScrub);
|
|
377
|
-
|
|
378
|
-
nextBtn.removeEventListener("click", onNext);
|
|
590
|
+
scrub.removeEventListener("keydown", onScrubKeydown);
|
|
379
591
|
pick.removeEventListener("change", onPick);
|
|
380
592
|
resetBtn.removeEventListener("click", onResetClick);
|
|
381
593
|
info.dispose();
|
|
382
594
|
placementObserver?.disconnect();
|
|
383
595
|
if (placementRaf && typeof cancelAnimationFrame === "function") cancelAnimationFrame(placementRaf);
|
|
596
|
+
scrubWrap.removeEventListener("pointermove", onWrapPointerMove);
|
|
597
|
+
scrubWrap.removeEventListener("pointerleave", onWrapPointerLeave);
|
|
598
|
+
scrubWrap.removeEventListener("pointercancel", onWrapPointerLeave);
|
|
599
|
+
hideChapterBubble(); // also clears hoverInside
|
|
600
|
+
chapterBubble.remove(); // a stage child, so the bar taking itself out misses it
|
|
384
601
|
bar.remove();
|
|
385
602
|
},
|
|
386
603
|
__viewer: viewer, // test hook only
|
package/src/framework/app.css
CHANGED
|
@@ -239,19 +239,50 @@ button.action:focus-visible, .adv-toggle:focus-visible, #viewbar button:focus-vi
|
|
|
239
239
|
.pf-anim-pick {
|
|
240
240
|
background: var(--pf-input-bg); border: 1px solid var(--pf-border);
|
|
241
241
|
border-radius: var(--pf-radius-control); padding: 3px 6px;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
242
|
+
/* The widest thing in the bar after the timeline, and the cheapest to give
|
|
243
|
+
up: a select's default `min-width: auto` floors it at its longest option,
|
|
244
|
+
so under pressure it would hold full width while the scrubber collapsed.
|
|
245
|
+
Let it yield first, and faster than everything else — but not to a bare
|
|
246
|
+
chevron: below this the control stops naming the animation it selects. */
|
|
247
|
+
min-width: 44px; flex-shrink: 4;
|
|
248
|
+
}
|
|
249
|
+
/* A child of the stage, not of the bar (the capped bar clips its contents, and
|
|
250
|
+
this sits above them) — animation-controls.js sets left/bottom per reveal,
|
|
251
|
+
stage-relative. z-index clears .pf-anim-bar's 15. */
|
|
252
|
+
.pf-anim-chapter {
|
|
253
|
+
position: absolute; transform: translateX(-50%); z-index: 16;
|
|
254
|
+
font-family: var(--pf-mono); font-size: 10px; color: var(--pf-text-2);
|
|
255
|
+
background: var(--pf-surface); border: 1px solid var(--pf-border);
|
|
256
|
+
border-radius: var(--pf-radius-control); box-shadow: var(--pf-shadow-float);
|
|
257
|
+
padding: 3px 8px; white-space: nowrap;
|
|
258
|
+
pointer-events: none;
|
|
259
|
+
/* Out of flow, so nothing else constrains it: a long chapter label would
|
|
260
|
+
otherwise run past both ends of the scrubber and off a narrow stage.
|
|
261
|
+
Capped at the wrap's nominal width and ellipsised instead. */
|
|
262
|
+
max-width: 220px; overflow: hidden; text-overflow: ellipsis;
|
|
263
|
+
opacity: 0; transition: opacity .12s ease;
|
|
264
|
+
}
|
|
265
|
+
.pf-anim-chapter.pf-show { opacity: 1; }
|
|
266
|
+
/* 220px when there is room. The floor is what matters under pressure: a
|
|
267
|
+
timeline is a pointing target, and below ~96px it stops being one — the
|
|
268
|
+
chapter ticks collapse onto each other and a drag can't resolve a chapter.
|
|
269
|
+
Everything else in the bar yields before this does. */
|
|
270
|
+
.pf-anim-scrub-wrap {
|
|
271
|
+
position: relative; display: inline-flex; align-items: center;
|
|
272
|
+
width: 220px; min-width: 80px;
|
|
273
|
+
}
|
|
274
|
+
/* Capped bar: the pagers go, and their width goes to the timeline. */
|
|
275
|
+
.pf-anim-bar.pf-squeezed .pf-anim-page { display: none; }
|
|
249
276
|
.pf-anim-scrub { width: 100%; accent-color: var(--pf-accent); }
|
|
250
277
|
.pf-anim-tick {
|
|
251
278
|
position: absolute; top: 50%; width: 2px; height: 8px; margin-top: -4px;
|
|
252
279
|
background: var(--pf-muted); pointer-events: none;
|
|
253
280
|
}
|
|
254
281
|
|
|
282
|
+
@media (prefers-reduced-motion: reduce) {
|
|
283
|
+
.pf-anim-chapter { transition: none; }
|
|
284
|
+
}
|
|
285
|
+
|
|
255
286
|
@media (max-width: 360px) {
|
|
256
287
|
/* #viewbar's card is 40px here (30px buttons) — keep the floor in step. */
|
|
257
288
|
.pf-anim-bar { min-height: 40px; }
|