@cngx/common 0.1.0-rc.6 → 0.1.0-rc.8

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 (72) hide show
  1. package/card/README.md +2 -1
  2. package/chart/README.md +85 -0
  3. package/command/README.md +157 -0
  4. package/data/README.md +33 -1
  5. package/dialog/README.md +23 -1
  6. package/fesm2022/cngx-common-a11y.mjs +356 -180
  7. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  8. package/fesm2022/cngx-common-audio.mjs +84 -42
  9. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  10. package/fesm2022/cngx-common-card.mjs +311 -53
  11. package/fesm2022/cngx-common-card.mjs.map +1 -1
  12. package/fesm2022/cngx-common-chart.mjs +4360 -1625
  13. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  14. package/fesm2022/cngx-common-command.mjs +171 -0
  15. package/fesm2022/cngx-common-command.mjs.map +1 -0
  16. package/fesm2022/cngx-common-data.mjs +1556 -616
  17. package/fesm2022/cngx-common-data.mjs.map +1 -1
  18. package/fesm2022/cngx-common-dialog.mjs +518 -112
  19. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  20. package/fesm2022/cngx-common-display.mjs +468 -87
  21. package/fesm2022/cngx-common-display.mjs.map +1 -1
  22. package/fesm2022/cngx-common-interactive.mjs +2725 -1303
  23. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  24. package/fesm2022/cngx-common-layout.mjs +943 -164
  25. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  26. package/fesm2022/cngx-common-popover.mjs +769 -103
  27. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  28. package/fesm2022/cngx-common-stepper.mjs +816 -348
  29. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  30. package/fesm2022/cngx-common-tabs.mjs +2330 -1554
  31. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  32. package/fesm2022/cngx-common-timeline.mjs +1170 -0
  33. package/fesm2022/cngx-common-timeline.mjs.map +1 -0
  34. package/fesm2022/cngx-common.mjs +2 -2
  35. package/fesm2022/cngx-common.mjs.map +1 -1
  36. package/interactive/README.md +15 -4
  37. package/layout/README.md +21 -1
  38. package/package.json +11 -1
  39. package/popover/README.md +18 -2
  40. package/stepper/README.md +7 -5
  41. package/theming/components/cngx-accordion.css +4 -1
  42. package/theming/components/cngx-backdrop.css +12 -0
  43. package/theming/components/cngx-badge.css +22 -0
  44. package/theming/components/cngx-bottom-sheet.css +14 -2
  45. package/theming/components/cngx-breadcrumb.css +8 -0
  46. package/theming/components/cngx-button-toggle.css +73 -5
  47. package/theming/components/cngx-data-grid.css +234 -1
  48. package/theming/components/cngx-dialog.css +25 -0
  49. package/theming/components/cngx-divider.css +12 -0
  50. package/theming/components/cngx-listbox.css +48 -12
  51. package/theming/components/cngx-menu.css +91 -15
  52. package/theming/components/cngx-popover.css +24 -0
  53. package/theming/components/cngx-recycler-placeholder.css +196 -0
  54. package/theming/components/cngx-ripple.css +2 -2
  55. package/theming/components/cngx-slider.css +32 -1
  56. package/theming/components/cngx-tooltip.css +23 -0
  57. package/timeline/README.md +155 -0
  58. package/types/cngx-common-a11y.d.ts +101 -31
  59. package/types/cngx-common-audio.d.ts +32 -32
  60. package/types/cngx-common-card.d.ts +211 -20
  61. package/types/cngx-common-chart.d.ts +1605 -169
  62. package/types/cngx-common-command.d.ts +190 -0
  63. package/types/cngx-common-data.d.ts +842 -163
  64. package/types/cngx-common-dialog.d.ts +372 -28
  65. package/types/cngx-common-display.d.ts +432 -148
  66. package/types/cngx-common-interactive.d.ts +1553 -370
  67. package/types/cngx-common-layout.d.ts +613 -27
  68. package/types/cngx-common-popover.d.ts +376 -36
  69. package/types/cngx-common-stepper.d.ts +414 -114
  70. package/types/cngx-common-tabs.d.ts +597 -72
  71. package/types/cngx-common-timeline.d.ts +1125 -0
  72. package/types/cngx-common.d.ts +1 -1
@@ -1,7 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { input, Directive, inject, PLATFORM_ID, Injectable, ElementRef, Injector, DestroyRef, afterNextRender, effect, signal, computed, model, contentChildren, InjectionToken, output } from '@angular/core';
2
+ import { input, Directive, inject, PLATFORM_ID, Injectable, ElementRef, Injector, DestroyRef, afterNextRender, effect, signal, computed, untracked, model, contentChildren, InjectionToken, output } from '@angular/core';
3
3
  import { DOCUMENT, isPlatformBrowser } from '@angular/common';
4
4
  import { FocusTrapFactory } from '@angular/cdk/a11y';
5
+ import { injectDirection, resolveInlineStep, resolveStepFrom, resolveBoundaryStep } from '@cngx/core';
6
+ import { injectLocale, createTypeaheadMatcher, createMediaQuerySignal } from '@cngx/core/utils';
5
7
 
