@writedocs/generator 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/astro.config.mjs +31 -69
- package/package.json +4 -2
- package/packages/components/package.json +53 -0
- package/{src → packages/components/src}/components/Accordion.astro +2 -2
- package/{src → packages/components/src}/components/AppIcon.astro +3 -3
- package/{src → packages/components/src}/components/Callout.astro +3 -3
- package/{src → packages/components/src}/components/CodeBlock.astro +8 -27
- package/{src → packages/components/src}/components/CodeGroup.astro +3 -3
- package/{src → packages/components/src}/components/Image.astro +7 -9
- package/{src → packages/components/src}/components/compound.ts +1 -1
- package/packages/components/src/host.js +24 -0
- package/packages/components/src/index.ts +59 -0
- package/packages/components/src/integration.js +151 -0
- package/packages/components/src/lib/base-path.js +39 -0
- package/{src → packages/components/src}/lib/code-line-numbers.js +1 -1
- package/packages/components/src/lib/code-transformers.js +45 -0
- package/{src → packages/components/src}/lib/icons.js +13 -7
- package/{src → packages/components/src}/lib/shiki-code-block.js +9 -9
- package/{src → packages/components/src}/lib/site-base.ts +9 -6
- package/packages/components/src/scripts/code-block.ts +62 -0
- package/packages/components/src/styles/components.css +373 -0
- package/packages/components/src/styles/theme.css +63 -0
- package/src/cli/run-astro.js +1 -1
- package/src/components/ApiPlayground.astro +2 -2
- package/src/components/ApiSchemaField.astro +1 -1
- package/src/components/CopyPageMenu.astro +2 -2
- package/src/icons/README.md +1 -1
- package/src/layout/BaseLayout.astro +7 -2
- package/src/layout/components/AnalyticsScripts.astro +2 -2
- package/src/layout/components/Breadcrumbs.astro +1 -1
- package/src/layout/components/ConsentBanner.astro +1 -1
- package/src/layout/components/MobileMenu.astro +2 -2
- package/src/layout/components/NavTree.astro +2 -2
- package/src/layout/components/Sidebar.astro +2 -2
- package/src/layout/components/SiteFooter.astro +2 -2
- package/src/layout/components/TopBar.astro +2 -2
- package/src/layout/styles/base.css +4 -37
- package/src/lib/a11y-check.js +1 -1
- package/src/lib/base-path.js +4 -25
- package/src/lib/color.js +1 -1
- package/src/lib/components-host.ts +21 -0
- package/src/lib/config-file.js +1 -1
- package/src/lib/config.ts +4 -3
- package/src/lib/content-check.js +2 -2
- package/src/lib/link-check.js +2 -2
- package/src/lib/mdx-inject-builtins.js +2 -2
- package/src/lib/mdx-inline-react.js +1 -1
- package/src/lib/mdx-title-anchor-ids.js +2 -2
- package/src/lib/mdx-unknown-components.js +1 -1
- package/src/lib/mintlify-convert.js +2 -2
- package/src/lib/openapi-reload-integration.js +1 -1
- package/src/lib/pages.js +1 -1
- package/src/lib/project-files-integration.js +1 -1
- package/src/lib/rehype-base-path.js +1 -1
- package/src/lib/writedocs-legacy-convert.js +1 -1
- package/src/pages/404.astro +1 -1
- package/src/pages/[...slug].astro +53 -416
- package/src/components/index.ts +0 -62
- /package/{src → packages/components/src}/components/AccordionGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Badge.astro +0 -0
- /package/{src → packages/components/src}/components/Card.astro +0 -0
- /package/{src → packages/components/src}/components/CardGroup.astro +0 -0
- /package/{src → packages/components/src}/components/Check.astro +0 -0
- /package/{src → packages/components/src}/components/Color.astro +0 -0
- /package/{src → packages/components/src}/components/ColorItem.astro +0 -0
- /package/{src → packages/components/src}/components/ColorRow.astro +0 -0
- /package/{src → packages/components/src}/components/Column.astro +0 -0
- /package/{src → packages/components/src}/components/Columns.astro +0 -0
- /package/{src → packages/components/src}/components/Danger.astro +0 -0
- /package/{src → packages/components/src}/components/Expandable.astro +0 -0
- /package/{src → packages/components/src}/components/Frame.astro +0 -0
- /package/{src → packages/components/src}/components/GitHubRepo.astro +0 -0
- /package/{src → packages/components/src}/components/Hint.astro +0 -0
- /package/{src → packages/components/src}/components/Icon.astro +0 -0
- /package/{src → packages/components/src}/components/Info.astro +0 -0
- /package/{src → packages/components/src}/components/Note.astro +0 -0
- /package/{src → packages/components/src}/components/Panel.astro +0 -0
- /package/{src → packages/components/src}/components/ParamField.astro +0 -0
- /package/{src → packages/components/src}/components/Parameter.astro +0 -0
- /package/{src → packages/components/src}/components/Prompt.astro +0 -0
- /package/{src → packages/components/src}/components/RequestExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseExample.astro +0 -0
- /package/{src → packages/components/src}/components/ResponseField.astro +0 -0
- /package/{src → packages/components/src}/components/Searchbar.astro +0 -0
- /package/{src → packages/components/src}/components/Step.astro +0 -0
- /package/{src → packages/components/src}/components/Steps.astro +0 -0
- /package/{src → packages/components/src}/components/Tab.astro +0 -0
- /package/{src → packages/components/src}/components/Tabs.astro +0 -0
- /package/{src → packages/components/src}/components/Tile.astro +0 -0
- /package/{src → packages/components/src}/components/Tip.astro +0 -0
- /package/{src → packages/components/src}/components/Tooltip.astro +0 -0
- /package/{src → packages/components/src}/components/Tree.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFile.astro +0 -0
- /package/{src → packages/components/src}/components/TreeFolder.astro +0 -0
- /package/{src → packages/components/src}/components/Update.astro +0 -0
- /package/{src → packages/components/src}/components/Video.astro +0 -0
- /package/{src → packages/components/src}/components/View.astro +0 -0
- /package/{src → packages/components/src}/components/Visibility.astro +0 -0
- /package/{src → packages/components/src}/components/Warning.astro +0 -0
- /package/{src → packages/components/src}/components/class-names.ts +0 -0
- /package/{src → packages/components/src}/lib/cli-report.js +0 -0
- /package/{src → packages/components/src}/lib/inline-markdown.js +0 -0
- /package/{src → packages/components/src}/lib/plain-text.js +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The base a site is served under ("" or "/docs" - writedocs.json's
|
|
2
|
+
// `basePath` in the generator) and the addresses that take it. Addresses come
|
|
3
|
+
// in two kinds, and only one of them takes the base:
|
|
4
|
+
// - site addresses: "/guides/a/", "/images/x.png" - a path in the site.
|
|
5
|
+
// withBase() prefixes them, once, where the final address is written -
|
|
6
|
+
// never twice: a page can live at "/docs/..." inside a site whose base is
|
|
7
|
+
// "/docs", so "already starts with the base" can't tell whether an address
|
|
8
|
+
// has been prefixed.
|
|
9
|
+
// - everything else - "https://...", "#a", "mailto:", "//cdn...", a relative
|
|
10
|
+
// "../a" - is left as it is.
|
|
11
|
+
//
|
|
12
|
+
// The generator's src/lib/base-path.js re-exports these, next to the parts
|
|
13
|
+
// only the generator needs (the field's pattern, withoutBase(), site URLs).
|
|
14
|
+
|
|
15
|
+
/** Whether `url` is a site address: a path from the site's root ("/a/b"),
|
|
16
|
+
* not a protocol-relative "//host/a". */
|
|
17
|
+
export function isSiteAddress(url) {
|
|
18
|
+
return typeof url === 'string' && url.startsWith('/') && !url.startsWith('//');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `url` with the base in front, if it's a site address - "/a/" -> "/docs/a/",
|
|
22
|
+
* "/" -> "/docs/". Anything else, and everything when there's no base,
|
|
23
|
+
* comes back as it is. */
|
|
24
|
+
export function withBase(base, url) {
|
|
25
|
+
if (!base || !isSiteAddress(url)) return url;
|
|
26
|
+
return base + url;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A `srcset` with the base in front of each site address in it. */
|
|
30
|
+
export function srcsetWithBase(base, srcset) {
|
|
31
|
+
if (!base || typeof srcset !== 'string') return srcset;
|
|
32
|
+
return srcset
|
|
33
|
+
.split(',')
|
|
34
|
+
.map((candidate) => {
|
|
35
|
+
const [url, ...descriptor] = candidate.trim().split(/\s+/);
|
|
36
|
+
return [withBase(base, url), ...descriptor].join(' ');
|
|
37
|
+
})
|
|
38
|
+
.join(', ');
|
|
39
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The width of a ```js lines block's number column, in digits: as many as
|
|
2
2
|
// its last line number has. The column is that many `ch` wide (see
|
|
3
|
-
// .wd-code-lines in
|
|
3
|
+
// .wd-code-lines in styles/components.css), so a block of under ten lines starts
|
|
4
4
|
// its numbers at the panel's padding, like Mintlify's, instead of inside a
|
|
5
5
|
// fixed-width box sized for two or three digits.
|
|
6
6
|
//
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The Shiki transformers every code block goes through - a ``` fence in the
|
|
2
|
+
// generator's Markdown (its astro.config.mjs passes this to
|
|
3
|
+
// markdown.shikiConfig) and a <CodeBlock> - so both look and behave the same.
|
|
4
|
+
// The official @shikijs/transformers annotation transformers, enabled for
|
|
5
|
+
// every block without per-page opt-in:
|
|
6
|
+
// ```js {1,3-5} -> transformerMetaHighlight
|
|
7
|
+
// ```js /someWord/ -> transformerMetaWordHighlight
|
|
8
|
+
// // [!code highlight] -> transformerNotationHighlight
|
|
9
|
+
// // [!code word:someWord] -> transformerNotationWordHighlight
|
|
10
|
+
// // [!code focus] -> transformerNotationFocus
|
|
11
|
+
// // [!code ++] / // [!code --] -> transformerNotationDiff
|
|
12
|
+
// // [!code error] / [!code warning] -> transformerNotationErrorLevel
|
|
13
|
+
// (comment syntax adapts to the language - # for Python/bash, // for JS/etc -
|
|
14
|
+
// see each transformer's own docs at shiki.style). Plus codeBlockTransformer,
|
|
15
|
+
// writedocs' own, for the copy button, an optional title bar, and the
|
|
16
|
+
// wrap/lines/expandable meta flags - see shiki-code-block.js. It runs last so
|
|
17
|
+
// its `root` hook wraps the <pre> only after every class the transformers
|
|
18
|
+
// above added to it is already in place - though in practice this doesn't
|
|
19
|
+
// matter, since all `pre`/`line` hooks across every transformer run to
|
|
20
|
+
// completion before any `root` hook runs at all (two separate passes, not
|
|
21
|
+
// interleaved).
|
|
22
|
+
import {
|
|
23
|
+
transformerMetaHighlight,
|
|
24
|
+
transformerMetaWordHighlight,
|
|
25
|
+
transformerNotationHighlight,
|
|
26
|
+
transformerNotationWordHighlight,
|
|
27
|
+
transformerNotationFocus,
|
|
28
|
+
transformerNotationDiff,
|
|
29
|
+
transformerNotationErrorLevel,
|
|
30
|
+
} from '@shikijs/transformers';
|
|
31
|
+
import { codeBlockTransformer } from './shiki-code-block.js';
|
|
32
|
+
|
|
33
|
+
/** A new list of the transformers, in the order they run. */
|
|
34
|
+
export function codeTransformers() {
|
|
35
|
+
return [
|
|
36
|
+
transformerMetaHighlight(),
|
|
37
|
+
transformerMetaWordHighlight(),
|
|
38
|
+
transformerNotationHighlight(),
|
|
39
|
+
transformerNotationWordHighlight(),
|
|
40
|
+
transformerNotationFocus(),
|
|
41
|
+
transformerNotationDiff(),
|
|
42
|
+
transformerNotationErrorLevel(),
|
|
43
|
+
codeBlockTransformer(),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// Plain JavaScript, not TypeScript, on purpose: `writedocs validate` loads
|
|
10
10
|
// this with plain Node to check icon names, and Node refuses to strip types
|
|
11
11
|
// from any file under node_modules - so a .ts version would work from the
|
|
12
|
-
// checkout and fail for everyone who installs the package.
|
|
13
|
-
//
|
|
12
|
+
// checkout and fail for everyone who installs the package. The generator's
|
|
13
|
+
// plain-Node checks import this file directly, and its lib/config.ts
|
|
14
|
+
// re-exports these for everything that runs inside its Astro.
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
import { createRequire } from 'node:module';
|
|
16
17
|
|
|
@@ -24,12 +25,17 @@ const DEFAULT_ICON_COLLECTION = 'lucide';
|
|
|
24
25
|
const BARE_ICON_COLLECTIONS = [DEFAULT_ICON_COLLECTION, 'fa6-solid', 'fa6-brands'];
|
|
25
26
|
|
|
26
27
|
// Loaded lazily, once per collection, from the installed @iconify-json/*
|
|
27
|
-
// packages (the same data astro-icon itself renders from).
|
|
28
|
-
// against
|
|
29
|
-
// is set by run-astro.js
|
|
30
|
-
//
|
|
28
|
+
// packages (the same data astro-icon itself renders from). Under the
|
|
29
|
+
// writedocs generator they're resolved against the generator, not the site
|
|
30
|
+
// being built - WRITEDOCS_PACKAGE_ROOT is set by its run-astro.js. Anywhere
|
|
31
|
+
// else (a project that installs @writedocs/components) from this file's own
|
|
32
|
+
// URL, which is inside that project's node_modules, where the collections
|
|
33
|
+
// this package depends on are installed. Exported for the integration, which
|
|
34
|
+
// hands the same sets to astro-icon.
|
|
31
35
|
const iconCollections = new Map();
|
|
32
|
-
|
|
36
|
+
/** An installed @iconify-json collection's data ("lucide" -> its
|
|
37
|
+
* icons.json), or null when it isn't installed. */
|
|
38
|
+
export function loadIconCollection(collection) {
|
|
33
39
|
if (!iconCollections.has(collection)) {
|
|
34
40
|
const packageRoot = process.env.WRITEDOCS_PACKAGE_ROOT;
|
|
35
41
|
const require = createRequire(packageRoot ? path.join(packageRoot, 'package.json') : import.meta.url);
|
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
// handful of writedocs-specific meta flags off the fence's info string
|
|
6
6
|
// (the part after the language, e.g. ```js title="foo.js" wrap lines
|
|
7
7
|
// expandable) to add a title bar and toggle wrap/line-numbers/
|
|
8
|
-
// expandable behavior.
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
8
|
+
// expandable behavior. Last in codeTransformers() (code-transformers.js),
|
|
9
|
+
// after the official @shikijs/transformers notation/meta-highlight
|
|
10
|
+
// transformers that handle the actual line/word annotation classes -
|
|
11
|
+
// the list the generator's markdown.shikiConfig and CodeBlock.astro share.
|
|
12
12
|
//
|
|
13
13
|
// Everything here only produces static HAST/HTML at build time - the
|
|
14
14
|
// click behavior for the copy and expand/collapse buttons lives in
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
15
|
+
// ../scripts/code-block.ts, and the CSS for all of this (including the
|
|
16
|
+
// classes the @shikijs/transformers transformers add) in
|
|
17
|
+
// ../styles/components.css.
|
|
18
18
|
//
|
|
19
19
|
// Deliberately NOT used by ApiPlayground/ApiReferencePanel's <Code/>
|
|
20
20
|
// usages - per Astro's docs, <Code/> doesn't inherit markdown.shikiConfig
|
|
21
21
|
// at all, so this only ever touches genuine ```-fenced MDX content and
|
|
22
22
|
// never collides with the API playground's own bespoke copy buttons.
|
|
23
23
|
|
|
24
|
-
import { iconSvg } from './
|
|
24
|
+
import { iconSvg } from './icons.js';
|
|
25
25
|
import { lineNumberDigits } from './code-line-numbers.js';
|
|
26
26
|
|
|
27
27
|
// The fence's info string after the language, split into tokens: a
|
|
@@ -131,7 +131,7 @@ export function codeBlockTransformer() {
|
|
|
131
131
|
return node;
|
|
132
132
|
},
|
|
133
133
|
// Same classes transformerNotationFocus (`// [!code focus]`) adds, so
|
|
134
|
-
// `focus={...}` reuses
|
|
134
|
+
// `focus={...}` reuses the existing dimming CSS (styles/components.css).
|
|
135
135
|
pre(node) {
|
|
136
136
|
if (this.options.meta?.__wdMeta?.focus.length) this.addClassToHast(node, 'has-focused');
|
|
137
137
|
return node;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// The site's base (writedocs.json `basePath`) for components and page
|
|
2
|
-
// scripts -
|
|
3
|
-
// __WD_BASE__ is "" or "/docs", set
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// scripts - base-path.js explains the base and which addresses take it.
|
|
3
|
+
// __WD_BASE__ is "" or "/docs", set with vite.define - by the generator's
|
|
4
|
+
// astro.config.mjs, or by this package's integration when it's given a
|
|
5
|
+
// `base` - so the same import works in a component's frontmatter and in a
|
|
6
|
+
// <script>; with no base, siteHref() returns its argument and the built
|
|
7
|
+
// pages don't change. A project that defines neither gets "": `typeof`
|
|
8
|
+
// doesn't throw on a name that was never declared.
|
|
6
9
|
//
|
|
7
10
|
// The rule: logic keeps site addresses as they are ("/guides/a/"); the base
|
|
8
11
|
// goes in where the address is written - an href, a src, a url() - with
|
|
@@ -10,10 +13,10 @@
|
|
|
10
13
|
// twice.
|
|
11
14
|
import { withBase, srcsetWithBase } from './base-path.js';
|
|
12
15
|
|
|
13
|
-
declare const __WD_BASE__: string;
|
|
16
|
+
declare const __WD_BASE__: string | undefined;
|
|
14
17
|
|
|
15
18
|
/** "" or "/docs". */
|
|
16
|
-
export const BASE: string = __WD_BASE__;
|
|
19
|
+
export const BASE: string = typeof __WD_BASE__ === 'string' ? __WD_BASE__ : '';
|
|
17
20
|
|
|
18
21
|
/** A site address with the base in front ("/a/" -> "/docs/a/"); anything
|
|
19
22
|
* else - a full URL, "#x", a relative path - as it is. */
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// What a code block's buttons do in the browser. The buttons themselves are
|
|
2
|
+
// emitted at build time by codeBlockTransformer (lib/shiki-code-block.js),
|
|
3
|
+
// which wraps each <pre> in a .wd-code-block container; this wires up their
|
|
4
|
+
// clicks. Each function marks what it has set up (data-wd-init), so calling
|
|
5
|
+
// it again - on every `astro:page-load`, or from two scripts on one page -
|
|
6
|
+
// sets up only what's new. The generator calls these from [...slug].astro's
|
|
7
|
+
// page script; the integration calls them on every page of any other project.
|
|
8
|
+
|
|
9
|
+
/** The copy-to-clipboard button on every code block under `root`. */
|
|
10
|
+
export function initCodeCopyButtons(root: ParentNode) {
|
|
11
|
+
root.querySelectorAll<HTMLButtonElement>(".wd-code-copy-btn").forEach((btn) => {
|
|
12
|
+
if (btn.dataset.wdInit) return;
|
|
13
|
+
btn.dataset.wdInit = "true";
|
|
14
|
+
btn.addEventListener("click", async () => {
|
|
15
|
+
const pre = btn.closest(".wd-code-block")?.querySelector("pre");
|
|
16
|
+
if (!pre) return;
|
|
17
|
+
try {
|
|
18
|
+
await navigator.clipboard.writeText(pre.textContent ?? "");
|
|
19
|
+
} catch {
|
|
20
|
+
return; // clipboard unavailable (e.g. insecure context) - fail silently
|
|
21
|
+
}
|
|
22
|
+
btn.textContent = "✓";
|
|
23
|
+
btn.classList.add("wd-code-copied");
|
|
24
|
+
window.setTimeout(() => {
|
|
25
|
+
btn.textContent = "⧉";
|
|
26
|
+
btn.classList.remove("wd-code-copied");
|
|
27
|
+
}, 1500);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The Show more/less toggle of every ```js expandable code block under
|
|
33
|
+
* `root` - codeBlockTransformer only adds this button when the fence's meta
|
|
34
|
+
* string contains the `expandable` keyword. */
|
|
35
|
+
export function initCodeExpandButtons(root: ParentNode) {
|
|
36
|
+
root.querySelectorAll<HTMLButtonElement>(".wd-code-expand-btn").forEach((btn) => {
|
|
37
|
+
if (btn.dataset.wdInit) return;
|
|
38
|
+
btn.dataset.wdInit = "true";
|
|
39
|
+
const block = btn.closest<HTMLElement>(".wd-code-expandable");
|
|
40
|
+
if (!block) return;
|
|
41
|
+
// A block no taller than the collapsed height has nothing to show
|
|
42
|
+
// more of: .wd-code-fits drops the fade and the button. Only when
|
|
43
|
+
// it can be measured - a block in a hidden CodeGroup tab or a
|
|
44
|
+
// closed accordion has no height yet, and keeps its button.
|
|
45
|
+
const pre = block.querySelector("pre");
|
|
46
|
+
// The collapsed height shows 12 lines and hides only the bottom
|
|
47
|
+
// padding, so that padding doesn't count against fitting.
|
|
48
|
+
const padBottom = pre ? parseFloat(getComputedStyle(pre).paddingBottom) || 0 : 0;
|
|
49
|
+
if (pre && pre.clientHeight > 0 && pre.scrollHeight - padBottom <= pre.clientHeight + 1) {
|
|
50
|
+
block.classList.add("wd-code-fits");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
btn.addEventListener("click", () => {
|
|
54
|
+
const expanded = block.classList.toggle("wd-code-expanded");
|
|
55
|
+
btn.textContent = expanded ? "Show less" : "Show more";
|
|
56
|
+
btn.setAttribute("aria-expanded", String(expanded));
|
|
57
|
+
// Collapsing a long block can leave the reader below it: bring
|
|
58
|
+
// it back into view.
|
|
59
|
+
if (!expanded) block.scrollIntoView({ block: "nearest" });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/* The stylesheet the components share, beside each one's own scoped
|
|
2
|
+
<style>: code blocks (a <CodeBlock>, the blocks in a <CodeGroup>, and in
|
|
3
|
+
the generator every ``` fence too), Shiki's dark theme, and icons given as
|
|
4
|
+
an image. Global - the markup it styles is built by Shiki transformers
|
|
5
|
+
(lib/shiki-code-block.js), not by one component's template, so a scoped
|
|
6
|
+
style couldn't reach it. Everything uses the --wd-* variables: the
|
|
7
|
+
generator sets them from writedocs.json (BaseLayout.astro), anywhere else
|
|
8
|
+
theme.css gives them defaults. The generator imports this file in
|
|
9
|
+
BaseLayout.astro; the integration adds it to every page of any other
|
|
10
|
+
project. */
|
|
11
|
+
|
|
12
|
+
/* Astro's Shiki output (both the built-in MDX code-fence pipeline,
|
|
13
|
+
configured with dual themes in the generator's astro.config.mjs, and the
|
|
14
|
+
<Code /> component - <CodeBlock>, and the generator's API playground)
|
|
15
|
+
bakes the "light" theme as each element's base color/background and
|
|
16
|
+
stashes the dark equivalents in --shiki-dark/--shiki-dark-bg custom
|
|
17
|
+
properties. Swapping to those on [data-theme='dark'] is the officially
|
|
18
|
+
documented way to make Shiki-highlighted code follow a manual
|
|
19
|
+
(non-media-query) theme toggle - see
|
|
20
|
+
https://docs.astro.build/en/guides/syntax-highlighting/#setting-light-and-dark-mode-themes.
|
|
21
|
+
The background goes on the <pre> only: Shiki gives the spans inside no
|
|
22
|
+
background of their own, and painting the theme's background on every
|
|
23
|
+
span (.line included) covered the highlighted, diff, error and focus
|
|
24
|
+
line colors and the highlighted words in dark mode. */
|
|
25
|
+
[data-theme="dark"] .astro-code {
|
|
26
|
+
background-color: var(--shiki-dark-bg) !important;
|
|
27
|
+
}
|
|
28
|
+
[data-theme="dark"] .astro-code,
|
|
29
|
+
[data-theme="dark"] .astro-code span {
|
|
30
|
+
color: var(--shiki-dark) !important;
|
|
31
|
+
font-style: var(--shiki-dark-font-style) !important;
|
|
32
|
+
font-weight: var(--shiki-dark-font-weight) !important;
|
|
33
|
+
text-decoration: var(--shiki-dark-text-decoration) !important;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* An icon given as an image URL or path (resolveIcon()'s 'image' kind,
|
|
37
|
+
rendered by AppIcon.astro) - 1em square inside its caller's own icon
|
|
38
|
+
span, so it sizes like a glyph icon would. Lives here rather than in
|
|
39
|
+
AppIcon.astro so it's part of the shared stylesheet, not an inline
|
|
40
|
+
<style> added to every page. */
|
|
41
|
+
img.wd-icon-img {
|
|
42
|
+
display: block;
|
|
43
|
+
width: 1em;
|
|
44
|
+
height: 1em;
|
|
45
|
+
object-fit: contain;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* The "#" link beside a title - a Callout's or an Accordion's (each shows
|
|
49
|
+
it on hover of its own title, in its scoped <style>), and in the
|
|
50
|
+
generator a page heading's ([...slug].astro adds those and shows them on
|
|
51
|
+
hover of the heading). Hidden until then, and when it has focus. */
|
|
52
|
+
.wd-heading-anchor {
|
|
53
|
+
display: inline-block;
|
|
54
|
+
margin-left: 0.5rem;
|
|
55
|
+
color: var(--wd-text-muted);
|
|
56
|
+
opacity: 0;
|
|
57
|
+
text-decoration: none;
|
|
58
|
+
font-weight: 400;
|
|
59
|
+
transition: opacity 0.1s ease;
|
|
60
|
+
}
|
|
61
|
+
.wd-heading-anchor:focus {
|
|
62
|
+
opacity: 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Fenced (```) code blocks - codeBlockTransformer
|
|
66
|
+
(lib/shiki-code-block.js) wraps every one's <pre> in this
|
|
67
|
+
.wd-code-block div at build time (plus an optional .wd-code-title
|
|
68
|
+
bar, and the copy/expand buttons - see below). The card-like chrome
|
|
69
|
+
(border/radius/background) lives on the wrapper rather than the
|
|
70
|
+
<pre> itself so a title bar, when present, can sit flush above it
|
|
71
|
+
inside the same box; Astro's Shiki pipeline (dual light/dark themes)
|
|
72
|
+
already supplies the <pre>'s own background/text colors via inline
|
|
73
|
+
styles. Matches both a standalone block (direct child of .wd-article)
|
|
74
|
+
and one nested inside <CodeGroup> (which re-targets the margin/radius
|
|
75
|
+
itself via its own more specific `.wd-codegroup > .wd-code-block` rule
|
|
76
|
+
in CodeGroup.astro).
|
|
77
|
+
The panel rule below is scoped to the generator's .wd-article, as it
|
|
78
|
+
always was - a request/response example docked beside the article
|
|
79
|
+
isn't in it. theme.css gives a project's own pages the same panel.
|
|
80
|
+
The layout follows Mintlify's: a frame (the wrapper - border, surface
|
|
81
|
+
background, a 0.125rem inset) holding the title bar, and the code in
|
|
82
|
+
its own rounded panel inside it (the <pre>, in the code theme's
|
|
83
|
+
background). --wd-code-pad-x is the panel's side padding: the
|
|
84
|
+
highlighted and diff lines below stretch past it by the same amount
|
|
85
|
+
to reach the panel's edges. */
|
|
86
|
+
.wd-code-block {
|
|
87
|
+
--wd-code-pad-x: 1rem;
|
|
88
|
+
position: relative;
|
|
89
|
+
margin: 1.25rem 0 2rem;
|
|
90
|
+
padding: 0.125rem;
|
|
91
|
+
border: 1px solid var(--wd-border);
|
|
92
|
+
border-radius: 1rem;
|
|
93
|
+
background: var(--wd-surface);
|
|
94
|
+
}
|
|
95
|
+
.wd-article pre.astro-code {
|
|
96
|
+
margin: 0;
|
|
97
|
+
padding: 0.75rem var(--wd-code-pad-x);
|
|
98
|
+
border: none;
|
|
99
|
+
border-radius: 0.875rem;
|
|
100
|
+
font-size: 0.875rem;
|
|
101
|
+
line-height: 1.5rem;
|
|
102
|
+
}
|
|
103
|
+
/* On the frame, above the panel - room on the right for the copy
|
|
104
|
+
button, which moves into this bar when there is one (below). */
|
|
105
|
+
.wd-code-title {
|
|
106
|
+
padding: 0.25rem 2.75rem 0.25rem var(--wd-code-pad-x);
|
|
107
|
+
font-size: 0.75rem;
|
|
108
|
+
font-weight: 500;
|
|
109
|
+
line-height: 1.5rem;
|
|
110
|
+
color: var(--wd-text);
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
overflow: hidden;
|
|
113
|
+
text-overflow: ellipsis;
|
|
114
|
+
}
|
|
115
|
+
/* A fence's `icon="..."` (shiki-code-block.js) - the icon's own SVG
|
|
116
|
+
arrives as a data URL in --wd-code-icon and is used as a mask, so it
|
|
117
|
+
paints in the title's text color instead of the SVG's own fill. */
|
|
118
|
+
.wd-code-title-icon {
|
|
119
|
+
display: inline-block;
|
|
120
|
+
width: 1em;
|
|
121
|
+
height: 1em;
|
|
122
|
+
margin-right: 0.45rem;
|
|
123
|
+
vertical-align: -0.125em;
|
|
124
|
+
background: currentColor;
|
|
125
|
+
-webkit-mask: var(--wd-code-icon) center / contain no-repeat;
|
|
126
|
+
mask: var(--wd-code-icon) center / contain no-repeat;
|
|
127
|
+
}
|
|
128
|
+
/* Without a title bar, the copy button sits in the panel's top-right
|
|
129
|
+
corner and shows on hover or keyboard focus. */
|
|
130
|
+
.wd-code-copy-btn {
|
|
131
|
+
position: absolute;
|
|
132
|
+
top: 0.625rem;
|
|
133
|
+
right: 0.625rem;
|
|
134
|
+
z-index: 1;
|
|
135
|
+
display: inline-flex;
|
|
136
|
+
align-items: center;
|
|
137
|
+
justify-content: center;
|
|
138
|
+
width: 1.75rem;
|
|
139
|
+
height: 1.75rem;
|
|
140
|
+
padding: 0;
|
|
141
|
+
border-radius: 0.5rem;
|
|
142
|
+
border: 1px solid var(--wd-border);
|
|
143
|
+
background: var(--wd-surface);
|
|
144
|
+
color: var(--wd-text-muted);
|
|
145
|
+
font-size: 0.9rem;
|
|
146
|
+
line-height: 1;
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
opacity: 0;
|
|
149
|
+
transition:
|
|
150
|
+
opacity 0.15s ease,
|
|
151
|
+
color 0.15s ease,
|
|
152
|
+
background 0.15s ease,
|
|
153
|
+
border-color 0.15s ease;
|
|
154
|
+
}
|
|
155
|
+
.wd-code-block:hover .wd-code-copy-btn,
|
|
156
|
+
.wd-code-copy-btn:focus-visible {
|
|
157
|
+
opacity: 1;
|
|
158
|
+
}
|
|
159
|
+
.wd-code-copy-btn:hover {
|
|
160
|
+
color: var(--wd-text);
|
|
161
|
+
background: var(--wd-background);
|
|
162
|
+
}
|
|
163
|
+
/* With a title bar, it's an always-visible icon at the bar's right end,
|
|
164
|
+
like Mintlify's: centered in the 2rem bar, inside the frame's inset. */
|
|
165
|
+
.wd-code-title ~ .wd-code-copy-btn {
|
|
166
|
+
top: 0.375rem;
|
|
167
|
+
right: 0.5rem;
|
|
168
|
+
width: 1.5rem;
|
|
169
|
+
height: 1.5rem;
|
|
170
|
+
border-color: transparent;
|
|
171
|
+
background: transparent;
|
|
172
|
+
opacity: 1;
|
|
173
|
+
}
|
|
174
|
+
.wd-code-title ~ .wd-code-copy-btn:hover {
|
|
175
|
+
background: color-mix(in srgb, var(--wd-text) 8%, transparent);
|
|
176
|
+
}
|
|
177
|
+
.wd-code-copy-btn.wd-code-copied {
|
|
178
|
+
opacity: 1;
|
|
179
|
+
color: #16a34a;
|
|
180
|
+
border-color: #16a34a;
|
|
181
|
+
}
|
|
182
|
+
/* ```js wrap - opts a single block into wrapping long lines instead
|
|
183
|
+
of horizontal-scrolling (the default). */
|
|
184
|
+
.wd-code-wrap pre.astro-code,
|
|
185
|
+
.wd-code-wrap pre.astro-code code {
|
|
186
|
+
white-space: pre-wrap;
|
|
187
|
+
word-break: break-word;
|
|
188
|
+
overflow-x: hidden;
|
|
189
|
+
}
|
|
190
|
+
/* ```js lines (or showLineNumbers) - a CSS-counter gutter, no markup
|
|
191
|
+
needed beyond a class since every line is already its own .line
|
|
192
|
+
span. The column is --wd-code-digits characters wide (set on the
|
|
193
|
+
wrapper by shiki-code-block.js from the line count), so the numbers
|
|
194
|
+
start at the panel's padding and stay right-aligned past nine lines. */
|
|
195
|
+
.wd-code-lines pre.astro-code code {
|
|
196
|
+
counter-reset: wd-code-line;
|
|
197
|
+
}
|
|
198
|
+
.wd-code-lines pre.astro-code .line {
|
|
199
|
+
counter-increment: wd-code-line;
|
|
200
|
+
}
|
|
201
|
+
.wd-code-lines pre.astro-code .line::before {
|
|
202
|
+
content: counter(wd-code-line);
|
|
203
|
+
display: inline-block;
|
|
204
|
+
width: calc(var(--wd-code-digits, 2) * 1ch);
|
|
205
|
+
margin-right: 1.25rem;
|
|
206
|
+
text-align: right;
|
|
207
|
+
color: var(--wd-text-muted);
|
|
208
|
+
user-select: none;
|
|
209
|
+
}
|
|
210
|
+
/* ```js expandable - collapses to its first 12 lines (plus the panel's
|
|
211
|
+
top padding) with a "Show more" button below; toggled via
|
|
212
|
+
.wd-code-expanded, added by the click handler in
|
|
213
|
+
scripts/code-block.ts. A block that already fits gets .wd-code-fits
|
|
214
|
+
from the same script instead, and is never collapsed: no fade, no
|
|
215
|
+
button. */
|
|
216
|
+
.wd-code-expandable:not(.wd-code-expanded, .wd-code-fits) pre.astro-code {
|
|
217
|
+
max-height: calc(12 * 1.5rem + 0.75rem);
|
|
218
|
+
overflow-y: hidden;
|
|
219
|
+
}
|
|
220
|
+
/* The fade over the last visible lines: a strip at the end of the code,
|
|
221
|
+
stuck to the bottom of the clipped panel (and to its left edge, if
|
|
222
|
+
the block is scrolled sideways), three lines tall and solid over the
|
|
223
|
+
last one, so no line shows cut in half. It's the panel's own background -
|
|
224
|
+
`inherit` takes the <pre>'s computed color, the dark theme's in dark
|
|
225
|
+
mode - masked from transparent to solid, so it fades into whatever
|
|
226
|
+
code theme the site uses. */
|
|
227
|
+
.wd-code-expandable:not(.wd-code-expanded, .wd-code-fits) pre.astro-code::after {
|
|
228
|
+
content: "";
|
|
229
|
+
position: sticky;
|
|
230
|
+
/* Sticky offsets count from inside the <pre>'s padding: minus the
|
|
231
|
+
padding puts the strip on the panel's edges, over the padding too. */
|
|
232
|
+
bottom: -0.75rem;
|
|
233
|
+
left: calc(-1 * var(--wd-code-pad-x));
|
|
234
|
+
display: block;
|
|
235
|
+
width: calc(100% + 2 * var(--wd-code-pad-x));
|
|
236
|
+
height: 4.5rem;
|
|
237
|
+
margin: -4.5rem calc(-1 * var(--wd-code-pad-x)) 0;
|
|
238
|
+
background-color: inherit;
|
|
239
|
+
-webkit-mask-image: linear-gradient(to bottom, transparent, #000 70%);
|
|
240
|
+
mask-image: linear-gradient(to bottom, transparent, #000 70%);
|
|
241
|
+
pointer-events: none;
|
|
242
|
+
}
|
|
243
|
+
.wd-code-fits .wd-code-expand-btn {
|
|
244
|
+
display: none;
|
|
245
|
+
}
|
|
246
|
+
/* Below the panel, on the frame, with a chevron that turns up once
|
|
247
|
+
the block is open. */
|
|
248
|
+
.wd-code-expand-btn {
|
|
249
|
+
display: flex;
|
|
250
|
+
align-items: center;
|
|
251
|
+
justify-content: center;
|
|
252
|
+
gap: 0.5rem;
|
|
253
|
+
width: 100%;
|
|
254
|
+
padding: 0.25rem;
|
|
255
|
+
border: none;
|
|
256
|
+
border-radius: 0 0 0.875rem 0.875rem;
|
|
257
|
+
background: transparent;
|
|
258
|
+
color: var(--wd-text-muted);
|
|
259
|
+
font-family: inherit;
|
|
260
|
+
font-size: 0.75rem;
|
|
261
|
+
font-weight: 500;
|
|
262
|
+
line-height: 1.5rem;
|
|
263
|
+
cursor: pointer;
|
|
264
|
+
transition:
|
|
265
|
+
color 0.15s ease,
|
|
266
|
+
background 0.15s ease;
|
|
267
|
+
}
|
|
268
|
+
.wd-code-expand-btn::after {
|
|
269
|
+
content: "";
|
|
270
|
+
width: 0.375rem;
|
|
271
|
+
height: 0.375rem;
|
|
272
|
+
border-right: 1.5px solid currentColor;
|
|
273
|
+
border-bottom: 1.5px solid currentColor;
|
|
274
|
+
transform: translateY(-0.1rem) rotate(45deg);
|
|
275
|
+
transition: transform 0.15s ease;
|
|
276
|
+
}
|
|
277
|
+
.wd-code-expanded .wd-code-expand-btn::after {
|
|
278
|
+
transform: translateY(0.1rem) rotate(-135deg);
|
|
279
|
+
}
|
|
280
|
+
.wd-code-expand-btn:hover {
|
|
281
|
+
color: var(--wd-text);
|
|
282
|
+
background: color-mix(in srgb, var(--wd-text) 6%, transparent);
|
|
283
|
+
}
|
|
284
|
+
/* Line/word annotation classes added by the official
|
|
285
|
+
@shikijs/transformers transformers configured alongside
|
|
286
|
+
codeBlockTransformer (lib/code-transformers.js):
|
|
287
|
+
.line.highlighted - transformerMetaHighlight
|
|
288
|
+
(```js {1,3-5}) and
|
|
289
|
+
transformerNotationHighlight
|
|
290
|
+
(// [!code highlight]/[!code hl])
|
|
291
|
+
.line.diff.add / .diff.remove - transformerNotationDiff
|
|
292
|
+
(// [!code ++] / // [!code --])
|
|
293
|
+
.line.error / .warning / .info - transformerNotationErrorLevel
|
|
294
|
+
(// [!code error]/[!code warning])
|
|
295
|
+
(also carries .highlighted)
|
|
296
|
+
pre.has-focused, .line.focused - transformerNotationFocus
|
|
297
|
+
(// [!code focus])
|
|
298
|
+
.highlighted-word - transformerMetaWordHighlight
|
|
299
|
+
(```js /someWord/) and
|
|
300
|
+
transformerNotationWordHighlight
|
|
301
|
+
(// [!code word:someWord])
|
|
302
|
+
Every .line needs display:inline-block + full width for its
|
|
303
|
+
highlight background to stretch edge-to-edge (by default a <span>
|
|
304
|
+
only extends as wide as its own text) - harmless for plain lines,
|
|
305
|
+
since inline-block with no other styling renders identically to
|
|
306
|
+
the browser's normal inline flow here. */
|
|
307
|
+
.astro-code .line {
|
|
308
|
+
display: inline-block;
|
|
309
|
+
width: 100%;
|
|
310
|
+
}
|
|
311
|
+
.astro-code .line.highlighted {
|
|
312
|
+
background: color-mix(in srgb, var(--wd-primary) 12%, transparent);
|
|
313
|
+
margin: 0 calc(-1 * var(--wd-code-pad-x, 1rem));
|
|
314
|
+
padding: 0 var(--wd-code-pad-x, 1rem);
|
|
315
|
+
width: calc(100% + 2 * var(--wd-code-pad-x, 1rem));
|
|
316
|
+
}
|
|
317
|
+
.astro-code .line.diff {
|
|
318
|
+
margin: 0 calc(-1 * var(--wd-code-pad-x, 1rem));
|
|
319
|
+
padding: 0 var(--wd-code-pad-x, 1rem);
|
|
320
|
+
width: calc(100% + 2 * var(--wd-code-pad-x, 1rem));
|
|
321
|
+
position: relative;
|
|
322
|
+
}
|
|
323
|
+
.astro-code .line.diff.add {
|
|
324
|
+
background: color-mix(in srgb, #16a34a 15%, transparent);
|
|
325
|
+
}
|
|
326
|
+
.astro-code .line.diff.remove {
|
|
327
|
+
background: color-mix(in srgb, #dc2626 15%, transparent);
|
|
328
|
+
opacity: 0.85;
|
|
329
|
+
}
|
|
330
|
+
.astro-code .line.diff.add::before,
|
|
331
|
+
.astro-code .line.diff.remove::before {
|
|
332
|
+
position: absolute;
|
|
333
|
+
left: 0.3rem;
|
|
334
|
+
font-weight: 700;
|
|
335
|
+
}
|
|
336
|
+
.astro-code .line.diff.add::before {
|
|
337
|
+
content: "+";
|
|
338
|
+
color: #16a34a;
|
|
339
|
+
}
|
|
340
|
+
.astro-code .line.diff.remove::before {
|
|
341
|
+
content: "-";
|
|
342
|
+
color: #dc2626;
|
|
343
|
+
}
|
|
344
|
+
.astro-code .line.error {
|
|
345
|
+
background: color-mix(in srgb, #dc2626 15%, transparent);
|
|
346
|
+
}
|
|
347
|
+
.astro-code .line.warning {
|
|
348
|
+
background: color-mix(in srgb, #d97706 15%, transparent);
|
|
349
|
+
}
|
|
350
|
+
.astro-code .line.info {
|
|
351
|
+
background: color-mix(in srgb, #2563eb 12%, transparent);
|
|
352
|
+
}
|
|
353
|
+
pre.astro-code.has-focused .line {
|
|
354
|
+
opacity: 0.45;
|
|
355
|
+
filter: blur(0.3px);
|
|
356
|
+
transition:
|
|
357
|
+
opacity 0.2s ease,
|
|
358
|
+
filter 0.2s ease;
|
|
359
|
+
}
|
|
360
|
+
pre.astro-code.has-focused .line.focused {
|
|
361
|
+
opacity: 1;
|
|
362
|
+
filter: none;
|
|
363
|
+
}
|
|
364
|
+
pre.astro-code.has-focused:hover .line {
|
|
365
|
+
opacity: 1;
|
|
366
|
+
filter: none;
|
|
367
|
+
}
|
|
368
|
+
.astro-code .highlighted-word {
|
|
369
|
+
background: color-mix(in srgb, var(--wd-primary) 20%, transparent);
|
|
370
|
+
border-radius: 0.25rem;
|
|
371
|
+
padding: 0.05rem 0.2rem;
|
|
372
|
+
margin: -0.05rem -0.15rem;
|
|
373
|
+
}
|