import{b as J,d as Q,f as V}from"./chunk-TZKEAXTW.js";import{b as X,c as Z}from"./chunk-I547WOKC.js";import{a as F,e as T,f as C,h as G}from"./chunk-BJ43HUSB.js";import"./chunk-7NPRN4HX.js";import{a as h,b as B}from"./chunk-NMFL75IO.js";import{k as A}from"./chunk-24IZEI4V.js";var $=new WeakMap,H=(e,t,o,r=0,v=!1)=>{$.has(e)!==o&&(o?ne(e,t,r,v):ie(e,t))},ne=(e,t,o,r=!1)=>{let v=t.parentNode,l=t.cloneNode(!1);l.classList.add("cloned-input"),l.tabIndex=-1,r&&(l.disabled=!0);let S=e.ownerDocument.dir==="rtl";l.style.insetInlineStart=S?v.offsetWidth-t.offsetLeft-t.offsetWidth+"px":`${t.offsetLeft}px`,v.appendChild(l),$.set(e,l);let K=S?9999:-9999;e.style.pointerEvents="none",t.style.transform=`translate3d(${K}px,${o}px,0) scale(0)`},ie=(e,t)=>{let o=$.get(e);o&&($.delete(e),o.remove()),e.style.pointerEvents="",t.style.transform=""},q="input, textarea, [no-blur], [contenteditable]",_="$ionPaddingTimer",z=(e,t,o)=>{let r=e[_];r&&clearTimeout(r),t>0?e.style.setProperty("--keyboard-offset",`${t}px`):e[_]=setTimeout(()=>{e.style.setProperty("--keyboard-offset","0px"),o&&o()},120)},ee=(e,t,o)=>{e.addEventListener("focusout",()=>{t&&z(t,0,o)},{once:!0})},P=0,O="data-ionic-skip-scroll-assist",Y=e=>{var t;if(document.activeElement===e)return;let o=e.getAttribute("id"),r=e.closest(`label[for="${o}"]`),v=(t=document.activeElement)===null||t===void 0?void 0:t.closest(`label[for="${o}"]`);r!==null&&r===v||(e.setAttribute(O,"true"),e.focus())},te=(e,t,o,r,v,l,S=!1,K=0,I=!0)=>A(null,null,function*(){if(!o&&!r)return;let p=((m,c,L,b)=>{var n;return((s,i,w,y)=>{let d=s.top,u=s.bottom,a=i.top,f=a+15,E=Math.min(i.bottom,y-w)-50-u,D=f-d,x=Math.round(E<0?-E:D>0?-D:0),g=Math.min(x,d-a),M=Math.abs(g);return{scrollAmount:g,scrollDuration:Math.min(400,Math.max(150,M/.3)),scrollPadding:w,inputSafeY:4-(d-f)}})(((n=m.closest("ion-item,[ion-item]"))!==null&&n!==void 0?n:m).getBoundingClientRect(),c.getBoundingClientRect(),L,b)})(e,o||r,v,K);if(o&&Math.abs(p.scrollAmount)<4)return Y(t),void(l&&o!==null&&(z(o,P),ee(t,o,()=>P=0)));if(H(e,t,!0,p.inputSafeY,S),Y(t),G(()=>e.click()),l&&o&&(P=p.scrollPadding,z(o,P)),typeof window<"u"){let m,c=()=>A(null,null,function*(){m!==void 0&&clearTimeout(m),window.removeEventListener("ionKeyboardDidShow",L),window.removeEventListener("ionKeyboardDidShow",c),o&&(yield V(o,0,p.scrollAmount,p.scrollDuration)),H(e,t,!1,p.inputSafeY),document.activeElement===t&&Y(t),l&&ee(t,o,()=>P=0)}),L=()=>{window.removeEventListener("ionKeyboardDidShow",L),window.addEventListener("ionKeyboardDidShow",c)};if(o){let b=yield J(o);if(I&&p.scrollAmount>b.scrollHeight-b.clientHeight-b.scrollTop)return t.type==="password"?(p.scrollAmount+=50,window.addEventListener("ionKeyboardDidShow",L)):window.addEventListener("ionKeyboardDidShow",c),void(m=setTimeout(c,1e3))}c()}}),de=(e,t)=>A(null,null,function*(){if(B===void 0)return;let o=t==="ios",r=t==="android",v=e.getNumber("keyboardHeight",290),l=e.getBoolean("scrollAssist",!0),S=e.getBoolean("hideCaretOnScroll",o),K=e.getBoolean("inputBlurring",!1),I=e.getBoolean("scrollPadding",!0),p=Array.from(B.querySelectorAll("ion-input, ion-textarea")),m=new WeakMap,c=new WeakMap,L=yield Z.getResizeMode(),b=n=>A(null,null,function*(){yield new Promise(d=>F(n,d));let s=n.shadowRoot||n,i=s.querySelector("input")||s.querySelector("textarea"),w=Q(n),y=w?null:n.closest("ion-footer");if(i){if(w&&S&&!m.has(n)){let d=((u,a,f)=>{if(!f||!a)return()=>{};let E=M=>{var k;(k=a)===k.getRootNode().activeElement&&H(u,a,M)},D=()=>H(u,a,!1),x=()=>E(!0),g=()=>E(!1);return T(f,"ionScrollStart",x),T(f,"ionScrollEnd",g),a.addEventListener("blur",D),()=>{C(f,"ionScrollStart",x),C(f,"ionScrollEnd",g),a.removeEventListener("blur",D)}})(n,i,w);m.set(n,d)}if(i.type!=="date"&&i.type!=="datetime-local"&&(w||y)&&l&&!c.has(n)){let d=((u,a,f,E,D,x,g,M=!1)=>{let k=x&&(g===void 0||g.mode===X.None),N=!1,U=h!==void 0?h.innerHeight:0,R=oe=>{N!==!1?te(u,a,f,E,oe.detail.keyboardHeight,k,M,U,!1):N=!0},W=()=>{N=!1,h==null||h.removeEventListener("ionKeyboardDidShow",R),u.removeEventListener("focusout",W)},j=()=>A(null,null,function*(){a.hasAttribute(O)?a.removeAttribute(O):(te(u,a,f,E,D,k,M,U),h==null||h.addEventListener("ionKeyboardDidShow",R),u.addEventListener("focusout",W))});return u.addEventListener("focusin",j),()=>{u.removeEventListener("focusin",j),h==null||h.removeEventListener("ionKeyboardDidShow",R),u.removeEventListener("focusout",W)}})(n,i,w,y,v,I,L,r);c.set(n,d)}}});K&&(()=>{let n=!0,s=!1,i=document;T(i,"ionScrollStart",()=>{s=!0}),i.addEventListener("focusin",()=>{n=!0},!0),i.addEventListener("touchend",w=>{if(s)return void(s=!1);let y=i.activeElement;if(!y||y.matches(q))return;let d=w.target;d!==y&&(d.matches(q)||d.closest(q)||(n=!1,setTimeout(()=>{n||y.blur()},50)))},!1)})();for(let n of p)b(n);B.addEventListener("ionInputDidLoad",n=>{b(n.detail)}),B.addEventListener("ionInputDidUnload",n=>{(s=>{if(S){let i=m.get(s);i&&i(),m.delete(s)}if(l){let i=c.get(s);i&&i(),c.delete(s)}})(n.detail)})});export{de as startInputShims};
