@farming-labs/theme 0.0.27 → 0.0.28

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 (60) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -26
  2. package/dist/ai-search-dialog.mjs +1 -1
  3. package/dist/code-block-copy-wrapper.d.mts +1 -1
  4. package/dist/docs-layout.d.mts +1 -1
  5. package/dist/docs-layout.mjs +4 -4
  6. package/dist/docs-page-client.mjs +2 -2
  7. package/dist/index.mjs +1 -1
  8. package/dist/mdx.d.mts +1 -1
  9. package/dist/mdx.mjs +1 -1
  10. package/dist/page-actions.mjs +1 -1
  11. package/package.json +2 -2
  12. package/dist/get-app-dir.d.mts +0 -9
  13. package/dist/get-app-dir.test.d.mts +0 -1
  14. package/dist/get-app-dir.test.mjs +0 -41
  15. package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -77
  16. package/dist/node_modules/.pnpm/@vitest_expect@3.2.4/node_modules/@vitest/expect/dist/index.mjs +0 -1356
  17. package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.mjs +0 -1119
  18. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.mjs +0 -1091
  19. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/index.mjs +0 -4
  20. package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/utils.mjs +0 -3
  21. package/dist/node_modules/.pnpm/@vitest_snapshot@3.2.4/node_modules/@vitest/snapshot/dist/index.mjs +0 -1821
  22. package/dist/node_modules/.pnpm/@vitest_spy@3.2.4/node_modules/@vitest/spy/dist/index.mjs +0 -171
  23. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -124
  24. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/diff.mjs +0 -1334
  25. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/error.mjs +0 -105
  26. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.mjs +0 -118
  27. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.mjs +0 -455
  28. package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.mjs +0 -168
  29. package/dist/node_modules/.pnpm/chai@5.3.3/node_modules/chai/index.mjs +0 -3087
  30. package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.mjs +0 -384
  31. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.mjs +0 -11
  32. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.mjs +0 -16
  33. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.mjs +0 -11
  34. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.mjs +0 -15
  35. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.mjs +0 -13
  36. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.mjs +0 -34
  37. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.mjs +0 -12
  38. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.mjs +0 -122
  39. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.mjs +0 -39
  40. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.mjs +0 -99
  41. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.mjs +0 -25
  42. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.mjs +0 -14
  43. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.mjs +0 -21
  44. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.mjs +0 -5
  45. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.mjs +0 -12
  46. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.mjs +0 -18
  47. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.mjs +0 -25
  48. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.mjs +0 -8
  49. package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.mjs +0 -30
  50. package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -939
  51. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -81
  52. package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.mjs +0 -51
  53. package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.mjs +0 -81
  54. package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.mjs +0 -9
  55. package/dist/node_modules/.pnpm/tinyspy@4.0.4/node_modules/tinyspy/dist/index.mjs +0 -125
  56. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.mjs +0 -8
  57. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -50
  58. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/utils.XdZDrNZV.mjs +0 -48
  59. package/dist/node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@22.19.11_jiti@2.6.1_lightningcss@1.30.2_terser@5.46.0_yaml@2.8.2/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.mjs +0 -2613
  60. package/dist/serialize-icon.d.mts +0 -4
