@loro-dev/json-patch 0.0.0-stage → 0.1.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.
- package/README.md +314 -2
- package/dist/diff.cjs +1666 -0
- package/dist/diff.d.cts +126 -0
- package/dist/diff.d.ts +126 -0
- package/dist/diff.js +1463 -0
- package/dist/index.cjs +1124 -0
- package/dist/index.d.cts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +1097 -0
- package/dist/loro.cjs +2722 -0
- package/dist/loro.d.cts +115 -0
- package/dist/loro.d.ts +115 -0
- package/dist/loro.js +2710 -0
- package/package.json +70 -3
package/dist/diff.cjs
ADDED
|
@@ -0,0 +1,1666 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
//#region src/types.ts
|
|
26
|
+
/** Error thrown when {@link apply} or {@link applyOp} rejects an invalid path, index, boundary, or value. */
|
|
27
|
+
var ApplyError = class extends Error {
|
|
28
|
+
kind;
|
|
29
|
+
opIndex;
|
|
30
|
+
constructor(kind, opIndex, message) {
|
|
31
|
+
super(`op #${opIndex}: ${message}`);
|
|
32
|
+
this.name = "ApplyError";
|
|
33
|
+
this.kind = kind;
|
|
34
|
+
this.opIndex = opIndex;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** Error thrown by JSON or MessagePack wire codecs when encoding/decoding malformed patches or values. */
|
|
38
|
+
var DecodeError = class extends Error {
|
|
39
|
+
kind;
|
|
40
|
+
opCode;
|
|
41
|
+
constructor(kind, message, opCode) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "DecodeError";
|
|
44
|
+
this.kind = kind;
|
|
45
|
+
this.opCode = opCode;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const I64_MIN = -(1n << 63n);
|
|
49
|
+
const I64_MAX = (1n << 63n) - 1n;
|
|
50
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
51
|
+
const MIN_SAFE_BIG = BigInt(Number.MIN_SAFE_INTEGER);
|
|
52
|
+
const MAX_SAFE_BIG = BigInt(Number.MAX_SAFE_INTEGER);
|
|
53
|
+
function hasOwn(obj, key) {
|
|
54
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Define an own enumerable data property safely, avoiding Object.prototype
|
|
58
|
+
* `__proto__` setter mutation when `key === "__proto__"`.
|
|
59
|
+
*/
|
|
60
|
+
function setOwnProp(obj, key, value) {
|
|
61
|
+
if (key === "__proto__") Object.defineProperty(obj, key, {
|
|
62
|
+
value,
|
|
63
|
+
writable: true,
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true
|
|
66
|
+
});
|
|
67
|
+
else obj[key] = value;
|
|
68
|
+
}
|
|
69
|
+
/** Returns `true` for plain JSON records (excluding `null`, arrays, `Uint8Array`, and class instances). */
|
|
70
|
+
function isPlainObject(v) {
|
|
71
|
+
if (typeof v !== "object" || v === null) return false;
|
|
72
|
+
if (Array.isArray(v) || v instanceof Uint8Array) return false;
|
|
73
|
+
const proto = Object.getPrototypeOf(v);
|
|
74
|
+
return proto === Object.prototype || proto === null;
|
|
75
|
+
}
|
|
76
|
+
/** Validates that `value` is a legal {@link JsonValue} (no NaN/Infinity, no lone UTF-16 surrogates, valid i64/u64 bigints). */
|
|
77
|
+
function validateJsonValue(value, opIndex = 0) {
|
|
78
|
+
if (value === null) return;
|
|
79
|
+
switch (typeof value) {
|
|
80
|
+
case "boolean": return;
|
|
81
|
+
case "bigint":
|
|
82
|
+
if (value < I64_MIN || value > U64_MAX) throw new ApplyError("InvalidValue", opIndex, `bigint ${value} out of i64/u64 range`);
|
|
83
|
+
return;
|
|
84
|
+
case "string":
|
|
85
|
+
assertNoLoneSurrogates(value, opIndex);
|
|
86
|
+
return;
|
|
87
|
+
case "number":
|
|
88
|
+
if (!Number.isFinite(value)) throw new ApplyError("InvalidValue", opIndex, "non-finite float (NaN or Infinity) is forbidden");
|
|
89
|
+
return;
|
|
90
|
+
case "object":
|
|
91
|
+
if (value instanceof Uint8Array) return;
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
for (let i = 0; i < value.length; i++) validateJsonValue(value[i], opIndex);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (isPlainObject(value)) {
|
|
97
|
+
const keys = Object.keys(value);
|
|
98
|
+
for (let i = 0; i < keys.length; i++) {
|
|
99
|
+
const k = keys[i];
|
|
100
|
+
assertNoLoneSurrogates(k, opIndex);
|
|
101
|
+
validateJsonValue(value[k], opIndex);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
throw new ApplyError("InvalidValue", opIndex, "unsupported object type in JsonValue");
|
|
106
|
+
default: throw new ApplyError("InvalidValue", opIndex, `unsupported value type: ${typeof value}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validates `value` and normalizes `-0` to `+0` without cloning objects/arrays
|
|
111
|
+
* that already contain no `-0`.
|
|
112
|
+
*/
|
|
113
|
+
function validateAndNormalizeJsonValue(value, opIndex = 0) {
|
|
114
|
+
if (value === null) return null;
|
|
115
|
+
switch (typeof value) {
|
|
116
|
+
case "boolean": return value;
|
|
117
|
+
case "bigint":
|
|
118
|
+
if (value < I64_MIN || value > U64_MAX) throw new ApplyError("InvalidValue", opIndex, `bigint ${value} out of i64/u64 range`);
|
|
119
|
+
return value;
|
|
120
|
+
case "string":
|
|
121
|
+
assertNoLoneSurrogates(value, opIndex);
|
|
122
|
+
return value;
|
|
123
|
+
case "number":
|
|
124
|
+
if (!Number.isFinite(value)) throw new ApplyError("InvalidValue", opIndex, "non-finite float (NaN or Infinity) is forbidden");
|
|
125
|
+
return Object.is(value, -0) ? 0 : value;
|
|
126
|
+
case "object":
|
|
127
|
+
if (value instanceof Uint8Array) return value;
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
let out;
|
|
130
|
+
for (let i = 0; i < value.length; i++) {
|
|
131
|
+
const item = value[i];
|
|
132
|
+
const norm = validateAndNormalizeJsonValue(item, opIndex);
|
|
133
|
+
if (norm !== item || out !== void 0) {
|
|
134
|
+
if (!out) out = value.slice(0, i);
|
|
135
|
+
out.push(norm);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return out ?? value;
|
|
139
|
+
}
|
|
140
|
+
if (isPlainObject(value)) {
|
|
141
|
+
const keys = Object.keys(value);
|
|
142
|
+
let out;
|
|
143
|
+
for (let i = 0; i < keys.length; i++) {
|
|
144
|
+
const k = keys[i];
|
|
145
|
+
assertNoLoneSurrogates(k, opIndex);
|
|
146
|
+
const v = value[k];
|
|
147
|
+
const norm = validateAndNormalizeJsonValue(v, opIndex);
|
|
148
|
+
if (norm !== v || out !== void 0) {
|
|
149
|
+
if (!out) {
|
|
150
|
+
out = {};
|
|
151
|
+
for (let j = 0; j < i; j++) setOwnProp(out, keys[j], value[keys[j]]);
|
|
152
|
+
}
|
|
153
|
+
setOwnProp(out, k, norm);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return out ?? value;
|
|
157
|
+
}
|
|
158
|
+
throw new ApplyError("InvalidValue", opIndex, "unsupported object type in JsonValue");
|
|
159
|
+
default: throw new ApplyError("InvalidValue", opIndex, `unsupported value type: ${typeof value}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** Compares `number` and `bigint` values mathematically (handles `-0 === 0` and integer cross-type equality). */
|
|
163
|
+
function numbersEqual(a, b) {
|
|
164
|
+
if (typeof a === "number" && typeof b === "number") return a === b;
|
|
165
|
+
if (typeof a === "bigint" && typeof b === "bigint") return a === b;
|
|
166
|
+
if (typeof a === "bigint" && typeof b === "number") return Number.isInteger(b) && a === BigInt(b);
|
|
167
|
+
if (typeof a === "number" && typeof b === "bigint") return Number.isInteger(a) && BigInt(a) === b;
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/** Deep structural equality for two {@link JsonValue}s (including `Uint8Array` byte-by-byte and `bigint`/`number`). */
|
|
171
|
+
function valuesEqual(a, b) {
|
|
172
|
+
if (a === b) return true;
|
|
173
|
+
if ((typeof a === "number" || typeof a === "bigint") && (typeof b === "number" || typeof b === "bigint")) return numbersEqual(a, b);
|
|
174
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
175
|
+
if (a instanceof Uint8Array || b instanceof Uint8Array) {
|
|
176
|
+
if (!(a instanceof Uint8Array && b instanceof Uint8Array)) return false;
|
|
177
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
178
|
+
for (let i = 0; i < a.byteLength; i++) if (a[i] !== b[i]) return false;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
182
|
+
if (!(Array.isArray(a) && Array.isArray(b))) return false;
|
|
183
|
+
if (a.length !== b.length) return false;
|
|
184
|
+
for (let i = 0; i < a.length; i++) if (!valuesEqual(a[i], b[i])) return false;
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (!isPlainObject(a) || !isPlainObject(b)) return false;
|
|
188
|
+
const keysA = Object.keys(a);
|
|
189
|
+
const keysB = Object.keys(b);
|
|
190
|
+
if (keysA.length !== keysB.length) return false;
|
|
191
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
192
|
+
const key = keysA[i];
|
|
193
|
+
if (!hasOwn(b, key)) return false;
|
|
194
|
+
if (!valuesEqual(a[key], b[key])) return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/** Returns `true` if two {@link JsonPath}s contain identical segments. */
|
|
199
|
+
function pathsEqual(a, b) {
|
|
200
|
+
if (a.length !== b.length) return false;
|
|
201
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
/** Returns `true` if either path is a prefix of the other (including exact equality). */
|
|
205
|
+
function pathsOverlap(a, b) {
|
|
206
|
+
const n = Math.min(a.length, b.length);
|
|
207
|
+
for (let i = 0; i < n; i++) if (a[i] !== b[i]) return false;
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
/** Throws {@link ApplyError} (`"InvalidUtf16Boundary"`) if `offset` is out of bounds or splits a UTF-16 surrogate pair. */
|
|
211
|
+
function assertValidUtf16Boundary(s, offset, opIndex) {
|
|
212
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > s.length) throw new ApplyError("InvalidUtf16Boundary", opIndex, `UTF-16 offset ${offset} out of bounds for length ${s.length}`);
|
|
213
|
+
if (offset > 0 && offset < s.length) {
|
|
214
|
+
const prev = s.charCodeAt(offset - 1);
|
|
215
|
+
const curr = s.charCodeAt(offset);
|
|
216
|
+
if (prev >= 55296 && prev <= 56319 && curr >= 56320 && curr <= 57343) throw new ApplyError("InvalidUtf16Boundary", opIndex, `UTF-16 offset ${offset} splits a surrogate pair`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Validates `[at, at + del)` is a valid UTF-16 range not splitting surrogate pairs and returns `at + del`. */
|
|
220
|
+
function assertValidUtf16Range(s, at, del, opIndex) {
|
|
221
|
+
if (!Number.isSafeInteger(at) || at < 0 || !Number.isSafeInteger(del) || del < 0) throw new ApplyError("InvalidUtf16Boundary", opIndex, `invalid UTF-16 range (${at}, ${del})`);
|
|
222
|
+
const end = at + del;
|
|
223
|
+
if (end > s.length) throw new ApplyError("InvalidUtf16Boundary", opIndex, `UTF-16 range ${at}..${end} out of bounds for length ${s.length}`);
|
|
224
|
+
assertValidUtf16Boundary(s, at, opIndex);
|
|
225
|
+
assertValidUtf16Boundary(s, end, opIndex);
|
|
226
|
+
return end;
|
|
227
|
+
}
|
|
228
|
+
function hasLoneSurrogates(s) {
|
|
229
|
+
for (let i = 0; i < s.length; i++) {
|
|
230
|
+
const c = s.charCodeAt(i);
|
|
231
|
+
if (c >= 55296 && c <= 56319) {
|
|
232
|
+
const next = i + 1 < s.length ? s.charCodeAt(i + 1) : 0;
|
|
233
|
+
if (next >= 56320 && next <= 57343) i++;
|
|
234
|
+
else return true;
|
|
235
|
+
} else if (c >= 56320 && c <= 57343) return true;
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
/** Throws {@link ApplyError} (`"InvalidValue"`) if `s` contains any unpaired UTF-16 high/low surrogate. */
|
|
240
|
+
function assertNoLoneSurrogates(s, opIndex) {
|
|
241
|
+
for (let i = 0; i < s.length; i++) {
|
|
242
|
+
const c = s.charCodeAt(i);
|
|
243
|
+
if (c >= 55296 && c <= 56319) {
|
|
244
|
+
const next = i + 1 < s.length ? s.charCodeAt(i + 1) : 0;
|
|
245
|
+
if (next >= 56320 && next <= 57343) i++;
|
|
246
|
+
else throw new ApplyError("InvalidValue", opIndex, `lone high surrogate at UTF-16 offset ${i}`);
|
|
247
|
+
} else if (c >= 56320 && c <= 57343) throw new ApplyError("InvalidValue", opIndex, `lone low surrogate at UTF-16 offset ${i}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function assertValidIndexSeg(seg, len, allowEnd, opIndex) {
|
|
251
|
+
if (!Number.isSafeInteger(seg) || seg < 0) throw new ApplyError("InvalidPath", opIndex, `invalid array index segment: ${seg}`);
|
|
252
|
+
if (allowEnd ? seg > len : seg >= len) throw new ApplyError("IndexOutOfBounds", opIndex, `index ${seg} out of bounds for length ${len}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/apply.ts
|
|
257
|
+
function assertPathSegValid(seg, opIndex) {
|
|
258
|
+
if (typeof seg === "string") {
|
|
259
|
+
assertNoLoneSurrogates(seg, opIndex);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (typeof seg === "number" && Number.isSafeInteger(seg) && seg >= 0) return;
|
|
263
|
+
throw new ApplyError("InvalidPath", opIndex, `invalid path segment: ${String(seg)}`);
|
|
264
|
+
}
|
|
265
|
+
function validatePath(path, opIndex) {
|
|
266
|
+
for (let i = 0; i < path.length; i++) assertPathSegValid(path[i], opIndex);
|
|
267
|
+
}
|
|
268
|
+
function cowObjWith(obj, key, val, owned) {
|
|
269
|
+
if (owned?.has(obj)) {
|
|
270
|
+
setOwnProp(obj, key, val);
|
|
271
|
+
return obj;
|
|
272
|
+
}
|
|
273
|
+
const out = { ...obj };
|
|
274
|
+
setOwnProp(out, key, val);
|
|
275
|
+
owned?.add(out);
|
|
276
|
+
return out;
|
|
277
|
+
}
|
|
278
|
+
function cowObjWithout(obj, key, owned) {
|
|
279
|
+
if (owned?.has(obj)) {
|
|
280
|
+
delete obj[key];
|
|
281
|
+
return obj;
|
|
282
|
+
}
|
|
283
|
+
const out = {};
|
|
284
|
+
const keys = Object.keys(obj);
|
|
285
|
+
for (let i = 0; i < keys.length; i++) {
|
|
286
|
+
const k = keys[i];
|
|
287
|
+
if (k !== key) setOwnProp(out, k, obj[k]);
|
|
288
|
+
}
|
|
289
|
+
owned?.add(out);
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
function cowArrWith(arr, idx, val, owned) {
|
|
293
|
+
if (owned?.has(arr)) {
|
|
294
|
+
arr[idx] = val;
|
|
295
|
+
return arr;
|
|
296
|
+
}
|
|
297
|
+
const out = arr.slice();
|
|
298
|
+
out[idx] = val;
|
|
299
|
+
owned?.add(out);
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
function spliceArrayInPlace(arr, at, del, items) {
|
|
303
|
+
if (items.length <= 256) {
|
|
304
|
+
arr.splice(at, del, ...items);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const tail = arr.slice(at + del);
|
|
308
|
+
arr.length = at;
|
|
309
|
+
for (let i = 0; i < items.length; i++) arr.push(items[i]);
|
|
310
|
+
for (let i = 0; i < tail.length; i++) arr.push(tail[i]);
|
|
311
|
+
}
|
|
312
|
+
function containsMinusZero(v) {
|
|
313
|
+
if (typeof v === "number") return Object.is(v, -0);
|
|
314
|
+
if (typeof v !== "object" || v === null || v instanceof Uint8Array) return false;
|
|
315
|
+
if (Array.isArray(v)) {
|
|
316
|
+
for (let i = 0; i < v.length; i++) if (containsMinusZero(v[i])) return true;
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
if (isPlainObject(v)) {
|
|
320
|
+
const keys = Object.keys(v);
|
|
321
|
+
for (let i = 0; i < keys.length; i++) if (containsMinusZero(v[keys[i]])) return true;
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
function setAt(node, path, depth, value, opIndex, owned) {
|
|
326
|
+
if (depth === path.length) return valuesEqual(node, value) && !containsMinusZero(node) ? node : value;
|
|
327
|
+
const seg = path[depth];
|
|
328
|
+
if (typeof seg === "string") {
|
|
329
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
330
|
+
if (depth === path.length - 1) {
|
|
331
|
+
if (hasOwn(node, seg) && valuesEqual(node[seg], value) && !containsMinusZero(node[seg])) return node;
|
|
332
|
+
return cowObjWith(node, seg, value, owned);
|
|
333
|
+
}
|
|
334
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
335
|
+
const oldChild = node[seg];
|
|
336
|
+
const newChild = setAt(oldChild, path, depth + 1, value, opIndex, owned);
|
|
337
|
+
if (newChild === oldChild) return node;
|
|
338
|
+
return cowObjWith(node, seg, newChild, owned);
|
|
339
|
+
} else {
|
|
340
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
341
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
342
|
+
const oldChild = node[seg];
|
|
343
|
+
if (depth === path.length - 1) {
|
|
344
|
+
if (valuesEqual(oldChild, value) && !containsMinusZero(oldChild)) return node;
|
|
345
|
+
return cowArrWith(node, seg, value, owned);
|
|
346
|
+
}
|
|
347
|
+
const newChild = setAt(oldChild, path, depth + 1, value, opIndex, owned);
|
|
348
|
+
if (newChild === oldChild) return node;
|
|
349
|
+
return cowArrWith(node, seg, newChild, owned);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function unsetAt(node, path, depth, opIndex, owned) {
|
|
353
|
+
const seg = path[depth];
|
|
354
|
+
if (typeof seg === "string") {
|
|
355
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
356
|
+
if (depth === path.length - 1) {
|
|
357
|
+
if (!hasOwn(node, seg)) return node;
|
|
358
|
+
return cowObjWithout(node, seg, owned);
|
|
359
|
+
}
|
|
360
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
361
|
+
const oldChild = node[seg];
|
|
362
|
+
const newChild = unsetAt(oldChild, path, depth + 1, opIndex, owned);
|
|
363
|
+
if (newChild === oldChild) return node;
|
|
364
|
+
return cowObjWith(node, seg, newChild, owned);
|
|
365
|
+
} else {
|
|
366
|
+
if (depth === path.length - 1) throw new ApplyError("TypeMismatch", opIndex, "unset last segment must be a string key");
|
|
367
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
368
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
369
|
+
const oldChild = node[seg];
|
|
370
|
+
const newChild = unsetAt(oldChild, path, depth + 1, opIndex, owned);
|
|
371
|
+
if (newChild === oldChild) return node;
|
|
372
|
+
return cowArrWith(node, seg, newChild, owned);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function arrSpliceAt(node, path, depth, at, del, items, opIndex, owned) {
|
|
376
|
+
if (depth === path.length) {
|
|
377
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, "arr_splice target must be an Array");
|
|
378
|
+
if (!Number.isSafeInteger(at) || at < 0 || !Number.isSafeInteger(del) || del < 0 || at + del > Number.MAX_SAFE_INTEGER) throw new ApplyError("IndexOutOfBounds", opIndex, `invalid splice bounds (${at}, ${del})`);
|
|
379
|
+
const end = at + del;
|
|
380
|
+
if (at > node.length || end > node.length) throw new ApplyError("IndexOutOfBounds", opIndex, `arr_splice range ${at}..${end} out of bounds for length ${node.length}`);
|
|
381
|
+
if (del === 0 && items.length === 0) return node;
|
|
382
|
+
if (owned?.has(node)) {
|
|
383
|
+
spliceArrayInPlace(node, at, del, items);
|
|
384
|
+
return node;
|
|
385
|
+
}
|
|
386
|
+
const out = node.slice(0, at);
|
|
387
|
+
for (let i = 0; i < items.length; i++) out.push(items[i]);
|
|
388
|
+
for (let i = end; i < node.length; i++) out.push(node[i]);
|
|
389
|
+
owned?.add(out);
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
const seg = path[depth];
|
|
393
|
+
if (typeof seg === "string") {
|
|
394
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
395
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
396
|
+
const oldChild = node[seg];
|
|
397
|
+
const newChild = arrSpliceAt(oldChild, path, depth + 1, at, del, items, opIndex, owned);
|
|
398
|
+
if (newChild === oldChild) return node;
|
|
399
|
+
return cowObjWith(node, seg, newChild, owned);
|
|
400
|
+
} else {
|
|
401
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
402
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
403
|
+
const oldChild = node[seg];
|
|
404
|
+
const newChild = arrSpliceAt(oldChild, path, depth + 1, at, del, items, opIndex, owned);
|
|
405
|
+
if (newChild === oldChild) return node;
|
|
406
|
+
return cowArrWith(node, seg, newChild, owned);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function strSpliceAt(node, path, depth, at, del, ins, opIndex, owned) {
|
|
410
|
+
if (depth === path.length) {
|
|
411
|
+
if (typeof node !== "string") throw new ApplyError("TypeMismatch", opIndex, "str_splice target must be a String");
|
|
412
|
+
const end = assertValidUtf16Range(node, at, del, opIndex);
|
|
413
|
+
assertNoLoneSurrogates(ins, opIndex);
|
|
414
|
+
if (del === 0 && ins.length === 0) return node;
|
|
415
|
+
return node.slice(0, at) + ins + node.slice(end);
|
|
416
|
+
}
|
|
417
|
+
const seg = path[depth];
|
|
418
|
+
if (typeof seg === "string") {
|
|
419
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
420
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
421
|
+
const oldChild = node[seg];
|
|
422
|
+
const newChild = strSpliceAt(oldChild, path, depth + 1, at, del, ins, opIndex, owned);
|
|
423
|
+
if (newChild === oldChild) return node;
|
|
424
|
+
return cowObjWith(node, seg, newChild, owned);
|
|
425
|
+
} else {
|
|
426
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
427
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
428
|
+
const oldChild = node[seg];
|
|
429
|
+
const newChild = strSpliceAt(oldChild, path, depth + 1, at, del, ins, opIndex, owned);
|
|
430
|
+
if (newChild === oldChild) return node;
|
|
431
|
+
return cowArrWith(node, seg, newChild, owned);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function verifyPathExists(node, path, opIndex) {
|
|
435
|
+
let cur = node;
|
|
436
|
+
for (let i = 0; i < path.length; i++) {
|
|
437
|
+
const seg = path[i];
|
|
438
|
+
if (typeof seg === "string") {
|
|
439
|
+
if (!isPlainObject(cur)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
440
|
+
if (!hasOwn(cur, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
441
|
+
cur = cur[seg];
|
|
442
|
+
} else {
|
|
443
|
+
if (!Array.isArray(cur)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
444
|
+
assertValidIndexSeg(seg, cur.length, false, opIndex);
|
|
445
|
+
cur = cur[seg];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function takeAt(node, path, depth, opIndex, owned) {
|
|
450
|
+
const seg = path[depth];
|
|
451
|
+
if (typeof seg === "string") {
|
|
452
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
453
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
454
|
+
if (depth === path.length - 1) {
|
|
455
|
+
const taken = node[seg];
|
|
456
|
+
return {
|
|
457
|
+
next: cowObjWithout(node, seg, owned),
|
|
458
|
+
taken
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const res = takeAt(node[seg], path, depth + 1, opIndex, owned);
|
|
462
|
+
return {
|
|
463
|
+
next: cowObjWith(node, seg, res.next, owned),
|
|
464
|
+
taken: res.taken
|
|
465
|
+
};
|
|
466
|
+
} else {
|
|
467
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
468
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
469
|
+
if (depth === path.length - 1) {
|
|
470
|
+
const taken = node[seg];
|
|
471
|
+
if (owned?.has(node)) {
|
|
472
|
+
node.splice(seg, 1);
|
|
473
|
+
return {
|
|
474
|
+
next: node,
|
|
475
|
+
taken
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const out = node.slice(0, seg).concat(node.slice(seg + 1));
|
|
479
|
+
owned?.add(out);
|
|
480
|
+
return {
|
|
481
|
+
next: out,
|
|
482
|
+
taken
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
const res = takeAt(node[seg], path, depth + 1, opIndex, owned);
|
|
486
|
+
return {
|
|
487
|
+
next: cowArrWith(node, seg, res.next, owned),
|
|
488
|
+
taken: res.taken
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function insertAt(node, path, depth, val, opIndex, owned) {
|
|
493
|
+
const seg = path[depth];
|
|
494
|
+
if (typeof seg === "string") {
|
|
495
|
+
if (!isPlainObject(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Object at key "${seg}"`);
|
|
496
|
+
if (depth === path.length - 1) return cowObjWith(node, seg, val, owned);
|
|
497
|
+
if (!hasOwn(node, seg)) throw new ApplyError("MissingPath", opIndex, `missing object key "${seg}"`);
|
|
498
|
+
const oldChild = node[seg];
|
|
499
|
+
return cowObjWith(node, seg, insertAt(oldChild, path, depth + 1, val, opIndex, owned), owned);
|
|
500
|
+
} else {
|
|
501
|
+
if (!Array.isArray(node)) throw new ApplyError("TypeMismatch", opIndex, `expected Array at index ${seg}`);
|
|
502
|
+
if (depth === path.length - 1) {
|
|
503
|
+
assertValidIndexSeg(seg, node.length, true, opIndex);
|
|
504
|
+
if (owned?.has(node)) {
|
|
505
|
+
node.splice(seg, 0, val);
|
|
506
|
+
return node;
|
|
507
|
+
}
|
|
508
|
+
const out = node.slice(0, seg);
|
|
509
|
+
out.push(val);
|
|
510
|
+
for (let i = seg; i < node.length; i++) out.push(node[i]);
|
|
511
|
+
owned?.add(out);
|
|
512
|
+
return out;
|
|
513
|
+
}
|
|
514
|
+
assertValidIndexSeg(seg, node.length, false, opIndex);
|
|
515
|
+
const oldChild = node[seg];
|
|
516
|
+
return cowArrWith(node, seg, insertAt(oldChild, path, depth + 1, val, opIndex, owned), owned);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function applyOpInternal(state, op, opIndex, owned) {
|
|
520
|
+
switch (op.op) {
|
|
521
|
+
case "set": {
|
|
522
|
+
validatePath(op.path, opIndex);
|
|
523
|
+
const val = validateAndNormalizeJsonValue(op.value, opIndex);
|
|
524
|
+
return setAt(state, op.path, 0, val, opIndex, owned);
|
|
525
|
+
}
|
|
526
|
+
case "unset":
|
|
527
|
+
if (op.path.length === 0) throw new ApplyError("InvalidPath", opIndex, "unset requires non-empty path");
|
|
528
|
+
validatePath(op.path, opIndex);
|
|
529
|
+
return unsetAt(state, op.path, 0, opIndex, owned);
|
|
530
|
+
case "arr_splice": {
|
|
531
|
+
validatePath(op.path, opIndex);
|
|
532
|
+
let normItems;
|
|
533
|
+
for (let i = 0; i < op.items.length; i++) {
|
|
534
|
+
const item = op.items[i];
|
|
535
|
+
const norm = validateAndNormalizeJsonValue(item, opIndex);
|
|
536
|
+
if (norm !== item || normItems !== void 0) {
|
|
537
|
+
if (!normItems) normItems = op.items.slice(0, i);
|
|
538
|
+
normItems.push(norm);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return arrSpliceAt(state, op.path, 0, op.at, op.del, normItems ?? op.items, opIndex, owned);
|
|
542
|
+
}
|
|
543
|
+
case "move": {
|
|
544
|
+
if (op.from.length === 0 || op.to.length === 0) throw new ApplyError("InvalidPath", opIndex, "move requires non-empty from and to paths");
|
|
545
|
+
validatePath(op.from, opIndex);
|
|
546
|
+
validatePath(op.to, opIndex);
|
|
547
|
+
if (pathsEqual(op.from, op.to)) {
|
|
548
|
+
verifyPathExists(state, op.from, opIndex);
|
|
549
|
+
return state;
|
|
550
|
+
}
|
|
551
|
+
const { next: midState, taken } = takeAt(state, op.from, 0, opIndex, owned);
|
|
552
|
+
return insertAt(midState, op.to, 0, taken, opIndex, owned);
|
|
553
|
+
}
|
|
554
|
+
case "str_splice":
|
|
555
|
+
validatePath(op.path, opIndex);
|
|
556
|
+
return strSpliceAt(state, op.path, 0, op.at, op.del, op.ins, opIndex, owned);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Applies a single {@link JsonOp} copy-on-write without mutating `state`.
|
|
561
|
+
* @throws {@link ApplyError} on invalid path, out-of-bounds index, type mismatch, or bad UTF-16 boundary.
|
|
562
|
+
*/
|
|
563
|
+
function applyOp(state, op, opIndex = 0) {
|
|
564
|
+
return applyOpInternal(state, op, opIndex, void 0);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Structural-sharing Copy-on-Write `apply`.
|
|
568
|
+
* - Never mutates `state` or `patch` (atomic rollback on any error is guaranteed).
|
|
569
|
+
* - Uses transient batch ownership on newly allocated nodes to avoid re-cloning them per op.
|
|
570
|
+
* Total cost also includes container copies, array shifts, string scans, value validation,
|
|
571
|
+
* and deep equality checks; it is not bounded solely by operation count and path depth.
|
|
572
|
+
* - Preserves `===` object/array identities for all untouched subtrees and moved subtrees.
|
|
573
|
+
*/
|
|
574
|
+
function apply(state, patch) {
|
|
575
|
+
if (patch.length === 0) return state;
|
|
576
|
+
const owned = /* @__PURE__ */ new Set();
|
|
577
|
+
let cur = state;
|
|
578
|
+
for (let i = 0; i < patch.length; i++) cur = applyOpInternal(cur, patch[i], i, owned);
|
|
579
|
+
return cur;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
//#endregion
|
|
583
|
+
//#region src/diff.ts
|
|
584
|
+
/** Wildcard segment matching any single key or array index inside a pattern. */
|
|
585
|
+
const ANY_SEG = Symbol.for("loro.jsonPatch.any");
|
|
586
|
+
/** Rest wildcard matching zero or more trailing segments inside a pattern. */
|
|
587
|
+
const ANY_REST_SEG = Symbol.for("loro.jsonPatch.anyRest");
|
|
588
|
+
/** Returns `true` when `path` matches `pattern` (supports single-segment and multi-segment globs). */
|
|
589
|
+
function patternMatches(pattern, path) {
|
|
590
|
+
let pi = 0;
|
|
591
|
+
let si = 0;
|
|
592
|
+
let starPi = -1;
|
|
593
|
+
let starSi = 0;
|
|
594
|
+
while (si < path.length) {
|
|
595
|
+
if (pi < pattern.length) {
|
|
596
|
+
const p = pattern[pi];
|
|
597
|
+
if (p === ANY_REST_SEG) {
|
|
598
|
+
starPi = pi;
|
|
599
|
+
starSi = si;
|
|
600
|
+
pi++;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (p === ANY_SEG || path[si] === p) {
|
|
604
|
+
pi++;
|
|
605
|
+
si++;
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (starPi !== -1) {
|
|
610
|
+
pi = starPi + 1;
|
|
611
|
+
starSi++;
|
|
612
|
+
si = starSi;
|
|
613
|
+
} else return false;
|
|
614
|
+
}
|
|
615
|
+
while (pi < pattern.length && pattern[pi] === ANY_REST_SEG) pi++;
|
|
616
|
+
return pi === pattern.length;
|
|
617
|
+
}
|
|
618
|
+
const f64Buf = /* @__PURE__ */ new ArrayBuffer(8);
|
|
619
|
+
const f64View = new DataView(f64Buf);
|
|
620
|
+
function canonicalNumberKey(v) {
|
|
621
|
+
if (typeof v === "bigint") return `n:${v}`;
|
|
622
|
+
const norm = v === 0 ? 0 : v;
|
|
623
|
+
if (Number.isFinite(norm) && Number.isInteger(norm) && norm >= -0x8000000000000000 && norm < 0x10000000000000000) return `n:${BigInt(norm)}`;
|
|
624
|
+
f64View.setFloat64(0, norm, false);
|
|
625
|
+
return `f:${f64View.getUint32(0, false).toString(16).padStart(8, "0")}${f64View.getUint32(4, false).toString(16).padStart(8, "0")}`;
|
|
626
|
+
}
|
|
627
|
+
function extractKey(extractor, val) {
|
|
628
|
+
if (typeof extractor === "function") return extractor(val);
|
|
629
|
+
if (!isPlainObject(val) || !hasOwn(val, extractor)) return void 0;
|
|
630
|
+
const fieldVal = val[extractor];
|
|
631
|
+
if (typeof fieldVal === "string") return `s:${fieldVal}`;
|
|
632
|
+
if (typeof fieldVal === "number" || typeof fieldVal === "bigint") return canonicalNumberKey(fieldVal);
|
|
633
|
+
if (typeof fieldVal === "boolean") return `b:${fieldVal}`;
|
|
634
|
+
}
|
|
635
|
+
function findKeyExtractor(options, path) {
|
|
636
|
+
if (!options.keyExtractors) return void 0;
|
|
637
|
+
for (let i = 0; i < options.keyExtractors.length; i++) if (patternMatches(options.keyExtractors[i].path, path)) return options.keyExtractors[i].extractor;
|
|
638
|
+
}
|
|
639
|
+
function findTreeSpec(options, path) {
|
|
640
|
+
if (!options.treeSpecs) return void 0;
|
|
641
|
+
for (let i = 0; i < options.treeSpecs.length; i++) if (patternMatches(options.treeSpecs[i].rootPath, path)) return options.treeSpecs[i];
|
|
642
|
+
}
|
|
643
|
+
/** O(K log K) Longest Increasing Subsequence membership mask. */
|
|
644
|
+
function lisMask(seq) {
|
|
645
|
+
const k = seq.length;
|
|
646
|
+
const inLis = new Array(k).fill(false);
|
|
647
|
+
if (k === 0) return inLis;
|
|
648
|
+
const tailsVal = [];
|
|
649
|
+
const tailsPos = [];
|
|
650
|
+
const prev = new Array(k).fill(-1);
|
|
651
|
+
for (let i = 0; i < k; i++) {
|
|
652
|
+
const val = seq[i];
|
|
653
|
+
let lo = 0;
|
|
654
|
+
let hi = tailsVal.length;
|
|
655
|
+
while (lo < hi) {
|
|
656
|
+
const mid = lo + hi >>> 1;
|
|
657
|
+
if (tailsVal[mid] < val) lo = mid + 1;
|
|
658
|
+
else hi = mid;
|
|
659
|
+
}
|
|
660
|
+
if (lo > 0) prev[i] = tailsPos[lo - 1];
|
|
661
|
+
if (lo === tailsVal.length) {
|
|
662
|
+
tailsVal.push(val);
|
|
663
|
+
tailsPos.push(i);
|
|
664
|
+
} else {
|
|
665
|
+
tailsVal[lo] = val;
|
|
666
|
+
tailsPos[lo] = i;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
let cur = tailsPos.length > 0 ? tailsPos[tailsPos.length - 1] : -1;
|
|
670
|
+
while (cur !== -1) {
|
|
671
|
+
inLis[cur] = true;
|
|
672
|
+
cur = prev[cur];
|
|
673
|
+
}
|
|
674
|
+
return inLis;
|
|
675
|
+
}
|
|
676
|
+
const TREAP_NONE = -1;
|
|
677
|
+
function splitmix32(x) {
|
|
678
|
+
let z = x + 2654435769 | 0;
|
|
679
|
+
z = Math.imul(z ^ z >>> 16, 2246822507);
|
|
680
|
+
z = Math.imul(z ^ z >>> 13, 3266489909);
|
|
681
|
+
return (z ^ z >>> 16) >>> 0;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Compute minimal `[fromIdx, toIdx]` move pairs in `O(K log K)` transforming `[0..K)`
|
|
685
|
+
* into `targetSeq` (a permutation of `0..K`), keeping the LIS stationary.
|
|
686
|
+
*/
|
|
687
|
+
function lisMovePairs(targetSeq) {
|
|
688
|
+
const k = targetSeq.length;
|
|
689
|
+
if (k <= 1) return [];
|
|
690
|
+
const inLis = lisMask(targetSeq);
|
|
691
|
+
const placed = new Uint8Array(k);
|
|
692
|
+
let allPlaced = true;
|
|
693
|
+
for (let j = 0; j < k; j++) if (inLis[j]) placed[targetSeq[j]] = 1;
|
|
694
|
+
else allPlaced = false;
|
|
695
|
+
if (allPlaced) return [];
|
|
696
|
+
const left = new Int32Array(k).fill(TREAP_NONE);
|
|
697
|
+
const right = new Int32Array(k).fill(TREAP_NONE);
|
|
698
|
+
const parent = new Int32Array(k).fill(TREAP_NONE);
|
|
699
|
+
const size = new Int32Array(k).fill(1);
|
|
700
|
+
const prio = new Uint32Array(k);
|
|
701
|
+
for (let i = 0; i < k; i++) prio[i] = splitmix32(i);
|
|
702
|
+
function pull(x) {
|
|
703
|
+
const l = left[x];
|
|
704
|
+
const r = right[x];
|
|
705
|
+
const ls = l !== TREAP_NONE ? size[l] : 0;
|
|
706
|
+
const rs = r !== TREAP_NONE ? size[r] : 0;
|
|
707
|
+
size[x] = 1 + ls + rs;
|
|
708
|
+
if (l !== TREAP_NONE) parent[l] = x;
|
|
709
|
+
if (r !== TREAP_NONE) parent[r] = x;
|
|
710
|
+
}
|
|
711
|
+
function split(node, pos) {
|
|
712
|
+
if (node === TREAP_NONE) return [TREAP_NONE, TREAP_NONE];
|
|
713
|
+
const l = left[node];
|
|
714
|
+
const ls = l !== TREAP_NONE ? size[l] : 0;
|
|
715
|
+
if (pos <= ls) {
|
|
716
|
+
const [ll, lr] = split(l, pos);
|
|
717
|
+
left[node] = lr;
|
|
718
|
+
pull(node);
|
|
719
|
+
if (ll !== TREAP_NONE) parent[ll] = TREAP_NONE;
|
|
720
|
+
parent[node] = TREAP_NONE;
|
|
721
|
+
return [ll, node];
|
|
722
|
+
} else {
|
|
723
|
+
const r = right[node];
|
|
724
|
+
const [rl, rr] = split(r, pos - ls - 1);
|
|
725
|
+
right[node] = rl;
|
|
726
|
+
pull(node);
|
|
727
|
+
parent[node] = TREAP_NONE;
|
|
728
|
+
if (rr !== TREAP_NONE) parent[rr] = TREAP_NONE;
|
|
729
|
+
return [node, rr];
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
function merge(a, b) {
|
|
733
|
+
if (a === TREAP_NONE) {
|
|
734
|
+
if (b !== TREAP_NONE) parent[b] = TREAP_NONE;
|
|
735
|
+
return b;
|
|
736
|
+
}
|
|
737
|
+
if (b === TREAP_NONE) {
|
|
738
|
+
parent[a] = TREAP_NONE;
|
|
739
|
+
return a;
|
|
740
|
+
}
|
|
741
|
+
if (prio[a] > prio[b]) {
|
|
742
|
+
right[a] = merge(right[a], b);
|
|
743
|
+
pull(a);
|
|
744
|
+
parent[a] = TREAP_NONE;
|
|
745
|
+
return a;
|
|
746
|
+
} else {
|
|
747
|
+
left[b] = merge(a, left[b]);
|
|
748
|
+
pull(b);
|
|
749
|
+
parent[b] = TREAP_NONE;
|
|
750
|
+
return b;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function indexOf(x) {
|
|
754
|
+
let idx = left[x] !== TREAP_NONE ? size[left[x]] : 0;
|
|
755
|
+
let cur = x;
|
|
756
|
+
while (parent[cur] !== TREAP_NONE) {
|
|
757
|
+
const p = parent[cur];
|
|
758
|
+
if (right[p] === cur) {
|
|
759
|
+
const pls = left[p] !== TREAP_NONE ? size[left[p]] : 0;
|
|
760
|
+
idx += pls + 1;
|
|
761
|
+
}
|
|
762
|
+
cur = p;
|
|
763
|
+
}
|
|
764
|
+
return idx;
|
|
765
|
+
}
|
|
766
|
+
let root = TREAP_NONE;
|
|
767
|
+
for (let i = 0; i < k; i++) root = merge(root, i);
|
|
768
|
+
const moves = [];
|
|
769
|
+
for (let j = 0; j < k; j++) {
|
|
770
|
+
const elem = targetSeq[j];
|
|
771
|
+
if (placed[elem] === 1) continue;
|
|
772
|
+
const fromIdx = indexOf(elem);
|
|
773
|
+
let toIdx;
|
|
774
|
+
if (j === 0) toIdx = 0;
|
|
775
|
+
else {
|
|
776
|
+
const prevElem = targetSeq[j - 1];
|
|
777
|
+
const prevIdx = indexOf(prevElem);
|
|
778
|
+
toIdx = fromIdx < prevIdx ? prevIdx : prevIdx + 1;
|
|
779
|
+
}
|
|
780
|
+
if (fromIdx !== toIdx) {
|
|
781
|
+
moves.push([fromIdx, toIdx]);
|
|
782
|
+
const [l1, r1All] = split(root, fromIdx);
|
|
783
|
+
const [moved, r1] = split(r1All, 1);
|
|
784
|
+
root = merge(l1, r1);
|
|
785
|
+
const [l2, r2] = split(root, toIdx);
|
|
786
|
+
root = merge(merge(l2, moved), r2);
|
|
787
|
+
}
|
|
788
|
+
placed[elem] = 1;
|
|
789
|
+
}
|
|
790
|
+
return moves;
|
|
791
|
+
}
|
|
792
|
+
function emitLisMoves(path, indexOffset, targetSeq, ops) {
|
|
793
|
+
const pairs = lisMovePairs(targetSeq);
|
|
794
|
+
if (pairs.length === 0) return false;
|
|
795
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
796
|
+
const [fromIdx, toIdx] = pairs[i];
|
|
797
|
+
ops.push({
|
|
798
|
+
op: "move",
|
|
799
|
+
from: [...path, indexOffset + fromIdx],
|
|
800
|
+
to: [...path, indexOffset + toIdx]
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
function utf8ByteLength(s) {
|
|
806
|
+
let bytes = 0;
|
|
807
|
+
for (let i = 0; i < s.length; i++) {
|
|
808
|
+
const c = s.charCodeAt(i);
|
|
809
|
+
if (c < 128) bytes += 1;
|
|
810
|
+
else if (c < 2048) bytes += 2;
|
|
811
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < s.length) {
|
|
812
|
+
const c2 = s.charCodeAt(i + 1);
|
|
813
|
+
if (c2 >= 56320 && c2 <= 57343) {
|
|
814
|
+
bytes += 4;
|
|
815
|
+
i++;
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
bytes += 3;
|
|
819
|
+
} else bytes += 3;
|
|
820
|
+
}
|
|
821
|
+
return bytes;
|
|
822
|
+
}
|
|
823
|
+
function msgpackUintLen(n) {
|
|
824
|
+
if (n < 128) return 1;
|
|
825
|
+
if (n <= 255) return 2;
|
|
826
|
+
if (n <= 65535) return 3;
|
|
827
|
+
if (n <= 4294967295) return 5;
|
|
828
|
+
return 9;
|
|
829
|
+
}
|
|
830
|
+
function msgpackStrLen(byteLen) {
|
|
831
|
+
return (byteLen < 32 ? 1 : byteLen <= 255 ? 2 : byteLen <= 65535 ? 3 : 5) + byteLen;
|
|
832
|
+
}
|
|
833
|
+
function isHighSurrogate(c) {
|
|
834
|
+
return c >= 55296 && c <= 56319;
|
|
835
|
+
}
|
|
836
|
+
function isLowSurrogate(c) {
|
|
837
|
+
return c >= 56320 && c <= 57343;
|
|
838
|
+
}
|
|
839
|
+
/** Single-pass UTF-16 common prefix/suffix string diff avoiding surrogate splits. */
|
|
840
|
+
function diffStringAt(path, oldStr, newStr, ops) {
|
|
841
|
+
if (oldStr === newStr) return;
|
|
842
|
+
const minLen = Math.min(oldStr.length, newStr.length);
|
|
843
|
+
let prefix = 0;
|
|
844
|
+
while (prefix < minLen && oldStr.charCodeAt(prefix) === newStr.charCodeAt(prefix)) prefix++;
|
|
845
|
+
if (prefix > 0 && (prefix < oldStr.length && isHighSurrogate(oldStr.charCodeAt(prefix - 1)) && isLowSurrogate(oldStr.charCodeAt(prefix)) || prefix < newStr.length && isHighSurrogate(newStr.charCodeAt(prefix - 1)) && isLowSurrogate(newStr.charCodeAt(prefix)))) prefix--;
|
|
846
|
+
let suffix = 0;
|
|
847
|
+
const maxSuffix = minLen - prefix;
|
|
848
|
+
while (suffix < maxSuffix && oldStr.charCodeAt(oldStr.length - 1 - suffix) === newStr.charCodeAt(newStr.length - 1 - suffix)) suffix++;
|
|
849
|
+
if (suffix > 0 && (isLowSurrogate(oldStr.charCodeAt(oldStr.length - suffix)) && isHighSurrogate(oldStr.charCodeAt(oldStr.length - suffix - 1)) || isLowSurrogate(newStr.charCodeAt(newStr.length - suffix)) && isHighSurrogate(newStr.charCodeAt(newStr.length - suffix - 1)))) suffix--;
|
|
850
|
+
const delU16 = oldStr.length - prefix - suffix;
|
|
851
|
+
const ins = newStr.slice(prefix, newStr.length - suffix);
|
|
852
|
+
const hasShared = prefix > 0 || suffix > 0;
|
|
853
|
+
const spliceCost = msgpackUintLen(prefix) + msgpackUintLen(delU16) + msgpackStrLen(utf8ByteLength(ins));
|
|
854
|
+
const setCost = msgpackStrLen(utf8ByteLength(newStr));
|
|
855
|
+
if (hasShared && spliceCost <= setCost) ops.push({
|
|
856
|
+
op: "str_splice",
|
|
857
|
+
path: path.slice(),
|
|
858
|
+
at: prefix,
|
|
859
|
+
del: delU16,
|
|
860
|
+
ins
|
|
861
|
+
});
|
|
862
|
+
else ops.push({
|
|
863
|
+
op: "set",
|
|
864
|
+
path: path.slice(),
|
|
865
|
+
value: newStr
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
function hashString(h, s) {
|
|
869
|
+
for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619);
|
|
870
|
+
return h >>> 0;
|
|
871
|
+
}
|
|
872
|
+
function hashValue(val) {
|
|
873
|
+
let h1 = 2166136261;
|
|
874
|
+
let h2 = 16777619;
|
|
875
|
+
function visit(v) {
|
|
876
|
+
if (v === null) {
|
|
877
|
+
h1 = Math.imul(h1 ^ 1, 16777619);
|
|
878
|
+
h2 = Math.imul(h2 ^ 17, 2246822519);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
switch (typeof v) {
|
|
882
|
+
case "boolean":
|
|
883
|
+
h1 = Math.imul(h1 ^ (v ? 2 : 3), 16777619);
|
|
884
|
+
h2 = Math.imul(h2 ^ (v ? 12 : 13), 2246822519);
|
|
885
|
+
return;
|
|
886
|
+
case "number":
|
|
887
|
+
case "bigint": {
|
|
888
|
+
const s = canonicalNumberKey(v);
|
|
889
|
+
h1 = hashString(h1 ^ 4, s);
|
|
890
|
+
h2 = hashString(h2 ^ 20, s);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
case "string":
|
|
894
|
+
h1 = hashString(h1 ^ 5, v);
|
|
895
|
+
h2 = Math.imul(h2 ^ v.length, 2246822519);
|
|
896
|
+
return;
|
|
897
|
+
case "object":
|
|
898
|
+
if (v instanceof Uint8Array) {
|
|
899
|
+
h1 = Math.imul(h1 ^ 6 ^ v.byteLength, 16777619);
|
|
900
|
+
for (let i = 0; i < v.byteLength; i++) {
|
|
901
|
+
h1 = Math.imul(h1 ^ v[i], 16777619);
|
|
902
|
+
h2 = Math.imul(h2 ^ v[i] + i, 2246822519);
|
|
903
|
+
}
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (Array.isArray(v)) {
|
|
907
|
+
h1 = Math.imul(h1 ^ 7 ^ v.length, 16777619);
|
|
908
|
+
h2 = Math.imul(h2 ^ v.length, 2246822519);
|
|
909
|
+
for (let i = 0; i < v.length; i++) visit(v[i]);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
if (isPlainObject(v)) {
|
|
913
|
+
const keys = Object.keys(v).sort();
|
|
914
|
+
h1 = Math.imul(h1 ^ 8 ^ keys.length, 16777619);
|
|
915
|
+
h2 = Math.imul(h2 ^ keys.length, 2246822519);
|
|
916
|
+
for (let i = 0; i < keys.length; i++) {
|
|
917
|
+
const k = keys[i];
|
|
918
|
+
h1 = hashString(h1, k);
|
|
919
|
+
visit(v[k]);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
visit(val);
|
|
925
|
+
return `${h1 >>> 0}:${h2 >>> 0}`;
|
|
926
|
+
}
|
|
927
|
+
function normalizeNegZero(val) {
|
|
928
|
+
if (typeof val === "number") return Object.is(val, -0) ? 0 : val;
|
|
929
|
+
if (typeof val !== "object" || val === null || val instanceof Uint8Array) return val;
|
|
930
|
+
if (Array.isArray(val)) {
|
|
931
|
+
let changed = false;
|
|
932
|
+
const out = [];
|
|
933
|
+
for (let i = 0; i < val.length; i++) {
|
|
934
|
+
const nv = normalizeNegZero(val[i]);
|
|
935
|
+
if (nv !== val[i]) {
|
|
936
|
+
if (!changed) {
|
|
937
|
+
for (let j = 0; j < i; j++) out.push(val[j]);
|
|
938
|
+
changed = true;
|
|
939
|
+
}
|
|
940
|
+
out.push(nv);
|
|
941
|
+
} else if (changed) out.push(nv);
|
|
942
|
+
}
|
|
943
|
+
return changed ? out : val;
|
|
944
|
+
}
|
|
945
|
+
if (isPlainObject(val)) {
|
|
946
|
+
const keys = Object.keys(val);
|
|
947
|
+
let changed = false;
|
|
948
|
+
let out;
|
|
949
|
+
for (let i = 0; i < keys.length; i++) {
|
|
950
|
+
const k = keys[i];
|
|
951
|
+
const nv = normalizeNegZero(val[k]);
|
|
952
|
+
if (nv !== val[k]) {
|
|
953
|
+
if (!changed) {
|
|
954
|
+
out = {};
|
|
955
|
+
for (let j = 0; j < i; j++) setOwnProp(out, keys[j], val[keys[j]]);
|
|
956
|
+
changed = true;
|
|
957
|
+
}
|
|
958
|
+
setOwnProp(out, k, nv);
|
|
959
|
+
} else if (changed) setOwnProp(out, k, nv);
|
|
960
|
+
}
|
|
961
|
+
return changed ? out : val;
|
|
962
|
+
}
|
|
963
|
+
return val;
|
|
964
|
+
}
|
|
965
|
+
function diffKeyedArray(path, oldArr, newArr, oldKeys, newKeys, options, ops) {
|
|
966
|
+
const oldKeyMap = /* @__PURE__ */ new Map();
|
|
967
|
+
for (let i$1 = 0; i$1 < oldKeys.length; i$1++) {
|
|
968
|
+
const k = oldKeys[i$1];
|
|
969
|
+
if (k === void 0 || oldKeyMap.has(k)) {
|
|
970
|
+
diffUnkeyedArray(path, oldArr, newArr, options, ops);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
oldKeyMap.set(k, i$1);
|
|
974
|
+
}
|
|
975
|
+
const newKeySet = /* @__PURE__ */ new Set();
|
|
976
|
+
const oldToNew = new Array(oldArr.length).fill(-1);
|
|
977
|
+
const newToOld = new Array(newArr.length).fill(-1);
|
|
978
|
+
for (let j$1 = 0; j$1 < newKeys.length; j$1++) {
|
|
979
|
+
const k = newKeys[j$1];
|
|
980
|
+
if (k === void 0 || newKeySet.has(k)) {
|
|
981
|
+
diffUnkeyedArray(path, oldArr, newArr, options, ops);
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
newKeySet.add(k);
|
|
985
|
+
const oi = oldKeyMap.get(k);
|
|
986
|
+
if (oi !== void 0) {
|
|
987
|
+
oldToNew[oi] = j$1;
|
|
988
|
+
newToOld[j$1] = oi;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
let i = oldArr.length;
|
|
992
|
+
while (i > 0) {
|
|
993
|
+
i--;
|
|
994
|
+
if (oldToNew[i] === -1) {
|
|
995
|
+
let delCnt = 1;
|
|
996
|
+
while (i > 0 && oldToNew[i - 1] === -1) {
|
|
997
|
+
i--;
|
|
998
|
+
delCnt++;
|
|
999
|
+
}
|
|
1000
|
+
ops.push({
|
|
1001
|
+
op: "arr_splice",
|
|
1002
|
+
path: path.slice(),
|
|
1003
|
+
at: i,
|
|
1004
|
+
del: delCnt,
|
|
1005
|
+
items: []
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
const oldIdxToCompact = new Array(oldArr.length).fill(-1);
|
|
1010
|
+
let compactCnt = 0;
|
|
1011
|
+
for (let oi = 0; oi < oldArr.length; oi++) if (oldToNew[oi] !== -1) oldIdxToCompact[oi] = compactCnt++;
|
|
1012
|
+
const targetSeq = [];
|
|
1013
|
+
for (let nj = 0; nj < newArr.length; nj++) {
|
|
1014
|
+
const oi = newToOld[nj];
|
|
1015
|
+
if (oi !== -1) targetSeq.push(oldIdxToCompact[oi]);
|
|
1016
|
+
}
|
|
1017
|
+
emitLisMoves(path, 0, targetSeq, ops);
|
|
1018
|
+
let j = 0;
|
|
1019
|
+
while (j < newArr.length) if (newToOld[j] === -1) {
|
|
1020
|
+
const start = j;
|
|
1021
|
+
const items = [];
|
|
1022
|
+
while (j < newArr.length && newToOld[j] === -1) {
|
|
1023
|
+
items.push(normalizeNegZero(newArr[j]));
|
|
1024
|
+
j++;
|
|
1025
|
+
}
|
|
1026
|
+
ops.push({
|
|
1027
|
+
op: "arr_splice",
|
|
1028
|
+
path: path.slice(),
|
|
1029
|
+
at: start,
|
|
1030
|
+
del: 0,
|
|
1031
|
+
items
|
|
1032
|
+
});
|
|
1033
|
+
} else j++;
|
|
1034
|
+
for (let nj = 0; nj < newArr.length; nj++) {
|
|
1035
|
+
const oi = newToOld[nj];
|
|
1036
|
+
if (oi === -1) continue;
|
|
1037
|
+
path.push(nj);
|
|
1038
|
+
diffAt(path, oldArr[oi], newArr[nj], options, ops);
|
|
1039
|
+
path.pop();
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function diffUnkeyedArray(path, oldArr, newArr, options, ops) {
|
|
1043
|
+
const minLen = Math.min(oldArr.length, newArr.length);
|
|
1044
|
+
let prefix = 0;
|
|
1045
|
+
while (prefix < minLen && valuesEqual(oldArr[prefix], newArr[prefix])) prefix++;
|
|
1046
|
+
let suffix = 0;
|
|
1047
|
+
while (suffix < minLen - prefix && valuesEqual(oldArr[oldArr.length - 1 - suffix], newArr[newArr.length - 1 - suffix])) suffix++;
|
|
1048
|
+
const oldMidStart = prefix;
|
|
1049
|
+
const oldMidEnd = oldArr.length - suffix;
|
|
1050
|
+
const newMidStart = prefix;
|
|
1051
|
+
const newMidEnd = newArr.length - suffix;
|
|
1052
|
+
const oldMidLen = oldMidEnd - oldMidStart;
|
|
1053
|
+
const newMidLen = newMidEnd - newMidStart;
|
|
1054
|
+
if (oldMidLen === 0 && newMidLen === 0) return;
|
|
1055
|
+
if (oldMidLen === 0) {
|
|
1056
|
+
ops.push({
|
|
1057
|
+
op: "arr_splice",
|
|
1058
|
+
path: path.slice(),
|
|
1059
|
+
at: prefix,
|
|
1060
|
+
del: 0,
|
|
1061
|
+
items: newArr.slice(newMidStart, newMidEnd).map(normalizeNegZero)
|
|
1062
|
+
});
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (newMidLen === 0) {
|
|
1066
|
+
ops.push({
|
|
1067
|
+
op: "arr_splice",
|
|
1068
|
+
path: path.slice(),
|
|
1069
|
+
at: prefix,
|
|
1070
|
+
del: oldMidLen,
|
|
1071
|
+
items: []
|
|
1072
|
+
});
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
1076
|
+
for (let i$1 = oldMidLen - 1; i$1 >= 0; i$1--) {
|
|
1077
|
+
const h = hashValue(oldArr[oldMidStart + i$1]);
|
|
1078
|
+
let q = buckets.get(h);
|
|
1079
|
+
if (!q) {
|
|
1080
|
+
q = [];
|
|
1081
|
+
buckets.set(h, q);
|
|
1082
|
+
}
|
|
1083
|
+
q.push(i$1);
|
|
1084
|
+
}
|
|
1085
|
+
const oldToNew = new Array(oldMidLen).fill(-1);
|
|
1086
|
+
const newToOld = new Array(newMidLen).fill(-1);
|
|
1087
|
+
for (let j$1 = 0; j$1 < newMidLen; j$1++) {
|
|
1088
|
+
const targetVal = newArr[newMidStart + j$1];
|
|
1089
|
+
const h = hashValue(targetVal);
|
|
1090
|
+
const q = buckets.get(h);
|
|
1091
|
+
if (!q) continue;
|
|
1092
|
+
for (let qi = q.length - 1; qi >= 0; qi--) {
|
|
1093
|
+
const oi = q[qi];
|
|
1094
|
+
if (valuesEqual(oldArr[oldMidStart + oi], targetVal)) {
|
|
1095
|
+
if (qi === q.length - 1) q.pop();
|
|
1096
|
+
else q.splice(qi, 1);
|
|
1097
|
+
oldToNew[oi] = j$1;
|
|
1098
|
+
newToOld[j$1] = oi;
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
let matchedCount = 0;
|
|
1104
|
+
for (let i$1 = 0; i$1 < oldMidLen; i$1++) if (oldToNew[i$1] !== -1) matchedCount++;
|
|
1105
|
+
if (matchedCount === 0) {
|
|
1106
|
+
if (oldMidLen === newMidLen) for (let k = 0; k < oldMidLen; k++) {
|
|
1107
|
+
path.push(prefix + k);
|
|
1108
|
+
diffAt(path, oldArr[oldMidStart + k], newArr[newMidStart + k], options, ops);
|
|
1109
|
+
path.pop();
|
|
1110
|
+
}
|
|
1111
|
+
else ops.push({
|
|
1112
|
+
op: "arr_splice",
|
|
1113
|
+
path: path.slice(),
|
|
1114
|
+
at: prefix,
|
|
1115
|
+
del: oldMidLen,
|
|
1116
|
+
items: newArr.slice(newMidStart, newMidEnd).map(normalizeNegZero)
|
|
1117
|
+
});
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
let prevOld = -1;
|
|
1121
|
+
let needsMove = false;
|
|
1122
|
+
for (let nj = 0; nj < newMidLen; nj++) {
|
|
1123
|
+
const oi = newToOld[nj];
|
|
1124
|
+
if (oi !== -1) {
|
|
1125
|
+
if (prevOld !== -1 && oi < prevOld) {
|
|
1126
|
+
needsMove = true;
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
prevOld = oi;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
if (!needsMove) {
|
|
1133
|
+
let curLenDelta = 0;
|
|
1134
|
+
let oi = 0;
|
|
1135
|
+
let nj = 0;
|
|
1136
|
+
while (oi < oldMidLen || nj < newMidLen) {
|
|
1137
|
+
const delStart = oi;
|
|
1138
|
+
while (oi < oldMidLen && oldToNew[oi] === -1) oi++;
|
|
1139
|
+
const delCnt = oi - delStart;
|
|
1140
|
+
const insStart = nj;
|
|
1141
|
+
while (nj < newMidLen && newToOld[nj] === -1) nj++;
|
|
1142
|
+
const insCnt = nj - insStart;
|
|
1143
|
+
if (delCnt > 0 || insCnt > 0) {
|
|
1144
|
+
const at = prefix + delStart + curLenDelta;
|
|
1145
|
+
ops.push({
|
|
1146
|
+
op: "arr_splice",
|
|
1147
|
+
path: path.slice(),
|
|
1148
|
+
at,
|
|
1149
|
+
del: delCnt,
|
|
1150
|
+
items: newArr.slice(newMidStart + insStart, newMidStart + insStart + insCnt).map(normalizeNegZero)
|
|
1151
|
+
});
|
|
1152
|
+
curLenDelta += insCnt - delCnt;
|
|
1153
|
+
}
|
|
1154
|
+
if (oi < oldMidLen && nj < newMidLen) {
|
|
1155
|
+
path.push(prefix + nj);
|
|
1156
|
+
diffAt(path, oldArr[oldMidStart + oi], newArr[newMidStart + nj], options, ops);
|
|
1157
|
+
path.pop();
|
|
1158
|
+
oi++;
|
|
1159
|
+
nj++;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
let i = oldMidLen;
|
|
1165
|
+
while (i > 0) {
|
|
1166
|
+
i--;
|
|
1167
|
+
if (oldToNew[i] === -1) {
|
|
1168
|
+
let delCnt = 1;
|
|
1169
|
+
while (i > 0 && oldToNew[i - 1] === -1) {
|
|
1170
|
+
i--;
|
|
1171
|
+
delCnt++;
|
|
1172
|
+
}
|
|
1173
|
+
ops.push({
|
|
1174
|
+
op: "arr_splice",
|
|
1175
|
+
path: path.slice(),
|
|
1176
|
+
at: prefix + i,
|
|
1177
|
+
del: delCnt,
|
|
1178
|
+
items: []
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
const oldIdxToCompact = new Array(oldMidLen).fill(-1);
|
|
1183
|
+
let compactCnt = 0;
|
|
1184
|
+
for (let oi = 0; oi < oldMidLen; oi++) if (oldToNew[oi] !== -1) oldIdxToCompact[oi] = compactCnt++;
|
|
1185
|
+
const targetSeq = [];
|
|
1186
|
+
for (let nj = 0; nj < newMidLen; nj++) {
|
|
1187
|
+
const oi = newToOld[nj];
|
|
1188
|
+
if (oi !== -1) targetSeq.push(oldIdxToCompact[oi]);
|
|
1189
|
+
}
|
|
1190
|
+
emitLisMoves(path, prefix, targetSeq, ops);
|
|
1191
|
+
let j = 0;
|
|
1192
|
+
while (j < newMidLen) if (newToOld[j] === -1) {
|
|
1193
|
+
const start = j;
|
|
1194
|
+
const items = [];
|
|
1195
|
+
while (j < newMidLen && newToOld[j] === -1) {
|
|
1196
|
+
items.push(normalizeNegZero(newArr[newMidStart + j]));
|
|
1197
|
+
j++;
|
|
1198
|
+
}
|
|
1199
|
+
ops.push({
|
|
1200
|
+
op: "arr_splice",
|
|
1201
|
+
path: path.slice(),
|
|
1202
|
+
at: prefix + start,
|
|
1203
|
+
del: 0,
|
|
1204
|
+
items
|
|
1205
|
+
});
|
|
1206
|
+
} else j++;
|
|
1207
|
+
}
|
|
1208
|
+
function parseSimTreeNodes(arr, spec, seenIds) {
|
|
1209
|
+
const out = [];
|
|
1210
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1211
|
+
const item = arr[i];
|
|
1212
|
+
if (!isPlainObject(item) || !hasOwn(item, spec.idField)) return void 0;
|
|
1213
|
+
const rawId = item[spec.idField];
|
|
1214
|
+
let idStr;
|
|
1215
|
+
if (typeof rawId === "string") idStr = `s:${rawId}`;
|
|
1216
|
+
else if (typeof rawId === "number" || typeof rawId === "bigint") idStr = canonicalNumberKey(rawId);
|
|
1217
|
+
else return void 0;
|
|
1218
|
+
if (seenIds.has(idStr)) return void 0;
|
|
1219
|
+
seenIds.add(idStr);
|
|
1220
|
+
if (!hasOwn(item, spec.childrenField)) return void 0;
|
|
1221
|
+
const cVal = item[spec.childrenField];
|
|
1222
|
+
if (!Array.isArray(cVal)) return void 0;
|
|
1223
|
+
const children = parseSimTreeNodes(cVal, spec, seenIds);
|
|
1224
|
+
if (!children) return void 0;
|
|
1225
|
+
out.push({
|
|
1226
|
+
id: idStr,
|
|
1227
|
+
raw: item,
|
|
1228
|
+
children
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
return out;
|
|
1232
|
+
}
|
|
1233
|
+
function collectTreeIds(nodes, out) {
|
|
1234
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1235
|
+
out.add(nodes[i].id);
|
|
1236
|
+
collectTreeIds(nodes[i].children, out);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function anyDescendantIn(node, idSet) {
|
|
1240
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
1241
|
+
const c = node.children[i];
|
|
1242
|
+
if (idSet.has(c.id) || anyDescendantIn(c, idSet)) return true;
|
|
1243
|
+
}
|
|
1244
|
+
return false;
|
|
1245
|
+
}
|
|
1246
|
+
function findTreeNodePath(nodes, targetId, prefix, childrenField) {
|
|
1247
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1248
|
+
if (nodes[i].id === targetId) return [...prefix, i];
|
|
1249
|
+
const nextPrefix = [
|
|
1250
|
+
...prefix,
|
|
1251
|
+
i,
|
|
1252
|
+
childrenField
|
|
1253
|
+
];
|
|
1254
|
+
const found = findTreeNodePath(nodes[i].children, targetId, nextPrefix, childrenField);
|
|
1255
|
+
if (found) return found;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
function takeTreeNode(nodes, targetId) {
|
|
1259
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1260
|
+
if (nodes[i].id === targetId) return nodes.splice(i, 1)[0];
|
|
1261
|
+
const found = takeTreeNode(nodes[i].children, targetId);
|
|
1262
|
+
if (found) return found;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
function findTreeChildrenList(roots, parentId) {
|
|
1266
|
+
if (parentId === void 0) return roots;
|
|
1267
|
+
function findNode(nodes) {
|
|
1268
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1269
|
+
if (nodes[i].id === parentId) return nodes[i];
|
|
1270
|
+
const f = findNode(nodes[i].children);
|
|
1271
|
+
if (f) return f;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return findNode(roots)?.children;
|
|
1275
|
+
}
|
|
1276
|
+
function treeParentChildrenPath(roots, treePath, parentId, childrenField) {
|
|
1277
|
+
if (parentId === void 0) return {
|
|
1278
|
+
path: treePath.slice(),
|
|
1279
|
+
len: roots.length
|
|
1280
|
+
};
|
|
1281
|
+
const nodePath = findTreeNodePath(roots, parentId, treePath.slice(), childrenField);
|
|
1282
|
+
if (!nodePath) return void 0;
|
|
1283
|
+
const list = findTreeChildrenList(roots, parentId);
|
|
1284
|
+
return {
|
|
1285
|
+
path: [...nodePath, childrenField],
|
|
1286
|
+
len: list ? list.length : 0
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
function diffTreeArray(treePath, oldArr, newArr, spec, options, ops) {
|
|
1290
|
+
const oldIds = /* @__PURE__ */ new Set();
|
|
1291
|
+
const curRoots = parseSimTreeNodes(oldArr, spec, oldIds);
|
|
1292
|
+
const newIds = /* @__PURE__ */ new Set();
|
|
1293
|
+
const targetRoots = parseSimTreeNodes(newArr, spec, newIds);
|
|
1294
|
+
if (!curRoots || !targetRoots) return false;
|
|
1295
|
+
const placedWhole = /* @__PURE__ */ new Set();
|
|
1296
|
+
function placePreorder(parentId, targetNodes) {
|
|
1297
|
+
for (let i = 0; i < targetNodes.length; i++) {
|
|
1298
|
+
const tn = targetNodes[i];
|
|
1299
|
+
if (placedWhole.has(tn.id)) continue;
|
|
1300
|
+
if (!oldIds.has(tn.id)) {
|
|
1301
|
+
const parentInfo = treeParentChildrenPath(curRoots, treePath, parentId, spec.childrenField);
|
|
1302
|
+
if (!anyDescendantIn(tn, oldIds)) {
|
|
1303
|
+
ops.push({
|
|
1304
|
+
op: "arr_splice",
|
|
1305
|
+
path: parentInfo.path,
|
|
1306
|
+
at: parentInfo.len,
|
|
1307
|
+
del: 0,
|
|
1308
|
+
items: [normalizeNegZero(tn.raw)]
|
|
1309
|
+
});
|
|
1310
|
+
findTreeChildrenList(curRoots, parentId).push({
|
|
1311
|
+
id: tn.id,
|
|
1312
|
+
raw: tn.raw,
|
|
1313
|
+
children: tn.children.slice()
|
|
1314
|
+
});
|
|
1315
|
+
collectTreeIds([tn], placedWhole);
|
|
1316
|
+
continue;
|
|
1317
|
+
} else {
|
|
1318
|
+
const shell = {};
|
|
1319
|
+
const rawKeys = Object.keys(tn.raw);
|
|
1320
|
+
for (let rk = 0; rk < rawKeys.length; rk++) {
|
|
1321
|
+
const k = rawKeys[rk];
|
|
1322
|
+
setOwnProp(shell, k, k === spec.childrenField ? [] : tn.raw[k]);
|
|
1323
|
+
}
|
|
1324
|
+
setOwnProp(shell, spec.childrenField, []);
|
|
1325
|
+
ops.push({
|
|
1326
|
+
op: "arr_splice",
|
|
1327
|
+
path: parentInfo.path,
|
|
1328
|
+
at: parentInfo.len,
|
|
1329
|
+
del: 0,
|
|
1330
|
+
items: [normalizeNegZero(shell)]
|
|
1331
|
+
});
|
|
1332
|
+
findTreeChildrenList(curRoots, parentId).push({
|
|
1333
|
+
id: tn.id,
|
|
1334
|
+
raw: shell,
|
|
1335
|
+
children: []
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
} else if (!findTreeChildrenList(curRoots, parentId).some((s) => s.id === tn.id)) {
|
|
1339
|
+
const fromPath = findTreeNodePath(curRoots, tn.id, treePath.slice(), spec.childrenField);
|
|
1340
|
+
const moved = takeTreeNode(curRoots, tn.id);
|
|
1341
|
+
const toInfo = treeParentChildrenPath(curRoots, treePath, parentId, spec.childrenField);
|
|
1342
|
+
ops.push({
|
|
1343
|
+
op: "move",
|
|
1344
|
+
from: fromPath,
|
|
1345
|
+
to: [...toInfo.path, toInfo.len]
|
|
1346
|
+
});
|
|
1347
|
+
findTreeChildrenList(curRoots, parentId).push(moved);
|
|
1348
|
+
}
|
|
1349
|
+
placePreorder(tn.id, tn.children);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
placePreorder(void 0, targetRoots);
|
|
1353
|
+
function deleteDoomed(childrenPath, nodes) {
|
|
1354
|
+
let idx = nodes.length;
|
|
1355
|
+
while (idx > 0) {
|
|
1356
|
+
idx--;
|
|
1357
|
+
if (!newIds.has(nodes[idx].id)) {
|
|
1358
|
+
let delCnt = 1;
|
|
1359
|
+
while (idx > 0 && !newIds.has(nodes[idx - 1].id)) {
|
|
1360
|
+
idx--;
|
|
1361
|
+
delCnt++;
|
|
1362
|
+
}
|
|
1363
|
+
ops.push({
|
|
1364
|
+
op: "arr_splice",
|
|
1365
|
+
path: childrenPath.slice(),
|
|
1366
|
+
at: idx,
|
|
1367
|
+
del: delCnt,
|
|
1368
|
+
items: []
|
|
1369
|
+
});
|
|
1370
|
+
nodes.splice(idx, delCnt);
|
|
1371
|
+
} else deleteDoomed([
|
|
1372
|
+
...childrenPath,
|
|
1373
|
+
idx,
|
|
1374
|
+
spec.childrenField
|
|
1375
|
+
], nodes[idx].children);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
deleteDoomed(treePath.slice(), curRoots);
|
|
1379
|
+
function reorderAndDiff(childrenPath, curNodes, targetNodes) {
|
|
1380
|
+
if (targetNodes.length > 1) {
|
|
1381
|
+
const curIdxMap = /* @__PURE__ */ new Map();
|
|
1382
|
+
for (let i = 0; i < curNodes.length; i++) curIdxMap.set(curNodes[i].id, i);
|
|
1383
|
+
const targetSeq = targetNodes.map((tn) => curIdxMap.get(tn.id));
|
|
1384
|
+
if (emitLisMoves(childrenPath, 0, targetSeq, ops)) {
|
|
1385
|
+
const reordered = new Array(targetSeq.length);
|
|
1386
|
+
for (let i = 0; i < targetSeq.length; i++) reordered[i] = curNodes[targetSeq[i]];
|
|
1387
|
+
for (let i = 0; i < reordered.length; i++) curNodes[i] = reordered[i];
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
for (let i = 0; i < targetNodes.length; i++) {
|
|
1391
|
+
const cn = curNodes[i];
|
|
1392
|
+
const tn = targetNodes[i];
|
|
1393
|
+
if (!placedWhole.has(tn.id)) {
|
|
1394
|
+
const nodePath = [...childrenPath, i];
|
|
1395
|
+
const oldRaw = cn.raw;
|
|
1396
|
+
const newRaw = tn.raw;
|
|
1397
|
+
const oldKeys = Object.keys(oldRaw).sort();
|
|
1398
|
+
const newKeys = Object.keys(newRaw).sort();
|
|
1399
|
+
for (let ki = 0; ki < oldKeys.length; ki++) {
|
|
1400
|
+
const key = oldKeys[ki];
|
|
1401
|
+
if (key === spec.childrenField) continue;
|
|
1402
|
+
if (!hasOwn(newRaw, key)) ops.push({
|
|
1403
|
+
op: "unset",
|
|
1404
|
+
path: [...nodePath, key]
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
for (let ki = 0; ki < newKeys.length; ki++) {
|
|
1408
|
+
const key = newKeys[ki];
|
|
1409
|
+
if (key === spec.childrenField) continue;
|
|
1410
|
+
if (!hasOwn(oldRaw, key)) ops.push({
|
|
1411
|
+
op: "set",
|
|
1412
|
+
path: [...nodePath, key],
|
|
1413
|
+
value: normalizeNegZero(newRaw[key])
|
|
1414
|
+
});
|
|
1415
|
+
else diffAt([...nodePath, key], oldRaw[key], newRaw[key], options, ops);
|
|
1416
|
+
}
|
|
1417
|
+
reorderAndDiff([...nodePath, spec.childrenField], cn.children, tn.children);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
reorderAndDiff(treePath.slice(), curRoots, targetRoots);
|
|
1422
|
+
return true;
|
|
1423
|
+
}
|
|
1424
|
+
function diffAt(path, oldVal, newVal, options, ops) {
|
|
1425
|
+
if (valuesEqual(oldVal, newVal)) return;
|
|
1426
|
+
if (typeof oldVal === "string" && typeof newVal === "string") {
|
|
1427
|
+
diffStringAt(path, oldVal, newVal, ops);
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
if (isPlainObject(oldVal) && isPlainObject(newVal)) {
|
|
1431
|
+
const oldKeys = Object.keys(oldVal).sort();
|
|
1432
|
+
const newKeys = Object.keys(newVal).sort();
|
|
1433
|
+
for (let i = 0; i < oldKeys.length; i++) {
|
|
1434
|
+
const key = oldKeys[i];
|
|
1435
|
+
if (!hasOwn(newVal, key)) ops.push({
|
|
1436
|
+
op: "unset",
|
|
1437
|
+
path: [...path, key]
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
for (let i = 0; i < newKeys.length; i++) {
|
|
1441
|
+
const key = newKeys[i];
|
|
1442
|
+
if (!hasOwn(oldVal, key)) ops.push({
|
|
1443
|
+
op: "set",
|
|
1444
|
+
path: [...path, key],
|
|
1445
|
+
value: normalizeNegZero(newVal[key])
|
|
1446
|
+
});
|
|
1447
|
+
else {
|
|
1448
|
+
path.push(key);
|
|
1449
|
+
diffAt(path, oldVal[key], newVal[key], options, ops);
|
|
1450
|
+
path.pop();
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
if (Array.isArray(oldVal) && Array.isArray(newVal)) {
|
|
1456
|
+
const treeSpec = findTreeSpec(options, path);
|
|
1457
|
+
if (treeSpec && diffTreeArray(path, oldVal, newVal, treeSpec, options, ops)) return;
|
|
1458
|
+
const extractor = findKeyExtractor(options, path);
|
|
1459
|
+
if (extractor) {
|
|
1460
|
+
diffKeyedArray(path, oldVal, newVal, oldVal.map((item) => extractKey(extractor, item)), newVal.map((item) => extractKey(extractor, item)), options, ops);
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
diffUnkeyedArray(path, oldVal, newVal, options, ops);
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
ops.push({
|
|
1467
|
+
op: "set",
|
|
1468
|
+
path: path.slice(),
|
|
1469
|
+
value: normalizeNegZero(newVal)
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Computes {@link JsonOp} operations transforming plain JSON `oldState` into `newState`.
|
|
1474
|
+
* Emits `str_splice` on modified strings, `arr_splice` on unkeyed arrays, and LIS-minimal `move` + inner diffs
|
|
1475
|
+
* when `options.keyExtractors` matches an array path.
|
|
1476
|
+
* This function does not inspect a Loro DocSchema. Its string splices may be rejected by
|
|
1477
|
+
* strict Loro writes targeting atomic string values; use scalar `set` operations there and
|
|
1478
|
+
* reserve `str_splice` for LoroText containers. Key extractors only control array identity.
|
|
1479
|
+
*/
|
|
1480
|
+
function diff(oldState, newState, options = {}) {
|
|
1481
|
+
const ops = [];
|
|
1482
|
+
diffAt([], oldState, newState, options, ops);
|
|
1483
|
+
return ops;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
//#endregion
|
|
1487
|
+
Object.defineProperty(exports, 'ANY_REST_SEG', {
|
|
1488
|
+
enumerable: true,
|
|
1489
|
+
get: function () {
|
|
1490
|
+
return ANY_REST_SEG;
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
Object.defineProperty(exports, 'ANY_SEG', {
|
|
1494
|
+
enumerable: true,
|
|
1495
|
+
get: function () {
|
|
1496
|
+
return ANY_SEG;
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
Object.defineProperty(exports, 'ApplyError', {
|
|
1500
|
+
enumerable: true,
|
|
1501
|
+
get: function () {
|
|
1502
|
+
return ApplyError;
|
|
1503
|
+
}
|
|
1504
|
+
});
|
|
1505
|
+
Object.defineProperty(exports, 'DecodeError', {
|
|
1506
|
+
enumerable: true,
|
|
1507
|
+
get: function () {
|
|
1508
|
+
return DecodeError;
|
|
1509
|
+
}
|
|
1510
|
+
});
|
|
1511
|
+
Object.defineProperty(exports, 'I64_MAX', {
|
|
1512
|
+
enumerable: true,
|
|
1513
|
+
get: function () {
|
|
1514
|
+
return I64_MAX;
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
Object.defineProperty(exports, 'I64_MIN', {
|
|
1518
|
+
enumerable: true,
|
|
1519
|
+
get: function () {
|
|
1520
|
+
return I64_MIN;
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
Object.defineProperty(exports, 'MAX_SAFE_BIG', {
|
|
1524
|
+
enumerable: true,
|
|
1525
|
+
get: function () {
|
|
1526
|
+
return MAX_SAFE_BIG;
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
Object.defineProperty(exports, 'MIN_SAFE_BIG', {
|
|
1530
|
+
enumerable: true,
|
|
1531
|
+
get: function () {
|
|
1532
|
+
return MIN_SAFE_BIG;
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
Object.defineProperty(exports, 'U64_MAX', {
|
|
1536
|
+
enumerable: true,
|
|
1537
|
+
get: function () {
|
|
1538
|
+
return U64_MAX;
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
Object.defineProperty(exports, '__toESM', {
|
|
1542
|
+
enumerable: true,
|
|
1543
|
+
get: function () {
|
|
1544
|
+
return __toESM;
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
Object.defineProperty(exports, 'apply', {
|
|
1548
|
+
enumerable: true,
|
|
1549
|
+
get: function () {
|
|
1550
|
+
return apply;
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
Object.defineProperty(exports, 'applyOp', {
|
|
1554
|
+
enumerable: true,
|
|
1555
|
+
get: function () {
|
|
1556
|
+
return applyOp;
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
Object.defineProperty(exports, 'assertNoLoneSurrogates', {
|
|
1560
|
+
enumerable: true,
|
|
1561
|
+
get: function () {
|
|
1562
|
+
return assertNoLoneSurrogates;
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
Object.defineProperty(exports, 'assertValidUtf16Boundary', {
|
|
1566
|
+
enumerable: true,
|
|
1567
|
+
get: function () {
|
|
1568
|
+
return assertValidUtf16Boundary;
|
|
1569
|
+
}
|
|
1570
|
+
});
|
|
1571
|
+
Object.defineProperty(exports, 'assertValidUtf16Range', {
|
|
1572
|
+
enumerable: true,
|
|
1573
|
+
get: function () {
|
|
1574
|
+
return assertValidUtf16Range;
|
|
1575
|
+
}
|
|
1576
|
+
});
|
|
1577
|
+
Object.defineProperty(exports, 'diff', {
|
|
1578
|
+
enumerable: true,
|
|
1579
|
+
get: function () {
|
|
1580
|
+
return diff;
|
|
1581
|
+
}
|
|
1582
|
+
});
|
|
1583
|
+
Object.defineProperty(exports, 'diffStringAt', {
|
|
1584
|
+
enumerable: true,
|
|
1585
|
+
get: function () {
|
|
1586
|
+
return diffStringAt;
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
Object.defineProperty(exports, 'hasLoneSurrogates', {
|
|
1590
|
+
enumerable: true,
|
|
1591
|
+
get: function () {
|
|
1592
|
+
return hasLoneSurrogates;
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
Object.defineProperty(exports, 'hasOwn', {
|
|
1596
|
+
enumerable: true,
|
|
1597
|
+
get: function () {
|
|
1598
|
+
return hasOwn;
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
Object.defineProperty(exports, 'isPlainObject', {
|
|
1602
|
+
enumerable: true,
|
|
1603
|
+
get: function () {
|
|
1604
|
+
return isPlainObject;
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
Object.defineProperty(exports, 'lisMask', {
|
|
1608
|
+
enumerable: true,
|
|
1609
|
+
get: function () {
|
|
1610
|
+
return lisMask;
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
Object.defineProperty(exports, 'lisMovePairs', {
|
|
1614
|
+
enumerable: true,
|
|
1615
|
+
get: function () {
|
|
1616
|
+
return lisMovePairs;
|
|
1617
|
+
}
|
|
1618
|
+
});
|
|
1619
|
+
Object.defineProperty(exports, 'numbersEqual', {
|
|
1620
|
+
enumerable: true,
|
|
1621
|
+
get: function () {
|
|
1622
|
+
return numbersEqual;
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
Object.defineProperty(exports, 'pathsEqual', {
|
|
1626
|
+
enumerable: true,
|
|
1627
|
+
get: function () {
|
|
1628
|
+
return pathsEqual;
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
Object.defineProperty(exports, 'pathsOverlap', {
|
|
1632
|
+
enumerable: true,
|
|
1633
|
+
get: function () {
|
|
1634
|
+
return pathsOverlap;
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
Object.defineProperty(exports, 'patternMatches', {
|
|
1638
|
+
enumerable: true,
|
|
1639
|
+
get: function () {
|
|
1640
|
+
return patternMatches;
|
|
1641
|
+
}
|
|
1642
|
+
});
|
|
1643
|
+
Object.defineProperty(exports, 'setOwnProp', {
|
|
1644
|
+
enumerable: true,
|
|
1645
|
+
get: function () {
|
|
1646
|
+
return setOwnProp;
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
Object.defineProperty(exports, 'validateAndNormalizeJsonValue', {
|
|
1650
|
+
enumerable: true,
|
|
1651
|
+
get: function () {
|
|
1652
|
+
return validateAndNormalizeJsonValue;
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
Object.defineProperty(exports, 'validateJsonValue', {
|
|
1656
|
+
enumerable: true,
|
|
1657
|
+
get: function () {
|
|
1658
|
+
return validateJsonValue;
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
Object.defineProperty(exports, 'valuesEqual', {
|
|
1662
|
+
enumerable: true,
|
|
1663
|
+
get: function () {
|
|
1664
|
+
return valuesEqual;
|
|
1665
|
+
}
|
|
1666
|
+
});
|