mirror of
https://github.com/HoshinoSuzumi/rayine-ui.git
synced 2025-04-15 06:38:51 +08:00
🐛 Fix safelist
This commit is contained in:
parent
d4a601105d
commit
a542bc82b9
@ -10,6 +10,16 @@ import { installTailwind } from "./tailwind";
|
||||
import type { config } from "process";
|
||||
import type { Strategy, DeepPartial } from "./runtime/types/utils";
|
||||
import { createTemplates } from "./template";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const _require = createRequire(import.meta.url);
|
||||
const defaultColors = _require("tailwindcss/colors.js");
|
||||
|
||||
delete defaultColors.lightBlue;
|
||||
delete defaultColors.warmGray;
|
||||
delete defaultColors.trueGray;
|
||||
delete defaultColors.coolGray;
|
||||
delete defaultColors.blueGray;
|
||||
|
||||
type RayUI = {
|
||||
primary?: string;
|
||||
|
@ -1,17 +1,5 @@
|
||||
import type { Config as TwConfig } from "tailwindcss";
|
||||
import defaultColors from "tailwindcss/colors.js";
|
||||
import type { SafelistConfig } from "tailwindcss/types/config";
|
||||
|
||||
// @ts-ignore
|
||||
delete defaultColors.lightBlue;
|
||||
// @ts-ignore
|
||||
delete defaultColors.warmGray;
|
||||
// @ts-ignore
|
||||
delete defaultColors.trueGray;
|
||||
// @ts-ignore
|
||||
delete defaultColors.coolGray;
|
||||
// @ts-ignore
|
||||
delete defaultColors.blueGray;
|
||||
|
||||
const colorsToRegex = (colors: string[]): string => colors.join("|");
|
||||
|
||||
@ -136,32 +124,12 @@ const safelistForComponent: Record<
|
||||
],
|
||||
};
|
||||
|
||||
export const generateSafelist = (
|
||||
colors: string[],
|
||||
globalColors: string[]
|
||||
): string[] => {
|
||||
const safelist = Object.keys(safelistForComponent)
|
||||
.flatMap((component) =>
|
||||
safelistForComponent[component](colorsToRegex(colors))
|
||||
)
|
||||
.filter(
|
||||
(item): item is Exclude<SafelistConfig, string> => item !== undefined
|
||||
);
|
||||
export const generateSafelist = (colors: string[], globalColors: string[]) => {
|
||||
const safelist = Object.keys(safelistForComponent).flatMap((component) =>
|
||||
safelistForComponent[component](colorsToRegex(colors))
|
||||
);
|
||||
|
||||
const extractColorsFromPattern = (pattern: RegExp): string[] => {
|
||||
const matches = pattern.source.match(/\(([^)]+)\)/);
|
||||
if (!matches) return [];
|
||||
return matches[1].split("|").map((color) =>
|
||||
pattern.source.replace(matches[0], color).replace(/[\^\$]/g, "")
|
||||
);
|
||||
};
|
||||
|
||||
return safelist.flatMap((item) => {
|
||||
const replacedStrings = extractColorsFromPattern(item.pattern);
|
||||
return replacedStrings.concat(
|
||||
item.variants?.flatMap((variant) =>
|
||||
replacedStrings.map((str) => `${variant}:${str}`)
|
||||
) || []
|
||||
);
|
||||
});
|
||||
return [
|
||||
...safelist
|
||||
]
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ export const createTemplates = (nuxt = useNuxt()) => {
|
||||
const typesTemplate = addTemplate({
|
||||
filename: "ray.colors.d.ts",
|
||||
getContents: () =>
|
||||
`declare module '#ui-colors' { const defaultExport: ${JSON.stringify(
|
||||
`declare module '#ray-colors' { const defaultExport: ${JSON.stringify(
|
||||
nuxt.options.appConfig.rayui.colors
|
||||
)}; export default defaultExport; }`,
|
||||
write: true,
|
||||
|
Loading…
Reference in New Issue
Block a user