@cloudflare/workspace 0.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,737 @@
1
+ //#region ../../node_modules/diff/libesm/diff/base.js
2
+ var Diff = class {
3
+ diff(oldStr, newStr, options = {}) {
4
+ let callback;
5
+ if (typeof options === "function") {
6
+ callback = options;
7
+ options = {};
8
+ } else if ("callback" in options) callback = options.callback;
9
+ const oldString = this.castInput(oldStr, options);
10
+ const newString = this.castInput(newStr, options);
11
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
12
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
13
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
14
+ }
15
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
16
+ var _a;
17
+ const done = (value) => {
18
+ value = this.postProcess(value, options);
19
+ if (callback) {
20
+ setTimeout(function() {
21
+ callback(value);
22
+ }, 0);
23
+ return;
24
+ } else return value;
25
+ };
26
+ const newLen = newTokens.length, oldLen = oldTokens.length;
27
+ let editLength = 1;
28
+ let maxEditLength = newLen + oldLen;
29
+ if (options.maxEditLength != null) maxEditLength = Math.min(maxEditLength, options.maxEditLength);
30
+ const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
31
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
32
+ const bestPath = [{
33
+ oldPos: -1,
34
+ lastComponent: void 0
35
+ }];
36
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
37
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
38
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
39
+ const execEditLength = () => {
40
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
41
+ let basePath;
42
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
43
+ if (removePath) bestPath[diagonalPath - 1] = void 0;
44
+ let canAdd = false;
45
+ if (addPath) {
46
+ const addPathNewPos = addPath.oldPos - diagonalPath;
47
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
48
+ }
49
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
50
+ if (!canAdd && !canRemove) {
51
+ bestPath[diagonalPath] = void 0;
52
+ continue;
53
+ }
54
+ if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) basePath = this.addToPath(addPath, true, false, 0, options);
55
+ else basePath = this.addToPath(removePath, false, true, 1, options);
56
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
57
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
58
+ else {
59
+ bestPath[diagonalPath] = basePath;
60
+ if (basePath.oldPos + 1 >= oldLen) maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
61
+ if (newPos + 1 >= newLen) minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
62
+ }
63
+ }
64
+ editLength++;
65
+ };
66
+ if (callback) (function exec() {
67
+ setTimeout(function() {
68
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) return callback(void 0);
69
+ if (!execEditLength()) exec();
70
+ }, 0);
71
+ })();
72
+ else while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
73
+ const ret = execEditLength();
74
+ if (ret) return ret;
75
+ }
76
+ }
77
+ addToPath(path, added, removed, oldPosInc, options) {
78
+ const last = path.lastComponent;
79
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) return {
80
+ oldPos: path.oldPos + oldPosInc,
81
+ lastComponent: {
82
+ count: last.count + 1,
83
+ added,
84
+ removed,
85
+ previousComponent: last.previousComponent
86
+ }
87
+ };
88
+ else return {
89
+ oldPos: path.oldPos + oldPosInc,
90
+ lastComponent: {
91
+ count: 1,
92
+ added,
93
+ removed,
94
+ previousComponent: last
95
+ }
96
+ };
97
+ }
98
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
99
+ const newLen = newTokens.length, oldLen = oldTokens.length;
100
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
101
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
102
+ newPos++;
103
+ oldPos++;
104
+ commonCount++;
105
+ if (options.oneChangePerToken) basePath.lastComponent = {
106
+ count: 1,
107
+ previousComponent: basePath.lastComponent,
108
+ added: false,
109
+ removed: false
110
+ };
111
+ }
112
+ if (commonCount && !options.oneChangePerToken) basePath.lastComponent = {
113
+ count: commonCount,
114
+ previousComponent: basePath.lastComponent,
115
+ added: false,
116
+ removed: false
117
+ };
118
+ basePath.oldPos = oldPos;
119
+ return newPos;
120
+ }
121
+ equals(left, right, options) {
122
+ if (options.comparator) return options.comparator(left, right);
123
+ else return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
124
+ }
125
+ removeEmpty(array) {
126
+ const ret = [];
127
+ for (let i = 0; i < array.length; i++) if (array[i]) ret.push(array[i]);
128
+ return ret;
129
+ }
130
+ castInput(value, options) {
131
+ return value;
132
+ }
133
+ tokenize(value, options) {
134
+ return Array.from(value);
135
+ }
136
+ join(chars) {
137
+ return chars.join("");
138
+ }
139
+ postProcess(changeObjects, options) {
140
+ return changeObjects;
141
+ }
142
+ get useLongestToken() {
143
+ return false;
144
+ }
145
+ buildValues(lastComponent, newTokens, oldTokens) {
146
+ const components = [];
147
+ let nextComponent;
148
+ while (lastComponent) {
149
+ components.push(lastComponent);
150
+ nextComponent = lastComponent.previousComponent;
151
+ delete lastComponent.previousComponent;
152
+ lastComponent = nextComponent;
153
+ }
154
+ components.reverse();
155
+ const componentLen = components.length;
156
+ let componentPos = 0, newPos = 0, oldPos = 0;
157
+ for (; componentPos < componentLen; componentPos++) {
158
+ const component = components[componentPos];
159
+ if (!component.removed) {
160
+ if (!component.added && this.useLongestToken) {
161
+ let value = newTokens.slice(newPos, newPos + component.count);
162
+ value = value.map(function(value, i) {
163
+ const oldValue = oldTokens[oldPos + i];
164
+ return oldValue.length > value.length ? oldValue : value;
165
+ });
166
+ component.value = this.join(value);
167
+ } else component.value = this.join(newTokens.slice(newPos, newPos + component.count));
168
+ newPos += component.count;
169
+ if (!component.added) oldPos += component.count;
170
+ } else {
171
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
172
+ oldPos += component.count;
173
+ }
174
+ }
175
+ return components;
176
+ }
177
+ };
178
+ //#endregion
179
+ //#region ../../node_modules/diff/libesm/diff/character.js
180
+ var CharacterDiff = class extends Diff {};
181
+ new CharacterDiff();
182
+ //#endregion
183
+ //#region ../../node_modules/diff/libesm/util/string.js
184
+ function longestCommonPrefix(str1, str2) {
185
+ let i;
186
+ for (i = 0; i < str1.length && i < str2.length; i++) if (str1[i] != str2[i]) return str1.slice(0, i);
187
+ return str1.slice(0, i);
188
+ }
189
+ function longestCommonSuffix(str1, str2) {
190
+ let i;
191
+ if (!str1 || !str2 || str1[str1.length - 1] != str2[str2.length - 1]) return "";
192
+ for (i = 0; i < str1.length && i < str2.length; i++) if (str1[str1.length - (i + 1)] != str2[str2.length - (i + 1)]) return str1.slice(-i);
193
+ return str1.slice(-i);
194
+ }
195
+ function replacePrefix(string, oldPrefix, newPrefix) {
196
+ if (string.slice(0, oldPrefix.length) != oldPrefix) throw Error(`string ${JSON.stringify(string)} doesn't start with prefix ${JSON.stringify(oldPrefix)}; this is a bug`);
197
+ return newPrefix + string.slice(oldPrefix.length);
198
+ }
199
+ function replaceSuffix(string, oldSuffix, newSuffix) {
200
+ if (!oldSuffix) return string + newSuffix;
201
+ if (string.slice(-oldSuffix.length) != oldSuffix) throw Error(`string ${JSON.stringify(string)} doesn't end with suffix ${JSON.stringify(oldSuffix)}; this is a bug`);
202
+ return string.slice(0, -oldSuffix.length) + newSuffix;
203
+ }
204
+ function removePrefix(string, oldPrefix) {
205
+ return replacePrefix(string, oldPrefix, "");
206
+ }
207
+ function removeSuffix(string, oldSuffix) {
208
+ return replaceSuffix(string, oldSuffix, "");
209
+ }
210
+ function maximumOverlap(string1, string2) {
211
+ return string2.slice(0, overlapCount(string1, string2));
212
+ }
213
+ function overlapCount(a, b) {
214
+ let startA = 0;
215
+ if (a.length > b.length) startA = a.length - b.length;
216
+ let endB = b.length;
217
+ if (a.length < b.length) endB = a.length;
218
+ const map = Array(endB);
219
+ let k = 0;
220
+ map[0] = 0;
221
+ for (let j = 1; j < endB; j++) {
222
+ if (b[j] == b[k]) map[j] = map[k];
223
+ else map[j] = k;
224
+ while (k > 0 && b[j] != b[k]) k = map[k];
225
+ if (b[j] == b[k]) k++;
226
+ }
227
+ k = 0;
228
+ for (let i = startA; i < a.length; i++) {
229
+ while (k > 0 && a[i] != b[k]) k = map[k];
230
+ if (a[i] == b[k]) k++;
231
+ }
232
+ return k;
233
+ }
234
+ /**
235
+ * Split a string into segments using a word segmenter, merging consecutive
236
+ * segments if they are both whitespace segments. Whitespace segments can
237
+ * appear adjacent to one another for two reasons:
238
+ * - newlines always get their own segment
239
+ * - where a diacritic is attached to a whitespace character in the text, the
240
+ * segment ends after the diacritic, so e.g. " \u0300 " becomes two segments.
241
+ * This function therefore runs the segmenter's .segment() method and then
242
+ * merges consecutive segments of whitespace into a single part.
243
+ */
244
+ function segment(string, segmenter) {
245
+ const parts = [];
246
+ for (const segmentObj of Array.from(segmenter.segment(string))) {
247
+ const segment = segmentObj.segment;
248
+ if (parts.length && /\s/.test(parts[parts.length - 1]) && /\s/.test(segment)) parts[parts.length - 1] += segment;
249
+ else parts.push(segment);
250
+ }
251
+ return parts;
252
+ }
253
+ function trailingWs(string, segmenter) {
254
+ if (segmenter) return leadingAndTrailingWs(string, segmenter)[1];
255
+ let i;
256
+ for (i = string.length - 1; i >= 0; i--) if (!string[i].match(/\s/)) break;
257
+ return string.substring(i + 1);
258
+ }
259
+ function leadingWs(string, segmenter) {
260
+ if (segmenter) return leadingAndTrailingWs(string, segmenter)[0];
261
+ const match = string.match(/^\s*/);
262
+ return match ? match[0] : "";
263
+ }
264
+ function leadingAndTrailingWs(string, segmenter) {
265
+ if (!segmenter) return [leadingWs(string), trailingWs(string)];
266
+ if (segmenter.resolvedOptions().granularity != "word") throw new Error("The segmenter passed must have a granularity of \"word\"");
267
+ const segments = segment(string, segmenter);
268
+ const firstSeg = segments[0];
269
+ const lastSeg = segments[segments.length - 1];
270
+ return [/\s/.test(firstSeg) ? firstSeg : "", /\s/.test(lastSeg) ? lastSeg : ""];
271
+ }
272
+ //#endregion
273
+ //#region ../../node_modules/diff/libesm/diff/word.js
274
+ const extendedWordChars = "a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}";
275
+ const tokenizeIncludingWhitespace = new RegExp(`[${extendedWordChars}]+|\\s+|[^${extendedWordChars}]`, "ug");
276
+ var WordDiff = class extends Diff {
277
+ equals(left, right, options) {
278
+ if (options.ignoreCase) {
279
+ left = left.toLowerCase();
280
+ right = right.toLowerCase();
281
+ }
282
+ return left.trim() === right.trim();
283
+ }
284
+ tokenize(value, options = {}) {
285
+ let parts;
286
+ if (options.intlSegmenter) {
287
+ const segmenter = options.intlSegmenter;
288
+ if (segmenter.resolvedOptions().granularity != "word") throw new Error("The segmenter passed must have a granularity of \"word\"");
289
+ parts = segment(value, segmenter);
290
+ } else parts = value.match(tokenizeIncludingWhitespace) || [];
291
+ const tokens = [];
292
+ let prevPart = null;
293
+ parts.forEach((part) => {
294
+ if (/\s/.test(part)) if (prevPart == null) tokens.push(part);
295
+ else tokens.push(tokens.pop() + part);
296
+ else if (prevPart != null && /\s/.test(prevPart)) if (tokens[tokens.length - 1] == prevPart) tokens.push(tokens.pop() + part);
297
+ else tokens.push(prevPart + part);
298
+ else tokens.push(part);
299
+ prevPart = part;
300
+ });
301
+ return tokens;
302
+ }
303
+ join(tokens) {
304
+ return tokens.map((token, i) => {
305
+ if (i == 0) return token;
306
+ else return token.replace(/^\s+/, "");
307
+ }).join("");
308
+ }
309
+ postProcess(changes, options) {
310
+ if (!changes || options.oneChangePerToken) return changes;
311
+ let lastKeep = null;
312
+ let insertion = null;
313
+ let deletion = null;
314
+ changes.forEach((change) => {
315
+ if (change.added) insertion = change;
316
+ else if (change.removed) deletion = change;
317
+ else {
318
+ if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, change, options.intlSegmenter);
319
+ lastKeep = change;
320
+ insertion = null;
321
+ deletion = null;
322
+ }
323
+ });
324
+ if (insertion || deletion) dedupeWhitespaceInChangeObjects(lastKeep, deletion, insertion, null, options.intlSegmenter);
325
+ return changes;
326
+ }
327
+ };
328
+ new WordDiff();
329
+ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep, segmenter) {
330
+ if (deletion && insertion) {
331
+ const [oldWsPrefix, oldWsSuffix] = leadingAndTrailingWs(deletion.value, segmenter);
332
+ const [newWsPrefix, newWsSuffix] = leadingAndTrailingWs(insertion.value, segmenter);
333
+ if (startKeep) {
334
+ const commonWsPrefix = longestCommonPrefix(oldWsPrefix, newWsPrefix);
335
+ startKeep.value = replaceSuffix(startKeep.value, newWsPrefix, commonWsPrefix);
336
+ deletion.value = removePrefix(deletion.value, commonWsPrefix);
337
+ insertion.value = removePrefix(insertion.value, commonWsPrefix);
338
+ }
339
+ if (endKeep) {
340
+ const commonWsSuffix = longestCommonSuffix(oldWsSuffix, newWsSuffix);
341
+ endKeep.value = replacePrefix(endKeep.value, newWsSuffix, commonWsSuffix);
342
+ deletion.value = removeSuffix(deletion.value, commonWsSuffix);
343
+ insertion.value = removeSuffix(insertion.value, commonWsSuffix);
344
+ }
345
+ } else if (insertion) {
346
+ if (startKeep) {
347
+ const ws = leadingWs(insertion.value, segmenter);
348
+ insertion.value = insertion.value.substring(ws.length);
349
+ }
350
+ if (endKeep) {
351
+ const ws = leadingWs(endKeep.value, segmenter);
352
+ endKeep.value = endKeep.value.substring(ws.length);
353
+ }
354
+ } else if (startKeep && endKeep) {
355
+ const newWsFull = leadingWs(endKeep.value, segmenter), [delWsStart, delWsEnd] = leadingAndTrailingWs(deletion.value, segmenter);
356
+ const newWsStart = longestCommonPrefix(newWsFull, delWsStart);
357
+ deletion.value = removePrefix(deletion.value, newWsStart);
358
+ const newWsEnd = longestCommonSuffix(removePrefix(newWsFull, newWsStart), delWsEnd);
359
+ deletion.value = removeSuffix(deletion.value, newWsEnd);
360
+ endKeep.value = replacePrefix(endKeep.value, newWsFull, newWsEnd);
361
+ startKeep.value = replaceSuffix(startKeep.value, newWsFull, newWsFull.slice(0, newWsFull.length - newWsEnd.length));
362
+ } else if (endKeep) {
363
+ const endKeepWsPrefix = leadingWs(endKeep.value, segmenter);
364
+ const overlap = maximumOverlap(trailingWs(deletion.value, segmenter), endKeepWsPrefix);
365
+ deletion.value = removeSuffix(deletion.value, overlap);
366
+ } else if (startKeep) {
367
+ const overlap = maximumOverlap(trailingWs(startKeep.value, segmenter), leadingWs(deletion.value, segmenter));
368
+ deletion.value = removePrefix(deletion.value, overlap);
369
+ }
370
+ }
371
+ var WordsWithSpaceDiff = class extends Diff {
372
+ tokenize(value) {
373
+ const regex = new RegExp(`(\\r?\\n)|[${extendedWordChars}]+|[^\\S\\n\\r]+|[^${extendedWordChars}]`, "ug");
374
+ return value.match(regex) || [];
375
+ }
376
+ };
377
+ new WordsWithSpaceDiff();
378
+ //#endregion
379
+ //#region ../../node_modules/diff/libesm/diff/line.js
380
+ var LineDiff = class extends Diff {
381
+ constructor() {
382
+ super(...arguments);
383
+ this.tokenize = tokenize;
384
+ }
385
+ equals(left, right, options) {
386
+ if (options.ignoreWhitespace) {
387
+ if (!options.newlineIsToken || !left.includes("\n")) left = left.trim();
388
+ if (!options.newlineIsToken || !right.includes("\n")) right = right.trim();
389
+ } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
390
+ if (left.endsWith("\n")) left = left.slice(0, -1);
391
+ if (right.endsWith("\n")) right = right.slice(0, -1);
392
+ }
393
+ return super.equals(left, right, options);
394
+ }
395
+ };
396
+ const lineDiff = new LineDiff();
397
+ function diffLines(oldStr, newStr, options) {
398
+ return lineDiff.diff(oldStr, newStr, options);
399
+ }
400
+ function tokenize(value, options) {
401
+ if (options.stripTrailingCr) value = value.replace(/\r\n/g, "\n");
402
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
403
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) linesAndNewlines.pop();
404
+ for (let i = 0; i < linesAndNewlines.length; i++) {
405
+ const line = linesAndNewlines[i];
406
+ if (i % 2 && !options.newlineIsToken) retLines[retLines.length - 1] += line;
407
+ else retLines.push(line);
408
+ }
409
+ return retLines;
410
+ }
411
+ //#endregion
412
+ //#region ../../node_modules/diff/libesm/diff/sentence.js
413
+ function isSentenceEndPunct(char) {
414
+ return char == "." || char == "!" || char == "?";
415
+ }
416
+ var SentenceDiff = class extends Diff {
417
+ tokenize(value) {
418
+ var _a;
419
+ const result = [];
420
+ let tokenStartI = 0;
421
+ for (let i = 0; i < value.length; i++) {
422
+ if (i == value.length - 1) {
423
+ result.push(value.slice(tokenStartI));
424
+ break;
425
+ }
426
+ if (isSentenceEndPunct(value[i]) && value[i + 1].match(/\s/)) {
427
+ result.push(value.slice(tokenStartI, i + 1));
428
+ i = tokenStartI = i + 1;
429
+ while ((_a = value[i + 1]) === null || _a === void 0 ? void 0 : _a.match(/\s/)) i++;
430
+ result.push(value.slice(tokenStartI, i + 1));
431
+ tokenStartI = i + 1;
432
+ }
433
+ }
434
+ return result;
435
+ }
436
+ };
437
+ new SentenceDiff();
438
+ //#endregion
439
+ //#region ../../node_modules/diff/libesm/diff/css.js
440
+ var CssDiff = class extends Diff {
441
+ tokenize(value) {
442
+ return value.split(/([{}:;,]|\s+)/);
443
+ }
444
+ };
445
+ new CssDiff();
446
+ //#endregion
447
+ //#region ../../node_modules/diff/libesm/diff/json.js
448
+ var JsonDiff = class extends Diff {
449
+ constructor() {
450
+ super(...arguments);
451
+ this.tokenize = tokenize;
452
+ }
453
+ get useLongestToken() {
454
+ return true;
455
+ }
456
+ castInput(value, options) {
457
+ const { undefinedReplacement, stringifyReplacer = (k, v) => typeof v === "undefined" ? undefinedReplacement : v } = options;
458
+ return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), null, " ");
459
+ }
460
+ equals(left, right, options) {
461
+ return super.equals(left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1"), options);
462
+ }
463
+ };
464
+ new JsonDiff();
465
+ function canonicalize(obj, stack, replacementStack, replacer, key) {
466
+ stack = stack || [];
467
+ replacementStack = replacementStack || [];
468
+ if (replacer) obj = replacer(key === void 0 ? "" : key, obj);
469
+ let i;
470
+ for (i = 0; i < stack.length; i += 1) if (stack[i] === obj) return replacementStack[i];
471
+ let canonicalizedObj;
472
+ if ("[object Array]" === Object.prototype.toString.call(obj)) {
473
+ stack.push(obj);
474
+ canonicalizedObj = new Array(obj.length);
475
+ replacementStack.push(canonicalizedObj);
476
+ for (i = 0; i < obj.length; i += 1) canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, String(i));
477
+ stack.pop();
478
+ replacementStack.pop();
479
+ return canonicalizedObj;
480
+ }
481
+ if (obj && obj.toJSON) obj = obj.toJSON();
482
+ if (typeof obj === "object" && obj !== null) {
483
+ stack.push(obj);
484
+ canonicalizedObj = {};
485
+ replacementStack.push(canonicalizedObj);
486
+ const sortedKeys = [];
487
+ let key;
488
+ for (key in obj)
489
+ /* istanbul ignore else */
490
+ if (Object.prototype.hasOwnProperty.call(obj, key)) sortedKeys.push(key);
491
+ sortedKeys.sort();
492
+ for (i = 0; i < sortedKeys.length; i += 1) {
493
+ key = sortedKeys[i];
494
+ canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack, replacer, key);
495
+ }
496
+ stack.pop();
497
+ replacementStack.pop();
498
+ } else canonicalizedObj = obj;
499
+ return canonicalizedObj;
500
+ }
501
+ //#endregion
502
+ //#region ../../node_modules/diff/libesm/diff/array.js
503
+ var ArrayDiff = class extends Diff {
504
+ tokenize(value) {
505
+ return value.slice();
506
+ }
507
+ join(value) {
508
+ return value;
509
+ }
510
+ removeEmpty(value) {
511
+ return value;
512
+ }
513
+ };
514
+ new ArrayDiff();
515
+ //#endregion
516
+ //#region ../../node_modules/diff/libesm/patch/create.js
517
+ /**
518
+ * Returns true if the filename contains characters that require C-style
519
+ * quoting (as used by Git and GNU diffutils in diff output).
520
+ */
521
+ function needsQuoting(s) {
522
+ for (let i = 0; i < s.length; i++) if (s[i] < " " || s[i] > "~" || s[i] === "\"" || s[i] === "\\") return true;
523
+ return false;
524
+ }
525
+ /**
526
+ * C-style quotes a filename, encoding special characters as escape sequences
527
+ * and non-ASCII bytes as octal escapes. This is the inverse of
528
+ * `parseQuotedFileName` in parse.ts.
529
+ *
530
+ * Non-ASCII bytes are encoded as UTF-8 before being emitted as octal escapes.
531
+ * This matches the behaviour of both Git and GNU diffutils, which always emit
532
+ * UTF-8 octal escapes regardless of the underlying filesystem encoding (e.g.
533
+ * Git for Windows converts from NTFS's UTF-16 to UTF-8 internally).
534
+ *
535
+ * If the filename doesn't need quoting, returns it as-is.
536
+ */
537
+ function quoteFileNameIfNeeded(s) {
538
+ if (!needsQuoting(s)) return s;
539
+ let result = "\"";
540
+ const bytes = new TextEncoder().encode(s);
541
+ let i = 0;
542
+ while (i < bytes.length) {
543
+ const b = bytes[i];
544
+ if (b === 7) result += "\\a";
545
+ else if (b === 8) result += "\\b";
546
+ else if (b === 9) result += "\\t";
547
+ else if (b === 10) result += "\\n";
548
+ else if (b === 11) result += "\\v";
549
+ else if (b === 12) result += "\\f";
550
+ else if (b === 13) result += "\\r";
551
+ else if (b === 34) result += "\\\"";
552
+ else if (b === 92) result += "\\\\";
553
+ else if (b >= 32 && b <= 126) result += String.fromCharCode(b);
554
+ else result += "\\" + b.toString(8).padStart(3, "0");
555
+ i++;
556
+ }
557
+ result += "\"";
558
+ return result;
559
+ }
560
+ const INCLUDE_HEADERS = {
561
+ includeIndex: true,
562
+ includeUnderline: true,
563
+ includeFileHeaders: true
564
+ };
565
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
566
+ let optionsObj;
567
+ if (!options) optionsObj = {};
568
+ else if (typeof options === "function") optionsObj = { callback: options };
569
+ else optionsObj = options;
570
+ if (typeof optionsObj.context === "undefined") optionsObj.context = 4;
571
+ const context = optionsObj.context;
572
+ if (optionsObj.newlineIsToken) throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
573
+ if (!optionsObj.callback) return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
574
+ else {
575
+ const { callback } = optionsObj;
576
+ diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
577
+ callback(diffLinesResultToPatch(diff));
578
+ } }));
579
+ }
580
+ function diffLinesResultToPatch(diff) {
581
+ if (!diff) return;
582
+ diff.push({
583
+ value: "",
584
+ lines: []
585
+ });
586
+ function contextLines(lines) {
587
+ return lines.map(function(entry) {
588
+ return " " + entry;
589
+ });
590
+ }
591
+ const hunks = [];
592
+ let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
593
+ for (let i = 0; i < diff.length; i++) {
594
+ const current = diff[i], lines = current.lines || splitLines(current.value);
595
+ current.lines = lines;
596
+ if (current.added || current.removed) {
597
+ if (!oldRangeStart) {
598
+ const prev = diff[i - 1];
599
+ oldRangeStart = oldLine;
600
+ newRangeStart = newLine;
601
+ if (prev) {
602
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
603
+ oldRangeStart -= curRange.length;
604
+ newRangeStart -= curRange.length;
605
+ }
606
+ }
607
+ for (const line of lines) curRange.push((current.added ? "+" : "-") + line);
608
+ if (current.added) newLine += lines.length;
609
+ else oldLine += lines.length;
610
+ } else {
611
+ if (oldRangeStart) if (lines.length <= context * 2 && i < diff.length - 2) for (const line of contextLines(lines)) curRange.push(line);
612
+ else {
613
+ const contextSize = Math.min(lines.length, context);
614
+ for (const line of contextLines(lines.slice(0, contextSize))) curRange.push(line);
615
+ const hunk = {
616
+ oldStart: oldRangeStart,
617
+ oldLines: oldLine - oldRangeStart + contextSize,
618
+ newStart: newRangeStart,
619
+ newLines: newLine - newRangeStart + contextSize,
620
+ lines: curRange
621
+ };
622
+ hunks.push(hunk);
623
+ oldRangeStart = 0;
624
+ newRangeStart = 0;
625
+ curRange = [];
626
+ }
627
+ oldLine += lines.length;
628
+ newLine += lines.length;
629
+ }
630
+ }
631
+ for (const hunk of hunks) for (let i = 0; i < hunk.lines.length; i++) if (hunk.lines[i].endsWith("\n")) hunk.lines[i] = hunk.lines[i].slice(0, -1);
632
+ else {
633
+ hunk.lines.splice(i + 1, 0, "\");
634
+ i++;
635
+ }
636
+ return {
637
+ oldFileName,
638
+ newFileName,
639
+ oldHeader,
640
+ newHeader,
641
+ hunks
642
+ };
643
+ }
644
+ }
645
+ /**
646
+ * creates a unified diff patch.
647
+ *
648
+ * @param patch either a single structured patch object (as returned by `structuredPatch`) or an
649
+ * array of them (as returned by `parsePatch`).
650
+ * @param headerOptions behaves the same as the `headerOptions` option of `createTwoFilesPatch`.
651
+ * Ignored for patches where `isGit` is `true`.
652
+ *
653
+ * When a patch has `isGit: true`, `formatPatch` output is changed to more closely match Git's
654
+ * output: it emits a `diff --git` header, emits Git extended headers as appropriate based on
655
+ * properties like `isRename`, `isCreate`, `newMode`, etc, and will omit `---`/`+++` file
656
+ * headers for patches with no hunks (e.g. renames without content changes).
657
+ */
658
+ function formatPatch(patch, headerOptions) {
659
+ var _a, _b, _c, _d, _e, _f;
660
+ if (!headerOptions) headerOptions = INCLUDE_HEADERS;
661
+ if (Array.isArray(patch)) {
662
+ if (patch.length > 1 && !headerOptions.includeFileHeaders && !patch.every((p) => p.isGit)) throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");
663
+ return patch.map((p) => formatPatch(p, headerOptions)).join("\n");
664
+ }
665
+ const ret = [];
666
+ if (patch.isGit) {
667
+ headerOptions = INCLUDE_HEADERS;
668
+ if (!patch.oldFileName) throw new Error("oldFileName must be specified for Git patches");
669
+ if (!patch.newFileName) throw new Error("newFileName must be specified for Git patches");
670
+ let gitOldName = patch.oldFileName;
671
+ let gitNewName = patch.newFileName;
672
+ if (patch.isCreate && gitOldName === "/dev/null") gitOldName = gitNewName.replace(/^b\//, "a/");
673
+ else if (patch.isDelete && gitNewName === "/dev/null") gitNewName = gitOldName.replace(/^a\//, "b/");
674
+ ret.push("diff --git " + quoteFileNameIfNeeded(gitOldName) + " " + quoteFileNameIfNeeded(gitNewName));
675
+ if (patch.isDelete) ret.push("deleted file mode " + ((_a = patch.oldMode) !== null && _a !== void 0 ? _a : "100644"));
676
+ if (patch.isCreate) ret.push("new file mode " + ((_b = patch.newMode) !== null && _b !== void 0 ? _b : "100644"));
677
+ if (patch.oldMode && patch.newMode && !patch.isDelete && !patch.isCreate) {
678
+ ret.push("old mode " + patch.oldMode);
679
+ ret.push("new mode " + patch.newMode);
680
+ }
681
+ if (patch.isRename) {
682
+ ret.push("rename from " + quoteFileNameIfNeeded(((_c = patch.oldFileName) !== null && _c !== void 0 ? _c : "").replace(/^a\//, "")));
683
+ ret.push("rename to " + quoteFileNameIfNeeded(((_d = patch.newFileName) !== null && _d !== void 0 ? _d : "").replace(/^b\//, "")));
684
+ }
685
+ if (patch.isCopy) {
686
+ ret.push("copy from " + quoteFileNameIfNeeded(((_e = patch.oldFileName) !== null && _e !== void 0 ? _e : "").replace(/^a\//, "")));
687
+ ret.push("copy to " + quoteFileNameIfNeeded(((_f = patch.newFileName) !== null && _f !== void 0 ? _f : "").replace(/^b\//, "")));
688
+ }
689
+ } else {
690
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName && patch.oldFileName !== void 0) ret.push("Index: " + patch.oldFileName);
691
+ if (headerOptions.includeUnderline) ret.push("===================================================================");
692
+ }
693
+ const hasHunks = patch.hunks.length > 0;
694
+ if (headerOptions.includeFileHeaders && patch.oldFileName !== void 0 && patch.newFileName !== void 0 && (!patch.isGit || hasHunks)) {
695
+ ret.push("--- " + quoteFileNameIfNeeded(patch.oldFileName) + (patch.oldHeader ? " " + patch.oldHeader : ""));
696
+ ret.push("+++ " + quoteFileNameIfNeeded(patch.newFileName) + (patch.newHeader ? " " + patch.newHeader : ""));
697
+ }
698
+ for (let i = 0; i < patch.hunks.length; i++) {
699
+ const hunk = patch.hunks[i];
700
+ const oldStart = hunk.oldLines === 0 ? hunk.oldStart - 1 : hunk.oldStart;
701
+ const newStart = hunk.newLines === 0 ? hunk.newStart - 1 : hunk.newStart;
702
+ ret.push("@@ -" + oldStart + "," + hunk.oldLines + " +" + newStart + "," + hunk.newLines + " @@");
703
+ for (const line of hunk.lines) ret.push(line);
704
+ }
705
+ return ret.join("\n") + "\n";
706
+ }
707
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
708
+ if (typeof options === "function") options = { callback: options };
709
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
710
+ const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
711
+ if (!patchObj) return;
712
+ return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
713
+ } else {
714
+ const { callback } = options;
715
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
716
+ if (!patchObj) callback(void 0);
717
+ else callback(formatPatch(patchObj, options.headerOptions));
718
+ } }));
719
+ }
720
+ }
721
+ function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
722
+ return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
723
+ }
724
+ /**
725
+ * Split `text` into an array of lines, including the trailing newline character (where present)
726
+ */
727
+ function splitLines(text) {
728
+ const hasTrailingNl = text.endsWith("\n");
729
+ const result = text.split("\n").map((line) => line + "\n");
730
+ if (hasTrailingNl) result.pop();
731
+ else result.push(result.pop().slice(0, -1));
732
+ return result;
733
+ }
734
+ //#endregion
735
+ export { createPatch };
736
+
737
+ //# sourceMappingURL=shared-Dj4r_9xb.js.map