index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. const defaultNamespace = "el";
  5. const statePrefix = "is-";
  6. const _bem = (namespace, block, blockSuffix, element, modifier) => {
  7. let cls = `${namespace}-${block}`;
  8. if (blockSuffix) {
  9. cls += `-${blockSuffix}`;
  10. }
  11. if (element) {
  12. cls += `__${element}`;
  13. }
  14. if (modifier) {
  15. cls += `--${modifier}`;
  16. }
  17. return cls;
  18. };
  19. const namespaceContextKey = Symbol("namespaceContextKey");
  20. const useGetDerivedNamespace = (namespaceOverrides) => {
  21. const derivedNamespace = namespaceOverrides || (vue.getCurrentInstance() ? vue.inject(namespaceContextKey, vue.ref(defaultNamespace)) : vue.ref(defaultNamespace));
  22. const namespace = vue.computed(() => {
  23. return vue.unref(derivedNamespace) || defaultNamespace;
  24. });
  25. return namespace;
  26. };
  27. const useNamespace = (block, namespaceOverrides) => {
  28. const namespace = useGetDerivedNamespace(namespaceOverrides);
  29. const b = (blockSuffix = "") => _bem(namespace.value, block, blockSuffix, "", "");
  30. const e = (element) => element ? _bem(namespace.value, block, "", element, "") : "";
  31. const m = (modifier) => modifier ? _bem(namespace.value, block, "", "", modifier) : "";
  32. const be = (blockSuffix, element) => blockSuffix && element ? _bem(namespace.value, block, blockSuffix, element, "") : "";
  33. const em = (element, modifier) => element && modifier ? _bem(namespace.value, block, "", element, modifier) : "";
  34. const bm = (blockSuffix, modifier) => blockSuffix && modifier ? _bem(namespace.value, block, blockSuffix, "", modifier) : "";
  35. const bem = (blockSuffix, element, modifier) => blockSuffix && element && modifier ? _bem(namespace.value, block, blockSuffix, element, modifier) : "";
  36. const is = (name, ...args) => {
  37. const state = args.length >= 1 ? args[0] : true;
  38. return name && state ? `${statePrefix}${name}` : "";
  39. };
  40. const cssVar = (object) => {
  41. const styles = {};
  42. for (const key in object) {
  43. if (object[key]) {
  44. styles[`--${namespace.value}-${key}`] = object[key];
  45. }
  46. }
  47. return styles;
  48. };
  49. const cssVarBlock = (object) => {
  50. const styles = {};
  51. for (const key in object) {
  52. if (object[key]) {
  53. styles[`--${namespace.value}-${block}-${key}`] = object[key];
  54. }
  55. }
  56. return styles;
  57. };
  58. const cssVarName = (name) => `--${namespace.value}-${name}`;
  59. const cssVarBlockName = (name) => `--${namespace.value}-${block}-${name}`;
  60. return {
  61. namespace,
  62. b,
  63. e,
  64. m,
  65. be,
  66. em,
  67. bm,
  68. bem,
  69. is,
  70. cssVar,
  71. cssVarName,
  72. cssVarBlock,
  73. cssVarBlockName
  74. };
  75. };
  76. exports.defaultNamespace = defaultNamespace;
  77. exports.namespaceContextKey = namespaceContextKey;
  78. exports.useGetDerivedNamespace = useGetDerivedNamespace;
  79. exports.useNamespace = useNamespace;
  80. //# sourceMappingURL=index.js.map