@vef-framework/shared 2.0.4 → 2.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/dist/cjs/color/color-ops.cjs +1 -76
- package/dist/cjs/color/index.cjs +1 -24
- package/dist/cjs/color/name.cjs +1 -49
- package/dist/cjs/color/palette.cjs +1 -126
- package/dist/cjs/constants/color-names.cjs +1 -1580
- package/dist/cjs/constants/color-palettes.cjs +1 -372
- package/dist/cjs/constants/index.cjs +1 -14
- package/dist/cjs/index.cjs +1 -339
- package/dist/cjs/types/color.cjs +1 -3
- package/dist/cjs/types/common.cjs +1 -3
- package/dist/cjs/types/deep-keys.cjs +1 -3
- package/dist/cjs/types/index.cjs +1 -7
- package/dist/cjs/utils/chrono.cjs +1 -139
- package/dist/cjs/utils/equal.cjs +1 -175
- package/dist/cjs/utils/error.cjs +3 -60
- package/dist/cjs/utils/event.cjs +1 -62
- package/dist/cjs/utils/format.cjs +1 -31
- package/dist/cjs/utils/function.cjs +1 -49
- package/dist/cjs/utils/id.cjs +1 -38
- package/dist/cjs/utils/index.cjs +1 -86
- package/dist/cjs/utils/key.cjs +1 -34
- package/dist/cjs/utils/lib.cjs +1 -234
- package/dist/cjs/utils/object.cjs +1 -20
- package/dist/cjs/utils/path.cjs +1 -63
- package/dist/cjs/utils/pinyin.cjs +1 -53
- package/dist/cjs/utils/security.cjs +1 -44
- package/dist/cjs/utils/string.cjs +1 -13
- package/dist/cjs/utils/task.cjs +1 -17
- package/dist/cjs/utils/tree.cjs +1 -262
- package/dist/cjs/utils/zod.cjs +1 -14
- package/dist/es/color/color-ops.js +64 -58
- package/dist/es/color/index.js +18 -4
- package/dist/es/color/name.js +24 -37
- package/dist/es/color/palette.js +67 -100
- package/dist/es/constants/color-names.js +6 -9
- package/dist/es/constants/color-palettes.js +8 -15
- package/dist/es/constants/index.js +8 -3
- package/dist/es/index.js +165 -30
- package/dist/es/types/color.js +1 -1
- package/dist/es/types/common.js +1 -1
- package/dist/es/types/deep-keys.js +1 -1
- package/dist/es/types/index.js +3 -4
- package/dist/es/utils/chrono.js +71 -88
- package/dist/es/utils/equal.js +111 -161
- package/dist/es/utils/error.js +28 -25
- package/dist/es/utils/event.js +18 -23
- package/dist/es/utils/format.js +16 -22
- package/dist/es/utils/function.js +32 -32
- package/dist/es/utils/id.js +18 -27
- package/dist/es/utils/index.js +80 -18
- package/dist/es/utils/key.js +19 -25
- package/dist/es/utils/lib.js +64 -10
- package/dist/es/utils/object.js +11 -14
- package/dist/es/utils/path.js +57 -48
- package/dist/es/utils/pinyin.js +28 -29
- package/dist/es/utils/security.js +29 -37
- package/dist/es/utils/string.js +7 -8
- package/dist/es/utils/task.js +7 -12
- package/dist/es/utils/tree.js +156 -219
- package/dist/es/utils/zod.js +7 -6
- package/package.json +1 -1
|
@@ -1,76 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
-
|
|
6
|
-
const colord = require('colord');
|
|
7
|
-
const labPlugin = require('colord/plugins/lab');
|
|
8
|
-
const mixPlugin = require('colord/plugins/mix');
|
|
9
|
-
const namesPlugin = require('colord/plugins/names');
|
|
10
|
-
|
|
11
|
-
colord.extend([namesPlugin, mixPlugin, labPlugin]);
|
|
12
|
-
const WHITE_COLOR = "#ffffff";
|
|
13
|
-
function isValidColor(color) {
|
|
14
|
-
return colord.colord(color).isValid();
|
|
15
|
-
}
|
|
16
|
-
function toHexColor(color) {
|
|
17
|
-
return colord.colord(color).toHex();
|
|
18
|
-
}
|
|
19
|
-
function toRgbColor(color) {
|
|
20
|
-
return colord.colord(color).toRgb();
|
|
21
|
-
}
|
|
22
|
-
function toHslColor(color) {
|
|
23
|
-
return colord.colord(color).toHsl();
|
|
24
|
-
}
|
|
25
|
-
function toHsvColor(color) {
|
|
26
|
-
return colord.colord(color).toHsv();
|
|
27
|
-
}
|
|
28
|
-
function getColorDifference(firstColor, secondColor) {
|
|
29
|
-
return colord.colord(firstColor).delta(secondColor);
|
|
30
|
-
}
|
|
31
|
-
function convertHslToHex(hslColor) {
|
|
32
|
-
return colord.colord(hslColor).toHex();
|
|
33
|
-
}
|
|
34
|
-
function setColorAlpha(color, alphaValue) {
|
|
35
|
-
return colord.colord(color).alpha(alphaValue).toHex();
|
|
36
|
-
}
|
|
37
|
-
function mixColor(baseColor, blendColor, blendRatio) {
|
|
38
|
-
return colord.colord(baseColor).mix(blendColor, blendRatio).toHex();
|
|
39
|
-
}
|
|
40
|
-
function convertTransparentToOpaque(color, alphaValue, backgroundColor = WHITE_COLOR) {
|
|
41
|
-
const transparentColor = setColorAlpha(color, alphaValue);
|
|
42
|
-
const {
|
|
43
|
-
r: foregroundR,
|
|
44
|
-
g: foregroundG,
|
|
45
|
-
b: foregroundB
|
|
46
|
-
} = colord.colord(transparentColor).toRgb();
|
|
47
|
-
const {
|
|
48
|
-
r: backgroundR,
|
|
49
|
-
g: backgroundG,
|
|
50
|
-
b: backgroundB
|
|
51
|
-
} = colord.colord(backgroundColor).toRgb();
|
|
52
|
-
const resultRgb = {
|
|
53
|
-
r: calculateRgbComponent(foregroundR, backgroundR, alphaValue),
|
|
54
|
-
g: calculateRgbComponent(foregroundG, backgroundG, alphaValue),
|
|
55
|
-
b: calculateRgbComponent(foregroundB, backgroundB, alphaValue)
|
|
56
|
-
};
|
|
57
|
-
return colord.colord(resultRgb).toHex();
|
|
58
|
-
}
|
|
59
|
-
function isWhiteColor(color) {
|
|
60
|
-
return colord.colord(color).isEqual(WHITE_COLOR);
|
|
61
|
-
}
|
|
62
|
-
function calculateRgbComponent(foregroundValue, backgroundValue, alphaValue) {
|
|
63
|
-
return backgroundValue + (foregroundValue - backgroundValue) * alphaValue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
exports.convertHslToHex = convertHslToHex;
|
|
67
|
-
exports.convertTransparentToOpaque = convertTransparentToOpaque;
|
|
68
|
-
exports.getColorDifference = getColorDifference;
|
|
69
|
-
exports.isValidColor = isValidColor;
|
|
70
|
-
exports.isWhiteColor = isWhiteColor;
|
|
71
|
-
exports.mixColor = mixColor;
|
|
72
|
-
exports.setColorAlpha = setColorAlpha;
|
|
73
|
-
exports.toHexColor = toHexColor;
|
|
74
|
-
exports.toHslColor = toHslColor;
|
|
75
|
-
exports.toHsvColor = toHsvColor;
|
|
76
|
-
exports.toRgbColor = toRgbColor;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("colord"),a=require("colord/plugins/lab"),b=require("colord/plugins/mix"),x=require("colord/plugins/names");r.extend([x,b,a]);const l="#ffffff";function R(o){return r.colord(o).isValid()}function v(o){return r.colord(o).toHex()}function T(o){return r.colord(o).toRgb()}function m(o){return r.colord(o).toHsl()}function p(o){return r.colord(o).toHsv()}function q(o,t){return r.colord(o).delta(t)}function O(o){return r.colord(o).toHex()}function c(o,t){return r.colord(o).alpha(t).toHex()}function P(o,t,n){return r.colord(o).mix(t,n).toHex()}function W(o,t,n=l){const u=c(o,t),{r:i,g:s,b:d}=r.colord(u).toRgb(),{r:f,g,b:C}=r.colord(n).toRgb(),H={r:e(i,f,t),g:e(s,g,t),b:e(d,C,t)};return r.colord(H).toHex()}function h(o){return r.colord(o).isEqual(l)}function e(o,t,n){return t+(o-t)*n}exports.convertHslToHex=O;exports.convertTransparentToOpaque=W;exports.getColorDifference=q;exports.isValidColor=R;exports.isWhiteColor=h;exports.mixColor=P;exports.setColorAlpha=c;exports.toHexColor=v;exports.toHslColor=m;exports.toHsvColor=p;exports.toRgbColor=T;
|
package/dist/cjs/color/index.cjs
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
-
|
|
6
|
-
const colorOps = require('./color-ops.cjs');
|
|
7
|
-
const name = require('./name.cjs');
|
|
8
|
-
const palette = require('./palette.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.convertHslToHex = colorOps.convertHslToHex;
|
|
13
|
-
exports.convertTransparentToOpaque = colorOps.convertTransparentToOpaque;
|
|
14
|
-
exports.getColorDifference = colorOps.getColorDifference;
|
|
15
|
-
exports.isValidColor = colorOps.isValidColor;
|
|
16
|
-
exports.isWhiteColor = colorOps.isWhiteColor;
|
|
17
|
-
exports.mixColor = colorOps.mixColor;
|
|
18
|
-
exports.setColorAlpha = colorOps.setColorAlpha;
|
|
19
|
-
exports.toHexColor = colorOps.toHexColor;
|
|
20
|
-
exports.toHslColor = colorOps.toHslColor;
|
|
21
|
-
exports.toHsvColor = colorOps.toHsvColor;
|
|
22
|
-
exports.toRgbColor = colorOps.toRgbColor;
|
|
23
|
-
exports.getColorName = name.getColorName;
|
|
24
|
-
exports.getColorPalette = palette.getColorPalette;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./color-ops.cjs"),e=require("./name.cjs"),r=require("./palette.cjs");exports.convertHslToHex=o.convertHslToHex;exports.convertTransparentToOpaque=o.convertTransparentToOpaque;exports.getColorDifference=o.getColorDifference;exports.isValidColor=o.isValidColor;exports.isWhiteColor=o.isWhiteColor;exports.mixColor=o.mixColor;exports.setColorAlpha=o.setColorAlpha;exports.toHexColor=o.toHexColor;exports.toHslColor=o.toHslColor;exports.toHsvColor=o.toHsvColor;exports.toRgbColor=o.toRgbColor;exports.getColorName=e.getColorName;exports.getColorPalette=r.getColorPalette;
|
package/dist/cjs/color/name.cjs
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
-
|
|
6
|
-
require('../constants/index.cjs');
|
|
7
|
-
const colorOps = require('./color-ops.cjs');
|
|
8
|
-
const colorNames = require('../constants/color-names.cjs');
|
|
9
|
-
|
|
10
|
-
const COLOR_DISTANCE_WEIGHTS = {
|
|
11
|
-
RGB: 1,
|
|
12
|
-
HSL: 2
|
|
13
|
-
};
|
|
14
|
-
function getColorName(color) {
|
|
15
|
-
const inputHex = colorOps.toHexColor(color);
|
|
16
|
-
const inputRgb = colorOps.toRgbColor(color);
|
|
17
|
-
const inputHsl = colorOps.toHslColor(color);
|
|
18
|
-
let closestColorName = "";
|
|
19
|
-
let smallestDistance = Number.POSITIVE_INFINITY;
|
|
20
|
-
let closestColorIndex = -1;
|
|
21
|
-
const exactMatch = colorNames.colorEntries.find(([hexValue]) => inputHex === hexValue);
|
|
22
|
-
if (exactMatch) {
|
|
23
|
-
return exactMatch[1];
|
|
24
|
-
}
|
|
25
|
-
for (const [index, [hexValue, colorName]] of colorNames.colorEntries.entries()) {
|
|
26
|
-
const distance = calculateColorDistance(inputRgb, inputHsl, hexValue);
|
|
27
|
-
if (distance < smallestDistance) {
|
|
28
|
-
smallestDistance = distance;
|
|
29
|
-
closestColorName = colorName;
|
|
30
|
-
closestColorIndex = index;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return closestColorName || colorNames.colorEntries[closestColorIndex]?.[1] || "Unknown";
|
|
34
|
-
}
|
|
35
|
-
function calculateRgbDistance(rgb1, rgb2) {
|
|
36
|
-
return (rgb1.r - rgb2.r) ** 2 + (rgb1.g - rgb2.g) ** 2 + (rgb1.b - rgb2.b) ** 2;
|
|
37
|
-
}
|
|
38
|
-
function calculateHslDistance(hsl1, hsl2) {
|
|
39
|
-
return (hsl1.h - hsl2.h) ** 2 + (hsl1.s - hsl2.s) ** 2 + (hsl1.l - hsl2.l) ** 2;
|
|
40
|
-
}
|
|
41
|
-
function calculateColorDistance(sourceRgb, sourceHsl, targetHex) {
|
|
42
|
-
const targetRgb = colorOps.toRgbColor(targetHex);
|
|
43
|
-
const targetHsl = colorOps.toHslColor(targetHex);
|
|
44
|
-
const rgbDistance = calculateRgbDistance(sourceRgb, targetRgb);
|
|
45
|
-
const hslDistance = calculateHslDistance(sourceHsl, targetHsl);
|
|
46
|
-
return rgbDistance * COLOR_DISTANCE_WEIGHTS.RGB + hslDistance * COLOR_DISTANCE_WEIGHTS.HSL;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.getColorName = getColorName;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../constants/index.cjs");const e=require("./color-ops.cjs"),a=require("../constants/color-names.cjs"),f={RGB:1,HSL:2};function N(t){const o=e.toHexColor(t),n=e.toRgbColor(t),l=e.toHslColor(t);let c="",r=Number.POSITIVE_INFINITY,s=-1;const u=a.colorEntries.find(([i])=>o===i);if(u)return u[1];for(const[i,[g,H]]of a.colorEntries.entries()){const C=R(n,l,g);C<r&&(r=C,c=H,s=i)}return c||a.colorEntries[s]?.[1]||"Unknown"}function m(t,o){return(t.r-o.r)**2+(t.g-o.g)**2+(t.b-o.b)**2}function I(t,o){return(t.h-o.h)**2+(t.s-o.s)**2+(t.l-o.l)**2}function R(t,o,n){const l=e.toRgbColor(n),c=e.toHslColor(n),r=m(t,l),s=I(o,c);return r*f.RGB+s*f.HSL}exports.getColorName=N;
|
|
@@ -1,126 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
-
|
|
6
|
-
const tinyLru = require('tiny-lru');
|
|
7
|
-
require('../constants/index.cjs');
|
|
8
|
-
const colorOps = require('./color-ops.cjs');
|
|
9
|
-
const name = require('./name.cjs');
|
|
10
|
-
const colorPalettes = require('../constants/color-palettes.cjs');
|
|
11
|
-
|
|
12
|
-
const MAIN_COLOR_NUMBER = 500;
|
|
13
|
-
const CACHE = tinyLru.lru(100);
|
|
14
|
-
function getColorPalette(color) {
|
|
15
|
-
if (CACHE.has(color)) {
|
|
16
|
-
return CACHE.get(color);
|
|
17
|
-
}
|
|
18
|
-
const { colorMap } = generateMatchedColorPalette(color);
|
|
19
|
-
CACHE.set(color, colorMap);
|
|
20
|
-
return colorMap;
|
|
21
|
-
}
|
|
22
|
-
function generateMatchedColorPalette(inputColor) {
|
|
23
|
-
const basePalette = generateColorPalette(inputColor);
|
|
24
|
-
let mainColorSwatch;
|
|
25
|
-
const matchedColorSwatch = basePalette.swatches.find((swatch) => swatch.hex === inputColor);
|
|
26
|
-
const colorMap = /* @__PURE__ */ new Map();
|
|
27
|
-
for (const swatch of basePalette.swatches) {
|
|
28
|
-
colorMap.set(swatch.number, swatch.hex);
|
|
29
|
-
if (swatch.number === MAIN_COLOR_NUMBER) {
|
|
30
|
-
mainColorSwatch = swatch;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (!mainColorSwatch) {
|
|
34
|
-
throw new Error(`Main color swatch (${MAIN_COLOR_NUMBER}) not found in palette`);
|
|
35
|
-
}
|
|
36
|
-
if (!matchedColorSwatch) {
|
|
37
|
-
throw new Error("Matched color swatch not found in generated palette");
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...basePalette,
|
|
41
|
-
colorMap,
|
|
42
|
-
main: mainColorSwatch,
|
|
43
|
-
matched: matchedColorSwatch
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function generateColorPalette(inputColor) {
|
|
47
|
-
if (!colorOps.isValidColor(inputColor)) {
|
|
48
|
-
throw new Error(`Invalid color format: "${inputColor}". Please provide a valid color value.`);
|
|
49
|
-
}
|
|
50
|
-
const normalizedColorName = normalizeColorName(name.getColorName(inputColor));
|
|
51
|
-
const inputHsl = colorOps.toHslColor(inputColor);
|
|
52
|
-
const nearestPaletteData = findNearestColorPalette(inputColor, colorPalettes.colorPalettes);
|
|
53
|
-
const { nearestLightnessSwatch, swatches: referencePalette } = nearestPaletteData;
|
|
54
|
-
const adjustments = calculateColorAdjustments(inputHsl, nearestLightnessSwatch);
|
|
55
|
-
const adjustedSwatches = referencePalette.map((referenceSwatch) => {
|
|
56
|
-
const isExactMatch = nearestLightnessSwatch.number === referenceSwatch.number;
|
|
57
|
-
if (isExactMatch) {
|
|
58
|
-
return {
|
|
59
|
-
hex: inputColor,
|
|
60
|
-
number: referenceSwatch.number
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
const adjustedHex = applyColorAdjustments(referenceSwatch.hex, adjustments);
|
|
64
|
-
return {
|
|
65
|
-
hex: adjustedHex,
|
|
66
|
-
number: referenceSwatch.number
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
name: normalizedColorName,
|
|
71
|
-
swatches: adjustedSwatches
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function normalizeColorName(colorName) {
|
|
75
|
-
return colorName.toLowerCase().replaceAll(/\s+/g, "-");
|
|
76
|
-
}
|
|
77
|
-
function calculateColorAdjustments(inputHsl, referenceSwatch) {
|
|
78
|
-
const referenceHsl = colorOps.toHslColor(referenceSwatch.hex);
|
|
79
|
-
return {
|
|
80
|
-
hueDelta: inputHsl.h - referenceHsl.h,
|
|
81
|
-
saturationRatio: referenceHsl.s > 0 ? inputHsl.s / referenceHsl.s : 1
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function applyColorAdjustments(referenceHex, adjustments) {
|
|
85
|
-
const {
|
|
86
|
-
h: referenceHue,
|
|
87
|
-
s: referenceSaturation,
|
|
88
|
-
l: referenceLightness
|
|
89
|
-
} = colorOps.toHslColor(referenceHex);
|
|
90
|
-
const adjustedHue = referenceHue + adjustments.hueDelta;
|
|
91
|
-
const adjustedSaturation = referenceSaturation * adjustments.saturationRatio;
|
|
92
|
-
return colorOps.convertHslToHex({
|
|
93
|
-
h: adjustedHue,
|
|
94
|
-
s: adjustedSaturation,
|
|
95
|
-
l: referenceLightness
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function findNearestColorPalette(inputColor, availablePalettes) {
|
|
99
|
-
const palettesWithDistances = availablePalettes.map((palette) => {
|
|
100
|
-
const swatchesWithDistances = palette.swatches.map((swatch) => ({
|
|
101
|
-
...swatch,
|
|
102
|
-
delta: colorOps.getColorDifference(inputColor, swatch.hex)
|
|
103
|
-
}));
|
|
104
|
-
const nearestSwatch = swatchesWithDistances.reduce((closest, current) => current.delta < closest.delta ? current : closest);
|
|
105
|
-
return {
|
|
106
|
-
...palette,
|
|
107
|
-
swatches: swatchesWithDistances,
|
|
108
|
-
nearestSwatch
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
const nearestPalette = palettesWithDistances.reduce((closest, current) => current.nearestSwatch.delta < closest.nearestSwatch.delta ? current : closest);
|
|
112
|
-
const inputLightness = colorOps.toHslColor(inputColor).l;
|
|
113
|
-
const nearestLightnessSwatch = nearestPalette.swatches.reduce((closest, current) => {
|
|
114
|
-
const closestLightness = colorOps.toHslColor(closest.hex).l;
|
|
115
|
-
const currentLightness = colorOps.toHslColor(current.hex).l;
|
|
116
|
-
const closestLightnessDelta = Math.abs(closestLightness - inputLightness);
|
|
117
|
-
const currentLightnessDelta = Math.abs(currentLightness - inputLightness);
|
|
118
|
-
return currentLightnessDelta < closestLightnessDelta ? current : closest;
|
|
119
|
-
});
|
|
120
|
-
return {
|
|
121
|
-
...nearestPalette,
|
|
122
|
-
nearestLightnessSwatch
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
exports.getColorPalette = getColorPalette;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("tiny-lru");require("../constants/index.cjs");const l=require("./color-ops.cjs"),w=require("./name.cjs"),g=require("../constants/color-palettes.cjs"),m=500,d=f.lru(100);function C(e){if(d.has(e))return d.get(e);const{colorMap:t}=x(e);return d.set(e,t),t}function x(e){const t=H(e);let s;const c=t.swatches.find(n=>n.hex===e),o=new Map;for(const n of t.swatches)o.set(n.number,n.hex),n.number===m&&(s=n);if(!s)throw new Error(`Main color swatch (${m}) not found in palette`);if(!c)throw new Error("Matched color swatch not found in generated palette");return{...t,colorMap:o,main:s,matched:c}}function H(e){if(!l.isValidColor(e))throw new Error(`Invalid color format: "${e}". Please provide a valid color value.`);const t=b(w.getColorName(e)),s=l.toHslColor(e),c=L(e,g.colorPalettes),{nearestLightnessSwatch:o,swatches:n}=c,a=M(s,o),r=n.map(h=>o.number===h.number?{hex:e,number:h.number}:{hex:P(h.hex,a),number:h.number});return{name:t,swatches:r}}function b(e){return e.toLowerCase().replaceAll(/\s+/g,"-")}function M(e,t){const s=l.toHslColor(t.hex);return{hueDelta:e.h-s.h,saturationRatio:s.s>0?e.s/s.s:1}}function P(e,t){const{h:s,s:c,l:o}=l.toHslColor(e),n=s+t.hueDelta,a=c*t.saturationRatio;return l.convertHslToHex({h:n,s:a,l:o})}function L(e,t){const c=t.map(a=>{const r=a.swatches.map(i=>({...i,delta:l.getColorDifference(e,i.hex)})),h=r.reduce((i,u)=>u.delta<i.delta?u:i);return{...a,swatches:r,nearestSwatch:h}}).reduce((a,r)=>r.nearestSwatch.delta<a.nearestSwatch.delta?r:a),o=l.toHslColor(e).l,n=c.swatches.reduce((a,r)=>{const h=l.toHslColor(a.hex).l,i=l.toHslColor(r.hex).l,u=Math.abs(h-o);return Math.abs(i-o)<u?r:a});return{...c,nearestLightnessSwatch:n}}exports.getColorPalette=C;
|