Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
giamir committed Oct 12, 2023
0 parents commit 00cc1a5
Show file tree
Hide file tree
Showing 13 changed files with 6,717 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "prettier"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
"prettier/prettier": "error",
},
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.DS_Store
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"quoteProps": "consistent",
"printWidth": 80,
"endOfLine": "auto"
}
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright 2023 Stack Exchange Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# axe-apca

This package contains custom axe rules and checks for [APCA](https://readtech.org/) Bronze and Silver+ [conformance levels](https://readtech.org/ARC/tests/visual-readability-contrast/?tn=criterion).

## Usage

### Installation

```bash
npm install --save-dev axe-core axe-apca
```

### Setup

```js
import axe from "axe-core";
import { registerAxeAPCA } from 'axe-apca';

registerAxeAPCA('bronze'); // or registerAxeAPCA('silver');

// consider turning off default WCAG 2.2 AA color contrast rules when using APCA
axe.configure({
rules: [{ id: "color-contrast", enabled: false }]
})

axe.run(document, (err, results) => {
if (err) throw err;
console.log(results);
});
```

### Using custom APCA thresholds

To set custom thresholds for APCA checks, follow these steps:

1. Use `custom` as the first argument when calling `registerAxeAPCA`.
1. Provide a function as the second argument, optionally accepting `fontSize` and `fontWeight` arguments.


```js
const customConformanceThresholdFn = (fontSize, fontWeight) => {
const size = parseFloat(fontSize);
const weight = parseFloat(fontWeight);

return size >= 32 || weight > 700 ? 45 : 60;
};

registerAxeAPCA('custom', customConformanceThresholdFn);
```

## Development

### Prerequisites

- Node.js v18+

### Linting
To run eslint (including prettier as a formatter) you can run
```
npm run lint
```
To have eslint fix any autofixable issue run
```
npm run lint:fix
```

### Testing

Tests are run by web-test-runner in combination with playwright against chromium, firefox and webkit

```
npm run test
```

For watch mode
```
npm run test:watch
```

### Publishing

TBC

## License
Copyright 2023 Stack Exchange, Inc and released under the [MIT License](/LICENSE.MD).
Loading

0 comments on commit 00cc1a5

Please sign in to comment.