@aglyn/plugins-ai 1.10.0 → 1.12.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 (58) hide show
  1. package/package.json +17 -17
  2. package/src/lib/jobs/ai-job-import-step.d.ts +1 -1
  3. package/src/lib/jobs/ai-job-import-step.js +26 -7
  4. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  5. package/src/lib/jobs/ai-job-privacy-step.js +2 -2
  6. package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
  7. package/src/lib/jobs/ai-site-import-compile.js +27 -37
  8. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  9. package/src/lib/jobs/ai-site-import-look.js +20 -1
  10. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  11. package/src/lib/layout-language/ai-layout-compiler.js +7 -1
  12. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  13. package/src/lib/model/ai-credit-estimate.d.ts +15 -0
  14. package/src/lib/model/ai-credit-estimate.js +13 -0
  15. package/src/lib/model/ai-credit-estimate.js.map +1 -1
  16. package/src/lib/model/ai-site-import-fidelity.d.ts +46 -3
  17. package/src/lib/model/ai-site-import-fidelity.js +254 -62
  18. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  19. package/src/lib/model/ai-site-import-report.d.ts +7 -0
  20. package/src/lib/model/ai-site-import-report.js +17 -5
  21. package/src/lib/model/ai-site-import-report.js.map +1 -1
  22. package/src/lib/model/ai-site-import.d.ts +46 -3
  23. package/src/lib/model/ai-site-import.js +34 -11
  24. package/src/lib/model/ai-site-import.js.map +1 -1
  25. package/src/lib/model/ai-site-look.d.ts +16 -0
  26. package/src/lib/model/ai-site-look.js +76 -14
  27. package/src/lib/model/ai-site-look.js.map +1 -1
  28. package/src/lib/site-import/fixtures/aglyn-com-recordings.d.ts +2 -1
  29. package/src/lib/site-import/fixtures/aglyn-com-recordings.js +3 -2
  30. package/src/lib/site-import/fixtures/aglyn-com-recordings.js.map +1 -1
  31. package/src/lib/site-import/fixtures/site-import-crawl-recordings.d.ts +5 -0
  32. package/src/lib/site-import/fixtures/site-import-crawl-recordings.js +116 -3
  33. package/src/lib/site-import/fixtures/site-import-crawl-recordings.js.map +1 -1
  34. package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +7 -0
  35. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +15 -0
  36. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  37. package/src/lib/site-import/fixtures/site-layout-recordings.js +4 -3
  38. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  39. package/src/lib/site-import/fixtures/site-look-slate.d.ts +2 -1
  40. package/src/lib/site-import/fixtures/site-look-slate.js +2 -1
  41. package/src/lib/site-import/fixtures/site-look-slate.js.map +1 -1
  42. package/src/lib/site-import/site-import-crawl.d.ts +7 -1
  43. package/src/lib/site-import/site-import-crawl.js +101 -6
  44. package/src/lib/site-import/site-import-crawl.js.map +1 -1
  45. package/src/lib/site-import/site-import-css.d.ts +8 -1
  46. package/src/lib/site-import/site-import-css.js +30 -8
  47. package/src/lib/site-import/site-import-css.js.map +1 -1
  48. package/src/lib/site-import/site-import-html.d.ts +2 -0
  49. package/src/lib/site-import/site-import-html.js +3 -0
  50. package/src/lib/site-import/site-import-html.js.map +1 -1
  51. package/src/lib/site-import/site-import-layout.d.ts +9 -2
  52. package/src/lib/site-import/site-import-layout.js +104 -30
  53. package/src/lib/site-import/site-import-layout.js.map +1 -1
  54. package/src/lib/site-import/site-import-page.js +5 -0
  55. package/src/lib/site-import/site-import-page.js.map +1 -1
  56. package/src/lib/site-import/site-import-same-page.d.ts +41 -0
  57. package/src/lib/site-import/site-import-same-page.js +108 -0
  58. package/src/lib/site-import/site-import-same-page.js.map +1 -0
@@ -63,6 +63,12 @@ import { SITE_IMPORT_PLAY_WORDS, siteImportWidthOf } from "./ai-site-import.js";
63
63
  import { aiHexOklch } from "./ai-site-look.js";
64
64
  /** 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;
65
65
  /** How far a ground of the theme may sit from the source's (AGL-4152), in OKLab. */ export const SITE_IMPORT_GROUND_DELTA = 0.05;
66
+ /**
67
+ * How far an outlined button's color may sit from the source's (AGL-4152), in
68
+ * OKLab: it is the theme's primary, a shade deepened to carry white words where
69
+ * the source's own does not, so a role and not a pin. A grey or a light one is
70
+ * far past it.
71
+ */ export const SITE_IMPORT_OUTLINE_DELTA = 0.1;
66
72
  /** How far the hero heading's share of its section may sit from the source's (AGL-4152), relatively. */ export const SITE_IMPORT_MEASURE_SHARE = 0.1;
67
73
  /** The least share of a line's content words a rewrite keeps (G4): a bold rewrite, the owner asked 11/4, still keeps a third. */ export const SITE_IMPORT_MEANING_FLOOR = 0.3;
