@noma.to/qwik-testing-library 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +61 -0
  2. package/lib/_virtual/_commonjsHelpers.qwik.cjs +2 -0
  3. package/lib/_virtual/_commonjsHelpers.qwik.mjs +2 -0
  4. package/lib/_virtual/sourcemap-codec.umd.qwik.cjs +4 -0
  5. package/lib/_virtual/sourcemap-codec.umd.qwik.mjs +4 -0
  6. package/lib/index.qwik.cjs +4 -0
  7. package/lib/index.qwik.mjs +4 -0
  8. package/lib/lib/mock.qwik.cjs +14 -0
  9. package/lib/lib/mock.qwik.mjs +14 -0
  10. package/lib/lib/qwik-testing-library.qwik.cjs +4 -0
  11. package/lib/lib/qwik-testing-library.qwik.mjs +4 -0
  12. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.cjs +425 -0
  13. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.qwik.mjs +425 -0
  14. package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.cjs +1967 -0
  15. package/lib/node_modules/.pnpm/@vitest_expect@2.1.1/node_modules/@vitest/expect/dist/index.qwik.mjs +1967 -0
  16. package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +1202 -0
  17. package/lib/node_modules/.pnpm/@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +1202 -0
  18. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +44 -0
  19. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +44 -0
  20. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.cjs +665 -0
  21. package/lib/node_modules/.pnpm/@vitest_runner@2.1.1/node_modules/@vitest/runner/dist/index.qwik.mjs +665 -0
  22. package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.cjs +1641 -0
  23. package/lib/node_modules/.pnpm/@vitest_snapshot@2.1.1/node_modules/@vitest/snapshot/dist/index.qwik.mjs +1641 -0
  24. package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.cjs +148 -0
  25. package/lib/node_modules/.pnpm/@vitest_spy@2.1.1/node_modules/@vitest/spy/dist/index.qwik.mjs +148 -0
  26. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.cjs +158 -0
  27. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/chunk-display.qwik.mjs +158 -0
  28. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.cjs +1731 -0
  29. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/diff.qwik.mjs +1731 -0
  30. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.cjs +137 -0
  31. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/error.qwik.mjs +137 -0
  32. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.cjs +150 -0
  33. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/helpers.qwik.mjs +150 -0
  34. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.cjs +81 -0
  35. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/index.qwik.mjs +81 -0
  36. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.cjs +216 -0
  37. package/lib/node_modules/.pnpm/@vitest_utils@2.1.1/node_modules/@vitest/utils/dist/source-map.qwik.mjs +216 -0
  38. package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.cjs +3905 -0
  39. package/lib/node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.qwik.mjs +3905 -0
  40. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.cjs +9 -0
  41. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/arguments.qwik.mjs +10 -0
  42. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.cjs +16 -0
  43. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/array.qwik.mjs +17 -0
  44. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.cjs +9 -0
  45. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/bigint.qwik.mjs +10 -0
  46. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.cjs +16 -0
  47. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/class.qwik.mjs +17 -0
  48. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.cjs +12 -0
  49. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/date.qwik.mjs +13 -0
  50. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.cjs +30 -0
  51. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/error.qwik.mjs +31 -0
  52. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.cjs +11 -0
  53. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/function.qwik.mjs +12 -0
  54. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.cjs +160 -0
  55. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/helpers.qwik.mjs +160 -0
  56. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.cjs +36 -0
  57. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/html.qwik.mjs +36 -0
  58. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.cjs +130 -0
  59. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/index.qwik.mjs +130 -0
  60. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.cjs +25 -0
  61. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/map.qwik.mjs +26 -0
  62. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.cjs +19 -0
  63. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/number.qwik.mjs +20 -0
  64. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.cjs +24 -0
  65. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/object.qwik.mjs +25 -0
  66. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.cjs +17 -0
  67. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/promise.qwik.mjs +18 -0
  68. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.cjs +9 -0
  69. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/regexp.qwik.mjs +10 -0
  70. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.cjs +16 -0
  71. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/set.qwik.mjs +17 -0
  72. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.cjs +24 -0
  73. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/string.qwik.mjs +25 -0
  74. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.cjs +8 -0
  75. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/symbol.qwik.mjs +9 -0
  76. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.cjs +34 -0
  77. package/lib/node_modules/.pnpm/loupe@3.1.1/node_modules/loupe/lib/typedarray.qwik.mjs +35 -0
  78. package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.cjs +968 -0
  79. package/lib/node_modules/.pnpm/magic-string@0.30.11/node_modules/magic-string/dist/magic-string.es.qwik.mjs +968 -0
  80. package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.cjs +101 -0
  81. package/lib/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.qwik.mjs +101 -0
  82. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +7 -0
  83. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +8 -0
  84. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +80 -0
  85. package/lib/node_modules/.pnpm/tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +80 -0
  86. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +104 -0
  87. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +104 -0
  88. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +8 -0
  89. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +8 -0
  90. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.cjs +6 -0
  91. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/base.BlXpj3e_.qwik.mjs +6 -0
  92. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +56 -0
  93. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +56 -0
  94. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.cjs +16 -0
  95. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/utils.Ck2hJTRs.qwik.mjs +16 -0
  96. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.cjs +2556 -0
  97. package/lib/node_modules/.pnpm/vitest@2.1.1_@types_node@22.7.4_@vitest_ui@2.1.1_jsdom@25.0.1/node_modules/vitest/dist/chunks/vi.D6IHiKAI.qwik.mjs +2556 -0
  98. package/lib-types/lib/mock.d.ts +34 -0
  99. package/lib-types/lib/qwik-testing-library.d.ts +2 -1
  100. package/package.json +5 -4
