@aglyn/plugins-ai 1.7.0 → 1.8.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 (69) hide show
  1. package/package.json +17 -17
  2. package/src/lib/jobs/ai-job-import-step.d.ts +28 -2
  3. package/src/lib/jobs/ai-job-import-step.js +170 -14
  4. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  5. package/src/lib/jobs/ai-job-layout-language.js +2 -0
  6. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  7. package/src/lib/jobs/ai-job-page-language.js +6 -2
  8. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  9. package/src/lib/jobs/ai-site-import-compile.d.ts +13 -3
  10. package/src/lib/jobs/ai-site-import-compile.js +336 -27
  11. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  12. package/src/lib/jobs/ai-site-import-document.d.ts +3 -1
  13. package/src/lib/jobs/ai-site-import-document.js +36 -0
  14. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  15. package/src/lib/jobs/ai-site-import-look.d.ts +9 -0
  16. package/src/lib/jobs/ai-site-import-look.js +89 -6
  17. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  18. package/src/lib/layout-language/ai-layout-compiler.d.ts +16 -0
  19. package/src/lib/layout-language/ai-layout-compiler.js +351 -54
  20. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  21. package/src/lib/layout-language/ai-layout-frame-source.d.ts +88 -2
  22. package/src/lib/layout-language/ai-layout-frame-source.js +591 -30
  23. package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
  24. package/src/lib/layout-language/ai-layout-frame.js +30 -18
  25. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  26. package/src/lib/layout-language/ai-layout-language.d.ts +72 -3
  27. package/src/lib/layout-language/ai-layout-language.js +5 -3
  28. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  29. package/src/lib/layout-language/ai-layout-store.d.ts +8 -0
  30. package/src/lib/layout-language/ai-layout-store.js +32 -6
  31. package/src/lib/layout-language/ai-layout-store.js.map +1 -1
  32. package/src/lib/model/ai-site-import-fidelity.d.ts +31 -1
  33. package/src/lib/model/ai-site-import-fidelity.js +347 -25
  34. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  35. package/src/lib/model/ai-site-import.d.ts +203 -6
  36. package/src/lib/model/ai-site-import.js +161 -5
  37. package/src/lib/model/ai-site-import.js.map +1 -1
  38. package/src/lib/model/ai-site-look.d.ts +8 -1
  39. package/src/lib/model/ai-site-look.js +8 -5
  40. package/src/lib/model/ai-site-look.js.map +1 -1
  41. package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -1
  42. package/src/lib/runtime/ai-doctrine-validators.js +25 -2
  43. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  44. package/src/lib/runtime/ai-node-tree.js +19 -2
  45. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  46. package/src/lib/runtime/ai-page-links.d.ts +15 -0
  47. package/src/lib/runtime/ai-page-links.js +48 -0
  48. package/src/lib/runtime/ai-page-links.js.map +1 -1
  49. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +30 -5
  50. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  51. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +9 -0
  52. package/src/lib/site-import/fixtures/site-layout-recordings.js +24 -5
  53. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  54. package/src/lib/site-import/site-import-crawl.d.ts +3 -1
  55. package/src/lib/site-import/site-import-crawl.js +8 -3
  56. package/src/lib/site-import/site-import-crawl.js.map +1 -1
  57. package/src/lib/site-import/site-import-css.d.ts +20 -0
  58. package/src/lib/site-import/site-import-css.js +106 -0
  59. package/src/lib/site-import/site-import-css.js.map +1 -1
  60. package/src/lib/site-import/site-import-html.d.ts +39 -0
  61. package/src/lib/site-import/site-import-html.js +515 -5
  62. package/src/lib/site-import/site-import-html.js.map +1 -1
  63. package/src/lib/site-import/site-import-layout.d.ts +16 -6
  64. package/src/lib/site-import/site-import-layout.js +524 -52
  65. package/src/lib/site-import/site-import-layout.js.map +1 -1
  66. package/src/lib/site-import/site-import-nav.js +286 -24
  67. package/src/lib/site-import/site-import-nav.js.map +1 -1
  68. package/src/lib/site-import/site-import-page.js +3 -0
  69. package/src/lib/site-import/site-import-page.js.map +1 -1
@@ -35,13 +35,26 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
35
35
  * - **The buttons.** The source's own, with their own addresses: an address
36
36
  * off the site stays off it, as the source sends it. Drawn as the source
37
37
  * draws them: filled, outlined or as text.
38
+ * - **The panels (AGL-4139).** A mega menu's columns side by side in the
39
+ * source's order, each its own width, its heading, words and picture, its
40
+ * light or dark box, each icon in its tile, all in theme roles.
41
+ * - **How a menu opens (AGL-4139).** As the source's: one shown on hover
42
+ * under a name that is a link stays that link, which a click follows, and
43
+ * shows its panel on hover; one whose name goes nowhere is the Dropdown or
44
+ * Mega Menu element opened on hover and on a click; one the source opens
45
+ * on a click opens on a click.
38
46
  * - **The phone menu.** Each menu as a heading over its entries, then the
39
47
  * links, then the buttons: every part of the menu as present as the rest.
