@rolemodel/optics 2.6.0 → 2.6.1

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.
Binary file
package/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.6.1] - 2026-10-21
8
+
9
+ ### Theme Token Changes
10
+
11
+ - Add a `--mode` option to the contrast checker by @Jeremy-Walton in https://github.com/RoleModel/optics/pull/371
12
+ - `optics-check-contrast` takes `--mode=light` or `--mode=dark` to check only one color mode. Use it if your app forces one mode, such as with `data-theme-mode="light"`. Both modes are still checked by default. See [Contrast Checker](https://docs.optics.rolemodel.design/?path=/docs/tools-contrast-checker--docs)
13
+
14
+ ### Dependencies
15
+
16
+ - Add a `--mode` option to the contrast checker by @Jeremy-Walton in https://github.com/RoleModel/optics/pull/371
17
+ - Includes the vite bump from 8.1.4 to 8.1.6 from https://github.com/RoleModel/optics/pull/369. Development dependencies were updated in the lockfile. It does not affect the shipped CSS.
18
+
19
+ ### Documentation Changes
20
+
21
+ - Add a `--mode` option to the contrast checker by @Jeremy-Walton in https://github.com/RoleModel/optics/pull/371
22
+ - The [Contrast Checker](https://docs.optics.rolemodel.design/?path=/docs/tools-contrast-checker--docs) page lists the `--mode` option and the default for each option.
23
+
7
24
  ## [2.6.0] - 2026-10-21
8
25
 
9
26
  ### Theme Token Changes
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolemodel/optics",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "packageManager": "yarn@4.8.1",
5
5
  "description": "Optics is a css package that provides base styles and components that can be integrated and customized in a variety of projects.",
6
6
  "main": "dist/css/optics.css",
@@ -1,18 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Checks WCAG 2.1 contrast between every Optics scale step and its `on` text
4
- * colors, in light and dark mode, for your theme:
4
+ * colors, in light and dark mode (or just one, with --mode), for your theme:
5
5
  *
6
6
  * --op-color-primary-plus-five vs --op-color-primary-on-plus-five (needs --min)
7
7
  * --op-color-primary-plus-five vs --op-color-primary-on-plus-five-alt (needs --alt-min)
8
8
  *
9
9
  * Usage:
10
- * optics-check-contrast [files...] [--hsl | --oklch] [--min=4.5] [--alt-min=4.5] [--report]
10
+ * optics-check-contrast [files...] [--hsl | --oklch] [--mode=light | --mode=dark] [--min=4.5] [--alt-min=4.5] [--report]
11
11
  *
12
12
  * files CSS with your --op-* overrides: theme files, or your compiled CSS bundle.
13
13
  * They are applied on top of the Optics tokens, the last value of each token wins.
14
14
  * --hsl Check against the HSL tokens (optics.css). Detected from -s / hsl() in your files.
15
15
  * --oklch Check against the OKLCH tokens (optics-oklch.css). Detected from -c / oklch().
16
+ * --mode Check only light or dark mode. Both are checked by default.
16
17
  * --report List every pair, and don't fail.
17
18
  *
18
19
  * Tokens are read without their selectors, so overrides scoped to a class or
@@ -3,7 +3,7 @@ const ColorPair = require('./color-pair.cjs')
3
3
  const ContrastResult = require('./contrast-result.cjs')
4
4
  const ThemedColor = require('./colors/themed-color.cjs')
5
5
 
6
- // Measures every scale step against its `on` and `on-alt` text colors, in light and dark mode.
6
+ // Measures every scale step against its `on` and `on-alt` text colors, in light and dark mode, or just --mode.
7
7
  class ContrastCheck {
8
8
  #theme
9
9
  #options
@@ -15,10 +15,11 @@ class ContrastCheck {
15
15
 
16
16
  // Yields one result per pair and mode, so a report can print each one as it is measured.
17
17
  *results() {
18
+ const modes = this.#options.mode ? [this.#options.mode] : ThemedColor.MODES
18
19
  for (const pair of ColorPair.findAll(this.#theme)) {
19
20
  const background = this.#colorOf(pair.background)
20
21
  const text = this.#colorOf(pair.text)
21
- for (const mode of ThemedColor.MODES) {
22
+ for (const mode of modes) {
22
23
  const ratio = background.in(mode).contrastWith(text.in(mode))
23
24
  // NaN < min is false, so an unmeasurable pair would otherwise pass.
24
25
  if (!Number.isFinite(ratio))
@@ -19,10 +19,11 @@ class ContrastReporter {
19
19
  }
20
20
 
21
21
  finish() {
22
- const { min, altMin, report } = this.#options
22
+ const { mode, min, altMin, report } = this.#options
23
23
  const passed = this.#count - this.#failures.length
24
+ const checked = mode ? ` (${mode})` : ''
24
25
  this.#print(
25
- `Optics ${this.#build.name} contrast: ${passed}/${this.#count} pairs pass (on >= ${min}, on-alt >= ${altMin})`
26
+ `Optics ${this.#build.name} contrast${checked}: ${passed}/${this.#count} pairs pass (on >= ${min}, on-alt >= ${altMin})`
26
27
  )
27
28
  if (report || !this.#failures.length) return 0
28
29
 
@@ -1,9 +1,10 @@
1
1
  const CheckError = require('./check-error.cjs')
2
+ const ThemedColor = require('./colors/themed-color.cjs')
2
3
 
3
4
  const DEFAULT_MIN = 4.5
4
5
  const FLAG = /^--([a-z-]+)(?:=(.*))?$/
5
6
 
6
- // The command-line arguments: optics-check-contrast [files...] [--hsl | --oklch] [--min=4.5] [--alt-min=4.5] [--report]
7
+ // The command-line arguments: optics-check-contrast [files...] [--hsl | --oklch] [--mode=light | --mode=dark] [--min=4.5] [--alt-min=4.5] [--report]
7
8
  class ToolOptions {
8
9
  static parse(args) {
9
10
  const flags = {}
@@ -19,6 +20,7 @@ class ToolOptions {
19
20
  constructor(files, flags) {
20
21
  this.files = files
21
22
  this.buildName = forcedBuildName(flags)
23
+ this.mode = mode(flags.mode)
22
24
  this.min = threshold(flags.min)
23
25
  this.altMin = threshold(flags['alt-min'])
24
26
  this.report = Boolean(flags.report)
@@ -31,6 +33,11 @@ function forcedBuildName(flags) {
31
33
  return undefined
32
34
  }
33
35
 
36
+ function mode(value) {
37
+ if (value === undefined || ThemedColor.MODES.includes(value)) return value
38
+ throw new CheckError('--mode must be light or dark')
39
+ }
40
+
34
41
  function threshold(value) {
35
42
  if (value === undefined) return DEFAULT_MIN
36
43
  // A bare --min (true) or empty --min= ('') would become 1 or 0 with Number(), so require a numeric string.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolemodel/optics",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "packageManager": "yarn@4.8.1",
5
5
  "description": "Optics is a css package that provides base styles and components that can be integrated and customized in a variety of projects.",
6
6
  "main": "dist/css/optics.css",