@forsakringskassan/docs-generator 2.27.2 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16325,11 +16325,11 @@ function requireRegisterTs () {
16325
16325
 
16326
16326
  requireRegisterTs();
16327
16327
 
16328
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16329
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16330
- function _defineProperty$1(obj, key, value) { key = _toPropertyKey$1(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16331
- function _toPropertyKey$1(arg) { var key = _toPrimitive$1(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16332
- function _toPrimitive$1(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16328
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16329
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16330
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16331
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
16332
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16333
16333
  const dedent = createDedent({});
16334
16334
  function createDedent(options) {
16335
16335
  dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
@@ -28558,366 +28558,425 @@ function deflist_plugin (md) {
28558
28558
  md.block.ruler.before('paragraph', 'deflist', deflist, { alt: ['paragraph', 'reference', 'blockquote'] });
28559
28559
  }
28560
28560
 
28561
- function Diff() {}
28562
- Diff.prototype = {
28563
- diff: function diff(oldString, newString) {
28564
- var _options$timeout;
28565
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
28566
- var callback = options.callback;
28567
- if (typeof options === 'function') {
28568
- callback = options;
28569
- options = {};
28570
- }
28571
- var self = this;
28572
- function done(value) {
28573
- value = self.postProcess(value, options);
28574
- if (callback) {
28575
- setTimeout(function () {
28576
- callback(value);
28577
- }, 0);
28578
- return true;
28579
- } else {
28580
- return value;
28581
- }
28561
+ var Diff = /** @class */ (function () {
28562
+ function Diff() {
28582
28563
  }
28583
-
28584
- // Allow subclasses to massage the input prior to running
28585
- oldString = this.castInput(oldString, options);
28586
- newString = this.castInput(newString, options);
28587
- oldString = this.removeEmpty(this.tokenize(oldString, options));
28588
- newString = this.removeEmpty(this.tokenize(newString, options));
28589
- var newLen = newString.length,
28590
- oldLen = oldString.length;
28591
- var editLength = 1;
28592
- var maxEditLength = newLen + oldLen;
28593
- if (options.maxEditLength != null) {
28594
- maxEditLength = Math.min(maxEditLength, options.maxEditLength);
28595
- }
28596
- var maxExecutionTime = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : Infinity;
28597
- var abortAfterTimestamp = Date.now() + maxExecutionTime;
28598
- var bestPath = [{
28599
- oldPos: -1,
28600
- lastComponent: undefined
28601
- }];
28602
-
28603
- // Seed editLength = 0, i.e. the content starts with the same values
28604
- var newPos = this.extractCommon(bestPath[0], newString, oldString, 0, options);
28605
- if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28606
- // Identity per the equality and tokenizer
28607
- return done(buildValues(self, bestPath[0].lastComponent, newString, oldString, self.useLongestToken));
28608
- }
28609
-
28610
- // Once we hit the right edge of the edit graph on some diagonal k, we can
28611
- // definitely reach the end of the edit graph in no more than k edits, so
28612
- // there's no point in considering any moves to diagonal k+1 any more (from
28613
- // which we're guaranteed to need at least k+1 more edits).
28614
- // Similarly, once we've reached the bottom of the edit graph, there's no
28615
- // point considering moves to lower diagonals.
28616
- // We record this fact by setting minDiagonalToConsider and
28617
- // maxDiagonalToConsider to some finite value once we've hit the edge of
28618
- // the edit graph.
28619
- // This optimization is not faithful to the original algorithm presented in
28620
- // Myers's paper, which instead pointlessly extends D-paths off the end of
28621
- // the edit graph - see page 7 of Myers's paper which notes this point
28622
- // explicitly and illustrates it with a diagram. This has major performance
28623
- // implications for some common scenarios. For instance, to compute a diff
28624
- // where the new text simply appends d characters on the end of the
28625
- // original text of length n, the true Myers algorithm will take O(n+d^2)
28626
- // time while this optimization needs only O(n+d) time.
28627
- var minDiagonalToConsider = -Infinity,
28628
- maxDiagonalToConsider = Infinity;
28629
-
28630
- // Main worker method. checks all permutations of a given edit length for acceptance.
28631
- function execEditLength() {
28632
- for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
28633
- var basePath = void 0;
28634
- var removePath = bestPath[diagonalPath - 1],
28635
- addPath = bestPath[diagonalPath + 1];
28636
- if (removePath) {
28637
- // No one else is going to attempt to use this value, clear it
28638
- bestPath[diagonalPath - 1] = undefined;
28639
- }
28640
- var canAdd = false;
28641
- if (addPath) {
28642
- // what newPos will be after we do an insertion:
28643
- var addPathNewPos = addPath.oldPos - diagonalPath;
28644
- canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
28645
- }
28646
- var canRemove = removePath && removePath.oldPos + 1 < oldLen;
28647
- if (!canAdd && !canRemove) {
28648
- // If this path is a terminal then prune
28649
- bestPath[diagonalPath] = undefined;
28650
- continue;
28564
+ Diff.prototype.diff = function (oldString, newString,
28565
+ // Type below is not accurate/complete - see above for full possibilities - but it compiles
28566
+ options) {
28567
+ if (options === void 0) { options = {}; }
28568
+ var callback;
28569
+ if (typeof options === 'function') {
28570
+ callback = options;
28571
+ options = {};
28651
28572
  }
28652
-
28653
- // Select the diagonal that we want to branch from. We select the prior
28654
- // path whose position in the old string is the farthest from the origin
28655
- // and does not pass the bounds of the diff graph
28656
- if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
28657
- basePath = self.addToPath(addPath, true, false, 0, options);
28658
- } else {
28659
- basePath = self.addToPath(removePath, false, true, 1, options);
28573
+ else if ('callback' in options) {
28574
+ callback = options.callback;
28660
28575
  }
28661
- newPos = self.extractCommon(basePath, newString, oldString, diagonalPath, options);
28662
- if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28663
- // If we have hit the end of both strings, then we are done
28664
- return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken));
28665
- } else {
28666
- bestPath[diagonalPath] = basePath;
28667
- if (basePath.oldPos + 1 >= oldLen) {
28668
- maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
28669
- }
28670
- if (newPos + 1 >= newLen) {
28671
- minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
28672
- }
28576
+ // Allow subclasses to massage the input prior to running
28577
+ oldString = this.castInput(oldString, options);
28578
+ newString = this.castInput(newString, options);
28579
+ var oldTokens = this.removeEmpty(this.tokenize(oldString, options));
28580
+ var newTokens = this.removeEmpty(this.tokenize(newString, options));
28581
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
28582
+ };
28583
+ Diff.prototype.diffWithOptionsObj = function (oldTokens, newTokens, options, callback) {
28584
+ var _this = this;
28585
+ var _a;
28586
+ var done = function (value) {
28587
+ value = _this.postProcess(value, options);
28588
+ if (callback) {
28589
+ setTimeout(function () { callback(value); }, 0);
28590
+ return undefined;
28591
+ }
28592
+ else {
28593
+ return value;
28594
+ }
28595
+ };
28596
+ var newLen = newTokens.length, oldLen = oldTokens.length;
28597
+ var editLength = 1;
28598
+ var maxEditLength = newLen + oldLen;
28599
+ if (options.maxEditLength != null) {
28600
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
28601
+ }
28602
+ var maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
28603
+ var abortAfterTimestamp = Date.now() + maxExecutionTime;
28604
+ var bestPath = [{ oldPos: -1, lastComponent: undefined }];
28605
+ // Seed editLength = 0, i.e. the content starts with the same values
28606
+ var newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
28607
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28608
+ // Identity per the equality and tokenizer
28609
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
28610
+ }
28611
+ // Once we hit the right edge of the edit graph on some diagonal k, we can
28612
+ // definitely reach the end of the edit graph in no more than k edits, so
28613
+ // there's no point in considering any moves to diagonal k+1 any more (from
28614
+ // which we're guaranteed to need at least k+1 more edits).
28615
+ // Similarly, once we've reached the bottom of the edit graph, there's no
28616
+ // point considering moves to lower diagonals.
28617
+ // We record this fact by setting minDiagonalToConsider and
28618
+ // maxDiagonalToConsider to some finite value once we've hit the edge of
28619
+ // the edit graph.
28620
+ // This optimization is not faithful to the original algorithm presented in
28621
+ // Myers's paper, which instead pointlessly extends D-paths off the end of
28622
+ // the edit graph - see page 7 of Myers's paper which notes this point
28623
+ // explicitly and illustrates it with a diagram. This has major performance
28624
+ // implications for some common scenarios. For instance, to compute a diff
28625
+ // where the new text simply appends d characters on the end of the
28626
+ // original text of length n, the true Myers algorithm will take O(n+d^2)
28627
+ // time while this optimization needs only O(n+d) time.
28628
+ var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
28629
+ // Main worker method. checks all permutations of a given edit length for acceptance.
28630
+ var execEditLength = function () {
28631
+ for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
28632
+ var basePath = void 0;
28633
+ var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
28634
+ if (removePath) {
28635
+ // No one else is going to attempt to use this value, clear it
28636
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
28637
+ bestPath[diagonalPath - 1] = undefined;
28638
+ }
28639
+ var canAdd = false;
28640
+ if (addPath) {
28641
+ // what newPos will be after we do an insertion:
28642
+ var addPathNewPos = addPath.oldPos - diagonalPath;
28643
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
28644
+ }
28645
+ var canRemove = removePath && removePath.oldPos + 1 < oldLen;
28646
+ if (!canAdd && !canRemove) {
28647
+ // If this path is a terminal then prune
28648
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
28649
+ bestPath[diagonalPath] = undefined;
28650
+ continue;
28651
+ }
28652
+ // Select the diagonal that we want to branch from. We select the prior
28653
+ // path whose position in the old string is the farthest from the origin
28654
+ // and does not pass the bounds of the diff graph
28655
+ if (!canRemove || (canAdd && removePath.oldPos < addPath.oldPos)) {
28656
+ basePath = _this.addToPath(addPath, true, false, 0, options);
28657
+ }
28658
+ else {
28659
+ basePath = _this.addToPath(removePath, false, true, 1, options);
28660
+ }
28661
+ newPos = _this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
28662
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28663
+ // If we have hit the end of both strings, then we are done
28664
+ return done(_this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
28665
+ }
28666
+ else {
28667
+ bestPath[diagonalPath] = basePath;
28668
+ if (basePath.oldPos + 1 >= oldLen) {
28669
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
28670
+ }
28671
+ if (newPos + 1 >= newLen) {
28672
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
28673
+ }
28674
+ }
28675
+ }
28676
+ editLength++;
28677
+ };
28678
+ // Performs the length of edit iteration. Is a bit fugly as this has to support the
28679
+ // sync and async mode which is never fun. Loops over execEditLength until a value
28680
+ // is produced, or until the edit length exceeds options.maxEditLength (if given),
28681
+ // in which case it will return undefined.
28682
+ if (callback) {
28683
+ (function exec() {
28684
+ setTimeout(function () {
28685
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
28686
+ return callback(undefined);
28687
+ }
28688
+ if (!execEditLength()) {
28689
+ exec();
28690
+ }
28691
+ }, 0);
28692
+ }());
28673
28693
  }
28674
- }
28675
- editLength++;
28676
- }
28677
-
28678
- // Performs the length of edit iteration. Is a bit fugly as this has to support the
28679
- // sync and async mode which is never fun. Loops over execEditLength until a value
28680
- // is produced, or until the edit length exceeds options.maxEditLength (if given),
28681
- // in which case it will return undefined.
28682
- if (callback) {
28683
- (function exec() {
28684
- setTimeout(function () {
28685
- if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
28686
- return callback();
28687
- }
28688
- if (!execEditLength()) {
28689
- exec();
28690
- }
28691
- }, 0);
28692
- })();
28693
- } else {
28694
- while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
28695
- var ret = execEditLength();
28696
- if (ret) {
28697
- return ret;
28694
+ else {
28695
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
28696
+ var ret = execEditLength();
28697
+ if (ret) {
28698
+ return ret;
28699
+ }
28700
+ }
28698
28701
  }
28699
- }
28700
- }
28701
- },
28702
- addToPath: function addToPath(path, added, removed, oldPosInc, options) {
28703
- var last = path.lastComponent;
28704
- if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
28705
- return {
28706
- oldPos: path.oldPos + oldPosInc,
28707
- lastComponent: {
28708
- count: last.count + 1,
28709
- added: added,
28710
- removed: removed,
28711
- previousComponent: last.previousComponent
28702
+ };
28703
+ Diff.prototype.addToPath = function (path, added, removed, oldPosInc, options) {
28704
+ var last = path.lastComponent;
28705
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
28706
+ return {
28707
+ oldPos: path.oldPos + oldPosInc,
28708
+ lastComponent: { count: last.count + 1, added: added, removed: removed, previousComponent: last.previousComponent }
28709
+ };
28712
28710
  }
28713
- };
28714
- } else {
28715
- return {
28716
- oldPos: path.oldPos + oldPosInc,
28717
- lastComponent: {
28718
- count: 1,
28719
- added: added,
28720
- removed: removed,
28721
- previousComponent: last
28711
+ else {
28712
+ return {
28713
+ oldPos: path.oldPos + oldPosInc,
28714
+ lastComponent: { count: 1, added: added, removed: removed, previousComponent: last }
28715
+ };
28722
28716
  }
28723
- };
28724
- }
28725
- },
28726
- extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath, options) {
28727
- var newLen = newString.length,
28728
- oldLen = oldString.length,
28729
- oldPos = basePath.oldPos,
28730
- newPos = oldPos - diagonalPath,
28731
- commonCount = 0;
28732
- while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldString[oldPos + 1], newString[newPos + 1], options)) {
28733
- newPos++;
28734
- oldPos++;
28735
- commonCount++;
28736
- if (options.oneChangePerToken) {
28737
- basePath.lastComponent = {
28738
- count: 1,
28739
- previousComponent: basePath.lastComponent,
28740
- added: false,
28741
- removed: false
28742
- };
28743
- }
28744
- }
28745
- if (commonCount && !options.oneChangePerToken) {
28746
- basePath.lastComponent = {
28747
- count: commonCount,
28748
- previousComponent: basePath.lastComponent,
28749
- added: false,
28750
- removed: false
28751
- };
28752
- }
28753
- basePath.oldPos = oldPos;
28754
- return newPos;
28755
- },
28756
- equals: function equals(left, right, options) {
28757
- if (options.comparator) {
28758
- return options.comparator(left, right);
28759
- } else {
28760
- return left === right || options.ignoreCase && left.toLowerCase() === right.toLowerCase();
28761
- }
28762
- },
28763
- removeEmpty: function removeEmpty(array) {
28764
- var ret = [];
28765
- for (var i = 0; i < array.length; i++) {
28766
- if (array[i]) {
28767
- ret.push(array[i]);
28768
- }
28769
- }
28770
- return ret;
28771
- },
28772
- castInput: function castInput(value) {
28773
- return value;
28774
- },
28775
- tokenize: function tokenize(value) {
28776
- return Array.from(value);
28777
- },
28778
- join: function join(chars) {
28779
- return chars.join('');
28780
- },
28781
- postProcess: function postProcess(changeObjects) {
28782
- return changeObjects;
28783
- }
28784
- };
28785
- function buildValues(diff, lastComponent, newString, oldString, useLongestToken) {
28786
- // First we convert our linked list of components in reverse order to an
28787
- // array in the right order:
28788
- var components = [];
28789
- var nextComponent;
28790
- while (lastComponent) {
28791
- components.push(lastComponent);
28792
- nextComponent = lastComponent.previousComponent;
28793
- delete lastComponent.previousComponent;
28794
- lastComponent = nextComponent;
28795
- }
28796
- components.reverse();
28797
- var componentPos = 0,
28798
- componentLen = components.length,
28799
- newPos = 0,
28800
- oldPos = 0;
28801
- for (; componentPos < componentLen; componentPos++) {
28802
- var component = components[componentPos];
28803
- if (!component.removed) {
28804
- if (!component.added && useLongestToken) {
28805
- var value = newString.slice(newPos, newPos + component.count);
28806
- value = value.map(function (value, i) {
28807
- var oldValue = oldString[oldPos + i];
28808
- return oldValue.length > value.length ? oldValue : value;
28809
- });
28810
- component.value = diff.join(value);
28811
- } else {
28812
- component.value = diff.join(newString.slice(newPos, newPos + component.count));
28813
- }
28814
- newPos += component.count;
28815
-
28816
- // Common case
28817
- if (!component.added) {
28818
- oldPos += component.count;
28819
- }
28820
- } else {
28821
- component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
28822
- oldPos += component.count;
28717
+ };
28718
+ Diff.prototype.extractCommon = function (basePath, newTokens, oldTokens, diagonalPath, options) {
28719
+ var newLen = newTokens.length, oldLen = oldTokens.length;
28720
+ var oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
28721
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
28722
+ newPos++;
28723
+ oldPos++;
28724
+ commonCount++;
28725
+ if (options.oneChangePerToken) {
28726
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
28727
+ }
28728
+ }
28729
+ if (commonCount && !options.oneChangePerToken) {
28730
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
28731
+ }
28732
+ basePath.oldPos = oldPos;
28733
+ return newPos;
28734
+ };
28735
+ Diff.prototype.equals = function (left, right, options) {
28736
+ if (options.comparator) {
28737
+ return options.comparator(left, right);
28738
+ }
28739
+ else {
28740
+ return left === right
28741
+ || (!!options.ignoreCase && left.toLowerCase() === right.toLowerCase());
28742
+ }
28743
+ };
28744
+ Diff.prototype.removeEmpty = function (array) {
28745
+ var ret = [];
28746
+ for (var i = 0; i < array.length; i++) {
28747
+ if (array[i]) {
28748
+ ret.push(array[i]);
28749
+ }
28750
+ }
28751
+ return ret;
28752
+ };
28753
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28754
+ Diff.prototype.castInput = function (value, options) {
28755
+ return value;
28756
+ };
28757
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28758
+ Diff.prototype.tokenize = function (value, options) {
28759
+ return Array.from(value);
28760
+ };
28761
+ Diff.prototype.join = function (chars) {
28762
+ // Assumes ValueT is string, which is the case for most subclasses.
28763
+ // When it's false, e.g. in diffArrays, this method needs to be overridden (e.g. with a no-op)
28764
+ // Yes, the casts are verbose and ugly, because this pattern - of having the base class SORT OF
28765
+ // assume tokens and values are strings, but not completely - is weird and janky.
28766
+ return chars.join('');
28767
+ };
28768
+ Diff.prototype.postProcess = function (changeObjects,
28769
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28770
+ options) {
28771
+ return changeObjects;
28772
+ };
28773
+ Object.defineProperty(Diff.prototype, "useLongestToken", {
28774
+ get: function () {
28775
+ return false;
28776
+ },
28777
+ enumerable: false,
28778
+ configurable: true
28779
+ });
28780
+ Diff.prototype.buildValues = function (lastComponent, newTokens, oldTokens) {
28781
+ // First we convert our linked list of components in reverse order to an
28782
+ // array in the right order:
28783
+ var components = [];
28784
+ var nextComponent;
28785
+ while (lastComponent) {
28786
+ components.push(lastComponent);
28787
+ nextComponent = lastComponent.previousComponent;
28788
+ delete lastComponent.previousComponent;
28789
+ lastComponent = nextComponent;
28790
+ }
28791
+ components.reverse();
28792
+ var componentLen = components.length;
28793
+ var componentPos = 0, newPos = 0, oldPos = 0;
28794
+ for (; componentPos < componentLen; componentPos++) {
28795
+ var component = components[componentPos];
28796
+ if (!component.removed) {
28797
+ if (!component.added && this.useLongestToken) {
28798
+ var value = newTokens.slice(newPos, newPos + component.count);
28799
+ value = value.map(function (value, i) {
28800
+ var oldValue = oldTokens[oldPos + i];
28801
+ return oldValue.length > value.length ? oldValue : value;
28802
+ });
28803
+ component.value = this.join(value);
28804
+ }
28805
+ else {
28806
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
28807
+ }
28808
+ newPos += component.count;
28809
+ // Common case
28810
+ if (!component.added) {
28811
+ oldPos += component.count;
28812
+ }
28813
+ }
28814
+ else {
28815
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
28816
+ oldPos += component.count;
28817
+ }
28818
+ }
28819
+ return components;
28820
+ };
28821
+ return Diff;
28822
+ }());
28823
+
28824
+ var __extends$6 = (undefined && undefined.__extends) || (function () {
28825
+ var extendStatics = function (d, b) {
28826
+ extendStatics = Object.setPrototypeOf ||
28827
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28828
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28829
+ return extendStatics(d, b);
28830
+ };
28831
+ return function (d, b) {
28832
+ if (typeof b !== "function" && b !== null)
28833
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28834
+ extendStatics(d, b);
28835
+ function __() { this.constructor = d; }
28836
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28837
+ };
28838
+ })();
28839
+ var CharacterDiff = /** @class */ (function (_super) {
28840
+ __extends$6(CharacterDiff, _super);
28841
+ function CharacterDiff() {
28842
+ return _super !== null && _super.apply(this, arguments) || this;
28823
28843
  }
28824
- }
28825
- return components;
28826
- }
28844
+ return CharacterDiff;
28845
+ }(Diff));
28846
+ new CharacterDiff();
28827
28847
 
