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