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

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 (69) hide show
  1. package/card/README.md +2 -1
  2. package/command/README.md +29 -0
  3. package/data/README.md +15 -3
  4. package/dialog/README.md +23 -1
  5. package/fesm2022/cngx-common-a11y.mjs +517 -184
  6. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  7. package/fesm2022/cngx-common-audio.mjs +62 -17
  8. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  9. package/fesm2022/cngx-common-card.mjs +301 -46
  10. package/fesm2022/cngx-common-card.mjs.map +1 -1
  11. package/fesm2022/cngx-common-chart.mjs +1221 -479
  12. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  13. package/fesm2022/cngx-common-command.mjs +97 -16
  14. package/fesm2022/cngx-common-command.mjs.map +1 -1
  15. package/fesm2022/cngx-common-data.mjs +1496 -499
  16. package/fesm2022/cngx-common-data.mjs.map +1 -1
  17. package/fesm2022/cngx-common-dialog.mjs +236 -61
  18. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  19. package/fesm2022/cngx-common-display.mjs +364 -93
  20. package/fesm2022/cngx-common-display.mjs.map +1 -1
  21. package/fesm2022/cngx-common-interactive.mjs +2040 -1046
  22. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  23. package/fesm2022/cngx-common-layout.mjs +955 -125
  24. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  25. package/fesm2022/cngx-common-popover.mjs +1293 -89
  26. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  27. package/fesm2022/cngx-common-stepper.mjs +997 -453
  28. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  29. package/fesm2022/cngx-common-tabs.mjs +1794 -1265
  30. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  31. package/fesm2022/cngx-common-timeline.mjs +151 -61
  32. package/fesm2022/cngx-common-timeline.mjs.map +1 -1
  33. package/fesm2022/cngx-common.mjs +1 -1
  34. package/interactive/README.md +15 -4
  35. package/layout/README.md +37 -1
  36. package/package.json +20 -7
  37. package/popover/README.md +58 -2
  38. package/schematics/collection.json +9 -0
  39. package/schematics/ng-add/index.js +9 -0
  40. package/schematics/ng-add/schema.json +91 -0
  41. package/schematics/package.json +3 -0
  42. package/stepper/README.md +11 -8
  43. package/theming/components/cngx-accordion.css +1 -1
  44. package/theming/components/cngx-backdrop.css +12 -0
  45. package/theming/components/cngx-button-toggle.css +29 -3
  46. package/theming/components/cngx-data-grid.css +168 -1
  47. package/theming/components/cngx-dialog.css +13 -0
  48. package/theming/components/cngx-listbox.css +21 -12
  49. package/theming/components/cngx-menu.css +56 -16
  50. package/theming/components/cngx-popover-sheet.css +402 -0
  51. package/theming/components/cngx-popover.css +28 -0
  52. package/theming/components/cngx-recycler-placeholder.css +196 -0
  53. package/theming/components/cngx-ripple.css +1 -1
  54. package/theming/components/cngx-slider.css +32 -1
  55. package/theming/components/cngx-tooltip.css +12 -0
  56. package/timeline/README.md +155 -0
  57. package/types/cngx-common-a11y.d.ts +205 -28
  58. package/types/cngx-common-card.d.ts +201 -17
  59. package/types/cngx-common-chart.d.ts +345 -48
  60. package/types/cngx-common-command.d.ts +50 -10
  61. package/types/cngx-common-data.d.ts +743 -92
  62. package/types/cngx-common-dialog.d.ts +161 -10
  63. package/types/cngx-common-display.d.ts +356 -142
  64. package/types/cngx-common-interactive.d.ts +910 -226
  65. package/types/cngx-common-layout.d.ts +603 -32
  66. package/types/cngx-common-popover.d.ts +612 -49
  67. package/types/cngx-common-stepper.d.ts +526 -237
  68. package/types/cngx-common-tabs.d.ts +358 -75
  69. package/types/cngx-common-timeline.d.ts +108 -22
@@ -1,9 +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, untracked, InjectionToken, output } from '@angular/core';
2
+ import { input, Directive, inject, PLATFORM_ID, Injectable, DestroyRef, ElementRef, Injector, afterNextRender, effect, signal, InjectionToken, computed, untracked, model, contentChildren, output, linkedSignal } 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
+ import { injectDirection, resolveInlineStep, resolveStepFrom, resolveBoundaryStep } from '@cngx/core';
6
+ import { injectLocale, createTypeaheadMatcher, createMediaQuerySignal } from '@cngx/core/utils';
7
7
 
