@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.
@@ -30,6 +30,7 @@ var node_exports = {};
30
30
  __export(node_exports, {
31
31
  BitField: () => BitField,
32
32
  Callback: () => Callback,
33
+ CircularBuffer: () => CircularBuffer,
33
34
  ComplexMap: () => ComplexMap,
34
35
  ComplexSet: () => ComplexSet,
35
36
  HumanHasher: () => HumanHasher,
@@ -65,7 +66,12 @@ __export(node_exports, {
65
66
  getDeep: () => getDeep,
66
67
  getHostPlatform: () => getHostPlatform,
67
68
  getPrototypeSpecificInstanceId: () => getPrototypeSpecificInstanceId,
69
+ hexToEmoji: () => hexToEmoji,
70
+ hexToFallback: () => hexToFallback,
71
+ hexToHue: () => hexToHue,
68
72
  humanize: () => humanize,
73
+ idEmoji: () => idEmoji,
74
+ idHue: () => idHue,
69
75
  inferObjectOrder: () => inferObjectOrder,
70
76
  inferRecordOrder: () => inferRecordOrder,
71
77
  iosCheck: () => iosCheck,
@@ -75,6 +81,9 @@ __export(node_exports, {
75
81
  jsonKeyReplacer: () => jsonKeyReplacer,
76
82
  jsonReplacer: () => jsonReplacer,
77
83
  jsonify: () => jsonify,
84
+ keyToEmoji: () => keyToEmoji,
85
+ keyToFallback: () => keyToFallback,
86
+ keyToHue: () => keyToHue,
78
87
  makeMap: () => makeMap,
79
88
  makeSet: () => makeSet,
80
89
  mapValues: () => mapValues,
@@ -95,6 +104,9 @@ __export(node_exports, {
95
104
  stringToArray: () => stringToArray,
96
105
  stripUndefinedValues: () => stripUndefinedValues,
97
106
  sum: () => sum,
107
+ toEmoji: () => toEmoji,
108
+ toFallback: () => toFallback,
109
+ toHue: () => toHue,
98
110
  tracer: () => tracer
99
111
  });
100
112
  module.exports = __toCommonJS(node_exports);
@@ -107,6 +119,7 @@ var import_debug = require("@dxos/debug");
107
119
  var import_keys = require("@dxos/keys");
108
120
  var import_node_util3 = require("node:util");
109
121
  var import_keys2 = require("@dxos/keys");
122
+ var import_invariant4 = require("@dxos/invariant");
110
123
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/util/src/assign.ts";
111
124
  var assignDeep = (doc, path, value) => {
112
125
  (0, import_invariant.invariant)(path.length > 0, void 0, {
@@ -407,6 +420,183 @@ var makeMap = (keyProjection) => class BoundComplexMap extends ComplexMap {
407
420
  }
408
421
  };
409
422
  var deferFunction = (fnProvider) => (...args) => fnProvider()(...args);
423
+ var idEmoji = [
424
+ // When changing this set, please check the result in a console or e.g. RunKit (https://runkit.com/thure/642214441dd6ae000855a8de)
425
+ // 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.
426
+ // This set was chosen from the characters in Unicode Emoji v15.0 based on the following criteria:
427
+ // – not people or isolated anthropomorphic faces
428
+ // – not flags
429
+ // – more concrete than abstract
430
+ // – less culturally specific
431
+ // – less easily confused with another emoji in the set
432
+ // – requires less special knowledge to identify
433
+ // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
434
+ // – less common as a signifier in UX
435
+ // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
436
+ "\u{1F479}",
437
+ "\u{1F47B}",
438
+ "\u{1F47D}",
439
+ "\u{1F916}",
440
+ "\u{1F383}",
441
+ "\u{1F9BE}",
442
+ "\u{1F9BF}",
443
+ "\u{1F9B7}",
444
+ "\u{1F463}",
445
+ "\u{1F441}\uFE0F",
446
+ "\u{1F9F6}",
447
+ "\u{1F451}",
448
+ "\u{1F412}",
449
+ "\u{1F986}",
450
+ "\u{1F989}",
451
+ "\u{1F434}",
452
+ "\u{1F984}",
453
+ "\u{1F41D}",
454
+ "\u{1F98B}",
455
+ "\u{1F41E}",
456
+ "\u{1FAB2}",
457
+ "\u{1F422}",
458
+ "\u{1F98E}",
459
+ "\u{1F995}",
460
+ "\u{1F991}",
461
+ "\u{1F980}",
462
+ "\u{1F420}",
463
+ "\u{1F42C}",
464
+ "\u{1F40B}",
465
+ "\u{1F9AD}",
466
+ "\u{1F405}",
467
+ "\u{1F406}",
468
+ "\u{1F993}",
469
+ "\u{1F98D}",
470
+ "\u{1F9A7}",
471
+ "\u{1F418}",
472
+ "\u{1F42B}",
473
+ "\u{1F992}",
474
+ "\u{1F998}",
475
+ "\u{1F9AC}",
476
+ "\u{1F416}",
477
+ "\u{1F40F}",
478
+ "\u{1F98C}",
479
+ "\u{1F415}",
480
+ "\u{1F408}",
481
+ "\u{1F413}",
482
+ "\u{1F99A}",
483
+ "\u{1F99C}",
484
+ "\u{1F9A2}",
485
+ "\u{1F9A9}",
486
+ "\u{1F9A6}",
487
+ "\u{1F401}",
488
+ "\u{1F43F}\uFE0F",
489
+ "\u{1F335}",
490
+ "\u{1F332}",
491
+ "\u{1F333}",
492
+ "\u{1FAB5}",
493
+ "\u{1F331}",
494
+ "\u{1F341}",
495
+ "\u{1FABA}",
496
+ "\u{1F344}",
497
+ "\u{1F41A}",
498
+ "\u{1FAB8}",
499
+ "\u{1FAA8}",
500
+ "\u{1F33E}",
501
+ "\u{1F337}",
502
+ "\u{1F33B}",
503
+ "\u2600\uFE0F",
504
+ "\u{1F319}",
505
+ "\u{1FA90}",
506
+ "\u2B50\uFE0F",
507
+ "\u26A1\uFE0F",
508
+ "\u2604\uFE0F",
509
+ "\u{1F525}",
510
+ "\u{1F308}",
511
+ "\u2601\uFE0F",
512
+ "\u{1F4A7}",
513
+ "\u26F1\uFE0F",
514
+ "\u{1F30A}",
515
+ "\u{1F34E}",
516
+ "\u{1F34B}",
517
+ "\u{1F349}",
518
+ "\u{1F347}",
519
+ "\u{1FAD0}",
520
+ "\u{1F348}",
521
+ "\u{1F352}",
522
+ "\u{1F351}",
523
+ "\u{1F96D}",
524
+ "\u{1F34D}",
525
+ "\u{1F965}",
526
+ "\u{1F95D}",
527
+ "\u{1F951}",
528
+ "\u{1F336}\uFE0F",
529
+ "\u{1F33D}",
530
+ "\u{1F955}",
531
+ "\u{1F36C}",
532
+ "\u{1F95C}",
533
+ "\u{1FAD6}",
534
+ "\u2615\uFE0F",
535
+ "\u{1F375}",
536
+ "\u{1F9CA}",
537
+ "\u{1F9C2}",
538
+ "\u{1F3D4}\uFE0F",
539
+ "\u2693\uFE0F",
540
+ "\u{1F6DF}",
541
+ "\u{1F3DD}\uFE0F",
542
+ "\u{1F6F6}",
543
+ "\u{1F680}",
544
+ "\u{1F6F0}\uFE0F",
545
+ "\u26F2\uFE0F",
546
+ "\u{1F3F0}",
547
+ "\u{1F6B2}",
548
+ "\u26FA\uFE0F",
549
+ "\u{1F399}\uFE0F",
550
+ "\u{1F9F2}",
551
+ "\u2699\uFE0F",
552
+ "\u{1F529}",
553
+ "\u{1F52E}",
554
+ "\u{1F52D}",
555
+ "\u{1F52C}",
556
+ "\u{1F9EC}",
557
+ "\u{1F321}\uFE0F",
558
+ "\u{1F9FA}",
559
+ "\u{1F6CE}\uFE0F",
560
+ "\u{1F511}",
561
+ "\u{1FA91}",
562
+ "\u{1F9F8}",
563
+ "\u{1F388}",
564
+ "\u{1F380}",
565
+ "\u{1F38A}",
566
+ "\u267B\uFE0F",
567
+ "\u{1F3B5}"
568
+ ];
569
+ var idHue = [
570
+ "red",
571
+ // 'orange' as const, /* More shades in these palettes are considered “ugly” */
572
+ "amber",
573
+ // 'yellow' as const, /* More shades in these palettes are considered “ugly” */
574
+ "lime",
575
+ "green",
576
+ "emerald",
577
+ "teal",
578
+ "cyan",
579
+ // 'sky' as const, /* Omitted since it is quite similar to the primary accent palette */
580
+ // 'blue' as const, /* Omitted since it is quite similar to the primary accent palette */
581
+ // 'indigo' as const, /* Omitted since it is quite similar to the primary accent palette */
582
+ "violet",
583
+ "purple",
584
+ "fuchsia",
585
+ "pink",
586
+ "rose"
587
+ ];
588
+ var keyToEmoji = (key) => hexToEmoji(key.toHex());
589
+ var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
590
+ var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
591
+ var keyToHue = (key) => hexToHue(key.toHex());
592
+ var hexToHue = (hex) => toHue(parseInt(hex, 16));
593
+ var toHue = (hash) => idHue[hash % idHue.length];
594
+ var keyToFallback = (key) => hexToFallback(key.toHex());
595
+ var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
596
+ var toFallback = (hash) => ({
597
+ emoji: toEmoji(hash),
598
+ hue: toHue(hash)
599
+ });
410
600
  var entry = (map, key) => new MapEntry(map, key);
411
601
  var MapEntry = class {
412
602
  /**
@@ -1162,7 +1352,7 @@ var getPrototypeSpecificInstanceId = (instance) => {
1162
1352
  return id;
1163
1353
  };
1164
1354
  var getDebugName = (instance) => {
1165
- if (instance === null) {
1355
+ if (instance == null) {
1166
1356
  return "null";
1167
1357
  }
1168
1358
  const prototype = Object.getPrototypeOf(instance);
@@ -1299,10 +1489,62 @@ var DeferAsyncGuard = class {
1299
1489
  await this._fn();
1300
1490
  }
1301
1491
  };
1492
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/util/src/circular-buffer.ts";
1493
+ var CircularBuffer = class {
1494
+ constructor(size) {
1495
+ this._nextIndex = 0;
1496
+ this._elementCount = 0;
1497
+ (0, import_invariant4.invariant)(size >= 1, void 0, {
1498
+ F: __dxlog_file4,
1499
+ L: 13,
1500
+ S: this,
1501
+ A: [
1502
+ "size >= 1",
1503
+ ""
1504
+ ]
1505
+ });
1506
+ this._buffer = new Array(size);
1507
+ }
1508
+ push(element) {
1509
+ this._buffer[this._nextIndex] = element;
1510
+ this._nextIndex = (this._nextIndex + 1) % this._buffer.length;
1511
+ this._elementCount = Math.min(this._buffer.length, this._elementCount + 1);
1512
+ }
1513
+ getLast() {
1514
+ if (this._elementCount === 0) {
1515
+ return void 0;
1516
+ }
1517
+ if (this._nextIndex === 0) {
1518
+ return this._buffer[this._buffer.length - 1];
1519
+ }
1520
+ return this._buffer[this._nextIndex - 1];
1521
+ }
1522
+ [Symbol.iterator]() {
1523
+ return this.values();
1524
+ }
1525
+ *values() {
1526
+ if (this._elementCount === 0) {
1527
+ return;
1528
+ }
1529
+ if (this._elementCount < this._buffer.length) {
1530
+ for (let i = 0; i < this._elementCount; i++) {
1531
+ yield this._buffer[i];
1532
+ }
1533
+ return;
1534
+ }
1535
+ for (let i = this._nextIndex; i < this._buffer.length; i++) {
1536
+ yield this._buffer[i];
1537
+ }
1538
+ for (let i = 0; i < this._nextIndex; i++) {
1539
+ yield this._buffer[i];
1540
+ }
1541
+ }
1542
+ };
1302
1543
  // Annotate the CommonJS export names for ESM import in node:
1303
1544
  0 && (module.exports = {
1304
1545
  BitField,
1305
1546
  Callback,
1547
+ CircularBuffer,
1306
1548
  ComplexMap,
1307
1549
  ComplexSet,
1308
1550
  HumanHasher,
@@ -1338,7 +1580,12 @@ var DeferAsyncGuard = class {
1338
1580
  getDeep,
1339
1581
  getHostPlatform,
1340
1582
  getPrototypeSpecificInstanceId,
1583
+ hexToEmoji,
1584
+ hexToFallback,
1585
+ hexToHue,
1341
1586
  humanize,
1587
+ idEmoji,
1588
+ idHue,
1342
1589
  inferObjectOrder,
1343
1590
  inferRecordOrder,
1344
1591
  iosCheck,
@@ -1348,6 +1595,9 @@ var DeferAsyncGuard = class {
1348
1595
  jsonKeyReplacer,
1349
1596
  jsonReplacer,
1350
1597
  jsonify,
1598
+ keyToEmoji,
1599
+ keyToFallback,
1600
+ keyToHue,
1351
1601
  makeMap,
1352
1602
  makeSet,
1353
1603
  mapValues,
@@ -1368,6 +1618,9 @@ var DeferAsyncGuard = class {
1368
1618
  stringToArray,
1369
1619
  stripUndefinedValues,
1370
1620
  sum,
1621
+ toEmoji,
1622
+ toFallback,
1623
+ toHue,
1371
1624
  tracer
1372
1625
  });
1373
1626
  //# sourceMappingURL=index.cjs.map