@desource/phone-mask-svelte 1.3.0 β 1.3.1
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/CHANGELOG.md +10 -0
- package/README.md +97 -8
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @desource/phone-mask-svelte
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Core Upgrades:
|
|
8
|
+
- Sync country masks with google-libphonenumber (πΈπ° Slovakia updates)
|
|
9
|
+
|
|
10
|
+
- Updated dependencies []:
|
|
11
|
+
- @desource/phone-mask@1.3.1
|
|
12
|
+
|
|
3
13
|
## 1.3.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -204,6 +204,101 @@ With auto-detection:
|
|
|
204
204
|
<input use:phoneMask={{ detect: true, onChange: handleChange }} />
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
+
### Send Raw Digits to Backend
|
|
208
|
+
|
|
209
|
+
```svelte
|
|
210
|
+
<script lang="ts">
|
|
211
|
+
import { PhoneInput, type PMaskPhoneNumber } from '@desource/phone-mask-svelte';
|
|
212
|
+
|
|
213
|
+
let digits = $state('');
|
|
214
|
+
|
|
215
|
+
async function handlePhoneChange(phone: PMaskPhoneNumber) {
|
|
216
|
+
await fetch('/api/profile/phone', {
|
|
217
|
+
method: 'POST',
|
|
218
|
+
headers: { 'content-type': 'application/json' },
|
|
219
|
+
body: JSON.stringify({
|
|
220
|
+
phoneDigits: phone.digits, // unformatted value for backend
|
|
221
|
+
phoneFull: phone.full // optional full number with country code
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
</script>
|
|
226
|
+
|
|
227
|
+
<PhoneInput bind:value={digits} country="US" onchange={handlePhoneChange} />
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Dynamic Mask Updates on Country Change
|
|
231
|
+
|
|
232
|
+
```svelte
|
|
233
|
+
<script lang="ts">
|
|
234
|
+
import { usePhoneMask, type PCountryKey } from '@desource/phone-mask-svelte';
|
|
235
|
+
|
|
236
|
+
let selectedCountry = $state<PCountryKey>('US');
|
|
237
|
+
let digits = $state('');
|
|
238
|
+
|
|
239
|
+
const phoneMask = usePhoneMask({
|
|
240
|
+
value: () => digits,
|
|
241
|
+
onChange: (value) => (digits = value),
|
|
242
|
+
country: () => selectedCountry
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
function onCountrySelect(nextCountry: PCountryKey) {
|
|
246
|
+
selectedCountry = nextCountry;
|
|
247
|
+
phoneMask.setCountry(nextCountry); // updates mask immediately
|
|
248
|
+
}
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<select
|
|
252
|
+
value={selectedCountry}
|
|
253
|
+
onchange={(e) => onCountrySelect((e.currentTarget as HTMLSelectElement).value as PCountryKey)}
|
|
254
|
+
>
|
|
255
|
+
<option value="US">US</option>
|
|
256
|
+
<option value="GB">GB</option>
|
|
257
|
+
<option value="DE">DE</option>
|
|
258
|
+
</select>
|
|
259
|
+
|
|
260
|
+
<input bind:this={phoneMask.inputRef} type="tel" />
|
|
261
|
+
<p>{phoneMask.fullFormatted}</p>
|
|
262
|
+
<p>{phoneMask.isComplete ? 'complete' : 'incomplete'}</p>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Multi-tenant: tenantId Default Country + Tenant-specific Validation Rules
|
|
266
|
+
|
|
267
|
+
```svelte
|
|
268
|
+
<script lang="ts">
|
|
269
|
+
import { usePhoneMask, type PCountryKey } from '@desource/phone-mask-svelte';
|
|
270
|
+
|
|
271
|
+
type TenantPolicy = {
|
|
272
|
+
defaultCountry: PCountryKey;
|
|
273
|
+
prefixRule?: RegExp;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
let { tenantId }: { tenantId: string } = $props();
|
|
277
|
+
|
|
278
|
+
const TENANT_POLICIES: Record<string, TenantPolicy> = {
|
|
279
|
+
acme: { defaultCountry: 'US', prefixRule: /^(202|303)\d{7}$/ },
|
|
280
|
+
globex: { defaultCountry: 'GB', prefixRule: /^7\d{9}$/ }
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const policy = $derived(TENANT_POLICIES[tenantId] ?? { defaultCountry: 'US' as const });
|
|
284
|
+
let digits = $state('');
|
|
285
|
+
|
|
286
|
+
const phoneMask = usePhoneMask({
|
|
287
|
+
value: () => digits,
|
|
288
|
+
onChange: (value) => (digits = value),
|
|
289
|
+
country: () => policy.defaultCountry
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
const isTenantValid = $derived(
|
|
293
|
+
phoneMask.isComplete && (policy.prefixRule ? policy.prefixRule.test(phoneMask.digits) : true)
|
|
294
|
+
);
|
|
295
|
+
</script>
|
|
296
|
+
|
|
297
|
+
<input bind:this={phoneMask.inputRef} type="tel" />
|
|
298
|
+
<p>Default country: {policy.defaultCountry}</p>
|
|
299
|
+
<p>Tenant validation: {isTenantValid ? 'pass' : 'fail'}</p>
|
|
300
|
+
```
|
|
301
|
+
|
|
207
302
|
## π Component API
|
|
208
303
|
|
|
209
304
|
### Props
|
|
@@ -507,10 +602,7 @@ Pass reactive state directly β the factory re-runs automatically when `selecte
|
|
|
507
602
|
<option value="DE">π©πͺ Germany</option>
|
|
508
603
|
</select>
|
|
509
604
|
|
|
510
|
-
<input
|
|
511
|
-
{@attach phoneMask({ country: selectedCountry, onChange: (p) => (phoneData = p) })}
|
|
512
|
-
placeholder="Phone number"
|
|
513
|
-
/>
|
|
605
|
+
<input {@attach phoneMask({ country: selectedCountry, onChange: (p) => (phoneData = p) })} placeholder="Phone number" />
|
|
514
606
|
```
|
|
515
607
|
|
|
516
608
|
## π¬ Action API
|
|
@@ -583,10 +675,7 @@ Pass reactive `$state` inside the options object β Svelte calls `update()` aut
|
|
|
583
675
|
<option value="DE">π©πͺ Germany</option>
|
|
584
676
|
</select>
|
|
585
677
|
|
|
586
|
-
<input
|
|
587
|
-
use:phoneMask={{ country: selectedCountry, onChange: (p) => (phoneData = p) }}
|
|
588
|
-
placeholder="Phone number"
|
|
589
|
-
/>
|
|
678
|
+
<input use:phoneMask={{ country: selectedCountry, onChange: (p) => (phoneData = p) }} placeholder="Phone number" />
|
|
590
679
|
```
|
|
591
680
|
|
|
592
681
|
### Action vs Attachment
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));require(`svelte/internal/disclose-version`);let c=require(`svelte/internal/client`);c=s(c);let l=require(`svelte`),u=require(`@desource/phone-mask`);function d({country:e,locale:t,detect:n,onCountryChange:r}={}){let i=c.state(c.proxy((0,u.parseCountryCode)(e?.(),`US`))),a=c.derived(()=>t?.()||(0,u.getNavigatorLang)()),o=c.derived(()=>(0,u.getCountry)(c.get(i),c.get(a))),s=e=>{let t=(0,u.parseCountryCode)(e);return t?(c.set(i,t,!0),!0):!1},l=async()=>{s(await(0,u.detectByGeoIp)())||s((0,u.detectCountryFromLocale)())};return c.user_effect(()=>{let t=e?.();t&&t!==c.get(i)&&s(t)}),c.user_effect(()=>{n?.()&&!e?.()&&l()}),c.user_effect(()=>{r?.(c.get(o))}),{get country(){return c.get(o)},get locale(){return c.get(a)},setCountry:s}}function f({country:e,value:t,onChange:n,onPhoneChange:r,onValidationChange:i}){let a=c.derived(()=>(0,u.createPhoneFormatter)(e())),o=c.derived(()=>c.get(a).getMaxDigits()),s=c.derived(()=>(0,u.extractDigits)(t(),c.get(o))),l=c.derived(()=>c.get(a).getPlaceholder()),d=c.derived(()=>c.get(a).formatDisplay(c.get(s))),f=c.derived(()=>c.get(s)?`${e().code}${c.get(s)}`:``),p=c.derived(()=>c.get(d)?`${e().code} ${c.get(d)}`:``),m=c.derived(()=>c.get(a).isComplete(c.get(s))),h=c.derived(()=>c.get(s).length===0),g=c.derived(()=>!c.get(h)&&!c.get(m)),_=c.derived(()=>({full:c.get(f),fullFormatted:c.get(p),digits:c.get(s)}));return c.user_pre_effect(()=>{let e=t(),r=c.get(s);e!==r&&n(r)}),c.user_effect(()=>{r?.(c.get(_))}),c.user_effect(()=>{i?.(c.get(m))}),{get digits(){return c.get(s)},get formatter(){return c.get(a)},get displayPlaceholder(){return c.get(l)},get displayValue(){return c.get(d)},get full(){return c.get(f)},get fullFormatted(){return c.get(p)},get isComplete(){return c.get(m)},get isEmpty(){return c.get(h)},get shouldShowWarn(){return c.get(g)}}}function p(){let e=null,t=()=>{e&&=(clearTimeout(e),null)};return(0,l.onDestroy)(t),{set:(n,r)=>{t(),e=setTimeout(n,r)},clear:t}}function m(){let e=c.state(!1),t=p();return{get showValidationHint(){return c.get(e)},clearValidationHint:(n=!0)=>{n&&c.set(e,!1),t.clear()},scheduleValidationHint:n=>{c.set(e,!1),t.set(()=>{c.set(e,!0)},n)}}}var h=500,g=300;function _(e){let{formatter:t,digits:n,inactive:r,onChange:i,scheduleValidationHint:a}=e,o=(e,n)=>{(0,l.tick)().then(()=>{e&&(0,u.setCaret)(e,t().getCaretPosition(n))})};return{handleBeforeInput:e=>{(0,u.processBeforeInput)(e)},handleInput:e=>{if(r?.())return;let n=(0,u.processInput)(e,{formatter:t()});n&&(i?.(n.newDigits),o(e.target,n.caretDigitIndex),a?.(h))},handleKeydown:e=>{if(r?.())return;let s=(0,u.processKeydown)(e,{digits:n(),formatter:t()});s&&(i?.(s.newDigits),o(e.target,s.caretDigitIndex),a?.(g))},handlePaste:e=>{if(r?.())return;let s=(0,u.processPaste)(e,{digits:n(),formatter:t()});s&&(i?.(s.newDigits),o(e.target,s.caretDigitIndex),a?.(g))}}}function v({rootRef:e,dropdownRef:t,searchRef:n,selectorRef:r,locale:i,countryOption:a,inactive:o,onSelectCountry:s,onAfterSelect:d}){let f=c.state(``),p=c.state(!1),m=c.state(!1),h=c.state(c.proxy({})),g=c.state(0),_=c.derived(()=>(0,u.MasksFull)(i())),v=c.derived(()=>(0,u.filterCountries)(c.get(_),c.get(f))),y=c.derived(()=>!a?.()&&c.get(_).length>1),b=e=>{c.set(g,e,!0)},ee=()=>{(0,l.tick)().then(()=>n()?.focus({preventScroll:!0}))},x=()=>{c.get(p)&&c.set(m,!0)},S=()=>{c.set(m,!1),c.set(p,!0),b(0),ee()},te=()=>{c.get(m)&&(c.set(p,!1),c.set(m,!1))},C=()=>{o?.()||!c.get(y)||(c.get(p)?x():S())},w=e=>{s(e),x(),c.set(f,``),b(0),d?.()},ne=e=>{c.set(f,e.target.value,!0),b(0)},T=e=>{let n=e.target,i=t(),a=r();n&&(i?.contains(n)||a?.contains(n)||x())},E=n=>{if(n?.type===`scroll`&&n.target&&t()?.contains(n.target))return;let r=e();if(!r)return;let i=r.getBoundingClientRect();c.set(h,{top:`${i.bottom+globalThis.scrollY+8}px`,left:`${i.left+globalThis.scrollX}px`,width:`${i.width}px`},!0)},D=()=>{(0,l.tick)().then(()=>{let e=t()?.lastElementChild,n=e?.children[c.get(g)];if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),a=0;if(i.top<r.top)a=e.scrollTop-(r.top-i.top);else if(i.bottom>r.bottom)a=e.scrollTop+(i.bottom-r.bottom);else return;e.scrollTo({top:a,behavior:`smooth`})})},re=e=>{e.key===`ArrowDown`?(e.preventDefault(),b(Math.min(c.get(g)+1,c.get(v).length-1)),D()):e.key===`ArrowUp`?(e.preventDefault(),b(Math.max(c.get(g)-1,0)),D()):e.key===`Enter`&&c.get(v)[c.get(g)]?(e.preventDefault(),w(c.get(v)[c.get(g)].id)):e.key===`Escape`&&x()},O=()=>{globalThis.removeEventListener(`resize`,E),globalThis.removeEventListener(`scroll`,E,!0),globalThis.removeEventListener(`click`,T,!0)};return c.user_effect(()=>{!c.get(y)&&c.get(p)&&x()}),c.user_effect(()=>{if(!c.get(p)){O();return}E(),globalThis.addEventListener(`resize`,E),globalThis.addEventListener(`scroll`,E,!0),globalThis.addEventListener(`click`,T,!0)}),(0,l.onDestroy)(O),{get dropdownOpen(){return c.get(p)},get isClosing(){return c.get(m)},get search(){return c.get(f)},get focusedIndex(){return c.get(g)},get dropdownStyle(){return c.get(h)},get filteredCountries(){return c.get(v)},get hasDropdown(){return c.get(y)},openDropdown:S,closeDropdown:x,toggleDropdown:C,selectCountry:w,setFocusedIndex:b,handleSearchChange:ne,handleSearchKeydown:re,handleDropdownAnimationEnd:te}}function y(e=1800){let t=c.state(!1),n=c.state(!1),r=p();return{get copied(){return c.get(t)},get isCopying(){return c.get(n)},copy:async i=>{if(c.get(n))return!1;let a=i.trim();if(!a)return!1;c.set(n,!0);try{return await navigator.clipboard.writeText(a),c.set(t,!0),r.set(()=>{c.set(t,!1)},e),!0}catch(e){return console.warn(`Copy failed`,e),!1}finally{c.set(n,!1)}}}}var b=1800;function ee({liveRef:e,fullFormatted:t,onCopy:n}){let r=p(),i=y(b),a=c.derived(()=>i.copied?`Copied`:`Copy ${t()}`),o=c.derived(()=>i.copied?`Copied`:`Copy phone number`),s=t=>{let n=e?.();n&&(n.textContent=t,r.set(()=>{let t=e?.();t&&(t.textContent=``)},b))};return{get copied(){return i.copied},get copyAriaLabel(){return c.get(a)},get copyButtonTitle(){return c.get(o)},onCopyClick:async()=>{let e=t().trim();await i.copy(e)&&(n?.(e),s(`Phone number copied to clipboard`))}}}function x({theme:e}){let t=c.state(!1),n=c.derived(()=>(()=>{let n=e();return n===`auto`?c.get(t)?`theme-dark`:`theme-light`:`theme-${n}`})());return c.user_effect(()=>{let e=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`)??null;if(!e)return;c.set(t,e.matches,!0);let n=e=>{c.set(t,e.matches,!0)};return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)}),{get themeClass(){return c.get(n)}}}var S=c.from_svg(`<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 4.5L6 8L9.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>`),te=c.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z" fill="currentColor"></path></svg>`),C=c.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),w=c.from_html(`<button type="button"><!></button>`),ne=c.from_svg(`<svg width="11" height="11" viewBox="0 0 14 14" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),T=c.from_html(`<button type="button" class="pi-btn pi-btn-clear"><!></button>`),E=c.from_html(`<li role="option"><span class="pi-flag" role="img"><!></span> <span class="pi-opt-name"> </span> <span class="pi-opt-code"> </span></li>`),D=c.from_html(`<li class="pi-empty"> </li>`),re=c.from_html(`<div role="dialog" aria-modal="false" aria-label="Select country"><div class="pi-search-wrap"><input type="search" class="pi-search" aria-label="Search countries"/></div> <ul class="pi-options" role="listbox" tabindex="-1"></ul></div>`),O=c.from_html(`<div><div class="pi-selector"><button type="button"><span class="pi-flag" role="img"><!></span> <span class="pi-code"> </span> <!></button></div> <div class="pi-input-wrap"><input type="tel" inputmode="tel" autocomplete="tel-national" autocorrect="off" autocapitalize="off" spellcheck="false" class="pi-input"/> <div class="pi-actions" role="toolbar" aria-label="Phone input actions"><!> <!> <!></div></div></div> <!> <div class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>`,1);function ie(e,t){c.push(t,!0);let n=c.prop(t,`value`,15,``),r=c.prop(t,`detect`,3,!0),i=c.prop(t,`size`,3,`normal`),a=c.prop(t,`theme`,3,`auto`),o=c.prop(t,`disabled`,3,!1),s=c.prop(t,`readonly`,3,!1),u=c.prop(t,`showCopy`,3,!0),p=c.prop(t,`showClear`,3,!1),h=c.prop(t,`withValidity`,3,!0),g=c.prop(t,`searchPlaceholder`,3,`Search country or code...`),y=c.prop(t,`noResultsText`,3,`No countries found`),b=c.prop(t,`clearButtonLabel`,3,`Clear phone number`),ie=c.prop(t,`dropdownClass`,3,``),k=c.prop(t,`disableDefaultStyles`,3,!1),ae=c.rest_props(t,`$$slots.$$events.$$legacy.value.id.name.country.detect.locale.size.theme.disabled.readonly.showCopy.showClear.withValidity.searchPlaceholder.noResultsText.clearButtonLabel.dropdownClass.disableDefaultStyles.onchange.oncountrychange.onvalidationchange.onfocus.onblur.oncopy.onclear.flag.copysvg.clearsvg.actionsbefore.class`.split(`.`)),A=c.state(null),j=c.state(null),M=c.state(null),N=c.state(null),P=c.state(null),F=c.state(null),I=d({country:()=>t.country,locale:()=>t.locale,detect:()=>r(),onCountryChange:(...e)=>t.oncountrychange?.(...e)}),L=f({country:()=>I.country,value:()=>n(),onChange:e=>n(e),onPhoneChange:(...e)=>t.onchange?.(...e),onValidationChange:(...e)=>t.onvalidationchange?.(...e)}),R=m(),z=c.derived(()=>o()||s()),oe=c.derived(()=>R.showValidationHint&&L.shouldShowWarn),se=c.derived(()=>u()&&!L.isEmpty&&!o()),B=c.derived(()=>p()&&!L.isEmpty&&!c.get(z)),V=ee({liveRef:()=>c.get(M),fullFormatted:()=>L.fullFormatted,onCopy:(...e)=>t.oncopy?.(...e)}),H=()=>(0,l.tick)().then(()=>c.get(j)?.focus()),U=v({rootRef:()=>c.get(A),dropdownRef:()=>c.get(N),searchRef:()=>c.get(P),selectorRef:()=>c.get(F),locale:()=>I.locale,countryOption:()=>t.country,inactive:()=>c.get(z),onSelectCountry:I.setCountry,onAfterSelect:H}),W=c.state(`0`);(0,l.onMount)(()=>{c.set(W,Math.random().toString(36).slice(2,10),!0)});let G=c.derived(()=>`pi-options-${c.get(W)}`),K=e=>`pi-option-${c.get(W)}-${e}`,ce=c.derived(()=>U.dropdownOpen&&U.filteredCountries[U.focusedIndex]?K(U.focusedIndex):void 0),q=_({formatter:()=>L.formatter,digits:()=>L.digits,inactive:()=>c.get(z),onChange:e=>n(e),scheduleValidationHint:R.scheduleValidationHint}),le=e=>{R.clearValidationHint(!1),U.closeDropdown(),t.onfocus?.(e)},ue=e=>t.onblur?.(e);function de(){H()}function fe(){c.get(j)?.blur()}function pe(){n(``),R.clearValidationHint(),t.onclear?.()}function me(e){I.setCountry(e)}function he(){return L.full}function ge(){return L.fullFormatted}function _e(){return L.digits}function ve(){return L.isComplete}function ye(){return L.isComplete}let be=()=>{pe(),H()},xe=x({theme:()=>a()}),Se=c.derived(()=>[`phone-input`,`size-${i()}`,xe.themeClass,o()&&`is-disabled`,s()&&`is-readonly`,k()&&`is-unstyled`,h()&&c.get(oe)&&`is-incomplete`,h()&&L.isComplete&&`is-complete`,t.class].filter(Boolean).join(` `)),Ce=c.derived(()=>+c.get(se)+ +c.get(B)+(t.actionsbefore?1:0));function we(e){return document.body.appendChild(e),{destroy:()=>e.remove()}}var Te={focus:de,blur:fe,clear:pe,selectCountry:me,getFullNumber:he,getFullFormattedNumber:ge,getDigits:_e,isValid:ve,isComplete:ye},Ee=O(),J=c.first_child(Ee);c.attribute_effect(J,()=>({class:c.get(Se),...ae,role:`group`,"aria-label":`Phone input with country selector`,[c.STYLE]:{"--pi-actions-count":c.get(Ce)}}));var Y=c.child(J),X=c.child(Y);let De;var Z=c.child(X),Oe=c.child(Z),ke=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.flag,()=>I.country),c.append(e,n)},Ae=e=>{var t=c.text();c.template_effect(()=>c.set_text(t,I.country.flag)),c.append(e,t)};c.if(Oe,e=>{t.flag?e(ke):e(Ae,-1)}),c.reset(Z);var Q=c.sibling(Z,2),je=c.child(Q,!0);c.reset(Q);var Me=c.sibling(Q,2),Ne=e=>{var t=S();let n;c.template_effect(()=>n=c.set_class(t,0,`pi-chevron`,null,n,{"is-open":U.dropdownOpen})),c.append(e,t)};c.if(Me,e=>{!c.get(z)&&U.hasDropdown&&e(Ne)}),c.reset(X),c.reset(Y),c.bind_this(Y,e=>c.set(F,e),()=>c.get(F));var Pe=c.sibling(Y,2),$=c.child(Pe);c.remove_input_defaults($),c.bind_this($,e=>c.set(j,e),()=>c.get(j));var Fe=c.sibling($,2),Ie=c.child(Fe),Le=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.actionsbefore),c.append(e,n)};c.if(Ie,e=>{t.actionsbefore&&e(Le)});var Re=c.sibling(Ie,2),ze=e=>{var n=w();let r;var i=c.child(n),a=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.copysvg,()=>V.copied),c.append(e,n)},o=e=>{var t=te();c.append(e,t)},s=e=>{var t=C();c.append(e,t)};c.if(i,e=>{t.copysvg?e(a):V.copied?e(o,1):e(s,-1)}),c.reset(n),c.template_effect(()=>{r=c.set_class(n,1,`pi-btn pi-btn-copy`,null,r,{"is-copied":V.copied}),c.set_attribute(n,`aria-label`,V.copyAriaLabel),c.set_attribute(n,`title`,V.copyButtonTitle)}),c.delegated(`click`,n,function(...e){V.onCopyClick?.apply(this,e)}),c.append(e,n)};c.if(Re,e=>{c.get(se)&&e(ze)});var Be=c.sibling(Re,2),Ve=e=>{var n=T(),r=c.child(n),i=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.clearsvg),c.append(e,n)},a=e=>{var t=ne();c.append(e,t)};c.if(r,e=>{t.clearsvg?e(i):e(a,-1)}),c.reset(n),c.template_effect(()=>{c.set_attribute(n,`aria-label`,b()),c.set_attribute(n,`title`,b())}),c.delegated(`click`,n,be),c.append(e,n)};c.if(Be,e=>{c.get(B)&&e(Ve)}),c.reset(Fe),c.reset(Pe),c.reset(J),c.bind_this(J,e=>c.set(A,e),()=>c.get(A));var He=c.sibling(J,2),Ue=e=>{var n=re();let r,i;var a=c.child(n),o=c.child(a);c.remove_input_defaults(o),c.bind_this(o,e=>c.set(P,e),()=>c.get(P)),c.reset(a);var s=c.sibling(a,2);c.each(s,23,()=>U.filteredCountries,e=>e.id,(e,n,r)=>{var i=E();let a;var o=c.child(i),s=c.child(o),l=e=>{var r=c.comment(),i=c.first_child(r);c.snippet(i,()=>t.flag,()=>c.get(n)),c.append(e,r)},u=e=>{var t=c.text();c.template_effect(()=>c.set_text(t,c.get(n).flag)),c.append(e,t)};c.if(s,e=>{t.flag?e(l):e(u,-1)}),c.reset(o);var d=c.sibling(o,2),f=c.child(d,!0);c.reset(d);var p=c.sibling(d,2),m=c.child(p,!0);c.reset(p),c.reset(i),c.template_effect(e=>{c.set_attribute(i,`id`,e),a=c.set_class(i,1,`pi-option`,null,a,{"is-focused":c.get(r)===U.focusedIndex,"is-selected":c.get(n).id===I.country.id}),c.set_attribute(i,`aria-selected`,c.get(n).id===I.country.id),c.set_attribute(i,`title`,c.get(n).name),c.set_attribute(o,`aria-label`,`${c.get(n).name??``} flag`),c.set_text(f,c.get(n).name),c.set_text(m,c.get(n).code)},[()=>K(c.get(r))]),c.delegated(`click`,i,()=>U.selectCountry(c.get(n).id)),c.event(`mouseenter`,i,()=>U.setFocusedIndex(c.get(r))),c.append(e,i)},e=>{var t=D(),n=c.child(t,!0);c.reset(t),c.template_effect(()=>c.set_text(n,y())),c.append(e,t)}),c.reset(s),c.reset(n),c.action(n,e=>we?.(e)),c.bind_this(n,e=>c.set(N,e),()=>c.get(N)),c.template_effect(()=>{r=c.set_class(n,1,`phone-dropdown ${ie()??``} ${xe.themeClass??``}`,null,r,{"is-closing":U.isClosing}),i=c.set_style(n,``,i,{position:`absolute`,top:U.dropdownStyle.top,left:U.dropdownStyle.left,width:U.dropdownStyle.width}),c.set_attribute(o,`placeholder`,g()),c.set_attribute(o,`aria-controls`,c.get(G)),c.set_attribute(o,`aria-activedescendant`,c.get(ce)),c.set_value(o,U.search),c.set_attribute(s,`id`,c.get(G))}),c.event(`animationend`,n,function(...e){U.handleDropdownAnimationEnd?.apply(this,e)}),c.delegated(`keydown`,o,function(...e){U.handleSearchKeydown?.apply(this,e)}),c.delegated(`input`,o,function(...e){U.handleSearchChange?.apply(this,e)}),c.append(e,n)};c.if(He,e=>{U.dropdownOpen&&e(Ue)});var We=c.sibling(He,2);return c.bind_this(We,e=>c.set(M,e),()=>c.get(M)),c.template_effect(()=>{De=c.set_class(X,1,`pi-selector-btn`,null,De,{"no-dropdown":!U.hasDropdown||s()}),X.disabled=o(),c.set_attribute(X,`tabindex`,c.get(z)||!U.hasDropdown?-1:void 0),c.set_attribute(X,`aria-label`,`Selected country: ${I.country.name??``}`),c.set_attribute(X,`aria-expanded`,U.dropdownOpen),c.set_attribute(X,`aria-haspopup`,U.hasDropdown?`listbox`:void 0),c.set_attribute(Z,`aria-label`,`${I.country.name??``} flag`),c.set_text(je,I.country.code),c.set_attribute($,`id`,t.id),c.set_attribute($,`name`,t.name),c.set_attribute($,`placeholder`,L.displayPlaceholder),c.set_value($,L.displayValue),$.disabled=o(),$.readOnly=s(),c.set_attribute($,`aria-invalid`,c.get(oe))}),c.delegated(`click`,X,function(...e){U.toggleDropdown?.apply(this,e)}),c.delegated(`beforeinput`,$,function(...e){q.handleBeforeInput?.apply(this,e)}),c.delegated(`input`,$,function(...e){q.handleInput?.apply(this,e)}),c.delegated(`keydown`,$,function(...e){q.handleKeydown?.apply(this,e)}),c.event(`paste`,$,function(...e){q.handlePaste?.apply(this,e)}),c.event(`focus`,$,le),c.event(`blur`,$,ue),c.append(e,Ee),c.pop(Te)}c.delegate([`click`,`beforeinput`,`input`,`keydown`]);function k(e){let t=c.state(null),n=d({country:e.country,locale:e.locale,detect:e.detect,onCountryChange:e.onCountryChange}),r=f({country:()=>n.country,value:e.value,onChange:e.onChange,onPhoneChange:e.onPhoneChange}),{handleBeforeInput:i,handleInput:a,handleKeydown:o,handlePaste:s}=_({formatter:()=>r.formatter,digits:()=>r.digits,onChange:e.onChange});return c.user_effect(()=>{let e=c.get(t);if(e)return e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.addEventListener(`beforeinput`,i),e.addEventListener(`input`,a),e.addEventListener(`keydown`,o),e.addEventListener(`paste`,s),()=>{e.removeEventListener(`beforeinput`,i),e.removeEventListener(`input`,a),e.removeEventListener(`keydown`,o),e.removeEventListener(`paste`,s)}}),c.user_effect(()=>{let e=c.get(t);e&&(e.value=r.displayValue,e.setAttribute(`placeholder`,r.displayPlaceholder))}),{get inputRef(){return c.get(t)},set inputRef(e){c.set(t,e,!0)},get digits(){return r.digits},get formatter(){return r.formatter},get full(){return r.full},get fullFormatted(){return r.fullFormatted},get isComplete(){return r.isComplete},get isEmpty(){return r.isEmpty},get shouldShowWarn(){return r.shouldShowWarn},get country(){return n.country},get locale(){return n.locale},setCountry:n.setCountry,clear:()=>{e.onChange(``)}}}function ae(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function A(e){return t=>{if(t.tagName!==`INPUT`){console.warn(`[phoneMaskAttachment] Attachment can only be used on input elements`);return}let n=ae(e),r=c.effect_root(()=>{let e=c.state(c.proxy(t.value||``)),r=k({country:()=>n.country,locale:()=>n.locale,detect:()=>n.detect,value:()=>c.get(e),onChange:t=>{c.set(e,t,!0)},onPhoneChange:n.onChange,onCountryChange:n.onCountryChange});r.inputRef=t,t.__phoneMaskState={get country(){return r.country},get formatter(){return r.formatter},get digits(){return r.digits},get locale(){return r.locale},options:n,setCountry:e=>r.setCountry(e)}});return()=>{r(),delete t.__phoneMaskState}}}function j(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function M(e,t,n){if(t.digits=n,e.value=t.formatter.formatDisplay(t.digits),t.options.onChange){let n=e.value?`${t.country.code} ${e.value}`:``,r=t.digits?`${t.country.code}${t.digits}`:``;t.options.onChange({full:r,fullFormatted:n,digits:t.digits})}}function N(e,t){let n=t.formatter.getMaxDigits(),r=(0,u.extractDigits)(e.value,n),i=t.formatter.formatDisplay(r);(r!==t.digits||e.value!==i)&&M(e,t,r)}function P(e){let t=e.country.id,n=(0,u.parseCountryCode)(e.options.country);n&&n!==t&&e.setCountry(n)}function F(e,t,n){return r=>{let i=n(r,t);i&&(M(e,t,i.newDigits),Promise.resolve().then(()=>{(0,u.setCaret)(e,t.formatter.getCaretPosition(i.caretDigitIndex))}))}}async function I(e){let t=(0,u.parseCountryCode)(e.country);if(t)return t;if(e.detect){let e=(0,u.parseCountryCode)(await(0,u.detectByGeoIp)());if(e)return e;let t=(0,u.parseCountryCode)((0,u.detectCountryFromLocale)());if(t)return t}return`US`}function L(e,t){if(e.tagName!==`INPUT`)return console.warn(`[phoneMaskAction] Action can only be used on input elements`),{update(){},destroy(){}};e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.setAttribute(`placeholder`,``);let n=j(t),r=n.locale||(0,u.getNavigatorLang)(),i=(0,u.getCountry)((0,u.parseCountryCode)(n.country,`US`),r),a={country:i,formatter:(0,u.createPhoneFormatter)(i),digits:``,locale:r,options:n,setCountry(t){let n=(0,u.parseCountryCode)(t);if(!n)return!1;let r=(0,u.getCountry)(n,this.locale);return this.country=r,this.options.onCountryChange?.(r),this.formatter=(0,u.createPhoneFormatter)(r),e.placeholder=this.formatter.getPlaceholder(),N(e,this),!0}};e.__phoneMaskState=a;let o=F(e,a,u.processInput),s=F(e,a,u.processKeydown),c=F(e,a,u.processPaste);return e.addEventListener(`beforeinput`,u.processBeforeInput),e.addEventListener(`input`,o),e.addEventListener(`keydown`,s),e.addEventListener(`paste`,c),I(n).then(t=>{e.__phoneMaskState===a&&a.setCountry(t)}),{update(t){a.options=j(t),P(a),N(e,a)},destroy(){e.removeEventListener(`beforeinput`,u.processBeforeInput),e.removeEventListener(`input`,o),e.removeEventListener(`keydown`,s),e.removeEventListener(`paste`,c),delete e.__phoneMaskState}}}var R=ie;exports.PhoneInput=R,exports.phoneMaskAction=L,exports.phoneMaskAttachment=A,exports.usePhoneMask=k;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));require(`svelte/internal/disclose-version`);let c=require(`svelte/internal/client`),l=s(c,1);c=s(c);let u=require(`svelte`),d=require(`@desource/phone-mask`);function f({country:e,locale:t,detect:n,onCountryChange:r}={}){let i=l.state(l.proxy((0,d.parseCountryCode)(e?.(),`US`))),a=l.derived(()=>t?.()||(0,d.getNavigatorLang)()),o=l.derived(()=>(0,d.getCountry)(l.get(i),l.get(a))),s=e=>{let t=(0,d.parseCountryCode)(e);return t?(l.set(i,t,!0),!0):!1},c=async()=>{s(await(0,d.detectByGeoIp)())||s((0,d.detectCountryFromLocale)())};return l.user_effect(()=>{let t=e?.();t&&t!==l.get(i)&&s(t)}),l.user_effect(()=>{n?.()&&!e?.()&&c()}),l.user_effect(()=>{r?.(l.get(o))}),{get country(){return l.get(o)},get locale(){return l.get(a)},setCountry:s}}function p({country:e,value:t,onChange:n,onPhoneChange:r,onValidationChange:i}){let a=l.derived(()=>(0,d.createPhoneFormatter)(e())),o=l.derived(()=>l.get(a).getMaxDigits()),s=l.derived(()=>(0,d.extractDigits)(t(),l.get(o))),c=l.derived(()=>l.get(a).getPlaceholder()),u=l.derived(()=>l.get(a).formatDisplay(l.get(s))),f=l.derived(()=>l.get(s)?`${e().code}${l.get(s)}`:``),p=l.derived(()=>l.get(u)?`${e().code} ${l.get(u)}`:``),m=l.derived(()=>l.get(a).isComplete(l.get(s))),h=l.derived(()=>l.get(s).length===0),g=l.derived(()=>!l.get(h)&&!l.get(m)),_=l.derived(()=>({full:l.get(f),fullFormatted:l.get(p),digits:l.get(s)}));return l.user_pre_effect(()=>{let e=t(),r=l.get(s);e!==r&&n(r)}),l.user_effect(()=>{r?.(l.get(_))}),l.user_effect(()=>{i?.(l.get(m))}),{get digits(){return l.get(s)},get formatter(){return l.get(a)},get displayPlaceholder(){return l.get(c)},get displayValue(){return l.get(u)},get full(){return l.get(f)},get fullFormatted(){return l.get(p)},get isComplete(){return l.get(m)},get isEmpty(){return l.get(h)},get shouldShowWarn(){return l.get(g)}}}function m(){let e=null,t=()=>{e&&=(clearTimeout(e),null)};return(0,u.onDestroy)(t),{set:(n,r)=>{t(),e=setTimeout(n,r)},clear:t}}function h(){let e=l.state(!1),t=m();return{get showValidationHint(){return l.get(e)},clearValidationHint:(n=!0)=>{n&&l.set(e,!1),t.clear()},scheduleValidationHint:n=>{l.set(e,!1),t.set(()=>{l.set(e,!0)},n)}}}var g=500,_=300;function v(e){let{formatter:t,digits:n,inactive:r,onChange:i,scheduleValidationHint:a}=e,o=(e,n)=>{(0,u.tick)().then(()=>{e&&(0,d.setCaret)(e,t().getCaretPosition(n))})};return{handleBeforeInput:e=>{(0,d.processBeforeInput)(e)},handleInput:e=>{if(r?.())return;let n=(0,d.processInput)(e,{formatter:t()});n&&(i?.(n.newDigits),o(e.target,n.caretDigitIndex),a?.(g))},handleKeydown:e=>{if(r?.())return;let s=(0,d.processKeydown)(e,{digits:n(),formatter:t()});s&&(i?.(s.newDigits),o(e.target,s.caretDigitIndex),a?.(_))},handlePaste:e=>{if(r?.())return;let s=(0,d.processPaste)(e,{digits:n(),formatter:t()});s&&(i?.(s.newDigits),o(e.target,s.caretDigitIndex),a?.(_))}}}function y({rootRef:e,dropdownRef:t,searchRef:n,selectorRef:r,locale:i,countryOption:a,inactive:o,onSelectCountry:s,onAfterSelect:c}){let f=l.state(``),p=l.state(!1),m=l.state(!1),h=l.state(l.proxy({})),g=l.state(0),_=l.derived(()=>(0,d.MasksFull)(i())),v=l.derived(()=>(0,d.filterCountries)(l.get(_),l.get(f))),y=l.derived(()=>!a?.()&&l.get(_).length>1),b=e=>{l.set(g,e,!0)},x=()=>{(0,u.tick)().then(()=>n()?.focus({preventScroll:!0}))},S=()=>{l.get(p)&&l.set(m,!0)},C=()=>{l.set(m,!1),l.set(p,!0),b(0),x()},ee=()=>{l.get(m)&&(l.set(p,!1),l.set(m,!1))},te=()=>{o?.()||!l.get(y)||(l.get(p)?S():C())},w=e=>{s(e),S(),l.set(f,``),b(0),c?.()},ne=e=>{l.set(f,e.target.value,!0),b(0)},T=e=>{let n=e.target,i=t(),a=r();n&&(i?.contains(n)||a?.contains(n)||S())},E=n=>{if(n?.type===`scroll`&&n.target&&t()?.contains(n.target))return;let r=e();if(!r)return;let i=r.getBoundingClientRect();l.set(h,{top:`${i.bottom+globalThis.scrollY+8}px`,left:`${i.left+globalThis.scrollX}px`,width:`${i.width}px`},!0)},D=()=>{(0,u.tick)().then(()=>{let e=t()?.lastElementChild,n=e?.children[l.get(g)];if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),a=0;if(i.top<r.top)a=e.scrollTop-(r.top-i.top);else if(i.bottom>r.bottom)a=e.scrollTop+(i.bottom-r.bottom);else return;e.scrollTo({top:a,behavior:`smooth`})})},re=e=>{e.key===`ArrowDown`?(e.preventDefault(),b(Math.min(l.get(g)+1,l.get(v).length-1)),D()):e.key===`ArrowUp`?(e.preventDefault(),b(Math.max(l.get(g)-1,0)),D()):e.key===`Enter`&&l.get(v)[l.get(g)]?(e.preventDefault(),w(l.get(v)[l.get(g)].id)):e.key===`Escape`&&S()},O=()=>{globalThis.removeEventListener(`resize`,E),globalThis.removeEventListener(`scroll`,E,!0),globalThis.removeEventListener(`click`,T,!0)};return l.user_effect(()=>{!l.get(y)&&l.get(p)&&S()}),l.user_effect(()=>{if(!l.get(p)){O();return}E(),globalThis.addEventListener(`resize`,E),globalThis.addEventListener(`scroll`,E,!0),globalThis.addEventListener(`click`,T,!0)}),(0,u.onDestroy)(O),{get dropdownOpen(){return l.get(p)},get isClosing(){return l.get(m)},get search(){return l.get(f)},get focusedIndex(){return l.get(g)},get dropdownStyle(){return l.get(h)},get filteredCountries(){return l.get(v)},get hasDropdown(){return l.get(y)},openDropdown:C,closeDropdown:S,toggleDropdown:te,selectCountry:w,setFocusedIndex:b,handleSearchChange:ne,handleSearchKeydown:re,handleDropdownAnimationEnd:ee}}function b(e=1800){let t=l.state(!1),n=l.state(!1),r=m();return{get copied(){return l.get(t)},get isCopying(){return l.get(n)},copy:async i=>{if(l.get(n))return!1;let a=i.trim();if(!a)return!1;l.set(n,!0);try{return await navigator.clipboard.writeText(a),l.set(t,!0),r.set(()=>{l.set(t,!1)},e),!0}catch(e){return console.warn(`Copy failed`,e),!1}finally{l.set(n,!1)}}}}var x=1800;function S({liveRef:e,fullFormatted:t,onCopy:n}){let r=m(),i=b(x),a=l.derived(()=>i.copied?`Copied`:`Copy ${t()}`),o=l.derived(()=>i.copied?`Copied`:`Copy phone number`),s=t=>{let n=e?.();n&&(n.textContent=t,r.set(()=>{let t=e?.();t&&(t.textContent=``)},x))};return{get copied(){return i.copied},get copyAriaLabel(){return l.get(a)},get copyButtonTitle(){return l.get(o)},onCopyClick:async()=>{let e=t().trim();await i.copy(e)&&(n?.(e),s(`Phone number copied to clipboard`))}}}function C({theme:e}){let t=l.state(!1),n=l.derived(()=>(()=>{let n=e();return n===`auto`?l.get(t)?`theme-dark`:`theme-light`:`theme-${n}`})());return l.user_effect(()=>{let e=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`)??null;if(!e)return;l.set(t,e.matches,!0);let n=e=>{l.set(t,e.matches,!0)};return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)}),{get themeClass(){return l.get(n)}}}var ee=c.from_svg(`<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 4.5L6 8L9.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>`),te=c.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z" fill="currentColor"></path></svg>`),w=c.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),ne=c.from_html(`<button type="button"><!></button>`),T=c.from_svg(`<svg width="11" height="11" viewBox="0 0 14 14" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),E=c.from_html(`<button type="button" class="pi-btn pi-btn-clear"><!></button>`),D=c.from_html(`<li role="option"><span class="pi-flag" role="img"><!></span> <span class="pi-opt-name"> </span> <span class="pi-opt-code"> </span></li>`),re=c.from_html(`<li class="pi-empty"> </li>`),O=c.from_html(`<div role="dialog" aria-modal="false" aria-label="Select country"><div class="pi-search-wrap"><input type="search" class="pi-search" aria-label="Search countries"/></div> <ul class="pi-options" role="listbox" tabindex="-1"></ul></div>`),ie=c.from_html(`<div><div class="pi-selector"><button type="button"><span class="pi-flag" role="img"><!></span> <span class="pi-code"> </span> <!></button></div> <div class="pi-input-wrap"><input type="tel" inputmode="tel" autocomplete="tel-national" autocorrect="off" autocapitalize="off" spellcheck="false" class="pi-input"/> <div class="pi-actions" role="toolbar" aria-label="Phone input actions"><!> <!> <!></div></div></div> <!> <div class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>`,1);function ae(e,t){c.push(t,!0);let n=c.prop(t,`value`,15,``),r=c.prop(t,`detect`,3,!0),i=c.prop(t,`size`,3,`normal`),a=c.prop(t,`theme`,3,`auto`),o=c.prop(t,`disabled`,3,!1),s=c.prop(t,`readonly`,3,!1),l=c.prop(t,`showCopy`,3,!0),d=c.prop(t,`showClear`,3,!1),m=c.prop(t,`withValidity`,3,!0),g=c.prop(t,`searchPlaceholder`,3,`Search country or code...`),_=c.prop(t,`noResultsText`,3,`No countries found`),b=c.prop(t,`clearButtonLabel`,3,`Clear phone number`),x=c.prop(t,`dropdownClass`,3,``),ae=c.prop(t,`disableDefaultStyles`,3,!1),k=c.rest_props(t,`$$slots.$$events.$$legacy.value.id.name.country.detect.locale.size.theme.disabled.readonly.showCopy.showClear.withValidity.searchPlaceholder.noResultsText.clearButtonLabel.dropdownClass.disableDefaultStyles.onchange.oncountrychange.onvalidationchange.onfocus.onblur.oncopy.onclear.flag.copysvg.clearsvg.actionsbefore.class`.split(`.`)),A=c.state(null),j=c.state(null),M=c.state(null),N=c.state(null),P=c.state(null),F=c.state(null),I=f({country:()=>t.country,locale:()=>t.locale,detect:()=>r(),onCountryChange:(...e)=>t.oncountrychange?.(...e)}),L=p({country:()=>I.country,value:()=>n(),onChange:e=>n(e),onPhoneChange:(...e)=>t.onchange?.(...e),onValidationChange:(...e)=>t.onvalidationchange?.(...e)}),R=h(),z=c.derived(()=>o()||s()),oe=c.derived(()=>R.showValidationHint&&L.shouldShowWarn),se=c.derived(()=>l()&&!L.isEmpty&&!o()),B=c.derived(()=>d()&&!L.isEmpty&&!c.get(z)),V=S({liveRef:()=>c.get(M),fullFormatted:()=>L.fullFormatted,onCopy:(...e)=>t.oncopy?.(...e)}),H=()=>(0,u.tick)().then(()=>c.get(j)?.focus()),U=y({rootRef:()=>c.get(A),dropdownRef:()=>c.get(N),searchRef:()=>c.get(P),selectorRef:()=>c.get(F),locale:()=>I.locale,countryOption:()=>t.country,inactive:()=>c.get(z),onSelectCountry:I.setCountry,onAfterSelect:H}),W=c.state(`0`);(0,u.onMount)(()=>{c.set(W,Math.random().toString(36).slice(2,10),!0)});let G=c.derived(()=>`pi-options-${c.get(W)}`),K=e=>`pi-option-${c.get(W)}-${e}`,ce=c.derived(()=>U.dropdownOpen&&U.filteredCountries[U.focusedIndex]?K(U.focusedIndex):void 0),q=v({formatter:()=>L.formatter,digits:()=>L.digits,inactive:()=>c.get(z),onChange:e=>n(e),scheduleValidationHint:R.scheduleValidationHint}),le=e=>{R.clearValidationHint(!1),U.closeDropdown(),t.onfocus?.(e)},ue=e=>t.onblur?.(e);function de(){H()}function fe(){c.get(j)?.blur()}function pe(){n(``),R.clearValidationHint(),t.onclear?.()}function me(e){I.setCountry(e)}function he(){return L.full}function ge(){return L.fullFormatted}function _e(){return L.digits}function ve(){return L.isComplete}function ye(){return L.isComplete}let be=()=>{pe(),H()},xe=C({theme:()=>a()}),Se=c.derived(()=>[`phone-input`,`size-${i()}`,xe.themeClass,o()&&`is-disabled`,s()&&`is-readonly`,ae()&&`is-unstyled`,m()&&c.get(oe)&&`is-incomplete`,m()&&L.isComplete&&`is-complete`,t.class].filter(Boolean).join(` `)),Ce=c.derived(()=>+c.get(se)+ +c.get(B)+ +!!t.actionsbefore);function we(e){return document.body.appendChild(e),{destroy:()=>e.remove()}}var Te={focus:de,blur:fe,clear:pe,selectCountry:me,getFullNumber:he,getFullFormattedNumber:ge,getDigits:_e,isValid:ve,isComplete:ye},Ee=ie(),J=c.first_child(Ee);c.attribute_effect(J,()=>({class:c.get(Se),...k,role:`group`,"aria-label":`Phone input with country selector`,[c.STYLE]:{"--pi-actions-count":c.get(Ce)}}));var Y=c.child(J),X=c.child(Y);let De;var Z=c.child(X),Oe=c.child(Z),ke=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.flag,()=>I.country),c.append(e,n)},Ae=e=>{var t=c.text();c.template_effect(()=>c.set_text(t,I.country.flag)),c.append(e,t)};c.if(Oe,e=>{t.flag?e(ke):e(Ae,-1)}),c.reset(Z);var Q=c.sibling(Z,2),je=c.child(Q,!0);c.reset(Q);var Me=c.sibling(Q,2),Ne=e=>{var t=ee();let n;c.template_effect(()=>n=c.set_class(t,0,`pi-chevron`,null,n,{"is-open":U.dropdownOpen})),c.append(e,t)};c.if(Me,e=>{!c.get(z)&&U.hasDropdown&&e(Ne)}),c.reset(X),c.reset(Y),c.bind_this(Y,e=>c.set(F,e),()=>c.get(F));var Pe=c.sibling(Y,2),$=c.child(Pe);c.remove_input_defaults($),c.bind_this($,e=>c.set(j,e),()=>c.get(j));var Fe=c.sibling($,2),Ie=c.child(Fe),Le=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.actionsbefore),c.append(e,n)};c.if(Ie,e=>{t.actionsbefore&&e(Le)});var Re=c.sibling(Ie,2),ze=e=>{var n=ne();let r;var i=c.child(n),a=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.copysvg,()=>V.copied),c.append(e,n)},o=e=>{var t=te();c.append(e,t)},s=e=>{var t=w();c.append(e,t)};c.if(i,e=>{t.copysvg?e(a):V.copied?e(o,1):e(s,-1)}),c.reset(n),c.template_effect(()=>{r=c.set_class(n,1,`pi-btn pi-btn-copy`,null,r,{"is-copied":V.copied}),c.set_attribute(n,`aria-label`,V.copyAriaLabel),c.set_attribute(n,`title`,V.copyButtonTitle)}),c.delegated(`click`,n,function(...e){V.onCopyClick?.apply(this,e)}),c.append(e,n)};c.if(Re,e=>{c.get(se)&&e(ze)});var Be=c.sibling(Re,2),Ve=e=>{var n=E(),r=c.child(n),i=e=>{var n=c.comment(),r=c.first_child(n);c.snippet(r,()=>t.clearsvg),c.append(e,n)},a=e=>{var t=T();c.append(e,t)};c.if(r,e=>{t.clearsvg?e(i):e(a,-1)}),c.reset(n),c.template_effect(()=>{c.set_attribute(n,`aria-label`,b()),c.set_attribute(n,`title`,b())}),c.delegated(`click`,n,be),c.append(e,n)};c.if(Be,e=>{c.get(B)&&e(Ve)}),c.reset(Fe),c.reset(Pe),c.reset(J),c.bind_this(J,e=>c.set(A,e),()=>c.get(A));var He=c.sibling(J,2),Ue=e=>{var n=O();let r,i;var a=c.child(n),o=c.child(a);c.remove_input_defaults(o),c.bind_this(o,e=>c.set(P,e),()=>c.get(P)),c.reset(a);var s=c.sibling(a,2);c.each(s,23,()=>U.filteredCountries,e=>e.id,(e,n,r)=>{var i=D();let a;var o=c.child(i),s=c.child(o),l=e=>{var r=c.comment(),i=c.first_child(r);c.snippet(i,()=>t.flag,()=>c.get(n)),c.append(e,r)},u=e=>{var t=c.text();c.template_effect(()=>c.set_text(t,c.get(n).flag)),c.append(e,t)};c.if(s,e=>{t.flag?e(l):e(u,-1)}),c.reset(o);var d=c.sibling(o,2),f=c.child(d,!0);c.reset(d);var p=c.sibling(d,2),m=c.child(p,!0);c.reset(p),c.reset(i),c.template_effect(e=>{c.set_attribute(i,`id`,e),a=c.set_class(i,1,`pi-option`,null,a,{"is-focused":c.get(r)===U.focusedIndex,"is-selected":c.get(n).id===I.country.id}),c.set_attribute(i,`aria-selected`,c.get(n).id===I.country.id),c.set_attribute(i,`title`,c.get(n).name),c.set_attribute(o,`aria-label`,`${c.get(n).name??``} flag`),c.set_text(f,c.get(n).name),c.set_text(m,c.get(n).code)},[()=>K(c.get(r))]),c.delegated(`click`,i,()=>U.selectCountry(c.get(n).id)),c.event(`mouseenter`,i,()=>U.setFocusedIndex(c.get(r))),c.append(e,i)},e=>{var t=re(),n=c.child(t,!0);c.reset(t),c.template_effect(()=>c.set_text(n,_())),c.append(e,t)}),c.reset(s),c.reset(n),c.action(n,e=>we?.(e)),c.bind_this(n,e=>c.set(N,e),()=>c.get(N)),c.template_effect(()=>{r=c.set_class(n,1,`phone-dropdown ${x()??``} ${xe.themeClass??``}`,null,r,{"is-closing":U.isClosing}),i=c.set_style(n,``,i,{position:`absolute`,top:U.dropdownStyle.top,left:U.dropdownStyle.left,width:U.dropdownStyle.width}),c.set_attribute(o,`placeholder`,g()),c.set_attribute(o,`aria-controls`,c.get(G)),c.set_attribute(o,`aria-activedescendant`,c.get(ce)),c.set_value(o,U.search),c.set_attribute(s,`id`,c.get(G))}),c.event(`animationend`,n,function(...e){U.handleDropdownAnimationEnd?.apply(this,e)}),c.delegated(`keydown`,o,function(...e){U.handleSearchKeydown?.apply(this,e)}),c.delegated(`input`,o,function(...e){U.handleSearchChange?.apply(this,e)}),c.append(e,n)};c.if(He,e=>{U.dropdownOpen&&e(Ue)});var We=c.sibling(He,2);return c.bind_this(We,e=>c.set(M,e),()=>c.get(M)),c.template_effect(()=>{De=c.set_class(X,1,`pi-selector-btn`,null,De,{"no-dropdown":!U.hasDropdown||s()}),X.disabled=o(),c.set_attribute(X,`tabindex`,c.get(z)||!U.hasDropdown?-1:void 0),c.set_attribute(X,`aria-label`,`Selected country: ${I.country.name??``}`),c.set_attribute(X,`aria-expanded`,U.dropdownOpen),c.set_attribute(X,`aria-haspopup`,U.hasDropdown?`listbox`:void 0),c.set_attribute(Z,`aria-label`,`${I.country.name??``} flag`),c.set_text(je,I.country.code),c.set_attribute($,`id`,t.id),c.set_attribute($,`name`,t.name),c.set_attribute($,`placeholder`,L.displayPlaceholder),c.set_value($,L.displayValue),$.disabled=o(),$.readOnly=s(),c.set_attribute($,`aria-invalid`,c.get(oe))}),c.delegated(`click`,X,function(...e){U.toggleDropdown?.apply(this,e)}),c.delegated(`beforeinput`,$,function(...e){q.handleBeforeInput?.apply(this,e)}),c.delegated(`input`,$,function(...e){q.handleInput?.apply(this,e)}),c.delegated(`keydown`,$,function(...e){q.handleKeydown?.apply(this,e)}),c.event(`paste`,$,function(...e){q.handlePaste?.apply(this,e)}),c.event(`focus`,$,le),c.event(`blur`,$,ue),c.append(e,Ee),c.pop(Te)}c.delegate([`click`,`beforeinput`,`input`,`keydown`]);function k(e){let t=l.state(null),n=f({country:e.country,locale:e.locale,detect:e.detect,onCountryChange:e.onCountryChange}),r=p({country:()=>n.country,value:e.value,onChange:e.onChange,onPhoneChange:e.onPhoneChange}),{handleBeforeInput:i,handleInput:a,handleKeydown:o,handlePaste:s}=v({formatter:()=>r.formatter,digits:()=>r.digits,onChange:e.onChange});return l.user_effect(()=>{let e=l.get(t);if(e)return e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.addEventListener(`beforeinput`,i),e.addEventListener(`input`,a),e.addEventListener(`keydown`,o),e.addEventListener(`paste`,s),()=>{e.removeEventListener(`beforeinput`,i),e.removeEventListener(`input`,a),e.removeEventListener(`keydown`,o),e.removeEventListener(`paste`,s)}}),l.user_effect(()=>{let e=l.get(t);e&&(e.value=r.displayValue,e.setAttribute(`placeholder`,r.displayPlaceholder))}),{get inputRef(){return l.get(t)},set inputRef(e){l.set(t,e,!0)},get digits(){return r.digits},get formatter(){return r.formatter},get full(){return r.full},get fullFormatted(){return r.fullFormatted},get isComplete(){return r.isComplete},get isEmpty(){return r.isEmpty},get shouldShowWarn(){return r.shouldShowWarn},get country(){return n.country},get locale(){return n.locale},setCountry:n.setCountry,clear:()=>{e.onChange(``)}}}function A(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function j(e){return t=>{if(t.tagName!==`INPUT`){console.warn(`[phoneMaskAttachment] Attachment can only be used on input elements`);return}let n=A(e),r=l.effect_root(()=>{let e=l.state(l.proxy(t.value||``)),r=k({country:()=>n.country,locale:()=>n.locale,detect:()=>n.detect,value:()=>l.get(e),onChange:t=>{l.set(e,t,!0)},onPhoneChange:n.onChange,onCountryChange:n.onCountryChange});r.inputRef=t,t.__phoneMaskState={get country(){return r.country},get formatter(){return r.formatter},get digits(){return r.digits},get locale(){return r.locale},options:n,setCountry:e=>r.setCountry(e)}});return()=>{r(),delete t.__phoneMaskState}}}function M(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function N(e,t,n){if(t.digits=n,e.value=t.formatter.formatDisplay(t.digits),t.options.onChange){let n=e.value?`${t.country.code} ${e.value}`:``,r=t.digits?`${t.country.code}${t.digits}`:``;t.options.onChange({full:r,fullFormatted:n,digits:t.digits})}}function P(e,t){let n=t.formatter.getMaxDigits(),r=(0,d.extractDigits)(e.value,n),i=t.formatter.formatDisplay(r);(r!==t.digits||e.value!==i)&&N(e,t,r)}function F(e){let t=e.country.id,n=(0,d.parseCountryCode)(e.options.country);n&&n!==t&&e.setCountry(n)}function I(e,t,n){return r=>{let i=n(r,t);i&&(N(e,t,i.newDigits),Promise.resolve().then(()=>{(0,d.setCaret)(e,t.formatter.getCaretPosition(i.caretDigitIndex))}))}}async function L(e){let t=(0,d.parseCountryCode)(e.country);if(t)return t;if(e.detect){let e=(0,d.parseCountryCode)(await(0,d.detectByGeoIp)());if(e)return e;let t=(0,d.parseCountryCode)((0,d.detectCountryFromLocale)());if(t)return t}return`US`}function R(e,t){if(e.tagName!==`INPUT`)return console.warn(`[phoneMaskAction] Action can only be used on input elements`),{update(){},destroy(){}};e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.setAttribute(`placeholder`,``);let n=M(t),r=n.locale||(0,d.getNavigatorLang)(),i=(0,d.getCountry)((0,d.parseCountryCode)(n.country,`US`),r),a={country:i,formatter:(0,d.createPhoneFormatter)(i),digits:``,locale:r,options:n,setCountry(t){let n=(0,d.parseCountryCode)(t);if(!n)return!1;let r=(0,d.getCountry)(n,this.locale);return this.country=r,this.options.onCountryChange?.(r),this.formatter=(0,d.createPhoneFormatter)(r),e.placeholder=this.formatter.getPlaceholder(),P(e,this),!0}};e.__phoneMaskState=a;let o=I(e,a,d.processInput),s=I(e,a,d.processKeydown),c=I(e,a,d.processPaste);return e.addEventListener(`beforeinput`,d.processBeforeInput),e.addEventListener(`input`,o),e.addEventListener(`keydown`,s),e.addEventListener(`paste`,c),L(n).then(t=>{e.__phoneMaskState===a&&a.setCountry(t)}),{update(t){a.options=M(t),F(a),P(e,a)},destroy(){e.removeEventListener(`beforeinput`,d.processBeforeInput),e.removeEventListener(`input`,o),e.removeEventListener(`keydown`,s),e.removeEventListener(`paste`,c),delete e.__phoneMaskState}}}var z=ae;exports.PhoneInput=z,exports.phoneMaskAction=R,exports.phoneMaskAttachment=j,exports.usePhoneMask=k;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"svelte/internal/disclose-version";import*as e from"svelte/internal/client";import{onDestroy as t,onMount as n,tick as r}from"svelte";import{MasksFull as i,createPhoneFormatter as a,detectByGeoIp as o,detectCountryFromLocale as s,extractDigits as c,filterCountries as l,getCountry as u,getNavigatorLang as d,parseCountryCode as f,processBeforeInput as p,processInput as m,processKeydown as h,processPaste as g,setCaret as _}from"@desource/phone-mask";function v({country:t,locale:n,detect:r,onCountryChange:i}={}){let a=e.state(e.proxy(f(t?.(),`US`))),c=e.derived(()=>n?.()||d()),l=e.derived(()=>u(e.get(a),e.get(c))),p=t=>{let n=f(t);return n?(e.set(a,n,!0),!0):!1},m=async()=>{p(await o())||p(s())};return e.user_effect(()=>{let n=t?.();n&&n!==e.get(a)&&p(n)}),e.user_effect(()=>{r?.()&&!t?.()&&m()}),e.user_effect(()=>{i?.(e.get(l))}),{get country(){return e.get(l)},get locale(){return e.get(c)},setCountry:p}}function y({country:t,value:n,onChange:r,onPhoneChange:i,onValidationChange:o}){let s=e.derived(()=>a(t())),l=e.derived(()=>e.get(s).getMaxDigits()),u=e.derived(()=>c(n(),e.get(l))),d=e.derived(()=>e.get(s).getPlaceholder()),f=e.derived(()=>e.get(s).formatDisplay(e.get(u))),p=e.derived(()=>e.get(u)?`${t().code}${e.get(u)}`:``),m=e.derived(()=>e.get(f)?`${t().code} ${e.get(f)}`:``),h=e.derived(()=>e.get(s).isComplete(e.get(u))),g=e.derived(()=>e.get(u).length===0),_=e.derived(()=>!e.get(g)&&!e.get(h)),v=e.derived(()=>({full:e.get(p),fullFormatted:e.get(m),digits:e.get(u)}));return e.user_pre_effect(()=>{let t=n(),i=e.get(u);t!==i&&r(i)}),e.user_effect(()=>{i?.(e.get(v))}),e.user_effect(()=>{o?.(e.get(h))}),{get digits(){return e.get(u)},get formatter(){return e.get(s)},get displayPlaceholder(){return e.get(d)},get displayValue(){return e.get(f)},get full(){return e.get(p)},get fullFormatted(){return e.get(m)},get isComplete(){return e.get(h)},get isEmpty(){return e.get(g)},get shouldShowWarn(){return e.get(_)}}}function b(){let e=null,n=()=>{e&&=(clearTimeout(e),null)};return t(n),{set:(t,r)=>{n(),e=setTimeout(t,r)},clear:n}}function x(){let t=e.state(!1),n=b();return{get showValidationHint(){return e.get(t)},clearValidationHint:(r=!0)=>{r&&e.set(t,!1),n.clear()},scheduleValidationHint:r=>{e.set(t,!1),n.set(()=>{e.set(t,!0)},r)}}}var S=500,C=300;function w(e){let{formatter:t,digits:n,inactive:i,onChange:a,scheduleValidationHint:o}=e,s=(e,n)=>{r().then(()=>{e&&_(e,t().getCaretPosition(n))})};return{handleBeforeInput:e=>{p(e)},handleInput:e=>{if(i?.())return;let n=m(e,{formatter:t()});n&&(a?.(n.newDigits),s(e.target,n.caretDigitIndex),o?.(S))},handleKeydown:e=>{if(i?.())return;let r=h(e,{digits:n(),formatter:t()});r&&(a?.(r.newDigits),s(e.target,r.caretDigitIndex),o?.(C))},handlePaste:e=>{if(i?.())return;let r=g(e,{digits:n(),formatter:t()});r&&(a?.(r.newDigits),s(e.target,r.caretDigitIndex),o?.(C))}}}function T({rootRef:n,dropdownRef:a,searchRef:o,selectorRef:s,locale:c,countryOption:u,inactive:d,onSelectCountry:f,onAfterSelect:p}){let m=e.state(``),h=e.state(!1),g=e.state(!1),_=e.state(e.proxy({})),v=e.state(0),y=e.derived(()=>i(c())),b=e.derived(()=>l(e.get(y),e.get(m))),x=e.derived(()=>!u?.()&&e.get(y).length>1),S=t=>{e.set(v,t,!0)},C=()=>{r().then(()=>o()?.focus({preventScroll:!0}))},w=()=>{e.get(h)&&e.set(g,!0)},T=()=>{e.set(g,!1),e.set(h,!0),S(0),C()},E=()=>{e.get(g)&&(e.set(h,!1),e.set(g,!1))},D=()=>{d?.()||!e.get(x)||(e.get(h)?w():T())},O=t=>{f(t),w(),e.set(m,``),S(0),p?.()},ee=t=>{e.set(m,t.target.value,!0),S(0)},k=e=>{let t=e.target,n=a(),r=s();t&&(n?.contains(t)||r?.contains(t)||w())},A=t=>{if(t?.type===`scroll`&&t.target&&a()?.contains(t.target))return;let r=n();if(!r)return;let i=r.getBoundingClientRect();e.set(_,{top:`${i.bottom+globalThis.scrollY+8}px`,left:`${i.left+globalThis.scrollX}px`,width:`${i.width}px`},!0)},j=()=>{r().then(()=>{let t=a()?.lastElementChild,n=t?.children[e.get(v)];if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),o=0;if(i.top<r.top)o=t.scrollTop-(r.top-i.top);else if(i.bottom>r.bottom)o=t.scrollTop+(i.bottom-r.bottom);else return;t.scrollTo({top:o,behavior:`smooth`})})},te=t=>{t.key===`ArrowDown`?(t.preventDefault(),S(Math.min(e.get(v)+1,e.get(b).length-1)),j()):t.key===`ArrowUp`?(t.preventDefault(),S(Math.max(e.get(v)-1,0)),j()):t.key===`Enter`&&e.get(b)[e.get(v)]?(t.preventDefault(),O(e.get(b)[e.get(v)].id)):t.key===`Escape`&&w()},M=()=>{globalThis.removeEventListener(`resize`,A),globalThis.removeEventListener(`scroll`,A,!0),globalThis.removeEventListener(`click`,k,!0)};return e.user_effect(()=>{!e.get(x)&&e.get(h)&&w()}),e.user_effect(()=>{if(!e.get(h)){M();return}A(),globalThis.addEventListener(`resize`,A),globalThis.addEventListener(`scroll`,A,!0),globalThis.addEventListener(`click`,k,!0)}),t(M),{get dropdownOpen(){return e.get(h)},get isClosing(){return e.get(g)},get search(){return e.get(m)},get focusedIndex(){return e.get(v)},get dropdownStyle(){return e.get(_)},get filteredCountries(){return e.get(b)},get hasDropdown(){return e.get(x)},openDropdown:T,closeDropdown:w,toggleDropdown:D,selectCountry:O,setFocusedIndex:S,handleSearchChange:ee,handleSearchKeydown:te,handleDropdownAnimationEnd:E}}function E(t=1800){let n=e.state(!1),r=e.state(!1),i=b();return{get copied(){return e.get(n)},get isCopying(){return e.get(r)},copy:async a=>{if(e.get(r))return!1;let o=a.trim();if(!o)return!1;e.set(r,!0);try{return await navigator.clipboard.writeText(o),e.set(n,!0),i.set(()=>{e.set(n,!1)},t),!0}catch(e){return console.warn(`Copy failed`,e),!1}finally{e.set(r,!1)}}}}var D=1800;function O({liveRef:t,fullFormatted:n,onCopy:r}){let i=b(),a=E(D),o=e.derived(()=>a.copied?`Copied`:`Copy ${n()}`),s=e.derived(()=>a.copied?`Copied`:`Copy phone number`),c=e=>{let n=t?.();n&&(n.textContent=e,i.set(()=>{let e=t?.();e&&(e.textContent=``)},D))};return{get copied(){return a.copied},get copyAriaLabel(){return e.get(o)},get copyButtonTitle(){return e.get(s)},onCopyClick:async()=>{let e=n().trim();await a.copy(e)&&(r?.(e),c(`Phone number copied to clipboard`))}}}function ee({theme:t}){let n=e.state(!1),r=e.derived(()=>(()=>{let r=t();return r===`auto`?e.get(n)?`theme-dark`:`theme-light`:`theme-${r}`})());return e.user_effect(()=>{let t=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`)??null;if(!t)return;e.set(n,t.matches,!0);let r=t=>{e.set(n,t.matches,!0)};return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)}),{get themeClass(){return e.get(r)}}}var k=e.from_svg(`<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 4.5L6 8L9.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>`),A=e.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z" fill="currentColor"></path></svg>`),j=e.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),te=e.from_html(`<button type="button"><!></button>`),M=e.from_svg(`<svg width="11" height="11" viewBox="0 0 14 14" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),ne=e.from_html(`<button type="button" class="pi-btn pi-btn-clear"><!></button>`),re=e.from_html(`<li role="option"><span class="pi-flag" role="img"><!></span> <span class="pi-opt-name"> </span> <span class="pi-opt-code"> </span></li>`),ie=e.from_html(`<li class="pi-empty"> </li>`),ae=e.from_html(`<div role="dialog" aria-modal="false" aria-label="Select country"><div class="pi-search-wrap"><input type="search" class="pi-search" aria-label="Search countries"/></div> <ul class="pi-options" role="listbox" tabindex="-1"></ul></div>`),oe=e.from_html(`<div><div class="pi-selector"><button type="button"><span class="pi-flag" role="img"><!></span> <span class="pi-code"> </span> <!></button></div> <div class="pi-input-wrap"><input type="tel" inputmode="tel" autocomplete="tel-national" autocorrect="off" autocapitalize="off" spellcheck="false" class="pi-input"/> <div class="pi-actions" role="toolbar" aria-label="Phone input actions"><!> <!> <!></div></div></div> <!> <div class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>`,1);function N(t,i){e.push(i,!0);let a=e.prop(i,`value`,15,``),o=e.prop(i,`detect`,3,!0),s=e.prop(i,`size`,3,`normal`),c=e.prop(i,`theme`,3,`auto`),l=e.prop(i,`disabled`,3,!1),u=e.prop(i,`readonly`,3,!1),d=e.prop(i,`showCopy`,3,!0),f=e.prop(i,`showClear`,3,!1),p=e.prop(i,`withValidity`,3,!0),m=e.prop(i,`searchPlaceholder`,3,`Search country or code...`),h=e.prop(i,`noResultsText`,3,`No countries found`),g=e.prop(i,`clearButtonLabel`,3,`Clear phone number`),_=e.prop(i,`dropdownClass`,3,``),b=e.prop(i,`disableDefaultStyles`,3,!1),S=e.rest_props(i,`$$slots.$$events.$$legacy.value.id.name.country.detect.locale.size.theme.disabled.readonly.showCopy.showClear.withValidity.searchPlaceholder.noResultsText.clearButtonLabel.dropdownClass.disableDefaultStyles.onchange.oncountrychange.onvalidationchange.onfocus.onblur.oncopy.onclear.flag.copysvg.clearsvg.actionsbefore.class`.split(`.`)),C=e.state(null),E=e.state(null),D=e.state(null),N=e.state(null),P=e.state(null),F=e.state(null),I=v({country:()=>i.country,locale:()=>i.locale,detect:()=>o(),onCountryChange:(...e)=>i.oncountrychange?.(...e)}),L=y({country:()=>I.country,value:()=>a(),onChange:e=>a(e),onPhoneChange:(...e)=>i.onchange?.(...e),onValidationChange:(...e)=>i.onvalidationchange?.(...e)}),R=x(),z=e.derived(()=>l()||u()),B=e.derived(()=>R.showValidationHint&&L.shouldShowWarn),V=e.derived(()=>d()&&!L.isEmpty&&!l()),H=e.derived(()=>f()&&!L.isEmpty&&!e.get(z)),U=O({liveRef:()=>e.get(D),fullFormatted:()=>L.fullFormatted,onCopy:(...e)=>i.oncopy?.(...e)}),W=()=>r().then(()=>e.get(E)?.focus()),G=T({rootRef:()=>e.get(C),dropdownRef:()=>e.get(N),searchRef:()=>e.get(P),selectorRef:()=>e.get(F),locale:()=>I.locale,countryOption:()=>i.country,inactive:()=>e.get(z),onSelectCountry:I.setCountry,onAfterSelect:W}),K=e.state(`0`);n(()=>{e.set(K,Math.random().toString(36).slice(2,10),!0)});let se=e.derived(()=>`pi-options-${e.get(K)}`),ce=t=>`pi-option-${e.get(K)}-${t}`,le=e.derived(()=>G.dropdownOpen&&G.filteredCountries[G.focusedIndex]?ce(G.focusedIndex):void 0),q=w({formatter:()=>L.formatter,digits:()=>L.digits,inactive:()=>e.get(z),onChange:e=>a(e),scheduleValidationHint:R.scheduleValidationHint}),ue=e=>{R.clearValidationHint(!1),G.closeDropdown(),i.onfocus?.(e)},de=e=>i.onblur?.(e);function fe(){W()}function pe(){e.get(E)?.blur()}function me(){a(``),R.clearValidationHint(),i.onclear?.()}function he(e){I.setCountry(e)}function ge(){return L.full}function _e(){return L.fullFormatted}function ve(){return L.digits}function ye(){return L.isComplete}function be(){return L.isComplete}let xe=()=>{me(),W()},Se=ee({theme:()=>c()}),Ce=e.derived(()=>[`phone-input`,`size-${s()}`,Se.themeClass,l()&&`is-disabled`,u()&&`is-readonly`,b()&&`is-unstyled`,p()&&e.get(B)&&`is-incomplete`,p()&&L.isComplete&&`is-complete`,i.class].filter(Boolean).join(` `)),we=e.derived(()=>+e.get(V)+ +e.get(H)+(i.actionsbefore?1:0));function Te(e){return document.body.appendChild(e),{destroy:()=>e.remove()}}var Ee={focus:fe,blur:pe,clear:me,selectCountry:he,getFullNumber:ge,getFullFormattedNumber:_e,getDigits:ve,isValid:ye,isComplete:be},De=oe(),J=e.first_child(De);e.attribute_effect(J,()=>({class:e.get(Ce),...S,role:`group`,"aria-label":`Phone input with country selector`,[e.STYLE]:{"--pi-actions-count":e.get(we)}}));var Y=e.child(J),X=e.child(Y);let Oe;var Z=e.child(X),ke=e.child(Z),Ae=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.flag,()=>I.country),e.append(t,n)},je=t=>{var n=e.text();e.template_effect(()=>e.set_text(n,I.country.flag)),e.append(t,n)};e.if(ke,e=>{i.flag?e(Ae):e(je,-1)}),e.reset(Z);var Q=e.sibling(Z,2),Me=e.child(Q,!0);e.reset(Q);var Ne=e.sibling(Q,2),Pe=t=>{var n=k();let r;e.template_effect(()=>r=e.set_class(n,0,`pi-chevron`,null,r,{"is-open":G.dropdownOpen})),e.append(t,n)};e.if(Ne,t=>{!e.get(z)&&G.hasDropdown&&t(Pe)}),e.reset(X),e.reset(Y),e.bind_this(Y,t=>e.set(F,t),()=>e.get(F));var Fe=e.sibling(Y,2),$=e.child(Fe);e.remove_input_defaults($),e.bind_this($,t=>e.set(E,t),()=>e.get(E));var Ie=e.sibling($,2),Le=e.child(Ie),Re=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.actionsbefore),e.append(t,n)};e.if(Le,e=>{i.actionsbefore&&e(Re)});var ze=e.sibling(Le,2),Be=t=>{var n=te();let r;var a=e.child(n),o=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.copysvg,()=>U.copied),e.append(t,n)},s=t=>{var n=A();e.append(t,n)},c=t=>{var n=j();e.append(t,n)};e.if(a,e=>{i.copysvg?e(o):U.copied?e(s,1):e(c,-1)}),e.reset(n),e.template_effect(()=>{r=e.set_class(n,1,`pi-btn pi-btn-copy`,null,r,{"is-copied":U.copied}),e.set_attribute(n,`aria-label`,U.copyAriaLabel),e.set_attribute(n,`title`,U.copyButtonTitle)}),e.delegated(`click`,n,function(...e){U.onCopyClick?.apply(this,e)}),e.append(t,n)};e.if(ze,t=>{e.get(V)&&t(Be)});var Ve=e.sibling(ze,2),He=t=>{var n=ne(),r=e.child(n),a=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.clearsvg),e.append(t,n)},o=t=>{var n=M();e.append(t,n)};e.if(r,e=>{i.clearsvg?e(a):e(o,-1)}),e.reset(n),e.template_effect(()=>{e.set_attribute(n,`aria-label`,g()),e.set_attribute(n,`title`,g())}),e.delegated(`click`,n,xe),e.append(t,n)};e.if(Ve,t=>{e.get(H)&&t(He)}),e.reset(Ie),e.reset(Fe),e.reset(J),e.bind_this(J,t=>e.set(C,t),()=>e.get(C));var Ue=e.sibling(J,2),We=t=>{var n=ae();let r,a;var o=e.child(n),s=e.child(o);e.remove_input_defaults(s),e.bind_this(s,t=>e.set(P,t),()=>e.get(P)),e.reset(o);var c=e.sibling(o,2);e.each(c,23,()=>G.filteredCountries,e=>e.id,(t,n,r)=>{var a=re();let o;var s=e.child(a),c=e.child(s),l=t=>{var r=e.comment(),a=e.first_child(r);e.snippet(a,()=>i.flag,()=>e.get(n)),e.append(t,r)},u=t=>{var r=e.text();e.template_effect(()=>e.set_text(r,e.get(n).flag)),e.append(t,r)};e.if(c,e=>{i.flag?e(l):e(u,-1)}),e.reset(s);var d=e.sibling(s,2),f=e.child(d,!0);e.reset(d);var p=e.sibling(d,2),m=e.child(p,!0);e.reset(p),e.reset(a),e.template_effect(t=>{e.set_attribute(a,`id`,t),o=e.set_class(a,1,`pi-option`,null,o,{"is-focused":e.get(r)===G.focusedIndex,"is-selected":e.get(n).id===I.country.id}),e.set_attribute(a,`aria-selected`,e.get(n).id===I.country.id),e.set_attribute(a,`title`,e.get(n).name),e.set_attribute(s,`aria-label`,`${e.get(n).name??``} flag`),e.set_text(f,e.get(n).name),e.set_text(m,e.get(n).code)},[()=>ce(e.get(r))]),e.delegated(`click`,a,()=>G.selectCountry(e.get(n).id)),e.event(`mouseenter`,a,()=>G.setFocusedIndex(e.get(r))),e.append(t,a)},t=>{var n=ie(),r=e.child(n,!0);e.reset(n),e.template_effect(()=>e.set_text(r,h())),e.append(t,n)}),e.reset(c),e.reset(n),e.action(n,e=>Te?.(e)),e.bind_this(n,t=>e.set(N,t),()=>e.get(N)),e.template_effect(()=>{r=e.set_class(n,1,`phone-dropdown ${_()??``} ${Se.themeClass??``}`,null,r,{"is-closing":G.isClosing}),a=e.set_style(n,``,a,{position:`absolute`,top:G.dropdownStyle.top,left:G.dropdownStyle.left,width:G.dropdownStyle.width}),e.set_attribute(s,`placeholder`,m()),e.set_attribute(s,`aria-controls`,e.get(se)),e.set_attribute(s,`aria-activedescendant`,e.get(le)),e.set_value(s,G.search),e.set_attribute(c,`id`,e.get(se))}),e.event(`animationend`,n,function(...e){G.handleDropdownAnimationEnd?.apply(this,e)}),e.delegated(`keydown`,s,function(...e){G.handleSearchKeydown?.apply(this,e)}),e.delegated(`input`,s,function(...e){G.handleSearchChange?.apply(this,e)}),e.append(t,n)};e.if(Ue,e=>{G.dropdownOpen&&e(We)});var Ge=e.sibling(Ue,2);return e.bind_this(Ge,t=>e.set(D,t),()=>e.get(D)),e.template_effect(()=>{Oe=e.set_class(X,1,`pi-selector-btn`,null,Oe,{"no-dropdown":!G.hasDropdown||u()}),X.disabled=l(),e.set_attribute(X,`tabindex`,e.get(z)||!G.hasDropdown?-1:void 0),e.set_attribute(X,`aria-label`,`Selected country: ${I.country.name??``}`),e.set_attribute(X,`aria-expanded`,G.dropdownOpen),e.set_attribute(X,`aria-haspopup`,G.hasDropdown?`listbox`:void 0),e.set_attribute(Z,`aria-label`,`${I.country.name??``} flag`),e.set_text(Me,I.country.code),e.set_attribute($,`id`,i.id),e.set_attribute($,`name`,i.name),e.set_attribute($,`placeholder`,L.displayPlaceholder),e.set_value($,L.displayValue),$.disabled=l(),$.readOnly=u(),e.set_attribute($,`aria-invalid`,e.get(B))}),e.delegated(`click`,X,function(...e){G.toggleDropdown?.apply(this,e)}),e.delegated(`beforeinput`,$,function(...e){q.handleBeforeInput?.apply(this,e)}),e.delegated(`input`,$,function(...e){q.handleInput?.apply(this,e)}),e.delegated(`keydown`,$,function(...e){q.handleKeydown?.apply(this,e)}),e.event(`paste`,$,function(...e){q.handlePaste?.apply(this,e)}),e.event(`focus`,$,ue),e.event(`blur`,$,de),e.append(t,De),e.pop(Ee)}e.delegate([`click`,`beforeinput`,`input`,`keydown`]);function P(t){let n=e.state(null),r=v({country:t.country,locale:t.locale,detect:t.detect,onCountryChange:t.onCountryChange}),i=y({country:()=>r.country,value:t.value,onChange:t.onChange,onPhoneChange:t.onPhoneChange}),{handleBeforeInput:a,handleInput:o,handleKeydown:s,handlePaste:c}=w({formatter:()=>i.formatter,digits:()=>i.digits,onChange:t.onChange});return e.user_effect(()=>{let t=e.get(n);if(t)return t.setAttribute(`type`,`tel`),t.setAttribute(`inputmode`,`tel`),t.addEventListener(`beforeinput`,a),t.addEventListener(`input`,o),t.addEventListener(`keydown`,s),t.addEventListener(`paste`,c),()=>{t.removeEventListener(`beforeinput`,a),t.removeEventListener(`input`,o),t.removeEventListener(`keydown`,s),t.removeEventListener(`paste`,c)}}),e.user_effect(()=>{let t=e.get(n);t&&(t.value=i.displayValue,t.setAttribute(`placeholder`,i.displayPlaceholder))}),{get inputRef(){return e.get(n)},set inputRef(t){e.set(n,t,!0)},get digits(){return i.digits},get formatter(){return i.formatter},get full(){return i.full},get fullFormatted(){return i.fullFormatted},get isComplete(){return i.isComplete},get isEmpty(){return i.isEmpty},get shouldShowWarn(){return i.shouldShowWarn},get country(){return r.country},get locale(){return r.locale},setCountry:r.setCountry,clear:()=>{t.onChange(``)}}}function F(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function I(t){return n=>{if(n.tagName!==`INPUT`){console.warn(`[phoneMaskAttachment] Attachment can only be used on input elements`);return}let r=F(t),i=e.effect_root(()=>{let t=e.state(e.proxy(n.value||``)),i=P({country:()=>r.country,locale:()=>r.locale,detect:()=>r.detect,value:()=>e.get(t),onChange:n=>{e.set(t,n,!0)},onPhoneChange:r.onChange,onCountryChange:r.onCountryChange});i.inputRef=n,n.__phoneMaskState={get country(){return i.country},get formatter(){return i.formatter},get digits(){return i.digits},get locale(){return i.locale},options:r,setCountry:e=>i.setCountry(e)}});return()=>{i(),delete n.__phoneMaskState}}}function L(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function R(e,t,n){if(t.digits=n,e.value=t.formatter.formatDisplay(t.digits),t.options.onChange){let n=e.value?`${t.country.code} ${e.value}`:``,r=t.digits?`${t.country.code}${t.digits}`:``;t.options.onChange({full:r,fullFormatted:n,digits:t.digits})}}function z(e,t){let n=t.formatter.getMaxDigits(),r=c(e.value,n),i=t.formatter.formatDisplay(r);(r!==t.digits||e.value!==i)&&R(e,t,r)}function B(e){let t=e.country.id,n=f(e.options.country);n&&n!==t&&e.setCountry(n)}function V(e,t,n){return r=>{let i=n(r,t);i&&(R(e,t,i.newDigits),Promise.resolve().then(()=>{_(e,t.formatter.getCaretPosition(i.caretDigitIndex))}))}}async function H(e){let t=f(e.country);if(t)return t;if(e.detect){let e=f(await o());if(e)return e;let t=f(s());if(t)return t}return`US`}function U(e,t){if(e.tagName!==`INPUT`)return console.warn(`[phoneMaskAction] Action can only be used on input elements`),{update(){},destroy(){}};e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.setAttribute(`placeholder`,``);let n=L(t),r=n.locale||d(),i=u(f(n.country,`US`),r),o={country:i,formatter:a(i),digits:``,locale:r,options:n,setCountry(t){let n=f(t);if(!n)return!1;let r=u(n,this.locale);return this.country=r,this.options.onCountryChange?.(r),this.formatter=a(r),e.placeholder=this.formatter.getPlaceholder(),z(e,this),!0}};e.__phoneMaskState=o;let s=V(e,o,m),c=V(e,o,h),l=V(e,o,g);return e.addEventListener(`beforeinput`,p),e.addEventListener(`input`,s),e.addEventListener(`keydown`,c),e.addEventListener(`paste`,l),H(n).then(t=>{e.__phoneMaskState===o&&o.setCountry(t)}),{update(t){o.options=L(t),B(o),z(e,o)},destroy(){e.removeEventListener(`beforeinput`,p),e.removeEventListener(`input`,s),e.removeEventListener(`keydown`,c),e.removeEventListener(`paste`,l),delete e.__phoneMaskState}}}var W=N;export{W as PhoneInput,U as phoneMaskAction,I as phoneMaskAttachment,P as usePhoneMask};
|
|
1
|
+
import"svelte/internal/disclose-version";import*as e from"svelte/internal/client";import{onDestroy as t,onMount as n,tick as r}from"svelte";import{MasksFull as i,createPhoneFormatter as a,detectByGeoIp as o,detectCountryFromLocale as s,extractDigits as c,filterCountries as l,getCountry as u,getNavigatorLang as d,parseCountryCode as f,processBeforeInput as p,processInput as m,processKeydown as h,processPaste as g,setCaret as _}from"@desource/phone-mask";function v({country:t,locale:n,detect:r,onCountryChange:i}={}){let a=e.state(e.proxy(f(t?.(),`US`))),c=e.derived(()=>n?.()||d()),l=e.derived(()=>u(e.get(a),e.get(c))),p=t=>{let n=f(t);return n?(e.set(a,n,!0),!0):!1},m=async()=>{p(await o())||p(s())};return e.user_effect(()=>{let n=t?.();n&&n!==e.get(a)&&p(n)}),e.user_effect(()=>{r?.()&&!t?.()&&m()}),e.user_effect(()=>{i?.(e.get(l))}),{get country(){return e.get(l)},get locale(){return e.get(c)},setCountry:p}}function y({country:t,value:n,onChange:r,onPhoneChange:i,onValidationChange:o}){let s=e.derived(()=>a(t())),l=e.derived(()=>e.get(s).getMaxDigits()),u=e.derived(()=>c(n(),e.get(l))),d=e.derived(()=>e.get(s).getPlaceholder()),f=e.derived(()=>e.get(s).formatDisplay(e.get(u))),p=e.derived(()=>e.get(u)?`${t().code}${e.get(u)}`:``),m=e.derived(()=>e.get(f)?`${t().code} ${e.get(f)}`:``),h=e.derived(()=>e.get(s).isComplete(e.get(u))),g=e.derived(()=>e.get(u).length===0),_=e.derived(()=>!e.get(g)&&!e.get(h)),v=e.derived(()=>({full:e.get(p),fullFormatted:e.get(m),digits:e.get(u)}));return e.user_pre_effect(()=>{let t=n(),i=e.get(u);t!==i&&r(i)}),e.user_effect(()=>{i?.(e.get(v))}),e.user_effect(()=>{o?.(e.get(h))}),{get digits(){return e.get(u)},get formatter(){return e.get(s)},get displayPlaceholder(){return e.get(d)},get displayValue(){return e.get(f)},get full(){return e.get(p)},get fullFormatted(){return e.get(m)},get isComplete(){return e.get(h)},get isEmpty(){return e.get(g)},get shouldShowWarn(){return e.get(_)}}}function b(){let e=null,n=()=>{e&&=(clearTimeout(e),null)};return t(n),{set:(t,r)=>{n(),e=setTimeout(t,r)},clear:n}}function x(){let t=e.state(!1),n=b();return{get showValidationHint(){return e.get(t)},clearValidationHint:(r=!0)=>{r&&e.set(t,!1),n.clear()},scheduleValidationHint:r=>{e.set(t,!1),n.set(()=>{e.set(t,!0)},r)}}}var S=500,C=300;function w(e){let{formatter:t,digits:n,inactive:i,onChange:a,scheduleValidationHint:o}=e,s=(e,n)=>{r().then(()=>{e&&_(e,t().getCaretPosition(n))})};return{handleBeforeInput:e=>{p(e)},handleInput:e=>{if(i?.())return;let n=m(e,{formatter:t()});n&&(a?.(n.newDigits),s(e.target,n.caretDigitIndex),o?.(S))},handleKeydown:e=>{if(i?.())return;let r=h(e,{digits:n(),formatter:t()});r&&(a?.(r.newDigits),s(e.target,r.caretDigitIndex),o?.(C))},handlePaste:e=>{if(i?.())return;let r=g(e,{digits:n(),formatter:t()});r&&(a?.(r.newDigits),s(e.target,r.caretDigitIndex),o?.(C))}}}function T({rootRef:n,dropdownRef:a,searchRef:o,selectorRef:s,locale:c,countryOption:u,inactive:d,onSelectCountry:f,onAfterSelect:p}){let m=e.state(``),h=e.state(!1),g=e.state(!1),_=e.state(e.proxy({})),v=e.state(0),y=e.derived(()=>i(c())),b=e.derived(()=>l(e.get(y),e.get(m))),x=e.derived(()=>!u?.()&&e.get(y).length>1),S=t=>{e.set(v,t,!0)},C=()=>{r().then(()=>o()?.focus({preventScroll:!0}))},w=()=>{e.get(h)&&e.set(g,!0)},T=()=>{e.set(g,!1),e.set(h,!0),S(0),C()},E=()=>{e.get(g)&&(e.set(h,!1),e.set(g,!1))},D=()=>{d?.()||!e.get(x)||(e.get(h)?w():T())},O=t=>{f(t),w(),e.set(m,``),S(0),p?.()},ee=t=>{e.set(m,t.target.value,!0),S(0)},k=e=>{let t=e.target,n=a(),r=s();t&&(n?.contains(t)||r?.contains(t)||w())},A=t=>{if(t?.type===`scroll`&&t.target&&a()?.contains(t.target))return;let r=n();if(!r)return;let i=r.getBoundingClientRect();e.set(_,{top:`${i.bottom+globalThis.scrollY+8}px`,left:`${i.left+globalThis.scrollX}px`,width:`${i.width}px`},!0)},j=()=>{r().then(()=>{let t=a()?.lastElementChild,n=t?.children[e.get(v)];if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),o=0;if(i.top<r.top)o=t.scrollTop-(r.top-i.top);else if(i.bottom>r.bottom)o=t.scrollTop+(i.bottom-r.bottom);else return;t.scrollTo({top:o,behavior:`smooth`})})},te=t=>{t.key===`ArrowDown`?(t.preventDefault(),S(Math.min(e.get(v)+1,e.get(b).length-1)),j()):t.key===`ArrowUp`?(t.preventDefault(),S(Math.max(e.get(v)-1,0)),j()):t.key===`Enter`&&e.get(b)[e.get(v)]?(t.preventDefault(),O(e.get(b)[e.get(v)].id)):t.key===`Escape`&&w()},M=()=>{globalThis.removeEventListener(`resize`,A),globalThis.removeEventListener(`scroll`,A,!0),globalThis.removeEventListener(`click`,k,!0)};return e.user_effect(()=>{!e.get(x)&&e.get(h)&&w()}),e.user_effect(()=>{if(!e.get(h)){M();return}A(),globalThis.addEventListener(`resize`,A),globalThis.addEventListener(`scroll`,A,!0),globalThis.addEventListener(`click`,k,!0)}),t(M),{get dropdownOpen(){return e.get(h)},get isClosing(){return e.get(g)},get search(){return e.get(m)},get focusedIndex(){return e.get(v)},get dropdownStyle(){return e.get(_)},get filteredCountries(){return e.get(b)},get hasDropdown(){return e.get(x)},openDropdown:T,closeDropdown:w,toggleDropdown:D,selectCountry:O,setFocusedIndex:S,handleSearchChange:ee,handleSearchKeydown:te,handleDropdownAnimationEnd:E}}function E(t=1800){let n=e.state(!1),r=e.state(!1),i=b();return{get copied(){return e.get(n)},get isCopying(){return e.get(r)},copy:async a=>{if(e.get(r))return!1;let o=a.trim();if(!o)return!1;e.set(r,!0);try{return await navigator.clipboard.writeText(o),e.set(n,!0),i.set(()=>{e.set(n,!1)},t),!0}catch(e){return console.warn(`Copy failed`,e),!1}finally{e.set(r,!1)}}}}var D=1800;function O({liveRef:t,fullFormatted:n,onCopy:r}){let i=b(),a=E(D),o=e.derived(()=>a.copied?`Copied`:`Copy ${n()}`),s=e.derived(()=>a.copied?`Copied`:`Copy phone number`),c=e=>{let n=t?.();n&&(n.textContent=e,i.set(()=>{let e=t?.();e&&(e.textContent=``)},D))};return{get copied(){return a.copied},get copyAriaLabel(){return e.get(o)},get copyButtonTitle(){return e.get(s)},onCopyClick:async()=>{let e=n().trim();await a.copy(e)&&(r?.(e),c(`Phone number copied to clipboard`))}}}function ee({theme:t}){let n=e.state(!1),r=e.derived(()=>(()=>{let r=t();return r===`auto`?e.get(n)?`theme-dark`:`theme-light`:`theme-${r}`})());return e.user_effect(()=>{let t=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`)??null;if(!t)return;e.set(n,t.matches,!0);let r=t=>{e.set(n,t.matches,!0)};return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)}),{get themeClass(){return e.get(r)}}}var k=e.from_svg(`<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 4.5L6 8L9.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>`),A=e.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z" fill="currentColor"></path></svg>`),j=e.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),te=e.from_html(`<button type="button"><!></button>`),M=e.from_svg(`<svg width="11" height="11" viewBox="0 0 14 14" fill="none" aria-hidden="true"><path 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" fill="currentColor"></path></svg>`),ne=e.from_html(`<button type="button" class="pi-btn pi-btn-clear"><!></button>`),re=e.from_html(`<li role="option"><span class="pi-flag" role="img"><!></span> <span class="pi-opt-name"> </span> <span class="pi-opt-code"> </span></li>`),ie=e.from_html(`<li class="pi-empty"> </li>`),ae=e.from_html(`<div role="dialog" aria-modal="false" aria-label="Select country"><div class="pi-search-wrap"><input type="search" class="pi-search" aria-label="Search countries"/></div> <ul class="pi-options" role="listbox" tabindex="-1"></ul></div>`),oe=e.from_html(`<div><div class="pi-selector"><button type="button"><span class="pi-flag" role="img"><!></span> <span class="pi-code"> </span> <!></button></div> <div class="pi-input-wrap"><input type="tel" inputmode="tel" autocomplete="tel-national" autocorrect="off" autocapitalize="off" spellcheck="false" class="pi-input"/> <div class="pi-actions" role="toolbar" aria-label="Phone input actions"><!> <!> <!></div></div></div> <!> <div class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>`,1);function N(t,i){e.push(i,!0);let a=e.prop(i,`value`,15,``),o=e.prop(i,`detect`,3,!0),s=e.prop(i,`size`,3,`normal`),c=e.prop(i,`theme`,3,`auto`),l=e.prop(i,`disabled`,3,!1),u=e.prop(i,`readonly`,3,!1),d=e.prop(i,`showCopy`,3,!0),f=e.prop(i,`showClear`,3,!1),p=e.prop(i,`withValidity`,3,!0),m=e.prop(i,`searchPlaceholder`,3,`Search country or code...`),h=e.prop(i,`noResultsText`,3,`No countries found`),g=e.prop(i,`clearButtonLabel`,3,`Clear phone number`),_=e.prop(i,`dropdownClass`,3,``),b=e.prop(i,`disableDefaultStyles`,3,!1),S=e.rest_props(i,`$$slots.$$events.$$legacy.value.id.name.country.detect.locale.size.theme.disabled.readonly.showCopy.showClear.withValidity.searchPlaceholder.noResultsText.clearButtonLabel.dropdownClass.disableDefaultStyles.onchange.oncountrychange.onvalidationchange.onfocus.onblur.oncopy.onclear.flag.copysvg.clearsvg.actionsbefore.class`.split(`.`)),C=e.state(null),E=e.state(null),D=e.state(null),N=e.state(null),P=e.state(null),F=e.state(null),I=v({country:()=>i.country,locale:()=>i.locale,detect:()=>o(),onCountryChange:(...e)=>i.oncountrychange?.(...e)}),L=y({country:()=>I.country,value:()=>a(),onChange:e=>a(e),onPhoneChange:(...e)=>i.onchange?.(...e),onValidationChange:(...e)=>i.onvalidationchange?.(...e)}),R=x(),z=e.derived(()=>l()||u()),B=e.derived(()=>R.showValidationHint&&L.shouldShowWarn),V=e.derived(()=>d()&&!L.isEmpty&&!l()),H=e.derived(()=>f()&&!L.isEmpty&&!e.get(z)),U=O({liveRef:()=>e.get(D),fullFormatted:()=>L.fullFormatted,onCopy:(...e)=>i.oncopy?.(...e)}),W=()=>r().then(()=>e.get(E)?.focus()),G=T({rootRef:()=>e.get(C),dropdownRef:()=>e.get(N),searchRef:()=>e.get(P),selectorRef:()=>e.get(F),locale:()=>I.locale,countryOption:()=>i.country,inactive:()=>e.get(z),onSelectCountry:I.setCountry,onAfterSelect:W}),K=e.state(`0`);n(()=>{e.set(K,Math.random().toString(36).slice(2,10),!0)});let se=e.derived(()=>`pi-options-${e.get(K)}`),ce=t=>`pi-option-${e.get(K)}-${t}`,le=e.derived(()=>G.dropdownOpen&&G.filteredCountries[G.focusedIndex]?ce(G.focusedIndex):void 0),q=w({formatter:()=>L.formatter,digits:()=>L.digits,inactive:()=>e.get(z),onChange:e=>a(e),scheduleValidationHint:R.scheduleValidationHint}),ue=e=>{R.clearValidationHint(!1),G.closeDropdown(),i.onfocus?.(e)},de=e=>i.onblur?.(e);function fe(){W()}function pe(){e.get(E)?.blur()}function me(){a(``),R.clearValidationHint(),i.onclear?.()}function he(e){I.setCountry(e)}function ge(){return L.full}function _e(){return L.fullFormatted}function ve(){return L.digits}function ye(){return L.isComplete}function be(){return L.isComplete}let xe=()=>{me(),W()},Se=ee({theme:()=>c()}),Ce=e.derived(()=>[`phone-input`,`size-${s()}`,Se.themeClass,l()&&`is-disabled`,u()&&`is-readonly`,b()&&`is-unstyled`,p()&&e.get(B)&&`is-incomplete`,p()&&L.isComplete&&`is-complete`,i.class].filter(Boolean).join(` `)),we=e.derived(()=>+e.get(V)+ +e.get(H)+ +!!i.actionsbefore);function Te(e){return document.body.appendChild(e),{destroy:()=>e.remove()}}var Ee={focus:fe,blur:pe,clear:me,selectCountry:he,getFullNumber:ge,getFullFormattedNumber:_e,getDigits:ve,isValid:ye,isComplete:be},De=oe(),J=e.first_child(De);e.attribute_effect(J,()=>({class:e.get(Ce),...S,role:`group`,"aria-label":`Phone input with country selector`,[e.STYLE]:{"--pi-actions-count":e.get(we)}}));var Y=e.child(J),X=e.child(Y);let Oe;var Z=e.child(X),ke=e.child(Z),Ae=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.flag,()=>I.country),e.append(t,n)},je=t=>{var n=e.text();e.template_effect(()=>e.set_text(n,I.country.flag)),e.append(t,n)};e.if(ke,e=>{i.flag?e(Ae):e(je,-1)}),e.reset(Z);var Q=e.sibling(Z,2),Me=e.child(Q,!0);e.reset(Q);var Ne=e.sibling(Q,2),Pe=t=>{var n=k();let r;e.template_effect(()=>r=e.set_class(n,0,`pi-chevron`,null,r,{"is-open":G.dropdownOpen})),e.append(t,n)};e.if(Ne,t=>{!e.get(z)&&G.hasDropdown&&t(Pe)}),e.reset(X),e.reset(Y),e.bind_this(Y,t=>e.set(F,t),()=>e.get(F));var Fe=e.sibling(Y,2),$=e.child(Fe);e.remove_input_defaults($),e.bind_this($,t=>e.set(E,t),()=>e.get(E));var Ie=e.sibling($,2),Le=e.child(Ie),Re=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.actionsbefore),e.append(t,n)};e.if(Le,e=>{i.actionsbefore&&e(Re)});var ze=e.sibling(Le,2),Be=t=>{var n=te();let r;var a=e.child(n),o=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.copysvg,()=>U.copied),e.append(t,n)},s=t=>{var n=A();e.append(t,n)},c=t=>{var n=j();e.append(t,n)};e.if(a,e=>{i.copysvg?e(o):U.copied?e(s,1):e(c,-1)}),e.reset(n),e.template_effect(()=>{r=e.set_class(n,1,`pi-btn pi-btn-copy`,null,r,{"is-copied":U.copied}),e.set_attribute(n,`aria-label`,U.copyAriaLabel),e.set_attribute(n,`title`,U.copyButtonTitle)}),e.delegated(`click`,n,function(...e){U.onCopyClick?.apply(this,e)}),e.append(t,n)};e.if(ze,t=>{e.get(V)&&t(Be)});var Ve=e.sibling(ze,2),He=t=>{var n=ne(),r=e.child(n),a=t=>{var n=e.comment(),r=e.first_child(n);e.snippet(r,()=>i.clearsvg),e.append(t,n)},o=t=>{var n=M();e.append(t,n)};e.if(r,e=>{i.clearsvg?e(a):e(o,-1)}),e.reset(n),e.template_effect(()=>{e.set_attribute(n,`aria-label`,g()),e.set_attribute(n,`title`,g())}),e.delegated(`click`,n,xe),e.append(t,n)};e.if(Ve,t=>{e.get(H)&&t(He)}),e.reset(Ie),e.reset(Fe),e.reset(J),e.bind_this(J,t=>e.set(C,t),()=>e.get(C));var Ue=e.sibling(J,2),We=t=>{var n=ae();let r,a;var o=e.child(n),s=e.child(o);e.remove_input_defaults(s),e.bind_this(s,t=>e.set(P,t),()=>e.get(P)),e.reset(o);var c=e.sibling(o,2);e.each(c,23,()=>G.filteredCountries,e=>e.id,(t,n,r)=>{var a=re();let o;var s=e.child(a),c=e.child(s),l=t=>{var r=e.comment(),a=e.first_child(r);e.snippet(a,()=>i.flag,()=>e.get(n)),e.append(t,r)},u=t=>{var r=e.text();e.template_effect(()=>e.set_text(r,e.get(n).flag)),e.append(t,r)};e.if(c,e=>{i.flag?e(l):e(u,-1)}),e.reset(s);var d=e.sibling(s,2),f=e.child(d,!0);e.reset(d);var p=e.sibling(d,2),m=e.child(p,!0);e.reset(p),e.reset(a),e.template_effect(t=>{e.set_attribute(a,`id`,t),o=e.set_class(a,1,`pi-option`,null,o,{"is-focused":e.get(r)===G.focusedIndex,"is-selected":e.get(n).id===I.country.id}),e.set_attribute(a,`aria-selected`,e.get(n).id===I.country.id),e.set_attribute(a,`title`,e.get(n).name),e.set_attribute(s,`aria-label`,`${e.get(n).name??``} flag`),e.set_text(f,e.get(n).name),e.set_text(m,e.get(n).code)},[()=>ce(e.get(r))]),e.delegated(`click`,a,()=>G.selectCountry(e.get(n).id)),e.event(`mouseenter`,a,()=>G.setFocusedIndex(e.get(r))),e.append(t,a)},t=>{var n=ie(),r=e.child(n,!0);e.reset(n),e.template_effect(()=>e.set_text(r,h())),e.append(t,n)}),e.reset(c),e.reset(n),e.action(n,e=>Te?.(e)),e.bind_this(n,t=>e.set(N,t),()=>e.get(N)),e.template_effect(()=>{r=e.set_class(n,1,`phone-dropdown ${_()??``} ${Se.themeClass??``}`,null,r,{"is-closing":G.isClosing}),a=e.set_style(n,``,a,{position:`absolute`,top:G.dropdownStyle.top,left:G.dropdownStyle.left,width:G.dropdownStyle.width}),e.set_attribute(s,`placeholder`,m()),e.set_attribute(s,`aria-controls`,e.get(se)),e.set_attribute(s,`aria-activedescendant`,e.get(le)),e.set_value(s,G.search),e.set_attribute(c,`id`,e.get(se))}),e.event(`animationend`,n,function(...e){G.handleDropdownAnimationEnd?.apply(this,e)}),e.delegated(`keydown`,s,function(...e){G.handleSearchKeydown?.apply(this,e)}),e.delegated(`input`,s,function(...e){G.handleSearchChange?.apply(this,e)}),e.append(t,n)};e.if(Ue,e=>{G.dropdownOpen&&e(We)});var Ge=e.sibling(Ue,2);return e.bind_this(Ge,t=>e.set(D,t),()=>e.get(D)),e.template_effect(()=>{Oe=e.set_class(X,1,`pi-selector-btn`,null,Oe,{"no-dropdown":!G.hasDropdown||u()}),X.disabled=l(),e.set_attribute(X,`tabindex`,e.get(z)||!G.hasDropdown?-1:void 0),e.set_attribute(X,`aria-label`,`Selected country: ${I.country.name??``}`),e.set_attribute(X,`aria-expanded`,G.dropdownOpen),e.set_attribute(X,`aria-haspopup`,G.hasDropdown?`listbox`:void 0),e.set_attribute(Z,`aria-label`,`${I.country.name??``} flag`),e.set_text(Me,I.country.code),e.set_attribute($,`id`,i.id),e.set_attribute($,`name`,i.name),e.set_attribute($,`placeholder`,L.displayPlaceholder),e.set_value($,L.displayValue),$.disabled=l(),$.readOnly=u(),e.set_attribute($,`aria-invalid`,e.get(B))}),e.delegated(`click`,X,function(...e){G.toggleDropdown?.apply(this,e)}),e.delegated(`beforeinput`,$,function(...e){q.handleBeforeInput?.apply(this,e)}),e.delegated(`input`,$,function(...e){q.handleInput?.apply(this,e)}),e.delegated(`keydown`,$,function(...e){q.handleKeydown?.apply(this,e)}),e.event(`paste`,$,function(...e){q.handlePaste?.apply(this,e)}),e.event(`focus`,$,ue),e.event(`blur`,$,de),e.append(t,De),e.pop(Ee)}e.delegate([`click`,`beforeinput`,`input`,`keydown`]);function P(t){let n=e.state(null),r=v({country:t.country,locale:t.locale,detect:t.detect,onCountryChange:t.onCountryChange}),i=y({country:()=>r.country,value:t.value,onChange:t.onChange,onPhoneChange:t.onPhoneChange}),{handleBeforeInput:a,handleInput:o,handleKeydown:s,handlePaste:c}=w({formatter:()=>i.formatter,digits:()=>i.digits,onChange:t.onChange});return e.user_effect(()=>{let t=e.get(n);if(t)return t.setAttribute(`type`,`tel`),t.setAttribute(`inputmode`,`tel`),t.addEventListener(`beforeinput`,a),t.addEventListener(`input`,o),t.addEventListener(`keydown`,s),t.addEventListener(`paste`,c),()=>{t.removeEventListener(`beforeinput`,a),t.removeEventListener(`input`,o),t.removeEventListener(`keydown`,s),t.removeEventListener(`paste`,c)}}),e.user_effect(()=>{let t=e.get(n);t&&(t.value=i.displayValue,t.setAttribute(`placeholder`,i.displayPlaceholder))}),{get inputRef(){return e.get(n)},set inputRef(t){e.set(n,t,!0)},get digits(){return i.digits},get formatter(){return i.formatter},get full(){return i.full},get fullFormatted(){return i.fullFormatted},get isComplete(){return i.isComplete},get isEmpty(){return i.isEmpty},get shouldShowWarn(){return i.shouldShowWarn},get country(){return r.country},get locale(){return r.locale},setCountry:r.setCountry,clear:()=>{t.onChange(``)}}}function F(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function I(t){return n=>{if(n.tagName!==`INPUT`){console.warn(`[phoneMaskAttachment] Attachment can only be used on input elements`);return}let r=F(t),i=e.effect_root(()=>{let t=e.state(e.proxy(n.value||``)),i=P({country:()=>r.country,locale:()=>r.locale,detect:()=>r.detect,value:()=>e.get(t),onChange:n=>{e.set(t,n,!0)},onPhoneChange:r.onChange,onCountryChange:r.onCountryChange});i.inputRef=n,n.__phoneMaskState={get country(){return i.country},get formatter(){return i.formatter},get digits(){return i.digits},get locale(){return i.locale},options:r,setCountry:e=>i.setCountry(e)}});return()=>{i(),delete n.__phoneMaskState}}}function L(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function R(e,t,n){if(t.digits=n,e.value=t.formatter.formatDisplay(t.digits),t.options.onChange){let n=e.value?`${t.country.code} ${e.value}`:``,r=t.digits?`${t.country.code}${t.digits}`:``;t.options.onChange({full:r,fullFormatted:n,digits:t.digits})}}function z(e,t){let n=t.formatter.getMaxDigits(),r=c(e.value,n),i=t.formatter.formatDisplay(r);(r!==t.digits||e.value!==i)&&R(e,t,r)}function B(e){let t=e.country.id,n=f(e.options.country);n&&n!==t&&e.setCountry(n)}function V(e,t,n){return r=>{let i=n(r,t);i&&(R(e,t,i.newDigits),Promise.resolve().then(()=>{_(e,t.formatter.getCaretPosition(i.caretDigitIndex))}))}}async function H(e){let t=f(e.country);if(t)return t;if(e.detect){let e=f(await o());if(e)return e;let t=f(s());if(t)return t}return`US`}function U(e,t){if(e.tagName!==`INPUT`)return console.warn(`[phoneMaskAction] Action can only be used on input elements`),{update(){},destroy(){}};e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`),e.setAttribute(`placeholder`,``);let n=L(t),r=n.locale||d(),i=u(f(n.country,`US`),r),o={country:i,formatter:a(i),digits:``,locale:r,options:n,setCountry(t){let n=f(t);if(!n)return!1;let r=u(n,this.locale);return this.country=r,this.options.onCountryChange?.(r),this.formatter=a(r),e.placeholder=this.formatter.getPlaceholder(),z(e,this),!0}};e.__phoneMaskState=o;let s=V(e,o,m),c=V(e,o,h),l=V(e,o,g);return e.addEventListener(`beforeinput`,p),e.addEventListener(`input`,s),e.addEventListener(`keydown`,c),e.addEventListener(`paste`,l),H(n).then(t=>{e.__phoneMaskState===o&&o.setCountry(t)}),{update(t){o.options=L(t),B(o),z(e,o)},destroy(){e.removeEventListener(`beforeinput`,p),e.removeEventListener(`input`,s),e.removeEventListener(`keydown`,c),e.removeEventListener(`paste`,l),delete e.__phoneMaskState}}}var W=N;export{W as PhoneInput,U as phoneMaskAction,I as phoneMaskAttachment,P as usePhoneMask};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@desource/phone-mask-svelte",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "π Svelte 5 component, composable, action, and attachment for international phone number masking. Powered by @desource/phone-mask with Google libphonenumber sync.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"svelte": "^5.0.0"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@desource/phone-mask": "1.3.
|
|
63
|
+
"@desource/phone-mask": "1.3.1"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
67
67
|
"@testing-library/svelte": "^5.3.1",
|
|
68
|
-
"svelte": "^5.55.
|
|
69
|
-
"svelte-check": "^4.4.
|
|
68
|
+
"svelte": "^5.55.4",
|
|
69
|
+
"svelte-check": "^4.4.6"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"clean": "rimraf dist tsconfig.tsbuildinfo test-results coverage",
|