@vectoriox/iox-ui 5.134.0 → 5.136.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 (38) hide show
  1. package/composite-core/index.d.ts +15 -2
  2. package/design-core/index.d.ts +153 -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 +241 -48
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  9. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1291 -126
  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/generation-core/index.d.ts +485 -61
  14. package/harness-core/index.d.ts +4 -2
  15. package/package.json +1 -1
  16. package/src/assist-core/page-sections.ts +4 -31
  17. package/src/composite-core/slider.ts +35 -0
  18. package/src/design-core/design-settings.ts +16 -3
  19. package/src/design-core/design-token.model.ts +3 -0
  20. package/src/design-core/flavor-spec.generated.ts +98 -25
  21. package/src/design-core/motion-language.ts +12 -9
  22. package/src/design-core/preloader.ts +129 -0
  23. package/src/design-core/public-api.ts +1 -0
  24. package/src/design-core/style-presets.ts +3 -1
  25. package/src/generation-core/carry.ts +37 -0
  26. package/src/generation-core/compose-site.ts +222 -9
  27. package/src/generation-core/node-baselines.generated.ts +2 -1
  28. package/src/generation-core/opening-edit.ts +240 -0
  29. package/src/generation-core/opening-mix.ts +639 -0
  30. package/src/generation-core/patterns.ts +3 -0
  31. package/src/generation-core/plan-wire.ts +26 -4
  32. package/src/generation-core/public-api.ts +2 -0
  33. package/src/generation-core/site-build-run.ts +70 -1
  34. package/src/generation-core/site-plan.model.ts +3 -1
  35. package/src/generation-core/site-spec.generated.ts +137 -56
  36. package/src/generation-core/validate-site-plan.ts +5 -3
  37. package/src/harness-core/starting-design.ts +8 -4
  38. package/styles/iox-design.css +32 -0
