-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(postcss-minify-gradients): replace is-color-stop with own code
Get rid of 7 dependencies in a cssnano install. is-color-stop duplicates functionality available from other dependencies. It copies unit parsing code directly from postcss-value-parser. cssnano has color detection logic is already available in colord. Bringing the code inside might also help #560
- Loading branch information
1 parent
04bd16e
commit 91f4daa
Showing
5 changed files
with
62 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/postcss-minify-gradients/src/__tests__/isColorStop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import isColorStop from '../isColorStop.js'; | ||
|
||
test('should recognise color stops', () => { | ||
expect(isColorStop('yellow')).toBe(true); | ||
expect(isColorStop('yellow', '12px')).toBe(true); | ||
expect(isColorStop('yellow', 'px')).toBe(false); | ||
expect(isColorStop('yellow', 'calc(100%)')).toBe(true); | ||
expect(isColorStop(undefined)).toBe(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { unit } from 'postcss-value-parser'; | ||
import { colord, extend } from 'colord'; | ||
import namesPlugin from 'colord/plugins/names'; | ||
|
||
extend([namesPlugin]); | ||
|
||
const lengthArray = [ | ||
'PX', | ||
'IN', | ||
'CM', | ||
'MM', | ||
'EM', | ||
'REM', | ||
'POINTS', | ||
'PC', | ||
'EX', | ||
'CH', | ||
'VW', | ||
'VH', | ||
'VMIN', | ||
'VMAX', | ||
'%', | ||
]; | ||
|
||
function isCSSLengthUnit(input) { | ||
return lengthArray.indexOf(input.toUpperCase()) >= 0; | ||
} | ||
|
||
function isStop(str) { | ||
let stop = !str; | ||
|
||
if (!stop) { | ||
const node = unit(str); | ||
if (node) { | ||
if ( | ||
node.number === 0 || | ||
(!isNaN(node.number) && isCSSLengthUnit(node.unit)) | ||
) { | ||
stop = true; | ||
} | ||
} else { | ||
stop = /^calc\(\S+\)$/g.test(str); | ||
} | ||
} | ||
return stop; | ||
} | ||
|
||
export default function isColorStop(color, stop) { | ||
return colord(color).isValid() && isStop(stop); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters