@lovrozagar/flare 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ssr/head-prefix.ts +10 -5
package/package.json
CHANGED
package/src/ssr/head-prefix.ts
CHANGED
|
@@ -8,9 +8,15 @@ function escapeAttr(str: string): string {
|
|
|
8
8
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/*
|
|
12
|
+
* The scheme before the theme script runs, or without JavaScript: the default theme, where
|
|
13
|
+
* "system" is the OS preference (`light dark`). Once the script sets the attribute, it wins.
|
|
14
|
+
*/
|
|
15
|
+
function colorSchemeCss(theme: ThemeConfig | undefined): string {
|
|
16
|
+
const attr = (theme?.attribute ?? "data-theme").replace(/[^\w-]/g, "") || "data-theme";
|
|
17
|
+
const fallback =
|
|
18
|
+
theme?.defaultTheme === "light" || theme?.defaultTheme === "dark" ? theme.defaultTheme : "light dark";
|
|
19
|
+
return `html{color-scheme:${fallback}}html[${attr}=light]{color-scheme:light}html[${attr}=dark]{color-scheme:dark}`;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
export interface HeadPrefixOptions {
|
|
@@ -42,9 +48,8 @@ export function buildHeadPrefix(options: HeadPrefixOptions): string {
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
const nonceAttr = ` nonce="${escapedNonce}"`;
|
|
45
|
-
const themeAttr = options.theme?.attribute ?? "data-theme";
|
|
46
51
|
prefix += `<script${nonceAttr}>${getThemeScript(options.theme)}</script>`;
|
|
47
|
-
prefix += `<style${nonceAttr}>${colorSchemeCss(
|
|
52
|
+
prefix += `<style${nonceAttr}>${colorSchemeCss(options.theme)}</style>`;
|
|
48
53
|
|
|
49
54
|
if (options.direction) {
|
|
50
55
|
prefix += `<script${nonceAttr}>${getDirectionScript(options.direction)}</script>`;
|