@rpcbase/ui 0.246.0 → 0.248.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.
Files changed (177) hide show
  1. package/dist/components/Notifications/NotificationsDrawer.d.ts.map +1 -1
  2. package/dist/index10.js +2 -2
  3. package/dist/index106.js +1 -1
  4. package/dist/index11.js +2 -2
  5. package/dist/index12.js +3 -3
  6. package/dist/index13.js +2 -2
  7. package/dist/index14.js +2 -2
  8. package/dist/index15.js +2 -2
  9. package/dist/index16.js +158 -158
  10. package/dist/index16.js.map +1 -1
  11. package/dist/index167.js +3 -3
  12. package/dist/index17.js +1 -1
  13. package/dist/index172.js +6 -6
  14. package/dist/index178.js +1 -1
  15. package/dist/index18.js +7 -7
  16. package/dist/index184.js +1 -1
  17. package/dist/index185.js +1 -1
  18. package/dist/index186.js +1 -1
  19. package/dist/index187.js +1 -1
  20. package/dist/index188.js +2 -2
  21. package/dist/index189.js +3 -3
  22. package/dist/index19.js +16 -16
  23. package/dist/index21.js +1 -1
  24. package/dist/index22.js +2 -2
  25. package/dist/index23.js +1 -1
  26. package/dist/index24.js +1 -1
  27. package/dist/index246.js +1 -1
  28. package/dist/index25.js +1 -1
  29. package/dist/index252.js +1 -1
  30. package/dist/index272.js +2 -2
  31. package/dist/index277.js +1 -1
  32. package/dist/index278.js +1 -1
  33. package/dist/index28.js +2 -2
  34. package/dist/index282.js +1 -1
  35. package/dist/index287.js +1 -1
  36. package/dist/index29.js +56 -3
  37. package/dist/index29.js.map +1 -1
  38. package/dist/index293.js +1 -1
  39. package/dist/index3.js +2 -2
  40. package/dist/index30.js +3 -242
  41. package/dist/index30.js.map +1 -1
  42. package/dist/index302.js +1 -1
  43. package/dist/index31.js +239 -21
  44. package/dist/index31.js.map +1 -1
  45. package/dist/index32.js +23 -4
  46. package/dist/index32.js.map +1 -1
  47. package/dist/index321.js +2 -2
  48. package/dist/index33.js +3 -6
  49. package/dist/index33.js.map +1 -1
  50. package/dist/index334.js +1 -1
  51. package/dist/index338.js +8 -24
  52. package/dist/index338.js.map +1 -1
  53. package/dist/index339.js +11 -28
  54. package/dist/index339.js.map +1 -1
  55. package/dist/index34.js +8 -38
  56. package/dist/index34.js.map +1 -1
  57. package/dist/index340.js +7 -15
  58. package/dist/index340.js.map +1 -1
  59. package/dist/index341.js +13 -8
  60. package/dist/index341.js.map +1 -1
  61. package/dist/index342.js +3 -11
  62. package/dist/index342.js.map +1 -1
  63. package/dist/index343.js +3 -8
  64. package/dist/index343.js.map +1 -1
  65. package/dist/index344.js +16 -12
  66. package/dist/index344.js.map +1 -1
  67. package/dist/index345.js +24 -3
  68. package/dist/index345.js.map +1 -1
  69. package/dist/index346.js +28 -3
  70. package/dist/index346.js.map +1 -1
  71. package/dist/index347.js +15 -16
  72. package/dist/index347.js.map +1 -1
  73. package/dist/index349.js +61 -5
  74. package/dist/index349.js.map +1 -1
  75. package/dist/index35.js +35 -74
  76. package/dist/index35.js.map +1 -1
  77. package/dist/index350.js +65 -60
  78. package/dist/index350.js.map +1 -1
  79. package/dist/index351.js +5 -66
  80. package/dist/index351.js.map +1 -1
  81. package/dist/index36.js +74 -20
  82. package/dist/index36.js.map +1 -1
  83. package/dist/index365.js +4 -12
  84. package/dist/index365.js.map +1 -1
  85. package/dist/index366.js +12 -4
  86. package/dist/index366.js.map +1 -1
  87. package/dist/index37.js +18 -33
  88. package/dist/index37.js.map +1 -1
  89. package/dist/index379.js +2 -2
  90. package/dist/index38.js +36 -26
  91. package/dist/index38.js.map +1 -1
  92. package/dist/index386.js +1 -1
  93. package/dist/index388.js +1 -1
  94. package/dist/index39.js +26 -21
  95. package/dist/index39.js.map +1 -1
  96. package/dist/index4.js +2 -2
  97. package/dist/index40.js +20 -56
  98. package/dist/index40.js.map +1 -1
  99. package/dist/index41.js +59 -51
  100. package/dist/index41.js.map +1 -1
  101. package/dist/index411.js +15 -3
  102. package/dist/index411.js.map +1 -1
  103. package/dist/index412.js +3 -15
  104. package/dist/index412.js.map +1 -1
  105. package/dist/index417.js +1 -1
  106. package/dist/index419.js +1 -1
  107. package/dist/index42.js +50 -21
  108. package/dist/index42.js.map +1 -1
  109. package/dist/index420.js +2 -2
  110. package/dist/index423.js +1 -1
  111. package/dist/index424.js +1 -1
  112. package/dist/index427.js +1 -1
  113. package/dist/index428.js +1 -1
  114. package/dist/index43.js +18 -127
  115. package/dist/index43.js.map +1 -1
  116. package/dist/index430.js +16 -2
  117. package/dist/index430.js.map +1 -1
  118. package/dist/index431.js +29 -2
  119. package/dist/index431.js.map +1 -1
  120. package/dist/index432.js +13 -2
  121. package/dist/index432.js.map +1 -1
  122. package/dist/index433.js +7 -2
  123. package/dist/index433.js.map +1 -1
  124. package/dist/index434.js +2 -16
  125. package/dist/index434.js.map +1 -1
  126. package/dist/index435.js +2 -29
  127. package/dist/index435.js.map +1 -1
  128. package/dist/index436.js +2 -13
  129. package/dist/index436.js.map +1 -1
  130. package/dist/index437.js +2 -7
  131. package/dist/index437.js.map +1 -1
  132. package/dist/index44.js +122 -39
  133. package/dist/index44.js.map +1 -1
  134. package/dist/index45.js +42 -85
  135. package/dist/index45.js.map +1 -1
  136. package/dist/index46.js +87 -123
  137. package/dist/index46.js.map +1 -1
  138. package/dist/index47.js +126 -5
  139. package/dist/index47.js.map +1 -1
  140. package/dist/index48.js +5 -332
  141. package/dist/index48.js.map +1 -1
  142. package/dist/index49.js +320 -245
  143. package/dist/index49.js.map +1 -1
  144. package/dist/index5.js +2 -2
  145. package/dist/index50.js +254 -23
  146. package/dist/index50.js.map +1 -1
  147. package/dist/index51.js +25 -129
  148. package/dist/index51.js.map +1 -1
  149. package/dist/index52.js +129 -24
  150. package/dist/index52.js.map +1 -1
  151. package/dist/index53.js +22 -19
  152. package/dist/index53.js.map +1 -1
  153. package/dist/index54.js +19 -134
  154. package/dist/index54.js.map +1 -1
  155. package/dist/index55.js +133 -30
  156. package/dist/index55.js.map +1 -1
  157. package/dist/index56.js +30 -24
  158. package/dist/index56.js.map +1 -1
  159. package/dist/index57.js +26 -38
  160. package/dist/index57.js.map +1 -1
  161. package/dist/index58.js +38 -18
  162. package/dist/index58.js.map +1 -1
  163. package/dist/index59.js +17 -132
  164. package/dist/index59.js.map +1 -1
  165. package/dist/index6.js +4 -4
  166. package/dist/index60.js +134 -49
  167. package/dist/index60.js.map +1 -1
  168. package/dist/index61.js +48 -25
  169. package/dist/index61.js.map +1 -1
  170. package/dist/index62.js +28 -57
  171. package/dist/index62.js.map +1 -1
  172. package/dist/index63.js +57 -56
  173. package/dist/index63.js.map +1 -1
  174. package/dist/index7.js +11 -11
  175. package/dist/index8.js +2 -2
  176. package/dist/index9.js +1 -1
  177. package/package.json +1 -1
