mn-angular-lib 2.0.34 → 2.0.35

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 (52) hide show
  1. package/fesm2022/mn-angular-lib-alert.mjs +515 -527
  2. package/fesm2022/mn-angular-lib-alert.mjs.map +1 -1
  3. package/fesm2022/mn-angular-lib-bottom-sheet.mjs +264 -357
  4. package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -1
  5. package/fesm2022/mn-angular-lib-button.mjs +819 -382
  6. package/fesm2022/mn-angular-lib-button.mjs.map +1 -1
  7. package/fesm2022/mn-angular-lib-calendar-core.mjs +240 -365
  8. package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -1
  9. package/fesm2022/mn-angular-lib-calendar.mjs +1691 -1545
  10. package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -1
  11. package/fesm2022/mn-angular-lib-collection.mjs +2367 -2796
  12. package/fesm2022/mn-angular-lib-collection.mjs.map +1 -1
  13. package/fesm2022/mn-angular-lib-core.mjs +693 -1241
  14. package/fesm2022/mn-angular-lib-core.mjs.map +1 -1
  15. package/fesm2022/mn-angular-lib-display.mjs +679 -712
  16. package/fesm2022/mn-angular-lib-display.mjs.map +1 -1
  17. package/fesm2022/mn-angular-lib-forms.mjs +3671 -4647
  18. package/fesm2022/mn-angular-lib-forms.mjs.map +1 -1
  19. package/fesm2022/mn-angular-lib-keyboard.mjs +221 -190
  20. package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -1
  21. package/fesm2022/mn-angular-lib-modal-core.mjs +711 -896
  22. package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -1
  23. package/fesm2022/mn-angular-lib-modal-ui.mjs +2089 -2035
  24. package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -1
  25. package/fesm2022/mn-angular-lib-modal.mjs +76 -121
  26. package/fesm2022/mn-angular-lib-modal.mjs.map +1 -1
  27. package/fesm2022/mn-angular-lib-rich-text-editor.mjs +289 -277
  28. package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -1
  29. package/fesm2022/mn-angular-lib-segmented.mjs +189 -241
  30. package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -1
  31. package/fesm2022/mn-angular-lib-tab.mjs +409 -642
  32. package/fesm2022/mn-angular-lib-tab.mjs.map +1 -1
  33. package/fesm2022/mn-angular-lib.mjs +16 -29
  34. package/package.json +1 -1
  35. package/types/mn-angular-lib-alert.d.ts +239 -241
  36. package/types/mn-angular-lib-bottom-sheet.d.ts +190 -150
  37. package/types/mn-angular-lib-button.d.ts +319 -317
  38. package/types/mn-angular-lib-calendar-core.d.ts +199 -209
  39. package/types/mn-angular-lib-calendar.d.ts +656 -511
  40. package/types/mn-angular-lib-collection.d.ts +1649 -1585
  41. package/types/mn-angular-lib-core.d.ts +524 -535
  42. package/types/mn-angular-lib-display.d.ts +946 -886
  43. package/types/mn-angular-lib-forms.d.ts +3012 -3013
  44. package/types/mn-angular-lib-keyboard.d.ts +125 -85
  45. package/types/mn-angular-lib-modal-core.d.ts +978 -994
  46. package/types/mn-angular-lib-modal-ui.d.ts +541 -493
  47. package/types/mn-angular-lib-modal.d.ts +24 -27
  48. package/types/mn-angular-lib-rich-text-editor.d.ts +131 -98
  49. package/types/mn-angular-lib-segmented.d.ts +354 -341
  50. package/types/mn-angular-lib-tab.d.ts +345 -336
  51. package/types/mn-angular-lib.d.ts +16 -16
  52. package/fesm2022/mn-angular-lib.mjs.map +0 -1
@@ -1,536 +1,524 @@
1
- import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, Injectable, DestroyRef, signal, Input, ChangeDetectionStrategy, Component } from '@angular/core';
3
- import { BehaviorSubject } from 'rxjs';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import * as i1 from '@angular/common';
6
- import { CommonModule } from '@angular/common';
7
- import { tv } from 'tailwind-variants';
8
- import { MnButton } from 'mn-angular-lib/button';
9
- import { MnLanguageService } from 'mn-angular-lib/core';
10
-
11
- // projects/mn-angular-lib/src/lib/mn-mn-alert/mn-mn-alert.tokens.ts
12
- const MN_ALERT_CONFIG = new InjectionToken('MN_ALERT_CONFIG');
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, DestroyRef, Injectable, InjectionToken, Input, inject, signal } from "@angular/core";
3
+ import { BehaviorSubject } from "rxjs";
4
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
5
+ import * as i1 from "@angular/common";
6
+ import { CommonModule } from "@angular/common";
7
+ import { tv } from "tailwind-variants";
8
+ import { MnButton } from "mn-angular-lib/button";
9
+ import { MnLanguageService } from "mn-angular-lib/core";
10
+ const MN_ALERT_CONFIG = new InjectionToken("MN_ALERT_CONFIG");
13
11
  const DEFAULT_MN_ALERT_CONFIG = {
14
- durations: { success: 3000, info: 4000, warning: 5000, error: 7000, default: 4000 },
15
- cssClasses: {
16
- success: 'mn-alert-success',
17
- info: 'mn-alert-info',
18
- warning: 'mn-alert-warning',
19
- error: 'mn-alert-error',
20
- default: 'alert'
21
- },
22
- icons: {},
23
- fallbackDuration: 4000,
24
- maxVisible: 3,
25
- finalize: (a) => a
12
+ durations: {
13
+ success: 3e3,
14
+ info: 4e3,
15
+ warning: 5e3,
16
+ error: 7e3,
17
+ default: 4e3
18
+ },
19
+ cssClasses: {
20
+ success: "mn-alert-success",
21
+ info: "mn-alert-info",
22
+ warning: "mn-alert-warning",
23
+ error: "mn-alert-error",
24
+ default: "alert"
25
+ },
26
+ icons: {},
27
+ fallbackDuration: 4e3,
28
+ maxVisible: 3,
29
+ finalize: (a) => a
26
30
  };
