@dxos/util 0.4.7-main.33db07e → 0.4.7-main.340e96b

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.
@@ -325,6 +325,185 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
325
325
  // packages/common/util/src/defer-function.ts
326
326
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
327
327
 
328
+ // packages/common/util/src/to-fallback.ts
329
+ var idEmoji = [
330
+ // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
331
+ // Emoji sometimes use a combination of code points, and some code points aren't visible on their own, so by adding or deleting you may unintentionally create non-visible items.
332
+ // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
333
+ // – not people or isolated anthropomorphic faces
334
+ // – not flags
335
+ // – more concrete than abstract
336
+ // – less culturally specific
337
+ // – less easily confused with another emoji in the set
338
+ // – requires less special knowledge to identify
339
+ // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
340
+ // – less common as a signifier in UX
341
+ // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
342
+ "\u{1F479}",
343
+ "\u{1F47B}",
344
+ "\u{1F47D}",
345
+ "\u{1F916}",
346
+ "\u{1F383}",
347
+ "\u{1F9BE}",
348
+ "\u{1F9BF}",
349
+ "\u{1F9B7}",
350
+ "\u{1F463}",
351
+ "\u{1F441}\uFE0F",
352
+ "\u{1F9F6}",
353
+ "\u{1F451}",
354
+ "\u{1F412}",
355
+ "\u{1F986}",
356
+ "\u{1F989}",
357
+ "\u{1F434}",
358
+ "\u{1F984}",
359
+ "\u{1F41D}",
360
+ "\u{1F98B}",
361
+ "\u{1F41E}",
362
+ "\u{1FAB2}",
363
+ "\u{1F422}",
364
+ "\u{1F98E}",
365
+ "\u{1F995}",
366
+ "\u{1F991}",
367
+ "\u{1F980}",
368
+ "\u{1F420}",
369
+ "\u{1F42C}",
370
+ "\u{1F40B}",
371
+ "\u{1F9AD}",
372
+ "\u{1F405}",
373
+ "\u{1F406}",
374
+ "\u{1F993}",
375
+ "\u{1F98D}",
376
+ "\u{1F9A7}",
377
+ "\u{1F418}",
378
+ "\u{1F42B}",
379
+ "\u{1F992}",
380
+ "\u{1F998}",
381
+ "\u{1F9AC}",
382
+ "\u{1F416}",
383
+ "\u{1F40F}",
384
+ "\u{1F98C}",
385
+ "\u{1F415}",
386
+ "\u{1F408}",
387
+ "\u{1F413}",
388
+ "\u{1F99A}",
389
+ "\u{1F99C}",
390
+ "\u{1F9A2}",
391
+ "\u{1F9A9}",
392
+ "\u{1F9A6}",
393
+ "\u{1F401}",
394
+ "\u{1F43F}\uFE0F",
395
+ "\u{1F335}",
396
+ "\u{1F332}",
397
+ "\u{1F333}",
398
+ "\u{1FAB5}",
399
+ "\u{1F331}",
400
+ "\u{1F341}",
401
+ "\u{1FABA}",
402
+ "\u{1F344}",
403
+ "\u{1F41A}",
404
+ "\u{1FAB8}",
405
+ "\u{1FAA8}",
406
+ "\u{1F33E}",
407
+ "\u{1F337}",
408
+ "\u{1F33B}",
409
+ "\u2600\uFE0F",
410
+ "\u{1F319}",
411
+ "\u{1FA90}",
412
+ "\u2B50\uFE0F",
413
+ "\u26A1\uFE0F",
414
+ "\u2604\uFE0F",
415
+ "\u{1F525}",
416
+ "\u{1F308}",
417
+ "\u2601\uFE0F",
418
+ "\u{1F4A7}",
419
+ "\u26F1\uFE0F",
420
+ "\u{1F30A}",
421
+ "\u{1F34E}",
422
+ "\u{1F34B}",
423
+ "\u{1F349}",
424
+ "\u{1F347}",
425
+ "\u{1FAD0}",
426
+ "\u{1F348}",
427
+ "\u{1F352}",
428
+ "\u{1F351}",
429
+ "\u{1F96D}",
430
+ "\u{1F34D}",
431
+ "\u{1F965}",
432
+ "\u{1F95D}",
433
+ "\u{1F951}",
434
+ "\u{1F336}\uFE0F",
435
+ "\u{1F33D}",
436
+ "\u{1F955}",
437
+ "\u{1F36C}",
438
+ "\u{1F95C}",
439
+ "\u{1FAD6}",
440
+ "\u2615\uFE0F",
441
+ "\u{1F375}",
442
+ "\u{1F9CA}",
443
+ "\u{1F9C2}",
444
+ "\u{1F3D4}\uFE0F",
445
+ "\u2693\uFE0F",
446
+ "\u{1F6DF}",
447
+ "\u{1F3DD}\uFE0F",
448
+ "\u{1F6F6}",
449
+ "\u{1F680}",
450
+ "\u{1F6F0}\uFE0F",
451
+ "\u26F2\uFE0F",
452
+ "\u{1F3F0}",
453
+ "\u{1F6B2}",
454
+ "\u26FA\uFE0F",
455
+ "\u{1F399}\uFE0F",
456
+ "\u{1F9F2}",
457
+ "\u2699\uFE0F",
458
+ "\u{1F529}",
459
+ "\u{1F52E}",
460
+ "\u{1F52D}",
461
+ "\u{1F52C}",
462
+ "\u{1F9EC}",
463
+ "\u{1F321}\uFE0F",
464
+ "\u{1F9FA}",
465
+ "\u{1F6CE}\uFE0F",
466
+ "\u{1F511}",
467
+ "\u{1FA91}",
468
+ "\u{1F9F8}",
469
+ "\u{1F388}",
470
+ "\u{1F380}",
471
+ "\u{1F38A}",
472
+ "\u267B\uFE0F",
473
+ "\u{1F3B5}"
474
+ ];
475
+ var idHue = [
476
+ "red",
477
+ // 'orange' as const, /* More shades in these palettes are considered “ugly” */
478
+ "amber",
479
+ // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
480
+ "lime",
481
+ "green",
482
+ "emerald",
483
+ "teal",
484
+ "cyan",
485
+ // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
486
+ // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
487
+ // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
488
+ "violet",
489
+ "purple",
490
+ "fuchsia",
491
+ "pink",
492
+ "rose"
493
+ ];
494
+ var keyToEmoji = (key) => hexToEmoji(key.toHex());
495
+ var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
496
+ var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
497
+ var keyToHue = (key) => hexToHue(key.toHex());
498
+ var hexToHue = (hex) => toHue(parseInt(hex, 16));
499
+ var toHue = (hash) => idHue[hash % idHue.length];
500
+ var keyToFallback = (key) => hexToFallback(key.toHex());
501
+ var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
502
+ var toFallback = (hash) => ({
503
+ emoji: toEmoji(hash),
504
+ hue: toHue(hash)
505
+ });
506
+
328
507
  // packages/common/util/src/entry.ts
