ssqch 0.10.1 → 0.11.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 (93) hide show
  1. package/bundled/completions/bash +61 -15
  2. package/bundled/completions/elvish +27 -12
  3. package/bundled/completions/fish +35 -23
  4. package/bundled/completions/powershell +29 -12
  5. package/bundled/completions/zsh +39 -19
  6. package/bundled/docs/agents.md +11 -0
  7. package/bundled/docs/comparing-builds.md +37 -5
  8. package/bundled/docs/configuring.md +30 -5
  9. package/bundled/docs/field-guide.md +1 -1
  10. package/bundled/docs/github-pages.md +1 -1
  11. package/bundled/docs/index.md +1 -1
  12. package/bundled/docs/known-gaps.md +1 -1
  13. package/bundled/docs/markdown.md +63 -5
  14. package/bundled/docs/multilingual.md +20 -3
  15. package/bundled/docs/nav.yml +1 -0
  16. package/bundled/docs/netlify.md +2 -2
  17. package/bundled/docs/plugins.md +4 -4
  18. package/bundled/docs/seo.md +39 -1
  19. package/bundled/docs/template-languages.md +6 -4
  20. package/bundled/docs/templates.md +3 -3
  21. package/bundled/docs/trailheads/from-eleventy.md +25 -13
  22. package/bundled/docs/trailheads/from-hugo.md +103 -0
  23. package/bundled/docs/trailheads/from-jekyll.md +49 -15
  24. package/bundled/docs/trailheads/from-mkdocs.md +54 -9
  25. package/bundled/docs/trailheads/from-zola.md +2 -2
  26. package/bundled/docs/trailheads.md +22 -5
  27. package/bundled/docs/where-values-come-from.md +1 -1
  28. package/bundled/mkdocs/404.jinja +6 -0
  29. package/bundled/ssqch.d.ts +71 -16
  30. package/lib/assets.js +10 -9
  31. package/lib/{chunk-MUYWL4ZX.js → chunk-2L3HR67O.js} +71 -18
  32. package/lib/{chunk-ERNVEZOK.js → chunk-2QTJTEBV.js} +1 -1
  33. package/lib/{chunk-CXRHH5P5.js → chunk-3HZZY3Y7.js} +5 -5
  34. package/lib/{chunk-G67W2FTJ.js → chunk-3K237XAX.js} +9 -8
  35. package/lib/{chunk-6RSZV5O2.js → chunk-443ZQLVX.js} +3 -3
  36. package/lib/{chunk-ZZBHBLDB.js → chunk-5ELAUHRL.js} +18 -16
  37. package/lib/{chunk-MDG5A4NI.js → chunk-A75EVUJX.js} +5 -5
  38. package/lib/{chunk-JFPLNHEQ.js → chunk-AIMEXBTK.js} +28 -5
  39. package/lib/{chunk-6OUT5VFK.js → chunk-B5E27PLU.js} +10 -39
  40. package/lib/{chunk-R2YGC3VE.js → chunk-CMJ7X5WW.js} +3 -2
  41. package/lib/{chunk-MDB3D3LP.js → chunk-ERAIEV3O.js} +2 -2
  42. package/lib/{chunk-DTSTCVRX.js → chunk-FCM3NYFR.js} +11 -8
  43. package/lib/{chunk-X7C6GFUM.js → chunk-GJNIQAIH.js} +8 -8
  44. package/lib/{chunk-FYRC2HBU.js → chunk-GLJQ4C76.js} +39 -18
  45. package/lib/{chunk-BXARVN5Z.js → chunk-GS5B3CBW.js} +1 -1
  46. package/lib/chunk-H5K2ZE7B.js +219 -0
  47. package/lib/{chunk-DNWA7WNO.js → chunk-HFSWUTXX.js} +1 -1
  48. package/lib/{chunk-7JGYYAKI.js → chunk-HWW5NCVJ.js} +1 -1
  49. package/lib/{chunk-BT3NVQOD.js → chunk-I3HYKEEW.js} +1 -1
  50. package/lib/{chunk-RFNLZM7W.js → chunk-IOBC665M.js} +1 -1
  51. package/lib/chunk-JC54PHIT.js +7992 -0
  52. package/lib/{chunk-3BQJY6GF.js → chunk-KCF2Z6N7.js} +1 -1
  53. package/lib/{chunk-HMVYNV6M.js → chunk-KZZS4W2V.js} +14 -12
  54. package/lib/{chunk-XR7GFL4B.js → chunk-LJOURBYT.js} +14 -12
  55. package/lib/chunk-OQGXZYZS.js +45 -0
  56. package/lib/chunk-OSBEH67S.js +6296 -0
  57. package/lib/{chunk-FYU22VDK.js → chunk-QJ5ZFTML.js} +14 -12
  58. package/lib/{chunk-LU73FTIR.js → chunk-QLUTNR37.js} +11 -10
  59. package/lib/{chunk-DUGGZ4EE.js → chunk-RBNPBTDP.js} +1 -1
  60. package/lib/{chunk-F65YUXZ7.js → chunk-RIAOXEXC.js} +10 -4
  61. package/lib/chunk-RVXGUMFI.js +21 -0
  62. package/lib/{chunk-FZGJUJAL.js → chunk-RYIWYWRQ.js} +3 -3
  63. package/lib/{chunk-LYPKL524.js → chunk-RZYAIX2R.js} +12 -10
  64. package/lib/{chunk-3NDFUMV2.js → chunk-V2FSMOFX.js} +3 -3
  65. package/lib/{chunk-26SHWRC6.js → chunk-X2GAVYV2.js} +524 -72
  66. package/lib/chunk-XS4EJSEK.js +279 -0
  67. package/lib/chunk-YCOTX2VM.js +37 -0
  68. package/lib/{chunk-P2TRR6XK.js → chunk-Z44IAMNG.js} +85 -16
  69. package/lib/chunk-Z5OP43HU.js +2945 -0
  70. package/lib/{chunk-3LODFCCH.js → chunk-ZINLHOX4.js} +2 -2
  71. package/lib/{chunk-HNG372DW.js → chunk-ZR3JYLFB.js} +814 -12347
  72. package/lib/cli.js +78 -37
  73. package/lib/elements.js +10 -9
  74. package/lib/image.js +11 -10
  75. package/lib/links.js +10 -9
  76. package/lib/minify.js +71 -12
  77. package/lib/redirects.js +10 -9
  78. package/lib/rss.js +13 -10
  79. package/lib/sass.js +13 -243
  80. package/lib/sitemap.js +18 -15
  81. package/lib/ssqch.js +6 -4
  82. package/package.json +1 -1
  83. package/types/index.d.ts +52 -11
  84. package/types/minify.d.ts +15 -3
  85. package/types/sass.d.ts +2 -0
  86. package/types/sitemap.d.ts +2 -2
  87. package/wasm/markdown.wasm +0 -0
  88. package/wasm/minify.wasm +0 -0
  89. package/wasm/sass.wasm +0 -0
  90. package/lib/chunk-II7ZRIAC.js +0 -1285
  91. package/lib/chunk-IOXCGMSF.js +0 -1539
  92. /package/lib/{chunk-JFPLNHEQ.js.LEGAL.txt → chunk-AIMEXBTK.js.LEGAL.txt} +0 -0
  93. /package/lib/{chunk-HNG372DW.js.LEGAL.txt → chunk-ZR3JYLFB.js.LEGAL.txt} +0 -0
@@ -3,15 +3,11 @@ const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  buildFiles,
5
5
  urlOf