27
-
28
31
  function provideMnAlerts(config = {}) {
29
- const merged = {
30
- ...DEFAULT_MN_ALERT_CONFIG,
31
- ...config,
32
- durations: { ...DEFAULT_MN_ALERT_CONFIG.durations, ...(config.durations ?? {}) },
33
- cssClasses: { ...DEFAULT_MN_ALERT_CONFIG.cssClasses, ...(config.cssClasses ?? {}) },
34
- icons: { ...DEFAULT_MN_ALERT_CONFIG.icons, ...(config.icons ?? {}) }
35
- };
36
- return { provide: MN_ALERT_CONFIG, useValue: merged };
32
+ const merged = {
33
+ ...DEFAULT_MN_ALERT_CONFIG,
34
+ ...config,
35
+ durations: {
36
+ ...DEFAULT_MN_ALERT_CONFIG.durations,
37
+ ...config.durations ?? {}
38
+ },
39
+ cssClasses: {
40
+ ...DEFAULT_MN_ALERT_CONFIG.cssClasses,
41
+ ...config.cssClasses ?? {}
42
+ },
43
+ icons: {
44
+ ...DEFAULT_MN_ALERT_CONFIG.icons,
45
+ ...config.icons ?? {}
46
+ }
47
+ };
48
+ return {
49
+ provide: MN_ALERT_CONFIG,
50
+ useValue: merged
51
+ };
37
52
  }
38
-
39
53
  let COUNTER = 0;
40
54
  const uid = () => `mn_${++COUNTER}`;
