@vectoriox/iox-ui 5.120.0 → 5.122.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 +246 -18
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +692 -16
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assist-core/assist-turn.ts +6 -3
- package/src/assist-core/brief.ts +2 -0
- package/src/assist-core/page-edits.ts +33 -12
- package/src/assist-core/page-sections.ts +371 -0
- package/src/assist-core/page-style.ts +6 -3
- package/src/assist-core/page-words.ts +23 -1
- package/src/assist-core/public-api.ts +2 -0
- package/src/assist-core/site-look.ts +321 -0
- package/src/assist-core/surfaces.ts +6 -3
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
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, patternById, composeSection } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle, flavorPackById, parseHexColor, resolveDesignChoices, SPEC_AXES, stylePresetOfChoices, BETWEEN_IDS, ANIMATE_IDS, SCROLL_IDS, TINT_IDS, STYLE_PRESETS, stylePresetById, presetChoices, designTokenRows, auditDesignContrast } from '@vectoriox/iox-ui/design-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
|
|
@@ -81,6 +81,7 @@ var AssistPermission;
|
|
|
81
81
|
AssistPermission["PageDelete"] = "page_delete";
|
|
82
82
|
AssistPermission["StorageAll"] = "storage_all";
|
|
83
83
|
AssistPermission["ProductsAll"] = "products_all";
|
|
84
|
+
AssistPermission["SettingsAll"] = "settings_all";
|
|
84
85
|
})(AssistPermission || (AssistPermission = {}));
|
|
85
86
|
var SurfaceStatus;
|
|
86
87
|
(function (SurfaceStatus) {
|
|
@@ -93,14 +94,16 @@ const spec = (s) => ({
|
|
|
93
94
|
...s,
|
|
94
95
|
});
|
|
95
96
|
const SURFACES = {
|
|
96
|
-
// S1 offers only the families the server answers (the route can never pick one it cannot)
|
|
97
|
-
//
|
|
97
|
+
// S1 offers only the families the server answers (the route can never pick one it cannot). The look is the SITE's: it
|
|
98
|
+
// needs what Design ▸ Apply needs — the design row (settings) and the token rows (pages) — and the builder commits it
|
|
99
|
+
// through Design's own Apply, never as a page history step.
|
|
98
100
|
[AssistSurface.BuilderPage]: spec({
|
|
99
101
|
surface: AssistSurface.BuilderPage,
|
|
100
|
-
families: [EditFamily.Words, EditFamily.Style],
|
|
102
|
+
families: [EditFamily.Words, EditFamily.Style, EditFamily.Sections, EditFamily.Look],
|
|
101
103
|
commit: CommitKind.BuilderStep,
|
|
102
104
|
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
103
105
|
permissions: [AssistPermission.PageUpdate],
|
|
106
|
+
familyPermissions: { [EditFamily.Look]: [AssistPermission.SettingsAll, AssistPermission.PageCreate] },
|
|
104
107
|
scopes: [AssistScope.Node, AssistScope.Section, AssistScope.Page],
|
|
105
108
|
status: SurfaceStatus.Built,
|
|
106
109
|
}),
|
|
@@ -256,6 +259,8 @@ var AssistIssueCode;
|
|
|
256
259
|
AssistIssueCode["InventedFact"] = "inventedFact";
|
|
257
260
|
/** A word this site must not use. */
|
|
258
261
|
AssistIssueCode["AvoidWord"] = "avoidWord";
|
|
262
|
+
/** A look whose colours fail the contrast audit in a mode the site is worn in (family `look`, R4). */
|
|
263
|
+
AssistIssueCode["Contrast"] = "contrast";
|
|
259
264
|
})(AssistIssueCode || (AssistIssueCode = {}));
|
|
260
265
|
/** A caller's mistake building a brief (a focus that is not on the screen) — never a model answer. */
|
|
261
266
|
class AssistBriefError extends Error {
|
|
@@ -1218,16 +1223,16 @@ function styleJsonSchema(looks) {
|
|
|
1218
1223
|
assertAssistBudget('style', [part]);
|
|
1219
1224
|
return { parts: [part], handles: [[...new Set([...styled, ...schemed, ...sized].map(([h]) => h))]] };
|
|
1220
1225
|
}
|
|
1221
|
-
const listOf = (answer, key) => {
|
|
1226
|
+
const listOf$1 = (answer, key) => {
|
|
1222
1227
|
const list = answer && typeof answer === 'object' ? answer[key] : undefined;
|
|
1223
1228
|
return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
|
|
1224
1229
|
};
|
|
1225
1230
|
/** The answer → the edits it makes. */
|
|
1226
1231
|
function decodeStyleAnswers(answers) {
|
|
1227
1232
|
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'] ?? '') })),
|
|
1233
|
+
...listOf$1(answer, StyleAnswerKey.Styles).map(x => ({ handle: String(x['handle'] ?? ''), style: String(x['style'] ?? '') })),
|
|
1234
|
+
...listOf$1(answer, StyleAnswerKey.Schemes).map(x => ({ handle: String(x['handle'] ?? ''), scheme: String(x['scheme'] ?? '') })),
|
|
1235
|
+
...listOf$1(answer, StyleAnswerKey.Sizes).map(x => ({ handle: String(x['handle'] ?? ''), axis: String(x['axis'] ?? ''), step: String(x['step'] ?? '') })),
|
|
1231
1236
|
]);
|
|
1232
1237
|
}
|
|
1233
1238
|
const isStyleEdit = (e) => typeof e.style === 'string';
|
|
@@ -1240,6 +1245,9 @@ var PageChangeOp;
|
|
|
1240
1245
|
PageChangeOp["Style"] = "style";
|
|
1241
1246
|
PageChangeOp["Scheme"] = "scheme";
|
|
1242
1247
|
PageChangeOp["Size"] = "size";
|
|
1248
|
+
PageChangeOp["Section"] = "section";
|
|
1249
|
+
/** The site's look (family `look`, AI2e) — every page follows. */
|
|
1250
|
+
PageChangeOp["Look"] = "look";
|
|
1243
1251
|
})(PageChangeOp || (PageChangeOp = {}));
|
|
1244
1252
|
/** The serialized baseline: the type's constructor values, its text colour released as a new node's is (generation-core `createSerializedNode`). */
|
|
1245
1253
|
const serializedBaselineStyles = type => {
|
|
@@ -1351,6 +1359,655 @@ function applyStyleEdits(layout, edits, ctx) {
|
|
|
1351
1359
|
return { ok: true, result, changes, issues: [] };
|
|
1352
1360
|
}
|
|
1353
1361
|
|
|
1362
|
+
/**
|
|
1363
|
+
* Surface S1 (the builder, this page), family `sections` (ai-assist-plan AI2d; ai-session-panel-plan `addSection` /
|
|
1364
|
+
* `removeSection` / `moveSection` / `swapPattern`): a section is added, removed, moved or swapped for another — and every
|
|
1365
|
+
* section Ask adds is a library pattern stamped by generation-core's `composeSection`, the SAME recipe the builder palette's
|
|
1366
|
+
* ready-made sections and the composer use (R-H9). The model names a pattern from a closed list and a place by handle;
|
|
1367
|
+
* it never writes a node. The same pure functions run on the server (the check on a copy) and in the builder (the trial).
|
|
1368
|
+
*/
|
|
1369
|
+
/**
|
|
1370
|
+
* The library patterns Ask may add or swap to — those `composeSection` stamps on their own with no Site Plan behind
|
|
1371
|
+
* them. Not offered: headers and footers (globals), lists and products (they need a content source — a Pages & data
|
|
1372
|
+
* change), Scenes and the owner's film (the look's motion decides them, and a page holds one).
|
|
1373
|
+
*/
|
|
1374
|
+
const ASK_SECTION_PATTERNS = [
|
|
1375
|
+
'hero.split', 'hero.centered', 'hero.full-bleed-media', 'hero.stacked-editorial',
|
|
1376
|
+
'proof.logo-strip', 'proof.stat-row', 'proof.testimonial-single',
|
|
1377
|
+
'feature.triad', 'feature.alternating-rows', 'feature.icon-list', 'feature.tabbed',
|
|
1378
|
+
'story.long-form', 'story.timeline', 'story.quote-break',
|
|
1379
|
+
'cta.banner', 'cta.split-form', 'contact.simple', 'faq.accordion', 'pricing.tiers',
|
|
1380
|
+
];
|
|
1381
|
+
/** Where an added or moved section goes when it is first on the page. */
|
|
1382
|
+
const SECTION_START = 'start';
|
|
1383
|
+
/** The library pattern a section root was stamped from, by its label (the composer names a root by its pattern). */
|
|
1384
|
+
function sectionPatternOf(root) {
|
|
1385
|
+
const label = (root.label ?? '').split(' · ')[0].trim();
|
|
1386
|
+
if (!label)
|
|
1387
|
+
return undefined;
|
|
1388
|
+
return ASK_SECTION_PATTERNS.find(id => patternById(id)?.label === label);
|
|
1389
|
+
}
|
|
1390
|
+
/** The patterns Ask offers, as the model and the owner read them: id → its name ("Hero — words centred"). */
|
|
1391
|
+
function askSectionPatternNames() {
|
|
1392
|
+
return Object.fromEntries(ASK_SECTION_PATTERNS.map(id => [id, patternById(id)?.label ?? id]));
|
|
1393
|
+
}
|
|
1394
|
+
var SectionsAnswerKey;
|
|
1395
|
+
(function (SectionsAnswerKey) {
|
|
1396
|
+
SectionsAnswerKey["Add"] = "add";
|
|
1397
|
+
SectionsAnswerKey["Remove"] = "remove";
|
|
1398
|
+
SectionsAnswerKey["Move"] = "move";
|
|
1399
|
+
SectionsAnswerKey["Swap"] = "swap";
|
|
1400
|
+
SectionsAnswerKey["Note"] = "note";
|
|
1401
|
+
})(SectionsAnswerKey || (SectionsAnswerKey = {}));
|
|
1402
|
+
/**
|
|
1403
|
+
* The strict format of family `sections` — ONE request: `add [{pattern, after}]`, `remove [{handle}]`,
|
|
1404
|
+
* `move [{handle, after}]`, `swap [{handle, pattern}]`, `note`. Handles are enums of the page's sections (the focus's for
|
|
1405
|
+
* what may change), patterns an enum of {@link ASK_SECTION_PATTERNS}. Whether an op makes sense is the check's.
|
|
1406
|
+
*/
|
|
1407
|
+
function sectionsJsonSchema(sections) {
|
|
1408
|
+
const all = Object.keys(sections);
|
|
1409
|
+
const focus = all.filter(h => sections[h].focus);
|
|
1410
|
+
const places = [SECTION_START, ...all];
|
|
1411
|
+
const patterns = jsonOneOf([...ASK_SECTION_PATTERNS]);
|
|
1412
|
+
const properties = {
|
|
1413
|
+
[SectionsAnswerKey.Add]: {
|
|
1414
|
+
...jsonListOf(jsonClosedObject({ pattern: patterns, after: jsonOneOf(places) }, ['pattern', 'after'])),
|
|
1415
|
+
description: 'A new section from the library, placed after a section (or at the start); [] adds none.',
|
|
1416
|
+
},
|
|
1417
|
+
};
|
|
1418
|
+
if (focus.length) {
|
|
1419
|
+
properties[SectionsAnswerKey.Remove] = {
|
|
1420
|
+
...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus) }, ['handle'])),
|
|
1421
|
+
description: 'A section taken off the page; [] removes none.',
|
|
1422
|
+
};
|
|
1423
|
+
properties[SectionsAnswerKey.Move] = {
|
|
1424
|
+
...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus), after: jsonOneOf(places) }, ['handle', 'after'])),
|
|
1425
|
+
description: 'A section moved to after another (or to the start); [] moves none.',
|
|
1426
|
+
};
|
|
1427
|
+
properties[SectionsAnswerKey.Swap] = {
|
|
1428
|
+
...jsonListOf(jsonClosedObject({ handle: jsonOneOf(focus), pattern: patterns }, ['handle', 'pattern'])),
|
|
1429
|
+
description: 'A section redrawn as another library section, its words and pictures carried over; [] swaps none.',
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
properties[SectionsAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
|
|
1433
|
+
const part = jsonClosedObject(properties, Object.keys(properties));
|
|
1434
|
+
assertAssistBudget('sections', [part]);
|
|
1435
|
+
return { parts: [part], handles: [focus] };
|
|
1436
|
+
}
|
|
1437
|
+
const isSectionEdit = (e) => 'add' in e || 'remove' in e || 'move' in e || 'swap' in e;
|
|
1438
|
+
const listOf = (answer, key) => {
|
|
1439
|
+
const list = answer && typeof answer === 'object' ? answer[key] : undefined;
|
|
1440
|
+
return Array.isArray(list) ? list.filter((x) => !!x && typeof x === 'object') : [];
|
|
1441
|
+
};
|
|
1442
|
+
const str = (v) => String(v ?? '');
|
|
1443
|
+
/** The answer → the edits it makes. */
|
|
1444
|
+
function decodeSectionsAnswers(answers) {
|
|
1445
|
+
return answers.flatMap(answer => [
|
|
1446
|
+
...listOf(answer, SectionsAnswerKey.Swap).map(x => ({ swap: str(x['handle']), pattern: str(x['pattern']) })),
|
|
1447
|
+
...listOf(answer, SectionsAnswerKey.Remove).map(x => ({ remove: str(x['handle']) })),
|
|
1448
|
+
...listOf(answer, SectionsAnswerKey.Move).map(x => ({ move: str(x['handle']), after: str(x['after']) })),
|
|
1449
|
+
...listOf(answer, SectionsAnswerKey.Add).map(x => ({ add: str(x['pattern']), after: str(x['after']) })),
|
|
1450
|
+
]);
|
|
1451
|
+
}
|
|
1452
|
+
var SectionChangeKind;
|
|
1453
|
+
(function (SectionChangeKind) {
|
|
1454
|
+
SectionChangeKind["Add"] = "add";
|
|
1455
|
+
SectionChangeKind["Remove"] = "remove";
|
|
1456
|
+
SectionChangeKind["Move"] = "move";
|
|
1457
|
+
SectionChangeKind["Swap"] = "swap";
|
|
1458
|
+
})(SectionChangeKind || (SectionChangeKind = {}));
|
|
1459
|
+
/** Why a section cannot be redrawn as another: it holds what a swap would lose (a form, words from content, a Scene). */
|
|
1460
|
+
function swapBlocker(root) {
|
|
1461
|
+
let blocker = null;
|
|
1462
|
+
walkSerialized([root], n => {
|
|
1463
|
+
if (blocker)
|
|
1464
|
+
return;
|
|
1465
|
+
if (n.role === 'scene')
|
|
1466
|
+
blocker = 'it plays as a Scene';
|
|
1467
|
+
else if (n.type === 'Form')
|
|
1468
|
+
blocker = 'it holds a form';
|
|
1469
|
+
else if (n.type === 'Repeater' || (n.bindings ?? []).length)
|
|
1470
|
+
blocker = 'its words come from your content';
|
|
1471
|
+
});
|
|
1472
|
+
return blocker;
|
|
1473
|
+
}
|
|
1474
|
+
/** A section's parts a swap carries over, in reading order, by kind. */
|
|
1475
|
+
var CarryKind;
|
|
1476
|
+
(function (CarryKind) {
|
|
1477
|
+
CarryKind["Eyebrow"] = "eyebrow";
|
|
1478
|
+
CarryKind["Heading"] = "heading";
|
|
1479
|
+
CarryKind["Text"] = "text";
|
|
1480
|
+
CarryKind["Button"] = "button";
|
|
1481
|
+
CarryKind["Image"] = "image";
|
|
1482
|
+
})(CarryKind || (CarryKind = {}));
|
|
1483
|
+
/** A button the owner's words and link travel in — never a tab, a price switch or a cart button (their recipe's own). */
|
|
1484
|
+
const CARRIED_BUTTON_STYLES = new Set(['button-primary', 'button-secondary', 'button-ghost']);
|
|
1485
|
+
/** Words that belong to their recipe, not the owner's copy: a figure ("40+", a price), a badge — left where they are. */
|
|
1486
|
+
const KEPT_TEXT_STYLES = new Set(['price', 'badge-label']);
|
|
1487
|
+
function carryKind(n) {
|
|
1488
|
+
if (n.elementStyle === 'eyebrow' && (n.type === 'Heading' || n.type === 'Text'))
|
|
1489
|
+
return CarryKind.Eyebrow;
|
|
1490
|
+
if (n.type === 'Heading')
|
|
1491
|
+
return CarryKind.Heading;
|
|
1492
|
+
if (n.type === 'Text')
|
|
1493
|
+
return KEPT_TEXT_STYLES.has(n.elementStyle ?? '') ? null : CarryKind.Text;
|
|
1494
|
+
if (n.type === 'Image')
|
|
1495
|
+
return CarryKind.Image;
|
|
1496
|
+
return null;
|
|
1497
|
+
}
|
|
1498
|
+
function carryParts(root) {
|
|
1499
|
+
const out = { eyebrow: [], heading: [], text: [], button: [], image: [] };
|
|
1500
|
+
const visit = (n) => {
|
|
1501
|
+
if (n.type === 'ButtonBlock') {
|
|
1502
|
+
if (CARRIED_BUTTON_STYLES.has(n.elementStyle ?? ''))
|
|
1503
|
+
out.button.push(n);
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
const kind = carryKind(n);
|
|
1507
|
+
if (kind)
|
|
1508
|
+
out[kind].push(n);
|
|
1509
|
+
for (const c of n.children ?? [])
|
|
1510
|
+
visit(c);
|
|
1511
|
+
};
|
|
1512
|
+
for (const c of root.children ?? [])
|
|
1513
|
+
visit(c);
|
|
1514
|
+
return out;
|
|
1515
|
+
}
|
|
1516
|
+
const BUTTON_LINK_PROPS = ['tag', 'linkType', 'href', 'pageRoute', 'url', 'target'];
|
|
1517
|
+
const labelOf$1 = (button) => (button.children ?? []).find(c => c.type === 'Text');
|
|
1518
|
+
/** The owner's words and pictures, placed into the new section part for part (kind by kind, in order); how many found no place. */
|
|
1519
|
+
function carryOver(from, to) {
|
|
1520
|
+
const old = carryParts(from);
|
|
1521
|
+
const fresh = carryParts(to);
|
|
1522
|
+
let notPlaced = 0;
|
|
1523
|
+
for (const kind of Object.values(CarryKind)) {
|
|
1524
|
+
old[kind].forEach((source, i) => {
|
|
1525
|
+
const target = fresh[kind][i];
|
|
1526
|
+
if (!target) {
|
|
1527
|
+
const hasContent = kind === CarryKind.Image ? !!source.props['src'] : true;
|
|
1528
|
+
if (hasContent)
|
|
1529
|
+
notPlaced++;
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
if (kind === CarryKind.Image) {
|
|
1533
|
+
if (!source.props['src'])
|
|
1534
|
+
return;
|
|
1535
|
+
target.props = { ...target.props, src: source.props['src'], alt: source.props['alt'] ?? target.props['alt'] };
|
|
1536
|
+
}
|
|
1537
|
+
else if (kind === CarryKind.Button) {
|
|
1538
|
+
const words = labelOf$1(source);
|
|
1539
|
+
const into = labelOf$1(target);
|
|
1540
|
+
if (words && into)
|
|
1541
|
+
into.props = { ...into.props, content: words.props['content'] };
|
|
1542
|
+
const link = Object.fromEntries(BUTTON_LINK_PROPS.filter(k => k in source.props).map(k => [k, source.props[k]]));
|
|
1543
|
+
target.props = { ...target.props, ...link };
|
|
1544
|
+
}
|
|
1545
|
+
else {
|
|
1546
|
+
target.props = { ...target.props, content: source.props['content'] };
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
return notPlaced;
|
|
1551
|
+
}
|
|
1552
|
+
/** A stable id no node of the page holds (nor any of its parts' derived ids, `<id>-0-1`). */
|
|
1553
|
+
function stableIds(layout) {
|
|
1554
|
+
const taken = [];
|
|
1555
|
+
walkSerialized([...layout], n => taken.push(n.id));
|
|
1556
|
+
let n = 0;
|
|
1557
|
+
return () => {
|
|
1558
|
+
let id;
|
|
1559
|
+
do
|
|
1560
|
+
id = `ask-s${++n}`;
|
|
1561
|
+
while (taken.some(t => t === id || t.startsWith(`${id}-`)));
|
|
1562
|
+
taken.push(id);
|
|
1563
|
+
return id;
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
const patternName = (id) => patternById(id)?.label ?? id;
|
|
1567
|
+
/**
|
|
1568
|
+
* Family `sections`, applied — the SAME check on the server and in the builder. All or none; never mutates its input.
|
|
1569
|
+
* Swaps redraw in place, then removals, moves and additions, each placed by the ORIGINAL handles. Refused (re-asked once
|
|
1570
|
+
* by the server, never repaired): a handle not on the page or not in the focus, a pattern not offered, a section given two
|
|
1571
|
+
* changes, a place that is the section itself or one removed in the same answer, a swap of a section holding a form,
|
|
1572
|
+
* content-bound words or a Scene.
|
|
1573
|
+
*/
|
|
1574
|
+
function applySectionEdits(layout, edits, ctx) {
|
|
1575
|
+
const result = JSON.parse(JSON.stringify(layout));
|
|
1576
|
+
const issues = [];
|
|
1577
|
+
const changes = [];
|
|
1578
|
+
const newId = ctx.newId ?? stableIds(layout);
|
|
1579
|
+
const has = (h) => Object.prototype.hasOwnProperty.call(ctx.sections, h);
|
|
1580
|
+
const refuse = (handle, code, message) => issues.push({ code, handle, message });
|
|
1581
|
+
/** The sections as they stood — what "before" reads, and what a moved, swapped section is placed by. */
|
|
1582
|
+
const original = ctx.sections;
|
|
1583
|
+
/** The kinds of change each section was given: a swap may come with a move; a removal comes alone; no kind twice. */
|
|
1584
|
+
const touched = new Map();
|
|
1585
|
+
const removed = new Set(edits.filter((e) => 'remove' in e).map(e => e.remove));
|
|
1586
|
+
const changeable = (handle, kind) => {
|
|
1587
|
+
if (!has(handle)) {
|
|
1588
|
+
refuse(handle, AssistIssueCode.UnknownHandle, `"${handle}" is not a section of this page`);
|
|
1589
|
+
return null;
|
|
1590
|
+
}
|
|
1591
|
+
const target = ctx.sections[handle];
|
|
1592
|
+
if (!target.focus) {
|
|
1593
|
+
refuse(handle, AssistIssueCode.UnknownHandle, `${target.label} is not in the focus — widen the chip to change it`);
|
|
1594
|
+
return null;
|
|
1595
|
+
}
|
|
1596
|
+
const kinds = touched.get(handle) ?? new Set();
|
|
1597
|
+
if (kinds.has(kind) || (kinds.size && (kind === SectionChangeKind.Remove || kinds.has(SectionChangeKind.Remove)))) {
|
|
1598
|
+
refuse(handle, AssistIssueCode.Duplicate, `${target.label} is given two changes that cannot go together`);
|
|
1599
|
+
return null;
|
|
1600
|
+
}
|
|
1601
|
+
touched.set(handle, kinds.add(kind));
|
|
1602
|
+
return target;
|
|
1603
|
+
};
|
|
1604
|
+
const place = (handle, after) => {
|
|
1605
|
+
if (after === SECTION_START)
|
|
1606
|
+
return true;
|
|
1607
|
+
if (!has(after)) {
|
|
1608
|
+
refuse(handle, AssistIssueCode.UnknownHandle, `"${after}" is not a section of this page`);
|
|
1609
|
+
return false;
|
|
1610
|
+
}
|
|
1611
|
+
if (after === handle) {
|
|
1612
|
+
refuse(handle, AssistIssueCode.NotAnOption, 'a section cannot go after itself');
|
|
1613
|
+
return false;
|
|
1614
|
+
}
|
|
1615
|
+
if (removed.has(after)) {
|
|
1616
|
+
refuse(handle, AssistIssueCode.NotAnOption, `${ctx.sections[after].label} is removed in the same answer — place it after another section`);
|
|
1617
|
+
return false;
|
|
1618
|
+
}
|
|
1619
|
+
return true;
|
|
1620
|
+
};
|
|
1621
|
+
const offered = (handle, pattern) => {
|
|
1622
|
+
if (ASK_SECTION_PATTERNS.includes(pattern))
|
|
1623
|
+
return true;
|
|
1624
|
+
refuse(handle, AssistIssueCode.NotAnOption, `"${pattern}" is not a section Ask can add`);
|
|
1625
|
+
return false;
|
|
1626
|
+
};
|
|
1627
|
+
const indexOf = (id) => result.findIndex(n => n.id === id);
|
|
1628
|
+
const whereLabel = (after) => after === SECTION_START ? 'At the start' : `After ${ctx.sections[after].label}`;
|
|
1629
|
+
/** The handle of the section a section stood after, or the start. */
|
|
1630
|
+
const stoodAfter = (handle) => {
|
|
1631
|
+
const at = layout.findIndex(n => n.id === original[handle].id);
|
|
1632
|
+
const prev = at > 0 ? Object.entries(original).find(([, t]) => t.id === layout[at - 1].id) : undefined;
|
|
1633
|
+
return prev ? prev[0] : SECTION_START;
|
|
1634
|
+
};
|
|
1635
|
+
const standsAfter = (handle) => {
|
|
1636
|
+
const prev = stoodAfter(handle);
|
|
1637
|
+
return prev === SECTION_START ? 'At the start' : `After ${original[prev].label}`;
|
|
1638
|
+
};
|
|
1639
|
+
const insertAfter = (node, after) => {
|
|
1640
|
+
if (after === SECTION_START) {
|
|
1641
|
+
result.unshift(node);
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
const at = indexOf(ctx.sections[after].id);
|
|
1645
|
+
result.splice(at + 1, 0, node);
|
|
1646
|
+
};
|
|
1647
|
+
// Swaps first, in place — so an addition or a move placed after a swapped section lands after its new drawing.
|
|
1648
|
+
for (const edit of edits) {
|
|
1649
|
+
if (!('swap' in edit))
|
|
1650
|
+
continue;
|
|
1651
|
+
const target = changeable(edit.swap, SectionChangeKind.Swap);
|
|
1652
|
+
if (!target || !offered(edit.swap, edit.pattern))
|
|
1653
|
+
continue;
|
|
1654
|
+
const at = indexOf(target.id);
|
|
1655
|
+
const blocker = swapBlocker(result[at]);
|
|
1656
|
+
if (blocker) {
|
|
1657
|
+
refuse(edit.swap, AssistIssueCode.NotAnOption, `${target.label} cannot be redrawn — ${blocker}; add a new section and remove this one instead`);
|
|
1658
|
+
continue;
|
|
1659
|
+
}
|
|
1660
|
+
const section = composeSection(edit.pattern, ctx.input ?? {}, { id: newId() }).section;
|
|
1661
|
+
const notPlaced = carryOver(result[at], section);
|
|
1662
|
+
result[at] = section;
|
|
1663
|
+
// Later places name the section by its ORIGINAL id — it stands where the swapped one stood.
|
|
1664
|
+
ctx = { ...ctx, sections: { ...ctx.sections, [edit.swap]: { ...target, id: section.id } } };
|
|
1665
|
+
changes.push({
|
|
1666
|
+
op: PageChangeOp.Section, kind: SectionChangeKind.Swap, handle: edit.swap, nodeId: section.id, label: target.label,
|
|
1667
|
+
pattern: edit.pattern, before: target.label, after: patternName(edit.pattern), ...(notPlaced ? { notPlaced } : {}),
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
for (const edit of edits) {
|
|
1671
|
+
if (!('remove' in edit))
|
|
1672
|
+
continue;
|
|
1673
|
+
const target = changeable(edit.remove, SectionChangeKind.Remove);
|
|
1674
|
+
if (!target)
|
|
1675
|
+
continue;
|
|
1676
|
+
result.splice(indexOf(target.id), 1);
|
|
1677
|
+
changes.push({ op: PageChangeOp.Section, kind: SectionChangeKind.Remove, handle: edit.remove, nodeId: target.id, label: target.label, before: standsAfter(edit.remove), after: 'Removed' });
|
|
1678
|
+
}
|
|
1679
|
+
for (const edit of edits) {
|
|
1680
|
+
if (!('move' in edit))
|
|
1681
|
+
continue;
|
|
1682
|
+
const target = changeable(edit.move, SectionChangeKind.Move);
|
|
1683
|
+
if (!target || !place(edit.move, edit.after))
|
|
1684
|
+
continue;
|
|
1685
|
+
const [node] = result.splice(indexOf(target.id), 1);
|
|
1686
|
+
insertAfter(node, edit.after);
|
|
1687
|
+
if (stoodAfter(edit.move) === edit.after)
|
|
1688
|
+
continue;
|
|
1689
|
+
changes.push({
|
|
1690
|
+
op: PageChangeOp.Section, kind: SectionChangeKind.Move, handle: edit.move, nodeId: target.id, label: target.label,
|
|
1691
|
+
before: standsAfter(edit.move), after: whereLabel(edit.after),
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
// Additions in answer order: two after the same section stand in that order.
|
|
1695
|
+
const lastAdded = new Map();
|
|
1696
|
+
for (const edit of edits) {
|
|
1697
|
+
if (!('add' in edit))
|
|
1698
|
+
continue;
|
|
1699
|
+
if (!offered('new', edit.add) || !place('new', edit.after))
|
|
1700
|
+
continue;
|
|
1701
|
+
const section = composeSection(edit.add, ctx.input ?? {}, { id: newId() }).section;
|
|
1702
|
+
const anchor = lastAdded.get(edit.after);
|
|
1703
|
+
if (anchor)
|
|
1704
|
+
result.splice(indexOf(anchor) + 1, 0, section);
|
|
1705
|
+
else
|
|
1706
|
+
insertAfter(section, edit.after);
|
|
1707
|
+
lastAdded.set(edit.after, section.id);
|
|
1708
|
+
changes.push({ op: PageChangeOp.Section, kind: SectionChangeKind.Add, handle: 'new', nodeId: section.id, label: patternName(edit.add), pattern: edit.add, before: '', after: whereLabel(edit.after) });
|
|
1709
|
+
}
|
|
1710
|
+
if (issues.length)
|
|
1711
|
+
return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
|
|
1712
|
+
return { ok: true, result, changes, issues: [] };
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* Surface S1 (the builder), family `look` (ai-assist-plan §4 AI2e; ai-session-panel-plan `setLook` / `setMotion`): the
|
|
1717
|
+
* SITE's look and motion — every page follows — changed only along the contract's own axes: a style preset, the brand
|
|
1718
|
+
* colour, the background tint, corners, pill buttons, spacing, the type pairing, the colour mode, speed, scrolling, how
|
|
1719
|
+
* animated and the change between pages. Never a token value, never CSS. A preset brings its whole look and keeps the
|
|
1720
|
+
* site's own Scrolling · How animated · Between pages (MO-D3, as Design ▸ Look does); a type pairing is one of the worn
|
|
1721
|
+
* style's own. The colour is checked by the SAME audit the contract gates every preset with (`auditDesignContrast`, in
|
|
1722
|
+
* every mode the look is worn) — a colour that fails is refused, never worn (R4: the AA gate decides the colour).
|
|
1723
|
+
* The SAME pure functions run on the server (the check) and in the builder (the trial through the Design side-card's
|
|
1724
|
+
* own trial): `lookJsonSchema`, `decodeLookAnswers`, `applyLookEdits`.
|
|
1725
|
+
*/
|
|
1726
|
+
/** One axis of the look, as the answer names it and the change card says it. */
|
|
1727
|
+
var LookAxis;
|
|
1728
|
+
(function (LookAxis) {
|
|
1729
|
+
LookAxis["Style"] = "style";
|
|
1730
|
+
LookAxis["Colour"] = "colour";
|
|
1731
|
+
LookAxis["Tint"] = "tint";
|
|
1732
|
+
LookAxis["Corners"] = "corners";
|
|
1733
|
+
LookAxis["Buttons"] = "buttons";
|
|
1734
|
+
LookAxis["Spacing"] = "spacing";
|
|
1735
|
+
LookAxis["Type"] = "type";
|
|
1736
|
+
LookAxis["Mode"] = "mode";
|
|
1737
|
+
LookAxis["Speed"] = "speed";
|
|
1738
|
+
LookAxis["Scrolling"] = "scrolling";
|
|
1739
|
+
LookAxis["Entrances"] = "entrances";
|
|
1740
|
+
LookAxis["Between"] = "between";
|
|
1741
|
+
})(LookAxis || (LookAxis = {}));
|
|
1742
|
+
/** How the card names each axis (the builder translates it by the axis). */
|
|
1743
|
+
const LOOK_AXIS_LABELS = {
|
|
1744
|
+
[LookAxis.Style]: 'Style', [LookAxis.Colour]: 'Brand colour', [LookAxis.Tint]: 'Background tint', [LookAxis.Corners]: 'Corners',
|
|
1745
|
+
[LookAxis.Buttons]: 'Buttons', [LookAxis.Spacing]: 'Spacing', [LookAxis.Type]: 'Fonts', [LookAxis.Mode]: 'Mode', [LookAxis.Speed]: 'Speed',
|
|
1746
|
+
[LookAxis.Scrolling]: 'Scrolling', [LookAxis.Entrances]: 'How animated', [LookAxis.Between]: 'Between pages',
|
|
1747
|
+
};
|
|
1748
|
+
/** The axes in the order a card lists them (and the answer asks them). */
|
|
1749
|
+
const LOOK_AXES = Object.values(LookAxis);
|
|
1750
|
+
/** The answer's extra key. Every axis is required; `''` keeps it as it is. */
|
|
1751
|
+
var LookAnswerKey;
|
|
1752
|
+
(function (LookAnswerKey) {
|
|
1753
|
+
LookAnswerKey["Note"] = "note";
|
|
1754
|
+
})(LookAnswerKey || (LookAnswerKey = {}));
|
|
1755
|
+
/** "Keep it as it is" — strict outputs require every key. */
|
|
1756
|
+
const LOOK_KEEP = '';
|
|
1757
|
+
/** `buttons`: pill-shaped or as the look draws them. */
|
|
1758
|
+
var LookButtons;
|
|
1759
|
+
(function (LookButtons) {
|
|
1760
|
+
LookButtons["Pill"] = "pill";
|
|
1761
|
+
LookButtons["Look"] = "look";
|
|
1762
|
+
})(LookButtons || (LookButtons = {}));
|
|
1763
|
+
/** How the owner reads a colour mode. */
|
|
1764
|
+
const MODE_LABELS = { light: 'Light', dark: 'Dark', auto: 'Follow the visitor' };
|
|
1765
|
+
const BUTTON_LABELS = { [LookButtons.Pill]: 'Pill-shaped', [LookButtons.Look]: 'As the look draws them' };
|
|
1766
|
+
/** The worn modes a colour is judged in (`auto` = both). */
|
|
1767
|
+
const wornModes = (mode) => (mode === 'auto' ? ['light', 'dark'] : [mode]);
|
|
1768
|
+
const labelOf = (table, id) => table[id]?.label ?? id;
|
|
1769
|
+
/** The type pairings of a flavor: id → its label ("Fraunces + Manrope"). */
|
|
1770
|
+
function pairsOf(flavorId) {
|
|
1771
|
+
return flavorPackById(flavorId)?.pairs ?? [];
|
|
1772
|
+
}
|
|
1773
|
+
/** A colour as the look stores it (`#RRGGBB`), or null. */
|
|
1774
|
+
function lookHex(value) {
|
|
1775
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((value ?? '').trim());
|
|
1776
|
+
if (!m || !parseHexColor(value))
|
|
1777
|
+
return null;
|
|
1778
|
+
const h = m[1].length === 3 ? m[1].split('').map(c => c + c).join('') : m[1];
|
|
1779
|
+
return `#${h.toUpperCase()}`;
|
|
1780
|
+
}
|
|
1781
|
+
/** How the owner reads one axis of a set of choices. */
|
|
1782
|
+
function lookAxisValue(choices, axis) {
|
|
1783
|
+
const c = resolveDesignChoices(choices);
|
|
1784
|
+
switch (axis) {
|
|
1785
|
+
case LookAxis.Style: {
|
|
1786
|
+
const preset = stylePresetOfChoices(c);
|
|
1787
|
+
const flavor = flavorPackById(c.flavorId)?.name ?? c.flavorId;
|
|
1788
|
+
return preset ? { id: preset.id, label: preset.name } : { id: c.flavorId, label: `${flavor}, your own` };
|
|
1789
|
+
}
|
|
1790
|
+
case LookAxis.Colour: return { id: c.seed.toUpperCase(), label: c.seed.toUpperCase() };
|
|
1791
|
+
case LookAxis.Tint: return { id: c.tint ?? '', label: labelOf(SPEC_AXES.tints, c.tint ?? '') };
|
|
1792
|
+
case LookAxis.Corners: return { id: c.shape, label: labelOf(SPEC_AXES.shapes, c.shape) };
|
|
1793
|
+
case LookAxis.Buttons: {
|
|
1794
|
+
const id = c.pillButtons ? LookButtons.Pill : LookButtons.Look;
|
|
1795
|
+
return { id, label: BUTTON_LABELS[id] };
|
|
1796
|
+
}
|
|
1797
|
+
case LookAxis.Spacing: return { id: c.density, label: labelOf(SPEC_AXES.densities, c.density) };
|
|
1798
|
+
case LookAxis.Type: return { id: c.pairId, label: pairsOf(c.flavorId).find(p => p.id === c.pairId)?.label ?? c.pairId };
|
|
1799
|
+
case LookAxis.Mode: return { id: c.mode, label: MODE_LABELS[c.mode] ?? c.mode };
|
|
1800
|
+
case LookAxis.Speed: return { id: c.motion, label: labelOf(SPEC_AXES.motions, c.motion) };
|
|
1801
|
+
case LookAxis.Scrolling: return { id: c.scroll ?? '', label: labelOf(SPEC_AXES.scrolls, c.scroll ?? '') };
|
|
1802
|
+
case LookAxis.Entrances: return { id: c.animate ?? '', label: labelOf(SPEC_AXES.animations, c.animate ?? '') };
|
|
1803
|
+
case LookAxis.Between: return { id: c.between ?? '', label: labelOf(SPEC_AXES.betweens, c.between ?? '') };
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
function summarizeLook(choices) {
|
|
1807
|
+
return Object.fromEntries(LOOK_AXES.map(axis => [axis, lookAxisValue(choices, axis).label]));
|
|
1808
|
+
}
|
|
1809
|
+
/** The ids an axis may take — what the strict format lists (`''` keeps it). Type: the worn style's own pairings. */
|
|
1810
|
+
function axisOptions(axis, current) {
|
|
1811
|
+
switch (axis) {
|
|
1812
|
+
case LookAxis.Style: return STYLE_PRESETS.map(p => p.id);
|
|
1813
|
+
case LookAxis.Colour: return [];
|
|
1814
|
+
case LookAxis.Tint: return TINT_IDS;
|
|
1815
|
+
case LookAxis.Corners: return Object.keys(SPEC_AXES.shapes);
|
|
1816
|
+
case LookAxis.Buttons: return Object.values(LookButtons);
|
|
1817
|
+
case LookAxis.Spacing: return Object.keys(SPEC_AXES.densities);
|
|
1818
|
+
case LookAxis.Type: return pairsOf(resolveDesignChoices(current).flavorId).map(p => p.id);
|
|
1819
|
+
case LookAxis.Mode: return SPEC_AXES.modes;
|
|
1820
|
+
case LookAxis.Speed: return Object.keys(SPEC_AXES.motions);
|
|
1821
|
+
case LookAxis.Scrolling: return SCROLL_IDS;
|
|
1822
|
+
case LookAxis.Entrances: return ANIMATE_IDS;
|
|
1823
|
+
case LookAxis.Between: return BETWEEN_IDS;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
const options = (ids, says) => ids.map(id => `${id} = ${says(id)}`).join('; ');
|
|
1827
|
+
/** What each axis's ids mean, in the format's own descriptions — read only when the look is asked. */
|
|
1828
|
+
function axisDescription(axis, current) {
|
|
1829
|
+
const keep = 'Empty string = keep it as it is.';
|
|
1830
|
+
switch (axis) {
|
|
1831
|
+
case LookAxis.Style:
|
|
1832
|
+
return `A whole style for the site (colour, type, corners, spacing and speed together). ${keep} `
|
|
1833
|
+
+ options(STYLE_PRESETS.map(p => p.id), id => {
|
|
1834
|
+
const p = stylePresetById(id);
|
|
1835
|
+
return `${p.name} (${p.moods.join(', ')}; ${p.modes.join('/')}): ${p.blurb}`;
|
|
1836
|
+
});
|
|
1837
|
+
case LookAxis.Colour:
|
|
1838
|
+
return `The brand colour as #RRGGBB, only when the owner names or describes one ("our green", "#2E7D45"); every background, `
|
|
1839
|
+
+ `button and link is derived from it and checked for contrast. ${keep}`;
|
|
1840
|
+
case LookAxis.Tint: return `How much of the brand colour the backgrounds carry. ${keep} ${options(TINT_IDS, id => labelOf(SPEC_AXES.tints, id))}`;
|
|
1841
|
+
case LookAxis.Corners: return `Corner roundness everywhere. ${keep} ${options(Object.keys(SPEC_AXES.shapes), id => labelOf(SPEC_AXES.shapes, id))}`;
|
|
1842
|
+
case LookAxis.Buttons: return `Button shape. ${keep} ${options(Object.values(LookButtons), id => BUTTON_LABELS[id])}`;
|
|
1843
|
+
case LookAxis.Spacing: return `Space around and between every section of the site. ${keep} ${options(Object.keys(SPEC_AXES.densities), id => labelOf(SPEC_AXES.densities, id))}`;
|
|
1844
|
+
case LookAxis.Type: return `The site's fonts, as one of the pairings the current style offers. ${keep} ${options(axisOptions(axis, current), id => pairsOf(resolveDesignChoices(current).flavorId).find(p => p.id === id)?.label ?? id)}`;
|
|
1845
|
+
case LookAxis.Mode: return `Light or dark site. ${keep} ${options(SPEC_AXES.modes, id => MODE_LABELS[id])}`;
|
|
1846
|
+
case LookAxis.Speed: return `How fast buttons and cards respond and things move. ${keep} ${options(Object.keys(SPEC_AXES.motions), id => labelOf(SPEC_AXES.motions, id))}`;
|
|
1847
|
+
case LookAxis.Scrolling: return `How the page scrolls. ${keep} ${options(SCROLL_IDS, id => `${labelOf(SPEC_AXES.scrolls, id)}: ${SPEC_AXES.scrolls[id].hint}`)}`;
|
|
1848
|
+
case LookAxis.Entrances: return `How content moves in as the visitor scrolls (the site's "how animated"). ${keep} ${options(ANIMATE_IDS, id => `${labelOf(SPEC_AXES.animations, id)}: ${SPEC_AXES.animations[id].hint}`)}`;
|
|
1849
|
+
case LookAxis.Between: return `What plays between pages. ${keep} ${options(BETWEEN_IDS, id => `${labelOf(SPEC_AXES.betweens, id)}: ${SPEC_AXES.betweens[id].hint}`)}`;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
/** Family `look`'s ONE strict format: every axis required, `''` keeps it; the ids listed and described from the contract. */
|
|
1853
|
+
function lookJsonSchema(current) {
|
|
1854
|
+
const properties = {};
|
|
1855
|
+
for (const axis of LOOK_AXES) {
|
|
1856
|
+
const ids = axisOptions(axis, current);
|
|
1857
|
+
properties[axis] = { ...(axis === LookAxis.Colour ? jsonText() : jsonOneOf([LOOK_KEEP, ...ids])), description: axisDescription(axis, current) };
|
|
1858
|
+
}
|
|
1859
|
+
properties[LookAnswerKey.Note] = { ...jsonText(), description: 'One short line for the owner on what changed, or what needs them.' };
|
|
1860
|
+
const part = jsonClosedObject(properties, Object.keys(properties));
|
|
1861
|
+
assertAssistBudget('look', [part]);
|
|
1862
|
+
return { parts: [part], handles: [[]] };
|
|
1863
|
+
}
|
|
1864
|
+
const isSiteLookEdit = (e) => !!e && typeof e === 'object' && 'look' in e;
|
|
1865
|
+
/** The answer as ONE edit (or none, when every axis is kept). */
|
|
1866
|
+
function decodeLookAnswers(answers) {
|
|
1867
|
+
const look = {};
|
|
1868
|
+
for (const answer of answers) {
|
|
1869
|
+
const a = (answer && typeof answer === 'object' ? answer : {});
|
|
1870
|
+
for (const axis of LOOK_AXES) {
|
|
1871
|
+
const v = typeof a[axis] === 'string' ? a[axis].trim() : '';
|
|
1872
|
+
if (v)
|
|
1873
|
+
look[axis] = v;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
return Object.keys(look).length ? [{ look }] : [];
|
|
1877
|
+
}
|
|
1878
|
+
/** The axes `presetChoices` sets that the site keeps (MO-D3: a style pick in the builder keeps its motion). */
|
|
1879
|
+
const SITE_MOTION = ['scroll', 'animate', 'between'];
|
|
1880
|
+
/** The first finding a failed audit names, as the owner reads it. */
|
|
1881
|
+
const findingLine = (f) => `${f.element} ${f.part} on ${f.scheme} is ${f.ratio.toFixed(2)}:1 (needs ${f.min}:1)`;
|
|
1882
|
+
/**
|
|
1883
|
+
* The answer on the current look: a style first (its whole look, the site's motion kept, the mode kept when the style
|
|
1884
|
+
* offers it), then every other axis named. Refused, all or none: an id the axis does not have, a colour that is not one,
|
|
1885
|
+
* a pairing the style does not offer, a mode the style was not drawn in, and a colour, tint or mode that fails the contrast
|
|
1886
|
+
* audit in a mode the site is worn in. A look that is exactly an audited style is not re-audited (the contract gated it).
|
|
1887
|
+
*/
|
|
1888
|
+
function applyLookEdits(current, edits) {
|
|
1889
|
+
const before = resolveDesignChoices(current ?? null);
|
|
1890
|
+
const asked = Object.assign({}, ...edits.map(e => e.look));
|
|
1891
|
+
const issues = [];
|
|
1892
|
+
const refuse = (axis, code, message) => issues.push({ code, message: `${axis}: ${message}` });
|
|
1893
|
+
const has = (axis) => typeof asked[axis] === 'string' && asked[axis] !== LOOK_KEEP;
|
|
1894
|
+
const valid = (axis, ids) => {
|
|
1895
|
+
const v = asked[axis];
|
|
1896
|
+
if (ids.includes(v))
|
|
1897
|
+
return v;
|
|
1898
|
+
refuse(axis, AssistIssueCode.NotAnOption, `"${v}" is not one of ${ids.join(', ')}`);
|
|
1899
|
+
return null;
|
|
1900
|
+
};
|
|
1901
|
+
let next = { ...before };
|
|
1902
|
+
const mode = has(LookAxis.Mode) ? valid(LookAxis.Mode, SPEC_AXES.modes) : null;
|
|
1903
|
+
if (has(LookAxis.Style)) {
|
|
1904
|
+
const id = valid(LookAxis.Style, STYLE_PRESETS.map(p => p.id));
|
|
1905
|
+
const preset = id ? stylePresetById(id) : undefined;
|
|
1906
|
+
if (preset) {
|
|
1907
|
+
const wear = mode ?? (presetChoices(preset.id, before.mode) ? before.mode : undefined);
|
|
1908
|
+
const look = presetChoices(preset.id, wear);
|
|
1909
|
+
if (!look) {
|
|
1910
|
+
refuse(LookAxis.Mode, AssistIssueCode.NotAnOption, `${preset.name} is drawn in ${preset.modes.join(' and ')} only, not ${MODE_LABELS[wear]}`);
|
|
1911
|
+
}
|
|
1912
|
+
else {
|
|
1913
|
+
const { fonts: _drop, ...rest } = look;
|
|
1914
|
+
next = { ...rest, ...Object.fromEntries(SITE_MOTION.map(k => [k, before[k]])) };
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
if (has(LookAxis.Colour)) {
|
|
1919
|
+
const hex = lookHex(asked[LookAxis.Colour]);
|
|
1920
|
+
if (hex)
|
|
1921
|
+
next = { ...next, seed: hex };
|
|
1922
|
+
else
|
|
1923
|
+
refuse(LookAxis.Colour, AssistIssueCode.WrongType, `"${asked[LookAxis.Colour]}" is not a colour (#RRGGBB)`);
|
|
1924
|
+
}
|
|
1925
|
+
if (has(LookAxis.Tint)) {
|
|
1926
|
+
const v = valid(LookAxis.Tint, TINT_IDS);
|
|
1927
|
+
if (v)
|
|
1928
|
+
next = { ...next, tint: v };
|
|
1929
|
+
}
|
|
1930
|
+
if (has(LookAxis.Corners)) {
|
|
1931
|
+
const v = valid(LookAxis.Corners, Object.keys(SPEC_AXES.shapes));
|
|
1932
|
+
if (v)
|
|
1933
|
+
next = { ...next, shape: v };
|
|
1934
|
+
}
|
|
1935
|
+
if (has(LookAxis.Buttons)) {
|
|
1936
|
+
const v = valid(LookAxis.Buttons, Object.values(LookButtons));
|
|
1937
|
+
if (v)
|
|
1938
|
+
next = { ...next, pillButtons: v === LookButtons.Pill };
|
|
1939
|
+
}
|
|
1940
|
+
if (has(LookAxis.Spacing)) {
|
|
1941
|
+
const v = valid(LookAxis.Spacing, Object.keys(SPEC_AXES.densities));
|
|
1942
|
+
if (v)
|
|
1943
|
+
next = { ...next, density: v };
|
|
1944
|
+
}
|
|
1945
|
+
if (has(LookAxis.Type)) {
|
|
1946
|
+
const pairs = pairsOf(next.flavorId);
|
|
1947
|
+
const v = asked[LookAxis.Type];
|
|
1948
|
+
if (pairs.some(p => p.id === v)) {
|
|
1949
|
+
if (v !== next.pairId) {
|
|
1950
|
+
const { fonts: _drop, ...rest } = next;
|
|
1951
|
+
next = { ...rest, pairId: v };
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
else {
|
|
1955
|
+
refuse(LookAxis.Type, AssistIssueCode.NotAnOption, `"${v}" is not a pairing of ${flavorPackById(next.flavorId)?.name ?? next.flavorId} (${pairs.map(p => p.id).join(', ')})`);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
if (mode)
|
|
1959
|
+
next = { ...next, mode };
|
|
1960
|
+
if (has(LookAxis.Speed)) {
|
|
1961
|
+
const v = valid(LookAxis.Speed, Object.keys(SPEC_AXES.motions));
|
|
1962
|
+
if (v)
|
|
1963
|
+
next = { ...next, motion: v };
|
|
1964
|
+
}
|
|
1965
|
+
if (has(LookAxis.Scrolling)) {
|
|
1966
|
+
const v = valid(LookAxis.Scrolling, SCROLL_IDS);
|
|
1967
|
+
if (v)
|
|
1968
|
+
next = { ...next, scroll: v };
|
|
1969
|
+
}
|
|
1970
|
+
if (has(LookAxis.Entrances)) {
|
|
1971
|
+
const v = valid(LookAxis.Entrances, ANIMATE_IDS);
|
|
1972
|
+
if (v)
|
|
1973
|
+
next = { ...next, animate: v };
|
|
1974
|
+
}
|
|
1975
|
+
if (has(LookAxis.Between)) {
|
|
1976
|
+
const v = valid(LookAxis.Between, BETWEEN_IDS);
|
|
1977
|
+
if (v)
|
|
1978
|
+
next = { ...next, between: v };
|
|
1979
|
+
}
|
|
1980
|
+
next = resolveDesignChoices(next);
|
|
1981
|
+
// The AA gate decides the colour: judged where the look paints, in every mode the site is worn in.
|
|
1982
|
+
const colourMoved = ['flavorId', 'seed', 'tint', 'mode'].some(k => String(next[k] ?? '').toLowerCase() !== String(before[k] ?? '').toLowerCase());
|
|
1983
|
+
if (!issues.length && colourMoved && !stylePresetOfChoices(next)) {
|
|
1984
|
+
const rows = designTokenRows(next);
|
|
1985
|
+
for (const worn of wornModes(next.mode)) {
|
|
1986
|
+
const failed = auditDesignContrast(rows, worn).filter(f => !f.pass);
|
|
1987
|
+
if (failed.length) {
|
|
1988
|
+
const axis = has(LookAxis.Colour) ? LookAxis.Colour : has(LookAxis.Tint) ? LookAxis.Tint : LookAxis.Mode;
|
|
1989
|
+
refuse(axis, AssistIssueCode.Contrast, `in ${MODE_LABELS[worn]} it does not pass contrast: ${findingLine(failed[0])}`
|
|
1990
|
+
+ `${failed.length > 1 ? ` and ${failed.length - 1} more` : ''} — choose a ${worn === 'dark' ? 'lighter' : 'deeper'} colour or keep it`);
|
|
1991
|
+
break;
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
if (issues.length)
|
|
1996
|
+
return { ok: false, choices: before, changes: [], issues };
|
|
1997
|
+
const said = new Set([...(has(LookAxis.Style) ? [LookAxis.Style] : []), ...LOOK_AXES.filter(has)]);
|
|
1998
|
+
const changes = [];
|
|
1999
|
+
for (const axis of LOOK_AXES) {
|
|
2000
|
+
if (!said.has(axis))
|
|
2001
|
+
continue;
|
|
2002
|
+
const was = lookAxisValue(before, axis);
|
|
2003
|
+
const now = lookAxisValue(next, axis);
|
|
2004
|
+
if (was.id.toLowerCase() === now.id.toLowerCase() && was.label === now.label)
|
|
2005
|
+
continue;
|
|
2006
|
+
changes.push({ op: PageChangeOp.Look, axis, label: LOOK_AXIS_LABELS[axis], from: was.id, to: now.id, before: was.label, after: now.label });
|
|
2007
|
+
}
|
|
2008
|
+
return { ok: true, choices: next, changes, issues: [] };
|
|
2009
|
+
}
|
|
2010
|
+
|
|
1354
2011
|
/**
|
|
1355
2012
|
* Surface S1 (the builder, this page), family `words` (ai-assist-plan §4, ai-session-panel-plan §3b–§3d): the page as
|
|
1356
2013
|
* the model sees it — sections in order, each a handle (`s0`), the parts that carry words as handles (`s0.heading1`,
|
|
@@ -1479,6 +2136,10 @@ function summarizePage(layout, ctx) {
|
|
|
1479
2136
|
handle: sectionHandle(index),
|
|
1480
2137
|
label: sectionLabel(root, index),
|
|
1481
2138
|
parts: walked.filter(w => w.section === index).map(w => ({ ...w.part, words: clipText(w.part.words, FOCUS_TEXT_CHARS) })),
|
|
2139
|
+
...(() => {
|
|
2140
|
+
const pattern = sectionPatternOf(root);
|
|
2141
|
+
return pattern ? { pattern } : {};
|
|
2142
|
+
})(),
|
|
1482
2143
|
...(() => {
|
|
1483
2144
|
const looks = walkedLooks.filter(l => l.section === index).map(l => l.look);
|
|
1484
2145
|
return looks.length ? { looks } : {};
|
|
@@ -1531,12 +2192,16 @@ function summarizePage(layout, ctx) {
|
|
|
1531
2192
|
: selectedNode ? { selectedLabel: `${sections[0]?.label ?? ''} ▸ ${selectedNode.part.label}` } : {}),
|
|
1532
2193
|
...(Object.keys(names.styles).length ? { styleNames: names.styles } : {}),
|
|
1533
2194
|
...(Object.keys(names.schemes).length ? { schemeNames: names.schemes } : {}),
|
|
2195
|
+
sectionPatterns: askSectionPatternNames(),
|
|
1534
2196
|
};
|
|
2197
|
+
const sectionMap = Object.fromEntries(layout.map((root, index) => [sectionHandle(index), {
|
|
2198
|
+
id: root.id, label: sectionLabel(root, index), focus: scope === AssistScope.Page || index === selectedSection,
|
|
2199
|
+
}]));
|
|
1535
2200
|
return {
|
|
1536
2201
|
brief: {
|
|
1537
2202
|
surface: AssistSurface.BuilderPage,
|
|
1538
2203
|
focus,
|
|
1539
|
-
around: { sections: around, pages: [...(ctx.pages ?? [])] },
|
|
2204
|
+
around: { sections: around, pages: [...(ctx.pages ?? [])], ...(ctx.look ? { look: summarizeLook(ctx.look) } : {}) },
|
|
1540
2205
|
owner: ctx.owner ?? null,
|
|
1541
2206
|
rules,
|
|
1542
2207
|
memory: [...(ctx.memory ?? [])],
|
|
@@ -1545,6 +2210,7 @@ function summarizePage(layout, ctx) {
|
|
|
1545
2210
|
focusHandles: focusWalked.filter(w => !w.part.bound).map(w => w.part.handle),
|
|
1546
2211
|
nodes,
|
|
1547
2212
|
looks,
|
|
2213
|
+
sections: sectionMap,
|
|
1548
2214
|
};
|
|
1549
2215
|
}
|
|
1550
2216
|
var WordsAnswerKey;
|
|
@@ -1739,16 +2405,25 @@ function pageWriteLocale(layout, ctx) {
|
|
|
1739
2405
|
}
|
|
1740
2406
|
|
|
1741
2407
|
const isWordEdit = (e) => 'value' in e;
|
|
2408
|
+
const isNodeStyleEdit = (e) => !isWordEdit(e) && !isSectionEdit(e) && !isSiteLookEdit(e) && (isStyleEdit(e) || isSchemeEdit(e) || isSizeEdit(e));
|
|
1742
2409
|
function applyPageEdits(layout, edits, ctx) {
|
|
1743
2410
|
const words = applyWordEdits(layout, edits.filter(isWordEdit), {
|
|
1744
2411
|
handles: ctx.summary.handles, never: ctx.summary.brief.rules.never, sentence: ctx.sentence, words: ctx.words,
|
|
1745
2412
|
});
|
|
1746
|
-
const
|
|
1747
|
-
const
|
|
1748
|
-
const
|
|
2413
|
+
const style = applyStyleEdits(words.result, edits.filter(isNodeStyleEdit), { looks: ctx.summary.looks, baseline: ctx.baseline });
|
|
2414
|
+
const sectionEdits = edits.filter(isSectionEdit);
|
|
2415
|
+
const sections = sectionEdits.length
|
|
2416
|
+
? applySectionEdits(style.result, sectionEdits, { sections: ctx.summary.sections ?? {}, input: ctx.sectionInput, newId: ctx.newId })
|
|
2417
|
+
: { result: style.result, changes: [], issues: [] };
|
|
2418
|
+
const lookEdits = edits.filter(isSiteLookEdit);
|
|
2419
|
+
const look = lookEdits.length ? applyLookEdits(ctx.look, lookEdits) : null;
|
|
2420
|
+
const issues = [...words.issues, ...style.issues, ...sections.issues, ...(look?.issues ?? [])];
|
|
1749
2421
|
if (issues.length)
|
|
1750
2422
|
return { ok: false, result: JSON.parse(JSON.stringify(layout)), changes: [], issues };
|
|
1751
|
-
return {
|
|
2423
|
+
return {
|
|
2424
|
+
ok: true, result: sections.result, changes: [...words.changes, ...style.changes, ...sections.changes, ...(look?.changes ?? [])], issues: [],
|
|
2425
|
+
...(look?.changes.length ? { look: look.choices } : {}),
|
|
2426
|
+
};
|
|
1752
2427
|
}
|
|
1753
2428
|
|
|
1754
2429
|
/**
|
|
@@ -1771,7 +2446,8 @@ const isTerminalTurn = (status) => TERMINAL.has(status);
|
|
|
1771
2446
|
const ASSIST_MODEL_AUTO = 'auto';
|
|
1772
2447
|
const ASSIST_POLL_MS = 750;
|
|
1773
2448
|
const MAX_SENTENCE_CHARS = 2000;
|
|
1774
|
-
const isLookChange = (c) => 'op' in c
|
|
2449
|
+
const isLookChange = (c) => 'op' in c
|
|
2450
|
+
&& (c.op === PageChangeOp.Style || c.op === PageChangeOp.Scheme || c.op === PageChangeOp.Size || c.op === PageChangeOp.Section || c.op === PageChangeOp.Look);
|
|
1775
2451
|
/** A turn's own refusals and failures, beside generation-core's `AiRefusalCode`s (credits, plan, key), which a turn returns as they are. */
|
|
1776
2452
|
var AssistRefusalCode;
|
|
1777
2453
|
(function (AssistRefusalCode) {
|
|
@@ -1919,5 +2595,5 @@ function validateTurnRequest(req) {
|
|
|
1919
2595
|
* Generated bundle index. Do not edit.
|
|
1920
2596
|
*/
|
|
1921
2597
|
|
|
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 };
|
|
2598
|
+
export { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_SECTION_PATTERNS, 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, LOOK_AXES, LOOK_AXIS_LABELS, LOOK_KEEP, LookAnswerKey, LookAxis, LookButtons, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, MODE_LABELS, NEW_TARGET, NONE_TEXT, NeverWriteReason, PAGE_WORD_SLOTS, PageChangeOp, PagePartKind, PageSuggestionKind, RouteAnswerKey, SECTION_START, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SectionChangeKind, SectionsAnswerKey, StyleAnswerKey, SurfaceStatus, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, applyFieldEdits, applyLookEdits, applyPageEdits, applySectionEdits, applyStyleEdits, applyWordEdits, askSectionPatternNames, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeLookAnswers, decodeSectionsAnswers, decodeStyleAnswers, decodeWordsAnswers, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, isEmptyFieldValue, isPlainRecord, isSchemeEdit, isSectionEdit, isSessionOf, isSiteLookEdit, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookAxisValue, lookHex, lookJsonSchema, lookNames, memoryLine, namedLocale, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, sectionPatternOf, sectionsJsonSchema, serializedBaselineStyles, sessionMemory, styleJsonSchema, summarizeItem, summarizeLook, summarizePage, surfacePermissions, surfaceSpec, titleField, turnLocale, unknownHandles, validateTurnRequest, wordsJsonSchema };
|
|
1923
2599
|
//# sourceMappingURL=vectoriox-iox-ui-assist-core.mjs.map
|