@forsakringskassan/docs-generator 2.27.2 → 2.28.1

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));
@@ -24151,8 +24151,7 @@ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
24151
24151
  }
24152
24152
  return matched;
24153
24153
  };
24154
- const deepFind = function (obj, path) {
24155
- let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
24154
+ const deepFind = (obj, path, keySeparator = '.') => {
24156
24155
  if (!obj) return undefined;
24157
24156
  if (obj[path]) {
24158
24157
  if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
@@ -24202,39 +24201,25 @@ const consoleLogger = {
24202
24201
  }
24203
24202
  };
24204
24203
  class Logger {
24205
- constructor(concreteLogger) {
24206
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24204
+ constructor(concreteLogger, options = {}) {
24207
24205
  this.init(concreteLogger, options);
24208
24206
  }
24209
- init(concreteLogger) {
24210
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24207
+ init(concreteLogger, options = {}) {
24211
24208
  this.prefix = options.prefix || 'i18next:';
24212
24209
  this.logger = concreteLogger || consoleLogger;
24213
24210
  this.options = options;
24214
24211
  this.debug = options.debug;
24215
24212
  }
24216
- log() {
24217
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24218
- args[_key] = arguments[_key];
24219
- }
24213
+ log(...args) {
24220
24214
  return this.forward(args, 'log', '', true);
24221
24215
  }
24222
- warn() {
24223
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
24224
- args[_key2] = arguments[_key2];
24225
- }
24216
+ warn(...args) {
24226
24217
  return this.forward(args, 'warn', '', true);
24227
24218
  }
24228
- error() {
24229
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
24230
- args[_key3] = arguments[_key3];
24231
- }
24219
+ error(...args) {
24232
24220
  return this.forward(args, 'error', '');
24233
24221
  }
24234
- deprecate() {
24235
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
24236
- args[_key4] = arguments[_key4];
24237
- }
24222
+ deprecate(...args) {
24238
24223
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
24239
24224
  }
24240
24225
  forward(args, lvl, prefix, debugOnly) {
@@ -24278,14 +24263,10 @@ class EventEmitter {
24278
24263
  }
24279
24264
  this.observers[event].delete(listener);
24280
24265
  }
24281
- emit(event) {
24282
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
24283
- args[_key - 1] = arguments[_key];
24284
- }
24266
+ emit(event, ...args) {
24285
24267
  if (this.observers[event]) {
24286
24268
  const cloned = Array.from(this.observers[event].entries());
24287
- cloned.forEach(_ref => {
24288
- let [observer, numTimesAdded] = _ref;
24269
+ cloned.forEach(([observer, numTimesAdded]) => {
24289
24270
  for (let i = 0; i < numTimesAdded; i++) {
24290
24271
  observer(...args);
24291
24272
  }
@@ -24293,8 +24274,7 @@ class EventEmitter {
24293
24274
  }
24294
24275
  if (this.observers['*']) {
24295
24276
  const cloned = Array.from(this.observers['*'].entries());
24296
- cloned.forEach(_ref2 => {
24297
- let [observer, numTimesAdded] = _ref2;
24277
+ cloned.forEach(([observer, numTimesAdded]) => {
24298
24278
  for (let i = 0; i < numTimesAdded; i++) {
24299
24279
  observer.apply(observer, [event, ...args]);
24300
24280
  }
@@ -24304,11 +24284,10 @@ class EventEmitter {
24304
24284
  }
24305
24285
 
24306
24286
  class ResourceStore extends EventEmitter {
24307
- constructor(data) {
24308
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
24309
- ns: ['translation'],
24310
- defaultNS: 'translation'
24311
- };
24287
+ constructor(data, options = {
24288
+ ns: ['translation'],
24289
+ defaultNS: 'translation'
24290
+ }) {
24312
24291
  super();
24313
24292
  this.data = data || {};
24314
24293
  this.options = options;
@@ -24330,8 +24309,7 @@ class ResourceStore extends EventEmitter {
24330
24309
  this.options.ns.splice(index, 1);
24331
24310
  }
24332
24311
  }
24333
- getResource(lng, ns, key) {
24334
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
24312
+ getResource(lng, ns, key, options = {}) {
24335
24313
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
24336
24314
  const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
24337
24315
  let path;
@@ -24358,10 +24336,9 @@ class ResourceStore extends EventEmitter {
24358
24336
  if (result || !ignoreJSONStructure || !isString(key)) return result;
24359
24337
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
24360
24338
  }
24361
- addResource(lng, ns, key, value) {
24362
- let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
24363
- silent: false
24364
- };
24339
+ addResource(lng, ns, key, value, options = {
24340
+ silent: false
24341
+ }) {
24365
24342
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
24366
24343
  let path = [lng, ns];
24367
24344
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
@@ -24374,10 +24351,9 @@ class ResourceStore extends EventEmitter {
24374
24351
  setPath(this.data, path, value);
24375
24352
  if (!options.silent) this.emit('added', lng, ns, key, value);
24376
24353
  }
24377
- addResources(lng, ns, resources) {
24378
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
24379
- silent: false
24380
- };
24354
+ addResources(lng, ns, resources, options = {
24355
+ silent: false
24356
+ }) {
24381
24357
  for (const m in resources) {
24382
24358
  if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
24383
24359
  silent: true
@@ -24385,11 +24361,10 @@ class ResourceStore extends EventEmitter {
24385
24361
  }
24386
24362
  if (!options.silent) this.emit('added', lng, ns, resources);
24387
24363
  }
24388
- addResourceBundle(lng, ns, resources, deep, overwrite) {
24389
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
24390
- silent: false,
24391
- skipCopy: false
24392
- };
24364
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
24365
+ silent: false,
24366
+ skipCopy: false
24367
+ }) {
24393
24368
  let path = [lng, ns];
24394
24369
  if (lng.indexOf('.') > -1) {
24395
24370
  path = lng.split('.');
@@ -24454,8 +24429,7 @@ var postProcessor = {
24454
24429
  const checkedLoadedFor = {};
24455
24430
  const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
24456
24431
  class Translator extends EventEmitter {
24457
- constructor(services) {
24458
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24432
+ constructor(services, options = {}) {
24459
24433
  super();
24460
24434
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
24461
24435
  this.options = options;
@@ -24467,10 +24441,9 @@ class Translator extends EventEmitter {
24467
24441
  changeLanguage(lng) {
24468
24442
  if (lng) this.language = lng;
24469
24443
  }
24470
- exists(key) {
24471
- let o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
24472
- interpolation: {}
24473
- };
24444
+ exists(key, o = {
24445
+ interpolation: {}
24446
+ }) {
24474
24447
  const opt = {
24475
24448
  ...o
24476
24449
  };
@@ -24522,11 +24495,12 @@ class Translator extends EventEmitter {
24522
24495
  namespaces
24523
24496
  } = this.extractFromKey(keys[keys.length - 1], opt);
24524
24497
  const namespace = namespaces[namespaces.length - 1];
24498
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
24499
+ if (nsSeparator === undefined) nsSeparator = ':';
24525
24500
  const lng = opt.lng || this.language;
24526
24501
  const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
24527
24502
  if (lng?.toLowerCase() === 'cimode') {
24528
24503
  if (appendNamespaceToCIMode) {
24529
- const nsSeparator = opt.nsSeparator || this.options.nsSeparator;
24530
24504
  if (returnDetails) {
24531
24505
  return {
24532
24506
  res: `${namespace}${nsSeparator}${key}`,
@@ -24681,9 +24655,11 @@ class Translator extends EventEmitter {
24681
24655
  }
24682
24656
  }
24683
24657
  res = this.extendTranslation(res, keys, opt, resolved, lastKey);
24684
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
24658
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
24659
+ res = `${namespace}${nsSeparator}${key}`;
24660
+ }
24685
24661
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
24686
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined, opt);
24662
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
24687
24663
  }
24688
24664
  }
24689
24665
  if (returnDetails) {
@@ -24694,7 +24670,6 @@ class Translator extends EventEmitter {
24694
24670
  return res;
24695
24671
  }
24696
24672
  extendTranslation(res, key, opt, resolved, lastKey) {
24697
- var _this = this;
24698
24673
  if (this.i18nFormat?.parse) {
24699
24674
  res = this.i18nFormat.parse(res, {
24700
24675
  ...this.options.interpolation.defaultVariables,
@@ -24730,15 +24705,12 @@ class Translator extends EventEmitter {
24730
24705
  if (nestBef < nestAft) opt.nest = false;
24731
24706
  }
24732
24707
  if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
24733
- if (opt.nest !== false) res = this.interpolator.nest(res, function () {
24734
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24735
- args[_key] = arguments[_key];
24736
- }
24708
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
24737
24709
  if (lastKey?.[0] === args[0] && !opt.context) {
24738
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
24710
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
24739
24711
  return null;
24740
24712
  }
24741
- return _this.translate(...args, key);
24713
+ return this.translate(...args, key);
24742
24714
  }, opt);
24743
24715
  if (opt.interpolation) this.interpolator.reset();
24744
24716
  }
@@ -24755,8 +24727,7 @@ class Translator extends EventEmitter {
24755
24727
  }
24756
24728
  return res;
24757
24729
  }
24758
- resolve(keys) {
24759
- let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24730
+ resolve(keys, opt = {}) {
24760
24731
  let found;
24761
24732
  let usedKey;
24762
24733
  let exactUsedKey;
@@ -24836,13 +24807,11 @@ class Translator extends EventEmitter {
24836
24807
  isValidLookup(res) {
24837
24808
  return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
24838
24809
  }
24839
- getResource(code, ns, key) {
24840
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
24810
+ getResource(code, ns, key, options = {}) {
24841
24811
  if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
24842
24812
  return this.resourceStore.getResource(code, ns, key, options);
24843
24813
  }
24844
- getUsedParamsDetails() {
24845
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24814
+ getUsedParamsDetails(options = {}) {
24846
24815
  const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
24847
24816
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
24848
24817
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -24999,8 +24968,7 @@ const dummyRule = {
24999
24968
  })
25000
24969
  };
25001
24970
  class PluralResolver {
25002
- constructor(languageUtils) {
25003
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24971
+ constructor(languageUtils, options = {}) {
25004
24972
  this.languageUtils = languageUtils;
25005
24973
  this.options = options;
25006
24974
  this.logger = baseLogger.create('pluralResolver');
@@ -25012,8 +24980,7 @@ class PluralResolver {
25012
24980
  clearCache() {
25013
24981
  this.pluralRulesCache = {};
25014
24982
  }
25015
- getRule(code) {
25016
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24983
+ getRule(code, options = {}) {
25017
24984
  const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
25018
24985
  const type = options.ordinal ? 'ordinal' : 'cardinal';
25019
24986
  const cacheKey = JSON.stringify({
@@ -25040,25 +25007,21 @@ class PluralResolver {
25040
25007
  this.pluralRulesCache[cacheKey] = rule;
25041
25008
  return rule;
25042
25009
  }
25043
- needsPlural(code) {
25044
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25010
+ needsPlural(code, options = {}) {
25045
25011
  let rule = this.getRule(code, options);
25046
25012
  if (!rule) rule = this.getRule('dev', options);
25047
25013
  return rule?.resolvedOptions().pluralCategories.length > 1;
25048
25014
  }
25049
- getPluralFormsOfKey(code, key) {
25050
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25015
+ getPluralFormsOfKey(code, key, options = {}) {
25051
25016
  return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
25052
25017
  }
25053
- getSuffixes(code) {
25054
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25018
+ getSuffixes(code, options = {}) {
25055
25019
  let rule = this.getRule(code, options);
25056
25020
  if (!rule) rule = this.getRule('dev', options);
25057
25021
  if (!rule) return [];
25058
25022
  return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
25059
25023
  }
25060
- getSuffix(code, count) {
25061
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25024
+ getSuffix(code, count, options = {}) {
25062
25025
  const rule = this.getRule(code, options);
25063
25026
  if (rule) {
25064
25027
  return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
@@ -25068,9 +25031,7 @@ class PluralResolver {
25068
25031
  }
25069
25032
  }
25070
25033
 
25071
- const deepFindWithDefaults = function (data, defaultData, key) {
25072
- let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
25073
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
25034
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignoreJSONStructure = true) => {
25074
25035
  let path = getPathWithDefaults(data, defaultData, key);
25075
25036
  if (!path && ignoreJSONStructure && isString(key)) {
25076
25037
  path = deepFind(data, key, keySeparator);
@@ -25080,15 +25041,13 @@ const deepFindWithDefaults = function (data, defaultData, key) {
25080
25041
  };
25081
25042
  const regexSafe = val => val.replace(/\$/g, '$$$$');
25082
25043
  class Interpolator {
25083
- constructor() {
25084
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25044
+ constructor(options = {}) {
25085
25045
  this.logger = baseLogger.create('interpolator');
25086
25046
  this.options = options;
25087
25047
  this.format = options?.interpolation?.format || (value => value);
25088
25048
  this.init(options);
25089
25049
  }
25090
- init() {
25091
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25050
+ init(options = {}) {
25092
25051
  if (!options.interpolation) options.interpolation = {
25093
25052
  escapeValue: true
25094
25053
  };
@@ -25211,8 +25170,7 @@ class Interpolator {
25211
25170
  });
25212
25171
  return str;
25213
25172
  }
25214
- nest(str, fc) {
25215
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25173
+ nest(str, fc, options = {}) {
25216
25174
  let match;
25217
25175
  let value;
25218
25176
  let clonedOptions;
@@ -25309,68 +25267,68 @@ const parseFormatStr = formatStr => {
25309
25267
  };
25310
25268
  const createCachedFormatter = fn => {
25311
25269
  const cache = {};
25312
- return (val, lng, options) => {
25313
- let optForCache = options;
25314
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
25270
+ return (v, l, o) => {
25271
+ let optForCache = o;
25272
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
25315
25273
  optForCache = {
25316
25274
  ...optForCache,
25317
- [options.interpolationkey]: undefined
25275
+ [o.interpolationkey]: undefined
25318
25276
  };
25319
25277
  }
25320
- const key = lng + JSON.stringify(optForCache);
25321
- let formatter = cache[key];
25322
- if (!formatter) {
25323
- formatter = fn(getCleanedCode(lng), options);
25324
- cache[key] = formatter;
25278
+ const key = l + JSON.stringify(optForCache);
25279
+ let frm = cache[key];
25280
+ if (!frm) {
25281
+ frm = fn(getCleanedCode(l), o);
25282
+ cache[key] = frm;
25325
25283
  }
25326
- return formatter(val);
25284
+ return frm(v);
25327
25285
  };
25328
25286
  };
25287
+ const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
25329
25288
  class Formatter {
25330
- constructor() {
25331
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25289
+ constructor(options = {}) {
25332
25290
  this.logger = baseLogger.create('formatter');
25333
25291
  this.options = options;
25292
+ this.init(options);
25293
+ }
25294
+ init(services, options = {
25295
+ interpolation: {}
25296
+ }) {
25297
+ this.formatSeparator = options.interpolation.formatSeparator || ',';
25298
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
25334
25299
  this.formats = {
25335
- number: createCachedFormatter((lng, opt) => {
25300
+ number: cf((lng, opt) => {
25336
25301
  const formatter = new Intl.NumberFormat(lng, {
25337
25302
  ...opt
25338
25303
  });
25339
25304
  return val => formatter.format(val);
25340
25305
  }),
25341
- currency: createCachedFormatter((lng, opt) => {
25306
+ currency: cf((lng, opt) => {
25342
25307
  const formatter = new Intl.NumberFormat(lng, {
25343
25308
  ...opt,
25344
25309
  style: 'currency'
25345
25310
  });
25346
25311
  return val => formatter.format(val);
25347
25312
  }),
25348
- datetime: createCachedFormatter((lng, opt) => {
25313
+ datetime: cf((lng, opt) => {
25349
25314
  const formatter = new Intl.DateTimeFormat(lng, {
25350
25315
  ...opt
25351
25316
  });
25352
25317
  return val => formatter.format(val);
25353
25318
  }),
25354
- relativetime: createCachedFormatter((lng, opt) => {
25319
+ relativetime: cf((lng, opt) => {
25355
25320
  const formatter = new Intl.RelativeTimeFormat(lng, {
25356
25321
  ...opt
25357
25322
  });
25358
25323
  return val => formatter.format(val, opt.range || 'day');
25359
25324
  }),
25360
- list: createCachedFormatter((lng, opt) => {
25325
+ list: cf((lng, opt) => {
25361
25326
  const formatter = new Intl.ListFormat(lng, {
25362
25327
  ...opt
25363
25328
  });
25364
25329
  return val => formatter.format(val);
25365
25330
  })
25366
25331
  };
25367
- this.init(options);
25368
- }
25369
- init(services) {
25370
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
25371
- interpolation: {}
25372
- };
25373
- this.formatSeparator = options.interpolation.formatSeparator || ',';
25374
25332
  }
25375
25333
  add(name, fc) {
25376
25334
  this.formats[name.toLowerCase().trim()] = fc;
@@ -25378,8 +25336,7 @@ class Formatter {
25378
25336
  addCached(name, fc) {
25379
25337
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
25380
25338
  }
25381
- format(value, format, lng) {
25382
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
25339
+ format(value, format, lng, options = {}) {
25383
25340
  const formats = format.split(this.formatSeparator);
25384
25341
  if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
25385
25342
  const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
@@ -25420,8 +25377,7 @@ const removePending = (q, name) => {
25420
25377
  }
25421
25378
  };
25422
25379
  class Connector extends EventEmitter {
25423
- constructor(backend, store, services) {
25424
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
25380
+ constructor(backend, store, services, options = {}) {
25425
25381
  super();
25426
25382
  this.backend = backend;
25427
25383
  this.store = store;
@@ -25515,10 +25471,7 @@ class Connector extends EventEmitter {
25515
25471
  this.emit('loaded', loaded);
25516
25472
  this.queue = this.queue.filter(q => !q.done);
25517
25473
  }
25518
- read(lng, ns, fcName) {
25519
- let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
25520
- let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
25521
- let callback = arguments.length > 5 ? arguments[5] : undefined;
25474
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
25522
25475
  if (!lng.length) return callback(null, {});
25523
25476
  if (this.readingCalls >= this.maxParallelReads) {
25524
25477
  this.waitingReads.push({
@@ -25562,9 +25515,7 @@ class Connector extends EventEmitter {
25562
25515
  }
25563
25516
  return fc(lng, ns, resolver);
25564
25517
  }
25565
- prepareLoading(languages, namespaces) {
25566
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25567
- let callback = arguments.length > 3 ? arguments[3] : undefined;
25518
+ prepareLoading(languages, namespaces, options = {}, callback) {
25568
25519
  if (!this.backend) {
25569
25520
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
25570
25521
  return callback && callback();
@@ -25588,8 +25539,7 @@ class Connector extends EventEmitter {
25588
25539
  reload: true
25589
25540
  }, callback);
25590
25541
  }
25591
- loadOne(name) {
25592
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
25542
+ loadOne(name, prefix = '') {
25593
25543
  const s = name.split('|');
25594
25544
  const lng = s[0];
25595
25545
  const ns = s[1];
@@ -25599,9 +25549,7 @@ class Connector extends EventEmitter {
25599
25549
  this.loaded(name, err, data);
25600
25550
  });
25601
25551
  }
25602
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
25603
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
25604
- let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
25552
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
25605
25553
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
25606
25554
  this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
25607
25555
  return;
@@ -25696,7 +25644,8 @@ const get$1 = () => ({
25696
25644
  nestingOptionsSeparator: ',',
25697
25645
  maxReplaces: 1000,
25698
25646
  skipOnVariables: true
25699
- }
25647
+ },
25648
+ cacheInBuiltFormats: true
25700
25649
  });
25701
25650
  const transformOptions = options => {
25702
25651
  if (isString(options.ns)) options.ns = [options.ns];
@@ -25719,9 +25668,7 @@ const bindMemberFunctions = inst => {
25719
25668
  });
25720
25669
  };
25721
25670
  class I18n extends EventEmitter {
25722
- constructor() {
25723
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25724
- let callback = arguments.length > 1 ? arguments[1] : undefined;
25671
+ constructor(options = {}, callback) {
25725
25672
  super();
25726
25673
  this.options = transformOptions(options);
25727
25674
  this.services = {};
@@ -25740,10 +25687,7 @@ class I18n extends EventEmitter {
25740
25687
  }, 0);
25741
25688
  }
25742
25689
  }
25743
- init() {
25744
- var _this = this;
25745
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25746
- let callback = arguments.length > 1 ? arguments[1] : undefined;
25690
+ init(options = {}, callback) {
25747
25691
  this.isInitializing = true;
25748
25692
  if (typeof options === 'function') {
25749
25693
  callback = options;
@@ -25809,11 +25753,8 @@ class I18n extends EventEmitter {
25809
25753
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
25810
25754
  };
25811
25755
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
25812
- s.backendConnector.on('*', function (event) {
25813
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
25814
- args[_key - 1] = arguments[_key];
25815
- }
25816
- _this.emit(event, ...args);
25756
+ s.backendConnector.on('*', (event, ...args) => {
25757
+ this.emit(event, ...args);
25817
25758
  });
25818
25759
  if (this.modules.languageDetector) {
25819
25760
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -25824,11 +25765,8 @@ class I18n extends EventEmitter {
25824
25765
  if (s.i18nFormat.init) s.i18nFormat.init(this);
25825
25766
  }
25826
25767
  this.translator = new Translator(this.services, this.options);
25827
- this.translator.on('*', function (event) {
25828
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
25829
- args[_key2 - 1] = arguments[_key2];
25830
- }
25831
- _this.emit(event, ...args);
25768
+ this.translator.on('*', (event, ...args) => {
25769
+ this.emit(event, ...args);
25832
25770
  });
25833
25771
  this.modules.external.forEach(m => {
25834
25772
  if (m.init) m.init(this);
@@ -25845,15 +25783,13 @@ class I18n extends EventEmitter {
25845
25783
  }
25846
25784
  const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
25847
25785
  storeApi.forEach(fcName => {
25848
- this[fcName] = function () {
25849
- return _this.store[fcName](...arguments);
25850
- };
25786
+ this[fcName] = (...args) => this.store[fcName](...args);
25851
25787
  });
25852
25788
  const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
25853
25789
  storeApiChained.forEach(fcName => {
25854
- this[fcName] = function () {
25855
- _this.store[fcName](...arguments);
25856
- return _this;
25790
+ this[fcName] = (...args) => {
25791
+ this.store[fcName](...args);
25792
+ return this;
25857
25793
  };
25858
25794
  });
25859
25795
  const deferred = defer();
@@ -25877,8 +25813,7 @@ class I18n extends EventEmitter {
25877
25813
  }
25878
25814
  return deferred;
25879
25815
  }
25880
- loadResources(language) {
25881
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
25816
+ loadResources(language, callback = noop) {
25882
25817
  let usedCallback = callback;
25883
25818
  const usedLng = isString(language) ? language : this.language;
25884
25819
  if (typeof language === 'function') usedCallback = language;
@@ -25971,7 +25906,6 @@ class I18n extends EventEmitter {
25971
25906
  }
25972
25907
  }
25973
25908
  changeLanguage(lng, callback) {
25974
- var _this2 = this;
25975
25909
  this.isLanguageChangingTo = lng;
25976
25910
  const deferred = defer();
25977
25911
  this.emit('languageChanging', lng);
@@ -25993,12 +25927,8 @@ class I18n extends EventEmitter {
25993
25927
  } else {
25994
25928
  this.isLanguageChangingTo = undefined;
25995
25929
  }
25996
- deferred.resolve(function () {
25997
- return _this2.t(...arguments);
25998
- });
25999
- if (callback) callback(err, function () {
26000
- return _this2.t(...arguments);
26001
- });
25930
+ deferred.resolve((...args) => this.t(...args));
25931
+ if (callback) callback(err, (...args) => this.t(...args));
26002
25932
  };
26003
25933
  const setLng = lngs => {
26004
25934
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
@@ -26029,14 +25959,10 @@ class I18n extends EventEmitter {
26029
25959
  return deferred;
26030
25960
  }
26031
25961
  getFixedT(lng, ns, keyPrefix) {
26032
- var _this3 = this;
26033
- const fixedT = function (key, opts) {
25962
+ const fixedT = (key, opts, ...rest) => {
26034
25963
  let o;
26035
25964
  if (typeof opts !== 'object') {
26036
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
26037
- rest[_key3 - 2] = arguments[_key3];
26038
- }
26039
- o = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
25965
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
26040
25966
  } else {
26041
25967
  o = {
26042
25968
  ...opts
@@ -26046,14 +25972,14 @@ class I18n extends EventEmitter {
26046
25972
  o.lngs = o.lngs || fixedT.lngs;
26047
25973
  o.ns = o.ns || fixedT.ns;
26048
25974
  if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
26049
- const keySeparator = _this3.options.keySeparator || '.';
25975
+ const keySeparator = this.options.keySeparator || '.';
26050
25976
  let resultKey;
26051
25977
  if (o.keyPrefix && Array.isArray(key)) {
26052
25978
  resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
26053
25979
  } else {
26054
25980
  resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
26055
25981
  }
26056
- return _this3.t(resultKey, o);
25982
+ return this.t(resultKey, o);
26057
25983
  };
26058
25984
  if (isString(lng)) {
26059
25985
  fixedT.lng = lng;
@@ -26064,23 +25990,16 @@ class I18n extends EventEmitter {
26064
25990
  fixedT.keyPrefix = keyPrefix;
26065
25991
  return fixedT;
26066
25992
  }
26067
- t() {
26068
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
26069
- args[_key4] = arguments[_key4];
26070
- }
25993
+ t(...args) {
26071
25994
  return this.translator?.translate(...args);
26072
25995
  }
26073
- exists() {
26074
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
26075
- args[_key5] = arguments[_key5];
26076
- }
25996
+ exists(...args) {
26077
25997
  return this.translator?.exists(...args);
26078
25998
  }
26079
25999
  setDefaultNamespace(ns) {
26080
26000
  this.options.defaultNS = ns;
26081
26001
  }
26082
- hasLoadedNamespace(ns) {
26083
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26002
+ hasLoadedNamespace(ns, options = {}) {
26084
26003
  if (!this.isInitialized) {
26085
26004
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
26086
26005
  return false;
@@ -26145,14 +26064,10 @@ class I18n extends EventEmitter {
26145
26064
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get$1());
26146
26065
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
26147
26066
  }
26148
- static createInstance() {
26149
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26150
- let callback = arguments.length > 1 ? arguments[1] : undefined;
26067
+ static createInstance(options = {}, callback) {
26151
26068
  return new I18n(options, callback);
26152
26069
  }
26153
- cloneInstance() {
26154
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26155
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
26070
+ cloneInstance(options = {}, callback = noop) {
26156
26071
  const forkResourceStore = options.forkResourceStore;
26157
26072
  if (forkResourceStore) delete options.forkResourceStore;
26158
26073
  const mergedOptions = {
@@ -26193,10 +26108,7 @@ class I18n extends EventEmitter {
26193
26108
  clone.services.resourceStore = clone.store;
26194
26109
  }
26195
26110
  clone.translator = new Translator(clone.services, mergedOptions);
26196
- clone.translator.on('*', function (event) {
26197
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
26198
- args[_key6 - 1] = arguments[_key6];
26199
- }
26111
+ clone.translator.on('*', (event, ...args) => {
26200
26112
  clone.emit(event, ...args);
26201
26113
  });
26202
26114
  clone.init(mergedOptions, callback);
@@ -28558,366 +28470,425 @@ function deflist_plugin (md) {
28558
28470
  md.block.ruler.before('paragraph', 'deflist', deflist, { alt: ['paragraph', 'reference', 'blockquote'] });
28559
28471
  }
28560
28472
 
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 = {};
28473
+ var Diff = /** @class */ (function () {
28474
+ function Diff() {
28570
28475
  }
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
- }
28582
- }
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;
28476
+ Diff.prototype.diff = function (oldStr, newStr,
28477
+ // Type below is not accurate/complete - see above for full possibilities - but it compiles
28478
+ options) {
28479
+ if (options === void 0) { options = {}; }
28480
+ var callback;
28481
+ if (typeof options === 'function') {
28482
+ callback = options;
28483
+ options = {};
28651
28484
  }
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);
28485
+ else if ('callback' in options) {
28486
+ callback = options.callback;
28660
28487
  }
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
- }
28488
+ // Allow subclasses to massage the input prior to running
28489
+ var oldString = this.castInput(oldStr, options);
28490
+ var newString = this.castInput(newStr, options);
28491
+ var oldTokens = this.removeEmpty(this.tokenize(oldString, options));
28492
+ var newTokens = this.removeEmpty(this.tokenize(newString, options));
28493
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
28494
+ };
28495
+ Diff.prototype.diffWithOptionsObj = function (oldTokens, newTokens, options, callback) {
28496
+ var _this = this;
28497
+ var _a;
28498
+ var done = function (value) {
28499
+ value = _this.postProcess(value, options);
28500
+ if (callback) {
28501
+ setTimeout(function () { callback(value); }, 0);
28502
+ return undefined;
28503
+ }
28504
+ else {
28505
+ return value;
28506
+ }
28507
+ };
28508
+ var newLen = newTokens.length, oldLen = oldTokens.length;
28509
+ var editLength = 1;
28510
+ var maxEditLength = newLen + oldLen;
28511
+ if (options.maxEditLength != null) {
28512
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
28513
+ }
28514
+ var maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
28515
+ var abortAfterTimestamp = Date.now() + maxExecutionTime;
28516
+ var bestPath = [{ oldPos: -1, lastComponent: undefined }];
28517
+ // Seed editLength = 0, i.e. the content starts with the same values
28518
+ var newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
28519
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28520
+ // Identity per the equality and tokenizer
28521
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
28522
+ }
28523
+ // Once we hit the right edge of the edit graph on some diagonal k, we can
28524
+ // definitely reach the end of the edit graph in no more than k edits, so
28525
+ // there's no point in considering any moves to diagonal k+1 any more (from
28526
+ // which we're guaranteed to need at least k+1 more edits).
28527
+ // Similarly, once we've reached the bottom of the edit graph, there's no
28528
+ // point considering moves to lower diagonals.
28529
+ // We record this fact by setting minDiagonalToConsider and
28530
+ // maxDiagonalToConsider to some finite value once we've hit the edge of
28531
+ // the edit graph.
28532
+ // This optimization is not faithful to the original algorithm presented in
28533
+ // Myers's paper, which instead pointlessly extends D-paths off the end of
28534
+ // the edit graph - see page 7 of Myers's paper which notes this point
28535
+ // explicitly and illustrates it with a diagram. This has major performance
28536
+ // implications for some common scenarios. For instance, to compute a diff
28537
+ // where the new text simply appends d characters on the end of the
28538
+ // original text of length n, the true Myers algorithm will take O(n+d^2)
28539
+ // time while this optimization needs only O(n+d) time.
28540
+ var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
28541
+ // Main worker method. checks all permutations of a given edit length for acceptance.
28542
+ var execEditLength = function () {
28543
+ for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
28544
+ var basePath = void 0;
28545
+ var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
28546
+ if (removePath) {
28547
+ // No one else is going to attempt to use this value, clear it
28548
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
28549
+ bestPath[diagonalPath - 1] = undefined;
28550
+ }
28551
+ var canAdd = false;
28552
+ if (addPath) {
28553
+ // what newPos will be after we do an insertion:
28554
+ var addPathNewPos = addPath.oldPos - diagonalPath;
28555
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
28556
+ }
28557
+ var canRemove = removePath && removePath.oldPos + 1 < oldLen;
28558
+ if (!canAdd && !canRemove) {
28559
+ // If this path is a terminal then prune
28560
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
28561
+ bestPath[diagonalPath] = undefined;
28562
+ continue;
28563
+ }
28564
+ // Select the diagonal that we want to branch from. We select the prior
28565
+ // path whose position in the old string is the farthest from the origin
28566
+ // and does not pass the bounds of the diff graph
28567
+ if (!canRemove || (canAdd && removePath.oldPos < addPath.oldPos)) {
28568
+ basePath = _this.addToPath(addPath, true, false, 0, options);
28569
+ }
28570
+ else {
28571
+ basePath = _this.addToPath(removePath, false, true, 1, options);
28572
+ }
28573
+ newPos = _this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
28574
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
28575
+ // If we have hit the end of both strings, then we are done
28576
+ return done(_this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
28577
+ }
28578
+ else {
28579
+ bestPath[diagonalPath] = basePath;
28580
+ if (basePath.oldPos + 1 >= oldLen) {
28581
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
28582
+ }
28583
+ if (newPos + 1 >= newLen) {
28584
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
28585
+ }
28586
+ }
28587
+ }
28588
+ editLength++;
28589
+ };
28590
+ // Performs the length of edit iteration. Is a bit fugly as this has to support the
28591
+ // sync and async mode which is never fun. Loops over execEditLength until a value
28592
+ // is produced, or until the edit length exceeds options.maxEditLength (if given),
28593
+ // in which case it will return undefined.
28594
+ if (callback) {
28595
+ (function exec() {
28596
+ setTimeout(function () {
28597
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
28598
+ return callback(undefined);
28599
+ }
28600
+ if (!execEditLength()) {
28601
+ exec();
28602
+ }
28603
+ }, 0);
28604
+ }());
28673
28605
  }
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;
28606
+ else {
28607
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
28608
+ var ret = execEditLength();
28609
+ if (ret) {
28610
+ return ret;
28611
+ }
28612
+ }
28698
28613
  }
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
28614
+ };
28615
+ Diff.prototype.addToPath = function (path, added, removed, oldPosInc, options) {
28616
+ var last = path.lastComponent;
28617
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
28618
+ return {
28619
+ oldPos: path.oldPos + oldPosInc,
28620
+ lastComponent: { count: last.count + 1, added: added, removed: removed, previousComponent: last.previousComponent }
28621
+ };
28712
28622
  }
28713
- };
28714
- } else {
28715
- return {
28716
- oldPos: path.oldPos + oldPosInc,
28717
- lastComponent: {
28718
- count: 1,
28719
- added: added,
28720
- removed: removed,
28721
- previousComponent: last
28623
+ else {
28624
+ return {
28625
+ oldPos: path.oldPos + oldPosInc,
28626
+ lastComponent: { count: 1, added: added, removed: removed, previousComponent: last }
28627
+ };
28722
28628
  }
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;
28629
+ };
28630
+ Diff.prototype.extractCommon = function (basePath, newTokens, oldTokens, diagonalPath, options) {
28631
+ var newLen = newTokens.length, oldLen = oldTokens.length;
28632
+ var oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
28633
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
28634
+ newPos++;
28635
+ oldPos++;
28636
+ commonCount++;
28637
+ if (options.oneChangePerToken) {
28638
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
28639
+ }
28640
+ }
28641
+ if (commonCount && !options.oneChangePerToken) {
28642
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
28643
+ }
28644
+ basePath.oldPos = oldPos;
28645
+ return newPos;
28646
+ };
28647
+ Diff.prototype.equals = function (left, right, options) {
28648
+ if (options.comparator) {
28649
+ return options.comparator(left, right);
28650
+ }
28651
+ else {
28652
+ return left === right
28653
+ || (!!options.ignoreCase && left.toLowerCase() === right.toLowerCase());
28654
+ }
28655
+ };
28656
+ Diff.prototype.removeEmpty = function (array) {
28657
+ var ret = [];
28658
+ for (var i = 0; i < array.length; i++) {
28659
+ if (array[i]) {
28660
+ ret.push(array[i]);
28661
+ }
28662
+ }
28663
+ return ret;
28664
+ };
28665
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28666
+ Diff.prototype.castInput = function (value, options) {
28667
+ return value;
28668
+ };
28669
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28670
+ Diff.prototype.tokenize = function (value, options) {
28671
+ return Array.from(value);
28672
+ };
28673
+ Diff.prototype.join = function (chars) {
28674
+ // Assumes ValueT is string, which is the case for most subclasses.
28675
+ // When it's false, e.g. in diffArrays, this method needs to be overridden (e.g. with a no-op)
28676
+ // Yes, the casts are verbose and ugly, because this pattern - of having the base class SORT OF
28677
+ // assume tokens and values are strings, but not completely - is weird and janky.
28678
+ return chars.join('');
28679
+ };
28680
+ Diff.prototype.postProcess = function (changeObjects,
28681
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28682
+ options) {
28683
+ return changeObjects;
28684
+ };
28685
+ Object.defineProperty(Diff.prototype, "useLongestToken", {
28686
+ get: function () {
28687
+ return false;
28688
+ },
28689
+ enumerable: false,
28690
+ configurable: true
28691
+ });
28692
+ Diff.prototype.buildValues = function (lastComponent, newTokens, oldTokens) {
28693
+ // First we convert our linked list of components in reverse order to an
28694
+ // array in the right order:
28695
+ var components = [];
28696
+ var nextComponent;
28697
+ while (lastComponent) {
28698
+ components.push(lastComponent);
28699
+ nextComponent = lastComponent.previousComponent;
28700
+ delete lastComponent.previousComponent;
28701
+ lastComponent = nextComponent;
28702
+ }
28703
+ components.reverse();
28704
+ var componentLen = components.length;
28705
+ var componentPos = 0, newPos = 0, oldPos = 0;
28706
+ for (; componentPos < componentLen; componentPos++) {
28707
+ var component = components[componentPos];
28708
+ if (!component.removed) {
28709
+ if (!component.added && this.useLongestToken) {
28710
+ var value = newTokens.slice(newPos, newPos + component.count);
28711
+ value = value.map(function (value, i) {
28712
+ var oldValue = oldTokens[oldPos + i];
28713
+ return oldValue.length > value.length ? oldValue : value;
28714
+ });
28715
+ component.value = this.join(value);
28716
+ }
28717
+ else {
28718
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
28719
+ }
28720
+ newPos += component.count;
28721
+ // Common case
28722
+ if (!component.added) {
28723
+ oldPos += component.count;
28724
+ }
28725
+ }
28726
+ else {
28727
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
28728
+ oldPos += component.count;
28729
+ }
28730
+ }
28731
+ return components;
28732
+ };
28733
+ return Diff;
28734
+ }());
28735
+
28736
+ var __extends$6 = (undefined && undefined.__extends) || (function () {
28737
+ var extendStatics = function (d, b) {
28738
+ extendStatics = Object.setPrototypeOf ||
28739
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28740
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28741
+ return extendStatics(d, b);
28742
+ };
28743
+ return function (d, b) {
28744
+ if (typeof b !== "function" && b !== null)
28745
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28746
+ extendStatics(d, b);
28747
+ function __() { this.constructor = d; }
28748
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28749
+ };
28750
+ })();
28751
+ var CharacterDiff = /** @class */ (function (_super) {
28752
+ __extends$6(CharacterDiff, _super);
28753
+ function CharacterDiff() {
28754
+ return _super !== null && _super.apply(this, arguments) || this;
28823
28755
  }
28824
- }
28825
- return components;
28826
- }
28756
+ return CharacterDiff;
28757
+ }(Diff));
28758
+ new CharacterDiff();
28827
28759
 
28828
28760
  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);
28761
+ var i;
28762
+ for (i = 0; i < str1.length && i < str2.length; i++) {
28763
+ if (str1[i] != str2[i]) {
28764
+ return str1.slice(0, i);
28765
+ }
28833
28766
  }
28834
- }
28835
- return str1.slice(0, i);
28767
+ return str1.slice(0, i);
28836
28768
  }
28837
28769
  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);
28770
+ var i;
28771
+ // Unlike longestCommonPrefix, we need a special case to handle all scenarios
28772
+ // where we return the empty string since str1.slice(-0) will return the
28773
+ // entire string.
28774
+ if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) {
28775
+ return '';
28849
28776
  }
28850
- }
28851
- return str1.slice(-i);
28777
+ for (i = 0; i < str1.length && i < str2.length; i++) {
28778
+ if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) {
28779
+ return str1.slice(-i);
28780
+ }
28781
+ }
28782
+ return str1.slice(-i);
28852
28783
  }
28853
28784
  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);
28785
+ if (string.slice(0, oldPrefix.length) != oldPrefix) {
28786
+ throw Error("string ".concat(JSON.stringify(string), " doesn't start with prefix ").concat(JSON.stringify(oldPrefix), "; this is a bug"));
28787
+ }
28788
+ return newPrefix + string.slice(oldPrefix.length);
28858
28789
  }
28859
28790
  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;
28791
+ if (!oldSuffix) {
28792
+ return string + newSuffix;
28793
+ }
28794
+ if (string.slice(-oldSuffix.length) != oldSuffix) {
28795
+ throw Error("string ".concat(JSON.stringify(string), " doesn't end with suffix ").concat(JSON.stringify(oldSuffix), "; this is a bug"));
28796
+ }
28797
+ return string.slice(0, -oldSuffix.length) + newSuffix;
28867
28798
  }
28868
28799
  function removePrefix(string, oldPrefix) {
28869
- return replacePrefix(string, oldPrefix, '');
28800
+ return replacePrefix(string, oldPrefix, '');
28870
28801
  }
28871
28802
  function removeSuffix(string, oldSuffix) {
28872
- return replaceSuffix(string, oldSuffix, '');
28803
+ return replaceSuffix(string, oldSuffix, '');
28873
28804
  }
28874
28805
  function maximumOverlap(string1, string2) {
28875
- return string2.slice(0, overlapCount(string1, string2));
28806
+ return string2.slice(0, overlapCount(string1, string2));
28876
28807
  }
28877
-
28878
28808
  // Nicked from https://stackoverflow.com/a/60422853/1709587
28879
28809
  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;
28900
- }
28901
- while (k > 0 && b[j] != b[k]) {
28902
- k = map[k];
28810
+ // Deal with cases where the strings differ in length
28811
+ var startA = 0;
28812
+ if (a.length > b.length) {
28813
+ startA = a.length - b.length;
28903
28814
  }
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++;
28815
+ var endB = b.length;
28816
+ if (a.length < b.length) {
28817
+ endB = a.length;
28818
+ }
28819
+ // Create a back-reference for each index
28820
+ // that should be followed in case of a mismatch.
28821
+ // We only need B to make these references:
28822
+ var map = Array(endB);
28823
+ var k = 0; // Index that lags behind j
28824
+ map[0] = 0;
28825
+ for (var j = 1; j < endB; j++) {
28826
+ if (b[j] == b[k]) {
28827
+ map[j] = map[k]; // skip over the same character (optional optimisation)
28828
+ }
28829
+ else {
28830
+ map[j] = k;
28831
+ }
28832
+ while (k > 0 && b[j] != b[k]) {
28833
+ k = map[k];
28834
+ }
28835
+ if (b[j] == b[k]) {
28836
+ k++;
28837
+ }
28838
+ }
28839
+ // Phase 2: use these references while iterating over A
28840
+ k = 0;
28841
+ for (var i = startA; i < a.length; i++) {
28842
+ while (k > 0 && a[i] != b[k]) {
28843
+ k = map[k];
28844
+ }
28845
+ if (a[i] == b[k]) {
28846
+ k++;
28847
+ }
28848
+ }
28849
+ return k;
28850
+ }
28851
+ function trailingWs(string) {
28852
+ // Yes, this looks overcomplicated and dumb - why not replace the whole function with
28853
+ // return string match(/\s*$/)[0]
28854
+ // you ask? Because:
28855
+ // 1. the trap described at https://markamery.com/blog/quadratic-time-regexes/ would mean doing
28856
+ // this would cause this function to take O(n²) time in the worst case (specifically when
28857
+ // there is a massive run of NON-TRAILING whitespace in `string`), and
28858
+ // 2. the fix proposed in the same blog post, of using a negative lookbehind, is incompatible
28859
+ // with old Safari versions that we'd like to not break if possible (see
28860
+ // https://github.com/kpdecker/jsdiff/pull/550)
28861
+ // It feels absurd to do this with an explicit loop instead of a regex, but I really can't see a
28862
+ // better way that doesn't result in broken behaviour.
28863
+ var i;
28864
+ for (i = string.length - 1; i >= 0; i--) {
28865
+ if (!string[i].match(/\s/)) {
28866
+ break;
28867
+ }
28916
28868
  }
28917
- }
28918
- return k;
28869
+ return string.substring(i + 1);
28870
+ }
28871
+ function leadingWs(string) {
28872
+ // Thankfully the annoying considerations described in trailingWs don't apply here:
28873
+ var match = string.match(/^\s*/);
28874
+ return match ? match[0] : '';
28919
28875
  }
28920
28876
 
28877
+ var __extends$5 = (undefined && undefined.__extends) || (function () {
28878
+ var extendStatics = function (d, b) {
28879
+ extendStatics = Object.setPrototypeOf ||
28880
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
28881
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
28882
+ return extendStatics(d, b);
28883
+ };
28884
+ return function (d, b) {
28885
+ if (typeof b !== "function" && b !== null)
28886
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28887
+ extendStatics(d, b);
28888
+ function __() { this.constructor = d; }
28889
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28890
+ };
28891
+ })();
28921
28892
  // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
28922
28893
  //
28923
28894
  // Ranges and exceptions:
@@ -28936,8 +28907,7 @@ function overlapCount(a, b) {
28936
28907
  // - U+02DC ˜ &#732; Small Tilde
28937
28908
  // - U+02DD ˝ &#733; Double Acute Accent
28938
28909
  // 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
-
28910
+ 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
28911
  // Each token is one of the following:
28942
28912
  // - A punctuation mark plus the surrounding whitespace
28943
28913
  // - A word plus the surrounding whitespace
@@ -28958,652 +28928,737 @@ var extendedWordChars = "a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6
28958
28928
  //
28959
28929
  // Keeping the surrounding whitespace of course has implications for .equals
28960
28930
  // and .join, not just .tokenize.
28961
-
28962
28931
  // This regex does NOT fully implement the tokenization rules described above.
28963
28932
  // Instead, it gives runs of whitespace their own "token". The tokenize method
28964
28933
  // then handles stitching whitespace tokens onto adjacent word or punctuation
28965
28934
  // tokens.
28966
28935
  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+/, '');
29021
- }
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;
28936
+ var WordDiff = /** @class */ (function (_super) {
28937
+ __extends$5(WordDiff, _super);
28938
+ function WordDiff() {
28939
+ return _super !== null && _super.apply(this, arguments) || this;
29046
28940
  }
29047
- });
29048
- if (insertion || deletion) {
29049
- dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
29050
- }
29051
- return changes;
29052
- };
28941
+ WordDiff.prototype.equals = function (left, right, options) {
28942
+ if (options.ignoreCase) {
28943
+ left = left.toLowerCase();
28944
+ right = right.toLowerCase();
28945
+ }
28946
+ return left.trim() === right.trim();
28947
+ };
28948
+ WordDiff.prototype.tokenize = function (value, options) {
28949
+ if (options === void 0) { options = {}; }
28950
+ var parts;
28951
+ if (options.intlSegmenter) {
28952
+ var segmenter = options.intlSegmenter;
28953
+ if (segmenter.resolvedOptions().granularity != 'word') {
28954
+ throw new Error('The segmenter passed must have a granularity of "word"');
28955
+ }
28956
+ parts = Array.from(segmenter.segment(value), function (segment) { return segment.segment; });
28957
+ }
28958
+ else {
28959
+ parts = value.match(tokenizeIncludingWhitespace) || [];
28960
+ }
28961
+ var tokens = [];
28962
+ var prevPart = null;
28963
+ parts.forEach(function (part) {
28964
+ if ((/\s/).test(part)) {
28965
+ if (prevPart == null) {
28966
+ tokens.push(part);
28967
+ }
28968
+ else {
28969
+ tokens.push(tokens.pop() + part);
28970
+ }
28971
+ }
28972
+ else if (prevPart != null && (/\s/).test(prevPart)) {
28973
+ if (tokens[tokens.length - 1] == prevPart) {
28974
+ tokens.push(tokens.pop() + part);
28975
+ }
28976
+ else {
28977
+ tokens.push(prevPart + part);
28978
+ }
28979
+ }
28980
+ else {
28981
+ tokens.push(part);
28982
+ }
28983
+ prevPart = part;
28984
+ });
28985
+ return tokens;
28986
+ };
28987
+ WordDiff.prototype.join = function (tokens) {
28988
+ // Tokens being joined here will always have appeared consecutively in the
28989
+ // same text, so we can simply strip off the leading whitespace from all the
28990
+ // tokens except the first (and except any whitespace-only tokens - but such
28991
+ // a token will always be the first and only token anyway) and then join them
28992
+ // and the whitespace around words and punctuation will end up correct.
28993
+ return tokens.map(function (token, i) {
28994
+ if (i == 0) {
28995
+ return token;
28996
+ }
28997
+ else {
28998
+ return token.replace((/^\s+/), '');
28999
+ }
29000
+ }).join('');
29001
+ };
29002
+ WordDiff.prototype.postProcess = function (changes, options) {
29003
+ if (!changes || options.oneChangePerToken) {
29004
+ return changes;
29005
+ }
29006
+ var lastKeep = null;
29007
+ // Change objects representing any insertion or deletion since the last
29008
+ // "keep" change object. There can be at most one of each.
29009
+ var insertion = null;
29010
+ var deletion = null;
29011
+ changes.forEach(function (change) {
29012
+ if (change.added) {
29013
+ insertion = change;
29014
+ }
29015
+ else if (change.removed) {
29016
+ deletion = change;
29017
+ }
29018
+ else {
29019
+ if (insertion || deletion) { // May be false at start of text
29020
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change);
29021
+ }
29022
+ lastKeep = change;
29023
+ insertion = null;
29024
+ deletion = null;
29025
+ }
29026
+ });
29027
+ if (insertion || deletion) {
29028
+ dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null);
29029
+ }
29030
+ return changes;
29031
+ };
29032
+ return WordDiff;
29033
+ }(Diff));
29034
+ new WordDiff();
29053
29035
  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);
29036
+ // Before returning, we tidy up the leading and trailing whitespace of the
29037
+ // change objects to eliminate cases where trailing whitespace in one object
29038
+ // is repeated as leading whitespace in the next.
29039
+ // Below are examples of the outcomes we want here to explain the code.
29040
+ // I=insert, K=keep, D=delete
29041
+ // 1. diffing 'foo bar baz' vs 'foo baz'
29042
+ // Prior to cleanup, we have K:'foo ' D:' bar ' K:' baz'
29043
+ // After cleanup, we want: K:'foo ' D:'bar ' K:'baz'
29044
+ //
29045
+ // 2. Diffing 'foo bar baz' vs 'foo qux baz'
29046
+ // Prior to cleanup, we have K:'foo ' D:' bar ' I:' qux ' K:' baz'
29047
+ // After cleanup, we want K:'foo ' D:'bar' I:'qux' K:' baz'
29048
+ //
29049
+ // 3. Diffing 'foo\nbar baz' vs 'foo baz'
29050
+ // Prior to cleanup, we have K:'foo ' D:'\nbar ' K:' baz'
29051
+ // After cleanup, we want K'foo' D:'\nbar' K:' baz'
29052
+ //
29053
+ // 4. Diffing 'foo baz' vs 'foo\nbar baz'
29054
+ // Prior to cleanup, we have K:'foo\n' I:'\nbar ' K:' baz'
29055
+ // After cleanup, we ideally want K'foo' I:'\nbar' K:' baz'
29056
+ // but don't actually manage this currently (the pre-cleanup change
29057
+ // objects don't contain enough information to make it possible).
29058
+ //
29059
+ // 5. 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
+ // Our handling is unavoidably imperfect in the case where there's a single
29064
+ // indel between keeps and the whitespace has changed. For instance, consider
29065
+ // diffing 'foo\tbar\nbaz' vs 'foo baz'. Unless we create an extra change
29066
+ // object to represent the insertion of the space character (which isn't even
29067
+ // a token), we have no way to avoid losing information about the texts'
29068
+ // original whitespace in the result we return. Still, we do our best to
29069
+ // output something that will look sensible if we e.g. print it with
29070
+ // insertions in green and deletions in red.
29071
+ // Between two "keep" change objects (or before the first or after the last
29072
+ // change object), we can have either:
29073
+ // * A "delete" followed by an "insert"
29074
+ // * Just an "insert"
29075
+ // * Just a "delete"
29076
+ // We handle the three cases separately.
29077
+ if (deletion && insertion) {
29078
+ var oldWsPrefix = leadingWs(deletion.value);
29079
+ var oldWsSuffix = trailingWs(deletion.value);
29080
+ var newWsPrefix = leadingWs(insertion.value);
29081
+ var newWsSuffix = trailingWs(insertion.value);
29082
+ if (startKeep) {
29083
+ var commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
29084
+ startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
29085
+ deletion.value = removePrefix(deletion.value, commonWsPrefix);
29086
+ insertion.value = removePrefix(insertion.value, commonWsPrefix);
29087
+ }
29088
+ if (endKeep) {
29089
+ var commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
29090
+ endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
29091
+ deletion.value = removeSuffix(deletion.value, commonWsSuffix);
29092
+ insertion.value = removeSuffix(insertion.value, commonWsSuffix);
29093
+ }
29094
+ }
29095
+ else if (insertion) {
29096
+ // The whitespaces all reflect what was in the new text rather than
29097
+ // the old, so we essentially have no information about whitespace
29098
+ // insertion or deletion. We just want to dedupe the whitespace.
29099
+ // We do that by having each change object keep its trailing
29100
+ // whitespace and deleting duplicate leading whitespace where
29101
+ // present.
29102
+ if (startKeep) {
29103
+ var ws = leadingWs(insertion.value);
29104
+ insertion.value = insertion.value.substring(ws.length);
29105
+ }
29106
+ if (endKeep) {
29107
+ var ws = leadingWs(endKeep.value);
29108
+ endKeep.value = endKeep.value.substring(ws.length);
29109
+ }
29110
+ // otherwise we've got a deletion and no insertion
29111
+ }
29112
+ else if (startKeep && endKeep) {
29113
+ var newWsFull = leadingWs(endKeep.value), delWsStart = leadingWs(deletion.value), delWsEnd = trailingWs(deletion.value);
29114
+ // Any whitespace that comes straight after startKeep in both the old and
29115
+ // new texts, assign to startKeep and remove from the deletion.
29116
+ var newWsStart = longestCommonPrefix(newWsFull, delWsStart);
29117
+ deletion.value = removePrefix(deletion.value, newWsStart);
29118
+ // Any whitespace that comes straight before endKeep in both the old and
29119
+ // new texts, and hasn't already been assigned to startKeep, assign to
29120
+ // endKeep and remove from the deletion.
29121
+ var newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
29122
+ deletion.value = removeSuffix(deletion.value, newWsEnd);
29123
+ endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
29124
+ // If there's any whitespace from the new text that HASN'T already been
29125
+ // assigned, assign it to the start:
29126
+ startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
29127
+ }
29128
+ else if (endKeep) {
29129
+ // We are at the start of the text. Preserve all the whitespace on
29130
+ // endKeep, and just remove whitespace from the end of deletion to the
29131
+ // extent that it overlaps with the start of endKeep.
29132
+ var endKeepWsPrefix = leadingWs(endKeep.value);
29133
+ var deletionWsSuffix = trailingWs(deletion.value);
29134
+ var overlap = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
29135
+ deletion.value = removeSuffix(deletion.value, overlap);
29136
+ }
29137
+ else if (startKeep) {
29138
+ // We are at the END of the text. Preserve all the whitespace on
29139
+ // startKeep, and just remove whitespace from the start of deletion to
29140
+ // the extent that it overlaps with the end of startKeep.
29141
+ var startKeepWsSuffix = trailingWs(startKeep.value);
29142
+ var deletionWsPrefix = leadingWs(deletion.value);
29143
+ var overlap = maximumOverlap(startKeepWsSuffix, deletionWsPrefix);
29144
+ deletion.value = removePrefix(deletion.value, overlap);
29145
+ }
29146
+ }
29147
+ var WordsWithSpaceDiff = /** @class */ (function (_super) {
29148
+ __extends$5(WordsWithSpaceDiff, _super);
29149
+ function WordsWithSpaceDiff() {
29150
+ return _super !== null && _super.apply(this, arguments) || this;
29151
+ }
29152
+ WordsWithSpaceDiff.prototype.tokenize = function (value) {
29153
+ // Slightly different to the tokenizeIncludingWhitespace regex used above in
29154
+ // that this one treats each individual newline as a distinct tokens, rather
29155
+ // than merging them into other surrounding whitespace. This was requested
29156
+ // in https://github.com/kpdecker/jsdiff/issues/180 &
29157
+ // https://github.com/kpdecker/jsdiff/issues/211
29158
+ var regex = new RegExp("(\\r?\\n)|[".concat(extendedWordChars, "]+|[^\\S\\n\\r]+|[^").concat(extendedWordChars, "]"), 'ug');
29159
+ return value.match(regex) || [];
29160
+ };
29161
+ return WordsWithSpaceDiff;
29162
+ }(Diff));
29163
+ new WordsWithSpaceDiff();
29164
+
29165
+ var __extends$4 = (undefined && undefined.__extends) || (function () {
29166
+ var extendStatics = function (d, b) {
29167
+ extendStatics = Object.setPrototypeOf ||
29168
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29169
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29170
+ return extendStatics(d, b);
29171
+ };
29172
+ return function (d, b) {
29173
+ if (typeof b !== "function" && b !== null)
29174
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29175
+ extendStatics(d, b);
29176
+ function __() { this.constructor = d; }
29177
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29178
+ };
29179
+ })();
29180
+ var LineDiff = /** @class */ (function (_super) {
29181
+ __extends$4(LineDiff, _super);
29182
+ function LineDiff() {
29183
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29184
+ _this.tokenize = tokenize;
29185
+ return _this;
29197
29186
  }
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);
29187
+ LineDiff.prototype.equals = function (left, right, options) {
29188
+ // If we're ignoring whitespace, we need to normalise lines by stripping
29189
+ // whitespace before checking equality. (This has an annoying interaction
29190
+ // with newlineIsToken that requires special handling: if newlines get their
29191
+ // own token, then we DON'T want to trim the *newline* tokens down to empty
29192
+ // strings, since this would cause us to treat whitespace-only line content
29193
+ // as equal to a separator between lines, which would be weird and
29194
+ // inconsistent with the documented behavior of the options.)
29195
+ if (options.ignoreWhitespace) {
29196
+ if (!options.newlineIsToken || !left.includes('\n')) {
29197
+ left = left.trim();
29198
+ }
29199
+ if (!options.newlineIsToken || !right.includes('\n')) {
29200
+ right = right.trim();
29201
+ }
29202
+ }
29203
+ else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
29204
+ if (left.endsWith('\n')) {
29205
+ left = left.slice(0, -1);
29206
+ }
29207
+ if (right.endsWith('\n')) {
29208
+ right = right.slice(0, -1);
29209
+ }
29210
+ }
29211
+ return _super.prototype.equals.call(this, left, right, options);
29212
+ };
29213
+ return LineDiff;
29214
+ }(Diff));
29215
+ var lineDiff = new LineDiff();
29216
+ function diffLines(oldStr, newStr, options) {
29217
+ return lineDiff.diff(oldStr, newStr, options);
29218
+ }
29219
+ // Exported standalone so it can be used from jsonDiff too.
29220
+ function tokenize(value, options) {
29221
+ if (options.stripTrailingCr) {
29222
+ // remove one \r before \n to match GNU diff's --strip-trailing-cr behavior
29223
+ value = value.replace(/\r\n/g, '\n');
29224
+ }
29225
+ var retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
29226
+ // Ignore the final empty token that occurs if the string ends with a new line
29227
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
29228
+ linesAndNewlines.pop();
29229
+ }
29230
+ // Merge the content and line separators into single tokens
29231
+ for (var i = 0; i < linesAndNewlines.length; i++) {
29232
+ var line = linesAndNewlines[i];
29233
+ if (i % 2 && !options.newlineIsToken) {
29234
+ retLines[retLines.length - 1] += line;
29235
+ }
29236
+ else {
29237
+ retLines.push(line);
29238
+ }
29239
+ }
29240
+ return retLines;
29228
29241
  }
29229
29242
 
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
29243
+ var __extends$3 = (undefined && undefined.__extends) || (function () {
29244
+ var extendStatics = function (d, b) {
29245
+ extendStatics = Object.setPrototypeOf ||
29246
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29247
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29248
+ return extendStatics(d, b);
29249
+ };
29250
+ return function (d, b) {
29251
+ if (typeof b !== "function" && b !== null)
29252
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29253
+ extendStatics(d, b);
29254
+ function __() { this.constructor = d; }
29255
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29256
+ };
29257
+ })();
29258
+ var SentenceDiff = /** @class */ (function (_super) {
29259
+ __extends$3(SentenceDiff, _super);
29260
+ function SentenceDiff() {
29261
+ return _super !== null && _super.apply(this, arguments) || this;
29262
+ }
29263
+ SentenceDiff.prototype.tokenize = function (value) {
29264
+ return value.split(/(?<=[.!?])(\s+|$)/);
29265
+ };
29266
+ return SentenceDiff;
29267
+ }(Diff));
29268
+ new SentenceDiff();
29269
+
29270
+ var __extends$2 = (undefined && undefined.__extends) || (function () {
29271
+ var extendStatics = function (d, b) {
29272
+ extendStatics = Object.setPrototypeOf ||
29273
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29274
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29275
+ return extendStatics(d, b);
29276
+ };
29277
+ return function (d, b) {
29278
+ if (typeof b !== "function" && b !== null)
29279
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29280
+ extendStatics(d, b);
29281
+ function __() { this.constructor = d; }
29282
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29283
+ };
29284
+ })();
29285
+ var CssDiff = /** @class */ (function (_super) {
29286
+ __extends$2(CssDiff, _super);
29287
+ function CssDiff() {
29288
+ return _super !== null && _super.apply(this, arguments) || this;
29289
+ }
29290
+ CssDiff.prototype.tokenize = function (value) {
29291
+ return value.split(/([{}:;,]|\s+)/);
29292
+ };
29293
+ return CssDiff;
29294
+ }(Diff));
29295
+ new CssDiff();
29296
+
29297
+ var __extends$1 = (undefined && undefined.__extends) || (function () {
29298
+ var extendStatics = function (d, b) {
29299
+ extendStatics = Object.setPrototypeOf ||
29300
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29301
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29302
+ return extendStatics(d, b);
29303
+ };
29304
+ return function (d, b) {
29305
+ if (typeof b !== "function" && b !== null)
29306
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29307
+ extendStatics(d, b);
29308
+ function __() { this.constructor = d; }
29309
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29310
+ };
29311
+ })();
29312
+ var JsonDiff = /** @class */ (function (_super) {
29313
+ __extends$1(JsonDiff, _super);
29314
+ function JsonDiff() {
29315
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29316
+ _this.tokenize = tokenize;
29317
+ return _this;
29318
+ }
29319
+ Object.defineProperty(JsonDiff.prototype, "useLongestToken", {
29320
+ get: function () {
29321
+ // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
29322
+ // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
29323
+ return true;
29324
+ },
29325
+ enumerable: false,
29326
+ configurable: true
29292
29327
  });
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
-
29328
+ JsonDiff.prototype.castInput = function (value, options) {
29329
+ var undefinedReplacement = options.undefinedReplacement, _a = options.stringifyReplacer, stringifyReplacer = _a === void 0 ? function (k, v) { return typeof v === 'undefined' ? undefinedReplacement : v; } : _a;
29330
+ return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, ' ');
29331
+ };
29332
+ JsonDiff.prototype.equals = function (left, right, options) {
29333
+ return _super.prototype.equals.call(this, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'), options);
29334
+ };
29335
+ return JsonDiff;
29336
+ }(Diff));
29337
+ new JsonDiff();
29341
29338
  // This function handles the presence of circular references by bailing out when encountering an
29342
29339
  // object that is already on the "stack" of items being processed. Accepts an optional replacer
29343
29340
  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
- }
29341
+ stack = stack || [];
29342
+ replacementStack = replacementStack || [];
29343
+ if (replacer) {
29344
+ obj = replacer(key === undefined ? '' : key, obj);
29345
+ }
29346
+ var i;
29347
+ for (i = 0; i < stack.length; i += 1) {
29348
+ if (stack[i] === obj) {
29349
+ return replacementStack[i];
29350
+ }
29351
+ }
29352
+ var canonicalizedObj;
29353
+ if ('[object Array]' === Object.prototype.toString.call(obj)) {
29354
+ stack.push(obj);
29355
+ canonicalizedObj = new Array(obj.length);
29356
+ replacementStack.push(canonicalizedObj);
29357
+ for (i = 0; i < obj.length; i += 1) {
29358
+ canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
29359
+ }
29360
+ stack.pop();
29361
+ replacementStack.pop();
29362
+ return canonicalizedObj;
29363
+ }
29364
+ if (obj && obj.toJSON) {
29365
+ obj = obj.toJSON();
29366
+ }
29367
+ if (typeof obj === 'object' && obj !== null) {
29368
+ stack.push(obj);
29369
+ canonicalizedObj = {};
29370
+ replacementStack.push(canonicalizedObj);
29371
+ var sortedKeys = [];
29372
+ var key_1;
29373
+ for (key_1 in obj) {
29374
+ /* istanbul ignore else */
29375
+ if (Object.prototype.hasOwnProperty.call(obj, key_1)) {
29376
+ sortedKeys.push(key_1);
29377
+ }
29378
+ }
29379
+ sortedKeys.sort();
29380
+ for (i = 0; i < sortedKeys.length; i += 1) {
29381
+ key_1 = sortedKeys[i];
29382
+ canonicalizedObj[key_1] = canonicalize(obj[key_1], stack, replacementStack, replacer, key_1);
29383
+ }
29384
+ stack.pop();
29385
+ replacementStack.pop();
29381
29386
  }
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);
29387
+ else {
29388
+ canonicalizedObj = obj;
29386
29389
  }
29387
- stack.pop();
29388
- replacementStack.pop();
29389
- } else {
29390
- canonicalizedObj = obj;
29391
- }
29392
- return canonicalizedObj;
29390
+ return canonicalizedObj;
29393
29391
  }
29394
29392
 
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;
29393
+ var __extends = (undefined && undefined.__extends) || (function () {
29394
+ var extendStatics = function (d, b) {
29395
+ extendStatics = Object.setPrototypeOf ||
29396
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29397
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
29398
+ return extendStatics(d, b);
29399
+ };
29400
+ return function (d, b) {
29401
+ if (typeof b !== "function" && b !== null)
29402
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29403
+ extendStatics(d, b);
29404
+ function __() { this.constructor = d; }
29405
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29406
+ };
29407
+ })();
29408
+ var ArrayDiff = /** @class */ (function (_super) {
29409
+ __extends(ArrayDiff, _super);
29410
+ function ArrayDiff() {
29411
+ return _super !== null && _super.apply(this, arguments) || this;
29412
+ }
29413
+ ArrayDiff.prototype.tokenize = function (value) {
29414
+ return value.slice();
29415
+ };
29416
+ ArrayDiff.prototype.join = function (value) {
29417
+ return value;
29418
+ };
29419
+ ArrayDiff.prototype.removeEmpty = function (value) {
29420
+ return value;
29421
+ };
29422
+ return ArrayDiff;
29423
+ }(Diff));
29424
+ new ArrayDiff();
29425
+
29426
+ var __assign$2 = (undefined && undefined.__assign) || function () {
29427
+ __assign$2 = Object.assign || function(t) {
29428
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29429
+ s = arguments[i];
29430
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29431
+ t[p] = s[p];
29432
+ }
29433
+ return t;
29434
+ };
29435
+ return __assign$2.apply(this, arguments);
29401
29436
  };
29402
29437
 
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
29438
+ var __assign$1 = (undefined && undefined.__assign) || function () {
29439
+ __assign$1 = Object.assign || function(t) {
29440
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29441
+ s = arguments[i];
29442
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29443
+ t[p] = s[p];
29444
+ }
29445
+ return t;
29410
29446
  };
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...
29447
+ return __assign$1.apply(this, arguments);
29448
+ };
29433
29449
 
29434
- if (!diff) {
29435
- return;
29450
+ var __assign = (undefined && undefined.__assign) || function () {
29451
+ __assign = Object.assign || function(t) {
29452
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
29453
+ s = arguments[i];
29454
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29455
+ t[p] = s[p];
29456
+ }
29457
+ return t;
29458
+ };
29459
+ return __assign.apply(this, arguments);
29460
+ };
29461
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
29462
+ var optionsObj;
29463
+ if (!options) {
29464
+ optionsObj = {};
29436
29465
  }
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
- });
29466
+ else if (typeof options === 'function') {
29467
+ optionsObj = { callback: options };
29446
29468
  }
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;
29469
+ else {
29470
+ optionsObj = options;
29471
+ }
29472
+ if (typeof optionsObj.context === 'undefined') {
29473
+ optionsObj.context = 4;
29474
+ }
29475
+ // We copy this into its own variable to placate TypeScript, which thinks
29476
+ // optionsObj.context might be undefined in the callbacks below.
29477
+ var context = optionsObj.context;
29478
+ // @ts-expect-error (runtime check for something that is correctly a static type error)
29479
+ if (optionsObj.newlineIsToken) {
29480
+ throw new Error('newlineIsToken may not be used with patch-generation functions, only with diffing functions');
29481
+ }
29482
+ if (!optionsObj.callback) {
29483
+ return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
29484
+ }
29485
+ else {
29486
+ var callback_1 = optionsObj.callback;
29487
+ diffLines(oldStr, newStr, __assign(__assign({}, optionsObj), { callback: function (diff) {
29488
+ var patch = diffLinesResultToPatch(diff);
29489
+ // TypeScript is unhappy without the cast because it does not understand that `patch` may
29490
+ // be undefined here only if `callback` is StructuredPatchCallbackAbortable:
29491
+ callback_1(patch);
29492
+ } }));
29493
+ }
29494
+ function diffLinesResultToPatch(diff) {
29495
+ // STEP 1: Build up the patch with no "" lines and with the arrays
29496
+ // of lines containing trailing newline characters. We'll tidy up later...
29497
+ if (!diff) {
29498
+ return;
29481
29499
  }
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
- }
29500
+ diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
29501
+ function contextLines(lines) {
29502
+ return lines.map(function (entry) { return ' ' + entry; });
29503
+ }
29504
+ var hunks = [];
29505
+ var oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
29506
+ for (var i = 0; i < diff.length; i++) {
29507
+ var current = diff[i], lines = current.lines || splitLines(current.value);
29508
+ current.lines = lines;
29509
+ if (current.added || current.removed) {
29510
+ // If we have previous context, start with that
29511
+ if (!oldRangeStart) {
29512
+ var prev = diff[i - 1];
29513
+ oldRangeStart = oldLine;
29514
+ newRangeStart = newLine;
29515
+ if (prev) {
29516
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
29517
+ oldRangeStart -= curRange.length;
29518
+ newRangeStart -= curRange.length;
29519
+ }
29520
+ }
29521
+ // Output our changes
29522
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
29523
+ var line = lines_1[_i];
29524
+ curRange.push((current.added ? '+' : '-') + line);
29525
+ }
29526
+ // Track the updated file position
29527
+ if (current.added) {
29528
+ newLine += lines.length;
29529
+ }
29530
+ else {
29531
+ oldLine += lines.length;
29532
+ }
29533
+ }
29534
+ else {
29535
+ // Identical context lines. Track line changes
29536
+ if (oldRangeStart) {
29537
+ // Close out any changes that have been output (or join overlapping)
29538
+ if (lines.length <= context * 2 && i < diff.length - 2) {
29539
+ // Overlapping
29540
+ for (var _a = 0, _b = contextLines(lines); _a < _b.length; _a++) {
29541
+ var line = _b[_a];
29542
+ curRange.push(line);
29543
+ }
29544
+ }
29545
+ else {
29546
+ // end the range and output
29547
+ var contextSize = Math.min(lines.length, context);
29548
+ for (var _c = 0, _d = contextLines(lines.slice(0, contextSize)); _c < _d.length; _c++) {
29549
+ var line = _d[_c];
29550
+ curRange.push(line);
29551
+ }
29552
+ var hunk = {
29553
+ oldStart: oldRangeStart,
29554
+ oldLines: (oldLine - oldRangeStart + contextSize),
29555
+ newStart: newRangeStart,
29556
+ newLines: (newLine - newRangeStart + contextSize),
29557
+ lines: curRange
29558
+ };
29559
+ hunks.push(hunk);
29560
+ oldRangeStart = 0;
29561
+ newRangeStart = 0;
29562
+ curRange = [];
29563
+ }
29564
+ }
29565
+ oldLine += lines.length;
29566
+ newLine += lines.length;
29567
+ }
29507
29568
  }
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
29569
+ // Step 2: eliminate the trailing `\n` from each line of each hunk, and, where needed, add
29570
+ // "".
29571
+ for (var _e = 0, hunks_1 = hunks; _e < hunks_1.length; _e++) {
29572
+ var hunk = hunks_1[_e];
29573
+ for (var i = 0; i < hunk.lines.length; i++) {
29574
+ if (hunk.lines[i].endsWith('\n')) {
29575
+ hunk.lines[i] = hunk.lines[i].slice(0, -1);
29576
+ }
29577
+ else {
29578
+ hunk.lines.splice(i + 1, 0, '\');
29579
+ i++; // Skip the line we just added, then continue iterating
29580
+ }
29581
+ }
29526
29582
  }
29527
- }
29583
+ return {
29584
+ oldFileName: oldFileName, newFileName: newFileName,
29585
+ oldHeader: oldHeader, newHeader: newHeader,
29586
+ hunks: hunks
29587
+ };
29528
29588
  }
29529
- return {
29530
- oldFileName: oldFileName,
29531
- newFileName: newFileName,
29532
- oldHeader: oldHeader,
29533
- newHeader: newHeader,
29534
- hunks: hunks
29535
- };
29536
- }
29537
29589
  }
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;
29590
+ /**
29591
+ * creates a unified diff patch.
29592
+ * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
29593
+ */
29594
+ function formatPatch(patch) {
29595
+ if (Array.isArray(patch)) {
29596
+ return patch.map(formatPatch).join('\n');
29556
29597
  }
29557
- if (hunk.newLines === 0) {
29558
- hunk.newStart -= 1;
29598
+ var ret = [];
29599
+ if (patch.oldFileName == patch.newFileName) {
29600
+ ret.push('Index: ' + patch.oldFileName);
29559
29601
  }
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';
29602
+ ret.push('===================================================================');
29603
+ ret.push('--- ' + patch.oldFileName + (typeof patch.oldHeader === 'undefined' ? '' : '\t' + patch.oldHeader));
29604
+ ret.push('+++ ' + patch.newFileName + (typeof patch.newHeader === 'undefined' ? '' : '\t' + patch.newHeader));
29605
+ for (var i = 0; i < patch.hunks.length; i++) {
29606
+ var hunk = patch.hunks[i];
29607
+ // Unified Diff Format quirk: If the chunk size is 0,
29608
+ // the first number is one lower than one would expect.
29609
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
29610
+ if (hunk.oldLines === 0) {
29611
+ hunk.oldStart -= 1;
29612
+ }
29613
+ if (hunk.newLines === 0) {
29614
+ hunk.newStart -= 1;
29615
+ }
29616
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines
29617
+ + ' +' + hunk.newStart + ',' + hunk.newLines
29618
+ + ' @@');
29619
+ for (var _i = 0, _a = hunk.lines; _i < _a.length; _i++) {
29620
+ var line = _a[_i];
29621
+ ret.push(line);
29622
+ }
29623
+ }
29624
+ return ret.join('\n') + '\n';
29564
29625
  }
29565
29626
  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;
29627
+ if (typeof options === 'function') {
29628
+ options = { callback: options };
29576
29629
  }
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) {
29630
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
29631
+ var patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
29583
29632
  if (!patchObj) {
29584
- _callback2();
29585
- } else {
29586
- _callback2(formatPatch(patchObj));
29633
+ return;
29587
29634
  }
29588
- }
29589
- }));
29590
- }
29635
+ return formatPatch(patchObj);
29636
+ }
29637
+ else {
29638
+ var callback_2 = options.callback;
29639
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, __assign(__assign({}, options), { callback: function (patchObj) {
29640
+ if (!patchObj) {
29641
+ callback_2(undefined);
29642
+ }
29643
+ else {
29644
+ callback_2(formatPatch(patchObj));
29645
+ }
29646
+ } }));
29647
+ }
29591
29648
  }
29592
-
29593
29649
  /**
29594
29650
  * Split `text` into an array of lines, including the trailing newline character (where present)
29595
29651
  */
29596
29652
  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;
29653
+ var hasTrailingNl = text.endsWith('\n');
29654
+ var result = text.split('\n').map(function (line) { return line + '\n'; });
29655
+ if (hasTrailingNl) {
29656
+ result.pop();
29657
+ }
29658
+ else {
29659
+ result.push(result.pop().slice(0, -1));
29660
+ }
29661
+ return result;
29607
29662
  }
29608
29663
 
29609
29664
  /* eslint-disable no-multi-assign */
@@ -56710,4 +56765,4 @@ var srcExports = requireSrc();
56710
56765
  var tinylr = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
56711
56766
 
56712
56767
  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
56768
+ //# sourceMappingURL=vendor-IOoC49Xw.mjs.map