@rimelight/ui 0.0.33 → 0.0.35
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 +158 -157
- package/package.json +100 -105
- package/src/components/astro/RLAAccordion.astro +94 -18
- package/src/components/astro/RLAAspectRatio.astro +2 -2
- package/src/components/astro/RLAAvatar.astro +135 -68
- package/src/components/astro/RLABadge.astro +4 -2
- package/src/components/astro/RLABanner.astro +138 -23
- package/src/components/astro/RLABreadcrumb.astro +13 -0
- package/src/components/astro/RLAButton.astro +145 -139
- package/src/components/astro/RLACallout.astro +112 -0
- package/src/components/astro/RLACard.astro +6 -5
- package/src/components/astro/RLACarousel.astro +104 -75
- package/src/components/astro/RLAChart.astro +23 -35
- package/src/components/astro/RLAChip.astro +11 -5
- package/src/components/astro/RLACollapsible.astro +4 -1
- package/src/components/astro/RLAColorArea.astro +432 -0
- package/src/components/astro/RLAColorField.astro +300 -0
- package/src/components/astro/RLAColorSlider.astro +413 -0
- package/src/components/astro/RLAConfirm.astro +13 -11
- package/src/components/astro/RLACopyMarkdown.astro +78 -0
- package/src/components/astro/RLADate.astro +30 -0
- package/src/components/astro/RLADrawer.astro +50 -3
- package/src/components/astro/RLADropdownMenu.astro +78 -51
- package/src/components/astro/RLAFieldGroup.astro +4 -1
- package/src/components/astro/RLAFileUpload.astro +114 -100
- package/src/components/astro/RLAFooter.astro +2 -1
- package/src/components/astro/RLAFormField.astro +10 -6
- package/src/components/astro/RLAGrid.astro +31 -39
- package/src/components/astro/RLAHead.astro +528 -197
- package/src/components/astro/RLAHeader.astro +67 -59
- package/src/components/astro/RLAImage.astro +274 -209
- package/src/components/astro/RLAInput.astro +14 -9
- package/src/components/astro/RLAInputMenu.astro +119 -83
- package/src/components/astro/RLAKbd.astro +5 -5
- package/src/components/astro/RLALayoutGrid.astro +395 -0
- package/src/components/astro/RLALink.astro +44 -23
- package/src/components/astro/RLALinkGroup.astro +99 -37
- package/src/components/astro/RLALocaleSelector.astro +130 -113
- package/src/components/astro/RLALogo.astro +117 -90
- package/src/components/astro/RLAMain.astro +8 -3
- package/src/components/astro/RLAMarquee.astro +9 -2
- package/src/components/astro/RLAModal.astro +48 -18
- package/src/components/astro/RLANavigationMenu.astro +381 -137
- package/src/components/astro/{RLADocsPackageManagers.astro → RLAPackageManagers.astro} +81 -87
- package/src/components/astro/RLAPageSection.astro +4 -2
- package/src/components/astro/RLAPagination.astro +2 -4
- package/src/components/astro/RLAPopover.astro +4 -3
- package/src/components/astro/RLAPost.astro +11 -2
- package/src/components/astro/RLAProgress.astro +8 -2
- package/src/components/astro/RLAScrollArea.astro +4 -1
- package/src/components/astro/RLAScrollToTop.astro +200 -172
- package/src/components/astro/RLASearch.astro +282 -0
- package/src/components/astro/RLASelect.astro +101 -64
- package/src/components/astro/RLASeparator.astro +11 -6
- package/src/components/astro/RLAShare.astro +60 -0
- package/src/components/astro/RLAShortcuts.astro +429 -0
- package/src/components/astro/RLASidebar.astro +158 -212
- package/src/components/astro/RLASlideover.astro +99 -4
- package/src/components/astro/RLASlider.astro +14 -14
- package/src/components/astro/RLASplitter.astro +207 -142
- package/src/components/astro/RLASteps.astro +118 -71
- package/src/components/astro/RLAStickySurface.astro +9 -2
- package/src/components/astro/RLASurround.astro +39 -0
- package/src/components/astro/RLATable.astro +4 -1
- package/src/components/astro/RLATableOfContents.astro +109 -23
- package/src/components/astro/RLATabs.astro +147 -133
- package/src/components/astro/RLATextarea.astro +4 -1
- package/src/components/astro/RLAThemeSelector.astro +105 -76
- package/src/components/astro/RLAToast.astro +35 -21
- package/src/components/vue/RLVBanner.vue +230 -0
- package/src/components/vue/RLVButton.vue +3 -2
- package/src/components/vue/RLVCheckbox.vue +70 -68
- package/src/components/vue/RLVFooter.vue +3 -2
- package/src/components/vue/RLVForm.vue +44 -44
- package/src/components/vue/RLVFormField.vue +58 -58
- package/src/components/vue/RLVHeader.vue +3 -2
- package/src/components/vue/RLVIcon.vue +4 -2
- package/src/components/vue/RLVInput.vue +94 -93
- package/src/components/vue/RLVLogo.vue +25 -3
- package/src/components/vue/RLVPlaceholder.vue +3 -2
- package/src/components/vue/RLVPost.vue +69 -63
- package/src/components/vue/RLVPosts.vue +21 -21
- package/src/components/vue/RLVProgress.vue +60 -0
- package/src/components/vue/RLVScrollToTop.vue +65 -52
- package/src/components/vue/RLVSection.vue +14 -13
- package/src/components/vue/RLVToast.vue +81 -68
- package/src/components/vue/RLVToaster.vue +29 -29
- package/src/composables/index.ts +4 -3
- package/src/composables/useHeaderStore.ts +14 -14
- package/src/composables/useScrollToTop.ts +62 -62
- package/src/composables/useShortcuts.ts +11 -0
- package/src/composables/useToast.ts +43 -42
- package/src/config/index.ts +1 -0
- package/src/config/security.ts +227 -0
- package/src/config/site.config.ts +1 -0
- package/src/docs/components/ApiChangelog.astro +147 -0
- package/src/{plugins/starlightDocsApi → docs}/components/ApiEmits.astro +4 -4
- package/src/{plugins/starlightDocsApi → docs}/components/ApiProps.astro +4 -4
- package/src/{plugins/starlightDocsApi → docs}/components/ApiSlots.astro +4 -4
- package/src/docs/components/ApiTheme.astro +100 -0
- package/src/docs/extractAll.ts +94 -0
- package/src/docs/extractors/extractAstro.ts +69 -0
- package/src/docs/extractors/extractTheme.ts +56 -0
- package/src/{plugins/starlightDocsApi/extract-vue.ts → docs/extractors/extractVue.ts} +164 -15
- package/src/{plugins/starlightDocsApi → docs}/utils.ts +1 -2
- package/src/env.d.ts +0 -12
- package/src/integrations/ui.ts +215 -199
- package/src/middleware/security.ts +145 -29
- package/src/presets/defaults.ts +297 -297
- package/src/presets/index.ts +508 -637
- package/src/styles/index.css +158 -160
- package/src/themes/3d-hover.theme.ts +13 -13
- package/src/themes/accordion.theme.ts +39 -13
- package/src/themes/app.theme.ts +13 -13
- package/src/themes/aspect-ratio.theme.ts +1 -1
- package/src/themes/audio.theme.ts +13 -13
- package/src/themes/avatar-group.theme.ts +1 -1
- package/src/themes/avatar.theme.ts +84 -84
- package/src/themes/badge.theme.ts +168 -163
- package/src/themes/banner.theme.ts +49 -13
- package/src/themes/breadcrumb.theme.ts +1 -1
- package/src/themes/browser-mockup.theme.ts +13 -13
- package/src/themes/button.theme.ts +223 -202
- package/src/themes/calendar.theme.ts +13 -13
- package/src/themes/{alert.theme.ts → callout.theme.ts} +104 -125
- package/src/themes/card.theme.ts +50 -42
- package/src/themes/carousel.theme.ts +1 -1
- package/src/themes/chart.theme.ts +22 -22
- package/src/themes/chat-message.theme.ts +13 -13
- package/src/themes/chat-messages.theme.ts +13 -13
- package/src/themes/chat-palette.theme.ts +13 -13
- package/src/themes/chat-prompt-submit.theme.ts +13 -13
- package/src/themes/chat-prompt.theme.ts +13 -13
- package/src/themes/chat-reasoning.theme.ts +13 -13
- package/src/themes/chat-shimmer.theme.ts +13 -13
- package/src/themes/chat-tool.theme.ts +13 -13
- package/src/themes/chat.theme.ts +13 -13
- package/src/themes/checkbox.theme.ts +49 -50
- package/src/themes/chip.theme.ts +73 -74
- package/src/themes/color-area.theme.ts +33 -0
- package/src/themes/color-field.theme.ts +32 -0
- package/src/themes/color-picker.theme.ts +13 -13
- package/src/themes/color-slider.theme.ts +34 -0
- package/src/themes/command-palette.theme.ts +13 -13
- package/src/themes/compare.theme.ts +13 -13
- package/src/themes/confirm.theme.ts +48 -48
- package/src/themes/container.theme.ts +13 -13
- package/src/themes/context-menu.theme.ts +13 -13
- package/src/themes/dashboard-group.theme.ts +13 -13
- package/src/themes/dashboard-navbar.theme.ts +13 -13
- package/src/themes/dashboard-panel.theme.ts +13 -13
- package/src/themes/dashboard-resize-handle.theme.ts +13 -13
- package/src/themes/dashboard-search-button.theme.ts +13 -13
- package/src/themes/dashboard-search.theme.ts +13 -13
- package/src/themes/dashboard-sidebar-collapse.theme.ts +13 -13
- package/src/themes/dashboard-sidebar-toggle.theme.ts +13 -13
- package/src/themes/dashboard-sidebar.theme.ts +13 -13
- package/src/themes/dashboard-toolbar.theme.ts +13 -13
- package/src/themes/dock.theme.ts +13 -13
- package/src/themes/drawer.theme.ts +61 -61
- package/src/themes/dropdown-menu.theme.ts +29 -29
- package/src/themes/editor.theme.ts +13 -13
- package/src/themes/empty.theme.ts +13 -13
- package/src/themes/error.theme.ts +13 -13
- package/src/themes/field-group.theme.ts +24 -24
- package/src/themes/fieldset.theme.ts +13 -13
- package/src/themes/floating-action.theme.ts +13 -13
- package/src/themes/footer.theme.ts +30 -30
- package/src/themes/form.theme.ts +13 -13
- package/src/themes/gallery.theme.ts +13 -13
- package/src/themes/grid.theme.ts +38 -0
- package/src/themes/head.theme.ts +13 -13
- package/src/themes/header.theme.ts +46 -46
- package/src/themes/hover-card.theme.ts +1 -1
- package/src/themes/icon.theme.ts +23 -23
- package/src/themes/image.theme.ts +33 -19
- package/src/themes/input-date.theme.ts +13 -13
- package/src/themes/input-menu.theme.ts +35 -35
- package/src/themes/input-number.theme.ts +13 -13
- package/src/themes/input-tags.theme.ts +13 -13
- package/src/themes/input-time.theme.ts +13 -13
- package/src/themes/input.theme.ts +48 -42
- package/src/themes/kbd.theme.ts +94 -89
- package/src/themes/knob.theme.ts +13 -13
- package/src/themes/label.theme.ts +1 -1
- package/src/themes/layout-grid.theme.ts +16 -0
- package/src/themes/link-group.theme.ts +28 -32
- package/src/themes/link.theme.ts +13 -13
- package/src/themes/listbox.theme.ts +13 -13
- package/src/themes/locale-selector.theme.ts +49 -49
- package/src/themes/logo.theme.ts +13 -13
- package/src/themes/main.theme.ts +13 -13
- package/src/themes/marquee.theme.ts +1 -1
- package/src/themes/meter.theme.ts +13 -13
- package/src/themes/modal.theme.ts +1 -1
- package/src/themes/navigation-menu.theme.ts +44 -27
- package/src/themes/page-aside.theme.ts +13 -13
- package/src/themes/page-body.theme.ts +13 -13
- package/src/themes/page-header.theme.ts +13 -13
- package/src/themes/page-section.theme.ts +189 -187
- package/src/themes/page.theme.ts +13 -13
- package/src/themes/pagination.theme.ts +1 -1
- package/src/themes/password.theme.ts +13 -13
- package/src/themes/phone-mockup.theme.ts +13 -13
- package/src/themes/pin-input.theme.ts +1 -1
- package/src/themes/placeholder.theme.ts +15 -15
- package/src/themes/popover.theme.ts +1 -1
- package/src/themes/post.theme.ts +53 -33
- package/src/themes/pricing-plan.theme.ts +13 -13
- package/src/themes/pricing-table.theme.ts +13 -13
- package/src/themes/progress.theme.ts +37 -38
- package/src/themes/prose.theme.ts +13 -13
- package/src/themes/qr-code.theme.ts +13 -13
- package/src/themes/quote.theme.ts +13 -13
- package/src/themes/radio-group.theme.ts +13 -13
- package/src/themes/rating.theme.ts +13 -13
- package/src/themes/scroll-area.theme.ts +26 -26
- package/src/themes/scroll-to-top.theme.ts +51 -52
- package/src/themes/search.theme.ts +64 -0
- package/src/themes/select.theme.ts +29 -29
- package/src/themes/separator.theme.ts +147 -147
- package/src/themes/sidebar.theme.ts +38 -38
- package/src/themes/skeleton.theme.ts +21 -21
- package/src/themes/slideover.theme.ts +5 -5
- package/src/themes/slider.theme.ts +35 -36
- package/src/themes/speed-dial.theme.ts +13 -13
- package/src/themes/spinner.theme.ts +33 -34
- package/src/themes/splitter.theme.ts +23 -23
- package/src/themes/spoiler.theme.ts +13 -13
- package/src/themes/stepper.theme.ts +13 -13
- package/src/themes/{megamenu.theme.ts → steps.theme.ts} +13 -13
- package/src/themes/sticky-surface.theme.ts +1 -1
- package/src/themes/switch.theme.ts +66 -67
- package/src/themes/table-of-contents.theme.ts +67 -48
- package/src/themes/tabs.theme.ts +52 -52
- package/src/themes/textarea.theme.ts +27 -27
- package/src/themes/theme-selector.theme.ts +15 -15
- package/src/themes/timeline.theme.ts +18 -13
- package/src/themes/toast.theme.ts +31 -31
- package/src/themes/tooltip.theme.ts +28 -28
- package/src/themes/tour.theme.ts +13 -13
- package/src/themes/tree.theme.ts +13 -13
- package/src/themes/user.theme.ts +13 -13
- package/src/themes/video.theme.ts +17 -17
- package/src/themes/watermark.theme.ts +13 -13
- package/src/themes/window-mockup.theme.ts +13 -13
- package/src/types/components/3d-hover.ts +11 -11
- package/src/types/components/accordion.ts +35 -2
- package/src/types/components/app.ts +11 -11
- package/src/types/components/audio.ts +11 -11
- package/src/types/components/avatar-group.ts +11 -11
- package/src/types/components/avatar.ts +76 -60
- package/src/types/components/badge.ts +2 -2
- package/src/types/components/banner.ts +53 -11
- package/src/types/components/browser-mockup.ts +11 -11
- package/src/types/components/button.ts +73 -81
- package/src/types/components/calendar.ts +11 -11
- package/src/types/components/{alert.ts → callout.ts} +8 -8
- package/src/types/components/changelog.ts +11 -11
- package/src/types/components/chart.ts +2 -1
- package/src/types/components/chat-message.ts +11 -11
- package/src/types/components/chat-messages.ts +11 -11
- package/src/types/components/chat-palette.ts +11 -11
- package/src/types/components/chat-prompt-submit.ts +11 -11
- package/src/types/components/chat-prompt.ts +11 -11
- package/src/types/components/chat-reasoning.ts +11 -11
- package/src/types/components/chat-shimmer.ts +11 -11
- package/src/types/components/chat-tool.ts +11 -11
- package/src/types/components/chat.ts +11 -11
- package/src/types/components/checkbox.ts +2 -2
- package/src/types/components/chip.ts +17 -17
- package/src/types/components/collapsible.ts +2 -1
- package/src/types/components/color-area.ts +19 -0
- package/src/types/components/color-field.ts +21 -0
- package/src/types/components/color-picker.ts +11 -11
- package/src/types/components/color-slider.ts +20 -0
- package/src/types/components/command-palette.ts +11 -11
- package/src/types/components/compare.ts +11 -11
- package/src/types/components/container.ts +17 -17
- package/src/types/components/context-menu.ts +11 -11
- package/src/types/components/dashboard-group.ts +11 -11
- package/src/types/components/dashboard-navbar.ts +11 -11
- package/src/types/components/dashboard-panel.ts +11 -11
- package/src/types/components/dashboard-resize-handle.ts +11 -11
- package/src/types/components/dashboard-search-button.ts +11 -11
- package/src/types/components/dashboard-search.ts +11 -11
- package/src/types/components/dashboard-sidebar-collapse.ts +11 -11
- package/src/types/components/dashboard-sidebar-toggle.ts +11 -11
- package/src/types/components/dashboard-sidebar.ts +11 -11
- package/src/types/components/dashboard-toolbar.ts +11 -11
- package/src/types/components/dock.ts +11 -11
- package/src/types/components/dropdown-menu.ts +2 -1
- package/src/types/components/editor.ts +11 -11
- package/src/types/components/empty.ts +11 -11
- package/src/types/components/error.ts +11 -11
- package/src/types/components/fieldset.ts +11 -11
- package/src/types/components/file-upload.ts +2 -1
- package/src/types/components/floating-action.ts +11 -11
- package/src/types/components/form.ts +19 -19
- package/src/types/components/gallery.ts +11 -11
- package/src/types/components/grid.ts +23 -0
- package/src/types/components/icon.ts +19 -19
- package/src/types/components/image.ts +32 -28
- package/src/types/components/input-date.ts +11 -11
- package/src/types/components/input-menu.ts +44 -43
- package/src/types/components/input-number.ts +11 -11
- package/src/types/components/input-pin.ts +36 -35
- package/src/types/components/input-tags.ts +11 -11
- package/src/types/components/input-time.ts +11 -11
- package/src/types/components/input.ts +6 -2
- package/src/types/components/knob.ts +11 -11
- package/src/types/components/layout-grid.ts +145 -0
- package/src/types/components/link-group.ts +47 -23
- package/src/types/components/link.ts +19 -0
- package/src/types/components/listbox.ts +11 -11
- package/src/types/components/locale-selector.ts +33 -33
- package/src/types/components/logo.ts +32 -31
- package/src/types/components/main.ts +17 -17
- package/src/types/components/meter.ts +11 -11
- package/src/types/components/modal.ts +39 -39
- package/src/types/components/navigation-menu.ts +59 -54
- package/src/types/components/page-aside.ts +11 -11
- package/src/types/components/page-body.ts +11 -11
- package/src/types/components/page-header.ts +11 -11
- package/src/types/components/page.ts +11 -11
- package/src/types/components/password.ts +11 -11
- package/src/types/components/phone-mockup.ts +5 -5
- package/src/types/components/pin-input.ts +11 -11
- package/src/types/components/popover.ts +23 -23
- package/src/types/components/post.ts +47 -35
- package/src/types/components/pricing-plan.ts +11 -11
- package/src/types/components/pricing-table.ts +11 -11
- package/src/types/components/progress.ts +33 -33
- package/src/types/components/prose.ts +11 -11
- package/src/types/components/qr-code.ts +11 -11
- package/src/types/components/radio-group.ts +11 -11
- package/src/types/components/rating.ts +11 -11
- package/src/types/components/scroll-area.ts +23 -23
- package/src/types/components/scroll-to-top.ts +2 -2
- package/src/types/components/search.ts +29 -0
- package/src/types/components/select.ts +2 -1
- package/src/types/components/separator.ts +19 -19
- package/src/types/components/sidebar.ts +83 -72
- package/src/types/components/slideover.ts +31 -31
- package/src/types/components/slider.ts +2 -2
- package/src/types/components/speed-dial.ts +11 -11
- package/src/types/components/spinner.ts +25 -25
- package/src/types/components/splitter.ts +19 -19
- package/src/types/components/spoiler.ts +11 -11
- package/src/types/components/stepper.ts +11 -11
- package/src/types/components/{megamenu.ts → steps.ts} +17 -11
- package/src/types/components/sticky-surface.ts +19 -19
- package/src/types/components/switch.ts +41 -41
- package/src/types/components/table-of-contents.ts +39 -17
- package/src/types/components/tabs.ts +2 -1
- package/src/types/components/textarea.ts +2 -1
- package/src/types/components/theme-selector.ts +15 -15
- package/src/types/components/timeline.ts +11 -11
- package/src/types/components/toast.ts +6 -1
- package/src/types/components/tooltip.ts +23 -23
- package/src/types/components/tour.ts +11 -11
- package/src/types/components/tree.ts +11 -11
- package/src/types/components/user.ts +11 -11
- package/src/types/components/watermark.ts +11 -11
- package/src/types/components/window-mockup.ts +11 -11
- package/src/types/docs.ts +40 -0
- package/src/types/index.ts +151 -1
- package/src/types/theme.ts +11 -1
- package/src/utils/color.ts +165 -0
- package/src/utils/docs.ts +365 -189
- package/src/utils/headerStack.ts +115 -95
- package/src/utils/index.ts +7 -5
- package/src/utils/shortcuts.ts +322 -0
- package/src/components/TableOfContents.astro +0 -107
- package/src/components/astro/RLAAlert.astro +0 -93
- package/src/components/astro/RLABlogPost.astro +0 -7
- package/src/components/astro/RLABlogPosts.astro +0 -9
- package/src/components/astro/RLAChangelog.astro +0 -23
- package/src/components/astro/RLAMegamenu.astro +0 -23
- package/src/components/astro/RLAPosts.astro +0 -23
- package/src/plugins/index.ts +0 -2
- package/src/plugins/starlightDocsApi/components/ApiTheme.astro +0 -27
- package/src/plugins/starlightDocsApi/index.ts +0 -272
- package/src/styles/prism.css +0 -42
- package/src/themes/changelog.theme.ts +0 -13
- package/src/themes/posts.theme.ts +0 -13
- package/src/types/components/index.ts +0 -135
- package/src/types/components/posts.ts +0 -11
- /package/src/{plugins/starlightDocsApi → docs}/types.ts +0 -0
package/src/utils/headerStack.ts
CHANGED
|
@@ -1,95 +1,115 @@
|
|
|
1
|
-
export interface HeaderLayer {
|
|
2
|
-
id: string
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
layer
|
|
61
|
-
layer
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
1
|
+
export interface HeaderLayer {
|
|
2
|
+
id: string
|
|
3
|
+
type: "banner" | "header"
|
|
4
|
+
order: number
|
|
5
|
+
naturalHeight: number
|
|
6
|
+
isVisible: boolean
|
|
7
|
+
el: HTMLElement | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface HeaderStackManager {
|
|
11
|
+
layers: HeaderLayer[]
|
|
12
|
+
register: (
|
|
13
|
+
id: string,
|
|
14
|
+
order: number,
|
|
15
|
+
naturalHeight: number,
|
|
16
|
+
isVisible: boolean,
|
|
17
|
+
el: HTMLElement | null,
|
|
18
|
+
type?: "banner" | "header"
|
|
19
|
+
) => void
|
|
20
|
+
unregister: (id: string) => void
|
|
21
|
+
update: () => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare global {
|
|
25
|
+
interface Window {
|
|
26
|
+
RLHeaderStack?: HeaderStackManager
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initializes and returns a global vanilla JS header stack manager. This ensures Vue and Astro
|
|
32
|
+
* components share the exact same layer state and can dynamically push each other up/down when
|
|
33
|
+
* hiding on scroll.
|
|
34
|
+
*/
|
|
35
|
+
export function getHeaderStack(): HeaderStackManager {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
// SSR stub
|
|
38
|
+
return {
|
|
39
|
+
layers: [],
|
|
40
|
+
register() {},
|
|
41
|
+
unregister() {},
|
|
42
|
+
update() {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!window.RLHeaderStack) {
|
|
47
|
+
window.RLHeaderStack = {
|
|
48
|
+
layers: [] as HeaderLayer[],
|
|
49
|
+
register(
|
|
50
|
+
id: string,
|
|
51
|
+
order: number,
|
|
52
|
+
naturalHeight: number,
|
|
53
|
+
isVisible: boolean,
|
|
54
|
+
el: HTMLElement | null,
|
|
55
|
+
type: "banner" | "header" = "header"
|
|
56
|
+
) {
|
|
57
|
+
if (el && !el.isConnected) return
|
|
58
|
+
let layer = this.layers.find((l: HeaderLayer) => l.id === id)
|
|
59
|
+
if (!layer) {
|
|
60
|
+
layer = { id, type, order, naturalHeight, isVisible, el }
|
|
61
|
+
this.layers.push(layer)
|
|
62
|
+
this.layers.sort((a: HeaderLayer, b: HeaderLayer) => {
|
|
63
|
+
if (a.type !== b.type) return a.type === "banner" ? -1 : 1
|
|
64
|
+
return a.order - b.order
|
|
65
|
+
})
|
|
66
|
+
} else {
|
|
67
|
+
layer.naturalHeight = naturalHeight
|
|
68
|
+
layer.isVisible = isVisible
|
|
69
|
+
layer.el = el
|
|
70
|
+
}
|
|
71
|
+
this.update()
|
|
72
|
+
},
|
|
73
|
+
unregister(id: string) {
|
|
74
|
+
const layer = this.layers.find((l: HeaderLayer) => l.id === id)
|
|
75
|
+
if (layer && layer.el) {
|
|
76
|
+
const el = layer.el as HTMLElement & {
|
|
77
|
+
rlScrollListener?: () => void
|
|
78
|
+
rlResizeObserver?: ResizeObserver
|
|
79
|
+
}
|
|
80
|
+
if (el.rlScrollListener) {
|
|
81
|
+
window.removeEventListener("scroll", el.rlScrollListener)
|
|
82
|
+
}
|
|
83
|
+
if (el.rlResizeObserver) {
|
|
84
|
+
el.rlResizeObserver.disconnect()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
this.layers = this.layers.filter((l: HeaderLayer) => l.id !== id)
|
|
88
|
+
this.update()
|
|
89
|
+
},
|
|
90
|
+
update() {
|
|
91
|
+
let currentTop = 0
|
|
92
|
+
for (const layer of this.layers) {
|
|
93
|
+
if (layer.el) {
|
|
94
|
+
// If hidden, slide it up out of view (or exactly to its negative height so it's ready to slide down)
|
|
95
|
+
const topPx = layer.isVisible ? `${currentTop}px` : `-${layer.naturalHeight}px`
|
|
96
|
+
layer.el.style.top = topPx
|
|
97
|
+
layer.el.style.opacity = layer.isVisible ? "1" : "0"
|
|
98
|
+
layer.el.style.pointerEvents = layer.isVisible ? "auto" : "none"
|
|
99
|
+
layer.el.style.setProperty(
|
|
100
|
+
"--rl-header-bottom",
|
|
101
|
+
`calc(${topPx} + ${layer.naturalHeight}px)`
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
if (layer.isVisible) {
|
|
105
|
+
currentTop += layer.naturalHeight
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (currentTop > 0) {
|
|
109
|
+
document.documentElement.style.setProperty("--rl-total-header-height", `${currentTop}px`)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return window.RLHeaderStack
|
|
115
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from "./defineTheme"
|
|
2
|
-
export * from "./resolveClasses"
|
|
3
|
-
export * from "./useUi.ts"
|
|
4
|
-
export * from "./docs"
|
|
5
|
-
export * from "./embed"
|
|
1
|
+
export * from "./defineTheme"
|
|
2
|
+
export * from "./resolveClasses"
|
|
3
|
+
export * from "./useUi.ts"
|
|
4
|
+
export * from "./docs"
|
|
5
|
+
export * from "./embed"
|
|
6
|
+
export * from "./shortcuts"
|
|
7
|
+
export * from "./color"
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { atom } from "nanostores"
|
|
2
|
+
|
|
3
|
+
export type Handler = (e: KeyboardEvent) => void
|
|
4
|
+
|
|
5
|
+
export interface ShortcutConfig {
|
|
6
|
+
handler: Handler
|
|
7
|
+
usingInput?: boolean | string
|
|
8
|
+
label?: string
|
|
9
|
+
description?: string
|
|
10
|
+
category?: string
|
|
11
|
+
order?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ShortcutsConfig {
|
|
15
|
+
[key: string]: ShortcutConfig | Handler | false | null | undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ShortcutsOptions {
|
|
19
|
+
chainDelay?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface Shortcut {
|
|
23
|
+
key: string
|
|
24
|
+
handler: Handler
|
|
25
|
+
chained: boolean
|
|
26
|
+
ctrlKey: boolean
|
|
27
|
+
metaKey: boolean
|
|
28
|
+
shiftKey: boolean
|
|
29
|
+
altKey: boolean
|
|
30
|
+
usingInput?: boolean | string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RegisteredShortcut {
|
|
34
|
+
id: string
|
|
35
|
+
keys: string[]
|
|
36
|
+
label?: string
|
|
37
|
+
description?: string
|
|
38
|
+
category?: string
|
|
39
|
+
order?: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// OS detection
|
|
43
|
+
const macOS =
|
|
44
|
+
typeof window !== "undefined" &&
|
|
45
|
+
typeof navigator !== "undefined" &&
|
|
46
|
+
/Macintosh;/.test(navigator.userAgent)
|
|
47
|
+
|
|
48
|
+
// Modifiers map for human-readable display
|
|
49
|
+
const kbdKeysMap: Record<string, string> = {
|
|
50
|
+
meta: macOS ? "⌘" : "Ctrl",
|
|
51
|
+
command: macOS ? "⌘" : "Ctrl",
|
|
52
|
+
ctrl: macOS ? "Ctrl" : "Ctrl",
|
|
53
|
+
control: macOS ? "Ctrl" : "Ctrl",
|
|
54
|
+
alt: macOS ? "⌥" : "Alt",
|
|
55
|
+
option: macOS ? "⌥" : "Alt",
|
|
56
|
+
shift: macOS ? "⇧" : "Shift",
|
|
57
|
+
enter: "↵",
|
|
58
|
+
delete: "⌦",
|
|
59
|
+
backspace: "⌫",
|
|
60
|
+
escape: "Esc",
|
|
61
|
+
tab: "⇥",
|
|
62
|
+
space: "Space",
|
|
63
|
+
arrowup: "↑",
|
|
64
|
+
arrowdown: "↓",
|
|
65
|
+
arrowleft: "←",
|
|
66
|
+
arrowright: "→"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Convert a combination string (e.g. meta_alt_t) into platform-specific readable key symbol arrays
|
|
70
|
+
export function formatShortcutKeys(keyStr: string): string[] {
|
|
71
|
+
const separator = keyStr.includes("-") ? "-" : "_"
|
|
72
|
+
const parts = keyStr.split(separator)
|
|
73
|
+
return parts.map((part) => {
|
|
74
|
+
const lower = part.toLowerCase()
|
|
75
|
+
if (kbdKeysMap[lower] !== undefined) {
|
|
76
|
+
return kbdKeysMap[lower]
|
|
77
|
+
}
|
|
78
|
+
if (lower.length === 1) {
|
|
79
|
+
return lower.toUpperCase()
|
|
80
|
+
}
|
|
81
|
+
return part.charAt(0).toUpperCase() + part.slice(1)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Reactive store containing all currently registered shortcuts on the page
|
|
86
|
+
export const activeShortcutsStore = atom<RegisteredShortcut[]>([])
|
|
87
|
+
|
|
88
|
+
// Simple key to code conversion for layout/translation independence under Alt
|
|
89
|
+
function convertKeyToCode(key: string): string {
|
|
90
|
+
if (/^[a-z]$/i.test(key)) {
|
|
91
|
+
return `Key${key.toUpperCase()}`
|
|
92
|
+
}
|
|
93
|
+
if (/^\d$/.test(key)) {
|
|
94
|
+
return `Digit${key}`
|
|
95
|
+
}
|
|
96
|
+
if (/^f\d+$/i.test(key)) {
|
|
97
|
+
return key.toUpperCase()
|
|
98
|
+
}
|
|
99
|
+
const specialKeys: Record<string, string> = {
|
|
100
|
+
space: "Space",
|
|
101
|
+
enter: "Enter",
|
|
102
|
+
escape: "Escape",
|
|
103
|
+
tab: "Tab",
|
|
104
|
+
backspace: "Backspace",
|
|
105
|
+
delete: "Delete",
|
|
106
|
+
arrowup: "ArrowUp",
|
|
107
|
+
arrowdown: "ArrowDown",
|
|
108
|
+
arrowleft: "ArrowLeft",
|
|
109
|
+
arrowright: "ArrowRight"
|
|
110
|
+
}
|
|
111
|
+
return specialKeys[key.toLowerCase()] || key
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Input tag checking
|
|
115
|
+
function isUsingInput(activeElement: Element | null): boolean | string {
|
|
116
|
+
if (!activeElement) return false
|
|
117
|
+
const tagName = activeElement.tagName
|
|
118
|
+
const contentEditable = activeElement.getAttribute("contenteditable")
|
|
119
|
+
const isInput =
|
|
120
|
+
tagName === "INPUT" ||
|
|
121
|
+
tagName === "TEXTAREA" ||
|
|
122
|
+
contentEditable === "true" ||
|
|
123
|
+
contentEditable === "plaintext-only"
|
|
124
|
+
if (isInput) {
|
|
125
|
+
return activeElement.getAttribute("name") || true
|
|
126
|
+
}
|
|
127
|
+
return false
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function defineShortcuts(
|
|
131
|
+
config: ShortcutsConfig,
|
|
132
|
+
options: ShortcutsOptions = {}
|
|
133
|
+
): () => void {
|
|
134
|
+
if (typeof window === "undefined") {
|
|
135
|
+
return () => {}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const chainDelay = options.chainDelay ?? 800
|
|
139
|
+
const chainedInputs: string[] = []
|
|
140
|
+
let debounceTimer: any = null
|
|
141
|
+
|
|
142
|
+
const clearChainedInput = () => {
|
|
143
|
+
chainedInputs.length = 0
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Pre-parse the shortcuts configuration
|
|
147
|
+
const parsedShortcuts: Shortcut[] = Object.entries(config)
|
|
148
|
+
.map(([key, shortcutConfig]) => {
|
|
149
|
+
if (!shortcutConfig) return null
|
|
150
|
+
|
|
151
|
+
let handler: Handler
|
|
152
|
+
let usingInput: boolean | string = false
|
|
153
|
+
|
|
154
|
+
if (typeof shortcutConfig === "function") {
|
|
155
|
+
handler = shortcutConfig
|
|
156
|
+
} else {
|
|
157
|
+
handler = shortcutConfig.handler
|
|
158
|
+
usingInput = shortcutConfig.usingInput ?? false
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!handler) return null
|
|
162
|
+
|
|
163
|
+
const chained = key.includes("-") && key !== "-" && !key.includes("_")
|
|
164
|
+
let baseKey = ""
|
|
165
|
+
let ctrlKey = false
|
|
166
|
+
let metaKey = false
|
|
167
|
+
let shiftKey = false
|
|
168
|
+
let altKey = false
|
|
169
|
+
|
|
170
|
+
if (chained) {
|
|
171
|
+
baseKey = key.toLowerCase()
|
|
172
|
+
} else {
|
|
173
|
+
const parts = key.toLowerCase().split("_")
|
|
174
|
+
baseKey = parts
|
|
175
|
+
.filter((p) => !["meta", "command", "ctrl", "shift", "alt", "option"].includes(p))
|
|
176
|
+
.join("_")
|
|
177
|
+
ctrlKey = parts.includes("ctrl")
|
|
178
|
+
metaKey = parts.includes("meta") || parts.includes("command")
|
|
179
|
+
shiftKey = parts.includes("shift")
|
|
180
|
+
altKey = parts.includes("alt") || parts.includes("option")
|
|
181
|
+
|
|
182
|
+
// Normalize Cmd/Ctrl for non-macOS
|
|
183
|
+
if (!macOS && metaKey && !ctrlKey) {
|
|
184
|
+
metaKey = false
|
|
185
|
+
ctrlKey = true
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
key: baseKey,
|
|
191
|
+
handler,
|
|
192
|
+
chained,
|
|
193
|
+
ctrlKey,
|
|
194
|
+
metaKey,
|
|
195
|
+
shiftKey,
|
|
196
|
+
altKey,
|
|
197
|
+
usingInput
|
|
198
|
+
} as Shortcut
|
|
199
|
+
})
|
|
200
|
+
.filter((item): item is Shortcut => item != null)
|
|
201
|
+
|
|
202
|
+
// Register documented shortcuts to the store
|
|
203
|
+
const itemsToRegister: RegisteredShortcut[] = Object.entries(config).flatMap(
|
|
204
|
+
([key, shortcutConfig]) => {
|
|
205
|
+
if (!shortcutConfig || typeof shortcutConfig !== "object") return []
|
|
206
|
+
|
|
207
|
+
const { label, description, category, order } = shortcutConfig
|
|
208
|
+
if (!label && !description) return [] // only register documented shortcuts
|
|
209
|
+
|
|
210
|
+
const item: RegisteredShortcut = {
|
|
211
|
+
id: `${key}-${Math.random().toString(36).slice(2, 7)}`,
|
|
212
|
+
keys: formatShortcutKeys(key),
|
|
213
|
+
category: category || "system"
|
|
214
|
+
}
|
|
215
|
+
if (label) item.label = label
|
|
216
|
+
if (description) item.description = description
|
|
217
|
+
if (order !== undefined) item.order = order
|
|
218
|
+
return [item]
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
if (itemsToRegister.length > 0) {
|
|
223
|
+
activeShortcutsStore.set([...activeShortcutsStore.get(), ...itemsToRegister])
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
227
|
+
if (!e.key) return
|
|
228
|
+
|
|
229
|
+
const activeEl = document.activeElement
|
|
230
|
+
const currentlyUsingInput = isUsingInput(activeEl)
|
|
231
|
+
|
|
232
|
+
// Helper to check if a shortcut is enabled given current focus state
|
|
233
|
+
const isShortcutEnabled = (shortcut: Shortcut) => {
|
|
234
|
+
if (!shortcut.usingInput) {
|
|
235
|
+
return !currentlyUsingInput
|
|
236
|
+
}
|
|
237
|
+
if (typeof shortcut.usingInput === "string") {
|
|
238
|
+
return currentlyUsingInput === shortcut.usingInput
|
|
239
|
+
}
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Handle chained shortcuts
|
|
244
|
+
chainedInputs.push(e.key.toLowerCase())
|
|
245
|
+
clearTimeout(debounceTimer)
|
|
246
|
+
|
|
247
|
+
if (chainedInputs.length >= 2) {
|
|
248
|
+
const chainedKey = chainedInputs.slice(-2).join("-")
|
|
249
|
+
const matchedChained = parsedShortcuts.find((s) => s.chained && s.key === chainedKey)
|
|
250
|
+
if (matchedChained && isShortcutEnabled(matchedChained)) {
|
|
251
|
+
e.preventDefault()
|
|
252
|
+
matchedChained.handler(e)
|
|
253
|
+
clearChainedInput()
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Handle standard shortcuts
|
|
259
|
+
for (const shortcut of parsedShortcuts) {
|
|
260
|
+
if (shortcut.chained) continue
|
|
261
|
+
|
|
262
|
+
if (e.ctrlKey !== shortcut.ctrlKey) continue
|
|
263
|
+
if (e.metaKey !== shortcut.metaKey) continue
|
|
264
|
+
if (e.altKey !== shortcut.altKey) continue
|
|
265
|
+
|
|
266
|
+
// Match by code when Alt modifier is active to avoid key translation issues
|
|
267
|
+
const useCode = shortcut.altKey && e.altKey
|
|
268
|
+
if (useCode) {
|
|
269
|
+
if (e.code !== convertKeyToCode(shortcut.key)) continue
|
|
270
|
+
} else {
|
|
271
|
+
const pressedKey = e.key.toLowerCase()
|
|
272
|
+
if (pressedKey !== shortcut.key) continue
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Shift modifier check:
|
|
276
|
+
// If the shortcut explicitly specifies shiftKey: true, then e.shiftKey must be true.
|
|
277
|
+
// If the shortcut does NOT specify shiftKey: true, but e.shiftKey is true:
|
|
278
|
+
// - If the base key is a letter (e.g. 'k'), then we do NOT match (because it's Shift+K, not K).
|
|
279
|
+
// - If the base key is a shiftable control key (like 'arrowleft'), we do NOT match.
|
|
280
|
+
// - For other keys (like '?', '/', etc.), we allow it to match even if e.shiftKey is true.
|
|
281
|
+
const alphabetKey = /^[a-z]$/i.test(shortcut.key)
|
|
282
|
+
const shiftableKeys = [
|
|
283
|
+
"arrowleft",
|
|
284
|
+
"arrowright",
|
|
285
|
+
"arrowup",
|
|
286
|
+
"arrowdown",
|
|
287
|
+
"tab",
|
|
288
|
+
"escape",
|
|
289
|
+
"enter",
|
|
290
|
+
"backspace"
|
|
291
|
+
]
|
|
292
|
+
const shiftableKey = shiftableKeys.includes(shortcut.key)
|
|
293
|
+
|
|
294
|
+
if (shortcut.shiftKey && !e.shiftKey) continue
|
|
295
|
+
if (!shortcut.shiftKey && e.shiftKey && (alphabetKey || shiftableKey)) continue
|
|
296
|
+
|
|
297
|
+
if (isShortcutEnabled(shortcut)) {
|
|
298
|
+
e.preventDefault()
|
|
299
|
+
shortcut.handler(e)
|
|
300
|
+
clearChainedInput()
|
|
301
|
+
return
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
debounceTimer = setTimeout(clearChainedInput, chainDelay)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
window.addEventListener("keydown", onKeyDown)
|
|
309
|
+
|
|
310
|
+
return () => {
|
|
311
|
+
window.removeEventListener("keydown", onKeyDown)
|
|
312
|
+
clearTimeout(debounceTimer)
|
|
313
|
+
|
|
314
|
+
// Unregister items from the active store
|
|
315
|
+
if (itemsToRegister.length > 0) {
|
|
316
|
+
const idsToRemove = new Set(itemsToRegister.map((item) => item.id))
|
|
317
|
+
activeShortcutsStore.set(
|
|
318
|
+
activeShortcutsStore.get().filter((item) => !idsToRemove.has(item.id))
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
export interface TableOfContentsHeading {
|
|
3
|
-
depth: number;
|
|
4
|
-
slug: string;
|
|
5
|
-
text: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface TableOfContentsConfig {
|
|
9
|
-
minHeadingLevel?: number;
|
|
10
|
-
maxHeadingLevel?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface TableOfContentsProps {
|
|
14
|
-
headings: TableOfContentsHeading[];
|
|
15
|
-
/** false = hide entirely, object = heading level bounds */
|
|
16
|
-
tableOfContents?: false | TableOfContentsConfig;
|
|
17
|
-
/** @deprecated use tableOfContents.maxHeadingLevel instead */
|
|
18
|
-
levels?: 1 | 2 | 3;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Props = TableOfContentsProps;
|
|
22
|
-
|
|
23
|
-
const { headings, tableOfContents, levels = 2 } = Astro.props as Props;
|
|
24
|
-
|
|
25
|
-
if (tableOfContents === false) {
|
|
26
|
-
// Render nothing — parent should also skip rendering this component,
|
|
27
|
-
// but guard here as a safety net.
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const minLevel = (tableOfContents !== false && tableOfContents?.minHeadingLevel) ?? 2;
|
|
31
|
-
const maxLevel = (tableOfContents !== false && tableOfContents?.maxHeadingLevel) ?? levels;
|
|
32
|
-
|
|
33
|
-
const filteredHeadings = tableOfContents !== false
|
|
34
|
-
? headings.filter(h => h.depth >= minLevel && h.depth <= maxLevel)
|
|
35
|
-
: [];
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
{tableOfContents !== false && filteredHeadings.length > 0 && (
|
|
39
|
-
<div class="border-border rounded-xs border p-3xs text-sm leading-tight">
|
|
40
|
-
<h4 class="text-xl font-medium">On this page</h4>
|
|
41
|
-
<ul class="mt-2xl flex flex-col gap-3xs">
|
|
42
|
-
{filteredHeadings.map(heading => (
|
|
43
|
-
<li
|
|
44
|
-
class:list={{
|
|
45
|
-
"pl-3xs": heading.depth === 2,
|
|
46
|
-
"pl-6": heading.depth === 3,
|
|
47
|
-
"pl-9": heading.depth >= 4
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<a
|
|
51
|
-
href={`#${heading.slug}`}
|
|
52
|
-
class="toc-link transition hover:text-primary-accent"
|
|
53
|
-
>
|
|
54
|
-
{heading.text}
|
|
55
|
-
</a>
|
|
56
|
-
</li>
|
|
57
|
-
))}
|
|
58
|
-
</ul>
|
|
59
|
-
</div>
|
|
60
|
-
)}
|
|
61
|
-
|
|
62
|
-
<style>
|
|
63
|
-
.toc-current {
|
|
64
|
-
color: var(--primary);
|
|
65
|
-
font-weight: 500;
|
|
66
|
-
}
|
|
67
|
-
</style>
|
|
68
|
-
|
|
69
|
-
<script>
|
|
70
|
-
let wrappingElement: Element | null;
|
|
71
|
-
let observeHeaderTags: IntersectionObserver;
|
|
72
|
-
let allHeaderTags: NodeListOf<Element>;
|
|
73
|
-
|
|
74
|
-
function setCurrent(e: IntersectionObserverEntry[]) {
|
|
75
|
-
const allSectionLinks = document.querySelectorAll(".toc-link");
|
|
76
|
-
e.map(i => {
|
|
77
|
-
if (i.isIntersecting === true) {
|
|
78
|
-
allSectionLinks.forEach(link => link.classList.remove("toc-current"));
|
|
79
|
-
const targetLink = document.querySelector(`a[href="#${i.target.id}"].toc-link`);
|
|
80
|
-
if (targetLink) targetLink.classList.add("toc-current");
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function initTOC() {
|
|
86
|
-
wrappingElement = document.querySelector(".markdown-content");
|
|
87
|
-
if (wrappingElement !== null) {
|
|
88
|
-
allHeaderTags = wrappingElement.querySelectorAll(":scope > h1, :scope > h2, :scope > h3, :scope > h4");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const options: IntersectionObserverInit = {
|
|
92
|
-
root: null,
|
|
93
|
-
rootMargin: "0px 0px -50% 0px",
|
|
94
|
-
threshold: [1]
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
observeHeaderTags = new IntersectionObserver(setCurrent, options);
|
|
98
|
-
if (wrappingElement === null) return;
|
|
99
|
-
allHeaderTags.forEach(tag => {
|
|
100
|
-
tag.classList.add("scroll-mt-3xl");
|
|
101
|
-
observeHeaderTags.observe(tag);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
initTOC();
|
|
106
|
-
document.addEventListener("astro:after-swap", initTOC);
|
|
107
|
-
</script>
|