8
8
  /**
9
9
  * Manages `aria-expanded` and optionally `aria-controls` on the host element.
@@ -37,7 +37,6 @@ import { createMediaQuerySignal } from '@cngx/core/utils';
37
37
  * ```
38
38
  *
39
39
  * @category common/a11y
40
- * @docsKind primary
41
40
  * @wcag AA
42
41
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/aria-expanded.directive.ts
43
42
  * @since 0.1.0
@@ -96,7 +95,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
96
95
  * ```
97
96
  *
98
97
  * @category common/a11y
99
- * @docsKind primary
100
98
  * @wcag AA
101
99
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-region.directive.ts
102
100
  * @since 0.1.0
@@ -137,6 +135,119 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
137
135
  // One frame. Clear the region this long before writing so an intentionally
138
136
  // repeated identical string still registers as a content change for the SR.
139
137
  const CLEAR_DELAY_MS = 16;
138
+ const POLITENESS = ['polite', 'assertive'];
139
+ /**
140
+ * @internal Browser only: callers guard the server path. Each region is a
141
+ * visually hidden `aria-live` + `aria-atomic="true"` span (the attribute
142
+ * contract of `CngxLiveRegion`), created lazily on the first announce of its
143
+ * politeness or by `ensure()`.
144
+ *
145
+ * `redirect` is asked when a write is due: returning `true` means the caller
146
+ * took the message elsewhere (its container stopped being readable while the
147
+ * write was pending), so nothing is written here.
148
+ */
149
+ function createLiveRegionPair(container, doc, redirect) {
150
+ const regions = {
151
+ polite: null,
152
+ assertive: null,
153
+ };
154
+ const pending = {
155
+ polite: null,
156
+ assertive: null,
157
+ };
158
+ const ensureRegion = (politeness) => {
159
+ const existing = regions[politeness];
160
+ if (existing) {
161
+ return existing;
162
+ }
163
+ const span = doc.createElement('span');
164
+ span.setAttribute('aria-live', politeness);
165
+ span.setAttribute('aria-atomic', 'true');
166
+ span.className = 'cngx-sr-only';
167
+ span.style.position = 'absolute';
168
+ span.style.width = '1px';
169
+ span.style.height = '1px';
170
+ span.style.padding = '0';
171
+ span.style.margin = '-1px';
172
+ span.style.overflow = 'hidden';
173
+ span.style.clip = 'rect(0, 0, 0, 0)';
174
+ span.style.whiteSpace = 'nowrap';
175
+ span.style.border = '0';
176
+ container.appendChild(span);
177
+ regions[politeness] = span;
178
+ return span;
179
+ };
180
+ const cancel = (politeness) => {
181
+ const write = pending[politeness];
182
+ if (write) {
183
+ clearTimeout(write.timer);
184
+ pending[politeness] = null;
185
+ }
186
+ return write;
187
+ };
188
+ return {
189
+ announce(message, politeness, delayMs = CLEAR_DELAY_MS) {
190
+ const region = ensureRegion(politeness);
191
+ // Clear first, then write one frame later so repeating the same string
192
+ // still registers as a content change for the SR. Polite and assertive
193
+ // keep independent timers so one politeness never cancels the other.
194
+ region.textContent = '';
195
+ cancel(politeness);
196
+ pending[politeness] = {
197
+ message,
198
+ timer: setTimeout(() => {
199
+ pending[politeness] = null;
200
+ if (redirect?.({ message, politeness })) {
201
+ return;
202
+ }
203
+ region.textContent = message;
204
+ }, delayMs),
205
+ };
206
+ },
207
+ ensure() {
208
+ for (const politeness of POLITENESS) {
209
+ ensureRegion(politeness);
210
+ }
211
+ },
212
+ takePending() {
213
+ const taken = [];
214
+ for (const politeness of POLITENESS) {
215
+ const write = cancel(politeness);
216
+ if (write) {
217
+ taken.push({ message: write.message, politeness });
218
+ }
219
+ }
220
+ return taken;
221
+ },
222
+ destroy() {
223
+ for (const politeness of POLITENESS) {
224
+ cancel(politeness);
225
+ regions[politeness]?.remove();
226
+ regions[politeness] = null;
227
+ }
228
+ },
229
+ };
230
+ }
231
+
232
+ // A screen reader commonly misses a change to a live region that entered the
233
+ // DOM a frame earlier. A modal pair is created on the announcement that needs
234
+ // it, so its first write waits until the regions have settled.
235
+ const FIRST_MODAL_WRITE_DELAY_MS = 100;
236
+ const MODAL_SELECTOR = '[aria-modal="true"]';
237
+ /** A modal container a screen reader currently reads. */
238
+ function isOpenModal(el) {
239
+ if (!el.isConnected || el.getAttribute('aria-modal') !== 'true') {
240
+ return false;
241
+ }
242
+ return !(el instanceof HTMLDialogElement) || el.open;
243
+ }
244
+ // Overlays such as CngxDialog are appended to the body, and a nested modal
245
+ // follows its container, so document order is stacking order: the last open
246
+ // modal outside an inert subtree is the one a screen reader still reads.
247
+ function topmostOpenModal(doc) {
248
+ const open = Array.from(doc.querySelectorAll(MODAL_SELECTOR)).filter((el) => isOpenModal(el) && !el.closest('[inert]'));
249
+ return open.at(-1) ?? null;
250
+ }
140
251
  /**
141
252
  * Imperative, reusable polite/assertive live-region announcer.
142
253
  *
@@ -154,6 +265,24 @@ const CLEAR_DELAY_MS = 16;
154
265
  * polite one. Per region, the text is cleared and re-set one frame later so an
155
266
  * identical consecutive message is still re-read by the screen reader.
156
267
  *
268
+ * A modal dialog hides everything outside it from assistive technology, so a
269
+ * body region is silent while one is open. Pass the announcing element as the
270
+ * third argument and the message goes to a region pair inside its enclosing
271
+ * `[aria-modal="true"]` container instead; without a modal ancestor it goes to
272
+ * the body regions as before. When another modal covers that one, the topmost
273
+ * open modal receives it: the last `[aria-modal="true"]` element in document
274
+ * order that is open and not inside an `[inert]` subtree. That covers a modal
275
+ * nested inside the scope's own one as well as a sibling stacked on top of it,
276
+ * which is how `CngxDialog` stacks dialogs (every host is appended to
277
+ * `document.body`); a covered modal is hidden from assistive technology, so
278
+ * its region would be silent. The pair is created with both regions on first
279
+ * use and its first write waits until the regions have settled in the DOM. A
280
+ * message still pending when its modal closes moves to the next enclosing open
281
+ * modal, else to the topmost modal still open, else to the body regions, and
282
+ * the pair is removed. The scope is opt-in per call - an unscoped announcement
283
+ * never guesses a modal. {@link injectScopedLiveRegion} is the injection-time
284
+ * alternative when the caller knows its overlay host up front.
285
+ *
157
286
  * SSR-safe: all DOM access is guarded by `isPlatformBrowser`; on the server
158
287
  * `announce()` is a no-op and no region is created.
159
288
  *
@@ -161,10 +290,10 @@ const CLEAR_DELAY_MS = 16;
161
290
  * const announcer = inject(CngxLiveAnnouncer);
162
291
  * announcer.announce('Copied');
163
292
  * announcer.announce('Save failed', 'assertive');
293
+ * announcer.announce('Alert dismissed', 'polite', hostElement); // inside a modal
164
294
  * ```
165
295
  *
166
296
  * @category common/a11y
167
- * @docsKind primary
168
297
  * @wcag AA
169
298
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/live-announcer.ts
170
299
  * @since 0.1.0
@@ -173,12 +302,13 @@ const CLEAR_DELAY_MS = 16;
173
302
  class CngxLiveAnnouncer {
174
303
  doc = inject(DOCUMENT);
175
304
  isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
176
- politeRegion = null;
177
- assertiveRegion = null;
178
- pending = {
179
- polite: null,
180
- assertive: null,
181
- };
305
+ regions = null;
306
+ /**
307
+ * One pair per open `aria-modal` container, released once it closes.
308
+ * `outer` is the container's parent at creation, the route for its unwritten
309
+ * messages when it is removed from the DOM.
310
+ */
311
+ modalRegions = new Map();
182
312
  /**
183
313
  * Announces `message` through the fixed-politeness live region.
184
314
  *
@@ -186,64 +316,103 @@ class CngxLiveAnnouncer {
186
316
  * @param politeness `'polite'` (default) queues after the current
187
317
  * utterance; `'assertive'` interrupts immediately. Each politeness owns its
188
318
  * own region, so the two never overwrite each other.
319
+ * @param scope The announcing element. When it sits inside an
320
+ * `[aria-modal="true"]` container, the message is written into a region
321
+ * inside the topmost open modal (that container unless another modal
322
+ * covers it), which a screen reader still reads while the modal hides the
323
+ * rest of the page. `null` / omitted: the body regions.
189
324
  */
190
- announce(message, politeness = 'polite') {
325
+ announce(message, politeness = 'polite', scope) {
191
326
  if (!this.isBrowser) {
192
327
  return;
193
328
  }
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.
198
- region.textContent = '';
199
- const existing = this.pending[politeness];
200
- if (existing !== null) {
201
- clearTimeout(existing);
202
- }
203
- this.pending[politeness] = setTimeout(() => {
204
- region.textContent = message;
205
- this.pending[politeness] = null;
206
- }, CLEAR_DELAY_MS);
329
+ this.releaseClosedModals();
330
+ this.route(scope, { message, politeness });
207
331
  }
208
332
  ngOnDestroy() {
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
- }
333
+ this.regions?.destroy();
334
+ this.regions = null;
335
+ for (const { pair } of this.modalRegions.values()) {
336
+ pair.destroy();
215
337
  }
216
- this.politeRegion?.remove();
217
- this.assertiveRegion?.remove();
218
- this.politeRegion = null;
219
- this.assertiveRegion = null;
338
+ this.modalRegions.clear();
220
339
  }
221
- ensureRegion(politeness) {
222
- const existing = politeness === 'polite' ? this.politeRegion : this.assertiveRegion;
340
+ /**
341
+ * `fromModal` marks a message that was already scoped to a modal which has
342
+ * since closed: with no open modal around its new scope it still goes to the
343
+ * topmost open modal rather than to the silent body regions.
344
+ */
345
+ route(scope, announcement, fromModal = false) {
346
+ const modal = this.targetModal(scope, fromModal);
347
+ if (!modal) {
348
+ this.regions ??= createLiveRegionPair(this.doc.body, this.doc);
349
+ this.regions.announce(announcement.message, announcement.politeness);
350
+ return;
351
+ }
352
+ const existing = this.modalRegions.get(modal);
223
353
  if (existing) {
224
- return existing;
354
+ existing.pair.announce(announcement.message, announcement.politeness);
355
+ return;
225
356
  }
226
- const span = this.doc.createElement('span');
227
- span.setAttribute('aria-live', politeness);
228
- span.setAttribute('aria-atomic', 'true');
229
- span.className = 'cngx-sr-only';
230
- span.style.position = 'absolute';
231
- span.style.width = '1px';
232
- span.style.height = '1px';
233
- span.style.padding = '0';
234
- span.style.margin = '-1px';
235
- span.style.overflow = 'hidden';
236
- span.style.clip = 'rect(0, 0, 0, 0)';
237
- span.style.whiteSpace = 'nowrap';
238
- span.style.border = '0';
239
- this.doc.body.appendChild(span);
240
- if (politeness === 'polite') {
241
- this.politeRegion = span;
357
+ const pair = createLiveRegionPair(modal, this.doc, (due) => this.redirectIfClosed(modal, due));
358
+ pair.ensure();
359
+ this.modalRegions.set(modal, { pair, outer: modal.parentElement });
360
+ pair.announce(announcement.message, announcement.politeness, FIRST_MODAL_WRITE_DELAY_MS);
361
+ }
362
+ /**
363
+ * The topmost open modal when `scope` sits in an open modal (or the message
364
+ * comes from a closed one), else `null` for the body regions. Falls back to
365
+ * the scope's own modal when no candidate outside an inert subtree is open.
366
+ */
367
+ targetModal(scope, fromModal) {
368
+ const own = this.enclosingOpenModal(scope);
369
+ if (!own && !fromModal) {
370
+ return null;
242
371
  }
243
- else {
244
- this.assertiveRegion = span;
372
+ return topmostOpenModal(this.doc) ?? own;
373
+ }
374
+ enclosingOpenModal(scope) {
375
+ let candidate = scope?.closest(MODAL_SELECTOR) ?? null;
376
+ while (candidate) {
377
+ if (candidate instanceof HTMLElement && isOpenModal(candidate)) {
378
+ return candidate;
379
+ }
380
+ candidate = candidate.parentElement?.closest(MODAL_SELECTOR) ?? null;
245
381
  }
246
- return span;
382
+ return null;
383
+ }
384
+ redirectIfClosed(modal, due) {
385
+ if (isOpenModal(modal)) {
386
+ return false;
387
+ }
388
+ const outer = this.outerOf(modal);
389
+ this.release(modal);
390
+ this.route(outer, due, true);
391
+ return true;
392
+ }
393
+ releaseClosedModals() {
394
+ for (const modal of Array.from(this.modalRegions.keys())) {
395
+ if (!isOpenModal(modal)) {
396
+ this.release(modal);
397
+ }
398
+ }
399
+ }
400
+ /** Drop the pair of a closed modal; its unwritten messages move outward. */
401
+ release(modal) {
402
+ const entry = this.modalRegions.get(modal);
403
+ if (!entry) {
404
+ return;
405
+ }
406
+ const outer = this.outerOf(modal);
407
+ this.modalRegions.delete(modal);
408
+ const unwritten = entry.pair.takePending();
409
+ entry.pair.destroy();
410
+ for (const announcement of unwritten) {
411
+ this.route(outer, announcement, true);
412
+ }
413
+ }
414
+ outerOf(modal) {
415
+ return modal.parentElement ?? this.modalRegions.get(modal)?.outer ?? null;
247
416
  }
248
417
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
249
418
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxLiveAnnouncer, providedIn: 'root' });
@@ -253,6 +422,69 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
253
422
  args: [{ providedIn: 'root' }]
254
423
  }] });
