Skip to content

Commit 0ef60dd

Browse files
authored
feat(core): a theme's motion takes tempo and character (#8661)
## Why A theme author cannot say how motion should feel, quicker, crisper or reduced, without overriding durations and curves per component. `spec:AST-108` (#8613) gives `defineTheme`'s `motion` three knobs: `tempo`, `character` and `reducedMotion`. This pull request ships `tempo` and `character`, and exports their types (`ThemeMotionConfig`, `ThemeMotionKnobs`, `MotionCharacter`). `reducedMotion` stays out of the public type until `'always'` works: component Reduce Motion styles, script readers and the animator must follow it first. Every theme follows each person's setting, as `'system'` does. ## What led to it This comes from the work to make Astryx's touch components behave as native iOS ones do, where a theme's motion must reach springs and press feedback, not only CSS. Themes could scale their duration tokens, but easing was one curve for everything, and Reduce Motion only followed the system setting. ## Options and tradeoffs - CSS-only knobs compose through the cascade but cost the animator a style read per motion; attribute-only knobs are free for scripts but invisible to CSS. - Busy loops (Spinner, Skeleton) could be exempted from `tempo` by name, or read a copy of each duration taken before `tempo`. - An extending theme could resolve base first, then generated (the theme-authoring contract), or let a base's explicit motion tokens win over its children's knobs. ## Why this choice - CSS gets tokens now; the attributes the animator reads come with the animator's own pull request. - The copies: every layer that writes a duration writes one, so later components need nothing special. - The contract's precedence, as the maintainer ruled; a child with no `slow` keeps its base's slow band (#8748). - `--ease-exit` is #8004's; this defines none, and `character` never moves it. - `reducedMotion: 'always'` would have reached only motion-keyed adaptation rules and the press release fade, so a theme setting it would reduce a little of the page and leave Spinner, Skeleton and most components moving. With `'system'` as the only value the field would do nothing, so the public type leaves it out until every component follows `'always'`. ## How to check it 1. Wrap a Dialog story in `<Theme theme={defineTheme({name: 'Slow', motion: {tempo: 1.5}})}>`: it opens 1.5 times slower; a Spinner beside it keeps its speed. 2. Add `character: 'expressive'`: `--ease-entrance` and `--ease-move` take the overshooting curve, so a style that eases on them overshoots on entrance; `--ease-standard` and exits do not change. Dialog still eases on `--ease-standard`, so it does not overshoot yet. 3. Under tempo 1.5, tap or click a Button: its pressed highlight fades out over 300 ms instead of 200 ms. 4. Extend a theme that sets `--duration-medium: 300ms` with `tempo: 1.2`: the child's is 492 ms. 5. `defineTheme({name: 'Partial', motion: {fast: 100, tempo: 1.2}})` throws: a duration scale needs `fast`, `medium` and `ratio`, from the theme or its base. ## Evidence - Tests: `packages/core/src/theme/themeMotion.test.ts` and `packages/core/src/utils/pressFeedback.test.ts`. Each new case fails without its part of the change. - The theme, press feedback, Spinner and Skeleton suites, the theme private-variable and CSS build checks, the CLI doc goldens, type check and lint pass on this head. ## Writing rubric results R1 narration, R2 research, R4 rejected alternatives, R5 change references and R6 open questions: none. R3 evidence: INV15's row cites its test file. ## Scope - [x] One capability is added. - [x] Unrelated fixes, cleanup, and policy changes were removed or split. - [x] Consumer docs, focused tests, and migration evidence ship with the feature. - [x] Public text and artifacts contain no internal Meta context.
1 parent eaae8e3 commit 0ef60dd

35 files changed

Lines changed: 1738 additions & 245 deletions

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astryxdesign/core': patch
3+
'@astryxdesign/cli': patch
4+
---
5+
6+
[feat] A theme's `motion` takes two knobs beside the duration scale: `tempo` (0.75–1.5) scales every motion duration, and `character` (`'crisp'`, `'standard'` or `'expressive'`) sets the new `--ease-entrance` and `--ease-move` tokens; `--ease-exit` stays the same at every character. Their types, `ThemeMotionConfig`, `ThemeMotionKnobs` and `MotionCharacter`, are exported. 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.
7+
8+
@vjeux

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

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ applies_to:
1818
packages/core/src/theme/expandTypeScale.ts,
1919
packages/core/src/theme/expandRadiusScale.ts,
2020
packages/core/src/theme/expandMotionScale.ts,
21+
packages/core/src/theme/themeMotion.ts,
22+
packages/core/src/theme/motionKnobs.ts,
2123
packages/core/src/theme/mergeComponents.ts,
2224
packages/core/src/theme/onMediaTokens.ts,
2325
packages/core/src/theme/localTokens.ts,
@@ -33,6 +35,7 @@ verified_by:
3335
packages/core/src/theme/expandTypeScale.test.ts,
3436
packages/core/src/theme/expandRadiusScale.test.ts,
3537
packages/core/src/theme/expandMotionScale.test.ts,
38+
packages/core/src/theme/themeMotion.test.ts,
3639
packages/core/src/theme/onMediaTokens.test.ts,
3740
scripts/check-theme-template.test.mjs,
3841
]
@@ -52,6 +55,7 @@ deciding_specs:
5255
spec:AST-087/DEC-7,
5356
spec:AST-087/DEC-9,
5457
spec:AST-087/DEC-10,
58+
spec:AST-108/DEC-1,
5559
]
5660
---
5761

