@hagicode/hagilight-starlight 0.6.0 → 0.6.1-dev.74.1.7df157f

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/README.md CHANGED
@@ -31,7 +31,11 @@ The plugin also exposes `@hagicode/hagilight-starlight/schema` for optional SEO
31
31
 
32
32
  ### Theme picker
33
33
 
34
- By default the plugin replaces Starlight's light/dark toggle with a theme picker offering nine choices: the default theme plus the Ocean, Sakura, and Forest themes in light and dark, and a "Default" choice that follows the visitor's system color scheme while a randomly assigned theme (stable per visitor, stored in `localStorage`) provides the palette. Disable it to keep Starlight's built-in toggle or compose `@hagicode/hagilight-starlight/ThemeSelect` yourself:
34
+ By default the plugin replaces Starlight's light/dark toggle with a theme picker offering nine choices: the default theme plus the Ocean, Sakura, and Forest themes in light and dark, and a "Default" choice that follows the visitor's system color scheme and renders the Forest theme. First-time visitors, and visitors with an invalid saved choice, therefore see Forest; the other themes appear only after an explicit selection, which is remembered in `localStorage`.
35
+
36
+ Earlier versions assigned each first-time visitor a random theme and stored it under `hagilight-theme-random`. That value is now ignored: returning visitors who never picked a theme explicitly see Forest after upgrading, while visitors with an explicit choice keep it.
37
+
38
+ Disable the picker to keep Starlight's built-in toggle or compose `@hagicode/hagilight-starlight/ThemeSelect` yourself:
35
39
 
