@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovrozagar/flare",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Solid meta-framework. Server-driven, NDJSON streaming, renderToStream.",
5
5
  "keywords": [
6
6
  "flare",
@@ -8,9 +8,15 @@ function escapeAttr(str: string): string {
8
8
  return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
9
9
  }
10
10
 
11
- function colorSchemeCss(attribute: string): string {
12
- const attr = attribute.replace(/[^\w-]/g, "") || "data-theme";
13
- return `html{color-scheme:light}html[${attr}=dark]{color-scheme:dark}`;
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(themeAttr)}</style>`;
52
+ prefix += `<style${nonceAttr}>${colorSchemeCss(options.theme)}</style>`;
48
53
 
49
54
  if (options.direction) {
50
55
  prefix += `<script${nonceAttr}>${getDirectionScript(options.direction)}</script>`;