unix update

This commit is contained in:
icssoa 2025-06-08 10:33:20 +08:00
parent e43576ac01
commit da26abc4d7
3 changed files with 62 additions and 14 deletions

View File

@ -7,7 +7,6 @@
const config = { const config = {
type: "admin", type: "admin",
reqUrl: "", reqUrl: "",
demo: false,
nameTag: true, nameTag: true,
eps: { eps: {
enable: true, enable: true,
@ -245,13 +244,36 @@
while ((ternaryMatch = ternaryRegex.exec(value)) !== null) { while ((ternaryMatch = ternaryRegex.exec(value)) !== null) {
ternaryMatch[2].trim() && names.add(ternaryMatch[2]); ternaryMatch[2].trim() && names.add(ternaryMatch[2]);
} }
// 匹配反引号模板字符串
const templateRegex = /`([^`]*)`/g;
let templateMatch;
while ((templateMatch = templateRegex.exec(value)) !== null) {
const templateContent = templateMatch[1];
// 提取模板字符串中的普通文本部分(排除 ${} 表达式)
const textParts = templateContent.split(/\$\{[^}]*\}/);
textParts.forEach((part) => {
part.trim()
.split(/\s+/)
.forEach((className) => {
className.trim() && names.add(className.trim());
});
});
// 提取模板字符串中 ${} 表达式内的字符串
const expressionRegex = /\$\{([^}]*)\}/g;
let expressionMatch;
while ((expressionMatch = expressionRegex.exec(templateContent)) !== null) {
const expression = expressionMatch[1];
// 递归处理表达式中的动态类名
getDynamicClassNames(expression).forEach((name) => names.add(name));
}
}
return Array.from(names); return Array.from(names);
}; };
/** /**
* 获取类名 * 获取类名
*/ */
function getClassNames(html) { function getClassNames(html) {
const classRegex = /(?:class|:class)\s*=\s*(["'])([\s\S]*?)\1/gi; const classRegex = /(?:class|:class|:pt)\s*=\s*(['"`])([\s\S]*?)\1/gi;
const classNames = new Set(); const classNames = new Set();
let match; let match;
while ((match = classRegex.exec(html)) !== null) { while ((match = classRegex.exec(html)) !== null) {
@ -272,7 +294,7 @@
* 获取 class 内容 * 获取 class 内容
*/ */
function getClassContent(html) { function getClassContent(html) {
const regex = /(?:class|:class)\s*=\s*(['"])([\s\S]*?)\1/g; const regex = /(?:class|:class|:pt)\s*=\s*(['"`])([\s\S]*?)\1/g;
const texts = []; const texts = [];
let match; let match;
while ((match = regex.exec(html)) !== null) { while ((match = regex.exec(html)) !== null) {
@ -410,6 +432,9 @@
"group-hover:", "group-hover:",
]; ];
const statePrefixes = ["dark:", "light:", "sm:", "md:", "lg:", "xl:", "2xl:"]; const statePrefixes = ["dark:", "light:", "sm:", "md:", "lg:", "xl:", "2xl:"];
if (className.includes("!")) {
return true;
}
for (const prefix of prefixes) { for (const prefix of prefixes) {
if (className.startsWith(prefix)) { if (className.startsWith(prefix)) {
return true; return true;
@ -1165,13 +1190,8 @@
if (match) { if (match) {
const value = match[1]; const value = match[1];
try { try {
if (config.type == "uniapp-x") { const { target, rewrite } = proxy[`/${value}/`];
return proxy[value].target; return target + rewrite(`/${value}`);
}
else {
const { target, rewrite } = proxy[`/${value}/`];
return target + rewrite(`/${value}`);
}
} }
catch (err) { catch (err) {
error(`[cool-proxy] Error${value}` + getPath()); error(`[cool-proxy] Error${value}` + getPath());
@ -1823,7 +1843,6 @@ if (typeof window !== 'undefined') {
.replaceAll(':class="{}"', "") .replaceAll(':class="{}"', "")
.replaceAll('class=""', "") .replaceAll('class=""', "")
.replaceAll('class=" "', ""); .replaceAll('class=" "', "");
// console.log(modifiedCode);
return { return {
code: modifiedCode, code: modifiedCode,
map: { mappings: "" }, map: { mappings: "" },

View File

@ -331,7 +331,6 @@ function transformPlugin(): Plugin {
.replaceAll('class=""', "") .replaceAll('class=""', "")
.replaceAll('class=" "', ""); .replaceAll('class=" "', "");
// console.log(modifiedCode);
return { return {
code: modifiedCode, code: modifiedCode,
map: { mappings: "" }, map: { mappings: "" },

View File

@ -25,6 +25,32 @@ export const getDynamicClassNames = (value: string): string[] => {
ternaryMatch[2].trim() && names.add(ternaryMatch[2]); ternaryMatch[2].trim() && names.add(ternaryMatch[2]);
} }
// 匹配反引号模板字符串
const templateRegex = /`([^`]*)`/g;
let templateMatch;
while ((templateMatch = templateRegex.exec(value)) !== null) {
const templateContent = templateMatch[1];
// 提取模板字符串中的普通文本部分(排除 ${} 表达式)
const textParts = templateContent.split(/\$\{[^}]*\}/);
textParts.forEach((part) => {
part.trim()
.split(/\s+/)
.forEach((className) => {
className.trim() && names.add(className.trim());
});
});
// 提取模板字符串中 ${} 表达式内的字符串
const expressionRegex = /\$\{([^}]*)\}/g;
let expressionMatch;
while ((expressionMatch = expressionRegex.exec(templateContent)) !== null) {
const expression = expressionMatch[1];
// 递归处理表达式中的动态类名
getDynamicClassNames(expression).forEach((name) => names.add(name));
}
}
return Array.from(names); return Array.from(names);
}; };
@ -32,7 +58,7 @@ export const getDynamicClassNames = (value: string): string[] => {
* *
*/ */
export function getClassNames(html: string): string[] { export function getClassNames(html: string): string[] {
const classRegex = /(?:class|:class)\s*=\s*(["'])([\s\S]*?)\1/gi; const classRegex = /(?:class|:class|:pt)\s*=\s*(['"`])([\s\S]*?)\1/gi;
const classNames = new Set<string>(); const classNames = new Set<string>();
let match; let match;
@ -56,7 +82,7 @@ export function getClassNames(html: string): string[] {
* class * class
*/ */
export function getClassContent(html: string) { export function getClassContent(html: string) {
const regex = /(?:class|:class)\s*=\s*(['"])([\s\S]*?)\1/g; const regex = /(?:class|:class|:pt)\s*=\s*(['"`])([\s\S]*?)\1/g;
const texts: string[] = []; const texts: string[] = [];
let match; let match;
@ -222,6 +248,10 @@ export function isTailwindClass(className: string): boolean {
const statePrefixes = ["dark:", "light:", "sm:", "md:", "lg:", "xl:", "2xl:"]; const statePrefixes = ["dark:", "light:", "sm:", "md:", "lg:", "xl:", "2xl:"];
if (className.includes("!")) {
return true;
}
for (const prefix of prefixes) { for (const prefix of prefixes) {
if (className.startsWith(prefix)) { if (className.startsWith(prefix)) {
return true; return true;