unocss.config.ts

9c6588973e856dbc27ebb283f0d963c792faa8df
wotaku/unocss.config.ts history · blame · raw

149 lines · 3787 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  'i-lucide:settings'
 79]
 80
 81export default defineConfig({
 82  content: {
 83    filesystem: ['.vitepress/configs/constants.ts', 'docs/index.md']
 84  },
 85  extractors: [emojiShortcodeExtractor],
 86  safelist,
 87  theme: {
 88    easing: {
 89      'out-expo': 'cubic-bezier(0.16, 1, 0.3, 1)',
 90      'in-expo': 'cubic-bezier(0.7, 0, 0.84, 0)'
 91    },
 92    colors: {
 93      ...colors,
 94      primary: 'var(--vp-c-brand-1)',
 95      bg: 'var(--vp-c-bg)',
 96      'bg-alt': 'var(--vp-c-bg-alt)',
 97      'bg-elv': 'var(--vp-c-bg-elv)',
 98      text: 'var(--vp-c-text-1)',
 99      'text-2': 'var(--vp-c-text-2)',
100      div: 'var(--vp-c-divider)',
101      // Ayanami Blue
102      'brand': {
103        '50': 'oklch(0.965 0.011 256.71)',
104        '100': 'oklch(0.93 0.024 256.1)',
105        '200': 'oklch(0.861 0.048 253.25)',
106        '300': 'oklch(0.791 0.076 251.19)',
107        '400': 'oklch(0.722 0.105 247.48)',
108        '500': 'oklch(0.626 0.098 247.46)',
109        '600': 'oklch(0.523 0.081 246.86)',
110        '700': 'oklch(0.43 0.066 246.75)',
111        '800': 'oklch(0.335 0.052 246.76)',
112        '900': 'oklch(0.233 0.035 246.39)',
113        '950': 'oklch(0.186 0.029 247.31)'
114      }
115    }
116  },
117  presets: [
118    presetWind4({
119      preflights: {
120        theme: true
121      }
122    }),
123    presetAttributify(),
124    presetWebFonts({
125      fonts: {
126        serif: 'Source Serif 4 Variable',
127        pacifico: {
128          name: 'Pacifico',
129          weights: [400],
130          italic: true
131        }
132      }
133    }),
134    presetIcons({
135      scale: 1.2,
136      extraProperties: {
137        display: 'inline-block',
138        'vertical-align': '-0.125em', // changed from 'middle'
139        'min-width': '1.2rem'
140      },
141      warn: false,
142      collections: {
143        custom: FileSystemIconLoader(resolve(__dirname, 'docs/public/custom')),
144        inline: customIcons
145      }
146    })
147  ],
148  transformers: [transformerDirectives()]
149})