everyhexcode 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,135 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Moltke Benjaminsen ApS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
106
+
107
+ ---
108
+
109
+ ## Third-party notices
110
+
111
+ The bundled `dist/everyhexcode.js` includes culori (https://culori.js.org), under the MIT License:
112
+
113
+ ```
114
+ MIT License
115
+
116
+ Copyright (c) 2018 Dan Burzo
117
+
118
+ Permission is hereby granted, free of charge, to any person obtaining a copy
119
+ of this software and associated documentation files (the "Software"), to deal
120
+ in the Software without restriction, including without limitation the rights
121
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
122
+ copies of the Software, and to permit persons to whom the Software is
123
+ furnished to do so, subject to the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be included in all
126
+ copies or substantial portions of the Software.
127
+
128
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
129
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
130
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
131
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
132
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
133
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
134
+ SOFTWARE.
135
+ ```
package/README.md CHANGED
@@ -1,3 +1,100 @@
1
- # Temporary Holding Version
1
+ # everyhexcode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Check the colors in your code the way people will see them. `everyhexcode` reads your CSS, SCSS, Less, Tailwind config or design tokens, works out which colors are text and which are backgrounds, and checks every pair that meets against WCAG 2, in light and dark mode. It flags status and chart colors that look alike with color blindness, and gives you the nearest passing colors as a diff of your own files.
4
+
5
+ It runs on your machine and in your own CI. Nothing is uploaded. The engine is the same one behind the [color checker on everyhexcode.com](https://everyhexcode.com/color-checker).
6
+
7
+ ```
8
+ $ npx everyhexcode check src/styles
9
+ src/styles/globals.css (css, 39 colors, light and dark)
10
+ ✗ --muted-foreground on --muted [light]: 2.7:1, needs 4.5:1 (text) src/styles/globals.css:11
11
+ fix: --muted-foreground → #6f6f77
12
+ ✗ --muted-foreground on --background [light]: 2.97:1, needs 4.5:1 (text) src/styles/globals.css:11
13
+ fix: --muted-foreground → #6f6f77
14
+ …
15
+ 24 pass, 12 fail against WCAG 2 AA
16
+ ```
17
+
18
+ ## What it reads
19
+
20
+ | Input | How pairs are found |
21
+ |---|---|
22
+ | CSS custom properties, including shadcn/ui's bare `hsl` numbers, `var()` chains, `.dark`, `[data-theme=dark]` and `prefers-color-scheme` blocks | By name: `--primary-foreground` on `--primary`, `--foreground` on `--background`, `--input` and `--ring` as input borders (3:1) |
23
+ | CSS rules | A rule that sets `color` and `background` is checked as written; `color` alone is checked on the page background; `border-color` on inputs and buttons needs 3:1 |
24
+ | SCSS `$vars`, Less `@vars` | By name, like custom properties |
25
+ | `tailwind.config.js` / `.ts`, Tailwind v4 `@theme` | The colors under `colors`, by name |
26
+ | Design tokens: W3C DTCG (`$value`, `{aliases}`), Style Dictionary, Figma variables exports | By name, aliases resolved, a `light` or `dark` level in the path read as the mode |
27
+ | A rendered page (`scan`) | Every visible text and the color actually behind it, in your own headless Chrome |
28
+
29
+ Stylesheets given together are read as one cascade, so a variable set in `tokens.css` resolves where `button.css` uses it.
30
+
31
+ ## Commands
32
+
33
+ ```
34
+ everyhexcode check [files or folders...] # default: the current folder
35
+ everyhexcode fix [files...] --write # write the nearest passing colors back, in the same format (hex stays hex, hsl stays hsl)
36
+ everyhexcode scan http://localhost:3000 # load the page in headless Chrome, light and dark, and check what it draws
37
+ ```
38
+
39
+ Options: `--target AA|AAA`, `--format text|json|sarif|markdown|github`, `--out <file>`, `--sarif <file>`, `--lock <names>` (colors the fix must not change, such as your brand color), `--fail-on fail|warn|none`, `--config <file>`, `--verbose`, `--chrome <path>`, `--width <px>`.
40
+
41
+ Exit codes: `0` all pass, `1` a pair fails, `2` a usage or read error.
42
+
43
+ ### How fixes are chosen
44
+
45
+ Each fix keeps the color's hue and chroma and moves only its lightness, in OKLCH. The checker picks the one color whose move fixes the most failing pairs with the smallest visible change (ΔE in OKLab), repeats until everything passes, and never breaks a pair that already passes. Text colors move before backgrounds, brand and accent colors last. `--lock` keeps any color where it is.
46
+
47
+ ### The rendered scan
48
+
49
+ `scan` starts your installed Chrome, Chromium or Edge headless, with a temporary profile it deletes afterwards. For every visible text it takes the backgrounds under the text's own spot, composites translucent layers, and where an image or gradient is behind the text, it hides the text, photographs the box and takes the worst tenth of what is behind it. It uses chrome-headless-shell when one is installed (`npx @puppeteer/browsers install chrome-headless-shell@stable`, into the current folder or Puppeteer's cache), else your Chrome, Chromium or Edge; `CHROME_PATH` or `--chrome` picks one. Use the shell for heavy pages: in our tests full headless Chrome stalled on stripe.com, where the shell read 600 texts in 15 s. A page that stops answering gives a partial result with a note (`--timeout`, default 150 s), and a site that blocks automated browsers (nytimes.com) is reported as having nothing to read. The GitHub Action installs the shell by itself when you give it `url:`. It needs Node 22 or newer (Node 20 with `--experimental-websocket`).
50
+
51
+ ## Settings: `colorcheck.json`
52
+
53
+ ```json
54
+ {
55
+ "files": ["src/styles", "tokens/*.json"],
56
+ "target": "AA",
57
+ "lock": ["--brand"],
58
+ "roles": { "--muted": "bg", "--highlight": "text" },
59
+ "pairs": [["--link", "--card", "text"]],
60
+ "ignore": ["--decorative-gradient-stop"],
61
+ "failOn": "fail"
62
+ }
63
+ ```
64
+
65
+ Roles are `bg`, `text`, `accent`, `border` (decoration, no minimum), `control` (input borders and focus rings, 3:1), `chart` (3:1) and `ignore`.
66
+
67
+ ## GitHub Action
68
+
69
+ ```yaml
70
+ name: Colors
71
+ on: [pull_request]
72
+ jobs:
73
+ check:
74
+ runs-on: ubuntu-latest
75
+ permissions:
76
+ contents: read
77
+ security-events: write # only for the SARIF upload
78
+ steps:
79
+ - uses: actions/checkout@v4
80
+ - uses: Benjaminsen/everyhexcode-cli@v0
81
+ with:
82
+ files: src/styles tokens
83
+ sarif: colors.sarif
84
+ - if: always()
85
+ uses: github/codeql-action/upload-sarif@v3
86
+ with:
87
+ sarif_file: colors.sarif
88
+ ```
89
+
90
+ Failing pairs show as annotations on the lines that set the color, and a summary table with the fixes lands on the job page. To check a running preview as drawn, pass `url:`. The job runs on your own runners; nothing is sent to a server.
91
+
92
+ ## What it does not do
93
+
94
+ - APCA is not included in this package. Its licence covers web content under the W3C's agreement; the [APCA contrast checker](https://everyhexcode.com/apca-contrast-checker) on the site shows it as an advisory value.
95
+ - It checks colors only, not other accessibility criteria such as alt text or keyboard use.
96
+ - A static check cannot see colors set by scripts or text over images; use `scan` for those.
97
+
98
+ ## Licence
99
+
100
+ [Functional Source License 1.1, ALv2 future licence](LICENSE.md) (FSL-1.1-ALv2): free to use, change and run for your own projects and your company's, including in CI. What it does not allow is offering it as a competing product or service. Each version becomes Apache 2.0 two years after its release. Copyright 2026 Moltke Benjaminsen ApS.
package/action.yml ADDED
@@ -0,0 +1,91 @@
1
+ name: Every Hex Code color check
2
+ description: Check the colors in your CSS, Tailwind config and design tokens against WCAG 2 contrast and color blindness, with the nearest passing colors.
3
+ author: Moltke Benjaminsen ApS
4
+ branding:
5
+ icon: droplet
6
+ color: blue
7
+ inputs:
8
+ files:
9
+ description: Files, folders or globs to check, separated by spaces. Default the "files" in colorcheck.json, else the whole repository.
10
+ required: false
11
+ default: ''
12
+ target:
13
+ description: WCAG 2 level, AA or AAA. Default the "target" in colorcheck.json, else AA.
14
+ required: false
15
+ default: ''
16
+ url:
17
+ description: Optional. A page to load in headless Chrome and check as it is drawn, such as a preview deployment or a local server started earlier in the job.
18
+ required: false
19
+ default: ''
20
+ fail-on:
21
+ description: fail (failing pairs fail the step), warn (look-alike colors too) or none. Default the "failOn" in colorcheck.json, else fail.
22
+ required: false
23
+ default: ''
24
+ config:
25
+ description: Settings file. Default colorcheck.json when it exists.
26
+ required: false
27
+ default: ''
28
+ lock:
29
+ description: Comma-separated names or hex codes the suggested fixes must not change.
30
+ required: false
31
+ default: ''
32
+ sarif:
33
+ description: Also write SARIF to this file, for github/codeql-action/upload-sarif.
34
+ required: false
35
+ default: ''
36
+ outputs:
37
+ exit-code:
38
+ description: 0 when everything passes, 1 when a pair fails, 2 on a usage or read error.
39
+ value: ${{ steps.check.outputs.exit-code }}
40
+ runs:
41
+ using: composite
42
+ steps:
43
+ - id: node
44
+ shell: bash
45
+ run: echo "major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)" >> "$GITHUB_OUTPUT"
46
+ - if: steps.node.outputs.major < 20
47
+ uses: actions/setup-node@v4
48
+ with:
49
+ node-version: 22
50
+ - id: check
51
+ shell: bash
52
+ env:
53
+ INPUT_FILES: ${{ inputs.files }}
54
+ INPUT_TARGET: ${{ inputs.target }}
55
+ INPUT_URL: ${{ inputs.url }}
56
+ INPUT_FAIL_ON: ${{ inputs.fail-on }}
57
+ INPUT_CONFIG: ${{ inputs.config }}
58
+ INPUT_LOCK: ${{ inputs.lock }}
59
+ INPUT_SARIF: ${{ inputs.sarif }}
60
+ run: |
61
+ set +e
62
+ CLI="$GITHUB_ACTION_PATH/dist/everyhexcode.js"
63
+ FLAGS=""
64
+ [ "$(node -p 'process.versions.node.split(".")[0]')" -lt 22 ] && FLAGS="--experimental-websocket"
65
+ # an input left empty leaves the setting to colorcheck.json (and the CLI's own default)
66
+ COMMON=()
67
+ [ -n "$INPUT_TARGET" ] && COMMON+=(--target "$INPUT_TARGET")
68
+ [ -n "$INPUT_FAIL_ON" ] && COMMON+=(--fail-on "$INPUT_FAIL_ON")
69
+ ARGS=("${COMMON[@]}" --format github)
70
+ [ -n "$INPUT_CONFIG" ] && ARGS+=(--config "$INPUT_CONFIG")
71
+ [ -n "$INPUT_LOCK" ] && ARGS+=(--lock "$INPUT_LOCK")
72
+ [ -n "$INPUT_SARIF" ] && ARGS+=(--sarif "$INPUT_SARIF")
73
+ read -r -a FILES <<< "$INPUT_FILES"
74
+ node $FLAGS "$CLI" check "${FILES[@]}" "${ARGS[@]}"
75
+ code=$?
76
+ if [ -n "$INPUT_URL" ] && [ -z "$CHROME_PATH" ]; then
77
+ # chrome-headless-shell scans heavy pages that full headless Chrome can stall on
78
+ SHELL_OUT=$(npx -y @puppeteer/browsers install chrome-headless-shell@stable --path "$RUNNER_TEMP/ehc-chrome" 2>/dev/null | tail -1)
79
+ CHROME_PATH="${SHELL_OUT##* }"; export CHROME_PATH
80
+ [ -x "$CHROME_PATH" ] || unset CHROME_PATH
81
+ fi
82
+ if [ -n "$INPUT_URL" ]; then
83
+ SCAN=("${COMMON[@]}" --format github)
84
+ [ -n "$INPUT_CONFIG" ] && SCAN+=(--config "$INPUT_CONFIG")
85
+ [ -n "$INPUT_SARIF" ] && SCAN+=(--sarif "${INPUT_SARIF%.sarif}-page.sarif")
86
+ node $FLAGS "$CLI" scan "$INPUT_URL" "${SCAN[@]}"
87
+ c2=$?
88
+ [ "$c2" -gt "$code" ] && code=$c2
89
+ fi
90
+ echo "exit-code=$code" >> "$GITHUB_OUTPUT"
91
+ exit $code