@digdir/designsystemet 1.0.5 → 1.0.6
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 +7 -0
- package/dist/bin/designsystemet.js +49 -42
- package/dist/src/colors/index.js +32 -0
- package/dist/src/colors/theme.js +1 -0
- package/dist/src/colors/utils.d.ts +13 -0
- package/dist/src/colors/utils.d.ts.map +1 -1
- package/dist/src/colors/utils.js +32 -0
- package/dist/src/config.js +1 -0
- package/dist/src/index.js +80 -42
- package/dist/src/scripts/createJsonSchema.js +39 -38
- package/dist/src/tokens/build.js +48 -42
- package/dist/src/tokens/create/generators/$designsystemet.js +22 -20
- package/dist/src/tokens/create/generators/$themes.js +10 -10
- package/dist/src/tokens/create/generators/color.js +1 -0
- package/dist/src/tokens/create/write.js +32 -30
- package/dist/src/tokens/create.js +1 -0
- package/dist/src/tokens/format.js +49 -42
- package/dist/src/tokens/index.js +49 -42
- package/dist/src/tokens/process/configs/color.js +26 -22
- package/dist/src/tokens/process/configs/semantic.js +16 -12
- package/dist/src/tokens/process/configs/shared.js +16 -12
- package/dist/src/tokens/process/configs/storefront.js +16 -12
- package/dist/src/tokens/process/configs/typography.js +16 -12
- package/dist/src/tokens/process/configs.js +26 -22
- package/dist/src/tokens/process/formats/css/color.js +16 -12
- package/dist/src/tokens/process/formats/css/semantic.js +16 -12
- package/dist/src/tokens/process/formats/css.js +16 -12
- package/dist/src/tokens/process/formats/js-tokens.js +16 -12
- package/dist/src/tokens/process/platform.js +26 -22
- package/dist/src/tokens/process/theme.js +22 -20
- package/dist/src/tokens/process/transformers.js +16 -12
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +26 -22
- package/dist/src/tokens/utils.d.ts +2 -2
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +16 -12
- package/package.json +31 -29
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Digitaliseringsdirektoratet (Digdir)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -9,6 +9,7 @@ import { fromError } from "zod-validation-error";
|
|
|
9
9
|
|
|
10
10
|
// src/colors/utils.ts
|
|
11
11
|
import chroma from "chroma-js";
|
|
12
|
+
import Colorjs from "colorjs.io";
|
|
12
13
|
import { Hsluv } from "hsluv";
|
|
13
14
|
var getLuminanceFromLightness = (lightness) => {
|
|
14
15
|
const conv = new Hsluv();
|
|
@@ -2687,11 +2688,11 @@ import chalk3 from "chalk";
|
|
|
2687
2688
|
// package.json
|
|
2688
2689
|
var package_default = {
|
|
2689
2690
|
name: "@digdir/designsystemet",
|
|
2690
|
-
version: "1.0.
|
|
2691
|
+
version: "1.0.6",
|
|
2691
2692
|
description: "CLI for Designsystemet",
|
|
2692
2693
|
author: "Designsystemet team",
|
|
2693
2694
|
engines: {
|
|
2694
|
-
node: ">=22.
|
|
2695
|
+
node: ">=22.15.0"
|
|
2695
2696
|
},
|
|
2696
2697
|
repository: {
|
|
2697
2698
|
type: "git",
|
|
@@ -2721,56 +2722,58 @@ var package_default = {
|
|
|
2721
2722
|
},
|
|
2722
2723
|
scripts: {
|
|
2723
2724
|
designsystemet: "tsx ./bin/designsystemet.ts",
|
|
2724
|
-
"build:tokens": "
|
|
2725
|
+
"build:tokens": "pnpm run designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
2725
2726
|
"build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
2726
|
-
build: "tsup &&
|
|
2727
|
+
build: "tsup && pnpm build:types && pnpm build:json-schema",
|
|
2727
2728
|
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
2728
2729
|
"build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
|
|
2729
2730
|
types: "tsc --noEmit",
|
|
2730
|
-
"test:tokens-create-options":
|
|
2731
|
-
"test:tokens-create-config": "
|
|
2732
|
-
"test:tokens-build": "
|
|
2733
|
-
"test:tokens-build-config": "
|
|
2734
|
-
"test:tokens-create-and-build-options": "
|
|
2735
|
-
"test:tokens-create-and-build-config": "
|
|
2736
|
-
test: "
|
|
2737
|
-
"internal:tokens-create": "
|
|
2731
|
+
"test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./test-tokens/options --theme options --clean',
|
|
2732
|
+
"test:tokens-create-config": "pnpm run designsystemet tokens create --config ./test/test-tokens.config.json",
|
|
2733
|
+
"test:tokens-build": "pnpm run designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
|
|
2734
|
+
"test:tokens-build-config": "pnpm run designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
|
|
2735
|
+
"test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
|
|
2736
|
+
"test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
|
|
2737
|
+
test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
|
|
2738
|
+
"internal:tokens-create": "pnpm run designsystemet tokens create --config ./internal.config.json",
|
|
2738
2739
|
"update:template": "tsx ./src/scripts/update-template.ts",
|
|
2739
|
-
"update:design-tokens": "
|
|
2740
|
-
verify: "
|
|
2740
|
+
"update:design-tokens": "pnpm internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
|
|
2741
|
+
verify: "pnpm test && pnpm update:template && pnpm update:design-tokens"
|
|
2741
2742
|
},
|
|
2742
2743
|
dependencies: {
|
|
2743
2744
|
"@commander-js/extra-typings": "^13.1.0",
|
|
2744
|
-
"@tokens-studio/sd-transforms": "1.
|
|
2745
|
+
"@tokens-studio/sd-transforms": "1.3.0",
|
|
2745
2746
|
"apca-w3": "^0.1.9",
|
|
2746
2747
|
chalk: "^5.4.1",
|
|
2747
2748
|
"change-case": "^5.4.4",
|
|
2748
2749
|
"chroma-js": "^3.1.2",
|
|
2750
|
+
"colorjs.io": "^0.6.0-alpha.1",
|
|
2749
2751
|
commander: "^13.1.0",
|
|
2750
2752
|
"fast-glob": "^3.3.3",
|
|
2751
2753
|
hsluv: "^1.0.1",
|
|
2752
2754
|
"object-hash": "^3.0.0",
|
|
2753
2755
|
postcss: "^8.5.3",
|
|
2754
2756
|
ramda: "^0.30.1",
|
|
2755
|
-
"style-dictionary": "^4.
|
|
2756
|
-
zod: "^3.24.
|
|
2757
|
+
"style-dictionary": "^4.4.0",
|
|
2758
|
+
zod: "^3.24.4",
|
|
2757
2759
|
"zod-validation-error": "^3.4.0"
|
|
2758
2760
|
},
|
|
2759
2761
|
devDependencies: {
|
|
2762
|
+
"@tokens-studio/types": "0.5.2",
|
|
2760
2763
|
"@types/apca-w3": "^0.1.3",
|
|
2761
2764
|
"@types/chroma-js": "^3.1.1",
|
|
2762
2765
|
"@types/fs-extra": "^11.0.4",
|
|
2763
2766
|
"@types/glob": "^8.1.0",
|
|
2764
2767
|
"@types/jscodeshift": "^0.12.0",
|
|
2765
|
-
"@types/node": "^22.
|
|
2768
|
+
"@types/node": "^22.15.3",
|
|
2766
2769
|
"@types/object-hash": "^3.0.6",
|
|
2767
2770
|
"@types/ramda": "^0.30.2",
|
|
2768
2771
|
"fs-extra": "^11.3.0",
|
|
2769
2772
|
"ts-toolbelt": "^9.6.0",
|
|
2770
2773
|
tslib: "^2.8.1",
|
|
2771
2774
|
tsup: "^8.4.0",
|
|
2772
|
-
tsx: "^4.19.
|
|
2773
|
-
typescript: "^5.8.
|
|
2775
|
+
tsx: "^4.19.4",
|
|
2776
|
+
typescript: "^5.8.3",
|
|
2774
2777
|
"zod-to-json-schema": "^3.24.5"
|
|
2775
2778
|
}
|
|
2776
2779
|
};
|
|
@@ -2871,20 +2874,24 @@ var mapToLowerCase = R11.map(R11.toLower);
|
|
|
2871
2874
|
var hasAnyTruth = R11.any(R11.equals(true));
|
|
2872
2875
|
var getType = (token) => (token.$type ?? token.type) || "";
|
|
2873
2876
|
var getValue = (token) => token.$value ?? token.value;
|
|
2874
|
-
var typeEquals = R11.curry(
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
+
var typeEquals = R11.curry(
|
|
2878
|
+
(types, token) => {
|
|
2879
|
+
if (R11.isNil(token)) {
|
|
2880
|
+
return false;
|
|
2881
|
+
}
|
|
2882
|
+
return R11.includes(R11.toLower(getType(token)), R11.map(R11.toLower, Array.isArray(types) ? types : [types]));
|
|
2877
2883
|
}
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2884
|
+
);
|
|
2885
|
+
var pathStartsWithOneOf = R11.curry(
|
|
2886
|
+
(paths, token) => {
|
|
2887
|
+
if (R11.isNil(token)) {
|
|
2888
|
+
return false;
|
|
2889
|
+
}
|
|
2890
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
2891
|
+
const matchPathsStartingWith = R11.map((path5) => R11.startsWith([path5], tokenPath), mapToLowerCase(paths));
|
|
2892
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
2883
2893
|
}
|
|
2884
|
-
|
|
2885
|
-
const matchPathsStartingWith = R11.map((path5) => R11.startsWith([path5], tokenPath), mapToLowerCase(paths));
|
|
2886
|
-
return hasAnyTruth(matchPathsStartingWith);
|
|
2887
|
-
});
|
|
2894
|
+
);
|
|
2888
2895
|
function isSemanticToken(token) {
|
|
2889
2896
|
return token.filePath.includes("semantic/");
|
|
2890
2897
|
}
|
|
@@ -3440,14 +3447,14 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
3440
3447
|
};
|
|
3441
3448
|
};
|
|
3442
3449
|
|
|
3443
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
|
|
3450
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
|
|
3444
3451
|
var BoxShadowTypes;
|
|
3445
3452
|
(function(BoxShadowTypes2) {
|
|
3446
3453
|
BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
|
|
3447
3454
|
BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
|
|
3448
3455
|
})(BoxShadowTypes || (BoxShadowTypes = {}));
|
|
3449
3456
|
|
|
3450
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
|
|
3457
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
|
|
3451
3458
|
var ColorModifierTypes;
|
|
3452
3459
|
(function(ColorModifierTypes2) {
|
|
3453
3460
|
ColorModifierTypes2["LIGHTEN"] = "lighten";
|
|
@@ -3456,7 +3463,7 @@ var ColorModifierTypes;
|
|
|
3456
3463
|
ColorModifierTypes2["ALPHA"] = "alpha";
|
|
3457
3464
|
})(ColorModifierTypes || (ColorModifierTypes = {}));
|
|
3458
3465
|
|
|
3459
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
|
|
3466
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
|
|
3460
3467
|
var ColorSpaceTypes;
|
|
3461
3468
|
(function(ColorSpaceTypes2) {
|
|
3462
3469
|
ColorSpaceTypes2["LCH"] = "lch";
|
|
@@ -3465,7 +3472,7 @@ var ColorSpaceTypes;
|
|
|
3465
3472
|
ColorSpaceTypes2["HSL"] = "hsl";
|
|
3466
3473
|
})(ColorSpaceTypes || (ColorSpaceTypes = {}));
|
|
3467
3474
|
|
|
3468
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
|
|
3475
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js
|
|
3469
3476
|
var Properties;
|
|
3470
3477
|
(function(Properties2) {
|
|
3471
3478
|
Properties2["sizing"] = "sizing";
|
|
@@ -3517,7 +3524,7 @@ var Properties;
|
|
|
3517
3524
|
Properties2["description"] = "description";
|
|
3518
3525
|
})(Properties || (Properties = {}));
|
|
3519
3526
|
|
|
3520
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
|
|
3527
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
|
|
3521
3528
|
var TokenSetStatus;
|
|
3522
3529
|
(function(TokenSetStatus2) {
|
|
3523
3530
|
TokenSetStatus2["DISABLED"] = "disabled";
|
|
@@ -3525,7 +3532,7 @@ var TokenSetStatus;
|
|
|
3525
3532
|
TokenSetStatus2["ENABLED"] = "enabled";
|
|
3526
3533
|
})(TokenSetStatus || (TokenSetStatus = {}));
|
|
3527
3534
|
|
|
3528
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
|
|
3535
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
|
|
3529
3536
|
var TokenTypes;
|
|
3530
3537
|
(function(TokenTypes2) {
|
|
3531
3538
|
TokenTypes2["OTHER"] = "other";
|
|
@@ -3556,7 +3563,7 @@ var TokenTypes;
|
|
|
3556
3563
|
TokenTypes2["NUMBER"] = "number";
|
|
3557
3564
|
})(TokenTypes || (TokenTypes = {}));
|
|
3558
3565
|
|
|
3559
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
|
|
3566
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js
|
|
3560
3567
|
var BorderValues;
|
|
3561
3568
|
(function(BorderValues2) {
|
|
3562
3569
|
BorderValues2["BORDER_COLOR"] = "color";
|
|
@@ -3564,7 +3571,7 @@ var BorderValues;
|
|
|
3564
3571
|
BorderValues2["BORDER_STYLE"] = "style";
|
|
3565
3572
|
})(BorderValues || (BorderValues = {}));
|
|
3566
3573
|
|
|
3567
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
|
|
3574
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
|
|
3568
3575
|
var StrokeStyleValues;
|
|
3569
3576
|
(function(StrokeStyleValues2) {
|
|
3570
3577
|
StrokeStyleValues2["SOLID"] = "solid";
|
|
@@ -3577,7 +3584,7 @@ var StrokeStyleValues;
|
|
|
3577
3584
|
StrokeStyleValues2["INSET"] = "inset";
|
|
3578
3585
|
})(StrokeStyleValues || (StrokeStyleValues = {}));
|
|
3579
3586
|
|
|
3580
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
|
|
3587
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
|
|
3581
3588
|
var BoxShadowValues;
|
|
3582
3589
|
(function(BoxShadowValues2) {
|
|
3583
3590
|
BoxShadowValues2["TYPE"] = "type";
|
|
@@ -3589,7 +3596,7 @@ var BoxShadowValues;
|
|
|
3589
3596
|
BoxShadowValues2["BLEND_MODE"] = "blendMode";
|
|
3590
3597
|
})(BoxShadowValues || (BoxShadowValues = {}));
|
|
3591
3598
|
|
|
3592
|
-
// ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
|
|
3599
|
+
// ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
|
|
3593
3600
|
var TypographyValues;
|
|
3594
3601
|
(function(TypographyValues2) {
|
|
3595
3602
|
TypographyValues2["FONT_FAMILY"] = "fontFamily";
|
package/dist/src/colors/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/colors/utils.ts
|
|
2
2
|
import chroma from "chroma-js";
|
|
3
|
+
import Colorjs from "colorjs.io";
|
|
3
4
|
import { Hsluv } from "hsluv";
|
|
4
5
|
var hexToCssHsl = (hex, valuesOnly = false) => {
|
|
5
6
|
const [h, s, l] = chroma(hex).hsl();
|
|
@@ -72,6 +73,9 @@ var getLuminanceFromLightness = (lightness) => {
|
|
|
72
73
|
conv.hsluvToHex();
|
|
73
74
|
return chroma(conv.hex).luminance();
|
|
74
75
|
};
|
|
76
|
+
var getLuminanceFromColor = (color) => {
|
|
77
|
+
return chroma(color).luminance();
|
|
78
|
+
};
|
|
75
79
|
var getLightnessFromHex = (hex) => {
|
|
76
80
|
const conv = new Hsluv();
|
|
77
81
|
conv.hex = hex;
|
|
@@ -106,6 +110,32 @@ var rgbToHex = (rgb) => {
|
|
|
106
110
|
return hex.length === 1 ? "0" + hex : hex;
|
|
107
111
|
}).join("")}`;
|
|
108
112
|
};
|
|
113
|
+
var convertColor = (cssColor, format) => {
|
|
114
|
+
const color = new Colorjs(cssColor);
|
|
115
|
+
switch (format) {
|
|
116
|
+
case "rgb":
|
|
117
|
+
case "rgba":
|
|
118
|
+
return color.toString({
|
|
119
|
+
format: {
|
|
120
|
+
name: format,
|
|
121
|
+
coords: ["<number>[0, 255]", "<number>[0, 255]", "<number>[0, 255]"]
|
|
122
|
+
},
|
|
123
|
+
precision: 3
|
|
124
|
+
});
|
|
125
|
+
case "hex":
|
|
126
|
+
return color.toString({ format, precision: 3 });
|
|
127
|
+
case "hct":
|
|
128
|
+
return color.to(format).toString({
|
|
129
|
+
format: {
|
|
130
|
+
name: format,
|
|
131
|
+
coords: ["<number>", "<number>", "<number>"]
|
|
132
|
+
},
|
|
133
|
+
precision: 3
|
|
134
|
+
});
|
|
135
|
+
default:
|
|
136
|
+
return color.to(format).toString({ precision: 3 });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
109
139
|
|
|
110
140
|
// src/colors/theme.ts
|
|
111
141
|
import chroma2 from "chroma-js";
|
|
@@ -450,6 +480,7 @@ export {
|
|
|
450
480
|
baseColors,
|
|
451
481
|
canTextBeUsedOnColors,
|
|
452
482
|
colorMetadata,
|
|
483
|
+
convertColor,
|
|
453
484
|
convertToHex,
|
|
454
485
|
generateColorContrast,
|
|
455
486
|
generateColorScale,
|
|
@@ -459,6 +490,7 @@ export {
|
|
|
459
490
|
getContrastFromLightness,
|
|
460
491
|
getCssVariable,
|
|
461
492
|
getLightnessFromHex,
|
|
493
|
+
getLuminanceFromColor,
|
|
462
494
|
getLuminanceFromLightness,
|
|
463
495
|
hexToCssHsl,
|
|
464
496
|
hexToHSL,
|
package/dist/src/colors/theme.js
CHANGED
|
@@ -253,6 +253,7 @@ var getColorMetadataByNumber = (number) => {
|
|
|
253
253
|
|
|
254
254
|
// src/colors/utils.ts
|
|
255
255
|
import chroma from "chroma-js";
|
|
256
|
+
import Colorjs from "colorjs.io";
|
|
256
257
|
import { Hsluv } from "hsluv";
|
|
257
258
|
var getLuminanceFromLightness = (lightness) => {
|
|
258
259
|
const conv = new Hsluv();
|
|
@@ -86,6 +86,12 @@ export declare const isHexColor: (hex: string) => boolean;
|
|
|
86
86
|
* @param lightness The lightness value
|
|
87
87
|
*/
|
|
88
88
|
export declare const getLuminanceFromLightness: (lightness: number) => number;
|
|
89
|
+
/**
|
|
90
|
+
* Get the relative luminance from any valid css color
|
|
91
|
+
*
|
|
92
|
+
* @param color
|
|
93
|
+
*/
|
|
94
|
+
export declare const getLuminanceFromColor: (color: string) => number;
|
|
89
95
|
/**
|
|
90
96
|
* Get the HSLuv lightness from a HEX color
|
|
91
97
|
*
|
|
@@ -112,4 +118,11 @@ export declare const rgbToHex: (rgb: {
|
|
|
112
118
|
g: number;
|
|
113
119
|
b: number;
|
|
114
120
|
}) => HexColor;
|
|
121
|
+
/**
|
|
122
|
+
* Convert a color to a different format
|
|
123
|
+
*
|
|
124
|
+
* @param cssColor Any valid css color
|
|
125
|
+
* @param format Color space/format supported here https://colorjs.io/docs/spaces
|
|
126
|
+
*/
|
|
127
|
+
export declare const convertColor: (cssColor: string, format: string) => string;
|
|
115
128
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/colors/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/colors/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,QAAQ,EAAE,oBAAkB,WAO5D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,QAAQ,aAGrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,QAAQ,aAKvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,WAExC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,QAE1D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAM,KAAK,GAAG,GAAW;;;;CAO9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,QAAQ,EAAE,QAAQ,QAAQ,WAIpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,WAAW,MAAM,EAAE,WAAW,QAAQ,EAAE,iBAAiB,QAAQ,WAYzG,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,QAAQ,EAAE,QAAQ,QAAQ,EAAE,OAAM,YAAY,GAAG,IAAI,GAAG,KAAY,YAYhH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,YAErC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,WAAW,MAAM,WAM1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,WAElD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,QAAQ,WAMhD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,kBAAkB,QAAQ,EAAE,iBAAiB,QAAQ,YAe1F,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,QAQ7C,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,QAOnE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,EAAE,QAAQ,MAAM,WA0B5D,CAAC"}
|
package/dist/src/colors/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/colors/utils.ts
|
|
2
2
|
import chroma from "chroma-js";
|
|
3
|
+
import Colorjs from "colorjs.io";
|
|
3
4
|
import { Hsluv } from "hsluv";
|
|
4
5
|
var hexToCssHsl = (hex, valuesOnly = false) => {
|
|
5
6
|
const [h, s, l] = chroma(hex).hsl();
|
|
@@ -72,6 +73,9 @@ var getLuminanceFromLightness = (lightness) => {
|
|
|
72
73
|
conv.hsluvToHex();
|
|
73
74
|
return chroma(conv.hex).luminance();
|
|
74
75
|
};
|
|
76
|
+
var getLuminanceFromColor = (color) => {
|
|
77
|
+
return chroma(color).luminance();
|
|
78
|
+
};
|
|
75
79
|
var getLightnessFromHex = (hex) => {
|
|
76
80
|
const conv = new Hsluv();
|
|
77
81
|
conv.hex = hex;
|
|
@@ -106,14 +110,42 @@ var rgbToHex = (rgb) => {
|
|
|
106
110
|
return hex.length === 1 ? "0" + hex : hex;
|
|
107
111
|
}).join("")}`;
|
|
108
112
|
};
|
|
113
|
+
var convertColor = (cssColor, format) => {
|
|
114
|
+
const color = new Colorjs(cssColor);
|
|
115
|
+
switch (format) {
|
|
116
|
+
case "rgb":
|
|
117
|
+
case "rgba":
|
|
118
|
+
return color.toString({
|
|
119
|
+
format: {
|
|
120
|
+
name: format,
|
|
121
|
+
coords: ["<number>[0, 255]", "<number>[0, 255]", "<number>[0, 255]"]
|
|
122
|
+
},
|
|
123
|
+
precision: 3
|
|
124
|
+
});
|
|
125
|
+
case "hex":
|
|
126
|
+
return color.toString({ format, precision: 3 });
|
|
127
|
+
case "hct":
|
|
128
|
+
return color.to(format).toString({
|
|
129
|
+
format: {
|
|
130
|
+
name: format,
|
|
131
|
+
coords: ["<number>", "<number>", "<number>"]
|
|
132
|
+
},
|
|
133
|
+
precision: 3
|
|
134
|
+
});
|
|
135
|
+
default:
|
|
136
|
+
return color.to(format).toString({ precision: 3 });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
109
139
|
export {
|
|
110
140
|
HSLToHex,
|
|
111
141
|
areColorsContrasting,
|
|
112
142
|
canTextBeUsedOnColors,
|
|
143
|
+
convertColor,
|
|
113
144
|
convertToHex,
|
|
114
145
|
getContrastFromHex,
|
|
115
146
|
getContrastFromLightness,
|
|
116
147
|
getLightnessFromHex,
|
|
148
|
+
getLuminanceFromColor,
|
|
117
149
|
getLuminanceFromLightness,
|
|
118
150
|
hexToCssHsl,
|
|
119
151
|
hexToHSL,
|