/*!
 * (C) Ionic http://ionicframework.com - MIT License
 */
import{w as o,d as n}from"./p-ZjP4CjeZ.js";import{g as t,c as i,f as r}from"./p-CwgG81ZD.js";import{f as a,m as e,r as s,c as d}from"./p-CTfR9YZG.js";import{a as c,K as l}from"./p-D13Eaw-8.js";import"./p-C8IsBmNU.js";import"./p-CIGNaXM1.js";const u=new WeakMap,f=(o,n,t,i=0,r=!1)=>{u.has(o)!==t&&(t?w(o,n,i,r):p(o,n))},w=(o,n,t,i=!1)=>{const r=n.parentNode,a=n.cloneNode(!1);a.classList.add("cloned-input"),a.tabIndex=-1,i&&(a.disabled=!0);const e="rtl"===o.ownerDocument.dir;a.style.top=`${n.offsetTop}px`,e?a.style.right=r.offsetWidth-n.offsetLeft-n.offsetWidth+"px":a.style.left=`${n.offsetLeft}px`,r.appendChild(a),u.set(o,a);const s=e?9999:-9999;o.style.pointerEvents="none",n.style.transform=`translate3d(${s}px,${t}px,0) scale(0)`},p=(o,n)=>{const t=u.get(o);t&&(u.delete(o),t.remove()),o.style.pointerEvents="",n.style.transform=""},m="input, textarea, [no-blur], [contenteditable]",h="$ionPaddingTimer",y=(o,n,t)=>{const i=o[h];i&&clearTimeout(i),n>0?o.style.setProperty("--keyboard-offset",`${n}px`):o[h]=setTimeout((()=>{o.style.setProperty("--keyboard-offset","0px"),t&&t()}),120)},S=(o,n,t)=>{o.addEventListener("focusout",(()=>{n&&y(n,0,t)}),{once:!0})};let b=0;const D="data-ionic-skip-scroll-assist",v=o=>{var n;if(document.activeElement===o)return;const t=o.getAttribute("id"),i=o.closest(`label[for="${t}"]`),r=null===(n=document.activeElement)||void 0===n?void 0:n.closest(`label[for="${t}"]`);null!==i&&i===r||(o.setAttribute(D,"true"),o.focus())},x=async(o,n,r,a,e,d,c=!1,l=0,u=!0)=>{if(!r&&!a)return;const w=((o,n,t,i)=>{var r;return((o,n,t,i)=>{const r=o.top,a=o.bottom,e=n.top,s=e+15,d=Math.min(n.bottom,i-t)-50-a,c=s-r,l=Math.round(d<0?-d:c>0?-c:0),u=Math.min(l,r-e),f=Math.abs(u);return{scrollAmount:u,scrollDuration:Math.min(400,Math.max(150,f/.3)),scrollPadding:t,inputSafeY:4-(r-s)}})((null!==(r=o.closest("ion-item,[ion-item]"))&&void 0!==r?r:o).getBoundingClientRect(),n.getBoundingClientRect(),t,i)})(o,r||a,e,l);if(r&&Math.abs(w.scrollAmount)<4)return v(n),void(d&&null!==r&&(y(r,b),S(n,r,(()=>b=0))));if(f(o,n,!0,w.inputSafeY,c),v(n),s((()=>o.click())),d&&r&&(b=w.scrollPadding,y(r,b)),"undefined"!=typeof window){let a;const e=async()=>{void 0!==a&&clearTimeout(a),window.removeEventListener("ionKeyboardDidShow",s),window.removeEventListener("ionKeyboardDidShow",e),r&&await i(r,0,w.scrollAmount,w.scrollDuration),f(o,n,!1,w.inputSafeY),v(n),d&&S(n,r,(()=>b=0))},s=()=>{window.removeEventListener("ionKeyboardDidShow",s),window.addEventListener("ionKeyboardDidShow",e)};if(r){const o=await t(r);if(u&&w.scrollAmount>o.scrollHeight-o.clientHeight-o.scrollTop)return"password"===n.type?(w.scrollAmount+=50,window.addEventListener("ionKeyboardDidShow",s)):window.addEventListener("ionKeyboardDidShow",e),void(a=setTimeout(e,1e3))}e()}},M=async(t,i)=>{if(void 0===n)return;const s="ios"===i,u="android"===i,w=t.getNumber("keyboardHeight",290),p=t.getBoolean("scrollAssist",!0),h=t.getBoolean("hideCaretOnScroll",s),y=t.getBoolean("inputBlurring",!1),S=t.getBoolean("scrollPadding",!0),b=Array.from(n.querySelectorAll("ion-input, ion-textarea")),v=new WeakMap,M=new WeakMap,K=await l.getResizeMode(),j=async n=>{await new Promise((o=>d(n,o)));const t=n.shadowRoot||n,i=t.querySelector("input")||t.querySelector("textarea"),s=r(n),l=s?null:n.closest("ion-footer");if(i){if(s&&h&&!v.has(n)){const o=((o,n,t)=>{if(!t||!n)return()=>{};const i=t=>{var i;(i=n)===i.getRootNode().activeElement&&f(o,n,t)},r=()=>f(o,n,!1),s=()=>i(!0),d=()=>i(!1);return a(t,"ionScrollStart",s),a(t,"ionScrollEnd",d),n.addEventListener("blur",r),()=>{e(t,"ionScrollStart",s),e(t,"ionScrollEnd",d),n.removeEventListener("blur",r)}})(n,i,s);v.set(n,o)}if("date"!==i.type&&"datetime-local"!==i.type&&(s||l)&&p&&!M.has(n)){const t=((n,t,i,r,a,e,s,d=!1)=>{const l=e&&(void 0===s||s.mode===c.None);let u=!1;const f=void 0!==o?o.innerHeight:0,w=o=>{!1!==u?x(n,t,i,r,o.detail.keyboardHeight,l,d,f,!1):u=!0},p=()=>{u=!1,null==o||o.removeEventListener("ionKeyboardDidShow",w),n.removeEventListener("focusout",p)},m=async()=>{t.hasAttribute(D)?t.removeAttribute(D):(x(n,t,i,r,a,l,d,f),null==o||o.addEventListener("ionKeyboardDidShow",w),n.addEventListener("focusout",p))};return n.addEventListener("focusin",m),()=>{n.removeEventListener("focusin",m),null==o||o.removeEventListener("ionKeyboardDidShow",w),n.removeEventListener("focusout",p)}})(n,i,s,l,w,S,K,u);M.set(n,t)}}};y&&(()=>{let o=!0,n=!1;const t=document;a(t,"ionScrollStart",(()=>{n=!0})),t.addEventListener("focusin",(()=>{o=!0}),!0),t.addEventListener("touchend",(i=>{if(n)return void(n=!1);const r=t.activeElement;if(!r)return;if(r.matches(m))return;const a=i.target;a!==r&&(a.matches(m)||a.closest(m)||(o=!1,setTimeout((()=>{o||r.blur()}),50)))}),!1)})();for(const o of b)j(o);n.addEventListener("ionInputDidLoad",(o=>{j(o.detail)})),n.addEventListener("ionInputDidUnload",(o=>{(o=>{if(h){const n=v.get(o);n&&n(),v.delete(o)}if(p){const n=M.get(o);n&&n(),M.delete(o)}})(o.detail)}))};export{M as startInputShims}