Add dark mode
This commit is contained in:
parent
48a55a4a97
commit
073f087e52
40 changed files with 864 additions and 531 deletions
9
src/framework/helper/dark-mode.ts
Normal file
9
src/framework/helper/dark-mode.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export const isSystemLevelDarkModeEnabled = (): boolean =>
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
|
||||
export const turnOnDarkMode = () =>
|
||||
document.body.parentElement.setAttribute('theme', 'dark');
|
||||
|
||||
export const turnOnLightMode = () =>
|
||||
document.body.parentElement.setAttribute('theme', 'light');
|
||||
|
|
@ -20,16 +20,12 @@ export const mixColors = (
|
|||
|
||||
const hexToRGB = (hex: hex): rgb => {
|
||||
const [r1, r2, g1, g2, b1, b2] = normalizeHex(hex);
|
||||
return [
|
||||
Number.parseInt(r1 + r2, 16),
|
||||
Number.parseInt(g1 + g2, 16),
|
||||
Number.parseInt(b1 + b2, 16),
|
||||
];
|
||||
return [parseInt(r1 + r2, 16), parseInt(g1 + g2, 16), parseInt(b1 + b2, 16)];
|
||||
};
|
||||
|
||||
const normalizeHex = (hex: hex): hex => {
|
||||
hex = hex.trim();
|
||||
if (hex.startsWith('#')) {
|
||||
if (hex[0] === '#') {
|
||||
hex = hex.substr(1);
|
||||
}
|
||||
return hex;
|
||||
|
|
@ -38,4 +34,4 @@ const normalizeHex = (hex: hex): hex => {
|
|||
const mix = (a: number, b: number, q: number): number => a * q + b * (1 - q);
|
||||
|
||||
const rgbToHex = (rgb: rgb): hex =>
|
||||
'#' + rgb.map(n => Math.round(n).toString(16)).join('');
|
||||
'#' + rgb.map(n => (n < 16 ? '0' : '') + Math.round(n).toString(16)).join('');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import { addImul } from '../polyfills';
|
||||
|
||||
export class Random {
|
||||
public constructor(private seed: number) {}
|
||||
public constructor(private seed: number) {
|
||||
addImul();
|
||||
}
|
||||
|
||||
public get next(): number {
|
||||
// result is in [0, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue