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