6
- } from "./chunk-FZGJUJAL.js";
7
- import "./chunk-ERNVEZOK.js";
6
+ } from "./chunk-RYIWYWRQ.js";
8
7
  import {
9
8
  bytes,
10
9
  count
11
- } from "./chunk-MDB3D3LP.js";
12
- import "./chunk-BXARVN5Z.js";
13
- import "./chunk-FVZ5JBRI.js";
14
- import "./chunk-UU43WIZG.js";
10
+ } from "./chunk-ERAIEV3O.js";
15
11
  import {
16
12
  charCount,
17
13
  firstChars,
@@ -21,8 +17,7 @@ import {
21
17
  BuildError,
22
18
  bail,
23
19
  compareText
24
- } from "./chunk-JFPLNHEQ.js";
25
- import "./chunk-I3PS26CI.js";
20
+ } from "./chunk-AIMEXBTK.js";
26
21
 
27
22
  // src/diff.ts
28
23
  import fs from "node:fs";
@@ -740,6 +735,9 @@ var GENERATOR = new RegExp(String.raw`SiteSquatch v\p{Nd}+\.\p{Nd}+\.\p{Nd}+[\p{
740
735
  var ID_ATTR = new RegExp(`\\p{White_Space}id=(?:"([^"]*)"|'([^']*)'|([^\\p{White_Space}>]+))`, "u");
741
736
  var MONTH = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