6
8
  /**
7
9
  * Manages `aria-expanded` and optionally `aria-controls` on the host element.
@@ -35,7 +37,6 @@ import { FocusTrapFactory } from '@angular/cdk/a11y';
35
37
  * ```
36
38
  *
37
39
  * @category common/a11y
38
- * @docsKind primary
39
40
  * @wcag AA
40
41
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/aria-expanded.directive.ts
41
42
  * @since 0.1.0
@@ -94,7 +95,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
94
95
  * ```
95
96
  *
96
97
  * @category common/a11y
97
- * @docsKind primary
98
98
  * @wcag AA
99
99
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-region.directive.ts
100
100
  * @since 0.1.0
@@ -132,22 +132,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
132
132
  }]
133
133
  }], propDecorators: { politeness: [{ type: i0.Input, args: [{ isSignal: true, alias: "politeness", required: false }] }], atomic: [{ type: i0.Input, args: [{ isSignal: true, alias: "atomic", required: false }] }], relevant: [{ type: i0.Input, args: [{ isSignal: true, alias: "relevant", required: false }] }] } });
134
134
 
135
+ // One frame. Clear the region this long before writing so an intentionally
136
+ // repeated identical string still registers as a content change for the SR.
137
+ const CLEAR_DELAY_MS = 16;
135
138
  /**
136
139
  * Imperative, reusable polite/assertive live-region announcer.
137
140
  *
138
141
  * The imperative counterpart to {@link CngxLiveRegion}: where the directive
139
142
  * decorates an element you render (the content IS the announcement), this
140
- * service owns a single visually-hidden `aria-live` element appended to
141
- * `document.body` and exposes an `announce(message)` call for template-less
143
+ * service owns two visually-hidden `aria-live` regions appended to
144
+ * `document.body` - one persistent polite node and one persistent assertive
145
+ * node - and exposes an `announce(message, politeness)` call for template-less
142
146
  * directives and event handlers (e.g. `CngxCopyValue` copy success,
143
147
  * `CngxOtpInput` completion).
144
148
  *
145
- * One root element is created lazily on the first announcement and reused for
146
- * every subsequent call. The text is cleared and re-set on the next macrotask
147
- * so an identical consecutive message is still re-read by the screen reader.
149
+ * Each region is created lazily on the first announcement of its politeness and
150
+ * reused thereafter. Because polite and assertive live in separate fixed-
151
+ * politeness nodes, an assertive announcement never clobbers a concurrent
152
+ * polite one. Per region, the text is cleared and re-set one frame later so an
153
+ * identical consecutive message is still re-read by the screen reader.
148
154
  *
149
155
  * SSR-safe: all DOM access is guarded by `isPlatformBrowser`; on the server
150
- * `announce()` is a no-op and no element is created.
156
+ * `announce()` is a no-op and no region is created.
151
157
  *
152
158
  * ```typescript
153
159
  * const announcer = inject(CngxLiveAnnouncer);
@@ -156,7 +162,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
156
162
  * ```
157
163
  *
158
164
  * @category common/a11y
159
- * @docsKind primary
160
165
  * @wcag AA
161
166
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-announcer.ts
162
167
  * @since 0.1.0
@@ -165,46 +170,58 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
165
170
  class CngxLiveAnnouncer {
166
171
  doc = inject(DOCUMENT);
167
172
  isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
168
- region = null;
169
- pending = null;
173
+ politeRegion = null;
174
+ assertiveRegion = null;
175
+ pending = {
176
+ polite: null,
177
+ assertive: null,
178
+ };
170
179
  /**
171
- * Announces `message` through the shared live region.
180
+ * Announces `message` through the fixed-politeness live region.
172
181
  *
173
182
  * @param message Text read by the screen reader.
174
183
  * @param politeness `'polite'` (default) queues after the current
175
- * utterance; `'assertive'` interrupts immediately.
184
+ * utterance; `'assertive'` interrupts immediately. Each politeness owns its
185
+ * own region, so the two never overwrite each other.
176
186
  */
