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