@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.
- package/actions-core/index.d.ts +8 -1
- package/design-core/index.d.ts +62 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +8 -1
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +121 -11
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +5443 -293
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +381 -32
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +2368 -5
- package/index.d.ts +117 -12
- package/package.json +1 -1
- package/src/actions-core/element-actions.ts +9 -0
- package/src/design-core/contrast-audit.ts +93 -11
- package/src/design-core/flavor-spec.generated.ts +19 -0
- package/src/design-core/image-alt.ts +27 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/generation-core/audit-site.ts +17 -3
- package/src/generation-core/baseline-roles.ts +10 -6
- package/src/generation-core/check-free.ts +12 -2
- package/src/generation-core/check-layout.ts +3 -2
- package/src/generation-core/compose-free.ts +3 -1
- package/src/generation-core/compose-layout.ts +1 -1
- package/src/generation-core/compose-site.ts +29 -11
- package/src/generation-core/critic-calibration.ts +175 -0
- package/src/generation-core/critic-prompt.ts +153 -0
- package/src/generation-core/critic-rubric.generated.ts +24 -0
- package/src/generation-core/critic-sheet.ts +203 -0
- package/src/generation-core/critic.ts +175 -0
- package/src/generation-core/design-doc-index.ts +58 -0
- package/src/generation-core/design-motion.ts +247 -0
- package/src/generation-core/design-ops-check.ts +370 -0
- package/src/generation-core/design-ops-of.ts +200 -0
- package/src/generation-core/design-ops.model.ts +239 -0
- package/src/generation-core/design-ops.schema.ts +122 -0
- package/src/generation-core/design-ops.ts +361 -0
- package/src/generation-core/design-recipes.ts +58 -0
- package/src/generation-core/designer-brief.ts +81 -0
- package/src/generation-core/designer-direction.ts +248 -0
- package/src/generation-core/designer-estimate.ts +171 -0
- package/src/generation-core/designer-lessons.generated.ts +653 -0
- package/src/generation-core/designer-lessons.ts +153 -0
- package/src/generation-core/designer-stop.ts +94 -0
- package/src/generation-core/footer-free.ts +23 -2
- package/src/generation-core/footer-mix.ts +60 -14
- package/src/generation-core/layout-language.ts +2 -0
- package/src/generation-core/node-baselines.generated.ts +953 -10
- package/src/generation-core/public-api.ts +21 -0
- package/src/generation-core/site-spec.generated.ts +82 -10
- package/src/generation-core/social-links.ts +370 -0
- package/src/generation-core/structure-fingerprint.ts +565 -0
- package/src/generation-core/templates.ts +39 -3
- package/styles/iox-design.css +26 -1
- package/styles/iox-forms.css +22 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { applyElementStyle } from '@vectoriox/iox-ui/design-core';
|
|
2
|
+
|
|
3
|
+
import { DesignDocIndex } from './design-doc-index';
|
|
4
|
+
import { designMotionIssues, motionIssueKey, MotionIssue } from './design-motion';
|
|
5
|
+
import { DesignCheckContext, designOpIssues, DESIGN_PARAM_PREFIX, DESIGN_PICTURE_PROPS, designSceneTracks, designTraitSlots, DESIGN_WORD_PROPS } from './design-ops-check';
|
|
6
|
+
import {
|
|
7
|
+
ActDesignOp, DESIGN_BASE_LAYER, DESIGN_END_INDEX, DESIGN_FONTS_CHOICE, DESIGN_NO_STYLE, DESIGN_PAGE_PARENT, DESIGN_TRIGGER_META, DESIGN_WIDTHS, DesignDoc,
|
|
8
|
+
DesignIssueCode, DesignMeta, DesignOp, DesignOpRefusal, DesignOpsResult, DesignTool, DesignTurn, DesignValue, LookDesignOp, LookEditKind,
|
|
9
|
+
MoveDesignOp, MoveOp, PictureDesignOp, PlaceDesignOp, PlaceOp, SceneDesignOp, StyleDesignOp, WordsDesignOp,
|
|
10
|
+
} from './design-ops.model';
|
|
11
|
+
import { DESIGN_RECIPES, DesignRecipe, recipeOptionValue } from './design-recipes';
|
|
12
|
+
import { NODE_BASELINES } from './node-baselines.generated';
|
|
13
|
+
import { PatternGlobalPosition } from './patterns';
|
|
14
|
+
import { createSerializedNode, SerializedNode } from './serialized-node';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* ONE `applyDesignOps` (ai-designer-plan §2b, AD1, R-H1): the designer's tool calls applied to a page, as the builder
|
|
18
|
+
* would apply the same hands — the palette's `createSerializedNode`, the Style panel's slots, the Interactions panel's
|
|
19
|
+
* rows, the Scene timeline, typing, the Files box, Design ▸ Tokens, drag / delete / Wrap in. Pure: the input document is
|
|
20
|
+
* never touched; the same document and ops give the same result, byte for byte, whoever calls (the designer loop, the
|
|
21
|
+
* builder's right-click, the Ask panel).
|
|
22
|
+
*
|
|
23
|
+
* Every op is checked first (`designOpIssues`). A refused op is not applied: on the FIRST turn it is returned once, with
|
|
24
|
+
* its paths, for the model to repair; on the REPAIR turn it is dropped and logged (§2e). What it writes is an ordinary
|
|
25
|
+
* saved page, its keys in ONE order (`canonicalDesignNode`).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export interface DesignOpsOptions {
|
|
29
|
+
/** Which turn of the round this is (the first answer, or its one repair). */
|
|
30
|
+
turn?: DesignTurn;
|
|
31
|
+
/** The page runs right to left: a start side is the right. */
|
|
32
|
+
rtl?: boolean;
|
|
33
|
+
/** The content rules (tokens, facts, motion, page invariants). Without it only the shape and the slots are read. */
|
|
34
|
+
check?: DesignCheckContext;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A saved node's keys in the order the builder's serializer writes them (iox-cms-client `serializeBuilderToPageLayout`,
|
|
38
|
+
* page-layout.mapper.ts) — so a page the designer wrote saves unchanged through the builder; anything else after, as found. */
|
|
39
|
+
export const DESIGN_NODE_KEY_ORDER: ReadonlyArray<string> = [
|
|
40
|
+
'id', 'type', 'label', 'props', 'styleProps', 'stylePresetId', 'styleOverrides', 'stateStyles', 'stateTriggers', 'partStyles',
|
|
41
|
+
'responsive', 'symbolId', 'detachedSymbolId', 'interactionPresetId', 'elementStyle', 'role', 'itemKey', 'sceneTracks',
|
|
42
|
+
'scenePhoneTracks', 'bindings', 'interactions', 'isGlobal', 'globalPosition', 'children',
|
|
43
|
+
];
|
|
44
|
+
export const DESIGN_ROW_KEY_ORDER: ReadonlyArray<string> = ['id', 'trigger', 'range', 'actions'];
|
|
45
|
+
export const DESIGN_ACTION_KEY_ORDER: ReadonlyArray<string> = ['type', 'target', 'duration', 'delay', 'easing', 'once', 'params'];
|
|
46
|
+
export const DESIGN_TRACK_KEY_ORDER: ReadonlyArray<string> = ['prop', 'from', 'keys', 'ease', 'range'];
|
|
47
|
+
|
|
48
|
+
type Plain = Record<string, unknown>;
|
|
49
|
+
const isPlain = (v: unknown): v is Plain => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
50
|
+
const clone = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;
|
|
51
|
+
|
|
52
|
+
function ordered<T extends object>(obj: T, order: ReadonlyArray<string>): T {
|
|
53
|
+
const src = obj as Plain;
|
|
54
|
+
const out: Plain = {};
|
|
55
|
+
for (const key of order) if (key in src) out[key] = src[key];
|
|
56
|
+
for (const key of Object.keys(src)) if (!(key in out)) out[key] = src[key];
|
|
57
|
+
return out as T;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A node with its own keys, its rows', its actions' and its tracks' keys in ONE order (and its children likewise). The
|
|
62
|
+
* values inside `props`, `styleProps`, a state or a width keep their own order (CSS can read it). Pure.
|
|
63
|
+
*/
|
|
64
|
+
export function canonicalDesignNode(node: SerializedNode): SerializedNode {
|
|
65
|
+
const out = ordered(node, DESIGN_NODE_KEY_ORDER);
|
|
66
|
+
if (Array.isArray(out.interactions)) {
|
|
67
|
+
out.interactions = out.interactions.map(row => {
|
|
68
|
+
if (!isPlain(row)) return row;
|
|
69
|
+
const r = ordered(row, DESIGN_ROW_KEY_ORDER);
|
|
70
|
+
if (Array.isArray(r['actions'])) r['actions'] = (r['actions'] as unknown[]).map(a => (isPlain(a) ? ordered(a, DESIGN_ACTION_KEY_ORDER) : a));
|
|
71
|
+
return r;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
for (const key of ['sceneTracks', 'scenePhoneTracks'] as const) {
|
|
75
|
+
const tracks = out[key];
|
|
76
|
+
if (Array.isArray(tracks)) out[key] = tracks.map(t => (isPlain(t) ? ordered(t, DESIGN_TRACK_KEY_ORDER) : t));
|
|
77
|
+
}
|
|
78
|
+
if (out.children) out.children = out.children.map(canonicalDesignNode);
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** An input's value as the node holds it: a list, an object or a null travels as its JSON text and is read back. */
|
|
83
|
+
function inputValue(type: string, name: string, value: DesignValue['value']): unknown {
|
|
84
|
+
const baseline = NODE_BASELINES[type]?.props?.[name];
|
|
85
|
+
if (typeof value !== 'string' || typeof baseline === 'string') return value;
|
|
86
|
+
if (value === 'null') return null;
|
|
87
|
+
return recipeOptionValue(value);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const inputsOf = (type: string, values: ReadonlyArray<DesignValue>) =>
|
|
91
|
+
Object.fromEntries(values.filter(v => !v.name.startsWith('@')).map(v => [v.name, inputValue(type, v.name, v.value)]));
|
|
92
|
+
|
|
93
|
+
/** A layer fact: `''` forgets it. */
|
|
94
|
+
function setFact(node: SerializedNode, key: 'label' | 'role' | 'itemKey', value: DesignValue['value']): void {
|
|
95
|
+
if (value === '') delete node[key];
|
|
96
|
+
else node[key] = String(value);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function writeMeta(node: SerializedNode, values: ReadonlyArray<DesignValue>, placed: boolean): void {
|
|
100
|
+
for (const { name, value } of values) {
|
|
101
|
+
if (name === DesignMeta.Label) setFact(node, 'label', value);
|
|
102
|
+
else if (name === DesignMeta.Role) setFact(node, 'role', value);
|
|
103
|
+
else if (name === DesignMeta.ItemKey) setFact(node, 'itemKey', value);
|
|
104
|
+
else if (name === DesignMeta.Global) {
|
|
105
|
+
if (value === '') { delete node.isGlobal; delete node.globalPosition; } else { node.isGlobal = true; node.globalPosition = String(value) as `${PatternGlobalPosition}`; }
|
|
106
|
+
} else if (name === DesignMeta.Style && !placed) {
|
|
107
|
+
if (value === '' || value === DESIGN_NO_STYLE) delete node.elementStyle;
|
|
108
|
+
else applyElementStyle(node, String(value));
|
|
109
|
+
} else if (name.startsWith(DESIGN_TRIGGER_META)) {
|
|
110
|
+
const state = name.slice(DESIGN_TRIGGER_META.length);
|
|
111
|
+
node.stateTriggers ??= {};
|
|
112
|
+
if (value === '') delete node.stateTriggers[state];
|
|
113
|
+
else node.stateTriggers[state] = String(value);
|
|
114
|
+
if (!Object.keys(node.stateTriggers).length) delete node.stateTriggers;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The part a `place` op drops: the palette's new node (`createSerializedNode`, its empty-drop sizes released — the design
|
|
121
|
+
* owns the box), its inputs, its element style (`@style`: absent or `''` = the type's default for these inputs, `none` =
|
|
122
|
+
* none), and its layer facts.
|
|
123
|
+
*/
|
|
124
|
+
export function placedDesignNode(id: string, type: string, values: ReadonlyArray<DesignValue>): SerializedNode {
|
|
125
|
+
const style = values.find(v => v.name === DesignMeta.Style)?.value;
|
|
126
|
+
const elementStyle = style === undefined || style === '' ? undefined : style === DESIGN_NO_STYLE ? '' : String(style);
|
|
127
|
+
const node = createSerializedNode(id, type, inputsOf(type, values), elementStyle, { releaseLayoutDefaults: true });
|
|
128
|
+
writeMeta(node, values, true);
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
class DesignRun {
|
|
133
|
+
readonly index: DesignDocIndex;
|
|
134
|
+
|
|
135
|
+
constructor(readonly doc: DesignDoc, private readonly rtl: boolean) {
|
|
136
|
+
this.index = new DesignDocIndex(doc);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The list a part goes into: a parent's children, else the page (a global part: the site's globals). */
|
|
140
|
+
private listOf(parent: string, global: boolean): { list: SerializedNode[]; parent: SerializedNode | null } {
|
|
141
|
+
if (parent === DESIGN_PAGE_PARENT) return { list: global ? this.doc.globals : this.doc.layout, parent: null };
|
|
142
|
+
const p = this.index.find(parent)!.node;
|
|
143
|
+
return { list: p.children!, parent: p };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private insert(node: SerializedNode, parent: string, index: number): void {
|
|
147
|
+
const into = this.listOf(parent, !!node.isGlobal);
|
|
148
|
+
const at = index === DESIGN_END_INDEX || index < 0 || index > into.list.length ? into.list.length : index;
|
|
149
|
+
into.list.splice(at, 0, node);
|
|
150
|
+
this.index.add(node, into.list, into.parent);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
place(op: PlaceDesignOp): void {
|
|
154
|
+
if (op.op === PlaceOp.Set) {
|
|
155
|
+
const node = this.index.find(op.node)!.node;
|
|
156
|
+
Object.assign(node.props, inputsOf(node.type, op.values));
|
|
157
|
+
writeMeta(node, op.values, false);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (op.op === PlaceOp.Recipe) {
|
|
161
|
+
const options = Object.fromEntries(op.values.map(v => [v.name, recipeOptionValue(v.value)]));
|
|
162
|
+
const root = DESIGN_RECIPES[op.type as DesignRecipe](
|
|
163
|
+
s => createSerializedNode(`${op.node}-${s.key}`, s.type, { ...(s.props ?? {}) }, s.elementStyle ?? null), options) as unknown as SerializedNode;
|
|
164
|
+
const ids: string[] = [];
|
|
165
|
+
const collect = (n: SerializedNode) => { ids.push(n.id); n.children?.forEach(collect); };
|
|
166
|
+
collect(root);
|
|
167
|
+
const taken = ids.find((id, i) => this.index.has(id) || ids.indexOf(id) !== i);
|
|
168
|
+
if (taken) throw new Error(`the recipe's part "${taken}" is taken — choose another id`);
|
|
169
|
+
this.insert(root, op.parent, op.index);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.insert(placedDesignNode(op.node, op.type, op.values), op.parent, op.index);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
style(op: StyleDesignOp): void {
|
|
176
|
+
const node = this.index.find(op.node)!.node;
|
|
177
|
+
const values = op.traits.flatMap(t => designTraitSlots(node, op.layer, t, this.rtl));
|
|
178
|
+
if (op.layer === DESIGN_BASE_LAYER) {
|
|
179
|
+
for (const [name, value] of values) node.styleProps[name] = value;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const width = DESIGN_WIDTHS.includes(op.layer);
|
|
183
|
+
let layer: Plain;
|
|
184
|
+
if (width) {
|
|
185
|
+
node.responsive ??= {};
|
|
186
|
+
const bp = (node.responsive[op.layer] ??= {});
|
|
187
|
+
layer = (bp.styleProps ??= {});
|
|
188
|
+
} else {
|
|
189
|
+
node.stateStyles ??= {};
|
|
190
|
+
layer = (node.stateStyles[op.layer] ??= {});
|
|
191
|
+
}
|
|
192
|
+
for (const [name, value] of values) {
|
|
193
|
+
if (value === '') delete layer[name];
|
|
194
|
+
else layer[name] = value;
|
|
195
|
+
}
|
|
196
|
+
if (Object.keys(layer).length) return;
|
|
197
|
+
if (width) {
|
|
198
|
+
const bp = node.responsive![op.layer]!;
|
|
199
|
+
delete bp.styleProps;
|
|
200
|
+
if (!Object.keys(bp).length) delete node.responsive![op.layer];
|
|
201
|
+
if (!Object.keys(node.responsive!).length) delete node.responsive;
|
|
202
|
+
} else {
|
|
203
|
+
delete node.stateStyles![op.layer];
|
|
204
|
+
if (!Object.keys(node.stateStyles!).length) delete node.stateStyles;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
act(op: ActDesignOp): void {
|
|
209
|
+
const node = this.index.find(op.node)!.node;
|
|
210
|
+
const rows = node.interactions as Plain[];
|
|
211
|
+
const at = rows.findIndex(r => r['id'] === op.id);
|
|
212
|
+
if (!op.trigger) { rows.splice(at, 1); return; }
|
|
213
|
+
let row = rows[at];
|
|
214
|
+
if (!row) {
|
|
215
|
+
row = { id: op.id, trigger: op.trigger, actions: [] };
|
|
216
|
+
rows.push(row);
|
|
217
|
+
}
|
|
218
|
+
row['trigger'] = op.trigger;
|
|
219
|
+
if (op.range) row['range'] = op.range;
|
|
220
|
+
else delete row['range'];
|
|
221
|
+
if (!op.type) return;
|
|
222
|
+
const action: Plain = { type: op.type };
|
|
223
|
+
for (const { name, value } of op.values) {
|
|
224
|
+
if (name.startsWith(DESIGN_PARAM_PREFIX)) {
|
|
225
|
+
const params = (action['params'] ??= {}) as Plain;
|
|
226
|
+
params[name.slice(DESIGN_PARAM_PREFIX.length)] = value;
|
|
227
|
+
} else action[name] = value;
|
|
228
|
+
}
|
|
229
|
+
(row['actions'] as Plain[]).push(action);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
scene(op: SceneDesignOp): void {
|
|
233
|
+
const node = this.index.find(op.node)!.node;
|
|
234
|
+
const key = op.phone ? 'scenePhoneTracks' : 'sceneTracks';
|
|
235
|
+
node[key] = designSceneTracks(op.tracks);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
words(op: WordsDesignOp): void {
|
|
239
|
+
const node = this.index.find(op.node)!.node;
|
|
240
|
+
node.props[DESIGN_WORD_PROPS[node.type]] = op.text;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
picture(op: PictureDesignOp): void {
|
|
244
|
+
const node = this.index.find(op.node)!.node;
|
|
245
|
+
node.props[DESIGN_PICTURE_PROPS[node.type]] = op.src;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
look(op: LookDesignOp): void {
|
|
249
|
+
const look = this.doc.look;
|
|
250
|
+
if (op.kind === LookEditKind.Token) {
|
|
251
|
+
if (op.value === '') delete look.tokenEdits[op.name];
|
|
252
|
+
else look.tokenEdits[op.name] = op.value;
|
|
253
|
+
} else if (op.kind === LookEditKind.Choice) look.choices[op.name] = op.value;
|
|
254
|
+
else {
|
|
255
|
+
const fonts = (look.choices[DESIGN_FONTS_CHOICE] ??= {}) as Plain;
|
|
256
|
+
fonts[op.name] = op.value;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
move(op: MoveDesignOp): void {
|
|
261
|
+
const place = this.index.find(op.node)!;
|
|
262
|
+
const from = place.list.indexOf(place.node);
|
|
263
|
+
if (op.op === MoveOp.Remove) {
|
|
264
|
+
place.list.splice(from, 1);
|
|
265
|
+
} else if (op.op === MoveOp.Move) {
|
|
266
|
+
place.list.splice(from, 1);
|
|
267
|
+
this.insert(place.node, op.parent, op.index);
|
|
268
|
+
} else {
|
|
269
|
+
const wrapper = createSerializedNode(op.parent, op.type, {}, undefined, { releaseLayoutDefaults: true });
|
|
270
|
+
wrapper.children = [place.node];
|
|
271
|
+
if (place.node.isGlobal) { wrapper.isGlobal = true; wrapper.globalPosition = place.node.globalPosition; delete place.node.isGlobal; delete place.node.globalPosition; }
|
|
272
|
+
place.list.splice(from, 1, wrapper);
|
|
273
|
+
}
|
|
274
|
+
this.index.rebuild();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
apply(op: DesignOp): void {
|
|
278
|
+
switch (op.tool) {
|
|
279
|
+
case DesignTool.Place: return this.place(op as PlaceDesignOp);
|
|
280
|
+
case DesignTool.Style: return this.style(op as StyleDesignOp);
|
|
281
|
+
case DesignTool.Act: return this.act(op as ActDesignOp);
|
|
282
|
+
case DesignTool.Scene: return this.scene(op as SceneDesignOp);
|
|
283
|
+
case DesignTool.Words: return this.words(op as WordsDesignOp);
|
|
284
|
+
case DesignTool.Picture: return this.picture(op as PictureDesignOp);
|
|
285
|
+
case DesignTool.Look: return this.look(op as LookDesignOp);
|
|
286
|
+
case DesignTool.Move: return this.move(op as MoveDesignOp);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Apply a stream of designer ops to a page (`doc`: its layout, the site's globals, the look). Returns a NEW document, how
|
|
293
|
+
* many ops it applied, and the refused ones — to send back once (first turn) or the dropped ones (repair turn). Pure.
|
|
294
|
+
*/
|
|
295
|
+
export function applyDesignOps(doc: DesignDoc, ops: ReadonlyArray<DesignOp>, options: DesignOpsOptions = {}): DesignOpsResult {
|
|
296
|
+
const run = new DesignRun(clone(doc), !!options.rtl);
|
|
297
|
+
const refusals: DesignOpRefusal[] = [];
|
|
298
|
+
const tokens = options.check?.tokens;
|
|
299
|
+
// Emil's rules (R-H20): an act or a style op that ADDS a motion issue is refused like any other. What one node's
|
|
300
|
+
// rows and styles can break is read on its scope — the node with what it holds and its ancestors — before and after;
|
|
301
|
+
// what reaches further (an action aimed at a part elsewhere) is in the turn's page reading, `motion`.
|
|
302
|
+
const motionOf = (scope: SerializedNode) => designMotionIssues({ layout: [scope], globals: [] }, { tokens });
|
|
303
|
+
let applied = 0;
|
|
304
|
+
ops.forEach((op, i) => {
|
|
305
|
+
let issues = designOpIssues(op, i, run.index, options);
|
|
306
|
+
if (!issues.length) {
|
|
307
|
+
try {
|
|
308
|
+
const node = options.check && MOTION_TOOLS.has(op.tool) ? run.index.find((op as ActDesignOp | StyleDesignOp).node)?.node : undefined;
|
|
309
|
+
const before = node ? { node: clone(node), keys: new Set(motionOf(motionScope(run.index, node)).map(motionIssueKey)) } : undefined;
|
|
310
|
+
run.apply(op);
|
|
311
|
+
if (node && before) {
|
|
312
|
+
const added = motionOf(motionScope(run.index, node)).filter(m => !before.keys.has(motionIssueKey(m)));
|
|
313
|
+
if (added.length) {
|
|
314
|
+
restore(node, before.node);
|
|
315
|
+
refusals.push({ index: i, op, issues: added.map(m => ({ code: m.code, path: motionOpPath(op, i, m), message: `${m.message} (${m.path})` })) });
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
applied++;
|
|
320
|
+
return;
|
|
321
|
+
} catch (e) {
|
|
322
|
+
// The palette itself refused (an element style with no slot, a recipe whose parts collide): the same refusal.
|
|
323
|
+
issues = [{ code: DesignIssueCode.Shape, path: `ops[${i}]`, message: (e as Error).message }];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
refusals.push({ index: i, op, issues });
|
|
327
|
+
});
|
|
328
|
+
const repair = options.turn === DesignTurn.Repair;
|
|
329
|
+
const out: DesignDoc = { ...run.doc, layout: run.doc.layout.map(canonicalDesignNode), globals: run.doc.globals.map(canonicalDesignNode) };
|
|
330
|
+
return {
|
|
331
|
+
doc: out, applied, refused: repair ? [] : refusals, dropped: repair ? refusals : [],
|
|
332
|
+
...(options.check ? { motion: designMotionIssues(out, { tokens }) } : {}),
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** The ops whose motion the page check reads op by op: each changes one node's rows or styles. */
|
|
337
|
+
const MOTION_TOOLS: ReadonlySet<string> = new Set([DesignTool.Act, DesignTool.Style]);
|
|
338
|
+
|
|
339
|
+
/** What one node's motion rules read: the node with its subtree, inside a chain of its ancestors (each holding only it). */
|
|
340
|
+
function motionScope(index: DesignDocIndex, node: SerializedNode): SerializedNode {
|
|
341
|
+
let scope = node;
|
|
342
|
+
for (let at = index.find(node.id); at?.parent; at = index.find(at.parent.id)) scope = { ...at.parent, children: [scope] };
|
|
343
|
+
return scope;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Put a node back as it was (in place: the index holds it). */
|
|
347
|
+
function restore(node: SerializedNode, before: SerializedNode): void {
|
|
348
|
+
for (const key of Object.keys(node)) delete (node as unknown as Plain)[key];
|
|
349
|
+
Object.assign(node, before);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** A motion issue as the op's own path: the act's value it names (easing, duration) or its type; the style's trait. */
|
|
353
|
+
function motionOpPath(op: DesignOp, i: number, issue: MotionIssue): string {
|
|
354
|
+
const leaf = issue.path.slice(issue.path.lastIndexOf('.') + 1);
|
|
355
|
+
if (op.tool === DesignTool.Act) {
|
|
356
|
+
const j = (op as ActDesignOp).values.findIndex(v => v.name === leaf);
|
|
357
|
+
return j >= 0 ? `ops[${i}].values[${j}]` : `ops[${i}].type`;
|
|
358
|
+
}
|
|
359
|
+
const j = (op as StyleDesignOp).traits.findIndex(t => t.name === leaf);
|
|
360
|
+
return j >= 0 ? `ops[${i}].traits[${j}]` : `ops[${i}].traits`;
|
|
361
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildAccordionRecipe, buildCardRecipe, buildCarouselRecipe, buildCounterRecipe, buildDisclosureRecipe, buildLightboxRecipe,
|
|
3
|
+
buildMarqueeRecipe, buildReadingBarRecipe, buildSegmentedRecipe, buildSlideshowRecipe, buildTabsRecipe, CompositeNode,
|
|
4
|
+
CompositeNodeFactory,
|
|
5
|
+
} from '@vectoriox/iox-ui/composite-core';
|
|
6
|
+
import { buildSceneRecipe } from '@vectoriox/iox-ui/scene-core';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The palette recipes the designer may drop (`place` op `recipe`, ai-designer-plan §2b): the builder's own composite-core
|
|
10
|
+
* and scene-core recipe builders, by the name the tool uses — never a recipe of the designer's own. Each takes the op's
|
|
11
|
+
* values as its options object; an option that holds a list or an object arrives as its JSON text and is read back here.
|
|
12
|
+
* Its parts are ordinary nodes, made by the factory the caller hands in (`createSerializedNode`, ids `<prefix>-<key>`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export enum DesignRecipe {
|
|
16
|
+
Accordion = 'accordion',
|
|
17
|
+
Card = 'card',
|
|
18
|
+
Carousel = 'carousel',
|
|
19
|
+
Counter = 'counter',
|
|
20
|
+
Disclosure = 'disclosure',
|
|
21
|
+
Lightbox = 'lightbox',
|
|
22
|
+
Marquee = 'marquee',
|
|
23
|
+
ReadingBar = 'reading-bar',
|
|
24
|
+
Scene = 'scene',
|
|
25
|
+
Segmented = 'segmented',
|
|
26
|
+
Slideshow = 'slideshow',
|
|
27
|
+
Tabs = 'tabs',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type RecipeBuild = (create: CompositeNodeFactory, options: Record<string, unknown>) => CompositeNode;
|
|
31
|
+
|
|
32
|
+
// Each builder's options type is its own; the op hands a plain object (the builders read only what they know).
|
|
33
|
+
const asOptions = <T>(options: Record<string, unknown>): T => options as T;
|
|
34
|
+
|
|
35
|
+
export const DESIGN_RECIPES: Readonly<Record<DesignRecipe, RecipeBuild>> = {
|
|
36
|
+
[DesignRecipe.Accordion]: (c, o) => buildAccordionRecipe(c, asOptions(o)),
|
|
37
|
+
[DesignRecipe.Card]: (c, o) => buildCardRecipe(c, asOptions(o)),
|
|
38
|
+
[DesignRecipe.Carousel]: (c, o) => buildCarouselRecipe(c, asOptions(o)),
|
|
39
|
+
[DesignRecipe.Counter]: (c, o) => buildCounterRecipe(c, asOptions(o)),
|
|
40
|
+
[DesignRecipe.Disclosure]: (c, o) => buildDisclosureRecipe(c, asOptions(o)),
|
|
41
|
+
[DesignRecipe.Lightbox]: (c, o) => buildLightboxRecipe(c, asOptions(o)),
|
|
42
|
+
[DesignRecipe.Marquee]: (c, o) => buildMarqueeRecipe(c, asOptions(o)),
|
|
43
|
+
[DesignRecipe.ReadingBar]: c => buildReadingBarRecipe(c),
|
|
44
|
+
[DesignRecipe.Scene]: (c, o) => buildSceneRecipe(c, asOptions(o)) as unknown as CompositeNode,
|
|
45
|
+
[DesignRecipe.Segmented]: (c, o) => buildSegmentedRecipe(c, asOptions(o)),
|
|
46
|
+
[DesignRecipe.Slideshow]: (c, o) => buildSlideshowRecipe(c, asOptions(o)),
|
|
47
|
+
[DesignRecipe.Tabs]: (c, o) => buildTabsRecipe(c, asOptions(o)),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const isDesignRecipe = (name: string): name is DesignRecipe => Object.prototype.hasOwnProperty.call(DESIGN_RECIPES, name);
|
|
51
|
+
|
|
52
|
+
/** A recipe option's value as the builder wants it: a JSON list or object text read back, anything else as given. */
|
|
53
|
+
export function recipeOptionValue(value: unknown): unknown {
|
|
54
|
+
if (typeof value !== 'string') return value;
|
|
55
|
+
const text = value.trim();
|
|
56
|
+
if (!text.startsWith('[') && !text.startsWith('{')) return value;
|
|
57
|
+
try { return JSON.parse(text); } catch { return value; }
|
|
58
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CRITIC_DIMENSIONS, CriticAnswer, CriticDimension } from './critic';
|
|
2
|
+
import { FreedomIssue, FreedomIssueCode } from './structure-fingerprint';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A ROUND'S BRIEF (ai-designer-plan §2d–§2f, AD-D19, R-H23): what the revise step is told to do next, composed from
|
|
6
|
+
* - the gate's counts (§2f "the gate first": nothing else is worth a round while a page blocks or asks);
|
|
7
|
+
* - the critic's broken bugs (they cap the page at 5 — fixed before any score is chased);
|
|
8
|
+
* - `designFreedomIssues` — a COPY of the reference or a REPEAT of the kind's recent builds caps the page like a broken
|
|
9
|
+
* bug, and a styling change does not lift it: the brief DEMANDS a structural change (the order and the shapes of the
|
|
10
|
+
* sections);
|
|
11
|
+
* - the critic's 1–3 changes, each with its dimension's score now, and the lowest dimension;
|
|
12
|
+
* - the rules applied every round (§2f), always, in the same words.
|
|
13
|
+
* Pure: it writes words, it does not judge them.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export enum RoundRuleId {
|
|
17
|
+
Gate = 'gate',
|
|
18
|
+
Emil = 'emil',
|
|
19
|
+
ScreenBudget = 'screen-budget',
|
|
20
|
+
ScrollMoment = 'scroll-moment',
|
|
21
|
+
Phone = 'phone',
|
|
22
|
+
LineBreaks = 'line-breaks',
|
|
23
|
+
}
|
|
24
|
+
/** §2f, in the plan's words — each one cost a round in the proof. */
|
|
25
|
+
export const DESIGNER_ROUND_RULES: ReadonlyArray<{ readonly id: RoundRuleId; readonly rule: string }> = [
|
|
26
|
+
{ id: RoundRuleId.Gate, rule: 'The gate first: the legal pages the country requires (Israel: privacy + accessibility statement; terms where there is a form or a shop), alt text on every picture, colours as tokens only — 0 blocking and 0 asking in every language.' },
|
|
27
|
+
{ id: RoundRuleId.Emil, rule: 'Emil: hover and motion on transform and opacity only, one entrance per container, never two entrance actions on one element, exits faster than entrances, reduced motion gentler and not zero.' },
|
|
28
|
+
{ id: RoundRuleId.ScreenBudget, rule: 'A screen budget: an inner page ≤ 8 laptop screens; each repeated item in its own arrangement; no two neighbouring sections on one skeleton.' },
|
|
29
|
+
{ id: RoundRuleId.ScrollMoment, rule: 'One scroll moment per page (a Scene or a scroll-lit line).' },
|
|
30
|
+
{ id: RoundRuleId.Phone, rule: 'The phone is its own design: its first screen shows the page\'s picture when the page is about a place; stacked flex children give up their flex share; a phone Scene is as long as what moves on it.' },
|
|
31
|
+
{ id: RoundRuleId.LineBreaks, rule: 'Line breaks are written into the words: a non-breaking space between the last two words of every title, number runs isolated in Hebrew.' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export interface RoundBriefInput {
|
|
35
|
+
critique: CriticAnswer;
|
|
36
|
+
/** This round's copy / repeat findings (`designFreedomIssues` on the built page). */
|
|
37
|
+
freedom?: ReadonlyArray<FreedomIssue>;
|
|
38
|
+
gate?: { blocking: number; asking: number };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface RoundBrief {
|
|
42
|
+
/** A copy or a repeat: the next round must change the structure, not the styling. */
|
|
43
|
+
structural: boolean;
|
|
44
|
+
/** The dimension the critic scored lowest (the first in rubric order on a tie). */
|
|
45
|
+
lowest: CriticDimension;
|
|
46
|
+
/** The brief, first thing first; `text` is the lines joined. */
|
|
47
|
+
lines: string[];
|
|
48
|
+
text: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const FREEDOM_WORD: Readonly<Record<FreedomIssueCode, string>> = {
|
|
52
|
+
[FreedomIssueCode.Copy]: 'copies the reference',
|
|
53
|
+
[FreedomIssueCode.Repeat]: 'repeats a recent build',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** The next round's brief: the gate, the broken bugs, a structural demand when the page copies or repeats, the critic's
|
|
57
|
+
* changes, the lowest dimension, then the every-round rules. */
|
|
58
|
+
export function roundBrief(input: RoundBriefInput): RoundBrief {
|
|
59
|
+
const { critique } = input;
|
|
60
|
+
const freedom = input.freedom ?? [];
|
|
61
|
+
const lines: string[] = [];
|
|
62
|
+
const gate = input.gate;
|
|
63
|
+
if (gate && (gate.blocking > 0 || gate.asking > 0)) {
|
|
64
|
+
lines.push(`THE GATE FIRST: ${gate.blocking} blocking and ${gate.asking} asking — clear them before anything else; a page that blocks is not scored.`);
|
|
65
|
+
}
|
|
66
|
+
for (const bug of critique.bugs.filter(b => b.broken)) lines.push(`BROKEN (caps the page at 5): ${bug.what}`);
|
|
67
|
+
if (freedom.length > 0) {
|
|
68
|
+
lines.push('STRUCTURAL CHANGE REQUIRED — a styling change does not lift this cap: change the order and the shapes of the sections.');
|
|
69
|
+
for (const issue of freedom) lines.push(`- it ${FREEDOM_WORD[issue.code]} ("${issue.of}", distance ${issue.distance}): ${issue.message}`);
|
|
70
|
+
}
|
|
71
|
+
critique.changes.forEach((c, i) => {
|
|
72
|
+
const score = critique.scores[c.dimension as CriticDimension]?.score;
|
|
73
|
+
lines.push(`${i + 1}. [${c.dimension}${typeof score === 'number' ? ` ${score}` : ''}] ${c.brief}`);
|
|
74
|
+
});
|
|
75
|
+
const lowest = CRITIC_DIMENSIONS.reduce((low, d) => (critique.scores[d].score < critique.scores[low].score ? d : low), CRITIC_DIMENSIONS[0]);
|
|
76
|
+
lines.push(`Lowest: ${lowest} ${critique.scores[lowest].score} — ${critique.scores[lowest].evidence}`);
|
|
77
|
+
for (const bug of critique.bugs.filter(b => !b.broken)) lines.push(`Bug: ${bug.what}`);
|
|
78
|
+
lines.push('Every round:');
|
|
79
|
+
for (const r of DESIGNER_ROUND_RULES) lines.push(`- ${r.rule}`);
|
|
80
|
+
return { structural: freedom.length > 0, lowest, lines, text: lines.join('\n') };
|
|
81
|
+
}
|