@tindtechnologies/universalviewer
Version:
The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎
2 lines (1 loc) • 4.15 kB
JavaScript
import{h as B}from"./chunk-4DAZ7WDM.js";import"./chunk-L67DAW3A.js";var g=new WeakMap,L=function(e,r,t,n){n===void 0&&(n=0),g.has(e)!==t&&(t?D(e,r,n):M(e,r))},T=function(e){return e===e.getRootNode().activeElement},D=function(e,r,t){var n=r.parentNode,a=r.cloneNode(!1);a.classList.add("cloned-input"),a.tabIndex=-1,n.appendChild(a),g.set(e,a);var i=e.ownerDocument,s=i.dir==="rtl"?9999:-9999;e.style.pointerEvents="none",r.style.transform="translate3d("+s+"px,"+t+"px,0) scale(0)"},M=function(e,r){var t=g.get(e);t&&(g.delete(e),t.remove()),e.style.pointerEvents="",r.style.transform=""},N=function(e,r,t){if(!t||!r)return function(){};var n=function(u){T(r)&&L(e,r,u)},a=function(){return L(e,r,!1)},i=function(){return n(!0)},s=function(){return n(!1)};return t.addEventListener("ionScrollStart",i),t.addEventListener("ionScrollEnd",s),r.addEventListener("blur",a),function(){t.removeEventListener("ionScrollStart",i),t.removeEventListener("ionScrollEnd",s),r.addEventListener("ionBlur",a)}},P="input, textarea, [no-blur]",C=function(){var e=!0,r=!1,t=document,n=function(){r=!0},a=function(){e=!0},i=function(s){if(r){r=!1;return}var u=t.activeElement;if(u&&!u.matches(P)){var v=s.target;v!==u&&(v.matches(P)||v.closest(P)||(e=!1,setTimeout(function(){e||u.blur()},50)))}};return t.addEventListener("ionScrollStart",n),t.addEventListener("focusin",a,!0),t.addEventListener("touchend",i,!1),function(){t.removeEventListener("ionScrollStart",n,!0),t.removeEventListener("focusin",a,!0),t.removeEventListener("touchend",i,!1)}},x=.3,w=function(e,r,t){var n=e.closest("ion-item,[ion-item]")||e;return p(n.getBoundingClientRect(),r.getBoundingClientRect(),t,e.ownerDocument.defaultView.innerHeight)},p=function(e,r,t,n){var a=e.top,i=e.bottom,s=r.top,u=Math.min(r.bottom,n-t),v=s+15,d=u*.5,c=d-i,m=v-a,l=Math.round(c<0?-c:m>0?-m:0),S=Math.min(l,a-s),A=Math.abs(S),o=A/x,f=Math.min(400,Math.max(150,o));return{scrollAmount:S,scrollDuration:f,scrollPadding:t,inputSafeY:-(a-v)+4}},R=function(e,r,t,n){var a,i=function(u){a=B(u)},s=function(u){if(a){var v=B(u);!F(6,a,v)&&!T(r)&&(u.preventDefault(),u.stopPropagation(),O(e,r,t,n))}};return e.addEventListener("touchstart",i,!0),e.addEventListener("touchend",s,!0),function(){e.removeEventListener("touchstart",i,!0),e.removeEventListener("touchend",s,!0)}},O=function(e,r,t,n){var a=w(e,t,n);if(Math.abs(a.scrollAmount)<4){r.focus();return}L(e,r,!0,a.inputSafeY),r.focus(),t.scrollByPoint(0,a.scrollAmount,a.scrollDuration).then(function(){L(e,r,!1,a.inputSafeY),r.focus()})},F=function(e,r,t){if(r&&t){var n=r.x-t.x,a=r.y-t.y,i=n*n+a*a;return i>e*e}return!1},b="$ionPaddingTimer",k=function(e){var r=document,t=function(a){y(a.target,e)},n=function(a){y(a.target,0)};return r.addEventListener("focusin",t),r.addEventListener("focusout",n),function(){r.removeEventListener("focusin",t),r.removeEventListener("focusout",n)}},y=function(e,r){if(e.tagName==="INPUT"&&!(e.parentElement&&e.parentElement.tagName==="ION-INPUT")&&!(e.parentElement&&e.parentElement.parentElement&&e.parentElement.parentElement.tagName==="ION-SEARCHBAR")){var t=e.closest("ion-content");if(t!==null){var n=t[b];n&&clearTimeout(n),r>0?t.style.setProperty("--keyboard-offset",r+"px"):t[b]=setTimeout(function(){t.style.setProperty("--keyboard-offset","0px")},120)}}},U=!0,H=!0,q=function(e){var r=document,t=e.getNumber("keyboardHeight",290),n=e.getBoolean("scrollAssist",!0),a=e.getBoolean("hideCaretOnScroll",!0),i=e.getBoolean("inputBlurring",!0),s=e.getBoolean("scrollPadding",!0),u=Array.from(r.querySelectorAll("ion-input, ion-textarea")),v=new WeakMap,d=new WeakMap,c=function(o){var f=(o.shadowRoot||o).querySelector("input")||(o.shadowRoot||o).querySelector("textarea"),h=o.closest("ion-content");if(f){if(h&&a&&!v.has(o)){var I=N(o,f,h);v.set(o,I)}if(h&&n&&!d.has(o)){var I=R(o,f,h,t);d.set(o,I)}}},m=function(o){if(a){var f=v.get(o);f&&f(),v.delete(o)}if(n){var f=d.get(o);f&&f(),d.delete(o)}};i&&U&&C(),s&&H&&k(t);for(var l=0,S=u;l<S.length;l++){var A=S[l];c(A)}r.addEventListener("ionInputDidLoad",function(o){c(o.detail)}),r.addEventListener("ionInputDidUnload",function(o){m(o.detail)})};export{q as startInputShims};