@desource/phone-mask-react 0.3.0 → 1.1.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 (37) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +51 -23
  3. package/dist/esm/components/PhoneInput.d.ts +2 -9
  4. package/dist/esm/components/PhoneInput.d.ts.map +1 -1
  5. package/dist/esm/hooks/internal/useCopyAction.d.ts +14 -0
  6. package/dist/esm/hooks/internal/useCopyAction.d.ts.map +1 -0
  7. package/dist/esm/hooks/internal/useCountry.d.ts +21 -0
  8. package/dist/esm/hooks/internal/useCountry.d.ts.map +1 -0
  9. package/dist/esm/hooks/internal/useCountrySelector.d.ts +32 -0
  10. package/dist/esm/hooks/internal/useCountrySelector.d.ts.map +1 -0
  11. package/dist/esm/hooks/internal/useFormatter.d.ts +45 -0
  12. package/dist/esm/hooks/internal/useFormatter.d.ts.map +1 -0
  13. package/dist/esm/hooks/internal/useInputHandlers.d.ts +21 -0
  14. package/dist/esm/hooks/internal/useInputHandlers.d.ts.map +1 -0
  15. package/dist/esm/hooks/internal/useTheme.d.ts +9 -0
  16. package/dist/esm/hooks/internal/useTheme.d.ts.map +1 -0
  17. package/dist/esm/hooks/internal/useValidationHint.d.ts +6 -0
  18. package/dist/esm/hooks/internal/useValidationHint.d.ts.map +1 -0
  19. package/dist/esm/hooks/usePhoneMask.d.ts +2 -1
  20. package/dist/esm/hooks/usePhoneMask.d.ts.map +1 -1
  21. package/dist/esm/hooks/utility/useClipboard.d.ts +6 -0
  22. package/dist/esm/hooks/utility/useClipboard.d.ts.map +1 -0
  23. package/dist/esm/hooks/utility/useTimer.d.ts +9 -0
  24. package/dist/esm/hooks/utility/useTimer.d.ts.map +1 -0
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/index.js +751 -705
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/types.d.ts +18 -20
  29. package/dist/esm/types.d.ts.map +1 -1
  30. package/dist/phone-mask-react.cjs +1 -1
  31. package/dist/phone-mask-react.cjs.map +1 -1
  32. package/dist/phone-mask-react.css +1 -1
  33. package/package.json +13 -11
  34. package/dist/esm/consts.d.ts +0 -4
  35. package/dist/esm/consts.d.ts.map +0 -1
  36. package/dist/esm/utils.d.ts +0 -16
  37. package/dist/esm/utils.d.ts.map +0 -1
