@cngx/common 0.1.0-rc.5 → 0.1.0-rc.7

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 (63) hide show
  1. package/chart/README.md +85 -0
  2. package/command/README.md +157 -0
  3. package/data/README.md +23 -0
  4. package/fesm2022/cngx-common-a11y.mjs +247 -85
  5. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  6. package/fesm2022/cngx-common-audio.mjs +37 -37
  7. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  8. package/fesm2022/cngx-common-card.mjs +13 -9
  9. package/fesm2022/cngx-common-card.mjs.map +1 -1
  10. package/fesm2022/cngx-common-chart.mjs +3404 -1392
  11. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  12. package/fesm2022/cngx-common-command.mjs +144 -0
  13. package/fesm2022/cngx-common-command.mjs.map +1 -0
  14. package/fesm2022/cngx-common-data.mjs +304 -213
  15. package/fesm2022/cngx-common-data.mjs.map +1 -1
  16. package/fesm2022/cngx-common-dialog.mjs +369 -100
  17. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  18. package/fesm2022/cngx-common-display.mjs +144 -30
  19. package/fesm2022/cngx-common-display.mjs.map +1 -1
  20. package/fesm2022/cngx-common-interactive.mjs +1089 -459
  21. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  22. package/fesm2022/cngx-common-layout.mjs +113 -61
  23. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  24. package/fesm2022/cngx-common-popover.mjs +430 -54
  25. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  26. package/fesm2022/cngx-common-stepper.mjs +107 -49
  27. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  28. package/fesm2022/cngx-common-tabs.mjs +1170 -752
  29. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  30. package/fesm2022/cngx-common-timeline.mjs +1086 -0
  31. package/fesm2022/cngx-common-timeline.mjs.map +1 -0
  32. package/fesm2022/cngx-common.mjs +2 -2
  33. package/fesm2022/cngx-common.mjs.map +1 -1
  34. package/package.json +11 -1
  35. package/stepper/README.md +1 -1
  36. package/theming/components/cngx-accordion.css +20 -6
  37. package/theming/components/cngx-badge.css +22 -0
  38. package/theming/components/cngx-bottom-sheet.css +14 -2
  39. package/theming/components/cngx-breadcrumb.css +9 -1
  40. package/theming/components/cngx-button-toggle.css +44 -2
  41. package/theming/components/cngx-data-grid.css +69 -4
  42. package/theming/components/cngx-dialog.css +12 -0
  43. package/theming/components/cngx-divider.css +12 -0
  44. package/theming/components/cngx-listbox.css +27 -0
  45. package/theming/components/cngx-menu.css +36 -0
  46. package/theming/components/cngx-ripple.css +1 -1
  47. package/theming/components/cngx-slider.css +1 -1
  48. package/theming/components/cngx-tooltip.css +11 -0
  49. package/types/cngx-common-a11y.d.ts +63 -17
  50. package/types/cngx-common-audio.d.ts +32 -32
  51. package/types/cngx-common-card.d.ts +10 -3
  52. package/types/cngx-common-chart.d.ts +1281 -141
  53. package/types/cngx-common-command.d.ts +167 -0
  54. package/types/cngx-common-data.d.ts +264 -98
  55. package/types/cngx-common-dialog.d.ts +214 -25
  56. package/types/cngx-common-display.d.ts +83 -13
  57. package/types/cngx-common-interactive.d.ts +708 -174
  58. package/types/cngx-common-layout.d.ts +48 -1
  59. package/types/cngx-common-popover.d.ts +120 -3
  60. package/types/cngx-common-stepper.d.ts +55 -5
  61. package/types/cngx-common-tabs.d.ts +386 -25
  62. package/types/cngx-common-timeline.d.ts +1059 -0
  63. 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, model, contentChildren, untracked, 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 } from '@cngx/core';
6
+ import { createMediaQuerySignal } from '@cngx/core/utils';
5
7
 
