@vectoriox/iox-ui 5.158.0 → 5.160.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.
@@ -0,0 +1,125 @@
1
+ import { decomposeCssFunctions, FILTER_FUNCTIONS } from '@vectoriox/iox-ui/design-core';
2
+
3
+ import { FreeNodeType, FreeStyle, FREE_BUILDER_TYPE } from './free-wire';
4
+ import { NODE_BASELINES } from './node-baselines.generated';
5
+
6
+ /**
7
+ * HOW A FREE STYLE IS HELD (FS3 stamp). The free language (`check-free.ts`) speaks CSS as a model writes it — sides as
8
+ * start / end, `rowGap`, `placeItems`, `flex`, one `filter` — while a builder node holds its look in its style CONTROLS
9
+ * (`NODE_BASELINES[type].styleTraits`): one `margin`, `left` / `right`, `alignItems` + `justifyItems`, `filterBlur`…
10
+ * A base style the builder has no control for is DROPPED on the first save (cms-client `serializeBuilderToPageLayout`
11
+ * keeps trait values only), so the stamp never writes one: each free property is folded into the controls here — the ONE
12
+ * table, read by the judge (`freeSlotIssues`: a property a node's type has no control for is refused, with a path) and
13
+ * by the stamp (`composeFree`). Start / end become left / right by the page's direction, as `bleedSides` does. Pure.
14
+ */
15
+
16
+ const SIDES = ['top', 'right', 'bottom', 'left'] as const;
17
+ type Sides = [string, string, string, string];
18
+ const BOX_GROUPS = ['margin', 'padding'] as const;
19
+ /** The free side keys of a box group, read in this order: the shorthand, then the axes, then each side. */
20
+ const SIDE_KEYS = ['', 'Block', 'Inline', 'Top', 'Bottom', 'InlineStart', 'InlineEnd'] as const;
21
+ const ZERO = '0px';
22
+
23
+ export interface FreeSlotOptions {
24
+ /** The page runs right to left: start is the right side. */
25
+ rtl: boolean;
26
+ /** What the node already holds at this width (its element style, a wider layer): a side the answer leaves is kept. */
27
+ held?: Readonly<Record<string, unknown>>;
28
+ }
29
+
30
+ /** CSS's 1–4 value box shorthand as four physical sides. */
31
+ export function boxSides(value: unknown): Sides | null {
32
+ const parts = String(value ?? '').trim().split(/\s+(?![^(]*\))/).filter(Boolean);
33
+ if (!parts.length || parts.length > 4) return null;
34
+ const [t, r = t, b = t, l = r] = parts;
35
+ return [t, r, b, l];
36
+ }
37
+
38
+ const sidesText = (s: Sides) => (s[1] === s[3] ? (s[0] === s[2] ? (s[0] === s[1] ? s[0] : `${s[0]} ${s[1]}`) : `${s[0]} ${s[1]} ${s[2]}`) : s.join(' '));
39
+ const pair = (value: string): [string, string] => {
40
+ const [a, b = a] = value.trim().split(/\s+(?![^(]*\))/);
41
+ return [a, b];
42
+ };
43
+ const NUMBER = /^-?\d*\.?\d+$/;
44
+
45
+ /** `flex` as grow / shrink / basis (CSS's own expansion). */
46
+ function flexParts(value: string): Record<string, string> | null {
47
+ const v = value.trim();
48
+ if (v === 'none') return { flexGrow: '0', flexShrink: '0', flexBasis: 'auto' };
49
+ if (v === 'auto') return { flexGrow: '1', flexShrink: '1', flexBasis: 'auto' };
50
+ if (v === 'initial') return { flexGrow: '0', flexShrink: '1', flexBasis: 'auto' };
51
+ const p = v.split(/\s+(?![^(]*\))/);
52
+ if (p.length === 1) return NUMBER.test(p[0]) ? { flexGrow: p[0], flexShrink: '1', flexBasis: '0%' } : { flexGrow: '1', flexShrink: '1', flexBasis: p[0] };
53
+ if (p.length === 2) return NUMBER.test(p[1]) ? { flexGrow: p[0], flexShrink: p[1], flexBasis: '0%' } : { flexGrow: p[0], flexShrink: '1', flexBasis: p[1] };
54
+ if (p.length === 3) return { flexGrow: p[0], flexShrink: p[1], flexBasis: p[2] };
55
+ return null;
56
+ }
57
+
58
+ /**
59
+ * A free style as the builder's controls hold it. A property with no fold is passed through as written — the judge says
60
+ * whether the node's type has a control for it (`freeSlotIssues`).
61
+ */
62
+ export function freeStyleToSlots(style: FreeStyle | undefined, options: FreeSlotOptions): Record<string, string> {
63
+ const out: Record<string, string> = {};
64
+ const held = options.held ?? {};
65
+ // The start side is the right (1) on a right-to-left page, the left (3) otherwise.
66
+ const start = options.rtl ? 1 : 3;
67
+ const end = options.rtl ? 3 : 1;
68
+ const given = style ?? {};
69
+ for (const group of BOX_GROUPS) {
70
+ const keys = SIDE_KEYS.map(k => `${group}${k}`).filter(k => given[k] !== undefined);
71
+ if (!keys.length) continue;
72
+ const sides: Sides = boxSides(held[group]) ?? [ZERO, ZERO, ZERO, ZERO];
73
+ for (const key of keys) {
74
+ const v = String(given[key]).trim();
75
+ const k = key.slice(group.length);
76
+ if (k === '') {
77
+ const s = boxSides(v);
78
+ if (s) sides.splice(0, 4, ...s);
79
+ } else if (k === 'Block') [sides[0], sides[2]] = pair(v);
80
+ else if (k === 'Inline') { const [a, b] = pair(v); sides[start] = a; sides[end] = b; }
81
+ else if (k === 'Top') sides[0] = v;
82
+ else if (k === 'Bottom') sides[2] = v;
83
+ else if (k === 'InlineStart') sides[start] = v;
84
+ else sides[end] = v;
85
+ }
86
+ out[group] = sidesText(sides);
87
+ }
88
+ for (const [prop, raw] of Object.entries(given)) {
89
+ const v = String(raw).trim();
90
+ if (BOX_GROUPS.some(g => prop.startsWith(g) && SIDE_KEYS.includes(prop.slice(g.length) as typeof SIDE_KEYS[number]))) continue;
91
+ if (prop === 'insetInlineStart') out[SIDES[start]] = v;
92
+ else if (prop === 'insetInlineEnd') out[SIDES[end]] = v;
93
+ else if (prop === 'rowGap' || prop === 'columnGap') {
94
+ const [row, col] = pair(String(out['gap'] ?? given['gap'] ?? held['gap'] ?? 'normal'));
95
+ const next: [string, string] = prop === 'rowGap' ? [v, col] : [row, v];
96
+ out['gap'] = next[0] === next[1] ? next[0] : next.join(' ');
97
+ } else if (prop === 'gap') {
98
+ if (out['gap'] === undefined) out['gap'] = v;
99
+ } else if (prop === 'placeItems') { const [a, b] = pair(v); out['alignItems'] = a; out['justifyItems'] = b; }
100
+ else if (prop === 'placeSelf') { const [a, b] = pair(v); out['alignSelf'] = a; out['justifySelf'] = b; }
101
+ else if (prop === 'flex') Object.assign(out, flexParts(v) ?? { flex: v });
102
+ else if (prop === 'filter') Object.assign(out, decomposeCssFunctions(FILTER_FUNCTIONS, v) ?? { filter: v });
103
+ else out[prop] = v;
104
+ }
105
+ return out;
106
+ }
107
+
108
+ /** The builder controls a free node's type has. */
109
+ export function freeControlsOf(type: FreeNodeType): ReadonlyArray<string> {
110
+ return NODE_BASELINES[FREE_BUILDER_TYPE[type]]?.styleTraits ?? [];
111
+ }
112
+
113
+ /**
114
+ * Each property of one free style map that the node's type has no control for, by the property as the answer wrote it
115
+ * (`[prop, the control it would need]`): what the stamp could not keep past the first save.
116
+ */
117
+ export function freeStyleWithoutSlot(type: FreeNodeType, style: FreeStyle | undefined): Array<[string, string]> {
118
+ const slots = freeControlsOf(type);
119
+ const out: Array<[string, string]> = [];
120
+ for (const [prop, value] of Object.entries(style ?? {})) {
121
+ const missing = Object.keys(freeStyleToSlots({ [prop]: value }, { rtl: false })).find(k => !slots.includes(k));
122
+ if (missing) out.push([prop, missing]);
123
+ }
124
+ return out;
125
+ }
@@ -168,6 +168,11 @@ export interface FreePage {
168
168
  read: FreeRead;
169
169
  pictures: string;
170
170
  sections: FreeNode[];
171
+ /**
172
+ * Set by the fall back only (never asked, never on the wire): how many of the model's sections it dropped — the page's
173
+ * section minimum forgives them, as a composed page's does (iox-ui#67, iox-ui#134).
174
+ */
175
+ givenAway?: number;
171
176
  }