@@ -1,1334 +0,0 @@
1
- import { u } from "../../../../../tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.mjs";
2
- import { format, plugins } from "../../../../../@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.mjs";
3
- import "../../../../../loupe@3.2.1/node_modules/loupe/lib/index.mjs";
4
- import { getDefaultExportFromCjs, stringify } from "./chunk-_commonjsHelpers.mjs";
5
- import { deepClone, getOwnProperties, getType as getType$1 } from "./helpers.mjs";
6
-
7
- //#region ../../node_modules/.pnpm/@vitest+utils@3.2.4/node_modules/@vitest/utils/dist/diff.js
8
- /**
9
- * Diff Match and Patch
10
- * Copyright 2018 The diff-match-patch Authors.
11
- * https://github.com/google/diff-match-patch
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- /**
26
- * @fileoverview Computes the difference between two texts to create a patch.
27
- * Applies the patch onto another text, allowing for errors.
28
- * @author fraser@google.com (Neil Fraser)
29
- */
30
- /**
31
- * CHANGES by pedrottimark to diff_match_patch_uncompressed.ts file:
32
- *
33
- * 1. Delete anything not needed to use diff_cleanupSemantic method
34
- * 2. Convert from prototype properties to var declarations
35
- * 3. Convert Diff to class from constructor and prototype
36
- * 4. Add type annotations for arguments and return values
37
- * 5. Add exports
38
- */
39
- /**
40
- * The data structure representing a diff is an array of tuples:
41
- * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
42
- * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
43
- */
44
- const DIFF_DELETE = -1;
45
- const DIFF_INSERT = 1;
46
- const DIFF_EQUAL = 0;
47
- /**
48
- * Class representing one diff tuple.
49
- * Attempts to look like a two-element array (which is what this used to be).
50
- * @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.
51
- * @param {string} text Text to be deleted, inserted, or retained.
52
- * @constructor
53
- */
54
- var Diff = class {
55
- 0;
56
- 1;
57
- constructor(op, text) {
58
- this[0] = op;
59
- this[1] = text;
60
- }
61
- };
62
- /**
63
- * Determine the common prefix of two strings.
64
- * @param {string} text1 First string.
65
- * @param {string} text2 Second string.
66
- * @return {number} The number of characters common to the start of each
67
- * string.
68
- */
69
- function diff_commonPrefix(text1, text2) {
70
- if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) return 0;
71
- let pointermin = 0;
72
- let pointermax = Math.min(text1.length, text2.length);
73
- let pointermid = pointermax;
74
- let pointerstart = 0;
75
- while (pointermin < pointermid) {
76
- if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
77
- pointermin = pointermid;
78
- pointerstart = pointermin;
79
- } else pointermax = pointermid;
80
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
81
- }
82
- return pointermid;
83
- }
84
- /**
85
- * Determine the common suffix of two strings.
86
- * @param {string} text1 First string.
87
- * @param {string} text2 Second string.
88
- * @return {number} The number of characters common to the end of each string.
89
- */
90
- function diff_commonSuffix(text1, text2) {
91
- if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) return 0;
92
- let pointermin = 0;
93
- let pointermax = Math.min(text1.length, text2.length);
94
- let pointermid = pointermax;
95
- let pointerend = 0;
96
- while (pointermin < pointermid) {
97
- if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
98
- pointermin = pointermid;
99
- pointerend = pointermin;
100
- } else pointermax = pointermid;
101
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
102
- }
103
- return pointermid;
104
- }
105
- /**
106
- * Determine if the suffix of one string is the prefix of another.
107
- * @param {string} text1 First string.
108
- * @param {string} text2 Second string.
109
- * @return {number} The number of characters common to the end of the first
110
- * string and the start of the second string.
111
- * @private
112
- */
113
- function diff_commonOverlap_(text1, text2) {
114
- const text1_length = text1.length;
115
- const text2_length = text2.length;
116
- if (text1_length === 0 || text2_length === 0) return 0;
117
- if (text1_length > text2_length) text1 = text1.substring(text1_length - text2_length);
118
- else if (text1_length < text2_length) text2 = text2.substring(0, text1_length);
119
- const text_length = Math.min(text1_length, text2_length);
120
- if (text1 === text2) return text_length;
121
- let best = 0;
122
- let length = 1;
123
- while (true) {
124
- const pattern = text1.substring(text_length - length);
125
- const found = text2.indexOf(pattern);
126
- if (found === -1) return best;
127
- length += found;
128
- if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
129
- best = length;
130
- length++;
131
- }
132
- }
133
- }
134
- /**
135
- * Reduce the number of edits by eliminating semantically trivial equalities.
136
- * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
137
- */
138
- function diff_cleanupSemantic(diffs) {
139
- let changes = false;
140
- const equalities = [];
141
- let equalitiesLength = 0;
142
- /** @type {?string} */
143
- let lastEquality = null;
144
- let pointer = 0;
145
- let length_insertions1 = 0;
146
- let length_deletions1 = 0;
147
- let length_insertions2 = 0;
148
- let length_deletions2 = 0;
149
- while (pointer < diffs.length) {
150
- if (diffs[pointer][0] === DIFF_EQUAL) {
151
- equalities[equalitiesLength++] = pointer;
152
- length_insertions1 = length_insertions2;
153
- length_deletions1 = length_deletions2;
154
- length_insertions2 = 0;
155
- length_deletions2 = 0;
156
- lastEquality = diffs[pointer][1];
157
- } else {
158
- if (diffs[pointer][0] === DIFF_INSERT) length_insertions2 += diffs[pointer][1].length;
159
- else length_deletions2 += diffs[pointer][1].length;
160
- if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
161
- diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
162
- diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
163
- equalitiesLength--;
164
- equalitiesLength--;
165
- pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
166
- length_insertions1 = 0;
167
- length_deletions1 = 0;
168
- length_insertions2 = 0;
169
- length_deletions2 = 0;
170
- lastEquality = null;
171
- changes = true;
172
- }
173
- }
174
- pointer++;
175
- }
176
- if (changes) diff_cleanupMerge(diffs);
177
- diff_cleanupSemanticLossless(diffs);
178
- pointer = 1;
179
- while (pointer < diffs.length) {
180
- if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
181
- const deletion = diffs[pointer - 1][1];
182
- const insertion = diffs[pointer][1];
183
- const overlap_length1 = diff_commonOverlap_(deletion, insertion);
184
- const overlap_length2 = diff_commonOverlap_(insertion, deletion);
185
- if (overlap_length1 >= overlap_length2) {
186
- if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
187
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
188
- diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
189
- diffs[pointer + 1][1] = insertion.substring(overlap_length1);
190
- pointer++;
191
- }
192
- } else if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
193
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
194
- diffs[pointer - 1][0] = DIFF_INSERT;
195
- diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
196
- diffs[pointer + 1][0] = DIFF_DELETE;
197
- diffs[pointer + 1][1] = deletion.substring(overlap_length2);
198
- pointer++;
199
- }
200
- pointer++;
201
- }
202
- pointer++;
203
- }
204
- }
205
- const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
206
- const whitespaceRegex_ = /\s/;
207
- const linebreakRegex_ = /[\r\n]/;
208
- const blanklineEndRegex_ = /\n\r?\n$/;
209
- const blanklineStartRegex_ = /^\r?\n\r?\n/;
210
- /**
211
- * Look for single edits surrounded on both sides by equalities
212
- * which can be shifted sideways to align the edit to a word boundary.
213
- * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
214
- * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
215
- */
216
- function diff_cleanupSemanticLossless(diffs) {
217
- let pointer = 1;
218
- while (pointer < diffs.length - 1) {
219
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
220
- let equality1 = diffs[pointer - 1][1];
221
- let edit = diffs[pointer][1];
222
- let equality2 = diffs[pointer + 1][1];
223
- const commonOffset = diff_commonSuffix(equality1, edit);
224
- if (commonOffset) {
225
- const commonString = edit.substring(edit.length - commonOffset);
226
- equality1 = equality1.substring(0, equality1.length - commonOffset);
227
- edit = commonString + edit.substring(0, edit.length - commonOffset);
228
- equality2 = commonString + equality2;
229
- }
230
- let bestEquality1 = equality1;
231
- let bestEdit = edit;
232
- let bestEquality2 = equality2;
233
- let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
234
- while (edit.charAt(0) === equality2.charAt(0)) {
235
- equality1 += edit.charAt(0);
236
- edit = edit.substring(1) + equality2.charAt(0);
237
- equality2 = equality2.substring(1);
238
- const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
239
- if (score >= bestScore) {
240
- bestScore = score;
241
- bestEquality1 = equality1;
242
- bestEdit = edit;
243
- bestEquality2 = equality2;
244
- }
245
- }
246
- if (diffs[pointer - 1][1] !== bestEquality1) {
247
- if (bestEquality1) diffs[pointer - 1][1] = bestEquality1;
248
- else {
249
- diffs.splice(pointer - 1, 1);
250
- pointer--;
251
- }
252
- diffs[pointer][1] = bestEdit;
253
- if (bestEquality2) diffs[pointer + 1][1] = bestEquality2;
254
- else {
255
- diffs.splice(pointer + 1, 1);
256
- pointer--;
257
- }
258
- }
259
- }
260
- pointer++;
261
- }
262
- }
263
- /**
264
- * Reorder and merge like edit sections. Merge equalities.
265
- * Any edit section can move as long as it doesn't cross an equality.
266
- * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
267
- */
268
- function diff_cleanupMerge(diffs) {
269
- diffs.push(new Diff(DIFF_EQUAL, ""));
270
- let pointer = 0;
271
- let count_delete = 0;
272
- let count_insert = 0;
273
- let text_delete = "";
274
- let text_insert = "";
275
- let commonlength;
276
- while (pointer < diffs.length) switch (diffs[pointer][0]) {
277
- case DIFF_INSERT:
278
- count_insert++;
279
- text_insert += diffs[pointer][1];
280
- pointer++;
281
- break;
282
- case DIFF_DELETE:
283
- count_delete++;
284
- text_delete += diffs[pointer][1];
285
- pointer++;
286
- break;
287
- case DIFF_EQUAL:
288
- if (count_delete + count_insert > 1) {
289
- if (count_delete !== 0 && count_insert !== 0) {
290
- commonlength = diff_commonPrefix(text_insert, text_delete);
291
- if (commonlength !== 0) {
292
- if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
293
- else {
294
- diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
295
- pointer++;
296
- }
297
- text_insert = text_insert.substring(commonlength);
298
- text_delete = text_delete.substring(commonlength);
299
- }
300
- commonlength = diff_commonSuffix(text_insert, text_delete);
301
- if (commonlength !== 0) {
302
- diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
303
- text_insert = text_insert.substring(0, text_insert.length - commonlength);
304
- text_delete = text_delete.substring(0, text_delete.length - commonlength);
305
- }
306
- }
307
- pointer -= count_delete + count_insert;
308
- diffs.splice(pointer, count_delete + count_insert);
309
- if (text_delete.length) {
310
- diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
311
- pointer++;
312
- }
313
- if (text_insert.length) {
314
- diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
315
- pointer++;
316
- }
317
- pointer++;
318
- } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
319
- diffs[pointer - 1][1] += diffs[pointer][1];
320
- diffs.splice(pointer, 1);
321
- } else pointer++;
322
- count_insert = 0;
323
- count_delete = 0;
324
- text_delete = "";
325
- text_insert = "";
326
- break;
327
- }
328
- if (diffs[diffs.length - 1][1] === "") diffs.pop();
329
- let changes = false;
330
- pointer = 1;
331
- while (pointer < diffs.length - 1) {
332
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
333
- if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
334
- diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
335
- diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
336
- diffs.splice(pointer - 1, 1);
337
- changes = true;
338
- } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
339
- diffs[pointer - 1][1] += diffs[pointer + 1][1];
340
- diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
341
- diffs.splice(pointer + 1, 1);
342
- changes = true;
343
- }
344
- }
345
- pointer++;
346
- }
347
- if (changes) diff_cleanupMerge(diffs);
348
- }
349
- /**
350
- * Given two strings, compute a score representing whether the internal
351
- * boundary falls on logical boundaries.
352
- * Scores range from 6 (best) to 0 (worst).
353
- * Closure, but does not reference any external variables.
354
- * @param {string} one First string.
355
- * @param {string} two Second string.
356
- * @return {number} The score.
357
- * @private
358
- */
359
- function diff_cleanupSemanticScore_(one, two) {
360
- if (!one || !two) return 6;
361
- const char1 = one.charAt(one.length - 1);
362
- const char2 = two.charAt(0);
363
- const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
364
- const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
365
- const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
366
- const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
367
- const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
368
- const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
369
- const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
370
- const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
371
- if (blankLine1 || blankLine2) return 5;
372
- else if (lineBreak1 || lineBreak2) return 4;
373
- else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) return 3;
374
- else if (whitespace1 || whitespace2) return 2;
375
- else if (nonAlphaNumeric1 || nonAlphaNumeric2) return 1;
376
- return 0;
377
- }
378
- /**
379
- * Copyright (c) Meta Platforms, Inc. and affiliates.
380
- *
381
- * This source code is licensed under the MIT license found in the
382
- * LICENSE file in the root directory of this source tree.
383
- */
384
- const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
385
- const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\nPrinting internal object structure without calling `toJSON` instead.";
386
- var build = {};
387
- var hasRequiredBuild;
388
- function requireBuild() {
389
- if (hasRequiredBuild) return build;
390
- hasRequiredBuild = 1;
391
- Object.defineProperty(build, "__esModule", { value: true });
392
- build.default = diffSequence;
393
- /**
394
- * Copyright (c) Meta Platforms, Inc. and affiliates.
395
- *
396
- * This source code is licensed under the MIT license found in the
397
- * LICENSE file in the root directory of this source tree.
398
- *
399
- */
400
- const pkg = "diff-sequences";
401
- const NOT_YET_SET = 0;
402
- const countCommonItemsF = (aIndex, aEnd, bIndex, bEnd, isCommon) => {
403
- let nCommon = 0;
404
- while (aIndex < aEnd && bIndex < bEnd && isCommon(aIndex, bIndex)) {
405
- aIndex += 1;
406
- bIndex += 1;
407
- nCommon += 1;
408
- }
409
- return nCommon;
410
- };
411
- const countCommonItemsR = (aStart, aIndex, bStart, bIndex, isCommon) => {
412
- let nCommon = 0;
413
- while (aStart <= aIndex && bStart <= bIndex && isCommon(aIndex, bIndex)) {
414
- aIndex -= 1;
415
- bIndex -= 1;
416
- nCommon += 1;
417
- }
418
- return nCommon;
419
- };
420
- const extendPathsF = (d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF) => {
421
- let iF = 0;
422
- let kF = -d;
423
- let aFirst = aIndexesF[iF];
424
- let aIndexPrev1 = aFirst;
425
- aIndexesF[iF] += countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
426
- const nF = d < iMaxF ? d : iMaxF;
427
- for (iF += 1, kF += 2; iF <= nF; iF += 1, kF += 2) {
428
- if (iF !== d && aIndexPrev1 < aIndexesF[iF]) aFirst = aIndexesF[iF];
429
- else {
430
- aFirst = aIndexPrev1 + 1;
431
- if (aEnd <= aFirst) return iF - 1;
432
- }
433
- aIndexPrev1 = aIndexesF[iF];
434
- aIndexesF[iF] = aFirst + countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
435
- }
436
- return iMaxF;
437
- };
438
- const extendPathsR = (d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR) => {
439
- let iR = 0;
440
- let kR = d;
441
- let aFirst = aIndexesR[iR];
442
- let aIndexPrev1 = aFirst;
443
- aIndexesR[iR] -= countCommonItemsR(aStart, aFirst - 1, bStart, bR + aFirst - kR - 1, isCommon);
444
- const nR = d < iMaxR ? d : iMaxR;
445
- for (iR += 1, kR -= 2; iR <= nR; iR += 1, kR -= 2) {
446
- if (iR !== d && aIndexesR[iR] < aIndexPrev1) aFirst = aIndexesR[iR];
447
- else {
448
- aFirst = aIndexPrev1 - 1;
449
- if (aFirst < aStart) return iR - 1;
450
- }
451
- aIndexPrev1 = aIndexesR[iR];
452
- aIndexesR[iR] = aFirst - countCommonItemsR(aStart, aFirst - 1, bStart, bR + aFirst - kR - 1, isCommon);
453
- }
454
- return iMaxR;
455
- };
456
- const extendOverlappablePathsF = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
457
- const bF = bStart - aStart;
458
- const aLength = aEnd - aStart;
459
- const baDeltaLength = bEnd - bStart - aLength;
460
- const kMinOverlapF = -baDeltaLength - (d - 1);
461
- const kMaxOverlapF = -baDeltaLength + (d - 1);
462
- let aIndexPrev1 = NOT_YET_SET;
463
- const nF = d < iMaxF ? d : iMaxF;
464
- for (let iF = 0, kF = -d; iF <= nF; iF += 1, kF += 2) {
465
- const insert = iF === 0 || iF !== d && aIndexPrev1 < aIndexesF[iF];
466
- const aLastPrev = insert ? aIndexesF[iF] : aIndexPrev1;
467
- const aFirst = insert ? aLastPrev : aLastPrev + 1;
468
- const bFirst = bF + aFirst - kF;
469
- const nCommonF = countCommonItemsF(aFirst + 1, aEnd, bFirst + 1, bEnd, isCommon);
470
- const aLast = aFirst + nCommonF;
471
- aIndexPrev1 = aIndexesF[iF];
472
- aIndexesF[iF] = aLast;
473
- if (kMinOverlapF <= kF && kF <= kMaxOverlapF) {
474
- const iR = (d - 1 - (kF + baDeltaLength)) / 2;
475
- if (iR <= iMaxR && aIndexesR[iR] - 1 <= aLast) {
476
- const bLastPrev = bF + aLastPrev - (insert ? kF + 1 : kF - 1);
477
- const nCommonR = countCommonItemsR(aStart, aLastPrev, bStart, bLastPrev, isCommon);
478
- const aIndexPrevFirst = aLastPrev - nCommonR;
479
- const bIndexPrevFirst = bLastPrev - nCommonR;
480
- const aEndPreceding = aIndexPrevFirst + 1;
481
- const bEndPreceding = bIndexPrevFirst + 1;
482
- division.nChangePreceding = d - 1;
483
- if (d - 1 === aEndPreceding + bEndPreceding - aStart - bStart) {
484
- division.aEndPreceding = aStart;
485
- division.bEndPreceding = bStart;
486
- } else {
487
- division.aEndPreceding = aEndPreceding;
488
- division.bEndPreceding = bEndPreceding;
489
- }
490
- division.nCommonPreceding = nCommonR;
491
- if (nCommonR !== 0) {
492
- division.aCommonPreceding = aEndPreceding;
493
- division.bCommonPreceding = bEndPreceding;
494
- }
495
- division.nCommonFollowing = nCommonF;
496
- if (nCommonF !== 0) {
497
- division.aCommonFollowing = aFirst + 1;
498
- division.bCommonFollowing = bFirst + 1;
499
- }
500
- const aStartFollowing = aLast + 1;
501
- const bStartFollowing = bFirst + nCommonF + 1;
502
- division.nChangeFollowing = d - 1;
503
- if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
504
- division.aStartFollowing = aEnd;
505
- division.bStartFollowing = bEnd;
506
- } else {
507
- division.aStartFollowing = aStartFollowing;
508
- division.bStartFollowing = bStartFollowing;
509
- }
510
- return true;
511
- }
512
- }
513
- }
514
- return false;
515
- };
516
- const extendOverlappablePathsR = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
517
- const bR = bEnd - aEnd;
518
- const aLength = aEnd - aStart;
519
- const baDeltaLength = bEnd - bStart - aLength;
520
- const kMinOverlapR = baDeltaLength - d;
521
- const kMaxOverlapR = baDeltaLength + d;
522
- let aIndexPrev1 = NOT_YET_SET;
523
- const nR = d < iMaxR ? d : iMaxR;
524
- for (let iR = 0, kR = d; iR <= nR; iR += 1, kR -= 2) {
525
- const insert = iR === 0 || iR !== d && aIndexesR[iR] < aIndexPrev1;
526
- const aLastPrev = insert ? aIndexesR[iR] : aIndexPrev1;
527
- const aFirst = insert ? aLastPrev : aLastPrev - 1;
528
- const bFirst = bR + aFirst - kR;
529
- const nCommonR = countCommonItemsR(aStart, aFirst - 1, bStart, bFirst - 1, isCommon);
530
- const aLast = aFirst - nCommonR;
531
- aIndexPrev1 = aIndexesR[iR];
532
- aIndexesR[iR] = aLast;
533
- if (kMinOverlapR <= kR && kR <= kMaxOverlapR) {
534
- const iF = (d + (kR - baDeltaLength)) / 2;
535
- if (iF <= iMaxF && aLast - 1 <= aIndexesF[iF]) {
536
- const bLast = bFirst - nCommonR;
537
- division.nChangePreceding = d;
538
- if (d === aLast + bLast - aStart - bStart) {
539
- division.aEndPreceding = aStart;
540
- division.bEndPreceding = bStart;
541
- } else {
542
- division.aEndPreceding = aLast;
543
- division.bEndPreceding = bLast;
544
- }
545
- division.nCommonPreceding = nCommonR;
546
- if (nCommonR !== 0) {
547
- division.aCommonPreceding = aLast;
548
- division.bCommonPreceding = bLast;
549
- }
550
- division.nChangeFollowing = d - 1;
551
- if (d === 1) {
552
- division.nCommonFollowing = 0;
553
- division.aStartFollowing = aEnd;
554
- division.bStartFollowing = bEnd;
555
- } else {
556
- const bLastPrev = bR + aLastPrev - (insert ? kR - 1 : kR + 1);
557
- const nCommonF = countCommonItemsF(aLastPrev, aEnd, bLastPrev, bEnd, isCommon);
558
- division.nCommonFollowing = nCommonF;
559
- if (nCommonF !== 0) {
560
- division.aCommonFollowing = aLastPrev;
561
- division.bCommonFollowing = bLastPrev;
562
- }
563
- const aStartFollowing = aLastPrev + nCommonF;
564
- const bStartFollowing = bLastPrev + nCommonF;
565
- if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
566
- division.aStartFollowing = aEnd;
567
- division.bStartFollowing = bEnd;
568
- } else {
569
- division.aStartFollowing = aStartFollowing;
570
- division.bStartFollowing = bStartFollowing;
571
- }
572
- }
573
- return true;
574
- }
575
- }
576
- }
577
- return false;
578
- };
579
- const divide = (nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division) => {
580
- const bF = bStart - aStart;
581
- const bR = bEnd - aEnd;
582
- const aLength = aEnd - aStart;
583
- const bLength = bEnd - bStart;
584
- const baDeltaLength = bLength - aLength;
585
- let iMaxF = aLength;
586
- let iMaxR = aLength;
587
- aIndexesF[0] = aStart - 1;
588
- aIndexesR[0] = aEnd;
589
- if (baDeltaLength % 2 === 0) {
590
- const dMin = (nChange || baDeltaLength) / 2;
591
- const dMax = (aLength + bLength) / 2;
592
- for (let d = 1; d <= dMax; d += 1) {
593
- iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
594
- if (d < dMin) iMaxR = extendPathsR(d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
595
- else if (extendOverlappablePathsR(d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)) return;
596
- }
597
- } else {
598
- const dMin = ((nChange || baDeltaLength) + 1) / 2;
599
- const dMax = (aLength + bLength + 1) / 2;
600
- let d = 1;
601
- iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
602
- for (d += 1; d <= dMax; d += 1) {
603
- iMaxR = extendPathsR(d - 1, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
604
- if (d < dMin) iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
605
- else if (extendOverlappablePathsF(d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)) return;
606
- }
607
- }
608
- /* istanbul ignore next */
609
- throw new Error(`${pkg}: no overlap aStart=${aStart} aEnd=${aEnd} bStart=${bStart} bEnd=${bEnd}`);
610
- };
611
- const findSubsequences = (nChange, aStart, aEnd, bStart, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division) => {
612
- if (bEnd - bStart < aEnd - aStart) {
613
- transposed = !transposed;
614
- if (transposed && callbacks.length === 1) {
615
- const { foundSubsequence, isCommon } = callbacks[0];
616
- callbacks[1] = {
617
- foundSubsequence: (nCommon, bCommon, aCommon) => {
618
- foundSubsequence(nCommon, aCommon, bCommon);
619
- },
620
- isCommon: (bIndex, aIndex) => isCommon(aIndex, bIndex)
621
- };
622
- }
623
- const tStart = aStart;
624
- const tEnd = aEnd;
625
- aStart = bStart;
626
- aEnd = bEnd;
627
- bStart = tStart;
628
- bEnd = tEnd;
629
- }
630
- const { foundSubsequence, isCommon } = callbacks[transposed ? 1 : 0];
631
- divide(nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division);
632
- const { nChangePreceding, aEndPreceding, bEndPreceding, nCommonPreceding, aCommonPreceding, bCommonPreceding, nCommonFollowing, aCommonFollowing, bCommonFollowing, nChangeFollowing, aStartFollowing, bStartFollowing } = division;
633
- if (aStart < aEndPreceding && bStart < bEndPreceding) findSubsequences(nChangePreceding, aStart, aEndPreceding, bStart, bEndPreceding, transposed, callbacks, aIndexesF, aIndexesR, division);
634
- if (nCommonPreceding !== 0) foundSubsequence(nCommonPreceding, aCommonPreceding, bCommonPreceding);
635
- if (nCommonFollowing !== 0) foundSubsequence(nCommonFollowing, aCommonFollowing, bCommonFollowing);
636
- if (aStartFollowing < aEnd && bStartFollowing < bEnd) findSubsequences(nChangeFollowing, aStartFollowing, aEnd, bStartFollowing, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division);
637
- };
638
- const validateLength = (name, arg) => {
639
- if (typeof arg !== "number") throw new TypeError(`${pkg}: ${name} typeof ${typeof arg} is not a number`);
640
- if (!Number.isSafeInteger(arg)) throw new RangeError(`${pkg}: ${name} value ${arg} is not a safe integer`);
641
- if (arg < 0) throw new RangeError(`${pkg}: ${name} value ${arg} is a negative integer`);
642
- };
643
- const validateCallback = (name, arg) => {
644
- const type = typeof arg;
645
- if (type !== "function") throw new TypeError(`${pkg}: ${name} typeof ${type} is not a function`);
646
- };
647
- function diffSequence(aLength, bLength, isCommon, foundSubsequence) {
648
- validateLength("aLength", aLength);
649
- validateLength("bLength", bLength);
650
- validateCallback("isCommon", isCommon);
651
- validateCallback("foundSubsequence", foundSubsequence);
652
- const nCommonF = countCommonItemsF(0, aLength, 0, bLength, isCommon);
653
- if (nCommonF !== 0) foundSubsequence(nCommonF, 0, 0);
654
- if (aLength !== nCommonF || bLength !== nCommonF) {
655
- const aStart = nCommonF;
656
- const bStart = nCommonF;
657
- const nCommonR = countCommonItemsR(aStart, aLength - 1, bStart, bLength - 1, isCommon);
658
- const aEnd = aLength - nCommonR;
659
- const bEnd = bLength - nCommonR;
660
- const nCommonFR = nCommonF + nCommonR;
661
- if (aLength !== nCommonFR && bLength !== nCommonFR) findSubsequences(0, aStart, aEnd, bStart, bEnd, false, [{
662
- foundSubsequence,
663
- isCommon
664
- }], [NOT_YET_SET], [NOT_YET_SET], {
665
- aCommonFollowing: NOT_YET_SET,
666
- aCommonPreceding: NOT_YET_SET,
667
- aEndPreceding: NOT_YET_SET,
668
- aStartFollowing: NOT_YET_SET,
669
- bCommonFollowing: NOT_YET_SET,
670
- bCommonPreceding: NOT_YET_SET,
671
- bEndPreceding: NOT_YET_SET,
672
- bStartFollowing: NOT_YET_SET,
673
- nChangeFollowing: NOT_YET_SET,
674
- nChangePreceding: NOT_YET_SET,
675
- nCommonFollowing: NOT_YET_SET,
676
- nCommonPreceding: NOT_YET_SET
677
- });
678
- if (nCommonR !== 0) foundSubsequence(nCommonR, aEnd, bEnd);
679
- }
680
- }
681
- return build;
682
- }
683
- var diffSequences = /* @__PURE__ */ getDefaultExportFromCjs(requireBuild());
684
- function formatTrailingSpaces(line, trailingSpaceFormatter) {
685
- return line.replace(/\s+$/, (match) => trailingSpaceFormatter(match));
686
- }
687
- function printDiffLine(line, isFirstOrLast, color, indicator, trailingSpaceFormatter, emptyFirstOrLastLinePlaceholder) {
688
- return line.length !== 0 ? color(`${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`) : indicator !== " " ? color(indicator) : isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0 ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
689
- }
690
- function printDeleteLine(line, isFirstOrLast, { aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
691
- return printDiffLine(line, isFirstOrLast, aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
692
- }
693
- function printInsertLine(line, isFirstOrLast, { bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
694
- return printDiffLine(line, isFirstOrLast, bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
695
- }
696
- function printCommonLine(line, isFirstOrLast, { commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
697
- return printDiffLine(line, isFirstOrLast, commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
698
- }
699
- function createPatchMark(aStart, aEnd, bStart, bEnd, { patchColor }) {
700
- return patchColor(`@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`);
701
- }
702
- function joinAlignedDiffsNoExpand(diffs, options) {
703
- const iLength = diffs.length;
704
- const nContextLines = options.contextLines;
705
- const nContextLines2 = nContextLines + nContextLines;
706
- let jLength = iLength;
707
- let hasExcessAtStartOrEnd = false;
708
- let nExcessesBetweenChanges = 0;
709
- let i = 0;
710
- while (i !== iLength) {
711
- const iStart = i;
712
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) i += 1;
713
- if (iStart !== i) if (iStart === 0) {
714
- if (i > nContextLines) {
715
- jLength -= i - nContextLines;
716
- hasExcessAtStartOrEnd = true;
717
- }
718
- } else if (i === iLength) {
719
- const n = i - iStart;
720
- if (n > nContextLines) {
721
- jLength -= n - nContextLines;
722
- hasExcessAtStartOrEnd = true;
723
- }
724
- } else {
725
- const n = i - iStart;
726
- if (n > nContextLines2) {
727
- jLength -= n - nContextLines2;
728
- nExcessesBetweenChanges += 1;
729
- }
730
- }
731
- while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) i += 1;
732
- }
733
- const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
734
- if (nExcessesBetweenChanges !== 0) jLength += nExcessesBetweenChanges + 1;
735
- else if (hasExcessAtStartOrEnd) jLength += 1;
736
- const jLast = jLength - 1;
737
- const lines = [];
738
- let jPatchMark = 0;
739
- if (hasPatch) lines.push("");
740
- let aStart = 0;
741
- let bStart = 0;
742
- let aEnd = 0;
743
- let bEnd = 0;
744
- const pushCommonLine = (line) => {
745
- const j = lines.length;
746
- lines.push(printCommonLine(line, j === 0 || j === jLast, options));
747
- aEnd += 1;
748
- bEnd += 1;
749
- };
750
- const pushDeleteLine = (line) => {
751
- const j = lines.length;
752
- lines.push(printDeleteLine(line, j === 0 || j === jLast, options));
753
- aEnd += 1;
754
- };
755
- const pushInsertLine = (line) => {
756
- const j = lines.length;
757
- lines.push(printInsertLine(line, j === 0 || j === jLast, options));
758
- bEnd += 1;
759
- };
760
- i = 0;
761
- while (i !== iLength) {
762
- let iStart = i;
763
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) i += 1;
764
- if (iStart !== i) if (iStart === 0) {
765
- if (i > nContextLines) {
766
- iStart = i - nContextLines;
767
- aStart = iStart;
768
- bStart = iStart;
769
- aEnd = aStart;
770
- bEnd = bStart;
771
- }
772
- for (let iCommon = iStart; iCommon !== i; iCommon += 1) pushCommonLine(diffs[iCommon][1]);
773
- } else if (i === iLength) {
774
- const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
775
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) pushCommonLine(diffs[iCommon][1]);
776
- } else {
777
- const nCommon = i - iStart;
778
- if (nCommon > nContextLines2) {
779
- const iEnd = iStart + nContextLines;
780
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) pushCommonLine(diffs[iCommon][1]);
781
- lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
782
- jPatchMark = lines.length;
783
- lines.push("");
784
- const nOmit = nCommon - nContextLines2;
785
- aStart = aEnd + nOmit;
786
- bStart = bEnd + nOmit;
787
- aEnd = aStart;
788
- bEnd = bStart;
789
- for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) pushCommonLine(diffs[iCommon][1]);
790
- } else for (let iCommon = iStart; iCommon !== i; iCommon += 1) pushCommonLine(diffs[iCommon][1]);
791
- }
792
- while (i !== iLength && diffs[i][0] === DIFF_DELETE) {
793
- pushDeleteLine(diffs[i][1]);
794
- i += 1;
795
- }
796
- while (i !== iLength && diffs[i][0] === DIFF_INSERT) {
797
- pushInsertLine(diffs[i][1]);
798
- i += 1;
799
- }
800
- }
801
- if (hasPatch) lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
802
- return lines.join("\n");
803
- }
804
- function joinAlignedDiffsExpand(diffs, options) {
805
- return diffs.map((diff, i, diffs) => {
806
- const line = diff[1];
807
- const isFirstOrLast = i === 0 || i === diffs.length - 1;
808
- switch (diff[0]) {
809
- case DIFF_DELETE: return printDeleteLine(line, isFirstOrLast, options);
810
- case DIFF_INSERT: return printInsertLine(line, isFirstOrLast, options);
811
- default: return printCommonLine(line, isFirstOrLast, options);
812
- }
813
- }).join("\n");
814
- }
815
- const noColor = (string) => string;
816
- const DIFF_CONTEXT_DEFAULT = 5;
817
- const DIFF_TRUNCATE_THRESHOLD_DEFAULT = 0;
818
- function getDefaultOptions() {
819
- return {
820
- aAnnotation: "Expected",
821
- aColor: u.green,
822
- aIndicator: "-",
823
- bAnnotation: "Received",
824
- bColor: u.red,
825
- bIndicator: "+",
826
- changeColor: u.inverse,
827
- changeLineTrailingSpaceColor: noColor,
828
- commonColor: u.dim,
829
- commonIndicator: " ",
830
- commonLineTrailingSpaceColor: noColor,
831
- compareKeys: void 0,
832
- contextLines: DIFF_CONTEXT_DEFAULT,
833
- emptyFirstOrLastLinePlaceholder: "",
834
- expand: false,
835
- includeChangeCounts: false,
836
- omitAnnotationLines: false,
837
- patchColor: u.yellow,
838
- printBasicPrototype: false,
839
- truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
840
- truncateAnnotation: "... Diff result is truncated",
841
- truncateAnnotationColor: noColor
842
- };
843
- }
844
- function getCompareKeys(compareKeys) {
845
- return compareKeys && typeof compareKeys === "function" ? compareKeys : void 0;
846
- }
847
- function getContextLines(contextLines) {
848
- return typeof contextLines === "number" && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
849
- }
850
- function normalizeDiffOptions(options = {}) {
851
- return {
852
- ...getDefaultOptions(),
853
- ...options,
854
- compareKeys: getCompareKeys(options.compareKeys),
855
- contextLines: getContextLines(options.contextLines)
856
- };
857
- }
858
- function isEmptyString(lines) {
859
- return lines.length === 1 && lines[0].length === 0;
860
- }
861
- function countChanges(diffs) {
862
- let a = 0;
863
- let b = 0;
864
- diffs.forEach((diff) => {
865
- switch (diff[0]) {
866
- case DIFF_DELETE:
867
- a += 1;
868
- break;
869
- case DIFF_INSERT:
870
- b += 1;
871
- break;
872
- }
873
- });
874
- return {
875
- a,
876
- b
877
- };
878
- }
879
- function printAnnotation({ aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator, includeChangeCounts, omitAnnotationLines }, changeCounts) {
880
- if (omitAnnotationLines) return "";
881
- let aRest = "";
882
- let bRest = "";
883
- if (includeChangeCounts) {
884
- const aCount = String(changeCounts.a);
885
- const bCount = String(changeCounts.b);
886
- const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
887
- const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
888
- const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
889
- const baCountLengthDiff = bCount.length - aCount.length;
890
- const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
891
- const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
892
- aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
893
- bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
894
- }
895
- const a = `${aIndicator} ${aAnnotation}${aRest}`;
896
- const b = `${bIndicator} ${bAnnotation}${bRest}`;
897
- return `${aColor(a)}\n${bColor(b)}\n\n`;
898
- }
899
- function printDiffLines(diffs, truncated, options) {
900
- return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`\n${options.truncateAnnotation}`) : "");
901
- }
902
- function diffLinesUnified(aLines, bLines, options) {
903
- const normalizedOptions = normalizeDiffOptions(options);
904
- const [diffs, truncated] = diffLinesRaw(isEmptyString(aLines) ? [] : aLines, isEmptyString(bLines) ? [] : bLines, normalizedOptions);
905
- return printDiffLines(diffs, truncated, normalizedOptions);
906
- }
907
- function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
908
- if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
909
- aLinesDisplay = [];
910
- aLinesCompare = [];
911
- }
912
- if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
913
- bLinesDisplay = [];
914
- bLinesCompare = [];
915
- }
916
- if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
917
- const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
918
- let aIndex = 0;
919
- let bIndex = 0;
920
- diffs.forEach((diff) => {
921
- switch (diff[0]) {
922
- case DIFF_DELETE:
923
- diff[1] = aLinesDisplay[aIndex];
924
- aIndex += 1;
925
- break;
926
- case DIFF_INSERT:
927
- diff[1] = bLinesDisplay[bIndex];
928
- bIndex += 1;
929
- break;
930
- default:
931
- diff[1] = bLinesDisplay[bIndex];
932
- aIndex += 1;
933
- bIndex += 1;
934
- }
935
- });
936
- return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
937
- }
938
- function diffLinesRaw(aLines, bLines, options) {
939
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
940
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
941
- const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
942
- const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
943
- const truncated = aLength !== aLines.length || bLength !== bLines.length;
944
- const isCommon = (aIndex, bIndex) => aLines[aIndex] === bLines[bIndex];
945
- const diffs = [];
946
- let aIndex = 0;
947
- let bIndex = 0;
948
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
949
- for (; aIndex !== aCommon; aIndex += 1) diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
950
- for (; bIndex !== bCommon; bIndex += 1) diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
951
- for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
952
- };
953
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
954
- for (; aIndex !== aLength; aIndex += 1) diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
955
- for (; bIndex !== bLength; bIndex += 1) diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
956
- return [diffs, truncated];
957
- }
958
- function getType(value) {
959
- if (value === void 0) return "undefined";
960
- else if (value === null) return "null";
961
- else if (Array.isArray(value)) return "array";
962
- else if (typeof value === "boolean") return "boolean";
963
- else if (typeof value === "function") return "function";
964
- else if (typeof value === "number") return "number";
965
- else if (typeof value === "string") return "string";
966
- else if (typeof value === "bigint") return "bigint";
967
- else if (typeof value === "object") {
968
- if (value != null) {
969
- if (value.constructor === RegExp) return "regexp";
970
- else if (value.constructor === Map) return "map";
971
- else if (value.constructor === Set) return "set";
972
- else if (value.constructor === Date) return "date";
973
- }
974
- return "object";
975
- } else if (typeof value === "symbol") return "symbol";
976
- throw new Error(`value of unknown type: ${value}`);
977
- }
978
- function getNewLineSymbol(string) {
979
- return string.includes("\r\n") ? "\r\n" : "\n";
980
- }
981
- function diffStrings(a, b, options) {
982
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
983
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
984
- let aLength = a.length;
985
- let bLength = b.length;
986
- if (truncate) {
987
- const aMultipleLines = a.includes("\n");
988
- const bMultipleLines = b.includes("\n");
989
- const aNewLineSymbol = getNewLineSymbol(a);
990
- const bNewLineSymbol = getNewLineSymbol(b);
991
- const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}\n` : a;
992
- const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}\n` : b;
993
- aLength = _a.length;
994
- bLength = _b.length;
995
- }
996
- const truncated = aLength !== a.length || bLength !== b.length;
997
- const isCommon = (aIndex, bIndex) => a[aIndex] === b[bIndex];
998
- let aIndex = 0;
999
- let bIndex = 0;
1000
- const diffs = [];
1001
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
1002
- if (aIndex !== aCommon) diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
1003
- if (bIndex !== bCommon) diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
1004
- aIndex = aCommon + nCommon;
1005
- bIndex = bCommon + nCommon;
1006
- diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
1007
- };
1008
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
1009
- if (aIndex !== aLength) diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
1010
- if (bIndex !== bLength) diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
1011
- return [diffs, truncated];
1012
- }
1013
- function concatenateRelevantDiffs(op, diffs, changeColor) {
1014
- return diffs.reduce((reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op && diff[1].length !== 0 ? changeColor(diff[1]) : ""), "");
1015
- }
1016
- var ChangeBuffer = class {
1017
- op;
1018
- line;
1019
- lines;
1020
- changeColor;
1021
- constructor(op, changeColor) {
1022
- this.op = op;
1023
- this.line = [];
1024
- this.lines = [];
1025
- this.changeColor = changeColor;
1026
- }
1027
- pushSubstring(substring) {
1028
- this.pushDiff(new Diff(this.op, substring));
1029
- }
1030
- pushLine() {
1031
- this.lines.push(this.line.length !== 1 ? new Diff(this.op, concatenateRelevantDiffs(this.op, this.line, this.changeColor)) : this.line[0][0] === this.op ? this.line[0] : new Diff(this.op, this.line[0][1]));
1032
- this.line.length = 0;
1033
- }
1034
- isLineEmpty() {
1035
- return this.line.length === 0;
1036
- }
1037
- pushDiff(diff) {
1038
- this.line.push(diff);
1039
- }
1040
- align(diff) {
1041
- const string = diff[1];
1042
- if (string.includes("\n")) {
1043
- const substrings = string.split("\n");
1044
- const iLast = substrings.length - 1;
1045
- substrings.forEach((substring, i) => {
1046
- if (i < iLast) {
1047
- this.pushSubstring(substring);
1048
- this.pushLine();
1049
- } else if (substring.length !== 0) this.pushSubstring(substring);
1050
- });
1051
- } else this.pushDiff(diff);
1052
- }
1053
- moveLinesTo(lines) {
1054
- if (!this.isLineEmpty()) this.pushLine();
1055
- lines.push(...this.lines);
1056
- this.lines.length = 0;
1057
- }
1058
- };
1059
- var CommonBuffer = class {
1060
- deleteBuffer;
1061
- insertBuffer;
1062
- lines;
1063
- constructor(deleteBuffer, insertBuffer) {
1064
- this.deleteBuffer = deleteBuffer;
1065
- this.insertBuffer = insertBuffer;
1066
- this.lines = [];
1067
- }
1068
- pushDiffCommonLine(diff) {
1069
- this.lines.push(diff);
1070
- }
1071
- pushDiffChangeLines(diff) {
1072
- const isDiffEmpty = diff[1].length === 0;
1073
- if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) this.deleteBuffer.pushDiff(diff);
1074
- if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) this.insertBuffer.pushDiff(diff);
1075
- }
1076
- flushChangeLines() {
1077
- this.deleteBuffer.moveLinesTo(this.lines);
1078
- this.insertBuffer.moveLinesTo(this.lines);
1079
- }
1080
- align(diff) {
1081
- const op = diff[0];
1082
- const string = diff[1];
1083
- if (string.includes("\n")) {
1084
- const substrings = string.split("\n");
1085
- const iLast = substrings.length - 1;
1086
- substrings.forEach((substring, i) => {
1087
- if (i === 0) {
1088
- const subdiff = new Diff(op, substring);
1089
- if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
1090
- this.flushChangeLines();
1091
- this.pushDiffCommonLine(subdiff);
1092
- } else {
1093
- this.pushDiffChangeLines(subdiff);
1094
- this.flushChangeLines();
1095
- }
1096
- } else if (i < iLast) this.pushDiffCommonLine(new Diff(op, substring));
1097
- else if (substring.length !== 0) this.pushDiffChangeLines(new Diff(op, substring));
1098
- });
1099
- } else this.pushDiffChangeLines(diff);
1100
- }
1101
- getLines() {
1102
- this.flushChangeLines();
1103
- return this.lines;
1104
- }
1105
- };
1106
- function getAlignedDiffs(diffs, changeColor) {
1107
- const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
1108
- const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
1109
- const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
1110
- diffs.forEach((diff) => {
1111
- switch (diff[0]) {
1112
- case DIFF_DELETE:
1113
- deleteBuffer.align(diff);
1114
- break;
1115
- case DIFF_INSERT:
1116
- insertBuffer.align(diff);
1117
- break;
1118
- default: commonBuffer.align(diff);
1119
- }
1120
- });
1121
- return commonBuffer.getLines();
1122
- }
1123
- function hasCommonDiff(diffs, isMultiline) {
1124
- if (isMultiline) {
1125
- const iLast = diffs.length - 1;
1126
- return diffs.some((diff, i) => diff[0] === DIFF_EQUAL && (i !== iLast || diff[1] !== "\n"));
1127
- }
1128
- return diffs.some((diff) => diff[0] === DIFF_EQUAL);
1129
- }
1130
- function diffStringsUnified(a, b, options) {
1131
- if (a !== b && a.length !== 0 && b.length !== 0) {
1132
- const isMultiline = a.includes("\n") || b.includes("\n");
1133
- const [diffs, truncated] = diffStringsRaw(isMultiline ? `${a}\n` : a, isMultiline ? `${b}\n` : b, true, options);
1134
- if (hasCommonDiff(diffs, isMultiline)) {
1135
- const optionsNormalized = normalizeDiffOptions(options);
1136
- return printDiffLines(getAlignedDiffs(diffs, optionsNormalized.changeColor), truncated, optionsNormalized);
1137
- }
1138
- }
1139
- return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1140
- }
1141
- function diffStringsRaw(a, b, cleanup, options) {
1142
- const [diffs, truncated] = diffStrings(a, b, options);
1143
- if (cleanup) diff_cleanupSemantic(diffs);
1144
- return [diffs, truncated];
1145
- }
1146
- function getCommonMessage(message, options) {
1147
- const { commonColor } = normalizeDiffOptions(options);
1148
- return commonColor(message);
1149
- }
1150
- const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
1151
- const PLUGINS = [
1152
- ReactTestComponent,
1153
- ReactElement,
1154
- DOMElement,
1155
- DOMCollection,
1156
- Immutable,
1157
- AsymmetricMatcher,
1158
- plugins.Error
1159
- ];
1160
- const FORMAT_OPTIONS = {
1161
- maxDepth: 20,
1162
- plugins: PLUGINS
1163
- };
1164
- const FALLBACK_FORMAT_OPTIONS = {
1165
- callToJSON: false,
1166
- maxDepth: 8,
1167
- plugins: PLUGINS
1168
- };
1169
- /**
1170
- * @param a Expected value
1171
- * @param b Received value
1172
- * @param options Diff options
1173
- * @returns {string | null} a string diff
1174
- */
1175
- function diff(a, b, options) {
1176
- if (Object.is(a, b)) return "";
1177
- const aType = getType(a);
1178
- let expectedType = aType;
1179
- let omitDifference = false;
1180
- if (aType === "object" && typeof a.asymmetricMatch === "function") {
1181
- if (a.$$typeof !== Symbol.for("jest.asymmetricMatcher")) return;
1182
- if (typeof a.getExpectedType !== "function") return;
1183
- expectedType = a.getExpectedType();
1184
- omitDifference = expectedType === "string";
1185
- }
1186
- if (expectedType !== getType(b)) {
1187
- const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
1188
- const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1189
- let aDisplay = format(a, formatOptions);
1190
- let bDisplay = format(b, formatOptions);
1191
- const MAX_LENGTH = 1e5;
1192
- function truncate(s) {
1193
- return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
1194
- }
1195
- aDisplay = truncate(aDisplay);
1196
- bDisplay = truncate(bDisplay);
1197
- return `${`${aColor(`${aIndicator} ${aAnnotation}:`)} \n${aDisplay}`}\n\n${`${bColor(`${bIndicator} ${bAnnotation}:`)} \n${bDisplay}`}`;
1198
- }
1199
- if (omitDifference) return;
1200
- switch (aType) {
1201
- case "string": return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1202
- case "boolean":
1203
- case "number": return comparePrimitive(a, b, options);
1204
- case "map": return compareObjects(sortMap(a), sortMap(b), options);
1205
- case "set": return compareObjects(sortSet(a), sortSet(b), options);
1206
- default: return compareObjects(a, b, options);
1207
- }
1208
- }
1209
- function comparePrimitive(a, b, options) {
1210
- const aFormat = format(a, FORMAT_OPTIONS);
1211
- const bFormat = format(b, FORMAT_OPTIONS);
1212
- return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
1213
- }
1214
- function sortMap(map) {
1215
- return new Map(Array.from(map.entries()).sort());
1216
- }
1217
- function sortSet(set) {
1218
- return new Set(Array.from(set.values()).sort());
1219
- }
1220
- function compareObjects(a, b, options) {
1221
- let difference;
1222
- let hasThrown = false;
1223
- try {
1224
- difference = getObjectsDifference(a, b, getFormatOptions(FORMAT_OPTIONS, options), options);
1225
- } catch {
1226
- hasThrown = true;
1227
- }
1228
- const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
1229
- if (difference === void 0 || difference === noDiffMessage) {
1230
- difference = getObjectsDifference(a, b, getFormatOptions(FALLBACK_FORMAT_OPTIONS, options), options);
1231
- if (difference !== noDiffMessage && !hasThrown) difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}\n\n${difference}`;
1232
- }
1233
- return difference;
1234
- }
1235
- function getFormatOptions(formatOptions, options) {
1236
- const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
1237
- return {
1238
- ...formatOptions,
1239
- compareKeys,
1240
- printBasicPrototype,
1241
- maxDepth: maxDepth ?? formatOptions.maxDepth
1242
- };
1243
- }
1244
- function getObjectsDifference(a, b, formatOptions, options) {
1245
- const formatOptionsZeroIndent = {
1246
- ...formatOptions,
1247
- indent: 0
1248
- };
1249
- const aCompare = format(a, formatOptionsZeroIndent);
1250
- const bCompare = format(b, formatOptionsZeroIndent);
1251
- if (aCompare === bCompare) return getCommonMessage(NO_DIFF_MESSAGE, options);
1252
- else {
1253
- const aDisplay = format(a, formatOptions);
1254
- const bDisplay = format(b, formatOptions);
1255
- return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
1256
- }
1257
- }
1258
- const MAX_DIFF_STRING_LENGTH = 2e4;
1259
- function isAsymmetricMatcher(data) {
1260
- return getType$1(data) === "Object" && typeof data.asymmetricMatch === "function";
1261
- }
1262
- function isReplaceable(obj1, obj2) {
1263
- const obj1Type = getType$1(obj1);
1264
- return obj1Type === getType$1(obj2) && (obj1Type === "Object" || obj1Type === "Array");
1265
- }
1266
- function printDiffOrStringify(received, expected, options) {
1267
- const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
1268
- if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
1269
- if (expected.includes("\n") || received.includes("\n")) return diffStringsUnified(expected, received, options);
1270
- const [diffs] = diffStringsRaw(expected, received, true);
1271
- const hasCommonDiff = diffs.some((diff) => diff[0] === DIFF_EQUAL);
1272
- const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
1273
- return `${printLabel(aAnnotation) + printExpected(getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff))}\n${printLabel(bAnnotation) + printReceived(getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff))}`;
1274
- }
1275
- const clonedExpected = deepClone(expected, { forceWritable: true });
1276
- const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(deepClone(received, { forceWritable: true }), clonedExpected);
1277
- return diff(replacedExpected, replacedActual, options);
1278
- }
1279
- function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
1280
- if (actual instanceof Error && expected instanceof Error && typeof actual.cause !== "undefined" && typeof expected.cause === "undefined") {
1281
- delete actual.cause;
1282
- return {
1283
- replacedActual: actual,
1284
- replacedExpected: expected
1285
- };
1286
- }
1287
- if (!isReplaceable(actual, expected)) return {
1288
- replacedActual: actual,
1289
- replacedExpected: expected
1290
- };
1291
- if (actualReplaced.has(actual) || expectedReplaced.has(expected)) return {
1292
- replacedActual: actual,
1293
- replacedExpected: expected
1294
- };
1295
- actualReplaced.add(actual);
1296
- expectedReplaced.add(expected);
1297
- getOwnProperties(expected).forEach((key) => {
1298
- const expectedValue = expected[key];
1299
- const actualValue = actual[key];
1300
- if (isAsymmetricMatcher(expectedValue)) {
1301
- if (expectedValue.asymmetricMatch(actualValue)) actual[key] = expectedValue;
1302
- } else if (isAsymmetricMatcher(actualValue)) {
1303
- if (actualValue.asymmetricMatch(expectedValue)) expected[key] = actualValue;
1304
- } else if (isReplaceable(actualValue, expectedValue)) {
1305
- const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
1306
- actual[key] = replaced.replacedActual;
1307
- expected[key] = replaced.replacedExpected;
1308
- }
1309
- });
1310
- return {
1311
- replacedActual: actual,
1312
- replacedExpected: expected
1313
- };
1314
- }
1315
- function getLabelPrinter(...strings) {
1316
- const maxLength = strings.reduce((max, string) => string.length > max ? string.length : max, 0);
1317
- return (string) => `${string}: ${" ".repeat(maxLength - string.length)}`;
1318
- }
1319
- const SPACE_SYMBOL = "·";
1320
- function replaceTrailingSpaces(text) {
1321
- return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
1322
- }
1323
- function printReceived(object) {
1324
- return u.red(replaceTrailingSpaces(stringify(object)));
1325
- }
1326
- function printExpected(value) {
1327
- return u.green(replaceTrailingSpaces(stringify(value)));
1328
- }
1329
- function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff) {
1330
- return diffs.reduce((reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op ? hasCommonDiff ? u.inverse(diff[1]) : diff[1] : ""), "");
1331
- }
1332
-
1333
- //#endregion
1334
- export { diff, printDiffOrStringify };