@vectoriox/iox-ui 5.203.0 → 5.204.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/actions-core/index.d.ts +8 -1
  2. package/design-core/index.d.ts +62 -2
  3. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +8 -1
  4. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  5. package/fesm2022/vectoriox-iox-ui-design-core.mjs +121 -11
  6. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  7. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +5165 -267
  8. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  9. package/fesm2022/vectoriox-iox-ui.mjs +381 -32
  10. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  11. package/generation-core/index.d.ts +2263 -5
  12. package/index.d.ts +117 -12
  13. package/package.json +1 -1
  14. package/src/actions-core/element-actions.ts +9 -0
  15. package/src/design-core/contrast-audit.ts +93 -11
  16. package/src/design-core/flavor-spec.generated.ts +19 -0
  17. package/src/design-core/image-alt.ts +27 -0
  18. package/src/design-core/public-api.ts +1 -0
  19. package/src/generation-core/audit-site.ts +17 -3
  20. package/src/generation-core/baseline-roles.ts +10 -6
  21. package/src/generation-core/check-free.ts +12 -2
  22. package/src/generation-core/check-layout.ts +3 -2
  23. package/src/generation-core/critic-calibration.ts +175 -0
  24. package/src/generation-core/critic-prompt.ts +153 -0
  25. package/src/generation-core/critic-rubric.generated.ts +24 -0
  26. package/src/generation-core/critic-sheet.ts +203 -0
  27. package/src/generation-core/critic.ts +175 -0
  28. package/src/generation-core/design-doc-index.ts +58 -0
  29. package/src/generation-core/design-motion.ts +247 -0
  30. package/src/generation-core/design-ops-check.ts +370 -0
  31. package/src/generation-core/design-ops-of.ts +200 -0
  32. package/src/generation-core/design-ops.model.ts +239 -0
  33. package/src/generation-core/design-ops.schema.ts +122 -0
  34. package/src/generation-core/design-ops.ts +361 -0
  35. package/src/generation-core/design-recipes.ts +58 -0
  36. package/src/generation-core/designer-brief.ts +81 -0
  37. package/src/generation-core/designer-direction.ts +248 -0
  38. package/src/generation-core/designer-estimate.ts +171 -0
  39. package/src/generation-core/designer-lessons.generated.ts +653 -0
  40. package/src/generation-core/designer-lessons.ts +153 -0
  41. package/src/generation-core/designer-stop.ts +94 -0
  42. package/src/generation-core/footer-mix.ts +3 -1
  43. package/src/generation-core/node-baselines.generated.ts +953 -10
  44. package/src/generation-core/public-api.ts +20 -0
  45. package/src/generation-core/site-spec.generated.ts +73 -11
  46. package/src/generation-core/social-links.ts +195 -2
  47. package/src/generation-core/structure-fingerprint.ts +565 -0
  48. package/src/generation-core/templates.ts +39 -3
  49. package/styles/iox-design.css +26 -1
  50. package/styles/iox-forms.css +22 -0
