unocss.config.ts

5f20afcddd9bf446affeb450596a58cc0fe7e4ca
wotaku/unocss.config.ts history · blame · raw

148 lines · 3764 bytes

  1/**
  2 *  All Rights Reserved
  3 *
  4 *  Copyright (c) 2025 taskylizard
  5 *
  6 *  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
  7 */
  8import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
  9import { colors } from '@taskylizard/colors'
 10import { resolve } from 'node:path'
 11import {
 12  defineConfig,
 13  presetAttributify,
 14  presetIcons,
 15  presetUno,
 16  presetWebFonts,
 17  presetWind4,
 18  transformerDirectives
 19} from 'unocss'
 20import { aliases } from './docs/.vitepress/configs/markdown/emoji'
 21
 22const iconPrefixes = [
 23  'octicon-',
 24  'logos-',
 25  'ic-',
 26  'mingcute-',
 27  'mdi-',
 28  'material-symbols-',
 29  'simple-icons-',
 30  'lucide-',
 31  'uil-',
 32  'akar-icons-',
 33  'map-',
 34  'bi-',
 35  'streamline-logos-',
 36  'streamline-ultimate-',
 37  'streamline-sharp-',
 38  'iconoir-'
 39]
 40
 41const emojiShortcodeExtractor = {
 42  name: 'emoji-shortcode',
 43  extract({ code }: { code: string }) {
 44    const tokens = new Set<string>()
 45    for (const [, markup] of code.matchAll(/:([A-Za-z0-9_+-]+):/g)) {
 46      if (aliases[markup]) {
 47        tokens.add(`i-${aliases[markup]}`)
 48      } else if (iconPrefixes.some((p) => markup.startsWith(p))) {
 49        tokens.add(`i-${markup}`)
 50      }
 51    }
 52    return tokens
 53  }
 54}
 55
 56// Custom icons collection
 57const customIcons = {
 58  circle:
 59    '<svg viewBox="0 0 120 120"><circle cx="60" cy="60" r="50"></circle></svg>'
 60  // Add more custom icons here as needed
 61}
 62
 63const safelist = [
 64  ...Object.entries(colors).flatMap(([group, shades]) =>
 65    Object.keys(shades).flatMap((shade) => [
 66      `text-${group}-${shade}`,
 67      `bg-${group}-${shade}`
 68    ])
 69  ),
 70  'i-lucide:circle-plus',
 71  'i-lucide:circle-alert',
 72  'i-lucide:circle-x',
 73  'i-lucide:lightbulb',
 74  'i-lucide:heart',
 75  'i-lucide:message-circle',
 76  'i-lucide:copy',
 77  'i-lucide:check'
 78]
 79
 80export default defineConfig({
 81  content: {
 82    filesystem: ['.vitepress/configs/constants.ts', 'docs/index.md']
 83  },
 84  extractors: [emojiShortcodeExtractor],
 85  safelist,
 86  theme: {
 87    easing: {
 88      'out-expo': 'cubic-bezier(0.16, 1, 0.3, 1)',
 89      'in-expo': 'cubic-bezier(0.7, 0, 0.84, 0)'
 90    },
 91    colors: {
 92      ...colors,
 93      primary: 'var(--vp-c-brand-1)',
 94      bg: 'var(--vp-c-bg)',
 95      'bg-alt': 'var(--vp-c-bg-alt)',
 96      'bg-elv': 'var(--vp-c-bg-elv)',
 97      text: 'var(--vp-c-text-1)',
 98      'text-2': 'var(--vp-c-text-2)',
 99      div: 'var(--vp-c-divider)',
100      // Ayanami Blue
101      'brand': {
102        '50': 'oklch(0.965 0.011 256.71)',
103        '100': 'oklch(0.93 0.024 256.1)',
104        '200': 'oklch(0.861 0.048 253.25)',
105        '300': 'oklch(0.791 0.076 251.19)',
106        '400': 'oklch(0.722 0.105 247.48)',
107        '500': 'oklch(0.626 0.098 247.46)',
108        '600': 'oklch(0.523 0.081 246.86)',
109        '700': 'oklch(0.43 0.066 246.75)',
110        '800': 'oklch(0.335 0.052 246.76)',
111        '900': 'oklch(0.233 0.035 246.39)',
112        '950': 'oklch(0.186 0.029 247.31)'
113      }
114    }
115  },
116  presets: [
117    presetWind4({
118      preflights: {
119        theme: true
120      }
121    }),
122    presetAttributify(),
123    presetWebFonts({
124      fonts: {
125        serif: 'Source Serif 4 Variable',
126        pacifico: {
127          name: 'Pacifico',
128          weights: [400],
129          italic: true
130        }
131      }
132    }),
133    presetIcons({
134      scale: 1.2,
135      extraProperties: {
136        display: 'inline-block',
137        'vertical-align': '-0.125em', // changed from 'middle'
138        'min-width': '1.2rem'
139      },
140      warn: false,
141      collections: {
142        custom: FileSystemIconLoader(resolve(__dirname, 'docs/public/custom')),
143        inline: customIcons
144      }
145    })
146  ],
147  transformers: [transformerDirectives()]
148})