@vectoriox/iox-ui 5.88.0 → 5.90.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 (49) hide show
  1. package/design-core/index.d.ts +523 -2
  2. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +3 -2
  3. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  4. package/fesm2022/vectoriox-iox-ui-design-core.mjs +581 -1
  5. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +4692 -160
  7. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +12 -1
  9. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-scene-core.mjs +46 -6
  11. package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui.mjs +6 -4
  13. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  14. package/generation-core/index.d.ts +1611 -10
  15. package/harness-core/index.d.ts +52 -3
  16. package/package.json +1 -1
  17. package/scene-core/index.d.ts +28 -2
  18. package/src/composite-core/slider.ts +3 -2
  19. package/src/design-core/flavor-spec.generated.ts +500 -0
  20. package/src/design-core/font-metrics.ts +105 -0
  21. package/src/design-core/public-api.ts +1 -0
  22. package/src/generation-core/ai-run.ts +11 -0
  23. package/src/generation-core/audit-site.ts +5 -0
  24. package/src/generation-core/check-layout.ts +940 -0
  25. package/src/generation-core/compose-layout.ts +907 -0
  26. package/src/generation-core/compose-site.ts +136 -5
  27. package/src/generation-core/layout-drift.ts +78 -0
  28. package/src/generation-core/layout-edits.ts +122 -0
  29. package/src/generation-core/layout-fingerprint.ts +203 -0
  30. package/src/generation-core/layout-language.ts +537 -0
  31. package/src/generation-core/layout-look.ts +57 -0
  32. package/src/generation-core/layout-photos.ts +19 -0
  33. package/src/generation-core/layout-render-check.ts +275 -0
  34. package/src/generation-core/layout-section-fallback.ts +156 -0
  35. package/src/generation-core/layout-type.ts +48 -0
  36. package/src/generation-core/layout-wire.ts +282 -0
  37. package/src/generation-core/nav-shape.ts +23 -1
  38. package/src/generation-core/photo-inventory.ts +250 -0
  39. package/src/generation-core/plan-edits.ts +25 -2
  40. package/src/generation-core/plan-wire.ts +19 -2
  41. package/src/generation-core/public-api.ts +13 -0
  42. package/src/generation-core/site-plan.model.ts +16 -0
  43. package/src/generation-core/site-spec.generated.ts +759 -2
  44. package/src/generation-core/validate-site-plan.ts +55 -1
  45. package/src/harness-core/generation-view.ts +52 -1
  46. package/src/scene-core/scroll-driver.ts +14 -2
  47. package/src/scene-core/scroll-range.ts +37 -4
  48. package/styles/iox-design.css +17 -0
  49. package/styles/iox-forms.css +4 -0
