decidim 0.27.3 → 0.27.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim might be problematic. Click here for more details.

Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +16 -2
  3. data/babel.config.json +1 -4
  4. data/lib/decidim/release_manager.rb.new +43 -0
  5. data/lib/decidim/version.rb +1 -1
  6. data/package-lock.json +343 -255
  7. data/packages/browserslist-config/package.json +1 -1
  8. data/packages/core/node_modules/diff/CONTRIBUTING.md +39 -0
  9. data/packages/core/node_modules/diff/LICENSE +31 -0
  10. data/packages/core/node_modules/diff/README.md +211 -0
  11. data/packages/core/node_modules/diff/dist/diff.js +1627 -0
  12. data/packages/core/node_modules/diff/dist/diff.min.js +38 -0
  13. data/packages/core/node_modules/diff/lib/convert/dmp.js +32 -0
  14. data/packages/core/node_modules/diff/lib/convert/xml.js +42 -0
  15. data/packages/core/node_modules/diff/lib/diff/array.js +45 -0
  16. data/packages/core/node_modules/diff/lib/diff/base.js +307 -0
  17. data/packages/core/node_modules/diff/lib/diff/character.js +37 -0
  18. data/packages/core/node_modules/diff/lib/diff/css.js +41 -0
  19. data/packages/core/node_modules/diff/lib/diff/json.js +163 -0
  20. data/packages/core/node_modules/diff/lib/diff/line.js +89 -0
  21. data/packages/core/node_modules/diff/lib/diff/sentence.js +41 -0
  22. data/packages/core/node_modules/diff/lib/diff/word.js +108 -0
  23. data/packages/core/node_modules/diff/lib/index.es6.js +1561 -0
  24. data/packages/core/node_modules/diff/lib/index.js +216 -0
  25. data/packages/core/node_modules/diff/lib/index.mjs +1561 -0
  26. data/packages/core/node_modules/diff/lib/patch/apply.js +238 -0
  27. data/packages/core/node_modules/diff/lib/patch/create.js +272 -0
  28. data/packages/core/node_modules/diff/lib/patch/merge.js +613 -0
  29. data/packages/core/node_modules/diff/lib/patch/parse.js +167 -0
  30. data/packages/core/node_modules/diff/lib/util/array.js +32 -0
  31. data/packages/core/node_modules/diff/lib/util/distance-iterator.js +57 -0
  32. data/packages/core/node_modules/diff/lib/util/params.js +24 -0
  33. data/packages/core/node_modules/diff/package.json +87 -0
  34. data/packages/core/node_modules/diff/release-notes.md +309 -0
  35. data/packages/core/node_modules/diff/runtime.js +3 -0
  36. data/packages/core/package-lock.json +4889 -0
  37. data/packages/core/package.json +1 -1
  38. data/packages/dev/package.json +1 -1
  39. data/packages/elections/package.json +1 -1
  40. data/packages/eslint-config/package.json +1 -1
  41. data/packages/stylelint-config/package.json +1 -1
  42. data/packages/webpacker/node_modules/argparse/CHANGELOG.md +216 -0
  43. data/packages/webpacker/node_modules/argparse/LICENSE +254 -0
  44. data/packages/webpacker/node_modules/argparse/README.md +84 -0
  45. data/packages/webpacker/node_modules/argparse/argparse.js +3707 -0
  46. data/packages/webpacker/node_modules/argparse/lib/sub.js +67 -0
  47. data/packages/webpacker/node_modules/argparse/lib/textwrap.js +440 -0
  48. data/packages/webpacker/node_modules/argparse/package.json +31 -0
  49. data/packages/{core/node_modules/uuid/LICENSE.md → webpacker/node_modules/brace-expansion/LICENSE} +2 -2
  50. data/packages/webpacker/node_modules/brace-expansion/README.md +135 -0
  51. data/packages/webpacker/node_modules/brace-expansion/index.js +203 -0
  52. data/packages/webpacker/node_modules/brace-expansion/package.json +46 -0
  53. data/packages/webpacker/node_modules/glob/LICENSE +15 -0
  54. data/packages/webpacker/node_modules/glob/README.md +1214 -0
  55. data/packages/webpacker/node_modules/glob/dist/cjs/package.json +4 -0
  56. data/packages/webpacker/node_modules/glob/dist/cjs/src/bin.d.ts +3 -0
  57. data/packages/webpacker/node_modules/glob/dist/cjs/src/bin.d.ts.map +1 -0
  58. data/packages/webpacker/node_modules/glob/dist/cjs/src/bin.js +270 -0
  59. data/packages/webpacker/node_modules/glob/dist/cjs/src/bin.js.map +1 -0
  60. data/packages/webpacker/node_modules/glob/dist/cjs/src/glob.d.ts +344 -0
  61. data/packages/webpacker/node_modules/glob/dist/cjs/src/glob.d.ts.map +1 -0
  62. data/packages/webpacker/node_modules/glob/dist/cjs/src/glob.js +238 -0
  63. data/packages/webpacker/node_modules/glob/dist/cjs/src/glob.js.map +1 -0
  64. data/packages/webpacker/node_modules/glob/dist/cjs/src/has-magic.d.ts +14 -0
  65. data/packages/webpacker/node_modules/glob/dist/cjs/src/has-magic.d.ts.map +1 -0
  66. data/packages/webpacker/node_modules/glob/dist/cjs/src/has-magic.js +27 -0
  67. data/packages/webpacker/node_modules/glob/dist/cjs/src/has-magic.js.map +1 -0
  68. data/packages/webpacker/node_modules/glob/dist/cjs/src/ignore.d.ts +20 -0
  69. data/packages/webpacker/node_modules/glob/dist/cjs/src/ignore.d.ts.map +1 -0
  70. data/packages/webpacker/node_modules/glob/dist/cjs/src/ignore.js +103 -0
  71. data/packages/webpacker/node_modules/glob/dist/cjs/src/ignore.js.map +1 -0
  72. data/packages/webpacker/node_modules/glob/dist/cjs/src/index.d.ts +95 -0
  73. data/packages/webpacker/node_modules/glob/dist/cjs/src/index.d.ts.map +1 -0
  74. data/packages/webpacker/node_modules/glob/dist/cjs/src/index.js +68 -0
  75. data/packages/webpacker/node_modules/glob/dist/cjs/src/index.js.map +1 -0
  76. data/packages/webpacker/node_modules/glob/dist/cjs/src/pattern.d.ts +77 -0
  77. data/packages/webpacker/node_modules/glob/dist/cjs/src/pattern.d.ts.map +1 -0
  78. data/packages/webpacker/node_modules/glob/dist/cjs/src/pattern.js +219 -0
  79. data/packages/webpacker/node_modules/glob/dist/cjs/src/pattern.js.map +1 -0
  80. data/packages/webpacker/node_modules/glob/dist/cjs/src/processor.d.ts +59 -0
  81. data/packages/webpacker/node_modules/glob/dist/cjs/src/processor.d.ts.map +1 -0
  82. data/packages/webpacker/node_modules/glob/dist/cjs/src/processor.js +309 -0
  83. data/packages/webpacker/node_modules/glob/dist/cjs/src/processor.js.map +1 -0
  84. data/packages/webpacker/node_modules/glob/dist/cjs/src/walker.d.ts +96 -0
  85. data/packages/webpacker/node_modules/glob/dist/cjs/src/walker.d.ts.map +1 -0
  86. data/packages/webpacker/node_modules/glob/dist/cjs/src/walker.js +358 -0
  87. data/packages/webpacker/node_modules/glob/dist/cjs/src/walker.js.map +1 -0
  88. data/packages/webpacker/node_modules/glob/dist/mjs/glob.d.ts +344 -0
  89. data/packages/webpacker/node_modules/glob/dist/mjs/glob.d.ts.map +1 -0
  90. data/packages/webpacker/node_modules/glob/dist/mjs/glob.js +234 -0
  91. data/packages/webpacker/node_modules/glob/dist/mjs/glob.js.map +1 -0
  92. data/packages/webpacker/node_modules/glob/dist/mjs/has-magic.d.ts +14 -0
  93. data/packages/webpacker/node_modules/glob/dist/mjs/has-magic.d.ts.map +1 -0
  94. data/packages/webpacker/node_modules/glob/dist/mjs/has-magic.js +23 -0
  95. data/packages/webpacker/node_modules/glob/dist/mjs/has-magic.js.map +1 -0
  96. data/packages/webpacker/node_modules/glob/dist/mjs/ignore.d.ts +20 -0
  97. data/packages/webpacker/node_modules/glob/dist/mjs/ignore.d.ts.map +1 -0
  98. data/packages/webpacker/node_modules/glob/dist/mjs/ignore.js +99 -0
  99. data/packages/webpacker/node_modules/glob/dist/mjs/ignore.js.map +1 -0
  100. data/packages/webpacker/node_modules/glob/dist/mjs/index.d.ts +95 -0
  101. data/packages/webpacker/node_modules/glob/dist/mjs/index.d.ts.map +1 -0
  102. data/packages/webpacker/node_modules/glob/dist/mjs/index.js +56 -0
  103. data/packages/webpacker/node_modules/glob/dist/mjs/index.js.map +1 -0
  104. data/packages/webpacker/node_modules/glob/dist/mjs/package.json +4 -0
  105. data/packages/webpacker/node_modules/glob/dist/mjs/pattern.d.ts +77 -0
  106. data/packages/webpacker/node_modules/glob/dist/mjs/pattern.d.ts.map +1 -0
  107. data/packages/webpacker/node_modules/glob/dist/mjs/pattern.js +215 -0
  108. data/packages/webpacker/node_modules/glob/dist/mjs/pattern.js.map +1 -0
  109. data/packages/webpacker/node_modules/glob/dist/mjs/processor.d.ts +59 -0
  110. data/packages/webpacker/node_modules/glob/dist/mjs/processor.d.ts.map +1 -0
  111. data/packages/webpacker/node_modules/glob/dist/mjs/processor.js +302 -0
  112. data/packages/webpacker/node_modules/glob/dist/mjs/processor.js.map +1 -0
  113. data/packages/webpacker/node_modules/glob/dist/mjs/walker.d.ts +96 -0
  114. data/packages/webpacker/node_modules/glob/dist/mjs/walker.d.ts.map +1 -0
  115. data/packages/webpacker/node_modules/glob/dist/mjs/walker.js +352 -0
  116. data/packages/webpacker/node_modules/glob/dist/mjs/walker.js.map +1 -0
  117. data/packages/webpacker/node_modules/glob/package.json +98 -0
  118. data/packages/webpacker/node_modules/js-yaml/CHANGELOG.md +616 -0
  119. data/packages/webpacker/node_modules/js-yaml/LICENSE +21 -0
  120. data/packages/webpacker/node_modules/js-yaml/README.md +246 -0
  121. data/packages/webpacker/node_modules/js-yaml/bin/js-yaml.js +126 -0
  122. data/packages/webpacker/node_modules/js-yaml/dist/js-yaml.js +3874 -0
  123. data/packages/webpacker/node_modules/js-yaml/dist/js-yaml.min.js +2 -0
  124. data/packages/webpacker/node_modules/js-yaml/dist/js-yaml.mjs +3851 -0
  125. data/packages/webpacker/node_modules/js-yaml/index.js +47 -0
  126. data/packages/webpacker/node_modules/js-yaml/lib/common.js +59 -0
  127. data/packages/webpacker/node_modules/js-yaml/lib/dumper.js +965 -0
  128. data/packages/webpacker/node_modules/js-yaml/lib/exception.js +55 -0
  129. data/packages/webpacker/node_modules/js-yaml/lib/loader.js +1727 -0
  130. data/packages/webpacker/node_modules/js-yaml/lib/schema/core.js +11 -0
  131. data/packages/webpacker/node_modules/js-yaml/lib/schema/default.js +22 -0
  132. data/packages/webpacker/node_modules/js-yaml/lib/schema/failsafe.js +17 -0
  133. data/packages/webpacker/node_modules/js-yaml/lib/schema/json.js +19 -0
  134. data/packages/webpacker/node_modules/js-yaml/lib/schema.js +121 -0
  135. data/packages/webpacker/node_modules/js-yaml/lib/snippet.js +101 -0
  136. data/packages/webpacker/node_modules/js-yaml/lib/type/binary.js +125 -0
  137. data/packages/webpacker/node_modules/js-yaml/lib/type/bool.js +35 -0
  138. data/packages/webpacker/node_modules/js-yaml/lib/type/float.js +97 -0
  139. data/packages/webpacker/node_modules/js-yaml/lib/type/int.js +156 -0
  140. data/packages/webpacker/node_modules/js-yaml/lib/type/map.js +8 -0
  141. data/packages/webpacker/node_modules/js-yaml/lib/type/merge.js +12 -0
  142. data/packages/webpacker/node_modules/js-yaml/lib/type/null.js +35 -0
  143. data/packages/webpacker/node_modules/js-yaml/lib/type/omap.js +44 -0
  144. data/packages/webpacker/node_modules/js-yaml/lib/type/pairs.js +53 -0
  145. data/packages/webpacker/node_modules/js-yaml/lib/type/seq.js +8 -0
  146. data/packages/webpacker/node_modules/js-yaml/lib/type/set.js +29 -0
  147. data/packages/webpacker/node_modules/js-yaml/lib/type/str.js +8 -0
  148. data/packages/webpacker/node_modules/js-yaml/lib/type/timestamp.js +88 -0
  149. data/packages/webpacker/node_modules/js-yaml/lib/type.js +66 -0
  150. data/packages/webpacker/node_modules/js-yaml/package.json +66 -0
  151. data/packages/webpacker/node_modules/minimatch/LICENSE +15 -0
  152. data/packages/webpacker/node_modules/minimatch/README.md +454 -0
  153. data/packages/webpacker/node_modules/minimatch/dist/cjs/assert-valid-pattern.d.ts +2 -0
  154. data/packages/webpacker/node_modules/minimatch/dist/cjs/assert-valid-pattern.d.ts.map +1 -0
  155. data/packages/webpacker/node_modules/minimatch/dist/cjs/assert-valid-pattern.js +14 -0
  156. data/packages/webpacker/node_modules/minimatch/dist/cjs/assert-valid-pattern.js.map +1 -0
  157. data/packages/webpacker/node_modules/minimatch/dist/cjs/ast.d.ts +19 -0
  158. data/packages/webpacker/node_modules/minimatch/dist/cjs/ast.d.ts.map +1 -0
  159. data/packages/webpacker/node_modules/minimatch/dist/cjs/ast.js +589 -0
  160. data/packages/webpacker/node_modules/minimatch/dist/cjs/ast.js.map +1 -0
  161. data/packages/webpacker/node_modules/minimatch/dist/cjs/brace-expressions.d.ts +8 -0
  162. data/packages/webpacker/node_modules/minimatch/dist/cjs/brace-expressions.d.ts.map +1 -0
  163. data/packages/webpacker/node_modules/minimatch/dist/cjs/brace-expressions.js +152 -0
  164. data/packages/webpacker/node_modules/minimatch/dist/cjs/brace-expressions.js.map +1 -0
  165. data/packages/webpacker/node_modules/minimatch/dist/cjs/escape.d.ts +12 -0
  166. data/packages/webpacker/node_modules/minimatch/dist/cjs/escape.d.ts.map +1 -0
  167. data/packages/webpacker/node_modules/minimatch/dist/cjs/escape.js +22 -0
  168. data/packages/webpacker/node_modules/minimatch/dist/cjs/escape.js.map +1 -0
  169. data/packages/webpacker/node_modules/minimatch/dist/cjs/index.d.ts +94 -0
  170. data/packages/webpacker/node_modules/minimatch/dist/cjs/index.d.ts.map +1 -0
  171. data/packages/webpacker/node_modules/minimatch/dist/cjs/index.js +1011 -0
  172. data/packages/webpacker/node_modules/minimatch/dist/cjs/index.js.map +1 -0
  173. data/packages/webpacker/node_modules/minimatch/dist/cjs/package.json +3 -0
  174. data/packages/webpacker/node_modules/minimatch/dist/cjs/unescape.d.ts +17 -0
  175. data/packages/webpacker/node_modules/minimatch/dist/cjs/unescape.d.ts.map +1 -0
  176. data/packages/webpacker/node_modules/minimatch/dist/cjs/unescape.js +24 -0
  177. data/packages/webpacker/node_modules/minimatch/dist/cjs/unescape.js.map +1 -0
  178. data/packages/webpacker/node_modules/minimatch/dist/mjs/assert-valid-pattern.d.ts +2 -0
  179. data/packages/webpacker/node_modules/minimatch/dist/mjs/assert-valid-pattern.d.ts.map +1 -0
  180. data/packages/webpacker/node_modules/minimatch/dist/mjs/assert-valid-pattern.js +10 -0
  181. data/packages/webpacker/node_modules/minimatch/dist/mjs/assert-valid-pattern.js.map +1 -0
  182. data/packages/webpacker/node_modules/minimatch/dist/mjs/ast.d.ts +19 -0
  183. data/packages/webpacker/node_modules/minimatch/dist/mjs/ast.d.ts.map +1 -0
  184. data/packages/webpacker/node_modules/minimatch/dist/mjs/ast.js +585 -0
  185. data/packages/webpacker/node_modules/minimatch/dist/mjs/ast.js.map +1 -0
  186. data/packages/webpacker/node_modules/minimatch/dist/mjs/brace-expressions.d.ts +8 -0
  187. data/packages/webpacker/node_modules/minimatch/dist/mjs/brace-expressions.d.ts.map +1 -0
  188. data/packages/webpacker/node_modules/minimatch/dist/mjs/brace-expressions.js +148 -0
  189. data/packages/webpacker/node_modules/minimatch/dist/mjs/brace-expressions.js.map +1 -0
  190. data/packages/webpacker/node_modules/minimatch/dist/mjs/escape.d.ts +12 -0
  191. data/packages/webpacker/node_modules/minimatch/dist/mjs/escape.d.ts.map +1 -0
  192. data/packages/webpacker/node_modules/minimatch/dist/mjs/escape.js +18 -0
  193. data/packages/webpacker/node_modules/minimatch/dist/mjs/escape.js.map +1 -0
  194. data/packages/webpacker/node_modules/minimatch/dist/mjs/index.d.ts +94 -0
  195. data/packages/webpacker/node_modules/minimatch/dist/mjs/index.d.ts.map +1 -0
  196. data/packages/webpacker/node_modules/minimatch/dist/mjs/index.js +995 -0
  197. data/packages/webpacker/node_modules/minimatch/dist/mjs/index.js.map +1 -0
  198. data/packages/webpacker/node_modules/minimatch/dist/mjs/package.json +3 -0
  199. data/packages/webpacker/node_modules/minimatch/dist/mjs/unescape.d.ts +17 -0
  200. data/packages/webpacker/node_modules/minimatch/dist/mjs/unescape.d.ts.map +1 -0
  201. data/packages/webpacker/node_modules/minimatch/dist/mjs/unescape.js +20 -0
  202. data/packages/webpacker/node_modules/minimatch/dist/mjs/unescape.js.map +1 -0
  203. data/packages/webpacker/node_modules/minimatch/package.json +86 -0
  204. data/packages/webpacker/package.json +2 -2
  205. metadata +237 -64
  206. data/packages/core/node_modules/uuid/AUTHORS +0 -5
  207. data/packages/core/node_modules/uuid/CHANGELOG.md +0 -119
  208. data/packages/core/node_modules/uuid/README.md +0 -276
  209. data/packages/core/node_modules/uuid/bin/uuid +0 -65
  210. data/packages/core/node_modules/uuid/index.js +0 -8
  211. data/packages/core/node_modules/uuid/lib/bytesToUuid.js +0 -26
  212. data/packages/core/node_modules/uuid/lib/md5-browser.js +0 -216
  213. data/packages/core/node_modules/uuid/lib/md5.js +0 -25
  214. data/packages/core/node_modules/uuid/lib/rng-browser.js +0 -34
  215. data/packages/core/node_modules/uuid/lib/rng.js +0 -8
  216. data/packages/core/node_modules/uuid/lib/sha1-browser.js +0 -89
  217. data/packages/core/node_modules/uuid/lib/sha1.js +0 -25
  218. data/packages/core/node_modules/uuid/lib/v35.js +0 -57
  219. data/packages/core/node_modules/uuid/package.json +0 -49
  220. data/packages/core/node_modules/uuid/v1.js +0 -109
  221. data/packages/core/node_modules/uuid/v3.js +0 -4
  222. data/packages/core/node_modules/uuid/v4.js +0 -29
  223. data/packages/core/node_modules/uuid/v5.js +0 -3
