Repository navigation
refactor(motion): core's shared theme-timing reader - #10068
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec 4300371 |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| DateTimeInput | 186.1 kB (+565 B) · 17.2 kB CSS (0) | — | — · — · — |
| SegmentedControl | 84.4 kB (+484 B) · 6.7 kB CSS (0) | — | ✓ · ✓ · ✓ |
| SegmentedControlItem | 12.1 kB (0) · 4.0 kB CSS (0) | — | ✓ · ✓ · ✓ |
Package size: @astryxdesign/core 6.57 MB packed (+3.5 kB); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 9 rows, core 4 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Changes requested. The shared reader and SegmentedControl's move onto it look right: the slide curve is unchanged, and calc() tokens resolve as the transition resolves them. Two things need fixing first:
pressFadeMs(packages/core/src/utils/pressFeedback.ts:165-178) and Lab'sendTiming(packages/lab/src/RefreshControl/refreshPull.ts:175-188) still parse token text beside the new reader, so with--duration-exit: calc(0.1s * 2)a press's fading state clears at 175 ms while its fade plays 200 ms, and with acalc()--duration-mediumRefreshControl's end skips its slide; please route both throughreadThemeTiming(exported by name from@astryxdesign/core/internal/touchfor Lab), or say in the description why it cannot serve them.readThemeTiming(element, {duration: '--duration-exit', …})returns no curve where no stylesheet sets the token, because its declared defaultvar(--duration-fast)is resolved on a probe under<body>where nothing defines--duration-fast(themeTiming.ts:105); resolve avar()default against the element before writing it, and add a--duration-exitcase tothemeTiming.test.ts.
[Automated review]
| probe.style.setProperty('display', 'none', 'important'); | ||
| probe.style.setProperty( | ||
| 'transition-duration', | ||
| read(tokens.duration, durationDefaults[tokens.duration]), |
There was a problem hiding this comment.
--duration-exit's declared default is var(--duration-fast). On this probe under <body>, nothing defines --duration-fast when no stylesheet sets the tokens, so the probe's duration computes to 0s. The reader then returns no curve instead of core's 175 ms. Resolve a var() default against the element before you write it here, and add a --duration-exit case to themeTiming.test.ts.
| @@ -2367,6 +2312,87 @@ test('a drag commits through the destination item’s click too: its onClick run | |||
| }); | |||
|
|
|||
| /** A desktop context: a mouse, no touch, a fine primary pointer. */ | |||
There was a problem hiding this comment.
Non-blocking: this JSDoc describes openWithMouse. It now sits above clickSlide's own JSDoc, so openWithMouse lost its description. Move it back above openWithMouse.
Core gains motion/themeTiming.ts. resolveTiming resolves a duration and an easing written in CSS as a transition resolves them, so the browser computes calc(). readThemeTokens reads theme tokens where an element is; a token with no value reads the default core declares, and the references in that default read their tokens there too. readThemeTiming builds the eased progress from those tokens or from the element's own transition. It returns no curve when the duration is not a positive length or the easing does not parse. SegmentedControl's selection slide drops its private themeTimingOf and timedCurve for these. It reads the same transition and plays the same curve, so its timing is unchanged, calc() tokens included.
4300371 to
3785e40
Compare
|
On the first point: routing |
|
/approve-spec 3785e40 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet. The pull request is a draft from a fork: once it is marked ready, a maintainer adds the ci:run label so CI runs.
There are no blocking findings: the shared reader resolves calc() tokens, nested scopes and the declared defaults as a transition does, SegmentedControl's slide curve is unchanged, and the --duration-exit default and the openWithMouse JSDoc are fixed. Moving pressFadeMs and Lab's endTiming onto the reader in #10069 is fine as its own change.
Non-blocking suggestions:
packages/core/src/motion/themeTiming.ts:69and:77: the JSDocs onfirstDurationMsandfirstEasingrestate their names and parameter type; consider deleting them.packages/core/src/motion/themeTiming.ts:96-97: "The easing is null when it is not a cubic Bézier, and a text left out gives null." carries two topics; consider "The easing is null when it is not a cubic Bézier. A value left out gives null."
[Automated review]
| }; | ||
| } | ||
|
|
||
| /** The first transition's duration in a computed style, in ms. */ |
There was a problem hiding this comment.
Non-blocking: this JSDoc and the one on firstEasing (line 77) restate the function names and their parameter type. Consider deleting both.
| * them where `element` is. A plain time or easing parses as written. Other | ||
| * text, such as `calc()`, resolves on a hidden probe's transition. The | ||
| * duration is null when it is not a time of zero or more. The easing is null | ||
| * when it is not a cubic Bézier, and a text left out gives null. |
There was a problem hiding this comment.
Non-blocking: this sentence carries two topics. Consider: "The easing is null when it is not a cubic Bézier. A value left out gives null."
There was a problem hiding this comment.
Approved pending CI: CI is still running on this head.
There are no blocking findings. The shared reader resolves calc() tokens, nested scopes and the declared defaults as a transition does, SegmentedControl's slide keeps its timing, and the merge of main leaves this pull request's own changes as they were.
Non-blocking suggestion:
packages/core/src/motion/themeTiming.ts:11-12: sincespec:AST-094FR45 changed onmain, a gesture component's tap-started move under touch plays a spring, so "Motion that a tap, a key or the program starts reads its duration and easing from the theme with it." overstates where the reader applies; consider "Motion that plays the theme's curve tokens reads its duration and easing with it."
[Automated review]
| * @position Motion foundation, internal to core. Motion that a tap, a key or | ||
| * the program starts reads its duration and easing from the theme with it. |
There was a problem hiding this comment.
Non-blocking: since spec:AST-094 FR45 changed on main, a gesture component's tap-started move under touch plays a spring (SegmentedControl's own settleLens springs when presenting). Consider: "Motion that plays the theme's curve tokens reads its duration and easing with it."
Maintainer impact
Ten open pull requests each carry a copy of a theme-timing reader, and SegmentedControl has a private one. Two readers disagree on a hand-written
calc()token: a computed transition resolves it, and a token read falls back. This adds one shared reader. SegmentedControl uses it, and the open pull requests move onto it.Intended invariant
A motion's timing is the theme's duration and easing, resolved where the element is:
tempoapplyspec:AST-094FR45;spec:AST-108FR2;spec:AST-090FR2 ("The durations resolve like any token")spec:AST-108FR2's released values (durationDefaults,easeDefaults)--duration-fastand--ease-standardcomponent:SegmentedControlFR9The default only applies without core's stylesheet, which gives every token a value. A zero, empty or unparseable value gets no rule: the reader returns no value, and the caller keeps its own behavior. SegmentedControl's lens lands at once, as before.
Change
motion/themeTiming.ts:resolveTimingresolves a CSS duration and easing as a transition does. Text such ascalc()resolves on a hidden probe's transition.readThemeTokensreads theme tokens where an element is.readThemeTimingbuilds the eased progress from those tokens, or from the element's own transition.themeTimingOfandtimedCurvefor these.Evidence
--duration-fast: calc(0.1s * 2), SegmentedControl reads 200 ms and a token reader 175 ms. A reader that parses token text, as the copies do, fails the reader'scalc()browser cases (not-for-landing 5fbdda3b66).calc(175ms * 1.2)scope. They read one easing for acalc()argument, in Chromium and WebKit. With no stylesheet,--duration-exitreads 175 ms, or the element's--duration-fast.themeTimingOf, moved as is. Its interaction spec, with the newcalc()case, passes on main's build and this one. The curve matches main'stimedCurveat all 293,040 samples before its end (not-for-landing 3534c2d9cc). Past its end the velocity is 0 instead of a one-sided slope or NaN, which a held segment's velocity read can see.Scope
Testing
At this head on main 57e0540. The unit, type and lint runs were at c7ecbc6, whose code is the same; one comment differs.
pnpm exec vitest run --project ui packages/core/src/motion packages/core/src/SegmentedControl packages/core/src/utils packages/core/src/internal packages/lab/src/RefreshControl: 2,123 passed in 95 files.pnpm -F @astryxdesign/core typecheck: 0 errors.CI=true pnpm lint: 0 errors and no new warning.check:knowledge,check:changesets,review:pre(0 findings, 847 lines) and the public-text check pass.themeTiming.interaction.browser.spec.ts: Chromium 6/6, WebKit 6/6. On not-for-landing 5fbdda3b66, which reads token text with a default fallback and no probe, 5 of the 6 fail. The no-stylesheet default case passes there.SegmentedControl.interaction.browser.spec.ts, this branch's file, ran against a Storybook built from main and one from this branch, order-balanced. Chromium: 47 passed in each of four runs. WebKit: 44 passed and 3 skipped by design on both. SegmentedControl's code is unchanged since.timedCurvewith the new curve over 293,040 samples: 5 easings with over- and undershoot, 8 lengths and 6 ranges.atis identical, and the velocity is within 1.5e-7 before the end.