bgm-wiki-rev-diff

show diff between bgm.tv wiki versions

目前为 2020-04-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name bgm-wiki-rev-diff
  3. // @namespace https://trim21.me/
  4. // @version 0.0.1
  5. // @author Trim21 <i@trim21.me>
  6. // @source https://github.com/Trim21/bgm-wiki-rev-diff
  7. // @license MIT
  8. // @match https://bgm.tv/subject/*/edit*
  9. // @require https://cdn.jsdelivr.net/npm/jquery@^3.5.0/dist/jquery.min.js
  10. // @grant GM_xmlhttpRequest
  11. // @connect bgm.tv
  12. // @run-at document-end
  13. // @description show diff between bgm.tv wiki versions
  14. // ==/UserScript==
  15.  
  16. /******/ (function(modules) { // webpackBootstrap
  17. /******/ // The module cache
  18. /******/ var installedModules = {};
  19. /******/
  20. /******/ // The require function
  21. /******/ function __webpack_require__(moduleId) {
  22. /******/
  23. /******/ // Check if module is in cache
  24. /******/ if(installedModules[moduleId]) {
  25. /******/ return installedModules[moduleId].exports;
  26. /******/ }
  27. /******/ // Create a new module (and put it into the cache)
  28. /******/ var module = installedModules[moduleId] = {
  29. /******/ i: moduleId,
  30. /******/ l: false,
  31. /******/ exports: {}
  32. /******/ };
  33. /******/
  34. /******/ // Execute the module function
  35. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  36. /******/
  37. /******/ // Flag the module as loaded
  38. /******/ module.l = true;
  39. /******/
  40. /******/ // Return the exports of the module
  41. /******/ return module.exports;
  42. /******/ }
  43. /******/
  44. /******/
  45. /******/ // expose the modules object (__webpack_modules__)
  46. /******/ __webpack_require__.m = modules;
  47. /******/
  48. /******/ // expose the module cache
  49. /******/ __webpack_require__.c = installedModules;
  50. /******/
  51. /******/ // define getter function for harmony exports
  52. /******/ __webpack_require__.d = function(exports, name, getter) {
  53. /******/ if(!__webpack_require__.o(exports, name)) {
  54. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  55. /******/ }
  56. /******/ };
  57. /******/
  58. /******/ // define __esModule on exports
  59. /******/ __webpack_require__.r = function(exports) {
  60. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  61. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  62. /******/ }
  63. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  64. /******/ };
  65. /******/
  66. /******/ // create a fake namespace object
  67. /******/ // mode & 1: value is a module id, require it
  68. /******/ // mode & 2: merge all properties of value into the ns
  69. /******/ // mode & 4: return value when already ns object
  70. /******/ // mode & 8|1: behave like require
  71. /******/ __webpack_require__.t = function(value, mode) {
  72. /******/ if(mode & 1) value = __webpack_require__(value);
  73. /******/ if(mode & 8) return value;
  74. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  75. /******/ var ns = Object.create(null);
  76. /******/ __webpack_require__.r(ns);
  77. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  78. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  79. /******/ return ns;
  80. /******/ };
  81. /******/
  82. /******/ // getDefaultExport function for compatibility with non-harmony modules
  83. /******/ __webpack_require__.n = function(module) {
  84. /******/ var getter = module && module.__esModule ?
  85. /******/ function getDefault() { return module['default']; } :
  86. /******/ function getModuleExports() { return module; };
  87. /******/ __webpack_require__.d(getter, 'a', getter);
  88. /******/ return getter;
  89. /******/ };
  90. /******/
  91. /******/ // Object.prototype.hasOwnProperty.call
  92. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  93. /******/
  94. /******/ // __webpack_public_path__
  95. /******/ __webpack_require__.p = "";
  96. /******/
  97. /******/
  98. /******/ // Load entry module and return exports
  99. /******/ return __webpack_require__(__webpack_require__.s = "e6Wu");
  100. /******/ })
  101. /************************************************************************/
  102. /******/ ({
  103.  
  104. /***/ "1gqn":
  105. /***/ (function(module, exports) {
  106.  
  107. module.exports = function isBuffer(arg) {
  108. return arg && typeof arg === 'object'
  109. && typeof arg.copy === 'function'
  110. && typeof arg.fill === 'function'
  111. && typeof arg.readUInt8 === 'function';
  112. }
  113.  
  114. /***/ }),
  115.  
  116. /***/ "7Mwc":
  117. /***/ (function(module, exports, __webpack_require__) {
  118.  
  119. module.exports = __webpack_require__("qVjC");
  120.  
  121.  
  122. /***/ }),
  123.  
  124. /***/ "8oxB":
  125. /***/ (function(module, exports) {
  126.  
  127. // shim for using process in browser
  128. var process = module.exports = {};
  129.  
  130. // cached from whatever global is present so that test runners that stub it
  131. // don't break things. But we need to wrap it in a try catch in case it is
  132. // wrapped in strict mode code which doesn't define any globals. It's inside a
  133. // function because try/catches deoptimize in certain engines.
  134.  
  135. var cachedSetTimeout;
  136. var cachedClearTimeout;
  137.  
  138. function defaultSetTimout() {
  139. throw new Error('setTimeout has not been defined');
  140. }
  141. function defaultClearTimeout () {
  142. throw new Error('clearTimeout has not been defined');
  143. }
  144. (function () {
  145. try {
  146. if (typeof setTimeout === 'function') {
  147. cachedSetTimeout = setTimeout;
  148. } else {
  149. cachedSetTimeout = defaultSetTimout;
  150. }
  151. } catch (e) {
  152. cachedSetTimeout = defaultSetTimout;
  153. }
  154. try {
  155. if (typeof clearTimeout === 'function') {
  156. cachedClearTimeout = clearTimeout;
  157. } else {
  158. cachedClearTimeout = defaultClearTimeout;
  159. }
  160. } catch (e) {
  161. cachedClearTimeout = defaultClearTimeout;
  162. }
  163. } ())
  164. function runTimeout(fun) {
  165. if (cachedSetTimeout === setTimeout) {
  166. //normal enviroments in sane situations
  167. return setTimeout(fun, 0);
  168. }
  169. // if setTimeout wasn't available but was latter defined
  170. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  171. cachedSetTimeout = setTimeout;
  172. return setTimeout(fun, 0);
  173. }
  174. try {
  175. // when when somebody has screwed with setTimeout but no I.E. maddness
  176. return cachedSetTimeout(fun, 0);
  177. } catch(e){
  178. try {
  179. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  180. return cachedSetTimeout.call(null, fun, 0);
  181. } catch(e){
  182. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  183. return cachedSetTimeout.call(this, fun, 0);
  184. }
  185. }
  186.  
  187.  
  188. }
  189. function runClearTimeout(marker) {
  190. if (cachedClearTimeout === clearTimeout) {
  191. //normal enviroments in sane situations
  192. return clearTimeout(marker);
  193. }
  194. // if clearTimeout wasn't available but was latter defined
  195. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  196. cachedClearTimeout = clearTimeout;
  197. return clearTimeout(marker);
  198. }
  199. try {
  200. // when when somebody has screwed with setTimeout but no I.E. maddness
  201. return cachedClearTimeout(marker);
  202. } catch (e){
  203. try {
  204. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  205. return cachedClearTimeout.call(null, marker);
  206. } catch (e){
  207. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  208. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  209. return cachedClearTimeout.call(this, marker);
  210. }
  211. }
  212.  
  213.  
  214.  
  215. }
  216. var queue = [];
  217. var draining = false;
  218. var currentQueue;
  219. var queueIndex = -1;
  220.  
  221. function cleanUpNextTick() {
  222. if (!draining || !currentQueue) {
  223. return;
  224. }
  225. draining = false;
  226. if (currentQueue.length) {
  227. queue = currentQueue.concat(queue);
  228. } else {
  229. queueIndex = -1;
  230. }
  231. if (queue.length) {
  232. drainQueue();
  233. }
  234. }
  235.  
  236. function drainQueue() {
  237. if (draining) {
  238. return;
  239. }
  240. var timeout = runTimeout(cleanUpNextTick);
  241. draining = true;
  242.  
  243. var len = queue.length;
  244. while(len) {
  245. currentQueue = queue;
  246. queue = [];
  247. while (++queueIndex < len) {
  248. if (currentQueue) {
  249. currentQueue[queueIndex].run();
  250. }
  251. }
  252. queueIndex = -1;
  253. len = queue.length;
  254. }
  255. currentQueue = null;
  256. draining = false;
  257. runClearTimeout(timeout);
  258. }
  259.  
  260. process.nextTick = function (fun) {
  261. var args = new Array(arguments.length - 1);
  262. if (arguments.length > 1) {
  263. for (var i = 1; i < arguments.length; i++) {
  264. args[i - 1] = arguments[i];
  265. }
  266. }
  267. queue.push(new Item(fun, args));
  268. if (queue.length === 1 && !draining) {
  269. runTimeout(drainQueue);
  270. }
  271. };
  272.  
  273. // v8 likes predictible objects
  274. function Item(fun, array) {
  275. this.fun = fun;
  276. this.array = array;
  277. }
  278. Item.prototype.run = function () {
  279. this.fun.apply(null, this.array);
  280. };
  281. process.title = 'browser';
  282. process.browser = true;
  283. process.env = {};
  284. process.argv = [];
  285. process.version = ''; // empty string to avoid regexp issues
  286. process.versions = {};
  287.  
  288. function noop() {}
  289.  
  290. process.on = noop;
  291. process.addListener = noop;
  292. process.once = noop;
  293. process.off = noop;
  294. process.removeListener = noop;
  295. process.removeAllListeners = noop;
  296. process.emit = noop;
  297. process.prependListener = noop;
  298. process.prependOnceListener = noop;
  299.  
  300. process.listeners = function (name) { return [] }
  301.  
  302. process.binding = function (name) {
  303. throw new Error('process.binding is not supported');
  304. };
  305.  
  306. process.cwd = function () { return '/' };
  307. process.chdir = function (dir) {
  308. throw new Error('process.chdir is not supported');
  309. };
  310. process.umask = function() { return 0; };
  311.  
  312.  
  313. /***/ }),
  314.  
  315. /***/ "9lTW":
  316. /***/ (function(module, exports, __webpack_require__) {
  317.  
  318. "use strict";
  319. /* WEBPACK VAR INJECTION */(function(global) {
  320.  
  321. var objectAssign = __webpack_require__("MgzW");
  322.  
  323. // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
  324. // original notice:
  325.  
  326. /*!
  327. * The buffer module from node.js, for the browser.
  328. *
  329. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  330. * @license MIT
  331. */
  332. function compare(a, b) {
  333. if (a === b) {
  334. return 0;
  335. }
  336.  
  337. var x = a.length;
  338. var y = b.length;
  339.  
  340. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  341. if (a[i] !== b[i]) {
  342. x = a[i];
  343. y = b[i];
  344. break;
  345. }
  346. }
  347.  
  348. if (x < y) {
  349. return -1;
  350. }
  351. if (y < x) {
  352. return 1;
  353. }
  354. return 0;
  355. }
  356. function isBuffer(b) {
  357. if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
  358. return global.Buffer.isBuffer(b);
  359. }
  360. return !!(b != null && b._isBuffer);
  361. }
  362.  
  363. // based on node assert, original notice:
  364. // NB: The URL to the CommonJS spec is kept just for tradition.
  365. // node-assert has evolved a lot since then, both in API and behavior.
  366.  
  367. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  368. //
  369. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  370. //
  371. // Originally from narwhal.js (http://narwhaljs.org)
  372. // Copyright (c) 2009 Thomas Robinson <280north.com>
  373. //
  374. // Permission is hereby granted, free of charge, to any person obtaining a copy
  375. // of this software and associated documentation files (the 'Software'), to
  376. // deal in the Software without restriction, including without limitation the
  377. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  378. // sell copies of the Software, and to permit persons to whom the Software is
  379. // furnished to do so, subject to the following conditions:
  380. //
  381. // The above copyright notice and this permission notice shall be included in
  382. // all copies or substantial portions of the Software.
  383. //
  384. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  385. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  386. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  387. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  388. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  389. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  390.  
  391. var util = __webpack_require__("MCLT");
  392. var hasOwn = Object.prototype.hasOwnProperty;
  393. var pSlice = Array.prototype.slice;
  394. var functionsHaveNames = (function () {
  395. return function foo() {}.name === 'foo';
  396. }());
  397. function pToString (obj) {
  398. return Object.prototype.toString.call(obj);
  399. }
  400. function isView(arrbuf) {
  401. if (isBuffer(arrbuf)) {
  402. return false;
  403. }
  404. if (typeof global.ArrayBuffer !== 'function') {
  405. return false;
  406. }
  407. if (typeof ArrayBuffer.isView === 'function') {
  408. return ArrayBuffer.isView(arrbuf);
  409. }
  410. if (!arrbuf) {
  411. return false;
  412. }
  413. if (arrbuf instanceof DataView) {
  414. return true;
  415. }
  416. if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
  417. return true;
  418. }
  419. return false;
  420. }
  421. // 1. The assert module provides functions that throw
  422. // AssertionError's when particular conditions are not met. The
  423. // assert module must conform to the following interface.
  424.  
  425. var assert = module.exports = ok;
  426.  
  427. // 2. The AssertionError is defined in assert.
  428. // new assert.AssertionError({ message: message,
  429. // actual: actual,
  430. // expected: expected })
  431.  
  432. var regex = /\s*function\s+([^\(\s]*)\s*/;
  433. // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
  434. function getName(func) {
  435. if (!util.isFunction(func)) {
  436. return;
  437. }
  438. if (functionsHaveNames) {
  439. return func.name;
  440. }
  441. var str = func.toString();
  442. var match = str.match(regex);
  443. return match && match[1];
  444. }
  445. assert.AssertionError = function AssertionError(options) {
  446. this.name = 'AssertionError';
  447. this.actual = options.actual;
  448. this.expected = options.expected;
  449. this.operator = options.operator;
  450. if (options.message) {
  451. this.message = options.message;
  452. this.generatedMessage = false;
  453. } else {
  454. this.message = getMessage(this);
  455. this.generatedMessage = true;
  456. }
  457. var stackStartFunction = options.stackStartFunction || fail;
  458. if (Error.captureStackTrace) {
  459. Error.captureStackTrace(this, stackStartFunction);
  460. } else {
  461. // non v8 browsers so we can have a stacktrace
  462. var err = new Error();
  463. if (err.stack) {
  464. var out = err.stack;
  465.  
  466. // try to strip useless frames
  467. var fn_name = getName(stackStartFunction);
  468. var idx = out.indexOf('\n' + fn_name);
  469. if (idx >= 0) {
  470. // once we have located the function frame
  471. // we need to strip out everything before it (and its line)
  472. var next_line = out.indexOf('\n', idx + 1);
  473. out = out.substring(next_line + 1);
  474. }
  475.  
  476. this.stack = out;
  477. }
  478. }
  479. };
  480.  
  481. // assert.AssertionError instanceof Error
  482. util.inherits(assert.AssertionError, Error);
  483.  
  484. function truncate(s, n) {
  485. if (typeof s === 'string') {
  486. return s.length < n ? s : s.slice(0, n);
  487. } else {
  488. return s;
  489. }
  490. }
  491. function inspect(something) {
  492. if (functionsHaveNames || !util.isFunction(something)) {
  493. return util.inspect(something);
  494. }
  495. var rawname = getName(something);
  496. var name = rawname ? ': ' + rawname : '';
  497. return '[Function' + name + ']';
  498. }
  499. function getMessage(self) {
  500. return truncate(inspect(self.actual), 128) + ' ' +
  501. self.operator + ' ' +
  502. truncate(inspect(self.expected), 128);
  503. }
  504.  
  505. // At present only the three keys mentioned above are used and
  506. // understood by the spec. Implementations or sub modules can pass
  507. // other keys to the AssertionError's constructor - they will be
  508. // ignored.
  509.  
  510. // 3. All of the following functions must throw an AssertionError
  511. // when a corresponding condition is not met, with a message that
  512. // may be undefined if not provided. All assertion methods provide
  513. // both the actual and expected values to the assertion error for
  514. // display purposes.
  515.  
  516. function fail(actual, expected, message, operator, stackStartFunction) {
  517. throw new assert.AssertionError({
  518. message: message,
  519. actual: actual,
  520. expected: expected,
  521. operator: operator,
  522. stackStartFunction: stackStartFunction
  523. });
  524. }
  525.  
  526. // EXTENSION! allows for well behaved errors defined elsewhere.
  527. assert.fail = fail;
  528.  
  529. // 4. Pure assertion tests whether a value is truthy, as determined
  530. // by !!guard.
  531. // assert.ok(guard, message_opt);
  532. // This statement is equivalent to assert.equal(true, !!guard,
  533. // message_opt);. To test strictly for the value true, use
  534. // assert.strictEqual(true, guard, message_opt);.
  535.  
  536. function ok(value, message) {
  537. if (!value) fail(value, true, message, '==', assert.ok);
  538. }
  539. assert.ok = ok;
  540.  
  541. // 5. The equality assertion tests shallow, coercive equality with
  542. // ==.
  543. // assert.equal(actual, expected, message_opt);
  544.  
  545. assert.equal = function equal(actual, expected, message) {
  546. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  547. };
  548.  
  549. // 6. The non-equality assertion tests for whether two objects are not equal
  550. // with != assert.notEqual(actual, expected, message_opt);
  551.  
  552. assert.notEqual = function notEqual(actual, expected, message) {
  553. if (actual == expected) {
  554. fail(actual, expected, message, '!=', assert.notEqual);
  555. }
  556. };
  557.  
  558. // 7. The equivalence assertion tests a deep equality relation.
  559. // assert.deepEqual(actual, expected, message_opt);
  560.  
  561. assert.deepEqual = function deepEqual(actual, expected, message) {
  562. if (!_deepEqual(actual, expected, false)) {
  563. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  564. }
  565. };
  566.  
  567. assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
  568. if (!_deepEqual(actual, expected, true)) {
  569. fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
  570. }
  571. };
  572.  
  573. function _deepEqual(actual, expected, strict, memos) {
  574. // 7.1. All identical values are equivalent, as determined by ===.
  575. if (actual === expected) {
  576. return true;
  577. } else if (isBuffer(actual) && isBuffer(expected)) {
  578. return compare(actual, expected) === 0;
  579.  
  580. // 7.2. If the expected value is a Date object, the actual value is
  581. // equivalent if it is also a Date object that refers to the same time.
  582. } else if (util.isDate(actual) && util.isDate(expected)) {
  583. return actual.getTime() === expected.getTime();
  584.  
  585. // 7.3 If the expected value is a RegExp object, the actual value is
  586. // equivalent if it is also a RegExp object with the same source and
  587. // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  588. } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  589. return actual.source === expected.source &&
  590. actual.global === expected.global &&
  591. actual.multiline === expected.multiline &&
  592. actual.lastIndex === expected.lastIndex &&
  593. actual.ignoreCase === expected.ignoreCase;
  594.  
  595. // 7.4. Other pairs that do not both pass typeof value == 'object',
  596. // equivalence is determined by ==.
  597. } else if ((actual === null || typeof actual !== 'object') &&
  598. (expected === null || typeof expected !== 'object')) {
  599. return strict ? actual === expected : actual == expected;
  600.  
  601. // If both values are instances of typed arrays, wrap their underlying
  602. // ArrayBuffers in a Buffer each to increase performance
  603. // This optimization requires the arrays to have the same type as checked by
  604. // Object.prototype.toString (aka pToString). Never perform binary
  605. // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
  606. // bit patterns are not identical.
  607. } else if (isView(actual) && isView(expected) &&
  608. pToString(actual) === pToString(expected) &&
  609. !(actual instanceof Float32Array ||
  610. actual instanceof Float64Array)) {
  611. return compare(new Uint8Array(actual.buffer),
  612. new Uint8Array(expected.buffer)) === 0;
  613.  
  614. // 7.5 For all other Object pairs, including Array objects, equivalence is
  615. // determined by having the same number of owned properties (as verified
  616. // with Object.prototype.hasOwnProperty.call), the same set of keys
  617. // (although not necessarily the same order), equivalent values for every
  618. // corresponding key, and an identical 'prototype' property. Note: this
  619. // accounts for both named and indexed properties on Arrays.
  620. } else if (isBuffer(actual) !== isBuffer(expected)) {
  621. return false;
  622. } else {
  623. memos = memos || {actual: [], expected: []};
  624.  
  625. var actualIndex = memos.actual.indexOf(actual);
  626. if (actualIndex !== -1) {
  627. if (actualIndex === memos.expected.indexOf(expected)) {
  628. return true;
  629. }
  630. }
  631.  
  632. memos.actual.push(actual);
  633. memos.expected.push(expected);
  634.  
  635. return objEquiv(actual, expected, strict, memos);
  636. }
  637. }
  638.  
  639. function isArguments(object) {
  640. return Object.prototype.toString.call(object) == '[object Arguments]';
  641. }
  642.  
  643. function objEquiv(a, b, strict, actualVisitedObjects) {
  644. if (a === null || a === undefined || b === null || b === undefined)
  645. return false;
  646. // if one is a primitive, the other must be same
  647. if (util.isPrimitive(a) || util.isPrimitive(b))
  648. return a === b;
  649. if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
  650. return false;
  651. var aIsArgs = isArguments(a);
  652. var bIsArgs = isArguments(b);
  653. if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
  654. return false;
  655. if (aIsArgs) {
  656. a = pSlice.call(a);
  657. b = pSlice.call(b);
  658. return _deepEqual(a, b, strict);
  659. }
  660. var ka = objectKeys(a);
  661. var kb = objectKeys(b);
  662. var key, i;
  663. // having the same number of owned properties (keys incorporates
  664. // hasOwnProperty)
  665. if (ka.length !== kb.length)
  666. return false;
  667. //the same set of keys (although not necessarily the same order),
  668. ka.sort();
  669. kb.sort();
  670. //~~~cheap key test
  671. for (i = ka.length - 1; i >= 0; i--) {
  672. if (ka[i] !== kb[i])
  673. return false;
  674. }
  675. //equivalent values for every corresponding key, and
  676. //~~~possibly expensive deep test
  677. for (i = ka.length - 1; i >= 0; i--) {
  678. key = ka[i];
  679. if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
  680. return false;
  681. }
  682. return true;
  683. }
  684.  
  685. // 8. The non-equivalence assertion tests for any deep inequality.
  686. // assert.notDeepEqual(actual, expected, message_opt);
  687.  
  688. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  689. if (_deepEqual(actual, expected, false)) {
  690. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  691. }
  692. };
  693.  
  694. assert.notDeepStrictEqual = notDeepStrictEqual;
  695. function notDeepStrictEqual(actual, expected, message) {
  696. if (_deepEqual(actual, expected, true)) {
  697. fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
  698. }
  699. }
  700.  
  701.  
  702. // 9. The strict equality assertion tests strict equality, as determined by ===.
  703. // assert.strictEqual(actual, expected, message_opt);
  704.  
  705. assert.strictEqual = function strictEqual(actual, expected, message) {
  706. if (actual !== expected) {
  707. fail(actual, expected, message, '===', assert.strictEqual);
  708. }
  709. };
  710.  
  711. // 10. The strict non-equality assertion tests for strict inequality, as
  712. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  713.  
  714. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  715. if (actual === expected) {
  716. fail(actual, expected, message, '!==', assert.notStrictEqual);
  717. }
  718. };
  719.  
  720. function expectedException(actual, expected) {
  721. if (!actual || !expected) {
  722. return false;
  723. }
  724.  
  725. if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  726. return expected.test(actual);
  727. }
  728.  
  729. try {
  730. if (actual instanceof expected) {
  731. return true;
  732. }
  733. } catch (e) {
  734. // Ignore. The instanceof check doesn't work for arrow functions.
  735. }
  736.  
  737. if (Error.isPrototypeOf(expected)) {
  738. return false;
  739. }
  740.  
  741. return expected.call({}, actual) === true;
  742. }
  743.  
  744. function _tryBlock(block) {
  745. var error;
  746. try {
  747. block();
  748. } catch (e) {
  749. error = e;
  750. }
  751. return error;
  752. }
  753.  
  754. function _throws(shouldThrow, block, expected, message) {
  755. var actual;
  756.  
  757. if (typeof block !== 'function') {
  758. throw new TypeError('"block" argument must be a function');
  759. }
  760.  
  761. if (typeof expected === 'string') {
  762. message = expected;
  763. expected = null;
  764. }
  765.  
  766. actual = _tryBlock(block);
  767.  
  768. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  769. (message ? ' ' + message : '.');
  770.  
  771. if (shouldThrow && !actual) {
  772. fail(actual, expected, 'Missing expected exception' + message);
  773. }
  774.  
  775. var userProvidedMessage = typeof message === 'string';
  776. var isUnwantedException = !shouldThrow && util.isError(actual);
  777. var isUnexpectedException = !shouldThrow && actual && !expected;
  778.  
  779. if ((isUnwantedException &&
  780. userProvidedMessage &&
  781. expectedException(actual, expected)) ||
  782. isUnexpectedException) {
  783. fail(actual, expected, 'Got unwanted exception' + message);
  784. }
  785.  
  786. if ((shouldThrow && actual && expected &&
  787. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  788. throw actual;
  789. }
  790. }
  791.  
  792. // 11. Expected to throw an error:
  793. // assert.throws(block, Error_opt, message_opt);
  794.  
  795. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  796. _throws(true, block, error, message);
  797. };
  798.  
  799. // EXTENSION! This is annoying to write outside this module.
  800. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  801. _throws(false, block, error, message);
  802. };
  803.  
  804. assert.ifError = function(err) { if (err) throw err; };
  805.  
  806. // Expose a strict only variant of assert
  807. function strict(value, message) {
  808. if (!value) fail(value, true, message, '==', strict);
  809. }
  810. assert.strict = objectAssign(strict, assert, {
  811. equal: assert.strictEqual,
  812. deepEqual: assert.deepStrictEqual,
  813. notEqual: assert.notStrictEqual,
  814. notDeepEqual: assert.notDeepStrictEqual
  815. });
  816. assert.strict.strict = assert.strict;
  817.  
  818. var objectKeys = Object.keys || function (obj) {
  819. var keys = [];
  820. for (var key in obj) {
  821. if (hasOwn.call(obj, key)) keys.push(key);
  822. }
  823. return keys;
  824. };
  825.  
  826. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("yLpj")))
  827.  
  828. /***/ }),
  829.  
  830. /***/ "Ekho":
  831. /***/ (function(module, exports, __webpack_require__) {
  832.  
  833. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// Generated by CoffeeScript 1.8.0
  834. (function() {
  835. var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup;
  836.  
  837. floor = Math.floor, min = Math.min;
  838.  
  839.  
  840. /*
  841. Default comparison function to be used
  842. */
  843.  
  844. defaultCmp = function(x, y) {
  845. if (x < y) {
  846. return -1;
  847. }
  848. if (x > y) {
  849. return 1;
  850. }
  851. return 0;
  852. };
  853.  
  854.  
  855. /*
  856. Insert item x in list a, and keep it sorted assuming a is sorted.
  857. If x is already in a, insert it to the right of the rightmost x.
  858. Optional args lo (default 0) and hi (default a.length) bound the slice
  859. of a to be searched.
  860. */
  861.  
  862. insort = function(a, x, lo, hi, cmp) {
  863. var mid;
  864. if (lo == null) {
  865. lo = 0;
  866. }
  867. if (cmp == null) {
  868. cmp = defaultCmp;
  869. }
  870. if (lo < 0) {
  871. throw new Error('lo must be non-negative');
  872. }
  873. if (hi == null) {
  874. hi = a.length;
  875. }
  876. while (lo < hi) {
  877. mid = floor((lo + hi) / 2);
  878. if (cmp(x, a[mid]) < 0) {
  879. hi = mid;
  880. } else {
  881. lo = mid + 1;
  882. }
  883. }
  884. return ([].splice.apply(a, [lo, lo - lo].concat(x)), x);
  885. };
  886.  
  887.  
  888. /*
  889. Push item onto heap, maintaining the heap invariant.
  890. */
  891.  
  892. heappush = function(array, item, cmp) {
  893. if (cmp == null) {
  894. cmp = defaultCmp;
  895. }
  896. array.push(item);
  897. return _siftdown(array, 0, array.length - 1, cmp);
  898. };
  899.  
  900.  
  901. /*
  902. Pop the smallest item off the heap, maintaining the heap invariant.
  903. */
  904.  
  905. heappop = function(array, cmp) {
  906. var lastelt, returnitem;
  907. if (cmp == null) {
  908. cmp = defaultCmp;
  909. }
  910. lastelt = array.pop();
  911. if (array.length) {
  912. returnitem = array[0];
  913. array[0] = lastelt;
  914. _siftup(array, 0, cmp);
  915. } else {
  916. returnitem = lastelt;
  917. }
  918. return returnitem;
  919. };
  920.  
  921.  
  922. /*
  923. Pop and return the current smallest value, and add the new item.
  924. This is more efficient than heappop() followed by heappush(), and can be
  925. more appropriate when using a fixed size heap. Note that the value
  926. returned may be larger than item! That constrains reasonable use of
  927. this routine unless written as part of a conditional replacement:
  928. if item > array[0]
  929. item = heapreplace(array, item)
  930. */
  931.  
  932. heapreplace = function(array, item, cmp) {
  933. var returnitem;
  934. if (cmp == null) {
  935. cmp = defaultCmp;
  936. }
  937. returnitem = array[0];
  938. array[0] = item;
  939. _siftup(array, 0, cmp);
  940. return returnitem;
  941. };
  942.  
  943.  
  944. /*
  945. Fast version of a heappush followed by a heappop.
  946. */
  947.  
  948. heappushpop = function(array, item, cmp) {
  949. var _ref;
  950. if (cmp == null) {
  951. cmp = defaultCmp;
  952. }
  953. if (array.length && cmp(array[0], item) < 0) {
  954. _ref = [array[0], item], item = _ref[0], array[0] = _ref[1];
  955. _siftup(array, 0, cmp);
  956. }
  957. return item;
  958. };
  959.  
  960.  
  961. /*
  962. Transform list into a heap, in-place, in O(array.length) time.
  963. */
  964.  
  965. heapify = function(array, cmp) {
  966. var i, _i, _j, _len, _ref, _ref1, _results, _results1;
  967. if (cmp == null) {
  968. cmp = defaultCmp;
  969. }
  970. _ref1 = (function() {
  971. _results1 = [];
  972. for (var _j = 0, _ref = floor(array.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--){ _results1.push(_j); }
  973. return _results1;
  974. }).apply(this).reverse();
  975. _results = [];
  976. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  977. i = _ref1[_i];
  978. _results.push(_siftup(array, i, cmp));
  979. }
  980. return _results;
  981. };
  982.  
  983.  
  984. /*
  985. Update the position of the given item in the heap.
  986. This function should be called every time the item is being modified.
  987. */
  988.  
  989. updateItem = function(array, item, cmp) {
  990. var pos;
  991. if (cmp == null) {
  992. cmp = defaultCmp;
  993. }
  994. pos = array.indexOf(item);
  995. if (pos === -1) {
  996. return;
  997. }
  998. _siftdown(array, 0, pos, cmp);
  999. return _siftup(array, pos, cmp);
  1000. };
  1001.  
  1002.  
  1003. /*
  1004. Find the n largest elements in a dataset.
  1005. */
  1006.  
  1007. nlargest = function(array, n, cmp) {
  1008. var elem, result, _i, _len, _ref;
  1009. if (cmp == null) {
  1010. cmp = defaultCmp;
  1011. }
  1012. result = array.slice(0, n);
  1013. if (!result.length) {
  1014. return result;
  1015. }
  1016. heapify(result, cmp);
  1017. _ref = array.slice(n);
  1018. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1019. elem = _ref[_i];
  1020. heappushpop(result, elem, cmp);
  1021. }
  1022. return result.sort(cmp).reverse();
  1023. };
  1024.  
  1025.  
  1026. /*
  1027. Find the n smallest elements in a dataset.
  1028. */
  1029.  
  1030. nsmallest = function(array, n, cmp) {
  1031. var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results;
  1032. if (cmp == null) {
  1033. cmp = defaultCmp;
  1034. }
  1035. if (n * 10 <= array.length) {
  1036. result = array.slice(0, n).sort(cmp);
  1037. if (!result.length) {
  1038. return result;
  1039. }
  1040. los = result[result.length - 1];
  1041. _ref = array.slice(n);
  1042. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  1043. elem = _ref[_i];
  1044. if (cmp(elem, los) < 0) {
  1045. insort(result, elem, 0, null, cmp);
  1046. result.pop();
  1047. los = result[result.length - 1];
  1048. }
  1049. }
  1050. return result;
  1051. }
  1052. heapify(array, cmp);
  1053. _results = [];
  1054. for (i = _j = 0, _ref1 = min(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
  1055. _results.push(heappop(array, cmp));
  1056. }
  1057. return _results;
  1058. };
  1059.  
  1060. _siftdown = function(array, startpos, pos, cmp) {
  1061. var newitem, parent, parentpos;
  1062. if (cmp == null) {
  1063. cmp = defaultCmp;
  1064. }
  1065. newitem = array[pos];
  1066. while (pos > startpos) {
  1067. parentpos = (pos - 1) >> 1;
  1068. parent = array[parentpos];
  1069. if (cmp(newitem, parent) < 0) {
  1070. array[pos] = parent;
  1071. pos = parentpos;
  1072. continue;
  1073. }
  1074. break;
  1075. }
  1076. return array[pos] = newitem;
  1077. };
  1078.  
  1079. _siftup = function(array, pos, cmp) {
  1080. var childpos, endpos, newitem, rightpos, startpos;
  1081. if (cmp == null) {
  1082. cmp = defaultCmp;
  1083. }
  1084. endpos = array.length;
  1085. startpos = pos;
  1086. newitem = array[pos];
  1087. childpos = 2 * pos + 1;
  1088. while (childpos < endpos) {
  1089. rightpos = childpos + 1;
  1090. if (rightpos < endpos && !(cmp(array[childpos], array[rightpos]) < 0)) {
  1091. childpos = rightpos;
  1092. }
  1093. array[pos] = array[childpos];
  1094. pos = childpos;
  1095. childpos = 2 * pos + 1;
  1096. }
  1097. array[pos] = newitem;
  1098. return _siftdown(array, startpos, pos, cmp);
  1099. };
  1100.  
  1101. Heap = (function() {
  1102. Heap.push = heappush;
  1103.  
  1104. Heap.pop = heappop;
  1105.  
  1106. Heap.replace = heapreplace;
  1107.  
  1108. Heap.pushpop = heappushpop;
  1109.  
  1110. Heap.heapify = heapify;
  1111.  
  1112. Heap.updateItem = updateItem;
  1113.  
  1114. Heap.nlargest = nlargest;
  1115.  
  1116. Heap.nsmallest = nsmallest;
  1117.  
  1118. function Heap(cmp) {
  1119. this.cmp = cmp != null ? cmp : defaultCmp;
  1120. this.nodes = [];
  1121. }
  1122.  
  1123. Heap.prototype.push = function(x) {
  1124. return heappush(this.nodes, x, this.cmp);
  1125. };
  1126.  
  1127. Heap.prototype.pop = function() {
  1128. return heappop(this.nodes, this.cmp);
  1129. };
  1130.  
  1131. Heap.prototype.peek = function() {
  1132. return this.nodes[0];
  1133. };
  1134.  
  1135. Heap.prototype.contains = function(x) {
  1136. return this.nodes.indexOf(x) !== -1;
  1137. };
  1138.  
  1139. Heap.prototype.replace = function(x) {
  1140. return heapreplace(this.nodes, x, this.cmp);
  1141. };
  1142.  
  1143. Heap.prototype.pushpop = function(x) {
  1144. return heappushpop(this.nodes, x, this.cmp);
  1145. };
  1146.  
  1147. Heap.prototype.heapify = function() {
  1148. return heapify(this.nodes, this.cmp);
  1149. };
  1150.  
  1151. Heap.prototype.updateItem = function(x) {
  1152. return updateItem(this.nodes, x, this.cmp);
  1153. };
  1154.  
  1155. Heap.prototype.clear = function() {
  1156. return this.nodes = [];
  1157. };
  1158.  
  1159. Heap.prototype.empty = function() {
  1160. return this.nodes.length === 0;
  1161. };
  1162.  
  1163. Heap.prototype.size = function() {
  1164. return this.nodes.length;
  1165. };
  1166.  
  1167. Heap.prototype.clone = function() {
  1168. var heap;
  1169. heap = new Heap();
  1170. heap.nodes = this.nodes.slice(0);
  1171. return heap;
  1172. };
  1173.  
  1174. Heap.prototype.toArray = function() {
  1175. return this.nodes.slice(0);
  1176. };
  1177.  
  1178. Heap.prototype.insert = Heap.prototype.push;
  1179.  
  1180. Heap.prototype.top = Heap.prototype.peek;
  1181.  
  1182. Heap.prototype.front = Heap.prototype.peek;
  1183.  
  1184. Heap.prototype.has = Heap.prototype.contains;
  1185.  
  1186. Heap.prototype.copy = Heap.prototype.clone;
  1187.  
  1188. return Heap;
  1189.  
  1190. })();
  1191.  
  1192. (function(root, factory) {
  1193. if (true) {
  1194. return !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  1195. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  1196. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  1197. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  1198. } else {}
  1199. })(this, function() {
  1200. return Heap;
  1201. });
  1202.  
  1203. }).call(this);
  1204.  
  1205.  
  1206. /***/ }),
  1207.  
  1208. /***/ "F1pL":
  1209. /***/ (function(module, exports, __webpack_require__) {
  1210.  
  1211. module.exports = __webpack_require__("Ekho");
  1212.  
  1213.  
  1214. /***/ }),
  1215.  
  1216. /***/ "KKCa":
  1217. /***/ (function(module, exports) {
  1218.  
  1219. if (typeof Object.create === 'function') {
  1220. // implementation from standard node.js 'util' module
  1221. module.exports = function inherits(ctor, superCtor) {
  1222. ctor.super_ = superCtor
  1223. ctor.prototype = Object.create(superCtor.prototype, {
  1224. constructor: {
  1225. value: ctor,
  1226. enumerable: false,
  1227. writable: true,
  1228. configurable: true
  1229. }
  1230. });
  1231. };
  1232. } else {
  1233. // old school shim for old browsers
  1234. module.exports = function inherits(ctor, superCtor) {
  1235. ctor.super_ = superCtor
  1236. var TempCtor = function () {}
  1237. TempCtor.prototype = superCtor.prototype
  1238. ctor.prototype = new TempCtor()
  1239. ctor.prototype.constructor = ctor
  1240. }
  1241. }
  1242.  
  1243.  
  1244. /***/ }),
  1245.  
  1246. /***/ "MCLT":
  1247. /***/ (function(module, exports, __webpack_require__) {
  1248.  
  1249. /* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors.
  1250. //
  1251. // Permission is hereby granted, free of charge, to any person obtaining a
  1252. // copy of this software and associated documentation files (the
  1253. // "Software"), to deal in the Software without restriction, including
  1254. // without limitation the rights to use, copy, modify, merge, publish,
  1255. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1256. // persons to whom the Software is furnished to do so, subject to the
  1257. // following conditions:
  1258. //
  1259. // The above copyright notice and this permission notice shall be included
  1260. // in all copies or substantial portions of the Software.
  1261. //
  1262. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1263. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1264. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1265. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1266. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1267. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1268. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1269.  
  1270. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  1271. function getOwnPropertyDescriptors(obj) {
  1272. var keys = Object.keys(obj);
  1273. var descriptors = {};
  1274. for (var i = 0; i < keys.length; i++) {
  1275. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  1276. }
  1277. return descriptors;
  1278. };
  1279.  
  1280. var formatRegExp = /%[sdj%]/g;
  1281. exports.format = function(f) {
  1282. if (!isString(f)) {
  1283. var objects = [];
  1284. for (var i = 0; i < arguments.length; i++) {
  1285. objects.push(inspect(arguments[i]));
  1286. }
  1287. return objects.join(' ');
  1288. }
  1289.  
  1290. var i = 1;
  1291. var args = arguments;
  1292. var len = args.length;
  1293. var str = String(f).replace(formatRegExp, function(x) {
  1294. if (x === '%%') return '%';
  1295. if (i >= len) return x;
  1296. switch (x) {
  1297. case '%s': return String(args[i++]);
  1298. case '%d': return Number(args[i++]);
  1299. case '%j':
  1300. try {
  1301. return JSON.stringify(args[i++]);
  1302. } catch (_) {
  1303. return '[Circular]';
  1304. }
  1305. default:
  1306. return x;
  1307. }
  1308. });
  1309. for (var x = args[i]; i < len; x = args[++i]) {
  1310. if (isNull(x) || !isObject(x)) {
  1311. str += ' ' + x;
  1312. } else {
  1313. str += ' ' + inspect(x);
  1314. }
  1315. }
  1316. return str;
  1317. };
  1318.  
  1319.  
  1320. // Mark that a method should not be used.
  1321. // Returns a modified function which warns once by default.
  1322. // If --no-deprecation is set, then it is a no-op.
  1323. exports.deprecate = function(fn, msg) {
  1324. if (typeof process !== 'undefined' && process.noDeprecation === true) {
  1325. return fn;
  1326. }
  1327.  
  1328. // Allow for deprecating things in the process of starting up.
  1329. if (typeof process === 'undefined') {
  1330. return function() {
  1331. return exports.deprecate(fn, msg).apply(this, arguments);
  1332. };
  1333. }
  1334.  
  1335. var warned = false;
  1336. function deprecated() {
  1337. if (!warned) {
  1338. if (process.throwDeprecation) {
  1339. throw new Error(msg);
  1340. } else if (process.traceDeprecation) {
  1341. console.trace(msg);
  1342. } else {
  1343. console.error(msg);
  1344. }
  1345. warned = true;
  1346. }
  1347. return fn.apply(this, arguments);
  1348. }
  1349.  
  1350. return deprecated;
  1351. };
  1352.  
  1353.  
  1354. var debugs = {};
  1355. var debugEnviron;
  1356. exports.debuglog = function(set) {
  1357. if (isUndefined(debugEnviron))
  1358. debugEnviron = process.env.NODE_DEBUG || '';
  1359. set = set.toUpperCase();
  1360. if (!debugs[set]) {
  1361. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  1362. var pid = process.pid;
  1363. debugs[set] = function() {
  1364. var msg = exports.format.apply(exports, arguments);
  1365. console.error('%s %d: %s', set, pid, msg);
  1366. };
  1367. } else {
  1368. debugs[set] = function() {};
  1369. }
  1370. }
  1371. return debugs[set];
  1372. };
  1373.  
  1374.  
  1375. /**
  1376. * Echos the value of a value. Trys to print the value out
  1377. * in the best way possible given the different types.
  1378. *
  1379. * @param {Object} obj The object to print out.
  1380. * @param {Object} opts Optional options object that alters the output.
  1381. */
  1382. /* legacy: obj, showHidden, depth, colors*/
  1383. function inspect(obj, opts) {
  1384. // default options
  1385. var ctx = {
  1386. seen: [],
  1387. stylize: stylizeNoColor
  1388. };
  1389. // legacy...
  1390. if (arguments.length >= 3) ctx.depth = arguments[2];
  1391. if (arguments.length >= 4) ctx.colors = arguments[3];
  1392. if (isBoolean(opts)) {
  1393. // legacy...
  1394. ctx.showHidden = opts;
  1395. } else if (opts) {
  1396. // got an "options" object
  1397. exports._extend(ctx, opts);
  1398. }
  1399. // set default options
  1400. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  1401. if (isUndefined(ctx.depth)) ctx.depth = 2;
  1402. if (isUndefined(ctx.colors)) ctx.colors = false;
  1403. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  1404. if (ctx.colors) ctx.stylize = stylizeWithColor;
  1405. return formatValue(ctx, obj, ctx.depth);
  1406. }
  1407. exports.inspect = inspect;
  1408.  
  1409.  
  1410. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  1411. inspect.colors = {
  1412. 'bold' : [1, 22],
  1413. 'italic' : [3, 23],
  1414. 'underline' : [4, 24],
  1415. 'inverse' : [7, 27],
  1416. 'white' : [37, 39],
  1417. 'grey' : [90, 39],
  1418. 'black' : [30, 39],
  1419. 'blue' : [34, 39],
  1420. 'cyan' : [36, 39],
  1421. 'green' : [32, 39],
  1422. 'magenta' : [35, 39],
  1423. 'red' : [31, 39],
  1424. 'yellow' : [33, 39]
  1425. };
  1426.  
  1427. // Don't use 'blue' not visible on cmd.exe
  1428. inspect.styles = {
  1429. 'special': 'cyan',
  1430. 'number': 'yellow',
  1431. 'boolean': 'yellow',
  1432. 'undefined': 'grey',
  1433. 'null': 'bold',
  1434. 'string': 'green',
  1435. 'date': 'magenta',
  1436. // "name": intentionally not styling
  1437. 'regexp': 'red'
  1438. };
  1439.  
  1440.  
  1441. function stylizeWithColor(str, styleType) {
  1442. var style = inspect.styles[styleType];
  1443.  
  1444. if (style) {
  1445. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  1446. '\u001b[' + inspect.colors[style][1] + 'm';
  1447. } else {
  1448. return str;
  1449. }
  1450. }
  1451.  
  1452.  
  1453. function stylizeNoColor(str, styleType) {
  1454. return str;
  1455. }
  1456.  
  1457.  
  1458. function arrayToHash(array) {
  1459. var hash = {};
  1460.  
  1461. array.forEach(function(val, idx) {
  1462. hash[val] = true;
  1463. });
  1464.  
  1465. return hash;
  1466. }
  1467.  
  1468.  
  1469. function formatValue(ctx, value, recurseTimes) {
  1470. // Provide a hook for user-specified inspect functions.
  1471. // Check that value is an object with an inspect function on it
  1472. if (ctx.customInspect &&
  1473. value &&
  1474. isFunction(value.inspect) &&
  1475. // Filter out the util module, it's inspect function is special
  1476. value.inspect !== exports.inspect &&
  1477. // Also filter out any prototype objects using the circular check.
  1478. !(value.constructor && value.constructor.prototype === value)) {
  1479. var ret = value.inspect(recurseTimes, ctx);
  1480. if (!isString(ret)) {
  1481. ret = formatValue(ctx, ret, recurseTimes);
  1482. }
  1483. return ret;
  1484. }
  1485.  
  1486. // Primitive types cannot have properties
  1487. var primitive = formatPrimitive(ctx, value);
  1488. if (primitive) {
  1489. return primitive;
  1490. }
  1491.  
  1492. // Look up the keys of the object.
  1493. var keys = Object.keys(value);
  1494. var visibleKeys = arrayToHash(keys);
  1495.  
  1496. if (ctx.showHidden) {
  1497. keys = Object.getOwnPropertyNames(value);
  1498. }
  1499.  
  1500. // IE doesn't make error fields non-enumerable
  1501. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  1502. if (isError(value)
  1503. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  1504. return formatError(value);
  1505. }
  1506.  
  1507. // Some type of object without properties can be shortcutted.
  1508. if (keys.length === 0) {
  1509. if (isFunction(value)) {
  1510. var name = value.name ? ': ' + value.name : '';
  1511. return ctx.stylize('[Function' + name + ']', 'special');
  1512. }
  1513. if (isRegExp(value)) {
  1514. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  1515. }
  1516. if (isDate(value)) {
  1517. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  1518. }
  1519. if (isError(value)) {
  1520. return formatError(value);
  1521. }
  1522. }
  1523.  
  1524. var base = '', array = false, braces = ['{', '}'];
  1525.  
  1526. // Make Array say that they are Array
  1527. if (isArray(value)) {
  1528. array = true;
  1529. braces = ['[', ']'];
  1530. }
  1531.  
  1532. // Make functions say that they are functions
  1533. if (isFunction(value)) {
  1534. var n = value.name ? ': ' + value.name : '';
  1535. base = ' [Function' + n + ']';
  1536. }
  1537.  
  1538. // Make RegExps say that they are RegExps
  1539. if (isRegExp(value)) {
  1540. base = ' ' + RegExp.prototype.toString.call(value);
  1541. }
  1542.  
  1543. // Make dates with properties first say the date
  1544. if (isDate(value)) {
  1545. base = ' ' + Date.prototype.toUTCString.call(value);
  1546. }
  1547.  
  1548. // Make error with message first say the error
  1549. if (isError(value)) {
  1550. base = ' ' + formatError(value);
  1551. }
  1552.  
  1553. if (keys.length === 0 && (!array || value.length == 0)) {
  1554. return braces[0] + base + braces[1];
  1555. }
  1556.  
  1557. if (recurseTimes < 0) {
  1558. if (isRegExp(value)) {
  1559. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  1560. } else {
  1561. return ctx.stylize('[Object]', 'special');
  1562. }
  1563. }
  1564.  
  1565. ctx.seen.push(value);
  1566.  
  1567. var output;
  1568. if (array) {
  1569. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  1570. } else {
  1571. output = keys.map(function(key) {
  1572. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  1573. });
  1574. }
  1575.  
  1576. ctx.seen.pop();
  1577.  
  1578. return reduceToSingleString(output, base, braces);
  1579. }
  1580.  
  1581.  
  1582. function formatPrimitive(ctx, value) {
  1583. if (isUndefined(value))
  1584. return ctx.stylize('undefined', 'undefined');
  1585. if (isString(value)) {
  1586. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  1587. .replace(/'/g, "\\'")
  1588. .replace(/\\"/g, '"') + '\'';
  1589. return ctx.stylize(simple, 'string');
  1590. }
  1591. if (isNumber(value))
  1592. return ctx.stylize('' + value, 'number');
  1593. if (isBoolean(value))
  1594. return ctx.stylize('' + value, 'boolean');
  1595. // For some reason typeof null is "object", so special case here.
  1596. if (isNull(value))
  1597. return ctx.stylize('null', 'null');
  1598. }
  1599.  
  1600.  
  1601. function formatError(value) {
  1602. return '[' + Error.prototype.toString.call(value) + ']';
  1603. }
  1604.  
  1605.  
  1606. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  1607. var output = [];
  1608. for (var i = 0, l = value.length; i < l; ++i) {
  1609. if (hasOwnProperty(value, String(i))) {
  1610. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  1611. String(i), true));
  1612. } else {
  1613. output.push('');
  1614. }
  1615. }
  1616. keys.forEach(function(key) {
  1617. if (!key.match(/^\d+$/)) {
  1618. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  1619. key, true));
  1620. }
  1621. });
  1622. return output;
  1623. }
  1624.  
  1625.  
  1626. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  1627. var name, str, desc;
  1628. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  1629. if (desc.get) {
  1630. if (desc.set) {
  1631. str = ctx.stylize('[Getter/Setter]', 'special');
  1632. } else {
  1633. str = ctx.stylize('[Getter]', 'special');
  1634. }
  1635. } else {
  1636. if (desc.set) {
  1637. str = ctx.stylize('[Setter]', 'special');
  1638. }
  1639. }
  1640. if (!hasOwnProperty(visibleKeys, key)) {
  1641. name = '[' + key + ']';
  1642. }
  1643. if (!str) {
  1644. if (ctx.seen.indexOf(desc.value) < 0) {
  1645. if (isNull(recurseTimes)) {
  1646. str = formatValue(ctx, desc.value, null);
  1647. } else {
  1648. str = formatValue(ctx, desc.value, recurseTimes - 1);
  1649. }
  1650. if (str.indexOf('\n') > -1) {
  1651. if (array) {
  1652. str = str.split('\n').map(function(line) {
  1653. return ' ' + line;
  1654. }).join('\n').substr(2);
  1655. } else {
  1656. str = '\n' + str.split('\n').map(function(line) {
  1657. return ' ' + line;
  1658. }).join('\n');
  1659. }
  1660. }
  1661. } else {
  1662. str = ctx.stylize('[Circular]', 'special');
  1663. }
  1664. }
  1665. if (isUndefined(name)) {
  1666. if (array && key.match(/^\d+$/)) {
  1667. return str;
  1668. }
  1669. name = JSON.stringify('' + key);
  1670. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  1671. name = name.substr(1, name.length - 2);
  1672. name = ctx.stylize(name, 'name');
  1673. } else {
  1674. name = name.replace(/'/g, "\\'")
  1675. .replace(/\\"/g, '"')
  1676. .replace(/(^"|"$)/g, "'");
  1677. name = ctx.stylize(name, 'string');
  1678. }
  1679. }
  1680.  
  1681. return name + ': ' + str;
  1682. }
  1683.  
  1684.  
  1685. function reduceToSingleString(output, base, braces) {
  1686. var numLinesEst = 0;
  1687. var length = output.reduce(function(prev, cur) {
  1688. numLinesEst++;
  1689. if (cur.indexOf('\n') >= 0) numLinesEst++;
  1690. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  1691. }, 0);
  1692.  
  1693. if (length > 60) {
  1694. return braces[0] +
  1695. (base === '' ? '' : base + '\n ') +
  1696. ' ' +
  1697. output.join(',\n ') +
  1698. ' ' +
  1699. braces[1];
  1700. }
  1701.  
  1702. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  1703. }
  1704.  
  1705.  
  1706. // NOTE: These type checking functions intentionally don't use `instanceof`
  1707. // because it is fragile and can be easily faked with `Object.create()`.
  1708. function isArray(ar) {
  1709. return Array.isArray(ar);
  1710. }
  1711. exports.isArray = isArray;
  1712.  
  1713. function isBoolean(arg) {
  1714. return typeof arg === 'boolean';
  1715. }
  1716. exports.isBoolean = isBoolean;
  1717.  
  1718. function isNull(arg) {
  1719. return arg === null;
  1720. }
  1721. exports.isNull = isNull;
  1722.  
  1723. function isNullOrUndefined(arg) {
  1724. return arg == null;
  1725. }
  1726. exports.isNullOrUndefined = isNullOrUndefined;
  1727.  
  1728. function isNumber(arg) {
  1729. return typeof arg === 'number';
  1730. }
  1731. exports.isNumber = isNumber;
  1732.  
  1733. function isString(arg) {
  1734. return typeof arg === 'string';
  1735. }
  1736. exports.isString = isString;
  1737.  
  1738. function isSymbol(arg) {
  1739. return typeof arg === 'symbol';
  1740. }
  1741. exports.isSymbol = isSymbol;
  1742.  
  1743. function isUndefined(arg) {
  1744. return arg === void 0;
  1745. }
  1746. exports.isUndefined = isUndefined;
  1747.  
  1748. function isRegExp(re) {
  1749. return isObject(re) && objectToString(re) === '[object RegExp]';
  1750. }
  1751. exports.isRegExp = isRegExp;
  1752.  
  1753. function isObject(arg) {
  1754. return typeof arg === 'object' && arg !== null;
  1755. }
  1756. exports.isObject = isObject;
  1757.  
  1758. function isDate(d) {
  1759. return isObject(d) && objectToString(d) === '[object Date]';
  1760. }
  1761. exports.isDate = isDate;
  1762.  
  1763. function isError(e) {
  1764. return isObject(e) &&
  1765. (objectToString(e) === '[object Error]' || e instanceof Error);
  1766. }
  1767. exports.isError = isError;
  1768.  
  1769. function isFunction(arg) {
  1770. return typeof arg === 'function';
  1771. }
  1772. exports.isFunction = isFunction;
  1773.  
  1774. function isPrimitive(arg) {
  1775. return arg === null ||
  1776. typeof arg === 'boolean' ||
  1777. typeof arg === 'number' ||
  1778. typeof arg === 'string' ||
  1779. typeof arg === 'symbol' || // ES6 symbol
  1780. typeof arg === 'undefined';
  1781. }
  1782. exports.isPrimitive = isPrimitive;
  1783.  
  1784. exports.isBuffer = __webpack_require__("1gqn");
  1785.  
  1786. function objectToString(o) {
  1787. return Object.prototype.toString.call(o);
  1788. }
  1789.  
  1790.  
  1791. function pad(n) {
  1792. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  1793. }
  1794.  
  1795.  
  1796. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  1797. 'Oct', 'Nov', 'Dec'];
  1798.  
  1799. // 26 Feb 16:19:34
  1800. function timestamp() {
  1801. var d = new Date();
  1802. var time = [pad(d.getHours()),
  1803. pad(d.getMinutes()),
  1804. pad(d.getSeconds())].join(':');
  1805. return [d.getDate(), months[d.getMonth()], time].join(' ');
  1806. }
  1807.  
  1808.  
  1809. // log is just a thin wrapper to console.log that prepends a timestamp
  1810. exports.log = function() {
  1811. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  1812. };
  1813.  
  1814.  
  1815. /**
  1816. * Inherit the prototype methods from one constructor into another.
  1817. *
  1818. * The Function.prototype.inherits from lang.js rewritten as a standalone
  1819. * function (not on Function.prototype). NOTE: If this file is to be loaded
  1820. * during bootstrapping this function needs to be rewritten using some native
  1821. * functions as prototype setup using normal JavaScript does not work as
  1822. * expected during bootstrapping (see mirror.js in r114903).
  1823. *
  1824. * @param {function} ctor Constructor function which needs to inherit the
  1825. * prototype.
  1826. * @param {function} superCtor Constructor function to inherit prototype from.
  1827. */
  1828. exports.inherits = __webpack_require__("KKCa");
  1829.  
  1830. exports._extend = function(origin, add) {
  1831. // Don't do anything if add isn't an object
  1832. if (!add || !isObject(add)) return origin;
  1833.  
  1834. var keys = Object.keys(add);
  1835. var i = keys.length;
  1836. while (i--) {
  1837. origin[keys[i]] = add[keys[i]];
  1838. }
  1839. return origin;
  1840. };
  1841.  
  1842. function hasOwnProperty(obj, prop) {
  1843. return Object.prototype.hasOwnProperty.call(obj, prop);
  1844. }
  1845.  
  1846. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  1847.  
  1848. exports.promisify = function promisify(original) {
  1849. if (typeof original !== 'function')
  1850. throw new TypeError('The "original" argument must be of type Function');
  1851.  
  1852. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  1853. var fn = original[kCustomPromisifiedSymbol];
  1854. if (typeof fn !== 'function') {
  1855. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  1856. }
  1857. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  1858. value: fn, enumerable: false, writable: false, configurable: true
  1859. });
  1860. return fn;
  1861. }
  1862.  
  1863. function fn() {
  1864. var promiseResolve, promiseReject;
  1865. var promise = new Promise(function (resolve, reject) {
  1866. promiseResolve = resolve;
  1867. promiseReject = reject;
  1868. });
  1869.  
  1870. var args = [];
  1871. for (var i = 0; i < arguments.length; i++) {
  1872. args.push(arguments[i]);
  1873. }
  1874. args.push(function (err, value) {
  1875. if (err) {
  1876. promiseReject(err);
  1877. } else {
  1878. promiseResolve(value);
  1879. }
  1880. });
  1881.  
  1882. try {
  1883. original.apply(this, args);
  1884. } catch (err) {
  1885. promiseReject(err);
  1886. }
  1887.  
  1888. return promise;
  1889. }
  1890.  
  1891. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  1892.  
  1893. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  1894. value: fn, enumerable: false, writable: false, configurable: true
  1895. });
  1896. return Object.defineProperties(
  1897. fn,
  1898. getOwnPropertyDescriptors(original)
  1899. );
  1900. }
  1901.  
  1902. exports.promisify.custom = kCustomPromisifiedSymbol
  1903.  
  1904. function callbackifyOnRejected(reason, cb) {
  1905. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  1906. // Because `null` is a special error value in callbacks which means "no error
  1907. // occurred", we error-wrap so the callback consumer can distinguish between
  1908. // "the promise rejected with null" or "the promise fulfilled with undefined".
  1909. if (!reason) {
  1910. var newReason = new Error('Promise was rejected with a falsy value');
  1911. newReason.reason = reason;
  1912. reason = newReason;
  1913. }
  1914. return cb(reason);
  1915. }
  1916.  
  1917. function callbackify(original) {
  1918. if (typeof original !== 'function') {
  1919. throw new TypeError('The "original" argument must be of type Function');
  1920. }
  1921.  
  1922. // We DO NOT return the promise as it gives the user a false sense that
  1923. // the promise is actually somehow related to the callback's execution
  1924. // and that the callback throwing will reject the promise.
  1925. function callbackified() {
  1926. var args = [];
  1927. for (var i = 0; i < arguments.length; i++) {
  1928. args.push(arguments[i]);
  1929. }
  1930.  
  1931. var maybeCb = args.pop();
  1932. if (typeof maybeCb !== 'function') {
  1933. throw new TypeError('The last argument must be of type Function');
  1934. }
  1935. var self = this;
  1936. var cb = function() {
  1937. return maybeCb.apply(self, arguments);
  1938. };
  1939. // In true node style we process the callback on `nextTick` with all the
  1940. // implications (stack, `uncaughtException`, `async_hooks`)
  1941. original.apply(this, args)
  1942. .then(function(ret) { process.nextTick(cb, null, ret) },
  1943. function(rej) { process.nextTick(callbackifyOnRejected, rej, cb) });
  1944. }
  1945.  
  1946. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  1947. Object.defineProperties(callbackified,
  1948. getOwnPropertyDescriptors(original));
  1949. return callbackified;
  1950. }
  1951. exports.callbackify = callbackify;
  1952.  
  1953. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__("8oxB")))
  1954.  
  1955. /***/ }),
  1956.  
  1957. /***/ "MgzW":
  1958. /***/ (function(module, exports, __webpack_require__) {
  1959.  
  1960. "use strict";
  1961. /*
  1962. object-assign
  1963. (c) Sindre Sorhus
  1964. @license MIT
  1965. */
  1966.  
  1967.  
  1968. /* eslint-disable no-unused-vars */
  1969. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  1970. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1971. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  1972.  
  1973. function toObject(val) {
  1974. if (val === null || val === undefined) {
  1975. throw new TypeError('Object.assign cannot be called with null or undefined');
  1976. }
  1977.  
  1978. return Object(val);
  1979. }
  1980.  
  1981. function shouldUseNative() {
  1982. try {
  1983. if (!Object.assign) {
  1984. return false;
  1985. }
  1986.  
  1987. // Detect buggy property enumeration order in older V8 versions.
  1988.  
  1989. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  1990. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  1991. test1[5] = 'de';
  1992. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  1993. return false;
  1994. }
  1995.  
  1996. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1997. var test2 = {};
  1998. for (var i = 0; i < 10; i++) {
  1999. test2['_' + String.fromCharCode(i)] = i;
  2000. }
  2001. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  2002. return test2[n];
  2003. });
  2004. if (order2.join('') !== '0123456789') {
  2005. return false;
  2006. }
  2007.  
  2008. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  2009. var test3 = {};
  2010. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  2011. test3[letter] = letter;
  2012. });
  2013. if (Object.keys(Object.assign({}, test3)).join('') !==
  2014. 'abcdefghijklmnopqrst') {
  2015. return false;
  2016. }
  2017.  
  2018. return true;
  2019. } catch (err) {
  2020. // We don't expect any of the above to throw, but better to be safe.
  2021. return false;
  2022. }
  2023. }
  2024.  
  2025. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  2026. var from;
  2027. var to = toObject(target);
  2028. var symbols;
  2029.  
  2030. for (var s = 1; s < arguments.length; s++) {
  2031. from = Object(arguments[s]);
  2032.  
  2033. for (var key in from) {
  2034. if (hasOwnProperty.call(from, key)) {
  2035. to[key] = from[key];
  2036. }
  2037. }
  2038.  
  2039. if (getOwnPropertySymbols) {
  2040. symbols = getOwnPropertySymbols(from);
  2041. for (var i = 0; i < symbols.length; i++) {
  2042. if (propIsEnumerable.call(from, symbols[i])) {
  2043. to[symbols[i]] = from[symbols[i]];
  2044. }
  2045. }
  2046. }
  2047. }
  2048.  
  2049. return to;
  2050. };
  2051.  
  2052.  
  2053. /***/ }),
  2054.  
  2055. /***/ "PKsF":
  2056. /***/ (function(module, exports, __webpack_require__) {
  2057.  
  2058. /*
  2059. * Copyright 2011 Twitter, Inc.
  2060. * Licensed under the Apache License, Version 2.0 (the "License");
  2061. * you may not use this file except in compliance with the License.
  2062. * You may obtain a copy of the License at
  2063. *
  2064. * http://www.apache.org/licenses/LICENSE-2.0
  2065. *
  2066. * Unless required by applicable law or agreed to in writing, software
  2067. * distributed under the License is distributed on an "AS IS" BASIS,
  2068. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2069. * See the License for the specific language governing permissions and
  2070. * limitations under the License.
  2071. */
  2072.  
  2073. (function (Hogan) {
  2074. // Setup regex assignments
  2075. // remove whitespace according to Mustache spec
  2076. var rIsWhitespace = /\S/,
  2077. rQuot = /\"/g,
  2078. rNewline = /\n/g,
  2079. rCr = /\r/g,
  2080. rSlash = /\\/g,
  2081. rLineSep = /\u2028/,
  2082. rParagraphSep = /\u2029/;
  2083.  
  2084. Hogan.tags = {
  2085. '#': 1, '^': 2, '<': 3, '$': 4,
  2086. '/': 5, '!': 6, '>': 7, '=': 8, '_v': 9,
  2087. '{': 10, '&': 11, '_t': 12
  2088. };
  2089.  
  2090. Hogan.scan = function scan(text, delimiters) {
  2091. var len = text.length,
  2092. IN_TEXT = 0,
  2093. IN_TAG_TYPE = 1,
  2094. IN_TAG = 2,
  2095. state = IN_TEXT,
  2096. tagType = null,
  2097. tag = null,
  2098. buf = '',
  2099. tokens = [],
  2100. seenTag = false,
  2101. i = 0,
  2102. lineStart = 0,
  2103. otag = '{{',
  2104. ctag = '}}';
  2105.  
  2106. function addBuf() {
  2107. if (buf.length > 0) {
  2108. tokens.push({tag: '_t', text: new String(buf)});
  2109. buf = '';
  2110. }
  2111. }
  2112.  
  2113. function lineIsWhitespace() {
  2114. var isAllWhitespace = true;
  2115. for (var j = lineStart; j < tokens.length; j++) {
  2116. isAllWhitespace =
  2117. (Hogan.tags[tokens[j].tag] < Hogan.tags['_v']) ||
  2118. (tokens[j].tag == '_t' && tokens[j].text.match(rIsWhitespace) === null);
  2119. if (!isAllWhitespace) {
  2120. return false;
  2121. }
  2122. }
  2123.  
  2124. return isAllWhitespace;
  2125. }
  2126.  
  2127. function filterLine(haveSeenTag, noNewLine) {
  2128. addBuf();
  2129.  
  2130. if (haveSeenTag && lineIsWhitespace()) {
  2131. for (var j = lineStart, next; j < tokens.length; j++) {
  2132. if (tokens[j].text) {
  2133. if ((next = tokens[j+1]) && next.tag == '>') {
  2134. // set indent to token value
  2135. next.indent = tokens[j].text.toString()
  2136. }
  2137. tokens.splice(j, 1);
  2138. }
  2139. }
  2140. } else if (!noNewLine) {
  2141. tokens.push({tag:'\n'});
  2142. }
  2143.  
  2144. seenTag = false;
  2145. lineStart = tokens.length;
  2146. }
  2147.  
  2148. function changeDelimiters(text, index) {
  2149. var close = '=' + ctag,
  2150. closeIndex = text.indexOf(close, index),
  2151. delimiters = trim(
  2152. text.substring(text.indexOf('=', index) + 1, closeIndex)
  2153. ).split(' ');
  2154.  
  2155. otag = delimiters[0];
  2156. ctag = delimiters[delimiters.length - 1];
  2157.  
  2158. return closeIndex + close.length - 1;
  2159. }
  2160.  
  2161. if (delimiters) {
  2162. delimiters = delimiters.split(' ');
  2163. otag = delimiters[0];
  2164. ctag = delimiters[1];
  2165. }
  2166.  
  2167. for (i = 0; i < len; i++) {
  2168. if (state == IN_TEXT) {
  2169. if (tagChange(otag, text, i)) {
  2170. --i;
  2171. addBuf();
  2172. state = IN_TAG_TYPE;
  2173. } else {
  2174. if (text.charAt(i) == '\n') {
  2175. filterLine(seenTag);
  2176. } else {
  2177. buf += text.charAt(i);
  2178. }
  2179. }
  2180. } else if (state == IN_TAG_TYPE) {
  2181. i += otag.length - 1;
  2182. tag = Hogan.tags[text.charAt(i + 1)];
  2183. tagType = tag ? text.charAt(i + 1) : '_v';
  2184. if (tagType == '=') {
  2185. i = changeDelimiters(text, i);
  2186. state = IN_TEXT;
  2187. } else {
  2188. if (tag) {
  2189. i++;
  2190. }
  2191. state = IN_TAG;
  2192. }
  2193. seenTag = i;
  2194. } else {
  2195. if (tagChange(ctag, text, i)) {
  2196. tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag,
  2197. i: (tagType == '/') ? seenTag - otag.length : i + ctag.length});
  2198. buf = '';
  2199. i += ctag.length - 1;
  2200. state = IN_TEXT;
  2201. if (tagType == '{') {
  2202. if (ctag == '}}') {
  2203. i++;
  2204. } else {
  2205. cleanTripleStache(tokens[tokens.length - 1]);
  2206. }
  2207. }
  2208. } else {
  2209. buf += text.charAt(i);
  2210. }
  2211. }
  2212. }
  2213.  
  2214. filterLine(seenTag, true);
  2215.  
  2216. return tokens;
  2217. }
  2218.  
  2219. function cleanTripleStache(token) {
  2220. if (token.n.substr(token.n.length - 1) === '}') {
  2221. token.n = token.n.substring(0, token.n.length - 1);
  2222. }
  2223. }
  2224.  
  2225. function trim(s) {
  2226. if (s.trim) {
  2227. return s.trim();
  2228. }
  2229.  
  2230. return s.replace(/^\s*|\s*$/g, '');
  2231. }
  2232.  
  2233. function tagChange(tag, text, index) {
  2234. if (text.charAt(index) != tag.charAt(0)) {
  2235. return false;
  2236. }
  2237.  
  2238. for (var i = 1, l = tag.length; i < l; i++) {
  2239. if (text.charAt(index + i) != tag.charAt(i)) {
  2240. return false;
  2241. }
  2242. }
  2243.  
  2244. return true;
  2245. }
  2246.  
  2247. // the tags allowed inside super templates
  2248. var allowedInSuper = {'_t': true, '\n': true, '$': true, '/': true};
  2249.  
  2250. function buildTree(tokens, kind, stack, customTags) {
  2251. var instructions = [],
  2252. opener = null,
  2253. tail = null,
  2254. token = null;
  2255.  
  2256. tail = stack[stack.length - 1];
  2257.  
  2258. while (tokens.length > 0) {
  2259. token = tokens.shift();
  2260.  
  2261. if (tail && tail.tag == '<' && !(token.tag in allowedInSuper)) {
  2262. throw new Error('Illegal content in < super tag.');
  2263. }
  2264.  
  2265. if (Hogan.tags[token.tag] <= Hogan.tags['$'] || isOpener(token, customTags)) {
  2266. stack.push(token);
  2267. token.nodes = buildTree(tokens, token.tag, stack, customTags);
  2268. } else if (token.tag == '/') {
  2269. if (stack.length === 0) {
  2270. throw new Error('Closing tag without opener: /' + token.n);
  2271. }
  2272. opener = stack.pop();
  2273. if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) {
  2274. throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n);
  2275. }
  2276. opener.end = token.i;
  2277. return instructions;
  2278. } else if (token.tag == '\n') {
  2279. token.last = (tokens.length == 0) || (tokens[0].tag == '\n');
  2280. }
  2281.  
  2282. instructions.push(token);
  2283. }
  2284.  
  2285. if (stack.length > 0) {
  2286. throw new Error('missing closing tag: ' + stack.pop().n);
  2287. }
  2288.  
  2289. return instructions;
  2290. }
  2291.  
  2292. function isOpener(token, tags) {
  2293. for (var i = 0, l = tags.length; i < l; i++) {
  2294. if (tags[i].o == token.n) {
  2295. token.tag = '#';
  2296. return true;
  2297. }
  2298. }
  2299. }
  2300.  
  2301. function isCloser(close, open, tags) {
  2302. for (var i = 0, l = tags.length; i < l; i++) {
  2303. if (tags[i].c == close && tags[i].o == open) {
  2304. return true;
  2305. }
  2306. }
  2307. }
  2308.  
  2309. function stringifySubstitutions(obj) {
  2310. var items = [];
  2311. for (var key in obj) {
  2312. items.push('"' + esc(key) + '": function(c,p,t,i) {' + obj[key] + '}');
  2313. }
  2314. return "{ " + items.join(",") + " }";
  2315. }
  2316.  
  2317. function stringifyPartials(codeObj) {
  2318. var partials = [];
  2319. for (var key in codeObj.partials) {
  2320. partials.push('"' + esc(key) + '":{name:"' + esc(codeObj.partials[key].name) + '", ' + stringifyPartials(codeObj.partials[key]) + "}");
  2321. }
  2322. return "partials: {" + partials.join(",") + "}, subs: " + stringifySubstitutions(codeObj.subs);
  2323. }
  2324.  
  2325. Hogan.stringify = function(codeObj, text, options) {
  2326. return "{code: function (c,p,i) { " + Hogan.wrapMain(codeObj.code) + " }," + stringifyPartials(codeObj) + "}";
  2327. }
  2328.  
  2329. var serialNo = 0;
  2330. Hogan.generate = function(tree, text, options) {
  2331. serialNo = 0;
  2332. var context = { code: '', subs: {}, partials: {} };
  2333. Hogan.walk(tree, context);
  2334.  
  2335. if (options.asString) {
  2336. return this.stringify(context, text, options);
  2337. }
  2338.  
  2339. return this.makeTemplate(context, text, options);
  2340. }
  2341.  
  2342. Hogan.wrapMain = function(code) {
  2343. return 'var t=this;t.b(i=i||"");' + code + 'return t.fl();';
  2344. }
  2345.  
  2346. Hogan.template = Hogan.Template;
  2347.  
  2348. Hogan.makeTemplate = function(codeObj, text, options) {
  2349. var template = this.makePartials(codeObj);
  2350. template.code = new Function('c', 'p', 'i', this.wrapMain(codeObj.code));
  2351. return new this.template(template, text, this, options);
  2352. }
  2353.  
  2354. Hogan.makePartials = function(codeObj) {
  2355. var key, template = {subs: {}, partials: codeObj.partials, name: codeObj.name};
  2356. for (key in template.partials) {
  2357. template.partials[key] = this.makePartials(template.partials[key]);
  2358. }
  2359. for (key in codeObj.subs) {
  2360. template.subs[key] = new Function('c', 'p', 't', 'i', codeObj.subs[key]);
  2361. }
  2362. return template;
  2363. }
  2364.  
  2365. function esc(s) {
  2366. return s.replace(rSlash, '\\\\')
  2367. .replace(rQuot, '\\\"')
  2368. .replace(rNewline, '\\n')
  2369. .replace(rCr, '\\r')
  2370. .replace(rLineSep, '\\u2028')
  2371. .replace(rParagraphSep, '\\u2029');
  2372. }
  2373.  
  2374. function chooseMethod(s) {
  2375. return (~s.indexOf('.')) ? 'd' : 'f';
  2376. }
  2377.  
  2378. function createPartial(node, context) {
  2379. var prefix = "<" + (context.prefix || "");
  2380. var sym = prefix + node.n + serialNo++;
  2381. context.partials[sym] = {name: node.n, partials: {}};
  2382. context.code += 't.b(t.rp("' + esc(sym) + '",c,p,"' + (node.indent || '') + '"));';
  2383. return sym;
  2384. }
  2385.  
  2386. Hogan.codegen = {
  2387. '#': function(node, context) {
  2388. context.code += 'if(t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),' +
  2389. 'c,p,0,' + node.i + ',' + node.end + ',"' + node.otag + " " + node.ctag + '")){' +
  2390. 't.rs(c,p,' + 'function(c,p,t){';
  2391. Hogan.walk(node.nodes, context);
  2392. context.code += '});c.pop();}';
  2393. },
  2394.  
  2395. '^': function(node, context) {
  2396. context.code += 'if(!t.s(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,1),c,p,1,0,0,"")){';
  2397. Hogan.walk(node.nodes, context);
  2398. context.code += '};';
  2399. },
  2400.  
  2401. '>': createPartial,
  2402. '<': function(node, context) {
  2403. var ctx = {partials: {}, code: '', subs: {}, inPartial: true};
  2404. Hogan.walk(node.nodes, ctx);
  2405. var template = context.partials[createPartial(node, context)];
  2406. template.subs = ctx.subs;
  2407. template.partials = ctx.partials;
  2408. },
  2409.  
  2410. '$': function(node, context) {
  2411. var ctx = {subs: {}, code: '', partials: context.partials, prefix: node.n};
  2412. Hogan.walk(node.nodes, ctx);
  2413. context.subs[node.n] = ctx.code;
  2414. if (!context.inPartial) {
  2415. context.code += 't.sub("' + esc(node.n) + '",c,p,i);';
  2416. }
  2417. },
  2418.  
  2419. '\n': function(node, context) {
  2420. context.code += write('"\\n"' + (node.last ? '' : ' + i'));
  2421. },
  2422.  
  2423. '_v': function(node, context) {
  2424. context.code += 't.b(t.v(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
  2425. },
  2426.  
  2427. '_t': function(node, context) {
  2428. context.code += write('"' + esc(node.text) + '"');
  2429. },
  2430.  
  2431. '{': tripleStache,
  2432.  
  2433. '&': tripleStache
  2434. }
  2435.  
  2436. function tripleStache(node, context) {
  2437. context.code += 't.b(t.t(t.' + chooseMethod(node.n) + '("' + esc(node.n) + '",c,p,0)));';
  2438. }
  2439.  
  2440. function write(s) {
  2441. return 't.b(' + s + ');';
  2442. }
  2443.  
  2444. Hogan.walk = function(nodelist, context) {
  2445. var func;
  2446. for (var i = 0, l = nodelist.length; i < l; i++) {
  2447. func = Hogan.codegen[nodelist[i].tag];
  2448. func && func(nodelist[i], context);
  2449. }
  2450. return context;
  2451. }
  2452.  
  2453. Hogan.parse = function(tokens, text, options) {
  2454. options = options || {};
  2455. return buildTree(tokens, '', [], options.sectionTags || []);
  2456. }
  2457.  
  2458. Hogan.cache = {};
  2459.  
  2460. Hogan.cacheKey = function(text, options) {
  2461. return [text, !!options.asString, !!options.disableLambda, options.delimiters, !!options.modelGet].join('||');
  2462. }
  2463.  
  2464. Hogan.compile = function(text, options) {
  2465. options = options || {};
  2466. var key = Hogan.cacheKey(text, options);
  2467. var template = this.cache[key];
  2468.  
  2469. if (template) {
  2470. var partials = template.partials;
  2471. for (var name in partials) {
  2472. delete partials[name].instance;
  2473. }
  2474. return template;
  2475. }
  2476.  
  2477. template = this.generate(this.parse(this.scan(text, options.delimiters), text, options), text, options);
  2478. return this.cache[key] = template;
  2479. }
  2480. })( true ? exports : undefined);
  2481.  
  2482.  
  2483. /***/ }),
  2484.  
  2485. /***/ "Ruv9":
  2486. /***/ (function(module, exports, __webpack_require__) {
  2487.  
  2488. /*
  2489. * Copyright 2011 Twitter, Inc.
  2490. * Licensed under the Apache License, Version 2.0 (the "License");
  2491. * you may not use this file except in compliance with the License.
  2492. * You may obtain a copy of the License at
  2493. *
  2494. * http://www.apache.org/licenses/LICENSE-2.0
  2495. *
  2496. * Unless required by applicable law or agreed to in writing, software
  2497. * distributed under the License is distributed on an "AS IS" BASIS,
  2498. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2499. * See the License for the specific language governing permissions and
  2500. * limitations under the License.
  2501. */
  2502.  
  2503. // This file is for use with Node.js. See dist/ for browser files.
  2504.  
  2505. var Hogan = __webpack_require__("PKsF");
  2506. Hogan.Template = __webpack_require__("cK6b").Template;
  2507. Hogan.template = Hogan.Template;
  2508. module.exports = Hogan;
  2509.  
  2510.  
  2511. /***/ }),
  2512.  
  2513. /***/ "cK6b":
  2514. /***/ (function(module, exports, __webpack_require__) {
  2515.  
  2516. /*
  2517. * Copyright 2011 Twitter, Inc.
  2518. * Licensed under the Apache License, Version 2.0 (the "License");
  2519. * you may not use this file except in compliance with the License.
  2520. * You may obtain a copy of the License at
  2521. *
  2522. * http://www.apache.org/licenses/LICENSE-2.0
  2523. *
  2524. * Unless required by applicable law or agreed to in writing, software
  2525. * distributed under the License is distributed on an "AS IS" BASIS,
  2526. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2527. * See the License for the specific language governing permissions and
  2528. * limitations under the License.
  2529. */
  2530.  
  2531. var Hogan = {};
  2532.  
  2533. (function (Hogan) {
  2534. Hogan.Template = function (codeObj, text, compiler, options) {
  2535. codeObj = codeObj || {};
  2536. this.r = codeObj.code || this.r;
  2537. this.c = compiler;
  2538. this.options = options || {};
  2539. this.text = text || '';
  2540. this.partials = codeObj.partials || {};
  2541. this.subs = codeObj.subs || {};
  2542. this.buf = '';
  2543. }
  2544.  
  2545. Hogan.Template.prototype = {
  2546. // render: replaced by generated code.
  2547. r: function (context, partials, indent) { return ''; },
  2548.  
  2549. // variable escaping
  2550. v: hoganEscape,
  2551.  
  2552. // triple stache
  2553. t: coerceToString,
  2554.  
  2555. render: function render(context, partials, indent) {
  2556. return this.ri([context], partials || {}, indent);
  2557. },
  2558.  
  2559. // render internal -- a hook for overrides that catches partials too
  2560. ri: function (context, partials, indent) {
  2561. return this.r(context, partials, indent);
  2562. },
  2563.  
  2564. // ensurePartial
  2565. ep: function(symbol, partials) {
  2566. var partial = this.partials[symbol];
  2567.  
  2568. // check to see that if we've instantiated this partial before
  2569. var template = partials[partial.name];
  2570. if (partial.instance && partial.base == template) {
  2571. return partial.instance;
  2572. }
  2573.  
  2574. if (typeof template == 'string') {
  2575. if (!this.c) {
  2576. throw new Error("No compiler available.");
  2577. }
  2578. template = this.c.compile(template, this.options);
  2579. }
  2580.  
  2581. if (!template) {
  2582. return null;
  2583. }
  2584.  
  2585. // We use this to check whether the partials dictionary has changed
  2586. this.partials[symbol].base = template;
  2587.  
  2588. if (partial.subs) {
  2589. // Make sure we consider parent template now
  2590. if (!partials.stackText) partials.stackText = {};
  2591. for (key in partial.subs) {
  2592. if (!partials.stackText[key]) {
  2593. partials.stackText[key] = (this.activeSub !== undefined && partials.stackText[this.activeSub]) ? partials.stackText[this.activeSub] : this.text;
  2594. }
  2595. }
  2596. template = createSpecializedPartial(template, partial.subs, partial.partials,
  2597. this.stackSubs, this.stackPartials, partials.stackText);
  2598. }
  2599. this.partials[symbol].instance = template;
  2600.  
  2601. return template;
  2602. },
  2603.  
  2604. // tries to find a partial in the current scope and render it
  2605. rp: function(symbol, context, partials, indent) {
  2606. var partial = this.ep(symbol, partials);
  2607. if (!partial) {
  2608. return '';
  2609. }
  2610.  
  2611. return partial.ri(context, partials, indent);
  2612. },
  2613.  
  2614. // render a section
  2615. rs: function(context, partials, section) {
  2616. var tail = context[context.length - 1];
  2617.  
  2618. if (!isArray(tail)) {
  2619. section(context, partials, this);
  2620. return;
  2621. }
  2622.  
  2623. for (var i = 0; i < tail.length; i++) {
  2624. context.push(tail[i]);
  2625. section(context, partials, this);
  2626. context.pop();
  2627. }
  2628. },
  2629.  
  2630. // maybe start a section
  2631. s: function(val, ctx, partials, inverted, start, end, tags) {
  2632. var pass;
  2633.  
  2634. if (isArray(val) && val.length === 0) {
  2635. return false;
  2636. }
  2637.  
  2638. if (typeof val == 'function') {
  2639. val = this.ms(val, ctx, partials, inverted, start, end, tags);
  2640. }
  2641.  
  2642. pass = !!val;
  2643.  
  2644. if (!inverted && pass && ctx) {
  2645. ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
  2646. }
  2647.  
  2648. return pass;
  2649. },
  2650.  
  2651. // find values with dotted names
  2652. d: function(key, ctx, partials, returnFound) {
  2653. var found,
  2654. names = key.split('.'),
  2655. val = this.f(names[0], ctx, partials, returnFound),
  2656. doModelGet = this.options.modelGet,
  2657. cx = null;
  2658.  
  2659. if (key === '.' && isArray(ctx[ctx.length - 2])) {
  2660. val = ctx[ctx.length - 1];
  2661. } else {
  2662. for (var i = 1; i < names.length; i++) {
  2663. found = findInScope(names[i], val, doModelGet);
  2664. if (found !== undefined) {
  2665. cx = val;
  2666. val = found;
  2667. } else {
  2668. val = '';
  2669. }
  2670. }
  2671. }
  2672.  
  2673. if (returnFound && !val) {
  2674. return false;
  2675. }
  2676.  
  2677. if (!returnFound && typeof val == 'function') {
  2678. ctx.push(cx);
  2679. val = this.mv(val, ctx, partials);
  2680. ctx.pop();
  2681. }
  2682.  
  2683. return val;
  2684. },
  2685.  
  2686. // find values with normal names
  2687. f: function(key, ctx, partials, returnFound) {
  2688. var val = false,
  2689. v = null,
  2690. found = false,
  2691. doModelGet = this.options.modelGet;
  2692.  
  2693. for (var i = ctx.length - 1; i >= 0; i--) {
  2694. v = ctx[i];
  2695. val = findInScope(key, v, doModelGet);
  2696. if (val !== undefined) {
  2697. found = true;
  2698. break;
  2699. }
  2700. }
  2701.  
  2702. if (!found) {
  2703. return (returnFound) ? false : "";
  2704. }
  2705.  
  2706. if (!returnFound && typeof val == 'function') {
  2707. val = this.mv(val, ctx, partials);
  2708. }
  2709.  
  2710. return val;
  2711. },
  2712.  
  2713. // higher order templates
  2714. ls: function(func, cx, partials, text, tags) {
  2715. var oldTags = this.options.delimiters;
  2716.  
  2717. this.options.delimiters = tags;
  2718. this.b(this.ct(coerceToString(func.call(cx, text)), cx, partials));
  2719. this.options.delimiters = oldTags;
  2720.  
  2721. return false;
  2722. },
  2723.  
  2724. // compile text
  2725. ct: function(text, cx, partials) {
  2726. if (this.options.disableLambda) {
  2727. throw new Error('Lambda features disabled.');
  2728. }
  2729. return this.c.compile(text, this.options).render(cx, partials);
  2730. },
  2731.  
  2732. // template result buffering
  2733. b: function(s) { this.buf += s; },
  2734.  
  2735. fl: function() { var r = this.buf; this.buf = ''; return r; },
  2736.  
  2737. // method replace section
  2738. ms: function(func, ctx, partials, inverted, start, end, tags) {
  2739. var textSource,
  2740. cx = ctx[ctx.length - 1],
  2741. result = func.call(cx);
  2742.  
  2743. if (typeof result == 'function') {
  2744. if (inverted) {
  2745. return true;
  2746. } else {
  2747. textSource = (this.activeSub && this.subsText && this.subsText[this.activeSub]) ? this.subsText[this.activeSub] : this.text;
  2748. return this.ls(result, cx, partials, textSource.substring(start, end), tags);
  2749. }
  2750. }
  2751.  
  2752. return result;
  2753. },
  2754.  
  2755. // method replace variable
  2756. mv: function(func, ctx, partials) {
  2757. var cx = ctx[ctx.length - 1];
  2758. var result = func.call(cx);
  2759.  
  2760. if (typeof result == 'function') {
  2761. return this.ct(coerceToString(result.call(cx)), cx, partials);
  2762. }
  2763.  
  2764. return result;
  2765. },
  2766.  
  2767. sub: function(name, context, partials, indent) {
  2768. var f = this.subs[name];
  2769. if (f) {
  2770. this.activeSub = name;
  2771. f(context, partials, this, indent);
  2772. this.activeSub = false;
  2773. }
  2774. }
  2775.  
  2776. };
  2777.  
  2778. //Find a key in an object
  2779. function findInScope(key, scope, doModelGet) {
  2780. var val;
  2781.  
  2782. if (scope && typeof scope == 'object') {
  2783.  
  2784. if (scope[key] !== undefined) {
  2785. val = scope[key];
  2786.  
  2787. // try lookup with get for backbone or similar model data
  2788. } else if (doModelGet && scope.get && typeof scope.get == 'function') {
  2789. val = scope.get(key);
  2790. }
  2791. }
  2792.  
  2793. return val;
  2794. }
  2795.  
  2796. function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) {
  2797. function PartialTemplate() {};
  2798. PartialTemplate.prototype = instance;
  2799. function Substitutions() {};
  2800. Substitutions.prototype = instance.subs;
  2801. var key;
  2802. var partial = new PartialTemplate();
  2803. partial.subs = new Substitutions();
  2804. partial.subsText = {}; //hehe. substext.
  2805. partial.buf = '';
  2806.  
  2807. stackSubs = stackSubs || {};
  2808. partial.stackSubs = stackSubs;
  2809. partial.subsText = stackText;
  2810. for (key in subs) {
  2811. if (!stackSubs[key]) stackSubs[key] = subs[key];
  2812. }
  2813. for (key in stackSubs) {
  2814. partial.subs[key] = stackSubs[key];
  2815. }
  2816.  
  2817. stackPartials = stackPartials || {};
  2818. partial.stackPartials = stackPartials;
  2819. for (key in partials) {
  2820. if (!stackPartials[key]) stackPartials[key] = partials[key];
  2821. }
  2822. for (key in stackPartials) {
  2823. partial.partials[key] = stackPartials[key];
  2824. }
  2825.  
  2826. return partial;
  2827. }
  2828.  
  2829. var rAmp = /&/g,
  2830. rLt = /</g,
  2831. rGt = />/g,
  2832. rApos = /\'/g,
  2833. rQuot = /\"/g,
  2834. hChars = /[&<>\"\']/;
  2835.  
  2836. function coerceToString(val) {
  2837. return String((val === null || val === undefined) ? '' : val);
  2838. }
  2839.  
  2840. function hoganEscape(str) {
  2841. str = coerceToString(str);
  2842. return hChars.test(str) ?
  2843. str
  2844. .replace(rAmp, '&amp;')
  2845. .replace(rLt, '&lt;')
  2846. .replace(rGt, '&gt;')
  2847. .replace(rApos, '&#39;')
  2848. .replace(rQuot, '&quot;') :
  2849. str;
  2850. }
  2851.  
  2852. var isArray = Array.isArray || function(a) {
  2853. return Object.prototype.toString.call(a) === '[object Array]';
  2854. };
  2855.  
  2856. })( true ? exports : undefined);
  2857.  
  2858.  
  2859. /***/ }),
  2860.  
  2861. /***/ "e6Wu":
  2862. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2863.  
  2864. "use strict";
  2865. // ESM COMPAT FLAG
  2866. __webpack_require__.r(__webpack_exports__);
  2867.  
  2868. // EXTERNAL MODULE: ./node_modules/difflib/index.js
  2869. var difflib = __webpack_require__("7Mwc");
  2870.  
  2871. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/types.js
  2872. var LineType;
  2873. (function (LineType) {
  2874. LineType["INSERT"] = "insert";
  2875. LineType["DELETE"] = "delete";
  2876. LineType["CONTEXT"] = "context";
  2877. })(LineType || (LineType = {}));
  2878. var OutputFormatType = {
  2879. LINE_BY_LINE: 'line-by-line',
  2880. SIDE_BY_SIDE: 'side-by-side',
  2881. };
  2882. var LineMatchingType = {
  2883. LINES: 'lines',
  2884. WORDS: 'words',
  2885. NONE: 'none',
  2886. };
  2887. var DiffStyleType = {
  2888. WORD: 'word',
  2889. CHAR: 'char',
  2890. };
  2891. //# sourceMappingURL=types.js.map
  2892. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/utils.js
  2893. var specials = [
  2894. '-',
  2895. '[',
  2896. ']',
  2897. '/',
  2898. '{',
  2899. '}',
  2900. '(',
  2901. ')',
  2902. '*',
  2903. '+',
  2904. '?',
  2905. '.',
  2906. '\\',
  2907. '^',
  2908. '$',
  2909. '|',
  2910. ];
  2911. var regex = RegExp('[' + specials.join('\\') + ']', 'g');
  2912. function escapeForRegExp(str) {
  2913. return str.replace(regex, '\\$&');
  2914. }
  2915. function unifyPath(path) {
  2916. return path ? path.replace(/\\/g, '/') : path;
  2917. }
  2918. function hashCode(text) {
  2919. var i, chr, len;
  2920. var hash = 0;
  2921. for (i = 0, len = text.length; i < len; i++) {
  2922. chr = text.charCodeAt(i);
  2923. hash = (hash << 5) - hash + chr;
  2924. hash |= 0;
  2925. }
  2926. return hash;
  2927. }
  2928. //# sourceMappingURL=utils.js.map
  2929. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/diff-parser.js
  2930. var __spreadArrays = (undefined && undefined.__spreadArrays) || function () {
  2931. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  2932. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  2933. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  2934. r[k] = a[j];
  2935. return r;
  2936. };
  2937.  
  2938.  
  2939. function getExtension(filename, language) {
  2940. var filenameParts = filename.split('.');
  2941. return filenameParts.length > 1 ? filenameParts[filenameParts.length - 1] : language;
  2942. }
  2943. function startsWithAny(str, prefixes) {
  2944. return prefixes.reduce(function (startsWith, prefix) { return startsWith || str.startsWith(prefix); }, false);
  2945. }
  2946. var baseDiffFilenamePrefixes = ['a/', 'b/', 'i/', 'w/', 'c/', 'o/'];
  2947. function getFilename(line, linePrefix, extraPrefix) {
  2948. var prefixes = extraPrefix !== undefined ? __spreadArrays(baseDiffFilenamePrefixes, [extraPrefix]) : baseDiffFilenamePrefixes;
  2949. var FilenameRegExp = linePrefix
  2950. ? new RegExp("^" + escapeForRegExp(linePrefix) + " \"?(.+?)\"?$")
  2951. : new RegExp('^"?(.+?)"?$');
  2952. var _a = FilenameRegExp.exec(line) || [], _b = _a[1], filename = _b === void 0 ? '' : _b;
  2953. var matchingPrefix = prefixes.find(function (p) { return filename.indexOf(p) === 0; });
  2954. var fnameWithoutPrefix = matchingPrefix ? filename.slice(matchingPrefix.length) : filename;
  2955. return fnameWithoutPrefix.replace(/\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)? [+-]\d{4}.*$/, '');
  2956. }
  2957. function getSrcFilename(line, srcPrefix) {
  2958. return getFilename(line, '---', srcPrefix);
  2959. }
  2960. function getDstFilename(line, dstPrefix) {
  2961. return getFilename(line, '+++', dstPrefix);
  2962. }
  2963. function parse(diffInput, config) {
  2964. if (config === void 0) { config = {}; }
  2965. var files = [];
  2966. var currentFile = null;
  2967. var currentBlock = null;
  2968. var oldLine = null;
  2969. var oldLine2 = null;
  2970. var newLine = null;
  2971. var possibleOldName = null;
  2972. var possibleNewName = null;
  2973. var oldFileNameHeader = '--- ';
  2974. var newFileNameHeader = '+++ ';
  2975. var hunkHeaderPrefix = '@@';
  2976. var oldMode = /^old mode (\d{6})/;
  2977. var newMode = /^new mode (\d{6})/;
  2978. var deletedFileMode = /^deleted file mode (\d{6})/;
  2979. var newFileMode = /^new file mode (\d{6})/;
  2980. var copyFrom = /^copy from "?(.+)"?/;
  2981. var copyTo = /^copy to "?(.+)"?/;
  2982. var renameFrom = /^rename from "?(.+)"?/;
  2983. var renameTo = /^rename to "?(.+)"?/;
  2984. var similarityIndex = /^similarity index (\d+)%/;
  2985. var dissimilarityIndex = /^dissimilarity index (\d+)%/;
  2986. var index = /^index ([\da-z]+)\.\.([\da-z]+)\s*(\d{6})?/;
  2987. var binaryFiles = /^Binary files (.*) and (.*) differ/;
  2988. var binaryDiff = /^GIT binary patch/;
  2989. var combinedIndex = /^index ([\da-z]+),([\da-z]+)\.\.([\da-z]+)/;
  2990. var combinedMode = /^mode (\d{6}),(\d{6})\.\.(\d{6})/;
  2991. var combinedNewFile = /^new file mode (\d{6})/;
  2992. var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/;
  2993. var diffLines = diffInput
  2994. .replace(/\\ No newline at end of file/g, '')
  2995. .replace(/\r\n?/g, '\n')
  2996. .split('\n');
  2997. function saveBlock() {
  2998. if (currentBlock !== null && currentFile !== null) {
  2999. currentFile.blocks.push(currentBlock);
  3000. currentBlock = null;
  3001. }
  3002. }
  3003. function saveFile() {
  3004. if (currentFile !== null) {
  3005. if (!currentFile.oldName && possibleOldName !== null) {
  3006. currentFile.oldName = possibleOldName;
  3007. }
  3008. if (!currentFile.newName && possibleNewName !== null) {
  3009. currentFile.newName = possibleNewName;
  3010. }
  3011. if (currentFile.newName) {
  3012. files.push(currentFile);
  3013. currentFile = null;
  3014. }
  3015. }
  3016. possibleOldName = null;
  3017. possibleNewName = null;
  3018. }
  3019. function startFile() {
  3020. saveBlock();
  3021. saveFile();
  3022. currentFile = {
  3023. blocks: [],
  3024. deletedLines: 0,
  3025. addedLines: 0,
  3026. };
  3027. }
  3028. function startBlock(line) {
  3029. saveBlock();
  3030. var values;
  3031. if (currentFile !== null) {
  3032. if ((values = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@.*/.exec(line))) {
  3033. currentFile.isCombined = false;
  3034. oldLine = parseInt(values[1], 10);
  3035. newLine = parseInt(values[2], 10);
  3036. }
  3037. else if ((values = /^@@@ -(\d+)(?:,\d+)? -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@@.*/.exec(line))) {
  3038. currentFile.isCombined = true;
  3039. oldLine = parseInt(values[1], 10);
  3040. oldLine2 = parseInt(values[2], 10);
  3041. newLine = parseInt(values[3], 10);
  3042. }
  3043. else {
  3044. if (line.startsWith(hunkHeaderPrefix)) {
  3045. console.error('Failed to parse lines, starting in 0!');
  3046. }
  3047. oldLine = 0;
  3048. newLine = 0;
  3049. currentFile.isCombined = false;
  3050. }
  3051. }
  3052. currentBlock = {
  3053. lines: [],
  3054. oldStartLine: oldLine,
  3055. oldStartLine2: oldLine2,
  3056. newStartLine: newLine,
  3057. header: line,
  3058. };
  3059. }
  3060. function createLine(line) {
  3061. if (currentFile === null || currentBlock === null || oldLine === null || newLine === null)
  3062. return;
  3063. var currentLine = {
  3064. content: line,
  3065. };
  3066. var addedPrefixes = currentFile.isCombined ? ['+ ', ' +', '++'] : ['+'];
  3067. var deletedPrefixes = currentFile.isCombined ? ['- ', ' -', '--'] : ['-'];
  3068. if (startsWithAny(line, addedPrefixes)) {
  3069. currentFile.addedLines++;
  3070. currentLine.type = LineType.INSERT;
  3071. currentLine.oldNumber = undefined;
  3072. currentLine.newNumber = newLine++;
  3073. }
  3074. else if (startsWithAny(line, deletedPrefixes)) {
  3075. currentFile.deletedLines++;
  3076. currentLine.type = LineType.DELETE;
  3077. currentLine.oldNumber = oldLine++;
  3078. currentLine.newNumber = undefined;
  3079. }
  3080. else {
  3081. currentLine.type = LineType.CONTEXT;
  3082. currentLine.oldNumber = oldLine++;
  3083. currentLine.newNumber = newLine++;
  3084. }
  3085. currentBlock.lines.push(currentLine);
  3086. }
  3087. function existHunkHeader(line, lineIdx) {
  3088. var idx = lineIdx;
  3089. while (idx < diffLines.length - 3) {
  3090. if (line.startsWith('diff')) {
  3091. return false;
  3092. }
  3093. if (diffLines[idx].startsWith(oldFileNameHeader) &&
  3094. diffLines[idx + 1].startsWith(newFileNameHeader) &&
  3095. diffLines[idx + 2].startsWith(hunkHeaderPrefix)) {
  3096. return true;
  3097. }
  3098. idx++;
  3099. }
  3100. return false;
  3101. }
  3102. diffLines.forEach(function (line, lineIndex) {
  3103. if (!line || line.startsWith('*')) {
  3104. return;
  3105. }
  3106. var values;
  3107. var prevLine = diffLines[lineIndex - 1];
  3108. var nxtLine = diffLines[lineIndex + 1];
  3109. var afterNxtLine = diffLines[lineIndex + 2];
  3110. if (line.startsWith('diff')) {
  3111. startFile();
  3112. var gitDiffStart = /^diff --git "?(.+)"? "?(.+)"?/;
  3113. if ((values = gitDiffStart.exec(line))) {
  3114. possibleOldName = getFilename(values[1], undefined, config.dstPrefix);
  3115. possibleNewName = getFilename(values[2], undefined, config.srcPrefix);
  3116. }
  3117. if (currentFile === null) {
  3118. throw new Error('Where is my file !!!');
  3119. }
  3120. currentFile.isGitDiff = true;
  3121. return;
  3122. }
  3123. if (!currentFile ||
  3124. (!currentFile.isGitDiff &&
  3125. currentFile &&
  3126. line.startsWith(oldFileNameHeader) &&
  3127. nxtLine.startsWith(newFileNameHeader) &&
  3128. afterNxtLine.startsWith(hunkHeaderPrefix))) {
  3129. startFile();
  3130. }
  3131. if ((line.startsWith(oldFileNameHeader) && nxtLine.startsWith(newFileNameHeader)) ||
  3132. (line.startsWith(newFileNameHeader) && prevLine.startsWith(oldFileNameHeader))) {
  3133. if (currentFile &&
  3134. !currentFile.oldName &&
  3135. line.startsWith('--- ') &&
  3136. (values = getSrcFilename(line, config.srcPrefix))) {
  3137. currentFile.oldName = values;
  3138. currentFile.language = getExtension(currentFile.oldName, currentFile.language);
  3139. return;
  3140. }
  3141. if (currentFile &&
  3142. !currentFile.newName &&
  3143. line.startsWith('+++ ') &&
  3144. (values = getDstFilename(line, config.dstPrefix))) {
  3145. currentFile.newName = values;
  3146. currentFile.language = getExtension(currentFile.newName, currentFile.language);
  3147. return;
  3148. }
  3149. }
  3150. if (currentFile &&
  3151. (line.startsWith(hunkHeaderPrefix) ||
  3152. (currentFile.isGitDiff && currentFile.oldName && currentFile.newName && !currentBlock))) {
  3153. startBlock(line);
  3154. return;
  3155. }
  3156. if (currentBlock && (line.startsWith('+') || line.startsWith('-') || line.startsWith(' '))) {
  3157. createLine(line);
  3158. return;
  3159. }
  3160. var doesNotExistHunkHeader = !existHunkHeader(line, lineIndex);
  3161. if (currentFile === null) {
  3162. throw new Error('Where is my file !!!');
  3163. }
  3164. if ((values = oldMode.exec(line))) {
  3165. currentFile.oldMode = values[1];
  3166. }
  3167. else if ((values = newMode.exec(line))) {
  3168. currentFile.newMode = values[1];
  3169. }
  3170. else if ((values = deletedFileMode.exec(line))) {
  3171. currentFile.deletedFileMode = values[1];
  3172. currentFile.isDeleted = true;
  3173. }
  3174. else if ((values = newFileMode.exec(line))) {
  3175. currentFile.newFileMode = values[1];
  3176. currentFile.isNew = true;
  3177. }
  3178. else if ((values = copyFrom.exec(line))) {
  3179. if (doesNotExistHunkHeader) {
  3180. currentFile.oldName = values[1];
  3181. }
  3182. currentFile.isCopy = true;
  3183. }
  3184. else if ((values = copyTo.exec(line))) {
  3185. if (doesNotExistHunkHeader) {
  3186. currentFile.newName = values[1];
  3187. }
  3188. currentFile.isCopy = true;
  3189. }
  3190. else if ((values = renameFrom.exec(line))) {
  3191. if (doesNotExistHunkHeader) {
  3192. currentFile.oldName = values[1];
  3193. }
  3194. currentFile.isRename = true;
  3195. }
  3196. else if ((values = renameTo.exec(line))) {
  3197. if (doesNotExistHunkHeader) {
  3198. currentFile.newName = values[1];
  3199. }
  3200. currentFile.isRename = true;
  3201. }
  3202. else if ((values = binaryFiles.exec(line))) {
  3203. currentFile.isBinary = true;
  3204. currentFile.oldName = getFilename(values[1], undefined, config.srcPrefix);
  3205. currentFile.newName = getFilename(values[2], undefined, config.dstPrefix);
  3206. startBlock('Binary file');
  3207. }
  3208. else if (binaryDiff.test(line)) {
  3209. currentFile.isBinary = true;
  3210. startBlock(line);
  3211. }
  3212. else if ((values = similarityIndex.exec(line))) {
  3213. currentFile.unchangedPercentage = parseInt(values[1], 10);
  3214. }
  3215. else if ((values = dissimilarityIndex.exec(line))) {
  3216. currentFile.changedPercentage = parseInt(values[1], 10);
  3217. }
  3218. else if ((values = index.exec(line))) {
  3219. currentFile.checksumBefore = values[1];
  3220. currentFile.checksumAfter = values[2];
  3221. values[3] && (currentFile.mode = values[3]);
  3222. }
  3223. else if ((values = combinedIndex.exec(line))) {
  3224. currentFile.checksumBefore = [values[2], values[3]];
  3225. currentFile.checksumAfter = values[1];
  3226. }
  3227. else if ((values = combinedMode.exec(line))) {
  3228. currentFile.oldMode = [values[2], values[3]];
  3229. currentFile.newMode = values[1];
  3230. }
  3231. else if ((values = combinedNewFile.exec(line))) {
  3232. currentFile.newFileMode = values[1];
  3233. currentFile.isNew = true;
  3234. }
  3235. else if ((values = combinedDeletedFile.exec(line))) {
  3236. currentFile.deletedFileMode = values[1];
  3237. currentFile.isDeleted = true;
  3238. }
  3239. });
  3240. saveBlock();
  3241. saveFile();
  3242. return files;
  3243. }
  3244. //# sourceMappingURL=diff-parser.js.map
  3245. // EXTERNAL MODULE: ./node_modules/diff/dist/diff.js
  3246. var dist_diff = __webpack_require__("v2jn");
  3247.  
  3248. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/rematch.js
  3249. function levenshtein(a, b) {
  3250. if (a.length === 0) {
  3251. return b.length;
  3252. }
  3253. if (b.length === 0) {
  3254. return a.length;
  3255. }
  3256. var matrix = [];
  3257. var i;
  3258. for (i = 0; i <= b.length; i++) {
  3259. matrix[i] = [i];
  3260. }
  3261. var j;
  3262. for (j = 0; j <= a.length; j++) {
  3263. matrix[0][j] = j;
  3264. }
  3265. for (i = 1; i <= b.length; i++) {
  3266. for (j = 1; j <= a.length; j++) {
  3267. if (b.charAt(i - 1) === a.charAt(j - 1)) {
  3268. matrix[i][j] = matrix[i - 1][j - 1];
  3269. }
  3270. else {
  3271. matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1));
  3272. }
  3273. }
  3274. }
  3275. return matrix[b.length][a.length];
  3276. }
  3277. function newDistanceFn(str) {
  3278. return function (x, y) {
  3279. var xValue = str(x).trim();
  3280. var yValue = str(y).trim();
  3281. var lev = levenshtein(xValue, yValue);
  3282. return lev / (xValue.length + yValue.length);
  3283. };
  3284. }
  3285. function newMatcherFn(distance) {
  3286. function findBestMatch(a, b, cache) {
  3287. if (cache === void 0) { cache = new Map(); }
  3288. var bestMatchDist = Infinity;
  3289. var bestMatch;
  3290. for (var i = 0; i < a.length; ++i) {
  3291. for (var j = 0; j < b.length; ++j) {
  3292. var cacheKey = JSON.stringify([a[i], b[j]]);
  3293. var md = void 0;
  3294. if (!(cache.has(cacheKey) && (md = cache.get(cacheKey)))) {
  3295. md = distance(a[i], b[j]);
  3296. cache.set(cacheKey, md);
  3297. }
  3298. if (md < bestMatchDist) {
  3299. bestMatchDist = md;
  3300. bestMatch = { indexA: i, indexB: j, score: bestMatchDist };
  3301. }
  3302. }
  3303. }
  3304. return bestMatch;
  3305. }
  3306. function group(a, b, level, cache) {
  3307. if (level === void 0) { level = 0; }
  3308. if (cache === void 0) { cache = new Map(); }
  3309. var bm = findBestMatch(a, b, cache);
  3310. if (!bm || a.length + b.length < 3) {
  3311. return [[a, b]];
  3312. }
  3313. var a1 = a.slice(0, bm.indexA);
  3314. var b1 = b.slice(0, bm.indexB);
  3315. var aMatch = [a[bm.indexA]];
  3316. var bMatch = [b[bm.indexB]];
  3317. var tailA = bm.indexA + 1;
  3318. var tailB = bm.indexB + 1;
  3319. var a2 = a.slice(tailA);
  3320. var b2 = b.slice(tailB);
  3321. var group1 = group(a1, b1, level + 1, cache);
  3322. var groupMatch = group(aMatch, bMatch, level + 1, cache);
  3323. var group2 = group(a2, b2, level + 1, cache);
  3324. var result = groupMatch;
  3325. if (bm.indexA > 0 || bm.indexB > 0) {
  3326. result = group1.concat(result);
  3327. }
  3328. if (a.length > tailA || b.length > tailB) {
  3329. result = result.concat(group2);
  3330. }
  3331. return result;
  3332. }
  3333. return group;
  3334. }
  3335. //# sourceMappingURL=rematch.js.map
  3336. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/render-utils.js
  3337. var __assign = (undefined && undefined.__assign) || function () {
  3338. __assign = Object.assign || function(t) {
  3339. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3340. s = arguments[i];
  3341. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  3342. t[p] = s[p];
  3343. }
  3344. return t;
  3345. };
  3346. return __assign.apply(this, arguments);
  3347. };
  3348.  
  3349.  
  3350.  
  3351.  
  3352. var CSSLineClass = {
  3353. INSERTS: 'd2h-ins',
  3354. DELETES: 'd2h-del',
  3355. CONTEXT: 'd2h-cntx',
  3356. INFO: 'd2h-info',
  3357. INSERT_CHANGES: 'd2h-ins d2h-change',
  3358. DELETE_CHANGES: 'd2h-del d2h-change',
  3359. };
  3360. var defaultRenderConfig = {
  3361. matching: LineMatchingType.NONE,
  3362. matchWordsThreshold: 0.25,
  3363. maxLineLengthHighlight: 10000,
  3364. diffStyle: DiffStyleType.WORD,
  3365. };
  3366. var separator = '/';
  3367. var distance = newDistanceFn(function (change) { return change.value; });
  3368. var render_utils_matcher = newMatcherFn(distance);
  3369. function isDevNullName(name) {
  3370. return name.indexOf('dev/null') !== -1;
  3371. }
  3372. function removeInsElements(line) {
  3373. return line.replace(/(<ins[^>]*>((.|\n)*?)<\/ins>)/g, '');
  3374. }
  3375. function removeDelElements(line) {
  3376. return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
  3377. }
  3378. function toCSSClass(lineType) {
  3379. switch (lineType) {
  3380. case LineType.CONTEXT:
  3381. return CSSLineClass.CONTEXT;
  3382. case LineType.INSERT:
  3383. return CSSLineClass.INSERTS;
  3384. case LineType.DELETE:
  3385. return CSSLineClass.DELETES;
  3386. }
  3387. }
  3388. function prefixLength(isCombined) {
  3389. return isCombined ? 2 : 1;
  3390. }
  3391. function escapeForHtml(str) {
  3392. return str
  3393. .slice(0)
  3394. .replace(/&/g, '&amp;')
  3395. .replace(/</g, '&lt;')
  3396. .replace(/>/g, '&gt;')
  3397. .replace(/"/g, '&quot;')
  3398. .replace(/'/g, '&#x27;')
  3399. .replace(/\//g, '&#x2F;');
  3400. }
  3401. function deconstructLine(line, isCombined, escape) {
  3402. if (escape === void 0) { escape = true; }
  3403. var indexToSplit = prefixLength(isCombined);
  3404. return {
  3405. prefix: line.substring(0, indexToSplit),
  3406. content: escape ? escapeForHtml(line.substring(indexToSplit)) : line.substring(indexToSplit),
  3407. };
  3408. }
  3409. function filenameDiff(file) {
  3410. var oldFilename = unifyPath(file.oldName);
  3411. var newFilename = unifyPath(file.newName);
  3412. if (oldFilename !== newFilename && !isDevNullName(oldFilename) && !isDevNullName(newFilename)) {
  3413. var prefixPaths = [];
  3414. var suffixPaths = [];
  3415. var oldFilenameParts = oldFilename.split(separator);
  3416. var newFilenameParts = newFilename.split(separator);
  3417. var oldFilenamePartsSize = oldFilenameParts.length;
  3418. var newFilenamePartsSize = newFilenameParts.length;
  3419. var i = 0;
  3420. var j = oldFilenamePartsSize - 1;
  3421. var k = newFilenamePartsSize - 1;
  3422. while (i < j && i < k) {
  3423. if (oldFilenameParts[i] === newFilenameParts[i]) {
  3424. prefixPaths.push(newFilenameParts[i]);
  3425. i += 1;
  3426. }
  3427. else {
  3428. break;
  3429. }
  3430. }
  3431. while (j > i && k > i) {
  3432. if (oldFilenameParts[j] === newFilenameParts[k]) {
  3433. suffixPaths.unshift(newFilenameParts[k]);
  3434. j -= 1;
  3435. k -= 1;
  3436. }
  3437. else {
  3438. break;
  3439. }
  3440. }
  3441. var finalPrefix = prefixPaths.join(separator);
  3442. var finalSuffix = suffixPaths.join(separator);
  3443. var oldRemainingPath = oldFilenameParts.slice(i, j + 1).join(separator);
  3444. var newRemainingPath = newFilenameParts.slice(i, k + 1).join(separator);
  3445. if (finalPrefix.length && finalSuffix.length) {
  3446. return (finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix);
  3447. }
  3448. else if (finalPrefix.length) {
  3449. return finalPrefix + separator + '{' + oldRemainingPath + ' → ' + newRemainingPath + '}';
  3450. }
  3451. else if (finalSuffix.length) {
  3452. return '{' + oldRemainingPath + ' → ' + newRemainingPath + '}' + separator + finalSuffix;
  3453. }
  3454. return oldFilename + ' → ' + newFilename;
  3455. }
  3456. else if (!isDevNullName(newFilename)) {
  3457. return newFilename;
  3458. }
  3459. else {
  3460. return oldFilename;
  3461. }
  3462. }
  3463. function getHtmlId(file) {
  3464. return "d2h-" + hashCode(filenameDiff(file))
  3465. .toString()
  3466. .slice(-6);
  3467. }
  3468. function getFileIcon(file) {
  3469. var templateName = 'file-changed';
  3470. if (file.isRename) {
  3471. templateName = 'file-renamed';
  3472. }
  3473. else if (file.isCopy) {
  3474. templateName = 'file-renamed';
  3475. }
  3476. else if (file.isNew) {
  3477. templateName = 'file-added';
  3478. }
  3479. else if (file.isDeleted) {
  3480. templateName = 'file-deleted';
  3481. }
  3482. else if (file.newName !== file.oldName) {
  3483. templateName = 'file-renamed';
  3484. }
  3485. return templateName;
  3486. }
  3487. function diffHighlight(diffLine1, diffLine2, isCombined, config) {
  3488. if (config === void 0) { config = {}; }
  3489. var _a = __assign(__assign({}, defaultRenderConfig), config), matching = _a.matching, maxLineLengthHighlight = _a.maxLineLengthHighlight, matchWordsThreshold = _a.matchWordsThreshold, diffStyle = _a.diffStyle;
  3490. var line1 = deconstructLine(diffLine1, isCombined, false);
  3491. var line2 = deconstructLine(diffLine2, isCombined, false);
  3492. if (line1.content.length > maxLineLengthHighlight || line2.content.length > maxLineLengthHighlight) {
  3493. return {
  3494. oldLine: {
  3495. prefix: line1.prefix,
  3496. content: line1.content,
  3497. },
  3498. newLine: {
  3499. prefix: line2.prefix,
  3500. content: line2.content,
  3501. },
  3502. };
  3503. }
  3504. var diff = diffStyle === 'char'
  3505. ? dist_diff["diffChars"](line1.content, line2.content)
  3506. : dist_diff["diffWordsWithSpace"](line1.content, line2.content);
  3507. var changedWords = [];
  3508. if (diffStyle === 'word' && matching === 'words') {
  3509. var removed = diff.filter(function (element) { return element.removed; });
  3510. var added = diff.filter(function (element) { return element.added; });
  3511. var chunks = render_utils_matcher(added, removed);
  3512. chunks.forEach(function (chunk) {
  3513. if (chunk[0].length === 1 && chunk[1].length === 1) {
  3514. var dist = distance(chunk[0][0], chunk[1][0]);
  3515. if (dist < matchWordsThreshold) {
  3516. changedWords.push(chunk[0][0]);
  3517. changedWords.push(chunk[1][0]);
  3518. }
  3519. }
  3520. });
  3521. }
  3522. var highlightedLine = diff.reduce(function (highlightedLine, part) {
  3523. var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
  3524. var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
  3525. var escapedValue = escapeForHtml(part.value);
  3526. return elemType !== null
  3527. ? highlightedLine + "<" + elemType + addClass + ">" + escapedValue + "</" + elemType + ">"
  3528. : "" + highlightedLine + escapedValue;
  3529. }, '');
  3530. return {
  3531. oldLine: {
  3532. prefix: line1.prefix,
  3533. content: removeInsElements(highlightedLine),
  3534. },
  3535. newLine: {
  3536. prefix: line2.prefix,
  3537. content: removeDelElements(highlightedLine),
  3538. },
  3539. };
  3540. }
  3541. //# sourceMappingURL=render-utils.js.map
  3542. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/file-list-renderer.js
  3543.  
  3544. var baseTemplatesPath = 'file-summary';
  3545. var iconsBaseTemplatesPath = 'icon';
  3546. function render(diffFiles, hoganUtils) {
  3547. var files = diffFiles
  3548. .map(function (file) {
  3549. return hoganUtils.render(baseTemplatesPath, 'line', {
  3550. fileHtmlId: getHtmlId(file),
  3551. oldName: file.oldName,
  3552. newName: file.newName,
  3553. fileName: filenameDiff(file),
  3554. deletedLines: '-' + file.deletedLines,
  3555. addedLines: '+' + file.addedLines,
  3556. }, {
  3557. fileIcon: hoganUtils.template(iconsBaseTemplatesPath, getFileIcon(file)),
  3558. });
  3559. })
  3560. .join('\n');
  3561. return hoganUtils.render(baseTemplatesPath, 'wrapper', {
  3562. filesNumber: diffFiles.length,
  3563. files: files,
  3564. });
  3565. }
  3566. //# sourceMappingURL=file-list-renderer.js.map
  3567. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/line-by-line-renderer.js
  3568. var line_by_line_renderer_assign = (undefined && undefined.__assign) || function () {
  3569. line_by_line_renderer_assign = Object.assign || function(t) {
  3570. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3571. s = arguments[i];
  3572. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  3573. t[p] = s[p];
  3574. }
  3575. return t;
  3576. };
  3577. return line_by_line_renderer_assign.apply(this, arguments);
  3578. };
  3579.  
  3580.  
  3581.  
  3582. var defaultLineByLineRendererConfig = line_by_line_renderer_assign(line_by_line_renderer_assign({}, defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 });
  3583. var genericTemplatesPath = 'generic';
  3584. var line_by_line_renderer_baseTemplatesPath = 'line-by-line';
  3585. var line_by_line_renderer_iconsBaseTemplatesPath = 'icon';
  3586. var tagsBaseTemplatesPath = 'tag';
  3587. var line_by_line_renderer_LineByLineRenderer = (function () {
  3588. function LineByLineRenderer(hoganUtils, config) {
  3589. if (config === void 0) { config = {}; }
  3590. this.hoganUtils = hoganUtils;
  3591. this.config = line_by_line_renderer_assign(line_by_line_renderer_assign({}, defaultLineByLineRendererConfig), config);
  3592. }
  3593. LineByLineRenderer.prototype.render = function (diffFiles) {
  3594. var _this = this;
  3595. var diffsHtml = diffFiles
  3596. .map(function (file) {
  3597. var diffs;
  3598. if (file.blocks.length) {
  3599. diffs = _this.generateFileHtml(file);
  3600. }
  3601. else {
  3602. diffs = _this.generateEmptyDiff();
  3603. }
  3604. return _this.makeFileDiffHtml(file, diffs);
  3605. })
  3606. .join('\n');
  3607. return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml });
  3608. };
  3609. LineByLineRenderer.prototype.makeFileDiffHtml = function (file, diffs) {
  3610. if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0)
  3611. return '';
  3612. var fileDiffTemplate = this.hoganUtils.template(line_by_line_renderer_baseTemplatesPath, 'file-diff');
  3613. var filePathTemplate = this.hoganUtils.template(genericTemplatesPath, 'file-path');
  3614. var fileIconTemplate = this.hoganUtils.template(line_by_line_renderer_iconsBaseTemplatesPath, 'file');
  3615. var fileTagTemplate = this.hoganUtils.template(tagsBaseTemplatesPath, getFileIcon(file));
  3616. return fileDiffTemplate.render({
  3617. file: file,
  3618. fileHtmlId: getHtmlId(file),
  3619. diffs: diffs,
  3620. filePath: filePathTemplate.render({
  3621. fileDiffName: filenameDiff(file),
  3622. }, {
  3623. fileIcon: fileIconTemplate,
  3624. fileTag: fileTagTemplate,
  3625. }),
  3626. });
  3627. };
  3628. LineByLineRenderer.prototype.generateEmptyDiff = function () {
  3629. return this.hoganUtils.render(genericTemplatesPath, 'empty-diff', {
  3630. contentClass: 'd2h-code-line',
  3631. CSSLineClass: CSSLineClass,
  3632. });
  3633. };
  3634. LineByLineRenderer.prototype.generateFileHtml = function (file) {
  3635. var _this = this;
  3636. var matcher = newMatcherFn(newDistanceFn(function (e) { return deconstructLine(e.content, file.isCombined).content; }));
  3637. return file.blocks
  3638. .map(function (block) {
  3639. var lines = _this.hoganUtils.render(genericTemplatesPath, 'block-header', {
  3640. CSSLineClass: CSSLineClass,
  3641. blockHeader: block.header,
  3642. lineClass: 'd2h-code-linenumber',
  3643. contentClass: 'd2h-code-line',
  3644. });
  3645. _this.applyLineGroupping(block).forEach(function (_a) {
  3646. var contextLines = _a[0], oldLines = _a[1], newLines = _a[2];
  3647. if (oldLines.length && newLines.length && !contextLines.length) {
  3648. _this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) {
  3649. var oldLines = _a[0], newLines = _a[1];
  3650. var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right;
  3651. lines += left;
  3652. lines += right;
  3653. });
  3654. }
  3655. else if (contextLines.length) {
  3656. contextLines.forEach(function (line) {
  3657. var _a = deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content;
  3658. lines += _this.generateSingleLineHtml({
  3659. type: CSSLineClass.CONTEXT,
  3660. prefix: prefix,
  3661. content: content,
  3662. oldNumber: line.oldNumber,
  3663. newNumber: line.newNumber,
  3664. });
  3665. });
  3666. }
  3667. else if (oldLines.length || newLines.length) {
  3668. var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right;
  3669. lines += left;
  3670. lines += right;
  3671. }
  3672. else {
  3673. console.error('Unknown state reached while processing groups of lines', contextLines, oldLines, newLines);
  3674. }
  3675. });
  3676. return lines;
  3677. })
  3678. .join('\n');
  3679. };
  3680. LineByLineRenderer.prototype.applyLineGroupping = function (block) {
  3681. var blockLinesGroups = [];
  3682. var oldLines = [];
  3683. var newLines = [];
  3684. for (var i = 0; i < block.lines.length; i++) {
  3685. var diffLine = block.lines[i];
  3686. if ((diffLine.type !== LineType.INSERT && newLines.length) ||
  3687. (diffLine.type === LineType.CONTEXT && oldLines.length > 0)) {
  3688. blockLinesGroups.push([[], oldLines, newLines]);
  3689. oldLines = [];
  3690. newLines = [];
  3691. }
  3692. if (diffLine.type === LineType.CONTEXT) {
  3693. blockLinesGroups.push([[diffLine], [], []]);
  3694. }
  3695. else if (diffLine.type === LineType.INSERT && oldLines.length === 0) {
  3696. blockLinesGroups.push([[], [], [diffLine]]);
  3697. }
  3698. else if (diffLine.type === LineType.INSERT && oldLines.length > 0) {
  3699. newLines.push(diffLine);
  3700. }
  3701. else if (diffLine.type === LineType.DELETE) {
  3702. oldLines.push(diffLine);
  3703. }
  3704. }
  3705. if (oldLines.length || newLines.length) {
  3706. blockLinesGroups.push([[], oldLines, newLines]);
  3707. oldLines = [];
  3708. newLines = [];
  3709. }
  3710. return blockLinesGroups;
  3711. };
  3712. LineByLineRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) {
  3713. var comparisons = oldLines.length * newLines.length;
  3714. var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; })));
  3715. var doMatching = comparisons < this.config.matchingMaxComparisons &&
  3716. maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison &&
  3717. (this.config.matching === 'lines' || this.config.matching === 'words');
  3718. return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]];
  3719. };
  3720. LineByLineRenderer.prototype.processChangedLines = function (isCombined, oldLines, newLines) {
  3721. var fileHtml = {
  3722. right: '',
  3723. left: '',
  3724. };
  3725. var maxLinesNumber = Math.max(oldLines.length, newLines.length);
  3726. for (var i = 0; i < maxLinesNumber; i++) {
  3727. var oldLine = oldLines[i];
  3728. var newLine = newLines[i];
  3729. var diff = oldLine !== undefined && newLine !== undefined
  3730. ? diffHighlight(oldLine.content, newLine.content, isCombined, this.config)
  3731. : undefined;
  3732. var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined
  3733. ? line_by_line_renderer_assign(line_by_line_renderer_assign({}, (diff !== undefined
  3734. ? {
  3735. prefix: diff.oldLine.prefix,
  3736. content: diff.oldLine.content,
  3737. type: CSSLineClass.DELETE_CHANGES,
  3738. }
  3739. : line_by_line_renderer_assign(line_by_line_renderer_assign({}, deconstructLine(oldLine.content, isCombined)), { type: toCSSClass(oldLine.type) }))), { oldNumber: oldLine.oldNumber, newNumber: oldLine.newNumber }) : undefined;
  3740. var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined
  3741. ? line_by_line_renderer_assign(line_by_line_renderer_assign({}, (diff !== undefined
  3742. ? {
  3743. prefix: diff.newLine.prefix,
  3744. content: diff.newLine.content,
  3745. type: CSSLineClass.INSERT_CHANGES,
  3746. }
  3747. : line_by_line_renderer_assign(line_by_line_renderer_assign({}, deconstructLine(newLine.content, isCombined)), { type: toCSSClass(newLine.type) }))), { oldNumber: newLine.oldNumber, newNumber: newLine.newNumber }) : undefined;
  3748. var _a = this.generateLineHtml(preparedOldLine, preparedNewLine), left = _a.left, right = _a.right;
  3749. fileHtml.left += left;
  3750. fileHtml.right += right;
  3751. }
  3752. return fileHtml;
  3753. };
  3754. LineByLineRenderer.prototype.generateLineHtml = function (oldLine, newLine) {
  3755. return {
  3756. left: this.generateSingleLineHtml(oldLine),
  3757. right: this.generateSingleLineHtml(newLine),
  3758. };
  3759. };
  3760. LineByLineRenderer.prototype.generateSingleLineHtml = function (line) {
  3761. if (line === undefined)
  3762. return '';
  3763. var lineNumberHtml = this.hoganUtils.render(line_by_line_renderer_baseTemplatesPath, 'numbers', {
  3764. oldNumber: line.oldNumber || '',
  3765. newNumber: line.newNumber || '',
  3766. });
  3767. return this.hoganUtils.render(genericTemplatesPath, 'line', {
  3768. type: line.type,
  3769. lineClass: 'd2h-code-linenumber',
  3770. contentClass: 'd2h-code-line',
  3771. prefix: line.prefix === ' ' ? '&nbsp;' : line.prefix,
  3772. content: line.content,
  3773. lineNumber: lineNumberHtml,
  3774. });
  3775. };
  3776. return LineByLineRenderer;
  3777. }());
  3778. /* harmony default export */ var line_by_line_renderer = (line_by_line_renderer_LineByLineRenderer);
  3779. //# sourceMappingURL=line-by-line-renderer.js.map
  3780. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/side-by-side-renderer.js
  3781. var side_by_side_renderer_assign = (undefined && undefined.__assign) || function () {
  3782. side_by_side_renderer_assign = Object.assign || function(t) {
  3783. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3784. s = arguments[i];
  3785. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  3786. t[p] = s[p];
  3787. }
  3788. return t;
  3789. };
  3790. return side_by_side_renderer_assign.apply(this, arguments);
  3791. };
  3792.  
  3793.  
  3794.  
  3795. var defaultSideBySideRendererConfig = side_by_side_renderer_assign(side_by_side_renderer_assign({}, defaultRenderConfig), { renderNothingWhenEmpty: false, matchingMaxComparisons: 2500, maxLineSizeInBlockForComparison: 200 });
  3796. var side_by_side_renderer_genericTemplatesPath = 'generic';
  3797. var side_by_side_renderer_baseTemplatesPath = 'side-by-side';
  3798. var side_by_side_renderer_iconsBaseTemplatesPath = 'icon';
  3799. var side_by_side_renderer_tagsBaseTemplatesPath = 'tag';
  3800. var side_by_side_renderer_SideBySideRenderer = (function () {
  3801. function SideBySideRenderer(hoganUtils, config) {
  3802. if (config === void 0) { config = {}; }
  3803. this.hoganUtils = hoganUtils;
  3804. this.config = side_by_side_renderer_assign(side_by_side_renderer_assign({}, defaultSideBySideRendererConfig), config);
  3805. }
  3806. SideBySideRenderer.prototype.render = function (diffFiles) {
  3807. var _this = this;
  3808. var diffsHtml = diffFiles
  3809. .map(function (file) {
  3810. var diffs;
  3811. if (file.blocks.length) {
  3812. diffs = _this.generateFileHtml(file);
  3813. }
  3814. else {
  3815. diffs = _this.generateEmptyDiff();
  3816. }
  3817. return _this.makeFileDiffHtml(file, diffs);
  3818. })
  3819. .join('\n');
  3820. return this.hoganUtils.render(side_by_side_renderer_genericTemplatesPath, 'wrapper', { content: diffsHtml });
  3821. };
  3822. SideBySideRenderer.prototype.makeFileDiffHtml = function (file, diffs) {
  3823. if (this.config.renderNothingWhenEmpty && Array.isArray(file.blocks) && file.blocks.length === 0)
  3824. return '';
  3825. var fileDiffTemplate = this.hoganUtils.template(side_by_side_renderer_baseTemplatesPath, 'file-diff');
  3826. var filePathTemplate = this.hoganUtils.template(side_by_side_renderer_genericTemplatesPath, 'file-path');
  3827. var fileIconTemplate = this.hoganUtils.template(side_by_side_renderer_iconsBaseTemplatesPath, 'file');
  3828. var fileTagTemplate = this.hoganUtils.template(side_by_side_renderer_tagsBaseTemplatesPath, getFileIcon(file));
  3829. return fileDiffTemplate.render({
  3830. file: file,
  3831. fileHtmlId: getHtmlId(file),
  3832. diffs: diffs,
  3833. filePath: filePathTemplate.render({
  3834. fileDiffName: filenameDiff(file),
  3835. }, {
  3836. fileIcon: fileIconTemplate,
  3837. fileTag: fileTagTemplate,
  3838. }),
  3839. });
  3840. };
  3841. SideBySideRenderer.prototype.generateEmptyDiff = function () {
  3842. return {
  3843. right: '',
  3844. left: this.hoganUtils.render(side_by_side_renderer_genericTemplatesPath, 'empty-diff', {
  3845. contentClass: 'd2h-code-side-line',
  3846. CSSLineClass: CSSLineClass,
  3847. }),
  3848. };
  3849. };
  3850. SideBySideRenderer.prototype.generateFileHtml = function (file) {
  3851. var _this = this;
  3852. var matcher = newMatcherFn(newDistanceFn(function (e) { return deconstructLine(e.content, file.isCombined).content; }));
  3853. return file.blocks
  3854. .map(function (block) {
  3855. var fileHtml = {
  3856. left: _this.makeHeaderHtml(block.header),
  3857. right: _this.makeHeaderHtml(''),
  3858. };
  3859. _this.applyLineGroupping(block).forEach(function (_a) {
  3860. var contextLines = _a[0], oldLines = _a[1], newLines = _a[2];
  3861. if (oldLines.length && newLines.length && !contextLines.length) {
  3862. _this.applyRematchMatching(oldLines, newLines, matcher).map(function (_a) {
  3863. var oldLines = _a[0], newLines = _a[1];
  3864. var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right;
  3865. fileHtml.left += left;
  3866. fileHtml.right += right;
  3867. });
  3868. }
  3869. else if (contextLines.length) {
  3870. contextLines.forEach(function (line) {
  3871. var _a = deconstructLine(line.content, file.isCombined), prefix = _a.prefix, content = _a.content;
  3872. var _b = _this.generateLineHtml({
  3873. type: CSSLineClass.CONTEXT,
  3874. prefix: prefix,
  3875. content: content,
  3876. number: line.oldNumber,
  3877. }, {
  3878. type: CSSLineClass.CONTEXT,
  3879. prefix: prefix,
  3880. content: content,
  3881. number: line.newNumber,
  3882. }), left = _b.left, right = _b.right;
  3883. fileHtml.left += left;
  3884. fileHtml.right += right;
  3885. });
  3886. }
  3887. else if (oldLines.length || newLines.length) {
  3888. var _b = _this.processChangedLines(file.isCombined, oldLines, newLines), left = _b.left, right = _b.right;
  3889. fileHtml.left += left;
  3890. fileHtml.right += right;
  3891. }
  3892. else {
  3893. console.error('Unknown state reached while processing groups of lines', contextLines, oldLines, newLines);
  3894. }
  3895. });
  3896. return fileHtml;
  3897. })
  3898. .reduce(function (accomulated, html) {
  3899. return { left: accomulated.left + html.left, right: accomulated.right + html.right };
  3900. }, { left: '', right: '' });
  3901. };
  3902. SideBySideRenderer.prototype.applyLineGroupping = function (block) {
  3903. var blockLinesGroups = [];
  3904. var oldLines = [];
  3905. var newLines = [];
  3906. for (var i = 0; i < block.lines.length; i++) {
  3907. var diffLine = block.lines[i];
  3908. if ((diffLine.type !== LineType.INSERT && newLines.length) ||
  3909. (diffLine.type === LineType.CONTEXT && oldLines.length > 0)) {
  3910. blockLinesGroups.push([[], oldLines, newLines]);
  3911. oldLines = [];
  3912. newLines = [];
  3913. }
  3914. if (diffLine.type === LineType.CONTEXT) {
  3915. blockLinesGroups.push([[diffLine], [], []]);
  3916. }
  3917. else if (diffLine.type === LineType.INSERT && oldLines.length === 0) {
  3918. blockLinesGroups.push([[], [], [diffLine]]);
  3919. }
  3920. else if (diffLine.type === LineType.INSERT && oldLines.length > 0) {
  3921. newLines.push(diffLine);
  3922. }
  3923. else if (diffLine.type === LineType.DELETE) {
  3924. oldLines.push(diffLine);
  3925. }
  3926. }
  3927. if (oldLines.length || newLines.length) {
  3928. blockLinesGroups.push([[], oldLines, newLines]);
  3929. oldLines = [];
  3930. newLines = [];
  3931. }
  3932. return blockLinesGroups;
  3933. };
  3934. SideBySideRenderer.prototype.applyRematchMatching = function (oldLines, newLines, matcher) {
  3935. var comparisons = oldLines.length * newLines.length;
  3936. var maxLineSizeInBlock = Math.max.apply(null, [0].concat(oldLines.concat(newLines).map(function (elem) { return elem.content.length; })));
  3937. var doMatching = comparisons < this.config.matchingMaxComparisons &&
  3938. maxLineSizeInBlock < this.config.maxLineSizeInBlockForComparison &&
  3939. (this.config.matching === 'lines' || this.config.matching === 'words');
  3940. return doMatching ? matcher(oldLines, newLines) : [[oldLines, newLines]];
  3941. };
  3942. SideBySideRenderer.prototype.makeHeaderHtml = function (blockHeader) {
  3943. return this.hoganUtils.render(side_by_side_renderer_genericTemplatesPath, 'block-header', {
  3944. CSSLineClass: CSSLineClass,
  3945. blockHeader: blockHeader,
  3946. lineClass: 'd2h-code-side-linenumber',
  3947. contentClass: 'd2h-code-side-line',
  3948. });
  3949. };
  3950. SideBySideRenderer.prototype.processChangedLines = function (isCombined, oldLines, newLines) {
  3951. var fileHtml = {
  3952. right: '',
  3953. left: '',
  3954. };
  3955. var maxLinesNumber = Math.max(oldLines.length, newLines.length);
  3956. for (var i = 0; i < maxLinesNumber; i++) {
  3957. var oldLine = oldLines[i];
  3958. var newLine = newLines[i];
  3959. var diff = oldLine !== undefined && newLine !== undefined
  3960. ? diffHighlight(oldLine.content, newLine.content, isCombined, this.config)
  3961. : undefined;
  3962. var preparedOldLine = oldLine !== undefined && oldLine.oldNumber !== undefined
  3963. ? side_by_side_renderer_assign(side_by_side_renderer_assign({}, (diff !== undefined
  3964. ? {
  3965. prefix: diff.oldLine.prefix,
  3966. content: diff.oldLine.content,
  3967. type: CSSLineClass.DELETE_CHANGES,
  3968. }
  3969. : side_by_side_renderer_assign(side_by_side_renderer_assign({}, deconstructLine(oldLine.content, isCombined)), { type: toCSSClass(oldLine.type) }))), { number: oldLine.oldNumber }) : undefined;
  3970. var preparedNewLine = newLine !== undefined && newLine.newNumber !== undefined
  3971. ? side_by_side_renderer_assign(side_by_side_renderer_assign({}, (diff !== undefined
  3972. ? {
  3973. prefix: diff.newLine.prefix,
  3974. content: diff.newLine.content,
  3975. type: CSSLineClass.INSERT_CHANGES,
  3976. }
  3977. : side_by_side_renderer_assign(side_by_side_renderer_assign({}, deconstructLine(newLine.content, isCombined)), { type: toCSSClass(newLine.type) }))), { number: newLine.newNumber }) : undefined;
  3978. var _a = this.generateLineHtml(preparedOldLine, preparedNewLine), left = _a.left, right = _a.right;
  3979. fileHtml.left += left;
  3980. fileHtml.right += right;
  3981. }
  3982. return fileHtml;
  3983. };
  3984. SideBySideRenderer.prototype.generateLineHtml = function (oldLine, newLine) {
  3985. return {
  3986. left: this.generateSingleHtml(oldLine),
  3987. right: this.generateSingleHtml(newLine),
  3988. };
  3989. };
  3990. SideBySideRenderer.prototype.generateSingleHtml = function (line) {
  3991. var lineClass = 'd2h-code-side-linenumber';
  3992. var contentClass = 'd2h-code-side-line';
  3993. return this.hoganUtils.render(side_by_side_renderer_genericTemplatesPath, 'line', {
  3994. type: (line === null || line === void 0 ? void 0 : line.type) || CSSLineClass.CONTEXT + " d2h-emptyplaceholder",
  3995. lineClass: line !== undefined ? lineClass : lineClass + " d2h-code-side-emptyplaceholder",
  3996. contentClass: line !== undefined ? contentClass : contentClass + " d2h-code-side-emptyplaceholder",
  3997. prefix: (line === null || line === void 0 ? void 0 : line.prefix) === ' ' ? '&nbsp;' : line === null || line === void 0 ? void 0 : line.prefix,
  3998. content: line === null || line === void 0 ? void 0 : line.content,
  3999. lineNumber: line === null || line === void 0 ? void 0 : line.number,
  4000. });
  4001. };
  4002. return SideBySideRenderer;
  4003. }());
  4004. /* harmony default export */ var side_by_side_renderer = (side_by_side_renderer_SideBySideRenderer);
  4005. //# sourceMappingURL=side-by-side-renderer.js.map
  4006. // EXTERNAL MODULE: ./node_modules/hogan.js/lib/hogan.js
  4007. var hogan = __webpack_require__("Ruv9");
  4008.  
  4009. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/diff2html-templates.js
  4010.  
  4011. var defaultTemplates = {};
  4012. defaultTemplates["file-summary-line"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<li class=\"d2h-file-list-line\">"); t.b("\n" + i); t.b(" <span class=\"d2h-file-name-wrapper\">"); t.b("\n" + i); t.b(t.rp("<fileIcon0", c, p, " ")); t.b(" <a href=\"#"); t.b(t.v(t.f("fileHtmlId", c, p, 0))); t.b("\" class=\"d2h-file-name\">"); t.b(t.v(t.f("fileName", c, p, 0))); t.b("</a>"); t.b("\n" + i); t.b(" <span class=\"d2h-file-stats\">"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-added\">"); t.b(t.v(t.f("addedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" <span class=\"d2h-lines-deleted\">"); t.b(t.v(t.f("deletedLines", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b(" </span>"); t.b("\n" + i); t.b("</li>"); return t.fl(); }, partials: { "<fileIcon0": { name: "fileIcon", partials: {}, subs: {} } }, subs: {} });
  4013. defaultTemplates["file-summary-wrapper"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div class=\"d2h-file-list-wrapper\">"); t.b("\n" + i); t.b(" <div class=\"d2h-file-list-header\">"); t.b("\n" + i); t.b(" <span class=\"d2h-file-list-title\">Files changed ("); t.b(t.v(t.f("filesNumber", c, p, 0))); t.b(")</span>"); t.b("\n" + i); t.b(" <a class=\"d2h-file-switch d2h-hide\">hide</a>"); t.b("\n" + i); t.b(" <a class=\"d2h-file-switch d2h-show\">show</a>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" <ol class=\"d2h-file-list\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("files", c, p, 0))); t.b("\n" + i); t.b(" </ol>"); t.b("\n" + i); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} });
  4014. defaultTemplates["generic-block-header"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<tr>"); t.b("\n" + i); t.b(" <td class=\""); t.b(t.v(t.f("lineClass", c, p, 0))); t.b(" "); t.b(t.v(t.d("CSSLineClass.INFO", c, p, 0))); t.b("\"></td>"); t.b("\n" + i); t.b(" <td class=\""); t.b(t.v(t.d("CSSLineClass.INFO", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" <div class=\""); t.b(t.v(t.f("contentClass", c, p, 0))); t.b(" "); t.b(t.v(t.d("CSSLineClass.INFO", c, p, 0))); t.b("\">"); t.b(t.t(t.f("blockHeader", c, p, 0))); t.b("</div>"); t.b("\n" + i); t.b(" </td>"); t.b("\n" + i); t.b("</tr>"); return t.fl(); }, partials: {}, subs: {} });
  4015. defaultTemplates["generic-empty-diff"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<tr>"); t.b("\n" + i); t.b(" <td class=\""); t.b(t.v(t.d("CSSLineClass.INFO", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" <div class=\""); t.b(t.v(t.f("contentClass", c, p, 0))); t.b(" "); t.b(t.v(t.d("CSSLineClass.INFO", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" File without changes"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" </td>"); t.b("\n" + i); t.b("</tr>"); return t.fl(); }, partials: {}, subs: {} });
  4016. defaultTemplates["generic-file-path"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<span class=\"d2h-file-name-wrapper\">"); t.b("\n" + i); t.b(t.rp("<fileIcon0", c, p, " ")); t.b(" <span class=\"d2h-file-name\">"); t.b(t.v(t.f("fileDiffName", c, p, 0))); t.b("</span>"); t.b("\n" + i); t.b(t.rp("<fileTag1", c, p, " ")); t.b("</span>"); return t.fl(); }, partials: { "<fileIcon0": { name: "fileIcon", partials: {}, subs: {} }, "<fileTag1": { name: "fileTag", partials: {}, subs: {} } }, subs: {} });
  4017. defaultTemplates["generic-line"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<tr>"); t.b("\n" + i); t.b(" <td class=\""); t.b(t.v(t.f("lineClass", c, p, 0))); t.b(" "); t.b(t.v(t.f("type", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("lineNumber", c, p, 0))); t.b("\n" + i); t.b(" </td>"); t.b("\n" + i); t.b(" <td class=\""); t.b(t.v(t.f("type", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" <div class=\""); t.b(t.v(t.f("contentClass", c, p, 0))); t.b(" "); t.b(t.v(t.f("type", c, p, 0))); t.b("\">"); t.b("\n" + i); if (t.s(t.f("prefix", c, p, 1), c, p, 0, 171, 247, "{{ }}")) {
  4018. t.rs(c, p, function (c, p, t) { t.b(" <span class=\"d2h-code-line-prefix\">"); t.b(t.t(t.f("prefix", c, p, 0))); t.b("</span>"); t.b("\n" + i); });
  4019. c.pop();
  4020. } if (!t.s(t.f("prefix", c, p, 1), c, p, 1, 0, 0, "")) {
  4021. t.b(" <span class=\"d2h-code-line-prefix\">&nbsp;</span>");
  4022. t.b("\n" + i);
  4023. } ; if (t.s(t.f("content", c, p, 1), c, p, 0, 380, 454, "{{ }}")) {
  4024. t.rs(c, p, function (c, p, t) { t.b(" <span class=\"d2h-code-line-ctn\">"); t.b(t.t(t.f("content", c, p, 0))); t.b("</span>"); t.b("\n" + i); });
  4025. c.pop();
  4026. } if (!t.s(t.f("content", c, p, 1), c, p, 1, 0, 0, "")) {
  4027. t.b(" <span class=\"d2h-code-line-ctn\"><br></span>");
  4028. t.b("\n" + i);
  4029. } ; t.b(" </div>"); t.b("\n" + i); t.b(" </td>"); t.b("\n" + i); t.b("</tr>"); return t.fl(); }, partials: {}, subs: {} });
  4030. defaultTemplates["generic-wrapper"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div class=\"d2h-wrapper\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("content", c, p, 0))); t.b("\n" + i); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} });
  4031. defaultTemplates["icon-file-added"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-added\" height=\"16\" title=\"added\" version=\"1.1\" viewBox=\"0 0 14 16\""); t.b("\n" + i); t.b(" width=\"14\">"); t.b("\n" + i); t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM6 9H3V7h3V4h2v3h3v2H8v3H6V9z\"></path>"); t.b("\n" + i); t.b("</svg>"); return t.fl(); }, partials: {}, subs: {} });
  4032. defaultTemplates["icon-file-changed"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-changed\" height=\"16\" title=\"modified\" version=\"1.1\""); t.b("\n" + i); t.b(" viewBox=\"0 0 14 16\" width=\"14\">"); t.b("\n" + i); t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z\"></path>"); t.b("\n" + i); t.b("</svg>"); return t.fl(); }, partials: {}, subs: {} });
  4033. defaultTemplates["icon-file-deleted"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-deleted\" height=\"16\" title=\"removed\" version=\"1.1\""); t.b("\n" + i); t.b(" viewBox=\"0 0 14 16\" width=\"14\">"); t.b("\n" + i); t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM11 9H3V7h8v2z\"></path>"); t.b("\n" + i); t.b("</svg>"); return t.fl(); }, partials: {}, subs: {} });
  4034. defaultTemplates["icon-file-renamed"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-moved\" height=\"16\" title=\"renamed\" version=\"1.1\""); t.b("\n" + i); t.b(" viewBox=\"0 0 14 16\" width=\"14\">"); t.b("\n" + i); t.b(" <path d=\"M6 9H3V7h3V4l5 4-5 4V9z m8-7v12c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h12c0.55 0 1 0.45 1 1z m-1 0H1v12h12V2z\"></path>"); t.b("\n" + i); t.b("</svg>"); return t.fl(); }, partials: {}, subs: {} });
  4035. defaultTemplates["icon-file"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<svg aria-hidden=\"true\" class=\"d2h-icon\" height=\"16\" version=\"1.1\" viewBox=\"0 0 12 16\" width=\"12\">"); t.b("\n" + i); t.b(" <path d=\"M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z\"></path>"); t.b("\n" + i); t.b("</svg>"); return t.fl(); }, partials: {}, subs: {} });
  4036. defaultTemplates["line-by-line-file-diff"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div id=\""); t.b(t.v(t.f("fileHtmlId", c, p, 0))); t.b("\" class=\"d2h-file-wrapper\" data-lang=\""); t.b(t.v(t.d("file.language", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" <div class=\"d2h-file-header\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("filePath", c, p, 0))); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" <div class=\"d2h-file-diff\">"); t.b("\n" + i); t.b(" <div class=\"d2h-code-wrapper\">"); t.b("\n" + i); t.b(" <table class=\"d2h-diff-table\">"); t.b("\n" + i); t.b(" <tbody class=\"d2h-diff-tbody\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("diffs", c, p, 0))); t.b("\n" + i); t.b(" </tbody>"); t.b("\n" + i); t.b(" </table>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} });
  4037. defaultTemplates["line-by-line-numbers"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div class=\"line-num1\">"); t.b(t.v(t.f("oldNumber", c, p, 0))); t.b("</div>"); t.b("\n" + i); t.b("<div class=\"line-num2\">"); t.b(t.v(t.f("newNumber", c, p, 0))); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} });
  4038. defaultTemplates["side-by-side-file-diff"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<div id=\""); t.b(t.v(t.f("fileHtmlId", c, p, 0))); t.b("\" class=\"d2h-file-wrapper\" data-lang=\""); t.b(t.v(t.d("file.language", c, p, 0))); t.b("\">"); t.b("\n" + i); t.b(" <div class=\"d2h-file-header\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.f("filePath", c, p, 0))); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" <div class=\"d2h-files-diff\">"); t.b("\n" + i); t.b(" <div class=\"d2h-file-side-diff\">"); t.b("\n" + i); t.b(" <div class=\"d2h-code-wrapper\">"); t.b("\n" + i); t.b(" <table class=\"d2h-diff-table\">"); t.b("\n" + i); t.b(" <tbody class=\"d2h-diff-tbody\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.d("diffs.left", c, p, 0))); t.b("\n" + i); t.b(" </tbody>"); t.b("\n" + i); t.b(" </table>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" <div class=\"d2h-file-side-diff\">"); t.b("\n" + i); t.b(" <div class=\"d2h-code-wrapper\">"); t.b("\n" + i); t.b(" <table class=\"d2h-diff-table\">"); t.b("\n" + i); t.b(" <tbody class=\"d2h-diff-tbody\">"); t.b("\n" + i); t.b(" "); t.b(t.t(t.d("diffs.right", c, p, 0))); t.b("\n" + i); t.b(" </tbody>"); t.b("\n" + i); t.b(" </table>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b(" </div>"); t.b("\n" + i); t.b("</div>"); return t.fl(); }, partials: {}, subs: {} });
  4039. defaultTemplates["tag-file-added"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<span class=\"d2h-tag d2h-added d2h-added-tag\">ADDED</span>"); return t.fl(); }, partials: {}, subs: {} });
  4040. defaultTemplates["tag-file-changed"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<span class=\"d2h-tag d2h-changed d2h-changed-tag\">CHANGED</span>"); return t.fl(); }, partials: {}, subs: {} });
  4041. defaultTemplates["tag-file-deleted"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<span class=\"d2h-tag d2h-deleted d2h-deleted-tag\">DELETED</span>"); return t.fl(); }, partials: {}, subs: {} });
  4042. defaultTemplates["tag-file-renamed"] = new hogan["Template"]({ code: function (c, p, i) { var t = this; t.b(i = i || ""); t.b("<span class=\"d2h-tag d2h-moved d2h-moved-tag\">RENAMED</span>"); return t.fl(); }, partials: {}, subs: {} });
  4043. //# sourceMappingURL=diff2html-templates.js.map
  4044. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/hoganjs-utils.js
  4045. var hoganjs_utils_assign = (undefined && undefined.__assign) || function () {
  4046. hoganjs_utils_assign = Object.assign || function(t) {
  4047. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4048. s = arguments[i];
  4049. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  4050. t[p] = s[p];
  4051. }
  4052. return t;
  4053. };
  4054. return hoganjs_utils_assign.apply(this, arguments);
  4055. };
  4056.  
  4057.  
  4058. var hoganjs_utils_HoganJsUtils = (function () {
  4059. function HoganJsUtils(_a) {
  4060. var _b = _a.compiledTemplates, compiledTemplates = _b === void 0 ? {} : _b, _c = _a.rawTemplates, rawTemplates = _c === void 0 ? {} : _c;
  4061. var compiledRawTemplates = Object.entries(rawTemplates).reduce(function (previousTemplates, _a) {
  4062. var _b;
  4063. var name = _a[0], templateString = _a[1];
  4064. var compiledTemplate = hogan["compile"](templateString, { asString: false });
  4065. return hoganjs_utils_assign(hoganjs_utils_assign({}, previousTemplates), (_b = {}, _b[name] = compiledTemplate, _b));
  4066. }, {});
  4067. this.preCompiledTemplates = hoganjs_utils_assign(hoganjs_utils_assign(hoganjs_utils_assign({}, defaultTemplates), compiledTemplates), compiledRawTemplates);
  4068. }
  4069. HoganJsUtils.compile = function (templateString) {
  4070. return hogan["compile"](templateString, { asString: false });
  4071. };
  4072. HoganJsUtils.prototype.render = function (namespace, view, params, partials, indent) {
  4073. var templateKey = this.templateKey(namespace, view);
  4074. try {
  4075. var template = this.preCompiledTemplates[templateKey];
  4076. return template.render(params, partials, indent);
  4077. }
  4078. catch (e) {
  4079. throw new Error("Could not find template to render '" + templateKey + "'");
  4080. }
  4081. };
  4082. HoganJsUtils.prototype.template = function (namespace, view) {
  4083. return this.preCompiledTemplates[this.templateKey(namespace, view)];
  4084. };
  4085. HoganJsUtils.prototype.templateKey = function (namespace, view) {
  4086. return namespace + "-" + view;
  4087. };
  4088. return HoganJsUtils;
  4089. }());
  4090. /* harmony default export */ var hoganjs_utils = (hoganjs_utils_HoganJsUtils);
  4091. //# sourceMappingURL=hoganjs-utils.js.map
  4092. // CONCATENATED MODULE: ./node_modules/diff2html/lib-esm/diff2html.js
  4093. var diff2html_assign = (undefined && undefined.__assign) || function () {
  4094. diff2html_assign = Object.assign || function(t) {
  4095. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4096. s = arguments[i];
  4097. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  4098. t[p] = s[p];
  4099. }
  4100. return t;
  4101. };
  4102. return diff2html_assign.apply(this, arguments);
  4103. };
  4104.  
  4105.  
  4106.  
  4107.  
  4108.  
  4109.  
  4110. var defaultDiff2HtmlConfig = diff2html_assign(diff2html_assign(diff2html_assign({}, defaultLineByLineRendererConfig), defaultSideBySideRendererConfig), { outputFormat: OutputFormatType.LINE_BY_LINE, drawFileList: true });
  4111. function diff2html_parse(diffInput, configuration) {
  4112. if (configuration === void 0) { configuration = {}; }
  4113. return parse(diffInput, diff2html_assign(diff2html_assign({}, defaultDiff2HtmlConfig), configuration));
  4114. }
  4115. function html(diffInput, configuration) {
  4116. if (configuration === void 0) { configuration = {}; }
  4117. var config = diff2html_assign(diff2html_assign({}, defaultDiff2HtmlConfig), configuration);
  4118. var diffJson = typeof diffInput === 'string' ? parse(diffInput, config) : diffInput;
  4119. var hoganUtils = new hoganjs_utils(config);
  4120. var fileList = config.drawFileList ? render(diffJson, hoganUtils) : '';
  4121. var diffOutput = config.outputFormat === 'side-by-side'
  4122. ? new side_by_side_renderer(hoganUtils, config).render(diffJson)
  4123. : new line_by_line_renderer(hoganUtils, config).render(diffJson);
  4124. return fileList + diffOutput;
  4125. }
  4126. //# sourceMappingURL=diff2html.js.map
  4127. // EXTERNAL MODULE: external "$"
  4128. var external_$_ = __webpack_require__("xeH2");
  4129.  
  4130. // CONCATENATED MODULE: ./src/js/utils.js
  4131. function request (url) {
  4132. return new Promise((resolve, reject) => {
  4133. window.GM_xmlhttpRequest({
  4134. url,
  4135. onload: function ({ response, responseText, }) {
  4136. resolve({ response, responseText })
  4137. }
  4138. })
  4139. })
  4140. }
  4141.  
  4142.  
  4143.  
  4144. // CONCATENATED MODULE: ./src/js/index.js
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150. function main () {
  4151. console.log('start bgm wiki rev diff UserScript')
  4152. initUI()
  4153. }
  4154.  
  4155. function initUI () {
  4156. external_$_('#pagehistory li').each(function () {
  4157. const el = external_$_(this)
  4158. const rev = parseRevEl(el)
  4159. el.prepend(`<input type="checkbox" class="rev-trim21-cn" name="rev" label="select to compare" value="${rev.id}">`)
  4160. })
  4161. external_$_('#columnInSubjectA span.text').append('<a href="#;" id="compare-trim21-cn" tar class="l"> > 比较选中的版本</a>')
  4162. external_$_('#compare-trim21-cn').click(function () {
  4163. const selectedRevs = getSelectedVersion()
  4164. compare(selectedRevs)
  4165. })
  4166. }
  4167.  
  4168. function getSelectedVersion () {
  4169. const selectedVersion = []
  4170. const selectedRev = external_$_('.rev-trim21-cn:checked')
  4171. if (selectedRev.length < 2) {
  4172. window.alert('请选中两个版本进行比较')
  4173. }
  4174. if (selectedRev.length > 2) {
  4175. window.alert('只能比较两个版本')
  4176. }
  4177. selectedRev.each(function () {
  4178. const el = external_$_(this)
  4179. selectedVersion.push(el.val())
  4180. })
  4181. selectedVersion.reverse()
  4182. return selectedVersion
  4183. }
  4184.  
  4185. function compare (revs) {
  4186. console.log('compare')
  4187. external_$_('head').append('<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css" />')
  4188. const rev1 = getRevInfo(revs[0])
  4189. const rev2 = getRevInfo(revs[1])
  4190. const p1 = request(rev1.url)
  4191. const p2 = request(rev2.url)
  4192. Promise.all([p1, p2]).then(values => {
  4193. const contents = []
  4194. for (const page of values) {
  4195. const jq = external_$_(page.responseText)
  4196. contents.push(jq.find('#subject_infobox').val())
  4197. }
  4198. const d = difflib["unifiedDiff"](contents[0].split('\n'), contents[1].split('\n'), {
  4199. fromfile: rev1.comment,
  4200. tofile: rev2.comment,
  4201. fromfiledate: rev1.date,
  4202. tofiledate: rev2.date,
  4203. lineterm: ''
  4204. })
  4205. const rendered = js_render(d.join('\n'), {})
  4206. external_$_('#columnInSubjectA').prepend(rendered)
  4207. })
  4208. }
  4209.  
  4210. function getRevs () {
  4211. const revs = []
  4212. external_$_('#pagehistory li').each(function () {
  4213. const el = external_$_(this)
  4214. revs.push(parseRevEl(el))
  4215. })
  4216. return revs
  4217. }
  4218.  
  4219. function parseRevEl (el) {
  4220. const date = el.find('a').first().html()
  4221. const revEL = el.find('a.l:contains("恢复")')
  4222. const revCommentEl = el.find('span.comment')
  4223. let comment = ''
  4224. if (revCommentEl.length) {
  4225. comment = revCommentEl.html()
  4226. comment = comment.substring(1, comment.length - 1)
  4227. }
  4228. const revHref = revEL.attr('href')
  4229. const revID = revHref.split('/').pop()
  4230. return {
  4231. id: revID,
  4232. comment,
  4233. date,
  4234. url: revHref,
  4235. }
  4236. }
  4237.  
  4238. function getRevInfo (revID) {
  4239. for (const rev of getRevs()) {
  4240. if (rev.id === revID) {
  4241. console.log(revID, rev)
  4242. return rev
  4243. }
  4244. }
  4245. }
  4246.  
  4247. function js_render (diff) {
  4248. return html(diff)
  4249. }
  4250.  
  4251. main()
  4252.  
  4253.  
  4254. /***/ }),
  4255.  
  4256. /***/ "qVjC":
  4257. /***/ (function(module, exports, __webpack_require__) {
  4258.  
  4259. // Generated by CoffeeScript 1.3.1
  4260.  
  4261. /*
  4262. Module difflib -- helpers for computing deltas between objects.
  4263.  
  4264. Function getCloseMatches(word, possibilities, n=3, cutoff=0.6):
  4265. Use SequenceMatcher to return list of the best "good enough" matches.
  4266.  
  4267. Function contextDiff(a, b):
  4268. For two lists of strings, return a delta in context diff format.
  4269.  
  4270. Function ndiff(a, b):
  4271. Return a delta: the difference between `a` and `b` (lists of strings).
  4272.  
  4273. Function restore(delta, which):
  4274. Return one of the two sequences that generated an ndiff delta.
  4275.  
  4276. Function unifiedDiff(a, b):
  4277. For two lists of strings, return a delta in unified diff format.
  4278.  
  4279. Class SequenceMatcher:
  4280. A flexible class for comparing pairs of sequences of any type.
  4281.  
  4282. Class Differ:
  4283. For producing human-readable deltas from sequences of lines of text.
  4284. */
  4285.  
  4286.  
  4287. (function() {
  4288. var Differ, Heap, IS_CHARACTER_JUNK, IS_LINE_JUNK, SequenceMatcher, assert, contextDiff, floor, getCloseMatches, max, min, ndiff, restore, unifiedDiff, _any, _arrayCmp, _calculateRatio, _countLeading, _formatRangeContext, _formatRangeUnified, _has,
  4289. __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
  4290.  
  4291. floor = Math.floor, max = Math.max, min = Math.min;
  4292.  
  4293. Heap = __webpack_require__("F1pL");
  4294.  
  4295. assert = __webpack_require__("9lTW");
  4296.  
  4297. _calculateRatio = function(matches, length) {
  4298. if (length) {
  4299. return 2.0 * matches / length;
  4300. } else {
  4301. return 1.0;
  4302. }
  4303. };
  4304.  
  4305. _arrayCmp = function(a, b) {
  4306. var i, la, lb, _i, _ref, _ref1;
  4307. _ref = [a.length, b.length], la = _ref[0], lb = _ref[1];
  4308. for (i = _i = 0, _ref1 = min(la, lb); 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
  4309. if (a[i] < b[i]) {
  4310. return -1;
  4311. }
  4312. if (a[i] > b[i]) {
  4313. return 1;
  4314. }
  4315. }
  4316. return la - lb;
  4317. };
  4318.  
  4319. _has = function(obj, key) {
  4320. return Object.prototype.hasOwnProperty.call(obj, key);
  4321. };
  4322.  
  4323. _any = function(items) {
  4324. var item, _i, _len;
  4325. for (_i = 0, _len = items.length; _i < _len; _i++) {
  4326. item = items[_i];
  4327. if (item) {
  4328. return true;
  4329. }
  4330. }
  4331. return false;
  4332. };
  4333.  
  4334. SequenceMatcher = (function() {
  4335.  
  4336. SequenceMatcher.name = 'SequenceMatcher';
  4337.  
  4338. /*
  4339. SequenceMatcher is a flexible class for comparing pairs of sequences of
  4340. any type, so long as the sequence elements are hashable. The basic
  4341. algorithm predates, and is a little fancier than, an algorithm
  4342. published in the late 1980's by Ratcliff and Obershelp under the
  4343. hyperbolic name "gestalt pattern matching". The basic idea is to find
  4344. the longest contiguous matching subsequence that contains no "junk"
  4345. elements (R-O doesn't address junk). The same idea is then applied
  4346. recursively to the pieces of the sequences to the left and to the right
  4347. of the matching subsequence. This does not yield minimal edit
  4348. sequences, but does tend to yield matches that "look right" to people.
  4349. SequenceMatcher tries to compute a "human-friendly diff" between two
  4350. sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the
  4351. longest *contiguous* & junk-free matching subsequence. That's what
  4352. catches peoples' eyes. The Windows(tm) windiff has another interesting
  4353. notion, pairing up elements that appear uniquely in each sequence.
  4354. That, and the method here, appear to yield more intuitive difference
  4355. reports than does diff. This method appears to be the least vulnerable
  4356. to synching up on blocks of "junk lines", though (like blank lines in
  4357. ordinary text files, or maybe "<P>" lines in HTML files). That may be
  4358. because this is the only method of the 3 that has a *concept* of
  4359. "junk" <wink>.
  4360. Example, comparing two strings, and considering blanks to be "junk":
  4361. >>> isjunk = (c) -> c is ' '
  4362. >>> s = new SequenceMatcher(isjunk,
  4363. 'private Thread currentThread;',
  4364. 'private volatile Thread currentThread;')
  4365. .ratio() returns a float in [0, 1], measuring the "similarity" of the
  4366. sequences. As a rule of thumb, a .ratio() value over 0.6 means the
  4367. sequences are close matches:
  4368. >>> s.ratio().toPrecision(3)
  4369. '0.866'
  4370. If you're only interested in where the sequences match,
  4371. .getMatchingBlocks() is handy:
  4372. >>> for [a, b, size] in s.getMatchingBlocks()
  4373. ... console.log("a[#{a}] and b[#{b}] match for #{size} elements");
  4374. a[0] and b[0] match for 8 elements
  4375. a[8] and b[17] match for 21 elements
  4376. a[29] and b[38] match for 0 elements
  4377. Note that the last tuple returned by .get_matching_blocks() is always a
  4378. dummy, (len(a), len(b), 0), and this is the only case in which the last
  4379. tuple element (number of elements matched) is 0.
  4380. If you want to know how to change the first sequence into the second,
  4381. use .get_opcodes():
  4382. >>> for [op, a1, a2, b1, b2] in s.getOpcodes()
  4383. ... console.log "#{op} a[#{a1}:#{a2}] b[#{b1}:#{b2}]"
  4384. equal a[0:8] b[0:8]
  4385. insert a[8:8] b[8:17]
  4386. equal a[8:29] b[17:38]
  4387. See the Differ class for a fancy human-friendly file differencer, which
  4388. uses SequenceMatcher both to compare sequences of lines, and to compare
  4389. sequences of characters within similar (near-matching) lines.
  4390. See also function getCloseMatches() in this module, which shows how
  4391. simple code building on SequenceMatcher can be used to do useful work.
  4392. Timing: Basic R-O is cubic time worst case and quadratic time expected
  4393. case. SequenceMatcher is quadratic time for the worst case and has
  4394. expected-case behavior dependent in a complicated way on how many
  4395. elements the sequences have in common; best case time is linear.
  4396. Methods:
  4397. constructor(isjunk=null, a='', b='')
  4398. Construct a SequenceMatcher.
  4399. setSeqs(a, b)
  4400. Set the two sequences to be compared.
  4401. setSeq1(a)
  4402. Set the first sequence to be compared.
  4403. setSeq2(b)
  4404. Set the second sequence to be compared.
  4405. findLongestMatch(alo, ahi, blo, bhi)
  4406. Find longest matching block in a[alo:ahi] and b[blo:bhi].
  4407. getMatchingBlocks()
  4408. Return list of triples describing matching subsequences.
  4409. getOpcodes()
  4410. Return list of 5-tuples describing how to turn a into b.
  4411. ratio()
  4412. Return a measure of the sequences' similarity (float in [0,1]).
  4413. quickRatio()
  4414. Return an upper bound on .ratio() relatively quickly.
  4415. realQuickRatio()
  4416. Return an upper bound on ratio() very quickly.
  4417. */
  4418.  
  4419.  
  4420. function SequenceMatcher(isjunk, a, b, autojunk) {
  4421. this.isjunk = isjunk;
  4422. if (a == null) {
  4423. a = '';
  4424. }
  4425. if (b == null) {
  4426. b = '';
  4427. }
  4428. this.autojunk = autojunk != null ? autojunk : true;
  4429. /*
  4430. Construct a SequenceMatcher.
  4431. Optional arg isjunk is null (the default), or a one-argument
  4432. function that takes a sequence element and returns true iff the
  4433. element is junk. Null is equivalent to passing "(x) -> 0", i.e.
  4434. no elements are considered to be junk. For example, pass
  4435. (x) -> x in ' \t'
  4436. if you're comparing lines as sequences of characters, and don't
  4437. want to synch up on blanks or hard tabs.
  4438. Optional arg a is the first of two sequences to be compared. By
  4439. default, an empty string. The elements of a must be hashable. See
  4440. also .setSeqs() and .setSeq1().
  4441. Optional arg b is the second of two sequences to be compared. By
  4442. default, an empty string. The elements of b must be hashable. See
  4443. also .setSeqs() and .setSeq2().
  4444. Optional arg autojunk should be set to false to disable the
  4445. "automatic junk heuristic" that treats popular elements as junk
  4446. (see module documentation for more information).
  4447. */
  4448.  
  4449. this.a = this.b = null;
  4450. this.setSeqs(a, b);
  4451. }
  4452.  
  4453. SequenceMatcher.prototype.setSeqs = function(a, b) {
  4454. /*
  4455. Set the two sequences to be compared.
  4456. >>> s = new SequenceMatcher()
  4457. >>> s.setSeqs('abcd', 'bcde')
  4458. >>> s.ratio()
  4459. 0.75
  4460. */
  4461. this.setSeq1(a);
  4462. return this.setSeq2(b);
  4463. };
  4464.  
  4465. SequenceMatcher.prototype.setSeq1 = function(a) {
  4466. /*
  4467. Set the first sequence to be compared.
  4468. The second sequence to be compared is not changed.
  4469. >>> s = new SequenceMatcher(null, 'abcd', 'bcde')
  4470. >>> s.ratio()
  4471. 0.75
  4472. >>> s.setSeq1('bcde')
  4473. >>> s.ratio()
  4474. 1.0
  4475. SequenceMatcher computes and caches detailed information about the
  4476. second sequence, so if you want to compare one sequence S against
  4477. many sequences, use .setSeq2(S) once and call .setSeq1(x)
  4478. repeatedly for each of the other sequences.
  4479. See also setSeqs() and setSeq2().
  4480. */
  4481. if (a === this.a) {
  4482. return;
  4483. }
  4484. this.a = a;
  4485. return this.matchingBlocks = this.opcodes = null;
  4486. };
  4487.  
  4488. SequenceMatcher.prototype.setSeq2 = function(b) {
  4489. /*
  4490. Set the second sequence to be compared.
  4491. The first sequence to be compared is not changed.
  4492. >>> s = new SequenceMatcher(null, 'abcd', 'bcde')
  4493. >>> s.ratio()
  4494. 0.75
  4495. >>> s.setSeq2('abcd')
  4496. >>> s.ratio()
  4497. 1.0
  4498. SequenceMatcher computes and caches detailed information about the
  4499. second sequence, so if you want to compare one sequence S against
  4500. many sequences, use .setSeq2(S) once and call .setSeq1(x)
  4501. repeatedly for each of the other sequences.
  4502. See also setSeqs() and setSeq1().
  4503. */
  4504. if (b === this.b) {
  4505. return;
  4506. }
  4507. this.b = b;
  4508. this.matchingBlocks = this.opcodes = null;
  4509. this.fullbcount = null;
  4510. return this._chainB();
  4511. };
  4512.  
  4513. SequenceMatcher.prototype._chainB = function() {
  4514. var b, b2j, elt, i, idxs, indices, isjunk, junk, n, ntest, popular, _i, _j, _len, _len1, _ref;
  4515. b = this.b;
  4516. this.b2j = b2j = {};
  4517. for (i = _i = 0, _len = b.length; _i < _len; i = ++_i) {
  4518. elt = b[i];
  4519. indices = _has(b2j, elt) ? b2j[elt] : b2j[elt] = [];
  4520. indices.push(i);
  4521. }
  4522. junk = {};
  4523. isjunk = this.isjunk;
  4524. if (isjunk) {
  4525. _ref = Object.keys(b2j);
  4526. for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
  4527. elt = _ref[_j];
  4528. if (isjunk(elt)) {
  4529. junk[elt] = true;
  4530. delete b2j[elt];
  4531. }
  4532. }
  4533. }
  4534. popular = {};
  4535. n = b.length;
  4536. if (this.autojunk && n >= 200) {
  4537. ntest = floor(n / 100) + 1;
  4538. for (elt in b2j) {
  4539. idxs = b2j[elt];
  4540. if (idxs.length > ntest) {
  4541. popular[elt] = true;
  4542. delete b2j[elt];
  4543. }
  4544. }
  4545. }
  4546. this.isbjunk = function(b) {
  4547. return _has(junk, b);
  4548. };
  4549. return this.isbpopular = function(b) {
  4550. return _has(popular, b);
  4551. };
  4552. };
  4553.  
  4554. SequenceMatcher.prototype.findLongestMatch = function(alo, ahi, blo, bhi) {
  4555. /*
  4556. Find longest matching block in a[alo...ahi] and b[blo...bhi].
  4557. If isjunk is not defined:
  4558. Return [i,j,k] such that a[i...i+k] is equal to b[j...j+k], where
  4559. alo <= i <= i+k <= ahi
  4560. blo <= j <= j+k <= bhi
  4561. and for all [i',j',k'] meeting those conditions,
  4562. k >= k'
  4563. i <= i'
  4564. and if i == i', j <= j'
  4565. In other words, of all maximal matching blocks, return one that
  4566. starts earliest in a, and of all those maximal matching blocks that
  4567. start earliest in a, return the one that starts earliest in b.
  4568. >>> isjunk = (x) -> x is ' '
  4569. >>> s = new SequenceMatcher(isjunk, ' abcd', 'abcd abcd')
  4570. >>> s.findLongestMatch(0, 5, 0, 9)
  4571. [1, 0, 4]
  4572. >>> s = new SequenceMatcher(null, 'ab', 'c')
  4573. >>> s.findLongestMatch(0, 2, 0, 1)
  4574. [0, 0, 0]
  4575. */
  4576.  
  4577. var a, b, b2j, besti, bestj, bestsize, i, isbjunk, j, j2len, k, newj2len, _i, _j, _len, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
  4578. _ref = [this.a, this.b, this.b2j, this.isbjunk], a = _ref[0], b = _ref[1], b2j = _ref[2], isbjunk = _ref[3];
  4579. _ref1 = [alo, blo, 0], besti = _ref1[0], bestj = _ref1[1], bestsize = _ref1[2];
  4580. j2len = {};
  4581. for (i = _i = alo; alo <= ahi ? _i < ahi : _i > ahi; i = alo <= ahi ? ++_i : --_i) {
  4582. newj2len = {};
  4583. _ref2 = (_has(b2j, a[i]) ? b2j[a[i]] : []);
  4584. for (_j = 0, _len = _ref2.length; _j < _len; _j++) {
  4585. j = _ref2[_j];
  4586. if (j < blo) {
  4587. continue;
  4588. }
  4589. if (j >= bhi) {
  4590. break;
  4591. }
  4592. k = newj2len[j] = (j2len[j - 1] || 0) + 1;
  4593. if (k > bestsize) {
  4594. _ref3 = [i - k + 1, j - k + 1, k], besti = _ref3[0], bestj = _ref3[1], bestsize = _ref3[2];
  4595. }
  4596. }
  4597. j2len = newj2len;
  4598. }
  4599. while (besti > alo && bestj > blo && !isbjunk(b[bestj - 1]) && a[besti - 1] === b[bestj - 1]) {
  4600. _ref4 = [besti - 1, bestj - 1, bestsize + 1], besti = _ref4[0], bestj = _ref4[1], bestsize = _ref4[2];
  4601. }
  4602. while (besti + bestsize < ahi && bestj + bestsize < bhi && !isbjunk(b[bestj + bestsize]) && a[besti + bestsize] === b[bestj + bestsize]) {
  4603. bestsize++;
  4604. }
  4605. while (besti > alo && bestj > blo && isbjunk(b[bestj - 1]) && a[besti - 1] === b[bestj - 1]) {
  4606. _ref5 = [besti - 1, bestj - 1, bestsize + 1], besti = _ref5[0], bestj = _ref5[1], bestsize = _ref5[2];
  4607. }
  4608. while (besti + bestsize < ahi && bestj + bestsize < bhi && isbjunk(b[bestj + bestsize]) && a[besti + bestsize] === b[bestj + bestsize]) {
  4609. bestsize++;
  4610. }
  4611. return [besti, bestj, bestsize];
  4612. };
  4613.  
  4614. SequenceMatcher.prototype.getMatchingBlocks = function() {
  4615. /*
  4616. Return list of triples describing matching subsequences.
  4617. Each triple is of the form [i, j, n], and means that
  4618. a[i...i+n] == b[j...j+n]. The triples are monotonically increasing in
  4619. i and in j. it's also guaranteed that if
  4620. [i, j, n] and [i', j', n'] are adjacent triples in the list, and
  4621. the second is not the last triple in the list, then i+n != i' or
  4622. j+n != j'. IOW, adjacent triples never describe adjacent equal
  4623. blocks.
  4624. The last triple is a dummy, [a.length, b.length, 0], and is the only
  4625. triple with n==0.
  4626. >>> s = new SequenceMatcher(null, 'abxcd', 'abcd')
  4627. >>> s.getMatchingBlocks()
  4628. [[0, 0, 2], [3, 2, 2], [5, 4, 0]]
  4629. */
  4630.  
  4631. var ahi, alo, bhi, blo, i, i1, i2, j, j1, j2, k, k1, k2, la, lb, matchingBlocks, nonAdjacent, queue, x, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4;
  4632. if (this.matchingBlocks) {
  4633. return this.matchingBlocks;
  4634. }
  4635. _ref = [this.a.length, this.b.length], la = _ref[0], lb = _ref[1];
  4636. queue = [[0, la, 0, lb]];
  4637. matchingBlocks = [];
  4638. while (queue.length) {
  4639. _ref1 = queue.pop(), alo = _ref1[0], ahi = _ref1[1], blo = _ref1[2], bhi = _ref1[3];
  4640. _ref2 = x = this.findLongestMatch(alo, ahi, blo, bhi), i = _ref2[0], j = _ref2[1], k = _ref2[2];
  4641. if (k) {
  4642. matchingBlocks.push(x);
  4643. if (alo < i && blo < j) {
  4644. queue.push([alo, i, blo, j]);
  4645. }
  4646. if (i + k < ahi && j + k < bhi) {
  4647. queue.push([i + k, ahi, j + k, bhi]);
  4648. }
  4649. }
  4650. }
  4651. matchingBlocks.sort(_arrayCmp);
  4652. i1 = j1 = k1 = 0;
  4653. nonAdjacent = [];
  4654. for (_i = 0, _len = matchingBlocks.length; _i < _len; _i++) {
  4655. _ref3 = matchingBlocks[_i], i2 = _ref3[0], j2 = _ref3[1], k2 = _ref3[2];
  4656. if (i1 + k1 === i2 && j1 + k1 === j2) {
  4657. k1 += k2;
  4658. } else {
  4659. if (k1) {
  4660. nonAdjacent.push([i1, j1, k1]);
  4661. }
  4662. _ref4 = [i2, j2, k2], i1 = _ref4[0], j1 = _ref4[1], k1 = _ref4[2];
  4663. }
  4664. }
  4665. if (k1) {
  4666. nonAdjacent.push([i1, j1, k1]);
  4667. }
  4668. nonAdjacent.push([la, lb, 0]);
  4669. return this.matchingBlocks = nonAdjacent;
  4670. };
  4671.  
  4672. SequenceMatcher.prototype.getOpcodes = function() {
  4673. /*
  4674. Return list of 5-tuples describing how to turn a into b.
  4675. Each tuple is of the form [tag, i1, i2, j1, j2]. The first tuple
  4676. has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
  4677. tuple preceding it, and likewise for j1 == the previous j2.
  4678. The tags are strings, with these meanings:
  4679. 'replace': a[i1...i2] should be replaced by b[j1...j2]
  4680. 'delete': a[i1...i2] should be deleted.
  4681. Note that j1==j2 in this case.
  4682. 'insert': b[j1...j2] should be inserted at a[i1...i1].
  4683. Note that i1==i2 in this case.
  4684. 'equal': a[i1...i2] == b[j1...j2]
  4685. >>> s = new SequenceMatcher(null, 'qabxcd', 'abycdf')
  4686. >>> s.getOpcodes()
  4687. [ [ 'delete' , 0 , 1 , 0 , 0 ] ,
  4688. [ 'equal' , 1 , 3 , 0 , 2 ] ,
  4689. [ 'replace' , 3 , 4 , 2 , 3 ] ,
  4690. [ 'equal' , 4 , 6 , 3 , 5 ] ,
  4691. [ 'insert' , 6 , 6 , 5 , 6 ] ]
  4692. */
  4693.  
  4694. var ai, answer, bj, i, j, size, tag, _i, _len, _ref, _ref1, _ref2;
  4695. if (this.opcodes) {
  4696. return this.opcodes;
  4697. }
  4698. i = j = 0;
  4699. this.opcodes = answer = [];
  4700. _ref = this.getMatchingBlocks();
  4701. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  4702. _ref1 = _ref[_i], ai = _ref1[0], bj = _ref1[1], size = _ref1[2];
  4703. tag = '';
  4704. if (i < ai && j < bj) {
  4705. tag = 'replace';
  4706. } else if (i < ai) {
  4707. tag = 'delete';
  4708. } else if (j < bj) {
  4709. tag = 'insert';
  4710. }
  4711. if (tag) {
  4712. answer.push([tag, i, ai, j, bj]);
  4713. }
  4714. _ref2 = [ai + size, bj + size], i = _ref2[0], j = _ref2[1];
  4715. if (size) {
  4716. answer.push(['equal', ai, i, bj, j]);
  4717. }
  4718. }
  4719. return answer;
  4720. };
  4721.  
  4722. SequenceMatcher.prototype.getGroupedOpcodes = function(n) {
  4723. var codes, group, groups, i1, i2, j1, j2, nn, tag, _i, _len, _ref, _ref1, _ref2, _ref3;
  4724. if (n == null) {
  4725. n = 3;
  4726. }
  4727. /*
  4728. Isolate change clusters by eliminating ranges with no changes.
  4729. Return a list groups with upto n lines of context.
  4730. Each group is in the same format as returned by get_opcodes().
  4731. >>> a = [1...40].map(String)
  4732. >>> b = a.slice()
  4733. >>> b[8...8] = 'i'
  4734. >>> b[20] += 'x'
  4735. >>> b[23...28] = []
  4736. >>> b[30] += 'y'
  4737. >>> s = new SequenceMatcher(null, a, b)
  4738. >>> s.getGroupedOpcodes()
  4739. [ [ [ 'equal' , 5 , 8 , 5 , 8 ],
  4740. [ 'insert' , 8 , 8 , 8 , 9 ],
  4741. [ 'equal' , 8 , 11 , 9 , 12 ] ],
  4742. [ [ 'equal' , 16 , 19 , 17 , 20 ],
  4743. [ 'replace' , 19 , 20 , 20 , 21 ],
  4744. [ 'equal' , 20 , 22 , 21 , 23 ],
  4745. [ 'delete' , 22 , 27 , 23 , 23 ],
  4746. [ 'equal' , 27 , 30 , 23 , 26 ] ],
  4747. [ [ 'equal' , 31 , 34 , 27 , 30 ],
  4748. [ 'replace' , 34 , 35 , 30 , 31 ],
  4749. [ 'equal' , 35 , 38 , 31 , 34 ] ] ]
  4750. */
  4751.  
  4752. codes = this.getOpcodes();
  4753. if (!codes.length) {
  4754. codes = [['equal', 0, 1, 0, 1]];
  4755. }
  4756. if (codes[0][0] === 'equal') {
  4757. _ref = codes[0], tag = _ref[0], i1 = _ref[1], i2 = _ref[2], j1 = _ref[3], j2 = _ref[4];
  4758. codes[0] = [tag, max(i1, i2 - n), i2, max(j1, j2 - n), j2];
  4759. }
  4760. if (codes[codes.length - 1][0] === 'equal') {
  4761. _ref1 = codes[codes.length - 1], tag = _ref1[0], i1 = _ref1[1], i2 = _ref1[2], j1 = _ref1[3], j2 = _ref1[4];
  4762. codes[codes.length - 1] = [tag, i1, min(i2, i1 + n), j1, min(j2, j1 + n)];
  4763. }
  4764. nn = n + n;
  4765. groups = [];
  4766. group = [];
  4767. for (_i = 0, _len = codes.length; _i < _len; _i++) {
  4768. _ref2 = codes[_i], tag = _ref2[0], i1 = _ref2[1], i2 = _ref2[2], j1 = _ref2[3], j2 = _ref2[4];
  4769. if (tag === 'equal' && i2 - i1 > nn) {
  4770. group.push([tag, i1, min(i2, i1 + n), j1, min(j2, j1 + n)]);
  4771. groups.push(group);
  4772. group = [];
  4773. _ref3 = [max(i1, i2 - n), max(j1, j2 - n)], i1 = _ref3[0], j1 = _ref3[1];
  4774. }
  4775. group.push([tag, i1, i2, j1, j2]);
  4776. }
  4777. if (group.length && !(group.length === 1 && group[0][0] === 'equal')) {
  4778. groups.push(group);
  4779. }
  4780. return groups;
  4781. };
  4782.  
  4783. SequenceMatcher.prototype.ratio = function() {
  4784. /*
  4785. Return a measure of the sequences' similarity (float in [0,1]).
  4786. Where T is the total number of elements in both sequences, and
  4787. M is the number of matches, this is 2.0*M / T.
  4788. Note that this is 1 if the sequences are identical, and 0 if
  4789. they have nothing in common.
  4790. .ratio() is expensive to compute if you haven't already computed
  4791. .getMatchingBlocks() or .getOpcodes(), in which case you may
  4792. want to try .quickRatio() or .realQuickRatio() first to get an
  4793. upper bound.
  4794. >>> s = new SequenceMatcher(null, 'abcd', 'bcde')
  4795. >>> s.ratio()
  4796. 0.75
  4797. >>> s.quickRatio()
  4798. 0.75
  4799. >>> s.realQuickRatio()
  4800. 1.0
  4801. */
  4802.  
  4803. var match, matches, _i, _len, _ref;
  4804. matches = 0;
  4805. _ref = this.getMatchingBlocks();
  4806. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  4807. match = _ref[_i];
  4808. matches += match[2];
  4809. }
  4810. return _calculateRatio(matches, this.a.length + this.b.length);
  4811. };
  4812.  
  4813. SequenceMatcher.prototype.quickRatio = function() {
  4814. /*
  4815. Return an upper bound on ratio() relatively quickly.
  4816. This isn't defined beyond that it is an upper bound on .ratio(), and
  4817. is faster to compute.
  4818. */
  4819.  
  4820. var avail, elt, fullbcount, matches, numb, _i, _j, _len, _len1, _ref, _ref1;
  4821. if (!this.fullbcount) {
  4822. this.fullbcount = fullbcount = {};
  4823. _ref = this.b;
  4824. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  4825. elt = _ref[_i];
  4826. fullbcount[elt] = (fullbcount[elt] || 0) + 1;
  4827. }
  4828. }
  4829. fullbcount = this.fullbcount;
  4830. avail = {};
  4831. matches = 0;
  4832. _ref1 = this.a;
  4833. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  4834. elt = _ref1[_j];
  4835. if (_has(avail, elt)) {
  4836. numb = avail[elt];
  4837. } else {
  4838. numb = fullbcount[elt] || 0;
  4839. }
  4840. avail[elt] = numb - 1;
  4841. if (numb > 0) {
  4842. matches++;
  4843. }
  4844. }
  4845. return _calculateRatio(matches, this.a.length + this.b.length);
  4846. };
  4847.  
  4848. SequenceMatcher.prototype.realQuickRatio = function() {
  4849. /*
  4850. Return an upper bound on ratio() very quickly.
  4851. This isn't defined beyond that it is an upper bound on .ratio(), and
  4852. is faster to compute than either .ratio() or .quickRatio().
  4853. */
  4854.  
  4855. var la, lb, _ref;
  4856. _ref = [this.a.length, this.b.length], la = _ref[0], lb = _ref[1];
  4857. return _calculateRatio(min(la, lb), la + lb);
  4858. };
  4859.  
  4860. return SequenceMatcher;
  4861.  
  4862. })();
  4863.  
  4864. getCloseMatches = function(word, possibilities, n, cutoff) {
  4865. var result, s, score, x, _i, _j, _len, _len1, _ref, _results;
  4866. if (n == null) {
  4867. n = 3;
  4868. }
  4869. if (cutoff == null) {
  4870. cutoff = 0.6;
  4871. }
  4872. /*
  4873. Use SequenceMatcher to return list of the best "good enough" matches.
  4874. word is a sequence for which close matches are desired (typically a
  4875. string).
  4876. possibilities is a list of sequences against which to match word
  4877. (typically a list of strings).
  4878. Optional arg n (default 3) is the maximum number of close matches to
  4879. return. n must be > 0.
  4880. Optional arg cutoff (default 0.6) is a float in [0, 1]. Possibilities
  4881. that don't score at least that similar to word are ignored.
  4882. The best (no more than n) matches among the possibilities are returned
  4883. in a list, sorted by similarity score, most similar first.
  4884. >>> getCloseMatches('appel', ['ape', 'apple', 'peach', 'puppy'])
  4885. ['apple', 'ape']
  4886. >>> KEYWORDS = require('coffee-script').RESERVED
  4887. >>> getCloseMatches('wheel', KEYWORDS)
  4888. ['when', 'while']
  4889. >>> getCloseMatches('accost', KEYWORDS)
  4890. ['const']
  4891. */
  4892.  
  4893. if (!(n > 0)) {
  4894. throw new Error("n must be > 0: (" + n + ")");
  4895. }
  4896. if (!((0.0 <= cutoff && cutoff <= 1.0))) {
  4897. throw new Error("cutoff must be in [0.0, 1.0]: (" + cutoff + ")");
  4898. }
  4899. result = [];
  4900. s = new SequenceMatcher();
  4901. s.setSeq2(word);
  4902. for (_i = 0, _len = possibilities.length; _i < _len; _i++) {
  4903. x = possibilities[_i];
  4904. s.setSeq1(x);
  4905. if (s.realQuickRatio() >= cutoff && s.quickRatio() >= cutoff && s.ratio() >= cutoff) {
  4906. result.push([s.ratio(), x]);
  4907. }
  4908. }
  4909. result = Heap.nlargest(result, n, _arrayCmp);
  4910. _results = [];
  4911. for (_j = 0, _len1 = result.length; _j < _len1; _j++) {
  4912. _ref = result[_j], score = _ref[0], x = _ref[1];
  4913. _results.push(x);
  4914. }
  4915. return _results;
  4916. };
  4917.  
  4918. _countLeading = function(line, ch) {
  4919. /*
  4920. Return number of `ch` characters at the start of `line`.
  4921. >>> _countLeading(' abc', ' ')
  4922. 3
  4923. */
  4924.  
  4925. var i, n, _ref;
  4926. _ref = [0, line.length], i = _ref[0], n = _ref[1];
  4927. while (i < n && line[i] === ch) {
  4928. i++;
  4929. }
  4930. return i;
  4931. };
  4932.  
  4933. Differ = (function() {
  4934.  
  4935. Differ.name = 'Differ';
  4936.  
  4937. /*
  4938. Differ is a class for comparing sequences of lines of text, and
  4939. producing human-readable differences or deltas. Differ uses
  4940. SequenceMatcher both to compare sequences of lines, and to compare
  4941. sequences of characters within similar (near-matching) lines.
  4942. Each line of a Differ delta begins with a two-letter code:
  4943. '- ' line unique to sequence 1
  4944. '+ ' line unique to sequence 2
  4945. ' ' line common to both sequences
  4946. '? ' line not present in either input sequence
  4947. Lines beginning with '? ' attempt to guide the eye to intraline
  4948. differences, and were not present in either input sequence. These lines
  4949. can be confusing if the sequences contain tab characters.
  4950. Note that Differ makes no claim to produce a *minimal* diff. To the
  4951. contrary, minimal diffs are often counter-intuitive, because they synch
  4952. up anywhere possible, sometimes accidental matches 100 pages apart.
  4953. Restricting synch points to contiguous matches preserves some notion of
  4954. locality, at the occasional cost of producing a longer diff.
  4955. Example: Comparing two texts.
  4956. >>> text1 = ['1. Beautiful is better than ugly.\n',
  4957. ... '2. Explicit is better than implicit.\n',
  4958. ... '3. Simple is better than complex.\n',
  4959. ... '4. Complex is better than complicated.\n']
  4960. >>> text1.length
  4961. 4
  4962. >>> text2 = ['1. Beautiful is better than ugly.\n',
  4963. ... '3. Simple is better than complex.\n',
  4964. ... '4. Complicated is better than complex.\n',
  4965. ... '5. Flat is better than nested.\n']
  4966. Next we instantiate a Differ object:
  4967. >>> d = new Differ()
  4968. Note that when instantiating a Differ object we may pass functions to
  4969. filter out line and character 'junk'.
  4970. Finally, we compare the two:
  4971. >>> result = d.compare(text1, text2)
  4972. [ ' 1. Beautiful is better than ugly.\n',
  4973. '- 2. Explicit is better than implicit.\n',
  4974. '- 3. Simple is better than complex.\n',
  4975. '+ 3. Simple is better than complex.\n',
  4976. '? ++\n',
  4977. '- 4. Complex is better than complicated.\n',
  4978. '? ^ ---- ^\n',
  4979. '+ 4. Complicated is better than complex.\n',
  4980. '? ++++ ^ ^\n',
  4981. '+ 5. Flat is better than nested.\n' ]
  4982. Methods:
  4983. constructor(linejunk=null, charjunk=null)
  4984. Construct a text differencer, with optional filters.
  4985. compare(a, b)
  4986. Compare two sequences of lines; generate the resulting delta.
  4987. */
  4988.  
  4989.  
  4990. function Differ(linejunk, charjunk) {
  4991. this.linejunk = linejunk;
  4992. this.charjunk = charjunk;
  4993. /*
  4994. Construct a text differencer, with optional filters.
  4995. The two optional keyword parameters are for filter functions:
  4996. - `linejunk`: A function that should accept a single string argument,
  4997. and return true iff the string is junk. The module-level function
  4998. `IS_LINE_JUNK` may be used to filter out lines without visible
  4999. characters, except for at most one splat ('#'). It is recommended
  5000. to leave linejunk null.
  5001. - `charjunk`: A function that should accept a string of length 1. The
  5002. module-level function `IS_CHARACTER_JUNK` may be used to filter out
  5003. whitespace characters (a blank or tab; **note**: bad idea to include
  5004. newline in this!). Use of IS_CHARACTER_JUNK is recommended.
  5005. */
  5006.  
  5007. }
  5008.  
  5009. Differ.prototype.compare = function(a, b) {
  5010. /*
  5011. Compare two sequences of lines; generate the resulting delta.
  5012. Each sequence must contain individual single-line strings ending with
  5013. newlines. Such sequences can be obtained from the `readlines()` method
  5014. of file-like objects. The delta generated also consists of newline-
  5015. terminated strings, ready to be printed as-is via the writeline()
  5016. method of a file-like object.
  5017. Example:
  5018. >>> d = new Differ
  5019. >>> d.compare(['one\n', 'two\n', 'three\n'],
  5020. ... ['ore\n', 'tree\n', 'emu\n'])
  5021. [ '- one\n',
  5022. '? ^\n',
  5023. '+ ore\n',
  5024. '? ^\n',
  5025. '- two\n',
  5026. '- three\n',
  5027. '? -\n',
  5028. '+ tree\n',
  5029. '+ emu\n' ]
  5030. */
  5031.  
  5032. var ahi, alo, bhi, blo, cruncher, g, line, lines, tag, _i, _j, _len, _len1, _ref, _ref1;
  5033. cruncher = new SequenceMatcher(this.linejunk, a, b);
  5034. lines = [];
  5035. _ref = cruncher.getOpcodes();
  5036. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  5037. _ref1 = _ref[_i], tag = _ref1[0], alo = _ref1[1], ahi = _ref1[2], blo = _ref1[3], bhi = _ref1[4];
  5038. switch (tag) {
  5039. case 'replace':
  5040. g = this._fancyReplace(a, alo, ahi, b, blo, bhi);
  5041. break;
  5042. case 'delete':
  5043. g = this._dump('-', a, alo, ahi);
  5044. break;
  5045. case 'insert':
  5046. g = this._dump('+', b, blo, bhi);
  5047. break;
  5048. case 'equal':
  5049. g = this._dump(' ', a, alo, ahi);
  5050. break;
  5051. default:
  5052. throw new Error("unknow tag (" + tag + ")");
  5053. }
  5054. for (_j = 0, _len1 = g.length; _j < _len1; _j++) {
  5055. line = g[_j];
  5056. lines.push(line);
  5057. }
  5058. }
  5059. return lines;
  5060. };
  5061.  
  5062. Differ.prototype._dump = function(tag, x, lo, hi) {
  5063. /*
  5064. Generate comparison results for a same-tagged range.
  5065. */
  5066.  
  5067. var i, _i, _results;
  5068. _results = [];
  5069. for (i = _i = lo; lo <= hi ? _i < hi : _i > hi; i = lo <= hi ? ++_i : --_i) {
  5070. _results.push("" + tag + " " + x[i]);
  5071. }
  5072. return _results;
  5073. };
  5074.  
  5075. Differ.prototype._plainReplace = function(a, alo, ahi, b, blo, bhi) {
  5076. var first, g, line, lines, second, _i, _j, _len, _len1, _ref;
  5077. assert(alo < ahi && blo < bhi);
  5078. if (bhi - blo < ahi - alo) {
  5079. first = this._dump('+', b, blo, bhi);
  5080. second = this._dump('-', a, alo, ahi);
  5081. } else {
  5082. first = this._dump('-', a, alo, ahi);
  5083. second = this._dump('+', b, blo, bhi);
  5084. }
  5085. lines = [];
  5086. _ref = [first, second];
  5087. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  5088. g = _ref[_i];
  5089. for (_j = 0, _len1 = g.length; _j < _len1; _j++) {
  5090. line = g[_j];
  5091. lines.push(line);
  5092. }
  5093. }
  5094. return lines;
  5095. };
  5096.  
  5097. Differ.prototype._fancyReplace = function(a, alo, ahi, b, blo, bhi) {
  5098. /*
  5099. When replacing one block of lines with another, search the blocks
  5100. for *similar* lines; the best-matching pair (if any) is used as a
  5101. synch point, and intraline difference marking is done on the
  5102. similar pair. Lots of work, but often worth it.
  5103. Example:
  5104. >>> d = new Differ
  5105. >>> d._fancyReplace(['abcDefghiJkl\n'], 0, 1,
  5106. ... ['abcdefGhijkl\n'], 0, 1)
  5107. [ '- abcDefghiJkl\n',
  5108. '? ^ ^ ^\n',
  5109. '+ abcdefGhijkl\n',
  5110. '? ^ ^ ^\n' ]
  5111. */
  5112.  
  5113. var aelt, ai, ai1, ai2, atags, belt, bestRatio, besti, bestj, bj, bj1, bj2, btags, cruncher, cutoff, eqi, eqj, i, j, la, lb, line, lines, tag, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _n, _o, _ref, _ref1, _ref10, _ref11, _ref12, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
  5114. _ref = [0.74, 0.75], bestRatio = _ref[0], cutoff = _ref[1];
  5115. cruncher = new SequenceMatcher(this.charjunk);
  5116. _ref1 = [null, null], eqi = _ref1[0], eqj = _ref1[1];
  5117. lines = [];
  5118. for (j = _i = blo; blo <= bhi ? _i < bhi : _i > bhi; j = blo <= bhi ? ++_i : --_i) {
  5119. bj = b[j];
  5120. cruncher.setSeq2(bj);
  5121. for (i = _j = alo; alo <= ahi ? _j < ahi : _j > ahi; i = alo <= ahi ? ++_j : --_j) {
  5122. ai = a[i];
  5123. if (ai === bj) {
  5124. if (eqi === null) {
  5125. _ref2 = [i, j], eqi = _ref2[0], eqj = _ref2[1];
  5126. }
  5127. continue;
  5128. }
  5129. cruncher.setSeq1(ai);
  5130. if (cruncher.realQuickRatio() > bestRatio && cruncher.quickRatio() > bestRatio && cruncher.ratio() > bestRatio) {
  5131. _ref3 = [cruncher.ratio(), i, j], bestRatio = _ref3[0], besti = _ref3[1], bestj = _ref3[2];
  5132. }
  5133. }
  5134. }
  5135. if (bestRatio < cutoff) {
  5136. if (eqi === null) {
  5137. _ref4 = this._plainReplace(a, alo, ahi, b, blo, bhi);
  5138. for (_k = 0, _len = _ref4.length; _k < _len; _k++) {
  5139. line = _ref4[_k];
  5140. lines.push(line);
  5141. }
  5142. return lines;
  5143. }
  5144. _ref5 = [eqi, eqj, 1.0], besti = _ref5[0], bestj = _ref5[1], bestRatio = _ref5[2];
  5145. } else {
  5146. eqi = null;
  5147. }
  5148. _ref6 = this._fancyHelper(a, alo, besti, b, blo, bestj);
  5149. for (_l = 0, _len1 = _ref6.length; _l < _len1; _l++) {
  5150. line = _ref6[_l];
  5151. lines.push(line);
  5152. }
  5153. _ref7 = [a[besti], b[bestj]], aelt = _ref7[0], belt = _ref7[1];
  5154. if (eqi === null) {
  5155. atags = btags = '';
  5156. cruncher.setSeqs(aelt, belt);
  5157. _ref8 = cruncher.getOpcodes();
  5158. for (_m = 0, _len2 = _ref8.length; _m < _len2; _m++) {
  5159. _ref9 = _ref8[_m], tag = _ref9[0], ai1 = _ref9[1], ai2 = _ref9[2], bj1 = _ref9[3], bj2 = _ref9[4];
  5160. _ref10 = [ai2 - ai1, bj2 - bj1], la = _ref10[0], lb = _ref10[1];
  5161. switch (tag) {
  5162. case 'replace':
  5163. atags += Array(la + 1).join('^');
  5164. btags += Array(lb + 1).join('^');
  5165. break;
  5166. case 'delete':
  5167. atags += Array(la + 1).join('-');
  5168. break;
  5169. case 'insert':
  5170. btags += Array(lb + 1).join('+');
  5171. break;
  5172. case 'equal':
  5173. atags += Array(la + 1).join(' ');
  5174. btags += Array(lb + 1).join(' ');
  5175. break;
  5176. default:
  5177. throw new Error("unknow tag (" + tag + ")");
  5178. }
  5179. }
  5180. _ref11 = this._qformat(aelt, belt, atags, btags);
  5181. for (_n = 0, _len3 = _ref11.length; _n < _len3; _n++) {
  5182. line = _ref11[_n];
  5183. lines.push(line);
  5184. }
  5185. } else {
  5186. lines.push(' ' + aelt);
  5187. }
  5188. _ref12 = this._fancyHelper(a, besti + 1, ahi, b, bestj + 1, bhi);
  5189. for (_o = 0, _len4 = _ref12.length; _o < _len4; _o++) {
  5190. line = _ref12[_o];
  5191. lines.push(line);
  5192. }
  5193. return lines;
  5194. };
  5195.  
  5196. Differ.prototype._fancyHelper = function(a, alo, ahi, b, blo, bhi) {
  5197. var g;
  5198. g = [];
  5199. if (alo < ahi) {
  5200. if (blo < bhi) {
  5201. g = this._fancyReplace(a, alo, ahi, b, blo, bhi);
  5202. } else {
  5203. g = this._dump('-', a, alo, ahi);
  5204. }
  5205. } else if (blo < bhi) {
  5206. g = this._dump('+', b, blo, bhi);
  5207. }
  5208. return g;
  5209. };
  5210.  
  5211. Differ.prototype._qformat = function(aline, bline, atags, btags) {
  5212. /*
  5213. Format "?" output and deal with leading tabs.
  5214. Example:
  5215. >>> d = new Differ
  5216. >>> d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
  5217. [ '- \tabcDefghiJkl\n',
  5218. '? \t ^ ^ ^\n',
  5219. '+ \tabcdefGhijkl\n',
  5220. '? \t ^ ^ ^\n' ]
  5221. */
  5222.  
  5223. var common, lines;
  5224. lines = [];
  5225. common = min(_countLeading(aline, '\t'), _countLeading(bline, '\t'));
  5226. common = min(common, _countLeading(atags.slice(0, common), ' '));
  5227. common = min(common, _countLeading(btags.slice(0, common), ' '));
  5228. atags = atags.slice(common).replace(/\s+$/, '');
  5229. btags = btags.slice(common).replace(/\s+$/, '');
  5230. lines.push('- ' + aline);
  5231. if (atags.length) {
  5232. lines.push("? " + (Array(common + 1).join('\t')) + atags + "\n");
  5233. }
  5234. lines.push('+ ' + bline);
  5235. if (btags.length) {
  5236. lines.push("? " + (Array(common + 1).join('\t')) + btags + "\n");
  5237. }
  5238. return lines;
  5239. };
  5240.  
  5241. return Differ;
  5242.  
  5243. })();
  5244.  
  5245. IS_LINE_JUNK = function(line, pat) {
  5246. if (pat == null) {
  5247. pat = /^\s*#?\s*$/;
  5248. }
  5249. /*
  5250. Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
  5251. Examples:
  5252. >>> IS_LINE_JUNK('\n')
  5253. true
  5254. >>> IS_LINE_JUNK(' # \n')
  5255. true
  5256. >>> IS_LINE_JUNK('hello\n')
  5257. false
  5258. */
  5259.  
  5260. return pat.test(line);
  5261. };
  5262.  
  5263. IS_CHARACTER_JUNK = function(ch, ws) {
  5264. if (ws == null) {
  5265. ws = ' \t';
  5266. }
  5267. /*
  5268. Return 1 for ignorable character: iff `ch` is a space or tab.
  5269. Examples:
  5270. >>> IS_CHARACTER_JUNK(' ').should.be.true
  5271. true
  5272. >>> IS_CHARACTER_JUNK('\t').should.be.true
  5273. true
  5274. >>> IS_CHARACTER_JUNK('\n').should.be.false
  5275. false
  5276. >>> IS_CHARACTER_JUNK('x').should.be.false
  5277. false
  5278. */
  5279.  
  5280. return __indexOf.call(ws, ch) >= 0;
  5281. };
  5282.  
  5283. _formatRangeUnified = function(start, stop) {
  5284. /*
  5285. Convert range to the "ed" format'
  5286. */
  5287.  
  5288. var beginning, length;
  5289. beginning = start + 1;
  5290. length = stop - start;
  5291. if (length === 1) {
  5292. return "" + beginning;
  5293. }
  5294. if (!length) {
  5295. beginning--;
  5296. }
  5297. return "" + beginning + "," + length;
  5298. };
  5299.  
  5300. unifiedDiff = function(a, b, _arg) {
  5301. var file1Range, file2Range, first, fromdate, fromfile, fromfiledate, group, i1, i2, j1, j2, last, line, lines, lineterm, n, started, tag, todate, tofile, tofiledate, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
  5302. _ref = _arg != null ? _arg : {}, fromfile = _ref.fromfile, tofile = _ref.tofile, fromfiledate = _ref.fromfiledate, tofiledate = _ref.tofiledate, n = _ref.n, lineterm = _ref.lineterm;
  5303. /*
  5304. Compare two sequences of lines; generate the delta as a unified diff.
  5305. Unified diffs are a compact way of showing line changes and a few
  5306. lines of context. The number of context lines is set by 'n' which
  5307. defaults to three.
  5308. By default, the diff control lines (those with ---, +++, or @@) are
  5309. created with a trailing newline.
  5310. For inputs that do not have trailing newlines, set the lineterm
  5311. argument to "" so that the output will be uniformly newline free.
  5312. The unidiff format normally has a header for filenames and modification
  5313. times. Any or all of these may be specified using strings for
  5314. 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
  5315. The modification times are normally expressed in the ISO 8601 format.
  5316. Example:
  5317. >>> unifiedDiff('one two three four'.split(' '),
  5318. ... 'zero one tree four'.split(' '), {
  5319. ... fromfile: 'Original'
  5320. ... tofile: 'Current',
  5321. ... fromfiledate: '2005-01-26 23:30:50',
  5322. ... tofiledate: '2010-04-02 10:20:52',
  5323. ... lineterm: ''
  5324. ... })
  5325. [ '--- Original\t2005-01-26 23:30:50',
  5326. '+++ Current\t2010-04-02 10:20:52',
  5327. '@@ -1,4 +1,4 @@',
  5328. '+zero',
  5329. ' one',
  5330. '-two',
  5331. '-three',
  5332. '+tree',
  5333. ' four' ]
  5334. */
  5335.  
  5336. if (fromfile == null) {
  5337. fromfile = '';
  5338. }
  5339. if (tofile == null) {
  5340. tofile = '';
  5341. }
  5342. if (fromfiledate == null) {
  5343. fromfiledate = '';
  5344. }
  5345. if (tofiledate == null) {
  5346. tofiledate = '';
  5347. }
  5348. if (n == null) {
  5349. n = 3;
  5350. }
  5351. if (lineterm == null) {
  5352. lineterm = '\n';
  5353. }
  5354. lines = [];
  5355. started = false;
  5356. _ref1 = (new SequenceMatcher(null, a, b)).getGroupedOpcodes();
  5357. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  5358. group = _ref1[_i];
  5359. if (!started) {
  5360. started = true;
  5361. fromdate = fromfiledate ? "\t" + fromfiledate : '';
  5362. todate = tofiledate ? "\t" + tofiledate : '';
  5363. lines.push("--- " + fromfile + fromdate + lineterm);
  5364. lines.push("+++ " + tofile + todate + lineterm);
  5365. }
  5366. _ref2 = [group[0], group[group.length - 1]], first = _ref2[0], last = _ref2[1];
  5367. file1Range = _formatRangeUnified(first[1], last[2]);
  5368. file2Range = _formatRangeUnified(first[3], last[4]);
  5369. lines.push("@@ -" + file1Range + " +" + file2Range + " @@" + lineterm);
  5370. for (_j = 0, _len1 = group.length; _j < _len1; _j++) {
  5371. _ref3 = group[_j], tag = _ref3[0], i1 = _ref3[1], i2 = _ref3[2], j1 = _ref3[3], j2 = _ref3[4];
  5372. if (tag === 'equal') {
  5373. _ref4 = a.slice(i1, i2);
  5374. for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
  5375. line = _ref4[_k];
  5376. lines.push(' ' + line);
  5377. }
  5378. continue;
  5379. }
  5380. if (tag === 'replace' || tag === 'delete') {
  5381. _ref5 = a.slice(i1, i2);
  5382. for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
  5383. line = _ref5[_l];
  5384. lines.push('-' + line);
  5385. }
  5386. }
  5387. if (tag === 'replace' || tag === 'insert') {
  5388. _ref6 = b.slice(j1, j2);
  5389. for (_m = 0, _len4 = _ref6.length; _m < _len4; _m++) {
  5390. line = _ref6[_m];
  5391. lines.push('+' + line);
  5392. }
  5393. }
  5394. }
  5395. }
  5396. return lines;
  5397. };
  5398.  
  5399. _formatRangeContext = function(start, stop) {
  5400. /*
  5401. Convert range to the "ed" format'
  5402. */
  5403.  
  5404. var beginning, length;
  5405. beginning = start + 1;
  5406. length = stop - start;
  5407. if (!length) {
  5408. beginning--;
  5409. }
  5410. if (length <= 1) {
  5411. return "" + beginning;
  5412. }
  5413. return "" + beginning + "," + (beginning + length - 1);
  5414. };
  5415.  
  5416. contextDiff = function(a, b, _arg) {
  5417. var file1Range, file2Range, first, fromdate, fromfile, fromfiledate, group, i1, i2, j1, j2, last, line, lines, lineterm, n, prefix, started, tag, todate, tofile, tofiledate, _, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
  5418. _ref = _arg != null ? _arg : {}, fromfile = _ref.fromfile, tofile = _ref.tofile, fromfiledate = _ref.fromfiledate, tofiledate = _ref.tofiledate, n = _ref.n, lineterm = _ref.lineterm;
  5419. /*
  5420. Compare two sequences of lines; generate the delta as a context diff.
  5421. Context diffs are a compact way of showing line changes and a few
  5422. lines of context. The number of context lines is set by 'n' which
  5423. defaults to three.
  5424. By default, the diff control lines (those with *** or ---) are
  5425. created with a trailing newline. This is helpful so that inputs
  5426. created from file.readlines() result in diffs that are suitable for
  5427. file.writelines() since both the inputs and outputs have trailing
  5428. newlines.
  5429. For inputs that do not have trailing newlines, set the lineterm
  5430. argument to "" so that the output will be uniformly newline free.
  5431. The context diff format normally has a header for filenames and
  5432. modification times. Any or all of these may be specified using
  5433. strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
  5434. The modification times are normally expressed in the ISO 8601 format.
  5435. If not specified, the strings default to blanks.
  5436. Example:
  5437. >>> a = ['one\n', 'two\n', 'three\n', 'four\n']
  5438. >>> b = ['zero\n', 'one\n', 'tree\n', 'four\n']
  5439. >>> contextDiff(a, b, {fromfile: 'Original', tofile: 'Current'})
  5440. [ '*** Original\n',
  5441. '--- Current\n',
  5442. '***************\n',
  5443. '*** 1,4 ****\n',
  5444. ' one\n',
  5445. '! two\n',
  5446. '! three\n',
  5447. ' four\n',
  5448. '--- 1,4 ----\n',
  5449. '+ zero\n',
  5450. ' one\n',
  5451. '! tree\n',
  5452. ' four\n' ]
  5453. */
  5454.  
  5455. if (fromfile == null) {
  5456. fromfile = '';
  5457. }
  5458. if (tofile == null) {
  5459. tofile = '';
  5460. }
  5461. if (fromfiledate == null) {
  5462. fromfiledate = '';
  5463. }
  5464. if (tofiledate == null) {
  5465. tofiledate = '';
  5466. }
  5467. if (n == null) {
  5468. n = 3;
  5469. }
  5470. if (lineterm == null) {
  5471. lineterm = '\n';
  5472. }
  5473. prefix = {
  5474. insert: '+ ',
  5475. "delete": '- ',
  5476. replace: '! ',
  5477. equal: ' '
  5478. };
  5479. started = false;
  5480. lines = [];
  5481. _ref1 = (new SequenceMatcher(null, a, b)).getGroupedOpcodes();
  5482. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  5483. group = _ref1[_i];
  5484. if (!started) {
  5485. started = true;
  5486. fromdate = fromfiledate ? "\t" + fromfiledate : '';
  5487. todate = tofiledate ? "\t" + tofiledate : '';
  5488. lines.push("*** " + fromfile + fromdate + lineterm);
  5489. lines.push("--- " + tofile + todate + lineterm);
  5490. _ref2 = [group[0], group[group.length - 1]], first = _ref2[0], last = _ref2[1];
  5491. lines.push('***************' + lineterm);
  5492. file1Range = _formatRangeContext(first[1], last[2]);
  5493. lines.push("*** " + file1Range + " ****" + lineterm);
  5494. if (_any((function() {
  5495. var _j, _len1, _ref3, _results;
  5496. _results = [];
  5497. for (_j = 0, _len1 = group.length; _j < _len1; _j++) {
  5498. _ref3 = group[_j], tag = _ref3[0], _ = _ref3[1], _ = _ref3[2], _ = _ref3[3], _ = _ref3[4];
  5499. _results.push(tag === 'replace' || tag === 'delete');
  5500. }
  5501. return _results;
  5502. })())) {
  5503. for (_j = 0, _len1 = group.length; _j < _len1; _j++) {
  5504. _ref3 = group[_j], tag = _ref3[0], i1 = _ref3[1], i2 = _ref3[2], _ = _ref3[3], _ = _ref3[4];
  5505. if (tag !== 'insert') {
  5506. _ref4 = a.slice(i1, i2);
  5507. for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
  5508. line = _ref4[_k];
  5509. lines.push(prefix[tag] + line);
  5510. }
  5511. }
  5512. }
  5513. }
  5514. file2Range = _formatRangeContext(first[3], last[4]);
  5515. lines.push("--- " + file2Range + " ----" + lineterm);
  5516. if (_any((function() {
  5517. var _l, _len3, _ref5, _results;
  5518. _results = [];
  5519. for (_l = 0, _len3 = group.length; _l < _len3; _l++) {
  5520. _ref5 = group[_l], tag = _ref5[0], _ = _ref5[1], _ = _ref5[2], _ = _ref5[3], _ = _ref5[4];
  5521. _results.push(tag === 'replace' || tag === 'insert');
  5522. }
  5523. return _results;
  5524. })())) {
  5525. for (_l = 0, _len3 = group.length; _l < _len3; _l++) {
  5526. _ref5 = group[_l], tag = _ref5[0], _ = _ref5[1], _ = _ref5[2], j1 = _ref5[3], j2 = _ref5[4];
  5527. if (tag !== 'delete') {
  5528. _ref6 = b.slice(j1, j2);
  5529. for (_m = 0, _len4 = _ref6.length; _m < _len4; _m++) {
  5530. line = _ref6[_m];
  5531. lines.push(prefix[tag] + line);
  5532. }
  5533. }
  5534. }
  5535. }
  5536. }
  5537. }
  5538. return lines;
  5539. };
  5540.  
  5541. ndiff = function(a, b, linejunk, charjunk) {
  5542. if (charjunk == null) {
  5543. charjunk = IS_CHARACTER_JUNK;
  5544. }
  5545. /*
  5546. Compare `a` and `b` (lists of strings); return a `Differ`-style delta.
  5547. Optional keyword parameters `linejunk` and `charjunk` are for filter
  5548. functions (or None):
  5549. - linejunk: A function that should accept a single string argument, and
  5550. return true iff the string is junk. The default is null, and is
  5551. recommended;
  5552. - charjunk: A function that should accept a string of length 1. The
  5553. default is module-level function IS_CHARACTER_JUNK, which filters out
  5554. whitespace characters (a blank or tab; note: bad idea to include newline
  5555. in this!).
  5556. Example:
  5557. >>> a = ['one\n', 'two\n', 'three\n']
  5558. >>> b = ['ore\n', 'tree\n', 'emu\n']
  5559. >>> ndiff(a, b)
  5560. [ '- one\n',
  5561. '? ^\n',
  5562. '+ ore\n',
  5563. '? ^\n',
  5564. '- two\n',
  5565. '- three\n',
  5566. '? -\n',
  5567. '+ tree\n',
  5568. '+ emu\n' ]
  5569. */
  5570.  
  5571. return (new Differ(linejunk, charjunk)).compare(a, b);
  5572. };
  5573.  
  5574. restore = function(delta, which) {
  5575. /*
  5576. Generate one of the two sequences that generated a delta.
  5577. Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
  5578. lines originating from file 1 or 2 (parameter `which`), stripping off line
  5579. prefixes.
  5580. Examples:
  5581. >>> a = ['one\n', 'two\n', 'three\n']
  5582. >>> b = ['ore\n', 'tree\n', 'emu\n']
  5583. >>> diff = ndiff(a, b)
  5584. >>> restore(diff, 1)
  5585. [ 'one\n',
  5586. 'two\n',
  5587. 'three\n' ]
  5588. >>> restore(diff, 2)
  5589. [ 'ore\n',
  5590. 'tree\n',
  5591. 'emu\n' ]
  5592. */
  5593.  
  5594. var line, lines, prefixes, tag, _i, _len, _ref;
  5595. tag = {
  5596. 1: '- ',
  5597. 2: '+ '
  5598. }[which];
  5599. if (!tag) {
  5600. throw new Error("unknow delta choice (must be 1 or 2): " + which);
  5601. }
  5602. prefixes = [' ', tag];
  5603. lines = [];
  5604. for (_i = 0, _len = delta.length; _i < _len; _i++) {
  5605. line = delta[_i];
  5606. if (_ref = line.slice(0, 2), __indexOf.call(prefixes, _ref) >= 0) {
  5607. lines.push(line.slice(2));
  5608. }
  5609. }
  5610. return lines;
  5611. };
  5612.  
  5613. exports._arrayCmp = _arrayCmp;
  5614.  
  5615. exports.SequenceMatcher = SequenceMatcher;
  5616.  
  5617. exports.getCloseMatches = getCloseMatches;
  5618.  
  5619. exports._countLeading = _countLeading;
  5620.  
  5621. exports.Differ = Differ;
  5622.  
  5623. exports.IS_LINE_JUNK = IS_LINE_JUNK;
  5624.  
  5625. exports.IS_CHARACTER_JUNK = IS_CHARACTER_JUNK;
  5626.  
  5627. exports._formatRangeUnified = _formatRangeUnified;
  5628.  
  5629. exports.unifiedDiff = unifiedDiff;
  5630.  
  5631. exports._formatRangeContext = _formatRangeContext;
  5632.  
  5633. exports.contextDiff = contextDiff;
  5634.  
  5635. exports.ndiff = ndiff;
  5636.  
  5637. exports.restore = restore;
  5638.  
  5639. }).call(this);
  5640.  
  5641.  
  5642. /***/ }),
  5643.  
  5644. /***/ "v2jn":
  5645. /***/ (function(module, exports, __webpack_require__) {
  5646.  
  5647. /*!
  5648.  
  5649. diff v4.0.1
  5650.  
  5651. Software License Agreement (BSD License)
  5652.  
  5653. Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
  5654.  
  5655. All rights reserved.
  5656.  
  5657. Redistribution and use of this software in source and binary forms, with or without modification,
  5658. are permitted provided that the following conditions are met:
  5659.  
  5660. * Redistributions of source code must retain the above
  5661. copyright notice, this list of conditions and the
  5662. following disclaimer.
  5663.  
  5664. * Redistributions in binary form must reproduce the above
  5665. copyright notice, this list of conditions and the
  5666. following disclaimer in the documentation and/or other
  5667. materials provided with the distribution.
  5668.  
  5669. * Neither the name of Kevin Decker nor the names of its
  5670. contributors may be used to endorse or promote products
  5671. derived from this software without specific prior
  5672. written permission.
  5673.  
  5674. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  5675. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5676. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  5677. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  5678. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  5679. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  5680. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  5681. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5682. @license
  5683. */
  5684. (function (global, factory) {
  5685. true ? factory(exports) :
  5686. undefined;
  5687. }(this, function (exports) { 'use strict';
  5688.  
  5689. function Diff() {}
  5690. Diff.prototype = {
  5691. diff: function diff(oldString, newString) {
  5692. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5693. var callback = options.callback;
  5694.  
  5695. if (typeof options === 'function') {
  5696. callback = options;
  5697. options = {};
  5698. }
  5699.  
  5700. this.options = options;
  5701. var self = this;
  5702.  
  5703. function done(value) {
  5704. if (callback) {
  5705. setTimeout(function () {
  5706. callback(undefined, value);
  5707. }, 0);
  5708. return true;
  5709. } else {
  5710. return value;
  5711. }
  5712. } // Allow subclasses to massage the input prior to running
  5713.  
  5714.  
  5715. oldString = this.castInput(oldString);
  5716. newString = this.castInput(newString);
  5717. oldString = this.removeEmpty(this.tokenize(oldString));
  5718. newString = this.removeEmpty(this.tokenize(newString));
  5719. var newLen = newString.length,
  5720. oldLen = oldString.length;
  5721. var editLength = 1;
  5722. var maxEditLength = newLen + oldLen;
  5723. var bestPath = [{
  5724. newPos: -1,
  5725. components: []
  5726. }]; // Seed editLength = 0, i.e. the content starts with the same values
  5727.  
  5728. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  5729.  
  5730. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  5731. // Identity per the equality and tokenizer
  5732. return done([{
  5733. value: this.join(newString),
  5734. count: newString.length
  5735. }]);
  5736. } // Main worker method. checks all permutations of a given edit length for acceptance.
  5737.  
  5738.  
  5739. function execEditLength() {
  5740. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  5741. var basePath = void 0;
  5742.  
  5743. var addPath = bestPath[diagonalPath - 1],
  5744. removePath = bestPath[diagonalPath + 1],
  5745. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  5746.  
  5747. if (addPath) {
  5748. // No one else is going to attempt to use this value, clear it
  5749. bestPath[diagonalPath - 1] = undefined;
  5750. }
  5751.  
  5752. var canAdd = addPath && addPath.newPos + 1 < newLen,
  5753. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  5754.  
  5755. if (!canAdd && !canRemove) {
  5756. // If this path is a terminal then prune
  5757. bestPath[diagonalPath] = undefined;
  5758. continue;
  5759. } // Select the diagonal that we want to branch from. We select the prior
  5760. // path whose position in the new string is the farthest from the origin
  5761. // and does not pass the bounds of the diff graph
  5762.  
  5763.  
  5764. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  5765. basePath = clonePath(removePath);
  5766. self.pushComponent(basePath.components, undefined, true);
  5767. } else {
  5768. basePath = addPath; // No need to clone, we've pulled it from the list
  5769.  
  5770. basePath.newPos++;
  5771. self.pushComponent(basePath.components, true, undefined);
  5772. }
  5773.  
  5774. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  5775.  
  5776. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  5777. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  5778. } else {
  5779. // Otherwise track this path as a potential candidate and continue.
  5780. bestPath[diagonalPath] = basePath;
  5781. }
  5782. }
  5783.  
  5784. editLength++;
  5785. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  5786. // sync and async mode which is never fun. Loops over execEditLength until a value
  5787. // is produced.
  5788.  
  5789.  
  5790. if (callback) {
  5791. (function exec() {
  5792. setTimeout(function () {
  5793. // This should not happen, but we want to be safe.
  5794.  
  5795. /* istanbul ignore next */
  5796. if (editLength > maxEditLength) {
  5797. return callback();
  5798. }
  5799.  
  5800. if (!execEditLength()) {
  5801. exec();
  5802. }
  5803. }, 0);
  5804. })();
  5805. } else {
  5806. while (editLength <= maxEditLength) {
  5807. var ret = execEditLength();
  5808.  
  5809. if (ret) {
  5810. return ret;
  5811. }
  5812. }
  5813. }
  5814. },
  5815. pushComponent: function pushComponent(components, added, removed) {
  5816. var last = components[components.length - 1];
  5817.  
  5818. if (last && last.added === added && last.removed === removed) {
  5819. // We need to clone here as the component clone operation is just
  5820. // as shallow array clone
  5821. components[components.length - 1] = {
  5822. count: last.count + 1,
  5823. added: added,
  5824. removed: removed
  5825. };
  5826. } else {
  5827. components.push({
  5828. count: 1,
  5829. added: added,
  5830. removed: removed
  5831. });
  5832. }
  5833. },
  5834. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  5835. var newLen = newString.length,
  5836. oldLen = oldString.length,
  5837. newPos = basePath.newPos,
  5838. oldPos = newPos - diagonalPath,
  5839. commonCount = 0;
  5840.  
  5841. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  5842. newPos++;
  5843. oldPos++;
  5844. commonCount++;
  5845. }
  5846.  
  5847. if (commonCount) {
  5848. basePath.components.push({
  5849. count: commonCount
  5850. });
  5851. }
  5852.  
  5853. basePath.newPos = newPos;
  5854. return oldPos;
  5855. },
  5856. equals: function equals(left, right) {
  5857. if (this.options.comparator) {
  5858. return this.options.comparator(left, right);
  5859. } else {
  5860. return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
  5861. }
  5862. },
  5863. removeEmpty: function removeEmpty(array) {
  5864. var ret = [];
  5865.  
  5866. for (var i = 0; i < array.length; i++) {
  5867. if (array[i]) {
  5868. ret.push(array[i]);
  5869. }
  5870. }
  5871.  
  5872. return ret;
  5873. },
  5874. castInput: function castInput(value) {
  5875. return value;
  5876. },
  5877. tokenize: function tokenize(value) {
  5878. return value.split('');
  5879. },
  5880. join: function join(chars) {
  5881. return chars.join('');
  5882. }
  5883. };
  5884.  
  5885. function buildValues(diff, components, newString, oldString, useLongestToken) {
  5886. var componentPos = 0,
  5887. componentLen = components.length,
  5888. newPos = 0,
  5889. oldPos = 0;
  5890.  
  5891. for (; componentPos < componentLen; componentPos++) {
  5892. var component = components[componentPos];
  5893.  
  5894. if (!component.removed) {
  5895. if (!component.added && useLongestToken) {
  5896. var value = newString.slice(newPos, newPos + component.count);
  5897. value = value.map(function (value, i) {
  5898. var oldValue = oldString[oldPos + i];
  5899. return oldValue.length > value.length ? oldValue : value;
  5900. });
  5901. component.value = diff.join(value);
  5902. } else {
  5903. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  5904. }
  5905.  
  5906. newPos += component.count; // Common case
  5907.  
  5908. if (!component.added) {
  5909. oldPos += component.count;
  5910. }
  5911. } else {
  5912. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  5913. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  5914. // The diffing algorithm is tied to add then remove output and this is the simplest
  5915. // route to get the desired output with minimal overhead.
  5916.  
  5917. if (componentPos && components[componentPos - 1].added) {
  5918. var tmp = components[componentPos - 1];
  5919. components[componentPos - 1] = components[componentPos];
  5920. components[componentPos] = tmp;
  5921. }
  5922. }
  5923. } // Special case handle for when one terminal is ignored (i.e. whitespace).
  5924. // For this case we merge the terminal into the prior string and drop the change.
  5925. // This is only available for string mode.
  5926.  
  5927.  
  5928. var lastComponent = components[componentLen - 1];
  5929.  
  5930. if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  5931. components[componentLen - 2].value += lastComponent.value;
  5932. components.pop();
  5933. }
  5934.  
  5935. return components;
  5936. }
  5937.  
  5938. function clonePath(path) {
  5939. return {
  5940. newPos: path.newPos,
  5941. components: path.components.slice(0)
  5942. };
  5943. }
  5944.  
  5945. var characterDiff = new Diff();
  5946. function diffChars(oldStr, newStr, options) {
  5947. return characterDiff.diff(oldStr, newStr, options);
  5948. }
  5949.  
  5950. function generateOptions(options, defaults) {
  5951. if (typeof options === 'function') {
  5952. defaults.callback = options;
  5953. } else if (options) {
  5954. for (var name in options) {
  5955. /* istanbul ignore else */
  5956. if (options.hasOwnProperty(name)) {
  5957. defaults[name] = options[name];
  5958. }
  5959. }
  5960. }
  5961.  
  5962. return defaults;
  5963. }
  5964.  
  5965. //
  5966. // Ranges and exceptions:
  5967. // Latin-1 Supplement, 0080–00FF
  5968. // - U+00D7 × Multiplication sign
  5969. // - U+00F7 ÷ Division sign
  5970. // Latin Extended-A, 0100–017F
  5971. // Latin Extended-B, 0180–024F
  5972. // IPA Extensions, 0250–02AF
  5973. // Spacing Modifier Letters, 02B0–02FF
  5974. // - U+02C7 ˇ &#711; Caron
  5975. // - U+02D8 ˘ &#728; Breve
  5976. // - U+02D9 ˙ &#729; Dot Above
  5977. // - U+02DA ˚ &#730; Ring Above
  5978. // - U+02DB ˛ &#731; Ogonek
  5979. // - U+02DC ˜ &#732; Small Tilde
  5980. // - U+02DD ˝ &#733; Double Acute Accent
  5981. // Latin Extended Additional, 1E00–1EFF
  5982.  
  5983. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  5984. var reWhitespace = /\S/;
  5985. var wordDiff = new Diff();
  5986.  
  5987. wordDiff.equals = function (left, right) {
  5988. if (this.options.ignoreCase) {
  5989. left = left.toLowerCase();
  5990. right = right.toLowerCase();
  5991. }
  5992.  
  5993. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  5994. };
  5995.  
  5996. wordDiff.tokenize = function (value) {
  5997. var tokens = value.split(/(\s+|[()[\]{}'"]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  5998.  
  5999. for (var i = 0; i < tokens.length - 1; i++) {
  6000. // If we have an empty string in the next field and we have only word chars before and after, merge
  6001. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  6002. tokens[i] += tokens[i + 2];
  6003. tokens.splice(i + 1, 2);
  6004. i--;
  6005. }
  6006. }
  6007.  
  6008. return tokens;
  6009. };
  6010.  
  6011. function diffWords(oldStr, newStr, options) {
  6012. options = generateOptions(options, {
  6013. ignoreWhitespace: true
  6014. });
  6015. return wordDiff.diff(oldStr, newStr, options);
  6016. }
  6017. function diffWordsWithSpace(oldStr, newStr, options) {
  6018. return wordDiff.diff(oldStr, newStr, options);
  6019. }
  6020.  
  6021. var lineDiff = new Diff();
  6022.  
  6023. lineDiff.tokenize = function (value) {
  6024. var retLines = [],
  6025. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  6026.  
  6027. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  6028. linesAndNewlines.pop();
  6029. } // Merge the content and line separators into single tokens
  6030.  
  6031.  
  6032. for (var i = 0; i < linesAndNewlines.length; i++) {
  6033. var line = linesAndNewlines[i];
  6034.  
  6035. if (i % 2 && !this.options.newlineIsToken) {
  6036. retLines[retLines.length - 1] += line;
  6037. } else {
  6038. if (this.options.ignoreWhitespace) {
  6039. line = line.trim();
  6040. }
  6041.  
  6042. retLines.push(line);
  6043. }
  6044. }
  6045.  
  6046. return retLines;
  6047. };
  6048.  
  6049. function diffLines(oldStr, newStr, callback) {
  6050. return lineDiff.diff(oldStr, newStr, callback);
  6051. }
  6052. function diffTrimmedLines(oldStr, newStr, callback) {
  6053. var options = generateOptions(callback, {
  6054. ignoreWhitespace: true
  6055. });
  6056. return lineDiff.diff(oldStr, newStr, options);
  6057. }
  6058.  
  6059. var sentenceDiff = new Diff();
  6060.  
  6061. sentenceDiff.tokenize = function (value) {
  6062. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  6063. };
  6064.  
  6065. function diffSentences(oldStr, newStr, callback) {
  6066. return sentenceDiff.diff(oldStr, newStr, callback);
  6067. }
  6068.  
  6069. var cssDiff = new Diff();
  6070.  
  6071. cssDiff.tokenize = function (value) {
  6072. return value.split(/([{}:;,]|\s+)/);
  6073. };
  6074.  
  6075. function diffCss(oldStr, newStr, callback) {
  6076. return cssDiff.diff(oldStr, newStr, callback);
  6077. }
  6078.  
  6079. function _typeof(obj) {
  6080. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  6081. _typeof = function (obj) {
  6082. return typeof obj;
  6083. };
  6084. } else {
  6085. _typeof = function (obj) {
  6086. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  6087. };
  6088. }
  6089.  
  6090. return _typeof(obj);
  6091. }
  6092.  
  6093. function _toConsumableArray(arr) {
  6094. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  6095. }
  6096.  
  6097. function _arrayWithoutHoles(arr) {
  6098. if (Array.isArray(arr)) {
  6099. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  6100.  
  6101. return arr2;
  6102. }
  6103. }
  6104.  
  6105. function _iterableToArray(iter) {
  6106. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  6107. }
  6108.  
  6109. function _nonIterableSpread() {
  6110. throw new TypeError("Invalid attempt to spread non-iterable instance");
  6111. }
  6112.  
  6113. var objectPrototypeToString = Object.prototype.toString;
  6114. var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  6115. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  6116.  
  6117. jsonDiff.useLongestToken = true;
  6118. jsonDiff.tokenize = lineDiff.tokenize;
  6119.  
  6120. jsonDiff.castInput = function (value) {
  6121. var _this$options = this.options,
  6122. undefinedReplacement = _this$options.undefinedReplacement,
  6123. _this$options$stringi = _this$options.stringifyReplacer,
  6124. stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
  6125. return typeof v === 'undefined' ? undefinedReplacement : v;
  6126. } : _this$options$stringi;
  6127. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
  6128. };
  6129.  
  6130. jsonDiff.equals = function (left, right) {
  6131. return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  6132. };
  6133.  
  6134. function diffJson(oldObj, newObj, options) {
  6135. return jsonDiff.diff(oldObj, newObj, options);
  6136. } // This function handles the presence of circular references by bailing out when encountering an
  6137. // object that is already on the "stack" of items being processed. Accepts an optional replacer
  6138.  
  6139. function canonicalize(obj, stack, replacementStack, replacer, key) {
  6140. stack = stack || [];
  6141. replacementStack = replacementStack || [];
  6142.  
  6143. if (replacer) {
  6144. obj = replacer(key, obj);
  6145. }
  6146.  
  6147. var i;
  6148.  
  6149. for (i = 0; i < stack.length; i += 1) {
  6150. if (stack[i] === obj) {
  6151. return replacementStack[i];
  6152. }
  6153. }
  6154.  
  6155. var canonicalizedObj;
  6156.  
  6157. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  6158. stack.push(obj);
  6159. canonicalizedObj = new Array(obj.length);
  6160. replacementStack.push(canonicalizedObj);
  6161.  
  6162. for (i = 0; i < obj.length; i += 1) {
  6163. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
  6164. }
  6165.  
  6166. stack.pop();
  6167. replacementStack.pop();
  6168. return canonicalizedObj;
  6169. }
  6170.  
  6171. if (obj && obj.toJSON) {
  6172. obj = obj.toJSON();
  6173. }
  6174.  
  6175. if (_typeof(obj) === 'object' && obj !== null) {
  6176. stack.push(obj);
  6177. canonicalizedObj = {};
  6178. replacementStack.push(canonicalizedObj);
  6179.  
  6180. var sortedKeys = [],
  6181. _key;
  6182.  
  6183. for (_key in obj) {
  6184. /* istanbul ignore else */
  6185. if (obj.hasOwnProperty(_key)) {
  6186. sortedKeys.push(_key);
  6187. }
  6188. }
  6189.  
  6190. sortedKeys.sort();
  6191.  
  6192. for (i = 0; i < sortedKeys.length; i += 1) {
  6193. _key = sortedKeys[i];
  6194. canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
  6195. }
  6196.  
  6197. stack.pop();
  6198. replacementStack.pop();
  6199. } else {
  6200. canonicalizedObj = obj;
  6201. }
  6202.  
  6203. return canonicalizedObj;
  6204. }
  6205.  
  6206. var arrayDiff = new Diff();
  6207.  
  6208. arrayDiff.tokenize = function (value) {
  6209. return value.slice();
  6210. };
  6211.  
  6212. arrayDiff.join = arrayDiff.removeEmpty = function (value) {
  6213. return value;
  6214. };
  6215.  
  6216. function diffArrays(oldArr, newArr, callback) {
  6217. return arrayDiff.diff(oldArr, newArr, callback);
  6218. }
  6219.  
  6220. function parsePatch(uniDiff) {
  6221. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  6222. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  6223. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  6224. list = [],
  6225. i = 0;
  6226.  
  6227. function parseIndex() {
  6228. var index = {};
  6229. list.push(index); // Parse diff metadata
  6230.  
  6231. while (i < diffstr.length) {
  6232. var line = diffstr[i]; // File header found, end parsing diff metadata
  6233.  
  6234. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  6235. break;
  6236. } // Diff index
  6237.  
  6238.  
  6239. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  6240.  
  6241. if (header) {
  6242. index.index = header[1];
  6243. }
  6244.  
  6245. i++;
  6246. } // Parse file headers if they are defined. Unified diff requires them, but
  6247. // there's no technical issues to have an isolated hunk without file header
  6248.  
  6249.  
  6250. parseFileHeader(index);
  6251. parseFileHeader(index); // Parse hunks
  6252.  
  6253. index.hunks = [];
  6254.  
  6255. while (i < diffstr.length) {
  6256. var _line = diffstr[i];
  6257.  
  6258. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  6259. break;
  6260. } else if (/^@@/.test(_line)) {
  6261. index.hunks.push(parseHunk());
  6262. } else if (_line && options.strict) {
  6263. // Ignore unexpected content unless in strict mode
  6264. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  6265. } else {
  6266. i++;
  6267. }
  6268. }
  6269. } // Parses the --- and +++ headers, if none are found, no lines
  6270. // are consumed.
  6271.  
  6272.  
  6273. function parseFileHeader(index) {
  6274. var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
  6275.  
  6276. if (fileHeader) {
  6277. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  6278. var data = fileHeader[2].split('\t', 2);
  6279. var fileName = data[0].replace(/\\\\/g, '\\');
  6280.  
  6281. if (/^".*"$/.test(fileName)) {
  6282. fileName = fileName.substr(1, fileName.length - 2);
  6283. }
  6284.  
  6285. index[keyPrefix + 'FileName'] = fileName;
  6286. index[keyPrefix + 'Header'] = (data[1] || '').trim();
  6287. i++;
  6288. }
  6289. } // Parses a hunk
  6290. // This assumes that we are at the start of a hunk.
  6291.  
  6292.  
  6293. function parseHunk() {
  6294. var chunkHeaderIndex = i,
  6295. chunkHeaderLine = diffstr[i++],
  6296. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  6297. var hunk = {
  6298. oldStart: +chunkHeader[1],
  6299. oldLines: +chunkHeader[2] || 1,
  6300. newStart: +chunkHeader[3],
  6301. newLines: +chunkHeader[4] || 1,
  6302. lines: [],
  6303. linedelimiters: []
  6304. };
  6305. var addCount = 0,
  6306. removeCount = 0;
  6307.  
  6308. for (; i < diffstr.length; i++) {
  6309. // Lines starting with '---' could be mistaken for the "remove line" operation
  6310. // But they could be the header for the next file. Therefore prune such cases out.
  6311. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  6312. break;
  6313. }
  6314.  
  6315. var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
  6316.  
  6317. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  6318. hunk.lines.push(diffstr[i]);
  6319. hunk.linedelimiters.push(delimiters[i] || '\n');
  6320.  
  6321. if (operation === '+') {
  6322. addCount++;
  6323. } else if (operation === '-') {
  6324. removeCount++;
  6325. } else if (operation === ' ') {
  6326. addCount++;
  6327. removeCount++;
  6328. }
  6329. } else {
  6330. break;
  6331. }
  6332. } // Handle the empty block count case
  6333.  
  6334.  
  6335. if (!addCount && hunk.newLines === 1) {
  6336. hunk.newLines = 0;
  6337. }
  6338.  
  6339. if (!removeCount && hunk.oldLines === 1) {
  6340. hunk.oldLines = 0;
  6341. } // Perform optional sanity checking
  6342.  
  6343.  
  6344. if (options.strict) {
  6345. if (addCount !== hunk.newLines) {
  6346. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  6347. }
  6348.  
  6349. if (removeCount !== hunk.oldLines) {
  6350. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  6351. }
  6352. }
  6353.  
  6354. return hunk;
  6355. }
  6356.  
  6357. while (i < diffstr.length) {
  6358. parseIndex();
  6359. }
  6360.  
  6361. return list;
  6362. }
  6363.  
  6364. // Iterator that traverses in the range of [min, max], stepping
  6365. // by distance from a given start position. I.e. for [0, 4], with
  6366. // start of 2, this will iterate 2, 3, 1, 4, 0.
  6367. function distanceIterator (start, minLine, maxLine) {
  6368. var wantForward = true,
  6369. backwardExhausted = false,
  6370. forwardExhausted = false,
  6371. localOffset = 1;
  6372. return function iterator() {
  6373. if (wantForward && !forwardExhausted) {
  6374. if (backwardExhausted) {
  6375. localOffset++;
  6376. } else {
  6377. wantForward = false;
  6378. } // Check if trying to fit beyond text length, and if not, check it fits
  6379. // after offset location (or desired location on first iteration)
  6380.  
  6381.  
  6382. if (start + localOffset <= maxLine) {
  6383. return localOffset;
  6384. }
  6385.  
  6386. forwardExhausted = true;
  6387. }
  6388.  
  6389. if (!backwardExhausted) {
  6390. if (!forwardExhausted) {
  6391. wantForward = true;
  6392. } // Check if trying to fit before text beginning, and if not, check it fits
  6393. // before offset location
  6394.  
  6395.  
  6396. if (minLine <= start - localOffset) {
  6397. return -localOffset++;
  6398. }
  6399.  
  6400. backwardExhausted = true;
  6401. return iterator();
  6402. } // We tried to fit hunk before text beginning and beyond text length, then
  6403. // hunk can't fit on the text. Return undefined
  6404.  
  6405. };
  6406. }
  6407.  
  6408. function applyPatch(source, uniDiff) {
  6409. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  6410.  
  6411. if (typeof uniDiff === 'string') {
  6412. uniDiff = parsePatch(uniDiff);
  6413. }
  6414.  
  6415. if (Array.isArray(uniDiff)) {
  6416. if (uniDiff.length > 1) {
  6417. throw new Error('applyPatch only works with a single input.');
  6418. }
  6419.  
  6420. uniDiff = uniDiff[0];
  6421. } // Apply the diff to the input
  6422.  
  6423.  
  6424. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  6425. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  6426. hunks = uniDiff.hunks,
  6427. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
  6428. return line === patchContent;
  6429. },
  6430. errorCount = 0,
  6431. fuzzFactor = options.fuzzFactor || 0,
  6432. minLine = 0,
  6433. offset = 0,
  6434. removeEOFNL,
  6435. addEOFNL;
  6436. /**
  6437. * Checks if the hunk exactly fits on the provided location
  6438. */
  6439.  
  6440.  
  6441. function hunkFits(hunk, toPos) {
  6442. for (var j = 0; j < hunk.lines.length; j++) {
  6443. var line = hunk.lines[j],
  6444. operation = line.length > 0 ? line[0] : ' ',
  6445. content = line.length > 0 ? line.substr(1) : line;
  6446.  
  6447. if (operation === ' ' || operation === '-') {
  6448. // Context sanity check
  6449. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  6450. errorCount++;
  6451.  
  6452. if (errorCount > fuzzFactor) {
  6453. return false;
  6454. }
  6455. }
  6456.  
  6457. toPos++;
  6458. }
  6459. }
  6460.  
  6461. return true;
  6462. } // Search best fit offsets for each hunk based on the previous ones
  6463.  
  6464.  
  6465. for (var i = 0; i < hunks.length; i++) {
  6466. var hunk = hunks[i],
  6467. maxLine = lines.length - hunk.oldLines,
  6468. localOffset = 0,
  6469. toPos = offset + hunk.oldStart - 1;
  6470. var iterator = distanceIterator(toPos, minLine, maxLine);
  6471.  
  6472. for (; localOffset !== undefined; localOffset = iterator()) {
  6473. if (hunkFits(hunk, toPos + localOffset)) {
  6474. hunk.offset = offset += localOffset;
  6475. break;
  6476. }
  6477. }
  6478.  
  6479. if (localOffset === undefined) {
  6480. return false;
  6481. } // Set lower text limit to end of the current hunk, so next ones don't try
  6482. // to fit over already patched text
  6483.  
  6484.  
  6485. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  6486. } // Apply patch hunks
  6487.  
  6488.  
  6489. var diffOffset = 0;
  6490.  
  6491. for (var _i = 0; _i < hunks.length; _i++) {
  6492. var _hunk = hunks[_i],
  6493. _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
  6494.  
  6495. diffOffset += _hunk.newLines - _hunk.oldLines;
  6496.  
  6497. if (_toPos < 0) {
  6498. // Creating a new file
  6499. _toPos = 0;
  6500. }
  6501.  
  6502. for (var j = 0; j < _hunk.lines.length; j++) {
  6503. var line = _hunk.lines[j],
  6504. operation = line.length > 0 ? line[0] : ' ',
  6505. content = line.length > 0 ? line.substr(1) : line,
  6506. delimiter = _hunk.linedelimiters[j];
  6507.  
  6508. if (operation === ' ') {
  6509. _toPos++;
  6510. } else if (operation === '-') {
  6511. lines.splice(_toPos, 1);
  6512. delimiters.splice(_toPos, 1);
  6513. /* istanbul ignore else */
  6514. } else if (operation === '+') {
  6515. lines.splice(_toPos, 0, content);
  6516. delimiters.splice(_toPos, 0, delimiter);
  6517. _toPos++;
  6518. } else if (operation === '\\') {
  6519. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  6520.  
  6521. if (previousOperation === '+') {
  6522. removeEOFNL = true;
  6523. } else if (previousOperation === '-') {
  6524. addEOFNL = true;
  6525. }
  6526. }
  6527. }
  6528. } // Handle EOFNL insertion/removal
  6529.  
  6530.  
  6531. if (removeEOFNL) {
  6532. while (!lines[lines.length - 1]) {
  6533. lines.pop();
  6534. delimiters.pop();
  6535. }
  6536. } else if (addEOFNL) {
  6537. lines.push('');
  6538. delimiters.push('\n');
  6539. }
  6540.  
  6541. for (var _k = 0; _k < lines.length - 1; _k++) {
  6542. lines[_k] = lines[_k] + delimiters[_k];
  6543. }
  6544.  
  6545. return lines.join('');
  6546. } // Wrapper that supports multiple file patches via callbacks.
  6547.  
  6548. function applyPatches(uniDiff, options) {
  6549. if (typeof uniDiff === 'string') {
  6550. uniDiff = parsePatch(uniDiff);
  6551. }
  6552.  
  6553. var currentIndex = 0;
  6554.  
  6555. function processIndex() {
  6556. var index = uniDiff[currentIndex++];
  6557.  
  6558. if (!index) {
  6559. return options.complete();
  6560. }
  6561.  
  6562. options.loadFile(index, function (err, data) {
  6563. if (err) {
  6564. return options.complete(err);
  6565. }
  6566.  
  6567. var updatedContent = applyPatch(data, index, options);
  6568. options.patched(index, updatedContent, function (err) {
  6569. if (err) {
  6570. return options.complete(err);
  6571. }
  6572.  
  6573. processIndex();
  6574. });
  6575. });
  6576. }
  6577.  
  6578. processIndex();
  6579. }
  6580.  
  6581. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  6582. if (!options) {
  6583. options = {};
  6584. }
  6585.  
  6586. if (typeof options.context === 'undefined') {
  6587. options.context = 4;
  6588. }
  6589.  
  6590. var diff = diffLines(oldStr, newStr, options);
  6591. diff.push({
  6592. value: '',
  6593. lines: []
  6594. }); // Append an empty value to make cleanup easier
  6595.  
  6596. function contextLines(lines) {
  6597. return lines.map(function (entry) {
  6598. return ' ' + entry;
  6599. });
  6600. }
  6601.  
  6602. var hunks = [];
  6603. var oldRangeStart = 0,
  6604. newRangeStart = 0,
  6605. curRange = [],
  6606. oldLine = 1,
  6607. newLine = 1;
  6608.  
  6609. var _loop = function _loop(i) {
  6610. var current = diff[i],
  6611. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  6612. current.lines = lines;
  6613.  
  6614. if (current.added || current.removed) {
  6615. var _curRange;
  6616.  
  6617. // If we have previous context, start with that
  6618. if (!oldRangeStart) {
  6619. var prev = diff[i - 1];
  6620. oldRangeStart = oldLine;
  6621. newRangeStart = newLine;
  6622.  
  6623. if (prev) {
  6624. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  6625. oldRangeStart -= curRange.length;
  6626. newRangeStart -= curRange.length;
  6627. }
  6628. } // Output our changes
  6629.  
  6630.  
  6631. (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
  6632. return (current.added ? '+' : '-') + entry;
  6633. }))); // Track the updated file position
  6634.  
  6635.  
  6636. if (current.added) {
  6637. newLine += lines.length;
  6638. } else {
  6639. oldLine += lines.length;
  6640. }
  6641. } else {
  6642. // Identical context lines. Track line changes
  6643. if (oldRangeStart) {
  6644. // Close out any changes that have been output (or join overlapping)
  6645. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  6646. var _curRange2;
  6647.  
  6648. // Overlapping
  6649. (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
  6650. } else {
  6651. var _curRange3;
  6652.  
  6653. // end the range and output
  6654. var contextSize = Math.min(lines.length, options.context);
  6655.  
  6656. (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
  6657.  
  6658. var hunk = {
  6659. oldStart: oldRangeStart,
  6660. oldLines: oldLine - oldRangeStart + contextSize,
  6661. newStart: newRangeStart,
  6662. newLines: newLine - newRangeStart + contextSize,
  6663. lines: curRange
  6664. };
  6665.  
  6666. if (i >= diff.length - 2 && lines.length <= options.context) {
  6667. // EOF is inside this hunk
  6668. var oldEOFNewline = /\n$/.test(oldStr);
  6669. var newEOFNewline = /\n$/.test(newStr);
  6670. var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
  6671.  
  6672. if (!oldEOFNewline && noNlBeforeAdds) {
  6673. // special case: old has no eol and no trailing context; no-nl can end up before adds
  6674. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  6675. }
  6676.  
  6677. if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
  6678. curRange.push('\\ No newline at end of file');
  6679. }
  6680. }
  6681.  
  6682. hunks.push(hunk);
  6683. oldRangeStart = 0;
  6684. newRangeStart = 0;
  6685. curRange = [];
  6686. }
  6687. }
  6688.  
  6689. oldLine += lines.length;
  6690. newLine += lines.length;
  6691. }
  6692. };
  6693.  
  6694. for (var i = 0; i < diff.length; i++) {
  6695. _loop(i);
  6696. }
  6697.  
  6698. return {
  6699. oldFileName: oldFileName,
  6700. newFileName: newFileName,
  6701. oldHeader: oldHeader,
  6702. newHeader: newHeader,
  6703. hunks: hunks
  6704. };
  6705. }
  6706. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  6707. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  6708. var ret = [];
  6709.  
  6710. if (oldFileName == newFileName) {
  6711. ret.push('Index: ' + oldFileName);
  6712. }
  6713.  
  6714. ret.push('===================================================================');
  6715. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  6716. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  6717.  
  6718. for (var i = 0; i < diff.hunks.length; i++) {
  6719. var hunk = diff.hunks[i];
  6720. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  6721. ret.push.apply(ret, hunk.lines);
  6722. }
  6723.  
  6724. return ret.join('\n') + '\n';
  6725. }
  6726. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  6727. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  6728. }
  6729.  
  6730. function arrayEqual(a, b) {
  6731. if (a.length !== b.length) {
  6732. return false;
  6733. }
  6734.  
  6735. return arrayStartsWith(a, b);
  6736. }
  6737. function arrayStartsWith(array, start) {
  6738. if (start.length > array.length) {
  6739. return false;
  6740. }
  6741.  
  6742. for (var i = 0; i < start.length; i++) {
  6743. if (start[i] !== array[i]) {
  6744. return false;
  6745. }
  6746. }
  6747.  
  6748. return true;
  6749. }
  6750.  
  6751. function calcLineCount(hunk) {
  6752. var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
  6753. oldLines = _calcOldNewLineCount.oldLines,
  6754. newLines = _calcOldNewLineCount.newLines;
  6755.  
  6756. if (oldLines !== undefined) {
  6757. hunk.oldLines = oldLines;
  6758. } else {
  6759. delete hunk.oldLines;
  6760. }
  6761.  
  6762. if (newLines !== undefined) {
  6763. hunk.newLines = newLines;
  6764. } else {
  6765. delete hunk.newLines;
  6766. }
  6767. }
  6768. function merge(mine, theirs, base) {
  6769. mine = loadPatch(mine, base);
  6770. theirs = loadPatch(theirs, base);
  6771. var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
  6772. // Leaving sanity checks on this to the API consumer that may know more about the
  6773. // meaning in their own context.
  6774.  
  6775. if (mine.index || theirs.index) {
  6776. ret.index = mine.index || theirs.index;
  6777. }
  6778.  
  6779. if (mine.newFileName || theirs.newFileName) {
  6780. if (!fileNameChanged(mine)) {
  6781. // No header or no change in ours, use theirs (and ours if theirs does not exist)
  6782. ret.oldFileName = theirs.oldFileName || mine.oldFileName;
  6783. ret.newFileName = theirs.newFileName || mine.newFileName;
  6784. ret.oldHeader = theirs.oldHeader || mine.oldHeader;
  6785. ret.newHeader = theirs.newHeader || mine.newHeader;
  6786. } else if (!fileNameChanged(theirs)) {
  6787. // No header or no change in theirs, use ours
  6788. ret.oldFileName = mine.oldFileName;
  6789. ret.newFileName = mine.newFileName;
  6790. ret.oldHeader = mine.oldHeader;
  6791. ret.newHeader = mine.newHeader;
  6792. } else {
  6793. // Both changed... figure it out
  6794. ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
  6795. ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
  6796. ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
  6797. ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
  6798. }
  6799. }
  6800.  
  6801. ret.hunks = [];
  6802. var mineIndex = 0,
  6803. theirsIndex = 0,
  6804. mineOffset = 0,
  6805. theirsOffset = 0;
  6806.  
  6807. while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
  6808. var mineCurrent = mine.hunks[mineIndex] || {
  6809. oldStart: Infinity
  6810. },
  6811. theirsCurrent = theirs.hunks[theirsIndex] || {
  6812. oldStart: Infinity
  6813. };
  6814.  
  6815. if (hunkBefore(mineCurrent, theirsCurrent)) {
  6816. // This patch does not overlap with any of the others, yay.
  6817. ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
  6818. mineIndex++;
  6819. theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
  6820. } else if (hunkBefore(theirsCurrent, mineCurrent)) {
  6821. // This patch does not overlap with any of the others, yay.
  6822. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
  6823. theirsIndex++;
  6824. mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
  6825. } else {
  6826. // Overlap, merge as best we can
  6827. var mergedHunk = {
  6828. oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
  6829. oldLines: 0,
  6830. newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
  6831. newLines: 0,
  6832. lines: []
  6833. };
  6834. mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
  6835. theirsIndex++;
  6836. mineIndex++;
  6837. ret.hunks.push(mergedHunk);
  6838. }
  6839. }
  6840.  
  6841. return ret;
  6842. }
  6843.  
  6844. function loadPatch(param, base) {
  6845. if (typeof param === 'string') {
  6846. if (/^@@/m.test(param) || /^Index:/m.test(param)) {
  6847. return parsePatch(param)[0];
  6848. }
  6849.  
  6850. if (!base) {
  6851. throw new Error('Must provide a base reference or pass in a patch');
  6852. }
  6853.  
  6854. return structuredPatch(undefined, undefined, base, param);
  6855. }
  6856.  
  6857. return param;
  6858. }
  6859.  
  6860. function fileNameChanged(patch) {
  6861. return patch.newFileName && patch.newFileName !== patch.oldFileName;
  6862. }
  6863.  
  6864. function selectField(index, mine, theirs) {
  6865. if (mine === theirs) {
  6866. return mine;
  6867. } else {
  6868. index.conflict = true;
  6869. return {
  6870. mine: mine,
  6871. theirs: theirs
  6872. };
  6873. }
  6874. }
  6875.  
  6876. function hunkBefore(test, check) {
  6877. return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
  6878. }
  6879.  
  6880. function cloneHunk(hunk, offset) {
  6881. return {
  6882. oldStart: hunk.oldStart,
  6883. oldLines: hunk.oldLines,
  6884. newStart: hunk.newStart + offset,
  6885. newLines: hunk.newLines,
  6886. lines: hunk.lines
  6887. };
  6888. }
  6889.  
  6890. function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
  6891. // This will generally result in a conflicted hunk, but there are cases where the context
  6892. // is the only overlap where we can successfully merge the content here.
  6893. var mine = {
  6894. offset: mineOffset,
  6895. lines: mineLines,
  6896. index: 0
  6897. },
  6898. their = {
  6899. offset: theirOffset,
  6900. lines: theirLines,
  6901. index: 0
  6902. }; // Handle any leading content
  6903.  
  6904. insertLeading(hunk, mine, their);
  6905. insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
  6906.  
  6907. while (mine.index < mine.lines.length && their.index < their.lines.length) {
  6908. var mineCurrent = mine.lines[mine.index],
  6909. theirCurrent = their.lines[their.index];
  6910.  
  6911. if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
  6912. // Both modified ...
  6913. mutualChange(hunk, mine, their);
  6914. } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
  6915. var _hunk$lines;
  6916.  
  6917. // Mine inserted
  6918. (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
  6919. } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
  6920. var _hunk$lines2;
  6921.  
  6922. // Theirs inserted
  6923. (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
  6924. } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
  6925. // Mine removed or edited
  6926. removal(hunk, mine, their);
  6927. } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
  6928. // Their removed or edited
  6929. removal(hunk, their, mine, true);
  6930. } else if (mineCurrent === theirCurrent) {
  6931. // Context identity
  6932. hunk.lines.push(mineCurrent);
  6933. mine.index++;
  6934. their.index++;
  6935. } else {
  6936. // Context mismatch
  6937. conflict(hunk, collectChange(mine), collectChange(their));
  6938. }
  6939. } // Now push anything that may be remaining
  6940.  
  6941.  
  6942. insertTrailing(hunk, mine);
  6943. insertTrailing(hunk, their);
  6944. calcLineCount(hunk);
  6945. }
  6946.  
  6947. function mutualChange(hunk, mine, their) {
  6948. var myChanges = collectChange(mine),
  6949. theirChanges = collectChange(their);
  6950.  
  6951. if (allRemoves(myChanges) && allRemoves(theirChanges)) {
  6952. // Special case for remove changes that are supersets of one another
  6953. if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
  6954. var _hunk$lines3;
  6955.  
  6956. (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
  6957.  
  6958. return;
  6959. } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
  6960. var _hunk$lines4;
  6961.  
  6962. (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
  6963.  
  6964. return;
  6965. }
  6966. } else if (arrayEqual(myChanges, theirChanges)) {
  6967. var _hunk$lines5;
  6968.  
  6969. (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
  6970.  
  6971. return;
  6972. }
  6973.  
  6974. conflict(hunk, myChanges, theirChanges);
  6975. }
  6976.  
  6977. function removal(hunk, mine, their, swap) {
  6978. var myChanges = collectChange(mine),
  6979. theirChanges = collectContext(their, myChanges);
  6980.  
  6981. if (theirChanges.merged) {
  6982. var _hunk$lines6;
  6983.  
  6984. (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
  6985. } else {
  6986. conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
  6987. }
  6988. }
  6989.  
  6990. function conflict(hunk, mine, their) {
  6991. hunk.conflict = true;
  6992. hunk.lines.push({
  6993. conflict: true,
  6994. mine: mine,
  6995. theirs: their
  6996. });
  6997. }
  6998.  
  6999. function insertLeading(hunk, insert, their) {
  7000. while (insert.offset < their.offset && insert.index < insert.lines.length) {
  7001. var line = insert.lines[insert.index++];
  7002. hunk.lines.push(line);
  7003. insert.offset++;
  7004. }
  7005. }
  7006.  
  7007. function insertTrailing(hunk, insert) {
  7008. while (insert.index < insert.lines.length) {
  7009. var line = insert.lines[insert.index++];
  7010. hunk.lines.push(line);
  7011. }
  7012. }
  7013.  
  7014. function collectChange(state) {
  7015. var ret = [],
  7016. operation = state.lines[state.index][0];
  7017.  
  7018. while (state.index < state.lines.length) {
  7019. var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
  7020.  
  7021. if (operation === '-' && line[0] === '+') {
  7022. operation = '+';
  7023. }
  7024.  
  7025. if (operation === line[0]) {
  7026. ret.push(line);
  7027. state.index++;
  7028. } else {
  7029. break;
  7030. }
  7031. }
  7032.  
  7033. return ret;
  7034. }
  7035.  
  7036. function collectContext(state, matchChanges) {
  7037. var changes = [],
  7038. merged = [],
  7039. matchIndex = 0,
  7040. contextChanges = false,
  7041. conflicted = false;
  7042.  
  7043. while (matchIndex < matchChanges.length && state.index < state.lines.length) {
  7044. var change = state.lines[state.index],
  7045. match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
  7046.  
  7047. if (match[0] === '+') {
  7048. break;
  7049. }
  7050.  
  7051. contextChanges = contextChanges || change[0] !== ' ';
  7052. merged.push(match);
  7053. matchIndex++; // Consume any additions in the other block as a conflict to attempt
  7054. // to pull in the remaining context after this
  7055.  
  7056. if (change[0] === '+') {
  7057. conflicted = true;
  7058.  
  7059. while (change[0] === '+') {
  7060. changes.push(change);
  7061. change = state.lines[++state.index];
  7062. }
  7063. }
  7064.  
  7065. if (match.substr(1) === change.substr(1)) {
  7066. changes.push(change);
  7067. state.index++;
  7068. } else {
  7069. conflicted = true;
  7070. }
  7071. }
  7072.  
  7073. if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
  7074. conflicted = true;
  7075. }
  7076.  
  7077. if (conflicted) {
  7078. return changes;
  7079. }
  7080.  
  7081. while (matchIndex < matchChanges.length) {
  7082. merged.push(matchChanges[matchIndex++]);
  7083. }
  7084.  
  7085. return {
  7086. merged: merged,
  7087. changes: changes
  7088. };
  7089. }
  7090.  
  7091. function allRemoves(changes) {
  7092. return changes.reduce(function (prev, change) {
  7093. return prev && change[0] === '-';
  7094. }, true);
  7095. }
  7096.  
  7097. function skipRemoveSuperset(state, removeChanges, delta) {
  7098. for (var i = 0; i < delta; i++) {
  7099. var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
  7100.  
  7101. if (state.lines[state.index + i] !== ' ' + changeContent) {
  7102. return false;
  7103. }
  7104. }
  7105.  
  7106. state.index += delta;
  7107. return true;
  7108. }
  7109.  
  7110. function calcOldNewLineCount(lines) {
  7111. var oldLines = 0;
  7112. var newLines = 0;
  7113. lines.forEach(function (line) {
  7114. if (typeof line !== 'string') {
  7115. var myCount = calcOldNewLineCount(line.mine);
  7116. var theirCount = calcOldNewLineCount(line.theirs);
  7117.  
  7118. if (oldLines !== undefined) {
  7119. if (myCount.oldLines === theirCount.oldLines) {
  7120. oldLines += myCount.oldLines;
  7121. } else {
  7122. oldLines = undefined;
  7123. }
  7124. }
  7125.  
  7126. if (newLines !== undefined) {
  7127. if (myCount.newLines === theirCount.newLines) {
  7128. newLines += myCount.newLines;
  7129. } else {
  7130. newLines = undefined;
  7131. }
  7132. }
  7133. } else {
  7134. if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
  7135. newLines++;
  7136. }
  7137.  
  7138. if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
  7139. oldLines++;
  7140. }
  7141. }
  7142. });
  7143. return {
  7144. oldLines: oldLines,
  7145. newLines: newLines
  7146. };
  7147. }
  7148.  
  7149. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  7150. function convertChangesToDMP(changes) {
  7151. var ret = [],
  7152. change,
  7153. operation;
  7154.  
  7155. for (var i = 0; i < changes.length; i++) {
  7156. change = changes[i];
  7157.  
  7158. if (change.added) {
  7159. operation = 1;
  7160. } else if (change.removed) {
  7161. operation = -1;
  7162. } else {
  7163. operation = 0;
  7164. }
  7165.  
  7166. ret.push([operation, change.value]);
  7167. }
  7168.  
  7169. return ret;
  7170. }
  7171.  
  7172. function convertChangesToXML(changes) {
  7173. var ret = [];
  7174.  
  7175. for (var i = 0; i < changes.length; i++) {
  7176. var change = changes[i];
  7177.  
  7178. if (change.added) {
  7179. ret.push('<ins>');
  7180. } else if (change.removed) {
  7181. ret.push('<del>');
  7182. }
  7183.  
  7184. ret.push(escapeHTML(change.value));
  7185.  
  7186. if (change.added) {
  7187. ret.push('</ins>');
  7188. } else if (change.removed) {
  7189. ret.push('</del>');
  7190. }
  7191. }
  7192.  
  7193. return ret.join('');
  7194. }
  7195.  
  7196. function escapeHTML(s) {
  7197. var n = s;
  7198. n = n.replace(/&/g, '&amp;');
  7199. n = n.replace(/</g, '&lt;');
  7200. n = n.replace(/>/g, '&gt;');
  7201. n = n.replace(/"/g, '&quot;');
  7202. return n;
  7203. }
  7204.  
  7205. /* See LICENSE file for terms of use */
  7206.  
  7207. exports.Diff = Diff;
  7208. exports.diffChars = diffChars;
  7209. exports.diffWords = diffWords;
  7210. exports.diffWordsWithSpace = diffWordsWithSpace;
  7211. exports.diffLines = diffLines;
  7212. exports.diffTrimmedLines = diffTrimmedLines;
  7213. exports.diffSentences = diffSentences;
  7214. exports.diffCss = diffCss;
  7215. exports.diffJson = diffJson;
  7216. exports.diffArrays = diffArrays;
  7217. exports.structuredPatch = structuredPatch;
  7218. exports.createTwoFilesPatch = createTwoFilesPatch;
  7219. exports.createPatch = createPatch;
  7220. exports.applyPatch = applyPatch;
  7221. exports.applyPatches = applyPatches;
  7222. exports.parsePatch = parsePatch;
  7223. exports.merge = merge;
  7224. exports.convertChangesToDMP = convertChangesToDMP;
  7225. exports.convertChangesToXML = convertChangesToXML;
  7226. exports.canonicalize = canonicalize;
  7227.  
  7228. Object.defineProperty(exports, '__esModule', { value: true });
  7229.  
  7230. }));
  7231.  
  7232.  
  7233. /***/ }),
  7234.  
  7235. /***/ "xeH2":
  7236. /***/ (function(module, exports) {
  7237.  
  7238. module.exports = $;
  7239.  
  7240. /***/ }),
  7241.  
  7242. /***/ "yLpj":
  7243. /***/ (function(module, exports) {
  7244.  
  7245. var g;
  7246.  
  7247. // This works in non-strict mode
  7248. g = (function() {
  7249. return this;
  7250. })();
  7251.  
  7252. try {
  7253. // This works if eval is allowed (see CSP)
  7254. g = g || new Function("return this")();
  7255. } catch (e) {
  7256. // This works if the window reference is available
  7257. if (typeof window === "object") g = window;
  7258. }
  7259.  
  7260. // g can still be undefined, but nothing to do about it...
  7261. // We return undefined, instead of nothing here, so it's
  7262. // easier to handle this case. if(!global) { ...}
  7263.  
  7264. module.exports = g;
  7265.  
  7266.  
  7267. /***/ })
  7268.  
  7269. /******/ });