742
737
  var DATE = new RegExp([
738
+ // Mon Mar 08 2021 00:00:00 GMT+0000 (Coordinated Universal Time): JavaScript's Date.toString(),
739
+ // as Eleventy's Nunjucks printed a date (a11yproject.com's JSON-LD, against ssqch's ISO 8601).
740
+ String.raw`${START}(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\p{White_Space}+${MONTH}\p{White_Space}+\p{Nd}{2}\p{White_Space}+\p{Nd}{4}\p{White_Space}+\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}\p{White_Space}+GMT[+\-]\p{Nd}{4}(?:\p{White_Space}+\([^)]*\))?`,
743
741
  // 2026-03-14T09:05:00Z
744
742
  String.raw`\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}(?:[T ]\p{Nd}{2}:\p{Nd}{2}(?::\p{Nd}{2}(?:\.\p{Nd}+)?)?(?:Z|[+\-]\p{Nd}{2}:?\p{Nd}{2})?)?`,
745
743
  // March 14, 2026
@@ -751,6 +749,13 @@ var DATE = new RegExp([
751
749
  // 2026
752
750
  String.raw`${START}(?:19|20)\p{Nd}{2}${END}`
753
751
  ].join("|"), "gu");
752
+ var IMAGE_ID = new RegExp(`(?<=[/"'=,\\p{White_Space}]|^)([A-Za-z0-9_-]{10})(?=-\\p{Nd}{1,5}\\.(?:avif|webp|jpe?g|png|gif|svg)(?![A-Za-z0-9]))`, "gu");
753
+ var isImageId = (id) => !/^(?:[a-z]+|[0-9]+)$/.test(id);
754
+ var isHashedImage = (file) => [...file.slice(file.lastIndexOf("/") + 1).matchAll(IMAGE_ID)].some((m) => m.index === 0 && isImageId(m[1]));
755
+ function withoutImageIds(text) {
756
+ if (!text.includes("-")) return text;
757
+ return text.replace(IMAGE_ID, (id) => isImageId(id) ? "{id}" : id);
758
+ }
754
759
  function withoutFingerprints(text) {
755
760
  if (!text.includes(".")) return text;
756
761
  return text.replace(FINGERPRINT, (whole, hash, ext) => /^(19|20)\d{6}$/.test(hash) ? whole : `.${ext}`);
@@ -772,10 +777,11 @@ function isInline(tag) {
772
777
  return INLINE.has(nameAt(tag, i));
773
778
  }
774
779
  function normalize(text, options) {
775
- if (options.exact) return text;
776
- let out = text.replaceAll("\r\n", "\n");
780
+ let out = options.exact ? text : text.replaceAll("\r\n", "\n");
777
781
  for (const re of options.ignore) out = out.replace(re, "");
782
+ if (options.exact) return out;
778
783
  out = withoutFingerprints(out);
784
+ out = withoutImageIds(out);
779
785
  if (out.includes("integrity=")) out = out.replace(INTEGRITY, "");
780
786
  if (out.includes("SiteSquatch v")) out = out.replace(GENERATOR, "SiteSquatch");
781
787
  return out;
@@ -804,6 +810,22 @@ function keyed(paths, exact) {
804
810
  return new Map(pairs.sort((a, b) => compareText(a[0], b[0])));
805
811
  }
806
812
  var isPage = (file) => file.endsWith(".html") || file.endsWith(".htm");
813
+ var isXml = (file) => /\.(?:xml|rss|atom|xsl)$/.test(file);
814
+ var CDATA = /<!\[CDATA\[([\s\S]*?)\]\]>/g;
815
+ var ESCAPED_TEXT = /(?<=>)([^<]*&lt;[^<]*)(?=<)/g;
816
+ function xmlWithMarkup(text) {
817
+ let out = text.includes("<![CDATA[") ? text.replace(CDATA, (_, inside) => inside) : text;
818
+ if (out.includes("&lt;")) out = out.replace(ESCAPED_TEXT, (escaped) => decodeEntitiesOnce(escaped));
819
+ return out;
820
+ }
821
+ function decodeEntitiesOnce(s) {
822
+ return s.replace(/&(lt|gt|quot|apos|amp|#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6});/g, (whole, name) => {
823
+ const named2 = { lt: "<", gt: ">", quot: '"', apos: "'", amp: "&" };
824
+ if (Object.hasOwn(named2, name)) return named2[name];
825
+ const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
826
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : whole;
827
+ });
828
+ }
807
829
  function isSpace(c) {
808
830
  return c === 32 || c >= 9 && c <= 13 || c >= 128 && (c === 133 || c === 160 || c === 5760 || c >= 8192 && c <= 8202 || c === 8232 || c === 8233 || c === 8239 || c === 8287 || c === 12288);
809
831
  }
@@ -856,19 +878,110 @@ function tagEnd(s, from) {
856
878
  }
857
879
  return void 0;
858
880
  }
881
+ var BOOLEAN = /* @__PURE__ */ new Set(["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "inert", "ismap", "itemscope", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected"]);
882
+ var SPACED = /* @__PURE__ */ new Set(["class", "rel", "sizes", "srcset"]);
883
+ var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
884
+ var ENTITY_OR_AMP = /&(?:(#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6}|[A-Za-z][A-Za-z0-9]*);)?/g;
885
+ var NAMED_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
886
+ function entityChar(name) {
887
+ if (name[0] !== "#") return Object.hasOwn(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : void 0;
888
+ const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
889
+ if (code === 160) return void 0;
890
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : void 0;
891
+ }
892
+ function canonicalText(text) {
893
+ if (!text.includes("&") && !text.includes(">")) return text;
894
+ return text.replace(ENTITY_OR_AMP, (whole, name) => {
895
+ if (name === void 0) return "&amp;";
896
+ if (name === "#160" || /^#[xX]0*[aA]0$/.test(name)) return "&nbsp;";
897
+ const c = entityChar(name);
898
+ return c === void 0 ? whole : c === "&" ? "&amp;" : c === "<" ? "&lt;" : c;
899
+ }).replaceAll("&gt;", ">");
900
+ }
901
+ function attributeValue(raw) {
902
+ if (!raw.includes("&")) return raw;
903
+ return raw.replace(ENTITY_OR_AMP, (whole, name) => name === void 0 ? whole : name === "nbsp" ? "\xA0" : entityChar(name) ?? whole);
904
+ }
905
+ var NO_ATTRIBUTES = /^<\/?[a-z][a-z0-9-]*>$/;
906
+ function canonicalTag(tag, foreign, xml = false) {
907
+ if (NO_ATTRIBUTES.test(tag)) return [tag, false];
908
+ const lower = xml ? (t) => t : asciiLower;
909
+ if (tag.startsWith("<!--")) return [tag, false];
910
+ if (/^<!doctype/i.test(tag)) return [asciiLower(tag), false];
911
+ const closing = tag.charCodeAt(1) === 47;
912
+ let i = closing ? 2 : 1;
913
+ const name = nameAt(tag, i);
914
+ if (name === "") return [tag, false];
915
+ i += name.length;
916
+ while (i < tag.length && /[A-Za-z0-9_:.-]/.test(tag[i])) i++;
917
+ const element = lower(tag.slice(closing ? 2 : 1, i));
918
+ const attrs = /* @__PURE__ */ new Map();
919
+ let selfClosing = false;
920
+ const end = tag.length - 1;
921
+ while (i < end) {
922
+ const c = tag.charCodeAt(i);
923
+ if (isSpace(c)) {
924
+ i++;
925
+ continue;
926
+ }
927
+ if (c === 47) {
928
+ let j2 = i + 1;
929
+ while (j2 < end && isSpace(tag.charCodeAt(j2))) j2++;
930
+ if (j2 === end) selfClosing = true;
931
+ i++;
932
+ continue;
933
+ }
934
+ let j = i;
935
+ while (j < end && !isSpace(tag.charCodeAt(j)) && tag[j] !== "=" && tag[j] !== ">" && !(tag[j] === "/" && j > i)) j++;
936
+ if (j === i) j++;
937
+ const attr2 = lower(tag.slice(i, j));
938
+ if (/["'<]/.test(attr2)) return [tag, false];
939
+ i = j;
940
+ while (i < end && isSpace(tag.charCodeAt(i))) i++;
941
+ let value;
942
+ if (tag[i] === "=") {
943
+ i++;
944
+ while (i < end && isSpace(tag.charCodeAt(i))) i++;
945
+ const q = tag[i];
946
+ if (q === '"' || q === "'") {
947
+ const close = tag.indexOf(q, i + 1);
948
+ if (close === -1) return [tag, false];
949
+ value = attributeValue(tag.slice(i + 1, close));
950
+ i = close + 1;
951
+ } else {
952
+ let k = i;
953
+ while (k < end && !isSpace(tag.charCodeAt(k))) k++;
954
+ value = attributeValue(tag.slice(i, k));
955
+ i = k;
956
+ }
957
+ }
958
+ if (attrs.has(attr2)) continue;
959
+ if (value !== void 0 && BOOLEAN.has(attr2) && !foreign && (value === "" || asciiLower(value) === attr2)) value = void 0;
960
+ if (value !== void 0 && SPACED.has(attr2)) value = collapse(value).replace(/ ?, ?/g, ", ");
961
+ attrs.set(attr2, value);
962
+ }
963
+ if (closing) return [`</${element}>`, false];
964
+ let out = `<${element}`;
965
+ for (const attr2 of [...attrs.keys()].sort()) {
966
+ const value = attrs.get(attr2);
967
+ out += value === void 0 ? ` ${attr2}` : ` ${attr2}="${value.replace(/&/g, "&amp;").replace(/"/g, "&quot;")}"`;
968
+ }
969
+ return [`${out}>`, selfClosing && (xml || foreign || element === "svg" || element === "math") && !VOID.has(element)];
970
+ }
859
971
  var RAW2 = /* @__PURE__ */ new Set(["script", "style", "pre", "textarea"]);
860
972
  var CLOSING = new Map([...RAW2].map((name) => [name, new RegExp(`</${name}`, "gi")]));
861
973
  var startsTag = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 47 || c === 33 || c === 63;
862
- function tokens(html) {
974
+ function tokens(html, xml = false) {
863
975
  const out = [];
864
976
  let i = 0;
865
977
  let textStart = 0;
978
+ let foreign = 0;
866
979
  const pushText = (s, nextTag) => {
867
980
  if (s === "") return;
868
981
  const last = out[out.length - 1];
869
982
  const before = isSpace(s.codePointAt(0)) && last !== void 0 && last.tag && isInline(last.text);
870
983
  const after = isSpace(s.charCodeAt(s.length - 1)) && nextTag !== void 0 && isInline(nextTag);
871
- let t = collapse(s);
984
+ let t = canonicalText(collapse(s));
872
985
  if (t === "") {
873
986
  if (before && after) out.push({ tag: false, text: " " });
874
987
  return;
@@ -891,10 +1004,15 @@ function tokens(html) {
891
1004
  }
892
1005
  const tag = html.slice(i, i + end);
893
1006
  pushText(html.slice(textStart, i), tag);
894
- out.push({ tag: true, text: collapseTag(tag) });
1007
+ const [text, closes] = canonicalTag(collapseTag(tag), foreign > 0, xml);
1008
+ out.push({ tag: true, text });
1009
+ const name = xml ? "" : nameAt(tag, 1);
1010
+ if (name === "svg" || name === "math") {
1011
+ if (!closes) foreign++;
1012
+ } else if (tag.charCodeAt(1) === 47 && (nameAt(tag, 2) === "svg" || nameAt(tag, 2) === "math")) foreign = Math.max(0, foreign - 1);
1013
+ if (closes) out.push({ tag: true, text: `</${text.slice(1, text.search(/[ >]/))}>` });
895
1014
  i += end;
896
1015
  textStart = i;
897
- const name = nameAt(tag, 1);
898
1016
  if (RAW2.has(name) && !tag.endsWith("/>")) {
899
1017
  const closing = CLOSING.get(name);
900
1018
  closing.lastIndex = i;
@@ -902,7 +1020,13 @@ function tokens(html) {
902
1020
  const len = (found ? found.index : html.length) - i;
903
1021
  let raw = html.slice(i, i + len);
904
1022
  if (name === "pre" || name === "textarea") raw = raw.startsWith("\r\n") ? raw.slice(2) : raw.startsWith("\n") ? raw.slice(1) : raw;
905
- if (raw !== "") for (const line of raw.split("\n")) out.push({ tag: false, text: line.endsWith("\r") ? line.slice(0, -1) : line });
1023
+ const entities = name === "pre" || name === "textarea";
1024
+ if (raw !== "") {
1025
+ for (const line of raw.split("\n")) {
1026
+ const text2 = line.endsWith("\r") ? line.slice(0, -1) : line;
1027
+ out.push({ tag: false, text: entities ? canonicalText(text2) : text2 });
1028
+ }
1029
+ }
906
1030
  i += len;
907
1031
  textStart = i;
908
1032
  }
@@ -926,6 +1050,62 @@ function title(list) {
926
1050
  const next = list[i + 1];
927
1051
  return next && !next.tag ? next.text : void 0;
928
1052
  }
1053
+ function headingAbove(list) {
1054
+ const found = /* @__PURE__ */ new Map();
1055
+ return (index) => {
1056
+ for (let i = Math.min(index, list.length) - 1; i >= 0; i--) {
1057
+ const t = list[i];
1058
+ if (!t.tag || !/^<h[1-6][\s>]/i.test(t.text)) continue;
1059
+ if (found.has(i)) return found.get(i);
1060
+ const id = attr(t.text, "id");
1061
+ let text = "";
1062
+ for (let j = i + 1; j < list.length && !/^<\/h[1-6]>/i.test(list[j].text); j++) if (!list[j].tag) text += list[j].text;
1063
+ const at = id ? `#${id}` : text.trim() ? `"${clip(text.trim())}"` : void 0;
1064
+ found.set(i, at);
1065
+ return at;
1066
+ }
1067
+ return void 0;
1068
+ };
1069
+ }
1070
+ function attr(tag, name) {
1071
+ const m = new RegExp(`\\s${name}="([^"]*)"`, "i").exec(tag);
1072
+ return m?.[1];
1073
+ }
1074
+ function wayfinding(list) {
1075
+ const out = {};
1076
+ for (const t of list) {
1077
+ if (!t.tag) continue;
1078
+ if (out.canonical === void 0 && /^<link\s/i.test(t.text) && /\srel="canonical"/i.test(t.text)) out.canonical = attr(t.text, "href");
1079
+ if (out.redirect === void 0 && /^<meta\s/i.test(t.text) && /\shttp-equiv="refresh"/i.test(t.text)) out.redirect = /url=\s*['"]?([^'"\s>]+)/i.exec(attr(t.text, "content") ?? "")?.[1];
1080
+ }
1081
+ return out;
1082
+ }
1083
+ function feedEntries(list) {
1084
+ const out = [];
1085
+ let inEntry = false;
1086
+ let id;
1087
+ let link;
1088
+ for (let i = 0; i < list.length; i++) {
1089
+ const t = list[i];
1090
+ if (!t.tag) continue;
1091
+ if (/^<(item|entry)[\s>]/i.test(t.text)) {
1092
+ inEntry = true;
1093
+ id = link = void 0;
1094
+ continue;
1095
+ }
1096
+ if (/^<\/(item|entry)>/i.test(t.text)) {
1097
+ if (inEntry) out.push(id ?? link ?? `(entry ${out.length + 1})`);
1098
+ inEntry = false;
1099
+ continue;
1100
+ }
1101
+ if (!inEntry) continue;
1102
+ const next = list[i + 1];
1103
+ const text = next && !next.tag ? next.text.trim() : void 0;
1104
+ if (/^<(guid|id)[\s>]/i.test(t.text) && text) id ??= text;
1105
+ else if (/^<link[\s>]/i.test(t.text)) link ??= attr(t.text, "href") ?? text;
1106
+ }
1107
+ return out;
1108
+ }
929
1109
  function lines(text) {
930
1110
  if (text === "") return [];
931
1111
  const out = text.split("\n");
@@ -935,7 +1115,7 @@ function lines(text) {
935
1115
  }
936
1116
  return out;
937
1117
  }
938
- function hunks(before, after, kind, show) {
1118
+ function hunks(before, after, kind, show, where) {
939
1119
  const numbers = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
940
1120
  let count2 = 0;
941
1121
  const number = (item) => {
@@ -957,7 +1137,10 @@ function hunks(before, after, kind, show) {
957
1137
  if (op.tag === "equal") continue;
958
1138
  for (let i = op.oldIndex; i < op.oldIndex + op.oldLen; i++) changed.push([true, i]);
959
1139
  for (let i = op.newIndex; i < op.newIndex + op.newLen; i++) changed.push([false, i]);
960
- out.push({ removed: before.slice(op.oldIndex, op.oldIndex + op.oldLen).map(show), added: after.slice(op.newIndex, op.newIndex + op.newLen).map(show) });
1140
+ const hunk = { removed: before.slice(op.oldIndex, op.oldIndex + op.oldLen).map(show), added: after.slice(op.newIndex, op.newIndex + op.newLen).map(show) };
1141
+ const at = where?.(op.oldIndex);
1142
+ if (at !== void 0) hunk.at = at;
1143
+ out.push(hunk);
961
1144
  }
962
1145
  return [out, changed];
963
1146
  }
@@ -971,7 +1154,7 @@ function firstLines(list, limit) {
971
1154
  left -= removed.length;
972
1155
  const added = h.added.slice(0, left);
973
1156
  left -= added.length;
974
- out.push({ removed, added });
1157
+ out.push(h.at === void 0 ? { removed, added } : { removed, added, at: h.at });
975
1158
  }
976
1159
  return out;
977
1160
  }
@@ -996,7 +1179,10 @@ function comparePair(a, b, pair, options) {
996
1179
  changedLines: 0,
997
1180
  onlyDates: void 0,
998
1181
  sizeBefore: a.length,
999
- sizeAfter: b.length
1182
+ sizeAfter: b.length,
1183
+ groups: [],
1184
+ ownHunks: [],
1185
+ ownLines: 0
1000
1186
  };
1001
1187
  const textA = decode(a), textB = decode(b);
1002
1188
  if (textA === void 0 || textB === void 0) return diff2;
@@ -1006,29 +1192,80 @@ function comparePair(a, b, pair, options) {
1006
1192
  if (isPage(pair.key) && !options.exact) {
1007
1193
  diff2.kind = "page";
1008
1194
  const ta = tokens(before), tb = tokens(after);
1009
- const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text);
1195
+ const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text, headingAbove(ta));
1010
1196
  if (!list.length) return void 0;
1011
1197
  const isTag = ([first, i]) => (first ? ta[i] : tb[i]).tag;
1012
1198
  if (changed.some((c) => !isTag(c))) diff2.what.push("text");
1013
1199
  if (changed.some(isTag)) diff2.what.push("markup");
1014
1200
  const [old, now] = [title(ta), title(tb)];
1015
1201
  if (old !== void 0 && now !== void 0 && old !== now) diff2.notes.push(`title: ${quoted(old)} -> ${quoted(now)}`);
1016
- const kept = new Set(ids(tb));
1017
- const gone = ids(ta).filter((id) => !kept.has(id)).map((id) => `#${id}`);
1202
+ const kept2 = new Set(ids(tb));
1203
+ const gone = ids(ta).filter((id) => !kept2.has(id)).map((id) => `#${id}`);
1018
1204
  if (gone.length) diff2.notes.push(`ids removed (links to them break): ${gone.slice(0, 8).join(", ")}${gone.length > 8 ? ` and ${gone.length - 8} more` : ""}`);
1205
+ const [wa, wb] = [wayfinding(ta), wayfinding(tb)];
1206
+ if (wa.canonical !== wb.canonical) diff2.notes.push(`canonical link: ${wa.canonical ?? "none"} -> ${wb.canonical ?? "none"}`);
1207
+ if (wa.redirect !== wb.redirect) diff2.notes.push(`redirects to: ${wa.redirect ?? "nowhere"} -> ${wb.redirect ?? "nowhere"}`);
1019
1208
  diff2.onlyDates = onlyDates(list);
1020
1209
  if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1021
1210
  found = list;
1211
+ } else if (isXml(pair.key) && !options.exact) {
1212
+ diff2.kind = "text";
1213
+ const ta = tokens(xmlWithMarkup(before), true), tb = tokens(xmlWithMarkup(after), true);
1214
+ found = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text)[0];
1215
+ if (!found.length) return void 0;
1216
+ const [ea, eb] = [feedEntries(ta), feedEntries(tb)];
1217
+ if (ea.length || eb.length) {
1218
+ const kept2 = new Set(eb), had = new Set(ea);
1219
+ const gone = ea.filter((e) => !kept2.has(e)), came = eb.filter((e) => !had.has(e));
1220
+ const some = (list) => `${list.slice(0, 3).join(", ")}${list.length > 3 ? ` and ${list.length - 3} more` : ""}`;
1221
+ if (gone.length) diff2.notes.push(`feed entries removed (readers see them go): ${some(gone)}`);
1222
+ if (came.length) diff2.notes.push(`feed entries added (readers see them as new): ${some(came)}`);
1223
+ }
1224
+ diff2.onlyDates = onlyDates(found);
1225
+ if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1022
1226
  } else {
1023
1227
  diff2.kind = isPage(pair.key) ? "page" : "text";
1024
1228
  const la = lines(before), lb = lines(after);
1025
1229
  found = hunks(la, lb, () => 0, (l) => l)[0];
1026
1230
  if (!found.length) found = [{ removed: [`(${Buffer.byteLength(before)} bytes)`], added: [`(${Buffer.byteLength(after)} bytes)`] }];
1231
+ else if (!isPage(pair.key)) {
1232
+ diff2.onlyDates = onlyDates(found);
1233
+ if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1234
+ }
1027
1235
  }
1236
+ if (!diff2.onlyDates && sameLines(found)) diff2.notes.push("the same lines, in another order");
1237
+ diff2.allHunks = found;
1028
1238
  diff2.changedLines = found.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1029
1239
  diff2.hunks = firstLines(found, options.lines);
1030
1240
  return diff2;
1031
1241
  }
1242
+ async function linkTarget(file) {
1243
+ try {
1244
+ return (await fs.promises.readlink(file)).replaceAll("\\", "/");
1245
+ } catch {
1246
+ return void 0;
1247
+ }
1248
+ }
1249
+ function compareLinks(a, b, pair) {
1250
+ if (a === b) return void 0;
1251
+ const side = (target) => target === void 0 ? "(a file, not a link)" : `-> ${target}`;
1252
+ return {
1253
+ path: pair.key,
1254
+ url: urlOf(pair.key),
1255
+ renamed: pair.before !== pair.after ? [pair.before, pair.after] : void 0,
1256
+ kind: "text",
1257
+ what: [],
1258
+ notes: [a !== void 0 && b !== void 0 ? "a link, to somewhere else" : "a link in one build and a file in the other"],
1259
+ hunks: [{ removed: [side(a)], added: [side(b)] }],
1260
+ changedLines: 2,
1261
+ onlyDates: void 0,
1262
+ sizeBefore: 0,
1263
+ sizeAfter: 0,
1264
+ groups: [],
1265
+ ownHunks: [],
1266
+ ownLines: 0
1267
+ };
1268
+ }
1032
1269
  var READS_AT_ONCE = 32;
1033
1270
  var Reader = class {
1034
1271
  buffer = Buffer.allocUnsafe(64 * 1024);
@@ -1055,15 +1292,25 @@ var Reader = class {
1055
1292
  });
1056
1293
  }
1057
1294
  };
1295
+ function kept(paths, options) {
1296
+ const { only, exclude } = options;
1297
+ return paths.filter((p) => (!only || only.some((re) => re.test(p))) && !(exclude ?? []).some((re) => re.test(p)));
1298
+ }
1299
+ function checkOnly(lists, options) {
1300
+ if (!options.only || lists.some((list) => list.some((p) => options.only.some((re) => re.test(p))))) return;
1301
+ const given = (options.onlyGiven ?? []).map((g) => `"${g}"`).join(", ");
1302
+ bail(`--only ${given || "(its globs)"} matched no file in ${lists.length === 2 ? "either build" : "any of the builds"}: it's a glob of paths in the build folder, like \`posts/pine/index.html\`, \`posts/**\` or \`/posts/pine/\` (a folder: everything in it)`);
1303
+ }
1058
1304
  async function compare(before, after, options) {
1059
- const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
1305
+ const keep = (paths) => kept(paths, options);
1060
1306
  const [walkA, walkB] = await Promise.allSettled([files(before), files(after)]);
1061
1307
  if (walkA.status === "rejected") throw walkA.reason;
1062
1308
  if (walkB.status === "rejected") throw walkB.reason;
1063
1309
  const [listA, listB] = [walkA.value, walkB.value];
1310
+ checkOnly([listA, listB], options);
1064
1311
  const a = keyed(keep(listA), options.exact);
1065
1312
  const b = keyed(keep(listB), options.exact);
1066
- const report = { before, after, exact: options.exact, added: [], removed: [], changed: [], unchangedPages: 0, unchangedFiles: 0 };
1313
+ const report = { before, after, exact: options.exact, added: [], removed: [], changed: [], groups: [], unchangedPages: 0, unchangedFiles: 0 };
1067
1314
  for (const key of a.keys()) if (!b.has(key)) report.removed.push(urlOf(key));
1068
1315
  for (const key of b.keys()) if (!a.has(key)) report.added.push(urlOf(key));
1069
1316
  const pairs = [];
@@ -1078,6 +1325,11 @@ async function compare(before, after, options) {
1078
1325
  while (next < pairs.length) {
1079
1326
  const i = next++;
1080
1327
  const pair = pairs[i];
1328
+ const [fromLink, toLink] = await Promise.all([linkTarget(path.join(before, pair.before)), linkTarget(path.join(after, pair.after))]);
1329
+ if (fromLink !== void 0 || toLink !== void 0) {
1330
+ results[i] = compareLinks(fromLink, toLink, pair);
1331
+ continue;
1332
+ }
1081
1333
  const [one, two] = await Promise.all([x.read(path.join(before, pair.before)), y.read(path.join(after, pair.after))]);
1082
1334
  results[i] = comparePair(one, two, pair, options);
1083
1335
  }
@@ -1089,8 +1341,136 @@ async function compare(before, after, options) {
1089
1341
  else if (isPage(pair.key)) report.unchangedPages += 1;
1090
1342
  else report.unchangedFiles += 1;
1091
1343
  });
1344
+ report.groups = options.ungrouped ? [] : groupChanges(report.changed);
1345
+ for (const file of report.changed) {
1346
+ if (!report.groups.length) file.ownHunks = file.allHunks ?? file.hunks;
1347
+ file.ownLines = file.ownHunks.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1348
+ file.ownHunks = firstLines(file.ownHunks, options.lines);
1349
+ delete file.allHunks;
1350
+ }
1092
1351
  return report;
1093
1352
  }
1353
+ var hunkKey = (h) => JSON.stringify([h.removed, h.added]);
1354
+ var lineShape = (line) => line.startsWith("<") ? line.replace(/="[^"]*"/g, '="\u2026"') : line;
1355
+ var shapeKeyOf = (h) => JSON.stringify([h.removed.map(lineShape), h.added.map(lineShape)]);
1356
+ function changedDates(h) {
1357
+ if (!onlyDates([h])) return void 0;
1358
+ const pairs = /* @__PURE__ */ new Set();
1359
+ h.removed.forEach((line, i) => {
1360
+ const old = [...line.matchAll(DATE)].map((m) => m[0]);
1361
+ const now = [...h.added[i].matchAll(DATE)].map((m) => m[0]);
1362
+ old.forEach((d, k) => {
1363
+ if (d !== now[k]) pairs.add(`${d}>${now[k]}`);
1364
+ });
1365
+ });
1366
+ return [...pairs].sort();
1367
+ }
1368
+ var shapeKey = (h) => {
1369
+ const dates = changedDates(h);
1370
+ return dates ? `dates:${JSON.stringify([...new Set(dates.map((pair) => pair.split(">")[0].replace(new RegExp("\\p{Nd}", "gu"), "0").replace(new RegExp("\\p{L}", "gu"), "a")))].sort())}` : shapeKeyOf(h);
1371
+ };
1372
+ var tagLine = (line) => line.startsWith("<") ? (/^<\/?[^\s>]+/.exec(line)?.[0] ?? line) + ">" : line;
1373
+ var once = (lines2) => lines2.filter((line, i) => i === 0 || line !== lines2[i - 1]);
1374
+ var tagKey = (h) => JSON.stringify([once(h.removed.map(tagLine)), once(h.added.map(tagLine))]);
1375
+ function kindOf(h) {
1376
+ if (onlyDates([h])) return "dates";
1377
+ if (sameLines([h])) return "order";
1378
+ const lines2 = [...h.removed, ...h.added];
1379
+ const tags = lines2.filter((l) => l.startsWith("<")).length;
1380
+ return tags === lines2.length ? "markup" : tags === 0 ? "text" : "markup and text";
1381
+ }
1382
+ function groupChanges(changed) {
1383
+ const found = /* @__PURE__ */ new Map();
1384
+ changed.forEach((f, i) => {
1385
+ for (const h of f.allHunks ?? f.hunks) {
1386
+ if (!h.removed.length && !h.added.length) continue;
1387
+ const k = shapeKey(h);
1388
+ const entry = found.get(k);
1389
+ if (!entry) found.set(k, { files: /* @__PURE__ */ new Set([i]), hunk: h, first: i, same: true });
1390
+ else {
1391
+ entry.files.add(i);
1392
+ if (entry.same && hunkKey(h) !== hunkKey(entry.hunk)) entry.same = false;
1393
+ }
1394
+ }
1395
+ });
1396
+ const drafts = [];
1397
+ const byShape = /* @__PURE__ */ new Map();
1398
+ for (const [k, e] of found) {
1399
+ if (e.files.size < 2) continue;
1400
+ byShape.set(k, drafts.length);
1401
+ drafts.push({ files: new Set(e.files), hunk: e.hunk, first: e.first, match: e.same ? "lines" : k.startsWith("dates:") ? "dates" : "values" });
1402
+ }
1403
+ const byTags = /* @__PURE__ */ new Map();
1404
+ const merged = /* @__PURE__ */ new Map();
1405
+ const hasTags = (h) => h.removed.length + h.added.length >= 3 && h.removed.concat(h.added).some((l) => l.startsWith("<"));
1406
+ [...drafts.keys()].sort((a, b) => drafts[b].files.size - drafts[a].files.size || drafts[a].first - drafts[b].first).forEach((i) => {
1407
+ const k = tagKey(drafts[i].hunk);
1408
+ const into = hasTags(drafts[i].hunk) ? byTags.get(k) : void 0;
1409
+ if (into === void 0) {
1410
+ byTags.set(k, i);
1411
+ return;
1412
+ }
1413
+ for (const f of drafts[i].files) drafts[into].files.add(f);
1414
+ drafts[into].match = "tags";
1415
+ merged.set(i, into);
1416
+ });
1417
+ for (const [shape, i] of byShape) if (merged.has(i)) byShape.set(shape, merged.get(i));
1418
+ const placed = /* @__PURE__ */ new Map();
1419
+ const loose = /* @__PURE__ */ new Map();
1420
+ changed.forEach((f, i) => {
1421
+ const at = /* @__PURE__ */ new Map();
1422
+ placed.set(f, at);
1423
+ for (const h of f.allHunks ?? f.hunks) {
1424
+ if (!h.removed.length && !h.added.length) continue;
1425
+ const shaped = byShape.get(shapeKey(h));
1426
+ if (shaped !== void 0) {
1427
+ at.set(h, shaped);
1428
+ continue;
1429
+ }
1430
+ const tags = byTags.get(tagKey(h));
1431
+ if (tags !== void 0 && hasTags(h)) {
1432
+ drafts[tags].files.add(i);
1433
+ drafts[tags].match = "tags";
1434
+ at.set(h, tags);
1435
+ continue;
1436
+ }
1437
+ const k = tagKey(h);
1438
+ const entry = loose.get(k) ?? { files: /* @__PURE__ */ new Set(), hunk: h, first: i, hunks: [] };
1439
+ entry.files.add(i);
1440
+ entry.hunks.push([i, h]);
1441
+ loose.set(k, entry);
1442
+ }
1443
+ });
1444
+ for (const e of loose.values()) {
1445
+ if (e.files.size < 2 || !hasTags(e.hunk)) continue;
1446
+ const index = drafts.length;
1447
+ drafts.push({ files: e.files, hunk: e.hunk, first: e.first, match: "tags" });
1448
+ for (const [i, h] of e.hunks) placed.get(changed[i]).set(h, index);
1449
+ }
1450
+ const order = drafts.map((_, i) => i).filter((i) => !merged.has(i)).sort((a, b) => drafts[b].files.size - drafts[a].files.size || drafts[a].first - drafts[b].first);
1451
+ const number = new Map(order.map((old, i) => [old, i]));
1452
+ const groups = order.map((i) => {
1453
+ const d = drafts[i];
1454
+ return { urls: [...d.files].sort((a, b) => a - b).map((f) => changed[f].url), same: d.match === "lines", match: d.match, kind: kindOf(d.hunk), hunk: d.hunk };
1455
+ });
1456
+ for (const f of changed) {
1457
+ const at = placed.get(f);
1458
+ const all = f.allHunks ?? f.hunks;
1459
+ f.groups = [...new Set(all.map((h) => at.get(h)).filter((g) => g !== void 0).map((g) => number.get(g)))].sort((a, b) => a - b);
1460
+ f.ownHunks = all.filter((h) => !at.has(h));
1461
+ }
1462
+ return groups;
1463
+ }
1464
+ function sameLines(list) {
1465
+ const counts = /* @__PURE__ */ new Map();
1466
+ let lines2 = 0;
1467
+ for (const hunk of list) {
1468
+ for (const line of hunk.removed) counts.set(line, (counts.get(line) ?? 0) + 1);
1469
+ for (const line of hunk.added) counts.set(line, (counts.get(line) ?? 0) - 1);
1470
+ lines2 += hunk.removed.length;
1471
+ }
1472
+ return lines2 > 0 && [...counts.values()].every((n) => n === 0);
1473
+ }
1094
1474
  function onlyDates(list) {
1095
1475
  const blank = (lines2) => lines2.map((l) => l.replace(DATE, "\0"));
1096
1476
  let first;
@@ -1113,17 +1493,66 @@ function onlyDates(list) {
1113
1493
  }
1114
1494
  return first;
1115
1495
  }
1496
+ var IGNORING = "Ignoring asset fingerprints, image ids, integrity hashes, the generator's version, whitespace between tags, and how tags are written where browsers read them the same (attribute order, quotes, entities, `<br/>`) (--exact compares bytes).\n";
1497
+ var IMAGES_LISTED = 5;
1498
+ function listed(urls, sign) {
1499
+ const images = urls.filter(isHashedImage);
1500
+ if (images.length <= IMAGES_LISTED) return urls.map((url) => ` ${sign} ${url}
1501
+ `);
1502
+ const out = urls.filter((url) => !isHashedImage(url)).map((url) => ` ${sign} ${url}
1503
+ `);
1504
+ out.push(` ${sign} ${plural(images.length, "image", "images")} named by an id (${images[0].replace(IMAGE_ID, "{id}")} and the like): two builds that hash images differently name them differently, so they're counted here (--format json lists them)
1505
+ `);
1506
+ return out;
1507
+ }
1116
1508
  function clip(line) {
1117
1509
  const MAX = 200;
1118
1510
  const n = charCount(line);
1119
1511
  return n <= MAX ? line : `${firstChars(line, MAX)}\u2026 (${n - MAX} more characters)`;
1120
1512
  }
1121
1513
  var plural = (n, one, many) => `${count(n)} ${n === 1 ? one : many}`;
1514
+ function linesText(hunks2, total, limit, paint, indent = " ") {
1515
+ let shown = 0;
1516
+ let text = "";
1517
+ let place;
1518
+ done: for (const hunk of hunks2) {
1519
+ if (hunk.at !== void 0 && hunk.at !== place && !(limit > 0 && shown >= limit)) text += paint("2", `${indent}@ under ${hunk.at}
1520
+ `);
1521
+ place = hunk.at;
1522
+ for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1523
+ for (const line of side) {
1524
+ if (limit > 0 && shown >= limit) break done;
1525
+ text += paint(code, `${indent}${sign} ${clip(line)}
1526
+ `);
1527
+ shown += 1;
1528
+ }
1529
+ }
1530
+ }
1531
+ if (total > shown) text += `${indent}... ${count(total - shown)} more changed ${total - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1532
+ `;
1533
+ return text;
1534
+ }
1535
+ var isPageUrl = (url) => url.endsWith("/") || isPage(url);
1536
+ function groupsText(groups, limit, paint, heading) {
1537
+ let out = ` ${heading}, the most files first (--ungrouped lists each file with all of it):
1538
+ `;
1539
+ for (const group of groups) {
1540
+ const n = group.urls.length;
1541
+ const what = group.urls.every(isPageUrl) ? n === 1 ? "page" : "pages" : n === 1 ? "file" : "files";
1542
+ const some = group.urls.slice(0, 3).join(", ");
1543
+ const alike = group.match === "lines" ? "" : group.match === "values" ? ", the same but for attribute values" : group.match === "dates" ? ", the same dates in other text" : ", the same tags with other attributes";
1544
+ out += ` ~ ${count(n)} ${what}${alike}: ${some}${n > 3 ? ` and ${count(n - 3)} more` : ""}
1545
+ `;
1546
+ out += linesText([group.hunk], group.hunk.removed.length + group.hunk.added.length, limit, paint);
1547
+ }
1548
+ return out;
1549
+ }
1122
1550
  function diffText(report, limit, color) {
1123
1551
  const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
1124
1552
  let out = `Comparing ${report.before} with ${report.after}
1125
1553
  `;
1126
- out += report.exact ? "Comparing bytes (--exact).\n" : "Ignoring asset fingerprints, integrity hashes, the generator's version, and whitespace between tags (--exact compares bytes).\n";
1554
+ out += report.exact ? "Comparing bytes (--exact).\n" : IGNORING;
1555
+ const pageUrl = isPageUrl;
1127
1556
  const unchanged = `${plural(report.unchangedPages, "page", "pages")} and ${plural(report.unchangedFiles, "other file", "other files")}`;
1128
1557
  if (isSame(report)) return `${out}
1129
1558
  No differences: ${unchanged} are the same. The stump has not moved.
@@ -1132,20 +1561,26 @@ No differences: ${unchanged} are the same. The stump has not moved.
1132
1561
  out += `
1133
1562
  Added (${report.added.length})
1134
1563
  `;
1135
- for (const url of report.added) out += paint("32", ` + ${url}
1136
- `);
1564
+ for (const line of listed(report.added, "+")) out += paint("32", line);
1137
1565
  }
1138
1566
  if (report.removed.length) {
1139
1567
  out += `
1140
1568
  Removed (${report.removed.length})
1141
1569
  `;
1142
- for (const url of report.removed) out += paint("31", ` - ${url}
1143
- `);
1570
+ for (const line of listed(report.removed, "-")) out += paint("31", line);
1144
1571
  }
1145
1572
  if (report.changed.length) out += `
1146
1573
  Changed (${report.changed.length})
1147
1574
  `;
1575
+ const grouped = report.groups.length > 0;
1576
+ if (grouped) {
1577
+ out += groupsText(report.groups, limit, paint, "The same change on more than one file");
1578
+ const rest = report.changed.filter((f) => f.ownLines > 0);
1579
+ if (rest.length) out += ` And what's left on ${plural(rest.length, "file", "files")}:
1580
+ `;
1581
+ }
1148
1582
  for (const file of report.changed) {
1583
+ if (grouped && file.ownLines === 0) continue;
1149
1584
  const about = [];
1150
1585
  if (file.what.length) about.push(file.what.join(" and "));
1151
1586
  if (file.renamed) {
@@ -1157,21 +1592,8 @@ Changed (${report.changed.length})
1157
1592
  `;
1158
1593
  for (const note of file.notes) out += ` ${note}
1159
1594
  `;
1160
- let shown = 0;
1161
- done: for (const hunk of file.hunks) {
1162
- for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1163
- for (const line of side) {
1164
- if (limit > 0 && shown >= limit) break done;
1165
- out += paint(code, ` ${sign} ${clip(line)}
1166
- `);
1167
- shown += 1;
1168
- }
1169
- }
1170
- }
1171
- if (file.changedLines > shown) out += ` ... ${count(file.changedLines - shown)} more changed ${file.changedLines - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1172
- `;
1595
+ out += grouped ? linesText(file.ownHunks, file.ownLines, limit, paint) : linesText(file.hunks, file.changedLines, limit, paint);
1173
1596
  }
1174
- const pageUrl = (url) => url.endsWith("/") || isPage(url);
1175
1597
  const pages = [...report.added, ...report.removed].filter(pageUrl).length + report.changed.filter((f) => isPage(f.path)).length;
1176
1598
  const others = report.added.length + report.removed.length + report.changed.length - pages;
1177
1599
  const found = others === 0 ? plural(pages, "page", "pages") : pages === 0 ? plural(others, "other file", "other files") : `${plural(pages, "page", "pages")} and ${plural(others, "other file", "other files")}`;
@@ -1182,6 +1604,7 @@ Changed (${report.changed.length})
1182
1604
  ${which} differ only in dates or years. See \`ssqch docs "dates that changed"\`: a page with no date of its own gets its file's modification time.
1183
1605
  `;
1184
1606
  }
1607
+ if (report.added.length || report.removed.length) out += "\nIf a folder held an earlier build, its leftover files are among the added and removed: to rule that out, build each side into an empty folder.\n";
1185
1608
  out += `
1186
1609
  Changes found: ${found} (${count(report.changed.length)} changed, ${count(report.added.length)} added, ${count(report.removed.length)} removed); ${unchanged} are the same. The stump has moved.
1187
1610
  `;
@@ -1199,7 +1622,8 @@ function diffJson(report, limit) {
1199
1622
  onlyDates: f.onlyDates !== void 0,
1200
1623
  sizeBefore: f.sizeBefore,
1201
1624
  sizeAfter: f.sizeAfter,
1202
- hunks: firstLines(f.hunks, limit)
1625
+ hunks: firstLines(f.hunks, limit),
1626
+ groups: f.groups
1203
1627
  };
1204
1628
  if (f.renamed) entry.renamed = { before: f.renamed[0], after: f.renamed[1] };
1205
1629
  return entry;
@@ -1213,16 +1637,19 @@ function diffJson(report, limit) {
1213
1637
  summary: { added: report.added.length, removed: report.removed.length, changed: report.changed.length, unchangedPages: report.unchangedPages, unchangedFiles: report.unchangedFiles },
1214
1638
  added: report.added,
1215
1639
  removed: report.removed,
1216
- changed
1640
+ changed,
1641
+ // Each change on more than one file, the most files first; a file's `groups` are places in this list.
1642
+ groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk }))
1217
1643
  };
1218
1644
  }
1219
1645
  async function compareRuns(dirs, options) {
1220
- const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
1646
+ const keep = (paths) => kept(paths, options);
1221
1647
  const walks = await Promise.allSettled(dirs.map(files));
1222
1648
  for (const walk of walks) if (walk.status === "rejected") throw walk.reason;
1649
+ checkOnly(walks.map((w) => w.value), options);
1223
1650
  const maps = walks.map((w) => keyed(keep(w.value), options.exact));
1224
1651
  const keys = [...new Set(maps.flatMap((m) => [...m.keys()]))].sort(compareText);
1225
- const report = { runs: dirs, exact: options.exact, varies: [], steadyPages: 0, steadyFiles: 0 };
1652
+ const report = { runs: dirs, exact: options.exact, varies: [], groups: [], steadyPages: 0, steadyFiles: 0, typical: 0 };
1226
1653
  const found = new Array(keys.length);
1227
1654
  let next = 0;
1228
1655
  const worker = async () => {
@@ -1243,6 +1670,17 @@ async function compareRuns(dirs, options) {
1243
1670
  else if (isPage(key)) report.steadyPages += 1;
1244
1671
  else report.steadyFiles += 1;
1245
1672
  });
1673
+ const typical = dirs.map(() => 0);
1674
+ for (const v of report.varies) if (!v.versions[0].missing) for (const run of v.versions[0].runs) typical[run] += 1;
1675
+ report.typical = typical.indexOf(Math.max(...typical));
1676
+ const samples = report.varies.map((v) => v.sample).filter((s) => s !== void 0);
1677
+ report.groups = options.ungrouped ? [] : groupChanges(samples);
1678
+ for (const sample of samples) {
1679
+ if (!report.groups.length) sample.ownHunks = sample.allHunks ?? sample.hunks;
1680
+ sample.ownLines = sample.ownHunks.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1681
+ sample.ownHunks = firstLines(sample.ownHunks, options.lines);
1682
+ delete sample.allHunks;
1683
+ }
1246
1684
  return report;
1247
1685
  }
1248
1686
  function seen(key, data, options) {
@@ -1250,6 +1688,7 @@ function seen(key, data, options) {
1250
1688
  if (text === void 0) return `b:${data.toString("base64")}`;
1251
1689
  const normal = normalize(text, options);
1252
1690
  if (isPage(key) && !options.exact) return `p:${tokens(normal).map((t) => `${t.tag ? 1 : 0}${t.text}`).join("\0")}`;
1691
+ if (isXml(key) && !options.exact) return `x:${tokens(xmlWithMarkup(normal), true).map((t) => `${t.tag ? 1 : 0}${t.text}`).join("\0")}`;
1253
1692
  return `t:${normal}`;
1254
1693
  }
1255
1694
  function varies(key, buffers, maps, options) {
@@ -1271,14 +1710,14 @@ function varies(key, buffers, maps, options) {
1271
1710
  }
1272
1711
  const first = buffers.find((b) => b !== void 0);
1273
1712
  const kind = decode(first) === void 0 ? "binary" : isPage(key) ? "page" : "text";
1274
- return { path: key, url: urlOf(key), kind, versions, sample };
1713
+ return { path: key, url: urlOf(key), kind, versions, sample, files: maps.map((m) => m.get(key)) };
1275
1714
  }
1276
- var named = (report, runs) => runs.map((r) => report.runs[r]).join(", ");
1715
+ var named = (report, runs) => runs.length > 4 ? `${runs.length} of ${report.runs.length} builds (${runs.slice(0, 3).map((r) => report.runs[r]).join(", ")}, ...)` : runs.map((r) => report.runs[r]).join(", ");
1277
1716
  function runsText(report, limit, color) {
1278
1717
  const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
1279
1718
  let out = `Comparing ${count(report.runs.length)} builds: ${report.runs.join(", ")}
1280
1719
  `;
1281
- out += report.exact ? "Comparing bytes (--exact).\n" : "Ignoring asset fingerprints, integrity hashes, the generator's version, and whitespace between tags (--exact compares bytes).\n";
1720
+ out += report.exact ? "Comparing bytes (--exact).\n" : IGNORING;
1282
1721
  const steady = `${plural(report.steadyPages, "page", "pages")} and ${plural(report.steadyFiles, "other file", "other files")}`;
1283
1722
  if (!report.varies.length) return `${out}
1284
1723
  Every build is the same: ${steady}. The tracks match every time.
@@ -1286,7 +1725,15 @@ Every build is the same: ${steady}. The tracks match every time.
1286
1725
  out += `
1287
1726
  Varies (${report.varies.length})
1288
1727
  `;
1728
+ const grouped = report.groups.length > 0;
1729
+ if (grouped) {
1730
+ out += groupsText(report.groups, limit, paint, "The same difference on more than one file");
1731
+ const rest = report.varies.filter((f) => !f.sample || f.sample.ownLines > 0);
1732
+ if (rest.length) out += ` And each file, with what's left:
1733
+ `;
1734
+ }
1289
1735
  for (const file of report.varies) {
1736
+ if (grouped && file.sample && file.sample.ownLines === 0) continue;
1290
1737
  const [most, ...rest] = file.versions;
1291
1738
  const onlyIn = most.missing && rest.length === 1;
1292
1739
  const others = rest.map((v) => v.missing ? `missing from ${named(report, v.runs)}` : onlyIn ? `only in ${named(report, v.runs)}` : `${named(report, v.runs)} differ${v.runs.length === 1 ? "s" : ""}`);
@@ -1297,22 +1744,16 @@ Varies (${report.varies.length})
1297
1744
  if (!sample) continue;
1298
1745
  for (const note of sample.notes) out += ` ${note}
1299
1746
  `;
1300
- let shown = 0;
1301
- done: for (const hunk of sample.hunks) {
1302
- for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1303
- for (const line of side) {
1304
- if (limit > 0 && shown >= limit) break done;
1305
- out += paint(code, ` ${sign} ${clip(line)}
1306
- `);
1307
- shown += 1;
1308
- }
1309
- }
1310
- }
1311
- if (sample.changedLines > shown) out += ` ... ${count(sample.changedLines - shown)} more changed ${sample.changedLines - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1312
- `;
1747
+ out += grouped ? linesText(sample.ownHunks, sample.ownLines, limit, paint) : linesText(sample.hunks, sample.changedLines, limit, paint);
1313
1748
  }
1314
1749
  out += `
1315
1750
  ${plural(report.varies.length, "file varies", "files vary")} between builds made the same way; ${steady} are the same in all of them. Pin what changes (the build's time, random ids) before comparing another build with these, or leave it out with --ignore.
1751
+ `;
1752
+ const common = report.varies.filter((v) => !v.versions[0].missing && v.versions[0].runs.includes(report.typical)).length;
1753
+ out += `The build most like the others: ${report.runs[report.typical]}, with the most common version of ${common} of the ${plural(report.varies.length, "file", "files")} that vary.
1754
+ `;
1755
+ const unsettled = report.varies.filter((v) => v.versions[0].runs.length < 2).length;
1756
+ if (unsettled) out += `${unsettled === 1 ? "1 file has" : `${unsettled} files have`} no most common version: each build has its own. More builds (--runs 20) show whether one is usual.
1316
1757
  `;
1317
1758
  return out;
1318
1759
  }
@@ -1324,25 +1765,36 @@ function runsJson(report, limit) {
1324
1765
  exact: report.exact,
1325
1766
  same: report.varies.length === 0,
1326
1767
  summary: { varies: report.varies.length, steadyPages: report.steadyPages, steadyFiles: report.steadyFiles },
1768
+ // The build with the most common version of the most files that vary.
1769
+ typical: runs[report.typical],
1327
1770
  varies: report.varies.map((f) => ({
1328
1771
  url: f.url,
1329
1772
  path: f.path,
1330
1773
  kind: f.kind,
1331
1774
  versions: f.versions.map((v) => ({ runs: v.runs.map((r) => runs[r]), missing: v.missing })),
1332
1775
  changedLines: f.sample?.changedLines ?? 0,
1333
- hunks: f.sample ? firstLines(f.sample.hunks, limit) : []
1334
- }))
1776
+ hunks: f.sample ? firstLines(f.sample.hunks, limit) : [],
1777
+ groups: f.sample?.groups ?? []
1778
+ })),
1779
+ // Each difference on more than one varying file, the most files first; a file's `groups` are places in this list.
1780
+ groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk }))
1335
1781
  };
1336
1782
  }
1783
+
1337
1784
  export {
1338
- compare,
1339
- compareRuns,
1340
- diffJson,
1341
- diffText,
1342
1785
  isSame,
1786
+ isHashedImage,
1787
+ withoutImageIds,
1788
+ withoutFingerprints,
1343
1789
  keyed,
1344
- runsJson,
1345
- runsText,
1790
+ canonicalText,
1791
+ canonicalTag,
1346
1792
  tokens,
1347
- withoutFingerprints
1793
+ compare,
1794
+ groupChanges,
1795
+ diffText,
1796
+ diffJson,
1797
+ compareRuns,
1798
+ runsText,
1799
+ runsJson
1348
1800
  };