@mirrordown/sat-file-tree 0.1.0 → 0.2.1

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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+
4
+
5
+ ## 0.2.1
6
+ <sub>2026-11-17</sub>
7
+
8
+ - *(patch)*
9
+ Fixes for a file name that made a tree fail to render, and for the tree's reading speed and client script.
10
+
11
+ - **A file named `constructor` renders** (all engines).
12
+
13
+ ````markdown
14
+ ```filetree
15
+ src/
16
+ constructor
17
+ toString
18
+ ```
19
+ ````
20
+
21
+ Was a `TypeError` that failed the whole document. Now a tree with both files, each with the icon of an unknown file. The same goes for `__proto__`, `valueOf`, `hasOwnProperty` and a name ending in `.constructor`.
22
+
23
+ - **A very long line is read in time proportional to its length** (all engines). A row of a few tens of thousands of characters took seconds to read; the rows read are the same.
24
+
25
+ - **The client script gives a tree one set of listeners however many times it is loaded** (all engines). Loaded twice, one key press acted twice: `→` on a closed folder opened it and moved into it.
26
+
27
+ The guide now says that a comment after a placeholder row is dropped and that a longer built-in icon match wins over a custom extension icon.
28
+
29
+ ## 0.2.0
30
+ <sub>2026-11-11</sub>
31
+
32
+ - *(minor)*
33
+ Require Sätteri 0.11.3 or later, which Astro ships from 7.4.7 (`@astrojs/markdown-satteri` 0.4.7). The plugins now read the document's features from Sätteri itself, so in Astro `satteriRuby()` needs no `features` passed to it, and tabs and steps no longer allow for a Sätteri that passes none. On Astro 7.4.6 or earlier, update Astro first.
34
+
3
35
  ## 0.1.0
4
36
  <sub>2026-11-03</sub>
5
37
 
package/README.md CHANGED
@@ -76,7 +76,7 @@ node_modules/…
76
76
 
77
77
  ### Comments, highlights and placeholders
78
78
 
79
- After a name, ` # ` or ` // ` starts a comment. `**name**` highlights a row. A row of `...` or `…` stands for entries left out.
79
+ After a name, ` # ` or ` // ` starts a comment. `**name**` highlights a row. A row of `...` or `…` stands for entries left out; a comment written after one is dropped.
80
80
 
81
81
  ````markdown
82
82
  ```filetree
@@ -141,7 +141,7 @@ export default defineConfig({
141
141
 
142
142
  ## The client script
143
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.
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 (a second copy leaves the trees the first one set up as they are), 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
145
 
146
146
  ```ts
147
147
  import "@mirrordown/remd-file-tree/client";
@@ -163,7 +163,7 @@ satteriFileTree({ theme: githubDark })
163
163
 
164
164
  ### Icons
165
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`.
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). A longer match of Seti's still wins: with your own `ts` icon, `a.test.ts` keeps Seti's icon for `test.ts`. The stylesheet sizes them to `1rem` and fills them with `currentColor`.
167
167
 
168
168
  ```ts
169
169
  satteriFileTree({ icons: { extensions: { astro: `<svg viewBox="0 0 24 24">...</svg>` } } })
package/dist/client.mjs CHANGED
@@ -3,7 +3,7 @@ const TREE = `.markdown-file-tree`;
3
3
  const ITEM = `[role="treeitem"]`;
4
4
  const ROW = `.markdown-file-tree-row`;
5
5
  const NAME = `.markdown-file-tree-name`;
6
- const upgraded = /* @__PURE__ */ new WeakSet();
6
+ const UPGRADED = Symbol.for(`mirrordown.file-tree`);
7
7
  const itemOf = (entry) => entry?.querySelector(`:scope > details`) ?? (entry instanceof HTMLElement ? entry : null);
8
8
  const isFolder = (item) => item instanceof HTMLDetailsElement;
9
9
  const isShown = (tree, item) => {
@@ -96,8 +96,9 @@ const label = (tree) => {
96
96
  }
97
97
  };
