@alwatr/delay 6.0.21 → 7.0.0
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/dist/main.js +5 -0
- package/dist/main.js.map +11 -0
- package/package.json +13 -15
- package/src/main.ts +135 -0
- package/src/polyfill.ts +45 -0
- package/CHANGELOG.md +0 -488
- package/dist/main.cjs +0 -3
- package/dist/main.cjs.map +0 -7
- package/dist/main.mjs +0 -3
- package/dist/main.mjs.map +0 -7
package/dist/main.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* 📦 @alwatr/delay v7.0.0 */
|
|
2
|
+
import{parseDuration as O}from"@alwatr/parse-duration";import{getGlobalThis as M}from"@alwatr/global-this";var H=M(),K=H.requestAnimationFrame?.bind(H)??((z)=>setTimeout(()=>z(performance.now()),16.666666666666668)),L=H.requestIdleCallback?.bind(H)??((z,B)=>{let E=Date.now();return setTimeout(()=>{z({didTimeout:!!B?.timeout,timeRemaining:()=>Math.max(0,50-(Date.now()-E))})},B?.timeout??20)});var U={by:(z)=>new Promise((B)=>setTimeout(B,O(z))),animationFrame:()=>new Promise((z)=>K(z)),idleCallback:(z)=>new Promise((B)=>L(B,z)),domEvent:(z,B,E={passive:!0})=>new Promise((J)=>z.addEventListener(B,J,{...E,once:!0})),event:(z,B,E={passive:!0})=>new Promise((J)=>z.addEventListener(B,J,{...E,once:!0})),nextMacrotask:()=>new Promise((z)=>setTimeout(z,0)),nextMicrotask:()=>Promise.resolve().then(()=>{})};export{L as requestIdleCallback,K as requestAnimationFrame,U as delay};
|
|
3
|
+
|
|
4
|
+
//# debugId=1D85DC7FC1CE00E964756E2164756E21
|
|
5
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/main.ts", "../src/polyfill.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"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",
|
|
6
|
+
"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"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAAA,wBAAQ,+BCAR,wBAAQ,4BAIR,IAAM,EAAa,EAAsC,EAU5C,EACX,EAAW,uBAAuB,KAAK,CAAU,IAChD,CAAC,IAAmC,WAAW,IAAM,EAAS,YAAY,IAAI,CAAC,EAAG,kBAAS,GAajF,EACX,EAAW,qBAAqB,KAAK,CAAU,IAC9C,CACC,EAGA,IACG,CACH,IAAM,EAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,EAAS,CACP,WAAY,CAAC,CAAC,GAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,EAAU,CAChE,CAAC,GACA,GAAS,SAAW,EAAE,IDlCtB,IAAM,EAAQ,CAanB,GAAI,CAAC,IAAsC,IAAI,QAAQ,CAAC,IAAY,WAAW,EAAS,EAAc,CAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAQ,CAAC,IAAY,EAAsB,CAAO,CAAC,EAgB3G,aAAc,CAAC,IAAwD,IAAI,QAAQ,CAAC,IAAY,EAAoB,EAAS,CAAO,CAAC,EAoBrI,SAAU,CACR,EACA,EACA,EAAmC,CAAC,QAAS,EAAI,IAEjD,IAAI,QAAQ,CAAC,IACX,EAAQ,iBAAiB,EAAW,EAAS,IACxC,EACH,KAAM,EACR,CAAC,CACH,EAgBF,MAAO,CAAC,EAAqB,EAAmB,EAAmC,CAAC,QAAS,EAAI,IAC/F,IAAI,QAAQ,CAAC,IACX,EAAO,iBAAiB,EAAW,EAAS,IACvC,EACH,KAAM,EACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAQ,CAAC,IAAY,WAAW,EAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,QAAQ,QAAQ,EAAE,KAAK,IAAM,EAAE,CACrE",
|
|
9
|
+
"debugId": "1D85DC7FC1CE00E964756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/delay",
|
|
3
3
|
"description": "Comprehensive toolkit for managing asynchronous operations.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0",
|
|
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": "
|
|
9
|
-
"@alwatr/parse-duration": "
|
|
8
|
+
"@alwatr/global-this": "6.0.0",
|
|
9
|
+
"@alwatr/parse-duration": "6.0.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@alwatr/nano-build": "
|
|
13
|
-
"@alwatr/prettier-config": "
|
|
14
|
-
"@alwatr/tsconfig-base": "
|
|
15
|
-
"@alwatr/type-helper": "
|
|
12
|
+
"@alwatr/nano-build": "7.0.0",
|
|
13
|
+
"@alwatr/prettier-config": "7.0.0",
|
|
14
|
+
"@alwatr/tsconfig-base": "7.0.0",
|
|
15
|
+
"@alwatr/type-helper": "8.0.0",
|
|
16
16
|
"@types/node": "^24.12.0",
|
|
17
17
|
"typescript": "^5.9.3"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./dist/main.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"require": "./dist/main.cjs"
|
|
22
|
+
"default": "./dist/main.js"
|
|
24
23
|
}
|
|
25
24
|
},
|
|
26
25
|
"files": [
|
|
27
|
-
"**/*.{js,mjs,cjs,map,d.ts,html,
|
|
26
|
+
"**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
|
|
27
|
+
"README.md",
|
|
28
28
|
"LICENSE",
|
|
29
29
|
"!demo/**/*",
|
|
30
30
|
"!**/*.test.js"
|
|
@@ -50,8 +50,6 @@
|
|
|
50
50
|
"wait"
|
|
51
51
|
],
|
|
52
52
|
"license": "MPL-2.0",
|
|
53
|
-
"main": "./dist/main.cjs",
|
|
54
|
-
"module": "./dist/main.mjs",
|
|
55
53
|
"prettier": "@alwatr/prettier-config",
|
|
56
54
|
"publishConfig": {
|
|
57
55
|
"access": "public"
|
|
@@ -64,12 +62,12 @@
|
|
|
64
62
|
"scripts": {
|
|
65
63
|
"b": "bun run build",
|
|
66
64
|
"build": "bun run build:ts && bun run build:es",
|
|
67
|
-
"build:es": "nano-build --preset=module",
|
|
65
|
+
"build:es": "nano-build --preset=module src/main.ts",
|
|
68
66
|
"build:ts": "tsc --build",
|
|
69
67
|
"c": "bun run clean",
|
|
70
68
|
"cb": "bun run clean && bun run build",
|
|
71
69
|
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
72
|
-
"d": "bun run build:es && bun
|
|
70
|
+
"d": "bun run build:es && bun",
|
|
73
71
|
"w": "bun run watch",
|
|
74
72
|
"watch": "bun run watch:ts & bun run watch:es",
|
|
75
73
|
"watch:es": "bun run build:es --watch",
|
|
@@ -78,5 +76,5 @@
|
|
|
78
76
|
"sideEffects": false,
|
|
79
77
|
"type": "module",
|
|
80
78
|
"types": "./dist/main.d.ts",
|
|
81
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
|
|
82
80
|
}
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {parseDuration, type Duration} from '@alwatr/parse-duration';
|
|
2
|
+
|
|
3
|
+
import {requestAnimationFrame, requestIdleCallback} from './polyfill.js';
|
|
4
|
+
|
|
5
|
+
export {requestAnimationFrame, requestIdleCallback};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A utility module to help manage asynchronous operations and waiting for events or timeouts.
|
|
9
|
+
*/
|
|
10
|
+
export const delay = {
|
|
11
|
+
/**
|
|
12
|
+
* Pauses execution for a specified duration.
|
|
13
|
+
*
|
|
14
|
+
* @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.
|
|
15
|
+
* @returns A Promise that resolves after the specified duration.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* await delay.by('1m'); // Wait for 1 minute
|
|
20
|
+
* await delay.by('2s'); // Wait for 2 seconds
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Pauses execution until the next animation frame.
|
|
27
|
+
*
|
|
28
|
+
* @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const timestamp = await delay.animationFrame();
|
|
33
|
+
* console.log(`Next frame at ${timestamp}`);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Pauses execution until the browser is idle.
|
|
40
|
+
*
|
|
41
|
+
* @param timeout An optional maximum duration to wait.
|
|
42
|
+
* @returns A Promise that resolves with an `IdleDeadline` object.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const deadline = await delay.idleCallback({ timeout: 2000 });
|
|
47
|
+
* if (deadline.didTimeout) {
|
|
48
|
+
* console.log('Idle callback timed out.');
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Pauses execution until a specific DOM event is dispatched on an element.
|
|
56
|
+
*
|
|
57
|
+
* @param element The HTMLElement to listen on.
|
|
58
|
+
* @param eventName The name of the event to wait for.
|
|
59
|
+
* @param options Optional event listener options.
|
|
60
|
+
* @template T The event map type for the element.
|
|
61
|
+
* @returns A Promise that resolves with the triggered event object.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const button = document.getElementById('my-button');
|
|
66
|
+
* if (button) {
|
|
67
|
+
* const clickEvent = await delay.domEvent(button, 'click');
|
|
68
|
+
* console.log('Button clicked!', clickEvent);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
domEvent: <T extends keyof HTMLElementEventMap>(
|
|
73
|
+
element: HTMLElement,
|
|
74
|
+
eventName: T,
|
|
75
|
+
options: AddEventListenerOptions = {passive: true},
|
|
76
|
+
): Promise<HTMLElementEventMap[T]> =>
|
|
77
|
+
new Promise((resolve) =>
|
|
78
|
+
element.addEventListener(eventName, resolve, {
|
|
79
|
+
...options,
|
|
80
|
+
once: true,
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Pauses execution until a specific event is dispatched on any event target.
|
|
86
|
+
*
|
|
87
|
+
* @param target The event target (e.g., window, document, or a custom event emitter).
|
|
88
|
+
* @param eventName The name of the event to wait for.
|
|
89
|
+
* @param options Optional event listener options.
|
|
90
|
+
* @returns A Promise that resolves with the triggered event object.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const resizeEvent = await delay.event(window, 'resize');
|
|
95
|
+
* console.log('Window resized:', resizeEvent);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>
|
|
99
|
+
new Promise((resolve) =>
|
|
100
|
+
target.addEventListener(eventName, resolve, {
|
|
101
|
+
...options,
|
|
102
|
+
once: true,
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Schedules a macrotask to run after the current event loop task completes.
|
|
108
|
+
* Uses `setTimeout(..., 0)`.
|
|
109
|
+
*
|
|
110
|
+
* @returns A Promise that resolves when the macrotask is executed.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* console.log('Start');
|
|
115
|
+
* await delay.nextMacrotask();
|
|
116
|
+
* console.log('End - after current task');
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Queues a microtask to run after the current task completes but before the next macrotask.
|
|
123
|
+
*
|
|
124
|
+
* @returns A Promise that resolves when the microtask is executed.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* console.log('Start');
|
|
129
|
+
* await delay.nextMicrotask();
|
|
130
|
+
* console.log('End - immediately after current task');
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
134
|
+
nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),
|
|
135
|
+
} as const;
|
package/src/polyfill.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {getGlobalThis} from '@alwatr/global-this';
|
|
2
|
+
|
|
3
|
+
import type {} from '@alwatr/type-helper';
|
|
4
|
+
|
|
5
|
+
const globalThis = getGlobalThis<DictionaryOpt<unknown>>();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ensures compatibility for `requestAnimationFrame` by using the native API
|
|
9
|
+
* available in `globalThis`. If it's not available, it falls back to a `setTimeout`
|
|
10
|
+
* call that aims for a 60 frames per second refresh rate.
|
|
11
|
+
*
|
|
12
|
+
* @param callback The function to call when it's time to update your animation for the next repaint.
|
|
13
|
+
* @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.
|
|
14
|
+
*/
|
|
15
|
+
export const requestAnimationFrame: (callback: FrameRequestCallback) => number =
|
|
16
|
+
globalThis.requestAnimationFrame?.bind(globalThis) ??
|
|
17
|
+
((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ensures compatibility for `requestIdleCallback` by using the native API.
|
|
21
|
+
* If unavailable, it falls back to a `setTimeout` that executes the callback
|
|
22
|
+
* after a short delay, providing a mock `IdleDeadline` object.
|
|
23
|
+
*
|
|
24
|
+
* The mock `IdleDeadline` gives the task a 50ms budget to run.
|
|
25
|
+
*
|
|
26
|
+
* @param callback A reference to a function that should be called in the near future, when the event loop is idle.
|
|
27
|
+
* @param options An optional object with configuration parameters.
|
|
28
|
+
* @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.
|
|
29
|
+
*/
|
|
30
|
+
export const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =
|
|
31
|
+
globalThis.requestIdleCallback?.bind(globalThis) ??
|
|
32
|
+
((
|
|
33
|
+
callback: (deadline: IdleDeadline) => void,
|
|
34
|
+
// options is not used in the fallback but kept for API consistency
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
options?: IdleRequestOptions,
|
|
37
|
+
) => {
|
|
38
|
+
const startTime = Date.now();
|
|
39
|
+
return setTimeout(() => {
|
|
40
|
+
callback({
|
|
41
|
+
didTimeout: !!options?.timeout,
|
|
42
|
+
timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),
|
|
43
|
+
});
|
|
44
|
+
}, options?.timeout ?? 20);
|
|
45
|
+
});
|
package/CHANGELOG.md
DELETED
|
@@ -1,488 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [6.0.21](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.20...@alwatr/delay@6.0.21) (2026-03-16)
|
|
7
|
-
|
|
8
|
-
### 🔨 Code Refactoring
|
|
9
|
-
|
|
10
|
-
* migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
|
|
11
|
-
|
|
12
|
-
### 🔗 Dependencies update
|
|
13
|
-
|
|
14
|
-
* bump the npm-dependencies group with 10 updates ([c48d9ba](https://github.com/Alwatr/nanolib/commit/c48d9baa1cd7c2dc144b3e01e0fda60bf87c074c))
|
|
15
|
-
|
|
16
|
-
## [6.0.20](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.19...@alwatr/delay@6.0.20) (2026-02-18)
|
|
17
|
-
|
|
18
|
-
### 🔗 Dependencies update
|
|
19
|
-
|
|
20
|
-
* update @types/node to version 24.10.13 across multiple packages ([4c6d2a3](https://github.com/Alwatr/nanolib/commit/4c6d2a37ab26b1c86812b2aa38b2eca4ee097cb6))
|
|
21
|
-
|
|
22
|
-
## [6.0.19](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.18...@alwatr/delay@6.0.19) (2025-12-23)
|
|
23
|
-
|
|
24
|
-
### 🔗 Dependencies update
|
|
25
|
-
|
|
26
|
-
* upgrade @types/node to version 24.10.4 and update related dependencies ([acf04df](https://github.com/Alwatr/nanolib/commit/acf04df71647f5a401ef5e6bbfffcc478e4326d2))
|
|
27
|
-
|
|
28
|
-
## [6.0.18](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.17...@alwatr/delay@6.0.18) (2025-12-13)
|
|
29
|
-
|
|
30
|
-
### 🔗 Dependencies update
|
|
31
|
-
|
|
32
|
-
* update `@types/node` and `[@lerna-lite](https://github.com/lerna-lite)` dependencies. ([8daa8fd](https://github.com/Alwatr/nanolib/commit/8daa8fd023d5414c9f95feb4319353c6ea34be31))
|
|
33
|
-
|
|
34
|
-
## [6.0.17](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.16...@alwatr/delay@6.0.17) (2025-12-10)
|
|
35
|
-
|
|
36
|
-
### 🔗 Dependencies update
|
|
37
|
-
|
|
38
|
-
* Upgrade lerna-lite, prettier, types/node, and yarn dependencies. ([42a7fca](https://github.com/Alwatr/nanolib/commit/42a7fca15430aca2ac1eaa19496c2a2ebfc8c470))
|
|
39
|
-
|
|
40
|
-
## [6.0.16](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.15...@alwatr/delay@6.0.16) (2025-11-18)
|
|
41
|
-
|
|
42
|
-
### 🐛 Bug Fixes
|
|
43
|
-
|
|
44
|
-
* add type imports from @alwatr/nano-build and @alwatr/type-helper across multiple packages ([5ab7f15](https://github.com/Alwatr/nanolib/commit/5ab7f159ba57788bf8df40fa96a3027f589d5a77))
|
|
45
|
-
|
|
46
|
-
### 🔨 Code Refactoring
|
|
47
|
-
|
|
48
|
-
* remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
|
|
49
|
-
|
|
50
|
-
## [6.0.15](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.14...@alwatr/delay@6.0.15) (2025-11-15)
|
|
51
|
-
|
|
52
|
-
### 🔗 Dependencies update
|
|
53
|
-
|
|
54
|
-
* bump the npm-dependencies group with 2 updates ([a80b84d](https://github.com/Alwatr/nanolib/commit/a80b84dada6c09b5e5621e7487c8ec13fff3c23a))
|
|
55
|
-
|
|
56
|
-
## [6.0.14](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.13...@alwatr/delay@6.0.14) (2025-11-15)
|
|
57
|
-
|
|
58
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
59
|
-
|
|
60
|
-
## [6.0.13](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.12...@alwatr/delay@6.0.13) (2025-11-04)
|
|
61
|
-
|
|
62
|
-
### 🔗 Dependencies update
|
|
63
|
-
|
|
64
|
-
* bump the npm-dependencies group across 1 directory with 9 updates ([fdf29d5](https://github.com/Alwatr/nanolib/commit/fdf29d5aa89983cb06f79d42650a364521f5c4b9))
|
|
65
|
-
* update @types/node from ^22.18.12 to ^24.10.0 across multiple packages ([1169a86](https://github.com/Alwatr/nanolib/commit/1169a86001da2abfbe99a7da33c8e92183f553f6))
|
|
66
|
-
|
|
67
|
-
## [6.0.12](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.11...@alwatr/delay@6.0.12) (2025-10-06)
|
|
68
|
-
|
|
69
|
-
### 🔗 Dependencies update
|
|
70
|
-
|
|
71
|
-
* bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
|
|
72
|
-
|
|
73
|
-
## [6.0.11](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.10...@alwatr/delay@6.0.11) (2025-09-27)
|
|
74
|
-
|
|
75
|
-
### 🧹 Miscellaneous Chores
|
|
76
|
-
|
|
77
|
-
* exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
|
|
78
|
-
|
|
79
|
-
## [6.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.9...@alwatr/delay@6.0.10) (2025-09-22)
|
|
80
|
-
|
|
81
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
82
|
-
|
|
83
|
-
## [6.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.8...@alwatr/delay@6.0.9) (2025-09-22)
|
|
84
|
-
|
|
85
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
86
|
-
|
|
87
|
-
## [6.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.7...@alwatr/delay@6.0.8) (2025-09-21)
|
|
88
|
-
|
|
89
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
90
|
-
|
|
91
|
-
## [6.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.6...@alwatr/delay@6.0.7) (2025-09-20)
|
|
92
|
-
|
|
93
|
-
### 🐛 Bug Fixes
|
|
94
|
-
|
|
95
|
-
* add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
|
|
96
|
-
* add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
|
|
97
|
-
* remove unnecessary pure annotations ([adeb916](https://github.com/Alwatr/nanolib/commit/adeb9166f8e911f59269032b76c36cb1888332cf))
|
|
98
|
-
|
|
99
|
-
### 🧹 Miscellaneous Chores
|
|
100
|
-
|
|
101
|
-
* remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
|
|
102
|
-
|
|
103
|
-
## [6.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.5...@alwatr/delay@6.0.6) (2025-09-19)
|
|
104
|
-
|
|
105
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
106
|
-
|
|
107
|
-
## [6.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.4...@alwatr/delay@6.0.5) (2025-09-15)
|
|
108
|
-
|
|
109
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
110
|
-
|
|
111
|
-
## [6.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.3...@alwatr/delay@6.0.4) (2025-09-14)
|
|
112
|
-
|
|
113
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
114
|
-
|
|
115
|
-
## [6.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.2...@alwatr/delay@6.0.3) (2025-09-13)
|
|
116
|
-
|
|
117
|
-
### 🔗 Dependencies update
|
|
118
|
-
|
|
119
|
-
* update @types/node version to ^22.18.3 in multiple package.json files ([13db6fc](https://github.com/Alwatr/nanolib/commit/13db6fc176bc6cdcefedc50d77ac550bd5052c9a))
|
|
120
|
-
|
|
121
|
-
## [6.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.1...@alwatr/delay@6.0.2) (2025-09-13)
|
|
122
|
-
|
|
123
|
-
### 🧹 Miscellaneous Chores
|
|
124
|
-
|
|
125
|
-
* remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
|
|
126
|
-
|
|
127
|
-
## [6.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@6.0.0...@alwatr/delay@6.0.1) (2025-09-09)
|
|
128
|
-
|
|
129
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
130
|
-
|
|
131
|
-
## [6.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.11...@alwatr/delay@6.0.0) (2025-09-08)
|
|
132
|
-
|
|
133
|
-
### ⚠ BREAKING CHANGES
|
|
134
|
-
|
|
135
|
-
* **delay:** The API has been completely redesigned. All previous standalone functions are removed and replaced by methods on the `delay` object.
|
|
136
|
-
|
|
137
|
-
- **REMOVED:**
|
|
138
|
-
- `untilNextAnimationFrame`
|
|
139
|
-
- `untilIdle`
|
|
140
|
-
- `untilDomEvent`
|
|
141
|
-
- `untilEvent`
|
|
142
|
-
- `immediate`
|
|
143
|
-
- `nextMicrotask`
|
|
144
|
-
|
|
145
|
-
- **ADDED:**
|
|
146
|
-
- `delay.animationFrame` (replaces `waitForAnimationFrame`)
|
|
147
|
-
- `delay.idleCallback` (replaces `waitForIdle`)
|
|
148
|
-
- `delay.domEvent` (replaces `waitForDomEvent`)
|
|
149
|
-
- `delay.event` (replaces `waitForEvent`)
|
|
150
|
-
- `delay.nextMacrotask` (replaces `waitForImmediate`)
|
|
151
|
-
- `delay.nextMicrotask` (replaces `waitForMicrotask`)
|
|
152
|
-
|
|
153
|
-
Users must update their code to import the `delay` object and use the new method names. For example, `delay.immediate()` should be changed to `delay.nextMacrotask()`.
|
|
154
|
-
|
|
155
|
-
### ✨ Features
|
|
156
|
-
|
|
157
|
-
* **delay:** Overhaul delay module with improved API and corrected implementations ([7c12483](https://github.com/Alwatr/nanolib/commit/7c1248354f2535a65cb7981c42ad4e319badb4aa))
|
|
158
|
-
|
|
159
|
-
### 🔨 Code Refactoring
|
|
160
|
-
|
|
161
|
-
* **polyfill:** rename global_ to globalThis for clarity and consistency ([7d1484f](https://github.com/Alwatr/nanolib/commit/7d1484fb91a66d46b62011d0fb7825f3089183f8))
|
|
162
|
-
* **polyfill:** streamline requestAnimationFrame and requestIdleCallback implementations ([d18443d](https://github.com/Alwatr/nanolib/commit/d18443d4dedddff8f54227aa7aff2bca5aaacdfa))
|
|
163
|
-
|
|
164
|
-
### 🧹 Miscellaneous Chores
|
|
165
|
-
|
|
166
|
-
* **main:** export requestAnimationFrame and requestIdleCallback from main module ([ef80797](https://github.com/Alwatr/nanolib/commit/ef80797319e3bded5c36e98352b6317427d08a59))
|
|
167
|
-
|
|
168
|
-
## [5.5.11](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.10...@alwatr/delay@5.5.11) (2025-09-06)
|
|
169
|
-
|
|
170
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
171
|
-
|
|
172
|
-
## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.9...@alwatr/delay@5.5.10) (2025-09-05)
|
|
173
|
-
|
|
174
|
-
### 🔗 Dependencies update
|
|
175
|
-
|
|
176
|
-
* update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
|
|
177
|
-
|
|
178
|
-
## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.8...@alwatr/delay@5.5.9) (2025-09-01)
|
|
179
|
-
|
|
180
|
-
### 🔗 Dependencies update
|
|
181
|
-
|
|
182
|
-
* update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
|
|
183
|
-
|
|
184
|
-
## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.7...@alwatr/delay@5.5.8) (2025-08-23)
|
|
185
|
-
|
|
186
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
187
|
-
|
|
188
|
-
## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.4...@alwatr/delay@5.5.7) (2025-08-23)
|
|
189
|
-
|
|
190
|
-
### 🐛 Bug Fixes
|
|
191
|
-
|
|
192
|
-
* update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
|
|
193
|
-
* update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
|
|
194
|
-
|
|
195
|
-
### 🔨 Code Refactoring
|
|
196
|
-
|
|
197
|
-
* Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
|
|
198
|
-
|
|
199
|
-
### 🧹 Miscellaneous Chores
|
|
200
|
-
|
|
201
|
-
* fix packages/delay/package.json dir ([9777696](https://github.com/Alwatr/nanolib/commit/9777696f070eef855058a791057dde948f6b564b))
|
|
202
|
-
* fix packages/delay/package.json homepage ([eb054b9](https://github.com/Alwatr/nanolib/commit/eb054b95e56840e2835e5a300647c3e6ddf0e21a))
|
|
203
|
-
* reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
|
|
204
|
-
* remove license and contributing sections from README.md ([ba91e2d](https://github.com/Alwatr/nanolib/commit/ba91e2d7faa883f4f2f74e762ee361b48839ce7c))
|
|
205
|
-
|
|
206
|
-
### 🔗 Dependencies update
|
|
207
|
-
|
|
208
|
-
* revert @types/node version to ^22.17.2 (LTS) ([49f8101](https://github.com/Alwatr/nanolib/commit/49f8101eac5c41aa7684112f4308254dbfab9787))
|
|
209
|
-
* update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
|
|
210
|
-
|
|
211
|
-
## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.4...@alwatr/delay@5.5.5) (2025-08-23)
|
|
212
|
-
|
|
213
|
-
### Code Refactoring
|
|
214
|
-
|
|
215
|
-
* Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
|
|
216
|
-
|
|
217
|
-
## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.3...@alwatr/delay@5.5.4) (2025-04-20)
|
|
218
|
-
|
|
219
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
220
|
-
|
|
221
|
-
## <small>5.5.3 (2025-04-15)</small>
|
|
222
|
-
|
|
223
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
224
|
-
|
|
225
|
-
## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.1...@alwatr/delay@5.5.2) (2025-04-01)
|
|
226
|
-
|
|
227
|
-
### Dependencies update
|
|
228
|
-
|
|
229
|
-
* bump the development-dependencies group across 1 directory with 2 updates ([c1320b4](https://github.com/Alwatr/nanolib/commit/c1320b447a492c5e720e25ad71e9df81eeea3670)) by @dependabot[bot]
|
|
230
|
-
|
|
231
|
-
## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.5.0...@alwatr/delay@5.5.1) (2025-03-18)
|
|
232
|
-
|
|
233
|
-
### Bug Fixes
|
|
234
|
-
|
|
235
|
-
* **delay:** specify type for getGlobalThis in polyfill.ts ([57fa717](https://github.com/Alwatr/nanolib/commit/57fa7173f6b040f7d4e536ecb18cf41fbaf218ea)) by @alimd
|
|
236
|
-
|
|
237
|
-
### Dependencies update
|
|
238
|
-
|
|
239
|
-
* bump the development-dependencies group with 9 updates ([7290aa3](https://github.com/Alwatr/nanolib/commit/7290aa3b52ce66ca237d2a12d28a7687b113f83d)) by @dependabot[bot]
|
|
240
|
-
|
|
241
|
-
## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@5.4.0...@alwatr/delay@5.5.0) (2025-03-06)
|
|
242
|
-
|
|
243
|
-
### Miscellaneous Chores
|
|
244
|
-
|
|
245
|
-
* update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
|
|
246
|
-
|
|
247
|
-
### Dependencies update
|
|
248
|
-
|
|
249
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
|
|
250
|
-
|
|
251
|
-
## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.8...@alwatr/delay@5.4.0) (2025-02-18)
|
|
252
|
-
|
|
253
|
-
### Dependencies update
|
|
254
|
-
|
|
255
|
-
* bump @types/node from ^22.13.0 to ^22.13.4 and prettier from 3.4.2 to 3.5.1; update eslint-import-resolver-typescript to 3.8.2 ([b9a8399](https://github.com/Alwatr/nanolib/commit/b9a8399add39509e90bfdc589fb5e2321718029d)) by @
|
|
256
|
-
|
|
257
|
-
## 5.3.0 (2025-02-03)
|
|
258
|
-
|
|
259
|
-
### Miscellaneous Chores
|
|
260
|
-
|
|
261
|
-
* edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
|
|
262
|
-
|
|
263
|
-
### Dependencies update
|
|
264
|
-
|
|
265
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
|
|
266
|
-
* update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
|
|
267
|
-
|
|
268
|
-
## 5.0.0 (2024-11-02)
|
|
269
|
-
|
|
270
|
-
### ⚠ BREAKING CHANGES
|
|
271
|
-
|
|
272
|
-
* To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
|
|
273
|
-
|
|
274
|
-
### Code Refactoring
|
|
275
|
-
|
|
276
|
-
* use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
|
|
277
|
-
|
|
278
|
-
## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
|
|
279
|
-
|
|
280
|
-
### Miscellaneous Chores
|
|
281
|
-
|
|
282
|
-
* edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
|
|
283
|
-
|
|
284
|
-
### Dependencies update
|
|
285
|
-
|
|
286
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
|
|
287
|
-
* update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
|
|
288
|
-
|
|
289
|
-
## 5.0.0 (2024-11-02)
|
|
290
|
-
|
|
291
|
-
### ⚠ BREAKING CHANGES
|
|
292
|
-
|
|
293
|
-
* To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
|
|
294
|
-
|
|
295
|
-
### Features
|
|
296
|
-
|
|
297
|
-
* use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @
|
|
298
|
-
|
|
299
|
-
### Bug Fixes
|
|
300
|
-
|
|
301
|
-
* use new `global-this` package & remove global type & prevent sidee-ffects ([092d448](https://github.com/Alwatr/nanolib/commit/092d44885738ed58215698917ae97c13958f7c7d)) by @
|
|
302
|
-
|
|
303
|
-
### Code Refactoring
|
|
304
|
-
|
|
305
|
-
* **delay:** prevent side-effects ([f92eeed](https://github.com/Alwatr/nanolib/commit/f92eeed7d917f6eb3ca9a407fab0b1ea77adc1d4)) by @
|
|
306
|
-
* **delay:** update delay package to use @alwatr/parse-duration for duration delays ([cca1be2](https://github.com/Alwatr/nanolib/commit/cca1be2dcfeec6dce388562ef867b81af1823b62)) by @
|
|
307
|
-
* **delay:** update untilIdle function to accept Duration instead of DurationString ([b3a5c32](https://github.com/Alwatr/nanolib/commit/b3a5c322a1b59833693149da644c7d2eddd6a374)) by @
|
|
308
|
-
* prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
|
|
309
|
-
* update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @
|
|
310
|
-
* use new `global-this` package ([42510b9](https://github.com/Alwatr/nanolib/commit/42510b9ae0e385206a902db093d188949f1cb84e)) by @
|
|
311
|
-
* use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
|
|
312
|
-
* use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
|
|
313
|
-
* **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @
|
|
314
|
-
|
|
315
|
-
### Miscellaneous Chores
|
|
316
|
-
|
|
317
|
-
* fix versions ([497a6d8](https://github.com/Alwatr/nanolib/commit/497a6d81ae5989e566e96d498fc5f1b6c80193ae)) by @
|
|
318
|
-
* include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
|
|
319
|
-
|
|
320
|
-
### Dependencies update
|
|
321
|
-
|
|
322
|
-
* bump the development-dependencies group across 1 directory with 2 updates ([2dfda9e](https://github.com/Alwatr/nanolib/commit/2dfda9ec38a595f1fd961490d1a2fbf060f20a66)) by @
|
|
323
|
-
* bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
|
|
324
|
-
* bump the development-dependencies group with 8 updates ([16847ac](https://github.com/Alwatr/nanolib/commit/16847acba91da027c422e3910d0f2dcc1f084e93)) by @
|
|
325
|
-
* update ([4434ba6](https://github.com/Alwatr/nanolib/commit/4434ba67c3f576bb1a0c307fbdb263c43cd9733a)) by @
|
|
326
|
-
|
|
327
|
-
## [1.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.7...@alwatr/delay@1.0.8) (2024-11-02)
|
|
328
|
-
|
|
329
|
-
### Dependencies update
|
|
330
|
-
|
|
331
|
-
* update ([4434ba6](https://github.com/Alwatr/nanolib/commit/4434ba67c3f576bb1a0c307fbdb263c43cd9733a)) by @alimd
|
|
332
|
-
|
|
333
|
-
## [1.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.6...@alwatr/delay@1.0.7) (2024-10-25)
|
|
334
|
-
|
|
335
|
-
### Dependencies update
|
|
336
|
-
|
|
337
|
-
* bump the development-dependencies group across 1 directory with 2 updates ([2dfda9e](https://github.com/Alwatr/nanolib/commit/2dfda9ec38a595f1fd961490d1a2fbf060f20a66)) by @dependabot[bot]
|
|
338
|
-
* bump the development-dependencies group with 8 updates ([16847ac](https://github.com/Alwatr/nanolib/commit/16847acba91da027c422e3910d0f2dcc1f084e93)) by @dependabot[bot]
|
|
339
|
-
|
|
340
|
-
## [1.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.5...@alwatr/delay@1.0.6) (2024-10-12)
|
|
341
|
-
|
|
342
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
343
|
-
|
|
344
|
-
## [1.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.4...@alwatr/delay@1.0.5) (2024-10-11)
|
|
345
|
-
|
|
346
|
-
### Bug Fixes
|
|
347
|
-
|
|
348
|
-
- use new `global-this` package & remove global type & prevent sidee-ffects ([092d448](https://github.com/Alwatr/nanolib/commit/092d44885738ed58215698917ae97c13958f7c7d)) by @mohammadhonarvar
|
|
349
|
-
|
|
350
|
-
### Code Refactoring
|
|
351
|
-
|
|
352
|
-
- **delay:** prevent side-effects ([f92eeed](https://github.com/Alwatr/nanolib/commit/f92eeed7d917f6eb3ca9a407fab0b1ea77adc1d4)) by @mohammadhonarvar
|
|
353
|
-
- prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
|
|
354
|
-
- use new `global-this` package ([42510b9](https://github.com/Alwatr/nanolib/commit/42510b9ae0e385206a902db093d188949f1cb84e)) by @mohammadhonarvar
|
|
355
|
-
|
|
356
|
-
## [1.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.3...@alwatr/delay@1.0.4) (2024-10-11)
|
|
357
|
-
|
|
358
|
-
### Miscellaneous Chores
|
|
359
|
-
|
|
360
|
-
- include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
|
|
361
|
-
|
|
362
|
-
## [1.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.2...@alwatr/delay@1.0.3) (2024-10-11)
|
|
363
|
-
|
|
364
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
365
|
-
|
|
366
|
-
## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.1...@alwatr/delay@1.0.2) (2024-10-10)
|
|
367
|
-
|
|
368
|
-
### Dependencies update
|
|
369
|
-
|
|
370
|
-
- bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
|
|
371
|
-
|
|
372
|
-
## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.0.0...@alwatr/delay@1.0.1) (2024-10-08)
|
|
373
|
-
|
|
374
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
375
|
-
|
|
376
|
-
## 1.0.0 (2024-09-29)
|
|
377
|
-
|
|
378
|
-
### Features
|
|
379
|
-
|
|
380
|
-
- use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @mohammadhonarvar
|
|
381
|
-
|
|
382
|
-
### Code Refactoring
|
|
383
|
-
|
|
384
|
-
- **delay:** update delay package to use @alwatr/parse-duration for duration delays ([cca1be2](https://github.com/Alwatr/nanolib/commit/cca1be2dcfeec6dce388562ef867b81af1823b62)) by @alimd
|
|
385
|
-
- **delay:** update untilIdle function to accept Duration instead of DurationString ([b3a5c32](https://github.com/Alwatr/nanolib/commit/b3a5c322a1b59833693149da644c7d2eddd6a374)) by @alimd
|
|
386
|
-
- update Dictionary type definitions ([c94cbc4](https://github.com/Alwatr/nanolib/commit/c94cbc4523864e2cc47828ccf5508b68945ac2b8)) by @alimd
|
|
387
|
-
- use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
|
|
388
|
-
- **wait:** rename package to delay ([cf8c45c](https://github.com/Alwatr/nanolib/commit/cf8c45cf3f5b61fdd4b1b1c7f744c4eb3e230016)) by @alimd
|
|
389
|
-
|
|
390
|
-
### Miscellaneous Chores
|
|
391
|
-
|
|
392
|
-
- fix versions ([497a6d8](https://github.com/Alwatr/nanolib/commit/497a6d81ae5989e566e96d498fc5f1b6c80193ae)) by @alimd
|
|
393
|
-
|
|
394
|
-
## [1.1.16](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.15...@alwatr/delay@1.1.16) (2024-09-21)
|
|
395
|
-
|
|
396
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
397
|
-
|
|
398
|
-
## [1.1.15](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.14...@alwatr/delay@1.1.15) (2024-09-15)
|
|
399
|
-
|
|
400
|
-
### Dependencies update
|
|
401
|
-
|
|
402
|
-
- bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
|
|
403
|
-
- update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @alimd
|
|
404
|
-
|
|
405
|
-
## [1.1.14](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.13...@alwatr/delay@1.1.14) (2024-08-31)
|
|
406
|
-
|
|
407
|
-
### Miscellaneous Chores
|
|
408
|
-
|
|
409
|
-
- Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
|
|
410
|
-
|
|
411
|
-
## [1.1.13](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.12...@alwatr/delay@1.1.13) (2024-08-31)
|
|
412
|
-
|
|
413
|
-
### Dependencies update
|
|
414
|
-
|
|
415
|
-
- update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
|
|
416
|
-
|
|
417
|
-
## [1.1.12](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.11...@alwatr/delay@1.1.12) (2024-07-04)
|
|
418
|
-
|
|
419
|
-
### Dependencies update
|
|
420
|
-
|
|
421
|
-
- update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
|
|
422
|
-
|
|
423
|
-
## [1.1.11](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.10...@alwatr/delay@1.1.11) (2024-05-12)
|
|
424
|
-
|
|
425
|
-
### Dependencies update
|
|
426
|
-
|
|
427
|
-
- upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @alimd
|
|
428
|
-
|
|
429
|
-
## [1.1.10](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.9...@alwatr/delay@1.1.10) (2024-04-25)
|
|
430
|
-
|
|
431
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
432
|
-
|
|
433
|
-
## [1.1.9](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.8...@alwatr/delay@1.1.9) (2024-03-28)
|
|
434
|
-
|
|
435
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
436
|
-
|
|
437
|
-
## [1.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.7...@alwatr/delay@1.1.8) (2024-01-31)
|
|
438
|
-
|
|
439
|
-
### Bug Fixes
|
|
440
|
-
|
|
441
|
-
- exported types by add .js extensions to all imports ([fc3d83e](https://github.com/Alwatr/nanolib/commit/fc3d83e8f375da97ba276314b2e6966aa82c9b3f)) by @alimd
|
|
442
|
-
|
|
443
|
-
### Miscellaneous Chores
|
|
444
|
-
|
|
445
|
-
- **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @alimd
|
|
446
|
-
|
|
447
|
-
## [1.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.6...@alwatr/delay@1.1.7) (2024-01-24)
|
|
448
|
-
|
|
449
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
450
|
-
|
|
451
|
-
## [1.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.5...@alwatr/delay@1.1.6) (2024-01-20)
|
|
452
|
-
|
|
453
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
454
|
-
|
|
455
|
-
## [1.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.4...@alwatr/delay@1.1.5) (2024-01-16)
|
|
456
|
-
|
|
457
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
458
|
-
|
|
459
|
-
## [1.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.3...@alwatr/delay@1.1.4) (2024-01-08)
|
|
460
|
-
|
|
461
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
462
|
-
|
|
463
|
-
## [1.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.2...@alwatr/delay@1.1.3) (2024-01-03)
|
|
464
|
-
|
|
465
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
466
|
-
|
|
467
|
-
## [1.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.1...@alwatr/delay@1.1.2) (2024-01-03)
|
|
468
|
-
|
|
469
|
-
### Bug Fixes
|
|
470
|
-
|
|
471
|
-
- **wait:** requestIdleCallback polyfill ([d41180d](https://github.com/Alwatr/nanolib/commit/d41180dc2f0c313eb86f05f60050e57e891897c3)) by @alimd
|
|
472
|
-
|
|
473
|
-
## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/delay@1.1.0...@alwatr/delay@1.1.1) (2023-12-27)
|
|
474
|
-
|
|
475
|
-
**Note:** Version bump only for package @alwatr/delay
|
|
476
|
-
|
|
477
|
-
# 1.1.0 (2023-12-27)
|
|
478
|
-
|
|
479
|
-
### Bug Fixes
|
|
480
|
-
|
|
481
|
-
- deps ([34cd4fe](https://github.com/Alwatr/nanolib/commit/34cd4fead81b309765144a24add67e3f63bca127)) by @njfamirm
|
|
482
|
-
- **wait:** polyfill ([6a0f5fb](https://github.com/Alwatr/nanolib/commit/6a0f5fb5f0ae369d832760c026c26428689d258d)) by @alimd
|
|
483
|
-
- **wait:** polyfill check ([cd9befa](https://github.com/Alwatr/nanolib/commit/cd9befa0ae01090016eb16befc08d1ce17ba881d)) by @njfamirm
|
|
484
|
-
|
|
485
|
-
### Features
|
|
486
|
-
|
|
487
|
-
- **wait:** base package ([8f29498](https://github.com/Alwatr/nanolib/commit/8f294983f9250e1ec8fb60dce72347f9586c561b)) by @njfamirm
|
|
488
|
-
- **wait:** polyfill and docs ([9725dc2](https://github.com/Alwatr/nanolib/commit/9725dc2cfa4d70fb5dac8a2816f986ad00c4f43f)) by @njfamirm
|
package/dist/main.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/** 📦 @alwatr/delay v6.0.21 */
|
|
2
|
-
"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});
|
|
3
|
-
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 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\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
|
-
"names": []
|
|
7
|
-
}
|
package/dist/main.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/** 📦 @alwatr/delay v6.0.21 */
|
|
2
|
-
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};
|
|
3
|
-
//# sourceMappingURL=main.mjs.map
|
package/dist/main.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 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\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
|
-
"names": []
|
|
7
|
-
}
|