zcw-shared 1.3.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.
@@ -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,CA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IAAI,KAAK,CAAC,aAAa,EAAE,CAAA;QAChE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACb,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zcw-shared",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "files": [
5
5
  "references",
6
6
  "dist",
@@ -119,6 +119,7 @@
119
119
  "./functions/vue/dynamicMount": "./dist/functions/vue/dynamicMount.js",
120
120
  "./functions/vue/isVNode": "./dist/functions/vue/isVNode.js",
121
121
  "./functions/vue/isVueComponent": "./dist/functions/vue/isVueComponent.js",
122
+ "./functions/vue/processVueFile": "./dist/functions/vue/processVueFile.js",
122
123
  "./functions/wechat/miniapp/downloadFile": "./dist/functions/wechat/miniapp/downloadFile.js",
123
124
  "./hooks/useAi": "./dist/hooks/useAi.js",
124
125
  "./hooks/useCache": "./dist/hooks/useCache.js",