@aglyn/plugins-ai 1.7.0 → 1.9.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 (105) hide show
  1. package/package.json +17 -17
  2. package/src/lib/activity/ai-activity.js +4 -2
  3. package/src/lib/activity/ai-activity.js.map +1 -1
  4. package/src/lib/components/ai-credits-card.component.d.ts +4 -3
  5. package/src/lib/components/ai-credits-card.component.js +13 -12
  6. package/src/lib/components/ai-credits-card.component.js.map +1 -1
  7. package/src/lib/components/ai-site-import-job.component.js +14 -5
  8. package/src/lib/components/ai-site-import-job.component.js.map +1 -1
  9. package/src/lib/components/ai-upsell-dialog.component.d.ts +2 -2
  10. package/src/lib/components/ai-upsell-dialog.component.js +3 -3
  11. package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
  12. package/src/lib/components/staff-org-ai-card.component.js +2 -2
  13. package/src/lib/components/staff-org-ai-card.component.js.map +1 -1
  14. package/src/lib/declarations.d.ts +2 -2
  15. package/src/lib/declarations.js +10 -9
  16. package/src/lib/declarations.js.map +1 -1
  17. package/src/lib/jobs/ai-job-import-step.d.ts +28 -2
  18. package/src/lib/jobs/ai-job-import-step.js +170 -14
  19. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  20. package/src/lib/jobs/ai-job-layout-language.js +2 -0
  21. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  22. package/src/lib/jobs/ai-job-page-language.js +6 -2
  23. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  24. package/src/lib/jobs/ai-site-import-compile.d.ts +13 -3
  25. package/src/lib/jobs/ai-site-import-compile.js +339 -27
  26. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  27. package/src/lib/jobs/ai-site-import-document.d.ts +3 -1
  28. package/src/lib/jobs/ai-site-import-document.js +42 -1
  29. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  30. package/src/lib/jobs/ai-site-import-look.d.ts +9 -0
  31. package/src/lib/jobs/ai-site-import-look.js +89 -6
  32. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  33. package/src/lib/layout-language/ai-layout-compiler.d.ts +16 -0
  34. package/src/lib/layout-language/ai-layout-compiler.js +378 -56
  35. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  36. package/src/lib/layout-language/ai-layout-frame-source.d.ts +88 -2
  37. package/src/lib/layout-language/ai-layout-frame-source.js +591 -30
  38. package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
  39. package/src/lib/layout-language/ai-layout-frame.js +30 -18
  40. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  41. package/src/lib/layout-language/ai-layout-language.d.ts +74 -3
  42. package/src/lib/layout-language/ai-layout-language.js +5 -3
  43. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  44. package/src/lib/layout-language/ai-layout-store.d.ts +8 -0
  45. package/src/lib/layout-language/ai-layout-store.js +32 -6
  46. package/src/lib/layout-language/ai-layout-store.js.map +1 -1
  47. package/src/lib/model/ai-site-import-fidelity.d.ts +31 -1
  48. package/src/lib/model/ai-site-import-fidelity.js +347 -25
  49. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  50. package/src/lib/model/ai-site-import-view.js +4 -3
  51. package/src/lib/model/ai-site-import-view.js.map +1 -1
  52. package/src/lib/model/ai-site-import.d.ts +205 -6
  53. package/src/lib/model/ai-site-import.js +161 -5
  54. package/src/lib/model/ai-site-import.js.map +1 -1
  55. package/src/lib/model/ai-site-look.d.ts +8 -1
  56. package/src/lib/model/ai-site-look.js +8 -5
  57. package/src/lib/model/ai-site-look.js.map +1 -1
  58. package/src/lib/model/ai-upsell-copy.js +4 -3
  59. package/src/lib/model/ai-upsell-copy.js.map +1 -1
  60. package/src/lib/plan-entitlements.d.ts +3 -3
  61. package/src/lib/plan-entitlements.js +1 -1
  62. package/src/lib/plan-entitlements.js.map +1 -1
  63. package/src/lib/providers/model-choice.d.ts +6 -3
  64. package/src/lib/providers/model-choice.js +8 -4
  65. package/src/lib/providers/model-choice.js.map +1 -1
  66. package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -1
  67. package/src/lib/runtime/ai-doctrine-validators.js +25 -2
  68. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  69. package/src/lib/runtime/ai-node-tree.js +19 -2
  70. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  71. package/src/lib/runtime/ai-page-links.d.ts +15 -0
  72. package/src/lib/runtime/ai-page-links.js +48 -0
  73. package/src/lib/runtime/ai-page-links.js.map +1 -1
  74. package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +1 -1
  75. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +35 -6
  76. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  77. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +9 -0
  78. package/src/lib/site-import/fixtures/site-layout-recordings.js +24 -5
  79. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  80. package/src/lib/site-import/site-import-crawl.d.ts +3 -1
  81. package/src/lib/site-import/site-import-crawl.js +8 -3
  82. package/src/lib/site-import/site-import-crawl.js.map +1 -1
  83. package/src/lib/site-import/site-import-css.d.ts +20 -0
  84. package/src/lib/site-import/site-import-css.js +106 -0
  85. package/src/lib/site-import/site-import-css.js.map +1 -1
  86. package/src/lib/site-import/site-import-html.d.ts +39 -0
  87. package/src/lib/site-import/site-import-html.js +515 -5
  88. package/src/lib/site-import/site-import-html.js.map +1 -1
  89. package/src/lib/site-import/site-import-layout.d.ts +16 -6
  90. package/src/lib/site-import/site-import-layout.js +528 -52
  91. package/src/lib/site-import/site-import-layout.js.map +1 -1
  92. package/src/lib/site-import/site-import-nav.js +286 -24
  93. package/src/lib/site-import/site-import-nav.js.map +1 -1
  94. package/src/lib/site-import/site-import-page.js +3 -0
  95. package/src/lib/site-import/site-import-page.js.map +1 -1
  96. package/src/lib/usage/assist-credits.d.ts +5 -4
  97. package/src/lib/usage/assist-credits.js +5 -4
  98. package/src/lib/usage/assist-credits.js.map +1 -1
  99. package/src/lib/usage/staff-org-ai-view.js +6 -6
  100. package/src/lib/usage/staff-org-ai-view.js.map +1 -1
  101. package/src/lib/usage/staff-org-ai.d.ts +4 -4
  102. package/src/lib/usage/staff-org-ai.js +8 -7
  103. package/src/lib/usage/staff-org-ai.js.map +1 -1
  104. package/src/lib/usage/staff-org-usage-ai.js +2 -2
  105. package/src/lib/usage/staff-org-usage-ai.js.map +1 -1
