Skip to content

hrobertking/roking-a11y

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

roking-a11y

Accessibility tools

Color

The Color object automatically converts between the three different color specifications: a hexadecimal number, an object with red, green, and blue values, and an object with hue, saturation, and lightness values and simplifies modification of the values.

Constructor

new Color([**_hcolor|rgb|hsl_**])

Internal Data Types

  • tinyint: A number between 0 and 255

  • hcolor: A 6-digit hexadecimal string with red in the first two digits, green in the third and fourth digits, and blue in the fifth and sixth digits or a 3-digit hexadecimal string with red in the first digit, green in the second digit, and blue in the third digit. If the 3-digit length is used, the digits are expanded by repitition. For example, if the value is 'ABC', the expanded value is 'AABBCC'.

  • rgb: An object with red, green, and blue values.

    • tinyint blue
    • tinyint green
    • tinyint red
  • hsl: An object with hue, lightness, and saturation.

    • number|string hue: The attribute of a visual sensation according to which an area appears to be similar to one of the perceived colors: red, yellow, green, and blue, or to a combination of two of them.
    • number|string lightness: The brightness relative to the brightness of a similarly illuminated white.
    • number|string saturation: The colorfulness of a stimulus relative to its own brightness.

Properties

  • tinyint blue: The blue portion of the color.
  • boolean canDarken: The color value can be darkened.
  • boolean canLighten: The color value can be lightened.
  • tinyint green: The green portion of the color.
  • hcolor hcolor The rgb value expressed as a 6-digit hexadecimal.
  • number hue: The attribute of a visual sensation according to which an area appears to be similar to one of the perceived colors: red, yellow, green, and blue, or to a combination of two of them.
  • tinyint lightness: The brightness relative to the brightness of a similarly illuminated white.
  • number luminance: A number between 0 and 100 (inclusive) representing the luminance of a color. The formulae used to determine luminance are those specified by the WCAG and can be found at https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef and https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests.
  • tinyint red: The red portion of the color.
  • number saturation: The colorfulness of a stimulus relative to its own brightness.

Methods

  • Color darken([integer amount]): Darkens the color the specified amount, setting the color to black when color is undefined.
  • Color lighten([integer amount]): Lightens the color the specified amount, setting the color to white when color is undefined.
  • boolean isColorType(any data): Returns true if the provided data is one of hcolor, rgb, or hsl.
  • HColor toString(): Returns the current value of the Color as an hcolor string.

Luminance

The Luminance object allows for easy generation of a contrast ratio, enabling comparison of two color definitions - background and foreground. Additionally, the contrast ratio can be tested against a threshold object.

Constructor

new Luminance([**_Color|LuminanceConfig_** foreground[, **_Color_** background]])

Internal Data Types

  • LuminanceConfig: A configuration object
    • Color background
    • Color foreground

Properties

Methods

  • LuminanceMatrix matrix(): Builds a contrast matrix for the palette provided. Palette can be provided as an array of colors or as individual colors, e.g., matrix(new Color('#fff'), ['#f00', '#ff0']).
  • Luminance reset(): Resets the Colors to their initial value.
  • Luminance search(number level[, Color isolate]): Adjusts either the Color(s) until the value cannot be adjusted further or the specified contrast level is reached. Adjustments may be isolated to either the foreground or the background using the isolate parameter.
  • boolean test(number level): Returns true if the contrast is greater than or equal to the provided level
  • string toHtml(): Uses matrix to generate a LuminanceMatrix object and converts it to an HTML table.

Readability

The Readability utility calculates the Läsbarhetsindex for content.

The current version of the Readability object does not account for phrases that are not complete sentences, so some measure of caution should be used. For example, the phrase "Last Name" would have a Läsbarhetsindex score of 2, but the the phrase "Surname" would have a Läsbarhetsindex score of 101, even though its complexity would not ordinarily be consider that much greater. I am currently working to determine how best to accommodate this.

Constructor

new Readability([**_string|string[]|HTMLElement|ConfigObject_ text**][, **_number_ size**][, **_string_** lang])
  • text: content to evaluate
  • size: length of a longword, defaults to 6 characters
  • lang: a BCP-47 langtag or an ISO 639-1 language code.

Internal Data Types

  • ConfigObject: A configuration object

    • string lang: A BCP-47 langtag or a ISO 639-1 language code.
    • number size: The character length of a longword.
    • string|string[]|HTMLElement text: The content to be parsed.
  • ScoredItem: A scored phrase

    • number longwords: The number of words with a length greater-than or equal-to wlong.
    • string phrase: The phrase that has been evaluated.
    • number score: The Läsbarhetsindex score for the phrase.
    • number sentences: The number of sentences in the phrase.
    • number words: The number of words in the phrase.

Properties

  • number avg: The average Läsbarhetsindex for all parsed content. READ-ONLY
  • string|string[]|HTMLElement content: Raw content to be evaluated.
  • string lang: BCP-47 langtag or an ISO 639-1 language code for content.
  • ScoredItem[] parsed: Phrases parsed into scored items, set by setting content or passing content to the score method. READ-ONLY
  • number_ wlong: The length, in characters, a word must be to be a long word. Defaults to 6 characters.

Methods

  • ScoredItem item(number index): Returns a scored item from the parsed collection.
  • number score([string|string[]|HTMLElement content]): Calculates and returns the Läsbarhetsindex for the specified content.

About

Accessibility tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published