@ckui/core 0.1.0-next.0 → 0.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,883 @@
1
+ import * as i0 from "@angular/core";
2
+ import { ApplicationRef, ChangeDetectionStrategy, Component, DestroyRef, ElementRef, EnvironmentInjector, Injectable, InjectionToken, Injector, PLATFORM_ID, ViewEncapsulation, afterNextRender, computed, createComponent, effect, inject, input, makeEnvironmentProviders, signal, untracked } from "@angular/core";
3
+ import { CK_CONFIG, CK_LABELS, CK_SIZES } from "@ckui/core";
4
+ import { DOCUMENT, isPlatformBrowser } from "@angular/common";
5
+ import { CkAnnouncer, CkIcon, CkMedia } from "@ckui/core/internal";
6
+ import { CkButton } from "@ckui/core/button";
7
+ const CK_TOAST_CONFIG = new InjectionToken("CK_TOAST_CONFIG", {
8
+ providedIn: "root",
9
+ factory: () => ({})
10
+ });
11
+ function provideCkToast(config = {}) {
12
+ const { position, align, max, size } = config;
13
+ if (position !== void 0 && position !== "top" && position !== "bottom") throw new TypeError(`provideCkToast: position must be "top" or "bottom", got "${position}".`);
14
+ if (align !== void 0 && align !== "center" && align !== "end") throw new TypeError(`provideCkToast: align must be "center" or "end", got "${align}".`);
15
+ if (max !== void 0 && (typeof max !== "number" || !Number.isInteger(max) || max < 1)) throw new TypeError(`provideCkToast: max must be a whole number of at least 1, got ${String(max)}.`);
16
+ if (size !== void 0 && !CK_SIZES.includes(size)) throw new TypeError(`provideCkToast: size must be one of ${CK_SIZES.join(", ")}, got "${size}".`);
17
+ return makeEnvironmentProviders([{
18
+ provide: CK_TOAST_CONFIG,
19
+ useValue: {
20
+ position,
21
+ align,
22
+ max,
23
+ size
24
+ }
25
+ }]);
26
+ }
27
+ var CkToastRef = class {
28
+ dismissed;
29
+ controls;
30
+ constructor(controls) {
31
+ this.controls = controls;
32
+ this.dismissed = controls.dismissed;
33
+ }
34
+ dismiss() {
35
+ this.controls.dismiss();
36
+ }
37
+ update(options) {
38
+ this.controls.update(options);
39
+ }
40
+ };
41
+ const DEFAULT_DURATION = 5e3;
42
+ const MIN_RESUME = 1e3;
43
+ const TONES = [
44
+ "neutral",
45
+ "success",
46
+ "warning",
47
+ "danger"
48
+ ];
49
+ var ToastEntry = class {
50
+ key;
51
+ id;
52
+ content;
53
+ phase = signal("queued", ...ngDevMode ? [{ debugName: "phase" }] : /* istanbul ignore next */ []);
54
+ swiped = signal(false, ...ngDevMode ? [{ debugName: "swiped" }] : /* istanbul ignore next */ []);
55
+ element = null;
56
+ ref;
57
+ settle = () => void 0;
58
+ timer;
59
+ remaining = null;
60
+ startedAt = 0;
61
+ pauses = /* @__PURE__ */ new Set();
62
+ announced = "";
63
+ constructor(key, id, content) {
64
+ this.key = key;
65
+ this.id = id;
66
+ this.content = signal(content, ...ngDevMode ? [{ debugName: "content" }] : /* istanbul ignore next */ []);
67
+ }
68
+ };
69
+ function present(value) {
70
+ return typeof value === "string" && value.trim() !== "";
71
+ }
72
+ function normaliseAction(action) {
73
+ const candidate = action;
74
+ return candidate && present(candidate.label) && typeof candidate.run === "function" ? {
75
+ label: candidate.label,
76
+ run: candidate.run
77
+ } : void 0;
78
+ }
79
+ function normalise(options) {
80
+ const source = typeof options === "object" && options !== null ? options : {};
81
+ const title = present(source["title"]) ? source["title"] : void 0;
82
+ const message = typeof source["message"] === "string" ? source["message"] : "";
83
+ if (message.trim() === "" && title === void 0) return null;
84
+ const duration = source["duration"];
85
+ return {
86
+ message,
87
+ title,
88
+ tone: TONES.includes(source["tone"]) ? source["tone"] : "neutral",
89
+ action: normaliseAction(source["action"]),
90
+ duration: typeof duration === "number" || duration === null ? duration : void 0
91
+ };
92
+ }
93
+ function effectiveDuration(content) {
94
+ const { duration } = content;
95
+ if (duration === null) return null;
96
+ if (typeof duration === "number") return Number.isFinite(duration) && duration > 0 && duration <= 2147483647 ? duration : null;
97
+ return content.action !== void 0 || content.tone === "danger" ? null : DEFAULT_DURATION;
98
+ }
99
+ function announcementOf(content) {
100
+ const { title, message } = content;
101
+ if (title === void 0) return message;
102
+ if (message.trim() === "") return title;
103
+ return /[.!?:]$/.test(title.trim()) ? `${title} ${message}` : `${title}. ${message}`;
104
+ }
105
+ var CkToastStore = class CkToastStore {
106
+ document = inject(DOCUMENT);
107
+ announcer = inject(CkAnnouncer);
108
+ config = inject(CK_TOAST_CONFIG);
109
+ ckConfig = inject(CK_CONFIG);
110
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
111
+ entries = signal([], ...ngDevMode ? [{ debugName: "entries" }] : /* istanbul ignore next */ []);
112
+ position = this.config.position ?? "bottom";
113
+ max = this.config.max ?? 3;
114
+ alignOverride = this.config.align;
115
+ size = computed(() => this.config.size ?? this.ckConfig.size, ...ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []);
116
+ beforeLeave = null;
117
+ nextKey = 0;
118
+ listening = false;
119
+ destroyed = false;
120
+ show(options) {
121
+ const content = normalise(options);
122
+ if (!this.isBrowser || this.destroyed || content === null) {
123
+ if (content === null && typeof ngDevMode !== "undefined" && ngDevMode) console.warn("[ckui] CkToast.show needs a message or a title, nothing was shown.");
124
+ return this.settledRef();
125
+ }
126
+ const id = present(options.id) ? options.id : void 0;
127
+ const existing = id === void 0 ? void 0 : this.entries().find((entry) => entry.id === id && entry.phase() !== "leaving");
128
+ if (existing) {
129
+ this.replace(existing, content);
130
+ return existing.ref;
131
+ }
132
+ this.listen();
133
+ const entry = new ToastEntry(this.nextKey++, id, content);
134
+ this.bind(entry);
135
+ this.entries.update((entries) => [...entries, entry]);
136
+ this.promote();
137
+ return entry.ref;
138
+ }
139
+ dismissAll() {
140
+ const all = [...this.entries()];
141
+ const queued = all.filter((entry) => entry.phase() === "queued");
142
+ for (const entry of queued) {
143
+ this.clearTimer(entry);
144
+ entry.settle("programmatic");
145
+ }
146
+ if (queued.length > 0) this.entries.update((entries) => entries.filter((entry) => !queued.includes(entry)));
147
+ for (const entry of all) if (!queued.includes(entry)) this.dismiss(entry, "programmatic");
148
+ }
149
+ dismiss(entry, reason, swiped = false) {
150
+ const phase = entry.phase();
151
+ if (phase === "leaving") return;
152
+ this.clearTimer(entry);
153
+ entry.settle(reason);
154
+ if (phase === "queued") {
155
+ this.remove(entry);
156
+ return;
157
+ }
158
+ this.beforeLeave?.(entry);
159
+ entry.swiped.set(swiped);
160
+ entry.phase.set("leaving");
161
+ this.promote();
162
+ }
163
+ remove(entry) {
164
+ this.clearTimer(entry);
165
+ if (this.entries().includes(entry)) this.entries.update((entries) => entries.filter((other) => other !== entry));
166
+ }
167
+ pause(entry, reason) {
168
+ entry.pauses.add(reason);
169
+ if (entry.timer !== void 0 && entry.remaining !== null) {
170
+ clearTimeout(entry.timer);
171
+ entry.timer = void 0;
172
+ entry.remaining = Math.max(entry.remaining - (Date.now() - entry.startedAt), MIN_RESUME);
173
+ }
174
+ }
175
+ resume(entry, reason) {
176
+ if (entry.pauses.delete(reason)) this.arm(entry);
177
+ }
178
+ teardown() {
179
+ this.destroyed = true;
180
+ this.beforeLeave = null;
181
+ for (const entry of this.entries()) {
182
+ this.clearTimer(entry);
183
+ entry.settle("programmatic");
184
+ entry.phase.set("leaving");
185
+ }
186
+ this.entries.set([]);
187
+ if (this.listening) {
188
+ this.listening = false;
189
+ this.document.removeEventListener("visibilitychange", this.onVisibilityChange);
190
+ }
191
+ }
192
+ bind(entry) {
193
+ let resolve = () => void 0;
194
+ const ref = new CkToastRef({
195
+ dismissed: new Promise((done) => resolve = done),
196
+ dismiss: () => {
197
+ if (entry.ref === ref) this.dismiss(entry, "programmatic");
198
+ },
199
+ update: (partial) => {
200
+ if (entry.ref === ref) this.update(entry, partial);
201
+ }
202
+ });
203
+ entry.ref = ref;
204
+ entry.settle = resolve;
205
+ }
206
+ settledRef() {
207
+ return new CkToastRef({
208
+ dismissed: Promise.resolve("programmatic"),
209
+ dismiss: () => void 0,
210
+ update: () => void 0
211
+ });
212
+ }
213
+ replace(entry, content) {
214
+ entry.settle("replaced");
215
+ this.bind(entry);
216
+ this.apply(entry, content);
217
+ }
218
+ update(entry, partial) {
219
+ if (entry.phase() === "leaving" || typeof partial !== "object" || partial === null) return;
220
+ const current = entry.content();
221
+ const has = (key) => Object.hasOwn(partial, key) && !(key === "message" && partial.message === void 0);
222
+ const merged = normalise({
223
+ message: has("message") ? partial.message : current.message,
224
+ title: has("title") ? partial.title : current.title,
225
+ tone: has("tone") ? partial.tone : current.tone,
226
+ action: has("action") ? partial.action : current.action,
227
+ duration: has("duration") ? partial.duration : current.duration
228
+ });
229
+ if (merged !== null) this.apply(entry, merged);
230
+ }
231
+ apply(entry, content) {
232
+ entry.content.set(content);
233
+ if (entry.phase() === "visible") {
234
+ this.restart(entry);
235
+ this.announce(entry);
236
+ }
237
+ }
238
+ promote() {
239
+ const entries = this.entries();
240
+ let free = this.max - entries.filter((entry) => entry.phase() === "visible").length;
241
+ for (const entry of entries) {
242
+ if (free <= 0) break;
243
+ if (entry.phase() === "queued") {
244
+ free--;
245
+ entry.phase.set("visible");
246
+ if (this.document.visibilityState === "hidden") entry.pauses.add("hidden");
247
+ this.restart(entry);
248
+ this.announce(entry);
249
+ }
250
+ }
251
+ }
252
+ restart(entry) {
253
+ this.clearTimer(entry);
254
+ entry.remaining = effectiveDuration(entry.content());
255
+ this.arm(entry);
256
+ }
257
+ arm(entry) {
258
+ if (entry.phase() !== "visible" || entry.remaining === null || entry.pauses.size > 0 || entry.timer !== void 0) return;
259
+ entry.startedAt = Date.now();
260
+ entry.timer = setTimeout(() => {
261
+ entry.timer = void 0;
262
+ this.dismiss(entry, "timeout");
263
+ }, entry.remaining);
264
+ }
265
+ clearTimer(entry) {
266
+ if (entry.timer !== void 0) {
267
+ clearTimeout(entry.timer);
268
+ entry.timer = void 0;
269
+ }
270
+ }
271
+ announce(entry) {
272
+ const content = entry.content();
273
+ const politeness = content.tone === "danger" ? "assertive" : "polite";
274
+ const text = announcementOf(content);
275
+ const signature = `${politeness}|${text}`;
276
+ if (signature !== entry.announced) {
277
+ entry.announced = signature;
278
+ this.announcer.announce(text, politeness);
279
+ }
280
+ }
281
+ listen() {
282
+ if (!this.listening) {
283
+ this.listening = true;
284
+ this.document.addEventListener("visibilitychange", this.onVisibilityChange);
285
+ }
286
+ }
287
+ onVisibilityChange = () => {
288
+ const hidden = this.document.visibilityState === "hidden";
289
+ for (const entry of this.entries()) {
290
+ if (entry.phase() !== "visible") continue;
291
+ if (hidden) this.pause(entry, "hidden");
292
+ else this.resume(entry, "hidden");
293
+ }
294
+ };
295
+ static ɵfac = i0.ɵɵngDeclareFactory({
296
+ minVersion: "12.0.0",
297
+ version: "22.2.4",
298
+ ngImport: i0,
299
+ type: CkToastStore,
300
+ deps: [],
301
+ target: i0.ɵɵFactoryTarget.Injectable
302
+ });
303
+ static ɵprov = i0.ɵɵngDeclareInjectable({
304
+ minVersion: "12.0.0",
305
+ version: "22.2.4",
306
+ ngImport: i0,
307
+ type: CkToastStore,
308
+ providedIn: "root"
309
+ });
310
+ };
311
+ i0.ɵɵngDeclareClassMetadata({
312
+ minVersion: "12.0.0",
313
+ version: "22.2.4",
314
+ ngImport: i0,
315
+ type: CkToastStore,
316
+ decorators: [{
317
+ type: Injectable,
318
+ args: [{ providedIn: "root" }]
319
+ }]
320
+ });
321
+ const SWIPE_SLOP = 8;
322
+ const SWIPE_DISTANCE_RATIO = .35;
323
+ const SWIPE_FLICK_VELOCITY = .5;
324
+ const SWIPE_FLICK_MIN_DISTANCE = 24;
325
+ const VELOCITY_WINDOW = 100;
326
+ const LEAVE_GRACE = 100;
327
+ const CLICK_AFTER_DRAG = 100;
328
+ const ICONS = {
329
+ neutral: "info",
330
+ success: "check",
331
+ warning: "alert-triangle",
332
+ danger: "alert-octagon"
333
+ };
334
+ function parseTime(value) {
335
+ const match = /^\s*(-?[\d.]+)(ms|s)\s*$/.exec(value);
336
+ if (!match) return 0;
337
+ const amount = Number(match[1]) * (match[2] === "s" ? 1e3 : 1);
338
+ return Number.isFinite(amount) && amount > 0 ? amount : 0;
339
+ }
340
+ var CkToastItem = class CkToastItem {
341
+ entry = input.required(...ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []);
342
+ store = inject(CkToastStore);
343
+ labels = inject(CK_LABELS);
344
+ media = inject(CkMedia);
345
+ injector = inject(Injector);
346
+ destroyRef = inject(DestroyRef);
347
+ element = inject(ElementRef).nativeElement;
348
+ view = this.element.ownerDocument.defaultView;
349
+ content = computed(() => this.entry().content(), ...ngDevMode ? [{ debugName: "content" }] : /* istanbul ignore next */ []);
350
+ leaving = computed(() => this.entry().phase() === "leaving", ...ngDevMode ? [{ debugName: "leaving" }] : /* istanbul ignore next */ []);
351
+ toneClass = computed(() => `ck-toast--${this.content().tone}`, ...ngDevMode ? [{ debugName: "toneClass" }] : /* istanbul ignore next */ []);
352
+ iconName = computed(() => ICONS[this.content().tone], ...ngDevMode ? [{ debugName: "iconName" }] : /* istanbul ignore next */ []);
353
+ destroyed = false;
354
+ stopTracking = null;
355
+ dragEndedAt = null;
356
+ constructor() {
357
+ const destroyRef = this.destroyRef;
358
+ const swallowClick = (event) => {
359
+ const endedAt = this.dragEndedAt;
360
+ this.dragEndedAt = null;
361
+ if (endedAt !== null && event.timeStamp - endedAt < CLICK_AFTER_DRAG) {
362
+ event.preventDefault();
363
+ event.stopImmediatePropagation();
364
+ }
365
+ };
366
+ this.element.addEventListener("click", swallowClick, { capture: true });
367
+ destroyRef.onDestroy(() => {
368
+ this.destroyed = true;
369
+ this.element.removeEventListener("click", swallowClick, { capture: true });
370
+ this.stopTracking?.();
371
+ });
372
+ effect(() => {
373
+ this.entry().element = this.element;
374
+ });
375
+ effect(() => {
376
+ if (this.leaving()) untracked(() => afterNextRender(() => this.finishLeaving(), { injector: this.injector }));
377
+ });
378
+ }
379
+ runAction() {
380
+ const entry = this.entry();
381
+ const action = entry.content().action;
382
+ if (!action || entry.phase() !== "visible") return;
383
+ try {
384
+ action.run();
385
+ } finally {
386
+ this.store.dismiss(entry, "action");
387
+ }
388
+ }
389
+ dismiss() {
390
+ this.store.dismiss(this.entry(), "user");
391
+ }
392
+ onPointerEnter(event) {
393
+ if (event.pointerType !== "touch") this.store.pause(this.entry(), "hover");
394
+ }
395
+ onPointerLeave(event) {
396
+ if (event.pointerType !== "touch") this.store.resume(this.entry(), "hover");
397
+ }
398
+ onFocusIn() {
399
+ this.store.pause(this.entry(), "focus");
400
+ }
401
+ onFocusOut(event) {
402
+ if (!(event.relatedTarget instanceof Node && this.element.contains(event.relatedTarget))) this.store.resume(this.entry(), "focus");
403
+ }
404
+ finishLeaving() {
405
+ if (this.destroyed) return;
406
+ const entry = this.entry();
407
+ const style = this.view.getComputedStyle(this.element);
408
+ const duration = parseTime(style.animationDuration.split(",")[0] ?? "");
409
+ if (style.animationName === "none" || duration === 0 || this.media.reducedMotion()) {
410
+ this.store.remove(entry);
411
+ return;
412
+ }
413
+ let done = false;
414
+ const finish = () => {
415
+ if (!done) {
416
+ done = true;
417
+ clearTimeout(fallback);
418
+ this.element.removeEventListener("animationend", finish);
419
+ this.store.remove(entry);
420
+ }
421
+ };
422
+ const fallback = setTimeout(finish, duration + LEAVE_GRACE);
423
+ this.element.addEventListener("animationend", finish);
424
+ this.destroyRef.onDestroy(() => clearTimeout(fallback));
425
+ }
426
+ onPointerDown(event) {
427
+ this.dragEndedAt = null;
428
+ const entry = this.entry();
429
+ if (this.stopTracking || !event.isPrimary || event.button !== 0 || entry.phase() !== "visible") return;
430
+ const element = this.element;
431
+ const doc = element.ownerDocument;
432
+ const now = () => this.view.performance.now();
433
+ const pointerId = event.pointerId;
434
+ const startX = event.clientX;
435
+ const startY = event.clientY;
436
+ const width = Math.max(element.getBoundingClientRect().width, 1);
437
+ let swiping = false;
438
+ let offset = 0;
439
+ let samples = [{
440
+ offset: 0,
441
+ time: now()
442
+ }];
443
+ this.store.pause(entry, "drag");
444
+ const end = () => {
445
+ doc.removeEventListener("pointermove", onMove);
446
+ doc.removeEventListener("pointerup", onUp);
447
+ doc.removeEventListener("pointercancel", onCancel);
448
+ this.stopTracking = null;
449
+ element.classList.remove("ck-toast--dragging");
450
+ this.store.resume(entry, "drag");
451
+ };
452
+ const snapBack = () => {
453
+ const from = offset;
454
+ const opacity = element.style.opacity || "1";
455
+ element.style.translate = "";
456
+ element.style.opacity = "";
457
+ const duration = this.media.reducedMotion() ? 0 : parseTime(this.view.getComputedStyle(element).getPropertyValue("--ck-duration-normal"));
458
+ if (from !== 0 && duration > 0 && typeof element.animate === "function") element.animate([{
459
+ translate: `${from}px 0`,
460
+ opacity
461
+ }, {
462
+ translate: "0 0",
463
+ opacity: "1"
464
+ }], {
465
+ duration,
466
+ easing: "ease-out"
467
+ });
468
+ };
469
+ const velocity = () => {
470
+ const current = now();
471
+ const recent = samples.filter((sample) => current - sample.time <= VELOCITY_WINDOW);
472
+ const first = recent[0];
473
+ const last = recent[recent.length - 1];
474
+ return first && last ? (Math.abs(last.offset) - Math.abs(first.offset)) / Math.max(1, current - first.time) : 0;
475
+ };
476
+ const onMove = (moved) => {
477
+ if (moved.pointerId !== pointerId) return;
478
+ const deltaX = moved.clientX - startX;
479
+ const deltaY = moved.clientY - startY;
480
+ if (!swiping) {
481
+ if (Math.max(Math.abs(deltaX), Math.abs(deltaY)) < SWIPE_SLOP) return;
482
+ if (Math.abs(deltaY) > Math.abs(deltaX)) {
483
+ end();
484
+ return;
485
+ }
486
+ swiping = true;
487
+ element.classList.add("ck-toast--dragging");
488
+ try {
489
+ element.setPointerCapture?.(pointerId);
490
+ } catch {}
491
+ }
492
+ offset = deltaX;
493
+ element.style.translate = `${offset}px 0`;
494
+ element.style.opacity = String(Math.max(0, 1 - Math.abs(offset) / width));
495
+ samples.push({
496
+ offset,
497
+ time: now()
498
+ });
499
+ };
500
+ const onUp = (released) => {
501
+ if (released.pointerId !== pointerId) return;
502
+ const distance = Math.abs(offset);
503
+ const dismissed = swiping && (distance > width * SWIPE_DISTANCE_RATIO || velocity() >= SWIPE_FLICK_VELOCITY && distance >= SWIPE_FLICK_MIN_DISTANCE);
504
+ end();
505
+ if (swiping) this.dragEndedAt = released.timeStamp;
506
+ if (dismissed) this.store.dismiss(entry, "user", true);
507
+ else if (swiping) snapBack();
508
+ };
509
+ const onCancel = (cancelled) => {
510
+ if (cancelled.pointerId !== pointerId) return;
511
+ end();
512
+ if (swiping) snapBack();
513
+ };
514
+ this.stopTracking = () => {
515
+ end();
516
+ samples = [];
517
+ };
518
+ doc.addEventListener("pointermove", onMove);
519
+ doc.addEventListener("pointerup", onUp);
520
+ doc.addEventListener("pointercancel", onCancel);
521
+ }
522
+ static ɵfac = i0.ɵɵngDeclareFactory({
523
+ minVersion: "12.0.0",
524
+ version: "22.2.4",
525
+ ngImport: i0,
526
+ type: CkToastItem,
527
+ deps: [],
528
+ target: i0.ɵɵFactoryTarget.Component
529
+ });
530
+ static ɵcmp = i0.ɵɵngDeclareComponent({
531
+ minVersion: "17.0.0",
532
+ version: "22.2.4",
533
+ type: CkToastItem,
534
+ isStandalone: true,
535
+ selector: "ck-toast-item",
536
+ inputs: { entry: {
537
+ classPropertyName: "entry",
538
+ publicName: "entry",
539
+ isSignal: true,
540
+ isRequired: true,
541
+ transformFunction: null
542
+ } },
543
+ host: {
544
+ listeners: {
545
+ "pointerenter": "onPointerEnter($event)",
546
+ "pointerleave": "onPointerLeave($event)",
547
+ "focusin": "onFocusIn()",
548
+ "focusout": "onFocusOut($event)",
549
+ "pointerdown": "onPointerDown($event)"
550
+ },
551
+ properties: {
552
+ "class": "toneClass()",
553
+ "class.ck-toast--leaving": "leaving()",
554
+ "class.ck-toast--swiped": "entry().swiped()",
555
+ "attr.inert": "leaving() ? \"\" : null"
556
+ },
557
+ classAttribute: "ck-toast"
558
+ },
559
+ ngImport: i0,
560
+ template: `
561
+ <span class="ck-toast__icon" aria-hidden="true">
562
+ <ck-icon [name]="iconName()" />
563
+ </span>
564
+ <div class="ck-toast__text">
565
+ @if (content().title; as title) {
566
+ <div class="ck-toast__title">{{ title }}</div>
567
+ }
568
+ @if (content().message.trim() !== '') {
569
+ <div class="ck-toast__message">{{ content().message }}</div>
570
+ }
571
+ </div>
572
+ <div class="ck-toast__buttons">
573
+ @if (content().action; as action) {
574
+ <button
575
+ ckButton
576
+ type="button"
577
+ variant="ghost"
578
+ class="ck-toast__action"
579
+ [size]="store.size()"
580
+ (click)="runAction()"
581
+ >
582
+ {{ action.label }}
583
+ </button>
584
+ }
585
+ <button
586
+ ckButton
587
+ type="button"
588
+ variant="ghost"
589
+ iconOnly
590
+ class="ck-toast__dismiss"
591
+ [size]="store.size()"
592
+ [attr.aria-label]="labels().dismiss"
593
+ (click)="dismiss()"
594
+ >
595
+ <ck-icon name="close" />
596
+ </button>
597
+ </div>
598
+ `,
599
+ isInline: true,
600
+ dependencies: [{
601
+ kind: "component",
602
+ type: CkButton,
603
+ selector: "button[ckButton], a[ckButton]",
604
+ inputs: [
605
+ "variant",
606
+ "size",
607
+ "iconOnly",
608
+ "loading",
609
+ "disabled"
610
+ ]
611
+ }, {
612
+ kind: "component",
613
+ type: CkIcon,
614
+ selector: "ck-icon",
615
+ inputs: ["name"]
616
+ }],
617
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
618
+ encapsulation: i0.ViewEncapsulation.None
619
+ });
620
+ };
621
+ i0.ɵɵngDeclareClassMetadata({
622
+ minVersion: "12.0.0",
623
+ version: "22.2.4",
624
+ ngImport: i0,
625
+ type: CkToastItem,
626
+ decorators: [{
627
+ type: Component,
628
+ args: [{
629
+ selector: "ck-toast-item",
630
+ imports: [CkButton, CkIcon],
631
+ changeDetection: ChangeDetectionStrategy.OnPush,
632
+ encapsulation: ViewEncapsulation.None,
633
+ host: {
634
+ class: "ck-toast",
635
+ "[class]": "toneClass()",
636
+ "[class.ck-toast--leaving]": "leaving()",
637
+ "[class.ck-toast--swiped]": "entry().swiped()",
638
+ "[attr.inert]": "leaving() ? \"\" : null",
639
+ "(pointerenter)": "onPointerEnter($event)",
640
+ "(pointerleave)": "onPointerLeave($event)",
641
+ "(focusin)": "onFocusIn()",
642
+ "(focusout)": "onFocusOut($event)",
643
+ "(pointerdown)": "onPointerDown($event)"
644
+ },
645
+ template: `
646
+ <span class="ck-toast__icon" aria-hidden="true">
647
+ <ck-icon [name]="iconName()" />
648
+ </span>
649
+ <div class="ck-toast__text">
650
+ @if (content().title; as title) {
651
+ <div class="ck-toast__title">{{ title }}</div>
652
+ }
653
+ @if (content().message.trim() !== '') {
654
+ <div class="ck-toast__message">{{ content().message }}</div>
655
+ }
656
+ </div>
657
+ <div class="ck-toast__buttons">
658
+ @if (content().action; as action) {
659
+ <button
660
+ ckButton
661
+ type="button"
662
+ variant="ghost"
663
+ class="ck-toast__action"
664
+ [size]="store.size()"
665
+ (click)="runAction()"
666
+ >
667
+ {{ action.label }}
668
+ </button>
669
+ }
670
+ <button
671
+ ckButton
672
+ type="button"
673
+ variant="ghost"
674
+ iconOnly
675
+ class="ck-toast__dismiss"
676
+ [size]="store.size()"
677
+ [attr.aria-label]="labels().dismiss"
678
+ (click)="dismiss()"
679
+ >
680
+ <ck-icon name="close" />
681
+ </button>
682
+ </div>
683
+ `
684
+ }]
685
+ }],
686
+ ctorParameters: () => [],
687
+ propDecorators: { entry: [{
688
+ type: i0.Input,
689
+ args: [{
690
+ isSignal: true,
691
+ alias: "entry",
692
+ required: true
693
+ }]
694
+ }] }
695
+ });
696
+ var CkToastHost = class CkToastHost {
697
+ store = inject(CkToastStore);
698
+ labels = inject(CK_LABELS);
699
+ media = inject(CkMedia);
700
+ align = computed(() => this.store.alignOverride ?? (this.media.narrow() ? "center" : "end"), ...ngDevMode ? [{ debugName: "align" }] : /* istanbul ignore next */ []);
701
+ shown = computed(() => {
702
+ const shown = this.store.entries().filter((entry) => entry.phase() !== "queued");
703
+ return this.store.position === "top" ? shown.reverse() : shown;
704
+ }, ...ngDevMode ? [{ debugName: "shown" }] : /* istanbul ignore next */ []);
705
+ static ɵfac = i0.ɵɵngDeclareFactory({
706
+ minVersion: "12.0.0",
707
+ version: "22.2.4",
708
+ ngImport: i0,
709
+ type: CkToastHost,
710
+ deps: [],
711
+ target: i0.ɵɵFactoryTarget.Component
712
+ });
713
+ static ɵcmp = i0.ɵɵngDeclareComponent({
714
+ minVersion: "17.0.0",
715
+ version: "22.2.4",
716
+ type: CkToastHost,
717
+ isStandalone: true,
718
+ selector: "ck-toast-host",
719
+ host: {
720
+ attributes: { "data-ck-inert-exempt": "" },
721
+ properties: {
722
+ "attr.aria-label": "labels().notifications",
723
+ "class.ck-toast-host--top": "store.position === \"top\"",
724
+ "class.ck-toast-host--bottom": "store.position === \"bottom\"",
725
+ "class.ck-toast-host--center": "align() === \"center\"",
726
+ "class.ck-toast-host--end": "align() === \"end\"",
727
+ "class.ck-toast-host--narrow": "media.narrow()",
728
+ "class.ck-toast-host--empty": "shown().length === 0"
729
+ },
730
+ classAttribute: "ck-toast-host"
731
+ },
732
+ ngImport: i0,
733
+ template: `
734
+ @for (entry of shown(); track entry.key) {
735
+ <ck-toast-item [entry]="entry" />
736
+ }
737
+ `,
738
+ isInline: true,
739
+ styles: ["@layer ckui{.ck-toast-host{position:fixed;inset-inline:0;z-index:var(--ck-z-toast, 1100);display:flex;flex-direction:column;gap:var(--ck-space-2);box-sizing:border-box;padding-block:var(--ck-space-4);padding-left:max(var(--ck-space-4),env(safe-area-inset-left,0px));padding-right:max(var(--ck-space-4),env(safe-area-inset-right,0px));pointer-events:none}.ck-toast-host--bottom{inset-block-end:0;padding-block-end:max(var(--ck-space-4),env(safe-area-inset-bottom,0px))}.ck-toast-host--top{inset-block-start:0;padding-block-start:max(var(--ck-space-4),env(safe-area-inset-top,0px))}.ck-toast-host--center{align-items:center}.ck-toast-host--end{align-items:flex-end}.ck-toast-host--empty{display:none}.ck-toast{--_ck-toast-bg: var(--ck-toast-bg, var(--ck-color-surface-raised));--_ck-toast-fg: var(--ck-toast-fg, var(--ck-color-fg));--_ck-toast-icon: var(--ck-color-fg-muted);--_ck-toast-shift: var(--ck-space-4);display:flex;flex-wrap:wrap;align-items:center;gap:var(--ck-space-3);box-sizing:border-box;inline-size:min(100%,var(--ck-toast-max-width, 28rem));padding-block:var(--ck-space-2);padding-inline:var(--ck-space-4) var(--ck-space-2);border:1px solid var(--ck-color-border-subtle);border-radius:var(--ck-toast-radius, var(--ck-radius-lg));background:var(--_ck-toast-bg);box-shadow:var(--ck-toast-shadow, var(--ck-shadow-lg));color:var(--_ck-toast-fg);color-scheme:var(--ck-color-scheme);font-family:var(--ck-font-sans);font-size:var(--ck-font-size-md);font-variant-numeric:var(--ck-font-variant-numeric);line-height:var(--ck-line-height-normal);pointer-events:auto;touch-action:pan-y;animation:ck-toast-in var(--ck-duration-normal) var(--ck-ease-emphasized)}.ck-toast-host--top .ck-toast{--_ck-toast-shift: calc(-1 * var(--ck-space-4))}.ck-toast-host--narrow .ck-toast{inline-size:100%}.ck-toast--success{--_ck-toast-icon: var(--ck-color-success)}.ck-toast--warning{--_ck-toast-icon: var(--ck-color-warning-fg)}.ck-toast--danger{--_ck-toast-bg: var(--ck-toast-danger-bg, var(--ck-color-danger));--_ck-toast-fg: var(--ck-toast-danger-fg, var(--ck-color-on-danger));--_ck-toast-icon: var(--_ck-toast-fg);border-color:transparent}.ck-toast--dragging{-webkit-user-select:none;user-select:none;cursor:grabbing}.ck-toast--leaving{animation:ck-toast-out var(--ck-duration-normal) var(--ck-ease-standard) forwards}.ck-toast--leaving.ck-toast--swiped{animation-name:ck-toast-fade}.ck-toast__icon{display:inline-flex;flex:none;align-items:center;justify-content:center;color:var(--_ck-toast-icon);font-size:var(--ck-font-size-xl)}.ck-toast__text{flex:1 1 6rem;box-sizing:border-box;min-inline-size:0;padding-block:var(--ck-space-1);overflow-wrap:break-word;max-block-size:30dvh;overflow-y:auto;overscroll-behavior:contain}.ck-toast__title{font-weight:var(--ck-font-weight-semibold)}.ck-toast__buttons{display:flex;flex:none;align-items:center;gap:var(--ck-space-1);max-inline-size:100%;margin-inline-start:auto}.ck-toast .ck-toast__action{flex:0 1 auto;min-inline-size:0}.ck-toast .ck-toast__dismiss{flex:none;color:var(--_ck-toast-fg)}.ck-toast--danger .ck-toast__action{border-color:currentColor;color:var(--_ck-toast-fg)}.ck-toast--danger .ck-button:focus-visible{outline-color:var(--_ck-toast-fg)}@media(hover:hover){.ck-toast--danger .ck-button:hover{background:var(--ck-color-danger-hover)}}.ck-toast--danger .ck-button:active{background:var(--ck-color-danger-active)}@keyframes ck-toast-in{0%{opacity:0;translate:0 var(--_ck-toast-shift)}}@keyframes ck-toast-out{to{opacity:0;translate:0 var(--_ck-toast-shift)}}@keyframes ck-toast-fade{to{opacity:0}}@media(prefers-reduced-motion:reduce){.ck-toast,.ck-toast--leaving{animation:none}}@media(forced-colors:active){.ck-toast,.ck-toast--danger{border-color:CanvasText}}}\n"],
740
+ dependencies: [{
741
+ kind: "component",
742
+ type: CkToastItem,
743
+ selector: "ck-toast-item",
744
+ inputs: ["entry"]
745
+ }],
746
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
747
+ encapsulation: i0.ViewEncapsulation.None
748
+ });
749
+ };
750
+ i0.ɵɵngDeclareClassMetadata({
751
+ minVersion: "12.0.0",
752
+ version: "22.2.4",
753
+ ngImport: i0,
754
+ type: CkToastHost,
755
+ decorators: [{
756
+ type: Component,
757
+ args: [{
758
+ selector: "ck-toast-host",
759
+ imports: [CkToastItem],
760
+ changeDetection: ChangeDetectionStrategy.OnPush,
761
+ encapsulation: ViewEncapsulation.None,
762
+ host: {
763
+ class: "ck-toast-host",
764
+ "data-ck-inert-exempt": "",
765
+ "[attr.aria-label]": "labels().notifications",
766
+ "[class.ck-toast-host--top]": "store.position === \"top\"",
767
+ "[class.ck-toast-host--bottom]": "store.position === \"bottom\"",
768
+ "[class.ck-toast-host--center]": "align() === \"center\"",
769
+ "[class.ck-toast-host--end]": "align() === \"end\"",
770
+ "[class.ck-toast-host--narrow]": "media.narrow()",
771
+ "[class.ck-toast-host--empty]": "shown().length === 0"
772
+ },
773
+ template: `
774
+ @for (entry of shown(); track entry.key) {
775
+ <ck-toast-item [entry]="entry" />
776
+ }
777
+ `,
778
+ styles: ["@layer ckui{.ck-toast-host{position:fixed;inset-inline:0;z-index:var(--ck-z-toast, 1100);display:flex;flex-direction:column;gap:var(--ck-space-2);box-sizing:border-box;padding-block:var(--ck-space-4);padding-left:max(var(--ck-space-4),env(safe-area-inset-left,0px));padding-right:max(var(--ck-space-4),env(safe-area-inset-right,0px));pointer-events:none}.ck-toast-host--bottom{inset-block-end:0;padding-block-end:max(var(--ck-space-4),env(safe-area-inset-bottom,0px))}.ck-toast-host--top{inset-block-start:0;padding-block-start:max(var(--ck-space-4),env(safe-area-inset-top,0px))}.ck-toast-host--center{align-items:center}.ck-toast-host--end{align-items:flex-end}.ck-toast-host--empty{display:none}.ck-toast{--_ck-toast-bg: var(--ck-toast-bg, var(--ck-color-surface-raised));--_ck-toast-fg: var(--ck-toast-fg, var(--ck-color-fg));--_ck-toast-icon: var(--ck-color-fg-muted);--_ck-toast-shift: var(--ck-space-4);display:flex;flex-wrap:wrap;align-items:center;gap:var(--ck-space-3);box-sizing:border-box;inline-size:min(100%,var(--ck-toast-max-width, 28rem));padding-block:var(--ck-space-2);padding-inline:var(--ck-space-4) var(--ck-space-2);border:1px solid var(--ck-color-border-subtle);border-radius:var(--ck-toast-radius, var(--ck-radius-lg));background:var(--_ck-toast-bg);box-shadow:var(--ck-toast-shadow, var(--ck-shadow-lg));color:var(--_ck-toast-fg);color-scheme:var(--ck-color-scheme);font-family:var(--ck-font-sans);font-size:var(--ck-font-size-md);font-variant-numeric:var(--ck-font-variant-numeric);line-height:var(--ck-line-height-normal);pointer-events:auto;touch-action:pan-y;animation:ck-toast-in var(--ck-duration-normal) var(--ck-ease-emphasized)}.ck-toast-host--top .ck-toast{--_ck-toast-shift: calc(-1 * var(--ck-space-4))}.ck-toast-host--narrow .ck-toast{inline-size:100%}.ck-toast--success{--_ck-toast-icon: var(--ck-color-success)}.ck-toast--warning{--_ck-toast-icon: var(--ck-color-warning-fg)}.ck-toast--danger{--_ck-toast-bg: var(--ck-toast-danger-bg, var(--ck-color-danger));--_ck-toast-fg: var(--ck-toast-danger-fg, var(--ck-color-on-danger));--_ck-toast-icon: var(--_ck-toast-fg);border-color:transparent}.ck-toast--dragging{-webkit-user-select:none;user-select:none;cursor:grabbing}.ck-toast--leaving{animation:ck-toast-out var(--ck-duration-normal) var(--ck-ease-standard) forwards}.ck-toast--leaving.ck-toast--swiped{animation-name:ck-toast-fade}.ck-toast__icon{display:inline-flex;flex:none;align-items:center;justify-content:center;color:var(--_ck-toast-icon);font-size:var(--ck-font-size-xl)}.ck-toast__text{flex:1 1 6rem;box-sizing:border-box;min-inline-size:0;padding-block:var(--ck-space-1);overflow-wrap:break-word;max-block-size:30dvh;overflow-y:auto;overscroll-behavior:contain}.ck-toast__title{font-weight:var(--ck-font-weight-semibold)}.ck-toast__buttons{display:flex;flex:none;align-items:center;gap:var(--ck-space-1);max-inline-size:100%;margin-inline-start:auto}.ck-toast .ck-toast__action{flex:0 1 auto;min-inline-size:0}.ck-toast .ck-toast__dismiss{flex:none;color:var(--_ck-toast-fg)}.ck-toast--danger .ck-toast__action{border-color:currentColor;color:var(--_ck-toast-fg)}.ck-toast--danger .ck-button:focus-visible{outline-color:var(--_ck-toast-fg)}@media(hover:hover){.ck-toast--danger .ck-button:hover{background:var(--ck-color-danger-hover)}}.ck-toast--danger .ck-button:active{background:var(--ck-color-danger-active)}@keyframes ck-toast-in{0%{opacity:0;translate:0 var(--_ck-toast-shift)}}@keyframes ck-toast-out{to{opacity:0;translate:0 var(--_ck-toast-shift)}}@keyframes ck-toast-fade{to{opacity:0}}@media(prefers-reduced-motion:reduce){.ck-toast,.ck-toast--leaving{animation:none}}@media(forced-colors:active){.ck-toast,.ck-toast--danger{border-color:CanvasText}}}\n"]
779
+ }]
780
+ }]
781
+ });
782
+ const FOCUSABLE = "button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
783
+ var CkToast = class CkToast {
784
+ store = inject(CkToastStore);
785
+ document = inject(DOCUMENT);
786
+ appRef = inject(ApplicationRef);
787
+ environmentInjector = inject(EnvironmentInjector);
788
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
789
+ host = null;
790
+ hostElement = null;
791
+ focusOrigin = null;
792
+ constructor() {
793
+ inject(DestroyRef).onDestroy(() => {
794
+ this.store.teardown();
795
+ this.hostElement?.removeEventListener("focusin", this.onFocusIn);
796
+ this.focusOrigin = null;
797
+ this.host?.destroy();
798
+ this.hostElement?.remove();
799
+ this.host = null;
800
+ this.hostElement = null;
801
+ });
802
+ }
803
+ show(options) {
804
+ const ref = this.store.show(options);
805
+ if (this.isBrowser && this.store.entries().length > 0) this.ensureHost();
806
+ return ref;
807
+ }
808
+ dismissAll() {
809
+ this.store.dismissAll();
810
+ }
811
+ ensureHost() {
812
+ if (this.host) return;
813
+ const element = this.document.createElement("section");
814
+ this.document.body.appendChild(element);
815
+ this.hostElement = element;
816
+ element.addEventListener("focusin", this.onFocusIn);
817
+ this.store.beforeLeave = (entry) => this.moveFocusAway(entry);
818
+ this.host = createComponent(CkToastHost, {
819
+ environmentInjector: this.environmentInjector,
820
+ hostElement: element
821
+ });
822
+ this.appRef.attachView(this.host.hostView);
823
+ this.host.changeDetectorRef.detectChanges();
824
+ }
825
+ onFocusIn = (event) => {
826
+ const origin = event.relatedTarget;
827
+ if (origin instanceof HTMLElement && !this.hostElement?.contains(origin)) this.focusOrigin = origin;
828
+ };
829
+ moveFocusAway(entry) {
830
+ const host = this.hostElement;
831
+ const active = this.document.activeElement;
832
+ if (!host || !entry.element || !active || !entry.element.contains(active)) return;
833
+ const slot = active.closest(".ck-toast__action") ? "action" : "dismiss";
834
+ const items = Array.from(host.querySelectorAll("ck-toast-item"));
835
+ const index = items.indexOf(entry.element);
836
+ const stays = (item) => item !== entry.element && this.store.entries().some((other) => other.element === item && other.phase() === "visible");
837
+ const neighbours = [...items.slice(index + 1).filter(stays), ...items.slice(0, index).filter(stays).reverse()];
838
+ for (const item of neighbours) {
839
+ const target = item.querySelector(`.ck-toast__${slot}`) ?? item.querySelector(".ck-toast__dismiss");
840
+ if (this.tryFocus(target)) return;
841
+ }
842
+ const origin = this.focusOrigin;
843
+ if (origin?.isConnected && !host.contains(origin) && this.tryFocus(origin)) return;
844
+ const modals = this.document.querySelectorAll("[aria-modal=\"true\"]");
845
+ const modal = modals[modals.length - 1];
846
+ if (modal) {
847
+ if (!this.tryFocus(modal.querySelector(FOCUSABLE))) this.tryFocus(modal);
848
+ }
849
+ }
850
+ tryFocus(element) {
851
+ element?.focus({ preventScroll: true });
852
+ return !!element && this.document.activeElement === element;
853
+ }
854
+ static ɵfac = i0.ɵɵngDeclareFactory({
855
+ minVersion: "12.0.0",
856
+ version: "22.2.4",
857
+ ngImport: i0,
858
+ type: CkToast,
859
+ deps: [],
860
+ target: i0.ɵɵFactoryTarget.Injectable
861
+ });
862
+ static ɵprov = i0.ɵɵngDeclareInjectable({
863
+ minVersion: "12.0.0",
864
+ version: "22.2.4",
865
+ ngImport: i0,
866
+ type: CkToast,
867
+ providedIn: "root"
868
+ });
869
+ };
870
+ i0.ɵɵngDeclareClassMetadata({
871
+ minVersion: "12.0.0",
872
+ version: "22.2.4",
873
+ ngImport: i0,
874
+ type: CkToast,
875
+ decorators: [{
876
+ type: Injectable,
877
+ args: [{ providedIn: "root" }]
878
+ }],
879
+ ctorParameters: () => []
880
+ });
881
+ export { CkToast, CkToastRef, provideCkToast };
882
+
883
+ //# sourceMappingURL=ckui-core-toast.mjs.map