zcw-shared 1.2.0 → 1.4.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/dist/functions/color-converter/extractColors.d.ts +16 -0
- package/dist/functions/color-converter/extractColors.js +111 -0
- package/dist/functions/color-converter/extractColors.js.map +1 -0
- package/dist/functions/vue/processVueFile.d.ts +20 -0
- package/dist/functions/vue/processVueFile.js +98 -0
- package/dist/functions/vue/processVueFile.js.map +1 -0
- package/package.json +3 -1
- package/types/color.d.ts +21 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ColorReference, ColorFormat, ColorPatterns } from '../../../types/color.d';
|
|
2
|
+
export interface ColorExtractorDependencies {
|
|
3
|
+
getColorPatterns: () => ColorPatterns;
|
|
4
|
+
standardizeColor: (color: string) => string;
|
|
5
|
+
detectColorFormat: (color: string) => ColorFormat | null;
|
|
6
|
+
isColorValue: (value: string) => {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
format?: ColorFormat;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ColorExtractionOptions {
|
|
12
|
+
cssVariables?: Record<string, string>;
|
|
13
|
+
thirdPartyVariables?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function extractColors(code: string, filePath: string, dependencies: ColorExtractorDependencies, options?: ColorExtractionOptions): ColorReference[];
|
|
16
|
+
export declare function extractColorsFromLine(line: string, filePath: string, lineNumber: number, dependencies: ColorExtractorDependencies, options?: ColorExtractionOptions): ColorReference[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export function extractColors(code, filePath, dependencies, options = {}) {
|
|
2
|
+
const { cssVariables = {}, thirdPartyVariables = {} } = options;
|
|
3
|
+
const colors = [];
|
|
4
|
+
const lines = code.split('\n');
|
|
5
|
+
const parsedCssVariables = parseCssVariables(code, filePath, dependencies);
|
|
6
|
+
const allCssVariables = { ...cssVariables, ...parsedCssVariables };
|
|
7
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
8
|
+
const line = lines[lineIndex];
|
|
9
|
+
const lineNumber = lineIndex + 1;
|
|
10
|
+
colors.push(...extractColorsFromLine(line, filePath, lineNumber, dependencies, { cssVariables: allCssVariables, thirdPartyVariables }));
|
|
11
|
+
}
|
|
12
|
+
return colors;
|
|
13
|
+
}
|
|
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
|
+
//# sourceMappingURL=extractColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractColors.js","sourceRoot":"","sources":["../../../src/functions/color-converter/extractColors.ts"],"names":[],"mappings":"AAyDA,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,QAAgB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,IAAY,EACZ,OAAe,EACf,aAAqB,EACrB,sBAA+B,KAAK,EACpC,YAAqB;IAErB,OAAO;QACL,aAAa;QACb,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE;QACvB,mBAAmB;QACnB,YAAY;KACb,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ColorReference } from '../../../types/color.d';
|
|
2
|
+
import type { ColorExtractorDependencies, ColorExtractionOptions } from '../color-converter/extractColors';
|
|
3
|
+
export type VueSectionType = 'template' | 'script' | 'style';
|
|
4
|
+
export interface VueSection {
|
|
5
|
+
type: VueSectionType;
|
|
6
|
+
content: string;
|
|
7
|
+
startLine: number;
|
|
8
|
+
endLine: number;
|
|
9
|
+
}
|
|
10
|
+
export interface VueProcessorDependencies extends ColorExtractorDependencies {
|
|
11
|
+
extractColors: (code: string, filePath: string, dependencies: ColorExtractorDependencies, options?: ColorExtractionOptions) => ColorReference[];
|
|
12
|
+
extractColorsFromLine: (line: string, filePath: string, lineNumber: number, dependencies: ColorExtractorDependencies, options?: ColorExtractionOptions) => ColorReference[];
|
|
13
|
+
}
|
|
14
|
+
export interface VueProcessingOptions extends ColorExtractionOptions {
|
|
15
|
+
includeSections?: VueSectionType[];
|
|
16
|
+
excludeSections?: VueSectionType[];
|
|
17
|
+
}
|
|
18
|
+
export declare function processVueFile(code: string, filePath: string, dependencies: VueProcessorDependencies, options?: VueProcessingOptions): ColorReference[];
|
|
19
|
+
export declare function parseVueFile(code: string): VueSection[];
|
|
20
|
+
export declare function extractColorsFromVueSection(section: VueSection, filePath: string, dependencies: VueProcessorDependencies, options?: VueProcessingOptions): ColorReference[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export function processVueFile(code, filePath, dependencies, options = {}) {
|
|
2
|
+
const colors = [];
|
|
3
|
+
const globalColors = dependencies.extractColors(code, filePath, dependencies, options);
|
|
4
|
+
const sections = parseVueFile(code);
|
|
5
|
+
const filteredSections = filterSections(sections, options);
|
|
6
|
+
for (const section of filteredSections) {
|
|
7
|
+
const sectionColors = extractColorsFromVueSection(section, filePath, dependencies, options);
|
|
8
|
+
colors.push(...sectionColors);
|
|
9
|
+
}
|
|
10
|
+
const allColors = [...globalColors, ...colors];
|
|
11
|
+
return deduplicateColors(allColors);
|
|
12
|
+
}
|
|
13
|
+
export function parseVueFile(code) {
|
|
14
|
+
const sections = [];
|
|
15
|
+
const lines = code.split('\n');
|
|
16
|
+
let currentSection = null;
|
|
17
|
+
let sectionStartLine = 0;
|
|
18
|
+
let sectionContent = [];
|
|
19
|
+
for (let i = 0; i < lines.length; i++) {
|
|
20
|
+
const line = lines[i];
|
|
21
|
+
const trimmedLine = line.trim();
|
|
22
|
+
if (trimmedLine.startsWith('<template') && !trimmedLine.includes('</template>')) {
|
|
23
|
+
saveVueSection(sections, currentSection, sectionStartLine, sectionContent);
|
|
24
|
+
currentSection = 'template';
|
|
25
|
+
sectionStartLine = i + 1;
|
|
26
|
+
sectionContent = [];
|
|
27
|
+
}
|
|
28
|
+
else if (trimmedLine.startsWith('<script') && !trimmedLine.includes('</script>')) {
|
|
29
|
+
saveVueSection(sections, currentSection, sectionStartLine, sectionContent);
|
|
30
|
+
currentSection = 'script';
|
|
31
|
+
sectionStartLine = i + 1;
|
|
32
|
+
sectionContent = [];
|
|
33
|
+
}
|
|
34
|
+
else if (trimmedLine.startsWith('<style') && !trimmedLine.includes('</style>')) {
|
|
35
|
+
saveVueSection(sections, currentSection, sectionStartLine, sectionContent);
|
|
36
|
+
currentSection = 'style';
|
|
37
|
+
sectionStartLine = i + 1;
|
|
38
|
+
sectionContent = [];
|
|
39
|
+
}
|
|
40
|
+
else if (trimmedLine === '</template>' ||
|
|
41
|
+
trimmedLine === '</script>' ||
|
|
42
|
+
trimmedLine === '</style>') {
|
|
43
|
+
if (currentSection) {
|
|
44
|
+
saveVueSection(sections, currentSection, sectionStartLine, sectionContent);
|
|
45
|
+
currentSection = null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (currentSection) {
|
|
49
|
+
sectionContent.push(line);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
saveVueSection(sections, currentSection, sectionStartLine, sectionContent);
|
|
53
|
+
return sections;
|
|
54
|
+
}
|
|
55
|
+
export function extractColorsFromVueSection(section, filePath, dependencies, options = {}) {
|
|
56
|
+
const colors = [];
|
|
57
|
+
const lines = section.content.split('\n');
|
|
58
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
59
|
+
const line = lines[lineIndex];
|
|
60
|
+
const actualLineNumber = section.startLine + lineIndex;
|
|
61
|
+
const lineColors = dependencies.extractColorsFromLine(line, filePath, actualLineNumber, dependencies, options);
|
|
62
|
+
colors.push(...lineColors);
|
|
63
|
+
}
|
|
64
|
+
return colors;
|
|
65
|
+
}
|
|
66
|
+
function filterSections(sections, options) {
|
|
67
|
+
let filteredSections = sections;
|
|
68
|
+
if (options.includeSections && options.includeSections.length > 0) {
|
|
69
|
+
filteredSections = filteredSections.filter(section => options.includeSections.includes(section.type));
|
|
70
|
+
}
|
|
71
|
+
if (options.excludeSections && options.excludeSections.length > 0) {
|
|
72
|
+
filteredSections = filteredSections.filter(section => !options.excludeSections.includes(section.type));
|
|
73
|
+
}
|
|
74
|
+
return filteredSections;
|
|
75
|
+
}
|
|
76
|
+
function saveVueSection(sections, sectionType, startLine, content) {
|
|
77
|
+
if (sectionType && content.length > 0) {
|
|
78
|
+
sections.push({
|
|
79
|
+
type: sectionType,
|
|
80
|
+
content: content.join('\n'),
|
|
81
|
+
startLine,
|
|
82
|
+
endLine: startLine + content.length - 1
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function deduplicateColors(colors) {
|
|
87
|
+
const seen = new Set();
|
|
88
|
+
const result = [];
|
|
89
|
+
for (const color of colors) {
|
|
90
|
+
const key = `${color.file}:${color.line}:${color.originalValue}`;
|
|
91
|
+
if (!seen.has(key)) {
|
|
92
|
+
seen.add(key);
|
|
93
|
+
result.push(color);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=processVueFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processVueFile.js","sourceRoot":"","sources":["../../../src/functions/vue/processVueFile.ts"],"names":[],"mappings":"AAqFA,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,QAAgB,EAChB,YAAsC,EACtC,UAAgC,EAAE;IAElC,MAAM,MAAM,GAAqB,EAAE,CAAA;IAGnC,MAAM,YAAY,GAAG,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IAGtF,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAGnC,MAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAG1D,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACvC,MAAM,aAAa,GAAG,2BAA2B,CAC/C,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,OAAO,CACR,CAAA;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAA;IAC/B,CAAC;IAGD,MAAM,SAAS,GAAG,CAAC,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC,CAAA;IAC9C,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAA;AACrC,CAAC;AA2BD,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,QAAQ,GAAiB,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE9B,IAAI,cAAc,GAA0B,IAAI,CAAA;IAChD,IAAI,gBAAgB,GAAG,CAAC,CAAA;IACxB,IAAI,cAAc,GAAa,EAAE,CAAA;IAEjC,KAAK,IAA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ACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcw-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"references",
|
|
6
6
|
"dist",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"./functions/base64/strToBase64": "./dist/functions/base64/strToBase64.js",
|
|
35
35
|
"./functions/color-converter/convertColor": "./dist/functions/color-converter/convertColor.js",
|
|
36
36
|
"./functions/color-converter/detectColorFormat": "./dist/functions/color-converter/detectColorFormat.js",
|
|
37
|
+
"./functions/color-converter/extractColors": "./dist/functions/color-converter/extractColors.js",
|
|
37
38
|
"./functions/color-converter/getColorPatterns": "./dist/functions/color-converter/getColorPatterns.js",
|
|
38
39
|
"./functions/color-converter/getNamedColorMap": "./dist/functions/color-converter/getNamedColorMap.js",
|
|
39
40
|
"./functions/color-converter/hueToRgb": "./dist/functions/color-converter/hueToRgb.js",
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
"./functions/vue/dynamicMount": "./dist/functions/vue/dynamicMount.js",
|
|
119
120
|
"./functions/vue/isVNode": "./dist/functions/vue/isVNode.js",
|
|
120
121
|
"./functions/vue/isVueComponent": "./dist/functions/vue/isVueComponent.js",
|
|
122
|
+
"./functions/vue/processVueFile": "./dist/functions/vue/processVueFile.js",
|
|
121
123
|
"./functions/wechat/miniapp/downloadFile": "./dist/functions/wechat/miniapp/downloadFile.js",
|
|
122
124
|
"./hooks/useAi": "./dist/hooks/useAi.js",
|
|
123
125
|
"./hooks/useCache": "./dist/hooks/useCache.js",
|
package/types/color.d.ts
CHANGED
|
@@ -112,4 +112,25 @@ export interface ColorConversionOptions {
|
|
|
112
112
|
alphaValue?: number
|
|
113
113
|
/** 是否使用8位十六进制格式 */
|
|
114
114
|
use8BitHex?: boolean
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 颜色引用信息
|
|
119
|
+
* 用于描述在代码中发现的颜色值及其上下文信息
|
|
120
|
+
*/
|
|
121
|
+
export interface ColorReference {
|
|
122
|
+
/** 原始颜色值 */
|
|
123
|
+
originalValue: string
|
|
124
|
+
/** 颜色格式类型 */
|
|
125
|
+
format: ColorFormat | 'css-variable' | 'third-party-variable'
|
|
126
|
+
/** 文件路径 */
|
|
127
|
+
file: string
|
|
128
|
+
/** 行号 */
|
|
129
|
+
line: number
|
|
130
|
+
/** 上下文代码 */
|
|
131
|
+
context: string
|
|
132
|
+
/** 是否为变量引用 */
|
|
133
|
+
isVariableReference?: boolean
|
|
134
|
+
/** 变量名称(当isVariableReference为true时) */
|
|
135
|
+
variableName?: string
|
|
115
136
|
}
|