import { BaseOutput } from './base-output'; export class AriaOutput extends BaseOutput { constructor(options = {}) { super(); this.timeout = 100; this.timeout = options.timeout || 100; this.init(); } init() { this.container = document.createElement('div'); this.container.setAttribute('aria-live', 'polite'); this.speechDisplay = document.createElement('div'); this.speechDisplay.setAttribute('aria-live', 'polite'); this.container.append(this.speechDisplay); document.body.appendChild(this.container); document.body.insertBefore(this.container, document.body.firstChild); } speak(text) { this.clearDisplay(); const node = document.createTextNode(text); const para = document.createElement('p'); para.appendChild(node); this.speechDisplay.appendChild(para); setTimeout(this.clearDisplay.bind(this), this.timeout); } stop() { this.clearDisplay(); } clearDisplay() { this.speechDisplay.innerHTML = ''; } }