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