import{i as t}from"./chunk-14141f33.js";const n=new WeakMap;function e(t,e,o,r=0){n.has(t)!==o&&(o?function(t,e,o){const r=e.parentNode,i=e.cloneNode(!1);i.classList.add("cloned-input"),i.tabIndex=-1,r.appendChild(i),n.set(t,i);const s="rtl"===t.ownerDocument.dir?9999:-9999;t.style.pointerEvents="none",e.style.transform=`translate3d(${s}px,${o}px,0) scale(0)`}(t,e,r):function(t,e){const o=n.get(t);o&&(n.delete(t),o.remove()),t.style.pointerEvents="",e.style.transform=""}(t,e))}function o(t){return t===t.getRootNode().activeElement}const r="input, textarea, [no-blur]",i=.3;function s(n,r,s,c){let a;const u=n=>{a=t(n)},l=u=>{if(!a)return;(function(t,n,e){if(a&&e){const t=a.x-e.x,n=a.y-e.y;return t*t+n*n>36}return!1})(0,0,t(u))||o(r)||(u.preventDefault(),u.stopPropagation(),function(t,n,o,r){const s=function(t,n,e){return function(t,n,e,o){const r=t.top,s=t.bottom,c=n.top+15,a=.5*Math.min(n.bottom,o-e)-s,u=c-r,l=Math.round(a<0?-a:u>0?-u:0),d=Math.abs(l);return{scrollAmount:l,scrollDuration:Math.min(400,Math.max(150,d/i)),scrollPadding:e,inputSafeY:4-(r-c)}}((t.closest("ion-item,[ion-item]")||t).getBoundingClientRect(),n.getBoundingClientRect(),e,window.innerHeight)}(t,o,r);Math.abs(s.scrollAmount)<4?n.focus():(e(t,n,!0,s.inputSafeY),n.focus(),o.scrollByPoint(0,s.scrollAmount,s.scrollDuration).then(()=>{e(t,n,!1,s.inputSafeY),n.focus()}))}(n,r,s,c))};return n.addEventListener("touchstart",u,!0),n.addEventListener("touchend",l,!0),()=>{n.removeEventListener("touchstart",u,!0),n.removeEventListener("touchend",l,!0)}}const c="$ionPaddingTimer";function a(t,n){if("INPUT"!==t.tagName)return;if(t.parentElement&&"ION-INPUT"===t.parentElement.tagName)return;const e=t.closest("ion-content");if(null===e)return;const o=e[c];o&&clearTimeout(o),n>0?e.style.setProperty("--keyboard-offset",`${n}px`):e[c]=setTimeout(()=>{e.style.setProperty("--keyboard-offset","0px")},120)}const u=!0,l=!0;function d(t,n){const i=n.getNumber("keyboardHeight",290),c=n.getBoolean("scrollAssist",!0),d=n.getBoolean("hideCaretOnScroll",!0),f=n.getBoolean("inputBlurring",!0),m=n.getBoolean("scrollPadding",!0),p=new WeakMap,v=new WeakMap;function g(t){const n=(t.shadowRoot||t).querySelector("input"),r=t.closest("ion-content");if(n){if(r&&d&&!p.has(t)){const i=function(t,n,r){if(!r||!n)return()=>{};const i=r=>{o(n)&&e(t,n,r)},s=()=>e(t,n,!1),c=()=>i(!0),a=()=>i(!1);return r.addEventListener("ionScrollStart",c),r.addEventListener("ionScrollEnd",a),n.addEventListener("blur",s),()=>{r.removeEventListener("ionScrollStart",c),r.removeEventListener("ionScrollEnd",a),n.addEventListener("ionBlur",s)}}(t,n,r);p.set(t,i)}if(r&&c&&!v.has(t)){const e=s(t,n,r,i);v.set(t,e)}}}f&&u&&function(t){let n=!0,e=!1;t.addEventListener("ionScrollStart",function(){e=!0}),t.addEventListener("focusin",function(){n=!0},!0),t.addEventListener("touchend",function(o){if(e)return void(e=!1);const i=t.activeElement;if(!i)return;if(i.matches(r))return;const s=o.target;s!==i&&(s.matches(r)||s.closest(r)||(n=!1,setTimeout(()=>{n||i.blur()},50)))},!1)}(t),m&&l&&function(t,n){t.addEventListener("focusin",function(t){a(t.target,n)}),t.addEventListener("focusout",function(t){a(t.target,0)})}(t,i);const E=Array.from(t.querySelectorAll("ion-input"));for(const t of E)g(t);t.body.addEventListener("ionInputDidLoad",t=>{g(t.target)}),t.body.addEventListener("ionInputDidUnload",t=>{!function(t){if(d){const n=p.get(t);n&&n(),p.delete(t)}if(c){const n=v.get(t);n&&n(),v.delete(t)}}(t.target)})}export{d as startInputShims};