@@ -43,7 +43,7 @@
43
43
  * site. The score is the lowest ratio of the structure; words are held apart
44
44
  * at exactly 1.
45
45
  *=========================================*/ import { _ as _extends } from "@swc/helpers/_/_extends";
46
- import { siteImportWidthOf } from "./ai-site-import.js";
46
+ import { SITE_IMPORT_PLAY_WORDS, siteImportWidthOf } from "./ai-site-import.js";
47
47
  /** The lowest score of structure a page brought in ships at (AGL-4109); words are held at exactly 1. */ export const SITE_IMPORT_FIDELITY_THRESHOLD = 0.9;
48
48
  /*------------------------------------------
49
49
  * Words and lines
@@ -258,9 +258,10 @@ const ratioBoth = (source, built)=>({
258
258
  const root = (_sectionRoots_index = sectionRoots[index]) != null ? _sectionRoots_index : built.tree.rootId;
259
259
  const scope = new Set(built.under(root));
260
260
  const pieces = built.pieces.filter((piece)=>scope.has(piece.node));
261
+ // A film's poster is placed as its Video element's (AGL-4140).
261
262
  const images = built.under(root).filter((id)=>{
262
- var _built_node;
263
- return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'image';
263
+ var _built_node, _built_node1;
264
+ return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'image' || ((_built_node1 = built.node(id)) == null ? void 0 : _built_node1.componentId) === 'video';
264
265
  });
265
266
  let cursor = -1;
266
267
  let previous = null;
@@ -270,8 +271,8 @@ const ratioBoth = (source, built)=>({
270
271
  if (block.kind === 'image') {
271
272
  const src = photoOf.get(block.url);
272
273
  const found = src ? images.find((id)=>{
273
- var _built_node_props, _built_node;
274
- return !this.imageClaimed.has(id) && ((_built_node = built.node(id)) == null ? void 0 : (_built_node_props = _built_node.props) == null ? void 0 : _built_node_props['src']) === src;
274
+ var _built_node, _built_node_props, _built_node1;
275
+ return !this.imageClaimed.has(id) && ((_built_node1 = built.node(id)) == null ? void 0 : (_built_node_props = _built_node1.props) == null ? void 0 : _built_node_props[((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'video' ? 'poster' : 'src']) === src;
275
276
  }) : undefined;
276
277
  if (found) {
277
278
  this.imageClaimed.add(found);
@@ -413,6 +414,12 @@ const ratioBoth = (source, built)=>({
413
414
  built: 0,
414
415
  lone: 0
415
416
  };
417
+ // The films drawn as the Video element, playing from an address (AGL-4140).
418
+ const drawnFilms = built.order.filter((id)=>{
419
+ var _built_node, _built_node_props, _built_node1;
420
+ return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'video' && !!clean((_built_node1 = built.node(id)) == null ? void 0 : (_built_node_props = _built_node1.props) == null ? void 0 : _built_node_props['src']);
421
+ }).length;
422
+ const films = drawnFilms > 0;
416
423
  sections.forEach((section, index)=>{
417
424
  var _roots_index;
418
425
  const root = (_roots_index = roots[index]) != null ? _roots_index : null;
@@ -426,6 +433,15 @@ const ratioBoth = (source, built)=>({
426
433
  var _drawnAs_props;
427
434
  if (!node.button) break;
428
435
  const block = source.blocks[node.line];
436
+ // A button whose words say it plays a film plays the page's film where one is drawn (AGL-4140).
437
+ if ((block == null ? void 0 : block.kind) === 'paragraph' && films && SITE_IMPORT_PLAY_WORDS.test(block.text)) {
438
+ var _drawnAs_props1;
439
+ buttons.source += 1;
440
+ const id = placement.of.get(node.line);
441
+ const drawnAs = id ? built.node(id) : undefined;
442
+ if ((drawnAs == null ? void 0 : drawnAs.componentId) === 'muiButton' && ((_drawnAs_props1 = drawnAs.props) == null ? void 0 : _drawnAs_props1['variant']) === BUTTON_VARIANT[node.button] && hasDestination(drawnAs)) buttons.built += 1;
443
+ break;
444
+ }
429
445
  // A button that goes nowhere a page can send a visitor (a film's play button its script runs) is kept as its words.
430
446
  if ((block == null ? void 0 : block.kind) !== 'link' || !/^(?:https?:|mailto:|tel:)/i.test(block.href)) {
431
447
  buttons.unlinked += 1;
@@ -458,7 +474,8 @@ const ratioBoth = (source, built)=>({
458
474
  node.items.forEach((item, at)=>{
459
475
  var _ref;
460
476
  var _item_list, _units_at;
461
- const wanted = (item.icon !== undefined ? 1 : 0) + (item.listIcon !== undefined ? (_ref = (_item_list = item.list) == null ? void 0 : _item_list.length) != null ? _ref : 0 : 0);
477
+ // Its corner arrow too (AGL-4138): a card's "↗" is an icon of its own.
478
+ const wanted = (item.icon !== undefined ? 1 : 0) + (item.mark !== undefined ? 1 : 0) + (item.listIcon !== undefined ? (_ref = (_item_list = item.list) == null ? void 0 : _item_list.length) != null ? _ref : 0 : 0);
462
479
  if (!wanted) return;
463
480
  icons.source += wanted;
464
481
  const element = (_units_at = units[at]) == null ? void 0 : _units_at.element;
@@ -528,12 +545,15 @@ const ratioBoth = (source, built)=>({
528
545
  }
529
546
  });
530
547
  const pictures = picturesScore(source, built, placement);
548
+ const framing = framingScore(source, built, placement);
531
549
  const headings = headingsScore(source, built, placement);
532
550
  const widths = widthsScore(sections, built, roots);
533
551
  const forms = ratioBoth(sections.reduce((total, section)=>total + layoutNodes(section.nodes).filter((node)=>node.kind === 'form').length, 0), built.order.filter((id)=>{
534
552
  var _built_node;
535
553
  return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'form';
536
554
  }).length);
555
+ // A film playing behind a section's words is drawn as its poster there, and is the pictures' to count.
556
+ const videos = ratioKept(sections.reduce((total, section)=>total + layoutNodes(section.nodes).reduce((count, node)=>count + (node.kind === 'video' ? 1 : node.kind === 'group' ? node.items.filter((item)=>item.video !== undefined).length : 0), 0), 0), drawnFilms);
537
557
  const report = {
538
558
  words,
539
559
  sections: ratioBoth(sections.length, drawnSections.length),
@@ -553,6 +573,7 @@ const ratioBoth = (source, built)=>({
553
573
  tables: ratioKept(tables.source, tables.built),
554
574
  tabs: ratioKept(tabs.source, tabs.built),
555
575
  pictures,
576
+ framing,
556
577
  icons: _extends({}, ratioKept(icons.source, icons.built), {
557
578
  lone: icons.lone
558
579
  }),
@@ -560,7 +581,8 @@ const ratioBoth = (source, built)=>({
560
581
  unlinked: buttons.unlinked
561
582
  }),
562
583
  headings,
563
- forms
584
+ forms,
585
+ videos
564
586
  };
565
587
  return _extends({}, lowestOf(pageMeasures(report)), report);
566
588
  }
@@ -571,8 +593,8 @@ const ratioBoth = (source, built)=>({
571
593
  if (kind === 'faq' && !built.has(element, (node)=>node.componentId === 'muiAccordion')) return false;
572
594
  // An item the source made a link as a whole still goes there.
573
595
  if (item.to && !built.has(element, hasDestination)) return false;
574
- // A picture of the item's own, where the library's copy is not known to the score.
575
- if (item.image !== undefined && !built.has(element, (node)=>node.componentId === 'image')) return false;
596
+ // A picture of the item's own, where the library's copy is not known to the score; a film's poster is its Video element's (AGL-4140).
597
+ if (item.image !== undefined && !built.has(element, (node)=>node.componentId === 'image' || node.componentId === 'video')) return false;
576
598
  return true;
577
599
  }
578
600
  /** The words: the source's lines against what the page shows, each word as often as it is said. */ function wordsScore(source, built) {
@@ -645,13 +667,116 @@ const WIDTH_RANK = {
645
667
  var _source_blocks_ref;
646
668
  return ((_source_blocks_ref = source.blocks[ref]) == null ? void 0 : _source_blocks_ref.kind) === 'image' && isLine(source.blocks[ref]);
647
669
  });
