@rpcbase/ui 0.261.0 → 0.263.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 (261) hide show
  1. package/dist/assets/sha256.worker-BEf4_Y9w.js.map +1 -0
  2. package/dist/components/FilesUploadField/index.d.ts +19 -6
  3. package/dist/components/FilesUploadField/index.d.ts.map +1 -1
  4. package/dist/components/FilesUploadField/sha256.d.ts +5 -0
  5. package/dist/components/FilesUploadField/sha256.d.ts.map +1 -0
  6. package/dist/components/FilesUploadField/sha256.worker.d.ts +4 -0
  7. package/dist/components/FilesUploadField/sha256.worker.d.ts.map +1 -0
  8. package/dist/components/ImagesField/index.d.ts +4 -2
  9. package/dist/components/ImagesField/index.d.ts.map +1 -1
  10. package/dist/index.js +10 -10
  11. package/dist/index298.js +11 -803
  12. package/dist/index298.js.map +1 -1
  13. package/dist/index299.js +865 -28
  14. package/dist/index299.js.map +1 -1
  15. package/dist/index300.js +26 -510
  16. package/dist/index300.js.map +1 -1
  17. package/dist/index301.js +481 -755
  18. package/dist/index301.js.map +1 -1
  19. package/dist/index302.js +786 -7428
  20. package/dist/index302.js.map +1 -1
  21. package/dist/index303.js +7429 -7
  22. package/dist/index303.js.map +1 -1
  23. package/dist/index304.js +6 -12
  24. package/dist/index304.js.map +1 -1
  25. package/dist/index305.js +12 -5
  26. package/dist/index305.js.map +1 -1
  27. package/dist/index306.js +3 -3
  28. package/dist/index306.js.map +1 -1
  29. package/dist/index307.js +5 -469
  30. package/dist/index307.js.map +1 -1
  31. package/dist/index308.js +464 -32
  32. package/dist/index308.js.map +1 -1
  33. package/dist/index309.js +36 -18
  34. package/dist/index309.js.map +1 -1
  35. package/dist/index310.js +17 -28
  36. package/dist/index310.js.map +1 -1
  37. package/dist/index311.js +30 -4
  38. package/dist/index311.js.map +1 -1
  39. package/dist/index312.js +4 -59
  40. package/dist/index312.js.map +1 -1
  41. package/dist/index313.js +59 -9
  42. package/dist/index313.js.map +1 -1
  43. package/dist/index314.js +9 -5
  44. package/dist/index314.js.map +1 -1
  45. package/dist/index315.js +5 -9
  46. package/dist/index315.js.map +1 -1
  47. package/dist/index316.js +9 -12
  48. package/dist/index316.js.map +1 -1
  49. package/dist/index317.js +13 -3
  50. package/dist/index317.js.map +1 -1
  51. package/dist/index318.js +3 -17
  52. package/dist/index318.js.map +1 -1
  53. package/dist/index319.js +14 -23
  54. package/dist/index319.js.map +1 -1
  55. package/dist/index320.js +23 -39
  56. package/dist/index320.js.map +1 -1
  57. package/dist/index321.js +41 -5
  58. package/dist/index321.js.map +1 -1
  59. package/dist/index322.js +5 -25
  60. package/dist/index322.js.map +1 -1
  61. package/dist/index323.js +24 -18
  62. package/dist/index323.js.map +1 -1
  63. package/dist/index324.js +17 -32
  64. package/dist/index324.js.map +1 -1
  65. package/dist/index325.js +34 -5
  66. package/dist/index325.js.map +1 -1
  67. package/dist/index326.js +5 -9
  68. package/dist/index326.js.map +1 -1
  69. package/dist/index327.js +8 -7
  70. package/dist/index327.js.map +1 -1
  71. package/dist/index328.js +8 -9
  72. package/dist/index328.js.map +1 -1
  73. package/dist/index329.js +9 -10
  74. package/dist/index329.js.map +1 -1
  75. package/dist/index330.js +10 -7
  76. package/dist/index330.js.map +1 -1
  77. package/dist/index331.js +7 -75
  78. package/dist/index331.js.map +1 -1
  79. package/dist/index332.js +66 -153
  80. package/dist/index332.js.map +1 -1
  81. package/dist/index333.js +147 -99
  82. package/dist/index333.js.map +1 -1
  83. package/dist/index334.js +113 -13
  84. package/dist/index334.js.map +1 -1
  85. package/dist/index335.js +12 -78
  86. package/dist/index335.js.map +1 -1
  87. package/dist/index336.js +57 -23
  88. package/dist/index336.js.map +1 -1
  89. package/dist/index337.js +45 -12
  90. package/dist/index337.js.map +1 -1
  91. package/dist/index338.js +13 -16
  92. package/dist/index338.js.map +1 -1
  93. package/dist/index339.js +15 -100
  94. package/dist/index339.js.map +1 -1
  95. package/dist/index340.js +95 -50
  96. package/dist/index340.js.map +1 -1
  97. package/dist/index341.js +5 -57
  98. package/dist/index341.js.map +1 -1
  99. package/dist/index342.js +78 -41
  100. package/dist/index342.js.map +1 -1
  101. package/dist/index343.js +58 -100
  102. package/dist/index343.js.map +1 -1
  103. package/dist/index344.js +104 -46
  104. package/dist/index344.js.map +1 -1
  105. package/dist/index345.js +51 -39
  106. package/dist/index345.js.map +1 -1
  107. package/dist/index346.js +42 -142
  108. package/dist/index346.js.map +1 -1
  109. package/dist/index347.js +123 -120
  110. package/dist/index347.js.map +1 -1
  111. package/dist/index348.js +108 -224
  112. package/dist/index348.js.map +1 -1
  113. package/dist/index349.js +174 -158
  114. package/dist/index349.js.map +1 -1
  115. package/dist/index350.js +144 -213
  116. package/dist/index350.js.map +1 -1
  117. package/dist/index351.js +309 -5
  118. package/dist/index351.js.map +1 -1
  119. package/dist/index352.js +5 -6
  120. package/dist/index352.js.map +1 -1
  121. package/dist/index353.js +6 -7
  122. package/dist/index353.js.map +1 -1
  123. package/dist/index354.js +5 -4
  124. package/dist/index354.js.map +1 -1
  125. package/dist/index355.js +4 -4
  126. package/dist/index355.js.map +1 -1
  127. package/dist/index356.js +6 -21
  128. package/dist/index356.js.map +1 -1
  129. package/dist/index357.js +21 -10
  130. package/dist/index357.js.map +1 -1
  131. package/dist/index358.js +10 -128
  132. package/dist/index358.js.map +1 -1
  133. package/dist/index359.js +122 -36
  134. package/dist/index359.js.map +1 -1
  135. package/dist/index360.js +38 -64
  136. package/dist/index360.js.map +1 -1
  137. package/dist/index361.js +66 -115
  138. package/dist/index361.js.map +1 -1
  139. package/dist/index362.js +112 -485
  140. package/dist/index362.js.map +1 -1
  141. package/dist/index363.js +490 -13
  142. package/dist/index363.js.map +1 -1
  143. package/dist/index364.js +13 -4
  144. package/dist/index364.js.map +1 -1
  145. package/dist/index365.js +4 -47
  146. package/dist/index365.js.map +1 -1
  147. package/dist/index366.js +44 -15
  148. package/dist/index366.js.map +1 -1
  149. package/dist/index367.js +19 -5
  150. package/dist/index367.js.map +1 -1
  151. package/dist/index368.js +5 -27
  152. package/dist/index368.js.map +1 -1
  153. package/dist/index369.js +27 -48
  154. package/dist/index369.js.map +1 -1
  155. package/dist/index370.js +46 -27
  156. package/dist/index370.js.map +1 -1
  157. package/dist/index371.js +27 -16
  158. package/dist/index371.js.map +1 -1
  159. package/dist/index372.js +16 -41
  160. package/dist/index372.js.map +1 -1
  161. package/dist/index373.js +42 -14
  162. package/dist/index373.js.map +1 -1
  163. package/dist/index374.js +14 -10
  164. package/dist/index374.js.map +1 -1
  165. package/dist/index375.js +9 -51
  166. package/dist/index375.js.map +1 -1
  167. package/dist/index376.js +53 -43
  168. package/dist/index376.js.map +1 -1
  169. package/dist/index377.js +43 -16
  170. package/dist/index377.js.map +1 -1
  171. package/dist/index378.js +15 -4
  172. package/dist/index378.js.map +1 -1
  173. package/dist/index379.js +4 -4
  174. package/dist/index379.js.map +1 -1
  175. package/dist/index380.js +4 -9
  176. package/dist/index380.js.map +1 -1
  177. package/dist/index381.js +9 -340
  178. package/dist/index381.js.map +1 -1
  179. package/dist/index382.js +339 -4
  180. package/dist/index382.js.map +1 -1
  181. package/dist/index383.js +5 -16
  182. package/dist/index383.js.map +1 -1
  183. package/dist/index384.js +16 -111
  184. package/dist/index384.js.map +1 -1
  185. package/dist/index385.js +109 -19
  186. package/dist/index385.js.map +1 -1
  187. package/dist/index386.js +18 -18
  188. package/dist/index386.js.map +1 -1
  189. package/dist/index387.js +21 -5
  190. package/dist/index387.js.map +1 -1
  191. package/dist/index388.js +5 -20
  192. package/dist/index388.js.map +1 -1
  193. package/dist/index389.js +19 -13
  194. package/dist/index389.js.map +1 -1
  195. package/dist/index390.js +13 -84
  196. package/dist/index390.js.map +1 -1
  197. package/dist/index391.js +84 -7
  198. package/dist/index391.js.map +1 -1
  199. package/dist/index392.js +9 -29
  200. package/dist/index392.js.map +1 -1
  201. package/dist/index393.js +28 -9
  202. package/dist/index393.js.map +1 -1
  203. package/dist/index394.js +9 -5
  204. package/dist/index394.js.map +1 -1
  205. package/dist/index395.js +6 -252
  206. package/dist/index395.js.map +1 -1
  207. package/dist/index396.js +250 -10
  208. package/dist/index396.js.map +1 -1
  209. package/dist/index397.js +11 -10
  210. package/dist/index397.js.map +1 -1
  211. package/dist/index398.js +10 -6
  212. package/dist/index398.js.map +1 -1
  213. package/dist/index399.js +6 -22
  214. package/dist/index399.js.map +1 -1
  215. package/dist/index400.js +21 -21
  216. package/dist/index400.js.map +1 -1
  217. package/dist/index401.js +21 -107
  218. package/dist/index401.js.map +1 -1
  219. package/dist/index402.js +109 -15
  220. package/dist/index402.js.map +1 -1
  221. package/dist/index403.js +15 -12
  222. package/dist/index403.js.map +1 -1
  223. package/dist/index404.js +10 -8
  224. package/dist/index404.js.map +1 -1
  225. package/dist/index405.js +8 -242
  226. package/dist/index405.js.map +1 -1
  227. package/dist/index406.js +238 -25
  228. package/dist/index406.js.map +1 -1
  229. package/dist/index407.js +29 -51
  230. package/dist/index407.js.map +1 -1
  231. package/dist/index408.js +51 -10
  232. package/dist/index408.js.map +1 -1
  233. package/dist/index409.js +11 -128
  234. package/dist/index409.js.map +1 -1
  235. package/dist/index410.js +124 -35
  236. package/dist/index410.js.map +1 -1
  237. package/dist/index411.js +36 -23
  238. package/dist/index411.js.map +1 -1
  239. package/dist/index412.js +26 -11
  240. package/dist/index412.js.map +1 -1
  241. package/dist/index413.js +11 -23
  242. package/dist/index413.js.map +1 -1
  243. package/dist/index414.js +19 -13
  244. package/dist/index414.js.map +1 -1
  245. package/dist/index415.js +14 -13
  246. package/dist/index415.js.map +1 -1
  247. package/dist/index416.js +14 -322
  248. package/dist/index416.js.map +1 -1
  249. package/dist/index417.js +323 -61
  250. package/dist/index417.js.map +1 -1
  251. package/dist/index418.js +63 -4
  252. package/dist/index418.js.map +1 -1
  253. package/dist/index419.js +4 -28
  254. package/dist/index419.js.map +1 -1
  255. package/dist/index420.js +25 -468
  256. package/dist/index420.js.map +1 -1
  257. package/dist/index421.js +452 -250
  258. package/dist/index421.js.map +1 -1
  259. package/dist/index422.js +272 -0
  260. package/dist/index422.js.map +1 -0
  261. package/package.json +2 -1