41
- class MnAlertStore {
42
- _alerts$ = new BehaviorSubject([]);
43
- alerts$ = this._alerts$.asObservable();
44
- /** Host configuration, when the app provided one. Only `maxVisible` is read here — the
45
- * per-kind durations are resolved by {@link MnAlertService} before an alert reaches the store. */
46
- cfg = inject(MN_ALERT_CONFIG, { optional: true });
47
- /** In-flight auto-dismiss timers keyed by alert id, so an alert that leaves early (dismissed
48
- * by hand, or pushed out by the visible cap) never fires a stale timeout later. */
49
- timers = new Map();
50
- /** How many alerts stay on screen at once; showing more drops the oldest ones. */
51
- get maxVisible() {
52
- const configured = this.cfg?.maxVisible;
53
- return typeof configured === 'number' && configured > 0
54
- ? configured
55
- : DEFAULT_MN_ALERT_CONFIG.maxVisible;
56
- }
57
- show(partial) {
58
- // Ensure every alert has a numeric duration: use provided or fall back to per-kind default
59
- const computedDuration = partial.duration ?? DEFAULT_MN_ALERT_CONFIG.durations[partial.kind ?? ''] ?? DEFAULT_MN_ALERT_CONFIG.fallbackDuration;
60
- const a = { id: uid(), ...partial, duration: computedDuration };
61
- // Newest alert last; anything beyond the cap is trimmed off the front (the oldest still
62
- // visible), so a burst of alerts scrolls rather than piling up.
63
- const queued = [...this._alerts$.value, a];
64
- const overflow = queued.length - this.maxVisible;
65
- if (overflow > 0) {
66
- queued.splice(0, overflow).forEach(dropped => this.clearTimer(dropped.id));
67
- }
68
- this._alerts$.next(queued);
69
- if (typeof a.duration === 'number' && a.duration > 0) {
70
- this.timers.set(a.id, setTimeout(() => this.dismiss(a.id), a.duration));
71
- }
72
- return a.id;
73
- }
74
- dismiss(id) {
75
- const list = this._alerts$.value;
76
- if (list.some(x => x.id === id)) {
77
- this.clearTimer(id);
78
- this._alerts$.next(list.filter(x => x.id !== id));
79
- }
80
- }
81
- clear() {
82
- this.timers.forEach(t => clearTimeout(t));
83
- this.timers.clear();
84
- this._alerts$.next([]);
85
- }
86
- clearTimer(id) {
87
- const timer = this.timers.get(id);
88
- if (timer !== undefined) {
89
- clearTimeout(timer);
90
- this.timers.delete(id);
91
- }
92
- }
93
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
94
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertStore, providedIn: 'root' });
95
- }
96
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertStore, decorators: [{
97
- type: Injectable,
98
- args: [{ providedIn: 'root' }]
99
- }] });
100
-
101
- // projects/mn-angular-lib/src/lib/mn-mn-alert/mn-mn-alert.service.ts
102
- class MnAlertService {
103
- store = inject(MnAlertStore);
104
- cfg;
105
- userDurations;
106
- hasUserDurations;
107
- constructor() {
108
- const cfg = inject(MN_ALERT_CONFIG, { optional: true });
109
- this.userDurations = cfg?.durations;
110
- this.hasUserDurations = !!cfg?.durations;
111
- this.cfg = {
112
- ...DEFAULT_MN_ALERT_CONFIG,
113
- ...(cfg ?? {}),
114
- // Do not pre-merge durations; keep defaults separate and use logic in kind()
115
- durations: DEFAULT_MN_ALERT_CONFIG.durations,
116
- cssClasses: { ...DEFAULT_MN_ALERT_CONFIG.cssClasses, ...(cfg?.cssClasses ?? {}) },
117
- icons: { ...DEFAULT_MN_ALERT_CONFIG.icons, ...(cfg?.icons ?? {}) }
118
- };
119
- }
120
- show(input) {
121
- // Always ensure a numeric duration is set
122
- let duration = input.duration;
123
- if (duration == null) {
124
- // Prefer user defaultDuration if provided and not null, otherwise use library per-kind default
125
- const userDefault = this.cfg.fallbackDuration;
126
- if (typeof userDefault === 'number') {
127
- duration = userDefault;
128
- }
129
- else {
130
- duration = DEFAULT_MN_ALERT_CONFIG.durations[input.kind];
131
- }
132
- }
133
- const a = {
134
- title: input.title,
135
- subTitle: input.subTitle,
136
- duration,
137
- icon: input.icon,
138
- cssClass: input.cssClass,
139
- meta: input.meta,
140
- kind: input.kind,
141
- variant: input.variant
142
- };
143
- return this.store.show(this.cfg.finalize(a));
144
- }
145
- success(title, subTitle, extra) {
146
- return this.kind('success', title, subTitle, extra);
147
- }
148
- info(title, subTitle, extra) {
149
- return this.kind('info', title, subTitle, extra);
150
- }
151
- warning(title, subTitle, extra) {
152
- return this.kind('warning', title, subTitle, extra);
153
- }
154
- error(title, subTitle, extra) {
155
- return this.kind('error', title, subTitle, extra);
156
- }
157
- dismiss(id) { this.store.dismiss(id); }
158
- clear() { this.store.clear(); }
159
- kind(kind, title, subTitle, extra) {
160
- let duration = extra?.duration;
161
- if (duration == null) {
162
- if (this.hasUserDurations) {
163
- const userDur = this.userDurations?.[kind];
164
- if (typeof userDur === 'number') {
165
- duration = userDur;
166
- }
167
- else {
168
- // userDur is undefined or null -> fallback to user defaultDuration if numeric
169
- if (typeof this.cfg.fallbackDuration === 'number') {
170
- duration = this.cfg.fallbackDuration;
171
- }
172
- else {
173
- duration = this.cfg.durations[kind];
174
- }
175
- }
176
- }
177
- else {
178
- // No user durations provided at all; use library defaults per kind
179
- duration = this.cfg.durations[kind];
180
- }
181
- }
182
- const cssClass = extra?.cssClass ?? this.cfg.cssClasses[kind];
183
- const icon = (extra?.icon ?? this.cfg.icons[kind]);
184
- const variant = extra?.variant;
185
- return this.show({ title, subTitle, duration: duration, cssClass, icon, meta: extra?.meta, kind: kind, variant });
186
- }
187
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
188
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertService, providedIn: 'root' });
189
- }
190
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertService, decorators: [{
191
- type: Injectable,
192
- args: [{ providedIn: 'root' }]
193
- }], ctorParameters: () => [] });
194
-
55
+ var MnAlertStore = class MnAlertStore {
56
+ _alerts$ = new BehaviorSubject([]);
57
+ alerts$ = this._alerts$.asObservable();
58
+ cfg = inject(MN_ALERT_CONFIG, { optional: true });
59
+ timers = /* @__PURE__ */ new Map();
60
+ get maxVisible() {
61
+ const configured = this.cfg?.maxVisible;
62
+ return typeof configured === "number" && configured > 0 ? configured : DEFAULT_MN_ALERT_CONFIG.maxVisible;
63
+ }
64
+ show(partial) {
65
+ const computedDuration = partial.duration ?? DEFAULT_MN_ALERT_CONFIG.durations[partial.kind ?? ""] ?? DEFAULT_MN_ALERT_CONFIG.fallbackDuration;
66
+ const a = {
67
+ id: uid(),
68
+ ...partial,
69
+ duration: computedDuration
70
+ };
71
+ const queued = [...this._alerts$.value, a];
72
+ const overflow = queued.length - this.maxVisible;
73
+ if (overflow > 0) queued.splice(0, overflow).forEach((dropped) => this.clearTimer(dropped.id));
74
+ this._alerts$.next(queued);
75
+ if (typeof a.duration === "number" && a.duration > 0) this.timers.set(a.id, setTimeout(() => this.dismiss(a.id), a.duration));
76
+ return a.id;
77
+ }
78
+ dismiss(id) {
79
+ const list = this._alerts$.value;
80
+ if (list.some((x) => x.id === id)) {
81
+ this.clearTimer(id);
82
+ this._alerts$.next(list.filter((x) => x.id !== id));
83
+ }
84
+ }
85
+ clear() {
86
+ this.timers.forEach((t) => clearTimeout(t));
87
+ this.timers.clear();
88
+ this._alerts$.next([]);
89
+ }
90
+ clearTimer(id) {
91
+ const timer = this.timers.get(id);
92
+ if (timer !== void 0) {
93
+ clearTimeout(timer);
94
+ this.timers.delete(id);
95
+ }
96
+ }
97
+ static ɵfac = i0.ɵɵngDeclareFactory({
98
+ minVersion: "12.0.0",
99
+ version: "22.2.2",
100
+ ngImport: i0,
101
+ type: MnAlertStore,
102
+ deps: [],
103
+ target: i0.ɵɵFactoryTarget.Injectable
104
+ });
105
+ static ɵprov = i0.ɵɵngDeclareInjectable({
106
+ minVersion: "12.0.0",
107
+ version: "22.2.2",
108
+ ngImport: i0,
109
+ type: MnAlertStore,
110
+ providedIn: "root"
111
+ });
112
+ };
113
+ i0.ɵɵngDeclareClassMetadata({
114
+ minVersion: "12.0.0",
115
+ version: "22.2.2",
116
+ ngImport: i0,
117
+ type: MnAlertStore,
118
+ decorators: [{
119
+ type: Injectable,
120
+ args: [{ providedIn: "root" }]
121
+ }]
122
+ });
123
+ var MnAlertService = class MnAlertService {
124
+ store = inject(MnAlertStore);
125
+ cfg;
126
+ userDurations;
127
+ hasUserDurations;
128
+ constructor() {
129
+ const cfg = inject(MN_ALERT_CONFIG, { optional: true });
130
+ this.userDurations = cfg?.durations;
131
+ this.hasUserDurations = !!cfg?.durations;
132
+ this.cfg = {
133
+ ...DEFAULT_MN_ALERT_CONFIG,
134
+ ...cfg ?? {},
135
+ durations: DEFAULT_MN_ALERT_CONFIG.durations,
136
+ cssClasses: {
137
+ ...DEFAULT_MN_ALERT_CONFIG.cssClasses,
138
+ ...cfg?.cssClasses ?? {}
139
+ },
140
+ icons: {
141
+ ...DEFAULT_MN_ALERT_CONFIG.icons,
142
+ ...cfg?.icons ?? {}
143
+ }
144
+ };
145
+ }
146
+ show(input) {
147
+ let duration = input.duration;
148
+ if (duration == null) {
149
+ const userDefault = this.cfg.fallbackDuration;
150
+ if (typeof userDefault === "number") duration = userDefault;
151
+ else duration = DEFAULT_MN_ALERT_CONFIG.durations[input.kind];
152
+ }
153
+ const a = {
154
+ title: input.title,
155
+ subTitle: input.subTitle,
156
+ duration,
157
+ icon: input.icon,
158
+ cssClass: input.cssClass,
159
+ meta: input.meta,
160
+ kind: input.kind,
161
+ variant: input.variant
162
+ };
163
+ return this.store.show(this.cfg.finalize(a));
164
+ }
165
+ success(title, subTitle, extra) {
166
+ return this.kind("success", title, subTitle, extra);
167
+ }
168
+ info(title, subTitle, extra) {
169
+ return this.kind("info", title, subTitle, extra);
170
+ }
171
+ warning(title, subTitle, extra) {
172
+ return this.kind("warning", title, subTitle, extra);
173
+ }
174
+ error(title, subTitle, extra) {
175
+ return this.kind("error", title, subTitle, extra);
176
+ }
177
+ dismiss(id) {
178
+ this.store.dismiss(id);
179
+ }
180
+ clear() {
181
+ this.store.clear();
182
+ }
183
+ kind(kind, title, subTitle, extra) {
184
+ let duration = extra?.duration;
185
+ if (duration == null) {
186
+ if (this.hasUserDurations) {
187
+ const userDur = this.userDurations?.[kind];
188
+ if (typeof userDur === "number") duration = userDur;
189
+ else if (typeof this.cfg.fallbackDuration === "number") duration = this.cfg.fallbackDuration;
190
+ else duration = this.cfg.durations[kind];
191
+ } else duration = this.cfg.durations[kind];
192
+ }
193
+ const cssClass = extra?.cssClass ?? this.cfg.cssClasses[kind];
194
+ const icon = extra?.icon ?? this.cfg.icons[kind];
195
+ const variant = extra?.variant;
196
+ return this.show({
197
+ title,
198
+ subTitle,
199
+ duration,
200
+ cssClass,
201
+ icon,
202
+ meta: extra?.meta,
203
+ kind,
204
+ variant
205
+ });
206
+ }
207
+ static ɵfac = i0.ɵɵngDeclareFactory({
208
+ minVersion: "12.0.0",
209
+ version: "22.2.2",
210
+ ngImport: i0,
211
+ type: MnAlertService,
212
+ deps: [],
213
+ target: i0.ɵɵFactoryTarget.Injectable
214
+ });
215
+ static ɵprov = i0.ɵɵngDeclareInjectable({
216
+ minVersion: "12.0.0",
217
+ version: "22.2.2",
218
+ ngImport: i0,
219
+ type: MnAlertService,
220
+ providedIn: "root"
221
+ });
222
+ };
223
+ i0.ɵɵngDeclareClassMetadata({
224
+ minVersion: "12.0.0",
225
+ version: "22.2.2",
226
+ ngImport: i0,
227
+ type: MnAlertService,
228
+ decorators: [{
229
+ type: Injectable,
230
+ args: [{ providedIn: "root" }]
231
+ }],
232
+ ctorParameters: () => []
233
+ });
195
234
  const mnAlertVariants = tv({
196
- base: 'flex items-start gap-3 p-4 border rounded-xl shadow-sm w-full ',
197
- variants: {
198
- kind: {
199
- success: 'bg-success/10 border-success/30 text-success',
200
- info: 'bg-info/10 border-info/30 text-info',
201
- warning: 'bg-warning/10 border-warning/30 text-warning',
202
- error: 'bg-error/10 border-error/30 text-error',
203
- default: 'bg-base-100 border-base-300 text-base-content',
204
- accent: 'bg-accent/10 border-accent/30 text-accent',
205
- },
206
- variant: {
207
- fill: '',
208
- outline: 'bg-base-200 border-2',
209
- soft: 'border-none shadow-none',
210
- }
211
- },
212
- compoundVariants: [
213
- {
214
- kind: 'success',
215
- variant: 'fill',
216
- class: 'bg-success border-success text-success-content'
217
- },
218
- {
219
- kind: 'info',
220
- variant: 'fill',
221
- class: 'bg-info border-info text-info-content'
222
- },
223
- {
224
- kind: 'warning',
225
- variant: 'fill',
226
- class: 'bg-warning border-warning text-warning-content'
227
- },
228
- {
229
- kind: 'error',
230
- variant: 'fill',
231
- class: 'bg-error border-error text-error-content'
232
- },
233
- {
234
- kind: 'accent',
235
- variant: 'fill',
236
- class: 'bg-accent border-accent text-accent-content'
237
- },
238
- ],
239
- defaultVariants: {
240
- kind: 'info',
241
- variant: 'soft'
242
- }
235
+ base: "flex items-start gap-3 p-4 border rounded-xl shadow-sm w-full ",
236
+ variants: {
237
+ kind: {
238
+ success: "bg-success/10 border-success/30 text-success",
239
+ info: "bg-info/10 border-info/30 text-info",
240
+ warning: "bg-warning/10 border-warning/30 text-warning",
241
+ error: "bg-error/10 border-error/30 text-error",
242
+ default: "bg-base-100 border-base-300 text-base-content",
243
+ accent: "bg-accent/10 border-accent/30 text-accent"
244
+ },
245
+ variant: {
246
+ fill: "",
247
+ outline: "bg-base-200 border-2",
248
+ soft: "border-none shadow-none"
249
+ }
250
+ },
251
+ compoundVariants: [
252
+ {
253
+ kind: "success",
254
+ variant: "fill",
255
+ class: "bg-success border-success text-success-content"
256
+ },
257
+ {
258
+ kind: "info",
259
+ variant: "fill",
260
+ class: "bg-info border-info text-info-content"
261
+ },
262
+ {
263
+ kind: "warning",
264
+ variant: "fill",
265
+ class: "bg-warning border-warning text-warning-content"
266
+ },
267
+ {
268
+ kind: "error",
269
+ variant: "fill",
270
+ class: "bg-error border-error text-error-content"
271
+ },
272
+ {
273
+ kind: "accent",
274
+ variant: "fill",
275
+ class: "bg-accent border-accent text-accent-content"
276
+ }
277
+ ],
278
+ defaultVariants: {
279
+ kind: "info",
280
+ variant: "soft"
281
+ }
282
+ });
283
+ var MnAlertOutletComponent = class MnAlertOutletComponent {
284
+ lang = inject(MnLanguageService);
285
+ store = inject(MnAlertStore);
286
+ destroyRef = inject(DestroyRef);
287
+ static SWIPE_DISMISS_THRESHOLD = 96;
288
+ static FLICK_VELOCITY = .4;
289
+ static FLICK_MIN_DISTANCE = 24;
290
+ static EXIT_MS = 320;
291
+ static DRAG_OPACITY_FLOOR = .35;
292
+ swipeAxis = "auto";
293
+ isApple = this.detectApple();
294
+ get vertical() {
295
+ if (this.swipeAxis === "vertical") return true;
296
+ if (this.swipeAxis === "horizontal") return false;
297
+ return this.isApple;
298
+ }
299
+ get closeLabel() {
300
+ return this.lang.translateIfPresent("mnAlert.close") ?? "Close";
301
+ }
302
+ template;
303
+ views = signal([], ...ngDevMode ? [{ debugName: "views" }] : /* istanbul ignore next */ []);
304
+ get touchAction() {
305
+ return this.vertical ? "pan-x" : "pan-y";
306
+ }
307
+ exitTimers = /* @__PURE__ */ new Map();
308
+ activeDrag = null;
309
+ constructor() {
310
+ this.store.alerts$.pipe(takeUntilDestroyed()).subscribe((alerts) => this.sync(alerts));
311
+ this.destroyRef.onDestroy(() => {
312
+ this.exitTimers.forEach((t) => clearTimeout(t));
313
+ this.exitTimers.clear();
314
+ });
315
+ }
316
+ trackById = (_, v) => v.alert.id;
317
+ getAlertClasses(a) {
318
+ return mnAlertVariants({
319
+ kind: a.kind,
320
+ variant: a.variant
321
+ });
322
+ }
323
+ countdownDuration(v) {
324
+ if (v.leaving) return null;
325
+ const duration = v.alert.duration;
326
+ return typeof duration === "number" && duration > 0 ? duration : null;
327
+ }
328
+ contextFor(a) {
329
+ return {
330
+ $implicit: a,
331
+ alert: a,
332
+ dismiss: () => this.dismissAlert(a.id)
333
+ };
334
+ }
335
+ dismissAlert(id) {
336
+ this.store.dismiss(id);
337
+ }
338
+ sync(alerts) {
339
+ const current = this.views();
340
+ const existing = new Set(current.map((v) => v.alert.id));
341
+ const storeById = new Map(alerts.map((a) => [a.id, a]));
342
+ const next = [];
343
+ for (const v of current) {
344
+ const fresh = storeById.get(v.alert.id);
345
+ if (fresh) v.alert = fresh;
346
+ else if (!v.leaving) this.beginLeave(v);
347
+ next.push(v);
348
+ }
349
+ for (const a of alerts) if (!existing.has(a.id)) next.push({
350
+ alert: a,
351
+ leaving: false,
352
+ dragging: false,
353
+ drag: 0,
354
+ fling: 0
355
+ });
356
+ this.views.set(next);
357
+ }
358
+ beginLeave(v, fling) {
359
+ if (v.leaving) return;
360
+ v.leaving = true;
361
+ v.dragging = false;
362
+ if (fling !== void 0) v.fling = fling;
363
+ const delay = this.prefersReducedMotion() ? 0 : MnAlertOutletComponent.EXIT_MS;
364
+ const timer = setTimeout(() => this.removeView(v.alert.id), delay);
365
+ this.exitTimers.set(v.alert.id, timer);
366
+ }
367
+ removeView(id) {
368
+ const timer = this.exitTimers.get(id);
369
+ if (timer) {
370
+ clearTimeout(timer);
371
+ this.exitTimers.delete(id);
372
+ }
373
+ this.views.update((list) => list.filter((v) => v.alert.id !== id));
374
+ }
375
+ onPointerDown(event, v) {
376
+ if (v.leaving) return;
377
+ if (event.target.closest("button, a, input, textarea, select")) return;
378
+ if (event.button !== void 0 && event.button !== 0) return;
379
+ const coord = this.axisCoord(event);
380
+ this.activeDrag = {
381
+ view: v,
382
+ startCoord: coord,
383
+ lastSample: {
384
+ c: coord,
385
+ t: event.timeStamp
386
+ },
387
+ prevSample: {
388
+ c: coord,
389
+ t: event.timeStamp
390
+ }
391
+ };
392
+ v.dragging = true;
393
+ event.currentTarget.setPointerCapture?.(event.pointerId);
394
+ }
395
+ onPointerMove(event, v) {
396
+ const drag = this.activeDrag;
397
+ if (!drag || drag.view !== v) return;
398
+ const delta = this.axisCoord(event) - drag.startCoord;
399
+ v.drag = this.vertical ? Math.min(0, delta) : Math.max(0, delta);
400
+ drag.prevSample = drag.lastSample;
401
+ drag.lastSample = {
402
+ c: this.axisCoord(event),
403
+ t: event.timeStamp
404
+ };
405
+ }
406
+ onPointerUp(event, v) {
407
+ const drag = this.activeDrag;
408
+ if (!drag || drag.view !== v) return;
409
+ this.activeDrag = null;
410
+ v.dragging = false;
411
+ if (this.shouldDismiss(drag, v)) {
412
+ const extent = this.viewportExtent() + Math.abs(v.drag);
413
+ const fling = this.vertical ? -extent : extent;
414
+ this.beginLeave(v, fling);
415
+ this.store.dismiss(v.alert.id);
416
+ } else v.drag = 0;
417
+ this.views.update((list) => [...list]);
418
+ }
419
+ shouldDismiss(drag, v) {
420
+ if (Math.abs(v.drag) > MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD) return true;
421
+ const dt = drag.lastSample.t - drag.prevSample.t;
422
+ return (dt > 0 ? Math.abs(drag.lastSample.c - drag.prevSample.c) / dt : 0) > MnAlertOutletComponent.FLICK_VELOCITY && Math.abs(v.drag) > MnAlertOutletComponent.FLICK_MIN_DISTANCE;
423
+ }
424
+ itemTransform(v) {
425
+ if (v.leaving) return v.fling !== 0 ? this.translate(v.fling) : null;
426
+ return v.drag !== 0 ? this.translate(v.drag) : null;
427
+ }
428
+ itemOpacity(v) {
429
+ if (v.leaving || !v.dragging || v.drag === 0) return null;
430
+ return 1 - Math.min(Math.abs(v.drag) / MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD, 1) * (1 - MnAlertOutletComponent.DRAG_OPACITY_FLOOR);
431
+ }
432
+ translate(px) {
433
+ return this.vertical ? `translateY(${px}px)` : `translateX(${px}px)`;
434
+ }
435
+ axisCoord(event) {
436
+ return this.vertical ? event.clientY : event.clientX;
437
+ }
438
+ viewportExtent() {
439
+ if (typeof window === "undefined") return 400;
440
+ return this.vertical ? window.innerHeight : window.innerWidth;
441
+ }
442
+ detectApple() {
443
+ if (typeof navigator === "undefined") return false;
444
+ const ua = navigator.userAgent ?? "";
445
+ const platform = navigator.platform ?? "";
446
+ const isIOS = /iP(hone|ad|od)/.test(platform) || /iPad|iPhone|iPod/.test(ua);
447
+ const isTouchMac = /Mac/.test(platform + " " + ua) && typeof document !== "undefined" && "ontouchend" in document;
448
+ const isMac = /Mac/.test(ua);
449
+ return isIOS || isTouchMac || isMac;
450
+ }
451
+ prefersReducedMotion() {
452
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
453
+ }
454
+ static ɵfac = i0.ɵɵngDeclareFactory({
455
+ minVersion: "12.0.0",
456
+ version: "22.2.2",
457
+ ngImport: i0,
458
+ type: MnAlertOutletComponent,
459
+ deps: [],
460
+ target: i0.ɵɵFactoryTarget.Component
461
+ });
462
+ static ɵcmp = i0.ɵɵngDeclareComponent({
463
+ minVersion: "17.0.0",
464
+ version: "22.2.2",
465
+ type: MnAlertOutletComponent,
466
+ isStandalone: true,
467
+ selector: "mn-alert-outlet",
468
+ inputs: {
469
+ swipeAxis: "swipeAxis",
470
+ template: "template"
471
+ },
472
+ ngImport: i0,
473
+ template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n &times;\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n",
474
+ styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"],
475
+ dependencies: [
476
+ {
477
+ kind: "ngmodule",
478
+ type: CommonModule
479
+ },
480
+ {
481
+ kind: "directive",
482
+ type: i1.NgTemplateOutlet,
483
+ selector: "[ngTemplateOutlet]",
484
+ inputs: [
485
+ "ngTemplateOutletContext",
486
+ "ngTemplateOutlet",
487
+ "ngTemplateOutletInjector"
488
+ ]
489
+ },
490
+ {
491
+ kind: "component",
492
+ type: MnButton,
493
+ selector: "button[mnButton], a[mnButton]",
494
+ inputs: ["data"]
495
+ }
496
+ ],
497
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
498
+ });
499
+ };
500
+ i0.ɵɵngDeclareClassMetadata({
501
+ minVersion: "12.0.0",
502
+ version: "22.2.2",
503
+ ngImport: i0,
504
+ type: MnAlertOutletComponent,
505
+ decorators: [{
506
+ type: Component,
507
+ args: [{
508
+ selector: "mn-alert-outlet",
509
+ standalone: true,
510
+ imports: [CommonModule, MnButton],
511
+ changeDetection: ChangeDetectionStrategy.OnPush,
512
+ template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n &times;\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n",
513
+ styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"]
514
+ }]
515
+ }],
516
+ ctorParameters: () => [],
517
+ propDecorators: {
518
+ swipeAxis: [{ type: Input }],
519
+ template: [{ type: Input }]
520
+ }
243
521
  });