package/dist/esm/index.js CHANGED
@@ -1,531 +1,708 @@
1
- import { jsxs as oe, Fragment as Tt, jsx as v } from "react/jsx-runtime";
2
- import { useRef as W, useState as x, useMemo as Ee, useEffect as B, useCallback as b, useImperativeHandle as Mt } from "react";
3
- import { createPortal as Lt } from "react-dom";
4
- const St = { AC: "+247 #####", AD: ["+376 ### ###", "+376 #### ####"], AE: ["+971 # ### ####", "+971 ## ### ####", "+971 ### ######", "+971 ### # #####"], AF: "+93 ## ### ####", AG: "+1 ###-###-####", AI: "+1 ###-###-####", AL: ["+355 ## ### ###", "+355 ## ### ####", "+355 ### ####", "+355 ### ###", "+355 ### #####"], AM: ["+374 ## ######", "+374 ### ## ###"], AO: "+244 ### ### ###", AR: ["+54 ## ####-####", "+54 # ## ####-####", "+54 ###-###-####"], AS: "+1 ###-###-####", AT: ["+43 # #########", "+43 ### ######"], AU: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###", "+61 ## ### ##"], AW: "+297 ### ####", AX: ["+358 ## #######", "+358 ### ######"], AZ: ["+994 ## ### ## ##", "+994 ### ## ## ##"], BA: ["+387 ## ###-###", "+387 ## ### ###"], BB: "+1 ###-###-####", BD: ["+880 #-#######", "+880 ####-######", "+880 ###-#######"], BE: ["+32 ## ## ## ##", "+32 ### ## ## ##", "+32 ### ## ###"], BF: "+226 ## ## ## ##", BG: ["+359 # ### ###", "+359 ## ### ###", "+359 ### ## ###"], BH: "+973 #### ####", BI: "+257 ## ## ## ##", BJ: ["+229 ## ## ## ## ##", "+229 ## ## ## ##"], BL: "+590 ### ## ## ##", BM: "+1 ###-###-####", BN: "+673 ### ####", BO: ["+591 # #######", "+591 ########", "+591 ### ## ####"], BQ: "+599 ### ####", BR: ["+55 ## ####-####", "+55 ## #####-####", "+55 ### ## ####", "+55 ####-####"], BS: "+1 ###-###-####", BT: ["+975 # ### ###", "+975 ## ## ## ##"], BW: ["+267 ### ####", "+267 ## ### ###", "+267 #### ### ###", "+267 ## #####"], BY: ["+375 ### ##-##-##", "+375 ## ###-##-##", "+375 ### ### ####"], BZ: ["+501 ###-####", "+501 #-###-####-###"], CA: "+1 ###-###-####", CC: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CD: ["+243 ## #####", "+243 ### ### ###"], CF: "+236 ## ## ## ##", CG: ["+242 ## ### ####", "+242 # #### ####"], CH: ["+41 ## ### ## ##", "+41 ### ### ###"], CI: ["+225 ## ## # #####", "+225 ## ## ## ####"], CK: "+682 ## ###", CL: ["+56 ### ### ###", "+56 # #### ####", "+56 ### ### ####", "+56 ## ### ####"], CM: ["+237 # ## ## ## ##", "+237 ## ## ## ##"], CN: ["+86 ## #### ####", "+86 ### #### ####", "+86 ### ### ####", "+86 ########"], CO: ["+57 ### #######", "+57 # ### #######"], CR: ["+506 #### ####", "+506 ###-###-####"], CU: ["+53 # #######", "+53 ### #######"], CV: "+238 ### ## ##", CW: ["+599 # ### ####", "+599 ### ####"], CX: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CY: "+357 ## ######", CZ: "+420 ### ### ###", DE: ["+49 ## ######", "+49 #### #######", "+49 ### ##########", "+49 ### # ######", "+49 ### # ####", "+49 ### #### ####", "+49 ########"], DJ: "+253 ## ## ## ##", DK: "+45 ## ## ## ##", DM: "+1 ###-###-####", DO: "+1 ###-###-####", DZ: ["+213 ## ## ## ##", "+213 ### ## ## ##", "+213 ## ### ## ##"], EC: ["+593 #-###-####", "+593 ## ### ####", "+593 #### ### ####"], EE: ["+372 ### ####", "+372 #### ####", "+372 ## ## ####"], EG: ["+20 # ########", "+20 ## ########", "+20 ### ### ####"], EH: ["+212 # ## ## ## ##", "+212 ##-#######"], ER: "+291 # ### ###", ES: ["+34 ### ## ## ##", "+34 ### ### ###"], ET: "+251 ## ### ####", FI: ["+358 ## #######", "+358 ### ######"], FJ: ["+679 ### ####", "+679 #### ### ####"], FK: "+500 #####", FM: "+691 ### ####", FO: "+298 ######", FR: ["+33 # ## ## ## ##", "+33 ### ## ## ##"], GA: "+241 ## ## ## ##", GB: ["+44 ### ### ####", "+44 #### ######", "+44 ## #### ####"], GD: "+1 ###-###-####", GE: ["+995 ## ### ## ##", "+995 ### ## ## ##", "+995 ### ### ###"], GF: "+594 ### ## ## ##", GG: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], GH: ["+233 ## ### ####", "+233 ### #####"], GI: ["+350 ### #####", "+350 ########"], GL: "+299 ## ## ##", GM: "+220 ### ####", GN: ["+224 ## ## ## ##", "+224 ### ## ## ##"], GP: "+590 ### ## ## ##", GQ: ["+240 ### ### ###", "+240 ### ######"], GR: ["+30 ## #### ####", "+30 ### ### ####"], GT: ["+502 #### ####", "+502 #### ### ####"], GU: "+1 ###-###-####", GW: ["+245 ### ### ###", "+245 ### ####"], GY: "+592 ### ####", HK: ["+852 #### ####", "+852 ### ### ###", "+852 ### ## ### ###"], HN: ["+504 ####-####", "+504 ###########"], HR: ["+385 # #### ###", "+385 ## ### ####", "+385 ### ### ###", "+385 ## ## ###", "+385 ## ### ###"], HT: "+509 ## ## ####", HU: ["+36 # ### ####", "+36 ## ### ####", "+36 ## ### ###"], ID: ["+62 ## #######", "+62 ###-###-###", "+62 ### #######", "+62 ### # ### ###", "+62 ### ### ####"], IE: ["+353 ## #####", "+353 ## ### ####", "+353 #### ### ###", "+353 ### ### ###"], IL: ["+972 #-###-####", "+972 ##-###-####", "+972 #-###-###-###"], IM: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], IN: ["+91 ##### #####", "+91 #### ## ####", "+91 #### ### ### ###", "+91 #### ### ####"], IO: "+246 ### ####", IQ: ["+964 # ### ####", "+964 ### ### ####"], IR: ["+98 ## #### ####", "+98 ### ### ####"], IS: "+354 ### ####", IT: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], JE: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], JM: "+1 ###-###-####", JO: ["+962 # ### ####", "+962 # #### ####", "+962 ### #####", "+962 ## #######"], JP: ["+81 #-####-####", "+81 ##-####-####", "+81 ###-###-###", "+81 ##-###-####"], KE: ["+254 ## #######", "+254 ### ######", "+254 ### ### ###"], KG: ["+996 ### ### ###", "+996 ### ### # ##"], KH: ["+855 ## ### ###", "+855 #### ### ###"], KI: ["+686 #####", "+686 ########"], KM: "+269 ### ## ##", KN: "+1 ###-###-####", KP: ["+850 # ### ####", "+850 ### ### ####"], KR: ["+82 #-###-####", "+82 ##-####-####", "+82 ##-###-####"], KW: ["+965 #### ####", "+965 ### #####", "+965 #### ###"], KY: "+1 ###-###-####", KZ: ["+7 ##### # ## ##", "+7 ### ### ####", "+7 ### ###-##-##"], LA: ["+856 ## ### ###", "+856 ## ## ### ###"], LB: ["+961 # ### ###", "+961 ## ### ###"], LC: "+1 ###-###-####", LI: ["+423 ### ## ##", "+423 ### ### ###"], LK: ["+94 ### ### ###", "+94 ## ### ####"], LR: ["+231 ## ### ###", "+231 ## ### ####"], LS: "+266 #### ####", LT: ["+370 ### #####", "+370 ### ## ###"], LU: ["+352 ## ## ## ##", "+352 ### ### ###", "+352 ### ## ###"], LV: "+371 ## ### ###", LY: "+218 ##-#######", MA: ["+212 # ## ## ## ##", "+212 ##-#######"], MC: ["+377 ## ## ## ##", "+377 # ## ## ## ##"], MD: ["+373 ## ### ###", "+373 ### ## ###", "+373 ### #####"], ME: "+382 ## ### ###", MF: "+590 ### ## ## ##", MG: "+261 ## ## ### ##", MH: "+692 ###-####", MK: ["+389 # ### ####", "+389 ## ### ###", "+389 ### # ## ##"], ML: "+223 ## ## ## ##", MM: ["+95 # ### ###", "+95 # ### ####", "+95 ### ### ####"], MN: "+976 #### ####", MO: ["+853 #### ####", "+853 #### ###"], MP: "+1 ###-###-####", MQ: "+596 ### ## ## ##", MR: "+222 ## ## ## ##", MS: "+1 ###-###-####", MT: "+356 #### ####", MU: ["+230 #### ####", "+230 ### ####"], MV: ["+960 ###-####", "+960 ### ### ####"], MW: ["+265 # ### ###", "+265 ### ## ## ##"], MX: "+52 ### ### ####", MY: ["+60 #-#### ####", "+60 ##-### ####", "+60 #-###-##-####", "+60 ###-### ####"], MZ: ["+258 ## ### ###", "+258 ## ### ####", "+258 ### ### ###"], NA: ["+264 ## ### ###", "+264 ## ### ####", "+264 ### ### ###"], NC: "+687 ##.##.##", NE: ["+227 ## ## ## ##", "+227 ## ### ###"], NF: ["+672 ## ####", "+672 # #####"], NG: ["+234 #### ## ####", "+234 ### ### ####", "+234 ### #### ####"], NI: "+505 #### ####", NL: ["+31 ## ### ####", "+31 # ########", "+31 ### ####", "+31 ## #######"], NO: ["+47 ## ## ## ##", "+47 ### ## ###"], NP: ["+977 #-#######", "+977 ###-#######", "+977 ###########"], NR: "+674 ### ####", NU: ["+683 ####", "+683 ### ####"], NZ: ["+64 # ### ####", "+64 ## ### ####", "+64 ### ### ###"], OM: ["+968 ## ######", "+968 #### ####", "+968 ### #####"], PA: ["+507 ###-####", "+507 ####-####"], PE: ["+51 # #######", "+51 ### ### ###", "+51 ### #####"], PF: ["+689 ## ## ## ##", "+689 ### ## ## ##"], PG: ["+675 ### ####", "+675 #### ####"], PH: ["+63 # #### ####", "+63 ### ### ####", "+63 #### # ### ####"], PK: ["+92 ## ########", "+92 ### #######", "+92 ### ### ##", "+92 #### #####"], PL: ["+48 ## ### ## ##", "+48 ### ### ###"], PM: ["+508 ## ## ##", "+508 ### ## ## ##"], PR: "+1 ###-###-####", PS: ["+970 # ### ####", "+970 ### ### ###", "+970 #### ### ###"], PT: ["+351 ## ### ####", "+351 ### ### ###"], PW: "+680 ### ####", PY: ["+595 ## ### ####", "+595 ### ######", "+595 #### ### ####"], QA: ["+974 #### ####", "+974 ### ####"], RE: "+262 ### ## ## ##", RO: ["+40 ## ### ####", "+40 ### ### ###"], RS: ["+381 ## ######", "+381 ## #######", "+381 ### #####"], RU: "+7 ### ###-##-##", RW: "+250 ### ### ###", SA: ["+966 ## ### ####", "+966 ### ### ####", "+966 #### #####"], SB: ["+677 #####", "+677 ## #####"], SC: ["+248 # ### ###", "+248 #######"], SD: "+249 ## ### ####", SE: ["+46 # ## ## ##", "+46 ## ### ## ##", "+46 ## ## ## ##", "+46 ### ## ## ###"], SG: ["+65 #### ####", "+65 #### ### ####"], SH: "+290 #####", SI: ["+386 # ### ## ##", "+386 ## ### ###", "+386 ## ######", "+386 ### #####"], SJ: ["+47 ## ## ## ##", "+47 ### ## ###"], SK: ["+421 #/### ### ##", "+421 ### ### ###", "+421 #######"], SL: "+232 ## ######", SM: ["+378 #### ######", "+378 ## ## ## ##"], SN: ["+221 ## ### ## ##", "+221 ### ## ## ##"], SO: ["+252 # ######", "+252 # #######"], SR: ["+597 ###-###", "+597 ###-####", "+597 ##-##-##"], SS: "+211 ### ### ###", ST: "+239 ### ####", SV: ["+503 #### ####", "+503 ### ####"], SX: "+1 ###-###-####", SY: ["+963 ## ### ####", "+963 ### ### ###"], SZ: ["+268 #### ####", "+268 ##### ####"], TA: "+290 ####", TC: "+1 ###-###-####", TD: "+235 ## ## ## ##", TG: "+228 ## ## ## ##", TH: ["+66 # ### ####", "+66 ## ### ####", "+66 #### ### ###"], TJ: ["+992 ### ## ####", "+992 ## ### ####"], TK: "+690 ####", TL: ["+670 ### ####", "+670 #### ####"], TM: ["+993 ## ##-##-##", "+993 ## ######"], TN: "+216 ## ### ###", TO: ["+676 ##-###", "+676 ### ####", "+676 #### ###"], TR: ["+90 ### ### ## ##", "+90 ### ### ####"], TT: "+1 ###-###-####", TV: ["+688 ## ###", "+688 ## ####"], TW: ["+886 # #### ####", "+886 ### ### ###", "+886 ## ### ####", "+886 ## #### ####"], TZ: ["+255 ## ### ####", "+255 ### ### ###", "+255 ### ## ####"], UA: ["+380 #### #####", "+380 ## ### ####", "+380 ### ### ###"], UG: ["+256 ## #######", "+256 ### ######"], US: "+1 ###-###-####", UY: ["+598 #### ####", "+598 ## ### ###", "+598 ### ####"], UZ: "+998 ## ### ## ##", VA: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], VC: "+1 ###-###-####", VE: "+58 ###-#######", VG: "+1 ###-###-####", VI: "+1 ###-###-####", VN: ["+84 ### #### ###", "+84 ### ### ###", "+84 #### ######", "+84 ## ### ## ##"], VU: ["+678 #####", "+678 ### ####"], WF: ["+681 ## ## ##", "+681 ### ## ## ##"], WS: ["+685 #####", "+685 ## #####", "+685 ### ###"], XK: ["+383 ## ### ###", "+383 ### #####"], YE: ["+967 # ### ###", "+967 ### ### ###"], YT: "+262 ### ## ## ##", ZA: ["+27 ## ### ####", "+27 ### ### ###"], ZM: ["+260 ### ### ###", "+260 ## #######", "+260 #########"], ZW: ["+263 ## #####", "+263 ## ### ####", "+263 ### ####", "+263 #### ######"] }, kt = /^[a-z]{2}$/i, me = (e) => {
5
- if (!kt.test(e)) {
6
- const t = typeof e;
7
- throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${t === "string" ? e : t}' instead.`);
1
+ import { jsxs as G, Fragment as Ct, jsx as C } from "react/jsx-runtime";
2
+ import { useMemo as M, useEffect as I, useState as k, useCallback as h, useRef as R, forwardRef as yt, useId as Dt, useImperativeHandle as vt } from "react";
3
+ import { createPortal as wt } from "react-dom";
4
+ const bt = { AC: "+247 #####", AD: ["+376 ### ###", "+376 #### ####"], AE: ["+971 # ### ####", "+971 ## ### ####", "+971 ### ######", "+971 ### # #####"], AF: "+93 ## ### ####", AG: "+1 ###-###-####", AI: "+1 ###-###-####", AL: ["+355 ## ### ###", "+355 ## ### ####", "+355 ### ####", "+355 ### ###", "+355 ### #####"], AM: ["+374 ## ######", "+374 ### ## ###"], AO: "+244 ### ### ###", AR: ["+54 ## ####-####", "+54 # ## ####-####", "+54 ###-###-####"], AS: "+1 ###-###-####", AT: ["+43 # #########", "+43 ### ######"], AU: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###", "+61 ## ### ##"], AW: "+297 ### ####", AX: ["+358 ## #######", "+358 ### ######"], AZ: ["+994 ## ### ## ##", "+994 ### ## ## ##"], BA: ["+387 ## ###-###", "+387 ## ### ###"], BB: "+1 ###-###-####", BD: ["+880 #-#######", "+880 ####-######", "+880 ###-#######"], BE: ["+32 ## ## ## ##", "+32 ### ## ## ##", "+32 ### ## ###"], BF: "+226 ## ## ## ##", BG: ["+359 # ### ###", "+359 ## ### ###", "+359 ### ## ###"], BH: "+973 #### ####", BI: "+257 ## ## ## ##", BJ: ["+229 ## ## ## ## ##", "+229 ## ## ## ##"], BL: "+590 ### ## ## ##", BM: "+1 ###-###-####", BN: "+673 ### ####", BO: ["+591 # #######", "+591 ########", "+591 ### ## ####"], BQ: "+599 ### ####", BR: ["+55 ## ####-####", "+55 ## #####-####", "+55 ### ## ####", "+55 ####-####"], BS: "+1 ###-###-####", BT: ["+975 # ### ###", "+975 ## ## ## ##"], BW: ["+267 ### ####", "+267 ## ### ###", "+267 #### ### ###", "+267 ## #####"], BY: ["+375 ### ##-##-##", "+375 ## ###-##-##", "+375 ### ### ####"], BZ: ["+501 ###-####", "+501 #-###-####-###"], CA: "+1 ###-###-####", CC: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CD: ["+243 ## #####", "+243 ### ### ###"], CF: "+236 ## ## ## ##", CG: ["+242 ## ### ####", "+242 # #### ####"], CH: ["+41 ## ### ## ##", "+41 ### ### ###"], CI: ["+225 ## ## # #####", "+225 ## ## ## ####"], CK: "+682 ## ###", CL: ["+56 ### ### ###", "+56 # #### ####", "+56 ### ### ####", "+56 ## ### ####"], CM: ["+237 # ## ## ## ##", "+237 ## ## ## ##"], CN: ["+86 ## #### ####", "+86 ### #### ####", "+86 ### ### ####", "+86 ########"], CO: ["+57 ### #######", "+57 # ### #######"], CR: ["+506 #### ####", "+506 ###-###-####"], CU: ["+53 # #######", "+53 ### #######"], CV: "+238 ### ## ##", CW: ["+599 # ### ####", "+599 ### ####"], CX: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CY: "+357 ## ######", CZ: "+420 ### ### ###", DE: ["+49 ## ######", "+49 #### #######", "+49 ### ##########", "+49 ### # ######", "+49 ### # ####", "+49 ### #### ####", "+49 ########"], DJ: "+253 ## ## ## ##", DK: "+45 ## ## ## ##", DM: "+1 ###-###-####", DO: "+1 ###-###-####", DZ: ["+213 ## ## ## ##", "+213 ### ## ## ##", "+213 ## ### ## ##"], EC: ["+593 #-###-####", "+593 ## ### ####", "+593 #### ### ####"], EE: ["+372 ### ####", "+372 #### ####", "+372 ## ## ####"], EG: ["+20 # ########", "+20 ## ########", "+20 ### ### ####"], EH: ["+212 # ## ## ## ##", "+212 ##-#######"], ER: "+291 # ### ###", ES: ["+34 ### ## ## ##", "+34 ### ### ###"], ET: "+251 ## ### ####", FI: ["+358 ## #######", "+358 ### ######"], FJ: ["+679 ### ####", "+679 #### ### ####"], FK: "+500 #####", FM: "+691 ### ####", FO: "+298 ######", FR: ["+33 # ## ## ## ##", "+33 ### ## ## ##"], GA: "+241 ## ## ## ##", GB: ["+44 ### ### ####", "+44 #### ######", "+44 ## #### ####"], GD: "+1 ###-###-####", GE: ["+995 ## ### ## ##", "+995 ### ## ## ##", "+995 ### ### ###"], GF: "+594 ### ## ## ##", GG: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], GH: ["+233 ## ### ####", "+233 ### #####"], GI: ["+350 ### #####", "+350 ########"], GL: "+299 ## ## ##", GM: "+220 ### ####", GN: ["+224 ## ## ## ##", "+224 ### ## ## ##"], GP: "+590 ### ## ## ##", GQ: ["+240 ### ### ###", "+240 ### ######"], GR: ["+30 ## #### ####", "+30 ### ### ####"], GT: ["+502 #### ####", "+502 #### ### ####"], GU: "+1 ###-###-####", GW: ["+245 ### ### ###", "+245 ### ####"], GY: "+592 ### ####", HK: ["+852 #### ####", "+852 ### ### ###", "+852 ### ## ### ###"], HN: ["+504 ####-####", "+504 ###########"], HR: ["+385 # #### ###", "+385 ## ### ####", "+385 ### ### ###", "+385 ## ## ###", "+385 ## ### ###"], HT: "+509 ## ## ####", HU: ["+36 # ### ####", "+36 ## ### ####", "+36 ## ### ###"], ID: ["+62 ## #######", "+62 ###-###-###", "+62 ### #######", "+62 ### # ### ###", "+62 ### ### ####"], IE: ["+353 ## #####", "+353 ## ### ####", "+353 #### ### ###", "+353 ### ### ###"], IL: ["+972 #-###-####", "+972 ##-###-####", "+972 #-###-###-###"], IM: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], IN: ["+91 ##### #####", "+91 #### ## ####", "+91 #### ### ### ###", "+91 #### ### ####"], IO: "+246 ### ####", IQ: ["+964 # ### ####", "+964 ### ### ####"], IR: ["+98 ## #### ####", "+98 ### ### ####"], IS: "+354 ### ####", IT: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], JE: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], JM: "+1 ###-###-####", JO: ["+962 # ### ####", "+962 # #### ####", "+962 ### #####", "+962 ## #######"], JP: ["+81 #-####-####", "+81 ##-####-####", "+81 ###-###-###", "+81 ##-###-####"], KE: ["+254 ## #######", "+254 ### ######", "+254 ### ### ###"], KG: ["+996 ### ### ###", "+996 ### ### # ##"], KH: ["+855 ## ### ###", "+855 #### ### ###"], KI: ["+686 #####", "+686 ########"], KM: "+269 ### ## ##", KN: "+1 ###-###-####", KP: ["+850 # ### ####", "+850 ### ### ####"], KR: ["+82 #-###-####", "+82 ##-####-####", "+82 ##-###-####"], KW: ["+965 #### ####", "+965 ### #####", "+965 #### ###"], KY: "+1 ###-###-####", KZ: ["+7 ##### # ## ##", "+7 ### ### ####", "+7 ### ###-##-##"], LA: ["+856 ## ### ###", "+856 ## ## ### ###"], LB: ["+961 # ### ###", "+961 ## ### ###"], LC: "+1 ###-###-####", LI: ["+423 ### ## ##", "+423 ### ### ###"], LK: ["+94 ### ### ###", "+94 ## ### ####"], LR: ["+231 ## ### ###", "+231 ## ### ####"], LS: "+266 #### ####", LT: ["+370 ### #####", "+370 ### ## ###"], LU: ["+352 ## ## ## ##", "+352 ### ### ###", "+352 ### ## ###"], LV: "+371 ## ### ###", LY: "+218 ##-#######", MA: ["+212 # ## ## ## ##", "+212 ##-#######"], MC: ["+377 ## ## ## ##", "+377 # ## ## ## ##"], MD: ["+373 ## ### ###", "+373 ### ## ###", "+373 ### #####"], ME: "+382 ## ### ###", MF: "+590 ### ## ## ##", MG: "+261 ## ## ### ##", MH: "+692 ###-####", MK: ["+389 # ### ####", "+389 ## ### ###", "+389 ### # ## ##"], ML: "+223 ## ## ## ##", MM: ["+95 # ### ###", "+95 # ### ####", "+95 ### ### ####"], MN: "+976 #### ####", MO: ["+853 #### ####", "+853 #### ###"], MP: "+1 ###-###-####", MQ: "+596 ### ## ## ##", MR: "+222 ## ## ## ##", MS: "+1 ###-###-####", MT: "+356 #### ####", MU: ["+230 #### ####", "+230 ### ####"], MV: ["+960 ###-####", "+960 ### ### ####"], MW: ["+265 # ### ###", "+265 ### ## ## ##"], MX: "+52 ### ### ####", MY: ["+60 #-#### ####", "+60 ##-### ####", "+60 #-###-##-####", "+60 ###-### ####"], MZ: ["+258 ## ### ###", "+258 ## ### ####", "+258 ### ### ###"], NA: ["+264 ## ### ###", "+264 ## ### ####", "+264 ### ### ###"], NC: "+687 ##.##.##", NE: ["+227 ## ## ## ##", "+227 ## ### ###"], NF: ["+672 ## ####", "+672 # #####"], NG: ["+234 #### ## ####", "+234 ### ### ####", "+234 ### #### ####"], NI: "+505 #### ####", NL: ["+31 ## ### ####", "+31 # ########", "+31 ### ####", "+31 ## #######"], NO: ["+47 ## ## ## ##", "+47 ### ## ###"], NP: ["+977 #-#######", "+977 ###-#######", "+977 ###########"], NR: "+674 ### ####", NU: ["+683 ####", "+683 ### ####"], NZ: ["+64 # ### ####", "+64 ## ### ####", "+64 ### ### ###"], OM: ["+968 ## ######", "+968 #### ####", "+968 ### #####"], PA: ["+507 ###-####", "+507 ####-####"], PE: ["+51 # #######", "+51 ### ### ###", "+51 ### #####"], PF: ["+689 ## ## ## ##", "+689 ### ## ## ##"], PG: ["+675 ### ####", "+675 #### ####"], PH: ["+63 # #### ####", "+63 ### ### ####", "+63 #### # ### ####"], PK: ["+92 ## ########", "+92 ### #######", "+92 ### ### ##", "+92 #### #####"], PL: ["+48 ## ### ## ##", "+48 ### ### ###"], PM: ["+508 ## ## ##", "+508 ### ## ## ##"], PR: "+1 ###-###-####", PS: ["+970 # ### ####", "+970 ### ### ###", "+970 #### ### ###"], PT: ["+351 ## ### ####", "+351 ### ### ###"], PW: "+680 ### ####", PY: ["+595 ## ### ####", "+595 ### ######", "+595 #### ### ####"], QA: ["+974 #### ####", "+974 ### ####"], RE: "+262 ### ## ## ##", RO: ["+40 ## ### ####", "+40 ### ### ###"], RS: ["+381 ## ######", "+381 ## #######", "+381 ### #####"], RU: "+7 ### ###-##-##", RW: "+250 ### ### ###", SA: ["+966 ## ### ####", "+966 ### ### ####", "+966 #### #####"], SB: ["+677 #####", "+677 ## #####"], SC: ["+248 # ### ###", "+248 #######"], SD: "+249 ## ### ####", SE: ["+46 # ## ## ##", "+46 ## ### ## ##", "+46 ## ## ## ##", "+46 ### ## ## ###"], SG: ["+65 #### ####", "+65 #### ### ####"], SH: "+290 #####", SI: ["+386 # ### ## ##", "+386 ## ### ###", "+386 ## ######", "+386 ### #####"], SJ: ["+47 ## ## ## ##", "+47 ### ## ###"], SK: ["+421 #/### ### ##", "+421 ### ### ###", "+421 #######"], SL: "+232 ## ######", SM: ["+378 #### ######", "+378 ## ## ## ##"], SN: ["+221 ## ### ## ##", "+221 ### ## ## ##"], SO: ["+252 # ######", "+252 # #######"], SR: ["+597 ###-###", "+597 ###-####", "+597 ##-##-##"], SS: "+211 ### ### ###", ST: "+239 ### ####", SV: ["+503 #### ####", "+503 ### ####"], SX: "+1 ###-###-####", SY: ["+963 ## ### ####", "+963 ### ### ###"], SZ: ["+268 #### ####", "+268 ##### ####"], TA: "+290 ####", TC: "+1 ###-###-####", TD: "+235 ## ## ## ##", TG: "+228 ## ## ## ##", TH: ["+66 # ### ####", "+66 ## ### ####", "+66 #### ### ###"], TJ: ["+992 ### ## ####", "+992 ## ### ####"], TK: "+690 ####", TL: ["+670 ### ####", "+670 #### ####"], TM: ["+993 ## ##-##-##", "+993 ## ######"], TN: "+216 ## ### ###", TO: ["+676 ##-###", "+676 ### ####", "+676 #### ###"], TR: ["+90 ### ### ## ##", "+90 ### ### ####"], TT: "+1 ###-###-####", TV: ["+688 ## ###", "+688 ## ####"], TW: ["+886 # #### ####", "+886 ### ### ###", "+886 ## ### ####", "+886 ## #### ####"], TZ: ["+255 ## ### ####", "+255 ### ### ###", "+255 ### ## ####"], UA: ["+380 #### #####", "+380 ## ### ####", "+380 ### ### ###"], UG: ["+256 ## #######", "+256 ### ######"], US: "+1 ###-###-####", UY: ["+598 #### ####", "+598 ## ### ###", "+598 ### ####"], UZ: "+998 ## ### ## ##", VA: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], VC: "+1 ###-###-####", VE: "+58 ###-#######", VG: "+1 ###-###-####", VI: "+1 ###-###-####", VN: ["+84 ### #### ###", "+84 ### ### ###", "+84 #### ######", "+84 ## ### ## ##"], VU: ["+678 #####", "+678 ### ####"], WF: ["+681 ## ## ##", "+681 ### ## ## ##"], WS: ["+685 #####", "+685 ## #####", "+685 ### ###"], XK: ["+383 ## ### ###", "+383 ### #####"], YE: ["+967 # ### ###", "+967 ### ### ###"], YT: "+262 ### ## ## ##", ZA: ["+27 ## ### ####", "+27 ### ### ###"], ZM: ["+260 ### ### ###", "+260 ## #######", "+260 #########"], ZW: ["+263 ## #####", "+263 ## ### ####", "+263 ### ####", "+263 #### ######"] }, It = /^[a-z]{2}$/i, _ = (e) => {
5
+ if (!It.test(e)) {
6
+ const n = typeof e;
7
+ throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${n === "string" ? e : n}' instead.`);
8
8
  }
9
- const r = [...e.toUpperCase()].map((t) => (t.codePointAt(0) ?? 0) + 127397);
10
- return String.fromCodePoint(...r);
11
- }, te = Object.entries(St), et = (e) => e.split(/ (.*)/s);
12
- function se(e) {
13
- let r = "", t = "";
9
+ const t = [...e.toUpperCase()].map((n) => (n.codePointAt(0) ?? 0) + 127397);
10
+ return String.fromCodePoint(...t);
11
+ }, Ce = "en", J = /* @__PURE__ */ new Map(), $e = (e) => {
12
+ const t = e.toLowerCase(), n = J.get(t);
13
+ if (n) return n;
14
+ const r = new Intl.DisplayNames([e], { type: "region" });
15
+ if (J.size >= 10) {
16
+ for (const s of J.keys()) if (s !== Ce) {
17
+ J.delete(s);
18
+ break;
19
+ }
20
+ }
21
+ return J.set(t, r), r;
22
+ }, K = Object.entries(bt), Be = (e) => e.split(/ (.*)/s);
23
+ function U(e) {
24
+ let t = "", n = "";
14
25
  if (Array.isArray(e)) {
15
- const s = [];
16
- for (const f of e) {
17
- const [c, y] = et(f);
18
- r || (r = c), s.push(y);
26
+ const r = [];
27
+ for (const s of e) {
28
+ const [o, i] = Be(s);
29
+ t || (t = o), r.push(i);
19
30
  }
20
- t = s;
31
+ n = r;
21
32
  } else {
22
- const [s, f] = et(e);
23
- r = s, t = f;
33
+ const [r, s] = Be(e);
34
+ t = r, n = s;
24
35
  }
25
- return [r, t];
36
+ return [t, n];
26
37
  }
27
- te.map(([e, r]) => ({ id: e, mask: r }));
28
- te.reduce((e, [r, t]) => {
29
- const [s, f] = se(t);
30
- return e[r] = { code: s, mask: f }, e;
38
+ K.map(([e, t]) => ({ id: e, mask: t }));
39
+ K.reduce((e, [t, n]) => {
40
+ const [r, s] = U(n);
41
+ return e[t] = { code: r, mask: s }, e;
31
42
  }, {});
32
- te.map(([e, r]) => {
33
- const [t, s] = se(r);
34
- return { id: e, code: t, mask: s };
43
+ K.map(([e, t]) => {
44
+ const [n, r] = U(t);
45
+ return { id: e, code: n, mask: r };
35
46
  });
36
- te.reduce((e, [r, t]) => {
37
- const [s, f] = se(t);
38
- return e[r] = { code: s, mask: f, flag: me(r) }, e;
47
+ K.reduce((e, [t, n]) => {
48
+ const [r, s] = U(n);
49
+ return e[t] = { code: r, mask: s, flag: _(t) }, e;
39
50
  }, {});
40
- te.map(([e, r]) => {
41
- const [t, s] = se(r);
42
- return { id: e, code: t, mask: s, flag: me(e) };
51
+ K.map(([e, t]) => {
52
+ const [n, r] = U(t);
53
+ return { id: e, code: n, mask: r, flag: _(e) };
43
54
  });
44
- const bt = (e) => {
45
- const r = new Intl.DisplayNames([e], { type: "region" });
46
- return te.reduce((t, [s, f]) => {
47
- const [c, y] = se(f), d = r.of(s) ?? "";
48
- return t[s] = { code: c, mask: y, name: d, flag: me(s) }, t;
55
+ const Ge = (e) => {
56
+ const t = $e(e);
57
+ return K.reduce((n, [r, s]) => {
58
+ const [o, i] = U(s), a = t.of(r) ?? "";
59
+ return n[r] = { code: o, mask: i, name: a, flag: _(r) }, n;
49
60
  }, {});
50
- }, Et = te.reduce((e, [r, t]) => {
51
- const [s, f] = se(t), c = new Intl.DisplayNames(["en"], { type: "region" });
52
- return e[r] = { code: s, mask: f, name: c.of(r) ?? "", flag: me(r) }, e;
53
- }, {});
54
- te.map(([e, r]) => {
55
- const [t, s] = se(r);
56
- return { id: e, code: t, mask: s, name: new Intl.DisplayNames(["en"], { type: "region" }).of(e) ?? "", flag: me(e) };
57
- });
58
- const Pt = me;
59
- function Ne() {
60
- return typeof navigator < "u" && navigator.language || "en";
61
+ }, Ke = (e) => {
62
+ const t = $e(e);
63
+ return K.map(([n, r]) => {
64
+ const [s, o] = U(r);
65
+ return { id: n, code: s, mask: o, name: t.of(n) ?? "", flag: _(n) };
66
+ });
67
+ }, St = Ge(Ce);
68
+ Ke(Ce);
69
+ const Lt = _;
70
+ function Fe() {
71
+ return globalThis.navigator?.language || "en";
72
+ }
73
+ function Mt() {
74
+ try {
75
+ const e = Fe();
76
+ try {
77
+ const n = new Intl.Locale(e);
78
+ if (n.region) return n.region.toUpperCase();
79
+ } catch {
80
+ }
81
+ const t = e.split(/[-_]/);
82
+ if (t.length > 1) return t[1]?.toUpperCase() || null;
83
+ } catch {
84
+ }
85
+ return null;
86
+ }
87
+ function Tt(e) {
88
+ const t = St;
89
+ return e.toUpperCase() in t;
61
90
  }
62
- function tt(e) {
63
- return e.toLowerCase().startsWith("en") ? Et : bt(e);
91
+ function Et(e, t) {
92
+ const n = Ge(t), r = e.toUpperCase();
93
+ return r in n ? { id: r, ...n[r] } : { id: "US", ...n.US };
64
94
  }
65
- function O(e, r) {
66
- const t = tt(r), s = e.toUpperCase();
67
- return s in t ? { id: s, ...t[s] } : { id: "US", ...t.US };
95
+ function ie(e, t) {
96
+ return e && Tt(e) ? e.toUpperCase() : t || "";
68
97
  }
69
- function nt(e) {
98
+ function Ue(e) {
70
99
  return Array.isArray(e) ? e : [e];
71
100
  }
72
- function Ge(e) {
101
+ function ye(e) {
73
102
  return (e.match(/#/g) || []).length;
74
103
  }
75
- function Ue(e) {
104
+ function ge(e) {
76
105
  return e.replace(/^\+\d+\s?/, "");
77
106
  }
78
- function rt(e, r) {
107
+ function We(e, t) {
108
+ if (!e.length) return "";
79
109
  if (e.length === 1) return e[0];
80
- const t = e.map((c) => ({ mask: c, count: Ge(c) })), s = t.filter((c) => c.count >= r).sort((c, y) => c.count - y.count);
81
- if (s.length > 0) return s[0].mask;
82
- const f = t.sort((c, y) => y.count - c.count)[0];
83
- return f ? f.mask : e[0];
84
- }
85
- function Pe(e, r) {
86
- let t = "";
87
- const s = [];
88
- let f = 0;
89
- const c = r.length, y = e.length;
90
- for (let d = 0; d < y; d++) {
91
- const M = e[d];
92
- if (M === "#") {
93
- if (!(f < c)) break;
94
- t += r[f], s.push(f), f++;
110
+ const n = e.map((o) => ({ mask: o, count: ye(o) })), r = n.filter((o) => o.count >= t).sort((o, i) => o.count - i.count);
111
+ if (r.length > 0) return r[0].mask;
112
+ const s = n.sort((o, i) => i.count - o.count)[0];
113
+ return s ? s.mask : e[0];
114
+ }
115
+ function se(e, t) {
116
+ let n = "";
117
+ const r = [];
118
+ let s = 0;
119
+ const o = t.length, i = e.length;
120
+ for (let a = 0; a < i; a++) {
121
+ const f = e[a];
122
+ if (f === "#") {
123
+ if (!(s < o)) break;
124
+ n += t[s], r.push(s), s++;
95
125
  } else {
96
- const D = e.indexOf("#", d + 1) !== -1 && f < c;
97
- (t.length > 0 || D) && (t += M, s.push(-1));
126
+ const c = e.indexOf("#", a + 1) !== -1 && s < o;
127
+ (n.length > 0 || c) && (n += f, r.push(-1));
98
128
  }
99
129
  }
100
- return { display: t, map: s };
130
+ return { display: n, map: r };
131
+ }
132
+ function kt(e, t) {
133
+ const n = t.trim().toUpperCase();
134
+ if (!n) return e;
135
+ const r = n.replace(/\D/g, ""), s = r.length > 0;
136
+ return e.map((o) => {
137
+ const i = o.name.toUpperCase(), a = o.id.toUpperCase(), f = o.code.toUpperCase(), c = o.code.replace(/\D/g, "");
138
+ let u = 0;
139
+ return i.startsWith(n) ? u = 1e3 : i.includes(n) && (u = 500), f.startsWith(n) ? u += 100 : f.includes(n) && (u += 50), a === n ? u += 200 : a.startsWith(n) && (u += 150), s && c.startsWith(r) ? u += 80 : s && c.includes(r) && (u += 40), { country: o, score: u };
140
+ }).filter((o) => o.score > 0).sort((o, i) => i.score === o.score ? o.country.name.localeCompare(i.country.name) : i.score - o.score).map((o) => o.country);
141
+ }
142
+ const At = [" ", "-", "(", ")"], Nt = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], Pt = /[^\d\s\-()]/;
143
+ function me(e, t, n) {
144
+ return { newDigits: e.slice(0, t) + e.slice(n), caretDigitIndex: t };
101
145
  }
102
- const Nt = "https://ipapi.co/json/", It = 1500, Fe = "@desource/phone-mask:geo", Rt = 864e5;
103
- async function ot(e = Nt, r = It) {
104
- const t = new AbortController(), s = setTimeout(() => t.abort(), r);
146
+ function He(e, t, n, r) {
147
+ if (n === r) return;
148
+ const s = t.getDigitRange(e, n, r);
149
+ if (!s) return;
150
+ const [o, i] = s;
151
+ return me(e, o, i);
152
+ }
153
+ function j(e, t) {
154
+ const n = e.replace(/\D/g, "");
155
+ return t ? n.slice(0, t) : n;
156
+ }
157
+ function Oe(e) {
158
+ return e ? [e.selectionStart ?? 0, e.selectionEnd ?? 0] : [0, 0];
159
+ }
160
+ function xt(e, t) {
161
+ if (e) try {
162
+ e.setSelectionRange(t, t);
163
+ } catch {
164
+ }
165
+ }
166
+ function Bt(e) {
167
+ if (!e.target) return;
168
+ const t = e.target, n = e.data;
169
+ e.inputType === "insertText" && n && (Pt.test(n) || n === " " && t.value.endsWith(" ")) && e.preventDefault();
170
+ }
171
+ function Ht(e, t) {
172
+ if (!e.target) return;
173
+ const n = e.target, { formatter: r } = t, s = r.getMaxDigits(), o = j(n.value, s);
174
+ return { newDigits: o, caretDigitIndex: o.length };
175
+ }
176
+ function Rt(e, t) {
177
+ if (!e.target) return;
178
+ const n = e.target, { digits: r, formatter: s } = t;
179
+ if ((function(c) {
180
+ return c.ctrlKey || c.metaKey || c.altKey || Nt.includes(c.key);
181
+ })(e)) return;
182
+ const [o, i] = Oe(n), a = n.value;
183
+ return e.key === "Backspace" ? (e.preventDefault(), He(r, s, o, i) ?? (function(c, u, l, d) {
184
+ if (d <= 0) return;
185
+ let p = d - 1;
186
+ for (; p >= 0 && At.includes(l[p]); ) p--;
187
+ if (p < 0) return;
188
+ const D = u.getDigitRange(c, p, p + 1);
189
+ if (!D) return;
190
+ const [v] = D;
191
+ return me(c, v, v + 1);
192
+ })(r, s, a, o)) : e.key === "Delete" ? (e.preventDefault(), He(r, s, o, i) ?? (function(c, u, l, d) {
193
+ if (d >= l.length) return;
194
+ const p = u.getDigitRange(c, d, l.length);
195
+ if (!p) return;
196
+ const [D] = p;
197
+ return me(c, D, D + 1);
198
+ })(r, s, a, o)) : void (/^\d$/.test(e.key) ? r.length >= s.getMaxDigits() && e.preventDefault() : e.key.length === 1 && e.preventDefault());
199
+ }
200
+ function Vt(e, t) {
201
+ if (!e.target) return;
202
+ e.preventDefault();
203
+ const n = e.target, { digits: r, formatter: s } = t, o = e.clipboardData?.getData("text") || "", i = s.getMaxDigits(), a = j(o, i);
204
+ if (a.length === 0) return;
205
+ const [f, c] = Oe(n);
206
+ if (f !== c) {
207
+ const d = s.getDigitRange(r, f, c);
208
+ if (d) {
209
+ const [p, D] = d;
210
+ return { newDigits: j(r.slice(0, p) + a + r.slice(D), i), caretDigitIndex: p + a.length };
211
+ }
212
+ }
213
+ const u = s.getDigitRange(r, 0, f), l = u ? u[1] : 0;
214
+ return { newDigits: j(r.slice(0, l) + a + r.slice(l), i), caretDigitIndex: l + a.length };
215
+ }
216
+ function $t(e) {
217
+ const t = Ue(e.mask), n = t.map((o) => ye(ge(o))), r = Math.max(...n), s = (o) => {
218
+ const i = We(t, o);
219
+ return ge(i);
220
+ };
221
+ return { formatDisplay: (o) => {
222
+ const i = s(o.length);
223
+ return se(i, o).display;
224
+ }, getMaxDigits: () => r, getPlaceholder: () => s(0), getCaretPosition: (o) => {
225
+ const i = Math.max(0, o);
226
+ if (i === 0) return 0;
227
+ const a = s(i), { display: f } = se(a, "0".repeat(i));
228
+ return f.length;
229
+ }, getDigitRange: (o, i, a) => {
230
+ const f = s(o.length), { map: c } = se(f, o);
231
+ let u = 1 / 0, l = -1 / 0;
232
+ for (let d = i; d < a && d < c.length; d++) {
233
+ const p = c[d];
234
+ p !== void 0 && p >= 0 && (u = Math.min(u, p), l = Math.max(l, p));
235
+ }
236
+ return u === 1 / 0 ? null : [u, l + 1];
237
+ }, isComplete: (o) => n.includes(o.length) };
238
+ }
239
+ const Gt = "https://ipapi.co/json/", Kt = 1500, he = "@desource/phone-mask:geo", Ft = 864e5;
240
+ async function Ut(e = Gt, t = Kt) {
241
+ const n = new AbortController(), r = setTimeout(() => n.abort(), t);
105
242
  try {
106
- const f = await fetch(e, { signal: t.signal, headers: { Accept: "application/json" } });
107
- if (clearTimeout(s), !f.ok) return null;
108
- const c = await f.json();
109
- return (c.country || c.country_code || c.countryCode || c.country_code2 || "").toString().toUpperCase() || null;
243
+ const s = await fetch(e, { signal: n.signal, headers: { Accept: "application/json" } });
244
+ if (clearTimeout(r), !s.ok) return null;
245
+ const o = await s.json();
246
+ return (o.country || o.country_code || o.countryCode || o.country_code2 || "").toString().toUpperCase() || null;
110
247
  } catch {
111
- return clearTimeout(s), null;
248
+ return clearTimeout(r), null;
112
249
  }
113
250
  }
114
- async function At(e) {
251
+ async function Wt() {
115
252
  try {
116
- const t = localStorage.getItem(Fe);
117
- if (t) {
118
- const s = JSON.parse(t), f = Date.now() - s.ts > Rt;
119
- if (!f && s.country_code && e(s.country_code)) return s.country_code.toUpperCase();
120
- f && localStorage.removeItem(Fe);
253
+ const n = localStorage.getItem(he);
254
+ if (n) {
255
+ const r = JSON.parse(n), s = Date.now() - r.ts > Ft, o = ie(r.country_code);
256
+ if (o && !s) return o;
257
+ localStorage.removeItem(he);
121
258
  }
122
259
  } catch {
123
260
  }
124
- const r = await ot();
125
- if (r && e(r)) {
261
+ const e = await Ut(), t = ie(e);
262
+ if (t) {
126
263
  try {
127
- localStorage.setItem(Fe, JSON.stringify({ country_code: r, ts: Date.now() }));
264
+ const n = JSON.stringify({ country_code: t, ts: Date.now() });
265
+ localStorage.setItem(he, n);
128
266
  } catch {
129
267
  }
130
- return r;
268
+ return t;
131
269
  }
132
270
  return null;
133
271
  }
134
- function He(e) {
135
- const r = nt(e.mask), t = r.map((c) => Ge(Ue(c))), s = Math.max(...t), f = (c) => {
136
- const y = rt(r, c);
137
- return Ue(y);
138
- };
139
- return {
140
- formatDisplay: (c) => {
141
- const y = f(c.length);
142
- return Pe(y, c).display;
143
- },
144
- getMaxDigits: () => s,
145
- getPlaceholder: () => f(0),
146
- getCaretPosition: (c) => {
147
- const y = f(c), { display: d, map: M } = Pe(y, "0".repeat(c));
148
- for (let D = 0; D < M.length; D++)
149
- if (M[D] === c) return D;
150
- if (c >= M.length) return d.length;
151
- for (let D = 0; D < M.length; D++)
152
- if (M[D] > c) return D;
153
- return d.length;
154
- },
155
- getDigitRange: (c, y, d) => {
156
- const M = f(c.length), { map: D } = Pe(M, c);
157
- let $ = 1 / 0, J = -1 / 0;
158
- for (let K = y; K < d && K < D.length; K++) {
159
- const _ = D[K];
160
- _ !== void 0 && _ >= 0 && ($ = Math.min($, _), J = Math.max(J, _));
161
- }
162
- return $ === 1 / 0 ? null : [$, J + 1];
163
- },
164
- isComplete: (c) => t.includes(c.length)
272
+ function Ze({
273
+ country: e,
274
+ value: t,
275
+ onChange: n,
276
+ onPhoneChange: r,
277
+ onValidationChange: s
278
+ }) {
279
+ const o = M(() => $t(e), [e]), i = o.getMaxDigits(), a = M(() => j(t, i), [t, i]), f = o.getPlaceholder(), c = o.formatDisplay(a), u = a ? `${e.code}${a}` : "", l = c ? `${e.code} ${c}` : "", d = o.isComplete(a), p = a.length === 0, D = !p && !d, v = M(() => ({ full: u, fullFormatted: l, digits: a }), [u, l, a]);
280
+ return I(() => {
281
+ t !== a && n(a);
282
+ }, [t, a, n]), I(() => {
283
+ r?.(v);
284
+ }, [v, r]), I(() => {
285
+ s?.(d);
286
+ }, [d, s]), {
287
+ digits: a,
288
+ formatter: o,
289
+ displayPlaceholder: f,
290
+ displayValue: c,
291
+ full: u,
292
+ fullFormatted: l,
293
+ isComplete: d,
294
+ isEmpty: p,
295
+ shouldShowWarn: D
165
296
  };
166
297
  }
167
- function R(e, r) {
168
- if (e)
169
- try {
170
- e.setSelectionRange(r, r);
171
- } catch {
172
- }
298
+ function Ye({
299
+ country: e,
300
+ locale: t,
301
+ detect: n,
302
+ onCountryChange: r
303
+ }) {
304
+ const s = M(() => t || Fe(), [t]), [o, i] = k(ie(e, "US")), a = M(() => Et(o, s), [o, s]), f = !!n && !e, c = h((l) => {
305
+ const d = ie(l);
306
+ return d ? (i(d), !0) : !1;
307
+ }, []), u = h(async () => {
308
+ const l = await Wt();
309
+ if (c(l)) return;
310
+ const d = Mt();
311
+ c(d);
312
+ }, [c]);
313
+ return I(() => {
314
+ e && e !== o && c(e);
315
+ }, [o, e, c]), I(() => {
316
+ f && u();
317
+ }, [f, u]), I(() => {
318
+ r?.(a);
319
+ }, [a, r]), { country: a, setCountry: c, locale: s };
173
320
  }
174
- function j(e, r) {
175
- const t = e.replace(/\D/g, "");
176
- return r ? t.slice(0, r) : t;
321
+ function De() {
322
+ const e = R(null), t = h(() => {
323
+ e.current && (clearTimeout(e.current), e.current = null);
324
+ }, []), n = h(
325
+ (r, s) => {
326
+ t(), e.current = setTimeout(r, s);
327
+ },
328
+ [t]
329
+ );
330
+ return I(() => t, [t]), M(() => ({ set: n, clear: t }), [n, t]);
177
331
  }
178
- function Ie(e) {
179
- return e ? [e.selectionStart ?? 0, e.selectionEnd ?? 0] : [0, 0];
332
+ function Ot() {
333
+ const [e, t] = k(!1), n = De(), r = h(
334
+ (o = !0) => {
335
+ o && t(!1), n.clear();
336
+ },
337
+ [n]
338
+ ), s = h(
339
+ (o) => {
340
+ t(!1), n.set(() => {
341
+ t(!0);
342
+ }, o);
343
+ },
344
+ [n]
345
+ );
346
+ return { showValidationHint: e, clearValidationHint: r, scheduleValidationHint: s };
180
347
  }
181
- const st = [" ", "-", "(", ")"], it = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], at = /[^\d\s\-()]/;
182
- function xt(e) {
183
- const r = tt(e);
184
- return Object.entries(r).map(([t, s]) => ({ id: t, ...s }));
348
+ function re(e) {
349
+ return "nativeEvent" in e ? e.nativeEvent : e;
185
350
  }
186
- const Bt = ({ ref: e, ...r }) => {
187
- const {
188
- value: t = "",
189
- country: s,
190
- detect: f = !0,
191
- locale: c,
192
- size: y = "normal",
193
- theme: d = "auto",
194
- disabled: M = !1,
195
- readonly: D = !1,
196
- showCopy: $ = !0,
197
- showClear: J = !1,
198
- withValidity: K = !0,
199
- searchPlaceholder: _ = "Search country or code...",
200
- noResultsText: Me = "No countries found",
201
- clearButtonLabel: ie = "Clear phone number",
202
- dropdownClass: Le = "",
203
- disableDefaultStyles: Se = !1,
204
- onChange: z,
205
- onPhoneChange: X,
206
- onCountryChange: o,
207
- onValidationChange: m,
208
- onFocus: h,
209
- onBlur: L,
210
- onCopy: T,
211
- onClear: C,
212
- renderActionsBefore: N,
213
- renderFlag: E,
214
- renderCopySvg: F,
215
- renderClearSvg: ae
216
- } = r, U = W(null), he = W(null), Q = W(null), ye = W(null), Ce = W(null), ke = W(null), H = c || Ne(), [I, ce] = x(() => O(s || "US", H)), [g, G] = x(""), [q, $e] = x(!1), [ct, Re] = x(!1), [Ae, Ke] = x(""), [we, le] = x(0), [De, Ve] = x(!1), [We, Oe] = x(!1), [lt, ut] = x({}), [dt, ee] = x(!1), S = W(null), ne = W(null), ue = W(null), [ve, ft] = x(!s), w = Ee(() => He(I), [I]), de = Ee(() => xt(H), [H]), xe = w.formatDisplay(g), pt = w.getPlaceholder(), re = w.isComplete(g), Be = g.length === 0, Ze = dt && !Be && !re, be = `${I.code}${g}`, fe = g ? `${I.code} ${xe}` : "", pe = Ee(() => {
217
- const n = Ae.trim();
218
- if (!n) return de;
219
- const i = n.toUpperCase(), l = i.replace(/\D/g, ""), p = l.length > 0;
220
- return de.map((a) => {
221
- const u = a.name.toUpperCase(), k = a.id.toUpperCase(), P = a.code.toUpperCase(), Y = a.code.replace(/\D/g, "");
222
- let A = 0;
223
- return u.startsWith(i) ? A = 1e3 : u.includes(i) && (A = 500), P.startsWith(i) ? A += 100 : P.includes(i) && (A += 50), k === i ? A += 200 : k.startsWith(i) && (A += 150), p && Y.startsWith(l) ? A += 80 : p && Y.includes(l) && (A += 40), { country: a, score: A };
224
- }).filter((a) => a.score > 0).sort((a, u) => u.score !== a.score ? u.score - a.score : a.country.name.localeCompare(u.country.name)).map((a) => a.country);
225
- }, [de, Ae]), V = M || D, Ye = $ && !Be && !M, je = J && !Be && !V;
226
- B(() => {
227
- ft(!s && de.length > 1);
228
- const n = (l) => {
229
- if (!l) return !1;
230
- const p = l.toUpperCase();
231
- return de.some((a) => a.id === p);
232
- }, i = () => {
233
- const l = typeof navigator < "u" && navigator.language ? navigator.language : "";
234
- try {
235
- if (Intl.Locale) {
236
- const a = new Intl.Locale(l);
237
- if (a?.region && n(a.region)) return a.region.toUpperCase();
238
- }
239
- } catch {
240
- }
241
- const p = l.split(/[-_]/);
242
- return p.length > 1 && n(p[1]) ? p[1].toUpperCase() : null;
243
- };
244
- (async () => {
245
- if (s && n(s)) {
246
- const a = O(s, H);
247
- ce((u) => u.id === a.id ? u : (o?.(a), a));
248
- return;
249
- }
250
- if (!f) return;
251
- const l = await At(n);
252
- if (l) {
253
- const a = O(l, H);
254
- ce((u) => u.id === a.id ? u : (o?.(a), a));
255
- return;
256
- }
257
- const p = i();
258
- if (p) {
259
- const a = O(p, H);
260
- ce((u) => u.id === a.id ? u : (o?.(a), a));
261
- }
262
- })();
263
- }, [s, f, de, H]), B(() => {
264
- const n = w.getMaxDigits();
265
- g.length > n && G((i) => i.slice(0, n));
266
- }, [w]), B(() => {
267
- const n = j(t || "");
268
- n !== g && G(n);
269
- }, [t]), B(() => {
270
- m?.(re);
271
- }, [re, m]);
272
- const Je = b(() => {
273
- z?.(g), X?.({ full: be, fullFormatted: fe, digits: g });
274
- }, [g, be, fe, z, X]);
275
- B(() => {
276
- Je();
277
- }, [Je]);
278
- const _e = b((n) => {
279
- const i = n.data;
280
- if (n.inputType !== "insertText" || !i) return;
281
- const l = U.current;
282
- l && (at.test(i) || i === " " && l.value.endsWith(" ")) && n.preventDefault();
283
- }, []), gt = b(() => {
284
- const n = U.current;
285
- if (!n || V) return;
286
- const i = n.value || "", l = w.getMaxDigits(), p = j(i, l);
287
- G(p), setTimeout(() => {
288
- const a = w.getCaretPosition(p.length);
289
- R(n, a);
290
- }, 0), ee(!1), S.current && clearTimeout(S.current), p.length > 0 && (S.current = setTimeout(() => {
291
- ee(!0);
292
- }, 500));
293
- }, [w, V]), ze = b(
294
- (n) => {
295
- if (V) return;
296
- const i = U.current;
297
- if (!i || n.ctrlKey || n.metaKey || n.altKey || it.includes(n.key)) return;
298
- const [l, p] = Ie(i);
299
- ee(!1), S.current && clearTimeout(S.current);
300
- const a = () => {
301
- S.current && clearTimeout(S.current), S.current = setTimeout(() => {
302
- ee(!0);
303
- }, 300);
304
- };
305
- if (n.key === "Backspace") {
306
- if (n.preventDefault(), l !== p) {
307
- const u = w.getDigitRange(g, l, p);
308
- if (u) {
309
- const [k, P] = u;
310
- G(g.slice(0, k) + g.slice(P)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
311
- }
312
- } else if (l > 0) {
313
- let u = l - 1;
314
- for (; u >= 0 && st.includes(i.value[u]); ) u--;
315
- if (u >= 0) {
316
- const k = w.getDigitRange(g, u, u + 1);
317
- if (k) {
318
- const [P] = k;
319
- G(g.slice(0, P) + g.slice(P + 1)), setTimeout(() => R(i, w.getCaretPosition(P)), 0);
320
- }
321
- }
322
- }
323
- a();
324
- return;
325
- }
326
- if (n.key === "Delete") {
327
- if (n.preventDefault(), l !== p) {
328
- const u = w.getDigitRange(g, l, p);
329
- if (u) {
330
- const [k, P] = u;
331
- G(g.slice(0, k) + g.slice(P)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
332
- }
333
- } else if (l < i.value.length) {
334
- const u = w.getDigitRange(g, l, l + 1);
335
- if (u) {
336
- const [k] = u;
337
- G(g.slice(0, k) + g.slice(k + 1)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
338
- }
339
- }
340
- a();
341
- return;
342
- }
343
- if (/^[0-9]$/.test(n.key)) {
344
- g.length >= w.getMaxDigits() && n.preventDefault(), a();
345
- return;
346
- }
347
- n.key.length === 1 && n.preventDefault(), a();
351
+ const Zt = 500, Re = 300;
352
+ function Je(e) {
353
+ const { formatter: t, digits: n, inactive: r, onChange: s, scheduleValidationHint: o } = e, i = h(
354
+ (l, d) => {
355
+ setTimeout(() => {
356
+ if (!l) return;
357
+ const p = t.getCaretPosition(d);
358
+ xt(l, p);
359
+ }, 0);
348
360
  },
349
- [V, w, g]
350
- ), Xe = b(
351
- (n) => {
352
- if (V) return;
353
- n.preventDefault();
354
- const i = U.current;
355
- if (!i) return;
356
- const l = n.clipboardData?.getData("text") || "", p = w.getMaxDigits(), a = j(l, p);
357
- if (!a) return;
358
- const [u, k] = Ie(i);
359
- if (u !== k) {
360
- const P = w.getDigitRange(g, u, k);
361
- if (P) {
362
- const [Y, A] = P, vt = j(g.slice(0, Y) + a + g.slice(A), p);
363
- G(vt), setTimeout(() => R(i, w.getCaretPosition(Y + a.length)), 0);
364
- }
365
- } else {
366
- const P = w.getDigitRange(g, u, u), Y = P ? P[0] : g.length, A = j(
367
- g.slice(0, Y) + a + g.slice(Y),
368
- p
369
- );
370
- G(A), setTimeout(() => R(i, w.getCaretPosition(Y + a.length)), 0);
371
- }
372
- ee(!1), S.current && clearTimeout(S.current), S.current = setTimeout(() => {
373
- ee(!0);
374
- }, 300);
361
+ [t]
362
+ ), a = h((l) => {
363
+ Bt(re(l));
364
+ }, []), f = h(
365
+ (l) => {
366
+ if (r) return;
367
+ const d = re(l), p = Ht(d, { formatter: t });
368
+ p && (s?.(p.newDigits), i(d.target, p.caretDigitIndex), o?.(Zt));
369
+ },
370
+ [r, t, s, i, o]
371
+ ), c = h(
372
+ (l) => {
373
+ if (r) return;
374
+ const d = re(l), p = Rt(d, { digits: n, formatter: t });
375
+ p && (s?.(p.newDigits), i(d.target, p.caretDigitIndex), o?.(Re));
375
376
  },
376
- [V, w, g]
377
- ), Z = b(() => {
378
- q && (Re(!0), ne.current && clearTimeout(ne.current), ne.current = setTimeout(() => {
379
- $e(!1), Re(!1);
380
- }, 200));
381
- }, [q]), mt = b(
382
- (n) => {
383
- S.current && clearTimeout(S.current), Z(), h?.(n);
377
+ [r, n, t, s, i, o]
378
+ ), u = h(
379
+ (l) => {
380
+ if (r) return;
381
+ const d = re(l), p = Vt(d, { digits: n, formatter: t });
382
+ p && (s?.(p.newDigits), i(d.target, p.caretDigitIndex), o?.(Re));
384
383
  },
385
- [h, Z]
384
+ [r, n, t, s, i, o]
386
385
  );
387
- B(() => {
388
- const n = U.current;
389
- if (!n) return;
390
- const i = _e, l = ze, p = Xe;
391
- return n.addEventListener("beforeinput", i), n.addEventListener("keydown", l), n.addEventListener("paste", p), () => {
392
- n.removeEventListener("beforeinput", i), n.removeEventListener("keydown", l), n.removeEventListener("paste", p);
393
- };
394
- }, [_e, ze, Xe]);
395
- const Te = b(
396
- (n) => {
397
- const i = O(n, H);
398
- ce(i), Z(), Ke(""), le(0), o?.(i), setTimeout(() => U.current?.focus(), 0);
386
+ return {
387
+ handleBeforeInput: a,
388
+ handleInput: f,
389
+ handleKeydown: c,
390
+ handlePaste: u
391
+ };
392
+ }
393
+ function Yt({
394
+ rootRef: e,
395
+ dropdownRef: t,
396
+ searchRef: n,
397
+ selectorRef: r,
398
+ locale: s,
399
+ countryOption: o,
400
+ inactive: i,
401
+ onSelectCountry: a,
402
+ onAfterSelect: f
403
+ }) {
404
+ const [c, u] = k(""), [l, d] = k(!1), [p, D] = k({}), [v, N] = k(!1), [P, g] = k(0), A = M(() => Ke(s), [s]), T = M(() => kt(A, c), [A, c]), E = M(() => !o && A.length > 1, [o, A]), x = h(() => {
405
+ setTimeout(() => n.current?.focus({ preventScroll: !0 }), 0);
406
+ }, []), b = h(() => {
407
+ l && N(!0);
408
+ }, [l]), W = h(() => {
409
+ N(!1), d(!0), g(0), x();
410
+ }, [x]), z = h(() => {
411
+ v && (d(!1), N(!1));
412
+ }, [v]), X = h(() => {
413
+ i || !E || (l ? b() : W());
414
+ }, [i, l, E, W, b]), B = h(
415
+ (m) => {
416
+ a(m), b(), u(""), g(0), f?.();
417
+ },
418
+ [a, b, f]
419
+ ), Q = h((m) => {
420
+ u(m.target.value), g(0);
421
+ }, []), F = h(
422
+ (m) => {
423
+ const y = m.target, S = t.current, H = r.current;
424
+ y && (S?.contains(y) || H?.contains(y) || b());
399
425
  },
400
- [H, o, Z]
401
- ), ge = b(() => {
402
- if (!he.current) return;
403
- const n = he.current.getBoundingClientRect();
404
- ut({
405
- top: `${n.bottom + window.scrollY + 8}px`,
406
- left: `${n.left + window.scrollX}px`,
407
- width: `${n.width}px`
426
+ [b]
427
+ ), w = h((m) => {
428
+ if (m?.type === "scroll" && m.target && t.current?.contains(m.target) || !e?.current) return;
429
+ const y = e.current.getBoundingClientRect();
430
+ D({
431
+ top: `${y.bottom + globalThis.scrollY + 8}px`,
432
+ left: `${y.left + globalThis.scrollX}px`,
433
+ width: `${y.width}px`
408
434
  });
409
- }, []);
410
- B(() => {
411
- if (!q) return;
412
- ge();
413
- const n = setTimeout(() => ye.current?.focus({ preventScroll: !0 }), 0), i = (l) => {
414
- const p = l.target, a = Q.current, u = ke.current;
415
- p && (a?.contains(p) || u?.contains(p) || Z());
416
- };
417
- return window.addEventListener("resize", ge), window.addEventListener("scroll", ge, !0), window.addEventListener("click", i, !0), () => {
418
- clearTimeout(n), window.removeEventListener("resize", ge), window.removeEventListener("scroll", ge, !0), window.removeEventListener("click", i, !0);
419
- };
420
- }, [q, ge, Z]), B(() => () => {
421
- ne.current && clearTimeout(ne.current), ue.current && clearTimeout(ue.current), S.current && clearTimeout(S.current);
422
- }, []);
423
- const ht = b(async () => {
424
- if (We) return;
425
- const n = fe.trim();
426
- if (n) {
427
- Oe(!0);
435
+ }, []), O = h((m) => {
436
+ setTimeout(() => {
437
+ const y = t.current?.lastElementChild, S = y?.children[m];
438
+ if (!y || !S) return;
439
+ const H = y.getBoundingClientRect(), V = S.getBoundingClientRect();
440
+ let $ = 0;
441
+ if (V.top < H.top)
442
+ $ = y.scrollTop - (H.top - V.top);
443
+ else if (V.bottom > H.bottom)
444
+ $ = y.scrollTop + (V.bottom - H.bottom);
445
+ else
446
+ return;
447
+ y.scrollTo({ top: $, behavior: "smooth" });
448
+ }, 0);
449
+ }, []), ae = h(
450
+ (m) => {
451
+ m.key === "ArrowDown" ? (m.preventDefault(), g((y) => {
452
+ const S = Math.min(y + 1, T.length - 1);
453
+ return O(S), S;
454
+ })) : m.key === "ArrowUp" ? (m.preventDefault(), g((y) => {
455
+ const S = Math.max(y - 1, 0);
456
+ return O(S), S;
457
+ })) : m.key === "Enter" && T[P] ? (m.preventDefault(), B(T[P].id)) : m.key === "Escape" && b();
458
+ },
459
+ [T, P, B, b, O]
460
+ );
461
+ return I(() => {
462
+ !E && l && b();
463
+ }, [E, l, b]), I(() => {
464
+ if (l)
465
+ return w(), globalThis.addEventListener("resize", w), globalThis.addEventListener("scroll", w, !0), globalThis.addEventListener("click", F, !0), () => {
466
+ globalThis.removeEventListener("resize", w), globalThis.removeEventListener("scroll", w, !0), globalThis.removeEventListener("click", F, !0);
467
+ };
468
+ }, [l, w, F]), {
469
+ // State
470
+ dropdownOpen: l,
471
+ isClosing: v,
472
+ search: c,
473
+ focusedIndex: P,
474
+ dropdownStyle: p,
475
+ // Derived
476
+ filteredCountries: T,
477
+ hasDropdown: E,
478
+ // Actions
479
+ openDropdown: W,
480
+ closeDropdown: b,
481
+ toggleDropdown: X,
482
+ selectCountry: B,
483
+ setFocusedIndex: g,
484
+ handleSearchChange: Q,
485
+ handleSearchKeydown: ae,
486
+ handleDropdownAnimationEnd: z
487
+ };
488
+ }
489
+ function Jt(e = 1800) {
490
+ const [t, n] = k(!1), [r, s] = k(!1), o = De(), i = h(
491
+ async (a) => {
492
+ if (r) return !1;
493
+ const f = a.trim();
494
+ if (!f) return !1;
495
+ s(!0);
428
496
  try {
429
- await navigator.clipboard.writeText(n), Ve(!0), T?.(n), Ce.current && (Ce.current.textContent = "Phone number copied to clipboard"), ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
430
- Ve(!1), ue.current = null;
431
- }, 1800);
432
- } catch (i) {
433
- console.warn("Copy failed", i);
497
+ return await navigator.clipboard.writeText(f), n(!0), o.set(() => {
498
+ n(!1);
499
+ }, e), !0;
500
+ } catch (c) {
501
+ return console.warn("Copy failed", c), !1;
434
502
  } finally {
435
- Oe(!1);
503
+ s(!1);
436
504
  }
437
- }
438
- }, [fe, T, We]), yt = b(() => {
439
- G(""), ee(!1), S.current && clearTimeout(S.current), z?.(""), X?.({ full: "", fullFormatted: "", digits: "" }), C?.(), setTimeout(() => U.current?.focus(), 0);
440
- }, [z, X, C]);
441
- Mt(
442
- e,
505
+ },
506
+ [r, o]
507
+ );
508
+ return { copied: t, isCopying: r, copy: i };
509
+ }
510
+ const Ve = 1800;
511
+ function jt({ liveRef: e, fullFormatted: t, onCopy: n }) {
512
+ const r = De(), { copied: s, copy: o } = Jt(Ve), i = M(() => s ? "Copied" : `Copy ${t}`, [s, t]), a = M(() => s ? "Copied" : "Copy phone number", [s]), f = h(
513
+ (u) => {
514
+ e?.current && (e.current.textContent = u, r.set(() => {
515
+ e.current && (e.current.textContent = "");
516
+ }, Ve));
517
+ },
518
+ [e, r]
519
+ ), c = h(async () => {
520
+ const u = t.trim();
521
+ await o(u) && (n?.(u), f("Phone number copied to clipboard"));
522
+ }, [t, o, n, f]);
523
+ return {
524
+ copied: s,
525
+ copyAriaLabel: i,
526
+ copyButtonTitle: a,
527
+ onCopyClick: c
528
+ };
529
+ }
530
+ function _t({ theme: e }) {
531
+ const [t, n] = k(!1), r = M(() => e === "auto" ? t ? "theme-dark" : "theme-light" : `theme-${e}`, [e, t]);
532
+ return I(() => {
533
+ const s = globalThis.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
534
+ if (!s) return;
535
+ n(s.matches);
536
+ const o = (i) => {
537
+ n(i.matches);
538
+ };
539
+ return s.addEventListener("change", o), () => s.removeEventListener("change", o);
540
+ }, []), {
541
+ themeClass: r
542
+ };
543
+ }
544
+ const zt = (e, t) => {
545
+ const {
546
+ value: n = "",
547
+ country: r,
548
+ detect: s = !0,
549
+ locale: o,
550
+ size: i = "normal",
551
+ theme: a = "auto",
552
+ disabled: f = !1,
553
+ readonly: c = !1,
554
+ showCopy: u = !0,
555
+ showClear: l = !1,
556
+ withValidity: d = !0,
557
+ searchPlaceholder: p = "Search country or code...",
558
+ noResultsText: D = "No countries found",
559
+ clearButtonLabel: v = "Clear phone number",
560
+ dropdownClass: N = "",
561
+ disableDefaultStyles: P = !1,
562
+ onChange: g,
563
+ onPhoneChange: A,
564
+ onCountryChange: T,
565
+ onValidationChange: E,
566
+ onFocus: x,
567
+ onBlur: b,
568
+ onCopy: W,
569
+ onClear: z,
570
+ renderActionsBefore: X,
571
+ renderFlag: B,
572
+ renderCopySvg: Q,
573
+ renderClearSvg: F
574
+ } = e, { country: w, setCountry: O, locale: ae } = Ye({
575
+ country: r,
576
+ locale: o,
577
+ detect: s,
578
+ onCountryChange: T
579
+ }), {
580
+ digits: m,
581
+ formatter: y,
582
+ displayPlaceholder: S,
583
+ displayValue: H,
584
+ full: V,
585
+ fullFormatted: $,
586
+ isComplete: q,
587
+ isEmpty: ve,
588
+ shouldShowWarn: je
589
+ } = Ze({
590
+ country: w,
591
+ value: n,
592
+ onChange: g,
593
+ onPhoneChange: A,
594
+ onValidationChange: E
595
+ }), { showValidationHint: _e, clearValidationHint: ee, scheduleValidationHint: ze } = Ot(), we = Dt(), ce = R(null), be = R(null), Ie = R(null), Se = R(null), Le = R(null), Me = R(null), Z = f || c, Te = _e && je, Ee = u && !ve && !f, ke = l && !ve && !Z, {
596
+ copied: le,
597
+ copyAriaLabel: Xe,
598
+ copyButtonTitle: Qe,
599
+ onCopyClick: qe
600
+ } = jt({
601
+ liveRef: Ie,
602
+ fullFormatted: $,
603
+ onCopy: W
604
+ }), Y = h(() => {
605
+ setTimeout(() => ce.current?.focus(), 0);
606
+ }, []), { handleBeforeInput: et, handleInput: tt, handleKeydown: nt, handlePaste: ot } = Je({
607
+ formatter: y,
608
+ digits: m,
609
+ inactive: Z,
610
+ onChange: g,
611
+ scheduleValidationHint: ze
612
+ }), {
613
+ dropdownOpen: te,
614
+ isClosing: rt,
615
+ search: st,
616
+ focusedIndex: ue,
617
+ dropdownStyle: it,
618
+ filteredCountries: de,
619
+ hasDropdown: ne,
620
+ closeDropdown: Ae,
621
+ toggleDropdown: at,
622
+ selectCountry: pe,
623
+ setFocusedIndex: ct,
624
+ handleSearchChange: lt,
625
+ handleSearchKeydown: ut,
626
+ handleDropdownAnimationEnd: dt
627
+ } = Yt({
628
+ rootRef: be,
629
+ dropdownRef: Se,
630
+ searchRef: Le,
631
+ selectorRef: Me,
632
+ locale: ae,
633
+ inactive: Z,
634
+ countryOption: r,
635
+ onSelectCountry: O,
636
+ onAfterSelect: Y
637
+ }), pt = h(
638
+ (L) => {
639
+ ee(!1), Ae(), x?.(L);
640
+ },
641
+ [x, Ae, ee]
642
+ ), oe = h(() => {
643
+ g?.(""), ee(), z?.();
644
+ }, [g, z, ee]), ft = h(() => {
645
+ oe(), Y();
646
+ }, [oe, Y]);
647
+ vt(
648
+ t,
443
649
  () => ({
444
- focus: () => U.current?.focus(),
445
- blur: () => U.current?.blur(),
446
- clear: () => {
447
- G(""), ee(!1), S.current && clearTimeout(S.current), z?.(""), X?.({ full: "", fullFormatted: "", digits: "" }), C?.();
448
- },
449
- selectCountry: Te,
450
- getFullNumber: () => be,
451
- getFullFormattedNumber: () => fe,
452
- getDigits: () => g,
453
- isValid: () => re,
454
- isComplete: () => re
650
+ focus: Y,
651
+ blur: () => ce.current?.blur(),
652
+ clear: oe,
653
+ selectCountry: pe,
654
+ getFullNumber: () => V,
655
+ getFullFormattedNumber: () => $,
656
+ getDigits: () => m,
657
+ isValid: () => q,
658
+ isComplete: () => q
455
659
  }),
456
- [Te, be, fe, g, re, C, z, X]
660
+ [Y, pe, V, $, m, q, oe]
457
661
  );
458
- const Qe = (n) => {
459
- setTimeout(() => {
460
- const i = Q.current?.lastElementChild, l = i?.children[n];
461
- if (!i || !l) return;
462
- const p = i.getBoundingClientRect(), a = l.getBoundingClientRect();
463
- let u = 0;
464
- if (a.top < p.top)
465
- u = i.scrollTop - (p.top - a.top);
466
- else if (a.bottom > p.bottom)
467
- u = i.scrollTop + (a.bottom - p.bottom);
468
- else
469
- return;
470
- i.scrollTo({ top: u, behavior: "smooth" });
471
- }, 0);
472
- }, Ct = b(
473
- (n) => {
474
- n.key === "ArrowDown" ? (n.preventDefault(), le((i) => {
475
- const l = Math.min(i + 1, pe.length - 1);
476
- return Qe(l), l;
477
- })) : n.key === "ArrowUp" ? (n.preventDefault(), le((i) => {
478
- const l = Math.max(i - 1, 0);
479
- return Qe(l), l;
480
- })) : n.key === "Enter" && pe[we] ? (n.preventDefault(), Te(pe[we].id)) : n.key === "Escape" && Z();
481
- },
482
- [pe, we, Te, Z]
483
- ), qe = Ee(() => d !== "auto" ? `theme-${d}` : typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "theme-dark" : "theme-light", [d]), wt = [
662
+ const { themeClass: Ne } = _t({ theme: a }), ht = [
484
663
  "phone-input",
485
- `size-${y}`,
486
- qe,
487
- M && "is-disabled",
488
- D && "is-readonly",
489
- Se && "is-unstyled",
490
- K && Ze && "is-incomplete",
491
- K && re && "is-complete"
492
- ].filter(Boolean).join(" "), Dt = +Ye + +je + (N ? 1 : 0);
493
- return /* @__PURE__ */ oe(Tt, { children: [
494
- /* @__PURE__ */ oe(
664
+ `size-${i}`,
665
+ Ne,
666
+ f && "is-disabled",
667
+ c && "is-readonly",
668
+ P && "is-unstyled",
669
+ d && Te && "is-incomplete",
670
+ d && q && "is-complete"
671
+ ].filter(Boolean).join(" "), gt = +Ee + +ke + (X ? 1 : 0), Pe = `pi-options-${we}`, xe = `pi-option-${we}`, mt = te && de[ue] ? `${xe}-${ue}` : void 0;
672
+ return /* @__PURE__ */ G(Ct, { children: [
673
+ /* @__PURE__ */ G(
495
674
  "div",
496
675
  {
497
- ref: he,
498
- className: wt,
499
- style: { "--pi-actions-count": Dt },
676
+ ref: be,
677
+ className: ht,
678
+ style: { "--pi-actions-count": gt },
500
679
  role: "group",
501
680
  "aria-label": "Phone input with country selector",
502
681
  children: [
503
- /* @__PURE__ */ v("div", { className: "pi-selector", ref: ke, children: /* @__PURE__ */ oe(
682
+ /* @__PURE__ */ C("div", { className: "pi-selector", ref: Me, children: /* @__PURE__ */ G(
504
683
  "button",
505
684
  {
506
685
  type: "button",
507
- className: `pi-selector-btn ${!ve || D ? "no-dropdown" : ""}`,
508
- disabled: M,
509
- tabIndex: V || !ve ? -1 : void 0,
510
- "aria-label": `Selected country: ${I.name}`,
511
- "aria-expanded": q,
512
- "aria-haspopup": ve ? "listbox" : void 0,
513
- onClick: () => {
514
- V || !ve || (q ? Z() : (ne.current && clearTimeout(ne.current), Re(!1), $e(!0), le(0)));
515
- },
686
+ className: `pi-selector-btn ${!ne || c ? "no-dropdown" : ""}`,
687
+ disabled: f,
688
+ tabIndex: Z || !ne ? -1 : void 0,
689
+ "aria-label": `Selected country: ${w.name}`,
690
+ "aria-expanded": te,
691
+ "aria-haspopup": ne ? "listbox" : void 0,
692
+ onClick: at,
516
693
  children: [
517
- /* @__PURE__ */ v("span", { className: "pi-flag", role: "img", "aria-label": `${I.name} flag`, children: E ? E(I) : I.flag }),
518
- /* @__PURE__ */ v("span", { className: "pi-code", children: I.code }),
519
- !V && ve && /* @__PURE__ */ v(
694
+ /* @__PURE__ */ C("span", { className: "pi-flag", role: "img", "aria-label": `${w.name} flag`, children: B ? B(w) : w.flag }),
695
+ /* @__PURE__ */ C("span", { className: "pi-code", children: w.code }),
696
+ !Z && ne && /* @__PURE__ */ C(
520
697
  "svg",
521
698
  {
522
- className: `pi-chevron ${q ? "is-open" : ""}`,
699
+ className: `pi-chevron ${te ? "is-open" : ""}`,
523
700
  width: "12",
524
701
  height: "12",
525
702
  viewBox: "0 0 12 12",
526
703
  fill: "none",
527
704
  "aria-hidden": "true",
528
- children: /* @__PURE__ */ v(
705
+ children: /* @__PURE__ */ C(
529
706
  "path",
530
707
  {
531
708
  d: "M2.5 4.5L6 8L9.5 4.5",
@@ -540,11 +717,11 @@ const Bt = ({ ref: e, ...r }) => {
540
717
  ]
541
718
  }
542
719
  ) }),
543
- /* @__PURE__ */ oe("div", { className: "pi-input-wrap", children: [
544
- /* @__PURE__ */ v(
720
+ /* @__PURE__ */ G("div", { className: "pi-input-wrap", children: [
721
+ /* @__PURE__ */ C(
545
722
  "input",
546
723
  {
547
- ref: U,
724
+ ref: ce,
548
725
  type: "tel",
549
726
  inputMode: "tel",
550
727
  autoComplete: "tel-national",
@@ -552,27 +729,30 @@ const Bt = ({ ref: e, ...r }) => {
552
729
  autoCapitalize: "off",
553
730
  spellCheck: !1,
554
731
  className: "pi-input",
555
- placeholder: pt,
556
- value: xe,
557
- disabled: M,
558
- readOnly: D,
559
- "aria-invalid": Ze,
560
- onInput: gt,
561
- onFocus: mt,
562
- onBlur: L
732
+ placeholder: S,
733
+ value: H,
734
+ disabled: f,
735
+ readOnly: c,
736
+ "aria-invalid": Te,
737
+ onInput: tt,
738
+ onBeforeInput: et,
739
+ onKeyDown: nt,
740
+ onPaste: ot,
741
+ onFocus: pt,
742
+ onBlur: b
563
743
  }
564
744
  ),
565
- /* @__PURE__ */ oe("div", { className: "pi-actions", role: "toolbar", "aria-label": "Phone input actions", children: [
566
- N && N(),
567
- Ye && /* @__PURE__ */ v(
745
+ /* @__PURE__ */ G("div", { className: "pi-actions", role: "toolbar", "aria-label": "Phone input actions", children: [
746
+ X?.(),
747
+ Ee && /* @__PURE__ */ C(
568
748
  "button",
569
749
  {
570
750
  type: "button",
571
- className: `pi-btn ${De ? "is-copied" : ""}`,
572
- "aria-label": De ? "Copied" : `Copy ${I.code} ${xe}`,
573
- title: De ? "Copied" : "Copy phone number",
574
- onClick: ht,
575
- children: F ? F(De) : De ? /* @__PURE__ */ v("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v("path", { d: "M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z", fill: "currentColor" }) }) : /* @__PURE__ */ v("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v(
751
+ className: `pi-btn pi-btn-copy ${le ? "is-copied" : ""}`,
752
+ "aria-label": Xe,
753
+ title: Qe,
754
+ onClick: qe,
755
+ children: Q ? Q(le) : le ? /* @__PURE__ */ C("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ C("path", { d: "M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z", fill: "currentColor" }) }) : /* @__PURE__ */ C("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ C(
576
756
  "path",
577
757
  {
578
758
  d: "M13.5 5.5V13.5H5.5V5.5H13.5ZM13.5 4H5.5C4.67 4 4 4.67 4 5.5V13.5C4 14.33 4.67 15 5.5 15H13.5C14.33 15 15 14.33 15 13.5V5.5C15 4.67 14.33 4 13.5 4ZM10.5 1H2.5V11H4V2.5H10.5V1Z",
@@ -581,15 +761,15 @@ const Bt = ({ ref: e, ...r }) => {
581
761
  ) })
582
762
  }
583
763
  ),
584
- je && /* @__PURE__ */ v(
764
+ ke && /* @__PURE__ */ C(
585
765
  "button",
586
766
  {
587
767
  type: "button",
588
- className: "pi-btn",
589
- "aria-label": ie,
590
- title: ie,
591
- onClick: yt,
592
- children: ae ? ae() : /* @__PURE__ */ v("svg", { width: "11", height: "11", viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v(
768
+ className: "pi-btn pi-btn-clear",
769
+ "aria-label": v,
770
+ title: v,
771
+ onClick: ft,
772
+ children: F ? F() : /* @__PURE__ */ C("svg", { width: "11", height: "11", viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ C(
593
773
  "path",
594
774
  {
595
775
  d: "M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z",
@@ -603,262 +783,128 @@ const Bt = ({ ref: e, ...r }) => {
603
783
  ]
604
784
  }
605
785
  ),
606
- q && typeof document < "u" && Lt(
607
- /* @__PURE__ */ oe(
786
+ te && typeof document < "u" && wt(
787
+ /* @__PURE__ */ G(
608
788
  "div",
609
789
  {
610
- ref: Q,
611
- className: `phone-dropdown ${Le} ${qe} ${ct ? "is-closing" : ""}`,
612
- style: lt,
790
+ ref: Se,
791
+ className: `phone-dropdown ${N} ${Ne} ${rt ? "is-closing" : ""}`,
792
+ style: it,
613
793
  role: "dialog",
614
794
  "aria-modal": "false",
615
795
  "aria-label": "Select country",
796
+ onAnimationEnd: dt,
616
797
  children: [
617
- /* @__PURE__ */ v("div", { className: "pi-search-wrap", children: /* @__PURE__ */ v(
798
+ /* @__PURE__ */ C("div", { className: "pi-search-wrap", children: /* @__PURE__ */ C(
618
799
  "input",
619
800
  {
620
- ref: ye,
801
+ ref: Le,
621
802
  type: "search",
622
803
  className: "pi-search",
623
804
  "aria-label": "Search countries",
624
- placeholder: _,
625
- value: Ae,
626
- onChange: (n) => {
627
- Ke(n.target.value), le(0);
628
- },
629
- onKeyDown: Ct
805
+ "aria-controls": Pe,
806
+ "aria-activedescendant": mt,
807
+ placeholder: p,
808
+ value: st,
809
+ onChange: lt,
810
+ onKeyDown: ut
630
811
  }
631
812
  ) }),
632
- /* @__PURE__ */ v("ul", { className: "pi-options", role: "listbox", "aria-activedescendant": `option-${we}`, tabIndex: -1, children: pe.length > 0 ? pe.map((n, i) => /* @__PURE__ */ oe(
813
+ /* @__PURE__ */ C("ul", { id: Pe, className: "pi-options", role: "listbox", tabIndex: -1, children: de.length > 0 ? de.map((L, fe) => /* @__PURE__ */ G(
633
814
  "li",
634
815
  {
635
- id: `option-${i}`,
816
+ id: `${xe}-${fe}`,
636
817
  role: "option",
637
- className: `pi-option ${i === we ? "is-focused" : ""} ${n.id === I.id ? "is-selected" : ""}`,
638
- "aria-selected": n.id === I.id,
639
- title: n.name,
640
- onClick: () => Te(n.id),
641
- onMouseEnter: () => le(i),
818
+ className: `pi-option ${fe === ue ? "is-focused" : ""} ${L.id === w.id ? "is-selected" : ""}`,
819
+ "aria-selected": L.id === w.id,
820
+ title: L.name,
821
+ onClick: () => pe(L.id),
822
+ onMouseEnter: () => ct(fe),
642
823
  children: [
643
- /* @__PURE__ */ v("span", { className: "pi-flag", role: "img", "aria-label": `${n.name} flag`, children: E ? E(n) : n.flag }),
644
- /* @__PURE__ */ v("span", { className: "pi-opt-name", children: n.name }),
645
- /* @__PURE__ */ v("span", { className: "pi-opt-code", children: n.code })
824
+ /* @__PURE__ */ C("span", { className: "pi-flag", role: "img", "aria-label": `${L.name} flag`, children: B ? B(L) : L.flag }),
825
+ /* @__PURE__ */ C("span", { className: "pi-opt-name", children: L.name }),
826
+ /* @__PURE__ */ C("span", { className: "pi-opt-code", children: L.code })
646
827
  ]
647
828
  },
648
- n.id
649
- )) : /* @__PURE__ */ v("li", { className: "pi-empty", children: Me }) })
829
+ L.id
830
+ )) : /* @__PURE__ */ C("li", { className: "pi-empty", children: D }) })
650
831
  ]
651
832
  }
652
833
  ),
653
834
  document.body
654
835
  ),
655
- /* @__PURE__ */ v("div", { ref: Ce, className: "sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true" })
836
+ /* @__PURE__ */ C("div", { ref: Ie, className: "sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true" })
656
837
  ] });
657
- };
658
- Bt.displayName = "PhoneInput";
659
- function Ft() {
660
- try {
661
- const e = Ne();
662
- try {
663
- const t = new Intl.Locale(e);
664
- if (t.region) return t.region.toUpperCase();
665
- } catch {
666
- }
667
- const r = e.split(/[-_]/);
668
- if (r.length > 1) return r[1]?.toUpperCase() || null;
669
- } catch {
670
- }
671
- return null;
672
- }
673
- function $t(e = {}) {
674
- const r = W(null), [t, s] = x(""), [f, c] = x(() => {
675
- const o = e.locale || Ne();
676
- return O(e.country || "US", o);
677
- }), y = e.locale || Ne(), d = He(f), M = d.formatDisplay(t), D = `${f.code}${t}`, $ = t ? `${f.code} ${M}` : "", J = d.isComplete(t), K = t.length === 0, _ = !K && !J;
678
- B(() => {
679
- e.detect && (async () => {
680
- const o = await ot();
681
- if (o) {
682
- const h = O(o, y);
683
- c(h), e.onCountryChange?.(h);
684
- return;
685
- }
686
- const m = Ft();
687
- if (m) {
688
- const h = O(m, y);
689
- c(h), e.onCountryChange?.(h);
690
- }
691
- })();
692
- }, [e.detect]), B(() => {
693
- if (e.country) {
694
- const o = O(e.country, y);
695
- o.id !== f.id && (c(o), e.onCountryChange?.(o));
696
- }
697
- }, [e.country, y]), B(() => {
698
- const o = r.current;
699
- o && (o.value = M, o.placeholder = d.getPlaceholder());
700
- }, [M, d]), B(() => {
701
- if (e.onChange) {
702
- const o = {
703
- full: D,
704
- fullFormatted: $,
705
- digits: t
706
- };
707
- e.onChange(o);
708
- }
709
- }, [t, D, $]);
710
- const Me = b((o) => {
711
- const m = o.data;
712
- if (o.inputType !== "insertText" || !m) return;
713
- const h = r.current;
714
- h && (at.test(m) || m === " " && h.value.endsWith(" ")) && o.preventDefault();
715
- }, []), ie = b(() => {
716
- const o = r.current;
717
- if (!o) return;
718
- const m = o.value || "", h = d.getMaxDigits(), L = j(m, h);
719
- s(L), setTimeout(() => {
720
- const T = d.getCaretPosition(L.length);
721
- R(o, T);
722
- }, 0);
723
- }, [d]), Le = b(
724
- (o) => {
725
- const m = r.current;
726
- if (!m || o.ctrlKey || o.metaKey || o.altKey || it.includes(o.key)) return;
727
- const [h, L] = Ie(m);
728
- if (o.key === "Backspace") {
729
- if (o.preventDefault(), h !== L) {
730
- const T = d.getDigitRange(t, h, L);
731
- if (T) {
732
- const [C, N] = T, E = t.slice(0, C) + t.slice(N);
733
- s(E), setTimeout(() => {
734
- const F = d.getCaretPosition(C);
735
- R(m, F);
736
- }, 0);
737
- }
738
- return;
739
- }
740
- if (h > 0) {
741
- const T = m.value;
742
- let C = h - 1;
743
- for (; C >= 0 && st.includes(T[C]); )
744
- C--;
745
- if (C >= 0) {
746
- const N = d.getDigitRange(t, C, C + 1);
747
- if (N) {
748
- const [E] = N, F = t.slice(0, E) + t.slice(E + 1);
749
- s(F), setTimeout(() => {
750
- const ae = d.getCaretPosition(E);
751
- R(m, ae);
752
- }, 0);
753
- }
754
- }
755
- }
756
- return;
757
- }
758
- if (o.key === "Delete") {
759
- if (o.preventDefault(), h !== L) {
760
- const T = d.getDigitRange(t, h, L);
761
- if (T) {
762
- const [C, N] = T, E = t.slice(0, C) + t.slice(N);
763
- s(E), setTimeout(() => {
764
- const F = d.getCaretPosition(C);
765
- R(m, F);
766
- }, 0);
767
- }
768
- return;
769
- }
770
- if (h < m.value.length) {
771
- const T = d.getDigitRange(t, h, h + 1);
772
- if (T) {
773
- const [C] = T, N = t.slice(0, C) + t.slice(C + 1);
774
- s(N), setTimeout(() => {
775
- const E = d.getCaretPosition(C);
776
- R(m, E);
777
- }, 0);
778
- }
779
- }
780
- return;
781
- }
782
- if (/^[0-9]$/.test(o.key)) {
783
- t.length >= d.getMaxDigits() && o.preventDefault();
784
- return;
785
- }
786
- o.key.length === 1 && o.preventDefault();
787
- },
788
- [t, d]
789
- ), Se = b(
790
- (o) => {
791
- o.preventDefault();
792
- const m = r.current;
793
- if (!m) return;
794
- const h = o.clipboardData?.getData("text") || "", L = d.getMaxDigits(), T = j(h, L);
795
- if (T.length === 0) return;
796
- const [C, N] = Ie(m);
797
- if (C !== N) {
798
- const Q = d.getDigitRange(t, C, N);
799
- if (Q) {
800
- const [ye, Ce] = Q, ke = t.slice(0, ye), H = t.slice(Ce), I = j(ke + T + H, L);
801
- s(I), setTimeout(() => {
802
- const ce = d.getCaretPosition(ye + T.length);
803
- R(m, ce);
804
- }, 0);
805
- return;
806
- }
807
- }
808
- const E = d.getDigitRange(t, C, C), F = E ? E[0] : t.length, ae = t.slice(0, F), U = t.slice(F), he = j(ae + T + U, L);
809
- s(he), setTimeout(() => {
810
- const Q = d.getCaretPosition(F + T.length);
811
- R(m, Q);
812
- }, 0);
813
- },
814
- [t, d]
815
- );
816
- B(() => {
817
- const o = r.current;
818
- if (!o) return;
819
- o.setAttribute("type", "tel"), o.setAttribute("inputmode", "tel"), o.setAttribute("placeholder", d.getPlaceholder());
820
- const m = Me, h = Le, L = Se;
821
- return o.addEventListener("beforeinput", m), o.addEventListener("input", ie), o.addEventListener("keydown", h), o.addEventListener("paste", L), () => {
822
- o.removeEventListener("beforeinput", m), o.removeEventListener("input", ie), o.removeEventListener("keydown", h), o.removeEventListener("paste", L);
838
+ }, Xt = yt(zt);
839
+ Xt.displayName = "PhoneInput";
840
+ function tn(e) {
841
+ const t = R(null), { country: n, setCountry: r } = Ye({
842
+ country: e.country,
843
+ locale: e.locale,
844
+ detect: e.detect,
845
+ onCountryChange: e.onCountryChange
846
+ }), {
847
+ digits: s,
848
+ formatter: o,
849
+ displayPlaceholder: i,
850
+ displayValue: a,
851
+ full: f,
852
+ fullFormatted: c,
853
+ isComplete: u,
854
+ isEmpty: l,
855
+ shouldShowWarn: d
856
+ } = Ze({
857
+ country: n,
858
+ value: e.value,
859
+ onChange: e.onChange,
860
+ onPhoneChange: e.onPhoneChange
861
+ }), { handleBeforeInput: p, handleInput: D, handleKeydown: v, handlePaste: N } = Je({
862
+ formatter: o,
863
+ digits: s,
864
+ onChange: e.onChange
865
+ });
866
+ I(() => {
867
+ const g = t.current;
868
+ g && (g.setAttribute("type", "tel"), g.setAttribute("inputmode", "tel"));
869
+ }, []), I(() => {
870
+ const g = t.current;
871
+ g && (g.value = a, g.setAttribute("placeholder", i));
872
+ }, [a, i]), I(() => {
873
+ const g = t.current;
874
+ if (!g) return;
875
+ const A = p, T = D, E = v, x = N;
876
+ return g.addEventListener("beforeinput", A), g.addEventListener("input", T), g.addEventListener("keydown", E), g.addEventListener("paste", x), () => {
877
+ g.removeEventListener("beforeinput", A), g.removeEventListener("input", T), g.removeEventListener("keydown", E), g.removeEventListener("paste", x);
823
878
  };
824
- }, [Me, ie, Le, Se, d]);
825
- const z = b(
826
- (o) => {
827
- const m = O(o, y);
828
- c(m);
829
- const L = He(m).getMaxDigits();
830
- t.length > L && s(t.slice(0, L)), e.onCountryChange?.(m);
831
- },
832
- [y, t, e]
833
- ), X = b(() => {
834
- s("");
835
- const o = r.current;
836
- o && (o.value = "");
837
- }, []);
879
+ }, [p, D, v, N]);
880
+ const P = h(() => {
881
+ e.onChange("");
882
+ }, [e.onChange]);
838
883
  return {
839
- ref: r,
840
- digits: t,
841
- full: D,
842
- fullFormatted: $,
843
- isComplete: J,
844
- isEmpty: K,
845
- shouldShowWarn: _,
846
- country: f,
847
- setCountry: z,
848
- clear: X
884
+ ref: t,
885
+ digits: s,
886
+ formatter: o,
887
+ full: f,
888
+ fullFormatted: c,
889
+ isComplete: u,
890
+ isEmpty: l,
891
+ shouldShowWarn: d,
892
+ country: n,
893
+ setCountry: r,
894
+ clear: P
849
895
  };
850
896
  }
851
- const Kt = {
852
- getFlagEmoji: Pt,
853
- countPlaceholders: Ge,
854
- formatDigitsWithMap: Pe,
855
- pickMaskVariant: rt,
856
- removeCountryCodePrefix: Ue,
857
- toArray: nt
897
+ const nn = {
898
+ getFlagEmoji: Lt,
899
+ countPlaceholders: ye,
900
+ formatDigitsWithMap: se,
901
+ pickMaskVariant: We,
902
+ removeCountryCodePrefix: ge,
903
+ toArray: Ue
858
904
  };
859
905
  export {
860
- Kt as PMaskHelpers,
861
- Bt as PhoneInput,
862
- $t as usePhoneMask
906
+ nn as PMaskHelpers,
907
+ Xt as PhoneInput,
908
+ tn as usePhoneMask
863
909
  };
864
910
  //# sourceMappingURL=index.js.map