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