1 | import { DOCUMENT } from '@angular/common';
|
2 | import * as i0 from '@angular/core';
|
3 | import { inject, APP_ID, Injectable, Inject, QueryList, Directive, Input, InjectionToken, Optional, EventEmitter, Output, NgModule } from '@angular/core';
|
4 | import * as i1 from '@angular/cdk/platform';
|
5 | import { _getFocusedElementPierceShadowDom, normalizePassiveListenerOptions, _getEventTarget, _getShadowRoot } from '@angular/cdk/platform';
|
6 | import { Subject, Subscription, BehaviorSubject, of } from 'rxjs';
|
7 | import { hasModifierKey, A, Z, ZERO, NINE, END, HOME, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, TAB, ALT, CONTROL, MAC_META, META, SHIFT } from '@angular/cdk/keycodes';
|
8 | import { tap, debounceTime, filter, map, take, skip, distinctUntilChanged, takeUntil } from 'rxjs/operators';
|
9 | import { coerceBooleanProperty, coerceElement } from '@angular/cdk/coercion';
|
10 | import * as i1$1 from '@angular/cdk/observers';
|
11 | import { ObserversModule } from '@angular/cdk/observers';
|
12 | import { BreakpointObserver } from '@angular/cdk/layout';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | const ID_DELIMITER = ' ';
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function addAriaReferencedId(el, attr, id) {
|
28 | const ids = getAriaReferenceIds(el, attr);
|
29 | if (ids.some(existingId => existingId.trim() == id.trim())) {
|
30 | return;
|
31 | }
|
32 | ids.push(id.trim());
|
33 | el.setAttribute(attr, ids.join(ID_DELIMITER));
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function removeAriaReferencedId(el, attr, id) {
|
40 | const ids = getAriaReferenceIds(el, attr);
|
41 | const filteredIds = ids.filter(val => val != id.trim());
|
42 | if (filteredIds.length) {
|
43 | el.setAttribute(attr, filteredIds.join(ID_DELIMITER));
|
44 | }
|
45 | else {
|
46 | el.removeAttribute(attr);
|
47 | }
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | function getAriaReferenceIds(el, attr) {
|
54 |
|
55 | return (el.getAttribute(attr) || '').match(/\S+/g) || [];
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | const MESSAGES_CONTAINER_ID = 'cdk-describedby-message-container';
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | const CDK_DESCRIBEDBY_ID_PREFIX = 'cdk-describedby-message';
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | const CDK_DESCRIBEDBY_HOST_ATTRIBUTE = 'cdk-describedby-host';
|
83 |
|
84 | let nextId = 0;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | class AriaDescriber {
|
91 | constructor(_document,
|
92 | /**
|
93 | * @deprecated To be turned into a required parameter.
|
94 | * @breaking-change 14.0.0
|
95 | */
|
96 | _platform) {
|
97 | this._platform = _platform;
|
98 |
|
99 | this._messageRegistry = new Map();
|
100 |
|
101 | this._messagesContainer = null;
|
102 |
|
103 | this._id = `${nextId++}`;
|
104 | this._document = _document;
|
105 | this._id = inject(APP_ID) + '-' + nextId++;
|
106 | }
|
107 | describe(hostElement, message, role) {
|
108 | if (!this._canBeDescribed(hostElement, message)) {
|
109 | return;
|
110 | }
|
111 | const key = getKey(message, role);
|
112 | if (typeof message !== 'string') {
|
113 |
|
114 | setMessageId(message, this._id);
|
115 | this._messageRegistry.set(key, { messageElement: message, referenceCount: 0 });
|
116 | }
|
117 | else if (!this._messageRegistry.has(key)) {
|
118 | this._createMessageElement(message, role);
|
119 | }
|
120 | if (!this._isElementDescribedByMessage(hostElement, key)) {
|
121 | this._addMessageReference(hostElement, key);
|
122 | }
|
123 | }
|
124 | removeDescription(hostElement, message, role) {
|
125 | if (!message || !this._isElementNode(hostElement)) {
|
126 | return;
|
127 | }
|
128 | const key = getKey(message, role);
|
129 | if (this._isElementDescribedByMessage(hostElement, key)) {
|
130 | this._removeMessageReference(hostElement, key);
|
131 | }
|
132 |
|
133 |
|
134 | if (typeof message === 'string') {
|
135 | const registeredMessage = this._messageRegistry.get(key);
|
136 | if (registeredMessage && registeredMessage.referenceCount === 0) {
|
137 | this._deleteMessageElement(key);
|
138 | }
|
139 | }
|
140 | if (this._messagesContainer?.childNodes.length === 0) {
|
141 | this._messagesContainer.remove();
|
142 | this._messagesContainer = null;
|
143 | }
|
144 | }
|
145 |
|
146 | ngOnDestroy() {
|
147 | const describedElements = this._document.querySelectorAll(`[${CDK_DESCRIBEDBY_HOST_ATTRIBUTE}="${this._id}"]`);
|
148 | for (let i = 0; i < describedElements.length; i++) {
|
149 | this._removeCdkDescribedByReferenceIds(describedElements[i]);
|
150 | describedElements[i].removeAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE);
|
151 | }
|
152 | this._messagesContainer?.remove();
|
153 | this._messagesContainer = null;
|
154 | this._messageRegistry.clear();
|
155 | }
|
156 | |
157 |
|
158 |
|
159 |
|
160 | _createMessageElement(message, role) {
|
161 | const messageElement = this._document.createElement('div');
|
162 | setMessageId(messageElement, this._id);
|
163 | messageElement.textContent = message;
|
164 | if (role) {
|
165 | messageElement.setAttribute('role', role);
|
166 | }
|
167 | this._createMessagesContainer();
|
168 | this._messagesContainer.appendChild(messageElement);
|
169 | this._messageRegistry.set(getKey(message, role), { messageElement, referenceCount: 0 });
|
170 | }
|
171 |
|
172 | _deleteMessageElement(key) {
|
173 | this._messageRegistry.get(key)?.messageElement?.remove();
|
174 | this._messageRegistry.delete(key);
|
175 | }
|
176 |
|
177 | _createMessagesContainer() {
|
178 | if (this._messagesContainer) {
|
179 | return;
|
180 | }
|
181 | const containerClassName = 'cdk-describedby-message-container';
|
182 | const serverContainers = this._document.querySelectorAll(`.${containerClassName}[platform="server"]`);
|
183 | for (let i = 0; i < serverContainers.length; i++) {
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | serverContainers[i].remove();
|
189 | }
|
190 | const messagesContainer = this._document.createElement('div');
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | messagesContainer.style.visibility = 'hidden';
|
196 |
|
197 |
|
198 | messagesContainer.classList.add(containerClassName);
|
199 | messagesContainer.classList.add('cdk-visually-hidden');
|
200 |
|
201 | if (this._platform && !this._platform.isBrowser) {
|
202 | messagesContainer.setAttribute('platform', 'server');
|
203 | }
|
204 | this._document.body.appendChild(messagesContainer);
|
205 | this._messagesContainer = messagesContainer;
|
206 | }
|
207 |
|
208 | _removeCdkDescribedByReferenceIds(element) {
|
209 |
|
210 | const originalReferenceIds = getAriaReferenceIds(element, 'aria-describedby').filter(id => id.indexOf(CDK_DESCRIBEDBY_ID_PREFIX) != 0);
|
211 | element.setAttribute('aria-describedby', originalReferenceIds.join(' '));
|
212 | }
|
213 | |
214 |
|
215 |
|
216 |
|
217 | _addMessageReference(element, key) {
|
218 | const registeredMessage = this._messageRegistry.get(key);
|
219 |
|
220 |
|
221 | addAriaReferencedId(element, 'aria-describedby', registeredMessage.messageElement.id);
|
222 | element.setAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE, this._id);
|
223 | registeredMessage.referenceCount++;
|
224 | }
|
225 | |
226 |
|
227 |
|
228 |
|
229 | _removeMessageReference(element, key) {
|
230 | const registeredMessage = this._messageRegistry.get(key);
|
231 | registeredMessage.referenceCount--;
|
232 | removeAriaReferencedId(element, 'aria-describedby', registeredMessage.messageElement.id);
|
233 | element.removeAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE);
|
234 | }
|
235 |
|
236 | _isElementDescribedByMessage(element, key) {
|
237 | const referenceIds = getAriaReferenceIds(element, 'aria-describedby');
|
238 | const registeredMessage = this._messageRegistry.get(key);
|
239 | const messageId = registeredMessage && registeredMessage.messageElement.id;
|
240 | return !!messageId && referenceIds.indexOf(messageId) != -1;
|
241 | }
|
242 |
|
243 | _canBeDescribed(element, message) {
|
244 | if (!this._isElementNode(element)) {
|
245 | return false;
|
246 | }
|
247 | if (message && typeof message === 'object') {
|
248 |
|
249 |
|
250 |
|
251 | return true;
|
252 | }
|
253 | const trimmedMessage = message == null ? '' : `${message}`.trim();
|
254 | const ariaLabel = element.getAttribute('aria-label');
|
255 |
|
256 |
|
257 | return trimmedMessage ? !ariaLabel || ariaLabel.trim() !== trimmedMessage : false;
|
258 | }
|
259 |
|
260 | _isElementNode(element) {
|
261 | return element.nodeType === this._document.ELEMENT_NODE;
|
262 | }
|
263 | }
|
264 | AriaDescriber.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: AriaDescriber, deps: [{ token: DOCUMENT }, { token: i1.Platform }], target: i0.ɵɵFactoryTarget.Injectable });
|
265 | AriaDescriber.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: AriaDescriber, providedIn: 'root' });
|
266 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: AriaDescriber, decorators: [{
|
267 | type: Injectable,
|
268 | args: [{ providedIn: 'root' }]
|
269 | }], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
270 | type: Inject,
|
271 | args: [DOCUMENT]
|
272 | }] }, { type: i1.Platform }]; } });
|
273 |
|
274 | function getKey(message, role) {
|
275 | return typeof message === 'string' ? `${role || ''}/${message}` : message;
|
276 | }
|
277 |
|
278 | function setMessageId(element, serviceId) {
|
279 | if (!element.id) {
|
280 | element.id = `${CDK_DESCRIBEDBY_ID_PREFIX}-${serviceId}-${nextId++}`;
|
281 | }
|
282 | }
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 | class ListKeyManager {
|
296 | constructor(_items) {
|
297 | this._items = _items;
|
298 | this._activeItemIndex = -1;
|
299 | this._activeItem = null;
|
300 | this._wrap = false;
|
301 | this._letterKeyStream = new Subject();
|
302 | this._typeaheadSubscription = Subscription.EMPTY;
|
303 | this._vertical = true;
|
304 | this._allowedModifierKeys = [];
|
305 | this._homeAndEnd = false;
|
306 | |
307 |
|
308 |
|
309 |
|
310 | this._skipPredicateFn = (item) => item.disabled;
|
311 |
|
312 | this._pressedLetters = [];
|
313 | |
314 |
|
315 |
|
316 |
|
317 | this.tabOut = new Subject();
|
318 |
|
319 | this.change = new Subject();
|
320 |
|
321 |
|
322 |
|
323 | if (_items instanceof QueryList) {
|
324 | _items.changes.subscribe((newItems) => {
|
325 | if (this._activeItem) {
|
326 | const itemArray = newItems.toArray();
|
327 | const newIndex = itemArray.indexOf(this._activeItem);
|
328 | if (newIndex > -1 && newIndex !== this._activeItemIndex) {
|
329 | this._activeItemIndex = newIndex;
|
330 | }
|
331 | }
|
332 | });
|
333 | }
|
334 | }
|
335 | |
336 |
|
337 |
|
338 |
|
339 |
|
340 | skipPredicate(predicate) {
|
341 | this._skipPredicateFn = predicate;
|
342 | return this;
|
343 | }
|
344 | |
345 |
|
346 |
|
347 |
|
348 |
|
349 | withWrap(shouldWrap = true) {
|
350 | this._wrap = shouldWrap;
|
351 | return this;
|
352 | }
|
353 | |
354 |
|
355 |
|
356 |
|
357 | withVerticalOrientation(enabled = true) {
|
358 | this._vertical = enabled;
|
359 | return this;
|
360 | }
|
361 | |
362 |
|
363 |
|
364 |
|
365 |
|
366 | withHorizontalOrientation(direction) {
|
367 | this._horizontal = direction;
|
368 | return this;
|
369 | }
|
370 | |
371 |
|
372 |
|
373 |
|
374 | withAllowedModifierKeys(keys) {
|
375 | this._allowedModifierKeys = keys;
|
376 | return this;
|
377 | }
|
378 | |
379 |
|
380 |
|
381 |
|
382 | withTypeAhead(debounceInterval = 200) {
|
383 | if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
|
384 | this._items.length &&
|
385 | this._items.some(item => typeof item.getLabel !== 'function')) {
|
386 | throw Error('ListKeyManager items in typeahead mode must implement the `getLabel` method.');
|
387 | }
|
388 | this._typeaheadSubscription.unsubscribe();
|
389 |
|
390 |
|
391 |
|
392 | this._typeaheadSubscription = this._letterKeyStream
|
393 | .pipe(tap(letter => this._pressedLetters.push(letter)), debounceTime(debounceInterval), filter(() => this._pressedLetters.length > 0), map(() => this._pressedLetters.join('')))
|
394 | .subscribe(inputString => {
|
395 | const items = this._getItemsArray();
|
396 |
|
397 |
|
398 | for (let i = 1; i < items.length + 1; i++) {
|
399 | const index = (this._activeItemIndex + i) % items.length;
|
400 | const item = items[index];
|
401 | if (!this._skipPredicateFn(item) &&
|
402 | item.getLabel().toUpperCase().trim().indexOf(inputString) === 0) {
|
403 | this.setActiveItem(index);
|
404 | break;
|
405 | }
|
406 | }
|
407 | this._pressedLetters = [];
|
408 | });
|
409 | return this;
|
410 | }
|
411 | |
412 |
|
413 |
|
414 |
|
415 |
|
416 | withHomeAndEnd(enabled = true) {
|
417 | this._homeAndEnd = enabled;
|
418 | return this;
|
419 | }
|
420 | setActiveItem(item) {
|
421 | const previousActiveItem = this._activeItem;
|
422 | this.updateActiveItem(item);
|
423 | if (this._activeItem !== previousActiveItem) {
|
424 | this.change.next(this._activeItemIndex);
|
425 | }
|
426 | }
|
427 | |
428 |
|
429 |
|
430 |
|
431 | onKeydown(event) {
|
432 | const keyCode = event.keyCode;
|
433 | const modifiers = ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'];
|
434 | const isModifierAllowed = modifiers.every(modifier => {
|
435 | return !event[modifier] || this._allowedModifierKeys.indexOf(modifier) > -1;
|
436 | });
|
437 | switch (keyCode) {
|
438 | case TAB:
|
439 | this.tabOut.next();
|
440 | return;
|
441 | case DOWN_ARROW:
|
442 | if (this._vertical && isModifierAllowed) {
|
443 | this.setNextItemActive();
|
444 | break;
|
445 | }
|
446 | else {
|
447 | return;
|
448 | }
|
449 | case UP_ARROW:
|
450 | if (this._vertical && isModifierAllowed) {
|
451 | this.setPreviousItemActive();
|
452 | break;
|
453 | }
|
454 | else {
|
455 | return;
|
456 | }
|
457 | case RIGHT_ARROW:
|
458 | if (this._horizontal && isModifierAllowed) {
|
459 | this._horizontal === 'rtl' ? this.setPreviousItemActive() : this.setNextItemActive();
|
460 | break;
|
461 | }
|
462 | else {
|
463 | return;
|
464 | }
|
465 | case LEFT_ARROW:
|
466 | if (this._horizontal && isModifierAllowed) {
|
467 | this._horizontal === 'rtl' ? this.setNextItemActive() : this.setPreviousItemActive();
|
468 | break;
|
469 | }
|
470 | else {
|
471 | return;
|
472 | }
|
473 | case HOME:
|
474 | if (this._homeAndEnd && isModifierAllowed) {
|
475 | this.setFirstItemActive();
|
476 | break;
|
477 | }
|
478 | else {
|
479 | return;
|
480 | }
|
481 | case END:
|
482 | if (this._homeAndEnd && isModifierAllowed) {
|
483 | this.setLastItemActive();
|
484 | break;
|
485 | }
|
486 | else {
|
487 | return;
|
488 | }
|
489 | default:
|
490 | if (isModifierAllowed || hasModifierKey(event, 'shiftKey')) {
|
491 |
|
492 |
|
493 | if (event.key && event.key.length === 1) {
|
494 | this._letterKeyStream.next(event.key.toLocaleUpperCase());
|
495 | }
|
496 | else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
|
497 | this._letterKeyStream.next(String.fromCharCode(keyCode));
|
498 | }
|
499 | }
|
500 |
|
501 |
|
502 | return;
|
503 | }
|
504 | this._pressedLetters = [];
|
505 | event.preventDefault();
|
506 | }
|
507 |
|
508 | get activeItemIndex() {
|
509 | return this._activeItemIndex;
|
510 | }
|
511 |
|
512 | get activeItem() {
|
513 | return this._activeItem;
|
514 | }
|
515 |
|
516 | isTyping() {
|
517 | return this._pressedLetters.length > 0;
|
518 | }
|
519 |
|
520 | setFirstItemActive() {
|
521 | this._setActiveItemByIndex(0, 1);
|
522 | }
|
523 |
|
524 | setLastItemActive() {
|
525 | this._setActiveItemByIndex(this._items.length - 1, -1);
|
526 | }
|
527 |
|
528 | setNextItemActive() {
|
529 | this._activeItemIndex < 0 ? this.setFirstItemActive() : this._setActiveItemByDelta(1);
|
530 | }
|
531 |
|
532 | setPreviousItemActive() {
|
533 | this._activeItemIndex < 0 && this._wrap
|
534 | ? this.setLastItemActive()
|
535 | : this._setActiveItemByDelta(-1);
|
536 | }
|
537 | updateActiveItem(item) {
|
538 | const itemArray = this._getItemsArray();
|
539 | const index = typeof item === 'number' ? item : itemArray.indexOf(item);
|
540 | const activeItem = itemArray[index];
|
541 |
|
542 | this._activeItem = activeItem == null ? null : activeItem;
|
543 | this._activeItemIndex = index;
|
544 | }
|
545 | |
546 |
|
547 |
|
548 |
|
549 |
|
550 | _setActiveItemByDelta(delta) {
|
551 | this._wrap ? this._setActiveInWrapMode(delta) : this._setActiveInDefaultMode(delta);
|
552 | }
|
553 | |
554 |
|
555 |
|
556 |
|
557 |
|
558 | _setActiveInWrapMode(delta) {
|
559 | const items = this._getItemsArray();
|
560 | for (let i = 1; i <= items.length; i++) {
|
561 | const index = (this._activeItemIndex + delta * i + items.length) % items.length;
|
562 | const item = items[index];
|
563 | if (!this._skipPredicateFn(item)) {
|
564 | this.setActiveItem(index);
|
565 | return;
|
566 | }
|
567 | }
|
568 | }
|
569 | |
570 |
|
571 |
|
572 |
|
573 |
|
574 | _setActiveInDefaultMode(delta) {
|
575 | this._setActiveItemByIndex(this._activeItemIndex + delta, delta);
|
576 | }
|
577 | |
578 |
|
579 |
|
580 |
|
581 |
|
582 | _setActiveItemByIndex(index, fallbackDelta) {
|
583 | const items = this._getItemsArray();
|
584 | if (!items[index]) {
|
585 | return;
|
586 | }
|
587 | while (this._skipPredicateFn(items[index])) {
|
588 | index += fallbackDelta;
|
589 | if (!items[index]) {
|
590 | return;
|
591 | }
|
592 | }
|
593 | this.setActiveItem(index);
|
594 | }
|
595 |
|
596 | _getItemsArray() {
|
597 | return this._items instanceof QueryList ? this._items.toArray() : this._items;
|
598 | }
|
599 | }
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 | class ActiveDescendantKeyManager extends ListKeyManager {
|
609 | setActiveItem(index) {
|
610 | if (this.activeItem) {
|
611 | this.activeItem.setInactiveStyles();
|
612 | }
|
613 | super.setActiveItem(index);
|
614 | if (this.activeItem) {
|
615 | this.activeItem.setActiveStyles();
|
616 | }
|
617 | }
|
618 | }
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 | class FocusKeyManager extends ListKeyManager {
|
628 | constructor() {
|
629 | super(...arguments);
|
630 | this._origin = 'program';
|
631 | }
|
632 | |
633 |
|
634 |
|
635 |
|
636 | setFocusOrigin(origin) {
|
637 | this._origin = origin;
|
638 | return this;
|
639 | }
|
640 | setActiveItem(item) {
|
641 | super.setActiveItem(item);
|
642 | if (this.activeItem) {
|
643 | this.activeItem.focus(this._origin);
|
644 | }
|
645 | }
|
646 | }
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 | class IsFocusableConfig {
|
659 | constructor() {
|
660 | |
661 |
|
662 |
|
663 | this.ignoreVisibility = false;
|
664 | }
|
665 | }
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 | class InteractivityChecker {
|
674 | constructor(_platform) {
|
675 | this._platform = _platform;
|
676 | }
|
677 | |
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 | isDisabled(element) {
|
684 |
|
685 |
|
686 | return element.hasAttribute('disabled');
|
687 | }
|
688 | |
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 | isVisible(element) {
|
697 | return hasGeometry(element) && getComputedStyle(element).visibility === 'visible';
|
698 | }
|
699 | |
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 | isTabbable(element) {
|
707 |
|
708 | if (!this._platform.isBrowser) {
|
709 | return false;
|
710 | }
|
711 | const frameElement = getFrameElement(getWindow(element));
|
712 | if (frameElement) {
|
713 |
|
714 | if (getTabIndexValue(frameElement) === -1) {
|
715 | return false;
|
716 | }
|
717 |
|
718 | if (!this.isVisible(frameElement)) {
|
719 | return false;
|
720 | }
|
721 | }
|
722 | let nodeName = element.nodeName.toLowerCase();
|
723 | let tabIndexValue = getTabIndexValue(element);
|
724 | if (element.hasAttribute('contenteditable')) {
|
725 | return tabIndexValue !== -1;
|
726 | }
|
727 | if (nodeName === 'iframe' || nodeName === 'object') {
|
728 |
|
729 |
|
730 |
|
731 | return false;
|
732 | }
|
733 |
|
734 | if (this._platform.WEBKIT && this._platform.IOS && !isPotentiallyTabbableIOS(element)) {
|
735 | return false;
|
736 | }
|
737 | if (nodeName === 'audio') {
|
738 |
|
739 |
|
740 | if (!element.hasAttribute('controls')) {
|
741 | return false;
|
742 | }
|
743 |
|
744 |
|
745 | return tabIndexValue !== -1;
|
746 | }
|
747 | if (nodeName === 'video') {
|
748 |
|
749 |
|
750 |
|
751 |
|
752 | if (tabIndexValue === -1) {
|
753 | return false;
|
754 | }
|
755 |
|
756 |
|
757 | if (tabIndexValue !== null) {
|
758 | return true;
|
759 | }
|
760 |
|
761 |
|
762 |
|
763 | return this._platform.FIREFOX || element.hasAttribute('controls');
|
764 | }
|
765 | return element.tabIndex >= 0;
|
766 | }
|
767 | |
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 | isFocusable(element, config) {
|
775 |
|
776 |
|
777 | return (isPotentiallyFocusable(element) &&
|
778 | !this.isDisabled(element) &&
|
779 | (config?.ignoreVisibility || this.isVisible(element)));
|
780 | }
|
781 | }
|
782 | InteractivityChecker.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InteractivityChecker, deps: [{ token: i1.Platform }], target: i0.ɵɵFactoryTarget.Injectable });
|
783 | InteractivityChecker.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InteractivityChecker, providedIn: 'root' });
|
784 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InteractivityChecker, decorators: [{
|
785 | type: Injectable,
|
786 | args: [{ providedIn: 'root' }]
|
787 | }], ctorParameters: function () { return [{ type: i1.Platform }]; } });
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 | function getFrameElement(window) {
|
794 | try {
|
795 | return window.frameElement;
|
796 | }
|
797 | catch {
|
798 | return null;
|
799 | }
|
800 | }
|
801 |
|
802 | function hasGeometry(element) {
|
803 |
|
804 |
|
805 | return !!(element.offsetWidth ||
|
806 | element.offsetHeight ||
|
807 | (typeof element.getClientRects === 'function' && element.getClientRects().length));
|
808 | }
|
809 |
|
810 | function isNativeFormElement(element) {
|
811 | let nodeName = element.nodeName.toLowerCase();
|
812 | return (nodeName === 'input' ||
|
813 | nodeName === 'select' ||
|
814 | nodeName === 'button' ||
|
815 | nodeName === 'textarea');
|
816 | }
|
817 |
|
818 | function isHiddenInput(element) {
|
819 | return isInputElement(element) && element.type == 'hidden';
|
820 | }
|
821 |
|
822 | function isAnchorWithHref(element) {
|
823 | return isAnchorElement(element) && element.hasAttribute('href');
|
824 | }
|
825 |
|
826 | function isInputElement(element) {
|
827 | return element.nodeName.toLowerCase() == 'input';
|
828 | }
|
829 |
|
830 | function isAnchorElement(element) {
|
831 | return element.nodeName.toLowerCase() == 'a';
|
832 | }
|
833 |
|
834 | function hasValidTabIndex(element) {
|
835 | if (!element.hasAttribute('tabindex') || element.tabIndex === undefined) {
|
836 | return false;
|
837 | }
|
838 | let tabIndex = element.getAttribute('tabindex');
|
839 | return !!(tabIndex && !isNaN(parseInt(tabIndex, 10)));
|
840 | }
|
841 |
|
842 |
|
843 |
|
844 |
|
845 | function getTabIndexValue(element) {
|
846 | if (!hasValidTabIndex(element)) {
|
847 | return null;
|
848 | }
|
849 |
|
850 | const tabIndex = parseInt(element.getAttribute('tabindex') || '', 10);
|
851 | return isNaN(tabIndex) ? -1 : tabIndex;
|
852 | }
|
853 |
|
854 | function isPotentiallyTabbableIOS(element) {
|
855 | let nodeName = element.nodeName.toLowerCase();
|
856 | let inputType = nodeName === 'input' && element.type;
|
857 | return (inputType === 'text' ||
|
858 | inputType === 'password' ||
|
859 | nodeName === 'select' ||
|
860 | nodeName === 'textarea');
|
861 | }
|
862 |
|
863 |
|
864 |
|
865 |
|
866 | function isPotentiallyFocusable(element) {
|
867 |
|
868 | if (isHiddenInput(element)) {
|
869 | return false;
|
870 | }
|
871 | return (isNativeFormElement(element) ||
|
872 | isAnchorWithHref(element) ||
|
873 | element.hasAttribute('contenteditable') ||
|
874 | hasValidTabIndex(element));
|
875 | }
|
876 |
|
877 | function getWindow(node) {
|
878 |
|
879 | return (node.ownerDocument && node.ownerDocument.defaultView) || window;
|
880 | }
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 | class FocusTrap {
|
900 | constructor(_element, _checker, _ngZone, _document, deferAnchors = false) {
|
901 | this._element = _element;
|
902 | this._checker = _checker;
|
903 | this._ngZone = _ngZone;
|
904 | this._document = _document;
|
905 | this._hasAttached = false;
|
906 |
|
907 | this.startAnchorListener = () => this.focusLastTabbableElement();
|
908 | this.endAnchorListener = () => this.focusFirstTabbableElement();
|
909 | this._enabled = true;
|
910 | if (!deferAnchors) {
|
911 | this.attachAnchors();
|
912 | }
|
913 | }
|
914 |
|
915 | get enabled() {
|
916 | return this._enabled;
|
917 | }
|
918 | set enabled(value) {
|
919 | this._enabled = value;
|
920 | if (this._startAnchor && this._endAnchor) {
|
921 | this._toggleAnchorTabIndex(value, this._startAnchor);
|
922 | this._toggleAnchorTabIndex(value, this._endAnchor);
|
923 | }
|
924 | }
|
925 |
|
926 | destroy() {
|
927 | const startAnchor = this._startAnchor;
|
928 | const endAnchor = this._endAnchor;
|
929 | if (startAnchor) {
|
930 | startAnchor.removeEventListener('focus', this.startAnchorListener);
|
931 | startAnchor.remove();
|
932 | }
|
933 | if (endAnchor) {
|
934 | endAnchor.removeEventListener('focus', this.endAnchorListener);
|
935 | endAnchor.remove();
|
936 | }
|
937 | this._startAnchor = this._endAnchor = null;
|
938 | this._hasAttached = false;
|
939 | }
|
940 | |
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 | attachAnchors() {
|
947 |
|
948 | if (this._hasAttached) {
|
949 | return true;
|
950 | }
|
951 | this._ngZone.runOutsideAngular(() => {
|
952 | if (!this._startAnchor) {
|
953 | this._startAnchor = this._createAnchor();
|
954 | this._startAnchor.addEventListener('focus', this.startAnchorListener);
|
955 | }
|
956 | if (!this._endAnchor) {
|
957 | this._endAnchor = this._createAnchor();
|
958 | this._endAnchor.addEventListener('focus', this.endAnchorListener);
|
959 | }
|
960 | });
|
961 | if (this._element.parentNode) {
|
962 | this._element.parentNode.insertBefore(this._startAnchor, this._element);
|
963 | this._element.parentNode.insertBefore(this._endAnchor, this._element.nextSibling);
|
964 | this._hasAttached = true;
|
965 | }
|
966 | return this._hasAttached;
|
967 | }
|
968 | |
969 |
|
970 |
|
971 |
|
972 |
|
973 | focusInitialElementWhenReady(options) {
|
974 | return new Promise(resolve => {
|
975 | this._executeOnStable(() => resolve(this.focusInitialElement(options)));
|
976 | });
|
977 | }
|
978 | |
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 | focusFirstTabbableElementWhenReady(options) {
|
985 | return new Promise(resolve => {
|
986 | this._executeOnStable(() => resolve(this.focusFirstTabbableElement(options)));
|
987 | });
|
988 | }
|
989 | |
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 | focusLastTabbableElementWhenReady(options) {
|
996 | return new Promise(resolve => {
|
997 | this._executeOnStable(() => resolve(this.focusLastTabbableElement(options)));
|
998 | });
|
999 | }
|
1000 | |
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 | _getRegionBoundary(bound) {
|
1006 |
|
1007 | const markers = this._element.querySelectorAll(`[cdk-focus-region-${bound}], ` + `[cdkFocusRegion${bound}], ` + `[cdk-focus-${bound}]`);
|
1008 | if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
1009 | for (let i = 0; i < markers.length; i++) {
|
1010 |
|
1011 | if (markers[i].hasAttribute(`cdk-focus-${bound}`)) {
|
1012 | console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}', ` +
|
1013 | `use 'cdkFocusRegion${bound}' instead. The deprecated ` +
|
1014 | `attribute will be removed in 8.0.0.`, markers[i]);
|
1015 | }
|
1016 | else if (markers[i].hasAttribute(`cdk-focus-region-${bound}`)) {
|
1017 | console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}', ` +
|
1018 | `use 'cdkFocusRegion${bound}' instead. The deprecated attribute ` +
|
1019 | `will be removed in 8.0.0.`, markers[i]);
|
1020 | }
|
1021 | }
|
1022 | }
|
1023 | if (bound == 'start') {
|
1024 | return markers.length ? markers[0] : this._getFirstTabbableElement(this._element);
|
1025 | }
|
1026 | return markers.length
|
1027 | ? markers[markers.length - 1]
|
1028 | : this._getLastTabbableElement(this._element);
|
1029 | }
|
1030 | |
1031 |
|
1032 |
|
1033 |
|
1034 | focusInitialElement(options) {
|
1035 |
|
1036 | const redirectToElement = this._element.querySelector(`[cdk-focus-initial], ` + `[cdkFocusInitial]`);
|
1037 | if (redirectToElement) {
|
1038 |
|
1039 | if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
|
1040 | redirectToElement.hasAttribute(`cdk-focus-initial`)) {
|
1041 | console.warn(`Found use of deprecated attribute 'cdk-focus-initial', ` +
|
1042 | `use 'cdkFocusInitial' instead. The deprecated attribute ` +
|
1043 | `will be removed in 8.0.0`, redirectToElement);
|
1044 | }
|
1045 |
|
1046 |
|
1047 | if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
|
1048 | !this._checker.isFocusable(redirectToElement)) {
|
1049 | console.warn(`Element matching '[cdkFocusInitial]' is not focusable.`, redirectToElement);
|
1050 | }
|
1051 | if (!this._checker.isFocusable(redirectToElement)) {
|
1052 | const focusableChild = this._getFirstTabbableElement(redirectToElement);
|
1053 | focusableChild?.focus(options);
|
1054 | return !!focusableChild;
|
1055 | }
|
1056 | redirectToElement.focus(options);
|
1057 | return true;
|
1058 | }
|
1059 | return this.focusFirstTabbableElement(options);
|
1060 | }
|
1061 | |
1062 |
|
1063 |
|
1064 |
|
1065 | focusFirstTabbableElement(options) {
|
1066 | const redirectToElement = this._getRegionBoundary('start');
|
1067 | if (redirectToElement) {
|
1068 | redirectToElement.focus(options);
|
1069 | }
|
1070 | return !!redirectToElement;
|
1071 | }
|
1072 | |
1073 |
|
1074 |
|
1075 |
|
1076 | focusLastTabbableElement(options) {
|
1077 | const redirectToElement = this._getRegionBoundary('end');
|
1078 | if (redirectToElement) {
|
1079 | redirectToElement.focus(options);
|
1080 | }
|
1081 | return !!redirectToElement;
|
1082 | }
|
1083 | |
1084 |
|
1085 |
|
1086 | hasAttached() {
|
1087 | return this._hasAttached;
|
1088 | }
|
1089 |
|
1090 | _getFirstTabbableElement(root) {
|
1091 | if (this._checker.isFocusable(root) && this._checker.isTabbable(root)) {
|
1092 | return root;
|
1093 | }
|
1094 | const children = root.children;
|
1095 | for (let i = 0; i < children.length; i++) {
|
1096 | const tabbableChild = children[i].nodeType === this._document.ELEMENT_NODE
|
1097 | ? this._getFirstTabbableElement(children[i])
|
1098 | : null;
|
1099 | if (tabbableChild) {
|
1100 | return tabbableChild;
|
1101 | }
|
1102 | }
|
1103 | return null;
|
1104 | }
|
1105 |
|
1106 | _getLastTabbableElement(root) {
|
1107 | if (this._checker.isFocusable(root) && this._checker.isTabbable(root)) {
|
1108 | return root;
|
1109 | }
|
1110 |
|
1111 | const children = root.children;
|
1112 | for (let i = children.length - 1; i >= 0; i--) {
|
1113 | const tabbableChild = children[i].nodeType === this._document.ELEMENT_NODE
|
1114 | ? this._getLastTabbableElement(children[i])
|
1115 | : null;
|
1116 | if (tabbableChild) {
|
1117 | return tabbableChild;
|
1118 | }
|
1119 | }
|
1120 | return null;
|
1121 | }
|
1122 |
|
1123 | _createAnchor() {
|
1124 | const anchor = this._document.createElement('div');
|
1125 | this._toggleAnchorTabIndex(this._enabled, anchor);
|
1126 | anchor.classList.add('cdk-visually-hidden');
|
1127 | anchor.classList.add('cdk-focus-trap-anchor');
|
1128 | anchor.setAttribute('aria-hidden', 'true');
|
1129 | return anchor;
|
1130 | }
|
1131 | |
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 | _toggleAnchorTabIndex(isEnabled, anchor) {
|
1137 |
|
1138 |
|
1139 | isEnabled ? anchor.setAttribute('tabindex', '0') : anchor.removeAttribute('tabindex');
|
1140 | }
|
1141 | |
1142 |
|
1143 |
|
1144 |
|
1145 | toggleAnchors(enabled) {
|
1146 | if (this._startAnchor && this._endAnchor) {
|
1147 | this._toggleAnchorTabIndex(enabled, this._startAnchor);
|
1148 | this._toggleAnchorTabIndex(enabled, this._endAnchor);
|
1149 | }
|
1150 | }
|
1151 |
|
1152 | _executeOnStable(fn) {
|
1153 | if (this._ngZone.isStable) {
|
1154 | fn();
|
1155 | }
|
1156 | else {
|
1157 | this._ngZone.onStable.pipe(take(1)).subscribe(fn);
|
1158 | }
|
1159 | }
|
1160 | }
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 | class FocusTrapFactory {
|
1167 | constructor(_checker, _ngZone, _document) {
|
1168 | this._checker = _checker;
|
1169 | this._ngZone = _ngZone;
|
1170 | this._document = _document;
|
1171 | }
|
1172 | |
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 | create(element, deferCaptureElements = false) {
|
1180 | return new FocusTrap(element, this._checker, this._ngZone, this._document, deferCaptureElements);
|
1181 | }
|
1182 | }
|
1183 | FocusTrapFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapFactory, deps: [{ token: InteractivityChecker }, { token: i0.NgZone }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
1184 | FocusTrapFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapFactory, providedIn: 'root' });
|
1185 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapFactory, decorators: [{
|
1186 | type: Injectable,
|
1187 | args: [{ providedIn: 'root' }]
|
1188 | }], ctorParameters: function () { return [{ type: InteractivityChecker }, { type: i0.NgZone }, { type: undefined, decorators: [{
|
1189 | type: Inject,
|
1190 | args: [DOCUMENT]
|
1191 | }] }]; } });
|
1192 |
|
1193 | class CdkTrapFocus {
|
1194 | constructor(_elementRef, _focusTrapFactory,
|
1195 | /**
|
1196 | * @deprecated No longer being used. To be removed.
|
1197 | * @breaking-change 13.0.0
|
1198 | */
|
1199 | _document) {
|
1200 | this._elementRef = _elementRef;
|
1201 | this._focusTrapFactory = _focusTrapFactory;
|
1202 |
|
1203 | this._previouslyFocusedElement = null;
|
1204 | this.focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement, true);
|
1205 | }
|
1206 |
|
1207 | get enabled() {
|
1208 | return this.focusTrap.enabled;
|
1209 | }
|
1210 | set enabled(value) {
|
1211 | this.focusTrap.enabled = coerceBooleanProperty(value);
|
1212 | }
|
1213 | |
1214 |
|
1215 |
|
1216 |
|
1217 | get autoCapture() {
|
1218 | return this._autoCapture;
|
1219 | }
|
1220 | set autoCapture(value) {
|
1221 | this._autoCapture = coerceBooleanProperty(value);
|
1222 | }
|
1223 | ngOnDestroy() {
|
1224 | this.focusTrap.destroy();
|
1225 |
|
1226 |
|
1227 | if (this._previouslyFocusedElement) {
|
1228 | this._previouslyFocusedElement.focus();
|
1229 | this._previouslyFocusedElement = null;
|
1230 | }
|
1231 | }
|
1232 | ngAfterContentInit() {
|
1233 | this.focusTrap.attachAnchors();
|
1234 | if (this.autoCapture) {
|
1235 | this._captureFocus();
|
1236 | }
|
1237 | }
|
1238 | ngDoCheck() {
|
1239 | if (!this.focusTrap.hasAttached()) {
|
1240 | this.focusTrap.attachAnchors();
|
1241 | }
|
1242 | }
|
1243 | ngOnChanges(changes) {
|
1244 | const autoCaptureChange = changes['autoCapture'];
|
1245 | if (autoCaptureChange &&
|
1246 | !autoCaptureChange.firstChange &&
|
1247 | this.autoCapture &&
|
1248 | this.focusTrap.hasAttached()) {
|
1249 | this._captureFocus();
|
1250 | }
|
1251 | }
|
1252 | _captureFocus() {
|
1253 | this._previouslyFocusedElement = _getFocusedElementPierceShadowDom();
|
1254 | this.focusTrap.focusInitialElementWhenReady();
|
1255 | }
|
1256 | }
|
1257 | CdkTrapFocus.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkTrapFocus, deps: [{ token: i0.ElementRef }, { token: FocusTrapFactory }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Directive });
|
1258 | CdkTrapFocus.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: { enabled: ["cdkTrapFocus", "enabled"], autoCapture: ["cdkTrapFocusAutoCapture", "autoCapture"] }, exportAs: ["cdkTrapFocus"], usesOnChanges: true, ngImport: i0 });
|
1259 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkTrapFocus, decorators: [{
|
1260 | type: Directive,
|
1261 | args: [{
|
1262 | selector: '[cdkTrapFocus]',
|
1263 | exportAs: 'cdkTrapFocus',
|
1264 | }]
|
1265 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: FocusTrapFactory }, { type: undefined, decorators: [{
|
1266 | type: Inject,
|
1267 | args: [DOCUMENT]
|
1268 | }] }]; }, propDecorators: { enabled: [{
|
1269 | type: Input,
|
1270 | args: ['cdkTrapFocus']
|
1271 | }], autoCapture: [{
|
1272 | type: Input,
|
1273 | args: ['cdkTrapFocusAutoCapture']
|
1274 | }] } });
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 | class ConfigurableFocusTrap extends FocusTrap {
|
1290 | constructor(_element, _checker, _ngZone, _document, _focusTrapManager, _inertStrategy, config) {
|
1291 | super(_element, _checker, _ngZone, _document, config.defer);
|
1292 | this._focusTrapManager = _focusTrapManager;
|
1293 | this._inertStrategy = _inertStrategy;
|
1294 | this._focusTrapManager.register(this);
|
1295 | }
|
1296 |
|
1297 | get enabled() {
|
1298 | return this._enabled;
|
1299 | }
|
1300 | set enabled(value) {
|
1301 | this._enabled = value;
|
1302 | if (this._enabled) {
|
1303 | this._focusTrapManager.register(this);
|
1304 | }
|
1305 | else {
|
1306 | this._focusTrapManager.deregister(this);
|
1307 | }
|
1308 | }
|
1309 |
|
1310 | destroy() {
|
1311 | this._focusTrapManager.deregister(this);
|
1312 | super.destroy();
|
1313 | }
|
1314 |
|
1315 | _enable() {
|
1316 | this._inertStrategy.preventFocus(this);
|
1317 | this.toggleAnchors(true);
|
1318 | }
|
1319 |
|
1320 | _disable() {
|
1321 | this._inertStrategy.allowFocus(this);
|
1322 | this.toggleAnchors(false);
|
1323 | }
|
1324 | }
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 | const FOCUS_TRAP_INERT_STRATEGY = new InjectionToken('FOCUS_TRAP_INERT_STRATEGY');
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 | class EventListenerFocusTrapInertStrategy {
|
1356 | constructor() {
|
1357 |
|
1358 | this._listener = null;
|
1359 | }
|
1360 |
|
1361 | preventFocus(focusTrap) {
|
1362 |
|
1363 | if (this._listener) {
|
1364 | focusTrap._document.removeEventListener('focus', this._listener, true);
|
1365 | }
|
1366 | this._listener = (e) => this._trapFocus(focusTrap, e);
|
1367 | focusTrap._ngZone.runOutsideAngular(() => {
|
1368 | focusTrap._document.addEventListener('focus', this._listener, true);
|
1369 | });
|
1370 | }
|
1371 |
|
1372 | allowFocus(focusTrap) {
|
1373 | if (!this._listener) {
|
1374 | return;
|
1375 | }
|
1376 | focusTrap._document.removeEventListener('focus', this._listener, true);
|
1377 | this._listener = null;
|
1378 | }
|
1379 | |
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 | _trapFocus(focusTrap, event) {
|
1387 | const target = event.target;
|
1388 | const focusTrapRoot = focusTrap._element;
|
1389 |
|
1390 |
|
1391 | if (target && !focusTrapRoot.contains(target) && !target.closest?.('div.cdk-overlay-pane')) {
|
1392 |
|
1393 |
|
1394 |
|
1395 | setTimeout(() => {
|
1396 |
|
1397 | if (focusTrap.enabled && !focusTrapRoot.contains(focusTrap._document.activeElement)) {
|
1398 | focusTrap.focusFirstTabbableElement();
|
1399 | }
|
1400 | });
|
1401 | }
|
1402 | }
|
1403 | }
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 | class FocusTrapManager {
|
1414 | constructor() {
|
1415 |
|
1416 |
|
1417 | this._focusTrapStack = [];
|
1418 | }
|
1419 | |
1420 |
|
1421 |
|
1422 |
|
1423 | register(focusTrap) {
|
1424 |
|
1425 | this._focusTrapStack = this._focusTrapStack.filter(ft => ft !== focusTrap);
|
1426 | let stack = this._focusTrapStack;
|
1427 | if (stack.length) {
|
1428 | stack[stack.length - 1]._disable();
|
1429 | }
|
1430 | stack.push(focusTrap);
|
1431 | focusTrap._enable();
|
1432 | }
|
1433 | |
1434 |
|
1435 |
|
1436 |
|
1437 | deregister(focusTrap) {
|
1438 | focusTrap._disable();
|
1439 | const stack = this._focusTrapStack;
|
1440 | const i = stack.indexOf(focusTrap);
|
1441 | if (i !== -1) {
|
1442 | stack.splice(i, 1);
|
1443 | if (stack.length) {
|
1444 | stack[stack.length - 1]._enable();
|
1445 | }
|
1446 | }
|
1447 | }
|
1448 | }
|
1449 | FocusTrapManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
1450 | FocusTrapManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapManager, providedIn: 'root' });
|
1451 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusTrapManager, decorators: [{
|
1452 | type: Injectable,
|
1453 | args: [{ providedIn: 'root' }]
|
1454 | }] });
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 | class ConfigurableFocusTrapFactory {
|
1465 | constructor(_checker, _ngZone, _focusTrapManager, _document, _inertStrategy) {
|
1466 | this._checker = _checker;
|
1467 | this._ngZone = _ngZone;
|
1468 | this._focusTrapManager = _focusTrapManager;
|
1469 | this._document = _document;
|
1470 |
|
1471 | this._inertStrategy = _inertStrategy || new EventListenerFocusTrapInertStrategy();
|
1472 | }
|
1473 | create(element, config = { defer: false }) {
|
1474 | let configObject;
|
1475 | if (typeof config === 'boolean') {
|
1476 | configObject = { defer: config };
|
1477 | }
|
1478 | else {
|
1479 | configObject = config;
|
1480 | }
|
1481 | return new ConfigurableFocusTrap(element, this._checker, this._ngZone, this._document, this._focusTrapManager, this._inertStrategy, configObject);
|
1482 | }
|
1483 | }
|
1484 | ConfigurableFocusTrapFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: ConfigurableFocusTrapFactory, deps: [{ token: InteractivityChecker }, { token: i0.NgZone }, { token: FocusTrapManager }, { token: DOCUMENT }, { token: FOCUS_TRAP_INERT_STRATEGY, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
1485 | ConfigurableFocusTrapFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: ConfigurableFocusTrapFactory, providedIn: 'root' });
|
1486 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: ConfigurableFocusTrapFactory, decorators: [{
|
1487 | type: Injectable,
|
1488 | args: [{ providedIn: 'root' }]
|
1489 | }], ctorParameters: function () { return [{ type: InteractivityChecker }, { type: i0.NgZone }, { type: FocusTrapManager }, { type: undefined, decorators: [{
|
1490 | type: Inject,
|
1491 | args: [DOCUMENT]
|
1492 | }] }, { type: undefined, decorators: [{
|
1493 | type: Optional
|
1494 | }, {
|
1495 | type: Inject,
|
1496 | args: [FOCUS_TRAP_INERT_STRATEGY]
|
1497 | }] }]; } });
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 | function isFakeMousedownFromScreenReader(event) {
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 | return event.buttons === 0 || (event.offsetX === 0 && event.offsetY === 0);
|
1516 | }
|
1517 |
|
1518 | function isFakeTouchstartFromScreenReader(event) {
|
1519 | const touch = (event.touches && event.touches[0]) || (event.changedTouches && event.changedTouches[0]);
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | return (!!touch &&
|
1525 | touch.identifier === -1 &&
|
1526 | (touch.radiusX == null || touch.radiusX === 1) &&
|
1527 | (touch.radiusY == null || touch.radiusY === 1));
|
1528 | }
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 | const INPUT_MODALITY_DETECTOR_OPTIONS = new InjectionToken('cdk-input-modality-detector-options');
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 | const INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS = {
|
1559 | ignoreKeys: [ALT, CONTROL, MAC_META, META, SHIFT],
|
1560 | };
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 | const TOUCH_BUFFER_MS = 650;
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 | const modalityEventListenerOptions = normalizePassiveListenerOptions({
|
1574 | passive: true,
|
1575 | capture: true,
|
1576 | });
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 | class InputModalityDetector {
|
1592 | constructor(_platform, ngZone, document, options) {
|
1593 | this._platform = _platform;
|
1594 | |
1595 |
|
1596 |
|
1597 |
|
1598 | this._mostRecentTarget = null;
|
1599 |
|
1600 | this._modality = new BehaviorSubject(null);
|
1601 | |
1602 |
|
1603 |
|
1604 |
|
1605 | this._lastTouchMs = 0;
|
1606 | |
1607 |
|
1608 |
|
1609 |
|
1610 | this._onKeydown = (event) => {
|
1611 |
|
1612 |
|
1613 | if (this._options?.ignoreKeys?.some(keyCode => keyCode === event.keyCode)) {
|
1614 | return;
|
1615 | }
|
1616 | this._modality.next('keyboard');
|
1617 | this._mostRecentTarget = _getEventTarget(event);
|
1618 | };
|
1619 | |
1620 |
|
1621 |
|
1622 |
|
1623 | this._onMousedown = (event) => {
|
1624 |
|
1625 |
|
1626 |
|
1627 | if (Date.now() - this._lastTouchMs < TOUCH_BUFFER_MS) {
|
1628 | return;
|
1629 | }
|
1630 |
|
1631 |
|
1632 | this._modality.next(isFakeMousedownFromScreenReader(event) ? 'keyboard' : 'mouse');
|
1633 | this._mostRecentTarget = _getEventTarget(event);
|
1634 | };
|
1635 | |
1636 |
|
1637 |
|
1638 |
|
1639 | this._onTouchstart = (event) => {
|
1640 |
|
1641 |
|
1642 | if (isFakeTouchstartFromScreenReader(event)) {
|
1643 | this._modality.next('keyboard');
|
1644 | return;
|
1645 | }
|
1646 |
|
1647 |
|
1648 | this._lastTouchMs = Date.now();
|
1649 | this._modality.next('touch');
|
1650 | this._mostRecentTarget = _getEventTarget(event);
|
1651 | };
|
1652 | this._options = {
|
1653 | ...INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS,
|
1654 | ...options,
|
1655 | };
|
1656 |
|
1657 | this.modalityDetected = this._modality.pipe(skip(1));
|
1658 | this.modalityChanged = this.modalityDetected.pipe(distinctUntilChanged());
|
1659 |
|
1660 |
|
1661 | if (_platform.isBrowser) {
|
1662 | ngZone.runOutsideAngular(() => {
|
1663 | document.addEventListener('keydown', this._onKeydown, modalityEventListenerOptions);
|
1664 | document.addEventListener('mousedown', this._onMousedown, modalityEventListenerOptions);
|
1665 | document.addEventListener('touchstart', this._onTouchstart, modalityEventListenerOptions);
|
1666 | });
|
1667 | }
|
1668 | }
|
1669 |
|
1670 | get mostRecentModality() {
|
1671 | return this._modality.value;
|
1672 | }
|
1673 | ngOnDestroy() {
|
1674 | this._modality.complete();
|
1675 | if (this._platform.isBrowser) {
|
1676 | document.removeEventListener('keydown', this._onKeydown, modalityEventListenerOptions);
|
1677 | document.removeEventListener('mousedown', this._onMousedown, modalityEventListenerOptions);
|
1678 | document.removeEventListener('touchstart', this._onTouchstart, modalityEventListenerOptions);
|
1679 | }
|
1680 | }
|
1681 | }
|
1682 | InputModalityDetector.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InputModalityDetector, deps: [{ token: i1.Platform }, { token: i0.NgZone }, { token: DOCUMENT }, { token: INPUT_MODALITY_DETECTOR_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
1683 | InputModalityDetector.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InputModalityDetector, providedIn: 'root' });
|
1684 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: InputModalityDetector, decorators: [{
|
1685 | type: Injectable,
|
1686 | args: [{ providedIn: 'root' }]
|
1687 | }], ctorParameters: function () { return [{ type: i1.Platform }, { type: i0.NgZone }, { type: Document, decorators: [{
|
1688 | type: Inject,
|
1689 | args: [DOCUMENT]
|
1690 | }] }, { type: undefined, decorators: [{
|
1691 | type: Optional
|
1692 | }, {
|
1693 | type: Inject,
|
1694 | args: [INPUT_MODALITY_DETECTOR_OPTIONS]
|
1695 | }] }]; } });
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 | const LIVE_ANNOUNCER_ELEMENT_TOKEN = new InjectionToken('liveAnnouncerElement', {
|
1705 | providedIn: 'root',
|
1706 | factory: LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY,
|
1707 | });
|
1708 |
|
1709 | function LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY() {
|
1710 | return null;
|
1711 | }
|
1712 |
|
1713 | const LIVE_ANNOUNCER_DEFAULT_OPTIONS = new InjectionToken('LIVE_ANNOUNCER_DEFAULT_OPTIONS');
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 | class LiveAnnouncer {
|
1723 | constructor(elementToken, _ngZone, _document, _defaultOptions) {
|
1724 | this._ngZone = _ngZone;
|
1725 | this._defaultOptions = _defaultOptions;
|
1726 |
|
1727 |
|
1728 |
|
1729 | this._document = _document;
|
1730 | this._liveElement = elementToken || this._createLiveElement();
|
1731 | }
|
1732 | announce(message, ...args) {
|
1733 | const defaultOptions = this._defaultOptions;
|
1734 | let politeness;
|
1735 | let duration;
|
1736 | if (args.length === 1 && typeof args[0] === 'number') {
|
1737 | duration = args[0];
|
1738 | }
|
1739 | else {
|
1740 | [politeness, duration] = args;
|
1741 | }
|
1742 | this.clear();
|
1743 | clearTimeout(this._previousTimeout);
|
1744 | if (!politeness) {
|
1745 | politeness =
|
1746 | defaultOptions && defaultOptions.politeness ? defaultOptions.politeness : 'polite';
|
1747 | }
|
1748 | if (duration == null && defaultOptions) {
|
1749 | duration = defaultOptions.duration;
|
1750 | }
|
1751 |
|
1752 | this._liveElement.setAttribute('aria-live', politeness);
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 | return this._ngZone.runOutsideAngular(() => {
|
1759 | if (!this._currentPromise) {
|
1760 | this._currentPromise = new Promise(resolve => (this._currentResolve = resolve));
|
1761 | }
|
1762 | clearTimeout(this._previousTimeout);
|
1763 | this._previousTimeout = setTimeout(() => {
|
1764 | this._liveElement.textContent = message;
|
1765 | if (typeof duration === 'number') {
|
1766 | this._previousTimeout = setTimeout(() => this.clear(), duration);
|
1767 | }
|
1768 | this._currentResolve();
|
1769 | this._currentPromise = this._currentResolve = undefined;
|
1770 | }, 100);
|
1771 | return this._currentPromise;
|
1772 | });
|
1773 | }
|
1774 | |
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 | clear() {
|
1780 | if (this._liveElement) {
|
1781 | this._liveElement.textContent = '';
|
1782 | }
|
1783 | }
|
1784 | ngOnDestroy() {
|
1785 | clearTimeout(this._previousTimeout);
|
1786 | this._liveElement?.remove();
|
1787 | this._liveElement = null;
|
1788 | this._currentResolve?.();
|
1789 | this._currentPromise = this._currentResolve = undefined;
|
1790 | }
|
1791 | _createLiveElement() {
|
1792 | const elementClass = 'cdk-live-announcer-element';
|
1793 | const previousElements = this._document.getElementsByClassName(elementClass);
|
1794 | const liveEl = this._document.createElement('div');
|
1795 |
|
1796 | for (let i = 0; i < previousElements.length; i++) {
|
1797 | previousElements[i].remove();
|
1798 | }
|
1799 | liveEl.classList.add(elementClass);
|
1800 | liveEl.classList.add('cdk-visually-hidden');
|
1801 | liveEl.setAttribute('aria-atomic', 'true');
|
1802 | liveEl.setAttribute('aria-live', 'polite');
|
1803 | this._document.body.appendChild(liveEl);
|
1804 | return liveEl;
|
1805 | }
|
1806 | }
|
1807 | LiveAnnouncer.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LiveAnnouncer, deps: [{ token: LIVE_ANNOUNCER_ELEMENT_TOKEN, optional: true }, { token: i0.NgZone }, { token: DOCUMENT }, { token: LIVE_ANNOUNCER_DEFAULT_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
1808 | LiveAnnouncer.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LiveAnnouncer, providedIn: 'root' });
|
1809 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: LiveAnnouncer, decorators: [{
|
1810 | type: Injectable,
|
1811 | args: [{ providedIn: 'root' }]
|
1812 | }], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
1813 | type: Optional
|
1814 | }, {
|
1815 | type: Inject,
|
1816 | args: [LIVE_ANNOUNCER_ELEMENT_TOKEN]
|
1817 | }] }, { type: i0.NgZone }, { type: undefined, decorators: [{
|
1818 | type: Inject,
|
1819 | args: [DOCUMENT]
|
1820 | }] }, { type: undefined, decorators: [{
|
1821 | type: Optional
|
1822 | }, {
|
1823 | type: Inject,
|
1824 | args: [LIVE_ANNOUNCER_DEFAULT_OPTIONS]
|
1825 | }] }]; } });
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 | class CdkAriaLive {
|
1831 | constructor(_elementRef, _liveAnnouncer, _contentObserver, _ngZone) {
|
1832 | this._elementRef = _elementRef;
|
1833 | this._liveAnnouncer = _liveAnnouncer;
|
1834 | this._contentObserver = _contentObserver;
|
1835 | this._ngZone = _ngZone;
|
1836 | this._politeness = 'polite';
|
1837 | }
|
1838 |
|
1839 | get politeness() {
|
1840 | return this._politeness;
|
1841 | }
|
1842 | set politeness(value) {
|
1843 | this._politeness = value === 'off' || value === 'assertive' ? value : 'polite';
|
1844 | if (this._politeness === 'off') {
|
1845 | if (this._subscription) {
|
1846 | this._subscription.unsubscribe();
|
1847 | this._subscription = null;
|
1848 | }
|
1849 | }
|
1850 | else if (!this._subscription) {
|
1851 | this._subscription = this._ngZone.runOutsideAngular(() => {
|
1852 | return this._contentObserver.observe(this._elementRef).subscribe(() => {
|
1853 |
|
1854 | const elementText = this._elementRef.nativeElement.textContent;
|
1855 |
|
1856 |
|
1857 | if (elementText !== this._previousAnnouncedText) {
|
1858 | this._liveAnnouncer.announce(elementText, this._politeness, this.duration);
|
1859 | this._previousAnnouncedText = elementText;
|
1860 | }
|
1861 | });
|
1862 | });
|
1863 | }
|
1864 | }
|
1865 | ngOnDestroy() {
|
1866 | if (this._subscription) {
|
1867 | this._subscription.unsubscribe();
|
1868 | }
|
1869 | }
|
1870 | }
|
1871 | CdkAriaLive.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAriaLive, deps: [{ token: i0.ElementRef }, { token: LiveAnnouncer }, { token: i1$1.ContentObserver }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
1872 | CdkAriaLive.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: CdkAriaLive, selector: "[cdkAriaLive]", inputs: { politeness: ["cdkAriaLive", "politeness"], duration: ["cdkAriaLiveDuration", "duration"] }, exportAs: ["cdkAriaLive"], ngImport: i0 });
|
1873 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAriaLive, decorators: [{
|
1874 | type: Directive,
|
1875 | args: [{
|
1876 | selector: '[cdkAriaLive]',
|
1877 | exportAs: 'cdkAriaLive',
|
1878 | }]
|
1879 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: LiveAnnouncer }, { type: i1$1.ContentObserver }, { type: i0.NgZone }]; }, propDecorators: { politeness: [{
|
1880 | type: Input,
|
1881 | args: ['cdkAriaLive']
|
1882 | }], duration: [{
|
1883 | type: Input,
|
1884 | args: ['cdkAriaLiveDuration']
|
1885 | }] } });
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 | const FOCUS_MONITOR_DEFAULT_OPTIONS = new InjectionToken('cdk-focus-monitor-default-options');
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 | const captureEventListenerOptions = normalizePassiveListenerOptions({
|
1901 | passive: true,
|
1902 | capture: true,
|
1903 | });
|
1904 |
|
1905 | class FocusMonitor {
|
1906 | constructor(_ngZone, _platform, _inputModalityDetector,
|
1907 | /** @breaking-change 11.0.0 make document required */
|
1908 | document, options) {
|
1909 | this._ngZone = _ngZone;
|
1910 | this._platform = _platform;
|
1911 | this._inputModalityDetector = _inputModalityDetector;
|
1912 |
|
1913 | this._origin = null;
|
1914 |
|
1915 | this._windowFocused = false;
|
1916 | |
1917 |
|
1918 |
|
1919 |
|
1920 | this._originFromTouchInteraction = false;
|
1921 |
|
1922 | this._elementInfo = new Map();
|
1923 |
|
1924 | this._monitoredElementCount = 0;
|
1925 | |
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 | this._rootNodeFocusListenerCount = new Map();
|
1932 | |
1933 |
|
1934 |
|
1935 |
|
1936 | this._windowFocusListener = () => {
|
1937 |
|
1938 |
|
1939 | this._windowFocused = true;
|
1940 | this._windowFocusTimeoutId = window.setTimeout(() => (this._windowFocused = false));
|
1941 | };
|
1942 |
|
1943 | this._stopInputModalityDetector = new Subject();
|
1944 | |
1945 |
|
1946 |
|
1947 |
|
1948 | this._rootNodeFocusAndBlurListener = (event) => {
|
1949 | const target = _getEventTarget(event);
|
1950 |
|
1951 | for (let element = target; element; element = element.parentElement) {
|
1952 | if (event.type === 'focus') {
|
1953 | this._onFocus(event, element);
|
1954 | }
|
1955 | else {
|
1956 | this._onBlur(event, element);
|
1957 | }
|
1958 | }
|
1959 | };
|
1960 | this._document = document;
|
1961 | this._detectionMode = options?.detectionMode || 0 ;
|
1962 | }
|
1963 | monitor(element, checkChildren = false) {
|
1964 | const nativeElement = coerceElement(element);
|
1965 |
|
1966 | if (!this._platform.isBrowser || nativeElement.nodeType !== 1) {
|
1967 | return of(null);
|
1968 | }
|
1969 |
|
1970 |
|
1971 |
|
1972 | const rootNode = _getShadowRoot(nativeElement) || this._getDocument();
|
1973 | const cachedInfo = this._elementInfo.get(nativeElement);
|
1974 |
|
1975 | if (cachedInfo) {
|
1976 | if (checkChildren) {
|
1977 |
|
1978 |
|
1979 |
|
1980 | cachedInfo.checkChildren = true;
|
1981 | }
|
1982 | return cachedInfo.subject;
|
1983 | }
|
1984 |
|
1985 | const info = {
|
1986 | checkChildren: checkChildren,
|
1987 | subject: new Subject(),
|
1988 | rootNode,
|
1989 | };
|
1990 | this._elementInfo.set(nativeElement, info);
|
1991 | this._registerGlobalListeners(info);
|
1992 | return info.subject;
|
1993 | }
|
1994 | stopMonitoring(element) {
|
1995 | const nativeElement = coerceElement(element);
|
1996 | const elementInfo = this._elementInfo.get(nativeElement);
|
1997 | if (elementInfo) {
|
1998 | elementInfo.subject.complete();
|
1999 | this._setClasses(nativeElement);
|
2000 | this._elementInfo.delete(nativeElement);
|
2001 | this._removeGlobalListeners(elementInfo);
|
2002 | }
|
2003 | }
|
2004 | focusVia(element, origin, options) {
|
2005 | const nativeElement = coerceElement(element);
|
2006 | const focusedElement = this._getDocument().activeElement;
|
2007 |
|
2008 |
|
2009 |
|
2010 | if (nativeElement === focusedElement) {
|
2011 | this._getClosestElementsInfo(nativeElement).forEach(([currentElement, info]) => this._originChanged(currentElement, origin, info));
|
2012 | }
|
2013 | else {
|
2014 | this._setOrigin(origin);
|
2015 |
|
2016 | if (typeof nativeElement.focus === 'function') {
|
2017 | nativeElement.focus(options);
|
2018 | }
|
2019 | }
|
2020 | }
|
2021 | ngOnDestroy() {
|
2022 | this._elementInfo.forEach((_info, element) => this.stopMonitoring(element));
|
2023 | }
|
2024 |
|
2025 | _getDocument() {
|
2026 | return this._document || document;
|
2027 | }
|
2028 |
|
2029 | _getWindow() {
|
2030 | const doc = this._getDocument();
|
2031 | return doc.defaultView || window;
|
2032 | }
|
2033 | _getFocusOrigin(focusEventTarget) {
|
2034 | if (this._origin) {
|
2035 |
|
2036 |
|
2037 | if (this._originFromTouchInteraction) {
|
2038 | return this._shouldBeAttributedToTouch(focusEventTarget) ? 'touch' : 'program';
|
2039 | }
|
2040 | else {
|
2041 | return this._origin;
|
2042 | }
|
2043 | }
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 | if (this._windowFocused && this._lastFocusOrigin) {
|
2054 | return this._lastFocusOrigin;
|
2055 | }
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 | if (focusEventTarget && this._isLastInteractionFromInputLabel(focusEventTarget)) {
|
2061 | return 'mouse';
|
2062 | }
|
2063 | return 'program';
|
2064 | }
|
2065 | |
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 | _shouldBeAttributedToTouch(focusEventTarget) {
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 | return (this._detectionMode === 1 ||
|
2085 | !!focusEventTarget?.contains(this._inputModalityDetector._mostRecentTarget));
|
2086 | }
|
2087 | |
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 | _setClasses(element, origin) {
|
2093 | element.classList.toggle('cdk-focused', !!origin);
|
2094 | element.classList.toggle('cdk-touch-focused', origin === 'touch');
|
2095 | element.classList.toggle('cdk-keyboard-focused', origin === 'keyboard');
|
2096 | element.classList.toggle('cdk-mouse-focused', origin === 'mouse');
|
2097 | element.classList.toggle('cdk-program-focused', origin === 'program');
|
2098 | }
|
2099 | |
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 | _setOrigin(origin, isFromInteraction = false) {
|
2107 | this._ngZone.runOutsideAngular(() => {
|
2108 | this._origin = origin;
|
2109 | this._originFromTouchInteraction = origin === 'touch' && isFromInteraction;
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 | if (this._detectionMode === 0 ) {
|
2116 | clearTimeout(this._originTimeoutId);
|
2117 | const ms = this._originFromTouchInteraction ? TOUCH_BUFFER_MS : 1;
|
2118 | this._originTimeoutId = setTimeout(() => (this._origin = null), ms);
|
2119 | }
|
2120 | });
|
2121 | }
|
2122 | |
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 | _onFocus(event, element) {
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 | const elementInfo = this._elementInfo.get(element);
|
2135 | const focusEventTarget = _getEventTarget(event);
|
2136 | if (!elementInfo || (!elementInfo.checkChildren && element !== focusEventTarget)) {
|
2137 | return;
|
2138 | }
|
2139 | this._originChanged(element, this._getFocusOrigin(focusEventTarget), elementInfo);
|
2140 | }
|
2141 | |
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 | _onBlur(event, element) {
|
2147 |
|
2148 |
|
2149 | const elementInfo = this._elementInfo.get(element);
|
2150 | if (!elementInfo ||
|
2151 | (elementInfo.checkChildren &&
|
2152 | event.relatedTarget instanceof Node &&
|
2153 | element.contains(event.relatedTarget))) {
|
2154 | return;
|
2155 | }
|
2156 | this._setClasses(element);
|
2157 | this._emitOrigin(elementInfo, null);
|
2158 | }
|
2159 | _emitOrigin(info, origin) {
|
2160 | if (info.subject.observers.length) {
|
2161 | this._ngZone.run(() => info.subject.next(origin));
|
2162 | }
|
2163 | }
|
2164 | _registerGlobalListeners(elementInfo) {
|
2165 | if (!this._platform.isBrowser) {
|
2166 | return;
|
2167 | }
|
2168 | const rootNode = elementInfo.rootNode;
|
2169 | const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode) || 0;
|
2170 | if (!rootNodeFocusListeners) {
|
2171 | this._ngZone.runOutsideAngular(() => {
|
2172 | rootNode.addEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
|
2173 | rootNode.addEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
|
2174 | });
|
2175 | }
|
2176 | this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners + 1);
|
2177 |
|
2178 | if (++this._monitoredElementCount === 1) {
|
2179 |
|
2180 |
|
2181 | this._ngZone.runOutsideAngular(() => {
|
2182 | const window = this._getWindow();
|
2183 | window.addEventListener('focus', this._windowFocusListener);
|
2184 | });
|
2185 |
|
2186 | this._inputModalityDetector.modalityDetected
|
2187 | .pipe(takeUntil(this._stopInputModalityDetector))
|
2188 | .subscribe(modality => {
|
2189 | this._setOrigin(modality, true );
|
2190 | });
|
2191 | }
|
2192 | }
|
2193 | _removeGlobalListeners(elementInfo) {
|
2194 | const rootNode = elementInfo.rootNode;
|
2195 | if (this._rootNodeFocusListenerCount.has(rootNode)) {
|
2196 | const rootNodeFocusListeners = this._rootNodeFocusListenerCount.get(rootNode);
|
2197 | if (rootNodeFocusListeners > 1) {
|
2198 | this._rootNodeFocusListenerCount.set(rootNode, rootNodeFocusListeners - 1);
|
2199 | }
|
2200 | else {
|
2201 | rootNode.removeEventListener('focus', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
|
2202 | rootNode.removeEventListener('blur', this._rootNodeFocusAndBlurListener, captureEventListenerOptions);
|
2203 | this._rootNodeFocusListenerCount.delete(rootNode);
|
2204 | }
|
2205 | }
|
2206 |
|
2207 | if (!--this._monitoredElementCount) {
|
2208 | const window = this._getWindow();
|
2209 | window.removeEventListener('focus', this._windowFocusListener);
|
2210 |
|
2211 | this._stopInputModalityDetector.next();
|
2212 |
|
2213 | clearTimeout(this._windowFocusTimeoutId);
|
2214 | clearTimeout(this._originTimeoutId);
|
2215 | }
|
2216 | }
|
2217 |
|
2218 | _originChanged(element, origin, elementInfo) {
|
2219 | this._setClasses(element, origin);
|
2220 | this._emitOrigin(elementInfo, origin);
|
2221 | this._lastFocusOrigin = origin;
|
2222 | }
|
2223 | |
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 | _getClosestElementsInfo(element) {
|
2229 | const results = [];
|
2230 | this._elementInfo.forEach((info, currentElement) => {
|
2231 | if (currentElement === element || (info.checkChildren && currentElement.contains(element))) {
|
2232 | results.push([currentElement, info]);
|
2233 | }
|
2234 | });
|
2235 | return results;
|
2236 | }
|
2237 | |
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 | _isLastInteractionFromInputLabel(focusEventTarget) {
|
2243 | const { _mostRecentTarget: mostRecentTarget, mostRecentModality } = this._inputModalityDetector;
|
2244 |
|
2245 |
|
2246 |
|
2247 | if (mostRecentModality !== 'mouse' ||
|
2248 | !mostRecentTarget ||
|
2249 | mostRecentTarget === focusEventTarget ||
|
2250 | (focusEventTarget.nodeName !== 'INPUT' && focusEventTarget.nodeName !== 'TEXTAREA') ||
|
2251 | focusEventTarget.disabled) {
|
2252 | return false;
|
2253 | }
|
2254 | const labels = focusEventTarget.labels;
|
2255 | if (labels) {
|
2256 | for (let i = 0; i < labels.length; i++) {
|
2257 | if (labels[i].contains(mostRecentTarget)) {
|
2258 | return true;
|
2259 | }
|
2260 | }
|
2261 | }
|
2262 | return false;
|
2263 | }
|
2264 | }
|
2265 | FocusMonitor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusMonitor, deps: [{ token: i0.NgZone }, { token: i1.Platform }, { token: InputModalityDetector }, { token: DOCUMENT, optional: true }, { token: FOCUS_MONITOR_DEFAULT_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
2266 | FocusMonitor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusMonitor, providedIn: 'root' });
|
2267 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: FocusMonitor, decorators: [{
|
2268 | type: Injectable,
|
2269 | args: [{ providedIn: 'root' }]
|
2270 | }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i1.Platform }, { type: InputModalityDetector }, { type: undefined, decorators: [{
|
2271 | type: Optional
|
2272 | }, {
|
2273 | type: Inject,
|
2274 | args: [DOCUMENT]
|
2275 | }] }, { type: undefined, decorators: [{
|
2276 | type: Optional
|
2277 | }, {
|
2278 | type: Inject,
|
2279 | args: [FOCUS_MONITOR_DEFAULT_OPTIONS]
|
2280 | }] }]; } });
|
2281 |
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 | class CdkMonitorFocus {
|
2291 | constructor(_elementRef, _focusMonitor) {
|
2292 | this._elementRef = _elementRef;
|
2293 | this._focusMonitor = _focusMonitor;
|
2294 | this.cdkFocusChange = new EventEmitter();
|
2295 | }
|
2296 | ngAfterViewInit() {
|
2297 | const element = this._elementRef.nativeElement;
|
2298 | this._monitorSubscription = this._focusMonitor
|
2299 | .monitor(element, element.nodeType === 1 && element.hasAttribute('cdkMonitorSubtreeFocus'))
|
2300 | .subscribe(origin => this.cdkFocusChange.emit(origin));
|
2301 | }
|
2302 | ngOnDestroy() {
|
2303 | this._focusMonitor.stopMonitoring(this._elementRef);
|
2304 | if (this._monitorSubscription) {
|
2305 | this._monitorSubscription.unsubscribe();
|
2306 | }
|
2307 | }
|
2308 | }
|
2309 | CdkMonitorFocus.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkMonitorFocus, deps: [{ token: i0.ElementRef }, { token: FocusMonitor }], target: i0.ɵɵFactoryTarget.Directive });
|
2310 | CdkMonitorFocus.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: CdkMonitorFocus, selector: "[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]", outputs: { cdkFocusChange: "cdkFocusChange" }, ngImport: i0 });
|
2311 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkMonitorFocus, decorators: [{
|
2312 | type: Directive,
|
2313 | args: [{
|
2314 | selector: '[cdkMonitorElementFocus], [cdkMonitorSubtreeFocus]',
|
2315 | }]
|
2316 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: FocusMonitor }]; }, propDecorators: { cdkFocusChange: [{
|
2317 | type: Output
|
2318 | }] } });
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 |
|
2328 | const BLACK_ON_WHITE_CSS_CLASS = 'cdk-high-contrast-black-on-white';
|
2329 |
|
2330 | const WHITE_ON_BLACK_CSS_CLASS = 'cdk-high-contrast-white-on-black';
|
2331 |
|
2332 | const HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS = 'cdk-high-contrast-active';
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 | class HighContrastModeDetector {
|
2345 | constructor(_platform, document) {
|
2346 | this._platform = _platform;
|
2347 | this._document = document;
|
2348 | this._breakpointSubscription = inject(BreakpointObserver)
|
2349 | .observe('(forced-colors: active)')
|
2350 | .subscribe(() => {
|
2351 | if (this._hasCheckedHighContrastMode) {
|
2352 | this._hasCheckedHighContrastMode = false;
|
2353 | this._applyBodyHighContrastModeCssClasses();
|
2354 | }
|
2355 | });
|
2356 | }
|
2357 |
|
2358 | getHighContrastMode() {
|
2359 | if (!this._platform.isBrowser) {
|
2360 | return 0 ;
|
2361 | }
|
2362 |
|
2363 |
|
2364 |
|
2365 | const testElement = this._document.createElement('div');
|
2366 | testElement.style.backgroundColor = 'rgb(1,2,3)';
|
2367 | testElement.style.position = 'absolute';
|
2368 | this._document.body.appendChild(testElement);
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 | const documentWindow = this._document.defaultView || window;
|
2374 | const computedStyle = documentWindow && documentWindow.getComputedStyle
|
2375 | ? documentWindow.getComputedStyle(testElement)
|
2376 | : null;
|
2377 | const computedColor = ((computedStyle && computedStyle.backgroundColor) || '').replace(/ /g, '');
|
2378 | testElement.remove();
|
2379 | switch (computedColor) {
|
2380 | case 'rgb(0,0,0)':
|
2381 | return 2 ;
|
2382 | case 'rgb(255,255,255)':
|
2383 | return 1 ;
|
2384 | }
|
2385 | return 0 ;
|
2386 | }
|
2387 | ngOnDestroy() {
|
2388 | this._breakpointSubscription.unsubscribe();
|
2389 | }
|
2390 |
|
2391 | _applyBodyHighContrastModeCssClasses() {
|
2392 | if (!this._hasCheckedHighContrastMode && this._platform.isBrowser && this._document.body) {
|
2393 | const bodyClasses = this._document.body.classList;
|
2394 | bodyClasses.remove(HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS, BLACK_ON_WHITE_CSS_CLASS, WHITE_ON_BLACK_CSS_CLASS);
|
2395 | this._hasCheckedHighContrastMode = true;
|
2396 | const mode = this.getHighContrastMode();
|
2397 | if (mode === 1 ) {
|
2398 | bodyClasses.add(HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS, BLACK_ON_WHITE_CSS_CLASS);
|
2399 | }
|
2400 | else if (mode === 2 ) {
|
2401 | bodyClasses.add(HIGH_CONTRAST_MODE_ACTIVE_CSS_CLASS, WHITE_ON_BLACK_CSS_CLASS);
|
2402 | }
|
2403 | }
|
2404 | }
|
2405 | }
|
2406 | HighContrastModeDetector.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: HighContrastModeDetector, deps: [{ token: i1.Platform }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
2407 | HighContrastModeDetector.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: HighContrastModeDetector, providedIn: 'root' });
|
2408 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: HighContrastModeDetector, decorators: [{
|
2409 | type: Injectable,
|
2410 | args: [{ providedIn: 'root' }]
|
2411 | }], ctorParameters: function () { return [{ type: i1.Platform }, { type: undefined, decorators: [{
|
2412 | type: Inject,
|
2413 | args: [DOCUMENT]
|
2414 | }] }]; } });
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 | class A11yModule {
|
2424 | constructor(highContrastModeDetector) {
|
2425 | highContrastModeDetector._applyBodyHighContrastModeCssClasses();
|
2426 | }
|
2427 | }
|
2428 | A11yModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: A11yModule, deps: [{ token: HighContrastModeDetector }], target: i0.ɵɵFactoryTarget.NgModule });
|
2429 | A11yModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: A11yModule, declarations: [CdkAriaLive, CdkTrapFocus, CdkMonitorFocus], imports: [ObserversModule], exports: [CdkAriaLive, CdkTrapFocus, CdkMonitorFocus] });
|
2430 | A11yModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: A11yModule, imports: [ObserversModule] });
|
2431 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: A11yModule, decorators: [{
|
2432 | type: NgModule,
|
2433 | args: [{
|
2434 | imports: [ObserversModule],
|
2435 | declarations: [CdkAriaLive, CdkTrapFocus, CdkMonitorFocus],
|
2436 | exports: [CdkAriaLive, CdkTrapFocus, CdkMonitorFocus],
|
2437 | }]
|
2438 | }], ctorParameters: function () { return [{ type: HighContrastModeDetector }]; } });
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 | export { A11yModule, ActiveDescendantKeyManager, AriaDescriber, CDK_DESCRIBEDBY_HOST_ATTRIBUTE, CDK_DESCRIBEDBY_ID_PREFIX, CdkAriaLive, CdkMonitorFocus, CdkTrapFocus, ConfigurableFocusTrap, ConfigurableFocusTrapFactory, EventListenerFocusTrapInertStrategy, FOCUS_MONITOR_DEFAULT_OPTIONS, FOCUS_TRAP_INERT_STRATEGY, FocusKeyManager, FocusMonitor, FocusTrap, FocusTrapFactory, HighContrastModeDetector, INPUT_MODALITY_DETECTOR_DEFAULT_OPTIONS, INPUT_MODALITY_DETECTOR_OPTIONS, InputModalityDetector, InteractivityChecker, IsFocusableConfig, LIVE_ANNOUNCER_DEFAULT_OPTIONS, LIVE_ANNOUNCER_ELEMENT_TOKEN, LIVE_ANNOUNCER_ELEMENT_TOKEN_FACTORY, ListKeyManager, LiveAnnouncer, MESSAGES_CONTAINER_ID, isFakeMousedownFromScreenReader, isFakeTouchstartFromScreenReader };
|
2461 |
|