Skip to content

Commit c8d45f8

Browse files
committed
Linting and cleanup and adjusted scrim
1 parent 29ed8e3 commit c8d45f8

11 files changed

+274
-327
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# PostCSS Easing Gradients
22
PostCSS plugin to create smooth linear-gradients that approximate easing functions.
33

4+
[![js-sta
5+
ndard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](http://standardjs.com)
6+
47
The syntax is `<gradient-type>([ <direction>,]? <start-color>, <stop-color>)` where
58
* `gradient-type` is one of the supported gradient types
69
* `direction` shares syntax with `linear-gradient` and is optional

demo/css/styles.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ body {
88
}
99

1010
.gradient {
11-
background-image: linear-gradient(to right, hsl(0, 100%, 50%), hsla(0, 100%, 50%, 0));
11+
background-image: linear-gradient(to right, black, transparent);
1212
background-position: center;
1313
background-repeat: no-repeat;
1414
background-size: cover;
1515
height: 50vh;
1616
width: 50vw;
17-
margin: 0 auto;
17+
margin-left: 25vw;
1818
}
1919

2020
.gradient--easing {
21-
background-image: linear-gradient(to right, hsl(0, 100%, 50%) 0, hsla(0, 100%, 50%, 0.917) 5.3%, hsla(0, 100%, 50%, 0.834) 10.6%, hsla(0, 100%, 50%, 0.753) 15.9%, hsla(0, 100%, 50%, 0.672) 21.3%, hsla(0, 100%, 50%, 0.591) 26.8%, hsla(0, 100%, 50%, 0.511) 32.5%, hsla(0, 100%, 50%, 0.433) 38.4%, hsla(0, 100%, 50%, 0.357) 44.5%, hsla(0, 100%, 50%, 0.283) 50.9%, hsla(0, 100%, 50%, 0.213) 57.7%, hsla(0, 100%, 50%, 0.147) 65%, hsla(0, 100%, 50%, 0.089) 72.9%, hsla(0, 100%, 50%, 0.042) 81.4%, hsla(0, 100%, 50%, 0.011) 90.6%, hsla(0, 100%, 50%, 0) 100%);
22-
width: 50vw;
21+
background-image: linear-gradient(to right, hsl(0, 0%, 0%) 0%, hsla(0, 0%, 0%, 0.738) 19%, hsla(0, 0%, 0%, 0.541) 34%, hsla(0, 0%, 0%, 0.382) 47%, hsla(0, 0%, 0%, 0.278) 56.5%, hsla(0, 0%, 0%, 0.194) 65%, hsla(0, 0%, 0%, 0.126) 73%, hsla(0, 0%, 0%, 0.075) 80.2%, hsla(0, 0%, 0%, 0.042) 86.1%, hsla(0, 0%, 0%, 0.021) 91%, hsla(0, 0%, 0%, 0.008) 95.2%, hsla(0, 0%, 0%, 0.002) 98.2%, transparent 100%);
22+
width: 65vw;
2323
}

demo/css/styles.pcss

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ body {
88
}
99

1010
.gradient {
11-
background-image: linear-gradient(to right, hsl(0, 100%, 50%), hsla(0, 100%, 50%, 0));
11+
background-image: linear-gradient(to right, black, transparent);
1212
background-position: center;
1313
background-repeat: no-repeat;
1414
background-size: cover;
1515
height: 50vh;
1616
width: 50vw;
17-
margin: 0 auto;
17+
margin-left: 25vw;
1818
}
1919

2020
.gradient--easing {
21-
background-image: ease-out-sine-gradient(to right, hsla(0, 100%, 50%, 1), hsla(0, 100%, 50%, 0));
22-
width: 50vw;
21+
background-image: scrim-gradient(to right, black, transparent);
22+
width: 65vw;
2323
}

helpers.js

-202
This file was deleted.

index.js

-108
This file was deleted.

lib/getColorStops.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Color = require('color')
2+
const getCoordinates = require('./getCoordinates.js')
3+
const helpers = require('./helpers.js')
4+
5+
/**
6+
* Calculate the color stops based on start+stopColor in an array and easingType
7+
*/
8+
module.exports = (colors, easingType, delta, alphaDecimals) => {
9+
const fixedColors = helpers.transparentFix(colors)
10+
const gradientCoordinates = getCoordinates(easingType, delta)
11+
let colorStops = ''
12+
Object.keys(gradientCoordinates).forEach((ammount) => {
13+
// https://github.com/Qix-/color
14+
let color = Color(fixedColors[1]).mix(Color(fixedColors[0]), ammount)
15+
color = color.hsl().string()
16+
color = helpers.roundHslAlpha(color, alphaDecimals)
17+
colorStops += `${color} ${gradientCoordinates[ammount]}, `
18+
})
19+
colorStops += `${colors[1]} 100%`
20+
return colorStops
21+
}

0 commit comments

Comments
 (0)