Home

tailwind-ctp-intellisense @6d88a5c31c4b0fb1532b64e157295ca20773cb68 - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tailwind-ctp-intellisense / packages / tailwindcss-language-service / src / util / getVariantsFromClassName.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
import { State } from './state'

export function getVariantsFromClassName(
  state: State,
  className: string
): { variants: string[]; offset: number } {
  let str = className
  let allVariants = Object.keys(state.variants)
  let allVariantsByLength = allVariants.sort((a, b) => b.length - a.length)
  let variants = new Set<string>()
  let offset = 0

  while (str) {
    let found = false
    for (let variant of allVariantsByLength) {
      if (str.startsWith(variant + state.separator)) {
        variants.add(variant)
        str = str.substr(variant.length + state.separator.length)
        offset += variant.length + state.separator.length
        found = true
        break
      }
    }
    if (!found) str = ''
  }

  return { variants: Array.from(variants), offset }
}