90c52b8c291c629ac87d1de984b2372b6be0d7d7304a3ad8eed49c98377597820b6dfb873824b19d8c08a0677095f1cf5b946d39ededd325967b99e22e7a95 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var types = require('../types.js');
  4. var core = require('@vueuse/core');
  5. var shared = require('@vue/shared');
  6. var objects = require('../objects.js');
  7. const classNameToArray = (cls = "") => cls.split(" ").filter((item) => !!item.trim());
  8. const hasClass = (el, cls) => {
  9. if (!el || !cls)
  10. return false;
  11. if (cls.includes(" "))
  12. throw new Error("className should not contain space.");
  13. return el.classList.contains(cls);
  14. };
  15. const addClass = (el, cls) => {
  16. if (!el || !cls.trim())
  17. return;
  18. el.classList.add(...classNameToArray(cls));
  19. };
  20. const removeClass = (el, cls) => {
  21. if (!el || !cls.trim())
  22. return;
  23. el.classList.remove(...classNameToArray(cls));
  24. };
  25. const getStyle = (element, styleName) => {
  26. var _a;
  27. if (!core.isClient || !element || !styleName)
  28. return "";
  29. let key = shared.camelize(styleName);
  30. if (key === "float")
  31. key = "cssFloat";
  32. try {
  33. const style = element.style[key];
  34. if (style)
  35. return style;
  36. const computed = (_a = document.defaultView) == null ? void 0 : _a.getComputedStyle(element, "");
  37. return computed ? computed[key] : "";
  38. } catch (e) {
  39. return element.style[key];
  40. }
  41. };
  42. const setStyle = (element, styleName, value) => {
  43. if (!element || !styleName)
  44. return;
  45. if (shared.isObject(styleName)) {
  46. objects.entriesOf(styleName).forEach(([prop, value2]) => setStyle(element, prop, value2));
  47. } else {
  48. const key = shared.camelize(styleName);
  49. element.style[key] = value;
  50. }
  51. };
  52. const removeStyle = (element, style) => {
  53. if (!element || !style)
  54. return;
  55. if (shared.isObject(style)) {
  56. objects.keysOf(style).forEach((prop) => removeStyle(element, prop));
  57. } else {
  58. setStyle(element, style, "");
  59. }
  60. };
  61. function addUnit(value, defaultUnit = "px") {
  62. if (!value)
  63. return "";
  64. if (types.isNumber(value) || types.isStringNumber(value)) {
  65. return `${value}${defaultUnit}`;
  66. } else if (shared.isString(value)) {
  67. return value;
  68. }
  69. }
  70. exports.addClass = addClass;
  71. exports.addUnit = addUnit;
  72. exports.classNameToArray = classNameToArray;
  73. exports.getStyle = getStyle;
  74. exports.hasClass = hasClass;
  75. exports.removeClass = removeClass;
  76. exports.removeStyle = removeStyle;
  77. exports.setStyle = setStyle;
  78. //# sourceMappingURL=style.js.map