@vectoriox/iox-ui 5.202.1 → 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 (55) 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 +5443 -293
  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 +2368 -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/compose-free.ts +3 -1
  24. package/src/generation-core/compose-layout.ts +1 -1
  25. package/src/generation-core/compose-site.ts +29 -11
  26. package/src/generation-core/critic-calibration.ts +175 -0
  27. package/src/generation-core/critic-prompt.ts +153 -0
  28. package/src/generation-core/critic-rubric.generated.ts +24 -0
  29. package/src/generation-core/critic-sheet.ts +203 -0
  30. package/src/generation-core/critic.ts +175 -0
  31. package/src/generation-core/design-doc-index.ts +58 -0
  32. package/src/generation-core/design-motion.ts +247 -0
  33. package/src/generation-core/design-ops-check.ts +370 -0
  34. package/src/generation-core/design-ops-of.ts +200 -0
  35. package/src/generation-core/design-ops.model.ts +239 -0
  36. package/src/generation-core/design-ops.schema.ts +122 -0
  37. package/src/generation-core/design-ops.ts +361 -0
  38. package/src/generation-core/design-recipes.ts +58 -0
  39. package/src/generation-core/designer-brief.ts +81 -0
  40. package/src/generation-core/designer-direction.ts +248 -0
  41. package/src/generation-core/designer-estimate.ts +171 -0
  42. package/src/generation-core/designer-lessons.generated.ts +653 -0
  43. package/src/generation-core/designer-lessons.ts +153 -0
  44. package/src/generation-core/designer-stop.ts +94 -0
  45. package/src/generation-core/footer-free.ts +23 -2
  46. package/src/generation-core/footer-mix.ts +60 -14
  47. package/src/generation-core/layout-language.ts +2 -0
  48. package/src/generation-core/node-baselines.generated.ts +953 -10
  49. package/src/generation-core/public-api.ts +21 -0
  50. package/src/generation-core/site-spec.generated.ts +82 -10
  51. package/src/generation-core/social-links.ts +370 -0
  52. package/src/generation-core/structure-fingerprint.ts +565 -0
  53. package/src/generation-core/templates.ts +39 -3
  54. package/styles/iox-design.css +26 -1
  55. package/styles/iox-forms.css +22 -0