@@ -192,6 +196,24 @@ it, typed as that theme's listed names.
192196
- **INV14 — The variant list is theme-level.** `iconVariants` lists the variant
193197
names the whole theme supports. It is never per icon and never combined with
194198
another theme's list.
199+
- **INV15 — Motion is three knobs beside the duration scale.** `motion` takes
200+
`tempo` (clamped to 0.75–1.5), `character` (`crisp`, `standard`,
201+
`expressive`), and `reducedMotion` (`system`, `always`) beside the duration
202+
scale. `tempo` scales every duration token and `character` sets
203+
`--ease-entrance` and `--ease-move`; with tempo 1 and `standard` the tokens
204+
are the defaults. A duration scale's durations win over `tempo`, and
205+
explicit tokens win over both. An extending theme inherits motion field by
206+
field: a duration-scale field or knob the child leaves unset keeps its
207+
base's value. Each duration's
208+
value before `tempo` is kept for busy-indicator loops, which never follow
209+
`tempo`. Neither `tempo` nor `character` moves finger tracking, momentum,
210+
the rubber band, the on-screen keyboard, the press model's onset delay,
211+
cancel distance and tap flash, hover-intent delays, gesture thresholds,
212+
busy-indicator loops, or the 200 ms Reduce Motion cap (`spec:AST-108` FR4).
213+
`reducedMotion: 'always'` marks the theme's root, and what keys
214+
reduced motion on `prefers-reduced-motion` keys it on that mark as well
215+
(`spec:AST-108` FR6). An adaptation rule may set `tempo` and `character`,
216+
never `reducedMotion`.
195217

196218
This record does not own:
197219

@@ -249,6 +271,9 @@ public surface belongs to
249271

250272
## Owning code
251273

274+
- An internal, pure `resolveThemeMotion(theme)` returns a theme's motion
275+
knobs, durations, and easings for the animator and for server code; it
276+
touches no DOM and has no import-time side effects (`spec:AST-108` FR6).
252277
- `packages/core/src/theme/defineTheme.ts` owns the public input, normalized IR,
253278
orchestration, and extension behavior.
254279
- `themeAdaptations.ts` owns the fixed breakpoint/condition vocabulary,
@@ -257,6 +282,9 @@ public surface belongs to
257282
adopts their tokens.
258283
- `expandColorScale.ts`, `expandTypeScale.ts`, `expandRadiusScale.ts`, and
259284
`expandMotionScale.ts` own their derived token/component values.
285+
- `motionKnobs.ts` owns the motion knobs' types, defaults and clamping;
286+
`themeMotion.ts` owns the tokens and pre-tempo durations they generate, and
287+
`resolveThemeMotion`, the pure read the animator and server code use.
260288
- `mergeComponents.ts` owns the shared deep-merge rule.
261289
- `onMediaTokens.ts` owns normalization of inverted-surface overrides.
262290
- `localTokens.ts` owns opt-in enrollment, valid CSS custom-property names, exact
@@ -275,7 +303,9 @@ behavior. AST-012 decisions 1–4 establish the fixed width map, named closed co
275303
ordered rule cascade, and source/built adaptation metadata parity. AST-017 decision 1
276304
owns released compatibility classification and migration. AST-087 decisions 2, 7, 9,
277305
and 10 establish function icon entries, node-valued public reads, the theme-level
278-
`iconVariants` list, and the static public view of `componentIcons`.
306+
`iconVariants` list, and the static public view of `componentIcons`. AST-108
307+
decision 1 establishes the three motion knobs and keeps per-role motion values
308+
internal.
279309

280310
## Known conformance and verification gaps
281311

@@ -285,11 +315,17 @@ classify local references. Until the implementation lands, INV8's prefix-indepen
285315
clauses are current authority but not enforcement. Existing explicit enrollment,
286316
owner, lineage, collision, cycle, and legacy-unenrolled behavior remains shipped.
287317

