windi.config.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { defineConfig } from 'vite-plugin-windicss';
  2. import { primaryColor } from './build/config/themeConfig';
  3. export default defineConfig({
  4. darkMode: 'class',
  5. plugins: [createEnterPlugin()],
  6. theme: {
  7. extend: {
  8. zIndex: {
  9. '-1': '-1',
  10. },
  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 = 6) {
  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. }