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

Function getEffectiveBackground

src/utils/snapCapture.ts:73–96  ·  view source on GitHub ↗
(el: HTMLElement | null)

Source from the content-addressed store, hash-verified

71}
72
73function getEffectiveBackground(el: HTMLElement | null): string {
74 const fallbackBackground: RgbaColor = { r: 17, g: 17, b: 17, a: 1 }
75
76 let node: HTMLElement | null = el
77 let blended: RgbaColor | null = null
78
79 while (node) {
80 const bg = window.getComputedStyle(node).backgroundColor
81 const parsed = parseCssColorToRgba(bg)
82 if (parsed && parsed.a > 0) {
83 blended = blended ? compositeOver(blended, parsed) : parsed
84 if (blended.a >= 0.999) {
85 return toOpaqueRgbString(blended)
86 }
87 }
88 node = node.parentElement
89 }
90
91 if (!blended) {
92 return toOpaqueRgbString(fallbackBackground)
93 }
94
95 return toOpaqueRgbString(compositeOver(blended, fallbackBackground))
96}
97
98function triggerDownload(href: string, filename: string) {
99 const a = document.createElement('a')

Callers 2

captureAsImageDataFunction · 0.85
captureAndDownloadPngFunction · 0.85

Calls 3

parseCssColorToRgbaFunction · 0.85
compositeOverFunction · 0.85
toOpaqueRgbStringFunction · 0.85

Tested by

no test coverage detected