a2bei4-utils 1.0.8 → 1.0.9

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.
@@ -465,7 +465,37 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
465
465
  document.removeEventListener("msfullscreenchange", handler);
466
466
  };
467
467
  }
468
- };
468
+ };
469
+
470
+ /**
471
+ * 复制文本到剪贴板
472
+ * @param {String} text
473
+ * @returns {Promise<void>}
474
+ */
475
+ async function copyTextToClipboard(text) {
476
+ if (window.navigator.clipboard) {
477
+ await window.navigator.clipboard.writeText(text);
478
+ return;
479
+ }
480
+
481
+ return new Promise((resolve, reject) => {
482
+ const ta = document.createElement("textarea");
483
+ ta.value = text;
484
+ ta.style.position = "fixed"; // 防止滚动
485
+ ta.style.opacity = "0";
486
+ document.body.appendChild(ta);
487
+ ta.focus();
488
+ ta.select();
489
+
490
+ try {
491
+ document.execCommand("copy") ? resolve() : reject(new Error("execCommand failed"));
492
+ } catch (err) {
493
+ reject(err);
494
+ } finally {
495
+ document.body.removeChild(ta);
496
+ }
497
+ });
498
+ }
469
499
 
470
500
  //#region 数据类型判断
471
501
 
@@ -2482,6 +2512,7 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
2482
2512
  exports.MyId = MyId;
2483
2513
  exports.WebSocketManager = WebSocketManager;
2484
2514
  exports.assignExisting = assignExisting;
2515
+ exports.copyTextToClipboard = copyTextToClipboard;
2485
2516
  exports.debounce = debounce;
2486
2517
  exports.deepCloneByJSON = deepCloneByJSON;
2487
2518
  exports.downloadByBlob = downloadByBlob;