@vectoriox/iox-ui 5.203.0 → 5.205.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 +70 -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 +131 -11
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +5294 -267
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +524 -112
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +2308 -6
- package/index.d.ts +159 -13
- 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/node-links.ts +12 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/generation-core/ai-run.ts +31 -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 +178 -0
- package/src/generation-core/critic-prompt.ts +174 -0
- package/src/generation-core/critic-rubric.generated.ts +24 -0
- package/src/generation-core/critic-sheet.ts +270 -0
- package/src/generation-core/critic.ts +189 -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 +82 -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,247 @@
|
|
|
1
|
+
import { actionOfferedUnder, ELEMENT_ACTION_DESCRIPTORS, ENTRANCE_ACTION_TYPES, EXIT_ACTION_TYPES } from '@vectoriox/iox-ui/actions-core';
|
|
2
|
+
import { DesignTokenLike, LEAVE_SHARE } from '@vectoriox/iox-ui/design-core';
|
|
3
|
+
|
|
4
|
+
import { FREE_HOVER_PROPS, freeStyleIssues } from './check-free';
|
|
5
|
+
import { auditLayoutMotion, LAYOUT_ENTRANCE_TRIGGERS } from './check-layout';
|
|
6
|
+
import { DESIGN_POINTER_STATES } from './design-ops-check';
|
|
7
|
+
import { DesignDoc, DesignIssue, DesignIssueCode } from './design-ops.model';
|
|
8
|
+
import { SerializedNode, walkSerialized } from './serialized-node';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* EMIL'S RULES, READ OFF A PAGE (ai-designer-plan §2f "Emil", R-H20): the static half of the motion review, over a saved
|
|
12
|
+
* page's own nodes — whoever wrote them (the designer's ops, a hand build, a composed page). What it holds:
|
|
13
|
+
* 1. PROPERTY — motion moves transform, opacity and clip-path (a filter only where the catalog's `blurIn` does): a
|
|
14
|
+
* transition never names a layout property (width, height, a side, margin, padding) nor `all`; a pointer state
|
|
15
|
+
* (hover, press) moves, scales, turns, fades or changes a colour token only (`FREE_HOVER_PROPS`). The catalog's own
|
|
16
|
+
* actions are held to the same by the spec (every motion action's frames, `buildInteractionKeyframes`).
|
|
17
|
+
* 2. ONE ENTRANCE — an element enters once (one entrance action under the self-playing triggers, whatever row it is in),
|
|
18
|
+
* and a CONTAINER that enters holds nothing that enters too: either the column rises or its words stagger in.
|
|
19
|
+
* 3. EXIT — an element's exit is faster than its entrance (about `LEAVE_SHARE` of it).
|
|
20
|
+
* 4. TIME — easings are tokens (a cubic-bezier, linear, a var()) and never ease-in; a CSS duration is the look's token
|
|
21
|
+
* (so reduced motion can collapse it); what a pointer drives on a control plays under `UI_MOTION_MAX_MS`, a
|
|
22
|
+
* picture's hover zoom in at most `PICTURE_HOVER_MAX_MS`; an entrance in at most `LAYOUT_ENTRANCE_MAX_MS` — but a
|
|
23
|
+
* count and a picture's ambient settle (AD-D23, `entranceCapExempt`); nothing grows from a tiny scale.
|
|
24
|
+
* 5. REDUCED MOTION, gentler not zero — the platform covers every catalog entrance with its floor's fade (`show` is the
|
|
25
|
+
* instant reveal a click opens, so it is refused as a self-playing entrance) and every scroll play with its own
|
|
26
|
+
* reduced play (scene-core `scroll-range`); a literal CSS duration is the one thing reduced motion cannot reach (4).
|
|
27
|
+
* 6. HOVER GATED — by the platform: every hover state is emitted inside `(hover: hover) and (pointer: fine)` and a hover
|
|
28
|
+
* trigger answers a mouse or a pen only (iox-ui `gateHoverRule`, `isHoverPointer`; held by the spec). A design has no
|
|
29
|
+
* other way to hover, so nothing here can break it.
|
|
30
|
+
* It reuses the composer's audit (`auditLayoutMotion`: ease-in, easing tokens, `transition: all`, scale floor, entrance
|
|
31
|
+
* length), the free tier's style rules (`freeStyleIssues`) and the catalog (actions-core) — never a second copy. Paths are
|
|
32
|
+
* node ids (`layout:<id>.interactions[0].actions[1].easing`). Pure.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/** What a pointer drives on the element itself plays this fast at most (Emil: UI under 300 ms; `emil-audit.cjs`). */
|
|
36
|
+
export const UI_MOTION_MAX_MS = 300;
|
|
37
|
+
/** The triggers that play by themselves: the composer's entrance triggers and a page arriving. */
|
|
38
|
+
export const MOTION_ENTRANCE_TRIGGERS: ReadonlySet<string> = new Set([...LAYOUT_ENTRANCE_TRIGGERS, 'pageEnter']);
|
|
39
|
+
/** The triggers a pointer drives. */
|
|
40
|
+
export const MOTION_POINTER_TRIGGERS: ReadonlySet<string> = new Set(['click', 'hover']);
|
|
41
|
+
/** A transition that names any of these animates layout (the prototype's Emil audit, `emil-audit.cjs`, ported). */
|
|
42
|
+
const LAYOUT_PROPERTY = /(^|[\s,])(width|height|top|left|right|bottom|inset|margin|padding)(-[a-z-]+)?(?![-\w])/i;
|
|
43
|
+
const EASE_IN = /(^|[\s,(])ease-in(?!-out)/;
|
|
44
|
+
/** The controls a visitor operates: what a pointer drives on them is UI (the prototype audit's `UI` selector, as types). */
|
|
45
|
+
export const MOTION_UI_TYPES: ReadonlySet<string> = new Set(['Button', 'ButtonBlock', 'Link', 'Field', 'SubmitButton']);
|
|
46
|
+
/** The parts that ARE a picture (AD-D23). */
|
|
47
|
+
export const MOTION_PICTURE_TYPES: ReadonlySet<string> = new Set(['Image', 'Video']);
|
|
48
|
+
/** AD-D23 (the lessons' "hover zoom under 0.9 s"): a picture's hover transform plays in this much at most. */
|
|
49
|
+
export const PICTURE_HOVER_MAX_MS = 900;
|
|
50
|
+
/** AD-D23: a picture's ambient settle (`zoomOut`) may play this long — the one entrance over the cap besides a count. */
|
|
51
|
+
export const PICTURE_SETTLE_MAX_MS = 7000;
|
|
52
|
+
/** AD-D23: the entrance cap's two named exemptions — a count (its duration is how long the digits count, nothing moves)
|
|
53
|
+
* and a picture's settle (`zoomOut` on a picture: 1.15 → 1, never under 0.9). */
|
|
54
|
+
export const COUNT_ACTION = 'countUp';
|
|
55
|
+
export const SETTLE_ACTION = 'zoomOut';
|
|
56
|
+
/** What a pointer state may move that is a transform (a picture's hover zoom). */
|
|
57
|
+
const TRANSFORM_PROPS: ReadonlyArray<string> = ['translateX', 'translateY', 'scaleX', 'scaleY', 'rotate'];
|
|
58
|
+
const CUBIC = /^cubic-bezier\(\s*([\d.]+)\s*,\s*(-?[\d.]+)\s*,/;
|
|
59
|
+
/** A look token made for a pointer state (`--iox-button-press-radius`, `--iox-button-hover-x`): the flavor's own state
|
|
60
|
+
* design, reviewed with it (premium-components), so a pointer state may name it whatever the property. */
|
|
61
|
+
const STATE_TOKEN = /^var\(\s*--iox-[a-z0-9-]*(hover|press)[a-z0-9-]*\s*\)$/;
|
|
62
|
+
/** The reveal a click opens: instant by design, so it has no reduced-motion fade (iox-ui `reducedEntranceFades`). */
|
|
63
|
+
const INSTANT_REVEAL = 'show';
|
|
64
|
+
const SELF = 'self';
|
|
65
|
+
|
|
66
|
+
export enum MotionRule {
|
|
67
|
+
Property = 'property',
|
|
68
|
+
OneEntrance = 'one-entrance',
|
|
69
|
+
Container = 'container',
|
|
70
|
+
Exit = 'exit',
|
|
71
|
+
Easing = 'easing',
|
|
72
|
+
Duration = 'duration',
|
|
73
|
+
Scale = 'scale',
|
|
74
|
+
Catalog = 'catalog',
|
|
75
|
+
Reduced = 'reduced',
|
|
76
|
+
}
|
|
77
|
+
export type MotionIssue = DesignIssue & { rule: MotionRule };
|
|
78
|
+
|
|
79
|
+
interface Action { type?: string; target?: string; duration?: number; easing?: string; params?: Record<string, unknown> }
|
|
80
|
+
interface Row { id?: string; trigger?: string; actions?: Action[] }
|
|
81
|
+
type Style = Record<string, unknown> | undefined;
|
|
82
|
+
|
|
83
|
+
/** A move as the page plays it: the element it moves, where it is written, its row's trigger. */
|
|
84
|
+
interface Move { element: string; path: string; trigger: string; action: Action }
|
|
85
|
+
|
|
86
|
+
const rowsOf = (node: SerializedNode) => (Array.isArray(node.interactions) ? node.interactions : []) as Row[];
|
|
87
|
+
const elementOf = (node: SerializedNode, a: Action) => (a.target && a.target !== SELF ? a.target : node.id);
|
|
88
|
+
const isEntrance = (m: Move) => MOTION_ENTRANCE_TRIGGERS.has(m.trigger) && ENTRANCE_ACTION_TYPES.has(String(m.action.type));
|
|
89
|
+
const isExit = (m: Move) => EXIT_ACTION_TYPES.has(String(m.action.type));
|
|
90
|
+
const ms = (m: Move) => Number(m.action.duration ?? 0);
|
|
91
|
+
const isMotion = (m: Move) => ELEMENT_ACTION_DESCRIPTORS.find(d => d.type === m.action.type)?.group === MOTION_GROUP;
|
|
92
|
+
const MOTION_GROUP = 'motion';
|
|
93
|
+
/** The token type of the look's curves (`ease-standard`, `ease-enter`…). */
|
|
94
|
+
const EASING_TOKEN_TYPE = 'easing';
|
|
95
|
+
|
|
96
|
+
/** A CSS time in ms: a literal (`240ms`, `.3s`) or a token the look holds (`var(--iox-dur-base)`); null when unknown. */
|
|
97
|
+
export function cssMs(value: unknown, tokens: ReadonlyArray<DesignTokenLike> = []): number | null {
|
|
98
|
+
const raw = String(value ?? '').trim();
|
|
99
|
+
const token = /^var\(\s*--iox-([a-z0-9-]+)/.exec(raw);
|
|
100
|
+
const v = token ? tokens.find(t => t.name === token[1])?.value ?? '' : raw;
|
|
101
|
+
const m = /^([\d.]+)(ms|s)$/.exec(v.trim());
|
|
102
|
+
return m ? Number(m[1]) * (m[2] === 's' ? 1000 : 1) : null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The composer's audit, as this check's issues (its node paths turned into the page's). */
|
|
106
|
+
function composerAudit(nodes: ReadonlyArray<SerializedNode>, named: ReadonlySet<string>): MotionIssue[] {
|
|
107
|
+
const ruleOf = (path: string): MotionRule =>
|
|
108
|
+
(/\.easing$/.test(path) ? MotionRule.Easing : /\.duration$/.test(path) ? MotionRule.Duration : /transition/.test(path) ? MotionRule.Property : MotionRule.Scale);
|
|
109
|
+
// An easing that NAMES the look's curve (`ease-enter`: both runtimes resolve it, iox-ui `interaction-easing`) is the
|
|
110
|
+
// token itself — the composer's audit, which stamps cubic-beziers, does not know the names.
|
|
111
|
+
return auditLayoutMotion(nodes).map(i => {
|
|
112
|
+
const path = i.path.replace(/^node\(([^)]*)\)/, 'layout:$1');
|
|
113
|
+
return { code: DesignIssueCode.Motion, rule: ruleOf(path), path, message: i.message };
|
|
114
|
+
}).filter(i => !named.has(i.path));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Every style map a node holds, with its path. */
|
|
118
|
+
function stylesOf(node: SerializedNode, at: string): Array<[string, Style, string | null]> {
|
|
119
|
+
return [
|
|
120
|
+
[`${at}.styleProps`, node.styleProps, null],
|
|
121
|
+
...Object.entries(node.stateStyles ?? {}).map(([s, v]) => [`${at}.stateStyles.${s}`, v as Style, s] as [string, Style, string]),
|
|
122
|
+
...Object.entries(node.responsive ?? {}).map(([w, r]) => [`${at}.responsive.${w}.styleProps`, (r as { styleProps?: Style })?.styleProps, null] as [string, Style, null]),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Rules 1 and 4 on a node's own styles. */
|
|
127
|
+
function styleIssues(node: SerializedNode, at: string, tokens: ReadonlyArray<DesignTokenLike> | undefined, say: (rule: MotionRule, path: string, message: string) => void): void {
|
|
128
|
+
const pointer = MOTION_UI_TYPES.has(node.type) && DESIGN_POINTER_STATES.some(s => Object.keys(node.stateStyles?.[s] ?? {}).length > 0);
|
|
129
|
+
// An unset duration is CSS's initial 0s; a state or a width without one plays the base's.
|
|
130
|
+
const zooms = MOTION_PICTURE_TYPES.has(node.type) && Object.keys(node.stateStyles?.['hover'] ?? {}).some(k => TRANSFORM_PROPS.includes(k));
|
|
131
|
+
const baseTime = node.styleProps?.['transitionDuration'] === undefined ? 0 : cssMs(node.styleProps['transitionDuration'], tokens);
|
|
132
|
+
for (const [path, style, state] of stylesOf(node, at)) {
|
|
133
|
+
if (!style) continue;
|
|
134
|
+
for (const key of ['transition', 'transitionProperty']) {
|
|
135
|
+
const v = String(style[key] ?? '');
|
|
136
|
+
const prop = LAYOUT_PROPERTY.exec(v);
|
|
137
|
+
if (prop) say(MotionRule.Property, `${path}.${key}`, `a transition on "${prop[2]}" animates layout — move transform and opacity (a clip-path to reveal) instead`);
|
|
138
|
+
}
|
|
139
|
+
for (const key of ['transition', 'transitionTimingFunction']) {
|
|
140
|
+
if (EASE_IN.test(String(style[key] ?? ''))) say(MotionRule.Easing, `${path}.${key}`, 'never ease-in: it starts slow where the eye is watching');
|
|
141
|
+
}
|
|
142
|
+
if (state && DESIGN_POINTER_STATES.includes(state)) {
|
|
143
|
+
for (const [k, v] of Object.entries(style)) {
|
|
144
|
+
if (v !== '' && !FREE_HOVER_PROPS.includes(k) && !STATE_TOKEN.test(String(v))) say(MotionRule.Property, `${path}.${k}`, `a ${state} moves, scales, turns, fades or changes a colour token only (${FREE_HOVER_PROPS.join(', ')}) — never "${k}"`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// A transition that lasts nothing plays nothing: the palette's stamp (`0ms`, `ease`) is not a choice to judge.
|
|
148
|
+
const time = cssMs(style['transitionDuration'], tokens) ?? (style['transitionDuration'] === undefined ? baseTime : null);
|
|
149
|
+
if (tokens && time !== 0) {
|
|
150
|
+
const timing = Object.fromEntries(['transitionDuration', 'transitionTimingFunction'].filter(k => style[k] !== undefined && style[k] !== '').map(k => [k, style[k] as string]));
|
|
151
|
+
for (const i of freeStyleIssues(timing, path, { tokens })) {
|
|
152
|
+
say(/Duration/.test(i.path) ? MotionRule.Duration : MotionRule.Easing, i.path, `${i.message} — a token, so reduced motion can collapse it`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (pointer && state === null && path.endsWith('.styleProps') && time !== null && time > UI_MOTION_MAX_MS) {
|
|
156
|
+
say(MotionRule.Duration, `${path}.transitionDuration`, `${time}ms — what a pointer drives plays under ${UI_MOTION_MAX_MS}ms`);
|
|
157
|
+
}
|
|
158
|
+
if (zooms && state === null && path.endsWith('.styleProps') && time !== null && time > PICTURE_HOVER_MAX_MS) {
|
|
159
|
+
say(MotionRule.Duration, `${path}.transitionDuration`, `${time}ms — a picture's hover zoom plays in ${PICTURE_HOVER_MAX_MS}ms at most`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Emil's rules over a page (its layout and the site's global parts), each refusal with its path. `tokens` (the look's
|
|
166
|
+
* rows) lets a CSS time be read through its token and asks that it BE one; without them only literal times are read.
|
|
167
|
+
*/
|
|
168
|
+
export function designMotionIssues(doc: Pick<DesignDoc, 'layout' | 'globals'>, options: { tokens?: ReadonlyArray<DesignTokenLike> } = {}): MotionIssue[] {
|
|
169
|
+
const nodes = [...doc.layout, ...doc.globals];
|
|
170
|
+
const curves = new Set((options.tokens ?? []).filter(t => t.type === EASING_TOKEN_TYPE).map(t => t.name));
|
|
171
|
+
const named = new Set<string>();
|
|
172
|
+
const types = new Map<string, string>();
|
|
173
|
+
walkSerialized(nodes, node => types.set(node.id, node.type));
|
|
174
|
+
walkSerialized(nodes, node => rowsOf(node).forEach((row, i) => (row?.actions ?? []).forEach((a, j) => {
|
|
175
|
+
const at = `layout:${node.id}.interactions[${i}].actions[${j}]`;
|
|
176
|
+
if (curves.has(String(a.easing ?? ''))) named.add(`${at}.easing`);
|
|
177
|
+
if (entranceCapExempt(a, types.get(elementOf(node, a)), curves)) named.add(`${at}.duration`);
|
|
178
|
+
})));
|
|
179
|
+
const out: MotionIssue[] = composerAudit(nodes, named);
|
|
180
|
+
const say = (rule: MotionRule, path: string, message: string) => out.push({ code: DesignIssueCode.Motion, rule, path, message });
|
|
181
|
+
const parents = new Map<string, string[]>();
|
|
182
|
+
const moves: Move[] = [];
|
|
183
|
+
walkSerialized(nodes, (node, ancestors) => {
|
|
184
|
+
const at = `layout:${node.id}`;
|
|
185
|
+
parents.set(node.id, ancestors.map(a => a.id));
|
|
186
|
+
styleIssues(node, at, options.tokens, say);
|
|
187
|
+
rowsOf(node).forEach((row, i) => (row?.actions ?? []).forEach((a, j) => {
|
|
188
|
+
const path = `${at}.interactions[${i}].actions[${j}]`;
|
|
189
|
+
const trigger = String(row.trigger ?? '');
|
|
190
|
+
const d = ELEMENT_ACTION_DESCRIPTORS.find(x => x.type === a.type);
|
|
191
|
+
if (!d) { say(MotionRule.Catalog, `${path}.type`, `"${a.type}" is not an action of the catalog`); return; }
|
|
192
|
+
if (!actionOfferedUnder(d, trigger)) { say(MotionRule.Catalog, `${path}.type`, `${a.type} is not offered under "${trigger}" — ${(d.triggers ?? []).join(', ')}`); return; }
|
|
193
|
+
moves.push({ element: elementOf(node, a), path, trigger, action: a });
|
|
194
|
+
}));
|
|
195
|
+
});
|
|
196
|
+
const entering = new Map<string, Move>();
|
|
197
|
+
for (const m of moves) {
|
|
198
|
+
if (MOTION_POINTER_TRIGGERS.has(m.trigger) && isMotion(m) && m.element === pathNode(m.path) && !isEntrance(m) && !isExit(m) && ms(m) > UI_MOTION_MAX_MS) {
|
|
199
|
+
say(MotionRule.Duration, `${m.path}.duration`, `${ms(m)}ms — what a pointer drives on the element itself plays under ${UI_MOTION_MAX_MS}ms`);
|
|
200
|
+
}
|
|
201
|
+
if (!isEntrance(m)) continue;
|
|
202
|
+
if (m.action.type === INSTANT_REVEAL) say(MotionRule.Reduced, `${m.path}.type`, `"show" is the instant reveal a click opens — an entrance that plays by itself fades, rises or reveals (reduced motion keeps a fade; it has none)`);
|
|
203
|
+
const first = entering.get(m.element);
|
|
204
|
+
if (first) say(MotionRule.OneEntrance, `${m.path}.type`, `"${m.element}" already enters (${first.path}) — one entrance per element; put a second move on a wrapper`);
|
|
205
|
+
else entering.set(m.element, m);
|
|
206
|
+
}
|
|
207
|
+
for (const [element, m] of entering) {
|
|
208
|
+
const above = (parents.get(element) ?? []).find(id => entering.has(id));
|
|
209
|
+
if (above) say(MotionRule.Container, `${m.path}.type`, `"${element}" enters inside "${above}", which enters too — one entrance per container: either the container rises or what it holds staggers in`);
|
|
210
|
+
}
|
|
211
|
+
for (const m of moves.filter(isExit)) {
|
|
212
|
+
const enter = entering.get(m.element);
|
|
213
|
+
if (enter && ms(enter) > 0 && ms(m) >= ms(enter)) {
|
|
214
|
+
say(MotionRule.Exit, `${m.path}.duration`, `${ms(m)}ms leaving against ${ms(enter)}ms entering — an exit is faster, about ${Math.round(ms(enter) * LEAVE_SHARE)}ms`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* AD-D23: an entrance the 1,200 ms cap lets pass — a count (its duration is the digits' clock), or a picture's ambient
|
|
222
|
+
* settle: `zoomOut` on an Image or a Video, at most `PICTURE_SETTLE_MAX_MS`, on an ease-out curve (the look's curve by
|
|
223
|
+
* name or var(), or a cubic-bezier that starts fast).
|
|
224
|
+
*/
|
|
225
|
+
function entranceCapExempt(a: Action, elementType: string | undefined, curves: ReadonlySet<string>): boolean {
|
|
226
|
+
if (a.type === COUNT_ACTION) return true;
|
|
227
|
+
if (a.type !== SETTLE_ACTION || !elementType || !MOTION_PICTURE_TYPES.has(elementType) || Number(a.duration ?? 0) > PICTURE_SETTLE_MAX_MS) return false;
|
|
228
|
+
const easing = String(a.easing ?? '').trim();
|
|
229
|
+
if (curves.has(easing) || /^var\(\s*--iox-ease-/.test(easing)) return true;
|
|
230
|
+
const m = CUBIC.exec(easing);
|
|
231
|
+
return !!m && Number(m[2]) > Number(m[1]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The node id a move's path is written on. */
|
|
235
|
+
function pathNode(path: string): string {
|
|
236
|
+
return /^layout:([^.]*)/.exec(path)?.[1] ?? '';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** One key per issue — what is new after an op is what that op did. */
|
|
240
|
+
export const motionIssueKey = (i: MotionIssue) => `${i.rule}|${i.path}|${i.message}`;
|
|
241
|
+
|
|
242
|
+
/** The rules' order, for a report: how many of each. */
|
|
243
|
+
export function motionIssueCounts(issues: ReadonlyArray<MotionIssue>): Partial<Record<MotionRule, number>> {
|
|
244
|
+
const out: Partial<Record<MotionRule, number>> = {};
|
|
245
|
+
for (const i of issues) out[i.rule] = (out[i.rule] ?? 0) + 1;
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
@@ -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
|
+
}
|