unocss.config.ts

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

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