@cngx/common 0.0.1-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/a11y/README.md +77 -0
  4. package/card/README.md +79 -0
  5. package/chart/README.md +31 -0
  6. package/data/README.md +883 -0
  7. package/dialog/README.md +84 -0
  8. package/display/README.md +30 -0
  9. package/fesm2022/cngx-common-a11y.mjs +1260 -0
  10. package/fesm2022/cngx-common-a11y.mjs.map +1 -0
  11. package/fesm2022/cngx-common-card.mjs +765 -0
  12. package/fesm2022/cngx-common-card.mjs.map +1 -0
  13. package/fesm2022/cngx-common-chart.mjs +2943 -0
  14. package/fesm2022/cngx-common-chart.mjs.map +1 -0
  15. package/fesm2022/cngx-common-data.mjs +2886 -0
  16. package/fesm2022/cngx-common-data.mjs.map +1 -0
  17. package/fesm2022/cngx-common-dialog.mjs +1366 -0
  18. package/fesm2022/cngx-common-dialog.mjs.map +1 -0
  19. package/fesm2022/cngx-common-display.mjs +1603 -0
  20. package/fesm2022/cngx-common-display.mjs.map +1 -0
  21. package/fesm2022/cngx-common-interactive.mjs +8185 -0
  22. package/fesm2022/cngx-common-interactive.mjs.map +1 -0
  23. package/fesm2022/cngx-common-layout.mjs +1335 -0
  24. package/fesm2022/cngx-common-layout.mjs.map +1 -0
  25. package/fesm2022/cngx-common-popover.mjs +1200 -0
  26. package/fesm2022/cngx-common-popover.mjs.map +1 -0
  27. package/fesm2022/cngx-common-stepper.mjs +1350 -0
  28. package/fesm2022/cngx-common-stepper.mjs.map +1 -0
  29. package/fesm2022/cngx-common-tabs.mjs +1551 -0
  30. package/fesm2022/cngx-common-tabs.mjs.map +1 -0
  31. package/fesm2022/cngx-common.mjs +34 -0
  32. package/fesm2022/cngx-common.mjs.map +1 -0
  33. package/interactive/README.md +211 -0
  34. package/layout/README.md +117 -0
  35. package/package.json +100 -0
  36. package/popover/README.md +218 -0
  37. package/stepper/README.md +102 -0
  38. package/tabs/README.md +32 -0
  39. package/types/cngx-common-a11y.d.ts +616 -0
  40. package/types/cngx-common-card.d.ts +413 -0
  41. package/types/cngx-common-chart.d.ts +1081 -0
  42. package/types/cngx-common-data.d.ts +1460 -0
  43. package/types/cngx-common-dialog.d.ts +772 -0
  44. package/types/cngx-common-display.d.ts +1136 -0
  45. package/types/cngx-common-interactive.d.ts +5013 -0
  46. package/types/cngx-common-layout.d.ts +737 -0
  47. package/types/cngx-common-popover.d.ts +520 -0
  48. package/types/cngx-common-stepper.d.ts +982 -0
  49. package/types/cngx-common-tabs.d.ts +1237 -0
  50. package/types/cngx-common.d.ts +13 -0