172
177
 
173
178
  /** The wire's node keys, in the order a model writes them. Every one is required. */
@@ -34,6 +34,21 @@ export enum SectionSwapRule {
34
34
  Fit = 'fit',
35
35
  /** A middle section no ready-made section fits (or every one that does would repeat a kept section, iox-ui#68): dropped. */
36
36
  NoFit = 'no-fit',
37
+ /**
38
+ * A middle section no ready-made section fits by its words, given the plan's unused middle section nearest its place
39
+ * — only when the caller keeps every place (`SectionFallbackOptions.keepPlace`: a free page, iox-ui#134).
40
+ */
41
+ Place = 'place',
42
+ }
43
+
44
+ /** How the fall back treats a middle place nothing fits. */
45
+ export interface SectionFallbackOptions {
46
+ /**
47
+ * iox-ui#134: keep the place — a middle section no ready-made section fits takes the plan's unused middle section
48
+ * nearest its place (never one that repeats a kept section) instead of being dropped. A free page asks this: its count
49
+ * is the model's, and a page one short of its minimum fell back WHOLE. Absent: dropped, as a composed page always was.
50
+ */
51
+ keepPlace?: boolean;
37
52
  }
38
53
 
39
54
  /** One place swapped, kept for us on the composed record — never shown to the owner. */
