@vectoriox/iox-ui 5.164.0 → 5.165.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/composite-core/index.d.ts +5 -0
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +5 -0
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +51 -16
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +304 -6
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +22 -3
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +7 -1
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/scene-core/index.d.ts +107 -6
- package/src/composite-core/composite-kinds.ts +5 -0
- package/src/generation-core/carry-fill.ts +1 -1
- package/src/generation-core/check-layout.ts +1 -1
- package/src/generation-core/compose-layout.ts +51 -12
- package/src/scene-core/scene.ts +5 -0
- package/src/scene-core/scroll-driver.ts +286 -2
- package/src/scene-core/split-text.ts +17 -4
- package/styles/iox-design.css +9 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SceneRole } from '@vectoriox/iox-ui/composite-core';
|
|
2
2
|
import { FramePlayer, normalizeFrameSequence, VideoAttribute } from '@vectoriox/iox-ui/media-core';
|
|
3
3
|
|
|
4
|
-
import { crossesStage, heldProgress, normalizeTracks, SCENE_PHONE_MAX_WIDTH, SceneAttribute, sceneFrame, SceneFrame, scenePlayed, SceneProgress, sceneWordOpacity, sceneWordsLit, SceneTrack } from './scene';
|
|
4
|
+
import { crossesStage, heldProgress, isHoldTrack, trackValueAt, normalizeTracks, SCENE_PHONE_MAX_WIDTH, SceneAttribute, sceneFrame, SceneFrame, scenePlayed, SceneProgress, SceneProp, sceneWordOpacity, sceneWordsLit, SceneTrack } from './scene';
|
|
5
5
|
import { rangeDistance, rangeProgress, ScrollBox, ScrollRange } from './scroll-range';
|
|
6
6
|
import { LIGHT_UP_PIECE_CAP, SplitText, splitText } from './split-text';
|
|
7
7
|
|
|
@@ -31,6 +31,8 @@ const MAX_FRAME_SECONDS = 0.1;
|
|
|
31
31
|
const WAKING_FRAME_SECONDS = 1 / 60;
|
|
32
32
|
const STAGE_SELECTOR = `.iox-role-${SceneRole.Stage.replace(/\./g, '-')}, [${SceneAttribute.Stage}]`;
|
|
33
33
|
const TRANSFORM_WILL_CHANGE = 'transform, opacity';
|
|
34
|
+
/** The steps of a Scene that slide over one another (a `drawers` signature): a later one covers the one before. */
|
|
35
|
+
const STEP_SELECTOR = `.iox-role-${SceneRole.Drawer.replace(/\./g, '-')}`;
|
|
34
36
|
/** The class Lenis keeps on the element it scrolls only while it is SMOOTHING a scroll (a jump, the keyboard and the scroll
|
|
35
37
|
* bar are not smoothed): what a driver with no named scroller reads. */
|
|
36
38
|
export const LENIS_SMOOTH_CLASS = 'lenis-smooth';
|
|
@@ -108,6 +110,99 @@ function sliderOf(stage: HTMLElement | null): PlayedSlider | null {
|
|
|
108
110
|
return swiper && typeof swiper.setProgress === 'function' && !swiper.destroyed ? swiper : null;
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
/** The hold moves a layer travels by: they say where it lands. */
|
|
114
|
+
const LANDING_PROPS: ReadonlySet<SceneProp> = new Set([SceneProp.X, SceneProp.Y]);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Where a layer that travels onto the stage has LANDED, as hold progress: the last key of its hold-range X / Y move (the
|
|
118
|
+
* later, when it has both). A layer with no such move (the first drawer, a phone's stacked panels) is on the stage from the
|
|
119
|
+
* start: 0.
|
|
120
|
+
*/
|
|
121
|
+
export function stepLanding(tracks: ReadonlyArray<SceneTrack>): number {
|
|
122
|
+
return tracks
|
|
123
|
+
.filter(track => LANDING_PROPS.has(track.prop) && isHoldTrack(track) && new Set(track.keys.map(([, value]) => value)).size > 1)
|
|
124
|
+
.reduce((at, move) => Math.max(at, move.keys[move.keys.length - 1][0]), 0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* AW10 (award plan "drawers" row): the trigger of an entrance played when its layer LANDS — the moment the Scene's progress
|
|
129
|
+
* reaches the last key of the layer's travel (`stepLanding`). Both interaction runtimes run it through `onSceneLand`.
|
|
130
|
+
*/
|
|
131
|
+
export const SCENE_LAND_TRIGGER = 'sceneLand';
|
|
132
|
+
/** Dispatched (not bubbling) on a layer as it lands. Never a DOM `scroll` (SC2). */
|
|
133
|
+
export const SCENE_LAND_EVENT = 'iox-scene-land';
|
|
134
|
+
/** Progress short of a landing that still counts as landed: the damping settles onto the scroll, never past it. */
|
|
135
|
+
const LANDED_SLACK = 1e-4;
|
|
136
|
+
/** How much of an element must show before a word with no landing to wait for arrives (the runtimes' viewport entry). */
|
|
137
|
+
const ARRIVE_THRESHOLD = 0.1;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Where a Scene of steps (each covering the one before once it lands) must stand for step `index` to be in FRONT, or null
|
|
141
|
+
* when it already is — or when no step moves (nothing covers anything; a phone stacks them). Step i is in front from its
|
|
142
|
+
* landing until the next one lands. vectoriox/iox-ui#139: focus must never sit on a covered or waiting step (WCAG 2.4.11).
|
|
143
|
+
*/
|
|
144
|
+
export function progressShowingStep(landings: ReadonlyArray<number>, index: number, progress: number): number | null {
|
|
145
|
+
if (index < 0 || index >= landings.length || landings.every(at => at === 0)) return null;
|
|
146
|
+
const from = landings[index];
|
|
147
|
+
const until = landings.slice(index + 1).find(at => at > from) ?? Infinity;
|
|
148
|
+
return progress >= from && progress < until ? null : from;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Where a layer's hold tracks stand at hold progress `p`: its move in % of the stage (x of its width, unmirrored; y of its
|
|
152
|
+
* height) and its opacity — the last hold track of each, as `sceneFrame` reads them. Other ranges do not follow the hold. */
|
|
153
|
+
export function holdLookAt(tracks: ReadonlyArray<SceneTrack>, p: number): { x: number; y: number; opacity: number } {
|
|
154
|
+
const last = (prop: SceneProp): SceneTrack | undefined => [...tracks].reverse().find(t => t.prop === prop && isHoldTrack(t));
|
|
155
|
+
const x = last(SceneProp.X);
|
|
156
|
+
const y = last(SceneProp.Y);
|
|
157
|
+
const opacity = last(SceneProp.Opacity);
|
|
158
|
+
return {
|
|
159
|
+
x: x ? trackValueAt(x, p) : 0,
|
|
160
|
+
y: y ? trackValueAt(y, p) : 0,
|
|
161
|
+
opacity: opacity ? Math.min(1, Math.max(0, trackValueAt(opacity, p))) : 1,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** A box on screen (a `DOMRect`'s edges). */
|
|
166
|
+
export interface SceneBox { left: number; top: number; right: number; bottom: number }
|
|
167
|
+
|
|
168
|
+
/** Px of rounding a box may stand past the frame and still count as inside it. */
|
|
169
|
+
const INSIDE_SLACK = 1;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* True when `box`, moved by `dx`/`dy`, stands inside `frame` on both axes. Along an axis on which the box is the larger,
|
|
173
|
+
* it must cover the frame instead: as much of it as can be seen is seen.
|
|
174
|
+
*/
|
|
175
|
+
export function boxInside(box: SceneBox, frame: SceneBox, dx = 0, dy = 0): boolean {
|
|
176
|
+
const along = (a: number, b: number, from: number, to: number): boolean => (b - a <= to - from
|
|
177
|
+
? a >= from - INSIDE_SLACK && b <= to + INSIDE_SLACK
|
|
178
|
+
: a <= from + INSIDE_SLACK && b >= to - INSIDE_SLACK);
|
|
179
|
+
return along(box.left + dx, box.right + dx, frame.left, frame.right) && along(box.top + dy, box.bottom + dy, frame.top, frame.bottom);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** How finely the hold is searched for where a focused control shows: 1/400 of the travel is under a px a screen. */
|
|
183
|
+
const SHOWING_SAMPLES = 400;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Where on the hold (0–1) a focused control shows, or null when it shows already at `current` — or nowhere. The nearest
|
|
187
|
+
* moment it shows (ahead first, in reading order), then the middle of the stretch it stays showing from there: a walk's card
|
|
188
|
+
* is brought to the middle of the screen, never left on the stage's edge. vectoriox/iox-ui#141 (WCAG 2.4.11).
|
|
189
|
+
*/
|
|
190
|
+
export function progressShowingFocus(current: number, shows: (p: number) => boolean, samples = SHOWING_SAMPLES): number | null {
|
|
191
|
+
const at = Math.min(1, Math.max(0, current));
|
|
192
|
+
if (shows(at)) return null;
|
|
193
|
+
for (let k = 1; k <= samples; k++) {
|
|
194
|
+
for (const sign of [1, -1]) {
|
|
195
|
+
const p = at + sign * (k / samples);
|
|
196
|
+
if (p < 0 || p > 1 || !shows(p)) continue;
|
|
197
|
+
// The stretch it shows over, away from `current`: it ends where it stops showing (or at the hold's end).
|
|
198
|
+
let end = p;
|
|
199
|
+
while (end + sign / samples >= 0 && end + sign / samples <= 1 && shows(end + sign / samples)) end += sign / samples;
|
|
200
|
+
return Math.round(((p + end) / 2) * 1e6) / 1e6;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
111
206
|
/** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
|
|
112
207
|
export function dampToward(current: number, target: number, seconds: number, rate: number = SCENE_DAMPING): number {
|
|
113
208
|
return current + (target - current) * (1 - Math.exp(-seconds * rate));
|
|
@@ -266,6 +361,9 @@ interface Layer {
|
|
|
266
361
|
/** Where it stands in its crossing (0–1), inline and block, as last read. */
|
|
267
362
|
crossInline: number;
|
|
268
363
|
crossBlock: number;
|
|
364
|
+
/** Where it lands at the Scene's width (`stepLanding`), 0 when it never travels there; and whether it has. */
|
|
365
|
+
landing: number;
|
|
366
|
+
landed: boolean;
|
|
269
367
|
}
|
|
270
368
|
|
|
271
369
|
interface Scene {
|
|
@@ -305,6 +403,12 @@ export class ScrollDriver {
|
|
|
305
403
|
private frame = 0;
|
|
306
404
|
private lastTime = 0;
|
|
307
405
|
private readonly wakeUp = (): void => this.wake();
|
|
406
|
+
/** Focus moving onto a control the Scene does not show now brings the scroll to where it does (#139, #141). */
|
|
407
|
+
private readonly onFocusIn = (e: Event): void => {
|
|
408
|
+
const root = e.currentTarget as HTMLElement;
|
|
409
|
+
const scene = this.scenes.get(root);
|
|
410
|
+
if (scene) this.showFocused(scene, e.target as HTMLElement);
|
|
411
|
+
};
|
|
308
412
|
private readonly onWakeEvent = (e: Event): void => {
|
|
309
413
|
// What arrived may be the stage itself (a played slider marks its stage when it boots): read the root again.
|
|
310
414
|
const scene = [...this.scenes.values()].find(s => s.root.contains(e.target as Node));
|
|
@@ -330,6 +434,8 @@ export class ScrollDriver {
|
|
|
330
434
|
const scene: Scene = { root, stage: null, layers: [], progress: 0, target: 0, position: 0, along: 0, height: 0, travel: 0, exit: 0, stick: 0, phone: false, inlineSign: 1, fresh: true, mutations: null };
|
|
331
435
|
this.scenes.set(root, scene);
|
|
332
436
|
this.resize?.observe(root);
|
|
437
|
+
// The canvas (it pins) is the author's: it is never scrolled for them.
|
|
438
|
+
if (!this.options.pin) root.addEventListener('focusin', this.onFocusIn);
|
|
333
439
|
if (this.options.observe) {
|
|
334
440
|
const Observer = (this.host as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
|
|
335
441
|
if (Observer) {
|
|
@@ -351,10 +457,12 @@ export class ScrollDriver {
|
|
|
351
457
|
if (!scene) return;
|
|
352
458
|
if (HELD.get(root) === this) HELD.delete(root);
|
|
353
459
|
scene.mutations?.disconnect();
|
|
460
|
+
root.removeEventListener('focusin', this.onFocusIn);
|
|
354
461
|
this.resize?.unobserve(root);
|
|
355
462
|
if (scene.stage) scene.stage.style.removeProperty('translate');
|
|
356
463
|
for (const layer of scene.layers) {
|
|
357
464
|
layer.el.style.removeProperty('will-change');
|
|
465
|
+
layer.el.removeAttribute(SceneAttribute.Landed);
|
|
358
466
|
this.restoreWords(layer);
|
|
359
467
|
this.stopPlayer(layer);
|
|
360
468
|
}
|
|
@@ -436,6 +544,87 @@ export class ScrollDriver {
|
|
|
436
544
|
this.resize?.disconnect();
|
|
437
545
|
}
|
|
438
546
|
|
|
547
|
+
/**
|
|
548
|
+
* Focus moved onto a control inside a Scene: the Scene is scrolled to where it shows it, and the frame lands at once.
|
|
549
|
+
* - The browser scrolls a clipping stage to reveal a focused control it holds off view (`overflow: hidden` is
|
|
550
|
+
* scrollable from script), and every layer would then stand shifted by that scroll until a reload. The driver alone
|
|
551
|
+
* decides what the stage shows: the offset goes now, and again after the browser's own focus scrolling, which may
|
|
552
|
+
* come after this event (vectoriox/iox-ui#139, #141).
|
|
553
|
+
* - On a step another covers, or one still waiting off the stage (drawers): to where that step has landed (#139).
|
|
554
|
+
* - Anywhere else (a card a walk has not brought in, a layer still flying in): to the nearest moment the control stands
|
|
555
|
+
* inside the stage, its moving layers' hold tracks read at each moment (#141).
|
|
556
|
+
* The canvas never listens (it pins: the author is never scrolled), and a phone, whose Scenes flow, is left alone.
|
|
557
|
+
*/
|
|
558
|
+
private showFocused(scene: Scene, focused: HTMLElement): void {
|
|
559
|
+
if (!scene.travel || !scene.stage) return;
|
|
560
|
+
this.unscrollStage(scene.stage);
|
|
561
|
+
this.host.requestAnimationFrame(() => this.unscrollStage(scene.stage));
|
|
562
|
+
const rect = scene.root.getBoundingClientRect();
|
|
563
|
+
const zoom = scene.height ? rect.height / scene.height : 1;
|
|
564
|
+
const scrolled = (scene.stick * zoom - rect.top) / (zoom || 1);
|
|
565
|
+
const step = this.stepShowing(scene, focused, scrolled);
|
|
566
|
+
const at = step === undefined ? this.progressShowing(scene, focused) : step;
|
|
567
|
+
if (at === null) return;
|
|
568
|
+
this.host.scrollBy({ top: Math.min(scene.travel, at * scene.travel + 1) - scrolled, behavior: 'instant' as ScrollBehavior });
|
|
569
|
+
scene.fresh = true;
|
|
570
|
+
this.wake();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** The tracks a layer plays at the Scene's width. */
|
|
574
|
+
private tracksOf(scene: Scene, layer: Layer): SceneTrack[] {
|
|
575
|
+
return scene.phone && layer.phoneTracks.length ? layer.phoneTracks : layer.tracks;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Where a drawers Scene must stand for the focused control's step to be in front: null when it is, undefined when the
|
|
580
|
+
* control is on no step (the general rule decides).
|
|
581
|
+
*/
|
|
582
|
+
private stepShowing(scene: Scene, focused: HTMLElement, scrolled: number): number | null | undefined {
|
|
583
|
+
const steps = Array.from(scene.stage!.querySelectorAll<HTMLElement>(STEP_SELECTOR))
|
|
584
|
+
.filter(step => step.closest(`[${SceneAttribute.Root}]`) === scene.root);
|
|
585
|
+
const index = steps.findIndex(step => step.contains(focused));
|
|
586
|
+
if (index < 0) return undefined;
|
|
587
|
+
const landings = steps.map(step => {
|
|
588
|
+
const layer = scene.layers.find(l => l.el === step);
|
|
589
|
+
return stepLanding(layer ? this.tracksOf(scene, layer) : []);
|
|
590
|
+
});
|
|
591
|
+
return progressShowingStep(landings, index, scrolled / scene.travel);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Where on the hold the focused control stands inside the stage, seen (its moving layers at least half opaque), or null
|
|
596
|
+
* when it does already, or never does. Its box is read where it is drawn now (at the damped progress) and moved by what
|
|
597
|
+
* its layers' hold moves would add at each other moment. Scale and rotation are not followed: a Scene moves a control
|
|
598
|
+
* into view by travel.
|
|
599
|
+
*/
|
|
600
|
+
private progressShowing(scene: Scene, focused: HTMLElement): number | null {
|
|
601
|
+
if (scene.phone) return null;
|
|
602
|
+
const stage = scene.stage!;
|
|
603
|
+
const moving = scene.layers.filter(layer => layer.el !== stage && layer.el.contains(focused)).map(layer => this.tracksOf(scene, layer));
|
|
604
|
+
if (!moving.length) return null;
|
|
605
|
+
const box = focused.getBoundingClientRect();
|
|
606
|
+
if (!box.width && !box.height) return null;
|
|
607
|
+
const frame = stage.getBoundingClientRect();
|
|
608
|
+
// cqw / cqh are the stage's own px; on screen they are drawn at the stage's scale.
|
|
609
|
+
const pxX = (frame.width || 0) / 100;
|
|
610
|
+
const pxY = (frame.height || 0) / 100;
|
|
611
|
+
const look = (p: number) => moving.reduce((sum, tracks) => {
|
|
612
|
+
const at = holdLookAt(tracks, p);
|
|
613
|
+
return { x: sum.x + at.x, y: sum.y + at.y, opacity: sum.opacity * at.opacity };
|
|
614
|
+
}, { x: 0, y: 0, opacity: 1 });
|
|
615
|
+
const now = look(scene.progress);
|
|
616
|
+
return progressShowingFocus(scene.progress, p => {
|
|
617
|
+
const then = look(p);
|
|
618
|
+
return then.opacity >= 0.5 && boxInside(box, frame, (then.x - now.x) * pxX * scene.inlineSign, (then.y - now.y) * pxY);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private unscrollStage(stage: HTMLElement | null): void {
|
|
623
|
+
if (!stage) return;
|
|
624
|
+
if (stage.scrollLeft) stage.scrollLeft = 0;
|
|
625
|
+
if (stage.scrollTop) stage.scrollTop = 0;
|
|
626
|
+
}
|
|
627
|
+
|
|
439
628
|
/** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
|
|
440
629
|
private readScene(scene: Scene): void {
|
|
441
630
|
scene.stage = scene.root.querySelector<HTMLElement>(STAGE_SELECTOR);
|
|
@@ -454,6 +643,7 @@ export class ScrollDriver {
|
|
|
454
643
|
|
|
455
644
|
private letGo(layer: Layer): void {
|
|
456
645
|
layer.el.style.removeProperty('will-change');
|
|
646
|
+
layer.el.removeAttribute(SceneAttribute.Landed);
|
|
457
647
|
for (const key of Object.keys(layer.last) as (keyof SceneFrame)[]) layer.el.style[key] = '';
|
|
458
648
|
this.restoreWords(layer);
|
|
459
649
|
this.stopPlayer(layer);
|
|
@@ -479,6 +669,7 @@ export class ScrollDriver {
|
|
|
479
669
|
el, tracks, phoneTracks, last: previous?.last ?? {}, stale: true, words: previous?.words ?? null, wordsRefused: false,
|
|
480
670
|
player: previous?.player ?? null, playerKey: previous?.playerKey ?? '',
|
|
481
671
|
crosses: crossesStage(tracks) || crossesStage(phoneTracks), crossInline: previous?.crossInline ?? 0, crossBlock: previous?.crossBlock ?? 0,
|
|
672
|
+
landing: 0, landed: previous?.landed ?? false,
|
|
482
673
|
};
|
|
483
674
|
}
|
|
484
675
|
|
|
@@ -496,7 +687,10 @@ export class ScrollDriver {
|
|
|
496
687
|
scene.stick = scene.stage ? (parseFloat(this.host.getComputedStyle(scene.stage).top) || 0) : 0;
|
|
497
688
|
scene.phone = (scene.stage?.offsetWidth ?? Infinity) <= SCENE_PHONE_MAX_WIDTH;
|
|
498
689
|
scene.inlineSign = scene.stage && this.host.getComputedStyle(scene.stage).direction === 'rtl' ? -1 : 1;
|
|
499
|
-
for (const layer of scene.layers)
|
|
690
|
+
for (const layer of scene.layers) {
|
|
691
|
+
layer.stale = true;
|
|
692
|
+
layer.landing = stepLanding(this.tracksOf(scene, layer));
|
|
693
|
+
}
|
|
500
694
|
}
|
|
501
695
|
|
|
502
696
|
private readonly tick = (now: number): void => {
|
|
@@ -644,7 +838,33 @@ export class ScrollDriver {
|
|
|
644
838
|
}
|
|
645
839
|
layer.last = frame;
|
|
646
840
|
layer.stale = false;
|
|
841
|
+
this.writeLanded(layer, scene.progress);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* A layer that travels lands when what is on screen (the damped progress) reaches the end of its travel: it is marked,
|
|
847
|
+
* and told once (`SCENE_LAND_EVENT`) — its words arrive then (AW10). Back before its landing it is unmarked, so a later
|
|
848
|
+
* listener does not run for a layer the visitor scrolled back away from.
|
|
849
|
+
*/
|
|
850
|
+
private writeLanded(layer: Layer, progress: number): void {
|
|
851
|
+
const landed = layer.landing > 0 && progress >= layer.landing - LANDED_SLACK;
|
|
852
|
+
if (landed === layer.landed) return;
|
|
853
|
+
layer.landed = landed;
|
|
854
|
+
if (!landed) {
|
|
855
|
+
layer.el.removeAttribute(SceneAttribute.Landed);
|
|
856
|
+
return;
|
|
647
857
|
}
|
|
858
|
+
layer.el.setAttribute(SceneAttribute.Landed, '');
|
|
859
|
+
const Event = (this.host as Window & { CustomEvent?: typeof CustomEvent }).CustomEvent ?? CustomEvent;
|
|
860
|
+
layer.el.dispatchEvent(new Event(SCENE_LAND_EVENT));
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** True when this driver tells `layer` it has landed: it holds its Scene and the layer travels at this width. */
|
|
864
|
+
landsOnScroll(layer: HTMLElement): boolean {
|
|
865
|
+
const root = layer.closest<HTMLElement>(`[${SceneAttribute.Root}]`);
|
|
866
|
+
const scene = root ? this.scenes.get(root) : undefined;
|
|
867
|
+
return !!scene?.layers.find(l => l.el === layer && l.landing > 0);
|
|
648
868
|
}
|
|
649
869
|
|
|
650
870
|
/**
|
|
@@ -733,3 +953,67 @@ export function attachSceneRoots(roots: ReadonlyArray<HTMLElement>, options: Scr
|
|
|
733
953
|
driver.destroy();
|
|
734
954
|
return null;
|
|
735
955
|
}
|
|
956
|
+
|
|
957
|
+
/** The layer `el` travels onto the stage with: the nearest one (itself or above it, inside its Scene) whose wide tracks
|
|
958
|
+
* land (`stepLanding` > 0). Null when nothing carries it in. */
|
|
959
|
+
export function travellingLayerOf(el: HTMLElement): HTMLElement | null {
|
|
960
|
+
for (let node: HTMLElement | null = el; node; node = node.parentElement) {
|
|
961
|
+
if (node.hasAttribute(SceneAttribute.Root)) return null;
|
|
962
|
+
if (node.hasAttribute(SceneAttribute.Tracks) && stepLanding(parseTracks(node.getAttribute(SceneAttribute.Tracks))) > 0) return node;
|
|
963
|
+
}
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/** The driver that tells `layer` it has landed, at this width — null when none plays its travel (reduced motion, a phone). */
|
|
968
|
+
function landingDriverOf(layer: HTMLElement): ScrollDriver | null {
|
|
969
|
+
const root = layer.closest<HTMLElement>(`[${SceneAttribute.Root}]`);
|
|
970
|
+
const driver = root ? HELD.get(root) : undefined;
|
|
971
|
+
return driver?.landsOnScroll(layer) ? driver : null;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Run `run` ONCE when `el`'s words are to arrive (AW10, `SCENE_LAND_TRIGGER`): as the layer that carries it onto the stage
|
|
976
|
+
* LANDS (`SCENE_LAND_EVENT`; at once when it already has), wherever a driver plays that travel. Where none does — the layer
|
|
977
|
+
* does not travel at this width (a phone's stacked Scene), the visitor asked for less motion (no driver; the Scene flows),
|
|
978
|
+
* nothing carries it (the first drawer, a node outside a Scene) — it arrives as it comes into view, as a viewport entrance
|
|
979
|
+
* does. Focus reaching it first makes it arrive at once. Both interaction runtimes call this. Returns the way to let go.
|
|
980
|
+
*/
|
|
981
|
+
export function onSceneLand(el: HTMLElement, run: () => void, host: Window = window): () => void {
|
|
982
|
+
let done = false;
|
|
983
|
+
const offs: Array<() => void> = [];
|
|
984
|
+
const letGo = (): void => { offs.splice(0).forEach(off => off()); };
|
|
985
|
+
const go = (): void => {
|
|
986
|
+
if (done) return;
|
|
987
|
+
done = true;
|
|
988
|
+
letGo();
|
|
989
|
+
run();
|
|
990
|
+
};
|
|
991
|
+
const layer = travellingLayerOf(el);
|
|
992
|
+
// A keyboard that reaches it first never focuses something still waiting to arrive (WCAG 2.4.7): it arrives now.
|
|
993
|
+
const focused = (): void => go();
|
|
994
|
+
el.addEventListener('focusin', focused);
|
|
995
|
+
offs.push(() => el.removeEventListener('focusin', focused));
|
|
996
|
+
if (layer) {
|
|
997
|
+
const heard = (): void => go();
|
|
998
|
+
layer.addEventListener(SCENE_LAND_EVENT, heard);
|
|
999
|
+
offs.push(() => layer.removeEventListener(SCENE_LAND_EVENT, heard));
|
|
1000
|
+
}
|
|
1001
|
+
const Observer = (host as Window & { IntersectionObserver?: typeof IntersectionObserver }).IntersectionObserver;
|
|
1002
|
+
if (Observer) {
|
|
1003
|
+
const io = new Observer(entries => {
|
|
1004
|
+
// Where a driver plays the travel it decides; the viewport only stands in where none does.
|
|
1005
|
+
if (entries.some(entry => entry.isIntersecting) && !(layer && landingDriverOf(layer))) go();
|
|
1006
|
+
}, { threshold: ARRIVE_THRESHOLD });
|
|
1007
|
+
io.observe(el);
|
|
1008
|
+
offs.push(() => io.disconnect());
|
|
1009
|
+
} else {
|
|
1010
|
+
// No observer to ask (an old browser): it stands in place on the next frame unless a driver will land it.
|
|
1011
|
+
const frame = host.requestAnimationFrame?.(() => { if (!(layer && landingDriverOf(layer))) go(); });
|
|
1012
|
+
if (frame) offs.push(() => host.cancelAnimationFrame?.(frame));
|
|
1013
|
+
}
|
|
1014
|
+
if (layer?.hasAttribute(SceneAttribute.Landed)) go();
|
|
1015
|
+
return () => {
|
|
1016
|
+
done = true;
|
|
1017
|
+
letGo();
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
@@ -262,8 +262,20 @@ const STAGGER_MS: Readonly<Record<TextRevealBy, number>> = {
|
|
|
262
262
|
[TextRevealBy.Letter]: LETTER_STAGGER_MS,
|
|
263
263
|
};
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
/** The most a reveal may ask between two pieces (`params.stagger`): past it a heading is spelled out, not assembled. */
|
|
266
|
+
export const REVEAL_STAGGER_MAX_MS = 300;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A reveal's own step between pieces, in ms (`params.stagger`; AW10 — a drawer's letters ~20 ms, its lines ~150 ms), or
|
|
270
|
+
* undefined for the step its kind of piece takes. Clamped to 0–`REVEAL_STAGGER_MAX_MS`; anything not a number is undefined.
|
|
271
|
+
*/
|
|
272
|
+
export function textRevealStaggerOf(value: unknown): number | undefined {
|
|
273
|
+
const ms = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
|
|
274
|
+
return Number.isFinite(ms) ? Math.min(REVEAL_STAGGER_MAX_MS, Math.max(0, Math.round(ms))) : undefined;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function revealStagger(groups: number, by: TextRevealBy, stagger?: number): number {
|
|
278
|
+
return groups > 1 ? Math.min(stagger ?? STAGGER_MS[by], STAGGER_BUDGET_MS / (groups - 1)) : 0;
|
|
267
279
|
}
|
|
268
280
|
|
|
269
281
|
/** Past the mask's negative inset, so nothing shows before a piece's turn. */
|
|
@@ -308,12 +320,13 @@ const playing = new WeakMap<HTMLElement, Animation>();
|
|
|
308
320
|
* nothing to re-split on a resize. Null when there is nothing to split or it is being edited: the caller plays its plain
|
|
309
321
|
* fade.
|
|
310
322
|
*/
|
|
311
|
-
export function playTextReveal(el: HTMLElement, by: TextRevealBy, timing: KeyframeAnimationOptions, look: TextRevealLook = TextRevealLook.Rise): Animation | null {
|
|
323
|
+
export function playTextReveal(el: HTMLElement, by: TextRevealBy, timing: KeyframeAnimationOptions, look: TextRevealLook = TextRevealLook.Rise, stagger?: number): Animation | null {
|
|
312
324
|
playing.get(el)?.cancel();
|
|
313
325
|
const planned = splitForReveal(el, by, look);
|
|
314
326
|
if (!planned) return null;
|
|
315
327
|
const { split, order, groups } = planned;
|
|
316
|
-
|
|
328
|
+
// An asked step is for the pieces it asked for: a letter step on a text that fell to words takes the words' own.
|
|
329
|
+
const step = revealStagger(groups, planned.by, planned.by === by ? stagger : undefined);
|
|
317
330
|
const duration = Number(timing.duration) || DEFAULT_PIECE_MS;
|
|
318
331
|
const delay = timing.delay ?? 0;
|
|
319
332
|
const frames = look === TextRevealLook.Light ? LIGHT_FRAMES : PIECE_FRAMES;
|
package/styles/iox-design.css
CHANGED
|
@@ -98,13 +98,20 @@ iox-gallery.iox-es-media[data-iox-empty] > .iox-gallery {
|
|
|
98
98
|
writing-mode: vertical-rl;
|
|
99
99
|
rotate: 180deg;
|
|
100
100
|
}
|
|
101
|
+
/* A walk's picture drifts by a share of its FRAME (generation-core `walkDrift`, in cqw): the frame is the size it reads. */
|
|
102
|
+
.iox-role-scene-walk-frame {
|
|
103
|
+
container-type: inline-size;
|
|
104
|
+
}
|
|
105
|
+
/* The row snaps a card to its padding edge, not the row's own edge: `scroll-padding` is the row's inline padding
|
|
106
|
+
(generation-core `LAYOUT_INSET`, which `walkSwipe` pads it with). Without it the first card loaded scrolled flush to the
|
|
107
|
+
screen's edge and every swipe landed a card there. */
|
|
101
108
|
@media (max-width: 767px) {
|
|
102
|
-
.iox-role-scene-walk { overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; }
|
|
109
|
+
.iox-role-scene-walk { overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; scroll-padding-inline: var(--iox-space-inline, max(4vw, 16px)); }
|
|
103
110
|
.iox-role-scene-walk-screen { scroll-snap-align: start; }
|
|
104
111
|
.iox-role-scene-drawer-spine { writing-mode: horizontal-tb; rotate: none; }
|
|
105
112
|
}
|
|
106
113
|
@container iox-canvas (max-width: 767px) {
|
|
107
|
-
.iox-role-scene-walk { overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; }
|
|
114
|
+
.iox-role-scene-walk { overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scrollbar-width: none; scroll-padding-inline: var(--iox-space-inline, max(4vw, 16px)); }
|
|
108
115
|
.iox-role-scene-walk-screen { scroll-snap-align: start; }
|
|
109
116
|
.iox-role-scene-drawer-spine { writing-mode: horizontal-tb; rotate: none; }
|
|
110
117
|
}
|