xpe 1.0.13 → 1.0.14
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/kernel/utils.d.ts +2 -1
- package/dist/kernel/utils.js +26 -1
- package/package.json +1 -1
package/dist/kernel/utils.d.ts
CHANGED
|
@@ -41,7 +41,8 @@ export declare function getAbsolutePath(url: string, base: string, hash?: boolea
|
|
|
41
41
|
export declare function getSyncUrl(id: string, prefix: {
|
|
42
42
|
[key: string]: string;
|
|
43
43
|
}): string;
|
|
44
|
-
|
|
44
|
+
/** Required startup work must progress even when a background tab gets no idle callback. */
|
|
45
|
+
export declare function requestIdleCallback(callback: IdleRequestCallback): number;
|
|
45
46
|
export declare function getContainer(container: string | HTMLElement): HTMLElement;
|
|
46
47
|
export declare function warn(msg: string, data?: any): void;
|
|
47
48
|
export declare function error(msg: string, data?: any): void;
|
package/dist/kernel/utils.js
CHANGED
|
@@ -198,7 +198,32 @@ export function getSyncUrl(id, prefix) {
|
|
|
198
198
|
return syncUrl;
|
|
199
199
|
}
|
|
200
200
|
// @ts-ignore
|
|
201
|
-
|
|
201
|
+
/** Required startup work must progress even when a background tab gets no idle callback. */
|
|
202
|
+
export function requestIdleCallback(callback) {
|
|
203
|
+
const target = window;
|
|
204
|
+
const native = target.requestIdleCallback;
|
|
205
|
+
if (!native) {
|
|
206
|
+
return target.setTimeout(() => callback({ didTimeout: true, timeRemaining: () => 0 }), 1);
|
|
207
|
+
}
|
|
208
|
+
let completed = false;
|
|
209
|
+
let idleId;
|
|
210
|
+
const fallback = target.setTimeout(() => {
|
|
211
|
+
if (completed)
|
|
212
|
+
return;
|
|
213
|
+
completed = true;
|
|
214
|
+
if (idleId !== undefined)
|
|
215
|
+
target.cancelIdleCallback?.(idleId);
|
|
216
|
+
callback({ didTimeout: true, timeRemaining: () => 0 });
|
|
217
|
+
}, 100);
|
|
218
|
+
idleId = native.call(target, (deadline) => {
|
|
219
|
+
if (completed)
|
|
220
|
+
return;
|
|
221
|
+
completed = true;
|
|
222
|
+
target.clearTimeout(fallback);
|
|
223
|
+
callback(deadline);
|
|
224
|
+
}, { timeout: 100 });
|
|
225
|
+
return idleId;
|
|
226
|
+
}
|
|
202
227
|
export function getContainer(container) {
|
|
203
228
|
return typeof container === "string" ? document.querySelector(container) : container;
|
|
204
229
|
}
|