Skip to content

Commit a2d7f42

Browse files
committed
fix(core): reducedMotion takes only 'system' until components follow 'always'
A theme's reducedMotion: 'always' reached only its motion-keyed adaptation rules and the press release fade; components' own Reduce Motion styles, Spinner and Skeleton among them, did not follow it. A theme that set it got a promise most of the page did not keep. The public type now offers only 'system', the default, and the root mark, its custom property, the marked adaptation blocks and the press release's mark arm go with it. The docs, template, changeset and the authoring contract's unshipped note say so.
1 parent c3831c0 commit a2d7f42

18 files changed

Lines changed: 59 additions & 483 deletions

‎.changeset/theme-motion-knobs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
'@astryxdesign/cli': patch
44
---
55

6-
[feat] A theme's `motion` takes three knobs beside the duration scale: `tempo` (0.75–1.5) scales every motion duration, `character` (`'crisp'`, `'standard'` or `'expressive'`) sets the new `--ease-entrance` and `--ease-move` tokens, and `reducedMotion: 'always'` reduces motion for everyone; so far the theme's motion-keyed adaptation rules and the press release fade follow it, not yet components' other Reduce Motion styles. A theme without them renders exactly as before; a duration scale and explicit tokens win over the knobs, Spinner's and Skeleton's loops keep their timing under every tempo, and the press release fade follows tempo up to the 200 ms Reduce Motion cap, under the person's setting or the theme's `'always'`. Springs don't read the knobs yet. The motion, token and theme-authoring docs and the theme template describe the knobs.
6+
[feat] A theme's `motion` takes three knobs beside the duration scale: `tempo` (0.75–1.5) scales every motion duration, `character` (`'crisp'`, `'standard'` or `'expressive'`) sets the new `--ease-entrance` and `--ease-move` tokens, and `reducedMotion: 'system'`, the only value, follows each person's Reduce Motion setting. A theme without them renders exactly as before; a duration scale and explicit tokens win over the knobs, Spinner's and Skeleton's loops keep their timing under every tempo, and the press release fade follows tempo up to the 200 ms Reduce Motion cap under the person's setting. Springs don't read the knobs yet. The motion, token and theme-authoring docs and the theme template describe the knobs.
77

88
@vjeux

‎docs/architecture/theme-authoring-contract.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ owner, lineage, collision, cycle, and legacy-unenrolled behavior remains shipped
315315
FR6): no spring reads the motion knobs yet. Until they land, that part of FR6
316316
is current authority but not enforcement.
317317

318-
The reach of `reducedMotion: 'always'` is accepted but partly unshipped
319-
(`spec:AST-108` FR6, INV15). Motion-keyed adaptation rules and the press
320-
release fade key reduced motion on the mark; components' other Reduce Motion
321-
styles, the animator, and other script readers of `prefers-reduced-motion` do
322-
not yet. Until they do, that part of INV15 and FR6 is current authority but not
323-
enforcement.
318+
`reducedMotion: 'always'` is accepted but unshipped (`spec:AST-108` FR6,
319+
INV15): `motion` takes only `reducedMotion: 'system'`, and nothing marks a
320+
theme's root, until component styles, the animator, script readers of
321+
`prefers-reduced-motion`, and motion-keyed adaptation rules key reduced motion
322+
on the mark. Until then, that part of INV15 and FR6 is current authority but
323+
not enforcement.
324324

325325
## Verification
326326

