uno.config.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import type { Theme } from 'unocss/preset-uno'
  2. import { entriesToCss } from '@unocss/core'
  3. import presetLegacyCompat from '@unocss/preset-legacy-compat'
  4. import {
  5. defineConfig,
  6. presetAttributify,
  7. presetIcons,
  8. presetTypography,
  9. presetWind3,
  10. transformerCompileClass,
  11. transformerDirectives,
  12. transformerVariantGroup,
  13. } from 'unocss'
  14. import { presetAnimations } from 'unocss-preset-animations'
  15. import { darkTheme, lightTheme } from './themes'
  16. export default defineConfig<Theme>({
  17. content: {
  18. pipeline: {
  19. include: [
  20. /\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/,
  21. 'src/**/*.{js,ts}',
  22. ],
  23. },
  24. },
  25. shortcuts: [
  26. [/^flex-?(col)?-(start|end|center|baseline|stretch)-?(start|end|center|between|around|evenly|left|right)?$/, ([, col, items, justify]) => {
  27. const cls = ['flex']
  28. if (col === 'col') {
  29. cls.push('flex-col')
  30. }
  31. if (items === 'center' && !justify) {
  32. cls.push('items-center')
  33. cls.push('justify-center')
  34. }
  35. else {
  36. cls.push(`items-${items}`)
  37. if (justify) {
  38. cls.push(`justify-${justify}`)
  39. }
  40. }
  41. return cls.join(' ')
  42. }],
  43. ],
  44. presets: [
  45. presetWind3(),
  46. presetAnimations(),
  47. presetAttributify(),
  48. presetIcons({
  49. extraProperties: {
  50. 'display': 'inline-block',
  51. 'vertical-align': 'middle',
  52. },
  53. }),
  54. presetTypography(),
  55. presetLegacyCompat({
  56. legacyColorSpace: true,
  57. }),
  58. {
  59. name: 'unocss-preset-shadcn',
  60. preflights: [
  61. {
  62. getCSS: () => {
  63. const returnCss: any = []
  64. // 明亮主题
  65. const lightCss = entriesToCss(Object.entries(lightTheme))
  66. returnCss.push(`:root{${lightCss}}`)
  67. // 暗黑主题
  68. const darkCss = entriesToCss(Object.entries(darkTheme))
  69. returnCss.push(`html.dark{${darkCss}}`)
  70. return `
  71. ${returnCss.join('\n')}
  72. * {
  73. border-color: hsl(var(--border));
  74. }
  75. body {
  76. color: hsl(var(--foreground));
  77. background: hsl(var(--background));
  78. }
  79. `
  80. },
  81. },
  82. ],
  83. theme: {
  84. colors: {
  85. border: 'hsl(var(--border))',
  86. input: 'hsl(var(--input))',
  87. ring: 'hsl(var(--ring))',
  88. background: 'hsl(var(--background))',
  89. foreground: 'hsl(var(--foreground))',
  90. primary: {
  91. DEFAULT: 'hsl(var(--primary))',
  92. foreground: 'hsl(var(--primary-foreground))',
  93. },
  94. secondary: {
  95. DEFAULT: 'hsl(var(--secondary))',
  96. foreground: 'hsl(var(--secondary-foreground))',
  97. },
  98. destructive: {
  99. DEFAULT: 'hsl(var(--destructive))',
  100. foreground: 'hsl(var(--destructive-foreground))',
  101. },
  102. muted: {
  103. DEFAULT: 'hsl(var(--muted))',
  104. foreground: 'hsl(var(--muted-foreground))',
  105. },
  106. accent: {
  107. DEFAULT: 'hsl(var(--accent))',
  108. foreground: 'hsl(var(--accent-foreground))',
  109. },
  110. popover: {
  111. DEFAULT: 'hsl(var(--popover))',
  112. foreground: 'hsl(var(--popover-foreground))',
  113. },
  114. card: {
  115. DEFAULT: 'hsl(var(--card))',
  116. foreground: 'hsl(var(--card-foreground))',
  117. },
  118. },
  119. borderRadius: {
  120. xl: 'calc(var(--radius) + 4px)',
  121. lg: 'var(--radius)',
  122. md: 'calc(var(--radius) - 2px)',
  123. sm: 'calc(var(--radius) - 4px)',
  124. },
  125. },
  126. },
  127. ],
  128. transformers: [
  129. transformerDirectives(),
  130. transformerVariantGroup(),
  131. transformerCompileClass(),
  132. ],
  133. configDeps: [
  134. 'themes/index.ts',
  135. ],
  136. })