util.js 964 B

123456789101112131415161718192021222324252627282930
  1. export function isNotGrey(color) {
  2. // eslint-disable-next-line no-useless-escape
  3. const match = (color || '').match(/rgba?\((\d*), (\d*), (\d*)(, [\d.]*)?\)/);
  4. if (match && match[1] && match[2] && match[3]) {
  5. return !(match[1] === match[2] && match[2] === match[3]);
  6. }
  7. return true;
  8. }
  9. export function isValidWaveColor(color) {
  10. 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) &&
  11. // any transparent rgba color
  12. color !== 'transparent';
  13. }
  14. export function getTargetWaveColor(node) {
  15. const {
  16. borderTopColor,
  17. borderColor,
  18. backgroundColor
  19. } = getComputedStyle(node);
  20. if (isValidWaveColor(borderTopColor)) {
  21. return borderTopColor;
  22. }
  23. if (isValidWaveColor(borderColor)) {
  24. return borderColor;
  25. }
  26. if (isValidWaveColor(backgroundColor)) {
  27. return backgroundColor;
  28. }
  29. return null;
  30. }