@vectoriox/iox-ui 5.164.1 → 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.
@@ -91,6 +91,8 @@ var SceneAttribute;
91
91
  SceneAttribute["PhoneTracks"] = "data-iox-tracks-phone";
92
92
  /** A root's stage that is not a Scene's `scene.stage` part: the slider a scroll plays (premium M4). */
93
93
  SceneAttribute["Stage"] = "data-iox-scene-stage";
94
+ /** On a layer whose hold move has ended — it has LANDED (AW10, `sceneLand`). Written by the driver, read by `onSceneLand`. */
95
+ SceneAttribute["Landed"] = "data-iox-landed";
94
96
  })(SceneAttribute || (SceneAttribute = {}));
95
97
  /**
96
98
  * A SLIDER THE SCROLL PLAYS (premium components M4 — M1.3's held gallery). Its progress rests on each picture and changes
@@ -1148,8 +1150,18 @@ const STAGGER_MS = {
1148
1150
  [TextRevealBy.Word]: WORD_STAGGER_MS,
1149
1151
  [TextRevealBy.Letter]: LETTER_STAGGER_MS,
1150
1152
  };
1151
- function revealStagger(groups, by) {
1152
- return groups > 1 ? Math.min(STAGGER_MS[by], STAGGER_BUDGET_MS / (groups - 1)) : 0;
1153
+ /** The most a reveal may ask between two pieces (`params.stagger`): past it a heading is spelled out, not assembled. */
1154
+ const REVEAL_STAGGER_MAX_MS = 300;
1155
+ /**
1156
+ * A reveal's own step between pieces, in ms (`params.stagger`; AW10 — a drawer's letters ~20 ms, its lines ~150 ms), or
1157
+ * undefined for the step its kind of piece takes. Clamped to 0–`REVEAL_STAGGER_MAX_MS`; anything not a number is undefined.
1158
+ */
1159
+ function textRevealStaggerOf(value) {
1160
+ const ms = typeof value === 'number' ? value : typeof value === 'string' && value.trim() ? Number(value) : NaN;
1161
+ return Number.isFinite(ms) ? Math.min(REVEAL_STAGGER_MAX_MS, Math.max(0, Math.round(ms))) : undefined;
1162
+ }
1163
+ function revealStagger(groups, by, stagger) {
1164
+ return groups > 1 ? Math.min(stagger ?? STAGGER_MS[by], STAGGER_BUDGET_MS / (groups - 1)) : 0;
1153
1165
  }
1154
1166
  /** Past the mask's negative inset, so nothing shows before a piece's turn. */
1155
1167
  const PIECE_FRAMES = [{ transform: 'translateY(120%)' }, { transform: 'translateY(0)' }];
@@ -1183,13 +1195,14 @@ const playing = new WeakMap();
1183
1195
  * nothing to re-split on a resize. Null when there is nothing to split or it is being edited: the caller plays its plain
1184
1196
  * fade.
1185
1197
  */
