Skip to content

Commit 7aad44b

Browse files
committed
Use easing-coordinates and change to proposed syntax
1 parent 3d7ddf2 commit 7aad44b

14 files changed

+232
-389
lines changed

README.md

+98-93
Original file line numberDiff line numberDiff line change
@@ -8,144 +8,149 @@
88

99
</div>
1010

11-
[PostCSS] plugin to create smooth linear-gradients that approximate easing functions.
11+
<br>
1212

13-
```css
14-
.demo {
15-
background: scrim-gradient(
16-
black,
17-
transparent
18-
);
13+
[PostCSS](https://github.com/postcss/postcss) plugin to create smooth linear-gradients that approximate easing functions.
1914

20-
background: ease-in-out-quad-gradient(
21-
to bottom left,
22-
#bada55,
23-
olive
24-
);
15+
Visual examples and online editor on [larsenwork.com/easing-gradients](https://larsenwork.com/easing-gradients/)
2516

26-
background: ease-in-sine-gradient(
27-
23deg,
28-
hsla(300, 80%, 50%, 0.7),
29-
rgb(120, 140, 255)
30-
);
31-
}
32-
```
17+
⚠️ The [syntax](#syntax) has changed substantially in `^v.2.0.0` ⚠️
18+
19+
<br>
3320

34-
becomes
21+
## Examples
3522

3623
```css
37-
.demo {
24+
.cubic-bezier {
3825
background: linear-gradient(
26+
to bottom,
27+
black,
28+
cubic-bezier(0.48, 0.30, 0.64, 1.00),
29+
transparent
30+
);
31+
/* => */
32+
background: linear-gradient(
33+
to bottom,
3934
hsl(0, 0%, 0%) 0%,
40-
hsla(0, 0%, 0%, 0.738) 19%,
41-
hsla(0, 0%, 0%, 0.541) 34%,
42-
hsla(0, 0%, 0%, 0.382) 47%,
43-
hsla(0, 0%, 0%, 0.278) 56.5%,
44-
hsla(0, 0%, 0%, 0.194) 65%,
45-
hsla(0, 0%, 0%, 0.126) 73%,
46-
hsla(0, 0%, 0%, 0.075) 80.2%,
47-
hsla(0, 0%, 0%, 0.042) 86.1%,
48-
hsla(0, 0%, 0%, 0.021) 91%,
49-
hsla(0, 0%, 0%, 0.008) 95.2%,
50-
hsla(0, 0%, 0%, 0.002) 98.2%,
35+
hsla(0, 0%, 0%, 0.94505) 7.9%,
36+
hsla(0, 0%, 0%, 0.88294) 15.3%,
37+
hsla(0, 0%, 0%, 0.81522) 22.2%,
38+
hsla(0, 0%, 0%, 0.7426) 28.7%,
39+
hsla(0, 0%, 0%, 0.66692) 34.8%,
40+
hsla(0, 0%, 0%, 0.58891) 40.6%,
41+
hsla(0, 0%, 0%, 0.50925) 46.2%,
42+
hsla(0, 0%, 0%, 0.42866) 51.7%,
43+
hsla(0, 0%, 0%, 0.34817) 57.2%,
44+
hsla(0, 0%, 0%, 0.2693) 62.8%,
45+
hsla(0, 0%, 0%, 0.19309) 68.7%,
46+
hsla(0, 0%, 0%, 0.12126) 75.2%,
47+
hsla(0, 0%, 0%, 0.05882) 82.6%,
48+
hsla(0, 0%, 0%, 0.01457) 91.2%,
5149
hsla(0, 0%, 0%, 0) 100%
5250
);
51+
}
5352

53+
.ease {
5454
background: linear-gradient(
55-
to bottom left,
56-
hsl(74.4, 64.3%, 59.4%) 0%,
57-
hsl(74.2, 63.2%, 58.8%) 9.7%,
58-
hsl(73.5, 60.7%, 57.1%) 18.3%,
59-
hsl(72.6, 57.5%, 54.9%) 25.7%,
60-
hsl(71.5, 54.2%, 52.3%) 32.2%,
61-
hsl(70.4, 52.1%, 49.6%) 37.9%,
62-
hsl(69.2, 55.1%, 46.7%) 43.1%,
63-
hsl(67.9, 58.7%, 43.7%) 47.9%,
64-
hsl(66.7, 62.8%, 40.6%) 52.4%,
65-
hsl(65.4, 67.6%, 37.7%) 57.2%,
66-
hsl(64.2, 72.9%, 34.8%) 62.4%,
67-
hsl(63, 79%, 32%) 68.2%,
68-
hsl(61.9, 85.5%, 29.5%) 74.7%,
69-
hsl(60.9, 92.3%, 27.3%) 82.2%,
70-
hsl(60.2, 97.8%, 25.7%) 90.9%,
71-
hsl(60, 100%, 25.1%) 100%
55+
green,
56+
ease,
57+
red
7258
);
73-
74-
59+
/* => */
7560
background: linear-gradient(
76-
23deg,
77-
hsla(300, 80%, 50%, 0.7) 0%,
78-
hsla(299.1, 80.2%, 50.6%, 0.703) 9.7%,
79-
hsla(296.8, 80.7%, 52.1%, 0.713) 18.9%,
80-
hsla(293.3, 81.6%, 54.3%, 0.727) 27.4%,
81-
hsla(289.1, 82.6%, 56.7%, 0.745) 35.2%,
82-
hsla(284.3, 83.7%, 59.2%, 0.764) 42.5%,
83-
hsla(279.2, 85%, 61.7%, 0.786) 49.3%,
84-
hsla(274, 86.4%, 64%, 0.808) 55.7%,
85-
hsla(268.5, 87.8%, 66.2%, 0.831) 61.8%,
86-
hsla(263, 89.4%, 68.2%, 0.854) 67.7%,
87-
hsla(257.4, 91%, 70.1%, 0.878) 73.4%,
88-
hsla(251.8, 92.7%, 71.8%, 0.902) 78.9%,
89-
hsla(246.2, 94.4%, 73.4%, 0.927) 84.3%,
90-
hsla(240.6, 96.2%, 74.9%, 0.951) 89.6%,
91-
hsla(235.4, 98.3%, 74.3%, 0.976) 94.9%,
92-
hsl(231.1, 100%, 73.5%) 100%
61+
hsl(120, 100%, 25.1%) 0%,
62+
hsl(111.85, 100%, 23.5%) 7.8%,
63+
hsl(98.92, 100%, 21.34%) 13.2%,
64+
hsl(82.02, 100%, 19.05%) 17.6%,
65+
hsl(60.02, 100%, 16.71%) 21.7%,
66+
hsl(40.57, 100%, 21.3%) 25.8%,
67+
hsl(28.11, 100%, 25.86%) 30.2%,
68+
hsl(19.54, 100%, 30.32%) 35.1%,
69+
hsl(13.47, 100%, 34.55%) 40.6%,
70+
hsl(9.01, 100%, 38.49%) 46.9%,
71+
hsl(5.73, 100%, 42.01%) 54.1%,
72+
hsl(3.36, 100%, 44.98%) 62.2%,
73+
hsl(1.74, 100%, 47.28%) 71.1%,
74+
hsl(0.7, 100%, 48.86%) 80.6%,
75+
hsl(0.15, 100%, 49.74%) 90.5%,
76+
hsl(0, 100%, 50%) 100%
9377
);
9478
}
95-
```
9679

97-
## Usage
98-
99-
```js
100-
postcss([ require('postcss-easing-gradients') ])
80+
.steps {
81+
background: linear-gradient(
82+
to right,
83+
green,
84+
steps(4, skip-none),
85+
red
86+
);
87+
/* => */
88+
background: linear-gradient(
89+
to right,
90+
hsl(120, 100%, 25.1%) 0%,
91+
hsl(120, 100%, 25.1%) 25%,
92+
hsl(60.23, 100%, 16.73%) 25%,
93+
hsl(60.23, 100%, 16.73%) 50%,
94+
hsl(15.06, 100%, 33.33%) 50%,
95+
hsl(15.06, 100%, 33.33%) 75%,
96+
hsl(0, 100%, 50%) 75%,
97+
hsl(0, 100%, 50%) 100%
98+
);
99+
}
101100
```
102101

103-
See [PostCSS] docs for examples for your environment.
102+
<br>
104103

105104
## Syntax
106105

107-
The syntax is `<gradient-type>([ <direction>,]? <start-color>, <stop-color>)` where
106+
Ccurrently only a subset of the [full syntax](https://github.com/w3c/csswg-drafts/issues/1332#issuecomment-299990698) is supported:
108107

109-
* `gradient-type` is one of the supported gradient types
110-
* `direction` shares syntax with `linear-gradient` and is optional
111-
* `start-color` and `stop-color` are css colors in any format
108+
```xml
109+
linear-gradient(
110+
[ <direction>,]?
111+
<color>,
112+
<animation-timing-function>,
113+
<color>
114+
)
115+
```
112116

113-
Note that it's exactly two colors and it doesn't support custom color stop locations.
117+
The steps syntax is also being figured out and currently [this](https://github.com/w3c/csswg-drafts/issues/1680#issuecomment-361550637) is supported.
114118

115-
## Supported Gradient Types
119+
<br>
116120

117-
```css
118-
ease-in-sine-gradient
119-
ease-out-sine-gradient
120-
ease-in-out-sine-gradient
121-
ease-in-quad-gradient
122-
ease-out-quad-gradient
123-
ease-in-out-quad-gradient
124-
scrim-gradient
121+
## Usage
122+
123+
```js
124+
postcss([ require('postcss-easing-gradients') ])
125125
```
126126

127+
See [PostCSS Usage](https://github.com/postcss/postcss#usage) docs for examples for your environment.
128+
129+
<br>
130+
127131
## Options
128132

129-
* `precision: 0.1` is the default value and creates ~17 color stops. I wouldn't recommending using anything above 0.2 as banding becomes very obvious.
130-
* `alphaDecimals: 3` is the default number of decimals for alpha values and I wouldn't recommend changing it. Increase it for greater precision.
133+
I wouldn't recommend tweaking from default values but:
131134

132-
## Preview
135+
* `precision: 0.1` is the default and creates ~17 color stops. A higher number creates a more "low poly" gradient and banding becomes very visible when using anything above 0.2.
136+
* `alphaDecimals: 5` is the default. A lower number can result in banding.
133137

134-
![preview](assets/linear-scrim-easeoutsine.gif)
138+
<br>
135139

136140
## Demo
137141

138142
Make sure that you have gulp cli installed and then `cd demo`, `npm install` and `gulp`.
139143

140144
If you want to develop then `npm link` in project root and then `npm link postcss-easing-gradients`
141145

146+
<br>
147+
142148
## Contributions
143149

144150
Are more than welcome. Code is linted using:
145151

146152
[![js-standard-style][js-img]][js]
147153

148-
[PostCSS]: https://github.com/postcss/postcss
149154
[ci-img]: https://img.shields.io/travis/larsenwork/postcss-easing-gradients.svg
150155
[ci]: https://travis-ci.org/larsenwork/postcss-easing-gradients
151156
[js-img]: https://cdn.rawgit.com/feross/standard/master/badge.svg

assets/linear-scrim-easeoutsine.gif

-868 KB
Binary file not shown.

demo/css/styles.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ body {
88
}
99

1010
.gradient {
11-
background-image: linear-gradient(to right, black, transparent);
11+
background-image: linear-gradient(to right, red, blue);
1212
background-position: center;
1313
background-repeat: no-repeat;
1414
background-size: cover;
@@ -17,7 +17,7 @@ body {
1717
}
1818

1919
.gradient--easing {
20-
background: linear-gradient(to right, black, hsla(0, 0%, 0%, 0.988) 7.7%, hsla(0, 0%, 0%, 0.956) 14.8%, hsla(0, 0%, 0%, 0.91) 21%, hsla(0, 0%, 0%, 0.854) 26.5%, hsla(0, 0%, 0%, 0.794) 31.4%, hsla(0, 0%, 0%, 0.731) 35.9%, hsla(0, 0%, 0%, 0.667) 40.1%, hsla(0, 0%, 0%, 0.599) 44.2%, hsla(0, 0%, 0%, 0.533) 48.1%, hsla(0, 0%, 0%, 0.466) 52%, hsla(0, 0%, 0%, 0.397) 56%, hsla(0, 0%, 0%, 0.33) 60.1%, hsla(0, 0%, 0%, 0.266) 64.3%, hsla(0, 0%, 0%, 0.203) 68.8%, hsla(0, 0%, 0%, 0.143) 73.7%, hsla(0, 0%, 0%, 0.089) 79.2%, hsla(0, 0%, 0%, 0.043) 85.4%, hsla(0, 0%, 0%, 0.011) 92.5%, transparent);
20+
background: linear-gradient(hsl(0, 0%, 0%) 0%, hsla(0, 0%, 0%, 0.94505) 7.9%, hsla(0, 0%, 0%, 0.88294) 15.3%, hsla(0, 0%, 0%, 0.81522) 22.2%, hsla(0, 0%, 0%, 0.7426) 28.7%, hsla(0, 0%, 0%, 0.66692) 34.8%, hsla(0, 0%, 0%, 0.58891) 40.6%, hsla(0, 0%, 0%, 0.50925) 46.2%, hsla(0, 0%, 0%, 0.42866) 51.7%, hsla(0, 0%, 0%, 0.34817) 57.2%, hsla(0, 0%, 0%, 0.2693) 62.8%, hsla(0, 0%, 0%, 0.19309) 68.7%, hsla(0, 0%, 0%, 0.12126) 75.2%, hsla(0, 0%, 0%, 0.05882) 82.6%, hsla(0, 0%, 0%, 0.01457) 91.2%, hsla(0, 0%, 0%, 0) 100%);
2121
width: 100vw;
2222
opacity: 1;
2323
}

demo/css/styles.pcss

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ body {
88
}
99

1010
.gradient {
11-
background-image: linear-gradient(to right, black, transparent);
11+
background-image: linear-gradient(to right, red, blue);
1212
background-position: center;
1313
background-repeat: no-repeat;
1414
background-size: cover;
@@ -17,12 +17,7 @@ body {
1717
}
1818

1919
.gradient--easing {
20-
background: linear-gradient(
21-
to right,
22-
black,
23-
cubic-bezier(0.42, 0, 0.58, 1),
24-
transparent
25-
);
20+
background: linear-gradient(black, cubic-bezier(0.48, 0.30, 0.64, 1.00), transparent);
2621
width: 100vw;
2722
opacity: 1;
2823
}

demo/gulpfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function css () {
3939
.pipe(gulpPostcss([
4040
easingGradient({
4141
// Default settings
42-
precision: 0.10,
43-
alphaDecimals: 3
42+
precision: 0.1,
43+
alphaDecimals: 5
4444
})
4545
]))
4646
.pipe(gulpRename({extname: '.css'}))

demo/package-lock.json

+23-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "MIT",
1111
"devDependencies": {
1212
"browser-sync": "^2.18.8",
13+
"easing-coordinates": "^1.0.1",
1314
"gulp": "^4.0.0",
1415
"gulp-postcss": "^6.4.0",
1516
"gulp-rename": "^1.2.2",

0 commit comments

Comments
 (0)