@whitesev/utils 2.11.0 → 2.11.1
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 +28 -8
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +28 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +28 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +28 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +28 -8
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +28 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/Utils.ts +27 -7
|
@@ -1617,8 +1617,9 @@ declare class Utils {
|
|
|
1617
1617
|
}) => any;
|
|
1618
1618
|
/**
|
|
1619
1619
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
1620
|
+
* @param timeout 超时时间,默认为`1500ms`
|
|
1620
1621
|
*/
|
|
1621
|
-
hasWorkerCSP(): Promise<boolean>;
|
|
1622
|
+
hasWorkerCSP(timeout?: number): Promise<boolean>;
|
|
1622
1623
|
}
|
|
1623
1624
|
declare const utils: Utils;
|
|
1624
1625
|
export { utils as Utils };
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -3868,10 +3868,13 @@ class Utils {
|
|
|
3868
3868
|
}
|
|
3869
3869
|
/**
|
|
3870
3870
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
3871
|
+
* @param timeout 超时时间,默认为`1500ms`
|
|
3871
3872
|
*/
|
|
3872
|
-
hasWorkerCSP() {
|
|
3873
|
+
hasWorkerCSP(timeout: number = 1500) {
|
|
3873
3874
|
return new Promise<boolean>((resolve) => {
|
|
3874
3875
|
let flag = true;
|
|
3876
|
+
let timeId: number | undefined = void 0;
|
|
3877
|
+
let worker: Worker | undefined = void 0;
|
|
3875
3878
|
let workerBlobUrl: string | undefined = void 0;
|
|
3876
3879
|
|
|
3877
3880
|
const workerJs = /*js*/ `
|
|
@@ -3888,11 +3891,26 @@ class Utils {
|
|
|
3888
3891
|
}
|
|
3889
3892
|
);
|
|
3890
3893
|
})();`;
|
|
3894
|
+
/**
|
|
3895
|
+
* 返回结果
|
|
3896
|
+
*/
|
|
3897
|
+
const finishCallBack = () => {
|
|
3898
|
+
clearTimeout(timeId);
|
|
3899
|
+
if (worker != null) {
|
|
3900
|
+
worker.terminate();
|
|
3901
|
+
}
|
|
3902
|
+
// 释放
|
|
3903
|
+
if (typeof workerBlobUrl === "string") {
|
|
3904
|
+
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
3905
|
+
workerBlobUrl = void 0;
|
|
3906
|
+
}
|
|
3907
|
+
resolve(flag);
|
|
3908
|
+
};
|
|
3891
3909
|
try {
|
|
3892
3910
|
const workerScript = new Blob([workerJs], {
|
|
3893
3911
|
type: "application/javascript",
|
|
3894
3912
|
});
|
|
3895
|
-
workerBlobUrl =
|
|
3913
|
+
workerBlobUrl = globalThis.URL.createObjectURL(workerScript);
|
|
3896
3914
|
// @ts-expect-error
|
|
3897
3915
|
if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
|
|
3898
3916
|
// 使用这个后虽然不报错,但是仍会有blob错误
|
|
@@ -3904,23 +3922,25 @@ class Utils {
|
|
|
3904
3922
|
});
|
|
3905
3923
|
workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
|
|
3906
3924
|
}
|
|
3907
|
-
|
|
3925
|
+
worker = new Worker(workerBlobUrl!);
|
|
3908
3926
|
worker.onmessage = (data) => {
|
|
3909
3927
|
if (data.data.success) {
|
|
3910
3928
|
flag = false;
|
|
3929
|
+
finishCallBack();
|
|
3911
3930
|
}
|
|
3912
3931
|
};
|
|
3913
|
-
setTimeout(() => {
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
}, 500);
|
|
3932
|
+
timeId = setTimeout(() => {
|
|
3933
|
+
finishCallBack();
|
|
3934
|
+
}, timeout);
|
|
3917
3935
|
worker.postMessage("test");
|
|
3918
3936
|
} catch {
|
|
3919
3937
|
flag = true;
|
|
3938
|
+
finishCallBack();
|
|
3920
3939
|
} finally {
|
|
3921
3940
|
// 释放
|
|
3922
3941
|
if (typeof workerBlobUrl === "string") {
|
|
3923
3942
|
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
3943
|
+
workerBlobUrl = void 0;
|
|
3924
3944
|
}
|
|
3925
3945
|
}
|
|
3926
3946
|
});
|