1186
- function playTextReveal(el, by, timing, look = TextRevealLook.Rise) {
1198
+ function playTextReveal(el, by, timing, look = TextRevealLook.Rise, stagger) {
1187
1199
  playing.get(el)?.cancel();
1188
1200
  const planned = splitForReveal(el, by, look);
1189
1201
  if (!planned)
1190
1202
  return null;
1191
1203
  const { split, order, groups } = planned;
1192
- const step = revealStagger(groups, planned.by);
1204
+ // An asked step is for the pieces it asked for: a letter step on a text that fell to words takes the words' own.
1205
+ const step = revealStagger(groups, planned.by, planned.by === by ? stagger : undefined);
1193
1206
  const duration = Number(timing.duration) || DEFAULT_PIECE_MS;
1194
1207
  const delay = timing.delay ?? 0;
1195
1208
  const frames = look === TextRevealLook.Light ? LIGHT_FRAMES : PIECE_FRAMES;
@@ -1355,14 +1368,29 @@ function sliderOf(stage) {
1355
1368
  const swiper = holder?.swiper;
1356
1369
  return swiper && typeof swiper.setProgress === 'function' && !swiper.destroyed ? swiper : null;
1357
1370
  }
1371
+ /** The hold moves a layer travels by: they say where it lands. */
1372
+ const LANDING_PROPS = new Set([SceneProp.X, SceneProp.Y]);
1358
1373
  /**
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.
1374
+ * Where a layer that travels onto the stage has LANDED, as hold progress: the last key of its hold-range X / Y move (the
1375
+ * 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
1376
+ * start: 0.
1361
1377
  */
1362
1378
  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;
1379
+ return tracks
1380
+ .filter(track => LANDING_PROPS.has(track.prop) && isHoldTrack(track) && new Set(track.keys.map(([, value]) => value)).size > 1)
1381
+ .reduce((at, move) => Math.max(at, move.keys[move.keys.length - 1][0]), 0);
1365
1382
  }
1383
+ /**
1384
+ * AW10 (award plan "drawers" row): the trigger of an entrance played when its layer LANDS — the moment the Scene's progress
1385
+ * reaches the last key of the layer's travel (`stepLanding`). Both interaction runtimes run it through `onSceneLand`.
1386
+ */
1387
+ const SCENE_LAND_TRIGGER = 'sceneLand';
1388
+ /** Dispatched (not bubbling) on a layer as it lands. Never a DOM `scroll` (SC2). */
1389
+ const SCENE_LAND_EVENT = 'iox-scene-land';
1390
+ /** Progress short of a landing that still counts as landed: the damping settles onto the scroll, never past it. */
1391
+ const LANDED_SLACK = 1e-4;
1392
+ /** How much of an element must show before a word with no landing to wait for arrives (the runtimes' viewport entry). */
1393
+ const ARRIVE_THRESHOLD = 0.1;
1366
1394
  /**
1367
1395
  * 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
1396
  * when it already is — or when no step moves (nothing covers anything; a phone stacks them). Step i is in front from its
@@ -1634,6 +1662,7 @@ class ScrollDriver {
1634
1662
  scene.stage.style.removeProperty('translate');
1635
1663
  for (const layer of scene.layers) {
1636
1664
  layer.el.style.removeProperty('will-change');
1665
+ layer.el.removeAttribute(SceneAttribute.Landed);
1637
1666
  this.restoreWords(layer);
1638
1667
  this.stopPlayer(layer);
1639
1668
  }
@@ -1814,6 +1843,7 @@ class ScrollDriver {
1814
1843
  }
1815
1844
  letGo(layer) {
1816
1845
  layer.el.style.removeProperty('will-change');
1846
+ layer.el.removeAttribute(SceneAttribute.Landed);
1817
1847
  for (const key of Object.keys(layer.last))
1818
1848
  layer.el.style[key] = '';
1819
1849
  this.restoreWords(layer);
@@ -1837,6 +1867,7 @@ class ScrollDriver {
1837
1867
  el, tracks, phoneTracks, last: previous?.last ?? {}, stale: true, words: previous?.words ?? null, wordsRefused: false,
1838
1868
  player: previous?.player ?? null, playerKey: previous?.playerKey ?? '',
1839
1869
  crosses: crossesStage(tracks) || crossesStage(phoneTracks), crossInline: previous?.crossInline ?? 0, crossBlock: previous?.crossBlock ?? 0,
1870
+ landing: 0, landed: previous?.landed ?? false,
1840
1871
  };
1841
1872
  }
1842
1873
  remeasureAll() {
@@ -1853,8 +1884,10 @@ class ScrollDriver {
1853
1884
  scene.stick = scene.stage ? (parseFloat(this.host.getComputedStyle(scene.stage).top) || 0) : 0;
1854
1885
  scene.phone = (scene.stage?.offsetWidth ?? Infinity) <= SCENE_PHONE_MAX_WIDTH;
1855
1886
  scene.inlineSign = scene.stage && this.host.getComputedStyle(scene.stage).direction === 'rtl' ? -1 : 1;
1856
- for (const layer of scene.layers)
1887
+ for (const layer of scene.layers) {
1857
1888
  layer.stale = true;
1889
+ layer.landing = stepLanding(this.tracksOf(scene, layer));
1890
+ }
1858
1891
  }
1859
1892
  /** True when the scroll the driver reads is being smoothed right now: it follows it (RT-D2). */
1860
1893
  following() {
@@ -1950,8 +1983,33 @@ class ScrollDriver {
1950
1983
  }
1951
1984
  layer.last = frame;
1952
1985
  layer.stale = false;
1986
+ this.writeLanded(layer, scene.progress);
1953
1987
  }
1954
1988
  }
