An open source design system that's fully customizable and agent ready
TypeScript
fix(core): preserve control state indication under forced colors (#4352)
Baraa Hamodi3ff5e18aab13
diff --git a/.changeset/a11y-forced-colors.md b/.changeset/a11y-forced-colors.mdnew file mode 100644index 0000000000..2f3c7c6b3b--- /dev/null+++ b/.changeset/a11y-forced-colors.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] core: preserve state indication for painted controls (Switch, CheckboxInput, RadioList, SegmentedControl, ToggleButton, Skeleton) under forced colors / Windows High Contrast (WCAG 1.4.11)+@bhamodidiff --git a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx b/packages/core/src/CheckboxInput/CheckboxInput.test.tsxindex 25064170df..d05ba298fd 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.test.tsx@@ -13,6 +13,7 @@ import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';import {render, screen, fireEvent, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {CheckboxInput} from './CheckboxInput';+import {getForcedColorsRules} from '../__tests__/forcedColors';import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';afterEach(() => {@@ -543,3 +544,25 @@ describe('CheckboxInput', () => {});});});++// jsdom cannot emulate forced-colors rendering, so this asserts that the+// compiled output includes the forced-colors rule; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles a forced-colors fill so the indeterminate mark survives Windows High Contrast', () => {+ render(+ <CheckboxInput label="All" value="indeterminate" onChange={() => {}} />,+ );+ // The painted indeterminate bar would be stripped to Canvas (invisible);+ // CanvasText keeps it perceivable.+ expect(getForcedColorsRules()).toContain('background-color: canvastext;');+ });++ it('compiles a forced-colors color so the checkmark survives Windows High Contrast', () => {+ render(<CheckboxInput label="Accept" value={true} onChange={() => {}} />);+ // The check strokes with currentColor; forced colors leaves it the same+ // white as the flattened box, so it needs its own CanvasText color to stay+ // perceivable on the Canvas box.+ expect(getForcedColorsRules()).toContain('color: canvastext;');+ });+});diff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsxindex b916270d50..0d36b73ea2 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx@@ -158,14 +158,29 @@ const styles = stylex.create({},checkmark: {display: 'none',- color: colorVars['--color-on-accent'],+ color: {+ default: colorVars['--color-on-accent'],+ // Forced colors (Windows High Contrast) does not reliably force an SVG+ // stroke painted with currentColor, so the check stays the same white as+ // the flattened (Canvas) box fill — a white check on a white box.+ // CanvasText keeps it perceivable on the Canvas box, matching the+ // indeterminate mark (WCAG 1.4.11).+ '@media (forced-colors: active)': 'CanvasText',+ },},checkmarkVisible: {display: 'block',},indeterminateMark: {display: 'none',- backgroundColor: colorVars['--color-on-accent'],+ backgroundColor: {+ default: colorVars['--color-on-accent'],+ // Forced colors (Windows High Contrast) strips painted backgrounds,+ // which would make the indeterminate bar invisible; CanvasText keeps it+ // perceivable on the Canvas box fill (WCAG 1.4.11). The checkmark carries+ // the matching CanvasText treatment on its own style.+ '@media (forced-colors: active)': 'CanvasText',+ },borderRadius: radiusVars['--radius-full'],},indeterminateMarkVisible: {diff --git a/packages/core/src/RadioList/RadioList.test.tsx b/packages/core/src/RadioList/RadioList.test.tsxindex d6af05d6f9..1f59da0b31 100644--- a/packages/core/src/RadioList/RadioList.test.tsx+++ b/packages/core/src/RadioList/RadioList.test.tsx@@ -14,6 +14,7 @@ import {render, screen, fireEvent, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {RadioList} from './RadioList';import {RadioListItem} from './RadioListItem';+import {getForcedColorsRules} from '../__tests__/forcedColors';// Mock showPopover/hidePopover (not implemented in jsdom) so the tooltip layer// reflects its open state via a `popover-open` attribute the tests can assert.@@ -580,7 +581,11 @@ describe('RadioList', () => {it('submits the selected value under htmlName', () => {const {container} = render(<form>- <RadioList label="Preference" htmlName="pref" value="b" onChange={() => {}}>+ <RadioList+ label="Preference"+ htmlName="pref"+ value="b"+ onChange={() => {}}><RadioListItem label="Option A" value="a" /><RadioListItem label="Option B" value="b" /></RadioList>@@ -599,13 +604,14 @@ describe('RadioList', () => {value="a"onChange={() => {}}isDisabled- disabledMessage="Locked"- >+ disabledMessage="Locked"><RadioListItem label="Option A" value="a" /></RadioList></form>,);- expect([...new FormData(container.querySelector('form')!).keys()]).toEqual([]);+ expect([+ ...new FormData(container.querySelector('form')!).keys(),+ ]).toEqual([]);});it('keeps working as an isolated group when htmlName is omitted', () => {@@ -642,3 +648,19 @@ describe('RadioList', () => {});});});++// jsdom cannot emulate forced-colors rendering, so this asserts that the+// compiled output includes the forced-colors rule; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles a forced-colors fill so the selected dot survives Windows High Contrast', () => {+ render(+ <RadioList label="Preference" value="a" onChange={() => {}}>+ <RadioListItem label="Option A" value="a" />+ </RadioList>,+ );+ // The painted inner dot would be stripped to Canvas (invisible), making+ // checked and unchecked radios identical; CanvasText keeps it perceivable.+ expect(getForcedColorsRules()).toContain('background-color: canvastext;');+ });+});diff --git a/packages/core/src/RadioList/RadioListItem.tsx b/packages/core/src/RadioList/RadioListItem.tsxindex c0f75e1d50..768733c554 100644--- a/packages/core/src/RadioList/RadioListItem.tsx+++ b/packages/core/src/RadioList/RadioListItem.tsx@@ -119,7 +119,14 @@ const styles = stylex.create({},innerDot: {borderRadius: '50%',- backgroundColor: colorVars['--color-on-accent'],+ backgroundColor: {+ default: colorVars['--color-on-accent'],+ // Forced colors (Windows High Contrast) strips painted backgrounds,+ // which would make the selected dot invisible — checked and unchecked+ // radios would look identical. CanvasText keeps the dot perceivable on+ // the Canvas circle fill (WCAG 1.4.11).+ '@media (forced-colors: active)': 'CanvasText',+ },},labelDisabled: {color: colorVars['--color-text-disabled'],diff --git a/packages/core/src/SegmentedControl/SegmentedControl.test.tsx b/packages/core/src/SegmentedControl/SegmentedControl.test.tsxindex 148de6b4a6..ed58f4722b 100644--- a/packages/core/src/SegmentedControl/SegmentedControl.test.tsx+++ b/packages/core/src/SegmentedControl/SegmentedControl.test.tsx@@ -14,6 +14,10 @@ import {render, screen, fireEvent, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {SegmentedControl} from './SegmentedControl';import {SegmentedControlItem} from './SegmentedControlItem';+import {+ getAllInjectedCss,+ getForcedColorsRules,+} from '../__tests__/forcedColors';// Mock showPopover/hidePopover (not implemented in jsdom) so the tooltip layer// reflects its open state via a `popover-open` attribute the tests can assert.@@ -780,3 +784,27 @@ describe('SegmentedControl container handler forwarding', () => {expect(onChange).not.toHaveBeenCalled();});});++// jsdom cannot emulate forced-colors rendering, so these assert that the+// compiled output includes the forced-colors rules; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles forced-colors overrides so the selected segment survives Windows High Contrast', () => {+ render(+ <SegmentedControl value="grid" onChange={() => {}} label="View mode">+ <SegmentedControlItem value="grid" label="Grid" />+ <SegmentedControlItem value="list" label="List" />+ </SegmentedControl>,+ );+ const css = getForcedColorsRules();+ // The painted surface fill and shadow are stripped; Highlight/+ // HighlightText marks the selected segment.+ expect(css).toContain('background-color: highlight;');+ expect(css).toContain('color: highlighttext;');+ // The segment is a <button>; without opting out of UA remapping it keeps+ // the native ButtonFace surface and ignores the Highlight fill, leaving+ // HighlightText text on a white surface. forced-color-adjust: none makes+ // both render as authored.+ expect(getAllInjectedCss()).toContain('forced-color-adjust: none;');+ });+});diff --git a/packages/core/src/SegmentedControl/SegmentedControlItem.tsx b/packages/core/src/SegmentedControl/SegmentedControlItem.tsxindex 21752e41d6..b372ce41fe 100644--- a/packages/core/src/SegmentedControl/SegmentedControlItem.tsx+++ b/packages/core/src/SegmentedControl/SegmentedControlItem.tsx@@ -103,9 +103,27 @@ const styles = stylex.create({},},selected: {- color: colorVars['--color-text-primary'],+ // Forced colors (Windows High Contrast) strips the painted surface fill+ // and box shadow, which would leave the selected segment with no state+ // indication beyond font weight. Highlight/HighlightText is the platform+ // convention for a selected item (WCAG 1.4.11).+ //+ // forced-color-adjust must be `none` here: the segment is a <button>, and+ // the UA keeps native form-control colors (ButtonFace surface) for it under+ // forced colors, ignoring the authored Highlight fill — the label kept its+ // HighlightText color, giving white text on a white surface. Opting the+ // selected segment out of UA remapping makes both the Highlight surface and+ // the HighlightText label render as authored, restoring figure-ground.+ forcedColorAdjust: 'none',+ color: {+ default: colorVars['--color-text-primary'],+ '@media (forced-colors: active)': 'HighlightText',+ },fontWeight: fontWeightVars['--font-weight-semibold'],- backgroundColor: colorVars['--color-background-surface'],+ backgroundColor: {+ default: colorVars['--color-background-surface'],+ '@media (forced-colors: active)': 'Highlight',+ },boxShadow: shadowVars['--shadow-low'],},disabled: {diff --git a/packages/core/src/Skeleton/Skeleton.test.tsx b/packages/core/src/Skeleton/Skeleton.test.tsxindex f2992c3cdc..3407d94af4 100644--- a/packages/core/src/Skeleton/Skeleton.test.tsx+++ b/packages/core/src/Skeleton/Skeleton.test.tsx@@ -3,6 +3,7 @@import {describe, it, expect} from 'vitest';import {render, screen} from '@testing-library/react';import {Skeleton} from './Skeleton';+import {getForcedColorsRules} from '../__tests__/forcedColors';describe('Skeleton', () => {it('renders a placeholder element', () => {@@ -23,3 +24,18 @@ describe('Skeleton', () => {expect(screen.getByTestId('sk')).toHaveAttribute('aria-hidden', 'false');});});++// jsdom cannot emulate forced-colors rendering, so these assert that the+// compiled output includes the forced-colors rules; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles forced-colors overrides so the placeholder stays visible under Windows High Contrast', () => {+ render(<Skeleton width={200} height={20} data-testid="sk" />);+ const css = getForcedColorsRules();+ // The painted fill is stripped to Canvas (invisible); GrayText is a+ // system color, so it survives forcing.+ expect(css).toContain('background-color: graytext;');+ // The resting 0.25 opacity is lifted so the static placeholder reads.+ expect(css).toContain('opacity: 1;');+ });+});diff --git a/packages/core/src/Skeleton/Skeleton.tsx b/packages/core/src/Skeleton/Skeleton.tsxindex 5ab5c358c1..84f3a0717e 100644--- a/packages/core/src/Skeleton/Skeleton.tsx+++ b/packages/core/src/Skeleton/Skeleton.tsx@@ -55,8 +55,20 @@ const styles = stylex.create({backgroundColor: {default: colorVars['--color-skeleton'],'@media (prefers-contrast: more)': `color-mix(in srgb, ${colorVars['--color-skeleton']}, ${colorVars['--color-text-primary']} 30%)`,+ // Forced colors (Windows High Contrast) strips painted backgrounds,+ // which would make the placeholder invisible. GrayText is a system+ // color, so it survives forcing and keeps the placeholder visible+ // (WCAG 1.4.11). Listed after prefers-contrast so it wins when both+ // media features are active.+ '@media (forced-colors: active)': 'GrayText',+ },+ opacity: {+ default: 0.25,+ // The resting 0.25 opacity would render GrayText nearly invisible on+ // Canvas; full opacity keeps the static placeholder perceivable (the+ // fade animation still pulses when motion is allowed).+ '@media (forced-colors: active)': 1,},- opacity: 0.25,},animate: {animationDirection: 'alternate',diff --git a/packages/core/src/Switch/Switch.test.tsx b/packages/core/src/Switch/Switch.test.tsxindex 55676752d0..cc6c9d49be 100644--- a/packages/core/src/Switch/Switch.test.tsx+++ b/packages/core/src/Switch/Switch.test.tsx@@ -13,6 +13,10 @@ import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';import {render, screen, fireEvent, waitFor} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {Switch} from './Switch';+import {+ getAllInjectedCss,+ getForcedColorsRules,+} from '../__tests__/forcedColors';import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';afterEach(() => {@@ -729,3 +733,36 @@ describe('Switch', () => {});});});++// jsdom cannot emulate forced-colors rendering, so these assert that the+// compiled output includes the forced-colors rules; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles forced-colors overrides so on/off state survives Windows High Contrast', () => {+ render(<Switch label="Notifications" value={true} onChange={() => {}} />);+ const css = getForcedColorsRules();+ // Track outline (backgrounds are stripped; the border keeps the bounds).+ expect(css).toContain('border-color: canvastext;');+ // Off track stays empty; on track uses the selection color.+ expect(css).toContain('background-color: canvas;');+ expect(css).toContain('background-color: highlight;');+ // Thumb fill per state.+ expect(css).toContain('background-color: canvastext;');+ expect(css).toContain('background-color: highlighttext;');+ // Disabled affordance (opacity dimming does not survive forcing).+ expect(css).toContain('border-color: graytext;');+ });++ it('gates the hover tint out of forced colors so the thumb stays visible on hover', () => {+ render(<Switch label="Notifications" value={true} onChange={() => {}} />);+ // The ancestor-hover tint is a non-system color-mix whose rule outranks the+ // plain forced-colors track rule. It is gated behind `forced-colors: none`+ // so it cannot reassert on hover and flatten the Highlight track to white+ // under the HighlightText thumb (white-on-white).+ expect(getAllInjectedCss()).toContain(+ '(hover: hover) and (forced-colors: none)',+ );+ // And the tint never leaks into the forced-colors output.+ expect(getForcedColorsRules()).not.toContain('color-mix');+ });+});diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsxindex 7a697a26a4..07479eeae0 100644--- a/packages/core/src/Switch/Switch.tsx+++ b/packages/core/src/Switch/Switch.tsx@@ -173,6 +173,21 @@ const styles = stylex.create({},transitionTimingFunction: easeVars['--ease-standard'],boxSizing: 'border-box',+ // Forced colors (Windows High Contrast) strips painted backgrounds, which+ // would leave the track invisible. A system-color border keeps the+ // control's bounds perceivable (WCAG 1.4.11).+ borderWidth: {+ default: 0,+ '@media (forced-colors: active)': '1px',+ },+ borderStyle: {+ default: 'none',+ '@media (forced-colors: active)': 'solid',+ },+ borderColor: {+ default: null,+ '@media (forced-colors: active)': 'CanvasText',+ },},trackFocus: {outline: {@@ -189,21 +204,39 @@ const styles = stylex.create({trackOff: {backgroundColor: {default: colorVars['--color-background-gray'],+ // Off = empty (Canvas) track; on = Highlight track, so the two states+ // stay distinguishable under forced colors.+ '@media (forced-colors: active)': 'Canvas',+ // The ancestor-hover tint is a non-system color-mix, and its rule+ // outranks the plain forced-colors rule above. Left ungated it would+ // reassert on hover under forced colors, where the UA flattens the+ // color-mix back to Canvas — so the HighlightText thumb would sit on a+ // white track (white-on-white). Gating on `forced-colors: none` keeps+ // the tint out of forced colors and lets the system-color track stand.[stylex.when.ancestor(':hover', switchScope)]: {- '@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-background-gray']}, ${colorVars['--color-tint-hover']} 5%)`,+ '@media (hover: hover) and (forced-colors: none)': `color-mix(in srgb, ${colorVars['--color-background-gray']}, ${colorVars['--color-tint-hover']} 5%)`,},},},trackOn: {backgroundColor: {default: colorVars['--color-accent'],+ '@media (forced-colors: active)': 'Highlight',+ // See trackOff: gate the hover tint out of forced colors so it cannot+ // flatten the Highlight track to white under the HighlightText thumb.[stylex.when.ancestor(':hover', switchScope)]: {- '@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,+ '@media (hover: hover) and (forced-colors: none)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},},trackDisabled: {opacity: 0.5,+ // Opacity dimming does not survive forced colors; GrayText is the+ // platform's disabled affordance there.+ borderColor: {+ default: null,+ '@media (forced-colors: active)': 'GrayText',+ },},trackDisabledOff: {backgroundColor: colorVars['--color-background-gray'],@@ -213,7 +246,6 @@ const styles = stylex.create({alignItems: 'center',justifyContent: 'center',borderRadius: radiusVars['--radius-full'],- backgroundColor: colorVars['--color-background-surface'],transitionProperty: 'transform, width, height',transitionDuration: {default: durationVars['--duration-fast'],@@ -221,6 +253,22 @@ const styles = stylex.create({},transitionTimingFunction: easeVars['--ease-standard'],},+ // The thumb fill lives on the on/off styles (not the shared thumb style)+ // because forced colors needs a per-state system color: CanvasText on the+ // empty off track, HighlightText on the Highlight on track. Sizing stays in+ // thumbOffSizeStyles/thumbOnSizeStyles; only the fill is state-dependent.+ thumbOff: {+ backgroundColor: {+ default: colorVars['--color-background-surface'],+ '@media (forced-colors: active)': 'CanvasText',+ },+ },+ thumbOn: {+ backgroundColor: {+ default: colorVars['--color-background-surface'],+ '@media (forced-colors: active)': 'HighlightText',+ },+ },labelWrapper: {display: 'flex',flexDirection: 'column',@@ -537,6 +585,7 @@ export function Switch({stylex.props(styles.thumb,isOn ? thumbOnSizeStyles[size] : thumbOffSizeStyles[size],+ isOn ? styles.thumbOn : styles.thumbOff,),)}>{isBusy && <Spinner size="sm" />}diff --git a/packages/core/src/ToggleButton/ToggleButton.test.tsx b/packages/core/src/ToggleButton/ToggleButton.test.tsxindex e9026ac40c..fc506415bc 100644--- a/packages/core/src/ToggleButton/ToggleButton.test.tsx+++ b/packages/core/src/ToggleButton/ToggleButton.test.tsx@@ -14,6 +14,10 @@ import userEvent from '@testing-library/user-event';import {useState, type MouseEvent} from 'react';import {ToggleButton} from './ToggleButton';import {ToggleButtonGroup} from './ToggleButtonGroup';+import {+ getAllInjectedCss,+ getForcedColorsRules,+} from '../__tests__/forcedColors';// =============================================================================// ToggleButton — Standalone@@ -517,3 +521,23 @@ describe('ToggleButtonGroup (multiple)', () => {);});});++// jsdom cannot emulate forced-colors rendering, so these assert that the+// compiled output includes the forced-colors rules; visual behavior needs+// manual verification under Windows High Contrast.+describe('forced colors (WCAG 1.4.11)', () => {+ it('compiles forced-colors overrides so the pressed state survives Windows High Contrast', () => {+ render(<ToggleButton label="Bold" isPressed onPressedChange={() => {}} />);+ const css = getForcedColorsRules();+ // The painted pressed overlay is stripped; Highlight/HighlightText marks+ // the pressed toggle (critical for icon-only toggles, which otherwise+ // lose all pressed indication).+ expect(css).toContain('background-color: highlight;');+ expect(css).toContain('color: highlighttext;');+ // ToggleButton renders a <button>; without opting out of UA remapping it+ // keeps the native ButtonFace surface and ignores the Highlight fill,+ // leaving HighlightText text on a white surface. forced-color-adjust: none+ // makes both render as authored.+ expect(getAllInjectedCss()).toContain('forced-color-adjust: none;');+ });+});diff --git a/packages/core/src/ToggleButton/ToggleButton.tsx b/packages/core/src/ToggleButton/ToggleButton.tsxindex a4f5ca2bb3..88e9c715d3 100644--- a/packages/core/src/ToggleButton/ToggleButton.tsx+++ b/packages/core/src/ToggleButton/ToggleButton.tsx@@ -40,7 +40,25 @@ import {themeProps} from '../utils/themeProps';*/const pressedStyles = stylex.create({background: {- backgroundColor: colorVars['--color-overlay-pressed'],+ // forced-color-adjust must be `none` here: ToggleButton renders a <button>,+ // and the UA keeps native form-control colors (ButtonFace surface) for it+ // under forced colors, ignoring the authored Highlight fill — the label kept+ // its HighlightText color, giving white text on a white surface. Opting the+ // pressed button out of UA remapping makes both the Highlight surface and+ // the HighlightText label render as authored, restoring figure-ground.+ forcedColorAdjust: 'none',+ backgroundColor: {+ default: colorVars['--color-overlay-pressed'],+ // Forced colors (Windows High Contrast) strips the painted pressed+ // overlay, which would leave icon-only toggles with no pressed+ // indication at all. Highlight/HighlightText is the platform convention+ // for a selected/pressed control (WCAG 1.4.11).+ '@media (forced-colors: active)': 'Highlight',+ },+ color: {+ default: null,+ '@media (forced-colors: active)': 'HighlightText',+ },},});diff --git a/packages/core/src/__tests__/forcedColors.ts b/packages/core/src/__tests__/forcedColors.tsnew file mode 100644index 0000000000..152d6cc2b7--- /dev/null+++ b/packages/core/src/__tests__/forcedColors.ts@@ -0,0 +1,60 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file forcedColors.ts+ * @input Uses the jsdom document (StyleX dev runtime injects rules into it)+ * @output Exports getForcedColorsRules, getAllInjectedCss test helpers+ * @position Shared test utility for asserting forced-colors style output+ *+ * jsdom cannot emulate `@media (forced-colors: active)` rendering, so+ * component tests assert the next-best thing: that the StyleX dev runtime+ * (runtimeInjection in vitest.config.ts) actually injected the forced-colors+ * rules a component relies on for Windows High Contrast support (WCAG 1.4.11).+ * Visual behavior needs manual verification in a forced-colors environment.+ */++/**+ * Collects the cssText of every injected CSS rule scoped to+ * `@media (forced-colors: active)`, including rules nested in other+ * conditions. Returns one string for substring assertions.+ */+export function getForcedColorsRules(): string {+ const chunks: string[] = [];+ for (const sheet of Array.from(document.styleSheets)) {+ let rules: CSSRule[];+ try {+ rules = Array.from(sheet.cssRules);+ } catch {+ continue;+ }+ for (const rule of rules) {+ if (rule.cssText.includes('forced-colors: active')) {+ chunks.push(rule.cssText);+ }+ }+ }+ return chunks.join('\n');+}++/**+ * Collects the cssText of every injected CSS rule, regardless of condition.+ * Use to assert declarations that live OUTSIDE `@media (forced-colors: active)`+ * yet still exist for forced-colors support — e.g. `forced-color-adjust: none`+ * (an unconditional declaration) or a hover tint gated behind+ * `(forced-colors: none)` so it cannot override the forced-colors state.+ */+export function getAllInjectedCss(): string {+ const chunks: string[] = [];+ for (const sheet of Array.from(document.styleSheets)) {+ let rules: CSSRule[];+ try {+ rules = Array.from(sheet.cssRules);+ } catch {+ continue;+ }+ for (const rule of rules) {+ chunks.push(rule.cssText);+ }+ }+ return chunks.join('\n');+}