329
508
  var entry = (map, key) => new MapEntry(map, key);
330
509
  var MapEntry = class {
@@ -1118,7 +1297,7 @@ var getPrototypeSpecificInstanceId = (instance) => {
1118
1297
  return id;
1119
1298
  };
1120
1299
  var getDebugName = (instance) => {
1121
- if (instance === null) {
1300
+ if (instance == null) {
1122
1301
  return "null";
1123
1302
  }
1124
1303
  const prototype = Object.getPrototypeOf(instance);
@@ -1267,9 +1446,64 @@ var DeferAsyncGuard = class {
1267
1446
  await this._fn();
1268
1447
  }
1269
1448
  };
1449
+
1450
+ // packages/common/util/src/circular-buffer.ts
1451
+ import { invariant as invariant4 } from "@dxos/invariant";
1452
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
1453
+ var CircularBuffer = class {
1454
+ constructor(size) {
1455
+ this._nextIndex = 0;
1456
+ this._elementCount = 0;
1457
+ invariant4(size >= 1, void 0, {
1458
+ F: __dxlog_file4,
1459
+ L: 13,
1460
+ S: this,
1461
+ A: [
1462
+ "size >= 1",
1463
+ ""
1464
+ ]
1465
+ });
1466
+ this._buffer = new Array(size);
1467
+ }
1468
+ push(element) {
1469
+ this._buffer[this._nextIndex] = element;
1470
+ this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
1471
+ this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
1472
+ }
1473
+ getLast() {
1474
+ if (this._elementCount === 0) {
1475
+ return void 0;
1476
+ }
1477
+ if (this._nextIndex === 0) {
1478
+ return this._buffer[this._buffer.length - 1];
1479
+ }
1480
+ return this._buffer[this._nextIndex - 1];
1481
+ }
1482
+ [Symbol.iterator]() {
1483
+ return this.values();
1484
+ }
1485
+ *values() {
1486
+ if (this._elementCount === 0) {
1487
+ return;
1488
+ }
1489
+ if (this._elementCount < this._buffer.length) {
1490
+ for (let i = 0; i < this._elementCount; i++) {
1491
+ yield this._buffer[i];
1492
+ }
1493
+ return;
1494
+ }
1495
+ for (let i = this._nextIndex; i < this._buffer.length; i++) {
1496
+ yield this._buffer[i];
1497
+ }
1498
+ for (let i = 0; i < this._nextIndex; i++) {
1499
+ yield this._buffer[i];
1500
+ }
1501
+ }
1502
+ };
1270
1503
  export {
1271
1504
  BitField,
1272
1505
  Callback,
1506
+ CircularBuffer,
1273
1507
  ComplexMap,
1274
1508
  ComplexSet,
1275
1509
  HumanHasher,
@@ -1305,7 +1539,12 @@ export {
1305
1539
  getDeep,
1306
1540
  getHostPlatform,
1307
1541
  getPrototypeSpecificInstanceId,
1542
+ hexToEmoji,
1543
+ hexToFallback,
1544
+ hexToHue,
1308
1545
  humanize,
1546
+ idEmoji,
1547
+ idHue,
1309
1548
  inferObjectOrder,
1310
1549
  inferRecordOrder,
1311
1550
  iosCheck,
@@ -1315,6 +1554,9 @@ export {
1315
1554
  jsonKeyReplacer,
1316
1555
  jsonReplacer,
1317
1556
  jsonify,
1557
+ keyToEmoji,
1558
+ keyToFallback,
1559
+ keyToHue,
1318
1560
  makeMap,
1319
1561
  makeSet,
1320
1562
  mapValues,
@@ -1335,6 +1577,9 @@ export {
1335
1577
  stringToArray,
1336
1578
  stripUndefinedValues,
1337
1579
  sum,
1580
+ toEmoji,
1581
+ toFallback,
1582
+ toHue,
1338
1583
  tracer
1339
1584
  };
1340
1585
  //# sourceMappingURL=index.mjs.map