@vectoriox/iox-ui 5.89.0 → 5.90.1
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/design-core/index.d.ts +523 -2
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +581 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +8489 -4897
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +12 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs +33 -6
- package/fesm2022/vectoriox-iox-ui-scene-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +3 -2
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +4140 -2890
- package/harness-core/index.d.ts +52 -3
- package/package.json +1 -1
- package/scene-core/index.d.ts +19 -2
- package/src/design-core/flavor-spec.generated.ts +500 -0
- package/src/design-core/font-metrics.ts +105 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/generation-core/ai-run.ts +11 -0
- package/src/generation-core/audit-site.ts +5 -0
- package/src/generation-core/check-layout.ts +994 -0
- package/src/generation-core/compose-layout.ts +123 -34
- package/src/generation-core/compose-site.ts +122 -3
- package/src/generation-core/function-words.ts +14 -0
- package/src/generation-core/layout-drift.ts +78 -0
- package/src/generation-core/layout-edits.ts +122 -0
- package/src/generation-core/layout-fingerprint.ts +203 -0
- package/src/generation-core/layout-language.ts +205 -12
- package/src/generation-core/layout-look.ts +57 -0
- package/src/generation-core/layout-photos.ts +19 -0
- package/src/generation-core/layout-render-check.ts +275 -0
- package/src/generation-core/layout-section-fallback.ts +187 -0
- package/src/generation-core/layout-type.ts +48 -0
- package/src/generation-core/layout-wire.ts +282 -0
- package/src/generation-core/nav-shape.ts +23 -1
- package/src/generation-core/photo-inventory.ts +250 -0
- package/src/generation-core/plan-edits.ts +25 -2
- package/src/generation-core/plan-wire.ts +19 -2
- package/src/generation-core/public-api.ts +11 -0
- package/src/generation-core/site-plan.model.ts +16 -0
- package/src/generation-core/site-spec.generated.ts +760 -2
- package/src/generation-core/stock-match.ts +4 -3
- package/src/generation-core/validate-site-plan.ts +55 -1
- package/src/harness-core/generation-view.ts +52 -1
- package/src/scene-core/scroll-driver.ts +14 -2
- package/src/scene-core/scroll-range.ts +23 -3
- package/styles/iox-forms.css +4 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { buildMarqueeRecipe, CompositeNode, CompositeNodeSpec, NO_ELEMENT_STYLE, SceneRole, SLIDER_PLACEMENT_TRAIT, SliderPlacement, SliderRole, syncSliderParts } from '@vectoriox/iox-ui/composite-core';
|
|
2
2
|
|
|
3
|
+
import { ColorScheme, DesignChoices, LinkType, setColorScheme } from '@vectoriox/iox-ui/design-core';
|
|
3
4
|
import { FORM_AFTER_SEND_TRAIT, FormAfterSend, FormPresetId } from '@vectoriox/iox-ui/forms-core';
|
|
4
5
|
import { composeNavHeader, composePresetForm } from './compose-site';
|
|
5
6
|
import {
|
|
6
|
-
LAYOUT_ACCENT_TEXT, LAYOUT_BEAT_DELAY, LAYOUT_COLOUR_TOKEN, LAYOUT_COLUMN_GAP, LAYOUT_DEPTH_ON_PHONE, LAYOUT_EASING, LAYOUT_GUTTER,
|
|
7
|
-
LAYOUT_PHONE_PADDING, LAYOUT_RISE, LAYOUT_TEXT_KINDS, LayoutBleed, LayoutColour,
|
|
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,
|
|
8
9
|
LayoutLayerKind, LayoutNavKind, LayoutPace, LayoutPhotoShape, LayoutRole, LayoutSection, LayoutSide, LayoutSite, LayoutTrack, LayoutTrackProp, LayoutTransition, phoneGapBefore,
|
|
9
10
|
screenFontSize,
|
|
10
11
|
} from './layout-language';
|
|
12
|
+
import { layoutGlideDepth } from './layout-drift';
|
|
13
|
+
import { layoutDesignOf, layoutElementStyle, layoutTextWidthEm, screenWordColumns } from './layout-type';
|
|
11
14
|
import { ComposeError, createSerializedNode, SerializedNode, setStyleProps, assertStyleSlots, walkSerialized } from './serialized-node';
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -21,7 +24,7 @@ import { ComposeError, createSerializedNode, SerializedNode, setStyleProps, asse
|
|
|
21
24
|
*/
|
|
22
25
|
|
|
23
26
|
export enum LayoutGapCode {
|
|
24
|
-
/** M8-G1: a `screen` word is sized from
|
|
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. */
|
|
25
28
|
ScreenFit = 'screen-fit',
|
|
26
29
|
/** M8-G2: no blur — a `blurIn` entrance rises without it, a `blur` track is dropped. */
|
|
27
30
|
Blur = 'blur',
|
|
@@ -46,6 +49,8 @@ export enum LayoutGapCode {
|
|
|
46
49
|
UnheldMotion = 'unheld-motion',
|
|
47
50
|
/** A form layer wears the product's preset: its fields are the preset's, the layout's options fill its choices. */
|
|
48
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',
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
export interface LayoutGap {
|
|
@@ -71,6 +76,15 @@ export interface ComposeLayoutOptions {
|
|
|
71
76
|
photoAlt?: (photoId: string) => string;
|
|
72
77
|
/** A photo's shape: the height its frame keeps where it stacks (a phone, a Scene with no scroll). Landscape when not given. */
|
|
73
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;
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
export interface ComposedLayout {
|
|
@@ -84,6 +98,8 @@ export interface ComposedLayout {
|
|
|
84
98
|
}
|
|
85
99
|
|
|
86
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;
|
|
87
103
|
const create = (id: string, type: string, props: Record<string, unknown> = {}, elementStyle?: string | null) =>
|
|
88
104
|
createSerializedNode(id, type, props, elementStyle, COMPOSED);
|
|
89
105
|
|
|
@@ -106,9 +122,6 @@ enum T {
|
|
|
106
122
|
|
|
107
123
|
const GRID_COLUMNS = 12;
|
|
108
124
|
const PHONE_FIRST_TOP = '84px';
|
|
109
|
-
const SCREEN_ADVANCE = 0.6;
|
|
110
|
-
const SCREEN_ADVANCE_HEBREW = 0.38;
|
|
111
|
-
const HEBREW = /[-]/;
|
|
112
125
|
const KINETIC_ALL_LIT = 0.8;
|
|
113
126
|
const INNER_SCALE = 0.07;
|
|
114
127
|
const CLIP_DURATION = 1.15;
|
|
@@ -131,17 +144,6 @@ const FORM_PRESET_CHOICE_LABEL: Readonly<Record<string, string>> = { guests: 'Pe
|
|
|
131
144
|
const LAYOUT_FORM_AFTER_SEND: Readonly<Partial<Record<string, FormAfterSend>>> = { [FormPresetId.Newsletter]: FormAfterSend.Toast };
|
|
132
145
|
const CHOICES = 'choices';
|
|
133
146
|
|
|
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
147
|
|
|
146
148
|
interface Ctx {
|
|
147
149
|
p: string;
|
|
@@ -152,9 +154,11 @@ interface Ctx {
|
|
|
152
154
|
ease: string;
|
|
153
155
|
sections: Record<string, string>;
|
|
154
156
|
gaps: LayoutGap[];
|
|
157
|
+
design: DesignChoices;
|
|
155
158
|
photoSrc: (id: string) => string;
|
|
156
159
|
photoAlt: (id: string) => string;
|
|
157
160
|
photoAspect: (id: string) => string;
|
|
161
|
+
sourceFields: (alias: string) => { image: string; title?: string } | null;
|
|
158
162
|
/** Every node a section link was written on, with the section id it scrolls to (resolved once all are stamped). */
|
|
159
163
|
links: Array<{ node: SerializedNode; to: string; closes?: string }>;
|
|
160
164
|
headingSeen: boolean;
|
|
@@ -378,8 +382,37 @@ function place(node: SerializedNode, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): vo
|
|
|
378
382
|
phone(node, onPhone);
|
|
379
383
|
}
|
|
380
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
|
+
|
|
381
414
|
function textLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
|
|
382
|
-
const style =
|
|
415
|
+
const style = layoutElementStyle(l);
|
|
383
416
|
let node: SerializedNode;
|
|
384
417
|
if (l.kind === LayoutLayerKind.Word || l.kind === LayoutLayerKind.Heading) {
|
|
385
418
|
const level = !ctx.headingSeen && lc.si === 0 && l.role === LayoutRole.Lead ? 'h1' : 'h2';
|
|
@@ -398,14 +431,15 @@ function textLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): Serializ
|
|
|
398
431
|
}
|
|
399
432
|
setStyleProps(node, { color: colourOf(l), margin: ZERO });
|
|
400
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' });
|
|
401
436
|
if (l.size === 'screen') {
|
|
402
437
|
const rows = l.row[1] - l.row[0];
|
|
403
|
-
const
|
|
404
|
-
const advance = HEBREW.test(l.text ?? '') ? SCREEN_ADVANCE_HEBREW : SCREEN_ADVANCE;
|
|
438
|
+
const em = layoutTextWidthEm(l, ctx.design);
|
|
405
439
|
const screens = lc.held ? 1 : lc.section.screens;
|
|
406
|
-
setStyleProps(node, { fontSize: screenFontSize(
|
|
407
|
-
phone(node, { fontSize: screenFontSize(
|
|
408
|
-
gap(ctx, LayoutGapCode.ScreenFit, lc.path, 'sized from its letters, not fitted
|
|
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');
|
|
409
443
|
}
|
|
410
444
|
return node;
|
|
411
445
|
}
|
|
@@ -417,7 +451,7 @@ function listLayer(id: string, l: LayoutLayer, ctx: Ctx): SerializedNode {
|
|
|
417
451
|
list.children = (l.items ?? []).map((item, i) => {
|
|
418
452
|
const li = create(`${id}-i${i}`, T.ListItem, {}, NO_ELEMENT_STYLE);
|
|
419
453
|
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' },
|
|
454
|
+
const text = create(`${id}-i${i}-t`, T.Text, { content: item, tag: 'span' }, layoutElementStyle(l));
|
|
421
455
|
setStyleProps(text, { color: 'inherit', margin: ZERO });
|
|
422
456
|
li.children = [text];
|
|
423
457
|
return li;
|
|
@@ -459,6 +493,8 @@ function galleryLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): Seria
|
|
|
459
493
|
const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
|
|
460
494
|
setStyleProps(frame, { position: 'relative' });
|
|
461
495
|
phone(frame, { height: 'auto' });
|
|
496
|
+
const scheme = layoutBandScheme(lc.section.ground);
|
|
497
|
+
if (scheme) setColorScheme(frame, scheme);
|
|
462
498
|
const effect = g.effect ?? 'slide';
|
|
463
499
|
const stacked = STACKED_EFFECTS.has(effect);
|
|
464
500
|
const per = stacked ? 1 : g.perView === 'auto' ? 'auto' : Number(g.perView ?? 1);
|
|
@@ -482,14 +518,37 @@ function galleryLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx): Seria
|
|
|
482
518
|
display: 'flex', flexDirection: 'column',
|
|
483
519
|
});
|
|
484
520
|
phone(slider, scrollPlays ? { height: 'auto', aspectRatio: GALLERY_STACKED_ASPECT } : { position: 'relative', height: 'auto', aspectRatio: GALLERY_STACKED_ASPECT });
|
|
485
|
-
|
|
486
|
-
const slide = create(`${id}
|
|
521
|
+
const slideOf = (key: string, caption: string, src: string, alt: string) => {
|
|
522
|
+
const slide = create(`${id}-${key}`, T.Slide, { caption }, 'media');
|
|
487
523
|
setStyleProps(slide, { overflow: 'hidden', height: FULL, aspectRatio: 'auto' });
|
|
488
|
-
const image = create(`${id}
|
|
524
|
+
const image = create(`${id}-${key}-img`, T.Image, { src, alt }, 'media');
|
|
489
525
|
setStyleProps(image, { display: 'block', width: FULL, height: FULL, maxWidth: 'none', aspectRatio: 'auto', objectFit: 'cover', borderRadius: ZERO });
|
|
490
526
|
slide.children = [image];
|
|
491
527
|
return slide;
|
|
492
|
-
}
|
|
528
|
+
};
|
|
529
|
+
// Gate 2: a gallery naming a list source repeats ONE slide over its items — their picture, their name as the
|
|
530
|
+
// caption and the alt — so the page shows the newest work and stays live as the studio adds more.
|
|
531
|
+
const bound = g.source ? ctx.sourceFields(g.source) : null;
|
|
532
|
+
if (g.source && bound) {
|
|
533
|
+
slider.bindings.push({ prop: 'source', source: g.source, path: '' });
|
|
534
|
+
const slide = slideOf('slide', '', '', '');
|
|
535
|
+
const image = slide.children![0];
|
|
536
|
+
image.bindings.push({ prop: 'src', source: g.source, path: bound.image });
|
|
537
|
+
if (bound.title) {
|
|
538
|
+
image.bindings.push({ prop: 'alt', source: g.source, path: bound.title });
|
|
539
|
+
slide.bindings.push({ prop: 'caption', source: g.source, path: bound.title });
|
|
540
|
+
slider.props['enableCaption'] = true;
|
|
541
|
+
}
|
|
542
|
+
slider.props['enableNavigation'] = !played;
|
|
543
|
+
slider.children = [slide];
|
|
544
|
+
} else if (g.slides.length) {
|
|
545
|
+
slider.children = g.slides.map((s, i) => slideOf(`slide${i}`, s.caption ?? '', ctx.photoSrc(s.photo?.id ?? ''), s.caption ?? ctx.photoAlt(s.photo?.id ?? '')));
|
|
546
|
+
} else {
|
|
547
|
+
// A source with no pictures and no slides of its own (iox-ui#59 — the check refuses it, so only an unchecked page
|
|
548
|
+
// gets here): photo boxes the owner fills, never an empty band.
|
|
549
|
+
if (g.source) gap(ctx, LayoutGapCode.GalleryNoPictures, `${lc.path}.gallery.source`, `${g.source} has no pictures: shown as boxes to fill`);
|
|
550
|
+
slider.children = Array.from({ length: EMPTY_GALLERY_BOXES }, (_, i) => slideOf(`slide${i}`, '', '', ''));
|
|
551
|
+
}
|
|
493
552
|
syncSliderParts(slider as unknown as CompositeNode, partFactory(`${id}-slider`));
|
|
494
553
|
// Its arrows say what they do on hover and focus (premium M5): their own accessible names.
|
|
495
554
|
walkSerialized([slider], node => {
|
|
@@ -515,17 +574,36 @@ function partFactory(id: string): (spec: CompositeNodeSpec) => CompositeNode {
|
|
|
515
574
|
|
|
516
575
|
function buttonLayer(id: string, l: LayoutLayer, ctx: Ctx): SerializedNode {
|
|
517
576
|
const variant = l.variant === 'secondary' ? 'button-secondary' : l.variant === 'ghost' ? 'button-ghost' : 'button-primary';
|
|
518
|
-
|
|
577
|
+
// Gate 2: a button to another page of the site is a page link (`/contact`); a section id scrolls (wireLinks).
|
|
578
|
+
const toPage = !!l.to && l.to.startsWith(PAGE_ROUTE_MARK);
|
|
579
|
+
const button = create(id, T.ButtonBlock, toPage ? { tag: 'a', linkType: LinkType.Page, pageRoute: l.to } : { tag: 'button', type: 'button' }, variant);
|
|
519
580
|
const label = create(`${id}-label`, T.Text, { content: l.text ?? '', tag: 'span' }, 'button-label');
|
|
520
581
|
button.children = [label];
|
|
521
|
-
if (l.to) ctx.links.push({ node: button, to: l.to });
|
|
582
|
+
if (l.to && !toPage) ctx.links.push({ node: button, to: l.to });
|
|
522
583
|
return button;
|
|
523
584
|
}
|
|
524
585
|
|
|
586
|
+
/** The colour scheme a form or a gallery wears on each band (iox-ui#58; the gallery's bar since M8 gate 2): its labels,
|
|
587
|
+
* fields, buttons, caption, count and arrows are drawn by element styles that read the page's tokens, so on a band
|
|
588
|
+
* painted with the ink (or the accent) they would vanish into it — a gallery's arrows were empty circles on the ink. The
|
|
589
|
+
* scheme re-declares those tokens for that band; on the page's own ground (or the soft one) they wear none. */
|
|
590
|
+
const BAND_SCHEME_ON: Readonly<Partial<Record<LayoutColour, ColorScheme>>> = {
|
|
591
|
+
[LayoutColour.Ink]: ColorScheme.Inverse,
|
|
592
|
+
[LayoutColour.Muted]: ColorScheme.Inverse,
|
|
593
|
+
[LayoutColour.Accent]: ColorScheme.Accent,
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
/** The scheme a form or a gallery on this section ground wears, or null on the page's own ground. */
|
|
597
|
+
export function layoutBandScheme(ground: string | undefined): ColorScheme | null {
|
|
598
|
+
return BAND_SCHEME_ON[(ground ?? LayoutColour.Ground) as LayoutColour] ?? null;
|
|
599
|
+
}
|
|
600
|
+
|
|
525
601
|
/** 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 {
|
|
602
|
+
function formLayer(id: string, l: LayoutLayer, lc: LayerCtx, ctx: Ctx, path: string): SerializedNode {
|
|
527
603
|
const f: LayoutForm = l.form ?? { preset: 'contact' };
|
|
528
604
|
const frame = create(id, T.Container, {}, NO_ELEMENT_STYLE);
|
|
605
|
+
const scheme = layoutBandScheme(lc.section.ground);
|
|
606
|
+
if (scheme) setColorScheme(frame, scheme);
|
|
529
607
|
setStyleProps(frame, { display: 'flex', flexDirection: 'column', gap: '12px', color: 'var(--iox-text)' });
|
|
530
608
|
const parts: SerializedNode[] = [];
|
|
531
609
|
if (f.title) {
|
|
@@ -588,7 +666,7 @@ function composeLayer(l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
|
|
|
588
666
|
case LayoutLayerKind.Gallery: outer = entering = galleryLayer(id, l, lc, ctx); break;
|
|
589
667
|
case LayoutLayerKind.Button: outer = entering = buttonLayer(id, l, ctx); break;
|
|
590
668
|
case LayoutLayerKind.List: outer = entering = listLayer(id, l, ctx); break;
|
|
591
|
-
case LayoutLayerKind.Form: outer = entering = formLayer(id, l, ctx, lc.path); break;
|
|
669
|
+
case LayoutLayerKind.Form: outer = entering = formLayer(id, l, lc, ctx, lc.path); break;
|
|
592
670
|
case LayoutLayerKind.Marquee: outer = entering = marqueeLayer(id, l); break;
|
|
593
671
|
case LayoutLayerKind.Shape: outer = entering = shapeLayer(id, l); break;
|
|
594
672
|
default:
|
|
@@ -621,8 +699,8 @@ function composeLayer(l: LayoutLayer, lc: LayerCtx, ctx: Ctx): SerializedNode {
|
|
|
621
699
|
if (enter) entering.interactions = [...entering.interactions, enter];
|
|
622
700
|
if (image && l.enter === LayoutEnter.ClipReveal && l.role !== LayoutRole.Decoration) image.interactions = [...image.interactions, zoomInteraction(image.id, l, ctx)];
|
|
623
701
|
}
|
|
624
|
-
const depth = l
|
|
625
|
-
if (
|
|
702
|
+
const depth = layoutGlideDepth(lc.section, l);
|
|
703
|
+
if (depth) {
|
|
626
704
|
interactions.push(depthInteraction(outer.id, depth));
|
|
627
705
|
gap(ctx, LayoutGapCode.DepthSpeed, lc.path, `${depth} glides at the product's one speed`);
|
|
628
706
|
}
|
|
@@ -744,6 +822,8 @@ function composeSection(s: LayoutSection, si: number, prevGround: string | null,
|
|
|
744
822
|
// ── The header ──────────────────────────────────────────────────────────────────────────────────────────
|
|
745
823
|
|
|
746
824
|
const NAV_ROUTE = '/';
|
|
825
|
+
/** A layer's `to` starting with it names a page of the site, not a section of this one. */
|
|
826
|
+
const PAGE_ROUTE_MARK = '/';
|
|
747
827
|
|
|
748
828
|
/** The product's site header (composeNavHeader) with the layout's section links: each one scrolls to its section; in the
|
|
749
829
|
* phone menu it closes the drawer first. */
|
|
@@ -801,14 +881,23 @@ export function composeLayout(site: LayoutSite, options: ComposeLayoutOptions):
|
|
|
801
881
|
ease: LAYOUT_EASING[(site.motion?.ease ?? LayoutEase.Out) as LayoutEase] ?? LAYOUT_EASING[LayoutEase.Out],
|
|
802
882
|
sections: {},
|
|
803
883
|
gaps: [],
|
|
884
|
+
design: options.design ?? layoutDesignOf(site.look?.preset, options.mode),
|
|
804
885
|
photoSrc: options.photoSrc,
|
|
805
886
|
photoAlt: options.photoAlt ?? (() => ''),
|
|
806
887
|
photoAspect: id => LAYOUT_PHOTO_ASPECT[(options.photoShape?.(id) ?? LayoutPhotoShape.Landscape) as LayoutPhotoShape] ?? LAYOUT_PHOTO_ASPECT[LayoutPhotoShape.Landscape],
|
|
888
|
+
sourceFields: options.sourceFields ?? (() => null),
|
|
807
889
|
links: [],
|
|
808
890
|
headingSeen: false,
|
|
809
891
|
};
|
|
810
892
|
let prev: string | null = null;
|
|
811
893
|
const layout = site.sections.map((s, si) => {
|
|
894
|
+
if (s.readyMade) {
|
|
895
|
+
if (!options.readyMade) throw new ComposeError(`sections[${si}]: a ready-made place needs its plan section stamped (options.readyMade)`);
|
|
896
|
+
const node = options.readyMade(s, `${ctx.p}-s${si}`);
|
|
897
|
+
ctx.sections[s.id] = node.id;
|
|
898
|
+
prev = LayoutColour.Ground;
|
|
899
|
+
return node;
|
|
900
|
+
}
|
|
812
901
|
const node = composeSection(s, si, prev, ctx);
|
|
813
902
|
const ground = String(s.ground ?? LayoutColour.Ground);
|
|
814
903
|
prev = ground.startsWith('photo:') ? LayoutColour.Ink : ground;
|
|
@@ -24,6 +24,9 @@ import { SitePlanSourceKind, ContentFieldControl, ContentFieldPlan,
|
|
|
24
24
|
} from './site-plan.model';
|
|
25
25
|
import { assertValidSitePlan, nextSourceOf, routeParams } from './validate-site-plan';
|
|
26
26
|
import { NavShape, planNavShape } from './nav-shape';
|
|
27
|
+
import { composeLayout, LayoutColourMode } from './compose-layout';
|
|
28
|
+
import { LayoutGalleryList, LayoutPage, LayoutPhotoShape, LayoutPhotoSource, LayoutSite, parseLayoutPhotoId } from './layout-language';
|
|
29
|
+
import { layoutMotionOf, layoutPresetOf } from './layout-look';
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* THE composer — a Site Plan in, ordinary IOX data out (design-system plan §6b, W1). Deterministic and
|
|
@@ -108,6 +111,31 @@ export interface ComposeIssue {
|
|
|
108
111
|
export interface ComposeContext {
|
|
109
112
|
/** The calendar year the copyright line reads (`{year}`), from the caller's clock. */
|
|
110
113
|
year: number;
|
|
114
|
+
/** M8 gate 2: where a composed page's photo lives (`own:<assetId>`, `stock:<key>`; a `box:<shape>` has none). A
|
|
115
|
+
* photo with no address is the empty image box (DS3), publish-blocking like a pattern's. */
|
|
116
|
+
photoSrc?: (photoId: string) => string;
|
|
117
|
+
/** A photo's description ('' = decorative). */
|
|
118
|
+
photoAlt?: (photoId: string) => string;
|
|
119
|
+
/** A photo's shape (the inventory's); a `box:<shape>` id names its own. */
|
|
120
|
+
photoShape?: (photoId: string) => `${LayoutPhotoShape}` | undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Where a composed layout's photos are, as the server keeps them and the screens read them (M8 gate 2): id → address. */
|
|
124
|
+
export interface LayoutPhotoAddress {
|
|
125
|
+
url: string;
|
|
126
|
+
alt: string;
|
|
127
|
+
shape?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The composer's context for a site whose layouts name photos: the year, and each photo's address, words and shape. */
|
|
131
|
+
export function composeContextOf(year: number, photos?: Readonly<Record<string, LayoutPhotoAddress>>): ComposeContext {
|
|
132
|
+
if (!photos) return { year };
|
|
133
|
+
return {
|
|
134
|
+
year,
|
|
135
|
+
photoSrc: id => photos[id]?.url ?? '',
|
|
136
|
+
photoAlt: id => photos[id]?.alt ?? '',
|
|
137
|
+
photoShape: id => photos[id]?.shape as `${LayoutPhotoShape}` | undefined,
|
|
138
|
+
};
|
|
111
139
|
}
|
|
112
140
|
|
|
113
141
|
export interface ComposedPage {
|
|
@@ -118,8 +146,9 @@ export interface ComposedPage {
|
|
|
118
146
|
status: 'draft';
|
|
119
147
|
/** The site's language (L0-2): the page's locale — the fonts it loads, the side its entrances slide from. */
|
|
120
148
|
locale: `${SiteLocale}`;
|
|
121
|
-
/** DS3: every page the wizard creates follows the look (page-bg / text / font-body).
|
|
122
|
-
|
|
149
|
+
/** DS3: every page the wizard creates follows the look (page-bg / text / font-body). M8 gate 2: a composed page names
|
|
150
|
+
* the plan page its layout is (`layoutSource`; the build adds its run) — what Design ▸ Re-fit recomposes it from. */
|
|
151
|
+
pageSettings: { designSystem: true; layoutSource?: { pageKey: string; runId?: string } };
|
|
123
152
|
/** M1-6c: the page's search-result words — written (a static page) or bound to the route item (a template page),
|
|
124
153
|
* in the seo-core document shape the shared `resolveSeo` reads. */
|
|
125
154
|
seo: SeoRawDoc;
|
|
@@ -394,13 +423,31 @@ function stampedPageValue(path: string, ctx: Ctx, nodeId: string): string {
|
|
|
394
423
|
const isPageScope = (path: string | undefined) => !!path && path.split('.')[0] === BindScope.Page;
|
|
395
424
|
|
|
396
425
|
/** The content type behind a data source alias (a relative source reads its `within` list's type). */
|
|
397
|
-
function contentTypeOfSource(alias: string, plan: SitePlan): ContentTypePlan | undefined {
|
|
426
|
+
export function contentTypeOfSource(alias: string, plan: SitePlan): ContentTypePlan | undefined {
|
|
398
427
|
const ds = plan.dataSources.find(d => d.alias === alias);
|
|
399
428
|
if (!ds) return undefined;
|
|
400
429
|
if (ds.type === PlanDataSourceType.Relative) return contentTypeOfSource(ds.within, plan);
|
|
401
430
|
return plan.contentTypes.find(t => t.name === ds.contentType);
|
|
402
431
|
}
|
|
403
432
|
|
|
433
|
+
/** Every list a composed gallery could name (the plan's query sources), in plan order: what it is called and whether its
|
|
434
|
+
* items carry a picture (an `image` role). */
|
|
435
|
+
export function layoutGalleryLists(plan: SitePlan): LayoutGalleryList[] {
|
|
436
|
+
return plan.dataSources
|
|
437
|
+
.filter(d => d.type === PlanDataSourceType.Cms && d.mode === PlanDataSourceMode.Query)
|
|
438
|
+
.map(d => {
|
|
439
|
+
const type = contentTypeOfSource(d.alias, plan);
|
|
440
|
+
return { alias: d.alias, words: [d.alias, type?.name, type?.label].filter((w): w is string => !!w), pictures: !!roleField(type, 'image') };
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** The list sources a composed gallery may show (`gallery.source`): the plan's query sources whose items have a picture.
|
|
445
|
+
* A list with none (a FAQ) would repeat no slide and draw an empty band (iox-ui#59), so it is never offered and the check
|
|
446
|
+
* refuses it. */
|
|
447
|
+
export function layoutGallerySources(plan: SitePlan): string[] {
|
|
448
|
+
return layoutGalleryLists(plan).filter(l => l.pictures).map(l => l.alias);
|
|
449
|
+
}
|
|
450
|
+
|
|
404
451
|
function addBinding(node: SerializedNode, binding: SerializedBinding): void {
|
|
405
452
|
const declared = NODE_BASELINES[node.type]?.traits ?? [];
|
|
406
453
|
if (!declared.includes(binding.prop) && !binding.prop.startsWith('routeParam:')) {
|
|
@@ -1173,6 +1220,69 @@ function composeItems(type: ContentTypePlan, fillEmpty: boolean): ComposedItem[]
|
|
|
1173
1220
|
return items;
|
|
1174
1221
|
}
|
|
1175
1222
|
|
|
1223
|
+
const FACT_TOKEN = /\{fact:([a-zA-Z]+)\}/g;
|
|
1224
|
+
const LAYOUT_TEXT_PROPS: ReadonlyArray<string> = ['content', 'caption', 'alt', 'label', 'ariaLabel'];
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* M8 gate 2: a composed page — its layout stamped by `composeLayout` in the plan's look (the preset's composition
|
|
1228
|
+
* notes give the pace and ease), with the site's facts written in: a `{fact:<key>}` the owner gave becomes their words,
|
|
1229
|
+
* one they did not becomes the fact's label and a publish-blocking placeholder (never invented). A photo with no
|
|
1230
|
+
* address is the empty image box, a placeholder like a pattern's. The site's header and footer are the plan's globals.
|
|
1231
|
+
*/
|
|
1232
|
+
function composeLayoutPage(
|
|
1233
|
+
page: PagePlan, layout: LayoutPage, plan: SitePlan, context: ComposeContext, design: DesignChoices, placeholders: ComposedPlaceholder[],
|
|
1234
|
+
readyMade: (section: PageSectionPlan, id: string) => SerializedNode,
|
|
1235
|
+
): SerializedNode[] {
|
|
1236
|
+
const preset = layoutPresetOf(plan.design);
|
|
1237
|
+
const site: LayoutSite = {
|
|
1238
|
+
name: plan.business.name,
|
|
1239
|
+
locale: plan.locale ?? DEFAULT_SITE_LOCALE,
|
|
1240
|
+
dial: layout.dial,
|
|
1241
|
+
look: { preset: preset.id },
|
|
1242
|
+
motion: layoutMotionOf(preset.id),
|
|
1243
|
+
sections: layout.sections,
|
|
1244
|
+
};
|
|
1245
|
+
const boxShape = (id: string) => {
|
|
1246
|
+
const read = parseLayoutPhotoId(id);
|
|
1247
|
+
return read?.source === LayoutPhotoSource.Box ? (read.key as `${LayoutPhotoShape}`) : undefined;
|
|
1248
|
+
};
|
|
1249
|
+
const { layout: nodes } = composeLayout(site, {
|
|
1250
|
+
id: page.key,
|
|
1251
|
+
mode: design.mode === LayoutColourMode.Dark ? LayoutColourMode.Dark : LayoutColourMode.Light,
|
|
1252
|
+
design,
|
|
1253
|
+
readyMade: (s, id) => {
|
|
1254
|
+
const section = page.sections[s.readyMade!.at];
|
|
1255
|
+
if (!section) throw new ComposeError(`${page.key}: a ready-made place names plan section ${s.readyMade!.at}, which the page does not have`);
|
|
1256
|
+
return readyMade(section, id);
|
|
1257
|
+
},
|
|
1258
|
+
photoSrc: id => (boxShape(id) ? '' : context.photoSrc?.(id) ?? ''),
|
|
1259
|
+
photoAlt: id => (boxShape(id) ? '' : context.photoAlt?.(id) ?? ''),
|
|
1260
|
+
photoShape: id => boxShape(id) ?? context.photoShape?.(id),
|
|
1261
|
+
sourceFields: alias => {
|
|
1262
|
+
const type = contentTypeOfSource(alias, plan);
|
|
1263
|
+
const image = roleField(type, 'image');
|
|
1264
|
+
return image ? { image, ...(roleField(type, 'title') ? { title: roleField(type, 'title')! } : {}) } : null;
|
|
1265
|
+
},
|
|
1266
|
+
});
|
|
1267
|
+
const facts = plan.business.facts ?? {};
|
|
1268
|
+
walkSerialized(nodes, node => {
|
|
1269
|
+
for (const prop of LAYOUT_TEXT_PROPS) {
|
|
1270
|
+
const value = node.props[prop];
|
|
1271
|
+
if (typeof value !== 'string' || !value.includes('{fact:')) continue;
|
|
1272
|
+
const missing: FactKey[] = [];
|
|
1273
|
+
node.props[prop] = value.replace(FACT_TOKEN, (_, key: string) => {
|
|
1274
|
+
const given = (facts as Record<string, string | undefined>)[key];
|
|
1275
|
+
if (nonEmpty(given)) return given.trim();
|
|
1276
|
+
missing.push(key as FactKey);
|
|
1277
|
+
return SITE_FACT_LABELS[key as FactKey] ?? key;
|
|
1278
|
+
});
|
|
1279
|
+
for (const fact of missing) placeholders.push({ nodeId: node.id, owner: page.key, kind: PlaceholderKind.Fact, fact, text: String(node.props[prop]) });
|
|
1280
|
+
}
|
|
1281
|
+
if (node.type === IMAGE && !node.props['src'] && !node.bindings.length) placeholders.push({ nodeId: node.id, owner: page.key, kind: PlaceholderKind.Image, text: '' });
|
|
1282
|
+
});
|
|
1283
|
+
return nodes;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1176
1286
|
/**
|
|
1177
1287
|
* Compose a Site Plan. Throws `SitePlanError` (every issue) when the plan does not validate — the
|
|
1178
1288
|
* composer never repairs a plan. `context` carries what the composer may not read for itself (the year).
|
|
@@ -1192,6 +1302,15 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
|
|
|
1192
1302
|
const rtl = isRtlLocale(locale);
|
|
1193
1303
|
const pages: ComposedPage[] = plan.pages.map(page => {
|
|
1194
1304
|
const nextAlias = page.routeSource ? nextSourceOf(relatives, page.routeSource) : null;
|
|
1305
|
+
if (page.layout) {
|
|
1306
|
+
return {
|
|
1307
|
+
key: page.key, name: page.name, route: { path: page.route }, isHome: page.isHome === true, status: STATUS_DRAFT, locale,
|
|
1308
|
+
pageSettings: { designSystem: true, layoutSource: { pageKey: page.key } }, seo: composePageSeo(page, plan),
|
|
1309
|
+
layout: composeLayoutPage(page, page.layout, plan, context, design, placeholders, (section, id) =>
|
|
1310
|
+
composePattern(patternById(section.pattern) as SitePattern, id, { ...base, owner: page.key, page, section, nextAlias },
|
|
1311
|
+
{ level: section.enter ?? design.animate ?? null, rtl })),
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1195
1314
|
const layout = page.sections.map((section, i) => {
|
|
1196
1315
|
const pattern = patternById(section.pattern) as SitePattern;
|
|
1197
1316
|
const motion: SectionMotion = { level: section.enter ?? design.animate ?? null, rtl };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words that carry no subject in the languages a site is written in (English, Hebrew): "the", "with", "our", "כמו",
|
|
3
|
+
* "שלנו"… Shared by every comparison of meaning by words — a stock photo against a slot (`stockWords`), a model's section
|
|
4
|
+
* against a ready-made one (silent section fallback). Lower case; only words of three letters or more (shorter ones never
|
|
5
|
+
* count anywhere).
|
|
6
|
+
*/
|
|
7
|
+
export const FUNCTION_WORDS: ReadonlySet<string> = new Set([
|
|
8
|
+
'the', 'and', 'with', 'for', 'your', 'our', 'you', 'from', 'into', 'this', 'that', 'here', 'there', 'about', 'how', 'what',
|
|
9
|
+
'who', 'are', 'all', 'but', 'not', 'was', 'were', 'has', 'have', 'had', 'its', 'they', 'them', 'their', 'then', 'than',
|
|
10
|
+
'when', 'where', 'which', 'will', 'can', 'just', 'out', 'over', 'under', 'onto', 'each', 'every', 'some', 'any', 'one', 'also',
|
|
11
|
+
'too', 'very', 'more', 'most', 'less', 'only', 'own', 'yours', 'ours', 'these', 'those',
|
|
12
|
+
'אנחנו', 'אני', 'הוא', 'היא', 'אתם', 'אתן', 'שלנו', 'שלכם', 'שלך', 'שלו', 'שלה', 'אצלנו', 'כמו', 'אבל', 'זאת', 'כאן', 'יותר',
|
|
13
|
+
'מאוד', 'כבר', 'עוד', 'אחרי', 'לפני', 'בין', 'כדי', 'איך',
|
|
14
|
+
]);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeParallaxPhone, parallaxOffset, parallaxRest, parallaxShift, ParallaxDepth, rangeDistance, rangeProgress, ScrollRange,
|
|
3
|
+
} from '@vectoriox/iox-ui/scene-core';
|
|
4
|
+
|
|
5
|
+
import { LAYOUT_DEPTH_ON_PHONE, LAYOUT_OPERATED, LayoutDepth, LayoutLayer, LayoutSection } from './layout-language';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Motion ON, judged without playing it (iox-ui#65). A layer at a depth glides against the page while it passes, so two
|
|
9
|
+
* layers at different depths move toward or away from each other as the page scrolls. The render check measures the page
|
|
10
|
+
* at rest; this replays the scroll over those boxes with the runtime's own maths (scene-core `parallaxShift` ·
|
|
11
|
+
* `parallaxRest` · `parallaxOffset`, the `cover` range the composer gives every depth) and says where two of them meet on
|
|
12
|
+
* screen. The same maths guards the depth mend (`checkLayout`), so a depth the composer adds can never cause one.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** A box in the page's px, the page's top at 0. */
|
|
16
|
+
export interface DriftBox { l: number; t: number; r: number; b: number }
|
|
17
|
+
|
|
18
|
+
/** One layer as the scroll sees it: where it stands at rest and the depth it glides at, if any. */
|
|
19
|
+
export interface DriftLayer {
|
|
20
|
+
box: DriftBox;
|
|
21
|
+
depth: `${ParallaxDepth}` | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Where two layers meet as the page scrolls: the scroll (px from the top) where they overlap most, and by how much. */
|
|
25
|
+
export interface DriftMeeting {
|
|
26
|
+
scroll: number;
|
|
27
|
+
overlap: DriftBox;
|
|
28
|
+
area: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The scroll is replayed in steps this long (px). */
|
|
32
|
+
const STEP_PX = 4;
|
|
33
|
+
|
|
34
|
+
/** The depth a layer glides at in a section, as the composer stamps it — or null (mid, a held section, what a visitor
|
|
35
|
+
* operates). ONE rule: `composeLayout` stamps by it, the render check and the depth mend replay by it. */
|
|
36
|
+
export function layoutGlideDepth(section: Pick<LayoutSection, 'pin'>, layer: Pick<LayoutLayer, 'depth' | 'kind'>): `${ParallaxDepth}` | null {
|
|
37
|
+
if (section.pin || !layer.depth || layer.depth === LayoutDepth.Mid || LAYOUT_OPERATED.has(layer.kind)) return null;
|
|
38
|
+
return layer.depth === LayoutDepth.Front ? ParallaxDepth.Front : ParallaxDepth.Back;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** How far a layer at `depth` stands off its place with the page scrolled `scroll` px, on a screen `viewHeight` tall. */
|
|
42
|
+
export function driftAt(layer: DriftLayer, scroll: number, viewHeight: number, phone = false): number {
|
|
43
|
+
if (!layer.depth) return 0;
|
|
44
|
+
const view = { top: 0, height: viewHeight };
|
|
45
|
+
const height = layer.box.b - layer.box.t;
|
|
46
|
+
const shift = parallaxShift(rangeDistance(ScrollRange.Cover, { top: layer.box.t, height }, view), viewHeight, { phone, onPhone: normalizeParallaxPhone(LAYOUT_DEPTH_ON_PHONE) });
|
|
47
|
+
if (!shift) return 0;
|
|
48
|
+
const rest = parallaxRest(rangeProgress(ScrollRange.Cover, { top: layer.box.t, height }, view));
|
|
49
|
+
const progress = rangeProgress(ScrollRange.Cover, { top: layer.box.t - scroll, height }, view);
|
|
50
|
+
return parallaxOffset(layer.depth as ParallaxDepth, shift, progress, rest);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const meet = (a: DriftBox, b: DriftBox): DriftBox => ({ l: Math.max(a.l, b.l), t: Math.max(a.t, b.t), r: Math.min(a.r, b.r), b: Math.min(a.b, b.b) });
|
|
54
|
+
const areaOf = (r: DriftBox) => Math.max(0, r.r - r.l) * Math.max(0, r.b - r.t);
|
|
55
|
+
const moved = (r: DriftBox, dy: number): DriftBox => ({ l: r.l, r: r.r, t: r.t + dy, b: r.b + dy });
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Where two layers overlap most on screen while the page scrolls past them, at least one gliding — inside `clip` (their
|
|
59
|
+
* section, which clips a glide) — or null when they never meet more than they already do at rest. `pageHeight` bounds the
|
|
60
|
+
* scroll. Pure: the same answer in the browser and the server.
|
|
61
|
+
*/
|
|
62
|
+
export function driftOverlap(a: DriftLayer, b: DriftLayer, view: { width: number; height: number; pageHeight: number; phone?: boolean }, clip?: DriftBox): DriftMeeting | null {
|
|
63
|
+
if (!a.depth && !b.depth) return null;
|
|
64
|
+
const rest = areaOf(clip ? meet(meet(a.box, b.box), clip) : meet(a.box, b.box));
|
|
65
|
+
const from = Math.max(0, Math.min(a.box.t, b.box.t) - view.height);
|
|
66
|
+
const to = Math.min(Math.max(0, view.pageHeight - view.height), Math.max(a.box.b, b.box.b));
|
|
67
|
+
let best: DriftMeeting | null = null;
|
|
68
|
+
for (let scroll = from; scroll <= to; scroll += STEP_PX) {
|
|
69
|
+
const screen: DriftBox = { l: 0, r: view.width, t: scroll, b: scroll + view.height };
|
|
70
|
+
const ra = moved(a.box, driftAt(a, scroll, view.height, view.phone));
|
|
71
|
+
const rb = moved(b.box, driftAt(b, scroll, view.height, view.phone));
|
|
72
|
+
let overlap = meet(meet(ra, rb), screen);
|
|
73
|
+
if (clip) overlap = meet(overlap, clip);
|
|
74
|
+
const area = areaOf(overlap);
|
|
75
|
+
if (area > rest && (!best || area > best.area)) best = { scroll, overlap: moved(overlap, -scroll), area };
|
|
76
|
+
}
|
|
77
|
+
return best;
|
|
78
|
+
}
|