@astrojs/starlight 0.41.11 → 0.42.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/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/MobileMenuToggle.astro +65 -0
- package/{components → dist/components}/PageFrame.astro +32 -8
- package/dist/components-internals/Icons.d.ts +415 -0
- package/dist/components-internals/Icons.js +140 -0
- package/dist/components-internals/SidebarPersistState.d.ts +1 -0
- package/dist/components-internals/SidebarPersistState.js +53 -0
- package/dist/components-internals/TableOfContents/starlight-toc.d.ts +18 -0
- package/dist/components-internals/TableOfContents/starlight-toc.js +88 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/{expressive-code.d.ts → dist/expressive-code.d.ts} +6 -13
- package/dist/expressive-code.js +31 -0
- package/dist/global.d.ts +62 -0
- package/dist/global.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +109 -0
- package/dist/integrations/aside-utils.d.ts +9 -0
- package/dist/integrations/aside-utils.js +35 -0
- package/dist/integrations/expressive-code/hast.d.ts +1 -0
- package/dist/integrations/expressive-code/hast.js +2 -0
- package/dist/integrations/expressive-code/index.d.ts +60 -0
- package/dist/integrations/expressive-code/index.js +48 -0
- package/dist/integrations/expressive-code/preprocessor.d.ts +17 -0
- package/dist/integrations/expressive-code/preprocessor.js +76 -0
- package/dist/integrations/expressive-code/themes/night-owl-dark.js +4 -0
- package/dist/integrations/expressive-code/themes/night-owl-light.js +4 -0
- package/dist/integrations/expressive-code/theming.d.ts +16 -0
- package/dist/integrations/expressive-code/theming.js +71 -0
- package/dist/integrations/expressive-code/translations.d.ts +8 -0
- package/dist/integrations/expressive-code/translations.js +26 -0
- package/dist/integrations/markdown-icon.d.ts +8 -0
- package/dist/integrations/markdown-icon.js +14 -0
- package/dist/integrations/markdown-plugins.d.ts +18 -0
- package/dist/integrations/markdown-plugins.js +36 -0
- package/dist/integrations/markdown-processor.d.ts +29 -0
- package/dist/integrations/markdown-processor.js +44 -0
- package/dist/integrations/pagefind.d.ts +7 -0
- package/dist/integrations/pagefind.js +34 -0
- package/dist/integrations/rehype-code-rtl-support.d.ts +21 -0
- package/dist/integrations/rehype-code-rtl-support.js +36 -0
- package/dist/integrations/rehype-heading-links.d.ts +10 -0
- package/dist/integrations/rehype-heading-links.js +57 -0
- package/dist/integrations/remark-asides.d.ts +32 -0
- package/dist/integrations/remark-asides.js +166 -0
- package/dist/integrations/remark-rehype.d.ts +17 -0
- package/dist/integrations/remark-rehype.js +51 -0
- package/dist/integrations/satteri.d.ts +13 -0
- package/dist/integrations/satteri.js +209 -0
- package/dist/integrations/shared/absolutePathToLang.d.ts +10 -0
- package/dist/integrations/shared/absolutePathToLang.js +13 -0
- package/dist/integrations/shared/localeToLang.d.ts +10 -0
- package/dist/integrations/shared/localeToLang.js +13 -0
- package/dist/integrations/shared/slugToLocale.d.ts +12 -0
- package/dist/integrations/shared/slugToLocale.js +15 -0
- package/dist/integrations/sitemap.d.ts +12 -0
- package/dist/integrations/sitemap.js +19 -0
- package/dist/integrations/vite-layer-order.d.ts +15 -0
- package/dist/integrations/vite-layer-order.js +56 -0
- package/dist/integrations/vite-lazy-barrel-optimization.d.ts +12 -0
- package/dist/integrations/vite-lazy-barrel-optimization.js +33 -0
- package/dist/integrations/vite-virtual-modules.d.ts +14 -0
- package/dist/integrations/vite-virtual-modules.js +108 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +3 -0
- package/dist/loaders.d.ts +20 -0
- package/dist/loaders.js +49 -0
- package/dist/locals.d.ts +15 -0
- package/dist/locals.js +33 -0
- package/dist/package.js +4 -0
- package/{props.ts → dist/props.d.ts} +6 -4
- package/dist/props.js +1 -0
- package/dist/route-data.d.ts +7 -0
- package/dist/route-data.js +6 -0
- package/dist/schema.d.ts +426 -0
- package/dist/schema.js +103 -0
- package/dist/schemas/badge.d.ts +86 -0
- package/dist/schemas/badge.js +39 -0
- package/dist/schemas/components.d.ts +236 -0
- package/dist/schemas/components.js +36 -0
- package/dist/schemas/expressiveCode.d.ts +7 -0
- package/dist/schemas/expressiveCode.js +5 -0
- package/dist/schemas/favicon.d.ts +9 -0
- package/dist/schemas/favicon.js +32 -0
- package/dist/schemas/head.d.ts +33 -0
- package/dist/schemas/head.js +41 -0
- package/dist/schemas/hero.d.ts +319 -0
- package/dist/schemas/hero.js +73 -0
- package/dist/schemas/i18n.d.ts +125 -0
- package/dist/schemas/i18n.js +76 -0
- package/dist/schemas/icon.d.ts +284 -0
- package/dist/schemas/icon.js +7 -0
- package/dist/schemas/locale.d.ts +20 -0
- package/dist/schemas/locale.js +11 -0
- package/dist/schemas/logo.d.ts +32 -0
- package/dist/schemas/logo.js +14 -0
- package/dist/schemas/pagefind.d.ts +166 -0
- package/dist/schemas/pagefind.js +31 -0
- package/dist/schemas/prevNextLink.d.ts +10 -0
- package/dist/schemas/prevNextLink.js +14 -0
- package/dist/schemas/sidebar.d.ts +205 -0
- package/dist/schemas/sidebar.js +71 -0
- package/dist/schemas/site-title.d.ts +7 -0
- package/dist/schemas/site-title.js +17 -0
- package/dist/schemas/social.d.ts +292 -0
- package/dist/schemas/social.js +18 -0
- package/dist/schemas/tableOfContents.d.ts +24 -0
- package/dist/schemas/tableOfContents.js +16 -0
- package/dist/translations/ar.js +36 -0
- package/dist/translations/ca.js +46 -0
- package/dist/translations/cs.js +46 -0
- package/dist/translations/da.js +33 -0
- package/dist/translations/de.js +33 -0
- package/dist/translations/el.js +33 -0
- package/dist/translations/en.js +33 -0
- package/dist/translations/es.js +46 -0
- package/dist/translations/fa.js +33 -0
- package/dist/translations/fi.js +33 -0
- package/dist/translations/fr.js +36 -0
- package/dist/translations/gl.js +46 -0
- package/dist/translations/he.js +33 -0
- package/dist/translations/hi.js +36 -0
- package/dist/translations/hu.js +46 -0
- package/dist/translations/id.js +33 -0
- package/dist/translations/index.d.ts +48 -0
- package/dist/translations/index.js +75 -0
- package/dist/translations/it.js +36 -0
- package/dist/translations/ja.js +36 -0
- package/dist/translations/ko.js +36 -0
- package/dist/translations/lv.js +33 -0
- package/dist/translations/nb.js +33 -0
- package/dist/translations/nl.js +33 -0
- package/dist/translations/pl.js +36 -0
- package/dist/translations/pt.js +36 -0
- package/dist/translations/ro.js +33 -0
- package/dist/translations/ru.js +36 -0
- package/dist/translations/sk.js +33 -0
- package/dist/translations/sv.js +33 -0
- package/dist/translations/th.js +33 -0
- package/dist/translations/tr.js +33 -0
- package/dist/translations/uk.js +33 -0
- package/dist/translations/vi.js +33 -0
- package/dist/translations/zh-CN.js +36 -0
- package/dist/translations/zh-TW.js +36 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/{user-components → dist/user-components}/FileTree.astro +1 -1
- package/{user-components → dist/user-components}/Steps.astro +1 -1
- package/{user-components → dist/user-components}/TabItem.astro +1 -1
- package/{user-components → dist/user-components}/Tabs.astro +1 -1
- package/dist/user-components/file-tree-icons.d.ts +178 -0
- package/dist/user-components/file-tree-icons.js +632 -0
- package/dist/user-components/file-tree-processor.d.ts +16 -0
- package/dist/user-components/file-tree-processor.js +132 -0
- package/dist/user-components/steps-processor.d.ts +10 -0
- package/dist/user-components/steps-processor.js +39 -0
- package/dist/user-components/tabs-processor.d.ts +23 -0
- package/dist/user-components/tabs-processor.js +70 -0
- package/dist/utils/base.d.ts +7 -0
- package/dist/utils/base.js +15 -0
- package/dist/utils/canonical.d.ts +10 -0
- package/dist/utils/canonical.js +14 -0
- package/dist/utils/collection-fs.d.ts +13 -0
- package/dist/utils/collection-fs.js +19 -0
- package/{utils/collection.ts → dist/utils/collection.d.ts} +9 -20
- package/dist/utils/collection.js +26 -0
- package/dist/utils/createPathFormatter.d.ts +9 -0
- package/dist/utils/createPathFormatter.js +35 -0
- package/dist/utils/createTranslationSystem.d.ts +23 -0
- package/dist/utils/createTranslationSystem.js +84 -0
- package/dist/utils/error-map.d.ts +23 -0
- package/dist/utils/error-map.js +125 -0
- package/dist/utils/format-path.d.ts +4 -0
- package/dist/utils/format-path.js +9 -0
- package/dist/utils/generateToC.d.ts +14 -0
- package/dist/utils/generateToC.js +25 -0
- package/dist/utils/git.d.ts +12 -0
- package/dist/utils/git.js +71 -0
- package/dist/utils/gitInlined.d.ts +6 -0
- package/dist/utils/gitInlined.js +11 -0
- package/dist/utils/head.d.ts +7 -0
- package/dist/utils/head.js +233 -0
- package/dist/utils/i18n.d.ts +50 -0
- package/dist/utils/i18n.js +141 -0
- package/dist/utils/localizedUrl.d.ts +8 -0
- package/dist/utils/localizedUrl.js +28 -0
- package/dist/utils/navigation.d.ts +19 -0
- package/dist/utils/navigation.js +353 -0
- package/dist/utils/path.d.ts +21 -0
- package/dist/utils/path.js +51 -0
- package/dist/utils/plugins.d.ts +721 -0
- package/dist/utils/plugins.js +174 -0
- package/dist/utils/routing/data.d.ts +20 -0
- package/dist/utils/routing/data.js +127 -0
- package/dist/utils/routing/index.d.ts +21 -0
- package/dist/utils/routing/index.js +106 -0
- package/dist/utils/routing/middleware.d.ts +11 -0
- package/dist/utils/routing/middleware.js +65 -0
- package/dist/utils/routing/types.d.ts +93 -0
- package/dist/utils/routing/types.js +1 -0
- package/dist/utils/slugs.d.ts +45 -0
- package/dist/utils/slugs.js +104 -0
- package/dist/utils/starlight-page.d.ts +36 -0
- package/dist/utils/starlight-page.js +120 -0
- package/dist/utils/translations-fs.d.ts +15 -0
- package/dist/utils/translations-fs.js +39 -0
- package/dist/utils/translations.d.ts +20 -0
- package/dist/utils/translations.js +29 -0
- package/dist/utils/types.d.ts +5 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/url.d.ts +7 -0
- package/{utils/url.ts → dist/utils/url.js} +5 -4
- package/dist/utils/user-config.d.ts +2055 -0
- package/dist/utils/user-config.js +136 -0
- package/dist/utils/validateLogoImports.d.ts +5 -0
- package/dist/utils/validateLogoImports.js +16 -0
- package/dist/utils/zodDeepMerge.d.ts +16 -0
- package/dist/utils/zodDeepMerge.js +53 -0
- package/package.json +60 -34
- package/CHANGELOG.md +0 -3051
- package/components/MobileMenuToggle.astro +0 -114
- package/components-internals/Icons.ts +0 -248
- package/components-internals/SidebarPersistState.ts +0 -71
- package/components-internals/TableOfContents/starlight-toc.ts +0 -127
- package/constants.ts +0 -4
- package/expressive-code.mjs +0 -23
- package/global.d.ts +0 -11
- package/i18n.d.ts +0 -18
- package/index.ts +0 -200
- package/integrations/aside-utils.ts +0 -41
- package/integrations/expressive-code/hast.d.ts +0 -5
- package/integrations/expressive-code/hast.mjs +0 -9
- package/integrations/expressive-code/index.ts +0 -125
- package/integrations/expressive-code/preprocessor.ts +0 -126
- package/integrations/expressive-code/themes/night-owl-dark.jsonc +0 -1796
- package/integrations/expressive-code/themes/night-owl-light.jsonc +0 -1695
- package/integrations/expressive-code/theming.ts +0 -105
- package/integrations/expressive-code/translations.ts +0 -36
- package/integrations/markdown-icon.ts +0 -13
- package/integrations/markdown-plugins.ts +0 -71
- package/integrations/markdown-processor.ts +0 -64
- package/integrations/pagefind.ts +0 -60
- package/integrations/rehype-code-rtl-support.ts +0 -37
- package/integrations/rehype-heading-links.ts +0 -79
- package/integrations/remark-asides.ts +0 -219
- package/integrations/remark-rehype.ts +0 -87
- package/integrations/satteri.ts +0 -265
- package/integrations/shared/absolutePathToLang.ts +0 -26
- package/integrations/shared/localeToLang.ts +0 -15
- package/integrations/shared/slugToLocale.ts +0 -18
- package/integrations/sitemap.ts +0 -23
- package/integrations/vite-layer-order.ts +0 -69
- package/integrations/vite-lazy-barrel-optimization.ts +0 -40
- package/integrations/vite-virtual-modules.ts +0 -175
- package/internal.ts +0 -6
- package/loaders.ts +0 -63
- package/locals.d.ts +0 -43
- package/locals.ts +0 -43
- package/route-data.ts +0 -11
- package/schema.ts +0 -167
- package/schemas/badge.ts +0 -40
- package/schemas/components.ts +0 -265
- package/schemas/expressiveCode.ts +0 -12
- package/schemas/favicon.ts +0 -40
- package/schemas/head.ts +0 -50
- package/schemas/hero.ts +0 -69
- package/schemas/i18n.ts +0 -244
- package/schemas/icon.ts +0 -7
- package/schemas/logo.ts +0 -28
- package/schemas/pagefind.ts +0 -128
- package/schemas/prevNextLink.ts +0 -18
- package/schemas/sidebar.ts +0 -163
- package/schemas/site-title.ts +0 -20
- package/schemas/social.ts +0 -23
- package/schemas/tableOfContents.ts +0 -21
- package/translations/README.md +0 -14
- package/translations/ar.json +0 -33
- package/translations/ca.json +0 -43
- package/translations/cs.json +0 -43
- package/translations/da.json +0 -30
- package/translations/de.json +0 -30
- package/translations/el.json +0 -30
- package/translations/en.json +0 -30
- package/translations/es.json +0 -43
- package/translations/fa.json +0 -30
- package/translations/fi.json +0 -30
- package/translations/fr.json +0 -33
- package/translations/gl.json +0 -43
- package/translations/he.json +0 -30
- package/translations/hi.json +0 -33
- package/translations/hu.json +0 -43
- package/translations/id.json +0 -30
- package/translations/index.ts +0 -76
- package/translations/it.json +0 -33
- package/translations/ja.json +0 -33
- package/translations/ko.json +0 -33
- package/translations/lv.json +0 -30
- package/translations/nb.json +0 -30
- package/translations/nl.json +0 -30
- package/translations/pl.json +0 -33
- package/translations/pt.json +0 -33
- package/translations/ro.json +0 -30
- package/translations/ru.json +0 -33
- package/translations/sk.json +0 -30
- package/translations/sv.json +0 -30
- package/translations/th.json +0 -30
- package/translations/tr.json +0 -30
- package/translations/uk.json +0 -30
- package/translations/vi.json +0 -30
- package/translations/zh-CN.json +0 -33
- package/translations/zh-TW.json +0 -33
- package/types.ts +0 -7
- package/user-components/file-tree-icons.ts +0 -782
- package/user-components/rehype-file-tree.ts +0 -251
- package/user-components/rehype-steps.ts +0 -85
- package/user-components/rehype-tabs.ts +0 -121
- package/utils/base.ts +0 -15
- package/utils/canonical.ts +0 -19
- package/utils/collection-fs.ts +0 -20
- package/utils/createPathFormatter.ts +0 -60
- package/utils/createTranslationSystem.ts +0 -137
- package/utils/error-map.ts +0 -222
- package/utils/format-path.ts +0 -7
- package/utils/generateToC.ts +0 -33
- package/utils/git.ts +0 -121
- package/utils/gitInlined.ts +0 -20
- package/utils/head.ts +0 -235
- package/utils/i18n.ts +0 -221
- package/utils/localizedUrl.ts +0 -51
- package/utils/navigation.ts +0 -574
- package/utils/path.ts +0 -58
- package/utils/plugins.ts +0 -498
- package/utils/routing/data.ts +0 -154
- package/utils/routing/index.ts +0 -139
- package/utils/routing/middleware.ts +0 -81
- package/utils/routing/types.ts +0 -101
- package/utils/slugs.ts +0 -119
- package/utils/starlight-page.ts +0 -205
- package/utils/translations-fs.ts +0 -54
- package/utils/translations.ts +0 -57
- package/utils/types.ts +0 -15
- package/utils/user-config.ts +0 -348
- package/utils/validateLogoImports.ts +0 -21
- package/utils/zodDeepMerge.ts +0 -144
- package/virtual-internal.d.ts +0 -149
- package/virtual.d.ts +0 -27
- /package/{components → dist/components}/AnchorHeading.astro +0 -0
- /package/{components → dist/components}/Banner.astro +0 -0
- /package/{components → dist/components}/ContentNotice.astro +0 -0
- /package/{components → dist/components}/ContentPanel.astro +0 -0
- /package/{components → dist/components}/DraftContentNotice.astro +0 -0
- /package/{components → dist/components}/EditLink.astro +0 -0
- /package/{components → dist/components}/FallbackContentNotice.astro +0 -0
- /package/{components → dist/components}/Footer.astro +0 -0
- /package/{components → dist/components}/Head.astro +0 -0
- /package/{components → dist/components}/Header.astro +0 -0
- /package/{components → dist/components}/Hero.astro +0 -0
- /package/{components → dist/components}/LanguageSelect.astro +0 -0
- /package/{components → dist/components}/LastUpdated.astro +0 -0
- /package/{components → dist/components}/MarkdownContent.astro +0 -0
- /package/{components → dist/components}/MobileMenuFooter.astro +0 -0
- /package/{components → dist/components}/MobileTableOfContents.astro +0 -0
- /package/{components → dist/components}/Page.astro +0 -0
- /package/{components → dist/components}/PageSidebar.astro +0 -0
- /package/{components → dist/components}/PageTitle.astro +0 -0
- /package/{components → dist/components}/Pagination.astro +0 -0
- /package/{components → dist/components}/Search.astro +0 -0
- /package/{components → dist/components}/Select.astro +0 -0
- /package/{components → dist/components}/Sidebar.astro +0 -0
- /package/{components → dist/components}/SidebarPersister.astro +0 -0
- /package/{components → dist/components}/SidebarRestorePoint.astro +0 -0
- /package/{components → dist/components}/SidebarSublist.astro +0 -0
- /package/{components → dist/components}/SiteTitle.astro +0 -0
- /package/{components → dist/components}/SkipLink.astro +0 -0
- /package/{components → dist/components}/SocialIcons.astro +0 -0
- /package/{components → dist/components}/StarlightPage.astro +0 -0
- /package/{components → dist/components}/TableOfContents.astro +0 -0
- /package/{components → dist/components}/ThemeProvider.astro +0 -0
- /package/{components → dist/components}/ThemeSelect.astro +0 -0
- /package/{components → dist/components}/TwoColumnContent.astro +0 -0
- /package/{components-internals → dist/components-internals}/TableOfContents/TableOfContentsList.astro +0 -0
- /package/{components.ts → dist/components.ts} +0 -0
- /package/{routes → dist/routes}/common.astro +0 -0
- /package/{routes → dist/routes}/ssr/404.astro +0 -0
- /package/{routes → dist/routes}/ssr/index.astro +0 -0
- /package/{routes → dist/routes}/static/404.astro +0 -0
- /package/{routes → dist/routes}/static/index.astro +0 -0
- /package/{style → dist/style}/anchor-links.css +0 -0
- /package/{style → dist/style}/asides.css +0 -0
- /package/{style → dist/style}/layers.css +0 -0
- /package/{style → dist/style}/markdown.css +0 -0
- /package/{style → dist/style}/print.css +0 -0
- /package/{style → dist/style}/props.css +0 -0
- /package/{style → dist/style}/reset.css +0 -0
- /package/{style → dist/style}/util.css +0 -0
- /package/{user-components → dist/user-components}/Aside.astro +0 -0
- /package/{user-components → dist/user-components}/Badge.astro +0 -0
- /package/{user-components → dist/user-components}/Card.astro +0 -0
- /package/{user-components → dist/user-components}/CardGrid.astro +0 -0
- /package/{user-components → dist/user-components}/Icon.astro +0 -0
- /package/{user-components → dist/user-components}/LinkButton.astro +0 -0
- /package/{user-components → dist/user-components}/LinkCard.astro +0 -0
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { PAGE_TITLE_ID } from '../../constants';
|
|
2
|
-
|
|
3
|
-
export class StarlightTOC extends HTMLElement {
|
|
4
|
-
private _current = this.querySelector<HTMLAnchorElement>('a[aria-current="true"]');
|
|
5
|
-
private minH = parseInt(this.dataset.minH || '2', 10);
|
|
6
|
-
private maxH = parseInt(this.dataset.maxH || '3', 10);
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* CSS selector string that matches only headings that can appear in the table of contents.
|
|
10
|
-
* Generates a selector like `h1#_top,:where(h2,h3)[id]`.
|
|
11
|
-
*/
|
|
12
|
-
private tocHeadingSelector =
|
|
13
|
-
`h1#${PAGE_TITLE_ID},` +
|
|
14
|
-
`:where(${[...Array.from({ length: 1 + this.maxH - this.minH }).map((_, index) => `h${this.minH + index}`)].join()})[id]`;
|
|
15
|
-
|
|
16
|
-
protected set current(link: HTMLAnchorElement) {
|
|
17
|
-
if (link === this._current) return;
|
|
18
|
-
if (this._current) this._current.removeAttribute('aria-current');
|
|
19
|
-
link.setAttribute('aria-current', 'true');
|
|
20
|
-
this._current = link;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private onIdle = (cb: IdleRequestCallback) =>
|
|
24
|
-
(window.requestIdleCallback || ((cb) => setTimeout(cb, 1)))(cb);
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
super();
|
|
28
|
-
this.onIdle(() => this.init());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private init = (): void => {
|
|
32
|
-
/** All the links in the table of contents. */
|
|
33
|
-
const links = [...this.querySelectorAll('a')];
|
|
34
|
-
|
|
35
|
-
/** Test if an element is a table-of-contents heading. */
|
|
36
|
-
const isHeading = (el: Element): el is HTMLHeadingElement =>
|
|
37
|
-
el.matches(this.tocHeadingSelector);
|
|
38
|
-
|
|
39
|
-
/** Walk up the DOM to find the nearest heading. */
|
|
40
|
-
const getElementHeading = (el: Element | null): HTMLHeadingElement | null => {
|
|
41
|
-
if (!el) return null;
|
|
42
|
-
const origin = el;
|
|
43
|
-
while (el) {
|
|
44
|
-
// Short circuit if we reach the top-level content container or one of the other containers in main.
|
|
45
|
-
if (el.matches('.sl-markdown-content, main > *')) {
|
|
46
|
-
return document.getElementById(PAGE_TITLE_ID) as HTMLHeadingElement;
|
|
47
|
-
}
|
|
48
|
-
if (isHeading(el)) return el;
|
|
49
|
-
// Find the first heading that is a child of this element, and return it if there is one.
|
|
50
|
-
const childHeading = el.querySelector<HTMLHeadingElement>(this.tocHeadingSelector);
|
|
51
|
-
if (childHeading) return childHeading;
|
|
52
|
-
// Assign the previous sibling’s last, most deeply nested child to el.
|
|
53
|
-
el = el.previousElementSibling;
|
|
54
|
-
while (el?.lastElementChild) {
|
|
55
|
-
el = el.lastElementChild;
|
|
56
|
-
}
|
|
57
|
-
// Look for headings amongst siblings.
|
|
58
|
-
const h = getElementHeading(el);
|
|
59
|
-
if (h) return h;
|
|
60
|
-
}
|
|
61
|
-
// Walk back up the parent.
|
|
62
|
-
return getElementHeading(origin.parentElement);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/** Handle intersections and set the current link to the heading for the current intersection. */
|
|
66
|
-
const setCurrent: IntersectionObserverCallback = (entries) => {
|
|
67
|
-
for (const { isIntersecting, target } of entries) {
|
|
68
|
-
if (!isIntersecting) continue;
|
|
69
|
-
const heading = getElementHeading(target);
|
|
70
|
-
if (!heading) continue;
|
|
71
|
-
const link = links.find((link) => link.hash === '#' + encodeURIComponent(heading.id));
|
|
72
|
-
if (link) {
|
|
73
|
-
this.current = link;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// Observe the following elements:
|
|
80
|
-
// - headings that appear in the table of contents
|
|
81
|
-
// - siblings of those headings or of the `.sl-heading-wrapper` added by Starlight’s anchor links feature
|
|
82
|
-
// - direct children of `.sl-markdown-content` to include elements before the first subheading
|
|
83
|
-
// - direct children of `main` that don’t include headings (mainly to target Starlight’s banner)
|
|
84
|
-
// Ignore any elements that themselves contain a table-of-contents heading, as we are already observing those children.
|
|
85
|
-
const toObserve = document.querySelectorAll(
|
|
86
|
-
[
|
|
87
|
-
`main :where(${this.tocHeadingSelector})`,
|
|
88
|
-
`main :where(${this.tocHeadingSelector}, .sl-heading-wrapper) ~ *:not(:has(${this.tocHeadingSelector}))`,
|
|
89
|
-
`main .sl-markdown-content > *:not(:has(${this.tocHeadingSelector}))`,
|
|
90
|
-
`main > *:not(:has(${this.tocHeadingSelector}))`,
|
|
91
|
-
].join()
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
let observer: IntersectionObserver | undefined;
|
|
95
|
-
const observe = () => {
|
|
96
|
-
if (observer) return;
|
|
97
|
-
observer = new IntersectionObserver(setCurrent, { rootMargin: this.getRootMargin() });
|
|
98
|
-
toObserve.forEach((h) => observer!.observe(h));
|
|
99
|
-
};
|
|
100
|
-
observe();
|
|
101
|
-
|
|
102
|
-
let timeout: NodeJS.Timeout;
|
|
103
|
-
window.addEventListener('resize', () => {
|
|
104
|
-
// Disable intersection observer while window is resizing.
|
|
105
|
-
if (observer) {
|
|
106
|
-
observer.disconnect();
|
|
107
|
-
observer = undefined;
|
|
108
|
-
}
|
|
109
|
-
clearTimeout(timeout);
|
|
110
|
-
timeout = setTimeout(() => this.onIdle(observe), 200);
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
private getRootMargin(): `-${number}px 0% ${number}px` {
|
|
115
|
-
const navBarHeight = document.querySelector('header')?.getBoundingClientRect().height || 0;
|
|
116
|
-
// `<summary>` only exists in mobile ToC, so will fall back to 0 in large viewport component.
|
|
117
|
-
const mobileTocHeight = this.querySelector('summary')?.getBoundingClientRect().height || 0;
|
|
118
|
-
/** Start intersections at nav height + 2rem padding. */
|
|
119
|
-
const top = navBarHeight + mobileTocHeight + 32;
|
|
120
|
-
/** End intersections `53px` later. This is slightly more than the maximum `margin-top` in Markdown content. */
|
|
121
|
-
const bottom = top + 53;
|
|
122
|
-
const height = document.documentElement.clientHeight;
|
|
123
|
-
return `-${top}px 0% ${bottom - height}px`;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
customElements.define('starlight-toc', StarlightTOC);
|
package/constants.ts
DELETED
package/expressive-code.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file This file is exported by Starlight as `@astrojs/starlight/expressive-code`.
|
|
3
|
-
*
|
|
4
|
-
* It is required by the `<Code>` component to access the same configuration preprocessor
|
|
5
|
-
* function as the one used by the integration.
|
|
6
|
-
*
|
|
7
|
-
* It also provides access to all of the Expressive Code classes and functions without having
|
|
8
|
-
* to install `astro-expressive-code` as an additional dependency into a user's project
|
|
9
|
-
* (and thereby risiking version conflicts).
|
|
10
|
-
*
|
|
11
|
-
* Note: This file is intentionally not a TypeScript module to allow access to all exported
|
|
12
|
-
* functionality even if TypeScript is not available, e.g. from the `ec.config.mjs` file
|
|
13
|
-
* that does not get processed by Vite.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export * from 'astro-expressive-code';
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
-
// @ts-ignore - Types are provided by the separate `expressive-code.d.ts` file and this may not be
|
|
20
|
-
// a type error for some users running `tsc --noEmit` depending on their `tsconfig.json` settings.
|
|
21
|
-
export function defineEcConfig(config) {
|
|
22
|
-
return config;
|
|
23
|
-
}
|
package/global.d.ts
DELETED
package/i18n.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file imports the original `i18next` types and extends them to configure the
|
|
3
|
-
* Starlight namespace.
|
|
4
|
-
*
|
|
5
|
-
* Note that the top-level `import` makes this module non-ambient, so can’t be
|
|
6
|
-
* combined with other `.d.ts` files such as `locals.d.ts`.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import 'i18next';
|
|
10
|
-
|
|
11
|
-
declare module 'i18next' {
|
|
12
|
-
interface CustomTypeOptions {
|
|
13
|
-
defaultNS: typeof import('./utils/createTranslationSystem').I18nextNamespace;
|
|
14
|
-
resources: {
|
|
15
|
-
starlight: Record<import('./utils/createTranslationSystem').I18nKeys, string>;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
package/index.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* These triple-slash directives defines dependencies to various declaration files that will be
|
|
3
|
-
* loaded when a user imports the Starlight integration in their Astro configuration file. These
|
|
4
|
-
* directives must be first at the top of the file and can only be preceded by this comment.
|
|
5
|
-
*/
|
|
6
|
-
/// <reference path="./locals.d.ts" />
|
|
7
|
-
/// <reference path="./i18n.d.ts" />
|
|
8
|
-
/// <reference path="./virtual.d.ts" />
|
|
9
|
-
|
|
10
|
-
import mdx from '@astrojs/mdx';
|
|
11
|
-
import type { AstroIntegration } from 'astro';
|
|
12
|
-
import { AstroError } from 'astro/errors';
|
|
13
|
-
import type { MarkdownProcessorPluginOptions } from './integrations/markdown-processor';
|
|
14
|
-
import {
|
|
15
|
-
applyStarlightMarkdownPlugins,
|
|
16
|
-
starlightDirectivesRestorationIntegration,
|
|
17
|
-
unifiedIntegration,
|
|
18
|
-
} from './integrations/markdown-plugins';
|
|
19
|
-
import { starlightExpressiveCode } from './integrations/expressive-code/index';
|
|
20
|
-
import { starlightPagefind } from './integrations/pagefind';
|
|
21
|
-
import { starlightSitemap } from './integrations/sitemap';
|
|
22
|
-
import { vitePluginStarlightCssLayerOrder } from './integrations/vite-layer-order';
|
|
23
|
-
import { vitePluginStarlightLazyBarrelOptimization } from './integrations/vite-lazy-barrel-optimization';
|
|
24
|
-
import { vitePluginStarlightVirtualModules } from './integrations/vite-virtual-modules';
|
|
25
|
-
import {
|
|
26
|
-
injectPluginTranslationsTypes,
|
|
27
|
-
runPlugins,
|
|
28
|
-
type PluginTranslations,
|
|
29
|
-
type StarlightUserConfigWithPlugins,
|
|
30
|
-
} from './utils/plugins';
|
|
31
|
-
import { processI18nConfig } from './utils/i18n';
|
|
32
|
-
import type { StarlightConfig } from './types';
|
|
33
|
-
|
|
34
|
-
export default function StarlightIntegration(
|
|
35
|
-
userOpts: StarlightUserConfigWithPlugins
|
|
36
|
-
): AstroIntegration {
|
|
37
|
-
if (typeof userOpts !== 'object' || userOpts === null || Array.isArray(userOpts))
|
|
38
|
-
throw new AstroError(
|
|
39
|
-
'Invalid config passed to starlight integration',
|
|
40
|
-
`The Starlight integration expects a configuration object with at least a \`title\` property.\n\n` +
|
|
41
|
-
`See more details in the [Starlight configuration reference](https://starlight.astro.build/reference/configuration/)\n`
|
|
42
|
-
);
|
|
43
|
-
const { plugins, ...opts } = userOpts;
|
|
44
|
-
let userConfig: StarlightConfig;
|
|
45
|
-
let pluginTranslations: PluginTranslations = {};
|
|
46
|
-
return {
|
|
47
|
-
name: '@astrojs/starlight',
|
|
48
|
-
hooks: {
|
|
49
|
-
'astro:config:setup': async ({
|
|
50
|
-
addMiddleware,
|
|
51
|
-
command,
|
|
52
|
-
config,
|
|
53
|
-
injectRoute,
|
|
54
|
-
isRestart,
|
|
55
|
-
logger,
|
|
56
|
-
updateConfig,
|
|
57
|
-
}) => {
|
|
58
|
-
// Run plugins to get the updated configuration and any extra Astro integrations to load.
|
|
59
|
-
const pluginResult = await runPlugins(opts, plugins, {
|
|
60
|
-
command,
|
|
61
|
-
config,
|
|
62
|
-
isRestart,
|
|
63
|
-
logger,
|
|
64
|
-
});
|
|
65
|
-
// Process the Astro and Starlight configurations for i18n and translations.
|
|
66
|
-
const { astroI18nConfig, starlightConfig } = processI18nConfig(
|
|
67
|
-
pluginResult.starlightConfig,
|
|
68
|
-
config.i18n
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const { integrations, useTranslations, absolutePathToLang } = pluginResult;
|
|
72
|
-
pluginTranslations = pluginResult.pluginTranslations;
|
|
73
|
-
userConfig = starlightConfig;
|
|
74
|
-
|
|
75
|
-
addMiddleware({ entrypoint: '@astrojs/starlight/locals', order: 'pre' });
|
|
76
|
-
|
|
77
|
-
if (!starlightConfig.disable404Route) {
|
|
78
|
-
injectRoute({
|
|
79
|
-
pattern: '404',
|
|
80
|
-
entrypoint: starlightConfig.prerender
|
|
81
|
-
? '@astrojs/starlight/routes/static/404.astro'
|
|
82
|
-
: '@astrojs/starlight/routes/ssr/404.astro',
|
|
83
|
-
prerender: starlightConfig.prerender,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
injectRoute({
|
|
87
|
-
pattern: '[...slug]',
|
|
88
|
-
entrypoint: starlightConfig.prerender
|
|
89
|
-
? '@astrojs/starlight/routes/static/index.astro'
|
|
90
|
-
: '@astrojs/starlight/routes/ssr/index.astro',
|
|
91
|
-
prerender: starlightConfig.prerender,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Resolve the configured processor and the optional Unified integration up front before
|
|
95
|
-
// wiring up the integrations below.
|
|
96
|
-
const processor = config.markdown.processor;
|
|
97
|
-
const unified = await unifiedIntegration;
|
|
98
|
-
|
|
99
|
-
// Add built-in integrations only if they are not already added by the user through the
|
|
100
|
-
// config or by a plugin.
|
|
101
|
-
const allIntegrations = [...config.integrations, ...integrations];
|
|
102
|
-
if (!allIntegrations.find(({ name }) => name === 'astro-expressive-code')) {
|
|
103
|
-
integrations.push(
|
|
104
|
-
...starlightExpressiveCode({ astroConfig: config, starlightConfig, useTranslations })
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
if (!allIntegrations.find(({ name }) => name === '@astrojs/sitemap')) {
|
|
108
|
-
integrations.push(starlightSitemap(starlightConfig));
|
|
109
|
-
}
|
|
110
|
-
if (!allIntegrations.find(({ name }) => name === '@astrojs/mdx')) {
|
|
111
|
-
integrations.push(mdx({ optimize: true }));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const markdownProcessorOptions: MarkdownProcessorPluginOptions = {
|
|
115
|
-
starlightConfig,
|
|
116
|
-
astroConfig: config,
|
|
117
|
-
useTranslations,
|
|
118
|
-
absolutePathToLang,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// We push our plugins onto the processor's options.
|
|
122
|
-
applyStarlightMarkdownPlugins(processor, markdownProcessorOptions, unified, logger);
|
|
123
|
-
|
|
124
|
-
// Add Starlight directives restoration integration at the end of the list so that
|
|
125
|
-
// remark/mdast plugins injected by Starlight plugins through Astro integrations can
|
|
126
|
-
// handle text and leaf directives before they are transformed back to their original
|
|
127
|
-
// form.
|
|
128
|
-
integrations.push(starlightDirectivesRestorationIntegration());
|
|
129
|
-
|
|
130
|
-
// Add integrations immediately after Starlight in the config array.
|
|
131
|
-
// e.g. if a user has `integrations: [starlight(), tailwind()]`, then the order will be
|
|
132
|
-
// `[starlight(), expressiveCode(), sitemap(), mdx(), tailwind()]`.
|
|
133
|
-
// This ensures users can add integrations before/after Starlight and we respect that order.
|
|
134
|
-
const selfIndex = config.integrations.findIndex((i) => i.name === '@astrojs/starlight');
|
|
135
|
-
config.integrations.splice(selfIndex + 1, 0, ...integrations);
|
|
136
|
-
|
|
137
|
-
// TODO: refactor once there is a reliable way to detect non-Node.js compatible
|
|
138
|
-
// environments, rather than relying on the presence of specific adapters/integrations.
|
|
139
|
-
const isCloudflareEnv =
|
|
140
|
-
config.adapter?.name === '@astrojs/cloudflare' ||
|
|
141
|
-
config.integrations.some(({ name }) => name === '@astrojs/cloudflare');
|
|
142
|
-
const isNodeCompatibleEnv = !isCloudflareEnv;
|
|
143
|
-
|
|
144
|
-
updateConfig({
|
|
145
|
-
vite: {
|
|
146
|
-
plugins: [
|
|
147
|
-
vitePluginStarlightCssLayerOrder(),
|
|
148
|
-
vitePluginStarlightLazyBarrelOptimization(),
|
|
149
|
-
vitePluginStarlightVirtualModules(
|
|
150
|
-
{ command, isNodeCompatibleEnv },
|
|
151
|
-
starlightConfig,
|
|
152
|
-
config,
|
|
153
|
-
pluginTranslations
|
|
154
|
-
),
|
|
155
|
-
],
|
|
156
|
-
ssr: isNodeCompatibleEnv
|
|
157
|
-
? {}
|
|
158
|
-
: {
|
|
159
|
-
optimizeDeps: {
|
|
160
|
-
include: [
|
|
161
|
-
// Prebundle some dependencies for non-Node.js compatible environments to
|
|
162
|
-
// speed up dev server start time and prevent restarts.
|
|
163
|
-
'@astrojs/cloudflare/entrypoints/server',
|
|
164
|
-
'@astrojs/starlight>i18next',
|
|
165
|
-
'@astrojs/starlight>js-yaml',
|
|
166
|
-
'@astrojs/starlight>klona/lite',
|
|
167
|
-
// TODO: once Expressive Code is refactored/fixed, remove this workaround for
|
|
168
|
-
// Expressive Code relying on CJS dependencies like postcss not compatible
|
|
169
|
-
// with non-Node.js compatible environments like Cloudflare.
|
|
170
|
-
'@astrojs/starlight>astro-expressive-code/components',
|
|
171
|
-
'@astrojs/starlight>astro-expressive-code>hast-util-select',
|
|
172
|
-
'@astrojs/starlight>astro-expressive-code>rehype',
|
|
173
|
-
'@astrojs/starlight>astro-expressive-code>unist-util-visit',
|
|
174
|
-
'@astrojs/starlight>astro-expressive-code>rehype-format',
|
|
175
|
-
'@astrojs/starlight>astro-expressive-code>hastscript',
|
|
176
|
-
'@astrojs/starlight>astro-expressive-code>hast-util-from-html',
|
|
177
|
-
'@astrojs/starlight>astro-expressive-code>hast-util-to-string',
|
|
178
|
-
'@astrojs/starlight>astro-expressive-code>@expressive-code/core>postcss',
|
|
179
|
-
],
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
scopedStyleStrategy: 'where',
|
|
184
|
-
// If not already configured, default to prefetching all links on hover.
|
|
185
|
-
prefetch: config.prefetch ?? { prefetchAll: true },
|
|
186
|
-
i18n: astroI18nConfig,
|
|
187
|
-
});
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
'astro:config:done': ({ injectTypes }) => {
|
|
191
|
-
injectPluginTranslationsTypes(pluginTranslations, injectTypes);
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
'astro:build:done': async (options) => {
|
|
195
|
-
if (!userConfig.pagefind) return;
|
|
196
|
-
return starlightPagefind(options);
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
};
|
|
200
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AstroError } from 'astro/errors';
|
|
2
|
-
import { Icons, type StarlightIcon } from '../components-internals/Icons';
|
|
3
|
-
|
|
4
|
-
export const asideVariants = ['note', 'tip', 'caution', 'danger'] as const;
|
|
5
|
-
export type AsideVariant = (typeof asideVariants)[number];
|
|
6
|
-
|
|
7
|
-
// A map of aside variants to their default Starlight icon names.
|
|
8
|
-
const asideIconNames: Record<AsideVariant, StarlightIcon> = {
|
|
9
|
-
note: 'information',
|
|
10
|
-
tip: 'rocket',
|
|
11
|
-
caution: 'warning',
|
|
12
|
-
danger: 'error',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const asideVariantSet = new Set<string>(asideVariants);
|
|
16
|
-
export function isAsideVariant(value: string): value is AsideVariant {
|
|
17
|
-
return asideVariantSet.has(value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function getAsideIconName(variant: AsideVariant, customIcon?: string | null): StarlightIcon {
|
|
21
|
-
let iconName = asideIconNames[variant];
|
|
22
|
-
|
|
23
|
-
if (customIcon) {
|
|
24
|
-
iconName = customIcon as StarlightIcon;
|
|
25
|
-
if (!Icons[iconName]) throwInvalidAsideIconError(iconName);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return iconName;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function getAsideIcon(variant: AsideVariant, customIcon?: string | null) {
|
|
32
|
-
return Icons[getAsideIconName(variant, customIcon)];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function throwInvalidAsideIconError(icon: string) {
|
|
36
|
-
throw new AstroError(
|
|
37
|
-
'Invalid aside icon',
|
|
38
|
-
`An aside custom icon must be set to the name of one of Starlight’s built-in icons, but received \`${icon}\`.\n\n` +
|
|
39
|
-
'See https://starlight.astro.build/reference/icons/#all-icons for a list of available icons.'
|
|
40
|
-
);
|
|
41
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file This file is exported by Starlight as `@astrojs/starlight/expressive-code/hast`.
|
|
3
|
-
*
|
|
4
|
-
* Note: This file is intentionally not a TypeScript module to allow access to all exported
|
|
5
|
-
* functionality even if TypeScript is not available, e.g. from the `ec.config.mjs` file
|
|
6
|
-
* that does not get processed by Vite.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export * from 'astro-expressive-code/hast';
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { astroExpressiveCode, type AstroExpressiveCodeOptions } from 'astro-expressive-code';
|
|
2
|
-
import type { AstroConfig, AstroIntegration } from 'astro';
|
|
3
|
-
import type { HookParameters, StarlightConfig } from '../../types';
|
|
4
|
-
import { getStarlightEcConfigPreprocessor } from './preprocessor';
|
|
5
|
-
import { type ThemeObjectOrBundledThemeName } from './theming';
|
|
6
|
-
import { getCollectionPosixPath } from '../../utils/collection-fs';
|
|
7
|
-
|
|
8
|
-
export type StarlightExpressiveCodeOptions = Omit<AstroExpressiveCodeOptions, 'themes'> & {
|
|
9
|
-
/**
|
|
10
|
-
* Set the themes used to style code blocks.
|
|
11
|
-
*
|
|
12
|
-
* See the [Expressive Code `themes` documentation](https://expressive-code.com/guides/themes/)
|
|
13
|
-
* for details of the supported theme formats.
|
|
14
|
-
*
|
|
15
|
-
* Starlight uses the dark and light variants of Sarah Drasner’s
|
|
16
|
-
* [Night Owl theme](https://github.com/sdras/night-owl-vscode-theme) by default.
|
|
17
|
-
*
|
|
18
|
-
* If you provide at least one dark and one light theme, Starlight will automatically keep
|
|
19
|
-
* the active code block theme in sync with the current site theme. Configure this behavior
|
|
20
|
-
* with the [`useStarlightDarkModeSwitch`](#usestarlightdarkmodeswitch) option.
|
|
21
|
-
*
|
|
22
|
-
* Defaults to `['starlight-dark', 'starlight-light']`.
|
|
23
|
-
*/
|
|
24
|
-
themes?: ThemeObjectOrBundledThemeName[] | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* When `true`, code blocks automatically switch between light and dark themes when the
|
|
27
|
-
* site theme changes.
|
|
28
|
-
*
|
|
29
|
-
* When `false`, you must manually add CSS to handle switching between multiple themes.
|
|
30
|
-
*
|
|
31
|
-
* **Note**: When setting `themes`, you must provide at least one dark and one light theme
|
|
32
|
-
* for the Starlight dark mode switch to work.
|
|
33
|
-
*
|
|
34
|
-
* Defaults to `true`.
|
|
35
|
-
*/
|
|
36
|
-
useStarlightDarkModeSwitch?: boolean | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* When `true`, Starlight's CSS variables are used for the colors of code block UI elements
|
|
39
|
-
* (backgrounds, buttons, shadows etc.), matching the
|
|
40
|
-
* [site color theme](/guides/css-and-tailwind/#theming).
|
|
41
|
-
*
|
|
42
|
-
* When `false`, the colors provided by the active syntax highlighting theme are used for
|
|
43
|
-
* these elements.
|
|
44
|
-
*
|
|
45
|
-
* Defaults to `true` if the `themes` option is not set (= you are using Starlight's
|
|
46
|
-
* default themes), and `false` otherwise.
|
|
47
|
-
*
|
|
48
|
-
* **Note**: When manually setting this to `true` with your custom set of `themes`, you must
|
|
49
|
-
* provide at least one dark and one light theme to ensure proper color contrast.
|
|
50
|
-
*/
|
|
51
|
-
useStarlightUiThemeColors?: boolean | undefined;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type StarlightEcIntegrationOptions = {
|
|
55
|
-
astroConfig: AstroConfig;
|
|
56
|
-
starlightConfig: StarlightConfig;
|
|
57
|
-
useTranslations: HookParameters<'config:setup'>['useTranslations'];
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const starlightExpressiveCode = ({
|
|
61
|
-
astroConfig,
|
|
62
|
-
starlightConfig,
|
|
63
|
-
useTranslations,
|
|
64
|
-
}: StarlightEcIntegrationOptions): AstroIntegration[] => {
|
|
65
|
-
// If Expressive Code is disabled, add a shim to prevent build errors and provide
|
|
66
|
-
// a helpful error message in case the user tries to use the `<Code>` component
|
|
67
|
-
if (starlightConfig.expressiveCode === false) {
|
|
68
|
-
const modules: Record<string, string> = {
|
|
69
|
-
'virtual:astro-expressive-code/api': 'export default {}',
|
|
70
|
-
'virtual:astro-expressive-code/config': 'export default {}',
|
|
71
|
-
'virtual:astro-expressive-code/preprocess-config': `throw new Error("Starlight's
|
|
72
|
-
Code component requires Expressive Code, which is disabled in your Starlight config.
|
|
73
|
-
Please remove \`expressiveCode: false\` from your config or import Astro's built-in
|
|
74
|
-
Code component from 'astro:components' instead.")`.replace(/\s+/g, ' '),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return [
|
|
78
|
-
{
|
|
79
|
-
name: 'astro-expressive-code-shim',
|
|
80
|
-
hooks: {
|
|
81
|
-
'astro:config:setup': ({ updateConfig }) => {
|
|
82
|
-
updateConfig({
|
|
83
|
-
vite: {
|
|
84
|
-
plugins: [
|
|
85
|
-
{
|
|
86
|
-
name: 'vite-plugin-astro-expressive-code-shim',
|
|
87
|
-
enforce: 'post',
|
|
88
|
-
resolveId: (id) => (id in modules ? `\0${id}` : undefined),
|
|
89
|
-
load: (id) => (id?.[0] === '\0' ? modules[id.slice(1)] : undefined),
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const configArgs =
|
|
101
|
-
typeof starlightConfig.expressiveCode === 'object'
|
|
102
|
-
? (starlightConfig.expressiveCode as AstroExpressiveCodeOptions)
|
|
103
|
-
: {};
|
|
104
|
-
|
|
105
|
-
const docsPath = getCollectionPosixPath('docs', astroConfig.srcDir);
|
|
106
|
-
|
|
107
|
-
return [
|
|
108
|
-
astroExpressiveCode({
|
|
109
|
-
...configArgs,
|
|
110
|
-
customConfigPreprocessors: {
|
|
111
|
-
preprocessAstroIntegrationConfig: getStarlightEcConfigPreprocessor({
|
|
112
|
-
docsPath,
|
|
113
|
-
starlightConfig,
|
|
114
|
-
useTranslations,
|
|
115
|
-
}),
|
|
116
|
-
preprocessComponentConfig: `
|
|
117
|
-
import starlightConfig from 'virtual:starlight/user-config'
|
|
118
|
-
import { useTranslations, getStarlightEcConfigPreprocessor } from '@astrojs/starlight/internal'
|
|
119
|
-
|
|
120
|
-
export default getStarlightEcConfigPreprocessor({ docsPath: ${JSON.stringify(docsPath)}, starlightConfig, useTranslations })
|
|
121
|
-
`,
|
|
122
|
-
},
|
|
123
|
-
}),
|
|
124
|
-
];
|
|
125
|
-
};
|