@mirrordown/sat-file-tree 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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+ <sub>2026-11-03</sub>
5
+
6
+ - *(minor)*
7
+ Add the file-tree plugin set, a port of Vocs' File Tree that degrades gracefully: a ` ```filetree ` fence renders as a file tree laid out like VS Code's explorer, and stays a readable code block where the plugin isn't installed, such as on GitHub. Rows nest by indentation, or by the branches the `tree` command draws (Unicode or `--charset=ascii`), or by list markers. `name/` marks a folder and `name/…` one that starts closed; `#` or `//` starts a comment, `**name**` highlights a row, and `[A]` `[M]` `[D]` `[R]` `[U]` `[I]` mark git status. Files get Seti UI's icons and colors as inline SVG, which the `icons` option adds to or replaces. The `theme` option takes a Shiki or VS Code theme, or a light and dark pair, so trees match the code blocks around them; each color can also be set with a `--markdown-file-tree-*` custom property, and a color left out or given an invalid value falls back on its own. Each folder is a `<details>`, so trees open and close without JavaScript, and folder rows stick to the page as their contents scroll past; the optional client script makes each tree an ARIA tree, navigated with the arrow keys. The Markdown File Tree VS Code extension renders trees in the preview in the editor's theme. The markdown-it, remark and Sätteri plugins emit identical HTML.
package/README.md CHANGED
@@ -1,3 +1,248 @@
1
- # Temporary Holding Version
1
+ # @mirrordown/sat-file-tree
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
4
+
5
+ A Sätteri plugin for the `file-tree` syntax extension.
6
+
7
+ ## Overview
8
+
9
+ The `file-tree` plugin turns a ` ```filetree ` code fence into a file tree, laid out like VS Code's explorer: icons from [Seti](https://github.com/jesseweed/seti-ui), folders that open and close, comments, highlighted rows and git status. Where the plugin isn't installed, such as on GitHub, the fence stays a code block, and still reads as a tree.
10
+
11
+ ````markdown
12
+ ```filetree
13
+ .
14
+ ├── src/
15
+ │ ├── components/
16
+ │ │ ├── Button.tsx [A] # new
17
+ │ │ └── Card.tsx
18
+ │ ├── **index.ts** [M] # the entry point
19
+ │ └── styles.css
20
+ ├── node_modules/…
21
+ ├── package.json
22
+ ├── README.md
23
+ └── vite.config.ts
24
+
25
+ 3 directories, 6 files
26
+ ```
27
+ ````
28
+
29
+ Each folder is a `<details>`, so the tree opens and closes without JavaScript, by mouse, keyboard and screen reader. An optional client script makes it an ARIA tree, navigated with the arrow keys.
30
+
31
+ ## Syntax
32
+
33
+ Write one name per line. A row goes inside the nearest row above it whose name starts further left, so indent however you like:
34
+
35
+ ````markdown
36
+ ```filetree
37
+ docs/
38
+ guide/
39
+ getting-started.md
40
+ plugins.md
41
+ index.md
42
+ package.json
43
+ ```
44
+ ````
45
+
46
+ Or paste what the `tree` command prints. Its branches, with `--charset=ascii` or without, are read as indentation, and its first line (`.`) and its count at the end are left out. List markers (`-`, `*`) are fine too.
47
+
48
+ ````markdown
49
+ ```filetree
50
+ .
51
+ |-- docs/
52
+ | |-- guide/
53
+ | | |-- getting-started.md
54
+ | | `-- plugins.md
55
+ | `-- index.md
56
+ `-- package.json
57
+
58
+ 2 directories, 4 files
59
+ ```
60
+ ````
61
+
62
+ ### Folders
63
+
64
+ A row with rows inside it is a folder, and so is a row ending in `/`, which marks an empty one. A folder ending in `/…` (or `/...`) starts closed; one with nothing listed inside shows `…` when opened. A row can be a path, such as `src/lib/utils.ts`, for folders that hold only one thing.
65
+
66
+ ````markdown
67
+ ```filetree
68
+ src/lib/utils.ts
69
+ public/
70
+ dist/…
71
+ index.js
72
+ index.d.ts
73
+ node_modules/…
74
+ ```
75
+ ````
76
+
77
+ ### Comments, highlights and placeholders
78
+
79
+ After a name, ` # ` or ` // ` starts a comment. `**name**` highlights a row. A row of `...` or `…` stands for entries left out.
80
+
81
+ ````markdown
82
+ ```filetree
83
+ src/
84
+ **index.ts** # start here
85
+ router.ts // maps URLs to pages
86
+ ...
87
+ ```
88
+ ````
89
+
90
+ ### Git status
91
+
92
+ A row's git status goes in brackets after its name, before any comment, with `git status`'s letters: `[A]` added, `[M]` modified, `[D]` deleted, `[R]` renamed, `[U]` untracked and `[I]` ignored. As in VS Code, the row takes the status's color with its letter at the end, and a folder holding changes gets a dot.
93
+
94
+ ````markdown
95
+ ```filetree
96
+ src/
97
+ cache.ts [A] # new
98
+ index.ts [M]
99
+ legacy.ts [D]
100
+ router.ts [R]
101
+ scratch.ts [U]
102
+ .env [I]
103
+ ```
104
+ ````
105
+
106
+ ### Icons
107
+
108
+ Each file gets its icon and color from Seti's table, by its name (`README.md`, `Dockerfile`), its extension, or part of its name, as VS Code's Seti theme does.
109
+
110
+ ````markdown
111
+ ```filetree
112
+ .github/
113
+ Dockerfile
114
+ README.md
115
+ LICENSE
116
+ astro.config.mjs
117
+ index.html
118
+ main.go
119
+ lib.rs
120
+ app.py
121
+ logo.svg
122
+ photo.png
123
+ data.csv
124
+ archive.zip
125
+ tsconfig.json
126
+ vite.config.ts
127
+ yarn.lock
128
+ ```
129
+ ````
130
+
131
+ Hosts that highlight code before your plugins run, such as Astro with Shiki, must leave `filetree` fences alone:
132
+
133
+ ```ts
134
+ // astro.config.ts
135
+ export default defineConfig({
136
+ markdown: {
137
+ syntaxHighlight: { type: "shiki", excludeLangs: ["filetree"] },
138
+ },
139
+ });
140
+ ```
141
+
142
+ ## The client script
143
+
144
+ Without it, a tree is nested lists, and its folders open and close as `<details>` do. Import it once per page, from the package for your engine, to make each tree an [ARIA tree](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/): one tab stop, ↑ and ↓ between rows, → and ← to open and close folders or move into and out of them, Home and End, `*` to open a folder's siblings, and typing a name's first letters to jump to it.
145
+
146
+ ```ts
147
+ import "@mirrordown/remd-file-tree/client";
148
+ ```
149
+
150
+ ## Configuration
151
+
152
+ All options are passed when registering the plugin, or as the presets' `fileTree` option.
153
+
154
+ ### Theme
155
+
156
+ `theme` takes a Shiki or VS Code theme, so trees match your code blocks: their background and text from the editor's colors, rows and git colors from the explorer's, and comments from the theme's comment color. Pass a light and a dark theme, as Shiki's `themes` takes them, to follow the page's `color-scheme`. Without a theme, the stylesheet's own colors apply. In VSCode's Markdown preview, with the Markdown File Tree extension, trees take the editor's theme on their own.
157
+
158
+ ```ts
159
+ import githubDark from "@shikijs/themes/github-dark";
160
+
161
+ satteriFileTree({ theme: githubDark })
162
+ ```
163
+
164
+ ### Icons
165
+
166
+ `icons` sets icons, as SVG markup, used before Seti's: `folder` for every folder, `file` for files nothing else matches, and `names` and `extensions` for files by name and extension (without its dot). The stylesheet sizes them to `1rem` and fills them with `currentColor`.
167
+
168
+ ```ts
169
+ satteriFileTree({ icons: { extensions: { astro: `<svg viewBox="0 0 24 24">...</svg>` } } })
170
+ ```
171
+
172
+ ## Accessibility
173
+
174
+ Without the client script, a tree is nested lists: screen readers announce each list's size and each row's place in it, and each folder's row is a `<summary>`, announced as expanded or collapsed. Icons are `aria-hidden`. With the script, the tree is an ARIA tree: the folder rows' `<summary>` elements leave the tab order, and each item announces its level, its place among its siblings and, for a folder, whether it's open. The tree is labeled "Files"; give it your own label with an attribute block on the fence, such as `{aria-label="Project files"}`.
175
+
176
+ ## Customization
177
+
178
+ The stylesheet keeps its rules in `@layer markdown-file-tree`, so any unlayered CSS you write overrides them. Each color comes from, in order: a custom property you set on the tree or any ancestor, the theme you passed, or the stylesheet's default. Each color falls back on its own, so you can set only some, and a value that isn't a color is ignored: the color falls back as if it weren't set. Colors can be written in any CSS notation, `oklch()` included, in your custom properties and in a theme alike.
179
+
180
+ ```css
181
+ .content {
182
+ --markdown-file-tree-background: oklch(0.2 0 none);
183
+ --markdown-file-tree-hover: oklch(0.6 0.15 250 / 0.15);
184
+ --markdown-file-tree-modified: oklch(0.75 0.12 80);
185
+ }
186
+ ```
187
+
188
+ The colors are `background`, `foreground`, `hover`, `highlight`, `highlight-foreground`, `guide`, `comment`, `focus`, and the git colors `added`, `modified`, `deleted`, `renamed`, `untracked` and `ignored`. Seti's icon colors are `--markdown-file-tree-blue`, `-green`, `-orange`, `-pink`, `-purple`, `-red`, `-yellow`, `-grey`, `-grey-light`, `-white`, `-ignore` and `-seti-primary`.
189
+
190
+ A folder's row sticks to the top of the page while its contents scroll past, under its parent folders' rows. If your page has a fixed header, set `--markdown-file-tree-sticky-offset` to its height, so the rows stick below it.
191
+
192
+ ## Install
193
+
194
+ ```sh
195
+ npm install @mirrordown/sat-file-tree
196
+ ```
197
+
198
+ List it before copy-code.
199
+
200
+ ### Standalone
201
+
202
+ ```ts
203
+ import { markdownToHtml } from "satteri";
204
+ import { satteriFileTree } from "@mirrordown/sat-file-tree";
205
+
206
+ const { html } = markdownToHtml(source, {
207
+ hastPlugins: [satteriFileTree()],
208
+ });
209
+
210
+ // In the page:
211
+ import "@mirrordown/sat-file-tree/file-tree.css";
212
+ import "@mirrordown/sat-file-tree/client";
213
+ ```
214
+
215
+ ### Astro
216
+
217
+ ```ts
218
+ // astro.config.ts
219
+ import { defineConfig } from "astro/config";
220
+ import { satteri } from "@astrojs/markdown-satteri";
221
+ import { satteriFileTree } from "@mirrordown/sat-file-tree";
222
+
223
+ export default defineConfig({
224
+ markdown: {
225
+ syntaxHighlight: { type: "shiki", excludeLangs: ["filetree"] },
226
+ processor: satteri({ hastPlugins: [satteriFileTree()] }),
227
+ },
228
+ });
229
+ ```
230
+
231
+ ```astro
232
+ ---
233
+ // In your layout:
234
+ import "@mirrordown/sat-file-tree/file-tree.css";
235
+ ---
236
+
237
+ <script>
238
+ import "@mirrordown/sat-file-tree/client";
239
+ </script>
240
+ ```
241
+
242
+ ## Documentation
243
+
244
+ Full documentation, more examples, and configuration options: [github.com/mirrordown/mirrordown](https://github.com/mirrordown/mirrordown) (dedicated docs site coming soon).
245
+
246
+ ## License
247
+
248
+ MIT © [Drake Costa](https://saeris.gg)
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,132 @@
1
+ // src/client.ts
2
+ const TREE = `.markdown-file-tree`;
3
+ const ITEM = `[role="treeitem"]`;
4
+ const ROW = `.markdown-file-tree-row`;
5
+ const NAME = `.markdown-file-tree-name`;
6
+ const upgraded = /* @__PURE__ */ new WeakSet();
7
+ const itemOf = (entry) => entry?.querySelector(`:scope > details`) ?? (entry instanceof HTMLElement ? entry : null);
8
+ const isFolder = (item) => item instanceof HTMLDetailsElement;
9
+ const isShown = (tree, item) => {
10
+ const closed = item.parentElement?.closest(`details:not([open])`);
11
+ return !closed || !tree.contains(closed);
12
+ };
13
+ const itemsOf = (tree) => [...tree.querySelectorAll(ITEM)].filter((item) => isShown(tree, item));
14
+ const focus = (tree, item) => {
15
+ if (!item) return;
16
+ for (const other of tree.querySelectorAll(`${ITEM}[tabindex="0"]`)) other.tabIndex = -1;
17
+ item.tabIndex = 0;
18
+ item.focus();
19
+ };
20
+ let typed = ``;
21
+ let typedAt = 0;
22
+ const onKey = (tree, event) => {
23
+ const item = event.target instanceof Element ? event.target.closest(ITEM) : null;
24
+ if (!item || !tree.contains(item)) return;
25
+ const items = itemsOf(tree);
26
+ const index = items.indexOf(item);
27
+ const folder = isFolder(item) ? item : null;
28
+ const rtl = getComputedStyle(tree).direction === `rtl`;
29
+ switch (rtl && event.key === `ArrowLeft` ? `ArrowRight` : rtl && event.key === `ArrowRight` ? `ArrowLeft` : event.key) {
30
+ case `ArrowDown`:
31
+ focus(tree, items[index + 1]);
32
+ break;
33
+ case `ArrowUp`:
34
+ focus(tree, items[index - 1]);
35
+ break;
36
+ case `Home`:
37
+ focus(tree, items[0]);
38
+ break;
39
+ case `End`:
40
+ focus(tree, items.at(-1));
41
+ break;
42
+ case `ArrowRight`:
43
+ if (!folder) return;
44
+ if (folder.open) focus(tree, itemOf(folder.querySelector(`:scope > ul > li`)));
45
+ else folder.open = true;
46
+ break;
47
+ case `ArrowLeft`:
48
+ if (folder?.open) folder.open = false;
49
+ else focus(tree, item.parentElement?.closest(ITEM) ?? null);
50
+ break;
51
+ case `Enter`:
52
+ case ` `:
53
+ if (!folder) return;
54
+ folder.open = !folder.open;
55
+ break;
56
+ case `*`:
57
+ for (const sibling of item.closest(`li`)?.parentElement?.children ?? []) {
58
+ const siblingItem = itemOf(sibling);
59
+ if (siblingItem && isFolder(siblingItem)) siblingItem.open = true;
60
+ }
61
+ break;
62
+ default: {
63
+ if (event.key.length !== 1 || event.ctrlKey || event.metaKey) return;
64
+ const now = event.timeStamp;
65
+ typed = now - typedAt < 500 ? typed + event.key : event.key;
66
+ typedAt = now;
67
+ const search = typed.toLowerCase();
68
+ const matches = (candidate) => (candidate.querySelector(NAME)?.textContent ?? ``).toLowerCase().startsWith(search);
69
+ const start = typed.length > 1 ? index : index + 1;
70
+ const ordered = [...items.slice(start), ...items.slice(0, start)];
71
+ focus(tree, ordered.find(matches));
72
+ break;
73
+ }
74
+ }
75
+ event.preventDefault();
76
+ };
77
+ const label = (tree) => {
78
+ let first = true;
79
+ for (const entry of tree.querySelectorAll(`li`)) {
80
+ const item = itemOf(entry);
81
+ if (!item) continue;
82
+ item.setAttribute(`role`, `treeitem`);
83
+ item.tabIndex = first ? 0 : -1;
84
+ first = false;
85
+ item.setAttribute(`aria-level`, entry.dataset.depth ?? `1`);
86
+ const siblings = [...entry.parentElement?.children ?? []];
87
+ item.setAttribute(`aria-setsize`, String(siblings.length));
88
+ item.setAttribute(`aria-posinset`, String(siblings.indexOf(entry) + 1));
89
+ if (!isFolder(item)) continue;
90
+ entry.setAttribute(`role`, `none`);
91
+ item.setAttribute(`aria-expanded`, String(item.open));
92
+ const row = item.querySelector(`:scope > ${ROW}`);
93
+ item.setAttribute(`aria-label`, [...row?.children ?? []].map((part) => part.textContent.trim()).filter((text) => text !== ``).join(` `));
94
+ row?.setAttribute(`tabindex`, `-1`);
95
+ item.querySelector(`:scope > ul`)?.setAttribute(`role`, `group`);
96
+ }
97
+ };
98
+ const upgrade = (tree) => {
99
+ if (upgraded.has(tree)) return;
100
+ upgraded.add(tree);
101
+ tree.setAttribute(`role`, `tree`);
102
+ if (!tree.hasAttribute(`aria-label`) && !tree.hasAttribute(`aria-labelledby`)) tree.setAttribute(`aria-label`, `Files`);
103
+ label(tree);
104
+ tree.addEventListener(`keydown`, (event) => onKey(tree, event));
105
+ tree.addEventListener(`click`, (event) => {
106
+ const item = event.target instanceof Element ? event.target.closest(ITEM) : null;
107
+ if (item && tree.contains(item)) focus(tree, item);
108
+ });
109
+ tree.addEventListener(`toggle`, (event) => {
110
+ const folder = event.target;
111
+ if (!(folder instanceof HTMLDetailsElement) || !tree.contains(folder)) return;
112
+ folder.setAttribute(`aria-expanded`, String(folder.open));
113
+ const active = document.activeElement;
114
+ if (!folder.open && active !== folder && folder.contains(active)) focus(tree, folder);
115
+ }, { capture: true });
116
+ };
117
+ const upgradeAll = (root) => {
118
+ for (const tree of root.querySelectorAll(TREE)) upgrade(tree);
119
+ };
120
+ upgradeAll(document);
121
+ new MutationObserver((records) => {
122
+ for (const record of records) for (const node of record.addedNodes) if (node instanceof HTMLElement) {
123
+ if (node.matches(TREE)) upgrade(node);
124
+ else upgradeAll(node);
125
+ }
126
+ }).observe(document.documentElement, {
127
+ childList: true,
128
+ subtree: true
129
+ });
130
+ export {};
131
+
132
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["// The file trees' optional client script: import it once per page. Without it a tree is nested lists whose folders are <details>, which open and close by mouse, keyboard and screen reader. With it, each tree becomes an ARIA tree (https://www.w3.org/WAI/ARIA/apg/patterns/treeview/): one tab stop, the arrow keys to move between rows and open and close folders, Home and End, `*` to open a folder's siblings, and typing a name's first letters to jump to it. Trees that client-side navigation swaps in are upgraded too.\n//\n// A file's item is its <li>. A folder's is its <details>, since browsers keep a <details>'s own role even when told it has none: its <li> takes no role instead, and its <summary> leaves the tab order.\n\nconst TREE = `.markdown-file-tree`;\nconst ITEM = `[role=\"treeitem\"]`;\nconst ROW = `.markdown-file-tree-row`;\nconst NAME = `.markdown-file-tree-name`;\n\nconst upgraded = new WeakSet<Element>();\n\n// The item a row's <li> holds.\nconst itemOf = (entry: Element | null | undefined): HTMLElement | null =>\n entry?.querySelector<HTMLElement>(`:scope > details`) ??\n (entry instanceof HTMLElement ? entry : null);\n\nconst isFolder = (item: Element): item is HTMLDetailsElement =>\n item instanceof HTMLDetailsElement;\n\n// An item is shown when no folder it's in is closed.\nconst isShown = (tree: Element, item: HTMLElement): boolean => {\n const closed = item.parentElement?.closest(`details:not([open])`);\n return !closed || !tree.contains(closed);\n};\n\nconst itemsOf = (tree: Element): HTMLElement[] =>\n [...tree.querySelectorAll<HTMLElement>(ITEM)].filter((item) =>\n isShown(tree, item)\n );\n\nconst focus = (tree: Element, item: HTMLElement | null | undefined): void => {\n if (!item) return;\n for (const other of tree.querySelectorAll<HTMLElement>(\n `${ITEM}[tabindex=\"0\"]`\n ))\n other.tabIndex = -1;\n item.tabIndex = 0;\n item.focus();\n};\n\n// Typed letters within a moment of each other search together, as in the APG's example.\nlet typed = ``;\nlet typedAt = 0;\n\nconst onKey = (tree: HTMLElement, event: KeyboardEvent): void => {\n const item =\n event.target instanceof Element\n ? event.target.closest<HTMLElement>(ITEM)\n : null;\n if (!item || !tree.contains(item)) return;\n const items = itemsOf(tree);\n const index = items.indexOf(item);\n const folder = isFolder(item) ? item : null;\n const rtl = getComputedStyle(tree).direction === `rtl`;\n const key =\n rtl && event.key === `ArrowLeft`\n ? `ArrowRight`\n : rtl && event.key === `ArrowRight`\n ? `ArrowLeft`\n : event.key;\n switch (key) {\n case `ArrowDown`:\n focus(tree, items[index + 1]);\n break;\n case `ArrowUp`:\n focus(tree, items[index - 1]);\n break;\n case `Home`:\n focus(tree, items[0]);\n break;\n case `End`:\n focus(tree, items.at(-1));\n break;\n case `ArrowRight`:\n if (!folder) return;\n if (folder.open)\n focus(tree, itemOf(folder.querySelector(`:scope > ul > li`)));\n else folder.open = true;\n break;\n case `ArrowLeft`:\n if (folder?.open) folder.open = false;\n else focus(tree, item.parentElement?.closest<HTMLElement>(ITEM) ?? null);\n break;\n case `Enter`:\n case ` `:\n if (!folder) return;\n folder.open = !folder.open;\n break;\n case `*`:\n for (const sibling of item.closest(`li`)?.parentElement?.children ?? []) {\n const siblingItem = itemOf(sibling);\n if (siblingItem && isFolder(siblingItem)) siblingItem.open = true;\n }\n break;\n default: {\n if (event.key.length !== 1 || event.ctrlKey || event.metaKey) return;\n const now = event.timeStamp;\n typed = now - typedAt < 500 ? typed + event.key : event.key;\n typedAt = now;\n const search = typed.toLowerCase();\n const matches = (candidate: HTMLElement): boolean =>\n (candidate.querySelector(NAME)?.textContent ?? ``)\n .toLowerCase()\n .startsWith(search);\n // From the next item on, wrapping; a search still being typed may match the focused item.\n const start = typed.length > 1 ? index : index + 1;\n const ordered = [...items.slice(start), ...items.slice(0, start)];\n focus(tree, ordered.find(matches));\n break;\n }\n }\n event.preventDefault();\n};\n\nconst label = (tree: HTMLElement): void => {\n let first = true;\n for (const entry of tree.querySelectorAll<HTMLElement>(`li`)) {\n const item = itemOf(entry);\n if (!item) continue;\n item.setAttribute(`role`, `treeitem`);\n item.tabIndex = first ? 0 : -1;\n first = false;\n item.setAttribute(`aria-level`, entry.dataset.depth ?? `1`);\n const siblings = [...(entry.parentElement?.children ?? [])];\n item.setAttribute(`aria-setsize`, String(siblings.length));\n item.setAttribute(`aria-posinset`, String(siblings.indexOf(entry) + 1));\n if (!isFolder(item)) continue;\n entry.setAttribute(`role`, `none`);\n item.setAttribute(`aria-expanded`, String(item.open));\n // Named by its row alone: from its content, it would take its whole subtree's text.\n const row = item.querySelector(`:scope > ${ROW}`);\n item.setAttribute(\n `aria-label`,\n [...(row?.children ?? [])]\n .map((part) => part.textContent.trim())\n .filter((text) => text !== ``)\n .join(` `)\n );\n row?.setAttribute(`tabindex`, `-1`);\n item.querySelector(`:scope > ul`)?.setAttribute(`role`, `group`);\n }\n};\n\nconst upgrade = (tree: HTMLElement): void => {\n if (upgraded.has(tree)) return;\n upgraded.add(tree);\n tree.setAttribute(`role`, `tree`);\n if (!tree.hasAttribute(`aria-label`) && !tree.hasAttribute(`aria-labelledby`))\n tree.setAttribute(`aria-label`, `Files`);\n label(tree);\n tree.addEventListener(`keydown`, (event) => onKey(tree, event));\n // A click on a row makes its item the one focused.\n tree.addEventListener(`click`, (event) => {\n const item =\n event.target instanceof Element\n ? event.target.closest<HTMLElement>(ITEM)\n : null;\n if (item && tree.contains(item)) focus(tree, item);\n });\n // The toggle event doesn't bubble: catch it on its way down to each <details>.\n tree.addEventListener(\n `toggle`,\n (event) => {\n const folder = event.target;\n if (!(folder instanceof HTMLDetailsElement) || !tree.contains(folder))\n return;\n folder.setAttribute(`aria-expanded`, String(folder.open));\n // Focus inside a folder that closed moves to the folder.\n const active = document.activeElement;\n if (!folder.open && active !== folder && folder.contains(active))\n focus(tree, folder);\n },\n { capture: true }\n );\n};\n\nconst upgradeAll = (root: ParentNode): void => {\n for (const tree of root.querySelectorAll<HTMLElement>(TREE)) upgrade(tree);\n};\n\nupgradeAll(document);\nnew MutationObserver((records) => {\n for (const record of records)\n for (const node of record.addedNodes)\n if (node instanceof HTMLElement) {\n if (node.matches(TREE)) upgrade(node);\n else upgradeAll(node);\n }\n}).observe(document.documentElement, { childList: true, subtree: true });\n\n// A module, so its names stay out of the global scope.\nexport {};\n"],"mappings":";AAIA,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,MAAM;AACZ,MAAM,OAAO;AAEb,MAAM,2BAAW,IAAI,QAAiB;AAGtC,MAAM,UAAU,UACd,OAAO,cAA2B,kBAAkB,MACnD,iBAAiB,cAAc,QAAQ;AAE1C,MAAM,YAAY,SAChB,gBAAgB;AAGlB,MAAM,WAAW,MAAe,SAA+B;CAC7D,MAAM,SAAS,KAAK,eAAe,QAAQ,qBAAqB;CAChE,OAAO,CAAC,UAAU,CAAC,KAAK,SAAS,MAAM;AACzC;AAEA,MAAM,WAAW,SACf,CAAC,GAAG,KAAK,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;AACnB,IAAI,kBAAkB,YAAY;CAChC,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,QAAQ,OAAO,YACxB,IAAI,gBAAgB,aAAa;EAC/B,IAAI,KAAK,QAAQ,IAAI,GAAG,QAAQ,IAAI;OAC/B,WAAW,IAAI;CACtB;AACN,CAAC,CAAC,CAAC,QAAQ,SAAS,iBAAiB;CAAE,WAAW;CAAM,SAAS;AAAK,CAAC"}
@@ -0,0 +1,613 @@
1
+ /*
2
+ File tree — default stylesheet
3
+ ------------------------------
4
+ Its visual rules live inside @layer markdown-file-tree so any unlayered
5
+ consumer CSS overrides them without needing !important. The resets that
6
+ keep a page's list styles off the tree sit outside the layer, since a
7
+ page's unlayered CSS would beat them inside it.
8
+
9
+ A tree is a <ul class="markdown-file-tree"> of rows, laid out like VS Code's
10
+ explorer: rows of one height that span the tree, indented by depth, with a
11
+ chevron on each folder, indent guides, Seti's icons and colors, and git
12
+ status colors with the status's letter at the row's end. Each folder is a
13
+ <details>, so it opens and closes without a script; its row sticks to the
14
+ top of the page while its contents scroll past.
15
+
16
+ Each color comes from, in order: a public token set on the tree or any
17
+ ancestor (--markdown-file-tree-<name>), the Shiki theme the plugin was given
18
+ (--markdown-file-tree-theme-<name>, set on the tree), or the default here.
19
+ Each color falls back on its own, so a partial override keeps the rest, and
20
+ an invalid value is ignored rather than leaving that color unset.
21
+
22
+ .content { --markdown-file-tree-hover: oklch(0.6 0.15 250 / 0.15); }
23
+ */
24
+
25
+ /*
26
+ How an invalid value falls back: the tree holds each color's default in a
27
+ registered private property, and each row reads the public token, or else
28
+ the theme's, into it again. A registered color property given something
29
+ that isn't a color, or nothing, inherits instead, so the row keeps the
30
+ tree's default. (With var() alone, an invalid value would unset the color
31
+ it's used for.) An invalid public token gives the default, not the theme's
32
+ color: a fallback can only skip to the parent's value. The registrations
33
+ are global, so they're named after the plugin.
34
+ */
35
+ @property --_file-tree-background {
36
+ syntax: "<color>";
37
+ inherits: true;
38
+ initial-value: transparent;
39
+ }
40
+ @property --_file-tree-foreground {
41
+ syntax: "<color>";
42
+ inherits: true;
43
+ initial-value: transparent;
44
+ }
45
+ @property --_file-tree-hover {
46
+ syntax: "<color>";
47
+ inherits: true;
48
+ initial-value: transparent;
49
+ }
50
+ @property --_file-tree-highlight {
51
+ syntax: "<color>";
52
+ inherits: true;
53
+ initial-value: transparent;
54
+ }
55
+ @property --_file-tree-highlight-foreground {
56
+ syntax: "<color>";
57
+ inherits: true;
58
+ initial-value: transparent;
59
+ }
60
+ @property --_file-tree-guide {
61
+ syntax: "<color>";
62
+ inherits: true;
63
+ initial-value: transparent;
64
+ }
65
+ @property --_file-tree-comment {
66
+ syntax: "<color>";
67
+ inherits: true;
68
+ initial-value: transparent;
69
+ }
70
+ @property --_file-tree-focus {
71
+ syntax: "<color>";
72
+ inherits: true;
73
+ initial-value: transparent;
74
+ }
75
+ @property --_file-tree-added {
76
+ syntax: "<color>";
77
+ inherits: true;
78
+ initial-value: transparent;
79
+ }
80
+ @property --_file-tree-modified {
81
+ syntax: "<color>";
82
+ inherits: true;
83
+ initial-value: transparent;
84
+ }
85
+ @property --_file-tree-deleted {
86
+ syntax: "<color>";
87
+ inherits: true;
88
+ initial-value: transparent;
89
+ }
90
+ @property --_file-tree-renamed {
91
+ syntax: "<color>";
92
+ inherits: true;
93
+ initial-value: transparent;
94
+ }
95
+ @property --_file-tree-untracked {
96
+ syntax: "<color>";
97
+ inherits: true;
98
+ initial-value: transparent;
99
+ }
100
+ @property --_file-tree-ignored {
101
+ syntax: "<color>";
102
+ inherits: true;
103
+ initial-value: transparent;
104
+ }
105
+ @property --_file-tree-blue {
106
+ syntax: "<color>";
107
+ inherits: true;
108
+ initial-value: transparent;
109
+ }
110
+ @property --_file-tree-green {
111
+ syntax: "<color>";
112
+ inherits: true;
113
+ initial-value: transparent;
114
+ }
115
+ @property --_file-tree-orange {
116
+ syntax: "<color>";
117
+ inherits: true;
118
+ initial-value: transparent;
119
+ }
120
+ @property --_file-tree-pink {
121
+ syntax: "<color>";
122
+ inherits: true;
123
+ initial-value: transparent;
124
+ }
125
+ @property --_file-tree-purple {
126
+ syntax: "<color>";
127
+ inherits: true;
128
+ initial-value: transparent;
129
+ }
130
+ @property --_file-tree-red {
131
+ syntax: "<color>";
132
+ inherits: true;
133
+ initial-value: transparent;
134
+ }
135
+ @property --_file-tree-yellow {
136
+ syntax: "<color>";
137
+ inherits: true;
138
+ initial-value: transparent;
139
+ }
140
+ @property --_file-tree-grey {
141
+ syntax: "<color>";
142
+ inherits: true;
143
+ initial-value: transparent;
144
+ }
145
+ @property --_file-tree-grey-light {
146
+ syntax: "<color>";
147
+ inherits: true;
148
+ initial-value: transparent;
149
+ }
150
+ @property --_file-tree-white {
151
+ syntax: "<color>";
152
+ inherits: true;
153
+ initial-value: transparent;
154
+ }
155
+ @property --_file-tree-ignore {
156
+ syntax: "<color>";
157
+ inherits: true;
158
+ initial-value: transparent;
159
+ }
160
+ @property --_file-tree-seti-primary {
161
+ syntax: "<color>";
162
+ inherits: true;
163
+ initial-value: transparent;
164
+ }
165
+
166
+ /* Where stuck folder rows stop: below a page's fixed header, for one. Registered, so an invalid value is ignored. */
167
+ @property --markdown-file-tree-sticky-offset {
168
+ syntax: "<length-percentage>";
169
+ inherits: true;
170
+ initial-value: 0px;
171
+ }
172
+
173
+ /* Outside the layer, and specific enough to beat `.content ul li`: a page's own list styles, unlayered as prose styles usually are, would otherwise bullet, indent and space the tree's lists, and the rows would no longer span the tree. */
174
+ .markdown-file-tree[class] {
175
+ padding: 0.375rem 0;
176
+ list-style: none;
177
+ }
178
+
179
+ .markdown-file-tree details > ul,
180
+ .markdown-file-tree li[data-depth] {
181
+ margin: 0;
182
+ padding: 0;
183
+ line-height: inherit;
184
+ list-style: none;
185
+ }
186
+
187
+ @layer markdown-file-tree {
188
+ .markdown-file-tree {
189
+ /* The defaults: opaque, so a stuck folder row covers the rows scrolling under it. */
190
+ --_file-tree-background: color-mix(in oklch, Canvas, CanvasText 4%);
191
+ --_file-tree-foreground: CanvasText;
192
+ --_file-tree-hover: color-mix(in oklch, currentColor 8%, transparent);
193
+ --_file-tree-highlight: color-mix(in oklch, currentColor 14%, transparent);
194
+ --_file-tree-highlight-foreground: currentColor;
195
+ --_file-tree-guide: color-mix(in oklch, currentColor 20%, transparent);
196
+ --_file-tree-comment: color-mix(in oklch, currentColor 55%, transparent);
197
+ --_file-tree-focus: currentColor;
198
+ --_file-tree-added: light-dark(#587c0c, #81b88b);
199
+ --_file-tree-modified: light-dark(#895503, #e2c08d);
200
+ --_file-tree-deleted: light-dark(#ad0707, #c74e39);
201
+ --_file-tree-renamed: light-dark(#007100, #73c991);
202
+ --_file-tree-untracked: light-dark(#007100, #73c991);
203
+ --_file-tree-ignored: light-dark(#8e8e90, #8c8c8c);
204
+ /* Seti's colors, darkened a fifth on light pages, where Seti's own (made for dark ones) are faint. */
205
+ --_file-tree-blue: light-dark(
206
+ color-mix(in oklch, #519aba, black 20%),
207
+ #519aba
208
+ );
209
+ --_file-tree-green: light-dark(
210
+ color-mix(in oklch, #8dc149, black 20%),
211
+ #8dc149
212
+ );
213
+ --_file-tree-orange: light-dark(
214
+ color-mix(in oklch, #e37933, black 20%),
215
+ #e37933
216
+ );
217
+ --_file-tree-pink: light-dark(
218
+ color-mix(in oklch, #f55385, black 20%),
219
+ #f55385
220
+ );
221
+ --_file-tree-purple: light-dark(
222
+ color-mix(in oklch, #a074c4, black 20%),
223
+ #a074c4
224
+ );
225
+ --_file-tree-red: light-dark(
226
+ color-mix(in oklch, #cc3e44, black 20%),
227
+ #cc3e44
228
+ );
229
+ --_file-tree-yellow: light-dark(
230
+ color-mix(in oklch, #cbcb41, black 35%),
231
+ #cbcb41
232
+ );
233
+ --_file-tree-grey: light-dark(#4d5a5e, #6d8086);
234
+ --_file-tree-grey-light: light-dark(#4d5a5e, #6d8086);
235
+ --_file-tree-white: light-dark(#4d5a5e, #d4d7d6);
236
+ --_file-tree-ignore: light-dark(#6d8086, #41535b);
237
+ --_file-tree-seti-primary: light-dark(
238
+ color-mix(in oklch, #4d8eb5, black 20%),
239
+ #4d8eb5
240
+ );
241
+
242
+ --_file-tree-row: 1.625rem;
243
+ --_file-tree-indent: 1rem;
244
+ --_file-tree-gutter: 0.5rem;
245
+ --_file-tree-chevron: 1rem;
246
+ --_file-tree-depth: 0;
247
+
248
+ position: relative;
249
+ /* Its own stacking context, so the stuck rows stack among themselves and stay under a page's fixed header. */
250
+ isolation: isolate;
251
+ border-radius: 0.5rem;
252
+ color: var(--_file-tree-foreground);
253
+ font-size: 0.875rem;
254
+ line-height: var(--_file-tree-row);
255
+ /* Clipped rather than scrolled, so a folder's row sticks to the page as it scrolls. */
256
+ overflow-x: clip;
257
+
258
+ /* The tree's background, drawn by a pseudo-element, which reads the public tokens as a row does. ::after, since hosts mark blocks with ::before: VS Code's preview borders a hovered block's. */
259
+ &::after {
260
+ content: "";
261
+ position: absolute;
262
+ z-index: -1;
263
+ inset: 0;
264
+ border-radius: inherit;
265
+ background-color: var(--_file-tree-background);
266
+ }
267
+ }
268
+
269
+ /* The public tokens, then the theme's, read where they're used: a color unset or invalid in both keeps the tree's default. */
270
+ .markdown-file-tree li,
271
+ .markdown-file-tree::after {
272
+ --_file-tree-background: var(
273
+ --markdown-file-tree-background,
274
+ var(--markdown-file-tree-theme-background)
275
+ );
276
+ --_file-tree-foreground: var(
277
+ --markdown-file-tree-foreground,
278
+ var(--markdown-file-tree-theme-foreground)
279
+ );
280
+ --_file-tree-hover: var(
281
+ --markdown-file-tree-hover,
282
+ var(--markdown-file-tree-theme-hover)
283
+ );
284
+ --_file-tree-highlight: var(
285
+ --markdown-file-tree-highlight,
286
+ var(--markdown-file-tree-theme-highlight)
287
+ );
288
+ --_file-tree-highlight-foreground: var(
289
+ --markdown-file-tree-highlight-foreground,
290
+ var(--markdown-file-tree-theme-highlight-foreground)
291
+ );
292
+ --_file-tree-guide: var(
293
+ --markdown-file-tree-guide,
294
+ var(--markdown-file-tree-theme-guide)
295
+ );
296
+ --_file-tree-comment: var(
297
+ --markdown-file-tree-comment,
298
+ var(--markdown-file-tree-theme-comment)
299
+ );
300
+ --_file-tree-focus: var(
301
+ --markdown-file-tree-focus,
302
+ var(--markdown-file-tree-theme-focus)
303
+ );
304
+ --_file-tree-added: var(
305
+ --markdown-file-tree-added,
306
+ var(--markdown-file-tree-theme-added)
307
+ );
308
+ --_file-tree-modified: var(
309
+ --markdown-file-tree-modified,
310
+ var(--markdown-file-tree-theme-modified)
311
+ );
312
+ --_file-tree-deleted: var(
313
+ --markdown-file-tree-deleted,
314
+ var(--markdown-file-tree-theme-deleted)
315
+ );
316
+ --_file-tree-renamed: var(
317
+ --markdown-file-tree-renamed,
318
+ var(--markdown-file-tree-theme-renamed)
319
+ );
320
+ --_file-tree-untracked: var(
321
+ --markdown-file-tree-untracked,
322
+ var(--markdown-file-tree-theme-untracked)
323
+ );
324
+ --_file-tree-ignored: var(
325
+ --markdown-file-tree-ignored,
326
+ var(--markdown-file-tree-theme-ignored)
327
+ );
328
+ --_file-tree-blue: var(--markdown-file-tree-blue);
329
+ --_file-tree-green: var(--markdown-file-tree-green);
330
+ --_file-tree-orange: var(--markdown-file-tree-orange);
331
+ --_file-tree-pink: var(--markdown-file-tree-pink);
332
+ --_file-tree-purple: var(--markdown-file-tree-purple);
333
+ --_file-tree-red: var(--markdown-file-tree-red);
334
+ --_file-tree-yellow: var(--markdown-file-tree-yellow);
335
+ --_file-tree-grey: var(--markdown-file-tree-grey);
336
+ --_file-tree-grey-light: var(--markdown-file-tree-grey-light);
337
+ --_file-tree-white: var(--markdown-file-tree-white);
338
+ --_file-tree-ignore: var(--markdown-file-tree-ignore);
339
+ --_file-tree-seti-primary: var(--markdown-file-tree-seti-primary);
340
+
341
+ color: var(--_file-tree-foreground);
342
+ }
343
+
344
+ /* Each row's depth, from its data-depth; rows deeper than twelve keep the twelfth's. */
345
+ .markdown-file-tree [data-depth="2"] {
346
+ --_file-tree-depth: 1;
347
+ }
348
+ .markdown-file-tree [data-depth="3"] {
349
+ --_file-tree-depth: 2;
350
+ }
351
+ .markdown-file-tree [data-depth="4"] {
352
+ --_file-tree-depth: 3;
353
+ }
354
+ .markdown-file-tree [data-depth="5"] {
355
+ --_file-tree-depth: 4;
356
+ }
357
+ .markdown-file-tree [data-depth="6"] {
358
+ --_file-tree-depth: 5;
359
+ }
360
+ .markdown-file-tree [data-depth="7"] {
361
+ --_file-tree-depth: 6;
362
+ }
363
+ .markdown-file-tree [data-depth="8"] {
364
+ --_file-tree-depth: 7;
365
+ }
366
+ .markdown-file-tree [data-depth="9"] {
367
+ --_file-tree-depth: 8;
368
+ }
369
+ .markdown-file-tree [data-depth="10"] {
370
+ --_file-tree-depth: 9;
371
+ }
372
+ .markdown-file-tree [data-depth="11"] {
373
+ --_file-tree-depth: 10;
374
+ }
375
+ .markdown-file-tree [data-depth="12"] {
376
+ --_file-tree-depth: 11;
377
+ }
378
+
379
+ .markdown-file-tree-row {
380
+ display: flex;
381
+ align-items: center;
382
+ gap: 0.375rem;
383
+ block-size: var(--_file-tree-row);
384
+ /* Indented by depth, past the chevron's place, which files keep too so names line up. */
385
+ padding-inline: calc(
386
+ var(--_file-tree-gutter) + var(--_file-tree-depth) *
387
+ var(--_file-tree-indent) + var(--_file-tree-chevron) + 0.125rem
388
+ )
389
+ 0.75rem;
390
+ white-space: nowrap;
391
+
392
+ @media (hover: hover) and (pointer: fine) {
393
+ &:hover {
394
+ background-image: linear-gradient(var(--_file-tree-hover) 0 0);
395
+ }
396
+ }
397
+ }
398
+
399
+ /* A folder's row: its chevron, drawn in CSS so it turns as the folder opens. */
400
+ summary.markdown-file-tree-row {
401
+ position: sticky;
402
+ inset-block-start: calc(
403
+ var(--markdown-file-tree-sticky-offset) + var(--_file-tree-depth) *
404
+ var(--_file-tree-row)
405
+ );
406
+ z-index: calc(100 - var(--_file-tree-depth));
407
+ background-color: var(--_file-tree-background);
408
+ cursor: pointer;
409
+ list-style: none;
410
+
411
+ &::-webkit-details-marker {
412
+ display: none;
413
+ }
414
+
415
+ &::before {
416
+ content: "";
417
+ position: absolute;
418
+ inset-inline-start: calc(
419
+ var(--_file-tree-gutter) + var(--_file-tree-depth) *
420
+ var(--_file-tree-indent) + var(--_file-tree-chevron) / 2
421
+ );
422
+ inline-size: 0.375rem;
423
+ block-size: 0.375rem;
424
+ border-block-end: 1.5px solid currentColor;
425
+ border-inline-end: 1.5px solid currentColor;
426
+ opacity: 0.7;
427
+ translate: -50% 0;
428
+ rotate: -45deg;
429
+ }
430
+
431
+ &:dir(rtl)::before {
432
+ rotate: 135deg;
433
+ }
434
+
435
+ &:focus-visible {
436
+ outline: 1px solid var(--_file-tree-focus);
437
+ outline-offset: -1px;
438
+ }
439
+ }
440
+
441
+ details[open] > summary.markdown-file-tree-row::before {
442
+ translate: -50% -25%;
443
+ rotate: 45deg;
444
+ }
445
+
446
+ @media (prefers-reduced-motion: no-preference) {
447
+ summary.markdown-file-tree-row::before {
448
+ transition: rotate 0.1s ease-out;
449
+ }
450
+ }
451
+
452
+ /* Indent guides: a line down each open folder's contents, under its chevron, drawn over the rows' hover. */
453
+ .markdown-file-tree details > ul {
454
+ position: relative;
455
+
456
+ &::before {
457
+ content: "";
458
+ position: absolute;
459
+ z-index: 1;
460
+ inset-block: 0;
461
+ inset-inline-start: calc(
462
+ var(--_file-tree-gutter) + var(--_file-tree-depth) *
463
+ var(--_file-tree-indent) + var(--_file-tree-chevron) / 2
464
+ );
465
+ border-inline-start: 1px solid var(--_file-tree-guide);
466
+ pointer-events: none;
467
+ }
468
+ }
469
+
470
+ .markdown-file-tree-icon {
471
+ display: inline-flex;
472
+ flex: none;
473
+ inline-size: 1rem;
474
+ block-size: 1rem;
475
+ color: color-mix(in oklch, currentColor 70%, transparent);
476
+
477
+ > svg {
478
+ inline-size: 100%;
479
+ block-size: 100%;
480
+ fill: currentColor;
481
+ }
482
+ }
483
+
484
+ .markdown-file-tree-icon[data-color="blue"] {
485
+ color: var(--_file-tree-blue);
486
+ }
487
+ .markdown-file-tree-icon[data-color="green"] {
488
+ color: var(--_file-tree-green);
489
+ }
490
+ .markdown-file-tree-icon[data-color="orange"] {
491
+ color: var(--_file-tree-orange);
492
+ }
493
+ .markdown-file-tree-icon[data-color="pink"] {
494
+ color: var(--_file-tree-pink);
495
+ }
496
+ .markdown-file-tree-icon[data-color="purple"] {
497
+ color: var(--_file-tree-purple);
498
+ }
499
+ .markdown-file-tree-icon[data-color="red"] {
500
+ color: var(--_file-tree-red);
501
+ }
502
+ .markdown-file-tree-icon[data-color="yellow"] {
503
+ color: var(--_file-tree-yellow);
504
+ }
505
+ .markdown-file-tree-icon[data-color="grey"] {
506
+ color: var(--_file-tree-grey);
507
+ }
508
+ .markdown-file-tree-icon[data-color="grey-light"] {
509
+ color: var(--_file-tree-grey-light);
510
+ }
511
+ .markdown-file-tree-icon[data-color="white"] {
512
+ color: var(--_file-tree-white);
513
+ }
514
+ .markdown-file-tree-icon[data-color="ignore"] {
515
+ color: var(--_file-tree-ignore);
516
+ }
517
+ .markdown-file-tree-icon[data-color="seti-primary"] {
518
+ color: var(--_file-tree-seti-primary);
519
+ }
520
+
521
+ .markdown-file-tree-name {
522
+ overflow: clip;
523
+ text-overflow: ellipsis;
524
+ }
525
+
526
+ .markdown-file-tree-comment {
527
+ flex: 1;
528
+ min-inline-size: 0;
529
+ overflow: clip;
530
+ padding-inline-start: 0.5rem;
531
+ color: var(--_file-tree-comment);
532
+ text-overflow: ellipsis;
533
+ }
534
+
535
+ .markdown-file-tree-status {
536
+ flex: none;
537
+ margin-inline-start: auto;
538
+ padding-inline-start: 0.5rem;
539
+ font-size: 0.75rem;
540
+ font-weight: 600;
541
+ }
542
+
543
+ .markdown-file-tree-more > .markdown-file-tree-row {
544
+ color: var(--_file-tree-comment);
545
+ }
546
+
547
+ /* A highlighted row: written **name**. */
548
+ [data-highlight] > .markdown-file-tree-row,
549
+ [data-highlight] > details > .markdown-file-tree-row {
550
+ background-image: linear-gradient(var(--_file-tree-highlight) 0 0);
551
+ color: var(--_file-tree-highlight-foreground);
552
+ }
553
+
554
+ /* Git status: the name and letter in the status's color. */
555
+ .markdown-file-tree [data-status] {
556
+ --_file-tree-status: currentColor;
557
+ }
558
+ .markdown-file-tree [data-status="added"] {
559
+ --_file-tree-status: var(--_file-tree-added);
560
+ }
561
+ .markdown-file-tree [data-status="modified"] {
562
+ --_file-tree-status: var(--_file-tree-modified);
563
+ }
564
+ .markdown-file-tree [data-status="deleted"] {
565
+ --_file-tree-status: var(--_file-tree-deleted);
566
+ }
567
+ .markdown-file-tree [data-status="renamed"] {
568
+ --_file-tree-status: var(--_file-tree-renamed);
569
+ }
570
+ .markdown-file-tree [data-status="untracked"] {
571
+ --_file-tree-status: var(--_file-tree-untracked);
572
+ }
573
+ .markdown-file-tree [data-status="ignored"] {
574
+ --_file-tree-status: var(--_file-tree-ignored);
575
+ }
576
+
577
+ [data-status] > .markdown-file-tree-row,
578
+ [data-status] > details > .markdown-file-tree-row {
579
+ > .markdown-file-tree-name,
580
+ > .markdown-file-tree-status {
581
+ color: var(--_file-tree-status);
582
+ }
583
+ }
584
+
585
+ [data-status="deleted"] > .markdown-file-tree-row > .markdown-file-tree-name {
586
+ text-decoration: line-through;
587
+ }
588
+
589
+ /* A folder holding changes, as VS Code marks one: a dot at its row's end. */
590
+ .markdown-file-tree-folder:not([data-status]):has(
591
+ [data-status]:not([data-status="ignored"])
592
+ )
593
+ > details
594
+ > .markdown-file-tree-row::after {
595
+ content: "";
596
+ flex: none;
597
+ inline-size: 0.375rem;
598
+ block-size: 0.375rem;
599
+ margin-inline-start: auto;
600
+ border-radius: 50%;
601
+ background-color: color-mix(in oklch, currentColor 60%, transparent);
602
+ }
603
+
604
+ /* With the client script, the tree is an ARIA tree: focus moves between its items (a file's <li>, a folder's <details>), and shows on the focused item's row. */
605
+ .markdown-file-tree [role="treeitem"] {
606
+ outline: 2px solid transparent;
607
+
608
+ &:focus-visible > .markdown-file-tree-row {
609
+ outline: 1px solid var(--_file-tree-focus);
610
+ outline-offset: -1px;
611
+ }
612
+ }
613
+ }
@@ -0,0 +1,21 @@
1
+ import { FileTreeIconOptions, FileTreeOptions, FileTreeTheme } from "@mirrordown/core/file-tree";
2
+ import { HastVisitorInstance, PluginFactoryContext } from "satteri";
3
+ type ElementVisitor = Extract<NonNullable<HastVisitorInstance["element"]>, {
4
+ filter: string[];
5
+ }>;
6
+ /**
7
+ * The plugin's definition: only the keys it defines, with a synchronous visitor, so `markdownToHtml` returns its result directly.
8
+ */
9
+ export interface FileTreePlugin {
10
+ name: string;
11
+ element: {
12
+ filter: string[];
13
+ visit: (...args: Parameters<ElementVisitor["visit"]>) => void;
14
+ };
15
+ }
16
+ /**
17
+ * Sätteri plugin that renders ` ```filetree ` fences as file trees: a `<ul class="markdown-file-tree">` of rows, each folder a `<details>` whose `<summary>` is its row, with Seti icons, git status marks and comments. Rows nest by indentation or by the branches the `tree` command draws, so the fence reads as a tree where the plugin isn't installed. The tree replaces the `<pre>` as a `raw` node, so it reaches the HTML exactly as the markdown-it and rehype plugins write it; attributes on the fence (`{#id .class}`, with the `attributes` feature) go on the `<ul>`. Options set a Shiki theme to color the trees with and icons to use. List it before copy-code. The optional client script (`@mirrordown/sat-file-tree/client`) makes each tree an ARIA tree, navigated with the arrow keys. The tree is shared with the markdown-it and rehype plugins through `@mirrordown/core`.
18
+ */
19
+ export declare const satteriFileTree: (options?: FileTreeOptions) => ((ctx: PluginFactoryContext) => FileTreePlugin);
20
+ export type { FileTreeIconOptions, FileTreeOptions, FileTreeTheme };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;KAgBK,iBAAiB,QACpB,YAAY;EACV;;;;;iBAMa;EACf;EACA;IACE;IACA,WAAW,MAAM,WAAW;;;;;;qBAOnB,kBACX,UAAS,sBACN,KAAK,yBAAyB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { hastAttributes } from "@mirrordown/core";
2
+ import { createFileTree, fileTreeBlock } from "@mirrordown/core/file-tree";
3
+ import { defineHastPlugin } from "satteri";
4
+ // src/index.ts
5
+ /**
6
+ * Sätteri plugin that renders ` ```filetree ` fences as file trees: a `<ul class="markdown-file-tree">` of rows, each folder a `<details>` whose `<summary>` is its row, with Seti icons, git status marks and comments. Rows nest by indentation or by the branches the `tree` command draws, so the fence reads as a tree where the plugin isn't installed. The tree replaces the `<pre>` as a `raw` node, so it reaches the HTML exactly as the markdown-it and rehype plugins write it; attributes on the fence (`{#id .class}`, with the `attributes` feature) go on the `<ul>`. Options set a Shiki theme to color the trees with and icons to use. List it before copy-code. The optional client script (`@mirrordown/sat-file-tree/client`) makes each tree an ARIA tree, navigated with the arrow keys. The tree is shared with the markdown-it and rehype plugins through `@mirrordown/core`.
7
+ */
8
+ const satteriFileTree = (options = {}) => {
9
+ const render = createFileTree(options);
10
+ return () => defineHastPlugin({
11
+ name: `file-tree`,
12
+ element: {
13
+ filter: [`pre`],
14
+ visit(node, ctx) {
15
+ const block = fileTreeBlock(node);
16
+ if (!block) return;
17
+ const html = render(block.source, hastAttributes(block.element.properties));
18
+ if (html !== void 0) ctx.replaceNode(node, {
19
+ type: `raw`,
20
+ value: html
21
+ });
22
+ }
23
+ }
24
+ });
25
+ };
26
+ export { satteriFileTree };
27
+
28
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { hastAttributes } from \"@mirrordown/core\";\nimport {\n createFileTree,\n fileTreeBlock,\n type FileTreeIconOptions,\n type FileTreeOptions,\n type FileTreeTheme\n} from \"@mirrordown/core/file-tree\";\nimport {\n defineHastPlugin,\n type HastVisitorInstance,\n type PluginFactoryContext\n} from \"satteri\";\n\nexport type { FileTreeIconOptions, FileTreeOptions, FileTreeTheme };\n\ntype ElementVisitor = Extract<\n NonNullable<HastVisitorInstance[\"element\"]>,\n { filter: string[] }\n>;\n\n/**\n * The plugin's definition: only the keys it defines, with a synchronous visitor, so `markdownToHtml` returns its result directly.\n */\nexport interface FileTreePlugin {\n name: string;\n element: {\n filter: string[];\n visit: (...args: Parameters<ElementVisitor[\"visit\"]>) => void;\n };\n}\n\n/**\n * Sätteri plugin that renders ` ```filetree ` fences as file trees: a `<ul class=\"markdown-file-tree\">` of rows, each folder a `<details>` whose `<summary>` is its row, with Seti icons, git status marks and comments. Rows nest by indentation or by the branches the `tree` command draws, so the fence reads as a tree where the plugin isn't installed. The tree replaces the `<pre>` as a `raw` node, so it reaches the HTML exactly as the markdown-it and rehype plugins write it; attributes on the fence (`{#id .class}`, with the `attributes` feature) go on the `<ul>`. Options set a Shiki theme to color the trees with and icons to use. List it before copy-code. The optional client script (`@mirrordown/sat-file-tree/client`) makes each tree an ARIA tree, navigated with the arrow keys. The tree is shared with the markdown-it and rehype plugins through `@mirrordown/core`.\n */\nexport const satteriFileTree = (\n options: FileTreeOptions = {}\n): ((ctx: PluginFactoryContext) => FileTreePlugin) => {\n const render = createFileTree(options);\n return () =>\n defineHastPlugin({\n name: `file-tree`,\n element: {\n filter: [`pre`],\n visit(node, ctx) {\n const block = fileTreeBlock(node);\n if (!block) return;\n const html = render(\n block.source,\n hastAttributes(block.element.properties)\n );\n if (html !== undefined)\n ctx.replaceNode(node, { type: `raw`, value: html });\n }\n }\n });\n};\n"],"mappings":";;;;;;;AAmCA,MAAa,mBACX,UAA2B,CAAC,MACwB;CACpD,MAAM,SAAS,eAAe,OAAO;CACrC,aACE,iBAAiB;EACf,MAAM;EACN,SAAS;GACP,QAAQ,CAAC,KAAK;GACd,MAAM,MAAM,KAAK;IACf,MAAM,QAAQ,cAAc,IAAI;IAChC,IAAI,CAAC,OAAO;IACZ,MAAM,OAAO,OACX,MAAM,QACN,eAAe,MAAM,QAAQ,UAAU,CACzC;IACA,IAAI,SAAS,KAAA,GACX,IAAI,YAAY,MAAM;KAAE,MAAM;KAAO,OAAO;IAAK,CAAC;GACtD;EACF;CACF,CAAC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@mirrordown/sat-file-tree",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "A Sätteri plugin to render file trees from filetree code fences, with Seti icons, git status and collapsible folders, that read as plain text where the plugin is not installed.",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mirrordown/mirrordown.git"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "development": "./src/index.ts",
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs"
20
+ },
21
+ "./client": {
22
+ "development": "./src/client.ts",
23
+ "types": "./dist/client.d.mts",
24
+ "import": "./dist/client.mjs"
25
+ },
26
+ "./*.css": "./dist/*.css"
27
+ },
28
+ "dependencies": {
29
+ "@mirrordown/core": "^0.1.4"
30
+ },
31
+ "devDependencies": {
32
+ "satteri": "^0.11.5"
33
+ },
34
+ "peerDependencies": {
35
+ "satteri": "^0.10.5 || ^0.11.0"
36
+ },
37
+ "engines": {
38
+ "node": ">=24.0.0"
39
+ },
40
+ "bumpy": {
41
+ "publishCommand": [
42
+ "node ../../scripts/sync-jsr-version.mjs",
43
+ "node ../../scripts/npm-publish.mjs",
44
+ "node ../../scripts/jsr-resolve-deps.mjs",
45
+ "node ../../scripts/jsr-publish.mjs"
46
+ ]
47
+ }
6
48
  }