ngx-auto-logout 1.0.0

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.
Files changed (37) hide show
  1. package/README.md +247 -0
  2. package/dist/README.md +247 -0
  3. package/dist/bundles/ngx-auto-logout.umd.js +864 -0
  4. package/dist/bundles/ngx-auto-logout.umd.js.map +1 -0
  5. package/dist/bundles/ngx-auto-logout.umd.min.js +16 -0
  6. package/dist/bundles/ngx-auto-logout.umd.min.js.map +1 -0
  7. package/dist/esm2015/lib/auto-logout.component.js +351 -0
  8. package/dist/esm2015/lib/auto-logout.module.js +26 -0
  9. package/dist/esm2015/lib/auto-logout.service.js +384 -0
  10. package/dist/esm2015/lib/models/auto-logout-config.interface.js +10 -0
  11. package/dist/esm2015/lib/models/auto-logout-config.token.js +7 -0
  12. package/dist/esm2015/lib/provide-auto-logout.js +11 -0
  13. package/dist/esm2015/ngx-auto-logout.js +5 -0
  14. package/dist/esm2015/public-api.js +10 -0
  15. package/dist/esm5/lib/auto-logout.component.js +196 -0
  16. package/dist/esm5/lib/auto-logout.module.js +30 -0
  17. package/dist/esm5/lib/auto-logout.service.js +391 -0
  18. package/dist/esm5/lib/models/auto-logout-config.interface.js +10 -0
  19. package/dist/esm5/lib/models/auto-logout-config.token.js +7 -0
  20. package/dist/esm5/lib/provide-auto-logout.js +11 -0
  21. package/dist/esm5/ngx-auto-logout.js +5 -0
  22. package/dist/esm5/public-api.js +10 -0
  23. package/dist/fesm2015/ngx-auto-logout.js +787 -0
  24. package/dist/fesm2015/ngx-auto-logout.js.map +1 -0
  25. package/dist/fesm5/ngx-auto-logout.js +643 -0
  26. package/dist/fesm5/ngx-auto-logout.js.map +1 -0
  27. package/dist/lib/auto-logout.component.d.ts +81 -0
  28. package/dist/lib/auto-logout.module.d.ts +8 -0
  29. package/dist/lib/auto-logout.service.d.ts +108 -0
  30. package/dist/lib/models/auto-logout-config.interface.d.ts +46 -0
  31. package/dist/lib/models/auto-logout-config.token.d.ts +7 -0
  32. package/dist/lib/provide-auto-logout.d.ts +6 -0
  33. package/dist/ngx-auto-logout.d.ts +4 -0
  34. package/dist/ngx-auto-logout.metadata.json +1 -0
  35. package/dist/package.json +41 -0
  36. package/dist/public-api.d.ts +6 -0
  37. package/package.json +53 -0
