@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.
@@ -1,4 +1,5 @@
1
- import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized } from '@vectoriox/iox-ui/generation-core';
1
+ import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized, AdjustKind, AdjustAxis, adjustStepOf, ADJUST_STEPS, NODE_BASELINES, adjustStyleProps, ADJUST_AXIS_LABELS, adjustStepLabel } from '@vectoriox/iox-ui/generation-core';
2
+ import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle } from '@vectoriox/iox-ui/design-core';
2
3
 
3
4
  /**
4
5
  * The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
@@ -96,7 +97,7 @@ const SURFACES = {
96
97
  // Style, Sections and Look & motion join as each slice ships (ai-assist-plan §6, AI2).
97
98
  [AssistSurface.BuilderPage]: spec({
98
99
  surface: AssistSurface.BuilderPage,
99
- families: [EditFamily.Words],
100
+ families: [EditFamily.Words, EditFamily.Style],
100
101
  commit: CommitKind.BuilderStep,
101
102
  steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
102
103
  permissions: [AssistPermission.PageUpdate],
@@ -1012,6 +1013,344 @@ function turnLocale(sentence, fields, values, uiLang) {
1012
1013
  /** The language's own name in the admin's language (`en` → "English" / "אנגלית"). */
1013
1014
  const languageName = (locale, uiLang) => displayName(locale, uiLang) ?? locale;
1014
1015
 