@@ -0,0 +1,565 @@
1
+ import { AccordionRole, CardRole, MarqueeRole, SceneRole, SLIDER_TYPE, TabsRole } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ import { LAYOUT_LIST_TOKEN, LAYOUT_READY_MADE_TOKEN, LayoutFingerprint, LayoutSequenceToken, LayoutSignatureId, sectionTokenOf, signatureOf } from './layout-fingerprint';
4
+ import { LayoutListArrange, LayoutPage } from './layout-language';
5
+ import { SerializedNode } from './serialized-node';
6
+
7
+ /**
8
+ * THE STRUCTURAL FINGERPRINT (ai-designer-plan §2a′ point 3, AD-D19, R-H23–R-H25): what a page's STRUCTURE is — the
9
+ * order of its sections, each read as a shape (its columns, its media, its repeated items, its held or moving part),
10
+ * how it opens, how much of it is pictures, and its signature parts. No words, no colours, no styling: two pages with
11
+ * one structure in two looks are the same structure.
12
+ *
13
+ * ONE reading for the three things a page can be, so they compare with each other:
14
+ * - a plan page (premium-sites D9): its sections' D9 tokens (`sectionTokenOf`, `signatureOf`) — `structureOfLayoutPage`
15
+ * — or a fingerprint the studio's memory already stores (`structureOfFingerprint`). D9 itself is unchanged.
16
+ * - a free tree of ordinary ComponentNodes (the AI designer's page, a proof site, a composed page) —
17
+ * `structureOfTree`, a section → shape classifier over the nodes' types, composite roles and layout styles.
18
+ * - a reference, from its reading's "Body structure" (`architecture/ai/references/*.md`) — `structureOfReading`.
19
+ * - a RENDERED page — a reference's own DOM, or one of ours — from iox-render's `structure.json` (`structureOfDom`):
20
+ * the reader that lets the not-a-copy check judge a design against what the reference really is.
21
+ *
22
+ * Then `structureDistance` (0 = one structure, 1 = nothing shared), `designFreedomIssues` (a copy of the reference, a
23
+ * repeat of the kind's recent builds) and `conceptsDistinct` (the three concepts, pairwise). The thresholds are named
24
+ * and calibrated in structure-fingerprint.spec on the proof sites, their references and the J10 builds. Pure.
25
+ */
26
+
27
+ /** What a section is, structurally. */
28
+ export enum SectionShape {
29
+ /** Words alone, one column: a statement, a quote, a heading and a line. */
30
+ Statement = 'statement',
31
+ /** A mixed section with no clearer shape (and every D9 `composition`). */
32
+ Composition = 'composition',
33
+ /** A breath between sections. */
34
+ Inhale = 'inhale',
35
+ /** A picture or a film that IS the section (at most a line of words). */
36
+ Media = 'media',
37
+ /** Words over a picture that fills the section. */
38
+ PhotoGround = 'photo-ground',
39
+ /** Two columns, one of them a picture. */
40
+ Split = 'split',
41
+ /** Two or more columns of words (no repeated item). */
42
+ Columns = 'columns',
43
+ /** Three or more repeated items side by side (cards, a product row, a gallery). */
44
+ Grid = 'grid',
45
+ /** Repeated items one under another (rows, an accordion, tabs, a timeline, a table). */
46
+ List = 'list',
47
+ /** A row that runs by itself. */
48
+ Marquee = 'marquee',
49
+ /** A form. */
50
+ Form = 'form',
51
+ /** A section held still while the page scrolls (a Scene, a sticky stage). */
52
+ Held = 'held',
53
+ /** A held section carried sideways. */
54
+ Sideways = 'sideways',
55
+ }
56
+
57
+ /** Shapes that are kin: half a match in `structureDistance` (a coarse D9 `composition` against a finer plain shape). */
58
+ enum ShapeFamily {
59
+ Plain = 'plain',
60
+ Picture = 'picture',
61
+ Items = 'items',
62
+ Held = 'held',
63
+ Form = 'form',
64
+ }
65
+ const SHAPE_FAMILY: Readonly<Record<SectionShape, ShapeFamily>> = {
66
+ [SectionShape.Statement]: ShapeFamily.Plain,
67
+ [SectionShape.Composition]: ShapeFamily.Plain,
68
+ [SectionShape.Inhale]: ShapeFamily.Plain,
69
+ [SectionShape.Columns]: ShapeFamily.Plain,
70
+ [SectionShape.Media]: ShapeFamily.Picture,
71
+ [SectionShape.PhotoGround]: ShapeFamily.Picture,
72
+ [SectionShape.Split]: ShapeFamily.Picture,
73
+ [SectionShape.Grid]: ShapeFamily.Items,
74
+ [SectionShape.List]: ShapeFamily.Items,
75
+ [SectionShape.Marquee]: ShapeFamily.Items,
76
+ [SectionShape.Held]: ShapeFamily.Held,
77
+ [SectionShape.Sideways]: ShapeFamily.Held,
78
+ [SectionShape.Form]: ShapeFamily.Form,
79
+ };
80
+ const KIN = 0.5;
81
+
82
+ /** A page's structure. `signatures`: the parts that make it (held, sideways, marquee, accordion, tabs, slider, cards,
83
+ * a scene's moves), sorted, each once. `media`: the share of its sections that carry a picture. */
84
+ export interface StructureFingerprint {
85
+ opening: SectionShape;
86
+ shapes: SectionShape[];
87
+ media: number;
88
+ signatures: string[];
89
+ /** Set when the structure was read from a RENDERED page (`structureOfDom`): the DOM sees only some signature parts
90
+ * (`DOM_SIGNATURES`), so a distance with such a side compares those only. Absent for every other reader. */
91
+ reader?: StructureReader;
92
+ }
93
+
94
+ /** Who read a structure, when it matters to a comparison. */
95
+ export enum StructureReader {
96
+ Dom = 'dom',
97
+ }
98
+
99
+ /** The signature parts, as they are named in `signatures`. */
100
+ export enum StructureSignature {
101
+ Held = 'held',
102
+ Sideways = 'sideways',
103
+ Marquee = 'marquee',
104
+ Accordion = 'accordion',
105
+ Tabs = 'tabs',
106
+ Slider = 'slider',
107
+ Cards = 'cards',
108
+ Form = 'form',
109
+ }
110
+ /** A D9 signature (`LayoutSignatureId`) or a Scene's moves, as a signature part: `scene:<id>`. */
111
+ const SCENE_SIGNATURE = 'scene:';
112
+
113
+ const round = (n: number) => Math.round(n * 1000) / 1000;
114
+ const uniqueSorted = (xs: Iterable<string>) => [...new Set(xs)].sort();
115
+ const fingerprint = (shapes: SectionShape[], media: number, signatures: Iterable<string>): StructureFingerprint =>
116
+ ({ opening: shapes[0] ?? SectionShape.Composition, shapes, media: round(media), signatures: uniqueSorted(signatures) });
117
+
118
+ // ── Plan pages (D9) ─────────────────────────────────────────────────────────────────────────────────────────────────
119
+
120
+ /** A D9 sequence token as a shape (a `list:<mix>` token is a list or a grid by its arrangement). */
121
+ const SHAPE_OF_D9: Readonly<Record<string, SectionShape>> = {
122
+ [LayoutSequenceToken.Inhale]: SectionShape.Inhale,
123
+ [LayoutSequenceToken.Sideways]: SectionShape.Sideways,
124
+ [LayoutSequenceToken.HeldWords]: SectionShape.Held,
125
+ [LayoutSequenceToken.HeldReel]: SectionShape.Held,
126
+ [LayoutSequenceToken.Held]: SectionShape.Held,
127
+ [LayoutSequenceToken.PhotoGround]: SectionShape.PhotoGround,
128
+ [LayoutSequenceToken.Gallery]: SectionShape.Grid,
129
+ [LayoutSequenceToken.Split]: SectionShape.Split,
130
+ [LayoutSequenceToken.Composition]: SectionShape.Composition,
131
+ [LAYOUT_READY_MADE_TOKEN]: SectionShape.Composition,
132
+ };
133
+ /** List arrangements laid one under another (list-ingredients `arrange`); the rest are side by side. */
134
+ const STACKED_LISTS: ReadonlySet<string> = new Set([LayoutListArrange.Rows, LayoutListArrange.Strips, LayoutListArrange.Deck]);
135
+ const D9_PICTURES: ReadonlySet<SectionShape> = new Set([SectionShape.PhotoGround, SectionShape.Split, SectionShape.Grid, SectionShape.Media]);
136
+
137
+ function shapeOfD9(token: string): SectionShape {
138
+ if (token.startsWith(`${LAYOUT_LIST_TOKEN}:`)) return STACKED_LISTS.has(token.slice(LAYOUT_LIST_TOKEN.length + 1).split('/')[0]) ? SectionShape.List : SectionShape.Grid;
139
+ return SHAPE_OF_D9[token] ?? SectionShape.Composition;
140
+ }
141
+
142
+ /** A fingerprint the memory stores (D9 `fingerprintOf`), as a structure. The opening is the first section's shape; the
143
+ * media share counts the shapes that hold a picture (a D9 sequence does not say more). */
144
+ export function structureOfFingerprint(fp: Pick<LayoutFingerprint, 'sequence' | 'signature'>): StructureFingerprint {
145
+ const shapes = fp.sequence.map(shapeOfD9);
146
+ const signatures = fp.signature && fp.signature !== LayoutSignatureId.HeldScreen ? [`${SCENE_SIGNATURE}${fp.signature}`] : [];
147
+ if (shapes.includes(SectionShape.Held)) signatures.push(StructureSignature.Held);
148
+ if (shapes.includes(SectionShape.Sideways)) signatures.push(StructureSignature.Sideways);
149
+ return fingerprint(shapes, shapes.length ? shapes.filter(s => D9_PICTURES.has(s)).length / shapes.length : 0, signatures);
150
+ }
151
+
152
+ /** A model-laid plan page, through D9's own tokens. */
153
+ export function structureOfLayoutPage(page: LayoutPage): StructureFingerprint {
154
+ const sections = page.sections ?? [];
155
+ return structureOfFingerprint({
156
+ sequence: sections.map(s => (s.readyMade || s.carry ? LAYOUT_READY_MADE_TOKEN : sectionTokenOf(s))),
157
+ signature: signatureOf(sections.find(s => s.signature)),
158
+ });
159
+ }
160
+
161
+ // ── Free trees ──────────────────────────────────────────────────────────────────────────────────────────────────────
162
+
163
+ const MEDIA_TYPES: ReadonlySet<string> = new Set(['Image', 'Video', SLIDER_TYPE]);
164
+ const WORD_TYPES: ReadonlySet<string> = new Set(['Heading', 'Text']);
165
+ const REPEATER_TYPES: ReadonlySet<string> = new Set(['Repeater', 'List', SLIDER_TYPE]);
166
+ /** A section of words alone holds at most this many headings and texts to read as a statement. */
167
+ const STATEMENT_WORDS = 4;
168
+ /** Repeated items: this many siblings of one build. */
169
+ const REPEATED = 3;
170
+
171
+ /** The layout styles the classifier reads (base width). */
172
+ interface LayoutStyle {
173
+ position?: string;
174
+ display?: string;
175
+ flexDirection?: string;
176
+ gridTemplateColumns?: string;
177
+ width?: string;
178
+ backgroundImage?: string;
179
+ }
180
+ const styleOf = (n: SerializedNode) => (n.styleProps ?? {}) as LayoutStyle;
181
+ const roleOf = (n: SerializedNode) => (n as { role?: string }).role ?? '';
182
+ const childrenOf = (n: SerializedNode) => n.children ?? [];
183
+ function every(n: SerializedNode, visit: (n: SerializedNode) => void): void {
184
+ visit(n);
185
+ for (const c of childrenOf(n)) every(c, visit);
186
+ }
187
+ function some(n: SerializedNode, test: (n: SerializedNode) => boolean): boolean {
188
+ if (test(n)) return true;
189
+ return childrenOf(n).some(c => some(c, test));
190
+ }
191
+ const isMedia = (n: SerializedNode) => MEDIA_TYPES.has(n.type) || /url\(/.test(String(styleOf(n).backgroundImage ?? ''));
192
+ const hasMedia = (n: SerializedNode) => some(n, isMedia);
193
+ const isAbsolute = (n: SerializedNode) => styleOf(n).position === 'absolute';
194
+ /** A picture laid behind the section's words: absolute, as wide as the section (100%, an inset calc, or an inset). */
195
+ const isGround = (n: SerializedNode) => isMedia(n) && isAbsolute(n) && /^(100%|calc\(100%)/.test(String(styleOf(n).width ?? ''));
196
+ /** A node's build: its type and its children's, so a card and its siblings read alike. */
197
+ const buildOf = (n: SerializedNode): string => `${n.type}(${childrenOf(n).map(c => c.type).join(',')})`;
198
+ /** How many of a container's in-flow children sit side by side: a row's children, or a grid's tracks. */
199
+ function across(n: SerializedNode): number {
200
+ const s = styleOf(n);
201
+ const kids = childrenOf(n).filter(c => !isAbsolute(c));
202
+ if (s.display === 'grid') {
203
+ const tracks = String(s.gridTemplateColumns ?? '');
204
+ const repeat = /repeat\(\s*(\d+)/.exec(tracks);
205
+ return repeat ? Number(repeat[1]) : tracks.split(/\s+(?![^(]*\))/).filter(t => t && t !== 'none').length || 1;
206
+ }
207
+ return s.display === 'flex' && (s.flexDirection ?? 'row') === 'row' ? kids.length : 1;
208
+ }
209
+ /** The widest run of repeated items in a section: how many, and whether they sit side by side. */
210
+ function repeatedItems(section: SerializedNode): { count: number; across: boolean } {
211
+ let best = { count: 0, across: false };
212
+ every(section, n => {
213
+ const kids = childrenOf(n).filter(c => !isAbsolute(c));
214
+ if (REPEATER_TYPES.has(n.type)) best = best.count >= REPEATED ? best : { count: REPEATED, across: across(n) > 1 || n.type === SLIDER_TYPE };
215
+ const builds = new Map<string, number>();
216
+ for (const k of kids) if (k.type !== 'Heading' && k.type !== 'Text') builds.set(buildOf(k), (builds.get(buildOf(k)) ?? 0) + 1);
217
+ const most = Math.max(0, ...builds.values());
218
+ if (most >= REPEATED && most > best.count) best = { count: most, across: across(n) > 1 };
219
+ });
220
+ return best;
221
+ }
222
+ /** The widest side-by-side row of a section whose children hold content: how many columns, and whether one is a picture. */
223
+ function columns(section: SerializedNode): { count: number; picture: boolean } {
224
+ let best = { count: 1, picture: false };
225
+ every(section, n => {
226
+ const count = across(n);
227
+ if (count < 2 || count <= best.count) return;
228
+ const kids = childrenOf(n).filter(c => !isAbsolute(c));
229
+ if (kids.length < 2 || !kids.every(k => some(k, c => WORD_TYPES.has(c.type) || isMedia(c)))) return;
230
+ best = { count, picture: kids.some(k => isMedia(k) || (hasMedia(k) && !some(k, c => WORD_TYPES.has(c.type)))) };
231
+ });
232
+ return best;
233
+ }
234
+
235
+ /** The roles a section's signature parts carry (composite-core), as signatures. */
236
+ const ROLE_SIGNATURES: ReadonlyArray<[string, StructureSignature]> = [
237
+ [MarqueeRole.Marquee, StructureSignature.Marquee],
238
+ [AccordionRole.Accordion, StructureSignature.Accordion],
239
+ [TabsRole.Tabs, StructureSignature.Tabs],
240
+ [CardRole.Card, StructureSignature.Cards],
241
+ ];
242
+
243
+ /** One section of a tree: its shape and its signature parts. First match wins, the most telling first. */
244
+ export function sectionShapeOf(section: SerializedNode): { shape: SectionShape; signatures: string[] } {
245
+ const signatures: string[] = [];
246
+ const roles = new Set<string>();
247
+ every(section, n => {
248
+ roles.add(roleOf(n));
249
+ for (const t of (n as { sceneTracks?: Array<{ prop?: string }> }).sceneTracks ?? []) if (t?.prop) signatures.push(`${SCENE_SIGNATURE}${t.prop}`);
250
+ });
251
+ for (const [role, signature] of ROLE_SIGNATURES) if (roles.has(role)) signatures.push(signature);
252
+ if (some(section, n => n.type === SLIDER_TYPE)) signatures.push(StructureSignature.Slider);
253
+ const held = roles.has(SceneRole.Scene) || some(section, n => styleOf(n).position === 'sticky');
254
+ const sideways = roles.has(SceneRole.Walk);
255
+ const form = some(section, n => n.type === 'Form');
256
+ if (sideways) signatures.push(StructureSignature.Sideways);
257
+ if (held) signatures.push(StructureSignature.Held);
258
+ if (form) signatures.push(StructureSignature.Form);
259
+ const words = (() => { let n = 0; every(section, c => { if (WORD_TYPES.has(c.type)) n++; }); return n; })();
260
+ const media = hasMedia(section);
261
+ const items = repeatedItems(section);
262
+ const cols = columns(section);
263
+ const shape = sideways ? SectionShape.Sideways
264
+ : held ? SectionShape.Held
265
+ : form ? SectionShape.Form
266
+ : roles.has(MarqueeRole.Marquee) ? SectionShape.Marquee
267
+ : roles.has(AccordionRole.Accordion) || roles.has(TabsRole.Tabs) ? SectionShape.List
268
+ : items.count >= REPEATED ? (items.across ? SectionShape.Grid : SectionShape.List)
269
+ : some(section, isGround) && words > 0 ? SectionShape.PhotoGround
270
+ : media && words <= 1 ? SectionShape.Media
271
+ : cols.count >= 2 ? (cols.picture && cols.count === 2 ? SectionShape.Split : SectionShape.Columns)
272
+ : !media && words <= STATEMENT_WORDS ? SectionShape.Statement
273
+ : SectionShape.Composition;
274
+ return { shape, signatures };
275
+ }
276
+
277
+ /** A page of ordinary nodes (its top-level sections, globals aside), as a structure. */
278
+ export function structureOfTree(layout: ReadonlyArray<SerializedNode>): StructureFingerprint {
279
+ const sections = layout.filter(n => !(n as { isGlobal?: boolean }).isGlobal);
280
+ const read = sections.map(sectionShapeOf);
281
+ return fingerprint(read.map(r => r.shape), sections.length ? sections.filter(hasMedia).length / sections.length : 0, read.flatMap(r => r.signatures));
282
+ }
283
+
284
+ // ── References (their readings) ─────────────────────────────────────────────────────────────────────────────────────
285
+
286
+ /** A reading's words for a section → its shape. First match wins; the most telling first (`overview (photo + text)` is
287
+ * a split before it is a photo). */
288
+ export const READING_SHAPES: ReadonlyArray<[RegExp, SectionShape]> = [
289
+ [/sideways|horizontal(ly)? scroll/i, SectionShape.Sideways],
290
+ [/marquee|ticker|drifting rows/i, SectionShape.Marquee],
291
+ [/\bform\b|newsletter|sign-?up field/i, SectionShape.Form],
292
+ [/accordion|\btabs?\b|\bfaq\b|timeline|table|\bindex\b|\bsteps?\b|\bspec\b|\bmenu\b|list/i, SectionShape.List],
293
+ [/sticky|\bheld\b|pinned|scroll-driven|scrub|stack(s|ing)? (on|by)/i, SectionShape.Held],
294
+ [/\bover (a |the )?(photo|picture|marble|film|video|image)|behind (the )?(subject|words)|full-bleed[^;]*\b(line|statement|words?|sentence|paragraph)\b/i, SectionShape.PhotoGround],
295
+ [/split|beside|halves|two columns|side by side|either side|(photo|picture|film|video|image)[^;]*\+[^;]*(text|words|line)|(text|words)[^;]*\+[^;]*(photo|picture|film|image)/i, SectionShape.Split],
296
+ [/cards?\b|\brow\b|grid|\d-up|three|four|collage|products?|projects|gallery|tiles?|strip of|logos/i, SectionShape.Grid],
297
+ [/film|video|photo|picture|campaign|façade|facade|illustration|line art|line-drawing|\bmap\b|image/i, SectionShape.Media],
298
+ [/statement|sentence|\bline\b|paragraph|quote|heading|word|welcome|\bname\b|intro|invitation|band|chip/i, SectionShape.Statement],
299
+ ];
300
+ const READING_PICTURES = /film|video|photo|picture|campaign|façade|facade|illustration|line art|image|gallery|collage|packshot|products?/i;
301
+
302
+ /** A reference's sections, in its reading's words, as a structure. */
303
+ export function structureOfReading(sections: ReadonlyArray<string>): StructureFingerprint {
304
+ const shapes = sections.map(words => READING_SHAPES.find(([re]) => re.test(words))?.[1] ?? SectionShape.Composition);
305
+ const signatures: string[] = [];
306
+ if (shapes.includes(SectionShape.Held)) signatures.push(StructureSignature.Held);
307
+ if (shapes.includes(SectionShape.Sideways)) signatures.push(StructureSignature.Sideways);
308
+ if (shapes.includes(SectionShape.Marquee)) signatures.push(StructureSignature.Marquee);
309
+ if (shapes.includes(SectionShape.Form)) signatures.push(StructureSignature.Form);
310
+ return fingerprint(shapes, sections.length ? sections.filter(s => READING_PICTURES.test(s)).length / sections.length : 0, signatures);
311
+ }
312
+
313
+ // ── A rendered page (its DOM, read by iox-render) ───────────────────────────────────────────────────────────────────
314
+
315
+ /** The version of iox-render's `structure.json` this reads (`iox-render/src/measures/structure.mjs`, `v`). */
316
+ export const DOM_STRUCTURE_VERSION = 1;
317
+
318
+ /** A box in page pixels, at the capture's width. */
319
+ export interface DomBox {
320
+ x: number;
321
+ y: number;
322
+ w: number;
323
+ h: number;
324
+ }
325
+ /** One top-level section of a rendered page, as iox-render's `SECTION_STRUCTURE` reads it (`v: 1`). */
326
+ export interface DomStructureSection {
327
+ index: number;
328
+ tag: string;
329
+ role: 'header' | 'footer' | 'section';
330
+ box: DomBox;
331
+ /** The most blocks laid side by side in one row. */
332
+ columns: number;
333
+ /** The longest run of like siblings (cards, rows, items) and how they run. */
334
+ repeated: number;
335
+ repeatedAxis: 'row' | 'column' | null;
336
+ /** The share of the section's area under pictures (0…1). */
337
+ mediaShare: number;
338
+ /** How many pictures. */
339
+ media: number;
340
+ pictureBehindWords: boolean;
341
+ /** A sticky stage (or a long section whose picture is sticky or fixed). */
342
+ held: boolean;
343
+ form: boolean;
344
+ words: number;
345
+ headings: number;
346
+ }
347
+ /** iox-render's `structure.json` (one width). */
348
+ export interface DomPageStructure {
349
+ v: number;
350
+ width: number;
351
+ height: number;
352
+ root: string;
353
+ sections: DomStructureSection[];
354
+ }
355
+
356
+ /** The signature parts a rendered page shows: a held stage and a form. A marquee, an accordion, tabs, a slider, cards
357
+ * or a Scene's moves are roles and tracks of nodes — a DOM measure never says them. */
358
+ export const DOM_SIGNATURES: ReadonlySet<string> = new Set([StructureSignature.Held, StructureSignature.Form]);
359
+
360
+ /** A `<header>` this short is the site's bar — a global in a tree, so not a section; a taller one holds the opening. */
361
+ export const DOM_HEADER_BAR_MAX_PX = 240;
362
+ /** An empty band (no words, no picture, no heading) this short is a breath between sections. */
363
+ export const DOM_INHALE_MAX_PX = 360;
364
+ /** A section holds a picture when it has one AND pictures cover at least this share of it (a logo or an icon does not). */
365
+ const DOM_PICTURED_SHARE = 0.05;
366
+ /** A picture that IS the section: it covers at least this share … */
367
+ const DOM_MEDIA_SHARE = 0.5;
368
+ /** … and the words come to at most a line. */
369
+ const DOM_MEDIA_MAX_WORDS = 12;
370
+ /** Repeated items one under another read as a list only with this many words (fewer: a column of lines, not a list). */
371
+ const DOM_LIST_MIN_WORDS = 40;
372
+ /** Like columns of words alone, at most this many across, are columns, not a grid (a logo strip or a ticker runs wider). */
373
+ const DOM_WORD_COLUMNS_MAX = 4;
374
+ /** Two columns are a split when pictures cover at least this share of the section. */
375
+ const DOM_SPLIT_SHARE = 0.25;
376
+ /** Words alone, at most this many, with pictures under this share: a statement. */
377
+ const DOM_STATEMENT_MAX_WORDS = 60;
378
+ const DOM_STATEMENT_MAX_SHARE = 0.1;
379
+ /** Cards over one picture read as a grid only when they are this many across, each with a heading. */
380
+ const DOM_GRID_OVER_PICTURE = 3;
381
+ /** Loose pieces of an unwrapped body (a heading, a paragraph, a nav) are parts of a section, never sections. */
382
+ const DOM_FRAGMENT_TAGS: ReadonlySet<string> = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'a', 'span', 'nav', 'ul', 'ol', 'li', 'button', 'img', 'picture', 'figure', 'svg']);
383
+
384
+ const domPictured = (s: DomStructureSection) => s.media > 0 && s.mediaShare >= DOM_PICTURED_SHARE;
385
+ const domContains = (outer: DomBox, inner: DomBox) => inner.y >= outer.y && inner.y + inner.h <= outer.y + outer.h;
386
+
387
+ /**
388
+ * Which rows of a rendered page are its sections, as a tree's are: the site's header bar and footer are globals in a
389
+ * tree (`structureOfTree` drops them), so they are dropped here; a loose fragment is dropped; and a BACKDROP — a box with
390
+ * no words and no heading that holds two or more of the other rows (a framed page's paper) — is the page's ground, not
391
+ * a section.
392
+ */
393
+ function domSections(page: DomPageStructure): DomStructureSection[] {
394
+ const rows = page.sections ?? [];
395
+ const backdrop = (s: DomStructureSection) => s.words === 0 && s.headings === 0 && rows.filter(o => o !== s && domContains(s.box, o.box)).length >= 2;
396
+ return rows.filter(s => s.role !== 'footer'
397
+ && !(s.role === 'header' && s.box.h <= DOM_HEADER_BAR_MAX_PX)
398
+ && !DOM_FRAGMENT_TAGS.has(s.tag)
399
+ && !backdrop(s));
400
+ }
401
+
402
+ /**
403
+ * One section of a rendered page → its shape. The same shapes as `sectionShapeOf`, read from measures instead of nodes.
404
+ * First match wins, the most telling first; it differs from the tree's order where the DOM is coarser:
405
+ * - a picture behind words comes before a form and repeated items (a booking bar or a row of season pills over the
406
+ * opening film is an opening over a picture; cards over one picture are a grid only ≥ 3 across, each headed);
407
+ * - like siblings one under another are a list only with ≥ 40 words (three paragraphs of a text column are alike too);
408
+ * - a "form" that is a player's controls (pictures ≥ half, at most a line of words) is the picture.
409
+ * The DOM cannot tell a marquee, an accordion, tabs or a sideways walk from a row or a held stage: it never says them.
410
+ */
411
+ export function domSectionShapeOf(s: DomStructureSection): SectionShape {
412
+ const items = s.repeated >= REPEATED;
413
+ const row = items && s.repeatedAxis === 'row' && s.columns >= 2;
414
+ const player = s.mediaShare >= DOM_MEDIA_SHARE && s.words <= DOM_MEDIA_MAX_WORDS;
415
+ if (s.held) return SectionShape.Held;
416
+ if (!domPictured(s) && s.words === 0 && s.headings === 0 && !s.form && s.box.h <= DOM_INHALE_MAX_PX) return SectionShape.Inhale;
417
+ if (s.pictureBehindWords && s.words > 0) {
418
+ return row && s.columns >= DOM_GRID_OVER_PICTURE && s.headings >= DOM_GRID_OVER_PICTURE ? SectionShape.Grid : SectionShape.PhotoGround;
419
+ }
420
+ if (s.form && !player) return SectionShape.Form;
421
+ // A few like columns of words alone (no picture, no heading each) are columns; many across are a strip (a grid).
422
+ if (row && !domPictured(s) && s.headings < REPEATED && s.columns <= DOM_WORD_COLUMNS_MAX) return SectionShape.Columns;
423
+ if (row) return SectionShape.Grid;
424
+ if (items && s.words >= DOM_LIST_MIN_WORDS) return SectionShape.List;
425
+ if (player) return SectionShape.Media;
426
+ if (s.columns >= 2) return s.columns === 2 && s.mediaShare >= DOM_SPLIT_SHARE ? SectionShape.Split : SectionShape.Columns;
427
+ if (s.mediaShare < DOM_STATEMENT_MAX_SHARE && s.words <= DOM_STATEMENT_MAX_WORDS) return SectionShape.Statement;
428
+ return SectionShape.Composition;
429
+ }
430
+
431
+ /**
432
+ * A RENDERED page — a reference's own DOM, or one of ours — as a structure (AD-D19): iox-render's `structure.json`
433
+ * (`v: 1`, one width; the laptop's compares with `structureOfTree`, which reads base styles). The media share is the
434
+ * share of sections that hold a picture, as the tree's; the signatures are the two the DOM can see (held, form).
435
+ * Throws on another version — a newer measure must be read on purpose, never guessed.
436
+ */
437
+ export function structureOfDom(page: DomPageStructure): StructureFingerprint {
438
+ if (page?.v !== DOM_STRUCTURE_VERSION) throw new Error(`structureOfDom: structure.json v${page?.v} is not v${DOM_STRUCTURE_VERSION}`);
439
+ const sections = domSections(page);
440
+ const shapes = sections.map(domSectionShapeOf);
441
+ const signatures: string[] = [];
442
+ if (shapes.includes(SectionShape.Held)) signatures.push(StructureSignature.Held);
443
+ if (shapes.includes(SectionShape.Form)) signatures.push(StructureSignature.Form);
444
+ return { ...fingerprint(shapes, sections.length ? sections.filter(domPictured).length / sections.length : 0, signatures), reader: StructureReader.Dom };
445
+ }
446
+
447
+ /** A reference read into fewer sections than this is too coarse to judge a copy by (a one-screen site, a canvas). */
448
+ export const MIN_REFERENCE_SECTIONS = 3;
449
+
450
+ /**
451
+ * A reference's structure for the not-a-copy check: its rendered DOM when iox-render captured one with at least
452
+ * {@link MIN_REFERENCE_SECTIONS} sections — the DOM speaks the tree's language (the same page read both ways sits
453
+ * 0.08–0.18 apart, under the copy line) — else its reading's "Body structure", else null (nothing to judge by).
454
+ */
455
+ export function structureOfReference(sources: { dom?: DomPageStructure | null; reading?: ReadonlyArray<string> | null }): StructureFingerprint | null {
456
+ const dom = sources.dom ? structureOfDom(sources.dom) : null;
457
+ if (dom && dom.shapes.length >= MIN_REFERENCE_SECTIONS) return dom;
458
+ return sources.reading && sources.reading.length >= MIN_REFERENCE_SECTIONS ? structureOfReading(sources.reading) : null;
459
+ }
460
+
461
+ // ── Distance and the rules ──────────────────────────────────────────────────────────────────────────────────────────
462
+
463
+ /** How the parts of the distance weigh (they add to 1): the order of shapes leads. */
464
+ export const STRUCTURE_WEIGHTS = { order: 0.55, opening: 0.15, length: 0.1, media: 0.1, signatures: 0.1 } as const;
465
+
466
+ function shapeSimilarity(a: SectionShape, b: SectionShape): number {
467
+ if (a === b) return 1;
468
+ return SHAPE_FAMILY[a] === SHAPE_FAMILY[b] ? KIN : 0;
469
+ }
470
+ /** The best alignment of two orders (a common subsequence, a kin pair counting half), over the longer. */
471
+ function orderShare(a: ReadonlyArray<SectionShape>, b: ReadonlyArray<SectionShape>): number {
472
+ const d = Array.from({ length: a.length + 1 }, () => new Array<number>(b.length + 1).fill(0));
473
+ for (let i = 1; i <= a.length; i++) {
474
+ for (let j = 1; j <= b.length; j++) d[i][j] = Math.max(d[i - 1][j], d[i][j - 1], d[i - 1][j - 1] + shapeSimilarity(a[i - 1], b[j - 1]));
475
+ }
476
+ return d[a.length][b.length] / Math.max(1, a.length, b.length);
477
+ }
478
+ function jaccard(a: ReadonlyArray<string>, b: ReadonlyArray<string>): number {
479
+ const union = new Set([...a, ...b]);
480
+ if (!union.size) return 1;
481
+ return a.filter(x => b.includes(x)).length / union.size;
482
+ }
483
+
484
+ /** How far apart two structures are: 0 = one structure, 1 = nothing shared. Symmetric. */
485
+ export function structureDistance(a: StructureFingerprint, b: StructureFingerprint): number {
486
+ const w = STRUCTURE_WEIGHTS;
487
+ // Like with like: against a rendered page, only the signature parts a DOM can see count (a tree's marquee role or a
488
+ // Scene's moves are not missing from the reference — the reference's reader cannot see them).
489
+ const seen = a.reader === StructureReader.Dom || b.reader === StructureReader.Dom;
490
+ const sigs = (x: StructureFingerprint) => (seen ? x.signatures.filter(sig => DOM_SIGNATURES.has(sig)) : x.signatures);
491
+ const similarity = w.order * orderShare(a.shapes, b.shapes)
492
+ + w.opening * shapeSimilarity(a.opening, b.opening)
493
+ + w.length * (Math.min(a.shapes.length, b.shapes.length) / Math.max(1, a.shapes.length, b.shapes.length))
494
+ + w.media * (1 - Math.abs(a.media - b.media))
495
+ + w.signatures * jaccard(sigs(a), sigs(b));
496
+ return round(1 - similarity);
497
+ }
498
+
499
+ /**
500
+ * AD-D19, calibrated (structure-fingerprint.spec, 2026-11-30):
501
+ * - COPY: the four proof exports' designed pages sit 0.587–0.844 from their references' readings, so none is a copy;
502
+ * a page laid in the reference's own order is 0, and with one section changed still under the line.
503
+ * - REPEAT: J10 Homes of one kind sit 0.212 (law, Pro against Free) and 0.253 (store, Pro against the 11-23 build) —
504
+ * repeats; law Home and law Services, two pages made with care on their own arrangements, sit 0.38 — distinct.
505
+ * Reading against tree is the weak seam: a reading's words are coarser than a tree's nodes, so a tree that follows its
506
+ * reference block for block still measures far (law Home against GRAYA, 0.663). The reference's own DOM
507
+ * (`structureOfDom`) closes it on our side: the proof's law and hotel Homes, read as trees and as rendered pages, sit
508
+ * 0.175 and 0.079 apart — under the copy line (spec "a rendered page") — while the proof's pages sit ≥ 0.317 from
509
+ * every one of the 32 captured references (measured 2026-11-30, ai-designer-plan "structureOfDom + bucket store as
510
+ * built"). GRAYA's DOM is itself coarse (its body is one 5,800 px block), so law Home still reads 0.659 from it.
511
+ */
512
+ export const FREEDOM_COPY_DISTANCE = 0.25;
513
+ export const FREEDOM_REPEAT_DISTANCE = 0.3;
514
+ /** R-H24: the three concepts must sit at least this far apart, pairwise — farther than a repeat. */
515
+ export const CONCEPT_MIN_DISTANCE = FREEDOM_REPEAT_DISTANCE;
516
+
517
+ export enum FreedomIssueCode {
518
+ /** Too close to the reference's structure. */
519
+ Copy = 'copy',
520
+ /** Too close to a recent build of the same kind. */
521
+ Repeat = 'repeat',
522
+ }
523
+ export interface FreedomIssue {
524
+ code: FreedomIssueCode;
525
+ /** The reference or the build it is too close to. */
526
+ of: string;
527
+ distance: number;
528
+ message: string;
529
+ }
530
+ export interface NamedStructure {
531
+ name: string;
532
+ structure: StructureFingerprint;
533
+ }
534
+
535
+ /** R-H23: a page too close to its reference (a copy) or to its kind's recent builds (a repeat). Either caps the page like
536
+ * a polish bug, and the next round's brief demands a structural change — the message says which (the caller's). */
537
+ export function designFreedomIssues(page: StructureFingerprint, context: { reference?: NamedStructure; recent?: ReadonlyArray<NamedStructure> }): FreedomIssue[] {
538
+ const issues: FreedomIssue[] = [];
539
+ const order = (s: StructureFingerprint) => s.shapes.join(' → ');
540
+ if (context.reference) {
541
+ const distance = structureDistance(page, context.reference.structure);
542
+ if (distance <= FREEDOM_COPY_DISTANCE) {
543
+ issues.push({ code: FreedomIssueCode.Copy, of: context.reference.name, distance, message: `the page's structure (${order(page)}) follows "${context.reference.name}" (${order(context.reference.structure)}) — distance ${distance}, a copy at ${FREEDOM_COPY_DISTANCE} or less; change the order and the shapes of the sections, not the styling` });
544
+ }
545
+ }
546
+ for (const r of context.recent ?? []) {
547
+ const distance = structureDistance(page, r.structure);
548
+ if (distance <= FREEDOM_REPEAT_DISTANCE) {
549
+ issues.push({ code: FreedomIssueCode.Repeat, of: r.name, distance, message: `the page's structure (${order(page)}) repeats "${r.name}" (${order(r.structure)}) — distance ${distance}, a repeat at ${FREEDOM_REPEAT_DISTANCE} or less; change the order and the shapes of the sections, not the styling` });
550
+ }
551
+ }
552
+ return issues;
553
+ }
554
+
555
+ /** R-H24: whether the concepts differ pairwise, and the closest pair. */
556
+ export function conceptsDistinct(concepts: ReadonlyArray<StructureFingerprint>): { distinct: boolean; closest: { a: number; b: number; distance: number } | null } {
557
+ let closest: { a: number; b: number; distance: number } | null = null;
558
+ for (let a = 0; a < concepts.length; a++) {
559
+ for (let b = a + 1; b < concepts.length; b++) {
560
+ const distance = structureDistance(concepts[a], concepts[b]);
561
+ if (!closest || distance < closest.distance) closest = { a, b, distance };
562
+ }
563
+ }
564
+ return { distinct: !closest || closest.distance >= CONCEPT_MIN_DISTANCE, closest };
565
+ }
@@ -1,6 +1,8 @@
1
1
  import type { DesignChoices } from '@vectoriox/iox-ui/design-core';
2
2
 
3
- import { ContentTypePlan, DataSourcePlan, GlobalSlot, PagePlan, SiteBusiness, SitePlan, SitePlanSourceKind, SITE_PLAN_VERSION } from './site-plan.model';
3
+ import {
4
+ ContentSeedPlan, ContentTypePlan, DataSourcePlan, GlobalSlot, PagePlan, SiteBusiness, SiteLocale, SitePlan, SitePlanSourceKind, SITE_PLAN_VERSION,
5
+ } from './site-plan.model';
4
6
  import { SPEC_SITE_TEMPLATES } from './site-spec.generated';
5
7
 
6
8
  /** A site structure the wizard offers (contract `site.templates`). A template is a Site Plan without the
@@ -15,6 +17,13 @@ export interface SiteTemplate {
15
17
  readonly dataSources: ReadonlyArray<DataSourcePlan>;
16
18
  readonly pages: ReadonlyArray<PagePlan>;
17
19
  readonly globals: Readonly<Record<`${GlobalSlot}`, string>>;
20
+ /**
21
+ * cms-client#149: the template's own words on a Hebrew site — English word → Hebrew, for every page name, section slot
22
+ * word, content-type label and sample-item word the template writes (the contract's TEMPLATE_COPY_HE, else COPY_HE;
23
+ * its gate refuses a word with no Hebrew). A table BESIDE the pages, never keys inside them: the import and showcase
24
+ * plans copy a template's pages and types into a Site Plan, whose validator refuses an undocumented key.
25
+ */
26
+ readonly copyHe?: Readonly<Record<string, string>>;
18
27
  }