6
8
  /**
7
9
  * Manages `aria-expanded` and optionally `aria-controls` on the host element.
@@ -132,22 +134,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
132
134
  }]
133
135
  }], 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
136
 
137
+ // One frame. Clear the region this long before writing so an intentionally
138
+ // repeated identical string still registers as a content change for the SR.
139
+ const CLEAR_DELAY_MS = 16;
135
140
  /**
136
141
  * Imperative, reusable polite/assertive live-region announcer.
137
142
  *
138
143
  * The imperative counterpart to {@link CngxLiveRegion}: where the directive
139
144
  * 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
145
+ * service owns two visually-hidden `aria-live` regions appended to
146
+ * `document.body` - one persistent polite node and one persistent assertive
147
+ * node - and exposes an `announce(message, politeness)` call for template-less
142
148
  * directives and event handlers (e.g. `CngxCopyValue` copy success,
143
149
  * `CngxOtpInput` completion).
144
150
  *
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.
151
+ * Each region is created lazily on the first announcement of its politeness and
152
+ * reused thereafter. Because polite and assertive live in separate fixed-
153
+ * politeness nodes, an assertive announcement never clobbers a concurrent
154
+ * polite one. Per region, the text is cleared and re-set one frame later so an
155
+ * identical consecutive message is still re-read by the screen reader.
148
156
  *
149
157
  * SSR-safe: all DOM access is guarded by `isPlatformBrowser`; on the server
150
- * `announce()` is a no-op and no element is created.
158
+ * `announce()` is a no-op and no region is created.
151
159
  *
152
160
  * ```typescript
153
161
  * const announcer = inject(CngxLiveAnnouncer);
@@ -165,46 +173,58 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
165
173
  class CngxLiveAnnouncer {
166
174
  doc = inject(DOCUMENT);
167
175
  isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
168
- region = null;
169
- pending = null;
176
+ politeRegion = null;
177
+ assertiveRegion = null;
178
+ pending = {
179
+ polite: null,
180
+ assertive: null,
181
+ };
170
182
  /**
171
- * Announces `message` through the shared live region.
183
+ * Announces `message` through the fixed-politeness live region.
172
184
  *
173
185
  * @param message Text read by the screen reader.
174
186
  * @param politeness `'polite'` (default) queues after the current
175
- * utterance; `'assertive'` interrupts immediately.
187
+ * utterance; `'assertive'` interrupts immediately. Each politeness owns its
188
+ * own region, so the two never overwrite each other.
176
189
  */
