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