48
+ * A menu shown on hover opens and closes on a tap, holding every word of
49
+ * its panel.
40
50
  * - **The footer.** The source's columns under their headings, its words,
41
51
  * its profiles, its address, phone and email, and its © line word for word.
42
52
  *
43
53
  * Every word is the source's, as written; nothing here is a model's.
44
- *=========================================*/ import { aiIsIconPathData } from "../runtime/ai-icon-library.js";
54
+ *=========================================*/ import { ELEMENT_HIDDEN_CLASS } from "@aglyn/aglyn/app-utils/element-hidden-style";
55
+ import { parseMediaRef } from "@aglyn/aglyn/app-utils/media-ref";
56
+ import { nodeInteractionSelector } from "@aglyn/aglyn/app-utils/node-interactions";
57
+ import { aiIsIconPathData } from "../runtime/ai-icon-library.js";
45
58
  import { isContactHref, isHttpsUrl, isRootRelativePath } from "../runtime/ai-node-tree.js";
46
59
  /** The most kept of each part: the reader's own limits, held again on the way in. */ export const AI_LAYOUT_FRAME_SOURCE_LIMITS = {
47
60
  groups: 12,
@@ -66,6 +79,52 @@ const GROUNDS = [
66
79
  'brand',
67
80
  'dark'
68
81
  ];
82
+ const COLOR_TOKENS = [
83
+ 'action.hover',
84
+ 'action.selected',
85
+ 'primary.main',
86
+ 'secondary.main',
87
+ 'text.secondary',
88
+ 'primary.contrastText',
89
+ 'secondary.contrastText'
90
+ ];
91
+ const BANDS = [
92
+ 'plain',
93
+ 'soft',
94
+ 'brand',
95
+ 'dark'
96
+ ];
97
+ /** The most columns a panel, lines a column and boxes a footer keep (AGL-4139). */ const PANEL_LIMITS = {
98
+ columns: 6,
99
+ lines: 6,
100
+ panels: 4
101
+ };
102
+ const roleOf = (value)=>COLOR_TOKENS.includes(value) ? value : null;
103
+ /** A column of a panel, or a box of a footer, read defensively (AGL-4139). */ function columnOf(raw) {
104
+ if (!isRecord(raw)) return null;
105
+ const limits = AI_LAYOUT_FRAME_SOURCE_LIMITS;
106
+ const heading = words(raw['heading'], limits.label) || null;
107
+ const lines = listOf(raw['lines']).slice(0, PANEL_LIMITS.lines).map((line)=>words(line, limits.line)).filter(Boolean);
108
+ const band = BANDS.includes(raw['band']) ? raw['band'] : 'plain';
109
+ const image = isRecord(raw['image']) ? raw['image'] : null;
110
+ const src = typeof (image == null ? void 0 : image['src']) === 'string' ? image['src'].trim() : '';
111
+ const ratio = typeof (image == null ? void 0 : image['ratio']) === 'number' && Number.isFinite(image['ratio']) && image['ratio'] > 0.2 && image['ratio'] < 8 ? Math.round(image['ratio'] * 1000) / 1000 : null;
112
+ const width = typeof raw['width'] === 'number' && Number.isFinite(raw['width']) && raw['width'] > 2 && raw['width'] <= 600 ? Math.round(raw['width']) : null;
113
+ return _extends({
114
+ heading,
115
+ lines,
116
+ band
117
+ }, src && parseMediaRef(src) ? {
118
+ image: _extends({
119
+ src,
120
+ alt: words(image == null ? void 0 : image['alt'], 200)
121
+ }, ratio ? {
122
+ ratio
123
+ } : {})
124
+ } : {}, width ? {
125
+ width
126
+ } : {});
127
+ }
69
128
  /** Whether a destination is one a link of the frame may carry. */ export function aiLayoutFrameSourceToAllowed(to) {
70
129
  if (typeof to !== 'string' || !to || to.length > 2048) return false;
71
130
  if (to.startsWith('page:')) return SCREEN_ID.test(to.slice(5));
@@ -102,21 +161,41 @@ const present = (value)=>value !== null;
102
161
  if (!link || !isRecord(entry)) return null;
103
162
  const text = words(entry['text'], limits.line);
104
163
  const column = words(entry['column'], limits.label);
164
+ const at = typeof entry['at'] === 'number' && Number.isInteger(entry['at']) && entry['at'] >= 0 && entry['at'] < PANEL_LIMITS.columns ? entry['at'] : null;
165
+ const tile = isRecord(entry['tile']) ? {
166
+ fill: roleOf(entry['tile']['fill']),
167
+ color: roleOf(entry['tile']['color'])
168
+ } : null;
105
169
  return _extends({}, link, text ? {
106
170
  text
107
171
  } : {}, aiIsIconPathData(entry['iconPath']) ? {
108
172
  iconPath: entry['iconPath']
109
173
  } : {}, column ? {
110
174
  column
175
+ } : {}, at !== null ? {
176
+ at
177
+ } : {}, (tile == null ? void 0 : tile.fill) && tile.color ? {
178
+ tile: {
179
+ fill: tile.fill,
180
+ color: tile.color
181
+ }
111
182
  } : {});
112
183
  }).filter(present);