‎packages/cli/assets/docs/author-a-theme.doc.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const docs = {
4141
['typography.scale', '--text-heading-*-size/weight/leading, --text-body-size/weight/leading', 'base (px), ratio'],
4242
['typography.body/heading/code', '--font-family-body, --font-family-heading, --font-family-code', 'family, fallbacks?, url?, weight?'],
4343
['radius', '--radius-inner, --radius-element, --radius-container, --radius-page, --radius-chat', 'base (px), multiplier (0–2)'],
44-
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (springs don\'t read them yet)', 'tempo? (0.75–1.5), character? (crisp|standard|expressive), reducedMotion? (system|always); and/or a duration scale: fast (ms), medium (ms), ratio, slow?, easing?. The scale wins over tempo for the durations it sets. See {@link generic:motion}.'],
44+
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (springs don\'t read them yet)', 'tempo? (0.75–1.5), character? (crisp|standard|expressive), reducedMotion? (system); and/or a duration scale: fast (ms), medium (ms), ratio, slow?, easing?. The scale wins over tempo for the durations it sets. See {@link generic:motion}.'],
4545
]},
4646
{type: 'prose', text: 'For dark mode tuples in token values, see the Dark mode section of {@link generic:use-a-theme}.'},
4747
],
@@ -106,7 +106,7 @@ export const docs = {
106106
{type: 'prose', text: "Precedence follows rule order. Root theme values apply first, then every matching rule in declaration order. A later rule may deliberately restore a root value. `onDark` and `onLight` media-surface overrides apply after adaptations and win on the same leaf."},
107107
{type: 'prose', text: "`extends` preserves the base rule order and appends child rules. Inherited conditions use the child's effective breakpoint map. An empty child rule is a no-op, not a removal operator."},
108108
{type: 'prose', text: "A rule may replace a theme-local token only when the exact name is already enrolled by root `localTokens` or an enrolled base. Component writes in a rule are validated exactly like root `components`: same targets, axes, and value domains. The one addition is that a rule may not be the only place a custom value is enrolled: a value that is valid only because a theme enrolls it generates unconditional type augmentation, so declare it on the root theme first and let rules restyle it. Built-in values need no root declaration. When rules can match together, their ordered portable and local token writes are validated as one effective graph; any reachable cycle fails before CSS is emitted."},
109-
{type: 'prose', text: "Adaptations compile to CSS media queries with no resize listener or styling rerender. Runtime and `{@command theme build}` use the same compiler, but only a built theme is present at first paint in an SSR app. Under `reducedMotion: 'always'`, the theme's own or an enclosing theme's, a `motion: 'reduce'` rule applies whatever the person's setting, and a `motion: 'no-preference'` rule does not."},
109+
{type: 'prose', text: "Adaptations compile to CSS media queries with no resize listener or styling rerender. Runtime and `{@command theme build}` use the same compiler, but only a built theme is present at first paint in an SSR app."},
110110
],
111111
},
112112
{

‎packages/cli/assets/docs/motion.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const styles = stylex.create({
158158
items: [
159159
"`tempo` scales every motion duration: 1 is Astryx's own, 0.75 the quickest and 1.5 the slowest (values outside are clamped).",
160160
"`character` sets how lively motion is: `'crisp'` decelerates without overshoot, `'standard'` is Astryx's own, and `'expressive'` overshoots slightly on entrances and moves. Exits and fades never overshoot.",
161-
"`reducedMotion: 'always'` reduces motion for everyone, as if each person had turned on Reduce Motion. Not everything follows it yet: the theme's motion-keyed adaptation rules and the press release fade do, and components' other Reduce Motion styles don't yet. `'system'`, the default, follows each person's setting. No value loosens Reduce Motion.",
161+
"`reducedMotion: 'system'`, the default and only value, follows each person's Reduce Motion setting. No theme loosens Reduce Motion.",
162162
],
163163
},
164164
{

‎packages/cli/assets/theme.template.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,8 @@ export const myTheme = defineTheme({
186186
* tempo — 1 is Astryx's own; 0.75 the quickest, 1.5 the slowest.
187187
* character — 'crisp' | 'standard' | 'expressive': the entrance and move
188188
* curves. Exits and fades never overshoot.
189-
* reducedMotion — 'always' reduces motion for everyone (so far the
190-
* theme's motion-keyed adaptation rules and the press release fade, not
191-
* yet components' other Reduce Motion styles); 'system' (the default)
192-
* follows each person's setting.
189+
* reducedMotion — 'system' (the default and only value) follows each
190+
* person's Reduce Motion setting.
193191
* e.g. motion: {tempo: 0.85, character: 'crisp'}
194192
* Finger tracking, momentum, the keyboard, hover, the press's onset delay
195193
* and tap flash, and busy loops never follow them; the press release fade

‎packages/core/src/theme/Theme.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const docs = {
6969
type: 'DefinedTheme',
7070
required: true,
7171
description:
72-
"Theme object to apply. Prefer built theme objects for static production themes; use runtime `defineTheme()` for dynamic themes. Its `motion` can set `character` (`'crisp' | 'standard' | 'expressive'`) and `reducedMotion` (`'system' | 'always'`).",
72+
"Theme object to apply. Prefer built theme objects for static production themes; use runtime `defineTheme()` for dynamic themes. Its `motion` can set `character` (`'crisp' | 'standard' | 'expressive'`) and `reducedMotion` (`'system'`).",
7373
},
7474
{
7575
name: 'mode',

‎packages/core/src/theme/Theme.tsx‎

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {registerTheme} from './themeRegistry';
4545
import {dataAttr} from '../naming';
4646
import {ThemeContext} from './useTheme';
4747
import {warnOnce} from '../utils/devWarning';
48-
import {REDUCED_MOTION_PROPERTY, resolveMotionKnobs} from './themeMotion';
4948

5049
/**
5150
* Theme provider props
@@ -68,11 +67,6 @@ const wrapperStyles = stylex.create({
6867
color: colorVars['--color-text-primary'],
6968
fontFamily: typographyVars['--font-family-body'],
7069
},
71-
// The reduced-motion mark's custom property (REDUCED_MOTION_PROPERTY in
72-
// themeMotion.ts), which every element under the mark inherits (FR6).
73-
reducedMotion: {
74-
'--_astryx-reduced-motion': '1',
75-
},
7670
light: {
7771
colorScheme: 'light',
7872
},
@@ -199,16 +193,11 @@ function useThemeStyleInjection(theme: DefinedTheme): void {
199193
*
200194
* - 'light' | 'dark' → sets data-theme="light" | "dark"
201195
* - 'system' → removes data-theme (reset.css defaults to color-scheme: light dark)
202-
*
203-
* A theme with `reducedMotion: 'always'` also marks `<html>` with
204-
* `data-astryx-reduced-motion` and its custom property, so layers portaled
205-
* outside the wrapper reduce their motion too (spec:AST-108 FR6).
206196
*/
207197
function useRootThemeSync(
208198
isNested: boolean,
209199
mode: ThemeMode,
210200
themeName: string,
211-
reducesMotion: boolean,
212201
): void {
213202
useIsomorphicLayoutEffect(() => {
214203
if (isNested) {
@@ -227,22 +216,12 @@ function useRootThemeSync(
227216

228217
// Sync theme name so @scope rules reach portals/fallback viewports.
229218
document.documentElement.setAttribute(dataAttr('theme'), themeName);
230-
// The mark and its custom property, which portaled layers inherit.
231-
if (reducesMotion) {
232-
document.documentElement.setAttribute(dataAttr('reduced-motion'), '');
233-
document.documentElement.style.setProperty(REDUCED_MOTION_PROPERTY, '1');
234-
} else {
235-
document.documentElement.removeAttribute(dataAttr('reduced-motion'));
236-
document.documentElement.style.removeProperty(REDUCED_MOTION_PROPERTY);
237-
}
238219

239220
return () => {
240221
document.documentElement.removeAttribute('data-theme');
241222
document.documentElement.removeAttribute(dataAttr('theme'));
242-
document.documentElement.removeAttribute(dataAttr('reduced-motion'));
243-
document.documentElement.style.removeProperty(REDUCED_MOTION_PROPERTY);
244223
};
245-
}, [isNested, mode, themeName, reducesMotion]);
224+
}, [isNested, mode, themeName]);
246225
}
247226

248227
// =============================================================================
@@ -272,13 +251,7 @@ export function Theme({
272251
registerTheme(theme);
273252

274253
useThemeStyleInjection(theme);
275-
// spec:AST-108 FR6: 'always' marks the theme's root. So far motion-keyed
276-
// adaptation rules and the press release fade key reduced motion on the
277-
// mark; components' other Reduce Motion styles don't yet (a known gap in
278-
// `architecture:theme-authoring-contract`).
279-
const knobs = resolveMotionKnobs(theme.__axes?.motion);
280-
const reducesMotion = knobs.reducedMotion === 'always';
281-
useRootThemeSync(isNested, mode, theme.name, reducesMotion);
254+
useRootThemeSync(isNested, mode, theme.name);
282255

283256
// Get color-scheme style
284257
const colorSchemeStyle =
@@ -295,13 +268,8 @@ export function Theme({
295268
<ThemeContext value={ctxValue}>
296269
<ThemeNestingContext value={true}>
297270
<div
298-
{...stylex.props(
299-
wrapperStyles.base,
300-
colorSchemeStyle,
301-
reducesMotion && wrapperStyles.reducedMotion,
302-
)}
271+
{...stylex.props(wrapperStyles.base, colorSchemeStyle)}
303272
data-astryx-theme={theme.name}
304-
data-astryx-reduced-motion={reducesMotion ? '' : undefined}
305273
data-theme={mode === 'system' ? undefined : mode}>
306274
{children}
307275
</div>

‎packages/core/src/theme/defineTheme.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,8 @@ export interface DefineThemeInput<
296296
* token; touch motion's springs don't read it yet.
297297
* - `character` (`'crisp'`, `'standard'` or `'expressive'`) sets the
298298
* entrance and move curves; exits and fades never overshoot.
299-
* - `reducedMotion` (`'system'` or `'always'`): `'always'` reduces motion
300-
* for everyone; so far the theme's motion-keyed adaptation rules and the
301-
* press release fade follow it, not yet components' other Reduce Motion
302-
* styles. Nothing loosens a person's own setting.
299+
* - `reducedMotion` (`'system'`, the default and only value) follows each
300+
* person's Reduce Motion setting. Nothing loosens it.
303301
*
304302
* A motion scale computes duration min/max variants from base values and a
305303
* ratio (min = base × ratio, max = base / ratio); its durations win over

‎packages/core/src/theme/generateThemeRules.ts‎

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ export function generateOnMediaCSS(
17511751
}
17521752
if (roleParts.length > 0) {
17531753
adaptationMediaRoleBlocks.push(
1754-
adaptationBlocks(rule, roleParts, scopeSelector),
1754+
generateAdaptationMediaBlock(rule.query, roleParts, scopeSelector),
17551755
);
17561756
}
17571757
}
@@ -1820,40 +1820,6 @@ function generateAdaptationMediaBlock(
18201820
.join('\n\n')}\n }\n}`;
18211821
}
18221822

1823-
/** The mark of `reducedMotion: 'always'` on a theme's root (spec:AST-108 FR6). */
1824-
const REDUCED_MOTION_MARK = `[data-${dataAttrNamespace}-reduced-motion]`;
1825-
1826-
/**
1827-
* An adaptation rule's blocks. A rule keyed on motion also honours the
1828-
* reduced-motion mark, on the theme's root or an ancestor's (spec:AST-108
1829-
* FR6): a `'reduce'` rule gets a second block without the motion feature,
1830-
* scoped to a marked theme, so it applies whatever the person's setting, and
1831-
* a `'no-preference'` rule's scope leaves marked themes out.
1832-
*/
1833-
function adaptationBlocks(
1834-
rule: Pick<ResolvedThemeAdaptationRule, 'when' | 'query' | 'markQuery'>,
1835-
parts: string[],
1836-
scopeSelector: string,
1837-
): string {
1838-
if (rule.when.motion === 'no-preference') {
1839-
return generateAdaptationMediaBlock(
1840-
rule.query,
1841-
parts,
1842-
`${scopeSelector}:not(${REDUCED_MOTION_MARK}):not(${REDUCED_MOTION_MARK} *)`,
1843-
);
1844-
}
1845-
const block = generateAdaptationMediaBlock(rule.query, parts, scopeSelector);
1846-
if (rule.when.motion !== 'reduce' || rule.markQuery === undefined) {
1847-
return block;
1848-
}
1849-
const markedScope = `${scopeSelector}${REDUCED_MOTION_MARK}, ${REDUCED_MOTION_MARK} ${scopeSelector}`;
1850-
const marked =
1851-
rule.markQuery === ''
1852-
? `@scope (${markedScope}) to (${THEME_SCOPE_TO}) {\n${parts.join('\n\n')}\n}`
1853-
: generateAdaptationMediaBlock(rule.markQuery, parts, markedScope);
1854-
return `${block}\n\n${marked}`;
1855-
}
1856-
18571823
/**
18581824
* Generate CSS for a theme's ordered adaptation rules.
18591825
*
@@ -1900,7 +1866,7 @@ export function generateAdaptationCSS(
19001866
if (parts.length === 0) {
19011867
continue;
19021868
}
1903-
blocks.push(adaptationBlocks(rule, parts, scopeSelector));
1869+
blocks.push(generateAdaptationMediaBlock(rule.query, parts, scopeSelector));
19041870
}
19051871

19061872
// Replay explicit role writes after every generated source alias. This keeps
@@ -1919,7 +1885,9 @@ export function generateAdaptationCSS(
19191885
roleEntries,
19201886
);
19211887
if (roleRule !== null) {
1922-
blocks.push(adaptationBlocks(rule, [roleRule], scopeSelector));
1888+
blocks.push(
1889+
generateAdaptationMediaBlock(rule.query, [roleRule], scopeSelector),
1890+
);
19231891
}
19241892
}
19251893

@@ -1948,7 +1916,13 @@ export function generateAdaptationCSS(
19481916
{authoredOnly: true},
19491917
);
19501918
if (authoredWeightParts.length > 0) {
1951-
blocks.push(adaptationBlocks(rule, authoredWeightParts, scopeSelector));
1919+
blocks.push(
1920+
generateAdaptationMediaBlock(
1921+
rule.query,
1922+
authoredWeightParts,
1923+
scopeSelector,
1924+
),
1925+
);
19521926
}
19531927
}
19541928
}

‎packages/core/src/theme/motionKnobs.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
/** How lively a theme's motion feels. */
1919
export type MotionCharacter = 'crisp' | 'standard' | 'expressive';
2020

21-
/** Whether a theme reduces motion for everyone. */
22-
export type ThemeReducedMotion = 'system' | 'always';
21+
/**
22+
* Whose Reduce Motion setting a theme follows: `'system'`, each person's own.
23+
*/
24+
export type ThemeReducedMotion = 'system';
2325

2426
/** The three motion knobs a theme sets (`spec:AST-108` FR1). */
2527
export interface ThemeMotionKnobs {
@@ -35,8 +37,8 @@ export interface ThemeMotionKnobs {
3537
*/
3638
character?: MotionCharacter;
3739
/**
38-
* `'always'` reduces motion for everyone; `'system'` follows each person's
39-
* Reduce Motion setting. No value loosens Reduce Motion. Default `'system'`.
40+
* `'system'` follows each person's Reduce Motion setting. It is the only
41+
* value, and the default: no theme loosens Reduce Motion.
4042
*/
4143
reducedMotion?: ThemeReducedMotion;
4244
}
@@ -79,7 +81,5 @@ export function resolveKnobs(
7981
config?.character != null && CHARACTERS.includes(config.character)
8082
? config.character
8183
: 'standard';
82-
const reducedMotion =
83-
config?.reducedMotion === 'always' ? 'always' : 'system';
84-
return {tempo, character, reducedMotion, tempoIsSet};
84+
return {tempo, character, reducedMotion: 'system', tempoIsSet};
8585
}

0 commit comments

Comments
 (0)