digitojs 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,11 +13,11 @@
13
13
  </p>
14
14
 
15
15
  <p align="center">
16
- <a href="https://digitojs.vercel.app"><img src="https://img.shields.io/badge/digitojs.vercel.app-0A0A0A?style=flat-square&logo=vercel&logoColor=white" alt="Live demo" /></a>
17
- <a href="https://www.npmjs.com/package/digitojs"><img src="https://img.shields.io/npm/v/digitojs?style=flat-square&color=0A0A0A" alt="npm" /></a>
18
- <a href="https://bundlephobia.com/package/digitojs"><img src="https://img.shields.io/bundlephobia/minzip/digitojs?style=flat-square&color=0A0A0A&label=gzip" /></a>
19
- <img src="https://img.shields.io/badge/zero_dependencies-0A0A0A?style=flat-square" />
20
- <img src="https://img.shields.io/badge/TypeScript-0A0A0A?style=flat-square&logo=typescript&logoColor=white" />
16
+ <a href="https://digitojs.vercel.app"><img src="https://img.shields.io/badge/digitojs.vercel.app-live-20C55C" alt="Live demo" /></a>&nbsp;
17
+ <a href="https://www.npmjs.com/package/digitojs"><img src="https://img.shields.io/npm/v/digitojs?color=20C55C&label=digitojs" alt="npm version" /></a>&nbsp;
18
+ <a href="https://bundlephobia.com/package/digitojs"><img src="https://img.shields.io/bundlephobia/minzip/digitojs?color=20C55C&label=gzip" alt="gzip size" /></a>&nbsp;
19
+ <img src="https://img.shields.io/badge/Dependencies-0-20C55C" alt="Zero dependencies" />&nbsp;
20
+ <a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-strict-20C55C" alt="TypeScript" /></a>
21
21
  </p>
22
22
 
23
23
  ---
