@input-kit/phone 0.1.3 → 0.2.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.
package/README.md CHANGED
@@ -1,21 +1,15 @@
1
1
  # @input-kit/phone
2
2
 
3
- Headless React phone input with a complete world country-code dataset, searchable country selection, and `libphonenumber-js` powered formatting and validation.
4
-
5
- ## Latest update
6
-
7
- Version `0.1.3` tightens country coverage and compatibility:
8
-
9
- - India is included as `IN` with `+91` and a localized phone placeholder.
10
- - The country list now matches all `245` regions supported by `libphonenumber-js`.
11
- - Fallback metadata is included for Ascension Island (`AC`), Tristan da Cunha (`TA`), and Caribbean Netherlands (`BQ`).
12
- - Primary dial-code lookup now works for shared codes like `+1`, so `getCountriesByDialCode('+1')` returns matching regions.
13
- - Older helper and hook aliases remain available for projects already using the previous API shape.
3
+ Headless React phone input with a complete world country-code dataset, searchable country selection, and `libphonenumber-js` powered formatting and validation.
4
+
5
+ ## Latest update
6
+
7
+ Version **0.2.0** adds structured validation, `parsePhoneValue`, `getCountryOptions`, Bun maintainer tooling, CI, integration docs, and `PhoneInput` UX improvements. See [CHANGELOG.md](./CHANGELOG.md).
14
8
 
15
9
  ## Features
16
10
 
17
11
  - **245 supported calling regions** derived from `libphonenumber-js` metadata and `world-countries`
18
- - **Headless hook and component** via `usePhoneInput()` and `PhoneInput`
12
+ - **Headless hook** via `usePhoneInput()` plus an optional **unstyled reference** `PhoneInput` component (class names only — no bundled CSS)
19
13
  - **Searchable country selector** with country name, ISO code, and dial-code matching
20
14
  - **Real formatting and validation** powered by `libphonenumber-js`
21
15
  - **International detection** for pasted or typed `+` / `00` numbers
@@ -33,6 +27,7 @@ npm install @input-kit/phone
33
27
 
34
28
  ```tsx
35
29
  import { PhoneInput } from '@input-kit/phone';
30
+ import '@your-app/phone-input.css'; // style .phone-input-* classes
36
31
 
37
32
  function Example() {
38
33
  return (
@@ -88,6 +83,58 @@ function Example() {
88
83
  }
89
84
  ```
90
85
 
