tailwindcss-custom-colors 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -11
- package/dist/index.d.ts +12 -4
- package/dist/index.js +64 -19
- package/dist/index.js.map +1 -1
- package/dist/utils/chroma.d.ts +8 -0
- package/dist/utils/chroma.js +39 -2
- package/dist/utils/chroma.js.map +1 -1
- package/dist/utils/hslToRgb.js +30 -6
- package/dist/utils/hslToRgb.js.map +1 -1
- package/dist/utils/variableName.d.ts +1 -0
- package/dist/utils/variableName.js +7 -0
- package/dist/utils/variableName.js.map +1 -0
- package/package.json +34 -30
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Quentin Juarez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## Installation
|
|
2
2
|
|
|
3
3
|
```bash
|
|
4
|
-
#
|
|
4
|
+
# With npm
|
|
5
5
|
npm i tailwindcss-custom-colors@latest
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# With yarn
|
|
8
8
|
yarn add tailwindcss-custom-colors@latest
|
|
9
9
|
```
|
|
10
10
|
|
|
@@ -38,7 +38,7 @@ const extendedColors = generateConfig(colorNames, options);
|
|
|
38
38
|
#### The generateConfig function takes the following parameters:
|
|
39
39
|
|
|
40
40
|
- `colorNames`: An array of color names or a single color name.
|
|
41
|
-
- `options` (optional): An object of options that allows you to customize the generated colors. The available
|
|
41
|
+
- `options` (optional): An object of options that allows you to customize the generated colors. The available options are `suffixMultiplier` (default: `100`), which determines the suffix used to generate variables names (e.g `[1, 10, 100]`) and `variablePrefix` (default: `undefined`), which determines the prefix for the css variable name, none by default.
|
|
42
42
|
|
|
43
43
|
The function returns a config object for Tailwind CSS with the specified color names and their respective tints.
|
|
44
44
|
|
|
@@ -48,16 +48,17 @@ The function returns a config object for Tailwind CSS with the specified color n
|
|
|
48
48
|
const variables = generateStyleVariables(colorParams, options);
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
#### The
|
|
51
|
+
#### The generateStyleVariables function takes the following parameters:
|
|
52
52
|
|
|
53
53
|
- `colorParams`: An array of color params or a single color params including a color (hex) and a name.
|
|
54
|
-
- `options` (optional): An object of options that allows you to customize the generated colors. The available
|
|
55
|
-
of css variables with the specified color names and their respective tints.
|
|
54
|
+
- `options` (optional): An object of options that allows you to customize the generated colors. The available options are `suffixMultiplier` (default: `100`), which determines the suffix used to generate variables names (e.g `[1, 10, 100]`) and `variablePrefix` (default: `undefined`), which determines the prefix for the css variable name, none by default.
|
|
56
55
|
|
|
57
56
|
## Example
|
|
58
57
|
|
|
59
58
|
Extend your tailwind config
|
|
60
59
|
|
|
60
|
+
_tailwind.config.js_
|
|
61
|
+
|
|
61
62
|
```js
|
|
62
63
|
/** @type {import('tailwindcss').Config} */
|
|
63
64
|
import { generateConfig } from "tailwindcss-custom-colors";
|
|
@@ -65,11 +66,7 @@ import { generateConfig } from "tailwindcss-custom-colors";
|
|
|
65
66
|
const extendedColors = generateConfig(["primary", "secondary"]);
|
|
66
67
|
|
|
67
68
|
module.exports = {
|
|
68
|
-
content: [
|
|
69
|
-
"./app/**/*.{js,ts,jsx,tsx}",
|
|
70
|
-
"./pages/**/*.{js,ts,jsx,tsx}",
|
|
71
|
-
"./components/**/*.{js,ts,jsx,tsx}",
|
|
72
|
-
],
|
|
69
|
+
content: ["./src/**/*.{index,vue,js,ts,jsx,tsx}"],
|
|
73
70
|
theme: {
|
|
74
71
|
extend: {
|
|
75
72
|
colors: extendedColors,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
interface Options {
|
|
2
|
-
suffixMultiplier
|
|
1
|
+
export interface Options {
|
|
2
|
+
suffixMultiplier?: 100 | 10 | 1;
|
|
3
|
+
variablePrefix?: string;
|
|
4
|
+
contrast?: boolean;
|
|
5
|
+
complement?: boolean;
|
|
6
|
+
classification?: {
|
|
7
|
+
light: string;
|
|
8
|
+
dark: string;
|
|
9
|
+
};
|
|
10
|
+
steps?: 100 | 50;
|
|
3
11
|
}
|
|
4
12
|
interface TailwindColorsConfig {
|
|
5
13
|
[key: string]: Record<string, string>;
|
|
@@ -21,5 +29,5 @@ interface ColorParams {
|
|
|
21
29
|
* @param {Options} [options] - An object of options (optional)
|
|
22
30
|
* @returns {string} A string of css variables
|
|
23
31
|
*/
|
|
24
|
-
declare const
|
|
25
|
-
export { generateConfig,
|
|
32
|
+
declare const generateStyleVariables: (colorParams: ColorParams[] | ColorParams, options?: Options) => string;
|
|
33
|
+
export { generateConfig, generateStyleVariables };
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.generateStyleVariables = exports.generateConfig = void 0;
|
|
7
7
|
const chroma_1 = require("./utils/chroma");
|
|
8
8
|
const hexToRgb_1 = require("./utils/hexToRgb");
|
|
9
9
|
const hexToHsl_1 = __importDefault(require("./utils/hexToHsl"));
|
|
10
10
|
const round_1 = __importDefault(require("./utils/round"));
|
|
11
|
-
const
|
|
11
|
+
const variableName_1 = __importDefault(require("./utils/variableName"));
|
|
12
|
+
const shades = {
|
|
13
|
+
100: [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
14
|
+
50: [
|
|
15
|
+
0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5,
|
|
16
|
+
],
|
|
17
|
+
};
|
|
12
18
|
const defaultOptions = {
|
|
13
|
-
suffixMultiplier: 100,
|
|
19
|
+
suffixMultiplier: 100,
|
|
20
|
+
variablePrefix: undefined,
|
|
21
|
+
contrast: true,
|
|
22
|
+
complement: true,
|
|
23
|
+
classification: {
|
|
24
|
+
light: "#FFFFFF",
|
|
25
|
+
dark: "#000000",
|
|
26
|
+
},
|
|
27
|
+
steps: 100,
|
|
14
28
|
};
|
|
15
29
|
/**
|
|
16
30
|
* Generate a config colors object for tailwindcss
|
|
@@ -19,18 +33,31 @@ const defaultOptions = {
|
|
|
19
33
|
* @returns {TailwindColorsConfig} A config object for tailwindcss
|
|
20
34
|
*/
|
|
21
35
|
const generateConfig = (colorNames, options) => {
|
|
22
|
-
const
|
|
36
|
+
const { suffixMultiplier, variablePrefix, contrast, complement, steps } = {
|
|
37
|
+
...defaultOptions,
|
|
38
|
+
...(options || {}),
|
|
39
|
+
};
|
|
23
40
|
const colors = Array.isArray(colorNames) ? colorNames : [colorNames];
|
|
24
41
|
const config = {};
|
|
25
|
-
colors.forEach((
|
|
42
|
+
colors.forEach((colorName) => {
|
|
26
43
|
const colorTints = {
|
|
27
|
-
DEFAULT: `rgb(var(${
|
|
44
|
+
DEFAULT: `rgb(var(${(0, variableName_1.default)(colorName, variablePrefix)}) / <alpha-value>)`,
|
|
45
|
+
...(contrast
|
|
46
|
+
? {
|
|
47
|
+
contrast: `rgb(var(${(0, variableName_1.default)(colorName, variablePrefix, "contrast")}) / <alpha-value>)`,
|
|
48
|
+
}
|
|
49
|
+
: {}),
|
|
50
|
+
...(complement
|
|
51
|
+
? {
|
|
52
|
+
complement: `rgb(var(${(0, variableName_1.default)(colorName, variablePrefix, "complement")}) / <alpha-value>)`,
|
|
53
|
+
}
|
|
54
|
+
: {}),
|
|
28
55
|
};
|
|
29
|
-
shades.forEach((shade) => {
|
|
30
|
-
const tintSuffix = `${shade *
|
|
31
|
-
colorTints[tintSuffix] = `rgb(var(${
|
|
56
|
+
shades[steps].forEach((shade) => {
|
|
57
|
+
const tintSuffix = `${shade * suffixMultiplier}`;
|
|
58
|
+
colorTints[tintSuffix] = `rgb(var(${(0, variableName_1.default)(colorName, variablePrefix, tintSuffix)}) / <alpha-value>)`;
|
|
32
59
|
});
|
|
33
|
-
config[
|
|
60
|
+
config[colorName] = colorTints;
|
|
34
61
|
});
|
|
35
62
|
return config;
|
|
36
63
|
};
|
|
@@ -41,29 +68,47 @@ exports.generateConfig = generateConfig;
|
|
|
41
68
|
* @param {Options} [options] - An object of options (optional)
|
|
42
69
|
* @returns {string} A string of css variables
|
|
43
70
|
*/
|
|
44
|
-
const
|
|
45
|
-
const
|
|
71
|
+
const generateStyleVariables = (colorParams, options) => {
|
|
72
|
+
const { suffixMultiplier, variablePrefix, contrast, complement, classification, steps, } = {
|
|
73
|
+
...defaultOptions,
|
|
74
|
+
...(options || {}),
|
|
75
|
+
};
|
|
46
76
|
const colors = Array.isArray(colorParams) ? colorParams : [colorParams];
|
|
47
77
|
const styles = colors.map(({ color, name }) => {
|
|
48
78
|
const hslColor = (0, hexToHsl_1.default)(color);
|
|
49
|
-
const tintsString = [
|
|
50
|
-
|
|
51
|
-
|
|
79
|
+
const tintsString = [
|
|
80
|
+
`${(0, variableName_1.default)(name, variablePrefix)}: ${(0, hexToRgb_1.hexToRgbString)(color)}`,
|
|
81
|
+
...(contrast
|
|
82
|
+
? [
|
|
83
|
+
`${(0, variableName_1.default)(name, variablePrefix, "contrast")}: ${(0, chroma_1.contrast)(hslColor, classification)}`,
|
|
84
|
+
]
|
|
85
|
+
: []),
|
|
86
|
+
...(complement
|
|
87
|
+
? [
|
|
88
|
+
`${(0, variableName_1.default)(name, variablePrefix, "complement")}: ${(0, chroma_1.complement)(hslColor, classification)}`,
|
|
89
|
+
]
|
|
90
|
+
: []),
|
|
91
|
+
];
|
|
92
|
+
shades[steps].forEach((shade) => {
|
|
93
|
+
const tintSuffix = `${shade * suffixMultiplier}`;
|
|
52
94
|
if (shade === 5) {
|
|
53
|
-
tintsString.push(`${name
|
|
95
|
+
tintsString.push(`${(0, variableName_1.default)(name, variablePrefix, tintSuffix)}: ${(0, hexToRgb_1.hexToRgbString)(color)}`);
|
|
54
96
|
}
|
|
55
97
|
else if (shade < 5) {
|
|
56
98
|
let ratio = (0, round_1.default)(-0.2 * shade + 1);
|
|
57
|
-
tintsString.push(`${name
|
|
99
|
+
tintsString.push(`${(0, variableName_1.default)(name, variablePrefix, tintSuffix)}: ${(0, chroma_1.lighten)(hslColor, ratio)}`);
|
|
58
100
|
}
|
|
59
101
|
else {
|
|
60
102
|
let ratio = (0, round_1.default)(0.2 * shade - 1.0);
|
|
61
|
-
tintsString.push(`${name
|
|
103
|
+
tintsString.push(`${(0, variableName_1.default)(name, variablePrefix, tintSuffix)}: ${(0, chroma_1.darken)(hslColor, ratio)}`);
|
|
62
104
|
}
|
|
63
105
|
});
|
|
64
106
|
return tintsString.join(";\n");
|
|
65
107
|
});
|
|
66
108
|
return styles.join(";\n");
|
|
67
109
|
};
|
|
68
|
-
exports.
|
|
110
|
+
exports.generateStyleVariables = generateStyleVariables;
|
|
111
|
+
const colorParams = { color: "#FF0000", name: "red" };
|
|
112
|
+
const styles = generateStyleVariables(colorParams);
|
|
113
|
+
console.log(styles);
|
|
69
114
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAKwB;AACxB,+CAAkD;AAClD,gEAAwC;AACxC,0DAAkC;AAClC,wEAAgD;AAEhD,MAAM,MAAM,GAAG;IACb,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChC,EAAE,EAAE;QACF,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;KAC5E;CACF,CAAC;AA0BF,MAAM,cAAc,GAAmB;IACrC,gBAAgB,EAAE,GAAG;IACrB,cAAc,EAAE,SAAS;IACzB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE;QACd,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,SAAS;KAChB;IACD,KAAK,EAAE,GAAG;CACX,CAAC;AAMF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CACrB,UAA6B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,KAAK,CAAC,EAAE;gBACf,WAAW,CAAC,IAAI,CACd,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,IAAA,yBAAc,EAClE,KAAK,CACN,EAAE,CACJ,CAAC;aACH;iBAAM,IAAI,KAAK,GAAG,CAAC,EAAE;gBACpB,IAAI,KAAK,GAAG,IAAA,eAAK,EAAC,CAAC,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;gBACpC,WAAW,CAAC,IAAI,CACd,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,IAAA,gBAAO,EAC3D,QAAQ,EACR,KAAK,CACN,EAAE,CACJ,CAAC;aACH;iBAAM;gBACL,IAAI,KAAK,GAAG,IAAA,eAAK,EAAC,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC,CAAC;gBACrC,WAAW,CAAC,IAAI,CACd,GAAG,IAAA,sBAAY,EAAC,IAAI,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,IAAA,eAAM,EAC1D,QAAQ,EACR,KAAK,CACN,EAAE,CACJ,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC;AAEuB,wDAAsB;AAE/C,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACtD,MAAM,MAAM,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;AAEnD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/utils/chroma.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function darken(hsl: [number, number, number], val: number): `${number} ${number} ${number}`;
|
|
2
2
|
export declare function lighten(hsl: [number, number, number], val: number): `${number} ${number} ${number}`;
|
|
3
|
+
export declare function contrast(hsl: [number, number, number], classification: {
|
|
4
|
+
light: string;
|
|
5
|
+
dark: string;
|
|
6
|
+
}): `${number} ${number} ${number}`;
|
|
7
|
+
export declare function complement(hsl: [number, number, number], classification: {
|
|
8
|
+
light: string;
|
|
9
|
+
dark: string;
|
|
10
|
+
}): `${number} ${number} ${number}`;
|
package/dist/utils/chroma.js
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.lighten = exports.darken = void 0;
|
|
7
|
-
const hexToRgb_1 = require("./hexToRgb");
|
|
29
|
+
exports.complement = exports.contrast = exports.lighten = exports.darken = void 0;
|
|
30
|
+
const hexToRgb_1 = __importStar(require("./hexToRgb"));
|
|
8
31
|
const hslToRgb_1 = __importDefault(require("./hslToRgb"));
|
|
9
32
|
function darkenHsl(hsl, val) {
|
|
33
|
+
hsl = [...hsl];
|
|
10
34
|
hsl[2] -= hsl[2] * val;
|
|
11
35
|
return hsl;
|
|
12
36
|
}
|
|
13
37
|
function lightenHsl(hsl, val) {
|
|
38
|
+
hsl = [...hsl];
|
|
14
39
|
hsl[2] += hsl[2] * val;
|
|
15
40
|
return hsl;
|
|
16
41
|
}
|
|
@@ -22,4 +47,16 @@ function lighten(hsl, val) {
|
|
|
22
47
|
return (0, hexToRgb_1.rgbToString)((0, hslToRgb_1.default)(lightenHsl(hsl, val)));
|
|
23
48
|
}
|
|
24
49
|
exports.lighten = lighten;
|
|
50
|
+
function contrast(hsl, classification) {
|
|
51
|
+
const [r, g, b] = (0, hslToRgb_1.default)(hsl);
|
|
52
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
53
|
+
return (0, hexToRgb_1.rgbToString)((0, hexToRgb_1.default)(luminance > 0.5 ? classification.dark : classification.light));
|
|
54
|
+
}
|
|
55
|
+
exports.contrast = contrast;
|
|
56
|
+
function complement(hsl, classification) {
|
|
57
|
+
const [r, g, b] = (0, hslToRgb_1.default)(hsl);
|
|
58
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
59
|
+
return (0, hexToRgb_1.rgbToString)((0, hexToRgb_1.default)(luminance < 0.5 ? classification.dark : classification.light));
|
|
60
|
+
}
|
|
61
|
+
exports.complement = complement;
|
|
25
62
|
//# sourceMappingURL=chroma.js.map
|
package/dist/utils/chroma.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chroma.js","sourceRoot":"","sources":["../../src/utils/chroma.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chroma.js","sourceRoot":"","sources":["../../src/utils/chroma.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAmD;AACnD,0DAAkC;AAElC,SAAS,SAAS,CAAC,GAA6B,EAAE,GAAW;IAC3D,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IAEf,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAEvB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,UAAU,CAAC,GAA6B,EAAE,GAAW;IAC5D,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IAEf,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IAEvB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,MAAM,CAAC,GAA6B,EAAE,GAAW;IAC/D,OAAO,IAAA,sBAAW,EAAC,IAAA,kBAAQ,EAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAFD,wBAEC;AAED,SAAgB,OAAO,CAAC,GAA6B,EAAE,GAAW;IAChE,OAAO,IAAA,sBAAW,EAAC,IAAA,kBAAQ,EAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC;AAFD,0BAEC;AAED,SAAgB,QAAQ,CACtB,GAA6B,EAC7B,cAA+C;IAE/C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAA,kBAAQ,EAAC,GAAG,CAAC,CAAC;IAEhC,MAAM,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IAE5D,OAAO,IAAA,sBAAW,EAChB,IAAA,kBAAQ,EAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CACvE,CAAC;AACJ,CAAC;AAXD,4BAWC;AAED,SAAgB,UAAU,CACxB,GAA6B,EAC7B,cAA+C;IAE/C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAA,kBAAQ,EAAC,GAAG,CAAC,CAAC;IAEhC,MAAM,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IAE5D,OAAO,IAAA,sBAAW,EAChB,IAAA,kBAAQ,EAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CACvE,CAAC;AACJ,CAAC;AAXD,gCAWC"}
|
package/dist/utils/hslToRgb.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const round_1 = __importDefault(require("./round"));
|
|
7
|
+
function hueToRgb([p, q, t]) {
|
|
8
|
+
if (t < 0)
|
|
9
|
+
t += 1;
|
|
10
|
+
if (t > 1)
|
|
11
|
+
t -= 1;
|
|
12
|
+
if (t < 1 / 6)
|
|
13
|
+
return p + (q - p) * 6 * t;
|
|
14
|
+
if (t < 1 / 2)
|
|
15
|
+
return q;
|
|
16
|
+
if (t < 2 / 3)
|
|
17
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
18
|
+
return p;
|
|
19
|
+
}
|
|
3
20
|
function hslToRgb([h, s, l]) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
21
|
+
const roundedL = (0, round_1.default)(l);
|
|
22
|
+
if (s === 0) {
|
|
23
|
+
return [
|
|
24
|
+
Math.round(roundedL * 255),
|
|
25
|
+
Math.round(roundedL * 255),
|
|
26
|
+
Math.round(roundedL * 255),
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
const q = roundedL < 0.5 ? roundedL * (1 + s) : roundedL + s - roundedL * s;
|
|
30
|
+
const p = 2 * roundedL - q;
|
|
7
31
|
return [
|
|
8
|
-
Math.round(
|
|
9
|
-
Math.round(
|
|
10
|
-
Math.round(
|
|
32
|
+
Math.round(hueToRgb([p, q, h + 1 / 3]) * 255),
|
|
33
|
+
Math.round(hueToRgb([p, q, h]) * 255),
|
|
34
|
+
Math.round(hueToRgb([p, q, h - 1 / 3]) * 255),
|
|
11
35
|
];
|
|
12
36
|
}
|
|
13
37
|
exports.default = hslToRgb;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hslToRgb.js","sourceRoot":"","sources":["../../src/utils/hslToRgb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hslToRgb.js","sourceRoot":"","sources":["../../src/utils/hslToRgb.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA2B;IACnD,IAAI,CAAC,GAAG,CAAC;QAAE,CAAC,IAAI,CAAC,CAAC;IAClB,IAAI,CAAC,GAAG,CAAC;QAAE,CAAC,IAAI,CAAC,CAAC;IAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACxB,IAAI,CAAC,GA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
|
|
1
|
+
export default function variableName(name: string, prefix?: string, tint?: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function variableName(name, prefix, tint) {
|
|
4
|
+
return `--${prefix ? prefix + "-" : ""}${name}${tint ? "-" + tint : ""}`;
|
|
5
|
+
}
|
|
6
|
+
exports.default = variableName;
|
|
7
|
+
//# sourceMappingURL=variableName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variableName.js","sourceRoot":"","sources":["../../src/utils/variableName.ts"],"names":[],"mappings":";;AAAA,SAAwB,YAAY,CAClC,IAAY,EACZ,MAAe,EACf,IAAa;IAEb,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3E,CAAC;AAND,+BAMC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tailwindcss-custom-colors",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Reactive color shades generator for TailwindCSS",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwindcss-custom-colors",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Reactive color shades generator for TailwindCSS",
|
|
5
|
+
"author": "quentinjuarez",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/quentinjuarez/tailwindcss-custom-colors"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"build": "tsc"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"tailwind",
|
|
20
|
+
"tailwindcss",
|
|
21
|
+
"colors",
|
|
22
|
+
"palette",
|
|
23
|
+
"shades",
|
|
24
|
+
"tints"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^29.5.3",
|
|
28
|
+
"@types/node": "^20.4.4",
|
|
29
|
+
"jest": "^29.6.1",
|
|
30
|
+
"ts-jest": "^29.1.1",
|
|
31
|
+
"typescript": "^5.1.6"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|