@vectoriox/iox-ui 5.114.0 → 5.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +2393 -1744
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +394 -7
- package/package.json +1 -1
- package/src/generation-core/compose-site.ts +10 -1
- package/src/generation-core/footer-mix.ts +328 -0
- package/src/generation-core/layout-fingerprint.ts +13 -3
- package/src/generation-core/plan-wire.ts +28 -4
- package/src/generation-core/public-api.ts +1 -0
- package/src/generation-core/site-plan.model.ts +9 -0
- package/src/generation-core/site-spec.generated.ts +294 -3
- package/src/generation-core/validate-site-plan.ts +20 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { DesignChoices, elementStyleFace, resolveDesignChoices, textWidthEm } from '@vectoriox/iox-ui/design-core';
|
|
2
|
+
|
|
3
|
+
import { screenFontSize, screenWordOverflowPx } from './layout-language';
|
|
4
|
+
import { PatternGlobalPosition, PatternNode, SITE_PATTERNS, SitePattern } from './patterns';
|
|
5
|
+
import { SPEC_SITE_FOOTER_PARTS, SPEC_SITE_LAYOUT } from './site-spec.generated';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* FOOTER INGREDIENTS (list-ingredients-plan.md LI5): a site's footer is a MIX — an arrangement, the blocks it holds, how
|
|
9
|
+
* it closes and what it stands on — never one of three footer patterns. Every word, its meaning, the named mixes stored
|
|
10
|
+
* plans use, the fingerprint and Doron's references live in ONE table, the contract's `site.layout.footer` (layout.mjs
|
|
11
|
+
* `FOOTER`); the parts a footer is made of are the contract's `site.footerParts`. This module reads both: it checks a
|
|
12
|
+
* mix (`checkFooter`) and arranges the parts (`footerPattern`) into an ordinary pattern the composer stamps — the same
|
|
13
|
+
* stamper, the same nodes as every section, on the canvas and both engine paths. Pure.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const F = SPEC_SITE_LAYOUT.footer;
|
|
17
|
+
const PARTS = SPEC_SITE_FOOTER_PARTS as unknown as Readonly<Record<string, PatternNode>>;
|
|
18
|
+
|
|
19
|
+
/** The ingredients, by the contract's keys (held equal to it by footer-mix.spec). */
|
|
20
|
+
export enum FooterIngredient {
|
|
21
|
+
Arrange = 'arrange',
|
|
22
|
+
Holds = 'holds',
|
|
23
|
+
Closing = 'closing',
|
|
24
|
+
Ground = 'ground',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export enum FooterArrange {
|
|
28
|
+
Columns = 'columns',
|
|
29
|
+
Centred = 'centred',
|
|
30
|
+
Line = 'line',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export enum FooterHold {
|
|
34
|
+
Pages = 'pages',
|
|
35
|
+
Visit = 'visit',
|
|
36
|
+
Contact = 'contact',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum FooterClosing {
|
|
40
|
+
None = 'none',
|
|
41
|
+
Call = 'call',
|
|
42
|
+
Name = 'name',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum FooterGround {
|
|
46
|
+
Inverse = 'inverse',
|
|
47
|
+
Plain = 'plain',
|
|
48
|
+
Subtle = 'subtle',
|
|
49
|
+
Accent = 'accent',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One word per ingredient; `holds` several, in the table's order. */
|
|
53
|
+
export interface FooterMix {
|
|
54
|
+
readonly arrange: string;
|
|
55
|
+
readonly holds: ReadonlyArray<string>;
|
|
56
|
+
readonly closing: string;
|
|
57
|
+
readonly ground: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class FooterMixError extends Error {}
|
|
61
|
+
|
|
62
|
+
const INGREDIENTS = F.ingredients as unknown as Readonly<Record<string, ReadonlyArray<string>>>;
|
|
63
|
+
const MEANINGS = F.meanings as Readonly<Record<string, string>>;
|
|
64
|
+
const MANY: ReadonlyArray<string> = F.many;
|
|
65
|
+
|
|
66
|
+
/** The footer pattern a plan names when it names none the table knows (the Studio footer). */
|
|
67
|
+
export const DEFAULT_FOOTER_PATTERN = 'footer.three-column';
|
|
68
|
+
|
|
69
|
+
/** The words an ingredient may take. */
|
|
70
|
+
export function footerWords(ingredient: `${FooterIngredient}`): ReadonlyArray<string> {
|
|
71
|
+
return INGREDIENTS[ingredient] ?? [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** What a word means, as the brief and the builder say it. */
|
|
75
|
+
export function footerMeaning(ingredient: `${FooterIngredient}`, word: string): string {
|
|
76
|
+
return MEANINGS[`${ingredient}.${word}`] ?? word;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A word list in the table's order, each once. */
|
|
80
|
+
const inOrder = (k: string, words: ReadonlyArray<string>): string[] => footerWords(k as FooterIngredient).filter(w => words.includes(w));
|
|
81
|
+
|
|
82
|
+
/** A whole mix from part of one: what is not named is the default. Refuses a word the table lacks. */
|
|
83
|
+
export function footerMix(partial: Partial<FooterMix> = {}): FooterMix {
|
|
84
|
+
const mix: Record<string, string | ReadonlyArray<string>> = { ...(F.defaults as unknown as FooterMix) };
|
|
85
|
+
for (const [k, v] of Object.entries(partial)) {
|
|
86
|
+
if (v === undefined) continue;
|
|
87
|
+
if (!INGREDIENTS[k]) throw new FooterMixError(`no footer ingredient "${k}"`);
|
|
88
|
+
const words = typeof v === 'string' ? [v] : v as ReadonlyArray<string>;
|
|
89
|
+
if (MANY.includes(k) !== (typeof v !== 'string')) throw new FooterMixError(`a footer's ${k} is ${MANY.includes(k) ? 'a list of words' : 'one word'}`);
|
|
90
|
+
for (const w of words) if (!INGREDIENTS[k].includes(w)) throw new FooterMixError(`a footer's ${k} cannot be "${w}" (${INGREDIENTS[k].join(' · ')})`);
|
|
91
|
+
mix[k] = MANY.includes(k) ? inOrder(k, words) : words[0];
|
|
92
|
+
}
|
|
93
|
+
return mix as unknown as FooterMix;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The mix a stored footer pattern id stands for (`footer.three-column`, `footer.mega`, `footer.minimal`), or null. */
|
|
97
|
+
export function namedFooterMix(patternId: string): FooterMix | null {
|
|
98
|
+
const named = (F.named as Readonly<Record<string, Partial<FooterMix>>>)[patternId];
|
|
99
|
+
return named ? footerMix(named) : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The stored footer pattern a mix is exactly, else null. */
|
|
103
|
+
export function footerPatternIdOf(mix: FooterMix): string | null {
|
|
104
|
+
const key = footerTokenOf(mix) + JSON.stringify(mix.holds);
|
|
105
|
+
return Object.keys(F.named).find(id => {
|
|
106
|
+
const m = namedFooterMix(id)!;
|
|
107
|
+
return footerTokenOf(m) + JSON.stringify(m.holds) === key;
|
|
108
|
+
}) ?? null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A mix on the wire: ONE list of `<ingredient>:<word>` words (the list wire's encoding), `holds` once per block. */
|
|
112
|
+
export function footerMixWords(mix: FooterMix): string[] {
|
|
113
|
+
return Object.values(FooterIngredient).flatMap(k => (MANY.includes(k) ? mix[k] as ReadonlyArray<string> : [mix[k] as string]).map(w => `${k}:${w}`));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Every `<ingredient>:<word>` the wire may carry (every footer word is drawn — the table's `waits` is empty). */
|
|
117
|
+
export function footerWireWords(): string[] {
|
|
118
|
+
return Object.values(FooterIngredient).flatMap(k => footerWords(k).filter(w => !(F.waits as Readonly<Record<string, unknown>>)[`${k}.${w}`]).map(w => `${k}:${w}`));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The words back into a mix: an ingredient not named is the default; a `holds` named is the whole list. Refuses an unknown
|
|
122
|
+
* word, and two words for a one-word ingredient. */
|
|
123
|
+
export function footerMixFromWords(words: ReadonlyArray<string>): FooterMix {
|
|
124
|
+
const partial: Record<string, string | string[]> = {};
|
|
125
|
+
for (const pair of words) {
|
|
126
|
+
const [k, w] = String(pair).split(':');
|
|
127
|
+
if (!INGREDIENTS[k] || !w) throw new FooterMixError(`"${pair}" is no footer word (<ingredient>:<word>)`);
|
|
128
|
+
if (MANY.includes(k)) ((partial[k] ??= []) as string[]).push(w);
|
|
129
|
+
else if (partial[k] !== undefined && partial[k] !== w) throw new FooterMixError(`a footer has one ${k} ("${partial[k]}" and "${w}")`);
|
|
130
|
+
else partial[k] = w;
|
|
131
|
+
}
|
|
132
|
+
return footerMix(partial as Partial<FooterMix>);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The site plan's footer as a mix: its `mixes.footer` when it has one, else its `globals.footer` pattern read as a named
|
|
136
|
+
* mix, else the Studio footer. */
|
|
137
|
+
export function footerMixOfPlan(plan: { readonly globals?: Readonly<Record<string, string>>; readonly mixes?: { readonly footer?: ReadonlyArray<string> } }): FooterMix {
|
|
138
|
+
if (plan.mixes?.footer?.length) return footerMixFromWords(plan.mixes.footer);
|
|
139
|
+
return namedFooterMix(plan.globals?.['footer'] ?? '') ?? footerMix();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The fingerprint's prefix for a footer. */
|
|
143
|
+
export const FOOTER_TOKEN = 'footer';
|
|
144
|
+
|
|
145
|
+
/** A footer as the fingerprint sees it: `footer:<arrange>/<closing>/<ground>` — what a visitor takes in at once, in the
|
|
146
|
+
* contract's order. Two sites with the same token wear the same footer. */
|
|
147
|
+
export function footerTokenOf(mix: FooterMix): string {
|
|
148
|
+
return `${FOOTER_TOKEN}:${(F.fingerprint as ReadonlyArray<string>).map(k => mix[k as keyof FooterMix]).join('/')}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** A footer token in words: `footer:columns/none/inverse` → "columns · none · inverse". */
|
|
152
|
+
export const footerTokenWords = (token: string): string => token.replace(`${FOOTER_TOKEN}:`, '').split('/').join(' · ');
|
|
153
|
+
|
|
154
|
+
/** Doron's reference footers, each as a whole mix. */
|
|
155
|
+
export function footerReferences(): ReadonlyArray<{ id: string; after: string; added: string; mix: FooterMix }> {
|
|
156
|
+
return (F.references as unknown as ReadonlyArray<{ id: string; after: string; added: string; mix: Partial<FooterMix> }>)
|
|
157
|
+
.map(r => ({ id: r.id, after: r.after, added: r.added, mix: footerMix(r.mix) }));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ── The check: any mix, judged and mended ──────────────────────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
export enum FooterRepairCode {
|
|
163
|
+
/** A one-line footer holds only the pages: the other blocks need room. */
|
|
164
|
+
LineHolds = 'line-holds',
|
|
165
|
+
/** A footer that holds nothing and closes with nothing: it holds the pages. */
|
|
166
|
+
Empty = 'empty',
|
|
167
|
+
/** The name is too long to stand across a phone's width at the smallest size: no closing name. */
|
|
168
|
+
NameTooLong = 'name-too-long',
|
|
169
|
+
/** Another site already wears this footer: the nearest free one (`distinctFooter`). */
|
|
170
|
+
Worn = 'worn',
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface FooterRepair {
|
|
174
|
+
code: FooterRepairCode;
|
|
175
|
+
/** In plain words, for the wizard and the model's next turn. */
|
|
176
|
+
said: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** What the check needs of the site: the business name and the look it wears. */
|
|
180
|
+
export interface FooterContext {
|
|
181
|
+
name: string;
|
|
182
|
+
design: DesignChoices;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The phone the closing name must fit (the render check's). */
|
|
186
|
+
const PHONE_WIDTH = 390;
|
|
187
|
+
|
|
188
|
+
/** How wide the name stands at 1em in the look's display face. */
|
|
189
|
+
const nameWidthEm = (ctx: FooterContext): number => textWidthEm(ctx.name, elementStyleFace(ctx.design, 'display'));
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The ONE judge of a footer mix: what the table's rules refuse is mended to the nearest mix that keeps them, and each mend
|
|
193
|
+
* is said. Never throws on a well-formed mix. Pure.
|
|
194
|
+
*/
|
|
195
|
+
export function checkFooter(mix: FooterMix, ctx: FooterContext): { mix: FooterMix; repairs: FooterRepair[] } {
|
|
196
|
+
const repairs: FooterRepair[] = [];
|
|
197
|
+
let holds = inOrder(FooterIngredient.Holds, mix.holds);
|
|
198
|
+
let closing = mix.closing;
|
|
199
|
+
if (mix.arrange === FooterArrange.Line) {
|
|
200
|
+
const kept = holds.filter(h => (F.rules.lineHolds as ReadonlyArray<string>).includes(h));
|
|
201
|
+
const left = holds.filter(h => !kept.includes(h));
|
|
202
|
+
if (left.length) repairs.push({ code: FooterRepairCode.LineHolds, said: `a one-line footer holds only ${F.rules.lineHolds.join(' and ')}: ${left.join(' and ')} left out` });
|
|
203
|
+
holds = kept;
|
|
204
|
+
}
|
|
205
|
+
if (closing === FooterClosing.Name && screenWordOverflowPx(nameWidthEm(ctx), 12, PHONE_WIDTH, true) > 0) {
|
|
206
|
+
repairs.push({ code: FooterRepairCode.NameTooLong, said: `"${ctx.name}" is too long to stand across a phone: the footer closes with nothing` });
|
|
207
|
+
closing = FooterClosing.None;
|
|
208
|
+
}
|
|
209
|
+
if (holds.length < F.rules.minHolds && closing === FooterClosing.None) {
|
|
210
|
+
repairs.push({ code: FooterRepairCode.Empty, said: 'a footer that holds nothing holds the pages' });
|
|
211
|
+
holds = [FooterHold.Pages];
|
|
212
|
+
}
|
|
213
|
+
return { mix: { ...mix, holds, closing }, repairs };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ── The recipe: the mix arranged from the contract's parts ─────────────────────────────────────────────────────────
|
|
217
|
+
|
|
218
|
+
const clone = <T>(v: T): T => JSON.parse(JSON.stringify(v));
|
|
219
|
+
const part = (id: string): PatternNode => clone(PARTS[id]);
|
|
220
|
+
/** A part with more layout, its own kept. */
|
|
221
|
+
const laid = (node: PatternNode, lay: Readonly<Record<string, string>>): PatternNode => ({ ...node, lay: { ...(node.lay ?? {}), ...lay } });
|
|
222
|
+
const GAP = 'var(--iox-space-gap)';
|
|
223
|
+
const CENTRED = { alignItems: 'center', textAlign: 'center' };
|
|
224
|
+
|
|
225
|
+
/** The columns of a footer's grid: the name's block wider, one column per block it holds. */
|
|
226
|
+
function columnsOf(count: number): Pick<PatternNode, 'lay' | 'resp'> {
|
|
227
|
+
const lay = { display: 'grid', gridTemplateColumns: ['2fr', ...Array.from({ length: count }, () => '1fr')].join(' '), gap: GAP };
|
|
228
|
+
const resp: Record<string, Record<string, string>> = count >= 3
|
|
229
|
+
? { tablet: { gridTemplateColumns: 'repeat(2, minmax(0, 1fr))' }, mobile: { gridTemplateColumns: 'minmax(0, 1fr)' } }
|
|
230
|
+
: { mobile: { gridTemplateColumns: 'minmax(0, 1fr)' } };
|
|
231
|
+
return { lay, resp };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The closing name: the business name across the width — fitted to the name in the look's display face as a layout's
|
|
235
|
+
* screen word is (`screenFontSize`, the 12-column room), never under the smallest or over the largest screen word. */
|
|
236
|
+
function closingName(ctx: FooterContext): PatternNode {
|
|
237
|
+
return laid(part('name'), { fontSize: screenFontSize(nameWidthEm(ctx), 12, 0, 0, 0) });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** A block it holds: how to reach the business leaves its city to the visit block when the footer holds both. */
|
|
241
|
+
function holdPart(hold: string, mix: FooterMix): PatternNode {
|
|
242
|
+
const node = part(hold);
|
|
243
|
+
if (hold !== FooterHold.Contact || !mix.holds.includes(FooterHold.Visit)) return node;
|
|
244
|
+
return { ...node, c: (node.c ?? []).filter(n => n.ph !== 'city') };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The body: the blocks it holds, arranged. */
|
|
248
|
+
function bodyOf(mix: FooterMix): PatternNode[] {
|
|
249
|
+
const holds = mix.holds.map(h => holdPart(h, mix));
|
|
250
|
+
switch (mix.arrange) {
|
|
251
|
+
case FooterArrange.Line: {
|
|
252
|
+
const row: PatternNode = { t: 'Container', es: 'box', lay: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', gap: GAP }, c: [
|
|
253
|
+
laid(part('copyright'), { width: 'auto' }),
|
|
254
|
+
...(mix.holds.includes(FooterHold.Pages) ? [part('pageRow')] : []),
|
|
255
|
+
] };
|
|
256
|
+
return [row];
|
|
257
|
+
}
|
|
258
|
+
case FooterArrange.Centred: {
|
|
259
|
+
const blocks = mix.holds.map(h => (h === FooterHold.Pages ? laid(part('pageRow'), { justifyContent: 'center' }) : laid(holdPart(h, mix), CENTRED)));
|
|
260
|
+
return [
|
|
261
|
+
{ t: 'Container', es: 'box', lay: { display: 'flex', flexDirection: 'column', gap: '28px', ...CENTRED }, c: [laid(part('brand'), CENTRED), ...blocks] },
|
|
262
|
+
part('rule'),
|
|
263
|
+
laid(part('copyright'), { textAlign: 'center' }),
|
|
264
|
+
];
|
|
265
|
+
}
|
|
266
|
+
default:
|
|
267
|
+
return [{ t: 'Container', es: 'box', ...columnsOf(holds.length), c: [part('brand'), ...holds] }, part('rule'), part('copyright')];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** A footer mix as a pattern: what the composer stamps as the site's footer (global, after the page). Check it first. */
|
|
272
|
+
export function footerPattern(mix: FooterMix, ctx: FooterContext): SitePattern {
|
|
273
|
+
const plain = mix.ground === FooterGround.Plain;
|
|
274
|
+
const call = mix.closing === FooterClosing.Call ? [mix.arrange === FooterArrange.Columns ? part('call') : laid(part('call'), CENTRED)] : [];
|
|
275
|
+
const name = mix.closing === FooterClosing.Name ? [closingName(ctx)] : [];
|
|
276
|
+
const c = [...(plain ? [part('rule')] : []), ...call, ...bodyOf(mix), ...name];
|
|
277
|
+
// The contract's shell; a Section with one child does not stack it (the patterns' rule, build-spec "more than one child").
|
|
278
|
+
const { lay, ...shell } = part('section');
|
|
279
|
+
const node: PatternNode = { ...shell, ...(c.length > 1 && lay ? { lay } : {}), ...(plain ? {} : { scheme: mix.ground }), c };
|
|
280
|
+
// A stored footer keeps its own name and intent (the composed root is labelled with it).
|
|
281
|
+
const stored = SITE_PATTERNS[footerPatternIdOf(mix) ?? ''];
|
|
282
|
+
return {
|
|
283
|
+
family: 'footer',
|
|
284
|
+
label: stored?.label ?? `Footer — ${footerTokenWords(footerTokenOf(mix))}`,
|
|
285
|
+
intent: stored?.intent ?? [footerMeaning(FooterIngredient.Arrange, mix.arrange), footerMeaning(FooterIngredient.Closing, mix.closing), footerMeaning(FooterIngredient.Ground, mix.ground)].join('; '),
|
|
286
|
+
global: PatternGlobalPosition.After,
|
|
287
|
+
node,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ── No sameness: another site's footer is never worn again ─────────────────────────────────────────────────────────
|
|
292
|
+
|
|
293
|
+
/** The ingredients `distinctFooter` may change, in the order it tries them: how it closes and what it stands on before the
|
|
294
|
+
* arrangement the model chose. */
|
|
295
|
+
const MEND_ORDER: ReadonlyArray<FooterIngredient.Closing | FooterIngredient.Ground | FooterIngredient.Arrange> = [
|
|
296
|
+
FooterIngredient.Closing, FooterIngredient.Ground, FooterIngredient.Arrange,
|
|
297
|
+
];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* A footer no other site wears (R-H10): the mix when its token is free, else the nearest mix whose token is — one changed
|
|
301
|
+
* ingredient before two, in `MEND_ORDER`, each word in the table's order — checked again (`checkFooter`), and said. When
|
|
302
|
+
* every footer is worn, the mix as it is. Pure, deterministic.
|
|
303
|
+
*/
|
|
304
|
+
export function distinctFooter(mix: FooterMix, taken: ReadonlyArray<string>, ctx: FooterContext): { mix: FooterMix; repairs: FooterRepair[] } {
|
|
305
|
+
const used = new Set(taken);
|
|
306
|
+
if (!used.has(footerTokenOf(mix))) return { mix, repairs: [] };
|
|
307
|
+
const tries: FooterMix[] = [];
|
|
308
|
+
for (const k of MEND_ORDER) for (const w of footerWords(k)) tries.push({ ...mix, [k]: w });
|
|
309
|
+
for (const [i, a] of MEND_ORDER.entries()) for (const b of MEND_ORDER.slice(i + 1)) {
|
|
310
|
+
for (const wa of footerWords(a)) for (const wb of footerWords(b)) tries.push({ ...mix, [a]: wa, [b]: wb });
|
|
311
|
+
}
|
|
312
|
+
for (const t of tries) {
|
|
313
|
+
const checked = checkFooter(t, ctx);
|
|
314
|
+
if (checked.repairs.length || used.has(footerTokenOf(checked.mix))) continue;
|
|
315
|
+
return { mix: checked.mix, repairs: [{ code: FooterRepairCode.Worn, said: `another site wears ${footerTokenWords(footerTokenOf(mix))}: this one is ${footerTokenWords(footerTokenOf(checked.mix))}` }] };
|
|
316
|
+
}
|
|
317
|
+
return { mix, repairs: [] };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** A plan's footer made distinct (R-H10): `distinctFooter` over the plan's own mix, the name and the look it wears; the
|
|
321
|
+
* plan unchanged when nothing was mended, else with the new mix in `mixes.footer`. Pure. */
|
|
322
|
+
export function withDistinctFooter<P extends { readonly business: { readonly name: string }; readonly design: Readonly<Partial<DesignChoices>>; readonly globals?: Readonly<Record<string, string>>; readonly mixes?: { readonly header?: ReadonlyArray<string>; readonly footer?: ReadonlyArray<string> } }>(
|
|
323
|
+
plan: P, taken: ReadonlyArray<string>,
|
|
324
|
+
): { plan: P; repairs: FooterRepair[] } {
|
|
325
|
+
const done = distinctFooter(footerMixOfPlan(plan), taken, { name: plan.business.name, design: resolveDesignChoices(JSON.parse(JSON.stringify(plan.design))) });
|
|
326
|
+
if (!done.repairs.length) return { plan, repairs: [] };
|
|
327
|
+
return { plan: { ...plan, mixes: { ...(plan.mixes ?? {}), footer: footerMixWords(done.mix) } }, repairs: done.repairs };
|
|
328
|
+
}
|
|
@@ -2,7 +2,8 @@ import { parseCssColour, relativeLuminance } from '@vectoriox/iox-ui/design-core
|
|
|
2
2
|
|
|
3
3
|
import { layoutPresetColours, splitSide } from './check-layout';
|
|
4
4
|
import { LayoutColour, LayoutIssue, LayoutIssueCode, LayoutLayerKind, LayoutListMix, LayoutListWho, LayoutPage, LayoutRole, LayoutSection, LayoutSectionKind, LayoutSize, LayoutTrackProp } from './layout-language';
|
|
5
|
-
import {
|
|
5
|
+
import { FooterMix, footerMixOfPlan, footerTokenOf } from './footer-mix';
|
|
6
|
+
import { HeaderMix, headerMixOfPlan, headerTokenOf } from './header-mix';
|
|
6
7
|
import { PHOTO_LIGHT_LUMINANCE, PhotoTone } from './photo-inventory';
|
|
7
8
|
import { SPEC_SITE_LAYOUT } from './site-spec.generated';
|
|
8
9
|
|
|
@@ -53,6 +54,9 @@ export interface LayoutFingerprint {
|
|
|
53
54
|
* named in the brief, never a refusal until the model chooses the header (HI1) — a refusal it cannot answer by
|
|
54
55
|
* changing its page would only spend a repair. */
|
|
55
56
|
header?: string;
|
|
57
|
+
/** The site's footer (`footerTokenOf`, list ingredients LI5); absent on a fingerprint stored before it. Another site's
|
|
58
|
+
* footer is never worn again: the plan's is mended to the nearest free one (`distinctFooter`). */
|
|
59
|
+
footer?: string;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
export interface FingerprintedPage {
|
|
@@ -137,9 +141,9 @@ function openingOf(s: LayoutSection | undefined): string {
|
|
|
137
141
|
return lead.size ? `${lead.size}-${lead.kind}` : lead.kind;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
/** A page's fingerprint, worn in `preset` and `mode`, under the site's `header` when
|
|
144
|
+
/** A page's fingerprint, worn in `preset` and `mode`, under the site's `header` and `footer` when they are known. A photo ground opens on
|
|
141
145
|
* the page's own ground colour. */
|
|
142
|
-
export function fingerprintOf(page: LayoutPage, preset: string, mode: 'light' | 'dark', header?: HeaderMix): LayoutFingerprint {
|
|
146
|
+
export function fingerprintOf(page: LayoutPage, preset: string, mode: 'light' | 'dark', header?: HeaderMix, footer?: FooterMix): LayoutFingerprint {
|
|
143
147
|
const sections = page.sections ?? [];
|
|
144
148
|
const lists = listTokensOf(page);
|
|
145
149
|
const first = sections[0];
|
|
@@ -155,9 +159,15 @@ export function fingerprintOf(page: LayoutPage, preset: string, mode: 'light' |
|
|
|
155
159
|
preset,
|
|
156
160
|
...(lists.length ? { lists } : {}),
|
|
157
161
|
...(header ? { header: headerTokenOf(header) } : {}),
|
|
162
|
+
...(footer ? { footer: footerTokenOf(footer) } : {}),
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
|
|
166
|
+
/** A composed page's fingerprint under its site plan's header and footer — the ONE call every reader of a plan makes. */
|
|
167
|
+
export function fingerprintOfPlanPage(page: LayoutPage, preset: string, mode: 'light' | 'dark', plan: Parameters<typeof footerMixOfPlan>[0]): LayoutFingerprint {
|
|
168
|
+
return fingerprintOf(page, preset, mode, headerMixOfPlan(plan), footerMixOfPlan(plan));
|
|
169
|
+
}
|
|
170
|
+
|
|
161
171
|
/** The longest common subsequence of two sequences. */
|
|
162
172
|
function lcs(a: ReadonlyArray<string>, b: ReadonlyArray<string>): number {
|
|
163
173
|
const d = Array.from({ length: a.length + 1 }, () => new Array<number>(b.length + 1).fill(0));
|
|
@@ -4,6 +4,7 @@ import { planFormPresetIds } from '@vectoriox/iox-ui/forms-core';
|
|
|
4
4
|
import { describeShapeKey, jsonAnyOf, jsonBoolean, jsonInteger, jsonListOf, jsonOneOf, JsonSchema, jsonShapedObject, jsonText } from './json-schema';
|
|
5
5
|
import { patternLinkSlots, patternOptionalParts, patternSlots, PatternGlobalPosition, SITE_PATTERNS } from './patterns';
|
|
6
6
|
import { withDerivedSources } from './plan-derived';
|
|
7
|
+
import { DEFAULT_FOOTER_PATTERN, FooterIngredient, footerMeaning, footerMix, footerMixFromWords, footerMixOfPlan, footerMixWords, footerPatternIdOf, footerWireWords, footerWords } from './footer-mix';
|
|
7
8
|
import { shopCategoriesOf } from './shop-plan';
|
|
8
9
|
import { ContentFieldControl, FIELD_TYPE_OF_CONTROL,
|
|
9
10
|
ContentFieldPlan, ContentTypePlan, DataSourcePlan, FactKey, GlobalSlot, PAGE_ARCHETYPES, PagePlan, PageSectionPlan, PlanDataSourceMode, PlanDataSourceType,
|
|
@@ -97,6 +98,11 @@ const inPart = (part: PlanPart, spec: WireKey): WireKey => ({ ...spec, part });
|
|
|
97
98
|
const ROLE_KEYS: ReadonlyArray<string> = shapeKeys(PLAN_SHAPE['roles']);
|
|
98
99
|
const roleWords = ROLE_KEYS.map(role => `${role}: ${describeShapeKey(PLAN_SHAPE['roles'], role).replace(/^string — /, '')}`).join('; ');
|
|
99
100
|
|
|
101
|
+
/** The footer's words as the model reads them (LI5): each ingredient, its words and their meanings, from the contract. */
|
|
102
|
+
const FOOTER_WIRE_TEXT = 'string[] — the footer as ONE list of <ingredient>:<word> words: one word per ingredient but "holds", which lists '
|
|
103
|
+
+ `each block it holds (holds:pages, holds:contact); an ingredient left out is the default (${footerMixWords(footerMix()).join(', ')}). `
|
|
104
|
+
+ Object.values(FooterIngredient).map(k => `${k}: ${footerWords(k).map(w => `${w} (${footerMeaning(k, w)})`).join(' | ')}`).join('; ');
|
|
105
|
+
|
|
100
106
|
const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, WireKey>>>> = {
|
|
101
107
|
plan: {
|
|
102
108
|
business: inPart(PlanPart.Structure, key('plan.business')),
|
|
@@ -196,7 +202,9 @@ const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, Wir
|
|
|
196
202
|
},
|
|
197
203
|
globals: {
|
|
198
204
|
header: key('globals.header'),
|
|
199
|
-
|
|
205
|
+
// LI5: the footer travels as its MIX — ONE list of `<ingredient>:<word>` words (footer-mix.ts), every word with its
|
|
206
|
+
// meaning from the contract's footer table; the plan keeps the pattern it reads as (`globals.footer`) and the mix.
|
|
207
|
+
footer: { refs: ['globals.footer', 'plan.mixes', 'mixes.footer'], text: FOOTER_WIRE_TEXT },
|
|
200
208
|
},
|
|
201
209
|
shopProduct: {
|
|
202
210
|
name: key('shopProduct.name'),
|
|
@@ -212,6 +220,7 @@ const WIRE_KEYS: Readonly<Record<`${PlanWireEntry}`, Readonly<Record<string, Wir
|
|
|
212
220
|
|
|
213
221
|
/** The plan keys the model does not write, and where the expander takes each from. */
|
|
214
222
|
export const PLAN_WIRE_DERIVED: Readonly<Record<string, string>> = {
|
|
223
|
+
'mixes.header': 'header ingredients HI1 — until then the header is its globals pattern',
|
|
215
224
|
'field.type': 'follows from the field\'s control (FIELD_TYPE_OF_CONTROL)',
|
|
216
225
|
'plan.version': `always '${SITE_PLAN_VERSION}'`,
|
|
217
226
|
'plan.source': 'this run (the context)',
|
|
@@ -380,7 +389,7 @@ const PLAN_TOP_SCHEMAS: Readonly<Record<string, () => JsonSchema>> = {
|
|
|
380
389
|
pages: () => jsonListOf(wirePageJsonSchema()),
|
|
381
390
|
globals: () => shaped(PlanWireEntry.Globals, {
|
|
382
391
|
[GlobalSlot.Header]: jsonOneOf(globalIds(PatternGlobalPosition.Before)),
|
|
383
|
-
[GlobalSlot.Footer]: jsonOneOf(
|
|
392
|
+
[GlobalSlot.Footer]: jsonListOf(jsonOneOf(footerWireWords())),
|
|
384
393
|
}),
|
|
385
394
|
direction: () => shaped(PlanWireEntry.Direction, { idea: jsonText(), cliche: jsonText(), flip: jsonText(), rules: jsonListOf(jsonText()) }),
|
|
386
395
|
shop: () => jsonListOf(wireShopProductJsonSchema()),
|
|
@@ -545,10 +554,11 @@ export function expandPlanWire(parts: PlanWireParts, context: PlanWireContext):
|
|
|
545
554
|
const odd = written.find(value => !isPlainObject(value));
|
|
546
555
|
if (odd !== undefined) return odd;
|
|
547
556
|
const wire: PlainObject = Object.assign({}, ...(written as PlainObject[]));
|
|
548
|
-
const { business, contentTypes, dataSources, pages, direction, shop, ...rest } = wire;
|
|
557
|
+
const { business, contentTypes, dataSources, pages, direction, shop, globals, ...rest } = wire;
|
|
549
558
|
const sells = expandWireShop(shop);
|
|
550
559
|
return withDerivedSources({
|
|
551
560
|
...rest,
|
|
561
|
+
...expandWireGlobals(globals),
|
|
552
562
|
...(sells === undefined ? {} : { shop: sells }),
|
|
553
563
|
...(isPlainObject(direction) && direction['idea'] === NONE ? {} : direction === undefined ? {} : { direction }),
|
|
554
564
|
version: SITE_PLAN_VERSION,
|
|
@@ -562,6 +572,20 @@ export function expandPlanWire(parts: PlanWireParts, context: PlanWireContext):
|
|
|
562
572
|
});
|
|
563
573
|
}
|
|
564
574
|
|
|
575
|
+
/** The wire's globals → the plan's: a footer mix that is a stored footer pattern becomes that pattern; any other becomes
|
|
576
|
+
* `mixes.footer` beside the Studio footer (the mix wins). A footer that is not a word list is left for the validator. */
|
|
577
|
+
function expandWireGlobals(globals: unknown): PlainObject {
|
|
578
|
+
if (globals === undefined) return {};
|
|
579
|
+
if (!isPlainObject(globals)) return { globals };
|
|
580
|
+
const words = globals[GlobalSlot.Footer];
|
|
581
|
+
if (!Array.isArray(words)) return { globals };
|
|
582
|
+
let named: string | null = null;
|
|
583
|
+
try { named = footerPatternIdOf(footerMixFromWords(words as string[])); } catch { /* the validator names the word */ }
|
|
584
|
+
// A mix that IS a stored footer is kept as that pattern alone (the plan stays as a template would write it).
|
|
585
|
+
if (named) return { globals: { ...globals, [GlobalSlot.Footer]: named } };
|
|
586
|
+
return { globals: { ...globals, [GlobalSlot.Footer]: DEFAULT_FOOTER_PATTERN }, mixes: { footer: [...words] } };
|
|
587
|
+
}
|
|
588
|
+
|
|
565
589
|
// ── The plan → the wire ────────────────────────────────────────────────────────────────────────────────────────────
|
|
566
590
|
|
|
567
591
|
export function fieldToWire(field: ContentFieldPlan): PlainObject {
|
|
@@ -615,7 +639,7 @@ const PLAN_TO_WIRE: Readonly<Record<string, (plan: SitePlan) => unknown>> = {
|
|
|
615
639
|
contentTypes: plan => plan.contentTypes.map(type => contentTypeToWire(type)),
|
|
616
640
|
dataSources: plan => plan.dataSources.map(dataSourceToWire),
|
|
617
641
|
pages: plan => plan.pages.map(page => pageToWire(page)),
|
|
618
|
-
globals: plan => ({ ...plan.globals }),
|
|
642
|
+
globals: plan => ({ ...plan.globals, [GlobalSlot.Footer]: footerMixWords(footerMixOfPlan(plan)) }),
|
|
619
643
|
direction: plan => ({ idea: plan.direction?.idea ?? NONE, cliche: plan.direction?.cliche ?? NONE, flip: plan.direction?.flip ?? NONE, rules: [...(plan.direction?.rules ?? [])] }),
|
|
620
644
|
shop: plan => (plan.shop?.products ?? []).map(p => ({ name: p.name, category: p.category, description: p.description, options: p.options.map(o => ({ name: o.name, values: [...o.values] })) })),
|
|
621
645
|
};
|
|
@@ -319,6 +319,15 @@ export interface SitePlan {
|
|
|
319
319
|
readonly artDirection?: ArtDirection;
|
|
320
320
|
/** M8 gate 2: what the site is built around, written with the pages and shown on the Plan step. */
|
|
321
321
|
readonly direction?: PlanDirection;
|
|
322
|
+
/** The header and footer as mixes of ingredients (ingredients.md): a mix wins over its `globals` pattern. */
|
|
323
|
+
readonly mixes?: PlanMixes;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A part's mix as `<ingredient>:<word>` words (the contract's `site.layout.<part>`): the footer since list ingredients
|
|
327
|
+
* LI5 (generation-core footer-mix.ts); the header joins at header ingredients HI1. */
|
|
328
|
+
export interface PlanMixes {
|
|
329
|
+
readonly header?: ReadonlyArray<string>;
|
|
330
|
+
readonly footer?: ReadonlyArray<string>;
|
|
322
331
|
}
|
|
323
332
|
|
|
324
333
|
/** M8 gate 2: the idea a site's composed pages serve — the usual site for the business, and what this one does instead. */
|