优化 cl-text 组件的字体大小和颜色,在 pt 配置中无需添加 ! 符号

This commit is contained in:
icssoa
2025-09-07 11:08:01 +08:00
parent 8e583121e4
commit 1b6fc90d59
57 changed files with 406 additions and 239 deletions

View File

@@ -610,73 +610,3 @@ export function isEqual(a: any, b: any): boolean {
return a == b;
}
/**
* 检查是否为小程序环境
* @returns 是否为小程序环境
*/
export const isMp = (): boolean => {
// #ifdef MP
return true;
// #endif
return false;
};
/**
* 检查是否为App环境
* @returns 是否为App环境
*/
export const isApp = (): boolean => {
// #ifdef APP
return true;
// #endif
return false;
};
/**
* 检查是否为App-IOS环境
* @returns 是否为App-IOS环境
*/
export const isAppIOS = (): boolean => {
// #ifdef APP-IOS
return true;
// #endif
return false;
};
/**
* 检查是否为App-Android环境
* @returns 是否为App-Android环境
*/
export const isAppAndroid = (): boolean => {
// #ifdef APP-ANDROID
return true;
// #endif
return false;
};
/**
* 检查是否为H5环境
* @returns 是否为H5环境
*/
export const isH5 = (): boolean => {
// #ifdef H5
return true;
// #endif
return false;
};
/**
* 检查是否为鸿蒙环境
* @returns 是否为鸿蒙环境
*/
export const isHarmony = (): boolean => {
// #ifdef APP-HARMONY
return true;
// #endif
return false;
};

View File

@@ -1,3 +1,73 @@
/**
* 检查是否为小程序环境
* @returns 是否为小程序环境
*/
export const isMp = (): boolean => {
// #ifdef MP
return true;
// #endif
return false;
};
/**
* 检查是否为App环境
* @returns 是否为App环境
*/
export const isApp = (): boolean => {
// #ifdef APP
return true;
// #endif
return false;
};
/**
* 检查是否为App-IOS环境
* @returns 是否为App-IOS环境
*/
export const isAppIOS = (): boolean => {
// #ifdef APP-IOS
return true;
// #endif
return false;
};
/**
* 检查是否为App-Android环境
* @returns 是否为App-Android环境
*/
export const isAppAndroid = (): boolean => {
// #ifdef APP-ANDROID
return true;
// #endif
return false;
};
/**
* 检查是否为H5环境
* @returns 是否为H5环境
*/
export const isH5 = (): boolean => {
// #ifdef H5
return true;
// #endif
return false;
};
/**
* 检查是否为鸿蒙环境
* @returns 是否为鸿蒙环境
*/
export const isHarmony = (): boolean => {
// #ifdef APP-HARMONY
return true;
// #endif
return false;
};
/**
* 获取设备像素比
* @returns 设备像素比

View File

@@ -1,3 +1,4 @@
export * from "./tailwind";
export * from "./comm";
export * from "./day";
export * from "./device";

View File

@@ -1,6 +1,6 @@
import { config } from "@/config";
import { router } from "../router";
import { isH5, isHarmony } from "./comm";
import { isH5, isHarmony } from "./device";
import { ctx } from "../ctx";
import { getPx } from "./parse";

28
cool/utils/tailwind.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* 判断 Tailwind class 字符串中是否包含文本颜色类(如 text-red, text-red-500, text-sky 等)
* @param className 传入的 class 字符串
* @returns 是否包含文本颜色类
*/
export function hasTextColor(className: string): boolean {
if (className == "") return false;
const regex =
/\btext-(primary|surface|red|blue|green|yellow|purple|pink|indigo|gray|grey|black|white|orange|amber|lime|emerald|teal|cyan|sky|violet|fuchsia|rose|slate|zinc|neutral|stone)(?:-\d+)?\b/;
return regex.test(className);
}
/**
* 判断 Tailwind class 字符串中是否包含字体大小类
* 支持如 text-xs, text-sm, text-base, text-lg, text-xl, 以及 text-[22px]、text-[22rpx] 等自定义写法
* @param className 传入的 class 字符串
* @returns 是否包含字体大小类
*/
export function hasTextSize(className: string): boolean {
if (className == "") return false;
const regex =
/\btext-(xs|sm|md|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl|\[\d+[a-zA-Z%]*\])\b/;
return regex.test(className);
}