do11y 0.4.2 → 0.5.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.
@@ -3,8 +3,15 @@ import { writeFileSync } from "node:fs";
3
3
  import { output } from "../files.js";
4
4
  import { render } from "./render.js";
5
5
  export const indexHtml = (folder, key) => ({
6
- writeBundle() {
7
- const html = render(`/assets/${key}.js`, `/assets/${key}.css`);
6
+ writeBundle(_, bundle) {
7
+ const chunk = Object.values(bundle).find((chunk) => {
8
+ return chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId?.endsWith(`${key}.js`);
9
+ });
10
+ if (!chunk) {
11
+ throw new Error(`Failed to create HTML file for ${key}.`);
12
+ }
13
+ const stylesheets = Array.from(chunk.viteMetadata?.importedCss || []);
14
+ const html = render(chunk.fileName, stylesheets);
8
15
  writeFileSync(join(output, `${key}.html`), html);
9
16
  if (key === "index") {
10
17
  writeFileSync(join(output, "404.html"), html);
@@ -1 +1 @@
1
- export declare const render: (script: string, stylesheet?: string) => string;
1
+ export declare const render: (script: string, stylesheets?: string[]) => string;
@@ -2,13 +2,13 @@ import { readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { JSDOM } from "jsdom";
4
4
  const template = readFileSync(join(import.meta.dirname, "index.html"), "utf-8");
5
- export const render = (script, stylesheet) => {
5
+ export const render = (script, stylesheets = []) => {
6
6
  const jsdom = new JSDOM(template);
7
7
  const scriptElement = jsdom.window.document.createElement("script");
8
8
  scriptElement.setAttribute("type", "module");
9
9
  scriptElement.setAttribute("src", script);
10
10
  jsdom.window.document.documentElement.appendChild(scriptElement);
11
- if (stylesheet) {
11
+ for (const stylesheet of stylesheets) {
12
12
  const linkElement = jsdom.window.document.createElement("link");
13
13
  linkElement.setAttribute("as", "style");
14
14
  linkElement.setAttribute("rel", "preload stylesheet");
@@ -2,6 +2,10 @@ import type { Options } from "./plugins/options.js";
2
2
  import type { Meta } from "./plugins/meta/meta-types.js";
3
3
  export type { Options, Meta };
4
4
  export interface SandboxIframeProps {
5
+ /**
6
+ * The accessible title for the Iframe.
7
+ */
8
+ title: string;
5
9
  /**
6
10
  * The `id` of the sandbox - which is the filename
7
11
  * in lower-case without the extension.
@@ -1,5 +1,5 @@
1
1
  import type { Plugin } from "vite";
2
- import type { App, Component } from "vue";
2
+ import type { App } from "vue";
3
3
  import type { Router } from "vue-router";
4
4
  import type { BundledTheme, ShikiTransformer, StringLiteralUnion, ThemeInput } from "shiki";
5
5
  import type { MarkdownPluginOptions } from "./markdown.js";
@@ -8,18 +8,10 @@ export interface Options extends MarkdownPluginOptions {
8
8
  * Additional setup for the app.
9
9
  */
10
10
  setup?(app: App, router: Router): void | Promise<void>;
11
- /**
12
- * The wrapper component for sandboxes.
13
- */
14
- Sandbox?: () => Promise<Component>;
15
11
  /**
16
12
  * Additional setup for the sandbox app.
17
13
  */
18
14
  setupSandbox?(app: App): void | Promise<void>;
19
- /**
20
- * Custom wrapper component for `.vue.sandbox` imports.
21
- */
22
- SandboxIframe?: () => Promise<Component>;
23
15
  /**
24
16
  * The code highlighter.
25
17
  * - Markdown code blocks
@@ -76,9 +68,15 @@ export interface ResolvedOptions extends Omit<Options, "highlighter"> {
76
68
  };
77
69
  }
78
70
  /**
79
- * Add ability to access options (`docs/do11y/do11y.ts`)
80
- * through `do11y:options`, the home component through `do11y:home`,
81
- * and the layout component through `do11y:page-layout`.
71
+ * Adds the ability to import options and setup files.
72
+ *
73
+ * `do11y:options` `docs/do11y/do11y.ts`
74
+ *
75
+ * `do11y:home` → `docs/do11y/pages/Home.vue`
76
+ * `do11y:page-layout` → `docs/do11y/layout/Page.vue`
77
+ *
78
+ * `do11y:sandbox` → `docs/do11y/pages/Sandbox.vue`
79
+ * `do11y:sandbox-iframe` → `docs/do11y/layout/SandboxIframe.vue`
82
80
  */
83
81
  declare const _default: () => Plugin;
84
82
  export default _default;
@@ -2,37 +2,41 @@ import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { do11y } from "../files.js";
4
4
  /**
5
- * Add ability to access options (`docs/do11y/do11y.ts`)
6
- * through `do11y:options`, the home component through `do11y:home`,
7
- * and the layout component through `do11y:page-layout`.
5
+ * Adds the ability to import options and setup files.
6
+ *
7
+ * `do11y:options` `docs/do11y/do11y.ts`
8
+ *
9
+ * `do11y:home` → `docs/do11y/pages/Home.vue`
10
+ * `do11y:page-layout` → `docs/do11y/layout/Page.vue`
11
+ *
12
+ * `do11y:sandbox` → `docs/do11y/pages/Sandbox.vue`
13
+ * `do11y:sandbox-iframe` → `docs/do11y/layout/SandboxIframe.vue`
8
14
  */
9
- export default () => ({
10
- name: "do11y:options",
11
- async resolveId(id, importer) {
12
- if (id === "do11y:options") {
13
- return this.resolve(join(do11y, "do11y.js"), importer);
14
- }
15
- if (id === "do11y:home") {
16
- const homeFile = join(do11y, "pages", "Home.vue");
17
- /* prettier-ignore */
18
- return existsSync(homeFile)
19
- ? this.resolve(homeFile, importer)
20
- : `\0do11y:home`;
21
- }
22
- if (id === "do11y:page-layout") {
23
- const pageLayoutFile = join(do11y, "layout", "Page.vue");
24
- /* prettier-ignore */
25
- return existsSync(pageLayoutFile)
26
- ? this.resolve(pageLayoutFile, importer)
27
- : `\0do11y:page-layout`;
28
- }
29
- },
30
- async load(id) {
31
- if (id === `\0do11y:home` || id === `\0do11y:page-layout`) {
32
- return {
33
- code: "export default undefined",
34
- moduleType: "js",
35
- };
36
- }
37
- },
38
- });
15
+ export default () => {
16
+ const setupFiles = {
17
+ "do11y:options": join(do11y, "do11y.js"),
18
+ "do11y:home": join(do11y, "pages", "Home.vue"),
19
+ "do11y:page-layout": join(do11y, "layout", "Page.vue"),
20
+ "do11y:sandbox": join(do11y, "pages", "Sandbox.vue"),
21
+ "do11y:sandbox-iframe": join(do11y, "layout", "SandboxIframe.vue"),
22
+ };
23
+ return {
24
+ name: "do11y:options",
25
+ async resolveId(id, importer) {
26
+ if (Object.keys(setupFiles).includes(id)) {
27
+ /* prettier-ignore */
28
+ return existsSync(setupFiles[id])
29
+ ? this.resolve(setupFiles[id], importer)
30
+ : `\0${id}`;
31
+ }
32
+ },
33
+ async load(id) {
34
+ if (id.startsWith("\0") && Object.keys(setupFiles).includes(id.replace("\0", ""))) {
35
+ return {
36
+ code: "export default undefined",
37
+ moduleType: "js",
38
+ };
39
+ }
40
+ },
41
+ };
42
+ };
@@ -2,8 +2,8 @@ import { join, parse } from "node:path";
2
2
  import { existsSync, readdirSync, readFileSync } from "node:fs";
3
3
  import { globSync } from "tinyglobby";
4
4
  import { root, do11y } from "../files.js";
5
- import fm from "front-matter";
6
5
  import { toParamId } from "./sandbox.js";
6
+ import fm from "front-matter";
7
7
  /**
8
8
  * Adds the ability to import routes through `do11y:routes`.
9
9
  *
@@ -24,9 +24,10 @@ export default () => {
24
24
  .map((path) => ({ path, frontmatter: fm(readFileSync(path, "utf-8")).attributes }))
25
25
  .filter((file) => typeof file.frontmatter.title === "string" && typeof file.frontmatter.slug === "string");
26
26
  /* prettier-ignore */
27
- const pages = existsSync(join(do11y, "pages"))
27
+ let pages = existsSync(join(do11y, "pages"))
28
28
  ? readdirSync(join(do11y, "pages")).filter((page) => page !== "Home.vue" && (page.endsWith(".md") || page.endsWith(".vue")))
29
29
  : [];
30
+ pages = pages.filter((page) => page !== "Sandbox.vue");
30
31
  return {
31
32
  name: "do11y:routes",
32
33
  resolveId(id) {
@@ -60,8 +61,6 @@ export default () => {
60
61
  import Home from 'do11y:home';
61
62
  import options from 'do11y:options';
62
63
 
63
- import { RouterView } from 'vue-router';
64
-
65
64
  const homeRoute = {
66
65
  path: "/",
67
66
  component: Home,
@@ -72,7 +71,7 @@ export default () => {
72
71
  }
73
72
  };
74
73
 
75
- const customRoutes = (options.routes ?? []).map(page => ({
74
+ const customRoutes = (options?.routes ?? []).map(page => ({
76
75
  ...page,
77
76
 
78
77
  meta: {
@@ -2,7 +2,7 @@ import type { Plugin } from "vite";
2
2
  export declare const toParamId: (path: string) => string;
3
3
  /**
4
4
  * Creates a seprate sandbox app, and
5
- * adds access to sandbox components through `do11y:sandbox`.
5
+ * adds access to sandbox components through `do11y:sandboxes`.
6
6
  */
7
7
  declare const _default: () => Plugin;
8
8
  export default _default;
@@ -5,10 +5,10 @@ import { indexHtml } from "../html/plugin.js";
5
5
  export const toParamId = (path) => parse(path).name.toLowerCase().replace(".sandbox", "").replace(".vue", "");
6
6
  /**
7
7
  * Creates a seprate sandbox app, and
8
- * adds access to sandbox components through `do11y:sandbox`.
8
+ * adds access to sandbox components through `do11y:sandboxes`.
9
9
  */
10
10
  export default () => {
11
- const moduleId = "do11y:sandbox";
11
+ const moduleId = "do11y:sandboxes";
12
12
  const resolvedModuleId = "\0" + moduleId;
13
13
  const sandboxFiles = globSync(["(docs|src|packages)/**/*.sandbox.vue"], {
14
14
  ignore: ["**/node_modules/**", "**/dist/**"],
@@ -17,7 +17,7 @@ export default () => {
17
17
  cwd: root,
18
18
  });
19
19
  return {
20
- name: "do11y:sandbox",
20
+ name: "do11y:sandboxes",
21
21
  ...indexHtml(ui, "sandbox"),
22
22
  resolveId(id) {
23
23
  if (id === moduleId) {
package/dist/ui/index.js CHANGED
@@ -1 +1 @@
1
- import{createApp as e,createBlock as t,defineComponent as n,onBeforeMount as r,openBlock as i,resolveComponent as a,unref as o}from"vue";import s from"do11y:options";import{createRouter as c,createWebHistory as l}from"vue-router";import u from"do11y:routes";import d from"do11y:page-layout";import f from"do11y:css";var p=n({__name:`Page`,setup(e){return r(async()=>{let e=document.createElement(`style`);e.innerHTML=f,document.head.appendChild(e)}),(e,n)=>{let r=a(`RouterView`);return o(d)?(i(),t(o(d),{key:0})):(i(),t(r,{key:1}))}}});(async()=>{let t=c({history:l(`/`),routes:u,scrollBehavior(e,t,n){if(!e.hash)return;let r=document.querySelector(e.hash);if(!r)return;let i=parseFloat(getComputedStyle(r).scrollMarginTop);return{el:e.hash,top:isNaN(i)?n?.top??0:i}}}),n=e(p);await s.setup?.(n,t),n.use(t),n.mount(`#app`)})();
1
+ import{createApp as e,createBlock as t,defineComponent as n,onBeforeMount as r,openBlock as i,resolveComponent as a,unref as o}from"vue";import{createRouter as s,createWebHistory as c}from"vue-router";import l from"do11y:routes";import u from"do11y:options";import d from"do11y:page-layout";import f from"do11y:css";var p=n({__name:`Page`,setup(e){return r(async()=>{let e=document.createElement(`style`);e.innerHTML=f,document.head.appendChild(e)}),(e,n)=>{let r=a(`RouterView`);return o(d)?(i(),t(o(d),{key:0})):(i(),t(r,{key:1}))}}});(async()=>{let t=s({history:c(`/`),routes:l,scrollBehavior(e,t,n){if(!e.hash)return;let r=document.querySelector(e.hash);if(!r)return;let i=parseFloat(getComputedStyle(r).scrollMarginTop);return{el:e.hash,top:isNaN(i)?n?.top??0:i}}}),n=e(p);await u?.setup?.(n,t),n.use(t),n.mount(`#app`)})();
@@ -1 +1 @@
1
- import{computed as e,createBlock as t,createElementBlock as n,defineComponent as r,mergeProps as i,onBeforeMount as a,openBlock as o,shallowRef as s,unref as c}from"vue";import l from"do11y:options";var u=[`src`],d=r({__name:`SandboxIframe`,props:{id:{},url:{},highlightedSource:{},highlightedStylelessSource:{},highlightedCssSource:{},passedProps:{}},setup(r){let d=r,f=e(()=>`/sandbox?id=${d.id}`),p=s();return a(async()=>{p.value=(await l.SandboxIframe?.())?.default}),(e,a)=>p.value?(o(),t(c(p),i({key:0,id:r.id,url:f.value,"highlighted-source":r.highlightedSource,"highlighted-css-source":r.highlightedCssSource,"highlighted-styleless-source":r.highlightedStylelessSource},r.passedProps),null,16,[`id`,`url`,`highlighted-source`,`highlighted-css-source`,`highlighted-styleless-source`])):(o(),n(`iframe`,{key:1,src:f.value},null,8,u))}});export{d as default};
1
+ import{computed as e,createBlock as t,createElementBlock as n,defineComponent as r,mergeProps as i,openBlock as a,unref as o}from"vue";import s from"do11y:sandbox-iframe";var c=[`title`,`src`],l=r({__name:`SandboxIframe`,props:{title:{},id:{},url:{},highlightedSource:{},highlightedStylelessSource:{},highlightedCssSource:{},passedProps:{}},setup(r){let l=r,u=e(()=>`/sandbox?id=${l.id}`);return(e,l)=>o(s)?(a(),t(o(s),i({key:0,title:r.title,id:r.id,url:u.value,"highlighted-source":r.highlightedSource,"highlighted-css-source":r.highlightedCssSource,"highlighted-styleless-source":r.highlightedStylelessSource},r.passedProps),null,16,[`title`,`id`,`url`,`highlighted-source`,`highlighted-css-source`,`highlighted-styleless-source`])):(a(),n(`iframe`,{key:1,title:r.title,src:u.value},null,8,c))}});export{l as default};
@@ -1 +1 @@
1
- import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,shallowRef as o,unref as s,withCtx as c}from"vue";import l from"do11y:options";import{parseQuery as u}from"vue-router";import d from"do11y:sandbox";e(r({__name:`Sandbox`,setup(e){let r=u(window.location.search),f=o(),p=o();return i(async()=>{let{component:e}=d.find(({url:e})=>e===r.id)??{};f.value=(await l.Sandbox?.())?.default,p.value=await e?.()}),(e,r)=>f.value?(a(),t(s(f),{key:0},{default:c(()=>[p.value?(a(),t(s(p),{key:0})):n(``,!0)]),_:1})):n(``,!0)}})).mount(`#app`);
1
+ import{createApp as e,createBlock as t,createCommentVNode as n,defineComponent as r,onBeforeMount as i,openBlock as a,shallowRef as o,unref as s,withCtx as c}from"vue";import{parseQuery as l}from"vue-router";import u from"do11y:sandboxes";import d from"do11y:sandbox";e(r({__name:`Sandbox`,setup(e){let r=l(window.location.search),f=o();return i(async()=>{let{component:e}=u.find(({url:e})=>e===r.id)??{};f.value=await e?.()}),(e,r)=>s(d)?(a(),t(s(d),{key:0},{default:c(()=>[f.value?(a(),t(s(f),{key:0})):n(``,!0)]),_:1})):n(``,!0)}})).mount(`#app`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "do11y",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",
@@ -50,7 +50,7 @@
50
50
  "jiti": "^2.6.1",
51
51
  "oxfmt": "^0.41.0",
52
52
  "oxlint": "^1.56.0",
53
- "typescript": "~5.9.3"
53
+ "typescript": "~6.0.2"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@vitejs/plugin-vue": "^6.0.5",
package/src/types.d.ts CHANGED
@@ -16,11 +16,13 @@ declare module "do11y:routes" {
16
16
  declare module "do11y:options" {
17
17
  import type { Options } from "do11y";
18
18
 
19
- const options: Omit<Options, "Layout" | "Sandbox" | "SandboxIframe"> & {
20
- Layout: () => Promise<{ default: Component }>;
21
- Sandbox?: () => Promise<{ default: Component }>;
22
- SandboxIframe?: () => Promise<{ default: Component }>;
23
- };
19
+ const options:
20
+ | (Omit<Options, "Layout" | "Sandbox" | "SandboxIframe"> & {
21
+ Layout: () => Promise<{ default: Component }>;
22
+ Sandbox?: () => Promise<{ default: Component }>;
23
+ SandboxIframe?: () => Promise<{ default: Component }>;
24
+ })
25
+ | undefined;
24
26
 
25
27
  export default options;
26
28
  }
@@ -37,12 +39,24 @@ declare module "do11y:page-layout" {
37
39
  export default layout;
38
40
  }
39
41
 
42
+ declare module "do11y:sandbox" {
43
+ import type { Component } from "vue";
44
+ const sandbox: Component | undefined;
45
+ export default sandbox;
46
+ }
47
+
48
+ declare module "do11y:sandbox-iframe" {
49
+ import type { Component } from "vue";
50
+ const iframe: Component | undefined;
51
+ export default iframe;
52
+ }
53
+
40
54
  declare module "do11y:css" {
41
55
  const css: string;
42
56
  export default string;
43
57
  }
44
58
 
45
- declare module "do11y:sandbox" {
59
+ declare module "do11y:sandboxes" {
46
60
  import type { Component } from "vue";
47
61
 
48
62
  const sandboxes: {