@alwatr/delay 6.0.15 → 6.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.0.17](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.16...@alwatr/delay@6.0.17) (2025-12-10)
7
+
8
+ ### 🔗 Dependencies update
9
+
10
+ * Upgrade lerna-lite, prettier, types/node, and yarn dependencies. ([42a7fca](https://github.com/Alwatr/nanolib/commit/42a7fca15430aca2ac1eaa19496c2a2ebfc8c470))
11
+
12
+ ## [6.0.16](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.15...@alwatr/delay@6.0.16) (2025-11-18)
13
+
14
+ ### 🐛 Bug Fixes
15
+
16
+ * add type imports from @alwatr/nano-build and @alwatr/type-helper across multiple packages ([5ab7f15](https://github.com/Alwatr/nanolib/commit/5ab7f159ba57788bf8df40fa96a3027f589d5a77))
17
+
18
+ ### 🔨 Code Refactoring
19
+
20
+ * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
21
+
6
22
  ## [6.0.15](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.14...@alwatr/delay@6.0.15) (2025-11-15)
7
23
 
8
24
  ### 🔗 Dependencies update
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /** 📦 @alwatr/delay v6.0.15 */
2
- __dev_mode__: console.debug("📦 @alwatr/delay v6.0.15");
1
+ /** 📦 @alwatr/delay v6.0.17 */
2
+ __dev_mode__: console.debug("📦 @alwatr/delay v6.0.17");
3
3
  "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{delay:()=>delay,requestAnimationFrame:()=>requestAnimationFrame,requestIdleCallback:()=>requestIdleCallback});module.exports=__toCommonJS(main_exports);var import_parse_duration=require("@alwatr/parse-duration");var import_global_this=require("@alwatr/global-this");var globalThis=(0,import_global_this.getGlobalThis)();var requestAnimationFrame=globalThis.requestAnimationFrame?.bind(globalThis)??(callback=>setTimeout(()=>callback(performance.now()),1e3/60));var requestIdleCallback=globalThis.requestIdleCallback?.bind(globalThis)??((callback,options)=>{const startTime=Date.now();return setTimeout(()=>{callback({didTimeout:!!options?.timeout,timeRemaining:()=>Math.max(0,50-(Date.now()-startTime))})},options?.timeout??20)});var delay={by:duration=>new Promise(resolve=>setTimeout(resolve,(0,import_parse_duration.parseDuration)(duration))),animationFrame:()=>new Promise(resolve=>requestAnimationFrame(resolve)),idleCallback:options=>new Promise(resolve=>requestIdleCallback(resolve,options)),domEvent:(element,eventName,options={passive:true})=>new Promise(resolve=>element.addEventListener(eventName,resolve,{...options,once:true})),event:(target,eventName,options={passive:true})=>new Promise(resolve=>target.addEventListener(eventName,resolve,{...options,once:true})),nextMacrotask:()=>new Promise(resolve=>setTimeout(resolve,0)),nextMicrotask:()=>Promise.resolve().then(()=>{})};0&&(module.exports={delay,requestAnimationFrame,requestIdleCallback});
4
4
  //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts", "../src/polyfill.ts"],
4
- "sourcesContent": ["import {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\nexport {requestAnimationFrame, requestIdleCallback};\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Pauses execution for a specified duration.\n *\n * @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.\n * @returns A Promise that resolves after the specified duration.\n *\n * @example\n * ```typescript\n * await delay.by('1m'); // Wait for 1 minute\n * await delay.by('2s'); // Wait for 2 seconds\n * ```\n */\n by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Pauses execution until the next animation frame.\n *\n * @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.animationFrame();\n * console.log(`Next frame at ${timestamp}`);\n * ```\n */\n animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Pauses execution until the browser is idle.\n *\n * @param timeout An optional maximum duration to wait.\n * @returns A Promise that resolves with an `IdleDeadline` object.\n *\n * @example\n * ```typescript\n * const deadline = await delay.idleCallback({ timeout: 2000 });\n * if (deadline.didTimeout) {\n * console.log('Idle callback timed out.');\n * }\n * ```\n */\n idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),\n\n /**\n * Pauses execution until a specific DOM event is dispatched on an element.\n *\n * @param element The HTMLElement to listen on.\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @template T The event map type for the element.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const button = document.getElementById('my-button');\n * if (button) {\n * const clickEvent = await delay.domEvent(button, 'click');\n * console.log('Button clicked!', clickEvent);\n * }\n * ```\n */\n domEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T,\n options: AddEventListenerOptions = {passive: true},\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Pauses execution until a specific event is dispatched on any event target.\n *\n * @param target The event target (e.g., window, document, or a custom event emitter).\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const resizeEvent = await delay.event(window, 'resize');\n * console.log('Window resized:', resizeEvent);\n * ```\n */\n event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Schedules a macrotask to run after the current event loop task completes.\n * Uses `setTimeout(..., 0)`.\n *\n * @returns A Promise that resolves when the macrotask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMacrotask();\n * console.log('End - after current task');\n * ```\n */\n nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),\n\n /**\n * Queues a microtask to run after the current task completes but before the next macrotask.\n *\n * @returns A Promise that resolves when the microtask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMicrotask();\n * console.log('End - immediately after current task');\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),\n} as const;\n", "import {getGlobalThis} from '@alwatr/global-this';\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"],
5
- "mappings": ";;qqBAAA,6NAA2C,kCCA3C,uBAA4B,+BAE5B,IAAM,cAAa,kCAAsC,EAUlD,IAAM,sBACX,WAAW,uBAAuB,KAAK,UAAU,IAC/C,UAAmC,WAAW,IAAM,SAAS,YAAY,IAAI,CAAC,EAAG,IAAO,EAAE,GAavF,IAAM,oBACX,WAAW,qBAAqB,KAAK,UAAU,IAC9C,CACC,SAGA,UACG,CACH,MAAM,UAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,SAAS,CACP,WAAY,CAAC,CAAC,SAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,UAAU,CAChE,CAAC,CACH,EAAG,SAAS,SAAW,EAAE,CAC3B,GDjCK,IAAM,MAAQ,CAanB,GAAK,UAAsC,IAAI,QAAS,SAAY,WAAW,WAAS,qCAAc,QAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAS,SAAY,sBAAsB,OAAO,CAAC,EAgB3G,aAAe,SAAwD,IAAI,QAAS,SAAY,oBAAoB,QAAS,OAAO,CAAC,EAoBrI,SAAU,CACR,QACA,UACA,QAAmC,CAAC,QAAS,IAAI,IAEjD,IAAI,QAAS,SACX,QAAQ,iBAAiB,UAAW,QAAS,CAC3C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAgBF,MAAO,CAAC,OAAqB,UAAmB,QAAmC,CAAC,QAAS,IAAI,IAC/F,IAAI,QAAS,SACX,OAAO,iBAAiB,UAAW,QAAS,CAC1C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAS,SAAY,WAAW,QAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,QAAQ,QAAQ,EAAE,KAAK,IAAM,CAAC,CAAC,CACrE",
4
+ "sourcesContent": ["import {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\nexport {requestAnimationFrame, requestIdleCallback};\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Pauses execution for a specified duration.\n *\n * @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.\n * @returns A Promise that resolves after the specified duration.\n *\n * @example\n * ```typescript\n * await delay.by('1m'); // Wait for 1 minute\n * await delay.by('2s'); // Wait for 2 seconds\n * ```\n */\n by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Pauses execution until the next animation frame.\n *\n * @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.animationFrame();\n * console.log(`Next frame at ${timestamp}`);\n * ```\n */\n animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Pauses execution until the browser is idle.\n *\n * @param timeout An optional maximum duration to wait.\n * @returns A Promise that resolves with an `IdleDeadline` object.\n *\n * @example\n * ```typescript\n * const deadline = await delay.idleCallback({ timeout: 2000 });\n * if (deadline.didTimeout) {\n * console.log('Idle callback timed out.');\n * }\n * ```\n */\n idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),\n\n /**\n * Pauses execution until a specific DOM event is dispatched on an element.\n *\n * @param element The HTMLElement to listen on.\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @template T The event map type for the element.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const button = document.getElementById('my-button');\n * if (button) {\n * const clickEvent = await delay.domEvent(button, 'click');\n * console.log('Button clicked!', clickEvent);\n * }\n * ```\n */\n domEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T,\n options: AddEventListenerOptions = {passive: true},\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Pauses execution until a specific event is dispatched on any event target.\n *\n * @param target The event target (e.g., window, document, or a custom event emitter).\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const resizeEvent = await delay.event(window, 'resize');\n * console.log('Window resized:', resizeEvent);\n * ```\n */\n event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Schedules a macrotask to run after the current event loop task completes.\n * Uses `setTimeout(..., 0)`.\n *\n * @returns A Promise that resolves when the macrotask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMacrotask();\n * console.log('End - after current task');\n * ```\n */\n nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),\n\n /**\n * Queues a microtask to run after the current task completes but before the next macrotask.\n *\n * @returns A Promise that resolves when the microtask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMicrotask();\n * console.log('End - immediately after current task');\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),\n} as const;\n", "import {getGlobalThis} from '@alwatr/global-this';\n\nimport type {} from '@alwatr/type-helper';\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"],
5
+ "mappings": ";;qqBAAA,6NAA2C,kCCA3C,uBAA4B,+BAI5B,IAAM,cAAa,kCAAsC,EAUlD,IAAM,sBACX,WAAW,uBAAuB,KAAK,UAAU,IAC/C,UAAmC,WAAW,IAAM,SAAS,YAAY,IAAI,CAAC,EAAG,IAAO,EAAE,GAavF,IAAM,oBACX,WAAW,qBAAqB,KAAK,UAAU,IAC9C,CACC,SAGA,UACG,CACH,MAAM,UAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,SAAS,CACP,WAAY,CAAC,CAAC,SAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,UAAU,CAChE,CAAC,CACH,EAAG,SAAS,SAAW,EAAE,CAC3B,GDnCK,IAAM,MAAQ,CAanB,GAAK,UAAsC,IAAI,QAAS,SAAY,WAAW,WAAS,qCAAc,QAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAS,SAAY,sBAAsB,OAAO,CAAC,EAgB3G,aAAe,SAAwD,IAAI,QAAS,SAAY,oBAAoB,QAAS,OAAO,CAAC,EAoBrI,SAAU,CACR,QACA,UACA,QAAmC,CAAC,QAAS,IAAI,IAEjD,IAAI,QAAS,SACX,QAAQ,iBAAiB,UAAW,QAAS,CAC3C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAgBF,MAAO,CAAC,OAAqB,UAAmB,QAAmC,CAAC,QAAS,IAAI,IAC/F,IAAI,QAAS,SACX,OAAO,iBAAiB,UAAW,QAAS,CAC1C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAS,SAAY,WAAW,QAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,QAAQ,QAAQ,EAAE,KAAK,IAAM,CAAC,CAAC,CACrE",
6
6
  "names": []
7
7
  }
package/dist/main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /** 📦 @alwatr/delay v6.0.15 */
2
- __dev_mode__: console.debug("📦 @alwatr/delay v6.0.15");
1
+ /** 📦 @alwatr/delay v6.0.17 */
2
+ __dev_mode__: console.debug("📦 @alwatr/delay v6.0.17");
3
3
  import{parseDuration}from"@alwatr/parse-duration";import{getGlobalThis}from"@alwatr/global-this";var globalThis=getGlobalThis();var requestAnimationFrame=globalThis.requestAnimationFrame?.bind(globalThis)??(callback=>setTimeout(()=>callback(performance.now()),1e3/60));var requestIdleCallback=globalThis.requestIdleCallback?.bind(globalThis)??((callback,options)=>{const startTime=Date.now();return setTimeout(()=>{callback({didTimeout:!!options?.timeout,timeRemaining:()=>Math.max(0,50-(Date.now()-startTime))})},options?.timeout??20)});var delay={by:duration=>new Promise(resolve=>setTimeout(resolve,parseDuration(duration))),animationFrame:()=>new Promise(resolve=>requestAnimationFrame(resolve)),idleCallback:options=>new Promise(resolve=>requestIdleCallback(resolve,options)),domEvent:(element,eventName,options={passive:true})=>new Promise(resolve=>element.addEventListener(eventName,resolve,{...options,once:true})),event:(target,eventName,options={passive:true})=>new Promise(resolve=>target.addEventListener(eventName,resolve,{...options,once:true})),nextMacrotask:()=>new Promise(resolve=>setTimeout(resolve,0)),nextMicrotask:()=>Promise.resolve().then(()=>{})};export{delay,requestAnimationFrame,requestIdleCallback};
4
4
  //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts", "../src/polyfill.ts"],
4
- "sourcesContent": ["import {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\nexport {requestAnimationFrame, requestIdleCallback};\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Pauses execution for a specified duration.\n *\n * @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.\n * @returns A Promise that resolves after the specified duration.\n *\n * @example\n * ```typescript\n * await delay.by('1m'); // Wait for 1 minute\n * await delay.by('2s'); // Wait for 2 seconds\n * ```\n */\n by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Pauses execution until the next animation frame.\n *\n * @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.animationFrame();\n * console.log(`Next frame at ${timestamp}`);\n * ```\n */\n animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Pauses execution until the browser is idle.\n *\n * @param timeout An optional maximum duration to wait.\n * @returns A Promise that resolves with an `IdleDeadline` object.\n *\n * @example\n * ```typescript\n * const deadline = await delay.idleCallback({ timeout: 2000 });\n * if (deadline.didTimeout) {\n * console.log('Idle callback timed out.');\n * }\n * ```\n */\n idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),\n\n /**\n * Pauses execution until a specific DOM event is dispatched on an element.\n *\n * @param element The HTMLElement to listen on.\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @template T The event map type for the element.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const button = document.getElementById('my-button');\n * if (button) {\n * const clickEvent = await delay.domEvent(button, 'click');\n * console.log('Button clicked!', clickEvent);\n * }\n * ```\n */\n domEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T,\n options: AddEventListenerOptions = {passive: true},\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Pauses execution until a specific event is dispatched on any event target.\n *\n * @param target The event target (e.g., window, document, or a custom event emitter).\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const resizeEvent = await delay.event(window, 'resize');\n * console.log('Window resized:', resizeEvent);\n * ```\n */\n event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Schedules a macrotask to run after the current event loop task completes.\n * Uses `setTimeout(..., 0)`.\n *\n * @returns A Promise that resolves when the macrotask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMacrotask();\n * console.log('End - after current task');\n * ```\n */\n nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),\n\n /**\n * Queues a microtask to run after the current task completes but before the next macrotask.\n *\n * @returns A Promise that resolves when the microtask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMicrotask();\n * console.log('End - immediately after current task');\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),\n} as const;\n", "import {getGlobalThis} from '@alwatr/global-this';\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"],
5
- "mappings": ";;AAAA,OAAQ,kBAAmC,yBCA3C,OAAQ,kBAAoB,sBAE5B,IAAM,WAAa,cAAsC,EAUlD,IAAM,sBACX,WAAW,uBAAuB,KAAK,UAAU,IAC/C,UAAmC,WAAW,IAAM,SAAS,YAAY,IAAI,CAAC,EAAG,IAAO,EAAE,GAavF,IAAM,oBACX,WAAW,qBAAqB,KAAK,UAAU,IAC9C,CACC,SAGA,UACG,CACH,MAAM,UAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,SAAS,CACP,WAAY,CAAC,CAAC,SAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,UAAU,CAChE,CAAC,CACH,EAAG,SAAS,SAAW,EAAE,CAC3B,GDjCK,IAAM,MAAQ,CAanB,GAAK,UAAsC,IAAI,QAAS,SAAY,WAAW,QAAS,cAAc,QAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAS,SAAY,sBAAsB,OAAO,CAAC,EAgB3G,aAAe,SAAwD,IAAI,QAAS,SAAY,oBAAoB,QAAS,OAAO,CAAC,EAoBrI,SAAU,CACR,QACA,UACA,QAAmC,CAAC,QAAS,IAAI,IAEjD,IAAI,QAAS,SACX,QAAQ,iBAAiB,UAAW,QAAS,CAC3C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAgBF,MAAO,CAAC,OAAqB,UAAmB,QAAmC,CAAC,QAAS,IAAI,IAC/F,IAAI,QAAS,SACX,OAAO,iBAAiB,UAAW,QAAS,CAC1C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAS,SAAY,WAAW,QAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,QAAQ,QAAQ,EAAE,KAAK,IAAM,CAAC,CAAC,CACrE",
4
+ "sourcesContent": ["import {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\nexport {requestAnimationFrame, requestIdleCallback};\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Pauses execution for a specified duration.\n *\n * @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.\n * @returns A Promise that resolves after the specified duration.\n *\n * @example\n * ```typescript\n * await delay.by('1m'); // Wait for 1 minute\n * await delay.by('2s'); // Wait for 2 seconds\n * ```\n */\n by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Pauses execution until the next animation frame.\n *\n * @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.animationFrame();\n * console.log(`Next frame at ${timestamp}`);\n * ```\n */\n animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Pauses execution until the browser is idle.\n *\n * @param timeout An optional maximum duration to wait.\n * @returns A Promise that resolves with an `IdleDeadline` object.\n *\n * @example\n * ```typescript\n * const deadline = await delay.idleCallback({ timeout: 2000 });\n * if (deadline.didTimeout) {\n * console.log('Idle callback timed out.');\n * }\n * ```\n */\n idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),\n\n /**\n * Pauses execution until a specific DOM event is dispatched on an element.\n *\n * @param element The HTMLElement to listen on.\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @template T The event map type for the element.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const button = document.getElementById('my-button');\n * if (button) {\n * const clickEvent = await delay.domEvent(button, 'click');\n * console.log('Button clicked!', clickEvent);\n * }\n * ```\n */\n domEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T,\n options: AddEventListenerOptions = {passive: true},\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Pauses execution until a specific event is dispatched on any event target.\n *\n * @param target The event target (e.g., window, document, or a custom event emitter).\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const resizeEvent = await delay.event(window, 'resize');\n * console.log('Window resized:', resizeEvent);\n * ```\n */\n event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Schedules a macrotask to run after the current event loop task completes.\n * Uses `setTimeout(..., 0)`.\n *\n * @returns A Promise that resolves when the macrotask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMacrotask();\n * console.log('End - after current task');\n * ```\n */\n nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),\n\n /**\n * Queues a microtask to run after the current task completes but before the next macrotask.\n *\n * @returns A Promise that resolves when the microtask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMicrotask();\n * console.log('End - immediately after current task');\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),\n} as const;\n", "import {getGlobalThis} from '@alwatr/global-this';\n\nimport type {} from '@alwatr/type-helper';\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"],
5
+ "mappings": ";;AAAA,OAAQ,kBAAmC,yBCA3C,OAAQ,kBAAoB,sBAI5B,IAAM,WAAa,cAAsC,EAUlD,IAAM,sBACX,WAAW,uBAAuB,KAAK,UAAU,IAC/C,UAAmC,WAAW,IAAM,SAAS,YAAY,IAAI,CAAC,EAAG,IAAO,EAAE,GAavF,IAAM,oBACX,WAAW,qBAAqB,KAAK,UAAU,IAC9C,CACC,SAGA,UACG,CACH,MAAM,UAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,SAAS,CACP,WAAY,CAAC,CAAC,SAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,UAAU,CAChE,CAAC,CACH,EAAG,SAAS,SAAW,EAAE,CAC3B,GDnCK,IAAM,MAAQ,CAanB,GAAK,UAAsC,IAAI,QAAS,SAAY,WAAW,QAAS,cAAc,QAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAS,SAAY,sBAAsB,OAAO,CAAC,EAgB3G,aAAe,SAAwD,IAAI,QAAS,SAAY,oBAAoB,QAAS,OAAO,CAAC,EAoBrI,SAAU,CACR,QACA,UACA,QAAmC,CAAC,QAAS,IAAI,IAEjD,IAAI,QAAS,SACX,QAAQ,iBAAiB,UAAW,QAAS,CAC3C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAgBF,MAAO,CAAC,OAAqB,UAAmB,QAAmC,CAAC,QAAS,IAAI,IAC/F,IAAI,QAAS,SACX,OAAO,iBAAiB,UAAW,QAAS,CAC1C,GAAG,QACH,KAAM,IACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAS,SAAY,WAAW,QAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,QAAQ,QAAQ,EAAE,KAAK,IAAM,CAAC,CAAC,CACrE",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,MAEwB,CAAC;AAEjG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,MAe5G,CAAC"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,MAEwB,CAAC;AAEjG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,MAe5G,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@alwatr/delay",
3
3
  "description": "Comprehensive toolkit for managing asynchronous operations.",
4
- "version": "6.0.15",
4
+ "version": "6.0.17",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "dependencies": {
8
- "@alwatr/global-this": "5.6.4",
9
- "@alwatr/parse-duration": "5.5.24"
8
+ "@alwatr/global-this": "5.6.6",
9
+ "@alwatr/parse-duration": "5.5.26"
10
10
  },
11
11
  "devDependencies": {
12
- "@alwatr/nano-build": "6.3.8",
13
- "@alwatr/prettier-config": "5.0.5",
14
- "@alwatr/tsconfig-base": "6.0.3",
15
- "@alwatr/type-helper": "6.1.6",
16
- "@types/node": "^24.10.1",
12
+ "@alwatr/nano-build": "6.3.10",
13
+ "@alwatr/prettier-config": "6.0.1",
14
+ "@alwatr/tsconfig-base": "6.0.4",
15
+ "@alwatr/type-helper": "6.1.8",
16
+ "@types/node": "^24.10.2",
17
17
  "typescript": "^5.9.3"
18
18
  },
19
19
  "exports": {
@@ -78,5 +78,5 @@
78
78
  "sideEffects": false,
79
79
  "type": "module",
80
80
  "types": "./dist/main.d.ts",
81
- "gitHead": "0368e2b199bb5c1b443a18b28566cd53ce6915ce"
81
+ "gitHead": "d4edc8bf4a48fc84e01cd2625ce840f906bff27d"
82
82
  }