This commit is contained in:
2026-01-28 22:37:27 +03:00
parent cbaa1cda9d
commit 53ca63ec91
64 changed files with 4375 additions and 2980 deletions

40
src/utils/colors.ts Normal file
View File

@@ -0,0 +1,40 @@
import { colors } from 'quasar'
function getColorWithOpacity(
color: string,
background: string = '#ffffff',
alpha: number = 0.8
): string {
const clampedAlpha = Math.max(0.01, Math.min(1, alpha))
const hexColor = color.startsWith('#') ? color : colors.getPaletteColor(color)
const hexBackground = background.startsWith('#') ? background : colors.getPaletteColor(background)
if (!hexColor || !hexColor.startsWith('#') || !hexBackground || !hexBackground.startsWith('#')) {
return color
}
const { r: rColor, g: gColor, b: bColor } = colors.hexToRgb(hexColor)
const { r: rBg, g: gBg, b: bBg } = colors.hexToRgb(hexBackground)
const calculateTargetChannel = (colorChannel: number, bgChannel: number): number => {
const target = (colorChannel - bgChannel * (1 - clampedAlpha)) / clampedAlpha
return Math.max(0, Math.min(255, Math.round(target)))
}
const targetChannels = [
calculateTargetChannel(rColor, rBg),
calculateTargetChannel(gColor, gBg),
calculateTargetChannel(bColor, bBg)
]
if (targetChannels.every(channel => channel === 0)) {
return `rgba(${rColor}, ${gColor}, ${bColor}, ${clampedAlpha})`
}
return `rgba(${targetChannels.join(', ')}, ${clampedAlpha})`
}
export {
getColorWithOpacity
}