windi.config.ts 1.9 KB

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