@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.
@@ -1,10 +1,14 @@
1
1
  import { BreakpointObserver } from "@angular/cdk/layout";
2
2
  import * as i0 from "@angular/core";
3
- import { ChangeDetectionStrategy, Component, Injectable, Injector, ViewEncapsulation, afterNextRender, computed, inject, input } from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, DestroyRef, Directive, Injectable, Injector, PLATFORM_ID, TemplateRef, ViewContainerRef, ViewEncapsulation, afterNextRender, booleanAttribute, computed, forwardRef, inject, input, model, signal, viewChild } from "@angular/core";
4
4
  import { toSignal } from "@angular/core/rxjs-interop";
5
5
  import { CK_CONFIG } from "@ckui/core";
6
6
  import { FocusTrapFactory, LiveAnnouncer } from "@angular/cdk/a11y";
7
- import { DOCUMENT } from "@angular/common";
7
+ import { _CdkPrivateStyleLoader, _VisuallyHiddenLoader } from "@angular/cdk/private";
8
+ import { DOCUMENT, isPlatformBrowser } from "@angular/common";
9
+ import { NG_VALUE_ACCESSOR } from "@angular/forms";
10
+ import { Overlay, OverlayContainer } from "@angular/cdk/overlay";
11
+ import { CdkPortalOutlet, ComponentPortal, TemplatePortal } from "@angular/cdk/portal";
8
12
  let counter = 0;
9
13
  function createCkId(prefix) {
10
14
  if (typeof prefix !== "string" || prefix.trim() === "") throw new TypeError("createCkId needs a non-empty prefix string.");
@@ -51,15 +55,68 @@ i0.ɵɵngDeclareClassMetadata({
51
55
  args: [{ providedIn: "root" }]
52
56
  }]
53
57
  });
58
+ function join(messages) {
59
+ return messages.reduce((text, message) => {
60
+ const trimmed = message.trim();
61
+ if (text === "") return trimmed;
62
+ return /[.!?:;,]$/.test(text) ? `${text} ${trimmed}` : `${text}. ${trimmed}`;
63
+ }, "");
64
+ }
65
+ const READ_OUT_WINDOW = 150;
54
66
  var CkAnnouncer = class CkAnnouncer {
55
67
  liveAnnouncer = inject(LiveAnnouncer);
68
+ pending = [];
69
+ waiters = [];
70
+ scheduled = false;
71
+ view = inject(DOCUMENT).defaultView;
72
+ last = null;
73
+ constructor() {
74
+ if (isPlatformBrowser(inject(PLATFORM_ID))) inject(_CdkPrivateStyleLoader).load(_VisuallyHiddenLoader);
75
+ }
56
76
  announce(message, politeness = "polite") {
57
77
  if (typeof message !== "string" || message.trim() === "") return Promise.resolve();
58
- return this.liveAnnouncer.announce(message, politeness);
78
+ this.pending.push({
79
+ message,
80
+ politeness
81
+ });
82
+ const done = new Promise((resolve) => this.waiters.push(resolve));
83
+ if (!this.scheduled) {
84
+ this.scheduled = true;
85
+ queueMicrotask(() => this.flush());
86
+ }
87
+ return done;
59
88
  }
60
89
  clear() {
90
+ this.pending = [];
91
+ this.last = null;
92
+ this.release();
61
93
  this.liveAnnouncer.clear();
62
94
  }
95
+ flush() {
96
+ this.scheduled = false;
97
+ const items = this.pending;
98
+ if (items.length === 0) return;
99
+ this.pending = [];
100
+ const waiters = this.waiters;
101
+ this.waiters = [];
102
+ const now = this.view?.performance.now() ?? Date.now();
103
+ const previous = this.last && now - this.last.at < READ_OUT_WINDOW ? this.last : null;
104
+ const fresh = join(items.map((item) => item.message));
105
+ const all = previous && previous.message !== fresh ? [previous, ...items] : items;
106
+ const politeness = all.some((item) => item.politeness === "assertive") ? "assertive" : "polite";
107
+ const message = all === items ? fresh : join(all.map((item) => item.message));
108
+ this.last = {
109
+ message,
110
+ politeness,
111
+ at: now
112
+ };
113
+ this.liveAnnouncer.announce(message, politeness).then(() => waiters.forEach((resolve) => resolve()));
114
+ }
115
+ release() {
116
+ const waiters = this.waiters;
117
+ this.waiters = [];
118
+ waiters.forEach((resolve) => resolve());
119
+ }
63
120
  static ɵfac = i0.ɵɵngDeclareFactory({
64
121
  minVersion: "12.0.0",
65
122
  version: "22.2.4",
@@ -84,7 +141,8 @@ i0.ɵɵngDeclareClassMetadata({
84
141
  decorators: [{
85
142
  type: Injectable,
86
143
  args: [{ providedIn: "root" }]
87
- }]
144
+ }],
145
+ ctorParameters: () => []
88
146
  });
89
147
  var CkFocusTrapFactory = class CkFocusTrapFactory {
90
148
  focusTrapFactory = inject(FocusTrapFactory);
@@ -96,11 +154,19 @@ var CkFocusTrapFactory = class CkFocusTrapFactory {
96
154
  let previous = null;
97
155
  let released = false;
98
156
  return {
99
- activate: () => {
157
+ activate: (initialFocus) => {
100
158
  if (released) return Promise.resolve(false);
101
159
  previous ??= document.activeElement instanceof HTMLElement ? document.activeElement : null;
102
160
  return new Promise((resolve) => {
103
- afterNextRender(() => resolve(released ? false : trap.focusInitialElement()), { injector });
161
+ afterNextRender(() => {
162
+ if (released) return resolve(false);
163
+ const target = initialFocus?.() ?? null;
164
+ if (target) {
165
+ target.focus();
166
+ if (document.activeElement === target) return resolve(true);
167
+ }
168
+ resolve(trap.focusInitialElement());
169
+ }, { injector });
104
170
  });
105
171
  },
106
172
  release: () => {
@@ -140,11 +206,15 @@ i0.ɵɵngDeclareClassMetadata({
140
206
  }]
141
207
  });
142
208
  const ICON_PATHS = {
209
+ "alert-octagon": "M5.2 2h5.6L14 5.2v5.6L10.8 14H5.2L2 10.8V5.2L5.2 2zM8 5.5v3M8 11v.01",
210
+ "alert-triangle": "M8 2.5l6 10.5H2L8 2.5zM8 6.5v3M8 11.5v.01",
143
211
  check: "M3 8.5l3.5 3.5L13 4.5",
144
212
  "chevron-down": "M4 6l4 4 4-4",
145
213
  "chevron-end": "M6 4l4 4-4 4",
146
214
  close: "M4 4l8 8M12 4l-8 8",
147
- minus: "M3.5 8h9"
215
+ info: "M8 14A6 6 0 108 2a6 6 0 000 12zM8 7.5v3.5M8 5v.01",
216
+ minus: "M3.5 8h9",
217
+ plus: "M8 3.5v9M3.5 8h9"
148
218
  };
149
219
  var CkIcon = class CkIcon {
150
220
  name = input.required(...ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []);
@@ -236,6 +306,660 @@ i0.ɵɵngDeclareClassMetadata({
236
306
  }]
237
307
  }] }
238
308
  });
