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.
@@ -459,7 +459,37 @@ const fullscreenHelper = {
459
459
  document.removeEventListener("msfullscreenchange", handler);
460
460
  };
461
461
  }
462
- };
462
+ };
463
+
464
+ /**
465
+ * 复制文本到剪贴板
466
+ * @param {String} text
467
+ * @returns {Promise<void>}
468
+ */
469
+ async function copyTextToClipboard(text) {
470
+ if (window.navigator.clipboard) {
471
+ await window.navigator.clipboard.writeText(text);
472
+ return;
473
+ }
474
+
475
+ return new Promise((resolve, reject) => {
476
+ const ta = document.createElement("textarea");
477
+ ta.value = text;
478
+ ta.style.position = "fixed"; // 防止滚动
479
+ ta.style.opacity = "0";
480
+ document.body.appendChild(ta);
481
+ ta.focus();
482
+ ta.select();
483
+
484
+ try {
485
+ document.execCommand("copy") ? resolve() : reject(new Error("execCommand failed"));
486
+ } catch (err) {
487
+ reject(err);
488
+ } finally {
489
+ document.body.removeChild(ta);
490
+ }
491
+ });
492
+ }
463
493
 
464
494
  //#region 数据类型判断
465
495
 
@@ -1791,6 +1821,10 @@ class IntervalTimer {
1791
1821
  this._fn = fn;
1792
1822
  this._ms = ms;
1793
1823
  this._timerId = null;
1824
+ /**
1825
+ * @type {symbol | null}
1826
+ */
1827
+ this._loopId = null;
1794
1828
  }
1795
1829
 
1796
1830
  /**
@@ -1799,8 +1833,17 @@ class IntervalTimer {
1799
1833
  */
1800
1834
  start() {
1801
1835
  this.stop();
1836
+
1837
+ const curLoopId = Symbol();
1838
+ this._loopId = curLoopId;
1839
+
1802
1840
  const loop = () => {
1841
+ if (this._loopId !== curLoopId) return;
1842
+
1803
1843
  this._fn(); // 执行业务
1844
+
1845
+ if (this._loopId !== curLoopId) return;
1846
+
1804
1847
  this._timerId = setTimeout(loop, this._ms);
1805
1848
  };
1806
1849
  loop(); // 立即执行第一次
@@ -1810,6 +1853,7 @@ class IntervalTimer {
1810
1853
  * 停止定时器。
1811
1854
  */
1812
1855
  stop() {
1856
+ this._loopId = null;
1813
1857
  if (this._timerId !== null) {
1814
1858
  clearTimeout(this._timerId);
1815
1859
  this._timerId = null;
@@ -2469,5 +2513,5 @@ class WebSocketManager {
2469
2513
  }
2470
2514
  }
2471
2515
 
2472
- export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting, debounce, deepCloneByJSON, downloadByBlob, downloadByData, downloadByUrl, downloadExcel, downloadJSON, extractFullyCheckedKeys, fetchOrDownloadByUrl, findObjAttrValueById, findTreeNodeById, findTreeNodePath, flatCompleteTree2NestedTree, formatTimeForLocale, fullscreenHelper, getAllSearchParams, getDataType, getFunctionArgNames, getGUID, getSearchParam, getTimePeriodName, getViewportSize, handleDbMenuItems, isBlob, isDate, isFunction, isNonEmptyString, isPlainObject, isPromise, millisecond2Duration, millisecond2DurationMaxDay, millisecond2DurationMaxHour, moveItem, nestedTree2IdMap, pcmToWavBlob, randomDateInRange, randomEnLetter, randomHan, randomHanOrEn, randomIntInRange, readBlobAsText, second2Duration, second2DurationMaxDay, second2DurationMaxHour, shuffle, throttle, toDate };
2516
+ export { AudioStreamResampler, IntervalTimer, MyEvent, MyEvent_CrossPagePlugin, MyId, WebSocketManager, assignExisting, copyTextToClipboard, debounce, deepCloneByJSON, downloadByBlob, downloadByData, downloadByUrl, downloadExcel, downloadJSON, extractFullyCheckedKeys, fetchOrDownloadByUrl, findObjAttrValueById, findTreeNodeById, findTreeNodePath, flatCompleteTree2NestedTree, formatTimeForLocale, fullscreenHelper, getAllSearchParams, getDataType, getFunctionArgNames, getGUID, getSearchParam, getTimePeriodName, getViewportSize, handleDbMenuItems, isBlob, isDate, isFunction, isNonEmptyString, isPlainObject, isPromise, millisecond2Duration, millisecond2DurationMaxDay, millisecond2DurationMaxHour, moveItem, nestedTree2IdMap, pcmToWavBlob, randomDateInRange, randomEnLetter, randomHan, randomHanOrEn, randomIntInRange, readBlobAsText, second2Duration, second2DurationMaxDay, second2DurationMaxHour, shuffle, throttle, toDate };
2473
2517
  //# sourceMappingURL=a2bei4.utils.esm.js.map