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