@vectoriox/iox-ui 5.69.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "5.69.0",
3
+ "version": "5.70.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -55,6 +55,10 @@
55
55
  "types": "./media-core/index.d.ts",
56
56
  "default": "./fesm2022/vectoriox-iox-ui-media-core.mjs"
57
57
  },
58
+ "./scene-core": {
59
+ "types": "./scene-core/index.d.ts",
60
+ "default": "./fesm2022/vectoriox-iox-ui-scene-core.mjs"
61
+ },
58
62
  "./seo-core": {
59
63
  "types": "./seo-core/index.d.ts",
60
64
  "default": "./fesm2022/vectoriox-iox-ui-seo-core.mjs"
@@ -0,0 +1,193 @@
1
+ import { CompositeNode, CompositeNodeFactory } 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
+ declare enum SceneProp {
13
+ /** Along the inline axis, in % of the stage's width. Positive runs toward the inline END (mirrored in RTL). */
14
+ X = "x",
15
+ /** Down, in % of the stage's height. */
16
+ Y = "y",
17
+ Scale = "scale",
18
+ /** Degrees. */
19
+ Rotate = "rotate",
20
+ /** 0–1. */
21
+ Opacity = "opacity",
22
+ /** Inset from every side, in % of the layer (0 = whole, 50 = gone). */
23
+ Clip = "clip",
24
+ /** The layer's background colour. */
25
+ Ground = "ground",
26
+ /** The layer's text colour. */
27
+ Ink = "ink"
28
+ }
29
+ /** One key: at progress `[0]` (0–1) the property holds `[1]`: a number, or a colour for Ground and Ink. */
30
+ type SceneKey = readonly [number, number | string];
31
+ interface SceneTrack {
32
+ prop: SceneProp;
33
+ /** Ascending by progress. Between two keys the value eases (smoothstep); outside them it holds the nearest. */
34
+ keys: ReadonlyArray<SceneKey>;
35
+ }
36
+ /** What a node carries (both a builder node and a saved one). */
37
+ interface SceneNodeSource {
38
+ role?: string | null;
39
+ /** How this layer moves, from the wide layout down to the phone's. */
40
+ sceneTracks?: ReadonlyArray<SceneTrack> | null;
41
+ /** How it moves at phone width instead (`SCENE_PHONE_MAX_WIDTH`). Absent = the same tracks. */
42
+ scenePhoneTracks?: ReadonlyArray<SceneTrack> | null;
43
+ }
44
+ /** A frame as inline-style properties (camelCase, as `CSSStyleDeclaration` and `Object.assign` take them). */
45
+ interface SceneFrame {
46
+ transform?: string;
47
+ opacity?: string;
48
+ clipPath?: string;
49
+ backgroundColor?: string;
50
+ color?: string;
51
+ }
52
+ declare enum SceneAttribute {
53
+ Root = "data-iox-scene",
54
+ Tracks = "data-iox-tracks",
55
+ PhoneTracks = "data-iox-tracks-phone"
56
+ }
57
+ /** At or under this stage width a layer plays its phone tracks. The `mobile` breakpoint's width. */
58
+ declare const SCENE_PHONE_MAX_WIDTH = 767;
59
+ /**
60
+ * The tracks a saved value really holds: unknown properties, bad keys and colours that are not colours are dropped,
61
+ * keys sorted by progress, a track left with no key dropped. Never throws on what a page document holds.
62
+ */
63
+ declare function normalizeTracks(tracks: unknown): SceneTrack[];
64
+ /** A numeric track's value at progress `p`. */
65
+ declare function valueAt(keys: ReadonlyArray<SceneKey>, p: number): number;
66
+ /**
67
+ * A colour track's value at progress `p`. Mixed by the browser, never computed here, so a design token stays a live
68
+ * reference (a re-theme reaches a Scene, as it reaches every saved page) and the path is perceptual.
69
+ */
70
+ declare function colourAt(keys: ReadonlyArray<SceneKey>, p: number): string;
71
+ interface SceneFrameOptions {
72
+ /** -1 when the stage reads right-to-left: the inline axis mirrors. */
73
+ inlineSign?: 1 | -1;
74
+ }
75
+ /**
76
+ * A layer's frame at progress `p`. Lengths are container-query units, so one frame is right at any width, under any
77
+ * canvas zoom, on the server and with no measuring: the stage is the size container (`iox-design.css`).
78
+ */
79
+ declare function sceneFrame(tracks: ReadonlyArray<SceneTrack>, p: number, options?: SceneFrameOptions): SceneFrame;
80
+ /** A frame as kebab-case style declarations, for a string renderer. */
81
+ declare function sceneFrameDeclarations(frame: SceneFrame): Record<string, string>;
82
+ /** The attributes a node's own element carries — the same decision in all three render paths. The runtime reads them,
83
+ * so it needs no node tree and is the same on every path. Empty for any node that is no part of a Scene. */
84
+ declare function sceneNodeAttributes(node: SceneNodeSource | null | undefined): Record<string, string>;
85
+ /** The frame a layer ships in from the server: where it stands before anyone has scrolled. Without it the page would
86
+ * paint every layer at once, and then jump when the script arrives. */
87
+ declare function sceneFirstFrame(node: SceneNodeSource | null | undefined): SceneFrame;
88
+ /**
89
+ * Make an element carry its node's Scene attributes: the live sync on the canvas and the component path's stamp.
90
+ * Removes stale ones, touches nothing else.
91
+ */
92
+ declare function syncSceneAttributes(el: HTMLElement | null | undefined, node: SceneNodeSource | null | undefined): void;
93
+ /** Stamp a layer's first frame on its element (the component path, on the server too). */
94
+ declare function applySceneFirstFrame(el: HTMLElement | null | undefined, node: SceneNodeSource | null | undefined): void;
95
+ /**
96
+ * Where nothing will drive it (reduced motion, no script) a Scene is ordinary content: it flows, every layer in its
97
+ * place and in its own look, every word readable. `!important` because it must beat a node's compiled height and
98
+ * position, and the inline first frame. The engine wraps it in a reduced-motion query and in `<noscript>`.
99
+ */
100
+ declare const SCENE_FLOW_RULES: string;
101
+ /** Under reduced motion the driver never starts, so the same rules hold for the whole visit. */
102
+ declare const SCENE_REDUCED_MOTION_CSS = "@media (prefers-reduced-motion: reduce){.iox-role-scene{height:auto!important}.iox-role-scene-stage{position:relative!important;top:auto!important;height:auto!important;overflow:visible!important;container-type:normal!important}[data-iox-tracks]{transform:none!important;opacity:1!important;clip-path:none!important}}";
103
+
104
+ /**
105
+ * The SCENE recipe: ordinary nodes, no new type, so all three render paths and every panel already know it.
106
+ *
107
+ * Section role scene height = how long it plays (× the viewport)
108
+ * └─ Container role scene.stage pinned, one viewport tall, clips its layers, the size container for their lengths
109
+ * ├─ Heading a layer with its own tracks
110
+ * └─ Text a layer with its own tracks
111
+ *
112
+ * How long it plays IS the root's height, so it follows the width system the way every other size does. The stage is a
113
+ * track-carrying layer too: its Ground is the colour the whole Scene moves through.
114
+ */
115
+ type SceneLayerNode = CompositeNode & SceneNodeSource;
116
+ interface SceneWords {
117
+ title: string;
118
+ line: string;
119
+ }
120
+ /** Generic words a fresh Scene starts with: the author's to replace. */
121
+ declare const SCENE_WORDS: Readonly<SceneWords>;
122
+ /** How long a fresh Scene plays: 4 viewports wide, 3 on a phone (a thumb travels less). */
123
+ declare const SCENE_LENGTH = "400vh";
124
+ declare const SCENE_PHONE_LENGTH = "300vh";
125
+ /** Small viewport height: a phone's toolbar never pushes the stage's bottom out of sight. */
126
+ declare const SCENE_STAGE_HEIGHT = "100svh";
127
+ /** A fresh Scene: it already moves, so the author sees what the thing is before touching it. */
128
+ declare function buildSceneRecipe(create: CompositeNodeFactory, words?: Partial<SceneWords>): SceneLayerNode;
129
+
130
+ /**
131
+ * The ONE scroll loop (premium-sites plan §5b, SC0). Every Scene on a page reads one progress value from it, on the
132
+ * canvas and on the live site alike. It reads where the root is and nothing else, so it has one code path: under the
133
+ * canvas's zoom the same rectangle divides by the same zoom, and the answer is the same at any scale.
134
+ *
135
+ * - The value is DAMPED: the scroll stops and the page settles a moment later. This is much of the prototype's weight,
136
+ * and why this is not a CSS scroll timeline, which cannot do it.
137
+ * - The live site pins with `position: sticky`, on the compositor. The canvas cannot (its page never scrolls itself,
138
+ * its Lenis scrolls a wrapper around a zoomed frame), so `pin` holds the stage there with `translate` instead.
139
+ * `translate`, not `transform`: a Stage may carry tracks of its own.
140
+ * - It sleeps. No frame is asked for unless something moved, so a page holding a settled Scene costs nothing.
141
+ * - Reads come first in a frame and writes after, and a write only ever touches compositor properties.
142
+ */
143
+ declare const SCENE_DAMPING = 9;
144
+ /** One frame of the damping: frame-rate independent, so 60 Hz and 120 Hz settle in the same time. */
145
+ declare function dampToward(current: number, target: number, seconds: number, rate?: number): number;
146
+ /** Where a root stands: scrolled `local` page px into its `travel`. `zoom` undoes the canvas's scale. */
147
+ declare function sceneScrollState(rootTop: number, originTop: number, zoom: number, travel: number): {
148
+ local: number;
149
+ progress: number;
150
+ };
151
+ interface ScrollDriverOptions {
152
+ /** Hold the stage with `translate` (the canvas). The live site's stage is sticky and needs nothing. */
153
+ pin?: boolean;
154
+ /** The element a root scrolls under, when that is not the window (the canvas's frame, Preview's page). */
155
+ originOf?: (root: HTMLElement) => HTMLElement | null;
156
+ /** Follow what changes inside a root: tracks edited, layers added (the canvas). */
157
+ observe?: boolean;
158
+ damping?: number;
159
+ /** The window, for a test. */
160
+ host?: Window;
161
+ }
162
+ declare class ScrollDriver {
163
+ private readonly options;
164
+ private readonly scenes;
165
+ private readonly host;
166
+ private readonly resize;
167
+ private frame;
168
+ private lastTime;
169
+ private readonly wakeUp;
170
+ constructor(options?: ScrollDriverOptions);
171
+ /** Drive a Scene's root. Idempotent: adding a root again re-reads it. */
172
+ add(root: HTMLElement): void;
173
+ remove(root: HTMLElement): void;
174
+ /** The damped progress a root's layers stand at. */
175
+ progressOf(root: HTMLElement): number | null;
176
+ /** Something moved that no scroll or resize announces (the canvas's zoom). */
177
+ wake(): void;
178
+ destroy(): void;
179
+ /** Read a root's stage and layers from its DOM: its own Scene's only, never a nested one's. */
180
+ private reread;
181
+ private readLayer;
182
+ private remeasureAll;
183
+ private measure;
184
+ private readonly tick;
185
+ private read;
186
+ private write;
187
+ }
188
+ /** A page's Scenes, driven by one driver; null when it holds none, or when the visitor asked for less motion (the
189
+ * page's own CSS then lets each Scene flow). The live site's door. */
190
+ declare function attachScenes(container: HTMLElement, options?: ScrollDriverOptions): ScrollDriver | null;
191
+
192
+ export { SCENE_DAMPING, SCENE_FLOW_RULES, SCENE_LENGTH, SCENE_PHONE_LENGTH, SCENE_PHONE_MAX_WIDTH, SCENE_REDUCED_MOTION_CSS, SCENE_STAGE_HEIGHT, SCENE_WORDS, SceneAttribute, SceneProp, ScrollDriver, applySceneFirstFrame, attachScenes, buildSceneRecipe, colourAt, dampToward, normalizeTracks, sceneFirstFrame, sceneFrame, sceneFrameDeclarations, sceneNodeAttributes, sceneScrollState, syncSceneAttributes, valueAt };
193
+ export type { SceneFrame, SceneFrameOptions, SceneKey, SceneLayerNode, SceneNodeSource, SceneTrack, SceneWords, ScrollDriverOptions };
@@ -0,0 +1,3 @@
1
+ {
2
+ "module": "../fesm2022/vectoriox-iox-ui-scene-core.mjs"
3
+ }
@@ -66,6 +66,15 @@ export enum SegmentedRole {
66
66
  Badge = 'segmented.badge',
67
67
  }
68
68
 
69
+ /**
70
+ * A SCENE (premium-sites plan §5b): a stage held still while the page scrolls past it. The stage is the root's only
71
+ * part; everything inside the stage is an ordinary node. Its maths and its runtime are `@vectoriox/iox-ui/scene-core`.
72
+ */
73
+ export enum SceneRole {
74
+ Scene = 'scene',
75
+ Stage = 'scene.stage',
76
+ }
77
+
69
78
  interface RoleLike { role?: string | null }
70
79
 
71
80
  /** The roles each open/close kind plays in the shared runtime. */
@@ -1,4 +1,4 @@
1
- import { AccordionRole, DisclosureRole, SegmentedRole, TabsRole } from './composite-kinds';
1
+ import { AccordionRole, DisclosureRole, SceneRole, SegmentedRole, TabsRole } from './composite-kinds';
2
2
  import { CardPart, CardRole } from './card';
3
3
  import { SLIDER_TYPE, SliderRole } from './slider';
4
4
 
@@ -56,6 +56,9 @@ export const COMPOSITE_ROLE_SPECS: Readonly<Record<string, CompositeRoleSpec>> =
56
56
  [SegmentedRole.Segmented]: { parent: null, accepts: [SegmentedRole.Option] },
57
57
  [SegmentedRole.Option]: { parent: SegmentedRole.Segmented, pinned: true },
58
58
  [SegmentedRole.Badge]: { parent: SegmentedRole.Option, pinned: true },
59
+ // A Scene always keeps its stage: everything it pins and clips lives there.
60
+ [SceneRole.Scene]: { parent: null },
61
+ [SceneRole.Stage]: { parent: SceneRole.Scene, locked: true },
59
62
  // CC3 — a Slider's controls are its own direct children (Swiper is handed them). The pause control stays while
60
63
  // Autoplay is on (WCAG 2.2.2): the Autoplay switch removes it, never Delete. The arrows and the dots follow
61
64
  // their switches and may be deleted.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @vectoriox/iox-ui/scene-core — a Scene: a stage that holds still while the page scrolls past it, its layers moving on
3
+ * ONE progress value (premium-sites plan §5b). FRAMEWORK-FREE: the builder canvas, both engine paths and (from SC6) the
4
+ * composer read the same tracks, frames and recipe; the driver is DOM-only and is the ONE scroll loop.
5
+ * ⚠️ Consumers wire the usual trio — ng-package raw-ts assets, jest moduleNameMapper, tsconfig paths.
6
+ */
7
+ export * from './scene';
8
+ export * from './scene-recipe';
9
+ export * from './scroll-driver';
@@ -0,0 +1,100 @@
1
+ import { CompositeNode, CompositeNodeFactory, makeCompositePart, NO_ELEMENT_STYLE, SceneRole, writeLayerStyles, writeStyles } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ import { SceneNodeSource, SceneProp, SceneTrack } from './scene';
4
+
5
+ /**
6
+ * The SCENE recipe: ordinary nodes, no new type, so all three render paths and every panel already know it.
7
+ *
8
+ * Section role scene height = how long it plays (× the viewport)
9
+ * └─ Container role scene.stage pinned, one viewport tall, clips its layers, the size container for their lengths
10
+ * ├─ Heading a layer with its own tracks
11
+ * └─ Text a layer with its own tracks
12
+ *
13
+ * How long it plays IS the root's height, so it follows the width system the way every other size does. The stage is a
14
+ * track-carrying layer too: its Ground is the colour the whole Scene moves through.
15
+ */
16
+
17
+ export type SceneLayerNode = CompositeNode & SceneNodeSource;
18
+
19
+ export interface SceneWords {
20
+ title: string;
21
+ line: string;
22
+ }
23
+
24
+ /** Generic words a fresh Scene starts with: the author's to replace. */
25
+ export const SCENE_WORDS: Readonly<SceneWords> = {
26
+ title: 'One idea, held still',
27
+ line: 'The page keeps moving. This stays until you have read it.',
28
+ };
29
+
30
+ /** How long a fresh Scene plays: 4 viewports wide, 3 on a phone (a thumb travels less). */
31
+ export const SCENE_LENGTH = '400vh';
32
+ export const SCENE_PHONE_LENGTH = '300vh';
33
+ /** Small viewport height: a phone's toolbar never pushes the stage's bottom out of sight. */
34
+ export const SCENE_STAGE_HEIGHT = '100svh';
35
+ const PHONE_BREAKPOINT = 'mobile';
36
+
37
+ enum Type {
38
+ Section = 'Section',
39
+ Container = 'Container',
40
+ Heading = 'Heading',
41
+ Text = 'Text',
42
+ }
43
+
44
+ const ROOT_LAYOUT: Readonly<Record<string, string>> = {
45
+ position: 'relative',
46
+ display: 'block',
47
+ width: '100%',
48
+ height: SCENE_LENGTH,
49
+ };
50
+
51
+ const STAGE_LAYOUT: Readonly<Record<string, string>> = {
52
+ position: 'sticky',
53
+ top: '0px',
54
+ display: 'flex',
55
+ flexDirection: 'column',
56
+ alignItems: 'center',
57
+ justifyContent: 'center',
58
+ width: '100%',
59
+ height: SCENE_STAGE_HEIGHT,
60
+ overflow: 'hidden',
61
+ };
62
+
63
+ const TITLE_TRACKS: ReadonlyArray<SceneTrack> = [
64
+ { prop: SceneProp.Opacity, keys: [[0, 0], [0.2, 1], [0.75, 1], [1, 0]] },
65
+ { prop: SceneProp.Y, keys: [[0, 8], [0.2, 0], [1, -6]] },
66
+ { prop: SceneProp.Scale, keys: [[0, 0.96], [0.6, 1], [1, 1.04]] },
67
+ ];
68
+
69
+ const LINE_TRACKS: ReadonlyArray<SceneTrack> = [
70
+ { prop: SceneProp.Opacity, keys: [[0.25, 0], [0.45, 1], [0.8, 1], [1, 0]] },
71
+ { prop: SceneProp.Y, keys: [[0.25, 6], [0.45, 0], [1, -4]] },
72
+ ];
73
+
74
+ const STAGE_TRACKS: ReadonlyArray<SceneTrack> = [
75
+ { prop: SceneProp.Ground, keys: [[0, 'var(--iox-surface-2)'], [0.6, 'var(--iox-page-bg)']] },
76
+ ];
77
+
78
+ const copyTracks = (tracks: ReadonlyArray<SceneTrack>): SceneTrack[] => tracks.map(t => ({ prop: t.prop, keys: t.keys.map(k => [k[0], k[1]] as const) }));
79
+
80
+ /** A fresh Scene: it already moves, so the author sees what the thing is before touching it. */
81
+ export function buildSceneRecipe(create: CompositeNodeFactory, words: Partial<SceneWords> = {}): SceneLayerNode {
82
+ const text = { ...SCENE_WORDS, ...words };
83
+ const root = makeCompositePart(create, { key: 'root', type: Type.Section, elementStyle: NO_ELEMENT_STYLE }, SceneRole.Scene, 'Scene', ROOT_LAYOUT) as SceneLayerNode;
84
+ writeLayerStyles(root, PHONE_BREAKPOINT, { height: SCENE_PHONE_LENGTH });
85
+
86
+ const stage = makeCompositePart(create, { key: 'stage', type: Type.Container, elementStyle: NO_ELEMENT_STYLE }, SceneRole.Stage, 'Stage', STAGE_LAYOUT) as SceneLayerNode;
87
+ stage.sceneTracks = copyTracks(STAGE_TRACKS);
88
+
89
+ const title = makeCompositePart(create, { key: 'title', type: Type.Heading, props: { text: text.title, tag: 'h2' } }, null, 'Title') as SceneLayerNode;
90
+ title.sceneTracks = copyTracks(TITLE_TRACKS);
91
+ writeStyles(title, { textAlign: 'center' });
92
+
93
+ const line = makeCompositePart(create, { key: 'line', type: Type.Text, props: { text: text.line } }, null, 'Line') as SceneLayerNode;
94
+ line.sceneTracks = copyTracks(LINE_TRACKS);
95
+ writeStyles(line, { textAlign: 'center' });
96
+
97
+ stage.children = [title, line];
98
+ root.children = [stage];
99
+ return root;
100
+ }
@@ -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}}`;