refactor(styles): share the Tailwind config from @lcui/tailwind-config

- replace the duplicated design tokens, core plugin whitelist and shadow
  plugin with the shared package
- drop scripts/theme-colors.js and scripts/tailwind-shadow-plugin.js now
  that both configs consume the package
This commit is contained in:
Liu
2026-11-15 23:40:46 +08:00
parent 57272be8d1
commit 17114108b7
4 changed files with 6 additions and 189 deletions
+3 -49
View File
@@ -1,55 +1,9 @@
const { colors, boxShadow } = require("../../scripts/theme-colors");
const { createConfig } = require("@lcui/tailwind-config");
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "class",
module.exports = createConfig({
content: [
"./app/**/*.{tsx,html}",
"../../docs/examples/**/*-tsx/example.tsx",
],
theme: {
extend: {
colors,
boxShadow,
},
},
plugins: [
require("../../scripts/tailwind-shadow-plugin")({ shadows: boxShadow }),
],
corePlugins: [
"display",
"flexDirection",
"flexWrap",
"flex",
"flexShrink",
"flexGrow",
"alignItems",
"justifyContent",
"width",
"height",
"minWidth",
"minHeight",
"maxWidth",
"maxHeight",
"overflow",
"padding",
"margin",
"gap",
"borderRadius",
"borderWidth",
"borderColor",
"backgroundColor",
"textColor",
"fontFamily",
"fontSize",
"fontWeight",
"lineHeight",
"opacity",
"whitespace",
"cursor",
"position",
"inset",
"textDecoration",
"textUnderlineOffset",
],
};
});
-34
View File
@@ -1,34 +0,0 @@
const plugin = require("tailwindcss/plugin");
/**
* Box-shadow utilities that inline the configured shadow value.
*
* Tailwind's built-in `box-shadow` plugin emits `--tw-shadow` /
* `--tw-shadow-colored` custom properties and a `var(...)` chain. LCUI's CSS
* parser has no custom-property support, so those declarations are ignored and
* the utilities would silently do nothing. This plugin keeps the familiar
* `shadow-<name>` class names while writing the literal value instead.
*
* Pass the shadow map explicitly so only the values this project defines are
* emitted; otherwise Tailwind's default theme would also expose `shadow`,
* `shadow-xl`, `shadow-inner` and friends.
*
* Only utilities that actually appear in the scanned content are emitted,
* because Tailwind still applies its candidate-based tree shaking.
*/
module.exports = plugin.withOptions((options = {}) => {
return ({ addUtilities, theme }) => {
const shadows = options.shadows || theme("boxShadow") || {};
const utilities = {};
for (const [name, value] of Object.entries(shadows)) {
if (typeof value !== "string" || value.length === 0) {
continue;
}
utilities[name === "DEFAULT" ? ".shadow" : `.shadow-${name}`] = {
boxShadow: value,
};
}
addUtilities(utilities);
};
});
-66
View File
@@ -1,66 +0,0 @@
/** Shared semantic color tokens for the LCUI light and dark themes. */
const colors = {
background: { DEFAULT: "#ffffff", dark: "#0a0a0a" },
foreground: { DEFAULT: "#0a0a0a", dark: "#fafafa" },
card: { DEFAULT: "#ffffff", dark: "#171717" },
"card-foreground": { DEFAULT: "#0a0a0a", dark: "#fafafa" },
popover: { DEFAULT: "#ffffff", dark: "#171717" },
"popover-foreground": { DEFAULT: "#0a0a0a", dark: "#fafafa" },
primary: { DEFAULT: "#171717", dark: "#fafafa" },
"primary-foreground": { DEFAULT: "#fafafa", dark: "#171717" },
secondary: { DEFAULT: "#f5f5f5", dark: "#262626" },
"secondary-foreground": { DEFAULT: "#171717", dark: "#fafafa" },
muted: { DEFAULT: "#f5f5f5", dark: "#262626" },
"muted-foreground": { DEFAULT: "#737373", dark: "#a1a1a1" },
accent: { DEFAULT: "#f5f5f5", dark: "#262626" },
"accent-foreground": { DEFAULT: "#171717", dark: "#fafafa" },
destructive: { DEFAULT: "#e7000b", dark: "#ff6467" },
"destructive-muted": { DEFAULT: "#ffe8e9", dark: "#4c0519" },
border: { DEFAULT: "#e5e5e5", dark: "rgba(255, 255, 255, 0.1)" },
input: { DEFAULT: "#e5e5e5", dark: "rgba(255, 255, 255, 0.15)" },
ring: { DEFAULT: "#a1a1a1", dark: "#d4d4d4" },
sidebar: { DEFAULT: "#fafafa", dark: "#171717" },
"sidebar-foreground": { DEFAULT: "#0a0a0a", dark: "#fafafa" },
"sidebar-primary": { DEFAULT: "#171717", dark: "#fafafa" },
"sidebar-primary-foreground": { DEFAULT: "#fafafa", dark: "#171717" },
"sidebar-accent": { DEFAULT: "#f5f5f5", dark: "#262626" },
"sidebar-accent-foreground": { DEFAULT: "#171717", dark: "#fafafa" },
"sidebar-border": {
DEFAULT: "#e5e5e5",
dark: "rgba(255, 255, 255, 0.1)",
},
success: { DEFAULT: "#16a34a", dark: "#4ade80" },
warning: { DEFAULT: "#f5b301", dark: "#facc15" },
code: { DEFAULT: "#f7f7f7", dark: "#171717" },
"code-foreground": { DEFAULT: "#1f2328", dark: "#d4d4d4" },
"code-header": { DEFAULT: "#f5f5f5", dark: "#1f1f1f" },
"code-border": { DEFAULT: "#e5e5e5", dark: "rgba(255, 255, 255, 0.1)" },
overlay: { DEFAULT: "rgba(0, 0, 0, 0.35)", dark: "rgba(0, 0, 0, 0.55)" },
"card-image-cover": { DEFAULT: "#94a3b8", dark: "#475569" },
"card-image-overlay": {
DEFAULT: "rgba(0, 0, 0, 0.35)",
dark: "rgba(0, 0, 0, 0.55)",
},
"admonition-note": { DEFAULT: "#3b82f6", dark: "#58a6ff" },
"admonition-note-foreground": { DEFAULT: "#1d4ed8", dark: "#79c0ff" },
"admonition-info": { DEFAULT: "#06b6d4", dark: "#39c5cf" },
"admonition-info-foreground": { DEFAULT: "#0891b2", dark: "#56d4dd" },
"admonition-tip": { DEFAULT: "#10b981", dark: "#56d364" },
"admonition-tip-foreground": { DEFAULT: "#047857", dark: "#7ee787" },
"admonition-caution": { DEFAULT: "#eab308", dark: "#e3b341" },
"admonition-caution-foreground": { DEFAULT: "#ca8a04", dark: "#f2cc60" },
"admonition-warning": { DEFAULT: "#ef4444", dark: "#f85149" },
"admonition-warning-foreground": { DEFAULT: "#b91c1c", dark: "#ff7b72" },
};
const boxShadow = {
sm: "0 1px 4px 0 rgba(0, 0, 0, 0.2)",
md: "0 8px 24px rgba(0, 0, 0, 0.12)",
lg: "0 10px 30px rgba(0, 0, 0, 0.15)",
focus: "0 0 0 3px rgba(34, 34, 34, 0.1)",
"focus-dark": "0 0 0 3px rgba(250, 250, 250, 0.18)",
"focus-sm": "0 0 0 2px rgba(34, 34, 34, 0.12)",
"focus-sm-dark": "0 0 0 2px rgba(250, 250, 250, 0.2)",
};
module.exports = { colors, boxShadow };
+3 -40
View File
@@ -1,43 +1,6 @@
const { colors, boxShadow } = require("./scripts/theme-colors");
const { createConfig } = require("@lcui/tailwind-config");
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "class",
module.exports = createConfig({
content: ["./src/**/*.{c,h,css}"],
theme: {
extend: {
colors,
boxShadow,
},
},
plugins: [
require("./scripts/tailwind-shadow-plugin")({ shadows: boxShadow }),
],
corePlugins: [
"display",
"flexDirection",
"flex",
"alignItems",
"justifyContent",
"width",
"height",
"padding",
"margin",
"gap",
"borderRadius",
"borderWidth",
"borderColor",
"backgroundColor",
"textColor",
"fontSize",
"fontWeight",
"lineHeight",
"textAlign",
"position",
"inset",
"pointerEvents",
"textDecoration",
"textUnderlineOffset",
"opacity",
],
};
});