windi.config.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. },
  14. screens: {
  15. sm: '576px',
  16. md: '768px',
  17. lg: '992px',
  18. xl: '1200px',
  19. '2xl': '1600px',
  20. },
  21. },
  22. },
  23. });
  24. /**
  25. * Used for animation when the element is displayed
  26. * @param maxOutput The larger the maxOutput output, the larger the generated css volume
  27. */
  28. function createEnterPlugin(maxOutput = 10) {
  29. const createCss = (index: number, d = 'x') => {
  30. const upd = d.toUpperCase();
  31. return {
  32. [`*> .enter-${d}:nth-child(${index})`]: {
  33. transform: `translate${upd}(50px)`,
  34. },
  35. [`*> .-enter-${d}:nth-child(${index})`]: {
  36. transform: `translate${upd}(-50px)`,
  37. },
  38. [`* > .enter-${d}:nth-child(${index}),* > .-enter-${d}:nth-child(${index})`]: {
  39. 'z-index': `${10 - index}`,
  40. opacity: '0',
  41. animation: `enter-${d}-animation 0.4s ease-in-out 0.3s`,
  42. 'animation-fill-mode': 'forwards',
  43. 'animation-delay': `${(index * 1) / 10}s`,
  44. },
  45. };
  46. };
  47. const handler = ({ addBase }) => {
  48. const addRawCss = {};
  49. for (let index = 1; index < maxOutput; index++) {
  50. Object.assign(addRawCss, {
  51. ...createCss(index, 'x'),
  52. ...createCss(index, 'y'),
  53. });
  54. }
  55. addBase({
  56. ...addRawCss,
  57. [`@keyframes enter-x-animation`]: {
  58. to: {
  59. opacity: '1',
  60. transform: 'translateX(0)',
  61. },
  62. },
  63. [`@keyframes enter-y-animation`]: {
  64. to: {
  65. opacity: '1',
  66. transform: 'translateY(0)',
  67. },
  68. },
  69. });
  70. };
  71. return { handler };
  72. }