forked from Myriad-Dreamin/tinymist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
160 lines (149 loc) · 6.14 KB
/
Copy pathindex.html
File metadata and controls
160 lines (149 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- https://github.com/darkreader/darkreader/blob/main/CONTRIBUTING.md#disabling-dark-reader-on-your-site -->
<meta name="darkreader-lock" />
<title>Editor Tools</title>
<style id="preview-theme-styles"></style>
</head>
<body
style="
padding: 0;
margin: 0;
height: fit-content;
width: 100%;
background-color: var(--typst-preview-background-color, #888) !important;
"
>
<script>
{
/// https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js
function deltaE(rgbA, rgbB) {
let labA = rgb2lab(rgbA);
let labB = rgb2lab(rgbB);
let deltaL = labA[0] - labB[0];
let deltaA = labA[1] - labB[1];
let deltaB = labA[2] - labB[2];
let c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
let c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
let deltaC = c1 - c2;
let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
let sc = 1.0 + 0.045 * c1;
let sh = 1.0 + 0.015 * c1;
let deltaLKlsl = deltaL / 1.0;
let deltaCkcsc = deltaC / sc;
let deltaHkhsh = deltaH / sh;
let i =
deltaLKlsl * deltaLKlsl +
deltaCkcsc * deltaCkcsc +
deltaHkhsh * deltaHkhsh;
return i < 0 ? 0 : Math.sqrt(i);
}
function rgb2lab(rgb) {
let r = rgb[0] / 255,
g = rgb[1] / 255,
b = rgb[2] / 255,
x,
y,
z;
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.0;
z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
}
// https://stackoverflow.com/questions/26414770/getting-the-rgb-values-for-a-css-html-named-color-in-javascript
function cssColorToRgba(cssColor) {
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
context.fillStyle = cssColor;
context.fillRect(0, 0, 1, 1);
return context.getImageData(0, 0, 1, 1).data;
}
const themeKind = document.body?.getAttribute("data-vscode-theme-kind");
const serverDark =
themeKind === "vscode-dark" ||
(typeof acquireVsCodeApi === "undefined" &&
window.matchMedia?.("(prefers-color-scheme: dark)").matches);
const defaultDarkBackgroundColor = "rgb(17, 17, 17)";
const defaultLightBackgroundColor = "rgb(255, 255, 255)";
const defaultBackgroundColor = serverDark
? defaultDarkBackgroundColor
: defaultLightBackgroundColor;
const defaultToolbarDarkFgColor = "#fff";
const defaultToolbarLightFgColor = "#000";
const defaultToolbarFgColor = serverDark
? defaultToolbarDarkFgColor
: defaultToolbarLightFgColor;
let previewBackgroundColor =
getComputedStyle(document.documentElement).getPropertyValue(
"--vscode-sideBar-background"
) || defaultBackgroundColor;
let previewToolbarFgColor =
getComputedStyle(document.documentElement).getPropertyValue(
"--vscode-menu-foreground"
) || defaultToolbarFgColor;
let preferColorScheme = "dark";
/// Perceptible distance between colors:
/// 0~1: cannot distinguish by human eyes
/// 1~2: perceptible through close observation
/// 2~10: perceptible at a glance
if (
deltaE(cssColorToRgba(previewBackgroundColor), [255, 255, 255]) < 5
) {
previewBackgroundColor = defaultLightBackgroundColor;
previewToolbarFgColor = defaultToolbarLightFgColor;
preferColorScheme = "light";
}
document.documentElement.style.colorScheme = preferColorScheme;
let previewForegroundColor = previewToolbarFgColor;
const defaultToolbarBorderColor = "rgba(0, 0, 0, 0)";
const previewToolbarBorderColor =
getComputedStyle(document.documentElement).getPropertyValue(
"--vscode-menu-border"
) || defaultToolbarBorderColor;
const defaultToolbarBgColor = "rgb(50, 54, 57)";
const previewToolbarBgColor =
getComputedStyle(document.documentElement).getPropertyValue(
"--vscode-menu-background"
) || defaultToolbarBgColor;
if (serverDark) {
document.body.classList.add("typst-preview-dark");
} else {
document.body.classList.add("typst-preview-light");
}
// append css variable --typst-preview-background-color
document.documentElement.style.setProperty(
"--typst-preview-background-color",
previewBackgroundColor
);
document.documentElement.style.setProperty(
"--typst-preview-foreground-color",
previewForegroundColor
);
document.documentElement.style.setProperty(
"--typst-preview-toolbar-fg-color",
previewToolbarFgColor
);
document.documentElement.style.setProperty(
"--typst-preview-toolbar-border-color",
previewToolbarBorderColor
);
document.documentElement.style.setProperty(
"--typst-preview-toolbar-bg-color",
previewToolbarBgColor
);
}
</script>
<script type="module" src="%VITE_ENTRY%"></script>
<div id="tinymist-app"></div>
</body>
</html>