windi.config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import lineClamp from 'windicss/plugin/line-clamp';
  2. import colors from 'windicss/colors';
  3. import { defineConfig } from 'vite-plugin-windicss';
  4. import { primaryColor } from './build/config/themeConfig';
  5. export default defineConfig({
  6. darkMode: 'class',
  7. plugins: [lineClamp, createEnterPlugin()],
  8. theme: {
  9. extend: {
  10. colors: {
  11. ...colors,
  12. primary: primaryColor,
  13. secondary: 'rgba(0, 0, 0, 0.45)',
  14. },
  15. screens: {
  16. sm: '576px',
  17. md: '768px',
  18. lg: '992px',
  19. xl: '1200px',
  20. '2xl': '1600px',
  21. },
  22. },
  23. },
  24. });
  25. /**
  26. * Used for animation when the element is displayed
  27. * @param maxOutput The larger the maxOutput output, the larger the generated css volume
  28. */
  29. function createEnterPlugin(maxOutput = 10) {
  30. const createCss = (index: number, d = 'x') => {
  31. const upd = d.toUpperCase();
  32. return {
  33. [`*> .enter-${d}:nth-child(${index})`]: {
  34. transform: `translate${upd}(50px)`,
  35. },
  36. [`*> .-enter-${d}:nth-child(${index})`]: {
  37. transform: `translate${upd}(-50px)`,
  38. },
  39. [`* > .enter-${d}:nth-child(${index}),* > .-enter-${d}:nth-child(${index})`]: {
  40. 'z-index': `${10 - index}`,
  41. opacity: '0',
  42. animation: `enter-${d}-animation 0.4s ease-in-out 0.3s`,
  43. 'animation-fill-mode': 'forwards',
  44. 'animation-delay': `${(index * 1) / 10}s`,
  45. },
  46. };
  47. };
  48. const handler = ({ addBase }) => {
  49. const addRawCss = {};
  50. for (let index = 1; index < maxOutput; index++) {
  51. Object.assign(addRawCss, {
  52. ...createCss(index, 'x'),
  53. ...createCss(index, 'y'),
  54. });
  55. }
  56. addBase({
  57. ...addRawCss,
  58. [`@keyframes enter-x-animation`]: {
  59. to: {
  60. opacity: '1',
  61. transform: 'translateX(0)',
  62. },
  63. },
  64. [`@keyframes enter-y-animation`]: {
  65. to: {
  66. opacity: '1',
  67. transform: 'translateY(0)',
  68. },
  69. },
  70. });
  71. };
  72. return { handler };
  73. }