113
184
  const to = aiLayoutFrameSourceToAllowed(group['to']) ? group['to'] : null;
185
+ const columns = listOf(group['columns']).slice(0, PANEL_LIMITS.columns).map(columnOf).filter(present);
186
+ const measure = group['measure'] === 'xl' || group['measure'] === 'lg' ? group['measure'] : null;
114
187
  // A name that opens nothing and goes nowhere is no item.
115
- return items.length || to ? {
188
+ return items.length || to ? _extends({
116
189
  label,
117
190
  to,
118
191
  items
119
- } : null;
192
+ }, items.length && columns.length ? {
193
+ columns
194
+ } : {}, items.length && group['hover'] === true ? {
195
+ hover: true
196
+ } : {}, items.length && measure ? {
197
+ measure
198
+ } : {}) : null;
120
199
  }).filter(present);
121
200
  const ctas = listOf(raw['ctas']).slice(0, limits.ctas).map((cta)=>{
122
201
  const link = linkOf(cta);
@@ -157,7 +236,18 @@ function footerOf(raw) {
157
236
  }) : null;
158
237
  }).filter(present);
159
238
  const fact = (key)=>words(raw[key], limits.line) || null;
160
- const footer = {
239
+ const panels = listOf(raw['panels']).slice(0, PANEL_LIMITS.panels).map((entry)=>{
240
+ const column = columnOf(entry);
241
+ if (!column || !isRecord(entry)) return null;
242
+ const boxLinks = listOf(entry['links']).slice(0, limits.links).map(linkOf).filter(present);
243
+ if (!column.heading && !column.lines.length && !boxLinks.length) return null;
244
+ return _extends({}, column, {
245
+ links: boxLinks
246
+ }, aiIsIconPathData(entry['iconPath']) ? {
247
+ iconPath: entry['iconPath']
248
+ } : {});
249
+ }).filter(present);
250
+ const footer = _extends({
161
251
  columns,
162
252
  links,
163
253
  text,
@@ -166,11 +256,14 @@ function footerOf(raw) {
166
256
  phone: fact('phone'),
167
257
  email: fact('email'),
168
258
  copyright: fact('copyright')
169
- };
170
- const empty = !columns.length && !links.length && !text.length && !social.length && !footer.address && !footer.phone && !footer.email && !footer.copyright;
259
+ }, panels.length ? {
260
+ panels
261
+ } : {});
262
+ const empty = !columns.length && !links.length && !text.length && !social.length && !footer.address && !footer.phone && !footer.email && !footer.copyright && !panels.length;
171
263
  return empty ? null : footer;
172
264
  }