@@ -0,0 +1,1366 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, signal, computed, Injectable, inject, ElementRef, Directive, Renderer2, DestroyRef, contentChild, input, effect, isDevMode, viewChild, ViewContainerRef, ChangeDetectionStrategy, Component, ApplicationRef, EnvironmentInjector, Injector, createComponent } from '@angular/core';
3
+ import { DOCUMENT } from '@angular/common';
4
+ import { nextUid, buildAsyncStateView, hasTransition, onTransitionDone } from '@cngx/core/utils';
5
+ import { isObservable, firstValueFrom, filter, take, map } from 'rxjs';
6
+ import { toObservable } from '@angular/core/rxjs-interop';
7
+ import { CngxSwipeDismiss } from '@cngx/common/interactive';
8
+
9
+ /** Injection token to access the nearest `DialogRef` from inside a dialog. */
10
+ const DIALOG_REF = new InjectionToken('CngxDialogRef');
11
+
12
+ /**
13
+ * Tracks open dialog instances as a stack for backdrop management.
14
+ *
15
+ * Provided in root — always available, no manual provider setup needed.
16
+ * When multiple modal dialogs are stacked, only the topmost shows
17
+ * its `::backdrop`. Each `CngxDialog` reads `isTopmost` from this service
18
+ * to control `--cngx-dialog-backdrop-opacity`.
19
+ */
20
+ class CngxDialogStack {
21
+ stackState = signal([], ...(ngDevMode ? [{ debugName: "stackState" }] : /* istanbul ignore next */ []));
22
+ /** Readonly snapshot of the current stack (bottom → top). */
23
+ stack = this.stackState.asReadonly();
24
+ /** ID of the topmost (most recently opened) dialog, or `null`. */
25
+ topmost = computed(() => this.stackState().at(-1) ?? null, ...(ngDevMode ? [{ debugName: "topmost" }] : /* istanbul ignore next */ []));
26
+ /** Push a dialog ID onto the stack (called on open). */
27
+ push(id) {
28
+ this.stackState.update((s) => [...s, id]);
29
+ }
30
+ /** Remove a dialog ID from the stack (called on close). */
31
+ pop(id) {
32
+ this.stackState.update((s) => s.filter((x) => x !== id));
33
+ }
34
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogStack, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
35
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogStack, providedIn: 'root' });
36
+ }
37
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogStack, decorators: [{
38
+ type: Injectable,
39
+ args: [{ providedIn: 'root' }]
40
+ }] });
41
+ /**
42
+ * Provide a scoped `CngxDialogStack` instance for nested dialog backdrop management.
43
+ *
44
+ * By default, `CngxDialogStack` is `providedIn: 'root'`, so all dialogs share
45
+ * one stack. Call `provideDialogStack()` in a component's `providers` array to
46
+ * create an isolated stack scope (e.g., for a sub-application or dialog group).
47
+ *
48
+ * ```typescript
49
+ * @Component({
50
+ * providers: [provideDialogStack()],
51
+ * })
52
+ * export class NestedDialogHost { }
53
+ * ```
54
+ */
55
+ function provideDialogStack() {
56
+ return CngxDialogStack;
57
+ }
58
+
59
+ /**
60
+ * Marks an element as the dialog's title for ARIA labelling.
61
+ *
62
+ * Automatically generates a deterministic ID and registers with the
63
+ * parent `CngxDialog` for `aria-labelledby`. The title text is also
64
+ * announced via `aria-live` when the dialog transitions to `'open'`.
65
+ *
66
+ * ```html
67
+ * <dialog cngxDialog>
68
+ * <h2 cngxDialogTitle>Confirm Delete</h2>
69
+ * …
70
+ * </dialog>
71
+ * ```
72
+ */
73
+ class CngxDialogTitle {
74
+ elRef = inject((ElementRef));
75
+ dialogRef = inject(DIALOG_REF, { optional: true });
76
+ /**
77
+ * Auto-generated unique ID bound to the host `[id]` attribute.
78
+ *
79
+ * Used by `CngxDialog` for `aria-labelledby`. When a parent `CngxDialog`
80
+ * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-title`).
81
+ */
82
+ id = signal(nextUid('cngx-dialog-title'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
83
+ /**
84
+ * Text content of the title element.
85
+ *
86
+ * Read by `CngxDialog` on open to announce the dialog title via
87
+ * an `aria-live` region for screen readers.
88
+ */
89
+ textContent = computed(() => this.elRef.nativeElement.textContent?.trim() ?? '', ...(ngDevMode ? [{ debugName: "textContent" }] : /* istanbul ignore next */ []));
90
+ constructor() {
91
+ if (this.dialogRef) {
92
+ this.id.set(`${this.dialogRef.id()}-title`);
93
+ }
94
+ }
95
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogTitle, deps: [], target: i0.ɵɵFactoryTarget.Directive });
96
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxDialogTitle, isStandalone: true, selector: "[cngxDialogTitle]", host: { properties: { "id": "id()" } }, exportAs: ["cngxDialogTitle"], ngImport: i0 });
97
+ }
98
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogTitle, decorators: [{
99
+ type: Directive,
100
+ args: [{
101
+ selector: '[cngxDialogTitle]',
102
+ exportAs: 'cngxDialogTitle',
103
+ standalone: true,
104
+ host: {
105
+ '[id]': 'id()',
106
+ },
107
+ }]
108
+ }], ctorParameters: () => [] });
109
+
110
+ /**
111
+ * Marks an element as the dialog's description for ARIA.
112
+ *
113
+ * Automatically generates a deterministic ID and registers with the
114
+ * parent `CngxDialog` for `aria-describedby`.
115
+ *
116
+ * ```html
117
+ * <dialog cngxDialog>
118
+ * <h2 cngxDialogTitle>Delete item?</h2>
119
+ * <p cngxDialogDescription>This action cannot be undone.</p>
120
+ * …
121
+ * </dialog>
122
+ * ```
123
+ */
124
+ class CngxDialogDescription {
125
+ dialogRef = inject(DIALOG_REF, { optional: true });
126
+ /**
127
+ * Auto-generated unique ID bound to the host `[id]` attribute.
128
+ *
129
+ * Used by `CngxDialog` for `aria-describedby`. When a parent `CngxDialog`
130
+ * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-desc`).
131
+ */
132
+ id = signal(nextUid('cngx-dialog-desc'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
133
+ constructor() {
134
+ if (this.dialogRef) {
135
+ this.id.set(`${this.dialogRef.id()}-desc`);
136
+ }
137
+ }
138
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive });
139
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxDialogDescription, isStandalone: true, selector: "[cngxDialogDescription]", host: { properties: { "id": "id()" } }, exportAs: ["cngxDialogDescription"], ngImport: i0 });
140
+ }
141
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDescription, decorators: [{
142
+ type: Directive,
143
+ args: [{
144
+ selector: '[cngxDialogDescription]',
145
+ exportAs: 'cngxDialogDescription',
146
+ standalone: true,
147
+ host: {
148
+ '[id]': 'id()',
149
+ },
150
+ }]
151
+ }], ctorParameters: () => [] });
152
+
153
+ /** Ref-count map for scroll lock — one lock per document root, shared across stacked modals. */
154
+ const lockCounts = new WeakMap();
155
+ /** Acquire a scroll lock on the document root, preserving prior overflow styles. */
156
+ function acquireScrollLock(html) {
157
+ const count = lockCounts.get(html) ?? 0;
158
+ if (count === 0) {
159
+ html.dataset['cngxPrevOverflow'] = html.style.overflow;
160
+ html.dataset['cngxPrevScrollbarGutter'] = html.style.scrollbarGutter;
161
+ html.style.overflow = 'hidden';
162
+ html.style.scrollbarGutter = 'stable';
163
+ }
164
+ lockCounts.set(html, count + 1);
165
+ }
166
+ /** Release a scroll lock. Restores prior overflow styles when the count reaches zero. */
167
+ function releaseScrollLock(html) {
168
+ const count = lockCounts.get(html) ?? 0;
169
+ if (count <= 1) {
170
+ html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
171
+ html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
172
+ delete html.dataset['cngxPrevOverflow'];
173
+ delete html.dataset['cngxPrevScrollbarGutter'];
174
+ lockCounts.set(html, 0);
175
+ }
176
+ else {
177
+ lockCounts.set(html, count - 1);
178
+ }
179
+ }
180
+ /**
181
+ * Signal-driven state machine for native `<dialog>`.
182
+ *
183
+ * Wraps the browser's `<dialog>` element with reactive state, typed results,
184
+ * deterministic focus management, and full ARIA communication. Supports both
185
+ * modal and non-modal modes, CSS transition-aware open/close lifecycle, and
186
+ * ref-counted scroll locking for stacked modals.
187
+ *
188
+ * The directive implements `DialogRef<T>` and provides itself via `DIALOG_REF`,
189
+ * so child directives (`CngxDialogTitle`, `CngxDialogClose`, etc.) can inject
190
+ * the reference without explicit wiring.
191
+ *
192
+ * State lifecycle: `closed` -> `opening` -> `open` -> `closing` -> `closed`.
193
+ * CSS classes `cngx-dialog--opening`, `cngx-dialog--open`, and
194
+ * `cngx-dialog--closing` are applied to the host for transition hooks.
195
+ *
196
+ * ### Declarative (template-driven)
197
+ * ```html
198
+ * <dialog cngxDialog #dlg="cngxDialog">
199
+ * <h2 cngxDialogTitle>Delete item?</h2>
200
+ * <p cngxDialogDescription>This cannot be undone.</p>
201
+ * <button [cngxDialogClose]="false">Cancel</button>
202
+ * <button [cngxDialogClose]="true">Delete</button>
203
+ * </dialog>
204
+ * <button (click)="dlg.open()">Delete</button>
205
+ *
206
+ * @if (dlg.lifecycle() === 'closed' && dlg.result() === true) {
207
+ * <p>Item deleted.</p>
208
+ * }
209
+ * ```
210
+ *
211
+ * ### Programmatic (via CngxDialogOpener)
212
+ * ```typescript
213
+ * const ref = this.dialogService.open<boolean>(ConfirmDialog, {
214
+ * data: { message: 'Delete item?' },
215
+ * });
216
+ *
217
+ * ref.afterClosed().subscribe(result => {
218
+ * if (result === true) this.delete();
219
+ * });
220
+ * ```
221
+ *
222
+ * ### Non-modal dialog
223
+ * ```html
224
+ * <dialog cngxDialog [modal]="false" #tooltip="cngxDialog">
225
+ * <p>Inline tooltip content</p>
226
+ * </dialog>
227
+ * ```
228
+ *
229
+ * ### Custom focus target
230
+ * ```html
231
+ * <dialog cngxDialog [autoFocus]="'#name-input'">
232
+ * <input id="name-input" />
233
+ * </dialog>
234
+ * ```
235
+ */
236
+ class CngxDialog {
237
+ elRef = inject(ElementRef);
238
+ doc = inject(DOCUMENT);
239
+ renderer = inject(Renderer2);
240
+ destroyRef = inject(DestroyRef);
241
+ dialogStack = inject(CngxDialogStack);
242
+ titleDirective = contentChild(CngxDialogTitle, ...(ngDevMode ? [{ debugName: "titleDirective" }] : /* istanbul ignore next */ []));
243
+ descriptionDirective = contentChild(CngxDialogDescription, ...(ngDevMode ? [{ debugName: "descriptionDirective" }] : /* istanbul ignore next */ []));
244
+ /**
245
+ * Whether the dialog opens as modal (`showModal()`) or non-modal (`show()`).
246
+ *
247
+ * Modal dialogs block interaction with the rest of the page, acquire a
248
+ * scroll lock, and participate in the `CngxDialogStack` for backdrop
249
+ * management. Non-modal dialogs do not.
250
+ *
251
+ * @defaultValue `true`
252
+ */
253
+ modal = input(true, ...(ngDevMode ? [{ debugName: "modal" }] : /* istanbul ignore next */ []));
254
+ /**
255
+ * Whether clicking the backdrop dismisses the dialog.
256
+ *
257
+ * Only applies to modal dialogs. When `true`, a click on the
258
+ * `::backdrop` pseudo-element calls `dismiss()`.
259
+ *
260
+ * @defaultValue `true`
261
+ */
262
+ closeOnBackdropClick = input(true, ...(ngDevMode ? [{ debugName: "closeOnBackdropClick" }] : /* istanbul ignore next */ []));
263
+ /**
264
+ * Whether pressing Escape dismisses the dialog.
265
+ *
266
+ * Only applies to modal dialogs. The native `cancel` event is always
267
+ * prevented; this input controls whether `dismiss()` is called in response.
268
+ *
269
+ * @defaultValue `true`
270
+ */
271
+ closeOnEscape = input(true, ...(ngDevMode ? [{ debugName: "closeOnEscape" }] : /* istanbul ignore next */ []));
272
+ /**
273
+ * Focus strategy applied after the dialog transitions to `'open'`.
274
+ *
275
+ * Only applies to modal dialogs.
276
+ *
277
+ * - `'first-focusable'` -- focus the first `[autofocus]` element, or the
278
+ * first focusable element in DOM order (default)
279
+ * - `'none'` -- do not move focus
280
+ * - Any CSS selector string -- focus the first element matching the selector
281
+ *
282
+ * @defaultValue `'first-focusable'`
283
+ */
284
+ autoFocus = input('first-focusable', ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
285
+ /**
286
+ * Fallback element to focus when the original trigger element has been
287
+ * removed from the DOM by the time the dialog closes.
288
+ *
289
+ * When not set and the trigger is gone, no focus return occurs.
290
+ */
291
+ focusFallback = input(undefined, ...(ngDevMode ? [{ debugName: "focusFallback" }] : /* istanbul ignore next */ []));
292
+ /**
293
+ * Bind an async state — drives pending (aria-busy, prevents close) and
294
+ * error from a single source. When set, takes precedence over the
295
+ * `[error]` boolean input and `[submitAction]`.
296
+ *
297
+ * When `state.status()` is `'pending'`, the dialog prevents close/dismiss
298
+ * and applies `aria-busy`. When `state.status()` is `'error'`, the dialog
299
+ * applies `cngx-dialog--error` and announces the error via the SR live region.
300
+ */
301
+ state = input(undefined, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
302
+ /**
303
+ * Async action to execute when `close(value)` is called.
304
+ *
305
+ * Receives the close value as parameter. On success, the dialog auto-closes.
306
+ * On error, the dialog stays open with `cngx-dialog--error` and the error
307
+ * is announced to screen readers.
308
+ *
309
+ * When set, `close(value)` no longer closes immediately — it enters a
310
+ * `submitting` phase (`isPending() = true`, `aria-busy`, close blocked).
311
+ *
312
+ * The submit lifecycle is exposed via `submitState: CngxAsyncState<unknown>`.
313
+ * Ignored when `[state]` input is also set (external state takes precedence).
314
+ */
315
+ submitAction = input(undefined, ...(ngDevMode ? [{ debugName: "submitAction" }] : /* istanbul ignore next */ []));
316
+ /**
317
+ * Whether the dialog is in an error state. Fallback when neither `[state]`
318
+ * nor `[submitAction]` is set.
319
+ *
320
+ * When `true`, applies the `cngx-dialog--error` CSS class on the host.
321
+ * Use this to communicate form submission failures or other error
322
+ * conditions visually.
323
+ *
324
+ * Pair with `cngx-form-errors` (`role="alert"`) inside the dialog for
325
+ * WCAG-compliant error announcements.
326
+ *
327
+ * @defaultValue `false`
328
+ */
329
+ error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
330
+ lifecycleSignal = signal('closed', ...(ngDevMode ? [{ debugName: "lifecycleSignal" }] : /* istanbul ignore next */ []));
331
+ resultSignal = signal(undefined, ...(ngDevMode ? [{ debugName: "resultSignal" }] : /* istanbul ignore next */ []));
332
+ idSignal = signal(nextUid('cngx-dialog'), ...(ngDevMode ? [{ debugName: "idSignal" }] : /* istanbul ignore next */ []));
333
+ triggerElement = signal(null, ...(ngDevMode ? [{ debugName: "triggerElement" }] : /* istanbul ignore next */ []));
334
+ /**
335
+ * Current lifecycle state of the dialog.
336
+ *
337
+ * Possible values: `'closed'`, `'opening'`, `'open'`, `'closing'`.
338
+ */
339
+ lifecycle = this.lifecycleSignal.asReadonly();
340
+ /**
341
+ * The typed result of the dialog.
342
+ *
343
+ * - `undefined` before close (reset on each `open()` call)
344
+ * - `'dismissed'` when dismissed via Escape or backdrop click
345
+ * - `T` when closed with an explicit value via `close(value)`
346
+ */
347
+ result = this.resultSignal.asReadonly();
348
+ /** Unique auto-generated ID for this dialog instance. Used for ARIA and stack tracking. */
349
+ id = this.idSignal.asReadonly();
350
+ submitStatusState = signal('idle', ...(ngDevMode ? [{ debugName: "submitStatusState" }] : /* istanbul ignore next */ []));
351
+ submitErrorState = signal(undefined, ...(ngDevMode ? [{ debugName: "submitErrorState" }] : /* istanbul ignore next */ []));
352
+ /**
353
+ * Async state of the submit channel.
354
+ *
355
+ * Populated when `[submitAction]` is set. Tracks `idle` -> `pending` ->
356
+ * `success`/`error`. When `submitAction` is not set, remains at `'idle'`.
357
+ *
358
+ * Bind to any state consumer: `<cngx-alert [state]="dlg.submitState" />`.
359
+ */
360
+ submitState = buildAsyncStateView({
361
+ status: this.submitStatusState.asReadonly(),
362
+ data: computed(() => undefined),
363
+ error: this.submitErrorState.asReadonly(),
364
+ });
365
+ /**
366
+ * `true` when any async operation is pending. Blocks close/dismiss and sets `aria-busy`.
367
+ *
368
+ * External `[state]` short-circuits — when set, `submitAction` is ignored by the
369
+ * `close()` guard (`action && !this.state()`), so `submitStatusState` stays `'idle'`.
370
+ */
371
+ isPending = computed(() => {
372
+ const ext = this.state();
373
+ if (ext) {
374
+ return ext.isPending();
375
+ }
376
+ return this.submitStatusState() === 'pending';
377
+ }, ...(ngDevMode ? [{ debugName: "isPending" }] : /* istanbul ignore next */ []));
378
+ /**
379
+ * Resolved error — external `[state]` takes precedence over submit state,
380
+ * which takes precedence over the boolean `[error]` input.
381
+ */
382
+ effectiveError = computed(() => {
383
+ const ext = this.state();
384
+ if (ext) {
385
+ return !!ext.error();
386
+ }
387
+ // Use !== undefined to catch falsy error values (0, '', false)
388
+ if (this.submitErrorState() !== undefined) {
389
+ return true;
390
+ }
391
+ return this.error();
392
+ }, ...(ngDevMode ? [{ debugName: "effectiveError" }] : /* istanbul ignore next */ []));
393
+ isOpening = computed(() => this.lifecycleSignal() === 'opening', ...(ngDevMode ? [{ debugName: "isOpening" }] : /* istanbul ignore next */ []));
394
+ isOpen = computed(() => this.lifecycleSignal() === 'open', ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
395
+ isClosing = computed(() => this.lifecycleSignal() === 'closing', ...(ngDevMode ? [{ debugName: "isClosing" }] : /* istanbul ignore next */ []));
396
+ ariaModal = computed(() => this.modal() && this.lifecycleSignal() !== 'closed' ? 'true' : null, ...(ngDevMode ? [{ debugName: "ariaModal" }] : /* istanbul ignore next */ []));
397
+ ariaLabelledBy = computed(() => this.titleDirective()?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
398
+ ariaDescribedBy = computed(() => this.descriptionDirective()?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaDescribedBy" }] : /* istanbul ignore next */ []));
399
+ backdropOpacity = computed(() => this.dialogStack.topmost() === this.idSignal() ? null : '0', ...(ngDevMode ? [{ debugName: "backdropOpacity" }] : /* istanbul ignore next */ []));
400
+ liveRegion = null;
401
+ constructor() {
402
+ this.createLiveRegion();
403
+ effect(() => {
404
+ if (this.lifecycleSignal() === 'open') {
405
+ const titleText = this.titleDirective()?.textContent() ?? '';
406
+ if (titleText && this.liveRegion) {
407
+ this.liveRegion.textContent = titleText;
408
+ // Clear after one frame so subsequent opens re-announce
409
+ requestAnimationFrame(() => {
410
+ if (this.liveRegion) {
411
+ this.liveRegion.textContent = '';
412
+ }
413
+ });
414
+ }
415
+ }
416
+ });
417
+ effect(() => {
418
+ if (this.effectiveError() && this.liveRegion) {
419
+ const errMsg = this.state()?.error() ?? this.submitErrorState();
420
+ this.liveRegion.textContent = typeof errMsg === 'string' ? errMsg : 'An error occurred';
421
+ }
422
+ });
423
+ this.destroyRef.onDestroy(() => {
424
+ if (this.lifecycleSignal() !== 'closed') {
425
+ this.finalize();
426
+ }
427
+ });
428
+ }
429
+ /**
430
+ * Open the dialog.
431
+ *
432
+ * Resets the result from any previous open/close cycle, stores the
433
+ * currently focused element for focus return, and calls the native
434
+ * `showModal()` or `show()` depending on the `modal` input.
435
+ *
436
+ * No-op if the dialog is already open or in a transition state.
437
+ */
438
+ open() {
439
+ if (this.lifecycleSignal() !== 'closed') {
440
+ return;
441
+ }
442
+ const dialog = this.dialogElement;
443
+ // Reset result and submit state from previous cycle
444
+ this.resultSignal.set(undefined);
445
+ this.submitStatusState.set('idle');
446
+ this.submitErrorState.set(undefined);
447
+ // Store trigger element for focus return
448
+ this.triggerElement.set(this.doc.activeElement);
449
+ this.lifecycleSignal.set('opening');
450
+ if (this.modal()) {
451
+ dialog.showModal();
452
+ this.acquireScrollLock();
453
+ this.dialogStack.push(this.idSignal());
454
+ }
455
+ else {
456
+ dialog.show();
457
+ this.warnNonModalA11y();
458
+ }
459
+ // Transition to open after browser paints the opening class
460
+ requestAnimationFrame(() => {
461
+ if (this.lifecycleSignal() !== 'opening') {
462
+ return;
463
+ }
464
+ this.lifecycleSignal.set('open');
465
+ this.moveFocus();
466
+ });
467
+ }
468
+ /**
469
+ * Close the dialog with a typed result.
470
+ *
471
+ * When `[submitAction]` is set and `[state]` is not set, executes the action
472
+ * with `value` before closing. The dialog enters a submitting phase
473
+ * (`isPending() = true`) — on success it auto-closes, on error it stays open.
474
+ *
475
+ * When `[submitAction]` is not set (or `[state]` overrides), closes immediately.
476
+ *
477
+ * No-op if the dialog is not in the `'open'` or `'opening'` state, or if
478
+ * already pending.
479
+ *
480
+ * @param value - The typed result to deliver to consumers.
481
+ */
482
+ close(value) {
483
+ if (this.lifecycleSignal() !== 'open' && this.lifecycleSignal() !== 'opening') {
484
+ return;
485
+ }
486
+ if (this.isPending()) {
487
+ return;
488
+ }
489
+ const action = this.submitAction();
490
+ // External [state] takes full precedence — submitAction is ignored
491
+ if (action && !this.state()) {
492
+ void this.executeSubmit(action, value);
493
+ }
494
+ else {
495
+ this.resultSignal.set(value);
496
+ this.startClosing();
497
+ }
498
+ }
499
+ /**
500
+ * Dismiss the dialog without a typed result.
501
+ *
502
+ * Sets `result` to `'dismissed'`, then initiates the closing transition.
503
+ * Typically triggered by Escape key or backdrop click, but can be called
504
+ * directly. No-op if the dialog is not in the `'open'` or `'opening'` state.
505
+ */
506
+ dismiss() {
507
+ if (this.lifecycleSignal() !== 'open' && this.lifecycleSignal() !== 'opening') {
508
+ return;
509
+ }
510
+ if (this.isPending()) {
511
+ return;
512
+ }
513
+ this.resultSignal.set('dismissed');
514
+ this.startClosing();
515
+ }
516
+ async executeSubmit(action, value) {
517
+ this.submitStatusState.set('pending');
518
+ this.submitErrorState.set(undefined);
519
+ try {
520
+ const result$ = action(value);
521
+ const promise = isObservable(result$)
522
+ ? firstValueFrom(result$, { defaultValue: undefined })
523
+ : result$;
524
+ await promise;
525
+ // Guard against post-destroy signal writes
526
+ if (this.lifecycleSignal() === 'closed') {
527
+ return;
528
+ }
529
+ this.submitStatusState.set('success');
530
+ this.resultSignal.set(value);
531
+ this.startClosing();
532
+ }
533
+ catch (err) {
534
+ // Guard against post-destroy signal writes
535
+ if (this.lifecycleSignal() === 'closed') {
536
+ return;
537
+ }
538
+ this.submitStatusState.set('error');
539
+ this.submitErrorState.set(err);
540
+ }
541
+ }
542
+ handleCancel(event) {
543
+ event.preventDefault();
544
+ if (this.closeOnEscape() && this.modal()) {
545
+ this.dismiss();
546
+ }
547
+ }
548
+ handleClick(event) {
549
+ if (!this.modal() || !this.closeOnBackdropClick()) {
550
+ return;
551
+ }
552
+ if (this.lifecycleSignal() !== 'open') {
553
+ return;
554
+ }
555
+ // Detect backdrop click: click coordinates outside dialog content rect
556
+ const rect = this.dialogElement.getBoundingClientRect();
557
+ if (event.clientX < rect.left ||
558
+ event.clientX > rect.right ||
559
+ event.clientY < rect.top ||
560
+ event.clientY > rect.bottom) {
561
+ this.dismiss();
562
+ }
563
+ }
564
+ get dialogElement() {
565
+ return this.elRef.nativeElement;
566
+ }
567
+ startClosing() {
568
+ if (hasTransition(this.dialogElement)) {
569
+ this.lifecycleSignal.set('closing');
570
+ onTransitionDone(this.dialogElement, () => this.finalize());
571
+ }
572
+ else {
573
+ this.finalize();
574
+ }
575
+ }
576
+ finalize() {
577
+ const dialog = this.dialogElement;
578
+ if (dialog.open) {
579
+ dialog.close();
580
+ }
581
+ if (this.modal()) {
582
+ this.releaseScrollLock();
583
+ this.dialogStack.pop(this.idSignal());
584
+ }
585
+ this.lifecycleSignal.set('closed');
586
+ this.returnFocus();
587
+ }
588
+ moveFocus() {
589
+ if (!this.modal()) {
590
+ return;
591
+ }
592
+ const strategy = this.autoFocus();
593
+ const dialog = this.dialogElement;
594
+ if (strategy === 'none') {
595
+ return;
596
+ }
597
+ if (strategy === 'first-focusable') {
598
+ // Native dialog with autofocus attribute works; otherwise focus first focusable
599
+ const autofocusEl = dialog.querySelector('[autofocus]');
600
+ if (autofocusEl) {
601
+ autofocusEl.focus();
602
+ return;
603
+ }
604
+ const focusable = dialog.querySelector('a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])');
605
+ focusable?.focus();
606
+ }
607
+ else {
608
+ const target = dialog.querySelector(strategy);
609
+ target?.focus();
610
+ }
611
+ }
612
+ returnFocus() {
613
+ const trigger = this.triggerElement();
614
+ if (trigger?.isConnected) {
615
+ trigger.focus();
616
+ }
617
+ else {
618
+ const fallback = this.focusFallback();
619
+ fallback?.focus();
620
+ }
621
+ this.triggerElement.set(null);
622
+ }
623
+ createLiveRegion() {
624
+ const span = this.renderer.createElement('span');
625
+ span.setAttribute('aria-live', 'polite');
626
+ span.setAttribute('aria-atomic', 'true');
627
+ span.className = 'cngx-sr-only';
628
+ span.style.position = 'absolute';
629
+ span.style.width = '1px';
630
+ span.style.height = '1px';
631
+ span.style.padding = '0';
632
+ span.style.margin = '-1px';
633
+ span.style.overflow = 'hidden';
634
+ span.style.clip = 'rect(0, 0, 0, 0)';
635
+ span.style.whiteSpace = 'nowrap';
636
+ span.style.border = '0';
637
+ this.renderer.appendChild(this.dialogElement, span);
638
+ this.liveRegion = span;
639
+ }
640
+ acquireScrollLock() {
641
+ acquireScrollLock(this.doc.documentElement);
642
+ }
643
+ releaseScrollLock() {
644
+ releaseScrollLock(this.doc.documentElement);
645
+ }
646
+ warnNonModalA11y() {
647
+ if (!isDevMode()) {
648
+ return;
649
+ }
650
+ // Non-modal dialogs are silent to SR. Warn if no aria-live sibling found.
651
+ const trigger = this.triggerElement();
652
+ if (trigger) {
653
+ const parent = trigger.parentElement;
654
+ if (parent && !parent.querySelector('[aria-live]')) {
655
+ console.warn(`CngxDialog [${this.idSignal()}]: Non-modal dialog opened without an ` +
656
+ '`aria-live` region near the trigger. Screen reader users will not ' +
657
+ 'be notified that the dialog appeared. Add `aria-live="polite"` to a ' +
658
+ 'sibling element that announces the dialog presence.');
659
+ }
660
+ }
661
+ }
662
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialog, deps: [], target: i0.ɵɵFactoryTarget.Directive });
663
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialog, isStandalone: true, selector: "dialog[cngxDialog]", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null }, focusFallback: { classPropertyName: "focusFallback", publicName: "focusFallback", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, submitAction: { classPropertyName: "submitAction", publicName: "submitAction", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "cancel": "handleCancel($event)", "click": "handleClick($event)" }, properties: { "class.cngx-dialog--opening": "isOpening()", "class.cngx-dialog--open": "isOpen()", "class.cngx-dialog--closing": "isClosing()", "class.cngx-dialog--modal": "modal()", "attr.aria-modal": "ariaModal()", "attr.aria-labelledby": "ariaLabelledBy()", "attr.aria-describedby": "ariaDescribedBy()", "class.cngx-dialog--pending": "isPending()", "attr.aria-busy": "isPending() || null", "class.cngx-dialog--error": "effectiveError()", "style.--cngx-dialog-backdrop-opacity": "backdropOpacity()" } }, providers: [{ provide: DIALOG_REF, useExisting: CngxDialog }], queries: [{ propertyName: "titleDirective", first: true, predicate: CngxDialogTitle, descendants: true, isSignal: true }, { propertyName: "descriptionDirective", first: true, predicate: CngxDialogDescription, descendants: true, isSignal: true }], exportAs: ["cngxDialog"], ngImport: i0 });
664
+ }
665
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialog, decorators: [{
666
+ type: Directive,
667
+ args: [{
668
+ selector: 'dialog[cngxDialog]',
669
+ exportAs: 'cngxDialog',
670
+ standalone: true,
671
+ providers: [{ provide: DIALOG_REF, useExisting: CngxDialog }],
672
+ host: {
673
+ '[class.cngx-dialog--opening]': 'isOpening()',
674
+ '[class.cngx-dialog--open]': 'isOpen()',
675
+ '[class.cngx-dialog--closing]': 'isClosing()',
676
+ '[class.cngx-dialog--modal]': 'modal()',
677
+ '[attr.aria-modal]': 'ariaModal()',
678
+ '[attr.aria-labelledby]': 'ariaLabelledBy()',
679
+ '[attr.aria-describedby]': 'ariaDescribedBy()',
680
+ '[class.cngx-dialog--pending]': 'isPending()',
681
+ '[attr.aria-busy]': 'isPending() || null',
682
+ '[class.cngx-dialog--error]': 'effectiveError()',
683
+ '[style.--cngx-dialog-backdrop-opacity]': 'backdropOpacity()',
684
+ '(cancel)': 'handleCancel($event)',
685
+ '(click)': 'handleClick($event)',
686
+ },
687
+ }]
688
+ }], ctorParameters: () => [], propDecorators: { titleDirective: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxDialogTitle), { isSignal: true }] }], descriptionDirective: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxDialogDescription), { isSignal: true }] }], modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], closeOnBackdropClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnBackdropClick", required: false }] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], autoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoFocus", required: false }] }], focusFallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusFallback", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], submitAction: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitAction", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }] } });
689
+
690
+ /**
691
+ * Close trigger for a dialog. Place on any clickable element inside a dialog.
692
+ *
693
+ * - With a value: `[cngxDialogClose]="'confirm'"` calls `dialogRef.close(value)`
694
+ * - Without a value: `cngxDialogClose` calls `dialogRef.dismiss()`
695
+ *
696
+ * Automatically sets `type="button"` on `<button>` hosts to prevent
697
+ * accidental form submission. Sets a default `aria-label="Close dialog"`
698
+ * when the host has no descriptive text content (icon-only buttons).
699
+ *
700
+ * ```html
701
+ * <dialog cngxDialog>
702
+ * <button [cngxDialogClose]="false">Cancel</button>
703
+ * <button [cngxDialogClose]="true">Confirm</button>
704
+ * </dialog>
705
+ * ```
706
+ */
707
+ class CngxDialogClose {
708
+ dialogRef = inject(DIALOG_REF);
709
+ elRef = inject((ElementRef));
710
+ /** Value to pass to `close()`. When `undefined`, calls `dismiss()` instead. */
711
+ value = input(undefined, { ...(ngDevMode ? { debugName: "value" } : /* istanbul ignore next */ {}), alias: 'cngxDialogClose' });
712
+ /**
713
+ * Explicit `aria-label` override.
714
+ *
715
+ * When not set, the directive auto-detects whether the host element
716
+ * has descriptive text content. If it does (e.g. "Cancel", "Confirm"),
717
+ * no `aria-label` is added. If the content is a single character,
718
+ * empty, or visually an icon, `aria-label` defaults to `"Close dialog"`.
719
+ */
720
+ label = input(undefined, { ...(ngDevMode ? { debugName: "label" } : /* istanbul ignore next */ {}), alias: 'cngxDialogCloseLabel' });
721
+ /** Set type="button" on <button> hosts to prevent form submit. */
722
+ hostType = this.elRef.nativeElement.tagName === 'BUTTON' ? 'button' : null;
723
+ /**
724
+ * Computed `aria-label`. Returns:
725
+ * - explicit `label()` input if set
726
+ * - `null` if host text is descriptive (> 1 char, not whitespace-only)
727
+ * - `'Close dialog'` for icon-only / single-char content
728
+ */
729
+ ariaLabel = computed(() => {
730
+ // Explicit override wins
731
+ const explicit = this.label();
732
+ if (explicit !== undefined) {
733
+ return explicit || null;
734
+ }
735
+ // If host already has aria-label attribute set by the consumer, don't override
736
+ const el = this.elRef.nativeElement;
737
+ if (el.hasAttribute('aria-label')) {
738
+ return null;
739
+ }
740
+ // Check text content — if descriptive (multi-char word), no label needed
741
+ const text = el.textContent?.trim() ?? '';
742
+ if (text.length > 1) {
743
+ return null;
744
+ }
745
+ // Icon-only or single char (e.g. "X", "x") — set default
746
+ return 'Close dialog';
747
+ }, ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
748
+ handleClick() {
749
+ const v = this.value();
750
+ // Static attribute `cngxDialogClose` (no binding) resolves to '' — treat as dismiss.
751
+ // Only `[cngxDialogClose]="value"` with an explicit value calls close().
752
+ if (v !== undefined && v !== '') {
753
+ this.dialogRef.close(v);
754
+ }
755
+ else {
756
+ this.dialogRef.dismiss();
757
+ }
758
+ }
759
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogClose, deps: [], target: i0.ɵɵFactoryTarget.Directive });
760
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDialogClose, isStandalone: true, selector: "[cngxDialogClose]", inputs: { value: { classPropertyName: "value", publicName: "cngxDialogClose", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "cngxDialogCloseLabel", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "handleClick()" }, properties: { "attr.type": "hostType", "attr.aria-label": "ariaLabel()" } }, exportAs: ["cngxDialogClose"], ngImport: i0 });
761
+ }
762
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogClose, decorators: [{
763
+ type: Directive,
764
+ args: [{
765
+ selector: '[cngxDialogClose]',
766
+ exportAs: 'cngxDialogClose',
767
+ standalone: true,
768
+ host: {
769
+ '(click)': 'handleClick()',
770
+ '[attr.type]': 'hostType',
771
+ '[attr.aria-label]': 'ariaLabel()',
772
+ },
773
+ }]
774
+ }], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDialogClose", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDialogCloseLabel", required: false }] }] } });
775
+
776
+ /** Injection token for data passed to a programmatically opened dialog via `CngxDialogOpener.open()`. */
777
+ const CNGX_DIALOG_DATA = new InjectionToken('CngxDialogData');
778
+
779
+ /**
780
+ * Internal container component for programmatically opened dialogs.
781
+ *
782
+ * Not part of the public API — instantiated exclusively by `CngxDialogOpener`.
783
+ * Renders the native `<dialog>` shell and exposes a `<ng-container>` outlet
784
+ * where the content component or template is inserted.
785
+ *
786
+ * @internal
787
+ */
788
+ class CngxDialogOutlet {
789
+ modal = input(true, ...(ngDevMode ? [{ debugName: "modal" }] : /* istanbul ignore next */ []));
790
+ closeOnBackdropClick = input(true, ...(ngDevMode ? [{ debugName: "closeOnBackdropClick" }] : /* istanbul ignore next */ []));
791
+ closeOnEscape = input(true, ...(ngDevMode ? [{ debugName: "closeOnEscape" }] : /* istanbul ignore next */ []));
792
+ autoFocus = input('first-focusable', ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
793
+ dialog = viewChild.required(CngxDialog);
794
+ contentOutlet = viewChild('contentOutlet', { ...(ngDevMode ? { debugName: "contentOutlet" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
795
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOutlet, deps: [], target: i0.ɵɵFactoryTarget.Component });
796
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialogOutlet, isStandalone: true, selector: "cngx-dialog-outlet", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "dialog", first: true, predicate: CngxDialog, descendants: true, isSignal: true }, { propertyName: "contentOutlet", first: true, predicate: ["contentOutlet"], descendants: true, read: ViewContainerRef, isSignal: true }], ngImport: i0, template: `
797
+ <dialog
798
+ cngxDialog
799
+ [modal]="modal()"
800
+ [closeOnBackdropClick]="closeOnBackdropClick()"
801
+ [closeOnEscape]="closeOnEscape()"
802
+ [autoFocus]="autoFocus()"
803
+ #dialog="cngxDialog"
804
+ >
805
+ <ng-container #contentOutlet />
806
+ </dialog>
807
+ `, isInline: true, styles: [":host{display:contents}\n"], dependencies: [{ kind: "directive", type: CngxDialog, selector: "dialog[cngxDialog]", inputs: ["modal", "closeOnBackdropClick", "closeOnEscape", "autoFocus", "focusFallback", "state", "submitAction", "error"], exportAs: ["cngxDialog"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
808
+ }
809
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOutlet, decorators: [{
810
+ type: Component,
811
+ args: [{ selector: 'cngx-dialog-outlet', standalone: true, imports: [CngxDialog], template: `
812
+ <dialog
813
+ cngxDialog
814
+ [modal]="modal()"
815
+ [closeOnBackdropClick]="closeOnBackdropClick()"
816
+ [closeOnEscape]="closeOnEscape()"
817
+ [autoFocus]="autoFocus()"
818
+ #dialog="cngxDialog"
819
+ >
820
+ <ng-container #contentOutlet />
821
+ </dialog>
822
+ `, changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host{display:contents}\n"] }]
823
+ }], propDecorators: { modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], closeOnBackdropClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnBackdropClick", required: false }] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], autoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoFocus", required: false }] }], dialog: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CngxDialog), { isSignal: true }] }], contentOutlet: [{ type: i0.ViewChild, args: ['contentOutlet', { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
824
+
825
+ /**
826
+ * Reference to a programmatically opened dialog.
827
+ *
828
+ * Returned by `CngxDialogOpener.open()`. Provides both Signal-based access
829
+ * (`state`, `result`) and Observable convenience methods (`afterClosed()`,
830
+ * `afterOpened()`) for migration compatibility with `MatDialogRef`.
831
+ *
832
+ * ### Signal-based result reading
833
+ * ```typescript
834
+ * const ref = dialog.open<boolean>(ConfirmDialog);
835
+ *
836
+ * // In a computed or effect:
837
+ * const wasCancelled = ref.result() === 'dismissed';
838
+ * ```
839
+ *
840
+ * ### Observable-based result reading
841
+ * ```typescript
842
+ * ref.afterClosed().subscribe(result => {
843
+ * if (result !== 'dismissed') console.log('Confirmed:', result);
844
+ * });
845
+ * ```
846
+ */
847
+ class CngxDialogRef {
848
+ inner;
849
+ contentRef;
850
+ injector;
851
+ /** @internal */
852
+ _outletRef;
853
+ /** @internal */
854
+ constructor(inner, outletRef, contentRef, injector) {
855
+ this.inner = inner;
856
+ this.contentRef = contentRef;
857
+ this.injector = injector;
858
+ this._outletRef = outletRef;
859
+ }
860
+ /**
861
+ * Current lifecycle state of the dialog.
862
+ *
863
+ * Possible values: `'closed'`, `'opening'`, `'open'`, `'closing'`.
864
+ */
865
+ get lifecycle() {
866
+ return this.inner.lifecycle;
867
+ }
868
+ /**
869
+ * The typed result signal.
870
+ *
871
+ * - `undefined` before the dialog closes (reset on each open cycle)
872
+ * - `'dismissed'` when dismissed via Escape or backdrop click
873
+ * - `T` when closed with an explicit value
874
+ */
875
+ get result() {
876
+ return this.inner.result;
877
+ }
878
+ /** Unique auto-generated ID for this dialog instance. */
879
+ get id() {
880
+ return this.inner.id;
881
+ }
882
+ /**
883
+ * Close the dialog with a typed result value.
884
+ *
885
+ * @param value - The result to deliver to consumers.
886
+ */
887
+ close(value) {
888
+ this.inner.close(value);
889
+ }
890
+ /**
891
+ * Dismiss the dialog without a typed result.
892
+ *
893
+ * Sets the result to `'dismissed'`. Use for cancellation actions.
894
+ */
895
+ dismiss() {
896
+ this.inner.dismiss();
897
+ }
898
+ /**
899
+ * Observable that emits the result when the dialog closes.
900
+ *
901
+ * Emits exactly once with `T | 'dismissed'`, then completes.
902
+ * Compatible with `MatDialogRef.afterClosed()` usage patterns.
903
+ */
904
+ afterClosed() {
905
+ return toObservable(this.inner.lifecycle, { injector: this.injector }).pipe(filter((s) => s === 'closed'), take(1), map(() => this.inner.result()));
906
+ }
907
+ /**
908
+ * Observable that emits when the dialog finishes opening.
909
+ *
910
+ * Emits exactly once with `void` when the state transitions to `'open'`,
911
+ * then completes. Useful for post-open logic (e.g., focusing a specific
912
+ * element after animation completes).
913
+ */
914
+ afterOpened() {
915
+ return toObservable(this.inner.lifecycle, { injector: this.injector }).pipe(filter((s) => s === 'open'), take(1), map(() => undefined));
916
+ }
917
+ /**
918
+ * Reference to the content component instance.
919
+ *
920
+ * Returns `null` when the dialog was opened with a `TemplateRef` instead
921
+ * of a component type.
922
+ */
923
+ get componentRef() {
924
+ return this.contentRef;
925
+ }
926
+ }
927
+ /**
928
+ * Service for opening dialogs programmatically.
929
+ *
930
+ * Works like `MatDialog.open()` — pass a component type and config,
931
+ * get back a typed `CngxDialogRef<T>`.
932
+ *
933
+ * Must be provided via `provideDialog()`.
934
+ *
935
+ * ### Open a component dialog
936
+ * ```typescript
937
+ * const ref = this.dialog.open<User>(EditUserDialog, {
938
+ * data: { userId: 123 },
939
+ * });
940
+ *
941
+ * ref.afterClosed().subscribe(result => {
942
+ * if (result !== 'dismissed') saveUser(result);
943
+ * });
944
+ * ```
945
+ *
946
+ * ### Inside the dialog component
947
+ * ```typescript
948
+ * class EditUserDialog {
949
+ * private readonly data = inject(CNGX_DIALOG_DATA) as { userId: number };
950
+ * private readonly dialogRef = inject(DIALOG_REF) as DialogRef<User>;
951
+ *
952
+ * save(user: User) { this.dialogRef.close(user); }
953
+ * }
954
+ * ```
955
+ */
956
+ class CngxDialogOpener {
957
+ appRef = inject(ApplicationRef);
958
+ envInjector = inject(EnvironmentInjector);
959
+ injector = inject(Injector);
960
+ doc = inject(DOCUMENT);
961
+ openDialogs = [];
962
+ open(content, config = {}) {
963
+ const outletRef = createComponent(CngxDialogOutlet, {
964
+ environmentInjector: this.envInjector,
965
+ });
966
+ outletRef.setInput('modal', config.modal ?? true);
967
+ outletRef.setInput('closeOnBackdropClick', config.closeOnBackdropClick ?? true);
968
+ outletRef.setInput('closeOnEscape', config.closeOnEscape ?? true);
969
+ if (config.autoFocus) {
970
+ outletRef.setInput('autoFocus', config.autoFocus);
971
+ }
972
+ // Attach to ApplicationRef so change detection runs
973
+ this.appRef.attachView(outletRef.hostView);
974
+ const hostEl = outletRef.location.nativeElement;
975
+ this.doc.body.appendChild(hostEl);
976
+ const innerDialog = outletRef.instance.dialog();
977
+ const outletVcr = outletRef.instance.contentOutlet();
978
+ let contentRef = null;
979
+ // Build a child injector that provides DIALOG_REF and CNGX_DIALOG_DATA
980
+ const childInjector = Injector.create({
981
+ parent: this.injector,
982
+ providers: [
983
+ { provide: DIALOG_REF, useValue: innerDialog },
984
+ { provide: CNGX_DIALOG_DATA, useValue: config.data ?? null },
985
+ ],
986
+ });
987
+ if (outletVcr) {
988
+ if (typeof content === 'function') {
989
+ contentRef = outletVcr.createComponent(content, {
990
+ injector: childInjector,
991
+ });
992
+ }
993
+ else {
994
+ outletVcr.createEmbeddedView(content, { $implicit: innerDialog }, { injector: childInjector });
995
+ }
996
+ }
997
+ const dialogRef = new CngxDialogRef(innerDialog, outletRef, contentRef, this.injector);
998
+ this.openDialogs.push(dialogRef);
999
+ // CngxDialog has open() but the DialogRef<T> interface does not — call the concrete instance.
1000
+ const dialogInstance = outletRef.instance.dialog();
1001
+ dialogInstance.open();
1002
+ effect(() => {
1003
+ if (innerDialog.lifecycle() === 'closed' &&
1004
+ outletRef.hostView &&
1005
+ !outletRef.hostView.destroyed) {
1006
+ this.cleanup(dialogRef);
1007
+ }
1008
+ }, { injector: childInjector });
1009
+ return dialogRef;
1010
+ }
1011
+ /**
1012
+ * Dismiss all programmatically opened dialogs.
1013
+ *
1014
+ * Calls `dismiss()` on each open dialog in reverse order (most recent first).
1015
+ * Useful for route guards or global teardown.
1016
+ */
1017
+ closeAll() {
1018
+ for (const ref of [...this.openDialogs]) {
1019
+ ref.dismiss();
1020
+ }
1021
+ }
1022
+ cleanup(ref) {
1023
+ const idx = this.openDialogs.indexOf(ref);
1024
+ if (idx >= 0) {
1025
+ this.openDialogs.splice(idx, 1);
1026
+ }
1027
+ if (ref.componentRef && !ref.componentRef.hostView.destroyed) {
1028
+ ref.componentRef.destroy();
1029
+ }
1030
+ const outletRef = ref._outletRef;
1031
+ if (outletRef && !outletRef.hostView.destroyed) {
1032
+ this.appRef.detachView(outletRef.hostView);
1033
+ outletRef.location.nativeElement.remove();
1034
+ outletRef.destroy();
1035
+ }
1036
+ }
1037
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOpener, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1038
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOpener });
1039
+ }
1040
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOpener, decorators: [{
1041
+ type: Injectable
1042
+ }] });
1043
+ /**
1044
+ * Provide `CngxDialogOpener` for programmatic dialog opening.
1045
+ *
1046
+ * Must be called in the application's `providers` array or a route's
1047
+ * `providers` for `CngxDialogOpener` to be injectable.
1048
+ *
1049
+ * ```typescript
1050
+ * bootstrapApplication(AppComponent, {
1051
+ * providers: [provideDialog()],
1052
+ * });
1053
+ * ```
1054
+ */
1055
+ function provideDialog() {
1056
+ return [CngxDialogOpener];
1057
+ }
1058
+
1059
+ /**
1060
+ * Bottom sheet molecule — a `CngxDialog` positioned at the viewport bottom
1061
+ * with swipe-to-dismiss support.
1062
+ *
1063
+ * Place on the same `<dialog>` element alongside `cngxDialog`. Adds the
1064
+ * `cngx-bottom-sheet` CSS class (styled by `bottom-sheet-theme.scss`).
1065
+ * When `CngxSwipeDismiss` is also present, auto-wires the swipe output
1066
+ * to `dialogRef.dismiss()` — no manual `(swiped)` binding needed.
1067
+ *
1068
+ * ### Basic bottom sheet
1069
+ * ```html
1070
+ * <dialog cngxDialog cngxBottomSheet [cngxSwipeDismiss]="'down'"
1071
+ * #sheet="cngxDialog">
1072
+ * <h2 cngxDialogTitle>Share</h2>
1073
+ * <button [cngxDialogClose]="'copy'">Copy Link</button>
1074
+ * <button [cngxDialogClose]="'email'">Email</button>
1075
+ * <button cngxDialogClose>Cancel</button>
1076
+ * </dialog>
1077
+ * <button (click)="sheet.open()">Share</button>
1078
+ * ```
1079
+ *
1080
+ * ### Without swipe (static bottom sheet)
1081
+ * ```html
1082
+ * <dialog cngxDialog cngxBottomSheet #sheet="cngxDialog">
1083
+ * <p>Content positioned at the bottom.</p>
1084
+ * </dialog>
1085
+ * ```
1086
+ */
1087
+ class CngxBottomSheet {
1088
+ dialogRef = inject(DIALOG_REF);
1089
+ swipe = inject(CngxSwipeDismiss, { self: true, optional: true });
1090
+ /**
1091
+ * Whether the drag handle bar is visible.
1092
+ *
1093
+ * The handle itself is rendered via CSS (`::before` pseudo-element on the host).
1094
+ * Set to `false` to hide it.
1095
+ *
1096
+ * @defaultValue `true`
1097
+ */
1098
+ showHandle = input(true, ...(ngDevMode ? [{ debugName: "showHandle" }] : /* istanbul ignore next */ []));
1099
+ constructor() {
1100
+ // Auto-wire: swipe → dismiss (when CngxSwipeDismiss is on the same element)
1101
+ if (this.swipe) {
1102
+ const sub = this.swipe.swiped.subscribe(() => this.dialogRef.dismiss());
1103
+ inject(DestroyRef).onDestroy(() => sub.unsubscribe());
1104
+ }
1105
+ }
1106
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBottomSheet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1107
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBottomSheet, isStandalone: true, selector: "dialog[cngxBottomSheet]", inputs: { showHandle: { classPropertyName: "showHandle", publicName: "showHandle", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "cngx-bottom-sheet" }, exportAs: ["cngxBottomSheet"], ngImport: i0 });
1108
+ }
1109
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBottomSheet, decorators: [{
1110
+ type: Directive,
1111
+ args: [{
1112
+ selector: 'dialog[cngxBottomSheet]',
1113
+ exportAs: 'cngxBottomSheet',
1114
+ standalone: true,
1115
+ host: {
1116
+ class: 'cngx-bottom-sheet',
1117
+ },
1118
+ }]
1119
+ }], ctorParameters: () => [], propDecorators: { showHandle: [{ type: i0.Input, args: [{ isSignal: true, alias: "showHandle", required: false }] }] } });
1120
+
1121
+ /**
1122
+ * Opt-in drag behavior for `CngxDialog`.
1123
+ *
1124
+ * Uses Pointer Events for unified mouse/touch handling. Position is exposed
1125
+ * as CSS custom properties `--cngx-dialog-x` and `--cngx-dialog-y` — the
1126
+ * consumer applies the transform via CSS.
1127
+ *
1128
+ * Keyboard-based moving is mandatory for accessibility:
1129
+ * - Arrow keys move 10px
1130
+ * - Shift + Arrow moves 50px
1131
+ * - Home resets to origin
1132
+ *
1133
+ * ```html
1134
+ * <dialog cngxDialog cngxDialogDraggable>
1135
+ * <div class="dialog-header" #handle>Title</div>
1136
+ * …
1137
+ * </dialog>
1138
+ * ```
1139
+ *
1140
+ * ```css
1141
+ * dialog[cngxDialogDraggable] {
1142
+ * transform: translate(var(--cngx-dialog-x, 0px), var(--cngx-dialog-y, 0px));
1143
+ * }
1144
+ * ```
1145
+ */
1146
+ class CngxDialogDraggable {
1147
+ elRef = inject(ElementRef);
1148
+ doc = inject(DOCUMENT);
1149
+ destroyRef = inject(DestroyRef);
1150
+ /** Handle element for initiating drag. If not set, entire dialog is the handle. */
1151
+ handle = input(undefined, ...(ngDevMode ? [{ debugName: "handle" }] : /* istanbul ignore next */ []));
1152
+ /** Clamp position to viewport bounds. */
1153
+ constrainToViewport = input(false, ...(ngDevMode ? [{ debugName: "constrainToViewport" }] : /* istanbul ignore next */ []));
1154
+ /**
1155
+ * Snap position to a grid in pixels.
1156
+ *
1157
+ * When set to a positive number, the dialog position snaps to the nearest
1158
+ * grid increment. When `snapMode` is `'live'`, snapping happens during drag.
1159
+ * When `'release'`, position is free during drag and snaps on pointer up.
1160
+ *
1161
+ * @defaultValue `0` (no grid)
1162
+ */
1163
+ gridSize = input(0, ...(ngDevMode ? [{ debugName: "gridSize" }] : /* istanbul ignore next */ []));
1164
+ /**
1165
+ * When to apply grid snapping.
1166
+ *
1167
+ * - `'live'` — position snaps continuously during drag (default)
1168
+ * - `'release'` — position is free during drag, snaps on pointer up
1169
+ *
1170
+ * @defaultValue `'live'`
1171
+ */
1172
+ snapMode = input('live', ...(ngDevMode ? [{ debugName: "snapMode" }] : /* istanbul ignore next */ []));
1173
+ positionState = signal({ x: 0, y: 0 }, ...(ngDevMode ? [{ debugName: "positionState" }] : /* istanbul ignore next */ []));
1174
+ draggingState = signal(false, ...(ngDevMode ? [{ debugName: "draggingState" }] : /* istanbul ignore next */ []));
1175
+ /** Current offset position. */
1176
+ position = this.positionState.asReadonly();
1177
+ /** Whether a drag operation is in progress. */
1178
+ isDragging = this.draggingState.asReadonly();
1179
+ cssX = computed(() => `${this.positionState().x}px`, ...(ngDevMode ? [{ debugName: "cssX" }] : /* istanbul ignore next */ []));
1180
+ cssY = computed(() => `${this.positionState().y}px`, ...(ngDevMode ? [{ debugName: "cssY" }] : /* istanbul ignore next */ []));
1181
+ // Drag state — not reactive, perf critical (pointermove runs at framerate).
1182
+ dragStartX = 0;
1183
+ dragStartY = 0;
1184
+ posStartX = 0;
1185
+ posStartY = 0;
1186
+ boundMove = null;
1187
+ boundUp = null;
1188
+ constructor() {
1189
+ effect(() => {
1190
+ const handleEl = this.handle() ?? this.elRef.nativeElement;
1191
+ this.setupHandle(handleEl);
1192
+ });
1193
+ this.destroyRef.onDestroy(() => this.cleanup());
1194
+ }
1195
+ currentHandle = null;
1196
+ boundPointerDown = null;
1197
+ boundKeyDown = null;
1198
+ /** Attach pointer and keyboard listeners to `el`, cleaning up the previous handle first. */
1199
+ setupHandle(el) {
1200
+ if (this.currentHandle && this.boundPointerDown) {
1201
+ this.currentHandle.removeEventListener('pointerdown', this.boundPointerDown);
1202
+ }
1203
+ if (this.currentHandle && this.boundKeyDown) {
1204
+ this.currentHandle.removeEventListener('keydown', this.boundKeyDown);
1205
+ }
1206
+ this.currentHandle = el;
1207
+ // A11y: make handle focusable and describe as draggable
1208
+ if (!el.hasAttribute('tabindex') && el !== this.elRef.nativeElement) {
1209
+ el.setAttribute('tabindex', '0');
1210
+ }
1211
+ if (!el.hasAttribute('aria-roledescription') && el !== this.elRef.nativeElement) {
1212
+ el.setAttribute('aria-roledescription', 'draggable');
1213
+ el.setAttribute('aria-label', 'Move dialog');
1214
+ }
1215
+ el.style.cursor = 'var(--cngx-dialog-drag-cursor, grab)';
1216
+ el.style.touchAction = 'none';
1217
+ this.boundPointerDown = (e) => this.handlePointerDown(e);
1218
+ this.boundKeyDown = (e) => this.handleKeyDown(e);
1219
+ el.addEventListener('pointerdown', this.boundPointerDown);
1220
+ el.addEventListener('keydown', this.boundKeyDown);
1221
+ }
1222
+ handlePointerDown(event) {
1223
+ if (event.button !== 0) {
1224
+ return;
1225
+ }
1226
+ // Don't drag if the target is an interactive element inside the handle
1227
+ const target = event.target;
1228
+ if (target.closest('button, a, input, select, textarea, [tabindex]') &&
1229
+ target !== this.currentHandle) {
1230
+ return;
1231
+ }
1232
+ event.preventDefault();
1233
+ (this.currentHandle ?? this.elRef.nativeElement).setPointerCapture(event.pointerId);
1234
+ this.dragStartX = event.clientX;
1235
+ this.dragStartY = event.clientY;
1236
+ this.posStartX = this.positionState().x;
1237
+ this.posStartY = this.positionState().y;
1238
+ this.draggingState.set(true);
1239
+ // Prevent text selection during drag
1240
+ this.doc.documentElement.style.userSelect = 'none';
1241
+ if (this.currentHandle) {
1242
+ this.currentHandle.style.cursor = 'var(--cngx-dialog-dragging-cursor, grabbing)';
1243
+ }
1244
+ this.boundMove = (e) => this.handlePointerMove(e);
1245
+ this.boundUp = (e) => this.handlePointerUp(e);
1246
+ this.doc.addEventListener('pointermove', this.boundMove);
1247
+ this.doc.addEventListener('pointerup', this.boundUp);
1248
+ }
1249
+ handlePointerMove(event) {
1250
+ let x = this.posStartX + (event.clientX - this.dragStartX);
1251
+ let y = this.posStartY + (event.clientY - this.dragStartY);
1252
+ if (this.constrainToViewport()) {
1253
+ const win = this.doc.defaultView;
1254
+ if (win) {
1255
+ const rect = this.elRef.nativeElement.getBoundingClientRect();
1256
+ const baseX = rect.left - this.positionState().x;
1257
+ const baseY = rect.top - this.positionState().y;
1258
+ x = Math.max(-baseX, Math.min(x, win.innerWidth - baseX - rect.width));
1259
+ y = Math.max(-baseY, Math.min(y, win.innerHeight - baseY - rect.height));
1260
+ }
1261
+ }
1262
+ if (this.gridSize() > 0 && this.snapMode() === 'live') {
1263
+ ({ x, y } = this.snap(x, y));
1264
+ }
1265
+ this.positionState.set({ x, y });
1266
+ }
1267
+ handlePointerUp(event) {
1268
+ (this.currentHandle ?? this.elRef.nativeElement).releasePointerCapture(event.pointerId);
1269
+ this.draggingState.set(false);
1270
+ this.doc.documentElement.style.userSelect = '';
1271
+ if (this.currentHandle) {
1272
+ this.currentHandle.style.cursor = 'var(--cngx-dialog-drag-cursor, grab)';
1273
+ }
1274
+ if (this.gridSize() > 0 && this.snapMode() === 'release') {
1275
+ const { x, y } = this.positionState();
1276
+ this.positionState.set(this.snap(x, y));
1277
+ }
1278
+ if (this.boundMove) {
1279
+ this.doc.removeEventListener('pointermove', this.boundMove);
1280
+ }
1281
+ if (this.boundUp) {
1282
+ this.doc.removeEventListener('pointerup', this.boundUp);
1283
+ }
1284
+ this.boundMove = null;
1285
+ this.boundUp = null;
1286
+ }
1287
+ handleKeyDown(event) {
1288
+ const grid = this.gridSize();
1289
+ // When grid is active, Arrow keys step by grid size (Shift = 5x grid)
1290
+ const step = grid > 0 ? (event.shiftKey ? grid * 5 : grid) : event.shiftKey ? 50 : 10;
1291
+ const { x, y } = this.positionState();
1292
+ switch (event.key) {
1293
+ case 'ArrowLeft':
1294
+ event.preventDefault();
1295
+ this.positionState.set(this.snap(x - step, y));
1296
+ break;
1297
+ case 'ArrowRight':
1298
+ event.preventDefault();
1299
+ this.positionState.set(this.snap(x + step, y));
1300
+ break;
1301
+ case 'ArrowUp':
1302
+ event.preventDefault();
1303
+ this.positionState.set(this.snap(x, y - step));
1304
+ break;
1305
+ case 'ArrowDown':
1306
+ event.preventDefault();
1307
+ this.positionState.set(this.snap(x, y + step));
1308
+ break;
1309
+ case 'Home':
1310
+ event.preventDefault();
1311
+ this.positionState.set({ x: 0, y: 0 });
1312
+ break;
1313
+ }
1314
+ }
1315
+ /** Snap `x`/`y` to the nearest `gridSize` increment. Pass-through when grid is disabled. */
1316
+ snap(x, y) {
1317
+ const grid = this.gridSize();
1318
+ if (grid <= 0) {
1319
+ return { x, y };
1320
+ }
1321
+ return {
1322
+ x: Math.round(x / grid) * grid,
1323
+ y: Math.round(y / grid) * grid,
1324
+ };
1325
+ }
1326
+ cleanup() {
1327
+ if (this.boundMove) {
1328
+ this.doc.removeEventListener('pointermove', this.boundMove);
1329
+ }
1330
+ if (this.boundUp) {
1331
+ this.doc.removeEventListener('pointerup', this.boundUp);
1332
+ }
1333
+ if (this.currentHandle && this.boundPointerDown) {
1334
+ this.currentHandle.removeEventListener('pointerdown', this.boundPointerDown);
1335
+ }
1336
+ if (this.currentHandle && this.boundKeyDown) {
1337
+ this.currentHandle.removeEventListener('keydown', this.boundKeyDown);
1338
+ }
1339
+ }
1340
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDraggable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1341
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDialogDraggable, isStandalone: true, selector: "[cngxDialogDraggable]", inputs: { handle: { classPropertyName: "handle", publicName: "handle", isSignal: true, isRequired: false, transformFunction: null }, constrainToViewport: { classPropertyName: "constrainToViewport", publicName: "constrainToViewport", isSignal: true, isRequired: false, transformFunction: null }, gridSize: { classPropertyName: "gridSize", publicName: "gridSize", isSignal: true, isRequired: false, transformFunction: null }, snapMode: { classPropertyName: "snapMode", publicName: "snapMode", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.--cngx-dialog-x": "cssX()", "style.--cngx-dialog-y": "cssY()", "class.cngx-dialog--dragging": "isDragging()" } }, exportAs: ["cngxDialogDraggable"], ngImport: i0 });
1342
+ }
1343
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDraggable, decorators: [{
1344
+ type: Directive,
1345
+ args: [{
1346
+ selector: '[cngxDialogDraggable]',
1347
+ exportAs: 'cngxDialogDraggable',
1348
+ standalone: true,
1349
+ host: {
1350
+ '[style.--cngx-dialog-x]': 'cssX()',
1351
+ '[style.--cngx-dialog-y]': 'cssY()',
1352
+ '[class.cngx-dialog--dragging]': 'isDragging()',
1353
+ },
1354
+ }]
1355
+ }], ctorParameters: () => [], propDecorators: { handle: [{ type: i0.Input, args: [{ isSignal: true, alias: "handle", required: false }] }], constrainToViewport: [{ type: i0.Input, args: [{ isSignal: true, alias: "constrainToViewport", required: false }] }], gridSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "gridSize", required: false }] }], snapMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "snapMode", required: false }] }] } });
1356
+
1357
+ /**
1358
+ * @module @cngx/common/dialog
1359
+ */
1360
+
1361
+ /**
1362
+ * Generated bundle index. Do not edit.
1363
+ */
1364
+
1365
+ export { CNGX_DIALOG_DATA, CngxBottomSheet, CngxDialog, CngxDialogClose, CngxDialogDescription, CngxDialogDraggable, CngxDialogOpener, CngxDialogRef, CngxDialogStack, CngxDialogTitle, DIALOG_REF, provideDialog, provideDialogStack };
1366
+ //# sourceMappingURL=cngx-common-dialog.mjs.map