177
187
  announce(message, politeness = 'polite') {
178
188
  if (!this.isBrowser) {
179
189
  return;
180
190
  }
181
- const region = this.ensureRegion();
182
- region.setAttribute('aria-live', politeness);
183
- // Clear first, then write on the next macrotask so repeating the same
184
- // string still registers as a content change for the SR.
191
+ const region = this.ensureRegion(politeness);
192
+ // Clear first, then write one frame later so repeating the same string
193
+ // still registers as a content change for the SR. Polite and assertive
194
+ // keep independent timers so one politeness never cancels the other.
185
195
  region.textContent = '';
186
- if (this.pending !== null) {
187
- clearTimeout(this.pending);
196
+ const existing = this.pending[politeness];
197
+ if (existing !== null) {
198
+ clearTimeout(existing);
188
199
  }
189
- this.pending = setTimeout(() => {
200
+ this.pending[politeness] = setTimeout(() => {
190
201
  region.textContent = message;
191
- this.pending = null;
192
- });
202
+ this.pending[politeness] = null;
203
+ }, CLEAR_DELAY_MS);
193
204
  }
194
205
  ngOnDestroy() {
195
- if (this.pending !== null) {
196
- clearTimeout(this.pending);
197
- this.pending = null;
206
+ for (const politeness of ['polite', 'assertive']) {
207
+ const timer = this.pending[politeness];
208
+ if (timer !== null) {
209
+ clearTimeout(timer);
210
+ this.pending[politeness] = null;
211
+ }
198
212
  }
199
- this.region?.remove();
200
- this.region = null;
213
+ this.politeRegion?.remove();
214
+ this.assertiveRegion?.remove();
215
+ this.politeRegion = null;
216
+ this.assertiveRegion = null;
201
217
  }
202
- ensureRegion() {
203
- if (this.region) {
204
- return this.region;
218
+ ensureRegion(politeness) {
219
+ const existing = politeness === 'polite' ? this.politeRegion : this.assertiveRegion;
220
+ if (existing) {
221
+ return existing;
205
222
  }
206
223
  const span = this.doc.createElement('span');
207
- span.setAttribute('aria-live', 'polite');
224
+ span.setAttribute('aria-live', politeness);
208
225
  span.setAttribute('aria-atomic', 'true');
209
226
  span.className = 'cngx-sr-only';
210
227
  span.style.position = 'absolute';
@@ -217,7 +234,12 @@ class CngxLiveAnnouncer {
217
234
  span.style.whiteSpace = 'nowrap';
218
235
  span.style.border = '0';
219
236
  this.doc.body.appendChild(span);
220
- this.region = span;
237
+ if (politeness === 'polite') {
238
+ this.politeRegion = span;
239
+ }
240
+ else {
241
+ this.assertiveRegion = span;
242
+ }
221
243
  return span;
222
244
  }
223
245
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
@@ -256,7 +278,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
256
278
  * ```
257
279
  *
258
280
  * @category common/a11y
259
- * @docsKind primary
260
281
  * @wcag AA
261
282
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/autofocus.directive.ts
262
283
  * @since 0.1.0
@@ -305,7 +326,14 @@ class CngxAutofocus {
305
326
  }
306
327
  }
307
328
  applyFocus() {
308
- this.el.nativeElement.focus(this.options());
329
+ const el = this.el.nativeElement;
330
+ // A delayed schedule can outlive its trigger: the condition may have
331
+ // flipped off or the element may have left the DOM. Re-check both so a
332
+ // stale timer cannot steal focus from wherever it moved meanwhile.
333
+ if (!this.when() || !el.isConnected) {
334
+ return;
335
+ }
336
+ el.focus(this.options());
309
337
  }
310
338
  clearPending() {
311
339
  if (this.pendingTimer !== null) {
@@ -349,7 +377,9 @@ const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disa
349
377
  * `document.activeElement` at initialization time and restores it when the
350
378
  * host element is destroyed.
351
379
  *
352
- * Fallback chain: stored element → provided fallback → nearest focusable ancestor → body.
380
+ * Fallback chain: stored element → provided fallback → nearest focusable ancestor.
381
+ * When none resolves, focus is left where the browser put it - `<body>` is
382
+ * deliberately never a restore target.
353
383
  *
354
384
  * ### Panel that restores focus on close
355
385
  * ```html
@@ -370,7 +400,6 @@ const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disa
370
400
  * ```
371
401
  *
372
402
  * @category common/a11y
373
- * @docsKind primary
374
403
  * @wcag AA
375
404
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-restore.directive.ts
376
405
  * @since 0.1.0
@@ -479,6 +508,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
479
508
  * The CDK's imperative `create()` / `destroy()` / `enabled` setter lifecycle
480
509
  * is handled internally via `effect()` and `DestroyRef`.
481
510
  *
511
+ * **Nesting:** traps do not coordinate with each other. When traps nest
512
+ * (dialog over drawer), enable only the innermost one and drive each
513
+ * `enabled` from your layering state - two simultaneously enabled traps
514
+ * fight over Tab. `CngxDialogStack` already does this for stacked dialogs.
515
+ *
482
516
  * ### Modal dialog
483
517
  * ```html
484
518
  * <div cngxFocusTrap [enabled]="isOpen()" [autoFocus]="true"
@@ -511,18 +545,27 @@ class CngxFocusTrap {
511
545
  enabled = input(false, ...(ngDevMode ? [{ debugName: "enabled" }] : /* istanbul ignore next */ []));
512
546
  /** Whether to auto-focus the first tabbable element when the trap activates. */
513
547
  autoFocus = input(true, ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
514
- /** Computed signal reflecting the current trap state. */
548
+ /**
549
+ * Readable alias of `enabled` for `exportAs` consumers
550
+ * (`trap.isActive()` reads better than re-binding the input).
551
+ */
515
552
  isActive = computed(() => this.enabled(), ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
516
553
  trap;
517
554
  constructor() {
518
555
  const el = inject((ElementRef));
519
556
  this.trap = inject(FocusTrapFactory).create(el.nativeElement);
557
+ // Track ONLY enabled: with autoFocus inside the tracked zone, flipping
558
+ // [autoFocus] while the trap is active would re-run the effect and yank
559
+ // focus back to the first tabbable element. The CDK calls are service
560
+ // work, not dependencies.
520
561
  effect(() => {
521
562
  const enabled = this.enabled();
522
- this.trap.enabled = enabled;
523
- if (enabled && this.autoFocus()) {
524
- void this.trap.focusFirstTabbableElementWhenReady();
525
- }
563
+ untracked(() => {
564
+ this.trap.enabled = enabled;
565
+ if (enabled && this.autoFocus()) {
566
+ void this.trap.focusFirstTabbableElementWhenReady();
567
+ }
568
+ });
526
569
  });
527
570
  inject(DestroyRef).onDestroy(() => this.trap.destroy());
528
571
  }
@@ -560,7 +603,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
560
603
  * ```
561
604
  *
562
605
  * @category common/a11y
563
- * @docsKind primary
564
606
  * @wcag AA
565
607
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-visible.directive.ts
566
608
  * @since 0.1.0
@@ -569,11 +611,50 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
569
611
  * <example-url>http://localhost:4200/#/common/a11y/focus-visible/keyboard-vs-pointer</example-url>
570
612
  */
571
613
  class CngxFocusVisible {
614
+ doc = inject(DOCUMENT);
572
615
  focusVisibleState = signal(false, ...(ngDevMode ? [{ debugName: "focusVisibleState" }] : /* istanbul ignore next */ []));
573
616
  /** `true` when focus was initiated via keyboard (not pointer). */
574
617
  focusVisible = this.focusVisibleState.asReadonly();
575
- /** @internal Cleared on `focusin` after being set by `pointerdown`. */
576
618
  pointerActive = false;
619
+ pointerClearTimer = null;
620
+ schedulePointerClear = () => {
621
+ // One macrotask of grace: on touch, the compat mousedown and the focusin
622
+ // fire AFTER pointerup, so a synchronous clear here would misread a tap
623
+ // as keyboard focus. The deferred clear runs after the whole tap
624
+ // sequence settled.
625
+ if (this.pointerClearTimer !== null) {
626
+ clearTimeout(this.pointerClearTimer);
627
+ }
628
+ this.pointerClearTimer = setTimeout(() => {
629
+ this.pointerActive = false;
630
+ this.pointerClearTimer = null;
631
+ }, 0);
632
+ };
633
+ constructor() {
634
+ inject(DestroyRef).onDestroy(() => {
635
+ this.doc.removeEventListener('pointerup', this.schedulePointerClear, true);
636
+ if (this.pointerClearTimer !== null) {
637
+ clearTimeout(this.pointerClearTimer);
638
+ }
639
+ });
640
+ }
641
+ /** @internal Arms the pointer flag for the imminent focusin. */
642
+ handlePointerDown() {
643
+ // A pending clear from the previous release must not fire mid-press.
644
+ if (this.pointerClearTimer !== null) {
645
+ clearTimeout(this.pointerClearTimer);
646
+ this.pointerClearTimer = null;
647
+ }
648
+ this.pointerActive = true;
649
+ // The flag must not outlive the click: a pointerdown that never focuses
650
+ // (disabled child, text selection, drag released off-host) would
651
+ // otherwise suppress the ring on the NEXT keyboard Tab-in. Document-level
652
+ // capture catches the release wherever it lands.
653
+ this.doc.addEventListener('pointerup', this.schedulePointerClear, {
654
+ once: true,
655
+ capture: true,
656
+ });
657
+ }
577
658
  /** @internal Sets focus-visible state; clears pointer flag. */
578
659
  handleFocus() {
579
660
  this.focusVisibleState.set(!this.pointerActive);
@@ -584,7 +665,7 @@ class CngxFocusVisible {
584
665
  this.focusVisibleState.set(false);
585
666
  }
586
667
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusVisible, deps: [], target: i0.ɵɵFactoryTarget.Directive });
587
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxFocusVisible, isStandalone: true, selector: "[cngxFocusVisible]", host: { listeners: { "pointerdown": "pointerActive = true", "focusin": "handleFocus()", "focusout": "handleBlur()" }, properties: { "class.cngx-focus-visible": "focusVisible()" } }, exportAs: ["cngxFocusVisible"], ngImport: i0 });
668
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxFocusVisible, isStandalone: true, selector: "[cngxFocusVisible]", host: { listeners: { "pointerdown": "handlePointerDown()", "focusin": "handleFocus()", "focusout": "handleBlur()" }, properties: { "class.cngx-focus-visible": "focusVisible()" } }, exportAs: ["cngxFocusVisible"], ngImport: i0 });
588
669
  }
589
670
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusVisible, decorators: [{
590
671
  type: Directive,
@@ -593,13 +674,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
593
674
  exportAs: 'cngxFocusVisible',
594
675
  standalone: true,
595
676
  host: {
596
- '(pointerdown)': 'pointerActive = true',
677
+ '(pointerdown)': 'handlePointerDown()',
597
678
  '(focusin)': 'handleFocus()',
598
679
  '(focusout)': 'handleBlur()',
599
680
  '[class.cngx-focus-visible]': 'focusVisible()',
600
681
  },
601
682
  }]
602
- }] });
683
+ }], ctorParameters: () => [] });
603
684
 
604
685
  /**
605
686
  * Marker directive for items managed by `CngxRovingTabindex`.
@@ -617,7 +698,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
617
698
  * ```
618
699
  *
619
700
  * @category common/a11y
620
- * @docsKind primary
621
701
  * @wcag AA
622
702
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/roving/roving-tabindex.directive.ts
623
703
  * @since 0.1.0
@@ -727,6 +807,8 @@ class CngxRovingTabindex {
727
807
  /** Host element for `data-cngx-recycle-index` queries in virtual mode. */
728
808
  hostEl = inject((ElementRef));
729
809
  pendingFocusState = signal(null, ...(ngDevMode ? [{ debugName: "pendingFocusState" }] : /* istanbul ignore next */ []));
810
+ /** Document writing direction - flips the horizontal-arrow index deltas under `rtl` (APG). */
811
+ direction = injectDirection();
730
812
  /**
731
813
  * Set true just before a navigation key (arrow / Home / End) moves focus to a
732
814
  * new item, cleared by {@link consumeNavigationKey}. Transient handshake, not
@@ -750,17 +832,38 @@ class CngxRovingTabindex {
750
832
  const active = this.activeIndex();
751
833
  const vc = this.virtualCount();
752
834
  if (vc != null) {
753
- // Virtual mode: match by data-cngx-recycle-index attribute
835
+ // Virtual mode: match by data-cngx-recycle-index attribute. Clamp the
836
+ // model itself when the virtual space shrinks below it - a ghost
837
+ // index would otherwise anchor the next arrow press. An empty space
838
+ // (vc 0) keeps the model untouched so a repopulated list restores it.
839
+ const clamped = vc > 0 ? Math.max(0, Math.min(active, vc - 1)) : active;
840
+ if (clamped !== active) {
841
+ untracked(() => this.activeIndex.set(clamped));
842
+ }
754
843
  items.forEach((item) => {
755
844
  const el = item.elementRef.nativeElement;
756
845
  const idx = el.dataset['cngxRecycleIndex'];
757
- el.setAttribute('tabindex', idx != null && Number(idx) === active ? '0' : '-1');
846
+ el.setAttribute('tabindex', idx != null && Number(idx) === clamped ? '0' : '-1');
758
847
  });
759
848
  }
760
849
  else {
761
- // Standard mode: match by array index
762
- const clamped = Math.max(0, Math.min(active, items.length - 1));
763
- items.forEach((item, i) => item.elementRef.nativeElement.setAttribute('tabindex', i === clamped ? '0' : '-1'));
850
+ // Standard mode: match by array index. The tab stop must land on an
851
+ // enabled item - fall back to the first enabled one when the clamped
852
+ // target is disabled (initial index into a disabled leaf, or the
853
+ // active item got disabled). The model is written back so keyboard
854
+ // navigation anchors where the tab stop actually sits. An empty list
855
+ // keeps the model untouched so a repopulated list restores it.
856
+ if (items.length === 0) {
857
+ return;
858
+ }
859
+ let target = Math.max(0, Math.min(active, items.length - 1));
860
+ if (items[target]?.disabled()) {
861
+ target = this.findFirst(items) ?? target;
862
+ }
863
+ if (target !== active) {
864
+ untracked(() => this.activeIndex.set(target));
865
+ }
866
+ items.forEach((item, i) => item.elementRef.nativeElement.setAttribute('tabindex', i === target ? '0' : '-1'));
764
867
  }
765
868
  });
766
869
  }
@@ -792,6 +895,11 @@ class CngxRovingTabindex {
792
895
  * based on whether `virtualCount` is set.
793
896
  */
794
897
  handleKeyDown(event) {
898
+ // Never hijack browser/app shortcuts: Ctrl/Cmd/Alt combos pass through
899
+ // untouched (Ctrl+Home, Cmd+ArrowLeft and friends belong to the app).
900
+ if (event.ctrlKey || event.metaKey || event.altKey) {
901
+ return;
902
+ }
795
903
  const vc = this.virtualCount();
796
904
  const allItems = this.items();
797
905
  const isVirtual = vc != null;
@@ -806,9 +914,16 @@ class CngxRovingTabindex {
806
914
  const navigate = (direction) => isVirtual
807
915
  ? this.findNextVirtual(currentActive, total, direction)
808
916
  : this.findNext(currentActive, allItems, direction);
917
+ const inlineNav = (key) => {
918
+ if (!this.isHorizontal()) {
919
+ return null;
920
+ }
921
+ const step = resolveInlineStep(key, this.direction());
922
+ return step === null ? null : navigate(step);
923
+ };
809
924
  const keyMap = {
810
- ArrowRight: () => (this.isHorizontal() ? navigate(1) : null),
811
- ArrowLeft: () => (this.isHorizontal() ? navigate(-1) : null),
925
+ ArrowRight: () => inlineNav('ArrowRight'),
926
+ ArrowLeft: () => inlineNav('ArrowLeft'),
812
927
  ArrowDown: () => (this.isVertical() ? navigate(1) : null),
813
928
  ArrowUp: () => (this.isVertical() ? navigate(-1) : null),
814
929
  Home: () => (isVirtual ? 0 : this.findFirst(allItems)),
@@ -837,6 +952,34 @@ class CngxRovingTabindex {
837
952
  event.preventDefault();
838
953
  }
839
954
  }
955
+ /**
956
+ * Keeps `activeIndex` in sync with real focus (APG): when an item gains
957
+ * focus by any means - pointer click, script focus, assistive tech - the
958
+ * tab stop follows it instead of staying on the last arrow-key target.
959
+ */
960
+ handleFocusIn(event) {
961
+ const target = event.target;
962
+ if (target === null) {
963
+ return;
964
+ }
965
+ const vc = this.virtualCount();
966
+ if (vc != null) {
967
+ const holder = target.closest('[data-cngx-recycle-index]');
968
+ const idx = holder === null ? NaN : Number(holder.getAttribute('data-cngx-recycle-index'));
969
+ if (Number.isInteger(idx) && idx >= 0 && idx < vc && idx !== this.activeIndex()) {
970
+ this.activeIndex.set(idx);
971
+ }
972
+ return;
973
+ }
974
+ const items = this.items();
975
+ const idx = items.findIndex((item) => {
976
+ const el = item.elementRef.nativeElement;
977
+ return el === target || el.contains(target);
978
+ });
979
+ if (idx >= 0 && !items[idx].disabled() && idx !== this.activeIndex()) {
980
+ this.activeIndex.set(idx);
981
+ }
982
+ }
840
983
  /**
841
984
  * Attempts to focus a virtual item by querying `data-cngx-recycle-index`.
842
985
  * If the element is not in the DOM, sets `pendingFocus` for external resolution.
@@ -853,20 +996,11 @@ class CngxRovingTabindex {
853
996
  }
854
997
  /**
855
998
  * Finds the next index in virtual mode. No disabled-item skipping - can't check
856
- * disabled state of items not in the DOM.
999
+ * disabled state of items not in the DOM (the resolver treats every index as
1000
+ * enabled when no `isDisabledAt` is supplied).
857
1001
  */
858
1002
  findNextVirtual(current, total, direction) {
859
- if (total === 0) {
860
- return null;
861
- }
862
- const idx = current + direction;
863
- if (this.loop()) {
864
- return ((idx % total) + total) % total;
865
- }
866
- if (idx < 0 || idx >= total) {
867
- return null;
868
- }
869
- return idx;
1003
+ return resolveStepFrom(current, direction, { count: total, loop: this.loop() });
870
1004
  }
871
1005
  enabledItems() {
872
1006
  return this.items().filter((item) => !item.disabled());
@@ -885,40 +1019,26 @@ class CngxRovingTabindex {
885
1019
  * Skips disabled items.
886
1020
  */
887
1021
  findNext(current, items, direction) {
888
- const len = items.length;
889
- if (len === 0) {
890
- return null;
891
- }
892
- let idx = current + direction;
893
- const loop = this.loop();
894
- for (let i = 0; i < len; i++) {
895
- if (loop) {
896
- idx = ((idx % len) + len) % len;
897
- }
898
- else if (idx < 0 || idx >= len) {
899
- return null;
900
- }
901
- if (!items[idx].disabled()) {
902
- return idx;
903
- }
904
- idx += direction;
905
- }
906
- return null;
1022
+ return resolveStepFrom(current, direction, {
1023
+ count: items.length,
1024
+ loop: this.loop(),
1025
+ isDisabledAt: (i) => items[i].disabled(),
1026
+ });
907
1027
  }
908
1028
  findFirst(items) {
909
- const idx = items.findIndex((item) => !item.disabled());
910
- return idx >= 0 ? idx : null;
1029
+ return resolveBoundaryStep(1, {
1030
+ count: items.length,
1031
+ isDisabledAt: (i) => items[i].disabled(),
1032
+ });
911
1033
  }
912
1034
  findLast(items) {
913
- for (let i = items.length - 1; i >= 0; i--) {
914
- if (!items[i].disabled()) {
915
- return i;
916
- }
917
- }
918
- return null;
1035
+ return resolveBoundaryStep(-1, {
1036
+ count: items.length,
1037
+ isDisabledAt: (i) => items[i].disabled(),
1038
+ });
919
1039
  }
920
1040
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRovingTabindex, deps: [], target: i0.ɵɵFactoryTarget.Directive });
921
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxRovingTabindex, isStandalone: true, selector: "[cngxRovingTabindex]", inputs: { orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { orientation: "orientationChange", activeIndex: "activeIndexChange" }, host: { listeners: { "keydown": "handleKeyDown($event)" } }, queries: [{ propertyName: "items", predicate: CngxRovingItem, isSignal: true }], exportAs: ["cngxRovingTabindex"], ngImport: i0 });
1041
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxRovingTabindex, isStandalone: true, selector: "[cngxRovingTabindex]", inputs: { orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { orientation: "orientationChange", activeIndex: "activeIndexChange" }, host: { listeners: { "keydown": "handleKeyDown($event)", "focusin": "handleFocusIn($event)" } }, queries: [{ propertyName: "items", predicate: CngxRovingItem, isSignal: true }], exportAs: ["cngxRovingTabindex"], ngImport: i0 });
922
1042
  }
923
1043
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRovingTabindex, decorators: [{
924
1044
  type: Directive,
@@ -928,6 +1048,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
928
1048
  standalone: true,
929
1049
  host: {
930
1050
  '(keydown)': 'handleKeyDown($event)',
1051
+ '(focusin)': 'handleFocusIn($event)',
931
1052
  },
932
1053
  }]
933
1054
  }], ctorParameters: () => [], propDecorators: { orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }, { type: i0.Output, args: ["orientationChange"] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], items: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CngxRovingItem), { isSignal: true }] }] } });