28828
28848
  function longestCommonPrefix(str1, str2) {
28829
- var i;
28830
- for (i = 0; i < str1.length && i < str2.length; i++) {
28831
- if (str1[i] != str2[i]) {
28832
- return str1.slice(0, i);
28849
+ var i;
28850
+ for (i = 0; i < str1.length && i < str2.length; i++) {
28851
+ if (str1[i] != str2[i]) {
28852
+ return str1.slice(0, i);
28853
+ }
28833
28854
  }
28834
- }
28835
- return str1.slice(0, i);
28855
+ return str1.slice(0, i);
28836
28856
  }
28837
28857
  function longestCommonSuffix(str1, str2) {
28838
- var i;
28839
-
28840
- // Unlike longestCommonPrefix, we need a special case to handle all scenarios
28841
- // where we return the empty string since str1.slice(-0) will return the
28842
- // entire string.
28843
- if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
28844
- return '';
28845
- }
28846
- for (i = 0; i < str1.length && i < str2.length; i++) {
28847
- if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
28848
- return str1.slice(-i);
28858
+ var i;
28859
+ // Unlike longestCommonPrefix, we need a special case to handle all scenarios
28860
+ // where we return the empty string since str1.slice(-0) will return the
28861
+ // entire string.
28862
+ if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
28863
+ return '';
28849
28864
  }
28850
- }
28851
- return str1.slice(-i);
28865
+ for (i = 0; i < str1.length && i < str2.length; i++) {
28866
+ if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
28867
+ return str1.slice(-i);
28868
+ }
28869
+ }
28870
+ return str1.slice(-i);
28852
28871
  }