@@ -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",
@@ -0,0 +1,240 @@
1
+ import { carryButtonLink, carryInto } from './carry';
2
+ import { composeOpening, ComposedOpening, OpeningInput, openingContextOf } from './compose-site';
3
+ import { headerShape } from './header-edit';
4
+ import {
5
+ checkOpening, drawnOpeningMix, OpeningIngredient, openingGalleryIdOf, openingMix, OpeningMix, OpeningMedia, OpeningRepair, OpeningRole,
6
+ OPENING_MIX_PROP, storedOpeningMix,
7
+ } from './opening-mix';
8
+ import { SerializedNode, walkSerialized } from './serialized-node';
9
+
10
+ /**
11
+ * EDITING AN OPENING IN THE BUILDER (AW8, board award-opening — OB-2, OB-4, OB-5, OB-6): what Bindings ▸ Opening and the
12
+ * Opening studio read off a page's opening, and what Apply writes. Pure, one recipe with the generator: every opening is
13
+ * `composeOpening(mix)`; the builder never builds one by hand.
14
+ *
15
+ * - `readOpening` — the mix the opening root stores (`openingMix`), and which rows the owner changed by hand (Custom).
16
+ * - `applyOpeningMix` — the opening for a new mix: the owner's words, pictures, film, button links, card, badge and form
17
+ * are carried into the parts the new mix has, and what found no place is said (OB-4) — never dropped silently.
18
+ * - `openingFromSection` — "Make this an opening" (OB-6): a hand-made first section becomes the default opening, carrying
19
+ * its words, its first picture and its first button by Ask's swap rule (generation-core `carryInto`).
20
+ * - `openingAdvice` — `checkOpening` as advice: what it would mend, never mended by itself (as `headerAdvice`).
21
+ */
22
+
23
+ /** What an opening is composed from in the builder: the studio (its name, pages, language, look) — the mix aside. */
24
+ export type OpeningSite = Omit<OpeningInput, 'mix' | 'asAsked'>;
25
+
26
+ /** The page's opening: its first root section composed as one (role `opening`), else null. */
27
+ export function findOpening(layout: ReadonlyArray<SerializedNode>): SerializedNode | null {
28
+ const first = layout.find(n => !n.isGlobal);
29
+ return first?.role === OpeningRole.Root ? first : null;
30
+ }
31
+
32
+ /** The roles each Bindings row (and studio tab) reads: a row is Custom when one of its parts changed by hand. */
33
+ const ROW_ROLES: Readonly<Record<OpeningIngredient, ReadonlyArray<string>>> = {
34
+ [OpeningIngredient.Frame]: [OpeningRole.Frame, OpeningRole.FrameSettles],
35
+ [OpeningIngredient.Media]: [OpeningRole.Media, OpeningRole.MediaZooms, OpeningRole.Second, OpeningRole.Pair, OpeningRole.Film, OpeningRole.Slides, OpeningRole.Object, OpeningRole.Form],
36
+ [OpeningIngredient.Words]: [OpeningRole.Words, OpeningRole.Title, OpeningRole.Lead, OpeningRole.Action, OpeningRole.Apart, OpeningRole.ApartWord, OpeningRole.Aside, OpeningRole.Cutout, OpeningRole.Scrim],
37
+ [OpeningIngredient.Extras]: [OpeningRole.Card, OpeningRole.Badge, OpeningRole.Cue],
38
+ [OpeningIngredient.Motion]: [],
39
+ };
40
+
41
+ /** The props that are the owner's CONTENT (words, pictures, a film, a form's identity) — never a sign of a hand edit. */
42
+ const CONTENT_PROPS: ReadonlyArray<string> = [OPENING_MIX_PROP, 'src', 'poster', 'frames', 'formId', 'name'];
43
+
44
+ /** A part's shape without its content: what it is made of and what it wears. */
45
+ function partShape(node: SerializedNode): string {
46
+ const strip = (n: SerializedNode): SerializedNode => ({
47
+ ...n, props: Object.fromEntries(Object.entries(n.props ?? {}).filter(([k]) => !CONTENT_PROPS.includes(k))), children: (n.children ?? []).map(strip),
48
+ });
49
+ return headerShape(strip(node));
50
+ }
51
+
52
+ /** Every part with a role in `roles`, by role, in reading order (the frame is read as its own props, not its children). */
53
+ function partsOf(root: SerializedNode, roles: ReadonlyArray<string>): string {
54
+ const out: string[] = [];
55
+ walkSerialized([root], n => {
56
+ if (!n.role || !roles.includes(n.role)) return;
57
+ const own = n.role === OpeningRole.Frame || n.role === OpeningRole.FrameSettles ? { ...n, children: [] } : n;
58
+ out.push(`${n.role}:${partShape(own)}`);
59
+ });
60
+ return out.join('|');
61
+ }
62
+
63
+ export interface OpeningReading {
64
+ /** The mix the opening stores. */
65
+ mix: OpeningMix;
66
+ /** The rows the owner changed by hand (board 2: a drifted row reads Custom). */
67
+ custom: OpeningIngredient[];
68
+ /** The gallery mix it is, or null. */
69
+ galleryId: string | null;
70
+ }
71
+
72
+ /** The opening composed as `mix` for the studio, with the same id — what `readOpening` compares and Apply starts from. */
73
+ function compose(mix: OpeningMix, site: OpeningSite, id: string): ComposedOpening {
74
+ return composeOpening({ ...site, mix, asAsked: true }, { id });
75
+ }
76
+
77
+ /** What an opening is (OB-5): its stored mix, and which rows are no longer what that mix composes. Null: the section
78
+ * stores no mix (a hand-made section — OB-6's "Make this an opening", never an inferred mix). Pure. */
79
+ export function readOpening(root: SerializedNode, site: OpeningSite): OpeningReading | null {
80
+ const mix = storedOpeningMix(root);
81
+ if (!mix) return null;
82
+ const base = compose(mix, siteFor(site, root), root.id).section;
83
+ const custom = (Object.keys(ROW_ROLES) as OpeningIngredient[])
84
+ .filter(k => ROW_ROLES[k].length && partsOf(root, ROW_ROLES[k]) !== partsOf(base, ROW_ROLES[k]));
85
+ return { mix, custom, galleryId: openingGalleryIdOf(mix) };
86
+ }
87
+
88
+ // ── The carry (OB-4) ───────────────────────────────────────────────────────────────────────────────────────────────
89
+
90
+ const PICTURE_ROLES: ReadonlyArray<string> = [OpeningRole.Media, OpeningRole.MediaZooms, OpeningRole.Second, OpeningRole.Object, OpeningRole.Cutout];
91
+
92
+ /** The words a node shows (a button's are its label's). */
93
+ function wordsOf(n: SerializedNode | undefined): string {
94
+ if (!n) return '';
95
+ const own = n.props?.['content'] ?? n.props?.['label'];
96
+ if (typeof own === 'string' && own.trim()) return own.replace(/<[^>]+>/g, '').trim();
97
+ for (const c of n.children ?? []) { const w = wordsOf(c); if (w) return w; }
98
+ return '';
99
+ }
100
+
101
+ const byRole = (root: SerializedNode, role: string): SerializedNode[] => {
102
+ const out: SerializedNode[] = [];
103
+ walkSerialized([root], n => { if (n.role === role) out.push(n); });
104
+ return out;
105
+ };
106
+ const firstRole = (root: SerializedNode, role: string): SerializedNode | undefined => byRole(root, role)[0];
107
+
108
+ /** The pictures of an opening, in order: the media, the second, the slideshow's, the object, the cut-out. */
109
+ function picturesOf(root: SerializedNode): SerializedNode[] {
110
+ const out: SerializedNode[] = [];
111
+ walkSerialized([root], (n, ancestors) => {
112
+ if (n.type !== 'Image') return;
113
+ if ((n.role && PICTURE_ROLES.includes(n.role)) || ancestors.some(a => a.role === OpeningRole.Slides)) out.push(n);
114
+ });
115
+ return out;
116
+ }
117
+
118
+ /** The title's words as the owner wrote them: the heading, or the words placed apart read as one line. */
119
+ function titleWordsOf(root: SerializedNode): string {
120
+ const apart = firstRole(root, OpeningRole.Apart);
121
+ if (apart) return (apart.children ?? []).map(c => wordsOf(c)).filter(Boolean).join(' ');
122
+ return wordsOf(firstRole(root, OpeningRole.Title));
123
+ }
124
+
125
+ /** The site an opening is recomposed for: its display words are the owner's title (a re-mix never rewrites them). */
126
+ function siteFor(site: OpeningSite, current: SerializedNode): OpeningSite {
127
+ const title = titleWordsOf(current);
128
+ return title ? { ...site, business: { ...(site.business ?? { name: '' }), name: title } } : site;
129
+ }
130
+
131
+ /** Something of the owner's that the new mix has no place for — said before Apply. */
132
+ export interface OpeningNotPlaced {
133
+ role: string;
134
+ /** Its words, or empty (a picture). */
135
+ words: string;
136
+ nodeId: string;
137
+ }
138
+
139
+ export interface OpeningApplied {
140
+ /** The opening for the new mix — the same id, with the owner's content. */
141
+ section: SerializedNode;
142
+ mix: OpeningMix;
143
+ /** What found no place (empty: everything was carried). */
144
+ notPlaced: OpeningNotPlaced[];
145
+ }
146
+
147
+ const setWords = (n: SerializedNode, words: string): void => {
148
+ if (n.type === 'ButtonBlock') {
149
+ const label = (n.children ?? []).find(c => c.type === 'Text');
150
+ if (label) label.props = { ...label.props, content: words };
151
+ return;
152
+ }
153
+ n.props = { ...n.props, content: words };
154
+ };
155
+
156
+ /**
157
+ * The owner's content carried from one opening into another, part for part (OB-4): the title, the line, the action (its
158
+ * words and where it leads), the cue's and the badge's words, the pictures in order, the film, the card's words and
159
+ * picture, the form (verbatim — its id, its fields). Returns what found no place.
160
+ */
161
+ function carryOpening(from: SerializedNode, to: SerializedNode): OpeningNotPlaced[] {
162
+ const notPlaced: OpeningNotPlaced[] = [];
163
+ const miss = (n: SerializedNode, words = wordsOf(n)) => notPlaced.push({ role: n.role ?? n.type, words, nodeId: n.id });
164
+ for (const role of [OpeningRole.Lead, OpeningRole.Action, OpeningRole.Cue] as const) {
165
+ const src = firstRole(from, role);
166
+ if (!src) continue;
167
+ const dst = firstRole(to, role);
168
+ if (!dst) { if (role !== OpeningRole.Cue) miss(src); continue; }
169
+ setWords(dst, wordsOf(src));
170
+ if (role === OpeningRole.Action) carryButtonLink(src, dst);
171
+ }
172
+ const badge = firstRole(from, OpeningRole.Badge);
173
+ if (badge) {
174
+ const dst = firstRole(to, OpeningRole.Badge);
175
+ const words = wordsOf(badge);
176
+ if (dst) (dst.children ?? []).forEach(c => setWords(c, words));
177
+ else miss(badge, words);
178
+ }
179
+ const pictures = picturesOf(from).filter(p => typeof p.props?.['src'] === 'string' && p.props['src']);
180
+ const slots = picturesOf(to);
181
+ pictures.forEach((p, i) => {
182
+ const slot = slots[i];
183
+ if (!slot) { miss(p, ''); return; }
184
+ slot.props = { ...slot.props, src: p.props['src'], alt: p.props['alt'] ?? slot.props['alt'] ?? '' };
185
+ });
186
+ const film = firstRole(from, OpeningRole.Film);
187
+ if (film && film.props?.['src']) {
188
+ const dst = firstRole(to, OpeningRole.Film);
189
+ if (dst) dst.props = { ...dst.props, ...Object.fromEntries(['src', 'poster', 'frames'].filter(k => k in film.props).map(k => [k, film.props[k]])) };
190
+ else miss(film, '');
191
+ }
192
+ const card = firstRole(from, OpeningRole.Card);
193
+ if (card) {
194
+ const dst = firstRole(to, OpeningRole.Card);
195
+ if (!dst) miss(card);
196
+ else carryInto(card, dst);
197
+ }
198
+ const form = firstRole(from, OpeningRole.Form);
199
+ if (form) {
200
+ const dst = firstRole(to, OpeningRole.Form);
201
+ if (!dst) miss(form, wordsOf(form));
202
+ else dst.children = JSON.parse(JSON.stringify(form.children ?? []));
203
+ }
204
+ return notPlaced;
205
+ }
206
+
207
+ /** The opening for `next` (OB-4): the recipe's opening for the new mix, with the owner's content carried in, and what
208
+ * found no place said. The same id, still the page's first section. Pure. */
209
+ export function applyOpeningMix(current: SerializedNode, next: OpeningMix, site: OpeningSite): OpeningApplied {
210
+ const fresh = compose(next, siteFor(site, current), current.id);
211
+ const section = fresh.section;
212
+ const notPlaced = carryOpening(current, section);
213
+ return { section, mix: fresh.mix, notPlaced };
214
+ }
215
+
216
+ /** "Make this an opening" (OB-6): a hand-made first section as the default opening — its words, first picture and first
217
+ * button carried by the swap rule; what found no place said. The same id. Pure. */
218
+ export function openingFromSection(section: SerializedNode, site: OpeningSite, mix: OpeningMix = openingMix()): OpeningApplied {
219
+ const headings: SerializedNode[] = [];
220
+ walkSerialized([section], n => { if (n.type === 'Heading') headings.push(n); });
221
+ const named = wordsOf(headings[0]);
222
+ const at: OpeningSite = named ? { ...site, business: { ...(site.business ?? { name: '' }), name: named } } : site;
223
+ const fresh = compose(mix, at, section.id);
224
+ const lost = carryInto(section, fresh.section);
225
+ return { section: fresh.section, mix: fresh.mix, notPlaced: lost.map(n => ({ role: n.role ?? n.type, words: n.type === 'Image' ? '' : wordsOf(n), nodeId: n.id })) };
226
+ }
227
+
228
+ /** What `checkOpening` would mend in a mix on this site — said in the studio, never applied by itself. */
229
+ export function openingAdvice(mix: OpeningMix, site: OpeningSite): OpeningRepair[] {
230
+ return checkOpening(drawnOpeningMix(mix).drawn, openingContextOf(site)).repairs;
231
+ }
232
+
233
+ /** The mix the advice's one action applies (the check's own mend), or null. */
234
+ export function openingAdviceMix(mix: OpeningMix, site: OpeningSite): OpeningMix | null {
235
+ const checked = checkOpening(drawnOpeningMix(mix).drawn, openingContextOf(site));
236
+ return checked.repairs.length ? checked.mix : null;
237
+ }
238
+
239
+ /** Media that move on their own — the slideshow's pause control is part of them (board 5). */
240
+ export const MOVING_OPENING_MEDIA: ReadonlySet<string> = new Set([OpeningMedia.Film, OpeningMedia.Slideshow]);