255
424
 
425
+ /**
426
+ * Create a polite + assertive live-region pair inside `host`.
427
+ *
428
+ * The scoped counterpart to {@link CngxLiveAnnouncer}: same regions, same
429
+ * clear-then-set timing, but appended to an overlay host instead of
430
+ * `document.body`. Use it for modal overlays: under `aria-modal` VoiceOver
431
+ * drops body-level live regions and speaks them late after the overlay
432
+ * closes, while a region inside the modal is spoken on every platform.
433
+ * Polite and assertive keep separate regions, so an assertive error never
434
+ * clobbers a polite status.
435
+ *
436
+ * Must run in an injection context; the regions are removed when that context
437
+ * is destroyed. No-op on the server.
438
+ *
439
+ * ```typescript
440
+ * private readonly region = injectScopedLiveRegion(inject(ElementRef).nativeElement);
441
+ *
442
+ * protected handleSaveFailed(): void {
443
+ * this.region.announce('Save failed', 'assertive');
444
+ * }
445
+ * ```
446
+ *
447
+ * @param host - Element that receives the two visually hidden regions.
448
+ *
449
+ * @category common/a11y
450
+ * @wcag AA
451
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/aria/scoped-live-region.ts
452
+ * @since 0.1.0
453
+ * @relatedTo CngxLiveAnnouncer, CngxLiveRegion
454
+ */
455
+ function injectScopedLiveRegion(host) {
456
+ const doc = inject(DOCUMENT);
457
+ const isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
458
+ let pair = null;
459
+ const ensurePair = () => {
460
+ pair ??= createLiveRegionPair(host, doc);
461
+ return pair;
462
+ };
463
+ const region = {
464
+ announce(message, politeness = 'polite') {
465
+ if (!isBrowser) {
466
+ return;
467
+ }
468
+ ensurePair().announce(message, politeness);
469
+ },
470
+ ensure() {
471
+ if (!isBrowser) {
472
+ return;
473
+ }
474
+ ensurePair().ensure();
475
+ },
476
+ takePending() {
477
+ return pair?.takePending() ?? [];
478
+ },
479
+ destroy() {
480
+ pair?.destroy();
481
+ pair = null;
482
+ },
483
+ };
484
+ inject(DestroyRef).onDestroy(() => region.destroy());
485
+ return region;
486
+ }
487
+
256
488
  /**
257
489
  * Reactive autofocus for dynamically inserted elements.
258
490
  *
@@ -281,7 +513,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
281
513
  * ```
282
514
  *
283
515
  * @category common/a11y
284
- * @docsKind primary
285
516
  * @wcag AA
286
517
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/autofocus.directive.ts
287
518
  * @since 0.1.0
@@ -330,7 +561,14 @@ class CngxAutofocus {
330
561
  }
331
562
  }
332
563
  applyFocus() {
333
- this.el.nativeElement.focus(this.options());
564
+ const el = this.el.nativeElement;
565
+ // A delayed schedule can outlive its trigger: the condition may have
566
+ // flipped off or the element may have left the DOM. Re-check both so a
567
+ // stale timer cannot steal focus from wherever it moved meanwhile.
568
+ if (!this.when() || !el.isConnected) {
569
+ return;
570
+ }
571
+ el.focus(this.options());
334
572
  }
335
573
  clearPending() {
336
574
  if (this.pendingTimer !== null) {
@@ -374,7 +612,9 @@ const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disa
374
612
  * `document.activeElement` at initialization time and restores it when the
375
613
  * host element is destroyed.
376
614
  *
377
- * Fallback chain: stored element → provided fallback → nearest focusable ancestor → body.
615
+ * Fallback chain: stored element → provided fallback → nearest focusable ancestor.
616
+ * When none resolves, focus is left where the browser put it - `<body>` is
617
+ * deliberately never a restore target.
378
618
  *
379
619
  * ### Panel that restores focus on close
380
620
  * ```html
@@ -395,7 +635,6 @@ const CNGX_FOCUSABLE_SELECTOR = 'a[href], button:not(:disabled), input:not(:disa
395
635
  * ```
396
636
  *
397
637
  * @category common/a11y
398
- * @docsKind primary
399
638
  * @wcag AA
400
639
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-restore.directive.ts
401
640
  * @since 0.1.0
@@ -493,6 +732,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
493
732
  }]
494
733
  }], ctorParameters: () => [], propDecorators: { restoreOnDestroy: [{ type: i0.Input, args: [{ isSignal: true, alias: "restoreOnDestroy", required: false }] }], fallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "fallback", required: false }] }] } });
495
734
 
735
+ /** @internal See {@link CngxFocusTrapDriver}. */
736
+ const CNGX_FOCUS_TRAP_DRIVER = new InjectionToken('CngxFocusTrapDriver');
496
737
  /**
497
738
  * Traps keyboard focus within the host element using the CDK `FocusTrap`.
498
739
  *
@@ -504,6 +745,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
504
745
  * The CDK's imperative `create()` / `destroy()` / `enabled` setter lifecycle
505
746
  * is handled internally via `effect()` and `DestroyRef`.
506
747
  *
748
+ * **Nesting:** traps do not coordinate with each other. When traps nest
749
+ * (dialog over drawer), enable only the innermost one and drive each
750
+ * `enabled` from your layering state - two simultaneously enabled traps
751
+ * fight over Tab. `CngxDialogStack` already does this for stacked dialogs.
752
+ *
507
753
  * ### Modal dialog
508
754
  * ```html
509
755
  * <div cngxFocusTrap [enabled]="isOpen()" [autoFocus]="true"
@@ -536,28 +782,72 @@ class CngxFocusTrap {
536
782
  enabled = input(false, ...(ngDevMode ? [{ debugName: "enabled" }] : /* istanbul ignore next */ []));