@@ -139,6 +154,21 @@ function fitScore(section: LayoutSection, plan: PageSectionPlan): number {
139
154
  /** The least a middle section's fit scores to be given a ready-made section (two shared words, a form or a list). */
140
155
  const FIT_MIN = 2;
141
156
 
157
+ /**
158
+ * iox-ui#134: the plan's middle section (neither its opening nor its close) not yet used whose place is nearest the model's
159
+ * section's — by their share of each page's length, the earlier one on a tie — and that repeats no kept section; else null.
160
+ */
161
+ function nearestUnusedMiddle(plan: ReadonlyArray<PageSectionPlan>, i: number, lastAt: number, used: ReadonlySet<number>, kept: ReadonlyArray<LayoutSection>): number | null {
162
+ const share = lastAt > 0 ? i / lastAt : 0;
163
+ const planLast = plan.length - 1;
164
+ const candidates = plan
165
+ .map((p, at) => ({ at, p }))
166
+ .filter(c => c.at > 0 && c.at < planLast && !used.has(c.at) && !repeatsKept(c.p, kept))
167
+ .map(c => ({ at: c.at, off: Math.abs(c.at / planLast - share) }))
168
+ .sort((a, b) => a.off - b.off || a.at - b.at);
169
+ return candidates[0]?.at ?? null;
170
+ }
171
+
142
172
  /** A ready-made stub at a place: no layers of its own — the composer stamps the plan section's pattern there. */
143
173
  function readyMadeSection(original: LayoutSection, at: number, plan: PageSectionPlan): LayoutSection {
144
174
  return { id: original.id, kind: 'content', screens: 1, rows: 1, layers: [], phone: [], readyMade: { at, pattern: plan.pattern } };
@@ -149,7 +179,9 @@ function readyMadeSection(original: LayoutSection, at: number, plan: PageSection
149
179
  * more (a page-wide issue beside them may be cured by the swap — the judge says). `plan` is the page's ready-made
150
180
  * sections (`PagePlan.sections`), in order; `issues` what is left after the mends and the one repair.
151
181
  */
152
- export function fallBackBySection(page: LayoutPage, plan: ReadonlyArray<PageSectionPlan>, issues: ReadonlyArray<LayoutIssue>, judge: SectionJudge): SectionFallback {
182
+ export function fallBackBySection(
183
+ page: LayoutPage, plan: ReadonlyArray<PageSectionPlan>, issues: ReadonlyArray<LayoutIssue>, judge: SectionJudge, options: SectionFallbackOptions = {},
184
+ ): SectionFallback {
153
185
  const current: LayoutPage = structuredClone(page) as LayoutPage;
154
186
  const swaps: SectionSwap[] = [];
155
187
  const last = (lastResort: `${SectionFallbackLastResort}`, left: LayoutIssue[], at: LayoutPage = current): SectionFallback => ({ page: at, swaps, left, lastResort });
@@ -180,10 +212,15 @@ export function fallBackBySection(page: LayoutPage, plan: ReadonlyArray<PageSect
180
212
  .map((p, at) => ({ at, score: at > 0 && at < plan.length - 1 && !used.has(at) && !repeatsKept(p, keptSections) ? fitScore(s, p) : -1 }))
181
213
  .filter(c => c.score >= FIT_MIN)
182
214
  .sort((a, b) => b.score - a.score || a.at - b.at)[0];
215
+ const near = !best && options.keepPlace ? nearestUnusedMiddle(plan, i, lastAt, used, keptSections) : null;
183
216
  if (best) {
184
217
  used.add(best.at);
185
218
  next[i] = readyMadeSection(s, best.at, plan[best.at]);
186
219
  record(SectionSwapAction.Replaced, SectionSwapRule.Fit, { at: best.at, pattern: plan[best.at].pattern });
220
+ } else if (near !== null) {
221
+ used.add(near);
222
+ next[i] = readyMadeSection(s, near, plan[near]);
223
+ record(SectionSwapAction.Replaced, SectionSwapRule.Place, { at: near, pattern: plan[near].pattern });
187
224
  } else {
188
225
  drop.add(i);
189
226
  record(SectionSwapAction.Dropped, SectionSwapRule.NoFit);
@@ -281,6 +281,11 @@ export const PLAN_WIRE_DERIVED: Readonly<Record<string, string>> = {
281
281
  'page.layout': 'the layout step: one request per composed page, after the pages (M8 gate 2)',
282
282
  'shop.categories': "the products' own categories, in order (shopCategoriesOf)",
283
283
  layoutPage: 'the layout step: one request per composed page, after the pages (M8 gate 2)',
284
+ 'page.free': 'the free step: a page the model writes free, on its own wire, set by the server (FS3)',
285
+ 'section.free': 'the free step: one signature section written free, set by the server (FS3, FS-D19)',
286
+ freePage: 'the free step: a page the model writes free, on its own wire, set by the server (FS3)',
287
+ freeRead: 'the free step (FS3)',
288
+ freeNode: 'the free step (FS3)',
284
289
  };
285
290
 
286
291
  const wireText = (spec: WireKey): string => {
@@ -63,6 +63,8 @@ export * from './layout-section-fallback';
63
63
  export * from './free-wire';
64
64
  export * from './check-free';
65
65
  export * from './free-fallback';
66
+ export * from './free-slots';
67
+ export * from './compose-free';
66
68
  export * from './prompt-limits';
67
69
  export * from './layout-photos';
68
70
  export * from './photo-inventory';
@@ -2,6 +2,7 @@ import type { FrameSequence } from '@vectoriox/iox-ui/media-core';
2
2
  import type { AnimateId, DesignChoices } from '@vectoriox/iox-ui/design-core';
3
3
  import { LocaleDirection, localeDirection } from '@vectoriox/iox-ui/design-core';
4
4
  import type { ArtDirection } from './art-direction';
5
+ import type { FreeNode, FreePage } from './free-wire';
5
6
  import type { LayoutPage } from './layout-language';
6
7
 
7
8
  import { SPEC_SITE_ARCHETYPES, SPEC_SITE_FACTS, SPEC_SITE_LOCALES, SPEC_SITE_NEED_IDS, SPEC_SITE_REQUIRED_ROLES, SPEC_SITE_ROLES } from './site-spec.generated';
@@ -241,6 +242,11 @@ export interface PageSectionPlan {
241
242
  readonly form?: string;
242
243
  /** How this section moves in, instead of the look's How animated (M1-6b; M2's "make the hero calmer"). */
243
244
  readonly enter?: AnimateId;
245
+ /**
246
+ * FS3 (award plan §11, FS-D19): ONE signature section the model wrote free — ordinary nodes, the look's tokens — stamped
247
+ * in this section's place (`composeFreeSection`); `pattern` stays its fall back. Set by the server, never by a model.
248
+ */
249
+ readonly free?: FreeNode;
244
250
  }
245
251
 
246
252
  /** A page's search-result words, when the plan writes them (each within the seo-core limits). */
@@ -291,6 +297,12 @@ export interface PagePlan {
291
297
  readonly compose?: boolean;
292
298
  /** M8 gate 2: the composed page — when present it is stamped (`composeLayout`) instead of `sections`. */
293
299
  readonly layout?: LayoutPage;
300
+ /**
301
+ * FS3 (award plan §11, FS-D19): the page the model wrote free — when present it is stamped (`composeFreePage`) instead of
302
+ * `sections`, a place the fall back gave away standing as its ready-made section (`readyMade.at` names `sections`).
303
+ * Set by the server, never by a model; never beside `layout`.
304
+ */
305
+ readonly free?: FreePage;
294
306
  }
295
307
 
296
308
  /**
@@ -168,7 +168,38 @@ export const SPEC_SITE_PLAN_SHAPE = {
168
168
  "seo?": "pageSeo",
169
169
  "sections": "section[] — the page from patterns; a composed page keeps them as its fallback",
170
170
  "compose?": "boolean — the page is composed in the layout language (M8 gate 2): which pages is the generation’s tier (AW-D23/24) — Basic the home page and at most one other, Award every page that is no per-item or legal page; written with the pages, the layout step fills `layout`",
171
- "layout?": "layoutPage — the composed page (the layout step's, never the Pages request's): when present the page is stamped from it and `sections` is not"
171
+ "layout?": "layoutPage — the composed page (the layout step's, never the Pages request's): when present the page is stamped from it and `sections` is not",
172
+ "free?": "freePage — FS3 (award plan §11, FS-D19): the page the model wrote free (the free step's, set by the server, never a model's): when present the page is stamped from it (generation-core composeFreePage) and `sections` is not, but a place the fall back gave away stands as its ready-made section (readyMade.at names `sections`); never beside `layout`"
173
+ },
174
+ "freePage": {
175
+ "read": "freeRead — what the answer says about itself",
176
+ "pictures": "string — generation-core FreePictures: how the page treats its pictures (information, never a gate)",
177
+ "sections": "freeNode[] — the page: Sections only at the top (4–9, FREE_SECTIONS)",
178
+ "givenAway?": "integer — the model's sections the fall back dropped (the page's minimum forgives them, iox-ui#134). Set by the fall back, never by a model"
179
+ },
180
+ "freeRead": {
181
+ "idea": "string — one sentence: the page's idea",
182
+ "why": "string — one sentence: why it suits this business",
183
+ "followed": "string — which of the owner's words the page followed, quoting them as written (R-H17)"
184
+ },
185
+ "freeNode": {
186
+ "id": "string — unique on the page (a #id link scrolls to it)",
187
+ "type": "string — generation-core FreeNodeType: Section · Container · Heading · Text · Button · Image · Video · Slot (stamped as FREE_BUILDER_TYPE)",
188
+ "purpose?": "string — a Section: generation-core FreePurpose (what it is for; the fall back reads it)",
189
+ "elementStyle?": "string — one of the look's element styles the type wears (FREE_ELEMENT_STYLES)",
190
+ "level?": "integer — a Heading: 1–4",
191
+ "role?": "'lead' — the heading a visitor reads first",
192
+ "text?": "string — a Heading, Text or Button: its words, in the site's language",
193
+ "src?": "string — an Image or Video: a material id (the owner's photo or video)",
194
+ "href?": "string — a Button: a page route of the plan, or #<id> of a section of this page",
195
+ "slot?": "string — a Slot: what stands there — list:<a query source alias> (composeList) or form:<a forms-core preset> (the preset's form)",
196
+ "opts?": "string[] — a Slot's options: a list's mix words <ingredient>:<word> (site.layout.list)",
197
+ "styleProps": "{ [style trait]: string } — the node's styles (generation-core FREE_STYLE_PROPS + FREE_TOKEN_PROPS; a value the look owns is its token)",
198
+ "responsive?": "{ mobile?, tablet? } — the styles a width overrides (a phone layer: `mobile` reaches `small`)",
199
+ "hover?": "{ [style trait]: string } — a hover: transform, opacity or a colour token only (FREE_HOVER_PROPS)",
200
+ "move?": "{ trigger, action, params? } — ONE move: generation-core FREE_MOVES (viewportEnter · scrollProgress)",
201
+ "children?": "freeNode[] — a Section or Container only",
202
+ "readyMade?": "{ at, pattern } — set by the fall back: the plan section `sections[at]` (its pattern) stands here instead"
172
203
  },
173
204
  "pageSeo": {
174
205
  "title?": "string ≤ 60 — the page title in search results (absent = the page name · the business)",
@@ -181,7 +212,8 @@ export const SPEC_SITE_PLAN_SHAPE = {
181
212
  "binding?": "string — the list source a pattern's $binding repeater iterates (exactly when it has one); a $binding? pattern (faq.accordion) MAY take one — then its items come from that content",
182
213
  "without?": "string[] — the pattern's optional parts to leave out",
183
214
  "form?": "string — a forms-core preset for the pattern's form (contact · newsletter · application · booking)",
184
- "enter?": "string — axes.animations: how this section moves in, instead of the look's (M2: 'make the hero calmer')"
215
+ "enter?": "string — axes.animations: how this section moves in, instead of the look's (M2: 'make the hero calmer')",
216
+ "free?": "freeNode — FS3 (award plan §11, FS-D19): ONE signature Section the model wrote free (set by the server, never a model's), stamped in this section's place (generation-core composeFreeSection); `pattern` stays its fall back. Never on a section with a binding or a form, never on a per-item page"
185
217
  },
186
218
  "globals": {
187
219
  "header": "string — a header pattern (global: before)",
@@ -20,6 +20,8 @@ import { headerMixFromWords } from './header-mix';
20
20
  import { openingMixFromWords } from './opening-mix';
21
21
  import { bodyMixFromWords } from './body-mix';
22
22
  import { patternListGap } from './recipe-fields';
23
+ import { freeSlotIssues } from './check-free';
24
+ import { FREE_ELEMENT_STYLES, FREE_HOLDERS, FREE_MOVES, FREE_WORD_TYPES, FreeLayer, FreeNode, FreeNodeType, FreeTrigger } from './free-wire';
23
25
  import { SPEC_SITE_LAYOUT, SPEC_SITE_PLAN_SHAPE } from './site-spec.generated';
24
26
  import {
25
27
  isNonEmptyString, isPlainObject as isObject, PathIssue, PathIssueCollector, pathAt as at, PlainObject as Obj, requiredShapeKeys, ShapeEntry, shapeKeys,
@@ -95,6 +97,9 @@ export enum SitePlanIssueCode {
95
97
  Compose = 'compose',
96
98
  /** M8 gate 2: a composed page's layout (`checkLayout`'s issues, each at its path under `layout`). */
97
99
  Layout = 'layout',
100
+ /** FS3: a free page or a free signature section the stamp could not make as written — its shape, a node type, a slot,
101
+ * a link, a ready-made place, a style the node's type has no control for (the rest is `checkFree`'s). */
102
+ Free = 'free',
98
103
  /** Commerce C-D21: what the business sells — a selling business without its products, one that sells nothing with a
99
104
  * shop, a product past the sixth, a shop source with no shop, or a content type named after a shop list. */
100
105
  Shop = 'shop',
@@ -160,6 +165,9 @@ const FILM_KEYS = shapeKeys(SHAPE['film']);
160
165
  const ART_DIRECTION_KEYS = shapeKeys(SHAPE['artDirection']);
161
166
  const DIRECTION_KEYS = shapeKeys(SHAPE['direction']);
162
167
  const LAYOUT_PAGE_KEYS = shapeKeys(SHAPE['layoutPage']);
168
+ const FREE_PAGE_KEYS = shapeKeys(SHAPE['freePage']);
169
+ const FREE_READ_KEYS = shapeKeys(SHAPE['freeRead']);
170
+ const FREE_NODE_KEYS = shapeKeys(SHAPE['freeNode']);
163
171
  const LAYOUT_DIALS: ReadonlyArray<string> = SPEC_SITE_LAYOUT.vocab.dials;
164
172
  const COMPOSED_PAGES_MAX: number = SPEC_SITE_LAYOUT.limits.composedPages;
165
173
  const DIRECTION_RULES_MAX = 3;
@@ -790,6 +798,7 @@ export function validateSitePlan(plan: unknown, ctx: SitePlanContext = {}): Site
790
798
  validateArtDirection(c, plan['artDirection']);
791
799
  validateDirection(c, plan['direction']);
792
800
  validateComposed(c, c.array(plan, 'pages', ''), ctx.tier);
801
+ validateFree(c, c.array(plan, 'pages', ''), sources);
793
802
  return { valid: c.issues.length === 0, issues: c.issues };
794
803
  }
795
804
 
@@ -836,6 +845,121 @@ function validateComposed(c: Collector, pages: unknown[], tier: `${GenerationTie
836
845
  if (composed > composedPagesMax(tier ?? GenerationTier.Basic)) c.add(SitePlanIssueCode.Compose, 'pages', `${composed} composed pages — the home page and at most ${COMPOSED_PAGES_MAX - 1} other`);
837
846
  }
838
847
 
848
+ /**
849
+ * FS3: the free pages and the free signature sections — what the stamp (`composeFree`) needs to make them as written: a
850
+ * free page only on a page marked `compose` and never beside a layout; its shape; node types where they may stand; ids
851
+ * unique; element styles a type wears; a move the product has; a list slot a list source of the plan, a form slot a
852
+ * forms-core preset; a button to a page of the plan or a section of the same page; a ready-made place one of the page's
853
+ * own; a style its type has a control for. A signature section stands on a page stamped from patterns. Taste, words,
854
+ * contrast and the phone are `checkFree`'s.
855
+ */
856
+ function validateFree(c: Collector, pages: unknown[], sources: Map<string, SourceInfo>): void {
857
+ const routes = new Set(pages.map(p => (isObject(p) && typeof p['route'] === 'string' && !routeParams(p['route']).length ? p['route'] : null)).filter((r): r is string => !!r));
858
+ pages.forEach((raw, i) => {
859
+ if (!isObject(raw)) return;
860
+ const path = `pages[${i}]`;
861
+ const plan = Array.isArray(raw['sections']) ? raw['sections'] : [];
862
+ const free = raw['free'];
863
+ if (free !== undefined) {
864
+ if (raw['compose'] !== true) c.add(SitePlanIssueCode.Compose, `${path}.free`, 'a free page only on a page marked compose');
865
+ if (raw['layout'] !== undefined) c.add(SitePlanIssueCode.Free, `${path}.free`, 'a page is laid out or free — never both');
866
+ if (!isObject(free)) c.add(SitePlanIssueCode.Shape, `${path}.free`, 'must be an object');
867
+ else {
868
+ const fp = `${path}.free`;
869
+ c.keys(free, FREE_PAGE_KEYS, fp);
870
+ if (!isObject(free['read'])) c.add(SitePlanIssueCode.Shape, `${fp}.read`, 'must be an object');
871
+ else c.keys(free['read'], FREE_READ_KEYS, `${fp}.read`);
872
+ c.string(free, 'pictures', fp);
873
+ if (free['givenAway'] !== undefined && !(Number.isInteger(free['givenAway']) && (free['givenAway'] as number) >= 0)) c.add(SitePlanIssueCode.Shape, `${fp}.givenAway`, 'a count');
874
+ const sections = c.array(free, 'sections', fp);
875
+ if (!sections.length) c.add(SitePlanIssueCode.Free, `${fp}.sections`, 'a free page has its sections');
876
+ validateFreeTree(c, sections, `${fp}.sections`, { routes, sources, plan, readyMade: true });
877
+ }
878
+ }
879
+ plan.forEach((s, j) => {
880
+ if (!isObject(s) || s['free'] === undefined) return;
881
+ const sp = `${path}.sections[${j}].free`;
882
+ if (raw['layout'] !== undefined || free !== undefined) c.add(SitePlanIssueCode.Free, sp, 'a free section stands on a page stamped from its sections — not on a laid-out or free page');
883
+ if (isPerItemPage(raw)) c.add(SitePlanIssueCode.Free, sp, 'a per-item page shows its item from patterns');
884
+ if (s['binding'] !== undefined || s['form'] !== undefined) c.add(SitePlanIssueCode.Free, sp, 'a free section never stands where the section binds content or holds a form — it places them as slots');
885
+ if (!isObject(s['free'])) return c.add(SitePlanIssueCode.Shape, sp, 'must be an object');
886
+ validateFreeTree(c, [s['free']], sp, { routes, sources, plan, readyMade: false }, true);
887
+ });
888
+ });
889
+ }
890
+
891
+ interface FreeTreeContext {
892
+ routes: ReadonlySet<string>;
893
+ sources: Map<string, SourceInfo>;
894
+ /** The page's plan sections (a ready-made place names one). */
895
+ plan: ReadonlyArray<unknown>;
896
+ readyMade: boolean;
897
+ }
898
+
899
+ const FREE_LIST_SLOT = 'list:';
900
+ const FREE_FORM_SLOT = 'form:';
901
+
902
+ function validateFreeTree(c: Collector, roots: unknown[], path: string, ctx: FreeTreeContext, single = false): void {
903
+ const ids = new Set<string>();
904
+ const seen = (n: unknown) => {
905
+ if (!isObject(n)) return;
906
+ if (typeof n['id'] === 'string') ids.add(n['id']);
907
+ if (Array.isArray(n['children'])) n['children'].forEach(seen);
908
+ };
909
+ roots.forEach(seen);
910
+ const used = new Set<string>();
911
+ const node = (raw: unknown, p: string, top: boolean) => {
912
+ if (!isObject(raw)) return c.add(SitePlanIssueCode.Shape, p, 'must be an object');
913
+ c.keys(raw, FREE_NODE_KEYS, p);
914
+ const id = c.string(raw, 'id', p);
915
+ if (id && used.has(id)) c.add(SitePlanIssueCode.Duplicate, `${p}.id`, `the id "${id}" is used twice`);
916
+ if (id) used.add(id);
917
+ const type = raw['type'] as FreeNodeType;
918
+ if (!Object.values(FreeNodeType).includes(type)) return c.add(SitePlanIssueCode.Free, `${p}.type`, `"${String(type)}" is not a free node type (${Object.values(FreeNodeType).join(', ')})`);
919
+ if ((type === FreeNodeType.Section) !== top) c.add(SitePlanIssueCode.Free, p, top ? 'the top holds Sections only' : 'a Section stands at the top only');
920
+ const ready = raw['readyMade'];
921
+ if (ready !== undefined) {
922
+ const at = isObject(ready) ? ready['at'] : undefined;
923
+ const section = Number.isInteger(at) ? ctx.plan[at as number] : undefined;
924
+ if (!ctx.readyMade || !top) c.add(SitePlanIssueCode.Free, `${p}.readyMade`, 'a ready-made place only stands for a section of a free page');
925
+ else if (!isObject(section) || !isObject(ready) || section['pattern'] !== ready['pattern']) c.add(SitePlanIssueCode.Free, `${p}.readyMade`, 'names a section of this page, with its pattern');
926
+ return;
927
+ }
928
+ const styles = FREE_ELEMENT_STYLES[type] ?? [];
929
+ const style = raw['elementStyle'];
930
+ if (style !== undefined && !styles.includes(String(style))) c.add(SitePlanIssueCode.Free, `${p}.elementStyle`, `a ${type} wears ${styles.join(', ') || 'no element style'}`);
931
+ if (FREE_WORD_TYPES.includes(type) && !isNonEmptyString(raw['text'])) c.add(SitePlanIssueCode.Free, `${p}.text`, 'its words are missing');
932
+ if (type === FreeNodeType.Heading && !(Number.isInteger(raw['level']) && (raw['level'] as number) >= 1 && (raw['level'] as number) <= 4)) c.add(SitePlanIssueCode.Free, `${p}.level`, 'a Heading is level 1 to 4');
933
+ if (type === FreeNodeType.Button) {
934
+ const href = String(raw['href'] ?? '');
935
+ if (!(ctx.routes.has(href) || (href.startsWith('#') && ids.has(href.slice(1))))) c.add(SitePlanIssueCode.Free, `${p}.href`, 'a button goes to a page of the plan or to a section of this page (#id)');
936
+ }
937
+ if (type === FreeNodeType.Slot) {
938
+ const slot = String(raw['slot'] ?? '');
939
+ const ok = slot.startsWith(FREE_LIST_SLOT) ? isListSource(ctx.sources.get(slot.slice(FREE_LIST_SLOT.length)))
940
+ : slot.startsWith(FREE_FORM_SLOT) ? !!formPresetById(slot.slice(FREE_FORM_SLOT.length)) : false;
941
+ if (!ok) c.add(SitePlanIssueCode.Free, `${p}.slot`, `"${slot}" — list:<a list source of the plan> or form:<a form preset>`);
942
+ }
943
+ const move = raw['move'];
944
+ if (move !== undefined && !(isObject(move) && FREE_MOVES[move['trigger'] as FreeTrigger]?.[String(move['action'])])) c.add(SitePlanIssueCode.Free, `${p}.move`, 'a move the product has (FREE_MOVES)');
945
+ if (!isObject(raw['styleProps'])) c.add(SitePlanIssueCode.Shape, `${p}.styleProps`, 'must be an object');
946
+ const responsive = raw['responsive'];
947
+ if (responsive !== undefined) {
948
+ if (!isObject(responsive)) c.add(SitePlanIssueCode.Shape, `${p}.responsive`, 'must be an object');
949
+ else for (const bp of Object.keys(responsive)) if (!(Object.values(FreeLayer) as string[]).includes(bp)) c.add(SitePlanIssueCode.Free, `${p}.responsive.${bp}`, `a width is ${Object.values(FreeLayer).join(' or ')}`);
950
+ }
951
+ for (const i of freeSlotIssues(raw as unknown as FreeNode, p)) c.add(SitePlanIssueCode.Free, i.path, i.message);
952
+ const children = raw['children'];
953
+ if (children !== undefined) {
954
+ if (!Array.isArray(children)) return c.add(SitePlanIssueCode.Shape, `${p}.children`, 'must be an array');
955
+ if (children.length && !FREE_HOLDERS.includes(type)) c.add(SitePlanIssueCode.Free, `${p}.children`, `a ${type} holds no children`);
956
+ children.forEach((child, k) => node(child, `${p}.children[${k}]`, false));
957
+ }
958
+ };
959
+ if (single && roots.length !== 1) c.add(SitePlanIssueCode.Free, path, 'a free section is ONE Section');
960
+ roots.forEach((r, k) => node(r, single ? path : `${path}[${k}]`, true));
961
+ }
962
+
839
963
  /** The plan's content types and, for each shop list a source reads, the shop's own (fixed fields and roles). */
840
964
  function withShopTypes(types: Map<string, ContentTypeInfo>, sources: Map<string, SourceInfo>): Map<string, ContentTypeInfo> {
841
965
  const out = new Map(types);