@vectoriox/iox-ui 5.117.0 → 5.119.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assist-core/index.d.ts +198 -6
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +388 -14
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +178 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +56 -2
- package/package.json +1 -1
- package/src/assist-core/assist-turn.ts +7 -4
- package/src/assist-core/page-edits.ts +40 -0
- package/src/assist-core/page-style.ts +448 -0
- package/src/assist-core/page-words.ts +38 -9
- package/src/assist-core/public-api.ts +5 -2
- package/src/assist-core/surfaces.ts +1 -1
- package/src/generation-core/adjustments.ts +182 -0
- package/src/generation-core/public-api.ts +1 -0
|
@@ -4,6 +4,7 @@ import { assistFactIssues, AssistWordContext } from './assist-facts';
|
|
|
4
4
|
import { namedLocale } from './assist-locale';
|
|
5
5
|
import { assertAssistBudget, MAX_ASSIST_PROPERTIES } from './budget';
|
|
6
6
|
import { AssistIssue, AssistIssueCode, Brief, BriefRules, HandleMap, NeverWrite, resolveHandle } from './brief';
|
|
7
|
+
import { LookMap, lookNames, PageChangeOp, PageLook, pageLooks, sectionLabel } from './page-style';
|
|
7
8
|
import { containsHtml, escapeText, paragraphsToRichText, richTextParagraphs } from './rich-text';
|
|
8
9
|
import { clipText } from './summarize-item';
|
|
9
10
|
import { AssistScope, AssistSurface, EditFamily, SURFACES } from './surfaces';
|
|
@@ -91,6 +92,8 @@ export interface PageSectionSummary {
|
|
|
91
92
|
/** The section's own name ("Hero", "Our work") or "Section 3". */
|
|
92
93
|
readonly label: string;
|
|
93
94
|
readonly parts: ReadonlyArray<PagePart>;
|
|
95
|
+
/** Family `style`: the elements of the section that may take another element style, colour scheme or size step. */
|
|
96
|
+
readonly looks?: ReadonlyArray<PageLook>;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
export interface PageFocus {
|
|
@@ -101,6 +104,9 @@ export interface PageFocus {
|
|
|
101
104
|
readonly selected: ReadonlyArray<string>;
|
|
102
105
|
/** The selection as the owner sees it ("Hero ▸ Heading 1"). */
|
|
103
106
|
readonly selectedLabel?: string;
|
|
107
|
+
/** How the owner reads the style and scheme ids the looks name. */
|
|
108
|
+
readonly styleNames?: Readonly<Record<string, string>>;
|
|
109
|
+
readonly schemeNames?: Readonly<Record<string, string>>;
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
export interface PageAround {
|
|
@@ -132,18 +138,14 @@ export interface SummarizedPage {
|
|
|
132
138
|
readonly focusHandles: ReadonlyArray<string>;
|
|
133
139
|
/** Every part of the page with its node id (for the client to outline a change) — never sent. */
|
|
134
140
|
readonly nodes: Readonly<Record<string, string>>;
|
|
141
|
+
/** Family `style`: the focus's targets — what a style request carries and the check may write. */
|
|
142
|
+
readonly looks: LookMap;
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
const sectionHandle = (index: number): string => `s${index}`;
|
|
138
146
|
|
|
139
147
|
const capitalise = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
140
148
|
|
|
141
|
-
/** "Hero · ground" → "Hero"; a composed section's id label ("hero-1") reads as words. */
|
|
142
|
-
function sectionLabel(node: SerializedNode, index: number): string {
|
|
143
|
-
const own = (node.label ?? '').split(' · ')[0].trim();
|
|
144
|
-
return own ? capitalise(own.replace(/[-_]+/g, ' ')) : `Section ${index + 1}`;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
149
|
function boundLabel(node: SerializedNode, prop: string): string | undefined {
|
|
148
150
|
const b = (node.bindings ?? []).find(x => x.prop === prop);
|
|
149
151
|
return b ? [b.source, b.path].filter(Boolean).join(' ▸ ') : undefined;
|
|
@@ -222,6 +224,12 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
222
224
|
const inFocus = (w: Walked) => scope === AssistScope.Page || w.section === selectedSection;
|
|
223
225
|
const selectedParts = scope === AssistScope.Node ? walked.filter(w => w.lineage.includes(ctx.selectedId!)) : [];
|
|
224
226
|
|
|
227
|
+
const wordHandles = new Map(walked.filter(w => !w.part.handle.split('.')[2]).map(w => [w.nodeId, w.part.handle]));
|
|
228
|
+
const walkedLooks = pageLooks(layout, wordHandles, ctx.selectedId);
|
|
229
|
+
const selectedWords = new Set(selectedParts.map(w => w.part.handle));
|
|
230
|
+
const lookInFocus = (l: (typeof walkedLooks)[number]) => scope === AssistScope.Page || (l.section === selectedSection
|
|
231
|
+
&& (scope === AssistScope.Section || l.lineage.includes(ctx.selectedId!) || selectedWords.has(l.look.handle)));
|
|
232
|
+
|
|
225
233
|
const sections: PageSectionSummary[] = layout
|
|
226
234
|
.map((root, index) => ({ root, index }))
|
|
227
235
|
.filter(({ index }) => scope === AssistScope.Page || index === selectedSection)
|
|
@@ -229,6 +237,10 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
229
237
|
handle: sectionHandle(index),
|
|
230
238
|
label: sectionLabel(root, index),
|
|
231
239
|
parts: walked.filter(w => w.section === index).map(w => ({ ...w.part, words: clipText(w.part.words, FOCUS_TEXT_CHARS) })),
|
|
240
|
+
...(() => {
|
|
241
|
+
const looks = walkedLooks.filter(l => l.section === index).map(l => l.look);
|
|
242
|
+
return looks.length ? { looks } : {};
|
|
243
|
+
})(),
|
|
232
244
|
}));
|
|
233
245
|
const around = layout
|
|
234
246
|
.map((root, index) => ({ root, index }))
|
|
@@ -245,6 +257,13 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
245
257
|
if (!w.part.bound) handles[w.part.handle] = { key: w.prop, path: [], id: w.nodeId };
|
|
246
258
|
}
|
|
247
259
|
layout.forEach((root, index) => { nodes[sectionHandle(index)] = root.id; });
|
|
260
|
+
const focusLooks = walkedLooks.filter(lookInFocus);
|
|
261
|
+
const looks: LookMap = Object.fromEntries(focusLooks.map(l => [l.look.handle, {
|
|
262
|
+
id: l.nodeId, type: l.type, label: l.look.label, styles: [...(l.look.styles ?? [])], scheme: l.look.scheme !== undefined,
|
|
263
|
+
...(Object.keys(l.axes).length ? { sizes: { ...l.axes } } : {}),
|
|
264
|
+
}]));
|
|
265
|
+
for (const l of walkedLooks) nodes[l.look.handle] ??= l.nodeId;
|
|
266
|
+
const names = lookNames(focusLooks.map(l => l.look));
|
|
248
267
|
|
|
249
268
|
const focusWalked = scope === AssistScope.Node && selectedParts.length ? selectedParts : walked.filter(inFocus);
|
|
250
269
|
const never: NeverWrite[] = focusWalked.filter(w => w.part.bound)
|
|
@@ -257,12 +276,19 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
257
276
|
widensTo: WIDENS[scope] ?? [],
|
|
258
277
|
};
|
|
259
278
|
const selectedNode = selectedParts[0];
|
|
279
|
+
const selectedLook = scope === AssistScope.Node ? focusLooks.find(l => l.nodeId === ctx.selectedId) : undefined;
|
|
260
280
|
const focus: PageFocus = {
|
|
261
281
|
scope,
|
|
262
282
|
page: ctx.page,
|
|
263
283
|
sections,
|
|
264
|
-
selected:
|
|
265
|
-
|
|
284
|
+
selected: [...new Set([
|
|
285
|
+
...selectedParts.map(w => w.part.handle),
|
|
286
|
+
...(scope === AssistScope.Node ? focusLooks.map(l => l.look.handle) : []),
|
|
287
|
+
])],
|
|
288
|
+
...(selectedLook ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedLook.look.label}` }
|
|
289
|
+
: selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
|
|
290
|
+
...(Object.keys(names.styles).length ? { styleNames: names.styles } : {}),
|
|
291
|
+
...(Object.keys(names.schemes).length ? { schemeNames: names.schemes } : {}),
|
|
266
292
|
};
|
|
267
293
|
return {
|
|
268
294
|
brief: {
|
|
@@ -276,6 +302,7 @@ export function summarizePage(layout: ReadonlyArray<SerializedNode>, ctx: PageBr
|
|
|
276
302
|
handles,
|
|
277
303
|
focusHandles: focusWalked.filter(w => !w.part.bound).map(w => w.part.handle),
|
|
278
304
|
nodes,
|
|
305
|
+
looks,
|
|
279
306
|
};
|
|
280
307
|
}
|
|
281
308
|
|
|
@@ -346,6 +373,8 @@ export function decodeWordsAnswers(answers: ReadonlyArray<unknown>): WordEdit[]
|
|
|
346
373
|
}
|
|
347
374
|
|
|
348
375
|
export interface WordChange {
|
|
376
|
+
/** Absent on a turn stored before AI2b — a words change. */
|
|
377
|
+
readonly op?: PageChangeOp.Words;
|
|
349
378
|
readonly handle: string;
|
|
350
379
|
/** The node the change is on — the builder outlines it; never sent to the model. */
|
|
351
380
|
readonly nodeId: string;
|
|
@@ -431,7 +460,7 @@ export function applyWordEdits(layout: ReadonlyArray<SerializedNode>, edits: Rea
|
|
|
431
460
|
if (readable === readableWords(before)) continue;
|
|
432
461
|
written.push({ handle: edit.handle, text: readable });
|
|
433
462
|
node.props = { ...(node.props ?? {}), [prop]: stored };
|
|
434
|
-
changes.push({ handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
|
|
463
|
+
changes.push({ op: PageChangeOp.Words, handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
|
|
435
464
|
}
|
|
436
465
|
|
|
437
466
|
issues.push(...assistFactIssues(written, { words: ctx.words, sentence: ctx.sentence, existing: pageTexts(layout) }));
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* request, and family `fields` for surface S2 (one content item) — its brief (`summarizeItem`), its strict output format
|
|
5
5
|
* (`fieldsJsonSchema`) and the ONE check that applies an answer (`applyFieldEdits`), run by iox-cms on a copy and by
|
|
6
6
|
* cms-client as the trial — and family `words` for surface S1 (the builder, this page): `summarizePage`, `wordsJsonSchema`,
|
|
7
|
-
* `applyWordEdits`, `pageSuggestions
|
|
7
|
+
* `applyWordEdits`, `pageSuggestions` — and family `style` (`pageLooks`, `styleJsonSchema`, `applyStyleEdits`; both applied as
|
|
8
|
+
* one turn by `applyPageEdits`). Every family's words pass ONE fact gate (`assistFactIssues` over generation-core's
|
|
8
9
|
* `factIssues`, R-H2). Pure: no transport, no clock, no randomness.
|
|
9
10
|
* ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest
|
|
10
11
|
* moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM. It imports generation-core (the strict
|
|
11
|
-
* schema builders and budget), so a consumer maps
|
|
12
|
+
* schema builders and budget) and design-core (element styles, schemes), so a consumer maps all three.
|
|
12
13
|
*/
|
|
13
14
|
export * from './surfaces';
|
|
14
15
|
export * from './budget';
|
|
@@ -22,5 +23,7 @@ export * from './route-schema';
|
|
|
22
23
|
export * from './assist-facts';
|
|
23
24
|
export * from './field-edits';
|
|
24
25
|
export * from './page-words';
|
|
26
|
+
export * from './page-style';
|
|
27
|
+
export * from './page-edits';
|
|
25
28
|
export * from './assist-turn';
|
|
26
29
|
export * from './assist-locale';
|
|
@@ -120,7 +120,7 @@ export const SURFACES: Readonly<Record<AssistSurface, SurfaceSpec>> = {
|
|
|
120
120
|
// Style, Sections and Look & motion join as each slice ships (ai-assist-plan §6, AI2).
|
|
121
121
|
[AssistSurface.BuilderPage]: spec({
|
|
122
122
|
surface: AssistSurface.BuilderPage,
|
|
123
|
-
families: [EditFamily.Words],
|
|
123
|
+
families: [EditFamily.Words, EditFamily.Style],
|
|
124
124
|
commit: CommitKind.BuilderStep,
|
|
125
125
|
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
126
126
|
permissions: [AssistPermission.PageUpdate],
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ADJUSTMENTS` — the size and spacing STEPS an element may take by asking (ai-session-panel-plan `adjust`, ai-assist-plan
|
|
3
|
+
* AI2c). "Make the hero taller" is a row of this table, never a number: the model picks an axis and a step, this file is
|
|
4
|
+
* the ONLY place their style literals come from, and every value is a token of the look wherever a token exists (the
|
|
5
|
+
* section rhythm `--iox-space-section`, a framed box's padding `--iox-space-pad`) — so a re-themed site keeps its steps in
|
|
6
|
+
* proportion. The same pure functions read the current step (`adjustStepOf`) and write a new one (`adjustStyleProps`) on
|
|
7
|
+
* the server's check and in the builder's trial.
|
|
8
|
+
*
|
|
9
|
+
* Every value is a desktop-first BASE value: a width the author (or the composer) set on its own keeps its own value.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** What a step changes. */
|
|
13
|
+
export enum AdjustAxis {
|
|
14
|
+
/** How tall a section stands: fit its content · tall · one screen. */
|
|
15
|
+
Height = 'height',
|
|
16
|
+
/** The space inside: a section's rhythm above and below, a card's or panel's padding all round. */
|
|
17
|
+
Spacing = 'spacing',
|
|
18
|
+
/** Where words sit on their line: start · centre · end (logical — follows the page's direction). */
|
|
19
|
+
Align = 'align',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Which kind of element an axis acts on — a section's spacing is its rhythm, a card's is its padding. */
|
|
23
|
+
export enum AdjustKind {
|
|
24
|
+
Section = 'section',
|
|
25
|
+
Box = 'box',
|
|
26
|
+
Words = 'words',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What a node holds when its value is none of the steps — the author's (or the composer's) own. */
|
|
30
|
+
export const ADJUST_OWN = 'own';
|
|
31
|
+
|
|
32
|
+
export interface AdjustStep {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/** How the owner reads it on a change card. */
|
|
35
|
+
readonly label: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The steps of each axis, smallest first. */
|
|
39
|
+
export const ADJUST_STEPS: Readonly<Record<AdjustAxis, ReadonlyArray<AdjustStep>>> = {
|
|
40
|
+
[AdjustAxis.Height]: [
|
|
41
|
+
{ id: 'fit', label: 'Fits its content' },
|
|
42
|
+
{ id: 'tall', label: 'Tall' },
|
|
43
|
+
{ id: 'screen', label: 'One screen' },
|
|
44
|
+
],
|
|
45
|
+
[AdjustAxis.Spacing]: [
|
|
46
|
+
{ id: 'tight', label: 'Tight' },
|
|
47
|
+
{ id: 'normal', label: 'Normal' },
|
|
48
|
+
{ id: 'airy', label: 'Airy' },
|
|
49
|
+
],
|
|
50
|
+
[AdjustAxis.Align]: [
|
|
51
|
+
{ id: 'start', label: 'Start' },
|
|
52
|
+
{ id: 'center', label: 'Centre' },
|
|
53
|
+
{ id: 'end', label: 'End' },
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const ADJUST_AXIS_LABELS: Readonly<Record<AdjustAxis, string>> = {
|
|
58
|
+
[AdjustAxis.Height]: 'Height',
|
|
59
|
+
[AdjustAxis.Spacing]: 'Spacing',
|
|
60
|
+
[AdjustAxis.Align]: 'Alignment',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const SECTION_SPACE = 'var(--iox-space-section)';
|
|
64
|
+
const BOX_PAD = 'var(--iox-space-pad)';
|
|
65
|
+
/** The section style's padding (`--iox-section-pad` = `var(--iox-space-section) var(--iox-space-gutter)`). */
|
|
66
|
+
const SECTION_PAD = 'var(--iox-section-pad)';
|
|
67
|
+
const SECTION_GUTTER = 'var(--iox-space-gutter)';
|
|
68
|
+
|
|
69
|
+
const scaled = (token: string, by: number) => by === 1 ? token : `calc(${token} * ${by})`;
|
|
70
|
+
|
|
71
|
+
/** A step's scale of the axis's token (spacing). */
|
|
72
|
+
const SPACING_SCALE: Readonly<Record<string, number>> = { tight: 0.5, normal: 1, airy: 1.5 };
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* THE table: per axis and kind, the style props each step writes. Spacing on a section writes only the block (top and
|
|
76
|
+
* bottom) half of its padding — the sides stay the section's own (`adjustStyleProps`).
|
|
77
|
+
*/
|
|
78
|
+
export const ADJUSTMENTS: Readonly<Record<AdjustAxis, Partial<Record<AdjustKind, Readonly<Record<string, Readonly<Record<string, string>>>>>>>> = {
|
|
79
|
+
[AdjustAxis.Height]: {
|
|
80
|
+
[AdjustKind.Section]: {
|
|
81
|
+
fit: { height: 'auto', minHeight: '0px' },
|
|
82
|
+
tall: { height: 'auto', minHeight: '70svh' },
|
|
83
|
+
screen: { height: 'auto', minHeight: '100svh' },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
[AdjustAxis.Spacing]: {
|
|
87
|
+
[AdjustKind.Section]: Object.fromEntries(Object.entries(SPACING_SCALE).map(([id, by]) => [id, { paddingBlock: scaled(SECTION_SPACE, by) }])),
|
|
88
|
+
[AdjustKind.Box]: Object.fromEntries(Object.entries(SPACING_SCALE).map(([id, by]) => [id, { padding: scaled(BOX_PAD, by) }])),
|
|
89
|
+
},
|
|
90
|
+
[AdjustAxis.Align]: {
|
|
91
|
+
[AdjustKind.Words]: {
|
|
92
|
+
start: { textAlign: 'start' },
|
|
93
|
+
center: { textAlign: 'center' },
|
|
94
|
+
end: { textAlign: 'end' },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Split a CSS value on its top-level spaces (a `calc(a * b)` stays one part). */
|
|
100
|
+
export function splitCssValue(value: string): string[] {
|
|
101
|
+
const parts: string[] = [];
|
|
102
|
+
let depth = 0;
|
|
103
|
+
let current = '';
|
|
104
|
+
for (const ch of value.trim()) {
|
|
105
|
+
if (ch === '(') depth++;
|
|
106
|
+
if (ch === ')') depth = Math.max(0, depth - 1);
|
|
107
|
+
if (/\s/.test(ch) && depth === 0) {
|
|
108
|
+
if (current) parts.push(current);
|
|
109
|
+
current = '';
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
current += ch;
|
|
113
|
+
}
|
|
114
|
+
if (current) parts.push(current);
|
|
115
|
+
return parts;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A `padding` value as its four sides (top, right, bottom, left). The section style's pad token is read as its pair. */
|
|
119
|
+
function paddingSides(value: unknown): [string, string, string, string] {
|
|
120
|
+
const raw = typeof value === 'string' ? value.trim() : '';
|
|
121
|
+
if (!raw) return ['0px', '0px', '0px', '0px'];
|
|
122
|
+
if (raw === SECTION_PAD) return [SECTION_SPACE, SECTION_GUTTER, SECTION_SPACE, SECTION_GUTTER];
|
|
123
|
+
const p = splitCssValue(raw);
|
|
124
|
+
if (p.length === 1) return [p[0], p[0], p[0], p[0]];
|
|
125
|
+
if (p.length === 2) return [p[0], p[1], p[0], p[1]];
|
|
126
|
+
if (p.length === 3) return [p[0], p[1], p[2], p[1]];
|
|
127
|
+
return [p[0], p[1], p[2], p[3]];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Four sides back to the shortest `padding`; the section style's own pair is written as its token. */
|
|
131
|
+
function paddingValue([top, right, bottom, left]: [string, string, string, string]): string {
|
|
132
|
+
if (top === SECTION_SPACE && bottom === SECTION_SPACE && right === SECTION_GUTTER && left === SECTION_GUTTER) return SECTION_PAD;
|
|
133
|
+
if (right === left) return top === bottom ? (top === right ? top : `${top} ${right}`) : `${top} ${right} ${bottom}`;
|
|
134
|
+
return `${top} ${right} ${bottom} ${left}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const isStep = (axis: AdjustAxis, step: string) => ADJUST_STEPS[axis].some(s => s.id === step);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The style props a step writes on a node holding `styleProps` (merged by the caller), or null when the axis does not act
|
|
141
|
+
* on that kind or the step is not one of its rows. Section spacing keeps the node's own sides.
|
|
142
|
+
*/
|
|
143
|
+
export function adjustStyleProps(
|
|
144
|
+
axis: AdjustAxis, kind: AdjustKind, step: string, styleProps: Readonly<Record<string, unknown>> = {},
|
|
145
|
+
): Record<string, string> | null {
|
|
146
|
+
const row = ADJUSTMENTS[axis][kind]?.[step];
|
|
147
|
+
if (!row || !isStep(axis, step)) return null;
|
|
148
|
+
if (axis === AdjustAxis.Spacing && kind === AdjustKind.Section) {
|
|
149
|
+
const [, right, , left] = paddingSides(styleProps['padding']);
|
|
150
|
+
const block = row['paddingBlock'];
|
|
151
|
+
return { padding: paddingValue([block, right, block, left]) };
|
|
152
|
+
}
|
|
153
|
+
return { ...row };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The step a node's current values are, or {@link ADJUST_OWN} when they are none of the rows. */
|
|
157
|
+
export function adjustStepOf(axis: AdjustAxis, kind: AdjustKind, styleProps: Readonly<Record<string, unknown>> = {}): string {
|
|
158
|
+
const rows = ADJUSTMENTS[axis][kind];
|
|
159
|
+
if (!rows) return ADJUST_OWN;
|
|
160
|
+
const value = (name: string): string => String(styleProps[name] ?? '').trim();
|
|
161
|
+
for (const { id } of ADJUST_STEPS[axis]) {
|
|
162
|
+
const row = rows[id];
|
|
163
|
+
if (!row) continue;
|
|
164
|
+
if (axis === AdjustAxis.Spacing && kind === AdjustKind.Section) {
|
|
165
|
+
const [top, , bottom] = paddingSides(styleProps['padding']);
|
|
166
|
+
if (top === row['paddingBlock'] && bottom === row['paddingBlock']) return id;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
// `height: auto` is also what an unset height is.
|
|
170
|
+
if (Object.entries(row).every(([name, want]) => value(name) === want || (name === 'height' && want === 'auto' && !value(name)))) return id;
|
|
171
|
+
}
|
|
172
|
+
return ADJUST_OWN;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** How the owner reads a step id ("own" → "As set"). */
|
|
176
|
+
export function adjustStepLabel(axis: AdjustAxis, step: string): string {
|
|
177
|
+
if (step === ADJUST_OWN) return 'As set';
|
|
178
|
+
return ADJUST_STEPS[axis].find(s => s.id === step)?.label ?? step;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Every step id of every axis — the strict format's enum (which axis takes which step is the check's). */
|
|
182
|
+
export const ADJUST_STEP_IDS: ReadonlyArray<string> = [...new Set(Object.values(ADJUST_STEPS).flat().map(s => s.id))];
|