MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / parseCssColorToRgba

Function parseCssColorToRgba

src/utils/snapCapture.ts:27–53  ·  view source on GitHub ↗
(color: string)

Source from the content-addressed store, hash-verified

25const colorProbeCtx = colorProbeCanvas.getContext('2d', { willReadFrequently: true })
26
27function parseCssColorToRgba(color: string): RgbaColor | null {
28 if (!colorProbeCtx) return null
29
30 const ctx = colorProbeCtx
31 ctx.clearRect(0, 0, 1, 1)
32
33 // 先写入完全透明作为基底,确保读取到 alpha 信息。
34 ctx.fillStyle = 'rgba(0, 0, 0, 0)'
35 ctx.fillRect(0, 0, 1, 1)
36
37 try {
38 ctx.fillStyle = color
39 } catch {
40 return null
41 }
42
43 ctx.fillRect(0, 0, 1, 1)
44 const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data
45 if (a === 0) return null
46
47 return {
48 r,
49 g,
50 b,
51 a: a / 255,
52 }
53}
54
55function compositeOver(top: RgbaColor, bottom: RgbaColor): RgbaColor {
56 const alpha = top.a + bottom.a * (1 - top.a)

Callers 1

getEffectiveBackgroundFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected