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