pleroma-fe/src/services/user_highlighter/user_highlighter.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

import { hex2rgb } from '../color_convert/color_convert.js'
2026-01-06 16:23:17 +02:00
const highlightStyle = (prefs) => {
if (prefs === undefined) return
2019-07-05 10:02:14 +03:00
const { color, type } = prefs
if (typeof color !== 'string') return
const rgb = hex2rgb(color)
if (rgb == null) return
const solidColor = `rgb(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)})`
const tintColor = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .1)`
const tintColor2 = `rgba(${Math.floor(rgb.r)}, ${Math.floor(rgb.g)}, ${Math.floor(rgb.b)}, .2)`
2021-06-07 23:42:04 +03:00
const customProps = {
'--____highlight-solidColor': solidColor,
'--____highlight-tintColor': tintColor,
2026-01-06 16:22:52 +02:00
'--____highlight-tintColor2': tintColor2,
2021-06-07 23:42:04 +03:00
}
if (type === 'striped') {
return {
backgroundImage: [
'repeating-linear-gradient(135deg,',
`${tintColor} ,`,
`${tintColor} 20px,`,
`${tintColor2} 20px,`,
2026-01-06 16:22:52 +02:00
`${tintColor2} 40px`,
].join(' '),
2021-06-07 23:42:04 +03:00
backgroundPosition: '0 0',
2026-01-06 16:22:52 +02:00
...customProps,
}
} else if (type === 'solid') {
return {
2021-06-07 23:42:04 +03:00
backgroundColor: tintColor2,
2026-01-06 16:22:52 +02:00
...customProps,
}
} else if (type === 'side') {
return {
backgroundImage: [
'linear-gradient(to right,',
`${solidColor} ,`,
`${solidColor} 2px,`,
2026-01-06 16:22:52 +02:00
'transparent 6px',
].join(' '),
2021-06-07 23:42:04 +03:00
backgroundPosition: '0 0',
2026-01-06 16:22:52 +02:00
...customProps,
}
}
}
const highlightClass = (user) => {
2026-01-06 16:22:52 +02:00
return (
'USER____' + user.screen_name?.replace(/\./g, '_').replace(/@/g, '_AT_')
)
}
2026-01-06 16:22:52 +02:00
export { highlightClass, highlightStyle }