28853
28872
  function replacePrefix(string, oldPrefix, newPrefix) {
28854
- if (string.slice(0, oldPrefix.length) != oldPrefix) {
28855
- throw Error("string ".concat(JSON.stringify(string), " doesn't start with prefix ").concat(JSON.stringify(oldPrefix), "; this is a bug"));
28856
- }
28857
- return newPrefix + string.slice(oldPrefix.length);
28873
+ if (string.slice(0, oldPrefix.length) != oldPrefix) {
28874
+ throw Error("string ".concat(JSON.stringify(string), " doesn't start with prefix ").concat(JSON.stringify(oldPrefix), "; this is a bug"));
28875
+ }
28876
+ return newPrefix + string.slice(oldPrefix.length);
28858
28877
  }
28859
28878
  function replaceSuffix(string, oldSuffix, newSuffix) {
28860
- if (!oldSuffix) {
28861
- return string + newSuffix;
28862
- }
28863
- if (string.slice(-oldSuffix.length) != oldSuffix) {
28864
- throw Error("string ".concat(JSON.stringify(string), " doesn't end with suffix ").concat(JSON.stringify(oldSuffix), "; this is a bug"));
28865
- }
28866
- return string.slice(0, -oldSuffix.length) + newSuffix;
28879
+ if (!oldSuffix) {
28880
+ return string + newSuffix;
28881
+ }
28882
+ if (string.slice(-oldSuffix.length) != oldSuffix) {
28883
+ throw Error("string ".concat(JSON.stringify(string), " doesn't end with suffix ").concat(JSON.stringify(oldSuffix), "; this is a bug"));
28884
+ }
28885
+ return string.slice(0, -oldSuffix.length) + newSuffix;
28867
28886
  }
28868
28887
  function removePrefix(string, oldPrefix) {
28869
- return replacePrefix(string, oldPrefix, '');
28888
+ return replacePrefix(string, oldPrefix, '');
28870
28889
  }
28871
28890
  function removeSuffix(string, oldSuffix) {
28872
- return replaceSuffix(string, oldSuffix, '');
28891
+ return replaceSuffix(string, oldSuffix, '');
28873
28892
  }
28874
28893
  function maximumOverlap(string1, string2) {
28875
- return string2.slice(0, overlapCount(string1, string2));
28894
+ return string2.slice(0, overlapCount(string1, string2));
28876
28895
  }
28877
-
28878
28896
  // Nicked from https://stackoverflow.com/a/60422853/1709587
