@ionic/core
Version:
Base components for Ionic
4 lines • 4.76 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{w as o,d as t}from"./p-7b30edcc.js";import{g as n,c as i,f as r}from"./p-c3f9d9fe.js";import{a,b as e,r as s,c as d}from"./p-ece78e7b.js";import{a as c,K as l}from"./p-27281edd.js";import"./p-3f4327f7.js";import"./p-597ff9af.js";import"./p-66a5d6a8.js";import"./p-c61cc894.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]",b="$ionPaddingTimer",h=(o,t,n)=>{const i=o[b];i&&clearTimeout(i),t>0?o.style.setProperty("--keyboard-offset",`${t}px`):o[b]=setTimeout((()=>{o.style.setProperty("--keyboard-offset","0px"),n&&n()}),120)},y=(o,t,n)=>{o.addEventListener("focusout",(()=>{t&&h(t,0,n)}),{once:!0})};let S=0;const D="data-ionic-skip-scroll-assist",v=o=>{document.activeElement!==o&&(o.setAttribute(D,"true"),o.focus())},K=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 v(t),void(d&&null!==r&&(h(r,S),y(t,r,(()=>S=0))));if(f(o,t,!0,p.inputSafeY,c),v(t),s((()=>o.click())),d&&r&&(S=p.scrollPadding,h(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),v(t),d&&y(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()}},M=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),b=n.getBoolean("hideCaretOnScroll",s),h=n.getBoolean("inputBlurring",!1),y=n.getBoolean("scrollPadding",!0),S=Array.from(t.querySelectorAll("ion-input, ion-textarea")),v=new WeakMap,M=new WeakMap,j=await l.getResizeMode(),x=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&&b&&!v.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);v.set(t,o)}if("date"!==i.type&&"datetime-local"!==i.type&&(s||l)&&w&&!M.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?K(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(D)?n.removeAttribute(D):(K(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,y,j,u);M.set(t,n)}}};h&&(()=>{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)x(o);t.addEventListener("ionInputDidLoad",(o=>{x(o.detail)})),t.addEventListener("ionInputDidUnload",(o=>{(o=>{if(b){const t=v.get(o);t&&t(),v.delete(o)}if(w){const t=M.get(o);t&&t(),M.delete(o)}})(o.detail)}))};export{M as startInputShims}