@seaverse/auth-sdk 0.4.0 → 0.4.1

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/README.md CHANGED
@@ -570,8 +570,22 @@ Toast.success('操作成功', '数据已保存');
570
570
  Toast.error('操作失败', '请稍后重试');
571
571
  Toast.warning('注意', '账号已存在');
572
572
  Toast.info('提示', '邮件已发送');
573
+
574
+ // 自定义显示时长(默认 3000ms)
575
+ Toast.success('操作成功', '数据已保存', 5000);
573
576
  ```
574
577
 
578
+ **🎯 智能交互特性**
579
+
580
+ Toast 提供了智能的用户交互体验:
581
+
582
+ - **Hover 暂停**:当鼠标悬停在 Toast 上时,自动暂停倒计时,让用户有足够时间阅读消息
583
+ - **离开继续**:鼠标移开后,继续倒计时并自动消失
584
+ - **手动关闭**:点击右上角的关闭按钮可立即关闭通知
585
+ - **自动消失**:默认 3 秒后自动消失(可自定义时长)
586
+
587
+ 这些特性确保用户不会错过重要提示信息。
588
+
575
589
  #### 重置密码流程
576
590
 
577
591
  AuthModal 支持完整的密码重置流程:
package/dist/index.cjs CHANGED
@@ -2247,6 +2247,7 @@ class Toast {
2247
2247
  }
2248
2248
  // Create toast element
2249
2249
  const toast = this.createToast(type, title, message, onClose);
2250
+ const toastId = toast.id;
2250
2251
  // Add to container
2251
2252
  this.container.appendChild(toast);
2252
2253
  this.toasts.push(toast);
@@ -2254,11 +2255,17 @@ class Toast {
2254
2255
  requestAnimationFrame(() => {
2255
2256
  toast.classList.add('toast-show');
2256
2257
  });
2257
- // Auto-dismiss
2258
+ // Auto-dismiss with hover support
2258
2259
  if (duration > 0) {
2259
- setTimeout(() => {
2260
- this.dismiss(toast, onClose);
2261
- }, duration);
2260
+ this.scheduleAutoDismiss(toast, duration, onClose);
2261
+ // Pause auto-dismiss on hover
2262
+ toast.addEventListener('mouseenter', () => {
2263
+ this.clearAutoDismiss(toastId);
2264
+ });
2265
+ // Resume auto-dismiss on leave
2266
+ toast.addEventListener('mouseleave', () => {
2267
+ this.scheduleAutoDismiss(toast, duration, onClose);
2268
+ });
2262
2269
  }
2263
2270
  }
2264
2271
  /**
@@ -2472,6 +2479,30 @@ class Toast {
2472
2479
  svg.appendChild(path);
2473
2480
  return svg;
2474
2481
  }
2482
+ /**
2483
+ * Schedule auto-dismiss for a toast
2484
+ */
2485
+ static scheduleAutoDismiss(toast, duration, onClose) {
2486
+ const toastId = toast.id;
2487
+ // Clear existing timer if any
2488
+ this.clearAutoDismiss(toastId);
2489
+ // Schedule new timer
2490
+ const timer = setTimeout(() => {
2491
+ this.dismiss(toast, onClose);
2492
+ this.timers.delete(toastId);
2493
+ }, duration);
2494
+ this.timers.set(toastId, timer);
2495
+ }
2496
+ /**
2497
+ * Clear auto-dismiss timer for a toast
2498
+ */
2499
+ static clearAutoDismiss(toastId) {
2500
+ const timer = this.timers.get(toastId);
2501
+ if (timer) {
2502
+ clearTimeout(timer);
2503
+ this.timers.delete(toastId);
2504
+ }
2505
+ }
2475
2506
  /**
2476
2507
  * Dismiss a toast
2477
2508
  */
@@ -2764,6 +2795,7 @@ Toast.container = null;
2764
2795
  Toast.toasts = [];
2765
2796
  Toast.nextId = 0;
2766
2797
  Toast.cssInjected = false;
2798
+ Toast.timers = new Map();
2767
2799
 
2768
2800
  class AuthModal {
2769
2801
  constructor(options) {