@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.
- package/composite-core/index.d.ts +15 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +14 -0
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +409 -23
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +175 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +6 -3
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +41 -7
- package/index.d.ts +4 -1
- package/package.json +1 -1
- package/scene-core/index.d.ts +68 -3
- package/src/composite-core/composite-kinds.ts +14 -0
- package/src/generation-core/check-layout.ts +34 -4
- package/src/generation-core/compose-layout.ts +219 -10
- package/src/generation-core/compose-site.ts +2 -0
- package/src/generation-core/layout-drawers.ts +106 -0
- package/src/generation-core/layout-fingerprint.ts +3 -0
- package/src/generation-core/layout-language.ts +4 -0
- package/src/generation-core/layout-space.ts +3 -2
- package/src/generation-core/layout-wire.ts +15 -3
- package/src/generation-core/patterns.ts +4 -0
- package/src/generation-core/site-spec.generated.ts +57 -5
- package/src/scene-core/scene.ts +6 -0
- package/src/scene-core/scroll-driver.ts +169 -1
- package/styles/iox-design.css +27 -0
package/src/scene-core/scene.ts
CHANGED
|
@@ -445,6 +445,12 @@ export const SCENE_FLOW_RULES = `.iox-role-scene{height:auto!important}`
|
|
|
445
445
|
+ `[${SceneAttribute.Tracks}]{transform:none!important;opacity:1!important;clip-path:none!important;pointer-events:auto!important}`
|
|
446
446
|
// 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.
|
|
447
447
|
+ `[${SceneAttribute.Tracks}]{max-width:100%!important;flex-wrap:wrap!important}`
|
|
448
|
+
// Drawers (AW9) flow as the phone draws them: each step full width, its spine a label above its words.
|
|
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}`
|
|
453
|
+
+ `.iox-role-scene-drawer-spine{writing-mode:horizontal-tb!important;rotate:none!important;width:auto!important;height:auto!important}`
|
|
448
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.
|
|
449
455
|
+ `[${VideoAttribute.Frames}]{height:auto!important}`
|
|
450
456
|
// On the component path it stands inside a host that took no height from it, so the host steps out of the layout.
|
|
@@ -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);
|
package/styles/iox-design.css
CHANGED
|
@@ -89,6 +89,33 @@ iox-gallery.iox-es-media[data-iox-empty] > .iox-gallery {
|
|
|
89
89
|
overflow-x: clip;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/* AW9 (award plan "Reddottours"). A sideways walk on a phone is a row the visitor swipes (RT-D4): each screen is a card
|
|
93
|
+
the row snaps to, the next one peeking. A drawer's spine (`drawers`) stands on end beside its step, and is a label above
|
|
94
|
+
the step on a phone. The sizes are the nodes' own (`composeLayout`); only what a node has no style for is here. Written
|
|
95
|
+
twice, because a size query (the canvas) and a media query cannot share a block. Reduced motion and no script flow
|
|
96
|
+
them (scene-core `SCENE_FLOW_RULES`). */
|
|
97
|
+
.iox-role-scene-drawer-spine {
|
|
98
|
+
writing-mode: vertical-rl;
|
|
99
|
+
rotate: 180deg;
|
|
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. */
|
|
108
|
+
@media (max-width: 767px) {
|
|
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)); }
|
|
110
|
+
.iox-role-scene-walk-screen { scroll-snap-align: start; }
|
|
111
|
+
.iox-role-scene-drawer-spine { writing-mode: horizontal-tb; rotate: none; }
|
|
112
|
+
}
|
|
113
|
+
@container iox-canvas (max-width: 767px) {
|
|
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)); }
|
|
115
|
+
.iox-role-scene-walk-screen { scroll-snap-align: start; }
|
|
116
|
+
.iox-role-scene-drawer-spine { writing-mode: horizontal-tb; rotate: none; }
|
|
117
|
+
}
|
|
118
|
+
|
|
92
119
|
/* ── Card v2 (composite T23; complex-components board 8) ──────────────────────────────────────────
|
|
93
120
|
The parts are ordinary nodes; `nodeDesignClasses` writes `iox-role-<role>` on each, so these rules are
|
|
94
121
|
the same in every renderer. Zero-specificity where an author's own value must win. */
|