File tree Expand file tree Collapse file tree
static/docs/[version]/assets/js Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import sidebarScroll from './partials/sidebar.js'
1111import snippets from './partials/snippets.js'
1212import stickyNav from './partials/sticky.js'
13+ import theme from './partials/theme.js'
1314import tocDrawer from './partials/toc.js'
1415
1516export default ( ) => {
1617 sidebarScroll ( )
1718 snippets ( )
1819 stickyNav ( )
20+ theme ( )
1921 tocDrawer ( )
2022}
Original file line number Diff line number Diff line change 1+ // NOTICE: Internal docs helpers — not shipped in Bootstrap; not for reuse.
2+
3+ /*
4+ * JavaScript for Bootstrap's docs (https://getbootstrap.com/)
5+ * Copyright 2011-2026 The Bootstrap Authors
6+ * Licensed under the Creative Commons Attribution 3.0 Unported License.
7+ * For details, see https://creativecommons.org/licenses/by/3.0/.
8+ */
9+
10+ import { Menu } from '@bootstrap'
11+
12+ export default ( ) => {
13+ const themeSwitcher = document . getElementById ( 'bd-theme' )
14+
15+ if ( ! themeSwitcher ) {
16+ return
17+ }
18+
19+ document . addEventListener ( 'click' , event => {
20+ const toggle = event . target . closest ( '[data-bs-theme-value]' )
21+
22+ if ( ! toggle ) {
23+ return
24+ }
25+
26+ Menu . getOrCreateInstance ( themeSwitcher ) . hide ( )
27+ } , true )
28+ }
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ export async function highlightCode(
5858 light : { ...( bootstrapLight as any ) , name : '' } ,
5959 dark : { ...( bootstrapDark as any ) , name : '' }
6060 } ,
61+ defaultColor : 'light-dark()' ,
6162 transformers
6263 } )
6364
Original file line number Diff line number Diff line change 3939 background-color : color-mix (in oklch , var (--primary-bg ) 10% , transparent );
4040}
4141
42- // Dark mode theming for Shiki
43- // When using dual themes, Shiki generates inline styles with CSS variables
44- // We need to switch from the light theme vars to dark theme vars
4542[data-bs-theme = " dark" ] {
4643 --shell-prompt-color : #868e96 ;
47-
48- .astro-code span ,
49- .astro-code-themes span {
50- // Override Shiki's inline color with the dark theme color
51- color : var (--shiki-dark ) !important ; // stylelint-disable-line declaration-no-important
52- }
5344}
5445
5546// Shell prompts - these work with Shiki's transformer that adds .line class
Original file line number Diff line number Diff line change 1919 return 'auto'
2020 }
2121
22- const setTheme = theme => {
22+ const resolveTheme = theme => {
2323 if ( theme === 'auto' ) {
24- document . documentElement . setAttribute ( 'data-bs-theme' , ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ) )
25- } else {
26- document . documentElement . setAttribute ( 'data-bs-theme' , theme )
24+ return window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light'
25+ }
26+
27+ return theme
28+ }
29+
30+ const setTheme = theme => {
31+ const resolved = resolveTheme ( theme )
32+
33+ if ( document . documentElement . getAttribute ( 'data-bs-theme' ) !== resolved ) {
34+ document . documentElement . setAttribute ( 'data-bs-theme' , resolved )
2735 }
2836 }
2937
7078 toggle . addEventListener ( 'click' , ( ) => {
7179 const theme = toggle . getAttribute ( 'data-bs-theme-value' )
7280 setStoredTheme ( theme )
73- setTheme ( theme )
74- showActiveTheme ( theme , true )
81+
82+ requestAnimationFrame ( ( ) => {
83+ setTheme ( theme )
84+ showActiveTheme ( theme )
85+ } )
7586 } )
7687 } )
7788 } )
You can’t perform that action at this time.
0 commit comments