a2bei4-utils 1.0.8 → 1.0.10
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/a2bei4.utils.cjs.js +46 -1
- package/dist/a2bei4.utils.cjs.js.map +1 -1
- package/dist/a2bei4.utils.cjs.min.js +1 -1
- package/dist/a2bei4.utils.cjs.min.js.map +1 -1
- package/dist/a2bei4.utils.esm.js +46 -2
- package/dist/a2bei4.utils.esm.js.map +1 -1
- package/dist/a2bei4.utils.esm.min.js +1 -1
- package/dist/a2bei4.utils.esm.min.js.map +1 -1
- package/dist/a2bei4.utils.umd.js +46 -1
- package/dist/a2bei4.utils.umd.js.map +1 -1
- package/dist/a2bei4.utils.umd.min.js +1 -1
- package/dist/a2bei4.utils.umd.min.js.map +1 -1
- package/dist/browser.cjs +32 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +32 -2
- package/dist/browser.js.map +1 -1
- package/dist/timer.cjs +14 -0
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.js +14 -0
- package/dist/timer.js.map +1 -1
- package/package.json +5 -5
- package/readme.txt +2 -1
- package/types/browser.d.ts +7 -1
- package/types/index.d.ts +12 -2
- package/types/timer.d.ts +4 -0
package/dist/a2bei4.utils.umd.js
CHANGED
|
@@ -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
|
|
|
@@ -1797,6 +1827,10 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
|
|
|
1797
1827
|
this._fn = fn;
|
|
1798
1828
|
this._ms = ms;
|
|
1799
1829
|
this._timerId = null;
|
|
1830
|
+
/**
|
|
1831
|
+
* @type {symbol | null}
|
|
1832
|
+
*/
|
|
1833
|
+
this._loopId = null;
|
|
1800
1834
|
}
|
|
1801
1835
|
|
|
1802
1836
|
/**
|
|
@@ -1805,8 +1839,17 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
|
|
|
1805
1839
|
*/
|
|
1806
1840
|
start() {
|
|
1807
1841
|
this.stop();
|
|
1842
|
+
|
|
1843
|
+
const curLoopId = Symbol();
|
|
1844
|
+
this._loopId = curLoopId;
|
|
1845
|
+
|
|
1808
1846
|
const loop = () => {
|
|
1847
|
+
if (this._loopId !== curLoopId) return;
|
|
1848
|
+
|
|
1809
1849
|
this._fn(); // 执行业务
|
|
1850
|
+
|
|
1851
|
+
if (this._loopId !== curLoopId) return;
|
|
1852
|
+
|
|
1810
1853
|
this._timerId = setTimeout(loop, this._ms);
|
|
1811
1854
|
};
|
|
1812
1855
|
loop(); // 立即执行第一次
|
|
@@ -1816,6 +1859,7 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
|
|
|
1816
1859
|
* 停止定时器。
|
|
1817
1860
|
*/
|
|
1818
1861
|
stop() {
|
|
1862
|
+
this._loopId = null;
|
|
1819
1863
|
if (this._timerId !== null) {
|
|
1820
1864
|
clearTimeout(this._timerId);
|
|
1821
1865
|
this._timerId = null;
|
|
@@ -2482,6 +2526,7 @@ registerProcessor('audio-stream-resampler-processor', AudioStreamResamplerProces
|
|
|
2482
2526
|
exports.MyId = MyId;
|
|
2483
2527
|
exports.WebSocketManager = WebSocketManager;
|
|
2484
2528
|
exports.assignExisting = assignExisting;
|
|
2529
|
+
exports.copyTextToClipboard = copyTextToClipboard;
|
|
2485
2530
|
exports.debounce = debounce;
|
|
2486
2531
|
exports.deepCloneByJSON = deepCloneByJSON;
|
|
2487
2532
|
exports.downloadByBlob = downloadByBlob;
|