537
783
  /** Whether to auto-focus the first tabbable element when the trap activates. */
538
784
  autoFocus = input(true, ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
539
- /** Computed signal reflecting the current trap state. */
540
- isActive = computed(() => this.enabled(), ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
541
- trap;
785
+ injector = inject(Injector);
786
+ resolvedDriver = undefined;
787
+ driver() {
788
+ if (this.resolvedDriver === undefined) {
789
+ this.resolvedDriver = this.injector.get(CNGX_FOCUS_TRAP_DRIVER, null, { self: true });
790
+ }
791
+ return this.resolvedDriver;
792
+ }
793
+ /**
794
+ * The enabled state the trap actually follows: a composer's driver
795
+ * (see {@link CngxFocusTrapDriver}) wins over the `[enabled]` input.
796
+ */
797
+ effectiveEnabled = computed(() => this.driver()?.focusTrapEnabled() ?? this.enabled(), ...(ngDevMode ? [{ debugName: "effectiveEnabled" }] : /* istanbul ignore next */ []));
798
+ /**
799
+ * Readable alias of the effective enabled state for `exportAs` consumers
800
+ * (`trap.isActive()` reads better than re-binding the input).
801
+ */
802
+ isActive = computed(() => this.effectiveEnabled(), ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
803
+ host = inject(ElementRef).nativeElement;
804
+ factory = inject(FocusTrapFactory);
805
+ trap = null;
542
806
  constructor() {
543
- const el = inject((ElementRef));
544
- this.trap = inject(FocusTrapFactory).create(el.nativeElement);
807
+ // Track ONLY the effective enabled state: with autoFocus inside the
808
+ // tracked zone, flipping [autoFocus] while the trap is active would
809
+ // re-run the effect and yank focus back to the first tabbable element.
810
+ // The CDK calls are service work, not dependencies.
545
811
  effect(() => {
546
- const enabled = this.enabled();
547
- this.trap.enabled = enabled;
548
- if (enabled && this.autoFocus()) {
549
- void this.trap.focusFirstTabbableElementWhenReady();
550
- }
812
+ const enabled = this.effectiveEnabled();
813
+ untracked(() => {
814
+ if (!enabled && !this.trap) {
815
+ return;
816
+ }
817
+ const trap = this.ensureTrap();
818
+ trap.enabled = enabled;
819
+ if (enabled && !trap.hasAttached()) {
820
+ trap.attachAnchors();
821
+ }
822
+ if (enabled && (this.driver()?.focusTrapAutoFocus ?? this.autoFocus())) {
823
+ void trap.focusFirstTabbableElementWhenReady();
824
+ }
825
+ });
551
826
  });
552
- inject(DestroyRef).onDestroy(() => this.trap.destroy());
827
+ inject(DestroyRef).onDestroy(() => this.trap?.destroy());
553
828
  }
554
829
  /** Programmatically focus the first tabbable element within the trap. */
555
830
  focusFirst() {
556
- void this.trap.focusFirstTabbableElementWhenReady();
831
+ void this.ensureTrap().focusFirstTabbableElementWhenReady();
557
832
  }
558
833
  /** Programmatically focus the last tabbable element within the trap. */
559
834
  focusLast() {
560
- void this.trap.focusLastTabbableElementWhenReady();
835
+ void this.ensureTrap().focusLastTabbableElementWhenReady();
836
+ }
837
+ /**
838
+ * @internal Focus the first tabbable element right now, in the caller's
839
+ * stack. `focusFirst()` waits for the next render, which is too late for a
840
+ * composer that must move focus inside the user gesture that opened it.
841
+ * Returns `false` when nothing inside is tabbable.
842
+ */
843
+ focusFirstNow() {
844
+ return this.ensureTrap().focusFirstTabbableElement();
845
+ }
846
+ // Deferred anchors: the CDK sentinels are inserted on the first enable,
847
+ // so a trap that is never enabled leaves the DOM untouched.
848
+ ensureTrap() {
849
+ this.trap ??= this.factory.create(this.host, true);
850
+ return this.trap;
561
851
  }
562
852
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusTrap, deps: [], target: i0.ɵɵFactoryTarget.Directive });
563
853
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxFocusTrap, isStandalone: true, selector: "[cngxFocusTrap]", inputs: { enabled: { classPropertyName: "enabled", publicName: "enabled", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxFocusTrap"], ngImport: i0 });
@@ -585,7 +875,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
585
875
  * ```
586
876
  *
587
877
  * @category common/a11y
588
- * @docsKind primary
589
878
  * @wcag AA
590
879
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/focus/focus-visible.directive.ts
591
880
  * @since 0.1.0
@@ -594,11 +883,50 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
594
883
  * <example-url>http://localhost:4200/#/common/a11y/focus-visible/keyboard-vs-pointer</example-url>
595
884
  */
596
885
  class CngxFocusVisible {
886
+ doc = inject(DOCUMENT);
597
887
  focusVisibleState = signal(false, ...(ngDevMode ? [{ debugName: "focusVisibleState" }] : /* istanbul ignore next */ []));
598
888
  /** `true` when focus was initiated via keyboard (not pointer). */
599
889
  focusVisible = this.focusVisibleState.asReadonly();
600
- /** @internal Cleared on `focusin` after being set by `pointerdown`. */
601
890
  pointerActive = false;
891
+ pointerClearTimer = null;
892
+ schedulePointerClear = () => {
893
+ // One macrotask of grace: on touch, the compat mousedown and the focusin
894
+ // fire AFTER pointerup, so a synchronous clear here would misread a tap
895
+ // as keyboard focus. The deferred clear runs after the whole tap
896
+ // sequence settled.
897
+ if (this.pointerClearTimer !== null) {
898
+ clearTimeout(this.pointerClearTimer);
899
+ }
900
+ this.pointerClearTimer = setTimeout(() => {
901
+ this.pointerActive = false;
902
+ this.pointerClearTimer = null;
903
+ }, 0);
904
+ };
905
+ constructor() {
906
+ inject(DestroyRef).onDestroy(() => {
907
+ this.doc.removeEventListener('pointerup', this.schedulePointerClear, true);
908
+ if (this.pointerClearTimer !== null) {
909
+ clearTimeout(this.pointerClearTimer);
910
+ }
911
+ });
912
+ }
913
+ /** @internal Arms the pointer flag for the imminent focusin. */
914
+ handlePointerDown() {
915
+ // A pending clear from the previous release must not fire mid-press.
916
+ if (this.pointerClearTimer !== null) {
917
+ clearTimeout(this.pointerClearTimer);
918
+ this.pointerClearTimer = null;
919
+ }
920
+ this.pointerActive = true;
921
+ // The flag must not outlive the click: a pointerdown that never focuses
922
+ // (disabled child, text selection, drag released off-host) would
923
+ // otherwise suppress the ring on the NEXT keyboard Tab-in. Document-level
924
+ // capture catches the release wherever it lands.
925
+ this.doc.addEventListener('pointerup', this.schedulePointerClear, {
926
+ once: true,
927
+ capture: true,
928
+ });
929
+ }
602
930
  /** @internal Sets focus-visible state; clears pointer flag. */
603
931
  handleFocus() {
604
932
  this.focusVisibleState.set(!this.pointerActive);
@@ -609,7 +937,7 @@ class CngxFocusVisible {
609
937
  this.focusVisibleState.set(false);
610
938
  }
611
939
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusVisible, deps: [], target: i0.ɵɵFactoryTarget.Directive });
612
- 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 });
940
+ 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 });
613
941
  }
614
942
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFocusVisible, decorators: [{
615
943
  type: Directive,
@@ -618,13 +946,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
618
946
  exportAs: 'cngxFocusVisible',
619
947
  standalone: true,
620
948
  host: {
621
- '(pointerdown)': 'pointerActive = true',
949
+ '(pointerdown)': 'handlePointerDown()',
622
950
  '(focusin)': 'handleFocus()',
623
951
  '(focusout)': 'handleBlur()',
624
952
  '[class.cngx-focus-visible]': 'focusVisible()',
625
953
  },
626
954
  }]
627
- }] });
955
+ }], ctorParameters: () => [] });
628
956
 
629
957
  /**
630
958
  * Marker directive for items managed by `CngxRovingTabindex`.
@@ -642,7 +970,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
642
970
  * ```
643
971
  *
644
972
  * @category common/a11y
645
- * @docsKind primary
646
973
  * @wcag AA
647
974
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/roving/roving-tabindex.directive.ts
648
975
  * @since 0.1.0
@@ -941,20 +1268,11 @@ class CngxRovingTabindex {
941
1268
  }
942
1269
  /**
943
1270
  * Finds the next index in virtual mode. No disabled-item skipping - can't check
944
- * disabled state of items not in the DOM.
1271
+ * disabled state of items not in the DOM (the resolver treats every index as
1272
+ * enabled when no `isDisabledAt` is supplied).
945
1273
  */
946
1274
  findNextVirtual(current, total, direction) {
947
- if (total === 0) {
948
- return null;
949
- }
950
- const idx = current + direction;
951
- if (this.loop()) {
952
- return ((idx % total) + total) % total;
953
- }
954
- if (idx < 0 || idx >= total) {
955
- return null;
956
- }
957
- return idx;
1275
+ return resolveStepFrom(current, direction, { count: total, loop: this.loop() });
958
1276
  }
959
1277
  enabledItems() {
960
1278
  return this.items().filter((item) => !item.disabled());
@@ -973,37 +1291,23 @@ class CngxRovingTabindex {
973
1291
  * Skips disabled items.
974
1292
  */
975
1293
  findNext(current, items, direction) {
976
- const len = items.length;
977
- if (len === 0) {
978
- return null;
979
- }
980
- let idx = current + direction;
981
- const loop = this.loop();
982
- for (let i = 0; i < len; i++) {
983
- if (loop) {
984
- idx = ((idx % len) + len) % len;
985
- }
986
- else if (idx < 0 || idx >= len) {
987
- return null;
988
- }
989
- if (!items[idx].disabled()) {
990
- return idx;
991
- }
992
- idx += direction;
993
- }
994
- return null;
1294
+ return resolveStepFrom(current, direction, {
1295
+ count: items.length,
1296
+ loop: this.loop(),
1297
+ isDisabledAt: (i) => items[i].disabled(),
1298
+ });
995
1299
  }
996
1300
  findFirst(items) {
997
- const idx = items.findIndex((item) => !item.disabled());
998
- return idx >= 0 ? idx : null;
1301
+ return resolveBoundaryStep(1, {
1302
+ count: items.length,
1303
+ isDisabledAt: (i) => items[i].disabled(),
1304
+ });
999
1305
  }
1000
1306
  findLast(items) {
1001
- for (let i = items.length - 1; i >= 0; i--) {
1002
- if (!items[i].disabled()) {
1003
- return i;
1004
- }
1005
- }
1006
- return null;
1307
+ return resolveBoundaryStep(-1, {
1308
+ count: items.length,
1309
+ isDisabledAt: (i) => items[i].disabled(),
1310
+ });
1007
1311
  }
1008
1312
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRovingTabindex, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1009
1313
  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 });
@@ -1118,18 +1422,35 @@ class CngxActiveDescendant {
1118
1422
  * Ignored when `virtualCount` is unset.
1119
1423
  */
1120
1424
  windowStart = input(0, ...(ngDevMode ? [{ debugName: "windowStart" }] : /* istanbul ignore next */ []));
1425
+ /**
1426
+ * Equality used to find the previously active value again after the item
1427
+ * list changes. Defaults to `Object.is`; pass the same comparator as the
1428
+ * surrounding listbox / select when options are re-fetched as new objects
1429
+ * with equal identity, or the highlight drops on every refresh. The
1430
+ * parameters are typed `never` so a comparator over any value type binds
1431
+ * while the directive itself stays non-generic.
1432
+ */
1433
+ compareWith = input(Object.is, ...(ngDevMode ? [{ debugName: "compareWith" }] : /* istanbul ignore next */ []));
1121
1434
  /** Emitted when `activateCurrent()` is called with an active item. */
1122
1435
  activated = output();
1123
1436
  /** Emitted whenever the highlighted item changes. */
1124
1437
  highlighted = output();
1438
+ /**
1439
+ * Emitted when a typeahead query finds no match in the rendered window.
1440
+ * Carries the resolved query term (lowercased; a repeated single letter
1441
+ * collapses to that letter per the APG cycle rule). The rendered window
1442
+ * is AD's whole search space - hosts whose real item space is larger
1443
+ * (collapsed tree branches, virtualized rows outside the window) listen
1444
+ * here to resolve the miss themselves.
1445
+ */
1446
+ typeaheadMissed = output();
1125
1447
  hostEl = inject((ElementRef));
1448
+ locale = injectLocale();
1126
1449
  registered = contentChildren(CNGX_AD_ITEM, { ...(ngDevMode ? { debugName: "registered" } : /* istanbul ignore next */ {}), descendants: true });
1127
1450
  /** Document writing direction - flips the horizontal-arrow steps under `rtl` (APG). */
1128
1451
  direction = injectDirection();
1129
1452
  /** Guards host attribute writes until after first render. */
1130
1453
  initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
1131
- /** -1 means "no active item". Range is [0, resolvedItems().length). */
1132
- activeIndexState = signal(-1, ...(ngDevMode ? [{ debugName: "activeIndexState" }] : /* istanbul ignore next */ []));
1133
1454
  /** Index of an item that should be highlighted but is not in the DOM. */
1134
1455
  pendingHighlightState = signal(null, ...(ngDevMode ? [{ debugName: "pendingHighlightState" }] : /* istanbul ignore next */ []));
1135
1456
  pendingHighlight = this.pendingHighlightState.asReadonly();
@@ -1144,6 +1465,29 @@ class CngxActiveDescendant {
1144
1465
  }
1145
1466
  return this.registered().map(handleToItem);
1146
1467
  }, ...(ngDevMode ? [{ debugName: "resolvedItems" }] : /* istanbul ignore next */ []));
1468
+ /**
1469
+ * -1 means "no active item". Range is `[0, totalCount())`.
1470
+ *
1471
+ * Navigation writes the index; a change of the item space re-derives it.
1472
+ * The highlight follows its value, not its index: after the item list
1473
+ * changes, the previously active value is looked up again with
1474
+ * `compareWith`. Gone from a plain list means no highlight; in a virtual
1475
+ * window a value that merely scrolled out keeps its absolute index. The result is clamped to the new
1476
+ * item space, so the next arrow press never starts from a ghost index.
1477
+ */
1478
+ activeIndexState = linkedSignal({ ...(ngDevMode ? { debugName: "activeIndexState" } : /* istanbul ignore next */ {}), source: () => ({
1479
+ items: this.resolvedItems(),
1480
+ total: this.totalCount(),
1481
+ offset: this.windowOffset(),
1482
+ virtual: this.virtualCount() != null,
1483
+ compareWith: this.compareWith(),
1484
+ }),
1485
+ computation: (source, previous) => {
1486
+ if (!previous) {
1487
+ return -1;
1488
+ }
1489
+ return clampIndex(reResolveIndex(source, previous.source, previous.value), source.total);
1490
+ } });
1147
1491
  /** Current active index. `-1` when no item is highlighted. */
1148
1492
  activeIndex = computed(() => {
1149
1493
  const idx = this.activeIndexState();
@@ -1210,16 +1554,6 @@ class CngxActiveDescendant {
1210
1554
  }
1211
1555
  queueMicrotask(() => this.scrollActiveIntoView());
1212
1556
  });
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
- });
1223
1557
  inject(DestroyRef).onDestroy(() => {
1224
1558
  if (this.typeaheadTimer !== null) {
1225
1559
  clearTimeout(this.typeaheadTimer);
@@ -1396,7 +1730,8 @@ class CngxActiveDescendant {
1396
1730
  this.handleTypeahead(ch);
1397
1731
  }
1398
1732
  handleTypeahead(ch) {
1399
- const next = this.typeaheadBuffer() + ch.toLowerCase();
1733
+ const locale = this.locale();
1734
+ const next = this.typeaheadBuffer() + ch.toLocaleLowerCase(locale);
1400
1735
  this.typeaheadBuffer.set(next);
1401
1736
  if (this.typeaheadTimer !== null) {
1402
1737
  clearTimeout(this.typeaheadTimer);
@@ -1410,80 +1745,52 @@ class CngxActiveDescendant {
1410
1745
  const items = this.resolvedItems();
1411
1746
  const skip = this.skipDisabled();
1412
1747
  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
1748
  // APG cycle: a single-character query (including a repeated letter, whose
1419
1749
  // buffer collapses back to that letter) searches AFTER the active item so
1420
1750
  // each press advances through the matches. A genuine multi-character query
1421
1751
  // keeps matching the current item first.
1422
1752
  const sameChar = next.length > 1 && [...next].every((c) => c === next[0]);
1423
1753
  const term = sameChar ? next[0] : next;
1754
+ if (count === 0) {
1755
+ this.typeaheadMissed.emit(term);
1756
+ return;
1757
+ }
1758
+ const windowOffset = this.windowOffset();
1759
+ const activeRel = this.activeIndexState() < 0 ? -1 : this.activeIndexState() - windowOffset;
1424
1760
  const cycles = term.length === 1;
1425
1761
  const startRel = cycles ? activeRel + 1 : Math.max(0, activeRel);
1762
+ const matches = createTypeaheadMatcher(term, locale);
1426
1763
  for (let step = 0; step < count; step++) {
1427
1764
  const rel = (((startRel + step) % count) + count) % count;
1428
1765
  const candidate = items[rel];
1429
1766
  if (skip && candidate.disabled) {
1430
1767
  continue;
1431
1768
  }
1432
- if (candidate.label.toLowerCase().startsWith(term)) {
1769
+ if (matches(candidate.label, candidate)) {
1433
1770
  this.activeIndexState.set(rel + windowOffset);
1434
1771
  return;
1435
1772
  }
1436
1773
  }
1774
+ this.typeaheadMissed.emit(term);
1437
1775
  }
1438
1776
  findFrom(current, direction) {
1439
- const total = this.totalCount();
1440
- if (total === 0) {
1441
- return null;
1442
- }
1443
- const skip = this.skipDisabled();
1444
- const loop = this.loop();
1445
- let idx = current < 0 ? (direction === 1 ? -1 : total) : current;
1446
- for (let step = 0; step < total; step++) {
1447
- idx += direction;
1448
- if (idx < 0 || idx >= total) {
1449
- if (!loop) {
1450
- return null;
1451
- }
1452
- idx = ((idx % total) + total) % total;
1453
- }
1454
- if (!skip || !this.isDisabledAt(idx)) {
1455
- return idx;
1456
- }
1457
- }
1458
- return null;
1777
+ return resolveStepFrom(current, direction, {
1778
+ count: this.totalCount(),
1779
+ loop: this.loop(),
1780
+ isDisabledAt: this.skipDisabled() ? (i) => this.isDisabledAt(i) : undefined,
1781
+ });
1459
1782
  }
1460
1783
  /**
1461
1784
  * First/last navigable absolute index. Spans the full virtual range - End
1462
1785
  * targets `totalCount - 1` even when that item is not rendered (it surfaces
1463
1786
  * as `pendingHighlight`); unrendered items count as enabled because their
1464
- * disabled state is unknowable.
1787
+ * disabled state is unknowable (`isDisabledAt` resolves them to `false`).
1465
1788
  */
1466
1789
  findBoundary(direction) {
1467
- const total = this.totalCount();
1468
- if (total === 0) {
1469
- return null;
1470
- }
1471
- const skip = this.skipDisabled();
1472
- if (direction === 1) {
1473
- for (let i = 0; i < total; i++) {
1474
- if (!skip || !this.isDisabledAt(i)) {
1475
- return i;
1476
- }
1477
- }
1478
- }
1479
- else {
1480
- for (let i = total - 1; i >= 0; i--) {
1481
- if (!skip || !this.isDisabledAt(i)) {
1482
- return i;
1483
- }
1484
- }
1485
- }
1486
- return null;
1790
+ return resolveBoundaryStep(direction, {
1791
+ count: this.totalCount(),
1792
+ isDisabledAt: this.skipDisabled() ? (i) => this.isDisabledAt(i) : undefined,
1793
+ });
1487
1794
  }
1488
1795
  totalCount() {
1489
1796
  const vc = this.virtualCount();
@@ -1525,7 +1832,7 @@ class CngxActiveDescendant {
1525
1832
  }
1526
1833
  }
1527
1834
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, deps: [], target: i0.ɵɵFactoryTarget.Directive });
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 });
1835
+ 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 }, compareWith: { classPropertyName: "compareWith", publicName: "compareWith", 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 });
1529
1836
  }
