util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getTargetWaveColor = getTargetWaveColor;
  6. exports.isNotGrey = isNotGrey;
  7. exports.isValidWaveColor = isValidWaveColor;
  8. function isNotGrey(color) {
  9. // eslint-disable-next-line no-useless-escape
  10. const match = (color || '').match(/rgba?\((\d*), (\d*), (\d*)(, [\d.]*)?\)/);
  11. if (match && match[1] && match[2] && match[3]) {
  12. return !(match[1] === match[2] && match[2] === match[3]);
  13. }
  14. return true;
  15. }
  16. function isValidWaveColor(color) {
  17. return color && color !== '#fff' && color !== '#ffffff' && color !== 'rgb(255, 255, 255)' && color !== 'rgba(255, 255, 255, 1)' && isNotGrey(color) && !/rgba\((?:\d*, ){3}0\)/.test(color) &&
  18. // any transparent rgba color
  19. color !== 'transparent';
  20. }
  21. function getTargetWaveColor(node) {
  22. const {
  23. borderTopColor,
  24. borderColor,
  25. backgroundColor
  26. } = getComputedStyle(node);
  27. if (isValidWaveColor(borderTopColor)) {
  28. return borderTopColor;
  29. }
  30. if (isValidWaveColor(borderColor)) {
  31. return borderColor;
  32. }
  33. if (isValidWaveColor(backgroundColor)) {
  34. return backgroundColor;
  35. }
  36. return null;
  37. }