@vectoriox/iox-ui 5.133.0 → 5.135.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.
Files changed (77) hide show
  1. package/commerce-core/index.d.ts +12 -1
  2. package/composite-core/index.d.ts +27 -22
  3. package/design-core/index.d.ts +436 -35
  4. package/domain-core/index.d.ts +353 -0
  5. package/domain-core/package.json +3 -0
  6. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +2 -0
  7. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-assist-core.mjs +6 -48
  9. package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +21 -0
  11. package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +68 -57
  13. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  14. package/fesm2022/vectoriox-iox-ui-design-core.mjs +895 -416
  15. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  16. package/fesm2022/vectoriox-iox-ui-domain-core.mjs +422 -0
  17. package/fesm2022/vectoriox-iox-ui-domain-core.mjs.map +1 -0
  18. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +14039 -12067
  19. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  20. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +9 -3
  21. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  22. package/fesm2022/vectoriox-iox-ui-mail-core.mjs +210 -2
  23. package/fesm2022/vectoriox-iox-ui-mail-core.mjs.map +1 -1
  24. package/fesm2022/vectoriox-iox-ui.mjs +290 -16
  25. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  26. package/generation-core/index.d.ts +1511 -432
  27. package/harness-core/index.d.ts +6 -1
  28. package/index.d.ts +139 -10
  29. package/mail-core/index.d.ts +190 -2
  30. package/package.json +5 -1
  31. package/src/actions-core/element-actions.ts +2 -0
  32. package/src/assist-core/page-sections.ts +7 -37
  33. package/src/commerce-core/shop-display.ts +21 -0
  34. package/src/composite-core/shop.ts +71 -57
  35. package/src/design-core/design-settings.ts +16 -0
  36. package/src/design-core/design-token.model.ts +7 -1
  37. package/src/design-core/flavor-spec.generated.ts +374 -35
  38. package/src/design-core/flavor-tokens.ts +12 -1
  39. package/src/design-core/header-behaviour.ts +32 -0
  40. package/src/design-core/motion-language.ts +115 -0
  41. package/src/design-core/public-api.ts +1 -0
  42. package/src/design-core/style-presets.ts +3 -0
  43. package/src/domain-core/domain-vocabulary.ts +125 -0
  44. package/src/domain-core/domain-wire.ts +95 -0
  45. package/src/domain-core/org-path-redirect.ts +105 -0
  46. package/src/domain-core/public-api.ts +12 -0
  47. package/src/domain-core/web-domain.ts +251 -0
  48. package/src/generation-core/carry-fill.ts +36 -0
  49. package/src/generation-core/carry.ts +398 -0
  50. package/src/generation-core/check-carry.ts +216 -0
  51. package/src/generation-core/check-layout.ts +71 -5
  52. package/src/generation-core/compose-layout.ts +187 -28
  53. package/src/generation-core/compose-site.ts +154 -31
  54. package/src/generation-core/entrances.ts +66 -10
  55. package/src/generation-core/header-edit.ts +299 -0
  56. package/src/generation-core/header-mix.ts +64 -5
  57. package/src/generation-core/layout-fingerprint.ts +5 -1
  58. package/src/generation-core/layout-language.ts +20 -1
  59. package/src/generation-core/layout-space.ts +4 -4
  60. package/src/generation-core/layout-wire.ts +36 -1
  61. package/src/generation-core/node-baselines.generated.ts +1 -0
  62. package/src/generation-core/public-api.ts +7 -0
  63. package/src/generation-core/redesign-additions.ts +273 -0
  64. package/src/generation-core/redesign-run.ts +364 -0
  65. package/src/generation-core/refit-page.ts +151 -0
  66. package/src/generation-core/section-stamp.ts +4 -4
  67. package/src/generation-core/shop-plan.ts +15 -0
  68. package/src/generation-core/site-build-run.ts +67 -3
  69. package/src/generation-core/site-spec.generated.ts +194 -94
  70. package/src/generation-core/site-tree.ts +19 -5
  71. package/src/generation-core/validate-site-plan.ts +37 -3
  72. package/src/harness-core/motion.ts +13 -3
  73. package/src/harness-core/starting-design.ts +1 -1
  74. package/src/mail-core/mail-domain.ts +305 -0
  75. package/src/mail-core/mail-wire.ts +8 -0
  76. package/src/mail-core/public-api.ts +3 -1
  77. package/styles/iox-design.css +30 -1