@@ -0,0 +1,907 @@
1
+ import { buildMarqueeRecipe, CompositeNode, CompositeNodeSpec, NO_ELEMENT_STYLE, SceneRole, SLIDER_PLACEMENT_TRAIT, SliderPlacement, SliderRole, syncSliderParts } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ import { ColorScheme, DesignChoices, LinkType, setColorScheme } from '@vectoriox/iox-ui/design-core';
4
+ import { FORM_AFTER_SEND_TRAIT, FormAfterSend, FormPresetId } from '@vectoriox/iox-ui/forms-core';
5
+ import { composeNavHeader, composePresetForm } from './compose-site';
6
+ import {
7
+ LAYOUT_ACCENT_TEXT, LAYOUT_BEAT_DELAY, LAYOUT_COLOUR_TOKEN, LAYOUT_COLUMN_GAP, LAYOUT_DEPTH_ON_PHONE, LAYOUT_EASING, LAYOUT_GUTTER, LAYOUT_PACE, LAYOUT_PHONE_BREAKPOINT, LAYOUT_PHOTO_ASPECT, LAYOUT_TOOLTIP_TRAIT,
8
+ LAYOUT_PHONE_PADDING, LAYOUT_RISE, LAYOUT_TEXT_KINDS, LayoutBleed, LayoutColour, LayoutEase, LayoutEnter, LayoutForm, LayoutGallery, LayoutLayer,
9
+ LayoutLayerKind, LayoutNavKind, LayoutPace, LayoutPhotoShape, LayoutRole, LayoutSection, LayoutSide, LayoutSite, LayoutTrack, LayoutTrackProp, LayoutTransition, phoneGapBefore,
10
+ screenFontSize,
11
+ } from './layout-language';
12
+ import { layoutGlideDepth } from './layout-drift';
13
+ import { layoutDesignOf, layoutElementStyle, layoutTextWidthEm, screenWordColumns } from './layout-type';
14
+ import { ComposeError, createSerializedNode, SerializedNode, setStyleProps, assertStyleSlots, walkSerialized } from './serialized-node';
15
+
16
+ /**
17
+ * THE layout composer (premium components M8, gate 1): a page written in the layout language (`layout-language.ts`) in,
18
+ * ordinary builder nodes out — the same `createSerializedNode` every composed page is made of, so the builder reloads it
19
+ * and saves it unchanged and the engine renders it with nothing new to learn. No second renderer: a section is a Section
20
+ * holding a 12-column grid, a held section is a Scene, a layer is a Heading / Text / Image / Slider / Form / Button
21
+ * placed on the grid, its time entrance a `viewportEnter` interaction, its depth a `scrollProgress` parallax, its held
22
+ * motion scene-core tracks. What the product cannot say yet is returned as a GAP (named in m8-proof-sites.md), never
23
+ * worked around with CSS. Pure and deterministic.
24
+ */
25
+
26
+ export enum LayoutGapCode {
27
+ /** M8-G1: a `screen` word is sized from its face's measured letters (iox-ui#46), not fitted to its cell in the browser. */
28
+ ScreenFit = 'screen-fit',
29
+ /** M8-G2: no blur — a `blurIn` entrance rises without it, a `blur` track is dropped. */
30
+ Blur = 'blur',
31
+ /** M8-G3: `scaleIn` / `pop` start at the product's 0.8, not 0.95 / 0.9, and `pop` has no overshoot. */
32
+ ScaleIn = 'scale-in',
33
+ /** M8-G4: a held layer's keys ease one way (smoothstep), whatever the layout's ease. */
34
+ TrackEase = 'track-ease',
35
+ /** M8-G5: a depth glides at the product's one speed (no per-look scale), and a picture's own drift inside its frame
36
+ * is a fixed over-scale. */
37
+ DepthSpeed = 'depth-speed',
38
+ /** M8-G6: the navigation is the product's bar — a corner, index or side menu is drawn as the bar. */
39
+ NavKind = 'nav-kind',
40
+ /** M8-G7: a link to a section scrolls by an action; it is no address (`#id`) a visitor can share. */
41
+ SectionLink = 'section-link',
42
+ /** M8-G9: a slider on a held section's stage is played by the scroll whether or not the layout asked. */
43
+ StageSlider = 'stage-slider',
44
+ /** M8-G10: a flood opens from the centre as an inset, not as a circle from the top edge. */
45
+ Flood = 'flood',
46
+ /** M8-G11: a held section stacks on a phone and its layers stand at rest (they cannot say "no motion here"). */
47
+ PhoneRest = 'phone-rest',
48
+ /** Motion or a sideways track on a section that is not held: the product moves layers by tracks only in a Scene. */
49
+ UnheldMotion = 'unheld-motion',
50
+ /** A form layer wears the product's preset: its fields are the preset's, the layout's options fill its choices. */
51
+ FormPreset = 'form-preset',
52
+ /** A gallery naming a list with no pictures and no slides of its own shows photo boxes (iox-ui#59). */
53
+ GalleryNoPictures = 'gallery-no-pictures',
54
+ }
55
+
56
+ export interface LayoutGap {
57
+ code: LayoutGapCode;
58
+ /** `sections[i].layers[j]`, `sections[i]` or `nav`. */
59
+ path: string;
60
+ detail: string;
61
+ }
62
+
63
+ export enum LayoutColourMode {
64
+ Light = 'light',
65
+ Dark = 'dark',
66
+ }
67
+
68
+ export interface ComposeLayoutOptions {
69
+ /** Prefix of every node id (`<id>-s0-l1`). */
70
+ id?: string;
71
+ /** The look's colour mode: which colour names are light (a scrim under light words is dark, and the other way). */
72
+ mode?: `${LayoutColourMode}`;
73
+ /** Where the studio keeps each photo (its media URL). */
74
+ photoSrc: (photoId: string) => string;
75
+ /** A photo's description; '' (decorative) when not given. */
76
+ photoAlt?: (photoId: string) => string;
77
+ /** A photo's shape: the height its frame keeps where it stacks (a phone, a Scene with no scroll). Landscape when not given. */
78
+ photoShape?: (photoId: string) => `${LayoutPhotoShape}` | undefined;
79
+ /** Silent section fallback: the node a place given to the plan's ready-made section stands as (`LayoutSection.readyMade`),
80
+ * stamped by the caller from that plan section's pattern with `id` as its root id. A layout with such a place and no
81
+ * stamper is refused. */
82
+ readyMade?: (section: LayoutSection, id: string) => SerializedNode;
83
+ /** The design the page wears (its fonts size a `screen` word, iox-ui#46). Default: the look's preset in `mode`. */
84
+ design?: DesignChoices;
85
+ /** Gate 2: a list data source's picture and name fields — a gallery naming the source shows its items. Null when the
86
+ * source has no picture field (the gallery keeps its own slides). */
87
+ sourceFields?: (alias: string) => { image: string; title?: string } | null;
88
+ }
89
+
90
+ export interface ComposedLayout {
91
+ /** The page's layout: one root per section. */
92
+ layout: SerializedNode[];
93
+ /** The site header (a global BEFORE element) with the layout's section links, or null when the layout has no nav. */
94
+ header: SerializedNode | null;
95
+ /** The node id each section's id became (what its links scroll to). */
96
+ sections: Record<string, string>;
97
+ gaps: LayoutGap[];
98
+ }
99
+
100
+ const COMPOSED = { releaseLayoutDefaults: true } as const;
101
+ /** The boxes a gallery shows when it has nothing to show (the check's fewest slides). */
102
+ const EMPTY_GALLERY_BOXES = 3;
103
+ const create = (id: string, type: string, props: Record<string, unknown> = {}, elementStyle?: string | null) =>
104
+ createSerializedNode(id, type, props, elementStyle, COMPOSED);
105
+
106
+ enum T {
107
+ Section = 'Section',
108
+ Container = 'Container',
109
+ Heading = 'Heading',
110
+ Text = 'Text',
111
+ Image = 'Image',
112
+ ButtonBlock = 'ButtonBlock',
113
+ List = 'List',
114
+ ListItem = 'ListItem',
115
+ Slider = 'SliderContainer',
116
+ Slide = 'SliderSlide',
117
+ Link = 'Link',
118
+ Field = 'Field',
119
+ SubmitButton = 'SubmitButton',
120
+ FormSuccess = 'FormSuccess',
121
+ }
122
+
123
+ const GRID_COLUMNS = 12;
124
+ const PHONE_FIRST_TOP = '84px';
125
+ const KINETIC_ALL_LIT = 0.8;
126
+ const INNER_SCALE = 0.07;
127
+ const CLIP_DURATION = 1.15;
128
+ const ZOOM_DURATION = 1.6;
129
+ const NUMBER_PHONE_SIZE = 'clamp(36px, 11vw, 52px)';
130
+ const SLIDE_GAP = 18;
131
+ const GALLERY_SPEED = 900;
132
+ const GALLERY_STACKED_ASPECT = '4 / 5';
133
+ const FULL = '100%';
134
+ const ZERO = '0px';
135
+ const PHONE_GROUND_BRIGHTNESS = '0.75';
136
+ const GALLERY_BAR_TOP = '12px';
137
+ const STRETCH_KINDS: ReadonlySet<string> = new Set([LayoutLayerKind.Photo, LayoutLayerKind.Shape, LayoutLayerKind.Gallery, LayoutLayerKind.Form]);
138
+ const STACKED_EFFECTS: ReadonlySet<string> = new Set(['fade', 'cube', 'flip', 'cards']);
139
+ const SHADOW_UNDER_LIGHT = '0 1px 2px rgba(0,0,0,.55), 0 6px 34px rgba(0,0,0,.6)';
140
+ const HALO_UNDER_DARK = '0 1px 2px rgba(255,255,255,.5), 0 4px 26px rgba(255,255,255,.75), 0 0 60px rgba(255,255,255,.45)';
141
+ const FORM_PRESET_CHOICE_LABEL: Readonly<Record<string, string>> = { guests: 'People', needs: 'What do you need?', budget: 'Estimated budget' };
142
+ /** A form someone may send again says its Sent words in a toast and keeps its fields (premium M5, N3); the rest show the
143
+ * success in place. */
144
+ const LAYOUT_FORM_AFTER_SEND: Readonly<Partial<Record<string, FormAfterSend>>> = { [FormPresetId.Newsletter]: FormAfterSend.Toast };
145
+ const CHOICES = 'choices';
146
+
147
+
148
+ interface Ctx {
149
+ p: string;
150
+ site: LayoutSite;
151
+ rtl: boolean;
152
+ mode: LayoutColourMode;
153
+ pace: { lead: number; support: number; decoration: number; gap: number };
154
+ ease: string;
155
+ sections: Record<string, string>;
156
+ gaps: LayoutGap[];
157
+ design: DesignChoices;
158
+ photoSrc: (id: string) => string;
159
+ photoAlt: (id: string) => string;
160
+ photoAspect: (id: string) => string;
161
+ sourceFields: (alias: string) => { image: string; title?: string } | null;
162
+ /** Every node a section link was written on, with the section id it scrolls to (resolved once all are stamped). */
163
+ links: Array<{ node: SerializedNode; to: string; closes?: string }>;
164
+ headingSeen: boolean;
165
+ }
166
+
167
+ function gap(ctx: Ctx, code: LayoutGapCode, path: string, detail: string): void {
168
+ if (!ctx.gaps.some(g => g.code === code && g.path === path)) ctx.gaps.push({ code, path, detail });
169
+ }
170
+
171
+ function phone(node: SerializedNode, values: Readonly<Record<string, unknown>>): void {
172
+ assertStyleSlots(node.type, Object.keys(values));
173
+ const layers = (node.responsive ??= {});
174
+ const layer = (layers[LAYOUT_PHONE_BREAKPOINT] ??= { styleProps: {} });
175
+ Object.assign((layer.styleProps ??= {}), values);
176
+ }
177
+
178
+ function setProp(node: SerializedNode, name: string, value: unknown): void {
179
+ node.props[name] = value;
180
+ }
181
+
182
+ /** A colour name as the token the layer paints with: words in the accent read its text shade. */
183
+ function colourOf(l: LayoutLayer): string {
184
+ const colour = (l.color ?? LayoutColour.Ink) as LayoutColour;
185
+ if (colour === LayoutColour.Accent && LAYOUT_TEXT_KINDS.has(l.kind)) return LAYOUT_ACCENT_TEXT;
186
+ return LAYOUT_COLOUR_TOKEN[colour] ?? LAYOUT_COLOUR_TOKEN[LayoutColour.Ink];
187
+ }
188
+
189
+ /** A ground as paint: the page's own ground shows through (the round-four renderer leaves it transparent). */
190
+ function groundPaint(ground: string): string {
191
+ if (ground === LayoutColour.Ground) return 'transparent';
192
+ return LAYOUT_COLOUR_TOKEN[ground as LayoutColour] ?? 'transparent';
193
+ }
194
+
195
+ /** A ground as the colour a transition paints (the page's own ground for `ground`). */
196
+ function veilPaint(ground: string): string {
197
+ return ground === LayoutColour.Ground ? 'var(--iox-page-bg)' : LAYOUT_COLOUR_TOKEN[ground as LayoutColour] ?? 'var(--iox-page-bg)';
198
+ }
199
+
200
+ /** Is this colour light in this mode — what a scrim under it must be dark for. */
201
+ function isLight(colour: string | undefined, mode: LayoutColourMode): boolean {
202
+ const name = (colour ?? LayoutColour.Ink) as LayoutColour;
203
+ const ground = name === LayoutColour.Ground || name === LayoutColour.Soft;
204
+ return mode === LayoutColourMode.Light ? ground : !ground;
205
+ }
206
+
207
+ const gridTemplate = (count: number) => `repeat(${count}, minmax(0, 1fr))`;
208
+
209
+ /** The grid a section's layers are placed on: 12 columns per screen, its rows, the page's gutter. */
210
+ function gridLayout(rows: number, track: number): Record<string, string> {
211
+ return {
212
+ display: 'grid',
213
+ gridTemplateColumns: gridTemplate(GRID_COLUMNS * track),
214
+ gridTemplateRows: gridTemplate(rows),
215
+ gap: `${ZERO} ${LAYOUT_COLUMN_GAP}`,
216
+ padding: `${ZERO} ${LAYOUT_GUTTER}`,
217
+ };
218
+ }
219
+
220
+ /** The same grid on a phone: one column, in the section's `phone` order, with the M1.3 padding. */
221
+ function phoneStack(first: boolean): Record<string, string> {
222
+ return {
223
+ display: 'flex',
224
+ flexDirection: 'column',
225
+ height: 'auto',
226
+ gap: ZERO,
227
+ padding: `${first ? PHONE_FIRST_TOP : LAYOUT_PHONE_PADDING} ${LAYOUT_GUTTER} ${LAYOUT_PHONE_PADDING} ${LAYOUT_GUTTER}`,
228
+ };
229
+ }
230
+
231
+ /** A bleed's width: its cell and the gutters it runs into (a negative margin alone moves a box that holds its width). */
232
+ function bleedWidth(bleed: string | undefined): string | null {
233
+ if (!bleed || bleed === LayoutBleed.None) return null;
234
+ return bleed === LayoutBleed.Both ? `calc(100% + 2 * ${LAYOUT_GUTTER})` : `calc(100% + ${LAYOUT_GUTTER})`;
235
+ }
236
+
237
+ /** The physical sides a bleed runs into, from the page's direction. */
238
+ function bleedSides(bleed: string | undefined, rtl: boolean): { left: boolean; right: boolean } | null {
239
+ if (!bleed || bleed === LayoutBleed.None) return null;
240
+ const start = bleed === LayoutBleed.Start || bleed === LayoutBleed.Both;
241
+ const end = bleed === LayoutBleed.End || bleed === LayoutBleed.Both;
242
+ return rtl ? { left: end, right: start } : { left: start, right: end };
243
+ }
244
+
245
+ /** A bleed: the layer runs into the gutter on that side. */
246
+ function bleedMargin(bleed: string | undefined, rtl: boolean): string | null {
247
+ const sides = bleedSides(bleed, rtl);
248
+ if (!sides) return null;
249
+ const out = `calc(-1 * ${LAYOUT_GUTTER})`;
250
+ return `${ZERO} ${sides.right ? out : ZERO} ${ZERO} ${sides.left ? out : ZERO}`;
251
+ }
252
+
253
+ // ── Motion ──────────────────────────────────────────────────────────────────────────────────────────────
254
+
255
+ const ENTER_TYPE: Readonly<Record<string, string>> = {
256
+ [LayoutEnter.Fade]: 'fadeIn',
257
+ [LayoutEnter.FadeRise]: 'moveUp',
258
+ [LayoutEnter.ScaleIn]: 'scaleIn',
259
+ [LayoutEnter.Pop]: 'scaleIn',
260
+ [LayoutEnter.ClipReveal]: 'clipReveal',
261
+ [LayoutEnter.MaskRise]: 'revealText',
262
+ [LayoutEnter.BlurIn]: 'moveUp',
263
+ };
264
+
265
+ /** A time entrance: the round-four renderer's `playEnter` as a `viewportEnter` interaction on the node. */
266
+ function enterInteraction(nodeId: string, l: LayoutLayer, ctx: Ctx, path: string, textual: boolean, scale = 1): unknown | null {
267
+ const enter = l.enter ?? LayoutEnter.None;
268
+ if (enter === LayoutEnter.None) return null;
269
+ const role = (l.role ?? LayoutRole.Support) as LayoutRole;
270
+ const recipe = role === LayoutRole.Decoration ? LayoutEnter.Fade : enter;
271
+ const duration = Math.round((role === LayoutRole.Lead ? ctx.pace.lead : role === LayoutRole.Decoration ? ctx.pace.decoration : ctx.pace.support) * scale);
272
+ const delay = Math.round(LAYOUT_BEAT_DELAY[Math.max(0, Math.min(5, l.beat ?? 0))] * ctx.pace.gap);
273
+ let type = ENTER_TYPE[recipe] ?? 'fadeIn';
274
+ const params: Record<string, unknown> = {};
275
+ const rise = LAYOUT_RISE[role] ?? LAYOUT_RISE[LayoutRole.Support];
276
+ if (recipe === LayoutEnter.FadeRise) params['distance'] = rise;
277
+ if (recipe === LayoutEnter.BlurIn) {
278
+ params['distance'] = Math.round(rise / 2);
279
+ gap(ctx, LayoutGapCode.Blur, path, 'blurIn rises without its blur');
280
+ }
281
+ if (recipe === LayoutEnter.ScaleIn || recipe === LayoutEnter.Pop) gap(ctx, LayoutGapCode.ScaleIn, path, `${recipe} starts at 0.8`);
282
+ if (recipe === LayoutEnter.ClipReveal) params['from'] = l.from ?? LayoutSide.Bottom;
283
+ if (recipe === LayoutEnter.MaskRise) {
284
+ if (textual) params['by'] = 'word';
285
+ else {
286
+ type = 'moveUp';
287
+ params['distance'] = rise;
288
+ }
289
+ }
290
+ return {
291
+ id: `${nodeId}-enter`,
292
+ trigger: 'viewportEnter',
293
+ actions: [{ type, target: 'self', duration: recipe === LayoutEnter.ClipReveal ? Math.round(duration * CLIP_DURATION) : duration, delay, easing: ctx.ease, once: true, ...(Object.keys(params).length ? { params } : {}) }],
294
+ };
295
+ }
296
+
297
+ /** A picture settling inside its frame as the frame wipes open (`clipReveal` on a photo). */
298
+ function zoomInteraction(nodeId: string, l: LayoutLayer, ctx: Ctx): unknown {
299
+ const role = (l.role ?? LayoutRole.Support) as LayoutRole;
300
+ const duration = role === LayoutRole.Lead ? ctx.pace.lead : ctx.pace.support;
301
+ return {
302
+ id: `${nodeId}-settle`,
303
+ trigger: 'viewportEnter',
304
+ actions: [{ type: 'zoomOut', target: 'self', duration: Math.round(duration * ZOOM_DURATION), delay: Math.round(LAYOUT_BEAT_DELAY[Math.max(0, Math.min(5, l.beat ?? 0))] * ctx.pace.gap), easing: ctx.ease, once: true }],
305
+ };
306
+ }
307
+
308
+ /** A depth: the layer glides against the page while it passes (`parallax`, the product's one speed). */
309
+ function depthInteraction(nodeId: string, depth: string): unknown {
310
+ // Stacked on a phone, a layer never glides into its neighbour.
311
+ return { id: `${nodeId}-depth`, trigger: 'scrollProgress', range: 'cover', actions: [{ type: 'parallax', target: 'self', duration: 1000, delay: 0, easing: 'linear', params: { depth, phone: LAYOUT_DEPTH_ON_PHONE } }] };
312
+ }
313
+
314
+ const TRACK_REST: Readonly<Record<string, number>> = { x: 0, y: 0, scale: 1, rotate: 0, opacity: 1, clip: 100, words: 100 };
315
+
316
+ interface SceneTrackOut { prop: string; keys: Array<[number, number]>; from?: string }
317
+
318
+ /** A layout track as a scene-core track: lengths move from the layer's own box to the stage's (cqw / cqh). */
319
+ function sceneTrackOf(t: LayoutTrack, l: LayoutLayer, rows: number, ctx: Ctx, path: string): SceneTrackOut | null {
320
+ const [a, b] = t.at ?? [0, 1];
321
+ if (t.prop === LayoutTrackProp.Blur) {
322
+ gap(ctx, LayoutGapCode.Blur, path, 'a blur track is dropped');
323
+ return null;
324
+ }
325
+ if (t.ease && t.ease !== LayoutEase.InOut) gap(ctx, LayoutGapCode.TrackEase, path, `${t.prop} eases (smoothstep), not ${t.ease}`);
326
+ let scale = 1;
327
+ if (t.prop === LayoutTrackProp.X) scale = (l.col[1] - l.col[0]) / GRID_COLUMNS;
328
+ if (t.prop === LayoutTrackProp.Y) scale = (l.row[1] - l.row[0]) / rows;
329
+ const round = (v: number) => Math.round(v * scale * 100) / 100;
330
+ const track: SceneTrackOut = { prop: t.prop, keys: [[a, round(Number(t.from))], [b, round(Number(t.to))]] };
331
+ if (t.prop === LayoutTrackProp.Clip) track.from = LayoutSide.Bottom;
332
+ return track;
333
+ }
334
+
335
+ /** On a phone a held section stacks: each of its tracks stands at rest. */
336
+ function restingTracks(tracks: ReadonlyArray<SceneTrackOut>): SceneTrackOut[] {
337
+ return tracks.map(t => ({ prop: t.prop, keys: [[0, TRACK_REST[t.prop] ?? 0]], ...(t.from ? { from: t.from } : {}) }));
338
+ }
339
+
340
+ // ── Layers ──────────────────────────────────────────────────────────────────────────────────────────────
341
+
342
+ interface LayerCtx {
343
+ section: LayoutSection;
344
+ si: number;
345
+ li: number;
346
+ path: string;
347
+ held: boolean;
348
+ track: number;
349
+ /** The layer's place in the phone order and the space above it there. */
350
+ order: number;
351
+ phoneGap: number;
352
+ phoneAlign: string;
353
+ }
354
+
355
+ /** The node that sits on the grid: its cell, its stacking, its bleed and its tilt — and on a phone, its place in the stack. */
356
+ function place(node: SerializedNode, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): void {
357
+ const stretch = STRETCH_KINDS.has(l.kind);
358
+ const values: Record<string, unknown> = {
359
+ gridColumn: `${l.col[0]} / ${l.col[1]}`,
360
+ gridRow: `${l.row[0]} / ${l.row[1]}`,
361
+ alignSelf: stretch ? 'stretch' : 'center',
362
+ zIndex: String(1 + (l.z ?? 0)),
363
+ position: 'relative',
364
+ minWidth: ZERO,
365
+ };
366
+ const margin = bleedMargin(l.bleed, ctx.rtl);
367
+ if (margin) values['margin'] = margin;
368
+ const width = l.kind === LayoutLayerKind.Button ? null : bleedWidth(l.bleed);
369
+ if (width) values['width'] = width;
370
+ if (l.rotate) values['rotate'] = `${l.rotate}deg`;
371
+ if (l.kind === LayoutLayerKind.Button) values['justifySelf'] = l.align === 'center' ? 'center' : l.align === 'end' ? 'end' : 'start';
372
+ else if (l.kind !== LayoutLayerKind.Photo && l.kind !== LayoutLayerKind.Gallery && l.kind !== LayoutLayerKind.Shape) values['textAlign'] = l.align ?? 'start';
373
+ setStyleProps(node, values);
374
+ const onPhone: Record<string, unknown> = {
375
+ gridColumn: 'auto', gridRow: 'auto', alignSelf: l.kind === LayoutLayerKind.Button ? 'flex-start' : 'stretch', order: String(lc.order),
376
+ margin: `${lc.phoneGap}px ${ZERO} ${ZERO} ${ZERO}`,
377
+ };
378
+ if (width) onPhone['width'] = FULL;
379
+ if (l.kind === LayoutLayerKind.Button && lc.phoneAlign === 'center') onPhone['alignSelf'] = 'center';
380
+ if (values['textAlign']) onPhone['textAlign'] = lc.phoneAlign;
381
+ if (l.kind === LayoutLayerKind.Shape) onPhone['display'] = 'none';
382
+ phone(node, onPhone);
383
+ }
384
+
385
+ /** Grounds the page's light colours paint, and the dark ones (a photo ground is dimmed on a phone). */
386
+ const LIGHT_GROUNDS: ReadonlySet<string> = new Set([LayoutColour.Ground, LayoutColour.Soft]);
387
+ const DARK_GROUNDS: ReadonlySet<string> = new Set([LayoutColour.Ink, LayoutColour.Muted]);
388
+ /** Word colours that vanish on a light ground, and on a dark one. */
389
+ const LIGHT_WORDS: ReadonlySet<string> = new Set([LayoutColour.Ground, LayoutColour.Soft]);
390
+ const DARK_WORDS: ReadonlySet<string> = new Set([LayoutColour.Ink, LayoutColour.Muted]);
391
+
392
+ const cellsMeet = (a: LayoutLayer, b: LayoutLayer) =>
393
+ a.col[0] < b.col[1] && b.col[0] < a.col[1] && a.row[0] < b.row[1] && b.row[0] < a.row[1];
394
+
395
+ /**
396
+ * Words drawn on a shape or a photo at a laptop's width lose it on a phone: the shape is hidden and every layer stacks,
397
+ * so they read on the section's own ground there. When their colour would vanish into that ground (the live clinic's
398
+ * "What we treat", white on its shape, and the bar's label on its photo — 1:1 on the phone), the phone gives them the
399
+ * colour the ground's words take; otherwise null (M8 gate 2, fix first part 3).
400
+ */
401
+ export function phoneWordsColour(l: LayoutLayer, li: number, s: Pick<LayoutSection, 'layers' | 'ground'>): string | null {
402
+ if (!LAYOUT_TEXT_KINDS.has(l.kind)) return null;
403
+ const backdrop = s.layers.some((o, oi) => oi !== li && (o.kind === LayoutLayerKind.Shape || o.kind === LayoutLayerKind.Photo)
404
+ && (o.z ?? 0) < (l.z ?? 0) && cellsMeet(o, l));
405
+ if (!backdrop) return null;
406
+ const ground = String(s.ground ?? LayoutColour.Ground);
407
+ const colour = String(l.color ?? LayoutColour.Ink);
408
+ const dark = DARK_GROUNDS.has(ground) || ground.startsWith('photo:');
409
+ if (LIGHT_GROUNDS.has(ground) && LIGHT_WORDS.has(colour)) return LAYOUT_COLOUR_TOKEN[LayoutColour.Ink];
410
+ if (dark && DARK_WORDS.has(colour)) return LAYOUT_COLOUR_TOKEN[LayoutColour.Ground];
411
+ return null;
412
+ }
413
+
414
+ function textLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
415
+ const style = layoutElementStyle(l);
416
+ let node: SerializedNode;
417
+ if (l.kind === LayoutLayerKind.Word || l.kind === LayoutLayerKind.Heading) {
418
+ const level = !ctx.headingSeen && lc.si === 0 && l.role === LayoutRole.Lead ? 'h1' : 'h2';
419
+ if (level === 'h1') ctx.headingSeen = true;
420
+ node = create(id, T.Heading, { content: l.text ?? '', level }, style);
421
+ } else if (l.kind === LayoutLayerKind.Number) {
422
+ // A number is set in the display face, but it is no heading: a Text wearing the display tokens.
423
+ node = create(id, T.Text, { content: l.text ?? '', tag: 'p' }, NO_ELEMENT_STYLE);
424
+ setStyleProps(node, {
425
+ fontFamily: 'var(--iox-font-display)', fontSize: 'var(--iox-size-display)', fontWeight: 'var(--iox-weight-display)',
426
+ letterSpacing: 'var(--iox-tracking-display)', lineHeight: '1', fontVariantNumeric: 'tabular-nums',
427
+ });
428
+ phone(node, { fontSize: NUMBER_PHONE_SIZE });
429
+ } else {
430
+ node = create(id, T.Text, { content: l.text ?? '', tag: 'p' }, style);
431
+ }
432
+ setStyleProps(node, { color: colourOf(l), margin: ZERO });
433
+ if (l.scrim) setStyleProps(node, { textShadow: isLight(l.color, ctx.mode) ? SHADOW_UNDER_LIGHT : HALO_UNDER_DARK });
434
+ const onPhone = phoneWordsColour(l, lc.li, lc.section);
435
+ if (onPhone) phone(node, { color: onPhone, textShadow: 'none' });
436
+ if (l.size === 'screen') {
437
+ const rows = l.row[1] - l.row[0];
438
+ const em = layoutTextWidthEm(l, ctx.design);
439
+ const screens = lc.held ? 1 : lc.section.screens;
440
+ setStyleProps(node, { fontSize: screenFontSize(em, screenWordColumns(l), rows, lc.section.rows, screens) });
441
+ phone(node, { fontSize: screenFontSize(em, GRID_COLUMNS, 0, 0, 0) });
442
+ gap(ctx, LayoutGapCode.ScreenFit, lc.path, 'sized from its face\'s measured letters (no kerning), not fitted in the browser');
443
+ }
444
+ return node;
445
+ }
446
+
447
+ function listLayer(id: string, l: LayoutLayer, ctx: Ctx): SerializedNode {
448
+ const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
449
+ const list = create(`${id}-list`, T.List, { htmlTag: 'ul' }, NO_ELEMENT_STYLE);
450
+ setStyleProps(list, { display: 'grid', gap: '0.5em', margin: ZERO, padding: ZERO, listStyleType: 'none', color: colourOf(l) });
451
+ list.children = (l.items ?? []).map((item, i) => {
452
+ const li = create(`${id}-i${i}`, T.ListItem, {}, NO_ELEMENT_STYLE);
453
+ setStyleProps(li, { borderWidth: '1px 0px 0px 0px', borderStyle: 'solid', borderColor: 'currentColor', padding: '0.45em 0px 0px 0px', opacity: '0.9' });
454
+ const text = create(`${id}-i${i}-t`, T.Text, { content: item, tag: 'span' }, layoutElementStyle(l));
455
+ setStyleProps(text, { color: 'inherit', margin: ZERO });
456
+ li.children = [text];
457
+ return li;
458
+ });
459
+ frame.children = [list];
460
+ return frame;
461
+ }
462
+
463
+ function photoLayer(id: string, l: LayoutLayer, ctx: Ctx, path: string): { frame: SerializedNode; image: SerializedNode } {
464
+ const photoId = l.photo?.id ?? '';
465
+ const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
466
+ // Its cell gives it both sides (the shape is ignored there); where it stacks, its width and its shape give it a height.
467
+ const aspectRatio = ctx.photoAspect(photoId);
468
+ setStyleProps(frame, { overflow: 'hidden', borderRadius: 'var(--iox-image-radius)', height: FULL, aspectRatio });
469
+ phone(frame, { aspectRatio, height: 'auto' });
470
+ const image = create(`${id}-img`, T.Image, { src: ctx.photoSrc(photoId), alt: ctx.photoAlt(photoId) }, 'media');
471
+ setStyleProps(image, {
472
+ display: 'block', width: FULL, height: FULL, aspectRatio: 'auto', objectFit: l.fit === 'contain' ? 'contain' : 'cover', borderRadius: ZERO,
473
+ });
474
+ // A picture with room to drift is over-scaled inside its frame (M8-G5: the drift itself has no speed of its own). The
475
+ // scale sits on a box between them: an Image's own size is capped at its frame (vectoriox/iox-ui#8), and its
476
+ // transform belongs to its entrance (zoomOut).
477
+ const k = INNER_SCALE * Math.max(0, Math.min(3, l.inner ?? 0));
478
+ if (!k) {
479
+ frame.children = [image];
480
+ return { frame, image };
481
+ }
482
+ const drift = create(`${id}-drift`, T.Container, {}, NO_ELEMENT_STYLE);
483
+ const scale = String(Math.round((1 + k) * 1000) / 1000);
484
+ setStyleProps(drift, { width: FULL, height: FULL, scaleX: scale, scaleY: scale });
485
+ drift.children = [image];
486
+ gap(ctx, LayoutGapCode.DepthSpeed, path, `inner ${l.inner}: over-scaled ×${(1 + k).toFixed(2)}, no drift`);
487
+ frame.children = [drift];
488
+ return { frame, image };
489
+ }
490
+
491
+ function galleryLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
492
+ const g: LayoutGallery = l.gallery ?? { slides: [] };
493
+ const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
494
+ setStyleProps(frame, { position: 'relative' });
495
+ phone(frame, { height: 'auto' });
496
+ const effect = g.effect ?? 'slide';
497
+ const stacked = STACKED_EFFECTS.has(effect);
498
+ const per = stacked ? 1 : g.perView === 'auto' ? 'auto' : Number(g.perView ?? 1);
499
+ // On a held stage the Scene's own driver plays the gallery (scene-core `sliderOf`); "Scroll plays it" there would give
500
+ // it a runway — a second Scene inside the first, two drivers on one slider. Off a stage, `scroll` is that runway.
501
+ const scrollPlays = !!g.scroll && !lc.held;
502
+ const played = scrollPlays || lc.held;
503
+ const slider = create(`${id}-slider`, T.Slider, {
504
+ dir: ctx.rtl ? 'rtl' : 'ltr', effect, slidesPerView: per, centeredSlides: !!g.centered, spaceBetween: per === 1 ? 0 : SLIDE_GAP,
505
+ loop: g.loop && !played ? 'on' : 'off', freeMode: !!g.freeMode && !played, grabCursor: !played, speed: GALLERY_SPEED,
506
+ enableParallax: !!g.drift, enableAutoplay: !!g.autoplay && !played, autoplayDelay: Math.max(1800, g.autoplay || 0),
507
+ autoplayDisableOnInteraction: true, enableKeyboard: true, scrollPlays,
508
+ enableCaption: g.slides.some(s => !!s.caption), enableCount: true, enableNavigation: !played && g.slides.length > 1,
509
+ [SLIDER_PLACEMENT_TRAIT]: SliderPlacement.Under, ariaLabel: l.text ?? '',
510
+ }, NO_ELEMENT_STYLE);
511
+ // Bounded by its cell: the engine wraps a slider in a host of no height, so `height: 100%` alone would grow the
512
+ // gallery to its picture and push the bar past the cell. On a phone it stacks at its own shape. A gallery the
513
+ // scroll plays is held mid-screen by its runway (shared CSS) at its pictures' own height instead.
514
+ setStyleProps(slider, scrollPlays ? { width: FULL, height: FULL, minHeight: ZERO } : {
515
+ position: 'absolute', top: ZERO, right: ZERO, bottom: ZERO, left: ZERO, width: FULL, height: FULL, minHeight: ZERO,
516
+ display: 'flex', flexDirection: 'column',
517
+ });
518
+ phone(slider, scrollPlays ? { height: 'auto', aspectRatio: GALLERY_STACKED_ASPECT } : { position: 'relative', height: 'auto', aspectRatio: GALLERY_STACKED_ASPECT });
519
+ const slideOf = (key: string, caption: string, src: string, alt: string) => {
520
+ const slide = create(`${id}-${key}`, T.Slide, { caption }, 'media');
521
+ setStyleProps(slide, { overflow: 'hidden', height: FULL, aspectRatio: 'auto' });
522
+ const image = create(`${id}-${key}-img`, T.Image, { src, alt }, 'media');
523
+ setStyleProps(image, { display: 'block', width: FULL, height: FULL, maxWidth: 'none', aspectRatio: 'auto', objectFit: 'cover', borderRadius: ZERO });
524
+ slide.children = [image];
525
+ return slide;
526
+ };
527
+ // Gate 2: a gallery naming a list source repeats ONE slide over its items — their picture, their name as the
528
+ // caption and the alt — so the page shows the newest work and stays live as the studio adds more.
529
+ const bound = g.source ? ctx.sourceFields(g.source) : null;
530
+ if (g.source && bound) {
531
+ slider.bindings.push({ prop: 'source', source: g.source, path: '' });
532
+ const slide = slideOf('slide', '', '', '');
533
+ const image = slide.children![0];
534
+ image.bindings.push({ prop: 'src', source: g.source, path: bound.image });
535
+ if (bound.title) {
536
+ image.bindings.push({ prop: 'alt', source: g.source, path: bound.title });
537
+ slide.bindings.push({ prop: 'caption', source: g.source, path: bound.title });
538
+ slider.props['enableCaption'] = true;
539
+ }
540
+ slider.props['enableNavigation'] = !played;
541
+ slider.children = [slide];
542
+ } else if (g.slides.length) {
543
+ slider.children = g.slides.map((s, i) => slideOf(`slide${i}`, s.caption ?? '', ctx.photoSrc(s.photo?.id ?? ''), s.caption ?? ctx.photoAlt(s.photo?.id ?? '')));
544
+ } else {
545
+ // A source with no pictures and no slides of its own (iox-ui#59 — the check refuses it, so only an unchecked page
546
+ // gets here): photo boxes the owner fills, never an empty band.
547
+ if (g.source) gap(ctx, LayoutGapCode.GalleryNoPictures, `${lc.path}.gallery.source`, `${g.source} has no pictures: shown as boxes to fill`);
548
+ slider.children = Array.from({ length: EMPTY_GALLERY_BOXES }, (_, i) => slideOf(`slide${i}`, '', '', ''));
549
+ }
550
+ syncSliderParts(slider as unknown as CompositeNode, partFactory(`${id}-slider`));
551
+ // Its arrows say what they do on hover and focus (premium M5): their own accessible names.
552
+ walkSerialized([slider], node => {
553
+ if (node.role === SliderRole.Prev || node.role === SliderRole.Next) node.props[LAYOUT_TOOLTIP_TRAIT] = node.props['ariaLabel'];
554
+ });
555
+ // A gallery that bleeds to the screen's edge keeps its bar inside the page's margin on that side (the bar's own
556
+ // padding assumes a slider centred on the screen).
557
+ const sides = bleedSides(l.bleed, ctx.rtl);
558
+ const bar = (slider.children ?? []).find(c => c.role === SliderRole.Bar);
559
+ if (sides && bar) {
560
+ setStyleProps(bar, { padding: `${GALLERY_BAR_TOP} ${sides.right ? LAYOUT_GUTTER : ZERO} ${ZERO} ${sides.left ? LAYOUT_GUTTER : ZERO}` });
561
+ phone(bar, { padding: `${GALLERY_BAR_TOP} ${ZERO} ${ZERO} ${ZERO}` });
562
+ }
563
+ if (lc.held) gap(ctx, LayoutGapCode.StageSlider, lc.path, 'played by the Scene\'s driver, which plays any slider on its stage (vectoriox/iox-ui#54)');
564
+ frame.children = [slider];
565
+ return frame;
566
+ }
567
+
568
+ /** Recipe parts stamped with this composer's ids (`<id>-<key>`). */
569
+ function partFactory(id: string): (spec: CompositeNodeSpec) => CompositeNode {
570
+ return spec => create(`${id}-${spec.key}`, spec.type, { ...(spec.props ?? {}) }, spec.elementStyle ?? null) as unknown as CompositeNode;
571
+ }
572
+
573
+ function buttonLayer(id: string, l: LayoutLayer, ctx: Ctx): SerializedNode {
574
+ const variant = l.variant === 'secondary' ? 'button-secondary' : l.variant === 'ghost' ? 'button-ghost' : 'button-primary';
575
+ // Gate 2: a button to another page of the site is a page link (`/contact`); a section id scrolls (wireLinks).
576
+ const toPage = !!l.to && l.to.startsWith(PAGE_ROUTE_MARK);
577
+ const button = create(id, T.ButtonBlock, toPage ? { tag: 'a', linkType: LinkType.Page, pageRoute: l.to } : { tag: 'button', type: 'button' }, variant);
578
+ const label = create(`${id}-label`, T.Text, { content: l.text ?? '', tag: 'span' }, 'button-label');
579
+ button.children = [label];
580
+ if (l.to && !toPage) ctx.links.push({ node: button, to: l.to });
581
+ return button;
582
+ }
583
+
584
+ /** The colour scheme a form wears on each band (iox-ui#58): its labels, fields and button are drawn by element styles that
585
+ * read the page's tokens, so on a band painted with the ink (or the accent) they would vanish into it. The scheme
586
+ * re-declares those tokens for that band; on the page's own ground (or the soft one) the form wears none. */
587
+ const FORM_SCHEME_ON: Readonly<Partial<Record<LayoutColour, ColorScheme>>> = {
588
+ [LayoutColour.Ink]: ColorScheme.Inverse,
589
+ [LayoutColour.Muted]: ColorScheme.Inverse,
590
+ [LayoutColour.Accent]: ColorScheme.Accent,
591
+ };
592
+
593
+ /** The scheme a form on this section ground wears, or null on the page's own ground. */
594
+ export function layoutFormScheme(ground: string | undefined): ColorScheme | null {
595
+ return FORM_SCHEME_ON[(ground ?? LayoutColour.Ground) as LayoutColour] ?? null;
596
+ }
597
+
598
+ /** A form layer: its title and intro, and the product's preset form — the layout's options become the preset's choices. */
599
+ function formLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx, path: string): SerializedNode {
600
+ const f: LayoutForm = l.form ?? { preset: 'contact' };
601
+ const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
602
+ const scheme = layoutFormScheme(lc.section.ground);
603
+ if (scheme) setColorScheme(frame, scheme);
604
+ setStyleProps(frame, { display: 'flex', flexDirection: 'column', gap: '12px', color: 'var(--iox-text)' });
605
+ const parts: SerializedNode[] = [];
606
+ if (f.title) {
607
+ const title = create(`${id}-title`, T.Heading, { content: f.title, level: 'h3' }, 'h3');
608
+ setStyleProps(title, { margin: ZERO });
609
+ parts.push(title);
610
+ }
611
+ if (f.intro) {
612
+ const intro = create(`${id}-intro`, T.Text, { content: f.intro, tag: 'p' }, 'body');
613
+ setStyleProps(intro, { margin: ZERO });
614
+ parts.push(intro);
615
+ }
616
+ const form = composePresetForm(`${id}-form`, f.preset, ctx.p);
617
+ const afterSend = LAYOUT_FORM_AFTER_SEND[f.preset];
618
+ if (afterSend) form.props[FORM_AFTER_SEND_TRAIT] = afterSend;
619
+ walkSerialized([form], node => {
620
+ if (node.type === T.Field) {
621
+ for (const [key, options] of Object.entries(f.options ?? {})) {
622
+ if (!options?.length || node.props['label'] !== FORM_PRESET_CHOICE_LABEL[key]) continue;
623
+ node.props['control'] = CHOICES;
624
+ node.props['optionsText'] = options.join('\n');
625
+ gap(ctx, LayoutGapCode.FormPreset, path, `the preset's "${node.props['label']}" takes the layout's ${key} as choices`);
626
+ }
627
+ }
628
+ if (node.type === T.SubmitButton && f.submit) node.props['label'] = f.submit;
629
+ if (node.type === T.FormSuccess && (f.successTitle || f.successText)) {
630
+ const text = node.children?.[0];
631
+ if (text) text.props['content'] = [f.successTitle, f.successText].filter(Boolean).join(' ');
632
+ }
633
+ });
634
+ parts.push(form);
635
+ frame.children = parts;
636
+ return frame;
637
+ }
638
+
639
+ function marqueeLayer(id: string, l: LayoutLayer): SerializedNode {
640
+ return buildMarqueeRecipe(partFactory(id), { words: l.items?.length ? l.items : l.text ? [l.text] : undefined }) as unknown as SerializedNode;
641
+ }
642
+
643
+ function shapeLayer(id: string, l: LayoutLayer): SerializedNode {
644
+ const shape = create(id, T.Container, {}, NO_ELEMENT_STYLE);
645
+ setStyleProps(shape, { backgroundColor: LAYOUT_COLOUR_TOKEN[(l.color ?? LayoutColour.Accent) as LayoutColour], borderRadius: 'var(--iox-image-radius)' });
646
+ return shape;
647
+ }
648
+
649
+ /** One layer → its node(s), placed, with its entrance, depth and tracks. */
650
+ function composeLayer(l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
651
+ const id = `${ctx.p}-s${lc.si}-l${lc.li}`;
652
+ let outer: SerializedNode;
653
+ let entering: SerializedNode;
654
+ let textual = false;
655
+ let image: SerializedNode | null = null;
656
+ switch (l.kind) {
657
+ case LayoutLayerKind.Photo: {
658
+ const made = photoLayer(id, l, ctx, lc.path);
659
+ outer = entering = made.frame;
660
+ image = made.image;
661
+ break;
662
+ }
663
+ case LayoutLayerKind.Gallery: outer = entering = galleryLayer(id, l, lc, ctx); break;
664
+ case LayoutLayerKind.Button: outer = entering = buttonLayer(id, l, ctx); break;
665
+ case LayoutLayerKind.List: outer = entering = listLayer(id, l, ctx); break;
666
+ case LayoutLayerKind.Form: outer = entering = formLayer(id, l, lc, ctx, lc.path); break;
667
+ case LayoutLayerKind.Marquee: outer = entering = marqueeLayer(id, l); break;
668
+ case LayoutLayerKind.Shape: outer = entering = shapeLayer(id, l); break;
669
+ default:
670
+ outer = entering = textLayer(id, l, lc, ctx);
671
+ textual = true;
672
+ }
673
+ outer.label = `${lc.section.id} · ${l.kind}${l.role ? ` (${l.role})` : ''}`;
674
+ place(outer, l, lc, ctx);
675
+
676
+ // Held: the layer moves by tracks; a kinetic heading lights word by word as the section is read.
677
+ const tracks: SceneTrackOut[] = [];
678
+ if (lc.held) {
679
+ for (const t of l.motion ?? []) {
680
+ const track = sceneTrackOf(t, l, lc.section.rows, ctx, lc.path);
681
+ if (track) tracks.push(track);
682
+ }
683
+ if (l.kinetic && textual) tracks.push({ prop: 'words', keys: [[0, 0], [KINETIC_ALL_LIT, 100]] });
684
+ if (tracks.length) {
685
+ outer.sceneTracks = tracks;
686
+ outer.scenePhoneTracks = restingTracks(tracks);
687
+ gap(ctx, LayoutGapCode.PhoneRest, lc.path, 'stands at rest on a phone');
688
+ }
689
+ } else if (l.motion?.length) {
690
+ gap(ctx, LayoutGapCode.UnheldMotion, lc.path, 'motion tracks on a section that is not held are dropped');
691
+ }
692
+
693
+ const interactions: unknown[] = [];
694
+ if (!(lc.held && l.kinetic && textual)) {
695
+ const enter = enterInteraction(entering.id, l, ctx, lc.path, textual);
696
+ if (enter) entering.interactions = [...entering.interactions, enter];
697
+ if (image && l.enter === LayoutEnter.ClipReveal && l.role !== LayoutRole.Decoration) image.interactions = [...image.interactions, zoomInteraction(image.id, l, ctx)];
698
+ }
699
+ const depth = layoutGlideDepth(lc.section, l);
700
+ if (depth) {
701
+ interactions.push(depthInteraction(outer.id, depth));
702
+ gap(ctx, LayoutGapCode.DepthSpeed, lc.path, `${depth} glides at the product's one speed`);
703
+ }
704
+ if (interactions.length) outer.interactions = [...outer.interactions, ...interactions];
705
+ return outer;
706
+ }
707
+
708
+ // ── Sections ────────────────────────────────────────────────────────────────────────────────────────────
709
+
710
+ function transitionOf(s: LayoutSection, prev: string | null, ctx: Ctx, si: number): SerializedNode[] {
711
+ const kind = s.transition ?? LayoutTransition.Cut;
712
+ const ground = String(s.ground ?? LayoutColour.Ground);
713
+ if (kind === LayoutTransition.Cut || !prev || ground.startsWith('photo:') || prev === ground) return [];
714
+ const box = { position: 'absolute', top: ZERO, left: ZERO, width: FULL, height: 'min(100%, 100svh)', zIndex: '0', minHeight: ZERO };
715
+ const under = create(`${ctx.p}-s${si}-under`, T.Container, {}, NO_ELEMENT_STYLE);
716
+ setStyleProps(under, { ...box, backgroundColor: veilPaint(prev) });
717
+ const veil = create(`${ctx.p}-s${si}-veil`, T.Container, {}, NO_ELEMENT_STYLE);
718
+ setStyleProps(veil, { ...box, backgroundColor: veilPaint(ground) });
719
+ for (const n of [under, veil]) {
720
+ n.label = `${s.id} · ${kind}`;
721
+ phone(n, { display: 'none' });
722
+ }
723
+ const from: Readonly<Record<string, string>> = {
724
+ [LayoutTransition.Flood]: 'centre', [LayoutTransition.WipeUp]: LayoutSide.Bottom, [LayoutTransition.WipeDown]: LayoutSide.Top,
725
+ [LayoutTransition.WipeStart]: LayoutSide.Start, [LayoutTransition.WipeEnd]: LayoutSide.End,
726
+ };
727
+ if (kind === LayoutTransition.Flood) gap(ctx, LayoutGapCode.Flood, `sections[${si}]`, 'the flood opens from the centre as an inset');
728
+ veil.interactions = [{
729
+ id: `${veil.id}-arrive`, trigger: 'scrollProgress', range: 'enter',
730
+ actions: [{ type: 'clipReveal', target: 'self', duration: 1000, delay: 0, easing: 'linear', params: { from: from[kind] ?? LayoutSide.Bottom } }],
731
+ }];
732
+ return [under, veil];
733
+ }
734
+
735
+ function groundPhoto(s: LayoutSection, si: number, ctx: Ctx): SerializedNode | null {
736
+ const ground = String(s.ground ?? '');
737
+ if (!ground.startsWith('photo:')) return null;
738
+ const id = ground.slice('photo:'.length);
739
+ const image = create(`${ctx.p}-s${si}-ground`, T.Image, { src: ctx.photoSrc(id), alt: '' }, 'media');
740
+ setStyleProps(image, {
741
+ position: 'absolute', top: ZERO, left: ZERO, width: FULL, height: FULL, maxWidth: 'none', aspectRatio: 'auto', objectFit: 'cover', zIndex: '0', borderRadius: ZERO,
742
+ });
743
+ // On a phone the words span the picture's whole width, so they always sit on its detail: it is dimmed under them
744
+ // (the section's words read light on a photo ground — its paint is ink).
745
+ phone(image, { filterBrightness: PHONE_GROUND_BRIGHTNESS });
746
+ image.label = `${s.id} · ground`;
747
+ return image;
748
+ }
749
+
750
+ function composeSection(s: LayoutSection, si: number, prevGround: string | null, ctx: Ctx): SerializedNode {
751
+ const id = `${ctx.p}-s${si}`;
752
+ const held = !!s.pin;
753
+ const track = Math.max(1, s.track ?? 1);
754
+ const ground = String(s.ground ?? LayoutColour.Ground);
755
+ ctx.sections[s.id] = id;
756
+ if (track > 1 && !held) gap(ctx, LayoutGapCode.UnheldMotion, `sections[${si}]`, 'a sideways section that is not held cannot travel');
757
+
758
+ const order = Array.isArray(s.phone) && s.phone.length ? s.phone : s.layers.map((_, i) => i);
759
+ const textKinds = s.layers.filter(x => LAYOUT_TEXT_KINDS.has(x.kind) || x.kind === LayoutLayerKind.Button);
760
+ const phoneAlign = textKinds.length && textKinds.every(x => x.align === 'center') ? 'center' : 'start';
761
+ const layers = s.layers.map((l, li) => {
762
+ const at = order.indexOf(li);
763
+ const prevIdx = at > 0 ? order[at - 1] : -1;
764
+ const visiblePrev = prevIdx >= 0 && s.layers[prevIdx]?.kind !== LayoutLayerKind.Shape ? s.layers[prevIdx] : null;
765
+ const lc: LayerCtx = {
766
+ section: s, si, li, path: `sections[${si}].layers[${li}]`, held, track: held ? track : 1,
767
+ order: at < 0 ? s.layers.length + li : at, phoneGap: phoneGapBefore(visiblePrev, l), phoneAlign,
768
+ };
769
+ return composeLayer(l, lc, ctx);
770
+ });
771
+
772
+ const root = create(id, T.Section, {}, NO_ELEMENT_STYLE);
773
+ root.label = s.id;
774
+ const paint = ground.startsWith('photo:') ? LAYOUT_COLOUR_TOKEN[LayoutColour.Ink] : groundPaint(ground);
775
+ const base = {
776
+ position: 'relative', width: FULL, minHeight: ZERO, height: `${s.screens * 100}svh`, backgroundColor: paint, color: 'var(--iox-text)', margin: ZERO,
777
+ ...(ctx.rtl ? { textDirection: 'rtl' } : {}),
778
+ };
779
+ const behind = [groundPhoto(s, si, ctx), ...transitionOf(s, prevGround, ctx, si)].filter((n): n is SerializedNode => !!n);
780
+
781
+ if (!held) {
782
+ setStyleProps(root, { ...base, ...gridLayout(s.rows, 1), overflow: 'clip' });
783
+ phone(root, phoneStack(si === 0));
784
+ root.children = [...behind, ...layers];
785
+ return root;
786
+ }
787
+
788
+ // Held: a Scene — the section is how long it plays, its stage the screen that holds still (scene-core's recipe). On a
789
+ // phone it stacks (M8-D5): the stage steps out of the layout (`contents`), because its size containment would give a
790
+ // stage that flows no height at all, and its layers stand in the section's stack.
791
+ root.role = SceneRole.Scene;
792
+ setStyleProps(root, { ...base, display: 'block', padding: ZERO });
793
+ const stage = create(`${id}-stage`, T.Container, {}, NO_ELEMENT_STYLE);
794
+ stage.role = SceneRole.Stage;
795
+ stage.label = `${s.id} · stage`;
796
+ const stageBox = { position: 'sticky', top: ZERO, width: FULL, height: '100svh', minHeight: ZERO, overflow: 'hidden', zIndex: '1' };
797
+ phone(stage, { display: 'contents' });
798
+ if (track === 1) {
799
+ setStyleProps(stage, { ...stageBox, ...gridLayout(s.rows, 1) });
800
+ phone(root, phoneStack(si === 0));
801
+ stage.children = layers;
802
+ } else {
803
+ setStyleProps(stage, { ...stageBox, display: 'block' });
804
+ phone(root, { height: 'auto' });
805
+ const wide = create(`${id}-track`, T.Container, {}, NO_ELEMENT_STYLE);
806
+ wide.label = `${s.id} · ${track} screens wide`;
807
+ setStyleProps(wide, { ...gridLayout(s.rows, track), width: `${track * 100}%`, height: FULL, minHeight: ZERO });
808
+ phone(wide, { width: FULL, ...phoneStack(si === 0) });
809
+ wide.sceneTracks = [{ prop: 'x', keys: [[0, 0], [1, -(track - 1) * 100]] }];
810
+ wide.scenePhoneTracks = [{ prop: 'x', keys: [[0, 0]] }];
811
+ gap(ctx, LayoutGapCode.TrackEase, `sections[${si}]`, 'the sideways travel eases (smoothstep), not linear');
812
+ wide.children = layers;
813
+ stage.children = [wide];
814
+ }
815
+ root.children = [...behind, stage];
816
+ return root;
817
+ }
818
+
819
+ // ── The header ──────────────────────────────────────────────────────────────────────────────────────────
820
+
821
+ const NAV_ROUTE = '/';
822
+ /** A layer's `to` starting with it names a page of the site, not a section of this one. */
823
+ const PAGE_ROUTE_MARK = '/';
824
+
825
+ /** The product's site header (composeNavHeader) with the layout's section links: each one scrolls to its section; in the
826
+ * phone menu it closes the drawer first. */
827
+ function composeHeader(ctx: Ctx): SerializedNode | null {
828
+ const links = ctx.site.nav?.links ?? [];
829
+ if (!links.length) return null;
830
+ const kind = ctx.site.nav?.kind ?? LayoutNavKind.Bar;
831
+ if (kind !== LayoutNavKind.Bar) gap(ctx, LayoutGapCode.NavKind, 'nav', `a ${kind} menu is drawn as the product's bar`);
832
+ gap(ctx, LayoutGapCode.SectionLink, 'nav', 'section links scroll by an action, with no #address');
833
+ const pages = [{ name: ctx.site.name, route: NAV_ROUTE, isHome: true }, ...links.map(link => ({ name: link.label, route: `/${link.to}` }))];
834
+ let n = 0;
835
+ const { header } = composeNavHeader({ business: { name: ctx.site.name } as never, pages }, { id: `${ctx.p}-nav`, newId: suffix => `${ctx.p}-nav-${++n}-${suffix}` });
836
+ if (ctx.rtl) setStyleProps(header, { textDirection: 'rtl' });
837
+ let drawer: string | undefined;
838
+ walkSerialized([header], node => { if (node.role === 'nav.drawer') drawer = node.id; });
839
+ walkSerialized([header], (node, ancestors) => {
840
+ if (node.type !== T.Link) return;
841
+ const to = String(node.props['pageRoute'] ?? '').slice(1);
842
+ if (!to || !links.some(l => l.to === to)) return;
843
+ node.props['linkType'] = 'external';
844
+ node.props['url'] = `#${to}`;
845
+ node.props['pageRoute'] = '';
846
+ const inDrawer = ancestors.some(a => a.role === 'nav.drawer');
847
+ ctx.links.push({ node, to, ...(inDrawer && drawer ? { closes: drawer } : {}) });
848
+ });
849
+ return header;
850
+ }
851
+
852
+ /** Every section link, now that each section's node id is known: a click scrolls to it. */
853
+ function wireLinks(ctx: Ctx): void {
854
+ for (const { node, to, closes } of ctx.links) {
855
+ const target = ctx.sections[to];
856
+ if (!target) throw new ComposeError(`${node.id}: links to a section "${to}" the layout does not have`);
857
+ const actions: unknown[] = [];
858
+ if (closes) actions.push({ type: 'closeDialog', target: closes, duration: 0, delay: 0, easing: 'ease' });
859
+ actions.push({ type: 'scrollTo', target, duration: 0, delay: 0, easing: 'ease' });
860
+ node.interactions = [...node.interactions, { id: `${node.id}-to`, trigger: 'click', actions }];
861
+ }
862
+ }
863
+
864
+ /**
865
+ * A layout-language page → its layout and header. Deterministic: the same layout composes to byte-identical nodes.
866
+ * Refuses (ComposeError) a link to a section the layout does not have; everything the product cannot say comes back in
867
+ * `gaps`.
868
+ */
869
+ export function composeLayout(site: LayoutSite, options: ComposeLayoutOptions): ComposedLayout {
870
+ if (!site?.sections?.length) throw new ComposeError('a layout needs at least one section');
871
+ const pace = LAYOUT_PACE[(site.motion?.pace ?? LayoutPace.Normal) as LayoutPace] ?? LAYOUT_PACE[LayoutPace.Normal];
872
+ const ctx: Ctx = {
873
+ p: options.id ?? 'cl',
874
+ site,
875
+ rtl: site.locale === 'he',
876
+ mode: (options.mode ?? LayoutColourMode.Light) as LayoutColourMode,
877
+ pace,
878
+ ease: LAYOUT_EASING[(site.motion?.ease ?? LayoutEase.Out) as LayoutEase] ?? LAYOUT_EASING[LayoutEase.Out],
879
+ sections: {},
880
+ gaps: [],
881
+ design: options.design ?? layoutDesignOf(site.look?.preset, options.mode),
882
+ photoSrc: options.photoSrc,
883
+ photoAlt: options.photoAlt ?? (() => ''),
884
+ photoAspect: id => LAYOUT_PHOTO_ASPECT[(options.photoShape?.(id) ?? LayoutPhotoShape.Landscape) as LayoutPhotoShape] ?? LAYOUT_PHOTO_ASPECT[LayoutPhotoShape.Landscape],
885
+ sourceFields: options.sourceFields ?? (() => null),
886
+ links: [],
887
+ headingSeen: false,
888
+ };
889
+ let prev: string | null = null;
890
+ const layout = site.sections.map((s, si) => {
891
+ if (s.readyMade) {
892
+ if (!options.readyMade) throw new ComposeError(`sections[${si}]: a ready-made place needs its plan section stamped (options.readyMade)`);
893
+ const node = options.readyMade(s, `${ctx.p}-s${si}`);
894
+ ctx.sections[s.id] = node.id;
895
+ prev = LayoutColour.Ground;
896
+ return node;
897
+ }
898
+ const node = composeSection(s, si, prev, ctx);
899
+ const ground = String(s.ground ?? LayoutColour.Ground);
900
+ prev = ground.startsWith('photo:') ? LayoutColour.Ink : ground;
901
+ return node;
902
+ });
903
+ const header = composeHeader(ctx);
904
+ if (ctx.links.some(l => !l.closes) && !site.nav?.links?.length) gap(ctx, LayoutGapCode.SectionLink, 'buttons', 'a button to a section scrolls by an action');
905
+ wireLinks(ctx);
906
+ return { layout, header, sections: ctx.sections, gaps: ctx.gaps };
907
+ }