pinafore/src/routes/_utils/convertCssPropertyToDataUrl.js
Nolan Lawson 8c6a701d6f
fix: ensure "disable blurhash" setting is honored (#1422)
* fix: ensure "disable blurhash" setting is honored

fixes #1421

* remove play button for audio/video
2019-08-22 09:09:21 -07:00

23 lines
559 B
JavaScript

const colorsToUrls = new Map()
let canvas
let context
export function convertCssPropertyToDataUrl (prop) {
const color = getComputedStyle(document.documentElement).getPropertyValue(prop)
let url = colorsToUrls.get(color)
if (!url) {
if (!canvas) {
canvas = document.createElement('canvas')
canvas.width = 1
canvas.height = 1
context = canvas.getContext('2d')
}
context.fillStyle = color
context.rect(0, 0, 1, 1)
context.fill()
url = canvas.toDataURL()
colorsToUrls.set(color, url)
}
return url
}