@nyxwire/starlight 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +221 -2
- package/dist/config.d.ts +9 -0
- package/dist/config.js +32 -0
- package/dist/docs/foundations/accessibility.md +71 -0
- package/dist/docs/foundations/color-roles.md +114 -0
- package/dist/docs/foundations/effects-motion.md +150 -0
- package/dist/docs/foundations/flavors.md +156 -0
- package/dist/docs/foundations/icons.md +45 -0
- package/dist/docs/foundations/palette.md +180 -0
- package/dist/docs/foundations/spacing-elevation.md +168 -0
- package/dist/docs/foundations/typography.md +80 -0
- package/dist/docs/index.md +51 -0
- package/dist/docs/kitchen-sink.md +283 -0
- package/dist/docs/manifest.json +61 -0
- package/dist/docs/setup.md +190 -0
- package/dist/ec-themes.d.ts +443 -0
- package/dist/ec-themes.js +217 -0
- package/dist/expressive-code.d.ts +75 -0
- package/dist/expressive-code.js +101 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +25 -0
- package/dist/options.d.ts +29 -0
- package/dist/options.js +56 -0
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.js +52 -0
- package/dist/theme-bridge.d.ts +27 -0
- package/dist/theme-bridge.js +73 -0
- package/package.json +67 -3
- package/src/chrome.css +191 -0
- package/src/components/ThemeProvider.astro +15 -0
- package/src/components/ThemeSelect.astro +51 -0
- package/src/components/env.d.ts +5 -0
- package/src/config.ts +53 -0
- package/src/content-components.css +154 -0
- package/src/ec-themes.ts +246 -0
- package/src/expressive-code.ts +115 -0
- package/src/index.ts +32 -0
- package/src/options.ts +80 -0
- package/src/prose.css +108 -0
- package/src/runtime.ts +67 -0
- package/src/theme-bridge.css +130 -0
- package/src/theme-bridge.ts +89 -0
- package/styles.css +299 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { StarlightExpressiveCodeOptions, StyleOverrides } from '@astrojs/starlight/expressive-code';
|
|
2
|
+
import type { StarlightUserConfig } from '@astrojs/starlight/types';
|
|
3
|
+
import type { NyxwireStarlightConfig } from './options.js';
|
|
4
|
+
/**
|
|
5
|
+
* Expressive Code style settings that point every code-block surface at Nyxwire CSS
|
|
6
|
+
* variables, so frames, backgrounds and markers follow the active flavor and accent at runtime.
|
|
7
|
+
* Applied as global style overrides (not inside the theme objects) so user overrides still win.
|
|
8
|
+
*/
|
|
9
|
+
export declare const expressiveCodeStyleOverrides: {
|
|
10
|
+
readonly borderRadius: "var(--nw-radius-lg)";
|
|
11
|
+
readonly borderWidth: "1px";
|
|
12
|
+
readonly borderColor: "var(--nw-line)";
|
|
13
|
+
readonly codeBackground: "var(--nw-canvas-sunken)";
|
|
14
|
+
readonly codeForeground: "var(--nw-fg)";
|
|
15
|
+
readonly codeFontFamily: "var(--nw-font-mono)";
|
|
16
|
+
readonly codeSelectionBackground: "color-mix(in oklab, var(--nw-synth) 30%, transparent)";
|
|
17
|
+
readonly gutterBorderColor: "var(--nw-line)";
|
|
18
|
+
readonly gutterForeground: "var(--nw-fg-subtle)";
|
|
19
|
+
readonly gutterHighlightForeground: "var(--nw-fg-muted)";
|
|
20
|
+
readonly uiFontFamily: "var(--nw-font-sans)";
|
|
21
|
+
readonly uiSelectionBackground: "var(--nw-selection)";
|
|
22
|
+
readonly uiSelectionForeground: "var(--nw-fg)";
|
|
23
|
+
readonly focusBorder: "var(--nw-ring)";
|
|
24
|
+
readonly scrollbarThumbColor: "var(--nw-line-strong)";
|
|
25
|
+
readonly scrollbarThumbHoverColor: "var(--nw-line-bright)";
|
|
26
|
+
readonly frames: {
|
|
27
|
+
readonly frameBoxShadowCssValue: "none";
|
|
28
|
+
readonly editorBackground: "var(--nw-canvas-sunken)";
|
|
29
|
+
readonly terminalBackground: "var(--nw-canvas-sunken)";
|
|
30
|
+
readonly editorTabBarBackground: "var(--nw-panel)";
|
|
31
|
+
readonly editorTabBarBorderColor: "var(--nw-line)";
|
|
32
|
+
readonly editorTabBarBorderBottomColor: "var(--nw-line)";
|
|
33
|
+
readonly editorActiveTabBackground: "var(--nw-canvas-sunken)";
|
|
34
|
+
readonly editorActiveTabForeground: "var(--nw-fg)";
|
|
35
|
+
readonly editorActiveTabBorderColor: "transparent";
|
|
36
|
+
readonly editorActiveTabIndicatorTopColor: "var(--nw-primary)";
|
|
37
|
+
readonly editorActiveTabIndicatorBottomColor: "transparent";
|
|
38
|
+
readonly terminalTitlebarBackground: "var(--nw-panel)";
|
|
39
|
+
readonly terminalTitlebarForeground: "var(--nw-fg-muted)";
|
|
40
|
+
readonly terminalTitlebarBorderBottomColor: "var(--nw-line)";
|
|
41
|
+
readonly terminalTitlebarDotsForeground: "var(--nw-fg-faint)";
|
|
42
|
+
readonly terminalTitlebarDotsOpacity: "0.55";
|
|
43
|
+
readonly inlineButtonBackground: "var(--nw-primary)";
|
|
44
|
+
readonly inlineButtonForeground: "var(--nw-fg-muted)";
|
|
45
|
+
readonly inlineButtonBorder: "var(--nw-line-bright)";
|
|
46
|
+
readonly tooltipSuccessBackground: "var(--nw-success)";
|
|
47
|
+
readonly tooltipSuccessForeground: "var(--nw-on-success)";
|
|
48
|
+
};
|
|
49
|
+
readonly textMarkers: {
|
|
50
|
+
readonly markBackground: "color-mix(in oklab, var(--nw-primary) 14%, transparent)";
|
|
51
|
+
readonly markBorderColor: "var(--nw-primary)";
|
|
52
|
+
readonly insBackground: "color-mix(in oklab, var(--nw-success) 14%, transparent)";
|
|
53
|
+
readonly insBorderColor: "var(--nw-success)";
|
|
54
|
+
readonly insDiffIndicatorColor: "var(--nw-success)";
|
|
55
|
+
readonly delBackground: "color-mix(in oklab, var(--nw-danger) 14%, transparent)";
|
|
56
|
+
readonly delBorderColor: "var(--nw-danger)";
|
|
57
|
+
readonly delDiffIndicatorColor: "var(--nw-danger)";
|
|
58
|
+
readonly lineMarkerLabelColor: "var(--nw-on-accent)";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/** Shallow merge per style group; every key the user sets wins over ours. */
|
|
62
|
+
export declare function mergeStyleOverrides(base: StyleOverrides, user: StyleOverrides | undefined): StyleOverrides;
|
|
63
|
+
/**
|
|
64
|
+
* Expressive Code lifts token colors to 5.5:1 by default. The generated themes already guarantee
|
|
65
|
+
* that on their dimmest code surface, so the render-time floor only needs WCAG AA (4.5:1) and
|
|
66
|
+
* applies to user themes.
|
|
67
|
+
*/
|
|
68
|
+
export declare const MIN_SYNTAX_CONTRAST = 4.5;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the Expressive Code options to hand back to Starlight, or `undefined` when code blocks
|
|
71
|
+
* must stay untouched (plugin option off, or Expressive Code disabled by the user).
|
|
72
|
+
* Every user-provided option, `themes` and style override wins. Everything is JSON data except
|
|
73
|
+
* `themeCssSelector` when the generated themes are used.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createExpressiveCodeOptions(user: StarlightUserConfig['expressiveCode'], config: NyxwireStarlightConfig): StarlightExpressiveCodeOptions | undefined;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createCodeThemes, flavorThemeSelector } from './ec-themes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Expressive Code style settings that point every code-block surface at Nyxwire CSS
|
|
4
|
+
* variables, so frames, backgrounds and markers follow the active flavor and accent at runtime.
|
|
5
|
+
* Applied as global style overrides (not inside the theme objects) so user overrides still win.
|
|
6
|
+
*/
|
|
7
|
+
export const expressiveCodeStyleOverrides = {
|
|
8
|
+
borderRadius: 'var(--nw-radius-lg)',
|
|
9
|
+
borderWidth: '1px',
|
|
10
|
+
borderColor: 'var(--nw-line)',
|
|
11
|
+
codeBackground: 'var(--nw-canvas-sunken)',
|
|
12
|
+
codeForeground: 'var(--nw-fg)',
|
|
13
|
+
codeFontFamily: 'var(--nw-font-mono)',
|
|
14
|
+
codeSelectionBackground: 'color-mix(in oklab, var(--nw-synth) 30%, transparent)',
|
|
15
|
+
gutterBorderColor: 'var(--nw-line)',
|
|
16
|
+
gutterForeground: 'var(--nw-fg-subtle)',
|
|
17
|
+
gutterHighlightForeground: 'var(--nw-fg-muted)',
|
|
18
|
+
uiFontFamily: 'var(--nw-font-sans)',
|
|
19
|
+
uiSelectionBackground: 'var(--nw-selection)',
|
|
20
|
+
uiSelectionForeground: 'var(--nw-fg)',
|
|
21
|
+
focusBorder: 'var(--nw-ring)',
|
|
22
|
+
scrollbarThumbColor: 'var(--nw-line-strong)',
|
|
23
|
+
scrollbarThumbHoverColor: 'var(--nw-line-bright)',
|
|
24
|
+
frames: {
|
|
25
|
+
frameBoxShadowCssValue: 'none',
|
|
26
|
+
editorBackground: 'var(--nw-canvas-sunken)',
|
|
27
|
+
terminalBackground: 'var(--nw-canvas-sunken)',
|
|
28
|
+
editorTabBarBackground: 'var(--nw-panel)',
|
|
29
|
+
editorTabBarBorderColor: 'var(--nw-line)',
|
|
30
|
+
editorTabBarBorderBottomColor: 'var(--nw-line)',
|
|
31
|
+
editorActiveTabBackground: 'var(--nw-canvas-sunken)',
|
|
32
|
+
editorActiveTabForeground: 'var(--nw-fg)',
|
|
33
|
+
editorActiveTabBorderColor: 'transparent',
|
|
34
|
+
editorActiveTabIndicatorTopColor: 'var(--nw-primary)',
|
|
35
|
+
editorActiveTabIndicatorBottomColor: 'transparent',
|
|
36
|
+
terminalTitlebarBackground: 'var(--nw-panel)',
|
|
37
|
+
terminalTitlebarForeground: 'var(--nw-fg-muted)',
|
|
38
|
+
terminalTitlebarBorderBottomColor: 'var(--nw-line)',
|
|
39
|
+
terminalTitlebarDotsForeground: 'var(--nw-fg-faint)',
|
|
40
|
+
terminalTitlebarDotsOpacity: '0.55',
|
|
41
|
+
inlineButtonBackground: 'var(--nw-primary)',
|
|
42
|
+
inlineButtonForeground: 'var(--nw-fg-muted)',
|
|
43
|
+
inlineButtonBorder: 'var(--nw-line-bright)',
|
|
44
|
+
tooltipSuccessBackground: 'var(--nw-success)',
|
|
45
|
+
tooltipSuccessForeground: 'var(--nw-on-success)',
|
|
46
|
+
},
|
|
47
|
+
textMarkers: {
|
|
48
|
+
markBackground: 'color-mix(in oklab, var(--nw-primary) 14%, transparent)',
|
|
49
|
+
markBorderColor: 'var(--nw-primary)',
|
|
50
|
+
insBackground: 'color-mix(in oklab, var(--nw-success) 14%, transparent)',
|
|
51
|
+
insBorderColor: 'var(--nw-success)',
|
|
52
|
+
insDiffIndicatorColor: 'var(--nw-success)',
|
|
53
|
+
delBackground: 'color-mix(in oklab, var(--nw-danger) 14%, transparent)',
|
|
54
|
+
delBorderColor: 'var(--nw-danger)',
|
|
55
|
+
delDiffIndicatorColor: 'var(--nw-danger)',
|
|
56
|
+
lineMarkerLabelColor: 'var(--nw-on-accent)',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
/** Shallow merge per style group; every key the user sets wins over ours. */
|
|
60
|
+
export function mergeStyleOverrides(base, user) {
|
|
61
|
+
if (user === undefined)
|
|
62
|
+
return base;
|
|
63
|
+
const { frames, textMarkers, ...rest } = user;
|
|
64
|
+
return {
|
|
65
|
+
...base,
|
|
66
|
+
...rest,
|
|
67
|
+
frames: { ...base.frames, ...frames },
|
|
68
|
+
textMarkers: { ...base.textMarkers, ...textMarkers },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Expressive Code lifts token colors to 5.5:1 by default. The generated themes already guarantee
|
|
73
|
+
* that on their dimmest code surface, so the render-time floor only needs WCAG AA (4.5:1) and
|
|
74
|
+
* applies to user themes.
|
|
75
|
+
*/
|
|
76
|
+
export const MIN_SYNTAX_CONTRAST = 4.5;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the Expressive Code options to hand back to Starlight, or `undefined` when code blocks
|
|
79
|
+
* must stay untouched (plugin option off, or Expressive Code disabled by the user).
|
|
80
|
+
* Every user-provided option, `themes` and style override wins. Everything is JSON data except
|
|
81
|
+
* `themeCssSelector` when the generated themes are used.
|
|
82
|
+
*/
|
|
83
|
+
export function createExpressiveCodeOptions(user, config) {
|
|
84
|
+
if (!config.expressiveCode || user === false)
|
|
85
|
+
return undefined;
|
|
86
|
+
const options = typeof user === 'object' ? user : {};
|
|
87
|
+
return {
|
|
88
|
+
minSyntaxHighlightingColorContrast: MIN_SYNTAX_CONTRAST,
|
|
89
|
+
...(options.themes === undefined
|
|
90
|
+
? {
|
|
91
|
+
themes: createCodeThemes(config.flavors.dark),
|
|
92
|
+
useStarlightUiThemeColors: false,
|
|
93
|
+
useStarlightDarkModeSwitch: false,
|
|
94
|
+
useDarkModeMediaQuery: false,
|
|
95
|
+
themeCssSelector: flavorThemeSelector,
|
|
96
|
+
}
|
|
97
|
+
: {}),
|
|
98
|
+
...options,
|
|
99
|
+
styleOverrides: mergeStyleOverrides(expressiveCodeStyleOverrides, options.styleOverrides),
|
|
100
|
+
};
|
|
101
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StarlightPlugin } from '@astrojs/starlight/types';
|
|
2
|
+
import type { NyxwireStarlightOptions } from './options.js';
|
|
3
|
+
export * from './config.js';
|
|
4
|
+
export * from './ec-themes.js';
|
|
5
|
+
export * from './expressive-code.js';
|
|
6
|
+
export * from './options.js';
|
|
7
|
+
export * from './runtime.js';
|
|
8
|
+
export type { StarlightThemeBridgeConfig } from './theme-bridge.js';
|
|
9
|
+
export type { AccentName, DarkFlavorName, FlavorName } from '@nyxwire/palette';
|
|
10
|
+
/**
|
|
11
|
+
* Starlight plugin: Nyxwire theme (CSS), flavor runtime + selector (component overrides)
|
|
12
|
+
* and palette-generated Expressive Code themes. Options are validated eagerly.
|
|
13
|
+
*/
|
|
14
|
+
export declare function nyxwireStarlight(options?: NyxwireStarlightOptions): StarlightPlugin;
|
|
15
|
+
export default nyxwireStarlight;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PACKAGE_NAME, createConfigUpdate } from './config.js';
|
|
2
|
+
import { normalizeStarlightOptions } from './options.js';
|
|
3
|
+
import { createRuntimeIntegration } from './runtime.js';
|
|
4
|
+
export * from './config.js';
|
|
5
|
+
export * from './ec-themes.js';
|
|
6
|
+
export * from './expressive-code.js';
|
|
7
|
+
export * from './options.js';
|
|
8
|
+
export * from './runtime.js';
|
|
9
|
+
/**
|
|
10
|
+
* Starlight plugin: Nyxwire theme (CSS), flavor runtime + selector (component overrides)
|
|
11
|
+
* and palette-generated Expressive Code themes. Options are validated eagerly.
|
|
12
|
+
*/
|
|
13
|
+
export function nyxwireStarlight(options = {}) {
|
|
14
|
+
const config = normalizeStarlightOptions(options);
|
|
15
|
+
return {
|
|
16
|
+
name: PACKAGE_NAME,
|
|
17
|
+
hooks: {
|
|
18
|
+
'config:setup'({ config: userConfig, updateConfig, addIntegration, logger }) {
|
|
19
|
+
updateConfig(createConfigUpdate(userConfig, config, (message) => logger.warn(message)));
|
|
20
|
+
addIntegration(createRuntimeIntegration(config));
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export default nyxwireStarlight;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FlavorConfig, FlavorPreference } from '@nyxwire/astro';
|
|
2
|
+
import type { AccentName, DarkFlavorName } from '@nyxwire/palette';
|
|
3
|
+
export type NyxwireStarlightOptions = {
|
|
4
|
+
readonly flavors?: {
|
|
5
|
+
readonly dark?: DarkFlavorName;
|
|
6
|
+
readonly light?: 'lumen';
|
|
7
|
+
};
|
|
8
|
+
readonly accent?: AccentName;
|
|
9
|
+
readonly defaultFlavor?: FlavorPreference;
|
|
10
|
+
readonly flavorSelect?: boolean;
|
|
11
|
+
readonly expressiveCode?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type NyxwireStarlightConfig = {
|
|
14
|
+
readonly flavors: {
|
|
15
|
+
readonly dark: DarkFlavorName;
|
|
16
|
+
readonly light: 'lumen';
|
|
17
|
+
};
|
|
18
|
+
readonly defaultFlavor: FlavorPreference;
|
|
19
|
+
readonly accent: FlavorConfig['accent'];
|
|
20
|
+
readonly flavorSelect: boolean;
|
|
21
|
+
readonly expressiveCode: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare class NyxwireStarlightOptionsError extends TypeError {
|
|
24
|
+
readonly option: string;
|
|
25
|
+
readonly expected: string;
|
|
26
|
+
constructor(option: string, expected: string);
|
|
27
|
+
}
|
|
28
|
+
/** Validates plugin options; flavor and accent rules are shared with `@nyxwire/astro`. */
|
|
29
|
+
export declare function normalizeStarlightOptions(options?: unknown): NyxwireStarlightConfig;
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NyxwireOptionsError, normalizeOptions } from '@nyxwire/astro';
|
|
2
|
+
const OPTION_NAMES = [
|
|
3
|
+
'flavors',
|
|
4
|
+
'defaultFlavor',
|
|
5
|
+
'accent',
|
|
6
|
+
'flavorSelect',
|
|
7
|
+
'expressiveCode',
|
|
8
|
+
];
|
|
9
|
+
export class NyxwireStarlightOptionsError extends TypeError {
|
|
10
|
+
option;
|
|
11
|
+
expected;
|
|
12
|
+
constructor(option, expected) {
|
|
13
|
+
super(`@nyxwire/starlight: ${option} must be ${expected}.`);
|
|
14
|
+
this.name = 'NyxwireStarlightOptionsError';
|
|
15
|
+
this.option = option;
|
|
16
|
+
this.expected = expected;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function record(value, name) {
|
|
20
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
21
|
+
throw new NyxwireStarlightOptionsError(name, 'an object');
|
|
22
|
+
}
|
|
23
|
+
return Object.fromEntries(Object.entries(value));
|
|
24
|
+
}
|
|
25
|
+
function enabled(value, name) {
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return true;
|
|
28
|
+
if (typeof value !== 'boolean')
|
|
29
|
+
throw new NyxwireStarlightOptionsError(name, 'true or false');
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
/** Validates plugin options; flavor and accent rules are shared with `@nyxwire/astro`. */
|
|
33
|
+
export function normalizeStarlightOptions(options = {}) {
|
|
34
|
+
const input = record(options, 'options');
|
|
35
|
+
for (const key of Object.keys(input)) {
|
|
36
|
+
if (!OPTION_NAMES.some((name) => name === key)) {
|
|
37
|
+
throw new NyxwireStarlightOptionsError(key, `a recognized option (${OPTION_NAMES.join(', ')})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const flavorSelect = enabled(input['flavorSelect'], 'flavorSelect');
|
|
41
|
+
const expressiveCode = enabled(input['expressiveCode'], 'expressiveCode');
|
|
42
|
+
try {
|
|
43
|
+
const { flavors, accent, defaultFlavor } = normalizeOptions({
|
|
44
|
+
defaultFlavor: input['defaultFlavor'],
|
|
45
|
+
...(input['flavors'] === undefined ? {} : { flavors: input['flavors'] }),
|
|
46
|
+
...(input['accent'] === undefined ? {} : { accent: input['accent'] }),
|
|
47
|
+
});
|
|
48
|
+
return { flavors, defaultFlavor, accent, flavorSelect, expressiveCode };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof NyxwireOptionsError) {
|
|
52
|
+
throw new NyxwireStarlightOptionsError(error.option, error.expected);
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import type { NyxwireStarlightConfig } from './options.js';
|
|
3
|
+
/** Virtual module read by the ThemeProvider override. */
|
|
4
|
+
export declare const RUNTIME_MODULE_ID = "virtual:nyxwire/starlight-runtime";
|
|
5
|
+
/** Starlight's own localStorage key for its dark/light/auto select. */
|
|
6
|
+
export declare const STARLIGHT_THEME_STORAGE_KEY = "starlight-theme";
|
|
7
|
+
export type StarlightThemeRuntime = {
|
|
8
|
+
/** Inline no-FOUC script: flavor runtime followed by the Starlight bridge. */
|
|
9
|
+
readonly script: string;
|
|
10
|
+
/** Initial `<meta name="theme-color">` (configured dark flavor base); the runtime updates it. */
|
|
11
|
+
readonly themeColor: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function buildThemeProviderScript(config: NyxwireStarlightConfig): string;
|
|
14
|
+
export declare function createThemeRuntime(config: NyxwireStarlightConfig): StarlightThemeRuntime;
|
|
15
|
+
/** Astro integration exposing the runtime to the ThemeProvider through a Vite virtual module. */
|
|
16
|
+
export declare function createRuntimeIntegration(config: NyxwireStarlightConfig): AstroIntegration;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FLAVOR_CHANGE_EVENT, FLAVOR_STORAGE_KEY, buildFlavorScript } from '@nyxwire/astro';
|
|
2
|
+
import { palette } from '@nyxwire/palette';
|
|
3
|
+
import { starlightThemeBridge } from './theme-bridge.js';
|
|
4
|
+
/** Virtual module read by the ThemeProvider override. */
|
|
5
|
+
export const RUNTIME_MODULE_ID = 'virtual:nyxwire/starlight-runtime';
|
|
6
|
+
/** Starlight's own localStorage key for its dark/light/auto select. */
|
|
7
|
+
export const STARLIGHT_THEME_STORAGE_KEY = 'starlight-theme';
|
|
8
|
+
export function buildThemeProviderScript(config) {
|
|
9
|
+
const bridge = {
|
|
10
|
+
dark: config.flavors.dark,
|
|
11
|
+
light: config.flavors.light,
|
|
12
|
+
storageKey: FLAVOR_STORAGE_KEY,
|
|
13
|
+
legacyKey: STARLIGHT_THEME_STORAGE_KEY,
|
|
14
|
+
changeEvent: FLAVOR_CHANGE_EVENT,
|
|
15
|
+
};
|
|
16
|
+
const runtime = buildFlavorScript({
|
|
17
|
+
flavors: config.flavors,
|
|
18
|
+
defaultFlavor: config.defaultFlavor,
|
|
19
|
+
accent: config.accent ?? undefined,
|
|
20
|
+
});
|
|
21
|
+
const serialized = JSON.stringify(bridge).replace(/</g, '\\u003c');
|
|
22
|
+
return `${runtime}\n(${starlightThemeBridge.toString()})(${serialized});`;
|
|
23
|
+
}
|
|
24
|
+
export function createThemeRuntime(config) {
|
|
25
|
+
return {
|
|
26
|
+
script: buildThemeProviderScript(config),
|
|
27
|
+
themeColor: palette[config.defaultFlavor === 'auto' ? config.flavors.dark : config.defaultFlavor].base,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Astro integration exposing the runtime to the ThemeProvider through a Vite virtual module. */
|
|
31
|
+
export function createRuntimeIntegration(config) {
|
|
32
|
+
const resolvedId = `\0${RUNTIME_MODULE_ID}`;
|
|
33
|
+
const code = `export default ${JSON.stringify(createThemeRuntime(config))};`;
|
|
34
|
+
return {
|
|
35
|
+
name: '@nyxwire/starlight/runtime',
|
|
36
|
+
hooks: {
|
|
37
|
+
'astro:config:setup': ({ updateConfig }) => {
|
|
38
|
+
updateConfig({
|
|
39
|
+
vite: {
|
|
40
|
+
plugins: [
|
|
41
|
+
{
|
|
42
|
+
name: 'nyxwire-starlight-runtime',
|
|
43
|
+
resolveId: (id) => (id === RUNTIME_MODULE_ID ? resolvedId : undefined),
|
|
44
|
+
load: (id) => (id === resolvedId ? code : undefined),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DarkFlavorName } from '@nyxwire/palette';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
StarlightThemeProvider?: {
|
|
5
|
+
readonly updatePickers: (theme?: string) => void;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export type StarlightThemeBridgeConfig = {
|
|
10
|
+
readonly dark: DarkFlavorName;
|
|
11
|
+
readonly light: 'lumen';
|
|
12
|
+
readonly storageKey: string;
|
|
13
|
+
readonly legacyKey: string;
|
|
14
|
+
readonly changeEvent: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Connects Starlight's theme API to the Nyxwire flavor runtime. Runs inline in `<head>` right
|
|
18
|
+
* after the flavor runtime and is stringified: it must not reference anything outside its body.
|
|
19
|
+
*
|
|
20
|
+
* - `window.StarlightThemeProvider.updatePickers(theme?)` keeps Starlight's contract: it syncs every
|
|
21
|
+
* `<starlight-theme-select>` / `<nw-starlight-flavor-select>` (value + label icon). Called with a
|
|
22
|
+
* Starlight theme that differs from the current one (Starlight's own select changed), it maps
|
|
23
|
+
* `dark|light|auto` to the configured dark flavor, the light flavor, or auto.
|
|
24
|
+
* - The Starlight `starlight-theme` storage key mirrors the flavor (`''` for auto), and a stored
|
|
25
|
+
* Starlight preference is adopted once when no flavor has been stored yet.
|
|
26
|
+
*/
|
|
27
|
+
export declare function starlightThemeBridge(config: StarlightThemeBridgeConfig): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connects Starlight's theme API to the Nyxwire flavor runtime. Runs inline in `<head>` right
|
|
3
|
+
* after the flavor runtime and is stringified: it must not reference anything outside its body.
|
|
4
|
+
*
|
|
5
|
+
* - `window.StarlightThemeProvider.updatePickers(theme?)` keeps Starlight's contract: it syncs every
|
|
6
|
+
* `<starlight-theme-select>` / `<nw-starlight-flavor-select>` (value + label icon). Called with a
|
|
7
|
+
* Starlight theme that differs from the current one (Starlight's own select changed), it maps
|
|
8
|
+
* `dark|light|auto` to the configured dark flavor, the light flavor, or auto.
|
|
9
|
+
* - The Starlight `starlight-theme` storage key mirrors the flavor (`''` for auto), and a stored
|
|
10
|
+
* Starlight preference is adopted once when no flavor has been stored yet.
|
|
11
|
+
*/
|
|
12
|
+
export function starlightThemeBridge(config) {
|
|
13
|
+
const controller = window.nyxwire;
|
|
14
|
+
if (!controller)
|
|
15
|
+
return;
|
|
16
|
+
const read = (key) => {
|
|
17
|
+
try {
|
|
18
|
+
return localStorage.getItem(key);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!(error instanceof DOMException))
|
|
22
|
+
throw error;
|
|
23
|
+
// Storage is blocked: behave as if nothing was stored.
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const write = (key, value) => {
|
|
28
|
+
try {
|
|
29
|
+
localStorage.setItem(key, value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!(error instanceof DOMException))
|
|
33
|
+
throw error;
|
|
34
|
+
// Storage is blocked or full: the in-memory flavor still applies.
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const legacy = read(config.legacyKey);
|
|
38
|
+
if (read(config.storageKey) === null && (legacy === 'dark' || legacy === 'light')) {
|
|
39
|
+
controller.setFlavor(legacy === 'dark' ? config.dark : config.light);
|
|
40
|
+
}
|
|
41
|
+
const current = () => controller.getFlavor() === 'auto'
|
|
42
|
+
? 'auto'
|
|
43
|
+
: controller.resolve() === config.light
|
|
44
|
+
? 'light'
|
|
45
|
+
: 'dark';
|
|
46
|
+
const sync = () => {
|
|
47
|
+
const theme = current();
|
|
48
|
+
const legacy = theme === 'auto' ? '' : theme;
|
|
49
|
+
if (read(config.legacyKey) !== legacy)
|
|
50
|
+
write(config.legacyKey, legacy);
|
|
51
|
+
const template = document.getElementById('theme-icons');
|
|
52
|
+
const icon = template instanceof HTMLTemplateElement ? template.content.querySelector(`.${theme}`) : null;
|
|
53
|
+
for (const picker of document.querySelectorAll('starlight-theme-select, nw-starlight-flavor-select')) {
|
|
54
|
+
const select = picker.querySelector('select');
|
|
55
|
+
if (select) {
|
|
56
|
+
select.value =
|
|
57
|
+
picker.localName === 'starlight-theme-select' ? theme : controller.getFlavor();
|
|
58
|
+
}
|
|
59
|
+
const label = picker.querySelector('svg.label-icon');
|
|
60
|
+
if (icon && label)
|
|
61
|
+
label.replaceChildren(...icon.cloneNode(true).childNodes);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const updatePickers = (theme) => {
|
|
65
|
+
if ((theme === 'auto' || theme === 'dark' || theme === 'light') && theme !== current()) {
|
|
66
|
+
controller.setFlavor(theme === 'auto' ? 'auto' : theme === 'dark' ? config.dark : config.light);
|
|
67
|
+
}
|
|
68
|
+
sync();
|
|
69
|
+
};
|
|
70
|
+
window.StarlightThemeProvider = { ...window.StarlightThemeProvider, updatePickers };
|
|
71
|
+
document.addEventListener(config.changeEvent, sync);
|
|
72
|
+
sync();
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyxwire/starlight",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nyxwire's Starlight theme: every docs surface, the code blocks and the flavor switch in Nyxwire's identity.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nyxwire",
|
|
7
|
+
"design-system",
|
|
8
|
+
"astro",
|
|
9
|
+
"starlight",
|
|
10
|
+
"starlight-theme",
|
|
11
|
+
"withastro"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://nyxwire.dissidence.ovh/starlight/setup/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/fmauNeko/nyxwire/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/fmauNeko/nyxwire.git",
|
|
20
|
+
"directory": "packages/starlight"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Florian Maunier",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src",
|
|
28
|
+
"styles.css"
|
|
29
|
+
],
|
|
30
|
+
"skills": [
|
|
31
|
+
"npm:@nyxwire/css"
|
|
32
|
+
],
|
|
33
|
+
"sideEffects": [
|
|
34
|
+
"*.css"
|
|
35
|
+
],
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./components/*": "./src/components/*",
|
|
42
|
+
"./styles.css": "./styles.css"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@astrojs/starlight": ">=0.42",
|
|
46
|
+
"astro": "^7"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@expressive-code/core": "0.44.3",
|
|
50
|
+
"@nyxwire/palette": "0.1.0",
|
|
51
|
+
"@nyxwire/css": "0.1.0",
|
|
52
|
+
"@nyxwire/astro": "0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@astrojs/starlight": "0.42.10",
|
|
56
|
+
"@types/node": "^26",
|
|
57
|
+
"astro": "7.4.7",
|
|
58
|
+
"astro-expressive-code": "0.44.3",
|
|
59
|
+
"typescript": "6.0.3",
|
|
60
|
+
"vitest": "5.1.0"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.build.json && node ../agent-docs/src/run.ts",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
69
|
+
}
|
|
6
70
|
}
|