@zenera/view 0.0.0-stage → 1.1.27
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 +111 -2
- package/dist/client/app.css +1 -0
- package/dist/client/app.js +10 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.js +55 -0
- package/dist/render.d.ts +15 -0
- package/dist/render.js +372 -0
- package/dist/server.d.ts +30 -0
- package/dist/server.js +406 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +2 -0
- package/dist/watch.d.ts +13 -0
- package/dist/watch.js +110 -0
- package/package.json +61 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Ryabov
|
|
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,112 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/andreyryabov/ZeneraNeo/main/docs/imgs/banner-view-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/andreyryabov/ZeneraNeo/main/docs/imgs/banner-view-light.svg" alt="ZENERA VIEW" width="747">
|
|
5
|
+
</picture>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/@zenera/view)
|
|
8
|
+
[](https://github.com/andreyryabov/ZeneraNeo/blob/main/LICENSE)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
# @zenera/view
|
|
14
|
+
|
|
15
|
+
**A live local viewer for a folder. Markdown with tables and Mermaid diagrams,
|
|
16
|
+
highlighted code, directory listings - redrawn in place as the files change.**
|
|
17
|
+
|
|
18
|
+
> Part of [ZeneraNeo](https://github.com/andreyryabov/ZeneraNeo). It ships with
|
|
19
|
+
> [`zen`](https://github.com/andreyryabov/ZeneraNeo/blob/main/packages/cli/README.md)
|
|
20
|
+
> as the `view` **subcommand**, and works just as well as a library on its own.
|
|
21
|
+
|
|
22
|
+
## Why
|
|
23
|
+
|
|
24
|
+
Agents write reports, plans, traces and diagrams to disk, and keep rewriting
|
|
25
|
+
them while they work. `@zenera/view` turns that folder into a page you can leave
|
|
26
|
+
open: every change shows up within a second, with no reload, no lost scroll
|
|
27
|
+
position, and no flicker of diagrams that did not change.
|
|
28
|
+
|
|
29
|
+
- **Markdown as GitHub draws it** - GFM tables, task lists, heading anchors and
|
|
30
|
+
[Mermaid](https://mermaid.js.org) diagrams.
|
|
31
|
+
- **Highlighted code** - `.json`, `.jsonl`, `.py`, `.ts`, `.yaml`, `.patch` and more.
|
|
32
|
+
- **Directories as listings**, so the whole tree is navigable from one page.
|
|
33
|
+
- **Everything else as is** - images, HTML and PDF are handed to the browser.
|
|
34
|
+
- **Live, minimal updates** - only the nodes that changed are repainted.
|
|
35
|
+
- **Local and offline** - loopback only, nothing fetched from the network.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Node.js 24+, ESM only. It comes with the CLI:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm i -g @zenera/cli
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or on its own, as a library:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm i @zenera/view
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Use
|
|
52
|
+
|
|
53
|
+
### From the command line
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
zen view # this folder
|
|
57
|
+
zen view finetune/STATUS.md --open # one file, opened in the browser
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`zen view` serves until Ctrl-C and prints its address. `--port`, `--throttle`
|
|
61
|
+
and `--hidden` map to the options below; `zen view --help` has the details.
|
|
62
|
+
|
|
63
|
+
### From code
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { serveView } from '@zenera/view';
|
|
67
|
+
|
|
68
|
+
const server = await serveView({ root: './reports', start: '/STATUS.md' });
|
|
69
|
+
console.log(server.url); // http://127.0.0.1:<port>/STATUS.md
|
|
70
|
+
// ...
|
|
71
|
+
await server.close();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Options
|
|
75
|
+
|
|
76
|
+
| option | default | meaning |
|
|
77
|
+
| ------------ | ------------------------------ | ------------------------------------------- |
|
|
78
|
+
| `root` | - | the directory served; nothing outside it |
|
|
79
|
+
| `port` | derived from `root`, else free | a page left open reconnects after a restart |
|
|
80
|
+
| `start` | `/` | the page `url` opens |
|
|
81
|
+
| `hidden` | `false` | serve dotfiles; `.env`, `.git` never are |
|
|
82
|
+
| `maxBytes` | 2 MB | the most of one file rendered |
|
|
83
|
+
| `maxClients` | 64 | pages open at once |
|
|
84
|
+
| `throttleMs` | 1000 | least time between two pushes of one path |
|
|
85
|
+
|
|
86
|
+
## How it works
|
|
87
|
+
|
|
88
|
+
The server parses each file into a sanitized HTML syntax tree (remark + GFM for
|
|
89
|
+
markdown, lowlight for code). It pushes that tree to the page over server-sent
|
|
90
|
+
events, on connect and again whenever the file changes. The page is a small
|
|
91
|
+
React app that turns the tree into elements, so an update repaints only the
|
|
92
|
+
nodes that differ. Mermaid runs in the browser from the copy installed with
|
|
93
|
+
this package.
|
|
94
|
+
|
|
95
|
+
Files are watched through their directory, so a writer that replaces a file by
|
|
96
|
+
renaming a temporary file over it is still followed. A slow poll backs up
|
|
97
|
+
`fs.watch`. Each change is rendered once however many pages show the file, and
|
|
98
|
+
one path is pushed at most once per `throttleMs`.
|
|
99
|
+
|
|
100
|
+
## Safety
|
|
101
|
+
|
|
102
|
+
- Listens on `127.0.0.1` only, and answers only requests whose `Host` names it,
|
|
103
|
+
so a web page cannot reach it through a DNS name pointed at loopback.
|
|
104
|
+
- Every path is resolved to a real path under the root; `..`, symlinks out of
|
|
105
|
+
the root, dotfiles and secrets are refused.
|
|
106
|
+
- Markdown is sanitized and raw HTML in it is dropped; the page runs under a
|
|
107
|
+
strict Content-Security-Policy. Files served as they are (HTML, SVG, …) carry
|
|
108
|
+
a `sandbox` CSP, so they run - if at all - in an origin of their own.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{color-scheme:light dark;--fg: #24292f;--muted: #57606a;--bg: #ffffff;--panel: #f6f8fa;--line: #d0d7de;--link: #0969da;--hover: #eaeef2;--on: #ddf4ff;--ok: #1a7f37;--warn: #9a6700;--err: #cf222e;--hl-keyword: #cf222e;--hl-string: #0a3069;--hl-number: #0550ae;--hl-attr: #0550ae;--hl-title: #8250df;--hl-comment: #6e7781;--hl-meta: #953800;--hl-add: #116329;--hl-add-bg: #dafbe1;--hl-del: #82071e;--hl-del-bg: #ffebe9}@media(prefers-color-scheme:dark){:root{--fg: #e6edf3;--muted: #8d96a0;--bg: #0d1117;--panel: #161b22;--line: #30363d;--link: #4493f8;--hover: #1f242c;--on: #12233a;--ok: #3fb950;--warn: #d29922;--err: #f85149;--hl-keyword: #ff7b72;--hl-string: #a5d6ff;--hl-number: #79c0ff;--hl-attr: #79c0ff;--hl-title: #d2a8ff;--hl-comment: #8b949e;--hl-meta: #ffa657;--hl-add: #aff5b4;--hl-add-bg: #033a16;--hl-del: #ffdcd7;--hl-del-bg: #67060c}}body{font:14px/1.5 system-ui,sans-serif;margin:0;color:var(--fg);background:var(--bg)}a{color:var(--link)}#toc{position:fixed;top:0;left:0;bottom:0;width:220px;overflow:auto;padding:1em 6px;box-sizing:border-box;border-right:1px solid var(--line);background:var(--panel);font-size:13px}#toc a{display:block;padding:2px 8px;border-radius:4px;color:var(--fg);text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}#toc a.top{font-weight:600;margin-bottom:6px}#toc a.sub{padding-left:22px;color:var(--muted)}#toc a:hover{background:var(--hover)}#toc a.on{background:var(--on);color:var(--link);font-weight:600}#page.with-toc{margin-left:220px}header{position:sticky;top:0;z-index:2;display:flex;gap:1em;justify-content:space-between;align-items:baseline;padding:6px 2em;background:var(--bg);border-bottom:1px solid var(--line);font-size:13px}header .crumbs a{text-decoration:none}header .aside{display:flex;gap:1em;color:var(--muted);white-space:nowrap}.link:before{content:"\25cf";margin-right:4px}.link.live:before{color:var(--ok)}.link.connecting:before{color:var(--warn)}.link.lost:before{color:var(--err)}main{padding:1em 2em;max-width:1600px}h1,h2,h3,h4{scroll-margin-top:44px}.note{color:var(--muted)}@media(max-width:800px){#toc{display:none}#page.with-toc{margin-left:0}}.table-wrap{overflow:auto;max-height:75vh;margin:1em 0;border:1px solid var(--line);width:fit-content;max-width:100%}table{border-collapse:collapse}.table-wrap table{margin:0}th,td{border:1px solid var(--line);padding:4px 8px;vertical-align:top}.table-wrap tr:first-child>*{border-top:none}.table-wrap tr>:first-child{border-left:none}.table-wrap tr>:last-child{border-right:none}th{background:var(--panel);position:sticky;top:0;z-index:1}td.num{text-align:right;white-space:nowrap}table.listing td{white-space:nowrap}.table-wrap:has(td.lines),.table-wrap:has(td.lines) table{width:100%}td.lines{width:40%}td.lines>.line{contain:inline-size;min-width:24ch;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}code{font:12.5px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--panel);padding:0 4px;border-radius:4px}pre{background:var(--panel);padding:8px 12px;overflow:auto;border-radius:6px}pre code{padding:0;background:none}main.code pre,main.text pre{margin:0}.mermaid{margin:1em 0;overflow:auto}.mermaid-svg svg{max-width:100%;height:auto}.mermaid-error{color:var(--err);font-size:12px;white-space:pre-wrap}main.mermaid .mermaid-svg svg{max-width:none}img{max-width:100%}.hljs-keyword,.hljs-selector-tag,.hljs-built_in,.hljs-literal,.hljs-type{color:var(--hl-keyword)}.hljs-string,.hljs-regexp,.hljs-symbol{color:var(--hl-string)}.hljs-number,.hljs-variable,.hljs-template-variable{color:var(--hl-number)}.hljs-attr,.hljs-attribute,.hljs-property,.hljs-selector-class,.hljs-selector-id{color:var(--hl-attr)}.hljs-title,.hljs-section,.hljs-name{color:var(--hl-title)}.hljs-comment,.hljs-quote{color:var(--hl-comment);font-style:italic}.hljs-meta,.hljs-params{color:var(--hl-meta)}.hljs-addition{color:var(--hl-add);background:var(--hl-add-bg)}.hljs-deletion{color:var(--hl-del);background:var(--hl-del-bg)}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:600}
|