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