244
-
245
- class MnAlertOutletComponent {
246
- lang = inject(MnLanguageService);
247
- store = inject(MnAlertStore);
248
- destroyRef = inject(DestroyRef);
249
- /** Drag distance (px) past which a release dismisses regardless of speed. */
250
- static SWIPE_DISMISS_THRESHOLD = 96;
251
- /** Release speed (px/ms) above which a short drag still dismisses — a "flick". */
252
- static FLICK_VELOCITY = 0.4;
253
- /** Minimum drag distance (px) a flick must cover, so an incidental fast tap never dismisses. */
254
- static FLICK_MIN_DISTANCE = 24;
255
- /** Upper bound for the leave wait; kept a touch longer than the CSS exit so removal never
256
- * preempts the animation. Mirrored by the `--mn-alert-exit` duration in the stylesheet. */
257
- static EXIT_MS = 320;
258
- /** Opacity floor a card fades to at the dismiss threshold, for drag feedback. */
259
- static DRAG_OPACITY_FLOOR = 0.35;
260
- /**
261
- * How the dismiss swipe is oriented:
262
- * - `'auto'` (default) matches the host platform's convention — Apple platforms
263
- * (iOS/iPadOS/macOS) flick a top banner *upward*, so we swipe vertically; Android (and
264
- * every other platform) dismisses toasts *to the right*, so we swipe horizontally.
265
- *
266
- * Either axis is one-directional: only an upward (vertical) or rightward (horizontal)
267
- * drag dismisses; dragging the opposite way springs the card back.
268
- * - `'vertical'` / `'horizontal'` force the axis regardless of platform. Useful when the
269
- * host can't be sniffed reliably (e.g. Chrome DevTools *Responsive* mode does not spoof
270
- * the user agent, so `'auto'` there resolves to the desktop/Android horizontal axis).
271
- */
272
- swipeAxis = 'auto';
273
- /** Whether the running device is an Apple platform. Sniffed once from `navigator` at
274
- * construction (the UA is read at page load and does not change mid-session). */
275
- isApple = this.detectApple();
276
- /** The resolved swipe axis: the explicit {@link swipeAxis} override, or the platform
277
- * default when left on `'auto'`. */
278
- get vertical() {
279
- if (this.swipeAxis === 'vertical')
280
- return true;
281
- if (this.swipeAxis === 'horizontal')
282
- return false;
283
- return this.isApple;
284
- }
285
- /**
286
- * Accessible name for this control. Resolved through the conventional
287
- * `mnAlert.close` key so an app can translate it, falling back to English when the
288
- * key is not defined rather than leaking the raw key into the UI.
289
- */
290
- get closeLabel() {
291
- return this.lang.translateIfPresent('mnAlert.close') ?? 'Close';
292
- }
293
- template;
294
- /** The view-layer mirror of the store's alerts, retaining alerts mid-leave. A signal so
295
- * writes from the (external) store subscription and leave timers schedule change
296
- * detection in a zoneless app. */
297
- views = signal([], /* @ts-ignore */
298
- ...(ngDevMode ? [{ debugName: "views" }] : /* istanbul ignore next */ []));
299
- /**
300
- * `touch-action` for the swipe wrapper: reserve the swipe axis for our gesture while
301
- * leaving the cross-axis to the browser. Vertical swipe (Apple) claims the Y axis
302
- * (`pan-x`); horizontal swipe (Android/other) claims the X axis (`pan-y`).
303
- */
304
- get touchAction() {
305
- return this.vertical ? 'pan-x' : 'pan-y';
306
- }
307
- /** In-flight leave-removal timers, keyed by alert id, cleared on destroy so a fired
308
- * timer never touches a torn-down view. */
309
- exitTimers = new Map();
310
- /** The single active swipe, or null. Only one card is dragged at a time. `startCoord`
311
- * and the samples are taken along the active axis (Y when vertical, else X). */
312
- activeDrag = null;
313
- constructor() {
314
- this.store.alerts$
315
- .pipe(takeUntilDestroyed())
316
- .subscribe(alerts => this.sync(alerts));
317
- this.destroyRef.onDestroy(() => {
318
- this.exitTimers.forEach(t => clearTimeout(t));
319
- this.exitTimers.clear();
320
- });
321
- }
322
- trackById = (_, v) => v.alert.id;
323
- getAlertClasses(a) {
324
- return mnAlertVariants({ kind: a.kind, variant: a.variant });
325
- }
326
- /**
327
- * The lifetime (ms) to run the countdown bar over, or null when no bar should show: an alert
328
- * that never auto-dismisses has nothing to count down, and one already leaving would only
329
- * restart the animation mid-exit.
330
- */
331
- countdownDuration(v) {
332
- if (v.leaving)
333
- return null;
334
- const duration = v.alert.duration;
335
- return typeof duration === 'number' && duration > 0 ? duration : null;
336
- }
337
- contextFor(a) {
338
- return {
339
- $implicit: a,
340
- alert: a,
341
- dismiss: () => this.dismissAlert(a.id)
342
- };
343
- }
344
- /** Dismisses via the store; the store's removal is turned into a leave animation by
345
- * {@link sync}. Used by the close button and the custom-template `dismiss` context. */
346
- dismissAlert(id) {
347
- this.store.dismiss(id);
348
- }
349
- // =========================
350
- // Store → view reconciliation
351
- // =========================
352
- /** Reconciles the view list against the store: appends new alerts, updates the alert
353
- * reference for still-present ones, and marks vanished ones as leaving (they stay in the
354
- * list, animating out, until their removal timer fires). */
355
- sync(alerts) {
356
- const current = this.views();
357
- const existing = new Set(current.map(v => v.alert.id));
358
- const storeById = new Map(alerts.map(a => [a.id, a]));
359
- const next = [];
360
- for (const v of current) {
361
- const fresh = storeById.get(v.alert.id);
362
- if (fresh) {
363
- v.alert = fresh;
364
- }
365
- else if (!v.leaving) {
366
- this.beginLeave(v);
367
- }
368
- next.push(v);
369
- }
370
- for (const a of alerts) {
371
- if (!existing.has(a.id)) {
372
- next.push({ alert: a, leaving: false, dragging: false, drag: 0, fling: 0 });
373
- }
374
- }
375
- this.views.set(next);
376
- }
377
- /** Flags a view as leaving and schedules its removal once the exit animation has run.
378
- * Idempotent: a card already leaving (e.g. flung by a swipe) is left untouched, so a
379
- * synchronous store re-emit cannot overwrite the swipe direction with the default fade. */
380
- beginLeave(v, fling) {
381
- if (v.leaving)
382
- return;
383
- v.leaving = true;
384
- v.dragging = false;
385
- if (fling !== undefined)
386
- v.fling = fling;
387
- const delay = this.prefersReducedMotion() ? 0 : MnAlertOutletComponent.EXIT_MS;
388
- const timer = setTimeout(() => this.removeView(v.alert.id), delay);
389
- this.exitTimers.set(v.alert.id, timer);
390
- }
391
- removeView(id) {
392
- const timer = this.exitTimers.get(id);
393
- if (timer) {
394
- clearTimeout(timer);
395
- this.exitTimers.delete(id);
396
- }
397
- this.views.update(list => list.filter(v => v.alert.id !== id));
398
- }
399
- // =========================
400
- // Swipe-to-dismiss
401
- // =========================
402
- onPointerDown(event, v) {
403
- if (v.leaving)
404
- return;
405
- // Don't hijack a press that begins on an interactive control inside the alert.
406
- if (event.target.closest('button, a, input, textarea, select'))
407
- return;
408
- if (event.button !== undefined && event.button !== 0)
409
- return;
410
- const coord = this.axisCoord(event);
411
- this.activeDrag = {
412
- view: v,
413
- startCoord: coord,
414
- lastSample: { c: coord, t: event.timeStamp },
415
- prevSample: { c: coord, t: event.timeStamp },
416
- };
417
- v.dragging = true;
418
- event.currentTarget.setPointerCapture?.(event.pointerId);
419
- }
420
- onPointerMove(event, v) {
421
- const drag = this.activeDrag;
422
- if (!drag || drag.view !== v)
423
- return;
424
- const delta = this.axisCoord(event) - drag.startCoord;
425
- // Dismissal is one-directional: vertical (Apple) tracks upward only (clamp ≤ 0),
426
- // horizontal (Android/other) tracks rightward only (clamp ≥ 0). A drag the other way
427
- // rests at 0 and springs back.
428
- v.drag = this.vertical ? Math.min(0, delta) : Math.max(0, delta);
429
- drag.prevSample = drag.lastSample;
430
- drag.lastSample = { c: this.axisCoord(event), t: event.timeStamp };
431
- }
432
- onPointerUp(event, v) {
433
- const drag = this.activeDrag;
434
- if (!drag || drag.view !== v)
435
- return;
436
- this.activeDrag = null;
437
- v.dragging = false;
438
- if (this.shouldDismiss(drag, v)) {
439
- // Fling the card the rest of the way off its edge, then dismiss through the store.
440
- // Vertical flings upward (off the top); horizontal flings rightward (off the right).
441
- const extent = this.viewportExtent() + Math.abs(v.drag);
442
- const fling = this.vertical ? -extent : extent;
443
- this.beginLeave(v, fling);
444
- this.store.dismiss(v.alert.id);
445
- }
446
- else {
447
- // Snap back to rest; the wrapper's transition eases the offset → 0.
448
- v.drag = 0;
449
- }
450
- // Notify: pointerup is template-bound (schedules CD), but the leave/snap mutations live
451
- // on the view object — re-set the signal so the new transform is reflected reliably.
452
- this.views.update(list => [...list]);
453
- }
454
- shouldDismiss(drag, v) {
455
- if (Math.abs(v.drag) > MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD)
456
- return true;
457
- const dt = drag.lastSample.t - drag.prevSample.t;
458
- const velocity = dt > 0 ? Math.abs(drag.lastSample.c - drag.prevSample.c) / dt : 0;
459
- return velocity > MnAlertOutletComponent.FLICK_VELOCITY
460
- && Math.abs(v.drag) > MnAlertOutletComponent.FLICK_MIN_DISTANCE;
461
- }
462
- // =========================
463
- // Template style helpers
464
- // =========================
465
- /** Offset transform for a card: the fling target while leaving via swipe, otherwise the
466
- * live drag offset, translated along the active axis. Returns null when neither applies,
467
- * letting the stylesheet own the default (fade-in-place) leave. */
468
- itemTransform(v) {
469
- if (v.leaving) {
470
- return v.fling !== 0 ? this.translate(v.fling) : null;
471
- }
472
- return v.drag !== 0 ? this.translate(v.drag) : null;
473
- }
474
- /** Fades a card toward a floor as it is dragged toward the dismiss threshold. Null (CSS
475
- * owns opacity) when at rest or leaving. */
476
- itemOpacity(v) {
477
- if (v.leaving || !v.dragging || v.drag === 0)
478
- return null;
479
- const progress = Math.min(Math.abs(v.drag) / MnAlertOutletComponent.SWIPE_DISMISS_THRESHOLD, 1);
480
- return 1 - progress * (1 - MnAlertOutletComponent.DRAG_OPACITY_FLOOR);
481
- }
482
- translate(px) {
483
- return this.vertical ? `translateY(${px}px)` : `translateX(${px}px)`;
484
- }
485
- axisCoord(event) {
486
- return this.vertical ? event.clientY : event.clientX;
487
- }
488
- viewportExtent() {
489
- if (typeof window === 'undefined')
490
- return 400;
491
- return this.vertical ? window.innerHeight : window.innerWidth;
492
- }
493
- /** Whether the current device runs an Apple OS (iOS/iPadOS/macOS). iPadOS 13+ masquerades
494
- * as a Mac, so it is caught by the touch-capable-Mac branch. */
495
- detectApple() {
496
- if (typeof navigator === 'undefined')
497
- return false;
498
- const ua = navigator.userAgent ?? '';
499
- const platform = navigator.platform ?? '';
500
- const isIOS = /iP(hone|ad|od)/.test(platform) || /iPad|iPhone|iPod/.test(ua);
501
- const isTouchMac = /Mac/.test(platform + ' ' + ua)
502
- && typeof document !== 'undefined' && 'ontouchend' in document;
503
- const isMac = /Mac/.test(ua);
504
- return isIOS || isTouchMac || isMac;
505
- }
506
- prefersReducedMotion() {
507
- return typeof window !== 'undefined'
508
- && typeof window.matchMedia === 'function'
509
- && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
510
- }
511
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertOutletComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
512
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: MnAlertOutletComponent, isStandalone: true, selector: "mn-alert-outlet", inputs: { swipeAxis: "swipeAxis", template: "template" }, ngImport: i0, template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n &times;\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n", styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
513
- }
514
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnAlertOutletComponent, decorators: [{
515
- type: Component,
516
- args: [{ selector: 'mn-alert-outlet', standalone: true, imports: [CommonModule, MnButton], changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- The stack is a polite live region so every toast is announced; an error toast upgrades itself to an alert. -->\n<div aria-live=\"polite\" role=\"status\" class=\"fixed top-4 left-0 right-0 z-[9999] flex flex-col w-full px-2 sm:px-0 sm:left-auto sm:right-4 sm:max-w-sm\">\n @for (v of views(); track trackById($index, v)) {\n <div\n class=\"mn-alert-item\"\n [attr.role]=\"v.alert.kind === 'error' ? 'alert' : null\"\n [class.dragging]=\"v.dragging\"\n [class.leaving]=\"v.leaving\"\n [style.touch-action]=\"touchAction\"\n [style.transform]=\"itemTransform(v)\"\n [style.opacity]=\"itemOpacity(v)\"\n (pointerdown)=\"onPointerDown($event, v)\"\n (pointermove)=\"onPointerMove($event, v)\"\n (pointerup)=\"onPointerUp($event, v)\"\n (pointercancel)=\"onPointerUp($event, v)\"\n >\n <div class=\"mn-alert-inner\">\n @if (template) {\n <ng-container\n [ngTemplateOutlet]=\"template\"\n [ngTemplateOutletContext]=\"contextFor(v.alert)\">\n </ng-container>\n } @else {\n <div [class.extra]=\"v.alert.cssClass\" [class]=\"getAlertClasses(v.alert)\" class=\"relative overflow-hidden\">\n <div class=\"flex-1 min-w-0 pr-8\">\n <h4 class=\"font-semibold text-sm\">{{ v.alert.title }}</h4>\n @if (v.alert.subTitle) {\n <p class=\"text-sm mt-1 opacity-90 leading-tight\">{{ v.alert.subTitle }}</p>\n }\n </div>\n <button\n [attr.aria-label]=\"closeLabel\"\n mnButton\n [data]=\"{ size: 'md', variant: 'text' }\"\n (click)=\"dismissAlert(v.alert.id)\"\n class=\"absolute top-2 right-2 shrink-0 !text-current hover:!bg-current/10\"\n type=\"button\"\n >\n &times;\n </button>\n @if (countdownDuration(v); as ms) {\n <span aria-hidden=\"true\" class=\"mn-alert-progress\">\n <span [style.animation-duration.ms]=\"ms\" class=\"mn-alert-progress-bar\"></span>\n </span>\n }\n </div>\n }\n </div>\n </div>\n }\n</div>\n", styles: [":host{--mn-alert-exit: .32s}.mn-alert-item{display:grid;grid-template-rows:1fr;margin-bottom:.75rem;touch-action:pan-y;cursor:grab;transition:transform .28s cubic-bezier(.22,1,.36,1),opacity var(--mn-alert-exit) ease,grid-template-rows var(--mn-alert-exit) cubic-bezier(.4,0,.2,1),margin-bottom var(--mn-alert-exit) cubic-bezier(.4,0,.2,1)}.mn-alert-item:last-child{margin-bottom:0}.mn-alert-item.dragging{transition:none;cursor:grabbing;-webkit-user-select:none;user-select:none}.mn-alert-inner{min-height:0}.mn-alert-item.leaving{grid-template-rows:0fr;opacity:0;margin-bottom:0;pointer-events:none}.mn-alert-item.leaving .mn-alert-inner{overflow:hidden}.mn-alert-progress{position:absolute;left:0;right:0;bottom:0;height:3px;overflow:hidden;background-color:color-mix(in srgb,currentColor 18%,transparent);pointer-events:none}.mn-alert-progress-bar{display:block;height:100%;background-color:currentColor;opacity:.55;transform-origin:left center;animation-name:mn-alert-countdown;animation-timing-function:linear;animation-fill-mode:forwards}@keyframes mn-alert-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@media(prefers-reduced-motion:reduce){.mn-alert-item{transition:none}}\n"] }]
517
- }], ctorParameters: () => [], propDecorators: { swipeAxis: [{
518
- type: Input
519
- }], template: [{
520
- type: Input
521
- }] } });
522
-
523
- /**
524
- * Public API of the `mn-angular-lib/alert` entry point: toast alerts.
525
- *
526
- * Each entry point is its own module in the published package, so a consumer's bundler
527
- * splits it into the chunk that uses it instead of loading the whole library at startup.
528
- * The root `mn-angular-lib` entry re-exports every entry point.
529
- */
530
-
531
- /**
532
- * Generated bundle index. Do not edit.
533
- */
534
-
535
522
  export { DEFAULT_MN_ALERT_CONFIG, MN_ALERT_CONFIG, MnAlertOutletComponent, MnAlertService, MnAlertStore, mnAlertVariants, provideMnAlerts };
536
- //# sourceMappingURL=mn-angular-lib-alert.mjs.map
523
+
524
+ //# sourceMappingURL=mn-angular-lib-alert.mjs.map