Skip to content

Commit 33a6082

Browse files
committed
drop support for older browsers
1 parent 7fff0e5 commit 33a6082

File tree

1 file changed

+25
-51
lines changed

1 file changed

+25
-51
lines changed

lib/support/Chart.ts

+25-51
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,32 @@
99
import FileSaver from 'file-saver'
1010
import html2canvas from 'html2canvas'
1111

12-
const isLightDarkSupported
13-
= typeof CSS !== 'undefined' && CSS.supports('color', 'light-dark(#000, #fff)')
14-
1512
export const c = {
16-
text1: isLightDarkSupported ? 'light-dark(#1c2024, #edeef0)' : 'var(--c-text-1)',
17-
text2: isLightDarkSupported ? 'light-dark(#0007149e, #eff5ffb0)' : 'var(--c-text-2)',
18-
divider: isLightDarkSupported ? 'light-dark(#e0e0e1, #2e3035)' : 'var(--c-divider)'
19-
}
20-
21-
const c_light = {
22-
text1: '#1c2024',
23-
text2: '#0007149e',
24-
divider: '#e0e0e1'
13+
text1: 'light-dark(#1c2024, #edeef0)',
14+
text2: 'light-dark(#0007149e, #eff5ffb0)',
15+
divider: 'light-dark(#e0e0e1, #2e3035)'
2516
}
2617

2718
// radixLight.9, radixDark.10
2819
export const chartColors = {
29-
// orange: isLightDarkSupported ? 'light-dark(#f76b15, #ff801f)' : '#f76b15',
30-
tomato: isLightDarkSupported ? 'light-dark(#e54d2e, #ec6142)' : '#e54d2e',
31-
// red: isLightDarkSupported ? 'light-dark(#e5484d, #ec5d5e)' : '#e5484d',
32-
ruby: isLightDarkSupported ? 'light-dark(#e54666, #ec5a72)' : '#e54666',
33-
// crimson: isLightDarkSupported ? 'light-dark(#e93d82, #ee518a)' : '#e93d82',
34-
pink: isLightDarkSupported ? 'light-dark(#d6409f, #de51a8)' : '#d6409f',
35-
// plum: isLightDarkSupported ? 'light-dark(#ab4aba, #b658c4)' : '#ab4aba',
36-
purple: isLightDarkSupported ? 'light-dark(#8e4ec6, #9a5cd0)' : '#8e4ec6',
37-
// violet: isLightDarkSupported ? 'light-dark(#6e56cf, #7d66d9)' : '#6e56cf',
38-
iris: isLightDarkSupported ? 'light-dark(#5b5bd6, #6e6ade)' : '#5b5bd6',
39-
// indigo: isLightDarkSupported ? 'light-dark(#3e63dd, #5472e4)' : '#3e63dd',
40-
blue: isLightDarkSupported ? 'light-dark(#0090ff, #3b9eff)' : '#0090ff',
41-
// cyan: isLightDarkSupported ? 'light-dark(#00a2c7, #23afd0)' : '#00a2c7',
42-
teal: isLightDarkSupported ? 'light-dark(#12a594, #0eb39e)' : '#12a594',
43-
// jade: isLightDarkSupported ? 'light-dark(#29a383, #27b08b)' : '#29a383',
44-
green: isLightDarkSupported ? 'light-dark(#30a46c, #33b074)' : '#30a46c',
45-
// grass: isLightDarkSupported ? 'light-dark(#46a758, #53b365)' : '#46a758',
46-
gray: isLightDarkSupported ? 'light-dark(#8d8d8d, #7b7b7b)' : '#8d8d8d'
20+
// orange: 'light-dark(#f76b15, #ff801f)',
21+
tomato: 'light-dark(#e54d2e, #ec6142)',
22+
// red: 'light-dark(#e5484d, #ec5d5e)',
23+
ruby: 'light-dark(#e54666, #ec5a72)',
24+
// crimson: 'light-dark(#e93d82, #ee518a)',
25+
pink: 'light-dark(#d6409f, #de51a8)',
26+
// plum: 'light-dark(#ab4aba, #b658c4)',
27+
purple: 'light-dark(#8e4ec6, #9a5cd0)',
28+
// violet: 'light-dark(#6e56cf, #7d66d9)',
29+
iris: 'light-dark(#5b5bd6, #6e6ade)',
30+
// indigo: 'light-dark(#3e63dd, #5472e4)',
31+
blue: 'light-dark(#0090ff, #3b9eff)',
32+
// cyan: 'light-dark(#00a2c7, #23afd0)',
33+
teal: 'light-dark(#12a594, #0eb39e)',
34+
// jade: 'light-dark(#29a383, #27b08b)',
35+
green: 'light-dark(#30a46c, #33b074)',
36+
// grass: 'light-dark(#46a758, #53b365)',
37+
gray: 'light-dark(#8d8d8d, #7b7b7b)'
4738
} as const
4839

4940
// eslint-disable-next-line @typescript-eslint/ban-types
@@ -97,31 +88,14 @@ export async function exportAsPng(_el: any, fileName = 'chart.png', delay = 0):
9788
ignoreElements: (el) => el.classList.contains('SControlActionBar'),
9889
onclone(document, element) {
9990
document.documentElement.classList.remove('dark')
100-
for (const el of element.querySelectorAll<HTMLElement>('*')) {
91+
element.querySelectorAll<HTMLElement>('*').forEach((el) => {
10192
el.style.backgroundColor = 'transparent'
102-
for (const [key, value] of Object.entries(c)) {
103-
for (const attr of ['fill', 'stroke'] as const) {
104-
if (el.getAttribute(attr) === value) {
105-
el.style[attr] = c_light[key as keyof typeof c_light]
106-
}
107-
}
108-
}
109-
}
93+
el.style.fill = el.getAttribute('fill') ?? el.style.fill
94+
el.style.stroke = el.getAttribute('stroke') ?? el.style.stroke
95+
})
11096
}
11197
})
11298

113-
// // for debugging
114-
// const blob = await new Promise<Blob>((resolve) => {
115-
// canvas.toBlob((b) => {
116-
// if (b) {
117-
// resolve(b)
118-
// } else {
119-
// resolve(new Blob())
120-
// }
121-
// }, 'image/png')
122-
// })
123-
// window.open(URL.createObjectURL(blob), '_blank')
124-
12599
const dataUrl = canvas.toDataURL('image/png')
126100
FileSaver.saveAs(dataUrl, fileName)
127101
}

0 commit comments

Comments
 (0)