@@ -1,4 +1,4 @@
1
- /*! Digito v1.2.2 | Olawale Balo — Product Designer + Design Engineer */
1
+ /*! Digito v1.2.4 | Olawale Balo — Product Designer + Design Engineer */
2
2
  "use strict";(()=>{var lt=Object.defineProperty,dt=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var it=Object.getOwnPropertySymbols;var ut=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var st=(i,d,t)=>d in i?lt(i,d,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[d]=t,O=(i,d)=>{for(var t in d||(d={}))ut.call(d,t)&&st(i,t,d[t]);if(it)for(var t of it(d))ht.call(d,t)&&st(i,t,d[t]);return i},j=(i,d)=>dt(i,ct(d));function I(i,d,t){if(!i||i.length!==1)return"";if(t!==void 0)return t.global&&(t.lastIndex=0),t.test(i)?i:"";switch(d){case"numeric":return/^[0-9]$/.test(i)?i:"";case"alphabet":return/^[a-zA-Z]$/.test(i)?i:"";case"alphanumeric":return/^[a-zA-Z0-9]$/.test(i)?i:"";case"any":return i;default:return""}}function M(i,d,t){return Array.from(i).filter(e=>I(e,d,t)!=="").join("")}function q(i){let{totalSeconds:d,onTick:t,onExpire:e}=i,n=d,r=null;function p(){r!==null&&(clearInterval(r),r=null)}function f(){p(),n=d}function C(){if(p(),d<=0){e==null||e();return}r=setInterval(()=>{n-=1,t==null||t(n),n<=0&&(p(),e==null||e())},1e3)}function a(){f(),C()}return{start:C,stop:p,reset:f,restart:a}}function R(i){let d=Math.floor(i/60),t=i%60;return d>0?`${d}:${String(t).padStart(2,"0")}`:`0:${String(t).padStart(2,"0")}`}function X(){var i;try{(i=navigator==null?void 0:navigator.vibrate)==null||i.call(navigator,10)}catch(d){}}function nt(){try{let i=new AudioContext,d=i.createOscillator(),t=i.createGain();d.connect(t),t.connect(i.destination),d.frequency.value=880,t.gain.setValueAtTime(.08,i.currentTime),t.gain.exponentialRampToValueAtTime(.001,i.currentTime+.08),d.start(),d.stop(i.currentTime+.08),d.onended=()=>{i.close().catch(()=>{})}}catch(i){}}function Z(i){return i.every(d=>d.length===1)}function H(i,d,t){return Math.max(d,Math.min(t,i))}function ot(i){return i.join("")}function G(i={}){var K,W,Y,J,Q,U;let d=(K=i.length)!=null?K:6,t=isNaN(d)?6:Math.max(1,Math.floor(d)),{type:e="numeric",pattern:n,onComplete:r,onInvalidChar:p,haptic:f=!0,sound:C=!1,pasteTransformer:a}=i,l=(W=i.disabled)!=null?W:!1,u=(Y=i.readOnly)!=null?Y:!1,o={slotValues:Array(t).fill(""),activeSlot:0,hasError:!1,isComplete:!1,timerSeconds:(J=i.timer)!=null?J:0,isDisabled:(Q=i.disabled)!=null?Q:!1,isReadOnly:(U=i.readOnly)!=null?U:!1},w=new Set;function h(s){if(o=O(O({},o),s),w.size>0){let v=j(O({},o),{slotValues:[...o.slotValues]});w.forEach(E=>E(v))}return o}let b=null;function c(s){if(!Z(s)||!r)return;f&&X(),C&&nt();let v=ot(s);b!==null&&clearTimeout(b),b=setTimeout(()=>{b=null,r(v)},10)}function N(){b!==null&&(clearTimeout(b),b=null)}function V(s,v){if(l||u||s<0||s>=t)return o;let E=I(v,e,n);if(!E)return v.length===1&&(p==null||p(v,s)),o.activeSlot!==s?h({activeSlot:s}):o;let A=[...o.slotValues];A[s]=E;let k=s<t-1?s+1:t-1,L=h({slotValues:A,activeSlot:k,hasError:!1,isComplete:Z(A)});return c(A),L}function B(s){if(l||u||s<0||s>=t)return o;let v=[...o.slotValues];if(v[s])return v[s]="",h({slotValues:v,activeSlot:s,isComplete:!1});let E=H(s-1,0,t-1);return v[E]="",h({slotValues:v,activeSlot:E,isComplete:!1})}function z(s){return h({activeSlot:H(s-1,0,t-1)})}function m(s){return h({activeSlot:H(s+1,0,t-1)})}function g(s,v){if(l||u)return o;let E;try{E=a?a(v):v}catch(_){console.warn("[digito] pasteTransformer threw \u2014 using raw paste text.",_),E=v}if(p&&E){let _=s;for(let et of Array.from(E))I(et,e,n)?_=(_+1)%t:p(et,_)}let A=M(E,e,n);if(!A)return o;let k=[...o.slotValues],L=s;for(let _=0;_<A.length&&_<t;_++)k[L]=A[_],L=(L+1)%t;let tt=Math.min(A.length,t),rt=tt>=t?t-1:(s+tt)%t,at=h({slotValues:k,activeSlot:rt,hasError:!1,isComplete:Z(k)});return c(k),at}function y(s){if(l||u||s<0||s>=t||!o.slotValues[s])return o;let v=[...o.slotValues];return v[s]="",h({slotValues:v,activeSlot:s,isComplete:!1})}function S(s){return s&&f&&X(),h({hasError:s})}function F(){var s;return b!==null&&(clearTimeout(b),b=null),h({slotValues:Array(t).fill(""),activeSlot:0,hasError:!1,isComplete:!1,timerSeconds:(s=i.timer)!=null?s:0})}function D(s){return h({activeSlot:H(s,0,t-1)})}function x(s){l=s,h({isDisabled:s})}function T(s){u=s,h({isReadOnly:s})}function P(s){return w.add(s),()=>{w.delete(s)}}return{get state(){return o},inputChar:V,deleteChar:B,clearSlot:y,moveFocusLeft:z,moveFocusRight:m,pasteString:g,setError:S,resetState:F,moveFocusTo:D,cancelPendingComplete:N,setDisabled:x,setReadOnly:T,getCode:()=>ot(o.slotValues),getSnapshot:()=>j(O({},o),{slotValues:[...o.slotValues]}),subscribe:P,getState:()=>j(O({},o),{slotValues:[...o.slotValues]})}}var pt=`
3
3
  :host {
4
4
  display: inline-block;
@@ -1,4 +1,4 @@
1
- /*! Digito v1.2.2 | Olawale Balo — Product Designer + Design Engineer */
1
+ /*! Digito v1.2.4 | Olawale Balo — Product Designer + Design Engineer */
2
2
  "use strict";var Digito=(()=>{var ae=Object.defineProperty,nt=Object.defineProperties,ot=Object.getOwnPropertyDescriptor,rt=Object.getOwnPropertyDescriptors,at=Object.getOwnPropertyNames,qe=Object.getOwnPropertySymbols;var We=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var $e=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$=(e,t)=>{for(var n in t||(t={}))We.call(t,n)&&$e(e,n,t[n]);if(qe)for(var n of qe(t))st.call(t,n)&&$e(e,n,t[n]);return e},se=(e,t)=>nt(e,rt(t));var lt=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},ct=(e,t,n,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of at(t))!We.call(e,p)&&p!==n&&ae(e,p,{get:()=>t[p],enumerable:!(u=ot(t,p))||u.enumerable});return e};var dt=e=>ct(ae({},"__esModule",{value:!0}),e);var vt={};lt(vt,{createDigito:()=>te,createTimer:()=>W,filterChar:()=>z,filterString:()=>w,formatCountdown:()=>M,initDigito:()=>me,triggerHapticFeedback:()=>G,triggerSoundFeedback:()=>ee});function z(e,t,n){if(!e||e.length!==1)return"";if(n!==void 0)return n.global&&(n.lastIndex=0),n.test(e)?e:"";switch(t){case"numeric":return/^[0-9]$/.test(e)?e:"";case"alphabet":return/^[a-zA-Z]$/.test(e)?e:"";case"alphanumeric":return/^[a-zA-Z0-9]$/.test(e)?e:"";case"any":return e;default:return""}}function w(e,t,n){return Array.from(e).filter(u=>z(u,t,n)!=="").join("")}function W(e){let{totalSeconds:t,onTick:n,onExpire:u}=e,p=t,A=null;function h(){A!==null&&(clearInterval(A),A=null)}function N(){h(),p=t}function R(){if(h(),t<=0){u==null||u();return}A=setInterval(()=>{p-=1,n==null||n(p),p<=0&&(h(),u==null||u())},1e3)}function V(){N(),R()}return{start:R,stop:h,reset:N,restart:V}}function M(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}:${String(n).padStart(2,"0")}`:`0:${String(n).padStart(2,"0")}`}function G(){var e;try{(e=navigator==null?void 0:navigator.vibrate)==null||e.call(navigator,10)}catch(t){}}function ee(){try{let e=new AudioContext,t=e.createOscillator(),n=e.createGain();t.connect(n),n.connect(e.destination),t.frequency.value=880,n.gain.setValueAtTime(.08,e.currentTime),n.gain.exponentialRampToValueAtTime(.001,e.currentTime+.08),t.start(),t.stop(e.currentTime+.08),t.onended=()=>{e.close().catch(()=>{})}}catch(e){}}function ge(e){return e.every(t=>t.length===1)}function le(e,t,n){return Math.max(t,Math.min(n,e))}function Ge(e){return e.join("")}function te(e={}){var P,o,J,S,F,k;let t=(P=e.length)!=null?P:6,n=isNaN(t)?6:Math.max(1,Math.floor(t)),{type:u="numeric",pattern:p,onComplete:A,onInvalidChar:h,haptic:N=!0,sound:R=!1,pasteTransformer:V}=e,L=(o=e.disabled)!=null?o:!1,T=(J=e.readOnly)!=null?J:!1,l={slotValues:Array(n).fill(""),activeSlot:0,hasError:!1,isComplete:!1,timerSeconds:(S=e.timer)!=null?S:0,isDisabled:(F=e.disabled)!=null?F:!1,isReadOnly:(k=e.readOnly)!=null?k:!1},H=new Set;function y(r){if(l=$($({},l),r),H.size>0){let c=se($({},l),{slotValues:[...l.slotValues]});H.forEach(f=>f(c))}return l}let E=null;function j(r){if(!ge(r)||!A)return;N&&G(),R&&ee();let c=Ge(r);E!==null&&clearTimeout(E),E=setTimeout(()=>{E=null,A(c)},10)}function K(){E!==null&&(clearTimeout(E),E=null)}function ce(r,c){if(L||T||r<0||r>=n)return l;let f=z(c,u,p);if(!f)return c.length===1&&(h==null||h(c,r)),l.activeSlot!==r?y({activeSlot:r}):l;let C=[...l.slotValues];C[r]=f;let m=r<n-1?r+1:n-1,_=y({slotValues:C,activeSlot:m,hasError:!1,isComplete:ge(C)});return j(C),_}function ie(r){if(L||T||r<0||r>=n)return l;let c=[...l.slotValues];if(c[r])return c[r]="",y({slotValues:c,activeSlot:r,isComplete:!1});let f=le(r-1,0,n-1);return c[f]="",y({slotValues:c,activeSlot:f,isComplete:!1})}function ne(r){return y({activeSlot:le(r-1,0,n-1)})}function X(r){return y({activeSlot:le(r+1,0,n-1)})}function de(r,c){if(L||T)return l;let f;try{f=V?V(c):c}catch(D){console.warn("[digito] pasteTransformer threw \u2014 using raw paste text.",D),f=c}if(h&&f){let D=r;for(let Y of Array.from(f))z(Y,u,p)?D=(D+1)%n:h(Y,D)}let C=w(f,u,p);if(!C)return l;let m=[...l.slotValues],_=r;for(let D=0;D<C.length&&D<n;D++)m[_]=C[D],_=(_+1)%n;let U=Math.min(C.length,n),oe=U>=n?n-1:(r+U)%n,re=y({slotValues:m,activeSlot:oe,hasError:!1,isComplete:ge(m)});return j(m),re}function ue(r){if(L||T||r<0||r>=n||!l.slotValues[r])return l;let c=[...l.slotValues];return c[r]="",y({slotValues:c,activeSlot:r,isComplete:!1})}function Z(r){return r&&N&&G(),y({hasError:r})}function fe(){var r;return E!==null&&(clearTimeout(E),E=null),y({slotValues:Array(n).fill(""),activeSlot:0,hasError:!1,isComplete:!1,timerSeconds:(r=e.timer)!=null?r:0})}function s(r){return y({activeSlot:le(r,0,n-1)})}function B(r){L=r,y({isDisabled:r})}function I(r){T=r,y({isReadOnly:r})}function O(r){return H.add(r),()=>{H.delete(r)}}return{get state(){return l},inputChar:ce,deleteChar:ie,clearSlot:ue,moveFocusLeft:ne,moveFocusRight:X,pasteString:de,setError:Z,resetState:fe,moveFocusTo:s,cancelPendingComplete:K,setDisabled:B,setReadOnly:I,getCode:()=>Ge(l.slotValues),getSnapshot:()=>se($({},l),{slotValues:[...l.slotValues]}),subscribe:O,getState:()=>se($({},l),{slotValues:[...l.slotValues]})}}var Ke="digito-styles";function ut(){if(typeof document=="undefined"||document.getElementById(Ke))return;let e=document.createElement("style");e.id=Ke,e.textContent=[".digito-element{position:relative;display:inline-block;line-height:1}",".digito-hidden-input{position:absolute;inset:0;width:100%;height:100%;opacity:0;border:none;outline:none;background:transparent;color:transparent;caret-color:transparent;z-index:1;cursor:text;font-size:1px}",".digito-content{display:inline-flex;gap:var(--digito-gap,12px);align-items:center;padding:24px 0 0px;position:relative}",".digito-slot{position:relative;width:var(--digito-size,56px);height:var(--digito-size,56px);border:1px solid var(--digito-border-color,#E5E5E5);border-radius:var(--digito-radius,10px);font-size:var(--digito-font-size,24px);font-weight:600;display:flex;align-items:center;justify-content:center;background:var(--digito-bg,#FAFAFA);color:var(--digito-color,#0A0A0A);transition:border-color 150ms ease,box-shadow 150ms ease,background 150ms ease;user-select:none;-webkit-user-select:none;cursor:text;font-family:inherit}",".digito-slot.is-active{border-color:var(--digito-active-color,#3D3D3D);box-shadow:0 0 0 3px color-mix(in srgb,var(--digito-active-color,#3D3D3D) 10%,transparent);background:var(--digito-bg-filled,#FFFFFF)}",".digito-slot.is-filled{background:var(--digito-bg-filled,#FFFFFF)}",".digito-slot.is-error{border-color:var(--digito-error-color,#FB2C36);box-shadow:0 0 0 3px color-mix(in srgb,var(--digito-error-color,#FB2C36) 12%,transparent)}",".digito-slot.is-success{border-color:var(--digito-success-color,#00C950);box-shadow:0 0 0 3px color-mix(in srgb,var(--digito-success-color,#00C950) 12%,transparent)}",".digito-slot.is-disabled{opacity:0.45;cursor:not-allowed;pointer-events:none}",".digito-caret{position:absolute;width:2px;height:52%;background:var(--digito-caret-color,#3D3D3D);border-radius:1px;animation:digito-blink 1s step-start infinite;pointer-events:none}","@keyframes digito-blink{0%,100%{opacity:1}50%{opacity:0}}",".digito-separator{display:flex;align-items:center;justify-content:center;color:var(--digito-separator-color,#A1A1A1);font-size:var(--digito-separator-size,18px);font-weight:400;user-select:none;flex-shrink:0;}",".digito-slot:not(.is-filled){font-size:var(--digito-placeholder-size,16px);color:var(--digito-placeholder-color,#D3D3D3)}",".digito-slot.is-masked.is-filled{font-size:var(--digito-masked-size,16px)}",".digito-timer{display:flex;align-items:center;gap:8px;font-size:14px;padding:20px 0 0}",".digito-timer-label{color:var(--digito-timer-color,#5C5C5C);font-size:14px}",".digito-timer-badge{display:inline-flex;align-items:center;background:color-mix(in srgb,var(--digito-error-color,#FB2C36) 10%,transparent);color:var(--digito-error-color,#FB2C36);font-weight:500;font-size:14px;padding:2px 10px;border-radius:99px;height: 24px}",".digito-resend{display:none;align-items:center;gap:8px;font-size:14px;color:var(--digito-timer-color,#5C5C5C);padding:20px 0 0}",".digito-resend.is-visible{display:flex}",".digito-resend-btn{display:inline-flex;align-items:center;background:#E8E8E8;border:none;padding:2px 10px;border-radius:99px;color:#0A0A0A;font-weight:500;font-size:14px;transition:background 150ms ease;cursor:pointer;height: 24px}",".digito-resend-btn:hover{background:#E5E5E5}",".digito-resend-btn:disabled{color:#A1A1A1;cursor:not-allowed;background:#F5F5F5}"].join(""),document.head.appendChild(e)}function me(e=".digito-wrapper",t={}){return ut(),(typeof e=="string"?Array.from(document.querySelectorAll(e)):[e]).map(u=>ft(u,t))}function ft(e,t){var ve,be,he,ye,Se,Ce,xe,Ee,De,Ae,Te,Fe,ke,Re,Le,Oe,Ve,we,Me,_e,Ne,He,Ie,ze;e.querySelector(".digito-element")&&console.warn("[digito] initDigito() called on an already-initialised wrapper \u2014 call instance.destroy() first to avoid leaks.");let n=(be=t.length)!=null?be:parseInt((ve=e.dataset.length)!=null?ve:"6",10),u=(ye=(he=t.type)!=null?he:e.dataset.type)!=null?ye:"numeric",p=(Ce=t.timer)!=null?Ce:parseInt((Se=e.dataset.timer)!=null?Se:"0",10),A=(Ee=t.resendAfter)!=null?Ee:parseInt((xe=e.dataset.resend)!=null?xe:"30",10),h=t.onResend,N=t.onComplete,R=t.onTick,V=t.onExpire,L=t.pattern,T=(De=t.disabled)!=null?De:!1,l=(Ae=t.readOnly)!=null?Ae:!1,H=(Te=t.defaultValue)!=null?Te:"",y=t.autoFocus!==!1,E=t.name,j=t.onFocus,K=t.onBlur,ce=(Fe=t.placeholder)!=null?Fe:"",ie=(ke=t.selectOnFocus)!=null?ke:!1,ne=(Re=t.blurOnComplete)!=null?Re:!1,X=(Le=t.separatorAfter)!=null?Le:e.dataset.separatorAfter!==void 0?e.dataset.separatorAfter.split(",").map(i=>parseInt(i.trim(),10)).filter(i=>!isNaN(i)&&i>0):[],de=Array.isArray(X)?X:[X],ue=(Ve=(Oe=t.separator)!=null?Oe:e.dataset.separator)!=null?Ve:"\u2014",Z=(we=t.masked)!=null?we:e.dataset.masked==="true",fe=(_e=(Me=t.maskChar)!=null?Me:e.dataset.maskChar)!=null?_e:"\u25CF",s=te({length:n,type:u,timer:p,resendAfter:A,onComplete:N,onTick:R,onExpire:V,pattern:L,pasteTransformer:t.pasteTransformer,onInvalidChar:t.onInvalidChar,sound:(Ne=t.sound)!=null?Ne:!1,haptic:(He=t.haptic)!=null?He:!0,disabled:T,readOnly:l});for(;e.firstChild;)e.removeChild(e.firstChild);let B=document.createElement("div");B.className="digito-element";let I=document.createElement("div");I.className="digito-content";let O=[],P=[];for(let i=0;i<n;i++){let a=document.createElement("div");a.className="digito-slot",a.setAttribute("aria-hidden","true"),a.setAttribute("data-slot",String(i));let g=document.createElement("div");if(g.className="digito-caret",g.style.display="none",a.appendChild(g),P.push(g),O.push(a),I.appendChild(a),de.some(d=>d>0&&i===d-1)){let d=document.createElement("div");d.className="digito-separator",d.textContent=ue,d.setAttribute("aria-hidden","true"),I.appendChild(d)}}let o=document.createElement("input");if(o.type=Z?"password":"text",o.inputMode=u==="numeric"?"numeric":"text",o.autocomplete="one-time-code",o.maxLength=n,o.className="digito-hidden-input",E&&(o.name=E),o.setAttribute("aria-label",`Enter your ${n}-${u==="numeric"?"digit":"character"} code`),o.setAttribute("spellcheck","false"),o.setAttribute("autocorrect","off"),o.setAttribute("autocapitalize","off"),B.appendChild(I),B.appendChild(o),e.appendChild(B),l&&o.setAttribute("aria-readonly","true"),H){let i=w(H.slice(0,n),u,L);if(i){for(let a=0;a<i.length;a++)s.inputChar(a,i[a]);s.cancelPendingComplete(),o.value=i}}let J=()=>{};requestAnimationFrame(()=>{let i=I.getBoundingClientRect().width||0;J=pt(o,i)});let S=null,F=null,k=null,r=null,c=null,f=null;if((Ie=e.__digitoFooterEl)==null||Ie.remove(),(ze=e.__digitoResendRowEl)==null||ze.remove(),e.__digitoFooterEl=null,e.__digitoResendRowEl=null,p>0){let i=!R;if(i){c=document.createElement("div"),c.className="digito-timer";let a=document.createElement("span");a.className="digito-timer-label",a.textContent="Code expires in",S=document.createElement("span"),S.className="digito-timer-badge",S.textContent=M(p),c.appendChild(a),c.appendChild(S),e.insertAdjacentElement("afterend",c),f=document.createElement("div"),f.className="digito-resend";let g=document.createElement("span");g.textContent="Didn\u2019t receive the code?",F=document.createElement("button"),F.className="digito-resend-btn",F.textContent="Resend",F.type="button",f.appendChild(g),f.appendChild(F),c.insertAdjacentElement("afterend",f),e.__digitoFooterEl=c,e.__digitoResendRowEl=f}k=W({totalSeconds:p,onTick:a=>{S&&(S.textContent=M(a)),R==null||R(a)},onExpire:()=>{c&&(c.style.display="none"),f&&f.classList.add("is-visible"),V==null||V()}}),k.start(),i&&F&&F.addEventListener("click",()=>{!F||!S||!c||!f||(f.classList.remove("is-visible"),c.style.display="flex",S.textContent=M(A),r==null||r.stop(),r=W({totalSeconds:A,onTick:a=>{S&&(S.textContent=M(a))},onExpire:()=>{c&&(c.style.display="none"),f&&f.classList.add("is-visible")}}),r.start(),h==null||h())})}let C=null;typeof navigator!="undefined"&&"credentials"in navigator&&(C=new AbortController,navigator.credentials.get({otp:{transport:["sms"]},signal:C.signal}).then(i=>{if(!(i!=null&&i.code))return;let a=w(i.code,u,L).slice(0,n);if(!a)return;s.resetState();for(let b=0;b<a.length;b++)a[b]&&s.inputChar(b,a[b]);let g=a.length,d=Math.min(g,n-1);o.value=a,o.setSelectionRange(d,d),s.moveFocusTo(d),m()}).catch(()=>{}));function m(){let{slotValues:i,activeSlot:a,hasError:g}=s.state,d=document.activeElement===o;O.forEach((x,v)=>{var Pe;let q=(Pe=i[v])!=null?Pe:"",je=v===a&&d,Be=q.length===1,Q=x.childNodes[1];(!Q||Q.nodeType!==Node.TEXT_NODE)&&(Q=document.createTextNode(""),x.appendChild(Q)),Q.nodeValue=Z&&q?fe:q||ce,x.classList.toggle("is-active",je),x.classList.toggle("is-filled",Be),x.classList.toggle("is-masked",Z),x.classList.toggle("is-error",g),g&&x.classList.remove("is-success"),P[v].style.display=je&&!Be?"block":"none"});let b=i.join("");o.value!==b&&(o.value=b),e.toggleAttribute("data-complete",s.state.isComplete),e.toggleAttribute("data-invalid",s.state.hasError),e.toggleAttribute("data-disabled",T),e.toggleAttribute("data-readonly",l)}function _(i){var g;let a=(g=o.selectionStart)!=null?g:0;if(i.key==="Backspace"){if(i.preventDefault(),l)return;s.deleteChar(a),m(),o.setSelectionRange(s.state.activeSlot,s.state.activeSlot)}else if(i.key==="Delete"){if(i.preventDefault(),l)return;s.clearSlot(a),m(),o.setSelectionRange(a,a)}else if(i.key==="Tab"){if(i.shiftKey){if(a===0)return;i.preventDefault(),s.moveFocusLeft(a)}else{if(!s.state.slotValues[a]||a>=n-1)return;i.preventDefault(),s.moveFocusRight(a)}let d=s.state.activeSlot;o.setSelectionRange(d,d),m()}else if(i.key==="ArrowLeft"){i.preventDefault(),s.moveFocusLeft(a);let d=s.state.activeSlot;o.setSelectionRange(d,d),m()}else if(i.key==="ArrowRight"){i.preventDefault(),s.moveFocusRight(a);let d=s.state.activeSlot;o.setSelectionRange(d,d),m()}}function U(i){if(l)return;let a=o.value;if(!a){s.resetState(),o.value="",o.setSelectionRange(0,0),m();return}let g=w(a,u,L),d=Array(n).fill("");for(let v=0;v<Math.min(g.length,n);v++)d[v]=g[v];s.resetState();for(let v=0;v<d.length;v++)d[v]&&s.inputChar(v,d[v]);let b=d.filter(v=>v!=="").length,x=Math.min(b,n-1);o.value=g.slice(0,n),o.setSelectionRange(x,x),s.moveFocusTo(x),m(),ne&&s.state.isComplete&&requestAnimationFrame(()=>o.blur())}function oe(i){var x,v,q;if(i.preventDefault(),l)return;let a=(v=(x=i.clipboardData)==null?void 0:x.getData("text"))!=null?v:"",g=(q=o.selectionStart)!=null?q:0;s.pasteString(g,a);let{slotValues:d,activeSlot:b}=s.state;o.value=d.join(""),o.setSelectionRange(b,b),m(),ne&&s.state.isComplete&&requestAnimationFrame(()=>o.blur())}function re(){j==null||j(),requestAnimationFrame(()=>{let i=s.state.activeSlot,a=s.state.slotValues[i];ie&&a?o.setSelectionRange(i,i+1):o.setSelectionRange(i,i),m()})}function D(){K==null||K(),O.forEach(i=>i.classList.remove("is-active")),P.forEach(i=>{i.style.display="none"})}o.addEventListener("keydown",_),o.addEventListener("input",U),o.addEventListener("paste",oe),o.addEventListener("focus",re),o.addEventListener("blur",D),o.addEventListener("click",Y);function Y(i){if(T)return;let a=O.length-1;for(let b=0;b<O.length;b++)if(i.clientX<=O[b].getBoundingClientRect().right){a=b;break}let g=Math.min(a,o.value.length);s.moveFocusTo(g);let d=s.state.slotValues[g];ie&&d?o.setSelectionRange(g,g+1):o.setSelectionRange(g,g),m()}requestAnimationFrame(()=>{!T&&y&&o.focus(),o.setSelectionRange(0,0),m()});function pe(){s.resetState(),o.value="",S&&(S.textContent=M(p)),c&&(c.style.display="flex"),f&&f.classList.remove("is-visible"),r==null||r.stop(),k==null||k.restart(),requestAnimationFrame(()=>{o.focus(),o.setSelectionRange(0,0),m()})}function Ze(){pe(),h==null||h()}function Je(i){s.setError(i),m()}function Ue(i){O.forEach(a=>{a.classList.toggle("is-success",i),i&&a.classList.remove("is-error")})}function Ye(i){T=i,s.setDisabled(i),o.disabled=i,O.forEach(a=>{a.classList.toggle("is-disabled",i),a.style.pointerEvents=i?"none":""})}function Qe(i){l=i,s.setReadOnly(i),i?o.setAttribute("aria-readonly","true"):o.removeAttribute("aria-readonly"),m()}function et(){return s.getCode()}function tt(i){s.moveFocusTo(i),o.focus(),o.setSelectionRange(i,i),m()}function it(){o.removeEventListener("keydown",_),o.removeEventListener("input",U),o.removeEventListener("paste",oe),o.removeEventListener("focus",re),o.removeEventListener("blur",D),o.removeEventListener("click",Y),k==null||k.stop(),r==null||r.stop(),J(),C==null||C.abort(),e.__digitoFooterEl=null,e.__digitoResendRowEl=null}return{reset:pe,resend:Ze,setError:Je,setSuccess:Ue,setDisabled:Ye,setReadOnly:Qe,getCode:et,focus:tt,destroy:it}}var gt=["[data-lastpass-icon-root]","[data-lastpass-root]","[data-op-autofill]","[data-1p-ignore]","[data-dashlane-rid]","[data-dashlane-label]","[data-kwimpalastatus]","[data-bwautofill]","com-bitwarden-browser-arctic-modal"],mt=40;function Xe(){return typeof document=="undefined"?!1:gt.some(e=>{try{return document.querySelector(e)!==null}catch(t){return!1}})}function pt(e,t){if(typeof MutationObserver=="undefined")return()=>{};function n(){e.style.width=`${t+mt}px`}if(Xe())return n(),()=>{};let u=new MutationObserver(()=>{Xe()&&(n(),u.disconnect())});return u.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-lastpass-icon-root","data-lastpass-root","data-1p-ignore","data-dashlane-rid","data-kwimpalastatus"]}),()=>u.disconnect()}typeof window!="undefined"&&(window.Digito={init:me});return dt(vt);})();
3
3
  /**
4
4
  * digito/core/filter
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "digitojs",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Reliable OTP inputs for any framework from a single core.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -48,7 +48,6 @@
48
48
  ],
49
49
  "files": [
50
50
  "dist",
51
- "src",
52
51
  "README.md",
53
52
  "LICENSE",
54
53
  "CHANGELOG.md"
@@ -112,4 +111,4 @@
112
111
  "typescript": "^5.4.0"
113
112
  },
114
113
  "type": "module"
115
- }
114
+ }