@alwatr/delay 5.5.0 → 5.5.2

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
+ ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.1...@alwatr/delay@5.5.2) (2025-04-01)
7
+
8
+ ### Dependencies update
9
+
10
+ * bump the development-dependencies group across 1 directory with 2 updates ([c1320b4](https://github.com/Alwatr/nanolib/commit/c1320b447a492c5e720e25ad71e9df81eeea3670)) by @dependabot[bot]
11
+
12
+ ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.0...@alwatr/delay@5.5.1) (2025-03-18)
13
+
14
+ ### Bug Fixes
15
+
16
+ * **delay:** specify type for getGlobalThis in polyfill.ts ([57fa717](https://github.com/Alwatr/nanolib/commit/57fa7173f6b040f7d4e536ecb18cf41fbaf218ea)) by @alimd
17
+
18
+ ### Dependencies update
19
+
20
+ * bump the development-dependencies group with 9 updates ([7290aa3](https://github.com/Alwatr/nanolib/commit/7290aa3b52ce66ca237d2a12d28a7687b113f83d)) by @dependabot[bot]
21
+
6
22
  ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.4.0...@alwatr/delay@5.5.0) (2025-03-06)
7
23
 
8
24
  ### Miscellaneous Chores
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/delay v5.5.0 */
1
+ /* @alwatr/delay v5.5.2 */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -36,7 +36,7 @@ var requestIdleCallbackFallback = (callback, options) => setTimeout(callback, op
36
36
  var requestIdleCallback = /* @__PURE__ */ (() => win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();
37
37
 
38
38
  // src/main.ts
39
- __dev_mode__: import_package_tracer.packageTracer.add("@alwatr/delay", "5.5.0");
39
+ __dev_mode__: import_package_tracer.packageTracer.add("@alwatr/delay", "5.5.2");
40
40
  var delay = {
41
41
  /**
42
42
  * Delays execution for a specified duration (in milliseconds).
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 {packageTracer} from '@alwatr/package-tracer';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Delays execution for a specified duration (in milliseconds).\n *\n * @param duration - The duration to wait (in milliseconds). Use `0` to yield control to the event loop.\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 * ```\n */\n by: (duration: Duration): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Delays execution until the next animation frame.\n *\n * @returns A Promise that resolves with the current timestamp when the next animation frame is fired.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.untilNextAnimationFrame();\n * ```\n */\n untilNextAnimationFrame: (): Promise<DOMHighResTimeStamp> =>\n new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Delays execution until the browser's idle period or the specified timeout.\n *\n * @param timeout - Optional timeout (in milliseconds) for the idle callback.\n * @returns A Promise that resolves with the IdleDeadline object when the browser is idle or the timeout is reached.\n *\n * @example\n * ```typescript\n * const deadline = await delay.untilIdle();\n * ```\n */\n untilIdle: (timeout?: Duration): Promise<IdleDeadline> =>\n new Promise((resolve) => requestIdleCallback(resolve, timeout === undefined ? undefined : {\n timeout: parseDuration(timeout)\n })),\n\n /**\n * Delays execution until a specific DOM event occurs on an HTMLElement.\n *\n * @param element - The HTMLElement to listen for the event on.\n * @param eventName - The name of the DOM event to wait for.\n * @template T The event map type.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const clickEvent = await delay.untilDomEvent(document.body, 'click');\n * ```\n */\n untilDomEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Delays execution until a specific event occurs on an object with an `addEventListener` method.\n *\n * @param target - The target object to listen for the event on.\n * @param eventName - The name of the event to wait for.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const server = http.createServer();\n * const requestEvent = await delay.untilEvent(server, 'request');\n * ```\n */\n untilEvent: (target: HasAddEventListener, eventName: string): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Yields control to the event loop immediately.\n *\n * Uses `setImmediate` if available, falls back to `queueMicrotask`, and then to `setTimeout(0)`.\n *\n * @returns A Promise that resolves immediately after yielding control to the event loop.\n *\n * @example\n * ```typescript\n * await delay.immediate();\n * ```\n */\n immediate: (): Promise<void> => {\n if (typeof setImmediate !== 'function') {\n if (typeof queueMicrotask === 'function') {\n return delay.nextMicrotask();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => setImmediate(resolve));\n },\n\n /**\n * Delays execution until the next microtask queue is empty\n *\n * @returns A Promise that resolves when the next microtask queue is empty.\n *\n * @example\n * ```typescript\n * await delay.nextMicrotask();\n * ```\n */\n nextMicrotask: (): Promise<void> => {\n if (typeof queueMicrotask !== 'function') {\n if (typeof setImmediate === 'function') {\n return delay.immediate();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => queueMicrotask(resolve));\n },\n} as const;\n", "import {getGlobalThis, type GlobalThis} from '@alwatr/global-this';\n\nexport const win = /* #__PURE__ */ getGlobalThis();\n\n// prettier-ignore\nconst requestAnimationFrameFallback =\n (callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>\n setTimeout(() => callback(Date.now()), 1000 / 60);\n\nexport const requestAnimationFrame: GlobalThis['requestAnimationFrame'] = /* #__PURE__ */ (() =>\n win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || requestAnimationFrameFallback)();\n\n// prettier-ignore\nconst requestIdleCallbackFallback =\n (callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>\n setTimeout(callback, options?.timeout ?? 2000);\n\nexport const requestIdleCallback: GlobalThis['requestIdleCallback'] = /* #__PURE__ */ (() =>\n win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAC5B,4BAA2C;;;ACD3C,yBAA6C;AAEtC,IAAM,MAAsB,sDAAc;AAGjD,IAAM,gCACJ,CAAC,aACC,WAAW,MAAM,SAAS,KAAK,IAAI,CAAC,GAAG,MAAO,EAAE;AAE7C,IAAM,wBAA8E,uBACzF,IAAI,yBAAyB,IAAI,+BAA+B,IAAI,4BAA4B,+BAA+B;AAGjI,IAAM,8BACJ,CAAC,UAAsB,YACrB,WAAW,UAAU,SAAS,WAAW,GAAI;AAE1C,IAAM,sBAA0E,uBACrF,IAAI,uBAAuB,IAAI,6BAA6B,IAAI,0BAA0B,6BAA6B;;;ADfzH,aAAc,qCAAc,IAAI,iBAAkB,OAAmB;AAO9D,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYnB,IAAI,CAAC,aACH,IAAI,QAAQ,CAAC,YAAY,WAAW,aAAS,qCAAc,QAAQ,CAAC,CAA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BAAiB,YAAY;AACtC,eAAO,MAAM,UAAU;AAAA,MACzB;AAGA,aAAO,MAAM,GAAG,CAAC;AAAA,IACnB;AACA,WAAO,IAAI,QAAQ,CAAC,YAAY,eAAe,OAAO,CAAC;AAAA,EACzD;AACF;",
4
+ "sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Delays execution for a specified duration (in milliseconds).\n *\n * @param duration - The duration to wait (in milliseconds). Use `0` to yield control to the event loop.\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 * ```\n */\n by: (duration: Duration): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Delays execution until the next animation frame.\n *\n * @returns A Promise that resolves with the current timestamp when the next animation frame is fired.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.untilNextAnimationFrame();\n * ```\n */\n untilNextAnimationFrame: (): Promise<DOMHighResTimeStamp> =>\n new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Delays execution until the browser's idle period or the specified timeout.\n *\n * @param timeout - Optional timeout (in milliseconds) for the idle callback.\n * @returns A Promise that resolves with the IdleDeadline object when the browser is idle or the timeout is reached.\n *\n * @example\n * ```typescript\n * const deadline = await delay.untilIdle();\n * ```\n */\n untilIdle: (timeout?: Duration): Promise<IdleDeadline> =>\n new Promise((resolve) => requestIdleCallback(resolve, timeout === undefined ? undefined : {\n timeout: parseDuration(timeout)\n })),\n\n /**\n * Delays execution until a specific DOM event occurs on an HTMLElement.\n *\n * @param element - The HTMLElement to listen for the event on.\n * @param eventName - The name of the DOM event to wait for.\n * @template T The event map type.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const clickEvent = await delay.untilDomEvent(document.body, 'click');\n * ```\n */\n untilDomEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Delays execution until a specific event occurs on an object with an `addEventListener` method.\n *\n * @param target - The target object to listen for the event on.\n * @param eventName - The name of the event to wait for.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const server = http.createServer();\n * const requestEvent = await delay.untilEvent(server, 'request');\n * ```\n */\n untilEvent: (target: HasAddEventListener, eventName: string): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Yields control to the event loop immediately.\n *\n * Uses `setImmediate` if available, falls back to `queueMicrotask`, and then to `setTimeout(0)`.\n *\n * @returns A Promise that resolves immediately after yielding control to the event loop.\n *\n * @example\n * ```typescript\n * await delay.immediate();\n * ```\n */\n immediate: (): Promise<void> => {\n if (typeof setImmediate !== 'function') {\n if (typeof queueMicrotask === 'function') {\n return delay.nextMicrotask();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => setImmediate(resolve));\n },\n\n /**\n * Delays execution until the next microtask queue is empty\n *\n * @returns A Promise that resolves when the next microtask queue is empty.\n *\n * @example\n * ```typescript\n * await delay.nextMicrotask();\n * ```\n */\n nextMicrotask: (): Promise<void> => {\n if (typeof queueMicrotask !== 'function') {\n if (typeof setImmediate === 'function') {\n return delay.immediate();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => queueMicrotask(resolve));\n },\n} as const;\n", "import {getGlobalThis, type GlobalThis} from '@alwatr/global-this';\n\nexport const win = /* #__PURE__ */ getGlobalThis<DictionaryOpt<unknown>>();\n\n// prettier-ignore\nconst requestAnimationFrameFallback =\n (callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>\n setTimeout(() => callback(Date.now()), 1000 / 60);\n\nexport const requestAnimationFrame: GlobalThis['requestAnimationFrame'] = /* #__PURE__ */ (() =>\n win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || requestAnimationFrameFallback)();\n\n// prettier-ignore\nconst requestIdleCallbackFallback =\n (callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>\n setTimeout(callback, options?.timeout ?? 2000);\n\nexport const requestIdleCallback: GlobalThis['requestIdleCallback'] = /* #__PURE__ */ (() =>\n win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAC5B,4BAA2C;;;ACD3C,yBAA6C;AAEtC,IAAM,MAAsB,sDAAsC;AAGzE,IAAM,gCACJ,CAAC,aACC,WAAW,MAAM,SAAS,KAAK,IAAI,CAAC,GAAG,MAAO,EAAE;AAE7C,IAAM,wBAA8E,uBACzF,IAAI,yBAAyB,IAAI,+BAA+B,IAAI,4BAA4B,+BAA+B;AAGjI,IAAM,8BACJ,CAAC,UAAsB,YACrB,WAAW,UAAU,SAAS,WAAW,GAAI;AAE1C,IAAM,sBAA0E,uBACrF,IAAI,uBAAuB,IAAI,6BAA6B,IAAI,0BAA0B,6BAA6B;;;ADfzH,aAAc,qCAAc,IAAI,iBAAkB,OAAmB;AAO9D,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYnB,IAAI,CAAC,aACH,IAAI,QAAQ,CAAC,YAAY,WAAW,aAAS,qCAAc,QAAQ,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYvE,yBAAyB,MACvB,IAAI,QAAQ,CAAC,YAAY,sBAAsB,OAAO,CAAC;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AO,CAAC;AAAA,EACzD;AACF;",
6
6
  "names": []
7
7
  }
package/dist/main.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @alwatr/delay v5.5.0 */
1
+ /* @alwatr/delay v5.5.2 */
2
2
 
3
3
  // src/main.ts
4
4
  import { packageTracer } from "@alwatr/package-tracer";
@@ -13,7 +13,7 @@ var requestIdleCallbackFallback = (callback, options) => setTimeout(callback, op
13
13
  var requestIdleCallback = /* @__PURE__ */ (() => win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();
14
14
 
15
15
  // src/main.ts
16
- __dev_mode__: packageTracer.add("@alwatr/delay", "5.5.0");
16
+ __dev_mode__: packageTracer.add("@alwatr/delay", "5.5.2");
17
17
  var delay = {
18
18
  /**
19
19
  * Delays execution for a specified duration (in milliseconds).
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 {packageTracer} from '@alwatr/package-tracer';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Delays execution for a specified duration (in milliseconds).\n *\n * @param duration - The duration to wait (in milliseconds). Use `0` to yield control to the event loop.\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 * ```\n */\n by: (duration: Duration): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Delays execution until the next animation frame.\n *\n * @returns A Promise that resolves with the current timestamp when the next animation frame is fired.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.untilNextAnimationFrame();\n * ```\n */\n untilNextAnimationFrame: (): Promise<DOMHighResTimeStamp> =>\n new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Delays execution until the browser's idle period or the specified timeout.\n *\n * @param timeout - Optional timeout (in milliseconds) for the idle callback.\n * @returns A Promise that resolves with the IdleDeadline object when the browser is idle or the timeout is reached.\n *\n * @example\n * ```typescript\n * const deadline = await delay.untilIdle();\n * ```\n */\n untilIdle: (timeout?: Duration): Promise<IdleDeadline> =>\n new Promise((resolve) => requestIdleCallback(resolve, timeout === undefined ? undefined : {\n timeout: parseDuration(timeout)\n })),\n\n /**\n * Delays execution until a specific DOM event occurs on an HTMLElement.\n *\n * @param element - The HTMLElement to listen for the event on.\n * @param eventName - The name of the DOM event to wait for.\n * @template T The event map type.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const clickEvent = await delay.untilDomEvent(document.body, 'click');\n * ```\n */\n untilDomEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Delays execution until a specific event occurs on an object with an `addEventListener` method.\n *\n * @param target - The target object to listen for the event on.\n * @param eventName - The name of the event to wait for.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const server = http.createServer();\n * const requestEvent = await delay.untilEvent(server, 'request');\n * ```\n */\n untilEvent: (target: HasAddEventListener, eventName: string): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Yields control to the event loop immediately.\n *\n * Uses `setImmediate` if available, falls back to `queueMicrotask`, and then to `setTimeout(0)`.\n *\n * @returns A Promise that resolves immediately after yielding control to the event loop.\n *\n * @example\n * ```typescript\n * await delay.immediate();\n * ```\n */\n immediate: (): Promise<void> => {\n if (typeof setImmediate !== 'function') {\n if (typeof queueMicrotask === 'function') {\n return delay.nextMicrotask();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => setImmediate(resolve));\n },\n\n /**\n * Delays execution until the next microtask queue is empty\n *\n * @returns A Promise that resolves when the next microtask queue is empty.\n *\n * @example\n * ```typescript\n * await delay.nextMicrotask();\n * ```\n */\n nextMicrotask: (): Promise<void> => {\n if (typeof queueMicrotask !== 'function') {\n if (typeof setImmediate === 'function') {\n return delay.immediate();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => queueMicrotask(resolve));\n },\n} as const;\n", "import {getGlobalThis, type GlobalThis} from '@alwatr/global-this';\n\nexport const win = /* #__PURE__ */ getGlobalThis();\n\n// prettier-ignore\nconst requestAnimationFrameFallback =\n (callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>\n setTimeout(() => callback(Date.now()), 1000 / 60);\n\nexport const requestAnimationFrame: GlobalThis['requestAnimationFrame'] = /* #__PURE__ */ (() =>\n win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || requestAnimationFrameFallback)();\n\n// prettier-ignore\nconst requestIdleCallbackFallback =\n (callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>\n setTimeout(callback, options?.timeout ?? 2000);\n\nexport const requestIdleCallback: GlobalThis['requestIdleCallback'] = /* #__PURE__ */ (() =>\n win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();\n"],
5
- "mappings": ";;;AAAA,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAmC;;;ACD3C,SAAQ,qBAAqC;AAEtC,IAAM,MAAsB,8BAAc;AAGjD,IAAM,gCACJ,CAAC,aACC,WAAW,MAAM,SAAS,KAAK,IAAI,CAAC,GAAG,MAAO,EAAE;AAE7C,IAAM,wBAA8E,uBACzF,IAAI,yBAAyB,IAAI,+BAA+B,IAAI,4BAA4B,+BAA+B;AAGjI,IAAM,8BACJ,CAAC,UAAsB,YACrB,WAAW,UAAU,SAAS,WAAW,GAAI;AAE1C,IAAM,sBAA0E,uBACrF,I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AAM,cAAc;AAAA,MAC7B;AAGA,aAAO,MAAM,GAAG,CAAC;AAAA,IACnB;AACA,WAAO,IAAI,QAAQ,CAAC,YAAY,aAAa,OAAO,CAAC;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,eAAe,MAAqB;AAClC,QAAI,OAAO,mBAAmB,YAAY;AACxC,UAAI,OAAO,iBAAiB,YAAY;AACtC,eAAO,MAAM,UAAU;AAAA,MACzB;AAGA,aAAO,MAAM,GAAG,CAAC;AAAA,IACnB;AACA,WAAO,IAAI,QAAQ,CAAC,YAAY,eAAe,OAAO,CAAC;AAAA,EACzD;AACF;",
4
+ "sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Delays execution for a specified duration (in milliseconds).\n *\n * @param duration - The duration to wait (in milliseconds). Use `0` to yield control to the event loop.\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 * ```\n */\n by: (duration: Duration): Promise<void> =>\n new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Delays execution until the next animation frame.\n *\n * @returns A Promise that resolves with the current timestamp when the next animation frame is fired.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.untilNextAnimationFrame();\n * ```\n */\n untilNextAnimationFrame: (): Promise<DOMHighResTimeStamp> =>\n new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Delays execution until the browser's idle period or the specified timeout.\n *\n * @param timeout - Optional timeout (in milliseconds) for the idle callback.\n * @returns A Promise that resolves with the IdleDeadline object when the browser is idle or the timeout is reached.\n *\n * @example\n * ```typescript\n * const deadline = await delay.untilIdle();\n * ```\n */\n untilIdle: (timeout?: Duration): Promise<IdleDeadline> =>\n new Promise((resolve) => requestIdleCallback(resolve, timeout === undefined ? undefined : {\n timeout: parseDuration(timeout)\n })),\n\n /**\n * Delays execution until a specific DOM event occurs on an HTMLElement.\n *\n * @param element - The HTMLElement to listen for the event on.\n * @param eventName - The name of the DOM event to wait for.\n * @template T The event map type.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const clickEvent = await delay.untilDomEvent(document.body, 'click');\n * ```\n */\n untilDomEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Delays execution until a specific event occurs on an object with an `addEventListener` method.\n *\n * @param target - The target object to listen for the event on.\n * @param eventName - The name of the event to wait for.\n * @returns A Promise that resolves with the event object when the specified event occurs.\n *\n * @example\n * ```typescript\n * const server = http.createServer();\n * const requestEvent = await delay.untilEvent(server, 'request');\n * ```\n */\n untilEvent: (target: HasAddEventListener, eventName: string): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, { once: true, passive: true })\n ),\n\n /**\n * Yields control to the event loop immediately.\n *\n * Uses `setImmediate` if available, falls back to `queueMicrotask`, and then to `setTimeout(0)`.\n *\n * @returns A Promise that resolves immediately after yielding control to the event loop.\n *\n * @example\n * ```typescript\n * await delay.immediate();\n * ```\n */\n immediate: (): Promise<void> => {\n if (typeof setImmediate !== 'function') {\n if (typeof queueMicrotask === 'function') {\n return delay.nextMicrotask();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => setImmediate(resolve));\n },\n\n /**\n * Delays execution until the next microtask queue is empty\n *\n * @returns A Promise that resolves when the next microtask queue is empty.\n *\n * @example\n * ```typescript\n * await delay.nextMicrotask();\n * ```\n */\n nextMicrotask: (): Promise<void> => {\n if (typeof queueMicrotask !== 'function') {\n if (typeof setImmediate === 'function') {\n return delay.immediate();\n }\n\n // else\n return delay.by(0);\n }\n return new Promise((resolve) => queueMicrotask(resolve));\n },\n} as const;\n", "import {getGlobalThis, type GlobalThis} from '@alwatr/global-this';\n\nexport const win = /* #__PURE__ */ getGlobalThis<DictionaryOpt<unknown>>();\n\n// prettier-ignore\nconst requestAnimationFrameFallback =\n (callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>\n setTimeout(() => callback(Date.now()), 1000 / 60);\n\nexport const requestAnimationFrame: GlobalThis['requestAnimationFrame'] = /* #__PURE__ */ (() =>\n win.requestAnimationFrame || win.webkitRequestAnimationFrame || win.mozRequestAnimationFrame || requestAnimationFrameFallback)();\n\n// prettier-ignore\nconst requestIdleCallbackFallback =\n (callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>\n setTimeout(callback, options?.timeout ?? 2000);\n\nexport const requestIdleCallback: GlobalThis['requestIdleCallback'] = /* #__PURE__ */ (() =>\n win.requestIdleCallback || win.webkitRequestIdleCallback || win.mozRequestIdleCallback || requestIdleCallbackFallback)();\n"],
5
+ "mappings": ";;;AAAA,SAAQ,qBAAoB;AAC5B,SAAQ,qBAAmC;;;ACD3C,SAAQ,qBAAqC;AAEtC,IAAM,MAAsB,8BAAsC;AAGzE,IAAM,gCACJ,CAAC,aACC,WAAW,MAAM,SAAS,KAAK,IAAI,CAAC,GAAG,MAAO,EAAE;AAE7C,IAAM,wBAA8E,uBACzF,IAAI,yBAAyB,IAAI,+BAA+B,IAAI,4BAA4B,+BAA+B;AAGjI,IAAM,8BACJ,CAAC,UAAsB,YACrB,WAAW,UAAU,SAAS,WAAW,GAAI;AAE1C,IAAM,sBAA0E,uBACrF,IAAI,uBAAuB,IAAI,6BAA6B,IAAI,0BAA0B,6BAA6B;;;ADfzH,aAAc,eAAc,IAAI,iBAAkB,OAAmB;AAO9D,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AAA;AAAA;AAAA;AAAA;AAAA,EAYA,eAAe,MAAqB;AAClC,QAAI,OAAO,mBAAmB,YAAY;AACxC,UAAI,OAAO,iBAAiB,YAAY;AACtC,eAAO,MAAM,UAAU;AAAA,MACzB;AAGA,aAAO,MAAM,GAAG,CAAC;AAAA,IACnB;AACA,WAAO,IAAI,QAAQ,CAAC,YAAY,eAAe,OAAO,CAAC;AAAA,EACzD;AACF;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAEnE,eAAO,MAAM,GAAG,4CAAkC,CAAC;AAOnD,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAAC,uBAAuB,CAC4D,CAAC;AAOnI,eAAO,MAAM,mBAAmB,EAAE,UAAU,CAAC,qBAAqB,CACwD,CAAC"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAEnE,eAAO,MAAM,GAAG,4CAA0D,CAAC;AAO3E,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAAC,uBAAuB,CAC4D,CAAC;AAOnI,eAAO,MAAM,mBAAmB,EAAE,UAAU,CAAC,qBAAqB,CACwD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/delay",
3
- "version": "5.5.0",
3
+ "version": "5.5.2",
4
4
  "description": "Comprehensive toolkit for managing asynchronous operations.",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "keywords": [
@@ -67,17 +67,17 @@
67
67
  "clean": "rm -rfv dist *.tsbuildinfo"
68
68
  },
69
69
  "dependencies": {
70
- "@alwatr/global-this": "^5.5.0",
71
- "@alwatr/package-tracer": "^5.5.0",
72
- "@alwatr/parse-duration": "^5.5.0"
70
+ "@alwatr/global-this": "^5.5.2",
71
+ "@alwatr/package-tracer": "^5.5.2",
72
+ "@alwatr/parse-duration": "^5.5.2"
73
73
  },
74
74
  "devDependencies": {
75
- "@alwatr/nano-build": "^5.5.0",
75
+ "@alwatr/nano-build": "^5.5.2",
76
76
  "@alwatr/prettier-config": "^5.0.0",
77
77
  "@alwatr/tsconfig-base": "^5.0.0",
78
78
  "@alwatr/type-helper": "^5.4.0",
79
- "@types/node": "^22.13.9",
79
+ "@types/node": "^22.13.13",
80
80
  "typescript": "^5.8.2"
81
81
  },
82
- "gitHead": "fdf8e6de77cca359465110a75ff18faff0649a95"
82
+ "gitHead": "2756475ba2fa108bae7af6d8d9747e0c7815dfa2"
83
83
  }