1016
+ /**
1017
+ * Surface S1 (the builder, this page), family `style` (ai-assist-plan §4, AI2b; ai-session-panel-plan `setStyle` /
1018
+ * `setScheme`): an element takes ANOTHER of the look's element styles, a section (or a box) another colour scheme — never
1019
+ * a CSS value, a colour or a size. What a node may take is a closed list: the other members of the swap set its current
1020
+ * style is in that its type may wear ({@link ASK_STYLE_SETS}). The SAME pure functions run on the server (the check on a
1021
+ * copy) and in the builder (the trial): `pageLooks` (the targets and their handles), `styleJsonSchema`,
1022
+ * `decodeStyleAnswers`, `applyStyleEdits` — design-core's `switchElementStyle` (the author's own changes are kept) and
1023
+ * `setColorScheme` (the ONE scheme writer), all or none.
1024
+ *
1025
+ * AI2c adds SIZE STEPS to the same family: a section's height and spacing, a card's or panel's padding, where words sit
1026
+ * — each a row of generation-core `ADJUSTMENTS` (the only place their values come from), never a number the model wrote.
1027
+ */
1028
+ /**
1029
+ * The styles an owner may swap between by asking — each set is ONE kind of thing (a button, a heading, words, a box, a
1030
+ * badge). Every other element style (a tab, an accordion part, a cart button, the navigation bar) belongs to the recipe
1031
+ * that stamped it and is never offered. A node wearing a style is offered the union of the sets that style is in, kept
1032
+ * to the styles its type may wear (design-core `elementStylesFor`).
1033
+ */
1034
+ const ASK_STYLE_SETS = [
1035
+ ['button-primary', 'button-secondary', 'button-ghost'],
1036
+ ['display', 'h1', 'h2', 'h3', 'eyebrow'],
1037
+ ['lead', 'body', 'small', 'eyebrow'],
1038
+ ['section', 'box', 'card', 'panel'],
1039
+ ['badge-neutral', 'badge-success', 'badge-warning', 'badge-accent'],
1040
+ ];
1041
+ /** A box that only holds things — offered a style only when it is the selection ("make this a card"). */
1042
+ const PLAIN_BOX_STYLE = 'box';
1043
+ /** A box wearing one of these paints its own ground — a colour scheme shows on it. */
1044
+ const SURFACE_STYLES = new Set(['section', 'card', 'panel']);
1045
+ const paintsGround = (style) => SURFACE_STYLES.has(style ?? '');
1046
+ /** A Text wearing this is a ButtonBlock's words: the button is the style target. */
1047
+ const BUTTON_LABEL_STYLE$1 = 'button-label';
1048
+ /** The words types whose line alignment may be asked for (a button's or a link's words sit as their button does). */
1049
+ const ALIGNABLE_TYPES = new Set(['Heading', 'Text']);
1050
+ /** Boxes whose padding is a framed box's (`--iox-space-pad`). */
1051
+ const PADDED_STYLES = new Set(['card', 'panel']);
1052
+ /** A Scene, or a section holding a pinned (sticky) part, owns its height — it plays over the scroll it is given. */
1053
+ function ownsItsHeight(root) {
1054
+ let owns = false;
1055
+ walkSerialized([root], n => { if (n.role === 'scene' || n.styleProps?.['position'] === 'sticky')
1056
+ owns = true; });
1057
+ return owns;
1058
+ }
1059
+ /**
1060
+ * The size axes a node may be stepped on, and which kind each acts as (AI2c): a section root its height and rhythm, a
1061
+ * card or panel its padding, a heading or text its alignment. A node that is none of these takes no step.
1062
+ */
1063
+ function adjustAxesOf(node, isRoot, carriesWords) {
1064
+ const axes = {};
1065
+ if (isRoot) {
1066
+ if (!ownsItsHeight(node))
1067
+ axes[AdjustAxis.Height] = AdjustKind.Section;
1068
+ axes[AdjustAxis.Spacing] = AdjustKind.Section;
1069
+ }
1070
+ else if (PADDED_STYLES.has(node.elementStyle ?? '')) {
1071
+ axes[AdjustAxis.Spacing] = AdjustKind.Box;
1072
+ }
1073
+ if (carriesWords && ALIGNABLE_TYPES.has(node.type) && node.elementStyle !== BUTTON_LABEL_STYLE$1)
1074
+ axes[AdjustAxis.Align] = AdjustKind.Words;
1075
+ return axes;
1076
+ }
1077
+ /** The styles a node may take by asking — its own among them — or [] when it is not a target. */
1078
+ function askableStyles(node) {
1079
+ const current = node.elementStyle;
1080
+ if (!current)
1081
+ return [];
1082
+ const wears = new Set(elementStylesFor(node.type).map(s => s.id));
1083
+ const offered = new Set(ASK_STYLE_SETS.filter(set => set.includes(current)).flat().filter(id => wears.has(id)));
1084
+ return offered.size > 1 ? [...offered] : [];
1085
+ }
1086
+ const isRecipePart = (node) => !!node.role && node.role.includes('.');
1087
+ /**
1088
+ * Every style / scheme target of the page in reading order. A node that carries words keeps its words handle
1089
+ * (`wordHandles`: node id → `s0.heading1`); a ButtonBlock is named by its words' handle (`s0.button1`); a section root is
1090
+ * `s{i}`; any other box is `s{i}.box{n}`. `selectedId` lets a plain box that is the selection be a target.
1091
+ */
1092
+ function pageLooks(layout, wordHandles, selectedId) {
1093
+ const out = [];
1094
+ layout.forEach((root, index) => {
1095
+ let boxes = 0;
1096
+ const visit = (node, lineage) => {
1097
+ const here = [...lineage, node.id];
1098
+ const styles = askableStyles(node);
1099
+ const isRoot = node === root;
1100
+ const plain = node.elementStyle === PLAIN_BOX_STYLE && !isRoot && node.id !== selectedId;
1101
+ const takesStyle = styles.length > 0 && !plain && !(isRecipePart(node) && !wordHandles.has(node.id) && node.type !== 'ButtonBlock');
1102
+ const scheme = colorSchemeOf(node) ?? ColorScheme.Default;
1103
+ // A scheme re-declares tokens: only a node that paints a ground of its own (a section, card or panel style) shows
1104
+ // it — on any other the words take the scheme's ink over the page's ground (white on white). A node that may
1105
+ // TAKE such a style is offered one too; the check refuses the scheme unless the turn gives it that style.
1106
+ const takesScheme = COLOR_SCHEME_TYPES.includes(node.type) && !isRecipePart(node)
1107
+ && (paintsGround(node.elementStyle) || scheme !== ColorScheme.Default || (takesStyle && styles.some(paintsGround)));
1108
+ const axes = adjustAxesOf(node, isRoot, wordHandles.has(node.id));
1109
+ const sized = Object.entries(axes);
1110
+ if (takesStyle || takesScheme || sized.length) {
1111
+ const handle = lookHandle(node, index, isRoot, wordHandles, () => ++boxes);
1112
+ if (handle) {
1113
+ out.push({
1114
+ look: {
1115
+ handle,
1116
+ label: lookLabel(handle, root, index),
1117
+ ...(takesStyle ? { style: node.elementStyle, styles } : {}),
1118
+ ...(takesScheme ? { scheme } : {}),
1119
+ ...(sized.length ? { sizes: Object.fromEntries(sized.map(([axis, kind]) => [axis, adjustStepOf(axis, kind, node.styleProps)])) } : {}),
1120
+ },
1121
+ axes, section: index, nodeId: node.id, type: node.type, lineage: here,
1122
+ });
1123
+ }
1124
+ }
1125
+ for (const child of node.children ?? [])
1126
+ visit(child, here);
1127
+ };
1128
+ visit(root, []);
1129
+ });
1130
+ return out;
1131
+ }
1132
+ function lookHandle(node, section, isRoot, wordHandles, nextBox) {
1133
+ if (isRoot)
1134
+ return `s${section}`;
1135
+ const own = wordHandles.get(node.id);
1136
+ if (own)
1137
+ return own;
1138
+ if (node.type === 'ButtonBlock') {
1139
+ const label = (node.children ?? []).find(c => c.type === 'Text' && c.elementStyle === BUTTON_LABEL_STYLE$1);
1140
+ return label ? wordHandles.get(label.id) ?? null : null;
1141
+ }
1142
+ return `s${section}.box${nextBox()}`;
1143
+ }
1144
+ const capitalise$1 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
1145
+ /** "Hero · ground" → "Hero"; a composed section's id label ("hero-1") reads as words; else "Section 3". */
1146
+ function sectionLabel(node, index) {
1147
+ const own = (node.label ?? '').split(' · ')[0].trim();
1148
+ return own ? capitalise$1(own.replace(/[-_]+/g, ' ')) : `Section ${index + 1}`;
1149
+ }
1150
+ /** `s0` → the section's own name; `s0.box2` → "Box 2"; `s1.heading1` → "Heading 1". */
1151
+ function lookLabel(handle, root, index) {
1152
+ const tail = handle.split('.').slice(1).join(' ');
1153
+ if (!tail)
1154
+ return sectionLabel(root, index);
1155
+ return tail.replace(/^([a-z]+)(\d+)/, (_, k, n) => `${capitalise$1(k)} ${n}`);
1156
+ }
1157
+ /** The labels of the styles and schemes a brief mentions — the model reads ids, the owner reads these. */
1158
+ function lookNames(looks) {
1159
+ const styles = {};
1160
+ for (const look of looks)
1161
+ for (const id of look.styles ?? [])
1162
+ styles[id] = elementStyleById(id)?.label ?? id;
1163
+ const schemes = looks.some(l => l.scheme) ? Object.fromEntries(COLOR_SCHEMES.map(s => [s.id, s.label])) : {};
1164
+ return { styles, schemes };
1165
+ }
1166
+ var StyleAnswerKey;
1167
+ (function (StyleAnswerKey) {
1168
+ StyleAnswerKey["Styles"] = "styles";
1169
+ StyleAnswerKey["Schemes"] = "schemes";
1170
+ StyleAnswerKey["Sizes"] = "sizes";
1171
+ StyleAnswerKey["Note"] = "note";
1172
+ })(StyleAnswerKey || (StyleAnswerKey = {}));
1173
+ /**
1174
+ * The strict format of family `style` for the focus — ONE request: a list of `{ handle, style }` and a list of
1175
+ * `{ handle, scheme }`, each handle an enum of the focus's targets ([] leaves everything as it is). A list whose enum
1176
+ * would be empty is left out. The pairing (does THIS handle take THAT style) is the check's, so the format stays small
1177
+ * whatever the page holds.
1178
+ */
1179
+ function styleJsonSchema(looks) {
1180
+ const styled = Object.entries(looks).filter(([, t]) => t.styles.length);
1181
+ const schemed = Object.entries(looks).filter(([, t]) => t.scheme);
1182
+ const sized = Object.entries(looks).filter(([, t]) => Object.keys(t.sizes ?? {}).length);
1183
+ if (!styled.length && !schemed.length && !sized.length)
1184
+ return { parts: [], handles: [] };
1185
+ const properties = {};
1186
+ if (styled.length) {
1187
+ const ids = [...new Set(styled.flatMap(([, t]) => t.styles))];
1188
+ properties[StyleAnswerKey.Styles] = {
1189
+ ...jsonListOf(jsonClosedObject({
1190
+ handle: jsonOneOf(styled.map(([h]) => h)),
1191
+ style: jsonOneOf(ids),
1192
+ }, ['handle', 'style'])),
1193
+ description: 'An element taking another of the styles the focus lists for it; [] changes no style.',
1194
+ };
1195
+ }
1196
+ if (schemed.length) {
1197
+ properties[StyleAnswerKey.Schemes] = {
1198
+ ...jsonListOf(jsonClosedObject({
1199
+ handle: jsonOneOf(schemed.map(([h]) => h)),
1200
+ scheme: jsonOneOf(COLOR_SCHEMES.map(s => s.id)),
1201
+ }, ['handle', 'scheme'])),
1202
+ description: 'A section or box taking another colour scheme; [] changes no colours.',
1203
+ };
1204
+ }
1205
+ if (sized.length) {
1206
+ const axes = [...new Set(sized.flatMap(([, t]) => Object.keys(t.sizes ?? {})))];
1207
+ properties[StyleAnswerKey.Sizes] = {
1208
+ ...jsonListOf(jsonClosedObject({
1209
+ handle: jsonOneOf(sized.map(([h]) => h)),
1210
+ axis: jsonOneOf(axes),
1211
+ step: jsonOneOf([...new Set(axes.flatMap(a => ADJUST_STEPS[a].map(s => s.id)))]),
1212
+ }, ['handle', 'axis', 'step'])),
1213
+ description: 'An element stepped on one of the size axes the focus lists for it; [] changes no size.',
1214
+ };
1215
+ }
1216
+ properties[StyleAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
1217
+ const part = jsonClosedObject(properties, Object.keys(properties));
1218
+ assertAssistBudget('style', [part]);
1219
+ return { parts: [part], handles: [[...new Set([...styled, ...schemed, ...sized].map(([h]) => h))]] };
1220
+ }
1221
+ const listOf = (answer, key) => {
1222
+ const list = answer && typeof answer === 'object' ? answer[key] : undefined;
1223
+ return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
1224
+ };
1225
+ /** The answer → the edits it makes. */
1226
+ function decodeStyleAnswers(answers) {
1227
+ return answers.flatMap(answer => [
1228
+ ...listOf(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
1229
+ ...listOf(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
1230
+ ...listOf(answer, StyleAnswerKey.Sizes).map(x => ({ handle: String(x['handle'] ?? ''), axis: String(x['axis'] ?? ''), step: String(x['step'] ?? '') })),
1231
+ ]);
1232
+ }
1233
+ const isStyleEdit = (e) => typeof e.style === 'string';
1234
+ const isSchemeEdit = (e) => typeof e.scheme === 'string';
1235
+ const isSizeEdit = (e) => typeof e.axis === 'string' && typeof e.step === 'string';
1236
+ /** Which kind of change a change card shows. */
1237
+ var PageChangeOp;
1238
+ (function (PageChangeOp) {
1239
+ PageChangeOp["Words"] = "words";
1240
+ PageChangeOp["Style"] = "style";
1241
+ PageChangeOp["Scheme"] = "scheme";
1242
+ PageChangeOp["Size"] = "size";
1243
+ })(PageChangeOp || (PageChangeOp = {}));
1244
+ /** The serialized baseline: the type's constructor values, its text colour released as a new node's is (generation-core `createSerializedNode`). */
1245
+ const serializedBaselineStyles = type => {
1246
+ const own = { ...(NODE_BASELINES[type]?.styleProps ?? {}) };
1247
+ for (const [name, value] of Object.entries(NEW_NODE_STYLE_DEFAULTS))
1248
+ if (name in own)
1249
+ own[name] = value;
1250
+ return own;
1251
+ };
1252
+ const schemeLabel = (id) => COLOR_SCHEMES.find(s => s.id === id)?.label ?? id;
1253
+ const styleLabel = (id) => elementStyleById(id)?.label ?? id;
1254
+ /**
1255
+ * Family `style`, applied — the SAME check on the server and in the builder. All or none; never mutates its input. A
1256
+ * handle not in the focus, a style the target may not take, a scheme on a target that takes none are refused (re-asked
1257
+ * once by the server, never repaired here); an edit that changes nothing is dropped.
1258
+ */
1259
+ function applyStyleEdits(layout, edits, ctx) {
1260
+ const result = JSON.parse(JSON.stringify(layout));
1261
+ const byId = new Map();
1262
+ walkSerialized(result, n => byId.set(n.id, n));
1263
+ const baseline = ctx.baseline ?? serializedBaselineStyles;
1264
+ const issues = [];
1265
+ const changes = [];
1266
+ const seen = new Set();
1267
+ // Styles first: a scheme may need the style the same turn gives its node (a plain box made a panel, then darkened);
1268
+ // size steps last, over what the style switch released.
1269
+ const ordered = [
1270
+ ...edits.filter(e => !isSchemeEdit(e) && !isSizeEdit(e)), ...edits.filter(isSchemeEdit), ...edits.filter(isSizeEdit),
1271
+ ];
1272
+ for (const edit of ordered) {
1273
+ const scheme = isSchemeEdit(edit);
1274
+ const size = isSizeEdit(edit);
1275
+ const key = size ? `size:${edit.handle}:${edit.axis}` : `${scheme ? 'scheme' : 'style'}:${edit.handle}`;
1276
+ const refuse = (code, message) => issues.push({ code, handle: edit.handle, message });
1277
+ if (seen.has(key)) {
1278
+ refuse(AssistIssueCode.Duplicate, `"${edit.handle}" is given two ${size ? `${edit.axis} steps` : scheme ? 'schemes' : 'styles'}`);
1279
+ continue;
1280
+ }
1281
+ seen.add(key);
1282
+ const target = Object.prototype.hasOwnProperty.call(ctx.looks, edit.handle) ? ctx.looks[edit.handle] : undefined;
1283
+ const node = target ? byId.get(target.id) : undefined;
1284
+ if (!target || !node) {
1285
+ refuse(AssistIssueCode.UnknownHandle, `"${edit.handle}" is not an element of the focus`);
1286
+ continue;
1287
+ }
1288
+ if (size) {
1289
+ const axis = edit.axis;
1290
+ const kind = Object.prototype.hasOwnProperty.call(target.sizes ?? {}, axis) ? target.sizes[axis] : undefined;
1291
+ if (!kind) {
1292
+ const takes = Object.keys(target.sizes ?? {});
1293
+ refuse(AssistIssueCode.NotAnOption, `${target.label} takes no ${edit.axis} step${takes.length ? ` — only ${takes.join(', ')}` : ''}`);
1294
+ continue;
1295
+ }
1296
+ const props = adjustStyleProps(axis, kind, edit.step, node.styleProps);
1297
+ if (!props) {
1298
+ refuse(AssistIssueCode.NotAnOption, `${ADJUST_AXIS_LABELS[axis].toLowerCase()} takes ${ADJUST_STEPS[axis].map(s => `"${s.id}"`).join(', ')} — not "${edit.step}"`);
1299
+ continue;
1300
+ }
1301
+ const from = adjustStepOf(axis, kind, node.styleProps);
1302
+ if (from === edit.step)
1303
+ continue;
1304
+ node.styleProps = { ...(node.styleProps ?? {}), ...props };
1305
+ changes.push({
1306
+ op: PageChangeOp.Size, axis, handle: edit.handle, nodeId: node.id, label: `${target.label} · ${ADJUST_AXIS_LABELS[axis].toLowerCase()}`,
1307
+ from, to: edit.step, before: adjustStepLabel(axis, from), after: adjustStepLabel(axis, edit.step),
1308
+ });
1309
+ continue;
1310
+ }
1311
+ if (scheme) {
1312
+ const to = edit.scheme;
1313
+ if (!target.scheme) {
1314
+ refuse(AssistIssueCode.NotAnOption, `${target.label} takes no colour scheme`);
1315
+ continue;
1316
+ }
1317
+ if (!COLOR_SCHEMES.some(s => s.id === to)) {
1318
+ refuse(AssistIssueCode.NotAnOption, `"${to}" is not a colour scheme`);
1319
+ continue;
1320
+ }
1321
+ const from = colorSchemeOf(node) ?? ColorScheme.Default;
1322
+ if (to !== ColorScheme.Default && !paintsGround(node.elementStyle)) {
1323
+ refuse(AssistIssueCode.NotAnOption, `${target.label} paints no ground of its own — give it the section, card or panel style in the same answer, or leave its colours`);
1324
+ continue;
1325
+ }
1326
+ if (!setColorScheme(node, to))
1327
+ continue;
1328
+ changes.push({ op: PageChangeOp.Scheme, handle: edit.handle, nodeId: node.id, label: target.label, from, to, before: schemeLabel(from), after: schemeLabel(to) });
1329
+ continue;
1330
+ }
1331
+ const to = edit.style;
1332
+ if (!target.styles.includes(to)) {
1333
+ refuse(AssistIssueCode.NotAnOption, `${target.label} may take ${target.styles.map(s => `"${s}"`).join(', ')} — not "${to}"`);
1334
+ continue;
1335
+ }
1336
+ const from = node.elementStyle ?? '';
1337
+ if (from === to)
1338
+ continue;
1339
+ const switched = switchElementStyle(node, from, to, baseline(node.type));
1340
+ if (!switched.applied) {
1341
+ refuse(AssistIssueCode.NotAnOption, `"${to}" is not an element style`);
1342
+ continue;
1343
+ }
1344
+ changes.push({
1345
+ op: PageChangeOp.Style, handle: edit.handle, nodeId: node.id, label: target.label, from, to,
1346
+ before: styleLabel(from), after: styleLabel(to), ...(switched.kept.length ? { keptOwn: switched.kept.length } : {}),
1347
+ });
1348
+ }
1349
+ if (issues.length)
1350
+ return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
1351
+ return { ok: true, result, changes, issues: [] };
1352
+ }
1353
+
1015
1354
  /**
1016
1355
  * Surface S1 (the builder, this page), family `words` (ai-assist-plan §4, ai-session-panel-plan §3b–§3d): the page as
1017
1356
  * the model sees it — sections in order, each a handle (`s0`), the parts that carry words as handles (`s0.heading1`,
@@ -1062,11 +1401,6 @@ function readableWords(value) {
1062
1401
  }
1063
1402
  const sectionHandle = (index) => `s${index}`;
1064
1403
  const capitalise = (s) => s.charAt(0).toUpperCase() + s.slice(1);
1065
- /** "Hero · ground" → "Hero"; a composed section's id label ("hero-1") reads as words. */
1066
- function sectionLabel(node, index) {
1067
- const own = (node.label ?? '').split(' · ')[0].trim();
1068
- return own ? capitalise(own.replace(/[-_]+/g, ' ')) : `Section ${index + 1}`;
1069
- }
1070
1404
  function boundLabel(node, prop) {
1071
1405
  const b = (node.bindings ?? []).find(x => x.prop === prop);
1072
1406
  return b ? [b.source, b.path].filter(Boolean).join(' ▸ ') : undefined;
@@ -1133,6 +1467,11 @@ function summarizePage(layout, ctx) {
1133
1467
  const scope = selectedSection < 0 ? AssistScope.Page : asked;
1134
1468
  const inFocus = (w) => scope === AssistScope.Page || w.section === selectedSection;
1135
1469
  const selectedParts = scope === AssistScope.Node ? walked.filter(w => w.lineage.includes(ctx.selectedId)) : [];
1470
+ const wordHandles = new Map(walked.filter(w => !w.part.handle.split('.')[2]).map(w => [w.nodeId, w.part.handle]));
1471
+ const walkedLooks = pageLooks(layout, wordHandles, ctx.selectedId);
1472
+ const selectedWords = new Set(selectedParts.map(w => w.part.handle));
1473
+ const lookInFocus = (l) => scope === AssistScope.Page || (l.section === selectedSection
1474
+ && (scope === AssistScope.Section || l.lineage.includes(ctx.selectedId) || selectedWords.has(l.look.handle)));
1136
1475
  const sections = layout
1137
1476
  .map((root, index) => ({ root, index }))
1138
1477
  .filter(({ index }) => scope === AssistScope.Page || index === selectedSection)
@@ -1140,6 +1479,10 @@ function summarizePage(layout, ctx) {
1140
1479
  handle: sectionHandle(index),
1141
1480
  label: sectionLabel(root, index),
1142
1481
  parts: walked.filter(w => w.section === index).map(w => ({ ...w.part, words: clipText(w.part.words, FOCUS_TEXT_CHARS) })),
1482
+ ...(() => {
1483
+ const looks = walkedLooks.filter(l => l.section === index).map(l => l.look);
1484
+ return looks.length ? { looks } : {};
1485
+ })(),
1143
1486
  }));
1144
1487
  const around = layout
1145
1488
  .map((root, index) => ({ root, index }))
@@ -1156,6 +1499,14 @@ function summarizePage(layout, ctx) {
1156
1499
  handles[w.part.handle] = { key: w.prop, path: [], id: w.nodeId };
1157
1500
  }
1158
1501
  layout.forEach((root, index) => { nodes[sectionHandle(index)] = root.id; });
1502
+ const focusLooks = walkedLooks.filter(lookInFocus);
1503
+ const looks = Object.fromEntries(focusLooks.map(l => [l.look.handle, {
1504
+ id: l.nodeId, type: l.type, label: l.look.label, styles: [...(l.look.styles ?? [])], scheme: l.look.scheme !== undefined,
1505
+ ...(Object.keys(l.axes).length ? { sizes: { ...l.axes } } : {}),
1506
+ }]));
1507
+ for (const l of walkedLooks)
1508
+ nodes[l.look.handle] ??= l.nodeId;
1509
+ const names = lookNames(focusLooks.map(l => l.look));
1159
1510
  const focusWalked = scope === AssistScope.Node && selectedParts.length ? selectedParts : walked.filter(inFocus);
1160
1511
  const never = focusWalked.filter(w => w.part.bound)
1161
1512
  .map(w => ({ handle: w.part.handle, label: w.part.label, reason: `its words come from ${w.part.bound} — change them in that item` }));
@@ -1167,12 +1518,19 @@ function summarizePage(layout, ctx) {
1167
1518
  widensTo: WIDENS[scope] ?? [],
1168
1519
  };
1169
1520
  const selectedNode = selectedParts[0];
1521
+ const selectedLook = scope === AssistScope.Node ? focusLooks.find(l => l.nodeId === ctx.selectedId) : undefined;
1170
1522
  const focus = {
1171
1523
  scope,
1172
1524
  page: ctx.page,
1173
1525
  sections,
1174
- selected: selectedParts.map(w => w.part.handle),
1175
- ...(selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
1526
+ selected: [...new Set([
1527
+ ...selectedParts.map(w => w.part.handle),
1528
+ ...(scope === AssistScope.Node ? focusLooks.map(l => l.look.handle) : []),
1529
+ ])],
1530
+ ...(selectedLook ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedLook.look.label}` }
1531
+ : selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
1532
+ ...(Object.keys(names.styles).length ? { styleNames: names.styles } : {}),
1533
+ ...(Object.keys(names.schemes).length ? { schemeNames: names.schemes } : {}),
1176
1534
  };
1177
1535
  return {
1178
1536
  brief: {
@@ -1186,6 +1544,7 @@ function summarizePage(layout, ctx) {
1186
1544
  handles,
1187
1545
  focusHandles: focusWalked.filter(w => !w.part.bound).map(w => w.part.handle),
1188
1546
  nodes,
1547
+ looks,
1189
1548
  };
1190
1549
  }
1191
1550
  var WordsAnswerKey;
@@ -1316,7 +1675,7 @@ function applyWordEdits(layout, edits, ctx) {
1316
1675
  continue;
1317
1676
  written.push({ handle: edit.handle, text: readable });
1318
1677
  node.props = { ...(node.props ?? {}), [prop]: stored };
1319
- changes.push({ handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
1678
+ changes.push({ op: PageChangeOp.Words, handle: edit.handle, nodeId: node.id, ...partLabel(node, prop, edit.handle), before: readableWords(before), after: readable });
1320
1679
  }
1321
1680
  issues.push(...assistFactIssues(written, { words: ctx.words, sentence: ctx.sentence, existing: pageTexts(layout) }));
1322
1681
  if (issues.length)
@@ -1379,6 +1738,19 @@ function pageWriteLocale(layout, ctx) {
1379
1738
  return ctx.uiLang;
1380
1739
  }
1381
1740
 
1741
+ const isWordEdit = (e) => 'value' in e;
1742
+ function applyPageEdits(layout, edits, ctx) {
1743
+ const words = applyWordEdits(layout, edits.filter(isWordEdit), {
1744
+ handles: ctx.summary.handles, never: ctx.summary.brief.rules.never, sentence: ctx.sentence, words: ctx.words,
1745
+ });
1746
+ const looks = edits.filter((e) => !isWordEdit(e) && (isStyleEdit(e) || isSchemeEdit(e) || isSizeEdit(e)));
1747
+ const style = applyStyleEdits(words.result, looks, { looks: ctx.summary.looks, baseline: ctx.baseline });
1748
+ const issues = [...words.issues, ...style.issues];
1749
+ if (issues.length)
1750
+ return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
1751
+ return { ok: true, result: style.result, changes: [...words.changes, ...style.changes], issues: [] };
1752
+ }
1753
+
1382
1754
  /**
1383
1755
  * The turn wire (plan §3d) — what cms-client posts and polls and iox-cms stores and answers, ONE definition both sides
1384
1756
  * import (generation-core `ai-run.ts` is the precedent for generations). A turn is a document on the jobs runner:
@@ -1399,6 +1771,7 @@ const isTerminalTurn = (status) => TERMINAL.has(status);
1399
1771
  const ASSIST_MODEL_AUTO = 'auto';
1400
1772
  const ASSIST_POLL_MS = 750;
1401
1773
  const MAX_SENTENCE_CHARS = 2000;
1774
+ const isLookChange = (c) => 'op' in c && (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size);
1402
1775
  /** A turn's own refusals and failures, beside generation-core's `AiRefusalCode`s (credits, plan, key), which a turn returns as they are. */
1403
1776
  var AssistRefusalCode;
1404
1777
  (function (AssistRefusalCode) {
@@ -1463,7 +1836,7 @@ function assistSessionKey(surface, target = {}) {
1463
1836
  }
1464
1837
  const SENTENCE_IN_MEMORY_CHARS = 80;
1465
1838
  function outcome(turn) {
1466
- const named = (list) => (list ?? []).map(c => ('locale' in c && c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
1839
+ const named = (list) => (list ?? []).map(c => (isLookChange(c) ? `${c.label} → ${c.after}` : 'locale' in c && c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
1467
1840
  switch (turn.status) {
1468
1841
  case AssistTurnStatus.Refused: return `refused: ${turn.refusal?.message ?? ''}`.trim();
1469
1842
  case AssistTurnStatus.Failed: return 'failed';
@@ -1534,16 +1907,17 @@ function validateTurnRequest(req) {
1534
1907
  * request, and family `fields` for surface S2 (one content item) — its brief (`summarizeItem`), its strict output format
1535
1908
  * (`fieldsJsonSchema`) and the ONE check that applies an answer (`applyFieldEdits`), run by iox-cms on a copy and by
1536
1909
  * cms-client as the trial — and family `words` for surface S1 (the builder, this page): `summarizePage`, `wordsJsonSchema`,
1537
- * `applyWordEdits`, `pageSuggestions`. Every family's words pass ONE fact gate (`assistFactIssues` over generation-core's
1910
+ * `applyWordEdits`, `pageSuggestions` — and family `style` (`pageLooks`, `styleJsonSchema`, `applyStyleEdits`; both applied as
1911
+ * one turn by `applyPageEdits`). Every family's words pass ONE fact gate (`assistFactIssues` over generation-core's
1538
1912
  * `factIssues`, R-H2). Pure: no transport, no clock, no randomness.
1539
1913
  * ⚠️ Not re-exported from the main entry. Consumers wire the usual trio — ng-package raw-ts assets, jest
1540
1914
  * moduleNameMapper, tsconfig paths — or `nest start` dies with ERR_REQUIRE_ESM. It imports generation-core (the strict
1541
- * schema builders and budget), so a consumer maps both.
1915
+ * schema builders and budget) and design-core (element styles, schemes), so a consumer maps all three.
1542
1916
  */
1543
1917
 
1544
1918
  /**
1545
1919
  * Generated bundle index. Do not edit.
1546
1920
  */
1547
1921
 
1548
- export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PagePartKind, PageSuggestionKind, RouteAnswerKey, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, applyFieldEdits, applyWordEdits, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSessionOf, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, memoryLine, namedLocale, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sessionMemory, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
1922
+ export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistIssueCode, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PageChangeOp, PagePartKind, PageSuggestionKind, RouteAnswerKey, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, StyleAnswerKey, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, applyFieldEdits, applyPageEdits, applyStyleEdits, applyWordEdits, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeStyleAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSchemeEdit, isSessionOf, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookNames, memoryLine, namedLocale, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, serializedBaselineStyles, sessionMemory, styleJsonSchema, summarizeItem, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
1549
1923
  //# sourceMappingURL=vectoriox-iox-ui-assist-core.mjs.map