import{i as pointerCoord}from"./chunk-3488a752.js";var cloneMap=new WeakMap;function relocateInput(e,t,n,o){void 0===o&&(o=0),cloneMap.has(e)!==n&&(n?addClone(e,t,o):removeClone(e,t))}function isFocused(e){return e===e.getRootNode().activeElement}function addClone(e,t,n){var o=t.parentNode,r=t.cloneNode(!1);r.classList.add("cloned-input"),r.tabIndex=-1,o.appendChild(r),cloneMap.set(e,r);var a="rtl"===e.ownerDocument.dir?9999:-9999;e.style.pointerEvents="none",t.style.transform="translate3d("+a+"px,"+n+"px,0) scale(0)"}function removeClone(e,t){var n=cloneMap.get(e);n&&(cloneMap.delete(e),n.remove()),e.style.pointerEvents="",t.style.transform=""}function enableHideCaretOnScroll(e,t,n){if(!n||!t)return function(){};var o=function(n){isFocused(t)&&relocateInput(e,t,n)},r=function(){return relocateInput(e,t,!1)},a=function(){return o(!0)},i=function(){return o(!1)};return n.addEventListener("ionScrollStart",a),n.addEventListener("ionScrollEnd",i),t.addEventListener("blur",r),function(){n.removeEventListener("ionScrollStart",a),n.removeEventListener("ionScrollEnd",i),t.addEventListener("ionBlur",r)}}var SKIP_SELECTOR="input, textarea, [no-blur]";function enableInputBlurring(e){var t=!0,n=!1;function o(){n=!0}function r(){t=!0}function a(o){if(n)n=!1;else{var r=e.activeElement;if(r&&!r.matches(SKIP_SELECTOR)){var a=o.target;a!==r&&(a.matches(SKIP_SELECTOR)||a.closest(SKIP_SELECTOR)||(t=!1,setTimeout(function(){t||r.blur()},50)))}}}return e.addEventListener("ionScrollStart",o),e.addEventListener("focusin",r,!0),e.addEventListener("touchend",a,!1),function(){e.removeEventListener("ionScrollStart",o,!0),e.removeEventListener("focusin",r,!0),e.removeEventListener("touchend",a,!1)}}var SCROLL_ASSIST_SPEED=.3;function getScrollData(e,t,n){return calcScrollData((e.closest("ion-item,[ion-item]")||e).getBoundingClientRect(),t.getBoundingClientRect(),n,e.ownerDocument.defaultView.innerHeight)}function calcScrollData(e,t,n,o){var r=e.top,a=e.bottom,i=t.top,l=i+15,c=.5*Math.min(t.bottom,o-n)-a,u=l-r,s=Math.round(c<0?-c:u>0?-u:0),d=Math.min(s,r-i),f=Math.abs(d);return{scrollAmount:d,scrollDuration:Math.min(400,Math.max(150,f/SCROLL_ASSIST_SPEED)),scrollPadding:n,inputSafeY:4-(r-l)}}function enableScrollAssist(e,t,n,o){var r,a=function(e){r=pointerCoord(e)},i=function(a){if(r){var i=pointerCoord(a);hasPointerMoved(6,r,i)||isFocused(t)||(a.preventDefault(),a.stopPropagation(),jsSetFocus(e,t,n,o))}};return e.addEventListener("touchstart",a,!0),e.addEventListener("touchend",i,!0),function(){e.removeEventListener("touchstart",a,!0),e.removeEventListener("touchend",i,!0)}}function jsSetFocus(e,t,n,o){var r=getScrollData(e,n,o);Math.abs(r.scrollAmount)<4?t.focus():(relocateInput(e,t,!0,r.inputSafeY),t.focus(),n.scrollByPoint(0,r.scrollAmount,r.scrollDuration).then(function(){relocateInput(e,t,!1,r.inputSafeY),t.focus()}))}function hasPointerMoved(e,t,n){if(t&&n){var o=t.x-n.x,r=t.y-n.y;return o*o+r*r>e*e}return!1}var PADDING_TIMER_KEY="$ionPaddingTimer";function enableScrollPadding(e,t){function n(e){setScrollPadding(e.target,t)}function o(e){setScrollPadding(e.target,0)}return e.addEventListener("focusin",n),e.addEventListener("focusout",o),function(){e.removeEventListener("focusin",n),e.removeEventListener("focusout",o)}}function setScrollPadding(e,t){if("INPUT"===e.tagName&&!(e.parentElement&&"ION-INPUT"===e.parentElement.tagName||e.parentElement&&e.parentElement.parentElement&&"ION-SEARCHBAR"===e.parentElement.parentElement.tagName)){var n=e.closest("ion-content");if(null!==n){var o=n[PADDING_TIMER_KEY];o&&clearTimeout(o),t>0?n.style.setProperty("--keyboard-offset",t+"px"):n[PADDING_TIMER_KEY]=setTimeout(function(){n.style.setProperty("--keyboard-offset","0px")},120)}}}var INPUT_BLURRING=!0,SCROLL_PADDING=!0;function startInputShims(e,t){var n=t.getNumber("keyboardHeight",290),o=t.getBoolean("scrollAssist",!0),r=t.getBoolean("hideCaretOnScroll",!0),a=t.getBoolean("inputBlurring",!0),i=t.getBoolean("scrollPadding",!0),l=new WeakMap,c=new WeakMap;function u(e){var t=(e.shadowRoot||e).querySelector("input")||(e.shadowRoot||e).querySelector("textarea"),a=e.closest("ion-content");if(t){if(a&&r&&!l.has(e)){var i=enableHideCaretOnScroll(e,t,a);l.set(e,i)}a&&o&&!c.has(e)&&(i=enableScrollAssist(e,t,a,n),c.set(e,i))}}a&&INPUT_BLURRING&&enableInputBlurring(e),i&&SCROLL_PADDING&&enableScrollPadding(e,n);for(var s=0,d=Array.from(e.querySelectorAll("ion-input, ion-textarea"));s<d.length;s++)u(d[s]);e.body.addEventListener("ionInputDidLoad",function(e){u(e.target)}),e.body.addEventListener("ionInputDidUnload",function(e){var t,n;t=e.target,r&&((n=l.get(t))&&n(),l.delete(t)),o&&((n=c.get(t))&&n(),c.delete(t))})}export{startInputShims};