@@ -0,0 +1,643 @@
1
+ import { InjectionToken, NgZone, ɵɵdefineInjectable, ɵɵinject, Injectable, EventEmitter, Input, Output, Component, NgModule } from '@angular/core';
2
+ import { __assign, __decorate } from 'tslib';
3
+ import { BehaviorSubject, interval } from 'rxjs';
4
+ import { CommonModule } from '@angular/common';
5
+
6
+ /**
7
+ * 默认配置
8
+ */
9
+ var DEFAULT_AUTO_LOGOUT_CONFIG = {
10
+ mode: 'fixed',
11
+ timeout: 300,
12
+ warningTime: 30,
13
+ maxExtendTimes: -1,
14
+ };
15
+
16
+ /**
17
+ * InjectionToken for auto logout configuration
18
+ * Extracted to a separate file to avoid Angular 9 Ivy compilation scope issues
19
+ */
20
+ var AUTO_LOGOUT_CONFIG = new InjectionToken('AutoLogoutConfig');
21
+
22
+ /**
23
+ * Auto logout service
24
+ * Angular 9 compatible: use providedIn: 'root' (official pattern)
25
+ */
26
+ var AutoLogoutService = /** @class */ (function () {
27
+ /**
28
+ * Constructor
29
+ * Note: Do NOT use @Inject() here, it causes DI errors in Angular 9 VE
30
+ * Config should be passed via startMonitoring() method instead
31
+ */
32
+ function AutoLogoutService(ngZone) {
33
+ this.ngZone = ngZone;
34
+ // 配置是否已初始化
35
+ this.isConfigInitialized = false;
36
+ // localStorage 键名
37
+ this.LOGIN_TIME_KEY = 'autoLogout_loginTime';
38
+ this.LAST_ACTIVITY_KEY = 'autoLogout_lastActivity';
39
+ this.EXTEND_COUNT_KEY = 'autoLogout_extendCount';
40
+ this.PAUSE_STATE_KEY = 'autoLogout_pauseState';
41
+ this.lastActivityTime = Date.now();
42
+ this.countdownValue = 0;
43
+ this.countdownSubject = new BehaviorSubject(0);
44
+ this.timerSubscription = null;
45
+ this.activityListeners = [];
46
+ this.warningShown = false;
47
+ // 是否启用活动监听
48
+ this.enableActivityTracking = false;
49
+ // 暂停状态
50
+ this.isPaused = false;
51
+ this.pauseStartTime = 0;
52
+ this.pausedRemainingTime = 0;
53
+ // Use default config, will be overridden by startMonitoring()
54
+ this.currentConfig = __assign({}, DEFAULT_AUTO_LOGOUT_CONFIG);
55
+ this.countdownValue = Math.floor(this.currentConfig.timeout);
56
+ this.countdownSubject = new BehaviorSubject(this.countdownValue);
57
+ }
58
+ AutoLogoutService.prototype.getCountdown = function () {
59
+ return this.countdownSubject.asObservable();
60
+ };
61
+ /**
62
+ * 启动自动登出监控
63
+ */
64
+ AutoLogoutService.prototype.startMonitoring = function (config, enableTracking) {
65
+ var _this = this;
66
+ if (enableTracking === void 0) { enableTracking = false; }
67
+ this.stopMonitoring();
68
+ if (config) {
69
+ this.currentConfig = __assign(__assign({}, this.currentConfig), config);
70
+ }
71
+ // 恢复暂停状态
72
+ this.restorePauseState();
73
+ if (this.isPaused) {
74
+ return;
75
+ }
76
+ // 根据模式初始化
77
+ if (this.currentConfig.mode === 'fixed') {
78
+ this.initFixedMode();
79
+ }
80
+ else {
81
+ this.initIdleMode(enableTracking);
82
+ }
83
+ this.warningShown = false;
84
+ // 启动定时器
85
+ this.ngZone.runOutsideAngular(function () {
86
+ _this.timerSubscription = interval(1000).subscribe(function () {
87
+ _this.updateCountdown();
88
+ });
89
+ });
90
+ };
91
+ /**
92
+ * 停止监控
93
+ */
94
+ AutoLogoutService.prototype.stopMonitoring = function () {
95
+ if (this.timerSubscription) {
96
+ this.timerSubscription.unsubscribe();
97
+ this.timerSubscription = null;
98
+ }
99
+ this.removeActivityListeners();
100
+ };
101
+ /**
102
+ * 清除登录时间
103
+ */
104
+ AutoLogoutService.prototype.clearLoginTime = function () {
105
+ localStorage.removeItem(this.LOGIN_TIME_KEY);
106
+ localStorage.removeItem(this.LAST_ACTIVITY_KEY);
107
+ this.resetExtendCount();
108
+ this.clearPauseState();
109
+ };
110
+ /**
111
+ * 延长会话
112
+ */
113
+ AutoLogoutService.prototype.extendSession = function (extendSeconds) {
114
+ if (extendSeconds === void 0) { extendSeconds = 1800; }
115
+ if (this.isMaxExtendReached()) {
116
+ console.warn('已达到最大延长次数');
117
+ return false;
118
+ }
119
+ if (this.currentConfig.mode === 'fixed') {
120
+ this.lastActivityTime -= extendSeconds * 1000;
121
+ }
122
+ else {
123
+ this.resetActivityTimer();
124
+ }
125
+ this.incrementExtendCount();
126
+ if (this.currentConfig.onExtended) {
127
+ this.currentConfig.onExtended(extendSeconds);
128
+ }
129
+ return true;
130
+ };
131
+ /**
132
+ * 检查是否可以延长
133
+ */
134
+ AutoLogoutService.prototype.canExtendSession = function () {
135
+ return !this.isMaxExtendReached() && !this.isPaused;
136
+ };
137
+ /**
138
+ * 获取剩余可延长次数
139
+ */
140
+ AutoLogoutService.prototype.getRemainingExtendTimes = function () {
141
+ if (this.currentConfig.maxExtendTimes === -1 || this.currentConfig.maxExtendTimes === undefined) {
142
+ return -1;
143
+ }
144
+ var usedCount = this.getExtendCount();
145
+ return Math.max(0, this.currentConfig.maxExtendTimes - usedCount);
146
+ };
147
+ /**
148
+ * 获取最后操作时间显示
149
+ */
150
+ AutoLogoutService.prototype.getLastActivityDisplay = function () {
151
+ if (this.currentConfig.mode !== 'idle') {
152
+ return '';
153
+ }
154
+ var lastActivity = this.getLastActivityTime();
155
+ if (!lastActivity) {
156
+ return '';
157
+ }
158
+ var minutesAgo = Math.floor((Date.now() - lastActivity) / 60000);
159
+ if (minutesAgo < 1) {
160
+ return '刚刚操作';
161
+ }
162
+ return minutesAgo + "\u5206\u949F\u524D\u64CD\u4F5C";
163
+ };
164
+ /**
165
+ * 暂停
166
+ */
167
+ AutoLogoutService.prototype.pause = function () {
168
+ if (this.isPaused)
169
+ return;
170
+ this.isPaused = true;
171
+ this.pauseStartTime = Date.now();
172
+ this.pausedRemainingTime = this.countdownValue;
173
+ this.stopMonitoring();
174
+ this.savePauseState();
175
+ if (this.currentConfig.onPaused) {
176
+ this.currentConfig.onPaused();
177
+ }
178
+ };
179
+ /**
180
+ * 恢复
181
+ */
182
+ AutoLogoutService.prototype.resume = function () {
183
+ if (!this.isPaused)
184
+ return;
185
+ var pauseDuration = Date.now() - this.pauseStartTime;
186
+ if (this.currentConfig.mode === 'fixed') {
187
+ this.lastActivityTime += pauseDuration;
188
+ }
189
+ else {
190
+ this.lastActivityTime += pauseDuration;
191
+ this.setLastActivityTime(this.lastActivityTime);
192
+ }
193
+ this.isPaused = false;
194
+ this.pauseStartTime = 0;
195
+ this.pausedRemainingTime = 0;
196
+ this.clearPauseState();
197
+ this.startMonitoring(this.currentConfig, this.enableActivityTracking);
198
+ if (this.currentConfig.onResumed) {
199
+ this.currentConfig.onResumed();
200
+ }
201
+ };
202
+ /**
203
+ * 检查是否暂停
204
+ */
205
+ AutoLogoutService.prototype.isAutoLogoutPaused = function () {
206
+ return this.isPaused;
207
+ };
208
+ /**
209
+ * 格式化倒计时
210
+ */
211
+ AutoLogoutService.prototype.formatCountdown = function (seconds) {
212
+ var mins = Math.floor(seconds / 60);
213
+ var secs = seconds % 60;
214
+ return mins.toString().padStart(2, '0') + ":" + secs.toString().padStart(2, '0');
215
+ };
216
+ /**
217
+ * 判断是否警告状态
218
+ */
219
+ AutoLogoutService.prototype.isWarningState = function (seconds) {
220
+ var warningTime = this.currentConfig.warningTime || 30;
221
+ return seconds <= warningTime && seconds > 0;
222
+ };
223
+ /**
224
+ * 判断是否紧急状态(最后10秒)
225
+ */
226
+ AutoLogoutService.prototype.isUrgentState = function (seconds) {
227
+ return seconds <= 10 && seconds > 0;
228
+ };
229
+ /**
230
+ * 获取当前模式
231
+ */
232
+ AutoLogoutService.prototype.getCurrentMode = function () {
233
+ return this.currentConfig.mode;
234
+ };
235
+ // ==================== 私有方法 ====================
236
+ AutoLogoutService.prototype.initFixedMode = function () {
237
+ var loginTime = this.getLoginTime();
238
+ if (!loginTime) {
239
+ this.setLoginTime(Date.now());
240
+ this.lastActivityTime = Date.now();
241
+ }
242
+ else {
243
+ this.lastActivityTime = loginTime;
244
+ }
245
+ this.updateCountdownValue();
246
+ };
247
+ AutoLogoutService.prototype.initIdleMode = function (enableTracking) {
248
+ this.enableActivityTracking = enableTracking || true;
249
+ var lastActivity = this.getLastActivityTime();
250
+ if (!lastActivity) {
251
+ this.setLastActivityTime(Date.now());
252
+ this.lastActivityTime = Date.now();
253
+ }
254
+ else {
255
+ this.lastActivityTime = lastActivity;
256
+ }
257
+ this.registerActivityListeners();
258
+ this.updateCountdownValue();
259
+ };
260
+ AutoLogoutService.prototype.updateCountdownValue = function () {
261
+ var now = Date.now();
262
+ var elapsed = now - this.lastActivityTime;
263
+ var remaining = Math.max(0, Math.floor((this.currentConfig.timeout * 1000 - elapsed) / 1000));
264
+ this.countdownValue = remaining;
265
+ this.countdownSubject.next(this.countdownValue);
266
+ };
267
+ AutoLogoutService.prototype.updateCountdown = function () {
268
+ var _this = this;
269
+ var now = Date.now();
270
+ var elapsed = now - this.lastActivityTime;
271
+ var remaining = Math.max(0, Math.floor((this.currentConfig.timeout * 1000 - elapsed) / 1000));
272
+ if (remaining !== this.countdownValue) {
273
+ this.countdownValue = remaining;
274
+ this.ngZone.run(function () {
275
+ _this.countdownSubject.next(_this.countdownValue);
276
+ });
277
+ // 警告回调
278
+ var warningTime = this.currentConfig.warningTime || 30;
279
+ if (remaining === warningTime && !this.warningShown) {
280
+ this.warningShown = true;
281
+ if (this.currentConfig.onWarning) {
282
+ this.currentConfig.onWarning(remaining);
283
+ }
284
+ }
285
+ // 超时回调
286
+ if (remaining <= 0) {
287
+ this.performAutoLogout();
288
+ }
289
+ }
290
+ };
291
+ AutoLogoutService.prototype.performAutoLogout = function () {
292
+ this.stopMonitoring();
293
+ this.clearLoginTime();
294
+ if (this.currentConfig.onTimeout) {
295
+ this.currentConfig.onTimeout();
296
+ }
297
+ else {
298
+ // 默认行为:导航到登录页
299
+ // Note: Router navigation removed to avoid DI issues in Angular 9 VE
300
+ // Use onTimeout callback for custom navigation
301
+ console.warn('Auto logout timeout - implement custom navigation via onTimeout callback');
302
+ }
303
+ };
304
+ AutoLogoutService.prototype.registerActivityListeners = function () {
305
+ var _this = this;
306
+ var events = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'];
307
+ events.forEach(function (event) {
308
+ var listener = function () { return _this.resetActivityTimer(); };
309
+ document.addEventListener(event, listener, true);
310
+ _this.activityListeners.push({ event: event, listener: listener });
311
+ });
312
+ };
313
+ AutoLogoutService.prototype.removeActivityListeners = function () {
314
+ this.activityListeners.forEach(function (_a) {
315
+ var event = _a.event, listener = _a.listener;
316
+ document.removeEventListener(event, listener, true);
317
+ });
318
+ this.activityListeners = [];
319
+ };
320
+ AutoLogoutService.prototype.resetActivityTimer = function () {
321
+ if (this.currentConfig.mode === 'idle') {
322
+ this.lastActivityTime = Date.now();
323
+ this.setLastActivityTime(this.lastActivityTime);
324
+ this.updateCountdownValue();
325
+ this.warningShown = false;
326
+ }
327
+ };
328
+ AutoLogoutService.prototype.isMaxExtendReached = function () {
329
+ if (this.currentConfig.maxExtendTimes === -1 || this.currentConfig.maxExtendTimes === undefined) {
330
+ return false;
331
+ }
332
+ var usedCount = this.getExtendCount();
333
+ return usedCount >= this.currentConfig.maxExtendTimes;
334
+ };
335
+ AutoLogoutService.prototype.getExtendCount = function () {
336
+ var countStr = localStorage.getItem(this.EXTEND_COUNT_KEY);
337
+ return countStr ? parseInt(countStr, 10) : 0;
338
+ };
339
+ AutoLogoutService.prototype.incrementExtendCount = function () {
340
+ var currentCount = this.getExtendCount();
341
+ localStorage.setItem(this.EXTEND_COUNT_KEY, (currentCount + 1).toString());
342
+ };
343
+ AutoLogoutService.prototype.resetExtendCount = function () {
344
+ localStorage.removeItem(this.EXTEND_COUNT_KEY);
345
+ };
346
+ AutoLogoutService.prototype.getLoginTime = function () {
347
+ var timeStr = localStorage.getItem(this.LOGIN_TIME_KEY);
348
+ return timeStr ? parseInt(timeStr, 10) : null;
349
+ };
350
+ AutoLogoutService.prototype.setLoginTime = function (time) {
351
+ localStorage.setItem(this.LOGIN_TIME_KEY, time.toString());
352
+ };
353
+ AutoLogoutService.prototype.getLastActivityTime = function () {
354
+ var timeStr = localStorage.getItem(this.LAST_ACTIVITY_KEY);
355
+ return timeStr ? parseInt(timeStr, 10) : null;
356
+ };
357
+ AutoLogoutService.prototype.setLastActivityTime = function (time) {
358
+ localStorage.setItem(this.LAST_ACTIVITY_KEY, time.toString());
359
+ };
360
+ AutoLogoutService.prototype.savePauseState = function () {
361
+ var state = {
362
+ isPaused: true,
363
+ pauseStartTime: this.pauseStartTime,
364
+ pausedRemainingTime: this.pausedRemainingTime,
365
+ mode: this.currentConfig.mode,
366
+ lastActivityTime: this.lastActivityTime
367
+ };
368
+ localStorage.setItem(this.PAUSE_STATE_KEY, JSON.stringify(state));
369
+ };
370
+ AutoLogoutService.prototype.clearPauseState = function () {
371
+ localStorage.removeItem(this.PAUSE_STATE_KEY);
372
+ };
373
+ AutoLogoutService.prototype.restorePauseState = function () {
374
+ var stateStr = localStorage.getItem(this.PAUSE_STATE_KEY);
375
+ if (!stateStr)
376
+ return;
377
+ try {
378
+ var state = JSON.parse(stateStr);
379
+ if (state.isPaused) {
380
+ this.isPaused = true;
381
+ this.pauseStartTime = state.pauseStartTime;
382
+ this.pausedRemainingTime = state.pausedRemainingTime;
383
+ this.lastActivityTime = state.lastActivityTime;
384
+ this.currentConfig.mode = state.mode;
385
+ if (this.timerSubscription) {
386
+ this.timerSubscription.unsubscribe();
387
+ this.timerSubscription = null;
388
+ }
389
+ this.removeActivityListeners();
390
+ }
391
+ }
392
+ catch (e) {
393
+ console.error('恢复暂停状态失败:', e);
394
+ this.clearPauseState();
395
+ }
396
+ };
397
+ AutoLogoutService.ctorParameters = function () { return [
398
+ { type: NgZone }
399
+ ]; };
400
+ AutoLogoutService.ɵprov = ɵɵdefineInjectable({ factory: function AutoLogoutService_Factory() { return new AutoLogoutService(ɵɵinject(NgZone)); }, token: AutoLogoutService, providedIn: "root" });
401
+ AutoLogoutService = __decorate([
402
+ Injectable({ providedIn: 'root' })
403
+ ], AutoLogoutService);
404
+ return AutoLogoutService;
405
+ }());
406
+
407
+ var AutoLogoutComponent = /** @class */ (function () {
408
+ function AutoLogoutComponent(autoLogout) {
409
+ this.autoLogout = autoLogout;
410
+ // ==================== 输入属性 ====================
411
+ /**
412
+ * 是否显示延长按钮
413
+ */
414
+ this.showExtendButton = true;
415
+ /**
416
+ * 是否显示暂停按钮
417
+ */
418
+ this.showPauseButton = true;
419
+ /**
420
+ * 延长的秒数(默认30分钟)
421
+ */
422
+ this.extendSeconds = 1800;
423
+ // ==================== 输出事件 ====================
424
+ /**
425
+ * 警告事件
426
+ */
427
+ this.onWarning = new EventEmitter();
428
+ /**
429
+ * 超时事件
430
+ */
431
+ this.onTimeout = new EventEmitter();
432
+ /**
433
+ * 延长成功事件
434
+ */
435
+ this.onExtended = new EventEmitter();
436
+ /**
437
+ * 暂停事件
438
+ */
439
+ this.onPaused = new EventEmitter();
440
+ /**
441
+ * 恢复事件
442
+ */
443
+ this.onResumed = new EventEmitter();
444
+ // ==================== 内部状态 ====================
445
+ this.subscription = null;
446
+ this.countdown = '00:00';
447
+ this.isWarning = false;
448
+ this.isUrgent = false;
449
+ this.isPaused = false;
450
+ this.canExtend = true;
451
+ this.remainingExtends = -1;
452
+ }
453
+ AutoLogoutComponent.prototype.ngOnInit = function () {
454
+ var _this = this;
455
+ // 如果提供了自定义配置,启动监控
456
+ if (this.config) {
457
+ this.autoLogout.startMonitoring(this.config);
458
+ }
459
+ // 订阅倒计时
460
+ this.subscription = this.autoLogout.getCountdown().subscribe(function (seconds) {
461
+ var _a;
462
+ _this.countdown = _this.autoLogout.formatCountdown(seconds);
463
+ _this.isWarning = _this.autoLogout.isWarningState(seconds);
464
+ _this.isUrgent = _this.autoLogout.isUrgentState(seconds);
465
+ // 触发警告事件
466
+ var warningTime = ((_a = _this.config) === null || _a === void 0 ? void 0 : _a.warningTime) || 30;
467
+ if (seconds === warningTime) {
468
+ _this.onWarning.emit(seconds);
469
+ }
470
+ // 触发超时事件
471
+ if (seconds <= 0) {
472
+ _this.onTimeout.emit();
473
+ }
474
+ });
475
+ // 定期检查状态
476
+ setInterval(function () {
477
+ _this.updateStatus();
478
+ }, 1000);
479
+ this.updateStatus();
480
+ };
481
+ AutoLogoutComponent.prototype.ngOnDestroy = function () {
482
+ if (this.subscription) {
483
+ this.subscription.unsubscribe();
484
+ }
485
+ };
486
+ // ==================== 公开方法 ====================
487
+ /**
488
+ * 延长会话
489
+ */
490
+ AutoLogoutComponent.prototype.extendSession = function () {
491
+ this.handleExtend();
492
+ };
493
+ /**
494
+ * 暂停
495
+ */
496
+ AutoLogoutComponent.prototype.pause = function () {
497
+ this.handleTogglePause();
498
+ };
499
+ /**
500
+ * 恢复
501
+ */
502
+ AutoLogoutComponent.prototype.resume = function () {
503
+ this.handleTogglePause();
504
+ };
505
+ Object.defineProperty(AutoLogoutComponent.prototype, "templateContext", {
506
+ /**
507
+ * 获取模板上下文(用于自定义模板)
508
+ */
509
+ get: function () {
510
+ var _this = this;
511
+ return {
512
+ countdown: this.countdown,
513
+ isWarning: this.isWarning,
514
+ isUrgent: this.isUrgent,
515
+ isPaused: this.isPaused,
516
+ canExtend: this.canExtend,
517
+ remainingExtends: this.remainingExtends,
518
+ extendSession: function () { return _this.handleExtend(); },
519
+ togglePause: function () { return _this.handleTogglePause(); },
520
+ formatCountdown: function (seconds) { return _this.autoLogout.formatCountdown(seconds); }
521
+ };
522
+ },
523
+ enumerable: true,
524
+ configurable: true
525
+ });
526
+ // ==================== 内部方法 ====================
527
+ AutoLogoutComponent.prototype.updateStatus = function () {
528
+ this.isPaused = this.autoLogout.isAutoLogoutPaused();
529
+ this.canExtend = this.autoLogout.canExtendSession();
530
+ this.remainingExtends = this.autoLogout.getRemainingExtendTimes();
531
+ };
532
+ /**
533
+ * 处理延长会话(模板调用)
534
+ */
535
+ AutoLogoutComponent.prototype.handleExtend = function () {
536
+ var success = this.autoLogout.extendSession(this.extendSeconds);
537
+ if (success) {
538
+ this.onExtended.emit(this.extendSeconds);
539
+ }
540
+ this.updateStatus();
541
+ };
542
+ /**
543
+ * 处理暂停/恢复切换(模板调用)
544
+ */
545
+ AutoLogoutComponent.prototype.handleTogglePause = function () {
546
+ if (this.isPaused) {
547
+ this.autoLogout.resume();
548
+ this.onResumed.emit();
549
+ }
550
+ else {
551
+ this.autoLogout.pause();
552
+ this.onPaused.emit();
553
+ }
554
+ this.updateStatus();
555
+ };
556
+ AutoLogoutComponent.ctorParameters = function () { return [
557
+ { type: AutoLogoutService }
558
+ ]; };
559
+ __decorate([
560
+ Input()
561
+ ], AutoLogoutComponent.prototype, "showExtendButton", void 0);
562
+ __decorate([
563
+ Input()
564
+ ], AutoLogoutComponent.prototype, "showPauseButton", void 0);
565
+ __decorate([
566
+ Input()
567
+ ], AutoLogoutComponent.prototype, "extendSeconds", void 0);
568
+ __decorate([
569
+ Input()
570
+ ], AutoLogoutComponent.prototype, "config", void 0);
571
+ __decorate([
572
+ Input()
573
+ ], AutoLogoutComponent.prototype, "customTemplate", void 0);
574
+ __decorate([
575
+ Output()
576
+ ], AutoLogoutComponent.prototype, "onWarning", void 0);
577
+ __decorate([
578
+ Output()
579
+ ], AutoLogoutComponent.prototype, "onTimeout", void 0);
580
+ __decorate([
581
+ Output()
582
+ ], AutoLogoutComponent.prototype, "onExtended", void 0);
583
+ __decorate([
584
+ Output()
585
+ ], AutoLogoutComponent.prototype, "onPaused", void 0);
586
+ __decorate([
587
+ Output()
588
+ ], AutoLogoutComponent.prototype, "onResumed", void 0);
589
+ AutoLogoutComponent = __decorate([
590
+ Component({
591
+ selector: 'ngx-auto-logout',
592
+ template: "\n <!-- \u9ED8\u8BA4UI\u6A21\u5F0F\uFF08\u50BB\u74DC\u6A21\u5F0F\uFF09 -->\n <div *ngIf=\"!customTemplate\" class=\"ngx-auto-logout-container\">\n <!-- \u5012\u8BA1\u65F6\u663E\u793A -->\n <div class=\"countdown-display\" [class.warning]=\"isWarning\" [class.urgent]=\"isUrgent\" [class.paused]=\"isPaused\">\n <span class=\"icon\">{{ isPaused ? '\u23F8\uFE0F' : '\u23F1\uFE0F' }}</span>\n <span class=\"time\">{{ countdown }}</span>\n <span *ngIf=\"isPaused\" class=\"pause-label\">(\u5DF2\u6682\u505C)</span>\n </div>\n\n <!-- \u63A7\u5236\u6309\u94AE -->\n <div class=\"controls\">\n <!-- \u5EF6\u957F\u4F1A\u8BDD\u6309\u94AE -->\n <button *ngIf=\"showExtendButton && canExtend\" class=\"btn btn-extend\" (click)=\"handleExtend()\" [disabled]=\"!canExtend\" title=\"\u5EF6\u957F30\u5206\u949F\">\n \u2795 \u5EF6\u957F\n <span *ngIf=\"remainingExtends !== -1\" class=\"extend-count\"> ({{ remainingExtends }}) </span>\n </button>\n\n <!-- \u6682\u505C/\u6062\u590D\u6309\u94AE -->\n <button\n *ngIf=\"showPauseButton\"\n class=\"btn btn-pause\"\n [class.paused]=\"isPaused\"\n (click)=\"handleTogglePause()\"\n [title]=\"isPaused ? '\u6062\u590D\u81EA\u52A8\u767B\u51FA' : '\u6682\u505C\u81EA\u52A8\u767B\u51FA'\"\n >\n {{ isPaused ? '\u25B6\uFE0F \u6062\u590D' : '\u23F8\uFE0F \u6682\u505C' }}\n </button>\n </div>\n </div>\n\n <!-- \u81EA\u5B9A\u4E49\u6A21\u677F\u6A21\u5F0F\uFF08\u4E13\u5BB6\u6A21\u5F0F\uFF09 -->\n <ng-container *ngIf=\"customTemplate\">\n <ng-container [ngTemplateOutlet]=\"customTemplate\" [ngTemplateOutletContext]=\"templateContext\"></ng-container>\n </ng-container>\n ",
593
+ styles: ["\n .ngx-auto-logout-container {\n display: inline-flex;\n align-items: center;\n gap: 12px;\n padding: 8px 12px;\n background: #f8f9fa;\n border-radius: 6px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n }\n\n .countdown-display {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 6px 12px;\n background: white;\n border-radius: 4px;\n font-weight: bold;\n font-size: 16px;\n transition: all 0.3s ease;\n }\n\n .countdown-display.warning {\n background: #fff3cd;\n color: #856404;\n animation: blink-warning 1s ease-in-out infinite;\n }\n\n .countdown-display.urgent {\n background: #f8d7da;\n color: #721c24;\n animation: blink-urgent 0.5s ease-in-out infinite;\n }\n\n .countdown-display.paused {\n opacity: 0.6;\n background: #e9ecef;\n }\n\n .icon {\n font-size: 18px;\n }\n\n .time {\n min-width: 50px;\n text-align: center;\n }\n\n .pause-label {\n font-size: 12px;\n color: #6c757d;\n font-weight: normal;\n }\n\n .controls {\n display: flex;\n gap: 8px;\n }\n\n .btn {\n padding: 6px 12px;\n font-size: 13px;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n transition: all 0.2s;\n font-weight: 500;\n }\n\n .btn-extend {\n background: #28a745;\n color: white;\n }\n\n .btn-extend:hover:not(:disabled) {\n background: #218838;\n transform: translateY(-1px);\n }\n\n .btn-extend:disabled {\n background: #ccc;\n cursor: not-allowed;\n opacity: 0.6;\n }\n\n .btn-pause {\n background: #007bff;\n color: white;\n }\n\n .btn-pause:hover {\n background: #0056b3;\n transform: translateY(-1px);\n }\n\n .btn-pause.paused {\n background: #ffc107;\n color: #212529;\n }\n\n .extend-count {\n font-size: 11px;\n opacity: 0.9;\n }\n\n @keyframes blink-warning {\n 0%,\n 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.7;\n }\n }\n\n @keyframes blink-urgent {\n 0%,\n 100% {\n opacity: 1;\n transform: scale(1);\n }\n 50% {\n opacity: 0.6;\n transform: scale(1.05);\n }\n }\n "]
594
+ })
595
+ ], AutoLogoutComponent);
596
+ return AutoLogoutComponent;
597
+ }());
598
+
599
+ /**
600
+ * Auto logout module
601
+ * Note: Service uses providedIn: 'root', module only declares/exports component
602
+ */
603
+ var AutoLogoutModule = /** @class */ (function () {
604
+ function AutoLogoutModule() {
605
+ }
606
+ AutoLogoutModule_1 = AutoLogoutModule;
607
+ AutoLogoutModule.forRoot = function () {
608
+ return {
609
+ ngModule: AutoLogoutModule_1,
610
+ providers: []
611
+ };
612
+ };
613
+ var AutoLogoutModule_1;
614
+ AutoLogoutModule = AutoLogoutModule_1 = __decorate([
615
+ NgModule({
616
+ declarations: [AutoLogoutComponent],
617
+ imports: [CommonModule],
618
+ exports: [AutoLogoutComponent]
619
+ })
620
+ ], AutoLogoutModule);
621
+ return AutoLogoutModule;
622
+ }());
623
+
624
+ /**
625
+ * 提供自动登出配置(Angular 15+ Standalone)
626
+ */
627
+ function provideAutoLogout(config) {
628
+ return {
629
+ provide: AUTO_LOGOUT_CONFIG,
630
+ useValue: config
631
+ };
632
+ }
633
+
634
+ /*
635
+ * Public API Surface of auto-logout
636
+ */
637
+
638
+ /**
639
+ * Generated bundle index. Do not edit.
640
+ */
641
+
642
+ export { AUTO_LOGOUT_CONFIG, AutoLogoutComponent, AutoLogoutModule, AutoLogoutService, DEFAULT_AUTO_LOGOUT_CONFIG, provideAutoLogout };
643
+ //# sourceMappingURL=ngx-auto-logout.js.map