Home

tailwind-ctp-intellisense @03e16a4ac0640fb8d5403dd15130d80c1940b3bc - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / src / lsp / util / getClassNameAtPosition.ts
- 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 { State } from './state'
const dlv = require('dlv')

export function getClassNameParts(state: State, className: string): string[] {
  let separator = state.separator
  className = className.replace(/^\./, '')
  let parts: string[] = className.split(separator)

  if (parts.length === 1) {
    return dlv(state.classNames.classNames, [className, '__rule']) === true ||
      Array.isArray(dlv(state.classNames.classNames, [className]))
      ? [className]
      : null
  }

  let points = combinations('123456789'.substr(0, parts.length - 1)).map((x) =>
    x.split('').map((x) => parseInt(x, 10))
  )

  let possibilities: string[][] = [
    [className],
    ...points.map((p) => {
      let result = []
      let i = 0
      p.forEach((x) => {
        result.push(parts.slice(i, x).join('-'))
        i = x
      })
      result.push(parts.slice(i).join('-'))
      return result
    }),
  ]

  return possibilities.find((key) => {
    if (
      dlv(state.classNames.classNames, [...key, '__rule']) === true ||
      Array.isArray(dlv(state.classNames.classNames, [...key]))
    ) {
      return true
    }
    return false
  })
}

function combinations(str: string): string[] {
  let fn = function (active: string, rest: string, a: string[]) {
    if (!active && !rest) return
    if (!rest) {
      a.push(active)
    } else {
      fn(active + rest[0], rest.slice(1), a)
      fn(active, rest.slice(1), a)
    }
    return a
  }
  return fn('', str, [])
}