zcw-shared 1.3.0 → 1.5.0
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/README.md +223 -50
- package/dist/constants/colorPatterns.d.ts +2 -0
- package/dist/constants/colorPatterns.js +9 -0
- package/dist/constants/colorPatterns.js.map +1 -0
- package/dist/constants/namedColors.d.ts +2 -0
- package/dist/constants/namedColors.js +17 -0
- package/dist/constants/namedColors.js.map +1 -0
- package/dist/constants/softwareConfigs.d.ts +15 -0
- package/dist/constants/softwareConfigs.js +157 -0
- package/dist/constants/softwareConfigs.js.map +1 -0
- package/dist/functions/ag-grid/generateLicense.d.ts +1 -2
- package/dist/functions/ag-grid/generateLicense.js +2 -2
- package/dist/functions/ag-grid/generateLicense.js.map +1 -1
- package/dist/functions/altool/createAltoolClient.js +4 -10
- package/dist/functions/altool/createAltoolClient.js.map +1 -1
- package/dist/functions/altool/getAltoolAuth.d.ts +2 -0
- package/dist/functions/altool/getAltoolAuth.js +8 -0
- package/dist/functions/altool/getAltoolAuth.js.map +1 -0
- package/dist/functions/altool/getAppInfo.js +1 -54
- package/dist/functions/altool/getAppInfo.js.map +1 -1
- package/dist/functions/altool/parseAppInfoOutput.d.ts +2 -0
- package/dist/functions/altool/parseAppInfoOutput.js +55 -0
- package/dist/functions/altool/parseAppInfoOutput.js.map +1 -0
- package/dist/functions/altool/parseValidationOutput.d.ts +6 -0
- package/dist/functions/altool/parseValidationOutput.js +21 -0
- package/dist/functions/altool/parseValidationOutput.js.map +1 -0
- package/dist/functions/altool/validateApp.js +2 -21
- package/dist/functions/altool/validateApp.js.map +1 -1
- package/dist/functions/color/convertColor.d.ts +6 -0
- package/dist/functions/color/convertColor.js +308 -0
- package/dist/functions/color/convertColor.js.map +1 -0
- package/dist/functions/color/deduplicateColors.d.ts +4 -0
- package/dist/functions/color/deduplicateColors.js +55 -0
- package/dist/functions/color/deduplicateColors.js.map +1 -0
- package/dist/functions/color/detectColorFormat.d.ts +2 -0
- package/dist/functions/color/detectColorFormat.js +112 -0
- package/dist/functions/color/detectColorFormat.js.map +1 -0
- package/dist/functions/color/extractColors.d.ts +4 -0
- package/dist/functions/color/extractColors.js +98 -0
- package/dist/functions/color/extractColors.js.map +1 -0
- package/dist/functions/color-converter/convertColor.js +4 -230
- package/dist/functions/color-converter/convertColor.js.map +1 -1
- package/dist/functions/color-converter/createColorReference.d.ts +2 -0
- package/dist/functions/color-converter/createColorReference.js +12 -0
- package/dist/functions/color-converter/createColorReference.js.map +1 -0
- package/dist/functions/color-converter/extractColors.d.ts +2 -15
- package/dist/functions/color-converter/extractColors.js +9 -104
- package/dist/functions/color-converter/extractColors.js.map +1 -1
- package/dist/functions/color-converter/extractColorsFromLine.d.ts +2 -0
- package/dist/functions/color-converter/extractColorsFromLine.js +18 -0
- package/dist/functions/color-converter/extractColorsFromLine.js.map +1 -0
- package/dist/functions/color-converter/extractColorsGeneric.d.ts +2 -0
- package/dist/functions/color-converter/extractColorsGeneric.js +12 -0
- package/dist/functions/color-converter/extractColorsGeneric.js.map +1 -0
- package/dist/functions/color-converter/extractCssVariableReferences.d.ts +2 -0
- package/dist/functions/color-converter/extractCssVariableReferences.js +15 -0
- package/dist/functions/color-converter/extractCssVariableReferences.js.map +1 -0
- package/dist/functions/color-converter/extractThirdPartyVariableReferences.d.ts +2 -0
- package/dist/functions/color-converter/extractThirdPartyVariableReferences.js +15 -0
- package/dist/functions/color-converter/extractThirdPartyVariableReferences.js.map +1 -0
- package/dist/functions/color-converter/formatColorOutput.d.ts +5 -0
- package/dist/functions/color-converter/formatColorOutput.js +48 -0
- package/dist/functions/color-converter/formatColorOutput.js.map +1 -0
- package/dist/functions/color-converter/hslToRgbInternal.d.ts +2 -0
- package/dist/functions/color-converter/hslToRgbInternal.js +24 -0
- package/dist/functions/color-converter/hslToRgbInternal.js.map +1 -0
- package/dist/functions/color-converter/isValidColorValue.d.ts +1 -0
- package/dist/functions/color-converter/isValidColorValue.js +4 -0
- package/dist/functions/color-converter/isValidColorValue.js.map +1 -0
- package/dist/functions/color-converter/isValidHslColor.d.ts +2 -0
- package/dist/functions/color-converter/isValidHslColor.js +14 -0
- package/dist/functions/color-converter/isValidHslColor.js.map +1 -0
- package/dist/functions/color-converter/isValidRgbColor.d.ts +2 -0
- package/dist/functions/color-converter/isValidRgbColor.js +14 -0
- package/dist/functions/color-converter/isValidRgbColor.js.map +1 -0
- package/dist/functions/color-converter/normalizeColorInput.d.ts +6 -0
- package/dist/functions/color-converter/normalizeColorInput.js +94 -0
- package/dist/functions/color-converter/normalizeColorInput.js.map +1 -0
- package/dist/functions/color-converter/parseColorString.d.ts +0 -3
- package/dist/functions/color-converter/parseColorString.js +0 -27
- package/dist/functions/color-converter/parseColorString.js.map +1 -1
- package/dist/functions/color-converter/parseCssVariables.d.ts +2 -0
- package/dist/functions/color-converter/parseCssVariables.js +19 -0
- package/dist/functions/color-converter/parseCssVariables.js.map +1 -0
- package/dist/functions/color-converter/parseHexColor.d.ts +6 -0
- package/dist/functions/color-converter/parseHexColor.js +42 -0
- package/dist/functions/color-converter/parseHexColor.js.map +1 -0
- package/dist/functions/color-converter/rgbToHslInternal.d.ts +2 -0
- package/dist/functions/color-converter/rgbToHslInternal.js +31 -0
- package/dist/functions/color-converter/rgbToHslInternal.js.map +1 -0
- package/dist/functions/css/extractCssVariables.d.ts +12 -0
- package/dist/functions/css/extractCssVariables.js +53 -0
- package/dist/functions/css/extractCssVariables.js.map +1 -0
- package/dist/functions/dom/detectOverflow.js.map +1 -1
- package/dist/functions/dom/getElementRect.js.map +1 -1
- package/dist/functions/dom/getRelativePosition.js.map +1 -1
- package/dist/functions/dom/getViewportRect.js.map +1 -1
- package/dist/functions/dom/getViewportSize.js.map +1 -1
- package/dist/functions/image/generateMacIcons.js.map +1 -1
- package/dist/functions/image/generateMacTrayIcon.js.map +1 -1
- package/dist/functions/image/generatePaddedImage.js.map +1 -1
- package/dist/functions/image/generatePwaIcons.js.map +1 -1
- package/dist/functions/image/generateRoundedImage.js.map +1 -1
- package/dist/functions/ipc/dispatchIpcRequest.js +1 -1
- package/dist/functions/ipc/dispatchIpcRequest.js.map +1 -1
- package/dist/functions/software/buildPathExecutables.js +11 -1
- package/dist/functions/software/buildPathExecutables.js.map +1 -1
- package/dist/functions/software/buildSoftwarePaths.d.ts +1 -1
- package/dist/functions/software/createConfigGenerator.d.ts +1 -1
- package/dist/functions/software/detectPlatform.d.ts +1 -1
- package/dist/functions/software/detectPlatform.js +6 -1
- package/dist/functions/software/detectPlatform.js.map +1 -1
- package/dist/functions/software/find.js +1 -1
- package/dist/functions/software/find.js.map +1 -1
- package/dist/functions/software/findSoftware.d.ts +1 -2
- package/dist/functions/software/findSoftware.js +33 -19
- package/dist/functions/software/findSoftware.js.map +1 -1
- package/dist/functions/software/findSoftwareWithGenerator.d.ts +1 -1
- package/dist/functions/software/getConfigGenerator.d.ts +1 -1
- package/dist/functions/software/getEnvironmentSoftwarePath.js +5 -1
- package/dist/functions/software/getEnvironmentSoftwarePath.js.map +1 -1
- package/dist/functions/software/parseEnvironmentPaths.js +6 -2
- package/dist/functions/software/parseEnvironmentPaths.js.map +1 -1
- package/dist/functions/string/base64.d.ts +2 -0
- package/dist/functions/string/base64.js +6 -0
- package/dist/functions/string/base64.js.map +1 -0
- package/dist/functions/string/caseConverter.d.ts +20 -0
- package/dist/functions/string/caseConverter.js +101 -0
- package/dist/functions/string/caseConverter.js.map +1 -0
- package/dist/functions/string/desensitize.d.ts +13 -0
- package/dist/functions/string/desensitize.js +107 -0
- package/dist/functions/string/desensitize.js.map +1 -0
- package/dist/functions/string/htmlEscape.d.ts +17 -0
- package/dist/functions/string/htmlEscape.js +68 -0
- package/dist/functions/string/htmlEscape.js.map +1 -0
- package/dist/functions/string/pad.d.ts +14 -0
- package/dist/functions/string/pad.js +53 -0
- package/dist/functions/string/pad.js.map +1 -0
- package/dist/functions/string/similarity.js +1 -26
- package/dist/functions/string/similarity.js.map +1 -1
- package/dist/functions/tencent-cloud/getSecret.d.ts +1 -2
- package/dist/functions/tencent-cloud/getSecret.js +2 -3
- package/dist/functions/tencent-cloud/getSecret.js.map +1 -1
- package/dist/functions/uniapp/app-plus/androidProjectStrategy.d.ts +6 -20
- package/dist/functions/uniapp/app-plus/androidProjectStrategy.js +43 -48
- package/dist/functions/uniapp/app-plus/androidProjectStrategy.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildAndroidProject.js +2 -2
- package/dist/functions/uniapp/app-plus/buildAndroidProject.js.map +1 -1
- package/dist/functions/uniapp/app-plus/configureAndroidProject.js +2 -2
- package/dist/functions/uniapp/app-plus/configureAndroidProject.js.map +1 -1
- package/dist/functions/uniapp/waitForPages.d.ts +1 -1
- package/dist/functions/uniapp/waitForPages.js +3 -2
- package/dist/functions/uniapp/waitForPages.js.map +1 -1
- package/dist/functions/utils/flow.d.ts +1 -1
- package/dist/functions/utils/flow.js +5 -1
- package/dist/functions/utils/flow.js.map +1 -1
- package/dist/functions/vue/checkVueType.d.ts +8 -0
- package/dist/functions/vue/checkVueType.js +29 -0
- package/dist/functions/vue/checkVueType.js.map +1 -0
- package/dist/functions/vue/deduplicateColors.d.ts +2 -0
- package/dist/functions/vue/deduplicateColors.js +13 -0
- package/dist/functions/vue/deduplicateColors.js.map +1 -0
- package/dist/functions/vue/extractColorsFromVueFile.d.ts +3 -0
- package/dist/functions/vue/extractColorsFromVueFile.js +27 -0
- package/dist/functions/vue/extractColorsFromVueFile.js.map +1 -0
- package/dist/functions/vue/extractColorsFromVueSection.d.ts +3 -0
- package/dist/functions/vue/extractColorsFromVueSection.js +53 -0
- package/dist/functions/vue/extractColorsFromVueSection.js.map +1 -0
- package/dist/functions/vue/filterSections.d.ts +2 -0
- package/dist/functions/vue/filterSections.js +11 -0
- package/dist/functions/vue/filterSections.js.map +1 -0
- package/dist/functions/vue/parseVueFile.d.ts +2 -0
- package/dist/functions/vue/parseVueFile.js +53 -0
- package/dist/functions/vue/parseVueFile.js.map +1 -0
- package/dist/functions/vue/processVueFile.d.ts +3 -0
- package/dist/functions/vue/processVueFile.js +26 -0
- package/dist/functions/vue/processVueFile.js.map +1 -0
- package/dist/functions/vue/saveVueSection.d.ts +2 -0
- package/dist/functions/vue/saveVueSection.js +11 -0
- package/dist/functions/vue/saveVueSection.js.map +1 -0
- package/dist/hooks/useAltool.d.ts +68 -0
- package/dist/hooks/useAltool.js +350 -0
- package/dist/hooks/useAltool.js.map +1 -0
- package/package.json +26 -44
- package/types/color.d.ts +30 -3
- package/types/geometry.d.ts +3 -1
- package/types/software.d.ts +27 -0
- package/types/vue.d.ts +30 -0
|
@@ -1,111 +1,16 @@
|
|
|
1
|
+
import { extractColorsFromLine } from './extractColorsFromLine';
|
|
2
|
+
import { parseCssVariables } from './parseCssVariables';
|
|
1
3
|
export function extractColors(code, filePath, dependencies, options = {}) {
|
|
2
|
-
const
|
|
4
|
+
const cssVariables = parseCssVariables(code, filePath, dependencies);
|
|
5
|
+
const thirdPartyVariables = options.thirdPartyVariables || {};
|
|
3
6
|
const colors = [];
|
|
4
7
|
const lines = code.split('\n');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
colors.push(...extractColorsFromLine(line, filePath, lineNumber, dependencies, { cssVariables: allCssVariables, thirdPartyVariables }));
|
|
8
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9
|
+
const line = lines[i];
|
|
10
|
+
const lineNumber = i + 1;
|
|
11
|
+
const lineColors = extractColorsFromLine(line, filePath, lineNumber, dependencies, { cssVariables, thirdPartyVariables });
|
|
12
|
+
colors.push(...lineColors);
|
|
11
13
|
}
|
|
12
14
|
return colors;
|
|
13
15
|
}
|
|
14
|
-
export function extractColorsFromLine(line, filePath, lineNumber, dependencies, options = {}) {
|
|
15
|
-
const { cssVariables = {}, thirdPartyVariables = {} } = options;
|
|
16
|
-
const colors = [];
|
|
17
|
-
const patterns = dependencies.getColorPatterns();
|
|
18
|
-
colors.push(...extractHexColors(line, filePath, lineNumber, patterns, dependencies));
|
|
19
|
-
colors.push(...extractRgbColors(line, filePath, lineNumber, patterns, dependencies));
|
|
20
|
-
colors.push(...extractRgbaColors(line, filePath, lineNumber, patterns, dependencies));
|
|
21
|
-
colors.push(...extractHslColors(line, filePath, lineNumber, patterns, dependencies));
|
|
22
|
-
colors.push(...extractHslaColors(line, filePath, lineNumber, patterns, dependencies));
|
|
23
|
-
colors.push(...extractNamedColors(line, filePath, lineNumber, patterns, dependencies));
|
|
24
|
-
colors.push(...extractCssVariableReferences(line, filePath, lineNumber, patterns, cssVariables));
|
|
25
|
-
colors.push(...extractThirdPartyVariableReferences(line, filePath, lineNumber, patterns, thirdPartyVariables));
|
|
26
|
-
return colors;
|
|
27
|
-
}
|
|
28
|
-
function extractHexColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
29
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.hex, 'hex', dependencies);
|
|
30
|
-
}
|
|
31
|
-
function extractRgbColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
32
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.rgb, 'rgb', dependencies);
|
|
33
|
-
}
|
|
34
|
-
function extractRgbaColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
35
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.rgba, 'rgba', dependencies);
|
|
36
|
-
}
|
|
37
|
-
function extractHslColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
38
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.hsl, 'hsl', dependencies);
|
|
39
|
-
}
|
|
40
|
-
function extractHslaColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
41
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.hsla, 'hsla', dependencies);
|
|
42
|
-
}
|
|
43
|
-
function extractNamedColors(line, filePath, lineNumber, patterns, dependencies) {
|
|
44
|
-
return extractColorsGeneric(line, filePath, lineNumber, patterns.namedColors, 'named', dependencies);
|
|
45
|
-
}
|
|
46
|
-
function extractCssVariableReferences(line, filePath, lineNumber, patterns, cssVariables) {
|
|
47
|
-
const colors = [];
|
|
48
|
-
const cssVarPattern = /var\(\s*--([\w-]+)\s*\)/g;
|
|
49
|
-
const matches = line.matchAll(cssVarPattern);
|
|
50
|
-
for (const match of matches) {
|
|
51
|
-
const variableName = match[1];
|
|
52
|
-
const variableValue = cssVariables[variableName];
|
|
53
|
-
if (variableValue) {
|
|
54
|
-
colors.push(createColorReference(variableValue, 'css-variable', filePath, lineNumber, line, variableValue, true, variableName));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return colors;
|
|
58
|
-
}
|
|
59
|
-
function extractThirdPartyVariableReferences(line, filePath, lineNumber, patterns, thirdPartyVariables) {
|
|
60
|
-
const colors = [];
|
|
61
|
-
const thirdPartyPattern = /\$([\w-]+)/g;
|
|
62
|
-
const matches = line.matchAll(thirdPartyPattern);
|
|
63
|
-
for (const match of matches) {
|
|
64
|
-
const variableName = match[1];
|
|
65
|
-
const variableValue = thirdPartyVariables[variableName];
|
|
66
|
-
if (variableValue) {
|
|
67
|
-
colors.push(createColorReference(variableValue, 'third-party-variable', filePath, lineNumber, line, variableName, true, variableName));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return colors;
|
|
71
|
-
}
|
|
72
|
-
function extractColorsGeneric(line, filePath, lineNumber, pattern, format, dependencies) {
|
|
73
|
-
const colors = [];
|
|
74
|
-
const matches = line.matchAll(new RegExp(pattern.source, 'g'));
|
|
75
|
-
for (const match of matches) {
|
|
76
|
-
const originalColor = match[0];
|
|
77
|
-
const standardizedColor = dependencies.standardizeColor(originalColor);
|
|
78
|
-
colors.push(createColorReference(standardizedColor, format, filePath, lineNumber, line, originalColor));
|
|
79
|
-
}
|
|
80
|
-
return colors;
|
|
81
|
-
}
|
|
82
|
-
function parseCssVariables(code, filePath, dependencies) {
|
|
83
|
-
const variables = {};
|
|
84
|
-
const lines = code.split('\n');
|
|
85
|
-
const cssVarDefPattern = /--([\w-]+)\s*:\s*([^;]+);/g;
|
|
86
|
-
for (const line of lines) {
|
|
87
|
-
const matches = line.matchAll(cssVarDefPattern);
|
|
88
|
-
for (const match of matches) {
|
|
89
|
-
const [, variableName, variableValue] = match;
|
|
90
|
-
const trimmedValue = variableValue.trim();
|
|
91
|
-
const validation = dependencies.isColorValue(trimmedValue);
|
|
92
|
-
if (validation.isValid) {
|
|
93
|
-
const standardizedValue = dependencies.standardizeColor(trimmedValue);
|
|
94
|
-
variables[variableName] = standardizedValue;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return variables;
|
|
99
|
-
}
|
|
100
|
-
function createColorReference(value, format, file, line, context, originalValue, isVariableReference = false, variableName) {
|
|
101
|
-
return {
|
|
102
|
-
originalValue,
|
|
103
|
-
format,
|
|
104
|
-
file,
|
|
105
|
-
line,
|
|
106
|
-
context: context.trim(),
|
|
107
|
-
isVariableReference,
|
|
108
|
-
variableName
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
16
|
//# sourceMappingURL=extractColors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractColors.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractColors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extractColors.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractColors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAmCvD,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,QAAgB,EAChB,YAAwC,EACxC,UAAkC,EAAE;IAGpC,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;IAGpE,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,EAAE,CAAA;IAE7D,MAAM,MAAM,GAAqB,EAAE,CAAA;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,MAAM,UAAU,GAAG,CAAC,GAAG,CAAC,CAAA;QAGxB,MAAM,UAAU,GAAG,qBAAqB,CACtC,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,EAAE,YAAY,EAAE,mBAAmB,EAAE,CACtC,CAAA;QAED,MAAM,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAA;IAC5B,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { ColorReference, ColorExtractorDependencies, ColorExtractionOptions } from '../../../types/color';
|
|
2
|
+
export declare function extractColorsFromLine(line: string, filePath: string, lineNumber: number, dependencies: ColorExtractorDependencies, options?: ColorExtractionOptions): ColorReference[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { extractColorsGeneric } from './extractColorsGeneric';
|
|
2
|
+
import { extractCssVariableReferences } from './extractCssVariableReferences';
|
|
3
|
+
import { extractThirdPartyVariableReferences } from './extractThirdPartyVariableReferences';
|
|
4
|
+
export function extractColorsFromLine(line, filePath, lineNumber, dependencies, options = {}) {
|
|
5
|
+
const { cssVariables = {}, thirdPartyVariables = {} } = options;
|
|
6
|
+
const colors = [];
|
|
7
|
+
const patterns = dependencies.getColorPatterns();
|
|
8
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.hex, 'hex', dependencies));
|
|
9
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.rgb, 'rgb', dependencies));
|
|
10
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.rgba, 'rgba', dependencies));
|
|
11
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.hsl, 'hsl', dependencies));
|
|
12
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.hsla, 'hsla', dependencies));
|
|
13
|
+
colors.push(...extractColorsGeneric(line, filePath, lineNumber, patterns.namedColors, 'named', dependencies));
|
|
14
|
+
colors.push(...extractCssVariableReferences(line, filePath, lineNumber, patterns, cssVariables));
|
|
15
|
+
colors.push(...extractThirdPartyVariableReferences(line, filePath, lineNumber, patterns, thirdPartyVariables));
|
|
16
|
+
return colors;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=extractColorsFromLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractColorsFromLine.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractColorsFromLine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAC7E,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAA;AAqC3F,MAAM,UAAU,qBAAqB,CACnC,IAAY,EACZ,QAAgB,EAChB,UAAkB,EAClB,YAAwC,EACxC,UAAkC,EAAE;IAEpC,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,mBAAmB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;IAC/D,MAAM,MAAM,GAAqB,EAAE,CAAA;IACnC,MAAM,QAAQ,GAAG,YAAY,CAAC,gBAAgB,EAAE,CAAA;IAGhD,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;IACnG,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;IACnG,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;IACrG,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;IACnG,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;IACrG,MAAM,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAA;IAC7G,MAAM,CAAC,IAAI,CAAC,GAAG,4BAA4B,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAA;IAChG,MAAM,CAAC,IAAI,CAAC,GAAG,mCAAmC,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAA;IAE9G,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { ColorReference, ColorFormat, ColorExtractorDependencies } from '../../../types/color';
|
|
2
|
+
export declare function extractColorsGeneric(line: string, filePath: string, lineNumber: number, pattern: RegExp, format: ColorFormat, dependencies: ColorExtractorDependencies): ColorReference[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createColorReference } from './createColorReference';
|
|
2
|
+
export function extractColorsGeneric(line, filePath, lineNumber, pattern, format, dependencies) {
|
|
3
|
+
const colors = [];
|
|
4
|
+
const matches = line.matchAll(new RegExp(pattern.source, 'g'));
|
|
5
|
+
for (const match of matches) {
|
|
6
|
+
const originalColor = match[0];
|
|
7
|
+
const standardizedColor = dependencies.standardizeColor(originalColor);
|
|
8
|
+
colors.push(createColorReference(standardizedColor, format, filePath, lineNumber, line, originalColor));
|
|
9
|
+
}
|
|
10
|
+
return colors;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=extractColorsGeneric.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractColorsGeneric.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractColorsGeneric.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAoC7D,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,QAAgB,EAChB,UAAkB,EAClB,OAAe,EACf,MAAmB,EACnB,YAAwC;IAExC,MAAM,MAAM,GAAqB,EAAE,CAAA;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IAE9D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAE9B,MAAM,iBAAiB,GAAG,YAAY,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAA;QAEtE,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAC9B,iBAAiB,EACjB,MAAM,EACN,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,aAAa,CACd,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createColorReference } from './createColorReference';
|
|
2
|
+
export function extractCssVariableReferences(line, filePath, lineNumber, patterns, cssVariables) {
|
|
3
|
+
const colors = [];
|
|
4
|
+
const cssVarPattern = /var\(\s*--([\w-]+)\s*\)/g;
|
|
5
|
+
const matches = line.matchAll(cssVarPattern);
|
|
6
|
+
for (const match of matches) {
|
|
7
|
+
const variableName = match[1];
|
|
8
|
+
const variableValue = cssVariables[variableName];
|
|
9
|
+
if (variableValue) {
|
|
10
|
+
colors.push(createColorReference(variableValue, 'css-variable', filePath, lineNumber, line, variableValue, true, variableName));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return colors;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=extractCssVariableReferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractCssVariableReferences.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractCssVariableReferences.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAmC7D,MAAM,UAAU,4BAA4B,CAC1C,IAAY,EACZ,QAAgB,EAChB,UAAkB,EAClB,QAAuB,EACvB,YAAoC;IAEpC,MAAM,MAAM,GAAqB,EAAE,CAAA;IAGnC,MAAM,aAAa,GAAG,0BAA0B,CAAA;IAChD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAE5C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAC7B,MAAM,aAAa,GAAG,YAAY,CAAC,YAAY,CAAC,CAAA;QAEhD,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAC9B,aAAa,EACb,cAAc,EACd,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,aAAa,EACb,IAAI,EACJ,YAAY,CACb,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createColorReference } from './createColorReference';
|
|
2
|
+
export function extractThirdPartyVariableReferences(line, filePath, lineNumber, patterns, thirdPartyVariables) {
|
|
3
|
+
const colors = [];
|
|
4
|
+
const thirdPartyPattern = /\$([\w-]+)/g;
|
|
5
|
+
const matches = line.matchAll(thirdPartyPattern);
|
|
6
|
+
for (const match of matches) {
|
|
7
|
+
const variableName = match[1];
|
|
8
|
+
const variableValue = thirdPartyVariables[variableName];
|
|
9
|
+
if (variableValue) {
|
|
10
|
+
colors.push(createColorReference(variableValue, 'third-party-variable', filePath, lineNumber, line, variableName, true, variableName));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return colors;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=extractThirdPartyVariableReferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractThirdPartyVariableReferences.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractThirdPartyVariableReferences.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAmC7D,MAAM,UAAU,mCAAmC,CACjD,IAAY,EACZ,QAAgB,EAChB,UAAkB,EAClB,QAAuB,EACvB,mBAA2C;IAE3C,MAAM,MAAM,GAAqB,EAAE,CAAA;IAGnC,MAAM,iBAAiB,GAAG,aAAa,CAAA;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAA;IAEhD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAC7B,MAAM,aAAa,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAA;QAEvD,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAC9B,aAAa,EACb,sBAAsB,EACtB,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,YAAY,CACb,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getNamedColorMap } from './getNamedColorMap';
|
|
2
|
+
import { rgbToHslInternal } from './rgbToHslInternal';
|
|
3
|
+
export function formatColorOutput(rgb, alpha, targetFormat, options) {
|
|
4
|
+
const { includeAlpha = false, precision = 0 } = options;
|
|
5
|
+
const r = Math.max(0, Math.min(255, Math.round(rgb.r)));
|
|
6
|
+
const g = Math.max(0, Math.min(255, Math.round(rgb.g)));
|
|
7
|
+
const b = Math.max(0, Math.min(255, Math.round(rgb.b)));
|
|
8
|
+
const a = Math.max(0, Math.min(1, alpha));
|
|
9
|
+
switch (targetFormat) {
|
|
10
|
+
case 'hex': {
|
|
11
|
+
const toHex = (value) => {
|
|
12
|
+
const hex = value.toString(16);
|
|
13
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
14
|
+
};
|
|
15
|
+
let result = `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
16
|
+
if (includeAlpha || a < 1) {
|
|
17
|
+
const alphaHex = Math.round(a * 255);
|
|
18
|
+
result += toHex(alphaHex);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
case 'rgb':
|
|
23
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
24
|
+
case 'rgba':
|
|
25
|
+
return `rgba(${r}, ${g}, ${b}, ${a.toFixed(precision)})`;
|
|
26
|
+
case 'hsl': {
|
|
27
|
+
const hsl = rgbToHslInternal({ r, g, b });
|
|
28
|
+
return `hsl(${hsl.h}, ${hsl.s}%, ${hsl.l}%)`;
|
|
29
|
+
}
|
|
30
|
+
case 'hsla': {
|
|
31
|
+
const hsl = rgbToHslInternal({ r, g, b });
|
|
32
|
+
return `hsla(${hsl.h}, ${hsl.s}%, ${hsl.l}%, ${a.toFixed(precision)})`;
|
|
33
|
+
}
|
|
34
|
+
case 'named': {
|
|
35
|
+
const namedColorMap = getNamedColorMap();
|
|
36
|
+
const targetHex = `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
|
|
37
|
+
for (const [name, hex] of Object.entries(namedColorMap)) {
|
|
38
|
+
if (hex.toLowerCase() === targetHex.toLowerCase()) {
|
|
39
|
+
return name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return targetHex;
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=formatColorOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatColorOutput.js","sourceRoot":"","sources":["../../../src/functions/color-converter/formatColorOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAmCrD,MAAM,UAAU,iBAAiB,CAC/B,GAAa,EACb,KAAa,EACb,YAAyB,EACzB,OAAuD;IAEvD,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,SAAS,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;IAGvD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACvD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACvD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAA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Math.min(100, hsl.l)) / 100;
|
|
8
|
+
if (s === 0) {
|
|
9
|
+
const gray = Math.round(l * 255);
|
|
10
|
+
return { r: gray, g: gray, b: gray };
|
|
11
|
+
}
|
|
12
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
13
|
+
const p = 2 * l - q;
|
|
14
|
+
const hNormalized = h / 360;
|
|
15
|
+
const r = hueToRgb(p, q, hNormalized + 1 / 3);
|
|
16
|
+
const g = hueToRgb(p, q, hNormalized);
|
|
17
|
+
const b = hueToRgb(p, q, hNormalized - 1 / 3);
|
|
18
|
+
return {
|
|
19
|
+
r: Math.round(r * 255),
|
|
20
|
+
g: Math.round(g * 255),
|
|
21
|
+
b: Math.round(b * 255)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=hslToRgbInternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hslToRgbInternal.js","sourceRoot":"","sources":["../../../src/functions/color-converter/hslToRgbInternal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AA8BrC,MAAM,UAAU,gBAAgB,CAAC,GAAa;IAC5C,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;IACnB,IAAI,CAAC,GAAG,CAAC;QAAE,CAAC,IAAI,GAAG,CAAA;IACnB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IACjD,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IAEjD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAA;QAChC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAA;IACtC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEnB,MAAM,WAAW,GAAG,CAAC,GAAG,GAAG,CAAA;IAC3B,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,CAAC,GAAC,CAAC,CAAC,CAAA;IAC3C,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,CAAA;IACrC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,CAAC,GAAC,CAAC,CAAC,CAAA;IAE3C,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;QACtB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;QACtB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;KACvB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidColorValue(value: any): value is number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidColorValue.js","sourceRoot":"","sources":["../../../src/functions/color-converter/isValidColorValue.ts"],"names":[],"mappings":"AA2BA,MAAM,UAAU,iBAAiB,CAAC,KAAU;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;AACtE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isValidColorValue } from './isValidColorValue';
|
|
2
|
+
export function isValidHslColor(hsl, strict = true) {
|
|
3
|
+
if (!hsl || typeof hsl !== 'object')
|
|
4
|
+
return false;
|
|
5
|
+
const { h, s, l } = hsl;
|
|
6
|
+
if (!isValidColorValue(h) || !isValidColorValue(s) || !isValidColorValue(l)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (strict) {
|
|
10
|
+
return h >= 0 && h <= 360 && s >= 0 && s <= 100 && l >= 0 && l <= 100;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=isValidHslColor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidHslColor.js","sourceRoot":"","sources":["../../../src/functions/color-converter/isValidHslColor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAkCvD,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,SAAkB,IAAI;IAC9D,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAEjD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,GAAG,CAAA;IAEvB,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAA;IACvE,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isValidColorValue } from './isValidColorValue';
|
|
2
|
+
export function isValidRgbColor(rgb, strict = true) {
|
|
3
|
+
if (!rgb || typeof rgb !== 'object')
|
|
4
|
+
return false;
|
|
5
|
+
const { r, g, b } = rgb;
|
|
6
|
+
if (!isValidColorValue(r) || !isValidColorValue(g) || !isValidColorValue(b)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (strict) {
|
|
10
|
+
return r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=isValidRgbColor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidRgbColor.js","sourceRoot":"","sources":["../../../src/functions/color-converter/isValidRgbColor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAiCvD,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,SAAkB,IAAI;IAC9D,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAEjD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,GAAG,CAAA;IAEvB,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAA;IACvE,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { parseColorString } from './parseColorString';
|
|
2
|
+
import { isValidRgbColor } from './isValidRgbColor';
|
|
3
|
+
import { isValidHslColor } from './isValidHslColor';
|
|
4
|
+
import { getNamedColorMap } from './getNamedColorMap';
|
|
5
|
+
import { detectColorFormat } from './detectColorFormat';
|
|
6
|
+
import { parseHexColor } from './parseHexColor';
|
|
7
|
+
import { hslToRgbInternal } from './hslToRgbInternal';
|
|
8
|
+
export function normalizeColorInput(input) {
|
|
9
|
+
if (Array.isArray(input)) {
|
|
10
|
+
if (input.length >= 3) {
|
|
11
|
+
const [r, g, b, a = 1] = input;
|
|
12
|
+
if (typeof r === 'number' && typeof g === 'number' && typeof b === 'number') {
|
|
13
|
+
const rgb = { r: Math.round(r), g: Math.round(g), b: Math.round(b) };
|
|
14
|
+
if (isValidRgbColor(rgb)) {
|
|
15
|
+
return { rgb, alpha: typeof a === 'number' ? a : 1, originalFormat: 'rgb' };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (typeof input === 'object' && input !== null) {
|
|
22
|
+
if ('r' in input && 'g' in input && 'b' in input) {
|
|
23
|
+
const rgb = input;
|
|
24
|
+
if (isValidRgbColor(rgb)) {
|
|
25
|
+
const alpha = 'a' in input ? input.a : 1;
|
|
26
|
+
return { rgb, alpha, originalFormat: 'a' in input ? 'rgba' : 'rgb' };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if ('h' in input && 's' in input && 'l' in input) {
|
|
30
|
+
const hsl = input;
|
|
31
|
+
if (isValidHslColor(hsl)) {
|
|
32
|
+
const rgb = hslToRgbInternal(hsl);
|
|
33
|
+
if (rgb) {
|
|
34
|
+
const alpha = 'a' in input ? input.a : 1;
|
|
35
|
+
return { rgb, alpha, originalFormat: 'a' in input ? 'hsla' : 'hsl' };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (typeof input === 'string') {
|
|
42
|
+
const trimmed = input.trim();
|
|
43
|
+
const format = detectColorFormat(trimmed);
|
|
44
|
+
if (!format) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
switch (format) {
|
|
48
|
+
case 'hex':
|
|
49
|
+
return parseHexColor(trimmed);
|
|
50
|
+
case 'rgb':
|
|
51
|
+
case 'rgba': {
|
|
52
|
+
const parseResult = parseColorString(trimmed);
|
|
53
|
+
if (parseResult.isValid && (parseResult.type === 'rgb' || parseResult.type === 'rgba')) {
|
|
54
|
+
const value = parseResult.value;
|
|
55
|
+
return {
|
|
56
|
+
rgb: { r: value.r, g: value.g, b: value.b },
|
|
57
|
+
alpha: value.a ?? 1,
|
|
58
|
+
originalFormat: parseResult.type
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'hsl':
|
|
64
|
+
case 'hsla': {
|
|
65
|
+
const parseResult = parseColorString(trimmed);
|
|
66
|
+
if (parseResult.isValid && (parseResult.type === 'hsl' || parseResult.type === 'hsla')) {
|
|
67
|
+
const value = parseResult.value;
|
|
68
|
+
const rgb = hslToRgbInternal(value);
|
|
69
|
+
if (rgb) {
|
|
70
|
+
return {
|
|
71
|
+
rgb,
|
|
72
|
+
alpha: value.a ?? 1,
|
|
73
|
+
originalFormat: parseResult.type
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'named': {
|
|
80
|
+
const namedColorMap = getNamedColorMap();
|
|
81
|
+
const hexValue = namedColorMap[trimmed.toLowerCase()];
|
|
82
|
+
if (hexValue) {
|
|
83
|
+
const result = parseHexColor(hexValue);
|
|
84
|
+
if (result) {
|
|
85
|
+
return { ...result, originalFormat: 'named' };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=normalizeColorInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeColorInput.js","sourceRoot":"","sources":["../../../src/functions/color-converter/normalizeColorInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AA8BrD,MAAM,UAAU,mBAAmB,CACjC,KAA8C;IAO9C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;YAC9B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC5E,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;gBACpE,IAAI,eAAe,C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AK,MAAM,CAAC,EAAE,CAAC;oBACvF,MAAM,KAAK,GAAG,WAAW,CAAC,KAAkC,CAAA;oBAC5D,MAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;oBACnC,IAAI,GAAG,EAAE,CAAC;wBACR,OAAO;4BACL,GAAG;4BACH,KAAK,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC;4BACnB,cAAc,EAAE,WAAW,CAAC,IAAI;yBACjC,CAAA;oBACH,CAAC;gBACH,CAAC;gBACD,MAAK;YACP,CAAC;YAED,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;gBACxC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;gBACrD,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;oBACtC,IAAI,MAAM,EAAE,CAAC;wBACX,OAAO,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,CAAA;oBAC/C,CAAC;gBACH,CAAC;gBACD,MAAK;YACP,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -10,6 +10,3 @@ export declare function parseColorString(colorString: string, options?: {
|
|
|
10
10
|
}) | null;
|
|
11
11
|
isValid: boolean;
|
|
12
12
|
};
|
|
13
|
-
export declare function isValidColorValue(value: any): value is number;
|
|
14
|
-
export declare function isValidRgbColor(rgb: any, strict?: boolean): rgb is RgbColor;
|
|
15
|
-
export declare function isValidHslColor(hsl: any, strict?: boolean): hsl is HslColor;
|
|
@@ -86,31 +86,4 @@ export function parseColorString(colorString, options = {}) {
|
|
|
86
86
|
}
|
|
87
87
|
return { type: null, value: null, isValid: false };
|
|
88
88
|
}
|
|
89
|
-
export function isValidColorValue(value) {
|
|
90
|
-
return typeof value === 'number' && !isNaN(value) && isFinite(value);
|
|
91
|
-
}
|
|
92
|
-
export function isValidRgbColor(rgb, strict = true) {
|
|
93
|
-
if (!rgb || typeof rgb !== 'object')
|
|
94
|
-
return false;
|
|
95
|
-
const { r, g, b } = rgb;
|
|
96
|
-
if (!isValidColorValue(r) || !isValidColorValue(g) || !isValidColorValue(b)) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
if (strict) {
|
|
100
|
-
return r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255;
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
export function isValidHslColor(hsl, strict = true) {
|
|
105
|
-
if (!hsl || typeof hsl !== 'object')
|
|
106
|
-
return false;
|
|
107
|
-
const { h, s, l } = hsl;
|
|
108
|
-
if (!isValidColorValue(h) || !isValidColorValue(s) || !isValidColorValue(l)) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (strict) {
|
|
112
|
-
return h >= 0 && h <= 360 && s >= 0 && s <= 100 && l >= 0 && l <= 100;
|
|
113
|
-
}
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
89
|
//# sourceMappingURL=parseColorString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseColorString.js","sourceRoot":"","sources":["../../../src/functions/color-converter/parseColorString.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseColorString.js","sourceRoot":"","sources":["../../../src/functions/color-converter/parseColorString.ts"],"names":[],"mappings":"AAwCA,MAAM,UAAU,gBAAgB,CAC9B,WAAmB,EACnB,UAAgC,EAAE;IAMlC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAEjC,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IACpD,CAAC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C1B,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;YACpD,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;gBACrB,OAAO,EAAE,IAAI;aACd,CAAA;QACH,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;gBAClB,OAAO,EAAE,IAAI;aACd,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AACpD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function parseCssVariables(code, filePath, dependencies) {
|
|
2
|
+
const variables = {};
|
|
3
|
+
const lines = code.split('\n');
|
|
4
|
+
const cssVarDefPattern = /--([\w-]+)\s*:\s*([^;]+);/g;
|
|
5
|
+
for (const line of lines) {
|
|
6
|
+
const matches = line.matchAll(cssVarDefPattern);
|
|
7
|
+
for (const match of matches) {
|
|
8
|
+
const [, variableName, variableValue] = match;
|
|
9
|
+
const trimmedValue = variableValue.trim();
|
|
10
|
+
const validation = dependencies.isColorValue(trimmedValue);
|
|
11
|
+
if (validation.isValid) {
|
|
12
|
+
const standardizedValue = dependencies.standardizeColor(trimmedValue);
|
|
13
|
+
variables[variableName] = standardizedValue;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return variables;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parseCssVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseCssVariables.js","sourceRoot":"","sources":["../../../src/functions/color-converter/parseCssVariables.ts"],"names":[],"mappings":"AAoCA,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,QAAgB,EAChB,YAAwC;IAExC,MAAM,SAAS,GAA2B,EAAE,CAAA;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAG9B,MAAM,gBAAgB,GAAG,4BAA4B,CAAA;IAErD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;QAE/C,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,EAAE,YAAY,EAAE,aAAa,CAAC,GAAG,KAAK,CAAA;YAC7C,MAAM,YAAY,GAAG,aAAa,CAAC,IAAI,EAAE,CAAA;YAEzC,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,CAAA;YAC1D,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;gBAEvB,MAAM,iBAAiB,GAAG,YAAY,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;gBACrE,SAAS,CAAC,YAAY,CAAC,GAAG,iBAAiB,CAAA;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC"}
|