@@ -973,9 +1094,13 @@ const CNGX_AD_ITEM = new InjectionToken('CNGX_AD_ITEM');
973
1094
  *
974
1095
  * ### Virtualization
975
1096
  *
976
- * When `virtualCount` is set, navigation can address indices not currently
977
- * in the DOM. `pendingHighlight` tells the consumer to scroll the missing
978
- * item into view; the consumer calls `clearPendingHighlight()` afterwards.
1097
+ * When `virtualCount` is set, navigation addresses the absolute index space
1098
+ * `[0, virtualCount)` even when only a window is rendered. Bind `windowStart`
1099
+ * to the recycler's window start so item lookups (id resolution, disabled
1100
+ * checks, typeahead labels) map absolute indices onto the rendered subset.
1101
+ * Targets outside the window surface as `pendingHighlight`; the consumer
1102
+ * scrolls them into view (`connectRecyclerToActiveDescendant`) and the
1103
+ * directive clears the pending state once the target renders.
979
1104
  *
980
1105
  * ### Material/CDK equivalent
981
1106
  *
@@ -1018,12 +1143,31 @@ class CngxActiveDescendant {
1018
1143
  * range surface as `pendingHighlight` for scroll-and-retry protocols.
1019
1144
  */
1020
1145
  virtualCount = input(undefined, ...(ngDevMode ? [{ debugName: "virtualCount" }] : /* istanbul ignore next */ []));
1146
+ /**
1147
+ * Absolute index of the first rendered item in virtual mode - the recycler
1148
+ * window start. All rendered-item lookups are offset by it so absolute
1149
+ * indices resolve the right item once the window has scrolled past 0.
1150
+ * Ignored when `virtualCount` is unset.
1151
+ */
1152
+ windowStart = input(0, ...(ngDevMode ? [{ debugName: "windowStart" }] : /* istanbul ignore next */ []));
1021
1153
  /** Emitted when `activateCurrent()` is called with an active item. */
1022
1154
  activated = output();
1023
1155
  /** Emitted whenever the highlighted item changes. */
1024
1156
  highlighted = output();
1157
+ /**
1158
+ * Emitted when a typeahead query finds no match in the rendered window.
1159
+ * Carries the resolved query term (lowercased; a repeated single letter
1160
+ * collapses to that letter per the APG cycle rule). The rendered window
1161
+ * is AD's whole search space - hosts whose real item space is larger
1162
+ * (collapsed tree branches, virtualized rows outside the window) listen
1163
+ * here to resolve the miss themselves.
1164
+ */
1165
+ typeaheadMissed = output();
1025
1166
  hostEl = inject((ElementRef));
1167
+ locale = injectLocale();
1026
1168
  registered = contentChildren(CNGX_AD_ITEM, { ...(ngDevMode ? { debugName: "registered" } : /* istanbul ignore next */ {}), descendants: true });
1169
+ /** Document writing direction - flips the horizontal-arrow steps under `rtl` (APG). */
1170
+ direction = injectDirection();
1027
1171
  /** Guards host attribute writes until after first render. */
1028
1172
  initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
1029
1173
  /** -1 means "no active item". Range is [0, resolvedItems().length). */
@@ -1060,9 +1204,15 @@ class CngxActiveDescendant {
1060
1204
  if (idx < 0) {
1061
1205
  return null;
1062
1206
  }
1063
- const list = this.resolvedItems();
1064
- return list[idx] ?? null;
1207
+ return this.itemAt(idx);
1065
1208
  }, ...(ngDevMode ? [{ debugName: "activeItem" }] : /* istanbul ignore next */ []));
