do11y 0.1.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -4
- package/dist/docs/files.js +4 -2
- package/dist/docs/index.d.ts +6 -5
- package/dist/docs/options.d.ts +3 -3
- package/dist/docs/options.js +30 -2
- package/dist/docs/plugins/highlight.d.ts +9 -0
- package/dist/docs/plugins/highlight.js +103 -0
- package/dist/docs/plugins/markdown.d.ts +0 -5
- package/dist/docs/plugins/markdown.js +3 -2
- package/dist/docs/plugins/options.d.ts +29 -4
- package/dist/docs/plugins/plugins.js +2 -0
- package/dist/docs/plugins/sandbox.js +5 -26
- package/dist/docs/vite-config.js +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/ui/sandbox-iframe.js +1 -1
- package/package.json +14 -1
- package/src/types.d.ts +6 -0
package/README.md
CHANGED
|
@@ -2,7 +2,101 @@
|
|
|
2
2
|
|
|
3
3
|
A bare-bones tool to document Vue components.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Markdown components with [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
|
|
8
|
+
|
|
9
|
+
Markdown files are treated as single file Vue components with the help of [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
|
|
10
|
+
|
|
11
|
+
You can customize the markdown-it instance through the `markdownSetup` option.
|
|
12
|
+
|
|
13
|
+
### Import markdown route files as routes through `do11y:routes`
|
|
14
|
+
|
|
15
|
+
To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter.
|
|
16
|
+
|
|
17
|
+
### [Shiki](https://shiki.style) code highlighting
|
|
18
|
+
|
|
19
|
+
Code blocks are automatically highlighted with [Shiki](https://shiki.style).
|
|
20
|
+
|
|
21
|
+
You can customize the Shiki instance through the `highlighter` options.
|
|
22
|
+
|
|
23
|
+
### Highlight imports
|
|
24
|
+
|
|
25
|
+
You can import Vue files as highlighted code blocks through `.vue?highlight`, or `.vue?highlight&lang=css` (if you want the output to compile the style tags).
|
|
26
|
+
|
|
27
|
+
These imports return HTML strings meaning you have to render the code block using `v-html`.
|
|
28
|
+
|
|
29
|
+
> [!WARNING]
|
|
30
|
+
> Imports of type `.vue?highlight&lang=css` only work on built sites. During development it will return the same result as `.vue?highlight`.
|
|
31
|
+
|
|
32
|
+
### Sandboxes
|
|
33
|
+
|
|
34
|
+
Create sandbox components - e.g. `Button.sandbox.vue` will be available under the url `/sandbox?id=button`, and if importing the component it will be wrapped inside an iframe component that has access to the components `?highlight` imports.
|
|
35
|
+
|
|
36
|
+
To customize the sandbox app, use the `Sandbox` option - and to cutomize the iframe component used for import, use the `SandboxIframe` option.
|
|
37
|
+
|
|
38
|
+
> [!NOTE]
|
|
39
|
+
> The id is based on the filename - not the path to the file - this means if you have two sandbox files of the same name in different locations - they won't both work.
|
|
40
|
+
|
|
41
|
+
### Document components with [vue-component-meta](https://www.npmjs.com/package/vue-component-meta)
|
|
42
|
+
|
|
43
|
+
Document components through meta imports (`Button.vue?meta`) which give a simplified version of a result from [vue-component-meta](https://www.npmjs.com/package/vue-component-meta).
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
Expected to be in file `docs/do11y/do11y.ts`.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export interface Options {
|
|
51
|
+
/**
|
|
52
|
+
* The home page.
|
|
53
|
+
*/
|
|
54
|
+
Home: () => Promise<Component>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The layout for each route.
|
|
58
|
+
*/
|
|
59
|
+
Layout?: () => Promise<Component>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Additional setup for the app.
|
|
63
|
+
*/
|
|
64
|
+
setup?(app: App, router: Router): void | Promise<void>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The wrapper component for sandboxes.
|
|
68
|
+
*/
|
|
69
|
+
Sandbox?: () => Promise<Component>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Additional setup for the sandbox app.
|
|
73
|
+
*/
|
|
74
|
+
setupSandbox?(app: App): void | Promise<void>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Custom wrapper component for `.vue.sandbox` imports.
|
|
78
|
+
*/
|
|
79
|
+
SandboxIframe?: () => Promise<Component>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The code highlighter.
|
|
83
|
+
* - Markdown code blocks
|
|
84
|
+
* - `.vue?highlight` & `.vue?highlight&lang=css` imports
|
|
85
|
+
* - `highlightedSource` and `highlightedCssSource` props in SandboxIframe
|
|
86
|
+
*
|
|
87
|
+
* If using multiple themes - you can set the `data-theme` attribute
|
|
88
|
+
* to switch between them, e.g. `data-theme="vitesse-light"`.
|
|
89
|
+
*/
|
|
90
|
+
highlighter?: {
|
|
91
|
+
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
92
|
+
defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
|
|
93
|
+
transformers?: ShikiTransformer[];
|
|
94
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Additional markdown-it setup.
|
|
99
|
+
*/
|
|
100
|
+
markdownSetup?: PluginSimple;
|
|
101
|
+
}
|
|
102
|
+
```
|
package/dist/docs/files.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { searchForWorkspaceRoot } from "vite";
|
|
3
|
+
const [_, __, ___, relativePath] = process.argv;
|
|
3
4
|
export const ui = join(import.meta.dirname, "../ui");
|
|
4
|
-
export const root =
|
|
5
|
-
|
|
5
|
+
export const root = relativePath
|
|
6
|
+
? join(searchForWorkspaceRoot(process.cwd()), relativePath)
|
|
7
|
+
: searchForWorkspaceRoot(process.cwd());
|
|
6
8
|
export const docs = join(root, "docs");
|
|
7
9
|
export const output = join(docs, "dist");
|
|
8
10
|
export const do11y = join(docs, "do11y", "do11y.ts");
|
package/dist/docs/index.d.ts
CHANGED
|
@@ -16,16 +16,17 @@ export interface SandboxIframeProps {
|
|
|
16
16
|
*/
|
|
17
17
|
url: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* HTML string containing the highlighted source code.
|
|
20
20
|
*
|
|
21
21
|
* @do11y Automatically passed.
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
highlightedSource: string;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* HTML string containing the highlighted source code,
|
|
26
|
+
* with all the style tags compiled to CSS.
|
|
27
27
|
*
|
|
28
28
|
* @do11y Automatically passed.
|
|
29
|
+
* @caveat Only works in a built solution - during development this returns the same as `highlightedSource`.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
highlightedCssSource: string;
|
|
31
32
|
}
|
package/dist/docs/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResolvedOptions } from "./plugins/options.js";
|
|
2
2
|
/**
|
|
3
|
-
* Access plugin options (`docs/do11y/
|
|
3
|
+
* Access plugin options (`docs/do11y/do11y.ts`).
|
|
4
4
|
*/
|
|
5
|
-
export declare const do11yOptions:
|
|
5
|
+
export declare const do11yOptions: ResolvedOptions;
|
package/dist/docs/options.js
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { do11y } from "./files.js";
|
|
2
|
+
const resolveOptions = async () => {
|
|
3
|
+
const options = (await import(do11y)).default;
|
|
4
|
+
const themes = options.highlighter?.themes.map(async (theme) => {
|
|
5
|
+
if (typeof theme === "string") {
|
|
6
|
+
return theme;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const resolvedTheme = await (typeof theme === "function" ? await theme() : theme);
|
|
10
|
+
return "default" in resolvedTheme ? resolvedTheme.default.name : resolvedTheme.name;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
/* prettier-ignore */
|
|
14
|
+
let resolvedThemes = (await Promise.all(themes ?? [])).filter((theme) => !!theme);
|
|
15
|
+
if (!resolvedThemes.length) {
|
|
16
|
+
resolvedThemes = ["vitesse-light", "vitesse-black", "vitesse-dark"];
|
|
17
|
+
}
|
|
18
|
+
const themesInput = {};
|
|
19
|
+
resolvedThemes.forEach((theme) => (themesInput[theme] = theme));
|
|
20
|
+
return {
|
|
21
|
+
...options,
|
|
22
|
+
highlighter: {
|
|
23
|
+
defaultTheme: options.highlighter?.defaultTheme || resolvedThemes[0],
|
|
24
|
+
themes: options.highlighter?.themes ?? [],
|
|
25
|
+
themesInput,
|
|
26
|
+
transformers: options.highlighter?.transformers || [],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
|
2
30
|
/**
|
|
3
|
-
* Access plugin options (`docs/do11y/
|
|
31
|
+
* Access plugin options (`docs/do11y/do11y.ts`).
|
|
4
32
|
*/
|
|
5
|
-
export const do11yOptions =
|
|
33
|
+
export const do11yOptions = await resolveOptions();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare const highlightCode: (code: string, lang: string) => string;
|
|
3
|
+
export declare const highlightAndFormatCode: (path: string, code: string) => Promise<string>;
|
|
4
|
+
/**
|
|
5
|
+
* Adds `.vue?highlight` imports which returns the
|
|
6
|
+
* highlighted code from Shiki.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: () => Plugin;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { parse as parseVue } from "vue/compiler-sfc";
|
|
3
|
+
import { format } from "oxfmt";
|
|
4
|
+
import { createHighlighter, bundledLanguages, bundledThemes } from "shiki";
|
|
5
|
+
import { JSDOM } from "jsdom";
|
|
6
|
+
import { do11yOptions } from "../options.js";
|
|
7
|
+
import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationHighlight, } from "@shikijs/transformers";
|
|
8
|
+
const shiki = await createHighlighter({
|
|
9
|
+
langs: Object.keys(bundledLanguages),
|
|
10
|
+
themes: [...Object.values(bundledThemes), ...do11yOptions.highlighter.themes],
|
|
11
|
+
});
|
|
12
|
+
export const highlightCode = (code, lang) => {
|
|
13
|
+
return shiki.codeToHtml(code, {
|
|
14
|
+
lang,
|
|
15
|
+
themes: do11yOptions.highlighter.themesInput,
|
|
16
|
+
defaultColor: do11yOptions.highlighter.defaultTheme,
|
|
17
|
+
transformers: [
|
|
18
|
+
transformerNotationHighlight(),
|
|
19
|
+
transformerNotationDiff(),
|
|
20
|
+
transformerNotationErrorLevel(),
|
|
21
|
+
...do11yOptions.highlighter.transformers,
|
|
22
|
+
{
|
|
23
|
+
name: "do11y",
|
|
24
|
+
postprocess(html) {
|
|
25
|
+
const jsdom = new JSDOM(html);
|
|
26
|
+
const preTag = jsdom.window.document.querySelector("pre");
|
|
27
|
+
do11yOptions.highlighter.postprocess?.(preTag);
|
|
28
|
+
return preTag.parentElement.innerHTML;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const highlightAndFormatCode = async (path, code) => {
|
|
35
|
+
return highlightCode((await format(path, code)).code, "vue");
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Adds `.vue?highlight` imports which returns the
|
|
39
|
+
* highlighted code from Shiki.
|
|
40
|
+
*/
|
|
41
|
+
export default () => {
|
|
42
|
+
let viteDevServer;
|
|
43
|
+
return {
|
|
44
|
+
name: "do11y:shiki",
|
|
45
|
+
configureServer(server) {
|
|
46
|
+
viteDevServer = server;
|
|
47
|
+
},
|
|
48
|
+
async resolveId(id) {
|
|
49
|
+
if (id === "do11y:css") {
|
|
50
|
+
return "\0dolly:css.css";
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
async load(id) {
|
|
54
|
+
if (id === "\0dolly:css.css") {
|
|
55
|
+
const generateThemeCss = (theme) => `
|
|
56
|
+
[data-theme="${theme}"] .shiki {
|
|
57
|
+
background-color: var(--shiki-${theme}-bg) !important;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[data-theme="${theme}"] .shiki span {
|
|
61
|
+
color: var(--shiki-${theme}) !important;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
return Object.keys(do11yOptions.highlighter.themesInput)
|
|
65
|
+
.filter((theme) => do11yOptions.highlighter.defaultTheme !== theme)
|
|
66
|
+
.map((theme) => generateThemeCss(theme))
|
|
67
|
+
.join("\n");
|
|
68
|
+
}
|
|
69
|
+
else if (id.endsWith(".vue?highlight") || id.endsWith(".vue?highlight&lang=css")) {
|
|
70
|
+
const path = id.replace("?highlight", "").replace("&lang=css", "");
|
|
71
|
+
const source = readFileSync(path, "utf-8");
|
|
72
|
+
/**
|
|
73
|
+
* Getting the code from `load` does not work during development,
|
|
74
|
+
* so we return the original code during development.
|
|
75
|
+
*
|
|
76
|
+
* We also return the original code if the import does not specifically ask
|
|
77
|
+
* to compile the style tags to CSS.
|
|
78
|
+
*/
|
|
79
|
+
if (viteDevServer?.config.command === "serve" || !id.endsWith("lang=css")) {
|
|
80
|
+
return `export default ${JSON.stringify(await highlightAndFormatCode(path, source))};`;
|
|
81
|
+
}
|
|
82
|
+
const loadCss = async (index, lang) => {
|
|
83
|
+
const { code } = await this.load({
|
|
84
|
+
id: path + `?vue&type=style&index=${index}&lang.${lang}?inline`,
|
|
85
|
+
});
|
|
86
|
+
return code?.replace(/^(export default ")/, "").replace(/"$/, "");
|
|
87
|
+
};
|
|
88
|
+
const sourceWithoutStyles = source.replace(/\n<style\b[^>]*>[\s\S]*?<\/style>/gi, "");
|
|
89
|
+
const stylesheets = parseVue(source).descriptor.styles.map((style, i) => {
|
|
90
|
+
/* prettier-ignore */
|
|
91
|
+
return !style.lang || style.lang === "css"
|
|
92
|
+
? style.content
|
|
93
|
+
: loadCss(i, style.lang);
|
|
94
|
+
});
|
|
95
|
+
const css = (await Promise.all(stylesheets))
|
|
96
|
+
.filter((stylesheet) => !!stylesheet)
|
|
97
|
+
.map((stylesheet) => `<style>${stylesheet}</style>`)
|
|
98
|
+
.join("\n");
|
|
99
|
+
return `export default ${JSON.stringify(await highlightAndFormatCode(path, sourceWithoutStyles + css))};`;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { type MarkdownSfcBlocks } from "@mdit-vue/plugin-sfc";
|
|
2
2
|
import type { PluginSimple } from "markdown-it";
|
|
3
3
|
import type { Plugin } from "vite";
|
|
4
|
-
import type MarkdownIt from "markdown-it";
|
|
5
4
|
export interface MarkdownPluginOptions {
|
|
6
5
|
/**
|
|
7
6
|
* Additional markdown-it setup.
|
|
8
7
|
*/
|
|
9
8
|
markdownSetup?: PluginSimple;
|
|
10
|
-
/**
|
|
11
|
-
* The highlight option for `markdown-it`.
|
|
12
|
-
*/
|
|
13
|
-
markdownHighlight?: (md: MarkdownIt, code: string, lang: string, attrs: string) => string;
|
|
14
9
|
}
|
|
15
10
|
export interface MarkdownItEnv {
|
|
16
11
|
/**
|
|
@@ -3,6 +3,7 @@ import { sfcPlugin } from "@mdit-vue/plugin-sfc";
|
|
|
3
3
|
import { frontmatterPlugin } from "@mdit-vue/plugin-frontmatter";
|
|
4
4
|
import attrsPlugin from "markdown-it-attrs";
|
|
5
5
|
import markdown from "markdown-it";
|
|
6
|
+
import { highlightCode } from "./highlight.js";
|
|
6
7
|
/**
|
|
7
8
|
* Processes blocks with the lang set to `md` into HTML,
|
|
8
9
|
* and turns `.md` files into single file vue components
|
|
@@ -11,8 +12,8 @@ import markdown from "markdown-it";
|
|
|
11
12
|
export default (options) => {
|
|
12
13
|
const md = markdown({
|
|
13
14
|
html: true,
|
|
14
|
-
highlight(code, lang
|
|
15
|
-
return
|
|
15
|
+
highlight(code, lang) {
|
|
16
|
+
return highlightCode(code, lang);
|
|
16
17
|
},
|
|
17
18
|
});
|
|
18
19
|
md.use(frontmatterPlugin);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import type { App, Component } from "vue";
|
|
3
3
|
import type { Router } from "vue-router";
|
|
4
|
+
import type { BundledTheme, ShikiTransformer, StringLiteralUnion, ThemeInput } from "shiki";
|
|
4
5
|
import type { MarkdownPluginOptions } from "./markdown.js";
|
|
5
6
|
export interface Options extends MarkdownPluginOptions {
|
|
6
7
|
/**
|
|
7
|
-
* The home page
|
|
8
|
+
* The home page.
|
|
8
9
|
*/
|
|
9
10
|
Home: () => Promise<Component>;
|
|
10
11
|
/**
|
|
11
|
-
* The layout
|
|
12
|
+
* The layout for each route.
|
|
12
13
|
*/
|
|
13
14
|
Layout?: () => Promise<Component>;
|
|
14
15
|
/**
|
|
@@ -16,7 +17,7 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
16
17
|
*/
|
|
17
18
|
setup?(app: App, router: Router): void | Promise<void>;
|
|
18
19
|
/**
|
|
19
|
-
* The wrapper component for
|
|
20
|
+
* The wrapper component for sandboxes.
|
|
20
21
|
*/
|
|
21
22
|
Sandbox?: () => Promise<Component>;
|
|
22
23
|
/**
|
|
@@ -24,9 +25,33 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
24
25
|
*/
|
|
25
26
|
setupSandbox?(app: App): void | Promise<void>;
|
|
26
27
|
/**
|
|
27
|
-
* Custom wrapper component for
|
|
28
|
+
* Custom wrapper component for `.vue.sandbox` imports.
|
|
28
29
|
*/
|
|
29
30
|
SandboxIframe?: () => Promise<Component>;
|
|
31
|
+
/**
|
|
32
|
+
* The code highlighter.
|
|
33
|
+
* - Markdown code blocks
|
|
34
|
+
* - `.vue?highlight` & `.vue?highlight&lang=css` imports
|
|
35
|
+
* - `highlightedSource` and `highlightedCssSource` props in SandboxIframe
|
|
36
|
+
*
|
|
37
|
+
* If using multiple themes - you can set the `data-theme` attribute
|
|
38
|
+
* to switch between them, e.g. `data-theme="vitesse-light"`.
|
|
39
|
+
*/
|
|
40
|
+
highlighter?: {
|
|
41
|
+
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
42
|
+
defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
|
|
43
|
+
transformers?: ShikiTransformer[];
|
|
44
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface ResolvedOptions extends Omit<Options, "highlighter"> {
|
|
48
|
+
highlighter: {
|
|
49
|
+
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
50
|
+
themesInput: Record<string, string>;
|
|
51
|
+
defaultTheme: string;
|
|
52
|
+
transformers: ShikiTransformer[];
|
|
53
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
54
|
+
};
|
|
30
55
|
}
|
|
31
56
|
/**
|
|
32
57
|
* Add ability to access options (`docs/do11y/do11y.ts`)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ui from "./ui.js";
|
|
2
2
|
import sandbox from "./sandbox.js";
|
|
3
|
+
import highlight from "./highlight.js";
|
|
3
4
|
import meta from "./meta/meta.js";
|
|
4
5
|
import markdown from "./markdown.js";
|
|
5
6
|
import block from "v-custom-block";
|
|
@@ -9,6 +10,7 @@ import { do11yOptions } from "../options.js";
|
|
|
9
10
|
export const plugins = () => [
|
|
10
11
|
ui(),
|
|
11
12
|
sandbox(),
|
|
13
|
+
highlight(),
|
|
12
14
|
meta(),
|
|
13
15
|
markdown(do11yOptions),
|
|
14
16
|
block("docs"),
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { join, parse } from "node:path";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
2
|
import { globSync } from "tinyglobby";
|
|
4
|
-
import { parse as parseVue } from "vue/compiler-sfc";
|
|
5
3
|
import { root, ui } from "../files.js";
|
|
6
4
|
import { indexHtml } from "../html/plugin.js";
|
|
7
5
|
const toParamId = (path) => parse(path).name.toLowerCase().replace(".sandbox", "");
|
|
@@ -37,40 +35,21 @@ export default () => {
|
|
|
37
35
|
return `export default [${stringifiedSandboxes.join(",\n")}];`;
|
|
38
36
|
}
|
|
39
37
|
},
|
|
40
|
-
|
|
38
|
+
transform(_, id) {
|
|
41
39
|
if (id.endsWith(".sandbox.vue")) {
|
|
42
|
-
const source = readFileSync(id, "utf-8");
|
|
43
|
-
const sourceWithoutStyles = source.replace(/\n<style\b[^>]*>[\s\S]*?<\/style>/gi, "");
|
|
44
|
-
const { descriptor } = parseVue(source, {
|
|
45
|
-
filename: id,
|
|
46
|
-
ignoreEmpty: true,
|
|
47
|
-
});
|
|
48
|
-
const usesSass = descriptor.styles.some((s) => s.lang && ["sass", "scss"].includes(s.lang));
|
|
49
|
-
const imports = descriptor.styles
|
|
50
|
-
.map((_, i) => `import Css${i} from "${id}?vue&type=style&index=${i}&lang.scss?inline";`)
|
|
51
|
-
.join("");
|
|
52
|
-
const stylesheets = descriptor.styles.map((_, i) => `Css${i}`).join(", ");
|
|
53
40
|
const code = `
|
|
54
41
|
import { defineComponent, h } from "vue";
|
|
55
42
|
|
|
56
43
|
import SandboxIframe from "${join(ui, "sandbox-iframe.js")}";
|
|
57
44
|
|
|
58
|
-
${
|
|
59
|
-
|
|
60
|
-
const sourceWithoutStyleTags = ${JSON.stringify(sourceWithoutStyles)};
|
|
61
|
-
|
|
62
|
-
const cssStylesheet = [${stylesheets}].join("");
|
|
63
|
-
|
|
64
|
-
const sourceWithStylesheet = !!cssStylesheet
|
|
65
|
-
? sourceWithoutStyleTags + '<style>' + cssStylesheet + '</style>'
|
|
66
|
-
: sourceWithoutStyleTags;
|
|
45
|
+
import highlightedSource from "${id}?highlight";
|
|
46
|
+
import highlightedCssSource from "${id}?highlight&lang=css";
|
|
67
47
|
|
|
68
48
|
export default defineComponent((props) => {
|
|
69
49
|
return () => h(SandboxIframe, {
|
|
70
50
|
id: "${toParamId(id)}",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
passedProps: props,
|
|
51
|
+
highlightedSource,
|
|
52
|
+
highlightedCssSource,
|
|
74
53
|
});
|
|
75
54
|
});
|
|
76
55
|
`.trim();
|
package/dist/docs/vite-config.js
CHANGED
|
@@ -39,7 +39,7 @@ const getUserPlugins = async (userViteConfig) => {
|
|
|
39
39
|
VuePlugin({
|
|
40
40
|
...vuePluginApi.options,
|
|
41
41
|
include: [/\.vue$/, /\.md$/],
|
|
42
|
-
exclude: [/\.vue\?meta$/],
|
|
42
|
+
exclude: [/\.vue\?meta$/, /\.vue\?highlight$/, /\.vue\?highlight&lang=css$/],
|
|
43
43
|
}),
|
|
44
44
|
...resolvedUserPlugins.filter((i) => i.name !== "vite:vue"),
|
|
45
45
|
];
|
package/dist/ui/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,renderSlot as o,shallowRef as s,unref as c,withCtx as l}from"vue";import u from"do11y:options";import{createRouter as d,createWebHistory as f}from"vue-router";import p from"do11y:routes";var m=r({__name:`Page`,setup(e){let n=s();return i(async()=>{n.value=(await u.Layout?.())?.default}),(e,r)=>n.value?(a(),t(c(n),{key:0},{default:l(()=>[o(e.$slots,`default`)]),_:3})):o(e.$slots,`default`,{key:1})}});(async()=>{let t=d({history:f(`/`),routes:p}),n=e(m);await u.setup?.(n,t),n.use(t),n.mount(`#app`)})();
|
|
1
|
+
import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,renderSlot as o,shallowRef as s,unref as c,withCtx as l}from"vue";import u from"do11y:options";import{createRouter as d,createWebHistory as f}from"vue-router";import p from"do11y:routes";import"do11y:css";var m=r({__name:`Page`,setup(e){let n=s();return i(async()=>{n.value=(await u.Layout?.())?.default}),(e,r)=>n.value?(a(),t(c(n),{key:0},{default:l(()=>[o(e.$slots,`default`)]),_:3})):o(e.$slots,`default`,{key:1})}});(async()=>{let t=d({history:f(`/`),routes:p}),n=e(m);await u.setup?.(n,t),n.use(t),n.mount(`#app`)})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{computed as e,createBlock as t,createCommentVNode as n,createElementBlock as r,defineComponent as i,mergeProps as a,onBeforeMount as o,openBlock as s,shallowRef as c,unref as l}from"vue";import u from"do11y:options";var d=[`src`],f=i({__name:`SandboxIframe`,props:{id:{},url:{},
|
|
1
|
+
import{computed as e,createBlock as t,createCommentVNode as n,createElementBlock as r,defineComponent as i,mergeProps as a,onBeforeMount as o,openBlock as s,shallowRef as c,unref as l}from"vue";import u from"do11y:options";var d=[`src`],f=i({__name:`SandboxIframe`,props:{id:{},url:{},highlightedSource:{},highlightedCssSource:{},passedProps:{}},setup(n){let i=n,f=e(()=>`/sandbox?id=${i.id}`),p=c();return o(async()=>{p.value=(await u.SandboxIframe?.())?.default}),(e,i)=>p.value?(s(),t(l(p),a({key:0,id:n.id,url:f.value,"highlighted-source":n.highlightedSource,"highlighted-css-source":n.highlightedCssSource},n.passedProps),null,16,[`id`,`url`,`highlighted-source`,`highlighted-css-source`])):(s(),r(`iframe`,{key:1,src:f.value},null,8,d))}});export{f as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "do11y",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A bare-bones tool to document Vue components.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docs-generator",
|
|
7
|
+
"markdown",
|
|
8
|
+
"shiki",
|
|
9
|
+
"story",
|
|
10
|
+
"vite",
|
|
11
|
+
"vue"
|
|
12
|
+
],
|
|
5
13
|
"license": "MIT",
|
|
6
14
|
"repository": "github:sq11y/do11y",
|
|
7
15
|
"bin": "./dist/docs/cli.js",
|
|
@@ -21,11 +29,16 @@
|
|
|
21
29
|
"@mdit-vue/plugin-component": "^3.0.2",
|
|
22
30
|
"@mdit-vue/plugin-frontmatter": "^3.0.2",
|
|
23
31
|
"@mdit-vue/plugin-sfc": "^3.0.2",
|
|
32
|
+
"@shikijs/engine-oniguruma": "^3.22.0",
|
|
33
|
+
"@shikijs/langs": "^3.22.0",
|
|
34
|
+
"@shikijs/themes": "^3.22.0",
|
|
35
|
+
"@shikijs/transformers": "^3.22.0",
|
|
24
36
|
"front-matter": "^4.0.2",
|
|
25
37
|
"jsdom": "^28.1.0",
|
|
26
38
|
"markdown-it": "^14.1.1",
|
|
27
39
|
"markdown-it-attrs": "^4.3.1",
|
|
28
40
|
"sass": "^1.97.3",
|
|
41
|
+
"shiki": "^3.22.0",
|
|
29
42
|
"tinyglobby": "^0.2.15",
|
|
30
43
|
"v-custom-block": "^1.0.67",
|
|
31
44
|
"vue-component-meta": "^3.2.4"
|
package/src/types.d.ts
CHANGED