19
28
 
20
29
  export const SITE_TEMPLATES: Readonly<Record<string, SiteTemplate>> = SPEC_SITE_TEMPLATES;
@@ -30,12 +39,37 @@ export interface TemplatePlanInput {
30
39
  design: DesignChoices;
31
40
  /** Keys of the template's OPTIONAL pages to leave out (the wizard's Pages step). */
32
41
  omitPages?: ReadonlyArray<string>;
42
+ /** cms-client#149: the site's language — the plan's `locale` (every page's), and on `he` the template's own words in
43
+ * Hebrew (`SiteTemplate.copyHe`). Absent = English, as a plan with no locale. */
44
+ locale?: `${SiteLocale}`;
33
45
  }
34
46
 
35
47
  export class SiteTemplateError extends Error {}
36
48
 
37
49
  const clone = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;
38
50
 
51
+ /** The template's own words in the site's language: on `he` every word `copyHe` holds is swapped, the rest kept (a slug,
52
+ * a `{sampleImage:n}`, a count). English — or a template with no table — is the template as written. */
53
+ function wordsIn(template: SiteTemplate, locale: string | undefined): (word: string) => string {
54
+ const table = locale === SiteLocale.He ? template.copyHe : undefined;
55
+ return table ? (word: string) => table[word] ?? word : (word: string) => word;
56
+ }
57
+
58
+ const SEED_NOT_WORDS: ReadonlySet<string> = new Set(['slug']);
59
+
60
+ function localPage(page: PagePlan, word: (w: string) => string): PagePlan {
61
+ return {
62
+ ...page, name: word(page.name),
63
+ sections: page.sections.map(s => (s.slots ? { ...s, slots: Object.fromEntries(Object.entries(s.slots).map(([k, v]) => [k, word(v)])) } : s)),
64
+ };
65
+ }
66
+
67
+ function localType(type: ContentTypePlan, word: (w: string) => string): ContentTypePlan {
68
+ const seed = type.seed && Object.fromEntries(Object.entries(type.seed)
69
+ .map(([k, v]) => [k, typeof v === 'string' && !SEED_NOT_WORDS.has(k) ? word(v) : v])) as unknown as ContentSeedPlan;
70
+ return { ...type, label: word(type.label), ...(seed ? { seed } : {}) };
71
+ }
72
+
39
73
  /**
40
74
  * The template as a Site Plan (`source.kind: template`), with the customer's business and look. A
41
75
  * required page cannot be left out, and an unknown key is refused — nothing is guessed.
@@ -47,14 +81,16 @@ export function planFromTemplate(template: SiteTemplate, input: TemplatePlanInpu
47
81
  if (!page) throw new SiteTemplateError(`template ${template.id} has no page "${key}"`);
48
82
  if (page.required) throw new SiteTemplateError(`page "${key}" of template ${template.id} is required`);
49
83
  }
84
+ const word = wordsIn(template, input.locale);
50
85
  return {
51
86
  version: SITE_PLAN_VERSION,
52
87
  source: { kind: SitePlanSourceKind.Template, templateId: template.id, templateVersion: template.version },
53
88
  business: clone(input.business),
89
+ ...(input.locale ? { locale: input.locale } : {}),
54
90
  design: clone(input.design),
55
- contentTypes: clone(template.contentTypes),
91
+ contentTypes: clone(template.contentTypes.map(t => localType(t, word))),
56
92
  dataSources: clone(template.dataSources),
57
- pages: clone(template.pages.filter(p => !omit.has(p.key))),
93
+ pages: clone(template.pages.filter(p => !omit.has(p.key)).map(p => localPage(p, word))),
58
94
  globals: clone(template.globals),
59
95
  };
60
96
  }