@vectoriox/iox-ui 5.87.0 → 5.89.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.
Files changed (38) hide show
  1. package/actions-core/index.d.ts +17 -3
  2. package/composite-core/index.d.ts +208 -2
  3. package/design-core/index.d.ts +373 -1
  4. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +30 -4
  5. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +659 -118
  7. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs +444 -3
  9. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1082 -51
  11. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui-scene-core.mjs +244 -7
  13. package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
  14. package/fesm2022/vectoriox-iox-ui.mjs +604 -20
  15. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  16. package/generation-core/index.d.ts +375 -2
  17. package/index.d.ts +196 -2
  18. package/package.json +1 -1
  19. package/scene-core/index.d.ts +167 -2
  20. package/src/actions-core/action.model.ts +3 -0
  21. package/src/actions-core/element-actions.ts +32 -3
  22. package/src/composite-core/marquee-runtime.ts +255 -0
  23. package/src/composite-core/marquee.ts +267 -0
  24. package/src/composite-core/public-api.ts +3 -0
  25. package/src/composite-core/scroll-recipes.ts +74 -0
  26. package/src/composite-core/slider.ts +3 -2
  27. package/src/composite-core/structure.ts +7 -0
  28. package/src/design-core/contrast-audit.ts +6 -1
  29. package/src/design-core/flavor-spec.generated.ts +435 -1
  30. package/src/generation-core/compose-layout.ts +821 -0
  31. package/src/generation-core/compose-site.ts +14 -2
  32. package/src/generation-core/layout-language.ts +354 -0
  33. package/src/generation-core/node-baselines.generated.ts +5 -1
  34. package/src/generation-core/public-api.ts +2 -0
  35. package/src/scene-core/public-api.ts +1 -0
  36. package/src/scene-core/scroll-driver.ts +98 -0
  37. package/src/scene-core/scroll-range.ts +208 -0
  38. package/styles/iox-design.css +66 -1
@@ -526,14 +526,26 @@ function composeForm(node: SerializedNode, pn: PatternNode, id: string, ctx: Ctx
526
526
  }
527
527
  // A section may give the pattern's form another preset (`form`: Practice's contact page asks to book).
528
528
  const presetId = ctx.section?.form ?? pn.preset;
529
+ if (pn.c?.length) throw new ComposeError(`${id}: a preset Form takes its fields from the preset, not the pattern`);
530
+ stampPresetForm(node, presetId, id, ctx.owner);
531
+ }
532
+
533
+ /** A preset's name, stable form id and children on a Form node — the ONE stamping `composeSite` and `composeLayout` share. */
534
+ function stampPresetForm(node: SerializedNode, presetId: string, id: string, owner: string): void {
529
535
  const preset = formPresetById(presetId);
530
536
  if (!preset) throw new ComposeError(`${id}: no form preset "${presetId}" in forms-core`);
531
- if (pn.c?.length) throw new ComposeError(`${id}: a preset Form takes its fields from the preset, not the pattern`);
532
537
  setProp(node, 'name', preset.formName);
533
- setProp(node, 'formId', `${preset.id}-${stableHash(`${ctx.owner}/${id}`)}`);
538
+ setProp(node, 'formId', `${preset.id}-${stableHash(`${owner}/${id}`)}`);
534
539
  node.children = presetChildren(preset, id);
535
540
  }
536
541
 
542
+ /** A NEW Form stamped from a forms-core preset, exactly as a pattern's preset form is (premium M8: a layout's form layer). */
543
+ export function composePresetForm(id: string, presetId: string, owner: string): SerializedNode {
544
+ const node = create(id, FORM);
545
+ stampPresetForm(node, presetId, id, owner);
546
+ return node;
547
+ }
548
+
537
549
  /** A pattern node's children; an `each` child is stamped once per navigation page, its id carrying the
538
550
  * page key so it survives a page being left out or reordered. */