package/dist/index358.js CHANGED
@@ -1,132 +1,14 @@
1
- import { getCountryCallingCode as e } from "./index355.js";
2
- import { getCountryList as t } from "./index357.js";
3
- var n = t(), r = /* @__PURE__ */ new Map(), i = "__default_locale__", a = Array.from(new Set(n.map((t) => e(t)))).sort((e, t) => t.length - e.length);
4
- a.reduce((e, t) => Math.max(e, t.length), 0);
5
- var o = [
6
- "0011",
7
- "001",
8
- "011",
9
- "00",
10
- "810"
11
- ];
12
- function s(e) {
13
- return e && n.includes(e) ? e : "US";
14
- }
15
- function c(e) {
16
- if (typeof Intl > "u" || Intl.DisplayNames === void 0) return null;
17
- try {
18
- let t = Array.isArray(e) ? e : e ? [e] : void 0;
19
- return new Intl.DisplayNames(t, { type: "region" });
20
- } catch {
21
- return null;
22
- }
23
- }
24
- function l(t) {
25
- let r = c(t), i = c("en");
26
- return n.map((t) => {
27
- let n = e(t), a = r?.of(t) ?? i?.of(t) ?? t, o = i?.of(t) ?? a, s = x(t), c = Array.from(new Set([
28
- a,
29
- o,
30
- t.toUpperCase(),
31
- t.toLowerCase(),
32
- ...s
33
- ].filter(Boolean)));
34
- return {
35
- value: t,
36
- name: a,
37
- dialCode: n,
38
- label: `${a} (+${n})`,
39
- flag: g(t),
40
- searchableTokens: c,
41
- normalizedSearchableTokens: c.map((e) => y(e))
42
- };
43
- }).sort((e, t) => {
44
- let n = u(e.value), r = u(t.value);
45
- return n === r ? e.name.localeCompare(t.name) : n - r;
46
- });
47
- }
48
- function u(t) {
49
- return t === "US" ? 0 : t === "CA" ? 1 : e(t) === "1" ? 2 : 3;
50
- }
51
- function d(e) {
52
- return e ? Array.isArray(e) ? e.join("\0") : e : i;
53
- }
54
- function f(e) {
55
- if (e !== i) {
56
- if (e.includes("\0")) {
57
- let t = e.split("\0").filter(Boolean);
58
- return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
59
- }
60
- return e;
61
- }
62
- }
63
- function p(e, t) {
64
- let n = r.get(t);
65
- if (n) return n;
66
- let i = l(e);
67
- return r.set(t, i), i;
68
- }
69
- function m(e) {
70
- return {
71
- code: e.value,
72
- name: e.name,
73
- dialCode: e.dialCode,
74
- flag: e.flag
75
- };
76
- }
77
- function h(t) {
78
- return {
79
- code: t,
80
- name: t,
81
- dialCode: e(t),
82
- flag: g(t)
83
- };
84
- }
85
- function g(e) {
86
- let t = e?.toUpperCase();
87
- if (!t || t.length !== 2 || /[^A-Z]/.test(t)) return "";
88
- let n = 127397;
89
- return String.fromCodePoint(t.charCodeAt(0) + n, t.charCodeAt(1) + n);
90
- }
91
- var _ = /[\u0300-\u036f]/g;
92
- function v(e) {
93
- return e.normalize("NFD").replace(_, "");
94
- }
95
- function y(e) {
96
- return v(e).toLowerCase();
97
- }
98
- function b(e, t) {
99
- let n = 2 ** 53 - 1;
100
- for (let r of e) {
101
- let e = r.indexOf(t);
102
- e >= 0 && e < n && (n = e);
103
- }
104
- return n === 2 ** 53 - 1 ? 2 ** 53 - 1 : n;
105
- }
106
- function x(e) {
107
- switch (e) {
108
- case "US": return [
109
- "USA",
110
- "United States",
111
- "America",
112
- "United States of America"
113
- ];
114
- case "GB": return [
115
- "UK",
116
- "United Kingdom",
117
- "Great Britain",
118
- "England"
119
- ];
120
- case "AE": return ["UAE", "United Arab Emirates"];
121
- case "KR": return ["South Korea", "Korea"];
122
- case "CN": return ["China", "PRC"];
123
- case "CD": return ["DRC", "Congo-Kinshasa"];
124
- case "CG": return ["Congo-Brazzaville"];
125
- case "BR": return ["Brazil"];
126
- default: return [];
127
- }
1
+ import { getCountries as e } from "./index355.js";
2
+ //#region src/components/PhoneNumberInput/countries.ts
3
+ var t = /* @__PURE__ */ new Set([
4
+ "IM",
5
+ "GG",
6
+ "JE"
7
+ ]), n = e().filter((e) => !t.has(e));
8
+ function r() {
9
+ return n;
128
10
  }
129
11
  //#endregion
130
- export { o as COMMON_IDD_PREFIXES, a as COUNTRY_DIAL_CODES, h as buildFallbackSelectedCountry, p as getCachedCountryOptions, d as getLocaleCacheKey, s as getValidCountry, y as normalizeSearchValue, b as optionMatchIndex, f as parseLocaleCacheKey, m as toSelectedCountry };
12
+ export { r as getCountryList };
131
13
 
132
14
  //# sourceMappingURL=index358.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index358.js","names":["CountryCode","getCountryCallingCode","CountryOption","PhoneNumberSelectedCountry","getCountryList","DEFAULT_COUNTRY","COUNTRY_OPTIONS","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","sort","a","b","length","MAX_DIAL_CODE_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"],"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"],"mappings":";;AAQA,IAAMM,IAAkBF,EAAe,GAEjCG,oBAAwB,IAAIC,IAA6B,GACzDC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIP,EAAgBQ,KAAKC,MAASd,EAAsBc,CAAI,CAAC,CAAC,CACpE,CAAC,CAACC,MAAMC,GAAGC,MAAMA,EAAEC,SAASF,EAAEE,MAAM;AACAT,EAAmBW,QACpDC,GAAKC,MAASC,KAAKF,IAAIA,GAAKC,EAAKJ,MAAM,GACxC,CACF;AACA,IAAaM,IAAsB;CAAC;CAAQ;CAAO;CAAO;CAAM;AAAK;AAErE,SAAgBC,EAAgBC,GAAgC;CAK9D,OAJKA,KAIErB,EAAgBsB,SAASD,CAAK,IAAIA,IAAAA;AAC3C;AAEA,SAASE,EAAmBC,GAA4B;CACtD,IAAI,OAAOC,OAAS,OAAsBA,KAAKC,iBAAiB,QAC9D,OAAO;CAGT,IAAI;EACF,IAAMC,IAAUtB,MAAMuB,QAAQJ,CAAM,IAAIA,IAASA,IAAS,CAACA,CAAM,IAAIK,KAAAA;EACrE,OAAO,IAAIJ,K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A,SAAgBuC,EAAiBC,GAAkBC,GAAe;CAChE,IAAIC;CACJ,KAAK,IAAMjC,KAAS+B,GAAQ;EAC1B,IAAMK,IAAQpC,EAAMqC,QAAQL,CAAK;EACjC,AAAII,KAAS,KAAKA,IAAQH,MACxBA,IAAOG;CAEX;CACA,OAAOH,kCAA6DA;AACtE;AAEA,SAAS7C,EAAkB/B,GAA6B;CACtD,QAAQA,GAAR;EACA,KAAK,MACH,OAAO;GAAC;GAAO;GAAiB;GAAW;EAA0B;EACvE,KAAK,MACH,OAAO;GAAC;GAAM;GAAkB;GAAiB;EAAS;EAC5D,KAAK,MACH,OAAO,CAAC,OAAO,sBAAsB;EACvC,KAAK,MACH,OAAO,CAAC,eAAe,OAAO;EAChC,KAAK,MACH,OAAO,CAAC,SAAS,KAAK;EACxB,KAAK,MACH,OAAO,CAAC,OAAO,gBAAgB;EACjC,KAAK,MACH,OAAO,CAAC,mBAAmB;EAC7B,KAAK,MACH,OAAO,CAAC,QAAQ;EAClB,SACE,OAAO,CAAA;CACT;AACF"}
1
+ {"version":3,"file":"index358.js","names":["getCountries","CountryCode","EXCLUDED_COUNTRIES","EXCLUDED_SET","Set","FILTERED_COUNTRIES","filter","code","has","getCountryList"],"sources":["../src/components/PhoneNumberInput/countries.ts"],"sourcesContent":["import { getCountries } from \"libphonenumber-js\"\nimport type { CountryCode } from \"libphonenumber-js\"\n\n\nconst EXCLUDED_COUNTRIES: CountryCode[] = [\"IM\", \"GG\", \"JE\"]\nconst EXCLUDED_SET = new Set(EXCLUDED_COUNTRIES)\n\nconst FILTERED_COUNTRIES = getCountries().filter((code) => !EXCLUDED_SET.has(code))\n\nexport function getCountryList(): CountryCode[] {\n return FILTERED_COUNTRIES\n}\n"],"mappings":";;AAKA,IAAMG,oBAAe,IAAIC,IAAIF;CADc;CAAM;CAAM;AAC1BA,CAAkB,GAEzCG,IAAqBL,EAAa,CAAC,CAACM,QAAQC,MAAS,CAACJ,EAAaK,IAAID,CAAI,CAAC;AAElF,SAAgBE,IAAgC;CAC9C,OAAOJ;AACT"}
package/dist/index359.js CHANGED
@@ -1,46 +1,132 @@
1
- import { validatePhoneNumberLength as e } from "./index352.js";
2
- import { AsYouType as t } from "./index353.js";
3
- //#region src/components/PhoneNumberInput/normalization.ts
4
- function n(e) {
5
- return e.replace(/\D/g, "");
6
- }
7
- var r = {
8
- GG: "GB",
9
- JE: "GB",
10
- IM: "GB"
11
- };
12
- function i(e) {
13
- if (e) return r[e] ?? e;
14
- }
15
- function a(e, r) {
16
- if (e === "+") return {
17
- international: "+",
18
- national: "",
19
- formatted: "+",
20
- phoneNumber: null,
21
- detectedCountry: void 0
1
+ import { getCountryCallingCode as e } from "./index356.js";
2
+ import { getCountryList as t } from "./index358.js";
3
+ var n = t(), r = /* @__PURE__ */ new Map(), i = "__default_locale__", a = Array.from(new Set(n.map((t) => e(t)))).sort((e, t) => t.length - e.length);
4
+ a.reduce((e, t) => Math.max(e, t.length), 0);
5
+ var o = [
6
+ "0011",
7
+ "001",
8
+ "011",
9
+ "00",
10
+ "810"
11
+ ];
12
+ function s(e) {
13
+ return e && n.includes(e) ? e : "US";
14
+ }
15
+ function c(e) {
16
+ if (typeof Intl > "u" || Intl.DisplayNames === void 0) return null;
17
+ try {
18
+ let t = Array.isArray(e) ? e : e ? [e] : void 0;
19
+ return new Intl.DisplayNames(t, { type: "region" });
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+ function l(t) {
25
+ let r = c(t), i = c("en");
26
+ return n.map((t) => {
27
+ let n = e(t), a = r?.of(t) ?? i?.of(t) ?? t, o = i?.of(t) ?? a, s = x(t), c = Array.from(new Set([
28
+ a,
29
+ o,
30
+ t.toUpperCase(),
31
+ t.toLowerCase(),
32
+ ...s
33
+ ].filter(Boolean)));
34
+ return {
35
+ value: t,
36
+ name: a,
37
+ dialCode: n,
38
+ label: `${a} (+${n})`,
39
+ flag: g(t),
40
+ searchableTokens: c,
41
+ normalizedSearchableTokens: c.map((e) => y(e))
42
+ };
43
+ }).sort((e, t) => {
44
+ let n = u(e.value), r = u(t.value);
45
+ return n === r ? e.name.localeCompare(t.name) : n - r;
46
+ });
47
+ }
48
+ function u(t) {
49
+ return t === "US" ? 0 : t === "CA" ? 1 : e(t) === "1" ? 2 : 3;
50
+ }
51
+ function d(e) {
52
+ return e ? Array.isArray(e) ? e.join("\0") : e : i;
53
+ }
54
+ function f(e) {
55
+ if (e !== i) {
56
+ if (e.includes("\0")) {
57
+ let t = e.split("\0").filter(Boolean);
58
+ return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
59
+ }
60
+ return e;
61
+ }
62
+ }
63
+ function p(e, t) {
64
+ let n = r.get(t);
65
+ if (n) return n;
66
+ let i = l(e);
67
+ return r.set(t, i), i;
68
+ }
69
+ function m(e) {
70
+ return {
71
+ code: e.value,
72
+ name: e.name,
73
+ dialCode: e.dialCode,
74
+ flag: e.flag
22
75
  };
23
- let a = r ? new t(r) : new t(), o = a.input(e), s = a.getNumber(), c = i(s?.country ?? a.country ?? void 0), l = s?.formatInternational() ?? o;
76
+ }
77
+ function h(t) {
24
78
  return {
25
- international: l,
26
- national: s?.formatNational() ?? n(l),
27
- formatted: o,
28
- phoneNumber: s,
29
- detectedCountry: c
79
+ code: t,
80
+ name: t,
81
+ dialCode: e(t),
82
+ flag: g(t)
30
83
  };
31
84
  }
32
- function o(e, t) {
33
- return e.startsWith(t) ? e.slice(t.length) : e;
85
+ function g(e) {
86
+ let t = e?.toUpperCase();
87
+ if (!t || t.length !== 2 || /[^A-Z]/.test(t)) return "";
88
+ let n = 127397;
89
+ return String.fromCodePoint(t.charCodeAt(0) + n, t.charCodeAt(1) + n);
34
90
  }
35
- function s(t, n) {
36
- if (!n || !t) return null;
37
- try {
38
- return e(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
39
- } catch {
40
- return null;
91
+ var _ = /[\u0300-\u036f]/g;
92
+ function v(e) {
93
+ return e.normalize("NFD").replace(_, "");
94
+ }
95
+ function y(e) {
96
+ return v(e).toLowerCase();
97
+ }
98
+ function b(e, t) {
99
+ let n = 2 ** 53 - 1;
100
+ for (let r of e) {
101
+ let e = r.indexOf(t);
102
+ e >= 0 && e < n && (n = e);
103
+ }
104
+ return n === 2 ** 53 - 1 ? 2 ** 53 - 1 : n;
105
+ }
106
+ function x(e) {
107
+ switch (e) {
108
+ case "US": return [
109
+ "USA",
110
+ "United States",
111
+ "America",
112
+ "United States of America"
113
+ ];
114
+ case "GB": return [
115
+ "UK",
116
+ "United Kingdom",
117
+ "Great Britain",
118
+ "England"
119
+ ];
120
+ case "AE": return ["UAE", "United Arab Emirates"];
121
+ case "KR": return ["South Korea", "Korea"];
122
+ case "CN": return ["China", "PRC"];
123
+ case "CD": return ["DRC", "Congo-Kinshasa"];
124
+ case "CG": return ["Congo-Brazzaville"];
125
+ case "BR": return ["Brazil"];
126
+ default: return [];
41
127
  }
42
128
  }
43
129
  //#endregion
44
- export { a as formatWithAsYouType, s as getLengthIssue, n as sanitizeDigits, o as stripPrefix };
130
+ export { o as COMMON_IDD_PREFIXES, a as COUNTRY_DIAL_CODES, h as buildFallbackSelectedCountry, p as getCachedCountryOptions, d as getLocaleCacheKey, s as getValidCountry, y as normalizeSearchValue, b as optionMatchIndex, f as parseLocaleCacheKey, m as toSelectedCountry };
45
131
 
46
132
  //# sourceMappingURL=index359.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index359.js","names":["CountryCode","AsYouType","validatePhoneNumberLength","LengthIssue","sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","Partial","Record","GG","JE","IM","canonicalizeDetectedCountry","candidate","undefined","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","formatter","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","result"],"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"],"mappings":";;;AAMA,SAAgBI,EAAeC,GAAe;CAC5C,OAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,IAAMC,IAAwE;CAC5EG,IAAI;CACJC,IAAI;CACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;CAC3FA,OAGL,OAAOP,EAA2BO,MAAcA;AAClD;AAEA,SAAgBE,EAAoBX,GAAeY,GAA2B;CAC5E,IAAIZ,MAAU,KACZ,OAAO;EACLa,eAAe;EACfC,UAAU;EACVC,WAAW;EACXC,aAAa;EACbC,iBAAiBP,KAAAA;CACnB;CAGF,IAAMQ,IAAYN,IAAc,IAAIhB,EAAUgB,CAAW,IAAI,IAAIhB,EAAU,GACrEmB,IAAYG,EAAUC,MAAMnB,CAAK,GACjCgB,IAAcE,EAAUE,UAAU,GAClCH,IAAkBT,EACrBQ,GAAaK,WAAWH,EAAUG,WAAWX,KAAAA,CAChD,GACMG,IAAgBG,GAAaM,oBAAoB,KAAKP;CAG5D,OAAO;EACLF;EACAC,UAJeE,GAAaO,eAAe,KAAKxB,EAAec,CAAa;EAK5EE;EACAC;EACAC;CACF;AACF;AAEA,SAAgBO,EAAYxB,GAAeyB,GAAgB;CACzD,OAAOzB,EAAM0B,WAAWD,CAAM,IAAIzB,EAAM2B,MAAMF,EAAOG,MAAM,IAAI5B;AACjE;AAEA,SAAgB6B,EAAe7B,GAAeqB,GAAsD;CAClG,IAAI,CAACA,KAAW,CAACrB,GACf,OAAO;CAGT,IAAI;EAEF,OADeH,EAA0BG,GAAOqB,CACzCS,MAAW,aAAa,aAAa;CAC9C,QAAQ;EACN,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"index359.js","names":["CountryCode","getCountryCallingCode","CountryOption","PhoneNumberSelectedCountry","getCountryList","DEFAULT_COUNTRY","COUNTRY_OPTIONS","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","sort","a","b","length","MAX_DIAL_CODE_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"],"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"],"mappings":";;AAQA,IAAMM,IAAkBF,EAAe,GAEjCG,oBAAwB,IAAIC,IAA6B,GACzDC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIP,EAAgBQ,KAAKC,MAASd,EAAsBc,CAAI,CAA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ection.ts
2
- function e(e) {
3
- if (!e) return !1;
4
- let t = e.charCodeAt(0);
5
- return t >= 48 && t <= 57;
6
- }
7
- function t(t, n) {
8
- let r = 0, i = Math.min(n, t.length);
9
- for (let n = 0; n < i; n += 1) e(t[n] ?? "") && (r += 1);
10
- return r;
11
- }
12
- function n(t, n) {
13
- if (n <= 0) return t.startsWith("+") ? Math.min(1, t.length) : 0;
14
- let r = 0;
15
- for (let i = 0; i < t.length; i += 1) if (e(t[i] ?? "") && (r += 1, r === n)) return i + 1;
16
- return t.length;
17
- }
18
- function r(t) {
19
- return !t || e(t) ? !1 : t !== "+";
20
- }
21
- function i(e, t) {
22
- let n = t;
23
- for (; n > 0 && r(e[n - 1] ?? "");) --n;
24
- return n;
25
- }
26
- function a(e, t) {
27
- let n = t;
28
- for (; n < e.length && r(e[n] ?? "");) n += 1;
29
- return n;
30
- }
31
- function o(e) {
32
- let { value: n } = e, r = e.selectionStart ?? n.length, i = e.selectionEnd ?? r, a = r <= 1 && n.startsWith("+"), o = i <= 1 && n.startsWith("+");
1
+ import { validatePhoneNumberLength as e } from "./index353.js";
2
+ import { AsYouType as t } from "./index354.js";
3
+ //#region src/components/PhoneNumberInput/normalization.ts
4
+ function n(e) {
5
+ return e.replace(/\D/g, "");
6
+ }
7
+ var r = {
8
+ GG: "GB",
9
+ JE: "GB",
10
+ IM: "GB"
11
+ };
12
+ function i(e) {
13
+ if (e) return r[e] ?? e;
14
+ }
15
+ function a(e, r) {
16
+ if (e === "+") return {
17
+ international: "+",
18
+ national: "",
19
+ formatted: "+",
20
+ phoneNumber: null,
21
+ detectedCountry: void 0
22
+ };
23
+ let a = r ? new t(r) : new t(), o = a.input(e), s = a.getNumber(), c = i(s?.country ?? a.country ?? void 0), l = s?.formatInternational() ?? o;
33
24
  return {
34
- selectionStart: r,
35
- selectionEnd: i,
36
- startDigits: t(n, r),
37
- endDigits: t(n, i),
38
- preserveStartIndex: a,
39
- preserveEndIndex: o,
40
- wasAtStart: r === 0,
41
- wasAtEnd: i === n.length
25
+ international: l,
26
+ national: s?.formatNational() ?? n(l),
27
+ formatted: o,
28
+ phoneNumber: s,
29
+ detectedCountry: c
42
30
  };
43
31
  }
44
- function s(e, t) {
45
- if (e.selectionStart === e.selectionEnd) {
46
- if (e.wasAtEnd) {
47
- let e = t.length;
48
- return {
49
- start: e,
50
- end: e
51
- };
52
- }
53
- if (e.wasAtStart) return {
54
- start: 0,
55
- end: 0
56
- };
32
+ function o(e, t) {
33
+ return e.startsWith(t) ? e.slice(t.length) : e;
34
+ }
35
+ function s(t, n) {
36
+ if (!n || !t) return null;
37
+ try {
38
+ return e(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
39
+ } catch {
40
+ return null;
57
41
  }
58
- let r = e.preserveStartIndex ? Math.min(e.selectionStart, t.length) : n(t, e.startDigits), i = e.preserveEndIndex ? Math.min(e.selectionEnd, t.length) : n(t, e.endDigits), a = r, o = i;
59
- e.wasAtStart && (a = 0), e.wasAtEnd && (o = t.length), e.selectionStart === e.selectionEnd && (a = o);
60
- let s = Math.min(Math.max(a, 0), t.length), c = Math.min(Math.max(o, 0), t.length);
61
- return s > c ? {
62
- start: c,
63
- end: c
64
- } : {
65
- start: s,
66
- end: c
67
- };
68
42
  }
69
43
  //#endregion
70
- export { o as captureSelectionSnapshot, s as resolveSelection, i as skipFormattingCharactersLeft, a as skipFormattingCharactersRight };
44
+ export { a as formatWithAsYouType, s as getLengthIssue, n as sanitizeDigits, o as stripPrefix };
71
45
 
72
46
  //# sourceMappingURL=index360.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index360.js","names":["isDigitCharacter","char","code","charCodeAt","countDigitsBefore","value","index","count","limit","Math","min","length","position","findIndexForDigitCount","digitCount","startsWith","seen","isFormattingCharacter","skipFormattingCharactersLeft","next","skipFormattingCharactersRight","SelectionSnapshot","selectionStart","selectionEnd","startDigits","endDigits","preserveStartIndex","preserveEndIndex","wasAtStart","wasAtEnd","captureSelectionSnapshot","input","HTMLInputElement","resolveSelection","snapshot","end","start","resolvedStart","resolvedEnd","clampedStart","max","clampedEnd"],"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"],"mappings":";AAAA,SAASA,EAAiBC,GAAc;CACtC,IAAI,CAACA,GACH,OAAO;CAET,IAAMC,IAAOD,EAAKE,WAAW,CAAC;CAC9B,OAAOD,KAAQ,MAAMA,KAAQ;AAC/B;AAEA,SAASE,EAAkBC,GAAeC,GAAe;CACvD,IAAIC,IAAQ,GACNC,IAAQC,KAAKC,IAAIJ,GAAOD,EAAMM,MAAM;CAC1C,KAAK,IAAIC,IAAW,GAAGA,IAAWJ,GAAOI,KAAY,GACnD,AAAIZ,EAAiBK,EAAMO,MAAa,EAAE,MACxCL,KAAS;CAGb,OAAOA;AACT;AAEA,SAASM,EAAuBR,GAAeS,GA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MM;GAClB,OAAO;IAAEyB,OAAOD;IAAKA;GAAI;EAC3B;EACA,IAAID,EAASN,YACX,OAAO;GAAEQ,OAAO;GAAGD,KAAK;EAAE;CAE9B;CAEA,IAAMC,IAAQF,EAASR,qBACnBjB,KAAKC,IAAIwB,EAASZ,gBAAgBjB,EAAMM,MAAM,IAC9CE,EAAuBR,GAAO6B,EAASV,WAAW,GAChDW,IAAMD,EAASP,mBACjBlB,KAAKC,IAAIwB,EAASX,cAAclB,EAAMM,MAAM,IAC5CE,EAAuBR,GAAO6B,EAAST,SAAS,GAEhDY,IAAgBD,GAChBE,IAAcH;CAUlB,AARID,EAASN,eACXS,IAAgB,IAGdH,EAASL,aACXS,IAAcjC,EAAMM,SAGlBuB,EAASZ,mBAAmBY,EAASX,iBACvCc,IAAgBC;CAGlB,IAAMC,IAAe9B,KAAKC,IAAID,KAAK+B,IAAIH,GAAe,CAAC,GAAGhC,EAAMM,MAAM,GAChE8B,IAAahC,KAAKC,IAAID,KAAK+B,IAAIF,GAAa,CAAC,GAAGjC,EAAMM,MAAM;CAMlE,OAJI4B,IAAeE,IACV;EAAEL,OAAOK;EAAYN,KAAKM;CAAW,IAGvC;EAAEL,OAAOG;EAAcJ,KAAKM;CAAW;AAChD"}
1
+ {"version":3,"file":"index360.js","names":["CountryCode","AsYouType","validatePhoneNumberLength","LengthIssue","sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","Partial","Record","GG","JE","IM","canonicalizeDetectedCountry","candidate","undefined","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","formatter","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","result"],"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"],"mappings":";;;AAMA,SAAgBI,EAAeC,GAAe;CAC5C,OAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,IAAMC,IAAwE;CAC5EG,IAAI;CACJC,IAAI;CACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;CAC3FA,OAGL,OAAOP,EAA2BO,MAAcA;AAClD;AAEA,SAAgBE,EAAoBX,GAAeY,GAA2B;CAC5E,IAAIZ,MAAU,KACZ,OAAO;EACLa,eAAe;EACfC,UAAU;EACVC,WAAW;EACXC,aAAa;EACbC,iBAAiBP,KAAAA;CACnB;CAGF,IAAMQ,IAAYN,IAAc,IAAIhB,EAAUgB,CAAW,IAAI,IAAIhB,EAAU,GACrEmB,IAAYG,EAAUC,MAAMnB,CAAK,GACjCgB,IAAcE,EAAUE,UAAU,GAClCH,IAAkBT,EACrBQ,GAAaK,WAAWH,EAAUG,WAAWX,KAAAA,CAChD,GACMG,IAAgBG,GAAaM,oBAAoB,KAAKP;CAG5D,OAAO;EACLF;EACAC,UAJeE,GAAaO,eAAe,KAAKxB,EAAec,CAAa;EAK5EE;EACAC;EACAC;CACF;AACF;AAEA,SAAgBO,EAAYxB,GAAeyB,GAAgB;CACzD,OAAOzB,EAAM0B,WAAWD,CAAM,IAAIzB,EAAM2B,MAAMF,EAAOG,MAAM,IAAI5B;AACjE;AAEA,SAAgB6B,EAAe7B,GAAeqB,GAAsD;CAClG,IAAI,CAACA,KAAW,CAACrB,GACf,OAAO;CAGT,IAAI;EAEF,OADeH,EAA0BG,GAAOqB,CACzCS,MAAW,aAAa,aAAa;CAC9C,QAAQ;EACN,OAAO;CACT;AACF"}