@vectoriox/iox-ui 5.135.0 → 5.137.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/composite-core/index.d.ts +15 -2
  2. package/design-core/index.d.ts +184 -9
  3. package/fesm2022/vectoriox-iox-ui-assist-core.mjs +6 -36
  4. package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
  5. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +28 -1
  6. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  7. package/fesm2022/vectoriox-iox-ui-design-core.mjs +296 -48
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  9. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1269 -154
  10. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  11. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +7 -3
  12. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  13. package/fesm2022/vectoriox-iox-ui.mjs +355 -2
  14. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  15. package/generation-core/index.d.ts +481 -89
  16. package/harness-core/index.d.ts +4 -2
  17. package/index.d.ts +105 -3
  18. package/package.json +1 -1
  19. package/src/assist-core/page-sections.ts +4 -31
  20. package/src/composite-core/slider.ts +35 -0
  21. package/src/design-core/design-settings.ts +16 -3
  22. package/src/design-core/design-token.model.ts +3 -0
  23. package/src/design-core/flavor-spec.generated.ts +98 -25
  24. package/src/design-core/motion-language.ts +12 -9
  25. package/src/design-core/preloader-of.ts +26 -0
  26. package/src/design-core/preloader.ts +174 -0
  27. package/src/design-core/public-api.ts +2 -0
  28. package/src/design-core/style-presets.ts +3 -1
  29. package/src/generation-core/carry.ts +37 -0
  30. package/src/generation-core/compose-site.ts +222 -9
  31. package/src/generation-core/node-baselines.generated.ts +2 -1
  32. package/src/generation-core/opening-edit.ts +240 -0
  33. package/src/generation-core/opening-mix.ts +639 -0
  34. package/src/generation-core/patterns.ts +3 -0
  35. package/src/generation-core/plan-wire.ts +26 -4
  36. package/src/generation-core/public-api.ts +2 -0
  37. package/src/generation-core/redesign-run.ts +42 -2
  38. package/src/generation-core/site-build-run.ts +27 -1
  39. package/src/generation-core/site-plan.model.ts +3 -1
  40. package/src/generation-core/site-spec.generated.ts +137 -84
  41. package/src/generation-core/validate-site-plan.ts +5 -3
  42. package/src/harness-core/starting-design.ts +8 -4
  43. package/styles/iox-design.css +32 -0
