@whitesev/utils 2.6.7 → 2.6.8
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 +69 -1
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +69 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +69 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +69 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +69 -1
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +69 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +13 -0
- package/package.json +1 -1
- package/src/Utils.ts +81 -1
package/dist/index.system.js
CHANGED
|
@@ -5255,7 +5255,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5255
5255
|
this.windowApi = new WindowApi(option);
|
|
5256
5256
|
}
|
|
5257
5257
|
/** 版本号 */
|
|
5258
|
-
version = "2025.5.
|
|
5258
|
+
version = "2025.5.28";
|
|
5259
5259
|
addStyle(cssText) {
|
|
5260
5260
|
if (typeof cssText !== "string") {
|
|
5261
5261
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -8522,6 +8522,74 @@ System.register('Utils', [], (function (exports) {
|
|
|
8522
8522
|
globalThis.clearInterval(timeId);
|
|
8523
8523
|
}
|
|
8524
8524
|
}
|
|
8525
|
+
/**
|
|
8526
|
+
* 获取剪贴板信息
|
|
8527
|
+
*/
|
|
8528
|
+
async getClipboardInfo() {
|
|
8529
|
+
return new Promise((resolve) => {
|
|
8530
|
+
/** 读取剪贴板 */
|
|
8531
|
+
function readClipboardText() {
|
|
8532
|
+
navigator.clipboard
|
|
8533
|
+
.readText()
|
|
8534
|
+
.then((clipboardText) => {
|
|
8535
|
+
resolve({
|
|
8536
|
+
error: null,
|
|
8537
|
+
content: clipboardText,
|
|
8538
|
+
});
|
|
8539
|
+
})
|
|
8540
|
+
.catch((error) => {
|
|
8541
|
+
resolve({
|
|
8542
|
+
error: error,
|
|
8543
|
+
content: "",
|
|
8544
|
+
});
|
|
8545
|
+
});
|
|
8546
|
+
}
|
|
8547
|
+
/** 申请读取剪贴板的权限 */
|
|
8548
|
+
function requestPermissionsWithClipboard() {
|
|
8549
|
+
navigator.permissions
|
|
8550
|
+
.query({
|
|
8551
|
+
// @ts-ignore
|
|
8552
|
+
name: "clipboard-read",
|
|
8553
|
+
})
|
|
8554
|
+
.then((permissionStatus) => {
|
|
8555
|
+
readClipboardText();
|
|
8556
|
+
})
|
|
8557
|
+
.catch((error) => {
|
|
8558
|
+
/* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
|
|
8559
|
+
readClipboardText();
|
|
8560
|
+
});
|
|
8561
|
+
}
|
|
8562
|
+
/**
|
|
8563
|
+
* 检查当前环境是否支持读取剪贴板Api
|
|
8564
|
+
*/
|
|
8565
|
+
function checkClipboardApi() {
|
|
8566
|
+
if (typeof navigator?.clipboard?.readText !== "function") {
|
|
8567
|
+
return false;
|
|
8568
|
+
}
|
|
8569
|
+
if (typeof navigator?.permissions?.query !== "function") {
|
|
8570
|
+
return false;
|
|
8571
|
+
}
|
|
8572
|
+
return true;
|
|
8573
|
+
}
|
|
8574
|
+
if (!checkClipboardApi()) {
|
|
8575
|
+
resolve({
|
|
8576
|
+
error: new Error("当前环境不支持读取剪贴板Api"),
|
|
8577
|
+
content: "",
|
|
8578
|
+
});
|
|
8579
|
+
return;
|
|
8580
|
+
}
|
|
8581
|
+
if (document.hasFocus()) {
|
|
8582
|
+
requestPermissionsWithClipboard();
|
|
8583
|
+
}
|
|
8584
|
+
else {
|
|
8585
|
+
window.addEventListener("focus", () => {
|
|
8586
|
+
requestPermissionsWithClipboard();
|
|
8587
|
+
}, {
|
|
8588
|
+
once: true,
|
|
8589
|
+
});
|
|
8590
|
+
}
|
|
8591
|
+
});
|
|
8592
|
+
}
|
|
8525
8593
|
}
|
|
8526
8594
|
let utils = exports("default", new Utils());
|
|
8527
8595
|
|