{"version":3,"file":"delay.mjs","names":["IN_BROWSER","propsFactory","makeDelayProps","closeDelay","Number","String","openDelay","useDelay","props","cb","delays","runDelayFactory","prop","Promise","resolve","active","window","clearTimeout","delay","parseInt","setTimeout","runCloseDelay","runOpenDelay"],"sources":["../../src/composables/delay.ts"],"sourcesContent":["// Utilities\nimport { IN_BROWSER, propsFactory } from '@/util'\n\n// Types\nexport interface DelayProps {\n closeDelay?: number | string\n openDelay?: number | string\n}\n\n// Composables\nexport const makeDelayProps = propsFactory({\n closeDelay: [Number, String],\n openDelay: [Number, String],\n}, 'delay')\n\nexport function useDelay (props: DelayProps, cb?: (value: boolean) => void) {\n const delays: Partial> = {}\n const runDelayFactory = (prop: keyof DelayProps) => (): Promise => {\n // istanbul ignore next\n if (!IN_BROWSER) return Promise.resolve(true)\n\n const active = prop === 'openDelay'\n\n delays.closeDelay && window.clearTimeout(delays.closeDelay)\n delete delays.closeDelay\n\n delays.openDelay && window.clearTimeout(delays.openDelay)\n delete delays.openDelay\n\n return new Promise(resolve => {\n const delay = parseInt(props[prop] ?? 0, 10)\n\n delays[prop] = window.setTimeout(() => {\n cb?.(active)\n resolve(active)\n }, delay)\n })\n }\n\n return {\n runCloseDelay: runDelayFactory('closeDelay'),\n runOpenDelay: runDelayFactory('openDelay'),\n }\n}\n"],"mappings":"AAAA;AAAA,SACSA,UAAU,EAAEC,YAAY,6BAEjC;AAMA;AACA,OAAO,MAAMC,cAAc,GAAGD,YAAY,CAAC;EACzCE,UAAU,EAAE,CAACC,MAAM,EAAEC,MAAM,CAAC;EAC5BC,SAAS,EAAE,CAACF,MAAM,EAAEC,MAAM;AAC5B,CAAC,EAAE,OAAO,CAAC;AAEX,OAAO,SAASE,QAAQA,CAAEC,KAAiB,EAAEC,EAA6B,EAAE;EAC1E,MAAMC,MAAiD,GAAG,CAAC,CAAC;EAC5D,MAAMC,eAAe,GAAIC,IAAsB,IAAK,MAAwB;IAC1E;IACA,IAAI,CAACZ,UAAU,EAAE,OAAOa,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