288-
The motion resolver is accepted but unshipped: an internal, pure
289-
`resolveThemeMotion(theme)` returns a theme's motion knobs, durations, easings,
290-
and role tables for the animator and for server code, touching no DOM and with
291-
no import-time side effects (`spec:AST-108` FR6). Until it lands, FR6's
292-
resolution is current authority but not enforcement.
318+
`resolveThemeMotion`'s role tables are accepted but unshipped (`spec:AST-108`
319+
FR6): no spring reads the motion knobs yet. Until they land, that part of FR6
320+
is current authority but not enforcement.
321+
322+
`reducedMotion: 'always'` is accepted but unshipped (`spec:AST-108` FR6,
323+
INV15): the public `motion` type has no `reducedMotion` field, every theme
324+
follows each person's setting as `'system'` does, and nothing marks a
325+
theme's root, until component styles, the animator, script readers of
326+
`prefers-reduced-motion`, and motion-keyed adaptation rules key reduced motion
327+
on the mark. Until then, that part of INV15 and FR6 is current authority but
328+
not enforcement.
293329

294330
## Verification
295331

@@ -304,5 +340,6 @@ resolution is current authority but not enforcement.
304340
| INV11 | `DefineThemeInput`/output diff plus runtime/build fixtures | Validation-only data enters the normalized theme, or productive input loses construction validation |
305341
| INV12 | Core theme export diff, constructed-value evidence, and current-consumer callsite | A theme `define*` helper only checks input and returns that exact input unchanged |
306342
| INV13, INV14 | `defineTheme.test.ts` type and normalization tests for function entries, slot functions, and the list | A public read returns a function, a child merges variant lists, or an entry sees another theme's names |
343+
| INV15 | `themeMotion.test.ts` over tempo bounds, characters, a duration scale, explicit tokens, and extension | A token off its knob, a knob beating a scale or explicit token, a lost inherited knob, or a loop following `tempo` |
307344
| Theme/Core compatibility | Maintained theme source/build against the minimum Core in its currently supported peer/dependency range | A theme update silently requires newer in-range Core or bypasses the `spec:AST-017` path |
308345
| Authoring projection | `scripts/check-theme-template.test.mjs` | A supported authoring concept is missing or misstated in the template |

