Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c784084
spec(AST-094): touch presentations feel native by default
cixzhang Oct 24, 2026
0c35c43
chore(core): the UIKit constants table for touch presentations
vjeux Oct 24, 2026
17c181b
chore(core): UIKit's spring, decay, rubber-band and projection math
vjeux Oct 24, 2026
6bd2851
chore(core): the constants table names only what exists, and dates ev…
vjeux Oct 24, 2026
76be493
fix(core): paging past the last page lands on a real page
vjeux Oct 24, 2026
2f13d6e
feat(core): themes retune touch motion through motion roles
vjeux Oct 24, 2026
bf4ec6f
fix(core): theme motion role ids are checked against the generated li…
vjeux Oct 24, 2026
47c509c
fix(core): theme adaptations have no platform condition
vjeux Oct 25, 2026
4bdae8e
fix(core): reading a motion table registers nothing, and a theme ship…
vjeux Oct 25, 2026
704375c
fix(core): a page registers and ships only the motion tables it anima…
vjeux Oct 25, 2026
d0bd06d
test(core): the role registry test checks every table discovery regis…
vjeux Oct 25, 2026
ce3a7e0
fix(core): the Reduce Motion fade is not a theme role
vjeux Oct 25, 2026
c87c600
docs(cli): the theme template names no platform condition
vjeux Oct 25, 2026
4b3de64
Merge main into the constants table (lab typechecks with its tests)
vjeux Oct 25, 2026
530315f
Merge #8053 (main merged in) into the motion math
vjeux Oct 25, 2026
b2210be
Merge #8054 (main merged in) into the theme motion roles
vjeux Oct 25, 2026
a3fb27e
fix(core): UIKit's menu spring under Reduce Motion is not a theme role
vjeux Oct 25, 2026
e7df427
perf(core): the gesture table's sources move to JSDoc, out of the bundle
vjeux Oct 25, 2026
439dcc3
docs(spec): the draft AST-094 copy leaves this stack
vjeux Oct 25, 2026
0bf13da
Merge main (the deploy typecheck gate test reads the step as written)…
vjeux Oct 25, 2026
bbbcb60
refactor(core): the platform presets are named for their use
vjeux Oct 25, 2026
7c5f71c
Merge main (67dc45f66d3) into #8054
cixzhang Oct 25, 2026
6705708
Merge main (67dc45f66d3) into #8257
cixzhang Oct 25, 2026
03f66c3
fix(core): the UIKit table keeps only what a touch presentation plays…
cixzhang Oct 25, 2026
1133bf9
Merge remote-tracking branch 'origin/main' into m8053
cixzhang Oct 25, 2026
eded944
style(core): MEASUREMENTS.md table widths after the dropped rows
cixzhang Oct 25, 2026
f9d0900
feat(core): the press release's curve is a press value
vjeux Oct 25, 2026
9db9315
docs(core): the velocity weight says a rested finger releases at 0
vjeux Oct 25, 2026
5d3cab6
Merge #8053 (the table keeps only what a touch presentation plays; th…
vjeux Oct 25, 2026
7e36bcd
fix(core): the table's notes point at what exists, and the press entr…
cixzhang Oct 25, 2026
c1fa660
Merge #8053's notes and press pins into the press release's curve and…
vjeux Oct 25, 2026
59a748f
Merge #8053 (the table's notes point at what exists; the press entrie…
vjeux Oct 25, 2026
6ae3390
Merge main (#8043's interaction proofs) into the UIKit constants table
vjeux Oct 25, 2026
51b3ecb
Merge #8053 (main with #8043's interaction proofs) into the motion math
vjeux Oct 25, 2026
1f751c9
docs(core): M-S2 feeds scroll.decelerationRate, where the coast readi…
cixzhang Oct 25, 2026
96f8240
Merge #8053 (M-S2 feeds scroll.decelerationRate) into the press relea…
vjeux Oct 25, 2026
1ae9200
Merge #8053 (M-S2 feeds scroll.decelerationRate) into the motion math
vjeux Oct 25, 2026
b2d79c2
fix(motion): roles are named for their use, keyboard motion is no rol…
cixzhang Oct 25, 2026
e6d3ae3
Merge #8054 (the motion math, the table's use names and the press rel…
vjeux Oct 25, 2026
72b2649
feat(core): every role AST-094 FR4 names is a motion role a theme can…
vjeux Oct 25, 2026
9991180
docs(core): the sub-menu springs name their UIKit readings
vjeux Oct 25, 2026
e74ff9f
docs(core): the motion docs say when a theme value applies, not that …
vjeux Oct 25, 2026
e3cd975
docs(core): the theme guide says how motion roles inherit, with tests…
vjeux Oct 25, 2026
4bbd83e
test(cli): the docs golden lists the motion roles under their use names
vjeux Oct 25, 2026
5dba859
docs(core): a motion.durations value takes precedence for its role; t…
vjeux Oct 25, 2026
7234d44
Merge main (99ad3f6d906) into the motion math
cixzhang Oct 26, 2026
afe98cb
Merge #8054 (main with #8053's table) into the theme motion roles
vjeux Oct 26, 2026
0b6bf62
feat(core): the theme's motion config types are exported
vjeux Oct 26, 2026
6327d43
docs(core): the motion role table marks a guessed or WebKit default
vjeux Oct 26, 2026
011705f
feat(core): the motion roles are the ones spec:AST-094 FR4 names
vjeux Oct 26, 2026
6061322
Merge main (b298b37d: the landed motion math and gesture recognizer c…
vjeux Oct 26, 2026
3f29b03
refactor(core): touch motion stays internal: no theme surface
cixzhang Oct 26, 2026
6b2f0a3
test(cli): the stable-output goldens drop the motion docs' touch section
vjeux Oct 26, 2026
a10f5a2
refactor(core): the internal motion roles drop inert rename maps and …
vjeux Oct 26, 2026
18ad544
perf(core): each UIKit spring is its own export, so a component bundl…
vjeux Oct 26, 2026
10fcb7b
test(motion): an unsourced one-line spring export fails the source ch…
cixzhang Oct 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/touch-motion-theme-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[chore] Internal: the touch motion tables register their springs, durations and curves as internal motion roles, each read once when a motion starts, so every component keeps its measured value. Nothing public changes: themes do not set motion roles, and no shipped component reads the roles yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the 17 values spec:AST-094 FR4 names register, and at this head nothing reads a role when a motion starts (nothing outside packages/core/src/motion/ imports the registry). Something like "the touch motion tables register the 17 values spec:AST-094 FR4 names as internal motion roles" would match the code.


@vjeux
5 changes: 3 additions & 2 deletions packages/core/src/motion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ UIKit constants table (every spring, duration, deceleration rate, rubber-band
constant, curve and gesture threshold a touch presentation uses, each with its
source) and the spring, decay, rubber-band and projection math UIKit uses.
Nothing here is exported from the package entry point. Core's motion and
gesture modules read the table by path; components take touch motion from the
theme's motion roles (`spec:AST-094` FR4), not from this table.
gesture modules read the table by path; components read touch motion through
its internal motion roles (`roles.ts`), so each keeps its measured value; no
shipped component reads the roles yet.

## Files

Expand Down
105 changes: 105 additions & 0 deletions packages/core/src/motion/roleValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file roleValue.ts
* @input A role id, or a role's kind and value
* @output isMotionRoleId, motionRoleVariable and formatMotionRoleValue (a
* role value's CSS form), with the role kinds
* @position The value half of the internal motion roles: no registry and
* no parsing. roles.ts holds the registry and re-exports these.
*
* SYNC: When modified, update /packages/core/src/motion/roles.test.ts.
*/

import {durationBounceOf, toSpring, type SpringDescription} from './spring';

/** The three kinds of value a role can hold. */
export type MotionRoleKind = 'spring' | 'duration' | 'curve';

/** Cubic-bézier control points `[x1, y1, x2, y2]`. */
export type MotionCurvePoints = readonly [number, number, number, number];

const ROLE_ID = /^[a-z][A-Za-z0-9]*(\.[a-z][A-Za-z0-9]*)+$/;

/** Whether `id` is a well-formed role name (a dotted table path). */
export function isMotionRoleId(id: string): boolean {
return ROLE_ID.test(id);
}

/** The CSS custom property for a role: `--motion-` + the path in kebab case. */
export function motionRoleVariable(id: string): string {
if (!isMotionRoleId(id)) {
throw new Error(
`motion role "${id}" must be a dotted table path such as "springs.sheetPresent"`,
);
}
return `--motion-${id
.split('.')
.map(part => part.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`))
.join('-')}`;
}

export function isSpring(value: unknown): value is SpringDescription {
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
return false;
}
return (
('response' in value && 'dampingRatio' in value) ||
('duration' in value && 'bounce' in value) ||
('stiffness' in value && 'damping' in value)
);
}

export function isCurve(value: unknown): value is MotionCurvePoints {
return (
Array.isArray(value) &&
value.length === 4 &&
value.every(n => typeof n === 'number')
);
}

/** Six significant digits: enough for any motion, free of float noise. */
export function short(n: number): string {
return String(Number(n.toPrecision(6)));
}

/**
* A role value as its CSS custom property holds it:
* - spring: SwiftUI's duration and bounce, `0.5s 0.15` (exact for every
* spring: mass folds into the duration, overdamping into a negative bounce);
* - duration: `250ms`;
* - curve: `cubic-bezier(0.42, 0, 0.58, 1)`, usable as is in CSS.
* Throws on a value that is not a valid value of its kind.
*/
export function formatMotionRoleValue(
kind: MotionRoleKind,
value: unknown,
): string {
if (kind === 'spring') {
if (!isSpring(value)) {
throw new TypeError(
'a spring is {response, dampingRatio}, {duration, bounce} or {mass?, stiffness, damping}',
);
}
const {duration, bounce} = durationBounceOf(toSpring(value));
if (!(bounce < 1)) {
throw new RangeError(
'a spring must settle: its bounce must be below 1 (a damping ratio above 0)',
);
}
return `${short(duration)}s ${short(bounce)}`;
}
if (kind === 'duration') {
if (!(typeof value === 'number' && Number.isFinite(value) && value >= 0)) {
throw new TypeError('a duration is a finite number of milliseconds ≥ 0');
}
return `${short(value)}ms`;
}
if (!isCurve(value) || !value.every(Number.isFinite)) {
throw new TypeError('a curve is four finite numbers [x1, y1, x2, y2]');
}
if (value[0] < 0 || value[0] > 1 || value[2] < 0 || value[2] > 1) {
throw new RangeError("a curve's x1 and x2 must lie in [0, 1]");
}
return `cubic-bezier(${value.map(short).join(', ')})`;
}
256 changes: 256 additions & 0 deletions packages/core/src/motion/roles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file roles.test.ts
* @input roles.ts and the shared UIKit tables (registered on import)
* @output Proof that each spring, duration and curve of a registered table is
* a role named by its path, that non-motion values are not, and that a
* role's CSS value reads back as the same motion
* @position Testing for /packages/core/src/motion/roles.ts
*/

import {readFileSync} from 'node:fs';
import {resolve} from 'node:path';
import {describe, expect, it} from 'vitest';
import {
formatMotionRoleValue,
isMotionRoleId,
listMotionRoles,
motionRoleIn,
motionRoleOf,
motionRoleVariable,
parseMotionRoleValue,
registerMotionTable,
} from './roles';
import {dampingRatioOf, naturalFrequency, toSpring} from './spring';
import {navigation, scroll, springs, timing} from './uikit';
import {
motionTableFiles,
REGISTER_EXPORT,
} from '../../../../scripts/motion-table-files.mjs';

// Every table the role list is generated from, registered the way the
// generator does: through each module's register<Name>Table.
for (const file of motionTableFiles(resolve(__dirname, '..'))) {
const module = (await import(file)) as Record<string, unknown>;
for (const [name, value] of Object.entries(module)) {
if (REGISTER_EXPORT.test(name) && typeof value === 'function') {
(value as () => void)();
}
}
}
// The tables that discovery registered, before any test adds a fixture.
const DISCOVERED = new Set(
listMotionRoles().map(role => role.id.split('.')[0]),
);

describe('motion roles', () => {
it('names a role by its table path, and its CSS variable in kebab case', () => {
expect(isMotionRoleId('sheet.present')).toBe(true);
expect(isMotionRoleId('timing.curves.move')).toBe(true);
expect(isMotionRoleId('sheet')).toBe(false);
expect(isMotionRoleId('Sheet.present')).toBe(false);
expect(motionRoleVariable('springs.sheetDetent')).toBe(
'--motion-springs-sheet-detent',
);
expect(motionRoleVariable('timing.curves.move')).toBe(
'--motion-timing-curves-move',
);
expect(() => motionRoleVariable('sheet')).toThrow(/dotted table path/);
});

it('leaves a table value FR4 does not name an internal constant', () => {
const shared = {response: 0.4, dampingRatio: 0.9};
const table = {
present: shared,
dismiss: shared,
fadeMs: 200,
curves: {out: [0, 0, 0.58, 1] as const},
};
registerMotionTable('fixture', table);
// No role, no CSS variable, and the table is untouched.
expect(motionRoleOf(table.present)).toBeUndefined();
expect(table.dismiss).toBe(table.present);
expect(motionRoleIn(table, 'fadeMs')).toBeUndefined();
expect(motionRoleOf(table.curves.out)).toBeUndefined();
expect(listMotionRoles().some(role => role.id.startsWith('fixture.'))).toBe(
false,
);
});

it('has exactly the roles spec:AST-094 FR4 names', () => {
const spec = readFileSync(
resolve(
__dirname,
'../../../../docs/specs/AST-094-touch-presentations/spec.md',
),
'utf8',
);
const fr4 = spec.slice(spec.indexOf('**FR4'), spec.indexOf('**FR5'));
const named = [...fr4.matchAll(/^\s*\| `([a-z][\w.]*)`\s*\|/gm)].map(
match => match[1],
);
expect(named.length).toBeGreaterThan(0);
// Every table registered, the roles are exactly FR4's (other tests
// here register a fixture, which lists none).
expect(new Set(listMotionRoles().map(role => role.id))).toEqual(
new Set(named),
);
});

it('names the shared roles for their use, as spec:AST-094 FR4 does', () => {
expect(
[
springs.fingerTracking,
springs.emphasis,
springs.settle,
springs.quickChange,
springs.viewChange,
springs.timedChange,
springs.stateChange,
springs.directChange,
springs.menuOpen,
springs.menuClose,
timing.curves.viewChange,
timing.curves.exit,
timing.curves.entrance,
timing.curves.move,
].map(leaf => motionRoleOf(leaf)?.id),
).toEqual([
'springs.fingerTracking',
'springs.emphasis',
'springs.settle',
'springs.quickChange',
'springs.viewChange',
'springs.timedChange',
'springs.stateChange',
'springs.directChange',
'springs.menuOpen',
'springs.menuClose',
'timing.curves.viewChange',
'timing.curves.exit',
'timing.curves.entrance',
'timing.curves.move',
]);
expect(motionRoleIn(timing, 'stateChangeMs')?.id).toBe(
'timing.stateChangeMs',
);
// A preset or curve-shape name is no role id.
for (const old of [
'springs.smooth',
'springs.bouncy',
'timing.curves.easeInOut',
'timing.implicitAnimationMs',
]) {
expect(listMotionRoles().map(role => role.id)).not.toContain(old);
}
});

it("leaves the keyboard's motion out: it rides the keyboard (FR4)", () => {
expect(motionRoleOf(springs.keyboard)).toBeUndefined();
expect(motionRoleIn(timing, 'keyboardNotificationMs')).toBeUndefined();
});

it('refuses a spring that never settles', () => {
expect(() =>
formatMotionRoleValue('spring', {duration: 0.5, bounce: 1}),
).toThrow(/must settle/);
expect(() =>
formatMotionRoleValue('spring', {response: 0.5, dampingRatio: 0}),
).toThrow(/must settle/);
expect(parseMotionRoleValue('spring', '0.5s 1')).toBeNull();
});

it('makes the roles of the shared tables, and keeps every other value internal', () => {
expect(motionRoleOf(springs.viewChange)?.id).toBe('springs.viewChange');
expect(motionRoleOf(timing.curves.move)?.kind).toBe('curve');
expect(motionRoleIn(timing, 'stateChangeMs')?.kind).toBe('duration');
// A component's measured value is an internal constant, not a role.
expect(motionRoleOf(springs.sheetPresent)).toBeUndefined();
expect(springs.sheetPresent).toEqual(springs.viewChange);
expect(motionRoleOf(scroll.bounce)).toBeUndefined();
expect(motionRoleIn(timing.press, 'flashMs')).toBeUndefined();
expect(motionRoleIn(navigation, 'transitionMs')).toBeUndefined();
// The Reduced Motion fade, UIKit's menu spring under Reduce Motion, the
// thresholds and the arbitration timings are not motion roles either.
expect(motionRoleIn(timing, 'reducedMotionCrossFadeMs')).toBeUndefined();
expect(motionRoleOf(springs.menuReducedMotion)).toBeUndefined();
expect(motionRoleIn(timing.press, 'scrollBrakeMs')).toBeUndefined();
expect(motionRoleIn(scroll, 'delaysContentTouchesMs')).toBeUndefined();
expect(motionRoleIn(navigation, 'parallax')).toBeUndefined();
const ids = listMotionRoles().map(role => role.id);
expect(ids.some(id => id.startsWith('gestures.'))).toBe(false);
// Every role has its own CSS variable.
const variables = listMotionRoles().map(role => role.variable);
expect(new Set(variables).size).toBe(variables.length);
});

it('registers exactly the roles spec:AST-094 FR4 names, internally', () => {
// Every table discovery registered (other tests here add fixtures).
const discovered = listMotionRoles().filter(role =>
DISCOVERED.has(role.id.split('.')[0]),
);
expect(
Object.fromEntries(discovered.map(role => [role.id, role.kind])),
).toEqual({
'springs.directChange': 'spring',
'springs.emphasis': 'spring',
'springs.fingerTracking': 'spring',
'springs.menuClose': 'spring',
'springs.menuOpen': 'spring',
'springs.quickChange': 'spring',
'springs.settle': 'spring',
'springs.stateChange': 'spring',
'springs.subMenuBack': 'spring',
'springs.subMenuOpen': 'spring',
'springs.timedChange': 'spring',
'springs.viewChange': 'spring',
'timing.curves.entrance': 'curve',
'timing.curves.exit': 'curve',
'timing.curves.move': 'curve',
'timing.curves.viewChange': 'curve',
'timing.stateChangeMs': 'duration',
});
});

it('writes every table value in CSS form and reads back the same motion', () => {
for (const role of listMotionRoles()) {
const text = formatMotionRoleValue(role.kind, role.value);
const back = parseMotionRoleValue(role.kind, text);
expect(back, `${role.id}: ${text}`).not.toBeNull();
if (role.kind === 'spring') {
const a = toSpring(role.value as Parameters<typeof toSpring>[0]);
const b = toSpring(back as Parameters<typeof toSpring>[0]);
expect(naturalFrequency(b) / naturalFrequency(a)).toBeCloseTo(1, 5);
expect(dampingRatioOf(b)).toBeCloseTo(dampingRatioOf(a), 5);
} else {
expect(back).toEqual(role.value);
}
}
expect(
formatMotionRoleValue('spring', {response: 0.5, dampingRatio: 0.85}),
).toBe('0.5s 0.15');
expect(formatMotionRoleValue('duration', 250)).toBe('250ms');
expect(formatMotionRoleValue('curve', [0.42, 0, 0.58, 1])).toBe(
'cubic-bezier(0.42, 0, 0.58, 1)',
);
});

it('refuses invalid values and reads malformed CSS as unset', () => {
expect(() => formatMotionRoleValue('duration', -1)).toThrow(/≥ 0/);
expect(() => formatMotionRoleValue('curve', [2, 0, 0.5, 1])).toThrow(
/x1 and x2/,
);
expect(() => formatMotionRoleValue('spring', {response: 0.5})).toThrow(
/spring is/,
);
expect(parseMotionRoleValue('spring', '')).toBeNull();
expect(parseMotionRoleValue('spring', 'fast')).toBeNull();
expect(parseMotionRoleValue('spring', '0.4s 0.2')).toEqual({
duration: 0.4,
bounce: 0.2,
});
expect(parseMotionRoleValue('duration', ' 0.3s ')).toBe(300);
expect(parseMotionRoleValue('curve', 'ease-in')).toBeNull();
});
});
Loading
Loading