@vectoriox/iox-ui 5.199.0 → 5.201.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/design-core/index.d.ts +454 -52
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +640 -55
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-forms-core.mjs +5 -2
- package/fesm2022/vectoriox-iox-ui-forms-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1062 -177
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs +441 -63
- package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +5 -2
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +473 -124
- package/harness-core/index.d.ts +282 -6
- package/package.json +1 -1
- package/src/design-core/brand-neutrals.ts +125 -3
- package/src/design-core/colour-words.ts +48 -0
- package/src/design-core/design-settings.ts +24 -5
- package/src/design-core/design-token.model.ts +8 -0
- package/src/design-core/flavor-fixtures.generated.ts +272 -2
- package/src/design-core/flavor-spec.generated.ts +310 -40
- package/src/design-core/flavor-tokens.ts +5 -1
- package/src/design-core/public-api.ts +2 -0
- package/src/design-core/signature-move.ts +107 -0
- package/src/design-core/style-presets.ts +9 -3
- package/src/design-core/token-css.ts +59 -1
- package/src/forms-core/form-presets.ts +5 -2
- package/src/generation-core/body-mix.ts +41 -0
- package/src/generation-core/check-layout.ts +17 -7
- package/src/generation-core/colour-mix.ts +53 -3
- package/src/generation-core/compose-site.ts +136 -32
- package/src/generation-core/composition.ts +320 -0
- package/src/generation-core/footer-mix.ts +43 -3
- package/src/generation-core/footer-sign-up.ts +51 -0
- package/src/generation-core/header-edit.ts +15 -0
- package/src/generation-core/header-mix.ts +128 -19
- package/src/generation-core/opening-edit.ts +17 -3
- package/src/generation-core/opening-mix.ts +69 -5
- package/src/generation-core/plan-wire.ts +22 -5
- package/src/generation-core/public-api.ts +2 -0
- package/src/generation-core/site-build-run.ts +3 -0
- package/src/generation-core/site-plan.model.ts +3 -0
- package/src/generation-core/site-spec.generated.ts +250 -104
- package/src/generation-core/type-led.ts +4 -2
- package/src/generation-core/validate-site-plan.ts +2 -1
- package/src/harness-core/business-types.ts +27 -0
- package/src/harness-core/harness-spec.generated.ts +405 -56
- package/src/harness-core/motion.ts +19 -2
- package/src/harness-core/run-compose-context.ts +9 -3
- package/src/harness-core/starting-design.ts +15 -7
- package/styles/iox-design.css +10 -0
- package/styles/iox-forms.css +53 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { patternById, patternNeedsBinding } from './patterns';
|
|
2
|
+
import { SPEC_SITE_LAYOUT } from './site-spec.generated';
|
|
3
|
+
import {
|
|
4
|
+
DataSourcePlan, DEFAULT_SITE_LOCALE, PAGE_ARCHETYPES, PagePlan, PageSectionPlan, PlanDataSourceMode, PlanDataSourceType, SitePlan,
|
|
5
|
+
} from './site-plan.model';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* COMPOSITION (iox-ai-guidance architecture/ai/composition-plan.md, contract `site.layout.composition`): how a page built
|
|
9
|
+
* from PATTERNS is put together. The J10 baseline read Composition 4.2 — Homes of three or four sections (a split hero,
|
|
10
|
+
* three services, a band), two three-across sections side by side, inner pages of a header and one list — where the
|
|
11
|
+
* references hold 5–11 distinct skeletons on a Home and "no two neighbouring sections share a skeleton".
|
|
12
|
+
*
|
|
13
|
+
* Two pure decisions, both read by `composeSite` for a pattern page (never a model-laid or a free one — checkLayout
|
|
14
|
+
* judges those):
|
|
15
|
+
* - `compositionBorrows` — what a page below its kind's `distinct` skeletons may BORROW from what the plan already wrote
|
|
16
|
+
* on its other pages (a list page's items as a preview, a statement, the questions, the Home's Ask). Never a word the
|
|
17
|
+
* plan does not hold but the preview's "See all" (`words.more`); the caller refuses a borrow that would leave a
|
|
18
|
+
* placeholder (`fits`).
|
|
19
|
+
* - `orderPlaces` — the order of a page's sections nearest the archetype's in which no two neighbours share a skeleton
|
|
20
|
+
* (the first place stays first, a closing Ask stays last).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The contract's composition table (layout.mjs COMPOSITION). */
|
|
24
|
+
export interface CompositionBorrow {
|
|
25
|
+
readonly kind: `${BorrowKind}`;
|
|
26
|
+
readonly families?: ReadonlyArray<string>;
|
|
27
|
+
readonly pattern?: string;
|
|
28
|
+
readonly limit?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CompositionTable {
|
|
31
|
+
readonly skeletons: Readonly<Record<string, string>>;
|
|
32
|
+
readonly neighbours: 'differ';
|
|
33
|
+
readonly distinct: Readonly<Record<string, number>>;
|
|
34
|
+
readonly maxSections: Readonly<Record<string, number>>;
|
|
35
|
+
readonly borrows: Readonly<Record<string, ReadonlyArray<CompositionBorrow>>>;
|
|
36
|
+
readonly words: { readonly more: Readonly<Record<string, string>> };
|
|
37
|
+
readonly swaps: Readonly<Record<string, CompositionSwap>>;
|
|
38
|
+
}
|
|
39
|
+
/** A sibling a section may wear when no order clears its neighbour: every slot carried (`slots`: source → target). */
|
|
40
|
+
export interface CompositionSwap {
|
|
41
|
+
readonly pattern: string;
|
|
42
|
+
readonly slots: Readonly<Record<string, string>>;
|
|
43
|
+
readonly without?: ReadonlyArray<string>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const COMPOSITION = (SPEC_SITE_LAYOUT as unknown as { composition: CompositionTable }).composition;
|
|
47
|
+
|
|
48
|
+
export enum BorrowKind {
|
|
49
|
+
List = 'list',
|
|
50
|
+
Section = 'section',
|
|
51
|
+
Ask = 'ask',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const HOME_KIND = 'home';
|
|
55
|
+
const ASK_FAMILY = 'cta';
|
|
56
|
+
const FREE_SKELETON = 'free';
|
|
57
|
+
/** The middle a page reorders whole (8! orders); a longer page keeps the archetype's order. */
|
|
58
|
+
const MAX_REORDERED = 8;
|
|
59
|
+
const FAULT_COST = 1000;
|
|
60
|
+
|
|
61
|
+
/** A pattern's skeleton (`skeletons`); a pattern the table does not know reads as its own. */
|
|
62
|
+
export function skeletonOf(pattern: string): string {
|
|
63
|
+
return COMPOSITION.skeletons[pattern] ?? pattern;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The skeleton a plan section reads as: a free signature section is its own (never the same as a neighbour). */
|
|
67
|
+
export function sectionSkeleton(section: PageSectionPlan, at: number): string {
|
|
68
|
+
return section.free ? `${FREE_SKELETON}:${at}` : skeletonOf(section.pattern);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The page kind the composition table is keyed by: the Home, else the page's archetype. */
|
|
72
|
+
export function pageKindOf(page: Pick<PagePlan, 'isHome' | 'archetype'>): string | null {
|
|
73
|
+
return page.isHome ? HOME_KIND : page.archetype ?? null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A page the composition table arranges: a pattern page (never model-laid, free, or a template's item page) of a kind
|
|
77
|
+
* the table names a minimum for. */
|
|
78
|
+
export function composesPage(page: Pick<PagePlan, 'isHome' | 'archetype' | 'layout' | 'free' | 'routeSource' | 'template'>): boolean {
|
|
79
|
+
const kind = pageKindOf(page);
|
|
80
|
+
return !!kind && kind in COMPOSITION.distinct && !page.layout && !page.free && !page.routeSource && !page.template;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Two neighbours on one skeleton, counted along a page. */
|
|
84
|
+
export function neighbourFaults(skeletons: ReadonlyArray<string>): number {
|
|
85
|
+
let n = 0;
|
|
86
|
+
for (let i = 1; i < skeletons.length; i++) if (skeletons[i] === skeletons[i - 1]) n++;
|
|
87
|
+
return n;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A section a page borrows: the plan section to stamp, the list's cut, the page it was read from, said in plain words. */
|
|
91
|
+
export interface BorrowedSection {
|
|
92
|
+
readonly kind: BorrowKind;
|
|
93
|
+
readonly section: PageSectionPlan;
|
|
94
|
+
/** The borrowed list shows its first `limit` items (a Repeater's / accordion's `limit`). */
|
|
95
|
+
readonly limit?: number;
|
|
96
|
+
/** The page key the words were read from. */
|
|
97
|
+
readonly from: string;
|
|
98
|
+
readonly skeleton: string;
|
|
99
|
+
readonly said: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type TypeKey = string;
|
|
103
|
+
function typeKeyOf(ds: DataSourcePlan | undefined): TypeKey | null {
|
|
104
|
+
if (!ds || ds.type === PlanDataSourceType.Relative || ds.mode !== PlanDataSourceMode.Query) return null;
|
|
105
|
+
return ds.type === PlanDataSourceType.Cms ? `cms:${ds.contentType}` : `shop:${ds.resource}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const familyOf = (pattern: string): string | null => patternById(pattern)?.family ?? null;
|
|
109
|
+
|
|
110
|
+
/** The words a list page is titled by: its page header's title, else its name. */
|
|
111
|
+
function listTitleOf(page: PagePlan): string {
|
|
112
|
+
const header = page.sections.find(s => familyOf(s.pattern) === 'header' && s.slots?.['title']?.trim());
|
|
113
|
+
return header?.slots?.['title']?.trim() || page.name;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Every candidate a page may borrow, in the table's order (the caller takes what fits). Pure. */
|
|
117
|
+
function candidatesFor(page: PagePlan, plan: SitePlan, borrow: CompositionBorrow): BorrowedSection[] {
|
|
118
|
+
const others = plan.pages.filter(p => p.key !== page.key && !p.free);
|
|
119
|
+
const own = new Set(page.sections.map(s => s.pattern));
|
|
120
|
+
if (borrow.kind === BorrowKind.List) {
|
|
121
|
+
const aliasOf = new Map(plan.dataSources.map(d => [d.alias, d]));
|
|
122
|
+
const shown = new Set(page.sections.map(s => typeKeyOf(s.binding ? aliasOf.get(s.binding) : undefined)).filter(Boolean));
|
|
123
|
+
const out: BorrowedSection[] = [];
|
|
124
|
+
for (const list of others) {
|
|
125
|
+
// A list page: one that lists a type (never a template page showing one item).
|
|
126
|
+
if (list.routeSource || list.template || list.isHome) continue;
|
|
127
|
+
for (const s of list.sections) {
|
|
128
|
+
const pattern = patternById(s.pattern);
|
|
129
|
+
if (s.free || !s.binding || !pattern || !(borrow.families ?? []).includes(pattern.family) || !patternNeedsBinding(pattern)) continue;
|
|
130
|
+
const type = typeKeyOf(aliasOf.get(s.binding));
|
|
131
|
+
if (!type || shown.has(type)) continue;
|
|
132
|
+
// The plan's own short source of that type (a "latest three") is the preview the model meant.
|
|
133
|
+
const short = plan.dataSources.find(d => typeKeyOf(d) === type && 'limit' in d && d.limit !== undefined && d.limit <= 6);
|
|
134
|
+
const title = listTitleOf(list);
|
|
135
|
+
const more = COMPOSITION.words.more[plan.locale ?? DEFAULT_SITE_LOCALE] ?? COMPOSITION.words.more[DEFAULT_SITE_LOCALE];
|
|
136
|
+
out.push({
|
|
137
|
+
kind: BorrowKind.List,
|
|
138
|
+
section: { pattern: s.pattern, slots: { title, more }, links: { more: list.route }, binding: short?.alias ?? s.binding },
|
|
139
|
+
...(short ? {} : borrow.limit ? { limit: borrow.limit } : {}),
|
|
140
|
+
from: list.key,
|
|
141
|
+
skeleton: skeletonOf(s.pattern),
|
|
142
|
+
said: `${page.name} shows the first of ${list.name} ("${title}"), linked to ${list.route}`,
|
|
143
|
+
});
|
|
144
|
+
shown.add(type);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
if (borrow.kind === BorrowKind.Section) {
|
|
150
|
+
if (!borrow.pattern || own.has(borrow.pattern)) return [];
|
|
151
|
+
for (const other of others) {
|
|
152
|
+
const s = other.sections.find(x => x.pattern === borrow.pattern && !x.free);
|
|
153
|
+
if (!s) continue;
|
|
154
|
+
const { free: _free, ...section } = s;
|
|
155
|
+
return [{
|
|
156
|
+
kind: BorrowKind.Section, section, ...(borrow.limit ? { limit: borrow.limit } : {}), from: other.key,
|
|
157
|
+
skeleton: skeletonOf(s.pattern), said: `${page.name} shows ${other.name}'s ${patternById(s.pattern)?.label ?? s.pattern}`,
|
|
158
|
+
}];
|
|
159
|
+
}
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
// The Ask: the Home's closing band, unless the page already asks or the band asks for this very page.
|
|
163
|
+
const home = plan.pages.find(p => p.isHome);
|
|
164
|
+
if (!borrow.pattern || !home || home.key === page.key || page.sections.some(s => familyOf(s.pattern) === ASK_FAMILY)) return [];
|
|
165
|
+
const last = home.sections[home.sections.length - 1];
|
|
166
|
+
if (!last || last.pattern !== borrow.pattern || last.free) return [];
|
|
167
|
+
if (Object.values(last.links ?? {}).includes(page.route)) return [];
|
|
168
|
+
const { free: _free, ...section } = last;
|
|
169
|
+
return [{ kind: BorrowKind.Ask, section, from: home.key, skeleton: skeletonOf(last.pattern), said: `${page.name} closes on the Home's Ask` }];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* What a pattern page borrows: candidates in the table's order, each taken only while the page is below its kind's
|
|
174
|
+
* `distinct` skeletons and `maxSections`, only when its skeleton is not on the page yet, and only when `fits` (the
|
|
175
|
+
* caller: it stamps without a placeholder). A model-laid page, a free page or a kind the table names no borrows for
|
|
176
|
+
* borrows nothing. Pure.
|
|
177
|
+
*/
|
|
178
|
+
export function compositionBorrows(page: PagePlan, plan: SitePlan, fits: (b: BorrowedSection) => boolean = () => true): BorrowedSection[] {
|
|
179
|
+
const kind = pageKindOf(page);
|
|
180
|
+
if (!kind || !composesPage(page)) return [];
|
|
181
|
+
const borrows = COMPOSITION.borrows[kind] ?? [];
|
|
182
|
+
const target = COMPOSITION.distinct[kind] ?? 0;
|
|
183
|
+
const max = COMPOSITION.maxSections[kind] ?? 0;
|
|
184
|
+
const skeletons = new Set(page.sections.map(sectionSkeleton));
|
|
185
|
+
let count = page.sections.length;
|
|
186
|
+
const taken: BorrowedSection[] = [];
|
|
187
|
+
for (const borrow of borrows) {
|
|
188
|
+
for (const found of candidatesFor(page, plan, borrow)) {
|
|
189
|
+
if (skeletons.size >= target || count >= max) return taken;
|
|
190
|
+
// CO4b: a borrow on a skeleton the page already shows may wear its swap (every slot carried).
|
|
191
|
+
const swapped = skeletons.has(found.skeleton) ? swapOf(found.section) : null;
|
|
192
|
+
const c = swapped ? { ...found, section: swapped, skeleton: skeletonOf(swapped.pattern), said: `${found.said}, worn as ${patternById(swapped.pattern)?.label ?? swapped.pattern}` } : found;
|
|
193
|
+
if (skeletons.has(c.skeleton) || !fits(c)) continue;
|
|
194
|
+
taken.push(c);
|
|
195
|
+
skeletons.add(c.skeleton);
|
|
196
|
+
count++;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return taken;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** One place on a page: its skeleton, its archetype rank (the slot its family fills) and whether it is held in place. */
|
|
203
|
+
export interface Place {
|
|
204
|
+
readonly skeleton: string;
|
|
205
|
+
readonly rank: number;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** A family's rank on a page kind: the first archetype slot that allows it (absent: the middle). */
|
|
209
|
+
export function archetypeRank(kind: string | null, pattern: string): number {
|
|
210
|
+
const slots = kind ? PAGE_ARCHETYPES[kind]?.slots ?? [] : [];
|
|
211
|
+
const family = familyOf(pattern);
|
|
212
|
+
const at = slots.findIndex(s => family !== null && s.families.includes(family));
|
|
213
|
+
return at >= 0 ? at : slots.length / 2;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Where borrowed places stand among a page's own: each after the last own place of a rank at most its own (never after
|
|
217
|
+
* a closing Ask; an Ask itself goes last). Returns the base order as indices into `[...own, ...borrowed]`. Pure. */
|
|
218
|
+
export function baseOrder(own: ReadonlyArray<Place & { ask?: boolean }>, borrowed: ReadonlyArray<Place & { ask?: boolean }>): number[] {
|
|
219
|
+
const order = own.map((_, i) => i);
|
|
220
|
+
const closing = own.length > 1 && own[own.length - 1].ask;
|
|
221
|
+
borrowed.forEach((b, j) => {
|
|
222
|
+
const index = own.length + j;
|
|
223
|
+
if (b.ask) { order.push(index); return; }
|
|
224
|
+
const end = closing ? order.length - 1 : order.length;
|
|
225
|
+
let at = 1;
|
|
226
|
+
for (let k = 1; k < end; k++) {
|
|
227
|
+
const place = order[k] < own.length ? own[order[k]] : borrowed[order[k] - own.length];
|
|
228
|
+
if (place.rank <= b.rank) at = k + 1;
|
|
229
|
+
}
|
|
230
|
+
order.splice(Math.min(Math.max(at, 1), end), 0, index);
|
|
231
|
+
});
|
|
232
|
+
return order;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The order of a page's places nearest `base` in which no two neighbours share a skeleton: the first place stays first,
|
|
237
|
+
* a held last place (a closing Ask) stays last, and among the orders with the fewest such pairs the one with the fewest
|
|
238
|
+
* swapped pairs against `base` wins (ties: the earliest found, so `base` itself when it has no fault). A middle longer
|
|
239
|
+
* than eight keeps `base`. Pure.
|
|
240
|
+
*/
|
|
241
|
+
export function orderPlaces(places: ReadonlyArray<Place>, base: ReadonlyArray<number>, holdLast: boolean): number[] {
|
|
242
|
+
const sk = (i: number) => places[i].skeleton;
|
|
243
|
+
const faultsOf = (order: ReadonlyArray<number>) => neighbourFaults(order.map(sk));
|
|
244
|
+
if (faultsOf(base) === 0 || base.length < 3) return [...base];
|
|
245
|
+
const head = base[0];
|
|
246
|
+
const tail = holdLast ? base[base.length - 1] : null;
|
|
247
|
+
const middle = base.slice(1, holdLast ? -1 : undefined);
|
|
248
|
+
if (middle.length > MAX_REORDERED) return [...base];
|
|
249
|
+
const pos = new Map(base.map((v, i) => [v, i]));
|
|
250
|
+
const inversions = (order: ReadonlyArray<number>) => {
|
|
251
|
+
let n = 0;
|
|
252
|
+
for (let i = 0; i < order.length; i++) for (let j = i + 1; j < order.length; j++) if (pos.get(order[i])! > pos.get(order[j])!) n++;
|
|
253
|
+
return n;
|
|
254
|
+
};
|
|
255
|
+
let best: number[] = [...base];
|
|
256
|
+
let bestCost = faultsOf(base) * FAULT_COST;
|
|
257
|
+
const used = new Array(middle.length).fill(false);
|
|
258
|
+
const current: number[] = [head];
|
|
259
|
+
const walk = (): void => {
|
|
260
|
+
if (current.length === middle.length + 1) {
|
|
261
|
+
const order = tail === null ? [...current] : [...current, tail];
|
|
262
|
+
const cost = faultsOf(order) * FAULT_COST + inversions(order);
|
|
263
|
+
if (cost < bestCost) { best = order; bestCost = cost; }
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
for (let i = 0; i < middle.length; i++) {
|
|
267
|
+
if (used[i]) continue;
|
|
268
|
+
// Prune: a neighbour pair already laid costs a fault the best may not afford.
|
|
269
|
+
const prev = current[current.length - 1];
|
|
270
|
+
const added = sk(prev) === sk(middle[i]) ? 1 : 0;
|
|
271
|
+
const partial = neighbourFaults(current.map(sk)) + added;
|
|
272
|
+
if (partial * FAULT_COST >= bestCost) continue;
|
|
273
|
+
used[i] = true;
|
|
274
|
+
current.push(middle[i]);
|
|
275
|
+
walk();
|
|
276
|
+
current.pop();
|
|
277
|
+
used[i] = false;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
walk();
|
|
281
|
+
return best;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** A section worn as its `swaps` sibling — every slot and link carried to the sibling's slot, the sibling's `without`
|
|
285
|
+
* left out — or null when the table names none. Pure. */
|
|
286
|
+
export function swapOf(section: PageSectionPlan): PageSectionPlan | null {
|
|
287
|
+
const swap = section.free ? undefined : COMPOSITION.swaps[section.pattern];
|
|
288
|
+
if (!swap) return null;
|
|
289
|
+
const carry = (from: Readonly<Record<string, string>> | undefined) => Object.fromEntries(Object.entries(from ?? {}).filter(([k]) => swap.slots[k]).map(([k, v]) => [swap.slots[k], v]));
|
|
290
|
+
const links = carry(section.links);
|
|
291
|
+
return {
|
|
292
|
+
pattern: swap.pattern, slots: carry(section.slots), ...(Object.keys(links).length ? { links } : {}),
|
|
293
|
+
...(swap.without?.length ? { without: [...swap.without] } : {}), ...(section.enter ? { enter: section.enter } : {}),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The last mend: for each pair of neighbours still on one skeleton, a movable place of the pair (never the first, never a
|
|
299
|
+
* held last) whose plan section has a `swaps` row, worn as that sibling when its skeleton differs from both neighbours.
|
|
300
|
+
* Returns the plan section index → the swapped section (every slot carried, the sibling's `without` left out); the
|
|
301
|
+
* caller stamps it and keeps it only when it stamps clean. Pure.
|
|
302
|
+
*/
|
|
303
|
+
export function compositionSwaps(sections: ReadonlyArray<PageSectionPlan>, order: ReadonlyArray<number>, skeletons: ReadonlyArray<string>, holdLast: boolean): Map<number, PageSectionPlan> {
|
|
304
|
+
const out = new Map<number, PageSectionPlan>();
|
|
305
|
+
const sk = order.map(i => skeletons[i]);
|
|
306
|
+
for (let k = 1; k < order.length; k++) {
|
|
307
|
+
if (sk[k] !== sk[k - 1]) continue;
|
|
308
|
+
for (const at of [k, k - 1]) {
|
|
309
|
+
const index = order[at];
|
|
310
|
+
if (at === 0 || (holdLast && at === order.length - 1) || index >= sections.length || out.has(index)) continue;
|
|
311
|
+
const swapped = swapOf(sections[index]);
|
|
312
|
+
const next = swapped ? skeletonOf(swapped.pattern) : null;
|
|
313
|
+
if (!swapped || !next || next === sk[at - 1] || next === sk[at + 1]) continue;
|
|
314
|
+
out.set(index, swapped);
|
|
315
|
+
sk[at] = next;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
@@ -111,7 +111,7 @@ export enum FooterBefore {
|
|
|
111
111
|
None = 'none',
|
|
112
112
|
/** A contact-form area (FV-D11, mdscollective · mooov). */
|
|
113
113
|
ContactForm = 'contact-form',
|
|
114
|
-
/** A sign-up band (cancan;
|
|
114
|
+
/** A sign-up band (cancan; AW12 newsletter). */
|
|
115
115
|
NewsletterBand = 'newsletter-band',
|
|
116
116
|
/** Where and when to visit, as a band. */
|
|
117
117
|
Visit = 'visit',
|
|
@@ -122,7 +122,7 @@ export enum FooterPhone {
|
|
|
122
122
|
Stack = 'stack',
|
|
123
123
|
/** The link columns fold into accordions (stroms, schlosshotel; waits — a fold only a phone wears). */
|
|
124
124
|
Accordion = 'accordion',
|
|
125
|
-
/** The sign-up comes first (8pm;
|
|
125
|
+
/** The sign-up comes first on a phone (8pm; AW12 newsletter). */
|
|
126
126
|
First = 'first',
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -157,6 +157,8 @@ export enum FooterRole {
|
|
|
157
157
|
Top = 'footer.top',
|
|
158
158
|
/** FV1b `before`: the block that opens the footer (the contact-form area, the visit band). */
|
|
159
159
|
Before = 'footer.before',
|
|
160
|
+
/** AW12 newsletter: the sign-up block, the band and the closing — the forms-core `newsletter` preset beside its words. */
|
|
161
|
+
Newsletter = 'footer.newsletter',
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
|
|
@@ -400,6 +402,13 @@ export enum FooterRepairCode {
|
|
|
400
402
|
SocialLeftOut = 'social-left-out',
|
|
401
403
|
/** FV1b: a visit band before the footer says where and when — the visit block is not said twice. */
|
|
402
404
|
VisitBeforeTwice = 'visit-before-twice',
|
|
405
|
+
/** AW12-D6 (H1): a sign-up only where the site has a reason to write (a journal, events, a shop, a kind of business
|
|
406
|
+
* whose references close with one, the owner's newsletter tick) — none: the sign-up is left out, said. */
|
|
407
|
+
NoReasonToWrite = 'no-reason-to-write',
|
|
408
|
+
/** AW12 newsletter: one sign-up per footer — the band before it, else the closing, else the block it holds. */
|
|
409
|
+
SignUpTwice = 'sign-up-twice',
|
|
410
|
+
/** AW12 newsletter: the sign-up first on a phone needs a sign-up block — none held: the blocks stack. */
|
|
411
|
+
FirstWithoutSignUp = 'first-without-sign-up',
|
|
403
412
|
}
|
|
404
413
|
|
|
405
414
|
export interface FooterRepair {
|
|
@@ -441,6 +450,9 @@ export interface FooterContext {
|
|
|
441
450
|
/** The tier the site is built at. Since AW-D42 it mends no word (every tier wears every drawn word); kept so its
|
|
442
451
|
* callers still read. */
|
|
443
452
|
tier?: `${GenerationTier}`;
|
|
453
|
+
/** AW12-D6: whether the site has a reason to write (`planWrites`, footer-sign-up.ts) — false: no sign-up, said
|
|
454
|
+
* (`no-reason-to-write`). Absent = not judged (a stored footer, the builder's own). */
|
|
455
|
+
writes?: boolean;
|
|
444
456
|
}
|
|
445
457
|
|
|
446
458
|
/** The phone the closing name must fit (the render check's). */
|
|
@@ -654,6 +666,27 @@ export function checkFooter(given: FooterMix, ctx: FooterContext): { mix: Footer
|
|
|
654
666
|
say(FooterRepairCode.VisitBeforeTwice, 'the band before the footer says where and when: the visit block is not said twice');
|
|
655
667
|
holds = holds.filter(h => h !== FooterHold.Visit);
|
|
656
668
|
}
|
|
669
|
+
// AW12 newsletter: a sign-up only with a reason to write (AW12-D6), and one per footer — the band before it first.
|
|
670
|
+
let before = beforeOf(mix);
|
|
671
|
+
let phone = phoneOf(mix);
|
|
672
|
+
const signsUp = (): boolean => before === FooterBefore.NewsletterBand || closing === FooterClosing.Newsletter || holds.includes(FooterHold.Newsletter);
|
|
673
|
+
if (ctx.writes === false && signsUp()) {
|
|
674
|
+
say(FooterRepairCode.NoReasonToWrite, 'a sign-up asks people to hear from the business, and this site has nothing to write about yet (no journal, events or shop): left out');
|
|
675
|
+
if (before === FooterBefore.NewsletterBand) before = FooterBefore.None;
|
|
676
|
+
if (closing === FooterClosing.Newsletter) closing = FooterClosing.Call;
|
|
677
|
+
holds = holds.filter(h => h !== FooterHold.Newsletter);
|
|
678
|
+
}
|
|
679
|
+
const twice = [before === FooterBefore.NewsletterBand, closing === FooterClosing.Newsletter, holds.includes(FooterHold.Newsletter)].filter(Boolean).length > 1;
|
|
680
|
+
if (twice) {
|
|
681
|
+
say(FooterRepairCode.SignUpTwice, `a footer asks people to sign up once: the sign-up ${before === FooterBefore.NewsletterBand ? 'band before it' : 'it opens on'} stays`);
|
|
682
|
+
if (before === FooterBefore.NewsletterBand && closing === FooterClosing.Newsletter) closing = FooterClosing.Call;
|
|
683
|
+
holds = holds.filter(h => h !== FooterHold.Newsletter);
|
|
684
|
+
}
|
|
685
|
+
if (phone === FooterPhone.First && !holds.includes(FooterHold.Newsletter)) {
|
|
686
|
+
// The band and the closing already come first; only a held block is moved, so without one the blocks stack.
|
|
687
|
+
if (!signsUp()) say(FooterRepairCode.FirstWithoutSignUp, 'the sign-up first on a phone needs a sign-up, and this footer holds none: the blocks stack');
|
|
688
|
+
phone = FooterPhone.Stack;
|
|
689
|
+
}
|
|
657
690
|
if (arrange === FooterArrange.Halves && !partHolds(holds).length) {
|
|
658
691
|
say(FooterRepairCode.HalvesEmpty, 'halves need a block beside the name and the footer holds none: drawn as columns');
|
|
659
692
|
arrange = FooterArrange.Columns;
|
|
@@ -662,7 +695,7 @@ export function checkFooter(given: FooterMix, ctx: FooterContext): { mix: Footer
|
|
|
662
695
|
say(FooterRepairCode.Empty, 'a footer that holds nothing holds the pages');
|
|
663
696
|
holds = inOrder(FooterIngredient.Holds, [FooterHold.Pages, ...holds]);
|
|
664
697
|
}
|
|
665
|
-
return { mix: { ...mix, holds, closing, arrange, nameStyle, ground }, repairs };
|
|
698
|
+
return { mix: { ...mix, holds, closing, arrange, nameStyle, ground, before, phone }, repairs };
|
|
666
699
|
}
|
|
667
700
|
|
|
668
701
|
// ── The recipe: the mix arranged from the contract's parts ─────────────────────────────────────────────────────────
|
|
@@ -752,6 +785,8 @@ function socialPart(ctx: FooterContext): PatternNode {
|
|
|
752
785
|
function holdPart(hold: string, mix: FooterMix, ctx: FooterContext): PatternNode {
|
|
753
786
|
if (hold === FooterHold.Social) return socialPart(ctx);
|
|
754
787
|
const node = part(hold);
|
|
788
|
+
// AW12 `phone.first` (8pm): on a phone the sign-up stands before the footer's other blocks — an order, never a copy.
|
|
789
|
+
if (hold === FooterHold.Newsletter) return phoneOf(mix) === FooterPhone.First ? { ...node, resp: { ...(node.resp ?? {}), mobile: { ...(node.resp?.['mobile'] ?? {}), order: '-1' } } } : node;
|
|
755
790
|
if (hold !== FooterHold.Contact || !mix.holds.includes(FooterHold.Visit)) return node;
|
|
756
791
|
return { ...node, c: (node.c ?? []).filter(n => n.ph !== 'city') };
|
|
757
792
|
}
|
|
@@ -787,6 +822,9 @@ function beforeBlock(mix: FooterMix, ctx: FooterContext): PatternNode[] {
|
|
|
787
822
|
const c = (node.c ?? []).map(n => (n.slot === 'beforeTitle' && line ? { ...n, text: line, ...(lineHe ? { textHe: lineHe } : {}) } : n));
|
|
788
823
|
return [{ ...node, c }, part('rule')];
|
|
789
824
|
}
|
|
825
|
+
case FooterBefore.NewsletterBand:
|
|
826
|
+
// AW12 newsletter (cancan): the sign-up as a band that opens the footer, a rule under it.
|
|
827
|
+
return [part('newsletter-band'), part('rule')];
|
|
790
828
|
case FooterBefore.Visit:
|
|
791
829
|
return [{ t: 'Container', es: 'box', role: FooterRole.Before, lay: { display: 'flex', flexWrap: 'wrap', alignItems: 'baseline', justifyContent: 'space-between', gap: GAP },
|
|
792
830
|
c: part(FooterHold.Visit).c ?? [] }, part('rule')];
|
|
@@ -874,6 +912,8 @@ export function footerPattern(given: FooterMix, ctx: FooterContext): SitePattern
|
|
|
874
912
|
[FooterClosing.Statement]: () => [part('statement')],
|
|
875
913
|
[FooterClosing.Word]: () => [callWord(ctx)],
|
|
876
914
|
[FooterClosing.Email]: () => (ctx.email?.trim() ? [emailLine(ctx.email.trim(), ctx)] : []),
|
|
915
|
+
// AW12 `closing.newsletter` (enigma): the footer opens on the sign-up, in the call's place.
|
|
916
|
+
[FooterClosing.Newsletter]: () => [mix.arrange === FooterArrange.Centred ? centred(part('newsletter-band')) : part('newsletter-band')],
|
|
877
917
|
} as Readonly<Record<string, () => PatternNode[]>>;
|
|
878
918
|
const before = opens[mix.closing]?.() ?? [];
|
|
879
919
|
const body = mix.closing === FooterClosing.NameAndAction ? endOf(mix, ctx) : bodyOf(mix, ctx);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { beforeOf, FooterArrange, FooterBefore, FooterClosing, FooterHold, FooterMix, footerTableWords, FooterIngredient } from './footer-mix';
|
|
2
|
+
import { planSells } from './shop-plan';
|
|
3
|
+
import { SPEC_SITE_LAYOUT } from './site-spec.generated';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AW12 newsletter (award-ingredients-plan §7.1g, AW12-D6): a footer asks people to sign up only where the site has a reason
|
|
7
|
+
* to write, and a kind of business whose references close with a sign-up gets one when its plan's footer has none — the
|
|
8
|
+
* same plan composes the same footer, so a rebuild from a kept plan picks the sign-up up with no model call. The sign-up is
|
|
9
|
+
* the forms-core `newsletter` preset: stored, sent nowhere (no third-party list, AW12-D6). Pure.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const WRITES_WORDS = (SPEC_SITE_LAYOUT.footer.rules as unknown as { writesWords: ReadonlyArray<string> }).writesWords;
|
|
13
|
+
/** A Hebrew word may carry one prefix letter before its stem (ו ה ב ל מ ש כ). */
|
|
14
|
+
const HE_PREFIX = '[והבלמשכ]?';
|
|
15
|
+
const escape = (w: string): string => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
16
|
+
const WRITES_RE = new RegExp(`(?:^|[^\\p{L}])${HE_PREFIX}(?:${WRITES_WORDS.map(escape).join('|')})`, 'iu');
|
|
17
|
+
|
|
18
|
+
/** What `planWrites` reads of a plan: its content types, its shop and the owner's popup ticks. */
|
|
19
|
+
export interface WritingPlan {
|
|
20
|
+
readonly contentTypes?: ReadonlyArray<{ readonly name: string; readonly label?: string }>;
|
|
21
|
+
readonly shop?: unknown;
|
|
22
|
+
readonly popup?: { readonly newsletter?: boolean } | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* AW12-D6: whether the site has a reason to write — it sells (a shop's new pieces), its kind of business closes with a
|
|
27
|
+
* sign-up (`typeSignUp`, harness FOOTER_SIGNUP: a hotel's seasons, a salon's offers), the owner ticked the newsletter popup,
|
|
28
|
+
* or one of its content types is a journal, events or news (the contract's `FOOTER.rules.writesWords`, at a word's start).
|
|
29
|
+
*/
|
|
30
|
+
export function planWrites(plan: WritingPlan, typeSignUp?: boolean): boolean {
|
|
31
|
+
if (typeSignUp || plan.popup?.newsletter === true || planSells(plan)) return true;
|
|
32
|
+
return (plan.contentTypes ?? []).some(t => WRITES_RE.test(t.name) || WRITES_RE.test(t.label ?? ''));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** True when a mix asks people to sign up anywhere — the band before it, the closing, or a block it holds. */
|
|
36
|
+
export function footerSignsUp(mix: FooterMix): boolean {
|
|
37
|
+
return beforeOf(mix) === FooterBefore.NewsletterBand || mix.closing === FooterClosing.Newsletter || mix.holds.includes(FooterHold.Newsletter);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The type's sign-up (team/reference-cards row 6: hotel 3/3, store 3/3, ceramics 2/3, salon 2/3): a footer that asks for no
|
|
42
|
+
* sign-up holds one when the kind of business closes with one AND the site has a reason to write. A footer that already
|
|
43
|
+
* signs up keeps its own; a one-line footer and a name-and-action footer have no place for a block (`checkFooter` would
|
|
44
|
+
* leave it out), so they are left as the plan wrote them. Pure: the same mix when nothing changes.
|
|
45
|
+
*/
|
|
46
|
+
export function withTypeSignUp(mix: FooterMix, given: { readonly signUp?: boolean; readonly writes?: boolean }): FooterMix {
|
|
47
|
+
if (!given.signUp || given.writes === false || footerSignsUp(mix)) return mix;
|
|
48
|
+
if (mix.arrange === FooterArrange.Line || mix.closing === FooterClosing.NameAndAction) return mix;
|
|
49
|
+
const holds = footerTableWords(FooterIngredient.Holds).filter(h => h === FooterHold.Newsletter || mix.holds.includes(h));
|
|
50
|
+
return { ...mix, holds };
|
|
51
|
+
}
|
|
@@ -52,10 +52,25 @@ function pagesOfHeader(current: SerializedNode, companions: ReadonlyArray<Serial
|
|
|
52
52
|
* pages). Only a header that links to no page takes the studio's. A header that holds the bag or the account entry is a
|
|
53
53
|
* selling site's (unless the site says). Pure.
|
|
54
54
|
*/
|
|
55
|
+
/** Whether the header's brand shows a picture (an Image with an address) — the logo a hanging name needs (HI3-D21). */
|
|
56
|
+
function brandHasPicture(current: SerializedNode): boolean {
|
|
57
|
+
let found = false;
|
|
58
|
+
const walk = (n: SerializedNode, inBrand: boolean): void => {
|
|
59
|
+
if (found) return;
|
|
60
|
+
const here = inBrand || n.role === NavRole.Brand;
|
|
61
|
+
if (here && n.type === 'Image' && typeof n.props?.['src'] === 'string' && (n.props['src'] as string).trim()) { found = true; return; }
|
|
62
|
+
(n.children ?? []).forEach(c => walk(c, here));
|
|
63
|
+
};
|
|
64
|
+
walk(current, false);
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
|
|
55
68
|
export function headerSiteFor(site: HeaderSite, current: SerializedNode, companions: ReadonlyArray<SerializedNode> = []): HeaderSite {
|
|
56
69
|
let at = site;
|
|
57
70
|
const own = pagesOfHeader(current, companions);
|
|
58
71
|
if (own.length) at = { ...at, pages: own };
|
|
72
|
+
// HI3-D21: a hanging name needs a logo picture — the header's own brand says whether it has one.
|
|
73
|
+
if (at.logo === undefined) at = { ...at, logo: brandHasPicture(current) };
|
|
59
74
|
if (at.storeSlots !== undefined) return at;
|
|
60
75
|
let sells = false;
|
|
61
76
|
const walk = (n: SerializedNode): void => { if (n.role && STORE_SLOT_ROLES.has(n.role)) sells = true; (n.children ?? []).forEach(walk); };
|