68
74
  /** The measures Improve it prints as free (AGL-4152): what it may change. */ export const SITE_IMPORT_IMPROVE_FREE = [
@@ -532,7 +538,11 @@ const ratioBoth = (source, built)=>({
532
538
  if (improvedWords) placement.placeRewritten();
533
539
  const look = new LookOf(built, source.layout.look, theme);
534
540
  const words = wordsScore(source, built);
535
- const read = sections.map((section)=>section.band);
541
+ // Improved, a page's bands are read as its colors alone say; kept, against its page's ground (AGL-4152).
542
+ const read = sections.map((section)=>{
543
+ var _section_absoluteBand;
544
+ return finished && finish === 'improve' ? (_section_absoluteBand = section.absoluteBand) != null ? _section_absoluteBand : section.band : section.band;
545
+ });
536
546
  const drawn = drawnSections.map((id)=>siteImportFidelityBandOf(built.node(id)));
537
547
  const bandsKept = read.filter((band, index)=>drawn[index] === band).length;
538
548
  const rows = {
@@ -562,6 +572,10 @@ const ratioBoth = (source, built)=>({
562
572
  source: 0,
563
573
  built: 0
564
574
  };
575
+ const buttonOutline = {
576
+ source: 0,
577
+ built: 0
578
+ };
565
579
  const boxed = {
566
580
  source: 0,
567
581
  built: 0
@@ -583,7 +597,7 @@ const ratioBoth = (source, built)=>({
583
597
  const drawnAs = id ? built.node(id) : undefined;
584
598
  const drawn = (drawnAs == null ? void 0 : drawnAs.componentId) === 'muiButton' && ((_drawnAs_props = drawnAs.props) == null ? void 0 : _drawnAs_props['variant']) === BUTTON_VARIANT[style] && hasDestination(drawnAs);
585
599
  if (!pinned) return drawn;
586
- const cased = look.caseKept(id != null ? id : null);
600
+ const cased = look.caseKept(id != null ? id : null, style);
587
601
  if (cased !== null) {
588
602
  buttonCase.source += 1;
589
603
  if (drawn && cased) buttonCase.built += 1;
@@ -593,7 +607,12 @@ const ratioBoth = (source, built)=>({
593
607
  buttonFill.source += 1;
594
608
  if (drawn && filled) buttonFill.built += 1;
595
609
  }
596
- return drawn && cased !== false && filled !== false;
610
+ const outlined = style === 'secondary' ? look.outlineKept(id != null ? id : null) : null;
611
+ if (outlined !== null) {
612
+ buttonOutline.source += 1;
613
+ if (drawn && outlined) buttonOutline.built += 1;
614
+ }
615
+ return drawn && cased !== false && filled !== false && outlined !== false;
597
616
  };
598
617
  sections.forEach((section, index)=>{
599
618
  var _roots_index;
@@ -605,8 +624,17 @@ const ratioBoth = (source, built)=>({
605
624
  break;
606
625
  case 'line':
607
626
  {
608
- if (!node.button) break;
609
627
  const block = source.blocks[node.line];
628
+ if (!node.button) {
629
+ var _built_node;
630
+ // A link standing on its own is drawn as a text button: under Keep my site it is held to the source's case as one (AGL-4152).
631
+ const id = placement.of.get(node.line);
632
+ if (pinned && (block == null ? void 0 : block.kind) === 'link' && id && ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'muiButton') {
633
+ buttons.source += 1;
634
+ if (buttonKept(node.line, 'quiet')) buttons.built += 1;
635
+ }
636
+ break;
637
+ }
610
638
  // A button whose words say it plays a film plays the page's film where one is drawn (AGL-4140).
611
639
  if ((block == null ? void 0 : block.kind) === 'paragraph' && films && SITE_IMPORT_PLAY_WORDS.test(block.text)) {
612
640
  buttons.source += 1;
@@ -701,7 +729,7 @@ const ratioBoth = (source, built)=>({
701
729
  }
702
730
  case 'tabs':
703
731
  {
704
- var _built_node;
732
+ var _built_node1;
705
733
  tabs.source += 1;
706
734
  const labels = node.tabs.flatMap((tab)=>tab.label !== null ? [
707
735
  tab.label
@@ -711,7 +739,7 @@ const ratioBoth = (source, built)=>({
711
739
  // The Tabs element names every tab itself; a strip draws each label as an element of its own, side by side.
712
740
  const one = new Set(found.nodes).size === 1;
713
741
  const strip = built.common(found.nodes);
714
- if (one ? ((_built_node = built.node(found.nodes[0])) == null ? void 0 : _built_node.componentId) === 'muiTabs' : !!strip && setsSideBySide(built.node(strip))) tabs.built += 1;
742
+ if (one ? ((_built_node1 = built.node(found.nodes[0])) == null ? void 0 : _built_node1.componentId) === 'muiTabs' : !!strip && setsSideBySide(built.node(strip))) tabs.built += 1;
715
743
  break;
716
744
  }
717
745
  default:
@@ -763,7 +791,8 @@ const ratioBoth = (source, built)=>({
763
791
  // The measures a finish adds (AGL-4152).
764
792
  if (pinned) report.buttons = _extends({}, report.buttons, {
765
793
  case: ratioKept(buttonCase.source, buttonCase.built),
766
- fill: ratioKept(buttonFill.source, buttonFill.built)
794
+ fill: ratioKept(buttonFill.source, buttonFill.built),
795
+ outline: ratioKept(buttonOutline.source, buttonOutline.built)
767
796
  });
768
797
  const added = _extends({
769
798
  scoredAs: {
@@ -778,9 +807,12 @@ const ratioBoth = (source, built)=>({
778
807
  ] : improvedWords ? [
779
808
  'words'
780
809
  ] : [],
781
- align: alignScore(source, built, placement),
810
+ align: alignScore(source, built, placement, pinned),
782
811
  boxed: ratioKept(boxed.source, boxed.built),
783
- ground: groundScore(sections, look, roots),
812
+ ground: groundScore(sections, look, roots, pinned)
813
+ }, pinned ? {
814
+ darkGround: darkGroundScore(sections, look, roots)
815
+ } : {}, {
784
816
  measure: measureScore(source, built, placement, roots),
785
817
  readable: look.readable(drawnSections)
786
818
  }, finish === 'improve' ? {
@@ -811,6 +843,10 @@ const ratioBoth = (source, built)=>({
811
843
  'ground',
812
844
  report.ground
813
845
  ],
846
+ [
847
+ 'darkGround',
848
+ report.darkGround
849
+ ],
814
850
  [
815
851
  'measure',
816
852
  report.measure
@@ -832,7 +868,7 @@ const ratioBoth = (source, built)=>({
832
868
  * Whether a page ships (AGL-4109, AGL-4152): its score at the bar, and what
833
869
  * is held at exactly 1 whole. Its words, as written, or under improved words
834
870
  * every fact and every line, and each line's meaning at the floor; under
835
- * Keep my site, its alignment, boxes, grounds and measure.
871
+ * Keep my site, its alignment, boxes, grounds in both schemes and measure.
836
872
  */ export function siteImportFidelityHolds(report, threshold = SITE_IMPORT_FIDELITY_THRESHOLD) {
837
873
  var _ref;
838
874
  var _report_scoredAs, _report_facts, _report_lines, _report_meaning, _report_scoredAs1;
@@ -844,6 +880,7 @@ const ratioBoth = (source, built)=>({
844
880
  report.align,
845
881
  report.boxed,
846
882
  report.ground,
883
+ report.darkGround,
847
884
  report.measure
848
885
  ].every((count)=>!count || count.ratio === 1);
849
886
  }
@@ -1156,12 +1193,14 @@ function schemeOf(colors) {
1156
1193
  paper: hexOf(pathIn(colors, 'background', 'paper')),
1157
1194
  brand: hexOf(pathIn(colors, 'primary', 'main')),
1158
1195
  onBrand: hexOf(pathIn(colors, 'primary', 'contrastText')),
1159
- ink: hexOf(pathIn(colors, 'text', 'primary'))
1196
+ ink: hexOf(pathIn(colors, 'text', 'primary')),
1197
+ brandLight: hexOf(pathIn(colors, 'primary', 'light')),
1198
+ divider: hexOf(pathIn(colors, 'divider'))
1160
1199
  };
1161
1200
  return Object.values(scheme).some(Boolean) ? scheme : null;
1162
1201
  }
1163
1202
  /** A color a style names, in a scheme: a palette path (`primary.main`) as the scheme draws it, a color as itself. */ function colorIn(value, scheme) {
1164
- var _paths_value;
1203
+ var _scheme_brandLight, _scheme_divider, _paths_value;
1165
1204
  const own = hexOf(value);
1166
1205
  if (own || typeof value !== 'string') return own;
1167
1206
  const paths = {
@@ -1169,10 +1208,19 @@ function schemeOf(colors) {
1169
1208
  'primary.contrastText': scheme.onBrand,
1170
1209
  'background.default': scheme.ground,
1171
1210
  'background.paper': scheme.paper,
1172
- 'text.primary': scheme.ink
1211
+ 'text.primary': scheme.ink,
1212
+ 'primary.light': (_scheme_brandLight = scheme.brandLight) != null ? _scheme_brandLight : null,
1213
+ divider: (_scheme_divider = scheme.divider) != null ? _scheme_divider : null,
1214
+ 'common.white': '#ffffff',
1215
+ 'common.black': '#000000'
1173
1216
  };
1174
1217
  return (_paths_value = paths[value]) != null ? _paths_value : null;
1175
1218
  }
1219
+ /** The color a theme draws an outlined button's words in, in its light scheme: its own style's, else the brand's. */ export function siteImportOutlinedColorOf(theme) {
1220
+ var _theme_button_outlined;
1221
+ const named = (_theme_button_outlined = theme.button.outlined) == null ? void 0 : _theme_button_outlined.text;
1222
+ return named === null || named === undefined ? theme.light.brand : colorIn(named, theme.light);
1223
+ }
1176
1224
  /** A CSS `text-transform` as the case a button's words are set in. */ const CASE_OF = {
1177
1225
  uppercase: 'upper',
1178
1226
  none: 'none',
@@ -1188,44 +1236,77 @@ function schemeOf(colors) {
1188
1236
  * `from` says whether the theme is the one the site stores or one computed
1189
1237
  * from its site style. `null` for a theme with no light ground.
1190
1238
  */ export function siteImportFidelityThemeOf(theme, from = 'theme') {
1191
- var _CASE_OF_transform;
1192
1239
  const light = schemeOf(pathIn(theme, 'colorSchemes', 'light'));
1193
1240
  if (!(light == null ? void 0 : light.ground)) return null;
1194
1241
  const button = pathIn(theme, 'components', 'MuiButton');
1195
1242
  const variants = pathIn(button, 'variants');
1196
- const contained = (Array.isArray(variants) ? variants : []).filter((entry)=>{
1197
- const color = pathIn(entry, 'props', 'color');
1198
- return pathIn(entry, 'props', 'variant') === 'contained' && (color === undefined || color === 'primary');
1199
- });
1200
- const styles = [
1201
- ...contained.flatMap((entry)=>[
1202
- pathIn(entry, 'style'),
1203
- pathIn(entry, 'sx')
1204
- ]),
1205
- pathIn(button, 'styleOverrides', 'containedPrimary'),
1206
- pathIn(button, 'styleOverrides', 'contained')
1207
- ].filter(isRecord);
1208
- const pick = (...keys)=>{
1209
- var _styles_flatMap_find;
1210
- return (_styles_flatMap_find = styles.flatMap((style)=>keys.map((key)=>colorIn(style[key], light))).find((color)=>!!color)) != null ? _styles_flatMap_find : null;
1243
+ /** A variant's styles, the one that wins first: the last of the variants, then its style overrides. */ const stylesOf = (variant)=>{
1244
+ const own = (Array.isArray(variants) ? variants : []).filter((entry)=>{
1245
+ const color = pathIn(entry, 'props', 'color');
1246
+ return pathIn(entry, 'props', 'variant') === variant && (color === undefined || color === 'primary');
1247
+ });
1248
+ return [
1249
+ ...[
1250
+ ...own
1251
+ ].reverse().flatMap((entry)=>[
1252
+ pathIn(entry, 'sx'),
1253
+ pathIn(entry, 'style')
1254
+ ]),
1255
+ pathIn(button, 'styleOverrides', `${variant}Primary`),
1256
+ pathIn(button, 'styleOverrides', variant)
1257
+ ].filter(isRecord);
1211
1258
  };
1259
+ const contained = stylesOf('contained');
1260
+ const dark = schemeOf(pathIn(theme, 'colorSchemes', 'dark'));
1261
+ const pickIn = (scheme, ...keys)=>{
1262
+ var _contained_flatMap_find;
1263
+ return (_contained_flatMap_find = contained.flatMap((style)=>keys.map((key)=>colorIn(style[key], scheme))).find((color)=>!!color)) != null ? _contained_flatMap_find : null;
1264
+ };
1265
+ const pick = (...keys)=>pickIn(light, ...keys);
1212
1266
  const transform = [
1213
1267
  pathIn(button, 'styleOverrides', 'root', 'textTransform'),
1214
1268
  pathIn(button, 'sx', 'root', 'textTransform'),
1215
1269
  pathIn(theme, 'typography', 'variants', 'button', 'textTransform'),
1216
1270
  pathIn(theme, 'typography', 'button', 'textTransform')
1217
1271
  ].find((value)=>typeof value === 'string');
1272
+ const caseIn = (styles)=>{
1273
+ var _CASE_OF_own;
1274
+ const own = [
1275
+ ...styles.map((style)=>style['textTransform']),
1276
+ transform
1277
+ ].find((value)=>typeof value === 'string');
1278
+ return own ? (_CASE_OF_own = CASE_OF[own]) != null ? _CASE_OF_own : null : null;
1279
+ };
1280
+ const outlined = stylesOf('outlined');
1281
+ const named = (...keys)=>{
1282
+ var _outlined_flatMap_find;
1283
+ return (_outlined_flatMap_find = outlined.flatMap((style)=>keys.map((key)=>style[key])).find((value)=>value !== undefined)) != null ? _outlined_flatMap_find : null;
1284
+ };
1218
1285
  return {
1219
1286
  from,
1220
1287
  light,
1221
- dark: schemeOf(pathIn(theme, 'colorSchemes', 'dark')),
1222
- button: {
1288
+ dark,
1289
+ button: _extends({
1223
1290
  fill: pick('backgroundColor', 'bgcolor', 'background'),
1224
- label: pick('color'),
1225
- case: transform ? (_CASE_OF_transform = CASE_OF[transform]) != null ? _CASE_OF_transform : null : null
1226
- }
1291
+ label: pick('color')
1292
+ }, dark ? {
1293
+ fillDark: pickIn(dark, 'backgroundColor', 'bgcolor', 'background'),
1294
+ labelDark: pickIn(dark, 'color')
1295
+ } : {}, {
1296
+ case: caseIn(contained),
1297
+ outlined: {
1298
+ text: named('color'),
1299
+ border: named('borderColor'),
1300
+ fill: named('backgroundColor', 'bgcolor', 'background'),
1301
+ case: caseIn(outlined)
1302
+ },
1303
+ text: {
1304
+ case: caseIn(stylesOf('text'))
1305
+ }
1306
+ })
1227
1307
  };
1228
1308
  }
1309
+ /** How near the page a fill sits and is the page's own, in OKLab: the look's own line for a fill to be drawn as one. */ const LIKE_THE_PAGE = 0.1;
1229
1310
  /** The look a built page is drawn in, read through its theme: each node's scheme, a section's ground and ink, a button's case and fill. */ let LookOf = class LookOf {
1230
1311
  /** The scheme a node is drawn in: the one the nearest node holding it sets. */ scheme(id) {
1231
1312
  if (!this.theme) return null;
@@ -1249,41 +1330,98 @@ function schemeOf(colors) {
1249
1330
  return scheme ? ((_this_built_node = this.built.node(id)) == null ? void 0 : (_this_built_node_sx = _this_built_node.sx) == null ? void 0 : _this_built_node_sx['bgcolor']) === 'primary.main' ? scheme.onBrand : scheme.ink : null;
1250
1331
  }
1251
1332
  /** A filled button's fill: its own, else the theme's for filled buttons, else its scheme's brand. */ fill(id) {
1252
- var _ref, _ref1;
1253
- var _this_built_node_sx, _this_built_node, _this_built_node_sx1, _this_built_node1, _this_theme;
1333
+ var _ref, _ref1, _ref2;
1334
+ var _this_built_node_sx, _this_built_node, _this_built_node_sx1, _this_built_node1, _this_theme, _this_theme1;
1254
1335
  const scheme = this.scheme(id);
1255
1336
  if (!scheme) return null;
1256
1337
  const own = (_ref = (_this_built_node = this.built.node(id)) == null ? void 0 : (_this_built_node_sx = _this_built_node.sx) == null ? void 0 : _this_built_node_sx['bgcolor']) != null ? _ref : (_this_built_node1 = this.built.node(id)) == null ? void 0 : (_this_built_node_sx1 = _this_built_node1.sx) == null ? void 0 : _this_built_node_sx1['backgroundColor'];
1257
- return own !== undefined ? colorIn(own, scheme) : (_ref1 = (_this_theme = this.theme) == null ? void 0 : _this_theme.button.fill) != null ? _ref1 : scheme.brand;
1338
+ if (own !== undefined) return colorIn(own, scheme);
1339
+ const button = (_this_theme = this.theme) == null ? void 0 : _this_theme.button;
1340
+ return (_ref1 = scheme === ((_this_theme1 = this.theme) == null ? void 0 : _this_theme1.dark) ? (_ref2 = button == null ? void 0 : button.fillDark) != null ? _ref2 : button == null ? void 0 : button.fill : button == null ? void 0 : button.fill) != null ? _ref1 : scheme.brand;
1258
1341
  }
1259
1342
  /** A filled button's label: its own, else the theme's for filled buttons, else the words on its scheme's brand. */ label(id) {
1260
- var _ref;
1261
- var _this_built_node_sx, _this_built_node, _this_theme;
1343
+ var _ref, _ref1;
1344
+ var _this_built_node_sx, _this_built_node, _this_theme, _this_theme1;
1262
1345
  const scheme = this.scheme(id);
1263
1346
  if (!scheme) return null;
1264
1347
  const own = (_this_built_node = this.built.node(id)) == null ? void 0 : (_this_built_node_sx = _this_built_node.sx) == null ? void 0 : _this_built_node_sx['color'];
1265
- return own !== undefined ? colorIn(own, scheme) : (_ref = (_this_theme = this.theme) == null ? void 0 : _this_theme.button.label) != null ? _ref : scheme.onBrand;
1348
+ if (own !== undefined) return colorIn(own, scheme);
1349
+ const button = (_this_theme = this.theme) == null ? void 0 : _this_theme.button;
1350
+ return (_ref = scheme === ((_this_theme1 = this.theme) == null ? void 0 : _this_theme1.dark) ? (_ref1 = button == null ? void 0 : button.labelDark) != null ? _ref1 : button == null ? void 0 : button.label : button == null ? void 0 : button.label) != null ? _ref : scheme.onBrand;
1266
1351
  }
1267
- /** Whether a button is set in the source's case: its own `textTransform`, else the theme's. `null` where either is not known. */ caseKept(id) {
1268
- var _CASE_OF_own, _ref;
1269
- var _this_facts, _this_built_node_sx, _this_built_node, _this_theme;
1270
- const wanted = (_this_facts = this.facts) == null ? void 0 : _this_facts.buttonCase;
1352
+ /**
1353
+ * Whether a button is set in its style's case in the source: its own
1354
+ * `textTransform`, else the theme's for that style. A read made before each
1355
+ * style's case was kept holds its filled buttons' alone. `null` where either
1356
+ * is not known.
1357
+ */ caseKept(id, style) {
1358
+ var _ref, _ref1, _CASE_OF_own;
1359
+ var _this_built_node_sx, _this_built_node, _this_theme, _button_outlined, _button_text;
1360
+ const facts = this.facts;
1361
+ const wanted = style === 'primary' ? facts == null ? void 0 : facts.buttonCase : style === 'secondary' ? (facts == null ? void 0 : facts.outlinedCase) === undefined ? facts == null ? void 0 : facts.buttonCase : facts.outlinedCase : (facts == null ? void 0 : facts.textCase) === undefined ? facts == null ? void 0 : facts.buttonCase : facts.textCase;
1271
1362
  if (wanted !== 'upper' && wanted !== 'none') return null;
1272
1363
  const own = id ? (_this_built_node = this.built.node(id)) == null ? void 0 : (_this_built_node_sx = _this_built_node.sx) == null ? void 0 : _this_built_node_sx['textTransform'] : undefined;
1273
- const drawn = typeof own === 'string' ? (_CASE_OF_own = CASE_OF[own]) != null ? _CASE_OF_own : 'none' : (_ref = (_this_theme = this.theme) == null ? void 0 : _this_theme.button.case) != null ? _ref : null;
1364
+ const button = (_this_theme = this.theme) == null ? void 0 : _this_theme.button;
1365
+ const themed = style === 'primary' ? button == null ? void 0 : button.case : style === 'secondary' ? (_ref = button == null ? void 0 : (_button_outlined = button.outlined) == null ? void 0 : _button_outlined.case) != null ? _ref : button == null ? void 0 : button.case : (_ref1 = button == null ? void 0 : (_button_text = button.text) == null ? void 0 : _button_text.case) != null ? _ref1 : button == null ? void 0 : button.case;
1366
+ const drawn = typeof own === 'string' ? (_CASE_OF_own = CASE_OF[own]) != null ? _CASE_OF_own : 'none' : themed != null ? themed : null;
1274
1367
  return drawn === null ? null : drawn === wanted;
1275
1368
  }
1276
- /** Whether a filled button is drawn in the source's own fill, within OKLab ΔE 0.05. `null` where either is not known. */ fillKept(id) {
1369
+ /**
1370
+ * Whether a filled button is drawn in the source's own fill, within OKLab ΔE
1371
+ * 0.05, whatever its label: a light fill under a label that cannot be read
1372
+ * on it keeps the fill and takes a label that can. A fill that sits on the
1373
+ * page like the page is no fill the look can keep: a white button on a near
1374
+ * white page reads as its border. `null` where either is not known.
1375
+ */ fillKept(id) {
1277
1376
  var _this_theme_button_fill;
1278
- var _this_facts, _this_facts1;
1377
+ var _this_facts;
1279
1378
  const wanted = hexOf((_this_facts = this.facts) == null ? void 0 : _this_facts.buttonFill);
1280
1379
  if (!wanted || !this.theme) return null;
1281
- // A fill its own label cannot be read on is deepened by the look's reading rule, Keep's polish, and is not a loss.
1282
- const label = hexOf((_this_facts1 = this.facts) == null ? void 0 : _this_facts1.buttonText);
1283
- if (label && !reads(label, wanted)) return null;
1380
+ if (siteImportOklabDelta(wanted, this.page()) < LIKE_THE_PAGE) return null;
1284
1381
  const drawn = id ? this.fill(id) : (_this_theme_button_fill = this.theme.button.fill) != null ? _this_theme_button_fill : this.theme.light.brand;
1285
1382
  return drawn ? siteImportOklabDelta(wanted, drawn) <= SITE_IMPORT_GROUND_DELTA : null;
1286
1383
  }
1384
+ /**
1385
+ * Whether an outlined button is drawn as the source draws its own: no fill
1386
+ * of its own where it sets none, and its words and border in its color,
1387
+ * within OKLab ΔE 0.1. On a dark band, which the source's color was not
1388
+ * read for, in the scheme's brand. `null` where either is not known.
1389
+ */ outlineKept(id) {
1390
+ var _ref, _ref1, _colorIn;
1391
+ var _this_facts, _this_facts1;
1392
+ const wanted = hexOf((_this_facts = this.facts) == null ? void 0 : _this_facts.buttonOutline);
1393
+ if (!wanted || !this.theme) return null;
1394
+ const scheme = (_ref = id ? this.scheme(id) : null) != null ? _ref : this.theme.light;
1395
+ const style = this.theme.button.outlined;
1396
+ const fill = (_ref1 = style == null ? void 0 : style.fill) != null ? _ref1 : null;
1397
+ const ownFill = hexOf((_this_facts1 = this.facts) == null ? void 0 : _this_facts1.outlinedFill);
1398
+ const filled = fill !== null && fill !== 'transparent' && fill !== 'none';
1399
+ if (ownFill ? !filled || siteImportOklabDelta(ownFill, (_colorIn = colorIn(fill, scheme)) != null ? _colorIn : ownFill) > SITE_IMPORT_GROUND_DELTA : filled) return false;
1400
+ const near = (color, to)=>!!color && !!to && siteImportOklabDelta(color, to) <= SITE_IMPORT_OUTLINE_DELTA;
1401
+ const named = [
1402
+ style == null ? void 0 : style.text,
1403
+ style == null ? void 0 : style.border
1404
+ ].map((color)=>color === null || color === undefined ? scheme.brand : colorIn(color, scheme));
1405
+ // A grey or a black of the source's is its words' color: the theme's words are their own ink, not a pin.
1406
+ const light = aiHexOklch(wanted).C < 0.03 ? scheme.ink : wanted;
1407
+ return named.every((color)=>{
1408
+ var _this_theme;
1409
+ return scheme === ((_this_theme = this.theme) == null ? void 0 : _this_theme.light) ? near(color, light) : near(color, scheme.brand) || near(color, scheme.brandLight) || near(color, scheme.ink);
1410
+ });
1411
+ }
1412
+ /** The source's page ground: white where it sets none. */ page() {
1413
+ var _hexOf;
1414
+ var _this_facts;
1415
+ return (_hexOf = hexOf((_this_facts = this.facts) == null ? void 0 : _this_facts.background)) != null ? _hexOf : '#ffffff';
1416
+ }
1417
+ /** The color a section is drawn on in the theme's dark scheme: its band's role there. `null` where the theme has no dark scheme. */ darkGround(id) {
1418
+ var _ref;
1419
+ var _this_theme, _this_built_node_sx, _this_built_node;
1420
+ const scheme = (_ref = (_this_theme = this.theme) == null ? void 0 : _this_theme.dark) != null ? _ref : null;
1421
+ if (!scheme) return null;
1422
+ const fill = (_this_built_node = this.built.node(id)) == null ? void 0 : (_this_built_node_sx = _this_built_node.sx) == null ? void 0 : _this_built_node_sx['bgcolor'];
1423
+ return fill === undefined || fill === null ? scheme.ground : colorIn(fill, scheme);
1424
+ }
1287
1425
  /** The inks and grounds the page shows: each section's, and each filled button's label on its fill, once each. */ pairs(sectionIds) {
1288
1426
  if (!this.theme) return [];
1289
1427
  const out = new Map();
@@ -1349,15 +1487,16 @@ function schemeOf(colors) {
1349
1487
  }).length > LONG_READ_PARAGRAPHS;
1350
1488
  /**
1351
1489
  * The sections set as the source sets them (AGL-4152): their headings, else
1352
- * their words, centered or at the start. The opening a hero draws is the
1353
- * hero's to place, and is measured by its framing and pictures; a long read
1354
- * set at the start, as text is read, is kept whatever its source centers.
1355
- */ function alignScore(source, built, placement) {
1490
+ * their words, centered or at the start; a long read set at the start, as
1491
+ * text is read, is kept whatever its source centers. Under Keep my site the
1492
+ * opening a hero draws is held to it too: a centered opening drawn at the
1493
+ * start is the opening moved. Elsewhere it is the hero's to place.
1494
+ */ function alignScore(source, built, placement, pinned) {
1356
1495
  let measured = 0;
1357
1496
  let kept = 0;
1358
1497
  for (const [index, section] of source.layout.sections.entries()){
1359
1498
  var _section_hero;
1360
- if (index === 0 && ((_section_hero = section.hero) == null ? void 0 : _section_hero.picture)) continue;
1499
+ if (index === 0 && ((_section_hero = section.hero) == null ? void 0 : _section_hero.picture) && !pinned) continue;
1361
1500
  const own = flowLines(section.nodes);
1362
1501
  const headings = own.filter((ref)=>{
1363
1502
  var _source_blocks_ref;
@@ -1389,11 +1528,23 @@ function schemeOf(colors) {
1389
1528
  }
1390
1529
  return ratioKept(measured, kept);
1391
1530
  }
1392
- /** Each section with a ground of its own on a ground of the theme within OKLab ΔE 0.05 of it. A picture or a film behind its words is its ground, and is not scored. */ function groundScore(sections, look, roots) {
1531
+ /** How far a ground may sit from its page's and still be its page's (AGL-4152), in OKLab. */ const SAME_GROUND = 0.02;
1532
+ /** Where a ground sits against its page's: on it, lighter or darker. */ function placeOn(ground, page) {
1533
+ if (siteImportOklabDelta(ground, page) <= SAME_GROUND) return 0;
1534
+ return aiHexOklch(ground).L > aiHexOklch(page).L ? 1 : -1;
1535
+ }
1536
+ /**
1537
+ * Each section with a ground of its own on a ground of the theme within OKLab
1538
+ * ΔE 0.05 of it. A picture or a film behind its words is its ground, and is
1539
+ * not scored. `ordered`, under Keep my site (AGL-4152), in its place against
1540
+ * the page too: two near whites read alike by ΔE, and swapped they draw the
1541
+ * wrong bands dark in the dark scheme.
1542
+ */ function groundScore(sections, look, roots, ordered) {
1393
1543
  if (!look.theme) return _extends({}, ratioKept(0, 0), {
1394
1544
  theme: null,
1395
1545
  worst: null
1396
1546
  });
1547
+ const themePage = look.theme.light.ground;
1397
1548
  let measured = 0;
1398
1549
  let kept = 0;
1399
1550
  let worst = null;
@@ -1407,13 +1558,53 @@ function schemeOf(colors) {
1407
1558
  if (!drawn) continue;
1408
1559
  const delta = siteImportOklabDelta(wanted, drawn);
1409
1560
  worst = Math.max(worst != null ? worst : 0, delta);
1410
- if (delta <= SITE_IMPORT_GROUND_DELTA) kept += 1;
1561
+ if (delta <= SITE_IMPORT_GROUND_DELTA && (!ordered || placeOn(wanted, look.page()) === placeOn(drawn, themePage))) kept += 1;
1411
1562
  }
1412
1563
  return _extends({}, ratioKept(measured, kept), {
1413
1564
  theme: look.theme.from,
1414
1565
  worst: worst === null ? null : round(worst)
1415
1566
  });
1416
1567
  }
1568
+ /**
1569
+ * The same sections in the theme's dark scheme (AGL-4152): on the source's own
1570
+ * dark fill within OKLab ΔE 0.05 where its stylesheets say one. Else as the
1571
+ * light page orders them, against the dark page: a section lighter than its
1572
+ * page draws lighter, one on its page's ground on the dark page, one darker
1573
+ * set apart from it, and a dark band of the source no lighter than the dark
1574
+ * page. A brand band is the brand's in either scheme, and is not scored.
1575
+ */ function darkGroundScore(sections, look, roots) {
1576
+ var _ref;
1577
+ var _look_theme_dark, _look_theme;
1578
+ const darkPage = (_ref = (_look_theme = look.theme) == null ? void 0 : (_look_theme_dark = _look_theme.dark) == null ? void 0 : _look_theme_dark.ground) != null ? _ref : null;
1579
+ if (!darkPage) return _extends({}, ratioKept(0, 0), {
1580
+ worst: null
1581
+ });
1582
+ let measured = 0;
1583
+ let kept = 0;
1584
+ let worst = null;
1585
+ for (const [index, section] of sections.entries()){
1586
+ var _section_backdrop, _section_backdrop1;
1587
+ const wanted = hexOf(section.background);
1588
+ if (!wanted || section.band === 'brand' || ((_section_backdrop = section.backdrop) == null ? void 0 : _section_backdrop.kind) === 'picture' || ((_section_backdrop1 = section.backdrop) == null ? void 0 : _section_backdrop1.kind) === 'video') continue;
1589
+ measured += 1;
1590
+ const root = roots[index];
1591
+ const drawn = root ? look.darkGround(root) : null;
1592
+ if (!drawn) continue;
1593
+ const own = hexOf(section.darkBackground);
1594
+ if (own) {
1595
+ const delta = siteImportOklabDelta(own, drawn);
1596
+ worst = Math.max(worst != null ? worst : 0, delta);
1597
+ if (delta <= SITE_IMPORT_GROUND_DELTA) kept += 1;
1598
+ continue;
1599
+ }
1600
+ const place = placeOn(drawn, darkPage);
1601
+ const wantedPlace = section.band === 'dark' ? -1 : placeOn(wanted, look.page());
1602
+ if (wantedPlace === -1 ? section.band === 'dark' ? place <= 0 : place !== 0 : place === wantedPlace) kept += 1;
1603
+ }
1604
+ return _extends({}, ratioKept(measured, kept), {
1605
+ worst: worst === null ? null : round(worst)
1606
+ });
1607
+ }
1417
1608
  /** The width a page is measured at (AGL-4152): the 1280 the 11/4 live checks set the source beside the import at. */ const VIEW_PX = 1280;
1418
1609
  /** The Container element's Max Width steps, in px, as the theme's breakpoints set them. */ const CONTAINER_PX = {
1419
1610
  xs: 444,
@@ -1511,6 +1702,10 @@ function schemeOf(colors) {
1511
1702
  const cap = container ? CONTAINER_PX[String(atView((_built_node = built.node(container)) == null ? void 0 : (_built_node_props = _built_node.props) == null ? void 0 : _built_node_props['maxWidth']))] : undefined;
1512
1703
  return Math.min(cap != null ? cap : VIEW_PX, VIEW_PX);
1513
1704
  }
1705
+ /** A section's band as Improve it reads it: by its color alone. */ const bandAsItsColor = (section)=>{
1706
+ var _ref;
1707
+ return (_ref = section == null ? void 0 : section.absoluteBand) != null ? _ref : section == null ? void 0 : section.band;
1708
+ };
1514
1709
  /** A line of the design measure: the share of what it asks the source and the build each do, `null` where neither is asked anything. */ function designLine(source, built) {
1515
1710
  if (!source[1] || !built[1]) return null;
1516
1711
  return {
@@ -1537,10 +1732,7 @@ function schemeOf(colors) {
1537
1732
  return !!id && (!!((_built_node = built.node(id)) == null ? void 0 : (_built_node_sx = _built_node.sx) == null ? void 0 : _built_node_sx['borderTop']) || !!((_built_node1 = built.node(id)) == null ? void 0 : (_built_node_sx1 = _built_node1.sx) == null ? void 0 : _built_node_sx1['borderBottom']));
1538
1733
  };
1539
1734
  const drawnBand = (id)=>siteImportFidelityBandOf(id ? built.node(id) : undefined);
1540
- const rhythm = designLine(apart(Math.max(0, sections.length - 1), (index)=>{
1541
- var _sections_index, _sections_;
1542
- return ((_sections_index = sections[index]) == null ? void 0 : _sections_index.band) !== ((_sections_ = sections[index + 1]) == null ? void 0 : _sections_.band);
1543
- }), apart(Math.max(0, drawnSections.length - 1), (index)=>drawnBand(drawnSections[index]) !== drawnBand(drawnSections[index + 1]) || ruled(drawnSections[index]) || ruled(drawnSections[index + 1])));
1735
+ const rhythm = designLine(apart(Math.max(0, sections.length - 1), (index)=>bandAsItsColor(sections[index]) !== bandAsItsColor(sections[index + 1])), apart(Math.max(0, drawnSections.length - 1), (index)=>drawnBand(drawnSections[index]) !== drawnBand(drawnSections[index + 1]) || ruled(drawnSections[index]) || ruled(drawnSections[index + 1])));
1544
1736
  // Measure: words that run no wider than `lg`, a long read no wider than `md`, each section as its Container runs it.
1545
1737
  const caps = sections.map((section)=>longRead(source, section) ? CONTAINER_PX['md'] : CONTAINER_PX['lg']);
1546
1738
  const measure = designLine(// The source's cap read as the Container step a page brought in draws it at; a section it sets none on runs the page.
@@ -1612,7 +1804,7 @@ function schemeOf(colors) {
1612
1804
  const ink = hexOf(facts == null ? void 0 : facts.text);
1613
1805
  for (const section of sections){
1614
1806
  const ground = hexOf(section.background);
1615
- if (ink && ground && (section.band === 'plain' || section.band === 'soft')) sourcePairs.push([
1807
+ if (ink && ground && (bandAsItsColor(section) === 'plain' || bandAsItsColor(section) === 'soft')) sourcePairs.push([
1616
1808
  ink,
1617
1809
  ground
1618
1810
  ]);