package/dist/index437.js CHANGED
@@ -1,10 +1,5 @@
1
- function r(t) {
2
- return (d = {}) => {
3
- const n = d.width ? String(d.width) : t.defaultWidth;
4
- return t.formats[n] || t.formats[t.defaultWidth];
5
- };
6
- }
1
+ var e = {};
7
2
  export {
8
- r as buildFormatLongFn
3
+ e as __exports
9
4
  };
10
5
  //# sourceMappingURL=index437.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index437.js","sources":["../../../node_modules/date-fns/locale/_lib/buildFormatLongFn.js"],"sourcesContent":["export function buildFormatLongFn(args) {\n return (options = {}) => {\n // TODO: Remove String()\n const width = options.width ? String(options.width) : args.defaultWidth;\n const format = args.formats[width] || args.formats[args.defaultWidth];\n return format;\n };\n}\n"],"names":["buildFormatLongFn","args","options","width"],"mappings":"AAAO,SAASA,EAAkBC,GAAM;AACtC,SAAO,CAACC,IAAU,OAAO;AAEvB,UAAMC,IAAQD,EAAQ,QAAQ,OAAOA,EAAQ,KAAK,IAAID,EAAK;AAE3D,WADeA,EAAK,QAAQE,CAAK,KAAKF,EAAK,QAAQA,EAAK,YAAY;AAAA,EAEtE;AACF;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"index437.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/dist/index44.js CHANGED
