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