import s from"../../_util/KeyCode.mjs";import u from"../../_util/raf.mjs";import Y from"../../vc-util/Dom/isVisible.mjs";const o=new Map;function E(e,r){let t;function a(){Y(e)?r():t=u(()=>{a()})}return a(),()=>{u.cancel(t)}}function k(e,r,t){if(o.get(e)&&u.cancel(o.get(e)),t<=0){o.set(e,u(()=>{e.scrollTop=r}));return}const n=(r-e.scrollTop)/t*10;o.set(e,u(()=>{e.scrollTop+=n,e.scrollTop!==r&&k(e,r,t-10)}))}function T(e,{onLeftRight:r,onCtrlLeftRight:t,onUpDown:a,onPageUpDown:n,onEnter:f}){const{which:m,ctrlKey:d,metaKey:l}=e;switch(m){case s.LEFT:if(d||l){if(t)return t(-1),!0}else if(r)return r(-1),!0;break;case s.RIGHT:if(d||l){if(t)return t(1),!0}else if(r)return r(1),!0;break;case s.UP:if(a)return a(-1),!0;break;case s.DOWN:if(a)return a(1),!0;break;case s.PAGE_UP:if(n)return n(-1),!0;break;case s.PAGE_DOWN:if(n)return n(1),!0;break;case s.ENTER:if(f)return f(),!0;break}return!1}function N(e,r,t,a){let n=e;if(!n)switch(r){case"time":n=a?"hh:mm:ss a":"HH:mm:ss";break;case"week":n="gggg-wo";break;case"month":n="YYYY-MM";break;case"quarter":n="YYYY-[Q]Q";break;case"year":n="YYYY";break;default:n=t?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD"}return n}function v(e,r,t){const a=e==="time"?8:10,n=typeof r=="function"?r(t.getNow()).length:r.length;return Math.max(a,n)+2}let c=null;const i=new Set;function F(e){return!c&&typeof window<"u"&&window.addEventListener&&(c=r=>{[...i].forEach(t=>{t(r)})},window.addEventListener("mousedown",c)),i.add(e),()=>{i.delete(e),i.size===0&&(window.removeEventListener("mousedown",c),c=null)}}function H(e){const r=e.target;return e.composed&&r.shadowRoot&&e.composedPath?.()[0]||r}const w=e=>e==="month"||e==="date"?"year":e,M=e=>e==="date"?"month":e,b=e=>e==="month"||e==="date"?"quarter":e,g=e=>e==="date"?"week":e,G={year:w,month:M,quarter:b,week:g,time:null,date:null};function K(e,r){return e.some(t=>t&&t.contains(r))}export{G as PickerModeMap,F as addGlobalMousedownEvent,T as createKeydownHandler,K as elementsContains,N as getDefaultFormat,v as getInputSize,H as getTargetFromEvent,k as scrollTo,E as waitElementReady};
