Home

tailwind-ctp-intellisense @3836cbf2a56469510e1066b56ed7f03df34fb475 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / src / class-names / getUtilityConfigMap.js
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { runPlugin } from './runPlugin'
import { getBuiltInPlugins } from './getPlugins'
import { isObject } from './isObject'

const proxyHandler = (base = []) => ({
  get(target, key) {
    if (isObject(target[key])) {
      return new Proxy(target[key], proxyHandler([...base, key]))
    } else {
      if (
        [...base, key].every((x) => typeof x === 'string') &&
        target.hasOwnProperty(key)
      ) {
        return '$dep$' + [...base, key].join('.')
      }
      return target[key]
    }
  },
})

export async function getUtilityConfigMap({ cwd, resolvedConfig, postcss }) {
  const builtInPlugins = await getBuiltInPlugins({ cwd, resolvedConfig })
  const userPlugins = Array.isArray(resolvedConfig.plugins)
    ? resolvedConfig.plugins
    : []

  try {
    const classNameConfigMap = {}
    const proxiedConfig = new Proxy(resolvedConfig, proxyHandler())

    ;[...builtInPlugins, ...userPlugins].forEach((plugin) => {
      runPlugin(plugin, {
        postcss,
        config: proxiedConfig,
        addUtilities: (utilities) => {
          Object.keys(utilities).forEach((util) => {
            let props = Object.keys(utilities[util])
            if (
              props.length === 1 &&
              /^\.[^\s]+$/.test(util) &&
              typeof utilities[util][props[0]] === 'string' &&
              utilities[util][props[0]].substr(0, 5) === '$dep$'
            ) {
              classNameConfigMap[util.substr(1)] = utilities[util][
                props[0]
              ].substr(5)
            }
          })
        },
      })
    })

    return classNameConfigMap
  } catch (_) {
    return {}
  }
}