@cngx/common 0.1.0-rc.9 → 0.3.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 (88) hide show
  1. package/a11y/README.md +15 -2
  2. package/button/README.md +258 -0
  3. package/command/README.md +19 -8
  4. package/data/README.md +10 -10
  5. package/fesm2022/cngx-common-a11y.mjs +701 -263
  6. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  7. package/fesm2022/cngx-common-audio.mjs +83 -64
  8. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  9. package/fesm2022/cngx-common-button.mjs +1084 -0
  10. package/fesm2022/cngx-common-button.mjs.map +1 -0
  11. package/fesm2022/cngx-common-card.mjs +135 -76
  12. package/fesm2022/cngx-common-card.mjs.map +1 -1
  13. package/fesm2022/cngx-common-chart.mjs +749 -296
  14. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  15. package/fesm2022/cngx-common-command.mjs +51 -29
  16. package/fesm2022/cngx-common-command.mjs.map +1 -1
  17. package/fesm2022/cngx-common-data.mjs +695 -405
  18. package/fesm2022/cngx-common-data.mjs.map +1 -1
  19. package/fesm2022/cngx-common-dialog.mjs +112 -112
  20. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  21. package/fesm2022/cngx-common-display.mjs +668 -308
  22. package/fesm2022/cngx-common-display.mjs.map +1 -1
  23. package/fesm2022/cngx-common-interactive.mjs +7066 -2739
  24. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  25. package/fesm2022/cngx-common-layout.mjs +2121 -492
  26. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  27. package/fesm2022/cngx-common-menu-button.mjs +557 -0
  28. package/fesm2022/cngx-common-menu-button.mjs.map +1 -0
  29. package/fesm2022/cngx-common-popover.mjs +1207 -569
  30. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  31. package/fesm2022/cngx-common-stepper.mjs +256 -261
  32. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  33. package/fesm2022/cngx-common-tabs.mjs +202 -262
  34. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  35. package/fesm2022/cngx-common-timeline.mjs +28 -61
  36. package/fesm2022/cngx-common-timeline.mjs.map +1 -1
  37. package/fesm2022/cngx-common.mjs +10 -10
  38. package/fesm2022/cngx-common.mjs.map +1 -1
  39. package/interactive/README.md +30 -19
  40. package/layout/README.md +1 -1
  41. package/menu-button/README.md +234 -0
  42. package/package.json +14 -4
  43. package/popover/README.md +42 -5
  44. package/popover/tooltip-indicator.scss +52 -0
  45. package/schematics/ng-add/index.js +7 -7
  46. package/schematics/ng-add/schema.json +5 -0
  47. package/stepper/README.md +0 -1
  48. package/theming/components/cngx-accordion.css +36 -7
  49. package/theming/components/cngx-async.css +185 -37
  50. package/theming/components/cngx-backdrop.css +3 -1
  51. package/theming/components/cngx-badge.css +20 -5
  52. package/theming/components/cngx-bottom-sheet.css +2 -0
  53. package/theming/components/cngx-breadcrumb.css +3 -1
  54. package/theming/components/cngx-button-group.css +325 -0
  55. package/theming/components/cngx-button-toggle.css +55 -23
  56. package/theming/components/cngx-button.css +975 -0
  57. package/theming/components/cngx-data-grid.css +2 -0
  58. package/theming/components/cngx-dialog.css +3 -1
  59. package/theming/components/cngx-divider.css +24 -9
  60. package/theming/components/cngx-drawer.css +153 -0
  61. package/theming/components/cngx-icon-glyph.css +76 -0
  62. package/theming/components/cngx-listbox.css +79 -25
  63. package/theming/components/cngx-menu.css +112 -52
  64. package/theming/components/cngx-nav.css +1220 -0
  65. package/theming/components/cngx-popover-sheet.css +43 -11
  66. package/theming/components/cngx-popover.css +37 -13
  67. package/theming/components/cngx-recycler-placeholder.css +2 -0
  68. package/theming/components/cngx-ripple.css +74 -16
  69. package/theming/components/cngx-sidebar.css +71 -0
  70. package/theming/components/cngx-slider.css +3 -1
  71. package/theming/components/cngx-tooltip.css +2 -0
  72. package/timeline/README.md +2 -2
  73. package/types/cngx-common-a11y.d.ts +343 -120
  74. package/types/cngx-common-audio.d.ts +60 -88
  75. package/types/cngx-common-button.d.ts +698 -0
  76. package/types/cngx-common-card.d.ts +104 -78
  77. package/types/cngx-common-chart.d.ts +671 -384
  78. package/types/cngx-common-command.d.ts +44 -47
  79. package/types/cngx-common-data.d.ts +350 -342
  80. package/types/cngx-common-dialog.d.ts +91 -120
  81. package/types/cngx-common-display.d.ts +475 -300
  82. package/types/cngx-common-interactive.d.ts +4350 -1723
  83. package/types/cngx-common-layout.d.ts +1365 -286
  84. package/types/cngx-common-menu-button.d.ts +382 -0
  85. package/types/cngx-common-popover.d.ts +671 -289
  86. package/types/cngx-common-stepper.d.ts +217 -347
  87. package/types/cngx-common-tabs.d.ts +173 -386
  88. package/types/cngx-common-timeline.d.ts +25 -104
@@ -1,14 +1,122 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, untracked, DestroyRef, InjectionToken, PLATFORM_ID, model, TemplateRef, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
2
+ import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, InjectionToken, computed, Injector, HostAttributeToken, DestroyRef, untracked, ViewEncapsulation, ChangeDetectionStrategy, Component, model, PLATFORM_ID, linkedSignal, TemplateRef, contentChild } from '@angular/core';
3
+ import { CNGX_LIVE_SURFACE_SELECTOR, createSlotRegistry, createOverrideMerge, createCloseWatcher, observeMediaQuery, createMediaQuerySignal, coerceSignal, nextUid, createTransitionTracker } from '@cngx/core/utils';
4
+ import { cngxDevWarn, CNGX_ICON_X, CNGX_ICON_MENU, CNGX_ICON_PANEL_CLOSE, CNGX_ICON_PANEL_OPEN, clamp } from '@cngx/utils';
3
5
  import { DOCUMENT, isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
4
- import { toObservable, outputToObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
5
- import { switchMap, fromEvent } from 'rxjs';
6
- import { createTransitionTracker, observeMediaQuery, createMediaQuerySignal, coerceSignal, createOverrideMerge } from '@cngx/core/utils';
7
6
  import * as i1 from '@cngx/common/a11y';
8
- import { CngxFocusTrap } from '@cngx/common/a11y';
9
- import { cngxDevWarn } from '@cngx/utils';
7
+ import { CngxFocusTrap, CNGX_FOCUS_TRAP_DRIVER, CNGX_FOCUS_RESTORE_DRIVER, CngxFocusRestore } from '@cngx/common/a11y';
8
+ import * as i2 from '@cngx/common/interactive';
9
+ import { createHotkeyScope, CNGX_HOTKEY_SCOPE, CngxClickOutside, CNGX_CLICK_OUTSIDE_DRIVER, createActivationKeyHandler, CngxHoverIntent, CNGX_HOVER_INTENT_DRIVER } from '@cngx/common/interactive';
10
+ import { injectWindow } from '@cngx/core/tokens';
11
+ import { createLanguageSection, formatMessage, createSectionBundle } from '@cngx/core/i18n';
12
+ import { toSignal } from '@angular/core/rxjs-interop';
10
13
  import { Router, ActivatedRoute } from '@angular/router';
11
- import { createLanguageSection } from '@cngx/core/i18n';
14
+ import * as i2$1 from '@cngx/common/button';
15
+ import { CngxButtonAdornment, provideButtonHost, CngxButtonBrain } from '@cngx/common/button';
16
+ import { CngxIconSvg } from '@cngx/common/display';
17
+ import { injectDirection, injectEffectiveMotion } from '@cngx/core';
18
+
19
+ /**
20
+ * @internal Elements that stay live in every scope:
21
+ *
22
+ * - CDK focus-trap anchors: an inert anchor cannot take focus, so the trap
23
+ * next to it stops wrapping and Tab leaves the modal.
24
+ * - Live regions, announcer containers (the CDK announcer) and every
25
+ * element marked with `CNGX_LIVE_SURFACE_ATTR` (the toast and banner
26
+ * outlets): inert content leaves the accessibility tree, and an
27
+ * announcement written into it is never spoken.
28
+ * - The CDK overlay container: overlays opened from inside the modal render
29
+ * there, outside the host.
30
+ * - A `CngxBackdrop` (static `data-cngx-backdrop` marker): it holds no
31
+ * focusable content, and inerting it would swallow its `backdropClick`. The
32
+ * marker does not wait for the visible class, which can land after a modal
33
+ * surface engaged in the same pass.
34
+ */
35
+ const KEEP_LIVE_SELECTOR = [
36
+ '.cdk-focus-trap-anchor',
37
+ '[aria-live]',
38
+ '[role="status"]',
39
+ '[role="alert"]',
40
+ '[role="log"]',
41
+ '.cdk-live-announcer-element',
42
+ CNGX_LIVE_SURFACE_SELECTOR,
43
+ '.cdk-overlay-container',
44
+ '[data-cngx-backdrop]',
45
+ ].join(', ');
46
+ /**
47
+ * @internal Top-layer surfaces that render outside the host after it engaged
48
+ * (a dialog the service appends to `<body>`, a tooltip placed next to its
49
+ * trigger) were opened from inside the modal and stay live. Only late
50
+ * additions get this exemption.
51
+ */
52
+ const LATE_LIVE_SELECTOR = 'dialog, [popover]';
53
+ /**
54
+ * @internal Marks the elements around `host` as `inert` and returns the
55
+ * release function. Shared by `CngxBackdrop` (`'siblings'`) and
56
+ * `CngxDrawerSurface` (`'outside'`).
57
+ *
58
+ * The set is queried at call time and then followed: an element rendered
59
+ * later next to the host or next to one of its ancestors inside the scope
60
+ * (`@if`, `@defer`, a routed view) is inerted as it arrives, unless it is or
61
+ * holds a `<dialog>` or `[popover]`, which a late addition only is when the
62
+ * modal opened it. Elements that already carry
63
+ * `inert` are skipped and never touched on release, so a consumer-set or
64
+ * other-owner `inert` survives. Focus-trap anchors, live regions, the CDK
65
+ * overlay container, marked live surfaces and a backdrop
66
+ * stay live; an element that only contains one of them is not inerted as a
67
+ * whole, its other children are.
68
+ * Release is idempotent and stops following the scope.
69
+ */
70
+ function createInertSiblings(host, options = {}) {
71
+ const { scope = 'siblings', exclude = () => false, within, keepLive } = options;
72
+ const root = scope === 'outside' ? (within ?? host.ownerDocument.body) : host.parentElement;
73
+ const liveSelector = keepLive ? `${KEEP_LIVE_SELECTOR}, ${keepLive}` : KEEP_LIVE_SELECTOR;
74
+ const lateLiveSelector = `${liveSelector}, ${LATE_LIVE_SELECTOR}`;
75
+ const targets = [];
76
+ const Observer = host.ownerDocument.defaultView?.MutationObserver;
77
+ const observer = Observer
78
+ ? new Observer((records) => {
79
+ for (const record of records) {
80
+ record.addedNodes.forEach((node) => visit(node, lateLiveSelector));
81
+ }
82
+ })
83
+ : null;
84
+ const keepsLive = (element, selector) => element.matches(selector) || exclude(element);
85
+ const containsLive = (element, selector) => element.contains(host) ||
86
+ Array.from(element.querySelectorAll(selector)).some((node) => !host.contains(node));
87
+ const visit = (child, selector) => {
88
+ if (child === host || !(child instanceof HTMLElement) || child.hasAttribute('inert')) {
89
+ return;
90
+ }
91
+ if (keepsLive(child, selector)) {
92
+ return;
93
+ }
94
+ if (containsLive(child, selector)) {
95
+ collect(child, selector);
96
+ return;
97
+ }
98
+ child.setAttribute('inert', '');
99
+ targets.push(child);
100
+ };
101
+ const collect = (container, selector) => {
102
+ observer?.observe(container, { childList: true });
103
+ for (const child of Array.from(container.children)) {
104
+ visit(child, selector);
105
+ }
106
+ };
107
+ if (root && root !== host && root.contains(host)) {
108
+ collect(root, liveSelector);
109
+ }
110
+ let released = false;
111
+ return () => {
112
+ if (released) {
113
+ return;
114
+ }
115
+ released = true;
116
+ observer?.disconnect();
117
+ targets.forEach((target) => target.removeAttribute('inert'));
118
+ };
119
+ }
12
120
 
13
121
  /**
14
122
  * Manages backdrop overlay behavior: visibility, click-to-close, and
@@ -18,13 +126,18 @@ import { createLanguageSection } from '@cngx/core/i18n';
18
126
  * attribute, preventing focus and interaction behind the backdrop.
19
127
  * This is critical for a11y in modal/drawer overlays. A sibling drawer
20
128
  * panel (`.cngx-drawer-panel`) is excluded - it is the surface the
21
- * backdrop guards, not content behind it. Siblings that already carry
129
+ * backdrop guards, not content behind it. Focus-trap anchors (the
130
+ * panel's trap would stop wrapping) and live regions (announcements would
131
+ * go silent) stay live too; a sibling that only contains a live region has
132
+ * its other children inerted instead. Siblings that already carry
22
133
  * `inert` are left alone, so a consumer-set `inert` survives the
23
134
  * show/hide cycle. The sibling set is re-queried on every show, so
24
135
  * siblings rendered after init are covered too.
25
136
  *
26
137
  * The directive is purely behavioral - it toggles the
27
- * `.cngx-backdrop--visible` class and `aria-hidden` attribute. Visual
138
+ * `.cngx-backdrop--visible` class and `aria-hidden` attribute, and marks
139
+ * its host with `data-cngx-backdrop`, which keeps it live under the inert
140
+ * set of a page-modal drawer so its `backdropClick` still fires. Visual
28
141
  * styling is opt-in: either consume the shipped default stylesheet or
29
142
  * provide your own.
30
143
  *
@@ -68,12 +181,12 @@ import { createLanguageSection } from '@cngx/core/i18n';
68
181
  * }
69
182
  * ```
70
183
  *
71
- * @category common/layout
72
184
  * @wcag AA
73
185
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/backdrop.directive.ts
74
- * @since 0.1.0
186
+ * @since 0.3.0
75
187
  * @relatedTo CngxDrawer, CngxDrawerPanel, CngxScrollLock
76
- * <example-url>http://localhost:4200/#/common/layout/backdrop/overlay-with-inert</example-url>
188
+ * <example-url>/#/common/layout/backdrop/overlay-with-inert</example-url>
189
+ * @axis level atom
77
190
  */
78
191
  class CngxBackdrop {
79
192
  /** Whether the backdrop is visible and siblings are inert. */
@@ -93,18 +206,11 @@ class CngxBackdrop {
93
206
  // Re-queried on every show: siblings rendered after init (@if/@defer)
94
207
  // must be inerted too. The drawer panel keeps working - it is the
95
208
  // surface the backdrop guards, not content behind it.
96
- const el = this.el.nativeElement;
97
- const parent = el.parentElement;
98
- // skip siblings that are already inert - removing it on cleanup
99
- // would clobber a consumer-set attribute that predated the show
100
- const targets = parent
101
- ? Array.from(parent.children).filter((child) => child !== el &&
102
- child instanceof HTMLElement &&
103
- !child.classList.contains('cngx-drawer-panel') &&
104
- !child.hasAttribute('inert'))
105
- : [];
106
- targets.forEach((target) => target.setAttribute('inert', ''));
107
- onCleanup(() => targets.forEach((target) => target.removeAttribute('inert')));
209
+ const release = createInertSiblings(this.el.nativeElement, {
210
+ scope: 'siblings',
211
+ exclude: (sibling) => sibling.classList.contains('cngx-drawer-panel'),
212
+ });
213
+ onCleanup(release);
108
214
  });
109
215
  }
110
216
  /** @internal */
@@ -114,7 +220,7 @@ class CngxBackdrop {
114
220
  }
115
221
  }
116
222
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, deps: [], target: i0.ɵɵFactoryTarget.Directive });
117
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBackdrop, isStandalone: true, selector: "[cngxBackdrop]", inputs: { visible: { classPropertyName: "visible", publicName: "cngxBackdrop", isSignal: true, isRequired: false, transformFunction: null }, closeOnClick: { classPropertyName: "closeOnClick", publicName: "closeOnClick", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { backdropClick: "backdropClick" }, host: { attributes: { "aria-hidden": "true" }, listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()" } }, exportAs: ["cngxBackdrop"], ngImport: i0 });
223
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBackdrop, isStandalone: true, selector: "[cngxBackdrop]", inputs: { visible: { classPropertyName: "visible", publicName: "cngxBackdrop", isSignal: true, isRequired: false, transformFunction: null }, closeOnClick: { classPropertyName: "closeOnClick", publicName: "closeOnClick", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { backdropClick: "backdropClick" }, host: { attributes: { "aria-hidden": "true", "data-cngx-backdrop": "" }, listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()" } }, exportAs: ["cngxBackdrop"], ngImport: i0 });
118
224
  }
119
225
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, decorators: [{
120
226
  type: Directive,
@@ -125,11 +231,64 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
125
231
  host: {
126
232
  '[class.cngx-backdrop--visible]': 'visible()',
127
233
  'aria-hidden': 'true',
234
+ 'data-cngx-backdrop': '',
128
235
  '(click)': 'handleHostClick()',
129
236
  },
130
237
  }]
131
238
  }], ctorParameters: () => [], propDecorators: { visible: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxBackdrop", required: false }] }], closeOnClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClick", required: false }] }], backdropClick: [{ type: i0.Output, args: ["backdropClick"] }] } });
132
239
 
240
+ /**
241
+ * The panel target of the surrounding drawer, sidebar or sidenav, for a
242
+ * `CngxPanelTrigger` placed inside it (a pin or close button). A trigger
243
+ * outside the panel takes the target as an explicit reference instead.
244
+ *
245
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-trigger/panel-target.ts
246
+ * @since 0.3.0
247
+ * @relatedTo CngxPanelTrigger, CngxDrawer
248
+ */
249
+ const CNGX_PANEL_TARGET = new InjectionToken('CngxPanelTarget');
250
+
251
+ /**
252
+ * The drawer host of a `CngxDrawerPanel` on the same element. `CngxDrawer`
253
+ * provides it via `useExisting`, so a bare `cngxDrawerPanel` attribute next
254
+ * to `cngxDrawer` resolves its drawer without injecting the concrete class.
255
+ * An explicit `[cngxDrawerPanel]` reference wins over it.
256
+ *
257
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-host.ts
258
+ * @since 0.3.0
259
+ * @relatedTo CngxDrawer, CngxDrawerPanel
260
+ */
261
+ const CNGX_DRAWER_HOST = new InjectionToken('CngxDrawerHost');
262
+
263
+ // Escape is dismissed one layer at a time. Host listeners bubble from the
264
+ // innermost surface outwards and run before CngxPopover's document listener,
265
+ // so each layer checks for a closer owner before it acts.
266
+ const claimed = new WeakSet();
267
+ /**
268
+ * @internal Whether a layer closer to the keypress than `host` owns this
269
+ * Escape: an inner surface or drawer already handled it, or an open popover
270
+ * inside `host` (a menu, a select panel) takes it through its own listener.
271
+ */
272
+ function escapeOwnedAbove(event, host) {
273
+ return claimed.has(event) || hasOpenPopover(host);
274
+ }
275
+ /** @internal Marks the Escape as handled for the layers around the handler. */
276
+ function claimEscape(event) {
277
+ claimed.add(event);
278
+ }
279
+ function hasOpenPopover(host) {
280
+ return Array.from(host.querySelectorAll('[popover]')).some(isOpenPopover);
281
+ }
282
+ // Engines without the Popover API reject the pseudo-class.
283
+ function isOpenPopover(element) {
284
+ try {
285
+ return element.matches(':popover-open');
286
+ }
287
+ catch {
288
+ return false;
289
+ }
290
+ }
291
+
133
292
  /**
134
293
  * State owner for a drawer / sidebar system.
135
294
  *
@@ -139,6 +298,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
139
298
  *
140
299
  * Child directives (`CngxDrawerPanel`, `CngxDrawerContent`) receive a
141
300
  * reference to this directive via an explicit input - no ancestor injection.
301
+ * The panel reads it through the `CngxDrawerHost` contract, which the drawer
302
+ * also provides as `CNGX_DRAWER_HOST` for a panel on its own element.
303
+ *
304
+ * The drawer is a `CngxPanelTarget`: a `[cngxPanelTrigger]="drawer"` button
305
+ * mirrors `opened` as `aria-expanded` and points `aria-controls` at
306
+ * `panelId`, which the panel takes as its `id`. Inside the drawer it provides
307
+ * `CNGX_PANEL_TARGET` for a bare `cngxPanelTrigger`. Its `mode`, `modal`
308
+ * and `side` follow the panel's `mode`, resolved modality and `position`,
309
+ * so a `CngxPanelToggle` draws the glyph of the current presentation.
310
+ *
311
+ * The drawer host is also the boundary of a `'contained'` panel and the
312
+ * area its scrim covers: with the opt-in `cngx-drawer` class (stylesheet
313
+ * `@cngx/common/theming/components/cngx-drawer.css`, part of the cngx
314
+ * bundle) the host places the panel on its side, lets the content fill the
315
+ * rest and paints a scrim over itself while a modal panel inside it is
316
+ * open. Keep an app header that must stay live outside the host.
317
+ *
318
+ * ### With a panel trigger
319
+ * ```html
320
+ * <button type="button" [cngxPanelTrigger]="drawer">Menu</button>
321
+ * <div cngxDrawer #drawer="cngxDrawer" panelId="main-nav">
322
+ * <nav [cngxDrawerPanel]="drawer">…</nav>
323
+ * </div>
324
+ * ```
142
325
  *
143
326
  * ### Uncontrolled
144
327
  * ```html
@@ -157,27 +340,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
157
340
  * </div>
158
341
  * ```
159
342
  *
160
- * @category common/layout
161
- * @docsKind primary
162
343
  * @wcag AA
163
344
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer.directive.ts
164
- * @since 0.1.0
345
+ * @since 0.3.0
165
346
  * @relatedTo CngxDrawerPanel, CngxDrawerContent, CngxBackdrop, CngxScrollLock
166
- * <example-url>http://localhost:4200/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
167
- * <example-url>http://localhost:4200/#/common/layout/drawer/controlled-mode</example-url>
168
- * <example-url>http://localhost:4200/#/common/layout/drawer/direction-all-four-sides</example-url>
169
- * <example-url>http://localhost:4200/#/common/layout/drawer/events-openedchange-closed</example-url>
170
- * <example-url>http://localhost:4200/#/common/layout/drawer/mode-over-push-side</example-url>
171
- * <example-url>http://localhost:4200/#/common/layout/drawer/pattern-consumer-wiring</example-url>
347
+ * <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
348
+ * <example-url>/#/common/layout/drawer/controlled-mode</example-url>
349
+ * <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
350
+ * <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
351
+ * <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
352
+ * <example-url>/#/common/layout/drawer/full-height-modal</example-url>
353
+ * <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
354
+ * <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
355
+ * @axis level organism
172
356
  */
