@zenera/view 0.0.0-stage → 1.1.26

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 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,62 @@
1
- # Temporary Holding Version
1
+ # @zenera/view
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
+ A live local viewer for a folder. Markdown is drawn with GitHub tables and
4
+ [Mermaid](https://mermaid.js.org) diagrams, code (`.json`, `.jsonl`, `.py`, `.ts`,
5
+ `.yaml`, `.patch`, …) is highlighted, a directory is a listing - and an open page
6
+ follows its file: when the file changes, only what changed is redrawn. No reload,
7
+ no lost scroll position, no flicker of diagrams that did not change.
8
+
9
+ ```sh
10
+ npm i @zenera/view
11
+ ```
12
+
13
+ ```ts
14
+ import { serveView } from '@zenera/view';
15
+
16
+ const server = await serveView({ root: './reports', start: '/STATUS.md' });
17
+ console.log(server.url); // http://127.0.0.1:<port>/STATUS.md
18
+ // ...
19
+ await server.close();
20
+ ```
21
+
22
+ With `@zenera/cli` installed the same thing is `zen view [path]`.
23
+
24
+ ## How it works
25
+
26
+ The server parses each file into a sanitized HTML syntax tree (remark + GFM for
27
+ markdown, lowlight for code) and pushes it to the page over server-sent events -
28
+ on connect, and again whenever the file changes. The page is a small React app
29
+ that turns the tree into elements, so an update repaints only the nodes that
30
+ differ. Mermaid runs in the browser, from the copy installed with this package,
31
+ so nothing is fetched from the network.
32
+
33
+ Files are watched through their directory, so a writer that replaces a file by
34
+ renaming a temporary over it is followed; a slow poll backs up `fs.watch`.
35
+ A file is rendered once per change however many pages show it, and one path is
36
+ pushed at most once per `throttleMs`.
37
+
38
+ ## Options
39
+
40
+ | option | default | meaning |
41
+ | ------------ | ------------------------------ | ------------------------------------------- |
42
+ | `root` | - | the directory served; nothing outside it |
43
+ | `port` | derived from `root`, else free | a page left open reconnects after a restart |
44
+ | `start` | `/` | the page `url` opens |
45
+ | `hidden` | `false` | serve dotfiles; `.env`, `.git` never are |
46
+ | `maxBytes` | 2 MB | the most of one file rendered |
47
+ | `maxClients` | 64 | pages open at once |
48
+ | `throttleMs` | 1000 | least time between two pushes of one path |
49
+
50
+ ## Safety
51
+
52
+ - Listens on `127.0.0.1` only, and answers only requests whose `Host` names it,
53
+ so a web page cannot reach it through a DNS name pointed at loopback.
54
+ - Every path is resolved to a real path under the root; `..`, symlinks out of
55
+ the root, dotfiles and secrets are refused.
56
+ - Markdown is sanitized and raw HTML in it is dropped; the page runs under a
57
+ strict Content-Security-Policy. Files served as they are (HTML, SVG, …) carry
58
+ a `sandbox` CSP, so they run - if at all - in an origin of their own.
59
+
60
+ ## License
61
+
62
+ 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}