Skip to content

Commit fdf598b

Browse files
author
Adam Plesnik
committed
BREAKING: replace .range-start, .range-end with .range
1 parent 4064982 commit fdf598b

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
The plugin provides utilities for a subset of CSS scroll-driven animation properties.
2929

3030
- `animation-timeline`
31-
- `animation-range-start`, `animation-range-end`
31+
- `animation-range`
3232
- `scroll-timeline`, `view-timeline`
3333
- `timeline-scope`
3434

@@ -42,7 +42,7 @@ Scroll and View timelines provide user with better control over the animations.
4242

4343
### Range
4444

45-
Animation range controls start and end of an animation. Utility classes `.range-start` and `.range-end` can be used for setting the start and the end of the range. They default to `entry` and `exit` respectively.
45+
Animation range controls start and end of an animation. Utility class `.range` offers various options along with a possibility to use length modifiers.
4646

4747
### Scope
4848

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adam.plesnik/tailwindcss-scroll-driven-animations",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"author": "Adam Plesnik <[email protected]>",
55
"scripts": {
66
"build": "swc ./src/index.js --out-dir ./dist"

src/index.ts

+17-28
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,18 @@ export = plugin(
5555

5656
matchUtilities(
5757
{
58-
'range-start': (value) => ({
59-
animationRangeStart: value,
58+
range: (value, { modifier }) => ({
59+
animationRange: splitAndCombine(value, modifier),
6060
}),
6161
},
6262
{
6363
values: {
64-
DEFAULT: 'entry',
65-
exit: 'exit',
66-
normal: 'normal',
67-
contain: 'contain',
68-
cover: 'cover',
69-
'entry-crossing': 'entry-crossing',
70-
'exit-crossing': 'exit-crossing',
71-
},
72-
}
73-
)
74-
75-
matchUtilities(
76-
{
77-
'range-end': (value) => ({
78-
animationRangeEnd: value,
79-
}),
80-
},
81-
{
82-
values: {
83-
DEFAULT: 'exit',
84-
entry: 'entry',
85-
normal: 'normal',
86-
contain: 'contain',
87-
cover: 'cover',
88-
'entry-crossing': 'entry-crossing',
89-
'exit-crossing': 'exit-crossing',
64+
DEFAULT: 'cover cover',
65+
'on-entry': 'entry entry',
66+
'on-exit': 'exit exit',
67+
contain: 'contain contain',
9068
},
69+
modifiers: 'any',
9170
}
9271
)
9372
},
@@ -102,3 +81,13 @@ export = plugin(
10281
},
10382
}
10483
)
84+
85+
function splitAndCombine(values: string, modifiers: string | null) {
86+
const defaultValueArray = ['0', '100%']
87+
const valueArray = (values || '').split(' ')
88+
const modifierArray = (modifiers || defaultValueArray.join(',')).split(',')
89+
90+
const combinedValues = [valueArray[0], modifierArray[0], valueArray[1], modifierArray[1]]
91+
92+
return combinedValues.join(' ')
93+
}

0 commit comments

Comments
 (0)