Skip to content

Commit ba3daae

Browse files
committed
Show current color in favicon
1 parent 55b10ab commit ba3daae

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ declare module '*?worker' {
1111
export default worker
1212
}
1313

14+
declare module '*.svg?url' {
15+
let image: string
16+
export default image
17+
}
18+
1419
declare const COLOR_FN: 'lch' | 'oklch'
1520
declare const LCH: boolean
1621
declare const L_MAX: number

view/base/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { formatLch } from '../../lib/colors.ts'
12
import { isHotkey } from '../../lib/hotkeys.ts'
23
import { accent } from '../../stores/accent.ts'
4+
import { current, valueToColor } from '../../stores/current.ts'
35
import { redo, undo } from '../../stores/history.ts'
46
import { loading } from '../../stores/loading.ts'
7+
import simpleLogo from './simple.svg?url'
58

69
// The only way to detect Mac is using old API
710
// eslint-disable-next-line @typescript-eslint/no-deprecated
@@ -35,3 +38,16 @@ document.body.addEventListener('keydown', e => {
3538
undo()
3639
}
3740
})
41+
42+
if (COLOR_FN === 'oklch') {
43+
let iconLink = document.querySelector<HTMLLinkElement>(
44+
'link[rel="icon"][type="image/svg+xml"]'
45+
)
46+
current.subscribe(value => {
47+
let colorLogo = simpleLogo.replace('%23000', formatLch(valueToColor(value)))
48+
if (value.l > 0.9) {
49+
colorLogo = colorLogo.replace('%23fff', '%23000')
50+
}
51+
iconLink?.setAttribute('href', colorLogo)
52+
})
53+
}

view/base/simple.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)