1209
+ /**
1210
+ * `activeItem` pinned to the item id for the `highlighted` emission: a
1211
+ * re-render that produces a fresh object for the same item must not
1212
+ * re-emit. `activeItem` itself stays identity-equal so `activeValue`
1213
+ * tracks value changes on an unchanged id.
1214
+ */
1215
+ highlightedItem = computed(() => this.activeItem(), { ...(ngDevMode ? { debugName: "highlightedItem" } : /* istanbul ignore next */ {}), equal: (a, b) => a === b || (a !== null && b !== null && a.id === b.id) });
1066
1216
  activeId = computed(() => this.activeItem()?.id ?? null, ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
1067
1217
  activeValue = computed(() => this.activeItem()?.value ?? null, ...(ngDevMode ? [{ debugName: "activeValue" }] : /* istanbul ignore next */ []));
1068
1218
  typeaheadBuffer = signal('', ...(ngDevMode ? [{ debugName: "typeaheadBuffer" }] : /* istanbul ignore next */ []));
@@ -1077,8 +1227,16 @@ class CngxActiveDescendant {
1077
1227
  this.highlightFirst();
1078
1228
  }
1079
1229
  });
1230
+ // Leading nulls are start-up state, not a highlight change - emit only
1231
+ // once something was highlighted (later resets back to null still emit).
1232
+ let hadHighlight = false;
1080
1233
  effect(() => {
1081
- this.highlighted.emit(this.activeItem());
1234
+ const item = this.highlightedItem();
1235
+ if (!hadHighlight && item === null) {
1236
+ return;
1237
+ }
1238
+ hadHighlight = true;
1239
+ this.highlighted.emit(item);
1082
1240
  });
