logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

user_highlighter.js (1573B)


  1. import { hex2rgb } from '../color_convert/color_convert.js'
  2. const highlightStyle = (prefs) => {
  3. if (prefs === undefined) return
  4. const { color, type } = prefs
  5. if (typeof color !== 'string') return
  6. const rgb = hex2rgb(color)
  7. if (rgb == null) return
  8. const solidColor = `rgb(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)})`
  9. const tintColor = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .1)`
  10. const tintColor2 = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .2)`
  11. const customProps = {
  12. '--____highlight-solidColor': solidColor,
  13. '--____highlight-tintColor': tintColor,
  14. '--____highlight-tintColor2': tintColor2
  15. }
  16. if (type === 'striped') {
  17. return {
  18. backgroundImage: [
  19. 'repeating-linear-gradient(135deg,',
  20. `${tintColor} ,`,
  21. `${tintColor} 20px,`,
  22. `${tintColor2} 20px,`,
  23. `${tintColor2} 40px`
  24. ].join(' '),
  25. backgroundPosition: '0 0',
  26. ...customProps
  27. }
  28. } else if (type === 'solid') {
  29. return {
  30. backgroundColor: tintColor2,
  31. ...customProps
  32. }
  33. } else if (type === 'side') {
  34. return {
  35. backgroundImage: [
  36. 'linear-gradient(to right,',
  37. `${solidColor} ,`,
  38. `${solidColor} 2px,`,
  39. 'transparent 6px'
  40. ].join(' '),
  41. backgroundPosition: '0 0',
  42. ...customProps
  43. }
  44. }
  45. }
  46. const highlightClass = (user) => {
  47. return 'USER____' + user.screen_name
  48. .replace(/\./g, '_')
  49. .replace(/@/g, '_AT_')
  50. }
  51. export {
  52. highlightClass,
  53. highlightStyle
  54. }