239
- export { CkAnnouncer, CkFocusTrapFactory, CkIcon, CkMedia, createCkId };
309
+ const SKIPPED = "script, style, link, template, noscript, [data-ck-inert-exempt], .cdk-live-announcer-element";
310
+ var CkInert = class CkInert {
311
+ document = inject(DOCUMENT);
312
+ holds = /* @__PURE__ */ new Map();
313
+ hold(elements) {
314
+ const held = new Set(elements);
315
+ for (const element of held) {
316
+ const entry = this.holds.get(element);
317
+ if (entry) {
318
+ entry.count++;
319
+ continue;
320
+ }
321
+ const original = element.getAttribute("inert");
322
+ this.holds.set(element, {
323
+ count: 1,
324
+ original
325
+ });
326
+ if (original === null) element.setAttribute("inert", "");
327
+ }
328
+ let released = false;
329
+ return () => {
330
+ if (released) return;
331
+ released = true;
332
+ for (const element of held) {
333
+ const entry = this.holds.get(element);
334
+ if (!entry || --entry.count > 0) continue;
335
+ this.holds.delete(element);
336
+ if (entry.original === null) element.removeAttribute("inert");
337
+ }
338
+ };
339
+ }
340
+ backgroundElements(keep) {
341
+ return Array.from(this.document.body.children).filter((element) => element !== keep && !element.matches(SKIPPED));
342
+ }
343
+ static ɵfac = i0.ɵɵngDeclareFactory({
344
+ minVersion: "12.0.0",
345
+ version: "22.2.4",
346
+ ngImport: i0,
347
+ type: CkInert,
348
+ deps: [],
349
+ target: i0.ɵɵFactoryTarget.Injectable
350
+ });
351
+ static ɵprov = i0.ɵɵngDeclareInjectable({
352
+ minVersion: "12.0.0",
353
+ version: "22.2.4",
354
+ ngImport: i0,
355
+ type: CkInert,
356
+ providedIn: "root"
357
+ });
358
+ };
359
+ i0.ɵɵngDeclareClassMetadata({
360
+ minVersion: "12.0.0",
361
+ version: "22.2.4",
362
+ ngImport: i0,
363
+ type: CkInert,
364
+ decorators: [{
365
+ type: Injectable,
366
+ args: [{ providedIn: "root" }]
367
+ }]
368
+ });
369
+ const noop = () => void 0;
370
+ var CkValueControl = class CkValueControl {
371
+ value = model(void 0, ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
372
+ disabled = input(false, {
373
+ ...ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {},
374
+ transform: booleanAttribute
375
+ });
376
+ touched = model(false, ...ngDevMode ? [{ debugName: "touched" }] : /* istanbul ignore next */ []);
377
+ controlDisabled = signal(false, ...ngDevMode ? [{ debugName: "controlDisabled" }] : /* istanbul ignore next */ []);
378
+ onChange = noop;
379
+ onTouched = noop;
380
+ isDisabled = computed(() => this.disabled() || this.controlDisabled(), ...ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []);
381
+ writeValue(value) {
382
+ this.value.set(value);
383
+ }
384
+ registerOnChange(onChange) {
385
+ this.onChange = onChange;
386
+ }
387
+ registerOnTouched(onTouched) {
388
+ this.onTouched = onTouched;
389
+ }
390
+ setDisabledState(isDisabled) {
391
+ this.controlDisabled.set(isDisabled);
392
+ }
393
+ commit(value) {
394
+ if (this.isDisabled() || Object.is(value, this.value())) return;
395
+ this.value.set(value);
396
+ this.onChange(value);
397
+ }
398
+ markTouched() {
399
+ this.touched.set(true);
400
+ this.onTouched();
401
+ }
402
+ static ɵfac = i0.ɵɵngDeclareFactory({
403
+ minVersion: "12.0.0",
404
+ version: "22.2.4",
405
+ ngImport: i0,
406
+ type: CkValueControl,
407
+ deps: [],
408
+ target: i0.ɵɵFactoryTarget.Directive
409
+ });
410
+ static ɵdir = i0.ɵɵngDeclareDirective({
411
+ minVersion: "17.1.0",
412
+ version: "22.2.4",
413
+ type: CkValueControl,
414
+ isStandalone: true,
415
+ inputs: {
416
+ value: {
417
+ classPropertyName: "value",
418
+ publicName: "value",
419
+ isSignal: true,
420
+ isRequired: false,
421
+ transformFunction: null
422
+ },
423
+ disabled: {
424
+ classPropertyName: "disabled",
425
+ publicName: "disabled",
426
+ isSignal: true,
427
+ isRequired: false,
428
+ transformFunction: null
429
+ },
430
+ touched: {
431
+ classPropertyName: "touched",
432
+ publicName: "touched",
433
+ isSignal: true,
434
+ isRequired: false,
435
+ transformFunction: null
436
+ }
437
+ },
438
+ outputs: {
439
+ value: "valueChange",
440
+ touched: "touchedChange"
441
+ },
442
+ ngImport: i0
443
+ });
444
+ };
445
+ i0.ɵɵngDeclareClassMetadata({
446
+ minVersion: "12.0.0",
447
+ version: "22.2.4",
448
+ ngImport: i0,
449
+ type: CkValueControl,
450
+ decorators: [{ type: Directive }],
451
+ propDecorators: {
452
+ value: [{
453
+ type: i0.Input,
454
+ args: [{
455
+ isSignal: true,
456
+ alias: "value",
457
+ required: false
458
+ }]
459
+ }, {
460
+ type: i0.Output,
461
+ args: ["valueChange"]
462
+ }],
463
+ disabled: [{
464
+ type: i0.Input,
465
+ args: [{
466
+ isSignal: true,
467
+ alias: "disabled",
468
+ required: false
469
+ }]
470
+ }],
471
+ touched: [{
472
+ type: i0.Input,
473
+ args: [{
474
+ isSignal: true,
475
+ alias: "touched",
476
+ required: false
477
+ }]
478
+ }, {
479
+ type: i0.Output,
480
+ args: ["touchedChange"]
481
+ }]
482
+ }
483
+ });
484
+ function provideCkValueAccessor(type) {
485
+ return {
486
+ provide: NG_VALUE_ACCESSOR,
487
+ useExisting: forwardRef(() => type),
488
+ multi: true
489
+ };
490
+ }
491
+ var CkOverlayPane = class CkOverlayPane {
492
+ grab = input(false, ...ngDevMode ? [{ debugName: "grab" }] : /* istanbul ignore next */ []);
493
+ outlet = viewChild.required(CdkPortalOutlet, ...ngDevMode ? [{ debugName: "outlet" }] : /* istanbul ignore next */ []);
494
+ viewContainerRef = inject(ViewContainerRef);
495
+ attach(portal) {
496
+ this.outlet().attach(portal);
497
+ }
498
+ static ɵfac = i0.ɵɵngDeclareFactory({
499
+ minVersion: "12.0.0",
500
+ version: "22.2.4",
501
+ ngImport: i0,
502
+ type: CkOverlayPane,
503
+ deps: [],
504
+ target: i0.ɵɵFactoryTarget.Component
505
+ });
506
+ static ɵcmp = i0.ɵɵngDeclareComponent({
507
+ minVersion: "17.0.0",
508
+ version: "22.2.4",
509
+ type: CkOverlayPane,
510
+ isStandalone: true,
511
+ selector: "ck-overlay-pane",
512
+ inputs: { grab: {
513
+ classPropertyName: "grab",
514
+ publicName: "grab",
515
+ isSignal: true,
516
+ isRequired: false,
517
+ transformFunction: null
518
+ } },
519
+ host: { classAttribute: "ck-overlay-pane" },
520
+ viewQueries: [{
521
+ propertyName: "outlet",
522
+ first: true,
523
+ predicate: CdkPortalOutlet,
524
+ descendants: true,
525
+ isSignal: true
526
+ }],
527
+ ngImport: i0,
528
+ template: `
529
+ @if (grab()) {
530
+ <div class="ck-overlay-grab" data-ck-sheet-grab aria-hidden="true">
531
+ <span class="ck-overlay-grab-bar"></span>
532
+ </div>
533
+ }
534
+ <ng-template cdkPortalOutlet />
535
+ `,
536
+ isInline: true,
537
+ styles: ["@layer ckui{.ck-overlay-backdrop{position:absolute;inset:0;z-index:-1;background:var(--ck-color-backdrop);pointer-events:auto;touch-action:manipulation}@media(forced-colors:active){.ck-overlay-backdrop{forced-color-adjust:none}}.ck-overlay-pane{position:relative;display:flex;flex:1 1 auto;flex-direction:column;min-inline-size:0;min-block-size:0;max-block-size:100%}.ck-overlay-pane>:not(.ck-overlay-grab){flex:1 1 auto;min-block-size:0}.ck-overlay-grab{display:flex;flex:none;justify-content:center;block-size:var(--ck-target-min);border-start-start-radius:var(--ck-radius-xl);border-start-end-radius:var(--ck-radius-xl);background:var(--ck-sheet-grab-bg, var(--ck-color-surface-raised));touch-action:none}.ck-overlay-grab-bar{margin-block-start:var(--ck-space-2);inline-size:var(--ck-space-10);block-size:var(--ck-space-1);border-radius:var(--ck-radius-full);background:var(--ck-color-border)}@media(forced-colors:active){.ck-overlay{border:1px solid CanvasText}.ck-overlay-grab-bar{background:CanvasText}}}\n"],
538
+ dependencies: [{
539
+ kind: "directive",
540
+ type: CdkPortalOutlet,
541
+ selector: "[cdkPortalOutlet]",
542
+ inputs: ["cdkPortalOutlet"],
543
+ outputs: ["attached"],
544
+ exportAs: ["cdkPortalOutlet"]
545
+ }],
546
+ changeDetection: i0.ChangeDetectionStrategy.OnPush,
547
+ encapsulation: i0.ViewEncapsulation.None
548
+ });
549
+ };
550
+ i0.ɵɵngDeclareClassMetadata({
551
+ minVersion: "12.0.0",
552
+ version: "22.2.4",
553
+ ngImport: i0,
554
+ type: CkOverlayPane,
555
+ decorators: [{
556
+ type: Component,
557
+ args: [{
558
+ selector: "ck-overlay-pane",
559
+ imports: [CdkPortalOutlet],
560
+ changeDetection: ChangeDetectionStrategy.OnPush,
561
+ encapsulation: ViewEncapsulation.None,
562
+ host: { class: "ck-overlay-pane" },
563
+ template: `
564
+ @if (grab()) {
565
+ <div class="ck-overlay-grab" data-ck-sheet-grab aria-hidden="true">
566
+ <span class="ck-overlay-grab-bar"></span>
567
+ </div>
568
+ }
569
+ <ng-template cdkPortalOutlet />
570
+ `,
571
+ styles: ["@layer ckui{.ck-overlay-backdrop{position:absolute;inset:0;z-index:-1;background:var(--ck-color-backdrop);pointer-events:auto;touch-action:manipulation}@media(forced-colors:active){.ck-overlay-backdrop{forced-color-adjust:none}}.ck-overlay-pane{position:relative;display:flex;flex:1 1 auto;flex-direction:column;min-inline-size:0;min-block-size:0;max-block-size:100%}.ck-overlay-pane>:not(.ck-overlay-grab){flex:1 1 auto;min-block-size:0}.ck-overlay-grab{display:flex;flex:none;justify-content:center;block-size:var(--ck-target-min);border-start-start-radius:var(--ck-radius-xl);border-start-end-radius:var(--ck-radius-xl);background:var(--ck-sheet-grab-bg, var(--ck-color-surface-raised));touch-action:none}.ck-overlay-grab-bar{margin-block-start:var(--ck-space-2);inline-size:var(--ck-space-10);block-size:var(--ck-space-1);border-radius:var(--ck-radius-full);background:var(--ck-color-border)}@media(forced-colors:active){.ck-overlay{border:1px solid CanvasText}.ck-overlay-grab-bar{background:CanvasText}}}\n"]
572
+ }]
573
+ }],
574
+ propDecorators: {
575
+ grab: [{
576
+ type: i0.Input,
577
+ args: [{
578
+ isSignal: true,
579
+ alias: "grab",
580
+ required: false
581
+ }]
582
+ }],
583
+ outlet: [{
584
+ type: i0.ViewChild,
585
+ args: [i0.forwardRef(() => CdkPortalOutlet), { isSignal: true }]
586
+ }]
587
+ }
588
+ });
589
+ const VELOCITY_WINDOW = 100;
590
+ function shouldDismissSwipe(distance, height, velocity) {
591
+ if (distance <= 0 || height <= 0) return false;
592
+ return distance > height * .3333333333333333 || velocity >= .5 && distance >= 16;
593
+ }
594
+ function attachSheetSwipe(options) {
595
+ const { pane, panel, backdrop } = options;
596
+ const doc = pane.ownerDocument;
597
+ const now = () => doc.defaultView.performance.now();
598
+ let pointerId = null;
599
+ let startY = 0;
600
+ let height = 0;
601
+ let offset = 0;
602
+ let samples = [];
603
+ function setOffset(next) {
604
+ offset = Math.max(0, next);
605
+ panel.style.transform = `translateY(${offset}px)`;
606
+ backdrop.style.opacity = String(Math.max(0, 1 - offset / Math.max(height, 1)));
607
+ samples.push({
608
+ offset,
609
+ time: now()
610
+ });
611
+ }
612
+ function velocity() {
613
+ const current = now();
614
+ const recent = samples.filter((sample) => current - sample.time <= VELOCITY_WINDOW);
615
+ const first = recent[0];
616
+ const last = recent[recent.length - 1];
617
+ if (!first || !last) return 0;
618
+ return (last.offset - first.offset) / Math.max(1, current - first.time);
619
+ }
620
+ function stopTracking() {
621
+ pointerId = null;
622
+ doc.removeEventListener("pointermove", onMove);
623
+ doc.removeEventListener("pointerup", onUp);
624
+ doc.removeEventListener("pointercancel", onCancel);
625
+ }
626
+ function snapBack() {
627
+ const from = offset;
628
+ panel.style.transform = "";
629
+ backdrop.style.opacity = "";
630
+ offset = 0;
631
+ const duration = options.duration();
632
+ if (from > 0 && duration > 0 && typeof panel.animate === "function") {
633
+ const timing = {
634
+ duration,
635
+ easing: options.easing()
636
+ };
637
+ panel.animate([{ transform: `translateY(${from}px)` }, { transform: "none" }], timing);
638
+ backdrop.animate([{ opacity: String(Math.max(0, 1 - from / Math.max(height, 1))) }, { opacity: "1" }], timing);
639
+ }
640
+ }
641
+ function onDown(event) {
642
+ const target = event.target;
643
+ if (pointerId !== null || !event.isPrimary || event.button !== 0 || !(target instanceof Element) || !target.closest("[data-ck-sheet-grab]")) return;
644
+ pointerId = event.pointerId;
645
+ startY = event.clientY;
646
+ height = panel.getBoundingClientRect().height;
647
+ offset = 0;
648
+ samples = [{
649
+ offset: 0,
650
+ time: now()
651
+ }];
652
+ try {
653
+ target.setPointerCapture?.(event.pointerId);
654
+ } catch {}
655
+ doc.addEventListener("pointermove", onMove);
656
+ doc.addEventListener("pointerup", onUp);
657
+ doc.addEventListener("pointercancel", onCancel);
658
+ }
659
+ function onMove(event) {
660
+ if (event.pointerId === pointerId) setOffset(event.clientY - startY);
661
+ }
662
+ function onUp(event) {
663
+ if (event.pointerId !== pointerId) return;
664
+ setOffset(event.clientY - startY);
665
+ const dismiss = shouldDismissSwipe(offset, height, velocity());
666
+ stopTracking();
667
+ if (!options.onRelease(dismiss)) snapBack();
668
+ }
669
+ function onCancel(event) {
670
+ if (event.pointerId === pointerId) {
671
+ stopTracking();
672
+ snapBack();
673
+ }
674
+ }
675
+ pane.addEventListener("pointerdown", onDown);
676
+ return () => {
677
+ pane.removeEventListener("pointerdown", onDown);
678
+ stopTracking();
679
+ };
680
+ }
681
+ const DEFAULT_DURATION = 200;
682
+ const SHEET_MAX_HEIGHT = "calc(100dvh - env(safe-area-inset-top, 0px))";
683
+ const MODAL_MARGIN = "var(--ck-space-4, 1rem)";
684
+ function parseDuration(value) {
685
+ const match = /^\s*(-?[\d.]+)(ms|s)\s*$/.exec(value);
686
+ if (!match) return DEFAULT_DURATION;
687
+ const amount = Number(match[1]) * (match[2] === "s" ? 1e3 : 1);
688
+ return Number.isFinite(amount) && amount >= 0 ? amount : DEFAULT_DURATION;
689
+ }
690
+ var CkOverlayHost = class CkOverlayHost {
691
+ overlay = inject(Overlay);
692
+ overlayContainer = inject(OverlayContainer);
693
+ media = inject(CkMedia);
694
+ inert = inject(CkInert);
695
+ focusTraps = inject(CkFocusTrapFactory);
696
+ injector = inject(Injector);
697
+ document = inject(DOCUMENT);
698
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
699
+ stack = [];
700
+ entries = /* @__PURE__ */ new Set();
701
+ scrollStrategy = null;
702
+ scrollLocks = 0;
703
+ listening = false;
704
+ constructor() {
705
+ inject(DestroyRef).onDestroy(() => {
706
+ for (const entry of [...this.entries]) entry.destroy();
707
+ this.entries.clear();
708
+ this.stack.length = 0;
709
+ this.listen(false);
710
+ if (this.scrollLocks > 0) {
711
+ this.scrollLocks = 0;
712
+ this.scrollStrategy?.disable();
713
+ }
714
+ });
715
+ }
716
+ open(content, config = {}, injector) {
717
+ const requested = config.mode ?? "auto";
718
+ const mode = requested === "auto" ? this.media.sheet() ? "sheet" : "modal" : requested;
719
+ if (!this.isBrowser) return this.inertHandle(mode);
720
+ const sheet = mode === "sheet";
721
+ const dismissible = config.dismissible ?? true;
722
+ const container = this.overlayContainer.getContainerElement();
723
+ container.style.zIndex = "var(--ck-z-overlay, 1000)";
724
+ const overlayRef = this.overlay.create({
725
+ positionStrategy: sheet ? this.overlay.position().global().bottom("0").centerHorizontally() : this.overlay.position().global().centerHorizontally().centerVertically(),
726
+ scrollStrategy: this.overlay.scrollStrategies.noop(),
727
+ width: sheet ? "100%" : void 0,
728
+ height: sheet && config.fullHeight ? SHEET_MAX_HEIGHT : void 0,
729
+ maxWidth: sheet ? void 0 : `calc(100% - 2 * ${MODAL_MARGIN})`,
730
+ maxHeight: sheet ? SHEET_MAX_HEIGHT : `calc(100dvh - 2 * ${MODAL_MARGIN})`,
731
+ panelClass: [
732
+ "ck-overlay",
733
+ sheet ? "ck-overlay--sheet" : "ck-overlay--modal",
734
+ ...config.panelClass === void 0 ? [] : [config.panelClass].flat()
735
+ ],
736
+ disposeOnNavigation: false,
737
+ usePopover: false
738
+ });
739
+ const panel = overlayRef.overlayElement;
740
+ const host = overlayRef.hostElement;
741
+ let paneRef;
742
+ try {
743
+ paneRef = overlayRef.attach(new ComponentPortal(CkOverlayPane, null, this.injector));
744
+ paneRef.setInput("grab", sheet && dismissible);
745
+ paneRef.changeDetectorRef.detectChanges();
746
+ paneRef.instance.attach(this.contentPortal(content, paneRef.instance, injector));
747
+ } catch (error) {
748
+ overlayRef.dispose();
749
+ throw error;
750
+ }
751
+ panel.setAttribute("role", config.role ?? "dialog");
752
+ panel.setAttribute("aria-modal", "true");
753
+ panel.tabIndex = -1;
754
+ for (const [attribute, value] of [
755
+ ["aria-label", config.ariaLabel],
756
+ ["aria-labelledby", config.ariaLabelledBy],
757
+ ["aria-describedby", config.ariaDescribedBy]
758
+ ]) if (value) panel.setAttribute(attribute, value);
759
+ const backdrop = this.document.createElement("div");
760
+ backdrop.className = "ck-overlay-backdrop";
761
+ host.prepend(backdrop);
762
+ const opener = this.document.activeElement instanceof HTMLElement ? this.document.activeElement : null;
763
+ const trap = this.focusTraps.create(panel);
764
+ const activation = trap.activate(config.initialFocus);
765
+ const releaseInert = this.inert.hold([...this.inert.backgroundElements(container), ...this.stack.map((other) => other.overlayRef.hostElement)]);
766
+ this.lockScroll();
767
+ let resolveClosed = () => void 0;
768
+ const closed = new Promise((resolve) => resolveClosed = resolve);
769
+ let closing = null;
770
+ let released = false;
771
+ let finishedOnce = false;
772
+ let openAnimations = [];
773
+ const view = this.document.defaultView;
774
+ const motion = () => {
775
+ const style = view.getComputedStyle(panel);
776
+ return {
777
+ duration: this.media.reducedMotion() ? 0 : parseDuration(style.getPropertyValue("--ck-duration-normal")),
778
+ easing: style.getPropertyValue("--ck-ease-standard").trim() || "ease"
779
+ };
780
+ };
781
+ const play = (element, keyframes, fill) => {
782
+ const { duration, easing } = motion();
783
+ if (duration <= 0 || typeof element.animate !== "function") return null;
784
+ return element.animate(keyframes, {
785
+ duration,
786
+ easing,
787
+ fill
788
+ });
789
+ };
790
+ const finished = (animation) => animation ? animation.finished.catch(() => void 0) : Promise.resolve();
791
+ const entry = {
792
+ overlayRef,
793
+ dismissible,
794
+ state: "open",
795
+ openers: opener ? [opener] : [],
796
+ dismiss: (reason) => {
797
+ if (config.onDismissRequest) config.onDismissRequest(reason);
798
+ else close();
799
+ },
800
+ destroy: () => {
801
+ release();
802
+ finish();
803
+ }
804
+ };
805
+ this.entries.add(entry);
806
+ this.stack.push(entry);
807
+ this.listen(true);
808
+ const detachSwipe = sheet && dismissible ? attachSheetSwipe({
809
+ pane: paneRef.location.nativeElement,
810
+ panel,
811
+ backdrop,
812
+ duration: () => motion().duration,
813
+ easing: () => motion().easing,
814
+ onRelease: (dismissed) => {
815
+ if (dismissed) entry.dismiss("swipe");
816
+ return entry.state !== "open";
817
+ }
818
+ }) : () => void 0;
819
+ const onBackdropClick = () => {
820
+ if (entry.state === "open" && dismissible && this.stack.at(-1) === entry) entry.dismiss("backdrop");
821
+ };
822
+ backdrop.addEventListener("click", onBackdropClick);
823
+ const release = () => {
824
+ if (released) return;
825
+ released = true;
826
+ entry.state = "closing";
827
+ const index = this.stack.indexOf(entry);
828
+ this.stack.splice(index, 1);
829
+ this.stack[index]?.openers.unshift(...entry.openers);
830
+ detachSwipe();
831
+ backdrop.removeEventListener("click", onBackdropClick);
832
+ for (const animation of openAnimations) animation.cancel();
833
+ releaseInert();
834
+ host.inert = true;
835
+ trap.release();
836
+ this.restoreFocus(entry);
837
+ };
838
+ const finish = () => {
839
+ if (finishedOnce) return;
840
+ finishedOnce = true;
841
+ entry.state = "closed";
842
+ this.entries.delete(entry);
843
+ overlayRef.dispose();
844
+ backdrop.remove();
845
+ this.unlockScroll();
846
+ if (this.entries.size === 0) this.listen(false);
847
+ resolveClosed();
848
+ };
849
+ openAnimations = [play(panel, sheet ? [{ transform: "translateY(100%)" }, { transform: "none" }] : [{
850
+ opacity: 0,
851
+ transform: "scale(0.96)"
852
+ }, {
853
+ opacity: 1,
854
+ transform: "none"
855
+ }], "none"), play(backdrop, [{ opacity: 0 }, { opacity: 1 }], "none")].filter((animation) => animation !== null);
856
+ activation.then((focused) => {
857
+ if (entry.state === "open" && !focused) panel.focus({ preventScroll: true });
858
+ });
859
+ const opened = Promise.all([activation, ...openAnimations.map((animation) => finished(animation))]).then(() => void 0);
860
+ const close = () => {
861
+ if (closing) return closing;
862
+ release();
863
+ const animations = [play(panel, sheet ? [{ transform: "translateY(100%)" }] : [{
864
+ opacity: 0,
865
+ transform: "scale(0.96)"
866
+ }], "forwards"), play(backdrop, [{ opacity: 0 }], "forwards")];
867
+ closing = Promise.all(animations.map(finished)).then(finish);
868
+ return closing;
869
+ };
870
+ return {
871
+ mode,
872
+ panel,
873
+ opened,
874
+ closed,
875
+ close
876
+ };
877
+ }
878
+ restoreFocus(closed) {
879
+ const top = this.stack.at(-1);
880
+ const active = this.document.activeElement;
881
+ if (top?.overlayRef.overlayElement.contains(active)) return;
882
+ const openers = [...closed.openers].reverse().filter((candidate) => candidate.isConnected);
883
+ if (active && openers.includes(active)) return;
884
+ for (const candidate of openers) {
885
+ candidate.focus();
886
+ if (this.document.activeElement === candidate) return;
887
+ }
888
+ top?.overlayRef.overlayElement.focus({ preventScroll: true });
889
+ }
890
+ contentPortal(content, pane, injector) {
891
+ return content instanceof TemplateRef ? new TemplatePortal(content, pane.viewContainerRef, void 0, injector) : new ComponentPortal(content, null, injector ?? this.injector);
892
+ }
893
+ inertHandle(mode) {
894
+ return {
895
+ mode,
896
+ panel: this.document.createElement("div"),
897
+ opened: Promise.resolve(),
898
+ closed: Promise.resolve(),
899
+ close: () => Promise.resolve()
900
+ };
901
+ }
902
+ lockScroll() {
903
+ this.scrollStrategy ??= this.overlay.scrollStrategies.block();
904
+ if (this.scrollLocks++ === 0) this.scrollStrategy.enable();
905
+ }
906
+ unlockScroll() {
907
+ if (this.scrollLocks > 0 && --this.scrollLocks === 0) this.scrollStrategy?.disable();
908
+ }
909
+ listen(active) {
910
+ if (active === this.listening) return;
911
+ this.listening = active;
912
+ if (active) this.document.addEventListener("keydown", this.onKeydown);
913
+ else this.document.removeEventListener("keydown", this.onKeydown);
914
+ }
915
+ onKeydown = (event) => {
916
+ if (event.key !== "Escape" || event.defaultPrevented || event.isComposing) return;
917
+ const top = this.stack.at(-1);
918
+ if (top?.dismissible) {
919
+ event.preventDefault();
920
+ top.dismiss("escape");
921
+ }
922
+ };
923
+ static ɵfac = i0.ɵɵngDeclareFactory({
924
+ minVersion: "12.0.0",
925
+ version: "22.2.4",
926
+ ngImport: i0,
927
+ type: CkOverlayHost,
928
+ deps: [],
929
+ target: i0.ɵɵFactoryTarget.Injectable
930
+ });
931
+ static ɵprov = i0.ɵɵngDeclareInjectable({
932
+ minVersion: "12.0.0",
933
+ version: "22.2.4",
934
+ ngImport: i0,
935
+ type: CkOverlayHost,
936
+ providedIn: "root"
937
+ });
938
+ };
939
+ i0.ɵɵngDeclareClassMetadata({
940
+ minVersion: "12.0.0",
941
+ version: "22.2.4",
942
+ ngImport: i0,
943
+ type: CkOverlayHost,
944
+ decorators: [{
945
+ type: Injectable,
946
+ args: [{ providedIn: "root" }]
947
+ }],
948
+ ctorParameters: () => []
949
+ });
950
+ function hasAccessibleName(element, sources) {
951
+ const attribute = (name) => (element.getAttribute(name) ?? "").trim() !== "";
952
+ if (attribute("aria-label") || sources.title && attribute("title")) return true;
953
+ if (sources.text && visibleText(element) !== "") return true;
954
+ const named = (node) => (node?.textContent ?? "").trim() !== "";
955
+ const labels = element.labels;
956
+ return (element.getAttribute("aria-labelledby") ?? "").split(/\s+/).some((id) => id !== "" && named(element.ownerDocument.getElementById(id))) || sources.labels === true && Array.from(labels ?? []).some(named);
957
+ }
958
+ function visibleText(node) {
959
+ if (node.nodeType === Node.TEXT_NODE) return (node.textContent ?? "").trim();
960
+ if (node instanceof Element && (node.getAttribute("aria-hidden") === "true" || node.hasAttribute("hidden"))) return "";
961
+ return Array.from(node.childNodes, visibleText).join("");
962
+ }
963
+ export { CkAnnouncer, CkFocusTrapFactory, CkIcon, CkInert, CkMedia, CkOverlayHost, CkValueControl, createCkId, hasAccessibleName, provideCkValueAccessor };
240
964
 
241
965
  //# sourceMappingURL=ckui-core-internal.mjs.map