86
+ ## Phone values
87
+
88
+ | Field | Meaning |
89
+ | --- | --- |
90
+ | `phone` | National digits stored by the hook (default) |
91
+ | `fullPhone` | National number plus dial code when `includeDialCode` is `true` |
92
+ | `onChange(phone, country)` | Same contract as `phone` / `includeDialCode` |
93
+ | E.164 for APIs | `parsePhoneValue(phone, country).e164` when valid — prefer this over raw concatenation |
94
+
95
+ ## Known behavior
96
+
97
+ Formatting, length checks, and validity follow **[libphonenumber-js](https://www.npmjs.com/package/libphonenumber-js)** (same family as `react-phone-number-input`). The package does not implement per-country rules outside that library.
98
+
99
+ ## Form integrations
100
+
101
+ See **[docs/integrations.md](./docs/integrations.md)** for React Hook Form, Formik, Zod, and controlled-input patterns.
102
+
103
+ ## Styled example
104
+
105
+ A minimal Vite demo using only the hook lives in **[examples/react-styled/](./examples/react-styled/)**.
106
+
107
+ ## Migration from 0.1.x
108
+
109
+ Compatibility aliases remain exported. Prefer the newer names in new code:
110
+
111
+ | Deprecated | Replacement |
112
+ | --- | --- |
113
+ | `setValue` | `setPhone` |
114
+ | `value` (hook) | `phone` |
115
+ | `allowedCountries` | `onlyCountries` |
116
+ | `excludedCountries` | `excludeCountries` |
117
+ | `autoDetectCountry` | `autoDetect` |
118
+ | `toggle` / `open` / `close` | `toggleDropdown` / `openDropdown` / `closeDropdown` |
119
+ | `countries` (hook list) | `filteredCountries` |
120
+ | `countrySelectorProps` | `countryButtonProps` |
121
+
122
+ Validation is unified in 0.2.0: `isValid` and `error` come from the same `validatePhoneNumber` call. Use `validationReason` or `onValidationChange` for structured form messages.
123
+
124
+ ## Development
125
+
126
+ Requires [Bun](https://bun.sh) (see `packageManager` in `package.json`).
127
+
128
+ ```bash
129
+ bun install
130
+ bun run test
131
+ bun run typecheck
132
+ bun run build
133
+ bun run lint
134
+ ```
135
+
136
+ Manual browser check: `test-demo/` (static HTML).
137
+
91
138
  ## Exports
92
139
 
93
140
  ### Components and hooks
@@ -101,26 +148,22 @@ function Example() {
101
148
  - `getCountryByCode(code)`
102
149
  - `getCountryByDialCode(dialCode)`
103
150
  - `getCountriesByDialCode(dialCode)`
151
+ - `getCountryOptions({ locale?, preferredCountries?, excludeCountries?, onlyCountries? })`
104
152
  - `detectCountryFromPhone(phone)`
105
153
 
106
- ### Utilities
107
-
108
- - `cleanPhone(phone)`
109
- - `formatPhone(phone, country)`
110
- - `unformatPhone(formattedPhone)`
111
- - `validatePhone(phone, country, validator?)`
112
- - `validatePhoneLength(phone, country)`
113
- - `addDialCode(phone, country)`
114
- - `removeDialCode(phone, country)`
115
- - `filterCountries(countries, query, preferredCountries?)`
116
- - `getPlaceholder(country)`
117
-
118
- Compatibility aliases are also exported for older consumers: `stripNonDigits`, `isInternationalFormat`, `detectCountry`, `formatPhoneNumber`, `parseToE164`, `getNationalNumber`, `validatePhoneNumber`, `isPhoneNumberComplete`, `formatAsYouType`, `normalizePhoneNumber`, `phoneNumbersEqual`, `getCountryDisplayLabel`, and `limitInputLength`.
154
+ ### Utilities
155
+
156
+ - `cleanPhone`, `formatPhone`, `unformatPhone`, `validatePhone`, `validatePhoneLength`
157
+ - `validatePhoneNumber` → `{ isValid, reason, message, error }`
158
+ - `parsePhoneValue` → `{ country, nationalNumber, e164, isValid }`
159
+ - `addDialCode`, `removeDialCode`, `filterCountries`, `getPlaceholder`
160
+
161
+ Compatibility aliases: `stripNonDigits`, `detectCountry`, `formatPhoneNumber`, `parseToE164`, `getNationalNumber`, `isPhoneNumberComplete`, `formatAsYouType`, `normalizePhoneNumber`, `phoneNumbersEqual`, `getCountryDisplayLabel`, `limitInputLength`.
119
162
 
120
163
  ## `usePhoneInput(options)`
121
164
 
122
165
  | Option | Type | Default | Description |
123
- |------|------|---------|-------------|
166
+ | --- | --- | --- | --- |
124
167
  | `defaultCountry` | `string` | `'US'` | Default selected country |
125
168
  | `preferredCountries` | `string[]` | - | Countries shown first in search results |
126
169
  | `excludeCountries` | `string[]` | - | Countries to exclude |
@@ -128,33 +171,11 @@ Compatibility aliases are also exported for older consumers: `stripNonDigits`, `
128
171
  | `autoDetect` | `boolean` | `true` | Detect country from international numbers |
129
172
  | `formatOnType` | `boolean` | `true` | Apply live formatting |
130
173
  | `includeDialCode` | `boolean` | `false` | Return values with dial code included |
174
+ | `required` | `boolean` | `false` | Empty value is invalid |
131
175
  | `validator` | `(phone, country) => boolean` | - | Custom validation override |
176
+ | `onValidationChange` | `(state) => void` | - | Fires when validation result changes |
132
177
 
133
- Important returned fields:
134
-
135
- - `phone`
136
- - `fullPhone`
137
- - `country`
138
- - `isValid`
139
- - `isOpen`
140
- - `searchQuery`
141
- - `filteredCountries`
142
- - `inputProps`
143
- - `countryButtonProps`
144
- - `setPhone()`
145
- - `setCountry()`
146
- - `selectCountry()`
147
- - `openDropdown()`
148
- - `closeDropdown()`
149
- - `toggleDropdown()`
150
- - `setSearchQuery()`
151
- - `clear()`
152
-
153
- ## Notes
154
-
155
- - Country coverage now comes from current `libphonenumber-js` supported regions instead of a short hand-maintained list, with fallback metadata for supported territories that are incomplete in `world-countries`.
156
- - Formatting and validation behavior follows `libphonenumber-js`, similar to libraries like `react-phone-number-input`.
157
- - The selector keeps a separate country button and number field, which matches the common multi-country pattern used by larger phone-input packages.
178
+ Important returned fields: `phone`, `fullPhone`, `country`, `isValid`, `validationReason`, `error`, `onValidationChange`, `filteredCountries`, `inputProps`, `countryButtonProps`, `dropdownProps`, `getCountryOptionId`.
158
179
 
159
180
  ## License
160
181
 
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),libphonenumberJs=require('libphonenumber-js'),Ze=require('libphonenumber-js/mobile/examples'),Je=require('world-countries'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Ze__default=/*#__PURE__*/_interopDefault(Ze);var Je__default=/*#__PURE__*/_interopDefault(Je);var et=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],tt=new Set(libphonenumberJs.getCountries()),nt=new Map(Je__default.default.map(e=>[e.cca2,e])),rt={AC:{name:"Ascension Island",dialCode:"+247"},TA:{name:"Tristan da Cunha",dialCode:"+290"},BQ:{name:"Caribbean Netherlands",dialCode:"+599"}};function ot(e,t){let n=e.startsWith("+")?e:`+${e}`,r=t.replace(/\D/g,"");return `${n}${r}`}function it(e){return e.toUpperCase().replace(/./g,t=>String.fromCodePoint(127397+t.charCodeAt(0)))}function at(e,t){let n=e?.idd?.root;if(!n)return [t];let o=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(l=>ot(n,l)).filter(l=>/^\+\d+$/.test(l));return Array.from(new Set([t,...o.length?o:[]]))}function st(e){let t=libphonenumberJs.getExampleNumber(e,Ze__default.default);return t?t.formatNational().replace(/\d/g,"#"):void 0}function Ee(e){let t=et.indexOf(e);return t===-1?Number.MAX_SAFE_INTEGER:t}var ut=Array.from(tt).map(e=>{let t=nt.get(e),n=rt[e],r=n?.dialCode??`+${libphonenumberJs.getCountryCallingCode(e)}`,o=at(t,r);return {code:e,name:t?.name.common??n?.name??e,dialCode:r,dialCodes:o,flag:t?.flag||n?.flag||it(e),format:st(e)}}).sort((e,t)=>{let n=Ee(e.code)-Ee(t.code);return n!==0?n:e.name.localeCompare(t.name)}),R=ut,lt=new Map(R.map(e=>[e.code,e])),ct=R.reduce((e,t)=>{for(let n of t.dialCodes){let r=e.get(n)??[];r.push(t),e.set(n,r);}return e},new Map),dt=R.flatMap(e=>e.dialCodes.map(t=>({dialCode:t,country:e}))).sort((e,t)=>t.dialCode.length-e.dialCode.length),Me=new Map;function pt(e){return Array.isArray(e)?[...e]:e?[e]:[]}function ft(e){let t=pt(e);if(t.length===0||typeof Intl>"u"||typeof Intl.DisplayNames>"u")return;let n=t.join("|"),r=Me.get(n);if(r)return r;try{let o=new Intl.DisplayNames(t,{type:"region"});return Me.set(n,o),o}catch{return}}function Ct(e){let t=e.replace(/\D/g,"");return t?`+${t}`:""}function j(e){return lt.get(e.toUpperCase())}function Re(e,t){return e?ft(t)?.of(e.code)??e.displayName??e.name:void 0}function X(e,t){if(!e)return;let n=Re(e,t);return n?{...e,displayName:n}:e}function Le(e,t){return t?e.map(n=>X(n,t)??n):e}function Fe(e){return ct.get(Ct(e))??[]}function yt(e){return Fe(e)[0]}function U(e){let t=e.trim();if(!t)return;let n=t.startsWith("+")?`+${t.replace(/\D/g,"")}`:t.startsWith("00")?`+${t.slice(2).replace(/\D/g,"")}`:"";if(!n)return;let r=libphonenumberJs.parsePhoneNumberFromString(n);return r?.country?j(r.country):dt.find(o=>n.startsWith(o.dialCode))?.country}var Ne={selectCountry:"Select country",countrySearchPlaceholder:"Search countries...",noCountriesFound:"No countries found",searchCountriesAriaLabel:"Search countries",countryOptionsAriaLabel:"Country options",countryButtonAriaLabel:"Open country selector"},gt={en:Ne,fr:{selectCountry:"Choisir un pays",countrySearchPlaceholder:"Rechercher un pays...",noCountriesFound:"Aucun pays trouv\xE9",searchCountriesAriaLabel:"Rechercher des pays",countryOptionsAriaLabel:"Options de pays",countryButtonAriaLabel:"Ouvrir le s\xE9lecteur de pays"},de:{selectCountry:"Land ausw\xE4hlen",countrySearchPlaceholder:"Land suchen...",noCountriesFound:"Keine L\xE4nder gefunden",searchCountriesAriaLabel:"L\xE4nder suchen",countryOptionsAriaLabel:"L\xE4nderoptionen",countryButtonAriaLabel:"L\xE4nderauswahl \xF6ffnen"},es:{selectCountry:"Seleccionar pa\xEDs",countrySearchPlaceholder:"Buscar pa\xEDs...",noCountriesFound:"No se encontraron pa\xEDses",searchCountriesAriaLabel:"Buscar pa\xEDses",countryOptionsAriaLabel:"Opciones de pa\xEDs",countryButtonAriaLabel:"Abrir selector de pa\xEDs"},pt:{selectCountry:"Selecionar pa\xEDs",countrySearchPlaceholder:"Pesquisar pa\xEDs...",noCountriesFound:"Nenhum pa\xEDs encontrado",searchCountriesAriaLabel:"Pesquisar pa\xEDses",countryOptionsAriaLabel:"Op\xE7\xF5es de pa\xEDs",countryButtonAriaLabel:"Abrir seletor de pa\xEDs"},it:{selectCountry:"Seleziona paese",countrySearchPlaceholder:"Cerca paese...",noCountriesFound:"Nessun paese trovato",searchCountriesAriaLabel:"Cerca paesi",countryOptionsAriaLabel:"Opzioni paese",countryButtonAriaLabel:"Apri selettore paese"},ja:{selectCountry:"\u56FD\u3092\u9078\u629E",countrySearchPlaceholder:"\u56FD\u3092\u691C\u7D22...",noCountriesFound:"\u56FD\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",searchCountriesAriaLabel:"\u56FD\u3092\u691C\u7D22",countryOptionsAriaLabel:"\u56FD\u306E\u5019\u88DC",countryButtonAriaLabel:"\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F"},ko:{selectCountry:"\uAD6D\uAC00 \uC120\uD0DD",countrySearchPlaceholder:"\uAD6D\uAC00 \uAC80\uC0C9...",noCountriesFound:"\uAD6D\uAC00\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",searchCountriesAriaLabel:"\uAD6D\uAC00 \uAC80\uC0C9",countryOptionsAriaLabel:"\uAD6D\uAC00 \uC635\uC158",countryButtonAriaLabel:"\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30"},zh:{selectCountry:"\u9009\u62E9\u56FD\u5BB6",countrySearchPlaceholder:"\u641C\u7D22\u56FD\u5BB6...",noCountriesFound:"\u672A\u627E\u5230\u56FD\u5BB6",searchCountriesAriaLabel:"\u641C\u7D22\u56FD\u5BB6",countryOptionsAriaLabel:"\u56FD\u5BB6\u9009\u9879",countryButtonAriaLabel:"\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668"},ar:{selectCountry:"\u0627\u062E\u062A\u0631 \u0627\u0644\u062F\u0648\u0644\u0629",countrySearchPlaceholder:"\u0627\u0628\u062D\u062B \u0639\u0646 \u062F\u0648\u0644\u0629...",noCountriesFound:"\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u062F\u0648\u0644",searchCountriesAriaLabel:"\u0627\u0628\u062D\u062B \u0639\u0646 \u0627\u0644\u062F\u0648\u0644",countryOptionsAriaLabel:"\u062E\u064A\u0627\u0631\u0627\u062A \u0627\u0644\u062F\u0648\u0644",countryButtonAriaLabel:"\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629"},hi:{selectCountry:"\u0926\u0947\u0936 \u091A\u0941\u0928\u0947\u0902",countrySearchPlaceholder:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902...",noCountriesFound:"\u0915\u094B\u0908 \u0926\u0947\u0936 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E",searchCountriesAriaLabel:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902",countryOptionsAriaLabel:"\u0926\u0947\u0936 \u0935\u093F\u0915\u0932\u094D\u092A",countryButtonAriaLabel:"\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902"}};function mt(e){let n=(Array.isArray(e)?e:e?[e]:[]).find(Boolean);return n?n.toLowerCase().split("-")[0]:void 0}function xe(e,t){let n=mt(e),r=n?gt[n]:void 0;return {...Ne,...r,...t}}function _(e){let t=e.trim(),n=d(t);return t.startsWith("+")&&!n?"+":n?t.startsWith("+")?`+${n}`:n:""}function Ie(e){return e?.code}function ze(e){return e?.format?.replace(/[^#]/g,"").length}function d(e){return e.replace(/\D/g,"")}function H(e,t){return e&&new libphonenumberJs.AsYouType(Ie(t)).input(_(e))}function le(e){return _(e)}function Te(e,t){return !e||!t?false:e.trim().startsWith("+")?libphonenumberJs.validatePhoneNumberLength(_(e))===void 0:libphonenumberJs.validatePhoneNumberLength(d(e),Ie(t))===void 0}function ce(e,t,n){if(!e)return false;if(n)return n(e,t??void 0);let r=_(e),o=Ie(t);return o?r.startsWith("+")?libphonenumberJs.isValidPhoneNumber(r):libphonenumberJs.isValidPhoneNumber(d(r),o):libphonenumberJs.isPossiblePhoneNumber(r.startsWith("+")?r:`+${d(r)}`)}function B(e,t){if(!t)return e;let n=_(e);if(!n||n==="+")return "";if(n.startsWith("+"))return n;let r=d(n);return t.dialCodes.find(l=>r.startsWith(l.replace("+","")))?`+${r}`:`${t.dialCode}${r}`}function O(e,t){if(!t)return e;let n=_(e),r=d(n),o=d(t.dialCode);if(r.startsWith(o))return r.slice(o.length);for(let l of t.dialCodes){let y=l.replace("+","");if(r.startsWith(y))return r.slice(y.length)}return r}function De(e,t,n){let r=t.toLowerCase().trim();return r?e.filter(o=>o.name.toLowerCase().includes(r)||(o.displayName??"").toLowerCase().includes(r)||o.code.toLowerCase().includes(r)||o.dialCodes.some(l=>l.includes(r))):n?.length?[...e].sort((o,l)=>{let y=n.indexOf(o.code),C=n.indexOf(l.code);return y!==-1&&C!==-1?y-C:y!==-1?-1:C!==-1?1:(o.displayName??o.name).localeCompare(l.displayName??l.name)}):e}function de(e){return e?.displayName??e?.name??""}function ve(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}var Pt=d;function Z(e){return e.trim().startsWith("+")||e.trim().startsWith("00")}function Lt(e){let t=d(e);if(!Z(e))return {dialCode:null,nationalNumber:t};let n=R.map(o=>o.dialCode).sort((o,l)=>l.length-o.length).find(o=>t.startsWith(d(o)));if(!n)return {dialCode:null,nationalNumber:t};let r=d(n);return {dialCode:r,nationalNumber:t.slice(r.length)}}function Nt(e){return U(e)??null}function xt(e,t,n="national"){if(!e)return "";if(n==="e164")return B(e,t);let r=Z(e)?O(e,t):e;if(!t&&n==="national")return d(r).slice(0,9).replace(/(\d{3})(?=\d)/g,"$1 ").trim();let o=H(r,t);return n==="international"?t?`${t.dialCode} ${o}`:B(e,t):o}function At(e,t){return B(e,t)}function It(e,t){if(t)return O(e,t);let n=U(e);return n?O(e,n):d(e)}function Se(e,t,n=false){let r=d(e);if(!r)return n?{isValid:false,error:"Phone number is required"}:{isValid:true,error:null};let o=ze(t),l=t?d(O(e,t)):r;return l.length<7?{isValid:false,error:"Phone number is too short"}:o&&l.length>o?{isValid:false,error:`Phone number is too long (max ${o} digits)`}:ce(e,t)?{isValid:true,error:null}:{isValid:false,error:"Invalid phone number"}}function Dt(e,t){return t?Te(e,t):d(e).length>=7}function vt(e,t){return Z(e)&&t?`${t.dialCode} ${H(O(e,t),t)}`:H(e,t)}var Ae=d;function St(e,t){return Ae(e)===Ae(t)}function wt(e,t=true){let n=`${e.flag} ${de(e)}`;return t?`${n} (${e.dialCode})`:n}function Bt(e,t){let n=ze(t);if(!n)return e;let r=Z(e),o=d(e),l=t?d(t.dialCode):"",y=r?l.length+n:n,C=o.slice(0,y);return r?`+${C}`:C}function Et(e,t){return e.slice(0,t).replace(/\D/g,"").length}function Mt(e,t){if(t<=0)return e.startsWith("+")?1:0;let n=0;for(let r=0;r<e.length;r+=1)if(/\d/.test(e[r])&&(n+=1,n===t))return r+1;return e.length}function Be(e={}){let{value:t,defaultValue:n="",onChange:r,onCountryChange:o,onBlur:l,onFocus:y,defaultCountry:C="US",preferredCountries:ee,excludeCountries:fe,excludedCountries:Ce,onlyCountries:ye,allowedCountries:ge,autoDetect:q,autoDetectCountry:me,formatOnType:te=true,includeDialCode:m=false,required:ne=false,validator:re,locale:N,labels:$}=e,F=ye??ge,I=fe??Ce,x=q??me??true,D=t!==void 0,z=react.useRef(null),G=react.useRef(null),v=react.useRef(C),p=react.useMemo(()=>{let i=R;return F?.length&&(i=i.filter(a=>F.includes(a.code))),I?.length&&(i=i.filter(a=>!I.includes(a.code))),i},[F,I]),Q=react.useMemo(()=>Le(p,N),[p,N]),T=react.useMemo(()=>xe(N,$),[N,$]),he=p.find(i=>i.code===C)||p[0],[be,oe]=react.useState(n),[s,W]=react.useState(he),[k,M]=react.useState(false),[S,P]=react.useState(""),u=D?t:be,g=react.useCallback(i=>X(i,N),[N]);react.useEffect(()=>{let i=v.current!==C;v.current=C;let a=p.find(Y=>Y.code===C)||p[0],h=s?p.some(Y=>Y.code===s.code):false;a&&(i||!h)&&W(a);},[C,p,s]),react.useEffect(()=>{if(x&&u){let i=U(u);i&&p.some(a=>a.code===i.code)&&i.code!==s?.code&&(W(i),o?.(g(i)));}},[p,x,u,s?.code,o,g]);let V=react.useMemo(()=>te?H(m&&u.startsWith("+")?O(u,s):u,s):m&&u.startsWith("+")?O(u,s):u,[te,m,u,s]),Pe=react.useMemo(()=>m&&s?B(u,s):u,[u,s,m]),ie=react.useMemo(()=>ce(u,s,re),[u,s,re]),c=react.useMemo(()=>Se(u,s,ne).error,[u,s,ne]),w=react.useMemo(()=>X(s,N),[s,N]),L=react.useMemo(()=>De(Q,S,ee),[Q,S,ee]);react.useLayoutEffect(()=>{let i=G.current,a=z.current;if(i===null||!a||typeof a.setSelectionRange!="function"||typeof document<"u"&&document.activeElement!==a)return;let h=Mt(V,i);a.setSelectionRange(h,h),G.current=null;},[V]);let A=react.useCallback(i=>{let a=le(i);D||oe(a),r?.(m?B(a,s):a,g(s));},[D,r,s,m,g]),Ue=react.useCallback(i=>{let a=j(i);a&&(W(a),o?.(g(a)),r?.(m?B(u,a):u,g(a)));},[u,r,o,m,g]),ae=react.useCallback(i=>{let a=j(i.code)??i;W(a),M(false),P(""),o?.(g(a)),r?.(m?B(u,a):u,g(a));},[u,r,o,m,g]),se=react.useCallback(()=>{M(i=>!i),k&&P("");},[k]),Oe=react.useCallback(()=>{M(true);},[]),ue=react.useCallback(()=>{M(false),P("");},[]),He=react.useCallback(()=>{D||oe(""),r?.("",g(s));},[D,r,s,g]),_e=react.useCallback(i=>{let a=i.target.value,h=i.target.selectionStart??a.length,Y=a.trim().startsWith("+")?`+${a.replace(/\D/g,"")}`:le(a);G.current=Et(a,h),A(Y);},[A]),Ke=react.useCallback(()=>{y?.();},[y]),qe=react.useCallback(()=>{l?.();},[l]),Ge=react.useCallback((i,a)=>({role:"option","aria-selected":i.code===s?.code,onClick:()=>ae(i),onKeyDown:h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),ae(i)),h.key==="Escape"&&(h.preventDefault(),ue());},tabIndex:a===0?0:-1}),[ue,s?.code,ae]);return {phone:u,value:u,fullPhone:Pe,country:w,isValid:ie,error:c,isOpen:k,searchQuery:S,labels:T,formattedValue:V,setPhone:A,setValue:A,setCountry:Ue,toggleDropdown:se,toggle:se,openDropdown:Oe,open:Oe,closeDropdown:ue,close:ue,setSearchQuery:P,clear:He,inputProps:{ref:z,value:V,onChange:_e,onFocus:Ke,onBlur:qe,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:ve(s),"aria-invalid":u?!ie:void 0},countryButtonProps:{onClick:se,"aria-expanded":k,"aria-haspopup":"listbox","aria-label":T.countryButtonAriaLabel},countrySelectorProps:{onClick:se,"aria-expanded":k,"aria-haspopup":true,"aria-label":T.countryButtonAriaLabel},dropdownProps:{role:"listbox","aria-label":T.countryOptionsAriaLabel},filteredCountries:L,countries:L,selectCountry:ae,getCountryOptionProps:Ge}}var Tt=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"18 15 12 9 6 15"})}),Wt=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})}),Vt=react.forwardRef(function(t,n){let{value:r,defaultValue:o,onChange:l,onBlur:y,onFocus:C,inputClassName:ee,selectorClassName:fe,containerClassName:Ce,searchable:ye=true,placeholder:ge,disabled:q,readOnly:me,name:te,id:m,"aria-label":ne,"aria-labelledby":re,...N}=t,$=react.useRef(null),F=react.useRef([]),[I,x]=react.useState(0),D=react.useId(),{inputProps:z,countryButtonProps:G,country:v,filteredCountries:p,isOpen:Q,isValid:T,searchQuery:he,setSearchQuery:be,setCountry:oe,selectCountry:s,clear:W,openDropdown:k,closeDropdown:M,labels:S}=Be({value:r,defaultValue:o,onChange:l,onBlur:y,onFocus:C,...N}),P=z.ref,u=react.useCallback(c=>{$.current=c,typeof P=="function"?P(c):P&&"current"in P&&(P.current=c);},[P]),g=react.useCallback(()=>{$.current?.focus();},[]),V=react.useCallback(()=>{$.current?.blur();},[]),Pe=react.useCallback(c=>{s(c),x(0);},[s]),ie=react.useCallback((c,w,L)=>{switch(c.key){case "Enter":case " ":c.preventDefault(),s(w),x(0);break;case "ArrowDown":if(c.preventDefault(),L<p.length-1){let A=L+1;x(A),F.current[A]?.focus();}break;case "ArrowUp":if(c.preventDefault(),L>0){let A=L-1;x(A),F.current[A]?.focus();}break;case "Escape":c.preventDefault(),M();break}},[s,p.length,M]);return react.useEffect(()=>{if(p.length===0){I!==0&&x(0);return}I>=p.length&&x(p.length-1);},[p.length,I]),react.useImperativeHandle(n,()=>({focus:g,blur:V,clear:W,setCountry:oe,getCountry:()=>v,open:k,close:M})),jsxRuntime.jsxs("div",{className:Ce,"data-valid":T,children:[jsxRuntime.jsxs("button",{...G,type:"button",className:fe,disabled:q,tabIndex:q?-1:0,"aria-controls":D,children:[v?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:v.flag}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:v.dialCode})]}):jsxRuntime.jsx("span",{className:"phone-input-placeholder",children:S.selectCountry}),jsxRuntime.jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:Q?jsxRuntime.jsx(Tt,{size:12}):jsxRuntime.jsx(Wt,{size:12})})]}),jsxRuntime.jsx("input",{...z,ref:u,id:m,name:te,className:ee,placeholder:ge||z.placeholder,disabled:q,readOnly:me,"aria-label":ne,"aria-labelledby":re}),Q&&jsxRuntime.jsxs("div",{className:"phone-input-dropdown",children:[ye&&jsxRuntime.jsx("div",{className:"phone-input-search",children:jsxRuntime.jsx("input",{type:"text",value:he,onChange:c=>be(c.target.value),placeholder:S.countrySearchPlaceholder,autoFocus:true,"aria-controls":D,"aria-label":S.searchCountriesAriaLabel})}),jsxRuntime.jsxs("ul",{className:"phone-input-country-list",id:D,role:"listbox","aria-label":S.countryOptionsAriaLabel,children:[p.map((c,w)=>jsxRuntime.jsxs("li",{ref:L=>{F.current[w]=L;},role:"option","aria-selected":c.code===v?.code,className:`phone-input-country-option ${c.code===v?.code?"selected":""} ${w===I?"highlighted":""}`,onClick:()=>Pe(c),onKeyDown:L=>ie(L,c,w),onMouseEnter:()=>x(w),tabIndex:w===I?0:-1,children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:c.flag}),jsxRuntime.jsx("span",{className:"phone-input-country-name",children:de(c)}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:c.dialCode})]},c.code)),p.length===0&&jsxRuntime.jsx("li",{className:"phone-input-no-results",children:S.noCountriesFound})]})]})]})});exports.DEFAULT_PHONE_INPUT_LABELS=Ne;exports.PhoneInput=Vt;exports.addDialCode=B;exports.cleanPhone=d;exports.countries=R;exports.detectCountry=Nt;exports.detectCountryFromPhone=U;exports.extractDialCode=Lt;exports.filterCountries=De;exports.formatAsYouType=vt;exports.formatPhone=H;exports.formatPhoneNumber=xt;exports.getCountriesByDialCode=Fe;exports.getCountryByCode=j;exports.getCountryByDialCode=yt;exports.getCountryDisplayLabel=wt;exports.getCountryDisplayName=de;exports.getLocalizedCountryName=Re;exports.getNationalNumber=It;exports.getPlaceholder=ve;exports.isInternationalFormat=Z;exports.isPhoneNumberComplete=Dt;exports.limitInputLength=Bt;exports.localizeCountries=Le;exports.localizeCountry=X;exports.normalizePhoneNumber=Ae;exports.parseToE164=At;exports.phoneNumbersEqual=St;exports.removeDialCode=O;exports.resolvePhoneInputLabels=xe;exports.stripNonDigits=Pt;exports.unformatPhone=le;exports.usePhoneInput=Be;exports.validatePhone=ce;exports.validatePhoneLength=Te;exports.validatePhoneNumber=Se;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var react=require('react'),libphonenumberJs=require('libphonenumber-js'),rn=require('libphonenumber-js/mobile/examples'),on=require('world-countries'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var rn__default=/*#__PURE__*/_interopDefault(rn);var on__default=/*#__PURE__*/_interopDefault(on);var an=["US","GB","CA","AU","DE","FR","IT","ES","JP","CN","IN","BR","MX","KR","NL","CH","SE","AE","SG","ZA","NG","SA","TR","ID","PH","TH","VN","MY","NZ","AR"],sn=new Set(libphonenumberJs.getCountries()),un=new Map(on__default.default.map(e=>[e.cca2,e])),ln={AC:{name:"Ascension Island",dialCode:"+247"},TA:{name:"Tristan da Cunha",dialCode:"+290"},BQ:{name:"Caribbean Netherlands",dialCode:"+599"}};function dn(e,n){let t=e.startsWith("+")?e:`+${e}`,r=n.replace(/\D/g,"");return `${t}${r}`}function cn(e){return e.toUpperCase().replace(/./g,n=>String.fromCodePoint(127397+n.charCodeAt(0)))}function pn(e,n){let t=e?.idd?.root;if(!t)return [n];let o=(e.idd?.suffixes?.length?e.idd.suffixes:[""]).map(s=>dn(t,s)).filter(s=>/^\+\d+$/.test(s));return Array.from(new Set([n,...o.length?o:[]]))}function fn(e){let n=libphonenumberJs.getExampleNumber(e,rn__default.default);return n?n.formatNational().replace(/\d/g,"#"):void 0}function Ve(e){let n=an.indexOf(e);return n===-1?Number.MAX_SAFE_INTEGER:n}var Cn=Array.from(sn).map(e=>{let n=un.get(e),t=ln[e],r=t?.dialCode??`+${libphonenumberJs.getCountryCallingCode(e)}`,o=pn(n,r);return {code:e,name:n?.name.common??t?.name??e,dialCode:r,dialCodes:o,flag:n?.flag||t?.flag||cn(e),format:fn(e)}}).sort((e,n)=>{let t=Ve(e.code)-Ve(n.code);return t!==0?t:e.name.localeCompare(n.name)}),S=Cn,gn=new Map(S.map(e=>[e.code,e])),yn=S.reduce((e,n)=>{for(let t of n.dialCodes){let r=e.get(t)??[];r.push(n),e.set(t,r);}return e},new Map),mn=S.flatMap(e=>e.dialCodes.map(n=>({dialCode:n,country:e}))).sort((e,n)=>n.dialCode.length-e.dialCode.length),$e=new Map;function hn(e){return Array.isArray(e)?[...e]:e?[e]:[]}function bn(e){let n=hn(e);if(n.length===0||typeof Intl>"u"||typeof Intl.DisplayNames>"u")return;let t=n.join("|"),r=$e.get(t);if(r)return r;try{let o=new Intl.DisplayNames(n,{type:"region"});return $e.set(t,o),o}catch{return}}function Pn(e){let n=e.replace(/\D/g,"");return n?`+${n}`:""}function T(e){return gn.get(e.toUpperCase())}function ke(e,n){return e?bn(n)?.of(e.code)??e.displayName??e.name:void 0}function Z(e,n){if(!e)return;let t=ke(e,n);return t?{...e,displayName:t}:e}function le(e,n){return n?e.map(t=>Z(t,n)??t):e}function ze(e){return yn.get(Pn(e))??[]}function Ln(e){return ze(e)[0]}function xn(e={}){let n=S;if(e.onlyCountries?.length){let t=new Set(e.onlyCountries.map(r=>r.toUpperCase()));n=n.filter(r=>t.has(r.code));}if(e.excludeCountries?.length){let t=new Set(e.excludeCountries.map(r=>r.toUpperCase()));n=n.filter(r=>!t.has(r.code));}if(n=le(n,e.locale),e.preferredCountries?.length){let t=e.preferredCountries.map(r=>r.toUpperCase());n=[...n].sort((r,o)=>{let s=t.indexOf(r.code),c=t.indexOf(o.code);return s!==-1&&c!==-1?s-c:s!==-1?-1:c!==-1?1:(r.displayName??r.name).localeCompare(o.displayName??o.name)});}return n.map(t=>({value:t.code,label:`${t.displayName??t.name} (${t.dialCode})`,dialCode:t.dialCode,flag:t.flag}))}function q(e){let n=e.trim();if(!n)return;let t=n.startsWith("+")?`+${n.replace(/\D/g,"")}`:n.startsWith("00")?`+${n.slice(2).replace(/\D/g,"")}`:"";if(!t)return;let r=libphonenumberJs.parsePhoneNumberFromString(t);return r?.country?T(r.country):mn.find(o=>t.startsWith(o.dialCode))?.country}var De={selectCountry:"Select country",countrySearchPlaceholder:"Search countries...",noCountriesFound:"No countries found",searchCountriesAriaLabel:"Search countries",countryOptionsAriaLabel:"Country options",countryButtonAriaLabel:"Open country selector"},Nn={en:De,fr:{selectCountry:"Choisir un pays",countrySearchPlaceholder:"Rechercher un pays...",noCountriesFound:"Aucun pays trouv\xE9",searchCountriesAriaLabel:"Rechercher des pays",countryOptionsAriaLabel:"Options de pays",countryButtonAriaLabel:"Ouvrir le s\xE9lecteur de pays"},de:{selectCountry:"Land ausw\xE4hlen",countrySearchPlaceholder:"Land suchen...",noCountriesFound:"Keine L\xE4nder gefunden",searchCountriesAriaLabel:"L\xE4nder suchen",countryOptionsAriaLabel:"L\xE4nderoptionen",countryButtonAriaLabel:"L\xE4nderauswahl \xF6ffnen"},es:{selectCountry:"Seleccionar pa\xEDs",countrySearchPlaceholder:"Buscar pa\xEDs...",noCountriesFound:"No se encontraron pa\xEDses",searchCountriesAriaLabel:"Buscar pa\xEDses",countryOptionsAriaLabel:"Opciones de pa\xEDs",countryButtonAriaLabel:"Abrir selector de pa\xEDs"},pt:{selectCountry:"Selecionar pa\xEDs",countrySearchPlaceholder:"Pesquisar pa\xEDs...",noCountriesFound:"Nenhum pa\xEDs encontrado",searchCountriesAriaLabel:"Pesquisar pa\xEDses",countryOptionsAriaLabel:"Op\xE7\xF5es de pa\xEDs",countryButtonAriaLabel:"Abrir seletor de pa\xEDs"},it:{selectCountry:"Seleziona paese",countrySearchPlaceholder:"Cerca paese...",noCountriesFound:"Nessun paese trovato",searchCountriesAriaLabel:"Cerca paesi",countryOptionsAriaLabel:"Opzioni paese",countryButtonAriaLabel:"Apri selettore paese"},ja:{selectCountry:"\u56FD\u3092\u9078\u629E",countrySearchPlaceholder:"\u56FD\u3092\u691C\u7D22...",noCountriesFound:"\u56FD\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",searchCountriesAriaLabel:"\u56FD\u3092\u691C\u7D22",countryOptionsAriaLabel:"\u56FD\u306E\u5019\u88DC",countryButtonAriaLabel:"\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F"},ko:{selectCountry:"\uAD6D\uAC00 \uC120\uD0DD",countrySearchPlaceholder:"\uAD6D\uAC00 \uAC80\uC0C9...",noCountriesFound:"\uAD6D\uAC00\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",searchCountriesAriaLabel:"\uAD6D\uAC00 \uAC80\uC0C9",countryOptionsAriaLabel:"\uAD6D\uAC00 \uC635\uC158",countryButtonAriaLabel:"\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30"},zh:{selectCountry:"\u9009\u62E9\u56FD\u5BB6",countrySearchPlaceholder:"\u641C\u7D22\u56FD\u5BB6...",noCountriesFound:"\u672A\u627E\u5230\u56FD\u5BB6",searchCountriesAriaLabel:"\u641C\u7D22\u56FD\u5BB6",countryOptionsAriaLabel:"\u56FD\u5BB6\u9009\u9879",countryButtonAriaLabel:"\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668"},ar:{selectCountry:"\u0627\u062E\u062A\u0631 \u0627\u0644\u062F\u0648\u0644\u0629",countrySearchPlaceholder:"\u0627\u0628\u062D\u062B \u0639\u0646 \u062F\u0648\u0644\u0629...",noCountriesFound:"\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u062F\u0648\u0644",searchCountriesAriaLabel:"\u0627\u0628\u062D\u062B \u0639\u0646 \u0627\u0644\u062F\u0648\u0644",countryOptionsAriaLabel:"\u062E\u064A\u0627\u0631\u0627\u062A \u0627\u0644\u062F\u0648\u0644",countryButtonAriaLabel:"\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629"},hi:{selectCountry:"\u0926\u0947\u0936 \u091A\u0941\u0928\u0947\u0902",countrySearchPlaceholder:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902...",noCountriesFound:"\u0915\u094B\u0908 \u0926\u0947\u0936 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E",searchCountriesAriaLabel:"\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902",countryOptionsAriaLabel:"\u0926\u0947\u0936 \u0935\u093F\u0915\u0932\u094D\u092A",countryButtonAriaLabel:"\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902"}};function vn(e){let t=(Array.isArray(e)?e:e?[e]:[]).find(Boolean);return t?t.toLowerCase().split("-")[0]:void 0}function Ae(e,n){let t=vn(e),r=t?Nn[t]:void 0;return {...De,...r,...n}}function W(e){let n=e.trim(),t=p(n);return n.startsWith("+")&&!t?"+":t?n.startsWith("+")?`+${t}`:t:""}function ce(e){return e?.code}function He(e){return e?.format?.replace(/[^#]/g,"").length}function p(e){return e.replace(/\D/g,"")}function K(e,n){return e&&new libphonenumberJs.AsYouType(ce(n)).input(W(e))}function pe(e){return W(e)}function Ge(e,n){return !e||!n?false:e.trim().startsWith("+")?libphonenumberJs.validatePhoneNumberLength(W(e))===void 0:libphonenumberJs.validatePhoneNumberLength(p(e),ce(n))===void 0}function qe(e,n,t){if(!e)return false;if(t)return t(e,n??void 0);let r=W(e),o=ce(n);return o?r.startsWith("+")?libphonenumberJs.isValidPhoneNumber(r):libphonenumberJs.isValidPhoneNumber(p(r),o):libphonenumberJs.isPossiblePhoneNumber(r.startsWith("+")?r:`+${p(r)}`)}function B(e,n){if(!n)return e;let t=W(e);if(!t||t==="+")return "";if(t.startsWith("+"))return t;let r=p(t);return n.dialCodes.find(s=>r.startsWith(s.replace("+","")))?`+${r}`:`${n.dialCode}${r}`}function O(e,n){if(!n)return e;let t=W(e),r=p(t),o=p(n.dialCode);if(r.startsWith(o))return r.slice(o.length);for(let s of n.dialCodes){let c=s.replace("+","");if(r.startsWith(c))return r.slice(c.length)}return r}function we(e,n,t){let r=n.toLowerCase().trim();return r?e.filter(o=>o.name.toLowerCase().includes(r)||(o.displayName??"").toLowerCase().includes(r)||o.code.toLowerCase().includes(r)||o.dialCodes.some(s=>s.includes(r))):t?.length?[...e].sort((o,s)=>{let c=t.indexOf(o.code),y=t.indexOf(s.code);return c!==-1&&y!==-1?c-y:c!==-1?-1:y!==-1?1:(o.displayName??o.name).localeCompare(s.displayName??s.name)}):e}function fe(e){return e?.displayName??e?.name??""}function Re(e){return e?.format?e.format.replace(/#/g,"0"):e?.dialCode?`${e.dialCode} 000 000 0000`:"Phone number"}var An=p;function J(e){return e.trim().startsWith("+")||e.trim().startsWith("00")}function On(e){let n=p(e);if(!J(e))return {dialCode:null,nationalNumber:n};let t=S.map(o=>o.dialCode).sort((o,s)=>s.length-o.length).find(o=>n.startsWith(p(o)));if(!t)return {dialCode:null,nationalNumber:n};let r=p(t);return {dialCode:r,nationalNumber:n.slice(r.length)}}function wn(e){return q(e)??null}function Rn(e,n,t="national"){if(!e)return "";if(t==="e164")return B(e,n);let r=J(e)?O(e,n):e;if(!n&&t==="national")return p(r).slice(0,9).replace(/(\d{3})(?=\d)/g,"$1 ").trim();let o=K(r,n);return t==="international"?n?`${n.dialCode} ${o}`:B(e,n):o}function En(e,n){return B(e,n)}function Sn(e,n){if(n)return O(e,n);let t=q(e);return t?O(e,t):p(e)}function de(e,n){return {isValid:false,reason:e,message:n,error:n}}function _e(){return {isValid:true,reason:null,message:null,error:null}}function Ee(e,n,t=false,r){let o=p(e);if(!o)return t?de("required","Phone number is required"):_e();let s=He(n),c=n?p(O(e,n)):o;return c.length<7?de("too_short","Phone number is too short"):s&&c.length>s?de("too_long",`Phone number is too long (max ${s} digits)`):(r?r(e,n??void 0):qe(e,n))?_e():de("invalid","Invalid phone number")}function Bn(e,n){let t=ce(n),r=W(e),o=r.startsWith("+")?libphonenumberJs.parsePhoneNumberFromString(r):libphonenumberJs.parsePhoneNumberFromString(p(r),t);if(!o){let c=n?O(e,n):p(e);return {country:n??void 0,nationalNumber:c,e164:void 0,isValid:false}}return {country:o.country?T(o.country):n??void 0,nationalNumber:o.nationalNumber,e164:o.isValid()?o.number:void 0,isValid:o.isValid()}}function Mn(e,n){return n?Ge(e,n):p(e).length>=7}function Fn(e,n){return J(e)&&n?`${n.dialCode} ${K(O(e,n),n)}`:K(e,n)}var Oe=p;function Vn(e,n){return Oe(e)===Oe(n)}function $n(e,n=true){let t=`${e.flag} ${fe(e)}`;return n?`${t} (${e.dialCode})`:t}function kn(e,n){let t=He(n);if(!t)return e;let r=J(e),o=p(e),s=n?p(n.dialCode):"",c=r?s.length+t:t,y=o.slice(0,c);return r?`+${y}`:y}function Tn(e,n){return e.slice(0,n).replace(/\D/g,"").length}function Wn(e,n){if(n<=0)return e.startsWith("+")?1:0;let t=0;for(let r=0;r<e.length;r+=1)if(/\d/.test(e[r])&&(t+=1,t===n))return r+1;return e.length}function Me(e={}){let{value:n,defaultValue:t="",onChange:r,onCountryChange:o,onBlur:s,onFocus:c,defaultCountry:y="US",preferredCountries:ne,excludeCountries:ge,excludedCountries:ye,onlyCountries:me,allowedCountries:he,autoDetect:Y,autoDetectCountry:be,formatOnType:te=true,includeDialCode:L=false,required:re=false,validator:oe,onValidationChange:ie,locale:P,labels:U}=e,V=me??he,I=ge??ye,D=Y??be??true,w=n!==void 0,_=react.useRef(null),j=react.useRef(null),ae=react.useRef(y),C=react.useMemo(()=>{let i=S;return V?.length&&(i=i.filter(a=>V.includes(a.code))),I?.length&&(i=i.filter(a=>!I.includes(a.code))),i},[V,I]),N=react.useMemo(()=>le(C,P),[C,P]),R=react.useMemo(()=>Ae(P,U),[P,U]),Pe=C.find(i=>i.code===y)||C[0],[Le,se]=react.useState(t),[d,E]=react.useState(Pe),[$,H]=react.useState(false),[A,k]=react.useState(""),l=w?n:Le,f=react.useCallback(i=>Z(i,P),[P]);react.useEffect(()=>{let i=ae.current!==y;ae.current=y;let a=C.find(X=>X.code===y)||C[0],v=d?C.some(X=>X.code===d.code):false;a&&(i||!v)&&E(a);},[y,C,d]),react.useEffect(()=>{if(D&&l){let i=q(l);i&&C.some(a=>a.code===i.code)&&i.code!==d?.code&&(E(i),o?.(f(i)));}},[C,D,l,d?.code,o,f]);let G=react.useMemo(()=>te?K(L&&l.startsWith("+")?O(l,d):l,d):L&&l.startsWith("+")?O(l,d):l,[te,L,l,d]),xe=react.useMemo(()=>L&&d?B(l,d):l,[l,d,L]),M=react.useMemo(()=>Ee(l,d,re,oe),[l,d,re,oe]);react.useEffect(()=>{ie?.(M);},[M,ie]);let Ne=react.useMemo(()=>Z(d,P),[d,P]),ue=react.useMemo(()=>we(N,A,ne),[N,A,ne]);react.useLayoutEffect(()=>{let i=j.current,a=_.current;if(i===null||!a||typeof a.setSelectionRange!="function"||typeof document<"u"&&document.activeElement!==a)return;let v=Wn(G,i);a.setSelectionRange(v,v),j.current=null;},[G]);let z=react.useCallback(i=>{let a=pe(i);w||se(a),r?.(L?B(a,d):a,f(d));},[w,r,d,L,f]),ve=react.useCallback(i=>{let a=T(i);a&&(E(a),o?.(f(a)),r?.(L?B(l,a):l,f(a)));},[l,r,o,L,f]),u=react.useCallback(i=>{let a=T(i.code)??i;E(a),H(false),k(""),o?.(f(a)),r?.(L?B(l,a):l,f(a));},[l,r,o,L,f]),h=react.useCallback(()=>{H(i=>!i),$&&k("");},[$]),b=react.useCallback(()=>{H(true);},[]),m=react.useCallback(()=>{H(false),k("");},[]),Qe=react.useCallback(()=>{w||se(""),r?.("",f(d));},[w,r,d,f]),Ye=react.useCallback(i=>{let a=i.target.value,v=i.target.selectionStart??a.length,X=a.trim().startsWith("+")?`+${a.replace(/\D/g,"")}`:pe(a);j.current=Tn(a,v),z(X);},[z]),je=react.useCallback(()=>{c?.();},[c]),Xe=react.useCallback(()=>{s?.();},[s]),Ie=react.useCallback(i=>`phone-input-country-${i}`,[]),Ze=react.useCallback((i,a)=>({id:Ie(i.code),role:"option","aria-selected":i.code===d?.code,onClick:()=>u(i),onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),u(i)),v.key==="Escape"&&(v.preventDefault(),m());},tabIndex:a===0?0:-1}),[m,d?.code,Ie,u]);return {phone:l,value:l,fullPhone:xe,country:Ne,isValid:M.isValid,validationReason:M.reason,error:M.error,isOpen:$,searchQuery:A,labels:R,formattedValue:G,setPhone:z,setValue:z,setCountry:ve,toggleDropdown:h,toggle:h,openDropdown:b,open:b,closeDropdown:m,close:m,setSearchQuery:k,clear:Qe,inputProps:{ref:_,value:G,onChange:Ye,onFocus:je,onBlur:Xe,type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:Re(d),"aria-invalid":l?!M.isValid:void 0},countryButtonProps:{onClick:h,"aria-expanded":$,"aria-haspopup":"listbox","aria-label":R.countryButtonAriaLabel},countrySelectorProps:{onClick:h,"aria-expanded":$,"aria-haspopup":"listbox","aria-label":R.countryButtonAriaLabel},dropdownProps:{role:"listbox","aria-label":R.countryOptionsAriaLabel},getCountryOptionId:Ie,filteredCountries:ue,countries:ue,selectCountry:u,getCountryOptionProps:Ze}}var qn=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"18 15 12 9 6 15"})}),Kn=({size:e=12})=>jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})}),Qn=react.forwardRef(function(n,t){let{value:r,defaultValue:o,onChange:s,onBlur:c,onFocus:y,inputClassName:ne,selectorClassName:ge,containerClassName:ye,searchable:me=true,placeholder:he,disabled:Y,readOnly:be,name:te,id:L,"aria-label":re,"aria-labelledby":oe,...ie}=n,P=react.useRef(null),U=react.useRef(null),V=react.useRef([]),[I,D]=react.useState(0),w=react.useId(),{inputProps:_,countryButtonProps:j,dropdownProps:ae,country:C,filteredCountries:N,isOpen:R,isValid:Pe,searchQuery:Le,setSearchQuery:se,setCountry:d,selectCountry:E,clear:$,openDropdown:H,closeDropdown:A,getCountryOptionId:k,labels:l}=Me({value:r,defaultValue:o,onChange:s,onBlur:c,onFocus:y,...ie}),f=_.ref,G=react.useCallback(u=>{U.current=u,typeof f=="function"?f(u):f&&"current"in f&&(f.current=u);},[f]),xe=react.useCallback(()=>{U.current?.focus();},[]),M=react.useCallback(()=>{U.current?.blur();},[]),Ne=react.useCallback(u=>{E(u),D(0);},[E]),ue=react.useCallback((u,h,b)=>{switch(u.key){case "Enter":case " ":u.preventDefault(),E(h),D(0);break;case "ArrowDown":if(u.preventDefault(),b<N.length-1){let m=b+1;D(m),V.current[m]?.focus();}break;case "ArrowUp":if(u.preventDefault(),b>0){let m=b-1;D(m),V.current[m]?.focus();}break;case "Escape":u.preventDefault(),A();break}},[E,N.length,A]);react.useEffect(()=>{if(!R)return;let u=b=>{let m=b.target;P.current&&m&&!P.current.contains(m)&&A();},h=b=>{let m=b.target;P.current&&m&&!P.current.contains(m)&&A();};return document.addEventListener("mousedown",u),document.addEventListener("focusin",h),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("focusin",h);}},[R,A]),react.useEffect(()=>{if(N.length===0){I!==0&&D(0);return}I>=N.length&&D(N.length-1);},[N.length,I]),react.useImperativeHandle(t,()=>({focus:xe,blur:M,clear:$,setCountry:d,getCountry:()=>C,open:H,close:A}));let z=N[I],ve=z?k(z.code):void 0;return jsxRuntime.jsxs("div",{ref:P,className:ye,"data-valid":Pe,children:[jsxRuntime.jsxs("button",{...j,type:"button",className:ge,disabled:Y,tabIndex:Y?-1:0,"aria-controls":w,children:[C?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:C.flag}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:C.dialCode})]}):jsxRuntime.jsx("span",{className:"phone-input-placeholder",children:l.selectCountry}),jsxRuntime.jsx("span",{className:"phone-input-arrow","aria-hidden":"true",children:R?jsxRuntime.jsx(qn,{size:12}):jsxRuntime.jsx(Kn,{size:12})})]}),jsxRuntime.jsx("input",{..._,ref:G,id:L,name:te,className:ne,placeholder:he||_.placeholder,disabled:Y,readOnly:be,"aria-label":re,"aria-labelledby":oe}),R&&jsxRuntime.jsxs("div",{className:"phone-input-dropdown",children:[me&&jsxRuntime.jsx("div",{className:"phone-input-search",children:jsxRuntime.jsx("input",{type:"text",value:Le,onChange:u=>se(u.target.value),placeholder:l.countrySearchPlaceholder,autoFocus:true,"aria-controls":w,"aria-label":l.searchCountriesAriaLabel})}),jsxRuntime.jsxs("ul",{...ae,className:"phone-input-country-list",id:w,"aria-activedescendant":ve,children:[N.map((u,h)=>jsxRuntime.jsxs("li",{id:k(u.code),ref:b=>{V.current[h]=b;},role:"option","aria-selected":u.code===C?.code,className:`phone-input-country-option ${u.code===C?.code?"selected":""} ${h===I?"highlighted":""}`,onClick:()=>Ne(u),onKeyDown:b=>ue(b,u,h),onMouseEnter:()=>D(h),tabIndex:h===I?0:-1,children:[jsxRuntime.jsx("span",{className:"phone-input-flag",children:u.flag}),jsxRuntime.jsx("span",{className:"phone-input-country-name",children:fe(u)}),jsxRuntime.jsx("span",{className:"phone-input-dial-code",children:u.dialCode})]},u.code)),N.length===0&&jsxRuntime.jsx("li",{className:"phone-input-no-results",children:l.noCountriesFound})]})]})]})});exports.DEFAULT_PHONE_INPUT_LABELS=De;exports.PhoneInput=Qn;exports.addDialCode=B;exports.cleanPhone=p;exports.countries=S;exports.detectCountry=wn;exports.detectCountryFromPhone=q;exports.extractDialCode=On;exports.filterCountries=we;exports.formatAsYouType=Fn;exports.formatPhone=K;exports.formatPhoneNumber=Rn;exports.getCountriesByDialCode=ze;exports.getCountryByCode=T;exports.getCountryByDialCode=Ln;exports.getCountryDisplayLabel=$n;exports.getCountryDisplayName=fe;exports.getCountryOptions=xn;exports.getLocalizedCountryName=ke;exports.getNationalNumber=Sn;exports.getPlaceholder=Re;exports.isInternationalFormat=J;exports.isPhoneNumberComplete=Mn;exports.limitInputLength=kn;exports.localizeCountries=le;exports.localizeCountry=Z;exports.normalizePhoneNumber=Oe;exports.parsePhoneValue=Bn;exports.parseToE164=En;exports.phoneNumbersEqual=Vn;exports.removeDialCode=O;exports.resolvePhoneInputLabels=Ae;exports.stripNonDigits=An;exports.unformatPhone=pe;exports.usePhoneInput=Me;exports.validatePhone=qe;exports.validatePhoneLength=Ge;exports.validatePhoneNumber=Ee;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map