Home

tailwind-ctp-intellisense @c4e301871fb75f35eb48c47b3e67df68af1bcfeb - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-service / src / 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
import { State } from './state'
import { combinations } from './combinations'
import dlv from '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, '__info', '__rule']) ===
      true ||
      Array.isArray(dlv(state.classNames.classNames, [className, '__info']))
      ? [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, '__info', '__rule']) === true ||
      Array.isArray(dlv(state.classNames.classNames, [...key, '__info']))
    ) {
      return true
    }
    return false
  })
}