36
40
  ```js
37
41
  hagilight({ themes: { enabled: false } })
package/dist/index.d.ts CHANGED
@@ -38,7 +38,8 @@ export interface HagilightThemesOptions {
38
38
  /**
39
39
  * Replace Starlight's light/dark picker with the Hagilight theme picker: four themes
40
40
  * (the default plus Ocean, Sakura, and Forest) in light and dark, plus a "default"
41
- * choice that assigns first-visit users one of the extra themes at random.
41
+ * choice that follows the system color scheme and renders the Forest theme, so
42
+ * first-visit users see Forest until they pick another theme.
42
43
  * Defaults to `true`.
43
44
  */
44
45
  enabled?: boolean;
@@ -56,7 +57,7 @@ export interface HagilightStarlightOptions {
56
57
  seo?: HagilightSeoOptions;
57
58
  contentComponents?: HagilightContentComponentsOptions;
58
59
  aiDisclosures?: HagilightAIDisclosureOptions;
59
- /** Theme picker with three extra light/dark themes plus a randomized first-visit default. */
60
+ /** Theme picker with three extra light/dark themes and a Forest first-visit default. */
60
61
  themes?: HagilightThemesOptions;
61
62
  /** End-of-article HagiCode introduction. */
62
63
  hagicodePromotion?: HagilightToggleOptions;
package/dist/themes.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Hagilight theme picker: four themes (the Starlight default plus Ocean, Sakura, and Forest),
3
- * each with a light and a dark appearance, plus a "default" choice that applies the site
4
- * default experience. The palette in use is exposed to CSS through the
3
+ * each with a light and a dark appearance, plus a "default" choice that follows the system
4
+ * color scheme and renders the Forest palette. The palette in use is exposed to CSS through the
5
5
  * `data-hagilight-theme` attribute on `<html>`; light/dark mode keeps using Starlight's
6
6
  * `data-theme` attribute and `starlight-theme` storage so Starlight's pre-paint script
7
7
  * continues to apply the correct mode.
@@ -9,12 +9,13 @@
9
9
  export type ThemeId = 'default' | 'ocean' | 'sakura' | 'forest';
10
10
  export type ThemeMode = 'light' | 'dark';
11
11
  export type ThemeChoice = 'default' | 'default-light' | 'default-dark' | 'ocean-light' | 'ocean-dark' | 'sakura-light' | 'sakura-dark' | 'forest-light' | 'forest-dark';
12
- /** Themes a first-visit user is randomly assigned while the "default" choice is selected. */
13
- export declare const RANDOM_THEME_IDS: readonly ["ocean", "sakura", "forest"];
12
+ /** Themes beyond the Starlight default; each must have light and dark palettes in `themes.css`. */
13
+ export declare const EXTRA_THEME_IDS: readonly ["ocean", "sakura", "forest"];
14
+ /** The palette the "default" choice renders, so first-visit users always see the same theme. */
15
+ export declare const DEFAULT_PALETTE_THEME_ID: Exclude<ThemeId, 'default'>;
14
16
  export declare const DEFAULT_THEME_CHOICE: ThemeChoice;
15
17
  export declare const THEME_CHOICES: readonly ["default", "default-light", "default-dark", "ocean-light", "ocean-dark", "sakura-light", "sakura-dark", "forest-light", "forest-dark"];
16
18
  export declare const THEME_STORAGE_KEY = "hagilight-theme";
17
- export declare const RANDOM_THEME_STORAGE_KEY = "hagilight-theme-random";
18
19
  /** Starlight's own storage key; kept in sync with the picker so its pre-paint script applies the right mode. */
19
20
  export declare const STARLIGHT_THEME_STORAGE_KEY = "starlight-theme";
20
21
  export declare function parseThemeChoice(value: unknown): ThemeChoice;
@@ -22,9 +23,7 @@ export declare function splitThemeChoice(choice: ThemeChoice): {
22
23
  themeId: ThemeId;
23
24
  mode?: ThemeMode;
24
25
  };
25
- /** The theme randomly assigned to this user, picking and persisting one on the first visit. */
26
- export declare function assignedRandomThemeId(): ThemeId;
27
- /** The theme id a choice renders as: the theme itself, or the user's random assignment for "default". */
26
+ /** The theme id a choice renders as: the theme itself, or the Forest palette for "default". */
28
27
  export declare function resolveThemeId(choice: ThemeChoice): ThemeId;
29
28
  export declare function readStoredThemeChoice(): ThemeChoice;
30
29
  /** Apply a choice to the document, persist it, and keep Starlight's mode storage in sync. */
@@ -35,7 +34,7 @@ export declare function applyThemeChoice(choice: ThemeChoice, root?: HTMLElement
35
34
  */
36
35
  export declare const THEME_BOOTSTRAP: string;
37
36
  export interface ThemePickerLabels {
38
- /** Label of the "default" choice: site default experience with an automatically assigned theme. */
37
+ /** Label of the "default" choice: follows the system color scheme and renders the Forest theme. */
39
38
  defaultOption: string;
40
39
  /** Label of the option group holding the built-in theme's light and dark appearances. */
41
40
  defaultThemeGroup: string;
package/dist/themes.js CHANGED
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * Hagilight theme picker: four themes (the Starlight default plus Ocean, Sakura, and Forest),
3
- * each with a light and a dark appearance, plus a "default" choice that applies the site
4
- * default experience. The palette in use is exposed to CSS through the
3
+ * each with a light and a dark appearance, plus a "default" choice that follows the system
4
+ * color scheme and renders the Forest palette. The palette in use is exposed to CSS through the
5
5
  * `data-hagilight-theme` attribute on `<html>`; light/dark mode keeps using Starlight's
6
6
  * `data-theme` attribute and `starlight-theme` storage so Starlight's pre-paint script
7
7
  * continues to apply the correct mode.
8
8
  */
9
- /** Themes a first-visit user is randomly assigned while the "default" choice is selected. */
10
- export const RANDOM_THEME_IDS = ['ocean', 'sakura', 'forest'];
9
+ /** Themes beyond the Starlight default; each must have light and dark palettes in `themes.css`. */
10
+ export const EXTRA_THEME_IDS = ['ocean', 'sakura', 'forest'];
11
+ /** The palette the "default" choice renders, so first-visit users always see the same theme. */
12
+ export const DEFAULT_PALETTE_THEME_ID = 'forest';
11
13
  export const DEFAULT_THEME_CHOICE = 'default';
12
14
  export const THEME_CHOICES = [
13
15
  'default',
@@ -21,10 +23,8 @@ export const THEME_CHOICES = [
21
23
  'forest-dark',
22
24
  ];
23
25
  export const THEME_STORAGE_KEY = 'hagilight-theme';
24
- export const RANDOM_THEME_STORAGE_KEY = 'hagilight-theme-random';
25
26
  /** Starlight's own storage key; kept in sync with the picker so its pre-paint script applies the right mode. */
26
27
  export const STARLIGHT_THEME_STORAGE_KEY = 'starlight-theme';
27
- const RANDOM_THEME_ID_SET = new Set(RANDOM_THEME_IDS);
28
28
  const THEME_CHOICE_SET = new Set(THEME_CHOICES);
29
29
  export function parseThemeChoice(value) {
30
30
  return THEME_CHOICE_SET.has(value) ? value : DEFAULT_THEME_CHOICE;
@@ -54,19 +54,10 @@ function writeStorage(key, value) {
54
54
  return;
55
55
  }
56
56
  }
57
- /** The theme randomly assigned to this user, picking and persisting one on the first visit. */
58
- export function assignedRandomThemeId() {
59
- let stored = readStorage(RANDOM_THEME_STORAGE_KEY);
60
- if (stored === null || !RANDOM_THEME_ID_SET.has(stored)) {
61
- stored = RANDOM_THEME_IDS[Math.floor(Math.random() * RANDOM_THEME_IDS.length)];
62
- writeStorage(RANDOM_THEME_STORAGE_KEY, stored);
63
- }
64
- return stored;
65
- }
66
- /** The theme id a choice renders as: the theme itself, or the user's random assignment for "default". */
57
+ /** The theme id a choice renders as: the theme itself, or the Forest palette for "default". */
67
58
  export function resolveThemeId(choice) {
68
59
  const { themeId, mode } = splitThemeChoice(choice);
69
- return mode === undefined ? assignedRandomThemeId() : themeId;
60
+ return mode === undefined ? DEFAULT_PALETTE_THEME_ID : themeId;
70
61
  }
71
62
  export function readStoredThemeChoice() {
72
63
  return parseThemeChoice(readStorage(THEME_STORAGE_KEY));
@@ -86,31 +77,15 @@ export function applyThemeChoice(choice, root = document.documentElement) {
86
77
  */
87
78
  export const THEME_BOOTSTRAP = `(function () {
88
79
  var choices = ${JSON.stringify(THEME_CHOICES)};
89
- var randomThemes = ${JSON.stringify(RANDOM_THEME_IDS)};
90
80
  var choiceKey = ${JSON.stringify(THEME_STORAGE_KEY)};
91
- var randomKey = ${JSON.stringify(RANDOM_THEME_STORAGE_KEY)};
92
81
  var choice = 'default';
93
82
  try {
94
83
  var stored = localStorage.getItem(choiceKey);
95
84
  if (choices.includes(stored)) choice = stored;
96
85
  } catch (error) {}
97
- var themeId;
98
- if (choice === 'default') {
99
- try {
100
- themeId = localStorage.getItem(randomKey);
101
- if (!randomThemes.includes(themeId)) themeId = null;
102
- } catch (error) {
103
- themeId = null;
104
- }
105
- if (!themeId) {
106
- themeId = randomThemes[Math.floor(Math.random() * randomThemes.length)];
107
- try {
108
- localStorage.setItem(randomKey, themeId);
109
- } catch (error) {}
110
- }
111
- } else {
112
- themeId = choice.slice(0, choice.lastIndexOf('-'));
113
- }
86
+ var themeId = choice === 'default'
87
+ ? ${JSON.stringify(DEFAULT_PALETTE_THEME_ID)}
88
+ : choice.slice(0, choice.lastIndexOf('-'));
114
89
  document.documentElement.dataset.hagilightTheme = themeId;
115
90
  })();`;
116
91
  const labels = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight-starlight",
3
- "version": "0.6.0",
3
+ "version": "0.6.1-dev.74.1.7df157f",
4
4
  "type": "module",
5
5
  "description": "Starlight plugin and components for HagiCode documentation",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "assets/showcase/*"
54
54
  ],
55
55
  "dependencies": {
56
- "@hagicode/hagilight-core": "0.6.0"
56
+ "@hagicode/hagilight-core": "0.6.1-dev.74.1.7df157f"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@astrojs/starlight": "^0.42.4",