unocss.config.ts

dc37a0812a9971107e75ecfdb141c3d5bf0289fc
wotaku/unocss.config.ts history · blame · raw

159 lines · 4165 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'
 21import { LANG_FLAG_FALLBACK, LANG_FLAG_ICONS } from './docs/.vitepress/configs/markdown/langFlags'
 22
 23const iconPrefixes = [
 24  'octicon-',
 25  'logos-',
 26  'ic-',
 27  'mingcute-',
 28  'mdi-',
 29  'material-symbols-',
 30  'simple-icons-',
 31  'lucide-',
 32  'uil-',
 33  'akar-icons-',
 34  'map-',
 35  'bi-',
 36  'streamline-logos-',
 37  'streamline-ultimate-',
 38  'streamline-sharp-',
 39  'iconoir-'
 40]
 41
 42const emojiShortcodeExtractor = {
 43  name: 'emoji-shortcode',
 44  extract({ code }: { code: string }) {
 45    const tokens = new Set<string>()
 46    for (const [, markup] of code.matchAll(/:([A-Za-z0-9_+-]+):/g)) {
 47      if (aliases[markup]) {
 48        tokens.add(`i-${aliases[markup]}`)
 49      } else if (iconPrefixes.some((p) => markup.startsWith(p))) {
 50        tokens.add(`i-${markup}`)
 51      }
 52    }
 53    return tokens
 54  }
 55}
 56
 57// Custom icons collection
 58const customIcons = {
 59  circle:
 60    '<svg viewBox="0 0 120 120"><circle cx="60" cy="60" r="50"></circle></svg>'
 61  // Add more custom icons here as needed
 62}
 63
 64const safelist = [
 65  ...Object.entries(colors).flatMap(([group, shades]) =>
 66    Object.keys(shades).flatMap((shade) => [
 67      `text-${group}-${shade}`,
 68      `bg-${group}-${shade}`
 69    ])
 70  ),
 71  'i-lucide:circle-plus',
 72  'i-lucide:circle-alert',
 73  'i-lucide:circle-x',
 74  'i-lucide:lightbulb',
 75  'i-lucide:heart',
 76  'i-lucide:message-circle',
 77  'i-lucide:copy',
 78  'i-lucide:check',
 79  'i-lucide:settings',
 80  'i-lucide:download',
 81  'i-lucide:chevron-down',
 82  'i-lucide:search',
 83  'i-lucide:languages',
 84  'i-lucide:shield',
 85  'i-twemoji-no-one-under-eighteen',
 86  ...Array.from(new Set([...Object.values(LANG_FLAG_ICONS), LANG_FLAG_FALLBACK])).map(
 87    (icon) => `i-twemoji-${icon}`
 88  )
 89]
 90
 91export default defineConfig({
 92  content: {
 93    filesystem: ['.vitepress/configs/constants.ts', 'docs/index.md']
 94  },
 95  extractors: [emojiShortcodeExtractor],
 96  safelist,
 97  theme: {
 98    easing: {
 99      'out-expo': 'cubic-bezier(0.16, 1, 0.3, 1)',
100      'in-expo': 'cubic-bezier(0.7, 0, 0.84, 0)'
101    },
102    colors: {
103      ...colors,
104      primary: 'var(--vp-c-brand-1)',
105      bg: 'var(--vp-c-bg)',
106      'bg-alt': 'var(--vp-c-bg-alt)',
107      'bg-elv': 'var(--vp-c-bg-elv)',
108      text: 'var(--vp-c-text-1)',
109      'text-2': 'var(--vp-c-text-2)',
110      div: 'var(--vp-c-divider)',
111      // Ayanami Blue
112      'brand': {
113        '50': 'oklch(0.965 0.011 256.71)',
114        '100': 'oklch(0.93 0.024 256.1)',
115        '200': 'oklch(0.861 0.048 253.25)',
116        '300': 'oklch(0.791 0.076 251.19)',
117        '400': 'oklch(0.722 0.105 247.48)',
118        '500': 'oklch(0.626 0.098 247.46)',
119        '600': 'oklch(0.523 0.081 246.86)',
120        '700': 'oklch(0.43 0.066 246.75)',
121        '800': 'oklch(0.335 0.052 246.76)',
122        '900': 'oklch(0.233 0.035 246.39)',
123        '950': 'oklch(0.186 0.029 247.31)'
124      }
125    }
126  },
127  presets: [
128    presetWind4({
129      preflights: {
130        theme: true
131      }
132    }),
133    presetAttributify(),
134    presetWebFonts({
135      fonts: {
136        serif: 'Source Serif 4 Variable',
137        pacifico: {
138          name: 'Pacifico',
139          weights: [400],
140          italic: true
141        }
142      }
143    }),
144    presetIcons({
145      scale: 1.2,
146      extraProperties: {
147        display: 'inline-block',
148        'vertical-align': '-0.125em', // changed from 'middle'
149        'min-width': '1.2rem'
150      },
151      warn: false,
152      collections: {
153        custom: FileSystemIconLoader(resolve(__dirname, 'docs/public/custom')),
154        inline: customIcons
155      }
156    })
157  ],
158  transformers: [transformerDirectives()]
159})