weapp-tailwindcss-webpack-plugin
Version:
把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!
44 lines (42 loc) • 945 B
JavaScript
// src/css-macro/constants.ts
var queryKey = "weapp-tw-platform";
function createMediaQuery(value) {
return `@media (${queryKey}:"${value}"){&}`;
}
function createNegativeMediaQuery(value) {
return `@media not screen and (${queryKey}:"${value}"){&}`;
}
function normalComment(text) {
if (typeof text === "string") {
return text.replaceAll(/(?<!\\)_/g, " ");
}
return text;
}
function ifdef(text) {
return {
start: `#ifdef ${normalComment(text)}`,
end: `#endif`
};
}
function ifndef(text) {
return {
start: `#ifndef ${normalComment(text)}`,
end: `#endif`
};
}
function matchCustomPropertyFromValue(str, cb) {
let arr;
let index = 0;
const regex = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
while ((arr = regex.exec(str)) !== null) {
cb(arr, index);
index++;
}
}
export {
createMediaQuery,
createNegativeMediaQuery,
ifdef,
ifndef,
matchCustomPropertyFromValue
};