@@ -0,0 +1,1561 @@
1
+ function Diff() {}
2
+ Diff.prototype = {
3
+ diff: function diff(oldString, newString) {
4
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5
+ var callback = options.callback;
6
+
7
+ if (typeof options === 'function') {
8
+ callback = options;
9
+ options = {};
10
+ }
11
+
12
+ this.options = options;
13
+ var self = this;
14
+
15
+ function done(value) {
16
+ if (callback) {
17
+ setTimeout(function () {
18
+ callback(undefined, value);
19
+ }, 0);
20
+ return true;
21
+ } else {
22
+ return value;
23
+ }
24
+ } // Allow subclasses to massage the input prior to running
25
+
26
+
27
+ oldString = this.castInput(oldString);
28
+ newString = this.castInput(newString);
29
+ oldString = this.removeEmpty(this.tokenize(oldString));
30
+ newString = this.removeEmpty(this.tokenize(newString));
31
+ var newLen = newString.length,
32
+ oldLen = oldString.length;
33
+ var editLength = 1;
34
+ var maxEditLength = newLen + oldLen;
35
+
36
+ if (options.maxEditLength) {
37
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
38
+ }
39
+
40
+ var bestPath = [{
41
+ newPos: -1,
42
+ components: []
43
+ }]; // Seed editLength = 0, i.e. the content starts with the same values
44
+
45
+ var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
46
+
47
+ if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
48
+ // Identity per the equality and tokenizer
49
+ return done([{
50
+ value: this.join(newString),
51
+ count: newString.length
52
+ }]);
53
+ } // Main worker method. checks all permutations of a given edit length for acceptance.
54
+
55
+
56
+ function execEditLength() {
57
+ for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
58
+ var basePath = void 0;
59
+
60
+ var addPath = bestPath[diagonalPath - 1],
61
+ removePath = bestPath[diagonalPath + 1],
62
+ _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
63
+
64
+ if (addPath) {
65
+ // No one else is going to attempt to use this value, clear it
66
+ bestPath[diagonalPath - 1] = undefined;
67
+ }
68
+
69
+ var canAdd = addPath && addPath.newPos + 1 < newLen,
70
+ canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
71
+
72
+ if (!canAdd && !canRemove) {
73
+ // If this path is a terminal then prune
74
+ bestPath[diagonalPath] = undefined;
75
+ continue;
76
+ } // Select the diagonal that we want to branch from. We select the prior
77
+ // path whose position in the new string is the farthest from the origin
78
+ // and does not pass the bounds of the diff graph
79
+
80
+
81
+ if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
82
+ basePath = clonePath(removePath);
83
+ self.pushComponent(basePath.components, undefined, true);
84
+ } else {
85
+ basePath = addPath; // No need to clone, we've pulled it from the list
86
+
87
+ basePath.newPos++;
88
+ self.pushComponent(basePath.components, true, undefined);
89
+ }
90
+
91
+ _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
92
+
93
+ if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
94
+ return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
95
+ } else {
96
+ // Otherwise track this path as a potential candidate and continue.
97
+ bestPath[diagonalPath] = basePath;
98
+ }
99
+ }
100
+
101
+ editLength++;
102
+ } // Performs the length of edit iteration. Is a bit fugly as this has to support the
103
+ // sync and async mode which is never fun. Loops over execEditLength until a value
104
+ // is produced, or until the edit length exceeds options.maxEditLength (if given),
105
+ // in which case it will return undefined.
106
+
107
+
108
+ if (callback) {
109
+ (function exec() {
110
+ setTimeout(function () {
111
+ if (editLength > maxEditLength) {
112
+ return callback();
113
+ }
114
+
115
+ if (!execEditLength()) {
116
+ exec();
117
+ }
118
+ }, 0);
119
+ })();
120
+ } else {
121
+ while (editLength <= maxEditLength) {
122
+ var ret = execEditLength();
123
+
124
+ if (ret) {
125
+ return ret;
126
+ }
127
+ }
128
+ }
129
+ },
130
+ pushComponent: function pushComponent(components, added, removed) {
131
+ var last = components[components.length - 1];
132
+
133
+ if (last && last.added === added && last.removed === removed) {
134
+ // We need to clone here as the component clone operation is just
135
+ // as shallow array clone
136
+ components[components.length - 1] = {
137
+ count: last.count + 1,
138
+ added: added,
139
+ removed: removed
140
+ };
141
+ } else {
142
+ components.push({
143
+ count: 1,
144
+ added: added,
145
+ removed: removed
146
+ });
147
+ }
148
+ },
149
+ extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
150
+ var newLen = newString.length,
151
+ oldLen = oldString.length,
152
+ newPos = basePath.newPos,
153
+ oldPos = newPos - diagonalPath,
154
+ commonCount = 0;
155
+
156
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
157
+ newPos++;
158
+ oldPos++;
159
+ commonCount++;
160
+ }
161
+
162
+ if (commonCount) {
163
+ basePath.components.push({
164
+ count: commonCount
165
+ });
166
+ }
167
+
168
+ basePath.newPos = newPos;
169
+ return oldPos;
170
+ },
171
+ equals: function equals(left, right) {
172
+ if (this.options.comparator) {
173
+ return this.options.comparator(left, right);
174
+ } else {
175
+ return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
176
+ }
177
+ },
178
+ removeEmpty: function removeEmpty(array) {
179
+ var ret = [];
180
+
181
+ for (var i = 0; i < array.length; i++) {
182
+ if (array[i]) {
183
+ ret.push(array[i]);
184
+ }
185
+ }
186
+
187
+ return ret;
188
+ },
189
+ castInput: function castInput(value) {
190
+ return value;
191
+ },
192
+ tokenize: function tokenize(value) {
193
+ return value.split('');
194
+ },
195
+ join: function join(chars) {
196
+ return chars.join('');
197
+ }
198
+ };
199
+
200
+ function buildValues(diff, components, newString, oldString, useLongestToken) {
201
+ var componentPos = 0,
202
+ componentLen = components.length,
203
+ newPos = 0,
204
+ oldPos = 0;
205
+
206
+ for (; componentPos < componentLen; componentPos++) {
207
+ var component = components[componentPos];
208
+
209
+ if (!component.removed) {
210
+ if (!component.added && useLongestToken) {
211
+ var value = newString.slice(newPos, newPos + component.count);
212
+ value = value.map(function (value, i) {
213
+ var oldValue = oldString[oldPos + i];
214
+ return oldValue.length > value.length ? oldValue : value;
215
+ });
216
+ component.value = diff.join(value);
217
+ } else {
218
+ component.value = diff.join(newString.slice(newPos, newPos + component.count));
219
+ }
220
+
221
+ newPos += component.count; // Common case
222
+
223
+ if (!component.added) {
224
+ oldPos += component.count;
225
+ }
226
+ } else {
227
+ component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
228
+ oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
229
+ // The diffing algorithm is tied to add then remove output and this is the simplest
230
+ // route to get the desired output with minimal overhead.
231
+
232
+ if (componentPos && components[componentPos - 1].added) {
233
+ var tmp = components[componentPos - 1];
234
+ components[componentPos - 1] = components[componentPos];
235
+ components[componentPos] = tmp;
236
+ }
237
+ }
238
+ } // Special case handle for when one terminal is ignored (i.e. whitespace).
239
+ // For this case we merge the terminal into the prior string and drop the change.
240
+ // This is only available for string mode.
241
+
242
+
243
+ var lastComponent = components[componentLen - 1];
244
+
245
+ if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
246
+ components[componentLen - 2].value += lastComponent.value;
247
+ components.pop();
248
+ }
249
+
250
+ return components;
251
+ }
252
+
253
+ function clonePath(path) {
254
+ return {
255
+ newPos: path.newPos,
256
+ components: path.components.slice(0)
257
+ };
258
+ }
259
+
260
+ var characterDiff = new Diff();
261
+ function diffChars(oldStr, newStr, options) {
262
+ return characterDiff.diff(oldStr, newStr, options);
263
+ }
264
+
265
+ function generateOptions(options, defaults) {
266
+ if (typeof options === 'function') {
267
+ defaults.callback = options;
268
+ } else if (options) {
269
+ for (var name in options) {
270
+ /* istanbul ignore else */
271
+ if (options.hasOwnProperty(name)) {
272
+ defaults[name] = options[name];
273
+ }
274
+ }
275
+ }
276
+
277
+ return defaults;
278
+ }
279
+
280
+ //
281
+ // Ranges and exceptions:
282
+ // Latin-1 Supplement, 0080–00FF
283
+ // - U+00D7 × Multiplication sign
284
+ // - U+00F7 ÷ Division sign
285
+ // Latin Extended-A, 0100–017F
286
+ // Latin Extended-B, 0180–024F
287
+ // IPA Extensions, 0250–02AF
288
+ // Spacing Modifier Letters, 02B0–02FF
289
+ // - U+02C7 ˇ &#711; Caron
290
+ // - U+02D8 ˘ &#728; Breve
291
+ // - U+02D9 ˙ &#729; Dot Above
292
+ // - U+02DA ˚ &#730; Ring Above
293
+ // - U+02DB ˛ &#731; Ogonek
294
+ // - U+02DC ˜ &#732; Small Tilde
295
+ // - U+02DD ˝ &#733; Double Acute Accent
296
+ // Latin Extended Additional, 1E00–1EFF
297
+
298
+ var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
299
+ var reWhitespace = /\S/;
300
+ var wordDiff = new Diff();
301
+
302
+ wordDiff.equals = function (left, right) {
303
+ if (this.options.ignoreCase) {
304
+ left = left.toLowerCase();
305
+ right = right.toLowerCase();
306
+ }
307
+
308
+ return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
309
+ };
310
+
311
+ wordDiff.tokenize = function (value) {
312
+ // All whitespace symbols except newline group into one token, each newline - in separate token
313
+ var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
314
+
315
+ for (var i = 0; i < tokens.length - 1; i++) {
316
+ // If we have an empty string in the next field and we have only word chars before and after, merge
317
+ if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
318
+ tokens[i] += tokens[i + 2];
319
+ tokens.splice(i + 1, 2);
320
+ i--;
321
+ }
322
+ }
323
+
324
+ return tokens;
325
+ };
326
+
327
+ function diffWords(oldStr, newStr, options) {
328
+ options = generateOptions(options, {
329
+ ignoreWhitespace: true
330
+ });
331
+ return wordDiff.diff(oldStr, newStr, options);
332
+ }
333
+ function diffWordsWithSpace(oldStr, newStr, options) {
334
+ return wordDiff.diff(oldStr, newStr, options);
335
+ }
336
+
337
+ var lineDiff = new Diff();
338
+
339
+ lineDiff.tokenize = function (value) {
340
+ var retLines = [],
341
+ linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
342
+
343
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
344
+ linesAndNewlines.pop();
345
+ } // Merge the content and line separators into single tokens
346
+
347
+
348
+ for (var i = 0; i < linesAndNewlines.length; i++) {
349
+ var line = linesAndNewlines[i];
350
+
351
+ if (i % 2 && !this.options.newlineIsToken) {
352
+ retLines[retLines.length - 1] += line;
353
+ } else {
354
+ if (this.options.ignoreWhitespace) {
355
+ line = line.trim();
356
+ }
357
+
358
+ retLines.push(line);
359
+ }
360
+ }
361
+
362
+ return retLines;
363
+ };
364
+
365
+ function diffLines(oldStr, newStr, callback) {
366
+ return lineDiff.diff(oldStr, newStr, callback);
367
+ }
368
+ function diffTrimmedLines(oldStr, newStr, callback) {
369
+ var options = generateOptions(callback, {
370
+ ignoreWhitespace: true
371
+ });
372
+ return lineDiff.diff(oldStr, newStr, options);
373
+ }
374
+
375
+ var sentenceDiff = new Diff();
376
+
377
+ sentenceDiff.tokenize = function (value) {
378
+ return value.split(/(\S.+?[.!?])(?=\s+|$)/);
379
+ };
380
+
381
+ function diffSentences(oldStr, newStr, callback) {
382
+ return sentenceDiff.diff(oldStr, newStr, callback);
383
+ }
384
+
385
+ var cssDiff = new Diff();
386
+
387
+ cssDiff.tokenize = function (value) {
388
+ return value.split(/([{}:;,]|\s+)/);
389
+ };
390
+
391
+ function diffCss(oldStr, newStr, callback) {
392
+ return cssDiff.diff(oldStr, newStr, callback);
393
+ }
394
+
395
+ function _typeof(obj) {
396
+ "@babel/helpers - typeof";
397
+
398
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
399
+ _typeof = function (obj) {
400
+ return typeof obj;
401
+ };
402
+ } else {
403
+ _typeof = function (obj) {
404
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
405
+ };
406
+ }
407
+
408
+ return _typeof(obj);
409
+ }
410
+
411
+ function _toConsumableArray(arr) {
412
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
413
+ }
414
+
415
+ function _arrayWithoutHoles(arr) {
416
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
417
+ }
418
+
419
+ function _iterableToArray(iter) {
420
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
421
+ }
422
+
423
+ function _unsupportedIterableToArray(o, minLen) {
424
+ if (!o) return;
425
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
426
+ var n = Object.prototype.toString.call(o).slice(8, -1);
427
+ if (n === "Object" && o.constructor) n = o.constructor.name;
428
+ if (n === "Map" || n === "Set") return Array.from(o);
429
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
430
+ }
431
+
432
+ function _arrayLikeToArray(arr, len) {
433
+ if (len == null || len > arr.length) len = arr.length;
434
+
435
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
436
+
437
+ return arr2;
438
+ }
439
+
440
+ function _nonIterableSpread() {
441
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
442
+ }
443
+
444
+ var objectPrototypeToString = Object.prototype.toString;
445
+ var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
446
+ // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
447
+
448
+ jsonDiff.useLongestToken = true;
449
+ jsonDiff.tokenize = lineDiff.tokenize;
450
+
451
+ jsonDiff.castInput = function (value) {
452
+ var _this$options = this.options,
453
+ undefinedReplacement = _this$options.undefinedReplacement,
454
+ _this$options$stringi = _this$options.stringifyReplacer,
455
+ stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
456
+ return typeof v === 'undefined' ? undefinedReplacement : v;
457
+ } : _this$options$stringi;
458
+ return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
459
+ };
460
+
461
+ jsonDiff.equals = function (left, right) {
462
+ return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
463
+ };
464
+
465
+ function diffJson(oldObj, newObj, options) {
466
+ return jsonDiff.diff(oldObj, newObj, options);
467
+ } // This function handles the presence of circular references by bailing out when encountering an
468
+ // object that is already on the "stack" of items being processed. Accepts an optional replacer
469
+
470
+ function canonicalize(obj, stack, replacementStack, replacer, key) {
471
+ stack = stack || [];
472
+ replacementStack = replacementStack || [];
473
+
474
+ if (replacer) {
475
+ obj = replacer(key, obj);
476
+ }
477
+
478
+ var i;
479
+
480
+ for (i = 0; i < stack.length; i += 1) {
481
+ if (stack[i] === obj) {
482
+ return replacementStack[i];
483
+ }
484
+ }
485
+
486
+ var canonicalizedObj;
487
+
488
+ if ('[object Array]' === objectPrototypeToString.call(obj)) {
489
+ stack.push(obj);
490
+ canonicalizedObj = new Array(obj.length);
491
+ replacementStack.push(canonicalizedObj);
492
+
493
+ for (i = 0; i < obj.length; i += 1) {
494
+ canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
495
+ }
496
+
497
+ stack.pop();
498
+ replacementStack.pop();
499
+ return canonicalizedObj;
500
+ }
501
+
502
+ if (obj && obj.toJSON) {
503
+ obj = obj.toJSON();
504
+ }
505
+
506
+ if (_typeof(obj) === 'object' && obj !== null) {
507
+ stack.push(obj);
508
+ canonicalizedObj = {};
509
+ replacementStack.push(canonicalizedObj);
510
+
511
+ var sortedKeys = [],
512
+ _key;
513
+
514
+ for (_key in obj) {
515
+ /* istanbul ignore else */
516
+ if (obj.hasOwnProperty(_key)) {
517
+ sortedKeys.push(_key);
518
+ }
519
+ }
520
+
521
+ sortedKeys.sort();
522
+
523
+ for (i = 0; i < sortedKeys.length; i += 1) {
524
+ _key = sortedKeys[i];
525
+ canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
526
+ }
527
+
528
+ stack.pop();
529
+ replacementStack.pop();
530
+ } else {
531
+ canonicalizedObj = obj;
532
+ }
533
+
534
+ return canonicalizedObj;
535
+ }
536
+
537
+ var arrayDiff = new Diff();
538
+
539
+ arrayDiff.tokenize = function (value) {
540
+ return value.slice();
541
+ };
542
+
543
+ arrayDiff.join = arrayDiff.removeEmpty = function (value) {
544
+ return value;
545
+ };
546
+
547
+ function diffArrays(oldArr, newArr, callback) {
548
+ return arrayDiff.diff(oldArr, newArr, callback);
549
+ }
550
+
551
+ function parsePatch(uniDiff) {
552
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
553
+ var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
554
+ delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
555
+ list = [],
556
+ i = 0;
557
+
558
+ function parseIndex() {
559
+ var index = {};
560
+ list.push(index); // Parse diff metadata
561
+
562
+ while (i < diffstr.length) {
563
+ var line = diffstr[i]; // File header found, end parsing diff metadata
564
+
565
+ if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
566
+ break;
567
+ } // Diff index
568
+
569
+
570
+ var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
571
+
572
+ if (header) {
573
+ index.index = header[1];
574
+ }
575
+
576
+ i++;
577
+ } // Parse file headers if they are defined. Unified diff requires them, but
578
+ // there's no technical issues to have an isolated hunk without file header
579
+
580
+
581
+ parseFileHeader(index);
582
+ parseFileHeader(index); // Parse hunks
583
+
584
+ index.hunks = [];
585
+
586
+ while (i < diffstr.length) {
587
+ var _line = diffstr[i];
588
+
589
+ if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
590
+ break;
591
+ } else if (/^@@/.test(_line)) {
592
+ index.hunks.push(parseHunk());
593
+ } else if (_line && options.strict) {
594
+ // Ignore unexpected content unless in strict mode
595
+ throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
596
+ } else {
597
+ i++;
598
+ }
599
+ }
600
+ } // Parses the --- and +++ headers, if none are found, no lines
601
+ // are consumed.
602
+
603
+
604
+ function parseFileHeader(index) {
605
+ var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
606
+
607
+ if (fileHeader) {
608
+ var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
609
+ var data = fileHeader[2].split('\t', 2);
610
+ var fileName = data[0].replace(/\\\\/g, '\\');
611
+
612
+ if (/^".*"$/.test(fileName)) {
613
+ fileName = fileName.substr(1, fileName.length - 2);
614
+ }
615
+
616
+ index[keyPrefix + 'FileName'] = fileName;
617
+ index[keyPrefix + 'Header'] = (data[1] || '').trim();
618
+ i++;
619
+ }
620
+ } // Parses a hunk
621
+ // This assumes that we are at the start of a hunk.
622
+
623
+
624
+ function parseHunk() {
625
+ var chunkHeaderIndex = i,
626
+ chunkHeaderLine = diffstr[i++],
627
+ chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
628
+ var hunk = {
629
+ oldStart: +chunkHeader[1],
630
+ oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
631
+ newStart: +chunkHeader[3],
632
+ newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
633
+ lines: [],
634
+ linedelimiters: []
635
+ }; // Unified Diff Format quirk: If the chunk size is 0,
636
+ // the first number is one lower than one would expect.
637
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
638
+
639
+ if (hunk.oldLines === 0) {
640
+ hunk.oldStart += 1;
641
+ }
642
+
643
+ if (hunk.newLines === 0) {
644
+ hunk.newStart += 1;
645
+ }
646
+
647
+ var addCount = 0,
648
+ removeCount = 0;
649
+
650
+ for (; i < diffstr.length; i++) {
651
+ // Lines starting with '---' could be mistaken for the "remove line" operation
652
+ // But they could be the header for the next file. Therefore prune such cases out.
653
+ if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
654
+ break;
655
+ }
656
+
657
+ var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
658
+
659
+ if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
660
+ hunk.lines.push(diffstr[i]);
661
+ hunk.linedelimiters.push(delimiters[i] || '\n');
662
+
663
+ if (operation === '+') {
664
+ addCount++;
665
+ } else if (operation === '-') {
666
+ removeCount++;
667
+ } else if (operation === ' ') {
668
+ addCount++;
669
+ removeCount++;
670
+ }
671
+ } else {
672
+ break;
673
+ }
674
+ } // Handle the empty block count case
675
+
676
+
677
+ if (!addCount && hunk.newLines === 1) {
678
+ hunk.newLines = 0;
679
+ }
680
+
681
+ if (!removeCount && hunk.oldLines === 1) {
682
+ hunk.oldLines = 0;
683
+ } // Perform optional sanity checking
684
+
685
+
686
+ if (options.strict) {
687
+ if (addCount !== hunk.newLines) {
688
+ throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
689
+ }
690
+
691
+ if (removeCount !== hunk.oldLines) {
692
+ throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
693
+ }
694
+ }
695
+
696
+ return hunk;
697
+ }
698
+
699
+ while (i < diffstr.length) {
700
+ parseIndex();
701
+ }
702
+
703
+ return list;
704
+ }
705
+
706
+ // Iterator that traverses in the range of [min, max], stepping
707
+ // by distance from a given start position. I.e. for [0, 4], with
708
+ // start of 2, this will iterate 2, 3, 1, 4, 0.
709
+ function distanceIterator (start, minLine, maxLine) {
710
+ var wantForward = true,
711
+ backwardExhausted = false,
712
+ forwardExhausted = false,
713
+ localOffset = 1;
714
+ return function iterator() {
715
+ if (wantForward && !forwardExhausted) {
716
+ if (backwardExhausted) {
717
+ localOffset++;
718
+ } else {
719
+ wantForward = false;
720
+ } // Check if trying to fit beyond text length, and if not, check it fits
721
+ // after offset location (or desired location on first iteration)
722
+
723
+
724
+ if (start + localOffset <= maxLine) {
725
+ return localOffset;
726
+ }
727
+
728
+ forwardExhausted = true;
729
+ }
730
+
731
+ if (!backwardExhausted) {
732
+ if (!forwardExhausted) {
733
+ wantForward = true;
734
+ } // Check if trying to fit before text beginning, and if not, check it fits
735
+ // before offset location
736
+
737
+
738
+ if (minLine <= start - localOffset) {
739
+ return -localOffset++;
740
+ }
741
+
742
+ backwardExhausted = true;
743
+ return iterator();
744
+ } // We tried to fit hunk before text beginning and beyond text length, then
745
+ // hunk can't fit on the text. Return undefined
746
+
747
+ };
748
+ }
749
+
750
+ function applyPatch(source, uniDiff) {
751
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
752
+
753
+ if (typeof uniDiff === 'string') {
754
+ uniDiff = parsePatch(uniDiff);
755
+ }
756
+
757
+ if (Array.isArray(uniDiff)) {
758
+ if (uniDiff.length > 1) {
759
+ throw new Error('applyPatch only works with a single input.');
760
+ }
761
+
762
+ uniDiff = uniDiff[0];
763
+ } // Apply the diff to the input
764
+
765
+
766
+ var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
767
+ delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
768
+ hunks = uniDiff.hunks,
769
+ compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
770
+ return line === patchContent;
771
+ },
772
+ errorCount = 0,
773
+ fuzzFactor = options.fuzzFactor || 0,
774
+ minLine = 0,
775
+ offset = 0,
776
+ removeEOFNL,
777
+ addEOFNL;
778
+ /**
779
+ * Checks if the hunk exactly fits on the provided location
780
+ */
781
+
782
+
783
+ function hunkFits(hunk, toPos) {
784
+ for (var j = 0; j < hunk.lines.length; j++) {
785
+ var line = hunk.lines[j],
786
+ operation = line.length > 0 ? line[0] : ' ',
787
+ content = line.length > 0 ? line.substr(1) : line;
788
+
789
+ if (operation === ' ' || operation === '-') {
790
+ // Context sanity check
791
+ if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
792
+ errorCount++;
793
+
794
+ if (errorCount > fuzzFactor) {
795
+ return false;
796
+ }
797
+ }
798
+
799
+ toPos++;
800
+ }
801
+ }
802
+
803
+ return true;
804
+ } // Search best fit offsets for each hunk based on the previous ones
805
+
806
+
807
+ for (var i = 0; i < hunks.length; i++) {
808
+ var hunk = hunks[i],
809
+ maxLine = lines.length - hunk.oldLines,
810
+ localOffset = 0,
811
+ toPos = offset + hunk.oldStart - 1;
812
+ var iterator = distanceIterator(toPos, minLine, maxLine);
813
+
814
+ for (; localOffset !== undefined; localOffset = iterator()) {
815
+ if (hunkFits(hunk, toPos + localOffset)) {
816
+ hunk.offset = offset += localOffset;
817
+ break;
818
+ }
819
+ }
820
+
821
+ if (localOffset === undefined) {
822
+ return false;
823
+ } // Set lower text limit to end of the current hunk, so next ones don't try
824
+ // to fit over already patched text
825
+
826
+
827
+ minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
828
+ } // Apply patch hunks
829
+
830
+
831
+ var diffOffset = 0;
832
+
833
+ for (var _i = 0; _i < hunks.length; _i++) {
834
+ var _hunk = hunks[_i],
835
+ _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
836
+
837
+ diffOffset += _hunk.newLines - _hunk.oldLines;
838
+
839
+ for (var j = 0; j < _hunk.lines.length; j++) {
840
+ var line = _hunk.lines[j],
841
+ operation = line.length > 0 ? line[0] : ' ',
842
+ content = line.length > 0 ? line.substr(1) : line,
843
+ delimiter = _hunk.linedelimiters[j];
844
+
845
+ if (operation === ' ') {
846
+ _toPos++;
847
+ } else if (operation === '-') {
848
+ lines.splice(_toPos, 1);
849
+ delimiters.splice(_toPos, 1);
850
+ /* istanbul ignore else */
851
+ } else if (operation === '+') {
852
+ lines.splice(_toPos, 0, content);
853
+ delimiters.splice(_toPos, 0, delimiter);
854
+ _toPos++;
855
+ } else if (operation === '\\') {
856
+ var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
857
+
858
+ if (previousOperation === '+') {
859
+ removeEOFNL = true;
860
+ } else if (previousOperation === '-') {
861
+ addEOFNL = true;
862
+ }
863
+ }
864
+ }
865
+ } // Handle EOFNL insertion/removal
866
+
867
+
868
+ if (removeEOFNL) {
869
+ while (!lines[lines.length - 1]) {
870
+ lines.pop();
871
+ delimiters.pop();
872
+ }
873
+ } else if (addEOFNL) {
874
+ lines.push('');
875
+ delimiters.push('\n');
876
+ }
877
+
878
+ for (var _k = 0; _k < lines.length - 1; _k++) {
879
+ lines[_k] = lines[_k] + delimiters[_k];
880
+ }
881
+
882
+ return lines.join('');
883
+ } // Wrapper that supports multiple file patches via callbacks.
884
+
885
+ function applyPatches(uniDiff, options) {
886
+ if (typeof uniDiff === 'string') {
887
+ uniDiff = parsePatch(uniDiff);
888
+ }
889
+
890
+ var currentIndex = 0;
891
+
892
+ function processIndex() {
893
+ var index = uniDiff[currentIndex++];
894
+
895
+ if (!index) {
896
+ return options.complete();
897
+ }
898
+
899
+ options.loadFile(index, function (err, data) {
900
+ if (err) {
901
+ return options.complete(err);
902
+ }
903
+
904
+ var updatedContent = applyPatch(data, index, options);
905
+ options.patched(index, updatedContent, function (err) {
906
+ if (err) {
907
+ return options.complete(err);
908
+ }
909
+
910
+ processIndex();
911
+ });
912
+ });
913
+ }
914
+
915
+ processIndex();
916
+ }
917
+
918
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
919
+ if (!options) {
920
+ options = {};
921
+ }
922
+
923
+ if (typeof options.context === 'undefined') {
924
+ options.context = 4;
925
+ }
926
+
927
+ var diff = diffLines(oldStr, newStr, options);
928
+
929
+ if (!diff) {
930
+ return;
931
+ }
932
+
933
+ diff.push({
934
+ value: '',
935
+ lines: []
936
+ }); // Append an empty value to make cleanup easier
937
+
938
+ function contextLines(lines) {
939
+ return lines.map(function (entry) {
940
+ return ' ' + entry;
941
+ });
942
+ }
943
+
944
+ var hunks = [];
945
+ var oldRangeStart = 0,
946
+ newRangeStart = 0,
947
+ curRange = [],
948
+ oldLine = 1,
949
+ newLine = 1;
950
+
951
+ var _loop = function _loop(i) {
952
+ var current = diff[i],
953
+ lines = current.lines || current.value.replace(/\n$/, '').split('\n');
954
+ current.lines = lines;
955
+
956
+ if (current.added || current.removed) {
957
+ var _curRange;
958
+
959
+ // If we have previous context, start with that
960
+ if (!oldRangeStart) {
961
+ var prev = diff[i - 1];
962
+ oldRangeStart = oldLine;
963
+ newRangeStart = newLine;
964
+
965
+ if (prev) {
966
+ curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
967
+ oldRangeStart -= curRange.length;
968
+ newRangeStart -= curRange.length;
969
+ }
970
+ } // Output our changes
971
+
972
+
973
+ (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
974
+ return (current.added ? '+' : '-') + entry;
975
+ }))); // Track the updated file position
976
+
977
+
978
+ if (current.added) {
979
+ newLine += lines.length;
980
+ } else {
981
+ oldLine += lines.length;
982
+ }
983
+ } else {
984
+ // Identical context lines. Track line changes
985
+ if (oldRangeStart) {
986
+ // Close out any changes that have been output (or join overlapping)
987
+ if (lines.length <= options.context * 2 && i < diff.length - 2) {
988
+ var _curRange2;
989
+
990
+ // Overlapping
991
+ (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
992
+ } else {
993
+ var _curRange3;
994
+
995
+ // end the range and output
996
+ var contextSize = Math.min(lines.length, options.context);
997
+
998
+ (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
999
+
1000
+ var hunk = {
1001
+ oldStart: oldRangeStart,
1002
+ oldLines: oldLine - oldRangeStart + contextSize,
1003
+ newStart: newRangeStart,
1004
+ newLines: newLine - newRangeStart + contextSize,
1005
+ lines: curRange
1006
+ };
1007
+
1008
+ if (i >= diff.length - 2 && lines.length <= options.context) {
1009
+ // EOF is inside this hunk
1010
+ var oldEOFNewline = /\n$/.test(oldStr);
1011
+ var newEOFNewline = /\n$/.test(newStr);
1012
+ var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
1013
+
1014
+ if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
1015
+ // special case: old has no eol and no trailing context; no-nl can end up before adds
1016
+ // however, if the old file is empty, do not output the no-nl line
1017
+ curRange.splice(hunk.oldLines, 0, '\');
1018
+ }
1019
+
1020
+ if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
1021
+ curRange.push('\');
1022
+ }
1023
+ }
1024
+
1025
+ hunks.push(hunk);
1026
+ oldRangeStart = 0;
1027
+ newRangeStart = 0;
1028
+ curRange = [];
1029
+ }
1030
+ }
1031
+
1032
+ oldLine += lines.length;
1033
+ newLine += lines.length;
1034
+ }
1035
+ };
1036
+
1037
+ for (var i = 0; i < diff.length; i++) {
1038
+ _loop(i);
1039
+ }
1040
+
1041
+ return {
1042
+ oldFileName: oldFileName,
1043
+ newFileName: newFileName,
1044
+ oldHeader: oldHeader,
1045
+ newHeader: newHeader,
1046
+ hunks: hunks
1047
+ };
1048
+ }
1049
+ function formatPatch(diff) {
1050
+ var ret = [];
1051
+
1052
+ if (diff.oldFileName == diff.newFileName) {
1053
+ ret.push('Index: ' + diff.oldFileName);
1054
+ }
1055
+
1056
+ ret.push('===================================================================');
1057
+ ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
1058
+ ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
1059
+
1060
+ for (var i = 0; i < diff.hunks.length; i++) {
1061
+ var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
1062
+ // the first number is one lower than one would expect.
1063
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
1064
+
1065
+ if (hunk.oldLines === 0) {
1066
+ hunk.oldStart -= 1;
1067
+ }
1068
+
1069
+ if (hunk.newLines === 0) {
1070
+ hunk.newStart -= 1;
1071
+ }
1072
+
1073
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
1074
+ ret.push.apply(ret, hunk.lines);
1075
+ }
1076
+
1077
+ return ret.join('\n') + '\n';
1078
+ }
1079
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
1080
+ return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
1081
+ }
1082
+ function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
1083
+ return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
1084
+ }
1085
+
1086
+ function arrayEqual(a, b) {
1087
+ if (a.length !== b.length) {
1088
+ return false;
1089
+ }
1090
+
1091
+ return arrayStartsWith(a, b);
1092
+ }
1093
+ function arrayStartsWith(array, start) {
1094
+ if (start.length > array.length) {
1095
+ return false;
1096
+ }
1097
+
1098
+ for (var i = 0; i < start.length; i++) {
1099
+ if (start[i] !== array[i]) {
1100
+ return false;
1101
+ }
1102
+ }
1103
+
1104
+ return true;
1105
+ }
1106
+
1107
+ function calcLineCount(hunk) {
1108
+ var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
1109
+ oldLines = _calcOldNewLineCount.oldLines,
1110
+ newLines = _calcOldNewLineCount.newLines;
1111
+
1112
+ if (oldLines !== undefined) {
1113
+ hunk.oldLines = oldLines;
1114
+ } else {
1115
+ delete hunk.oldLines;
1116
+ }
1117
+
1118
+ if (newLines !== undefined) {
1119
+ hunk.newLines = newLines;
1120
+ } else {
1121
+ delete hunk.newLines;
1122
+ }
1123
+ }
1124
+ function merge(mine, theirs, base) {
1125
+ mine = loadPatch(mine, base);
1126
+ theirs = loadPatch(theirs, base);
1127
+ var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
1128
+ // Leaving sanity checks on this to the API consumer that may know more about the
1129
+ // meaning in their own context.
1130
+
1131
+ if (mine.index || theirs.index) {
1132
+ ret.index = mine.index || theirs.index;
1133
+ }
1134
+
1135
+ if (mine.newFileName || theirs.newFileName) {
1136
+ if (!fileNameChanged(mine)) {
1137
+ // No header or no change in ours, use theirs (and ours if theirs does not exist)
1138
+ ret.oldFileName = theirs.oldFileName || mine.oldFileName;
1139
+ ret.newFileName = theirs.newFileName || mine.newFileName;
1140
+ ret.oldHeader = theirs.oldHeader || mine.oldHeader;
1141
+ ret.newHeader = theirs.newHeader || mine.newHeader;
1142
+ } else if (!fileNameChanged(theirs)) {
1143
+ // No header or no change in theirs, use ours
1144
+ ret.oldFileName = mine.oldFileName;
1145
+ ret.newFileName = mine.newFileName;
1146
+ ret.oldHeader = mine.oldHeader;
1147
+ ret.newHeader = mine.newHeader;
1148
+ } else {
1149
+ // Both changed... figure it out
1150
+ ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
1151
+ ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
1152
+ ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
1153
+ ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
1154
+ }
1155
+ }
1156
+
1157
+ ret.hunks = [];
1158
+ var mineIndex = 0,
1159
+ theirsIndex = 0,
1160
+ mineOffset = 0,
1161
+ theirsOffset = 0;
1162
+
1163
+ while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
1164
+ var mineCurrent = mine.hunks[mineIndex] || {
1165
+ oldStart: Infinity
1166
+ },
1167
+ theirsCurrent = theirs.hunks[theirsIndex] || {
1168
+ oldStart: Infinity
1169
+ };
1170
+
1171
+ if (hunkBefore(mineCurrent, theirsCurrent)) {
1172
+ // This patch does not overlap with any of the others, yay.
1173
+ ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
1174
+ mineIndex++;
1175
+ theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
1176
+ } else if (hunkBefore(theirsCurrent, mineCurrent)) {
1177
+ // This patch does not overlap with any of the others, yay.
1178
+ ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
1179
+ theirsIndex++;
1180
+ mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
1181
+ } else {
1182
+ // Overlap, merge as best we can
1183
+ var mergedHunk = {
1184
+ oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
1185
+ oldLines: 0,
1186
+ newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
1187
+ newLines: 0,
1188
+ lines: []
1189
+ };
1190
+ mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
1191
+ theirsIndex++;
1192
+ mineIndex++;
1193
+ ret.hunks.push(mergedHunk);
1194
+ }
1195
+ }
1196
+
1197
+ return ret;
1198
+ }
1199
+
1200
+ function loadPatch(param, base) {
1201
+ if (typeof param === 'string') {
1202
+ if (/^@@/m.test(param) || /^Index:/m.test(param)) {
1203
+ return parsePatch(param)[0];
1204
+ }
1205
+
1206
+ if (!base) {
1207
+ throw new Error('Must provide a base reference or pass in a patch');
1208
+ }
1209
+
1210
+ return structuredPatch(undefined, undefined, base, param);
1211
+ }
1212
+
1213
+ return param;
1214
+ }
1215
+
1216
+ function fileNameChanged(patch) {
1217
+ return patch.newFileName && patch.newFileName !== patch.oldFileName;
1218
+ }
1219
+
1220
+ function selectField(index, mine, theirs) {
1221
+ if (mine === theirs) {
1222
+ return mine;
1223
+ } else {
1224
+ index.conflict = true;
1225
+ return {
1226
+ mine: mine,
1227
+ theirs: theirs
1228
+ };
1229
+ }
1230
+ }
1231
+
1232
+ function hunkBefore(test, check) {
1233
+ return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
1234
+ }
1235
+
1236
+ function cloneHunk(hunk, offset) {
1237
+ return {
1238
+ oldStart: hunk.oldStart,
1239
+ oldLines: hunk.oldLines,
1240
+ newStart: hunk.newStart + offset,
1241
+ newLines: hunk.newLines,
1242
+ lines: hunk.lines
1243
+ };
1244
+ }
1245
+
1246
+ function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
1247
+ // This will generally result in a conflicted hunk, but there are cases where the context
1248
+ // is the only overlap where we can successfully merge the content here.
1249
+ var mine = {
1250
+ offset: mineOffset,
1251
+ lines: mineLines,
1252
+ index: 0
1253
+ },
1254
+ their = {
1255
+ offset: theirOffset,
1256
+ lines: theirLines,
1257
+ index: 0
1258
+ }; // Handle any leading content
1259
+
1260
+ insertLeading(hunk, mine, their);
1261
+ insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
1262
+
1263
+ while (mine.index < mine.lines.length && their.index < their.lines.length) {
1264
+ var mineCurrent = mine.lines[mine.index],
1265
+ theirCurrent = their.lines[their.index];
1266
+
1267
+ if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
1268
+ // Both modified ...
1269
+ mutualChange(hunk, mine, their);
1270
+ } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
1271
+ var _hunk$lines;
1272
+
1273
+ // Mine inserted
1274
+ (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
1275
+ } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
1276
+ var _hunk$lines2;
1277
+
1278
+ // Theirs inserted
1279
+ (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
1280
+ } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
1281
+ // Mine removed or edited
1282
+ removal(hunk, mine, their);
1283
+ } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
1284
+ // Their removed or edited
1285
+ removal(hunk, their, mine, true);
1286
+ } else if (mineCurrent === theirCurrent) {
1287
+ // Context identity
1288
+ hunk.lines.push(mineCurrent);
1289
+ mine.index++;
1290
+ their.index++;
1291
+ } else {
1292
+ // Context mismatch
1293
+ conflict(hunk, collectChange(mine), collectChange(their));
1294
+ }
1295
+ } // Now push anything that may be remaining
1296
+
1297
+
1298
+ insertTrailing(hunk, mine);
1299
+ insertTrailing(hunk, their);
1300
+ calcLineCount(hunk);
1301
+ }
1302
+
1303
+ function mutualChange(hunk, mine, their) {
1304
+ var myChanges = collectChange(mine),
1305
+ theirChanges = collectChange(their);
1306
+
1307
+ if (allRemoves(myChanges) && allRemoves(theirChanges)) {
1308
+ // Special case for remove changes that are supersets of one another
1309
+ if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
1310
+ var _hunk$lines3;
1311
+
1312
+ (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
1313
+
1314
+ return;
1315
+ } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
1316
+ var _hunk$lines4;
1317
+
1318
+ (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
1319
+
1320
+ return;
1321
+ }
1322
+ } else if (arrayEqual(myChanges, theirChanges)) {
1323
+ var _hunk$lines5;
1324
+
1325
+ (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
1326
+
1327
+ return;
1328
+ }
1329
+
1330
+ conflict(hunk, myChanges, theirChanges);
1331
+ }
1332
+
1333
+ function removal(hunk, mine, their, swap) {
1334
+ var myChanges = collectChange(mine),
1335
+ theirChanges = collectContext(their, myChanges);
1336
+
1337
+ if (theirChanges.merged) {
1338
+ var _hunk$lines6;
1339
+
1340
+ (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
1341
+ } else {
1342
+ conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
1343
+ }
1344
+ }
1345
+
1346
+ function conflict(hunk, mine, their) {
1347
+ hunk.conflict = true;
1348
+ hunk.lines.push({
1349
+ conflict: true,
1350
+ mine: mine,
1351
+ theirs: their
1352
+ });
1353
+ }
1354
+
1355
+ function insertLeading(hunk, insert, their) {
1356
+ while (insert.offset < their.offset && insert.index < insert.lines.length) {
1357
+ var line = insert.lines[insert.index++];
1358
+ hunk.lines.push(line);
1359
+ insert.offset++;
1360
+ }
1361
+ }
1362
+
1363
+ function insertTrailing(hunk, insert) {
1364
+ while (insert.index < insert.lines.length) {
1365
+ var line = insert.lines[insert.index++];
1366
+ hunk.lines.push(line);
1367
+ }
1368
+ }
1369
+
1370
+ function collectChange(state) {
1371
+ var ret = [],
1372
+ operation = state.lines[state.index][0];
1373
+
1374
+ while (state.index < state.lines.length) {
1375
+ var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
1376
+
1377
+ if (operation === '-' && line[0] === '+') {
1378
+ operation = '+';
1379
+ }
1380
+
1381
+ if (operation === line[0]) {
1382
+ ret.push(line);
1383
+ state.index++;
1384
+ } else {
1385
+ break;
1386
+ }
1387
+ }
1388
+
1389
+ return ret;
1390
+ }
1391
+
1392
+ function collectContext(state, matchChanges) {
1393
+ var changes = [],
1394
+ merged = [],
1395
+ matchIndex = 0,
1396
+ contextChanges = false,
1397
+ conflicted = false;
1398
+
1399
+ while (matchIndex < matchChanges.length && state.index < state.lines.length) {
1400
+ var change = state.lines[state.index],
1401
+ match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
1402
+
1403
+ if (match[0] === '+') {
1404
+ break;
1405
+ }
1406
+
1407
+ contextChanges = contextChanges || change[0] !== ' ';
1408
+ merged.push(match);
1409
+ matchIndex++; // Consume any additions in the other block as a conflict to attempt
1410
+ // to pull in the remaining context after this
1411
+
1412
+ if (change[0] === '+') {
1413
+ conflicted = true;
1414
+
1415
+ while (change[0] === '+') {
1416
+ changes.push(change);
1417
+ change = state.lines[++state.index];
1418
+ }
1419
+ }
1420
+
1421
+ if (match.substr(1) === change.substr(1)) {
1422
+ changes.push(change);
1423
+ state.index++;
1424
+ } else {
1425
+ conflicted = true;
1426
+ }
1427
+ }
1428
+
1429
+ if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
1430
+ conflicted = true;
1431
+ }
1432
+
1433
+ if (conflicted) {
1434
+ return changes;
1435
+ }
1436
+
1437
+ while (matchIndex < matchChanges.length) {
1438
+ merged.push(matchChanges[matchIndex++]);
1439
+ }
1440
+
1441
+ return {
1442
+ merged: merged,
1443
+ changes: changes
1444
+ };
1445
+ }
1446
+
1447
+ function allRemoves(changes) {
1448
+ return changes.reduce(function (prev, change) {
1449
+ return prev && change[0] === '-';
1450
+ }, true);
1451
+ }
1452
+
1453
+ function skipRemoveSuperset(state, removeChanges, delta) {
1454
+ for (var i = 0; i < delta; i++) {
1455
+ var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
1456
+
1457
+ if (state.lines[state.index + i] !== ' ' + changeContent) {
1458
+ return false;
1459
+ }
1460
+ }
1461
+
1462
+ state.index += delta;
1463
+ return true;
1464
+ }
1465
+
1466
+ function calcOldNewLineCount(lines) {
1467
+ var oldLines = 0;
1468
+ var newLines = 0;
1469
+ lines.forEach(function (line) {
1470
+ if (typeof line !== 'string') {
1471
+ var myCount = calcOldNewLineCount(line.mine);
1472
+ var theirCount = calcOldNewLineCount(line.theirs);
1473
+
1474
+ if (oldLines !== undefined) {
1475
+ if (myCount.oldLines === theirCount.oldLines) {
1476
+ oldLines += myCount.oldLines;
1477
+ } else {
1478
+ oldLines = undefined;
1479
+ }
1480
+ }
1481
+
1482
+ if (newLines !== undefined) {
1483
+ if (myCount.newLines === theirCount.newLines) {
1484
+ newLines += myCount.newLines;
1485
+ } else {
1486
+ newLines = undefined;
1487
+ }
1488
+ }
1489
+ } else {
1490
+ if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
1491
+ newLines++;
1492
+ }
1493
+
1494
+ if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
1495
+ oldLines++;
1496
+ }
1497
+ }
1498
+ });
1499
+ return {
1500
+ oldLines: oldLines,
1501
+ newLines: newLines
1502
+ };
1503
+ }
1504
+
1505
+ // See: http://code.google.com/p/google-diff-match-patch/wiki/API
1506
+ function convertChangesToDMP(changes) {
1507
+ var ret = [],
1508
+ change,
1509
+ operation;
1510
+
1511
+ for (var i = 0; i < changes.length; i++) {
1512
+ change = changes[i];
1513
+
1514
+ if (change.added) {
1515
+ operation = 1;
1516
+ } else if (change.removed) {
1517
+ operation = -1;
1518
+ } else {
1519
+ operation = 0;
1520
+ }
1521
+
1522
+ ret.push([operation, change.value]);
1523
+ }
1524
+
1525
+ return ret;
1526
+ }
1527
+
1528
+ function convertChangesToXML(changes) {
1529
+ var ret = [];
1530
+
1531
+ for (var i = 0; i < changes.length; i++) {
1532
+ var change = changes[i];
1533
+
1534
+ if (change.added) {
1535
+ ret.push('<ins>');
1536
+ } else if (change.removed) {
1537
+ ret.push('<del>');
1538
+ }
1539
+
1540
+ ret.push(escapeHTML(change.value));
1541
+
1542
+ if (change.added) {
1543
+ ret.push('</ins>');
1544
+ } else if (change.removed) {
1545
+ ret.push('</del>');
1546
+ }
1547
+ }
1548
+
1549
+ return ret.join('');
1550
+ }
1551
+
1552
+ function escapeHTML(s) {
1553
+ var n = s;
1554
+ n = n.replace(/&/g, '&amp;');
1555
+ n = n.replace(/</g, '&lt;');
1556
+ n = n.replace(/>/g, '&gt;');
1557
+ n = n.replace(/"/g, '&quot;');
1558
+ return n;
1559
+ }
1560
+
1561
+ export { Diff, applyPatch, applyPatches, canonicalize, convertChangesToDMP, convertChangesToXML, createPatch, createTwoFilesPatch, diffArrays, diffChars, diffCss, diffJson, diffLines, diffSentences, diffTrimmedLines, diffWords, diffWordsWithSpace, merge, parsePatch, structuredPatch };