@rspress-theme-anatole/theme-default
Version:
1,018 lines (989 loc) • 376 kB
JavaScript
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_react_0d3abecb__ from "@mdx-js/react";
import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress/runtime";
import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_htmr__ from "htmr";
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress-theme-anatole/shared";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_arrow_right_3f3bb17d__ from "@theme-assets/arrow-right";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_menu_9c72640c__ from "@theme-assets/menu";
import "nprogress/nprogress.css";
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_wrap_367cf3a3__ from "@theme-assets/wrap";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_wrapped_01fc4d47__ from "@theme-assets/wrapped";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_copy_ebc8477b__ from "@theme-assets/copy";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_success_55638e57__ from "@theme-assets/success";
import * as __WEBPACK_EXTERNAL_MODULE_copy_to_clipboard_b679b6a5__ from "copy-to-clipboard";
import * as __WEBPACK_EXTERNAL_MODULE_react_syntax_highlighter_bbd3b718__ from "react-syntax-highlighter";
import * as __WEBPACK_EXTERNAL_MODULE_virtual_prism_languages_a6edd1ed__ from "virtual-prism-languages";
import * as __WEBPACK_EXTERNAL_MODULE_flexsearch__ from "flexsearch";
import * as __WEBPACK_EXTERNAL_MODULE_virtual_search_index_hash_00b0989e__ from "virtual-search-index-hash";
import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
import * as __WEBPACK_EXTERNAL_MODULE_nprogress__ from "nprogress";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_small_menu_b89c442a__ from "@theme-assets/small-menu";
import * as __WEBPACK_EXTERNAL_MODULE_body_scroll_lock_935fd51e__ from "body-scroll-lock";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_translator_e1217f67__ from "@theme-assets/translator";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_arrow_down_f924fb68__ from "@theme-assets/arrow-down";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_moon_c120f886__ from "@theme-assets/moon";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_sun_beb20915__ from "@theme-assets/sun";
import * as __WEBPACK_EXTERNAL_MODULE_react_dom_7136dc57__ from "react-dom";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_down_345b1d5d__ from "@theme-assets/down";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_close_bcac2df4__ from "@theme-assets/close";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_loading_5f550a25__ from "@theme-assets/loading";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_search_1c295ce0__ from "@theme-assets/search";
import * as __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__ from "virtual-search-hooks";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_empty_326d8860__ from "@theme-assets/empty";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_file_9182f35f__ from "@theme-assets/file";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_header_54924fa3__ from "@theme-assets/header";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_jump_20d3ca88__ from "@theme-assets/jump";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_title_56a7311e__ from "@theme-assets/title";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_github_cac38251__ from "@theme-assets/github";
import * as __WEBPACK_EXTERNAL_MODULE__theme_assets_gitlab_a0e4f082__ from "@theme-assets/gitlab";
import style from "react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark";
function isMobileDevice() {
return window.innerWidth < 1280;
}
function renderHtmlOrText(str) {
if (!str) return '';
if ('number' == typeof str) return str;
const hasValidHtmlElements = /<([a-z]+)([^<]*)(?:>(.*?)<\/\1>|\s*\/>)/i.test(str);
if (hasValidHtmlElements) return (0, __WEBPACK_EXTERNAL_MODULE_htmr__["default"])(str);
return str.replace(/\\</g, '<').replace(/\\>/g, '>').replace(/</g, '<').replace(/>/g, '>');
}
const CODE_TEXT_PATTERN = /`(.*?)`/g;
const STRONG_TEXT_PATTERN = /\*{2}(?!\*)(.*?)\*{2}(?!\*)/g;
const EMPHASIS_TEXT_PATTERN = /\*(?!\*)(.*?)\*(?!\*)/g;
const DELETE_TEXT_PATTERN = /\~{2}(.*?)\~{2}/g;
function renderInlineMarkdown(text) {
const htmlText = text.replace(/`[^`]+`/g, (match) => match.replace(/</g, '<')).replace(STRONG_TEXT_PATTERN, '<strong>$1</strong>').replace(EMPHASIS_TEXT_PATTERN, '<em>$1</em>').replace(DELETE_TEXT_PATTERN, '<del>$1</del>').replace(CODE_TEXT_PATTERN, '<code>$1</code>');
return renderHtmlOrText(htmlText);
}
function parseInlineMarkdownText(mdx) {
return mdx.replace(STRONG_TEXT_PATTERN, '$1').replace(EMPHASIS_TEXT_PATTERN, '$1').replace(DELETE_TEXT_PATTERN, '$1').replace(CODE_TEXT_PATTERN, '$1');
}
function useEnableNav() {
const { siteData: { themeConfig }, page: { frontmatter = {} } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const initialState = (frontmatter?.navbar ?? true) && themeConfig?.hideNavbar !== 'always';
const [enableNav, setEnableNav] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialState);
return [
enableNav,
setEnableNav
];
}
function useHiddenNav() {
const { siteData: { themeConfig } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const hiddenBehavior = themeConfig.hideNavbar ?? 'never';
const [hiddenNav, setHiddenNav] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
const { pathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const lastScrollTop = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(0);
if ('never' === hiddenBehavior) return false;
if ('always' === hiddenBehavior) return true;
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
setHiddenNav(false);
const onScrollListen = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.throttle)(() => {
const { scrollTop } = document.documentElement;
if (scrollTop === lastScrollTop.current) return;
const shouldHidden = lastScrollTop.current > 0 && scrollTop - lastScrollTop.current > 0;
setHiddenNav(shouldHidden);
lastScrollTop.current = scrollTop <= 0 ? 0 : scrollTop;
}, 200);
window.addEventListener('scroll', onScrollListen);
return () => {
window.removeEventListener('scroll', onScrollListen);
};
}, [
pathname
]);
return hiddenNav;
}
const DEFAULT_NAV_HEIGHT = 72;
function getTargetTop(element, fallbackHeight = DEFAULT_NAV_HEIGHT) {
const targetPadding = Number.parseInt(window.getComputedStyle(element).paddingTop, 10);
const targetTop = window.scrollY + element.getBoundingClientRect().top - fallbackHeight - targetPadding;
return Math.round(targetTop);
}
function scrollToTarget(target, isSmooth, fallbackHeight = DEFAULT_NAV_HEIGHT) {
window.scrollTo({
left: 0,
top: getTargetTop(target, fallbackHeight),
...isSmooth ? {
behavior: 'smooth'
} : {}
});
}
function bindingWindowScroll() {
function scrollTo(el, hash, isSmooth = false) {
let target = null;
try {
target = el.classList.contains('header-anchor') ? el : document.getElementById(decodeURIComponent(hash.slice(1)));
} catch (e) {
console.warn(e);
}
if (target) scrollToTarget(target, isSmooth);
}
window.addEventListener('click', (e) => {
const link = e.target.closest('a');
if (link) {
const { origin, hash, target, pathname, search } = link;
const currentUrl = window.location;
if (hash && '_blank' !== target && origin === currentUrl.origin) {
if (pathname === currentUrl.pathname && search === currentUrl.search && hash && link.classList.contains('header-anchor')) {
e.preventDefault();
history.pushState(null, '', hash);
scrollTo(link, hash, true);
window.dispatchEvent(new Event('hashchange'));
} else window.addEventListener('RspressReloadContent', () => {
if (location.hash.length > 1) {
const ele = document.getElementById(location.hash.slice(1));
scrollToTarget(ele, false);
}
});
}
}
}, {
capture: true
});
window.addEventListener('hashchange', (e) => {
e.preventDefault();
});
}
function bindingAsideScroll() {
function isBottom() {
return document.documentElement.scrollTop + window.innerHeight >= document.documentElement.scrollHeight;
}
const aside = document.getElementById('aside-container');
const links = Array.from(document.querySelectorAll('.rspress-doc .header-anchor')).filter((item) => item.parentElement?.tagName !== 'H1');
if (!aside || !links.length) return;
let prevActiveLink = null;
const headers = Array.from(aside?.getElementsByTagName('a') || []).map((item) => decodeURIComponent(item.hash));
if (!headers.length) return;
const activate = (links, index) => {
if (links[index]) {
const id = links[index].getAttribute('href');
const currentLink = aside?.querySelector(`a[href="#${id?.slice(1)}"]`);
if (currentLink) {
if (prevActiveLink) prevActiveLink.classList.remove('aside-active');
prevActiveLink = currentLink;
prevActiveLink.classList.add('aside-active');
}
}
};
const setActiveLink = () => {
if (isBottom()) activate(links, links.length - 1);
else for (let i = 0; i < links.length; i++) {
const currentAnchor = links[i];
const nextAnchor = links[i + 1];
const scrollTop = Math.ceil(window.scrollY);
const currentAnchorTop = getTargetTop(currentAnchor.parentElement);
if (0 === i && scrollTop < currentAnchorTop || 0 === scrollTop) {
activate(links, 0);
break;
}
if (!nextAnchor) {
activate(links, i);
break;
}
const nextAnchorTop = getTargetTop(nextAnchor.parentElement);
if (scrollTop >= currentAnchorTop && scrollTop < nextAnchorTop) {
activate(links, i);
break;
}
}
};
const throttledSetLink = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.throttle)(setActiveLink, 100);
window.addEventListener('scroll', throttledSetLink);
setActiveLink();
return () => {
if (prevActiveLink) prevActiveLink.classList.remove('aside-active');
window.removeEventListener('scroll', throttledSetLink);
};
}
function setup() {
if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.inBrowser)()) return;
bindingWindowScroll();
}
const TocItem = ({ header, baseHeaderLevel }) => (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("li", {
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("a", {
href: `#${header.id}`,
title: parseInlineMarkdownText(header.text),
className: "aside-link transition-all duration-300 hover:text-text-1 text-text-2 block",
style: {
marginLeft: (header.depth - baseHeaderLevel) * 12,
fontWeight: 'semibold'
},
onClick: (e) => {
e.preventDefault();
window.location.hash = header.id;
},
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
className: "aside-link-text block",
children: renderInlineMarkdown(header.text),
style: {
color: '#32363E',
letterSpacing: '-1%',
}
})
})
});
function Aside(props) {
const { headers } = props;
const hasOutline = headers.length > 0;
const baseHeaderLevel = headers[0]?.depth || 2;
const hiddenNav = useHiddenNav();
const { hash: locationHash = '', pathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const decodedHash = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(() => decodeURIComponent(locationHash), [
locationHash
]);
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
let unbinding;
setTimeout(() => {
unbinding = bindingAsideScroll();
}, 100);
return () => {
if (unbinding) unbinding();
};
}, [
headers
]);
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
if (0 === decodedHash.length) window.scrollTo(0, 0);
else {
const target = document.getElementById(decodedHash.slice(1));
if (target) scrollToTarget(target, false, hiddenNav ? 0 : DEFAULT_NAV_HEIGHT);
}
}, [
decodedHash,
headers,
pathname
]);
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: "flex flex-col",
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: hasOutline ? '<lg:hidden' : 'hidden',
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
id: "aside-container",
className: "relative text-sm font-medium",
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: "leading-7 block text-sm font-semibold pl-3",
children: props.outlineTitle,
style: {
fontWeight: 400
}
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("nav", {
className: "mt-1",
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("ul", {
className: "relative",
children: headers.map((header) => (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(TocItem, {
baseHeaderLevel: baseHeaderLevel,
header: header
}, `${pathname}#${header.id}`))
})
})
]
})
})
});
}
const matchPath = (pattern, currentPathname) => {
const prefix = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)(pattern);
if (prefix === currentPathname) return true;
const prefixWithTrailingSlash = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(prefix);
if (currentPathname.startsWith(prefixWithTrailingSlash)) return true;
const prefixWithDot = `${prefix}.`;
return currentPathname.startsWith(prefixWithDot);
};
function getSidebarDataGroup_isActive(itemLink, currentPathname) {
const normalizedItemLink = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeRoutePath)((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)(itemLink));
const normalizedCurrentPathname = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeRoutePath)(currentPathname);
const linkMatched = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.matchPath)(normalizedItemLink, normalizedCurrentPathname);
return null !== linkMatched;
}
const getSidebarDataGroup = (sidebar, currentPathname) => {
const navRoutes = Object.keys(sidebar).sort((a, b) => b.length - a.length);
for (const name of navRoutes) if (matchPath(name, currentPathname)) {
const sidebarGroup = sidebar[name];
return sidebarGroup;
}
return [];
};
function useLocaleSiteData() {
const pageData = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const { page: { lang } } = pageData;
const themeConfig = pageData?.siteData?.themeConfig ?? {};
const defaultLang = pageData.siteData.lang ?? '';
const locales = themeConfig?.locales;
if (!locales || 0 === locales.length) return {
nav: themeConfig.nav,
sidebar: themeConfig.sidebar,
prevPageText: themeConfig.prevPageText,
nextPageText: themeConfig.nextPageText,
sourceCodeText: themeConfig.sourceCodeText,
searchPlaceholderText: themeConfig.searchPlaceholderText,
searchNoResultsText: themeConfig.searchNoResultsText,
searchSuggestedQueryText: themeConfig.searchSuggestedQueryText,
overview: themeConfig.overview
};
const localeInfo = locales.find((locale) => locale.lang === lang);
return {
...localeInfo,
langRoutePrefix: lang === defaultLang ? '/' : (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(lang)
};
}
function normalizeRoleList(value) {
if (!value) return [];
const list = Array.isArray(value) ? value : String(value).split(',');
return list.map((role) => String(role).trim().toLowerCase()).filter(Boolean);
}
// Cache for user context fetched from userContext endpoint
let _cachedUserContext = null;
let _userContextFetchPromise = null;
let _userContextResolved = false;
function isUserContextResolved() {
return _userContextResolved;
}
function getUserContext() {
// Return cached user context if available
if (_cachedUserContext !== null) return _cachedUserContext;
return { isAuthenticated: false, userId: null };
}
async function fetchUserContext(userContextUrl) {
if (!userContextUrl) return { isAuthenticated: false, userId: null };
if (_cachedUserContext !== null) return _cachedUserContext;
if (_userContextFetchPromise) return _userContextFetchPromise;
_userContextFetchPromise = (async () => {
try {
const response = await fetch(userContextUrl, { credentials: 'include' });
if (!response.ok) {
console.warn('Failed to fetch user context:', response.status);
_cachedUserContext = { isAuthenticated: false, userId: null };
_userContextResolved = true;
return _cachedUserContext;
}
const data = await response.json();
_cachedUserContext = {
isAuthenticated: data?.isAuthenticated || false,
userId: data?.userId || null
};
_userContextResolved = true;
// Dispatch event to trigger sidebar re-render
if (typeof window !== 'undefined') {
window.dispatchEvent(new Event('UserContextReady'));
}
return _cachedUserContext;
} catch (e) {
console.warn('Error fetching user context:', e);
_cachedUserContext = { isAuthenticated: false, userId: null };
_userContextResolved = true;
return _cachedUserContext;
} finally {
_userContextFetchPromise = null;
}
})();
return _userContextFetchPromise;
}
function isItemLocked(item, userContext) {
const requiredRoles = normalizeRoleList(item?.roles);
// No roles required = public content (not locked)
if (!requiredRoles.length) return false;
// User is authenticated with valid userId = unlocked (regardless of roles)
if (userContext?.isAuthenticated && userContext?.userId) return false;
// Has roles required but user is not authenticated = locked
return true;
}
function markLockedSidebarItems(items, userContext) {
if (!Array.isArray(items)) return items;
return items.map((item) => {
if (!item) return null;
let nextItem = item;
const locked = isItemLocked(item, userContext);
if (locked) {
nextItem = { ...nextItem, locked: true };
}
if ('items' in item && Array.isArray(item.items)) {
const markedItems = markLockedSidebarItems(item.items, userContext);
nextItem = { ...nextItem, items: markedItems };
}
return nextItem;
}).filter(Boolean);
}
function useSidebarData() {
const { sidebar } = useLocaleSiteData();
const { siteData } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const { pathname: rawPathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const pathname = decodeURIComponent(rawPathname);
const [roleVersion, setRoleVersion] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
// Fetch user context from userContext endpoint
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
const userContextUrl = siteData?.auth?.endpoints?.userContext;
if (userContextUrl) {
fetchUserContext(userContextUrl);
} else {
// No auth endpoint configured — mark as resolved immediately
_userContextResolved = true;
}
}, [siteData?.auth?.endpoints?.userContext]);
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
if ('undefined' == typeof window) return;
const handler = () => setRoleVersion((v) => v + 1);
window.addEventListener('MetaRolesReady', handler);
window.addEventListener('UserContextReady', handler);
return () => {
window.removeEventListener('MetaRolesReady', handler);
window.removeEventListener('UserContextReady', handler);
};
}, []);
const sidebarData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(() => {
const data = getSidebarDataGroup(sidebar, pathname);
const userContext = getUserContext();
let dataWithRoles = data;
try {
const roleMap = 'undefined' != typeof window ? window.__META_ROLE_MAP__ : null;
if (roleMap) {
const applyRoles = (items) => {
if (!Array.isArray(items)) return items;
return items.map((item) => {
if (!item) return item;
let nextItem = item;
const key = item._fileKey;
if (key && roleMap[key]) {
nextItem = {
...nextItem,
roles: roleMap[key]
};
}
if ('items' in nextItem && Array.isArray(nextItem.items)) {
const nextItems = applyRoles(nextItem.items);
if (nextItems !== nextItem.items) {
nextItem = {
...nextItem,
items: nextItems
};
}
}
return nextItem;
});
};
dataWithRoles = applyRoles(data);
}
} catch (e) {
}
return markLockedSidebarItems(dataWithRoles, userContext);
}, [
sidebar,
pathname,
roleVersion
]);
return sidebarData;
}
// Get first accessible (not locked) page from sidebar items
function getFirstAccessiblePage(items) {
if (!Array.isArray(items)) return null;
for (const item of items) {
if (!item) continue;
if ('dividerType' in item) continue;
// If item is locked, skip it
if (item.locked === true) continue;
// If item has a link and is not locked, return it
if ('link' in item && item.link) {
return { text: item.text, link: item.link };
}
// If item has children, search recursively
if ('items' in item && Array.isArray(item.items)) {
const found = getFirstAccessiblePage(item.items);
if (found) return found;
}
}
return null;
}
// Hook to redirect to first accessible page if current page is locked
function useRedirectToAccessiblePage() {
const { pathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const navigate = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useNavigate)();
const { siteData } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const items = useSidebarData();
const hasAuthEndpoint = !!siteData?.auth?.endpoints?.userContext;
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
if (!items || items.length === 0) return;
// If auth endpoint is configured, wait for user context to resolve before redirecting
if (hasAuthEndpoint && !isUserContextResolved()) return;
// Find current page in sidebar
const findCurrentPage = (items, targetPath) => {
for (const item of items) {
if (!item) continue;
if ('dividerType' in item) continue;
if ('link' in item && item.link) {
const itemPath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)(item.link);
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(itemPath, targetPath)) {
return item;
}
}
if ('items' in item && Array.isArray(item.items)) {
const found = findCurrentPage(item.items, targetPath);
if (found) return found;
}
}
return null;
};
const currentPage = findCurrentPage(items, pathname);
// If current page is locked, redirect to first accessible page
if (currentPage && currentPage.locked === true) {
const firstAccessible = getFirstAccessiblePage(items);
if (firstAccessible && firstAccessible.link) {
navigate((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)(firstAccessible.link), { replace: true });
}
}
}, [items, pathname, navigate]);
}
function usePrevNextPage() {
const { pathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const items = useSidebarData();
const flattenTitles = [];
const walk = (sidebarItem) => {
// Skip locked items
if (sidebarItem.locked === true) return;
if ('items' in sidebarItem) {
if (sidebarItem.link) flattenTitles.push({
text: sidebarItem.text,
link: sidebarItem.link
});
sidebarItem.items.forEach((item) => {
'dividerType' in item || walk(item);
});
} else flattenTitles.push(sidebarItem);
};
items.forEach((item) => !('dividerType' in item) && walk(item));
const pageIndex = flattenTitles.findIndex((item) => (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)(item.link), pathname));
const prevPage = flattenTitles[pageIndex - 1] || null;
const nextPage = flattenTitles[pageIndex + 1] || null;
return {
prevPage,
nextPage
};
}
const index_module = {
pager: "pager_d6903",
"has-next": "has-next_e91b1",
hasNext: "has-next_e91b1",
prev: "prev_c92d1",
next: "next_c11be"
};
function DocFooter() {
const { prevPage, nextPage } = usePrevNextPage();
const { lastUpdated: localesLastUpdated = false } = useLocaleSiteData();
const { siteData } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const { themeConfig } = siteData;
const showLastUpdated = themeConfig.lastUpdated || localesLastUpdated;
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("footer", {
className: "mt-8",
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: "xs:flex pb-5 px-2 justify-end items-center",
children: showLastUpdated && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.LastUpdated, {})
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: "flex flex-col",
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.EditLink, {})
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
className: "flex flex-col sm:flex-row sm:justify-around gap-4 pt-6",
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: `${index_module.prev} flex flex-col`,
children: prevPage ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.PrevNextPage, {
type: "prev",
text: prevPage.text,
href: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeHrefInRuntime)(prevPage.link)
}) : null
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: `${index_module.next} flex flex-col`,
children: nextPage ? (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.PrevNextPage, {
type: "next",
text: nextPage.text,
href: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeHrefInRuntime)(nextPage.link)
}) : null
})
]
})
]
});
}
const Nav_index_module = {
hidden: "hidden_f8586",
container: "container_e4235",
navContainer: "navContainer_d18b1",
leftNav: "leftNav_e6722",
rightNav: "rightNav_a2fea",
singleItem: "singleItem_c1154",
activeItem: "activeItem_a28b5",
navBarTitle: "navBarTitle_c5f07",
"menu-item": "menu-item_b8238",
menuItem: "menu-item_b8238",
mobileNavMenu: "mobileNavMenu_e7045",
mask: "mask_cea59",
docPage: "docPage_b27ff"
};
const NavBarTitle = () => {
const { siteData } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.usePageData)();
const localeData = useLocaleSiteData();
const { logo: rawLogo, logoText } = siteData;
const title = localeData.title ?? siteData.title;
const logo = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(() => {
if (!rawLogo) return null;
if ('string' == typeof rawLogo) return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("img", {
src: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeImagePath)(rawLogo),
alt: "logo",
id: "logo",
className: "rspress-logo"
});
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("img", {
src: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeImagePath)(rawLogo.light),
alt: "logo",
id: "logo",
className: "rspress-logo dark:hidden"
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("img", {
src: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeImagePath)(rawLogo.dark),
alt: "logo",
id: "logo",
className: "rspress-logo hidden dark:block"
})
]
});
}, [
rawLogo
]);
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: `${Nav_index_module.navBarTitle}`,
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Link, {
href: localeData.langRoutePrefix,
className: "flex items-center w-full h-full text-base font-semibold transition-opacity duration-300 hover:opacity-60",
children: [
logo && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: "min-w-8",
children: logo
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
style: {
border: '1px solid #D2D5DA',
height: '24px',
margin: '0 12px',
},
}),
logoText && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
children: logoText,
style: {
fontSize: '20px',
}
}),
!logo && !logoText && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
children: title
}),
],
})
});
};
function SidebarDivider(props) {
const { depth, dividerType } = props;
const borderTypeStyle = 'dashed' === dividerType ? 'border-dashed' : 'border-solid';
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: `${borderTypeStyle} border-t border-divider-light my-3`,
style: {
marginLeft: 0 === depth ? 0 : '18px'
}
});
}
function SvgWrapper({ icon: Icon, ...rest }) {
if (!Icon) return null;
if ('string' == typeof Icon) return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("img", {
src: Icon,
alt: "",
...rest
});
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(Icon, {
...rest
});
}
const Sidebar_index_module = {
navTitleMask: "navTitleMask_fb17c",
sidebar: "sidebar_dd719",
sidebarContent: "sidebarContent_da296",
open: "open_becbd",
menuLink: "menuLink_bb039",
menuItem: "menuItem_ac22e",
collapseContainer: "collapseContainer_d6e4e",
menuItemActive: "menuItemActive_de63c",
menuGroupActive: "menuGroupActive_e3177"
};
const isSidebarDivider = (item) => 'dividerType' in item;
const isSidebarSingleFile = (item) => !('items' in item) && 'link' in item;
const isSidebarSectionHeader = (item) => 'sectionHeaderText' in item;
const isSideBarCustomLink = (item) => 'link' in item && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(item.link);
const preloadLink = (link) => {
const route = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(link);
if (route) route.preload();
};
const useActiveMatcher = () => {
const { pathname: rawPathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
const activeMatcher = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((link) => {
const pathname = decodeURIComponent(rawPathname);
return getSidebarDataGroup_isActive(link, pathname);
}, [
rawPathname
]);
return activeMatcher;
};
function SidebarGroup(props) {
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
const navigate = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useNavigate)();
const containerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
const transitionRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
const innerRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
const initialRender = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(true);
const initialState = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(!('collapsed' in item) || item.collapsed);
const active = item.link && activeMatcher(item.link);
const { collapsed, collapsible = true } = item;
const isLocked = item.locked === true;
// Lock icon SVG for groups
const GroupLockIcon = () => (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("svg", {
xmlns: "http://www.w3.org/2000/svg",
width: "14",
height: "14",
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round",
style: { marginLeft: '6px', opacity: 0.6, flexShrink: 0 },
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("rect", { x: "3", y: "11", width: "18", height: "11", rx: "2", ry: "2" }),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" })
]
});
const collapsibleIcon = (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
style: {
cursor: isLocked ? 'not-allowed' : 'pointer',
transition: 'transform 0.2s ease-out',
transform: collapsed ? 'rotate(0deg)' : 'rotate(90deg)'
},
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SvgWrapper, {
icon: __WEBPACK_EXTERNAL_MODULE__theme_assets_arrow_right_3f3bb17d__["default"]
})
});
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
if (initialRender.current) return;
if (!containerRef.current || !innerRef.current) return;
if (transitionRef.current) clearTimeout(transitionRef.current);
const container = containerRef.current;
const inner = innerRef.current;
const contentHeight = inner.clientHeight + 4;
if (collapsed) {
container.style.maxHeight = `${contentHeight}px`;
container.style.transitionDuration = '0.5s';
inner.style.opacity = '0';
transitionRef.current = window.setTimeout(() => {
if (containerRef.current) containerRef.current.style.maxHeight = '0px';
}, 0);
} else {
container.style.maxHeight = `${contentHeight}px`;
container.style.transitionDuration = '0.3s';
inner.style.opacity = '1';
transitionRef.current = window.setTimeout(() => {
if (containerRef.current) containerRef.current.style.removeProperty('max-height');
}, 300);
}
}, [
collapsed
]);
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
initialRender.current = false;
}, []);
const toggleCollapse = (e) => {
e.stopPropagation();
if (isLocked) return; // Prevent collapse toggle for locked items
setSidebarData((sidebarData) => {
const newSidebarData = [
...sidebarData
];
const indexes = id.split('-').map(Number);
const initialIndex = indexes.shift();
const root = newSidebarData[initialIndex];
let current = root;
for (const index of indexes) current = current.items[index];
if ('items' in current) current.collapsed = !current.collapsed;
return newSidebarData;
});
};
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("section", {
className: "rspress-sidebar-section mt-0.5 block",
"data-context": item.context,
style: {
marginLeft: 0 === depth ? 0 : '18px',
opacity: isLocked ? 0.6 : 1
},
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
className: `rspress-sidebar-collapse flex items-center ${active ? Sidebar_index_module.menuItemActive : Sidebar_index_module.menuItem}`,
"data-context": item.context,
onMouseEnter: () => !isLocked && item.link && preloadLink(item.link),
onClick: (e) => {
if (isLocked) {
e.preventDefault();
e.stopPropagation();
return;
}
if (item.link) navigate((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.withBase)((0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeHrefInRuntime)(item.link)));
collapsible && toggleCollapse(e);
},
style: {
// borderRadius: 0 === depth ? '0 var(--rp-radius) var(--rp-radius) 0' : void 0,
cursor: isLocked ? 'not-allowed' : (collapsible || item.link ? 'pointer' : 'normal')
},
children: [
collapsible && !isLocked && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: `${Sidebar_index_module.collapseContainer} p-2 rounded-xl`,
style: {
paddingRight: 0
},
onClick: toggleCollapse,
children: collapsibleIcon
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("h2", {
className: "py-2 px-2 text-sm font-medium flex items-center",
style: {
...highlightTitleStyle
},
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Tag, {
tag: item.tag
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
className: "flex-center",
style: {
fontSize: 0 === depth ? '14px' : '13px',
fontWeight: 400,
letterSpacing: '-1%'
},
children: renderInlineMarkdown(item.text)
}),
isLocked && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(GroupLockIcon, {})
]
})
]
}),
!isLocked && (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
ref: containerRef,
className: "transition-all duration-300 ease-in-out",
style: {
overflow: 'hidden',
maxHeight: initialState.current ? 0 : void 0
},
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
ref: innerRef,
className: "rspress-sidebar-group transition-opacity duration-500 ease-in-out",
style: {
opacity: initialState.current ? 0 : 1,
marginLeft: 0 === depth ? '12px' : 0
},
children: item?.items?.map((item, index) => isSidebarDivider(item) ? __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx(SidebarDivider, {
depth: depth + 1,
dividerType: item.dividerType
}, index) : __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx("div", {
className: "rspress-sidebar-item",
"data-context": item.context,
children: __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx(SidebarItem, {
...props,
item: item,
depth: depth + 1,
id: `${id}-${index}`
})
}, index))
})
})
]
}, id);
}
function SidebarItem(props) {
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
const active = 'link' in item && item.link && activeMatcher(item.link);
const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
const isLocked = item.locked === true;
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
if (active) ref.current?.scrollIntoView({
block: 'center'
});
}, []);
if ('items' in item) return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SidebarGroup, {
id: id,
activeMatcher: activeMatcher,
item: item,
depth: depth,
collapsed: item.collapsed,
setSidebarData: setSidebarData
}, `${item.text}-${id}`);
// Lock icon SVG
const LockIcon = () => (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("svg", {
xmlns: "http://www.w3.org/2000/svg",
width: "14",
height: "14",
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: "2",
strokeLinecap: "round",
strokeLinejoin: "round",
style: { marginLeft: '6px', opacity: 0.6, flexShrink: 0 },
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("rect", { x: "3", y: "11", width: "18", height: "11", rx: "2", ry: "2" }),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" })
]
});
if (isLocked) {
// Locked item - show lock icon and prevent navigation
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
className: Sidebar_index_module.menuLink,
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
},
style: { cursor: 'not-allowed' },
children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
ref: ref,
className: `${Sidebar_index_module.menuItem} mt-0.5 py-2 px-3 font-medium flex items-center justify-between`,
style: {
fontSize: 0 === depth ? '14px' : '13px',
marginLeft: 0 === depth ? 0 : '18px',
opacity: 0.6,
...0 === depth ? highlightTitleStyle : {}
},
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("span", {
className: "flex items-center",
children: [
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Tag, {
tag: item.tag
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("span", {
style: {
fontSize: 0 === depth ? '14px' : '13px',
fontWeight: 400
},
children: renderInlineMarkdown(item.text)
})
]
}),
(0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(LockIcon, {})
]
})
});
}
return (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__theme_75e53063__.Link, {
href: (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.normalizeHrefInRuntime)(item.link),
className: Sidebar_