@minidocs/astro 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/behaviors.d.mts +114 -0
- package/dist/behaviors.mjs +635 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +262 -0
- package/dist/links-UTLyoo_o.mjs +177 -0
- package/dist/loaders.d.mts +20 -0
- package/dist/loaders.mjs +76 -0
- package/dist/routing-TMqRCY2Q.mjs +48 -0
- package/dist/runtime.d.mts +160 -0
- package/dist/runtime.mjs +310 -0
- package/package.json +80 -3
- package/src/components/Prose.astro +9 -0
- package/src/components/callout/Root.astro +14 -0
- package/src/components/callout/Title.astro +9 -0
- package/src/components/callout/index.ts +2 -0
- package/src/components/index.ts +7 -0
- package/src/components/layout/Aside.astro +29 -0
- package/src/components/layout/Header.astro +18 -0
- package/src/components/layout/Main.astro +9 -0
- package/src/components/layout/Root.astro +15 -0
- package/src/components/layout/Sidebar.astro +9 -0
- package/src/components/layout/Title.astro +10 -0
- package/src/components/layout/index.ts +6 -0
- package/src/components/pager/Label.astro +9 -0
- package/src/components/pager/Link.astro +12 -0
- package/src/components/pager/Root.astro +12 -0
- package/src/components/pager/Title.astro +9 -0
- package/src/components/pager/index.ts +4 -0
- package/src/components/search/Count.astro +10 -0
- package/src/components/search/Dialog.astro +14 -0
- package/src/components/search/Empty.astro +10 -0
- package/src/components/search/Error.astro +10 -0
- package/src/components/search/Found.astro +10 -0
- package/src/components/search/Idle.astro +10 -0
- package/src/components/search/Input.astro +26 -0
- package/src/components/search/Loading.astro +10 -0
- package/src/components/search/Query.astro +10 -0
- package/src/components/search/Results.astro +20 -0
- package/src/components/search/Root.astro +15 -0
- package/src/components/search/Shortcut.astro +14 -0
- package/src/components/search/Trigger.astro +28 -0
- package/src/components/search/index.ts +13 -0
- package/src/components/sidebar/Group.astro +45 -0
- package/src/components/sidebar/Item.astro +9 -0
- package/src/components/sidebar/Label.astro +9 -0
- package/src/components/sidebar/Link.astro +23 -0
- package/src/components/sidebar/List.astro +11 -0
- package/src/components/sidebar/Root.astro +24 -0
- package/src/components/sidebar/Trigger.astro +29 -0
- package/src/components/sidebar/index.ts +7 -0
- package/src/components/toc/Item.astro +9 -0
- package/src/components/toc/Link.astro +12 -0
- package/src/components/toc/List.astro +11 -0
- package/src/components/toc/Root.astro +20 -0
- package/src/components/toc/index.ts +4 -0
- package/src/styles/base.css +41 -0
- package/src/styles/callout.css +58 -0
- package/src/styles/layout.css +406 -0
- package/src/styles/pager.css +51 -0
- package/src/styles/prose.css +218 -0
- package/src/styles/search.css +202 -0
- package/src/styles/sidebar.css +162 -0
- package/src/styles/toc.css +79 -0
- package/src/styles.css +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ivan1F
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @minidocs/astro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Astro integration for building documentation sites from composable primitives.
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> minidocs is experimental. Until 1.0, minor versions may include breaking changes.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @minidocs/astro @astrojs/mdx
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// astro.config.mjs
|
|
14
|
+
import mdx from '@astrojs/mdx';
|
|
15
|
+
import { defineConfig } from 'astro/config';
|
|
16
|
+
import minidocs from '@minidocs/astro';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
integrations: [mdx(), minidocs({ prefix: 'docs' })],
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Astro 7 and Node.js 22.22 or later. See [Getting Started](https://github.com/Ivan-1F/minidocs/blob/main/docs/src/content/docs/en/getting-started.mdx) for the rest of the setup.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
//#region src/behaviors.d.ts
|
|
2
|
+
/** Framework-agnostic behaviors for minidocs markup. Each one returns a function that undoes it. */
|
|
3
|
+
/** What a sidebar remembers across page loads within a tab. */
|
|
4
|
+
export interface SidebarSnapshot {
|
|
5
|
+
/** Open state of every group, keyed by `data-md-key`. */
|
|
6
|
+
open: Record<string, boolean>;
|
|
7
|
+
scroll: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Restores a sidebar to how the reader left it on the previous page, so navigating changes nothing they can see.
|
|
11
|
+
* Groups containing the current page are always open. Without a snapshot, the current page is scrolled into view.
|
|
12
|
+
*
|
|
13
|
+
* Runs inline right after the sidebar markup, before the first paint, so it must not reference anything outside itself.
|
|
14
|
+
*/
|
|
15
|
+
export declare function restoreSidebar(root: HTMLElement): void;
|
|
16
|
+
/** Mirrors native collapsing into `data-state`, and remembers group and scroll state when the reader leaves the page. */
|
|
17
|
+
export declare function attachSidebar(root: HTMLElement): () => void;
|
|
18
|
+
export interface SidebarToggleDetail {
|
|
19
|
+
open: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Turns a button into a toggle for the element named by its `aria-controls`. */
|
|
22
|
+
export declare function attachTrigger(button: HTMLButtonElement): () => void;
|
|
23
|
+
export interface TocChangeDetail {
|
|
24
|
+
/** The link of the heading now being read. */
|
|
25
|
+
link: HTMLAnchorElement;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Marks the link of the heading being read with `aria-current="true"`. One link is always current.
|
|
29
|
+
* Each change dispatches a bubbling `md:toc-change` event with the link.
|
|
30
|
+
* A heading is passed once its top crosses its own `scroll-margin-top`, so anchor jumps and highlighting line up.
|
|
31
|
+
*/
|
|
32
|
+
export declare function attachToc(root: HTMLElement): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Marks a Layout.Root with `data-md-resizing` while the viewport is resized.
|
|
35
|
+
* Crossing a breakpoint changes the layout, not the state, so styles turn off transitions meant for opening and closing, e.g. the drawer sliding out.
|
|
36
|
+
*/
|
|
37
|
+
export declare function attachLayout(root: HTMLElement): () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Collapses a Layout.Aside that the styles show in its collapsible form, so it starts closed above the content.
|
|
40
|
+
* Runs inline right after the aside, before the first paint, so it must not reference anything outside itself.
|
|
41
|
+
*/
|
|
42
|
+
export declare function restoreAside(aside: HTMLDetailsElement): void;
|
|
43
|
+
/**
|
|
44
|
+
* Keeps a Layout.Aside open while the styles show it as a column, and closes it after a link inside is followed.
|
|
45
|
+
* The styles decide which form applies through --md-layout-aside-collapsible, so breakpoints live only in CSS.
|
|
46
|
+
* Its title shows the heading being read, taken from md:toc-change events.
|
|
47
|
+
*/
|
|
48
|
+
export declare function attachAside(aside: HTMLDetailsElement): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Fills a Search.Shortcut with the shortcut of the trigger around it, one nested `<kbd>` per key as HTML suggests for key combinations.
|
|
51
|
+
* Keys follow the platform: ⌘ and other symbols on Apple platforms, Ctrl and other names elsewhere. Each carries `data-key` for styling.
|
|
52
|
+
* Without a shortcut it hides. Runs inline right after it, before the first paint, so it must not reference anything outside itself.
|
|
53
|
+
*/
|
|
54
|
+
export declare function restoreShortcut(kbd: HTMLElement): void;
|
|
55
|
+
/** What a search panel shows: nothing typed, a first query on its way, or the outcome of the latest one. */
|
|
56
|
+
export type SearchStatus = 'idle' | 'loading' | 'found' | 'empty' | 'error';
|
|
57
|
+
export interface SearchContext {
|
|
58
|
+
/** Aborted once a newer query starts. */
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
/** Values of the named controls inside the root, e.g. filters. */
|
|
61
|
+
params: URLSearchParams;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Runs a query on any engine. Results can have any shape, since only `render` reads them.
|
|
65
|
+
* It also runs with an empty query, e.g. to suggest recent pages; returning nothing then leaves Search.Idle on show.
|
|
66
|
+
*/
|
|
67
|
+
export type SearchSource<T> = (query: string, context: SearchContext) => T[] | Promise<T[]>;
|
|
68
|
+
/** Renders results into the container with any renderer. Options are the elements with `role="option"`. */
|
|
69
|
+
export type SearchRender<T> = (results: T[], container: HTMLElement, context: {
|
|
70
|
+
query: string;
|
|
71
|
+
}) => void;
|
|
72
|
+
export interface SearchOptions<T> {
|
|
73
|
+
source: SearchSource<T>;
|
|
74
|
+
render: SearchRender<T>;
|
|
75
|
+
/** Milliseconds to wait after the last keystroke before searching. */
|
|
76
|
+
debounce?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface SearchSelectDetail {
|
|
79
|
+
/** The option that was followed, by click or Enter. */
|
|
80
|
+
option: HTMLElement;
|
|
81
|
+
query: string;
|
|
82
|
+
}
|
|
83
|
+
export interface SearchErrorDetail {
|
|
84
|
+
/** What the source threw. */
|
|
85
|
+
error: unknown;
|
|
86
|
+
query: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Runs the search inside a Search.Root: queries, states, keyboard navigation, the dialog and the triggers that point to it.
|
|
90
|
+
* It never changes what `render` puts in the results container; it only reads the options there.
|
|
91
|
+
* The root dispatches bubbling `md:search-open`, `md:search-close`, `md:search-select` and `md:search-error` events.
|
|
92
|
+
*/
|
|
93
|
+
export declare function attachSearch<T>(root: HTMLElement, { source, render, debounce }: SearchOptions<T>): () => void;
|
|
94
|
+
/** A piece of highlighted text from a search engine, marked when it matched the query. */
|
|
95
|
+
export interface MarkedText {
|
|
96
|
+
text: string;
|
|
97
|
+
marked: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Splits HTML such as an excerpt from Pagefind into plain and `<mark>`ed pieces, so any renderer can show it safely.
|
|
101
|
+
* Every other tag is dropped and only its text is kept.
|
|
102
|
+
*/
|
|
103
|
+
export declare function splitMarks(html: string): MarkedText[];
|
|
104
|
+
declare global {
|
|
105
|
+
interface HTMLElementEventMap {
|
|
106
|
+
'md:sidebar-toggle': CustomEvent<SidebarToggleDetail>;
|
|
107
|
+
'md:toc-change': CustomEvent<TocChangeDetail>;
|
|
108
|
+
'md:search-open': CustomEvent<null>;
|
|
109
|
+
'md:search-close': CustomEvent<null>;
|
|
110
|
+
'md:search-select': CustomEvent<SearchSelectDetail>;
|
|
111
|
+
'md:search-error': CustomEvent<SearchErrorDetail>;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|