@vectoriox/iox-ui 5.68.0 → 5.70.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.
@@ -0,0 +1,232 @@
1
+ import { SceneRole } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ /**
4
+ * A Scene's data and maths (premium-sites plan §5b). A Scene is a recipe of ordinary nodes — a tall Section, a pinned
5
+ * stage inside it, ordinary nodes as layers — so every word stays real, bound and translatable, and all three render
6
+ * paths already draw it. What moves a layer is its OWN `sceneTracks`, never a list on the root naming layer ids: a clone
7
+ * copies them with the layer, a delete takes them with it, and there is no id to remap.
8
+ *
9
+ * The vocabulary is closed. Every property is one the compositor can run without layout (CLS stays 0): a saved value
10
+ * outside it is dropped when read, so a page document can never write CSS through a track.
11
+ */
12
+
13
+ export enum SceneProp {
14
+ /** Along the inline axis, in % of the stage's width. Positive runs toward the inline END (mirrored in RTL). */
15
+ X = 'x',
16
+ /** Down, in % of the stage's height. */
17
+ Y = 'y',
18
+ Scale = 'scale',
19
+ /** Degrees. */
20
+ Rotate = 'rotate',
21
+ /** 0–1. */
22
+ Opacity = 'opacity',
23
+ /** Inset from every side, in % of the layer (0 = whole, 50 = gone). */
24
+ Clip = 'clip',
25
+ /** The layer's background colour. */
26
+ Ground = 'ground',
27
+ /** The layer's text colour. */
28
+ Ink = 'ink',
29
+ }
30
+
31
+ /** One key: at progress `[0]` (0–1) the property holds `[1]`: a number, or a colour for Ground and Ink. */
32
+ export type SceneKey = readonly [number, number | string];
33
+
34
+ export interface SceneTrack {
35
+ prop: SceneProp;
36
+ /** Ascending by progress. Between two keys the value eases (smoothstep); outside them it holds the nearest. */
37
+ keys: ReadonlyArray<SceneKey>;
38
+ }
39
+
40
+ /** What a node carries (both a builder node and a saved one). */
41
+ export interface SceneNodeSource {
42
+ role?: string | null;
43
+ /** How this layer moves, from the wide layout down to the phone's. */
44
+ sceneTracks?: ReadonlyArray<SceneTrack> | null;
45
+ /** How it moves at phone width instead (`SCENE_PHONE_MAX_WIDTH`). Absent = the same tracks. */
46
+ scenePhoneTracks?: ReadonlyArray<SceneTrack> | null;
47
+ }
48
+
49
+ /** A frame as inline-style properties (camelCase, as `CSSStyleDeclaration` and `Object.assign` take them). */
50
+ export interface SceneFrame {
51
+ transform?: string;
52
+ opacity?: string;
53
+ clipPath?: string;
54
+ backgroundColor?: string;
55
+ color?: string;
56
+ }
57
+
58
+ export enum SceneAttribute {
59
+ Root = 'data-iox-scene',
60
+ Tracks = 'data-iox-tracks',
61
+ PhoneTracks = 'data-iox-tracks-phone',
62
+ }
63
+
64
+ /** At or under this stage width a layer plays its phone tracks. The `mobile` breakpoint's width. */
65
+ export const SCENE_PHONE_MAX_WIDTH = 767;
66
+
67
+ const DECIMALS = 10000;
68
+ const round = (v: number): number => Math.round(v * DECIMALS) / DECIMALS;
69
+ const clamp01 = (v: number): number => Math.min(1, Math.max(0, v));
70
+ const smoothstep = (t: number): number => t * t * (3 - 2 * t);
71
+
72
+ /** A colour a track may hold: a hex, an rgb()/hsl() literal, or a design token. Anything else could break out of the
73
+ * inline style it lands in. */
74
+ const COLOUR = /^(#[0-9a-f]{3,8}|(rgb|hsl)a?\([\d\s.,%/]+\)|var\(--iox-[\w-]+\))$/i;
75
+ const COLOUR_PROPS: ReadonlySet<SceneProp> = new Set([SceneProp.Ground, SceneProp.Ink]);
76
+ const ALL_PROPS: ReadonlySet<string> = new Set(Object.values(SceneProp));
77
+
78
+ function validKey(key: unknown, colour: boolean): key is SceneKey {
79
+ if (!Array.isArray(key) || key.length !== 2) return false;
80
+ const [p, value] = key;
81
+ if (typeof p !== 'number' || !Number.isFinite(p) || p < 0 || p > 1) return false;
82
+ return colour ? typeof value === 'string' && COLOUR.test(value) : typeof value === 'number' && Number.isFinite(value);
83
+ }
84
+
85
+ /**
86
+ * The tracks a saved value really holds: unknown properties, bad keys and colours that are not colours are dropped,
87
+ * keys sorted by progress, a track left with no key dropped. Never throws on what a page document holds.
88
+ */
89
+ export function normalizeTracks(tracks: unknown): SceneTrack[] {
90
+ if (!Array.isArray(tracks)) return [];
91
+ const out: SceneTrack[] = [];
92
+ for (const track of tracks) {
93
+ const prop = (track as SceneTrack | null)?.prop;
94
+ if (!prop || !ALL_PROPS.has(prop) || !Array.isArray((track as SceneTrack).keys)) continue;
95
+ const keys = (track as SceneTrack).keys
96
+ .filter(key => validKey(key, COLOUR_PROPS.has(prop)))
97
+ .slice()
98
+ .sort((a, b) => a[0] - b[0]);
99
+ if (keys.length) out.push({ prop, keys });
100
+ }
101
+ return out;
102
+ }
103
+
104
+ /** The two keys around `p` and how far between them it eases. */
105
+ function span(keys: ReadonlyArray<SceneKey>, p: number): { a: SceneKey; b: SceneKey; f: number } {
106
+ const at = clamp01(p);
107
+ if (at <= keys[0][0]) return { a: keys[0], b: keys[0], f: 0 };
108
+ for (let i = 1; i < keys.length; i++) {
109
+ if (at <= keys[i][0]) {
110
+ const a = keys[i - 1];
111
+ const b = keys[i];
112
+ const width = b[0] - a[0];
113
+ return { a, b, f: width > 0 ? smoothstep((at - a[0]) / width) : 1 };
114
+ }
115
+ }
116
+ const last = keys[keys.length - 1];
117
+ return { a: last, b: last, f: 0 };
118
+ }
119
+
120
+ /** A numeric track's value at progress `p`. */
121
+ export function valueAt(keys: ReadonlyArray<SceneKey>, p: number): number {
122
+ if (!keys.length) return 0;
123
+ const { a, b, f } = span(keys, p);
124
+ const from = Number(a[1]);
125
+ return round(from + (Number(b[1]) - from) * f);
126
+ }
127
+
128
+ /**
129
+ * A colour track's value at progress `p`. Mixed by the browser, never computed here, so a design token stays a live
130
+ * reference (a re-theme reaches a Scene, as it reaches every saved page) and the path is perceptual.
131
+ */
132
+ export function colourAt(keys: ReadonlyArray<SceneKey>, p: number): string {
133
+ if (!keys.length) return '';
134
+ const { a, b, f } = span(keys, p);
135
+ if (f <= 0 || a === b) return String(a[1]);
136
+ if (f >= 1) return String(b[1]);
137
+ return `color-mix(in oklab, ${a[1]} ${round((1 - f) * 100)}%, ${b[1]})`;
138
+ }
139
+
140
+ export interface SceneFrameOptions {
141
+ /** -1 when the stage reads right-to-left: the inline axis mirrors. */
142
+ inlineSign?: 1 | -1;
143
+ }
144
+
145
+ /** What the tracks' transform-family properties rest at when a layer has no track for one. */
146
+ const TRANSFORM_REST: Readonly<Partial<Record<SceneProp, number>>> = { [SceneProp.X]: 0, [SceneProp.Y]: 0, [SceneProp.Scale]: 1, [SceneProp.Rotate]: 0 };
147
+
148
+ /**
149
+ * A layer's frame at progress `p`. Lengths are container-query units, so one frame is right at any width, under any
150
+ * canvas zoom, on the server and with no measuring: the stage is the size container (`iox-design.css`).
151
+ */
152
+ export function sceneFrame(tracks: ReadonlyArray<SceneTrack>, p: number, options: SceneFrameOptions = {}): SceneFrame {
153
+ const frame: SceneFrame = {};
154
+ const moves: Partial<Record<SceneProp, number>> = {};
155
+ for (const { prop, keys } of tracks) {
156
+ if (prop in TRANSFORM_REST) moves[prop] = valueAt(keys, p);
157
+ else if (prop === SceneProp.Opacity) frame.opacity = String(clamp01(valueAt(keys, p)));
158
+ else if (prop === SceneProp.Clip) frame.clipPath = `inset(${Math.min(50, Math.max(0, valueAt(keys, p)))}%)`;
159
+ else if (prop === SceneProp.Ground) frame.backgroundColor = colourAt(keys, p);
160
+ else if (prop === SceneProp.Ink) frame.color = colourAt(keys, p);
161
+ }
162
+ if (Object.keys(moves).length) {
163
+ const value = (prop: SceneProp): number => moves[prop] ?? TRANSFORM_REST[prop]!;
164
+ const x = round(value(SceneProp.X) * (options.inlineSign ?? 1));
165
+ frame.transform = `translate3d(${x}cqw, ${value(SceneProp.Y)}cqh, 0) rotate(${value(SceneProp.Rotate)}deg) scale(${value(SceneProp.Scale)})`;
166
+ }
167
+ return frame;
168
+ }
169
+
170
+ const CSS_NAME: Readonly<Record<keyof SceneFrame, string>> = {
171
+ transform: 'transform',
172
+ opacity: 'opacity',
173
+ clipPath: 'clip-path',
174
+ backgroundColor: 'background-color',
175
+ color: 'color',
176
+ };
177
+
178
+ /** A frame as kebab-case style declarations, for a string renderer. */
179
+ export function sceneFrameDeclarations(frame: SceneFrame): Record<string, string> {
180
+ const out: Record<string, string> = {};
181
+ for (const [key, value] of Object.entries(frame)) if (value) out[CSS_NAME[key as keyof SceneFrame]] = value;
182
+ return out;
183
+ }
184
+
185
+ /** The attributes a node's own element carries — the same decision in all three render paths. The runtime reads them,
186
+ * so it needs no node tree and is the same on every path. Empty for any node that is no part of a Scene. */
187
+ export function sceneNodeAttributes(node: SceneNodeSource | null | undefined): Record<string, string> {
188
+ const attrs: Record<string, string> = {};
189
+ if (node?.role === SceneRole.Scene) attrs[SceneAttribute.Root] = '';
190
+ const tracks = normalizeTracks(node?.sceneTracks);
191
+ const phone = normalizeTracks(node?.scenePhoneTracks);
192
+ if (tracks.length) attrs[SceneAttribute.Tracks] = JSON.stringify(tracks);
193
+ if (phone.length) attrs[SceneAttribute.PhoneTracks] = JSON.stringify(phone);
194
+ return attrs;
195
+ }
196
+
197
+ /** The frame a layer ships in from the server: where it stands before anyone has scrolled. Without it the page would
198
+ * paint every layer at once, and then jump when the script arrives. */
199
+ export function sceneFirstFrame(node: SceneNodeSource | null | undefined): SceneFrame {
200
+ return sceneFrame(normalizeTracks(node?.sceneTracks), 0);
201
+ }
202
+
203
+ /**
204
+ * Make an element carry its node's Scene attributes: the live sync on the canvas and the component path's stamp.
205
+ * Removes stale ones, touches nothing else.
206
+ */
207
+ export function syncSceneAttributes(el: HTMLElement | null | undefined, node: SceneNodeSource | null | undefined): void {
208
+ if (!el?.setAttribute) return;
209
+ const attrs = sceneNodeAttributes(node);
210
+ for (const name of Object.values(SceneAttribute)) {
211
+ if (name in attrs) el.setAttribute(name, attrs[name]);
212
+ else el.removeAttribute(name);
213
+ }
214
+ }
215
+
216
+ /** Stamp a layer's first frame on its element (the component path, on the server too). */
217
+ export function applySceneFirstFrame(el: HTMLElement | null | undefined, node: SceneNodeSource | null | undefined): void {
218
+ if (!el?.style) return;
219
+ for (const [name, value] of Object.entries(sceneFrameDeclarations(sceneFirstFrame(node)))) el.style.setProperty(name, value);
220
+ }
221
+
222
+ /**
223
+ * Where nothing will drive it (reduced motion, no script) a Scene is ordinary content: it flows, every layer in its
224
+ * place and in its own look, every word readable. `!important` because it must beat a node's compiled height and
225
+ * position, and the inline first frame. The engine wraps it in a reduced-motion query and in `<noscript>`.
226
+ */
227
+ export const SCENE_FLOW_RULES = `.iox-role-scene{height:auto!important}`
228
+ + `.iox-role-scene-stage{position:relative!important;top:auto!important;height:auto!important;overflow:visible!important;container-type:normal!important}`
229
+ + `[${SceneAttribute.Tracks}]{transform:none!important;opacity:1!important;clip-path:none!important}`;
230
+
231
+ /** Under reduced motion the driver never starts, so the same rules hold for the whole visit. */
232
+ export const SCENE_REDUCED_MOTION_CSS = `@media (prefers-reduced-motion: reduce){${SCENE_FLOW_RULES}}`;
@@ -0,0 +1,220 @@
1
+ import { SceneRole } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ import { normalizeTracks, SCENE_PHONE_MAX_WIDTH, SceneAttribute, sceneFrame, SceneFrame, SceneTrack } from './scene';
4
+
5
+ /**
6
+ * The ONE scroll loop (premium-sites plan §5b, SC0). Every Scene on a page reads one progress value from it, on the
7
+ * canvas and on the live site alike. It reads where the root is and nothing else, so it has one code path: under the
8
+ * canvas's zoom the same rectangle divides by the same zoom, and the answer is the same at any scale.
9
+ *
10
+ * - The value is DAMPED: the scroll stops and the page settles a moment later. This is much of the prototype's weight,
11
+ * and why this is not a CSS scroll timeline, which cannot do it.
12
+ * - The live site pins with `position: sticky`, on the compositor. The canvas cannot (its page never scrolls itself,
13
+ * its Lenis scrolls a wrapper around a zoomed frame), so `pin` holds the stage there with `translate` instead.
14
+ * `translate`, not `transform`: a Stage may carry tracks of its own.
15
+ * - It sleeps. No frame is asked for unless something moved, so a page holding a settled Scene costs nothing.
16
+ * - Reads come first in a frame and writes after, and a write only ever touches compositor properties.
17
+ */
18
+
19
+ export const SCENE_DAMPING = 9;
20
+ const SETTLED = 0.0005;
21
+ const MAX_FRAME_SECONDS = 0.1;
22
+ /** The first frame after a sleep has no previous one to measure from: it counts as one frame, or a scroll would lose it. */
23
+ const WAKING_FRAME_SECONDS = 1 / 60;
24
+ const STAGE_SELECTOR = `.iox-role-${SceneRole.Stage.replace(/\./g, '-')}`;
25
+ const TRANSFORM_WILL_CHANGE = 'transform, opacity';
26
+
27
+ /** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
28
+ export function dampToward(current: number, target: number, seconds: number, rate: number = SCENE_DAMPING): number {
29
+ return current + (target - current) * (1 - Math.exp(-seconds * rate));
30
+ }
31
+
32
+ /** Where a root stands: scrolled `local` page px into its `travel`. `zoom` undoes the canvas's scale. */
33
+ export function sceneScrollState(rootTop: number, originTop: number, zoom: number, travel: number): { local: number; progress: number } {
34
+ if (travel <= 0) return { local: 0, progress: 0 };
35
+ const local = Math.min(travel, Math.max(0, -(rootTop - originTop) / (zoom || 1)));
36
+ return { local, progress: local / travel };
37
+ }
38
+
39
+ export interface ScrollDriverOptions {
40
+ /** Hold the stage with `translate` (the canvas). The live site's stage is sticky and needs nothing. */
41
+ pin?: boolean;
42
+ /** The element a root scrolls under, when that is not the window (the canvas's frame, Preview's page). */
43
+ originOf?: (root: HTMLElement) => HTMLElement | null;
44
+ /** Follow what changes inside a root: tracks edited, layers added (the canvas). */
45
+ observe?: boolean;
46
+ damping?: number;
47
+ /** The window, for a test. */
48
+ host?: Window;
49
+ }
50
+
51
+ interface Layer {
52
+ el: HTMLElement;
53
+ tracks: SceneTrack[];
54
+ phoneTracks: SceneTrack[];
55
+ last: SceneFrame;
56
+ }
57
+
58
+ interface Scene {
59
+ root: HTMLElement;
60
+ stage: HTMLElement | null;
61
+ layers: Layer[];
62
+ progress: number;
63
+ /** Page px and the stage's own width, measured when something resizes and never per frame. */
64
+ height: number;
65
+ travel: number;
66
+ phone: boolean;
67
+ inlineSign: 1 | -1;
68
+ /** No frame written yet: the first one lands exactly where the scroll is, with no glide. */
69
+ fresh: boolean;
70
+ mutations: MutationObserver | null;
71
+ }
72
+
73
+ function parseTracks(raw: string | null): SceneTrack[] {
74
+ if (!raw) return [];
75
+ try { return normalizeTracks(JSON.parse(raw)); } catch { return []; }
76
+ }
77
+
78
+ export class ScrollDriver {
79
+ private readonly scenes = new Map<HTMLElement, Scene>();
80
+ private readonly host: Window;
81
+ private readonly resize: ResizeObserver | null;
82
+ private frame = 0;
83
+ private lastTime = 0;
84
+ private readonly wakeUp = (): void => this.wake();
85
+
86
+ constructor(private readonly options: ScrollDriverOptions = {}) {
87
+ this.host = options.host ?? window;
88
+ // In capture: a scroll does not bubble, and the canvas's Lenis scrolls an element, not the window.
89
+ this.host.addEventListener('scroll', this.wakeUp, { capture: true, passive: true });
90
+ this.host.addEventListener('resize', this.wakeUp, { passive: true });
91
+ const Observer = (this.host as Window & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;
92
+ this.resize = Observer ? new Observer(() => this.remeasureAll()) : null;
93
+ }
94
+
95
+ /** Drive a Scene's root. Idempotent: adding a root again re-reads it. */
96
+ add(root: HTMLElement): void {
97
+ this.remove(root);
98
+ const scene: Scene = { root, stage: null, layers: [], progress: 0, height: 0, travel: 0, phone: false, inlineSign: 1, fresh: true, mutations: null };
99
+ this.scenes.set(root, scene);
100
+ this.resize?.observe(root);
101
+ if (this.options.observe) {
102
+ const Observer = (this.host as Window & { MutationObserver?: typeof MutationObserver }).MutationObserver;
103
+ if (Observer) {
104
+ scene.mutations = new Observer(() => this.reread(scene));
105
+ scene.mutations.observe(root, { childList: true, subtree: true, attributes: true, attributeFilter: [SceneAttribute.Tracks, SceneAttribute.PhoneTracks] });
106
+ }
107
+ }
108
+ this.reread(scene);
109
+ }
110
+
111
+ remove(root: HTMLElement): void {
112
+ const scene = this.scenes.get(root);
113
+ if (!scene) return;
114
+ scene.mutations?.disconnect();
115
+ this.resize?.unobserve(root);
116
+ if (scene.stage) scene.stage.style.removeProperty('translate');
117
+ for (const layer of scene.layers) layer.el.style.removeProperty('will-change');
118
+ this.scenes.delete(root);
119
+ }
120
+
121
+ /** The damped progress a root's layers stand at. */
122
+ progressOf(root: HTMLElement): number | null {
123
+ return this.scenes.get(root)?.progress ?? null;
124
+ }
125
+
126
+ /** Something moved that no scroll or resize announces (the canvas's zoom). */
127
+ wake(): void {
128
+ if (this.frame) return;
129
+ this.frame = this.host.requestAnimationFrame(this.tick);
130
+ }
131
+
132
+ destroy(): void {
133
+ if (this.frame) this.host.cancelAnimationFrame(this.frame);
134
+ this.frame = 0;
135
+ this.host.removeEventListener('scroll', this.wakeUp, { capture: true });
136
+ this.host.removeEventListener('resize', this.wakeUp);
137
+ for (const root of [...this.scenes.keys()]) this.remove(root);
138
+ this.resize?.disconnect();
139
+ }
140
+
141
+ /** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
142
+ private reread(scene: Scene): void {
143
+ scene.stage = scene.root.querySelector<HTMLElement>(STAGE_SELECTOR);
144
+ scene.layers = Array.from(scene.root.querySelectorAll<HTMLElement>(`[${SceneAttribute.Tracks}], [${SceneAttribute.PhoneTracks}]`))
145
+ .filter(el => el === scene.root || el.parentElement?.closest(`[${SceneAttribute.Root}]`) === scene.root)
146
+ .map(el => this.readLayer(el, scene));
147
+ this.measure(scene);
148
+ scene.fresh = true;
149
+ this.wake();
150
+ }
151
+
152
+ private readLayer(el: HTMLElement, scene: Scene): Layer {
153
+ const previous = scene.layers.find(layer => layer.el === el);
154
+ el.style.setProperty('will-change', TRANSFORM_WILL_CHANGE);
155
+ return { el, tracks: parseTracks(el.getAttribute(SceneAttribute.Tracks)), phoneTracks: parseTracks(el.getAttribute(SceneAttribute.PhoneTracks)), last: previous?.last ?? {} };
156
+ }
157
+
158
+ private remeasureAll(): void {
159
+ for (const scene of this.scenes.values()) this.measure(scene);
160
+ this.wake();
161
+ }
162
+
163
+ private measure(scene: Scene): void {
164
+ scene.height = scene.root.offsetHeight;
165
+ scene.travel = Math.max(0, scene.height - (scene.stage?.offsetHeight ?? scene.height));
166
+ scene.phone = (scene.stage?.offsetWidth ?? Infinity) <= SCENE_PHONE_MAX_WIDTH;
167
+ scene.inlineSign = scene.stage && this.host.getComputedStyle(scene.stage).direction === 'rtl' ? -1 : 1;
168
+ for (const layer of scene.layers) layer.last = {};
169
+ }
170
+
171
+ private readonly tick = (now: number): void => {
172
+ this.frame = 0;
173
+ const seconds = this.lastTime ? Math.min(MAX_FRAME_SECONDS, (now - this.lastTime) / 1000) : WAKING_FRAME_SECONDS;
174
+ this.lastTime = now;
175
+ const reads = [...this.scenes.values()].map(scene => this.read(scene));
176
+ let moving = false;
177
+ for (const { scene, local, target } of reads) {
178
+ if (this.options.pin && scene.stage) scene.stage.style.setProperty('translate', `0 ${local}px`);
179
+ const next = scene.fresh ? target : dampToward(scene.progress, target, seconds, this.options.damping);
180
+ const settled = Math.abs(next - target) < SETTLED;
181
+ scene.progress = settled ? target : next;
182
+ scene.fresh = false;
183
+ this.write(scene);
184
+ moving = moving || !settled;
185
+ }
186
+ if (moving) this.wake();
187
+ else this.lastTime = 0;
188
+ };
189
+
190
+ private read(scene: Scene): { scene: Scene; local: number; target: number } {
191
+ const rect = scene.root.getBoundingClientRect();
192
+ const origin = this.options.originOf?.(scene.root)?.getBoundingClientRect().top ?? 0;
193
+ const zoom = scene.height ? rect.height / scene.height : 1;
194
+ const { local, progress } = sceneScrollState(rect.top, origin, zoom, scene.travel);
195
+ return { scene, local, target: progress };
196
+ }
197
+
198
+ private write(scene: Scene): void {
199
+ for (const layer of scene.layers) {
200
+ const tracks = scene.phone && layer.phoneTracks.length ? layer.phoneTracks : layer.tracks;
201
+ const frame = sceneFrame(tracks, scene.progress, { inlineSign: scene.inlineSign });
202
+ for (const key of Object.keys(frame) as (keyof SceneFrame)[]) {
203
+ if (frame[key] !== layer.last[key]) layer.el.style[key] = frame[key]!;
204
+ }
205
+ layer.last = frame;
206
+ }
207
+ }
208
+ }
209
+
210
+ /** A page's Scenes, driven by one driver; null when it holds none, or when the visitor asked for less motion (the
211
+ * page's own CSS then lets each Scene flow). The live site's door. */
212
+ export function attachScenes(container: HTMLElement, options: ScrollDriverOptions = {}): ScrollDriver | null {
213
+ const roots = container.querySelectorAll<HTMLElement>(`[${SceneAttribute.Root}]`);
214
+ if (!roots.length) return null;
215
+ const host = options.host ?? window;
216
+ if (host.matchMedia?.('(prefers-reduced-motion: reduce)').matches) return null;
217
+ const driver = new ScrollDriver(options);
218
+ roots.forEach(root => driver.add(root));
219
+ return driver;
220
+ }
@@ -67,6 +67,13 @@ iox-gallery.iox-es-media[data-iox-empty] > .iox-gallery {
67
67
  --iox-button-ghost-ink: currentColor;
68
68
  }
69
69
 
70
+ /* ── Scene (premium-sites plan §5b) ───────────────────────────────────────────────────────────────
71
+ The stage is the size container its layers' tracks measure against (`cqw` / `cqh`, scene-core), so one frame is
72
+ right at any width and under any canvas zoom, with no measuring. Its pin, size and clip are the node's own styles. */
73
+ .iox-role-scene-stage {
74
+ container-type: size;
75
+ }
76
+
70
77
  /* ── Card v2 (composite T23; complex-components board 8) ──────────────────────────────────────────
71
78
  The parts are ordinary nodes; `nodeDesignClasses` writes `iox-role-<role>` on each, so these rules are
72
79
  the same in every renderer. Zero-specificity where an author's own value must win. */