98
98
  const upgrade = (tree) => {
99
- if (upgraded.has(tree)) return;
100
- upgraded.add(tree);
99
+ const marked = tree;
100
+ if (marked[UPGRADED]) return;
101
+ marked[UPGRADED] = true;
101
102
  tree.setAttribute(`role`, `tree`);
102
103
  if (!tree.hasAttribute(`aria-label`) && !tree.hasAttribute(`aria-labelledby`)) tree.setAttribute(`aria-label`, `Files`);
103
104
  label(tree);
@@ -1 +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,iBAA8B,IAAI,CAAC,CAAC,CAAC,QAAQ,SACpD,QAAQ,MAAM,IAAI,CACpB;AAEF,MAAM,SAAS,MAAe,SAA+C;CAC3E,IAAI,CAAC,MAAM;CACX,KAAK,MAAM,SAAS,KAAK,iBACvB,GAAG,KAAK,eACV,GACE,MAAM,WAAW;CACnB,KAAK,WAAW;CAChB,KAAK,MAAM;AACb;AAGA,IAAI,QAAQ;AACZ,IAAI,UAAU;AAEd,MAAM,SAAS,MAAmB,UAA+B;CAC/D,MAAM,OACJ,MAAM,kBAAkB,UACpB,MAAM,OAAO,QAAq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C,IAAI,SAAS,IAAI,IAAI,GAAG;CACxB,SAAS,IAAI,IAAI;CACjB,KAAK,aAAa,QAAQ,MAAM;CAChC,IAAI,CAAC,KAAK,aAAa,YAAY,KAAK,CAAC,KAAK,aAAa,iBAAiB,GAC1E,KAAK,aAAa,cAAc,OAAO;CACzC,MAAM,IAAI;CACV,KAAK,iBAAiB,YAAY,UAAU,MAAM,MAAM,KAAK,CAAC;CAE9D,KAAK,iBAAiB,UAAU,UAAU;EACxC,MAAM,OACJ,MAAM,kBAAkB,UACpB,MAAM,OAAO,QAAqB,IAAI,IACtC;EACN,IAAI,QAAQ,KAAK,SAAS,IAAI,GAAG,MAAM,MAAM,IAAI;CACnD,CAAC;CAED,KAAK,iBACH,WACC,UAAU;EACT,MAAM,SAAS,MAAM;EACrB,IAAI,EAAE,kBAAkB,uBAAuB,CAAC,KAAK,SAAS,MAAM,GAClE;EACF,OAAO,aAAa,iBAAiB,OAAO,OAAO,IAAI,CAAC;EAExD,MAAM,SAAS,SAAS;EACxB,IAAI,CAAC,OAAO,QAAQ,WAAW,UAAU,OAAO,SAAS,MAAM,GAC7D,MAAM,MAAM,MAAM;CACtB,GACA,EAAE,SAAS,KAAK,CAClB;AACF;AAEA,MAAM,cAAc,SAA2B;CAC7C,KAAK,MAAM,QAAQ,KAAK,iBAA8B,IAAI,GAAG,QAAQ,IAAI;AAC3E;AAEA,WAAW,QAAQ;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"}
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\n// Set on each tree once it is upgraded. On the element, not in this module: a page can load the script twice (from two of the packages, a bundler's duplicate, a dev server's reload), and a second copy must not give a tree a second set of listeners, where one key press would act twice.\nconst UPGRADED = Symbol.for(`mirrordown.file-tree`);\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 const marked: HTMLElement & { [UPGRADED]?: true } = tree;\n if (marked[UPGRADED]) return;\n marked[UPGRADED] = true;\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;AAGb,MAAM,WAAW,OAAO,IAAI,sBAAsB;AAGlD,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,iBAA8B,IAAI,CAAC,CAAC,CAAC,QAAQ,SACpD,QAAQ,MAAM,IAAI,CACpB;AAEF,MAAM,SAAS,MAAe,SAA+C;CAC3E,IAAI,CAAC,MAAM;CACX,KAAK,MAAM,SAAS,KAAK,iBACvB,GAAG,KAAK,eACV,GACE,MAAM,WAAW;CACnB,KAAK,WAAW;CAChB,KAAK,MAAM;AACb;AAGA,IAAI,QAAQ;AACZ,IAAI,UAAU;AAEd,MAAM,SAAS,MAAmB,UAA+B;CAC/D,MAAM,OACJ,MAAM,kBAAkB,UACpB,MAAM,OAAO,QAAqB,IAAI,IACtC;CACN,IAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,IAAI,GAAG;CACnC,MAAM,QAAQ,QAAQ,IAAI;CAC1B,MAAM,QAAQ,MAAM,QAAQ,IAAI;CAChC,MAAM,SAAS,SAAS,IAAI,IAAI,OAAO;CACvC,MAAM,MAAM,iBAAiB,IAAI,CAAC,CAAC,cAAc;CAOjD,QALE,OAAO,MAAM,QAAQ,cACjB,eACA,OAAO,MAAM,QAAQ,eACnB,cACA,MAAM,KACd;EACE,KAAK;GACH,MAAM,MAAM,MAAM,QAAQ,EAAE;GAC5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N,IAAI,QAAQ,KAAK,SAAS,IAAI,GAAG,MAAM,MAAM,IAAI;CACnD,CAAC;CAED,KAAK,iBACH,WACC,UAAU;EACT,MAAM,SAAS,MAAM;EACrB,IAAI,EAAE,kBAAkB,uBAAuB,CAAC,KAAK,SAAS,MAAM,GAClE;EACF,OAAO,aAAa,iBAAiB,OAAO,OAAO,IAAI,CAAC;EAExD,MAAM,SAAS,SAAS;EACxB,IAAI,CAAC,OAAO,QAAQ,WAAW,UAAU,OAAO,SAAS,MAAM,GAC7D,MAAM,MAAM,MAAM;CACtB,GACA,EAAE,SAAS,KAAK,CAClB;AACF;AAEA,MAAM,cAAc,SAA2B;CAC7C,KAAK,MAAM,QAAQ,KAAK,iBAA8B,IAAI,GAAG,QAAQ,IAAI;AAC3E;AAEA,WAAW,QAAQ;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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mirrordown/sat-file-tree",
3
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",
4
+ "version": "0.2.1",
5
5
  "license": "MIT",
6
6
  "author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
7
7
  "repository": {
@@ -26,13 +26,13 @@
26
26
  "./*.css": "./dist/*.css"
27
27
  },
28
28
  "dependencies": {
29
- "@mirrordown/core": "^0.1.4"
29
+ "@mirrordown/core": "^0.2.0"
30
30
  },
31
31
  "devDependencies": {
32
- "satteri": "^0.11.5"
32
+ "satteri": "^0.11.6"
33
33
  },
34
34
  "peerDependencies": {
35
- "satteri": "^0.10.5 || ^0.11.0"
35
+ "satteri": "^0.11.3"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=24.0.0"