import{p as o}from"./p-71c4eb61.js";const t=new WeakMap,n=(o,n,i,a=0)=>{t.has(o)!==i&&(i?e(o,n,a):r(o,n))},i=o=>o===o.getRootNode().activeElement,e=(o,n,i)=>{const e=n.parentNode,r=n.cloneNode(!1);r.classList.add("cloned-input"),r.tabIndex=-1,e.appendChild(r),t.set(o,r);const a="rtl"===o.ownerDocument.dir?9999:-9999;o.style.pointerEvents="none",n.style.transform=`translate3d(${a}px,${i}px,0) scale(0)`},r=(o,n)=>{const i=t.get(o);i&&(t.delete(o),i.remove()),o.style.pointerEvents="",n.style.transform=""},a="input, textarea, [no-blur]",c=async(o,t,i,e,r)=>{if(!i&&!e)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,i||e,r);if(i&&Math.abs(a.scrollAmount)<4)t.focus();else if(n(o,t,!0,a.inputSafeY),t.focus(),"undefined"!=typeof window){let e;const r=async()=>{void 0!==e&&clearTimeout(e),window.removeEventListener("ionKeyboardDidShow",c),window.removeEventListener("ionKeyboardDidShow",r),i&&await i.scrollByPoint(0,a.scrollAmount,a.scrollDuration),n(o,t,!1,a.inputSafeY),t.focus()},c=()=>{window.removeEventListener("ionKeyboardDidShow",c),window.addEventListener("ionKeyboardDidShow",r)};if(i){const o=await i.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(e=setTimeout(r,1e3))}r()}},s=(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)},u=t=>{const e=document,r=t.getNumber("keyboardHeight",290),u=t.getBoolean("scrollAssist",!0),d=t.getBoolean("hideCaretOnScroll",!0),l=t.getBoolean("inputBlurring",!0),f=t.getBoolean("scrollPadding",!0),w=Array.from(e.querySelectorAll("ion-input, ion-textarea")),p=new WeakMap,h=new WeakMap,S=async t=>{t.componentOnReady&&await t.componentOnReady();const e=t.shadowRoot||t,a=e.querySelector("input")||e.querySelector("textarea"),s=t.closest("ion-content"),l=s?null:t.closest("ion-footer");if(a){if(s&&d&&!p.has(t)){const o=((o,t,e)=>{if(!e||!t)return()=>{};const r=e=>{i(t)&&n(o,t,e)},a=()=>n(o,t,!1),c=()=>r(!0),s=()=>r(!1);return e.addEventListener("ionScrollStart",c),e.addEventListener("ionScrollEnd",s),t.addEventListener("blur",a),()=>{e.removeEventListener("ionScrollStart",c),e.removeEventListener("ionScrollEnd",s),t.addEventListener("ionBlur",a)}})(t,a,s);p.set(t,o)}if((s||l)&&u&&!h.has(t)){const n=((t,n,e,r,a)=>{let s;const u=t=>{s=o(t)},d=u=>{if(!s)return;const d=o(u);((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,s,d)||i(n)||(u.preventDefault(),u.stopPropagation(),c(t,n,e,r,a))};return t.addEventListener("touchstart",u,!0),t.addEventListener("touchend",d,!0),()=>{t.removeEventListener("touchstart",u,!0),t.removeEventListener("touchend",d,!0)}})(t,a,s,l,r);h.set(t,n)}}};l&&(()=>{let o=!0,t=!1;const n=document;n.addEventListener("ionScrollStart",()=>{t=!0}),n.addEventListener("focusin",()=>{o=!0},!0),n.addEventListener("touchend",i=>{if(t)return void(t=!1);const e=n.activeElement;if(!e)return;if(e.matches(a))return;const r=i.target;r!==e&&(r.matches(a)||r.closest(a)||(o=!1,setTimeout(()=>{o||e.blur()},50)))},!1)})(),f&&(o=>{const t=document;t.addEventListener("focusin",t=>{s(t.target,o)}),t.addEventListener("focusout",o=>{s(o.target,0)})})(r);for(const o of w)S(o);e.addEventListener("ionInputDidLoad",o=>{S(o.detail)}),e.addEventListener("ionInputDidUnload",o=>{(o=>{if(d){const t=p.get(o);t&&t(),p.delete(o)}if(u){const t=h.get(o);t&&t(),h.delete(o)}})(o.detail)})};export{u as startInputShims}