@meshagent/meshagent 0.13.0 → 0.15.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.
@@ -192,6 +192,14 @@ var appendTo = (dest, src) => {
192
192
  }
193
193
  };
194
194
  var from = Array.from;
195
+ var every = (arr, f) => {
196
+ for (let i = 0; i < arr.length; i++) {
197
+ if (!f(arr[i], i, arr)) {
198
+ return false;
199
+ }
200
+ }
201
+ return true;
202
+ };
195
203
  var some = (arr, f) => {
196
204
  for (let i = 0; i < arr.length; i++) {
197
205
  if (f(arr[i], i, arr)) {
@@ -200,6 +208,13 @@ var some = (arr, f) => {
200
208
  }
201
209
  return false;
202
210
  };
211
+ var unfold = (len, f) => {
212
+ const array = new Array(len);
213
+ for (let i = 0; i < len; i++) {
214
+ array[i] = f(i, array);
215
+ }
216
+ return array;
217
+ };
203
218
  var isArray = Array.isArray;
204
219
 
205
220
  // ../node_modules/lib0/observable.js
@@ -339,7 +354,7 @@ var toLowerCase = (s) => s.toLowerCase();
339
354
  var trimLeftRegex = /^\s*/g;
340
355
  var trimLeft = (s) => s.replace(trimLeftRegex, "");
341
356
  var fromCamelCaseRegex = /([A-Z])/g;
342
- var fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, (match) => `${separator}${toLowerCase(match)}`));
357
+ var fromCamelCase = (s, separator) => trimLeft(s.replace(fromCamelCaseRegex, (match2) => `${separator}${toLowerCase(match2)}`));
343
358
  var _encodeUtf8Polyfill = (str) => {
344
359
  const encodedString = unescape(encodeURIComponent(str));
345
360
  const len = encodedString.length;
@@ -360,6 +375,7 @@ var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecode
360
375
  if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
361
376
  utf8TextDecoder = null;
362
377
  }
378
+ var repeat = (source, n) => unfold(n, () => source).join("");
363
379
 
364
380
  // ../node_modules/lib0/encoding.js