1530
1837
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxActiveDescendant, decorators: [{
1531
1838
  type: Directive,
@@ -1538,7 +1845,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1538
1845
  '(keydown)': 'handleKeydown($event)',
1539
1846
  },
1540
1847
  }]
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 }] }] } });
1848
+ }], 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 }] }], compareWith: [{ type: i0.Input, args: [{ isSignal: true, alias: "compareWith", 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 }] }] } });
1849
+ /**
1850
+ * @internal
1851
+ * Looks the previously active value up in the new item list. Unchanged items,
1852
+ * no previous highlight, or a previous index outside the old rendered window
1853
+ * keep the index as it is.
1854
+ */
1855
+ function reResolveIndex(source, previousSource, previousIndex) {
1856
+ if (previousSource.items === source.items || previousIndex < 0) {
1857
+ return previousIndex;
1858
+ }
1859
+ const previous = previousSource.items[previousIndex - previousSource.offset];
1860
+ if (!previous) {
1861
+ return previousIndex;
1862
+ }
1863
+ const match = source.items.findIndex((it) => source.compareWith(it.value, previous.value));
1864
+ if (match >= 0) {
1865
+ return match + source.offset;
1866
+ }
1867
+ return source.virtual ? previousIndex : -1;
1868
+ }
1869
+ /** @internal Pulls an index that ran past the item space back onto its last item. */
1870
+ function clampIndex(index, total) {
1871
+ if (index < total) {
1872
+ return index;
1873
+ }
1874
+ return total > 0 ? total - 1 : -1;
1875
+ }
1542
1876
  /** @internal */
