npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

screen-reader-bridge

v1.0.0

Published

A simple interface for making a variety of screen reader and browser combinations speak using an ARIA live region.

Downloads

6

Readme

ScreenReaderBridge

A simple interface for making a variety of screen reader and browser combinations speak using an ARIA live region.

Description

This package contains a single TypeScript class which handles manipulating an ARIA live region so that screen reading software will read out the text when desired. It will work with a number of different screen readers, screen reader versions, and browsers. The class includes a static method which will automatically configure the correct ARIA tags so things work as they should.

This does not create audio to play using the WebAudioAPI, nor does it use the WebSpeechAPI. The end-user must have a screen reader (e.g. Jaws, NVDA, VoiceOver, etc.) running to hear any output.

Useage

// Create or get a "div" element which will be used as the region.
let divElement = document.getElementById("MyDiv");
// Apply the ARIA attributes automatically.
ScreenReaderBridge.addAriaAttributes(divElement);
// Create the ScreenReaderBridge object.
let srb = new ScreenReaderBridge(divElement);
// Call srb.render to have screen readers speak the text.
srb.render("Hello, World!");

API notes

Here is a list of attributes and methods available on the ScreenReaderBridge object in TypeScript notation.

/**
 * A class that will handle passing text to screen readers to speak.
 * When a user of this class passes in a "caption" element, the renderer will add a child element to the caption for
 * each string that the screen reader should speak. The renderer will also remove old child nodes when a new string is
 * spoken.
 * The "caption" element must have a specific list of aria attributes to properly work, see the static method
 * "addAriaAttributes" for more details.
*/
declare class ScreenReaderBridge {

    /**
     * Automatically add the required aria attributes to an element for screen readers to properly work.
     * In order for the greatest number of screen reader and browser combinations to work, the following attributes will
     * be set on the element:
     * aria-live: assertive
     * roll: status
     * aria-atomic: true
     * aria-relevant: additions text
     *   For the aria-live attribute, "polite" may also work, but that will create a queue of messages for the screen
     *   reader to read out one after another which is probably not what you want.
     *
     * @param element - the "caption" element which will host the messages for the screen reader to speak
     * @param [ariaLive="assertive"] - the politeness of the aria-live attribute, one of "off", "assertive", or "polite"
     * @static
    */
    static addAriaAttributes(element: HTMLElement, ariaLive?: string): void;

    /**
     * Create a ScreenReaderBridge instance.
     *
     * @param captionElement - the "caption" element, typically a span or div element
    */
    constructor(captionElement: HTMLElement);

    /**
     * The last created child element of the "caption" element.
     * This is typically used for debugging and automated testing.
    */
    get lastCreatedElement(): HTMLElement | null;

    /**
     * Clear the contents of the live region.
     * You normally do not have to call this yourself since calls to the render method will automatically clean up old text.
    */
    clear(): void;

    /**
     * Speak the provided text.
     *
     * @param text - the text to speak
    */
    render(text: string): void;
}

Contributing and building from source

Download/clone this repository. To install needed packages and build, run the following:

npm install
npm run build

When you want to clean your workspace, run the following:

npm run clean

Contributions and bug reports are very welcome via pull requests and opening issues.