365
381
  var Encoder = class {
@@ -682,7 +698,7 @@ var errorUnexpectedEndOfArray = create3("Unexpected end of array");
682
698
  var errorIntegerOutOfRange = create3("Integer out of Range");
683
699
  var Decoder = class {
684
700
  /**
685
- * @param {Uint8Array} uint8Array Binary data to decode
701
+ * @param {Uint8Array<Buf>} uint8Array Binary data to decode
686
702
  */
687
703
  constructor(uint8Array) {
688
704
  this.arr = uint8Array;
@@ -976,7 +992,12 @@ try {
976
992
  }
977
993
  var varStorage = _localStorage;
978
994
 
995
+ // ../node_modules/lib0/trait/equality.js
996
+ var EqualityTraitSymbol = Symbol("Equality");
997
+ var equals = (a, b) => a === b || a[EqualityTraitSymbol]?.(b) || false;
998
+
979
999
  // ../node_modules/lib0/object.js
1000
+ var isObject = (o) => typeof o === "object";
980
1001
  var assign = Object.assign;
981
1002
  var keys = Object.keys;
982
1003
  var forEach = (obj, f) => {
@@ -991,7 +1012,7 @@ var isEmpty = (obj) => {
991
1012
  }
992
1013
  return true;
993
1014
  };
994
- var every = (obj, f) => {
1015
+ var every2 = (obj, f) => {
995
1016
  for (const key in obj) {
996
1017
  if (!f(obj[key], key)) {
997
1018
  return false;
@@ -1000,7 +1021,7 @@ var every = (obj, f) => {
1000
1021
  return true;
1001
1022
  };
1002
1023
  var hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
1003
- var equalFlat = (a, b) => a === b || size(a) === size(b) && every(a, (val, key) => (val !== void 0 || hasProperty(b, key)) && b[key] === val);
1024
+ var equalFlat = (a, b) => a === b || size(a) === size(b) && every2(a, (val, key) => (val !== void 0 || hasProperty(b, key)) && equals(b[key], val));
1004
1025
  var freeze = Object.freeze;
1005
1026
  var deepFreeze = (o) => {
1006
1027
  for (const key in o) {
@@ -1025,6 +1046,80 @@ var callAll = (fs, args2, i = 0) => {
1025
1046
  }
1026
1047
  };
1027
1048
  var id = (a) => a;
1049
+ var equalityDeep = (a, b) => {
1050
+ if (a === b) {
1051
+ return true;
1052
+ }
1053
+ if (a == null || b == null || a.constructor !== b.constructor && (a.constructor || Object) !== (b.constructor || Object)) {
1054
+ return false;
1055
+ }
1056
+ if (a[EqualityTraitSymbol] != null) {
1057
+ return a[EqualityTraitSymbol](b);
1058
+ }
1059
+ switch (a.constructor) {
1060
+ case ArrayBuffer:
1061
+ a = new Uint8Array(a);
1062
+ b = new Uint8Array(b);
1063
+ // eslint-disable-next-line no-fallthrough
1064
+ case Uint8Array: {
1065
+ if (a.byteLength !== b.byteLength) {
1066
+ return false;
1067
+ }
1068
+ for (let i = 0; i < a.length; i++) {
1069
+ if (a[i] !== b[i]) {
1070
+ return false;
1071
+ }
1072
+ }
1073
+ break;
1074
+ }
1075
+ case Set: {
1076
+ if (a.size !== b.size) {
1077
+ return false;
1078
+ }
1079
+ for (const value of a) {
1080
+ if (!b.has(value)) {
1081
+ return false;
1082
+ }
1083
+ }
1084
+ break;
1085
+ }
1086
+ case Map: {
1087
+ if (a.size !== b.size) {
1088
+ return false;
1089
+ }
1090
+ for (const key of a.keys()) {
1091
+ if (!b.has(key) || !equalityDeep(a.get(key), b.get(key))) {
1092
+ return false;
1093
+ }
1094
+ }
1095
+ break;
1096
+ }
1097
+ case void 0:
1098
+ case Object:
1099
+ if (size(a) !== size(b)) {
1100
+ return false;
1101
+ }
1102
+ for (const key in a) {
1103
+ if (!hasProperty(a, key) || !equalityDeep(a[key], b[key])) {
1104
+ return false;
1105
+ }
1106
+ }
1107
+ break;
1108
+ case Array:
1109
+ if (a.length !== b.length) {
1110
+ return false;
1111
+ }
1112
+ for (let i = 0; i < a.length; i++) {
1113
+ if (!equalityDeep(a[i], b[i])) {
1114
+ return false;
1115
+ }
1116
+ }
1117
+ break;
1118
+ default:
1119
+ return false;
1120
+ }
1121
+ return true;
1122
+ };
1028
1123
  var isOneOf = (value, options) => options.includes(value);
1029
1124
 
1030
1125
  // ../node_modules/lib0/environment.js
@@ -1101,15 +1196,770 @@ var Pair = class {
1101
1196
  };
1102
1197
  var create5 = (left, right) => new Pair(left, right);
1103
1198
 
1199
+ // ../node_modules/lib0/prng.js
1200
+ var bool = (gen) => gen.next() >= 0.5;
1201
+ var int53 = (gen, min2, max2) => floor(gen.next() * (max2 + 1 - min2) + min2);
1202
+ var int32 = (gen, min2, max2) => floor(gen.next() * (max2 + 1 - min2) + min2);
1203
+ var int31 = (gen, min2, max2) => int32(gen, min2, max2);
1204
+ var letter = (gen) => fromCharCode(int31(gen, 97, 122));
1205
+ var word = (gen, minLen = 0, maxLen = 20) => {
1206
+ const len = int31(gen, minLen, maxLen);
1207
+ let str = "";
1208
+ for (let i = 0; i < len; i++) {
1209
+ str += letter(gen);
1210
+ }
1211
+ return str;
1212
+ };
1213
+ var oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)];
1214
+
1215
+ // ../node_modules/lib0/schema.js
1216
+ var schemaSymbol = Symbol("0schema");
1217
+ var ValidationError = class {
1218
+ constructor() {
1219
+ this._rerrs = [];
1220
+ }
1221
+ /**
1222
+ * @param {string?} path
1223
+ * @param {string} expected
1224
+ * @param {string} has
1225
+ * @param {string?} message
1226
+ */
1227
+ extend(path, expected, has, message = null) {
1228
+ this._rerrs.push({ path, expected, has, message });
1229
+ }
1230
+ toString() {
1231
+ const s = [];
1232
+ for (let i = this._rerrs.length - 1; i > 0; i--) {
1233
+ const r = this._rerrs[i];
1234
+ s.push(repeat(" ", (this._rerrs.length - i) * 2) + `${r.path != null ? `[${r.path}] ` : ""}${r.has} doesn't match ${r.expected}. ${r.message}`);
1235
+ }
1236
+ return s.join("\n");
1237
+ }
1238
+ };
1239
+ var shapeExtends = (a, b) => {
1240
+ if (a === b) return true;
1241
+ if (a == null || b == null || a.constructor !== b.constructor) return false;
1242
+ if (a[EqualityTraitSymbol]) return equals(a, b);
1243
+ if (isArray(a)) {
1244
+ return every(
1245
+ a,
1246
+ (aitem) => some(b, (bitem) => shapeExtends(aitem, bitem))
1247
+ );
1248
+ } else if (isObject(a)) {
1249
+ return every2(
1250
+ a,
1251
+ (aitem, akey) => shapeExtends(aitem, b[akey])
1252
+ );
1253
+ }
1254
+ return false;
1255
+ };
1256
+ var Schema = class {
1257
+ // this.shape must not be defined on Schema. Otherwise typecheck on metatypes (e.g. $$object) won't work as expected anymore
1258
+ /**
1259
+ * If true, the more things are added to the shape the more objects this schema will accept (e.g.
1260
+ * union). By default, the more objects are added, the the fewer objects this schema will accept.
1261
+ * @protected
1262
+ */
1263
+ static _dilutes = false;
1264
+ /**
1265
+ * @param {Schema<any>} other
1266
+ */
1267
+ extends(other) {
1268
+ let [a, b] = [
1269
+ /** @type {any} */
1270
+ this.shape,
1271
+ /** @type {any} */
1272
+ other.shape
1273
+ ];
1274
+ if (
1275
+ /** @type {typeof Schema<any>} */
1276
+ this.constructor._dilutes
1277
+ ) [b, a] = [a, b];
1278
+ return shapeExtends(a, b);
1279
+ }
1280
+ /**
1281
+ * Overwrite this when necessary. By default, we only check the `shape` property which every shape
1282
+ * should have.
1283
+ * @param {Schema<any>} other
1284
+ */
1285
+ equals(other) {
1286
+ return this.constructor === other.constructor && equalityDeep(this.shape, other.shape);
1287
+ }
1288
+ [schemaSymbol]() {
1289
+ return true;
1290
+ }
1291
+ /**
1292
+ * @param {object} other
1293
+ */
1294
+ [EqualityTraitSymbol](other) {
1295
+ return this.equals(
1296
+ /** @type {any} */
1297
+ other
1298
+ );
1299
+ }
1300
+ /**
1301
+ * Use `schema.validate(obj)` with a typed parameter that is already of typed to be an instance of
1302
+ * Schema. Validate will check the structure of the parameter and return true iff the instance
1303
+ * really is an instance of Schema.
1304
+ *
1305
+ * @param {T} o
1306
+ * @return {boolean}
1307
+ */
1308
+ validate(o) {
1309
+ return this.check(o);
1310
+ }
1311
+ /* c8 ignore start */
1312
+ /**
1313
+ * Similar to validate, but this method accepts untyped parameters.
1314
+ *
1315
+ * @param {any} _o
1316
+ * @param {ValidationError} [_err]
1317
+ * @return {_o is T}
1318
+ */
1319
+ check(_o, _err) {
1320
+ methodUnimplemented();
1321
+ }
1322
+ /* c8 ignore stop */
1323
+ /**
1324
+ * @type {Schema<T?>}
1325
+ */
1326
+ get nullable() {
1327
+ return $union(this, $null);
1328
+ }
1329
+ /**
1330
+ * @type {$Optional<Schema<T>>}
1331
+ */
1332
+ get optional() {
1333
+ return new $Optional(
1334
+ /** @type {Schema<T>} */
1335
+ this
1336
+ );
1337
+ }
1338
+ /**
1339
+ * Cast a variable to a specific type. Returns the casted value, or throws an exception otherwise.
1340
+ * Use this if you know that the type is of a specific type and you just want to convince the type
1341
+ * system.
1342
+ *
1343
+ * **Do not rely on these error messages!**
1344
+ * Performs an assertion check only if not in a production environment.
1345
+ *
1346
+ * @template OO
1347
+ * @param {OO} o
1348
+ * @return {Extract<OO, T> extends never ? T : (OO extends Array<never> ? T : Extract<OO,T>)}
1349
+ */
1350
+ cast(o) {
1351
+ assert(o, this);
1352
+ return (
1353
+ /** @type {any} */
1354
+ o
1355
+ );
1356
+ }
1357
+ /**
1358
+ * EXPECTO PATRONUM!! 🪄
1359
+ * This function protects against type errors. Though it may not work in the real world.
1360
+ *
1361
+ * "After all this time?"
1362
+ * "Always." - Snape, talking about type safety
1363
+ *
1364
+ * Ensures that a variable is a a specific type. Returns the value, or throws an exception if the assertion check failed.
1365
+ * Use this if you know that the type is of a specific type and you just want to convince the type
1366
+ * system.
1367
+ *
1368
+ * Can be useful when defining lambdas: `s.lambda(s.$number, s.$void).expect((n) => n + 1)`
1369
+ *
1370
+ * **Do not rely on these error messages!**
1371
+ * Performs an assertion check if not in a production environment.
1372
+ *
1373
+ * @param {T} o
1374
+ * @return {o extends T ? T : never}
1375
+ */
1376
+ expect(o) {
1377
+ assert(o, this);
1378
+ return o;
1379
+ }
1380
+ };
1381
+ var $ConstructedBy = class extends Schema {
1382
+ /**
1383
+ * @param {C} c
1384
+ * @param {((o:Instance<C>)=>boolean)|null} check
1385
+ */
1386
+ constructor(c, check) {
1387
+ super();
1388
+ this.shape = c;
1389
+ this._c = check;
1390
+ }
1391
+ /**
1392
+ * @param {any} o
1393
+ * @param {ValidationError} [err]
1394
+ * @return {o is C extends ((...args:any[]) => infer T) ? T : (C extends (new (...args:any[]) => any) ? InstanceType<C> : never)} o
1395
+ */
1396
+ check(o, err = void 0) {
1397
+ const c = o?.constructor === this.shape && (this._c == null || this._c(o));
1398
+ !c && err?.extend(null, this.shape.name, o?.constructor.name, o?.constructor !== this.shape ? "Constructor match failed" : "Check failed");
1399
+ return c;
1400
+ }
1401
+ };
1402
+ var $constructedBy = (c, check = null) => new $ConstructedBy(c, check);
1403
+ var $$constructedBy = $constructedBy($ConstructedBy);
1404
+ var $Custom = class extends Schema {
1405
+ /**
1406
+ * @param {(o:any) => boolean} check
1407
+ */
1408
+ constructor(check) {
1409
+ super();
1410
+ this.shape = check;
1411
+ }
1412
+ /**
1413
+ * @param {any} o
1414
+ * @param {ValidationError} err
1415
+ * @return {o is any}
1416
+ */
1417
+ check(o, err) {
1418
+ const c = this.shape(o);
1419
+ !c && err?.extend(null, "custom prop", o?.constructor.name, "failed to check custom prop");
1420
+ return c;
1421
+ }
1422
+ };
1423
+ var $custom = (check) => new $Custom(check);
1424
+ var $$custom = $constructedBy($Custom);
1425
+ var $Literal = class extends Schema {
1426
+ /**
1427
+ * @param {Array<T>} literals
1428
+ */
1429
+ constructor(literals) {
1430
+ super();
1431
+ this.shape = literals;
1432
+ }
1433
+ /**
1434
+ *
1435
+ * @param {any} o
1436
+ * @param {ValidationError} [err]
1437
+ * @return {o is T}
1438
+ */
1439
+ check(o, err) {
1440
+ const c = this.shape.some((a) => a === o);
1441
+ !c && err?.extend(null, this.shape.join(" | "), o.toString());
1442
+ return c;
1443
+ }
1444
+ };
1445
+ var $literal = (...literals) => new $Literal(literals);
1446
+ var $$literal = $constructedBy($Literal);
1447
+ var _regexEscape = (
1448
+ /** @type {any} */
1449
+ RegExp.escape || /** @type {(str:string) => string} */
1450
+ ((str) => str.replace(/[().|&,$^[\]]/g, (s) => "\\" + s))
1451
+ );
1452
+ var _schemaStringTemplateToRegex = (s) => {
1453
+ if ($string.check(s)) {
1454
+ return [_regexEscape(s)];
1455
+ }
1456
+ if ($$literal.check(s)) {
1457
+ return (
1458
+ /** @type {Array<string|number>} */
1459
+ s.shape.map((v) => v + "")
1460
+ );
1461
+ }
1462
+ if ($$number.check(s)) {
1463
+ return ["[+-]?\\d+.?\\d*"];
1464
+ }
1465
+ if ($$string.check(s)) {
1466
+ return [".*"];
1467
+ }
1468
+ if ($$union.check(s)) {
1469
+ return s.shape.map(_schemaStringTemplateToRegex).flat(1);
1470
+ }
1471
+ unexpectedCase();
1472
+ };
1473
+ var $StringTemplate = class extends Schema {
1474
+ /**
1475
+ * @param {T} shape
1476
+ */
1477
+ constructor(shape) {
1478
+ super();
1479
+ this.shape = shape;
1480
+ this._r = new RegExp("^" + shape.map(_schemaStringTemplateToRegex).map((opts) => `(${opts.join("|")})`).join("") + "$");
1481
+ }
1482
+ /**
1483
+ * @param {any} o
1484
+ * @param {ValidationError} [err]
1485
+ * @return {o is CastStringTemplateArgsToTemplate<T>}
1486
+ */
1487
+ check(o, err) {
1488
+ const c = this._r.exec(o) != null;
1489
+ !c && err?.extend(null, this._r.toString(), o.toString(), "String doesn't match string template.");
1490
+ return c;
1491
+ }
1492
+ };
1493
+ var $$stringTemplate = $constructedBy($StringTemplate);
1494
+ var isOptionalSymbol = Symbol("optional");
1495
+ var $Optional = class extends Schema {
1496
+ /**
1497
+ * @param {S} shape
1498
+ */
1499
+ constructor(shape) {
1500
+ super();
1501
+ this.shape = shape;
1502
+ }
1503
+ /**
1504
+ * @param {any} o
1505
+ * @param {ValidationError} [err]
1506
+ * @return {o is (Unwrap<S>|undefined)}
1507
+ */
1508
+ check(o, err) {
1509
+ const c = o === void 0 || this.shape.check(o);
1510
+ !c && err?.extend(null, "undefined (optional)", "()");
1511
+ return c;
1512
+ }
1513
+ get [isOptionalSymbol]() {
1514
+ return true;
1515
+ }
1516
+ };
1517
+ var $$optional = $constructedBy($Optional);
1518
+ var $Never = class extends Schema {
1519
+ /**
1520
+ * @param {any} _o
1521
+ * @param {ValidationError} [err]
1522
+ * @return {_o is never}
1523
+ */
1524
+ check(_o, err) {
1525
+ err?.extend(null, "never", typeof _o);
1526
+ return false;
1527
+ }
1528
+ };
1529
+ var $never = new $Never();
1530
+ var $$never = $constructedBy($Never);
1531
+ var $Object = class _$Object extends Schema {
1532
+ /**
1533
+ * @param {S} shape
1534
+ * @param {boolean} partial
1535
+ */
1536
+ constructor(shape, partial = false) {
1537
+ super();
1538
+ this.shape = shape;
1539
+ this._isPartial = partial;
1540
+ }
1541
+ static _dilutes = true;
1542
+ /**
1543
+ * @type {Schema<Partial<$ObjectToType<S>>>}
1544
+ */
1545
+ get partial() {
1546
+ return new _$Object(this.shape, true);
1547
+ }
1548
+ /**
1549
+ * @param {any} o
1550
+ * @param {ValidationError} err
1551
+ * @return {o is $ObjectToType<S>}
1552
+ */
1553
+ check(o, err) {
1554
+ if (o == null) {
1555
+ err?.extend(null, "object", "null");
1556
+ return false;
1557
+ }
1558
+ return every2(this.shape, (vv, vk) => {
1559
+ const c = this._isPartial && !hasProperty(o, vk) || vv.check(o[vk], err);
1560
+ !c && err?.extend(vk.toString(), vv.toString(), typeof o[vk], "Object property does not match");
1561
+ return c;
1562
+ });
1563
+ }
1564
+ };
1565
+ var $object = (def) => (
1566
+ /** @type {any} */
1567
+ new $Object(def)
1568
+ );
1569
+ var $$object = $constructedBy($Object);
1570
+ var $objectAny = $custom((o) => o != null && (o.constructor === Object || o.constructor == null));
1571
+ var $Record = class extends Schema {
1572
+ /**
1573
+ * @param {Keys} keys
1574
+ * @param {Values} values
1575
+ */
1576
+ constructor(keys2, values) {
1577
+ super();
1578
+ this.shape = {
1579
+ keys: keys2,
1580
+ values
1581
+ };
1582
+ }
1583
+ /**
1584
+ * @param {any} o
1585
+ * @param {ValidationError} err
1586
+ * @return {o is { [key in Unwrap<Keys>]: Unwrap<Values> }}
1587
+ */
1588
+ check(o, err) {
1589
+ return o != null && every2(o, (vv, vk) => {
1590
+ const ck = this.shape.keys.check(vk, err);
1591
+ !ck && err?.extend(vk + "", "Record", typeof o, ck ? "Key doesn't match schema" : "Value doesn't match value");
1592
+ return ck && this.shape.values.check(vv, err);
1593
+ });
1594
+ }
1595
+ };
1596
+ var $record = (keys2, values) => new $Record(keys2, values);
1597
+ var $$record = $constructedBy($Record);
1598
+ var $Tuple = class extends Schema {
1599
+ /**
1600
+ * @param {S} shape
1601
+ */
1602
+ constructor(shape) {
1603
+ super();
1604
+ this.shape = shape;
1605
+ }
1606
+ /**
1607
+ * @param {any} o
1608
+ * @param {ValidationError} err
1609
+ * @return {o is { [K in keyof S]: S[K] extends Schema<infer Type> ? Type : never }}
1610
+ */
1611
+ check(o, err) {
1612
+ return o != null && every2(this.shape, (vv, vk) => {
1613
+ const c = (
1614
+ /** @type {Schema<any>} */
1615
+ vv.check(o[vk], err)
1616
+ );
1617
+ !c && err?.extend(vk.toString(), "Tuple", typeof vv);
1618
+ return c;
1619
+ });
1620
+ }
1621
+ };
1622
+ var $tuple = (...def) => new $Tuple(def);
1623
+ var $$tuple = $constructedBy($Tuple);
1624
+ var $Array = class extends Schema {
1625
+ /**
1626
+ * @param {Array<S>} v
1627
+ */
1628
+ constructor(v) {
1629
+ super();
1630
+ this.shape = v.length === 1 ? v[0] : new $Union(v);
1631
+ }
1632
+ /**
1633
+ * @param {any} o
1634
+ * @param {ValidationError} [err]
1635
+ * @return {o is Array<S extends Schema<infer T> ? T : never>} o
1636
+ */
1637
+ check(o, err) {
1638
+ const c = isArray(o) && every(o, (oi) => this.shape.check(oi));
1639
+ !c && err?.extend(null, "Array", "");
1640
+ return c;
1641
+ }
1642
+ };
1643
+ var $array = (...def) => new $Array(def);
1644
+ var $$array = $constructedBy($Array);
1645
+ var $arrayAny = $custom((o) => isArray(o));
1646
+ var $InstanceOf = class extends Schema {
1647
+ /**
1648
+ * @param {new (...args:any) => T} constructor
1649
+ * @param {((o:T) => boolean)|null} check
1650
+ */
1651
+ constructor(constructor, check) {
1652
+ super();
1653
+ this.shape = constructor;
1654
+ this._c = check;
1655
+ }
1656
+ /**
1657
+ * @param {any} o
1658
+ * @param {ValidationError} err
1659
+ * @return {o is T}
1660
+ */
1661
+ check(o, err) {
1662
+ const c = o instanceof this.shape && (this._c == null || this._c(o));
1663
+ !c && err?.extend(null, this.shape.name, o?.constructor.name);
1664
+ return c;
1665
+ }
1666
+ };
1667
+ var $instanceOf = (c, check = null) => new $InstanceOf(c, check);
1668
+ var $$instanceOf = $constructedBy($InstanceOf);
1669
+ var $$schema = $instanceOf(Schema);
1670
+ var $Lambda = class extends Schema {
1671
+ /**
1672
+ * @param {Args} args
1673
+ */
1674
+ constructor(args2) {
1675
+ super();
1676
+ this.len = args2.length - 1;
1677
+ this.args = $tuple(...args2.slice(-1));
1678
+ this.res = args2[this.len];
1679
+ }
1680
+ /**
1681
+ * @param {any} f
1682
+ * @param {ValidationError} err
1683
+ * @return {f is _LArgsToLambdaDef<Args>}
1684
+ */
1685
+ check(f, err) {
1686
+ const c = f.constructor === Function && f.length <= this.len;
1687
+ !c && err?.extend(null, "function", typeof f);
1688
+ return c;
1689
+ }
1690
+ };
1691
+ var $$lambda = $constructedBy($Lambda);
1692
+ var $function = $custom((o) => typeof o === "function");
1693
+ var $Intersection = class extends Schema {
1694
+ /**
1695
+ * @param {T} v
1696
+ */
1697
+ constructor(v) {
1698
+ super();
1699
+ this.shape = v;
1700
+ }
1701
+ /**
1702
+ * @param {any} o
1703
+ * @param {ValidationError} [err]
1704
+ * @return {o is Intersect<UnwrapArray<T>>}
1705
+ */
1706
+ check(o, err) {
1707
+ const c = every(this.shape, (check) => check.check(o, err));
1708
+ !c && err?.extend(null, "Intersectinon", typeof o);
1709
+ return c;
1710
+ }
1711
+ };
1712
+ var $$intersect = $constructedBy($Intersection, (o) => o.shape.length > 0);
1713
+ var $Union = class extends Schema {
1714
+ static _dilutes = true;
1715
+ /**
1716
+ * @param {Array<Schema<S>>} v
1717
+ */
1718
+ constructor(v) {
1719
+ super();
1720
+ this.shape = v;
1721
+ }
1722
+ /**
1723
+ * @param {any} o
1724
+ * @param {ValidationError} [err]
1725
+ * @return {o is S}
1726
+ */
1727
+ check(o, err) {
1728
+ const c = some(this.shape, (vv) => vv.check(o, err));
1729
+ err?.extend(null, "Union", typeof o);
1730
+ return c;
1731
+ }
1732
+ };
1733
+ var $union = (...schemas) => schemas.findIndex(($s) => $$union.check($s)) >= 0 ? $union(...schemas.map(($s) => $($s)).map(($s) => $$union.check($s) ? $s.shape : [$s]).flat(1)) : schemas.length === 1 ? schemas[0] : new $Union(schemas);
1734
+ var $$union = (
1735
+ /** @type {Schema<$Union<any>>} */
1736
+ $constructedBy($Union)
1737
+ );
1738
+ var _t = () => true;
1739
+ var $any = $custom(_t);
1740
+ var $$any = (
1741
+ /** @type {Schema<Schema<any>>} */
1742
+ $constructedBy($Custom, (o) => o.shape === _t)
1743
+ );
1744
+ var $bigint = $custom((o) => typeof o === "bigint");
1745
+ var $$bigint = (
1746
+ /** @type {Schema<Schema<BigInt>>} */
1747
+ $custom((o) => o === $bigint)
1748
+ );
1749
+ var $symbol = $custom((o) => typeof o === "symbol");
1750
+ var $$symbol = (
1751
+ /** @type {Schema<Schema<Symbol>>} */
1752
+ $custom((o) => o === $symbol)
1753
+ );
1754
+ var $number = $custom((o) => typeof o === "number");
1755
+ var $$number = (
1756
+ /** @type {Schema<Schema<number>>} */
1757
+ $custom((o) => o === $number)
1758
+ );
1759
+ var $string = $custom((o) => typeof o === "string");
1760
+ var $$string = (
1761
+ /** @type {Schema<Schema<string>>} */
1762
+ $custom((o) => o === $string)
1763
+ );
1764
+ var $boolean = $custom((o) => typeof o === "boolean");
1765
+ var $$boolean = (
1766
+ /** @type {Schema<Schema<Boolean>>} */
1767
+ $custom((o) => o === $boolean)
1768
+ );
1769
+ var $undefined = $literal(void 0);
1770
+ var $$undefined = (
1771
+ /** @type {Schema<Schema<undefined>>} */
1772
+ $constructedBy($Literal, (o) => o.shape.length === 1 && o.shape[0] === void 0)
1773
+ );
1774
+ var $void = $literal(void 0);
1775
+ var $null = $literal(null);
1776
+ var $$null = (
1777
+ /** @type {Schema<Schema<null>>} */
1778
+ $constructedBy($Literal, (o) => o.shape.length === 1 && o.shape[0] === null)
1779
+ );
1780
+ var $uint8Array = $constructedBy(Uint8Array);
1781
+ var $$uint8Array = (
1782
+ /** @type {Schema<Schema<Uint8Array>>} */
1783
+ $constructedBy($ConstructedBy, (o) => o.shape === Uint8Array)
1784
+ );
1785
+ var $primitive = $union($number, $string, $null, $undefined, $bigint, $boolean, $symbol);
1786
+ var $json = (() => {
1787
+ const $jsonArr = (
1788
+ /** @type {$Array<$any>} */
1789
+ $array($any)
1790
+ );
1791
+ const $jsonRecord = (
1792
+ /** @type {$Record<$string,$any>} */
1793
+ $record($string, $any)
1794
+ );
1795
+ const $json2 = $union($number, $string, $null, $boolean, $jsonArr, $jsonRecord);
1796
+ $jsonArr.shape = $json2;
1797
+ $jsonRecord.shape.values = $json2;
1798
+ return $json2;
1799
+ })();
1800
+ var $ = (o) => {
1801
+ if ($$schema.check(o)) {
1802
+ return (
1803
+ /** @type {any} */
1804
+ o
1805
+ );
1806
+ } else if ($objectAny.check(o)) {
1807
+ const o2 = {};
1808
+ for (const k in o) {
1809
+ o2[k] = $(o[k]);
1810
+ }
1811
+ return (
1812
+ /** @type {any} */
1813
+ $object(o2)
1814
+ );
1815
+ } else if ($arrayAny.check(o)) {
1816
+ return (
1817
+ /** @type {any} */
1818
+ $union(...o.map($))
1819
+ );
1820
+ } else if ($primitive.check(o)) {
1821
+ return (
1822
+ /** @type {any} */
1823
+ $literal(o)
1824
+ );
1825
+ } else if ($function.check(o)) {
1826
+ return (
1827
+ /** @type {any} */
1828
+ $constructedBy(
1829
+ /** @type {any} */
1830
+ o
1831
+ )
1832
+ );
1833
+ }
1834
+ unexpectedCase();
1835
+ };
1836
+ var assert = production ? () => {
1837
+ } : (o, schema) => {
1838
+ const err = new ValidationError();
1839
+ if (!schema.check(o, err)) {
1840
+ throw create3(`Expected value to be of type ${schema.constructor.name}.
1841
+ ${err.toString()}`);
1842
+ }
1843
+ };
1844
+ var PatternMatcher = class {
1845
+ /**
1846
+ * @param {Schema<State>} [$state]
1847
+ */
1848
+ constructor($state) {
1849
+ this.patterns = [];
1850
+ this.$state = $state;
1851
+ }
1852
+ /**
1853
+ * @template P
1854
+ * @template R
1855
+ * @param {P} pattern
1856
+ * @param {(o:NoInfer<Unwrap<ReadSchema<P>>>,s:State)=>R} handler
1857
+ * @return {PatternMatcher<State,Patterns|Pattern<Unwrap<ReadSchema<P>>,R>>}
1858
+ */
1859
+ if(pattern, handler) {
1860
+ this.patterns.push({ if: $(pattern), h: handler });
1861
+ return this;
1862
+ }
1863
+ /**
1864
+ * @template R
1865
+ * @param {(o:any,s:State)=>R} h
1866
+ */
1867
+ else(h) {
1868
+ return this.if($any, h);
1869
+ }
1870
+ /**
1871
+ * @return {State extends undefined
1872
+ * ? <In extends Unwrap<Patterns['if']>>(o:In,state?:undefined)=>PatternMatchResult<Patterns,In>
1873
+ * : <In extends Unwrap<Patterns['if']>>(o:In,state:State)=>PatternMatchResult<Patterns,In>}
1874
+ */
1875
+ done() {
1876
+ return (
1877
+ /** @type {any} */
1878
+ (o, s) => {
1879
+ for (let i = 0; i < this.patterns.length; i++) {
1880
+ const p = this.patterns[i];
1881
+ if (p.if.check(o)) {
1882
+ return p.h(o, s);
1883
+ }
1884
+ }
1885
+ throw create3("Unhandled pattern");
1886
+ }
1887
+ );
1888
+ }
1889
+ };
1890
+ var match = (state) => new PatternMatcher(
1891
+ /** @type {any} */
1892
+ state
1893
+ );
1894
+ var _random = (
1895
+ /** @type {any} */
1896
+ match(
1897
+ /** @type {Schema<prng.PRNG>} */
1898
+ $any
1899
+ ).if($$number, (_o, gen) => int53(gen, MIN_SAFE_INTEGER, MAX_SAFE_INTEGER)).if($$string, (_o, gen) => word(gen)).if($$boolean, (_o, gen) => bool(gen)).if($$bigint, (_o, gen) => BigInt(int53(gen, MIN_SAFE_INTEGER, MAX_SAFE_INTEGER))).if($$union, (o, gen) => random(gen, oneOf(gen, o.shape))).if($$object, (o, gen) => {
1900
+ const res = {};
1901
+ for (const k in o.shape) {
1902
+ let prop = o.shape[k];
1903
+ if ($$optional.check(prop)) {
1904
+ if (bool(gen)) {
1905
+ continue;
1906
+ }
1907
+ prop = prop.shape;
1908
+ }
1909
+ res[k] = _random(prop, gen);
1910
+ }
1911
+ return res;
1912
+ }).if($$array, (o, gen) => {
1913
+ const arr = [];
1914
+ const n = int32(gen, 0, 42);
1915
+ for (let i = 0; i < n; i++) {
1916
+ arr.push(random(gen, o.shape));
1917
+ }
1918
+ return arr;
1919
+ }).if($$literal, (o, gen) => {
1920
+ return oneOf(gen, o.shape);
1921
+ }).if($$null, (o, gen) => {
1922
+ return null;
1923
+ }).if($$lambda, (o, gen) => {
1924
+ const res = random(gen, o.res);
1925
+ return () => res;
1926
+ }).if($$any, (o, gen) => random(gen, oneOf(gen, [
1927
+ $number,
1928
+ $string,
1929
+ $null,
1930
+ $undefined,
1931
+ $bigint,
1932
+ $boolean,
1933
+ $array($number),
1934
+ $record($union("a", "b", "c"), $number)
1935
+ ]))).if($$record, (o, gen) => {
1936
+ const res = {};
1937
+ const keysN = int53(gen, 0, 3);
1938
+ for (let i = 0; i < keysN; i++) {
1939
+ const key = random(gen, o.shape.keys);
1940
+ const val = random(gen, o.shape.values);
1941
+ res[key] = val;
1942
+ }
1943
+ return res;
1944
+ }).done()
1945
+ );
1946
+ var random = (gen, schema) => (
1947
+ /** @type {any} */
1948
+ _random($(schema), gen)
1949
+ );
1950
+
1104
1951
  // ../node_modules/lib0/dom.js
1105
1952
  var doc = (
1106
1953
  /** @type {Document} */
1107
1954
  typeof document !== "undefined" ? document : {}
1108
1955
  );
1956
+ var $fragment = $custom((el) => el.nodeType === DOCUMENT_FRAGMENT_NODE);
1109
1957
  var domParser = (
1110
1958
  /** @type {DOMParser} */
1111
1959
  typeof DOMParser !== "undefined" ? new DOMParser() : null
1112
1960
  );
1961
+ var $element = $custom((el) => el.nodeType === ELEMENT_NODE);
1962
+ var $text = $custom((el) => el.nodeType === TEXT_NODE);
1113
1963
  var mapToStyleString = (m) => map(m, (value, key) => `${key}:${value};`).join("");
1114
1964
  var ELEMENT_NODE = doc.ELEMENT_NODE;
1115
1965
  var TEXT_NODE = doc.TEXT_NODE;
@@ -1118,6 +1968,7 @@ var COMMENT_NODE = doc.COMMENT_NODE;
1118
1968
  var DOCUMENT_NODE = doc.DOCUMENT_NODE;
1119
1969
  var DOCUMENT_TYPE_NODE = doc.DOCUMENT_TYPE_NODE;
1120
1970
  var DOCUMENT_FRAGMENT_NODE = doc.DOCUMENT_FRAGMENT_NODE;
1971
+ var $node = $custom((el) => el.nodeType === DOCUMENT_NODE);
1121
1972
 
1122
1973
  // ../node_modules/lib0/symbol.js
1123
1974
  var create6 = Symbol;
@@ -3580,7 +4431,7 @@ var YEvent = class {
3580
4431
  return isDeleted(this.transaction.deleteSet, struct.id);
3581
4432
  }
3582
4433
  /**
3583
- * @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any, newValue: any }>}
4434
+ * @type {Map<string, { action: 'add' | 'update' | 'delete', oldValue: any }>}
3584
4435
  */
3585
4436
  get keys() {
3586
4437
  if (this._keys === null) {
@@ -6266,11 +7117,13 @@ var YXmlElement = class _YXmlElement extends YXmlFragment {
6266
7117
  const el = new _YXmlElement(this.nodeName);
6267
7118
  const attrs = this.getAttributes();
6268
7119
  forEach(attrs, (value, key) => {
6269
- if (typeof value === "string") {
6270
- el.setAttribute(key, value);
6271
- }
7120
+ el.setAttribute(
7121
+ key,
7122
+ /** @type {any} */
7123
+ value
7124
+ );
6272
7125
  });
6273
- el.insert(0, this.toArray().map((item) => item instanceof AbstractType ? item.clone() : item));
7126
+ el.insert(0, this.toArray().map((v) => v instanceof AbstractType ? v.clone() : v));
6274
7127
  return el;
6275
7128
  }
6276
7129
  /**