670
+ // A film's poster is a picture drawn, on its Video element (AGL-4140).
648
671
  const drawn = built.order.filter((id)=>{
649
- var _built_node;
650
- return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'image';
672
+ var _built_node, _built_node1, _built_node_props, _built_node2;
673
+ return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'image' || ((_built_node1 = built.node(id)) == null ? void 0 : _built_node1.componentId) === 'video' && !!clean((_built_node2 = built.node(id)) == null ? void 0 : (_built_node_props = _built_node2.props) == null ? void 0 : _built_node_props['poster']);
651
674
  }).length;
652
675
  if (!((_source_photos = source.photos) == null ? void 0 : _source_photos.length)) return ratioBoth(refs.length, drawn);
653
676
  return ratioKept(refs.length, refs.filter((ref)=>placement.of.has(ref)).length);
654
677
  }
678
+ /** How near two shapes must be to be one (AGL-4138): 5%. */ const SAME_SHAPE = 0.05;
679
+ /** A box's shape as the compiler writes it, width over height: "1600 / 900", "1.7778", 1.5. */ function shapeOf(value) {
680
+ if (typeof value === 'number') return value > 0 ? value : null;
681
+ if (typeof value !== 'string') return null;
682
+ const match = /^\s*(\d*\.?\d+)\s*(?:\/\s*(\d*\.?\d+))?\s*$/.exec(value);
683
+ if (!match) return null;
684
+ const width = Number(match[1]);
685
+ const height = match[2] === undefined ? 1 : Number(match[2]);
686
+ return width > 0 && height > 0 ? width / height : null;
687
+ }
688
+ /** A height in px as the compiler writes one: "320px", 320. */ function heightOf(value) {
689
+ if (typeof value === 'number') return value > 1 ? value : null;
690
+ const match = typeof value === 'string' ? /^\s*(\d*\.?\d+)px\s*$/.exec(value) : null;
691
+ return match ? Number(match[1]) : null;
692
+ }
693
+ /**
694
+ * The box a built picture is shown in: its own `aspectRatio` or height, else
695
+ * the frame holding it alone that sets one; `whole` where nothing frames it, or
696
+ * it is fitted inside its box (`contain`), which cuts nothing.
697
+ */ function builtFrame(built, id) {
698
+ var _read;
699
+ var _image_props;
700
+ const image = built.node(id);
701
+ if (!image) return 'whole';
702
+ if (((_image_props = image.props) == null ? void 0 : _image_props['objectFit']) === 'contain') return 'whole';
703
+ const read = (node)=>{
704
+ var _ref, _ref1;
705
+ var _node_props;
706
+ const sx = (_ref = node == null ? void 0 : node.sx) != null ? _ref : {};
707
+ const height = heightOf((node == null ? void 0 : node.componentId) === 'image' ? (_ref1 = (_node_props = node.props) == null ? void 0 : _node_props['height']) != null ? _ref1 : sx['height'] : sx['height']);
708
+ if (height !== null) return {
709
+ ratios: [],
710
+ height
711
+ };
712
+ const ratio = sx['aspectRatio'];
713
+ const ratios = (ratio && typeof ratio === 'object' ? Object.values(ratio) : [
714
+ ratio
715
+ ]).map(shapeOf).filter((value)=>value !== null);
716
+ return ratios.length ? {
717
+ ratios,
718
+ height: null
719
+ } : null;
720
+ };
721
+ const own = read(image);
722
+ if (own) return own;
723
+ const frame = built.parent.get(id);
724
+ const holder = frame ? built.node(frame) : undefined;
725
+ if (holder && built.children(frame).length === 1 && holder.componentId === 'muiBox') return (_read = read(holder)) != null ? _read : 'whole';
726
+ return 'whole';
727
+ }
728
+ /**
729
+ * The pictures framed as their source frames them (AGL-4138): each placed
730
+ * picture's box against the shape the source shows it at — the box or the
731
+ * height it crops it to, else its own, by the library's copy's size or its
732
+ * `width` and `height` — within 5%; a picture the source shows whole may be
733
+ * shown in no box. A round portrait and the picture a section lays behind
734
+ * its words are not scored, nor a picture whose own shape is not known.
735
+ */ function framingScore(source, built, placement) {
736
+ var _source_photos;
737
+ const sizes = new Map();
738
+ for (const photo of (_source_photos = source.photos) != null ? _source_photos : [])if (photo.from && photo.width && photo.height) sizes.set(photo.from, photo.width / photo.height);
739
+ let measured = 0;
740
+ let kept = 0;
741
+ const score = (ref, fit)=>{
742
+ var _ref, _ref1, _sizes_get, _ref2;
743
+ const block = source.blocks[ref];
744
+ const id = placement.of.get(ref);
745
+ if ((block == null ? void 0 : block.kind) !== 'image' || !id || ((_ref = fit == null ? void 0 : fit.radius) != null ? _ref : 0) >= 999) return;
746
+ const frame = builtFrame(built, id);
747
+ const own = (_ref1 = (_sizes_get = sizes.get(block.url)) != null ? _sizes_get : fit == null ? void 0 : fit.ratio) != null ? _ref1 : null;
748
+ if (fit == null ? void 0 : fit.height) {
749
+ measured += 1;
750
+ if (frame !== 'whole' && frame.height !== null && Math.abs(frame.height / fit.height - 1) <= SAME_SHAPE) kept += 1;
751
+ return;
752
+ }
753
+ const wanted = (_ref2 = fit == null ? void 0 : fit.box) != null ? _ref2 : own;
754
+ if (wanted === null || wanted === undefined) return;
755
+ measured += 1;
756
+ if (frame === 'whole') {
757
+ if (!(fit == null ? void 0 : fit.box)) kept += 1;
758
+ return;
759
+ }
760
+ if (frame.height === null && frame.ratios.every((ratio)=>Math.abs(ratio / wanted - 1) <= SAME_SHAPE)) kept += 1;
761
+ };
762
+ for (const section of source.layout.sections){
763
+ var _section_hero;
764
+ // A picture the section lays behind its words fills the band, as it is meant to.
765
+ const behind = ((_section_hero = section.hero) == null ? void 0 : _section_hero.picture) === 'behind' ? section.lines.find((ref)=>{
766
+ var _source_blocks_ref;
767
+ return ((_source_blocks_ref = source.blocks[ref]) == null ? void 0 : _source_blocks_ref.kind) === 'image';
768
+ }) : undefined;
769
+ for (const node of layoutNodes(section.nodes)){
770
+ if (node.kind === 'picture' && node.line !== behind) score(node.line, node.fit);
771
+ // A film's poster is framed as any picture is (AGL-4140).
772
+ if (node.kind === 'video' && node.poster !== undefined && node.poster !== behind) score(node.poster, node.fit);
773
+ if (node.kind === 'group') {
774
+ for (const item of node.items)if (item.image !== undefined && item.image !== behind) score(item.image, item.imageFit);
775
+ }
776
+ }
777
+ }
778
+ return ratioKept(measured, kept);
779
+ }
655
780
  /** The headings: each of the source's drawn as a heading (an `h1`–`h6`, or the question of an accordion). */ function headingsScore(source, built, placement) {
656
781
  const refs = source.layout.sections.flatMap((section)=>section.lines).filter((ref)=>{
657
782
  var _source_blocks_ref;
@@ -700,6 +825,10 @@ const WIDTH_RANK = {
700
825
  'pictures',
701
826
  report.pictures
702
827
  ],
828
+ [
829
+ 'framing',
830
+ report.framing
831
+ ],
703
832
  [
704
833
  'icons',
705
834
  report.icons
@@ -715,6 +844,10 @@ const WIDTH_RANK = {
715
844
  [
716
845
  'forms',
717
846
  report.forms
847
+ ],
848
+ [
849
+ 'videos',
850
+ report.videos
718
851
  ]
719
852
  ];
720
853
  }
@@ -732,6 +865,59 @@ const WIDTH_RANK = {
732
865
  lowest
733
866
  };
734
867
  }
868
+ /**
869
+ * A menu of the header's row as it is built (AGL-4139): the Dropdown or Mega
870
+ * Menu element under its name, or its name as a link and the panel its hover
871
+ * shows; what it holds, and whether it opens on hover.
872
+ */ function siteImportBuiltMenu(built, row, name) {
873
+ var _built_children_find;
874
+ const named = (id)=>clean(labelOf(built.node(id))) === clean(name);
875
+ const hoverSteps = (id)=>{
876
+ var _ref;
877
+ var _built_node;
878
+ return ((_ref = (_built_node = built.node(id)) == null ? void 0 : _built_node.interactions) != null ? _ref : []).flatMap((interaction)=>{
879
+ var _record_steps;
880
+ var _record_trigger;
881
+ const record = interaction;
882
+ return record.enabled !== false && ((_record_trigger = record.trigger) == null ? void 0 : _record_trigger.event) === 'elementHoverEnter' ? (_record_steps = record.steps) != null ? _record_steps : [] : [];
883
+ });
884
+ };
885
+ const element = built.under(row).find((id)=>{
886
+ var _built_node, _built_node1;
887
+ return (((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'muiMegaMenu' || ((_built_node1 = built.node(id)) == null ? void 0 : _built_node1.componentId) === 'muiNavMenu') && named(id);
888
+ });
889
+ if (element) return {
890
+ inside: built.under(element),
891
+ hover: hoverSteps(element).some((step)=>step['type'] === 'openMenu')
892
+ };
893
+ const link = built.under(row).find((id)=>{
894
+ var _ref;
895
+ var _built_node;
896
+ return LINK_COMPONENTS.has((_ref = (_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) != null ? _ref : '') && named(id);
897
+ });
898
+ if (!link) return null;
899
+ // The panel its hover shows: on the name itself, or on the item that holds the name and its panel.
900
+ const item = (_built_children_find = built.children(row).find((id)=>built.holds(id, link))) != null ? _built_children_find : link;
901
+ const shown = [
902
+ ...hoverSteps(link),
903
+ ...hoverSteps(item)
904
+ ].filter((step)=>step['type'] === 'showElement');
905
+ const panelId = shown.map((step)=>{
906
+ var _step_selector;
907
+ var _exec;
908
+ return (_exec = /^\[data-aglyn="leaf:(.+)"\]$/.exec(String((_step_selector = step['selector']) != null ? _step_selector : ''))) == null ? void 0 : _exec[1];
909
+ }).find((id)=>!!id && !!built.node(id));
910
+ if (!panelId) return null;
911
+ return {
912
+ inside: [
913
+ ...new Set([
914
+ ...built.under(item),
915
+ ...built.under(panelId)
916
+ ])
917
+ ],
918
+ hover: true
919
+ };
920
+ }
735
921
  /** A node's label as a menu, a link or a button carries it. */ function labelOf(node) {
736
922
  var _node_props, _node_props1, _node_props2;
737
923
  if (!node) return '';
@@ -750,7 +936,7 @@ const LINK_COMPONENTS = new Set([
750
936
  * labels on one line; the footer's columns, links, profiles and facts. The
751
937
  * score is the lowest ratio.
752
938
  */ export function siteImportFrameFidelity(source, tree) {
753
- var _all_find, _all_find1, _all_find2, _inHeader_find, _source_nav, _ref, _ref1, _ref2, _ref3, _source_footer, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10;
939
+ var _all_find, _all_find1, _all_find2, _inHeader_find, _source_nav, _ref, _ref1, _ref2, _ref3, _source_footer, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11;
754
940
  var _built_node_sx, _built_node;
755
941
  const built = new Built(tree);
756
942
  const all = built.order;
@@ -775,8 +961,16 @@ const LINK_COMPONENTS = new Set([
775
961
  })) != null ? _inHeader_find : null;
776
962
  const nav = (_source_nav = source.nav) != null ? _source_nav : null;
777
963
  const groups = (_ref = nav == null ? void 0 : nav.items) != null ? _ref : [];
778
- // The row: its items by name, in order.
779
- const rowItems = row ? built.children(row).map((id)=>labelOf(built.node(id))) : [];
964
+ // The row: its items by name, in order; a menu drawn as its name and its panel by its name's.
965
+ const itemLabel = (id)=>{
966
+ var _built_children_find;
967
+ return labelOf(built.node(id)) || labelOf(built.node((_built_children_find = built.children(id).find((child)=>{
968
+ var _ref;
969
+ var _built_node;
970
+ return LINK_COMPONENTS.has((_ref = (_built_node = built.node(child)) == null ? void 0 : _built_node.componentId) != null ? _ref : '');
971
+ })) != null ? _built_children_find : ''));
972
+ };
973
+ const rowItems = row ? built.children(row).map(itemLabel) : [];
780
974
  const wanted = groups.map((item)=>clean(item.label));
781
975
  const left = [
782
976
  ...rowItems
@@ -803,21 +997,84 @@ const LINK_COMPONENTS = new Set([
803
997
  source: 0,
804
998
  built: 0
805
999
  };
1000
+ const menuColumns = {
1001
+ source: 0,
1002
+ built: 0
1003
+ };
1004
+ const panels = {
1005
+ source: 0,
1006
+ built: 0
1007
+ };
1008
+ const tiles = {
1009
+ source: 0,
1010
+ built: 0
1011
+ };
1012
+ const pictures = {
1013
+ source: 0,
1014
+ built: 0
1015
+ };
1016
+ const hover = {
1017
+ source: 0,
1018
+ built: 0
1019
+ };
1020
+ const filled = (id)=>{
1021
+ var _node_props, _node_sx;
1022
+ const node = built.node(id);
1023
+ return !!node && (node.componentId === 'muiCard' || ((_node_props = node.props) == null ? void 0 : _node_props['colorScheme']) === 'dark' || ((_node_sx = node.sx) == null ? void 0 : _node_sx['bgcolor']) !== undefined);
1024
+ };
1025
+ const label = (id)=>labelOf(built.node(id)) || shownTexts(built.node(id))[0] || '';
806
1026
  for (const group of groups){
1027
+ var _group_columns;
1028
+ var _group_panel, _group_panel1;
807
1029
  if (!group.items.length) continue;
808
1030
  menus.source += 1;
809
1031
  entries.source += group.items.length;
810
- const menu = row ? built.under(row).find((id)=>{
811
- var _built_node, _built_node1, _built_node_props, _built_node2;
812
- return (((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'muiMegaMenu' || ((_built_node1 = built.node(id)) == null ? void 0 : _built_node1.componentId) === 'muiNavMenu') && clean((_built_node2 = built.node(id)) == null ? void 0 : (_built_node_props = _built_node2.props) == null ? void 0 : _built_node_props['label']) === clean(group.label);
813
- }) : undefined;
1032
+ if ((_group_panel = group.panel) == null ? void 0 : _group_panel.hover) hover.source += 1;
1033
+ const drawnMenu = row ? siteImportBuiltMenu(built, row, group.label) : null;
814
1034
  for (const entry of group.items){
815
1035
  if (entry.text) details.source += 1;
816
1036
  if (entry.iconPath) details.source += 1;
1037
+ if (entry.tile) tiles.source += 1;
1038
+ }
1039
+ const columns = (_group_columns = group.columns) != null ? _group_columns : [];
1040
+ const panelled = columns.length >= 2 || columns.some((column)=>column.band !== 'plain' || !!column.image || column.lines.length > 0);
1041
+ if (panelled) {
1042
+ menuColumns.source += columns.length;
1043
+ panels.source += columns.filter((column)=>column.band !== 'plain').length;
1044
+ pictures.source += columns.filter((column)=>!!column.image).length;
817
1045
  }
818
- if (!menu) continue;
1046
+ if (!drawnMenu) continue;
819
1047
  menus.built += 1;
820
- const inside = built.under(menu);
1048
+ if (((_group_panel1 = group.panel) == null ? void 0 : _group_panel1.hover) && drawnMenu.hover) hover.built += 1;
1049
+ const inside = drawnMenu.inside;
1050
+ if (panelled) {
1051
+ // The panel's row: the part of it whose children hold the source's columns, each in its place.
1052
+ const wanted = columns.map((column, index)=>({
1053
+ column,
1054
+ labels: group.items.filter((entry)=>{
1055
+ var _entry_at;
1056
+ return Math.min((_entry_at = entry.at) != null ? _entry_at : 0, columns.length - 1) === index;
1057
+ }).map((entry)=>clean(entry.label))
1058
+ }));
1059
+ const placed = (cell, want)=>{
1060
+ const texts = new Set(built.under(cell).map(label));
1061
+ return want.labels.every((name)=>texts.has(name)) && (!want.column.heading || texts.has(clean(want.column.heading))) && want.column.lines.every((line)=>texts.has(clean(line)));
1062
+ };
1063
+ let best = [];
1064
+ for (const id of inside){
1065
+ const cells = built.children(id);
1066
+ if (cells.length < columns.length) continue;
1067
+ const kept = wanted.filter((want, index)=>!!cells[index] && placed(cells[index], want)).length;
1068
+ if (kept > best.filter(Boolean).length) best = wanted.map((want, index)=>cells[index] && placed(cells[index], want) ? cells[index] : '');
1069
+ }
1070
+ menuColumns.built += best.filter(Boolean).length;
1071
+ columns.forEach((column, index)=>{
1072
+ const cell = best[index];
1073
+ if (!cell) return;
1074
+ if (column.band !== 'plain' && built.under(cell).some(filled)) panels.built += 1;
1075
+ if (column.image && built.has(cell, (node)=>node.componentId === 'image')) pictures.built += 1;
1076
+ });
1077
+ }
821
1078
  const links = inside.filter((id)=>{
822
1079
  var _ref;
823
1080
  var _built_node;
@@ -830,6 +1087,13 @@ const LINK_COMPONENTS = new Set([
830
1087
  entries.built += 1;
831
1088
  if (entry.text && texts.has(clean(entry.text))) details.built += 1;
832
1089
  if (entry.iconPath && built.has(link, (node)=>node.componentId === 'icon')) details.built += 1;
1090
+ // A tile: the icon held in a filled box of its own.
1091
+ const icon = built.under(link).find((id)=>{
1092
+ var _built_node;
1093
+ return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'icon';
1094
+ });
1095
+ const box = icon ? built.parent.get(icon) : undefined;
1096
+ if (entry.tile && box && box !== link && filled(box)) tiles.built += 1;
833
1097
  }
834
1098
  }
835
1099
  // The buttons, as the source draws them.
@@ -850,10 +1114,20 @@ const LINK_COMPONENTS = new Set([
850
1114
  // The phone menu: every name, entry, link and button of the row.
851
1115
  const drawerTexts = new Set(drawer ? built.under(drawer).flatMap((id)=>shownTexts(built.node(id))) : []);
852
1116
  const drawerWanted = [
853
- ...groups.flatMap((group)=>[
1117
+ ...groups.flatMap((group)=>{
1118
+ var _group_columns;
1119
+ return [
854
1120
  clean(group.label),
855
- ...group.items.map((entry)=>clean(entry.label))
856
- ]),
1121
+ ...group.items.map((entry)=>clean(entry.label)),
1122
+ // Every word of a menu's panel too (AGL-4139): its columns' headings and lines.
1123
+ ...((_group_columns = group.columns) != null ? _group_columns : []).flatMap((column)=>[
1124
+ ...column.heading ? [
1125
+ clean(column.heading)
1126
+ ] : [],
1127
+ ...column.lines.map(clean)
1128
+ ])
1129
+ ];
1130
+ }),
857
1131
  ...((_ref2 = nav == null ? void 0 : nav.ctas) != null ? _ref2 : []).map((cta)=>clean(cta.label))
858
1132
  ].filter(Boolean);
859
1133
  const toggle = inHeader.some(is('muiDrawerToggle'));
@@ -901,6 +1175,24 @@ const LINK_COMPONENTS = new Set([
901
1175
  foot == null ? void 0 : foot.email,
902
1176
  foot == null ? void 0 : foot.copyright
903
1177
  ].map(clean).filter(Boolean);
1178
+ // Its filled boxes, each a filled box holding its heading, words and links (AGL-4139).
1179
+ for (const box of (_ref8 = foot == null ? void 0 : foot.panels) != null ? _ref8 : []){
1180
+ var _box_links;
1181
+ panels.source += 1;
1182
+ const want = [
1183
+ box.heading,
1184
+ ...box.lines,
1185
+ ...((_box_links = box.links) != null ? _box_links : []).map((entry)=>entry.label)
1186
+ ].filter((text)=>!!text).map(clean);
1187
+ if (footIds.some((id)=>filled(id) && want.every((text)=>built.under(id).some((at)=>label(at) === text)))) panels.built += 1;
1188
+ }
1189
+ // It opens with the logo: a picture before any of its words.
1190
+ const firstWords = footIds.find((id)=>shownTexts(built.node(id)).length > 0);
1191
+ const firstPicture = footIds.find((id)=>{
1192
+ var _built_node;
1193
+ return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'image';
1194
+ });
1195
+ const logo = ratioKept((foot == null ? void 0 : foot.logo) ? 1 : 0, (foot == null ? void 0 : foot.logo) && firstPicture && (!firstWords || footIds.indexOf(firstPicture) < footIds.indexOf(firstWords)) ? 1 : 0);
904
1196
  const report = {
905
1197
  // Over the larger of the two: a row of the site's page titles in place of the source's menus scores low.
906
1198
  items: {
@@ -916,9 +1208,15 @@ const LINK_COMPONENTS = new Set([
916
1208
  drawer: ratioKept(drawerWanted.length, drawerWanted.filter((label)=>drawerTexts.has(label)).length),
917
1209
  phone: ratioKept(hasRow ? 1 : 0, hasRow && toggle && !!drawer ? 1 : 0),
918
1210
  nowrap: ratioKept(row ? 1 : 0, row && ((_built_node = built.node(row)) == null ? void 0 : (_built_node_sx = _built_node.sx) == null ? void 0 : _built_node_sx['whiteSpace']) === 'nowrap' ? 1 : 0),
919
- columns: ratioKept((_ref8 = foot == null ? void 0 : foot.columns.length) != null ? _ref8 : 0, ((_ref9 = foot == null ? void 0 : foot.columns) != null ? _ref9 : []).filter((column)=>footTexts.has(clean(column.heading))).length),
1211
+ menuColumns: ratioKept(menuColumns.source, menuColumns.built),
1212
+ panels: ratioKept(panels.source, panels.built),
1213
+ tiles: ratioKept(tiles.source, tiles.built),
1214
+ pictures: ratioKept(pictures.source, pictures.built),
1215
+ hover: ratioKept(hover.source, hover.built),
1216
+ logo,
1217
+ columns: ratioKept((_ref9 = foot == null ? void 0 : foot.columns.length) != null ? _ref9 : 0, ((_ref10 = foot == null ? void 0 : foot.columns) != null ? _ref10 : []).filter((column)=>footTexts.has(clean(column.heading))).length),
920
1218
  links: ratioKept(linksWanted.length, linksKept),
921
- social: ratioKept((_ref10 = foot == null ? void 0 : foot.social.length) != null ? _ref10 : 0, socialKept),
1219
+ social: ratioKept((_ref11 = foot == null ? void 0 : foot.social.length) != null ? _ref11 : 0, socialKept),
922
1220
  facts: ratioKept(facts.length, facts.filter((fact)=>footTexts.has(fact)).length)
923
1221
  };
924
1222
  const measures = [
@@ -954,6 +1252,30 @@ const LINK_COMPONENTS = new Set([
954
1252
  'nowrap',
955
1253
  report.nowrap
956
1254
  ],
1255
+ [
1256
+ 'menuColumns',
1257
+ report.menuColumns
1258
+ ],
1259
+ [
1260
+ 'panels',
1261
+ report.panels
1262
+ ],
1263
+ [
1264
+ 'tiles',
1265
+ report.tiles
1266
+ ],
1267
+ [
1268
+ 'pictures',
1269
+ report.pictures
1270
+ ],
1271
+ [
1272
+ 'hover',
1273
+ report.hover
1274
+ ],
1275
+ [
1276
+ 'logo',
1277
+ report.logo
1278
+ ],
957
1279
  [
958
1280
  'columns',
959
1281
  report.columns