173
265
  /** The pages a source frame links by id, each once. */ export function aiLayoutFrameSourcePageIds(source) {
266
+ var _source_footer_panels;
174
267
  const all = [
175
268
  ...source.nav.flatMap((group)=>[
176
269
  group.to,
@@ -179,7 +272,8 @@ function footerOf(raw) {
179
272
  ...source.ctas.map((cta)=>cta.to),
180
273
  ...source.footer ? [
181
274
  ...source.footer.columns.flatMap((column)=>column.links.map((entry)=>entry.to)),
182
- ...source.footer.links.map((entry)=>entry.to)
275
+ ...source.footer.links.map((entry)=>entry.to),
276
+ ...((_source_footer_panels = source.footer.panels) != null ? _source_footer_panels : []).flatMap((box)=>box.links.map((entry)=>entry.to))
183
277
  ] : []
184
278
  ];
185
279
  return [
@@ -292,10 +386,29 @@ function footerOf(raw) {
292
386
  ];
293
387
  });
294
388
  }
295
- /** Whether a menu is drawn as a Mega Menu: its entries carry a line under them, or sit in more than one headed column. */ export function aiLayoutMenuIsMega(group) {
389
+ /**
390
+ * Whether a menu's panel is drawn in the source's own columns (AGL-4139):
391
+ * two or more side by side, or one the source sets apart with a fill, a
392
+ * picture or words of its own.
393
+ */ export function aiLayoutMenuHasPanelColumns(group) {
394
+ var _group_columns;
395
+ const columns = (_group_columns = group.columns) != null ? _group_columns : [];
396
+ return columns.length >= 2 || columns.some((column)=>column.band !== 'plain' || !!column.image || column.lines.length > 0);
397
+ }
398
+ /** Whether a menu is drawn as a Mega Menu: its entries carry a line under them, or sit in more than one headed column, or in the source's own columns. */ export function aiLayoutMenuIsMega(group) {
296
399
  if (group.items.some((entry)=>entry.text)) return true;
400
+ if (aiLayoutMenuHasPanelColumns(group)) return true;
297
401
  return new Set(group.items.map((entry)=>entry.column).filter(Boolean)).size >= 2 || group.items.length > COLUMN_ENTRIES * 2;
298
402
  }
403
+ /**
404
+ * The page a menu's own name opens (AGL-4139): a page of the site, never an
405
+ * address elsewhere (a Squarespace folder's address is no page), whether or
406
+ * not one of its entries opens it too. `null` for a name that only opens its
407
+ * menu.
408
+ */ export function aiLayoutMenuNamePage(group) {
409
+ const to = group.to;
410
+ return to && (to.startsWith('page:') || isRootRelativePath(to)) ? to : null;
411
+ }
299
412
  /**
300
413
  * The source's header drawn (AGL-4108): its menu row, its buttons and its
301
414
  * phone menu. `close` is the interaction a link of the phone menu closes it
@@ -316,7 +429,8 @@ function footerOf(raw) {
316
429
  if (interactions) tree.nodes[id].interactions = interactions;
317
430
  return id;
318
431
  };
319
- const items = source.nav.map((group)=>group.items.length ? menu(tree, group, link) : group.to ? link({
432
+ const hover = new AiLayoutHoverMenus(tree);
433
+ const items = source.nav.map((group)=>group.items.length ? menu(tree, group, link, hover) : group.to ? link({
320
434
  label: group.label,
321
435
  to: group.to
322
436
  }, 'navLink') : null);
@@ -376,6 +490,11 @@ function footerOf(raw) {
376
490
  continue;
377
491
  }
378
492
  flushLinks();
493
+ // A menu that opens on hover opens on a tap here, where there is no hover (AGL-4139).
494
+ if (group.hover) {
495
+ drawer.push(drawerGroup(tree, group, (entry, role)=>link(entry, role, input.close)));
496
+ continue;
497
+ }
379
498
  // The menu's name heads its entries; it links where the source's name opens a page and no entry does.
380
499
  const own = aiLayoutMenuOwnPage(group);
381
500
  const heading = own ? link({
@@ -428,7 +547,8 @@ function footerOf(raw) {
428
547
  nav,
429
548
  ctas,
430
549
  drawer,
431
- breakpoint
550
+ breakpoint,
551
+ panels: hover.region(breakpoint)
432
552
  };
433
553
  }
434
554
  /**
@@ -440,12 +560,79 @@ function footerOf(raw) {
440
560
  if (!to || !(to.startsWith('page:') || isRootRelativePath(to))) return null;
441
561
  return group.items.some((entry)=>entry.to === to) ? null : to;
442
562
  }
563
+ /**
564
+ * A menu in the phone menu that opens and closes on a tap (AGL-4139): its
565
+ * name as the Accordion's header, and under it every word of its panel —
566
+ * each column's heading and lines, then its entries — with the page its
567
+ * name opens first, where none of its entries opens it.
568
+ */ function drawerGroup(tree, group, link) {
569
+ var _group_columns;
570
+ const caption = (words, role)=>tree.add('muiTypography', {
571
+ children: words,
572
+ variant: 'caption',
573
+ component: 'p'
574
+ }, {
575
+ color: 'text.secondary'
576
+ }, null, role);
577
+ const own = aiLayoutMenuOwnPage(group);
578
+ const inside = own ? [
579
+ link({
580
+ label: group.label,
581
+ to: own
582
+ }, 'menuOverview')
583
+ ] : [];
584
+ const columns = (_group_columns = group.columns) != null ? _group_columns : [];
585
+ if (aiLayoutMenuHasPanelColumns(group)) {
586
+ const last = columns.length - 1;
587
+ columns.forEach((column, index)=>{
588
+ var _entry_at;
589
+ if (column.heading) inside.push(caption(column.heading, 'menuColumn'));
590
+ for (const line of column.lines)inside.push(caption(line, 'menuColumnText'));
591
+ for (const entry of group.items)if (Math.min((_entry_at = entry.at) != null ? _entry_at : 0, last) === index) inside.push(link(entry, 'menuEntry'));
592
+ });
593
+ } else {
594
+ let column = null;
595
+ for (const entry of group.items){
596
+ var _entry_column;
597
+ const under = (_entry_column = entry.column) != null ? _entry_column : null;
598
+ if (under && under !== column) inside.push(caption(under, 'menuColumn'));
599
+ column = under;
600
+ inside.push(link(entry, 'menuEntry'));
601
+ }
602
+ }
603
+ return tree.add('muiAccordion', {
604
+ disableGutters: true
605
+ }, // One style each, so a header of many menus repeats no inline look.
606
+ {
607
+ boxShadow: 'none'
608
+ }, [
609
+ tree.add('muiAccordionSummary', {
610
+ children: group.label
611
+ }, {
612
+ px: 0
613
+ }, null, 'menuGroupName'),
614
+ tree.add('muiAccordionDetails', null, {
615
+ px: 0
616
+ }, [
617
+ tree.add('muiStack', {
618
+ spacing: '1'
619
+ }, {
620
+ typography: 'body1'
621
+ }, inside, 'menuGroupEntries')
622
+ ], 'menuGroupPanel')
623
+ ], 'menuGroup');
624
+ }
443
625
  /**
444
626
  * A top-level item with entries: the Mega Menu, its entries in the source's
445
627
  * columns, each with its icon and the line under it; or the Dropdown Menu.
446
628
  * Where the item's own name goes somewhere none of its entries does, the menu
447
629
  * opens with that link, so the page the source's name opens stays reachable.
448
- */ function menu(tree, group, link) {
630
+ */ function menu(tree, group, link, hover) {
631
+ // A menu the source opens on hover under a name that opens a page of its
632
+ // own (AGL-4139): the name stays that link, and its panel shows on hover,
633
+ // as the source builds it and as this platform's own site does.
634
+ const named = group.hover ? aiLayoutMenuNamePage(group) : null;
635
+ if (named) return hoverMenu(tree, group, link, named, hover);
449
636
  const own = aiLayoutMenuOwnPage(group);
450
637
  const overview = own ? link({
451
638
  label: group.label,
@@ -453,9 +640,17 @@ function footerOf(raw) {
453
640
  }, 'menuOverview', undefined, {
454
641
  fontWeight: 700
455
642
  }) : null;
643
+ // A menu with no page of its own opens on hover too, where the source's
644
+ // does, and on a click, since its name has nowhere else to go.
645
+ const opened = (id)=>{
646
+ if (group.hover) tree.nodes[id].interactions = [
647
+ aiLayoutOpenMenuOnHover(id)
648
+ ];
649
+ return id;
650
+ };
456
651
  if (!aiLayoutMenuIsMega(group)) {
457
652
  // Its entries' words wrap as the source's do; only the row's labels are held to one line.
458
- return tree.add('muiNavMenu', {
653
+ return opened(tree.add('muiNavMenu', {
459
654
  label: group.label
460
655
  }, {
461
656
  flexShrink: 0
@@ -468,8 +663,46 @@ function footerOf(raw) {
468
663
  overview,
469
664
  ...group.items.map((entry)=>link(entry, 'menuItem'))
470
665
  ], 'menuItems')
471
- ], 'navMenu');
666
+ ], 'navMenu'));
472
667
  }
668
+ if (aiLayoutMenuHasPanelColumns(group)) {
669
+ const panel = tree.add('muiStack', {
670
+ spacing: '2'
671
+ }, {
672
+ whiteSpace: 'normal'
673
+ }, [
674
+ overview,
675
+ panelColumns(tree, group, link)
676
+ ], 'menuPanel');
677
+ return opened(tree.add('muiMegaMenu', {
678
+ label: group.label,
679
+ panelWidth: 'wide'
680
+ }, {
681
+ flexShrink: 0
682
+ }, [
683
+ panel
684
+ ], 'megaMenu'));
685
+ }
686
+ const grid = megaGrid(tree, group, link);
687
+ // Words in the panel wrap as the source's do; only the row's labels are held to one line.
688
+ const panel = tree.add('muiStack', {
689
+ spacing: '2'
690
+ }, {
691
+ whiteSpace: 'normal'
692
+ }, [
693
+ overview,
694
+ grid
695
+ ], 'menuPanel');
696
+ return opened(tree.add('muiMegaMenu', {
697
+ label: group.label,
698
+ panelWidth: 'wide'
699
+ }, {
700
+ flexShrink: 0
701
+ }, [
702
+ panel
703
+ ], 'megaMenu'));
704
+ }
705
+ /** A mega menu's entries in a grid of the columns the source heads them in, side by side from a tablet up, three at most to a row. */ function megaGrid(tree, group, link) {
473
706
  const columns = aiLayoutMenuColumns(group.items);
474
707
  // Its columns side by side from a tablet up, as many to a row as the source sets, three at most.
475
708
  const span = 12 / Math.min(3, Math.max(1, columns.length));
@@ -489,35 +722,324 @@ function footerOf(raw) {
489
722
  ...column.entries.map((entry)=>entry.text || entry.iconPath ? described(tree, entry) : link(entry, 'menuItem'))
490
723
  ], 'menuColumn')
491
724
  ], 'menuCell'));
492
- const grid = tree.add('muiGrid', {
725
+ return tree.add('muiGrid', {
493
726
  container: true,
494
727
  spacing: '2'
495
728
  }, null, cells, 'menuColumns');
496
- // Words in the panel wrap as the source's do; only the row's labels are held to one line.
497
- const panel = tree.add('muiStack', {
498
- spacing: '2'
729
+ }
730
+ /** How long a menu shown on hover stays once the pointer leaves it: the time to cross from its name to its panel. */ export const AI_LAYOUT_MENU_HOVER_GRACE_MS = 250;
731
+ /**
732
+ * The platform's own "On hover → Open menu" (AGL-4139), on a Dropdown or
733
+ * Mega Menu element: it opens when the pointer comes to it and closes itself
734
+ * when the pointer leaves its name and panel. A click still opens it.
735
+ */ export function aiLayoutOpenMenuOnHover(menuId) {
736
+ return {
737
+ id: 'ai-open-menu',
738
+ name: 'Open the menu on hover',
739
+ enabled: true,
740
+ trigger: {
741
+ event: 'elementHoverEnter',
742
+ everyTime: true
743
+ },
744
+ steps: [
745
+ {
746
+ type: 'openMenu',
747
+ menuNodeId: menuId
748
+ }
749
+ ]
750
+ };
751
+ }
752
+ /**
753
+ * The menus shown on hover under names that are links (AGL-4139), wired once
754
+ * every one is drawn: pointing at a menu's name or its panel shows it and
755
+ * hides every other at once, leaving them hides it a moment later, and Esc
756
+ * or a click elsewhere closes it. A mega menu's panel sits in the header
757
+ * bar's own panel region, the width of the bar; a dropdown's under its name.
758
+ */ export class AiLayoutHoverMenus {
759
+ add(on, panel, wide) {
760
+ this.menus.push({
761
+ on,
762
+ panel,
763
+ wide
764
+ });
765
+ }
766
+ /** The panels the width of the bar, in one region under it, shown from `breakpoint` up; `null` with none. */ region(breakpoint) {
767
+ for (const menu of this.menus){
768
+ const own = nodeInteractionSelector(menu.panel);
769
+ const others = this.menus.filter((other)=>other !== menu).map((other)=>({
770
+ type: 'hideElement',
771
+ selector: nodeInteractionSelector(other.panel)
772
+ }));
773
+ for (const id of menu.on){
774
+ this.tree.nodes[id].interactions = [
775
+ {
776
+ id: 'ai-show-menu',
777
+ name: 'Show the menu on hover',
778
+ enabled: true,
779
+ trigger: {
780
+ event: 'elementHoverEnter',
781
+ everyTime: true
782
+ },
783
+ steps: [
784
+ ...others,
785
+ {
786
+ type: 'showElement',
787
+ selector: own,
788
+ dismissOn: [
789
+ 'escape',
790
+ 'outsideClick'
791
+ ]
792
+ }
793
+ ]
794
+ },
795
+ {
796
+ id: 'ai-hide-menu',
797
+ name: 'Hide the menu when the pointer leaves',
798
+ enabled: true,
799
+ trigger: {
800
+ event: 'elementHoverLeave',
801
+ everyTime: true
802
+ },
803
+ steps: [
804
+ {
805
+ type: 'hideElement',
806
+ selector: own,
807
+ delayMs: AI_LAYOUT_MENU_HOVER_GRACE_MS
808
+ }
809
+ ]
810
+ }
811
+ ];
812
+ }
813
+ }
814
+ const wide = this.menus.filter((menu)=>menu.wide).map((menu)=>menu.panel);
815
+ // Under the whole bar, whose Toolbar its place is measured from.
816
+ return wide.length ? this.tree.add('muiBox', null, {
817
+ position: 'absolute',
818
+ top: '100%',
819
+ left: 0,
820
+ right: 0,
821
+ display: {
822
+ xs: 'none',
823
+ [breakpoint]: 'block'
824
+ }
825
+ }, wide, 'menuPanels') : null;
826
+ }
827
+ constructor(tree){
828
+ this.tree = tree;
829
+ this.menus = [];
830
+ }
831
+ }
832
+ /**
833
+ * A menu shown on hover under a name that is a link (AGL-4139), built as the
834
+ * source builds it and as this platform's own site does: the name, which a
835
+ * click follows to its page, and its panel, hidden until shown. A mega
836
+ * menu's panel holds its columns at the source's own measure, under the
837
+ * whole bar; a dropdown's sits under its name, its links on one line each.
838
+ */ function hoverMenu(tree, group, link, to, hover) {
839
+ const name = link({
840
+ label: group.label,
841
+ to
842
+ }, 'menuName');
843
+ if (aiLayoutMenuIsMega(group)) {
844
+ var _group_measure;
845
+ const body = aiLayoutMenuHasPanelColumns(group) ? panelColumns(tree, group, link) : megaGrid(tree, group, link);
846
+ // On paper, rounded and raised, as the source draws its panel's box.
847
+ const card = tree.add('muiCard', {
848
+ variant: 'elevation',
849
+ elevation: '3'
850
+ }, null, [
851
+ tree.add('muiCardContent', null, null, [
852
+ body
853
+ ], 'menuBody')
854
+ ], 'menuBox');
855
+ const measure = tree.add('muiContainer', {
856
+ maxWidth: (_group_measure = group.measure) != null ? _group_measure : 'lg'
857
+ }, null, [
858
+ card
859
+ ], 'menuMeasure');
860
+ const panel = tree.add('muiBox', {
861
+ className: AI_LAYOUT_START_HIDDEN_CLASS
862
+ }, null, [
863
+ measure
864
+ ], 'menuPanel');
865
+ hover.add([
866
+ name,
867
+ panel
868
+ ], panel, true);
869
+ return name;
870
+ }
871
+ // Below its name where the source's sits, as wide as its longest link.
872
+ const card = tree.add('muiCard', {
873
+ variant: 'elevation',
874
+ elevation: '3'
499
875
  }, {
500
- whiteSpace: 'normal'
876
+ width: 'max-content'
501
877
  }, [
502
- overview,
503
- grid
504
- ], 'menuPanel');
505
- return tree.add('muiMegaMenu', {
506
- label: group.label,
507
- panelWidth: 'wide'
878
+ tree.add('muiCardContent', null, null, [
879
+ tree.add('muiStack', {
880
+ spacing: '1'
881
+ }, null, group.items.map((entry)=>link(entry, 'menuItem')), 'menuItems')
882
+ ], 'menuBody')
883
+ ], 'menuBox');
884
+ const panel = tree.add('muiBox', {
885
+ className: AI_LAYOUT_START_HIDDEN_CLASS
508
886
  }, {
509
- flexShrink: 0
887
+ position: 'absolute'
510
888
  }, [
889
+ card
890
+ ], 'menuPanel');
891
+ const wrapper = tree.add('muiBox', null, {
892
+ position: 'relative'
893
+ }, [
894
+ name,
511
895
  panel
512
- ], 'megaMenu');
896
+ ], 'hoverMenu');
897
+ hover.add([
898
+ wrapper
899
+ ], panel, false);
900
+ return wrapper;
901
+ }
902
+ /**
903
+ * The Besigner's "Start hidden until an interaction shows it" (AGL-4139):
904
+ * the class the live site hides an element with from its first paint, which
905
+ * a Show an element step takes away. Code writes it; no model ever does.
906
+ */ export const AI_LAYOUT_START_HIDDEN_CLASS = ELEMENT_HIDDEN_CLASS;
907
+ /**
908
+ * A column's box, as the source fills it (AGL-4139): none; a light wash; the
909
+ * brand's; or the site's own dark scheme, so every word and link in it reads
910
+ * as it does on a dark band. A box is a Card, its corners the theme's shape.
911
+ */ function columnBox(tree, band, children, variant = 'flat') {
912
+ const content = tree.add('muiCardContent', null, null, [
913
+ tree.add('muiStack', {
914
+ spacing: '0.5'
915
+ }, null, children, 'menuColumnWords')
916
+ ], 'menuColumnContent');
917
+ const props = variant === 'outlined' ? {
918
+ variant: 'outlined'
919
+ } : {
920
+ variant: 'elevation',
921
+ elevation: '0'
922
+ };
923
+ if (band === 'soft') return tree.add('muiCard', props, {
924
+ bgcolor: 'action.hover'
925
+ }, [
926
+ content
927
+ ], 'menuColumnBox');
928
+ if (band === 'brand') return tree.add('muiCard', props, {
929
+ bgcolor: 'primary.main',
930
+ color: 'primary.contrastText'
931
+ }, [
932
+ content
933
+ ], 'menuColumnBox');
934
+ return tree.add('muiCard', props, null, [
935
+ content
936
+ ], 'menuColumnBox');
937
+ }
938
+ /**
939
+ * A panel's columns side by side, as the source sets them (AGL-4139): in its
940
+ * order, each its own width or a share of the row, each with its heading,
941
+ * its picture and its words, its entries under them, and its fill.
942
+ */ function panelColumns(tree, group, link) {
943
+ var _group_columns;
944
+ const columns = (_group_columns = group.columns) != null ? _group_columns : [];
945
+ const last = Math.max(0, columns.length - 1);
946
+ const cells = columns.map((column, index)=>{
947
+ const entries = group.items.filter((entry)=>{
948
+ var _entry_at;
949
+ return Math.min((_entry_at = entry.at) != null ? _entry_at : 0, last) === index;
950
+ });
951
+ const quiet = column.band === 'brand' ? null : {
952
+ color: 'text.secondary'
953
+ };
954
+ // The first short line is a title; the rest are its words, quiet.
955
+ const [first, ...rest] = column.lines;
956
+ const titled = !!first && first.length <= 60 && !/[.!?]$/.test(first);
957
+ const lines = [
958
+ ...first ? [
959
+ tree.add('muiTypography', {
960
+ children: first,
961
+ variant: titled ? 'subtitle1' : 'body2',
962
+ component: 'p'
963
+ }, titled ? {
964
+ fontWeight: 700
965
+ } : quiet, null, titled ? 'menuColumnTitle' : 'menuColumnText')
966
+ ] : [],
967
+ ...rest.map((line)=>tree.add('muiTypography', {
968
+ children: line,
969
+ variant: 'body2',
970
+ component: 'p'
971
+ }, quiet, null, 'menuColumnText'))
972
+ ];
973
+ const image = column.image ? tree.add('image', _extends({
974
+ src: column.image.src
975
+ }, column.image.alt ? {
976
+ alt: column.image.alt
977
+ } : {
978
+ decorative: true
979
+ }, {
980
+ objectFit: 'cover',
981
+ loading: 'lazy'
982
+ }), _extends({
983
+ width: '100%',
984
+ height: 'auto',
985
+ borderRadius: 2
986
+ }, column.image.ratio ? {
987
+ aspectRatio: `${column.image.ratio}`
988
+ } : {}), null, 'menuPicture') : null;
989
+ const words = [
990
+ column.heading ? tree.add('muiTypography', {
991
+ children: column.heading,
992
+ variant: 'overline',
993
+ component: 'p'
994
+ }, quiet, null, 'menuColumnHeading') : null,
995
+ image,
996
+ ...lines,
997
+ ...entries.map((entry)=>entry.text || entry.iconPath ? described(tree, entry) : link(entry, 'menuItem'))
998
+ ].filter((id)=>!!id);
999
+ // Its own width where the source sets one, else a share of the row.
1000
+ const flex = column.width ? `0 0 ${column.width}px` : '1 1 200px';
1001
+ if (column.band === 'plain') return tree.add('muiStack', {
1002
+ spacing: '0.5'
1003
+ }, {
1004
+ flex
1005
+ }, words, 'menuColumn');
1006
+ return tree.add('muiStack', column.band === 'dark' ? {
1007
+ colorScheme: 'dark'
1008
+ } : null, {
1009
+ flex
1010
+ }, [
1011
+ columnBox(tree, column.band, words)
1012
+ ], 'menuColumn');
1013
+ });
1014
+ return tree.add('muiStack', {
1015
+ direction: 'row',
1016
+ spacing: '2',
1017
+ alignItems: 'stretch',
1018
+ useFlexGap: true,
1019
+ flexWrap: 'wrap'
1020
+ }, null, cells, 'menuColumns');
513
1021
  }
514
1022
  /** A mega menu's entry: the whole of it one link, its icon beside its name and the line under it. */ function described(tree, entry) {
515
- // In the brand's color, as the source draws its menu's icons.
516
- const icon = entry.iconPath ? tree.add('icon', {
1023
+ var _ref;
1024
+ var _entry_tile;
1025
+ // In the brand's color, as the source draws its menu's icons; in its own box where the source tiles it (AGL-4139).
1026
+ const glyph = entry.iconPath ? tree.add('icon', {
517
1027
  iconPath: entry.iconPath,
518
1028
  size: '24',
519
- color: 'primary.main'
1029
+ color: (_ref = (_entry_tile = entry.tile) == null ? void 0 : _entry_tile.color) != null ? _ref : 'primary.main'
520
1030
  }, null, null, 'menuIcon') : null;
1031
+ // A tile is a flat Card, its corners the theme's shape, its fill a role; the icon keeps its room inside it.
1032
+ const icon = glyph && entry.tile ? tree.add('muiCard', {
1033
+ variant: 'elevation',
1034
+ elevation: '0'
1035
+ }, {
1036
+ bgcolor: entry.tile.fill
1037
+ }, [
1038
+ glyph
1039
+ ], 'menuTile') : glyph;
1040
+ if (glyph && entry.tile) tree.nodes[glyph].sx = {
1041
+ m: 0.75
1042
+ };
521
1043
  const name = tree.add('muiTypography', {
522
1044
  children: entry.label,
523
1045
  variant: 'subtitle2',
@@ -571,7 +1093,7 @@ function footerOf(raw) {
571
1093
  return isContactHref(href) ? href : null;
572
1094
  }
573
1095
  /** The source's footer drawn (AGL-4108): its words and profiles beside its columns, its © line and other links under a rule. */ export function aiLayoutSourceFooter(tree, footer, input) {
574
- var _footer_copyright;
1096
+ var _footer_panels, _footer_copyright;
575
1097
  // The footer's words are quiet and small, set once on the footer for every line and link under it.
576
1098
  const quiet = {
577
1099
  color: 'text.secondary'
@@ -629,8 +1151,47 @@ function footerOf(raw) {
629
1151
  to: mail
630
1152
  }, 'email') : null
631
1153
  ].filter((id)=>!!id);
1154
+ // Its filled boxes, under its words as the source sets them (AGL-4139): a heading with its icon, its words, its links.
1155
+ const boxes = ((_footer_panels = footer.panels) != null ? _footer_panels : []).map((box)=>{
1156
+ const icon = box.iconPath ? tree.add('icon', {
1157
+ iconPath: box.iconPath,
1158
+ size: '20',
1159
+ color: 'primary.main'
1160
+ }, null, null, 'footerBoxIcon') : null;
1161
+ const heading = box.heading ? tree.add('muiTypography', {
1162
+ children: box.heading,
1163
+ variant: 'overline',
1164
+ component: 'p'
1165
+ }, {
1166
+ color: 'text.primary'
1167
+ }, null, 'footerBoxHeading') : null;
1168
+ const words = [
1169
+ icon || heading ? tree.add('muiStack', {
1170
+ direction: 'row',
1171
+ spacing: '1',
1172
+ alignItems: 'center'
1173
+ }, null, [
1174
+ icon,
1175
+ heading
1176
+ ], 'footerBoxTitle') : null,
1177
+ ...box.lines.map((line)=>tree.add('muiTypography', {
1178
+ children: line,
1179
+ variant: 'body2',
1180
+ component: 'p'
1181
+ }, null, null, 'footerBoxText')),
1182
+ ...box.links.map((entry)=>footerLink(entry, 'footerBoxLink'))
1183
+ ].filter((id)=>!!id);
1184
+ // Ruled, as the source draws it; in the site's dark scheme where the source's is a dark box on a light footer.
1185
+ const card = columnBox(tree, box.band, words, 'outlined');
1186
+ return box.band === 'dark' ? tree.add('muiStack', {
1187
+ colorScheme: 'dark'
1188
+ }, null, [
1189
+ card
1190
+ ], 'footerBoxScheme') : card;
1191
+ });
632
1192
  const about = [
633
1193
  ...lines,
1194
+ ...boxes,
634
1195
  profiles,
635
1196
  ...reach.length ? [
636
1197
  tree.add('muiStack', {