@dxos/util 0.8.1-main.ba2dec9 → 0.8.1-staging.31c3ee1

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.
@@ -612,6 +612,33 @@ var MapEntry = class {
612
612
  }
613
613
  };
614
614
 
615
+ // packages/common/util/src/first-two-chars.ts
616
+ var renderableCharRegex = /^(?![\p{Control}\p{Mark}\p{Separator}\p{Surrogate}\p{Unassigned}\p{P}])[\p{L}\p{N}\p{S}\p{Emoji}]$/u;
617
+ var getFirstTwoRenderableChars = (label) => {
618
+ const characters = Array.from(label);
619
+ const result = [
620
+ "",
621
+ ""
622
+ ];
623
+ let foundFirst = false;
624
+ for (let i = 0; i < characters.length; i++) {
625
+ const char = characters[i];
626
+ if (renderableCharRegex.test(char)) {
627
+ if (!foundFirst) {
628
+ result[0] = char;
629
+ foundFirst = true;
630
+ } else {
631
+ const textBetween = characters.slice(result[0].length, i).join("");
632
+ if (/[^\p{L}\p{N}_]/u.test(textBetween)) {
633
+ result[1] = char;
634
+ break;
635
+ }
636
+ }
637
+ }
638
+ }
639
+ return result;
640
+ };
641
+
615
642
  // packages/common/util/src/for-each-async.ts
616
643
  var forEachAsync = (items, fn) => Promise.all(items.map(fn));
617
644
 
@@ -1352,7 +1379,7 @@ var randomInt = (max, min = 0) => {
1352
1379
  };
1353
1380
 
1354
1381
  // packages/common/util/src/range.ts
1355
- var range = (n, mapper) => {
1382
+ var range = (n = 0, mapper) => {
1356
1383
  const range2 = Array.from(Array(n).keys());
1357
1384
  return mapper == null ? range2 : range2.map(mapper);
1358
1385
  };
@@ -1607,8 +1634,8 @@ var idEmoji = [
1607
1634
  // – less likely to evoke negative feelings (no meat, no drugs, no weapons, etc)
1608
1635
  // – less common as a signifier in UX
1609
1636
  // NOTE that this is intentionally an array of strings because of the way emoji graphemes work.
1610
- "\u{1F479}",
1611
1637
  "\u{1F47B}",
1638
+ "\u{1F479}",
1612
1639
  "\u{1F47D}",
1613
1640
  "\u{1F916}",
1614
1641
  "\u{1F383}",
@@ -1759,18 +1786,24 @@ var idHue = [
1759
1786
  "pink",
1760
1787
  "rose"
1761
1788
  ];
1762
- var keyToEmoji = (key) => hexToEmoji(key.toHex());
1763
- var hexToEmoji = (hex) => toEmoji(parseInt(hex, 16));
1764
- var toEmoji = (hash) => idEmoji[hash % idEmoji.length];
1765
- var keyToHue = (key) => hexToHue(key.toHex());
1766
- var hexToHue = (hex) => toHue(parseInt(hex, 16));
1767
- var toHue = (hash) => idHue[hash % idHue.length];
1789
+ var keyToEmoji = (key) => keyToFallback(key).emoji;
1790
+ var hexToEmoji = (hex) => hexToFallback(hex).emoji;
1791
+ var toEmoji = (hash) => toFallback(hash).emoji;
1792
+ var keyToHue = (key) => keyToFallback(key).hue;
1793
+ var hexToHue = (hex) => hexToFallback(hex).hue;
1794
+ var toHue = (hash) => toFallback(hash).hue;
1768
1795
  var keyToFallback = (key) => hexToFallback(key.toHex());
1769
1796
  var hexToFallback = (hex) => toFallback(parseInt(hex, 16));
1770
- var toFallback = (hash) => ({
1771
- emoji: toEmoji(hash),
1772
- hue: toHue(hash)
1773
- });
1797
+ var toFallback = (hash) => {
1798
+ const totalCombinations = idEmoji.length * idHue.length;
1799
+ const combinationIndex = hash % totalCombinations;
1800
+ const emojiIndex = Math.floor(combinationIndex / idHue.length);
1801
+ const hueIndex = combinationIndex % idHue.length;
1802
+ return {
1803
+ emoji: idEmoji[emojiIndex],
1804
+ hue: idHue[hueIndex]
1805
+ };
1806
+ };
1774
1807
 
1775
1808
  // packages/common/util/src/tracer.ts
1776
1809
  var Tracer = class {
@@ -2072,6 +2105,7 @@ export {
2072
2105
  getDate,
2073
2106
  getDebugName,
2074
2107
  getDeep,
2108
+ getFirstTwoRenderableChars,
2075
2109
  getHostPlatform,
2076
2110
  getPrototypeSpecificInstanceId,
2077
2111
  getProviderValue,