@cloudcare/browser-core 3.2.3 → 3.2.4
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/cjs/helper/requestIdleCallback.js +46 -0
- package/cjs/helper/requestIdleCallback.js.map +1 -0
- package/cjs/helper/taskQueue.js +59 -0
- package/cjs/helper/taskQueue.js.map +1 -0
- package/cjs/helper/tools.js +1 -1
- package/cjs/helper/tools.js.map +1 -1
- package/cjs/index.js +22 -0
- package/cjs/index.js.map +1 -1
- package/esm/helper/requestIdleCallback.js +38 -0
- package/esm/helper/requestIdleCallback.js.map +1 -0
- package/esm/helper/taskQueue.js +52 -0
- package/esm/helper/taskQueue.js.map +1 -0
- package/esm/helper/tools.js +1 -1
- package/esm/helper/tools.js.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/helper/requestIdleCallback.js +38 -0
- package/src/helper/taskQueue.js +55 -0
- package/src/helper/tools.js +6 -1
- package/src/index.js +2 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MAX_TASK_TIME = void 0;
|
|
7
|
+
exports.requestIdleCallback = requestIdleCallback;
|
|
8
|
+
exports.requestIdleCallbackShim = requestIdleCallbackShim;
|
|
9
|
+
var _timer = require("./timer");
|
|
10
|
+
var _monitor = require("./monitor");
|
|
11
|
+
var _tools = require("./tools");
|
|
12
|
+
/**
|
|
13
|
+
* 'requestIdleCallback' with a shim.
|
|
14
|
+
*/
|
|
15
|
+
function requestIdleCallback(callback, opts) {
|
|
16
|
+
// Note: check both 'requestIdleCallback' and 'cancelIdleCallback' existence because some polyfills only implement 'requestIdleCallback'.
|
|
17
|
+
if (window.requestIdleCallback && window.cancelIdleCallback) {
|
|
18
|
+
var id = window.requestIdleCallback((0, _monitor.monitor)(callback), opts);
|
|
19
|
+
return function () {
|
|
20
|
+
return window.cancelIdleCallback(id);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return requestIdleCallbackShim(callback);
|
|
24
|
+
}
|
|
25
|
+
var MAX_TASK_TIME = 50;
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Shim from https://developer.chrome.com/blog/using-requestidlecallback#checking_for_requestidlecallback
|
|
29
|
+
* Note: there is no simple way to support the "timeout" option, so we ignore it.
|
|
30
|
+
*/
|
|
31
|
+
exports.MAX_TASK_TIME = MAX_TASK_TIME;
|
|
32
|
+
function requestIdleCallbackShim(callback) {
|
|
33
|
+
var start = (0, _tools.dateNow)();
|
|
34
|
+
var timeoutId = (0, _timer.setTimeout)(function () {
|
|
35
|
+
callback({
|
|
36
|
+
didTimeout: false,
|
|
37
|
+
timeRemaining: function timeRemaining() {
|
|
38
|
+
return Math.max(0, MAX_TASK_TIME - ((0, _tools.dateNow)() - start));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}, 0);
|
|
42
|
+
return function () {
|
|
43
|
+
return (0, _timer.clearTimeout)(timeoutId);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=requestIdleCallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestIdleCallback.js","names":["_timer","require","_monitor","_tools","requestIdleCallback","callback","opts","window","cancelIdleCallback","id","monitor","requestIdleCallbackShim","MAX_TASK_TIME","exports","start","dateNow","timeoutId","setTimeout","didTimeout","timeRemaining","Math","max","clearTimeout"],"sources":["../../src/helper/requestIdleCallback.js"],"sourcesContent":["import { setTimeout, clearTimeout } from './timer'\nimport { monitor } from './monitor'\nimport { dateNow } from './tools'\n\n/**\n * 'requestIdleCallback' with a shim.\n */\nexport function requestIdleCallback(callback, opts) {\n // Note: check both 'requestIdleCallback' and 'cancelIdleCallback' existence because some polyfills only implement 'requestIdleCallback'.\n if (window.requestIdleCallback && window.cancelIdleCallback) {\n const id = window.requestIdleCallback(monitor(callback), opts)\n return function () {\n return window.cancelIdleCallback(id)\n }\n }\n return requestIdleCallbackShim(callback)\n}\n\nexport const MAX_TASK_TIME = 50\n\n/*\n * Shim from https://developer.chrome.com/blog/using-requestidlecallback#checking_for_requestidlecallback\n * Note: there is no simple way to support the \"timeout\" option, so we ignore it.\n */\nexport function requestIdleCallbackShim(callback) {\n const start = dateNow()\n const timeoutId = setTimeout(function () {\n callback({\n didTimeout: false,\n timeRemaining: function () {\n return Math.max(0, MAX_TASK_TIME - (dateNow() - start))\n }\n })\n }, 0)\n return function () {\n return clearTimeout(timeoutId)\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACO,SAASG,mBAAmBA,CAACC,QAAQ,EAAEC,IAAI,EAAE;EAClD;EACA,IAAIC,MAAM,CAACH,mBAAmB,IAAIG,MAAM,CAACC,kBAAkB,EAAE;IAC3D,IAAMC,EAAE,GAAGF,MAAM,CAACH,mBAAmB,CAAC,IAAAM,gBAAO,EAACL,QAAQ,CAAC,EAAEC,IAAI,CAAC;IAC9D,OAAO,YAAY;MACjB,OAAOC,MAAM,CAACC,kBAAkB,CAACC,EAAE,CAAC;IACtC,CAAC;EACH;EACA,OAAOE,uBAAuB,CAACN,QAAQ,CAAC;AAC1C;AAEO,IAAMO,aAAa,GAAG,EAAE;;AAE/B;AACA;AACA;AACA;AAHAC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AAIO,SAASD,uBAAuBA,CAACN,QAAQ,EAAE;EAChD,IAAMS,KAAK,GAAG,IAAAC,cAAO,EAAC,CAAC;EACvB,IAAMC,SAAS,GAAG,IAAAC,iBAAU,EAAC,YAAY;IACvCZ,QAAQ,CAAC;MACPa,UAAU,EAAE,KAAK;MACjBC,aAAa,EAAE,SAAAA,cAAA,EAAY;QACzB,OAAOC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAET,aAAa,IAAI,IAAAG,cAAO,EAAC,CAAC,GAAGD,KAAK,CAAC,CAAC;MACzD;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,CAAC,CAAC;EACL,OAAO,YAAY;IACjB,OAAO,IAAAQ,mBAAY,EAACN,SAAS,CAAC;EAChC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MAX_EXECUTION_TIME_ON_TIMEOUT = void 0;
|
|
7
|
+
exports.createTaskQueue = createTaskQueue;
|
|
8
|
+
var _tools = require("./tools");
|
|
9
|
+
var _requestIdleCallback = require("./requestIdleCallback");
|
|
10
|
+
/**
|
|
11
|
+
* Maximum delay before starting to execute tasks in the queue. We don't want to wait too long
|
|
12
|
+
* before running tasks, as it might hurt reliability (ex: if the user navigates away, we might lose
|
|
13
|
+
* the opportunity to send some data). We also don't want to run tasks too often, as it might hurt
|
|
14
|
+
* performance.
|
|
15
|
+
*/
|
|
16
|
+
var IDLE_CALLBACK_TIMEOUT = _tools.ONE_SECOND;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Maximum amount of time allocated to running tasks when a timeout (`IDLE_CALLBACK_TIMEOUT`) is
|
|
20
|
+
* reached. We should not run tasks for too long as it will hurt performance, but we should still
|
|
21
|
+
* run some tasks to avoid postponing them forever.
|
|
22
|
+
*
|
|
23
|
+
* Rational: Running tasks for 30ms every second (IDLE_CALLBACK_TIMEOUT) should be acceptable.
|
|
24
|
+
*/
|
|
25
|
+
var MAX_EXECUTION_TIME_ON_TIMEOUT = 30;
|
|
26
|
+
exports.MAX_EXECUTION_TIME_ON_TIMEOUT = MAX_EXECUTION_TIME_ON_TIMEOUT;
|
|
27
|
+
function createTaskQueue() {
|
|
28
|
+
var pendingTasks = [];
|
|
29
|
+
function run(deadline) {
|
|
30
|
+
var executionTimeRemaining;
|
|
31
|
+
if (deadline.didTimeout) {
|
|
32
|
+
var start = performance.now();
|
|
33
|
+
executionTimeRemaining = function executionTimeRemaining() {
|
|
34
|
+
return MAX_EXECUTION_TIME_ON_TIMEOUT - (performance.now() - start);
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
executionTimeRemaining = deadline.timeRemaining.bind(deadline);
|
|
38
|
+
}
|
|
39
|
+
while (executionTimeRemaining() > 0 && pendingTasks.length) {
|
|
40
|
+
pendingTasks.shift()();
|
|
41
|
+
}
|
|
42
|
+
if (pendingTasks.length) {
|
|
43
|
+
scheduleNextRun();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function scheduleNextRun() {
|
|
47
|
+
(0, _requestIdleCallback.requestIdleCallback)(run, {
|
|
48
|
+
timeout: IDLE_CALLBACK_TIMEOUT
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
push: function push(task) {
|
|
53
|
+
if (pendingTasks.push(task) === 1) {
|
|
54
|
+
scheduleNextRun();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=taskQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taskQueue.js","names":["_tools","require","_requestIdleCallback","IDLE_CALLBACK_TIMEOUT","ONE_SECOND","MAX_EXECUTION_TIME_ON_TIMEOUT","exports","createTaskQueue","pendingTasks","run","deadline","executionTimeRemaining","didTimeout","start","performance","now","timeRemaining","bind","length","shift","scheduleNextRun","requestIdleCallback","timeout","push","task"],"sources":["../../src/helper/taskQueue.js"],"sourcesContent":["import { ONE_SECOND } from './tools'\nimport { requestIdleCallback } from './requestIdleCallback'\n\n/**\n * Maximum delay before starting to execute tasks in the queue. We don't want to wait too long\n * before running tasks, as it might hurt reliability (ex: if the user navigates away, we might lose\n * the opportunity to send some data). We also don't want to run tasks too often, as it might hurt\n * performance.\n */\nconst IDLE_CALLBACK_TIMEOUT = ONE_SECOND\n\n/**\n * Maximum amount of time allocated to running tasks when a timeout (`IDLE_CALLBACK_TIMEOUT`) is\n * reached. We should not run tasks for too long as it will hurt performance, but we should still\n * run some tasks to avoid postponing them forever.\n *\n * Rational: Running tasks for 30ms every second (IDLE_CALLBACK_TIMEOUT) should be acceptable.\n */\nexport const MAX_EXECUTION_TIME_ON_TIMEOUT = 30\n\nexport function createTaskQueue() {\n const pendingTasks = []\n\n function run(deadline) {\n let executionTimeRemaining\n if (deadline.didTimeout) {\n const start = performance.now()\n executionTimeRemaining = function () {\n return MAX_EXECUTION_TIME_ON_TIMEOUT - (performance.now() - start)\n }\n } else {\n executionTimeRemaining = deadline.timeRemaining.bind(deadline)\n }\n\n while (executionTimeRemaining() > 0 && pendingTasks.length) {\n pendingTasks.shift()()\n }\n\n if (pendingTasks.length) {\n scheduleNextRun()\n }\n }\n\n function scheduleNextRun() {\n requestIdleCallback(run, { timeout: IDLE_CALLBACK_TIMEOUT })\n }\n\n return {\n push(task) {\n if (pendingTasks.push(task) === 1) {\n scheduleNextRun()\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAME,qBAAqB,GAAGC,iBAAU;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,6BAA6B,GAAG,EAAE;AAAAC,OAAA,CAAAD,6BAAA,GAAAA,6BAAA;AAExC,SAASE,eAAeA,CAAA,EAAG;EAChC,IAAMC,YAAY,GAAG,EAAE;EAEvB,SAASC,GAAGA,CAACC,QAAQ,EAAE;IACrB,IAAIC,sBAAsB;IAC1B,IAAID,QAAQ,CAACE,UAAU,EAAE;MACvB,IAAMC,KAAK,GAAGC,WAAW,CAACC,GAAG,CAAC,CAAC;MAC/BJ,sBAAsB,GAAG,SAAAA,uBAAA,EAAY;QACnC,OAAON,6BAA6B,IAAIS,WAAW,CAACC,GAAG,CAAC,CAAC,GAAGF,KAAK,CAAC;MACpE,CAAC;IACH,CAAC,MAAM;MACLF,sBAAsB,GAAGD,QAAQ,CAACM,aAAa,CAACC,IAAI,CAACP,QAAQ,CAAC;IAChE;IAEA,OAAOC,sBAAsB,CAAC,CAAC,GAAG,CAAC,IAAIH,YAAY,CAACU,MAAM,EAAE;MAC1DV,YAAY,CAACW,KAAK,CAAC,CAAC,CAAC,CAAC;IACxB;IAEA,IAAIX,YAAY,CAACU,MAAM,EAAE;MACvBE,eAAe,CAAC,CAAC;IACnB;EACF;EAEA,SAASA,eAAeA,CAAA,EAAG;IACzB,IAAAC,wCAAmB,EAACZ,GAAG,EAAE;MAAEa,OAAO,EAAEnB;IAAsB,CAAC,CAAC;EAC9D;EAEA,OAAO;IACLoB,IAAI,WAAAA,KAACC,IAAI,EAAE;MACT,IAAIhB,YAAY,CAACe,IAAI,CAACC,IAAI,CAAC,KAAK,CAAC,EAAE;QACjCJ,eAAe,CAAC,CAAC;MACnB;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
package/cjs/helper/tools.js
CHANGED
|
@@ -1545,7 +1545,7 @@ function findByPath(source, path) {
|
|
|
1545
1545
|
var pathArr = path.split('.');
|
|
1546
1546
|
while (pathArr.length) {
|
|
1547
1547
|
var key = pathArr.shift();
|
|
1548
|
-
if (source && key in source && hasOwnProperty.call(source, key)) {
|
|
1548
|
+
if (source && isObject(source) && key in source && hasOwnProperty.call(source, key)) {
|
|
1549
1549
|
source = source[key];
|
|
1550
1550
|
} else {
|
|
1551
1551
|
return undefined;
|