28879
28897
  function overlapCount(a, b) {
28880
- // Deal with cases where the strings differ in length
28881
- var startA = 0;
28882
- if (a.length > b.length) {
28883
- startA = a.length - b.length;
28884
- }
28885
- var endB = b.length;
28886
- if (a.length < b.length) {
28887
- endB = a.length;
28888
- }
28889
- // Create a back-reference for each index
28890
- // that should be followed in case of a mismatch.
28891
- // We only need B to make these references:
28892
- var map = Array(endB);
28893
- var k = 0; // Index that lags behind j
28894
- map[0] = 0;
28895
- for (var j = 1; j < endB; j++) {
28896
- if (b[j] == b[k]) {
28897
- map[j] = map[k]; // skip over the same character (optional optimisation)
28898
- } else {
28899
- map[j] = k;
28898
+ // Deal with cases where the strings differ in length
28899
+ var startA = 0;
28900
+ if (a.length > b.length) {
28901
+ startA = a.length - b.length;
28900
28902
  }
28901
- while (k > 0 && b[j] != b[k]) {
28902
- k = map[k];
28903
- }
28904
- if (b[j] == b[k]) {
28905
- k++;
28906
- }
28907
- }
28908
- // Phase 2: use these references while iterating over A
28909
- k = 0;
28910
- for (var i = startA; i < a.length; i++) {
28911
- while (k > 0 && a[i] != b[k]) {
28912
- k = map[k];
28913
- }
28914
- if (a[i] == b[k]) {
28915
- k++;
28903
+ var endB = b.length;
28904
+ if (a.length < b.length) {
28905
+ endB = a.length;
28906
+ }
28907
+ // Create a back-reference for each index
28908
+ // that should be followed in case of a mismatch.
28909
+ // We only need B to make these references:
28910
+ var map = Array(endB);
28911
+ var k = 0; // Index that lags behind j
28912
+ map[0] = 0;
28913
+ for (var j = 1; j < endB; j++) {
28914
+ if (b[j] == b[k]) {
28915
+ map[j] = map[k]; // skip over the same character (optional optimisation)
28916
+ }
28917
+ else {
28918
+ map[j] = k;
28919
+ }
28920
+ while (k > 0 && b[j] != b[k]) {
28921
+ k = map[k];
28922
+ }
28923
+ if (b[j] == b[k]) {
28924
+ k++;
28925
+ }
28926
+ }
28927
+ // Phase 2: use these references while iterating over A
28928
+ k = 0;
28929
+ for (var i = startA; i < a.length; i++) {
28930
+ while (k > 0 && a[i] != b[k]) {
28931
+ k = map[k];
28932
+ }
28933
+ if (a[i] == b[k]) {
28934
+ k++;
28935
+ }
28936
+ }
28937
+ return k;
28938
+ }
28939
+ function trailingWs(string) {
28940
+ // Yes, this looks overcomplicated and dumb - why not replace the whole function with
28941
+ // return string match(/\s*$/)[0]
28942
+ // you ask? Because:
28943
+ // 1. the trap described at https://markamery.com/blog/quadratic-time-regexes/ would mean doing
28944
+ // this would cause this function to take O(n²) time in the worst case (specifically when
28945
+ // there is a massive run of NON-TRAILING whitespace in `string`), and
28946
+ // 2. the fix proposed in the same blog post, of using a negative lookbehind, is incompatible
28947
+ // with old Safari versions that we'd like to not break if possible (see
28948
+ // https://github.com/kpdecker/jsdiff/pull/550)
28949
+ // It feels absurd to do this with an explicit loop instead of a regex, but I really can't see a
28950
+ // better way that doesn't result in broken behaviour.
28951
+ var i;
28952
+ for (i = string.length - 1; i >= 0; i--) {
28953
+ if (!string[i].match(/\s/)) {
28954
+ break;
28955
+ }
28916
28956
  }
28917
- }
28918
- return k;
28957
+ return string.substring(i + 1);
28958
+ }
28959
+ function leadingWs(string) {
28960
+ // Thankfully the annoying considerations described in trailingWs don't apply here:
28961
+ var match = string.match(/^\s*/);
28962
+ return match ? match[0] : '';
28919
28963
  }
28920
28964
 
28965
+ var __extends$5 = (undefined && undefined.__extends) || (function () {
28966
+ var extendStatics = function (d, b) {
28967
+ extendStatics = Object.setPrototypeOf ||
28968
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28969
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28970
+ return extendStatics(d, b);
28971
+ };
28972
+ return function (d, b) {
28973
+ if (typeof b !== "function" && b !== null)
28974
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28975
+ extendStatics(d, b);
28976
+ function __() { this.constructor = d; }
28977
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28978
+ };
28979
+ })();
28921
28980
  // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
28922
28981
  //
28923
28982
  // Ranges and exceptions:
@@ -28936,8 +28995,7 @@ function overlapCount(a, b) {
28936
28995
  // - U+02DC ˜ &#732; Small Tilde
28937
28996
  // - U+02DD ˝ &#733; Double Acute Accent
28938
28997
  // Latin Extended Additional, 1E00–1EFF
28939
- var extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
28940
-
28998
+ var extendedWordChars = 'a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}';
28941
28999
  // Each token is one of the following:
28942
29000
  // - A punctuation mark plus the surrounding whitespace
28943
29001
  // - A word plus the surrounding whitespace
@@ -28958,652 +29016,737 @@ var extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6
28958
29016
  //
28959
29017
  // Keeping the surrounding whitespace of course has implications for .equals
28960
29018
  // and .join, not just .tokenize.
28961
-
28962
29019
  // This regex does NOT fully implement the tokenization rules described above.
28963
29020
  // Instead, it gives runs of whitespace their own "token". The tokenize method
28964
29021
  // then handles stitching whitespace tokens onto adjacent word or punctuation
28965
29022
  // tokens.
28966
29023
  var tokenizeIncludingWhitespace = new RegExp("[".concat(extendedWordChars, "]+|\\s+|[^").concat(extendedWordChars, "]"), 'ug');
28967
- var wordDiff = new Diff();
28968
- wordDiff.equals = function (left, right, options) {
28969
- if (options.ignoreCase) {
28970
- left = left.toLowerCase();
28971
- right = right.toLowerCase();
28972
- }
28973
- return left.trim() === right.trim();
28974
- };
28975
- wordDiff.tokenize = function (value) {
28976
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28977
- var parts;
28978
- if (options.intlSegmenter) {
28979
- if (options.intlSegmenter.resolvedOptions().granularity != 'word') {
28980
- throw new Error('The segmenter passed must have a granularity of "word"');
28981
- }
28982
- parts = Array.from(options.intlSegmenter.segment(value), function (segment) {
28983
- return segment.segment;
28984
- });
28985
- } else {
28986
- parts = value.match(tokenizeIncludingWhitespace) || [];
28987
- }
28988
- var tokens = [];
28989
- var prevPart = null;
28990
- parts.forEach(function (part) {
28991
- if (/\s/.test(part)) {
28992
- if (prevPart == null) {
28993
- tokens.push(part);
28994
- } else {
28995
- tokens.push(tokens.pop() + part);
28996
- }
28997
- } else if (/\s/.test(prevPart)) {
28998
- if (tokens[tokens.length - 1] == prevPart) {
28999
- tokens.push(tokens.pop() + part);
29000
- } else {
29001
- tokens.push(prevPart + part);
29002
- }
29003
- } else {
29004
- tokens.push(part);
29005
- }
29006
- prevPart = part;
29007
- });
29008
- return tokens;
29009
- };
29010
- wordDiff.join = function (tokens) {
29011
- // Tokens being joined here will always have appeared consecutively in the
29012
- // same text, so we can simply strip off the leading whitespace from all the
29013
- // tokens except the first (and except any whitespace-only tokens - but such
29014
- // a token will always be the first and only token anyway) and then join them
29015
- // and the whitespace around words and punctuation will end up correct.
29016
- return tokens.map(function (token, i) {
29017
- if (i == 0) {
29018
- return token;
29019
- } else {
29020
- return token.replace(/^\s+/, '');
29024
+ var WordDiff = /** @class */ (function (_super) {
29025
+ __extends$5(WordDiff, _super);
29026
+ function WordDiff() {
29027
+ return _super !== null && _super.apply(this, arguments) || this;
29021
29028
  }
29022
- }).join('');
29023
- };
29024
- wordDiff.postProcess = function (changes, options) {
29025
- if (!changes || options.oneChangePerToken) {
29026
- return changes;
29027
- }
29028
- var lastKeep = null;
29029
- // Change objects representing any insertion or deletion since the last
29030
- // "keep" change object. There can be at most one of each.
29031
- var insertion = null;
29032
- var deletion = null;
29033
- changes.forEach(function (change) {
29034
- if (change.added) {
29035
- insertion = change;
29036
- } else if (change.removed) {
29037
- deletion = change;
29038
- } else {
29039
- if (insertion || deletion) {
29040
- // May be false at start of text
29041
- dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
29042
- }
29043
- lastKeep = change;
29044
- insertion = null;
29045
- deletion = null;
29046
- }
29047
- });
29048
- if (insertion || deletion) {
29049
- dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
29050
- }
29051
- return changes;
29052
- };
29029
+ WordDiff.prototype.equals = function (left, right, options) {
29030
+ if (options.ignoreCase) {
29031
+ left = left.toLowerCase();
29032
+ right = right.toLowerCase();
29033
+ }
29034
+ return left.trim() === right.trim();
29035
+ };
29036
+ WordDiff.prototype.tokenize = function (value, options) {
29037
+ if (options === void 0) { options = {}; }
29038
+ var parts;
29039
+ if (options.intlSegmenter) {
29040
+ var segmenter = options.intlSegmenter;
29041
+ if (segmenter.resolvedOptions().granularity != 'word') {
29042
+ throw new Error('The segmenter passed must have a granularity of "word"');
29043
+ }
29044
+ parts = Array.from(segmenter.segment(value), function (segment) { return segment.segment; });
29045
+ }
29046
+ else {
29047
+ parts = value.match(tokenizeIncludingWhitespace) || [];
29048
+ }
29049
+ var tokens = [];
29050
+ var prevPart = null;
29051
+ parts.forEach(function (part) {
29052
+ if ((/\s/).test(part)) {
29053
+ if (prevPart == null) {
29054
+ tokens.push(part);
29055
+ }
29056
+ else {
29057
+ tokens.push(tokens.pop() + part);
29058
+ }
29059
+ }
29060
+ else if (prevPart != null && (/\s/).test(prevPart)) {
29061
+ if (tokens[tokens.length - 1] == prevPart) {
29062
+ tokens.push(tokens.pop() + part);
29063
+ }
29064
+ else {
29065
+ tokens.push(prevPart + part);
29066
+ }
29067
+ }
29068
+ else {
29069
+ tokens.push(part);
29070
+ }
29071
+ prevPart = part;
29072
+ });
29073
+ return tokens;
29074
+ };
29075
+ WordDiff.prototype.join = function (tokens) {
29076
+ // Tokens being joined here will always have appeared consecutively in the
29077
+ // same text, so we can simply strip off the leading whitespace from all the
29078
+ // tokens except the first (and except any whitespace-only tokens - but such
29079
+ // a token will always be the first and only token anyway) and then join them
29080
+ // and the whitespace around words and punctuation will end up correct.
29081
+ return tokens.map(function (token, i) {
29082
+ if (i == 0) {
29083
+ return token;
29084
+ }
29085
+ else {
29086
+ return token.replace((/^\s+/), '');
29087
+ }
29088
+ }).join('');
29089
+ };
29090
+ WordDiff.prototype.postProcess = function (changes, options) {
29091
+ if (!changes || options.oneChangePerToken) {
29092
+ return changes;
29093
+ }
29094
+ var lastKeep = null;
29095
+ // Change objects representing any insertion or deletion since the last
29096
+ // "keep" change object. There can be at most one of each.
29097
+ var insertion = null;
29098
+ var deletion = null;
29099
+ changes.forEach(function (change) {
29100
+ if (change.added) {
29101
+ insertion = change;
29102
+ }
29103
+ else if (change.removed) {
29104
+ deletion = change;
29105
+ }
29106
+ else {
29107
+ if (insertion || deletion) { // May be false at start of text
29108
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
29109
+ }
29110
+ lastKeep = change;
29111
+ insertion = null;
29112
+ deletion = null;
29113
+ }
29114
+ });
29115
+ if (insertion || deletion) {
29116
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
29117
+ }
29118
+ return changes;
29119
+ };
29120
+ return WordDiff;
29121
+ }(Diff));
29122
+ new WordDiff();
29053
29123
  function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep) {
29054
- // Before returning, we tidy up the leading and trailing whitespace of the
29055
- // change objects to eliminate cases where trailing whitespace in one object
29056
- // is repeated as leading whitespace in the next.
29057
- // Below are examples of the outcomes we want here to explain the code.
29058
- // I=insert, K=keep, D=delete
29059
- // 1. diffing 'foo bar baz' vs 'foo baz'
29060
- // Prior to cleanup, we have K:'foo ' D:' bar ' K:' baz'
29061
- // After cleanup, we want: K:'foo ' D:'bar ' K:'baz'
29062
- //
29063
- // 2. Diffing 'foo bar baz' vs 'foo qux baz'
29064
- // Prior to cleanup, we have K:'foo ' D:' bar ' I:' qux ' K:' baz'
29065
- // After cleanup, we want K:'foo ' D:'bar' I:'qux' K:' baz'
29066
- //
29067
- // 3. Diffing 'foo\nbar baz' vs 'foo baz'
29068
- // Prior to cleanup, we have K:'foo ' D:'\nbar ' K:' baz'
29069
- // After cleanup, we want K'foo' D:'\nbar' K:' baz'
29070
- //
29071
- // 4. Diffing 'foo baz' vs 'foo\nbar baz'
29072
- // Prior to cleanup, we have K:'foo\n' I:'\nbar ' K:' baz'
29073
- // After cleanup, we ideally want K'foo' I:'\nbar' K:' baz'
29074
- // but don't actually manage this currently (the pre-cleanup change
29075
- // objects don't contain enough information to make it possible).
29076
- //
29077
- // 5. Diffing 'foo bar baz' vs 'foo baz'
29078
- // Prior to cleanup, we have K:'foo ' D:' bar ' K:' baz'
29079
- // After cleanup, we want K:'foo ' D:' bar ' K:'baz'
29080
- //
29081
- // Our handling is unavoidably imperfect in the case where there's a single
29082
- // indel between keeps and the whitespace has changed. For instance, consider
29083
- // diffing 'foo\tbar\nbaz' vs 'foo baz'. Unless we create an extra change
29084
- // object to represent the insertion of the space character (which isn't even
29085
- // a token), we have no way to avoid losing information about the texts'
29086
- // original whitespace in the result we return. Still, we do our best to
29087
- // output something that will look sensible if we e.g. print it with
29088
- // insertions in green and deletions in red.
29089
-
29090
- // Between two "keep" change objects (or before the first or after the last
29091
- // change object), we can have either:
29092
- // * A "delete" followed by an "insert"
29093
- // * Just an "insert"
29094
- // * Just a "delete"
29095
- // We handle the three cases separately.
29096
- if (deletion && insertion) {
29097
- var oldWsPrefix = deletion.value.match(/^\s*/)[0];
29098
- var oldWsSuffix = deletion.value.match(/\s*$/)[0];
29099
- var newWsPrefix = insertion.value.match(/^\s*/)[0];
29100
- var newWsSuffix = insertion.value.match(/\s*$/)[0];
29101
- if (startKeep) {
29102
- var commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
29103
- startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
29104
- deletion.value = removePrefix(deletion.value, commonWsPrefix);
29105
- insertion.value = removePrefix(insertion.value, commonWsPrefix);
29106
- }
29107
- if (endKeep) {
29108
- var commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
29109
- endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
29110
- deletion.value = removeSuffix(deletion.value, commonWsSuffix);
29111
- insertion.value = removeSuffix(insertion.value, commonWsSuffix);
29112
- }
29113
- } else if (insertion) {
29114
- // The whitespaces all reflect what was in the new text rather than
29115
- // the old, so we essentially have no information about whitespace
29116
- // insertion or deletion. We just want to dedupe the whitespace.
29117
- // We do that by having each change object keep its trailing
29118
- // whitespace and deleting duplicate leading whitespace where
29119
- // present.
29120
- if (startKeep) {
29121
- insertion.value = insertion.value.replace(/^\s*/, '');
29122
- }
29123
- if (endKeep) {
29124
- endKeep.value = endKeep.value.replace(/^\s*/, '');
29125
- }
29126
- // otherwise we've got a deletion and no insertion
29127
- } else if (startKeep && endKeep) {
29128
- var newWsFull = endKeep.value.match(/^\s*/)[0],
29129
- delWsStart = deletion.value.match(/^\s*/)[0],
29130
- delWsEnd = deletion.value.match(/\s*$/)[0];
29131
-
29132
- // Any whitespace that comes straight after startKeep in both the old and
29133
- // new texts, assign to startKeep and remove from the deletion.
29134
- var newWsStart = longestCommonPrefix(newWsFull, delWsStart);
29135
- deletion.value = removePrefix(deletion.value, newWsStart);
29136
-
29137
- // Any whitespace that comes straight before endKeep in both the old and
29138
- // new texts, and hasn't already been assigned to startKeep, assign to
29139
- // endKeep and remove from the deletion.
29140
- var newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
29141
- deletion.value = removeSuffix(deletion.value, newWsEnd);
29142
- endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
29143
-
29144
- // If there's any whitespace from the new text that HASN'T already been
29145
- // assigned, assign it to the start:
29146
- startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
29147
- } else if (endKeep) {
29148
- // We are at the start of the text. Preserve all the whitespace on
29149
- // endKeep, and just remove whitespace from the end of deletion to the
29150
- // extent that it overlaps with the start of endKeep.
29151
- var endKeepWsPrefix = endKeep.value.match(/^\s*/)[0];
29152
- var deletionWsSuffix = deletion.value.match(/\s*$/)[0];
29153
- var overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
29154
- deletion.value = removeSuffix(deletion.value, overlap);
29155
- } else if (startKeep) {
29156
- // We are at the END of the text. Preserve all the whitespace on
29157
- // startKeep, and just remove whitespace from the start of deletion to
29158
- // the extent that it overlaps with the end of startKeep.
29159
- var startKeepWsSuffix = startKeep.value.match(/\s*$/)[0];
29160
- var deletionWsPrefix = deletion.value.match(/^\s*/)[0];
29161
- var _overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
29162
- deletion.value = removePrefix(deletion.value, _overlap);
29163
- }
29164
- }
29165
- var wordWithSpaceDiff = new Diff();
29166
- wordWithSpaceDiff.tokenize = function (value) {
29167
- // Slightly different to the tokenizeIncludingWhitespace regex used above in
29168
- // that this one treats each individual newline as a distinct tokens, rather
29169
- // than merging them into other surrounding whitespace. This was requested
29170
- // in https://github.com/kpdecker/jsdiff/issues/180 &
29171
- // https://github.com/kpdecker/jsdiff/issues/211
29172
- var regex = new RegExp("(\\r?\\n)|[".concat(extendedWordChars, "]+|[^\\S\\n\\r]+|[^").concat(extendedWordChars, "]"), 'ug');
29173
- return value.match(regex) || [];
29174
- };
29175
-
29176
- var lineDiff = new Diff();
29177
- lineDiff.tokenize = function (value, options) {
29178
- if (options.stripTrailingCr) {
29179
- // remove one \r before \n to match GNU diff's --strip-trailing-cr behavior
29180
- value = value.replace(/\r\n/g, '\n');
29181
- }
29182
- var retLines = [],
29183
- linesAndNewlines = value.split(/(\n|\r\n)/);
29184
-
29185
- // Ignore the final empty token that occurs if the string ends with a new line
29186
- if (!linesAndNewlines[linesAndNewlines.length - 1]) {
29187
- linesAndNewlines.pop();
29188
- }
29189
-
29190
- // Merge the content and line separators into single tokens
29191
- for (var i = 0; i < linesAndNewlines.length; i++) {
29192
- var line = linesAndNewlines[i];
29193
- if (i % 2 && !options.newlineIsToken) {
29194
- retLines[retLines.length - 1] += line;
29195
- } else {
29196
- retLines.push(line);
29124
+ // Before returning, we tidy up the leading and trailing whitespace of the
29125
+ // change objects to eliminate cases where trailing whitespace in one object
29126
+ // is repeated as leading whitespace in the next.
29127
+ // Below are examples of the outcomes we want here to explain the code.
29128
+ // I=insert, K=keep, D=delete
29129
+ // 1. diffing 'foo bar baz' vs 'foo baz'
29130
+ // Prior to cleanup, we have K:'foo ' D:' bar ' K:' baz'
29131
+ // After cleanup, we want: K:'foo ' D:'bar ' K:'baz'
29132
+ //
29133
+ // 2. Diffing 'foo bar baz' vs 'foo qux baz'
29134
+ // Prior to cleanup, we have K:'foo ' D:' bar ' I:' qux ' K:' baz'
29135
+ // After cleanup, we want K:'foo ' D:'bar' I:'qux' K:' baz'
29136
+ //
29137
+ // 3. Diffing 'foo\nbar baz' vs 'foo baz'
29138
+ // Prior to cleanup, we have K:'foo ' D:'\nbar ' K:' baz'
29139
+ // After cleanup, we want K'foo' D:'\nbar' K:' baz'
29140
+ //
29141
+ // 4. Diffing 'foo baz' vs 'foo\nbar baz'
29142
+ // Prior to cleanup, we have K:'foo\n' I:'\nbar ' K:' baz'
29143
+ // After cleanup, we ideally want K'foo' I:'\nbar' K:' baz'
29144
+ // but don't actually manage this currently (the pre-cleanup change
29145
+ // objects don't contain enough information to make it possible).
29146
+ //
29147
+ // 5. Diffing 'foo bar baz' vs 'foo baz'
29148
+ // Prior to cleanup, we have K:'foo ' D:' bar ' K:' baz'
29149
+ // After cleanup, we want K:'foo ' D:' bar ' K:'baz'
29150
+ //
29151
+ // Our handling is unavoidably imperfect in the case where there's a single
29152
+ // indel between keeps and the whitespace has changed. For instance, consider
29153
+ // diffing 'foo\tbar\nbaz' vs 'foo baz'. Unless we create an extra change
29154
+ // object to represent the insertion of the space character (which isn't even
29155
+ // a token), we have no way to avoid losing information about the texts'
29156
+ // original whitespace in the result we return. Still, we do our best to
29157
+ // output something that will look sensible if we e.g. print it with
29158
+ // insertions in green and deletions in red.
29159
+ // Between two "keep" change objects (or before the first or after the last
29160
+ // change object), we can have either:
29161
+ // * A "delete" followed by an "insert"
29162
+ // * Just an "insert"
29163
+ // * Just a "delete"
29164
+ // We handle the three cases separately.
29165
+ if (deletion && insertion) {
29166
+ var oldWsPrefix = leadingWs(deletion.value);
29167
+ var oldWsSuffix = trailingWs(deletion.value);
29168
+ var newWsPrefix = leadingWs(insertion.value);
29169
+ var newWsSuffix = trailingWs(insertion.value);
29170
+ if (startKeep) {
29171
+ var commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
29172
+ startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
29173
+ deletion.value = removePrefix(deletion.value, commonWsPrefix);
29174
+ insertion.value = removePrefix(insertion.value, commonWsPrefix);
29175
+ }
29176
+ if (endKeep) {
29177
+ var commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
29178
+ endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
29179
+ deletion.value = removeSuffix(deletion.value, commonWsSuffix);
29180
+ insertion.value = removeSuffix(insertion.value, commonWsSuffix);
29181
+ }
29182
+ }
29183
+ else if (insertion) {
29184
+ // The whitespaces all reflect what was in the new text rather than
29185
+ // the old, so we essentially have no information about whitespace
29186
+ // insertion or deletion. We just want to dedupe the whitespace.
29187
+ // We do that by having each change object keep its trailing
29188
+ // whitespace and deleting duplicate leading whitespace where
29189
+ // present.
29190
+ if (startKeep) {
29191
+ var ws = leadingWs(insertion.value);
29192
+ insertion.value = insertion.value.substring(ws.length);
29193
+ }
29194
+ if (endKeep) {
29195
+ var ws = leadingWs(endKeep.value);
29196
+ endKeep.value = endKeep.value.substring(ws.length);
29197
+ }
29198
+ // otherwise we've got a deletion and no insertion
29199
+ }
29200
+ else if (startKeep && endKeep) {
29201
+ var newWsFull = leadingWs(endKeep.value), delWsStart = leadingWs(deletion.value), delWsEnd = trailingWs(deletion.value);
29202
+ // Any whitespace that comes straight after startKeep in both the old and
29203
+ // new texts, assign to startKeep and remove from the deletion.
29204
+ var newWsStart = longestCommonPrefix(newWsFull, delWsStart);
29205
+ deletion.value = removePrefix(deletion.value, newWsStart);
29206
+ // Any whitespace that comes straight before endKeep in both the old and
29207
+ // new texts, and hasn't already been assigned to startKeep, assign to
29208
+ // endKeep and remove from the deletion.
29209
+ var newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
29210
+ deletion.value = removeSuffix(deletion.value, newWsEnd);
29211
+ endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
29212
+ // If there's any whitespace from the new text that HASN'T already been
29213
+ // assigned, assign it to the start:
29214
+ startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
29215
+ }
29216
+ else if (endKeep) {
29217
+ // We are at the start of the text. Preserve all the whitespace on
29218
+ // endKeep, and just remove whitespace from the end of deletion to the
29219
+ // extent that it overlaps with the start of endKeep.
29220
+ var endKeepWsPrefix = leadingWs(endKeep.value);
29221
+ var deletionWsSuffix = trailingWs(deletion.value);
29222
+ var overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
29223
+ deletion.value = removeSuffix(deletion.value, overlap);
29224
+ }
29225
+ else if (startKeep) {
29226
+ // We are at the END of the text. Preserve all the whitespace on
29227
+ // startKeep, and just remove whitespace from the start of deletion to
29228
+ // the extent that it overlaps with the end of startKeep.
29229
+ var startKeepWsSuffix = trailingWs(startKeep.value);
29230
+ var deletionWsPrefix = leadingWs(deletion.value);
29231
+ var overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
29232
+ deletion.value = removePrefix(deletion.value, overlap);
29233
+ }
29234
+ }
29235
+ var WordsWithSpaceDiff = /** @class */ (function (_super) {
29236
+ __extends$5(WordsWithSpaceDiff, _super);
29237
+ function WordsWithSpaceDiff() {
29238
+ return _super !== null && _super.apply(this, arguments) || this;
29239
+ }
29240
+ WordsWithSpaceDiff.prototype.tokenize = function (value) {
29241
+ // Slightly different to the tokenizeIncludingWhitespace regex used above in
29242
+ // that this one treats each individual newline as a distinct tokens, rather
29243
+ // than merging them into other surrounding whitespace. This was requested
29244
+ // in https://github.com/kpdecker/jsdiff/issues/180 &
29245
+ // https://github.com/kpdecker/jsdiff/issues/211
29246
+ var regex = new RegExp("(\\r?\\n)|[".concat(extendedWordChars, "]+|[^\\S\\n\\r]+|[^").concat(extendedWordChars, "]"), 'ug');
29247
+ return value.match(regex) || [];
29248
+ };
29249
+ return WordsWithSpaceDiff;
29250
+ }(Diff));
29251
+ new WordsWithSpaceDiff();
29252
+
29253
+ var __extends$4 = (undefined && undefined.__extends) || (function () {
29254
+ var extendStatics = function (d, b) {
29255
+ extendStatics = Object.setPrototypeOf ||
29256
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29257
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29258
+ return extendStatics(d, b);
29259
+ };
29260
+ return function (d, b) {
29261
+ if (typeof b !== "function" && b !== null)
29262
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29263
+ extendStatics(d, b);
29264
+ function __() { this.constructor = d; }
29265
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29266
+ };
29267
+ })();
29268
+ var LineDiff = /** @class */ (function (_super) {
29269
+ __extends$4(LineDiff, _super);
29270
+ function LineDiff() {
29271
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29272
+ _this.tokenize = tokenize;
29273
+ return _this;
29197
29274
  }
29198
- }
29199
- return retLines;
29200
- };
29201
- lineDiff.equals = function (left, right, options) {
29202
- // If we're ignoring whitespace, we need to normalise lines by stripping
29203
- // whitespace before checking equality. (This has an annoying interaction
29204
- // with newlineIsToken that requires special handling: if newlines get their
29205
- // own token, then we DON'T want to trim the *newline* tokens down to empty
29206
- // strings, since this would cause us to treat whitespace-only line content
29207
- // as equal to a separator between lines, which would be weird and
29208
- // inconsistent with the documented behavior of the options.)
29209
- if (options.ignoreWhitespace) {
29210
- if (!options.newlineIsToken || !left.includes('\n')) {
29211
- left = left.trim();
29212
- }
29213
- if (!options.newlineIsToken || !right.includes('\n')) {
29214
- right = right.trim();
29215
- }
29216
- } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
29217
- if (left.endsWith('\n')) {
29218
- left = left.slice(0, -1);
29219
- }
29220
- if (right.endsWith('\n')) {
29221
- right = right.slice(0, -1);
29222
- }
29223
- }
29224
- return Diff.prototype.equals.call(this, left, right, options);
29225
- };
29226
- function diffLines(oldStr, newStr, callback) {
29227
- return lineDiff.diff(oldStr, newStr, callback);
29275
+ LineDiff.prototype.equals = function (left, right, options) {
29276
+ // If we're ignoring whitespace, we need to normalise lines by stripping
29277
+ // whitespace before checking equality. (This has an annoying interaction
29278
+ // with newlineIsToken that requires special handling: if newlines get their
29279
+ // own token, then we DON'T want to trim the *newline* tokens down to empty
29280
+ // strings, since this would cause us to treat whitespace-only line content
29281
+ // as equal to a separator between lines, which would be weird and
29282
+ // inconsistent with the documented behavior of the options.)
29283
+ if (options.ignoreWhitespace) {
29284
+ if (!options.newlineIsToken || !left.includes('\n')) {
29285
+ left = left.trim();
29286
+ }
29287
+ if (!options.newlineIsToken || !right.includes('\n')) {
29288
+ right = right.trim();
29289
+ }
29290
+ }
29291
+ else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
29292
+ if (left.endsWith('\n')) {
29293
+ left = left.slice(0, -1);
29294
+ }
29295
+ if (right.endsWith('\n')) {
29296
+ right = right.slice(0, -1);
29297
+ }
29298
+ }
29299
+ return _super.prototype.equals.call(this, left, right, options);
29300
+ };
29301
+ return LineDiff;
29302
+ }(Diff));
29303
+ var lineDiff = new LineDiff();
29304
+ function diffLines(oldStr, newStr, options) {
29305
+ return lineDiff.diff(oldStr, newStr, options);
29306
+ }
29307
+ // Exported standalone so it can be used from jsonDiff too.
29308
+ function tokenize(value, options) {
29309
+ if (options.stripTrailingCr) {
29310
+ // remove one \r before \n to match GNU diff's --strip-trailing-cr behavior
29311
+ value = value.replace(/\r\n/g, '\n');
29312
+ }
29313
+ var retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
29314
+ // Ignore the final empty token that occurs if the string ends with a new line
29315
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
29316
+ linesAndNewlines.pop();
29317
+ }
29318
+ // Merge the content and line separators into single tokens
29319
+ for (var i = 0; i < linesAndNewlines.length; i++) {
29320
+ var line = linesAndNewlines[i];
29321
+ if (i % 2 && !options.newlineIsToken) {
29322
+ retLines[retLines.length - 1] += line;
29323
+ }
29324
+ else {
29325
+ retLines.push(line);
29326
+ }
29327
+ }
29328
+ return retLines;
29228
29329
  }
29229
29330
 
29230
- var sentenceDiff = new Diff();
29231
- sentenceDiff.tokenize = function (value) {
29232
- return value.split(/(\S.+?[.!?])(?=\s+|$)/);
29233
- };
29234
-
29235
- var cssDiff = new Diff();
29236
- cssDiff.tokenize = function (value) {
29237
- return value.split(/([{}:;,]|\s+)/);
29238
- };
29239
-
29240
- function ownKeys(e, r) {
29241
- var t = Object.keys(e);
29242
- if (Object.getOwnPropertySymbols) {
29243
- var o = Object.getOwnPropertySymbols(e);
29244
- r && (o = o.filter(function (r) {
29245
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
29246
- })), t.push.apply(t, o);
29247
- }
29248
- return t;
29249
- }
29250
- function _objectSpread2(e) {
29251
- for (var r = 1; r < arguments.length; r++) {
29252
- var t = null != arguments[r] ? arguments[r] : {};
29253
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
29254
- _defineProperty(e, r, t[r]);
29255
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
29256
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
29257
- });
29258
- }
29259
- return e;
29260
- }
29261
- function _toPrimitive(t, r) {
29262
- if ("object" != typeof t || !t) return t;
29263
- var e = t[Symbol.toPrimitive];
29264
- if (void 0 !== e) {
29265
- var i = e.call(t, r);
29266
- if ("object" != typeof i) return i;
29267
- throw new TypeError("@@toPrimitive must return a primitive value.");
29268
- }
29269
- return ("string" === r ? String : Number)(t);
29270
- }
29271
- function _toPropertyKey(t) {
29272
- var i = _toPrimitive(t, "string");
29273
- return "symbol" == typeof i ? i : i + "";
29274
- }
29275
- function _typeof(o) {
29276
- "@babel/helpers - typeof";
29277
-
29278
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
29279
- return typeof o;
29280
- } : function (o) {
29281
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
29282
- }, _typeof(o);
29283
- }
29284
- function _defineProperty(obj, key, value) {
29285
- key = _toPropertyKey(key);
29286
- if (key in obj) {
29287
- Object.defineProperty(obj, key, {
29288
- value: value,
29289
- enumerable: true,
29290
- configurable: true,
29291
- writable: true
29331
+ var __extends$3 = (undefined && undefined.__extends) || (function () {
29332
+ var extendStatics = function (d, b) {
29333
+ extendStatics = Object.setPrototypeOf ||
29334
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29335
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29336
+ return extendStatics(d, b);
29337
+ };
29338
+ return function (d, b) {
29339
+ if (typeof b !== "function" && b !== null)
29340
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29341
+ extendStatics(d, b);
29342
+ function __() { this.constructor = d; }
29343
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29344
+ };
29345
+ })();
29346
+ var SentenceDiff = /** @class */ (function (_super) {
29347
+ __extends$3(SentenceDiff, _super);
29348
+ function SentenceDiff() {
29349
+ return _super !== null && _super.apply(this, arguments) || this;
29350
+ }
29351
+ SentenceDiff.prototype.tokenize = function (value) {
29352
+ return value.split(/(?<=[.!?])(\s+|$)/);
29353
+ };
29354
+ return SentenceDiff;
29355
+ }(Diff));
29356
+ new SentenceDiff();
29357
+
29358
+ var __extends$2 = (undefined && undefined.__extends) || (function () {
29359
+ var extendStatics = function (d, b) {
29360
+ extendStatics = Object.setPrototypeOf ||
29361
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29362
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29363
+ return extendStatics(d, b);
29364
+ };
29365
+ return function (d, b) {
29366
+ if (typeof b !== "function" && b !== null)
29367
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29368
+ extendStatics(d, b);
29369
+ function __() { this.constructor = d; }
29370
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29371
+ };
29372
+ })();
29373
+ var CssDiff = /** @class */ (function (_super) {
29374
+ __extends$2(CssDiff, _super);
29375
+ function CssDiff() {
29376
+ return _super !== null && _super.apply(this, arguments) || this;
29377
+ }
29378
+ CssDiff.prototype.tokenize = function (value) {
29379
+ return value.split(/([{}:;,]|\s+)/);
29380
+ };
29381
+ return CssDiff;
29382
+ }(Diff));
29383
+ new CssDiff();
29384
+
29385
+ var __extends$1 = (undefined && undefined.__extends) || (function () {
29386
+ var extendStatics = function (d, b) {
29387
+ extendStatics = Object.setPrototypeOf ||
29388
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29389
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29390
+ return extendStatics(d, b);
29391
+ };
29392
+ return function (d, b) {
29393
+ if (typeof b !== "function" && b !== null)
29394
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29395
+ extendStatics(d, b);
29396
+ function __() { this.constructor = d; }
29397
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29398
+ };
29399
+ })();
29400
+ var JsonDiff = /** @class */ (function (_super) {
29401
+ __extends$1(JsonDiff, _super);
29402
+ function JsonDiff() {
29403
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29404
+ _this.tokenize = tokenize;
29405
+ return _this;
29406
+ }
29407
+ Object.defineProperty(JsonDiff.prototype, "useLongestToken", {
29408
+ get: function () {
29409
+ // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
29410
+ // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
29411
+ return true;
29412
+ },
29413
+ enumerable: false,
29414
+ configurable: true
29292
29415
  });
29293
- } else {
29294
- obj[key] = value;
29295
- }
29296
- return obj;
29297
- }
29298
- function _toConsumableArray(arr) {
29299
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
29300
- }
29301
- function _arrayWithoutHoles(arr) {
29302
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
29303
- }
29304
- function _iterableToArray(iter) {
29305
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
29306
- }
29307
- function _unsupportedIterableToArray(o, minLen) {
29308
- if (!o) return;
29309
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
29310
- var n = Object.prototype.toString.call(o).slice(8, -1);
29311
- if (n === "Object" && o.constructor) n = o.constructor.name;
29312
- if (n === "Map" || n === "Set") return Array.from(o);
29313
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
29314
- }
29315
- function _arrayLikeToArray(arr, len) {
29316
- if (len == null || len > arr.length) len = arr.length;
29317
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
29318
- return arr2;
29319
- }
29320
- function _nonIterableSpread() {
29321
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
29322
- }
29323
-
29324
- var jsonDiff = new Diff();
29325
- // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
29326
- // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
29327
- jsonDiff.useLongestToken = true;
29328
- jsonDiff.tokenize = lineDiff.tokenize;
29329
- jsonDiff.castInput = function (value, options) {
29330
- var undefinedReplacement = options.undefinedReplacement,
29331
- _options$stringifyRep = options.stringifyReplacer,
29332
- stringifyReplacer = _options$stringifyRep === void 0 ? function (k, v) {
29333
- return typeof v === 'undefined' ? undefinedReplacement : v;
29334
- } : _options$stringifyRep;
29335
- return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
29336
- };
29337
- jsonDiff.equals = function (left, right, options) {
29338
- return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'), options);
29339
- };
29340
-
29416
+ JsonDiff.prototype.castInput = function (value, options) {
29417
+ var undefinedReplacement = options.undefinedReplacement, _a = options.stringifyReplacer, stringifyReplacer = _a === void 0 ? function (k, v) { return typeof v === 'undefined' ? undefinedReplacement : v; } : _a;
29418
+ return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, ' ');
29419
+ };
29420
+ JsonDiff.prototype.equals = function (left, right, options) {
29421
+ return _super.prototype.equals.call(this, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'), options);
29422
+ };
29423
+ return JsonDiff;
29424
+ }(Diff));
29425
+ new JsonDiff();
29341
29426
  // This function handles the presence of circular references by bailing out when encountering an
29342
29427
  // object that is already on the "stack" of items being processed. Accepts an optional replacer
29343
29428
  function canonicalize(obj, stack, replacementStack, replacer, key) {
29344
- stack = stack || [];
29345
- replacementStack = replacementStack || [];
29346
- if (replacer) {
29347
- obj = replacer(key, obj);
29348
- }
29349
- var i;
29350
- for (i = 0; i < stack.length; i += 1) {
29351
- if (stack[i] === obj) {
29352
- return replacementStack[i];
29353
- }
29354
- }
29355
- var canonicalizedObj;
29356
- if ('[object Array]' === Object.prototype.toString.call(obj)) {
29357
- stack.push(obj);
29358
- canonicalizedObj = new Array(obj.length);
29359
- replacementStack.push(canonicalizedObj);
29360
- for (i = 0; i < obj.length; i += 1) {
29361
- canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
29362
- }
29363
- stack.pop();
29364
- replacementStack.pop();
29365
- return canonicalizedObj;
29366
- }
29367
- if (obj && obj.toJSON) {
29368
- obj = obj.toJSON();
29369
- }
29370
- if (_typeof(obj) === 'object' && obj !== null) {
29371
- stack.push(obj);
29372
- canonicalizedObj = {};
29373
- replacementStack.push(canonicalizedObj);
29374
- var sortedKeys = [],
29375
- _key;
29376
- for (_key in obj) {
29377
- /* istanbul ignore else */
29378
- if (Object.prototype.hasOwnProperty.call(obj, _key)) {
29379
- sortedKeys.push(_key);
29380
- }
29429
+ stack = stack || [];
29430
+ replacementStack = replacementStack || [];
29431
+ if (replacer) {
29432
+ obj = replacer(key === undefined ? '' : key, obj);
29433
+ }
29434
+ var i;
29435
+ for (i = 0; i < stack.length; i += 1) {
29436
+ if (stack[i] === obj) {
29437
+ return replacementStack[i];
29438
+ }
29439
+ }
29440
+ var canonicalizedObj;
29441
+ if ('[object Array]' === Object.prototype.toString.call(obj)) {
29442
+ stack.push(obj);
29443
+ canonicalizedObj = new Array(obj.length);
29444
+ replacementStack.push(canonicalizedObj);
29445
+ for (i = 0; i < obj.length; i += 1) {
29446
+ canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
29447
+ }
29448
+ stack.pop();
29449
+ replacementStack.pop();
29450
+ return canonicalizedObj;
29451
+ }
29452
+ if (obj && obj.toJSON) {
29453
+ obj = obj.toJSON();
29454
+ }
29455
+ if (typeof obj === 'object' && obj !== null) {
29456
+ stack.push(obj);
29457
+ canonicalizedObj = {};
29458
+ replacementStack.push(canonicalizedObj);
29459
+ var sortedKeys = [];
29460
+ var key_1;
29461
+ for (key_1 in obj) {
29462
+ /* istanbul ignore else */
29463
+ if (Object.prototype.hasOwnProperty.call(obj, key_1)) {
29464
+ sortedKeys.push(key_1);
29465
+ }
29466
+ }
29467
+ sortedKeys.sort();
29468
+ for (i = 0; i < sortedKeys.length; i += 1) {
29469
+ key_1 = sortedKeys[i];
29470
+ canonicalizedObj[key_1] = canonicalize(obj[key_1], stack, replacementStack, replacer, key_1);
29471
+ }
29472
+ stack.pop();
29473
+ replacementStack.pop();
29381
29474
  }
29382
- sortedKeys.sort();
29383
- for (i = 0; i < sortedKeys.length; i += 1) {
29384
- _key = sortedKeys[i];
29385
- canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
29475
+ else {
29476
+ canonicalizedObj = obj;
29386
29477
  }
29387
- stack.pop();
29388
- replacementStack.pop();
29389
- } else {
29390
- canonicalizedObj = obj;
29391
- }
29392
- return canonicalizedObj;
29478
+ return canonicalizedObj;
29393
29479
  }
29394
29480
 
29395
- var arrayDiff = new Diff();
29396
- arrayDiff.tokenize = function (value) {
29397
- return value.slice();
29398
- };
29399
- arrayDiff.join = arrayDiff.removeEmpty = function (value) {
29400
- return value;
29481
+ var __extends = (undefined && undefined.__extends) || (function () {
29482
+ var extendStatics = function (d, b) {
29483
+ extendStatics = Object.setPrototypeOf ||
29484
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29485
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29486
+ return extendStatics(d, b);
29487
+ };
29488
+ return function (d, b) {
29489
+ if (typeof b !== "function" && b !== null)
29490
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29491
+ extendStatics(d, b);
29492
+ function __() { this.constructor = d; }
29493
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29494
+ };
29495
+ })();
29496
+ var ArrayDiff = /** @class */ (function (_super) {
29497
+ __extends(ArrayDiff, _super);
29498
+ function ArrayDiff() {
29499
+ return _super !== null && _super.apply(this, arguments) || this;
29500
+ }
29501
+ ArrayDiff.prototype.tokenize = function (value) {
29502
+ return value.slice();
29503
+ };
29504
+ ArrayDiff.prototype.join = function (value) {
29505
+ return value;
29506
+ };
29507
+ ArrayDiff.prototype.removeEmpty = function (value) {
29508
+ return value;
29509
+ };
29510
+ return ArrayDiff;
29511
+ }(Diff));
29512
+ new ArrayDiff();
29513
+
29514
+ var __assign$2 = (undefined && undefined.__assign) || function () {
29515
+ __assign$2 = Object.assign || function(t) {
29516
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29517
+ s = arguments[i];
29518
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29519
+ t[p] = s[p];
29520
+ }
29521
+ return t;
29522
+ };
29523
+ return __assign$2.apply(this, arguments);
29401
29524
  };
29402
29525
 
29403
- function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
29404
- if (!options) {
29405
- options = {};
29406
- }
29407
- if (typeof options === 'function') {
29408
- options = {
29409
- callback: options
29526
+ var __assign$1 = (undefined && undefined.__assign) || function () {
29527
+ __assign$1 = Object.assign || function(t) {
29528
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29529
+ s = arguments[i];
29530
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29531
+ t[p] = s[p];
29532
+ }
29533
+ return t;
29410
29534
  };
29411
- }
29412
- if (typeof options.context === 'undefined') {
29413
- options.context = 4;
29414
- }
29415
- if (options.newlineIsToken) {
29416
- throw new Error('newlineIsToken may not be used with patch-generation functions, only with diffing functions');
29417
- }
29418
- if (!options.callback) {
29419
- return diffLinesResultToPatch(diffLines(oldStr, newStr, options));
29420
- } else {
29421
- var _options = options,
29422
- _callback = _options.callback;
29423
- diffLines(oldStr, newStr, _objectSpread2(_objectSpread2({}, options), {}, {
29424
- callback: function callback(diff) {
29425
- var patch = diffLinesResultToPatch(diff);
29426
- _callback(patch);
29427
- }
29428
- }));
29429
- }
29430
- function diffLinesResultToPatch(diff) {
29431
- // STEP 1: Build up the patch with no "" lines and with the arrays
29432
- // of lines containing trailing newline characters. We'll tidy up later...
29535
+ return __assign$1.apply(this, arguments);
29536
+ };
29433
29537
 
29434
- if (!diff) {
29435
- return;
29538
+ var __assign = (undefined && undefined.__assign) || function () {
29539
+ __assign = Object.assign || function(t) {
29540
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29541
+ s = arguments[i];
29542
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29543
+ t[p] = s[p];
29544
+ }
29545
+ return t;
29546
+ };
29547
+ return __assign.apply(this, arguments);
29548
+ };
29549
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
29550
+ var optionsObj;
29551
+ if (!options) {
29552
+ optionsObj = {};
29436
29553
  }
29437
- diff.push({
29438
- value: '',
29439
- lines: []
29440
- }); // Append an empty value to make cleanup easier
29441
-
29442
- function contextLines(lines) {
29443
- return lines.map(function (entry) {
29444
- return ' ' + entry;
29445
- });
29554
+ else if (typeof options === 'function') {
29555
+ optionsObj = { callback: options };
29446
29556
  }
29447
- var hunks = [];
29448
- var oldRangeStart = 0,
29449
- newRangeStart = 0,
29450
- curRange = [],
29451
- oldLine = 1,
29452
- newLine = 1;
29453
- var _loop = function _loop() {
29454
- var current = diff[i],
29455
- lines = current.lines || splitLines(current.value);
29456
- current.lines = lines;
29457
- if (current.added || current.removed) {
29458
- var _curRange;
29459
- // If we have previous context, start with that
29460
- if (!oldRangeStart) {
29461
- var prev = diff[i - 1];
29462
- oldRangeStart = oldLine;
29463
- newRangeStart = newLine;
29464
- if (prev) {
29465
- curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
29466
- oldRangeStart -= curRange.length;
29467
- newRangeStart -= curRange.length;
29468
- }
29469
- }
29470
-
29471
- // Output our changes
29472
- (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
29473
- return (current.added ? '+' : '-') + entry;
29474
- })));
29475
-
29476
- // Track the updated file position
29477
- if (current.added) {
29478
- newLine += lines.length;
29479
- } else {
29480
- oldLine += lines.length;
29557
+ else {
29558
+ optionsObj = options;
29559
+ }
29560
+ if (typeof optionsObj.context === 'undefined') {
29561
+ optionsObj.context = 4;
29562
+ }
29563
+ // We copy this into its own variable to placate TypeScript, which thinks
29564
+ // optionsObj.context might be undefined in the callbacks below.
29565
+ var context = optionsObj.context;
29566
+ // @ts-expect-error (runtime check for something that is correctly a static type error)
29567
+ if (optionsObj.newlineIsToken) {
29568
+ throw new Error('newlineIsToken may not be used with patch-generation functions, only with diffing functions');
29569
+ }
29570
+ if (!optionsObj.callback) {
29571
+ return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
29572
+ }
29573
+ else {
29574
+ var callback_1 = optionsObj.callback;
29575
+ diffLines(oldStr, newStr, __assign(__assign({}, optionsObj), { callback: function (diff) {
29576
+ var patch = diffLinesResultToPatch(diff);
29577
+ // TypeScript is unhappy without the cast because it does not understand that `patch` may
29578
+ // be undefined here only if `callback` is StructuredPatchCallbackAbortable:
29579
+ callback_1(patch);
29580
+ } }));
29581
+ }
29582
+ function diffLinesResultToPatch(diff) {
29583
+ // STEP 1: Build up the patch with no "" lines and with the arrays
29584
+ // of lines containing trailing newline characters. We'll tidy up later...
29585
+ if (!diff) {
29586
+ return;
29481
29587
  }
29482
- } else {
29483
- // Identical context lines. Track line changes
29484
- if (oldRangeStart) {
29485
- // Close out any changes that have been output (or join overlapping)
29486
- if (lines.length <= options.context * 2 && i < diff.length - 2) {
29487
- var _curRange2;
29488
- // Overlapping
29489
- (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
29490
- } else {
29491
- var _curRange3;
29492
- // end the range and output
29493
- var contextSize = Math.min(lines.length, options.context);
29494
- (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
29495
- var _hunk = {
29496
- oldStart: oldRangeStart,
29497
- oldLines: oldLine - oldRangeStart + contextSize,
29498
- newStart: newRangeStart,
29499
- newLines: newLine - newRangeStart + contextSize,
29500
- lines: curRange
29501
- };
29502
- hunks.push(_hunk);
29503
- oldRangeStart = 0;
29504
- newRangeStart = 0;
29505
- curRange = [];
29506
- }
29588
+ diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
29589
+ function contextLines(lines) {
29590
+ return lines.map(function (entry) { return ' ' + entry; });
29591
+ }
29592
+ var hunks = [];
29593
+ var oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
29594
+ for (var i = 0; i < diff.length; i++) {
29595
+ var current = diff[i], lines = current.lines || splitLines(current.value);
29596
+ current.lines = lines;
29597
+ if (current.added || current.removed) {
29598
+ // If we have previous context, start with that
29599
+ if (!oldRangeStart) {
29600
+ var prev = diff[i - 1];
29601
+ oldRangeStart = oldLine;
29602
+ newRangeStart = newLine;
29603
+ if (prev) {
29604
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
29605
+ oldRangeStart -= curRange.length;
29606
+ newRangeStart -= curRange.length;
29607
+ }
29608
+ }
29609
+ // Output our changes
29610
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
29611
+ var line = lines_1[_i];
29612
+ curRange.push((current.added ? '+' : '-') + line);
29613
+ }
29614
+ // Track the updated file position
29615
+ if (current.added) {
29616
+ newLine += lines.length;
29617
+ }
29618
+ else {
29619
+ oldLine += lines.length;
29620
+ }
29621
+ }
29622
+ else {
29623
+ // Identical context lines. Track line changes
29624
+ if (oldRangeStart) {
29625
+ // Close out any changes that have been output (or join overlapping)
29626
+ if (lines.length <= context * 2 && i < diff.length - 2) {
29627
+ // Overlapping
29628
+ for (var _a = 0, _b = contextLines(lines); _a < _b.length; _a++) {
29629
+ var line = _b[_a];
29630
+ curRange.push(line);
29631
+ }
29632
+ }
29633
+ else {
29634
+ // end the range and output
29635
+ var contextSize = Math.min(lines.length, context);
29636
+ for (var _c = 0, _d = contextLines(lines.slice(0, contextSize)); _c < _d.length; _c++) {
29637
+ var line = _d[_c];
29638
+ curRange.push(line);
29639
+ }
29640
+ var hunk = {
29641
+ oldStart: oldRangeStart,
29642
+ oldLines: (oldLine - oldRangeStart + contextSize),
29643
+ newStart: newRangeStart,
29644
+ newLines: (newLine - newRangeStart + contextSize),
29645
+ lines: curRange
29646
+ };
29647
+ hunks.push(hunk);
29648
+ oldRangeStart = 0;
29649
+ newRangeStart = 0;
29650
+ curRange = [];
29651
+ }
29652
+ }
29653
+ oldLine += lines.length;
29654
+ newLine += lines.length;
29655
+ }
29507
29656
  }
29508
- oldLine += lines.length;
29509
- newLine += lines.length;
29510
- }
29511
- };
29512
- for (var i = 0; i < diff.length; i++) {
29513
- _loop();
29514
- }
29515
-
29516
- // Step 2: eliminate the trailing `\n` from each line of each hunk, and, where needed, add
29517
- // "".
29518
- for (var _i = 0, _hunks = hunks; _i < _hunks.length; _i++) {
29519
- var hunk = _hunks[_i];
29520
- for (var _i2 = 0; _i2 < hunk.lines.length; _i2++) {
29521
- if (hunk.lines[_i2].endsWith('\n')) {
29522
- hunk.lines[_i2] = hunk.lines[_i2].slice(0, -1);
29523
- } else {
29524
- hunk.lines.splice(_i2 + 1, 0, '\');
29525
- _i2++; // Skip the line we just added, then continue iterating
29657
+ // Step 2: eliminate the trailing `\n` from each line of each hunk, and, where needed, add
29658
+ // "".
29659
+ for (var _e = 0, hunks_1 = hunks; _e < hunks_1.length; _e++) {
29660
+ var hunk = hunks_1[_e];
29661
+ for (var i = 0; i < hunk.lines.length; i++) {
29662
+ if (hunk.lines[i].endsWith('\n')) {
29663
+ hunk.lines[i] = hunk.lines[i].slice(0, -1);
29664
+ }
29665
+ else {
29666
+ hunk.lines.splice(i + 1, 0, '\');
29667
+ i++; // Skip the line we just added, then continue iterating
29668
+ }
29669
+ }
29526
29670
  }
29527
- }
29671
+ return {
29672
+ oldFileName: oldFileName, newFileName: newFileName,
29673
+ oldHeader: oldHeader, newHeader: newHeader,
29674
+ hunks: hunks
29675
+ };
29528
29676
  }
29529
- return {
29530
- oldFileName: oldFileName,
29531
- newFileName: newFileName,
29532
- oldHeader: oldHeader,
29533
- newHeader: newHeader,
29534
- hunks: hunks
29535
- };
29536
- }
29537
29677
  }
29538
- function formatPatch(diff) {
29539
- if (Array.isArray(diff)) {
29540
- return diff.map(formatPatch).join('\n');
29541
- }
29542
- var ret = [];
29543
- if (diff.oldFileName == diff.newFileName) {
29544
- ret.push('Index: ' + diff.oldFileName);
29545
- }
29546
- ret.push('===================================================================');
29547
- ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
29548
- ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
29549
- for (var i = 0; i < diff.hunks.length; i++) {
29550
- var hunk = diff.hunks[i];
29551
- // Unified Diff Format quirk: If the chunk size is 0,
29552
- // the first number is one lower than one would expect.
29553
- // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
29554
- if (hunk.oldLines === 0) {
29555
- hunk.oldStart -= 1;
29678
+ /**
29679
+ * creates a unified diff patch.
29680
+ * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
29681
+ */
29682
+ function formatPatch(patch) {
29683
+ if (Array.isArray(patch)) {
29684
+ return patch.map(formatPatch).join('\n');
29556
29685
  }
29557
- if (hunk.newLines === 0) {
29558
- hunk.newStart -= 1;
29686
+ var ret = [];
29687
+ if (patch.oldFileName == patch.newFileName) {
29688
+ ret.push('Index: ' + patch.oldFileName);
29559
29689
  }
29560
- ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
29561
- ret.push.apply(ret, hunk.lines);
29562
- }
29563
- return ret.join('\n') + '\n';
29690
+ ret.push('===================================================================');
29691
+ ret.push('--- ' + patch.oldFileName + (typeof patch.oldHeader === 'undefined' ? '' : '\t' + patch.oldHeader));
29692
+ ret.push('+++ ' + patch.newFileName + (typeof patch.newHeader === 'undefined' ? '' : '\t' + patch.newHeader));
29693
+ for (var i = 0; i < patch.hunks.length; i++) {
29694
+ var hunk = patch.hunks[i];
29695
+ // Unified Diff Format quirk: If the chunk size is 0,
29696
+ // the first number is one lower than one would expect.
29697
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
29698
+ if (hunk.oldLines === 0) {
29699
+ hunk.oldStart -= 1;
29700
+ }
29701
+ if (hunk.newLines === 0) {
29702
+ hunk.newStart -= 1;
29703
+ }
29704
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines
29705
+ + ' +' + hunk.newStart + ',' + hunk.newLines
29706
+ + ' @@');
29707
+ for (var _i = 0, _a = hunk.lines; _i < _a.length; _i++) {
29708
+ var line = _a[_i];
29709
+ ret.push(line);
29710
+ }
29711
+ }
29712
+ return ret.join('\n') + '\n';
29564
29713
  }
29565
29714
  function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
29566
- var _options2;
29567
- if (typeof options === 'function') {
29568
- options = {
29569
- callback: options
29570
- };
29571
- }
29572
- if (!((_options2 = options) !== null && _options2 !== void 0 && _options2.callback)) {
29573
- var patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
29574
- if (!patchObj) {
29575
- return;
29715
+ if (typeof options === 'function') {
29716
+ options = { callback: options };
29576
29717
  }
29577
- return formatPatch(patchObj);
29578
- } else {
29579
- var _options3 = options,
29580
- _callback2 = _options3.callback;
29581
- structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, _objectSpread2(_objectSpread2({}, options), {}, {
29582
- callback: function callback(patchObj) {
29718
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
29719
+ var patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
29583
29720
  if (!patchObj) {
29584
- _callback2();
29585
- } else {
29586
- _callback2(formatPatch(patchObj));
29721
+ return;
29587
29722
  }
29588
- }
29589
- }));
29590
- }
29723
+ return formatPatch(patchObj);
29724
+ }
29725
+ else {
29726
+ var callback_2 = options.callback;
29727
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, __assign(__assign({}, options), { callback: function (patchObj) {
29728
+ if (!patchObj) {
29729
+ callback_2(undefined);
29730
+ }
29731
+ else {
29732
+ callback_2(formatPatch(patchObj));
29733
+ }
29734
+ } }));
29735
+ }
29591
29736
  }
29592
-
29593
29737
  /**
29594
29738
  * Split `text` into an array of lines, including the trailing newline character (where present)
29595
29739
  */
29596
29740
  function splitLines(text) {
29597
- var hasTrailingNl = text.endsWith('\n');
29598
- var result = text.split('\n').map(function (line) {
29599
- return line + '\n';
29600
- });
29601
- if (hasTrailingNl) {
29602
- result.pop();
29603
- } else {
29604
- result.push(result.pop().slice(0, -1));
29605
- }
29606
- return result;
29741
+ var hasTrailingNl = text.endsWith('\n');
29742
+ var result = text.split('\n').map(function (line) { return line + '\n'; });
29743
+ if (hasTrailingNl) {
29744
+ result.pop();
29745
+ }
29746
+ else {
29747
+ result.push(result.pop().slice(0, -1));
29748
+ }
29749
+ return result;
29607
29750
  }
29608
29751
 
29609
29752
  /* eslint-disable no-multi-assign */
@@ -56710,4 +56853,4 @@ var srcExports = requireSrc();
56710
56853
  var tinylr = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
56711
56854
 
56712
56855
  export { HighlightJS as H, MarkdownIt as M, deflist_plugin as a, closest as b, createTwoFilesPatch as c, dedent as d, distance as e, fm as f, globSync as g, glob as h, isCI as i, moduleImporter as j, cliProgress as k, createInstance as l, minimatch as m, fse as n, tinylr as t, watch$1 as w };
56713
- //# sourceMappingURL=vendor-DmS_A2Yc.mjs.map
56856
+ //# sourceMappingURL=vendor-DxEOke6B.mjs.map