unocss.config.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. preflights: [
  23. {
  24. getCSS: () =>
  25. `*> .enter-x:nth-child(1) {transform:translateX(50px);}*> .-enter-x:nth-child(1) {transform:translateX(-50px);}* > .enter-x:nth-child(1),* > .-enter-x:nth-child(1) {z-index:9;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.1s;}*> .enter-y:nth-child(1) {transform:translateY(50px);}*> .-enter-y:nth-child(1) {transform:translateY(-50px);}* > .enter-y:nth-child(1),* > .-enter-y:nth-child(1) {z-index:9;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.1s;}*> .enter-x:nth-child(2) {transform:translateX(50px);}*> .-enter-x:nth-child(2) {transform:translateX(-50px);}* > .enter-x:nth-child(2),* > .-enter-x:nth-child(2) {z-index:8;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.2s;}*> .enter-y:nth-child(2) {transform:translateY(50px);}*> .-enter-y:nth-child(2) {transform:translateY(-50px);}* > .enter-y:nth-child(2),* > .-enter-y:nth-child(2) {z-index:8;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.2s;}*> .enter-x:nth-child(3) {transform:translateX(50px);}*> .-enter-x:nth-child(3) {transform:translateX(-50px);}* > .enter-x:nth-child(3),* > .-enter-x:nth-child(3) {z-index:7;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.3s;}*> .enter-y:nth-child(3) {transform:translateY(50px);}*> .-enter-y:nth-child(3) {transform:translateY(-50px);}* > .enter-y:nth-child(3),* > .-enter-y:nth-child(3) {z-index:7;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.3s;}*> .enter-x:nth-child(4) {transform:translateX(50px);}*> .-enter-x:nth-child(4) {transform:translateX(-50px);}* > .enter-x:nth-child(4),* > .-enter-x:nth-child(4) {z-index:6;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.4s;}*> .enter-y:nth-child(4) {transform:translateY(50px);}*> .-enter-y:nth-child(4) {transform:translateY(-50px);}* > .enter-y:nth-child(4),* > .-enter-y:nth-child(4) {z-index:6;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.4s;}*> .enter-x:nth-child(5) {transform:translateX(50px);}*> .-enter-x:nth-child(5) {transform:translateX(-50px);}* > .enter-x:nth-child(5),* > .-enter-x:nth-child(5) {z-index:5;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.5s;}*> .enter-y:nth-child(5) {transform:translateY(50px);}*> .-enter-y:nth-child(5) {transform:translateY(-50px);}* > .enter-y:nth-child(5),* > .-enter-y:nth-child(5) {z-index:5;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.5s;}*> .enter-x:nth-child(6) {transform:translateX(50px);}*> .-enter-x:nth-child(6) {transform:translateX(-50px);}* > .enter-x:nth-child(6),* > .-enter-x:nth-child(6) {z-index:4;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.6s;}*> .enter-y:nth-child(6) {transform:translateY(50px);}*> .-enter-y:nth-child(6) {transform:translateY(-50px);}* > .enter-y:nth-child(6),* > .-enter-y:nth-child(6) {z-index:4;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.6s;}*> .enter-x:nth-child(7) {transform:translateX(50px);}*> .-enter-x:nth-child(7) {transform:translateX(-50px);}* > .enter-x:nth-child(7),* > .-enter-x:nth-child(7) {z-index:3;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.7s;}*> .enter-y:nth-child(7) {transform:translateY(50px);}*> .-enter-y:nth-child(7) {transform:translateY(-50px);}* > .enter-y:nth-child(7),* > .-enter-y:nth-child(7) {z-index:3;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.7s;}*> .enter-x:nth-child(8) {transform:translateX(50px);}*> .-enter-x:nth-child(8) {transform:translateX(-50px);}* > .enter-x:nth-child(8),* > .-enter-x:nth-child(8) {z-index:2;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.8s;}*> .enter-y:nth-child(8) {transform:translateY(50px);}*> .-enter-y:nth-child(8) {transform:translateY(-50px);}* > .enter-y:nth-child(8),* > .-enter-y:nth-child(8) {z-index:2;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.8s;}*> .enter-x:nth-child(9) {transform:translateX(50px);}*> .-enter-x:nth-child(9) {transform:translateX(-50px);}* > .enter-x:nth-child(9),* > .-enter-x:nth-child(9) {z-index:1;opacity:0;animation:enter-x-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.9s;}*> .enter-y:nth-child(9) {transform:translateY(50px);}*> .-enter-y:nth-child(9) {transform:translateY(-50px);}* > .enter-y:nth-child(9),* > .-enter-y:nth-child(9) {z-index:1;opacity:0;animation:enter-y-animation 0.4s ease-in-out 0.3s;animation-fill-mode:forwards;animation-delay:0.9s;}@keyframes enter-x-animation {to {opacity:1;transform:translateX(0);}}@keyframes enter-y-animation {to {opacity:1;transform:translateY(0);}}`
  26. }
  27. ]
  28. // preflights: [
  29. // {
  30. // getCSS: () => createEnterPlugin()
  31. // }
  32. // ]
  33. // transformers: [transformerDirectives()]
  34. // rules: [createEnterPlugin()]
  35. // variants: [createEnterPlugin()]
  36. })
  37. }
  38. export default createConfig()
  39. /**
  40. * Used for animation when the element is displayed
  41. * @param maxOutput The larger the maxOutput output, the larger the generated css volume
  42. */
  43. // function createEnterPlugin(maxOutput = 10): string {
  44. // const createCss = (index: number, d = 'x') => {
  45. // const upd = d.toUpperCase()
  46. // return {
  47. // [`*> .enter-${d}:nth-child(${index})`]: {
  48. // transform: `translate${upd}(50px)`
  49. // },
  50. // [`*> .-enter-${d}:nth-child(${index})`]: {
  51. // transform: `translate${upd}(-50px)`
  52. // },
  53. // [`* > .enter-${d}:nth-child(${index}),* > .-enter-${d}:nth-child(${index})`]: {
  54. // 'z-index': `${10 - index}`,
  55. // opacity: '0',
  56. // animation: `enter-${d}-animation 0.4s ease-in-out 0.3s`,
  57. // 'animation-fill-mode': 'forwards',
  58. // 'animation-delay': `${(index * 1) / 10}s`
  59. // }
  60. // }
  61. // }
  62. // const handler = () => {
  63. // const addRawCss = {}
  64. // for (let index = 1; index < maxOutput; index++) {
  65. // Object.assign(addRawCss, {
  66. // ...createCss(index, 'x'),
  67. // ...createCss(index, 'y')
  68. // })
  69. // }
  70. // const entriesToCss = (arr?: CSSEntries) => {
  71. // if (!arr) return ''
  72. // return clearIdenticalEntries(arr)
  73. // .map(([key, value]) => {
  74. // if (isObject(value)) {
  75. // return value !== null ? `${key} {${entriesToCss(normalizeCSSEntries(value))}}` : undefined
  76. // }
  77. // return value !== null ? `${key}:${value};` : undefined
  78. // })
  79. // .filter(Boolean)
  80. // .join('')
  81. // }
  82. // return entriesToCss(
  83. // normalizeCSSEntries({
  84. // ...addRawCss,
  85. // [`@keyframes enter-x-animation`]: {
  86. // to: {
  87. // opacity: '1',
  88. // transform: 'translateX(0)'
  89. // }
  90. // },
  91. // [`@keyframes enter-y-animation`]: {
  92. // to: {
  93. // opacity: '1',
  94. // transform: 'translateY(0)'
  95. // }
  96. // }
  97. // })
  98. // )
  99. // }
  100. // return handler()
  101. // }