@@ -1,51 +1,134 @@
1
- import { AsYouType as u } from "./index77.js";
2
- import { validatePhoneNumberLength as a } from "./index78.js";
3
- function l(t) {
4
- return t.replace(/\D/g, "");
5
- }
6
- const f = {
7
- GG: "GB",
8
- JE: "GB",
9
- IM: "GB"
10
- };
11
- function m(t) {
12
- if (t)
13
- return f[t] ?? t;
1
+ import { getCountryList as E } from "./index76.js";
2
+ import { getCountryCallingCode as s } from "./index48.js";
3
+ const f = "US", u = E(), c = /* @__PURE__ */ new Map(), m = "__default_locale__", _ = Array.from(new Set(u.map((e) => s(e)))).sort((e, t) => t.length - e.length);
4
+ _.reduce((e, t) => Math.max(e, t.length), 0);
5
+ const O = ["0011", "001", "011", "00", "810"];
6
+ function y(e) {
7
+ return e && u.includes(e) ? e : f;
8
+ }
9
+ function C(e) {
10
+ if (typeof Intl > "u" || typeof Intl.DisplayNames > "u")
11
+ return null;
12
+ try {
13
+ const t = Array.isArray(e) ? e : e ? [e] : void 0;
14
+ return new Intl.DisplayNames(t, {
15
+ type: "region"
16
+ });
17
+ } catch {
18
+ return null;
19
+ }
14
20
  }
15
- function N(t, n) {
16
- if (t === "+")
21
+ function N(e) {
22
+ const t = C(e), r = C("en");
23
+ return u.map((n) => {
24
+ const a = s(n), o = t?.of(n) ?? r?.of(n) ?? n, i = r?.of(n) ?? o, g = T(n), l = Array.from(new Set([o, i, n.toUpperCase(), n.toLowerCase(), ...g].filter(Boolean)));
17
25
  return {
18
- international: "+",
19
- national: "",
20
- formatted: "+",
21
- phoneNumber: null,
22
- detectedCountry: void 0
26
+ value: n,
27
+ name: o,
28
+ dialCode: a,
29
+ label: `${o} (+${a})`,
30
+ flag: A(n),
31
+ searchableTokens: l,
32
+ normalizedSearchableTokens: l.map((p) => U(p))
23
33
  };
24
- const r = n ? new u(n) : new u(), o = r.input(t), e = r.getNumber(), c = m(e?.country ?? r.country ?? void 0), i = e?.formatInternational() ?? o, s = e?.formatNational() ?? l(i);
34
+ }).sort((n, a) => {
35
+ const o = d(n.value), i = d(a.value);
36
+ return o !== i ? o - i : n.name.localeCompare(a.name);
37
+ });
38
+ }
39
+ function d(e) {
40
+ return e === "US" ? 0 : e === "CA" ? 1 : s(e) === "1" ? 2 : 3;
41
+ }
42
+ function R(e) {
43
+ return e ? Array.isArray(e) ? e.join("\0") : e : m;
44
+ }
45
+ function b(e) {
46
+ if (e !== m) {
47
+ if (e.includes("\0")) {
48
+ const t = e.split("\0").filter(Boolean);
49
+ return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
50
+ }
51
+ return e;
52
+ }
53
+ }
54
+ function L(e, t) {
55
+ const r = c.get(t);
56
+ if (r)
57
+ return r;
58
+ const n = N(e);
59
+ return c.set(t, n), n;
60
+ }
61
+ function v(e) {
25
62
  return {
26
- international: i,
27
- national: s,
28
- formatted: o,
29
- phoneNumber: e,
30
- detectedCountry: c
63
+ code: e.value,
64
+ name: e.name,
65
+ dialCode: e.dialCode,
66
+ flag: e.flag
31
67
  };
32
68
  }
33
- function O(t, n) {
34
- return t.startsWith(n) ? t.slice(n.length) : t;
69
+ function F(e) {
70
+ return {
71
+ code: e,
72
+ name: e,
73
+ dialCode: s(e),
74
+ flag: A(e)
75
+ };
35
76
  }
36
- function d(t, n) {
37
- if (!n || !t)
38
- return null;
39
- try {
40
- return a(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
41
- } catch {
42
- return null;
77
+ function A(e) {
78
+ const t = e?.toUpperCase();
79
+ if (!t || t.length !== 2 || /[^A-Z]/.test(t))
80
+ return "";
81
+ const r = 127397;
82
+ return String.fromCodePoint(t.charCodeAt(0) + r, t.charCodeAt(1) + r);
83
+ }
84
+ const S = /[\u0300-\u036f]/g;
85
+ function h(e) {
86
+ return e.normalize("NFD").replace(S, "");
87
+ }
88
+ function U(e) {
89
+ return h(e).toLowerCase();
90
+ }
91
+ function B(e, t) {
92
+ let r = Number.MAX_SAFE_INTEGER;
93
+ for (const n of e) {
94
+ const a = n.indexOf(t);
95
+ a >= 0 && a < r && (r = a);
96
+ }
97
+ return r === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : r;
98
+ }
99
+ function T(e) {
100
+ switch (e) {
101
+ case "US":
102
+ return ["USA", "United States", "America", "United States of America"];
103
+ case "GB":
104
+ return ["UK", "United Kingdom", "Great Britain", "England"];
105
+ case "AE":
106
+ return ["UAE", "United Arab Emirates"];
107
+ case "KR":
108
+ return ["South Korea", "Korea"];
109
+ case "CN":
110
+ return ["China", "PRC"];
111
+ case "CD":
112
+ return ["DRC", "Congo-Kinshasa"];
113
+ case "CG":
114
+ return ["Congo-Brazzaville"];
115
+ case "BR":
116
+ return ["Brazil"];
117
+ default:
118
+ return [];
43
119
  }
44
120
  }
45
121
  export {
46
- N as formatWithAsYouType,
47
- d as getLengthIssue,
48
- l as sanitizeDigits,
49
- O as stripPrefix
122
+ O as COMMON_IDD_PREFIXES,
123
+ _ as COUNTRY_DIAL_CODES,
124
+ f as DEFAULT_COUNTRY,
125
+ F as buildFallbackSelectedCountry,
126
+ L as getCachedCountryOptions,
127
+ R as getLocaleCacheKey,
128
+ y as getValidCountry,
129
+ U as normalizeSearchValue,
130
+ B as optionMatchIndex,
131
+ b as parseLocaleCacheKey,
132
+ v as toSelectedCountry
50
133
  };
51
134
  //# sourceMappingURL=index44.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index44.js","sources":["../src/components/PhoneNumberInput/normalization.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { AsYouType, validatePhoneNumberLength } from \"libphonenumber-js\"\n\n\nexport type LengthIssue = \"TOO_LONG\"\n\nexport function sanitizeDigits(value: string) {\n return value.replace(/\\D/g, \"\")\n}\n\nconst DETECTED_COUNTRY_OVERRIDES: Partial<Record<CountryCode, CountryCode>> = {\n GG: \"GB\",\n JE: \"GB\",\n IM: \"GB\",\n}\n\nfunction canonicalizeDetectedCountry(candidate: CountryCode | undefined): CountryCode | undefined {\n if (!candidate) {\n return undefined\n }\n return DETECTED_COUNTRY_OVERRIDES[candidate] ?? candidate\n}\n\nexport function formatWithAsYouType(value: string, baseCountry?: CountryCode) {\n if (value === \"+\") {\n return {\n international: \"+\",\n national: \"\",\n formatted: \"+\",\n phoneNumber: null,\n detectedCountry: undefined,\n }\n }\n\n const formatter = baseCountry ? new AsYouType(baseCountry) : new AsYouType()\n const formatted = formatter.input(value)\n const phoneNumber = formatter.getNumber()\n const detectedCountry = canonicalizeDetectedCountry(\n (phoneNumber?.country ?? formatter.country ?? undefined) as CountryCode | undefined\n )\n const international = phoneNumber?.formatInternational() ?? formatted\n const national = phoneNumber?.formatNational() ?? sanitizeDigits(international)\n\n return {\n international,\n national,\n formatted,\n phoneNumber,\n detectedCountry,\n }\n}\n\nexport function stripPrefix(value: string, prefix: string) {\n return value.startsWith(prefix) ? value.slice(prefix.length) : value\n}\n\nexport function getLengthIssue(value: string, country: CountryCode | undefined): LengthIssue | null {\n if (!country || !value) {\n return null\n }\n\n try {\n const result = validatePhoneNumberLength(value, country)\n return result === \"TOO_LONG\" ? \"TOO_LONG\" : null\n } catch {\n return null\n }\n}\n"],"names":["sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","GG","JE","IM","canonicalizeDetectedCountry","candidate","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","undefined","formatter","AsYouType","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","validatePhoneNumberLength"],"mappings":";;AAMO,SAASA,EAAeC,GAAe;AAC5C,SAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,MAAMC,IAAwE;AAAA,EAC5EC,IAAI;AAAA,EACJC,IAAI;AAAA,EACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;AAChG,MAAKA;AAGL,WAAOL,EAA2BK,CAAS,KAAKA;AAClD;AAEO,SAASC,EAAoBR,GAAeS,GAA2B;AAC5E,MAAIT,MAAU;AACZ,WAAO;AAAA,MACLU,eAAe;AAAA,MACfC,UAAU;AAAA,MACVC,WAAW;AAAA,MACXC,aAAa;AAAA,MACbC,iBAAiBC;AAAAA,IAAAA;AAIrB,QAAMC,IAAYP,IAAc,IAAIQ,EAAUR,CAAW,IAAI,IAAIQ,EAAAA,GAC3DL,IAAYI,EAAUE,MAAMlB,CAAK,GACjCa,IAAcG,EAAUG,UAAAA,GACxBL,IAAkBR,EACrBO,GAAaO,WAAWJ,EAAUI,WAAWL,MAChD,GACML,IAAgBG,GAAaQ,oBAAAA,KAAyBT,GACtDD,IAAWE,GAAaS,eAAAA,KAAoBvB,EAAeW,CAAa;AAE9E,SAAO;AAAA,IACLA,eAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,WAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,iBAAAA;AAAAA,EAAAA;AAEJ;AAEO,SAASS,EAAYvB,GAAewB,GAAgB;AACzD,SAAOxB,EAAMyB,WAAWD,CAAM,IAAIxB,EAAM0B,MAAMF,EAAOG,MAAM,IAAI3B;AACjE;AAEO,SAAS4B,EAAe5B,GAAeoB,GAAsD;AAClG,MAAI,CAACA,KAAW,CAACpB;AACf,WAAO;AAGT,MAAI;AAEF,WADe6B,EAA0B7B,GAAOoB,CAAO,MACrC,aAAa,aAAa;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"index44.js","sources":["../src/components/PhoneNumberInput/country-options.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { getCountryCallingCode } from \"libphonenumber-js\"\n\nimport type { CountryOption, PhoneNumberSelectedCountry } from \"./types\"\nimport { getCountryList } from \"./countries\"\n\n\nexport const DEFAULT_COUNTRY: CountryCode = \"US\"\nconst COUNTRY_OPTIONS = getCountryList()\n\nconst COUNTRY_OPTIONS_CACHE = new Map<string, CountryOption[]>()\nconst DEFAULT_LOCALE_CACHE_KEY = \"__default_locale__\"\nexport const COUNTRY_DIAL_CODES = Array.from(\n new Set(COUNTRY_OPTIONS.map((code) => getCountryCallingCode(code)))\n).sort((a, b) => b.length - a.length)\nexport const MAX_DIAL_CODE_LENGTH = COUNTRY_DIAL_CODES.reduce(\n (max, dial) => Math.max(max, dial.length),\n 0\n)\nexport const COMMON_IDD_PREFIXES = [\"0011\", \"001\", \"011\", \"00\", \"810\"]\n\nexport function getValidCountry(input: CountryCode | undefined) {\n if (!input) {\n return DEFAULT_COUNTRY\n }\n\n return COUNTRY_OPTIONS.includes(input) ? input : DEFAULT_COUNTRY\n}\n\nfunction createDisplayNames(locale?: string | string[]) {\n if (typeof Intl === \"undefined\" || typeof Intl.DisplayNames === \"undefined\") {\n return null\n }\n\n try {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : undefined\n return new Intl.DisplayNames(locales, { type: \"region\" })\n } catch {\n return null\n }\n}\n\nfunction buildCountryOptions(locale?: string | string[]) {\n const displayNames = createDisplayNames(locale)\n const englishDisplayNames = createDisplayNames(\"en\")\n\n return COUNTRY_OPTIONS\n .map((country) => {\n const dialCode = getCountryCallingCode(country)\n const localizedName = displayNames?.of(country) ?? englishDisplayNames?.of(country) ?? country\n const englishName = englishDisplayNames?.of(country) ?? localizedName\n const aliasTokens = getCountryAliases(country)\n const searchableTokens = Array.from(\n new Set(\n [localizedName, englishName, country.toUpperCase(), country.toLowerCase(), ...aliasTokens].filter(\n Boolean\n )\n )\n ) as string[]\n return {\n value: country,\n name: localizedName,\n dialCode,\n label: `${localizedName} (+${dialCode})`,\n flag: countryCodeToFlagEmoji(country),\n searchableTokens,\n normalizedSearchableTokens: searchableTokens.map((token) => normalizeSearchValue(token)),\n }\n })\n .sort((a, b) => {\n const priorityA = getCountryPriority(a.value)\n const priorityB = getCountryPriority(b.value)\n if (priorityA !== priorityB) {\n return priorityA - priorityB\n }\n return a.name.localeCompare(b.name)\n })\n}\n\nfunction getCountryPriority(code: CountryCode) {\n if (code === \"US\") return 0\n if (code === \"CA\") return 1\n if (getCountryCallingCode(code) === \"1\") return 2\n return 3\n}\n\nexport function getLocaleCacheKey(locale?: string | string[]) {\n if (!locale) {\n return DEFAULT_LOCALE_CACHE_KEY\n }\n if (Array.isArray(locale)) {\n return locale.join(\"\\u0000\")\n }\n return locale\n}\n\nexport function parseLocaleCacheKey(cacheKey: string): string | string[] | undefined {\n if (cacheKey === DEFAULT_LOCALE_CACHE_KEY) {\n return undefined\n }\n\n if (cacheKey.includes(\"\\u0000\")) {\n const parts = cacheKey.split(\"\\u0000\").filter(Boolean)\n if (parts.length === 0) {\n return undefined\n }\n if (parts.length === 1) {\n return parts[0] ?? undefined\n }\n return parts\n }\n\n return cacheKey\n}\n\nexport function getCachedCountryOptions(locale: string | string[] | undefined, cacheKey: string) {\n const cached = COUNTRY_OPTIONS_CACHE.get(cacheKey)\n if (cached) {\n return cached\n }\n const built = buildCountryOptions(locale)\n COUNTRY_OPTIONS_CACHE.set(cacheKey, built)\n return built\n}\n\nexport function toSelectedCountry(option: CountryOption): PhoneNumberSelectedCountry {\n return {\n code: option.value,\n name: option.name,\n dialCode: option.dialCode,\n flag: option.flag,\n }\n}\n\nexport function buildFallbackSelectedCountry(country: CountryCode): PhoneNumberSelectedCountry {\n return {\n code: country,\n name: country,\n dialCode: getCountryCallingCode(country),\n flag: countryCodeToFlagEmoji(country),\n }\n}\n\nfunction countryCodeToFlagEmoji(country: CountryCode) {\n const upper = country?.toUpperCase()\n\n if (!upper || upper.length !== 2 || /[^A-Z]/.test(upper)) {\n return \"\"\n }\n\n const base = 127397\n return String.fromCodePoint(\n upper.charCodeAt(0) + base,\n upper.charCodeAt(1) + base\n )\n}\n\nconst DIACRITICS_REGEX = /[\\u0300-\\u036f]/g\n\nfunction stripDiacritics(value: string) {\n return value.normalize(\"NFD\").replace(DIACRITICS_REGEX, \"\")\n}\n\nexport function normalizeSearchValue(value: string) {\n return stripDiacritics(value).toLowerCase()\n}\n\nexport function optionMatchIndex(tokens: string[], query: string) {\n let best = Number.MAX_SAFE_INTEGER\n for (const token of tokens) {\n const index = token.indexOf(query)\n if (index >= 0 && index < best) {\n best = index\n }\n }\n return best === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : best\n}\n\nfunction getCountryAliases(code: CountryCode): string[] {\n switch (code) {\n case \"US\":\n return [\"USA\", \"United States\", \"America\", \"United States of America\"]\n case \"GB\":\n return [\"UK\", \"United Kingdom\", \"Great Britain\", \"England\"]\n case \"AE\":\n return [\"UAE\", \"United Arab Emirates\"]\n case \"KR\":\n return [\"South Korea\", \"Korea\"]\n case \"CN\":\n return [\"China\", \"PRC\"]\n case \"CD\":\n return [\"DRC\", \"Congo-Kinshasa\"]\n case \"CG\":\n return [\"Congo-Brazzaville\"]\n case \"BR\":\n return [\"Brazil\"]\n default:\n return []\n }\n}\n\n"],"names":["DEFAULT_COUNTRY","COUNTRY_OPTIONS","getCountryList","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","getCountryCallingCode","sort","a","b","length","reduce","max","dial","Math","COMMON_IDD_PREFIXES","getValidCountry","input","includes","createDisplayNames","locale","Intl","DisplayNames","locales","isArray","undefined","type","buildCountryOptions","displayNames","englishDisplayNames","country","dialCode","localizedName","of","englishName","aliasTokens","getCountryAliases","searchableTokens","toUpperCase","toLowerCase","filter","Boolean","value","name","label","flag","countryCodeToFlagEmoji","normalizedSearchableTokens","token","normalizeSearchValue","priorityA","getCountryPriority","priorityB","localeCompare","getLocaleCacheKey","join","parseLocaleCacheKey","cacheKey","parts","split","getCachedCountryOptions","cached","get","built","set","toSelectedCountry","option","buildFallbackSelectedCountry","upper","test","base","String","fromCodePoint","charCodeAt","DIACRITICS_REGEX","stripDiacritics","normalize","replace","optionMatchIndex","tokens","query","best","Number","MAX_SAFE_INTEGER","index","indexOf"],"mappings":";;AAOO,MAAMA,IAA+B,MACtCC,IAAkBC,EAAAA,GAElBC,wBAA4BC,IAAAA,GAC5BC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIR,EAAgBS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ACH,aAAO,CAAC,eAAe,OAAO;AAAA,IAChC,KAAK;AACH,aAAO,CAAC,SAAS,KAAK;AAAA,IACxB,KAAK;AACH,aAAO,CAAC,OAAO,gBAAgB;AAAA,IACjC,KAAK;AACH,aAAO,CAAC,mBAAmB;AAAA,IAC7B,KAAK;AACH,aAAO,CAAC,QAAQ;AAAA,IAClB;AACE,aAAO,CAAA;AAAA,EAAA;AAEX;"}
package/dist/index45.js CHANGED
@@ -1,94 +1,51 @@
1
- function c(t) {
2
- if (!t)
3
- return !1;
4
- const e = t.charCodeAt(0);
5
- return e >= 48 && e <= 57;
6
- }
7
- function l(t, e) {
8
- let n = 0;
9
- const r = Math.min(e, t.length);
10
- for (let i = 0; i < r; i += 1)
11
- c(t[i] ?? "") && (n += 1);
12
- return n;
13
- }
14
- function a(t, e) {
15
- if (e <= 0)
16
- return t.startsWith("+") ? Math.min(1, t.length) : 0;
17
- let n = 0;
18
- for (let r = 0; r < t.length; r += 1)
19
- if (c(t[r] ?? "") && (n += 1, n === e))
20
- return r + 1;
21
- return t.length;
22
- }
23
- function g(t) {
24
- return !t || c(t) ? !1 : t !== "+";
25
- }
26
- function h(t, e) {
27
- let n = e;
28
- for (; n > 0; ) {
29
- const r = t[n - 1] ?? "";
30
- if (!g(r))
31
- break;
32
- n -= 1;
33
- }
34
- return n;
35
- }
36
- function S(t, e) {
37
- let n = e;
38
- for (; n < t.length; ) {
39
- const r = t[n] ?? "";
40
- if (!g(r))
41
- break;
42
- n += 1;
43
- }
44
- return n;
45
- }
1
+ import { AsYouType as u } from "./index77.js";
2
+ import { validatePhoneNumberLength as a } from "./index78.js";
3
+ function l(t) {
4
+ return t.replace(/\D/g, "");
5
+ }
6
+ const f = {
7
+ GG: "GB",
8
+ JE: "GB",
9
+ IM: "GB"
10
+ };
46
11
  function m(t) {
47
- const {
48
- value: e
49
- } = t, n = t.selectionStart ?? e.length, r = t.selectionEnd ?? n, i = n <= 1 && e.startsWith("+"), o = r <= 1 && e.startsWith("+");
12
+ if (t)
13
+ return f[t] ?? t;
14
+ }
15
+ function N(t, n) {
16
+ if (t === "+")
17
+ return {
18
+ international: "+",
19
+ national: "",
20
+ formatted: "+",
21
+ phoneNumber: null,
22
+ detectedCountry: void 0
23
+ };
24
+ const r = n ? new u(n) : new u(), o = r.input(t), e = r.getNumber(), c = m(e?.country ?? r.country ?? void 0), i = e?.formatInternational() ?? o, s = e?.formatNational() ?? l(i);
50
25
  return {
51
- selectionStart: n,
52
- selectionEnd: r,
53
- startDigits: l(e, n),
54
- endDigits: l(e, r),
55
- preserveStartIndex: i,
56
- preserveEndIndex: o,
57
- wasAtStart: n === 0,
58
- wasAtEnd: r === e.length
26
+ international: i,
27
+ national: s,
28
+ formatted: o,
29
+ phoneNumber: e,
30
+ detectedCountry: c
59
31
  };
60
32
  }
61
- function u(t, e) {
62
- if (t.selectionStart === t.selectionEnd) {
63
- if (t.wasAtEnd) {
64
- const f = e.length;
65
- return {
66
- start: f,
67
- end: f
68
- };
69
- }
70
- if (t.wasAtStart)
71
- return {
72
- start: 0,
73
- end: 0
74
- };
33
+ function O(t, n) {
34
+ return t.startsWith(n) ? t.slice(n.length) : t;
35
+ }
36
+ function d(t, n) {
37
+ if (!n || !t)
38
+ return null;
39
+ try {
40
+ return a(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
41
+ } catch {
42
+ return null;
75
43
  }
76
- const n = t.preserveStartIndex ? Math.min(t.selectionStart, e.length) : a(e, t.startDigits), r = t.preserveEndIndex ? Math.min(t.selectionEnd, e.length) : a(e, t.endDigits);
77
- let i = n, o = r;
78
- t.wasAtStart && (i = 0), t.wasAtEnd && (o = e.length), t.selectionStart === t.selectionEnd && (i = o);
79
- const d = Math.min(Math.max(i, 0), e.length), s = Math.min(Math.max(o, 0), e.length);
80
- return d > s ? {
81
- start: s,
82
- end: s
83
- } : {
84
- start: d,
85
- end: s
86
- };
87
44
  }
88
45
  export {
89
- m as captureSelectionSnapshot,
90
- u as resolveSelection,
91
- h as skipFormattingCharactersLeft,
92
- S as skipFormattingCharactersRight
46
+ N as formatWithAsYouType,
47
+ d as getLengthIssue,
48
+ l as sanitizeDigits,
49
+ O as stripPrefix
93
50
  };
94
51
  //# sourceMappingURL=index45.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index45.js","sources":["../src/components/PhoneNumberInput/selection.ts"],"sourcesContent":["function isDigitCharacter(char: string) {\n if (!char) {\n return false\n }\n const code = char.charCodeAt(0)\n return code >= 48 && code <= 57\n}\n\nfunction countDigitsBefore(value: string, index: number) {\n let count = 0\n const limit = Math.min(index, value.length)\n for (let position = 0; position < limit; position += 1) {\n if (isDigitCharacter(value[position] ?? \"\")) {\n count += 1\n }\n }\n return count\n}\n\nfunction findIndexForDigitCount(value: string, digitCount: number) {\n if (digitCount <= 0) {\n return value.startsWith(\"+\") ? Math.min(1, value.length) : 0\n }\n\n let seen = 0\n for (let index = 0; index < value.length; index += 1) {\n if (isDigitCharacter(value[index] ?? \"\")) {\n seen += 1\n if (seen === digitCount) {\n return index + 1\n }\n }\n }\n\n return value.length\n}\n\nfunction isFormattingCharacter(char: string) {\n if (!char) {\n return false\n }\n if (isDigitCharacter(char)) {\n return false\n }\n return char !== \"+\"\n}\n\nexport function skipFormattingCharactersLeft(value: string, index: number) {\n let position = index\n while (position > 0) {\n const next = value[position - 1] ?? \"\"\n if (!isFormattingCharacter(next)) {\n break\n }\n position -= 1\n }\n return position\n}\n\nexport function skipFormattingCharactersRight(value: string, index: number) {\n let position = index\n while (position < value.length) {\n const next = value[position] ?? \"\"\n if (!isFormattingCharacter(next)) {\n break\n }\n position += 1\n }\n return position\n}\n\ntype SelectionSnapshot = {\n selectionStart: number\n selectionEnd: number\n startDigits: number\n endDigits: number\n preserveStartIndex: boolean\n preserveEndIndex: boolean\n wasAtStart: boolean\n wasAtEnd: boolean\n}\n\nexport function captureSelectionSnapshot(input: HTMLInputElement): SelectionSnapshot {\n const { value } = input\n const selectionStart = input.selectionStart ?? value.length\n const selectionEnd = input.selectionEnd ?? selectionStart\n const preserveStartIndex = selectionStart <= 1 && value.startsWith(\"+\")\n const preserveEndIndex = selectionEnd <= 1 && value.startsWith(\"+\")\n\n return {\n selectionStart,\n selectionEnd,\n startDigits: countDigitsBefore(value, selectionStart),\n endDigits: countDigitsBefore(value, selectionEnd),\n preserveStartIndex,\n preserveEndIndex,\n wasAtStart: selectionStart === 0,\n wasAtEnd: selectionEnd === value.length,\n }\n}\n\nexport function resolveSelection(snapshot: SelectionSnapshot, value: string) {\n if (snapshot.selectionStart === snapshot.selectionEnd) {\n if (snapshot.wasAtEnd) {\n const end = value.length\n return { start: end, end }\n }\n if (snapshot.wasAtStart) {\n return { start: 0, end: 0 }\n }\n }\n\n const start = snapshot.preserveStartIndex\n ? Math.min(snapshot.selectionStart, value.length)\n : findIndexForDigitCount(value, snapshot.startDigits)\n const end = snapshot.preserveEndIndex\n ? Math.min(snapshot.selectionEnd, value.length)\n : findIndexForDigitCount(value, snapshot.endDigits)\n\n let resolvedStart = start\n let resolvedEnd = end\n\n if (snapshot.wasAtStart) {\n resolvedStart = 0\n }\n\n if (snapshot.wasAtEnd) {\n resolvedEnd = value.length\n }\n\n if (snapshot.selectionStart === snapshot.selectionEnd) {\n resolvedStart = resolvedEnd\n }\n\n const clampedStart = Math.min(Math.max(resolvedStart, 0), value.length)\n const clampedEnd = Math.min(Math.max(resolvedEnd, 0), value.length)\n\n if (clampedStart > clampedEnd) {\n return { start: clampedEnd, end: clampedEnd }\n }\n\n return { start: clampedStart, end: clampedEnd }\n}\n\n"],"names":["isDigitCharacter","char","code","charCodeAt","countDigitsBefore","value","index","count","limit","Math","min","length","position","findIndexForDigitCount","digitCount","startsWith","seen","isFormattingCharacter","skipFormattingCharactersLeft","next","skipFormattingCharactersRight","captureSelectionSnapshot","input","selectionStart","selectionEnd","preserveStartIndex","preserveEndIndex","startDigits","endDigits","wasAtStart","wasAtEnd","resolveSelection","snapshot","end","start","resolvedStart","resolvedEnd","clampedStart","max","clampedEnd"],"mappings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,QAAMC,IAAe5B,KAAKC,IAAID,KAAK6B,IAAIH,GAAe,CAAC,GAAG9B,EAAMM,MAAM,GAChE4B,IAAa9B,KAAKC,IAAID,KAAK6B,IAAIF,GAAa,CAAC,GAAG/B,EAAMM,MAAM;AAElE,SAAI0B,IAAeE,IACV;AAAA,IAAEL,OAAOK;AAAAA,IAAYN,KAAKM;AAAAA,EAAAA,IAG5B;AAAA,IAAEL,OAAOG;AAAAA,IAAcJ,KAAKM;AAAAA,EAAAA;AACrC;"}
1
+ {"version":3,"file":"index45.js","sources":["../src/components/PhoneNumberInput/normalization.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { AsYouType, validatePhoneNumberLength } from \"libphonenumber-js\"\n\n\nexport type LengthIssue = \"TOO_LONG\"\n\nexport function sanitizeDigits(value: string) {\n return value.replace(/\\D/g, \"\")\n}\n\nconst DETECTED_COUNTRY_OVERRIDES: Partial<Record<CountryCode, CountryCode>> = {\n GG: \"GB\",\n JE: \"GB\",\n IM: \"GB\",\n}\n\nfunction canonicalizeDetectedCountry(candidate: CountryCode | undefined): CountryCode | undefined {\n if (!candidate) {\n return undefined\n }\n return DETECTED_COUNTRY_OVERRIDES[candidate] ?? candidate\n}\n\nexport function formatWithAsYouType(value: string, baseCountry?: CountryCode) {\n if (value === \"+\") {\n return {\n international: \"+\",\n national: \"\",\n formatted: \"+\",\n phoneNumber: null,\n detectedCountry: undefined,\n }\n }\n\n const formatter = baseCountry ? new AsYouType(baseCountry) : new AsYouType()\n const formatted = formatter.input(value)\n const phoneNumber = formatter.getNumber()\n const detectedCountry = canonicalizeDetectedCountry(\n (phoneNumber?.country ?? formatter.country ?? undefined) as CountryCode | undefined\n )\n const international = phoneNumber?.formatInternational() ?? formatted\n const national = phoneNumber?.formatNational() ?? sanitizeDigits(international)\n\n return {\n international,\n national,\n formatted,\n phoneNumber,\n detectedCountry,\n }\n}\n\nexport function stripPrefix(value: string, prefix: string) {\n return value.startsWith(prefix) ? value.slice(prefix.length) : value\n}\n\nexport function getLengthIssue(value: string, country: CountryCode | undefined): LengthIssue | null {\n if (!country || !value) {\n return null\n }\n\n try {\n const result = validatePhoneNumberLength(value, country)\n return result === \"TOO_LONG\" ? \"TOO_LONG\" : null\n } catch {\n return null\n }\n}\n"],"names":["sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","GG","JE","IM","canonicalizeDetectedCountry","candidate","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","undefined","formatter","AsYouType","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","validatePhoneNumberLength"],"mappings":";;AAMO,SAASA,EAAeC,GAAe;AAC5C,SAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,MAAMC,IAAwE;AAAA,EAC5EC,IAAI;AAAA,EACJC,IAAI;AAAA,EACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;AAChG,MAAKA;AAGL,WAAOL,EAA2BK,CAAS,KAAKA;AAClD;AAEO,SAASC,EAAoBR,GAAeS,GAA2B;AAC5E,MAAIT,MAAU;AACZ,WAAO;AAAA,MACLU,eAAe;AAAA,MACfC,UAAU;AAAA,MACVC,WAAW;AAAA,MACXC,aAAa;AAAA,MACbC,iBAAiBC;AAAAA,IAAAA;AAIrB,QAAMC,IAAYP,IAAc,IAAIQ,EAAUR,CAAW,IAAI,IAAIQ,EAAAA,GAC3DL,IAAYI,EAAUE,MAAMlB,CAAK,GACjCa,IAAcG,EAAUG,UAAAA,GACxBL,IAAkBR,EACrBO,GAAaO,WAAWJ,EAAUI,WAAWL,MAChD,GACML,IAAgBG,GAAaQ,oBAAAA,KAAyBT,GACtDD,IAAWE,GAAaS,eAAAA,KAAoBvB,EAAeW,CAAa;AAE9E,SAAO;AAAA,IACLA,eAAAA;AAAAA,IACAC,UAAAA;AAAAA,IACAC,WAAAA;AAAAA,IACAC,aAAAA;AAAAA,IACAC,iBAAAA;AAAAA,EAAAA;AAEJ;AAEO,SAASS,EAAYvB,GAAewB,GAAgB;AACzD,SAAOxB,EAAMyB,WAAWD,CAAM,IAAIxB,EAAM0B,MAAMF,EAAOG,MAAM,IAAI3B;AACjE;AAEO,SAAS4B,EAAe5B,GAAeoB,GAAsD;AAClG,MAAI,CAACA,KAAW,CAACpB;AACf,WAAO;AAGT,MAAI;AAEF,WADe6B,EAA0B7B,GAAOoB,CAAO,MACrC,aAAa,aAAa;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;"}
package/dist/index46.js CHANGED
@@ -1,130 +1,94 @@
1
- import { j as l } from "./index28.js";
2
- import { c as M } from "./index29.js";
3
- import * as v from "react";
4
- import { cn as L } from "./index2.js";
5
- const P = v.createContext(null);
6
- function T(t, e) {
7
- if (typeof t == "function") {
8
- t(e);
9
- return;
1
+ function c(t) {
2
+ if (!t)
3
+ return !1;
4
+ const e = t.charCodeAt(0);
5
+ return e >= 48 && e <= 57;
6
+ }
7
+ function l(t, e) {
8
+ let n = 0;
9
+ const r = Math.min(e, t.length);
10
+ for (let i = 0; i < r; i += 1)
11
+ c(t[i] ?? "") && (n += 1);
12
+ return n;
13
+ }
14
+ function a(t, e) {
15
+ if (e <= 0)
16
+ return t.startsWith("+") ? Math.min(1, t.length) : 0;
17
+ let n = 0;
18
+ for (let r = 0; r < t.length; r += 1)
19
+ if (c(t[r] ?? "") && (n += 1, n === e))
20
+ return r + 1;
21
+ return t.length;
22
+ }
23
+ function g(t) {
24
+ return !t || c(t) ? !1 : t !== "+";
25
+ }
26
+ function h(t, e) {
27
+ let n = e;
28
+ for (; n > 0; ) {
29
+ const r = t[n - 1] ?? "";
30
+ if (!g(r))
31
+ break;
32
+ n -= 1;
10
33
  }
11
- t && typeof t == "object" && Reflect.set(t, "current", e);
34
+ return n;
12
35
  }
13
- const V = (t) => {
14
- const e = M.c(30), n = v.useContext(P), o = n?.highlightedValue === t.data.value;
15
- let i, r, s;
16
- e[0] !== t.innerProps ? ({
17
- onMouseMove: i,
18
- className: r,
19
- ...s
20
- } = t.innerProps, e[0] = t.innerProps, e[1] = i, e[2] = r, e[3] = s) : (i = e[1], r = e[2], s = e[3]);
21
- let f;
22
- e[4] !== n?.renderOptionLabel ? (f = n?.renderOptionLabel ?? z, e[4] = n?.renderOptionLabel, e[5] = f) : f = e[5];
23
- const b = f, w = v.useRef(null), {
24
- innerRef: S
25
- } = t;
26
- let m;
27
- e[6] !== S ? (m = (c) => {
28
- w.current = c, T(S, c);
29
- }, e[6] = S, e[7] = m) : m = e[7];
30
- const j = m;
31
- let g;
32
- e[8] !== n?.consumeScrollBehavior || e[9] !== o ? (g = () => {
33
- if (!o)
34
- return;
35
- const c = n?.consumeScrollBehavior, H = c ? c() : "smooth", d = w.current;
36
- if (!d)
37
- return;
38
- const C = d.parentElement;
39
- if (!C)
40
- return;
41
- const N = d.offsetTop, B = N + d.offsetHeight, O = C.scrollTop, E = O + C.clientHeight;
42
- N >= O && B <= E || d.scrollIntoView({
43
- block: "nearest",
44
- behavior: H
45
- });
46
- }, e[8] = n?.consumeScrollBehavior, e[9] = o, e[10] = g) : g = e[10];
47
- let h;
48
- e[11] !== n || e[12] !== o ? (h = [n, o], e[11] = n, e[12] = o, e[13] = h) : h = e[13], v.useEffect(g, h);
49
- let p;
50
- e[14] !== n || e[15] !== i || e[16] !== t.data ? (p = (c) => {
51
- i?.(c), n?.setHighlightedOption(t.data);
52
- }, e[14] = n, e[15] = i, e[16] = t.data, e[17] = p) : p = e[17];
53
- const R = p, y = o ? "bg-muted text-foreground" : "text-foreground hover:bg-muted";
54
- let a;
55
- e[18] !== r || e[19] !== y ? (a = L("flex cursor-pointer items-center justify-between gap-3 px-3 py-2 text-sm", r, y), e[18] = r, e[19] = y, e[20] = a) : a = e[20];
56
- let u;
57
- e[21] !== t.data || e[22] !== b ? (u = b(t.data), e[21] = t.data, e[22] = b, e[23] = u) : u = e[23];
58
- let x;
59
- return e[24] !== j || e[25] !== R || e[26] !== s || e[27] !== a || e[28] !== u ? (x = /* @__PURE__ */ l.jsx("div", { ref: j, ...s, onMouseMove: R, className: a, children: u }), e[24] = j, e[25] = R, e[26] = s, e[27] = a, e[28] = u, e[29] = x) : x = e[29], x;
60
- }, $ = {
61
- control: () => ({
62
- display: "none"
63
- }),
64
- menu: (t) => ({
65
- ...t,
66
- marginTop: 4,
67
- borderRadius: "var(--radius)",
68
- boxShadow: "0 18px 36px rgba(15, 23, 42, 0.18)",
69
- backgroundColor: "hsl(var(--popover))",
70
- overflow: "hidden",
71
- zIndex: 20
72
- }),
73
- menuList: (t) => ({
74
- ...t,
75
- maxHeight: 240,
76
- padding: 0
77
- }),
78
- option: (t, e) => ({
79
- ...t,
80
- fontSize: "0.875rem",
81
- backgroundColor: e.isFocused ? "hsl(var(--muted))" : e.isSelected ? "hsl(var(--accent))" : "transparent",
82
- color: e.isSelected ? "hsl(var(--accent-foreground))" : "hsl(var(--foreground))",
83
- cursor: "pointer"
84
- }),
85
- noOptionsMessage: (t) => ({
86
- ...t,
87
- fontSize: "0.875rem",
88
- color: "hsl(var(--muted-foreground))"
89
- })
90
- }, A = (t) => {
91
- const e = M.c(5), {
92
- children: n,
93
- innerProps: o,
94
- innerRef: i
95
- } = t;
96
- let r;
97
- e[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (r = {
98
- height: 0,
99
- minHeight: 0,
100
- opacity: 0,
101
- overflow: "hidden",
102
- pointerEvents: "none"
103
- }, e[0] = r) : r = e[0];
104
- let s;
105
- return e[1] !== n || e[2] !== o || e[3] !== i ? (s = /* @__PURE__ */ l.jsx("div", { ...o, ref: i, style: r, children: n }), e[1] = n, e[2] = o, e[3] = i, e[4] = s) : s = e[4], s;
106
- }, q = () => null;
107
- function k(t) {
108
- return /* @__PURE__ */ l.jsxs(l.Fragment, { children: [
109
- /* @__PURE__ */ l.jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
110
- t.flag ? /* @__PURE__ */ l.jsx("span", { "aria-hidden": "true", className: "text-lg leading-none", children: t.flag }) : null,
111
- /* @__PURE__ */ l.jsx("span", { className: "truncate", children: t.name })
112
- ] }),
113
- /* @__PURE__ */ l.jsxs("span", { className: "text-xs text-muted-foreground", children: [
114
- "+",
115
- t.dialCode
116
- ] })
117
- ] });
36
+ function S(t, e) {
37
+ let n = e;
38
+ for (; n < t.length; ) {
39
+ const r = t[n] ?? "";
40
+ if (!g(r))
41
+ break;
42
+ n += 1;
43
+ }
44
+ return n;
45
+ }
46
+ function m(t) {
47
+ const {
48
+ value: e
49
+ } = t, n = t.selectionStart ?? e.length, r = t.selectionEnd ?? n, i = n <= 1 && e.startsWith("+"), o = r <= 1 && e.startsWith("+");
50
+ return {
51
+ selectionStart: n,
52
+ selectionEnd: r,
53
+ startDigits: l(e, n),
54
+ endDigits: l(e, r),
55
+ preserveStartIndex: i,
56
+ preserveEndIndex: o,
57
+ wasAtStart: n === 0,
58
+ wasAtEnd: r === e.length
59
+ };
118
60
  }
119
- function z(t) {
120
- return k(t);
61
+ function u(t, e) {
62
+ if (t.selectionStart === t.selectionEnd) {
63
+ if (t.wasAtEnd) {
64
+ const f = e.length;
65
+ return {
66
+ start: f,
67
+ end: f
68
+ };
69
+ }
70
+ if (t.wasAtStart)
71
+ return {
72
+ start: 0,
73
+ end: 0
74
+ };
75
+ }
76
+ const n = t.preserveStartIndex ? Math.min(t.selectionStart, e.length) : a(e, t.startDigits), r = t.preserveEndIndex ? Math.min(t.selectionEnd, e.length) : a(e, t.endDigits);
77
+ let i = n, o = r;
78
+ t.wasAtStart && (i = 0), t.wasAtEnd && (o = e.length), t.selectionStart === t.selectionEnd && (i = o);
79
+ const d = Math.min(Math.max(i, 0), e.length), s = Math.min(Math.max(o, 0), e.length);
80
+ return d > s ? {
81
+ start: s,
82
+ end: s
83
+ } : {
84
+ start: d,
85
+ end: s
86
+ };
121
87
  }
122
88
  export {
123
- A as HiddenControl,
124
- q as NullComponent,
125
- P as SuggestionContext,
126
- V as SuggestionOption,
127
- k as formatCountryOption,
128
- $ as suggestionSelectStyles
89
+ m as captureSelectionSnapshot,
90
+ u as resolveSelection,
91
+ h as skipFormattingCharactersLeft,
92
+ S as skipFormattingCharactersRight
129
93
  };
130
94
  //# sourceMappingURL=index46.js.map