173
357
  class CngxDrawer {
174
- /** @internal Host element ref - used by `CngxDrawerPanel` for click-outside containment. */
358
+ /** @internal Host element ref. */
175
359
  elementRef = inject((ElementRef));
360
+ host = inject(ElementRef).nativeElement;
361
+ /**
362
+ * The `id` of the drawer's panel element. `CngxDrawerPanel` renders it as
363
+ * its `id` unless the panel carries a static one, and a panel trigger
364
+ * points `aria-controls` at it.
365
+ */
366
+ panelId = input(undefined, ...(ngDevMode ? [{ debugName: "panelId" }] : /* istanbul ignore next */ []));
176
367
  /** Controlled opened state. When bound, takes precedence over internal state. */
177
368
  openedInput = input(undefined, { ...(ngDevMode ? { debugName: "openedInput" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerOpened' });
178
369
  openedState = signal(false, ...(ngDevMode ? [{ debugName: "openedState" }] : /* istanbul ignore next */ []));
179
370
  /** Resolved opened state - controlled input wins over internal state. */
180
371
  opened = computed(() => this.openedInput() ?? this.openedState(), ...(ngDevMode ? [{ debugName: "opened" }] : /* istanbul ignore next */ []));
372
+ /** {@link CngxPanelTarget} view of {@link panelId}; empty when unset. */
373
+ id = computed(() => this.panelId() ?? '', ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
374
+ /** {@link CngxPanelTarget} view of {@link opened}. */
375
+ expanded = this.opened;
376
+ panelSlot = createSlotRegistry();
377
+ /** {@link CngxPanelTarget} view of the panel's `mode`; `over` until a panel registers. */
378
+ mode = computed(() => this.panelSlot.current()?.mode() ?? 'over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
379
+ /**
380
+ * {@link CngxPanelTarget}: whether the panel's resolved modality blocks
381
+ * anything; `false` until a panel connects, like an unset `modal`.
382
+ */
383
+ modal = computed(() => this.panelSlot.current()?.modal() ?? false, ...(ngDevMode ? [{ debugName: "modal" }] : /* istanbul ignore next */ []));
384
+ /** {@link CngxPanelTarget} view of the panel's `position`; `left` until a panel registers. */
385
+ side = computed(() => this.panelSlot.current()?.position() ?? 'left', ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
181
386
  /** Emitted when the opened state changes. Wire to a signal for two-way binding. */
182
387
  openedChange = output();
183
388
  /** Emitted when the drawer closes. Convenience shorthand for close-only listeners. */
@@ -199,6 +404,27 @@ class CngxDrawer {
199
404
  this.openedChange.emit(false);
200
405
  this.closed.emit();
201
406
  }
407
+ // The open panel's surface already closed the drawer for an Escape inside
408
+ // it. A controlled drawer still reads the bound input as open until the
409
+ // owner writes it back, so a second close() here would emit twice. An open
410
+ // popover inside the drawer (a menu in the content) takes the keypress
411
+ // first.
412
+ handleEscape(event) {
413
+ if (!this.opened() || escapeOwnedAbove(event, this.host)) {
414
+ return;
415
+ }
416
+ const panel = this.panelSlot.current()?.element;
417
+ if (panel && event.target instanceof Node && panel.contains(event.target)) {
418
+ return;
419
+ }
420
+ claimEscape(event);
421
+ this.close();
422
+ }
423
+ /** {@link CngxDrawerHost}: connects a panel; the latest panel wins. */
424
+ connectPanel(panel) {
425
+ this.panelSlot.register(panel);
426
+ return () => this.panelSlot.unregister(panel);
427
+ }
202
428
  /** Toggles the drawer between open and closed. */
203
429
  toggle() {
204
430
  if (this.opened()) {
@@ -209,7 +435,10 @@ class CngxDrawer {
209
435
  }
210
436
  }
211
437
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, deps: [], target: i0.ɵɵFactoryTarget.Directive });
212
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawer, isStandalone: true, selector: "[cngxDrawer]", inputs: { openedInput: { classPropertyName: "openedInput", publicName: "cngxDrawerOpened", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { openedChange: "openedChange", closed: "closed" }, host: { listeners: { "keydown.escape": "close()" }, properties: { "class.cngx-drawer--opened": "opened()" } }, exportAs: ["cngxDrawer"], ngImport: i0 });
438
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawer, isStandalone: true, selector: "[cngxDrawer]", inputs: { panelId: { classPropertyName: "panelId", publicName: "panelId", isSignal: true, isRequired: false, transformFunction: null }, openedInput: { classPropertyName: "openedInput", publicName: "cngxDrawerOpened", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { openedChange: "openedChange", closed: "closed" }, host: { listeners: { "keydown.escape": "handleEscape($event)" }, properties: { "class.cngx-drawer--opened": "opened()" } }, providers: [
439
+ { provide: CNGX_PANEL_TARGET, useExisting: CngxDrawer },
440
+ { provide: CNGX_DRAWER_HOST, useExisting: CngxDrawer },
441
+ ], exportAs: ["cngxDrawer"], ngImport: i0 });
213
442
  }
214
443
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, decorators: [{
215
444
  type: Directive,
@@ -217,137 +446,867 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
217
446
  selector: '[cngxDrawer]',
218
447
  exportAs: 'cngxDrawer',
219
448
  standalone: true,
449
+ providers: [
450
+ { provide: CNGX_PANEL_TARGET, useExisting: CngxDrawer },
451
+ { provide: CNGX_DRAWER_HOST, useExisting: CngxDrawer },
452
+ ],
220
453
  host: {
221
454
  '[class.cngx-drawer--opened]': 'opened()',
222
- '(keydown.escape)': 'close()',
455
+ '(keydown.escape)': 'handleEscape($event)',
223
456
  },
224
457
  }]
225
- }], propDecorators: { openedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerOpened", required: false }] }], openedChange: [{ type: i0.Output, args: ["openedChange"] }], closed: [{ type: i0.Output, args: ["closed"] }] } });
458
+ }], propDecorators: { panelId: [{ type: i0.Input, args: [{ isSignal: true, alias: "panelId", required: false }] }], openedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerOpened", required: false }] }], openedChange: [{ type: i0.Output, args: ["openedChange"] }], closed: [{ type: i0.Output, args: ["closed"] }] } });
226
459
 
227
460
  /**
228
- * The sliding panel of a drawer. Reads its open state from an explicit
229
- * `[cngxDrawerPanel]` reference - no ancestor injection.
461
+ * The English layout section: the single source of the layout atoms'
462
+ * English copy. `CNGX_LAYOUT_I18N` defaults to it.
463
+ *
464
+ * @since 0.3.0
465
+ * @relatedTo CNGX_LAYOUT_I18N
466
+ */
467
+ const CNGX_LAYOUT_LANGUAGE_EN = {
468
+ expandableTextMore: 'Show more',
469
+ expandableTextLess: 'Show less',
470
+ resizeHandle: 'Resize',
471
+ resizeValueText: '{size} pixels',
472
+ panelTrigger: 'Panel',
473
+ sidebarRegion: 'Sidebar',
474
+ drawerDialog: 'Drawer',
475
+ };
476
+
477
+ /** @internal The English section with the active pack's layout section on top. */
478
+ const injectLayoutSection = createLanguageSection('layout', CNGX_LAYOUT_LANGUAGE_EN);
479
+ /** @internal Turns a layout section into the token's keys for a locale. */
480
+ function layoutBundleFrom(section, locale) {
481
+ return {
482
+ expandableTextMore: section.expandableTextMore,
483
+ expandableTextLess: section.expandableTextLess,
484
+ resizeHandle: section.resizeHandle,
485
+ resizeValueText: (size) => formatMessage(section.resizeValueText, { size }, locale),
486
+ panelTrigger: section.panelTrigger,
487
+ sidebarRegion: section.sidebarRegion,
488
+ drawerDialog: section.drawerDialog,
489
+ };
490
+ }
491
+ /** @internal Builds and reads the token, formatted for the reading locale. */
492
+ const layoutBundle = createSectionBundle({
493
+ section: injectLayoutSection,
494
+ toBundle: layoutBundleFrom,
495
+ });
496
+ /**
497
+ * DI token for the layout i18n bundle. `providedIn: 'root'`: the layout
498
+ * section of the active language pack over the English defaults; the value
499
+ * is a `Signal`, shared by every reader under one injector.
500
+ *
501
+ * @wcag AA
502
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/i18n/layout-i18n.ts
503
+ * @since 0.3.0
504
+ * @relatedTo CngxExpandableText, CngxResizable, CngxPanelTrigger, CngxSidebar, CngxDrawerPanel
505
+ */
506
+ const CNGX_LAYOUT_I18N = new InjectionToken('CngxLayoutI18n', {
507
+ providedIn: 'root',
508
+ factory: () => layoutBundle.build(),
509
+ });
510
+ /**
511
+ * Override layout labels via a partial bundle - unset keys keep the
512
+ * language pack's copy, or the English default. Pass a `Signal` of a partial
513
+ * bundle to switch languages at runtime.
514
+ *
515
+ * @since 0.3.0
516
+ */
517
+ function withLayoutI18nLabels(overrides) {
518
+ return (bundle) => createOverrideMerge(bundle, overrides);
519
+ }
520
+ /**
521
+ * Provider for the layout i18n bundle. Returns a plain `Provider`, so it
522
+ * also scopes a subtree through `viewProviders`. The features apply on top
523
+ * of the active language pack.
524
+ *
525
+ * ```ts
526
+ * bootstrapApplication(AppComponent, {
527
+ * providers: [
528
+ * provideLayoutI18n(
529
+ * withLayoutI18nLabels({ expandableTextMore: 'Mehr anzeigen', expandableTextLess: 'Weniger anzeigen' }),
530
+ * ),
531
+ * ],
532
+ * });
533
+ * ```
534
+ *
535
+ * @since 0.3.0
536
+ */
537
+ function provideLayoutI18n(...features) {
538
+ return {
539
+ provide: CNGX_LAYOUT_I18N,
540
+ useFactory: () => layoutBundle.build(features),
541
+ };
542
+ }
543
+ /**
544
+ * Inject the resolved layout i18n bundle signal. Read it inside a
545
+ * `computed()` or template so a runtime override flip re-derives.
230
546
  *
231
- * Composes `CngxFocusTrap` as a `hostDirective` - the consumer controls
232
- * the `[enabled]` and `[autoFocus]` inputs from the template.
547
+ * @since 0.3.0
548
+ */
549
+ function injectLayoutI18n() {
550
+ return layoutBundle.resolve(inject(CNGX_LAYOUT_I18N));
551
+ }
552
+
553
+ /**
554
+ * Ref-count per locked element. Module-private on purpose: this file is the
555
+ * single owner of the lock state. A second copy of this map (the pre-extraction
556
+ * state: one in `CngxScrollLock`, one in `CngxDialog`) shares the dataset keys
557
+ * below without sharing the count, so interleaved acquire/release across the
558
+ * two owners corrupts each other's saved overflow values.
559
+ *
560
+ * @internal
561
+ */
562
+ const lockCounts = new WeakMap();
563
+ /**
564
+ * Acquire a ref-counted scroll lock on an element and get back the matching
565
+ * release function.
566
+ *
567
+ * The target is the element that scrolls: the document root
568
+ * (`document.documentElement`) for the page, or any scroll container (a
569
+ * panel with `overflow-y: auto`) for a surface that overlays only that
570
+ * container. Each element keeps its own count, so locks on two containers
571
+ * never interfere.
572
+ *
573
+ * The first active lock on a target saves its inline `overflow` /
574
+ * `scrollbar-gutter` and sets `overflow: hidden` + `scrollbar-gutter: stable`
575
+ * (no layout shift when the scrollbar disappears). Releasing the last active
576
+ * lock on that target restores the saved values. The returned release
577
+ * function is idempotent - calling it twice cannot over-decrement the count.
578
+ *
579
+ * Shared engine behind `CngxScrollLock` and `CngxDialog`'s modal scroll lock;
580
+ * consumers composing their own overlay primitives can use it directly.
581
+ *
582
+ * ```typescript
583
+ * const release = createScrollLock(document.documentElement);
584
+ * // ... overlay open ...
585
+ * release();
586
+ * ```
587
+ *
588
+ * @param target - The scrolling element to lock.
589
+ * @returns Release function for this acquisition. Idempotent.
590
+ *
591
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
592
+ * @since 0.3.0
593
+ * @relatedTo CngxScrollLock, CngxDialog
594
+ */
595
+ function createScrollLock(target) {
596
+ const count = lockCounts.get(target) ?? 0;
597
+ if (count === 0) {
598
+ target.dataset['cngxPrevOverflow'] = target.style.overflow;
599
+ target.dataset['cngxPrevScrollbarGutter'] = target.style.scrollbarGutter;
600
+ target.style.overflow = 'hidden';
601
+ target.style.scrollbarGutter = 'stable';
602
+ }
603
+ lockCounts.set(target, count + 1);
604
+ let released = false;
605
+ return () => {
606
+ if (released) {
607
+ return;
608
+ }
609
+ released = true;
610
+ const current = lockCounts.get(target) ?? 0;
611
+ if (current <= 1) {
612
+ target.style.overflow = target.dataset['cngxPrevOverflow'] ?? '';
613
+ target.style.scrollbarGutter = target.dataset['cngxPrevScrollbarGutter'] ?? '';
614
+ delete target.dataset['cngxPrevOverflow'];
615
+ delete target.dataset['cngxPrevScrollbarGutter'];
616
+ lockCounts.set(target, 0);
617
+ }
618
+ else {
619
+ lockCounts.set(target, current - 1);
620
+ }
621
+ };
622
+ }
623
+ // The body properties the pin writes. Only these are saved and restored, so a
624
+ // style another owner sets on body while the pin is held survives the release.
625
+ const PINNED_BODY_PROPERTIES = ['position', 'top', 'inset-inline', 'overflow'];
626
+ /**
627
+ * Pin state per document root, separate from `lockCounts`: a pin also holds
628
+ * one `createScrollLock` acquisition, so the html overflow stays shared with
629
+ * every other owner.
630
+ *
631
+ * @internal
632
+ */
633
+ const pins = new WeakMap();
634
+ /**
635
+ * Acquire a ref-counted scroll lock that pins the page body in place, for
636
+ * overlays that must hold on iOS Safari.
233
637
  *
234
- * Optionally closes the drawer when the user clicks outside the panel
235
- * (`closeOnClickOutside`, default `true`). The click that opened the
236
- * drawer never counts as an outside click. While closed (except in
237
- * `side` mode) the panel is `aria-hidden` AND `inert`, so its focusable
238
- * children are unreachable for keyboard and AT alike. On close, focus
239
- * returns to the element that was focused when the drawer opened -
240
- * unless the user moved focus to another focusable element themselves
241
- * (a click on a focusable outside target keeps its focus).
638
+ * `overflow: hidden` on the root does not stop iOS Safari from scrolling a
639
+ * page that was already scrolled, and the visual viewport drifts with it, so
640
+ * a bottom-fixed overlay ends above the visible bottom. The first pin saves
641
+ * the body's inline `position`, `top`, `inset-inline` and `overflow` and the
642
+ * scroll position, fixes the body at `top: -scrollY`, and acquires
643
+ * {@link createScrollLock} on the root. The last
644
+ * release restores the body, releases the root lock and scrolls back to the
645
+ * saved position. The returned release function is idempotent.
646
+ *
647
+ * `CngxDialog` and `CngxScrollLock` keep {@link createScrollLock}; reach for
648
+ * this one when the overlay is pinned to the viewport bottom on touch devices.
649
+ *
650
+ * ```typescript
651
+ * const release = createPinnedScrollLock(document.documentElement);
652
+ * // ... sheet open ...
653
+ * release();
654
+ * ```
242
655
  *
243
- * The `role` input defaults to `complementary`. On a `<nav>` host pass
244
- * `[role]="null"` so the implicit navigation landmark survives:
656
+ * @param html - The document root (`document.documentElement`) to lock.
657
+ * @returns Release function for this acquisition. Idempotent.
658
+ *
659
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
660
+ * @since 0.3.0
661
+ * @relatedTo createScrollLock, CngxPopoverSheet
662
+ */
663
+ function createPinnedScrollLock(html) {
664
+ const body = html.ownerDocument.body;
665
+ const view = html.ownerDocument.defaultView;
666
+ const existing = pins.get(html);
667
+ if (existing) {
668
+ existing.count += 1;
669
+ }
670
+ else {
671
+ const scrollX = view?.scrollX ?? 0;
672
+ const scrollY = view?.scrollY ?? 0;
673
+ pins.set(html, {
674
+ count: 1,
675
+ saved: new Map(PINNED_BODY_PROPERTIES.map((name) => [
676
+ name,
677
+ {
678
+ value: body.style.getPropertyValue(name),
679
+ priority: body.style.getPropertyPriority(name),
680
+ },
681
+ ])),
682
+ scrollX,
683
+ scrollY,
684
+ releaseHtml: createScrollLock(html),
685
+ });
686
+ body.style.position = 'fixed';
687
+ body.style.top = `${-scrollY}px`;
688
+ body.style.insetInline = '0';
689
+ body.style.overflow = 'hidden';
690
+ }
691
+ let released = false;
692
+ return () => {
693
+ if (released) {
694
+ return;
695
+ }
696
+ released = true;
697
+ const state = pins.get(html);
698
+ if (!state) {
699
+ return;
700
+ }
701
+ state.count -= 1;
702
+ if (state.count > 0) {
703
+ return;
704
+ }
705
+ pins.delete(html);
706
+ for (const [name, { value, priority }] of state.saved) {
707
+ if (value) {
708
+ body.style.setProperty(name, value, priority);
709
+ }
710
+ else {
711
+ body.style.removeProperty(name);
712
+ }
713
+ }
714
+ state.releaseHtml();
715
+ view?.scrollTo({ left: state.scrollX, top: state.scrollY, behavior: 'instant' });
716
+ };
717
+ }
718
+
719
+ /** @internal See {@link CngxDrawerSurfaceDriver}. */
720
+ const CNGX_DRAWER_SURFACE_DRIVER = new InjectionToken('CngxDrawerSurfaceDriver');
721
+ const SCROLLING_OVERFLOW = new Set(['auto', 'scroll']);
722
+ /**
723
+ * The transient-surface behaviour of a drawer or an overlay rail, with an
724
+ * explicit modality.
725
+ *
726
+ * While `active`, the surface asks to be dismissed on Escape with focus
727
+ * inside (in every browser: the close Chromium derives from an Escape
728
+ * keypress is not a back gesture and is dropped), on the platform back
729
+ * gesture (`CloseWatcher`) and on a press outside the
730
+ * host. A press on the element whose `aria-controls` names the host `id` is
731
+ * not outside, so the trigger can toggle the surface itself. One Escape
732
+ * dismisses one layer: an inner surface or an open popover inside the host
733
+ * (a menu, a select panel) takes the keypress first. Focus returns
734
+ * to the element focused at activation when the surface deactivates.
735
+ *
736
+ * `modality` decides how far the engaged surface takes over the page:
737
+ *
738
+ * - `'page'` (default) additionally traps focus, renders `role="dialog"` +
739
+ * `aria-modal="true"`, makes everything outside the host `inert` up to
740
+ * `<body>` (the siblings of the host and of every ancestor, like a modal
741
+ * dialog) and locks scrolling on the nearest scroll container above the
742
+ * host (the nearest ancestor with a computed `overflow-y` of `auto` or
743
+ * `scroll`, else the document root).
744
+ * - `'contained'` does the same inside a boundary only: the host's siblings
745
+ * inside the boundary are `inert`, the nearest scroll container between
746
+ * the host and the boundary (inclusive) is locked if there is one, and
747
+ * nothing outside the boundary is touched. The element whose `aria-controls`
748
+ * names the host stays live wherever it sits. No trap and no
749
+ * `aria-modal` (the page around the boundary is operable, so the surface
750
+ * must not claim it is not); the landmark role stays and focus moves to
751
+ * the first tabbable element inside the host on activation. The
752
+ * boundary is the host's parent element unless a composer names one
753
+ * (`CngxDrawerPanel` names its `[cngxDrawer]` host).
754
+ * - `'none'` keeps the page around it operable: no trap, no lock, no
755
+ * inert, the landmark `role` (default `complementary`, `null` keeps the
756
+ * host's implicit role).
757
+ *
758
+ * In every modality focus-trap anchors, live regions, the CDK overlay
759
+ * container, the toast and banner outlets and a visible `CngxBackdrop` stay
760
+ * live, and an `inert` set by someone else is kept on release. Escape, the
761
+ * back gesture and an outside press ask for dismissal in all three.
762
+ *
763
+ * The surface does not own the open state: it reports `dismiss` and the
764
+ * owner decides. It composes `CngxFocusTrap`, `CngxFocusRestore` and
765
+ * `CngxClickOutside` and drives them; none of their inputs is re-exposed.
766
+ *
767
+ * ```html
768
+ * <aside id="filters" cngxDrawerSurface [active]="open()" modality="none"
769
+ * (dismiss)="open.set(false)">…</aside>
770
+ * <button aria-controls="filters" [attr.aria-expanded]="open()"
771
+ * (click)="open.set(!open())">Filters</button>
772
+ * ```
773
+ *
774
+ * `CngxDrawerPanel` hosts the surface for drawers; consumers rarely bind it
775
+ * directly.
776
+ *
777
+ * @wcag AA
778
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-surface.directive.ts
779
+ * @since 0.3.0
780
+ * @relatedTo CngxDrawerPanel, CngxFocusTrap, CngxFocusRestore, CngxClickOutside, createScrollLock
781
+ * <example-url>/#/common/layout/drawer/standalone-surface</example-url>
782
+ * @axis level molecule
783
+ */
784
+ class CngxDrawerSurface {
785
+ /**
786
+ * Whether the surface is engaged (the drawer or overlay is open). Bind it
787
+ * to the owner's open state.
788
+ */
789
+ active = input(false, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
790
+ /**
791
+ * How far the engaged surface takes over the page: `'page'` (modal dialog,
792
+ * inert up to `<body>`), `'contained'` (inert and scroll lock inside the
793
+ * boundary only, no trap) or `'none'`. See {@link CngxDrawerModality}.
794
+ */
795
+ modality = input('page', ...(ngDevMode ? [{ debugName: "modality" }] : /* istanbul ignore next */ []));
796
+ /**
797
+ * Landmark role while the surface is not an engaged page modal. Defaults
798
+ * to `complementary`; pass `navigation` for a nav surface, or `null` on a
799
+ * `<nav>` / `<aside>` host to keep its implicit role. A composer's driver
800
+ * wins over it.
801
+ */
802
+ role = input('complementary', ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
803
+ /**
804
+ * Accessible name of the surface. An engaged page modal (a `dialog`)
805
+ * without one falls back to a static `aria-label` on the host, then to
806
+ * `CNGX_LAYOUT_I18N.drawerDialog`; a host with a static `aria-labelledby`
807
+ * keeps that name. Outside an engaged page modal only a bound label or a
808
+ * static `aria-label` names the landmark.
809
+ */
810
+ labelInput = input(undefined, { ...(ngDevMode ? { debugName: "labelInput" } : /* istanbul ignore next */ {}), alias: 'label' });
811
+ /**
812
+ * Emitted when the user asks to dismiss the engaged surface: Escape, the
813
+ * back gesture, or a press outside the host. The owner closes it.
814
+ */
815
+ dismiss = output();
816
+ injector = inject(Injector);
817
+ host = inject(ElementRef).nativeElement;
818
+ doc = inject(DOCUMENT);
819
+ domReady = signal(false, ...(ngDevMode ? [{ debugName: "domReady" }] : /* istanbul ignore next */ []));
820
+ focusTrap = inject(CngxFocusTrap, { self: true });
821
+ i18n = injectLayoutI18n();
822
+ staticLabel = inject(new HostAttributeToken('aria-label'), { optional: true });
823
+ staticLabelledBy = inject(new HostAttributeToken('aria-labelledby'), {
824
+ optional: true,
825
+ });
826
+ staticTabindex = inject(new HostAttributeToken('tabindex'), { optional: true });
827
+ destroyed = false;
828
+ // Chromium also turns an unhandled Escape keydown, wherever focus is, into
829
+ // a CloseWatcher close. Escape belongs to the keydown path (focus inside
830
+ // the host, the drawer for its content), so a watcher close from the same
831
+ // keypress is not a back gesture. The flag lives for the keydown task only.
832
+ escapeKeyTimer = null;
833
+ escapeKeydown = (event) => {
834
+ if (event.key !== 'Escape') {
835
+ return;
836
+ }
837
+ this.clearEscapeKey();
838
+ this.escapeKeyTimer = setTimeout(() => {
839
+ this.escapeKeyTimer = null;
840
+ });
841
+ };
842
+ // Swallows the click that trails the outside press which dismissed an
843
+ // engaged page modal. iOS Safari fires pointerdown at touchstart but hit
844
+ // tests the synthesized click again after touchend; by then the dismissal
845
+ // has dropped `inert` and the click lands on the live opener, reopening it.
846
+ releaseTrailingClick = null;
847
+ resolvedDriver = undefined;
848
+ driver() {
849
+ if (this.resolvedDriver === undefined) {
850
+ this.resolvedDriver = this.injector.get(CNGX_DRAWER_SURFACE_DRIVER, null, { self: true });
851
+ }
852
+ return this.resolvedDriver;
853
+ }
854
+ /** Whether the surface is engaged, after the driver. */
855
+ isActive = computed(() => this.driver()?.surfaceActive() ?? this.active(), ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
856
+ /** The modality of the surface, after the driver. */
857
+ resolvedModality = computed(() => this.driver()?.surfaceModality() ?? this.modality(), ...(ngDevMode ? [{ debugName: "resolvedModality" }] : /* istanbul ignore next */ []));
858
+ /** The modality while engaged; `'none'` while the surface is not active. */
859
+ engagedModality = computed(() => this.isActive() ? this.resolvedModality() : 'none', ...(ngDevMode ? [{ debugName: "engagedModality" }] : /* istanbul ignore next */ []));
860
+ engagedPage = computed(() => this.engagedModality() === 'page', ...(ngDevMode ? [{ debugName: "engagedPage" }] : /* istanbul ignore next */ []));
861
+ /**
862
+ * @internal Hotkey scope of the surface subtree: modal while engaged as
863
+ * `'page'` or `'contained'`, so app bindings outside stay quiet while focus
864
+ * is inside. Always active: the drawer's own bindings (toggle, close) must
865
+ * fire whether the surface is engaged or not.
866
+ */
867
+ hotkeyScope = createHotkeyScope({
868
+ element: this.host,
869
+ modal: computed(() => this.engagedModality() !== 'none'),
870
+ parent: inject(CNGX_HOTKEY_SCOPE, { optional: true, skipSelf: true }),
871
+ destroyRef: inject(DestroyRef),
872
+ });
873
+ surfaceRole = computed(() => {
874
+ if (this.engagedPage()) {
875
+ return 'dialog';
876
+ }
877
+ const landmark = this.driver()?.surfaceLandmarkRole;
878
+ return landmark ? landmark() : this.role();
879
+ }, ...(ngDevMode ? [{ debugName: "surfaceRole" }] : /* istanbul ignore next */ []));
880
+ // A static aria-label or aria-labelledby names the host already; the
881
+ // fallback only fills a nameless engaged dialog.
882
+ namesWithFallback = computed(() => this.engagedPage() && this.staticLabel === null && this.staticLabelledBy === null, ...(ngDevMode ? [{ debugName: "namesWithFallback" }] : /* istanbul ignore next */ []));
883
+ /**
884
+ * The resolved accessible name: the bound `label`, else a static
885
+ * `aria-label`, else (engaged page modal without a static name)
886
+ * `CNGX_LAYOUT_I18N.drawerDialog`.
887
+ */
888
+ label = computed(() => {
889
+ const driven = this.driver()?.surfaceLabel;
890
+ if (driven) {
891
+ return driven();
892
+ }
893
+ return this.namesWithFallback()
894
+ ? (this.labelInput() ?? this.i18n().drawerDialog)
895
+ : (this.labelInput() ?? this.staticLabel ?? undefined);
896
+ }, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
897
+ ariaLabel = computed(() => this.label() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
898
+ /** @internal Drives the composed `CngxFocusTrap`. */
899
+ focusTrapEnabled = this.engagedPage;
900
+ /** @internal Drives the composed `CngxFocusTrap`. */
901
+ focusTrapAutoFocus = true;
902
+ /**
903
+ * @internal Drives the composed `CngxFocusRestore`. The restore edge can
904
+ * run before the scope effect below releases `inert` around the host; the
905
+ * restore then focuses the opener after the render, once it is live.
906
+ */
907
+ focusRestoreActive = this.isActive;
908
+ /**
909
+ * @internal Drives the composed `CngxFocusRestore`: when the surface was
910
+ * engaged with focus already inside it (a docked rail that turned into a
911
+ * drawer), there is no opener to return to, so focus goes to the element
912
+ * whose `aria-controls` names the host, the same relation an outside press
913
+ * is exempted by.
914
+ */
915
+ focusRestoreFallback() {
916
+ const id = this.host.id;
917
+ if (!id) {
918
+ return null;
919
+ }
920
+ const trigger = this.doc.querySelector(`[aria-controls~="${id.replace(/["\\]/g, '\\$&')}"]`);
921
+ return trigger instanceof HTMLElement && !this.host.contains(trigger) ? trigger : null;
922
+ }
923
+ // A press on a non-focusable spot inside an engaged surface would drop
924
+ // focus to <body>, out of reach of the host Escape listener (and of the
925
+ // page modal's own boundary). tabindex="-1" keeps focus on the host there,
926
+ // like a native <dialog>; it adds no Tab stop. A consumer tabindex wins.
927
+ hostTabindex = computed(() => this.staticTabindex ?? (this.isActive() ? '-1' : null), ...(ngDevMode ? [{ debugName: "hostTabindex" }] : /* istanbul ignore next */ []));
928
+ /** @internal Drives the composed `CngxClickOutside`. */
929
+ clickOutsideEnabled = computed(() => this.isActive() && (this.driver()?.surfaceOutsideDismiss?.() ?? true), ...(ngDevMode ? [{ debugName: "clickOutsideEnabled" }] : /* istanbul ignore next */ []));
930
+ closeWatcher = createCloseWatcher(() => this.handleCloseRequest(), injectWindow());
931
+ constructor() {
932
+ afterNextRender(() => this.domReady.set(true));
933
+ inject(DestroyRef).onDestroy(() => {
934
+ this.destroyed = true;
935
+ this.clearEscapeKey();
936
+ this.closeWatcher.disarm();
937
+ this.releaseTrailingClick?.();
938
+ });
939
+ inject(CngxClickOutside, { self: true }).clickOutside.subscribe(() => {
940
+ if (untracked(this.engagedPage)) {
941
+ this.swallowTrailingClick();
942
+ }
943
+ this.requestDismiss();
944
+ });
945
+ effect((onCleanup) => {
946
+ if (!this.isActive()) {
947
+ return;
948
+ }
949
+ untracked(() => {
950
+ this.doc.addEventListener('keydown', this.escapeKeydown, true);
951
+ this.closeWatcher.arm();
952
+ });
953
+ onCleanup(() => {
954
+ this.doc.removeEventListener('keydown', this.escapeKeydown, true);
955
+ this.clearEscapeKey();
956
+ this.closeWatcher.disarm();
957
+ });
958
+ });
959
+ effect((onCleanup) => {
960
+ const modality = this.engagedModality();
961
+ if (!this.domReady() || modality === 'none') {
962
+ return;
963
+ }
964
+ const release = untracked(() => modality === 'page' ? this.holdPageScope() : this.holdContainedScope());
965
+ onCleanup(release);
966
+ });
967
+ }
968
+ holdPageScope() {
969
+ const releaseInert = createInertSiblings(this.host, { scope: 'outside' });
970
+ const releaseLock = createScrollLock(this.scrollScope(this.doc.documentElement));
971
+ return () => {
972
+ releaseInert();
973
+ releaseLock();
974
+ };
975
+ }
976
+ // No trap: focus moves in once, Tab may leave for the live page around
977
+ // the boundary. The trap's focusFirst() waits for the render that drops
978
+ // the closed panel's inert.
979
+ holdContainedScope() {
980
+ const boundary = this.containedBoundary();
981
+ const id = this.host.id;
982
+ const releaseInert = createInertSiblings(this.host, {
983
+ scope: 'outside',
984
+ within: boundary,
985
+ keepLive: id ? `[aria-controls~="${id.replace(/["\\]/g, '\\$&')}"]` : undefined,
986
+ });
987
+ const scroller = this.scrollScope(null, boundary);
988
+ const releaseLock = scroller ? createScrollLock(scroller) : null;
989
+ this.focusTrap.focusFirst();
990
+ return () => {
991
+ releaseInert();
992
+ releaseLock?.();
993
+ };
994
+ }
995
+ containedBoundary() {
996
+ const named = this.driver()?.surfaceBoundary?.();
997
+ if (named && named !== this.host && named.contains(this.host)) {
998
+ return named;
999
+ }
1000
+ return this.host.parentElement ?? this.doc.body;
1001
+ }
1002
+ // An inner surface or an open popover inside the host takes the keypress
1003
+ // first; one Escape dismisses one layer.
1004
+ handleEscape(event) {
1005
+ if (!this.isActive() || escapeOwnedAbove(event, this.host)) {
1006
+ return;
1007
+ }
1008
+ claimEscape(event);
1009
+ this.emitDismiss();
1010
+ }
1011
+ clearEscapeKey() {
1012
+ if (this.escapeKeyTimer !== null) {
1013
+ clearTimeout(this.escapeKeyTimer);
1014
+ this.escapeKeyTimer = null;
1015
+ }
1016
+ }
1017
+ handleCloseRequest() {
1018
+ if (this.escapeKeyTimer === null) {
1019
+ this.emitDismiss();
1020
+ }
1021
+ this.rearmIfEngaged();
1022
+ }
1023
+ // One shot: the next click is the trailing one of the dismissing gesture.
1024
+ // A gesture that ends without a click (a scroll, a cancelled touch) is
1025
+ // followed by a pointerdown or a keydown before any later click, so either
1026
+ // drops the guard. Listeners added during the dismissing pointerdown's
1027
+ // bubble phase do not see that same event.
1028
+ swallowTrailingClick() {
1029
+ this.releaseTrailingClick?.();
1030
+ const doc = this.doc;
1031
+ const swallow = (event) => {
1032
+ event.preventDefault();
1033
+ event.stopImmediatePropagation();
1034
+ release();
1035
+ };
1036
+ const release = () => {
1037
+ doc.removeEventListener('click', swallow, true);
1038
+ doc.removeEventListener('pointerdown', release, true);
1039
+ doc.removeEventListener('keydown', release, true);
1040
+ this.releaseTrailingClick = null;
1041
+ };
1042
+ doc.addEventListener('click', swallow, true);
1043
+ doc.addEventListener('pointerdown', release, true);
1044
+ doc.addEventListener('keydown', release, true);
1045
+ this.releaseTrailingClick = release;
1046
+ }
1047
+ requestDismiss() {
1048
+ this.emitDismiss();
1049
+ this.rearmIfEngaged();
1050
+ }
1051
+ emitDismiss() {
1052
+ this.dismiss.emit();
1053
+ this.driver()?.surfaceDismiss();
1054
+ }
1055
+ // A blocked dismissal leaves the surface engaged; the spent watcher would
1056
+ // let the next back gesture leave the page.
1057
+ rearmIfEngaged() {
1058
+ if (!this.destroyed && untracked(this.isActive)) {
1059
+ this.closeWatcher.arm();
1060
+ }
1061
+ }
1062
+ // The nearest ancestor with a scrolling overflow-y, searched up to `stop`
1063
+ // (inclusive) or to the document root.
1064
+ scrollScope(fallback, stop) {
1065
+ const view = this.doc.defaultView;
1066
+ let node = this.host.parentElement;
1067
+ while (node && node !== this.doc.body && node !== this.doc.documentElement) {
1068
+ const overflowY = view?.getComputedStyle(node).overflowY ?? '';
1069
+ if (SCROLLING_OVERFLOW.has(overflowY)) {
1070
+ return node;
1071
+ }
1072
+ if (node === stop) {
1073
+ break;
1074
+ }
1075
+ node = node.parentElement;
1076
+ }
1077
+ return fallback;
1078
+ }
1079
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerSurface, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1080
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerSurface, isStandalone: true, selector: "[cngxDrawerSurface]", inputs: { active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null }, modality: { classPropertyName: "modality", publicName: "modality", isSignal: true, isRequired: false, transformFunction: null }, role: { classPropertyName: "role", publicName: "role", isSignal: true, isRequired: false, transformFunction: null }, labelInput: { classPropertyName: "labelInput", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dismiss: "dismiss" }, host: { listeners: { "keydown.escape": "handleEscape($event)" }, properties: { "attr.role": "surfaceRole()", "attr.aria-modal": "engagedPage() ? 'true' : null", "attr.aria-label": "ariaLabel()", "attr.tabindex": "hostTabindex()" } }, providers: [
1081
+ { provide: CNGX_FOCUS_TRAP_DRIVER, useExisting: CngxDrawerSurface },
1082
+ { provide: CNGX_FOCUS_RESTORE_DRIVER, useExisting: CngxDrawerSurface },
1083
+ { provide: CNGX_CLICK_OUTSIDE_DRIVER, useExisting: CngxDrawerSurface },
1084
+ { provide: CNGX_HOTKEY_SCOPE, useFactory: () => inject(CngxDrawerSurface).hotkeyScope },
1085
+ ], exportAs: ["cngxDrawerSurface"], hostDirectives: [{ directive: i1.CngxFocusTrap }, { directive: i1.CngxFocusRestore }, { directive: i2.CngxClickOutside }], ngImport: i0 });
1086
+ }
1087
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerSurface, decorators: [{
1088
+ type: Directive,
1089
+ args: [{
1090
+ selector: '[cngxDrawerSurface]',
1091
+ exportAs: 'cngxDrawerSurface',
1092
+ standalone: true,
1093
+ hostDirectives: [
1094
+ { directive: CngxFocusTrap, inputs: [], outputs: [] },
1095
+ { directive: CngxFocusRestore, inputs: [], outputs: [] },
1096
+ { directive: CngxClickOutside, inputs: [], outputs: [] },
1097
+ ],
1098
+ providers: [
1099
+ { provide: CNGX_FOCUS_TRAP_DRIVER, useExisting: CngxDrawerSurface },
1100
+ { provide: CNGX_FOCUS_RESTORE_DRIVER, useExisting: CngxDrawerSurface },
1101
+ { provide: CNGX_CLICK_OUTSIDE_DRIVER, useExisting: CngxDrawerSurface },
1102
+ { provide: CNGX_HOTKEY_SCOPE, useFactory: () => inject(CngxDrawerSurface).hotkeyScope },
1103
+ ],
1104
+ host: {
1105
+ '[attr.role]': 'surfaceRole()',
1106
+ '[attr.aria-modal]': "engagedPage() ? 'true' : null",
1107
+ '[attr.aria-label]': 'ariaLabel()',
1108
+ '[attr.tabindex]': 'hostTabindex()',
1109
+ '(keydown.escape)': 'handleEscape($event)',
1110
+ },
1111
+ }]
1112
+ }], ctorParameters: () => [], propDecorators: { active: [{ type: i0.Input, args: [{ isSignal: true, alias: "active", required: false }] }], modality: [{ type: i0.Input, args: [{ isSignal: true, alias: "modality", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }], labelInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], dismiss: [{ type: i0.Output, args: ["dismiss"] }] } });
1113
+
1114
+ /**
1115
+ * The sliding panel of a drawer. Reads its open state from an explicit
1116
+ * `[cngxDrawerPanel]` reference, or from the `CNGX_DRAWER_HOST` a
1117
+ * `CngxDrawer` on the same element provides when the attribute is bare - no
1118
+ * ancestor injection. Both go through the `CngxDrawerHost` contract, never
1119
+ * the concrete `CngxDrawer` class.
1120
+ *
1121
+ * The open panel is a transient surface (`CngxDrawerSurface`): Escape, the
1122
+ * Android back gesture and a press outside the panel close the drawer
1123
+ * (`closeOnClickOutside`, default `true`). A press on the trigger whose
1124
+ * `aria-controls` names the panel `id` is not outside, so the trigger
1125
+ * toggles the drawer itself. While closed the panel
1126
+ * is `aria-hidden` AND `inert`. On close, focus returns to the element that
1127
+ * was focused when the drawer opened - unless the user moved focus to
1128
+ * another element themselves.
1129
+ *
1130
+ * **Modality.** `modality` defaults to `'page'` for `over` and `'none'` for
1131
+ * `push`:
1132
+ *
1133
+ * - `'page'`: the open panel traps focus, renders `role="dialog"` +
1134
+ * `aria-modal="true"` (named by `label`, else a static `aria-label` /
1135
+ * `aria-labelledby`, else `CNGX_LAYOUT_I18N.drawerDialog`), makes
1136
+ * everything outside it `inert` up to `<body>`
1137
+ * (focus-trap anchors, live regions and a visible backdrop stay live) and
1138
+ * locks scrolling on the nearest scroll container above it (else the
1139
+ * document root). The full-height drawer that covers the app header.
1140
+ * - `'contained'`: the same inside the `[cngxDrawer]` host only. The
1141
+ * panel's siblings inside the host are `inert` and a scroll container
1142
+ * between the panel and the host is locked; everything outside the host
1143
+ * stays live. No trap and no `aria-modal`: focus moves into the panel on
1144
+ * open, returns to the opener on close, and Tab can reach the page
1145
+ * around the host. The clipped drawer below a live app header: place the
1146
+ * header outside `[cngxDrawer]`.
1147
+ * - `'none'`: the page around the panel stays operable.
1148
+ *
1149
+ * `push` is never modal: it lays the panel out next to the content, which
1150
+ * stays in use; `'page'` or `'contained'` with `push` resolve to `'none'`
1151
+ * and warn [`CNGX1076`](/error-codes/cngx1076.md) in development.
1152
+ *
1153
+ * **Scrim.** The panel renders `cngx-drawer-panel--modal` while its
1154
+ * resolved modality is `'page'` or `'contained'` (plus
1155
+ * `cngx-drawer-panel--contained` for the latter). The opt-in stylesheet
1156
+ * `cngx-drawer.css` skins the panel from its classes: add the `cngx-drawer`
1157
+ * class to the `[cngxDrawer]` host and the panel sits on its `position`
1158
+ * side with a surface and a border toward the content, slides in (in
1159
+ * `push` mode the content moves aside by its size), and the host shows a scrim over itself
1160
+ * while a modal panel inside it is open (`--cngx-drawer-scrim-bg`, default
1161
+ * `--cngx-backdrop-bg`). A press on the scrim is a press outside the panel
1162
+ * and closes the drawer. The panel sits above the scrim
1163
+ * (`--cngx-drawer-panel-z-index`, `2`, over `--cngx-drawer-scrim-z-index`,
1164
+ * `1`).
1165
+ *
1166
+ * The `role` input (landmark while not an open page modal) defaults to
1167
+ * `complementary`. On a `<nav>` host pass `[role]="null"` so the implicit
1168
+ * navigation landmark survives:
245
1169
  *
246
1170
  * ```html
247
- * <nav [cngxDrawerPanel]="drawer" position="left" mode="over" [role]="null"
248
- * [enabled]="drawer.opened()" [autoFocus]="true">
1171
+ * <button aria-controls="nav-panel" [attr.aria-expanded]="drawer.opened()"
1172
+ * (click)="drawer.toggle()">Menu</button>
1173
+ * <nav id="nav-panel" [cngxDrawerPanel]="drawer" position="left" mode="over" [role]="null">
249
1174
  * <a href="/home">Home</a>
250
1175
  * </nav>
251
1176
  * ```
252
1177
  *
253
- * @category common/layout
254
1178
  * @wcag AA
255
1179
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-panel.directive.ts
256
- * @since 0.1.0
1180
+ * @since 0.3.0
257
1181
  * @relatedTo CngxDrawer, CngxDrawerContent, CngxFocusTrap
258
- * <example-url>http://localhost:4200/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
259
- * <example-url>http://localhost:4200/#/common/layout/drawer/controlled-mode</example-url>
260
- * <example-url>http://localhost:4200/#/common/layout/drawer/direction-all-four-sides</example-url>
261
- * <example-url>http://localhost:4200/#/common/layout/drawer/events-openedchange-closed</example-url>
262
- * <example-url>http://localhost:4200/#/common/layout/drawer/mode-over-push-side</example-url>
263
- * <example-url>http://localhost:4200/#/common/layout/drawer/pattern-consumer-wiring</example-url>
1182
+ * <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
1183
+ * <example-url>/#/common/layout/drawer/controlled-mode</example-url>
1184
+ * <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
1185
+ * <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
1186
+ * <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
1187
+ * <example-url>/#/common/layout/drawer/full-height-modal</example-url>
1188
+ * <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
1189
+ * <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
264
1190
  */
265
1191
  class CngxDrawerPanel {
266
- /** Reference to the parent `CngxDrawer` state owner. */
267
- drawerRef = input.required({ ...(ngDevMode ? { debugName: "drawerRef" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerPanel' });
1192
+ /**
1193
+ * The drawer state owner (a `CngxDrawer`, or anything implementing
1194
+ * `CngxDrawerHost`). Bind it explicitly (`[cngxDrawerPanel]="drawer"`), or
1195
+ * leave the attribute bare on an element that also carries `cngxDrawer`.
1196
+ */
1197
+ drawerInput = input(undefined, { ...(ngDevMode ? { debugName: "drawerInput" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerPanel',
1198
+ transform: (v) => (typeof v === 'string' ? undefined : v) });
268
1199
  /** Direction the panel slides from. */
269
1200
  position = input('left', ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
270
1201
  /**
271
1202
  * How the panel interacts with the content area:
272
1203
  * - `'over'` (default) - overlays content (absolute positioned)
273
1204
  * - `'push'` - pushes content aside (content gets margin)
274
- * - `'side'` - always visible, no toggle behavior
275
1205
  */
276
1206
  mode = input('over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
277
- /** Whether clicking outside the panel closes the drawer. */
1207
+ /**
1208
+ * How much of the page the open panel blocks:
1209
+ *
1210
+ * - `'page'`: the whole page is blocked. The panel is a modal dialog,
1211
+ * focus is trapped in it and everything outside it is `inert` up to
1212
+ * `<body>`.
1213
+ * - `'contained'`: only the `[cngxDrawer]` host is blocked. The content
1214
+ * beside the panel is `inert` and scroll-locked, everything outside the
1215
+ * host (an app header above it) stays clickable, and focus moves into
1216
+ * the panel without being trapped.
1217
+ * - `'none'`: nothing is blocked. No `inert`, no lock, no trap.
1218
+ *
1219
+ * With the `cngx-drawer` stylesheet, `'page'` and `'contained'` show a
1220
+ * scrim over the `[cngxDrawer]` host. Unbound, it follows the mode: `over`
1221
+ * is `'page'`, `push` is `'none'`. `push` never blocks: `'page'` or
1222
+ * `'contained'` with `push` resolve to `'none'` and warn [`CNGX1076`](/error-codes/cngx1076.md) in
1223
+ * development. See {@link CngxDrawerModality}.
1224
+ */
1225
+ modality = input(undefined, ...(ngDevMode ? [{ debugName: "modality" }] : /* istanbul ignore next */ []));
1226
+ /** Whether a press outside the panel closes the drawer. */
278
1227
  closeOnClickOutside = input(true, ...(ngDevMode ? [{ debugName: "closeOnClickOutside" }] : /* istanbul ignore next */ []));
279
1228
  /**
280
- * Landmark role rendered on the panel. Defaults to `complementary`;
281
- * pass `navigation` for nav drawers or `null` to keep the element's
282
- * implicit role (e.g. on a `<nav>` host).
1229
+ * Landmark role rendered on the panel while it is not an open page modal
1230
+ * (an open `'page'` panel is a `dialog`; a `'contained'` one keeps this
1231
+ * role). Defaults to `complementary`; pass `navigation` for nav drawers or
1232
+ * `null` to keep the element's implicit role (e.g. on a `<nav>` host).
283
1233
  */
284
1234
  role = input('complementary', ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
285
- /** Whether the drawer is currently open (derived from the drawer ref). In `side` mode, always `true`. */
286
- isOpen = computed(() => this.mode() === 'side' || this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
287
- suppressOutsideClick = false;
288
- restoreTarget = null;
1235
+ hostDrawer = inject(CNGX_DRAWER_HOST, { self: true, optional: true });
1236
+ /** The resolved drawer: the explicit reference wins over a drawer host on the element. */
1237
+ drawerRef = computed(() => this.drawerInput() ?? this.hostDrawer, ...(ngDevMode ? [{ debugName: "drawerRef" }] : /* istanbul ignore next */ []));
1238
+ staticId = inject(new HostAttributeToken('id'), { optional: true });
1239
+ /** The panel's `id`: a static `id` attribute wins over the drawer's `panelId`. */
1240
+ panelId = computed(() => {
1241
+ const fromDrawer = this.drawerRef()?.panelId();
1242
+ if (this.staticId !== null) {
1243
+ return this.staticId;
1244
+ }
1245
+ return fromDrawer === undefined || fromDrawer === '' ? null : fromDrawer;
1246
+ }, ...(ngDevMode ? [{ debugName: "panelId" }] : /* istanbul ignore next */ []));
1247
+ /** Whether the drawer is currently open (derived from the drawer ref). */
1248
+ isOpen = computed(() => this.drawerRef()?.opened() ?? false, ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
1249
+ /** @internal Drives the composed `CngxDrawerSurface`. */
1250
+ surfaceActive = this.isOpen;
1251
+ /** @internal Drives the composed `CngxDrawerSurface`. */
1252
+ surfaceModality = computed(() => this.mode() === 'push' ? 'none' : (this.modality() ?? 'page'), ...(ngDevMode ? [{ debugName: "surfaceModality" }] : /* istanbul ignore next */ []));
1253
+ /** @internal Drives the composed `CngxDrawerSurface`: the `[cngxDrawer]` host. */
1254
+ surfaceBoundary = computed(() => this.drawerRef()?.elementRef.nativeElement ?? null, ...(ngDevMode ? [{ debugName: "surfaceBoundary" }] : /* istanbul ignore next */ []));
1255
+ /** @internal Drives the composed `CngxDrawerSurface`. */
1256
+ surfaceLandmarkRole = this.role;
1257
+ presentation = {
1258
+ mode: this.mode,
1259
+ modal: computed(() => this.surfaceModality() !== 'none'),
1260
+ position: this.position,
1261
+ element: inject(ElementRef).nativeElement,
1262
+ };
1263
+ /** @internal Drives the composed `CngxDrawerSurface`. */
1264
+ surfaceOutsideDismiss = this.closeOnClickOutside;
1265
+ connection = null;
289
1266
  constructor() {
290
- const doc = inject(DOCUMENT);
291
- const el = inject((ElementRef));
292
- // Focus restoration: closing puts `inert` on the panel, which would
293
- // silently drop focus to <body>. Capture the focused element at the
294
- // open transition and hand focus back at the close transition when
295
- // focus is still inside the panel (Escape) or already fell to <body>
296
- // (outside click on a non-focusable area). A focusable outside target
297
- // the user clicked keeps its focus.
298
- const openTransition = createTransitionTracker(() => this.isOpen());
299
- effect(() => {
300
- const open = openTransition.current();
301
- const wasOpen = openTransition.previous();
302
- if (open === wasOpen) {
303
- return;
304
- }
305
- untracked(() => {
306
- if (open) {
307
- const active = doc.activeElement;
308
- this.restoreTarget = active instanceof HTMLElement ? active : null;
1267
+ inject(DestroyRef).onDestroy(() => this.disconnect());
1268
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1269
+ effect(() => {
1270
+ const requested = this.modality();
1271
+ if (this.mode() !== 'push' || requested === undefined || requested === 'none') {
309
1272
  return;
310
1273
  }
311
- const active = doc.activeElement;
312
- const focusLost = active === null ||
313
- active === doc.body ||
314
- el.nativeElement.contains(active);
315
- if (focusLost && this.restoreTarget?.isConnected) {
316
- this.restoreTarget.focus();
317
- }
318
- this.restoreTarget = null;
1274
+ untracked(() => cngxDevWarn('CNGX1076', '[cngxDrawerPanel] mode="push" is never modal; a page or contained modality resolves to "none". ' +
1275
+ 'A push drawer lays out next to the content, which stays in use. ' +
1276
+ 'Use mode="over" for a modal drawer.', { modality: requested }));
319
1277
  });
320
- });
321
- // A click on a toggle OUTSIDE the container opens the drawer and then
322
- // bubbles on to the document listener below within the same dispatch -
323
- // without suppression it would close its own drawer instantly. The
324
- // openedChange emit is synchronous inside that dispatch; the flag is
325
- // lifted on the next macrotask, after the bubble phase has finished
326
- // (a microtask checkpoint can run between listeners of a native event).
327
- toObservable(this.drawerRef)
328
- .pipe(switchMap((drawer) => outputToObservable(drawer.openedChange)), takeUntilDestroyed())
329
- .subscribe((opened) => {
330
- if (opened) {
331
- this.suppressOutsideClick = true;
332
- setTimeout(() => (this.suppressOutsideClick = false));
333
- }
334
- });
335
- // Hit-test against the container, not the panel - toggle buttons and backdrops
336
- // sit inside the container and must not count as outside clicks.
337
- fromEvent(doc, 'click')
338
- .pipe(takeUntilDestroyed())
339
- .subscribe((e) => {
340
- if (!this.suppressOutsideClick &&
341
- this.mode() !== 'side' &&
342
- this.isOpen() &&
343
- this.closeOnClickOutside() &&
344
- !this.drawerRef().elementRef.nativeElement.contains(e.target)) {
345
- this.drawerRef().close();
346
- }
347
- });
1278
+ }
1279
+ }
1280
+ // Connecting registers the presentation in the drawer's slot, a signal
1281
+ // write; lifecycle hooks are no reactive context. ngOnChanges follows a
1282
+ // rebound reference, ngOnInit covers a panel without bound inputs.
1283
+ ngOnChanges() {
1284
+ this.syncConnection();
1285
+ }
1286
+ ngOnInit() {
1287
+ this.syncConnection();
1288
+ }
1289
+ syncConnection() {
1290
+ const drawer = untracked(this.drawerRef);
1291
+ if (this.connection?.drawer === drawer) {
1292
+ return;
1293
+ }
1294
+ this.disconnect();
1295
+ if (drawer) {
1296
+ this.connection = { drawer, disconnect: drawer.connectPanel(this.presentation) };
1297
+ }
1298
+ }
1299
+ disconnect() {
1300
+ const connection = this.connection;
1301
+ this.connection = null;
1302
+ connection?.disconnect();
1303
+ }
1304
+ /** @internal Drives the composed `CngxDrawerSurface`. */
1305
+ surfaceDismiss() {
1306
+ this.drawerRef()?.close();
348
1307
  }
349
1308
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
350
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerPanel", isSignal: true, isRequired: true, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, closeOnClickOutside: { classPropertyName: "closeOnClickOutside", publicName: "closeOnClickOutside", isSignal: true, isRequired: false, transformFunction: null }, role: { classPropertyName: "role", publicName: "role", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-drawer-panel": "true", "class.cngx-drawer-panel--open": "isOpen()", "class.cngx-drawer-panel--left": "position() === 'left'", "class.cngx-drawer-panel--right": "position() === 'right'", "class.cngx-drawer-panel--top": "position() === 'top'", "class.cngx-drawer-panel--bottom": "position() === 'bottom'", "class.cngx-drawer-panel--over": "mode() === 'over'", "class.cngx-drawer-panel--push": "mode() === 'push'", "class.cngx-drawer-panel--side": "mode() === 'side'", "attr.aria-hidden": "mode() !== 'side' && !isOpen() ? true : null", "attr.inert": "mode() !== 'side' && !isOpen() ? '' : null", "attr.role": "role()" } }, exportAs: ["cngxDrawerPanel"], hostDirectives: [{ directive: i1.CngxFocusTrap, inputs: ["enabled", "enabled", "autoFocus", "autoFocus"] }], ngImport: i0 });
1309
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerInput: { classPropertyName: "drawerInput", publicName: "cngxDrawerPanel", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, modality: { classPropertyName: "modality", publicName: "modality", isSignal: true, isRequired: false, transformFunction: null }, closeOnClickOutside: { classPropertyName: "closeOnClickOutside", publicName: "closeOnClickOutside", isSignal: true, isRequired: false, transformFunction: null }, role: { classPropertyName: "role", publicName: "role", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-drawer-panel": "true", "class.cngx-drawer-panel--open": "isOpen()", "class.cngx-drawer-panel--left": "position() === 'left'", "class.cngx-drawer-panel--right": "position() === 'right'", "class.cngx-drawer-panel--top": "position() === 'top'", "class.cngx-drawer-panel--bottom": "position() === 'bottom'", "class.cngx-drawer-panel--over": "mode() === 'over'", "class.cngx-drawer-panel--push": "mode() === 'push'", "class.cngx-drawer-panel--modal": "surfaceModality() !== 'none'", "class.cngx-drawer-panel--contained": "surfaceModality() === 'contained'", "attr.id": "panelId()", "attr.aria-hidden": "isOpen() ? null : true", "attr.inert": "isOpen() ? null : ''" } }, providers: [{ provide: CNGX_DRAWER_SURFACE_DRIVER, useExisting: CngxDrawerPanel }], exportAs: ["cngxDrawerPanel"], usesOnChanges: true, hostDirectives: [{ directive: CngxDrawerSurface, inputs: ["label", "label"] }], ngImport: i0 });
351
1310
  }
352
1311
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, decorators: [{
353
1312
  type: Directive,
@@ -355,7 +1314,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
355
1314
  selector: '[cngxDrawerPanel]',
356
1315
  exportAs: 'cngxDrawerPanel',
357
1316
  standalone: true,
358
- hostDirectives: [{ directive: CngxFocusTrap, inputs: ['enabled', 'autoFocus'] }],
1317
+ hostDirectives: [{ directive: CngxDrawerSurface, inputs: ['label'], outputs: [] }],
1318
+ providers: [{ provide: CNGX_DRAWER_SURFACE_DRIVER, useExisting: CngxDrawerPanel }],
359
1319
  host: {
360
1320
  '[class.cngx-drawer-panel]': 'true',
361
1321
  '[class.cngx-drawer-panel--open]': 'isOpen()',
@@ -365,19 +1325,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
365
1325
  '[class.cngx-drawer-panel--bottom]': "position() === 'bottom'",
366
1326
  '[class.cngx-drawer-panel--over]': "mode() === 'over'",
367
1327
  '[class.cngx-drawer-panel--push]': "mode() === 'push'",
368
- '[class.cngx-drawer-panel--side]': "mode() === 'side'",
369
- '[attr.aria-hidden]': "mode() !== 'side' && !isOpen() ? true : null",
370
- '[attr.inert]': "mode() !== 'side' && !isOpen() ? '' : null",
371
- '[attr.role]': 'role()',
1328
+ '[class.cngx-drawer-panel--modal]': "surfaceModality() !== 'none'",
1329
+ '[class.cngx-drawer-panel--contained]': "surfaceModality() === 'contained'",
1330
+ '[attr.id]': 'panelId()',
1331
+ '[attr.aria-hidden]': 'isOpen() ? null : true',
1332
+ '[attr.inert]': "isOpen() ? null : ''",
372
1333
  },
373
1334
  }]
374
- }], ctorParameters: () => [], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: true }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }] } });
1335
+ }], ctorParameters: () => [], propDecorators: { drawerInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], modality: [{ type: i0.Input, args: [{ isSignal: true, alias: "modality", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }] } });
375
1336
 
376
1337
  /**
377
1338
  * Marks the main content area adjacent to a drawer panel.
378
1339
  *
379
1340
  * Adds a CSS class when the drawer is open so the consumer can offset
380
- * the content via CSS transitions or transforms.
1341
+ * the content via CSS transitions or transforms. While a `push` panel is
1342
+ * open it also writes `data-drawer-push` with the panel's side (`left`,
1343
+ * `right`, `top`, `bottom`); `cngx-drawer.css` moves the content aside by
1344
+ * the panel size from it, so the panel itself slides at full size.
381
1345
  *
382
1346
  * ```html
383
1347
  * <main [cngxDrawerContent]="drawer">
@@ -385,24 +1349,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
385
1349
  * </main>
386
1350
  * ```
387
1351
  *
388
- * @category common/layout
389
1352
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-content.directive.ts
390
- * @since 0.1.0
1353
+ * @since 0.3.0
391
1354
  * @relatedTo CngxDrawer, CngxDrawerPanel
392
- * <example-url>http://localhost:4200/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
393
- * <example-url>http://localhost:4200/#/common/layout/drawer/controlled-mode</example-url>
394
- * <example-url>http://localhost:4200/#/common/layout/drawer/direction-all-four-sides</example-url>
395
- * <example-url>http://localhost:4200/#/common/layout/drawer/events-openedchange-closed</example-url>
396
- * <example-url>http://localhost:4200/#/common/layout/drawer/mode-over-push-side</example-url>
397
- * <example-url>http://localhost:4200/#/common/layout/drawer/pattern-consumer-wiring</example-url>
1355
+ * <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
1356
+ * <example-url>/#/common/layout/drawer/controlled-mode</example-url>
1357
+ * <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
1358
+ * <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
1359
+ * <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
1360
+ * <example-url>/#/common/layout/drawer/full-height-modal</example-url>
1361
+ * <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
1362
+ * <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
398
1363
  */
399
1364
  class CngxDrawerContent {
400
1365
  /** Reference to the parent `CngxDrawer` state owner. */
401
1366
  drawerRef = input.required({ ...(ngDevMode ? { debugName: "drawerRef" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerContent' });
402
1367
  /** Whether the drawer is currently open (derived from the drawer ref). */
403
1368
  isOpen = computed(() => this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
1369
+ /** Side of the open `push` panel the content gives way to; `null` otherwise. */
1370
+ pushSide = computed(() => {
1371
+ const drawer = this.drawerRef();
1372
+ const pushing = drawer.opened() && drawer.mode() === 'push';
1373
+ return pushing ? drawer.side() : null;
1374
+ }, ...(ngDevMode ? [{ debugName: "pushSide" }] : /* istanbul ignore next */ []));
404
1375
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
405
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerContent, isStandalone: true, selector: "[cngxDrawerContent]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerContent", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class.cngx-drawer-content": "true", "class.cngx-drawer-content--shifted": "isOpen()" } }, exportAs: ["cngxDrawerContent"], ngImport: i0 });
1376
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerContent, isStandalone: true, selector: "[cngxDrawerContent]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerContent", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class.cngx-drawer-content": "true", "class.cngx-drawer-content--shifted": "isOpen()", "attr.data-drawer-push": "pushSide()" } }, exportAs: ["cngxDrawerContent"], ngImport: i0 });
406
1377
  }
407
1378
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, decorators: [{
408
1379
  type: Directive,
@@ -413,6 +1384,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
413
1384
  host: {
414
1385
  '[class.cngx-drawer-content]': 'true',
415
1386
  '[class.cngx-drawer-content--shifted]': 'isOpen()',
1387
+ '[attr.data-drawer-push]': 'pushSide()',
416
1388
  },
417
1389
  }]
418
1390
  }], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerContent", required: true }] }] } });
@@ -451,12 +1423,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
451
1423
  * </div>
452
1424
  * ```
453
1425
  *
454
- * @category common/layout
455
- * @docsKind primary
456
1426
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/intersection-observer.directive.ts
457
- * @since 0.1.0
1427
+ * @since 0.3.0
458
1428
  * @relatedTo CngxResizeObserver, CngxMediaQuery, CngxInfiniteScroll, CngxScrollSpy
459
- * <example-url>http://localhost:4200/#/common/layout/intersection-observer/scroll-sentinel</example-url>
1429
+ * <example-url>/#/common/layout/intersection-observer/scroll-sentinel</example-url>
1430
+ * @axis level atom
460
1431
  */
461
1432
  class CngxIntersectionObserver {
462
1433
  /** CSS selector for the scroll container root. `null` (default) uses the viewport. */
@@ -532,7 +1503,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
532
1503
  * ```html
533
1504
  * <div cngxMediaQuery="(min-width: 1024px)" #mq="cngxMediaQuery">
534
1505
  * <nav [cngxDrawerPanel]="drawer"
535
- * [mode]="mq.matches() ? 'side' : 'over'">
1506
+ * [mode]="mq.matches() ? 'push' : 'over'">
536
1507
  * …
537
1508
  * </nav>
538
1509
  * </div>
@@ -545,12 +1516,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
545
1516
  * </div>
546
1517
  * ```
547
1518
  *
548
- * @category common/layout
549
- * @docsKind primary
550
1519
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/media-query.directive.ts
551
- * @since 0.1.0
1520
+ * @since 0.3.0
552
1521
  * @relatedTo CngxResizeObserver, CngxIntersectionObserver
553
- * <example-url>http://localhost:4200/#/common/layout/media-query/viewport-breakpoints</example-url>
1522
+ * <example-url>/#/common/layout/media-query/viewport-breakpoints</example-url>
1523
+ * <example-url>/#/ui/breadcrumb/recipes/mobile-parent-only</example-url>
1524
+ * @axis level atom
554
1525
  */
555
1526
  class CngxMediaQuery {
556
1527
  /** The CSS media query string to evaluate. */
@@ -606,11 +1577,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
606
1577
  *
607
1578
  * @param query A CSS media query string, e.g. `(max-width: 640px)`.
608
1579
  * @returns A reactive `Signal<boolean>` tracking the query's match state.
609
- * @category common/layout
610
1580
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/inject-media-query.ts
611
- * @since 0.1.0
1581
+ * @since 0.3.0
612
1582
  * @relatedTo CngxMediaQuery, CngxResizeObserver
613
- * <example-url>http://localhost:4200/#/common/layout/media-query/inject-breakpoint-signal</example-url>
1583
+ * <example-url>/#/common/layout/media-query/inject-breakpoint-signal</example-url>
614
1584
  */
615
1585
  function injectMediaQuery(query) {
616
1586
  return createMediaQuerySignal(query, inject(DestroyRef), inject(DOCUMENT).defaultView);
@@ -640,6 +1610,15 @@ function warnRouterAbsent(enables) {
640
1610
  * signal is the source and reflects outward. Re-hydrates on browser
641
1611
  * back/forward. Dev-warns once and no-ops when `@angular/router` is absent.
642
1612
  *
1613
+ * The key, the initial hydrate and the bookkeeping are resolved on the first
1614
+ * effect run, not in the call: a `Signal<string>` key backed by an input is
1615
+ * read after the input is bound, and in a directive the hydrated state is in
1616
+ * place before the caller's view first renders. A read of `state()` in the
1617
+ * caller's constructor or `ngOnInit` still sees the un-hydrated value. Called
1618
+ * from an environment injector (a service, `runInInjectionContext`), the
1619
+ * effects are root effects: `state()` is hydrated on the first application
1620
+ * tick, not when the call returns.
1621
+ *
643
1622
  * Loop-safety (the core of this helper): the reflect effect writes the URL in
644
1623
  * `untracked()` and skips `navigate` when the serialized `state()` equals the
645
1624
  * last value it wrote - a local closure seeded from the initial URL read, not
@@ -648,18 +1627,17 @@ function warnRouterAbsent(enables) {
648
1627
  * back/forward re-hydration never triggers a reflex navigate. A `param` rename
649
1628
  * is migrated in one navigate (`{ [old]: null, [new]: serialize(state()) }`)
650
1629
  * by a dedicated effect whose only tracked source is the normalized param
651
- * signal; its first run seeds bookkeeping and never navigates.
1630
+ * signal; its first run finds the key `init()` seeded and never navigates.
652
1631
  *
653
1632
  * The `state.set` inside the hydrate effect is a deliberate signal-write-in-
654
1633
  * effect: the URL is an external system and `state` is a caller-owned signal
655
1634
  * the consumer must stay able to toggle, so hydrate cannot be a `computed`. It
656
1635
  * is edge-guarded by serialized equality and wrapped in `untracked()`.
657
1636
  *
658
- * @category common/layout
659
1637
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/router/inject-query-param-sync.ts
660
- * @since 0.1.0
1638
+ * @since 0.3.0
661
1639
  * @relatedTo CngxStepperRouterSync
662
- * <example-url>http://localhost:4200/#/common/layout/router/persisted-toggle</example-url>
1640
+ * <example-url>/#/common/layout/router/persisted-toggle</example-url>
663
1641
  */
664
1642
  function injectQueryParamSync(state, opts) {
665
1643
  const router = inject(Router, { optional: true });
@@ -675,21 +1653,32 @@ function injectQueryParamSync(state, opts) {
675
1653
  const paramSignal = coerceSignal(opts.param);
676
1654
  const serialize = opts.serialize ?? ((value) => (value ? 'open' : null));
677
1655
  const deserialize = opts.deserialize ?? ((raw) => (raw != null));
678
- // Closure bookkeeping, seeded from the initial URL read. `lastWritten` is
679
- // the serialized value the reflect path last pushed to the URL; the hydrate
680
- // path also updates it so an accepted URL value is not reflected back.
681
- const initialParam = paramSignal();
682
- let lastWritten = route.snapshot.queryParamMap.get(initialParam) ?? null;
683
- let previousParam = initialParam;
684
- // URL wins on initial load.
685
- if (lastWritten != null) {
686
- const hydrated = deserialize(lastWritten);
687
- if (!Object.is(hydrated, state())) {
688
- state.set(hydrated);
1656
+ // Closure bookkeeping, seeded by `init()` from the initial URL read.
1657
+ // `lastWritten` is the serialized value the reflect path last pushed to the
1658
+ // URL; the hydrate path also updates it so an accepted URL value is not
1659
+ // reflected back.
1660
+ let lastWritten = null;
1661
+ let previousParam = '';
1662
+ let initialized = false;
1663
+ // Runs once, on the first run of whichever effect runs first, so an
1664
+ // input-backed key is read after binding. URL wins on initial load.
1665
+ const init = () => {
1666
+ if (initialized) {
1667
+ return;
689
1668
  }
690
- }
1669
+ initialized = true;
1670
+ previousParam = paramSignal();
1671
+ lastWritten = route.snapshot.queryParamMap.get(previousParam) ?? null;
1672
+ if (lastWritten != null) {
1673
+ const hydrated = deserialize(lastWritten);
1674
+ if (!Object.is(hydrated, state())) {
1675
+ state.set(hydrated);
1676
+ }
1677
+ }
1678
+ };
691
1679
  // Reflect: signal change -> URL. Tracks `state()` only; param read untracked.
692
1680
  effect(() => {
1681
+ untracked(init);
693
1682
  const raw = serialize(state());
694
1683
  untracked(() => {
695
1684
  if (raw === lastWritten) {
@@ -707,7 +1696,7 @@ function injectQueryParamSync(state, opts) {
707
1696
  });
708
1697
  // Re-hydrate: URL change (back/forward) -> signal. Tracks the query-param
709
1698
  // emission only; param and state reads are untracked. The first run mirrors
710
- // the initial snapshot already handled synchronously above, so it is skipped
1699
+ // the initial snapshot already handled by `init()`, so it is skipped
711
1700
  // - processing it would race the reflect effect's still-pending initial
712
1701
  // navigate and reset `state` to a stale value. Later runs skip our own
713
1702
  // reflect echo via the `lastWritten` guard.
@@ -718,6 +1707,7 @@ function injectQueryParamSync(state, opts) {
718
1707
  effect(() => {
719
1708
  const map = queryMap();
720
1709
  untracked(() => {
1710
+ init();
721
1711
  if (!hydrateInitialized) {
722
1712
  hydrateInitialized = true;
723
1713
  return;
@@ -735,10 +1725,12 @@ function injectQueryParamSync(state, opts) {
735
1725
  });
736
1726
  // Rename migration: param change -> one merged navigate that removes the old
737
1727
  // key and writes the current value under the new one. Tracks the param
738
- // signal only; the first run seeds `previousParam` and never navigates.
1728
+ // signal only; the first run finds the `previousParam` `init()` seeded and
1729
+ // never navigates.
739
1730
  effect(() => {
740
1731
  const param = paramSignal();
741
1732
  untracked(() => {
1733
+ init();
742
1734
  if (param === previousParam) {
743
1735
  return;
744
1736
  }
@@ -757,6 +1749,10 @@ function injectQueryParamSync(state, opts) {
757
1749
  });
758
1750
  }
759
1751
 
1752
+ /** @internal Whether `host` can observe at all: false on SSR and jsdom hosts. */
1753
+ function canObserveResize(host) {
1754
+ return typeof host?.ResizeObserver === 'function';
1755
+ }
760
1756
  /**
761
1757
  * Subscribes `apply` to size changes of `element` on `host`.
762
1758
  *
@@ -776,12 +1772,11 @@ function injectQueryParamSync(state, opts) {
776
1772
  * @param box Which box model to report.
777
1773
  * @param apply Receives the first entry of every observation batch.
778
1774
  * @returns Teardown that disconnects the observer.
779
- * @category common/layout/observers
780
1775
  * @relatedTo createResizeSignal, observeMediaQuery
781
- * @since 0.1.0
1776
+ * @since 0.3.0
782
1777
  */
783
1778
  function observeResize(host, element, box, apply) {
784
- if (!host || typeof host.ResizeObserver !== 'function') {
1779
+ if (!canObserveResize(host)) {
785
1780
  return () => undefined;
786
1781
  }
787
1782
  const observer = new host.ResizeObserver((entries) => apply(entries[0]));
@@ -815,9 +1810,8 @@ function observeResize(host, element, box, apply) {
815
1810
  * @param destroyRef Scope whose destruction disconnects the observer.
816
1811
  * @param host The window-like object to read `ResizeObserver` from.
817
1812
  * @returns A readonly signal carrying the latest entry.
818
- * @category common/layout/observers
819
1813
  * @relatedTo observeResize, createMediaQuerySignal
820
- * @since 0.1.0
1814
+ * @since 0.3.0
821
1815
  */
822
1816
  function createResizeSignal(element, box, destroyRef, host) {
823
1817
  const entry = signal(null, ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
@@ -850,12 +1844,12 @@ function createResizeSignal(element, box, destroyRef, host) {
850
1844
  * readonly columns = computed(() => (this.ro()?.width() ?? 0) > 600 ? 3 : 1);
851
1845
  * ```
852
1846
  *
853
- * @category common/layout
854
- * @docsKind primary
855
1847
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/resize-observer.directive.ts
856
- * @since 0.1.0
1848
+ * @since 0.3.0
857
1849
  * @relatedTo CngxIntersectionObserver, CngxMediaQuery
858
- * <example-url>http://localhost:4200/#/common/layout/resize-observer/live-size</example-url>
1850
+ * <example-url>/#/common/layout/resize-observer/live-size</example-url>
1851
+ * <example-url>/#/ui/breadcrumb/recipes/responsive-collapse</example-url>
1852
+ * @axis level atom
859
1853
  */
860
1854
  class CngxResizeObserver {
861
1855
  /** Which box model to observe. `'content-box'` (default), `'border-box'`, or `'device-pixel-content-box'`. */
@@ -904,8 +1898,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
904
1898
  * needs a container and finds none must say so (a dev-mode warning), not
905
1899
  * silently observe itself.
906
1900
  *
907
- * @category common/layout/observers
908
- * @since 0.1.0
1901
+ * @since 0.3.0
909
1902
  */
910
1903
  const CNGX_CONTAINER_SIZE = new InjectionToken('CNGX_CONTAINER_SIZE');
911
1904
  /**
@@ -920,9 +1913,8 @@ const CNGX_CONTAINER_SIZE = new InjectionToken('CNGX_CONTAINER_SIZE');
920
1913
  * @param element The container host.
921
1914
  * @param destroyRef Scope whose destruction disconnects the observer.
922
1915
  * @param win The window-like object providing `ResizeObserver` and `getComputedStyle`.
923
- * @category common/layout/observers
924
1916
  * @relatedTo injectContainerSize, CngxContainer
925
- * @since 0.1.0
1917
+ * @since 0.3.0
926
1918
  */
927
1919
  function createContainerSize(element, destroyRef, win) {
928
1920
  const entry = createResizeSignal(element, 'border-box', destroyRef, win);
@@ -962,7 +1954,7 @@ function createContainerSize(element, destroyRef, win) {
962
1954
  byName.set(key, value);
963
1955
  return value;
964
1956
  };
965
- return { inlineSize, blockSize, isReady, property };
1957
+ return { inlineSize, blockSize, isReady, observes: canObserveResize(win), property };
966
1958
  }
967
1959
  /**
968
1960
  * Reads the nearest query container declared by a `[cngxContainer]` ancestor,
@@ -975,7 +1967,7 @@ function createContainerSize(element, destroyRef, win) {
975
1967
  * ```typescript
976
1968
  * private readonly container = inject(CNGX_CONTAINER_SIZE, { optional: true });
977
1969
  * private readonly wide = this.container?.property('--cngx-thing-wide', this.host) ?? signal('').asReadonly();
978
- * readonly mode = computed(() => (this.wide() === '1' ? 'side' : 'over'));
1970
+ * readonly mode = computed(() => (this.wide() === '1' ? 'push' : 'over'));
979
1971
  * ```
980
1972
  *
981
1973
  * A component that declares the container in its own stylesheet and reads it
@@ -989,9 +1981,8 @@ function createContainerSize(element, destroyRef, win) {
989
1981
  * ```
990
1982
  *
991
1983
  * @param target Element to observe when no ancestor container exists.
992
- * @category common/layout/observers
993
1984
  * @relatedTo CngxContainer, injectMediaQuery
994
- * @since 0.1.0
1985
+ * @since 0.3.0
995
1986
  */
996
1987
  function injectContainerSize(target) {
997
1988
  const ancestor = inject(CNGX_CONTAINER_SIZE, { optional: true, skipSelf: true });
@@ -1041,12 +2032,11 @@ function injectContainerSize(target) {
1041
2032
  * content (an inline chip, a `width: max-content` bar) must not be a
1042
2033
  * container.
1043
2034
  *
1044
- * @category common/layout
1045
- * @docsKind primary
1046
2035
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/container.directive.ts
1047
- * @since 0.1.0
2036
+ * @since 0.3.0
1048
2037
  * @relatedTo injectContainerSize, CngxResizeObserver, CngxMediaQuery
1049
- * <example-url>http://localhost:4200/#/common/layout/container/css-decides-js-reads</example-url>
2038
+ * <example-url>/#/common/layout/container/css-decides-js-reads</example-url>
2039
+ * @axis level atom
1050
2040
  */
1051
2041
  class CngxContainer {
1052
2042
  size = createContainerSize(inject(ElementRef).nativeElement, inject(DestroyRef), inject(DOCUMENT).defaultView);
@@ -1056,6 +2046,8 @@ class CngxContainer {
1056
2046
  blockSize = this.size.blockSize;
1057
2047
  /** `true` once the first observation has arrived. */
1058
2048
  isReady = this.size.isReady;
2049
+ /** `false` on a host without `ResizeObserver` (SSR, jsdom). */
2050
+ observes = this.size.observes;
1059
2051
  /**
1060
2052
  * The resolved value of a custom property on `on` (default: this host),
1061
2053
  * re-read on every resize. The `@container` rule must style a descendant,
@@ -1079,176 +2071,547 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1079
2071
  }] });
1080
2072
 
1081
2073
  /**
1082
- * Ref-count per document root. Module-private on purpose: this file is the
1083
- * single owner of the lock state. A second copy of this map (the pre-extraction
1084
- * state: one in `CngxScrollLock`, one in `CngxDialog`) shares the dataset keys
1085
- * below without sharing the count, so interleaved acquire/release across the
1086
- * two owners corrupts each other's saved overflow values.
2074
+ * The trigger of a drawer, sidebar or sidenav panel. It owns no state: it
2075
+ * mirrors the target's `expanded` as `aria-expanded`, points
2076
+ * `aria-controls` at the target's `id`, and calls `toggle()` (or `peek()`)
2077
+ * on click, Enter and Space.
2078
+ *
2079
+ * The target is an explicit reference (`[cngxPanelTrigger]="drawer"`). A
2080
+ * bare `cngxPanelTrigger` inside the panel resolves the surrounding
2081
+ * `CNGX_PANEL_TARGET` (a pin or close button). Because the trigger names
2082
+ * the panel in `aria-controls`, a press on it is not an outside press for
2083
+ * the panel's dismissal, so one press toggles once.
2084
+ *
2085
+ * On a native `<button>` the browser turns Enter and Space into the click.
2086
+ * Any other host gets `role="button"`, `tabindex="0"` and its own
2087
+ * Enter / Space handling. An icon-only trigger (no text content; text
2088
+ * inside `hidden` or `aria-hidden` elements does not count) is named after
2089
+ * the panel: a bound `label`, else a static `aria-label`, else the
2090
+ * target's `label`, else
2091
+ * `CNGX_LAYOUT_I18N.panelTrigger`. The name stays the same while the panel
2092
+ * opens and closes; `aria-expanded` carries the state. A trigger with
2093
+ * visible text keeps its text as its name. The check follows the host
2094
+ * content: text added to or removed from the trigger later (an
2095
+ * interpolation, an `@if`) switches between the two.
2096
+ *
2097
+ * The trigger draws nothing: the host's content is the consumer's. For an
2098
+ * icon button with a glyph that follows the panel, use
2099
+ * `button[cngxPanelToggle]`, which composes this directive.
1087
2100
  *
1088
- * @internal
2101
+ * ```html
2102
+ * <button type="button" [cngxPanelTrigger]="drawer">Menu</button>
2103
+ * <div cngxDrawer #drawer="cngxDrawer" panelId="nav">
2104
+ * <nav [cngxDrawerPanel]="drawer">…</nav>
2105
+ * </div>
2106
+ * ```
2107
+ *
2108
+ * @wcag AA
2109
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-trigger/panel-trigger.directive.ts
2110
+ * @since 0.3.0
2111
+ * @relatedTo CngxPanelToggle, CngxPanelTarget, CNGX_PANEL_TARGET, CngxDrawer, CngxSidebar
2112
+ * <example-url>/#/common/layout/sidebar/clipped-below-header</example-url>
2113
+ * <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
2114
+ * <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
2115
+ * <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
2116
+ * <example-url>/#/common/layout/drawer/full-height-modal</example-url>
2117
+ * @axis level atom
1089
2118
  */
1090
- const lockCounts = new WeakMap();
2119
+ class CngxPanelTrigger {
2120
+ /**
2121
+ * The panel to control. Bind it explicitly, or leave the attribute bare
2122
+ * inside a panel that provides `CNGX_PANEL_TARGET`.
2123
+ */
2124
+ targetInput = input(undefined, { ...(ngDevMode ? { debugName: "targetInput" } : /* istanbul ignore next */ {}), alias: 'cngxPanelTrigger',
2125
+ transform: (v) => (typeof v === 'string' ? undefined : v) });
2126
+ /**
2127
+ * `toggle` (default) flips the panel. `peek` shows it temporarily; a target
2128
+ * without `peek()` toggles instead.
2129
+ */
2130
+ action = input('toggle', ...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
2131
+ /**
2132
+ * Accessible name. Unbound, a static `aria-label` on the host stays; on a
2133
+ * trigger without text content or a static `aria-label` it falls back to
2134
+ * the target's `label`, then to `CNGX_LAYOUT_I18N.panelTrigger`. It does
2135
+ * not follow the panel state; `aria-expanded` does.
2136
+ */
2137
+ label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
2138
+ host = inject(ElementRef).nativeElement;
2139
+ providedTarget = inject(CNGX_PANEL_TARGET, { optional: true });
2140
+ i18n = injectLayoutI18n();
2141
+ // The aria-label binding would drop a static aria-label, so it renders it.
2142
+ staticLabel = inject(new HostAttributeToken('aria-label'), { optional: true });
2143
+ rendered = signal(false, ...(ngDevMode ? [{ debugName: "rendered" }] : /* istanbul ignore next */ []));
2144
+ // Bumped by a MutationObserver on the host: the text and the attributes
2145
+ // that decide the name are not signals, so hasOwnName reads the DOM and
2146
+ // tracks this version instead of a written copy.
2147
+ nameVersion = signal(0, ...(ngDevMode ? [{ debugName: "nameVersion" }] : /* istanbul ignore next */ []));
2148
+ // Until the first render the projected content is not there yet; assume a
2149
+ // named trigger so no fallback label flashes onto a text trigger.
2150
+ hasOwnName = computed(() => {
2151
+ if (!this.rendered()) {
2152
+ return true;
2153
+ }
2154
+ this.nameVersion();
2155
+ return nameText(this.host).trim() !== '' || this.host.hasAttribute('aria-labelledby');
2156
+ }, ...(ngDevMode ? [{ debugName: "hasOwnName" }] : /* istanbul ignore next */ []));
2157
+ nativeButton = this.host.tagName === 'BUTTON';
2158
+ /** The resolved target: the explicit reference wins over the provided one. */
2159
+ target = computed(() => this.targetInput() ?? this.providedTarget, ...(ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []));
2160
+ /**
2161
+ * Whether the controlled panel is shown in its resting state. A peek is
2162
+ * transient pointer presentation, so a peeked target reads as collapsed.
2163
+ */
2164
+ expanded = computed(() => {
2165
+ const target = this.target();
2166
+ return !!target && target.expanded() && !(target.peeked?.() ?? false);
2167
+ }, ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
2168
+ controls = computed(() => {
2169
+ const id = this.target()?.id();
2170
+ return id === undefined || id === '' ? null : id;
2171
+ }, ...(ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []));
2172
+ fallbackLabel = computed(() => {
2173
+ if (this.hasOwnName()) {
2174
+ return null;
2175
+ }
2176
+ return this.target()?.label?.() ?? this.i18n().panelTrigger;
2177
+ }, ...(ngDevMode ? [{ debugName: "fallbackLabel" }] : /* istanbul ignore next */ []));
2178
+ resolvedLabel = computed(() => this.label() ?? this.staticLabel ?? this.fallbackLabel(), ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
2179
+ handleActivationKey = createActivationKeyHandler(this.host, () => this.activate());
2180
+ constructor() {
2181
+ let observer = null;
2182
+ inject(DestroyRef).onDestroy(() => observer?.disconnect());
2183
+ afterNextRender(() => {
2184
+ this.rendered.set(true);
2185
+ if (typeof MutationObserver === 'undefined') {
2186
+ return;
2187
+ }
2188
+ observer = new MutationObserver(() => this.nameVersion.update((v) => v + 1));
2189
+ observer.observe(this.host, {
2190
+ characterData: true,
2191
+ childList: true,
2192
+ subtree: true,
2193
+ attributes: true,
2194
+ attributeFilter: ['hidden', 'aria-hidden', 'aria-labelledby'],
2195
+ });
2196
+ });
2197
+ }
2198
+ /** Runs the action on the target. */
2199
+ activate() {
2200
+ const target = this.target();
2201
+ if (!target) {
2202
+ return;
2203
+ }
2204
+ if (this.action() === 'peek' && target.peek) {
2205
+ target.peek();
2206
+ return;
2207
+ }
2208
+ target.toggle();
2209
+ }
2210
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2211
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPanelTrigger, isStandalone: true, selector: "[cngxPanelTrigger]", inputs: { targetInput: { classPropertyName: "targetInput", publicName: "cngxPanelTrigger", isSignal: true, isRequired: false, transformFunction: null }, action: { classPropertyName: "action", publicName: "action", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "activate()", "keydown.enter": "handleActivationKey($event)", "keydown.space": "handleActivationKey($event)" }, properties: { "attr.aria-expanded": "expanded()", "attr.aria-controls": "controls()", "attr.aria-label": "resolvedLabel()", "attr.role": "nativeButton ? null : 'button'", "attr.tabindex": "nativeButton ? null : '0'" } }, exportAs: ["cngxPanelTrigger"], ngImport: i0 });
2212
+ }
2213
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelTrigger, decorators: [{
2214
+ type: Directive,
2215
+ args: [{
2216
+ selector: '[cngxPanelTrigger]',
2217
+ exportAs: 'cngxPanelTrigger',
2218
+ standalone: true,
2219
+ host: {
2220
+ '[attr.aria-expanded]': 'expanded()',
2221
+ '[attr.aria-controls]': 'controls()',
2222
+ '[attr.aria-label]': 'resolvedLabel()',
2223
+ '[attr.role]': "nativeButton ? null : 'button'",
2224
+ '[attr.tabindex]': "nativeButton ? null : '0'",
2225
+ '(click)': 'activate()',
2226
+ '(keydown.enter)': 'handleActivationKey($event)',
2227
+ '(keydown.space)': 'handleActivationKey($event)',
2228
+ },
2229
+ }]
2230
+ }], ctorParameters: () => [], propDecorators: { targetInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPanelTrigger", required: false }] }], action: [{ type: i0.Input, args: [{ isSignal: true, alias: "action", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
1091
2231
  /**
1092
- * Acquire a ref-counted scroll lock on a document root and get back the
1093
- * matching release function.
2232
+ * The text that names the host: its text content without `hidden` and
2233
+ * `aria-hidden` subtrees, which the accessible name skips as well (a
2234
+ * component's hidden disabled reason, an `aria-hidden` glyph slot).
2235
+ */
2236
+ function nameText(node) {
2237
+ if (node.nodeType === Node.TEXT_NODE) {
2238
+ return node.textContent ?? '';
2239
+ }
2240
+ return Array.from(node.childNodes)
2241
+ .filter((child) => !(child instanceof Element) ||
2242
+ !(child.hasAttribute('hidden') || child.getAttribute('aria-hidden') === 'true'))
2243
+ .map(nameText)
2244
+ .join('');
2245
+ }
2246
+
2247
+ /**
2248
+ * Icon button that opens and closes a drawer or sidebar and draws its own
2249
+ * glyph. The behaviour is a composed `CngxPanelTrigger`: `aria-expanded`
2250
+ * mirrors the panel, `aria-controls` names it, a press toggles it (or peeks
2251
+ * it with `action="peek"`), and the accessible name is the panel's: a
2252
+ * bound `label`, else the target's `label`, else
2253
+ * `CNGX_LAYOUT_I18N.panelTrigger`. The name stays the same while the panel
2254
+ * opens and closes.
2255
+ *
2256
+ * The glyph follows how the target presents the panel right now, so it
2257
+ * changes with a breakpoint that switches the panel's `mode`:
2258
+ *
2259
+ * - a modal over-drawer (the mobile nav: `mode="over"` with a `page` or
2260
+ * `contained` modality) shows three bars while closed and a cross while
2261
+ * open;
2262
+ * - every other presentation (an inline sidebar or rail, a push drawer, a
2263
+ * non-modal over-drawer) shows a panel glyph that draws what a press
2264
+ * does: a frame with a column on the panel's side and a chevron pointing
2265
+ * away from the column while the panel is closed (open it), toward the
2266
+ * column while it is open (close it). `aria-expanded` carries the same
2267
+ * state for assistive technology. The glyph mirrors for a panel
2268
+ * on the right: `position="right"`, or the end side in LTR and the start
2269
+ * side in RTL (`CNGX_DIRECTION`).
2270
+ *
2271
+ * A target without `mode` / `modal` / `side` (a consumer-built
2272
+ * `CngxPanelTarget`) reads as an inline panel on the start side. The glyph
2273
+ * is `aria-hidden`; project an icon to replace it. The state the default
2274
+ * glyph follows is public on the exported instance (`expanded`,
2275
+ * `modalOverlay`, `mirrored`), so a projected glyph can follow it too:
1094
2276
  *
1095
- * The first active lock saves the current `overflow` / `scrollbar-gutter`
1096
- * inline styles and sets `overflow: hidden` + `scrollbar-gutter: stable`
1097
- * (no layout shift when the scrollbar disappears). Releasing the last active
1098
- * lock restores the saved values. The returned release function is
1099
- * idempotent - calling it twice cannot over-decrement the count.
2277
+ * ```html
2278
+ * <button type="button" [cngxPanelToggle]="nav" #toggle="cngxPanelToggle">
2279
+ * <cngx-icon [style.transform]="toggle.mirrored() ? 'scaleX(-1)' : null">
2280
+ * <mat-icon>{{ toggle.expanded() ? 'menu_open' : 'menu' }}</mat-icon>
2281
+ * </cngx-icon>
2282
+ * </button>
2283
+ * ```
1100
2284
  *
1101
- * Shared engine behind `CngxScrollLock` and `CngxDialog`'s modal scroll lock;
1102
- * consumers composing their own overlay primitives can use it directly.
2285
+ * Shares the button family's state surface: `disabled` renders
2286
+ * `aria-disabled` (the button stays focusable and swallows activation) and
2287
+ * `disabledReason` is read through `aria-describedby`. The emphasis stays
2288
+ * `ghost` unless `variant` is set; `size` and `tone` fall through to the
2289
+ * group, `provideButtonConfig` and the icon-button defaults.
1103
2290
  *
1104
- * ```typescript
1105
- * const release = createScrollLock(document.documentElement);
1106
- * // ... overlay open ...
1107
- * release();
2291
+ * ```html
2292
+ * <button type="button" [cngxPanelToggle]="nav"></button>
2293
+ * <div cngxDrawer #nav="cngxDrawer" panelId="main-nav">
2294
+ * <nav [cngxDrawerPanel]="nav" [mode]="mobile() ? 'over' : 'push'">…</nav>
2295
+ * </div>
1108
2296
  * ```
1109
2297
  *
1110
- * @param html - The document root (`document.documentElement`) to lock.
1111
- * @returns Release function for this acquisition. Idempotent.
1112
- *
1113
- * @category common/layout
1114
- * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
1115
- * @since 0.1.0
1116
- * @relatedTo CngxScrollLock, CngxDialog
2298
+ * @wcag AA
2299
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-toggle/panel-toggle.component.ts
2300
+ * @since 0.3.0
2301
+ * @relatedTo CngxPanelTrigger, CngxPanelTarget, CngxDrawer, CngxSidebar, CngxIconButton
2302
+ * <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
2303
+ * <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
2304
+ * <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
2305
+ * <example-url>/#/common/layout/drawer/full-height-modal</example-url>
2306
+ * <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
2307
+ * <example-url>/#/common/layout/sidebar/projected-toggle-glyph</example-url>
2308
+ * @axis level molecule
1117
2309
  */
1118
- function createScrollLock(html) {
1119
- const count = lockCounts.get(html) ?? 0;
1120
- if (count === 0) {
1121
- html.dataset['cngxPrevOverflow'] = html.style.overflow;
1122
- html.dataset['cngxPrevScrollbarGutter'] = html.style.scrollbarGutter;
1123
- html.style.overflow = 'hidden';
1124
- html.style.scrollbarGutter = 'stable';
1125
- }
1126
- lockCounts.set(html, count + 1);
1127
- let released = false;
1128
- return () => {
1129
- if (released) {
1130
- return;
2310
+ class CngxPanelToggle {
2311
+ trigger = inject(CngxPanelTrigger, { host: true });
2312
+ direction = injectDirection();
2313
+ /**
2314
+ * Whether the target shows the panel right now. Read it from a projected
2315
+ * glyph through `#toggle="cngxPanelToggle"`.
2316
+ */
2317
+ expanded = this.trigger.expanded;
2318
+ /**
2319
+ * Whether the target presents the panel as a modal over-drawer right now
2320
+ * (`mode="over"` with a blocking modality). The default glyph draws menu
2321
+ * bars and a cross then; a projected glyph can follow the same switch.
2322
+ */
2323
+ modalOverlay = computed(() => {
2324
+ const target = this.trigger.target();
2325
+ const mode = target?.mode?.() ?? 'inline';
2326
+ return mode === 'over' && (target?.modal?.() ?? false);
2327
+ }, ...(ngDevMode ? [{ debugName: "modalOverlay" }] : /* istanbul ignore next */ []));
2328
+ /**
2329
+ * Whether a panel glyph drawn for a left panel must be flipped: the panel
2330
+ * sits on the right (`right`, `end` in LTR, `start` in RTL). Always
2331
+ * `false` while {@link modalOverlay} holds.
2332
+ */
2333
+ mirrored = computed(() => {
2334
+ if (this.modalOverlay()) {
2335
+ return false;
1131
2336
  }
1132
- released = true;
1133
- const current = lockCounts.get(html) ?? 0;
1134
- if (current <= 1) {
1135
- html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
1136
- html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
1137
- delete html.dataset['cngxPrevOverflow'];
1138
- delete html.dataset['cngxPrevScrollbarGutter'];
1139
- lockCounts.set(html, 0);
2337
+ const side = this.trigger.target()?.side?.() ?? 'start';
2338
+ const rtl = this.direction() === 'rtl';
2339
+ switch (side) {
2340
+ case 'right':
2341
+ return true;
2342
+ case 'start':
2343
+ return rtl;
2344
+ case 'end':
2345
+ return !rtl;
2346
+ default:
2347
+ return false;
1140
2348
  }
1141
- else {
1142
- lockCounts.set(html, current - 1);
2349
+ }, ...(ngDevMode ? [{ debugName: "mirrored" }] : /* istanbul ignore next */ []));
2350
+ /** @internal - the default glyph for the current presentation and state. */
2351
+ icon = computed(() => {
2352
+ const expanded = this.expanded();
2353
+ if (this.modalOverlay()) {
2354
+ return expanded ? CNGX_ICON_X : CNGX_ICON_MENU;
1143
2355
  }
1144
- };
1145
- }
1146
- // The body properties the pin writes. Only these are saved and restored, so a
1147
- // style another owner sets on body while the pin is held survives the release.
1148
- const PINNED_BODY_PROPERTIES = ['position', 'top', 'inset-inline', 'overflow'];
2356
+ return expanded ? CNGX_ICON_PANEL_CLOSE : CNGX_ICON_PANEL_OPEN;
2357
+ }, ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
2358
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelToggle, deps: [], target: i0.ɵɵFactoryTarget.Component });
2359
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.4", type: CngxPanelToggle, isStandalone: true, selector: "button[cngxPanelToggle]", host: { classAttribute: "cngx-button cngx-icon-button cngx-panel-toggle" }, providers: [provideButtonHost('cngxPanelToggle', { defaultVariant: 'ghost', iconOnly: true })], exportAs: ["cngxPanelToggle"], hostDirectives: [{ directive: CngxPanelTrigger, inputs: ["cngxPanelTrigger", "cngxPanelToggle", "action", "action", "label", "label"] }, { directive: i2$1.CngxButtonBrain, inputs: ["variant", "variant", "tone", "tone", "size", "size", "disabled", "disabled", "disabledReason", "disabledReason", "cngxDescribedBy", "cngxDescribedBy", "type", "type"] }], ngImport: i0, template: `
2360
+ <span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
2361
+ <ng-content>
2362
+ <svg
2363
+ class="cngx-panel-toggle__icon"
2364
+ [class.cngx-panel-toggle__icon--mirrored]="mirrored()"
2365
+ [cngxIconSvg]="icon()"
2366
+ ></svg>
2367
+ </ng-content>
2368
+ </span>
2369
+ <cngx-button-adornment />
2370
+ `, isInline: true, styles: ["@layer cngx.components{@scope(.cngx-panel-toggle){.cngx-panel-toggle__icon--mirrored{transform:scaleX(-1)}}}\n"], dependencies: [{ kind: "component", type: CngxIconSvg, selector: "svg[cngxIconSvg]", inputs: ["cngxIconSvg"] }, { kind: "component", type: CngxButtonAdornment, selector: "cngx-button-adornment" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
2371
+ }
2372
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelToggle, decorators: [{
2373
+ type: Component,
2374
+ args: [{ selector: 'button[cngxPanelToggle]', standalone: true, exportAs: 'cngxPanelToggle', imports: [CngxIconSvg, CngxButtonAdornment], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, hostDirectives: [
2375
+ {
2376
+ directive: CngxPanelTrigger,
2377
+ inputs: ['cngxPanelTrigger: cngxPanelToggle', 'action', 'label'],
2378
+ },
2379
+ {
2380
+ directive: CngxButtonBrain,
2381
+ inputs: ['variant', 'tone', 'size', 'disabled', 'disabledReason', 'cngxDescribedBy', 'type'],
2382
+ },
2383
+ ], providers: [provideButtonHost('cngxPanelToggle', { defaultVariant: 'ghost', iconOnly: true })], host: { class: 'cngx-button cngx-icon-button cngx-panel-toggle' }, template: `
2384
+ <span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
2385
+ <ng-content>
2386
+ <svg
2387
+ class="cngx-panel-toggle__icon"
2388
+ [class.cngx-panel-toggle__icon--mirrored]="mirrored()"
2389
+ [cngxIconSvg]="icon()"
2390
+ ></svg>
2391
+ </ng-content>
2392
+ </span>
2393
+ <cngx-button-adornment />
2394
+ `, styles: ["@layer cngx.components{@scope(.cngx-panel-toggle){.cngx-panel-toggle__icon--mirrored{transform:scaleX(-1)}}}\n"] }]
2395
+ }] });
2396
+
1149
2397
  /**
1150
- * Pin state per document root, separate from `lockCounts`: a pin also holds
1151
- * one `createScrollLock` acquisition, so the html overflow stays shared with
1152
- * every other owner.
1153
- *
1154
- * @internal
2398
+ * Optional DI fallback for `CngxResizable`'s `min` / `max` / `step` input
2399
+ * defaults. Resolution is `bound input -> injected default -> literal`
2400
+ * (120 / 600 / 16). A hostDirective input default cannot be overridden by the
2401
+ * host that composes it, so this token is the layered extension point a
2402
+ * resizable organism uses to set app-wide bounds. `optional`, so standalone
2403
+ * `[cngxResizable]` stays byte-identical when the token is absent.
2404
+ *
2405
+ * @relatedTo CngxResizable
2406
+ * @since 0.3.0
1155
2407
  */
1156
- const pins = new WeakMap();
2408
+ const CNGX_RESIZABLE_DEFAULTS = new InjectionToken('CNGX_RESIZABLE_DEFAULTS');
1157
2409
  /**
1158
- * Acquire a ref-counted scroll lock that pins the page body in place, for
1159
- * overlays that must hold on iOS Safari.
1160
- *
1161
- * `overflow: hidden` on the root does not stop iOS Safari from scrolling a
1162
- * page that was already scrolled, and the visual viewport drifts with it, so
1163
- * a bottom-fixed overlay ends above the visible bottom. The first pin saves
1164
- * the body's inline `position`, `top`, `inset-inline` and `overflow` and the
1165
- * scroll position, fixes the body at `top: -scrollY`, and acquires
1166
- * {@link createScrollLock} on the root. The last
1167
- * release restores the body, releases the root lock and scrolls back to the
1168
- * saved position. The returned release function is idempotent.
1169
- *
1170
- * `CngxDialog` and `CngxScrollLock` keep {@link createScrollLock}; reach for
1171
- * this one when the overlay is pinned to the viewport bottom on touch devices.
2410
+ * A resize handle for a side panel: the WAI-ARIA window-splitter pattern on
2411
+ * the handle element.
2412
+ *
2413
+ * The handle owns no layout. It reads and writes `size` (px) through a
2414
+ * two-way binding; the consumer applies the size to the panel (an inline
2415
+ * size or a custom property). Pointer drag runs with pointer capture and
2416
+ * writes at most once per animation frame; the handle sets
2417
+ * `touch-action: none`, so a touch drag resizes instead of panning the page.
2418
+ * The keyboard path makes the handle operable without a pointer (WCAG
2419
+ * 2.1.1): Arrow Left / Right move the handle by `step`, Home / End jump to
2420
+ * `min` / `max`. Modified keys pass through.
2421
+ *
2422
+ * `edge` names the panel edge the handle sits on: `inline-end` for a panel at
2423
+ * the start of the row (the handle grows the panel toward the end),
2424
+ * `inline-start` for a panel at the end. Under `dir="rtl"` the physical
2425
+ * directions flip with the writing direction.
2426
+ *
2427
+ * ARIA lives in the `computed()` graph: `role="separator"`,
2428
+ * `aria-orientation="vertical"`, `aria-valuenow` / `-min` / `-max`,
2429
+ * `aria-valuetext` and `aria-label` (copy from `CNGX_LAYOUT_I18N` unless the
2430
+ * `label` / `valueText` inputs are bound).
2431
+ * The pattern also refers the handle to the resized panel through
2432
+ * `aria-controls`; the handle does not know the panel, so set it on the host
2433
+ * (`aria-controls="filters"`) next to the panel's `id`. The handle never binds
2434
+ * it, so a static attribute stays.
2435
+ *
2436
+ * `min`, `max` and `step` fall back to `CNGX_RESIZABLE_DEFAULTS`, then to
2437
+ * 120 / 600 / 16.
1172
2438
  *
1173
- * ```typescript
1174
- * const release = createPinnedScrollLock(document.documentElement);
1175
- * // ... sheet open ...
1176
- * release();
2439
+ * ```html
2440
+ * <aside id="side" [style.inline-size.px]="width()">…</aside>
2441
+ * <div cngxResizable [(size)]="width" [min]="200" [max]="480" aria-controls="side"></div>
1177
2442
  * ```
1178
2443
  *
1179
- * @param html - The document root (`document.documentElement`) to lock.
1180
- * @returns Release function for this acquisition. Idempotent.
1181
- *
1182
- * @category common/layout
1183
- * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
1184
- * @since 0.1.0
1185
- * @relatedTo createScrollLock, CngxPopoverSheet
2444
+ * @wcag AA
2445
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/resizable/resizable.directive.ts
2446
+ * @since 0.3.0
2447
+ * @relatedTo CngxSidebar, CngxDrawerPanel, CNGX_LAYOUT_I18N
2448
+ * <example-url>/#/common/layout/resizable/side-panel</example-url>
2449
+ * @axis level atom
1186
2450
  */
1187
- function createPinnedScrollLock(html) {
1188
- const body = html.ownerDocument.body;
1189
- const view = html.ownerDocument.defaultView;
1190
- const existing = pins.get(html);
1191
- if (existing) {
1192
- existing.count += 1;
1193
- }
1194
- else {
1195
- const scrollX = view?.scrollX ?? 0;
1196
- const scrollY = view?.scrollY ?? 0;
1197
- pins.set(html, {
1198
- count: 1,
1199
- saved: new Map(PINNED_BODY_PROPERTIES.map((name) => [
1200
- name,
1201
- {
1202
- value: body.style.getPropertyValue(name),
1203
- priority: body.style.getPropertyPriority(name),
1204
- },
1205
- ])),
1206
- scrollX,
1207
- scrollY,
1208
- releaseHtml: createScrollLock(html),
1209
- });
1210
- body.style.position = 'fixed';
1211
- body.style.top = `${-scrollY}px`;
1212
- body.style.insetInline = '0';
1213
- body.style.overflow = 'hidden';
2451
+ class CngxResizable {
2452
+ /**
2453
+ * Optional app-wide bounds. Declared first so the input initialisers below
2454
+ * can source their fallback from it. Absent by default - standalone
2455
+ * `[cngxResizable]` then keeps the 120 / 600 / 16 literals.
2456
+ */
2457
+ defaults = inject(CNGX_RESIZABLE_DEFAULTS, { optional: true });
2458
+ /** Size of the resized panel in px. Two-way: `[(size)]="width"`. */
2459
+ size = model.required(...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
2460
+ /** Smallest size in px a drag or key can reach. */
2461
+ min = input(this.defaults?.min ?? 120, ...(ngDevMode ? [{ debugName: "min" }] : /* istanbul ignore next */ []));
2462
+ /** Largest size in px a drag or key can reach. */
2463
+ max = input(this.defaults?.max ?? 600, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
2464
+ /** The panel edge the handle sits on; sets the drag and arrow-key direction. */
2465
+ edge = input('inline-end', ...(ngDevMode ? [{ debugName: "edge" }] : /* istanbul ignore next */ []));
2466
+ /** Size change in px per arrow-key press. */
2467
+ step = input(this.defaults?.step ?? 16, ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
2468
+ /** Accessible name of the handle. Falls back to `CNGX_LAYOUT_I18N.resizeHandle`. */
2469
+ label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
2470
+ /**
2471
+ * `aria-valuetext` for a px size. Falls back to
2472
+ * `CNGX_LAYOUT_I18N.resizeValueText`.
2473
+ */
2474
+ valueText = input(undefined, ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
2475
+ doc = inject(DOCUMENT);
2476
+ direction = injectDirection();
2477
+ i18n = injectLayoutI18n();
2478
+ resizingState = signal(false, ...(ngDevMode ? [{ debugName: "resizingState" }] : /* istanbul ignore next */ []));
2479
+ dragAbort = null;
2480
+ /** Whether a pointer drag is in progress. */
2481
+ resizing = this.resizingState.asReadonly();
2482
+ valueNow = computed(() => Math.round(this.clamped(this.size())), ...(ngDevMode ? [{ debugName: "valueNow" }] : /* istanbul ignore next */ []));
2483
+ resolvedLabel = computed(() => this.label() ?? this.i18n().resizeHandle, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
2484
+ resolvedValueText = computed(() => {
2485
+ const format = this.valueText() ?? this.i18n().resizeValueText;
2486
+ return format(this.valueNow());
2487
+ }, ...(ngDevMode ? [{ debugName: "resolvedValueText" }] : /* istanbul ignore next */ []));
2488
+ /** +1 when moving the handle physically right grows the panel, else -1. */
2489
+ growSign = computed(() => {
2490
+ const endIsRight = this.direction() !== 'rtl';
2491
+ const onRight = this.edge() === 'inline-end' ? endIsRight : !endIsRight;
2492
+ return onRight ? 1 : -1;
2493
+ }, ...(ngDevMode ? [{ debugName: "growSign" }] : /* istanbul ignore next */ []));
2494
+ constructor() {
2495
+ inject(DestroyRef).onDestroy(() => this.dragAbort?.abort());
1214
2496
  }
1215
- let released = false;
1216
- return () => {
1217
- if (released) {
2497
+ handleKeydown(event) {
2498
+ if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) {
1218
2499
  return;
1219
2500
  }
1220
- released = true;
1221
- const state = pins.get(html);
1222
- if (!state) {
2501
+ const target = this.keyTarget(event.key);
2502
+ if (target === null) {
1223
2503
  return;
1224
2504
  }
1225
- state.count -= 1;
1226
- if (state.count > 0) {
2505
+ event.preventDefault();
2506
+ this.size.set(Math.round(this.clamped(target)));
2507
+ }
2508
+ handlePointerDown(event) {
2509
+ if (event.button !== 0) {
1227
2510
  return;
1228
2511
  }
1229
- pins.delete(html);
1230
- for (const [name, { value, priority }] of state.saved) {
1231
- if (value) {
1232
- body.style.setProperty(name, value, priority);
2512
+ event.preventDefault();
2513
+ const handle = event.currentTarget;
2514
+ handle.setPointerCapture?.(event.pointerId);
2515
+ this.dragAbort?.abort();
2516
+ const controller = new AbortController();
2517
+ this.dragAbort = controller;
2518
+ this.resizingState.set(true);
2519
+ const startX = event.clientX;
2520
+ const startSize = this.size();
2521
+ const sign = this.growSign();
2522
+ const view = this.doc.defaultView;
2523
+ let pending = startSize;
2524
+ let frame = 0;
2525
+ // Destroying the handle mid-drag aborts the controller; the queued
2526
+ // frame must not write the size of a gone handle.
2527
+ controller.signal.addEventListener('abort', () => {
2528
+ if (frame) {
2529
+ view?.cancelAnimationFrame(frame);
2530
+ frame = 0;
1233
2531
  }
1234
- else {
1235
- body.style.removeProperty(name);
2532
+ });
2533
+ const flush = () => {
2534
+ frame = 0;
2535
+ this.size.set(pending);
2536
+ };
2537
+ const onMove = (ev) => {
2538
+ pending = Math.round(this.clamped(startSize + (ev.clientX - startX) * sign));
2539
+ if (!frame) {
2540
+ frame = view?.requestAnimationFrame(flush) ?? 0;
2541
+ }
2542
+ };
2543
+ const onEnd = () => {
2544
+ if (frame) {
2545
+ view?.cancelAnimationFrame(frame);
2546
+ }
2547
+ flush();
2548
+ this.resizingState.set(false);
2549
+ controller.abort();
2550
+ if (this.dragAbort === controller) {
2551
+ this.dragAbort = null;
1236
2552
  }
2553
+ };
2554
+ const options = { signal: controller.signal };
2555
+ this.doc.addEventListener('pointermove', onMove, options);
2556
+ this.doc.addEventListener('pointerup', onEnd, options);
2557
+ this.doc.addEventListener('pointercancel', onEnd, options);
2558
+ }
2559
+ keyTarget(key) {
2560
+ const current = this.size();
2561
+ const step = this.step() * this.growSign();
2562
+ switch (key) {
2563
+ case 'ArrowRight':
2564
+ return current + step;
2565
+ case 'ArrowLeft':
2566
+ return current - step;
2567
+ case 'Home':
2568
+ return this.min();
2569
+ case 'End':
2570
+ return this.max();
2571
+ default:
2572
+ return null;
1237
2573
  }
1238
- state.releaseHtml();
1239
- view?.scrollTo({ left: state.scrollX, top: state.scrollY, behavior: 'instant' });
1240
- };
2574
+ }
2575
+ clamped(value) {
2576
+ return clamp(value, this.min(), this.max());
2577
+ }
2578
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2579
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxResizable, isStandalone: true, selector: "[cngxResizable]", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: true, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, edge: { classPropertyName: "edge", publicName: "edge", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, valueText: { classPropertyName: "valueText", publicName: "valueText", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { size: "sizeChange" }, host: { attributes: { "role": "separator", "tabindex": "0", "aria-orientation": "vertical" }, listeners: { "keydown": "handleKeydown($event)", "pointerdown": "handlePointerDown($event)" }, properties: { "attr.aria-valuenow": "valueNow()", "attr.aria-valuemin": "min()", "attr.aria-valuemax": "max()", "attr.aria-valuetext": "resolvedValueText()", "attr.aria-label": "resolvedLabel()", "class.cngx-resizable--resizing": "resizing()" }, styleAttribute: "touch-action: none" }, exportAs: ["cngxResizable"], ngImport: i0 });
1241
2580
  }
2581
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizable, decorators: [{
2582
+ type: Directive,
2583
+ args: [{
2584
+ selector: '[cngxResizable]',
2585
+ exportAs: 'cngxResizable',
2586
+ standalone: true,
2587
+ host: {
2588
+ role: 'separator',
2589
+ tabindex: '0',
2590
+ 'aria-orientation': 'vertical',
2591
+ style: 'touch-action: none',
2592
+ '[attr.aria-valuenow]': 'valueNow()',
2593
+ '[attr.aria-valuemin]': 'min()',
2594
+ '[attr.aria-valuemax]': 'max()',
2595
+ '[attr.aria-valuetext]': 'resolvedValueText()',
2596
+ '[attr.aria-label]': 'resolvedLabel()',
2597
+ '[class.cngx-resizable--resizing]': 'resizing()',
2598
+ '(keydown)': 'handleKeydown($event)',
2599
+ '(pointerdown)': 'handlePointerDown($event)',
2600
+ },
2601
+ }]
2602
+ }], ctorParameters: () => [], propDecorators: { size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: true }] }, { type: i0.Output, args: ["sizeChange"] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], edge: [{ type: i0.Input, args: [{ isSignal: true, alias: "edge", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], valueText: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueText", required: false }] }] } });
1242
2603
 
1243
2604
  /**
1244
- * Prevents scrolling on the document body when enabled.
2605
+ * Prevents scrolling on the document, or on a given scroll container, when
2606
+ * enabled.
1245
2607
  *
1246
- * Sets `overflow: hidden` and `scrollbar-gutter: stable` on `<html>` to
2608
+ * Sets `overflow: hidden` and `scrollbar-gutter: stable` on the target
2609
+ * (`<html>` unless `[cngxScrollLockTarget]` names another element) to
1247
2610
  * prevent layout shift when the scrollbar disappears. Restores original
1248
- * values when all lock instances are released.
2611
+ * values when all lock instances on that target are released.
1249
2612
  *
1250
- * Multiple instances are ref-counted - the original styles are only
1251
- * restored when the last lock is released.
2613
+ * Multiple instances are ref-counted per target - the original styles are
2614
+ * only restored when the last lock on that element is released.
1252
2615
  *
1253
2616
  * ### With a drawer
1254
2617
  * ```html
@@ -1262,34 +2625,46 @@ function createPinnedScrollLock(html) {
1262
2625
  * <div [cngxScrollLock]="isModalOpen()">…</div>
1263
2626
  * ```
1264
2627
  *
1265
- * @category common/layout
1266
- * @docsKind primary
2628
+ * ### Inside a scroll container
2629
+ * ```html
2630
+ * <section #pane class="pane">
2631
+ * <aside [cngxScrollLock]="open()" [cngxScrollLockTarget]="pane">…</aside>
2632
+ * </section>
2633
+ * ```
2634
+ *
1267
2635
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock.directive.ts
1268
- * @since 0.1.0
2636
+ * @since 0.3.0
1269
2637
  * @relatedTo CngxDrawer, CngxBackdrop
1270
- * <example-url>http://localhost:4200/#/common/layout/scroll-lock/toggle</example-url>
2638
+ * <example-url>/#/common/layout/scroll-lock/toggle</example-url>
2639
+ * @axis level atom
1271
2640
  */
1272
2641
  class CngxScrollLock {
1273
2642
  /** Whether scroll lock is active. */
1274
2643
  enabled = input(false, { ...(ngDevMode ? { debugName: "enabled" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLock' });
2644
+ /**
2645
+ * The scrolling element to lock. Defaults to the document root
2646
+ * (`document.documentElement`). Changing it while locked moves the lock.
2647
+ */
2648
+ target = input(undefined, { ...(ngDevMode ? { debugName: "target" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLockTarget' });
1275
2649
  constructor() {
1276
- const html = inject(DOCUMENT).documentElement;
2650
+ const root = inject(DOCUMENT).documentElement;
2651
+ let locked = null;
1277
2652
  let release = null;
1278
2653
  effect(() => {
1279
- if (this.enabled() && !release) {
1280
- release = createScrollLock(html);
1281
- }
1282
- else if (!this.enabled() && release) {
1283
- release();
1284
- release = null;
2654
+ const wanted = this.enabled() ? (this.target() ?? root) : null;
2655
+ if (wanted === locked) {
2656
+ return;
1285
2657
  }
2658
+ release?.();
2659
+ release = wanted ? createScrollLock(wanted) : null;
2660
+ locked = wanted;
1286
2661
  });
1287
2662
  inject(DestroyRef).onDestroy(() => {
1288
2663
  release?.();
1289
2664
  });
1290
2665
  }
1291
2666
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1292
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollLock, isStandalone: true, selector: "[cngxScrollLock]", inputs: { enabled: { classPropertyName: "enabled", publicName: "cngxScrollLock", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxScrollLock"], ngImport: i0 });
2667
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollLock, isStandalone: true, selector: "[cngxScrollLock]", inputs: { enabled: { classPropertyName: "enabled", publicName: "cngxScrollLock", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "cngxScrollLockTarget", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxScrollLock"], ngImport: i0 });
1293
2668
  }
1294
2669
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, decorators: [{
1295
2670
  type: Directive,
@@ -1298,7 +2673,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1298
2673
  exportAs: 'cngxScrollLock',
1299
2674
  standalone: true,
1300
2675
  }]
1301
- }], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }] } });
2676
+ }], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLockTarget", required: false }] }] } });
1302
2677
 
1303
2678
  /** Distances up to this many px count as "at the edge" (sub-pixel and zoom rounding). */
1304
2679
  const EDGE_TOLERANCE = 1;
@@ -1314,19 +2689,32 @@ function sameEdges(a, b) {
1314
2689
  a.inlineStart === b.inlineStart &&
1315
2690
  a.inlineEnd === b.inlineEnd);
1316
2691
  }
2692
+ /** `vertical-*` and `sideways-*` both lay the block axis out horizontally. */
2693
+ function isVerticalWritingMode(writingMode) {
2694
+ return writingMode.startsWith('vertical-') || writingMode.startsWith('sideways-');
2695
+ }
1317
2696
  /**
1318
2697
  * One read of the six scroll metrics. RTL `scrollLeft` runs over `[-max, 0]`
1319
2698
  * in every evergreen engine and LTR over `[0, max]`, so its magnitude is the
1320
2699
  * distance from the inline-start edge in both directions - no direction lookup
1321
- * and no `getComputedStyle` in the scroll path.
2700
+ * in the scroll path. A vertical writing mode swaps the axes: the block axis
2701
+ * runs on `scrollLeft` (negative under `vertical-rl`, whose block-start is the
2702
+ * right edge) and the inline axis on `scrollTop`.
1322
2703
  */
1323
- function readEdges(element) {
1324
- const inlineOffset = Math.abs(element.scrollLeft);
2704
+ function readEdges(element, vertical) {
2705
+ const horizontalOffset = Math.abs(element.scrollLeft);
2706
+ const verticalOffset = Math.abs(element.scrollTop);
2707
+ const horizontalMax = element.scrollWidth - element.clientWidth;
2708
+ const verticalMax = element.scrollHeight - element.clientHeight;
2709
+ const blockOffset = vertical ? horizontalOffset : verticalOffset;
2710
+ const blockMax = vertical ? horizontalMax : verticalMax;
2711
+ const inlineOffset = vertical ? verticalOffset : horizontalOffset;
2712
+ const inlineMax = vertical ? verticalMax : horizontalMax;
1325
2713
  return {
1326
- blockStart: element.scrollTop > EDGE_TOLERANCE,
1327
- blockEnd: element.scrollHeight - element.clientHeight - element.scrollTop > EDGE_TOLERANCE,
2714
+ blockStart: blockOffset > EDGE_TOLERANCE,
2715
+ blockEnd: blockMax - blockOffset > EDGE_TOLERANCE,
1328
2716
  inlineStart: inlineOffset > EDGE_TOLERANCE,
1329
- inlineEnd: element.scrollWidth - element.clientWidth - inlineOffset > EDGE_TOLERANCE,
2717
+ inlineEnd: inlineMax - inlineOffset > EDGE_TOLERANCE,
1330
2718
  };
1331
2719
  }
1332
2720
  /**
@@ -1353,7 +2741,7 @@ function readEdges(element) {
1353
2741
  * inject(DestroyRef),
1354
2742
  * inject(DOCUMENT).defaultView,
1355
2743
  * );
1356
- * const showTopShadow = edges.canScrollBlockStart;
2744
+ * const showStartShadow = edges.canScrollBlockStart;
1357
2745
  * ```
1358
2746
  *
1359
2747
  * @param element The scrollport to read.
@@ -1361,9 +2749,8 @@ function readEdges(element) {
1361
2749
  * every observer and cancels a pending frame.
1362
2750
  * @param host The window-like object to read the observer and frame APIs from.
1363
2751
  * @returns The four per-edge signals.
1364
- * @category common/layout
1365
2752
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges-core.ts
1366
- * @since 0.1.0
2753
+ * @since 0.3.0
1367
2754
  * @relatedTo CngxScrollEdges, observeResize
1368
2755
  */
1369
2756
  function createScrollEdges(element, destroyRef, host) {
@@ -1380,12 +2767,16 @@ function createScrollEdges(element, destroyRef, host) {
1380
2767
  let destroyed = false;
1381
2768
  let framePending = false;
1382
2769
  let frameHandle = 0;
2770
+ // Resolved on the first frame read, not here: a getComputedStyle at
2771
+ // construction would force a style recalc before the first render.
2772
+ let vertical = null;
1383
2773
  const read = () => {
1384
2774
  framePending = false;
1385
2775
  if (destroyed) {
1386
2776
  return;
1387
2777
  }
1388
- edges.set(readEdges(element));
2778
+ vertical ??= isVerticalWritingMode(host.getComputedStyle?.(element).writingMode ?? '');
2779
+ edges.set(readEdges(element, vertical));
1389
2780
  };
1390
2781
  const schedule = () => {
1391
2782
  if (destroyed || framePending) {
@@ -1451,14 +2842,17 @@ function createScrollEdges(element, destroyRef, host) {
1451
2842
  * the scroll metrics per animation frame; the attributes are present (empty
1452
2843
  * value) while true and absent otherwise:
1453
2844
  *
1454
- * - `data-scroll-block-start` / `canScrollBlockStart()` - content hidden above
1455
- * - `data-scroll-block-end` / `canScrollBlockEnd()` - content hidden below
2845
+ * - `data-scroll-block-start` / `canScrollBlockStart()` - hidden toward block start
2846
+ * - `data-scroll-block-end` / `canScrollBlockEnd()` - hidden toward block end
1456
2847
  * - `data-scroll-inline-start` / `canScrollInlineStart()` - hidden toward inline start
1457
2848
  * - `data-scroll-inline-end` / `canScrollInlineEnd()` - hidden toward inline end
1458
2849
  *
1459
- * Inline start / end follow the writing direction: in `dir="rtl"` the start
1460
- * edge is on the right. The direction is derived from the scroll offset
1461
- * itself, so a `dir="rtl"` subtree inside an LTR page reports correctly.
2850
+ * In a horizontal writing mode block start / end are the top and bottom
2851
+ * edges; under a `vertical-*` or `sideways-*` writing mode they are the
2852
+ * horizontal ones. Inline start / end follow the writing direction: in
2853
+ * `dir="rtl"` the start edge is on the right. The direction is derived from
2854
+ * the scroll offset itself, so a `dir="rtl"` subtree inside an LTR page
2855
+ * reports correctly.
1462
2856
  *
1463
2857
  * The directive paints nothing. The four attributes (present only while true)
1464
2858
  * are its public, stable contract; every visual belongs to the consumer CSS,
@@ -1498,23 +2892,22 @@ function createScrollEdges(element, destroyRef, host) {
1498
2892
  * `@container scroll-state(scrollable: block-start)` and its siblings, so the
1499
2893
  * CSS can swap to native scroll-state queries once they are Baseline.
1500
2894
  *
1501
- * @category common/layout
1502
- * @docsKind primary
1503
2895
  * @wcag AA
1504
2896
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges.directive.ts
1505
- * @since 0.1.0
2897
+ * @since 0.3.0
1506
2898
  * @relatedTo CngxStickyHeader, CngxScrollSpy, createScrollEdges
1507
- * <example-url>http://localhost:4200/#/common/layout/scroll-edges/edge-shadows</example-url>
2899
+ * <example-url>/#/common/layout/scroll-edges/edge-shadows</example-url>
2900
+ * @axis level atom
1508
2901
  */
1509
2902
  class CngxScrollEdges {
1510
2903
  edges = createScrollEdges(inject(ElementRef).nativeElement, inject(DestroyRef), isPlatformBrowser(inject(PLATFORM_ID)) ? inject(DOCUMENT).defaultView : null);
1511
- /** Content is hidden toward the block-start edge (above). */
2904
+ /** Content is hidden toward the block-start edge (top in horizontal writing modes). */
1512
2905
  canScrollBlockStart = this.edges.canScrollBlockStart;
1513
- /** Content is hidden toward the block-end edge (below). */
2906
+ /** Content is hidden toward the block-end edge (bottom in horizontal writing modes). */
1514
2907
  canScrollBlockEnd = this.edges.canScrollBlockEnd;
1515
- /** Content is hidden toward the inline-start edge (left in LTR, right in RTL). */
2908
+ /** Content is hidden toward the inline-start edge (left in LTR, right in RTL, horizontally). */
1516
2909
  canScrollInlineStart = this.edges.canScrollInlineStart;
1517
- /** Content is hidden toward the inline-end edge (right in LTR, left in RTL). */
2910
+ /** Content is hidden toward the inline-end edge (right in LTR, left in RTL, horizontally). */
1518
2911
  canScrollInlineEnd = this.edges.canScrollInlineEnd;
1519
2912
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollEdges, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1520
2913
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxScrollEdges, isStandalone: true, selector: "[cngxScrollEdges]", host: { properties: { "attr.data-scroll-block-start": "canScrollBlockStart() ? '' : null", "attr.data-scroll-block-end": "canScrollBlockEnd() ? '' : null", "attr.data-scroll-inline-start": "canScrollInlineStart() ? '' : null", "attr.data-scroll-inline-end": "canScrollInlineEnd() ? '' : null" } }, exportAs: ["cngxScrollEdges"], ngImport: i0 });
@@ -1534,6 +2927,331 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1534
2927
  }]
1535
2928
  }] });
1536
2929
 
2930
+ /** @internal See {@link CngxSidebarDriver}. */
2931
+ const CNGX_SIDEBAR_DRIVER = new InjectionToken('CngxSidebarDriver');
2932
+ /**
2933
+ * The brain of a persistent side region: a sidebar that stays in the layout
2934
+ * and reserves inline space, unlike a drawer, which is transient.
2935
+ *
2936
+ * `collapsed` (two-way) switches between the expanded size and the
2937
+ * collapsed rest, `collapsedAs` picks the rest: a `rail` stays operable at
2938
+ * `--cngx-sidebar-rail-size`, `hidden` reserves nothing and becomes `inert`
2939
+ * + `aria-hidden`. A collapsed sidebar can **peek**: it shows at full size
2940
+ * over the content without reflowing it (the reserved space stays at the
2941
+ * rest size). Peek comes from the pointer resting on the host
2942
+ * (`CngxHoverIntent`, gated by `expandOnHover`) or from `peek()`, and ends
2943
+ * on Escape (wherever focus is, so a hover peek over the page is
2944
+ * dismissible without moving focus, WCAG 1.4.13), on a press outside the
2945
+ * host (a press on the trigger whose `aria-controls` names the sidebar is
2946
+ * left to the trigger), when focus leaves the host, or when the pointer
2947
+ * leaves the host after resting on it. A `peek()` from a trigger outside the
2948
+ * host therefore stays until one of these happens, even if the pointer never
2949
+ * enters.
2950
+ * `pin()` turns a peek into the expanded state.
2951
+ *
2952
+ * `side` names the edge the sidebar sits on (`start`, default, or `end` for
2953
+ * an inspector after the content); a peek grows away from it.
2954
+ *
2955
+ * Sizes are tokens with fallbacks: `--cngx-sidebar-size` (expanded, default
2956
+ * `16rem`) and `--cngx-sidebar-rail-size` (default `3.5rem`), plus
2957
+ * `--cngx-sidebar-peek-z-index`. The host renders `data-sidebar-state`
2958
+ * (`expanded | rail | hidden | peek`) and `data-sidebar-side` for skins.
2959
+ * The base skin is opt-in with the `cngx-sidebar` class (`cngx-sidebar.css`
2960
+ * in `@cngx/themes/cngx.css`): surface, border and peek shadow of the box,
2961
+ * nothing for its content.
2962
+ *
2963
+ * The sidebar is a `CngxPanelTarget` and provides `CNGX_PANEL_TARGET`: a
2964
+ * `[cngxPanelTrigger]="sidebar"` mirrors `expanded` and toggles `collapsed`;
2965
+ * `action="peek"` peeks. It knows no nav model; `[cngxNavRailed]` crops the
2966
+ * nav rows inside it on the rail and adds the rail tooltip and group flyout.
2967
+ *
2968
+ * ```html
2969
+ * <button type="button" [cngxPanelTrigger]="sidebar"></button>
2970
+ * <div style="display: flex">
2971
+ * <nav cngxSidebar #sidebar="cngxSidebar" [(collapsed)]="collapsed" [role]="null">…</nav>
2972
+ * <main>…</main>
2973
+ * </div>
2974
+ * ```
2975
+ *
2976
+ * @wcag AA
2977
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/sidebar/sidebar.directive.ts
2978
+ * @since 0.3.0
2979
+ * @relatedTo CngxPanelTrigger, CngxDrawer, CngxHoverIntent, CngxResizable
2980
+ * <example-url>/#/common/layout/sidebar/clipped-below-header</example-url>
2981
+ * <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
2982
+ * <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
2983
+ * <example-url>/#/common/layout/sidebar/projected-toggle-glyph</example-url>
2984
+ * @axis level molecule
2985
+ */
2986
+ class CngxSidebar {
2987
+ /** Whether the sidebar rests collapsed. Two-way: `[(collapsed)]`. */
2988
+ collapsed = model(false, ...(ngDevMode ? [{ debugName: "collapsed" }] : /* istanbul ignore next */ []));
2989
+ /** How a collapsed sidebar rests: an operable `rail` or `hidden`. */
2990
+ collapsedAs = input('rail', ...(ngDevMode ? [{ debugName: "collapsedAs" }] : /* istanbul ignore next */ []));
2991
+ /**
2992
+ * {@link CngxPanelTarget}: the edge the sidebar sits on, in the writing
2993
+ * direction. A peek grows away from it.
2994
+ */
2995
+ side = input('start', ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
2996
+ /** Whether the pointer resting on a collapsed sidebar peeks it. */
2997
+ expandOnHover = input(true, ...(ngDevMode ? [{ debugName: "expandOnHover" }] : /* istanbul ignore next */ []));
2998
+ /**
2999
+ * ms the pointer rests on a collapsed sidebar before it peeks. Unbound,
3000
+ * `CNGX_HOVER_INTENT_DEFAULTS` applies, then 120.
3001
+ */
3002
+ expandDelay = input(undefined, ...(ngDevMode ? [{ debugName: "expandDelay" }] : /* istanbul ignore next */ []));
3003
+ /**
3004
+ * ms after the pointer leaves before a hover peek ends. Unbound,
3005
+ * `CNGX_HOVER_INTENT_DEFAULTS` applies, then 0.
3006
+ */
3007
+ collapseDelay = input(undefined, ...(ngDevMode ? [{ debugName: "collapseDelay" }] : /* istanbul ignore next */ []));
3008
+ /** @internal Drives the composed `CngxHoverIntent`. */
3009
+ hoverEnterDelay = this.expandDelay;
3010
+ /** @internal Drives the composed `CngxHoverIntent`. */
3011
+ hoverLeaveDelay = this.collapseDelay;
3012
+ /**
3013
+ * Landmark role. Defaults to `complementary`; pass `navigation` for a nav
3014
+ * sidebar, or `null` on a `<nav>` / `<aside>` host to keep its implicit role.
3015
+ */
3016
+ roleInput = input(undefined, { ...(ngDevMode ? { debugName: "roleInput" } : /* istanbul ignore next */ {}), alias: 'role' });
3017
+ /**
3018
+ * Accessible name of the region. Falls back to `CNGX_LAYOUT_I18N.sidebarRegion`
3019
+ * while the role is `complementary`.
3020
+ */
3021
+ labelInput = input(undefined, { ...(ngDevMode ? { debugName: "labelInput" } : /* istanbul ignore next */ {}), alias: 'label' });
3022
+ hover = inject(CngxHoverIntent, { self: true });
3023
+ injector = inject(Injector);
3024
+ resolvedDriver = undefined;
3025
+ driver() {
3026
+ if (this.resolvedDriver === undefined) {
3027
+ this.resolvedDriver = this.injector.get(CNGX_SIDEBAR_DRIVER, null, { self: true });
3028
+ }
3029
+ return this.resolvedDriver;
3030
+ }
3031
+ // What the sidebar renders: the driver wins over the inputs.
3032
+ restCollapsed = computed(() => this.driver()?.sidebarCollapsed() ?? this.collapsed(), ...(ngDevMode ? [{ debugName: "restCollapsed" }] : /* istanbul ignore next */ []));
3033
+ restAs = computed(() => this.driver()?.sidebarCollapsedAs?.() ?? this.collapsedAs(), ...(ngDevMode ? [{ debugName: "restAs" }] : /* istanbul ignore next */ []));
3034
+ host = inject(ElementRef).nativeElement;
3035
+ doc = inject(DOCUMENT);
3036
+ i18n = injectLayoutI18n();
3037
+ // An explicit peek ends when the pointer leaves the host after resting on
3038
+ // it; a pointer that never entered (a peek from an outside trigger) keeps
3039
+ // it until a press outside, Escape or focus leaving.
3040
+ peekState = linkedSignal({ ...(ngDevMode ? { debugName: "peekState" } : /* istanbul ignore next */ {}), source: this.hover.active,
3041
+ computation: (active, previous) => active && (previous?.value ?? false) });
3042
+ // Escape ends a hover peek while the pointer still rests on the host; the
3043
+ // next hover edge lifts the suppression.
3044
+ hoverSuppressed = linkedSignal({ ...(ngDevMode ? { debugName: "hoverSuppressed" } : /* istanbul ignore next */ {}), source: this.hover.active,
3045
+ computation: () => false });
3046
+ /**
3047
+ * The host `id` (a static `id` attribute, else a generated one); the
3048
+ * trigger's `aria-controls`.
3049
+ */
3050
+ id = signal(inject(new HostAttributeToken('id'), { optional: true }) ?? nextUid('cngx-sidebar')).asReadonly();
3051
+ /** {@link CngxPanelTarget}: a sidebar reserves inline space, it is never an overlay. */
3052
+ mode = signal('inline').asReadonly();
3053
+ /** Whether a collapsed sidebar currently shows at full size over the content. */
3054
+ peeked = computed(() => {
3055
+ if (!this.restCollapsed()) {
3056
+ return false;
3057
+ }
3058
+ if (this.peekState() || (this.driver()?.sidebarPeek?.() ?? false)) {
3059
+ return true;
3060
+ }
3061
+ return this.expandOnHover() && this.hover.active() && !this.hoverSuppressed();
3062
+ }, ...(ngDevMode ? [{ debugName: "peeked" }] : /* istanbul ignore next */ []));
3063
+ /** Whether the sidebar shows at full size: expanded, or collapsed and peeked. */
3064
+ expanded = computed(() => !this.restCollapsed() || this.peeked(), ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
3065
+ /** The rendered state: `expanded`, `peek`, or the collapsed rest. */
3066
+ state = computed(() => {
3067
+ if (!this.restCollapsed()) {
3068
+ return 'expanded';
3069
+ }
3070
+ return this.peeked() ? 'peek' : this.restAs();
3071
+ }, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
3072
+ /**
3073
+ * The rendered landmark role: the bound `role` (`null` keeps the host's
3074
+ * implicit role), else the composer's, else `complementary`.
3075
+ */
3076
+ role = computed(() => {
3077
+ const bound = this.roleInput();
3078
+ if (bound !== undefined) {
3079
+ return bound;
3080
+ }
3081
+ return this.driver()?.sidebarRole?.() ?? 'complementary';
3082
+ }, ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
3083
+ concealed = computed(() => this.state() === 'hidden' || (this.driver()?.sidebarConcealed?.() ?? false), ...(ngDevMode ? [{ debugName: "concealed" }] : /* istanbul ignore next */ []));
3084
+ /**
3085
+ * {@link CngxPanelTarget}: the region's resolved accessible name, the bound
3086
+ * `label`, else `CNGX_LAYOUT_I18N.sidebarRegion` while the role is
3087
+ * `complementary` (a `navigation` landmark announces its role already). An
3088
+ * icon-only trigger takes it as its name.
3089
+ */
3090
+ label = computed(() => {
3091
+ // A composer that names the region itself wins outright; its own
3092
+ // cascade already resolved input, config and copy.
3093
+ const driven = this.driver()?.sidebarLabel;
3094
+ if (driven) {
3095
+ return driven();
3096
+ }
3097
+ const fallback = this.role() === 'complementary' ? this.i18n().sidebarRegion : undefined;
3098
+ return this.labelInput() ?? fallback;
3099
+ }, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
3100
+ inlineSize = computed(() => {
3101
+ switch (this.state()) {
3102
+ case 'rail':
3103
+ return 'var(--cngx-sidebar-rail-size, 3.5rem)';
3104
+ case 'hidden':
3105
+ return '0px';
3106
+ default:
3107
+ return 'var(--cngx-sidebar-size, 16rem)';
3108
+ }
3109
+ }, ...(ngDevMode ? [{ debugName: "inlineSize" }] : /* istanbul ignore next */ []));
3110
+ // A peek keeps the rest footprint: a negative margin on the edge facing
3111
+ // the content cancels the growth, so the content does not reflow.
3112
+ peekOffset = computed(() => {
3113
+ if (!this.peeked()) {
3114
+ return null;
3115
+ }
3116
+ const rest = this.restAs() === 'rail' ? 'var(--cngx-sidebar-rail-size, 3.5rem)' : '0px';
3117
+ return `calc(${rest} - var(--cngx-sidebar-size, 16rem))`;
3118
+ }, ...(ngDevMode ? [{ debugName: "peekOffset" }] : /* istanbul ignore next */ []));
3119
+ constructor() {
3120
+ // The hidden rest moves focus out first: aria-hidden on an element that
3121
+ // holds focus is blocked (and warned about) by the browser, and inert
3122
+ // alone would only drop focus on the next rendering step. A composer that
3123
+ // conceals through the driver owns that move, since it may keep focus
3124
+ // inside by changing its own state in the same pass.
3125
+ effect(() => {
3126
+ if (this.state() !== 'hidden') {
3127
+ return;
3128
+ }
3129
+ untracked(() => {
3130
+ const active = this.doc.activeElement;
3131
+ if (active instanceof HTMLElement && this.host.contains(active)) {
3132
+ active.blur();
3133
+ }
3134
+ });
3135
+ });
3136
+ // A peek is content shown on hover: Escape must dismiss it even while
3137
+ // focus sits elsewhere on the page. Listen on the document only while
3138
+ // peeked; an Escape inside the host is the host binding's.
3139
+ effect((onCleanup) => {
3140
+ if (!this.peeked()) {
3141
+ return;
3142
+ }
3143
+ const onKeydown = (event) => {
3144
+ if (event.key !== 'Escape') {
3145
+ return;
3146
+ }
3147
+ if (event.target instanceof Node && this.host.contains(event.target)) {
3148
+ return;
3149
+ }
3150
+ this.unpeek();
3151
+ };
3152
+ // A press on the page beside the peek ends it; the trigger that names
3153
+ // the sidebar in aria-controls handles its own press.
3154
+ const onPointerDown = (event) => {
3155
+ const target = event.target;
3156
+ if (!(target instanceof Element) || this.host.contains(target)) {
3157
+ return;
3158
+ }
3159
+ if (this.isController(target)) {
3160
+ return;
3161
+ }
3162
+ this.unpeek();
3163
+ };
3164
+ this.doc.addEventListener('keydown', onKeydown);
3165
+ this.doc.addEventListener('pointerdown', onPointerDown, true);
3166
+ onCleanup(() => {
3167
+ this.doc.removeEventListener('keydown', onKeydown);
3168
+ this.doc.removeEventListener('pointerdown', onPointerDown, true);
3169
+ });
3170
+ });
3171
+ }
3172
+ /** Collapses an expanded sidebar, expands a collapsed one. Ends a peek. */
3173
+ toggle() {
3174
+ this.peekState.set(false);
3175
+ this.collapsed.update((collapsed) => !collapsed);
3176
+ }
3177
+ /** Shows a collapsed sidebar at full size over the content until dismissed. */
3178
+ peek() {
3179
+ if (this.restCollapsed()) {
3180
+ this.peekState.set(true);
3181
+ }
3182
+ }
3183
+ /** Ends a peek without changing `collapsed`. */
3184
+ unpeek() {
3185
+ this.peekState.set(false);
3186
+ if (this.hover.active()) {
3187
+ this.hoverSuppressed.set(true);
3188
+ }
3189
+ }
3190
+ /** Keeps the sidebar expanded: `collapsed = false`, any peek ends. */
3191
+ pin() {
3192
+ this.peekState.set(false);
3193
+ this.collapsed.set(false);
3194
+ }
3195
+ isController(target) {
3196
+ const controller = target.closest('[aria-controls]');
3197
+ const ids = controller?.getAttribute('aria-controls')?.split(/\s+/) ?? [];
3198
+ return ids.includes(this.id());
3199
+ }
3200
+ // One Escape dismisses one layer: an open popover inside the host or an
3201
+ // inner surface goes first. A driven peek is the composer's to dismiss, so
3202
+ // its Escape stays unclaimed for the composer's own surface.
3203
+ handleEscape(event) {
3204
+ if (!this.peeked() || escapeOwnedAbove(event, this.host)) {
3205
+ return;
3206
+ }
3207
+ if (this.driver()?.sidebarPeek?.()) {
3208
+ return;
3209
+ }
3210
+ claimEscape(event);
3211
+ this.unpeek();
3212
+ }
3213
+ handleFocusOut(event) {
3214
+ const next = event.relatedTarget;
3215
+ if (next instanceof Node && this.host.contains(next)) {
3216
+ return;
3217
+ }
3218
+ this.peekState.set(false);
3219
+ }
3220
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSidebar, deps: [], target: i0.ɵɵFactoryTarget.Directive });
3221
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSidebar, isStandalone: true, selector: "[cngxSidebar]", inputs: { collapsed: { classPropertyName: "collapsed", publicName: "collapsed", isSignal: true, isRequired: false, transformFunction: null }, collapsedAs: { classPropertyName: "collapsedAs", publicName: "collapsedAs", isSignal: true, isRequired: false, transformFunction: null }, side: { classPropertyName: "side", publicName: "side", isSignal: true, isRequired: false, transformFunction: null }, expandOnHover: { classPropertyName: "expandOnHover", publicName: "expandOnHover", isSignal: true, isRequired: false, transformFunction: null }, expandDelay: { classPropertyName: "expandDelay", publicName: "expandDelay", isSignal: true, isRequired: false, transformFunction: null }, collapseDelay: { classPropertyName: "collapseDelay", publicName: "collapseDelay", isSignal: true, isRequired: false, transformFunction: null }, roleInput: { classPropertyName: "roleInput", publicName: "role", isSignal: true, isRequired: false, transformFunction: null }, labelInput: { classPropertyName: "labelInput", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { collapsed: "collapsedChange" }, host: { listeners: { "keydown.escape": "handleEscape($event)", "focusout": "handleFocusOut($event)" }, properties: { "attr.id": "id()", "attr.role": "role()", "attr.aria-label": "label() ?? null", "attr.inert": "concealed() ? '' : null", "attr.aria-hidden": "concealed() ? 'true' : null", "attr.data-sidebar-state": "state()", "attr.data-sidebar-side": "side()", "style.inline-size": "inlineSize()", "style.margin-inline-end": "side() === 'start' ? peekOffset() : null", "style.margin-inline-start": "side() === 'end' ? peekOffset() : null", "style.z-index": "peeked() ? 'var(--cngx-sidebar-peek-z-index, 2)' : null" } }, providers: [
3222
+ { provide: CNGX_PANEL_TARGET, useExisting: CngxSidebar },
3223
+ { provide: CNGX_HOVER_INTENT_DRIVER, useExisting: CngxSidebar },
3224
+ ], exportAs: ["cngxSidebar"], hostDirectives: [{ directive: i2.CngxHoverIntent }], ngImport: i0 });
3225
+ }
3226
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSidebar, decorators: [{
3227
+ type: Directive,
3228
+ args: [{
3229
+ selector: '[cngxSidebar]',
3230
+ exportAs: 'cngxSidebar',
3231
+ standalone: true,
3232
+ hostDirectives: [CngxHoverIntent],
3233
+ providers: [
3234
+ { provide: CNGX_PANEL_TARGET, useExisting: CngxSidebar },
3235
+ { provide: CNGX_HOVER_INTENT_DRIVER, useExisting: CngxSidebar },
3236
+ ],
3237
+ host: {
3238
+ '[attr.id]': 'id()',
3239
+ '[attr.role]': 'role()',
3240
+ '[attr.aria-label]': 'label() ?? null',
3241
+ '[attr.inert]': "concealed() ? '' : null",
3242
+ '[attr.aria-hidden]': "concealed() ? 'true' : null",
3243
+ '[attr.data-sidebar-state]': 'state()',
3244
+ '[attr.data-sidebar-side]': 'side()',
3245
+ '[style.inline-size]': 'inlineSize()',
3246
+ '[style.margin-inline-end]': "side() === 'start' ? peekOffset() : null",
3247
+ '[style.margin-inline-start]': "side() === 'end' ? peekOffset() : null",
3248
+ '[style.z-index]': "peeked() ? 'var(--cngx-sidebar-peek-z-index, 2)' : null",
3249
+ '(keydown.escape)': 'handleEscape($event)',
3250
+ '(focusout)': 'handleFocusOut($event)',
3251
+ },
3252
+ }]
3253
+ }], ctorParameters: () => [], propDecorators: { collapsed: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapsed", required: false }] }, { type: i0.Output, args: ["collapsedChange"] }], collapsedAs: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapsedAs", required: false }] }], side: [{ type: i0.Input, args: [{ isSignal: true, alias: "side", required: false }] }], expandOnHover: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandOnHover", required: false }] }], expandDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandDelay", required: false }] }], collapseDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapseDelay", required: false }] }], roleInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }], labelInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
3254
+
1537
3255
  /**
1538
3256
  * Headless skeleton loading placeholder.
1539
3257
  *
@@ -1541,7 +3259,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1541
3259
  * No template -- the consumer renders the skeleton UI.
1542
3260
  *
1543
3261
  * Exposes an `indices()` signal for `@for` rendering of repeated skeleton elements.
1544
- * Respects `prefers-reduced-motion` (disables shimmer animation class).
3262
+ * Respects reduced motion, the in-app `CNGX_MOTION` pick or the OS query
3263
+ * (disables shimmer animation class).
1545
3264
  *
1546
3265
  * ### Basic loading placeholder
1547
3266
  * ```html
@@ -1574,14 +3293,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1574
3293
  * </div>
1575
3294
  * ```
1576
3295
  *
1577
- * @category common/layout
1578
- * @docsKind primary
1579
3296
  * @wcag AA
1580
3297
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/skeleton.directive.ts
1581
- * @since 0.1.0
3298
+ * @since 0.3.0
1582
3299
  * @relatedTo CngxTruncate, CngxExpandableText, CngxHighlight
1583
- * <example-url>http://localhost:4200/#/common/layout/skeleton/basic-skeleton</example-url>
1584
- * <example-url>http://localhost:4200/#/common/layout/skeleton/skeleton-container</example-url>
3300
+ * <example-url>/#/common/layout/skeleton/basic-skeleton</example-url>
3301
+ * @axis level atom
1585
3302
  */
1586
3303
  class CngxSkeleton {
1587
3304
  /** Controls the loading state. */
@@ -1590,18 +3307,15 @@ class CngxSkeleton {
1590
3307
  shimmer = input(true, ...(ngDevMode ? [{ debugName: "shimmer" }] : /* istanbul ignore next */ []));
1591
3308
  /** Repeat count - exposed via the `indices()` signal for `@for` rendering. */
1592
3309
  count = input(1, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
1593
- prefersReducedMotion;
1594
- constructor() {
1595
- this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
1596
- }
3310
+ motion = injectEffectiveMotion();
1597
3311
  /** Whether the skeleton is in loading state. Mirrors the `cngxSkeleton` input. */
1598
3312
  loading = computed(() => this.skeleton(), ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1599
3313
  /** Array of indices for `@for` rendering of repeated skeleton elements. */
1600
3314
  indices = computed(() => Array.from({ length: this.count() }, (_, i) => i), ...(ngDevMode ? [{ debugName: "indices" }] : /* istanbul ignore next */ []));
1601
3315
  /** @internal - shimmer class condition. */
1602
- showShimmer = computed(() => this.loading() && this.shimmer() && !this.prefersReducedMotion(), ...(ngDevMode ? [{ debugName: "showShimmer" }] : /* istanbul ignore next */ []));
3316
+ showShimmer = computed(() => this.loading() && this.shimmer() && this.motion() !== 'reduced', ...(ngDevMode ? [{ debugName: "showShimmer" }] : /* istanbul ignore next */ []));
1603
3317
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1604
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSkeleton, isStandalone: true, selector: "[cngxSkeleton]", inputs: { skeleton: { classPropertyName: "skeleton", publicName: "cngxSkeleton", isSignal: true, isRequired: false, transformFunction: null }, shimmer: { classPropertyName: "shimmer", publicName: "shimmer", isSignal: true, isRequired: false, transformFunction: null }, count: { classPropertyName: "count", publicName: "count", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-skeleton--loading": "loading()", "class.cngx-skeleton--shimmer": "showShimmer()", "attr.aria-busy": "loading() || null" }, classAttribute: "cngx-skeleton" }, exportAs: ["cngxSkeleton"], ngImport: i0 });
3318
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSkeleton, isStandalone: true, selector: "[cngxSkeleton]", inputs: { skeleton: { classPropertyName: "skeleton", publicName: "cngxSkeleton", isSignal: true, isRequired: false, transformFunction: null }, shimmer: { classPropertyName: "shimmer", publicName: "shimmer", isSignal: true, isRequired: false, transformFunction: null }, count: { classPropertyName: "count", publicName: "count", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-skeleton--loading": "loading()", "class.cngx-skeleton--shimmer": "showShimmer()", "attr.aria-busy": "loading() || null", "attr.data-cngx-busy": "loading() || null" }, classAttribute: "cngx-skeleton" }, exportAs: ["cngxSkeleton"], ngImport: i0 });
1605
3319
  }
1606
3320
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, decorators: [{
1607
3321
  type: Directive,
@@ -1614,9 +3328,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1614
3328
  '[class.cngx-skeleton--loading]': 'loading()',
1615
3329
  '[class.cngx-skeleton--shimmer]': 'showShimmer()',
1616
3330
  '[attr.aria-busy]': 'loading() || null',
3331
+ '[attr.data-cngx-busy]': 'loading() || null',
1617
3332
  },
1618
3333
  }]
1619
- }], ctorParameters: () => [], propDecorators: { skeleton: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSkeleton", required: false }] }], shimmer: [{ type: i0.Input, args: [{ isSignal: true, alias: "shimmer", required: false }] }], count: [{ type: i0.Input, args: [{ isSignal: true, alias: "count", required: false }] }] } });
3334
+ }], propDecorators: { skeleton: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSkeleton", required: false }] }], shimmer: [{ type: i0.Input, args: [{ isSignal: true, alias: "shimmer", required: false }] }], count: [{ type: i0.Input, args: [{ isSignal: true, alias: "count", required: false }] }] } });
1620
3335
 
1621
3336
  /**
1622
3337
  * Infinite scroll trigger using `IntersectionObserver`.
@@ -1663,13 +3378,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1663
3378
  * </div>
1664
3379
  * ```
1665
3380
  *
1666
- * @category common/layout
1667
- * @docsKind primary
1668
3381
  * @wcag AA
1669
3382
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/infinite-scroll.directive.ts
1670
- * @since 0.1.0
3383
+ * @since 0.3.0
1671
3384
  * @relatedTo CngxIntersectionObserver, CngxScrollSpy, CngxStickyHeader
1672
- * <example-url>http://localhost:4200/#/common/layout/infinite-scroll/scrollable-list</example-url>
3385
+ * <example-url>/#/common/layout/infinite-scroll/scrollable-list</example-url>
3386
+ * @axis level atom
1673
3387
  */
1674
3388
  class CngxInfiniteScroll {
1675
3389
  /** IntersectionObserver threshold (0–1). */
@@ -1801,13 +3515,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1801
3515
  * .cngx-sticky--active { box-shadow: 0 2px 4px rgba(0,0,0,.1); }
1802
3516
  * ```
1803
3517
  *
1804
- * @category common/layout
1805
- * @docsKind primary
1806
3518
  * @wcag AA
1807
3519
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/sticky-header.directive.ts
1808
- * @since 0.1.0
3520
+ * @since 0.3.0
1809
3521
  * @relatedTo CngxScrollSpy, CngxIntersectionObserver
1810
- * <example-url>http://localhost:4200/#/common/layout/sticky-header/sticky-header-with-shadow</example-url>
3522
+ * <example-url>/#/common/layout/sticky-header/sticky-header-with-shadow</example-url>
3523
+ * @axis level atom
1811
3524
  */
1812
3525
  class CngxStickyHeader {
1813
3526
  /** Intersection threshold - `0` triggers as soon as the sentinel leaves. */
@@ -1938,13 +3651,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1938
3651
  * <section id="pricing">…</section>
1939
3652
  * ```
1940
3653
  *
1941
- * @category common/layout
1942
- * @docsKind primary
1943
3654
  * @wcag AA
1944
3655
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-spy.directive.ts
1945
- * @since 0.1.0
3656
+ * @since 0.3.0
1946
3657
  * @relatedTo CngxIntersectionObserver, CngxStickyHeader, CngxInfiniteScroll
1947
- * <example-url>http://localhost:4200/#/common/layout/scroll-spy/scroll-based-navigation</example-url>
3658
+ * <example-url>/#/common/layout/scroll-spy/scroll-based-navigation</example-url>
3659
+ * @axis level atom
1948
3660
  */
1949
3661
  class CngxScrollSpy {
1950
3662
  /** IDs of the sections to observe. */
@@ -2057,14 +3769,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2057
3769
  * </button> * }
2058
3770
  * ```
2059
3771
  *
2060
- * @category common/layout
2061
- * @docsKind primary
2062
3772
  * @wcag AA
2063
3773
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/truncate.directive.ts
2064
- * @since 0.1.0
3774
+ * @since 0.3.0
2065
3775
  * @relatedTo CngxExpandableText, CngxExpandableToggle, CngxHighlight
2066
- * <example-url>http://localhost:4200/#/common/layout/truncate/short-text-no-toggle</example-url>
2067
- * <example-url>http://localhost:4200/#/common/layout/truncate/truncated-text-with-toggle</example-url>
3776
+ * <example-url>/#/common/layout/truncate/short-text-no-toggle</example-url>
3777
+ * <example-url>/#/common/layout/truncate/truncated-text-with-toggle</example-url>
3778
+ * @axis level atom
2068
3779
  */
2069
3780
  class CngxTruncate {
2070
3781
  /** Maximum number of visible lines when collapsed. */
@@ -2172,14 +3883,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2172
3883
  * </p>
2173
3884
  * ```
2174
3885
  *
2175
- * @category common/layout
2176
- * @docsKind primary
2177
3886
  * @wcag AA
2178
3887
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/highlight.directive.ts
2179
- * @since 0.1.0
3888
+ * @since 0.3.0
2180
3889
  * @relatedTo CngxTruncate, CngxExpandableText
2181
- * <example-url>http://localhost:4200/#/common/layout/highlight/live-search-highlighting</example-url>
2182
- * <example-url>http://localhost:4200/#/common/layout/highlight/multiple-paragraphs</example-url>
3890
+ * <example-url>/#/common/layout/highlight/live-search-highlighting</example-url>
3891
+ * <example-url>/#/common/layout/highlight/multiple-paragraphs</example-url>
3892
+ * @axis level atom
2183
3893
  */
2184
3894
  class CngxHighlight {
2185
3895
  /** The search term to highlight. Empty string clears all highlights. */
@@ -2297,86 +4007,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2297
4007
  }]
2298
4008
  }], ctorParameters: () => [], propDecorators: { term: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxHighlight", required: false }] }], caseSensitive: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightCaseSensitive", required: false }] }] } });
2299
4009
 
2300
- /**
2301
- * The English layout section: the single source of the layout atoms'
2302
- * English copy. `CNGX_LAYOUT_I18N` defaults to it.
2303
- *
2304
- * @category common/layout/i18n
2305
- * @since 0.1.0
2306
- * @relatedTo CNGX_LAYOUT_I18N
2307
- */
2308
- const CNGX_LAYOUT_LANGUAGE_EN = {
2309
- expandableTextMore: 'Show more',
2310
- expandableTextLess: 'Show less',
2311
- };
2312
-
2313
- /** @internal The English section with the active pack's layout section on top. */
2314
- const layoutBundleFromPack = createLanguageSection('layout', CNGX_LAYOUT_LANGUAGE_EN);
2315
- /**
2316
- * DI token for the layout i18n bundle. `providedIn: 'root'`: the layout
2317
- * section of the active language pack over the English defaults; the value
2318
- * is a `Signal`, shared by every reader under one injector.
2319
- *
2320
- * @category common/layout/i18n
2321
- * @wcag AA
2322
- * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/i18n/layout-i18n.ts
2323
- * @since 0.1.0
2324
- * @relatedTo CngxExpandableText
2325
- */
2326
- const CNGX_LAYOUT_I18N = new InjectionToken('CngxLayoutI18n', {
2327
- providedIn: 'root',
2328
- factory: layoutBundleFromPack,
2329
- });
2330
- /** @internal */
2331
- function defineLayoutI18nFeature(fn) {
2332
- return Object.assign(fn, { _target: 'i18n' });
2333
- }
2334
- /**
2335
- * Override layout labels via a partial bundle - unset keys keep the
2336
- * language pack's copy, or the English default. Pass a `Signal` of a partial
2337
- * bundle to switch languages at runtime.
2338
- *
2339
- * @category common/layout/i18n
2340
- * @since 0.1.0
2341
- */
2342
- function withLayoutI18nLabels(overrides) {
2343
- return defineLayoutI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
2344
- }
2345
- /**
2346
- * Provider for the layout i18n bundle. Returns a plain `Provider`, so it
2347
- * also scopes a subtree through `viewProviders`. The features apply on top
2348
- * of the active language pack.
2349
- *
2350
- * ```ts
2351
- * bootstrapApplication(AppComponent, {
2352
- * providers: [
2353
- * provideLayoutI18n(
2354
- * withLayoutI18nLabels({ expandableTextMore: 'Mehr anzeigen', expandableTextLess: 'Weniger anzeigen' }),
2355
- * ),
2356
- * ],
2357
- * });
2358
- * ```
2359
- *
2360
- * @category common/layout/i18n
2361
- * @since 0.1.0
2362
- */
2363
- function provideLayoutI18n(...features) {
2364
- return {
2365
- provide: CNGX_LAYOUT_I18N,
2366
- useFactory: () => features.reduce((bundle, feat) => feat(bundle), layoutBundleFromPack()),
2367
- };
2368
- }
2369
- /**
2370
- * Inject the resolved layout i18n bundle signal. Read it inside a
2371
- * `computed()` or template so a runtime override flip re-derives.
2372
- *
2373
- * @category common/layout/i18n
2374
- * @since 0.1.0
2375
- */
2376
- function injectLayoutI18n() {
2377
- return inject(CNGX_LAYOUT_I18N);
2378
- }
2379
-
2380
4010
  /**
2381
4011
  * Marks a custom toggle template inside `cngx-expandable-text`.
2382
4012
  *
@@ -2391,9 +4021,8 @@ function injectLayoutI18n() {
2391
4021
  * </cngx-expandable-text>
2392
4022
  * ```
2393
4023
  *
2394
- * @category common/layout
2395
4024
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/expandable-text.ts
2396
- * @since 0.1.0
4025
+ * @since 0.3.0
2397
4026
  * @relatedTo CngxExpandableText, CngxTruncate
2398
4027
  */
2399
4028
  class CngxExpandableToggle {
@@ -2442,16 +4071,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2442
4071
  * </cngx-expandable-text>
2443
4072
  * ```
2444
4073
  *
2445
- * @category common/layout
2446
- * @docsKind primary
2447
4074
  * @wcag AA
2448
4075
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/expandable-text.ts
2449
- * @since 0.1.0
4076
+ * @since 0.3.0
2450
4077
  * @relatedTo CngxTruncate, CngxExpandableToggle, CngxHighlight
2451
4078
  * @slot cngxExpandableToggle Replaces the show-more control; gets the current expanded state.
2452
- * <example-url>http://localhost:4200/#/common/layout/expandable-text/auto-toggle</example-url>
2453
- * <example-url>http://localhost:4200/#/common/layout/expandable-text/custom-labels</example-url>
2454
- * <example-url>http://localhost:4200/#/common/layout/expandable-text/custom-toggle-template</example-url>
4079
+ * <example-url>/#/common/layout/expandable-text/auto-toggle</example-url>
4080
+ * <example-url>/#/common/layout/expandable-text/custom-labels</example-url>
4081
+ * <example-url>/#/common/layout/expandable-text/custom-toggle-template</example-url>
4082
+ * <example-url>/#/common/layout/expandable-text/card-with-expandable-text</example-url>
4083
+ * @axis level molecule
2455
4084
  */
2456
4085
  class CngxExpandableText {
2457
4086
  i18n = injectLayoutI18n();
@@ -2547,12 +4176,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2547
4176
  }], propDecorators: { lines: [{ type: i0.Input, args: [{ isSignal: true, alias: "lines", required: false }] }], expanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "expanded", required: false }] }, { type: i0.Output, args: ["expandedChange"] }], moreLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "moreLabel", required: false }] }], lessLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "lessLabel", required: false }] }], customToggle: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxExpandableToggle), { isSignal: true }] }] } });
2548
4177
 
2549
4178
  /**
2550
- * @module @cngx/common/layout
4179
+ * @module `@cngx/common/layout`
2551
4180
  */
2552
4181
 
2553
4182
  /**
2554
4183
  * Generated bundle index. Do not edit.
2555
4184
  */
2556
4185
 
2557
- export { CNGX_CONTAINER_SIZE, CNGX_LAYOUT_I18N, CNGX_LAYOUT_LANGUAGE_EN, CngxBackdrop, CngxContainer, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollEdges, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate, createContainerSize, createPinnedScrollLock, createResizeSignal, createScrollEdges, createScrollLock, injectContainerSize, injectLayoutI18n, injectMediaQuery, injectQueryParamSync, observeResize, provideLayoutI18n, withLayoutI18nLabels };
4186
+ export { CNGX_CONTAINER_SIZE, CNGX_DRAWER_HOST, CNGX_DRAWER_SURFACE_DRIVER, CNGX_LAYOUT_I18N, CNGX_LAYOUT_LANGUAGE_EN, CNGX_PANEL_TARGET, CNGX_RESIZABLE_DEFAULTS, CNGX_SIDEBAR_DRIVER, CngxBackdrop, CngxContainer, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxDrawerSurface, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxPanelToggle, CngxPanelTrigger, CngxResizable, CngxResizeObserver, CngxScrollEdges, CngxScrollLock, CngxScrollSpy, CngxSidebar, CngxSkeleton, CngxStickyHeader, CngxTruncate, createContainerSize, createPinnedScrollLock, createResizeSignal, createScrollEdges, createScrollLock, injectContainerSize, injectLayoutI18n, injectMediaQuery, injectQueryParamSync, observeResize, provideLayoutI18n, withLayoutI18nLabels };
2558
4187
  //# sourceMappingURL=cngx-common-layout.mjs.map