539
551
  function composeChildren(pn: PatternNode, id: string, repeater: RepeaterScope | null, ctx: Ctx): SerializedNode[] {
@@ -0,0 +1,354 @@
1
+ /**
2
+ * The LAYOUT LANGUAGE (premium components M8 — the prototype's CL2 / CL2.1, premium-sites plan "Breaking limits"): a page
3
+ * composed as layers of closed kinds placed on a 12-column grid, with closed sizes, the look's five colours, roles, time
4
+ * entrances, a parallax depth, held sections whose layers move by tracks, sideways sections, galleries, forms and a phone
5
+ * reading order. The model writes no CSS and no node tree; `composeLayout` stamps ordinary builder nodes from it.
6
+ *
7
+ * Gate 1 types the shape the three proof sites were saved in (iox-ai-guidance `prototypes/breaking-limits/round4|round3`).
8
+ * The closed lists move into the contract in gate 2 (m8-proof-sites.md, M8-D1).
9
+ */
10
+
11
+ export enum LayoutLayerKind {
12
+ Word = 'word',
13
+ Heading = 'heading',
14
+ Text = 'text',
15
+ Photo = 'photo',
16
+ Gallery = 'gallery',
17
+ Button = 'button',
18
+ List = 'list',
19
+ Number = 'number',
20
+ Shape = 'shape',
21
+ Label = 'label',
22
+ Form = 'form',
23
+ Marquee = 'marquee',
24
+ }
25
+
26
+ export enum LayoutSize {
27
+ Xs = 'xs',
28
+ S = 's',
29
+ M = 'm',
30
+ L = 'l',
31
+ Xl = 'xl',
32
+ Xxl = 'xxl',
33
+ /** As wide as its columns allow — a word, never a sentence. */
34
+ Screen = 'screen',
35
+ }
36
+
37
+ /** The look's five colours, by role. */
38
+ export enum LayoutColour {
39
+ Ground = 'ground',
40
+ Ink = 'ink',
41
+ Accent = 'accent',
42
+ Soft = 'soft',
43
+ Muted = 'muted',
44
+ }
45
+
46
+ export enum LayoutRole {
47
+ Lead = 'lead',
48
+ Support = 'support',
49
+ Decoration = 'decoration',
50
+ Static = 'static',
51
+ }
52
+
53
+ export enum LayoutEnter {
54
+ None = 'none',
55
+ Fade = 'fade',
56
+ FadeRise = 'fadeRise',
57
+ ScaleIn = 'scaleIn',
58
+ ClipReveal = 'clipReveal',
59
+ MaskRise = 'maskRise',
60
+ BlurIn = 'blurIn',
61
+ Pop = 'pop',
62
+ }
63
+
64
+ export enum LayoutDepth {
65
+ Back = 'back',
66
+ Mid = 'mid',
67
+ Front = 'front',
68
+ }
69
+
70
+ export enum LayoutTransition {
71
+ Cut = 'cut',
72
+ Flood = 'flood',
73
+ WipeUp = 'wipe-up',
74
+ WipeDown = 'wipe-down',
75
+ WipeStart = 'wipe-start',
76
+ WipeEnd = 'wipe-end',
77
+ }
78
+
79
+ export enum LayoutEase {
80
+ Out = 'out',
81
+ InOut = 'inOut',
82
+ Drawer = 'drawer',
83
+ Linear = 'linear',
84
+ }
85
+
86
+ export enum LayoutPace {
87
+ Slow = 'slow',
88
+ Normal = 'normal',
89
+ Quick = 'quick',
90
+ }
91
+
92
+ export enum LayoutSide {
93
+ Bottom = 'bottom',
94
+ Top = 'top',
95
+ Start = 'start',
96
+ End = 'end',
97
+ }
98
+
99
+ export enum LayoutTrackProp {
100
+ X = 'x',
101
+ Y = 'y',
102
+ Scale = 'scale',
103
+ Opacity = 'opacity',
104
+ Rotate = 'rotate',
105
+ Clip = 'clip',
106
+ Blur = 'blur',
107
+ }
108
+
109
+ export enum LayoutAlign {
110
+ Start = 'start',
111
+ Center = 'center',
112
+ End = 'end',
113
+ }
114
+
115
+ export enum LayoutBleed {
116
+ None = 'none',
117
+ Start = 'start',
118
+ End = 'end',
119
+ Both = 'both',
120
+ }
121
+
122
+ /** A pool photo's shape (the inventory measures each one): what it keeps where nothing else gives it a height. */
123
+ export enum LayoutPhotoShape {
124
+ Wide = 'wide',
125
+ Landscape = 'landscape',
126
+ Square = 'square',
127
+ Portrait = 'portrait',
128
+ Tall = 'tall',
129
+ }
130
+
131
+ export const LAYOUT_PHOTO_ASPECT: Readonly<Record<LayoutPhotoShape, string>> = {
132
+ [LayoutPhotoShape.Wide]: '16 / 9',
133
+ [LayoutPhotoShape.Landscape]: '3 / 2',
134
+ [LayoutPhotoShape.Square]: '1 / 1',
135
+ [LayoutPhotoShape.Portrait]: '2 / 3',
136
+ [LayoutPhotoShape.Tall]: '9 / 16',
137
+ };
138
+
139
+ export enum LayoutSectionKind {
140
+ Content = 'content',
141
+ Inhale = 'inhale',
142
+ }
143
+
144
+ export enum LayoutButtonVariant {
145
+ Primary = 'primary',
146
+ Secondary = 'secondary',
147
+ Ghost = 'ghost',
148
+ }
149
+
150
+ /** The product SliderContainer's own effects (iox-ui `slider-options.ts`). */
151
+ export enum LayoutGalleryEffect {
152
+ Slide = 'slide',
153
+ Fade = 'fade',
154
+ Cube = 'cube',
155
+ Flip = 'flip',
156
+ Coverflow = 'coverflow',
157
+ Cards = 'cards',
158
+ Creative = 'creative',
159
+ }
160
+
161
+ export enum LayoutNavKind {
162
+ Bar = 'bar',
163
+ Corner = 'corner',
164
+ Index = 'index',
165
+ Side = 'side',
166
+ }
167
+
168
+ export interface LayoutTrack {
169
+ prop: `${LayoutTrackProp}`;
170
+ from: number;
171
+ to: number;
172
+ /** The part of the section's scroll it plays over (0 = it arrives, 1 = it leaves; held: 0..1 is the hold). */
173
+ at: [number, number];
174
+ ease?: `${LayoutEase}`;
175
+ }
176
+
177
+ export interface LayoutGallery {
178
+ slides: Array<{ photo: { id: string }; caption?: string }>;
179
+ effect?: `${LayoutGalleryEffect}`;
180
+ perView?: number | 'auto';
181
+ centered?: boolean;
182
+ freeMode?: boolean;
183
+ loop?: boolean;
184
+ /** 0 or milliseconds. */
185
+ autoplay?: number;
186
+ /** Captions and pictures move at their own speed inside each slide (Swiper parallax). */
187
+ drift?: boolean;
188
+ /** Only in a held section: the page's scroll turns the slides. */
189
+ scroll?: boolean;
190
+ }
191
+
192
+ export interface LayoutForm {
193
+ preset: 'lead' | 'contact' | 'booking' | 'newsletter';
194
+ title?: string;
195
+ intro?: string;
196
+ /** The chips a preset has (lead: needs, budget; booking: guests), in the business's language. */
197
+ options?: Partial<Record<'needs' | 'budget' | 'guests', string[]>>;
198
+ submit?: string;
199
+ successTitle?: string;
200
+ successText?: string;
201
+ channel?: { label: string; href?: string };
202
+ }
203
+
204
+ export interface LayoutLayer {
205
+ kind: `${LayoutLayerKind}`;
206
+ role?: `${LayoutRole}`;
207
+ text?: string;
208
+ items?: string[];
209
+ photo?: { id: string };
210
+ gallery?: LayoutGallery;
211
+ form?: LayoutForm;
212
+ variant?: `${LayoutButtonVariant}`;
213
+ /** Grid lines: 1..13, or 1..12×track+1 in a sideways section. */
214
+ col: [number, number];
215
+ row: [number, number];
216
+ size?: `${LayoutSize}`;
217
+ color?: `${LayoutColour}`;
218
+ align?: `${LayoutAlign}`;
219
+ z?: number;
220
+ bleed?: `${LayoutBleed}`;
221
+ rotate?: number;
222
+ fit?: 'cover' | 'contain';
223
+ /** A button's section id. */
224
+ to?: string;
225
+ scrim?: boolean;
226
+ enter?: `${LayoutEnter}`;
227
+ from?: `${LayoutSide}`;
228
+ beat?: number;
229
+ depth?: `${LayoutDepth}`;
230
+ inner?: number;
231
+ kinetic?: boolean;
232
+ motion?: LayoutTrack[];
233
+ }
234
+
235
+ export interface LayoutSection {
236
+ id: string;
237
+ kind?: `${LayoutSectionKind}`;
238
+ signature?: boolean;
239
+ screens: number;
240
+ pin?: boolean;
241
+ track?: number;
242
+ /** A colour name, or `photo:<id>`. */
243
+ ground?: string;
244
+ rows: number;
245
+ transition?: `${LayoutTransition}`;
246
+ layers: LayoutLayer[];
247
+ /** Every layer's index once, in a phone's reading order. */
248
+ phone?: number[];
249
+ }
250
+
251
+ export interface LayoutSite {
252
+ name: string;
253
+ idea?: string;
254
+ locale?: string;
255
+ dial?: 'distinct' | 'daring';
256
+ /** CL2.1: `{ preset, seed? }`. A CL2 site carries a round-three `recipe` and colours (the runner maps it to a preset). */
257
+ look?: { preset?: string; seed?: string; recipe?: string; accent?: string };
258
+ motion?: { ease?: `${LayoutEase}`; pace?: `${LayoutPace}` };
259
+ nav?: { kind?: `${LayoutNavKind}`; links?: Array<{ label: string; to: string }> };
260
+ sections: LayoutSection[];
261
+ }
262
+
263
+ // ── The tables the composer reads (the prototype renderer v4's values, `code/renderer-round4.src.html`) ──────────────
264
+
265
+ /** A size as CSS — the prototype's `.s-*` rules. `screen` is computed per word (`screenFontSize`). */
266
+ export const LAYOUT_FONT_SIZE: Readonly<Record<Exclude<LayoutSize, LayoutSize.Screen>, string>> = {
267
+ [LayoutSize.Xs]: '12px',
268
+ [LayoutSize.S]: '15px',
269
+ [LayoutSize.M]: '19px',
270
+ [LayoutSize.L]: 'clamp(26px, 2.8vw, 44px)',
271
+ [LayoutSize.Xl]: 'clamp(38px, 5vw, 82px)',
272
+ [LayoutSize.Xxl]: 'clamp(54px, 8.5vw, 150px)',
273
+ };
274
+
275
+ /** A colour name as the look's token (what the prototype probed off the preset: `--iox-bg` … `--iox-text-muted`). */
276
+ export const LAYOUT_COLOUR_TOKEN: Readonly<Record<LayoutColour, string>> = {
277
+ [LayoutColour.Ground]: 'var(--iox-bg)',
278
+ [LayoutColour.Ink]: 'var(--iox-text)',
279
+ [LayoutColour.Accent]: 'var(--iox-accent)',
280
+ [LayoutColour.Soft]: 'var(--iox-surface-2)',
281
+ [LayoutColour.Muted]: 'var(--iox-text-muted)',
282
+ };
283
+ /** Words in the accent colour read the accent's text shade (round four: `accent-text`). */
284
+ export const LAYOUT_ACCENT_TEXT = 'var(--iox-accent-text)';
285
+
286
+ /** Emil's easing tokens (never ease-in). */
287
+ export const LAYOUT_EASING: Readonly<Record<LayoutEase, string>> = {
288
+ [LayoutEase.Out]: 'cubic-bezier(0.23, 1, 0.32, 1)',
289
+ [LayoutEase.InOut]: 'cubic-bezier(0.77, 0, 0.175, 1)',
290
+ [LayoutEase.Drawer]: 'cubic-bezier(0.32, 0.72, 0, 1)',
291
+ [LayoutEase.Linear]: 'linear',
292
+ };
293
+
294
+ /** How long an entrance takes, by the look's pace and the layer's role, and how far apart the beats are. */
295
+ export const LAYOUT_PACE: Readonly<Record<LayoutPace, { lead: number; support: number; decoration: number; gap: number }>> = {
296
+ [LayoutPace.Slow]: { lead: 1100, support: 900, decoration: 900, gap: 1.3 },
297
+ [LayoutPace.Normal]: { lead: 800, support: 650, decoration: 600, gap: 1 },
298
+ [LayoutPace.Quick]: { lead: 560, support: 460, decoration: 420, gap: 0.7 },
299
+ };
300
+ /** A stagger that shrinks as the beats go on, capped at the sixth — never a metronome. */
301
+ export const LAYOUT_BEAT_DELAY: ReadonlyArray<number> = [0, 120, 210, 275, 320, 350];
302
+ /** How far a rise travels, by role (px). */
303
+ export const LAYOUT_RISE: Readonly<Record<LayoutRole, number>> = {
304
+ [LayoutRole.Lead]: 44,
305
+ [LayoutRole.Support]: 22,
306
+ [LayoutRole.Decoration]: 0,
307
+ [LayoutRole.Static]: 0,
308
+ };
309
+
310
+ /** The kinds a visitor OPERATES: never moved for style (Emil gate 4). */
311
+ export const LAYOUT_OPERATED: ReadonlySet<string> = new Set([LayoutLayerKind.Gallery, LayoutLayerKind.Button, LayoutLayerKind.Form, LayoutLayerKind.Marquee]);
312
+ export const LAYOUT_TEXT_KINDS: ReadonlySet<string> = new Set([
313
+ LayoutLayerKind.Word, LayoutLayerKind.Heading, LayoutLayerKind.Text, LayoutLayerKind.Label, LayoutLayerKind.Number, LayoutLayerKind.List,
314
+ ]);
315
+
316
+ /** The grid's gutter and column gap (the prototype's `--gutter` and `.grid`). */
317
+ export const LAYOUT_GUTTER = 'max(4vw, 16px)';
318
+ export const LAYOUT_COLUMN_GAP = '1.2vw';
319
+ /** A depth's `params.phone`: scene-core `ParallaxPhone.Rest` — stacked on a phone, a layer never glides into its neighbour.
320
+ * Stamped verbatim and read where it plays (not imported, as `PatternTrack`); compose-layout.spec holds the two equal. */
321
+ export const LAYOUT_DEPTH_ON_PHONE = 'rest';
322
+
323
+ /** A control's tooltip words: the main entry's `A11yTrait.Tooltip` (premium M5), held equal by compose-layout.spec. */
324
+ export const LAYOUT_TOOLTIP_TRAIT = 'tooltip';
325
+
326
+ /** The phone: at or under this breakpoint a section stacks in its `phone` order (the `mobile` breakpoint, ≤ 767px). */
327
+ export const LAYOUT_PHONE_BREAKPOINT = 'mobile';
328
+ /** A phone section's padding above and below (M1.3: 56). */
329
+ export const LAYOUT_PHONE_PADDING = '56px';
330
+
331
+ /** The kind of layer, for the phone's rhythm: the space between two stacked layers says how they belong (M1.3). */
332
+ export function phoneGapBefore(prev: LayoutLayer | null, next: LayoutLayer): number {
333
+ if (!prev) return 0;
334
+ const k = (l: LayoutLayer) => l.kind;
335
+ if (k(prev) === LayoutLayerKind.Photo || k(prev) === LayoutLayerKind.Gallery || k(next) === LayoutLayerKind.Photo || k(next) === LayoutLayerKind.Gallery) return 32;
336
+ if (k(next) === LayoutLayerKind.Button || k(next) === LayoutLayerKind.Form) return 28;
337
+ if (k(prev) === LayoutLayerKind.Label || (k(prev) === LayoutLayerKind.Number && k(next) === LayoutLayerKind.Heading)) return 10;
338
+ if ((k(prev) === LayoutLayerKind.Heading && (k(next) === LayoutLayerKind.Text || k(next) === LayoutLayerKind.List)) || (k(prev) === LayoutLayerKind.Text && k(next) === LayoutLayerKind.Text)) return 14;
339
+ return 20;
340
+ }
341
+
342
+ /**
343
+ * A `screen` word's size: its letters fill its columns' width (a display face runs about `advance` em a letter) and
344
+ * never stand taller than its rows; never under 36px or over 560px (M8-G1: estimated, the product fits nothing in the
345
+ * browser). `rows` 0 sizes by width alone (a phone's stacked word). Held sections are one screen tall.
346
+ */
347
+ export function screenFontSize(text: string, cols: number, rows: number, sectionRows: number, screens: number, advance = 0.6): string {
348
+ const letters = Math.max(1, Array.from(String(text ?? '').trim()).length);
349
+ // The columns' share of the screen's width less its gutters (92vw for 12 columns), at 98% (the renderer's margin).
350
+ const widthVw = Math.round(((92 * (cols / 12)) / (letters * advance)) * 0.98 * 100) / 100;
351
+ if (!rows || !sectionRows) return `clamp(36px, ${widthVw}vw, 560px)`;
352
+ const heightSvh = Math.round((((rows / sectionRows) * screens * 100) / 0.92) * 0.98 * 100) / 100;
353
+ return `clamp(36px, min(${widthVw}vw, ${heightSvh}svh), 560px)`;
354
+ }
@@ -697,7 +697,11 @@ export const NODE_BASELINES: Readonly<Record<string, NodeBaseline>> = {
697
697
  "orientation",
698
698
  "ariaLabel",
699
699
  "headerBehaviour",
700
- "headerEdge"
700
+ "headerEdge",
701
+ "marqueeSpeed",
702
+ "marqueeDirection",
703
+ "marqueeFade",
704
+ "marqueePauseOnHover"
701
705
  ],
702
706
  "styleTraits": [
703
707
  "position",
@@ -39,3 +39,5 @@ export * from './stock-photos';
39
39
  export * from './film';
40
40
  export * from './art-direction';
41
41
  export * from './pictures';
42
+ export * from './layout-language';
43
+ export * from './compose-layout';
@@ -8,4 +8,5 @@ export * from './scene';
8
8
  export * from './scene-edit';
9
9
  export * from './scene-recipe';
10
10
  export * from './scroll-driver';
11
+ export * from './scroll-range';
11
12
  export * from './split-text';
@@ -2,6 +2,7 @@ import { SceneRole } from '@vectoriox/iox-ui/composite-core';
2
2
  import { FramePlayer, normalizeFrameSequence, VideoAttribute } from '@vectoriox/iox-ui/media-core';
3
3
 
4
4
  import { heldProgress, normalizeTracks, SCENE_PHONE_MAX_WIDTH, SceneAttribute, sceneFrame, SceneFrame, scenePlayed, sceneWordOpacity, sceneWordsLit, SceneTrack } from './scene';
5
+ import { rangeDistance, rangeProgress, ScrollBox, ScrollRange } from './scroll-range';
5
6
  import { LIGHT_UP_PIECE_CAP, SplitText, splitText } from './split-text';
6
7
 
7
8
  /**
@@ -72,10 +73,64 @@ export interface ScrollDriverOptions {
72
73
  damping?: number;
73
74
  /** Called after every frame it writes, outside any framework's zone (the canvas's selection box follows on it). */
74
75
  onFrame?: (root: HTMLElement, state: SceneFrameState) => void;
76
+ /** The part of the screen the page is seen through, when that is not the window (the canvas's scroller). Links only. */
77
+ view?: () => ScrollBox | null;
75
78
  /** The window, for a test. */
76
79
  host?: Window;
77
80
  }
78
81
 
82
+ /**
83
+ * A SCROLL LINK (premium components M6, N7): something outside a Scene that follows where an element stands in the page —
84
+ * a scrubbed entrance, a parallax depth, a reading bar. It rides this same loop: read with every Scene, damped the same
85
+ * way, written in the same write phase. Never a second loop per element.
86
+ */
87
+ export interface ScrollLink {
88
+ /** What is measured: the element for a view range, the page for `ScrollRange.Page`. */
89
+ measured: HTMLElement;
90
+ range: ScrollRange;
91
+ /** Written in the write phase with the damped progress (0–1). Compositor properties only. */
92
+ write(progress: number, geometry: ScrollLinkGeometry): void;
93
+ /** Follow the scroll exactly, with no glide (reduced motion). */
94
+ immediate?: boolean;
95
+ /** The page the measured element stands in: its layout is measured inside it (`layoutBoxOnScreen`). */
96
+ within?: HTMLElement | null;
97
+ }
98
+
99
+ /** A link's geometry this frame, in the PAGE's px (the canvas's zoom undone). */
100
+ export interface ScrollLinkGeometry {
101
+ /** How far the scroll travels through the range. */
102
+ distance: number;
103
+ /** The height of the part of the page on screen. */
104
+ viewHeight: number;
105
+ }
106
+
107
+ interface LinkState {
108
+ link: ScrollLink;
109
+ progress: number;
110
+ target: number;
111
+ fresh: boolean;
112
+ geometry: ScrollLinkGeometry;
113
+ }
114
+
115
+ /**
116
+ * Where an element's LAYOUT box stands on screen: its offsets up to the nearest box that has no offset parent, placed by
117
+ * that box's own rectangle. Transforms on the element itself are not in it — a layer that glides is measured where it
118
+ * stands in the flow, so what it is moved by never feeds back into how far it is moved. `zoom` undoes the canvas's scale.
119
+ */
120
+ export function layoutBoxOnScreen(el: HTMLElement, within: HTMLElement | null = null): { box: ScrollBox; zoom: number } {
121
+ let offset = 0;
122
+ let ref: HTMLElement = el;
123
+ // Never past `within` (the page): offsets inside the canvas's zoomed frame are its own px, and the box that places them
124
+ // must be drawn at the same zoom.
125
+ while (ref.offsetParent instanceof HTMLElement && (!within || within.contains(ref.offsetParent))) {
126
+ offset += ref.offsetTop;
127
+ ref = ref.offsetParent;
128
+ }
129
+ const rect = ref.getBoundingClientRect();
130
+ const zoom = ref.offsetHeight > 0 && rect.height > 0 ? rect.height / ref.offsetHeight : 1;
131
+ return { box: { top: rect.top + offset * zoom, height: el.offsetHeight * zoom }, zoom };
132
+ }
133
+
79
134
  export interface SceneFrameState {
80
135
  /** Where the scroll stands, undamped: what a scrubber shows. */
81
136
  target: number;
@@ -125,6 +180,7 @@ function parseTracks(raw: string | null): SceneTrack[] {
125
180
 
126
181
  export class ScrollDriver {
127
182
  private readonly scenes = new Map<HTMLElement, Scene>();
183
+ private readonly links = new Set<LinkState>();
128
184
  private readonly host: Window;
129
185
  private readonly resize: ResizeObserver | null;
130
186
  private frame = 0;
@@ -228,6 +284,22 @@ export class ScrollDriver {
228
284
  }
229
285
  }
230
286
 
287
+ /**
288
+ * Follow where `link.measured` stands, on this loop. Returns the way to let go. A link that is added lands on its first
289
+ * frame exactly where the scroll is, with no glide.
290
+ */
291
+ addLink(link: ScrollLink): () => void {
292
+ const state: LinkState = { link, progress: 0, target: 0, fresh: true, geometry: { distance: 0, viewHeight: 0 } };
293
+ this.links.add(state);
294
+ this.wake();
295
+ return () => { this.links.delete(state); };
296
+ }
297
+
298
+ /** True while it plays anything: a Scene or a link. */
299
+ get busy(): boolean {
300
+ return this.scenes.size > 0 || this.links.size > 0;
301
+ }
302
+
231
303
  /** Something moved that no scroll or resize announces (the canvas's zoom). */
232
304
  wake(): void {
233
305
  if (this.frame) return;
@@ -241,6 +313,7 @@ export class ScrollDriver {
241
313
  this.host.removeEventListener('resize', this.wakeUp);
242
314
  this.host.removeEventListener(SCENE_WAKE_EVENT, this.onWakeEvent, { capture: true });
243
315
  for (const root of [...this.scenes.keys()]) this.remove(root);
316
+ this.links.clear();
244
317
  this.resize?.disconnect();
245
318
  }
246
319
 
@@ -305,6 +378,8 @@ export class ScrollDriver {
305
378
  const seconds = this.lastTime ? Math.min(MAX_FRAME_SECONDS, (now - this.lastTime) / 1000) : WAKING_FRAME_SECONDS;
306
379
  this.lastTime = now;
307
380
  const reads = [...this.scenes.values()].map(scene => this.read(scene));
381
+ const view = this.links.size ? this.viewBox() : null;
382
+ const linkReads = [...this.links].map(state => this.readLink(state, view!));
308
383
  let moving = false;
309
384
  for (const { scene, local, target } of reads) {
310
385
  if (this.options.pin && scene.stage) scene.stage.style.setProperty('translate', `0 ${local}px`);
@@ -318,10 +393,33 @@ export class ScrollDriver {
318
393
  this.options.onFrame?.(scene.root, { target, progress: scene.progress });
319
394
  moving = moving || !settled;
320
395
  }
396
+ for (const { state, target } of linkReads) {
397
+ const immediate = state.fresh || !!state.link.immediate;
398
+ const next = immediate ? target : dampToward(state.progress, target, seconds, this.options.damping);
399
+ const settled = immediate || Math.abs(target - state.progress) * Math.max(1, state.geometry.distance) < SETTLED_PX;
400
+ state.progress = settled ? target : next;
401
+ state.target = target;
402
+ state.fresh = false;
403
+ state.link.write(state.progress, state.geometry);
404
+ moving = moving || !settled;
405
+ }
321
406
  if (moving) this.wake();
322
407
  else this.lastTime = 0;
323
408
  };
324
409
 
410
+ /** The part of the page on screen: the host's own, or the window. */
411
+ private viewBox(): ScrollBox {
412
+ return this.options.view?.() ?? { top: 0, height: this.host.innerHeight };
413
+ }
414
+
415
+ private readLink(state: LinkState, view: ScrollBox): { state: LinkState; target: number } {
416
+ const { box, zoom } = layoutBoxOnScreen(state.link.measured, state.link.within ?? null);
417
+ const z = zoom || 1;
418
+ const target = rangeProgress(state.link.range, box, view);
419
+ state.geometry = { distance: rangeDistance(state.link.range, box, view) / z, viewHeight: view.height / z };
420
+ return { state, target };
421
+ }
422
+
325
423
  private read(scene: Scene): { scene: Scene; local: number; target: number } {
326
424
  const rect = scene.root.getBoundingClientRect();
327
425
  const origin = this.options.originOf?.(scene.root)?.getBoundingClientRect().top ?? 0;