‎docs/specs/AST-108-theme-motion/spec.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ defineTheme({
147147

148148
- `defineTheme`'s `motion` widens to accept the three knobs beside the existing
149149
`MotionScaleConfig`; existing themes render exactly as before.
150+
- Until `reducedMotion: 'always'` ships, the public `motion` type has no
151+
`reducedMotion` field and every theme follows each person's setting, as
152+
`'system'` does (the known gap in `architecture:theme-authoring-contract`).
150153
- Core gains `--ease-entrance`, `--ease-move`, and `--ease-exit`, and a
151154
theme-root mark for `reducedMotion: 'always'` that every component style
152155
keying reduced motion on `prefers-reduced-motion` also keys on; Carousel's

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

Lines changed: 3 additions & 3 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', '--duration-fast-min/fast/fast-max, --duration-medium-min/medium/medium-max', 'fast (ms), medium (ms), ratio, easing?'],
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); and/or a duration scale: fast (ms), medium (ms), ratio, slow?, easing?. The scale wins over tempo for the durations it sets, and explicit tokens win over both. Fixed whatever the knobs say: drags and momentum, rubber band, keyboard, press onset/cancel/flash, hover intent, gesture thresholds, Spinner/Skeleton loops, the 200 ms Reduce Motion cap. 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
],
@@ -58,7 +58,7 @@ export const docs = {
5858
['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
5959
['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
6060
['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
61-
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio."],
61+
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio. Each knob (`tempo`, `character`) the child leaves unset keeps the base's."],
6262
['typography, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
6363
['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
6464
]},
@@ -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.'},
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: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const docs = {
5050
content: [
5151
{
5252
type: 'prose',
53-
text: 'Two easing curves. `--ease-standard` decelerates, for things arriving and state changes. `--ease-exit` accelerates, for things leaving: it moves off from rest and leaves fast, so the travel stays visible for the whole duration.',
53+
text: "Four easing curves. `--ease-standard` decelerates, for state changes. `--ease-entrance` is for things arriving and `--ease-move` for things moving on screen; a theme's `character` sets both, and at `standard` they equal `--ease-standard`. `--ease-exit` accelerates, for things leaving: it moves off from rest and leaves fast, so the travel stays visible for the whole duration, and it is the same at every `character`.",
5454
},
5555
{
5656
type: 'token-ref',
@@ -120,7 +120,7 @@ export const docs = {
120120
content: [
121121
{
122122
type: 'prose',
123-
text: 'Set transition durations and easing from the motion tokens, so a theme that retunes motion retunes your animations too.',
123+
text: "Set transition durations and easing from the motion tokens, so a theme that retunes motion retunes your animations too. Ease something arriving on `--ease-entrance` and something moving on screen on `--ease-move`, so it follows the theme's `character`, and something leaving on `--ease-exit`, which stays the same at every `character`.",
124124
},
125125
{
126126
type: 'code',
@@ -137,12 +137,48 @@ const styles = stylex.create({
137137
slideUp: {
138138
transitionProperty: 'transform, opacity',
139139
transitionDuration: durationVars['--duration-medium'],
140-
transitionTimingFunction: easeVars['--ease-standard'],
140+
transitionTimingFunction: easeVars['--ease-entrance'],
141141
},
142142
});`,
143143
},
144144
],
145145
},
146+
{
147+
id: 'theme-motion',
148+
title: 'Tune motion from the theme',
149+
category: 'foundations',
150+
content: [
151+
{
152+
type: 'prose',
153+
text: "A theme sets how motion feels with two knobs in `defineTheme`'s `motion`. They drive the CSS motion tokens; the springs of touch motion don't read them yet. Every theme follows each person's Reduce Motion setting; no theme loosens it.",
154+
},
155+
{
156+
type: 'list',
157+
style: 'unordered',
158+
items: [
159+
"`tempo` scales every motion duration: 1 is Astryx's own, 0.75 the quickest and 1.5 the slowest (values outside are clamped).",
160+
"`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+
],
162+
},
163+
{
164+
type: 'code',
165+
lang: 'ts',
166+
label: 'A quicker, crisper theme',
167+
code: `export const brandTheme = defineTheme({
168+
name: 'brand',
169+
motion: {tempo: 0.85, character: 'crisp'},
170+
});`,
171+
},
172+
{
173+
type: 'prose',
174+
text: "Some motion never follows the knobs, because it tracks a finger or the system: finger tracking, momentum and the rubber band, the on-screen keyboard, the press model's onset delay, cancel distance and tap flash (its release fade follows tempo), hover-intent delays, gesture thresholds, the loops of busy indicators such as Spinner and Skeleton, and the 200 ms Reduce Motion cross-fade.",
175+
},
176+
{
177+
type: 'prose',
178+
text: 'Precedence, lowest to highest: the knobs, then a duration scale (`fast`, `medium`, `slow`, `ratio`) for the durations it sets, then explicit `tokens`. A theme with no `motion` renders exactly as before.',
179+
},
180+
],
181+
},
146182
{
147183
title: 'Best Practices',
148184
category: 'foundations',

‎packages/cli/assets/docs/tree/tokens-duration.doc.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export const docs = {
1717
"order": 100
1818
},
1919
"category": "foundations",
20-
"description": "Motion duration primitives. Three bands: fast (micro-interactions), medium (entrance/exit), slow (continuous). Min/max variants derive from base × ratio.",
20+
"description": "Motion duration primitives. Three bands: fast (micro-interactions), medium (entrance/exit), slow (continuous). Min/max variants derive from base × ratio. Of a theme's two `motion` knobs, `tempo` (0.75–1.5) scales every duration here; `character` leaves durations alone. A duration scale beats `tempo` for the bands it sets, and explicit `tokens` beat both. `tempo` leaves these unscaled: finger tracking, momentum, the rubber band, the on-screen keyboard, the press's onset delay, cancel distance and tap flash, hover-intent delays, gesture thresholds, Spinner's and Skeleton's loops, and the 200 ms Reduce Motion cap.",
2121
"sections": [
2222
{
2323
"title": "Duration Tokens",
2424
"content": [
2525
{
2626
"type": "prose",
27-
"text": "Motion duration primitives. Three bands: fast (micro-interactions), medium (entrance/exit), slow (continuous). Min/max variants derive from base × ratio."
27+
"text": "Motion duration primitives. Three bands: fast (micro-interactions), medium (entrance/exit), slow (continuous). Min/max variants derive from base × ratio. Of a theme's two `motion` knobs, `tempo` (0.75–1.5) scales every duration here; `character` leaves durations alone. A duration scale beats `tempo` for the bands it sets, and explicit `tokens` beat both. `tempo` leaves these unscaled: finger tracking, momentum, the rubber band, the on-screen keyboard, the press's onset delay, cancel distance and tap flash, hover-intent delays, gesture thresholds, Spinner's and Skeleton's loops, and the 200 ms Reduce Motion cap."
2828
},
2929
{
3030
"type": "table",

0 commit comments

Comments
 (0)