@vectoriox/iox-ui 5.163.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.
@@ -392,6 +392,12 @@ const SCENE_FLOW_RULES = `.iox-role-scene{height:auto!important}`
392
392
  + `[${SceneAttribute.Tracks}]{transform:none!important;opacity:1!important;clip-path:none!important;pointer-events:auto!important}`
393
393
  // A row the scroll slid sideways has no scroll to slide it now: it wraps, or its last items run off the side of a phone.
394
394
  + `[${SceneAttribute.Tracks}]{max-width:100%!important;flex-wrap:wrap!important}`
395
+ // Drawers (AW9) flow as the phone draws them: each step full width, its spine a label above its words.
396
+ + `.iox-role-scene-drawer{width:100%!important;height:auto!important;flex-direction:column!important}`
397
+ // …one band after another, edge to edge: each step is its own ground, so the stage's padding and gap would show the
398
+ // section's ground between them and around them (a phone's stack draws none).
399
+ + `.iox-role-scene-stage:has(>.iox-role-scene-drawer,>[class*="iox-outer-"]>.iox-role-scene-drawer){padding:0!important;gap:0!important}`
400
+ + `.iox-role-scene-drawer-spine{writing-mode:horizontal-tb!important;rotate:none!important;width:auto!important;height:auto!important}`
395
401
  // 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.
396
402
  + `[${VideoAttribute.Frames}]{height:auto!important}`
397
403
  // On the component path it stands inside a host that took no height from it, so the host steps out of the layout.
@@ -1288,6 +1294,8 @@ const MAX_FRAME_SECONDS = 0.1;
1288
1294
  const WAKING_FRAME_SECONDS = 1 / 60;
1289
1295
  const STAGE_SELECTOR = `.iox-role-${SceneRole.Stage.replace(/\./g, '-')}, [${SceneAttribute.Stage}]`;
1290
1296
  const TRANSFORM_WILL_CHANGE = 'transform, opacity';
1297
+ /** The steps of a Scene that slide over one another (a `drawers` signature): a later one covers the one before. */
1298
+ const STEP_SELECTOR = `.iox-role-${SceneRole.Drawer.replace(/\./g, '-')}`;
1291
1299
  /** The class Lenis keeps on the element it scrolls only while it is SMOOTHING a scroll (a jump, the keyboard and the scroll
1292
1300
  * bar are not smoothed): what a driver with no named scroller reads. */
1293
1301
  const LENIS_SMOOTH_CLASS = 'lenis-smooth';
@@ -1347,6 +1355,76 @@ function sliderOf(stage) {
1347
1355
  const swiper = holder?.swiper;
1348
1356
  return swiper && typeof swiper.setProgress === 'function' && !swiper.destroyed ? swiper : null;
1349
1357
  }
