source: trip-planner-front/node_modules/@angular/cdk/esm2015/a11y/aria-describer/aria-describer.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 33.2 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { DOCUMENT } from '@angular/common';
9import { Inject, Injectable } from '@angular/core';
10import { addAriaReferencedId, getAriaReferenceIds, removeAriaReferencedId } from './aria-reference';
11import * as i0 from "@angular/core";
12import * as i1 from "@angular/common";
13/** ID used for the body container where all messages are appended. */
14export const MESSAGES_CONTAINER_ID = 'cdk-describedby-message-container';
15/** ID prefix used for each created message element. */
16export const CDK_DESCRIBEDBY_ID_PREFIX = 'cdk-describedby-message';
17/** Attribute given to each host element that is described by a message element. */
18export const CDK_DESCRIBEDBY_HOST_ATTRIBUTE = 'cdk-describedby-host';
19/** Global incremental identifier for each registered message element. */
20let nextId = 0;
21/** Global map of all registered message elements that have been placed into the document. */
22const messageRegistry = new Map();
23/** Container for all registered messages. */
24let messagesContainer = null;
25/**
26 * Utility that creates visually hidden elements with a message content. Useful for elements that
27 * want to use aria-describedby to further describe themselves without adding additional visual
28 * content.
29 */
30export class AriaDescriber {
31 constructor(_document) {
32 this._document = _document;
33 }
34 describe(hostElement, message, role) {
35 if (!this._canBeDescribed(hostElement, message)) {
36 return;
37 }
38 const key = getKey(message, role);
39 if (typeof message !== 'string') {
40 // We need to ensure that the element has an ID.
41 setMessageId(message);
42 messageRegistry.set(key, { messageElement: message, referenceCount: 0 });
43 }
44 else if (!messageRegistry.has(key)) {
45 this._createMessageElement(message, role);
46 }
47 if (!this._isElementDescribedByMessage(hostElement, key)) {
48 this._addMessageReference(hostElement, key);
49 }
50 }
51 removeDescription(hostElement, message, role) {
52 if (!message || !this._isElementNode(hostElement)) {
53 return;
54 }
55 const key = getKey(message, role);
56 if (this._isElementDescribedByMessage(hostElement, key)) {
57 this._removeMessageReference(hostElement, key);
58 }
59 // If the message is a string, it means that it's one that we created for the
60 // consumer so we can remove it safely, otherwise we should leave it in place.
61 if (typeof message === 'string') {
62 const registeredMessage = messageRegistry.get(key);
63 if (registeredMessage && registeredMessage.referenceCount === 0) {
64 this._deleteMessageElement(key);
65 }
66 }
67 if (messagesContainer && messagesContainer.childNodes.length === 0) {
68 this._deleteMessagesContainer();
69 }
70 }
71 /** Unregisters all created message elements and removes the message container. */
72 ngOnDestroy() {
73 const describedElements = this._document.querySelectorAll(`[${CDK_DESCRIBEDBY_HOST_ATTRIBUTE}]`);
74 for (let i = 0; i < describedElements.length; i++) {
75 this._removeCdkDescribedByReferenceIds(describedElements[i]);
76 describedElements[i].removeAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE);
77 }
78 if (messagesContainer) {
79 this._deleteMessagesContainer();
80 }
81 messageRegistry.clear();
82 }
83 /**
84 * Creates a new element in the visually hidden message container element with the message
85 * as its content and adds it to the message registry.
86 */
87 _createMessageElement(message, role) {
88 const messageElement = this._document.createElement('div');
89 setMessageId(messageElement);
90 messageElement.textContent = message;
91 if (role) {
92 messageElement.setAttribute('role', role);
93 }
94 this._createMessagesContainer();
95 messagesContainer.appendChild(messageElement);
96 messageRegistry.set(getKey(message, role), { messageElement, referenceCount: 0 });
97 }
98 /** Deletes the message element from the global messages container. */
99 _deleteMessageElement(key) {
100 const registeredMessage = messageRegistry.get(key);
101 const messageElement = registeredMessage && registeredMessage.messageElement;
102 if (messagesContainer && messageElement) {
103 messagesContainer.removeChild(messageElement);
104 }
105 messageRegistry.delete(key);
106 }
107 /** Creates the global container for all aria-describedby messages. */
108 _createMessagesContainer() {
109 if (!messagesContainer) {
110 const preExistingContainer = this._document.getElementById(MESSAGES_CONTAINER_ID);
111 // When going from the server to the client, we may end up in a situation where there's
112 // already a container on the page, but we don't have a reference to it. Clear the
113 // old container so we don't get duplicates. Doing this, instead of emptying the previous
114 // container, should be slightly faster.
115 if (preExistingContainer && preExistingContainer.parentNode) {
116 preExistingContainer.parentNode.removeChild(preExistingContainer);
117 }
118 messagesContainer = this._document.createElement('div');
119 messagesContainer.id = MESSAGES_CONTAINER_ID;
120 // We add `visibility: hidden` in order to prevent text in this container from
121 // being searchable by the browser's Ctrl + F functionality.
122 // Screen-readers will still read the description for elements with aria-describedby even
123 // when the description element is not visible.
124 messagesContainer.style.visibility = 'hidden';
125 // Even though we use `visibility: hidden`, we still apply `cdk-visually-hidden` so that
126 // the description element doesn't impact page layout.
127 messagesContainer.classList.add('cdk-visually-hidden');
128 this._document.body.appendChild(messagesContainer);
129 }
130 }
131 /** Deletes the global messages container. */
132 _deleteMessagesContainer() {
133 if (messagesContainer && messagesContainer.parentNode) {
134 messagesContainer.parentNode.removeChild(messagesContainer);
135 messagesContainer = null;
136 }
137 }
138 /** Removes all cdk-describedby messages that are hosted through the element. */
139 _removeCdkDescribedByReferenceIds(element) {
140 // Remove all aria-describedby reference IDs that are prefixed by CDK_DESCRIBEDBY_ID_PREFIX
141 const originalReferenceIds = getAriaReferenceIds(element, 'aria-describedby')
142 .filter(id => id.indexOf(CDK_DESCRIBEDBY_ID_PREFIX) != 0);
143 element.setAttribute('aria-describedby', originalReferenceIds.join(' '));
144 }
145 /**
146 * Adds a message reference to the element using aria-describedby and increments the registered
147 * message's reference count.
148 */
149 _addMessageReference(element, key) {
150 const registeredMessage = messageRegistry.get(key);
151 // Add the aria-describedby reference and set the
152 // describedby_host attribute to mark the element.
153 addAriaReferencedId(element, 'aria-describedby', registeredMessage.messageElement.id);
154 element.setAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE, '');
155 registeredMessage.referenceCount++;
156 }
157 /**
158 * Removes a message reference from the element using aria-describedby
159 * and decrements the registered message's reference count.
160 */
161 _removeMessageReference(element, key) {
162 const registeredMessage = messageRegistry.get(key);
163 registeredMessage.referenceCount--;
164 removeAriaReferencedId(element, 'aria-describedby', registeredMessage.messageElement.id);
165 element.removeAttribute(CDK_DESCRIBEDBY_HOST_ATTRIBUTE);
166 }
167 /** Returns true if the element has been described by the provided message ID. */
168 _isElementDescribedByMessage(element, key) {
169 const referenceIds = getAriaReferenceIds(element, 'aria-describedby');
170 const registeredMessage = messageRegistry.get(key);
171 const messageId = registeredMessage && registeredMessage.messageElement.id;
172 return !!messageId && referenceIds.indexOf(messageId) != -1;
173 }
174 /** Determines whether a message can be described on a particular element. */
175 _canBeDescribed(element, message) {
176 if (!this._isElementNode(element)) {
177 return false;
178 }
179 if (message && typeof message === 'object') {
180 // We'd have to make some assumptions about the description element's text, if the consumer
181 // passed in an element. Assume that if an element is passed in, the consumer has verified
182 // that it can be used as a description.
183 return true;
184 }
185 const trimmedMessage = message == null ? '' : `${message}`.trim();
186 const ariaLabel = element.getAttribute('aria-label');
187 // We shouldn't set descriptions if they're exactly the same as the `aria-label` of the
188 // element, because screen readers will end up reading out the same text twice in a row.
189 return trimmedMessage ? (!ariaLabel || ariaLabel.trim() !== trimmedMessage) : false;
190 }
191 /** Checks whether a node is an Element node. */
192 _isElementNode(element) {
193 return element.nodeType === this._document.ELEMENT_NODE;
194 }
195}
196AriaDescriber.ɵprov = i0.ɵɵdefineInjectable({ factory: function AriaDescriber_Factory() { return new AriaDescriber(i0.ɵɵinject(i1.DOCUMENT)); }, token: AriaDescriber, providedIn: "root" });
197AriaDescriber.decorators = [
198 { type: Injectable, args: [{ providedIn: 'root' },] }
199];
200AriaDescriber.ctorParameters = () => [
201 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
202];
203/** Gets a key that can be used to look messages up in the registry. */
204function getKey(message, role) {
205 return typeof message === 'string' ? `${role || ''}/${message}` : message;
206}
207/** Assigns a unique ID to an element, if it doesn't have one already. */
208function setMessageId(element) {
209 if (!element.id) {
210 element.id = `${CDK_DESCRIBEDBY_ID_PREFIX}-${nextId++}`;
211 }
212}
213//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIj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