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