1358
+ /**
1359
+ * 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
1360
+ * no such move (the first drawer, a phone's stacked panels) is on the stage from the start: 0.
1361
+ */
1362
+ function stepLanding(tracks) {
1363
+ const move = tracks.find(track => track.prop === SceneProp.X && isHoldTrack(track) && new Set(track.keys.map(([, value]) => value)).size > 1);
1364
+ return move ? move.keys[move.keys.length - 1][0] : 0;
1365
+ }
1366
+ /**
1367
+ * Where a Scene of steps (each covering the one before once it lands) must stand for step `index` to be in FRONT, or null
1368
+ * when it already is — or when no step moves (nothing covers anything; a phone stacks them). Step i is in front from its
1369
+ * landing until the next one lands. vectoriox/iox-ui#139: focus must never sit on a covered or waiting step (WCAG 2.4.11).
1370
+ */
1371
+ function progressShowingStep(landings, index, progress) {
1372
+ if (index < 0 || index >= landings.length || landings.every(at => at === 0))
1373
+ return null;
1374
+ const from = landings[index];
1375
+ const until = landings.slice(index + 1).find(at => at > from) ?? Infinity;
1376
+ return progress >= from && progress < until ? null : from;
1377
+ }
1378
+ /** 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
1379
+ * height) and its opacity — the last hold track of each, as `sceneFrame` reads them. Other ranges do not follow the hold. */
1380
+ function holdLookAt(tracks, p) {
1381
+ const last = (prop) => [...tracks].reverse().find(t => t.prop === prop && isHoldTrack(t));
1382
+ const x = last(SceneProp.X);
1383
+ const y = last(SceneProp.Y);
1384
+ const opacity = last(SceneProp.Opacity);
1385
+ return {
1386
+ x: x ? trackValueAt(x, p) : 0,
1387
+ y: y ? trackValueAt(y, p) : 0,
1388
+ opacity: opacity ? Math.min(1, Math.max(0, trackValueAt(opacity, p))) : 1,
1389
+ };
1390
+ }
1391
+ /** Px of rounding a box may stand past the frame and still count as inside it. */
1392
+ const INSIDE_SLACK = 1;
1393
+ /**
1394
+ * True when `box`, moved by `dx`/`dy`, stands inside `frame` on both axes. Along an axis on which the box is the larger,
1395
+ * it must cover the frame instead: as much of it as can be seen is seen.
1396
+ */
1397
+ function boxInside(box, frame, dx = 0, dy = 0) {
1398
+ const along = (a, b, from, to) => (b - a <= to - from
1399
+ ? a >= from - INSIDE_SLACK && b <= to + INSIDE_SLACK
1400
+ : a <= from + INSIDE_SLACK && b >= to - INSIDE_SLACK);
1401
+ return along(box.left + dx, box.right + dx, frame.left, frame.right) && along(box.top + dy, box.bottom + dy, frame.top, frame.bottom);
1402
+ }
1403
+ /** How finely the hold is searched for where a focused control shows: 1/400 of the travel is under a px a screen. */
1404
+ const SHOWING_SAMPLES = 400;
1405
+ /**
1406
+ * Where on the hold (0–1) a focused control shows, or null when it shows already at `current` — or nowhere. The nearest
1407
+ * moment it shows (ahead first, in reading order), then the middle of the stretch it stays showing from there: a walk's card
1408
+ * is brought to the middle of the screen, never left on the stage's edge. vectoriox/iox-ui#141 (WCAG 2.4.11).
1409
+ */
1410
+ function progressShowingFocus(current, shows, samples = SHOWING_SAMPLES) {
1411
+ const at = Math.min(1, Math.max(0, current));
1412
+ if (shows(at))
1413
+ return null;
1414
+ for (let k = 1; k <= samples; k++) {
1415
+ for (const sign of [1, -1]) {
1416
+ const p = at + sign * (k / samples);
1417
+ if (p < 0 || p > 1 || !shows(p))
1418
+ continue;
1419
+ // The stretch it shows over, away from `current`: it ends where it stops showing (or at the hold's end).
1420
+ let end = p;
1421
+ while (end + sign / samples >= 0 && end + sign / samples <= 1 && shows(end + sign / samples))
1422
+ end += sign / samples;
1423
+ return Math.round(((p + end) / 2) * 1e6) / 1e6;
1424
+ }
1425
+ }
1426
+ return null;
1427
+ }
1350
1428
  /** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
1351
1429
  function dampToward(current, target, seconds, rate = SCENE_DAMPING) {
1352
1430
  return current + (target - current) * (1 - Math.exp(-seconds * rate));
@@ -1438,6 +1516,13 @@ class ScrollDriver {
1438
1516
  this.frame = 0;
1439
1517
  this.lastTime = 0;
1440
1518
  this.wakeUp = () => this.wake();
1519
+ /** Focus moving onto a control the Scene does not show now brings the scroll to where it does (#139, #141). */
1520
+ this.onFocusIn = (e) => {
1521
+ const root = e.currentTarget;
1522
+ const scene = this.scenes.get(root);
1523
+ if (scene)
1524
+ this.showFocused(scene, e.target);
1525
+ };
1441
1526
  this.onWakeEvent = (e) => {
1442
1527
  // What arrived may be the stage itself (a played slider marks its stage when it boots): read the root again.
1443
1528
  const scene = [...this.scenes.values()].find(s => s.root.contains(e.target));
@@ -1519,6 +1604,9 @@ class ScrollDriver {
1519
1604
  const 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 };
1520
1605
  this.scenes.set(root, scene);
1521
1606
  this.resize?.observe(root);
1607
+ // The canvas (it pins) is the author's: it is never scrolled for them.
1608
+ if (!this.options.pin)
1609
+ root.addEventListener('focusin', this.onFocusIn);
1522
1610
  if (this.options.observe) {
1523
1611
  const Observer = this.host.MutationObserver;
1524
1612
  if (Observer) {
@@ -1540,6 +1628,7 @@ class ScrollDriver {
1540
1628
  if (HELD.get(root) === this)
1541
1629
  HELD.delete(root);
1542
1630
  scene.mutations?.disconnect();
1631
+ root.removeEventListener('focusin', this.onFocusIn);
1543
1632
  this.resize?.unobserve(root);
1544
1633
  if (scene.stage)
1545
1634
  scene.stage.style.removeProperty('translate');
@@ -1622,6 +1711,91 @@ class ScrollDriver {
1622
1711
  this.links.clear();
1623
1712
  this.resize?.disconnect();
1624
1713
  }
1714
+ /**
1715
+ * Focus moved onto a control inside a Scene: the Scene is scrolled to where it shows it, and the frame lands at once.
1716
+ * - The browser scrolls a clipping stage to reveal a focused control it holds off view (`overflow: hidden` is
1717
+ * scrollable from script), and every layer would then stand shifted by that scroll until a reload. The driver alone
1718
+ * decides what the stage shows: the offset goes now, and again after the browser's own focus scrolling, which may
1719
+ * come after this event (vectoriox/iox-ui#139, #141).
1720
+ * - On a step another covers, or one still waiting off the stage (drawers): to where that step has landed (#139).
1721
+ * - Anywhere else (a card a walk has not brought in, a layer still flying in): to the nearest moment the control stands
1722
+ * inside the stage, its moving layers' hold tracks read at each moment (#141).
1723
+ * The canvas never listens (it pins: the author is never scrolled), and a phone, whose Scenes flow, is left alone.
1724
+ */
1725
+ showFocused(scene, focused) {
1726
+ if (!scene.travel || !scene.stage)
1727
+ return;
1728
+ this.unscrollStage(scene.stage);
1729
+ this.host.requestAnimationFrame(() => this.unscrollStage(scene.stage));
1730
+ const rect = scene.root.getBoundingClientRect();
1731
+ const zoom = scene.height ? rect.height / scene.height : 1;
1732
+ const scrolled = (scene.stick * zoom - rect.top) / (zoom || 1);
1733
+ const step = this.stepShowing(scene, focused, scrolled);
1734
+ const at = step === undefined ? this.progressShowing(scene, focused) : step;
1735
+ if (at === null)
1736
+ return;
1737
+ this.host.scrollBy({ top: Math.min(scene.travel, at * scene.travel + 1) - scrolled, behavior: 'instant' });
1738
+ scene.fresh = true;
1739
+ this.wake();
1740
+ }
1741
+ /** The tracks a layer plays at the Scene's width. */
1742
+ tracksOf(scene, layer) {
1743
+ return scene.phone && layer.phoneTracks.length ? layer.phoneTracks : layer.tracks;
1744
+ }
1745
+ /**
1746
+ * Where a drawers Scene must stand for the focused control's step to be in front: null when it is, undefined when the
1747
+ * control is on no step (the general rule decides).
1748
+ */
1749
+ stepShowing(scene, focused, scrolled) {
1750
+ const steps = Array.from(scene.stage.querySelectorAll(STEP_SELECTOR))
1751
+ .filter(step => step.closest(`[${SceneAttribute.Root}]`) === scene.root);
1752
+ const index = steps.findIndex(step => step.contains(focused));
1753
+ if (index < 0)
1754
+ return undefined;
1755
+ const landings = steps.map(step => {
1756
+ const layer = scene.layers.find(l => l.el === step);
1757
+ return stepLanding(layer ? this.tracksOf(scene, layer) : []);
1758
+ });
1759
+ return progressShowingStep(landings, index, scrolled / scene.travel);
1760
+ }
1761
+ /**
1762
+ * Where on the hold the focused control stands inside the stage, seen (its moving layers at least half opaque), or null
1763
+ * when it does already, or never does. Its box is read where it is drawn now (at the damped progress) and moved by what
1764
+ * its layers' hold moves would add at each other moment. Scale and rotation are not followed: a Scene moves a control
1765
+ * into view by travel.
1766
+ */
1767
+ progressShowing(scene, focused) {
1768
+ if (scene.phone)
1769
+ return null;
1770
+ const stage = scene.stage;
1771
+ const moving = scene.layers.filter(layer => layer.el !== stage && layer.el.contains(focused)).map(layer => this.tracksOf(scene, layer));
1772
+ if (!moving.length)
1773
+ return null;
1774
+ const box = focused.getBoundingClientRect();
1775
+ if (!box.width && !box.height)
1776
+ return null;
1777
+ const frame = stage.getBoundingClientRect();
1778
+ // cqw / cqh are the stage's own px; on screen they are drawn at the stage's scale.
1779
+ const pxX = (frame.width || 0) / 100;
1780
+ const pxY = (frame.height || 0) / 100;
1781
+ const look = (p) => moving.reduce((sum, tracks) => {
1782
+ const at = holdLookAt(tracks, p);
1783
+ return { x: sum.x + at.x, y: sum.y + at.y, opacity: sum.opacity * at.opacity };
1784
+ }, { x: 0, y: 0, opacity: 1 });
1785
+ const now = look(scene.progress);
1786
+ return progressShowingFocus(scene.progress, p => {
1787
+ const then = look(p);
1788
+ return then.opacity >= 0.5 && boxInside(box, frame, (then.x - now.x) * pxX * scene.inlineSign, (then.y - now.y) * pxY);
1789
+ });
1790
+ }
1791
+ unscrollStage(stage) {
1792
+ if (!stage)
1793
+ return;
1794
+ if (stage.scrollLeft)
1795
+ stage.scrollLeft = 0;
1796
+ if (stage.scrollTop)
1797
+ stage.scrollTop = 0;
1798
+ }
1625
1799
  /** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
1626
1800
  readScene(scene) {
1627
1801
  scene.stage = scene.root.querySelector(STAGE_SELECTOR);
@@ -1883,5 +2057,5 @@ function attachSceneRoots(roots, options = {}) {
1883
2057
  * Generated bundle index. Do not edit.
1884
2058
  */
1885
2059
 
1886
- 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 };
2060
+ 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 };
1887
2061
  //# sourceMappingURL=vectoriox-iox-ui-scene-core.mjs.map