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.
Context
css-analyzerexportsanalyzeAnimation(parsed, callback)which dissects theanimationshorthand into typed components — duration, delay, timing function, iteration count, direction, fill-mode, play-state. Thetransitionshorthand has an analogous structure but no equivalent utility exists.Consumers that need to extract individual components from a
transitionvalue currently must write their own parser loop, filtering outOPERATORnodes and manually inferring component type from node shape.Proposed API
The transition shorthand syntax is:
Comma-separated layers should each invoke the callback independently.
Example
Motivation
Resolves duplicate code paths in consumers that already use
analyzeAnimationfor theanimationshorthand but must fall back to manual walks fortransition. The two shorthands share the same easing-function and duration slot shapes — this utility would allow both to be handled uniformly.