Move background colour auto-detect script to where the other webpack files are

This commit is contained in:
Emma Winston
2019-09-18 21:26:33 +01:00
parent 20e17e496f
commit ec0a3e232d
3 changed files with 2 additions and 3 deletions

View File

@ -15,7 +15,6 @@ import { changeComposing } from '../../actions/compose';
import defaultmascotlight from '../../../images/defaultmascotlight.svg';
import defaultmascotdark from '../../../images/defaultmascotdark.svg';
import { mascot } from '../../initial_state';
import {svgSelect} from './util/svg_select';
import Icon from 'mastodon/components/icon';
const messages = defineMessages({
@ -38,7 +37,7 @@ let instanceMascot;
if (mascot) {
instanceMascot = <img alt='' draggable='false' src={mascot} />;
} else {
instanceMascot = <img alt='' draggable='false' className="defaultmascot" src={svgSelect(defaultmascotlight, defaultmascotdark)} />;
instanceMascot = <img alt='' draggable='false' className="defaultmascot" src={defaultmascotdark} />;
}
export default @connect(mapStateToProps)

View File

@ -1,21 +0,0 @@
export function svgSelect(light, dark) {
var svgbg = window.getComputedStyle(document.getElementsByClassName("drawer__inner")[0], null).getPropertyValue("background-color");
var rgbArray = ((svgbg.replace(/[^0-9,]/g, "")).split(",")).map(Number).map(x => x/255);
for ( var i = 0; i < rgbArray.length; ++i ) {
if ( rgbArray[i] <= 0.03928 ) {
rgbArray[i] = rgbArray[i] / 12.92
} else {
rgbArray[i] = Math.pow( ( rgbArray[i] + 0.055 ) / 1.055, 2.4);
}
}
var luminance = 0.2126 * rgbArray[0] + 0.7152 * rgbArray[1] + 0.0722 * rgbArray[2];
if ( luminance <= 0.179 ) {
return light;
} else {
return dark;
}
}