@@ -45,15 +45,17 @@ export interface MotionLanguage {
45
45
  export const isArriveId = (v: unknown): v is ArriveId => typeof v === 'string' && (ARRIVE_IDS as ReadonlyArray<string>).includes(v);
46
46
  export const isMoveId = (v: unknown): v is MoveId => typeof v === 'string' && (MOVE_IDS as ReadonlyArray<string>).includes(v);
47
47
 
48
- const PRESET_LANGUAGE = L.presets as Readonly<Record<string, { arrive: ArriveId; leave: LeaveId; move: MoveId }>>;
48
+ const PRESET_LANGUAGE = L.presets as Readonly<Record<string, { arrive: ArriveId; leave: LeaveId; move: MoveId; preloader: string; preloaderExit: string }>>;
49
49
  const LEAVE_FOR = L.leaveFor as Readonly<Record<ArriveId, LeaveId>>;
50
- /** The families a word's tier is asked of: the arrive / leave curves, the heading move, the cover between pages (AW4). */
51
- export type MotionWordKind = 'arrive' | 'leave' | 'move' | 'cover';
50
+ /** The families a word's tier is asked of: the arrive / leave curves, the heading move, the cover between pages (AW4),
51
+ * the first-visit preloader (AW5). */
52
+ export type MotionWordKind = 'arrive' | 'leave' | 'move' | 'cover' | 'preloader';
52
53
  const TIERS = L.tiers as Readonly<Record<MotionWordKind, Readonly<Record<string, `${MotionWordTier}`>>>>;
53
- const PLAN_FALLBACK = L.planFallback as Readonly<{ arrive: ArriveId; move: MoveId; cover: string }>;
54
+ const PLAN_FALLBACK = L.planFallback as Readonly<{ arrive: ArriveId; move: MoveId; cover: string; preloader: string }>;
54
55
 
55
- /** A style preset's own language (its Feel and Headings arrive) — undefined for an unknown id. */
56
- export function presetMotionLanguage(presetId: string | null | undefined): { arrive: ArriveId; leave: LeaveId; move: MoveId } | undefined {
56
+ /** A style preset's own language (its Feel, Headings arrive and first-visit preloader with its exit) — undefined for an
57
+ * unknown id. */
58
+ export function presetMotionLanguage(presetId: string | null | undefined): { arrive: ArriveId; leave: LeaveId; move: MoveId; preloader: string; preloaderExit: string } | undefined {
57
59
  return presetId ? PRESET_LANGUAGE[presetId] : undefined;
58
60
  }
59
61
 
@@ -88,16 +90,17 @@ export function motionCurve(word: ArriveId | LeaveId, tokenValue: (name: string)
88
90
 
89
91
  /**
90
92
  * What a lower plan wears of a language (AW-D23, MB-D6): a Pro word is drawn as the plan's own (the contract's
91
- * `planFallback`) — Feel today's arrival, a Pro move a fade, a Pro cover (AW4) a fade between pages. Applied where a
92
- * look is CHOSEN (a Look pick, a build); a built site keeps its words.
93
+ * `planFallback`) — Feel today's arrival, a Pro move a fade, a Pro cover (AW4) a fade between pages, a preloader (AW5)
94
+ * none. Applied where a look is CHOSEN (a Look pick, a build); a built site keeps its words.
93
95
  */
94
- export function motionLanguageForPlan<T extends Pick<DesignChoices, 'feel' | 'headings'> & { between?: DesignChoices['between'] }>(choices: T, pro: boolean): T {
96
+ export function motionLanguageForPlan<T extends Pick<DesignChoices, 'feel' | 'headings'> & { between?: DesignChoices['between']; preloader?: DesignChoices['preloader'] }>(choices: T, pro: boolean): T {
95
97
  if (pro) return choices;
96
98
  const proWord = (kind: MotionWordKind, word: unknown) => typeof word === 'string' && motionWordTier(kind, word) === MotionWordTier.Pro;
97
99
  const feel = isArriveId(choices.feel) && proWord('arrive', choices.feel) ? PLAN_FALLBACK.arrive : choices.feel;
98
100
  const headings = isMoveId(choices.headings) && proWord('move', choices.headings) ? PLAN_FALLBACK.move : choices.headings;
99
101
  const out = { ...choices, feel, headings };
100
102
  if (proWord('cover', choices.between)) out.between = PLAN_FALLBACK.cover as DesignChoices['between'];
103
+ if (proWord('preloader', choices.preloader)) out.preloader = PLAN_FALLBACK.preloader;
101
104
  return out;
102
105
  }
103
106
 
@@ -0,0 +1,26 @@
1
+ import { DesignConfigEntry, readDesignConfig } from './design-settings';
2
+ import type { DesignChoices } from './design-token.model';
3
+ import { planPreloader, PreloaderPlan } from './preloader';
4
+ import { stylePresetOfChoices } from './style-presets';
5
+
6
+ /**
7
+ * What a look opens a visitor's first page with (AW5, PL-D1/D3/D6): the kind is the look's word, the exit the style
8
+ * preset it is (`stylePresetOfChoices`; a customised look fades), the cap the contract's. A built site keeps its word
9
+ * (AW-D23: the plan clamp happened when the look was chosen), so this asks as Pro unless told otherwise; the visitor's
10
+ * side — reduced motion, a first visit — is the browser's to say (`preloaderHeadScript`). Null when it opens with nothing.
11
+ */
12
+ export function preloaderOfChoices(choices: Pick<DesignChoices, 'preloader' | 'animate'> & Partial<DesignChoices> | null | undefined, pro = true): PreloaderPlan | null {
13
+ if (!choices?.preloader) return null;
14
+ return planPreloader({
15
+ preloader: choices.preloader, animate: choices.animate,
16
+ presetId: stylePresetOfChoices(choices as DesignChoices)?.id ?? null,
17
+ pro, reducedMotion: false, firstVisit: true,
18
+ });
19
+ }
20
+
21
+ /** A STORED design's preloader — what the public page read hands the engine (`designPreloader`), beside
22
+ * `designMode` / `designMotion`. */
23
+ export function designPreloaderOf(config: ReadonlyArray<DesignConfigEntry> | null | undefined): PreloaderPlan | null {
24
+ const { choices, hasRow } = readDesignConfig(config);
25
+ return hasRow ? preloaderOfChoices(choices) : null;
26
+ }
@@ -0,0 +1,174 @@
1
+ import { SPEC_MOTION_LANGUAGE } from './flavor-spec.generated';
2
+ import { MotionWordTier, motionWordTier, presetMotionLanguage } from './motion-language';
3
+
4
+ /**
5
+ * THE FIRST-VISIT PRELOADER (award-ingredients-plan §5.3, AW5; Preloader board PL-D1…PL-D9) — pure, framework-free.
6
+ *
7
+ * A look may open a visitor's FIRST page of a session with a short preloader — the brand mark, a 0 → 100 count of real
8
+ * loading, or the opening's first words letter by letter — that leaves by the look's own exit. ONE decision here
9
+ * (`planPreloader`) for the engine's runtime, every builder preview and the generator; the rules are the contract's
10
+ * (`layout.mjs` MOTION → `SPEC_MOTION_LANGUAGE`): ≤ `preloaderCapMs`, Lively / Expressive looks only, a Pro word, never
11
+ * under reduced motion, never on a return visit. The page's words are always painted under it (T1); it never holds the
12
+ * scroll — a scroll, key or tap ends it (PL-D4).
13
+ */
14
+
15
+ const L = SPEC_MOTION_LANGUAGE;
16
+
17
+ /** What opens the first visit (`design.preloader`). */
18
+ export enum PreloaderKind {
19
+ None = 'none',
20
+ /** The header's brand — its logo, else the business name in the display face. */
21
+ Mark = 'mark',
22
+ /** A 0 → 100 count of the first screen's real loading (pictures + fonts), in the display face. */
23
+ Counter = 'counter',
24
+ /** The opening heading's first words, letter by letter. */
25
+ Letters = 'letters',
26
+ }
27
+
28
+ /** How it leaves — the look's own, never a separate choice (PL-D3). */
29
+ export enum PreloaderExit {
30
+ None = 'none',
31
+ Fade = 'fade',
32
+ /** An accent panel leaves upward. */
33
+ Sweep = 'sweep',
34
+ /** A frame grows from the centre. */
35
+ Window = 'window',
36
+ /** The whole layer rises away. */
37
+ Lift = 'lift',
38
+ }
39
+
40
+ export const PRELOADER_IDS: ReadonlyArray<string> = L.preloader;
41
+ export const PRELOADER_EXIT_IDS: ReadonlyArray<string> = L.preloaderExit;
42
+ /** AW-D7: a preloader leaves at the first screen's readiness or this many ms, whichever first. */
43
+ export const PRELOADER_CAP_MS: number = L.preloaderCapMs;
44
+ /** The How animated levels a preloader is offered on. */
45
+ export const PRELOADER_LEVELS: ReadonlyArray<string> = L.preloaderLevels;
46
+ /** A preloader's exit takes at most this long (Emil: exits are short; ≤ the covers' uncover). */
47
+ export const PRELOADER_EXIT_MAX_MS = 500;
48
+ /** Letters shows the opening heading only while it is this short (PL-D2); a longer one shows the business name. */
49
+ export const PRELOADER_LETTERS_MAX = 24;
50
+ /** A preloader never leaves before its own entrance is seen (board 2) — still never past the cap. */
51
+ export const PRELOADER_MIN_SHOW_MS: Readonly<Record<Exclude<PreloaderKind, PreloaderKind.None>, number>> = {
52
+ [PreloaderKind.Mark]: 450, [PreloaderKind.Counter]: 450, [PreloaderKind.Letters]: 700,
53
+ };
54
+ /** The fast ease-out a preloader leaves on when the look names no `ease-exit` (MB-D1's quart-out). */
55
+ export const PRELOADER_EXIT_EASE = 'cubic-bezier(0.25, 1, 0.5, 1)';
56
+ /** The ease-out its content arrives on when the look names no `ease-enter` (expo-out). */
57
+ export const PRELOADER_ENTER_EASE = 'cubic-bezier(0.16, 1, 0.3, 1)';
58
+
59
+ export const isPreloaderKind = (v: unknown): v is `${PreloaderKind}` => typeof v === 'string' && PRELOADER_IDS.includes(v);
60
+
61
+ /** What the runtime draws: the kind, the look's exit, and its cap. */
62
+ export interface PreloaderPlan {
63
+ readonly kind: Exclude<PreloaderKind, PreloaderKind.None>;
64
+ readonly exit: Exclude<PreloaderExit, PreloaderExit.None>;
65
+ readonly capMs: number;
66
+ }
67
+
68
+ /** Everything the decision needs; each renderer fills what only it can see. */
69
+ export interface PreloaderInput {
70
+ /** The look's choice (`design.preloader`); absent = none. */
71
+ readonly preloader: string | null | undefined;
72
+ /** The look's How animated (`design.animate`). */
73
+ readonly animate: string | null | undefined;
74
+ /** The style preset the look came from — its exit (`MOTION.presets`); absent or exit-less → Fade. */
75
+ readonly presetId?: string | null;
76
+ /** The studio's plan carries the Pro words (`GenerationTier.Award`). A built site keeps its word (AW-D23): pass true
77
+ * for a stored design — the clamp happens where a look is CHOSEN (`motionLanguageForPlan`). */
78
+ readonly pro: boolean;
79
+ /** The visitor asked for reduced motion. */
80
+ readonly reducedMotion: boolean;
81
+ /** This is the session's first page in this tab, not reached from another page of the site (`isFirstVisit`). */
82
+ readonly firstVisit: boolean;
83
+ }
84
+
85
+ /** The ONE decision: what opens this visit, or null for nothing (the page is simply there). */
86
+ export function planPreloader(input: PreloaderInput): PreloaderPlan | null {
87
+ const kind = input.preloader;
88
+ if (!isPreloaderKind(kind) || kind === PreloaderKind.None) return null;
89
+ if (input.reducedMotion || !input.firstVisit) return null;
90
+ if (!PRELOADER_LEVELS.includes(String(input.animate ?? ''))) return null;
91
+ if (!input.pro && motionWordTier('preloader', kind) === MotionWordTier.Pro) return null;
92
+ return { kind: kind as PreloaderPlan['kind'], exit: preloaderExitOf(input.presetId), capMs: PRELOADER_CAP_MS };
93
+ }
94
+
95
+ /** The look's exit (PL-D3): the preset's own, else a fade. */
96
+ export function preloaderExitOf(presetId: string | null | undefined): PreloaderPlan['exit'] {
97
+ const own = presetMotionLanguage(presetId ?? null)?.preloaderExit;
98
+ return own && own !== PreloaderExit.None && PRELOADER_EXIT_IDS.includes(own) ? (own as PreloaderPlan['exit']) : PreloaderExit.Fade;
99
+ }
100
+
101
+ /**
102
+ * When it leaves (PL-D4): at the page's readiness — never before its own entrance is seen (`minMs`), never past the cap;
103
+ * a readiness not yet known waits for the cap.
104
+ */
105
+ export function preloaderLeaveAt(readyMs: number | null | undefined, capMs: number = PRELOADER_CAP_MS, minMs = 0): number {
106
+ if (typeof readyMs !== 'number' || !Number.isFinite(readyMs) || readyMs < 0) return capMs;
107
+ return Math.min(Math.max(readyMs, minMs), capMs);
108
+ }
109
+
110
+ /** How a preloader leaves — frames (transform / opacity / clip-path only), a duration ≤ `PRELOADER_EXIT_MAX_MS`, and
111
+ * whether the layer turns the accent panel first (Sweep). */
112
+ export interface PreloaderExitMotion {
113
+ readonly frames: ReadonlyArray<Readonly<Record<string, string | number>>>;
114
+ readonly duration: number;
115
+ readonly accent: boolean;
116
+ }
117
+
118
+ /** Window's frame: the layer with a centred rectangular hole `x`% / `y`% in from each edge (even-odd). */
119
+ const windowHole = (x: number, y: number) =>
120
+ `polygon(evenodd, 0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%, ${x}% ${y}%, ${100 - x}% ${y}%, ${100 - x}% ${100 - y}%, ${x}% ${100 - y}%, ${x}% ${y}%)`;
121
+
122
+ const EXIT_MOTION: Readonly<Record<PreloaderPlan['exit'], PreloaderExitMotion>> = {
123
+ [PreloaderExit.Fade]: { frames: [{ opacity: 1 }, { opacity: 0 }], duration: 300, accent: false },
124
+ [PreloaderExit.Lift]: { frames: [{ transform: 'translateY(0)' }, { transform: 'translateY(-100%)' }], duration: 450, accent: false },
125
+ [PreloaderExit.Sweep]: { frames: [{ clipPath: 'inset(0% 0% 0% 0%)' }, { clipPath: 'inset(0% 0% 100% 0%)' }], duration: 420, accent: true },
126
+ [PreloaderExit.Window]: {
127
+ frames: [{ clipPath: windowHole(50, 50) }, { clipPath: windowHole(38, 40), offset: 0.25 }, { clipPath: windowHole(-1, -1) }],
128
+ duration: 480, accent: false,
129
+ },
130
+ };
131
+
132
+ /** The ONE description of each exit (PL-D3; Emil: transform / opacity / clip-path, ≤ 500 ms, on the look's ease-exit). */
133
+ export function preloaderExitMotion(exit: string | null | undefined): PreloaderExitMotion {
134
+ return EXIT_MOTION[exit as PreloaderPlan['exit']] ?? EXIT_MOTION[PreloaderExit.Fade];
135
+ }
136
+
137
+ /** A text as a reader sees its letters — a Hebrew letter keeps its points, an emoji its joiners (`Intl.Segmenter`). */
138
+ export function preloaderGraphemes(text: string): string[] {
139
+ const Seg = (Intl as unknown as { Segmenter?: new (l?: string, o?: { granularity: string }) => { segment(s: string): Iterable<{ segment: string }> } }).Segmenter;
140
+ if (!Seg) return Array.from(text);
141
+ return Array.from(new Seg(undefined, { granularity: 'grapheme' }).segment(text), s => s.segment);
142
+ }
143
+
144
+ /**
145
+ * PL-D5: a first visit is the session's first page in this tab AND not reached from another page of the same site
146
+ * (a new tab opened from the site, a reload after Back). `seen` = the tab's session memory; `referrer` and `origin`
147
+ * as the browser reports them.
148
+ */
149
+ export function isFirstVisit(seen: boolean, referrer: string | null | undefined, origin: string | null | undefined): boolean {
150
+ if (seen) return false;
151
+ if (!referrer || !origin) return true;
152
+ try {
153
+ return new URL(referrer).origin !== new URL(origin).origin;
154
+ } catch {
155
+ return true;
156
+ }
157
+ }
158
+
159
+ /**
160
+ * The counter's number (PL-D2): real loading only — `loaded` of `total` first-screen resources, a whole percent that
161
+ * never goes back; nothing to load reads 100. Never a timer.
162
+ */
163
+ export function preloaderPercent(loaded: number, total: number, previous = 0): number {
164
+ const t = Math.max(0, Math.floor(total));
165
+ const raw = t === 0 ? 100 : Math.floor((100 * Math.min(Math.max(0, loaded), t)) / t);
166
+ return Math.max(Math.min(100, Math.max(0, Math.floor(previous))), raw);
167
+ }
168
+
169
+ /** PL-D2: what Letters spells — the opening heading while it is short enough, else the business name. */
170
+ export function preloaderWords(heading: string | null | undefined, businessName: string | null | undefined): string {
171
+ const h = String(heading ?? '').replace(/\s+/g, ' ').trim();
172
+ if (h && preloaderGraphemes(h).length <= PRELOADER_LETTERS_MAX) return h;
173
+ return String(businessName ?? '').replace(/\s+/g, ' ').trim() || preloaderGraphemes(h).slice(0, PRELOADER_LETTERS_MAX).join('');
174
+ }
@@ -37,3 +37,5 @@ export * from './design-settings';
37
37
  export * from './design-apply';
38
38
  export * from './style-presets';
39
39
  export * from './motion-language';
40
+ export * from './preloader';
41
+ export * from './preloader-of';
@@ -71,8 +71,10 @@ export function presetChoices(id: string, mode?: DesignMode): DesignChoices | nu
71
71
  return resolveDesignChoices({
72
72
  flavorId: preset.flavorId, seed: preset.seed, pairId: preset.pairId, shape: preset.shape, density: preset.density,
73
73
  motion: preset.motion, pillButtons: preset.pillButtons, mode: wear, tint: preset.tint, ...preset.moves,
74
- // AW3: the look's own motion language — its Feel and how its headings arrive (MB-D5).
74
+ // AW3: the look's own motion language — its Feel and how its headings arrive (MB-D5); AW5: its first-visit
75
+ // preloader (PL-D1 — the exit is the preset's, never stored).
75
76
  feel: presetMotionLanguage(preset.id)?.arrive, headings: presetMotionLanguage(preset.id)?.move,
77
+ preloader: presetMotionLanguage(preset.id)?.preloader,
76
78
  });
77
79
  }
78
80
 
@@ -396,3 +396,40 @@ export function describeCarryForPrompt(carry: PageCarry): string {
396
396
  ];
397
397
  return lines.join('\n');
398
398
  }
399
+
400
+ /** A button's link (where it leads, how it opens) carried onto another button. */
401
+ export function carryButtonLink(from: SerializedNode, to: SerializedNode): void {
402
+ const link = Object.fromEntries(BUTTON_LINK_PROPS.filter(k => k in (from.props ?? {})).map(k => [k, from.props[k]]));
403
+ to.props = { ...to.props, ...link };
404
+ }
405
+
406
+ /**
407
+ * The owner's words and pictures, placed from one section into another part for part (kind by kind, in reading order,
408
+ * a button with its link) — Ask's swap rule (AI2d), shared. Returns the parts that held content and found no place.
409
+ */
410
+ export function carryInto(from: SerializedNode, to: SerializedNode): SerializedNode[] {
411
+ const old = swapParts(from);
412
+ const fresh = swapParts(to);
413
+ const lost: SerializedNode[] = [];
414
+ for (const kind of SWAP_CARRY_KINDS) {
415
+ old[kind].forEach((source, i) => {
416
+ const target = fresh[kind][i];
417
+ if (!target) {
418
+ if (kind !== CarryKind.Image || source.props['src']) lost.push(source);
419
+ return;
420
+ }
421
+ if (kind === CarryKind.Image) {
422
+ if (!source.props['src']) return;
423
+ target.props = { ...target.props, src: source.props['src'], alt: source.props['alt'] ?? target.props['alt'] };
424
+ } else if (kind === CarryKind.Button) {
425
+ const words = (source.children ?? []).find(c => c.type === 'Text');
426
+ const into = (target.children ?? []).find(c => c.type === 'Text');
427
+ if (words && into) into.props = { ...into.props, content: words.props['content'] };
428
+ carryButtonLink(source, target);
429
+ } else {
430
+ target.props = { ...target.props, content: source.props['content'] };
431
+ }
432
+ });
433
+ }
434
+ return lost;
435
+ }
@@ -1,4 +1,4 @@
1
- import type { PageCarry } from './carry';
1
+ import { carryInto, swapParts, type PageCarry } from './carry';
2
2
  import {
3
3
  AnimateId, COLOR_SCHEME_TRAIT, COLOR_SCHEMES, ColorScheme, colorSchemeClass, DEFAULT_MENU_LOOK, DesignChoices, LinkType, MenuLook, motionLanguageForPlan, resolveDesignChoices, setColorScheme,
4
4
  } from '@vectoriox/iox-ui/design-core';
@@ -6,7 +6,7 @@ import { SEO_DESCRIPTION_MAX, SEO_TITLE_MAX, SeoRawDoc } from '@vectoriox/iox-ui
6
6
  import { channelOpensNewTab, FORM_ACTIONS_ROLE, FORM_CHANNEL_ROLE, FormPresetChannel, FormPresetDef, FormPresetField, formPresetById, presetFormActions } from '@vectoriox/iox-ui/forms-core';
7
7
  import {
8
8
  ACCORDION_BIND_PROP, ACCORDION_CONTENT_LIMIT, ACCORDION_WORDS, accordionAnswerOf, accordionItems, accordionQuestionOf, AccordionRole,
9
- buildAccordionRecipe, buildCardRecipe, buildCarouselRecipe, buildLightboxRecipe, CardLayout, CardPart, CardRole, CARD_LAYOUTS, CARD_PARTS, CompositeNode,
9
+ buildAccordionRecipe, buildCardRecipe, buildCarouselRecipe, buildLightboxRecipe, buildSlideshowRecipe, CardLayout, CardPart, CardRole, CARD_LAYOUTS, CARD_PARTS, CompositeNode,
10
10
  AccordionAutoBinds, CompositeNodeSpec, findByRole, LIGHTBOX_LABEL, SLIDE_TO_ROW, SLIDE_TYPE, buildTabsRecipe, tabLabelNodeOf,
11
11
  tabPanelImageOf, tabPanelTextOf, tabsListOf, tabsPanels, tabsPanelsOf, tabsTriggers, TABS_CONTENT_LIMIT, TABS_IMAGE_BIND_PROP, TABS_LABEL_BIND_PROP,
12
12
  TABS_TEXT_BIND_PROP, TABS_WORDS, TabsAutoBinds, BadgeTone, BADGE_TONES, buildSegmentedRecipe, CardWords, ITEM_OPEN_STATE, segmentedOptions,
@@ -22,6 +22,7 @@ import {
22
22
  countryLegalFacts, FOOTER_LEGAL_ROLE, FORM_LEGAL_ROLE, formAsksPersonalData, formLegalFacts, LEGAL_PAGE_SETTING, LegalContext, LegalFact, LegalFacts,
23
23
  legalFormLine, LegalKind, legalKindsFor, legalLabel, legalRoute, legalTitle,
24
24
  } from './legal';
25
+ import { checkOpening, drawnOpeningMix, OpeningContext, openingMix, OpeningMix, openingMixOfPlan, openingRecipe, OpeningRole, stampOpeningMix } from './opening-mix';
25
26
  import { checkHeader, drawnHeaderMix, HeaderContext, headerContextOfPlan, headerMix, HeaderMix, headerRecipe, HeaderRecipe, stampHeaderMix, wornHeaderOfPlan } from './header-mix';
26
27
  import { NODE_BASELINES } from './node-baselines.generated';
27
28
  import {
@@ -114,6 +115,9 @@ export enum ComposeIssueCode {
114
115
  /** HI1: the header's mix asked for what the site cannot carry (`checkHeader`), or for a word the product does not draw
115
116
  * yet (drawn as its stand-in): the detail says how. */
116
117
  HeaderMended = 'header-mended',
118
+ /** AW8: the opening's mix asked for what the site cannot carry (`checkOpening`), or for a word the product does not
119
+ * draw yet (drawn as its stand-in): the detail says how. */
120
+ OpeningMended = 'opening-mended',
117
121
  }
118
122
 
119
123
  /** The issues that are a dangling link (a route the plan has no page for) and what was done about it. */
@@ -976,6 +980,7 @@ function composeRecipe(pn: PatternNode, id: string, repeater: RepeaterScope | nu
976
980
  if (pn.recipe === PatternRecipe.Accordion) return composeAccordion(pn, id, ctx);
977
981
  if (pn.recipe === PatternRecipe.Tabs) return composeTabs(pn, id, ctx);
978
982
  if (pn.recipe === PatternRecipe.Carousel) return composeCarousel(pn, id, ctx);
983
+ if (pn.recipe === PatternRecipe.Slideshow) return composeSlideshow(pn, id, ctx);
979
984
  if (pn.recipe === PatternRecipe.Lightbox) return composeLightbox(pn, id, repeater, ctx);
980
985
  if (pn.recipe === PatternRecipe.Segmented) return composeSegmented(pn, id);
981
986
  if (pn.recipe !== PatternRecipe.Card) throw new ComposeError(`${id}: no recipe "${pn.recipe}" in composite-core`);
@@ -1367,6 +1372,21 @@ function composeCarousel(pn: PatternNode, id: string, ctx: Ctx): SerializedNode
1367
1372
  return slider;
1368
1373
  }
1369
1374
 
1375
+ /**
1376
+ * AW8 (`media.slideshow`): composite-core's slideshow (a fading Slider, its pause control and dots), stamped with this
1377
+ * composer's factory; every picture is an empty-image placeholder (the studio's own go in). The pattern node's layout
1378
+ * places the slider.
1379
+ */
1380
+ function composeSlideshow(pn: PatternNode, id: string, ctx: Ctx): SerializedNode {
1381
+ const slider = buildSlideshowRecipe(recipeFactory(id, 'slideshow')) as SerializedNode;
1382
+ if (pn.lay) setStyleProps(slider, pn.lay);
1383
+ if (pn.role) slider.role = pn.role;
1384
+ for (const slide of (slider.children ?? []).filter(c => c.type === SLIDE_TYPE)) {
1385
+ for (const picture of slide.children ?? []) if (picture.type === IMAGE) ctx.placeholders.push({ nodeId: picture.id, owner: ctx.owner, kind: PlaceholderKind.Image, text: '' });
1386
+ }
1387
+ return slider;
1388
+ }
1389
+
1370
1390
  /**
1371
1391
  * CC3: the Lightbox — a Dialog holding a Slider bound to the node's `src` (the gallery's own source): one template
1372
1392
  * slide whose image reads the row (a bare URL row: decorative alt), its arrows hidden on a phone.
@@ -1646,21 +1666,25 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1646
1666
  if (page.layout) {
1647
1667
  // vectoriox/iox-ui#99: a composed page that is where the site lists the shop lists it (a stored layout too).
1648
1668
  const layout = withShownList(page.layout, layoutListsContext(page, plan)) ?? page.layout;
1649
- const opening = layoutBandScheme(layout.sections[0]?.ground);
1669
+ const stamped = stampLayoutSections(page, layout, composeLayoutPage(page, layout, plan, context, design, placeholders, (section, id) =>
1670
+ composePattern(patternById(section.pattern) as SitePattern, id, { ...base, owner: page.key, page, section, nextAlias },
1671
+ { level: section.enter ?? design.animate ?? null, rtl, move: design.headings ?? null })));
1672
+ // AW8: the plan's opening is the home page's first screen; a pinned or kept first place is never replaced.
1673
+ const first = layout.sections[0];
1674
+ const worn = wearPlanOpening(page, stamped, plan, context, design, placeholders, issues, !!(first?.pin || first?.carry));
1675
+ const opening = worn === stamped ? layoutBandScheme(first?.ground) : schemeOfFirst(worn);
1650
1676
  return {
1651
1677
  key: page.key, name: page.name, route: { path: page.route }, isHome: page.isHome === true, status: STATUS_DRAFT, locale,
1652
1678
  pageSettings: { designSystem: true, layoutSource: { pageKey: page.key }, ...(opening ? { opening } : {}) }, seo: composePageSeo(page, plan),
1653
- layout: stampLayoutSections(page, layout, composeLayoutPage(page, layout, plan, context, design, placeholders, (section, id) =>
1654
- composePattern(patternById(section.pattern) as SitePattern, id, { ...base, owner: page.key, page, section, nextAlias },
1655
- { level: section.enter ?? design.animate ?? null, rtl, move: design.headings ?? null }))),
1679
+ layout: worn,
1656
1680
  };
1657
1681
  }
1658
- const layout = page.sections.map((section, i) => {
1682
+ const layout = wearPlanOpening(page, page.sections.map((section, i) => {
1659
1683
  const pattern = patternById(section.pattern) as SitePattern;
1660
1684
  const motion: SectionMotion = { level: section.enter ?? design.animate ?? null, rtl, move: design.headings ?? null };
1661
1685
  return stampSection(composePattern(pattern, `${page.key}-${i}`, { ...base, owner: page.key, page, section, nextAlias }, motion), { pattern: section.pattern });
1662
- });
1663
- const opening = colorSchemeClass(layout[0]?.props?.[COLOR_SCHEME_TRAIT]) ? (layout[0].props[COLOR_SCHEME_TRAIT] as ColorScheme) : null;
1686
+ }), plan, context, design, placeholders, issues, false);
1687
+ const opening = schemeOfFirst(layout);
1664
1688
  return {
1665
1689
  key: page.key,
1666
1690
  name: page.name,
@@ -2085,3 +2109,192 @@ export function composeSection(patternId: string, input: SectionInput, options:
2085
2109
  const section = composePattern(pattern, options.id, ctx);
2086
2110
  return { section, placeholders, issues };
2087
2111
  }
2112
+
2113
+ // ── The opening (AW8, board award-opening) ──────────────────────────────────────────────────────────────────────
2114
+
2115
+ /** The colour scheme a page's first section wears — what the header over it follows (`pageSettings.opening`), or null. */
2116
+ function schemeOfFirst(layout: ReadonlyArray<SerializedNode>): ColorScheme | null {
2117
+ const scheme = layout[0]?.props?.[COLOR_SCHEME_TRAIT];
2118
+ return colorSchemeClass(scheme) ? (scheme as ColorScheme) : null;
2119
+ }
2120
+
2121
+ /** What a first section holds that an opening has no part for: a form, a list bound to content, a Scene. */
2122
+ const OPENING_KEEPS_TYPES: ReadonlySet<string> = new Set(['Form', 'Repeater', 'List']);
2123
+ const SCENE_ROLE = 'scene';
2124
+
2125
+ /** May the opening take the place of this first section? It must hold a heading (the opening's title is its words) and
2126
+ * nothing the opening has no part for — a form, bound content, a Scene stay and the opening comes before them. */
2127
+ function openingMayReplace(root: SerializedNode): boolean {
2128
+ let heading = false;
2129
+ let keeps = false;
2130
+ walkSerialized([root], n => {
2131
+ if (n.type === 'Heading') heading = true;
2132
+ if (OPENING_KEEPS_TYPES.has(n.type) || n.role === SCENE_ROLE || (n.bindings?.length ?? 0) > 0) keeps = true;
2133
+ });
2134
+ return heading && !keeps;
2135
+ }
2136
+
2137
+ /** The words a node shows, markup aside (the first that has any, in reading order). */
2138
+ function shownWords(root: SerializedNode | undefined): string {
2139
+ let words = '';
2140
+ if (root) walkSerialized([root], n => {
2141
+ const own = n.props?.['content'];
2142
+ if (!words && typeof own === 'string' && own.trim()) words = own.replace(/<[^>]+>/g, '').trim();
2143
+ });
2144
+ return words;
2145
+ }
2146
+
2147
+ /**
2148
+ * AW8: the plan's opening (`mixes.opening`) worn as the HOME page's first screen — THE composer of the builder's
2149
+ * Components ▸ Opening (`composeOpening`), judged against the site (`checkOpening`: the build's tier — absent, Basic —,
2150
+ * the hero's own title as the display words, no badge of the owner's, no cut-out picture). It takes the place of the
2151
+ * page's first section when that section may give way (`openingMayReplace`, and not `keep`), carrying its words,
2152
+ * pictures and buttons in by the ONE carry rule (`carryInto`), its placeholders following what was carried; else it comes
2153
+ * first. Every mend, and every part that found no place, is said (`opening-mended`). Any other page, or a plan with no
2154
+ * opening mix, is returned as it was. Mutates `placeholders` / `issues` like the composer; pure otherwise.
2155
+ */
2156
+ function wearPlanOpening(
2157
+ page: PagePlan, layout: SerializedNode[], plan: SitePlan, context: ComposeContext, design: DesignChoices,
2158
+ placeholders: ComposedPlaceholder[], issues: ComposeIssue[], keep: boolean,
2159
+ ): SerializedNode[] {
2160
+ const mix = openingMixOfPlan(plan);
2161
+ if (!mix || !(page.isHome === true || page.route === HOME_PATH)) return layout;
2162
+ const first = layout[0];
2163
+ const replace = !!first && !keep && openingMayReplace(first);
2164
+ const id = replace ? first.id : `${page.key}-opening`;
2165
+ const heading = replace ? swapParts(first)['heading'][0] : undefined;
2166
+ const title = shownWords(heading);
2167
+ const composed = composeOpening({
2168
+ business: { ...plan.business, name: title || plan.business.name },
2169
+ pages: plan.pages.map(p => ({ name: p.name, route: p.route, isHome: p.isHome === true })),
2170
+ mix, locale: plan.locale, design, badge: null, cutOut: false, tier: context.tier ?? GenerationTier.Basic,
2171
+ }, { id });
2172
+ const section = composed.section;
2173
+ const said = composed.issues.map(i => i.detail);
2174
+ let own: ComposedPlaceholder[] = composed.placeholders.map(p => ({ ...p, owner: page.key }));
2175
+ if (replace) {
2176
+ const gone = new Set<string>();
2177
+ walkSerialized([first], n => { gone.add(n.id); });
2178
+ const carried = placeholders.filter(p => gone.has(p.nodeId));
2179
+ for (let i = placeholders.length - 1; i >= 0; i--) if (gone.has(placeholders[i].nodeId)) placeholders.splice(i, 1);
2180
+ // The hero's title is already the opening's display words (composed above — split apart, set as a wordmark); the
2181
+ // carry places everything else, never over those words.
2182
+ const fromRest = withoutNodes(first, n => n === heading);
2183
+ const intoRest = withoutNodes(section, n => OPENING_TITLE_ROLES.has(n.role ?? ''));
2184
+ for (const lost of carryInto(fromRest, intoRest)) said.push(`the opening found no place for ${lost.type === IMAGE ? 'a picture' : `"${shownWords(lost) || lost.type}"`}`);
2185
+ // What the composer left as a placeholder holds only while the carry left it as it was; what was carried brings
2186
+ // its own placeholder with it (the hero's empty picture, its copy).
2187
+ const at = new Map<string, SerializedNode>();
2188
+ walkSerialized([section], n => { at.set(n.id, n); });
2189
+ own = own.filter(p => {
2190
+ const n = at.get(p.nodeId);
2191
+ return !!n && (p.kind === PlaceholderKind.Image ? !n.props['src'] : shownWords(n) === p.text);
2192
+ });
2193
+ for (const n of at.values()) {
2194
+ if (own.some(p => p.nodeId === n.id)) continue;
2195
+ const words = n.type === IMAGE ? null : (typeof n.props?.['content'] === 'string' ? shownWords(n) : null);
2196
+ const from = n.type === IMAGE
2197
+ ? (!n.props['src'] ? carried.find(p => p.kind === PlaceholderKind.Image) : undefined)
2198
+ : (words ? carried.find(p => p.kind !== PlaceholderKind.Image && p.text && p.text === words) : undefined);
2199
+ if (from) own.push({ ...from, nodeId: n.id });
2200
+ }
2201
+ }
2202
+ placeholders.push(...own);
2203
+ for (const detail of said) issues.push({ code: ComposeIssueCode.OpeningMended, nodeId: id, owner: page.key, detail });
2204
+ const was = replace ? first.composed : undefined;
2205
+ stampSection(section, was?.pattern ? { pattern: was.pattern } : { layout: was?.layout ?? OPENING_ORIGIN });
2206
+ return replace ? [section, ...layout.slice(1)] : [section, ...layout];
2207
+ }
2208
+
2209
+ /** The opening's parts that hold the display words — composed from the hero's title, so nothing is carried onto them. */
2210
+ const OPENING_TITLE_ROLES: ReadonlySet<string> = new Set([OpeningRole.Title, OpeningRole.Apart, OpeningRole.ApartWord]);
2211
+
2212
+ /** A view of `root` without the nodes `drop` names (and what they hold): only the containers above a dropped node are
2213
+ * copies, every other node is the SAME object — so a carry into the view writes the real tree. */
2214
+ function withoutNodes(root: SerializedNode, drop: (n: SerializedNode) => boolean): SerializedNode {
2215
+ const view = (n: SerializedNode): SerializedNode => {
2216
+ const kids = n.children ?? [];
2217
+ const kept = kids.filter(c => !drop(c)).map(view);
2218
+ return kept.length === kids.length && kept.every((c, i) => c === kids[i]) ? n : { ...n, children: kept };
2219
+ };
2220
+ return view(root);
2221
+ }
2222
+
2223
+ /** The origin an opening placed before a page's sections is stamped with (it replaced no section of the plan's). */
2224
+ const OPENING_ORIGIN = 'opening';
2225
+
2226
+ /** What an opening is composed from when there is no Site Plan (the builder): the studio's name and pages, its language,
2227
+ * its look, and the mix. */
2228
+ export interface OpeningInput extends SectionInput {
2229
+ /** The opening's mix. The defaults (a picture, edge to edge, a heading) when not given. */
2230
+ readonly mix?: OpeningMix;
2231
+ readonly locale?: string;
2232
+ readonly design?: Readonly<Partial<DesignChoices>>;
2233
+ /** The owner's own badge words; null = none given (a badge is left out), absent = a placeholder that holds Publish. */
2234
+ readonly badge?: string | null;
2235
+ /** The owner gives a cut-out picture (the name behind the subject). */
2236
+ readonly cutOut?: boolean;
2237
+ /** AW-D23: the tier the site is built at; absent = every word (the builder shows the Pro marks itself). */
2238
+ readonly tier?: OpeningContext['tier'];
2239
+ /** Draw the mix as asked, never mended — the Opening studio (it ADVISES the check's mends, OB-2). */
2240
+ readonly asAsked?: boolean;
2241
+ }
2242
+
2243
+ export interface ComposedOpening extends ComposedSection {
2244
+ /** The mix it was composed as — drawn, and checked unless asked as is (what Bindings ▸ Opening shows). */
2245
+ mix: OpeningMix;
2246
+ }
2247
+
2248
+ /** The context an opening is judged and measured in — the same for the check, the recipe and the studio's advice. */
2249
+ export function openingContextOf(input: Pick<OpeningInput, 'business' | 'design' | 'badge' | 'cutOut' | 'tier'>): OpeningContext {
2250
+ return {
2251
+ name: input.business?.name ?? '',
2252
+ design: resolveDesignChoices(JSON.parse(JSON.stringify(input.design ?? {}))),
2253
+ ...(input.tier ? { tier: input.tier } : {}),
2254
+ ...(input.cutOut !== undefined ? { cutOut: input.cutOut } : {}),
2255
+ ...(input.badge !== undefined ? { badge: input.badge } : {}),
2256
+ };
2257
+ }
2258
+
2259
+ /**
2260
+ * A page's opening — the builder's Components ▸ Opening and the Opening studio, and the generator's first section: THE
2261
+ * SAME recipe (`openingRecipe`) and composer as every pattern. The mix is drawn as the product draws it (a waiting word
2262
+ * becomes its stand-in) and judged against the site (`checkOpening`) unless asked as is; every mend is said as an issue.
2263
+ * Its words come from the business (the name, the tagline) or are its own placeholders; a badge is the owner's, never
2264
+ * written for them. The root stores the mix (OB-5). Pure.
2265
+ */
2266
+ export function composeOpening(input: OpeningInput, options: SectionOptions): ComposedOpening {
2267
+ if (!nonEmpty(options?.id)) throw new ComposeError('composeOpening needs the section id');
2268
+ const business: SiteBusiness = input.business ?? { name: '' } as SiteBusiness;
2269
+ const context = openingContextOf(input);
2270
+ const { drawn, gaps } = drawnOpeningMix(input.mix ?? openingMix());
2271
+ const checked = input.asAsked ? { mix: drawn, repairs: [] } : checkOpening(drawn, context);
2272
+ const pages = navPagePlans(input.pages ?? []);
2273
+ const plan = { business, pages, dataSources: [], contentTypes: [], locale: input.locale } as unknown as SitePlan;
2274
+ const email = nonEmpty(business.facts?.email) ? business.facts!.email!.trim() : null;
2275
+ const placeholders: ComposedPlaceholder[] = [];
2276
+ const issues: ComposeIssue[] = [];
2277
+ for (const said of [...gaps.map(g => `the opening's ${g.ingredient} "${g.word}" is drawn as ${g.drawnAs ? `"${g.drawnAs}"` : 'nothing'} until ${g.phase}`), ...checked.repairs.map(r => r.said)]) {
2278
+ issues.push({ code: ComposeIssueCode.OpeningMended, nodeId: options.id, owner: options.id, detail: said });
2279
+ }
2280
+ const ctx: Ctx = {
2281
+ owner: options.id, page: null, section: null, plan, year: 0, email, navPage: null, nextAlias: null,
2282
+ placeholders, issues, routes: new Set(pages.map(p => p.route)), keepButtons: true,
2283
+ };
2284
+ const recipe = openingRecipe(checked.mix, context);
2285
+ const section = composePattern(recipe.pattern, options.id, ctx);
2286
+ stampOpeningMix(section, recipe.mix);
2287
+ const badge = typeof input.badge === 'string' && input.badge.trim() ? input.badge.trim() : null;
2288
+ if (badge) {
2289
+ walkSerialized([section], n => {
2290
+ const holder = n.role === OpeningRole.Badge ? n : null;
2291
+ for (const words of holder?.children ?? []) {
2292
+ words.props = { ...words.props, content: badge };
2293
+ const at = placeholders.findIndex(p => p.nodeId === words.id);
2294
+ if (at >= 0) placeholders.splice(at, 1);
2295
+ }
2296
+ });
2297
+ }
2298
+ return { section, placeholders, issues, mix: recipe.mix };
2299
+ }
2300
+
@@ -1885,7 +1885,8 @@ export const NODE_BASELINES: Readonly<Record<string, NodeBaseline>> = {
1885
1885
  "transitionTimingFunction": "ease"
1886
1886
  },
1887
1887
  "traits": [
1888
- "colorScheme"
1888
+ "colorScheme",
1889
+ "openingMix"
1889
1890
  ],
1890
1891
  "styleTraits": [
1891
1892
  "position",