mirror of
https://github.com/flarum/core.git
synced 2025-08-07 08:56:38 +02:00
refactor: change getContrast to isDark with for a more direct approach
This commit is contained in:
@@ -33,7 +33,7 @@ import formatNumber from './utils/formatNumber';
|
|||||||
import mapRoutes from './utils/mapRoutes';
|
import mapRoutes from './utils/mapRoutes';
|
||||||
import withAttr from './utils/withAttr';
|
import withAttr from './utils/withAttr';
|
||||||
import * as FocusTrap from './utils/focusTrap';
|
import * as FocusTrap from './utils/focusTrap';
|
||||||
import getContrast from './utils/getContrast';
|
import isDark from './utils/isDark';
|
||||||
import Notification from './models/Notification';
|
import Notification from './models/Notification';
|
||||||
import User from './models/User';
|
import User from './models/User';
|
||||||
import Post from './models/Post';
|
import Post from './models/Post';
|
||||||
@@ -121,7 +121,7 @@ export default {
|
|||||||
'utils/throttleDebounce': ThrottleDebounce,
|
'utils/throttleDebounce': ThrottleDebounce,
|
||||||
'utils/isObject': isObject,
|
'utils/isObject': isObject,
|
||||||
'utils/focusTrap': FocusTrap,
|
'utils/focusTrap': FocusTrap,
|
||||||
'utils/getContrast': getContrast,
|
'utils/isDark': isDark,
|
||||||
'models/Notification': Notification,
|
'models/Notification': Notification,
|
||||||
'models/User': User,
|
'models/User': User,
|
||||||
'models/Post': Post,
|
'models/Post': Post,
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
* light?) See https://www.w3.org/TR/AERT/#color-contrast for references
|
* light?) See https://www.w3.org/TR/AERT/#color-contrast for references
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default function getContrast(hexcolor: String) {
|
export default function isDark(hexcolor: String) {
|
||||||
|
|
||||||
var hexnumbers = hexcolor.replace("#", "");
|
var hexnumbers = hexcolor.replace("#", "");
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export default function getContrast(hexcolor: String) {
|
|||||||
const r = parseInt(hexnumbers.substr(0,2),16);
|
const r = parseInt(hexnumbers.substr(0,2),16);
|
||||||
const g = parseInt(hexnumbers.substr(2,2),16);
|
const g = parseInt(hexnumbers.substr(2,2),16);
|
||||||
const b = parseInt(hexnumbers.substr(4,2),16);
|
const b = parseInt(hexnumbers.substr(4,2),16);
|
||||||
const contrast = ((r*299)+(g*587)+(b*114))/1000;
|
const yiq = ((r*299)+(g*587)+(b*114))/1000;
|
||||||
|
|
||||||
return contrast;
|
return (yiq >= 128) ? false : true;
|
||||||
}
|
}
|
Reference in New Issue
Block a user