import { ReaderAidMode, ReaderPreferences, ReaderProgressRecord, ReaderWidthPreset, ResolvedNavItemWithLink, ResolvedReaderOptions, ResolvedReaderPalette, ThemeSeries, ThemeSeriesData, } from '../../shared/index.js' export declare function createSymbol(name: string): symbol /** * Bounding rect of a trigger element. * * 触发元素的包围盒。 */ export interface PreviewRect { top: number left: number right: number bottom: number width: number height: number } /** * Size of an element or of the viewport. * * 元素或视口尺寸。 */ export interface PreviewSize { width: number height: number } /** * Options of the positioning algorithm. * * 定位算法的配置。 */ export interface PreviewPositionOptions { /** * Gap between the anchor and the card * * 卡片与链接之间的间距 */ offset?: number /** * Min gap between the card and the viewport edge * * 卡片与视口边缘的最小间距 */ margin?: number } /** * Resolved fixed position of the card. * * 计算出的卡片 fixed 定位。 */ export interface PreviewPosition { top: number left: number placement: 'top' | 'bottom' } /** * Normalize a route path into a comparable preview key. * Mirrors `node/features/linkPreview/key.ts`. * * 将路由路径序列化为可比较的预览键。 * 与 `node/features/linkPreview/key.ts` 保持一致。 * * @param pathname - Route path / 路由路径 */ export declare function normalizePreviewPath(pathname: string): string /** * Strip the site base prefix from a pathname. * * 去除站点 `base` 前缀(用前缀切片而不是正则)。 * * @param pathname - Absolute pathname / 绝对路径 * @param base - Site base / 站点 base */ export declare function stripBase(pathname: string, base: string): string /** * Resolve the preview key of an anchor href (pure, unit-testable). * * 由 `href` 解析预览键:剥离 base,标准化路径,并在以下情况 * 返回 `null`:锚点链接、外部协议、外站链接、当前页链接。 * * 相对路径按当前页面路由解析,与点击链接时的浏览器行为一致。 * * @param href - Raw `href` attribute / 链接的 `href` 属性值 * @param base - Site base / 站点 base * @param currentKey - Normalized key of the current page / 当前页的归一化键 * @param selfOrigin - `location.origin` / 当前站点 origin */ export declare function resolveAnchorKey( href: string | null | undefined, base: string, currentKey: string, selfOrigin: string, ): string | null /** * Resolve the fixed position of the preview card. * * 计算预览卡片的 fixed 定位:默认在链接下方,空间不足时翻转到上方, * 水平方向裁剪到视口内。 * * @param anchor - Bounding rect of the trigger / 触发链接的包围盒 * @param card - Size of the card / 卡片尺寸 * @param viewport - Size of the viewport / 视口尺寸 * @param options - Positioning options / 定位配置 */ export declare function resolvePreviewPosition( anchor: PreviewRect, card: PreviewSize, viewport: PreviewSize, options?: PreviewPositionOptions, ): PreviewPosition /** * Convert a DOMRect into a plain rect object. * * 将 DOMRect 转换为普通对象。 * * @param rect - DOM rect / DOM 包围盒 */ export declare function toPreviewRect( rect: | DOMRect | { top: number left: number right: number bottom: number width: number height: number }, ): PreviewRect /** * Minimal shape required to resolve a post's sticky priority. * * 解析文章置顶优先级所需的最小结构。 */ interface StickyPost { sticky?: boolean | number } /** * Resolve the numeric priority of a post's `sticky` frontmatter value. * * - `true` → `Number.MAX_SAFE_INTEGER`, so a plain `sticky: true` always ranks * above any number. * - A finite positive number → the number itself (larger ranks first). * - Anything else (`false`, `undefined`, `0`, negative or non-finite numbers) → `0`, * which means "not sticky". * * Normalizing to a single comparable number keeps the sort total and stable when * `true` and numbers are mixed, and makes `sticky: 0` behave as "not sticky". * * 解析文章 `sticky` frontmatter 的数值优先级。 * * - `true` → `Number.MAX_SAFE_INTEGER`,使 `sticky: true` 始终排在任意数字之前; * - 有限正数 → 数值本身(越大越靠前); * - 其他(`false`、`undefined`、`0`、负数或非有限数)→ `0`,表示不置顶。 * * 统一归一化为可比较的数值,可以在 `true` 与数字混用时保持排序完整且稳定, * 并让 `sticky: 0` 表现为不置顶。 */ export declare function resolveSticky(sticky: boolean | number | undefined | null): number /** * Sort posts by sticky priority (descending) without mutating the input. * * Sticky posts are moved to the front, ordered by descending priority; the * remaining posts keep their original relative order. Because * `Array.prototype.sort` is stable, posts sharing the same priority preserve * the order they were provided in. * * Note that the sorted list is paginated afterwards, so sticky posts are only * pinned on the first page. * * 按置顶优先级降序排列文章,且不修改入参。 * * 置顶文章被移动到最前并按优先级降序排列,其余文章保持原有相对顺序。由于 * `Array.prototype.sort` 是稳定的,优先级相同的文章会保持传入顺序。 * * 注意:排序后的列表会再进行分页切片,因此置顶文章仅在第 1 页置顶。 */ export declare function sortPostsBySticky(posts: readonly T[]): T[] /** * 能用上「桌面专属」控件的屏幕宽度。 * * 低于该宽度时正文本就铺满、没有 hover 可驱动辅助线、专注模式还会藏起唯一的导航入口, * 因此宽度、阅读辅助线与专注模式会被隐藏并使用默认值。 */ export declare const READER_DESKTOP_QUERY = '(min-width: 769px)' /** * Whether the settings panel has anything to offer. * * A locale may enable only the progress bar and the resume prompt, in which case * the settings entry should not render at all. On small screens only the reading * background is left, so a locale that enabled nothing else has no panel there. * * 设置面板是否有可操作项。 * * 语言配置可能只启用进度条与继续阅读,此时不应渲染设置入口。 * 小屏幕上只剩护眼背景,因此只启用了桌面控件时也不会出现入口。 * * @param options - Resolved options / 已解析的配置 * @param mobile - Whether the viewport is a small screen / 是否小屏幕 */ export declare function hasReaderControls( options: ResolvedReaderOptions | null, mobile?: boolean, ): boolean /** * Resolve the width preset that can actually be applied. * * Small screens always use `standard`: the text already fills the viewport, so a * preset would either do nothing or narrow the content for no reason. * * 解析真正能生效的宽度档位。 * * 小屏幕一律使用 `standard`:正文本就铺满视口,档位要么无效、要么无谓地收窄正文。 * * @param preset - Selected preset / 选中的档位 * @param options - Resolved options / 已解析的配置 * @param mobile - Whether the viewport is a small screen / 是否小屏幕 */ export declare function resolveEffectiveWidth( preset: ReaderPreferences['width'], options: ResolvedReaderOptions | null, mobile?: boolean, ): ReaderWidthPreset | null /** * Resolve whether the focus mode can actually be enabled. * * Small screens never use it: hiding the navbar there also hides the only way to * open the navigation drawer. * * 解析专注模式是否真正生效。 * * 小屏幕永不启用:那里的导航栏同时承载打开抽屉的唯一入口。 * * @param focus - Stored preference / 存储的偏好 * @param mobile - Whether the viewport is a small screen / 是否小屏幕 */ export declare function resolveEffectiveFocus( focus: ReaderPreferences['focus'], mobile?: boolean, ): boolean /** * Resolve the reading aid configuration that applies to the current page. * * `readerPreferences.readAid` wins; the legacy `collection.readAid` / * `theme.locales[].readAid` options are still honoured as the default mode when * the new option does not set one, where `true` keeps its historical meaning of * `left`. That way enabling `readerPreferences` never silently drops a * previously configured guide line. * * 解析当前页真正生效的阅读辅助线配置。 * * `readerPreferences.readAid` 优先;新配置未指定默认形态时,旧的 * `collection.readAid` / `theme.locales[].readAid` 仍作为默认形态, * 其中 `true` 沿用历史含义 `left`。这样启用阅读偏好不会静默丢掉原本配置的辅助线。 * * @param options - Resolved reader options / 已解析的阅读偏好配置 * @param legacy - Legacy option / 旧配置 */ export declare function resolveReaderAidConfig( options: ResolvedReaderOptions | null, legacy: boolean | ReaderAidMode | undefined, ): { modes: ReaderAidMode[] default: ReaderAidMode | null } | null /** * Normalize stored preferences against the allowed presets. * * Values outside the enabled presets are dropped, unknown fields are dropped. * This guarantees that tightening the configuration never leaves a stale value * driving a UI state that no longer exists. * * 用配置约束存储值:不在启用档位内的值被丢弃,未知字段被丢弃。 * 保证「站长收紧配置后,老用户的旧数据不会产生非法 UI」。 * * @param raw - Stored value, may be a JSON string or an already parsed object * 原始存储值,可以是 JSON 字符串或已解析的对象 * @param options - Resolved options, `null` when the feature is disabled * 已解析的配置,功能关闭时为 `null` */ export declare function normalizeReaderPreferences( raw: unknown, options: ResolvedReaderOptions | null, ): ReaderPreferences /** * Resolve the reading aid mode that can actually be applied. * * A stored mode wins when the configuration still offers it, otherwise the * configured default is used; `null` means "off". Small screens always get * `null`: there is no hover to follow. * * 解析真正生效的阅读辅助线形态。 * * 存储值仍在可选范围内时优先,否则回退到配置的默认值;`null` 表示关闭。 * 小屏幕一律为 `null`:没有 hover 可供跟随。 * * @param config - Reading aid configuration / 阅读辅助线配置 * @param stored - Stored mode / 存储的形态 * @param mobile - Whether the viewport is a small screen / 是否小屏幕 */ export declare function resolveEffectiveAid( config: { modes: ReaderAidMode[] default: ReaderAidMode | null } | null, stored: ReaderPreferences['aid'], mobile?: boolean, ): ReaderAidMode | null /** * Resolve the background palette that can actually be applied. * * In dark mode every palette is disabled (returns `null`), so that * "dark + sepia" cannot physically exist. `default` means "no override" and * writes no attribute either. * * 解析真正能生效的背景调色板。 * * 暗色模式下所有调色板一律失效(返回 `null`),让「深色 + 纸黄」在物理上不存在。 * `default` 表示「不覆盖」,同样不写属性。 * * @param presets - Enabled palettes / 启用的调色板 * @param stored - Stored palette name / 存储的调色板名称 * @param isDark - Whether the site is in dark mode / 是否深色模式 */ export declare function resolveEffectiveTheme( presets: ResolvedReaderPalette[] | null, stored: string | undefined, isDark: boolean, ): string | null /** * Resolve the brand palette that can actually be applied. * * Unlike the reading background it also works in dark mode. * * 解析真正能生效的品牌色调色板。 * * 与护眼背景不同,它在深色模式下同样生效。 * * @param presets - Enabled palettes / 启用的调色板 * @param stored - Stored palette name / 存储的调色板名称 */ export declare function resolveEffectiveBrand( presets: ResolvedReaderPalette[] | null, stored: string | undefined, ): string | null /** * Measurements used to compute the reading progress. * * 计算阅读进度所需的测量值。 */ export interface ReadingProgressInput { /** * Current scroll offset / 当前滚动位置 */ scrollY: number /** * Top offset of the content, relative to the document / 正文相对文档的顶部偏移 */ docTop: number /** * Height of the content / 正文高度 */ docHeight: number /** * Viewport height / 视口高度 */ viewportHeight: number } /** * Compute the reading progress from measurements. * * The progress is relative to the document body content, not to the whole page, * so that the footer, comments and related posts do not count as "read". * * 以正文为基准计算进度,返回 `0`–`1`。 * * 进度相对正文而不是整页,因此页脚、评论与相关推荐不会被算作「已读」。 * * @param input - Measurements / 测量值 */ export declare function computeReadingProgress(input: ReadingProgressInput): number /** * Inputs of the "continue reading" decision. * * 「继续阅读」判定的入参。 */ export interface ResumeDecisionInput { /** * Stored record, if any / 已保存的记录(如果有) */ stored?: ReaderProgressRecord /** * Whether the URL carries a hash / URL 是否带 hash */ hasHash: boolean /** * Whether the navigation came from `popstate` / 是否来自 `popstate` */ cameFromPopState: boolean /** * Lower bound of the prompt window / 提示窗口下界 */ minPercent: number /** * Upper bound of the prompt window / 提示窗口上界 */ maxPercent: number /** * Record TTL in days / 记录有效期(天) */ ttlDays: number /** * Current timestamp in ms / 当前时间戳(毫秒) */ now: number } /** * Decide whether to offer "continue reading". * * Shown only when a record exists, the URL has no hash, the navigation was not a * browser back/forward, the record is not expired, and the progress sits in the * `[minPercent, maxPercent]` window. * * 判断是否展示「继续阅读」。 * * 仅在「有记录 / 无 hash / 非浏览器的前进后退 / 未过期 / 进度落在窗口内」时展示。 * * @param input - Decision inputs / 判定入参 */ export declare function shouldOfferResume(input: ResumeDecisionInput): boolean /** * Prune stale records by TTL and count. * * Returns a new object, the input is never mutated. * * 按 TTL 与数量上限裁剪,返回新对象,不修改入参。 * * @param record - All records / 全部记录 * @param max - Max records kept / 最多保留条数 * @param ttlDays - TTL in days / 有效期(天) * @param now - Current timestamp in ms / 当前时间戳 */ export declare function pruneRecords< T extends { t: number }, >(record: Record, max: number, ttlDays: number, now: number): Record /** * Minimal attribute target, a subset of `Element`. * * 最小属性目标,是 `Element` 的子集。 */ export interface AttributeTarget { /** * Write an attribute / 写入属性 */ setAttribute: (name: string, value: string) => void /** * Remove an attribute / 移除属性 */ removeAttribute: (name: string) => void } /** * Set or remove an attribute. * * `null` removes the attribute, any other value writes it. `standard` / * `default` states therefore never appear in the DOM. * * 设置或移除属性。 * * `null` 表示移除属性,其余值写入属性。因此 `standard` / `default` 状态永远不会出现在 DOM 中。 * * @param target - Element to mutate / 要修改的元素 * @param name - Attribute name / 属性名 * @param value - Attribute value or `null` / 属性值或 `null` */ export declare function setReaderAttr( target: AttributeTarget, name: string, value?: string | null, ): void /** * Supported repository types * Represents the type of code hosting platform * * 支持的仓库类型 * 表示代码托管平台的类型 */ export type RepoType = 'GitHub' | 'GitLab' | 'Gitee' | 'Bitbucket' | null /** * Resolve the repository type from a repository URL * Detects the platform based on URL patterns * * 从仓库 URL 解析仓库类型 * 基于 URL 模式检测平台 * * @param repo - Repository URL or path / 仓库 URL 或路径 * @returns The detected repository type or null if unknown / 检测到的仓库类型,如果未知则返回 null */ export declare function resolveRepoType(repo: string): RepoType /** * Edit link patterns for different repository platforms * Maps repository types to their respective edit URL patterns * * 不同仓库平台的编辑链接模式 * 将仓库类型映射到各自的编辑 URL 模式 */ export declare const editLinkPatterns: Record, string> /** * Resolve the complete edit link URL for a file * Generates an edit link based on repository configuration and file path * * 解析文件的完整编辑链接 URL * 根据仓库配置和文件路径生成编辑链接 * * @param params - Parameters object / 参数对象 * @param params.docsRepo - Repository URL / 仓库 URL * @param params.docsBranch - Branch name / 分支名称 * @param params.docsDir - Documentation directory / 文档目录 * @param params.filePathRelative - Relative file path / 相对文件路径 * @param params.editLinkPattern - Custom edit link pattern / 自定义编辑链接模式 * @returns The complete edit link URL or null / 完整的编辑链接 URL,如果无法生成则返回 null */ export declare function resolveEditLink({ docsRepo, docsBranch, docsDir, filePathRelative, editLinkPattern, }: { docsRepo: string docsBranch: string docsDir: string filePathRelative: string | undefined editLinkPattern?: string }): string | null /** * Resolve NavLink props from string * Converts a link string to a resolved navigation item with metadata * * 从字符串解析 NavLink 属性 * 将链接字符串转换为带有元数据的解析导航项 * * @param link - The link string to resolve / 要解析的链接字符串 * @returns Resolved navigation item with link, text, icon and badge / 解析后的导航项,包含链接、文本、图标和徽章 * @example * - Input: '/README.md' * - Output: { text: 'Home', link: '/' } */ export declare function resolveNavLink(link: string): ResolvedNavItemWithLink /** * Normalize a link by combining base and link * Handles absolute links and protocol links correctly * * 通过组合 base 和 link 来规范化链接 * 正确处理绝对链接和协议链接 * * @param base - Base URL / 基础 URL * @param link - Link to normalize / 要规范化的链接 * @returns Normalized link / 规范化后的链接 */ export declare function normalizeLink(base?: string, link?: string): string /** * Normalize a prefix by ensuring it ends with a slash * * 规范化前缀,确保它以斜杠结尾 * * @param base - Base URL / 基础 URL * @param link - Link to normalize / 要规范化的链接 * @returns Normalized prefix with trailing slash / 带有尾部斜杠的规范化前缀 */ export declare function normalizePrefix(base: string, link?: string): string export declare const ANCHOR_SCROLL_OFFSET = 64 export declare const ACTIVE_ANCHOR_OFFSET = 80 export interface ScrollPosition { left: number top: number } /** * 解码 hash,它可能来自 `location.hash`,此时是百分号编码的。 * * @param hash - Hash to decode / 需要解码的 hash * @returns Decoded hash / 解码后的 hash */ export declare function decodeHash(hash: string): string /** * 标记一次需要保持滚动位置的导航。 * * 供滚动监听同步 URL hash 时使用:该导航不能移动页面,否则新的滚动位置会改变 * 激活标题,进而再次写入 hash 并再次滚动。 * * @param fullPath - Full path of the navigation / 导航的完整路径 * @param position - Position to restore / 需要还原的滚动位置 */ export declare function skipScrollPosition(fullPath: string, position: ScrollPosition): void /** * 当匹配的导航没有发生时,清除待处理的跳过标记。 * * @param fullPath - Full path of the navigation / 导航的完整路径 */ export declare function clearSkippedScrollPosition(fullPath: string): void /** * 获取并消费指定导航需要还原的滚动位置。 * * @param fullPath - Full path of the navigation / 导航的完整路径 * @returns Position to restore, or `null` / 需要还原的位置,没有则为 `null` */ export declare function consumeSkippedScrollPosition(fullPath: string): ScrollPosition | null /** * 解析锚点的滚动位置,并补偿导航栏高度。 * * @param hash - Hash of the anchor / 锚点的 hash * @param offset - Offset reserved for the navbar / 为导航栏预留的偏移量 * @returns Position to scroll to, or `null` when the anchor does not exist / 需要滚动到的位置,锚点不存在时为 `null` */ export declare function resolveAnchorScrollPosition( hash: string, offset?: number, ): ScrollPosition | null /** * Whether two route paths point at the same page, ignoring the trailing slash. * * 判断两个路由路径是否指向同一个页面(忽略结尾斜杠)。 * * @param a - First path / 第一个路径 * @param b - Second path / 第二个路径 */ export declare function isSamePath(a: string, b: string): boolean /** * Resolve the series of the current landing page. * * The path is resolved before the id, and only inside the current locale first: two * locales may declare a series with the same id, and the one of another locale must * never win by accident. The global fallback only accepts a candidate whose landing * page really matches the current path. * * 解析当前落地页对应的系列。优先按路径、且只在当前语言内查找: * 不同语言可能有同名 id 的系列,其它语言的结果不得抢先返回; * 全局回退时也只接受落地页路径确实与当前路径一致的候选项。 * * @param data - Series index of every locale / 所有语言的系列索引 * @param locale - Route locale of the current page / 当前页面的路由语言 * @param path - Route path of the current page / 当前页面的路由路径 * @param id - `frontmatter.seriesId` of the current page / 当前页面的 `frontmatter.seriesId` * @returns Series of the landing page, `null` when it cannot be resolved * 落地页对应的系列,无法解析时为 `null` */ export declare function resolveSeriesPage( data: ThemeSeriesData, locale: string, path: string, id?: unknown, ): ThemeSeries | null /** * Regular expression to match external URLs * * 匹配外部 URL 的正则表达式 */ export declare const EXTERNAL_URL_RE: RegExp /** * Regular expression to match pathname protocol * * 匹配 pathname 协议的正则表达式 */ export declare const PATHNAME_PROTOCOL_RE: RegExp /** * Regular expression to match hash * * 匹配哈希值的正则表达式 */ export declare const HASH_RE: RegExp /** * Regular expression to match file extension * * 匹配文件扩展名的正则表达式 */ export declare const EXT_RE: RegExp /** * Whether running in browser * * 是否在浏览器中运行 */ export declare const inBrowser: boolean /** * Convert value to array * * 将值转换为数组 * * @param value - Value to convert, can be single value or array / 要转换的值,可以是单个值或数组 * @returns Array containing the value(s) / 包含值的数组 */ export declare function toArray(value: T | T[]): T[] /** * Check if the current path matches the given match path * Supports both exact matching and regex matching * * 检查当前路径是否匹配给定的匹配路径 * 支持精确匹配和正则匹配 * * @param currentPath - Current path to check / 要检查的当前路径 * @param matchPath - Path pattern to match against / 要匹配的路径模式 * @param asRegex - Whether to treat matchPath as regex / 是否将 matchPath 视为正则表达式 * @returns True if paths match / 如果路径匹配则返回 true */ export declare function isActive( currentPath: string, matchPath?: string, asRegex?: boolean, ): boolean /** * Normalize a path by removing hash and file extension * * 通过移除哈希值和文件扩展名来规范化路径 * * @param path - Path to normalize / 要规范化的路径 * @returns Normalized path / 规范化后的路径 */ export declare function normalize(path: string): string /** * Convert a numeric value to CSS unit string * Adds 'px' suffix if the value is a plain number * * 将数值转换为 CSS 单位字符串 * 如果值是纯数字则添加 'px' 后缀 * * @param value - Value to convert, can be number or string with unit / 要转换的值,可以是数字或带单位的字符串 * @returns CSS unit string / CSS 单位字符串 */ export declare function numToUnit(value?: string | number): string /** * Check if a value is a CSS gradient * * 检查值是否为 CSS 渐变 * * @param value - Value to check / 要检查的值 * @returns True if value is a gradient / 如果值是渐变则返回 true */ export declare function isGradient(value: string): boolean /** * Get the absolute top position of an element * Accounts for fixed positioned ancestors * * 获取元素的绝对顶部位置 * 考虑固定定位的祖先元素 * * @param element - Element to measure / 要测量的元素 * @returns Absolute top position or NaN / 绝对顶部位置或 NaN */ export declare function getAbsoluteTop(element: HTMLElement): number export declare function stripHtmlTags(input: string): string export {}