@@ -0,0 +1,1731 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const index = require("../../../../../@vitest_pretty-format@2.1.1/node_modules/@vitest/pretty-format/dist/index.qwik.cjs");
7
+ const browser = require("../../../../../tinyrainbow@1.2.0/node_modules/tinyrainbow/dist/browser.qwik.cjs");
8
+ const chunkDisplay = require("./chunk-display.qwik.cjs");
9
+ const helpers = require("./helpers.qwik.cjs");
10
+ require("../../../../../loupe@3.1.1/node_modules/loupe/lib/index.qwik.cjs");
11
+ function getType(value) {
12
+ if (value === void 0) {
13
+ return "undefined";
14
+ } else if (value === null) {
15
+ return "null";
16
+ } else if (Array.isArray(value)) {
17
+ return "array";
18
+ } else if (typeof value === "boolean") {
19
+ return "boolean";
20
+ } else if (typeof value === "function") {
21
+ return "function";
22
+ } else if (typeof value === "number") {
23
+ return "number";
24
+ } else if (typeof value === "string") {
25
+ return "string";
26
+ } else if (typeof value === "bigint") {
27
+ return "bigint";
28
+ } else if (typeof value === "object") {
29
+ if (value != null) {
30
+ if (value.constructor === RegExp) {
31
+ return "regexp";
32
+ } else if (value.constructor === Map) {
33
+ return "map";
34
+ } else if (value.constructor === Set) {
35
+ return "set";
36
+ } else if (value.constructor === Date) {
37
+ return "date";
38
+ }
39
+ }
40
+ return "object";
41
+ } else if (typeof value === "symbol") {
42
+ return "symbol";
43
+ }
44
+ throw new Error(`value of unknown type: ${value}`);
45
+ }
46
+ const DIFF_DELETE = -1;
47
+ const DIFF_INSERT = 1;
48
+ const DIFF_EQUAL = 0;
49
+ class Diff {
50
+ constructor(op, text) {
51
+ __publicField(this, 0);
52
+ __publicField(this, 1);
53
+ this[0] = op;
54
+ this[1] = text;
55
+ }
56
+ }
57
+ const diff_commonPrefix = function(text1, text2) {
58
+ if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
59
+ return 0;
60
+ }
61
+ let pointermin = 0;
62
+ let pointermax = Math.min(text1.length, text2.length);
63
+ let pointermid = pointermax;
64
+ let pointerstart = 0;
65
+ while (pointermin < pointermid) {
66
+ if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
67
+ pointermin = pointermid;
68
+ pointerstart = pointermin;
69
+ } else {
70
+ pointermax = pointermid;
71
+ }
72
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
73
+ }
74
+ return pointermid;
75
+ };
76
+ const diff_commonSuffix = function(text1, text2) {
77
+ if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
78
+ return 0;
79
+ }
80
+ let pointermin = 0;
81
+ let pointermax = Math.min(text1.length, text2.length);
82
+ let pointermid = pointermax;
83
+ let pointerend = 0;
84
+ while (pointermin < pointermid) {
85
+ if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
86
+ pointermin = pointermid;
87
+ pointerend = pointermin;
88
+ } else {
89
+ pointermax = pointermid;
90
+ }
91
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
92
+ }
93
+ return pointermid;
94
+ };
95
+ const diff_commonOverlap_ = function(text1, text2) {
96
+ const text1_length = text1.length;
97
+ const text2_length = text2.length;
98
+ if (text1_length === 0 || text2_length === 0) {
99
+ return 0;
100
+ }
101
+ if (text1_length > text2_length) {
102
+ text1 = text1.substring(text1_length - text2_length);
103
+ } else if (text1_length < text2_length) {
104
+ text2 = text2.substring(0, text1_length);
105
+ }
106
+ const text_length = Math.min(text1_length, text2_length);
107
+ if (text1 === text2) {
108
+ return text_length;
109
+ }
110
+ let best = 0;
111
+ let length = 1;
112
+ while (true) {
113
+ const pattern = text1.substring(text_length - length);
114
+ const found = text2.indexOf(pattern);
115
+ if (found === -1) {
116
+ return best;
117
+ }
118
+ length += found;
119
+ if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
120
+ best = length;
121
+ length++;
122
+ }
123
+ }
124
+ };
125
+ const diff_cleanupSemantic = function(diffs) {
126
+ let changes = false;
127
+ const equalities = [];
128
+ let equalitiesLength = 0;
129
+ let lastEquality = null;
130
+ let pointer = 0;
131
+ let length_insertions1 = 0;
132
+ let length_deletions1 = 0;
133
+ let length_insertions2 = 0;
134
+ let length_deletions2 = 0;
135
+ while (pointer < diffs.length) {
136
+ if (diffs[pointer][0] === DIFF_EQUAL) {
137
+ equalities[equalitiesLength++] = pointer;
138
+ length_insertions1 = length_insertions2;
139
+ length_deletions1 = length_deletions2;
140
+ length_insertions2 = 0;
141
+ length_deletions2 = 0;
142
+ lastEquality = diffs[pointer][1];
143
+ } else {
144
+ if (diffs[pointer][0] === DIFF_INSERT) {
145
+ length_insertions2 += diffs[pointer][1].length;
146
+ } else {
147
+ length_deletions2 += diffs[pointer][1].length;
148
+ }
149
+ if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
150
+ diffs.splice(
151
+ equalities[equalitiesLength - 1],
152
+ 0,
153
+ new Diff(DIFF_DELETE, lastEquality)
154
+ );
155
+ diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
156
+ equalitiesLength--;
157
+ equalitiesLength--;
158
+ pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
159
+ length_insertions1 = 0;
160
+ length_deletions1 = 0;
161
+ length_insertions2 = 0;
162
+ length_deletions2 = 0;
163
+ lastEquality = null;
164
+ changes = true;
165
+ }
166
+ }
167
+ pointer++;
168
+ }
169
+ if (changes) {
170
+ diff_cleanupMerge(diffs);
171
+ }
172
+ diff_cleanupSemanticLossless(diffs);
173
+ pointer = 1;
174
+ while (pointer < diffs.length) {
175
+ if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
176
+ const deletion = diffs[pointer - 1][1];
177
+ const insertion = diffs[pointer][1];
178
+ const overlap_length1 = diff_commonOverlap_(deletion, insertion);
179
+ const overlap_length2 = diff_commonOverlap_(insertion, deletion);
180
+ if (overlap_length1 >= overlap_length2) {
181
+ if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
182
+ diffs.splice(
183
+ pointer,
184
+ 0,
185
+ new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1))
186
+ );
187
+ diffs[pointer - 1][1] = deletion.substring(
188
+ 0,
189
+ deletion.length - overlap_length1
190
+ );
191
+ diffs[pointer + 1][1] = insertion.substring(overlap_length1);
192
+ pointer++;
193
+ }
194
+ } else {
195
+ if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
196
+ diffs.splice(
197
+ pointer,
198
+ 0,
199
+ new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2))
200
+ );
201
+ diffs[pointer - 1][0] = DIFF_INSERT;
202
+ diffs[pointer - 1][1] = insertion.substring(
203
+ 0,
204
+ insertion.length - overlap_length2
205
+ );
206
+ diffs[pointer + 1][0] = DIFF_DELETE;
207
+ diffs[pointer + 1][1] = deletion.substring(overlap_length2);
208
+ pointer++;
209
+ }
210
+ }
211
+ pointer++;
212
+ }
213
+ pointer++;
214
+ }
215
+ };
216
+ const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
217
+ const whitespaceRegex_ = /\s/;
218
+ const linebreakRegex_ = /[\r\n]/;
219
+ const blanklineEndRegex_ = /\n\r?\n$/;
220
+ const blanklineStartRegex_ = /^\r?\n\r?\n/;
221
+ function diff_cleanupSemanticLossless(diffs) {
222
+ let pointer = 1;
223
+ while (pointer < diffs.length - 1) {
224
+ if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
225
+ let equality1 = diffs[pointer - 1][1];
226
+ let edit = diffs[pointer][1];
227
+ let equality2 = diffs[pointer + 1][1];
228
+ const commonOffset = diff_commonSuffix(equality1, edit);
229
+ if (commonOffset) {
230
+ const commonString = edit.substring(edit.length - commonOffset);
231
+ equality1 = equality1.substring(0, equality1.length - commonOffset);
232
+ edit = commonString + edit.substring(0, edit.length - commonOffset);
233
+ equality2 = commonString + equality2;
234
+ }
235
+ let bestEquality1 = equality1;
236
+ let bestEdit = edit;
237
+ let bestEquality2 = equality2;
238
+ let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
239
+ while (edit.charAt(0) === equality2.charAt(0)) {
240
+ equality1 += edit.charAt(0);
241
+ edit = edit.substring(1) + equality2.charAt(0);
242
+ equality2 = equality2.substring(1);
243
+ const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
244
+ if (score >= bestScore) {
245
+ bestScore = score;
246
+ bestEquality1 = equality1;
247
+ bestEdit = edit;
248
+ bestEquality2 = equality2;
249
+ }
250
+ }
251
+ if (diffs[pointer - 1][1] !== bestEquality1) {
252
+ if (bestEquality1) {
253
+ diffs[pointer - 1][1] = bestEquality1;
254
+ } else {
255
+ diffs.splice(pointer - 1, 1);
256
+ pointer--;
257
+ }
258
+ diffs[pointer][1] = bestEdit;
259
+ if (bestEquality2) {
260
+ diffs[pointer + 1][1] = bestEquality2;
261
+ } else {
262
+ diffs.splice(pointer + 1, 1);
263
+ pointer--;
264
+ }
265
+ }
266
+ }
267
+ pointer++;
268
+ }
269
+ }
270
+ function diff_cleanupMerge(diffs) {
271
+ diffs.push(new Diff(DIFF_EQUAL, ""));
272
+ let pointer = 0;
273
+ let count_delete = 0;
274
+ let count_insert = 0;
275
+ let text_delete = "";
276
+ let text_insert = "";
277
+ let commonlength;
278
+ while (pointer < diffs.length) {
279
+ switch (diffs[pointer][0]) {
280
+ case DIFF_INSERT:
281
+ count_insert++;
282
+ text_insert += diffs[pointer][1];
283
+ pointer++;
284
+ break;
285
+ case DIFF_DELETE:
286
+ count_delete++;
287
+ text_delete += diffs[pointer][1];
288
+ pointer++;
289
+ break;
290
+ case DIFF_EQUAL:
291
+ if (count_delete + count_insert > 1) {
292
+ if (count_delete !== 0 && count_insert !== 0) {
293
+ commonlength = diff_commonPrefix(text_insert, text_delete);
294
+ if (commonlength !== 0) {
295
+ if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
296
+ diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
297
+ } else {
298
+ diffs.splice(
299
+ 0,
300
+ 0,
301
+ new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength))
302
+ );
303
+ pointer++;
304
+ }
305
+ text_insert = text_insert.substring(commonlength);
306
+ text_delete = text_delete.substring(commonlength);
307
+ }
308
+ commonlength = diff_commonSuffix(text_insert, text_delete);
309
+ if (commonlength !== 0) {
310
+ diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
311
+ text_insert = text_insert.substring(
312
+ 0,
313
+ text_insert.length - commonlength
314
+ );
315
+ text_delete = text_delete.substring(
316
+ 0,
317
+ text_delete.length - commonlength
318
+ );
319
+ }
320
+ }
321
+ pointer -= count_delete + count_insert;
322
+ diffs.splice(pointer, count_delete + count_insert);
323
+ if (text_delete.length) {
324
+ diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
325
+ pointer++;
326
+ }
327
+ if (text_insert.length) {
328
+ diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
329
+ pointer++;
330
+ }
331
+ pointer++;
332
+ } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
333
+ diffs[pointer - 1][1] += diffs[pointer][1];
334
+ diffs.splice(pointer, 1);
335
+ } else {
336
+ pointer++;
337
+ }
338
+ count_insert = 0;
339
+ count_delete = 0;
340
+ text_delete = "";
341
+ text_insert = "";
342
+ break;
343
+ }
344
+ }
345
+ if (diffs[diffs.length - 1][1] === "") {
346
+ diffs.pop();
347
+ }
348
+ let changes = false;
349
+ pointer = 1;
350
+ while (pointer < diffs.length - 1) {
351
+ if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
352
+ if (diffs[pointer][1].substring(
353
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
354
+ ) === diffs[pointer - 1][1]) {
355
+ diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(
356
+ 0,
357
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
358
+ );
359
+ diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
360
+ diffs.splice(pointer - 1, 1);
361
+ changes = true;
362
+ } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
363
+ diffs[pointer - 1][1] += diffs[pointer + 1][1];
364
+ diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
365
+ diffs.splice(pointer + 1, 1);
366
+ changes = true;
367
+ }
368
+ }
369
+ pointer++;
370
+ }
371
+ if (changes) {
372
+ diff_cleanupMerge(diffs);
373
+ }
374
+ }
375
+ function diff_cleanupSemanticScore_(one, two) {
376
+ if (!one || !two) {
377
+ return 6;
378
+ }
379
+ const char1 = one.charAt(one.length - 1);
380
+ const char2 = two.charAt(0);
381
+ const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
382
+ const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
383
+ const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
384
+ const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
385
+ const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
386
+ const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
387
+ const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
388
+ const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
389
+ if (blankLine1 || blankLine2) {
390
+ return 5;
391
+ } else if (lineBreak1 || lineBreak2) {
392
+ return 4;
393
+ } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
394
+ return 3;
395
+ } else if (whitespace1 || whitespace2) {
396
+ return 2;
397
+ } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
398
+ return 1;
399
+ }
400
+ return 0;
401
+ }
402
+ const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
403
+ const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\nPrinting internal object structure without calling `toJSON` instead.";
404
+ var build = {};
405
+ Object.defineProperty(build, "__esModule", {
406
+ value: true
407
+ });
408
+ var _default = build.default = diffSequence;
409
+ const pkg = "diff-sequences";
410
+ const NOT_YET_SET = 0;
411
+ const countCommonItemsF = (aIndex, aEnd, bIndex, bEnd, isCommon) => {
412
+ let nCommon = 0;
413
+ while (aIndex < aEnd && bIndex < bEnd && isCommon(aIndex, bIndex)) {
414
+ aIndex += 1;
415
+ bIndex += 1;
416
+ nCommon += 1;
417
+ }
418
+ return nCommon;
419
+ };
420
+ const countCommonItemsR = (aStart, aIndex, bStart, bIndex, isCommon) => {
421
+ let nCommon = 0;
422
+ while (aStart <= aIndex && bStart <= bIndex && isCommon(aIndex, bIndex)) {
423
+ aIndex -= 1;
424
+ bIndex -= 1;
425
+ nCommon += 1;
426
+ }
427
+ return nCommon;
428
+ };
429
+ const extendPathsF = (d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF) => {
430
+ let iF = 0;
431
+ let kF = -d;
432
+ let aFirst = aIndexesF[iF];
433
+ let aIndexPrev1 = aFirst;
434
+ aIndexesF[iF] += countCommonItemsF(
435
+ aFirst + 1,
436
+ aEnd,
437
+ bF + aFirst - kF + 1,
438
+ bEnd,
439
+ isCommon
440
+ );
441
+ const nF = d < iMaxF ? d : iMaxF;
442
+ for (iF += 1, kF += 2; iF <= nF; iF += 1, kF += 2) {
443
+ if (iF !== d && aIndexPrev1 < aIndexesF[iF]) {
444
+ aFirst = aIndexesF[iF];
445
+ } else {
446
+ aFirst = aIndexPrev1 + 1;
447
+ if (aEnd <= aFirst) {
448
+ return iF - 1;
449
+ }
450
+ }
451
+ aIndexPrev1 = aIndexesF[iF];
452
+ aIndexesF[iF] = aFirst + countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
453
+ }
454
+ return iMaxF;
455
+ };
456
+ const extendPathsR = (d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR) => {
457
+ let iR = 0;
458
+ let kR = d;
459
+ let aFirst = aIndexesR[iR];
460
+ let aIndexPrev1 = aFirst;
461
+ aIndexesR[iR] -= countCommonItemsR(
462
+ aStart,
463
+ aFirst - 1,
464
+ bStart,
465
+ bR + aFirst - kR - 1,
466
+ isCommon
467
+ );
468
+ const nR = d < iMaxR ? d : iMaxR;
469
+ for (iR += 1, kR -= 2; iR <= nR; iR += 1, kR -= 2) {
470
+ if (iR !== d && aIndexesR[iR] < aIndexPrev1) {
471
+ aFirst = aIndexesR[iR];
472
+ } else {
473
+ aFirst = aIndexPrev1 - 1;
474
+ if (aFirst < aStart) {
475
+ return iR - 1;
476
+ }
477
+ }
478
+ aIndexPrev1 = aIndexesR[iR];
479
+ aIndexesR[iR] = aFirst - countCommonItemsR(
480
+ aStart,
481
+ aFirst - 1,
482
+ bStart,
483
+ bR + aFirst - kR - 1,
484
+ isCommon
485
+ );
486
+ }
487
+ return iMaxR;
488
+ };
489
+ const extendOverlappablePathsF = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
490
+ const bF = bStart - aStart;
491
+ const aLength = aEnd - aStart;
492
+ const bLength = bEnd - bStart;
493
+ const baDeltaLength = bLength - aLength;
494
+ const kMinOverlapF = -baDeltaLength - (d - 1);
495
+ const kMaxOverlapF = -baDeltaLength + (d - 1);
496
+ let aIndexPrev1 = NOT_YET_SET;
497
+ const nF = d < iMaxF ? d : iMaxF;
498
+ for (let iF = 0, kF = -d; iF <= nF; iF += 1, kF += 2) {
499
+ const insert = iF === 0 || iF !== d && aIndexPrev1 < aIndexesF[iF];
500
+ const aLastPrev = insert ? aIndexesF[iF] : aIndexPrev1;
501
+ const aFirst = insert ? aLastPrev : aLastPrev + 1;
502
+ const bFirst = bF + aFirst - kF;
503
+ const nCommonF = countCommonItemsF(
504
+ aFirst + 1,
505
+ aEnd,
506
+ bFirst + 1,
507
+ bEnd,
508
+ isCommon
509
+ );
510
+ const aLast = aFirst + nCommonF;
511
+ aIndexPrev1 = aIndexesF[iF];
512
+ aIndexesF[iF] = aLast;
513
+ if (kMinOverlapF <= kF && kF <= kMaxOverlapF) {
514
+ const iR = (d - 1 - (kF + baDeltaLength)) / 2;
515
+ if (iR <= iMaxR && aIndexesR[iR] - 1 <= aLast) {
516
+ const bLastPrev = bF + aLastPrev - (insert ? kF + 1 : kF - 1);
517
+ const nCommonR = countCommonItemsR(
518
+ aStart,
519
+ aLastPrev,
520
+ bStart,
521
+ bLastPrev,
522
+ isCommon
523
+ );
524
+ const aIndexPrevFirst = aLastPrev - nCommonR;
525
+ const bIndexPrevFirst = bLastPrev - nCommonR;
526
+ const aEndPreceding = aIndexPrevFirst + 1;
527
+ const bEndPreceding = bIndexPrevFirst + 1;
528
+ division.nChangePreceding = d - 1;
529
+ if (d - 1 === aEndPreceding + bEndPreceding - aStart - bStart) {
530
+ division.aEndPreceding = aStart;
531
+ division.bEndPreceding = bStart;
532
+ } else {
533
+ division.aEndPreceding = aEndPreceding;
534
+ division.bEndPreceding = bEndPreceding;
535
+ }
536
+ division.nCommonPreceding = nCommonR;
537
+ if (nCommonR !== 0) {
538
+ division.aCommonPreceding = aEndPreceding;
539
+ division.bCommonPreceding = bEndPreceding;
540
+ }
541
+ division.nCommonFollowing = nCommonF;
542
+ if (nCommonF !== 0) {
543
+ division.aCommonFollowing = aFirst + 1;
544
+ division.bCommonFollowing = bFirst + 1;
545
+ }
546
+ const aStartFollowing = aLast + 1;
547
+ const bStartFollowing = bFirst + nCommonF + 1;
548
+ division.nChangeFollowing = d - 1;
549
+ if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
550
+ division.aStartFollowing = aEnd;
551
+ division.bStartFollowing = bEnd;
552
+ } else {
553
+ division.aStartFollowing = aStartFollowing;
554
+ division.bStartFollowing = bStartFollowing;
555
+ }
556
+ return true;
557
+ }
558
+ }
559
+ }
560
+ return false;
561
+ };
562
+ const extendOverlappablePathsR = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
563
+ const bR = bEnd - aEnd;
564
+ const aLength = aEnd - aStart;
565
+ const bLength = bEnd - bStart;
566
+ const baDeltaLength = bLength - aLength;
567
+ const kMinOverlapR = baDeltaLength - d;
568
+ const kMaxOverlapR = baDeltaLength + d;
569
+ let aIndexPrev1 = NOT_YET_SET;
570
+ const nR = d < iMaxR ? d : iMaxR;
571
+ for (let iR = 0, kR = d; iR <= nR; iR += 1, kR -= 2) {
572
+ const insert = iR === 0 || iR !== d && aIndexesR[iR] < aIndexPrev1;
573
+ const aLastPrev = insert ? aIndexesR[iR] : aIndexPrev1;
574
+ const aFirst = insert ? aLastPrev : aLastPrev - 1;
575
+ const bFirst = bR + aFirst - kR;
576
+ const nCommonR = countCommonItemsR(
577
+ aStart,
578
+ aFirst - 1,
579
+ bStart,
580
+ bFirst - 1,
581
+ isCommon
582
+ );
583
+ const aLast = aFirst - nCommonR;
584
+ aIndexPrev1 = aIndexesR[iR];
585
+ aIndexesR[iR] = aLast;
586
+ if (kMinOverlapR <= kR && kR <= kMaxOverlapR) {
587
+ const iF = (d + (kR - baDeltaLength)) / 2;
588
+ if (iF <= iMaxF && aLast - 1 <= aIndexesF[iF]) {
589
+ const bLast = bFirst - nCommonR;
590
+ division.nChangePreceding = d;
591
+ if (d === aLast + bLast - aStart - bStart) {
592
+ division.aEndPreceding = aStart;
593
+ division.bEndPreceding = bStart;
594
+ } else {
595
+ division.aEndPreceding = aLast;
596
+ division.bEndPreceding = bLast;
597
+ }
598
+ division.nCommonPreceding = nCommonR;
599
+ if (nCommonR !== 0) {
600
+ division.aCommonPreceding = aLast;
601
+ division.bCommonPreceding = bLast;
602
+ }
603
+ division.nChangeFollowing = d - 1;
604
+ if (d === 1) {
605
+ division.nCommonFollowing = 0;
606
+ division.aStartFollowing = aEnd;
607
+ division.bStartFollowing = bEnd;
608
+ } else {
609
+ const bLastPrev = bR + aLastPrev - (insert ? kR - 1 : kR + 1);
610
+ const nCommonF = countCommonItemsF(
611
+ aLastPrev,
612
+ aEnd,
613
+ bLastPrev,
614
+ bEnd,
615
+ isCommon
616
+ );
617
+ division.nCommonFollowing = nCommonF;
618
+ if (nCommonF !== 0) {
619
+ division.aCommonFollowing = aLastPrev;
620
+ division.bCommonFollowing = bLastPrev;
621
+ }
622
+ const aStartFollowing = aLastPrev + nCommonF;
623
+ const bStartFollowing = bLastPrev + nCommonF;
624
+ if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
625
+ division.aStartFollowing = aEnd;
626
+ division.bStartFollowing = bEnd;
627
+ } else {
628
+ division.aStartFollowing = aStartFollowing;
629
+ division.bStartFollowing = bStartFollowing;
630
+ }
631
+ }
632
+ return true;
633
+ }
634
+ }
635
+ }
636
+ return false;
637
+ };
638
+ const divide = (nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division) => {
639
+ const bF = bStart - aStart;
640
+ const bR = bEnd - aEnd;
641
+ const aLength = aEnd - aStart;
642
+ const bLength = bEnd - bStart;
643
+ const baDeltaLength = bLength - aLength;
644
+ let iMaxF = aLength;
645
+ let iMaxR = aLength;
646
+ aIndexesF[0] = aStart - 1;
647
+ aIndexesR[0] = aEnd;
648
+ if (baDeltaLength % 2 === 0) {
649
+ const dMin = (nChange || baDeltaLength) / 2;
650
+ const dMax = (aLength + bLength) / 2;
651
+ for (let d = 1; d <= dMax; d += 1) {
652
+ iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
653
+ if (d < dMin) {
654
+ iMaxR = extendPathsR(d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
655
+ } else if (
656
+ // If a reverse path overlaps a forward path in the same diagonal,
657
+ // return a division of the index intervals at the middle change.
658
+ extendOverlappablePathsR(
659
+ d,
660
+ aStart,
661
+ aEnd,
662
+ bStart,
663
+ bEnd,
664
+ isCommon,
665
+ aIndexesF,
666
+ iMaxF,
667
+ aIndexesR,
668
+ iMaxR,
669
+ division
670
+ )
671
+ ) {
672
+ return;
673
+ }
674
+ }
675
+ } else {
676
+ const dMin = ((nChange || baDeltaLength) + 1) / 2;
677
+ const dMax = (aLength + bLength + 1) / 2;
678
+ let d = 1;
679
+ iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
680
+ for (d += 1; d <= dMax; d += 1) {
681
+ iMaxR = extendPathsR(
682
+ d - 1,
683
+ aStart,
684
+ bStart,
685
+ bR,
686
+ isCommon,
687
+ aIndexesR,
688
+ iMaxR
689
+ );
690
+ if (d < dMin) {
691
+ iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
692
+ } else if (
693
+ // If a forward path overlaps a reverse path in the same diagonal,
694
+ // return a division of the index intervals at the middle change.
695
+ extendOverlappablePathsF(
696
+ d,
697
+ aStart,
698
+ aEnd,
699
+ bStart,
700
+ bEnd,
701
+ isCommon,
702
+ aIndexesF,
703
+ iMaxF,
704
+ aIndexesR,
705
+ iMaxR,
706
+ division
707
+ )
708
+ ) {
709
+ return;
710
+ }
711
+ }
712
+ }
713
+ throw new Error(
714
+ `${pkg}: no overlap aStart=${aStart} aEnd=${aEnd} bStart=${bStart} bEnd=${bEnd}`
715
+ );
716
+ };
717
+ const findSubsequences = (nChange, aStart, aEnd, bStart, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division) => {
718
+ if (bEnd - bStart < aEnd - aStart) {
719
+ transposed = !transposed;
720
+ if (transposed && callbacks.length === 1) {
721
+ const { foundSubsequence: foundSubsequence2, isCommon: isCommon2 } = callbacks[0];
722
+ callbacks[1] = {
723
+ foundSubsequence: (nCommon, bCommon, aCommon) => {
724
+ foundSubsequence2(nCommon, aCommon, bCommon);
725
+ },
726
+ isCommon: (bIndex, aIndex) => isCommon2(aIndex, bIndex)
727
+ };
728
+ }
729
+ const tStart = aStart;
730
+ const tEnd = aEnd;
731
+ aStart = bStart;
732
+ aEnd = bEnd;
733
+ bStart = tStart;
734
+ bEnd = tEnd;
735
+ }
736
+ const { foundSubsequence, isCommon } = callbacks[transposed ? 1 : 0];
737
+ divide(
738
+ nChange,
739
+ aStart,
740
+ aEnd,
741
+ bStart,
742
+ bEnd,
743
+ isCommon,
744
+ aIndexesF,
745
+ aIndexesR,
746
+ division
747
+ );
748
+ const {
749
+ nChangePreceding,
750
+ aEndPreceding,
751
+ bEndPreceding,
752
+ nCommonPreceding,
753
+ aCommonPreceding,
754
+ bCommonPreceding,
755
+ nCommonFollowing,
756
+ aCommonFollowing,
757
+ bCommonFollowing,
758
+ nChangeFollowing,
759
+ aStartFollowing,
760
+ bStartFollowing
761
+ } = division;
762
+ if (aStart < aEndPreceding && bStart < bEndPreceding) {
763
+ findSubsequences(
764
+ nChangePreceding,
765
+ aStart,
766
+ aEndPreceding,
767
+ bStart,
768
+ bEndPreceding,
769
+ transposed,
770
+ callbacks,
771
+ aIndexesF,
772
+ aIndexesR,
773
+ division
774
+ );
775
+ }
776
+ if (nCommonPreceding !== 0) {
777
+ foundSubsequence(nCommonPreceding, aCommonPreceding, bCommonPreceding);
778
+ }
779
+ if (nCommonFollowing !== 0) {
780
+ foundSubsequence(nCommonFollowing, aCommonFollowing, bCommonFollowing);
781
+ }
782
+ if (aStartFollowing < aEnd && bStartFollowing < bEnd) {
783
+ findSubsequences(
784
+ nChangeFollowing,
785
+ aStartFollowing,
786
+ aEnd,
787
+ bStartFollowing,
788
+ bEnd,
789
+ transposed,
790
+ callbacks,
791
+ aIndexesF,
792
+ aIndexesR,
793
+ division
794
+ );
795
+ }
796
+ };
797
+ const validateLength = (name, arg) => {
798
+ if (typeof arg !== "number") {
799
+ throw new TypeError(`${pkg}: ${name} typeof ${typeof arg} is not a number`);
800
+ }
801
+ if (!Number.isSafeInteger(arg)) {
802
+ throw new RangeError(`${pkg}: ${name} value ${arg} is not a safe integer`);
803
+ }
804
+ if (arg < 0) {
805
+ throw new RangeError(`${pkg}: ${name} value ${arg} is a negative integer`);
806
+ }
807
+ };
808
+ const validateCallback = (name, arg) => {
809
+ const type = typeof arg;
810
+ if (type !== "function") {
811
+ throw new TypeError(`${pkg}: ${name} typeof ${type} is not a function`);
812
+ }
813
+ };
814
+ function diffSequence(aLength, bLength, isCommon, foundSubsequence) {
815
+ validateLength("aLength", aLength);
816
+ validateLength("bLength", bLength);
817
+ validateCallback("isCommon", isCommon);
818
+ validateCallback("foundSubsequence", foundSubsequence);
819
+ const nCommonF = countCommonItemsF(0, aLength, 0, bLength, isCommon);
820
+ if (nCommonF !== 0) {
821
+ foundSubsequence(nCommonF, 0, 0);
822
+ }
823
+ if (aLength !== nCommonF || bLength !== nCommonF) {
824
+ const aStart = nCommonF;
825
+ const bStart = nCommonF;
826
+ const nCommonR = countCommonItemsR(
827
+ aStart,
828
+ aLength - 1,
829
+ bStart,
830
+ bLength - 1,
831
+ isCommon
832
+ );
833
+ const aEnd = aLength - nCommonR;
834
+ const bEnd = bLength - nCommonR;
835
+ const nCommonFR = nCommonF + nCommonR;
836
+ if (aLength !== nCommonFR && bLength !== nCommonFR) {
837
+ const nChange = 0;
838
+ const transposed = false;
839
+ const callbacks = [
840
+ {
841
+ foundSubsequence,
842
+ isCommon
843
+ }
844
+ ];
845
+ const aIndexesF = [NOT_YET_SET];
846
+ const aIndexesR = [NOT_YET_SET];
847
+ const division = {
848
+ aCommonFollowing: NOT_YET_SET,
849
+ aCommonPreceding: NOT_YET_SET,
850
+ aEndPreceding: NOT_YET_SET,
851
+ aStartFollowing: NOT_YET_SET,
852
+ bCommonFollowing: NOT_YET_SET,
853
+ bCommonPreceding: NOT_YET_SET,
854
+ bEndPreceding: NOT_YET_SET,
855
+ bStartFollowing: NOT_YET_SET,
856
+ nChangeFollowing: NOT_YET_SET,
857
+ nChangePreceding: NOT_YET_SET,
858
+ nCommonFollowing: NOT_YET_SET,
859
+ nCommonPreceding: NOT_YET_SET
860
+ };
861
+ findSubsequences(
862
+ nChange,
863
+ aStart,
864
+ aEnd,
865
+ bStart,
866
+ bEnd,
867
+ transposed,
868
+ callbacks,
869
+ aIndexesF,
870
+ aIndexesR,
871
+ division
872
+ );
873
+ }
874
+ if (nCommonR !== 0) {
875
+ foundSubsequence(nCommonR, aEnd, bEnd);
876
+ }
877
+ }
878
+ }
879
+ function formatTrailingSpaces(line, trailingSpaceFormatter) {
880
+ return line.replace(/\s+$/, (match) => trailingSpaceFormatter(match));
881
+ }
882
+ function printDiffLine(line, isFirstOrLast, color, indicator, trailingSpaceFormatter, emptyFirstOrLastLinePlaceholder) {
883
+ return line.length !== 0 ? color(
884
+ `${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`
885
+ ) : indicator !== " " ? color(indicator) : isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0 ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
886
+ }
887
+ function printDeleteLine(line, isFirstOrLast, {
888
+ aColor,
889
+ aIndicator,
890
+ changeLineTrailingSpaceColor,
891
+ emptyFirstOrLastLinePlaceholder
892
+ }) {
893
+ return printDiffLine(
894
+ line,
895
+ isFirstOrLast,
896
+ aColor,
897
+ aIndicator,
898
+ changeLineTrailingSpaceColor,
899
+ emptyFirstOrLastLinePlaceholder
900
+ );
901
+ }
902
+ function printInsertLine(line, isFirstOrLast, {
903
+ bColor,
904
+ bIndicator,
905
+ changeLineTrailingSpaceColor,
906
+ emptyFirstOrLastLinePlaceholder
907
+ }) {
908
+ return printDiffLine(
909
+ line,
910
+ isFirstOrLast,
911
+ bColor,
912
+ bIndicator,
913
+ changeLineTrailingSpaceColor,
914
+ emptyFirstOrLastLinePlaceholder
915
+ );
916
+ }
917
+ function printCommonLine(line, isFirstOrLast, {
918
+ commonColor,
919
+ commonIndicator,
920
+ commonLineTrailingSpaceColor,
921
+ emptyFirstOrLastLinePlaceholder
922
+ }) {
923
+ return printDiffLine(
924
+ line,
925
+ isFirstOrLast,
926
+ commonColor,
927
+ commonIndicator,
928
+ commonLineTrailingSpaceColor,
929
+ emptyFirstOrLastLinePlaceholder
930
+ );
931
+ }
932
+ function createPatchMark(aStart, aEnd, bStart, bEnd, { patchColor }) {
933
+ return patchColor(
934
+ `@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`
935
+ );
936
+ }
937
+ function joinAlignedDiffsNoExpand(diffs, options) {
938
+ const iLength = diffs.length;
939
+ const nContextLines = options.contextLines;
940
+ const nContextLines2 = nContextLines + nContextLines;
941
+ let jLength = iLength;
942
+ let hasExcessAtStartOrEnd = false;
943
+ let nExcessesBetweenChanges = 0;
944
+ let i = 0;
945
+ while (i !== iLength) {
946
+ const iStart = i;
947
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
948
+ i += 1;
949
+ }
950
+ if (iStart !== i) {
951
+ if (iStart === 0) {
952
+ if (i > nContextLines) {
953
+ jLength -= i - nContextLines;
954
+ hasExcessAtStartOrEnd = true;
955
+ }
956
+ } else if (i === iLength) {
957
+ const n = i - iStart;
958
+ if (n > nContextLines) {
959
+ jLength -= n - nContextLines;
960
+ hasExcessAtStartOrEnd = true;
961
+ }
962
+ } else {
963
+ const n = i - iStart;
964
+ if (n > nContextLines2) {
965
+ jLength -= n - nContextLines2;
966
+ nExcessesBetweenChanges += 1;
967
+ }
968
+ }
969
+ }
970
+ while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
971
+ i += 1;
972
+ }
973
+ }
974
+ const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
975
+ if (nExcessesBetweenChanges !== 0) {
976
+ jLength += nExcessesBetweenChanges + 1;
977
+ } else if (hasExcessAtStartOrEnd) {
978
+ jLength += 1;
979
+ }
980
+ const jLast = jLength - 1;
981
+ const lines = [];
982
+ let jPatchMark = 0;
983
+ if (hasPatch) {
984
+ lines.push("");
985
+ }
986
+ let aStart = 0;
987
+ let bStart = 0;
988
+ let aEnd = 0;
989
+ let bEnd = 0;
990
+ const pushCommonLine = (line) => {
991
+ const j = lines.length;
992
+ lines.push(printCommonLine(line, j === 0 || j === jLast, options));
993
+ aEnd += 1;
994
+ bEnd += 1;
995
+ };
996
+ const pushDeleteLine = (line) => {
997
+ const j = lines.length;
998
+ lines.push(printDeleteLine(line, j === 0 || j === jLast, options));
999
+ aEnd += 1;
1000
+ };
1001
+ const pushInsertLine = (line) => {
1002
+ const j = lines.length;
1003
+ lines.push(printInsertLine(line, j === 0 || j === jLast, options));
1004
+ bEnd += 1;
1005
+ };
1006
+ i = 0;
1007
+ while (i !== iLength) {
1008
+ let iStart = i;
1009
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
1010
+ i += 1;
1011
+ }
1012
+ if (iStart !== i) {
1013
+ if (iStart === 0) {
1014
+ if (i > nContextLines) {
1015
+ iStart = i - nContextLines;
1016
+ aStart = iStart;
1017
+ bStart = iStart;
1018
+ aEnd = aStart;
1019
+ bEnd = bStart;
1020
+ }
1021
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1022
+ pushCommonLine(diffs[iCommon][1]);
1023
+ }
1024
+ } else if (i === iLength) {
1025
+ const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
1026
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1027
+ pushCommonLine(diffs[iCommon][1]);
1028
+ }
1029
+ } else {
1030
+ const nCommon = i - iStart;
1031
+ if (nCommon > nContextLines2) {
1032
+ const iEnd = iStart + nContextLines;
1033
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1034
+ pushCommonLine(diffs[iCommon][1]);
1035
+ }
1036
+ lines[jPatchMark] = createPatchMark(
1037
+ aStart,
1038
+ aEnd,
1039
+ bStart,
1040
+ bEnd,
1041
+ options
1042
+ );
1043
+ jPatchMark = lines.length;
1044
+ lines.push("");
1045
+ const nOmit = nCommon - nContextLines2;
1046
+ aStart = aEnd + nOmit;
1047
+ bStart = bEnd + nOmit;
1048
+ aEnd = aStart;
1049
+ bEnd = bStart;
1050
+ for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
1051
+ pushCommonLine(diffs[iCommon][1]);
1052
+ }
1053
+ } else {
1054
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1055
+ pushCommonLine(diffs[iCommon][1]);
1056
+ }
1057
+ }
1058
+ }
1059
+ }
1060
+ while (i !== iLength && diffs[i][0] === DIFF_DELETE) {
1061
+ pushDeleteLine(diffs[i][1]);
1062
+ i += 1;
1063
+ }
1064
+ while (i !== iLength && diffs[i][0] === DIFF_INSERT) {
1065
+ pushInsertLine(diffs[i][1]);
1066
+ i += 1;
1067
+ }
1068
+ }
1069
+ if (hasPatch) {
1070
+ lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
1071
+ }
1072
+ return lines.join("\n");
1073
+ }
1074
+ function joinAlignedDiffsExpand(diffs, options) {
1075
+ return diffs.map((diff2, i, diffs2) => {
1076
+ const line = diff2[1];
1077
+ const isFirstOrLast = i === 0 || i === diffs2.length - 1;
1078
+ switch (diff2[0]) {
1079
+ case DIFF_DELETE:
1080
+ return printDeleteLine(line, isFirstOrLast, options);
1081
+ case DIFF_INSERT:
1082
+ return printInsertLine(line, isFirstOrLast, options);
1083
+ default:
1084
+ return printCommonLine(line, isFirstOrLast, options);
1085
+ }
1086
+ }).join("\n");
1087
+ }
1088
+ const noColor = (string) => string;
1089
+ const DIFF_CONTEXT_DEFAULT = 5;
1090
+ const DIFF_TRUNCATE_THRESHOLD_DEFAULT = 0;
1091
+ function getDefaultOptions() {
1092
+ return {
1093
+ aAnnotation: "Expected",
1094
+ aColor: browser.default.green,
1095
+ aIndicator: "-",
1096
+ bAnnotation: "Received",
1097
+ bColor: browser.default.red,
1098
+ bIndicator: "+",
1099
+ changeColor: browser.default.inverse,
1100
+ changeLineTrailingSpaceColor: noColor,
1101
+ commonColor: browser.default.dim,
1102
+ commonIndicator: " ",
1103
+ commonLineTrailingSpaceColor: noColor,
1104
+ compareKeys: void 0,
1105
+ contextLines: DIFF_CONTEXT_DEFAULT,
1106
+ emptyFirstOrLastLinePlaceholder: "",
1107
+ expand: true,
1108
+ includeChangeCounts: false,
1109
+ omitAnnotationLines: false,
1110
+ patchColor: browser.default.yellow,
1111
+ truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
1112
+ truncateAnnotation: "... Diff result is truncated",
1113
+ truncateAnnotationColor: noColor
1114
+ };
1115
+ }
1116
+ function getCompareKeys(compareKeys) {
1117
+ return compareKeys && typeof compareKeys === "function" ? compareKeys : void 0;
1118
+ }
1119
+ function getContextLines(contextLines) {
1120
+ return typeof contextLines === "number" && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
1121
+ }
1122
+ function normalizeDiffOptions(options = {}) {
1123
+ return {
1124
+ ...getDefaultOptions(),
1125
+ ...options,
1126
+ compareKeys: getCompareKeys(options.compareKeys),
1127
+ contextLines: getContextLines(options.contextLines)
1128
+ };
1129
+ }
1130
+ function isEmptyString(lines) {
1131
+ return lines.length === 1 && lines[0].length === 0;
1132
+ }
1133
+ function countChanges(diffs) {
1134
+ let a = 0;
1135
+ let b = 0;
1136
+ diffs.forEach((diff2) => {
1137
+ switch (diff2[0]) {
1138
+ case DIFF_DELETE:
1139
+ a += 1;
1140
+ break;
1141
+ case DIFF_INSERT:
1142
+ b += 1;
1143
+ break;
1144
+ }
1145
+ });
1146
+ return { a, b };
1147
+ }
1148
+ function printAnnotation({
1149
+ aAnnotation,
1150
+ aColor,
1151
+ aIndicator,
1152
+ bAnnotation,
1153
+ bColor,
1154
+ bIndicator,
1155
+ includeChangeCounts,
1156
+ omitAnnotationLines
1157
+ }, changeCounts) {
1158
+ if (omitAnnotationLines) {
1159
+ return "";
1160
+ }
1161
+ let aRest = "";
1162
+ let bRest = "";
1163
+ if (includeChangeCounts) {
1164
+ const aCount = String(changeCounts.a);
1165
+ const bCount = String(changeCounts.b);
1166
+ const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
1167
+ const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
1168
+ const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
1169
+ const baCountLengthDiff = bCount.length - aCount.length;
1170
+ const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
1171
+ const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
1172
+ aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
1173
+ bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
1174
+ }
1175
+ const a = `${aIndicator} ${aAnnotation}${aRest}`;
1176
+ const b = `${bIndicator} ${bAnnotation}${bRest}`;
1177
+ return `${aColor(a)}
1178
+ ${bColor(b)}
1179
+
1180
+ `;
1181
+ }
1182
+ function printDiffLines(diffs, truncated, options) {
1183
+ return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`
1184
+ ${options.truncateAnnotation}`) : "");
1185
+ }
1186
+ function diffLinesUnified(aLines, bLines, options) {
1187
+ const normalizedOptions = normalizeDiffOptions(options);
1188
+ const [diffs, truncated] = diffLinesRaw(
1189
+ isEmptyString(aLines) ? [] : aLines,
1190
+ isEmptyString(bLines) ? [] : bLines,
1191
+ normalizedOptions
1192
+ );
1193
+ return printDiffLines(diffs, truncated, normalizedOptions);
1194
+ }
1195
+ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
1196
+ if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
1197
+ aLinesDisplay = [];
1198
+ aLinesCompare = [];
1199
+ }
1200
+ if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
1201
+ bLinesDisplay = [];
1202
+ bLinesCompare = [];
1203
+ }
1204
+ if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
1205
+ return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
1206
+ }
1207
+ const [diffs, truncated] = diffLinesRaw(
1208
+ aLinesCompare,
1209
+ bLinesCompare,
1210
+ options
1211
+ );
1212
+ let aIndex = 0;
1213
+ let bIndex = 0;
1214
+ diffs.forEach((diff2) => {
1215
+ switch (diff2[0]) {
1216
+ case DIFF_DELETE:
1217
+ diff2[1] = aLinesDisplay[aIndex];
1218
+ aIndex += 1;
1219
+ break;
1220
+ case DIFF_INSERT:
1221
+ diff2[1] = bLinesDisplay[bIndex];
1222
+ bIndex += 1;
1223
+ break;
1224
+ default:
1225
+ diff2[1] = bLinesDisplay[bIndex];
1226
+ aIndex += 1;
1227
+ bIndex += 1;
1228
+ }
1229
+ });
1230
+ return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
1231
+ }
1232
+ function diffLinesRaw(aLines, bLines, options) {
1233
+ const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
1234
+ const truncateThreshold = Math.max(
1235
+ Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
1236
+ 0
1237
+ );
1238
+ const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
1239
+ const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
1240
+ const truncated = aLength !== aLines.length || bLength !== bLines.length;
1241
+ const isCommon = (aIndex2, bIndex2) => aLines[aIndex2] === bLines[bIndex2];
1242
+ const diffs = [];
1243
+ let aIndex = 0;
1244
+ let bIndex = 0;
1245
+ const foundSubsequence = (nCommon, aCommon, bCommon) => {
1246
+ for (; aIndex !== aCommon; aIndex += 1) {
1247
+ diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1248
+ }
1249
+ for (; bIndex !== bCommon; bIndex += 1) {
1250
+ diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1251
+ }
1252
+ for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
1253
+ diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
1254
+ }
1255
+ };
1256
+ _default(aLength, bLength, isCommon, foundSubsequence);
1257
+ for (; aIndex !== aLength; aIndex += 1) {
1258
+ diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1259
+ }
1260
+ for (; bIndex !== bLength; bIndex += 1) {
1261
+ diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1262
+ }
1263
+ return [diffs, truncated];
1264
+ }
1265
+ function getNewLineSymbol(string) {
1266
+ return string.includes("\r\n") ? "\r\n" : "\n";
1267
+ }
1268
+ function diffStrings(a, b, options) {
1269
+ const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
1270
+ const truncateThreshold = Math.max(
1271
+ Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
1272
+ 0
1273
+ );
1274
+ let aLength = a.length;
1275
+ let bLength = b.length;
1276
+ if (truncate) {
1277
+ const aMultipleLines = a.includes("\n");
1278
+ const bMultipleLines = b.includes("\n");
1279
+ const aNewLineSymbol = getNewLineSymbol(a);
1280
+ const bNewLineSymbol = getNewLineSymbol(b);
1281
+ const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}
1282
+ ` : a;
1283
+ const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}
1284
+ ` : b;
1285
+ aLength = _a.length;
1286
+ bLength = _b.length;
1287
+ }
1288
+ const truncated = aLength !== a.length || bLength !== b.length;
1289
+ const isCommon = (aIndex2, bIndex2) => a[aIndex2] === b[bIndex2];
1290
+ let aIndex = 0;
1291
+ let bIndex = 0;
1292
+ const diffs = [];
1293
+ const foundSubsequence = (nCommon, aCommon, bCommon) => {
1294
+ if (aIndex !== aCommon) {
1295
+ diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
1296
+ }
1297
+ if (bIndex !== bCommon) {
1298
+ diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
1299
+ }
1300
+ aIndex = aCommon + nCommon;
1301
+ bIndex = bCommon + nCommon;
1302
+ diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
1303
+ };
1304
+ _default(aLength, bLength, isCommon, foundSubsequence);
1305
+ if (aIndex !== aLength) {
1306
+ diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
1307
+ }
1308
+ if (bIndex !== bLength) {
1309
+ diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
1310
+ }
1311
+ return [diffs, truncated];
1312
+ }
1313
+ function concatenateRelevantDiffs(op, diffs, changeColor) {
1314
+ return diffs.reduce(
1315
+ (reduced, diff2) => reduced + (diff2[0] === DIFF_EQUAL ? diff2[1] : diff2[0] === op && diff2[1].length !== 0 ? changeColor(diff2[1]) : ""),
1316
+ ""
1317
+ );
1318
+ }
1319
+ class ChangeBuffer {
1320
+ constructor(op, changeColor) {
1321
+ __publicField(this, "op");
1322
+ __publicField(this, "line");
1323
+ // incomplete line
1324
+ __publicField(this, "lines");
1325
+ // complete lines
1326
+ __publicField(this, "changeColor");
1327
+ this.op = op;
1328
+ this.line = [];
1329
+ this.lines = [];
1330
+ this.changeColor = changeColor;
1331
+ }
1332
+ pushSubstring(substring) {
1333
+ this.pushDiff(new Diff(this.op, substring));
1334
+ }
1335
+ pushLine() {
1336
+ this.lines.push(
1337
+ this.line.length !== 1 ? new Diff(
1338
+ this.op,
1339
+ concatenateRelevantDiffs(this.op, this.line, this.changeColor)
1340
+ ) : this.line[0][0] === this.op ? this.line[0] : new Diff(this.op, this.line[0][1])
1341
+ // was common diff
1342
+ );
1343
+ this.line.length = 0;
1344
+ }
1345
+ isLineEmpty() {
1346
+ return this.line.length === 0;
1347
+ }
1348
+ // Minor input to buffer.
1349
+ pushDiff(diff2) {
1350
+ this.line.push(diff2);
1351
+ }
1352
+ // Main input to buffer.
1353
+ align(diff2) {
1354
+ const string = diff2[1];
1355
+ if (string.includes("\n")) {
1356
+ const substrings = string.split("\n");
1357
+ const iLast = substrings.length - 1;
1358
+ substrings.forEach((substring, i) => {
1359
+ if (i < iLast) {
1360
+ this.pushSubstring(substring);
1361
+ this.pushLine();
1362
+ } else if (substring.length !== 0) {
1363
+ this.pushSubstring(substring);
1364
+ }
1365
+ });
1366
+ } else {
1367
+ this.pushDiff(diff2);
1368
+ }
1369
+ }
1370
+ // Output from buffer.
1371
+ moveLinesTo(lines) {
1372
+ if (!this.isLineEmpty()) {
1373
+ this.pushLine();
1374
+ }
1375
+ lines.push(...this.lines);
1376
+ this.lines.length = 0;
1377
+ }
1378
+ }
1379
+ class CommonBuffer {
1380
+ constructor(deleteBuffer, insertBuffer) {
1381
+ __publicField(this, "deleteBuffer");
1382
+ __publicField(this, "insertBuffer");
1383
+ __publicField(this, "lines");
1384
+ this.deleteBuffer = deleteBuffer;
1385
+ this.insertBuffer = insertBuffer;
1386
+ this.lines = [];
1387
+ }
1388
+ pushDiffCommonLine(diff2) {
1389
+ this.lines.push(diff2);
1390
+ }
1391
+ pushDiffChangeLines(diff2) {
1392
+ const isDiffEmpty = diff2[1].length === 0;
1393
+ if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
1394
+ this.deleteBuffer.pushDiff(diff2);
1395
+ }
1396
+ if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
1397
+ this.insertBuffer.pushDiff(diff2);
1398
+ }
1399
+ }
1400
+ flushChangeLines() {
1401
+ this.deleteBuffer.moveLinesTo(this.lines);
1402
+ this.insertBuffer.moveLinesTo(this.lines);
1403
+ }
1404
+ // Input to buffer.
1405
+ align(diff2) {
1406
+ const op = diff2[0];
1407
+ const string = diff2[1];
1408
+ if (string.includes("\n")) {
1409
+ const substrings = string.split("\n");
1410
+ const iLast = substrings.length - 1;
1411
+ substrings.forEach((substring, i) => {
1412
+ if (i === 0) {
1413
+ const subdiff = new Diff(op, substring);
1414
+ if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
1415
+ this.flushChangeLines();
1416
+ this.pushDiffCommonLine(subdiff);
1417
+ } else {
1418
+ this.pushDiffChangeLines(subdiff);
1419
+ this.flushChangeLines();
1420
+ }
1421
+ } else if (i < iLast) {
1422
+ this.pushDiffCommonLine(new Diff(op, substring));
1423
+ } else if (substring.length !== 0) {
1424
+ this.pushDiffChangeLines(new Diff(op, substring));
1425
+ }
1426
+ });
1427
+ } else {
1428
+ this.pushDiffChangeLines(diff2);
1429
+ }
1430
+ }
1431
+ // Output from buffer.
1432
+ getLines() {
1433
+ this.flushChangeLines();
1434
+ return this.lines;
1435
+ }
1436
+ }
1437
+ function getAlignedDiffs(diffs, changeColor) {
1438
+ const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
1439
+ const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
1440
+ const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
1441
+ diffs.forEach((diff2) => {
1442
+ switch (diff2[0]) {
1443
+ case DIFF_DELETE:
1444
+ deleteBuffer.align(diff2);
1445
+ break;
1446
+ case DIFF_INSERT:
1447
+ insertBuffer.align(diff2);
1448
+ break;
1449
+ default:
1450
+ commonBuffer.align(diff2);
1451
+ }
1452
+ });
1453
+ return commonBuffer.getLines();
1454
+ }
1455
+ function hasCommonDiff(diffs, isMultiline) {
1456
+ if (isMultiline) {
1457
+ const iLast = diffs.length - 1;
1458
+ return diffs.some(
1459
+ (diff2, i) => diff2[0] === DIFF_EQUAL && (i !== iLast || diff2[1] !== "\n")
1460
+ );
1461
+ }
1462
+ return diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
1463
+ }
1464
+ function diffStringsUnified(a, b, options) {
1465
+ if (a !== b && a.length !== 0 && b.length !== 0) {
1466
+ const isMultiline = a.includes("\n") || b.includes("\n");
1467
+ const [diffs, truncated] = diffStringsRaw(
1468
+ isMultiline ? `${a}
1469
+ ` : a,
1470
+ isMultiline ? `${b}
1471
+ ` : b,
1472
+ true,
1473
+ // cleanupSemantic
1474
+ options
1475
+ );
1476
+ if (hasCommonDiff(diffs, isMultiline)) {
1477
+ const optionsNormalized = normalizeDiffOptions(options);
1478
+ const lines = getAlignedDiffs(diffs, optionsNormalized.changeColor);
1479
+ return printDiffLines(lines, truncated, optionsNormalized);
1480
+ }
1481
+ }
1482
+ return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1483
+ }
1484
+ function diffStringsRaw(a, b, cleanup, options) {
1485
+ const [diffs, truncated] = diffStrings(a, b, options);
1486
+ {
1487
+ diff_cleanupSemantic(diffs);
1488
+ }
1489
+ return [diffs, truncated];
1490
+ }
1491
+ function getCommonMessage(message, options) {
1492
+ const { commonColor } = normalizeDiffOptions(options);
1493
+ return commonColor(message);
1494
+ }
1495
+ const {
1496
+ AsymmetricMatcher,
1497
+ DOMCollection,
1498
+ DOMElement,
1499
+ Immutable,
1500
+ ReactElement,
1501
+ ReactTestComponent
1502
+ } = index.plugins;
1503
+ const PLUGINS = [
1504
+ ReactTestComponent,
1505
+ ReactElement,
1506
+ DOMElement,
1507
+ DOMCollection,
1508
+ Immutable,
1509
+ AsymmetricMatcher
1510
+ ];
1511
+ const FORMAT_OPTIONS = {
1512
+ plugins: PLUGINS
1513
+ };
1514
+ const FALLBACK_FORMAT_OPTIONS = {
1515
+ callToJSON: false,
1516
+ maxDepth: 10,
1517
+ plugins: PLUGINS
1518
+ };
1519
+ function diff(a, b, options) {
1520
+ if (Object.is(a, b)) {
1521
+ return "";
1522
+ }
1523
+ const aType = getType(a);
1524
+ let expectedType = aType;
1525
+ let omitDifference = false;
1526
+ if (aType === "object" && typeof a.asymmetricMatch === "function") {
1527
+ if (a.$$typeof !== Symbol.for("jest.asymmetricMatcher")) {
1528
+ return void 0;
1529
+ }
1530
+ if (typeof a.getExpectedType !== "function") {
1531
+ return void 0;
1532
+ }
1533
+ expectedType = a.getExpectedType();
1534
+ omitDifference = expectedType === "string";
1535
+ }
1536
+ if (expectedType !== getType(b)) {
1537
+ const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
1538
+ const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1539
+ const aDisplay = index.format(a, formatOptions);
1540
+ const bDisplay = index.format(b, formatOptions);
1541
+ const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
1542
+ ${aDisplay}`;
1543
+ const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
1544
+ ${bDisplay}`;
1545
+ return `${aDiff}
1546
+
1547
+ ${bDiff}`;
1548
+ }
1549
+ if (omitDifference) {
1550
+ return void 0;
1551
+ }
1552
+ switch (aType) {
1553
+ case "string":
1554
+ return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1555
+ case "boolean":
1556
+ case "number":
1557
+ return comparePrimitive(a, b, options);
1558
+ case "map":
1559
+ return compareObjects(sortMap(a), sortMap(b), options);
1560
+ case "set":
1561
+ return compareObjects(sortSet(a), sortSet(b), options);
1562
+ default:
1563
+ return compareObjects(a, b, options);
1564
+ }
1565
+ }
1566
+ function comparePrimitive(a, b, options) {
1567
+ const aFormat = index.format(a, FORMAT_OPTIONS);
1568
+ const bFormat = index.format(b, FORMAT_OPTIONS);
1569
+ return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
1570
+ }
1571
+ function sortMap(map) {
1572
+ return new Map(Array.from(map.entries()).sort());
1573
+ }
1574
+ function sortSet(set) {
1575
+ return new Set(Array.from(set.values()).sort());
1576
+ }
1577
+ function compareObjects(a, b, options) {
1578
+ let difference;
1579
+ let hasThrown = false;
1580
+ try {
1581
+ const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
1582
+ difference = getObjectsDifference(a, b, formatOptions, options);
1583
+ } catch {
1584
+ hasThrown = true;
1585
+ }
1586
+ const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
1587
+ if (difference === void 0 || difference === noDiffMessage) {
1588
+ const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1589
+ difference = getObjectsDifference(a, b, formatOptions, options);
1590
+ if (difference !== noDiffMessage && !hasThrown) {
1591
+ difference = `${getCommonMessage(
1592
+ SIMILAR_MESSAGE,
1593
+ options
1594
+ )}
1595
+
1596
+ ${difference}`;
1597
+ }
1598
+ }
1599
+ return difference;
1600
+ }
1601
+ function getFormatOptions(formatOptions, options) {
1602
+ const { compareKeys } = normalizeDiffOptions(options);
1603
+ return {
1604
+ ...formatOptions,
1605
+ compareKeys
1606
+ };
1607
+ }
1608
+ function getObjectsDifference(a, b, formatOptions, options) {
1609
+ const formatOptionsZeroIndent = { ...formatOptions, indent: 0 };
1610
+ const aCompare = index.format(a, formatOptionsZeroIndent);
1611
+ const bCompare = index.format(b, formatOptionsZeroIndent);
1612
+ if (aCompare === bCompare) {
1613
+ return getCommonMessage(NO_DIFF_MESSAGE, options);
1614
+ } else {
1615
+ const aDisplay = index.format(a, formatOptions);
1616
+ const bDisplay = index.format(b, formatOptions);
1617
+ return diffLinesUnified2(
1618
+ aDisplay.split("\n"),
1619
+ bDisplay.split("\n"),
1620
+ aCompare.split("\n"),
1621
+ bCompare.split("\n"),
1622
+ options
1623
+ );
1624
+ }
1625
+ }
1626
+ const MAX_DIFF_STRING_LENGTH = 2e4;
1627
+ function isAsymmetricMatcher(data) {
1628
+ const type = helpers.getType(data);
1629
+ return type === "Object" && typeof data.asymmetricMatch === "function";
1630
+ }
1631
+ function isReplaceable(obj1, obj2) {
1632
+ const obj1Type = helpers.getType(obj1);
1633
+ const obj2Type = helpers.getType(obj2);
1634
+ return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
1635
+ }
1636
+ function printDiffOrStringify(expected, received, options) {
1637
+ const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
1638
+ 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) {
1639
+ if (expected.includes("\n") || received.includes("\n")) {
1640
+ return diffStringsUnified(received, expected, options);
1641
+ }
1642
+ const [diffs] = diffStringsRaw(received, expected);
1643
+ const hasCommonDiff2 = diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
1644
+ const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
1645
+ const expectedLine = printLabel(aAnnotation) + printExpected(
1646
+ getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff2)
1647
+ );
1648
+ const receivedLine = printLabel(bAnnotation) + printReceived(
1649
+ getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff2)
1650
+ );
1651
+ return `${expectedLine}
1652
+ ${receivedLine}`;
1653
+ }
1654
+ const clonedExpected = helpers.deepClone(expected, { forceWritable: true });
1655
+ const clonedReceived = helpers.deepClone(received, { forceWritable: true });
1656
+ const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedExpected, clonedReceived);
1657
+ const difference = diff(replacedExpected, replacedActual, options);
1658
+ return difference;
1659
+ }
1660
+ function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
1661
+ if (!isReplaceable(actual, expected)) {
1662
+ return { replacedActual: actual, replacedExpected: expected };
1663
+ }
1664
+ if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
1665
+ return { replacedActual: actual, replacedExpected: expected };
1666
+ }
1667
+ actualReplaced.add(actual);
1668
+ expectedReplaced.add(expected);
1669
+ helpers.getOwnProperties(expected).forEach((key) => {
1670
+ const expectedValue = expected[key];
1671
+ const actualValue = actual[key];
1672
+ if (isAsymmetricMatcher(expectedValue)) {
1673
+ if (expectedValue.asymmetricMatch(actualValue)) {
1674
+ actual[key] = expectedValue;
1675
+ }
1676
+ } else if (isAsymmetricMatcher(actualValue)) {
1677
+ if (actualValue.asymmetricMatch(expectedValue)) {
1678
+ expected[key] = actualValue;
1679
+ }
1680
+ } else if (isReplaceable(actualValue, expectedValue)) {
1681
+ const replaced = replaceAsymmetricMatcher(
1682
+ actualValue,
1683
+ expectedValue,
1684
+ actualReplaced,
1685
+ expectedReplaced
1686
+ );
1687
+ actual[key] = replaced.replacedActual;
1688
+ expected[key] = replaced.replacedExpected;
1689
+ }
1690
+ });
1691
+ return {
1692
+ replacedActual: actual,
1693
+ replacedExpected: expected
1694
+ };
1695
+ }
1696
+ function getLabelPrinter(...strings) {
1697
+ const maxLength = strings.reduce(
1698
+ (max, string) => string.length > max ? string.length : max,
1699
+ 0
1700
+ );
1701
+ return (string) => `${string}: ${" ".repeat(maxLength - string.length)}`;
1702
+ }
1703
+ const SPACE_SYMBOL = "·";
1704
+ function replaceTrailingSpaces(text) {
1705
+ return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
1706
+ }
1707
+ function printReceived(object) {
1708
+ return browser.default.red(replaceTrailingSpaces(chunkDisplay.s(object)));
1709
+ }
1710
+ function printExpected(value) {
1711
+ return browser.default.green(replaceTrailingSpaces(chunkDisplay.s(value)));
1712
+ }
1713
+ function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff2) {
1714
+ return diffs.reduce(
1715
+ (reduced, diff2) => reduced + (diff2[0] === DIFF_EQUAL ? diff2[1] : diff2[0] === op ? hasCommonDiff2 ? browser.default.inverse(diff2[1]) : diff2[1] : ""),
1716
+ ""
1717
+ );
1718
+ }
1719
+ exports.DIFF_DELETE = DIFF_DELETE;
1720
+ exports.DIFF_EQUAL = DIFF_EQUAL;
1721
+ exports.DIFF_INSERT = DIFF_INSERT;
1722
+ exports.Diff = Diff;
1723
+ exports.diff = diff;
1724
+ exports.diffLinesRaw = diffLinesRaw;
1725
+ exports.diffLinesUnified = diffLinesUnified;
1726
+ exports.diffLinesUnified2 = diffLinesUnified2;
1727
+ exports.diffStringsRaw = diffStringsRaw;
1728
+ exports.diffStringsUnified = diffStringsUnified;
1729
+ exports.getLabelPrinter = getLabelPrinter;
1730
+ exports.printDiffOrStringify = printDiffOrStringify;
1731
+ exports.replaceAsymmetricMatcher = replaceAsymmetricMatcher;