@@ -0,0 +1,203 @@
1
+ /**
2
+ * THE CRITIC'S SHEET (ai-designer-plan §2c–§2d, AD3): what the critic looks at — the reference beside ours, view by view,
3
+ * laptop then phone, then 4–6 zoomed crops (a defect under ~20px is invisible at sheet scale, law HARNESS §1.5). The
4
+ * captures come from a `CaptureSource`: today the folders the tester and the designer loop wrote
5
+ * (`<dir>/<laptop|phone>/0N-<view>.png` + `metrics.json`); from AD2 the `iox-render` service, behind the same interface.
6
+ * This file only PLANS the sheet (which pairs, which crops, what they cost in image tokens); the pixels are the caller's.
7
+ * Pure.
8
+ */
9
+
10
+ export enum CaptureWidth {
11
+ Laptop = 'laptop',
12
+ Phone = 'phone',
13
+ }
14
+ /** The widths' viewports (§2c). */
15
+ export const CAPTURE_VIEWPORTS: Readonly<Record<CaptureWidth, { w: number; h: number }>> = {
16
+ [CaptureWidth.Laptop]: { w: 1440, h: 900 },
17
+ [CaptureWidth.Phone]: { w: 390, h: 844 },
18
+ };
19
+
20
+ /**
21
+ * The views, in the order the sheet shows them: the tester's capture set (`first` … `full`) and the views `iox-render`
22
+ * adds in AD2 (two screens down, the Scenes at 25 / 50 / 90 %, reduced motion). A view a source does not have is skipped.
23
+ */
24
+ export enum CaptureView {
25
+ First = 'first',
26
+ HeaderOpen = 'header-open',
27
+ HeaderScrolled = 'header-scrolled',
28
+ Down1 = 'down-1',
29
+ Down2 = 'down-2.2',
30
+ List = 'list',
31
+ Scene25 = 'scene-25',
32
+ Scene50 = 'scene-50',
33
+ Scene90 = 'scene-90',
34
+ Reduced = 'reduced-motion',
35
+ Footer = 'footer',
36
+ Full = 'full',
37
+ }
38
+ export const CAPTURE_VIEW_ORDER: ReadonlyArray<CaptureView> = Object.values(CaptureView);
39
+
40
+ /** One captured picture: where it is (a path, a storage key — the caller reads it) and its size in pixels. */
41
+ export interface CaptureShot {
42
+ width: CaptureWidth;
43
+ view: CaptureView;
44
+ ref: string;
45
+ w: number;
46
+ h: number;
47
+ }
48
+
49
+ /** A box on a shot, in its pixels. */
50
+ export interface CaptureBox {
51
+ x: number;
52
+ y: number;
53
+ w: number;
54
+ h: number;
55
+ }
56
+
57
+ /** The measures a capture knows (a subset of the tester's `metrics.json`; AD2's measures add to it). */
58
+ export interface CaptureMetrics {
59
+ /** The header's box at load. */
60
+ header?: CaptureBox;
61
+ /** Boxes a measure flagged (an overlap, a lone word, a clipped line) — each one is cropped first. */
62
+ flagged?: Array<{ box: CaptureBox; view: CaptureView; why: string }>;
63
+ }
64
+
65
+ export interface CaptureSet {
66
+ /** The page (`law-home`) or the reference (`graya-institute`). */
67
+ name: string;
68
+ shots: CaptureShot[];
69
+ metrics?: Partial<Record<CaptureWidth, CaptureMetrics>>;
70
+ }
71
+
72
+ /** What a page or a reference is, to its capture source. */
73
+ export interface CaptureTarget {
74
+ name: string;
75
+ /** The address the source renders (iox-render), or the folder it reads (today). */
76
+ at: string;
77
+ }
78
+
79
+ /** The one interface the sheet is built from. Today a folder reader; from AD2, `iox-render`. */
80
+ export interface CaptureSource {
81
+ capture(target: CaptureTarget): Promise<CaptureSet>;
82
+ }
83
+
84
+ /**
85
+ * Image tokens a vision model reads for a picture of w × h (ai-cost-plan, ai-designer-plan §6b): ⌈w/28⌉ × ⌈h/28⌉,
86
+ * capped — a bigger picture is scaled down to the cap.
87
+ */
88
+ export const VISION_TOKEN_TILE = 28;
89
+ export const VISION_TOKEN_CAP = 4_784;
90
+ export function visionImageTokens(w: number, h: number): number {
91
+ return Math.min(Math.ceil(w / VISION_TOKEN_TILE) * Math.ceil(h / VISION_TOKEN_TILE), VISION_TOKEN_CAP);
92
+ }
93
+
94
+ /** A view of the sheet: the reference's shot and ours, at one width. */
95
+ export interface SheetPair {
96
+ width: CaptureWidth;
97
+ view: CaptureView;
98
+ reference: CaptureShot;
99
+ ours: CaptureShot;
100
+ }
101
+
102
+ /** A zoomed crop: the box on a shot, how much it is enlarged, and why it was chosen. `reference` crops the same place on
103
+ * the reference's shot, for a side by side (a flagged defect of ours has none). */
104
+ export interface SheetCrop {
105
+ width: CaptureWidth;
106
+ view: CaptureView;
107
+ why: string;
108
+ ours: { ref: string; box: CaptureBox };
109
+ reference?: { ref: string; box: CaptureBox };
110
+ zoom: number;
111
+ }
112
+
113
+ export interface CritiqueSheet {
114
+ pairs: SheetPair[];
115
+ crops: SheetCrop[];
116
+ /** The views one side has and the other has not (`phone/footer: no reference shot`). */
117
+ missing: string[];
118
+ /** The image tokens the sheet costs a vision model (pairs, then each crop at its zoom). */
119
+ imageTokens: number;
120
+ /** Of those, the reference's views — the share read from the cache from round 2 (`CriticSheetLayout.Cached`). */
121
+ referenceImageTokens: number;
122
+ }
123
+
124
+ /** Crops the sheet always looks at when the measures flagged fewer, as fractions of the shot (`box` in 0–1). */
125
+ export interface CropRecipe {
126
+ width: CaptureWidth;
127
+ view: CaptureView;
128
+ box: CaptureBox;
129
+ why: string;
130
+ }
131
+ export const CRITIC_CROP_RECIPES: ReadonlyArray<CropRecipe> = [
132
+ { width: CaptureWidth.Laptop, view: CaptureView.First, box: { x: 0, y: 0, w: 1, h: 0.16 }, why: 'the header on the opening' },
133
+ { width: CaptureWidth.Laptop, view: CaptureView.First, box: { x: 0, y: 0.16, w: 0.6, h: 0.6 }, why: 'the opening\'s words' },
134
+ { width: CaptureWidth.Laptop, view: CaptureView.Footer, box: { x: 0, y: 0.55, w: 1, h: 0.45 }, why: 'the footer\'s name and legal row' },
135
+ { width: CaptureWidth.Phone, view: CaptureView.First, box: { x: 0, y: 0, w: 1, h: 0.5 }, why: 'the phone opening and its header' },
136
+ { width: CaptureWidth.Phone, view: CaptureView.Footer, box: { x: 0, y: 0.5, w: 1, h: 0.5 }, why: 'the phone footer' },
137
+ ];
138
+ export const CRITIC_CROPS = { min: 4, max: 6 } as const;
139
+ /** Flagged boxes take at most this many crops (one per distinct finding — a clipped button repeated down the page is one),
140
+ * so the recipes always keep the fewest (`CRITIC_CROPS.min`): a page with nine findings still shows its header and footer. */
141
+ export const CRITIC_FLAGGED_CROPS = CRITIC_CROPS.max - CRITIC_CROPS.min;
142
+ /** A crop is enlarged until its long side fills a laptop view, at most this much. */
143
+ export const CRITIC_CROP_MAX_ZOOM = 2;
144
+ /** Room kept around a measured box (the header's), in pixels. */
145
+ const CROP_MARGIN = 16;
146
+
147
+ const shotOf = (set: CaptureSet, width: CaptureWidth, view: CaptureView) => set.shots.find(s => s.width === width && s.view === view);
148
+ const fraction = (shot: CaptureShot, f: CaptureBox): CaptureBox =>
149
+ ({ x: Math.round(f.x * shot.w), y: Math.round(f.y * shot.h), w: Math.round(f.w * shot.w), h: Math.round(f.h * shot.h) });
150
+ const clip = (shot: CaptureShot, b: CaptureBox): CaptureBox => {
151
+ const x = Math.max(0, Math.min(b.x, shot.w - 1));
152
+ const y = Math.max(0, Math.min(b.y, shot.h - 1));
153
+ return { x, y, w: Math.max(1, Math.min(b.w, shot.w - x)), h: Math.max(1, Math.min(b.h, shot.h - y)) };
154
+ };
155
+ function zoomOf(box: CaptureBox): number {
156
+ const fill = Math.min(CAPTURE_VIEWPORTS[CaptureWidth.Laptop].w / box.w, CAPTURE_VIEWPORTS[CaptureWidth.Laptop].h / box.h);
157
+ return Math.max(1, Math.min(CRITIC_CROP_MAX_ZOOM, Math.floor(fill * 4) / 4));
158
+ }
159
+
160
+ /**
161
+ * The sheet for one page against one reference: every view both sides have, laptop first, in `CAPTURE_VIEW_ORDER`; then
162
+ * the crops — ours' flagged boxes first (distinct findings, at most `CRITIC_FLAGGED_CROPS`), then the recipes on both
163
+ * sides, up to the most (the recipes alone give the fewest). The header recipe uses the measured header box when ours has one.
164
+ */
165
+ export function planCritiqueSheet(ours: CaptureSet, reference: CaptureSet): CritiqueSheet {
166
+ const pairs: SheetPair[] = [];
167
+ const missing: string[] = [];
168
+ for (const width of Object.values(CaptureWidth)) {
169
+ for (const view of CAPTURE_VIEW_ORDER) {
170
+ const o = shotOf(ours, width, view);
171
+ const r = shotOf(reference, width, view);
172
+ if (o && r) pairs.push({ width, view, reference: r, ours: o });
173
+ else if (o || r) missing.push(`${width}/${view}: no ${o ? 'reference' : 'page'} shot`);
174
+ }
175
+ }
176
+ const crops: SheetCrop[] = [];
177
+ const seen = new Set<string>();
178
+ for (const width of Object.values(CaptureWidth)) {
179
+ for (const f of ours.metrics?.[width]?.flagged ?? []) {
180
+ const shot = shotOf(ours, width, f.view);
181
+ if (!shot || crops.length >= CRITIC_FLAGGED_CROPS || seen.has(f.why)) continue;
182
+ seen.add(f.why);
183
+ const box = clip(shot, f.box);
184
+ crops.push({ width, view: f.view, why: f.why, ours: { ref: shot.ref, box }, zoom: zoomOf(box) });
185
+ }
186
+ }
187
+ for (const recipe of CRITIC_CROP_RECIPES) {
188
+ if (crops.length >= CRITIC_CROPS.max) break;
189
+ const o = shotOf(ours, recipe.width, recipe.view);
190
+ const r = shotOf(reference, recipe.width, recipe.view);
191
+ if (!o || !r) continue;
192
+ const header = recipe === CRITIC_CROP_RECIPES[0] ? ours.metrics?.[recipe.width]?.header : undefined;
193
+ const box = clip(o, header
194
+ ? { x: header.x - CROP_MARGIN, y: Math.max(0, header.y - CROP_MARGIN), w: header.w + 2 * CROP_MARGIN, h: header.h + 2 * CROP_MARGIN }
195
+ : fraction(o, recipe.box));
196
+ crops.push({ width: recipe.width, view: recipe.view, why: recipe.why, ours: { ref: o.ref, box }, reference: { ref: r.ref, box: clip(r, fraction(r, recipe.box)) }, zoom: zoomOf(box) });
197
+ }
198
+ const referenceImageTokens = pairs.reduce((n, p) => n + visionImageTokens(p.reference.w, p.reference.h), 0);
199
+ const pairTokens = referenceImageTokens + pairs.reduce((n, p) => n + visionImageTokens(p.ours.w, p.ours.h), 0);
200
+ const cropTokens = crops.reduce((n, c) => n + visionImageTokens(c.ours.box.w * c.zoom, c.ours.box.h * c.zoom)
201
+ + (c.reference ? visionImageTokens(c.reference.box.w * c.zoom, c.reference.box.h * c.zoom) : 0), 0);
202
+ return { pairs, crops, missing, imageTokens: pairTokens + cropTokens, referenceImageTokens };
203
+ }
@@ -0,0 +1,175 @@
1
+ import { CRITIC_RUBRIC_DIMENSIONS, CRITIC_RUBRIC_POLISH } from './critic-rubric.generated';
2
+ import { jsonBoolean, jsonClosedObject, jsonListOf, JsonSchema, jsonText } from './json-schema';
3
+ import { isPlainObject, PathIssue } from './shape-check';
4
+
5
+ /**
6
+ * THE AI DESIGNER'S CRITIC — its answer (ai-designer-plan §2d, AD3, AD-D18). Each round the critic reads the sheet (the
7
+ * reference beside ours, view by view, and zoomed crops) and answers ONE strict object: a score 0–10 and one line of
8
+ * evidence for each of the reference score's eight dimensions (`team/reference-score.md` §2, ported — never retyped —
9
+ * into `critic-rubric.generated.ts`), the polish bugs it saw (a bug a visitor would call broken caps the page), and the
10
+ * 1–3 changes that move the lowest score most, written as a brief for the revise step. The arithmetic — the design mean,
11
+ * the cap, the headline — is this file's, never the model's. Pure.
12
+ */
13
+
14
+ /** The eight dimensions, by the key the critic answers under — the rubric's order (a spec holds it to the port). */
15
+ export enum CriticDimension {
16
+ Colour = 'colour',
17
+ Type = 'type',
18
+ Composition = 'composition',
19
+ Imagery = 'imagery',
20
+ Header = 'header',
21
+ Footer = 'footer',
22
+ Motion = 'motion',
23
+ Polish = 'polish',
24
+ }
25
+ export const CRITIC_DIMENSIONS: ReadonlyArray<CriticDimension> = Object.values(CriticDimension);
26
+ /** Dimensions 1–7: the headline is their mean. */
27
+ export const CRITIC_DESIGN_DIMENSIONS: ReadonlyArray<CriticDimension> = CRITIC_DIMENSIONS.filter(d => d !== CriticDimension.Polish);
28
+ /** A score is 0–10 in half points, as the tester scores. */
29
+ export const CRITIC_SCORE = { min: 0, max: 10, step: 0.5 } as const;
30
+ /** How many changes a critique gives the revise step. */
31
+ export const CRITIC_CHANGES = { min: 1, max: 3 } as const;
32
+ /** The answer's format name (the request's output). */
33
+ export const CRITIC_OUTPUT_NAME = 'critique';
34
+
35
+ export interface CriticScore {
36
+ score: number;
37
+ /** One line, read off the sheet as a position, a size or a colour: "<reference> does X; ours does Y". */
38
+ evidence: string;
39
+ }
40
+ export interface CriticBug {
41
+ what: string;
42
+ /** A visitor would call it broken (a 404, text over text, a dead button): the page is capped. */
43
+ broken: boolean;
44
+ }
45
+ export interface CriticChange {
46
+ dimension: CriticDimension;
47
+ /** What the revise step should do, in our own terms — never "make it look like the reference". */
48
+ brief: string;
49
+ }
50
+ export interface CriticAnswer {
51
+ scores: Record<CriticDimension, CriticScore>;
52
+ bugs: CriticBug[];
53
+ changes: CriticChange[];
54
+ }
55
+
56
+ /** The critic's strict output format: every property required, every object closed (`strictSchemaComplexity`). */
57
+ export function criticAnswerSchema(): JsonSchema {
58
+ const score = jsonClosedObject(
59
+ { score: { type: 'number', description: `0–10 in half points.` }, evidence: { ...jsonText(), description: 'One line read off the sheet: a position, a size or a colour, the reference\'s and ours.' } },
60
+ ['score', 'evidence'],
61
+ );
62
+ const byName = Object.fromEntries(CRITIC_RUBRIC_DIMENSIONS.map(d => [d.key, { ...score, description: `${d.name}: ${d.compares}` }]));
63
+ return jsonClosedObject({
64
+ scores: jsonClosedObject(byName, CRITIC_RUBRIC_DIMENSIONS.map(d => d.key), 'One score per dimension of the rubric.'),
65
+ bugs: jsonListOf(jsonClosedObject({ what: jsonText(), broken: jsonBoolean() }, ['what', 'broken'], 'A polish bug; broken = a visitor would call it broken.')),
66
+ changes: jsonListOf(jsonClosedObject(
67
+ { dimension: { type: 'string', enum: [...CRITIC_DIMENSIONS] }, brief: jsonText() }, ['dimension', 'brief'],
68
+ `${CRITIC_CHANGES.min}–${CRITIC_CHANGES.max} changes that move the lowest score most, as a brief for the next round.`,
69
+ )),
70
+ }, ['scores', 'bugs', 'changes'], 'The critique of one page.');
71
+ }
72
+
73
+ export enum CriticIssueCode {
74
+ /** Not the answer's shape. */
75
+ Shape = 'shape',
76
+ /** A score outside 0–10 or not in half points. */
77
+ Range = 'range',
78
+ /** Evidence that is not one line read off the sheet (no position, size or colour in it). */
79
+ Evidence = 'evidence',
80
+ /** Not 1–3 changes, or none aimed at the lowest score. */
81
+ Changes = 'changes',
82
+ /** A polish score above what its bugs leave. */
83
+ Polish = 'polish',
84
+ /** A brief that asks for resemblance (AD-D18): the reference's name, "copy", "look like". */
85
+ Likeness = 'likeness',
86
+ }
87
+ export type CriticIssue = PathIssue<CriticIssueCode>;
88
+
89
+ export interface CriticContext {
90
+ /** The reference the page is scored against (its name, as the cards are named: `graya-institute`). */
91
+ reference: string;
92
+ }
93
+
94
+ /** A measurement: a number (a size, a position, a share) or a hex colour. */
95
+ const MEASURED = /\d/;
96
+ const LIKENESS_WORDS = /\b(copy|copies|copying|mimic|replicate|imitate|clone|look(?:s|ing)? like|same as|just like)\b/i;
97
+ const MIN_NAME_PART = 4;
98
+
99
+ /** The words of a reference's name a brief may not say (`graya-institute` → graya, institute). */
100
+ const nameParts = (reference: string) => reference.toLowerCase().split(/[^a-z0-9]+/).filter(p => p.length >= MIN_NAME_PART);
101
+
102
+ /** Why an answer is not a usable critique, each reason with its path. The one gate between the model and the loop. */
103
+ export function criticAnswerIssues(answer: unknown, ctx: CriticContext): CriticIssue[] {
104
+ const out: CriticIssue[] = [];
105
+ const say = (code: CriticIssueCode, path: string, message: string) => out.push({ code, path, message });
106
+ if (!isPlainObject(answer) || !isPlainObject(answer['scores']) || !Array.isArray(answer['bugs']) || !Array.isArray(answer['changes'])) {
107
+ say(CriticIssueCode.Shape, '', 'a critique is { scores, bugs, changes }');
108
+ return out;
109
+ }
110
+ const scores = answer['scores'];
111
+ for (const d of CRITIC_DIMENSIONS) {
112
+ const s = scores[d];
113
+ const path = `scores.${d}`;
114
+ if (!isPlainObject(s) || typeof s['score'] !== 'number' || typeof s['evidence'] !== 'string') { say(CriticIssueCode.Shape, path, 'a score and its evidence'); continue; }
115
+ const v = s['score'];
116
+ if (v < CRITIC_SCORE.min || v > CRITIC_SCORE.max || !Number.isInteger(v / CRITIC_SCORE.step)) say(CriticIssueCode.Range, `${path}.score`, `0–10 in half points, not ${v}`);
117
+ const evidence = s['evidence'].trim();
118
+ if (!evidence || /\n/.test(evidence) || !MEASURED.test(evidence)) {
119
+ say(CriticIssueCode.Evidence, `${path}.evidence`, 'one line read off the sheet — a position, a size or a colour, the reference\'s and ours');
120
+ }
121
+ }
122
+ const bugs = answer['bugs'] as unknown[];
123
+ bugs.forEach((b, i) => {
124
+ if (!isPlainObject(b) || typeof b['what'] !== 'string' || typeof b['broken'] !== 'boolean') say(CriticIssueCode.Shape, `bugs[${i}]`, 'a bug is { what, broken }');
125
+ });
126
+ const polish = (scores[CriticDimension.Polish] as { score?: unknown } | undefined)?.score;
127
+ const allowed = CRITIC_SCORE.max - CRITIC_RUBRIC_POLISH.bugPenalty * bugs.length;
128
+ if (typeof polish === 'number' && polish > allowed) say(CriticIssueCode.Polish, `scores.${CriticDimension.Polish}.score`, `${bugs.length} bug(s) leave at most ${allowed}`);
129
+ const changes = answer['changes'] as unknown[];
130
+ if (changes.length < CRITIC_CHANGES.min || changes.length > CRITIC_CHANGES.max) say(CriticIssueCode.Changes, 'changes', `${CRITIC_CHANGES.min}–${CRITIC_CHANGES.max} changes, not ${changes.length}`);
131
+ const names = nameParts(ctx.reference);
132
+ changes.forEach((c, i) => {
133
+ const path = `changes[${i}]`;
134
+ if (!isPlainObject(c) || !CRITIC_DIMENSIONS.includes(c['dimension'] as CriticDimension) || typeof c['brief'] !== 'string' || !c['brief'].trim()) {
135
+ say(CriticIssueCode.Shape, path, 'a change is { dimension, brief }');
136
+ return;
137
+ }
138
+ const brief = c['brief'].toLowerCase();
139
+ const named = names.find(n => new RegExp(`\\b${n}\\b`).test(brief));
140
+ if (named || LIKENESS_WORDS.test(brief)) {
141
+ say(CriticIssueCode.Likeness, `${path}.brief`, 'a brief asks for the level, in our own terms — never the reference by name, never to copy or look like it (AD-D18)');
142
+ }
143
+ });
144
+ if (out.length) return out;
145
+ const lowest = lowestDimensions(answer as unknown as CriticAnswer);
146
+ if (!(changes as CriticChange[]).some(c => lowest.includes(c.dimension))) {
147
+ say(CriticIssueCode.Changes, 'changes', `no change is aimed at the lowest score (${lowest.join(', ')})`);
148
+ }
149
+ return out;
150
+ }
151
+
152
+ /** The dimensions holding the lowest score (ties together). */
153
+ export function lowestDimensions(answer: CriticAnswer): CriticDimension[] {
154
+ const low = Math.min(...CRITIC_DIMENSIONS.map(d => answer.scores[d].score));
155
+ return CRITIC_DIMENSIONS.filter(d => answer.scores[d].score === low);
156
+ }
157
+
158
+ export interface CriticVerdict {
159
+ /** The mean of dimensions 1–7. */
160
+ designMean: number;
161
+ polish: number;
162
+ /** How many bugs a visitor would call broken. */
163
+ broken: number;
164
+ /** The rubric's headline: the design mean, capped when a bug is broken. */
165
+ headline: number;
166
+ capped: boolean;
167
+ }
168
+
169
+ /** What a critique comes to, by the rubric's rule (`CRITIC_RUBRIC_HEADLINE`): the mean of 1–7, capped by a broken bug. */
170
+ export function criticVerdict(answer: CriticAnswer): CriticVerdict {
171
+ const designMean = CRITIC_DESIGN_DIMENSIONS.reduce((sum, d) => sum + answer.scores[d].score, 0) / CRITIC_DESIGN_DIMENSIONS.length;
172
+ const broken = answer.bugs.filter(b => b.broken).length;
173
+ const capped = broken > 0 && designMean > CRITIC_RUBRIC_POLISH.brokenCap;
174
+ return { designMean, polish: answer.scores[CriticDimension.Polish].score, broken, headline: capped ? CRITIC_RUBRIC_POLISH.brokenCap : designMean, capped };
175
+ }
@@ -0,0 +1,58 @@
1
+ import type { DesignDoc } from './design-ops.model';
2
+ import type { SerializedNode } from './serialized-node';
3
+
4
+ /**
5
+ * Where each node of a design document sits (AD1): the node, the list that holds it (the page's layout, the site's
6
+ * globals, or a parent's children) and that parent. `applyDesignOps` keeps it as it works; the static check reads it.
7
+ */
8
+ export interface DesignNodePlace {
9
+ node: SerializedNode;
10
+ list: SerializedNode[];
11
+ parent: SerializedNode | null;
12
+ }
13
+
14
+ export class DesignDocIndex {
15
+ private readonly places = new Map<string, DesignNodePlace>();
16
+
17
+ constructor(readonly doc: DesignDoc) {
18
+ this.rebuild();
19
+ }
20
+
21
+ /** Index every node again (after a move, a removal or a wrap). */
22
+ rebuild(): void {
23
+ this.places.clear();
24
+ this.addList(this.doc.layout, null);
25
+ this.addList(this.doc.globals, null);
26
+ }
27
+
28
+ /** Index a node and its subtree, just inserted into `list` under `parent`. */
29
+ add(node: SerializedNode, list: SerializedNode[], parent: SerializedNode | null): void {
30
+ this.places.set(node.id, { node, list, parent });
31
+ if (node.children?.length) this.addList(node.children, node);
32
+ }
33
+
34
+ find(id: string): DesignNodePlace | undefined {
35
+ return this.places.get(id);
36
+ }
37
+
38
+ has(id: string): boolean {
39
+ return this.places.has(id);
40
+ }
41
+
42
+ /** Every node, in no promised order. */
43
+ nodes(): SerializedNode[] {
44
+ return [...this.places.values()].map(p => p.node);
45
+ }
46
+
47
+ /** Whether `id` is `ancestor` or sits inside it. */
48
+ within(id: string, ancestor: string): boolean {
49
+ for (let at = this.places.get(id); at; at = at.parent ? this.places.get(at.parent.id) : undefined) {
50
+ if (at.node.id === ancestor) return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+ private addList(list: SerializedNode[], parent: SerializedNode | null): void {
56
+ for (const node of list) this.add(node, list, parent);
57
+ }
58
+ }