1083
1241
  effect(() => {
1084
1242
  const idx = this.activeIndex();
@@ -1094,6 +1252,16 @@ class CngxActiveDescendant {
1094
1252
  }
1095
1253
  queueMicrotask(() => this.scrollActiveIntoView());
1096
1254
  });
1255
+ // Clamp the active STATE, not just the derived display, when the item
1256
+ // space shrinks below it - otherwise the next arrow press navigates
1257
+ // relative to a ghost index.
1258
+ effect(() => {
1259
+ const total = this.totalCount();
1260
+ const idx = this.activeIndexState();
1261
+ if (idx >= total) {
1262
+ untracked(() => this.activeIndexState.set(total > 0 ? total - 1 : -1));
1263
+ }
1264
+ });
1097
1265
  inject(DestroyRef).onDestroy(() => {
1098
1266
  if (this.typeaheadTimer !== null) {
1099
1267
  clearTimeout(this.typeaheadTimer);
@@ -1139,8 +1307,10 @@ class CngxActiveDescendant {
1139
1307
  this.activeIndexState.set(index);
1140
1308
  }
1141
1309
  /**
1142
- * Highlight the first item whose value matches (via `Object.is`). No-op if
1143
- * no match. Disabled items are rejected when `skipDisabled()` is true.
1310
+ * Highlight the first rendered item whose value matches (via `Object.is`).
1311
+ * No-op if no match. Disabled items are rejected when `skipDisabled()` is
1312
+ * true. In virtual mode only the rendered window is searched; the resolved
1313
+ * index is absolute.
1144
1314
  */
1145
1315
  highlightByValue(value) {
1146
1316
  const items = this.resolvedItems();
@@ -1151,7 +1321,7 @@ class CngxActiveDescendant {
1151
1321
  if (this.skipDisabled() && items[idx].disabled) {
1152
1322
  return;
1153
1323
  }
1154
- this.activeIndexState.set(idx);
1324
+ this.activeIndexState.set(idx + this.windowOffset());
1155
1325
  }
1156
1326
  /** Clear the highlight. */
1157
1327
  resetHighlight() {
@@ -1169,6 +1339,12 @@ class CngxActiveDescendant {
1169
1339
  this.pendingHighlightState.set(null);
1170
1340
  }
1171
1341
  handleKeydown(event) {
1342
+ // Never hijack browser/app shortcuts: Ctrl/Cmd/Alt combos pass through
1343
+ // untouched (Ctrl+C would otherwise hit the typeahead branch and get
1344
+ // preventDefault'd). Shift stays allowed - it produces printable chars.
1345
+ if (event.ctrlKey || event.metaKey || event.altKey) {
1346
+ return;
1347
+ }
1172
1348
  // Skip events from editable descendants. Without this, every
1173
1349
  // printable key typed into a descendant <input> hits AD's typeahead
1174
1350
  // branch, gets preventDefault'd, and never reaches the input.
@@ -1218,18 +1394,23 @@ class CngxActiveDescendant {
1218
1394
  this.highlightNext();
1219
1395
  }
1220
1396
  return;
1221
- case 'ArrowUp':
1222
- if (orientation === 'vertical') {
1223
- this.highlightPrev();
1224
- }
1225
- return;
1226
1397
  case 'ArrowRight':
1227
- if (orientation === 'horizontal') {
1398
+ case 'ArrowLeft': {
1399
+ if (orientation !== 'horizontal') {
1400
+ return;
1401
+ }
1402
+ // RTL flips the horizontal arrows (same kernel roving uses).
1403
+ const step = resolveInlineStep(key, this.direction());
1404
+ if (step === 1) {
1228
1405
  this.highlightNext();
1229
1406
  }
1407
+ else if (step === -1) {
1408
+ this.highlightPrev();
1409
+ }
1230
1410
  return;
1231
- case 'ArrowLeft':
1232
- if (orientation === 'horizontal') {
1411
+ }
1412
+ case 'ArrowUp':
1413
+ if (orientation === 'vertical') {
1233
1414
  this.highlightPrev();
1234
1415
  }
1235
1416
  return;
@@ -1257,7 +1438,8 @@ class CngxActiveDescendant {
1257
1438
  this.handleTypeahead(ch);
1258
1439
  }
1259
1440
  handleTypeahead(ch) {
1260
- const next = this.typeaheadBuffer() + ch.toLowerCase();
1441
+ const locale = this.locale();
1442
+ const next = this.typeaheadBuffer() + ch.toLocaleLowerCase(locale);
1261
1443
  this.typeaheadBuffer.set(next);
1262
1444
  if (this.typeaheadTimer !== null) {
1263
1445
  clearTimeout(this.typeaheadTimer);
@@ -1266,67 +1448,57 @@ class CngxActiveDescendant {
1266
1448
  this.typeaheadBuffer.set('');
1267
1449
  this.typeaheadTimer = null;
1268
1450
  }, this.typeaheadDebounce());
1451
+ // Labels exist only for rendered items, so the search space is the
1452
+ // rendered window; matches map back to absolute indices in virtual mode.
1269
1453
  const items = this.resolvedItems();
1270
1454
  const skip = this.skipDisabled();
1271
- const start = Math.max(0, this.activeIndexState());
1272
- const total = items.length;
1273
- for (let offset = 0; offset < total; offset++) {
1274
- const i = (start + offset) % total;
1275
- const candidate = items[i];
1455
+ const count = items.length;
1456
+ // APG cycle: a single-character query (including a repeated letter, whose
1457
+ // buffer collapses back to that letter) searches AFTER the active item so
1458
+ // each press advances through the matches. A genuine multi-character query
1459
+ // keeps matching the current item first.
1460
+ const sameChar = next.length > 1 && [...next].every((c) => c === next[0]);
1461
+ const term = sameChar ? next[0] : next;
1462
+ if (count === 0) {
1463
+ this.typeaheadMissed.emit(term);
1464
+ return;
1465
+ }
1466
+ const windowOffset = this.windowOffset();
1467
+ const activeRel = this.activeIndexState() < 0 ? -1 : this.activeIndexState() - windowOffset;
1468
+ const cycles = term.length === 1;
1469
+ const startRel = cycles ? activeRel + 1 : Math.max(0, activeRel);
1470
+ const matches = createTypeaheadMatcher(term, locale);
1471
+ for (let step = 0; step < count; step++) {
1472
+ const rel = (((startRel + step) % count) + count) % count;
1473
+ const candidate = items[rel];
1276
1474
  if (skip && candidate.disabled) {
1277
1475
  continue;
1278
1476
  }
1279
- if (candidate.label.toLowerCase().startsWith(next)) {
1280
- this.activeIndexState.set(i);
1477
+ if (matches(candidate.label, candidate)) {
1478
+ this.activeIndexState.set(rel + windowOffset);
1281
1479
  return;
1282
1480
  }
1283
1481
  }
1482
+ this.typeaheadMissed.emit(term);
1284
1483
  }
1285
1484
  findFrom(current, direction) {
1286
- const total = this.totalCount();
1287
- if (total === 0) {
1288
- return null;
1289
- }
1290
- const items = this.resolvedItems();
1291
- const skip = this.skipDisabled();
1292
- const loop = this.loop();
1293
- let idx = current < 0 ? (direction === 1 ? -1 : total) : current;
1294
- for (let step = 0; step < total; step++) {
1295
- idx += direction;
1296
- if (idx < 0 || idx >= total) {
1297
- if (!loop) {
1298
- return null;
1299
- }
1300
- idx = ((idx % total) + total) % total;
1301
- }
1302
- if (!skip || !items[idx]?.disabled) {
1303
- return idx;
1304
- }
1305
- }
1306
- return null;
1485
+ return resolveStepFrom(current, direction, {
1486
+ count: this.totalCount(),
1487
+ loop: this.loop(),
1488
+ isDisabledAt: this.skipDisabled() ? (i) => this.isDisabledAt(i) : undefined,
1489
+ });
1307
1490
  }
1491
+ /**
1492
+ * First/last navigable absolute index. Spans the full virtual range - End
1493
+ * targets `totalCount - 1` even when that item is not rendered (it surfaces
1494
+ * as `pendingHighlight`); unrendered items count as enabled because their
1495
+ * disabled state is unknowable (`isDisabledAt` resolves them to `false`).
1496
+ */
1308
1497
  findBoundary(direction) {
1309
- const items = this.resolvedItems();
1310
- const total = items.length;
1311
- if (total === 0) {
1312
- return null;
1313
- }
1314
- const skip = this.skipDisabled();
1315
- if (direction === 1) {
1316
- for (let i = 0; i < total; i++) {
1317
- if (!skip || !items[i].disabled) {
1318
- return i;
1319
- }
1320
- }
1321
- }
1322
- else {
1323
- for (let i = total - 1; i >= 0; i--) {
1324
- if (!skip || !items[i].disabled) {
1325
- return i;
1326
- }
1327
- }
1328
- }
1329
- return null;
1498
+ return resolveBoundaryStep(direction, {
1499
+ count: this.totalCount(),
1500
+ isDisabledAt: this.skipDisabled() ? (i) => this.isDisabledAt(i) : undefined,
1501
+ });
1330
1502
  }
1331
1503
  totalCount() {
1332
1504
  const vc = this.virtualCount();
@@ -1335,26 +1507,40 @@ class CngxActiveDescendant {
1335
1507
  }
1336
1508
  return this.resolvedItems().length;
1337
1509
  }
1338
- isDisabledAt(index) {
1510
+ /** Rendered-window offset: `windowStart` in virtual mode, `0` otherwise. */
1511
+ windowOffset() {
1512
+ return this.virtualCount() != null ? this.windowStart() : 0;
1513
+ }
1514
+ /** Item at an absolute index, `null` when outside the rendered window. */
1515
+ itemAt(index) {
1516
+ const rel = index - this.windowOffset();
1339
1517
  const items = this.resolvedItems();
1340
- return !!items[index]?.disabled;
1518
+ if (rel < 0 || rel >= items.length) {
1519
+ return null;
1520
+ }
1521
+ return items[rel] ?? null;
1522
+ }
1523
+ isDisabledAt(index) {
1524
+ return !!this.itemAt(index)?.disabled;
1341
1525
  }
1342
1526
  isRendered(index) {
1343
- const items = this.resolvedItems();
1344
- return index >= 0 && index < items.length && !!items[index];
1527
+ return this.itemAt(index) !== null;
1345
1528
  }
1346
1529
  scrollActiveIntoView() {
1347
1530
  const id = this.activeId();
1348
1531
  if (!id) {
1349
1532
  return;
1350
1533
  }
1351
- const el = this.hostEl.nativeElement.querySelector(`#${cssEscape(id)}`);
1534
+ // Document-wide by escaped id: aria-owns layouts render the option list
1535
+ // outside the host subtree, a host-scoped query never finds those.
1536
+ const doc = this.hostEl.nativeElement.ownerDocument;
1537
+ const el = doc.querySelector(`#${cssEscape(id)}`);
1352
1538
  if (el instanceof HTMLElement && typeof el.scrollIntoView === 'function') {
1353
1539
  el.scrollIntoView({ block: 'nearest', inline: 'nearest' });
1354
1540
  }
1355
1541
  }
1356
1542
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1357
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxActiveDescendant, isStandalone: true, selector: "[cngxActiveDescendant]", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, typeahead: { classPropertyName: "typeahead", publicName: "typeahead", isSignal: true, isRequired: false, transformFunction: null }, typeaheadDebounce: { classPropertyName: "typeaheadDebounce", publicName: "typeaheadDebounce", isSignal: true, isRequired: false, transformFunction: null }, autoHighlightFirst: { classPropertyName: "autoHighlightFirst", publicName: "autoHighlightFirst", isSignal: true, isRequired: false, transformFunction: null }, skipDisabled: { classPropertyName: "skipDisabled", publicName: "skipDisabled", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activated: "activated", highlighted: "highlighted" }, host: { listeners: { "keydown": "handleKeydown($event)" }, properties: { "attr.aria-activedescendant": "activeId()" } }, queries: [{ propertyName: "registered", predicate: CNGX_AD_ITEM, descendants: true, isSignal: true }], exportAs: ["cngxActiveDescendant"], ngImport: i0 });
1543
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxActiveDescendant, isStandalone: true, selector: "[cngxActiveDescendant]", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, typeahead: { classPropertyName: "typeahead", publicName: "typeahead", isSignal: true, isRequired: false, transformFunction: null }, typeaheadDebounce: { classPropertyName: "typeaheadDebounce", publicName: "typeaheadDebounce", isSignal: true, isRequired: false, transformFunction: null }, autoHighlightFirst: { classPropertyName: "autoHighlightFirst", publicName: "autoHighlightFirst", isSignal: true, isRequired: false, transformFunction: null }, skipDisabled: { classPropertyName: "skipDisabled", publicName: "skipDisabled", isSignal: true, isRequired: false, transformFunction: null }, virtualCount: { classPropertyName: "virtualCount", publicName: "virtualCount", isSignal: true, isRequired: false, transformFunction: null }, windowStart: { classPropertyName: "windowStart", publicName: "windowStart", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activated: "activated", highlighted: "highlighted", typeaheadMissed: "typeaheadMissed" }, host: { listeners: { "keydown": "handleKeydown($event)" }, properties: { "attr.aria-activedescendant": "activeId()" } }, queries: [{ propertyName: "registered", predicate: CNGX_AD_ITEM, descendants: true, isSignal: true }], exportAs: ["cngxActiveDescendant"], ngImport: i0 });
1358
1544
  }
1359
1545
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, decorators: [{
1360
1546
  type: Directive,
@@ -1367,7 +1553,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1367
1553
  '(keydown)': 'handleKeydown($event)',
1368
1554
  },
1369
1555
  }]
1370
- }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], typeahead: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeahead", required: false }] }], typeaheadDebounce: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeaheadDebounce", required: false }] }], autoHighlightFirst: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHighlightFirst", required: false }] }], skipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "skipDisabled", required: false }] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], activated: [{ type: i0.Output, args: ["activated"] }], highlighted: [{ type: i0.Output, args: ["highlighted"] }], registered: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_AD_ITEM), { ...{ descendants: true }, isSignal: true }] }] } });
1556
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], typeahead: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeahead", required: false }] }], typeaheadDebounce: [{ type: i0.Input, args: [{ isSignal: true, alias: "typeaheadDebounce", required: false }] }], autoHighlightFirst: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoHighlightFirst", required: false }] }], skipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "skipDisabled", required: false }] }], virtualCount: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualCount", required: false }] }], windowStart: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowStart", required: false }] }], activated: [{ type: i0.Output, args: ["activated"] }], highlighted: [{ type: i0.Output, args: ["highlighted"] }], typeaheadMissed: [{ type: i0.Output, args: ["typeaheadMissed"] }], registered: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_AD_ITEM), { ...{ descendants: true }, isSignal: true }] }] } });
1371
1557
  /** @internal */
