text: import{a as o,b as t,p as n}from"./p-9ea098f1.js";const i=new WeakMap,e=(o,t,n,e=0)=>{i.has(o)!==n&&(n?a(o,t,e):c(o,t))},r=o=>o===o.getRootNode().activeElement,a=(o,t,n)=>{const e=t.parentNode,r=t.cloneNode(!1);r.classList.add("cloned-input"),r.tabIndex=-1,e.appendChild(r),i.set(o,r);const a="rtl"===o.ownerDocument.dir?9999:-9999;o.style.pointerEvents="none",t.style.transform=`translate3d(${a}px,${n}px,0) scale(0)`},c=(o,t)=>{const n=i.get(o);n&&(i.delete(o),n.remove()),o.style.pointerEvents="",t.style.transform=""},s="input, textarea, [no-blur]",u=async(o,t,n,i,r)=>{if(!n&&!i)return;const a=((o,t,n)=>((o,t,n,i)=>{const e=o.top,r=o.bottom,a=t.top,c=a+15,s=.75*Math.min(t.bottom,i-n)-r,u=c-e,d=Math.round(s<0?-s:u>0?-u:0),l=Math.min(d,e-a),f=Math.abs(l);return{scrollAmount:l,scrollDuration:Math.min(400,Math.max(150,f/.3)),scrollPadding:n,inputSafeY:4-(e-c)}})((o.closest("ion-item,[ion-item]")||o).getBoundingClientRect(),t.getBoundingClientRect(),n,o.ownerDocument.defaultView.innerHeight))(o,n||i,r);if(n&&Math.abs(a.scrollAmount)<4)t.focus();else if(e(o,t,!0,a.inputSafeY),t.focus(),"undefined"!=typeof window){let i;const r=async()=>{void 0!==i&&clearTimeout(i),window.removeEventListener("ionKeyboardDidShow",c),window.removeEventListener("ionKeyboardDidShow",r),n&&await n.scrollByPoint(0,a.scrollAmount,a.scrollDuration),e(o,t,!1,a.inputSafeY),t.focus()},c=()=>{window.removeEventListener("ionKeyboardDidShow",c),window.addEventListener("ionKeyboardDidShow",r)};if(n){const o=await n.getScrollElement();if(a.scrollAmount>o.scrollHeight-o.clientHeight-o.scrollTop)return"password"===t.type?(a.scrollAmount+=50,window.addEventListener("ionKeyboardDidShow",c)):window.addEventListener("ionKeyboardDidShow",r),void(i=setTimeout(r,1e3))}r()}},d=(o,t)=>{if("INPUT"!==o.tagName)return;if(o.parentElement&&"ION-INPUT"===o.parentElement.tagName)return;if(o.parentElement&&o.parentElement.parentElement&&"ION-SEARCHBAR"===o.parentElement.parentElement.tagName)return;const n=o.closest("ion-content");if(null===n)return;const i=n.$ionPaddingTimer;i&&clearTimeout(i),t>0?n.style.setProperty("--keyboard-offset",t+"px"):n.$ionPaddingTimer=setTimeout(()=>{n.style.setProperty("--keyboard-offset","0px")},120)},l=i=>{const a=document,c=i.getNumber("keyboardHeight",290),l=i.getBoolean("scrollAssist",!0),f=i.getBoolean("hideCaretOnScroll",!0),w=i.getBoolean("inputBlurring",!0),p=i.getBoolean("scrollPadding",!0),h=Array.from(a.querySelectorAll("ion-input, ion-textarea")),S=new WeakMap,y=new WeakMap,m=async i=>{i.componentOnReady&&await i.componentOnReady();const a=i.shadowRoot||i,s=a.querySelector("input")||a.querySelector("textarea"),d=i.closest("ion-content"),w=d?null:i.closest("ion-footer");if(s){if(d&&f&&!S.has(i)){const n=((n,i,a)=>{if(!a||!i)return()=>{};const c=o=>{r(i)&&e(n,i,o)},s=()=>e(n,i,!1),u=()=>c(!0),d=()=>c(!1);return o(a,"ionScrollStart",u),o(a,"ionScrollEnd",d),i.addEventListener("blur",s),()=>{t(a,"ionScrollStart",u),t(a,"ionScrollEnd",d),i.addEventListener("ionBlur",s)}})(i,s,d);S.set(i,n)}if((d||w)&&l&&!y.has(i)){const o=((o,t,i,e,a)=>{let c;const s=o=>{c=n(o)},d=s=>{if(!c)return;const d=n(s);((o,t,n)=>{if(t&&n){const i=t.x-n.x,e=t.y-n.y;return i*i+e*e>o*o}return!1})(6,c,d)||r(t)||(s.preventDefault(),s.stopPropagation(),u(o,t,i,e,a))};return o.addEventListener("touchstart",s,!0),o.addEventListener("touchend",d,!0),()=>{o.removeEventListener("touchstart",s,!0),o.removeEventListener("touchend",d,!0)}})(i,s,d,w,c);y.set(i,o)}}};w&&(()=>{let t=!0,n=!1;const i=document;o(i,"ionScrollStart",()=>{n=!0}),i.addEventListener("focusin",()=>{t=!0},!0),i.addEventListener("touchend",o=>{if(n)return void(n=!1);const e=i.activeElement;if(!e)return;if(e.matches(s))return;const r=o.target;r!==e&&(r.matches(s)||r.closest(s)||(t=!1,setTimeout(()=>{t||e.blur()},50)))},!1)})(),p&&(o=>{const t=document;t.addEventListener("focusin",t=>{d(t.target,o)}),t.addEventListener("focusout",o=>{d(o.target,0)})})(c);for(const o of h)m(o);a.addEventListener("ionInputDidLoad",o=>{m(o.detail)}),a.addEventListener("ionInputDidUnload",o=>{(o=>{if(f){const t=S.get(o);t&&t(),S.delete(o)}if(l){const t=y.get(o);t&&t(),y.delete(o)}})(o.detail)})};export{l as startInputShims}