@vectoriox/iox-ui 5.203.0 → 5.204.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +5165 -267
- 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 +2263 -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/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-mix.ts +3 -1
- package/src/generation-core/node-baselines.generated.ts +953 -10
- package/src/generation-core/public-api.ts +20 -0
- package/src/generation-core/site-spec.generated.ts +73 -11
- package/src/generation-core/social-links.ts +195 -2
- 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,370 @@
|
|
|
1
|
+
import { actionOfferedUnder, ActionGroup, COUNT_UP_TRIGGERS, ELEMENT_ACTION_DESCRIPTORS } from '@vectoriox/iox-ui/actions-core';
|
|
2
|
+
import { DesignTokenLike, elementStyleById } from '@vectoriox/iox-ui/design-core';
|
|
3
|
+
import { normalizeTracks, SceneProp } from '@vectoriox/iox-ui/scene-core';
|
|
4
|
+
|
|
5
|
+
import { FREE_HOVER_PROPS, FreeIssueCode, freeStyleIssues } from './check-free';
|
|
6
|
+
import { DesignDocIndex } from './design-doc-index';
|
|
7
|
+
import {
|
|
8
|
+
ActDesignOp, DESIGN_BASE_LAYER, DESIGN_LAYERS, DESIGN_NO_STYLE, DESIGN_PAGE_PARENT, DESIGN_STATES, DESIGN_TRIGGER_META, DESIGN_WIDTHS,
|
|
9
|
+
DesignDoc, DesignIssue, DesignIssueCode, DesignMeta, DesignOp, DesignSceneRow, DesignTool, DesignTrait, DesignValue, LookDesignOp,
|
|
10
|
+
LookEditKind, MoveDesignOp, MoveOp, PlaceDesignOp, PlaceOp, SceneDesignOp, StyleDesignOp,
|
|
11
|
+
} from './design-ops.model';
|
|
12
|
+
import { isDesignRecipe } from './design-recipes';
|
|
13
|
+
import { freeStyleToSlots } from './free-slots';
|
|
14
|
+
import { NODE_BASELINES } from './node-baselines.generated';
|
|
15
|
+
import { factIssues, PlanWordContext, WrittenText } from './plan-words';
|
|
16
|
+
import type { SerializedNode } from './serialized-node';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* THE DESIGNER'S STATIC CHECK (ai-designer-plan §2e, §2f, R-H3): every reason one op may not be applied, with the path of
|
|
20
|
+
* what it wrote, in words the model can act on in its one repair. Two kinds:
|
|
21
|
+
* - ALWAYS (the op's shape and the type's slots): a node that is not there, a parent that holds no children, a taken id,
|
|
22
|
+
* an input or a style trait the type has no control for — the builder could not hold it (`assertStyleSlots`' rule).
|
|
23
|
+
* - With a `DesignCheckContext` (the free tier's closed rules, reused — never forked): colours, fonts, radii, shadows and
|
|
24
|
+
* durations as the look's tokens, start / end sides, no window units (`freeStyleIssues`); a hover moves transform,
|
|
25
|
+
* opacity and colour only; actions from the catalog under a trigger that offers them, one entrance per element; Scene
|
|
26
|
+
* tracks the timeline keeps; words that hold only the owner's facts (`factIssues`); one h1, a slide only in a slider.
|
|
27
|
+
* Pure.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export interface DesignCheckContext {
|
|
31
|
+
/** The studio's token rows with their types (what a `var(--iox-…)` may name). */
|
|
32
|
+
tokens: ReadonlyArray<DesignTokenLike>;
|
|
33
|
+
/** The owner's facts and the words this site must not use. */
|
|
34
|
+
words: PlanWordContext;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The palette types this check names. */
|
|
38
|
+
enum T {
|
|
39
|
+
Heading = 'Heading',
|
|
40
|
+
Text = 'Text',
|
|
41
|
+
Link = 'Link',
|
|
42
|
+
Button = 'Button',
|
|
43
|
+
SubmitButton = 'SubmitButton',
|
|
44
|
+
Field = 'Field',
|
|
45
|
+
Image = 'Image',
|
|
46
|
+
Video = 'Video',
|
|
47
|
+
Slide = 'SliderSlide',
|
|
48
|
+
Slider = 'SliderContainer',
|
|
49
|
+
}
|
|
50
|
+
const LEVEL = 'level';
|
|
51
|
+
const ALT = 'alt';
|
|
52
|
+
const MOTION: ActionGroup = 'motion';
|
|
53
|
+
|
|
54
|
+
/** The input that holds a part's words (the `words` tool writes it). */
|
|
55
|
+
export const DESIGN_WORD_PROPS: Readonly<Record<string, string>> = {
|
|
56
|
+
[T.Heading]: 'content', [T.Text]: 'content', [T.Link]: 'label', [T.Button]: 'label', [T.SubmitButton]: 'label', [T.Field]: 'label',
|
|
57
|
+
[T.Image]: ALT, [T.Video]: 'title', [T.Slide]: 'caption',
|
|
58
|
+
};
|
|
59
|
+
/** The input that holds a part's picture (the `picture` tool writes it). */
|
|
60
|
+
export const DESIGN_PICTURE_PROPS: Readonly<Record<string, string>> = { [T.Image]: 'src', [T.Video]: 'src' };
|
|
61
|
+
/** Inputs a visitor reads — their words are checked for facts whichever tool writes them. */
|
|
62
|
+
export const DESIGN_SAID_PROPS: ReadonlyArray<string> = [
|
|
63
|
+
'content', 'label', 'alt', 'title', 'caption', 'ariaLabel', 'tooltip', 'placeholder', 'help', 'loadingLabel', 'sentLabel', 'description',
|
|
64
|
+
];
|
|
65
|
+
/** An Interactions-panel row's timing values; anything else is `params.<name>`. */
|
|
66
|
+
export const DESIGN_ACT_VALUES: ReadonlyArray<string> = ['target', 'duration', 'delay', 'easing', 'once'];
|
|
67
|
+
export const DESIGN_PARAM_PREFIX = 'params.';
|
|
68
|
+
/** The states a pointer drives: they move transform and opacity, and change colour tokens — never layout (Emil). */
|
|
69
|
+
export const DESIGN_POINTER_STATES: ReadonlyArray<string> = ['hover', 'active'];
|
|
70
|
+
/** The triggers that fire on their own: an element has at most one motion under them (one entrance per element). */
|
|
71
|
+
export const DESIGN_ENTRANCE_TRIGGERS: ReadonlyArray<string> = COUNT_UP_TRIGGERS;
|
|
72
|
+
const H1 = 'h1';
|
|
73
|
+
|
|
74
|
+
const SCENE_PROPS: ReadonlyArray<string> = Object.values(SceneProp);
|
|
75
|
+
const META_NAMES: ReadonlyArray<string> = Object.values(DesignMeta);
|
|
76
|
+
const isContainer = (type: string) => !!NODE_BASELINES[type]?.container;
|
|
77
|
+
const at = (i: number) => `ops[${i}]`;
|
|
78
|
+
|
|
79
|
+
/** The style values a layer holds now: the base, a width over the base, a state over the base. */
|
|
80
|
+
function heldAt(node: SerializedNode, layer: string): Record<string, unknown> {
|
|
81
|
+
if (layer === DESIGN_BASE_LAYER) return node.styleProps;
|
|
82
|
+
if (DESIGN_WIDTHS.includes(layer)) return { ...node.styleProps, ...(node.responsive?.[layer]?.styleProps ?? {}) };
|
|
83
|
+
return { ...node.styleProps, ...(node.stateStyles?.[layer] ?? {}) };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* One trait as the builder's controls hold it: a control the type has is written as given — since Batch C3 / C4 that
|
|
88
|
+
* includes a start / end inset (`insetInlineStart`, kept: it mirrors with the page) and one margin / padding side; an
|
|
89
|
+
* axis or a shorthand the builder has no control for is folded into the controls by the page's direction
|
|
90
|
+
* (`freeStyleToSlots`, the free tier's one table). `''` stays `''` (a width or a state forgets the value).
|
|
91
|
+
*/
|
|
92
|
+
export function designTraitSlots(node: SerializedNode, layer: string, trait: DesignTrait, rtl: boolean): Array<[string, string]> {
|
|
93
|
+
const slots = NODE_BASELINES[node.type]?.styleTraits ?? [];
|
|
94
|
+
if (slots.includes(trait.name)) return [[trait.name, trait.value]];
|
|
95
|
+
const held = Object.fromEntries(Object.entries(heldAt(node, layer)).map(([k, v]) => [k, String(v ?? '')]));
|
|
96
|
+
return Object.entries(freeStyleToSlots({ [trait.name]: trait.value }, { rtl, held }));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The values of a place / set op that are inputs (not layer facts). */
|
|
100
|
+
const inputsOf = (values: ReadonlyArray<DesignValue>) => values.filter(v => !v.name.startsWith('@'));
|
|
101
|
+
|
|
102
|
+
function metaIssues(values: ReadonlyArray<DesignValue>, type: string, path: string): DesignIssue[] {
|
|
103
|
+
const out: DesignIssue[] = [];
|
|
104
|
+
values.forEach((v, j) => {
|
|
105
|
+
if (!v.name.startsWith('@')) return;
|
|
106
|
+
const where = `${path}.values[${j}]`;
|
|
107
|
+
if (v.name.startsWith(DESIGN_TRIGGER_META)) {
|
|
108
|
+
const state = v.name.slice(DESIGN_TRIGGER_META.length);
|
|
109
|
+
if (!DESIGN_STATES.includes(state)) out.push({ code: DesignIssueCode.Shape, path: where, message: `"${state}" is not a state — ${DESIGN_STATES.join(', ')}` });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (!META_NAMES.includes(v.name)) { out.push({ code: DesignIssueCode.Shape, path: where, message: `"${v.name}" is not a layer fact — ${META_NAMES.join(', ')}, ${DESIGN_TRIGGER_META}<state>` }); return; }
|
|
113
|
+
if (v.name === DesignMeta.Style && v.value !== '' && v.value !== DESIGN_NO_STYLE && !elementStyleById(String(v.value))?.appliesTo.includes(type)) {
|
|
114
|
+
out.push({ code: DesignIssueCode.Slot, path: where, message: `element style "${v.value}" does not apply to a ${type}` });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function inputIssues(values: ReadonlyArray<DesignValue>, type: string, path: string): DesignIssue[] {
|
|
121
|
+
// The inputs the type's panels hold: its own, and the hidden ones its composites edit (a marquee's speed, a header's ground).
|
|
122
|
+
const inputs = NODE_BASELINES[type]?.traits ?? [];
|
|
123
|
+
const out: DesignIssue[] = [];
|
|
124
|
+
values.forEach((v, j) => {
|
|
125
|
+
if (v.name.startsWith('@')) return;
|
|
126
|
+
if (!inputs.includes(v.name)) out.push({ code: DesignIssueCode.Slot, path: `${path}.values[${j}]`, message: `a ${type} has no input "${v.name}" — ${inputs.join(', ') || 'none'}` });
|
|
127
|
+
});
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function parentIssues(index: DesignDocIndex, parent: string, path: string): DesignIssue[] {
|
|
132
|
+
if (parent === DESIGN_PAGE_PARENT) return [];
|
|
133
|
+
const p = index.find(parent);
|
|
134
|
+
if (!p) return [{ code: DesignIssueCode.Shape, path: `${path}.parent`, message: `no part "${parent}" on this page` }];
|
|
135
|
+
if (!p.node.children) return [{ code: DesignIssueCode.Shape, path: `${path}.parent`, message: `a ${p.node.type} holds no parts` }];
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function nodeIssue(index: DesignDocIndex, id: string, path: string): DesignIssue[] {
|
|
140
|
+
return index.has(id) ? [] : [{ code: DesignIssueCode.Shape, path: `${path}.node`, message: `no part "${id}" on this page` }];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function placeShape(op: PlaceDesignOp, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
144
|
+
const out: DesignIssue[] = [];
|
|
145
|
+
if (op.op === PlaceOp.Set) {
|
|
146
|
+
const place = index.find(op.node);
|
|
147
|
+
if (!place) return nodeIssue(index, op.node, path);
|
|
148
|
+
return [...metaIssues(op.values, place.node.type, path), ...inputIssues(op.values, place.node.type, path)];
|
|
149
|
+
}
|
|
150
|
+
if (!op.node) out.push({ code: DesignIssueCode.Shape, path: `${path}.node`, message: 'a new part needs an id' });
|
|
151
|
+
else if (index.has(op.node)) out.push({ code: DesignIssueCode.Shape, path: `${path}.node`, message: `"${op.node}" is taken — a new part needs a new id` });
|
|
152
|
+
out.push(...parentIssues(index, op.parent, path));
|
|
153
|
+
if (op.op === PlaceOp.Recipe) {
|
|
154
|
+
if (!isDesignRecipe(op.type)) out.push({ code: DesignIssueCode.Recipe, path: `${path}.type`, message: `"${op.type}" is not a palette recipe` });
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
if (op.op !== PlaceOp.Place) return [{ code: DesignIssueCode.Shape, path: `${path}.op`, message: 'place | recipe | set' }];
|
|
158
|
+
if (!NODE_BASELINES[op.type]) return [...out, { code: DesignIssueCode.Shape, path: `${path}.type`, message: `"${op.type}" is not a part of the palette — ${Object.keys(NODE_BASELINES).join(', ')}` }];
|
|
159
|
+
return [...out, ...metaIssues(op.values, op.type, path), ...inputIssues(op.values, op.type, path)];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function styleShape(op: StyleDesignOp, path: string, index: DesignDocIndex, rtl: boolean): DesignIssue[] {
|
|
163
|
+
const place = index.find(op.node);
|
|
164
|
+
if (!place) return nodeIssue(index, op.node, path);
|
|
165
|
+
if (!DESIGN_LAYERS.includes(op.layer)) return [{ code: DesignIssueCode.Shape, path: `${path}.layer`, message: `"${op.layer}" is not a layer — ${DESIGN_LAYERS.join(', ')}` }];
|
|
166
|
+
const slots = NODE_BASELINES[place.node.type]?.styleTraits ?? [];
|
|
167
|
+
const out: DesignIssue[] = [];
|
|
168
|
+
op.traits.forEach((t, j) => {
|
|
169
|
+
const missing = designTraitSlots(place.node, op.layer, t, rtl).map(([k]) => k).filter(k => !slots.includes(k));
|
|
170
|
+
if (missing.length) out.push({ code: DesignIssueCode.Slot, path: `${path}.traits[${j}]`, message: `a ${place.node.type} has no style control "${missing.join('", "')}"${missing[0] === t.name ? '' : ` (what "${t.name}" becomes)`}` });
|
|
171
|
+
});
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function actShape(op: ActDesignOp, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
176
|
+
const place = index.find(op.node);
|
|
177
|
+
if (!place) return nodeIssue(index, op.node, path);
|
|
178
|
+
if (!op.id) return [{ code: DesignIssueCode.Shape, path: `${path}.id`, message: 'a row needs an id' }];
|
|
179
|
+
if (!op.trigger && !(place.node.interactions as Array<{ id?: string }>).some(r => r.id === op.id)) {
|
|
180
|
+
return [{ code: DesignIssueCode.Shape, path: `${path}.id`, message: `no row "${op.id}" to remove` }];
|
|
181
|
+
}
|
|
182
|
+
const out: DesignIssue[] = [];
|
|
183
|
+
op.values.forEach((v, j) => {
|
|
184
|
+
if (!DESIGN_ACT_VALUES.includes(v.name) && !(v.name.startsWith(DESIGN_PARAM_PREFIX) && v.name.length > DESIGN_PARAM_PREFIX.length)) {
|
|
185
|
+
out.push({ code: DesignIssueCode.Shape, path: `${path}.values[${j}]`, message: `"${v.name}" — ${DESIGN_ACT_VALUES.join(', ')} or ${DESIGN_PARAM_PREFIX}<name>` });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function sceneShape(op: SceneDesignOp, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
192
|
+
if (!index.has(op.node)) return nodeIssue(index, op.node, path);
|
|
193
|
+
const out: DesignIssue[] = [];
|
|
194
|
+
op.tracks.forEach((r, j) => {
|
|
195
|
+
if (!SCENE_PROPS.includes(r.prop)) out.push({ code: DesignIssueCode.Shape, path: `${path}.tracks[${j}].prop`, message: `"${r.prop}" — ${SCENE_PROPS.join(', ')}` });
|
|
196
|
+
});
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function propOpShape(node: string, table: Readonly<Record<string, string>>, what: string, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
201
|
+
const place = index.find(node);
|
|
202
|
+
if (!place) return nodeIssue(index, node, path);
|
|
203
|
+
return table[place.node.type] ? [] : [{ code: DesignIssueCode.Shape, path: `${path}.node`, message: `a ${place.node.type} has no ${what} — ${Object.keys(table).join(', ')}` }];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function lookShape(op: LookDesignOp, path: string): DesignIssue[] {
|
|
207
|
+
if (!(Object.values(LookEditKind) as string[]).includes(op.kind)) return [{ code: DesignIssueCode.Shape, path: `${path}.kind`, message: 'token | choice | font' }];
|
|
208
|
+
return op.name ? [] : [{ code: DesignIssueCode.Shape, path: `${path}.name`, message: 'a look edit needs a name' }];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function moveShape(op: MoveDesignOp, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
212
|
+
if (!index.has(op.node)) return nodeIssue(index, op.node, path);
|
|
213
|
+
if (op.op === MoveOp.Remove) return [];
|
|
214
|
+
if (op.op === MoveOp.Move) {
|
|
215
|
+
const out = parentIssues(index, op.parent, path);
|
|
216
|
+
if (!out.length && op.parent && index.within(op.parent, op.node)) out.push({ code: DesignIssueCode.Shape, path: `${path}.parent`, message: 'a part cannot go inside itself' });
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
if (op.op !== MoveOp.Wrap) return [{ code: DesignIssueCode.Shape, path: `${path}.op`, message: 'move | remove | wrap' }];
|
|
220
|
+
if (!op.parent || index.has(op.parent)) return [{ code: DesignIssueCode.Shape, path: `${path}.parent`, message: 'the wrapper needs a new id' }];
|
|
221
|
+
return isContainer(op.type) ? [] : [{ code: DesignIssueCode.Shape, path: `${path}.type`, message: `a ${op.type || '""'} cannot hold a part` }];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** What an op may not do whatever the context: its shape, and the controls its type has. */
|
|
225
|
+
function shapeIssues(op: DesignOp, path: string, index: DesignDocIndex, rtl: boolean): DesignIssue[] {
|
|
226
|
+
switch (op.tool) {
|
|
227
|
+
case DesignTool.Place: return placeShape(op as PlaceDesignOp, path, index);
|
|
228
|
+
case DesignTool.Style: return styleShape(op as StyleDesignOp, path, index, rtl);
|
|
229
|
+
case DesignTool.Act: return actShape(op as ActDesignOp, path, index);
|
|
230
|
+
case DesignTool.Scene: return sceneShape(op as SceneDesignOp, path, index);
|
|
231
|
+
case DesignTool.Words: return propOpShape(op.node, DESIGN_WORD_PROPS, 'words', path, index);
|
|
232
|
+
case DesignTool.Picture: return propOpShape(op.node, DESIGN_PICTURE_PROPS, 'picture', path, index);
|
|
233
|
+
case DesignTool.Look: return lookShape(op as LookDesignOp, path);
|
|
234
|
+
case DesignTool.Move: return moveShape(op as MoveDesignOp, path, index);
|
|
235
|
+
default: return [{ code: DesignIssueCode.Shape, path: `${path}.tool`, message: `not a tool — ${Object.values(DesignTool).join(', ')}` }];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ── the content rules (with a context) ──────────────────────────────────────────────────────────────────────────────
|
|
240
|
+
|
|
241
|
+
function said(texts: WrittenText[], ctx: DesignCheckContext): DesignIssue[] {
|
|
242
|
+
return factIssues(texts.filter(t => t.text.trim()), ctx.words).map(i => ({ code: DesignIssueCode.Fact, path: i.path, message: i.message }));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function styleRules(op: StyleDesignOp, path: string, ctx: DesignCheckContext): DesignIssue[] {
|
|
246
|
+
const out: DesignIssue[] = [];
|
|
247
|
+
op.traits.forEach((t, j) => {
|
|
248
|
+
if (t.value === '') return; // a width or a state forgetting a value
|
|
249
|
+
const where = `${path}.traits[${j}]`;
|
|
250
|
+
if (DESIGN_POINTER_STATES.includes(op.layer) && !FREE_HOVER_PROPS.includes(t.name)) {
|
|
251
|
+
out.push({ code: DesignIssueCode.Motion, path: where, message: `a ${op.layer} moves, scales, turns, fades or changes a colour token only (${FREE_HOVER_PROPS.join(', ')}) — never layout` });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
for (const i of freeStyleIssues({ [t.name]: t.value }, where, ctx, { anyProperty: true })) {
|
|
255
|
+
out.push({ code: i.code === FreeIssueCode.Token ? DesignIssueCode.Token : DesignIssueCode.Style, path: i.path, message: i.message });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const isEntrance = (trigger: string, type: string) =>
|
|
262
|
+
DESIGN_ENTRANCE_TRIGGERS.includes(trigger) && ELEMENT_ACTION_DESCRIPTORS.find(d => d.type === type)?.group === MOTION;
|
|
263
|
+
|
|
264
|
+
function actRules(op: ActDesignOp, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
265
|
+
if (!op.trigger || !op.type) return [];
|
|
266
|
+
const d = ELEMENT_ACTION_DESCRIPTORS.find(x => x.type === op.type);
|
|
267
|
+
if (!d) return [{ code: DesignIssueCode.Motion, path: `${path}.type`, message: `"${op.type}" is not an action of the catalog` }];
|
|
268
|
+
if (!actionOfferedUnder(d, op.trigger)) return [{ code: DesignIssueCode.Motion, path: `${path}.trigger`, message: `${op.type} is not offered under "${op.trigger}" — ${(d.triggers ?? []).join(', ')}` }];
|
|
269
|
+
if (!isEntrance(op.trigger, op.type)) return [];
|
|
270
|
+
const rows = index.find(op.node)!.node.interactions as Array<{ id?: string; trigger?: string; actions?: Array<{ type?: string }> }>;
|
|
271
|
+
const other = rows.find(r => r.id !== op.id && isEntrance(r.trigger ?? '', r.actions?.[0]?.type ?? ''));
|
|
272
|
+
return other ? [{ code: DesignIssueCode.Motion, path: `${path}.trigger`, message: `"${op.node}" already enters (row "${other.id}") — one entrance per element; put a second move on a wrapper` }] : [];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** A Scene op's rows as the layer's tracks: consecutive rows of one prop and one `from` are one track. */
|
|
276
|
+
export function designSceneTracks(rows: ReadonlyArray<DesignSceneRow>): Array<Record<string, unknown>> {
|
|
277
|
+
const tracks: Array<Record<string, unknown> & { keys: unknown[][] }> = [];
|
|
278
|
+
let last: DesignSceneRow | undefined;
|
|
279
|
+
for (const row of rows) {
|
|
280
|
+
if (!last || last.prop !== row.prop || last.from !== row.from) {
|
|
281
|
+
tracks.push(row.from ? { prop: row.prop, from: row.from, keys: [] } : { prop: row.prop, keys: [] });
|
|
282
|
+
}
|
|
283
|
+
tracks[tracks.length - 1].keys.push([row.at, row.value]);
|
|
284
|
+
last = row;
|
|
285
|
+
}
|
|
286
|
+
return tracks;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const canonicalJson = (v: unknown): string => JSON.stringify(v, (_k, x) => (x && typeof x === 'object' && !Array.isArray(x) ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => a.localeCompare(b))) : x));
|
|
290
|
+
|
|
291
|
+
function sceneRules(op: SceneDesignOp, path: string): DesignIssue[] {
|
|
292
|
+
const tracks = designSceneTracks(op.tracks);
|
|
293
|
+
return canonicalJson(normalizeTracks(tracks)) === canonicalJson(tracks) ? []
|
|
294
|
+
: [{ code: DesignIssueCode.Motion, path: `${path}.tracks`, message: 'the timeline would not keep these keys as written — each prop once, keys ascending by "at", a clip track says its "from"' }];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function headingLevel(op: PlaceDesignOp, type: string, current?: SerializedNode): string | undefined {
|
|
298
|
+
if (type !== T.Heading) return undefined;
|
|
299
|
+
const given = op.values.find(v => v.name === LEVEL);
|
|
300
|
+
return given ? String(given.value) : (current ? String(current.props[LEVEL] ?? '') : String(NODE_BASELINES[T.Heading].props[LEVEL]));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function placeRules(op: PlaceDesignOp, path: string, index: DesignDocIndex, ctx: DesignCheckContext): DesignIssue[] {
|
|
304
|
+
const out = said(inputsOf(op.values).map(v => ({ v, j: op.values.indexOf(v) }))
|
|
305
|
+
.filter(({ v }) => DESIGN_SAID_PROPS.includes(v.name) && typeof v.value === 'string')
|
|
306
|
+
.map(({ v, j }) => ({ path: `${path}.values[${j}]`, text: String(v.value) })), ctx);
|
|
307
|
+
const current = op.op === PlaceOp.Set ? index.find(op.node)?.node : undefined;
|
|
308
|
+
const type = current?.type ?? op.type;
|
|
309
|
+
if (op.op !== PlaceOp.Set) out.push(...slideIssues(type, op.parent, path, index));
|
|
310
|
+
if (headingLevel(op, type, current) === H1 && current?.props[LEVEL] !== H1) {
|
|
311
|
+
const other = index.nodes().find(n => n.type === T.Heading && n.props[LEVEL] === H1 && n.id !== op.node);
|
|
312
|
+
if (other) out.push({ code: DesignIssueCode.Layout, path, message: `the page already has its h1 ("${other.id}") — one h1 per page` });
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function slideIssues(type: string, parent: string, path: string, index: DesignDocIndex): DesignIssue[] {
|
|
318
|
+
const holder = parent ? index.find(parent)?.node.type : undefined;
|
|
319
|
+
// The `.swiper-slide` direct-child invariant (slider.md). A slider's controls are parts too, so the rule runs one way.
|
|
320
|
+
return type === T.Slide && holder !== T.Slider ? [{ code: DesignIssueCode.Layout, path: `${path}.parent`, message: 'a slide goes directly into a slider' }] : [];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function contentIssues(op: DesignOp, path: string, index: DesignDocIndex, ctx: DesignCheckContext): DesignIssue[] {
|
|
324
|
+
switch (op.tool) {
|
|
325
|
+
case DesignTool.Place: return placeRules(op as PlaceDesignOp, path, index, ctx);
|
|
326
|
+
case DesignTool.Style: return styleRules(op as StyleDesignOp, path, ctx);
|
|
327
|
+
case DesignTool.Act: return actRules(op as ActDesignOp, path, index);
|
|
328
|
+
case DesignTool.Scene: return sceneRules(op as SceneDesignOp, path);
|
|
329
|
+
case DesignTool.Words: return said([{ path: `${path}.text`, text: op.text }], ctx);
|
|
330
|
+
case DesignTool.Look: {
|
|
331
|
+
const look = op as LookDesignOp;
|
|
332
|
+
return look.kind === LookEditKind.Token && !ctx.tokens.some(t => t.name === look.name)
|
|
333
|
+
? [{ code: DesignIssueCode.Token, path: `${path}.name`, message: `"${look.name}" is not a token of this look` }] : [];
|
|
334
|
+
}
|
|
335
|
+
case DesignTool.Move: {
|
|
336
|
+
const move = op as MoveDesignOp;
|
|
337
|
+
return move.op === MoveOp.Move ? slideIssues(index.find(move.node)!.node.type, move.parent, path, index) : [];
|
|
338
|
+
}
|
|
339
|
+
default: return [];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Why op `i` of a stream may not be applied to the document as it stands, each reason with its path (`ops[i].traits[2].left`).
|
|
345
|
+
* Without `ctx` only the shape and the slots are read (what the builder itself could not hold).
|
|
346
|
+
*/
|
|
347
|
+
export function designOpIssues(op: DesignOp, i: number, index: DesignDocIndex, options: { rtl?: boolean; check?: DesignCheckContext } = {}): DesignIssue[] {
|
|
348
|
+
const path = at(i);
|
|
349
|
+
const shape = shapeIssues(op, path, index, !!options.rtl);
|
|
350
|
+
if (shape.length || !options.check) return shape;
|
|
351
|
+
return contentIssues(op, path, index, options.check);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* The page's invariants once a turn is applied (they hold for the page, not for one op): one h1, every picture described,
|
|
356
|
+
* a slide only directly in a slider. Paths are node ids (`layout:<id>`).
|
|
357
|
+
*/
|
|
358
|
+
export function designDocIssues(doc: DesignDoc): DesignIssue[] {
|
|
359
|
+
const out: DesignIssue[] = [];
|
|
360
|
+
const index = new DesignDocIndex(doc);
|
|
361
|
+
const nodes = index.nodes();
|
|
362
|
+
const h1 = nodes.filter(n => n.type === T.Heading && n.props[LEVEL] === H1);
|
|
363
|
+
if (h1.length > 1) out.push({ code: DesignIssueCode.Layout, path: h1.slice(1).map(n => `layout:${n.id}`).join(', '), message: `${h1.length} h1 on one page — one h1 per page` });
|
|
364
|
+
for (const n of nodes) {
|
|
365
|
+
const place = index.find(n.id)!;
|
|
366
|
+
if (n.type === T.Image && !String(n.props[ALT] ?? '').trim()) out.push({ code: DesignIssueCode.Layout, path: `layout:${n.id}`, message: 'a picture says what it shows (words on its alt)' });
|
|
367
|
+
if (n.type === T.Slide && place.parent?.type !== T.Slider) out.push({ code: DesignIssueCode.Layout, path: `layout:${n.id}`, message: 'a slide sits directly in a slider' });
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { DESIGN_ACT_VALUES, DESIGN_PARAM_PREFIX, DESIGN_PICTURE_PROPS, DESIGN_WORD_PROPS } from './design-ops-check';
|
|
2
|
+
import { placedDesignNode } from './design-ops';
|
|
3
|
+
import {
|
|
4
|
+
DESIGN_BASE_LAYER, DESIGN_END_INDEX, DESIGN_FONTS_CHOICE, DESIGN_NO_STYLE, DESIGN_PAGE_PARENT, DESIGN_TRIGGER_META, DesignLook, DesignMeta, DesignOp,
|
|
5
|
+
DesignSceneRow, DesignTool, DesignTrait, DesignValue, LookEditKind, PlaceOp,
|
|
6
|
+
} from './design-ops.model';
|
|
7
|
+
import type { SerializedNode } from './serialized-node';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A SAVED PAGE AS THE DESIGNER'S OPS (AD1, the replay — ai-designer-plan §2b, R-H2): each node as the one `place` that
|
|
11
|
+
* drops it, then what a person would do to it — type its words, choose its picture, its Style-panel values (base, widths,
|
|
12
|
+
* states), its Interactions rows, its Scene tracks — then its children. Only what differs from the palette's new node is
|
|
13
|
+
* written, so this is also the compact form a revise round speaks (§2e). Whatever a saved node holds that no tool can
|
|
14
|
+
* write is reported in `gaps` (never silently widened). Pure.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface DesignOpsOfOptions {
|
|
18
|
+
/** The page runs right to left (a `left` is its end side). */
|
|
19
|
+
rtl?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DesignOpsOf {
|
|
23
|
+
ops: DesignOp[];
|
|
24
|
+
/** What the ops cannot say, each with the node's id — empty when the page replays byte for byte. */
|
|
25
|
+
gaps: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Plain = Record<string, unknown>;
|
|
29
|
+
const isPlain = (v: unknown): v is Plain => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
30
|
+
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
|
|
31
|
+
const isScalar = (v: unknown): v is string | number | boolean => typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';
|
|
32
|
+
/** An input's value as a `place` value: a scalar as itself, a list / object / null as its JSON text. */
|
|
33
|
+
const asValue = (v: unknown): DesignValue['value'] => (isScalar(v) ? v : JSON.stringify(v));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A physical side, written as the start / end side it is on this page. The designer speaks start / end only (the check
|
|
37
|
+
* refuses a physical side), and since Batch C3 the builder HOLDS a start / end inset as its own control (Position ▸ Start /
|
|
38
|
+
* End, `insetInlineStart` / `insetInlineEnd` — it mirrors with the page), so a stored `left: 0px` comes back as
|
|
39
|
+
* `insetInlineStart: 0px` on an English page: the same box, held the way it mirrors.
|
|
40
|
+
*/
|
|
41
|
+
export function designSideName(name: string, rtl: boolean): string {
|
|
42
|
+
if (name === 'left') return rtl ? 'insetInlineEnd' : 'insetInlineStart';
|
|
43
|
+
if (name === 'right') return rtl ? 'insetInlineStart' : 'insetInlineEnd';
|
|
44
|
+
return name;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
class OpsWriter {
|
|
48
|
+
readonly ops: DesignOp[] = [];
|
|
49
|
+
readonly gaps: string[] = [];
|
|
50
|
+
|
|
51
|
+
constructor(private readonly rtl: boolean) {}
|
|
52
|
+
|
|
53
|
+
private gap(node: SerializedNode, what: string): void {
|
|
54
|
+
this.gaps.push(`${node.id}: ${what}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private placeValues(node: SerializedNode, global: boolean): DesignValue[] {
|
|
58
|
+
const values: DesignValue[] = [];
|
|
59
|
+
const said = [DESIGN_WORD_PROPS[node.type], DESIGN_PICTURE_PROPS[node.type]];
|
|
60
|
+
const bare = placedDesignNode(node.id, node.type, []);
|
|
61
|
+
for (const [name, value] of Object.entries(node.props)) {
|
|
62
|
+
if (said.includes(name) && typeof value === 'string') continue;
|
|
63
|
+
if (!same(bare.props[name], value)) values.push({ name, value: asValue(value) });
|
|
64
|
+
}
|
|
65
|
+
// The element style: the type's default for these inputs is the palette's; anything else is said.
|
|
66
|
+
const plain = placedDesignNode(node.id, node.type, values);
|
|
67
|
+
if ((plain.elementStyle ?? '') !== (node.elementStyle ?? '')) values.push({ name: DesignMeta.Style, value: node.elementStyle ?? DESIGN_NO_STYLE });
|
|
68
|
+
if (node.label !== undefined) values.push({ name: DesignMeta.Label, value: node.label });
|
|
69
|
+
if (node.role !== undefined) values.push({ name: DesignMeta.Role, value: node.role });
|
|
70
|
+
if (node.itemKey !== undefined) values.push({ name: DesignMeta.ItemKey, value: node.itemKey });
|
|
71
|
+
if (global && node.globalPosition) values.push({ name: DesignMeta.Global, value: node.globalPosition });
|
|
72
|
+
for (const [state, by] of Object.entries(node.stateTriggers ?? {})) if (by) values.push({ name: `${DESIGN_TRIGGER_META}${state}`, value: by });
|
|
73
|
+
return values;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private layerTraits(node: SerializedNode, layer: string, held: Plain, want: Plain, base: boolean): DesignTrait[] {
|
|
77
|
+
const traits: DesignTrait[] = [];
|
|
78
|
+
for (const [name, value] of Object.entries(want)) {
|
|
79
|
+
if (typeof value !== 'string') { this.gap(node, `${layer}.${name} holds a ${typeof value}, not a CSS value`); continue; }
|
|
80
|
+
if (!base && value === '') { this.gap(node, `${layer}.${name} holds "" (the tool's "" forgets a value)`); continue; }
|
|
81
|
+
if (held[name] === value) continue;
|
|
82
|
+
const said = designSideName(name, this.rtl);
|
|
83
|
+
// A physical side and its own start / end side both set: the ops speak start / end only, so one would be lost.
|
|
84
|
+
if (traits.some(t => t.name === said)) { this.gap(node, `${layer}.${said} is set twice — by a physical side and by itself (the ops say start / end only)`); continue; }
|
|
85
|
+
traits.push({ name: said, value });
|
|
86
|
+
}
|
|
87
|
+
for (const name of Object.keys(held)) {
|
|
88
|
+
if (name in want) continue;
|
|
89
|
+
if (base) this.gap(node, `base has no "${name}" (a base value cannot be forgotten)`);
|
|
90
|
+
else traits.push({ name: designSideName(name, this.rtl), value: '' });
|
|
91
|
+
}
|
|
92
|
+
return traits;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private styles(node: SerializedNode, made: SerializedNode): void {
|
|
96
|
+
const push = (layer: string, traits: DesignTrait[]) => { if (traits.length) this.ops.push({ tool: DesignTool.Style, node: node.id, layer, traits }); };
|
|
97
|
+
push(DESIGN_BASE_LAYER, this.layerTraits(node, DESIGN_BASE_LAYER, made.styleProps, node.styleProps, true));
|
|
98
|
+
for (const [bp, layer] of Object.entries(node.responsive ?? {})) {
|
|
99
|
+
const extra = Object.keys(layer ?? {}).filter(k => k !== 'styleProps');
|
|
100
|
+
if (extra.length) this.gap(node, `responsive.${bp} holds ${extra.join(', ')} (a width's inputs)`);
|
|
101
|
+
if (!layer?.styleProps || !Object.keys(layer.styleProps).length) { this.gap(node, `responsive.${bp} is empty`); continue; }
|
|
102
|
+
push(bp, this.layerTraits(node, bp, made.responsive?.[bp]?.styleProps ?? {}, layer.styleProps, false));
|
|
103
|
+
}
|
|
104
|
+
for (const [state, values] of Object.entries(node.stateStyles ?? {})) {
|
|
105
|
+
if (!values || !Object.keys(values).length) { this.gap(node, `stateStyles.${state} is empty`); continue; }
|
|
106
|
+
push(state, this.layerTraits(node, state, made.stateStyles?.[state] ?? {}, values, false));
|
|
107
|
+
}
|
|
108
|
+
for (const [state, values] of Object.entries(made.stateStyles ?? {})) {
|
|
109
|
+
if (!(state in (node.stateStyles ?? {}))) push(state, Object.keys(values ?? {}).map(name => ({ name: designSideName(name, this.rtl), value: '' })));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private acts(node: SerializedNode): void {
|
|
114
|
+
for (const row of node.interactions as Plain[]) {
|
|
115
|
+
const known = ['id', 'trigger', 'range', 'actions'];
|
|
116
|
+
const extra = Object.keys(row).filter(k => !known.includes(k));
|
|
117
|
+
if (extra.length) this.gap(node, `interaction ${row['id']} holds ${extra.join(', ')}`);
|
|
118
|
+
const base = { tool: DesignTool.Act as const, node: node.id, id: String(row['id']), trigger: String(row['trigger']), range: String(row['range'] ?? '') };
|
|
119
|
+
const actions = (row['actions'] as Plain[] | undefined) ?? [];
|
|
120
|
+
if (!actions.length) this.ops.push({ ...base, type: '', values: [] });
|
|
121
|
+
for (const action of actions) {
|
|
122
|
+
const values: DesignValue[] = [];
|
|
123
|
+
for (const [name, value] of Object.entries(action)) {
|
|
124
|
+
if (name === 'type') continue;
|
|
125
|
+
if (name === 'params' && isPlain(value)) {
|
|
126
|
+
for (const [p, v] of Object.entries(value)) {
|
|
127
|
+
if (isScalar(v)) values.push({ name: `${DESIGN_PARAM_PREFIX}${p}`, value: v });
|
|
128
|
+
else this.gap(node, `interaction ${row['id']} params.${p} is not one value`);
|
|
129
|
+
}
|
|
130
|
+
} else if (DESIGN_ACT_VALUES.includes(name) && isScalar(value)) values.push({ name, value });
|
|
131
|
+
else this.gap(node, `interaction ${row['id']} action ${name} = ${JSON.stringify(value)}`);
|
|
132
|
+
}
|
|
133
|
+
this.ops.push({ ...base, type: String(action['type']), values });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private scenes(node: SerializedNode): void {
|
|
139
|
+
for (const [key, phone] of [['sceneTracks', false], ['scenePhoneTracks', true]] as const) {
|
|
140
|
+
const tracks = node[key];
|
|
141
|
+
if (!tracks) continue;
|
|
142
|
+
const rows: DesignSceneRow[] = [];
|
|
143
|
+
let last = '';
|
|
144
|
+
for (const t of tracks as Plain[]) {
|
|
145
|
+
const extra = Object.keys(t).filter(k => !['prop', 'from', 'keys'].includes(k));
|
|
146
|
+
if (extra.length) this.gap(node, `${key} ${t['prop']} holds ${extra.join(', ')}`);
|
|
147
|
+
const from = String(t['from'] ?? '');
|
|
148
|
+
const id = `${t['prop']}|${from}`;
|
|
149
|
+
if (id === last) this.gap(node, `${key} has two ${t['prop']} tracks in a row`);
|
|
150
|
+
last = id;
|
|
151
|
+
for (const k of (t['keys'] as unknown[][]) ?? []) rows.push({ prop: String(t['prop']), from, at: Number(k[0]), value: k[1] as string | number });
|
|
152
|
+
}
|
|
153
|
+
this.ops.push({ tool: DesignTool.Scene, node: node.id, phone, tracks: rows });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
node(node: SerializedNode, parent: string, global: boolean): void {
|
|
158
|
+
if (node.bindings?.length) this.gap(node, 'holds bindings (the designer binds nothing)');
|
|
159
|
+
if (node.composed) this.gap(node, 'holds a composed stamp');
|
|
160
|
+
const values = this.placeValues(node, global);
|
|
161
|
+
this.ops.push({ tool: DesignTool.Place, op: PlaceOp.Place, node: node.id, type: node.type, parent, index: DESIGN_END_INDEX, values });
|
|
162
|
+
const made = placedDesignNode(node.id, node.type, values);
|
|
163
|
+
const word = DESIGN_WORD_PROPS[node.type];
|
|
164
|
+
if (word && typeof node.props[word] === 'string' && node.props[word] !== made.props[word]) this.ops.push({ tool: DesignTool.Words, node: node.id, text: node.props[word] as string });
|
|
165
|
+
const picture = DESIGN_PICTURE_PROPS[node.type];
|
|
166
|
+
if (picture && typeof node.props[picture] === 'string' && node.props[picture] !== made.props[picture]) this.ops.push({ tool: DesignTool.Picture, node: node.id, src: node.props[picture] as string });
|
|
167
|
+
this.styles(node, made);
|
|
168
|
+
this.acts(node);
|
|
169
|
+
this.scenes(node);
|
|
170
|
+
if (!!node.children !== !!made.children) this.gap(node, node.children ? 'holds children its type does not take' : 'a container without its children list');
|
|
171
|
+
for (const child of node.children ?? []) this.node(child, node.id, false);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
look(look: DesignLook): void {
|
|
175
|
+
for (const [name, value] of Object.entries(look.choices ?? {})) {
|
|
176
|
+
if (name === DESIGN_FONTS_CHOICE && isPlain(value)) {
|
|
177
|
+
for (const [role, font] of Object.entries(value)) this.ops.push({ tool: DesignTool.Look, kind: LookEditKind.Font, name: role, value: asValue(font) });
|
|
178
|
+
} else if (isScalar(value)) this.ops.push({ tool: DesignTool.Look, kind: LookEditKind.Choice, name, value });
|
|
179
|
+
else this.gap({ id: 'look' } as SerializedNode, `choice ${name} is not one value`);
|
|
180
|
+
}
|
|
181
|
+
for (const [name, value] of Object.entries(look.tokenEdits ?? {})) {
|
|
182
|
+
if (isScalar(value) && value !== '') this.ops.push({ tool: DesignTool.Look, kind: LookEditKind.Token, name, value });
|
|
183
|
+
else this.gap({ id: 'look' } as SerializedNode, `token ${name} = ${JSON.stringify(value)}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A page's layout (or the site's globals) as ops, parents first. */
|
|
189
|
+
export function designOpsOfLayout(nodes: ReadonlyArray<SerializedNode>, options: DesignOpsOfOptions & { globals?: boolean } = {}): DesignOpsOf {
|
|
190
|
+
const w = new OpsWriter(!!options.rtl);
|
|
191
|
+
for (const node of nodes) w.node(node, DESIGN_PAGE_PARENT, !!options.globals);
|
|
192
|
+
return { ops: w.ops, gaps: w.gaps };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The look as ops: Design ▸ Apply's choices (fonts in their place), then the token edits. */
|
|
196
|
+
export function designOpsOfLook(look: DesignLook): DesignOpsOf {
|
|
197
|
+
const w = new OpsWriter(false);
|
|
198
|
+
w.look(look);
|
|
199
|
+
return { ops: w.ops, gaps: w.gaps };
|
|
200
|
+
}
|