177
190
  announce(message, politeness = 'polite') {
178
191
  if (!this.isBrowser) {
179
192
  return;
180
193
  }
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.
194
+ const region = this.ensureRegion(politeness);
195
+ // Clear first, then write one frame later so repeating the same string
196
+ // still registers as a content change for the SR. Polite and assertive
197
+ // keep independent timers so one politeness never cancels the other.
185
198
  region.textContent = '';
186
- if (this.pending !== null) {
187
- clearTimeout(this.pending);
199
+ const existing = this.pending[politeness];
200
+ if (existing !== null) {
201
+ clearTimeout(existing);
188
202
  }
189
- this.pending = setTimeout(() => {
203
+ this.pending[politeness] = setTimeout(() => {
190
204
  region.textContent = message;
191
- this.pending = null;
192
- });
205
+ this.pending[politeness] = null;
206
+ }, CLEAR_DELAY_MS);
193
207
  }
194
208
  ngOnDestroy() {
195
- if (this.pending !== null) {
196
- clearTimeout(this.pending);
197
- this.pending = null;
209
+ for (const politeness of ['polite', 'assertive']) {
210
+ const timer = this.pending[politeness];
211
+ if (timer !== null) {
212
+ clearTimeout(timer);
213
+ this.pending[politeness] = null;
214
+ }
198
215
  }
199
- this.region?.remove();
200
- this.region = null;
216
+ this.politeRegion?.remove();
217
+ this.assertiveRegion?.remove();
218
+ this.politeRegion = null;
219
+ this.assertiveRegion = null;
201
220
  }
202
- ensureRegion() {
203
- if (this.region) {
204
- return this.region;
221
+ ensureRegion(politeness) {
222
+ const existing = politeness === 'polite' ? this.politeRegion : this.assertiveRegion;
223
+ if (existing) {
224
+ return existing;
205
225
  }
206
226
  const span = this.doc.createElement('span');
207
- span.setAttribute('aria-live', 'polite');
227
+ span.setAttribute('aria-live', politeness);
208
228
  span.setAttribute('aria-atomic', 'true');
209
229
  span.className = 'cngx-sr-only';
210
230
  span.style.position = 'absolute';
@@ -217,7 +237,12 @@ class CngxLiveAnnouncer {
217
237
  span.style.whiteSpace = 'nowrap';
218
238
  span.style.border = '0';
219
239
  this.doc.body.appendChild(span);
220
- this.region = span;
240
+ if (politeness === 'polite') {
241
+ this.politeRegion = span;
242
+ }
243
+ else {
244
+ this.assertiveRegion = span;
245
+ }
221
246
  return span;
222
247
  }
223
248
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
@@ -727,6 +752,8 @@ class CngxRovingTabindex {
727
752
  /** Host element for `data-cngx-recycle-index` queries in virtual mode. */
728
753
  hostEl = inject((ElementRef));
729
754
  pendingFocusState = signal(null, ...(ngDevMode ? [{ debugName: "pendingFocusState" }] : /* istanbul ignore next */ []));
755
+ /** Document writing direction - flips the horizontal-arrow index deltas under `rtl` (APG). */
756
+ direction = injectDirection();
730
757
  /**
731
758
  * Set true just before a navigation key (arrow / Home / End) moves focus to a
732
759
  * new item, cleared by {@link consumeNavigationKey}. Transient handshake, not
@@ -750,17 +777,38 @@ class CngxRovingTabindex {
750
777
  const active = this.activeIndex();
751
778
  const vc = this.virtualCount();
752
779
  if (vc != null) {
753
- // Virtual mode: match by data-cngx-recycle-index attribute
780
+ // Virtual mode: match by data-cngx-recycle-index attribute. Clamp the
781
+ // model itself when the virtual space shrinks below it - a ghost
782
+ // index would otherwise anchor the next arrow press. An empty space
783
+ // (vc 0) keeps the model untouched so a repopulated list restores it.
784
+ const clamped = vc > 0 ? Math.max(0, Math.min(active, vc - 1)) : active;
785
+ if (clamped !== active) {
786
+ untracked(() => this.activeIndex.set(clamped));
787
+ }
754
788
  items.forEach((item) => {
755
789
  const el = item.elementRef.nativeElement;
756
790
  const idx = el.dataset['cngxRecycleIndex'];
757
- el.setAttribute('tabindex', idx != null && Number(idx) === active ? '0' : '-1');
791
+ el.setAttribute('tabindex', idx != null && Number(idx) === clamped ? '0' : '-1');
758
792
  });
759
793
  }
760
794
  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'));
795
+ // Standard mode: match by array index. The tab stop must land on an
796
+ // enabled item - fall back to the first enabled one when the clamped
797
+ // target is disabled (initial index into a disabled leaf, or the
798
+ // active item got disabled). The model is written back so keyboard
799
+ // navigation anchors where the tab stop actually sits. An empty list
800
+ // keeps the model untouched so a repopulated list restores it.
801
+ if (items.length === 0) {
802
+ return;
803
+ }
804
+ let target = Math.max(0, Math.min(active, items.length - 1));
805
+ if (items[target]?.disabled()) {
806
+ target = this.findFirst(items) ?? target;
807
+ }
808
+ if (target !== active) {
809
+ untracked(() => this.activeIndex.set(target));
810
+ }
811
+ items.forEach((item, i) => item.elementRef.nativeElement.setAttribute('tabindex', i === target ? '0' : '-1'));
764
812
  }
765
813
  });
766
814
  }
@@ -792,6 +840,11 @@ class CngxRovingTabindex {
792
840
  * based on whether `virtualCount` is set.
793
841
  */
794
842
  handleKeyDown(event) {
843
+ // Never hijack browser/app shortcuts: Ctrl/Cmd/Alt combos pass through
844
+ // untouched (Ctrl+Home, Cmd+ArrowLeft and friends belong to the app).
845
+ if (event.ctrlKey || event.metaKey || event.altKey) {
846
+ return;
847
+ }
795
848
  const vc = this.virtualCount();
796
849
  const allItems = this.items();
797
850
  const isVirtual = vc != null;
@@ -806,9 +859,16 @@ class CngxRovingTabindex {
806
859
  const navigate = (direction) => isVirtual
807
860
  ? this.findNextVirtual(currentActive, total, direction)
808
861
  : this.findNext(currentActive, allItems, direction);
862
+ const inlineNav = (key) => {
863
+ if (!this.isHorizontal()) {
864
+ return null;
865
+ }
866
+ const step = resolveInlineStep(key, this.direction());
867
+ return step === null ? null : navigate(step);
868
+ };
809
869
  const keyMap = {
810
- ArrowRight: () => (this.isHorizontal() ? navigate(1) : null),
811
- ArrowLeft: () => (this.isHorizontal() ? navigate(-1) : null),
870
+ ArrowRight: () => inlineNav('ArrowRight'),
871
+ ArrowLeft: () => inlineNav('ArrowLeft'),
812
872
  ArrowDown: () => (this.isVertical() ? navigate(1) : null),
813
873
  ArrowUp: () => (this.isVertical() ? navigate(-1) : null),
814
874
  Home: () => (isVirtual ? 0 : this.findFirst(allItems)),
@@ -837,6 +897,34 @@ class CngxRovingTabindex {
837
897
  event.preventDefault();
838
898
  }
839
899
  }
900
+ /**
901
+ * Keeps `activeIndex` in sync with real focus (APG): when an item gains
902
+ * focus by any means - pointer click, script focus, assistive tech - the
903
+ * tab stop follows it instead of staying on the last arrow-key target.
904
+ */
905
+ handleFocusIn(event) {
906
+ const target = event.target;
907
+ if (target === null) {
908
+ return;
909
+ }
910
+ const vc = this.virtualCount();
911
+ if (vc != null) {
912
+ const holder = target.closest('[data-cngx-recycle-index]');
913
+ const idx = holder === null ? NaN : Number(holder.getAttribute('data-cngx-recycle-index'));
914
+ if (Number.isInteger(idx) && idx >= 0 && idx < vc && idx !== this.activeIndex()) {
915
+ this.activeIndex.set(idx);
916
+ }
917
+ return;
918
+ }
919
+ const items = this.items();
920
+ const idx = items.findIndex((item) => {
921
+ const el = item.elementRef.nativeElement;
922
+ return el === target || el.contains(target);
923
+ });
924
+ if (idx >= 0 && !items[idx].disabled() && idx !== this.activeIndex()) {
925
+ this.activeIndex.set(idx);
926
+ }
927
+ }
840
928
  /**
841
929
  * Attempts to focus a virtual item by querying `data-cngx-recycle-index`.
842
930
  * If the element is not in the DOM, sets `pendingFocus` for external resolution.
@@ -918,7 +1006,7 @@ class CngxRovingTabindex {
918
1006
  return null;
919
1007
  }
920
1008
  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 });
1009
+ 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
1010
  }
923
1011
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRovingTabindex, decorators: [{
924
1012
  type: Directive,
@@ -928,6 +1016,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
928
1016
  standalone: true,
929
1017
  host: {
930
1018
  '(keydown)': 'handleKeyDown($event)',
1019
+ '(focusin)': 'handleFocusIn($event)',
931
1020
  },
932
1021
  }]
933
1022
  }], 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 +1062,13 @@ const CNGX_AD_ITEM = new InjectionToken('CNGX_AD_ITEM');
973
1062
  *
974
1063
  * ### Virtualization
975
1064
  *
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.
1065
+ * When `virtualCount` is set, navigation addresses the absolute index space
1066
+ * `[0, virtualCount)` even when only a window is rendered. Bind `windowStart`
1067
+ * to the recycler's window start so item lookups (id resolution, disabled
1068
+ * checks, typeahead labels) map absolute indices onto the rendered subset.
1069
+ * Targets outside the window surface as `pendingHighlight`; the consumer
1070
+ * scrolls them into view (`connectRecyclerToActiveDescendant`) and the
1071
+ * directive clears the pending state once the target renders.
979
1072
  *
980
1073
  * ### Material/CDK equivalent
981
1074
  *
@@ -1018,12 +1111,21 @@ class CngxActiveDescendant {
1018
1111
  * range surface as `pendingHighlight` for scroll-and-retry protocols.
1019
1112
  */
1020
1113
  virtualCount = input(undefined, ...(ngDevMode ? [{ debugName: "virtualCount" }] : /* istanbul ignore next */ []));
1114
+ /**
1115
+ * Absolute index of the first rendered item in virtual mode - the recycler
1116
+ * window start. All rendered-item lookups are offset by it so absolute
1117
+ * indices resolve the right item once the window has scrolled past 0.
1118
+ * Ignored when `virtualCount` is unset.
1119
+ */
1120
+ windowStart = input(0, ...(ngDevMode ? [{ debugName: "windowStart" }] : /* istanbul ignore next */ []));
1021
1121
  /** Emitted when `activateCurrent()` is called with an active item. */
1022
1122
  activated = output();
1023
1123
  /** Emitted whenever the highlighted item changes. */
1024
1124
  highlighted = output();
1025
1125
  hostEl = inject((ElementRef));
1026
1126
  registered = contentChildren(CNGX_AD_ITEM, { ...(ngDevMode ? { debugName: "registered" } : /* istanbul ignore next */ {}), descendants: true });
1127
+ /** Document writing direction - flips the horizontal-arrow steps under `rtl` (APG). */
1128
+ direction = injectDirection();
1027
1129
  /** Guards host attribute writes until after first render. */
1028
1130
  initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
1029
1131
  /** -1 means "no active item". Range is [0, resolvedItems().length). */
@@ -1060,9 +1162,15 @@ class CngxActiveDescendant {
1060
1162
  if (idx < 0) {
1061
1163
  return null;
1062
1164
  }
1063
- const list = this.resolvedItems();
1064
- return list[idx] ?? null;
1165
+ return this.itemAt(idx);
1065
1166
  }, ...(ngDevMode ? [{ debugName: "activeItem" }] : /* istanbul ignore next */ []));
1167
+ /**
1168
+ * `activeItem` pinned to the item id for the `highlighted` emission: a
1169
+ * re-render that produces a fresh object for the same item must not
1170
+ * re-emit. `activeItem` itself stays identity-equal so `activeValue`
1171
+ * tracks value changes on an unchanged id.
1172
+ */
1173
+ highlightedItem = computed(() => this.activeItem(), { ...(ngDevMode ? { debugName: "highlightedItem" } : /* istanbul ignore next */ {}), equal: (a, b) => a === b || (a !== null && b !== null && a.id === b.id) });
1066
1174
  activeId = computed(() => this.activeItem()?.id ?? null, ...(ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []));
1067
1175
  activeValue = computed(() => this.activeItem()?.value ?? null, ...(ngDevMode ? [{ debugName: "activeValue" }] : /* istanbul ignore next */ []));
1068
1176
  typeaheadBuffer = signal('', ...(ngDevMode ? [{ debugName: "typeaheadBuffer" }] : /* istanbul ignore next */ []));
@@ -1077,8 +1185,16 @@ class CngxActiveDescendant {
1077
1185
  this.highlightFirst();
1078
1186
  }
1079
1187
  });
1188
+ // Leading nulls are start-up state, not a highlight change - emit only
1189
+ // once something was highlighted (later resets back to null still emit).
1190
+ let hadHighlight = false;
1080
1191
  effect(() => {
1081
- this.highlighted.emit(this.activeItem());
1192
+ const item = this.highlightedItem();
1193
+ if (!hadHighlight && item === null) {
1194
+ return;
1195
+ }
1196
+ hadHighlight = true;
1197
+ this.highlighted.emit(item);
1082
1198
  });
1083
1199
  effect(() => {
1084
1200
  const idx = this.activeIndex();
@@ -1094,6 +1210,16 @@ class CngxActiveDescendant {
1094
1210
  }
1095
1211
  queueMicrotask(() => this.scrollActiveIntoView());
1096
1212
  });
1213
+ // Clamp the active STATE, not just the derived display, when the item
1214
+ // space shrinks below it - otherwise the next arrow press navigates
1215
+ // relative to a ghost index.
1216
+ effect(() => {
1217
+ const total = this.totalCount();
1218
+ const idx = this.activeIndexState();
1219
+ if (idx >= total) {
1220
+ untracked(() => this.activeIndexState.set(total > 0 ? total - 1 : -1));
1221
+ }
1222
+ });
1097
1223
  inject(DestroyRef).onDestroy(() => {
1098
1224
  if (this.typeaheadTimer !== null) {
1099
1225
  clearTimeout(this.typeaheadTimer);
@@ -1139,8 +1265,10 @@ class CngxActiveDescendant {
1139
1265
  this.activeIndexState.set(index);
1140
1266
  }
1141
1267
  /**
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.
1268
+ * Highlight the first rendered item whose value matches (via `Object.is`).
1269
+ * No-op if no match. Disabled items are rejected when `skipDisabled()` is
1270
+ * true. In virtual mode only the rendered window is searched; the resolved
1271
+ * index is absolute.
1144
1272
  */
1145
1273
  highlightByValue(value) {
1146
1274
  const items = this.resolvedItems();
@@ -1151,7 +1279,7 @@ class CngxActiveDescendant {
1151
1279
  if (this.skipDisabled() && items[idx].disabled) {
1152
1280
  return;
1153
1281
  }
1154
- this.activeIndexState.set(idx);
1282
+ this.activeIndexState.set(idx + this.windowOffset());
1155
1283
  }
1156
1284
  /** Clear the highlight. */
1157
1285
  resetHighlight() {
@@ -1169,6 +1297,12 @@ class CngxActiveDescendant {
1169
1297
  this.pendingHighlightState.set(null);
1170
1298
  }
1171
1299
  handleKeydown(event) {
1300
+ // Never hijack browser/app shortcuts: Ctrl/Cmd/Alt combos pass through
1301
+ // untouched (Ctrl+C would otherwise hit the typeahead branch and get
1302
+ // preventDefault'd). Shift stays allowed - it produces printable chars.
1303
+ if (event.ctrlKey || event.metaKey || event.altKey) {
1304
+ return;
1305
+ }
1172
1306
  // Skip events from editable descendants. Without this, every
1173
1307
  // printable key typed into a descendant <input> hits AD's typeahead
1174
1308
  // branch, gets preventDefault'd, and never reaches the input.
@@ -1218,18 +1352,23 @@ class CngxActiveDescendant {
1218
1352
  this.highlightNext();
1219
1353
  }
1220
1354
  return;
1221
- case 'ArrowUp':
1222
- if (orientation === 'vertical') {
1223
- this.highlightPrev();
1224
- }
1225
- return;
1226
1355
  case 'ArrowRight':
1227
- if (orientation === 'horizontal') {
1356
+ case 'ArrowLeft': {
1357
+ if (orientation !== 'horizontal') {
1358
+ return;
1359
+ }
1360
+ // RTL flips the horizontal arrows (same kernel roving uses).
1361
+ const step = resolveInlineStep(key, this.direction());
1362
+ if (step === 1) {
1228
1363
  this.highlightNext();
1229
1364
  }
1365
+ else if (step === -1) {
1366
+ this.highlightPrev();
1367
+ }
1230
1368
  return;
1231
- case 'ArrowLeft':
1232
- if (orientation === 'horizontal') {
1369
+ }
1370
+ case 'ArrowUp':
1371
+ if (orientation === 'vertical') {
1233
1372
  this.highlightPrev();
1234
1373
  }
1235
1374
  return;
@@ -1266,18 +1405,32 @@ class CngxActiveDescendant {
1266
1405
  this.typeaheadBuffer.set('');
1267
1406
  this.typeaheadTimer = null;
1268
1407
  }, this.typeaheadDebounce());
1408
+ // Labels exist only for rendered items, so the search space is the
1409
+ // rendered window; matches map back to absolute indices in virtual mode.
1269
1410
  const items = this.resolvedItems();
1270
1411
  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];
1412
+ const count = items.length;
1413
+ if (count === 0) {
1414
+ return;
1415
+ }
1416
+ const windowOffset = this.windowOffset();
1417
+ const activeRel = this.activeIndexState() < 0 ? -1 : this.activeIndexState() - windowOffset;
1418
+ // APG cycle: a single-character query (including a repeated letter, whose
1419
+ // buffer collapses back to that letter) searches AFTER the active item so
1420
+ // each press advances through the matches. A genuine multi-character query
1421
+ // keeps matching the current item first.
1422
+ const sameChar = next.length > 1 && [...next].every((c) => c === next[0]);
1423
+ const term = sameChar ? next[0] : next;
1424
+ const cycles = term.length === 1;
1425
+ const startRel = cycles ? activeRel + 1 : Math.max(0, activeRel);
1426
+ for (let step = 0; step < count; step++) {
1427
+ const rel = (((startRel + step) % count) + count) % count;
1428
+ const candidate = items[rel];
1276
1429
  if (skip && candidate.disabled) {
1277
1430
  continue;
1278
1431
  }
1279
- if (candidate.label.toLowerCase().startsWith(next)) {
1280
- this.activeIndexState.set(i);
1432
+ if (candidate.label.toLowerCase().startsWith(term)) {
1433
+ this.activeIndexState.set(rel + windowOffset);
1281
1434
  return;
1282
1435
  }
1283
1436
  }
@@ -1287,7 +1440,6 @@ class CngxActiveDescendant {
1287
1440
  if (total === 0) {
1288
1441
  return null;
1289
1442
  }
1290
- const items = this.resolvedItems();
1291
1443
  const skip = this.skipDisabled();
1292
1444
  const loop = this.loop();
1293
1445
  let idx = current < 0 ? (direction === 1 ? -1 : total) : current;
@@ -1299,29 +1451,34 @@ class CngxActiveDescendant {
1299
1451
  }
1300
1452
  idx = ((idx % total) + total) % total;
1301
1453
  }
1302
- if (!skip || !items[idx]?.disabled) {
1454
+ if (!skip || !this.isDisabledAt(idx)) {
1303
1455
  return idx;
1304
1456
  }
1305
1457
  }
1306
1458
  return null;
1307
1459
  }
1460
+ /**
1461
+ * First/last navigable absolute index. Spans the full virtual range - End
1462
+ * targets `totalCount - 1` even when that item is not rendered (it surfaces
1463
+ * as `pendingHighlight`); unrendered items count as enabled because their
1464
+ * disabled state is unknowable.
1465
+ */
1308
1466
  findBoundary(direction) {
1309
- const items = this.resolvedItems();
1310
- const total = items.length;
1467
+ const total = this.totalCount();
1311
1468
  if (total === 0) {
1312
1469
  return null;
1313
1470
  }
1314
1471
  const skip = this.skipDisabled();
1315
1472
  if (direction === 1) {
1316
1473
  for (let i = 0; i < total; i++) {
1317
- if (!skip || !items[i].disabled) {
1474
+ if (!skip || !this.isDisabledAt(i)) {
1318
1475
  return i;
1319
1476
  }
1320
1477
  }
1321
1478
  }
1322
1479
  else {
1323
1480
  for (let i = total - 1; i >= 0; i--) {
1324
- if (!skip || !items[i].disabled) {
1481
+ if (!skip || !this.isDisabledAt(i)) {
1325
1482
  return i;
1326
1483
  }
1327
1484
  }
@@ -1335,26 +1492,40 @@ class CngxActiveDescendant {
1335
1492
  }
1336
1493
  return this.resolvedItems().length;
1337
1494
  }
1338
- isDisabledAt(index) {
1495
+ /** Rendered-window offset: `windowStart` in virtual mode, `0` otherwise. */
1496
+ windowOffset() {
1497
+ return this.virtualCount() != null ? this.windowStart() : 0;
1498
+ }
1499
+ /** Item at an absolute index, `null` when outside the rendered window. */
1500
+ itemAt(index) {
1501
+ const rel = index - this.windowOffset();
1339
1502
  const items = this.resolvedItems();
1340
- return !!items[index]?.disabled;
1503
+ if (rel < 0 || rel >= items.length) {
1504
+ return null;
1505
+ }
1506
+ return items[rel] ?? null;
1507
+ }
1508
+ isDisabledAt(index) {
1509
+ return !!this.itemAt(index)?.disabled;
1341
1510
  }
1342
1511
  isRendered(index) {
1343
- const items = this.resolvedItems();
1344
- return index >= 0 && index < items.length && !!items[index];
1512
+ return this.itemAt(index) !== null;
1345
1513
  }
1346
1514
  scrollActiveIntoView() {
1347
1515
  const id = this.activeId();
1348
1516
  if (!id) {
1349
1517
  return;
1350
1518
  }
1351
- const el = this.hostEl.nativeElement.querySelector(`#${cssEscape(id)}`);
1519
+ // Document-wide by escaped id: aria-owns layouts render the option list
1520
+ // outside the host subtree, a host-scoped query never finds those.
1521
+ const doc = this.hostEl.nativeElement.ownerDocument;
1522
+ const el = doc.querySelector(`#${cssEscape(id)}`);
1352
1523
  if (el instanceof HTMLElement && typeof el.scrollIntoView === 'function') {
1353
1524
  el.scrollIntoView({ block: 'nearest', inline: 'nearest' });
1354
1525
  }
1355
1526
  }
1356
1527
  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 });
1528
+ 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" }, 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
1529
  }
1359
1530
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, decorators: [{
1360
1531
  type: Directive,
@@ -1367,7 +1538,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1367
1538
  '(keydown)': 'handleKeydown($event)',
1368
1539
  },
1369
1540
  }]
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 }] }] } });
1541
+ }], 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"] }], registered: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => CNGX_AD_ITEM), { ...{ descendants: true }, isSignal: true }] }] } });
1371
1542
  /** @internal */
1372
1543
  function handleToItem(handle) {
1373
1544
  return {
@@ -1457,16 +1628,7 @@ class CngxReducedMotion {
1457
1628
  /** `true` when the user's OS is set to prefer reduced motion. Updates reactively. */
1458
1629
  prefersReducedMotion;
1459
1630
  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();
1631
+ this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
1470
1632
  }
1471
1633
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxReducedMotion, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1472
1634
  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 });