@omicronenergy/oscd-ui 0.0.13 → 0.0.14

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 (42) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/custom-elements.json +8243 -5766
  3. package/dist/decorators/localstorage.d.ts +8 -0
  4. package/dist/decorators/localstorage.js +136 -0
  5. package/dist/decorators/localstorage.js.map +1 -0
  6. package/dist/decorators/localstorage.spec.d.ts +1 -0
  7. package/dist/decorators/localstorage.spec.js +138 -0
  8. package/dist/decorators/localstorage.spec.js.map +1 -0
  9. package/dist/snackbar/OscdSnackbar.d.ts +133 -0
  10. package/dist/snackbar/OscdSnackbar.js +505 -0
  11. package/dist/snackbar/OscdSnackbar.js.map +1 -0
  12. package/dist/snackbar/OscdSnackbar.spec.d.ts +1 -0
  13. package/dist/snackbar/OscdSnackbar.spec.js +287 -0
  14. package/dist/snackbar/OscdSnackbar.spec.js.map +1 -0
  15. package/dist/snackbar/OscdSnackbar.stories.d.ts +22 -0
  16. package/dist/snackbar/OscdSnackbar.stories.js +214 -0
  17. package/dist/snackbar/OscdSnackbar.stories.js.map +1 -0
  18. package/dist/snackbar/oscd-snackbar.d.ts +2 -0
  19. package/dist/snackbar/oscd-snackbar.js +4 -0
  20. package/dist/snackbar/oscd-snackbar.js.map +1 -0
  21. package/dist/tree/OscdTree.d.ts +81 -0
  22. package/dist/tree/OscdTree.js +76 -0
  23. package/dist/tree/OscdTree.js.map +1 -0
  24. package/dist/tree/OscdTree.stories.d.ts +59 -0
  25. package/dist/tree/OscdTree.stories.js +341 -0
  26. package/dist/tree/OscdTree.stories.js.map +1 -0
  27. package/dist/tree/OscdTreeItem.d.ts +43 -0
  28. package/dist/tree/OscdTreeItem.js +39 -0
  29. package/dist/tree/OscdTreeItem.js.map +1 -0
  30. package/dist/tree/internal/Tree.d.ts +186 -0
  31. package/dist/tree/internal/Tree.js +590 -0
  32. package/dist/tree/internal/Tree.js.map +1 -0
  33. package/dist/tree/internal/TreeItem.d.ts +25 -0
  34. package/dist/tree/internal/TreeItem.js +200 -0
  35. package/dist/tree/internal/TreeItem.js.map +1 -0
  36. package/dist/tree/oscd-tree-item.d.ts +2 -0
  37. package/dist/tree/oscd-tree-item.js +4 -0
  38. package/dist/tree/oscd-tree-item.js.map +1 -0
  39. package/dist/tree/oscd-tree.d.ts +3 -0
  40. package/dist/tree/oscd-tree.js +5 -0
  41. package/dist/tree/oscd-tree.js.map +1 -0
  42. package/package.json +8 -1
