ssqch 0.11.0 → 0.13.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.
- package/bundled/completions/bash +67 -9
- package/bundled/completions/elvish +24 -4
- package/bundled/completions/fish +37 -25
- package/bundled/completions/powershell +26 -4
- package/bundled/completions/zsh +45 -10
- package/bundled/docs/agents.md +2 -2
- package/bundled/docs/build-summary.md +1 -1
- package/bundled/docs/comparing-builds.md +7 -4
- package/bundled/docs/configuring.md +7 -12
- package/bundled/docs/deploying.md +1 -1
- package/bundled/docs/field-guide.md +4 -4
- package/bundled/docs/github-pages.md +2 -1
- package/bundled/docs/index.md +1 -1
- package/bundled/docs/install.md +1 -1
- package/bundled/docs/known-gaps.md +1 -1
- package/bundled/docs/markdown.md +11 -13
- package/bundled/docs/nav.yml +6 -1
- package/bundled/docs/netlify.md +4 -2
- package/bundled/docs/patrol.md +48 -0
- package/bundled/docs/plugins.md +6 -4
- package/bundled/docs/robots.md +72 -0
- package/bundled/docs/seo.md +2 -38
- package/bundled/docs/serving-markdown.md +142 -0
- package/bundled/docs/template-languages.md +2 -1
- package/bundled/docs/templates.md +2 -1
- package/bundled/docs/trailheads/from-component-frameworks.md +9 -10
- package/bundled/docs/trailheads/from-hugo.md +5 -3
- package/bundled/docs/trailheads/from-jekyll.md +54 -13
- package/bundled/docs/trailheads/from-mkdocs.md +15 -12
- package/bundled/docs/trailheads/from-vitepress.md +142 -0
- package/bundled/docs/trailheads.md +5 -5
- package/bundled/docs/where-values-come-from.md +5 -5
- package/bundled/docs/writing-plugins.md +69 -0
- package/bundled/ssqch.d.ts +150 -34
- package/bundled/starter/engines/index.edge +1 -0
- package/bundled/starter/engines/index.ejs +1 -0
- package/bundled/starter/engines/index.hbs +1 -0
- package/bundled/starter/engines/index.liquid +1 -0
- package/bundled/starter/engines/layout.edge +7 -0
- package/bundled/starter/engines/layout.ejs +4 -0
- package/bundled/starter/engines/layout.hbs +4 -0
- package/bundled/starter/engines/layout.liquid +4 -0
- package/bundled/starter/src/_data/site.json +1 -0
- package/bundled/starter/src/_includes/layout.jinja +4 -0
- package/bundled/starter/src/index.jinja +1 -0
- package/bundled/starter/ssqch.config.js +14 -1
- package/bundled/starter-docs/engines/edge/base.edge +7 -0
- package/bundled/starter-docs/engines/edge/doc.edge +4 -0
- package/bundled/starter-docs/engines/ejs/base.ejs +4 -0
- package/bundled/starter-docs/engines/ejs/doc.ejs +4 -0
- package/bundled/starter-docs/engines/hbs/base.hbs +4 -0
- package/bundled/starter-docs/engines/hbs/doc.hbs +3 -0
- package/bundled/starter-docs/engines/liquid/base.liquid +4 -0
- package/bundled/starter-docs/engines/liquid/doc.liquid +4 -0
- package/bundled/starter-docs/src/_data/site.json +1 -0
- package/bundled/starter-docs/src/_includes/base.jinja +4 -0
- package/bundled/starter-docs/src/_includes/doc.jinja +4 -0
- package/bundled/starter-docs/src/assets/docs.css +4 -0
- package/bundled/starter-docs/src/assets/docs.js +17 -0
- package/bundled/starter-docs/ssqch.config.js +14 -1
- package/lib/assets.js +13 -11
- package/lib/chunk-25WERNDD.js +112 -0
- package/lib/{chunk-H5K2ZE7B.js → chunk-2BJFGKOE.js} +13 -5
- package/lib/chunk-2FKYWYAB.js +268 -0
- package/lib/{chunk-LJOURBYT.js → chunk-3ZTRIO6O.js} +21 -19
- package/lib/{chunk-IOBC665M.js → chunk-4AZFCSGJ.js} +5 -3
- package/lib/{chunk-HWW5NCVJ.js → chunk-4Q6WMTER.js} +1 -1
- package/lib/{chunk-V2FSMOFX.js → chunk-55WXDGO4.js} +3 -3
- package/lib/{chunk-ZR3JYLFB.js → chunk-6FY77I4M.js} +331 -58
- package/lib/{chunk-JC54PHIT.js → chunk-6OUCRDYI.js} +514 -141
- package/lib/{chunk-ERAIEV3O.js → chunk-6U5VIQVY.js} +9 -7
- package/lib/{chunk-Z5OP43HU.js → chunk-7U5GWTEH.js} +455 -94
- package/lib/{chunk-CMJ7X5WW.js → chunk-AIJNG6MJ.js} +3 -2
- package/lib/{chunk-3K237XAX.js → chunk-C2Q7JKFI.js} +12 -10
- package/lib/{chunk-GS5B3CBW.js → chunk-DDV6JEC2.js} +1 -1
- package/lib/{chunk-A75EVUJX.js → chunk-DFJFHULZ.js} +47 -20
- package/lib/{chunk-KZZS4W2V.js → chunk-ENWDM2RW.js} +45 -42
- package/lib/{chunk-I3HYKEEW.js → chunk-ER72RPD6.js} +3 -3
- package/lib/chunk-F3JPNFCZ.js +23 -0
- package/lib/{chunk-B5E27PLU.js → chunk-FENJHLNM.js} +6 -3
- package/lib/{chunk-UU43WIZG.js → chunk-FJML7INB.js} +4 -2
- package/lib/{chunk-KCF2Z6N7.js → chunk-FQZDUDFK.js} +5 -3
- package/lib/{chunk-GJNIQAIH.js → chunk-GSNRAGKQ.js} +13 -6
- package/lib/{chunk-443ZQLVX.js → chunk-GU7BBYWB.js} +5 -4
- package/lib/{chunk-X2GAVYV2.js → chunk-HDKU6LRI.js} +110 -748
- package/lib/chunk-J3C2LEW7.js +121 -0
- package/lib/{chunk-XS4EJSEK.js → chunk-K5WZ2VYK.js} +7 -5
- package/lib/{chunk-3HZZY3Y7.js → chunk-OOKBXQAY.js} +7 -6
- package/lib/chunk-P2WS4RM4.js +707 -0
- package/lib/{chunk-RBNPBTDP.js → chunk-SNQOHNXE.js} +1 -1
- package/lib/{chunk-HFSWUTXX.js → chunk-SPIFZBIW.js} +1 -1
- package/lib/{chunk-QLUTNR37.js → chunk-T5IUI7W7.js} +12 -11
- package/lib/{chunk-ZINLHOX4.js → chunk-TGSVSG2G.js} +3 -2
- package/lib/{chunk-2L3HR67O.js → chunk-U2KEMVXO.js} +24 -16
- package/lib/{chunk-RYIWYWRQ.js → chunk-UHRBPZ4A.js} +7 -5
- package/lib/{chunk-2QTJTEBV.js → chunk-ULCT3PAV.js} +1 -1
- package/lib/{chunk-FCM3NYFR.js → chunk-UZNUS7RP.js} +12 -9
- package/lib/{chunk-GLJQ4C76.js → chunk-V3G2QGL3.js} +13 -106
- package/lib/{chunk-Z44IAMNG.js → chunk-VILOEVK7.js} +60 -28
- package/lib/chunk-VJWQSYEG.js +119 -0
- package/lib/{chunk-5ELAUHRL.js → chunk-WGAIE3DD.js} +23 -19
- package/lib/{chunk-OQGXZYZS.js → chunk-WUCRAV36.js} +13 -7
- package/lib/{chunk-RZYAIX2R.js → chunk-XYAWJTHM.js} +11 -10
- package/lib/{chunk-OSBEH67S.js → chunk-YA23NDMW.js} +5 -3
- package/lib/{chunk-AIMEXBTK.js → chunk-YNJNMQWU.js} +37 -142
- package/lib/{chunk-QJ5ZFTML.js → chunk-ZMG25MXF.js} +20 -18
- package/lib/cli.js +72 -35
- package/lib/elements.js +13 -11
- package/lib/from-hugo.js +36 -0
- package/lib/from-jekyll.js +41 -0
- package/lib/from-mkdocs.js +49 -0
- package/lib/from-vitepress.js +49 -0
- package/lib/image.js +12 -11
- package/lib/links.js +13 -11
- package/lib/llms.js +613 -0
- package/lib/minify.js +14 -12
- package/lib/redirects.js +13 -11
- package/lib/robots.js +87 -0
- package/lib/rss.js +24 -13
- package/lib/sass.js +12 -11
- package/lib/sitemap.js +23 -18
- package/lib/ssqch.js +6 -5
- package/lib/vue.js +400 -0
- package/package.json +29 -1
- package/types/from-hugo.d.ts +5 -0
- package/types/from-jekyll.d.ts +11 -0
- package/types/from-mkdocs.d.ts +11 -0
- package/types/from-vitepress.d.ts +5 -0
- package/types/index.d.ts +51 -31
- package/types/llms.d.ts +27 -0
- package/types/robots.d.ts +13 -0
- package/types/sass.d.ts +1 -1
- package/types/sitemap.d.ts +2 -2
- package/types/vue.d.ts +17 -0
- package/wasm/markdown.wasm +0 -0
- package/lib/chunk-RVXGUMFI.js +0 -21
- /package/lib/{chunk-ZR3JYLFB.js.LEGAL.txt → chunk-6FY77I4M.js.LEGAL.txt} +0 -0
- /package/lib/{chunk-AIMEXBTK.js.LEGAL.txt → chunk-YNJNMQWU.js.LEGAL.txt} +0 -0
|
@@ -1,735 +1,40 @@
|
|
|
1
1
|
import { createRequire as __ssqchCreateRequire } from "node:module";
|
|
2
2
|
const require = __ssqchCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
diffOps
|
|
5
|
+
} from "./chunk-P2WS4RM4.js";
|
|
3
6
|
import {
|
|
4
7
|
buildFiles,
|
|
5
8
|
urlOf
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UHRBPZ4A.js";
|
|
7
10
|
import {
|
|
8
11
|
bytes,
|
|
9
12
|
count
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-6U5VIQVY.js";
|
|
14
|
+
import {
|
|
15
|
+
ACCOUNTS_DIFFER
|
|
16
|
+
} from "./chunk-FJML7INB.js";
|
|
11
17
|
import {
|
|
12
|
-
charCount,
|
|
13
18
|
firstChars,
|
|
14
19
|
quoted
|
|
15
20
|
} from "./chunk-CMUWRPSQ.js";
|
|
16
21
|
import {
|
|
17
22
|
BuildError,
|
|
18
|
-
bail
|
|
23
|
+
bail
|
|
24
|
+
} from "./chunk-YNJNMQWU.js";
|
|
25
|
+
import {
|
|
19
26
|
compareText
|
|
20
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-VJWQSYEG.js";
|
|
21
28
|
|
|
22
29
|
// src/diff.ts
|
|
23
30
|
import fs from "node:fs";
|
|
24
31
|
import path from "node:path";
|
|
25
|
-
|
|
26
|
-
// src/myers.ts
|
|
27
|
-
function diffOps(old, next) {
|
|
28
|
-
const capture = new Capture();
|
|
29
|
-
const compact = new Compact(new Replace(capture), old, next);
|
|
30
|
-
diff(compact, old, 0, old.length, next, 0, next.length);
|
|
31
|
-
return capture.ops;
|
|
32
|
-
}
|
|
33
|
-
var Capture = class {
|
|
34
|
-
ops = [];
|
|
35
|
-
equal(oldIndex, newIndex, len) {
|
|
36
|
-
this.ops.push({ tag: "equal", oldIndex, oldLen: len, newIndex, newLen: len });
|
|
37
|
-
}
|
|
38
|
-
delete(oldIndex, oldLen, newIndex) {
|
|
39
|
-
this.ops.push({ tag: "delete", oldIndex, oldLen, newIndex, newLen: 0 });
|
|
40
|
-
}
|
|
41
|
-
insert(oldIndex, newIndex, newLen) {
|
|
42
|
-
this.ops.push({ tag: "insert", oldIndex, oldLen: 0, newIndex, newLen });
|
|
43
|
-
}
|
|
44
|
-
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
45
|
-
this.ops.push({ tag: "replace", oldIndex, oldLen, newIndex, newLen });
|
|
46
|
-
}
|
|
47
|
-
finish() {
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var Replace = class {
|
|
51
|
-
d;
|
|
52
|
-
del;
|
|
53
|
-
ins;
|
|
54
|
-
eq;
|
|
55
|
-
constructor(d) {
|
|
56
|
-
this.d = d;
|
|
57
|
-
}
|
|
58
|
-
flushEq() {
|
|
59
|
-
if (this.eq) {
|
|
60
|
-
const [o, n, len] = this.eq;
|
|
61
|
-
this.eq = void 0;
|
|
62
|
-
this.d.equal(o, n, len);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
flushDelIns() {
|
|
66
|
-
if (this.del) {
|
|
67
|
-
const [o, ol, n] = this.del;
|
|
68
|
-
this.del = void 0;
|
|
69
|
-
if (this.ins) {
|
|
70
|
-
const [, insNew, insLen] = this.ins;
|
|
71
|
-
this.ins = void 0;
|
|
72
|
-
this.d.replace(o, ol, insNew, insLen);
|
|
73
|
-
} else this.d.delete(o, ol, n);
|
|
74
|
-
} else if (this.ins) {
|
|
75
|
-
const [o, n, nl] = this.ins;
|
|
76
|
-
this.ins = void 0;
|
|
77
|
-
this.d.insert(o, n, nl);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
equal(oldIndex, newIndex, len) {
|
|
81
|
-
this.flushDelIns();
|
|
82
|
-
this.eq = this.eq ? [this.eq[0], this.eq[1], this.eq[2] + len] : [oldIndex, newIndex, len];
|
|
83
|
-
}
|
|
84
|
-
delete(oldIndex, oldLen, newIndex) {
|
|
85
|
-
this.flushEq();
|
|
86
|
-
this.del = this.del ? [this.del[0], this.del[1] + oldLen, this.del[2]] : [oldIndex, oldLen, newIndex];
|
|
87
|
-
}
|
|
88
|
-
insert(oldIndex, newIndex, newLen) {
|
|
89
|
-
this.flushEq();
|
|
90
|
-
this.ins = this.ins ? [this.ins[0], this.ins[1], this.ins[2] + newLen] : [oldIndex, newIndex, newLen];
|
|
91
|
-
}
|
|
92
|
-
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
93
|
-
this.flushEq();
|
|
94
|
-
this.d.replace(oldIndex, oldLen, newIndex, newLen);
|
|
95
|
-
}
|
|
96
|
-
finish() {
|
|
97
|
-
this.flushEq();
|
|
98
|
-
this.flushDelIns();
|
|
99
|
-
this.d.finish();
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
var EQUAL = 0;
|
|
103
|
-
var DELETE = 1;
|
|
104
|
-
var INSERT = 2;
|
|
105
|
-
var oldStart = (op) => op.oldIndex;
|
|
106
|
-
var oldEnd = (op) => op.oldIndex + (op.tag === INSERT ? 0 : op.len);
|
|
107
|
-
var newStart = (op) => op.newIndex;
|
|
108
|
-
var newEnd = (op) => op.newIndex + (op.tag === DELETE ? 0 : op.len);
|
|
109
|
-
var isEmpty = (op) => oldEnd(op) <= oldStart(op) && newEnd(op) <= newStart(op);
|
|
110
|
-
var adjust = (op, offset, len) => {
|
|
111
|
-
op.oldIndex += offset;
|
|
112
|
-
op.newIndex += offset;
|
|
113
|
-
op.len += len;
|
|
114
|
-
};
|
|
115
|
-
var shiftLeft = (op, n) => adjust(op, -n, 0);
|
|
116
|
-
var shiftRight = (op, n) => adjust(op, n, 0);
|
|
117
|
-
var growLeft = (op, n) => adjust(op, -n, n);
|
|
118
|
-
var growRight = (op, n) => adjust(op, 0, n);
|
|
119
|
-
var shrinkLeft = (op, n) => adjust(op, 0, -n);
|
|
120
|
-
var shrinkRight = (op, n) => adjust(op, n, -n);
|
|
121
|
-
var Compact = class {
|
|
122
|
-
d;
|
|
123
|
-
ops = [];
|
|
124
|
-
old;
|
|
125
|
-
next;
|
|
126
|
-
constructor(d, old, next) {
|
|
127
|
-
this.d = d;
|
|
128
|
-
this.old = old;
|
|
129
|
-
this.next = next;
|
|
130
|
-
}
|
|
131
|
-
equal(oldIndex, newIndex, len) {
|
|
132
|
-
this.ops.push({ tag: EQUAL, oldIndex, newIndex, len });
|
|
133
|
-
}
|
|
134
|
-
delete(oldIndex, oldLen, newIndex) {
|
|
135
|
-
this.ops.push({ tag: DELETE, oldIndex, newIndex, len: oldLen });
|
|
136
|
-
}
|
|
137
|
-
insert(oldIndex, newIndex, newLen) {
|
|
138
|
-
this.ops.push({ tag: INSERT, oldIndex, newIndex, len: newLen });
|
|
139
|
-
}
|
|
140
|
-
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
141
|
-
this.delete(oldIndex, oldLen, newIndex);
|
|
142
|
-
this.insert(oldIndex, newIndex, newLen);
|
|
143
|
-
}
|
|
144
|
-
finish() {
|
|
145
|
-
const { ops, old, next } = this;
|
|
146
|
-
shiftAll(ops, old, next);
|
|
147
|
-
normalizeCursors(ops);
|
|
148
|
-
for (const op of ops) {
|
|
149
|
-
if (op.tag === EQUAL) this.d.equal(op.oldIndex, op.newIndex, op.len);
|
|
150
|
-
else if (op.tag === DELETE) this.d.delete(op.oldIndex, op.len, op.newIndex);
|
|
151
|
-
else this.d.insert(op.oldIndex, op.newIndex, op.len);
|
|
152
|
-
}
|
|
153
|
-
this.d.finish();
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
function shiftAll(ops, old, next) {
|
|
157
|
-
for (const tag of [DELETE, INSERT]) {
|
|
158
|
-
let pointer = 0;
|
|
159
|
-
while (pointer < ops.length) {
|
|
160
|
-
if (ops[pointer].tag === tag) {
|
|
161
|
-
pointer = shiftUp(ops, old, next, pointer);
|
|
162
|
-
pointer = shiftDown(ops, old, next, pointer);
|
|
163
|
-
}
|
|
164
|
-
pointer += 1;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function normalizeCursors(ops) {
|
|
169
|
-
if (!ops.length) return;
|
|
170
|
-
let oldCursor = oldStart(ops[0]);
|
|
171
|
-
let newCursor = newStart(ops[0]);
|
|
172
|
-
for (const op of ops) {
|
|
173
|
-
if (op.tag === EQUAL) {
|
|
174
|
-
oldCursor = op.oldIndex + op.len;
|
|
175
|
-
newCursor = op.newIndex + op.len;
|
|
176
|
-
} else if (op.tag === DELETE) {
|
|
177
|
-
op.newIndex = newCursor;
|
|
178
|
-
oldCursor = op.oldIndex + op.len;
|
|
179
|
-
} else {
|
|
180
|
-
op.oldIndex = oldCursor;
|
|
181
|
-
newCursor = op.newIndex + op.len;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function swapAdjacent(ops, left) {
|
|
186
|
-
const right = left + 1;
|
|
187
|
-
const oStart = oldStart(ops[left]);
|
|
188
|
-
const oEnd = oldEnd(ops[right]);
|
|
189
|
-
const nStart = newStart(ops[left]);
|
|
190
|
-
const nEnd = newEnd(ops[right]);
|
|
191
|
-
[ops[left], ops[right]] = [ops[right], ops[left]];
|
|
192
|
-
if (ops[left].tag === INSERT) ops[left].oldIndex = oStart;
|
|
193
|
-
else ops[left].newIndex = nStart;
|
|
194
|
-
if (ops[right].tag === INSERT) ops[right].oldIndex = oEnd;
|
|
195
|
-
else ops[right].newIndex = nEnd;
|
|
196
|
-
}
|
|
197
|
-
var copy = (op) => ({ ...op });
|
|
198
|
-
function shiftUp(ops, old, next, pointer) {
|
|
199
|
-
while (pointer >= 1 && pointer - 1 < ops.length) {
|
|
200
|
-
const prev = copy(ops[pointer - 1]);
|
|
201
|
-
const self = copy(ops[pointer]);
|
|
202
|
-
if ((self.tag === INSERT || self.tag === DELETE) && prev.tag === EQUAL) {
|
|
203
|
-
if (self.tag === DELETE && !(pointer >= 2 && ops[pointer - 2]?.tag === DELETE)) break;
|
|
204
|
-
const suffix = self.tag === INSERT ? commonSuffixLen(old, oldStart(prev), oldEnd(prev), next, newStart(self), newEnd(self)) : commonSuffixLen(old, oldStart(self), oldEnd(self), next, newStart(prev), newEnd(prev));
|
|
205
|
-
if (suffix > 0) {
|
|
206
|
-
if (ops[pointer + 1]?.tag === EQUAL) growLeft(ops[pointer + 1], suffix);
|
|
207
|
-
else {
|
|
208
|
-
const equalOld = (self.tag === INSERT ? oldEnd(prev) : oldEnd(self)) - suffix;
|
|
209
|
-
const equalNew = (self.tag === INSERT ? newEnd(self) : newEnd(prev)) - suffix;
|
|
210
|
-
ops.splice(pointer + 1, 0, { tag: EQUAL, oldIndex: equalOld, newIndex: equalNew, len: suffix });
|
|
211
|
-
}
|
|
212
|
-
shiftLeft(ops[pointer], suffix);
|
|
213
|
-
shrinkLeft(ops[pointer - 1], suffix);
|
|
214
|
-
if (isEmpty(ops[pointer - 1])) {
|
|
215
|
-
ops.splice(pointer - 1, 1);
|
|
216
|
-
pointer -= 1;
|
|
217
|
-
}
|
|
218
|
-
} else if (isEmpty(ops[pointer - 1])) {
|
|
219
|
-
ops.splice(pointer - 1, 1);
|
|
220
|
-
pointer -= 1;
|
|
221
|
-
} else break;
|
|
222
|
-
} else if (self.tag === INSERT && prev.tag === DELETE || self.tag === DELETE && prev.tag === INSERT) {
|
|
223
|
-
swapAdjacent(ops, pointer - 1);
|
|
224
|
-
pointer -= 1;
|
|
225
|
-
} else if (self.tag === prev.tag && self.tag !== EQUAL) {
|
|
226
|
-
growRight(ops[pointer - 1], self.len);
|
|
227
|
-
ops.splice(pointer, 1);
|
|
228
|
-
pointer -= 1;
|
|
229
|
-
} else throw new Error(`unexpected ops in the diff's cleanup: ${prev.tag} then ${self.tag}`);
|
|
230
|
-
}
|
|
231
|
-
return pointer;
|
|
232
|
-
}
|
|
233
|
-
function shiftDown(ops, old, next, pointer) {
|
|
234
|
-
while (pointer + 1 < ops.length) {
|
|
235
|
-
const following = copy(ops[pointer + 1]);
|
|
236
|
-
const self = copy(ops[pointer]);
|
|
237
|
-
if ((self.tag === INSERT || self.tag === DELETE) && following.tag === EQUAL) {
|
|
238
|
-
if (self.tag === DELETE && ops[pointer + 2]?.tag !== DELETE) break;
|
|
239
|
-
const prefix = self.tag === INSERT ? commonPrefixLen(old, oldStart(following), oldEnd(following), next, newStart(self), newEnd(self)) : commonPrefixLen(old, oldStart(self), oldEnd(self), next, newStart(following), newEnd(following));
|
|
240
|
-
if (prefix > 0) {
|
|
241
|
-
if (pointer >= 1 && ops[pointer - 1].tag === EQUAL) growRight(ops[pointer - 1], prefix);
|
|
242
|
-
else {
|
|
243
|
-
const equalOld = self.tag === INSERT ? oldStart(following) : oldStart(self);
|
|
244
|
-
ops.splice(pointer, 0, { tag: EQUAL, oldIndex: equalOld, newIndex: newStart(self), len: prefix });
|
|
245
|
-
pointer += 1;
|
|
246
|
-
}
|
|
247
|
-
shiftRight(ops[pointer], prefix);
|
|
248
|
-
shrinkRight(ops[pointer + 1], prefix);
|
|
249
|
-
if (isEmpty(ops[pointer + 1])) ops.splice(pointer + 1, 1);
|
|
250
|
-
} else if (isEmpty(ops[pointer + 1])) ops.splice(pointer + 1, 1);
|
|
251
|
-
else break;
|
|
252
|
-
} else if (self.tag === INSERT && following.tag === DELETE || self.tag === DELETE && following.tag === INSERT) {
|
|
253
|
-
swapAdjacent(ops, pointer);
|
|
254
|
-
pointer += 1;
|
|
255
|
-
} else if (self.tag === following.tag && self.tag !== EQUAL) {
|
|
256
|
-
growRight(ops[pointer], following.len);
|
|
257
|
-
ops.splice(pointer + 1, 1);
|
|
258
|
-
} else throw new Error(`unexpected ops in the diff's cleanup: ${self.tag} then ${following.tag}`);
|
|
259
|
-
}
|
|
260
|
-
return pointer;
|
|
261
|
-
}
|
|
262
|
-
function commonPrefixLen(old, os, oe, next, ns, ne) {
|
|
263
|
-
if (os >= oe || ns >= ne) return 0;
|
|
264
|
-
const max = Math.min(oe - os, ne - ns);
|
|
265
|
-
let n = 0;
|
|
266
|
-
while (n < max && next[ns + n] === old[os + n]) n++;
|
|
267
|
-
return n;
|
|
268
|
-
}
|
|
269
|
-
function commonSuffixLen(old, os, oe, next, ns, ne) {
|
|
270
|
-
if (os >= oe || ns >= ne) return 0;
|
|
271
|
-
const max = Math.min(oe - os, ne - ns);
|
|
272
|
-
let n = 0;
|
|
273
|
-
while (n < max && next[ne - 1 - n] === old[oe - 1 - n]) n++;
|
|
274
|
-
return n;
|
|
275
|
-
}
|
|
276
|
-
var DISJOINT_FAST_PATH_MIN_LEN = 512;
|
|
277
|
-
var DISJOINT_FAST_PATH_MIN_WORK = 128 * 1024;
|
|
278
|
-
var DISJOINT_FAST_PATH_BOUNDARY_PROBE = 8;
|
|
279
|
-
var CONFUSING_RECORD_SCAN_WINDOW = 100;
|
|
280
|
-
var CONFUSING_RECORD_RATIO = 4;
|
|
281
|
-
var MAX_MATCH_FREQUENCY_THRESHOLD = 1024;
|
|
282
|
-
var NO_MATCH = -1;
|
|
283
|
-
var DISCARD = 0;
|
|
284
|
-
var KEEP = 1;
|
|
285
|
-
var INVESTIGATE = 2;
|
|
286
|
-
var isqrt = (n) => {
|
|
287
|
-
let r = Math.floor(Math.sqrt(n));
|
|
288
|
-
while (r * r > n) r--;
|
|
289
|
-
while ((r + 1) * (r + 1) <= n) r++;
|
|
290
|
-
return r;
|
|
291
|
-
};
|
|
292
|
-
function diff(d, old, os, oe, next, ns, ne) {
|
|
293
|
-
const pre = reduceForMyers(old, os, oe, next, ns, ne);
|
|
294
|
-
if ("trimmed" in pre) diffReduced(d, pre);
|
|
295
|
-
else diffPretrimmed(d, old, next, pre, HEURISTIC);
|
|
296
|
-
}
|
|
297
|
-
function trim(old, os, oe, next, ns, ne) {
|
|
298
|
-
const prefixLen = commonPrefixLen(old, os, oe, next, ns, ne);
|
|
299
|
-
const suffixLen = commonSuffixLen(old, os + prefixLen, oe, next, ns + prefixLen, ne);
|
|
300
|
-
return { oldStart: os + prefixLen, oldEnd: oe - suffixLen, newStart: ns + prefixLen, newEnd: ne - suffixLen, originalOldStart: os, originalOldEnd: oe, originalNewStart: ns, originalNewEnd: ne, prefixLen, suffixLen };
|
|
301
|
-
}
|
|
302
|
-
function shouldScan(old, os, oe, next, ns, ne) {
|
|
303
|
-
const oldLen = oe - os, newLen = ne - ns;
|
|
304
|
-
if (oldLen < DISJOINT_FAST_PATH_MIN_LEN || newLen < DISJOINT_FAST_PATH_MIN_LEN || oldLen * newLen < DISJOINT_FAST_PATH_MIN_WORK) return false;
|
|
305
|
-
if (next[ns] === old[os] || next[ne - 1] === old[oe - 1]) return false;
|
|
306
|
-
const probe = Math.min(oldLen, newLen, DISJOINT_FAST_PATH_BOUNDARY_PROBE + 1);
|
|
307
|
-
for (let skip = 1; skip < probe; skip++) {
|
|
308
|
-
if (next[ns + skip] === old[os] || next[ns] === old[os + skip] || next[ne - 1 - skip] === old[oe - 1] || next[ne - 1] === old[oe - 1 - skip]) return false;
|
|
309
|
-
}
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
function recordActions(ids2, oppositeCounts) {
|
|
313
|
-
const limit = Math.min(Math.max(isqrt(ids2.length), 1), MAX_MATCH_FREQUENCY_THRESHOLD);
|
|
314
|
-
const out = new Uint8Array(ids2.length);
|
|
315
|
-
ids2.forEach((id, i) => {
|
|
316
|
-
const count2 = id === NO_MATCH ? 0 : oppositeCounts[id];
|
|
317
|
-
out[i] = count2 === 0 ? DISCARD : count2 < limit ? KEEP : INVESTIGATE;
|
|
318
|
-
});
|
|
319
|
-
return out;
|
|
320
|
-
}
|
|
321
|
-
function scanConfusingRun(actions, from, step) {
|
|
322
|
-
let discards = 0, investigates = 0;
|
|
323
|
-
for (let i = from, seen2 = 0; i >= 0 && i < actions.length && seen2 < CONFUSING_RECORD_SCAN_WINDOW; i += step, seen2++) {
|
|
324
|
-
if (actions[i] === DISCARD) discards++;
|
|
325
|
-
else if (actions[i] === INVESTIGATE) investigates++;
|
|
326
|
-
else break;
|
|
327
|
-
}
|
|
328
|
-
return [discards, investigates];
|
|
329
|
-
}
|
|
330
|
-
function keepRecord(actions, index) {
|
|
331
|
-
if (actions[index] === DISCARD) return false;
|
|
332
|
-
if (actions[index] === KEEP) return true;
|
|
333
|
-
const [leftDiscards, leftInvestigates] = scanConfusingRun(actions, index - 1, -1);
|
|
334
|
-
if (leftDiscards === 0) return true;
|
|
335
|
-
const [rightDiscards, rightInvestigates] = scanConfusingRun(actions, index + 1, 1);
|
|
336
|
-
if (rightDiscards === 0) return true;
|
|
337
|
-
const discards = leftDiscards + rightDiscards;
|
|
338
|
-
const investigates = leftInvestigates + rightInvestigates + 1;
|
|
339
|
-
return !(investigates * CONFUSING_RECORD_RATIO < investigates + discards);
|
|
340
|
-
}
|
|
341
|
-
function reduceForMyers(old, os, oe, next, ns, ne) {
|
|
342
|
-
const trimmed = trim(old, os, oe, next, ns, ne);
|
|
343
|
-
const { oldStart: o0, oldEnd: o1, newStart: n0, newEnd: n1 } = trimmed;
|
|
344
|
-
if (!shouldScan(old, o0, o1, next, n0, n1)) return trimmed;
|
|
345
|
-
const ids2 = /* @__PURE__ */ new Map();
|
|
346
|
-
const oldValues = [];
|
|
347
|
-
const newValues = [];
|
|
348
|
-
const oldCounts = [];
|
|
349
|
-
const newCounts = [];
|
|
350
|
-
for (let i = o0; i < o1; i++) {
|
|
351
|
-
let id = ids2.get(old[i]);
|
|
352
|
-
if (id === void 0) {
|
|
353
|
-
id = oldCounts.length;
|
|
354
|
-
ids2.set(old[i], id);
|
|
355
|
-
oldCounts.push(0);
|
|
356
|
-
newCounts.push(0);
|
|
357
|
-
}
|
|
358
|
-
oldCounts[id]++;
|
|
359
|
-
oldValues.push(id);
|
|
360
|
-
}
|
|
361
|
-
for (let i = n0; i < n1; i++) {
|
|
362
|
-
const id = ids2.get(next[i]) ?? NO_MATCH;
|
|
363
|
-
if (id !== NO_MATCH) newCounts[id]++;
|
|
364
|
-
newValues.push(id);
|
|
365
|
-
}
|
|
366
|
-
const reduced = { oldValues: [], oldIndices: [], newValues: [], newIndices: [], trimmed };
|
|
367
|
-
const oldActions = recordActions(oldValues, newCounts);
|
|
368
|
-
oldValues.forEach((id, offset) => {
|
|
369
|
-
if (keepRecord(oldActions, offset)) {
|
|
370
|
-
reduced.oldValues.push(id);
|
|
371
|
-
reduced.oldIndices.push(o0 + offset);
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
const newActions = recordActions(newValues, oldCounts);
|
|
375
|
-
newValues.forEach((id, offset) => {
|
|
376
|
-
if (keepRecord(newActions, offset)) {
|
|
377
|
-
reduced.newValues.push(id);
|
|
378
|
-
reduced.newIndices.push(n0 + offset);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
if (reduced.oldIndices.length === o1 - o0 && reduced.newIndices.length === n1 - n0) return trimmed;
|
|
382
|
-
return reduced;
|
|
383
|
-
}
|
|
384
|
-
var ReducedHook = class {
|
|
385
|
-
d;
|
|
386
|
-
reduced;
|
|
387
|
-
oldCursor;
|
|
388
|
-
newCursor;
|
|
389
|
-
constructor(d, reduced) {
|
|
390
|
-
this.d = d;
|
|
391
|
-
this.reduced = reduced;
|
|
392
|
-
this.oldCursor = reduced.trimmed.oldStart;
|
|
393
|
-
this.newCursor = reduced.trimmed.newStart;
|
|
394
|
-
}
|
|
395
|
-
gaps(oldAnchor, newAnchor) {
|
|
396
|
-
if (this.oldCursor < oldAnchor) {
|
|
397
|
-
this.d.delete(this.oldCursor, oldAnchor - this.oldCursor, this.newCursor);
|
|
398
|
-
this.oldCursor = oldAnchor;
|
|
399
|
-
}
|
|
400
|
-
if (this.newCursor < newAnchor) {
|
|
401
|
-
this.d.insert(this.oldCursor, this.newCursor, newAnchor - this.newCursor);
|
|
402
|
-
this.newCursor = newAnchor;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
equal(oldIndex, newIndex, len) {
|
|
406
|
-
const { oldIndices, newIndices } = this.reduced;
|
|
407
|
-
let offset = 0;
|
|
408
|
-
while (offset < len) {
|
|
409
|
-
const oldAnchor = oldIndices[oldIndex + offset];
|
|
410
|
-
const newAnchor = newIndices[newIndex + offset];
|
|
411
|
-
this.gaps(oldAnchor, newAnchor);
|
|
412
|
-
let run = 1;
|
|
413
|
-
while (offset + run < len && oldIndices[oldIndex + offset + run] === oldAnchor + run && newIndices[newIndex + offset + run] === newAnchor + run) run++;
|
|
414
|
-
this.d.equal(oldAnchor, newAnchor, run);
|
|
415
|
-
this.oldCursor = oldAnchor + run;
|
|
416
|
-
this.newCursor = newAnchor + run;
|
|
417
|
-
offset += run;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
delete() {
|
|
421
|
-
}
|
|
422
|
-
insert() {
|
|
423
|
-
}
|
|
424
|
-
replace() {
|
|
425
|
-
}
|
|
426
|
-
finish() {
|
|
427
|
-
this.gaps(this.reduced.trimmed.oldEnd, this.reduced.trimmed.newEnd);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
function diffReduced(d, reduced) {
|
|
431
|
-
const t = reduced.trimmed;
|
|
432
|
-
if (t.prefixLen > 0) d.equal(t.originalOldStart, t.originalNewStart, t.prefixLen);
|
|
433
|
-
const hook = new ReducedHook(d, reduced);
|
|
434
|
-
const { oldValues, newValues } = reduced;
|
|
435
|
-
diffPretrimmed(hook, oldValues, newValues, trim(oldValues, 0, oldValues.length, newValues, 0, newValues.length), HEURISTIC);
|
|
436
|
-
if (t.suffixLen > 0) d.equal(t.originalOldEnd - t.suffixLen, t.originalNewEnd - t.suffixLen, t.suffixLen);
|
|
437
|
-
d.finish();
|
|
438
|
-
}
|
|
439
|
-
var HEURISTIC = 0;
|
|
440
|
-
var RAW = 1;
|
|
441
|
-
function diffPretrimmed(d, old, next, t, mode) {
|
|
442
|
-
if (t.prefixLen > 0) d.equal(t.originalOldStart, t.originalNewStart, t.prefixLen);
|
|
443
|
-
const oldEmpty = t.oldStart >= t.oldEnd, newEmpty = t.newStart >= t.newEnd;
|
|
444
|
-
if (oldEmpty && newEmpty) {
|
|
445
|
-
} else if (oldEmpty) d.insert(t.oldStart, t.newStart, t.newEnd - t.newStart);
|
|
446
|
-
else if (newEmpty) d.delete(t.oldStart, t.oldEnd - t.oldStart, t.newStart);
|
|
447
|
-
else {
|
|
448
|
-
const maxD = maxDiagonals(t.oldEnd - t.oldStart, t.newEnd - t.newStart);
|
|
449
|
-
conquer(d, old, t.oldStart, t.oldEnd, next, t.newStart, t.newEnd, new V(maxD), new V(maxD), mode);
|
|
450
|
-
}
|
|
451
|
-
if (t.suffixLen > 0) d.equal(t.originalOldEnd - t.suffixLen, t.originalNewEnd - t.suffixLen, t.suffixLen);
|
|
452
|
-
d.finish();
|
|
453
|
-
}
|
|
454
|
-
var V = class {
|
|
455
|
-
offset;
|
|
456
|
-
v;
|
|
457
|
-
constructor(maxD) {
|
|
458
|
-
this.offset = maxD;
|
|
459
|
-
this.v = new Int32Array(2 * maxD);
|
|
460
|
-
}
|
|
461
|
-
get(k) {
|
|
462
|
-
return this.v[k + this.offset];
|
|
463
|
-
}
|
|
464
|
-
set(k, x) {
|
|
465
|
-
this.v[k + this.offset] = x;
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
var maxDiagonals = (n, m) => Math.ceil((n + m) / 2) + 1;
|
|
469
|
-
var SMALL_SIDE_EXACT_MAX = 64;
|
|
470
|
-
var SMALL_SIDE_EXACT_MIN_LARGE = 512;
|
|
471
|
-
var SMALL_SIDE_EXACT_MAX_WORK = 64e6;
|
|
472
|
-
var HEURISTIC_MIN_COST = 256;
|
|
473
|
-
var HEURISTIC_MIN_SNAKE = 20;
|
|
474
|
-
var HEURISTIC_MIN_MAX_COST = 256;
|
|
475
|
-
var HEURISTIC_PROGRESS_FACTOR = 4;
|
|
476
|
-
function conquer(d, old, os, oe, next, ns, ne, vf, vb, mode) {
|
|
477
|
-
const prefix = commonPrefixLen(old, os, oe, next, ns, ne);
|
|
478
|
-
if (prefix > 0) d.equal(os, ns, prefix);
|
|
479
|
-
os += prefix;
|
|
480
|
-
ns += prefix;
|
|
481
|
-
const suffix = commonSuffixLen(old, os, oe, next, ns, ne);
|
|
482
|
-
const suffixOld = oe - suffix, suffixNew = ne - suffix;
|
|
483
|
-
oe -= suffix;
|
|
484
|
-
ne -= suffix;
|
|
485
|
-
while (os < oe && ns < ne) {
|
|
486
|
-
const [o, n] = frontAnchor(d, old, os, oe, next, ns, ne);
|
|
487
|
-
if (o === os && n === ns) break;
|
|
488
|
-
os = o;
|
|
489
|
-
ns = n;
|
|
490
|
-
}
|
|
491
|
-
if (os >= oe && ns >= ne) {
|
|
492
|
-
} else if (ns >= ne) d.delete(os, oe - os, ns);
|
|
493
|
-
else if (os >= oe) d.insert(os, ns, ne - ns);
|
|
494
|
-
else if (smallSideExact(d, old, os, oe, next, ns, ne)) {
|
|
495
|
-
} else {
|
|
496
|
-
const split = middleSnake(old, os, oe, next, ns, ne, vf, vb, mode);
|
|
497
|
-
if (split) {
|
|
498
|
-
conquer(d, old, os, split.oldIndex, next, ns, split.newIndex, vf, vb, split.leftMode);
|
|
499
|
-
conquer(d, old, split.oldIndex, oe, next, split.newIndex, ne, vf, vb, split.rightMode);
|
|
500
|
-
} else {
|
|
501
|
-
d.delete(os, oe - os, ns);
|
|
502
|
-
d.insert(os, ns, ne - ns);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (suffix > 0) d.equal(suffixOld, suffixNew, suffix);
|
|
506
|
-
}
|
|
507
|
-
function frontAnchor(d, old, os, oe, next, ns, ne) {
|
|
508
|
-
const MAX_SKIP = 4;
|
|
509
|
-
const MIN_ANCHOR_COMMON = 96;
|
|
510
|
-
const oldLen = oe - os, newLen = ne - ns;
|
|
511
|
-
if (oldLen <= MIN_ANCHOR_COMMON || newLen <= MIN_ANCHOR_COMMON) return [os, ns];
|
|
512
|
-
const small = Math.min(oldLen, newLen), large = Math.max(oldLen, newLen);
|
|
513
|
-
if (large < small * 2) return [os, ns];
|
|
514
|
-
const maxOldSkip = Math.min(oldLen - 1, MAX_SKIP);
|
|
515
|
-
const maxNewSkip = Math.min(newLen - 1, MAX_SKIP);
|
|
516
|
-
const preferInsert = newLen > oldLen;
|
|
517
|
-
const preferDelete = oldLen > newLen;
|
|
518
|
-
let best;
|
|
519
|
-
search: for (let oldSkip2 = 0; oldSkip2 <= maxOldSkip; oldSkip2++) {
|
|
520
|
-
for (let newSkip2 = 0; newSkip2 <= maxNewSkip; newSkip2++) {
|
|
521
|
-
if (oldSkip2 === 0 && newSkip2 === 0) continue;
|
|
522
|
-
if (oldSkip2 !== 0 && newSkip2 !== 0) continue;
|
|
523
|
-
if (preferInsert && oldSkip2 !== 0) continue;
|
|
524
|
-
if (preferDelete && newSkip2 !== 0) continue;
|
|
525
|
-
if (next[ns + newSkip2] !== old[os + oldSkip2]) continue;
|
|
526
|
-
const common2 = commonPrefixLen(old, os + oldSkip2, oe, next, ns + newSkip2, ne);
|
|
527
|
-
if (common2 < MIN_ANCHOR_COMMON) continue;
|
|
528
|
-
if (common2 >= MIN_ANCHOR_COMMON * 8) {
|
|
529
|
-
best = [oldSkip2, newSkip2, common2];
|
|
530
|
-
break search;
|
|
531
|
-
}
|
|
532
|
-
const better2 = best === void 0 || compareTuples([common2, -Math.max(oldSkip2, newSkip2), oldSkip2, newSkip2], [best[2], -Math.max(best[0], best[1]), best[0], best[1]]) > 0;
|
|
533
|
-
if (better2) best = [oldSkip2, newSkip2, common2];
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (!best) return [os, ns];
|
|
537
|
-
const [oldSkip, newSkip, common] = best;
|
|
538
|
-
if (oldSkip === 0) d.insert(os, ns, newSkip);
|
|
539
|
-
else if (newSkip === 0) d.delete(os, oldSkip, ns);
|
|
540
|
-
else d.replace(os, oldSkip, ns, newSkip);
|
|
541
|
-
d.equal(os + oldSkip, ns + newSkip, common);
|
|
542
|
-
return [os + oldSkip + common, ns + newSkip + common];
|
|
543
|
-
}
|
|
544
|
-
function compareTuples(a, b) {
|
|
545
|
-
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
546
|
-
return 0;
|
|
547
|
-
}
|
|
548
|
-
function smallSideExact(d, old, os, oe, next, ns, ne) {
|
|
549
|
-
const oldLen = oe - os, newLen = ne - ns;
|
|
550
|
-
const small = Math.min(oldLen, newLen), large = Math.max(oldLen, newLen);
|
|
551
|
-
if (small === 0 || small > SMALL_SIDE_EXACT_MAX || large < SMALL_SIDE_EXACT_MIN_LARGE || oldLen * newLen > SMALL_SIDE_EXACT_MAX_WORK) return false;
|
|
552
|
-
if (oldLen <= newLen) smallOld(d, old, os, oldLen, next, ns, newLen);
|
|
553
|
-
else smallNew(d, old, os, oldLen, next, ns, newLen);
|
|
554
|
-
return true;
|
|
555
|
-
}
|
|
556
|
-
function smallOld(d, old, os, n, next, ns, m) {
|
|
557
|
-
const width = m + 1;
|
|
558
|
-
const dp = new Uint8Array((n + 1) * width);
|
|
559
|
-
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
560
|
-
const row = i2 * width, below = (i2 + 1) * width;
|
|
561
|
-
for (let j2 = m - 1; j2 >= 0; j2--) dp[row + j2] = next[ns + j2] === old[os + i2] ? dp[below + j2 + 1] + 1 : Math.max(dp[below + j2], dp[row + j2 + 1]);
|
|
562
|
-
}
|
|
563
|
-
const takes = (i2, j2) => next[ns + j2] === old[os + i2] && dp[i2 * width + j2] === dp[(i2 + 1) * width + j2 + 1] + 1;
|
|
564
|
-
let i = 0, j = 0;
|
|
565
|
-
while (i < n && j < m) {
|
|
566
|
-
if (takes(i, j)) {
|
|
567
|
-
const si = i, sj = j;
|
|
568
|
-
while (i < n && j < m && takes(i, j)) {
|
|
569
|
-
i++;
|
|
570
|
-
j++;
|
|
571
|
-
}
|
|
572
|
-
d.equal(os + si, ns + sj, i - si);
|
|
573
|
-
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
574
|
-
const si = i;
|
|
575
|
-
const at = ns + j;
|
|
576
|
-
while (i < n) {
|
|
577
|
-
if (j >= m) {
|
|
578
|
-
i = n;
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
if (takes(i, j)) break;
|
|
582
|
-
if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) i++;
|
|
583
|
-
else break;
|
|
584
|
-
}
|
|
585
|
-
d.delete(os + si, i - si, at);
|
|
586
|
-
} else {
|
|
587
|
-
const sj = j;
|
|
588
|
-
const at = os + i;
|
|
589
|
-
while (j < m) {
|
|
590
|
-
if (i >= n) {
|
|
591
|
-
j = m;
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
if (takes(i, j)) break;
|
|
595
|
-
if (dp[(i + 1) * width + j] < dp[i * width + j + 1]) j++;
|
|
596
|
-
else break;
|
|
597
|
-
}
|
|
598
|
-
d.insert(at, ns + sj, j - sj);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
if (i < n) d.delete(os + i, n - i, ns + j);
|
|
602
|
-
if (j < m) d.insert(os + i, ns + j, m - j);
|
|
603
|
-
}
|
|
604
|
-
function smallNew(d, old, os, n, next, ns, m) {
|
|
605
|
-
const width = n + 1;
|
|
606
|
-
const dp = new Uint8Array((m + 1) * width);
|
|
607
|
-
for (let i2 = m - 1; i2 >= 0; i2--) {
|
|
608
|
-
const row = i2 * width, below = (i2 + 1) * width;
|
|
609
|
-
for (let j2 = n - 1; j2 >= 0; j2--) dp[row + j2] = next[ns + i2] === old[os + j2] ? dp[below + j2 + 1] + 1 : Math.max(dp[below + j2], dp[row + j2 + 1]);
|
|
610
|
-
}
|
|
611
|
-
const takes = (i2, j2) => next[ns + i2] === old[os + j2] && dp[i2 * width + j2] === dp[(i2 + 1) * width + j2 + 1] + 1;
|
|
612
|
-
let i = 0, j = 0;
|
|
613
|
-
while (i < m && j < n) {
|
|
614
|
-
if (takes(i, j)) {
|
|
615
|
-
const si = i, sj = j;
|
|
616
|
-
while (i < m && j < n && takes(i, j)) {
|
|
617
|
-
i++;
|
|
618
|
-
j++;
|
|
619
|
-
}
|
|
620
|
-
d.equal(os + sj, ns + si, j - sj);
|
|
621
|
-
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
622
|
-
const si = i;
|
|
623
|
-
const at = os + j;
|
|
624
|
-
while (i < m) {
|
|
625
|
-
if (j >= n) {
|
|
626
|
-
i = m;
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
if (takes(i, j)) break;
|
|
630
|
-
if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) i++;
|
|
631
|
-
else break;
|
|
632
|
-
}
|
|
633
|
-
d.insert(at, ns + si, i - si);
|
|
634
|
-
} else {
|
|
635
|
-
const sj = j;
|
|
636
|
-
const at = ns + i;
|
|
637
|
-
while (j < n) {
|
|
638
|
-
if (i >= m) {
|
|
639
|
-
j = n;
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
if (takes(i, j)) break;
|
|
643
|
-
if (dp[(i + 1) * width + j] < dp[i * width + j + 1]) j++;
|
|
644
|
-
else break;
|
|
645
|
-
}
|
|
646
|
-
d.delete(os + sj, j - sj, at);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
if (j < n) d.delete(os + j, n - j, ns + i);
|
|
650
|
-
if (i < m) d.insert(os + j, ns + i, m - i);
|
|
651
|
-
}
|
|
652
|
-
var better = (best, candidate) => best === void 0 || candidate.progress > best.progress ? candidate : best;
|
|
653
|
-
var isInterior = (o, n, oldLen, newLen) => o <= oldLen && n <= newLen && (o !== 0 || n !== 0) && (o !== oldLen || n !== newLen);
|
|
654
|
-
function clampDiagonal(oldIndex, k, oldLen, newLen) {
|
|
655
|
-
if (k < 0 && -k > newLen) return void 0;
|
|
656
|
-
const min = Math.max(k, 0);
|
|
657
|
-
const max = k >= 0 ? Math.min(oldLen, newLen + k) : Math.min(oldLen, Math.max(0, newLen + k));
|
|
658
|
-
if (min > max) return void 0;
|
|
659
|
-
const o = Math.min(Math.max(oldIndex, min), max);
|
|
660
|
-
return [o, o - k];
|
|
661
|
-
}
|
|
662
|
-
function middleSnake(old, os, oe, next, ns, ne, vf, vb, mode) {
|
|
663
|
-
const n = oe - os, m = ne - ns;
|
|
664
|
-
const delta = n - m;
|
|
665
|
-
const odd = (delta & 1) === 1 || (delta & 1) === -1;
|
|
666
|
-
vf.set(1, 0);
|
|
667
|
-
vb.set(1, 0);
|
|
668
|
-
const dMax = maxDiagonals(n, m);
|
|
669
|
-
const maxCost = mode === HEURISTIC ? Math.max(isqrt(n + m), HEURISTIC_MIN_MAX_COST) : Infinity;
|
|
670
|
-
const heuristic = (c) => ({ oldIndex: os + c.oldIndex, newIndex: ns + c.newIndex, leftMode: c.forward ? RAW : HEURISTIC, rightMode: c.forward ? HEURISTIC : RAW });
|
|
671
|
-
for (let d = 0; d < dMax; d++) {
|
|
672
|
-
let good, forward, backward;
|
|
673
|
-
const trackLimit = mode === HEURISTIC && d >= maxCost;
|
|
674
|
-
const trackGood = mode === HEURISTIC && d > HEURISTIC_MIN_COST;
|
|
675
|
-
for (let k = d; k >= -d; k -= 2) {
|
|
676
|
-
let x = k === -d || k !== d && vf.get(k - 1) < vf.get(k + 1) ? vf.get(k + 1) : vf.get(k - 1) + 1;
|
|
677
|
-
const y = x - k;
|
|
678
|
-
const x0 = x, y0 = y;
|
|
679
|
-
if (x < n && y < m) x += commonPrefixLen(old, os + x, oe, next, ns + y, ne);
|
|
680
|
-
const snake = x - x0;
|
|
681
|
-
vf.set(k, x);
|
|
682
|
-
if (odd && Math.abs(k - delta) <= d - 1 && vf.get(k) + vb.get(-(k - delta)) >= n) return { oldIndex: x0 + os, newIndex: y0 + ns, leftMode: RAW, rightMode: RAW };
|
|
683
|
-
if (trackLimit) {
|
|
684
|
-
const point = clampDiagonal(x, k, n, m);
|
|
685
|
-
if (point && isInterior(point[0], point[1], n, m)) forward = better(forward, { oldIndex: point[0], newIndex: point[1], progress: point[0] + point[1], forward: true });
|
|
686
|
-
}
|
|
687
|
-
if (trackGood && snake >= HEURISTIC_MIN_SNAKE && x < n && y < m) {
|
|
688
|
-
const progress = Math.max(0, x + y - Math.abs(k));
|
|
689
|
-
if (progress > HEURISTIC_PROGRESS_FACTOR * d && isInterior(x0, y0, n, m)) good = better(good, { oldIndex: x0, newIndex: y0, progress, forward: true });
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
for (let k = d; k >= -d; k -= 2) {
|
|
693
|
-
let x = k === -d || k !== d && vb.get(k - 1) < vb.get(k + 1) ? vb.get(k + 1) : vb.get(k - 1) + 1;
|
|
694
|
-
let y = x - k;
|
|
695
|
-
const x0 = x;
|
|
696
|
-
if (x < n && y < m) {
|
|
697
|
-
const advance = commonSuffixLen(old, os, os + n - x, next, ns, ns + m - y);
|
|
698
|
-
x += advance;
|
|
699
|
-
y += advance;
|
|
700
|
-
}
|
|
701
|
-
const snake = x - x0;
|
|
702
|
-
vb.set(k, x);
|
|
703
|
-
if (!odd && Math.abs(k - delta) <= d && vb.get(k) + vf.get(-(k - delta)) >= n) return { oldIndex: n - x + os, newIndex: m - y + ns, leftMode: RAW, rightMode: RAW };
|
|
704
|
-
if (trackLimit) {
|
|
705
|
-
const point = clampDiagonal(x, k, n, m);
|
|
706
|
-
if (point) {
|
|
707
|
-
const splitOld = n - point[0], splitNew = m - point[1];
|
|
708
|
-
if (isInterior(splitOld, splitNew, n, m)) backward = better(backward, { oldIndex: splitOld, newIndex: splitNew, progress: point[0] + point[1], forward: false });
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
if (trackGood && snake >= HEURISTIC_MIN_SNAKE && x <= n && y <= m) {
|
|
712
|
-
const splitOld = n - x, splitNew = m - y;
|
|
713
|
-
const progress = Math.max(0, x + y - Math.abs(k));
|
|
714
|
-
if (splitOld > 0 && splitNew > 0 && progress > HEURISTIC_PROGRESS_FACTOR * d) good = better(good, { oldIndex: splitOld, newIndex: splitNew, progress, forward: false });
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
if (good) return heuristic(good);
|
|
718
|
-
if (d >= maxCost) {
|
|
719
|
-
const split = forward && backward ? forward.progress > backward.progress ? forward : backward : forward ?? backward;
|
|
720
|
-
if (!split) break;
|
|
721
|
-
return heuristic(split);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
return void 0;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// src/diff.ts
|
|
728
32
|
var isSame = (r) => !r.added.length && !r.removed.length && !r.changed.length;
|
|
729
33
|
var WORD = String.raw`[\p{Alphabetic}\p{M}\p{Nd}\p{Pc}\p{Join_Control}]`;
|
|
730
34
|
var START = `(?<!${WORD})`;
|
|
731
35
|
var END = `(?!${WORD})`;
|
|
732
|
-
var FINGERPRINT = new RegExp(String.raw
|
|
36
|
+
var FINGERPRINT = new RegExp(String.raw`([.\-])([0-9A-Za-z_\-]{8})\.(css|js|mjs|map|woff2?|ttf|otf|png|jpe?g|gif|svg|webp|avif|ico|json|xml|txt|pdf|wasm)` + END, "gu");
|
|
37
|
+
var FRAMEWORK_MARKERS = new RegExp(`\\p{White_Space}data-(?:v-[0-9a-f]{8}|astro-cid-[0-9a-z]{8})(?:=(?:""|''))?(?=[\\p{White_Space}/>])|<!--\\[-->|<!--\\]-->|<!---->`, "gu");
|
|
733
38
|
var INTEGRITY = new RegExp(`\\p{White_Space}+integrity=("[^"]*"|'[^']*'|[^\\p{White_Space}>]+)`, "gu");
|
|
734
39
|
var GENERATOR = new RegExp(String.raw`SiteSquatch v\p{Nd}+\.\p{Nd}+\.\p{Nd}+[\p{Alphabetic}\p{M}\p{Nd}\p{Pc}\p{Join_Control}.+\-]*`, "gu");
|
|
735
40
|
var ID_ATTR = new RegExp(`\\p{White_Space}id=(?:"([^"]*)"|'([^']*)'|([^\\p{White_Space}>]+))`, "u");
|
|
@@ -758,7 +63,12 @@ function withoutImageIds(text) {
|
|
|
758
63
|
}
|
|
759
64
|
function withoutFingerprints(text) {
|
|
760
65
|
if (!text.includes(".")) return text;
|
|
761
|
-
return text.replace(FINGERPRINT, (whole, hash, ext) =>
|
|
66
|
+
return text.replace(FINGERPRINT, (whole, before, hash, ext) => isFingerprint(before, hash) ? `.${ext}` : whole);
|
|
67
|
+
}
|
|
68
|
+
function isFingerprint(before, hash) {
|
|
69
|
+
if (before === "." && /^[0-9a-f]{8}$/.test(hash)) return !/^(19|20)\d{6}$/.test(hash);
|
|
70
|
+
if (!/[A-Z]/.test(hash) || !/[a-z0-9]/.test(hash)) return false;
|
|
71
|
+
return before === "." || /[0-9_\-]/.test(hash);
|
|
762
72
|
}
|
|
763
73
|
var INLINE = /* @__PURE__ */ new Set(["a", "abbr", "b", "bdi", "bdo", "button", "cite", "code", "data", "dfn", "em", "i", "img", "input", "kbd", "label", "mark", "q", "s", "samp", "select", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr"]);
|
|
764
74
|
var asciiLower = (text) => text.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
@@ -782,6 +92,7 @@ function normalize(text, options) {
|
|
|
782
92
|
if (options.exact) return out;
|
|
783
93
|
out = withoutFingerprints(out);
|
|
784
94
|
out = withoutImageIds(out);
|
|
95
|
+
if (out.includes("data-") || out.includes("<!--")) out = out.replace(FRAMEWORK_MARKERS, "");
|
|
785
96
|
if (out.includes("integrity=")) out = out.replace(INTEGRITY, "");
|
|
786
97
|
if (out.includes("SiteSquatch v")) out = out.replace(GENERATOR, "SiteSquatch");
|
|
787
98
|
return out;
|
|
@@ -902,6 +213,28 @@ function attributeValue(raw) {
|
|
|
902
213
|
if (!raw.includes("&")) return raw;
|
|
903
214
|
return raw.replace(ENTITY_OR_AMP, (whole, name) => name === void 0 ? whole : name === "nbsp" ? "\xA0" : entityChar(name) ?? whole);
|
|
904
215
|
}
|
|
216
|
+
var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "poster", "cite", "data"]);
|
|
217
|
+
var UTF8 = new TextDecoder("utf-8", { fatal: true });
|
|
218
|
+
function canonicalUrl(url) {
|
|
219
|
+
if (!url.includes("%")) return url;
|
|
220
|
+
return url.replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
|
|
221
|
+
const bytes2 = Uint8Array.from(run.slice(1).split("%"), (h) => Number.parseInt(h, 16));
|
|
222
|
+
let text;
|
|
223
|
+
try {
|
|
224
|
+
text = UTF8.decode(bytes2);
|
|
225
|
+
} catch {
|
|
226
|
+
return run;
|
|
227
|
+
}
|
|
228
|
+
let out = "";
|
|
229
|
+
let at = 0;
|
|
230
|
+
for (const c of text) {
|
|
231
|
+
const n = Buffer.byteLength(c);
|
|
232
|
+
out += c.charCodeAt(0) > 127 || ' "<>`{}'.includes(c) ? c : run.slice(at * 3, (at + n) * 3);
|
|
233
|
+
at += n;
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
905
238
|
var NO_ATTRIBUTES = /^<\/?[a-z][a-z0-9-]*>$/;
|
|
906
239
|
function canonicalTag(tag, foreign, xml = false) {
|
|
907
240
|
if (NO_ATTRIBUTES.test(tag)) return [tag, false];
|
|
@@ -958,6 +291,7 @@ function canonicalTag(tag, foreign, xml = false) {
|
|
|
958
291
|
if (attrs.has(attr2)) continue;
|
|
959
292
|
if (value !== void 0 && BOOLEAN.has(attr2) && !foreign && (value === "" || asciiLower(value) === attr2)) value = void 0;
|
|
960
293
|
if (value !== void 0 && SPACED.has(attr2)) value = collapse(value).replace(/ ?, ?/g, ", ");
|
|
294
|
+
if (value !== void 0 && URL_ATTRS.has(attr2)) value = canonicalUrl(value);
|
|
961
295
|
attrs.set(attr2, value);
|
|
962
296
|
}
|
|
963
297
|
if (closing) return [`</${element}>`, false];
|
|
@@ -968,8 +302,8 @@ function canonicalTag(tag, foreign, xml = false) {
|
|
|
968
302
|
}
|
|
969
303
|
return [`${out}>`, selfClosing && (xml || foreign || element === "svg" || element === "math") && !VOID.has(element)];
|
|
970
304
|
}
|
|
971
|
-
var
|
|
972
|
-
var CLOSING = new Map([...
|
|
305
|
+
var RAW = /* @__PURE__ */ new Set(["script", "style", "pre", "textarea"]);
|
|
306
|
+
var CLOSING = new Map([...RAW].map((name) => [name, new RegExp(`</${name}`, "gi")]));
|
|
973
307
|
var startsTag = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 47 || c === 33 || c === 63;
|
|
974
308
|
function tokens(html, xml = false) {
|
|
975
309
|
const out = [];
|
|
@@ -1013,7 +347,7 @@ function tokens(html, xml = false) {
|
|
|
1013
347
|
if (closes) out.push({ tag: true, text: `</${text.slice(1, text.search(/[ >]/))}>` });
|
|
1014
348
|
i += end;
|
|
1015
349
|
textStart = i;
|
|
1016
|
-
if (
|
|
350
|
+
if (RAW.has(name) && !tag.endsWith("/>")) {
|
|
1017
351
|
const closing = CLOSING.get(name);
|
|
1018
352
|
closing.lastIndex = i;
|
|
1019
353
|
const found = closing.exec(html);
|
|
@@ -1168,7 +502,7 @@ var decode = (data) => {
|
|
|
1168
502
|
};
|
|
1169
503
|
function comparePair(a, b, pair, options) {
|
|
1170
504
|
if (a.equals(b)) return void 0;
|
|
1171
|
-
const
|
|
505
|
+
const diff = {
|
|
1172
506
|
path: pair.key,
|
|
1173
507
|
url: urlOf(pair.key),
|
|
1174
508
|
renamed: pair.before !== pair.after ? [pair.before, pair.after] : void 0,
|
|
@@ -1185,31 +519,31 @@ function comparePair(a, b, pair, options) {
|
|
|
1185
519
|
ownLines: 0
|
|
1186
520
|
};
|
|
1187
521
|
const textA = decode(a), textB = decode(b);
|
|
1188
|
-
if (textA === void 0 || textB === void 0) return
|
|
522
|
+
if (textA === void 0 || textB === void 0) return diff;
|
|
1189
523
|
const before = normalize(textA, options), after = normalize(textB, options);
|
|
1190
524
|
if (before === after) return void 0;
|
|
1191
525
|
let found;
|
|
1192
526
|
if (isPage(pair.key) && !options.exact) {
|
|
1193
|
-
|
|
527
|
+
diff.kind = "page";
|
|
1194
528
|
const ta = tokens(before), tb = tokens(after);
|
|
1195
529
|
const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text, headingAbove(ta));
|
|
1196
530
|
if (!list.length) return void 0;
|
|
1197
531
|
const isTag = ([first, i]) => (first ? ta[i] : tb[i]).tag;
|
|
1198
|
-
if (changed.some((c) => !isTag(c)))
|
|
1199
|
-
if (changed.some(isTag))
|
|
532
|
+
if (changed.some((c) => !isTag(c))) diff.what.push("text");
|
|
533
|
+
if (changed.some(isTag)) diff.what.push("markup");
|
|
1200
534
|
const [old, now] = [title(ta), title(tb)];
|
|
1201
|
-
if (old !== void 0 && now !== void 0 && old !== now)
|
|
535
|
+
if (old !== void 0 && now !== void 0 && old !== now) diff.notes.push(`title: ${quoted(old)} -> ${quoted(now)}`);
|
|
1202
536
|
const kept2 = new Set(ids(tb));
|
|
1203
537
|
const gone = ids(ta).filter((id) => !kept2.has(id)).map((id) => `#${id}`);
|
|
1204
|
-
if (gone.length)
|
|
538
|
+
if (gone.length) diff.notes.push(`ids removed (links to them break): ${gone.slice(0, 8).join(", ")}${gone.length > 8 ? ` and ${gone.length - 8} more` : ""}`);
|
|
1205
539
|
const [wa, wb] = [wayfinding(ta), wayfinding(tb)];
|
|
1206
|
-
if (wa.canonical !== wb.canonical)
|
|
1207
|
-
if (wa.redirect !== wb.redirect)
|
|
1208
|
-
|
|
1209
|
-
if (
|
|
540
|
+
if (wa.canonical !== wb.canonical) diff.notes.push(`canonical link: ${wa.canonical ?? "none"} -> ${wb.canonical ?? "none"}`);
|
|
541
|
+
if (wa.redirect !== wb.redirect) diff.notes.push(`redirects to: ${wa.redirect ?? "nowhere"} -> ${wb.redirect ?? "nowhere"}`);
|
|
542
|
+
diff.onlyDates = onlyDates(list);
|
|
543
|
+
if (diff.onlyDates) diff.notes.push(`only dates changed (${diff.onlyDates[0]} -> ${diff.onlyDates[1]})`);
|
|
1210
544
|
found = list;
|
|
1211
545
|
} else if (isXml(pair.key) && !options.exact) {
|
|
1212
|
-
|
|
546
|
+
diff.kind = "text";
|
|
1213
547
|
const ta = tokens(xmlWithMarkup(before), true), tb = tokens(xmlWithMarkup(after), true);
|
|
1214
548
|
found = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text)[0];
|
|
1215
549
|
if (!found.length) return void 0;
|
|
@@ -1218,26 +552,26 @@ function comparePair(a, b, pair, options) {
|
|
|
1218
552
|
const kept2 = new Set(eb), had = new Set(ea);
|
|
1219
553
|
const gone = ea.filter((e) => !kept2.has(e)), came = eb.filter((e) => !had.has(e));
|
|
1220
554
|
const some = (list) => `${list.slice(0, 3).join(", ")}${list.length > 3 ? ` and ${list.length - 3} more` : ""}`;
|
|
1221
|
-
if (gone.length)
|
|
1222
|
-
if (came.length)
|
|
555
|
+
if (gone.length) diff.notes.push(`feed entries removed (readers see them go): ${some(gone)}`);
|
|
556
|
+
if (came.length) diff.notes.push(`feed entries added (readers see them as new): ${some(came)}`);
|
|
1223
557
|
}
|
|
1224
|
-
|
|
1225
|
-
if (
|
|
558
|
+
diff.onlyDates = onlyDates(found);
|
|
559
|
+
if (diff.onlyDates) diff.notes.push(`only dates changed (${diff.onlyDates[0]} -> ${diff.onlyDates[1]})`);
|
|
1226
560
|
} else {
|
|
1227
|
-
|
|
561
|
+
diff.kind = isPage(pair.key) ? "page" : "text";
|
|
1228
562
|
const la = lines(before), lb = lines(after);
|
|
1229
563
|
found = hunks(la, lb, () => 0, (l) => l)[0];
|
|
1230
564
|
if (!found.length) found = [{ removed: [`(${Buffer.byteLength(before)} bytes)`], added: [`(${Buffer.byteLength(after)} bytes)`] }];
|
|
1231
565
|
else if (!isPage(pair.key)) {
|
|
1232
|
-
|
|
1233
|
-
if (
|
|
566
|
+
diff.onlyDates = onlyDates(found);
|
|
567
|
+
if (diff.onlyDates) diff.notes.push(`only dates changed (${diff.onlyDates[0]} -> ${diff.onlyDates[1]})`);
|
|
1234
568
|
}
|
|
1235
569
|
}
|
|
1236
|
-
if (!
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
return
|
|
570
|
+
if (!diff.onlyDates && sameLines(found)) diff.notes.push("the same lines, in another order");
|
|
571
|
+
diff.allHunks = found;
|
|
572
|
+
diff.changedLines = found.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
|
|
573
|
+
diff.hunks = firstLines(found, options.lines);
|
|
574
|
+
return diff;
|
|
1241
575
|
}
|
|
1242
576
|
async function linkTarget(file) {
|
|
1243
577
|
try {
|
|
@@ -1451,7 +785,8 @@ function groupChanges(changed) {
|
|
|
1451
785
|
const number = new Map(order.map((old, i) => [old, i]));
|
|
1452
786
|
const groups = order.map((i) => {
|
|
1453
787
|
const d = drafts[i];
|
|
1454
|
-
|
|
788
|
+
const known = knownChange(d.hunk);
|
|
789
|
+
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, ...known ? { known } : {} };
|
|
1455
790
|
});
|
|
1456
791
|
for (const f of changed) {
|
|
1457
792
|
const at = placed.get(f);
|
|
@@ -1493,7 +828,7 @@ function onlyDates(list) {
|
|
|
1493
828
|
}
|
|
1494
829
|
return first;
|
|
1495
830
|
}
|
|
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";
|
|
831
|
+
var IGNORING = "Ignoring asset fingerprints, image ids, integrity hashes, the generator's version, Vue's and Astro's scope ids and fragment markers, whitespace between tags, and how tags are written where browsers read them the same (attribute order, quotes, entities, percent-encoding in URLs, `<br/>`) (--exact compares bytes).\n";
|
|
1497
832
|
var IMAGES_LISTED = 5;
|
|
1498
833
|
function listed(urls, sign) {
|
|
1499
834
|
const images = urls.filter(isHashedImage);
|
|
@@ -1505,10 +840,22 @@ function listed(urls, sign) {
|
|
|
1505
840
|
`);
|
|
1506
841
|
return out;
|
|
1507
842
|
}
|
|
1508
|
-
function clip(line) {
|
|
843
|
+
function clip(line, at = 0) {
|
|
1509
844
|
const MAX = 200;
|
|
1510
|
-
const
|
|
1511
|
-
|
|
845
|
+
const chars = Array.from(line);
|
|
846
|
+
const n = chars.length;
|
|
847
|
+
if (n <= MAX) return line;
|
|
848
|
+
const from = at > 60 ? Math.min(at - 40, n - MAX) : 0;
|
|
849
|
+
if (from <= 0) return `${firstChars(line, MAX)}\u2026 (${n - MAX} more characters)`;
|
|
850
|
+
const rest = n - from - MAX;
|
|
851
|
+
return `(from character ${count(from + 1)}) \u2026${chars.slice(from, from + MAX).join("")}${rest > 0 ? `\u2026 (${count(rest)} more characters)` : ""}`;
|
|
852
|
+
}
|
|
853
|
+
function firstDifference(a, b) {
|
|
854
|
+
if (a === void 0 || b === void 0) return 0;
|
|
855
|
+
const x = Array.from(a), y = Array.from(b);
|
|
856
|
+
let i = 0;
|
|
857
|
+
while (i < x.length && i < y.length && x[i] === y[i]) i++;
|
|
858
|
+
return i;
|
|
1512
859
|
}
|
|
1513
860
|
var plural = (n, one, many) => `${count(n)} ${n === 1 ? one : many}`;
|
|
1514
861
|
function linesText(hunks2, total, limit, paint, indent = " ") {
|
|
@@ -1519,10 +866,11 @@ function linesText(hunks2, total, limit, paint, indent = " ") {
|
|
|
1519
866
|
if (hunk.at !== void 0 && hunk.at !== place && !(limit > 0 && shown >= limit)) text += paint("2", `${indent}@ under ${hunk.at}
|
|
1520
867
|
`);
|
|
1521
868
|
place = hunk.at;
|
|
869
|
+
const at = hunk.removed.length === 1 && hunk.added.length === 1 ? firstDifference(hunk.removed[0], hunk.added[0]) : 0;
|
|
1522
870
|
for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
|
|
1523
871
|
for (const line of side) {
|
|
1524
872
|
if (limit > 0 && shown >= limit) break done;
|
|
1525
|
-
text += paint(code, `${indent}${sign} ${clip(line)}
|
|
873
|
+
text += paint(code, `${indent}${sign} ${clip(line, at)}
|
|
1526
874
|
`);
|
|
1527
875
|
shown += 1;
|
|
1528
876
|
}
|
|
@@ -1533,6 +881,16 @@ function linesText(hunks2, total, limit, paint, indent = " ") {
|
|
|
1533
881
|
return text;
|
|
1534
882
|
}
|
|
1535
883
|
var isPageUrl = (url) => url.endsWith("/") || isPage(url);
|
|
884
|
+
function knownChange(hunk) {
|
|
885
|
+
const removed = hunk.removed.join("\n");
|
|
886
|
+
const added = hunk.added.join("\n");
|
|
887
|
+
if (/__VP_HASH_MAP__|__VP_SITE_DATA__|\/assets\/chunks\/|\/assets\/app\.[\w-]+\.js/.test(removed) && !/__VP_/.test(added)) return "VitePress's client app: the scripts and preloads it puts in each page, to run the page in the browser. ssqch writes the HTML alone";
|
|
888
|
+
if (/<astro-island\b|\/_astro\/[\w.-]+\.js/.test(removed) && !/<astro-island\b/.test(added)) return "Astro's islands and scripts, which run the page's components in the browser. ssqch writes the HTML alone";
|
|
889
|
+
if (/__NEXT_DATA__|\/_next\/static\//.test(removed)) return "Next.js's client app: its scripts and page data. ssqch writes the HTML alone";
|
|
890
|
+
if (/___gatsby|\/page-data\/|webpack-runtime-/.test(removed)) return "Gatsby's client app: its scripts and page data. ssqch writes the HTML alone";
|
|
891
|
+
if (/style="(?:color:#|--shiki-)|class="shiki\b/.test(removed) && /class="(?:hl-|token |highlight)/.test(added)) return "Shiki's inline colors, where ssqch's highlighter writes classes (its stylesheet colors them): the code's text is the same";
|
|
892
|
+
return void 0;
|
|
893
|
+
}
|
|
1536
894
|
function groupsText(groups, limit, paint, heading) {
|
|
1537
895
|
let out = ` ${heading}, the most files first (--ungrouped lists each file with all of it):
|
|
1538
896
|
`;
|
|
@@ -1542,6 +900,8 @@ function groupsText(groups, limit, paint, heading) {
|
|
|
1542
900
|
const some = group.urls.slice(0, 3).join(", ");
|
|
1543
901
|
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
902
|
out += ` ~ ${count(n)} ${what}${alike}: ${some}${n > 3 ? ` and ${count(n - 3)} more` : ""}
|
|
903
|
+
`;
|
|
904
|
+
if (group.known) out += ` expected in a move: ${group.known}
|
|
1545
905
|
`;
|
|
1546
906
|
out += linesText([group.hunk], group.hunk.removed.length + group.hunk.added.length, limit, paint);
|
|
1547
907
|
}
|
|
@@ -1639,7 +999,7 @@ function diffJson(report, limit) {
|
|
|
1639
999
|
removed: report.removed,
|
|
1640
1000
|
changed,
|
|
1641
1001
|
// 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 }))
|
|
1002
|
+
groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk, ...g.known ? { known: g.known } : {} }))
|
|
1643
1003
|
};
|
|
1644
1004
|
}
|
|
1645
1005
|
async function compareRuns(dirs, options) {
|
|
@@ -1747,13 +1107,13 @@ Varies (${report.varies.length})
|
|
|
1747
1107
|
out += grouped ? linesText(sample.ownHunks, sample.ownLines, limit, paint) : linesText(sample.hunks, sample.changedLines, limit, paint);
|
|
1748
1108
|
}
|
|
1749
1109
|
out += `
|
|
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.
|
|
1110
|
+
${ACCOUNTS_DIFFER} ${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
1111
|
`;
|
|
1752
1112
|
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.
|
|
1113
|
+
if (common > 0 && report.varies.some((v) => v.versions[0].runs.length >= 2)) 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
1114
|
`;
|
|
1755
1115
|
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.
|
|
1116
|
+
if (unsettled) out += `${unsettled === 1 ? "1 file has" : `${unsettled} files have`} no most common version: each build has its own. ${report.runs.length < 20 ? "More builds (--runs 20) show whether one is usual." : `With ${report.runs.length} builds, more won't find one: something writes ${unsettled === 1 ? "it" : "them"} differently each time (a tool's output order, a time). Pin that, or leave ${unsettled === 1 ? "it" : "them"} out with --ignore or --only.`}
|
|
1757
1117
|
`;
|
|
1758
1118
|
return out;
|
|
1759
1119
|
}
|
|
@@ -1777,7 +1137,7 @@ function runsJson(report, limit) {
|
|
|
1777
1137
|
groups: f.sample?.groups ?? []
|
|
1778
1138
|
})),
|
|
1779
1139
|
// 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 }))
|
|
1140
|
+
groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk, ...g.known ? { known: g.known } : {} }))
|
|
1781
1141
|
};
|
|
1782
1142
|
}
|
|
1783
1143
|
|
|
@@ -1788,10 +1148,12 @@ export {
|
|
|
1788
1148
|
withoutFingerprints,
|
|
1789
1149
|
keyed,
|
|
1790
1150
|
canonicalText,
|
|
1151
|
+
canonicalUrl,
|
|
1791
1152
|
canonicalTag,
|
|
1792
1153
|
tokens,
|
|
1793
1154
|
compare,
|
|
1794
1155
|
groupChanges,
|
|
1156
|
+
knownChange,
|
|
1795
1157
|
diffText,
|
|
1796
1158
|
diffJson,
|
|
1797
1159
|
compareRuns,
|