windi.config.ts 1.8 KB

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