@minto-ai/tools 1.0.53 → 1.0.56

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.
@@ -3,4 +3,5 @@ import { default as isAndroid } from './is-android';
3
3
  import { default as isIos } from './is-ios';
4
4
  import { default as isMobile } from './is-mobile';
5
5
  import { default as isPc } from './is-pc';
6
- export { copyText, isAndroid, isIos, isMobile, isPc };
6
+ import { default as waitForUserInteraction } from './wait-for-user-interaction';
7
+ export { copyText, isAndroid, isIos, isMobile, isPc, waitForUserInteraction };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 等待用户交互的Promise函数
3
+ * 创建AudioContext检测是否已有用户交互,如果没有则监听多种用户交互事件
4
+ * @returns {Promise<boolean>} 返回Promise,用户交互后resolve为true,超时后resolve为false
5
+ */
6
+ declare function waitForUserInteraction(): Promise<boolean>;
7
+ export default waitForUserInteraction;
package/dist/index.js CHANGED
@@ -13252,6 +13252,47 @@ function isMobile() {
13252
13252
  function isPc() {
13253
13253
  return !isMobile();
13254
13254
  }
13255
+ function waitForUserInteraction() {
13256
+ return new Promise(function(resolve2) {
13257
+ var audioContext = new (window.AudioContext || window.webkitAudioContext)();
13258
+ if (audioContext.state === "running") {
13259
+ audioContext.close();
13260
+ resolve2(true);
13261
+ return;
13262
+ }
13263
+ var interactionEvents = ["click", "touchstart", "touchend", "keydown", "mousedown", "pointerdown"];
13264
+ var timeoutId = null;
13265
+ var isResolved = false;
13266
+ function handleInteraction() {
13267
+ if (isResolved) {
13268
+ return;
13269
+ }
13270
+ isResolved = true;
13271
+ if (timeoutId) {
13272
+ clearTimeout(timeoutId);
13273
+ }
13274
+ interactionEvents.forEach(function(eventType) {
13275
+ document.removeEventListener(eventType, handleInteraction);
13276
+ });
13277
+ resolve2(true);
13278
+ }
13279
+ timeoutId = setTimeout(function() {
13280
+ if (isResolved) {
13281
+ return;
13282
+ }
13283
+ isResolved = true;
13284
+ interactionEvents.forEach(function(eventType) {
13285
+ document.removeEventListener(eventType, handleInteraction);
13286
+ });
13287
+ resolve2(false);
13288
+ }, 1e4);
13289
+ interactionEvents.forEach(function(eventType) {
13290
+ document.addEventListener(eventType, handleInteraction, {
13291
+ passive: true
13292
+ });
13293
+ });
13294
+ });
13295
+ }
13255
13296
  function isNumber(value) {
13256
13297
  return typeof value === "number";
13257
13298
  }
@@ -16092,26 +16133,6 @@ function useTheme() {
16092
16133
  toggleTheme
16093
16134
  };
16094
16135
  }
16095
- function watchSystemTheme() {
16096
- if (typeof window === "undefined") {
16097
- return;
16098
- }
16099
- var mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
16100
- var handleChange = function handleChange2(event) {
16101
- if (!getStoredTheme()) {
16102
- var systemTheme = event.matches ? "dark" : "light";
16103
- currentTheme.value = systemTheme;
16104
- applyTheme(systemTheme);
16105
- }
16106
- };
16107
- mediaQuery.addEventListener("change", handleChange);
16108
- return function() {
16109
- mediaQuery.removeEventListener("change", handleChange);
16110
- };
16111
- }
16112
- if (typeof window !== "undefined") {
16113
- watchSystemTheme();
16114
- }
16115
16136
  function isValidUrl(url) {
16116
16137
  if (!isString$1(url)) {
16117
16138
  return false;
@@ -16202,5 +16223,5 @@ export {
16202
16223
  timeDelay,
16203
16224
  updateFilePathQuery,
16204
16225
  useTheme,
16205
- watchSystemTheme
16226
+ waitForUserInteraction
16206
16227
  };
@@ -21,4 +21,3 @@ export declare function useTheme(): {
21
21
  * 监听系统主题变化
22
22
  * @returns {(() => void) | undefined} 清理函数或undefined
23
23
  */
24
- export declare function watchSystemTheme(): (() => void) | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@minto-ai/tools",
3
3
  "type": "module",
4
- "version": "1.0.53",
4
+ "version": "1.0.56",
5
5
  "description": "明途公共工具库",
6
6
  "author": "hcc",
7
7
  "license": "ISC",