unocss.config.ts 2.0 KB

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