@vectoriox/iox-ui 5.121.0 → 5.122.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/assist-core/index.d.ts +123 -13
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +322 -14
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assist-core/assist-turn.ts +5 -4
- package/src/assist-core/brief.ts +2 -0
- package/src/assist-core/page-edits.ts +20 -8
- package/src/assist-core/page-style.ts +5 -3
- package/src/assist-core/page-words.ts +7 -1
- package/src/assist-core/public-api.ts +1 -0
- package/src/assist-core/site-look.ts +321 -0
- package/src/assist-core/surfaces.ts +6 -3
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { FieldEdit } from './fields-schema';
|
|
|
7
7
|
import { SectionChange, SectionEdit } from './page-sections';
|
|
8
8
|
import { PageChangeOp, SchemeEdit, SizeEdit, StyleChange, StyleEdit } from './page-style';
|
|
9
9
|
import { WordChange, WordEdit } from './page-words';
|
|
10
|
+
import { SiteLookChange, SiteLookEdit } from './site-look';
|
|
10
11
|
import { ContentRecord, clipText } from './summarize-item';
|
|
11
12
|
import { AssistScope, AssistSurface, CommitKind, EditFamily, SURFACES, SurfaceStatus } from './surfaces';
|
|
12
13
|
|
|
@@ -66,13 +67,13 @@ export interface AssistTurnRequest {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/** What a turn proposes, per family: a field's value (`fields`), a part's words (`words`), an element's style or a section's scheme (`style`). */
|
|
69
|
-
export type AssistEdit = FieldEdit | WordEdit | StyleEdit | SchemeEdit | SizeEdit | SectionEdit;
|
|
70
|
+
export type AssistEdit = FieldEdit | WordEdit | StyleEdit | SchemeEdit | SizeEdit | SectionEdit | SiteLookEdit;
|
|
70
71
|
|
|
71
72
|
/** What a turn changed, as the card says it. */
|
|
72
|
-
export type AssistChange = FieldChange | WordChange | StyleChange | SectionChange;
|
|
73
|
+
export type AssistChange = FieldChange | WordChange | StyleChange | SectionChange | SiteLookChange;
|
|
73
74
|
|
|
74
|
-
const isLookChange = (c: AssistChange): c is StyleChange | SectionChange => 'op' in c
|
|
75
|
-
&& (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size || c.op === PageChangeOp.Section);
|
|
75
|
+
const isLookChange = (c: AssistChange): c is StyleChange | SectionChange | SiteLookChange => 'op' in c
|
|
76
|
+
&& (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size || c.op === PageChangeOp.Section || c.op === PageChangeOp.Look);
|
|
76
77
|
|
|
77
78
|
/** POST's 202 answer. */
|
|
78
79
|
export interface AssistTurnAccepted {
|
package/src/assist-core/brief.ts
CHANGED
|
@@ -65,6 +65,8 @@ export enum AssistIssueCode {
|
|
|
65
65
|
InventedFact = 'inventedFact',
|
|
66
66
|
/** A word this site must not use. */
|
|
67
67
|
AvoidWord = 'avoidWord',
|
|
68
|
+
/** A look whose colours fail the contrast audit in a mode the site is worn in (family `look`, R4). */
|
|
69
|
+
Contrast = 'contrast',
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export interface AssistIssue {
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
import type { DesignChoices } from '@vectoriox/iox-ui/design-core';
|
|
1
2
|
import { SerializedNode } from '@vectoriox/iox-ui/generation-core';
|
|
2
3
|
|
|
3
4
|
import { AssistIssue } from './brief';
|
|
4
5
|
import { applyWordEdits, SummarizedPage, WordChange, WordEdit, WordEditContext } from './page-words';
|
|
5
6
|
import { applySectionEdits, isSectionEdit, SectionChange, SectionEdit, SectionEditContext } from './page-sections';
|
|
6
|
-
import { applyStyleEdits, BaselineStyles, isSchemeEdit, isSizeEdit, isStyleEdit,
|
|
7
|
+
import { applyStyleEdits, BaselineStyles, isSchemeEdit, isSizeEdit, isStyleEdit, NodeStyleEdit, SchemeEdit, SizeEdit, StyleChange, StyleEdit } from './page-style';
|
|
8
|
+
import { applyLookEdits, isSiteLookEdit, SiteLookChange, SiteLookEdit } from './site-look';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Surface S1's answer as ONE thing (AI2b–AI2d): the edits of every family a page turn routed to — words (`{ handle, value }`),
|
|
10
12
|
* styles (`{ handle, style }`), schemes (`{ handle, scheme }`), size steps (`{ handle, axis, step }`), sections
|
|
11
13
|
* (`{ add | remove | move | swap }`) — applied in that order on a copy, all or none. Sections go last: every handle the
|
|
12
|
-
* other families name is read on the page as it stood. The
|
|
14
|
+
* other families name is read on the page as it stood. The site's look (`{ look }`, AI2e) changes no node: it is applied
|
|
15
|
+
* on `ctx.look` (the look the site wears) and comes back as `look`, the choices the trial wears. The server checks each family as it is asked; the builder's trial
|
|
13
16
|
* applies the turn's edits through this, so both read one rule.
|
|
14
17
|
*/
|
|
15
|
-
export type PageEdit = WordEdit | StyleEdit | SchemeEdit | SizeEdit | SectionEdit;
|
|
16
|
-
export type PageChange = WordChange | StyleChange | SectionChange;
|
|
18
|
+
export type PageEdit = WordEdit | StyleEdit | SchemeEdit | SizeEdit | SectionEdit | SiteLookEdit;
|
|
19
|
+
export type PageChange = WordChange | StyleChange | SectionChange | SiteLookChange;
|
|
17
20
|
|
|
18
21
|
export interface PageEditContext extends Omit<WordEditContext, 'handles' | 'never'> {
|
|
19
22
|
readonly summary: Pick<SummarizedPage, 'handles' | 'looks'> & Partial<Pick<SummarizedPage, 'sections'>> & { readonly brief: { readonly rules: { readonly never: WordEditContext['never'] } } };
|
|
@@ -22,6 +25,8 @@ export interface PageEditContext extends Omit<WordEditContext, 'handles' | 'neve
|
|
|
22
25
|
/** Family `sections`: the studio's name and pages (what the palette composes with) and the builder's fresh ids. */
|
|
23
26
|
readonly sectionInput?: SectionEditContext['input'];
|
|
24
27
|
readonly newId?: SectionEditContext['newId'];
|
|
28
|
+
/** Family `look`: the look the site wears (its stored choices); absent = the default look. */
|
|
29
|
+
readonly look?: DesignChoices | null;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export interface PageEditsOutcome {
|
|
@@ -29,21 +34,28 @@ export interface PageEditsOutcome {
|
|
|
29
34
|
readonly result: SerializedNode[];
|
|
30
35
|
readonly changes: ReadonlyArray<PageChange>;
|
|
31
36
|
readonly issues: ReadonlyArray<AssistIssue>;
|
|
37
|
+
/** Family `look`: the choices the turn's look wears — present only when the turn changed the look. */
|
|
38
|
+
readonly look?: DesignChoices;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
const isWordEdit = (e: PageEdit): e is WordEdit => 'value' in e;
|
|
35
|
-
const
|
|
42
|
+
const isNodeStyleEdit = (e: PageEdit): e is NodeStyleEdit => !isWordEdit(e) && !isSectionEdit(e) && !isSiteLookEdit(e) && (isStyleEdit(e) || isSchemeEdit(e) || isSizeEdit(e));
|
|
36
43
|
|
|
37
44
|
export function applyPageEdits(layout: ReadonlyArray<SerializedNode>, edits: ReadonlyArray<PageEdit>, ctx: PageEditContext): PageEditsOutcome {
|
|
38
45
|
const words = applyWordEdits(layout, edits.filter(isWordEdit), {
|
|
39
46
|
handles: ctx.summary.handles, never: ctx.summary.brief.rules.never, sentence: ctx.sentence, words: ctx.words,
|
|
40
47
|
});
|
|
41
|
-
const style = applyStyleEdits(words.result, edits.filter(
|
|
48
|
+
const style = applyStyleEdits(words.result, edits.filter(isNodeStyleEdit), { looks: ctx.summary.looks, baseline: ctx.baseline });
|
|
42
49
|
const sectionEdits = edits.filter(isSectionEdit);
|
|
43
50
|
const sections = sectionEdits.length
|
|
44
51
|
? applySectionEdits(style.result, sectionEdits, { sections: ctx.summary.sections ?? {}, input: ctx.sectionInput, newId: ctx.newId })
|
|
45
52
|
: { result: style.result, changes: [], issues: [] };
|
|
46
|
-
const
|
|
53
|
+
const lookEdits = edits.filter(isSiteLookEdit);
|
|
54
|
+
const look = lookEdits.length ? applyLookEdits(ctx.look, lookEdits) : null;
|
|
55
|
+
const issues = [...words.issues, ...style.issues, ...sections.issues, ...(look?.issues ?? [])];
|
|
47
56
|
if (issues.length) return { ok: false, result: JSON.parse(JSON.stringify(layout)) as SerializedNode[], changes: [], issues };
|
|
48
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
ok: true, result: sections.result, changes: [...words.changes, ...style.changes, ...sections.changes, ...(look?.changes ?? [])], issues: [],
|
|
59
|
+
...(look?.changes.length ? { look: look.choices } : {}),
|
|
60
|
+
};
|
|
49
61
|
}
|
|
@@ -286,7 +286,7 @@ export interface SizeEdit {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
/** Any edit of family `style`. */
|
|
289
|
-
export type
|
|
289
|
+
export type NodeStyleEdit = StyleEdit | SchemeEdit | SizeEdit;
|
|
290
290
|
|
|
291
291
|
const listOf = (answer: unknown, key: StyleAnswerKey): Array<Record<string, unknown>> => {
|
|
292
292
|
const list = answer && typeof answer === 'object' ? (answer as Record<string, unknown>)[key] : undefined;
|
|
@@ -294,7 +294,7 @@ const listOf = (answer: unknown, key: StyleAnswerKey): Array<Record<string, unkn
|
|
|
294
294
|
};
|
|
295
295
|
|
|
296
296
|
/** The answer → the edits it makes. */
|
|
297
|
-
export function decodeStyleAnswers(answers: ReadonlyArray<unknown>):
|
|
297
|
+
export function decodeStyleAnswers(answers: ReadonlyArray<unknown>): NodeStyleEdit[] {
|
|
298
298
|
return answers.flatMap(answer => [
|
|
299
299
|
...listOf(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
|
|
300
300
|
...listOf(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
|
|
@@ -313,6 +313,8 @@ export enum PageChangeOp {
|
|
|
313
313
|
Scheme = 'scheme',
|
|
314
314
|
Size = 'size',
|
|
315
315
|
Section = 'section',
|
|
316
|
+
/** The site's look (family `look`, AI2e) — every page follows. */
|
|
317
|
+
Look = 'look',
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
export interface StyleChange {
|
|
@@ -363,7 +365,7 @@ const styleLabel = (id: string) => elementStyleById(id)?.label ?? id;
|
|
|
363
365
|
* once by the server, never repaired here); an edit that changes nothing is dropped.
|
|
364
366
|
*/
|
|
365
367
|
export function applyStyleEdits(
|
|
366
|
-
layout: ReadonlyArray<SerializedNode>, edits: ReadonlyArray<
|
|
368
|
+
layout: ReadonlyArray<SerializedNode>, edits: ReadonlyArray<NodeStyleEdit>, ctx: StyleEditContext,
|
|
367
369
|
): StyleEditsOutcome {
|
|
368
370
|
const result = JSON.parse(JSON.stringify(layout)) as SerializedNode[];
|
|
369
371
|
const byId = new Map<string, SerializedNode>();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsonClosedObject, jsonListOf, JsonSchema, jsonText, SerializedNode, walkSerialized } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
import type { DesignChoices } from '@vectoriox/iox-ui/design-core';
|
|
2
3
|
|
|
3
4
|
import { assistFactIssues, AssistWordContext } from './assist-facts';
|
|
4
5
|
import { namedLocale } from './assist-locale';
|
|
@@ -6,6 +7,7 @@ import { assertAssistBudget, MAX_ASSIST_PROPERTIES } from './budget';
|
|
|
6
7
|
import { AssistIssue, AssistIssueCode, Brief, BriefRules, HandleMap, NeverWrite, resolveHandle } from './brief';
|
|
7
8
|
import { LookMap, lookNames, PageChangeOp, PageLook, pageLooks, sectionLabel } from './page-style';
|
|
8
9
|
import { askSectionPatternNames, SectionMap, sectionPatternOf } from './page-sections';
|
|
10
|
+
import { LookSummary, summarizeLook } from './site-look';
|
|
9
11
|
import { containsHtml, escapeText, paragraphsToRichText, richTextParagraphs } from './rich-text';
|
|
10
12
|
import { clipText } from './summarize-item';
|
|
11
13
|
import { AssistScope, AssistSurface, EditFamily, SURFACES } from './surfaces';
|
|
@@ -119,6 +121,8 @@ export interface PageAround {
|
|
|
119
121
|
readonly sections: ReadonlyArray<{ readonly handle: string; readonly label: string; readonly headline: string }>;
|
|
120
122
|
/** The site's other pages, by name. */
|
|
121
123
|
readonly pages: ReadonlyArray<string>;
|
|
124
|
+
/** Family `look`: the look the whole site wears, one readable value per axis (AI2e). */
|
|
125
|
+
readonly look?: LookSummary;
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
export type PageBrief = Brief<PageFocus, PageAround>;
|
|
@@ -133,6 +137,8 @@ export interface PageBriefContext {
|
|
|
133
137
|
readonly pages?: ReadonlyArray<string>;
|
|
134
138
|
readonly owner?: string | null;
|
|
135
139
|
readonly memory?: ReadonlyArray<string>;
|
|
140
|
+
/** The look the site wears (its stored choices) — said in the brief so "rounder", "darker", "calmer" read from it. */
|
|
141
|
+
readonly look?: DesignChoices | null;
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
export interface SummarizedPage {
|
|
@@ -309,7 +315,7 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
309
315
|
brief: {
|
|
310
316
|
surface: AssistSurface.BuilderPage,
|
|
311
317
|
focus,
|
|
312
|
-
around: { sections: around, pages: [...(ctx.pages ?? [])] },
|
|
318
|
+
around: { sections: around, pages: [...(ctx.pages ?? [])], ...(ctx.look ? { look: summarizeLook(ctx.look) } : {}) },
|
|
313
319
|
owner: ctx.owner ?? null,
|
|
314
320
|
rules,
|
|
315
321
|
memory: [...(ctx.memory ?? [])],
|
|
@@ -25,6 +25,7 @@ export * from './field-edits';
|
|
|
25
25
|
export * from './page-words';
|
|
26
26
|
export * from './page-style';
|
|
27
27
|
export * from './page-sections';
|
|
28
|
+
export * from './site-look';
|
|
28
29
|
export * from './page-edits';
|
|
29
30
|
export * from './assist-turn';
|
|
30
31
|
export * from './assist-locale';
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANIMATE_IDS, auditDesignContrast, BETWEEN_IDS, ContrastFinding, DesignChoices, DesignMode, designTokenRows, flavorPackById, parseHexColor,
|
|
3
|
+
presetChoices, resolveDesignChoices, ResolvedMode, SCROLL_IDS, SPEC_AXES, STYLE_PRESETS, stylePresetById, stylePresetOfChoices, TINT_IDS,
|
|
4
|
+
} from '@vectoriox/iox-ui/design-core';
|
|
5
|
+
import { jsonClosedObject, jsonOneOf, JsonSchema, jsonText } from '@vectoriox/iox-ui/generation-core';
|
|
6
|
+
|
|
7
|
+
import { assertAssistBudget } from './budget';
|
|
8
|
+
import { AssistIssue, AssistIssueCode } from './brief';
|
|
9
|
+
import { PageChangeOp } from './page-style';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Surface S1 (the builder), family `look` (ai-assist-plan §4 AI2e; ai-session-panel-plan `setLook` / `setMotion`): the
|
|
13
|
+
* SITE's look and motion — every page follows — changed only along the contract's own axes: a style preset, the brand
|
|
14
|
+
* colour, the background tint, corners, pill buttons, spacing, the type pairing, the colour mode, speed, scrolling, how
|
|
15
|
+
* animated and the change between pages. Never a token value, never CSS. A preset brings its whole look and keeps the
|
|
16
|
+
* site's own Scrolling · How animated · Between pages (MO-D3, as Design ▸ Look does); a type pairing is one of the worn
|
|
17
|
+
* style's own. The colour is checked by the SAME audit the contract gates every preset with (`auditDesignContrast`, in
|
|
18
|
+
* every mode the look is worn) — a colour that fails is refused, never worn (R4: the AA gate decides the colour).
|
|
19
|
+
* The SAME pure functions run on the server (the check) and in the builder (the trial through the Design side-card's
|
|
20
|
+
* own trial): `lookJsonSchema`, `decodeLookAnswers`, `applyLookEdits`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** One axis of the look, as the answer names it and the change card says it. */
|
|
24
|
+
export enum LookAxis {
|
|
25
|
+
Style = 'style',
|
|
26
|
+
Colour = 'colour',
|
|
27
|
+
Tint = 'tint',
|
|
28
|
+
Corners = 'corners',
|
|
29
|
+
Buttons = 'buttons',
|
|
30
|
+
Spacing = 'spacing',
|
|
31
|
+
Type = 'type',
|
|
32
|
+
Mode = 'mode',
|
|
33
|
+
Speed = 'speed',
|
|
34
|
+
Scrolling = 'scrolling',
|
|
35
|
+
Entrances = 'entrances',
|
|
36
|
+
Between = 'between',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How the card names each axis (the builder translates it by the axis). */
|
|
40
|
+
export const LOOK_AXIS_LABELS: Readonly<Record<LookAxis, string>> = {
|
|
41
|
+
[LookAxis.Style]: 'Style', [LookAxis.Colour]: 'Brand colour', [LookAxis.Tint]: 'Background tint', [LookAxis.Corners]: 'Corners',
|
|
42
|
+
[LookAxis.Buttons]: 'Buttons', [LookAxis.Spacing]: 'Spacing', [LookAxis.Type]: 'Fonts', [LookAxis.Mode]: 'Mode', [LookAxis.Speed]: 'Speed',
|
|
43
|
+
[LookAxis.Scrolling]: 'Scrolling', [LookAxis.Entrances]: 'How animated', [LookAxis.Between]: 'Between pages',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The axes in the order a card lists them (and the answer asks them). */
|
|
47
|
+
export const LOOK_AXES: ReadonlyArray<LookAxis> = Object.values(LookAxis);
|
|
48
|
+
|
|
49
|
+
/** The answer's extra key. Every axis is required; `''` keeps it as it is. */
|
|
50
|
+
export enum LookAnswerKey {
|
|
51
|
+
Note = 'note',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** "Keep it as it is" — strict outputs require every key. */
|
|
55
|
+
export const LOOK_KEEP = '';
|
|
56
|
+
|
|
57
|
+
/** `buttons`: pill-shaped or as the look draws them. */
|
|
58
|
+
export enum LookButtons {
|
|
59
|
+
Pill = 'pill',
|
|
60
|
+
Look = 'look',
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** How the owner reads a colour mode. */
|
|
64
|
+
export const MODE_LABELS: Readonly<Record<DesignMode, string>> = { light: 'Light', dark: 'Dark', auto: 'Follow the visitor' };
|
|
65
|
+
|
|
66
|
+
const BUTTON_LABELS: Readonly<Record<LookButtons, string>> = { [LookButtons.Pill]: 'Pill-shaped', [LookButtons.Look]: 'As the look draws them' };
|
|
67
|
+
|
|
68
|
+
/** The worn modes a colour is judged in (`auto` = both). */
|
|
69
|
+
const wornModes = (mode: DesignMode): ResolvedMode[] => (mode === 'auto' ? ['light', 'dark'] : [mode]);
|
|
70
|
+
|
|
71
|
+
const labelOf = (table: Readonly<Record<string, { readonly label: string }>>, id: string): string => table[id]?.label ?? id;
|
|
72
|
+
|
|
73
|
+
/** The type pairings of a flavor: id → its label ("Fraunces + Manrope"). */
|
|
74
|
+
function pairsOf(flavorId: string): ReadonlyArray<{ readonly id: string; readonly label: string }> {
|
|
75
|
+
return flavorPackById(flavorId)?.pairs ?? [];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A colour as the look stores it (`#RRGGBB`), or null. */
|
|
79
|
+
export function lookHex(value: string): string | null {
|
|
80
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((value ?? '').trim());
|
|
81
|
+
if (!m || !parseHexColor(value)) return null;
|
|
82
|
+
const h = m[1].length === 3 ? m[1].split('').map(c => c + c).join('') : m[1];
|
|
83
|
+
return `#${h.toUpperCase()}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** How the owner reads one axis of a set of choices. */
|
|
87
|
+
export function lookAxisValue(choices: DesignChoices, axis: LookAxis): { readonly id: string; readonly label: string } {
|
|
88
|
+
const c = resolveDesignChoices(choices);
|
|
89
|
+
switch (axis) {
|
|
90
|
+
case LookAxis.Style: {
|
|
91
|
+
const preset = stylePresetOfChoices(c);
|
|
92
|
+
const flavor = flavorPackById(c.flavorId)?.name ?? c.flavorId;
|
|
93
|
+
return preset ? { id: preset.id, label: preset.name } : { id: c.flavorId, label: `${flavor}, your own` };
|
|
94
|
+
}
|
|
95
|
+
case LookAxis.Colour: return { id: c.seed.toUpperCase(), label: c.seed.toUpperCase() };
|
|
96
|
+
case LookAxis.Tint: return { id: c.tint ?? '', label: labelOf(SPEC_AXES.tints, c.tint ?? '') };
|
|
97
|
+
case LookAxis.Corners: return { id: c.shape, label: labelOf(SPEC_AXES.shapes, c.shape) };
|
|
98
|
+
case LookAxis.Buttons: {
|
|
99
|
+
const id = c.pillButtons ? LookButtons.Pill : LookButtons.Look;
|
|
100
|
+
return { id, label: BUTTON_LABELS[id] };
|
|
101
|
+
}
|
|
102
|
+
case LookAxis.Spacing: return { id: c.density, label: labelOf(SPEC_AXES.densities, c.density) };
|
|
103
|
+
case LookAxis.Type: return { id: c.pairId, label: pairsOf(c.flavorId).find(p => p.id === c.pairId)?.label ?? c.pairId };
|
|
104
|
+
case LookAxis.Mode: return { id: c.mode, label: MODE_LABELS[c.mode] ?? c.mode };
|
|
105
|
+
case LookAxis.Speed: return { id: c.motion, label: labelOf(SPEC_AXES.motions, c.motion) };
|
|
106
|
+
case LookAxis.Scrolling: return { id: c.scroll ?? '', label: labelOf(SPEC_AXES.scrolls, c.scroll ?? '') };
|
|
107
|
+
case LookAxis.Entrances: return { id: c.animate ?? '', label: labelOf(SPEC_AXES.animations, c.animate ?? '') };
|
|
108
|
+
case LookAxis.Between: return { id: c.between ?? '', label: labelOf(SPEC_AXES.betweens, c.between ?? '') };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The look as the brief says it — one readable value per axis (the model reads the site's look before changing it). */
|
|
113
|
+
export type LookSummary = Readonly<Record<LookAxis, string>>;
|
|
114
|
+
|
|
115
|
+
export function summarizeLook(choices: DesignChoices): LookSummary {
|
|
116
|
+
return Object.fromEntries(LOOK_AXES.map(axis => [axis, lookAxisValue(choices, axis).label])) as LookSummary;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The ids an axis may take — what the strict format lists (`''` keeps it). Type: the worn style's own pairings. */
|
|
120
|
+
function axisOptions(axis: LookAxis, current: DesignChoices | null | undefined): ReadonlyArray<string> {
|
|
121
|
+
switch (axis) {
|
|
122
|
+
case LookAxis.Style: return STYLE_PRESETS.map(p => p.id);
|
|
123
|
+
case LookAxis.Colour: return [];
|
|
124
|
+
case LookAxis.Tint: return TINT_IDS;
|
|
125
|
+
case LookAxis.Corners: return Object.keys(SPEC_AXES.shapes);
|
|
126
|
+
case LookAxis.Buttons: return Object.values(LookButtons);
|
|
127
|
+
case LookAxis.Spacing: return Object.keys(SPEC_AXES.densities);
|
|
128
|
+
case LookAxis.Type: return pairsOf(resolveDesignChoices(current).flavorId).map(p => p.id);
|
|
129
|
+
case LookAxis.Mode: return SPEC_AXES.modes;
|
|
130
|
+
case LookAxis.Speed: return Object.keys(SPEC_AXES.motions);
|
|
131
|
+
case LookAxis.Scrolling: return SCROLL_IDS;
|
|
132
|
+
case LookAxis.Entrances: return ANIMATE_IDS;
|
|
133
|
+
case LookAxis.Between: return BETWEEN_IDS;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const options = (ids: ReadonlyArray<string>, says: (id: string) => string) => ids.map(id => `${id} = ${says(id)}`).join('; ');
|
|
138
|
+
|
|
139
|
+
/** What each axis's ids mean, in the format's own descriptions — read only when the look is asked. */
|
|
140
|
+
function axisDescription(axis: LookAxis, current: DesignChoices | null | undefined): string {
|
|
141
|
+
const keep = 'Empty string = keep it as it is.';
|
|
142
|
+
switch (axis) {
|
|
143
|
+
case LookAxis.Style:
|
|
144
|
+
return `A whole style for the site (colour, type, corners, spacing and speed together). ${keep} `
|
|
145
|
+
+ options(STYLE_PRESETS.map(p => p.id), id => {
|
|
146
|
+
const p = stylePresetById(id)!;
|
|
147
|
+
return `${p.name} (${p.moods.join(', ')}; ${p.modes.join('/')}): ${p.blurb}`;
|
|
148
|
+
});
|
|
149
|
+
case LookAxis.Colour:
|
|
150
|
+
return `The brand colour as #RRGGBB, only when the owner names or describes one ("our green", "#2E7D45"); every background, `
|
|
151
|
+
+ `button and link is derived from it and checked for contrast. ${keep}`;
|
|
152
|
+
case LookAxis.Tint: return `How much of the brand colour the backgrounds carry. ${keep} ${options(TINT_IDS, id => labelOf(SPEC_AXES.tints, id))}`;
|
|
153
|
+
case LookAxis.Corners: return `Corner roundness everywhere. ${keep} ${options(Object.keys(SPEC_AXES.shapes), id => labelOf(SPEC_AXES.shapes, id))}`;
|
|
154
|
+
case LookAxis.Buttons: return `Button shape. ${keep} ${options(Object.values(LookButtons), id => BUTTON_LABELS[id as LookButtons])}`;
|
|
155
|
+
case LookAxis.Spacing: return `Space around and between every section of the site. ${keep} ${options(Object.keys(SPEC_AXES.densities), id => labelOf(SPEC_AXES.densities, id))}`;
|
|
156
|
+
case LookAxis.Type: return `The site's fonts, as one of the pairings the current style offers. ${keep} ${options(axisOptions(axis, current), id => pairsOf(resolveDesignChoices(current).flavorId).find(p => p.id === id)?.label ?? id)}`;
|
|
157
|
+
case LookAxis.Mode: return `Light or dark site. ${keep} ${options(SPEC_AXES.modes, id => MODE_LABELS[id as DesignMode])}`;
|
|
158
|
+
case LookAxis.Speed: return `How fast buttons and cards respond and things move. ${keep} ${options(Object.keys(SPEC_AXES.motions), id => labelOf(SPEC_AXES.motions, id))}`;
|
|
159
|
+
case LookAxis.Scrolling: return `How the page scrolls. ${keep} ${options(SCROLL_IDS, id => `${labelOf(SPEC_AXES.scrolls, id)}: ${(SPEC_AXES.scrolls as Record<string, { hint: string }>)[id].hint}`)}`;
|
|
160
|
+
case LookAxis.Entrances: return `How content moves in as the visitor scrolls (the site's "how animated"). ${keep} ${options(ANIMATE_IDS, id => `${labelOf(SPEC_AXES.animations, id)}: ${(SPEC_AXES.animations as Record<string, { hint: string }>)[id].hint}`)}`;
|
|
161
|
+
case LookAxis.Between: return `What plays between pages. ${keep} ${options(BETWEEN_IDS, id => `${labelOf(SPEC_AXES.betweens, id)}: ${(SPEC_AXES.betweens as Record<string, { hint: string }>)[id].hint}`)}`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface LookSchemas {
|
|
166
|
+
/** One request: every axis plus a note. */
|
|
167
|
+
readonly parts: ReadonlyArray<JsonSchema>;
|
|
168
|
+
/** No handles — the look is the site's. */
|
|
169
|
+
readonly handles: ReadonlyArray<ReadonlyArray<string>>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Family `look`'s ONE strict format: every axis required, `''` keeps it; the ids listed and described from the contract. */
|
|
173
|
+
export function lookJsonSchema(current: DesignChoices | null | undefined): LookSchemas {
|
|
174
|
+
const properties: Record<string, JsonSchema> = {};
|
|
175
|
+
for (const axis of LOOK_AXES) {
|
|
176
|
+
const ids = axisOptions(axis, current);
|
|
177
|
+
properties[axis] = { ...(axis === LookAxis.Colour ? jsonText() : jsonOneOf([LOOK_KEEP, ...ids])), description: axisDescription(axis, current) };
|
|
178
|
+
}
|
|
179
|
+
properties[LookAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
|
|
180
|
+
const part = jsonClosedObject(properties, Object.keys(properties));
|
|
181
|
+
assertAssistBudget('look', [part]);
|
|
182
|
+
return { parts: [part], handles: [[]] };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The look the answer asks for — the axes it names, nothing else. */
|
|
186
|
+
export interface SiteLookEdit {
|
|
187
|
+
readonly look: Readonly<Partial<Record<LookAxis, string>>>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export const isSiteLookEdit = (e: unknown): e is SiteLookEdit => !!e && typeof e === 'object' && 'look' in e;
|
|
191
|
+
|
|
192
|
+
/** The answer as ONE edit (or none, when every axis is kept). */
|
|
193
|
+
export function decodeLookAnswers(answers: ReadonlyArray<unknown>): SiteLookEdit[] {
|
|
194
|
+
const look: Partial<Record<LookAxis, string>> = {};
|
|
195
|
+
for (const answer of answers) {
|
|
196
|
+
const a = (answer && typeof answer === 'object' ? answer : {}) as Record<string, unknown>;
|
|
197
|
+
for (const axis of LOOK_AXES) {
|
|
198
|
+
const v = typeof a[axis] === 'string' ? (a[axis] as string).trim() : '';
|
|
199
|
+
if (v) look[axis] = v;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return Object.keys(look).length ? [{ look }] : [];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** One axis the turn changed, as the card says it. */
|
|
206
|
+
export interface SiteLookChange {
|
|
207
|
+
readonly op: PageChangeOp.Look;
|
|
208
|
+
readonly axis: LookAxis;
|
|
209
|
+
/** The axis as the card names it ("Corners"). */
|
|
210
|
+
readonly label: string;
|
|
211
|
+
/** The ids, and how the owner reads them. */
|
|
212
|
+
readonly from: string;
|
|
213
|
+
readonly to: string;
|
|
214
|
+
readonly before: string;
|
|
215
|
+
readonly after: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface LookEditsOutcome {
|
|
219
|
+
readonly ok: boolean;
|
|
220
|
+
/** The look the trial wears (the current one when not ok). */
|
|
221
|
+
readonly choices: DesignChoices;
|
|
222
|
+
readonly changes: ReadonlyArray<SiteLookChange>;
|
|
223
|
+
readonly issues: ReadonlyArray<AssistIssue>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The axes `presetChoices` sets that the site keeps (MO-D3: a style pick in the builder keeps its motion). */
|
|
227
|
+
const SITE_MOTION = ['scroll', 'animate', 'between'] as const;
|
|
228
|
+
|
|
229
|
+
/** The first finding a failed audit names, as the owner reads it. */
|
|
230
|
+
const findingLine = (f: ContrastFinding) => `${f.element} ${f.part} on ${f.scheme} is ${f.ratio.toFixed(2)}:1 (needs ${f.min}:1)`;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The answer on the current look: a style first (its whole look, the site's motion kept, the mode kept when the style
|
|
234
|
+
* offers it), then every other axis named. Refused, all or none: an id the axis does not have, a colour that is not one,
|
|
235
|
+
* a pairing the style does not offer, a mode the style was not drawn in, and a colour, tint or mode that fails the contrast
|
|
236
|
+
* audit in a mode the site is worn in. A look that is exactly an audited style is not re-audited (the contract gated it).
|
|
237
|
+
*/
|
|
238
|
+
export function applyLookEdits(current: DesignChoices | null | undefined, edits: ReadonlyArray<SiteLookEdit>): LookEditsOutcome {
|
|
239
|
+
const before = resolveDesignChoices(current ?? null);
|
|
240
|
+
const asked: Partial<Record<LookAxis, string>> = Object.assign({}, ...edits.map(e => e.look));
|
|
241
|
+
const issues: AssistIssue[] = [];
|
|
242
|
+
const refuse = (axis: LookAxis, code: AssistIssueCode, message: string) => issues.push({ code, message: `${axis}: ${message}` });
|
|
243
|
+
const has = (axis: LookAxis) => typeof asked[axis] === 'string' && asked[axis] !== LOOK_KEEP;
|
|
244
|
+
const valid = (axis: LookAxis, ids: ReadonlyArray<string>): string | null => {
|
|
245
|
+
const v = asked[axis]!;
|
|
246
|
+
if (ids.includes(v)) return v;
|
|
247
|
+
refuse(axis, AssistIssueCode.NotAnOption, `"${v}" is not one of ${ids.join(', ')}`);
|
|
248
|
+
return null;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
let next: DesignChoices = { ...before };
|
|
252
|
+
const mode = has(LookAxis.Mode) ? valid(LookAxis.Mode, SPEC_AXES.modes) as DesignMode | null : null;
|
|
253
|
+
if (has(LookAxis.Style)) {
|
|
254
|
+
const id = valid(LookAxis.Style, STYLE_PRESETS.map(p => p.id));
|
|
255
|
+
const preset = id ? stylePresetById(id) : undefined;
|
|
256
|
+
if (preset) {
|
|
257
|
+
const wear = mode ?? (presetChoices(preset.id, before.mode) ? before.mode : undefined);
|
|
258
|
+
const look = presetChoices(preset.id, wear);
|
|
259
|
+
if (!look) {
|
|
260
|
+
refuse(LookAxis.Mode, AssistIssueCode.NotAnOption, `${preset.name} is drawn in ${preset.modes.join(' and ')} only, not ${MODE_LABELS[wear!]}`);
|
|
261
|
+
} else {
|
|
262
|
+
const { fonts: _drop, ...rest } = look;
|
|
263
|
+
next = { ...rest, ...Object.fromEntries(SITE_MOTION.map(k => [k, before[k]])) } as DesignChoices;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (has(LookAxis.Colour)) {
|
|
268
|
+
const hex = lookHex(asked[LookAxis.Colour]!);
|
|
269
|
+
if (hex) next = { ...next, seed: hex };
|
|
270
|
+
else refuse(LookAxis.Colour, AssistIssueCode.WrongType, `"${asked[LookAxis.Colour]}" is not a colour (#RRGGBB)`);
|
|
271
|
+
}
|
|
272
|
+
if (has(LookAxis.Tint)) { const v = valid(LookAxis.Tint, TINT_IDS); if (v) next = { ...next, tint: v as DesignChoices['tint'] }; }
|
|
273
|
+
if (has(LookAxis.Corners)) { const v = valid(LookAxis.Corners, Object.keys(SPEC_AXES.shapes)); if (v) next = { ...next, shape: v as DesignChoices['shape'] }; }
|
|
274
|
+
if (has(LookAxis.Buttons)) { const v = valid(LookAxis.Buttons, Object.values(LookButtons)); if (v) next = { ...next, pillButtons: v === LookButtons.Pill }; }
|
|
275
|
+
if (has(LookAxis.Spacing)) { const v = valid(LookAxis.Spacing, Object.keys(SPEC_AXES.densities)); if (v) next = { ...next, density: v as DesignChoices['density'] }; }
|
|
276
|
+
if (has(LookAxis.Type)) {
|
|
277
|
+
const pairs = pairsOf(next.flavorId);
|
|
278
|
+
const v = asked[LookAxis.Type]!;
|
|
279
|
+
if (pairs.some(p => p.id === v)) {
|
|
280
|
+
if (v !== next.pairId) {
|
|
281
|
+
const { fonts: _drop, ...rest } = next;
|
|
282
|
+
next = { ...rest, pairId: v };
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
refuse(LookAxis.Type, AssistIssueCode.NotAnOption, `"${v}" is not a pairing of ${flavorPackById(next.flavorId)?.name ?? next.flavorId} (${pairs.map(p => p.id).join(', ')})`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (mode) next = { ...next, mode };
|
|
289
|
+
if (has(LookAxis.Speed)) { const v = valid(LookAxis.Speed, Object.keys(SPEC_AXES.motions)); if (v) next = { ...next, motion: v as DesignChoices['motion'] }; }
|
|
290
|
+
if (has(LookAxis.Scrolling)) { const v = valid(LookAxis.Scrolling, SCROLL_IDS); if (v) next = { ...next, scroll: v as DesignChoices['scroll'] }; }
|
|
291
|
+
if (has(LookAxis.Entrances)) { const v = valid(LookAxis.Entrances, ANIMATE_IDS); if (v) next = { ...next, animate: v as DesignChoices['animate'] }; }
|
|
292
|
+
if (has(LookAxis.Between)) { const v = valid(LookAxis.Between, BETWEEN_IDS); if (v) next = { ...next, between: v as DesignChoices['between'] }; }
|
|
293
|
+
next = resolveDesignChoices(next);
|
|
294
|
+
|
|
295
|
+
// The AA gate decides the colour: judged where the look paints, in every mode the site is worn in.
|
|
296
|
+
const colourMoved = (['flavorId', 'seed', 'tint', 'mode'] as const).some(k => String(next[k] ?? '').toLowerCase() !== String(before[k] ?? '').toLowerCase());
|
|
297
|
+
if (!issues.length && colourMoved && !stylePresetOfChoices(next)) {
|
|
298
|
+
const rows = designTokenRows(next);
|
|
299
|
+
for (const worn of wornModes(next.mode)) {
|
|
300
|
+
const failed = auditDesignContrast(rows, worn).filter(f => !f.pass);
|
|
301
|
+
if (failed.length) {
|
|
302
|
+
const axis = has(LookAxis.Colour) ? LookAxis.Colour : has(LookAxis.Tint) ? LookAxis.Tint : LookAxis.Mode;
|
|
303
|
+
refuse(axis, AssistIssueCode.Contrast, `in ${MODE_LABELS[worn]} it does not pass contrast: ${findingLine(failed[0])}`
|
|
304
|
+
+ `${failed.length > 1 ? ` and ${failed.length - 1} more` : ''} — choose a ${worn === 'dark' ? 'lighter' : 'deeper'} colour or keep it`);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (issues.length) return { ok: false, choices: before, changes: [], issues };
|
|
310
|
+
|
|
311
|
+
const said = new Set<LookAxis>([...(has(LookAxis.Style) ? [LookAxis.Style] : []), ...LOOK_AXES.filter(has)]);
|
|
312
|
+
const changes: SiteLookChange[] = [];
|
|
313
|
+
for (const axis of LOOK_AXES) {
|
|
314
|
+
if (!said.has(axis)) continue;
|
|
315
|
+
const was = lookAxisValue(before, axis);
|
|
316
|
+
const now = lookAxisValue(next, axis);
|
|
317
|
+
if (was.id.toLowerCase() === now.id.toLowerCase() && was.label === now.label) continue;
|
|
318
|
+
changes.push({ op: PageChangeOp.Look, axis, label: LOOK_AXIS_LABELS[axis], from: was.id, to: now.id, before: was.label, after: now.label });
|
|
319
|
+
}
|
|
320
|
+
return { ok: true, choices: next, changes, issues: [] };
|
|
321
|
+
}
|
|
@@ -82,6 +82,7 @@ export enum AssistPermission {
|
|
|
82
82
|
PageDelete = 'page_delete',
|
|
83
83
|
StorageAll = 'storage_all',
|
|
84
84
|
ProductsAll = 'products_all',
|
|
85
|
+
SettingsAll = 'settings_all',
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
export enum SurfaceStatus {
|
|
@@ -116,14 +117,16 @@ const spec = (s: Omit<SurfaceSpec, 'perContentType' | 'readsPhotos'> & Partial<P
|
|
|
116
117
|
});
|
|
117
118
|
|
|
118
119
|
export const SURFACES: Readonly<Record<AssistSurface, SurfaceSpec>> = {
|
|
119
|
-
// S1 offers only the families the server answers (the route can never pick one it cannot)
|
|
120
|
-
//
|
|
120
|
+
// S1 offers only the families the server answers (the route can never pick one it cannot). The look is the SITE's: it
|
|
121
|
+
// needs what Design ▸ Apply needs — the design row (settings) and the token rows (pages) — and the builder commits it
|
|
122
|
+
// through Design's own Apply, never as a page history step.
|
|
121
123
|
[AssistSurface.BuilderPage]: spec({
|
|
122
124
|
surface: AssistSurface.BuilderPage,
|
|
123
|
-
families: [EditFamily.Words, EditFamily.Style, EditFamily.Sections],
|
|
125
|
+
families: [EditFamily.Words, EditFamily.Style, EditFamily.Sections, EditFamily.Look],
|
|
124
126
|
commit: CommitKind.BuilderStep,
|
|
125
127
|
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
126
128
|
permissions: [AssistPermission.PageUpdate],
|
|
129
|
+
familyPermissions: { [EditFamily.Look]: [AssistPermission.SettingsAll, AssistPermission.PageCreate] },
|
|
127
130
|
scopes: [AssistScope.Node, AssistScope.Section, AssistScope.Page],
|
|
128
131
|
status: SurfaceStatus.Built,
|
|
129
132
|
}),
|