@whitesev/utils 2.6.6 → 2.6.7
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/index.amd.js +321 -14
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +321 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +321 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +321 -14
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +321 -14
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +321 -14
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +22 -0
- package/package.json +3 -2
- package/src/LockFunction.ts +1 -1
- package/src/Utils.ts +75 -13
package/dist/index.amd.js
CHANGED
|
@@ -3720,7 +3720,7 @@ define((function () { 'use strict';
|
|
|
3720
3720
|
* 解锁
|
|
3721
3721
|
*/
|
|
3722
3722
|
this.unlock = function () {
|
|
3723
|
-
|
|
3723
|
+
utils.workerSetTimeout(() => {
|
|
3724
3724
|
that.#flag = false;
|
|
3725
3725
|
}, that.#delayTime);
|
|
3726
3726
|
};
|
|
@@ -4603,6 +4603,251 @@ define((function () { 'use strict';
|
|
|
4603
4603
|
}
|
|
4604
4604
|
}
|
|
4605
4605
|
|
|
4606
|
+
const createCache = (lastNumberWeakMap) => {
|
|
4607
|
+
return (collection, nextNumber) => {
|
|
4608
|
+
lastNumberWeakMap.set(collection, nextNumber);
|
|
4609
|
+
return nextNumber;
|
|
4610
|
+
};
|
|
4611
|
+
};
|
|
4612
|
+
|
|
4613
|
+
/*
|
|
4614
|
+
* The value of the constant Number.MAX_SAFE_INTEGER equals (2 ** 53 - 1) but it
|
|
4615
|
+
* is fairly new.
|
|
4616
|
+
*/
|
|
4617
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER === undefined ? 9007199254740991 : Number.MAX_SAFE_INTEGER;
|
|
4618
|
+
const TWO_TO_THE_POWER_OF_TWENTY_NINE = 536870912;
|
|
4619
|
+
const TWO_TO_THE_POWER_OF_THIRTY = TWO_TO_THE_POWER_OF_TWENTY_NINE * 2;
|
|
4620
|
+
const createGenerateUniqueNumber = (cache, lastNumberWeakMap) => {
|
|
4621
|
+
return (collection) => {
|
|
4622
|
+
const lastNumber = lastNumberWeakMap.get(collection);
|
|
4623
|
+
/*
|
|
4624
|
+
* Let's try the cheapest algorithm first. It might fail to produce a new
|
|
4625
|
+
* number, but it is so cheap that it is okay to take the risk. Just
|
|
4626
|
+
* increase the last number by one or reset it to 0 if we reached the upper
|
|
4627
|
+
* bound of SMIs (which stands for small integers). When the last number is
|
|
4628
|
+
* unknown it is assumed that the collection contains zero based consecutive
|
|
4629
|
+
* numbers.
|
|
4630
|
+
*/
|
|
4631
|
+
let nextNumber = lastNumber === undefined ? collection.size : lastNumber < TWO_TO_THE_POWER_OF_THIRTY ? lastNumber + 1 : 0;
|
|
4632
|
+
if (!collection.has(nextNumber)) {
|
|
4633
|
+
return cache(collection, nextNumber);
|
|
4634
|
+
}
|
|
4635
|
+
/*
|
|
4636
|
+
* If there are less than half of 2 ** 30 numbers stored in the collection,
|
|
4637
|
+
* the chance to generate a new random number in the range from 0 to 2 ** 30
|
|
4638
|
+
* is at least 50%. It's benifitial to use only SMIs because they perform
|
|
4639
|
+
* much better in any environment based on V8.
|
|
4640
|
+
*/
|
|
4641
|
+
if (collection.size < TWO_TO_THE_POWER_OF_TWENTY_NINE) {
|
|
4642
|
+
while (collection.has(nextNumber)) {
|
|
4643
|
+
nextNumber = Math.floor(Math.random() * TWO_TO_THE_POWER_OF_THIRTY);
|
|
4644
|
+
}
|
|
4645
|
+
return cache(collection, nextNumber);
|
|
4646
|
+
}
|
|
4647
|
+
// Quickly check if there is a theoretical chance to generate a new number.
|
|
4648
|
+
if (collection.size > MAX_SAFE_INTEGER) {
|
|
4649
|
+
throw new Error('Congratulations, you created a collection of unique numbers which uses all available integers!');
|
|
4650
|
+
}
|
|
4651
|
+
// Otherwise use the full scale of safely usable integers.
|
|
4652
|
+
while (collection.has(nextNumber)) {
|
|
4653
|
+
nextNumber = Math.floor(Math.random() * MAX_SAFE_INTEGER);
|
|
4654
|
+
}
|
|
4655
|
+
return cache(collection, nextNumber);
|
|
4656
|
+
};
|
|
4657
|
+
};
|
|
4658
|
+
|
|
4659
|
+
const LAST_NUMBER_WEAK_MAP = new WeakMap();
|
|
4660
|
+
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
4661
|
+
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
4662
|
+
|
|
4663
|
+
const isMessagePort = (sender) => {
|
|
4664
|
+
return typeof sender.start === 'function';
|
|
4665
|
+
};
|
|
4666
|
+
|
|
4667
|
+
const PORT_MAP = new WeakMap();
|
|
4668
|
+
|
|
4669
|
+
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
4670
|
+
...partialBrokerImplementation,
|
|
4671
|
+
connect: ({ call }) => {
|
|
4672
|
+
return async () => {
|
|
4673
|
+
const { port1, port2 } = new MessageChannel();
|
|
4674
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
4675
|
+
PORT_MAP.set(port2, portId);
|
|
4676
|
+
return port2;
|
|
4677
|
+
};
|
|
4678
|
+
},
|
|
4679
|
+
disconnect: ({ call }) => {
|
|
4680
|
+
return async (port) => {
|
|
4681
|
+
const portId = PORT_MAP.get(port);
|
|
4682
|
+
if (portId === undefined) {
|
|
4683
|
+
throw new Error('The given port is not connected.');
|
|
4684
|
+
}
|
|
4685
|
+
await call('disconnect', { portId });
|
|
4686
|
+
};
|
|
4687
|
+
},
|
|
4688
|
+
isSupported: ({ call }) => {
|
|
4689
|
+
return () => call('isSupported');
|
|
4690
|
+
}
|
|
4691
|
+
});
|
|
4692
|
+
|
|
4693
|
+
const ONGOING_REQUESTS = new WeakMap();
|
|
4694
|
+
const createOrGetOngoingRequests = (sender) => {
|
|
4695
|
+
if (ONGOING_REQUESTS.has(sender)) {
|
|
4696
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
4697
|
+
return ONGOING_REQUESTS.get(sender);
|
|
4698
|
+
}
|
|
4699
|
+
const ongoingRequests = new Map();
|
|
4700
|
+
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
4701
|
+
return ongoingRequests;
|
|
4702
|
+
};
|
|
4703
|
+
const createBroker = (brokerImplementation) => {
|
|
4704
|
+
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
4705
|
+
return (sender) => {
|
|
4706
|
+
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
4707
|
+
sender.addEventListener('message', (({ data: message }) => {
|
|
4708
|
+
const { id } = message;
|
|
4709
|
+
if (id !== null && ongoingRequests.has(id)) {
|
|
4710
|
+
const { reject, resolve } = ongoingRequests.get(id);
|
|
4711
|
+
ongoingRequests.delete(id);
|
|
4712
|
+
if (message.error === undefined) {
|
|
4713
|
+
resolve(message.result);
|
|
4714
|
+
}
|
|
4715
|
+
else {
|
|
4716
|
+
reject(new Error(message.error.message));
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
}));
|
|
4720
|
+
if (isMessagePort(sender)) {
|
|
4721
|
+
sender.start();
|
|
4722
|
+
}
|
|
4723
|
+
const call = (method, params = null, transferables = []) => {
|
|
4724
|
+
return new Promise((resolve, reject) => {
|
|
4725
|
+
const id = generateUniqueNumber(ongoingRequests);
|
|
4726
|
+
ongoingRequests.set(id, { reject, resolve });
|
|
4727
|
+
if (params === null) {
|
|
4728
|
+
sender.postMessage({ id, method }, transferables);
|
|
4729
|
+
}
|
|
4730
|
+
else {
|
|
4731
|
+
sender.postMessage({ id, method, params }, transferables);
|
|
4732
|
+
}
|
|
4733
|
+
});
|
|
4734
|
+
};
|
|
4735
|
+
const notify = (method, params, transferables = []) => {
|
|
4736
|
+
sender.postMessage({ id: null, method, params }, transferables);
|
|
4737
|
+
};
|
|
4738
|
+
let functions = {};
|
|
4739
|
+
for (const [key, handler] of Object.entries(fullBrokerImplementation)) {
|
|
4740
|
+
functions = { ...functions, [key]: handler({ call, notify }) };
|
|
4741
|
+
}
|
|
4742
|
+
return { ...functions };
|
|
4743
|
+
};
|
|
4744
|
+
};
|
|
4745
|
+
|
|
4746
|
+
// Prefilling the Maps with a function indexed by zero is necessary to be compliant with the specification.
|
|
4747
|
+
const scheduledIntervalsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
4748
|
+
const scheduledTimeoutsState = new Map([[0, null]]); // tslint:disable-line no-empty
|
|
4749
|
+
const wrap = createBroker({
|
|
4750
|
+
clearInterval: ({ call }) => {
|
|
4751
|
+
return (timerId) => {
|
|
4752
|
+
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
4753
|
+
scheduledIntervalsState.set(timerId, null);
|
|
4754
|
+
call('clear', { timerId, timerType: 'interval' }).then(() => {
|
|
4755
|
+
scheduledIntervalsState.delete(timerId);
|
|
4756
|
+
});
|
|
4757
|
+
}
|
|
4758
|
+
};
|
|
4759
|
+
},
|
|
4760
|
+
clearTimeout: ({ call }) => {
|
|
4761
|
+
return (timerId) => {
|
|
4762
|
+
if (typeof scheduledTimeoutsState.get(timerId) === 'symbol') {
|
|
4763
|
+
scheduledTimeoutsState.set(timerId, null);
|
|
4764
|
+
call('clear', { timerId, timerType: 'timeout' }).then(() => {
|
|
4765
|
+
scheduledTimeoutsState.delete(timerId);
|
|
4766
|
+
});
|
|
4767
|
+
}
|
|
4768
|
+
};
|
|
4769
|
+
},
|
|
4770
|
+
setInterval: ({ call }) => {
|
|
4771
|
+
return (func, delay = 0, ...args) => {
|
|
4772
|
+
const symbol = Symbol();
|
|
4773
|
+
const timerId = generateUniqueNumber(scheduledIntervalsState);
|
|
4774
|
+
scheduledIntervalsState.set(timerId, symbol);
|
|
4775
|
+
const schedule = () => call('set', {
|
|
4776
|
+
delay,
|
|
4777
|
+
now: performance.timeOrigin + performance.now(),
|
|
4778
|
+
timerId,
|
|
4779
|
+
timerType: 'interval'
|
|
4780
|
+
}).then(() => {
|
|
4781
|
+
const state = scheduledIntervalsState.get(timerId);
|
|
4782
|
+
if (state === undefined) {
|
|
4783
|
+
throw new Error('The timer is in an undefined state.');
|
|
4784
|
+
}
|
|
4785
|
+
if (state === symbol) {
|
|
4786
|
+
func(...args);
|
|
4787
|
+
// Doublecheck if the interval should still be rescheduled because it could have been cleared inside of func().
|
|
4788
|
+
if (scheduledIntervalsState.get(timerId) === symbol) {
|
|
4789
|
+
schedule();
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
});
|
|
4793
|
+
schedule();
|
|
4794
|
+
return timerId;
|
|
4795
|
+
};
|
|
4796
|
+
},
|
|
4797
|
+
setTimeout: ({ call }) => {
|
|
4798
|
+
return (func, delay = 0, ...args) => {
|
|
4799
|
+
const symbol = Symbol();
|
|
4800
|
+
const timerId = generateUniqueNumber(scheduledTimeoutsState);
|
|
4801
|
+
scheduledTimeoutsState.set(timerId, symbol);
|
|
4802
|
+
call('set', {
|
|
4803
|
+
delay,
|
|
4804
|
+
now: performance.timeOrigin + performance.now(),
|
|
4805
|
+
timerId,
|
|
4806
|
+
timerType: 'timeout'
|
|
4807
|
+
}).then(() => {
|
|
4808
|
+
const state = scheduledTimeoutsState.get(timerId);
|
|
4809
|
+
if (state === undefined) {
|
|
4810
|
+
throw new Error('The timer is in an undefined state.');
|
|
4811
|
+
}
|
|
4812
|
+
if (state === symbol) {
|
|
4813
|
+
// A timeout can be savely deleted because it is only called once.
|
|
4814
|
+
scheduledTimeoutsState.delete(timerId);
|
|
4815
|
+
func(...args);
|
|
4816
|
+
}
|
|
4817
|
+
});
|
|
4818
|
+
return timerId;
|
|
4819
|
+
};
|
|
4820
|
+
}
|
|
4821
|
+
});
|
|
4822
|
+
const load = (url) => {
|
|
4823
|
+
const worker = new Worker(url);
|
|
4824
|
+
return wrap(worker);
|
|
4825
|
+
};
|
|
4826
|
+
|
|
4827
|
+
const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
4828
|
+
let broker = null;
|
|
4829
|
+
return () => {
|
|
4830
|
+
if (broker !== null) {
|
|
4831
|
+
return broker;
|
|
4832
|
+
}
|
|
4833
|
+
const blob = new Blob([worker], { type: 'application/javascript; charset=utf-8' });
|
|
4834
|
+
const url = URL.createObjectURL(blob);
|
|
4835
|
+
broker = loadBroker(url);
|
|
4836
|
+
// Bug #1: Edge up until v18 didn't like the URL to be revoked directly.
|
|
4837
|
+
setTimeout(() => URL.revokeObjectURL(url));
|
|
4838
|
+
return broker;
|
|
4839
|
+
};
|
|
4840
|
+
};
|
|
4841
|
+
|
|
4842
|
+
// This is the minified and stringified code of the worker-timers-worker package.
|
|
4843
|
+
const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),d=t(c);e.addUniqueNumber=d,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const d=r instanceof Promise?await r:r;if(null===a){if(void 0!==d.result)throw s(i)}else{if(void 0===d.result)throw s(i);const{result:e,transferables:r=[]}=d;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,(()=>{n(),t.close(),u.delete(o)})),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise((e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])}))){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),d=(e,t,r=()=>!0)=>{const n=c(d,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},l=e=>t=>{const r=e.get(t);if(void 0===r)return Promise.resolve(!1);const[n,o]=r;return clearTimeout(n),e.delete(t),o(!1),Promise.resolve(!0)},f=(e,t,r)=>(n,o,s)=>{const{expected:a,remainingDelay:i}=e(n,o);return new Promise((e=>{t.set(s,[setTimeout(r,i,a,t,e,s),e])}))},m=(e,t)=>{const r=performance.now(),n=e+t-r-performance.timeOrigin;return{expected:r+n,remainingDelay:n}},p=(e,t,r,n)=>{const o=e-performance.now();o>0?t.set(n,[setTimeout(p,o,e,t,r,n),r]):(t.delete(n),r(!0))},h=new Map,v=l(h),w=new Map,g=l(w),M=f(m,h,p),y=f(m,w,p);d(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?v(e):g(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?M:y)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
|
|
4844
|
+
|
|
4845
|
+
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
4846
|
+
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
4847
|
+
const clearTimeout = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
4848
|
+
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
4849
|
+
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
4850
|
+
|
|
4606
4851
|
// ==UserScript==
|
|
4607
4852
|
// @name ModuleRaid.js
|
|
4608
4853
|
// @namespace http://tampermonkey.net/
|
|
@@ -5007,7 +5252,7 @@ define((function () { 'use strict';
|
|
|
5007
5252
|
this.windowApi = new WindowApi(option);
|
|
5008
5253
|
}
|
|
5009
5254
|
/** 版本号 */
|
|
5010
|
-
version = "2025.
|
|
5255
|
+
version = "2025.5.26";
|
|
5011
5256
|
addStyle(cssText) {
|
|
5012
5257
|
if (typeof cssText !== "string") {
|
|
5013
5258
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5252,11 +5497,11 @@ define((function () { 'use strict';
|
|
|
5252
5497
|
}
|
|
5253
5498
|
debounce(fn, delay = 0) {
|
|
5254
5499
|
let timer = null;
|
|
5255
|
-
|
|
5500
|
+
let UtilsContext = this;
|
|
5256
5501
|
return function (...args) {
|
|
5257
|
-
|
|
5258
|
-
timer =
|
|
5259
|
-
fn.apply(
|
|
5502
|
+
UtilsContext.workerClearTimeout(timer);
|
|
5503
|
+
timer = UtilsContext.workerSetTimeout(function () {
|
|
5504
|
+
fn.apply(UtilsContext, args);
|
|
5260
5505
|
}, delay);
|
|
5261
5506
|
};
|
|
5262
5507
|
}
|
|
@@ -5293,6 +5538,7 @@ define((function () { 'use strict';
|
|
|
5293
5538
|
**/
|
|
5294
5539
|
Dictionary = UtilsDictionary;
|
|
5295
5540
|
dispatchEvent(element, eventName, details) {
|
|
5541
|
+
// let UtilsContext = this;
|
|
5296
5542
|
let eventNameList = [];
|
|
5297
5543
|
if (typeof eventName === "string") {
|
|
5298
5544
|
eventNameList = [eventName];
|
|
@@ -5309,6 +5555,7 @@ define((function () { 'use strict';
|
|
|
5309
5555
|
});
|
|
5310
5556
|
}
|
|
5311
5557
|
downloadBase64(base64Data, fileName, isIFrame = false) {
|
|
5558
|
+
let UtilsContext = this;
|
|
5312
5559
|
if (typeof base64Data !== "string") {
|
|
5313
5560
|
throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
|
|
5314
5561
|
}
|
|
@@ -5321,7 +5568,7 @@ define((function () { 'use strict';
|
|
|
5321
5568
|
iframeElement.style.display = "none";
|
|
5322
5569
|
iframeElement.src = base64Data;
|
|
5323
5570
|
this.windowApi.document.body.appendChild(iframeElement);
|
|
5324
|
-
|
|
5571
|
+
UtilsContext.workerSetTimeout(() => {
|
|
5325
5572
|
iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
5326
5573
|
this.windowApi.document.body.removeChild(iframeElement);
|
|
5327
5574
|
}, 100);
|
|
@@ -7279,17 +7526,18 @@ define((function () { 'use strict';
|
|
|
7279
7526
|
throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
|
|
7280
7527
|
}
|
|
7281
7528
|
return new Promise((resolve) => {
|
|
7282
|
-
|
|
7529
|
+
UtilsContext.workerSetTimeout(() => {
|
|
7283
7530
|
resolve(UtilsContext.tryCatch().run(callback));
|
|
7284
7531
|
}, delayTime);
|
|
7285
7532
|
});
|
|
7286
7533
|
}
|
|
7287
7534
|
sleep(delayTime = 0) {
|
|
7535
|
+
let UtilsContext = this;
|
|
7288
7536
|
if (typeof delayTime !== "number") {
|
|
7289
7537
|
throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
|
|
7290
7538
|
}
|
|
7291
7539
|
return new Promise((resolve) => {
|
|
7292
|
-
|
|
7540
|
+
UtilsContext.workerSetTimeout(() => {
|
|
7293
7541
|
resolve(undefined);
|
|
7294
7542
|
}, delayTime);
|
|
7295
7543
|
});
|
|
@@ -7653,7 +7901,7 @@ define((function () { 'use strict';
|
|
|
7653
7901
|
},
|
|
7654
7902
|
});
|
|
7655
7903
|
if (__timeout__ > 0) {
|
|
7656
|
-
|
|
7904
|
+
UtilsContext.workerSetTimeout(() => {
|
|
7657
7905
|
// 取消观察器
|
|
7658
7906
|
if (typeof observer?.disconnect === "function") {
|
|
7659
7907
|
observer.disconnect();
|
|
@@ -7975,12 +8223,13 @@ define((function () { 'use strict';
|
|
|
7975
8223
|
});
|
|
7976
8224
|
}
|
|
7977
8225
|
waitPropertyByInterval(checkObj, checkPropertyName, intervalTimer = 250, maxTime = -1) {
|
|
8226
|
+
let UtilsContext = this;
|
|
7978
8227
|
if (checkObj == null) {
|
|
7979
8228
|
throw new TypeError("checkObj 不能为空对象 ");
|
|
7980
8229
|
}
|
|
7981
8230
|
let isResolve = false;
|
|
7982
8231
|
return new Promise((resolve, reject) => {
|
|
7983
|
-
let interval =
|
|
8232
|
+
let interval = UtilsContext.workerSetInterval(() => {
|
|
7984
8233
|
let obj = checkObj;
|
|
7985
8234
|
if (typeof checkObj === "function") {
|
|
7986
8235
|
obj = checkObj();
|
|
@@ -7994,14 +8243,14 @@ define((function () { 'use strict';
|
|
|
7994
8243
|
if ((typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
|
|
7995
8244
|
Reflect.has(obj, checkPropertyName)) {
|
|
7996
8245
|
isResolve = true;
|
|
7997
|
-
|
|
8246
|
+
UtilsContext.workerClearInterval(interval);
|
|
7998
8247
|
resolve(obj[checkPropertyName]);
|
|
7999
8248
|
}
|
|
8000
8249
|
}, intervalTimer);
|
|
8001
8250
|
if (maxTime !== -1) {
|
|
8002
|
-
|
|
8251
|
+
UtilsContext.workerSetTimeout(() => {
|
|
8003
8252
|
if (!isResolve) {
|
|
8004
|
-
|
|
8253
|
+
UtilsContext.workerClearInterval(interval);
|
|
8005
8254
|
reject();
|
|
8006
8255
|
}
|
|
8007
8256
|
}, maxTime);
|
|
@@ -8212,6 +8461,64 @@ define((function () { 'use strict';
|
|
|
8212
8461
|
*/
|
|
8213
8462
|
Vue = Vue;
|
|
8214
8463
|
ModuleRaid = ModuleRaid;
|
|
8464
|
+
/**
|
|
8465
|
+
* 自动使用 Worker 执行 setTimeout
|
|
8466
|
+
* @param callback 回调函数
|
|
8467
|
+
* @param [timeout=0] 延迟时间,默认为0
|
|
8468
|
+
*/
|
|
8469
|
+
workerSetTimeout(callback, timeout = 0) {
|
|
8470
|
+
try {
|
|
8471
|
+
return setTimeout$1(callback, timeout);
|
|
8472
|
+
}
|
|
8473
|
+
catch (error) {
|
|
8474
|
+
return globalThis.setTimeout(callback, timeout);
|
|
8475
|
+
}
|
|
8476
|
+
}
|
|
8477
|
+
/**
|
|
8478
|
+
* 配合 .setTimeout 使用
|
|
8479
|
+
* @param timeId setTimeout 返回的`id`
|
|
8480
|
+
*/
|
|
8481
|
+
workerClearTimeout(timeId) {
|
|
8482
|
+
try {
|
|
8483
|
+
if (timeId != null) {
|
|
8484
|
+
clearTimeout(timeId);
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8487
|
+
catch (error) {
|
|
8488
|
+
}
|
|
8489
|
+
finally {
|
|
8490
|
+
globalThis.clearTimeout(timeId);
|
|
8491
|
+
}
|
|
8492
|
+
}
|
|
8493
|
+
/**
|
|
8494
|
+
* 自动使用 Worker 执行 setInterval
|
|
8495
|
+
* @param callback 回调函数
|
|
8496
|
+
* @param timeout 间隔时间,默认为0
|
|
8497
|
+
*/
|
|
8498
|
+
workerSetInterval(callback, timeout = 0) {
|
|
8499
|
+
try {
|
|
8500
|
+
return setInterval(callback, timeout);
|
|
8501
|
+
}
|
|
8502
|
+
catch (error) {
|
|
8503
|
+
return globalThis.setInterval(callback, timeout);
|
|
8504
|
+
}
|
|
8505
|
+
}
|
|
8506
|
+
/**
|
|
8507
|
+
* 配合 .setInterval 使用
|
|
8508
|
+
* @param timeId setInterval 返回的`id`
|
|
8509
|
+
*/
|
|
8510
|
+
workerClearInterval(timeId) {
|
|
8511
|
+
try {
|
|
8512
|
+
if (timeId != null) {
|
|
8513
|
+
clearInterval(timeId);
|
|
8514
|
+
}
|
|
8515
|
+
}
|
|
8516
|
+
catch (error) {
|
|
8517
|
+
}
|
|
8518
|
+
finally {
|
|
8519
|
+
globalThis.clearInterval(timeId);
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8215
8522
|
}
|
|
8216
8523
|
let utils = new Utils();
|
|
8217
8524
|
|