1989
+ /**
1990
+ * A layer that travels lands when what is on screen (the damped progress) reaches the end of its travel: it is marked,
1991
+ * and told once (`SCENE_LAND_EVENT`) — its words arrive then (AW10). Back before its landing it is unmarked, so a later
1992
+ * listener does not run for a layer the visitor scrolled back away from.
1993
+ */
1994
+ writeLanded(layer, progress) {
1995
+ const landed = layer.landing > 0 && progress >= layer.landing - LANDED_SLACK;
1996
+ if (landed === layer.landed)
1997
+ return;
1998
+ layer.landed = landed;
1999
+ if (!landed) {
2000
+ layer.el.removeAttribute(SceneAttribute.Landed);
2001
+ return;
2002
+ }
2003
+ layer.el.setAttribute(SceneAttribute.Landed, '');
2004
+ const Event = this.host.CustomEvent ?? CustomEvent;
2005
+ layer.el.dispatchEvent(new Event(SCENE_LAND_EVENT));
2006
+ }
2007
+ /** True when this driver tells `layer` it has landed: it holds its Scene and the layer travels at this width. */
2008
+ landsOnScroll(layer) {
2009
+ const root = layer.closest(`[${SceneAttribute.Root}]`);
2010
+ const scene = root ? this.scenes.get(root) : undefined;
2011
+ return !!scene?.layers.find(l => l.el === layer && l.landing > 0);
2012
+ }
1955
2013
  /**
1956
2014
  * The picture this moment asks for. The attribute sits on the Video's own root, which is the layer on the string path
1957
2015
  * and inside it on the component path. A layer with no pictures, or no Play track, holds its poster.
@@ -2045,6 +2103,75 @@ function attachSceneRoots(roots, options = {}) {
2045
2103
  driver.destroy();
2046
2104
  return null;
2047
2105
  }
2106
+ /** The layer `el` travels onto the stage with: the nearest one (itself or above it, inside its Scene) whose wide tracks
2107
+ * land (`stepLanding` > 0). Null when nothing carries it in. */
2108
+ function travellingLayerOf(el) {
2109
+ for (let node = el; node; node = node.parentElement) {
2110
+ if (node.hasAttribute(SceneAttribute.Root))
2111
+ return null;
2112
+ if (node.hasAttribute(SceneAttribute.Tracks) && stepLanding(parseTracks(node.getAttribute(SceneAttribute.Tracks))) > 0)
2113
+ return node;
2114
+ }
2115
+ return null;
2116
+ }
2117
+ /** The driver that tells `layer` it has landed, at this width — null when none plays its travel (reduced motion, a phone). */
2118
+ function landingDriverOf(layer) {
2119
+ const root = layer.closest(`[${SceneAttribute.Root}]`);
2120
+ const driver = root ? HELD.get(root) : undefined;
2121
+ return driver?.landsOnScroll(layer) ? driver : null;
2122
+ }
2123
+ /**
2124
+ * Run `run` ONCE when `el`'s words are to arrive (AW10, `SCENE_LAND_TRIGGER`): as the layer that carries it onto the stage
2125
+ * LANDS (`SCENE_LAND_EVENT`; at once when it already has), wherever a driver plays that travel. Where none does — the layer
2126
+ * does not travel at this width (a phone's stacked Scene), the visitor asked for less motion (no driver; the Scene flows),
2127
+ * nothing carries it (the first drawer, a node outside a Scene) — it arrives as it comes into view, as a viewport entrance
2128
+ * does. Focus reaching it first makes it arrive at once. Both interaction runtimes call this. Returns the way to let go.
2129
+ */
2130
+ function onSceneLand(el, run, host = window) {
2131
+ let done = false;
2132
+ const offs = [];
2133
+ const letGo = () => { offs.splice(0).forEach(off => off()); };
2134
+ const go = () => {
2135
+ if (done)
2136
+ return;
2137
+ done = true;
2138
+ letGo();
2139
+ run();
2140
+ };
2141
+ const layer = travellingLayerOf(el);
2142
+ // A keyboard that reaches it first never focuses something still waiting to arrive (WCAG 2.4.7): it arrives now.
2143
+ const focused = () => go();
2144
+ el.addEventListener('focusin', focused);
2145
+ offs.push(() => el.removeEventListener('focusin', focused));
2146
+ if (layer) {
2147
+ const heard = () => go();
2148
+ layer.addEventListener(SCENE_LAND_EVENT, heard);
2149
+ offs.push(() => layer.removeEventListener(SCENE_LAND_EVENT, heard));
2150
+ }
2151
+ const Observer = host.IntersectionObserver;
2152
+ if (Observer) {
2153
+ const io = new Observer(entries => {
2154
+ // Where a driver plays the travel it decides; the viewport only stands in where none does.
2155
+ if (entries.some(entry => entry.isIntersecting) && !(layer && landingDriverOf(layer)))
2156
+ go();
2157
+ }, { threshold: ARRIVE_THRESHOLD });
2158
+ io.observe(el);
2159
+ offs.push(() => io.disconnect());
2160
+ }
2161
+ else {
2162
+ // No observer to ask (an old browser): it stands in place on the next frame unless a driver will land it.
2163
+ const frame = host.requestAnimationFrame?.(() => { if (!(layer && landingDriverOf(layer)))
2164
+ go(); });
2165
+ if (frame)
2166
+ offs.push(() => host.cancelAnimationFrame?.(frame));
2167
+ }
2168
+ if (layer?.hasAttribute(SceneAttribute.Landed))
2169
+ go();
2170
+ return () => {
2171
+ done = true;
2172
+ letGo();
2173
+ };
2174
+ }
2048
2175
 
2049
2176
  /**
2050
2177
  * @vectoriox/iox-ui/scene-core — a Scene: a stage that holds still while the page scrolls past it, its layers moving on
@@ -2057,5 +2184,5 @@ function attachSceneRoots(roots, options = {}) {
2057
2184
  * Generated bundle index. Do not edit.
2058
2185
  */
2059
2186
 
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 };
2187
+ 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, REVEAL_STAGGER_MAX_MS, SCENE_BUDGET, SCENE_DAMPING, SCENE_FILM_SMOOTH, SCENE_FLOW_RULES, SCENE_LAND_EVENT, SCENE_LAND_TRIGGER, 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, onSceneLand, 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, textRevealStaggerOf, trackColourAt, trackEase, trackProgress, trackRange, trackValueAt, travellingLayerOf, unmovedBox, valueAt, withSceneKey, withScenePlayback, withSceneRevealFrom, withoutSceneKey, withoutScenePlayback };
2061
2188
  //# sourceMappingURL=vectoriox-iox-ui-scene-core.mjs.map