@@ -0,0 +1,505 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html, LitElement, nothing } from 'lit';
3
+ import { property, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
5
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';
6
+ import { OscdElevation } from '../elevation/OscdElevation.js';
7
+ import { OscdIcon } from '../icon/OscdIcon.js';
8
+ import { OscdIconButton } from '../iconbutton/OscdIconButton.js';
9
+ const closeAnimationMs = 160;
10
+ const iconByVariant = {
11
+ info: 'info',
12
+ success: 'check_circle',
13
+ warning: 'warning',
14
+ error: 'cancel',
15
+ };
16
+ let nextSnackbarId = 0;
17
+ /**
18
+ * @tagname oscd-snackbar
19
+ * @summary Snackbar banner for transient status, warning, and error messages.
20
+ *
21
+ * @cssprop [--oscd-snackbar-z-index=9999] - Stacking order for the fixed snackbar stack.
22
+ * @cssprop [--oscd-snackbar-bottom=16px] - Distance from the bottom viewport edge.
23
+ * @cssprop [--oscd-snackbar-gap=8px] - Gap between stacked snackbars.
24
+ * @cssprop [--oscd-snackbar-max-width=80vw] - Maximum snackbar stack width.
25
+ * @cssprop [--oscd-snackbar-min-width=min(360px, 80vw)] - Minimum snackbar item width.
26
+ * @cssprop [--oscd-snackbar-min-height=48px] - Minimum snackbar item height.
27
+ * @cssprop [--oscd-snackbar-container-padding=12px 16px] - Snackbar item padding.
28
+ * @cssprop [--oscd-snackbar-elevation-level=3] - Snackbar elevation level.
29
+ * @cssprop [--oscd-snackbar-enter-duration=160ms] - Show animation duration.
30
+ * @cssprop [--oscd-snackbar-exit-duration=160ms] - Hide animation duration.
31
+ * @cssprop [--oscd-snackbar-text-color=#233042] - Snackbar text color.
32
+ * @cssprop [--oscd-snackbar-font-family=var(--md-sys-typescale-body-large-font)] - Snackbar font family.
33
+ * @cssprop [--oscd-snackbar-font-size=var(--md-sys-typescale-body-large-size)] - Snackbar font size.
34
+ * @cssprop [--oscd-snackbar-line-height=var(--md-sys-typescale-body-large-line-height)] - Snackbar line height.
35
+ * @cssprop [--oscd-snackbar-message-line-clamp=3] - Maximum visible message lines before truncation.
36
+ *
37
+ * @cssprop [--oscd-snackbar-info-container-color=var(--md-sys-color-secondary-container)] - Info snackbar container color.
38
+ * @cssprop [--oscd-snackbar-info-text-color=var(--oscd-snackbar-text-color)] - Info text color.
39
+ * @cssprop [--oscd-snackbar-info-icon-color=var(--md-sys-color-on-secondary-container)] - Info icon color.
40
+ *
41
+ * @cssprop [--oscd-snackbar-success-container-color=#d8f8bd] - Success snackbar container color.
42
+ * @cssprop [--oscd-snackbar-success-text-color=var(--oscd-snackbar-text-color)] - Success text color.
43
+ * @cssprop [--oscd-snackbar-success-icon-color=#5ba300] - Success icon color.
44
+ *
45
+ * @cssprop [--oscd-snackbar-warning-container-color=#fff584] - Warning snackbar container color.
46
+ * @cssprop [--oscd-snackbar-warning-text-color=var(--oscd-snackbar-text-color)] - Warning text color.
47
+ * @cssprop [--oscd-snackbar-warning-icon-color=#f5a400] - Warning icon color.
48
+ *
49
+ * @cssprop [--oscd-snackbar-error-container-color=#ffd9df] - Error snackbar container color.
50
+ * @cssprop [--oscd-snackbar-error-text-color=var(--oscd-snackbar-text-color)] - Error text color.
51
+ * @cssprop [--oscd-snackbar-error-icon-color=#d52031] - Error icon color.
52
+ *
53
+ * @csspart snackbar - Snackbar surface.
54
+ * @csspart icon - Leading variant icon.
55
+ * @csspart message - Message text.
56
+ * @csspart action - Optional action button.
57
+ * @csspart action-icon - Icon inside the optional action button.
58
+ * @csspart action-label - Label inside the optional action button.
59
+ * @csspart close - Optional close button.
60
+ * @csspart elevation - Elevation shadow.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const id = snackbar.show({
65
+ * message: 'Validation failed',
66
+ * variant: 'error',
67
+ * autoDismiss: false,
68
+ * action: {
69
+ * label: 'See More',
70
+ * onClick: () => showValidationDetails(),
71
+ * },
72
+ * });
73
+ *
74
+ * snackbar.close(id); // closes a visible or queued notification
75
+ * snackbar.close(); // closes visible notifications and clears queued notifications
76
+ * ```
77
+ *
78
+ * @final
79
+ * @suppress {visibility}
80
+ */
81
+ export class OscdSnackbar extends ScopedElementsMixin(LitElement) {
82
+ constructor() {
83
+ super(...arguments);
84
+ this.defaultAutoDismissMs = 5000;
85
+ this.autoDismissMsPerWord = 500;
86
+ this.minAutoDismissMs = 5000;
87
+ this.maxAutoDismissMs = 15000;
88
+ this.maxVisible = 1;
89
+ this.mode = 'replace';
90
+ this.notifications = [];
91
+ this.queuedNotifications = [];
92
+ }
93
+ disconnectedCallback() {
94
+ super.disconnectedCallback();
95
+ OscdSnackbar.clearTimeouts(this.notifications);
96
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
97
+ }
98
+ /**
99
+ * Shows a notification and returns an id that can be passed to `close()`.
100
+ * In `stack` mode, notifications beyond `maxVisible` are queued until space
101
+ * becomes available. Auto-dismiss timing starts when a notification becomes
102
+ * visible, not while it is queued.
103
+ */
104
+ show(options) {
105
+ const notification = {
106
+ id: `snackbar-${++nextSnackbarId}`,
107
+ message: options.message,
108
+ variant: options.variant ?? 'info',
109
+ dismissible: options.dismissible ?? true,
110
+ action: options.action,
111
+ autoDismiss: options.autoDismiss,
112
+ };
113
+ const mode = options.mode ?? this.mode;
114
+ if (mode === 'replace') {
115
+ this.dismissNotifications(this.notifications);
116
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
117
+ this.queuedNotifications = [];
118
+ this.notifications = [
119
+ ...this.notifications.filter(existing => !existing.closing),
120
+ notification,
121
+ ];
122
+ this.scheduleAutoDismiss(notification);
123
+ return notification.id;
124
+ }
125
+ if (this.visibleNotifications.length < this.visibleLimit) {
126
+ this.notifications = [...this.notifications, notification];
127
+ this.scheduleAutoDismiss(notification);
128
+ }
129
+ else {
130
+ this.queuedNotifications = [...this.queuedNotifications, notification];
131
+ }
132
+ return notification.id;
133
+ }
134
+ /**
135
+ * Closes a visible or queued notification by id. Without an id, closes all
136
+ * visible notifications and clears all queued notifications.
137
+ */
138
+ close(id) {
139
+ if (id) {
140
+ const queuedNotificationCount = this.queuedNotifications.length;
141
+ this.queuedNotifications = this.queuedNotifications.filter(notification => notification.id !== id);
142
+ const notifications = this.notifications.filter(notification => notification.id === id);
143
+ if (notifications.length === 0 &&
144
+ this.queuedNotifications.length !== queuedNotificationCount) {
145
+ return;
146
+ }
147
+ if (notifications.length === 0) {
148
+ return;
149
+ }
150
+ this.dismissNotifications(notifications);
151
+ return;
152
+ }
153
+ const notifications = this.notifications;
154
+ OscdSnackbar.clearTimeouts(notifications);
155
+ OscdSnackbar.clearTimeouts(this.queuedNotifications);
156
+ this.queuedNotifications = [];
157
+ if (notifications.length === 0) {
158
+ return;
159
+ }
160
+ this.dismissNotifications(notifications);
161
+ }
162
+ dismissNotifications(notifications) {
163
+ OscdSnackbar.clearTimeouts(notifications);
164
+ this.notifications = this.notifications.map(notification => notifications.includes(notification)
165
+ ? { ...notification, closing: true }
166
+ : notification);
167
+ setTimeout(() => {
168
+ this.notifications = this.notifications.filter(notification => !notifications.some(closing => closing.id === notification.id));
169
+ this.promoteQueuedNotifications();
170
+ }, closeAnimationMs);
171
+ }
172
+ handleActionClick(notification) {
173
+ notification.action?.onClick();
174
+ this.close(notification.id);
175
+ }
176
+ handleCloseClick(notification) {
177
+ this.close(notification.id);
178
+ }
179
+ get visibleLimit() {
180
+ return Math.max(1, Math.floor(this.maxVisible));
181
+ }
182
+ get visibleNotifications() {
183
+ return this.notifications.filter(notification => !notification.closing);
184
+ }
185
+ static clearTimeouts(notifications) {
186
+ notifications.forEach(notification => {
187
+ clearTimeout(notification.timeoutId);
188
+ });
189
+ }
190
+ promoteQueuedNotifications() {
191
+ const availableSlots = this.visibleLimit - this.visibleNotifications.length;
192
+ if (availableSlots <= 0 || this.queuedNotifications.length === 0) {
193
+ return;
194
+ }
195
+ const promotedNotifications = this.queuedNotifications.slice(0, availableSlots);
196
+ this.queuedNotifications = this.queuedNotifications.slice(availableSlots);
197
+ this.notifications = [...this.notifications, ...promotedNotifications];
198
+ promotedNotifications.forEach(notification => {
199
+ this.scheduleAutoDismiss(notification);
200
+ });
201
+ }
202
+ scheduleAutoDismiss(notification) {
203
+ const timeoutMs = this.resolveAutoDismissMs(notification, notification.autoDismiss);
204
+ if (timeoutMs === undefined) {
205
+ return;
206
+ }
207
+ notification.timeoutId = setTimeout(() => {
208
+ this.close(notification.id);
209
+ }, timeoutMs);
210
+ }
211
+ resolveAutoDismissMs(notification, autoDismiss) {
212
+ if (autoDismiss === false) {
213
+ return undefined;
214
+ }
215
+ if (typeof autoDismiss === 'number') {
216
+ return autoDismiss > 0 ? autoDismiss : undefined;
217
+ }
218
+ if (autoDismiss === true) {
219
+ return this.calculateAutoDismissMs(notification.message);
220
+ }
221
+ if (notification.variant === 'error' || notification.action) {
222
+ return undefined;
223
+ }
224
+ return this.calculateAutoDismissMs(notification.message);
225
+ }
226
+ calculateAutoDismissMs(message) {
227
+ if (this.defaultAutoDismissMs <= 0) {
228
+ return undefined;
229
+ }
230
+ const wordCount = message.trim().split(/\s+/).filter(Boolean).length;
231
+ const timeoutMs = this.defaultAutoDismissMs + wordCount * this.autoDismissMsPerWord;
232
+ return Math.min(this.maxAutoDismissMs, Math.max(this.minAutoDismissMs, timeoutMs));
233
+ }
234
+ renderAction(notification) {
235
+ if (!notification.action) {
236
+ return nothing;
237
+ }
238
+ return html `<button
239
+ class="action"
240
+ part="action"
241
+ type="button"
242
+ @click=${() => this.handleActionClick(notification)}
243
+ >
244
+ <oscd-icon part="action-icon">arrow_forward</oscd-icon>
245
+ <span part="action-label">${notification.action.label}</span>
246
+ </button>`;
247
+ }
248
+ renderCloseButton(notification) {
249
+ if (!notification.dismissible) {
250
+ return nothing;
251
+ }
252
+ return html `<oscd-icon-button
253
+ class="close"
254
+ part="close"
255
+ aria-label="Close"
256
+ @click=${() => this.handleCloseClick(notification)}
257
+ >
258
+ <oscd-icon>close</oscd-icon>
259
+ </oscd-icon-button>`;
260
+ }
261
+ renderNotification(notification) {
262
+ return html `<div
263
+ class=${classMap({
264
+ snackbar: true,
265
+ [notification.variant]: true,
266
+ closing: !!notification.closing,
267
+ })}
268
+ part="snackbar"
269
+ role=${notification.variant === 'error' ? 'alert' : 'status'}
270
+ >
271
+ <oscd-icon class="variant-icon" part="icon"
272
+ >${iconByVariant[notification.variant]}</oscd-icon
273
+ >
274
+ <span class="message" part="message">${notification.message}</span>
275
+ ${this.renderAction(notification)} ${this.renderCloseButton(notification)}
276
+ <oscd-elevation part="elevation"></oscd-elevation>
277
+ </div>`;
278
+ }
279
+ render() {
280
+ return html `${[...this.notifications]
281
+ .reverse()
282
+ .map(notification => this.renderNotification(notification))}`;
283
+ }
284
+ }
285
+ OscdSnackbar.scopedElements = {
286
+ 'oscd-elevation': OscdElevation,
287
+ 'oscd-icon': OscdIcon,
288
+ 'oscd-icon-button': OscdIconButton,
289
+ };
290
+ OscdSnackbar.styles = css `
291
+ :host {
292
+ box-sizing: border-box;
293
+ display: flex;
294
+ position: fixed;
295
+ bottom: var(--oscd-snackbar-bottom, 16px);
296
+ left: 50%;
297
+ flex-direction: column-reverse;
298
+ align-items: center;
299
+ gap: var(--oscd-snackbar-gap, 8px);
300
+ width: max-content;
301
+ max-width: var(--oscd-snackbar-max-width, 80vw);
302
+ transform: translateX(-50%);
303
+ z-index: var(--oscd-snackbar-z-index, 9999);
304
+ pointer-events: none;
305
+ }
306
+
307
+ .snackbar {
308
+ box-sizing: border-box;
309
+ display: grid;
310
+ position: relative;
311
+ flex: 0 0 auto;
312
+ grid-template-columns: auto minmax(0, 1fr) auto auto;
313
+ align-items: center;
314
+ width: max-content;
315
+ min-width: var(--oscd-snackbar-min-width, min(360px, 80vw));
316
+ max-width: 100%;
317
+ min-height: var(--oscd-snackbar-min-height, 48px);
318
+ padding: var(--oscd-snackbar-container-padding, 12px 16px);
319
+ --md-elevation-level: var(--oscd-snackbar-elevation-level, 3);
320
+ color: var(
321
+ --oscd-snackbar-text-color,
322
+ var(--md-sys-color-on-surface, #233042)
323
+ );
324
+ font-family: var(
325
+ --oscd-snackbar-font-family,
326
+ var(--md-sys-typescale-body-large-font)
327
+ );
328
+ font-size: var(
329
+ --oscd-snackbar-font-size,
330
+ var(--md-sys-typescale-body-large-size)
331
+ );
332
+ line-height: var(
333
+ --oscd-snackbar-line-height,
334
+ var(--md-sys-typescale-body-large-line-height)
335
+ );
336
+ pointer-events: auto;
337
+ animation: snackbar-slide-in var(--oscd-snackbar-enter-duration, 160ms)
338
+ ease-out;
339
+ }
340
+
341
+ .snackbar.closing {
342
+ pointer-events: none;
343
+ animation: snackbar-fade-out var(--oscd-snackbar-exit-duration, 160ms)
344
+ ease-in forwards;
345
+ }
346
+
347
+ .snackbar.info {
348
+ background: var(
349
+ --oscd-snackbar-info-container-color,
350
+ var(--md-sys-color-secondary-container)
351
+ );
352
+ color: var(
353
+ --oscd-snackbar-info-text-color,
354
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
355
+ );
356
+ }
357
+
358
+ .snackbar.success {
359
+ background: var(
360
+ --oscd-snackbar-success-container-color,
361
+ var(--md-sys-color-tertiary-container, #d8f8bd)
362
+ );
363
+ color: var(
364
+ --oscd-snackbar-success-text-color,
365
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
366
+ );
367
+ }
368
+
369
+ .snackbar.warning {
370
+ background: var(
371
+ --oscd-snackbar-warning-container-color,
372
+ var(--md-sys-color-error-container, #fff584)
373
+ );
374
+ color: var(
375
+ --oscd-snackbar-warning-text-color,
376
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
377
+ );
378
+ }
379
+
380
+ .snackbar.error {
381
+ background: var(
382
+ --oscd-snackbar-error-container-color,
383
+ var(--md-sys-color-error-container, #ffd9df)
384
+ );
385
+ color: var(
386
+ --oscd-snackbar-error-text-color,
387
+ var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))
388
+ );
389
+ }
390
+
391
+ .variant-icon {
392
+ width: 24px;
393
+ height: 24px;
394
+ margin-inline-end: 16px;
395
+ font-size: 24px;
396
+ color: var(
397
+ --oscd-snackbar-info-icon-color,
398
+ var(--md-sys-color-on-secondary-container)
399
+ );
400
+ }
401
+
402
+ .success .variant-icon {
403
+ color: var(
404
+ --oscd-snackbar-success-icon-color,
405
+ var(--md-sys-color-on-tertiary-container, #5ba300)
406
+ );
407
+ }
408
+
409
+ .warning .variant-icon {
410
+ color: var(
411
+ --oscd-snackbar-warning-icon-color,
412
+ var(--md-sys-color-on-error-container, #f5a400)
413
+ );
414
+ }
415
+
416
+ .error .variant-icon {
417
+ color: var(
418
+ --oscd-snackbar-error-icon-color,
419
+ var(--md-sys-color-error, #d52031)
420
+ );
421
+ }
422
+
423
+ .message {
424
+ display: -webkit-box;
425
+ min-width: 0;
426
+ overflow: hidden;
427
+ text-overflow: ellipsis;
428
+ overflow-wrap: anywhere;
429
+ white-space: normal;
430
+ -webkit-box-orient: vertical;
431
+ -webkit-line-clamp: var(--oscd-snackbar-message-line-clamp, 3);
432
+ }
433
+
434
+ .action {
435
+ display: inline-flex;
436
+ align-items: center;
437
+ gap: 8px;
438
+ min-width: max-content;
439
+ margin-inline-start: 16px;
440
+ padding: 0;
441
+ border: 0;
442
+ background: none;
443
+ color: inherit;
444
+ cursor: pointer;
445
+ font: inherit;
446
+ font-size: var(--md-sys-typescale-label-large-size);
447
+ font-weight: var(--md-sys-typescale-label-large-weight);
448
+ line-height: var(--md-sys-typescale-label-large-line-height);
449
+ }
450
+
451
+ .action oscd-icon {
452
+ width: 18px;
453
+ height: 18px;
454
+ font-size: 18px;
455
+ }
456
+
457
+ .close {
458
+ margin-inline-start: 16px;
459
+ color: inherit;
460
+ }
461
+
462
+ @keyframes snackbar-slide-in {
463
+ from {
464
+ opacity: 0;
465
+ transform: translateY(16px);
466
+ }
467
+
468
+ to {
469
+ opacity: 1;
470
+ transform: translateY(0);
471
+ }
472
+ }
473
+
474
+ @keyframes snackbar-fade-out {
475
+ from {
476
+ opacity: 1;
477
+ }
478
+
479
+ to {
480
+ opacity: 0;
481
+ }
482
+ }
483
+ `;
484
+ __decorate([
485
+ property({ type: Number, attribute: 'default-auto-dismiss-ms' })
486
+ ], OscdSnackbar.prototype, "defaultAutoDismissMs", void 0);
487
+ __decorate([
488
+ property({ type: Number, attribute: 'auto-dismiss-ms-per-word' })
489
+ ], OscdSnackbar.prototype, "autoDismissMsPerWord", void 0);
490
+ __decorate([
491
+ property({ type: Number, attribute: 'min-auto-dismiss-ms' })
492
+ ], OscdSnackbar.prototype, "minAutoDismissMs", void 0);
493
+ __decorate([
494
+ property({ type: Number, attribute: 'max-auto-dismiss-ms' })
495
+ ], OscdSnackbar.prototype, "maxAutoDismissMs", void 0);
496
+ __decorate([
497
+ property({ type: Number, attribute: 'max-visible' })
498
+ ], OscdSnackbar.prototype, "maxVisible", void 0);
499
+ __decorate([
500
+ property({ type: String })
501
+ ], OscdSnackbar.prototype, "mode", void 0);
502
+ __decorate([
503
+ state()
504
+ ], OscdSnackbar.prototype, "notifications", void 0);
505
+ //# sourceMappingURL=OscdSnackbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OscdSnackbar.js","sourceRoot":"","sources":["../../snackbar/OscdSnackbar.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CA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AAGxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC;sDACpC;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;gDACtC;AAGf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CACI;AAGvB;IADP,KAAK,EAAE;mDAC2C","sourcesContent":["import { css, html, LitElement, nothing, TemplateResult } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js';\n\nimport { OscdElevation } from '../elevation/OscdElevation.js';\nimport { OscdIcon } from '../icon/OscdIcon.js';\nimport { OscdIconButton } from '../iconbutton/OscdIconButton.js';\n\nexport type SnackbarVariant = 'info' | 'success' | 'warning' | 'error';\n\nexport type SnackbarMode = 'replace' | 'stack';\n\nexport type SnackbarAutoDismiss = boolean | number;\n\nexport type SnackbarAction = {\n label: string;\n onClick: () => void;\n};\n\nexport type SnackbarShowOptions = {\n message: string;\n variant?: SnackbarVariant;\n autoDismiss?: SnackbarAutoDismiss;\n dismissible?: boolean;\n action?: SnackbarAction;\n mode?: SnackbarMode;\n};\n\ntype SnackbarNotification = Required<\n Pick<SnackbarShowOptions, 'message' | 'variant' | 'dismissible'>\n> & {\n id: string;\n action?: SnackbarAction;\n autoDismiss?: SnackbarAutoDismiss;\n closing?: boolean;\n timeoutId?: ReturnType<typeof setTimeout>;\n};\n\nconst closeAnimationMs = 160;\n\nconst iconByVariant: Record<SnackbarVariant, string> = {\n info: 'info',\n success: 'check_circle',\n warning: 'warning',\n error: 'cancel',\n};\n\nlet nextSnackbarId = 0;\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'oscd-snackbar': OscdSnackbar;\n }\n}\n\n/**\n * @tagname oscd-snackbar\n * @summary Snackbar banner for transient status, warning, and error messages.\n *\n * @cssprop [--oscd-snackbar-z-index=9999] - Stacking order for the fixed snackbar stack.\n * @cssprop [--oscd-snackbar-bottom=16px] - Distance from the bottom viewport edge.\n * @cssprop [--oscd-snackbar-gap=8px] - Gap between stacked snackbars.\n * @cssprop [--oscd-snackbar-max-width=80vw] - Maximum snackbar stack width.\n * @cssprop [--oscd-snackbar-min-width=min(360px, 80vw)] - Minimum snackbar item width.\n * @cssprop [--oscd-snackbar-min-height=48px] - Minimum snackbar item height.\n * @cssprop [--oscd-snackbar-container-padding=12px 16px] - Snackbar item padding.\n * @cssprop [--oscd-snackbar-elevation-level=3] - Snackbar elevation level.\n * @cssprop [--oscd-snackbar-enter-duration=160ms] - Show animation duration.\n * @cssprop [--oscd-snackbar-exit-duration=160ms] - Hide animation duration.\n * @cssprop [--oscd-snackbar-text-color=#233042] - Snackbar text color.\n * @cssprop [--oscd-snackbar-font-family=var(--md-sys-typescale-body-large-font)] - Snackbar font family.\n * @cssprop [--oscd-snackbar-font-size=var(--md-sys-typescale-body-large-size)] - Snackbar font size.\n * @cssprop [--oscd-snackbar-line-height=var(--md-sys-typescale-body-large-line-height)] - Snackbar line height.\n * @cssprop [--oscd-snackbar-message-line-clamp=3] - Maximum visible message lines before truncation.\n *\n * @cssprop [--oscd-snackbar-info-container-color=var(--md-sys-color-secondary-container)] - Info snackbar container color.\n * @cssprop [--oscd-snackbar-info-text-color=var(--oscd-snackbar-text-color)] - Info text color.\n * @cssprop [--oscd-snackbar-info-icon-color=var(--md-sys-color-on-secondary-container)] - Info icon color.\n *\n * @cssprop [--oscd-snackbar-success-container-color=#d8f8bd] - Success snackbar container color.\n * @cssprop [--oscd-snackbar-success-text-color=var(--oscd-snackbar-text-color)] - Success text color.\n * @cssprop [--oscd-snackbar-success-icon-color=#5ba300] - Success icon color.\n *\n * @cssprop [--oscd-snackbar-warning-container-color=#fff584] - Warning snackbar container color.\n * @cssprop [--oscd-snackbar-warning-text-color=var(--oscd-snackbar-text-color)] - Warning text color.\n * @cssprop [--oscd-snackbar-warning-icon-color=#f5a400] - Warning icon color.\n *\n * @cssprop [--oscd-snackbar-error-container-color=#ffd9df] - Error snackbar container color.\n * @cssprop [--oscd-snackbar-error-text-color=var(--oscd-snackbar-text-color)] - Error text color.\n * @cssprop [--oscd-snackbar-error-icon-color=#d52031] - Error icon color.\n *\n * @csspart snackbar - Snackbar surface.\n * @csspart icon - Leading variant icon.\n * @csspart message - Message text.\n * @csspart action - Optional action button.\n * @csspart action-icon - Icon inside the optional action button.\n * @csspart action-label - Label inside the optional action button.\n * @csspart close - Optional close button.\n * @csspart elevation - Elevation shadow.\n *\n * @example\n * ```ts\n * const id = snackbar.show({\n * message: 'Validation failed',\n * variant: 'error',\n * autoDismiss: false,\n * action: {\n * label: 'See More',\n * onClick: () => showValidationDetails(),\n * },\n * });\n *\n * snackbar.close(id); // closes a visible or queued notification\n * snackbar.close(); // closes visible notifications and clears queued notifications\n * ```\n *\n * @final\n * @suppress {visibility}\n */\nexport class OscdSnackbar extends ScopedElementsMixin(LitElement) {\n static scopedElements = {\n 'oscd-elevation': OscdElevation,\n 'oscd-icon': OscdIcon,\n 'oscd-icon-button': OscdIconButton,\n };\n\n @property({ type: Number, attribute: 'default-auto-dismiss-ms' })\n defaultAutoDismissMs = 5000;\n\n @property({ type: Number, attribute: 'auto-dismiss-ms-per-word' })\n autoDismissMsPerWord = 500;\n\n @property({ type: Number, attribute: 'min-auto-dismiss-ms' })\n minAutoDismissMs = 5000;\n\n @property({ type: Number, attribute: 'max-auto-dismiss-ms' })\n maxAutoDismissMs = 15000;\n\n @property({ type: Number, attribute: 'max-visible' })\n maxVisible = 1;\n\n @property({ type: String })\n mode: SnackbarMode = 'replace';\n\n @state()\n private notifications: SnackbarNotification[] = [];\n\n private queuedNotifications: SnackbarNotification[] = [];\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n OscdSnackbar.clearTimeouts(this.notifications);\n OscdSnackbar.clearTimeouts(this.queuedNotifications);\n }\n\n /**\n * Shows a notification and returns an id that can be passed to `close()`.\n * In `stack` mode, notifications beyond `maxVisible` are queued until space\n * becomes available. Auto-dismiss timing starts when a notification becomes\n * visible, not while it is queued.\n */\n show(options: SnackbarShowOptions): string {\n const notification: SnackbarNotification = {\n id: `snackbar-${++nextSnackbarId}`,\n message: options.message,\n variant: options.variant ?? 'info',\n dismissible: options.dismissible ?? true,\n action: options.action,\n autoDismiss: options.autoDismiss,\n };\n const mode = options.mode ?? this.mode;\n\n if (mode === 'replace') {\n this.dismissNotifications(this.notifications);\n OscdSnackbar.clearTimeouts(this.queuedNotifications);\n this.queuedNotifications = [];\n this.notifications = [\n ...this.notifications.filter(existing => !existing.closing),\n notification,\n ];\n this.scheduleAutoDismiss(notification);\n\n return notification.id;\n }\n\n if (this.visibleNotifications.length < this.visibleLimit) {\n this.notifications = [...this.notifications, notification];\n this.scheduleAutoDismiss(notification);\n } else {\n this.queuedNotifications = [...this.queuedNotifications, notification];\n }\n\n return notification.id;\n }\n\n /**\n * Closes a visible or queued notification by id. Without an id, closes all\n * visible notifications and clears all queued notifications.\n */\n close(id?: string): void {\n if (id) {\n const queuedNotificationCount = this.queuedNotifications.length;\n this.queuedNotifications = this.queuedNotifications.filter(\n notification => notification.id !== id,\n );\n const notifications = this.notifications.filter(\n notification => notification.id === id,\n );\n\n if (\n notifications.length === 0 &&\n this.queuedNotifications.length !== queuedNotificationCount\n ) {\n return;\n }\n\n if (notifications.length === 0) {\n return;\n }\n\n this.dismissNotifications(notifications);\n return;\n }\n\n const notifications = this.notifications;\n OscdSnackbar.clearTimeouts(notifications);\n OscdSnackbar.clearTimeouts(this.queuedNotifications);\n this.queuedNotifications = [];\n\n if (notifications.length === 0) {\n return;\n }\n\n this.dismissNotifications(notifications);\n }\n\n private dismissNotifications(notifications: SnackbarNotification[]): void {\n OscdSnackbar.clearTimeouts(notifications);\n this.notifications = this.notifications.map(notification =>\n notifications.includes(notification)\n ? { ...notification, closing: true }\n : notification,\n );\n\n setTimeout(() => {\n this.notifications = this.notifications.filter(\n notification =>\n !notifications.some(closing => closing.id === notification.id),\n );\n this.promoteQueuedNotifications();\n }, closeAnimationMs);\n }\n\n private handleActionClick(notification: SnackbarNotification): void {\n notification.action?.onClick();\n this.close(notification.id);\n }\n\n private handleCloseClick(notification: SnackbarNotification): void {\n this.close(notification.id);\n }\n\n private get visibleLimit(): number {\n return Math.max(1, Math.floor(this.maxVisible));\n }\n\n private get visibleNotifications(): SnackbarNotification[] {\n return this.notifications.filter(notification => !notification.closing);\n }\n\n private static clearTimeouts(notifications: SnackbarNotification[]): void {\n notifications.forEach(notification => {\n clearTimeout(notification.timeoutId);\n });\n }\n\n private promoteQueuedNotifications(): void {\n const availableSlots = this.visibleLimit - this.visibleNotifications.length;\n\n if (availableSlots <= 0 || this.queuedNotifications.length === 0) {\n return;\n }\n\n const promotedNotifications = this.queuedNotifications.slice(\n 0,\n availableSlots,\n );\n this.queuedNotifications = this.queuedNotifications.slice(availableSlots);\n this.notifications = [...this.notifications, ...promotedNotifications];\n promotedNotifications.forEach(notification => {\n this.scheduleAutoDismiss(notification);\n });\n }\n\n private scheduleAutoDismiss(notification: SnackbarNotification): void {\n const timeoutMs = this.resolveAutoDismissMs(\n notification,\n notification.autoDismiss,\n );\n\n if (timeoutMs === undefined) {\n return;\n }\n\n notification.timeoutId = setTimeout(() => {\n this.close(notification.id);\n }, timeoutMs);\n }\n\n private resolveAutoDismissMs(\n notification: SnackbarNotification,\n autoDismiss: SnackbarAutoDismiss | undefined,\n ): number | undefined {\n if (autoDismiss === false) {\n return undefined;\n }\n\n if (typeof autoDismiss === 'number') {\n return autoDismiss > 0 ? autoDismiss : undefined;\n }\n\n if (autoDismiss === true) {\n return this.calculateAutoDismissMs(notification.message);\n }\n\n if (notification.variant === 'error' || notification.action) {\n return undefined;\n }\n\n return this.calculateAutoDismissMs(notification.message);\n }\n\n private calculateAutoDismissMs(message: string): number | undefined {\n if (this.defaultAutoDismissMs <= 0) {\n return undefined;\n }\n\n const wordCount = message.trim().split(/\\s+/).filter(Boolean).length;\n const timeoutMs =\n this.defaultAutoDismissMs + wordCount * this.autoDismissMsPerWord;\n\n return Math.min(\n this.maxAutoDismissMs,\n Math.max(this.minAutoDismissMs, timeoutMs),\n );\n }\n\n private renderAction(\n notification: SnackbarNotification,\n ): TemplateResult | typeof nothing {\n if (!notification.action) {\n return nothing;\n }\n\n return html`<button\n class=\"action\"\n part=\"action\"\n type=\"button\"\n @click=${() => this.handleActionClick(notification)}\n >\n <oscd-icon part=\"action-icon\">arrow_forward</oscd-icon>\n <span part=\"action-label\">${notification.action.label}</span>\n </button>`;\n }\n\n private renderCloseButton(\n notification: SnackbarNotification,\n ): TemplateResult | typeof nothing {\n if (!notification.dismissible) {\n return nothing;\n }\n\n return html`<oscd-icon-button\n class=\"close\"\n part=\"close\"\n aria-label=\"Close\"\n @click=${() => this.handleCloseClick(notification)}\n >\n <oscd-icon>close</oscd-icon>\n </oscd-icon-button>`;\n }\n\n private renderNotification(\n notification: SnackbarNotification,\n ): TemplateResult {\n return html`<div\n class=${classMap({\n snackbar: true,\n [notification.variant]: true,\n closing: !!notification.closing,\n })}\n part=\"snackbar\"\n role=${notification.variant === 'error' ? 'alert' : 'status'}\n >\n <oscd-icon class=\"variant-icon\" part=\"icon\"\n >${iconByVariant[notification.variant]}</oscd-icon\n >\n <span class=\"message\" part=\"message\">${notification.message}</span>\n ${this.renderAction(notification)} ${this.renderCloseButton(notification)}\n <oscd-elevation part=\"elevation\"></oscd-elevation>\n </div>`;\n }\n\n override render(): TemplateResult {\n return html`${[...this.notifications]\n .reverse()\n .map(notification => this.renderNotification(notification))}`;\n }\n\n static override styles = css`\n :host {\n box-sizing: border-box;\n display: flex;\n position: fixed;\n bottom: var(--oscd-snackbar-bottom, 16px);\n left: 50%;\n flex-direction: column-reverse;\n align-items: center;\n gap: var(--oscd-snackbar-gap, 8px);\n width: max-content;\n max-width: var(--oscd-snackbar-max-width, 80vw);\n transform: translateX(-50%);\n z-index: var(--oscd-snackbar-z-index, 9999);\n pointer-events: none;\n }\n\n .snackbar {\n box-sizing: border-box;\n display: grid;\n position: relative;\n flex: 0 0 auto;\n grid-template-columns: auto minmax(0, 1fr) auto auto;\n align-items: center;\n width: max-content;\n min-width: var(--oscd-snackbar-min-width, min(360px, 80vw));\n max-width: 100%;\n min-height: var(--oscd-snackbar-min-height, 48px);\n padding: var(--oscd-snackbar-container-padding, 12px 16px);\n --md-elevation-level: var(--oscd-snackbar-elevation-level, 3);\n color: var(\n --oscd-snackbar-text-color,\n var(--md-sys-color-on-surface, #233042)\n );\n font-family: var(\n --oscd-snackbar-font-family,\n var(--md-sys-typescale-body-large-font)\n );\n font-size: var(\n --oscd-snackbar-font-size,\n var(--md-sys-typescale-body-large-size)\n );\n line-height: var(\n --oscd-snackbar-line-height,\n var(--md-sys-typescale-body-large-line-height)\n );\n pointer-events: auto;\n animation: snackbar-slide-in var(--oscd-snackbar-enter-duration, 160ms)\n ease-out;\n }\n\n .snackbar.closing {\n pointer-events: none;\n animation: snackbar-fade-out var(--oscd-snackbar-exit-duration, 160ms)\n ease-in forwards;\n }\n\n .snackbar.info {\n background: var(\n --oscd-snackbar-info-container-color,\n var(--md-sys-color-secondary-container)\n );\n color: var(\n --oscd-snackbar-info-text-color,\n var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))\n );\n }\n\n .snackbar.success {\n background: var(\n --oscd-snackbar-success-container-color,\n var(--md-sys-color-tertiary-container, #d8f8bd)\n );\n color: var(\n --oscd-snackbar-success-text-color,\n var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))\n );\n }\n\n .snackbar.warning {\n background: var(\n --oscd-snackbar-warning-container-color,\n var(--md-sys-color-error-container, #fff584)\n );\n color: var(\n --oscd-snackbar-warning-text-color,\n var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))\n );\n }\n\n .snackbar.error {\n background: var(\n --oscd-snackbar-error-container-color,\n var(--md-sys-color-error-container, #ffd9df)\n );\n color: var(\n --oscd-snackbar-error-text-color,\n var(--oscd-snackbar-text-color, var(--md-sys-color-on-surface, #233042))\n );\n }\n\n .variant-icon {\n width: 24px;\n height: 24px;\n margin-inline-end: 16px;\n font-size: 24px;\n color: var(\n --oscd-snackbar-info-icon-color,\n var(--md-sys-color-on-secondary-container)\n );\n }\n\n .success .variant-icon {\n color: var(\n --oscd-snackbar-success-icon-color,\n var(--md-sys-color-on-tertiary-container, #5ba300)\n );\n }\n\n .warning .variant-icon {\n color: var(\n --oscd-snackbar-warning-icon-color,\n var(--md-sys-color-on-error-container, #f5a400)\n );\n }\n\n .error .variant-icon {\n color: var(\n --oscd-snackbar-error-icon-color,\n var(--md-sys-color-error, #d52031)\n );\n }\n\n .message {\n display: -webkit-box;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n overflow-wrap: anywhere;\n white-space: normal;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: var(--oscd-snackbar-message-line-clamp, 3);\n }\n\n .action {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n min-width: max-content;\n margin-inline-start: 16px;\n padding: 0;\n border: 0;\n background: none;\n color: inherit;\n cursor: pointer;\n font: inherit;\n font-size: var(--md-sys-typescale-label-large-size);\n font-weight: var(--md-sys-typescale-label-large-weight);\n line-height: var(--md-sys-typescale-label-large-line-height);\n }\n\n .action oscd-icon {\n width: 18px;\n height: 18px;\n font-size: 18px;\n }\n\n .close {\n margin-inline-start: 16px;\n color: inherit;\n }\n\n @keyframes snackbar-slide-in {\n from {\n opacity: 0;\n transform: translateY(16px);\n }\n\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n @keyframes snackbar-fade-out {\n from {\n opacity: 1;\n }\n\n to {\n opacity: 0;\n }\n }\n `;\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};