1372
1558
  function handleToItem(handle) {
1373
1559
  return {
@@ -1446,7 +1632,6 @@ function cssEscape(id) {
1446
1632
  * ```
1447
1633
  *
1448
1634
  * @category common/a11y
1449
- * @docsKind primary
1450
1635
  * @wcag AA
1451
1636
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/motion/reduced-motion.directive.ts
1452
1637
  * @since 0.1.0
@@ -1457,16 +1642,7 @@ class CngxReducedMotion {
1457
1642
  /** `true` when the user's OS is set to prefer reduced motion. Updates reactively. */
1458
1643
  prefersReducedMotion;
1459
1644
  constructor() {
1460
- const win = inject(DOCUMENT).defaultView;
1461
- const pref = signal(false, ...(ngDevMode ? [{ debugName: "pref" }] : /* istanbul ignore next */ []));
1462
- if (win) {
1463
- const mq = win.matchMedia('(prefers-reduced-motion: reduce)');
1464
- pref.set(mq.matches);
1465
- const listener = (e) => pref.set(e.matches);
1466
- mq.addEventListener('change', listener);
1467
- inject(DestroyRef).onDestroy(() => mq.removeEventListener('change', listener));
1468
- }
1469
- this.prefersReducedMotion = pref.asReadonly();
1645
+ this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
1470
1646
  }
1471
1647
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxReducedMotion, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1472
1648
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxReducedMotion, isStandalone: true, selector: "[cngxReducedMotion]", host: { properties: { "class.cngx-reduced-motion": "prefersReducedMotion()" } }, exportAs: ["cngxReducedMotion"], ngImport: i0 });