You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
9.7 KiB

3 months ago
  1. {"ast":null,"code":"import { getCurrentInstance, inject, ref, computed, unref } from 'vue';\nconst defaultNamespace = \"el\";\nconst statePrefix = \"is-\";\nconst _bem = (namespace, block, blockSuffix, element, modifier) => {\n let cls = `${namespace}-${block}`;\n if (blockSuffix) {\n cls += `-${blockSuffix}`;\n }\n if (element) {\n cls += `__${element}`;\n }\n if (modifier) {\n cls += `--${modifier}`;\n }\n return cls;\n};\nconst namespaceContextKey = Symbol(\"namespaceContextKey\");\nconst useGetDerivedNamespace = namespaceOverrides => {\n const derivedNamespace = namespaceOverrides || (getCurrentInstance() ? inject(namespaceContextKey, ref(defaultNamespace)) : ref(defaultNamespace));\n const namespace = computed(() => {\n return unref(derivedNamespace) || defaultNamespace;\n });\n return namespace;\n};\nconst useNamespace = (block, namespaceOverrides) => {\n const namespace = useGetDerivedNamespace(namespaceOverrides);\n const b = (blockSuffix = \"\") => _bem(namespace.value, block, blockSuffix, \"\", \"\");\n const e = element => element ? _bem(namespace.value, block, \"\", element, \"\") : \"\";\n const m = modifier => modifier ? _bem(namespace.value, block, \"\", \"\", modifier) : \"\";\n const be = (blockSuffix, element) => blockSuffix && element ? _bem(namespace.value, block, blockSuffix, element, \"\") : \"\";\n const em = (element, modifier) => element && modifier ? _bem(namespace.value, block, \"\", element, modifier) : \"\";\n const bm = (blockSuffix, modifier) => blockSuffix && modifier ? _bem(namespace.value, block, blockSuffix, \"\", modifier) : \"\";\n const bem = (blockSuffix, element, modifier) => blockSuffix && element && modifier ? _bem(namespace.value, block, blockSuffix, element, modifier) : \"\";\n const is = (name, ...args) => {\n const state = args.length >= 1 ? args[0] : true;\n return name && state ? `${statePrefix}${name}` : \"\";\n };\n const cssVar = object => {\n const styles = {};\n for (const key in object) {\n if (object[key]) {\n styles[`--${namespace.value}-${key}`] = object[key];\n }\n }\n return styles;\n };\n const cssVarBlock = object => {\n const styles = {};\n for (const key in object) {\n if (object[key]) {\n styles[`--${namespace.value}-${block}-${key}`] = object[key];\n }\n }\n return styles;\n };\n const cssVarName = name => `--${namespace.value}-${name}`;\n const cssVarBlockName = name => `--${namespace.value}-${block}-${name}`;\n return {\n namespace,\n b,\n e,\n m,\n be,\n em,\n bm,\n bem,\n is,\n cssVar,\n cssVarName,\n cssVarBlock,\n cssVarBlockName\n };\n};\nexport { defaultNamespace, namespaceContextKey, useGetDerivedNamespace, useNamespace };","map":{"version":3,"names":["defaultNamespace","statePrefix","_bem","namespace","block","blockSuffix","element","modifier","cls","namespaceContextKey","Symbol","useGetDerivedNamespace","namespaceOverrides","derivedNamespace","getCurrentInstance","inject","ref","computed","unref","useNamespace","b","value","e","m","be","em","bm","bem","is","name","args","state","length","cssVar","object","styles","key","cssVarBlock","cssVarName","cssVarBlockName"],"sources":["../../../../../packages/hooks/use-namespace/index.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, ref, unref } from 'vue'\n\nimport type { InjectionKey, Ref } from 'vue'\n\nexport const defaultNamespace = 'el'\nconst statePrefix = 'is-'\n\nconst _bem = (\n namespace: string,\n block: string,\n blockSuffix: string,\n element: string,\n modifier: string\n) => {\n let cls = `${namespace}-${block}`\n if (blockSuffix) {\n cls += `-${blockSuffix}`\n }\n if (element) {\n cls += `__${element}`\n }\n if (modifier) {\n cls += `--${modifier}`\n }\n return cls\n}\n\nexport const namespaceContextKey: InjectionKey<Ref<string | undefined>> =\n Symbol('namespaceContextKey')\n\nexport const useGetDerivedNamespace = (\n namespaceOverrides?: Ref<string | undefined>\n) => {\n const derivedNamespace =\n