Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = minifyColor;
|
---|
7 |
|
---|
8 | var _color = require("./lib/color");
|
---|
9 |
|
---|
10 | var _getShortestString = _interopRequireDefault(require("./lib/getShortestString"));
|
---|
11 |
|
---|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Performs color value minification
|
---|
16 | *
|
---|
17 | * @param {string} input - CSS value
|
---|
18 | * @param {boolean} options.supportsAlphaHex - Does the browser support 4 & 8 character hex notation
|
---|
19 | * @param {boolean} options.supportsTransparent – Does the browser support "transparent" value properly
|
---|
20 | */
|
---|
21 | function minifyColor(input, options = {}) {
|
---|
22 | const settings = {
|
---|
23 | supportsAlphaHex: false,
|
---|
24 | supportsTransparent: true,
|
---|
25 | ...options
|
---|
26 | };
|
---|
27 | const instance = (0, _color.process)(input);
|
---|
28 |
|
---|
29 | if (instance.isValid()) {
|
---|
30 | // Try to shorten the string if it is a valid CSS color value.
|
---|
31 | // Fall back to the original input if it's smaller or has equal length/
|
---|
32 | return (0, _getShortestString.default)([input.toLowerCase(), instance.toShortString(settings)]);
|
---|
33 | } else {
|
---|
34 | // Possibly malformed, so pass through
|
---|
35 | return input;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | module.exports = exports.default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.