@vectoriox/iox-ui 5.164.0 → 5.164.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "5.164.0",
3
+ "version": "5.164.1",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -196,7 +196,7 @@ declare function applySceneFirstFrame(el: HTMLElement | null | undefined, node:
196
196
  */
197
197
  declare const SCENE_FLOW_RULES: string;
198
198
  /** Under reduced motion the driver never starts, so the same rules hold for the whole visit. */
199
- declare const SCENE_REDUCED_MOTION_CSS = "@media (prefers-reduced-motion: reduce){.iox-role-scene{height:auto!important}.iox-role-scene-stage{position:relative!important;top:auto!important;height:auto!important;overflow:visible!important;container-type:normal!important;display:flex!important;flex-direction:column!important;gap:clamp(40px,8vw,72px)!important;padding:clamp(72px,10vw,96px) clamp(16px,4vw,32px)!important;isolation:isolate}.iox-role-scene-stage>*{position:relative!important;inset:auto!important;max-width:100%!important}.iox-role-scene-stage>[class*=\"iox-outer-\"]>[class*=\"iox-node-\"]{position:relative!important;inset:auto!important}[data-iox-tracks]{transform:none!important;opacity:1!important;clip-path:none!important;pointer-events:auto!important}[data-iox-tracks]{max-width:100%!important;flex-wrap:wrap!important}.iox-role-scene-drawer{width:100%!important;height:auto!important;flex-direction:column!important}.iox-role-scene-drawer-spine{writing-mode:horizontal-tb!important;rotate:none!important;width:auto!important;height:auto!important}[data-iox-video-frames]{height:auto!important}iox-video:has(>[data-iox-video-frames]){display:contents!important}[data-iox-video-frames]>.iox-video__poster,[data-iox-video-frames]>picture>.iox-video__poster{position:static!important;height:auto!important}}";
199
+ declare const SCENE_REDUCED_MOTION_CSS = "@media (prefers-reduced-motion: reduce){.iox-role-scene{height:auto!important}.iox-role-scene-stage{position:relative!important;top:auto!important;height:auto!important;overflow:visible!important;container-type:normal!important;display:flex!important;flex-direction:column!important;gap:clamp(40px,8vw,72px)!important;padding:clamp(72px,10vw,96px) clamp(16px,4vw,32px)!important;isolation:isolate}.iox-role-scene-stage>*{position:relative!important;inset:auto!important;max-width:100%!important}.iox-role-scene-stage>[class*=\"iox-outer-\"]>[class*=\"iox-node-\"]{position:relative!important;inset:auto!important}[data-iox-tracks]{transform:none!important;opacity:1!important;clip-path:none!important;pointer-events:auto!important}[data-iox-tracks]{max-width:100%!important;flex-wrap:wrap!important}.iox-role-scene-drawer{width:100%!important;height:auto!important;flex-direction:column!important}.iox-role-scene-stage:has(>.iox-role-scene-drawer,>[class*=\"iox-outer-\"]>.iox-role-scene-drawer){padding:0!important;gap:0!important}.iox-role-scene-drawer-spine{writing-mode:horizontal-tb!important;rotate:none!important;width:auto!important;height:auto!important}[data-iox-video-frames]{height:auto!important}iox-video:has(>[data-iox-video-frames]){display:contents!important}[data-iox-video-frames]>.iox-video__poster,[data-iox-video-frames]>picture>.iox-video__poster{position:static!important;height:auto!important}}";
200
200
 
201
201
  declare function sceneKeyPosition(p: number): number;
202
202
  interface SceneTrackDef {
@@ -524,6 +524,42 @@ declare function scrollSubpixel(scroller: SmoothScroller | null): number;
524
524
  * it stands exactly on the scroll; it never snaps across one.
525
525
  */
526
526
  declare function followToward(current: number, previousTarget: number, target: number, seconds: number, rate?: number): number;
527
+ /**
528
+ * Where a step that slides onto the stage has LANDED, as hold progress: the last key of its hold-range X track. A step with
529
+ * no such move (the first drawer, a phone's stacked panels) is on the stage from the start: 0.
530
+ */
531
+ declare function stepLanding(tracks: ReadonlyArray<SceneTrack>): number;
532
+ /**
533
+ * Where a Scene of steps (each covering the one before once it lands) must stand for step `index` to be in FRONT, or null
534
+ * when it already is — or when no step moves (nothing covers anything; a phone stacks them). Step i is in front from its
535
+ * landing until the next one lands. vectoriox/iox-ui#139: focus must never sit on a covered or waiting step (WCAG 2.4.11).
536
+ */
537
+ declare function progressShowingStep(landings: ReadonlyArray<number>, index: number, progress: number): number | null;
538
+ /** 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
539
+ * height) and its opacity — the last hold track of each, as `sceneFrame` reads them. Other ranges do not follow the hold. */
540
+ declare function holdLookAt(tracks: ReadonlyArray<SceneTrack>, p: number): {
541
+ x: number;
542
+ y: number;
543
+ opacity: number;
544
+ };
545
+ /** A box on screen (a `DOMRect`'s edges). */
546
+ interface SceneBox {
547
+ left: number;
548
+ top: number;
549
+ right: number;
550
+ bottom: number;
551
+ }
552
+ /**
553
+ * True when `box`, moved by `dx`/`dy`, stands inside `frame` on both axes. Along an axis on which the box is the larger,
554
+ * it must cover the frame instead: as much of it as can be seen is seen.
555
+ */
556
+ declare function boxInside(box: SceneBox, frame: SceneBox, dx?: number, dy?: number): boolean;
557
+ /**
558
+ * Where on the hold (0–1) a focused control shows, or null when it shows already at `current` — or nowhere. The nearest
559
+ * moment it shows (ahead first, in reading order), then the middle of the stretch it stays showing from there: a walk's card
560
+ * is brought to the middle of the screen, never left on the stage's edge. vectoriox/iox-ui#141 (WCAG 2.4.11).
561
+ */
562
+ declare function progressShowingFocus(current: number, shows: (p: number) => boolean, samples?: number): number | null;
527
563
  /** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
528
564
  declare function dampToward(current: number, target: number, seconds: number, rate?: number): number;
529
565
  /** Where a root stands: scrolled `local` page px into its `travel`. `zoom` undoes the canvas's scale. */
@@ -620,6 +656,8 @@ declare class ScrollDriver {
620
656
  private frame;
621
657
  private lastTime;
622
658
  private readonly wakeUp;
659
+ /** Focus moving onto a control the Scene does not show now brings the scroll to where it does (#139, #141). */
660
+ private readonly onFocusIn;
623
661
  private readonly onWakeEvent;
624
662
  constructor(options?: ScrollDriverOptions);
625
663
  /** Drive a Scene's root. Idempotent: adding a root again re-reads it. False when another driver holds it. */
@@ -653,6 +691,33 @@ declare class ScrollDriver {
653
691
  /** Something moved that no scroll or resize announces (the canvas's zoom). */
654
692
  wake(): void;
655
693
  destroy(): void;
694
+ /**
695
+ * Focus moved onto a control inside a Scene: the Scene is scrolled to where it shows it, and the frame lands at once.
696
+ * - The browser scrolls a clipping stage to reveal a focused control it holds off view (`overflow: hidden` is
697
+ * scrollable from script), and every layer would then stand shifted by that scroll until a reload. The driver alone
698
+ * decides what the stage shows: the offset goes now, and again after the browser's own focus scrolling, which may
699
+ * come after this event (vectoriox/iox-ui#139, #141).
700
+ * - On a step another covers, or one still waiting off the stage (drawers): to where that step has landed (#139).
701
+ * - Anywhere else (a card a walk has not brought in, a layer still flying in): to the nearest moment the control stands
702
+ * inside the stage, its moving layers' hold tracks read at each moment (#141).
703
+ * The canvas never listens (it pins: the author is never scrolled), and a phone, whose Scenes flow, is left alone.
704
+ */
705
+ private showFocused;
706
+ /** The tracks a layer plays at the Scene's width. */
707
+ private tracksOf;
708
+ /**
709
+ * Where a drawers Scene must stand for the focused control's step to be in front: null when it is, undefined when the
710
+ * control is on no step (the general rule decides).
711
+ */
712
+ private stepShowing;
713
+ /**
714
+ * Where on the hold the focused control stands inside the stage, seen (its moving layers at least half opaque), or null
715
+ * when it does already, or never does. Its box is read where it is drawn now (at the damped progress) and moved by what
716
+ * its layers' hold moves would add at each other moment. Scale and rotation are not followed: a Scene moves a control
717
+ * into view by travel.
718
+ */
719
+ private progressShowing;
720
+ private unscrollStage;
656
721
  /** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
657
722
  private readScene;
658
723
  private letGo;
@@ -818,5 +883,5 @@ interface TextScrub {
818
883
  */
819
884
  declare function scrubTextReveal(el: HTMLElement, by: TextRevealBy, look?: TextRevealLook, easing?: string): TextScrub | null;
820
885
 
821
- export { LENIS_SMOOTH_CLASS, LETTER_PIECE_CAP, LIGHT_UP_PIECE_CAP, LetterRefusal, PARALLAX_DEPTH_DEFAULT, PARALLAX_PHONE_FACTOR, PARALLAX_REST_DEFAULT, PARALLAX_SPEED, PROGRESS_BAR_FRAMES, ParallaxDepth, ParallaxPhone, REVEAL_PIECE_CAP, SCENE_BUDGET, SCENE_DAMPING, SCENE_FILM_SMOOTH, SCENE_FLOW_RULES, SCENE_LENGTH, SCENE_MAX_SCREENS, SCENE_MIN_SCREENS, SCENE_PHONE_LENGTH, SCENE_PHONE_MAX_WIDTH, SCENE_REDUCED_MOTION_CSS, SCENE_REVEAL_DEFAULT, SCENE_STAGE_HEIGHT, SCENE_TRACK_DEFS, SCENE_TRACK_EASE, SCENE_WAKE_EVENT, SCENE_WORDS, SCENE_WORD_DIM, SCROLL_RANGE_DEFAULT, SCRUB_PIECES_IN_FLIGHT, SLIDER_HOLD_SHARE, SLIDER_SCROLL_STEP_SCREENS, SceneAttribute, SceneEase, SceneProp, SceneRange, SceneRevealFrom, ScrollActionKind, ScrollDriver, ScrollPlay, ScrollRange, TextRevealBy, TextRevealLook, applySceneFirstFrame, attachSceneRoots, attachScenes, buildSceneRecipe, colourAt, crossesStage, crossingOf, dampToward, followToward, gentleFrames, heldProgress, isHoldTrack, layoutBoxOnScreen, letterCount, letterRefusalOf, lettersSplittable, lightMotionWanted, lineIndexes, movedSceneKey, normalizeParallaxDepth, normalizeParallaxPhone, normalizeScrollRange, normalizeTracks, outermostNodeOf, pageScroller, parallaxFrames, parallaxOffset, parallaxRest, parallaxShift, playTextReveal, rangeDistance, rangeEnds, rangeProgress, revealClipPath, revealStagger, sceneBudget, sceneColourKeyAt, sceneDisplayValue, sceneFilmDensity, sceneFirstFrame, sceneFrame, sceneFrameDeclarations, sceneHasKeyAt, sceneHeightForScreens, sceneKeyPosition, sceneLayersOf, sceneNodeAttributes, scenePlayed, sceneRevealFromOf, sceneRootOnPath, sceneRootsIn, sceneScreensOf, sceneScrollAlong, sceneScrollState, sceneTrackDef, sceneTrackSpan, sceneWordOpacity, sceneWordsLit, scenesIn, scrollPlayFor, scrollSubpixel, scrubPieceProgress, scrubTextReveal, setPageScroller, splitForReveal, splitText, syncSceneAttributes, textPieces, textRevealByOf, textRevealLookOf, trackColourAt, trackEase, trackProgress, trackRange, trackValueAt, unmovedBox, valueAt, withSceneKey, withScenePlayback, withSceneRevealFrom, withoutSceneKey, withoutScenePlayback };
822
- export type { RevealSplit, SceneBudget, SceneFilmDensity, SceneFrame, SceneFrameOptions, SceneFrameState, SceneKey, SceneLayerNode, SceneNodeSource, SceneProgress, SceneTrack, SceneTrackDef, SceneTreeNode, SceneWords, ScrollBox, ScrollDriverOptions, ScrollLink, ScrollLinkGeometry, ScrollMotionEnv, SmoothScroller, SplitText, SplitTextOptions, TextPiece, TextScrub };
886
+ export { LENIS_SMOOTH_CLASS, LETTER_PIECE_CAP, LIGHT_UP_PIECE_CAP, LetterRefusal, PARALLAX_DEPTH_DEFAULT, PARALLAX_PHONE_FACTOR, PARALLAX_REST_DEFAULT, PARALLAX_SPEED, PROGRESS_BAR_FRAMES, ParallaxDepth, ParallaxPhone, REVEAL_PIECE_CAP, SCENE_BUDGET, SCENE_DAMPING, SCENE_FILM_SMOOTH, SCENE_FLOW_RULES, SCENE_LENGTH, SCENE_MAX_SCREENS, SCENE_MIN_SCREENS, SCENE_PHONE_LENGTH, SCENE_PHONE_MAX_WIDTH, SCENE_REDUCED_MOTION_CSS, SCENE_REVEAL_DEFAULT, SCENE_STAGE_HEIGHT, SCENE_TRACK_DEFS, SCENE_TRACK_EASE, SCENE_WAKE_EVENT, SCENE_WORDS, SCENE_WORD_DIM, SCROLL_RANGE_DEFAULT, SCRUB_PIECES_IN_FLIGHT, SLIDER_HOLD_SHARE, SLIDER_SCROLL_STEP_SCREENS, SceneAttribute, SceneEase, SceneProp, SceneRange, SceneRevealFrom, ScrollActionKind, ScrollDriver, ScrollPlay, ScrollRange, TextRevealBy, TextRevealLook, applySceneFirstFrame, attachSceneRoots, attachScenes, boxInside, buildSceneRecipe, colourAt, crossesStage, crossingOf, dampToward, followToward, gentleFrames, heldProgress, holdLookAt, isHoldTrack, layoutBoxOnScreen, letterCount, letterRefusalOf, lettersSplittable, lightMotionWanted, lineIndexes, movedSceneKey, normalizeParallaxDepth, normalizeParallaxPhone, normalizeScrollRange, normalizeTracks, outermostNodeOf, pageScroller, parallaxFrames, parallaxOffset, parallaxRest, parallaxShift, playTextReveal, progressShowingFocus, progressShowingStep, rangeDistance, rangeEnds, rangeProgress, revealClipPath, revealStagger, sceneBudget, sceneColourKeyAt, sceneDisplayValue, sceneFilmDensity, sceneFirstFrame, sceneFrame, sceneFrameDeclarations, sceneHasKeyAt, sceneHeightForScreens, sceneKeyPosition, sceneLayersOf, sceneNodeAttributes, scenePlayed, sceneRevealFromOf, sceneRootOnPath, sceneRootsIn, sceneScreensOf, sceneScrollAlong, sceneScrollState, sceneTrackDef, sceneTrackSpan, sceneWordOpacity, sceneWordsLit, scenesIn, scrollPlayFor, scrollSubpixel, scrubPieceProgress, scrubTextReveal, setPageScroller, splitForReveal, splitText, stepLanding, syncSceneAttributes, textPieces, textRevealByOf, textRevealLookOf, trackColourAt, trackEase, trackProgress, trackRange, trackValueAt, unmovedBox, valueAt, withSceneKey, withScenePlayback, withSceneRevealFrom, withoutSceneKey, withoutScenePlayback };
887
+ export type { RevealSplit, SceneBox, SceneBudget, SceneFilmDensity, SceneFrame, SceneFrameOptions, SceneFrameState, SceneKey, SceneLayerNode, SceneNodeSource, SceneProgress, SceneTrack, SceneTrackDef, SceneTreeNode, SceneWords, ScrollBox, ScrollDriverOptions, ScrollLink, ScrollLinkGeometry, ScrollMotionEnv, SmoothScroller, SplitText, SplitTextOptions, TextPiece, TextScrub };
@@ -77,6 +77,11 @@ export enum SceneRole {
77
77
  Walk = 'scene.walk',
78
78
  /** One screen of a walk: laid out on the wide row's grid (`display: contents`), on a phone a card the row snaps to. */
79
79
  WalkScreen = 'scene.walk-screen',
80
+ /**
81
+ * A picture's frame in a walk: the size its drift is measured against (`container-type: inline-size`, shared CSS), so a
82
+ * drift in `cqw` is a share of the FRAME, which is what the over-scale's slack is a share of.
83
+ */
84
+ WalkFrame = 'scene.walk-frame',
80
85
  /** AW9 `drawers`: one step — a panel that slides in from the inline end and stops one spine after the one before. */
81
86
  Drawer = 'scene.drawer',
82
87
  /** A drawer's spine: its number and heading, standing on end (on a phone, a label above the step). Decorative to
@@ -537,10 +537,16 @@ const FRAMED_SHOWING = 60;
537
537
  * `yPercent 30`). Measured over the exit range, after the hold. */
538
538
  const WINDOW_SINK: Readonly<SceneTrackOut> = { prop: SceneProp.Y, range: SceneRange.Exit, keys: [[0, 0], [1, 30]] };
539
539
  /** Reddottours S3: a walk's picture is over-scaled ×1.2 inside its frame and drifts against the row while it crosses the
540
- * screen (theirs: `xPercent 0 → 20` over its own crossing). The drift's reach, as a share of the frame's width, keeps
541
- * inside the over-scale's slack on both sides (0.08 × 1.2 < 0.1). */
540
+ * screen (theirs: `xPercent 0 → 20` over its own crossing). */
542
541
  const WALK_DRIFT_SCALE = 0.2;
543
- const WALK_DRIFT_SHARE = 0.08;
542
+ /**
543
+ * The drift's reach, a share of the FRAME's width — the frame is the size container (`SceneRole.WalkFrame`), so `cqw` there
544
+ * is the frame's. It moves the picture inside the over-scaled box, so it shows ×(1 + scale): it must stay under the slack a
545
+ * side, `scale / 2 / (1 + scale)` = 8.3%. A share of the stage (cqw of the stage, the col span's share) is NOT a share of
546
+ * the frame — gutters and the content column make a frame narrower than its columns' share, and an edge showed
547
+ * (vectoriox/iox-ui e2e:scenesites §2, 5.164.0: 0.103 of a frame against 0.1).
548
+ */
549
+ const WALK_DRIFT_SHARE = 0.07;
544
550
 
545
551
  /** The framed window: a held picture's opening clip, from the centre and from a frame, never from less. */
546
552
  function framedWindow(track: SceneTrackOut): SceneTrackOut {
@@ -554,9 +560,10 @@ function opensWindow(l: LayoutLayer, lc: LayerCtx): boolean {
554
560
  return (l.motion ?? []).some(t => t.prop === LayoutTrackProp.Clip && Number(t.to) >= 100 && Number(t.to) > Number(t.from));
555
561
  }
556
562
 
557
- /** A walk's picture drifting inside its frame as it crosses the screen: ± its share of the frame's width, in cqw. */
558
- function walkDrift(l: LayoutLayer): SceneTrackOut {
559
- const reach = Math.round(((l.col[1] - l.col[0]) / GRID_COLUMNS) * 100 * WALK_DRIFT_SHARE * 100) / 100;
563
+ /** A walk's picture drifting inside its frame as it crosses the screen: ± its share of the frame's width, in the frame's
564
+ * cqw (the frame is the size container — `SceneRole.WalkFrame`). */
565
+ function walkDrift(): SceneTrackOut {
566
+ const reach = Math.round(WALK_DRIFT_SHARE * 100 * 100) / 100;
560
567
  return { prop: SceneProp.X, range: SceneRange.CrossInline, keys: [[0, -reach], [1, reach]] };
561
568
  }
562
569
 
@@ -732,7 +739,8 @@ function photoLayer(id: string, l: LayoutLayer, ctx: Ctx, path: string, walking
732
739
  drift.children = [image];
733
740
  if (walking) {
734
741
  // On a phone the walk is a row the visitor swipes (RT-D4): the picture rests in its frame there.
735
- image.sceneTracks = [walkDrift(l)];
742
+ frame.role = SceneRole.WalkFrame;
743
+ image.sceneTracks = [walkDrift()];
736
744
  image.scenePhoneTracks = restingTracks(image.sceneTracks as SceneTrackOut[]);
737
745
  } else gap(ctx, LayoutGapCode.DepthSpeed, path, `inner ${l.inner}: over-scaled ×${(1 + k).toFixed(2)}, no drift`);
738
746
  frame.children = [drift];
@@ -447,6 +447,9 @@ export const SCENE_FLOW_RULES = `.iox-role-scene{height:auto!important}`
447
447
  + `[${SceneAttribute.Tracks}]{max-width:100%!important;flex-wrap:wrap!important}`
448
448
  // Drawers (AW9) flow as the phone draws them: each step full width, its spine a label above its words.
449
449
  + `.iox-role-scene-drawer{width:100%!important;height:auto!important;flex-direction:column!important}`
450
+ // …one band after another, edge to edge: each step is its own ground, so the stage's padding and gap would show the
451
+ // section's ground between them and around them (a phone's stack draws none).
452
+ + `.iox-role-scene-stage:has(>.iox-role-scene-drawer,>[class*="iox-outer-"]>.iox-role-scene-drawer){padding:0!important;gap:0!important}`
450
453
  + `.iox-role-scene-drawer-spine{writing-mode:horizontal-tb!important;rotate:none!important;width:auto!important;height:auto!important}`
451
454
  // A Video the scroll plays stands as its poster, at the poster's own height: a percent of a stage that now flows is nothing.
452
455
  + `[${VideoAttribute.Frames}]{height:auto!important}`
@@ -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,82 @@ function sliderOf(stage: HTMLElement | null): PlayedSlider | null {
108
110
  return swiper && typeof swiper.setProgress === 'function' && !swiper.destroyed ? swiper : null;
109
111
  }
110
112
 
113
+ /**
114
+ * Where a step that slides onto the stage has LANDED, as hold progress: the last key of its hold-range X track. A step with
115
+ * no such move (the first drawer, a phone's stacked panels) is on the stage from the start: 0.
116
+ */
117
+ export function stepLanding(tracks: ReadonlyArray<SceneTrack>): number {
118
+ const move = tracks.find(track => track.prop === SceneProp.X && isHoldTrack(track) && new Set(track.keys.map(([, value]) => value)).size > 1);
119
+ return move ? move.keys[move.keys.length - 1][0] : 0;
120
+ }
121
+
122
+ /**
123
+ * Where a Scene of steps (each covering the one before once it lands) must stand for step `index` to be in FRONT, or null
124
+ * when it already is — or when no step moves (nothing covers anything; a phone stacks them). Step i is in front from its
125
+ * landing until the next one lands. vectoriox/iox-ui#139: focus must never sit on a covered or waiting step (WCAG 2.4.11).
126
+ */
127
+ export function progressShowingStep(landings: ReadonlyArray<number>, index: number, progress: number): number | null {
128
+ if (index < 0 || index >= landings.length || landings.every(at => at === 0)) return null;
129
+ const from = landings[index];
130
+ const until = landings.slice(index + 1).find(at => at > from) ?? Infinity;
131
+ return progress >= from && progress < until ? null : from;
132
+ }
133
+
134
+ /** 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
135
+ * height) and its opacity — the last hold track of each, as `sceneFrame` reads them. Other ranges do not follow the hold. */
136
+ export function holdLookAt(tracks: ReadonlyArray<SceneTrack>, p: number): { x: number; y: number; opacity: number } {
137
+ const last = (prop: SceneProp): SceneTrack | undefined => [...tracks].reverse().find(t => t.prop === prop && isHoldTrack(t));
138
+ const x = last(SceneProp.X);
139
+ const y = last(SceneProp.Y);
140
+ const opacity = last(SceneProp.Opacity);
141
+ return {
142
+ x: x ? trackValueAt(x, p) : 0,
143
+ y: y ? trackValueAt(y, p) : 0,
144
+ opacity: opacity ? Math.min(1, Math.max(0, trackValueAt(opacity, p))) : 1,
145
+ };
146
+ }
147
+
148
+ /** A box on screen (a `DOMRect`'s edges). */
149
+ export interface SceneBox { left: number; top: number; right: number; bottom: number }
150
+
151
+ /** Px of rounding a box may stand past the frame and still count as inside it. */
152
+ const INSIDE_SLACK = 1;
153
+
154
+ /**
155
+ * True when `box`, moved by `dx`/`dy`, stands inside `frame` on both axes. Along an axis on which the box is the larger,
156
+ * it must cover the frame instead: as much of it as can be seen is seen.
157
+ */
158
+ export function boxInside(box: SceneBox, frame: SceneBox, dx = 0, dy = 0): boolean {
159
+ const along = (a: number, b: number, from: number, to: number): boolean => (b - a <= to - from
160
+ ? a >= from - INSIDE_SLACK && b <= to + INSIDE_SLACK
161
+ : a <= from + INSIDE_SLACK && b >= to - INSIDE_SLACK);
162
+ return along(box.left + dx, box.right + dx, frame.left, frame.right) && along(box.top + dy, box.bottom + dy, frame.top, frame.bottom);
163
+ }
164
+
165
+ /** How finely the hold is searched for where a focused control shows: 1/400 of the travel is under a px a screen. */
166
+ const SHOWING_SAMPLES = 400;
167
+
168
+ /**
169
+ * Where on the hold (0–1) a focused control shows, or null when it shows already at `current` — or nowhere. The nearest
170
+ * moment it shows (ahead first, in reading order), then the middle of the stretch it stays showing from there: a walk's card
171
+ * is brought to the middle of the screen, never left on the stage's edge. vectoriox/iox-ui#141 (WCAG 2.4.11).
172
+ */
173
+ export function progressShowingFocus(current: number, shows: (p: number) => boolean, samples = SHOWING_SAMPLES): number | null {
174
+ const at = Math.min(1, Math.max(0, current));
175
+ if (shows(at)) return null;
176
+ for (let k = 1; k <= samples; k++) {
177
+ for (const sign of [1, -1]) {
178
+ const p = at + sign * (k / samples);
179
+ if (p < 0 || p > 1 || !shows(p)) continue;
180
+ // The stretch it shows over, away from `current`: it ends where it stops showing (or at the hold's end).
181
+ let end = p;
182
+ while (end + sign / samples >= 0 && end + sign / samples <= 1 && shows(end + sign / samples)) end += sign / samples;
183
+ return Math.round(((p + end) / 2) * 1e6) / 1e6;
184
+ }
185
+ }
186
+ return null;
187
+ }
188
+
111
189
  /** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
112
190
  export function dampToward(current: number, target: number, seconds: number, rate: number = SCENE_DAMPING): number {
113
191
  return current + (target - current) * (1 - Math.exp(-seconds * rate));
@@ -305,6 +383,12 @@ export class ScrollDriver {
305
383
  private frame = 0;
306
384
  private lastTime = 0;
307
385
  private readonly wakeUp = (): void => this.wake();
386
+ /** Focus moving onto a control the Scene does not show now brings the scroll to where it does (#139, #141). */
387
+ private readonly onFocusIn = (e: Event): void => {
388
+ const root = e.currentTarget as HTMLElement;
389
+ const scene = this.scenes.get(root);
390
+ if (scene) this.showFocused(scene, e.target as HTMLElement);
391
+ };
308
392
  private readonly onWakeEvent = (e: Event): void => {
309
393
  // What arrived may be the stage itself (a played slider marks its stage when it boots): read the root again.
310
394
  const scene = [...this.scenes.values()].find(s => s.root.contains(e.target as Node));
@@ -330,6 +414,8 @@ export class ScrollDriver {
330
414
  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
415
  this.scenes.set(root, scene);
332
416
  this.resize?.observe(root);
417
+ // The canvas (it pins) is the author's: it is never scrolled for them.
418
+ if (!this.options.pin) root.addEventListener('focusin', this.onFocusIn);
333
419
  if (this.options.observe) {
334
420
  const Observer = (this.host as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
335
421
  if (Observer) {
@@ -351,6 +437,7 @@ export class ScrollDriver {
351
437
  if (!scene) return;
352
438
  if (HELD.get(root) === this) HELD.delete(root);
353
439
  scene.mutations?.disconnect();
440
+ root.removeEventListener('focusin', this.onFocusIn);
354
441
  this.resize?.unobserve(root);
355
442
  if (scene.stage) scene.stage.style.removeProperty('translate');
356
443
  for (const layer of scene.layers) {
@@ -436,6 +523,87 @@ export class ScrollDriver {
436
523
  this.resize?.disconnect();
437
524
  }
438
525
 
526
+ /**
527
+ * Focus moved onto a control inside a Scene: the Scene is scrolled to where it shows it, and the frame lands at once.
528
+ * - The browser scrolls a clipping stage to reveal a focused control it holds off view (`overflow: hidden` is
529
+ * scrollable from script), and every layer would then stand shifted by that scroll until a reload. The driver alone
530
+ * decides what the stage shows: the offset goes now, and again after the browser's own focus scrolling, which may
531
+ * come after this event (vectoriox/iox-ui#139, #141).
532
+ * - On a step another covers, or one still waiting off the stage (drawers): to where that step has landed (#139).
533
+ * - Anywhere else (a card a walk has not brought in, a layer still flying in): to the nearest moment the control stands
534
+ * inside the stage, its moving layers' hold tracks read at each moment (#141).
535
+ * The canvas never listens (it pins: the author is never scrolled), and a phone, whose Scenes flow, is left alone.
536
+ */
537
+ private showFocused(scene: Scene, focused: HTMLElement): void {
538
+ if (!scene.travel || !scene.stage) return;
539
+ this.unscrollStage(scene.stage);
540
+ this.host.requestAnimationFrame(() => this.unscrollStage(scene.stage));
541
+ const rect = scene.root.getBoundingClientRect();
542
+ const zoom = scene.height ? rect.height / scene.height : 1;
543
+ const scrolled = (scene.stick * zoom - rect.top) / (zoom || 1);
544
+ const step = this.stepShowing(scene, focused, scrolled);
545
+ const at = step === undefined ? this.progressShowing(scene, focused) : step;
546
+ if (at === null) return;
547
+ this.host.scrollBy({ top: Math.min(scene.travel, at * scene.travel + 1) - scrolled, behavior: 'instant' as ScrollBehavior });
548
+ scene.fresh = true;
549
+ this.wake();
550
+ }
551
+
552
+ /** The tracks a layer plays at the Scene's width. */
553
+ private tracksOf(scene: Scene, layer: Layer): SceneTrack[] {
554
+ return scene.phone && layer.phoneTracks.length ? layer.phoneTracks : layer.tracks;
555
+ }
556
+
557
+ /**
558
+ * Where a drawers Scene must stand for the focused control's step to be in front: null when it is, undefined when the
559
+ * control is on no step (the general rule decides).
560
+ */
561
+ private stepShowing(scene: Scene, focused: HTMLElement, scrolled: number): number | null | undefined {
562
+ const steps = Array.from(scene.stage!.querySelectorAll<HTMLElement>(STEP_SELECTOR))
563
+ .filter(step => step.closest(`[${SceneAttribute.Root}]`) === scene.root);
564
+ const index = steps.findIndex(step => step.contains(focused));
565
+ if (index < 0) return undefined;
566
+ const landings = steps.map(step => {
567
+ const layer = scene.layers.find(l => l.el === step);
568
+ return stepLanding(layer ? this.tracksOf(scene, layer) : []);
569
+ });
570
+ return progressShowingStep(landings, index, scrolled / scene.travel);
571
+ }
572
+
573
+ /**
574
+ * Where on the hold the focused control stands inside the stage, seen (its moving layers at least half opaque), or null
575
+ * when it does already, or never does. Its box is read where it is drawn now (at the damped progress) and moved by what
576
+ * its layers' hold moves would add at each other moment. Scale and rotation are not followed: a Scene moves a control
577
+ * into view by travel.
578
+ */
579
+ private progressShowing(scene: Scene, focused: HTMLElement): number | null {
580
+ if (scene.phone) return null;
581
+ const stage = scene.stage!;
582
+ const moving = scene.layers.filter(layer => layer.el !== stage && layer.el.contains(focused)).map(layer => this.tracksOf(scene, layer));
583
+ if (!moving.length) return null;
584
+ const box = focused.getBoundingClientRect();
585
+ if (!box.width && !box.height) return null;
586
+ const frame = stage.getBoundingClientRect();
587
+ // cqw / cqh are the stage's own px; on screen they are drawn at the stage's scale.
588
+ const pxX = (frame.width || 0) / 100;
589
+ const pxY = (frame.height || 0) / 100;
590
+ const look = (p: number) => moving.reduce((sum, tracks) => {
591
+ const at = holdLookAt(tracks, p);
592
+ return { x: sum.x + at.x, y: sum.y + at.y, opacity: sum.opacity * at.opacity };
593
+ }, { x: 0, y: 0, opacity: 1 });
594
+ const now = look(scene.progress);
595
+ return progressShowingFocus(scene.progress, p => {
596
+ const then = look(p);
597
+ return then.opacity >= 0.5 && boxInside(box, frame, (then.x - now.x) * pxX * scene.inlineSign, (then.y - now.y) * pxY);
598
+ });
599
+ }
600
+
601
+ private unscrollStage(stage: HTMLElement | null): void {
602
+ if (!stage) return;
603
+ if (stage.scrollLeft) stage.scrollLeft = 0;
604
+ if (stage.scrollTop) stage.scrollTop = 0;
605
+ }
606
+
439
607
  /** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
440
608
  private readScene(scene: Scene): void {
441
609
  scene.stage = scene.root.querySelector<HTMLElement>(STAGE_SELECTOR);
@@ -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
  }