projectwallace / projectwallace/css-analyzer
Add `analyzeTransition` function parallel to `analyzeAnimation`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 366
- Forks
- 15
- Avg merge
- 3h 23m
- Merged PRs (30d)
- 3
Description
Context
css-analyzer exports analyzeAnimation(parsed, callback) which dissects the animation shorthand into typed components — duration, delay, timing function, iteration count, direction, fill-mode, play-state. The transition shorthand has an analogous structure but no equivalent utility exists.
Consumers that need to extract individual components from a transition value currently must write their own parser loop, filtering out OPERATOR nodes and manually inferring component type from node shape.
Proposed API
type TransitionItem =
| { type: 'property'; value: Node }
| { type: 'duration'; value: Node }
| { type: 'delay'; value: Node }
| { type: 'fn'; value: Node }
function analyzeTransition(
parsed: ReturnType<typeof parse_value>,
callback: (item: TransitionItem) => void
): void
The transition shorthand syntax is:
transition: <property> || <duration> || <easing-function> || <delay>
Comma-separated layers should each invoke the callback independently.
Example
import { parse_value } from '@projectwallace/css-parser/parse-value'
import { analyzeTransition } from '@projectwallace/css-analyzer/values'
const parsed = parse_value('opacity 200ms ease-in-out 0s, transform 300ms linear')
analyzeTransition(parsed, (item) => {
if (item.type === 'duration') console.log(item.value.text) // '200ms', '300ms'
if (item.type === 'fn') console.log(item.value.text) // 'ease-in-out', 'linear'
if (item.type === 'property') console.log(item.value.text) // 'opacity', 'transform'
if (item.type === 'delay') console.log(item.value.text) // '0s'
})
Motivation
Resolves duplicate code paths in consumers that already use analyzeAnimation for the animation shorthand but must fall back to manual walks for transition. The two shorthands share the same easing-function and duration slot shapes — this utility would allow both to be handled uniformly.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing analyzeAnimation implementation and the values module entry point, then review how parsed nodes and comma-separated layers are handled. Add analyzeTransition with the proposed TransitionItem callback behavior, and verify that duration, delay, easing function, and property nodes are reported independently for each transition layer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100