| 2 | import { EMPTY_OBJ } from '@vue/shared' |
| 3 | |
| 4 | export function useCssModule(name = '$style'): Record<string, string> { |
| 5 | if (!__GLOBAL__) { |
| 6 | const instance = getCurrentInstance()! |
| 7 | if (!instance) { |
| 8 | __DEV__ && warn(`useCssModule must be called inside setup()`) |
| 9 | return EMPTY_OBJ |
| 10 | } |
| 11 | const modules = instance.type.__cssModules |
| 12 | if (!modules) { |
| 13 | __DEV__ && warn(`Current instance does not have CSS modules injected.`) |
| 14 | return EMPTY_OBJ |
| 15 | } |
| 16 | const mod = modules[name] |
| 17 | if (!mod) { |
| 18 | __DEV__ && |
| 19 | warn(`Current instance does not have CSS module named "${name}".`) |
| 20 | return EMPTY_OBJ |
| 21 | } |
| 22 | return mod as Record<string, string> |
| 23 | } else { |
| 24 | /* v8 ignore start */ |
| 25 | if (__DEV__) { |
| 26 | warn(`useCssModule() is not supported in the global build.`) |
| 27 | } |
| 28 | return EMPTY_OBJ |
| 29 | /* v8 ignore stop */ |
| 30 | } |
| 31 | } |