@@ -0,0 +1,398 @@
1
+ import { badgeToneOf, isAnyCompositeRoot, MarqueeRole, SLIDER_TYPE } from '@vectoriox/iox-ui/composite-core';
2
+
3
+ import { sectionOrigin, SectionMaker, SectionOriginContext } from './section-stamp';
4
+ import { SerializedNode } from './serialized-node';
5
+
6
+ /**
7
+ * THE CARRY (site-redesign plan §3b, RD1): what on a page is the owner's — the ONE owner-content rule. A redesign harvests
8
+ * it, the new layout places it by handle, `checkCarry` makes sure nothing is dropped silently (R-H3); Ask's section swap
9
+ * (assist-core, AI2d) reads the same classifier and carries only the kinds it carried before (RD-D19).
10
+ *
11
+ * Words eyebrow · heading (with its level) · text · button (with its link and interactions) · link · figure · badge
12
+ * Photos image · video (the same src, never re-uploaded)
13
+ * Forms the Form subtree verbatim — `form:<formId>` (field labels stay inside their form)
14
+ * Bound a repeater, a list, a detail binding — `bind:<n>`, whole, with the data source it reads (bound words belong to
15
+ * their block)
16
+ * Blocks an interactive composite carried WHOLE (RD-D18: Accordion / Disclosure, Tabs, Segmented, Marquee, Slider, a
17
+ * Dialog such as a Lightbox, a Popover) and the legacy leaf types whose words live in props (Gallery, the old
18
+ * Button and Card) — `block:<n>`
19
+ * Kept a section the owner built by hand on a BUILT page (RD-D17), ticked Keep (RD-D16), or any section of a legal
20
+ * page (its text is the owner's — RD-D17) — `keep:<n>`, verbatim
21
+ *
22
+ * A page the owner made by hand is REDESIGNED (RD-D16): every section is harvested, none kept whole unless ticked.
23
+ * Header and footer are globals and never harvested (RD-D8). Every handle carries its node VERBATIM — the composer stamps
24
+ * it, so a carried button keeps what it does; node-id references leaving a carried node are listed for `checkCarry`.
25
+ */
26
+
27
+ /** A carried word or photo, by kind. Ask's swap carries `SWAP_CARRY_KINDS` only. */
28
+ export enum CarryKind {
29
+ Eyebrow = 'eyebrow',
30
+ Heading = 'heading',
31
+ Text = 'text',
32
+ Button = 'button',
33
+ Link = 'link',
34
+ /** A number the studio stands behind or a price ("40+", "₪ 1,200") — the `price` element style (RD-D19). */
35
+ Figure = 'figure',
36
+ /** A badge's words (RD-D19). */
37
+ Badge = 'badge',
38
+ Image = 'image',
39
+ Video = 'video',
40
+ }
41
+
42
+ export const CARRY_PHOTO_KINDS: ReadonlySet<CarryKind> = new Set([CarryKind.Image, CarryKind.Video]);
43
+
44
+ /** What Ask's section swap carries over (AI2d) — unchanged by RD-D19: figures, badges, links and videos stay with their recipe. */
45
+ export const SWAP_CARRY_KINDS: ReadonlyArray<CarryKind> = [CarryKind.Eyebrow, CarryKind.Heading, CarryKind.Text, CarryKind.Button, CarryKind.Image];
46
+
47
+ /** A button Ask's swap moves the owner's words and link into — never a tab, a price switch or a cart button. */
48
+ export const CARRIED_BUTTON_STYLES: ReadonlySet<string> = new Set(['button-primary', 'button-secondary', 'button-ghost']);
49
+ /** A button's link: the props that travel with its words. */
50
+ export const BUTTON_LINK_PROPS: ReadonlyArray<string> = ['tag', 'linkType', 'href', 'pageRoute', 'url', 'target'];
51
+
52
+ /** Why a node is carried whole (RD-D18). */
53
+ export enum CarryBlockKind {
54
+ /** Accordion / Disclosure / Tabs / Segmented (composite-core's runtimes). */
55
+ Composite = 'composite',
56
+ Marquee = 'marquee',
57
+ Slider = 'slider',
58
+ /** A Dialog (a Lightbox is one) or a Popover — its content opens over the page. */
59
+ Overlay = 'overlay',
60
+ Gallery = 'gallery',
61
+ /** The old Button / Card types: their words live in props, not in children. */
62
+ Legacy = 'legacy',
63
+ }
64
+
65
+ const EYEBROW_STYLE = 'eyebrow';
66
+ const FIGURE_STYLE = 'price';
67
+ const BADGE_LABEL_STYLE = 'badge-label';
68
+ const SOURCE_PROP = 'source';
69
+
70
+ const BLOCK_TYPES: Readonly<Record<string, CarryBlockKind>> = {
71
+ [SLIDER_TYPE]: CarryBlockKind.Slider,
72
+ Dialog: CarryBlockKind.Overlay,
73
+ Popover: CarryBlockKind.Overlay,
74
+ Gallery: CarryBlockKind.Gallery,
75
+ Button: CarryBlockKind.Legacy,
76
+ Card: CarryBlockKind.Legacy,
77
+ };
78
+
79
+ /** The kind a node is carried as, word or photo — or null (a box, an icon, a part of a block). */
80
+ export function carryKindOf(node: SerializedNode): CarryKind | null {
81
+ if (node.elementStyle === EYEBROW_STYLE && (node.type === 'Heading' || node.type === 'Text')) return CarryKind.Eyebrow;
82
+ if (badgeToneOf(node)) return CarryKind.Badge;
83
+ switch (node.type) {
84
+ case 'Heading': return CarryKind.Heading;
85
+ case 'Text':
86
+ if (node.elementStyle === FIGURE_STYLE) return CarryKind.Figure;
87
+ return node.elementStyle === BADGE_LABEL_STYLE ? CarryKind.Badge : CarryKind.Text;
88
+ case 'ButtonBlock': return CarryKind.Button;
89
+ case 'Link': return CarryKind.Link;
90
+ case 'Image': return CarryKind.Image;
91
+ case 'Video': return CarryKind.Video;
92
+ default: return null;
93
+ }
94
+ }
95
+
96
+ /** Why a node is carried whole, or null. */
97
+ export function carryBlockOf(node: SerializedNode): CarryBlockKind | null {
98
+ if (isAnyCompositeRoot(node)) return CarryBlockKind.Composite;
99
+ if (node.role === MarqueeRole.Marquee) return CarryBlockKind.Marquee;
100
+ return BLOCK_TYPES[node.type] ?? null;
101
+ }
102
+
103
+ /** True when Ask's swap moves this part into the new section (today's kinds; a button only in an owner's style). */
104
+ function swapCarries(node: SerializedNode, kind: CarryKind | null): kind is CarryKind {
105
+ if (!kind || !SWAP_CARRY_KINDS.includes(kind)) return false;
106
+ return kind !== CarryKind.Button || CARRIED_BUTTON_STYLES.has(node.elementStyle ?? '');
107
+ }
108
+
109
+ /**
110
+ * A section's parts Ask's swap carries over, in reading order, by kind (assist-core `applySectionEdits`). The walk is
111
+ * Ask's since AI2d: a button is never entered, everything else is.
112
+ */
113
+ export function swapParts(root: SerializedNode): Record<string, SerializedNode[]> {
114
+ const out: Record<string, SerializedNode[]> = Object.fromEntries(SWAP_CARRY_KINDS.map(k => [k, [] as SerializedNode[]]));
115
+ const visit = (n: SerializedNode) => {
116
+ const kind = carryKindOf(n);
117
+ if (swapCarries(n, kind)) out[kind].push(n);
118
+ if (n.type === 'ButtonBlock') return;
119
+ for (const c of n.children ?? []) visit(c);
120
+ };
121
+ for (const c of root.children ?? []) visit(c);
122
+ return out;
123
+ }
124
+
125
+ // ─── The harvest ─────────────────────────────────────────────────────────────────────────────────────────────────────
126
+
127
+ interface CarryItem {
128
+ /** The handle a layout places (`w3`, `p1`, `form:contact-x`, `bind:2`, `block:1`, `keep:1`). */
129
+ handle: string;
130
+ /** The page section (root index) it came from. */
131
+ section: number;
132
+ nodeId: string;
133
+ /** The node exactly as saved — the composer stamps it, so a carried button keeps its link and interactions. */
134
+ node: SerializedNode;
135
+ }
136
+
137
+ export interface CarryWord extends CarryItem {
138
+ kind: CarryKind;
139
+ /** The words as plain text — what the model reads (`w3 · heading 2 · "Since 2009…"`); never typed back. */
140
+ text: string;
141
+ /** A heading's level (1–6). */
142
+ level?: number;
143
+ }
144
+
145
+ export interface CarryPhoto extends CarryItem {
146
+ kind: CarryKind.Image | CarryKind.Video;
147
+ src: string;
148
+ alt: string;
149
+ }
150
+
151
+ export interface CarryForm extends CarryItem {
152
+ formId: string;
153
+ }
154
+
155
+ export interface CarryBound extends CarryItem {
156
+ /** The data source the block reads (a repeater's list, a detail page's item). */
157
+ source: string;
158
+ /** The path inside it ('' = the source itself). */
159
+ path: string;
160
+ /** The alias a repeated row's children bind (the path's last segment, else the source); null outside a repeater. */
161
+ itemAlias: string | null;
162
+ /** Every data source the block's bindings read, its own rows' alias aside — what `checkCarry` finds on the studio. */
163
+ reads: string[];
164
+ }
165
+
166
+ export interface CarryBlock extends CarryItem {
167
+ kind: CarryBlockKind;
168
+ }
169
+
170
+ export interface CarryKept extends CarryItem {
171
+ /** Why it is kept as it is: the owner built it on a built page (RD-D17), or ticked Keep (RD-D16). */
172
+ because: CarryKeptReason;
173
+ }
174
+
175
+ export enum CarryKeptReason {
176
+ OwnerSection = 'owner-section',
177
+ Ticked = 'ticked',
178
+ /** A legal page (`pageSettings.legal`): its text is the owner's — never stamped, never recomposed (RD-D17). */
179
+ Legal = 'legal',
180
+ }
181
+
182
+ /** A node id a carried node points at (an interaction's target, a targeted state's driver) — remapped or reported. */
183
+ export interface CarryReference {
184
+ /** The carried handle the reference travels in. */
185
+ handle: string;
186
+ /** The node holding it. */
187
+ from: string;
188
+ /** The node it points at. */
189
+ to: string;
190
+ via: CarryReferenceVia;
191
+ /** True when the target travels in the same handle (a self-contained block). */
192
+ inside: boolean;
193
+ }
194
+
195
+ export enum CarryReferenceVia {
196
+ Interaction = 'interaction',
197
+ StateTrigger = 'stateTrigger',
198
+ }
199
+
200
+ export interface PageCarry {
201
+ words: CarryWord[];
202
+ photos: CarryPhoto[];
203
+ forms: CarryForm[];
204
+ bound: CarryBound[];
205
+ blocks: CarryBlock[];
206
+ kept: CarryKept[];
207
+ references: CarryReference[];
208
+ }
209
+
210
+ export interface HarvestContext extends SectionOriginContext {
211
+ /** The page was built (composed by a site build or a layout). Default: any root carries a section stamp. A section
212
+ * the owner made by hand is kept whole only on a built page (RD-D17); a hand-made page is redesigned (RD-D16). */
213
+ built?: boolean;
214
+ /** Section (root) indexes the owner ticked Keep. */
215
+ keep?: ReadonlyArray<number>;
216
+ /** The page is a legal page (`pageSettings.legal`, AW1): every section is kept verbatim (RD-D17). */
217
+ legal?: boolean;
218
+ }
219
+
220
+ const PLAIN_TAGS = /<[^>]*>/g;
221
+ const ENTITIES: Readonly<Record<string, string>> = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#39;': "'", '&nbsp;': ' ' };
222
+
223
+ /** A node's words as plain text (rich text loses its tags; the node keeps them). */
224
+ export function plainCarryText(value: unknown): string {
225
+ return String(value ?? '').replace(/<br\s*\/?>/gi, ' ').replace(PLAIN_TAGS, '').replace(/&(?:amp|lt|gt|quot|#39|nbsp);/g, e => ENTITIES[e]).replace(/\s+/g, ' ').trim();
226
+ }
227
+
228
+ const textChild = (node: SerializedNode): SerializedNode | undefined =>
229
+ (node.children ?? []).find(c => c.type === 'Text') ?? (node.children ?? []).map(textChild).find(Boolean);
230
+
231
+ function wordText(node: SerializedNode, kind: CarryKind): string {
232
+ switch (kind) {
233
+ case CarryKind.Button: return plainCarryText(textChild(node)?.props['content'] ?? node.props['ariaLabel']);
234
+ case CarryKind.Link: return plainCarryText(node.props['label']);
235
+ case CarryKind.Badge: return plainCarryText(node.type === 'Text' ? node.props['content'] : textChild(node)?.props['content']);
236
+ default: return plainCarryText(node.props['content']);
237
+ }
238
+ }
239
+
240
+ const headingLevel = (node: SerializedNode): number | undefined => {
241
+ const m = /^h([1-6])$/.exec(String(node.props['level'] ?? ''));
242
+ return m ? Number(m[1]) : undefined;
243
+ };
244
+
245
+ /** The binding that makes a node repeat (a Repeater, a bound Slider, an accordion From content): its `source`. */
246
+ function sourceBinding(node: SerializedNode): { source: string; path: string } | null {
247
+ const bound = (node.bindings ?? []).find(b => b.prop === SOURCE_PROP && b.source);
248
+ if (bound) return { source: bound.source, path: bound.path ?? '' };
249
+ const own = node.props[SOURCE_PROP];
250
+ return node.type === 'Repeater' && typeof own === 'string' && own ? { source: own, path: '' } : null;
251
+ }
252
+
253
+ function readsOf(node: SerializedNode, rowAlias: string | null): string[] {
254
+ const out = new Set<string>();
255
+ const visit = (n: SerializedNode) => {
256
+ for (const b of n.bindings ?? []) if (b.source && b.source !== rowAlias) out.add(b.source);
257
+ for (const c of n.children ?? []) visit(c);
258
+ };
259
+ visit(node);
260
+ return [...out];
261
+ }
262
+
263
+ const ids = (node: SerializedNode): Set<string> => {
264
+ const out = new Set<string>();
265
+ const visit = (n: SerializedNode) => { out.add(n.id); for (const c of n.children ?? []) visit(c); };
266
+ visit(node);
267
+ return out;
268
+ };
269
+
270
+ const SELF_TARGETS: ReadonlySet<string> = new Set(['', 'self']);
271
+
272
+ /** The node ids a carried subtree points at. */
273
+ function referencesOf(handle: string, node: SerializedNode): CarryReference[] {
274
+ const inside = ids(node);
275
+ const out: CarryReference[] = [];
276
+ const push = (from: string, to: unknown, via: CarryReferenceVia) => {
277
+ if (typeof to !== 'string' || SELF_TARGETS.has(to)) return;
278
+ out.push({ handle, from, to, via, inside: inside.has(to) });
279
+ };
280
+ const visit = (n: SerializedNode) => {
281
+ for (const ix of (n.interactions ?? []) as Array<{ actions?: unknown[]; reverseActions?: unknown[] }>) {
282
+ for (const action of [...(ix?.actions ?? []), ...(ix?.reverseActions ?? [])] as Array<{ target?: unknown }>) push(n.id, action?.target, CarryReferenceVia.Interaction);
283
+ }
284
+ for (const to of Object.values(n.stateTriggers ?? {})) push(n.id, to, CarryReferenceVia.StateTrigger);
285
+ for (const c of n.children ?? []) visit(c);
286
+ };
287
+ visit(node);
288
+ return out;
289
+ }
290
+
291
+ /**
292
+ * THE harvest (RD1): a page's carry, in reading order. Pure; never mutates the layout (every node is handed back as the
293
+ * same object — the caller clones before it edits).
294
+ */
295
+ export function harvestPage(layout: ReadonlyArray<SerializedNode>, ctx: HarvestContext = {}): PageCarry {
296
+ const carry: PageCarry = { words: [], photos: [], forms: [], bound: [], blocks: [], kept: [], references: [] };
297
+ const built = ctx.built ?? layout.some(root => !!root.composed);
298
+ const ticked = new Set(ctx.keep ?? []);
299
+ const counters = { w: 0, p: 0, bind: 0, block: 0, keep: 0 };
300
+ const refs = (handle: string, node: SerializedNode): void => { carry.references.push(...referencesOf(handle, node)); };
301
+
302
+ const visit = (node: SerializedNode, section: number): void => {
303
+ if (node.type === 'Form') {
304
+ const formId = String(node.props['formId'] ?? '') || node.id;
305
+ const handle = `form:${formId}`;
306
+ carry.forms.push({ handle, section, nodeId: node.id, node, formId });
307
+ return refs(handle, node);
308
+ }
309
+ const repeats = sourceBinding(node);
310
+ if (repeats || (node.bindings ?? []).length) {
311
+ const handle = `bind:${++counters.bind}`;
312
+ const own = repeats ?? { source: node.bindings[0].source, path: node.bindings[0].path ?? '' };
313
+ const itemAlias = repeats ? (repeats.path.split('.').filter(Boolean).pop() || repeats.source) : null;
314
+ carry.bound.push({ handle, section, nodeId: node.id, node, source: own.source, path: own.path, itemAlias, reads: [...new Set([own.source, ...readsOf(node, itemAlias)])] });
315
+ return refs(handle, node);
316
+ }
317
+ const block = carryBlockOf(node);
318
+ if (block) {
319
+ const handle = `block:${++counters.block}`;
320
+ carry.blocks.push({ handle, section, nodeId: node.id, node, kind: block });
321
+ return refs(handle, node);
322
+ }
323
+ const kind = carryKindOf(node);
324
+ if (kind && CARRY_PHOTO_KINDS.has(kind)) {
325
+ const src = String(node.props['src'] ?? '');
326
+ const film = kind === CarryKind.Video && !!node.props['frames'];
327
+ if (src || film) {
328
+ const handle = `p${++counters.p}`;
329
+ carry.photos.push({ handle, section, nodeId: node.id, node, kind: kind as CarryKind.Image | CarryKind.Video, src, alt: plainCarryText(node.props[kind === CarryKind.Image ? 'alt' : 'title']) });
330
+ refs(handle, node);
331
+ }
332
+ return;
333
+ }
334
+ if (kind) {
335
+ const text = wordText(node, kind);
336
+ if (text) {
337
+ const handle = `w${++counters.w}`;
338
+ const level = kind === CarryKind.Heading ? headingLevel(node) : undefined;
339
+ carry.words.push({ handle, section, nodeId: node.id, node, kind, text, ...(level ? { level } : {}) });
340
+ refs(handle, node);
341
+ }
342
+ // A heading, a text, a figure have no children; a button's or a badge's words are its own; a Link may wrap more.
343
+ if (kind !== CarryKind.Link) return;
344
+ }
345
+ for (const child of node.children ?? []) visit(child, section);
346
+ };
347
+
348
+ layout.forEach((root, section) => {
349
+ if (root.isGlobal) return;
350
+ const keep = ctx.legal ? CarryKeptReason.Legal
351
+ : ticked.has(section) ? CarryKeptReason.Ticked
352
+ : built && sectionOrigin(root, ctx).maker === SectionMaker.Owner ? CarryKeptReason.OwnerSection : null;
353
+ if (keep) {
354
+ const handle = `keep:${++counters.keep}`;
355
+ carry.kept.push({ handle, section, nodeId: root.id, node: root, because: keep });
356
+ return refs(handle, root);
357
+ }
358
+ visit(root, section);
359
+ });
360
+ return carry;
361
+ }
362
+
363
+ /** Every handle of a carry, in the order a layout may place them. */
364
+ export function carryHandles(carry: PageCarry): string[] {
365
+ return [...carry.words, ...carry.photos, ...carry.forms, ...carry.bound, ...carry.blocks, ...carry.kept].map(c => c.handle);
366
+ }
367
+
368
+ // ─── The carry as a layout request reads it (site-redesign RD2, H3) ─────────────────────────────────────────────────
369
+
370
+ /** How far a carried word is quoted to the model — enough to place it, never the whole of a long text. */
371
+ export const CARRY_PROMPT_QUOTE = 120;
372
+
373
+ const BLOCK_WORDS: Readonly<Record<CarryBlockKind, string>> = {
374
+ [CarryBlockKind.Composite]: 'questions, tabs or a switch, with their contents',
375
+ [CarryBlockKind.Marquee]: 'a moving band of words',
376
+ [CarryBlockKind.Slider]: 'a slider of slides',
377
+ [CarryBlockKind.Overlay]: 'a dialog or popover and what opens it',
378
+ [CarryBlockKind.Gallery]: 'a gallery of pictures',
379
+ [CarryBlockKind.Legacy]: 'a card or button of the older kind',
380
+ };
381
+
382
+ const quote = (text: string): string => JSON.stringify(text.length > CARRY_PROMPT_QUOTE ? `${text.slice(0, CARRY_PROMPT_QUOTE - 1)}…` : text);
383
+
384
+ /**
385
+ * The page's carry as the layout request shows it: one line per handle — what it is and its words — never a node, an id
386
+ * or a binding. The model places handles; it writes none of these words (RD-D5).
387
+ */
388
+ export function describeCarryForPrompt(carry: PageCarry): string {
389
+ const lines = [
390
+ ...carry.words.map(w => `- ${w.handle} · ${w.kind}${w.level ? ` ${w.level}` : ''} · ${quote(w.text)}`),
391
+ ...carry.photos.map(p => `- ${p.handle} · ${p.kind}${p.alt ? ` · ${quote(p.alt)}` : ''}`),
392
+ ...carry.forms.map(f => `- ${f.handle} · a form — on a form layer; it MUST be placed`),
393
+ ...carry.bound.map(b => `- ${b.handle} · shows "${b.source}"${b.itemAlias ? ' item by item' : ''} — a section of its own (its only layer names it), or a gallery or list layer`),
394
+ ...carry.blocks.map(b => `- ${b.handle} · ${BLOCK_WORDS[b.kind]} — a section of its own (its only layer names it), or a gallery or list layer`),
395
+ ...carry.kept.map(k => `- ${k.handle} · a section the owner keeps exactly as it is — a section of its own (its only layer names it)`),
396
+ ];
397
+ return lines.join('\n');
398
+ }
@@ -0,0 +1,216 @@
1
+ import type { SerializedNode } from './serialized-node';
2
+ import { CarryKind, CarryReferenceVia, PageCarry } from './carry';
3
+ import { LayoutIssue, LayoutIssueCode, LayoutLayer, LayoutLayerKind, LayoutMendKind, LayoutPage } from './layout-language';
4
+
5
+ /**
6
+ * THE carry judge (site-redesign plan §3b, RD1, R-H3): after `checkLayout`, a redesigned page is held to what the old one
7
+ * carried — never a silent drop.
8
+ *
9
+ * - a layer's handle names a part of the carry, sits on a layer that can show it, is placed once, and brings no copy of
10
+ * its own (the words are the owner's; the model writes none — RD-D5);
11
+ * - every FORM is placed (F8: the same `formId`, the same inbox) — refused, never listed;
12
+ * - every data source a bound part reads is one the studio has (the data relation is the alias — RD-D4);
13
+ * - a bound part, a block or a kept section is placed by a SECTION (`LayoutSection.carry`, RD-D20), or — as it was
14
+ * arranged — in a gallery, list or marquee layer; a section that carries one has no layers of its own;
15
+ * - every other part not placed is LISTED (`carryNotPlaced`) for Compare's "Not placed", never refused;
16
+ * - a placed part whose action points at a node the new page will not have (a scroll link to a section that left) is
17
+ * MENDED — the action is dropped and said (`mendCarry`), never refused.
18
+ */
19
+
20
+ /** The layer kinds that can show a carried word or photo — its words keep their kind (a button keeps what it does). */
21
+ export const CARRY_LAYER_KINDS: Readonly<Record<CarryKind, ReadonlyArray<LayoutLayerKind>>> = {
22
+ [CarryKind.Eyebrow]: [LayoutLayerKind.Label, LayoutLayerKind.Word, LayoutLayerKind.Text],
23
+ [CarryKind.Heading]: [LayoutLayerKind.Heading, LayoutLayerKind.Word],
24
+ [CarryKind.Text]: [LayoutLayerKind.Text],
25
+ [CarryKind.Button]: [LayoutLayerKind.Button],
26
+ [CarryKind.Link]: [LayoutLayerKind.Button],
27
+ [CarryKind.Figure]: [LayoutLayerKind.Number, LayoutLayerKind.Label],
28
+ [CarryKind.Badge]: [LayoutLayerKind.Label],
29
+ [CarryKind.Image]: [LayoutLayerKind.Photo],
30
+ [CarryKind.Video]: [LayoutLayerKind.Photo],
31
+ };
32
+
33
+ const FORM_HANDLE = /^form:/;
34
+
35
+ /** The layers that can hold a bound part or a block as it was arranged (Re-fit keeps a gallery where it stood). */
36
+ export const CARRY_WHOLE_LAYER_KINDS: ReadonlyArray<LayoutLayerKind> = [LayoutLayerKind.Gallery, LayoutLayerKind.List, LayoutLayerKind.Marquee];
37
+
38
+ export interface CarryCheckContext {
39
+ /** The data source aliases the studio has (the page's and the org's). Unset: not judged. */
40
+ sources?: ReadonlyArray<string>;
41
+ /** Node ids the new page has outside the carry — the site's global elements, which a page redesign never redraws.
42
+ * A composed node is never one: its id is new, and a section that happens to share an old id is another section. */
43
+ staying?: ReadonlyArray<string>;
44
+ }
45
+
46
+ interface Placed {
47
+ handle: string;
48
+ /** Null for a section place. */
49
+ layer: LayoutLayer | null;
50
+ path: string;
51
+ }
52
+
53
+ function placedLayers(page: LayoutPage): Placed[] {
54
+ const out: Placed[] = [];
55
+ (page?.sections ?? []).forEach((s, i) => {
56
+ if (typeof s?.carry === 'string' && s.carry) out.push({ handle: s.carry, layer: null, path: `sections[${i}].carry` });
57
+ (s?.layers ?? []).forEach((layer, j) => {
58
+ if (typeof layer?.carry === 'string' && layer.carry) out.push({ handle: layer.carry, layer, path: `sections[${i}].layers[${j}].carry` });
59
+ });
60
+ });
61
+ return out;
62
+ }
63
+
64
+ const issue = (path: string, message: string, mend?: LayoutIssue['mend']): LayoutIssue =>
65
+ ({ code: LayoutIssueCode.Carry, path, message, ...(mend ? { mend } : {}) });
66
+
67
+ const subtreeIds = (node: SerializedNode, into: Set<string>): void => {
68
+ into.add(node.id);
69
+ for (const c of node.children ?? []) subtreeIds(c, into);
70
+ };
71
+
72
+ /** What a layout must answer for the carry it was given. Empty when it holds. */
73
+ export function checkCarry(page: LayoutPage, carry: PageCarry, ctx: CarryCheckContext = {}): LayoutIssue[] {
74
+ const issues: LayoutIssue[] = [];
75
+ const words = new Map<string, CarryKind>([...carry.words, ...carry.photos].map(c => [c.handle, c.kind]));
76
+ const forms = new Set(carry.forms.map(f => f.handle));
77
+ const wholes = new Set([...carry.bound, ...carry.blocks, ...carry.kept].map(c => c.handle));
78
+ const kept = new Set(carry.kept.map(c => c.handle));
79
+ const seen = new Set<string>();
80
+
81
+ (page?.sections ?? []).forEach((s, i) => {
82
+ if (s?.carry && (s.layers ?? []).length) issues.push(issue(`sections[${i}].layers`, `a section carrying ${s.carry} has no layers of its own`));
83
+ });
84
+ for (const { handle, layer, path } of placedLayers(page)) {
85
+ if (seen.has(handle)) issues.push(issue(path, `${handle} is placed twice — a part of the page is placed once`));
86
+ seen.add(handle);
87
+ const kind = words.get(handle);
88
+ if (!layer) {
89
+ if (!wholes.has(handle)) issues.push(issue(path, `${handle} ${words.has(handle) || forms.has(handle) ? 'is placed by a layer, not a section' : 'names no part of this page'}`));
90
+ } else if (wholes.has(handle)) {
91
+ if (kept.has(handle)) issues.push(issue(path, `${handle} is a kept section; a section places it`));
92
+ else if (!CARRY_WHOLE_LAYER_KINDS.includes(layer.kind as LayoutLayerKind)) issues.push(issue(path, `${handle} is carried whole; a section or a ${CARRY_WHOLE_LAYER_KINDS.join(' · ')} layer places it`));
93
+ } else if (kind) {
94
+ if (!CARRY_LAYER_KINDS[kind].includes(layer.kind as LayoutLayerKind)) {
95
+ issues.push(issue(path, `${handle} is a ${kind}; a ${layer.kind} layer cannot show it (${CARRY_LAYER_KINDS[kind].join(' · ')})`));
96
+ }
97
+ const own = kind === CarryKind.Image || kind === CarryKind.Video ? layer.photo : layer.text;
98
+ if (own) issues.push(issue(path, `${handle} brings the owner's ${kind}; the layer writes none of its own`));
99
+ } else if (forms.has(handle)) {
100
+ if (layer.kind !== LayoutLayerKind.Form) issues.push(issue(path, `${handle} is a form; only a form layer places it`));
101
+ if (layer.form) issues.push(issue(path, `${handle} is the owner's form; the layer sets no form of its own`));
102
+ } else {
103
+ issues.push(issue(path, `${handle} names no part of this page`));
104
+ }
105
+ }
106
+
107
+ for (const f of carry.forms) {
108
+ if (!seen.has(f.handle)) issues.push(issue('sections', `${f.handle} is not placed — the page's form keeps its inbox (F8); place it in a form layer`));
109
+ }
110
+ issues.push(...danglingLinks(page, carry, seen, ctx));
111
+ if (ctx.sources) {
112
+ const has = new Set(ctx.sources);
113
+ for (const b of carry.bound) {
114
+ const missing = b.reads.filter(alias => !has.has(alias));
115
+ if (missing.length) issues.push(issue('sections', `${b.handle} reads ${missing.join(', ')}, which the studio does not have`));
116
+ }
117
+ }
118
+ return issues;
119
+ }
120
+
121
+ /**
122
+ * The actions of placed parts that point at a node the new page will not have. A target stays only when it travels in a
123
+ * part placed whole (a form, a bound part, a block, a kept section — their nodes keep their ids) or is in `ctx.staying`.
124
+ * Only actions are judged: a targeted state whose driver left styles nothing and costs nothing.
125
+ */
126
+ function danglingLinks(page: LayoutPage, carry: PageCarry, placed: ReadonlySet<string>, ctx: CarryCheckContext): LayoutIssue[] {
127
+ const staying = new Set(ctx.staying ?? []);
128
+ for (const c of [...carry.forms, ...carry.bound, ...carry.blocks, ...carry.kept]) if (placed.has(c.handle)) subtreeIds(c.node, staying);
129
+ const pathOf = new Map(placedLayers(page).map(p => [p.handle, p.path]));
130
+ const out: LayoutIssue[] = [];
131
+ const said = new Set<string>();
132
+ for (const ref of carry.references) {
133
+ if (ref.via !== CarryReferenceVia.Interaction || ref.inside || !placed.has(ref.handle) || staying.has(ref.to)) continue;
134
+ const key = `${ref.from}>${ref.to}`;
135
+ if (said.has(key)) continue;
136
+ said.add(key);
137
+ out.push(issue(pathOf.get(ref.handle) ?? 'sections', `${ref.handle} points at ${ref.to}, which the new page does not have — the action is dropped`,
138
+ { kind: LayoutMendKind.Link, handle: ref.handle, from: ref.from, to: ref.to }));
139
+ }
140
+ return out;
141
+ }
142
+
143
+ /**
144
+ * THE link mend (RD1): every `Link` issue's action leaves the carry — from the node holding it, forward and reverse; an
145
+ * interaction left with no action leaves too. Pure: a new carry, the parts it touched cloned. `mended` is what the owner
146
+ * is told (Compare lists it beside "Not placed").
147
+ */
148
+ export function mendCarry(carry: PageCarry, issues: ReadonlyArray<LayoutIssue>): { carry: PageCarry; mended: LayoutIssue[] } {
149
+ const links = issues.filter(i => i.mend?.kind === LayoutMendKind.Link);
150
+ if (!links.length) return { carry, mended: [] };
151
+ const next: PageCarry = { ...carry };
152
+ const mended: LayoutIssue[] = [];
153
+ const lists = ['words', 'photos', 'forms', 'bound', 'blocks', 'kept'] as const;
154
+ for (const i of links) {
155
+ const m = i.mend as { handle: string; from: string; to: string };
156
+ const list = lists.find(l => (next[l] as ReadonlyArray<{ handle: string }>).some(c => c.handle === m.handle));
157
+ if (!list) continue;
158
+ const items = [...next[list]] as Array<{ handle: string; node: SerializedNode }>;
159
+ const at = items.findIndex(c => c.handle === m.handle);
160
+ const node = structuredClone(items[at].node);
161
+ if (!dropActions(node, m.from, m.to)) continue;
162
+ items[at] = { ...items[at], node };
163
+ (next as unknown as Record<string, unknown>)[list] = items;
164
+ next.references = next.references.filter(r => !(r.handle === m.handle && r.from === m.from && r.to === m.to && r.via === CarryReferenceVia.Interaction));
165
+ mended.push(i);
166
+ }
167
+ return { carry: mended.length ? next : carry, mended };
168
+ }
169
+
170
+ function dropActions(root: SerializedNode, from: string, to: string): boolean {
171
+ const node = findNode(root, from);
172
+ if (!node?.interactions?.length) return false;
173
+ let dropped = false;
174
+ const keep = (actions: unknown[] | undefined) => (actions ?? []).filter(a => {
175
+ const hit = (a as { target?: unknown })?.target === to;
176
+ dropped ||= hit;
177
+ return !hit;
178
+ });
179
+ node.interactions = (node.interactions as Array<{ actions?: unknown[]; reverseActions?: unknown[] }>)
180
+ .map(ix => ({ ...ix, actions: keep(ix.actions), ...(ix.reverseActions ? { reverseActions: keep(ix.reverseActions) } : {}) }))
181
+ .filter(ix => ix.actions.length || (ix.reverseActions ?? []).length) as SerializedNode['interactions'];
182
+ return dropped;
183
+ }
184
+
185
+ function findNode(node: SerializedNode, id: string): SerializedNode | undefined {
186
+ if (node.id === id) return node;
187
+ for (const c of node.children ?? []) {
188
+ const hit = findNode(c, id);
189
+ if (hit) return hit;
190
+ }
191
+ return undefined;
192
+ }
193
+
194
+ /** What a layout leaves out — Compare's "Not placed" (R-H3): words, photos, bound parts, blocks, kept sections, each in
195
+ * reading order (a form is never left out: it is refused). */
196
+ export function carryNotPlaced(page: LayoutPage, carry: PageCarry): string[] {
197
+ const placed = new Set(placedLayers(page).map(p => p.handle));
198
+ return [...carry.words, ...carry.photos, ...carry.bound, ...carry.blocks, ...carry.kept].map(c => c.handle).filter(h => !placed.has(h) && !FORM_HANDLE.test(h));
199
+ }
200
+
201
+ /**
202
+ * The layout as the check reads it (RD2): every layer carrying a word shows the owner's words as plain text, so how they
203
+ * FIT (a size's characters, a screen word's width, pop and kinetic counts) is judged on the words the page will have —
204
+ * the fact rules never reach them (`checkLayout` skips a carried layer's words). Pure; the layout to compose keeps its
205
+ * handles and no text.
206
+ */
207
+ export function withCarriedText(page: LayoutPage, carry: PageCarry): LayoutPage {
208
+ const words = new Map(carry.words.map(w => [w.handle, w.text]));
209
+ return {
210
+ ...page,
211
+ sections: page.sections.map(s => ({
212
+ ...s,
213
+ layers: s.layers.map(l => (l.carry && words.has(l.carry) ? { ...l, text: words.get(l.carry)! } : l)),
214
+ })),
215
+ };
216
+ }