1543
1877
  function handleToItem(handle) {
1544
1878
  return {
@@ -1617,7 +1951,6 @@ function cssEscape(id) {
1617
1951
  * ```
1618
1952
  *
1619
1953
  * @category common/a11y
1620
- * @docsKind primary
1621
1954
  * @wcag AA
1622
1955
  * @github https://github.com/cngxjs/cngx/blob/main/projects/common/a11y/motion/reduced-motion.directive.ts
1623
1956
  * @since 0.1.0
@@ -1651,5 +1984,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1651
1984
  * Generated bundle index. Do not edit.
1652
1985
  */
1653
1986
 
1654
- export { CNGX_AD_ITEM, CNGX_FOCUSABLE_SELECTOR, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveAnnouncer, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex };
1987
+ export { CNGX_AD_ITEM, CNGX_FOCUSABLE_SELECTOR, CNGX_FOCUS_TRAP_DRIVER, CngxActiveDescendant, CngxAriaExpanded, CngxAutofocus, CngxFocusRestore, CngxFocusTrap, CngxFocusVisible, CngxLiveAnnouncer, CngxLiveRegion, CngxReducedMotion, CngxRovingItem, CngxRovingTabindex, injectScopedLiveRegion };
1655
1988
  //# sourceMappingURL=cngx-common-a11y.mjs.map