Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const knowledge = addKnowledge<DefaultTheme.Config>({
'/blog/': 'blog',
},
layoutSelectors: {
blog: '.container-content',
blog: '.vp-doc > .container',
},
pageSelectors: {
'examples.md': '#VPContent > .VPPage',
Expand Down
89 changes: 89 additions & 0 deletions docs/.vitepress/typedoc-inject-contents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// @ts-check
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';
import { ReflectionKind } from 'typedoc';

// Same algorithm as typedoc-vitepress-theme's slugifyAnchor so TOC links resolve.
// eslint-disable-next-line no-control-regex
const rControl = /[\u0000-\u001f]/g;
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
const rCombining = /[\u0300-\u036f]/g;

/** @param {string} str */
function slugifyAnchor(str) {
return str
.normalize('NFKD')
.replace(rCombining, '')
.replace(rControl, '')
.replace(rSpecial, '-')
.replace(/-{2,}/g, '-')
.replace(/^-+|-+$/g, '')
.replace(/^(\d)/, '_$1')
.toLowerCase();
}

/** @param {string} heading */
function plainHeadingText(heading) {
return heading
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
.replace(/[*`_~]/g, '')
.trim();
}

/**
* Restore the in-page "## Contents" TOC from typedoc-plugin-markdown
* 4.0.0-next.
*
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
*/
export function load(app) {
app.renderer.on(MarkdownPageEvent.END, (page) => {
if (!page.contents) return;
if (/(?:^|\n)## Contents\n/.test(page.contents)) return;
if (!page.isReflectionEvent()) return;

const reflection = page.model;
if (
!reflection.kindOf([
ReflectionKind.Project,
ReflectionKind.Module,
ReflectionKind.Namespace,
ReflectionKind.Enum,
ReflectionKind.Class,
ReflectionKind.Interface,
])
) {
return;
}

// TypeDoc 0.28 moved "own document" checks onto the router. Approximate the
// old hasToc gate: only inject when the page has multiple in-page headings.
const headingRe = /^(#{2,3})\s+(.+)$/gm;
/** @type {{ level: number; text: string }[]} */
const headings = [];
for (const match of page.contents.matchAll(headingRe)) {
headings.push({ level: match[1].length, text: match[2].trim() });
}
if (headings.length <= 2) return;

/** @type {Map<string, number>} */
const slugCounts = new Map();
const toc = headings
.map(({ level, text }) => {
const plain = plainHeadingText(text);
const base = slugifyAnchor(plain);
const count = (slugCounts.get(base) ?? 0) + 1;
slugCounts.set(base, count);
const slug = count > 1 ? `${base}-${count - 1}` : base;
const indent = ' '.repeat(Math.max(0, level - 2));
return `${indent}- [${plain}](#${slug})`;
})
.join('\n');

const lines = page.contents.split('\n');
const firstHeadingIndex = lines.findIndex((line) => line.startsWith('## '));
if (firstHeadingIndex < 1) return;

lines.splice(firstHeadingIndex, 0, '', '## Contents', '', toc, '');
page.contents = lines.join('\n');
});
}
2 changes: 1 addition & 1 deletion docs/.vitepress/utils/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function menuItem(
/** Clean up and add badges to typedoc leaf sections */
export function prepareTypedocSidebar(items: SidebarItem[]) {
// skip contents file
const filtered = items.slice(1);
const filtered = items;

// remove Typedoc's collapse: true from text nodes
const prepareItems = (items: DefaultTheme.SidebarItem[], depth = 0) => {
Expand Down
20 changes: 19 additions & 1 deletion docs/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"$schema": "https://typedoc.org/schema.json",
"name": "API",
"entryPointStrategy": "packages",
"docsRoot": ".",
"navigation": {
"includeFolders": false,
"includeGroups": true
},
"entryPoints": ["../packages/wxt"],
"plugin": [
"typedoc-plugin-markdown",
"typedoc-vitepress-theme",
"typedoc-plugin-frontmatter"
"typedoc-plugin-frontmatter",
"./.vitepress/typedoc-inject-contents.mjs"
],
"out": "./api/reference",
"githubPages": false,
Expand All @@ -15,5 +22,16 @@
"readme": "none",
"frontmatterGlobals": {
"editLink": false
},
"textContentMappings": {
"breadcrumbs.home": "API",
"footer.text": "Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)",
"title.indexPage": "API",
"title.modulePage": "{kind}: {name}"
},
"locales": {
"en": {
"theme_defined_in": "Source"
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"tinyglobby": "^0.2.16",
"tsdown": "catalog:",
"tsx": "4.21.0",
"typedoc": "^0.25.4",
"typedoc": "^0.28.20",
"typedoc-plugin-frontmatter": "^1.3.1",
"typedoc-plugin-markdown": "4.0.0-next.23",
"typedoc-vitepress-theme": "1.0.0-next.3",
"typedoc-plugin-markdown": "^4.12.0",
"typedoc-vitepress-theme": "^1.1.3",
"typescript": "catalog:",
"vitepress": "^1.6.4",
"vitepress-knowledge": "^0.4.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ export interface WxtHooks {
* Called when WXT has created Vite's config for the dev server. Useful if you
* want to add plugins or update the vite config per entrypoint group.
*
* @param viteConfig The config that will be used to build the entrypoints.
* Can be updated by reference.
* @param config The config that will be used to build the entrypoints. Can be
* updated by reference.
*/
'vite:devServer:extendConfig': (config: vite.InlineConfig) => HookResult;
}
Expand Down Expand Up @@ -695,7 +695,7 @@ export interface BaseScriptEntrypointOptions extends BaseEntrypointOptions {
* the default IIFE variable name may conflict with an existing variable on
* the target page. This applies to content scripts with world=MAIN, and
* others, such as unlisted scripts, that could be dynamically injected into
* the page with a <script> tag.
* the page with a `<script>` tag.
*
* Available options:
*
Expand Down Expand Up @@ -1449,15 +1449,15 @@ export interface WxtHooks {
* Called once all entrypoints have been grouped into their build groups.
*
* @param wxt The configured WXT object
* @param entrypoints The list of groups to build in each build step
* @param groups The list of groups to build in each build step
*/
'entrypoints:grouped': (wxt: Wxt, groups: EntrypointGroup[]) => HookResult;
/**
* Called when public assets are found. You can modify the `files` list by
* reference to add or remove public files.
*
* @param wxt The configured WXT object
* @param entrypoints The list of files that will be copied into the output
* @param files The list of files that will be copied into the output
* directory
*/
'build:publicAssets': (wxt: Wxt, files: ResolvedPublicFile[]) => HookResult;
Expand Down
1 change: 0 additions & 1 deletion packages/wxt/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"src/utils/match-patterns.ts",
"src/utils/split-shadow-root-css.ts",
"src/utils/storage.ts",
"src/testing/index.ts",
"src/testing/fake-browser.ts",
"src/testing/wxt-vitest-plugin.ts",
"src/modules.ts"
Expand Down