spider-paint 26.11.26002 → 26.11.26003
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/README.md +10 -18
- package/bin/spider-md.mjs +2 -1
- package/bin/term-app.mjs +54 -8
- package/bin/term-palette.mjs +115 -0
- package/help/building.md +3 -0
- package/help/commands.md +1 -0
- package/index.html +68 -0
- package/package.json +5 -2
- package/src/md/highlight.js +1 -1
- package/src/term-render.js +58 -0
package/README.md
CHANGED
|
@@ -70,7 +70,10 @@ and **the Enter line**, lighter while the Enter box is open (focused): what you
|
|
|
70
70
|
targets, `/l` scenes, `/mat`, `/help`…) covers the bottom of the view, ↑↓ / Tab / Enter / Esc and a click on a row work
|
|
71
71
|
as in the app; in the edit mode (Q), where Enter builds, cuts or turns, **Shift+Enter** opens the box (the terminal is asked
|
|
72
72
|
for the kitty keyboard protocol so that it can tell Shift+Enter apart; **Alt+Enter** does the same in every terminal).
|
|
73
|
-
|
|
73
|
+
The text box (Y, or T in Q) is typed on the same bottom line (`text › …`). **The palette (P)** is a text panel on the
|
|
74
|
+
right over the picture: ↑↓ (or the wheel) chooses the material, Tab chooses metal / rough / alpha / emit / soft and ← →
|
|
75
|
+
change it (Shift: five steps), a click takes a material or a place on a value's bar, ✕ / P / Esc close it; Ctrl+click on
|
|
76
|
+
the picture still paints. **`/q`** (`/quit`) in the box leaves. The mouse is the app's (the cross follows it, drag turns, the wheel zooms; Shift / Option + drag selects
|
|
74
77
|
terminal text). Ctrl+C quits. On WSL: install a Chrome or Chromium inside Ubuntu, or the native viewer starts.
|
|
75
78
|
|
|
76
79
|
A scene **file** (`.json`, `.3draft`, a sky catalogue, a story) is packed into the page's address, as an MCP link is, and
|
|
@@ -78,7 +81,7 @@ A scene **file** (`.json`, `.3draft`, a sky catalogue, a story) is packed into t
|
|
|
78
81
|
|
|
79
82
|
### In VS Code
|
|
80
83
|
|
|
81
|
-
`vscode/` is a VS Code extension: the app itself in a webview tab (sharp, every key). Commands: **
|
|
84
|
+
`vscode/` is a VS Code extension: the app itself in a webview tab (sharp, every key). Commands: **spider-paint: Open**,
|
|
82
85
|
**Open a scene from the list…**, **Show this scene file in 3D** (the editor's `.json` / `.3draft` beside it, reloaded on
|
|
83
86
|
every save; also a button in the editor's title bar). Try it from the checkout: open the `vscode` folder in VS Code and
|
|
84
87
|
press F5 (it uses the checkout's app), or build a `.vsix` (`cd vscode && npm run package`, then
|
|
@@ -93,27 +96,16 @@ languages nest — an ```html block's `<script>` is JavaScript, its `/** jsDoc *
|
|
|
93
96
|
types}` coloured, a `<style>` is CSS. The page's help panel and the terminal's help view (`?` in the app view, `/help
|
|
94
97
|
[word]` in the native one) show the same files with the same colours.
|
|
95
98
|
|
|
99
|
+
The same files as one web page: `npm run docs -- --out help.html` (or `--template page.html`, which puts the page
|
|
100
|
+
into a site's own header and footer). The Tüskék és Gyökerek docs page ([`dist/spider-docs.html`](https://github.com/Pengeszikra/tuskek-es-gyokerek/blob/main/dist/spider-docs.html))
|
|
101
|
+
is generated this way, by that site's `spider-docs` workflow, from the current `master`.
|
|
102
|
+
|
|
96
103
|
Markdown in colour on the console, with the same reader: `spider-paint -md file.md` (or `spider-md file.md`,
|
|
97
104
|
`npx spider-md README.md`; `-` reads stdin, `--width N`, `--page` through `less -R`, `--plain` without colours). A code
|
|
98
105
|
file (`.js`, `.html`, `.json`, `.rs`, `.sh`…) is shown as one coloured block. Pictures in the markdown (``, a path
|
|
99
106
|
beside the file or `https://…`) are drawn the way the 3D view is: half blocks, two pixels a cell (`--image-rows N`,
|
|
100
107
|
`--no-images`). PNG and GIF are read in node; JPEG, SVG and WebP go through a headless Chrome when there is one.
|
|
101
108
|
|
|
102
|
-
### In Vim / Neovim
|
|
103
|
-
|
|
104
|
-
The checkout is a Vim plugin too (`vim/plugin/spider-paint.vim`):
|
|
105
|
-
|
|
106
|
-
```vim
|
|
107
|
-
" vim-plug (lazy.nvim: { 'Pengeszikra/Spider-Paint', config = function(p) vim.opt.rtp:append(p.dir .. '/vim') end })
|
|
108
|
-
Plug 'Pengeszikra/Spider-Paint', { 'rtp': 'vim', 'do': 'npm install --omit=dev' }
|
|
109
|
-
set termguicolors mouse=a
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
`:SpiderPaint` opens spider-paint in a vertical terminal split: the buffer's scene file if it is one (saving it reloads the
|
|
113
|
-
view), else the start scene; `:SpiderPaint bridge` a scene of the + scene list; `:SpiderPaint path.json` a file.
|
|
114
|
-
`g:spider_paint_split` = `'vertical'` | `'horizontal'` | `'tab'`. In the split every key belongs to spider-paint; Ctrl+W
|
|
115
|
-
(Vim) or Ctrl+\ Ctrl+N (Neovim) gets back to the editor, Ctrl+C quits spider-paint. Vim 8.1+ or Neovim, node 22+.
|
|
116
|
-
|
|
117
109
|
**The native viewer (`--native`, or when there is no Chrome):** The scene is drawn with 24-bit colour half blocks (two pixels a character cell), a depth buffer and one shaded colour a
|
|
118
110
|
face (`src/term-render.js`, pure: no node, no DOM), with dark outlines at the silhouettes, folds and depth jumps in place of
|
|
119
111
|
the GPU's light play (`/outline` or `--flat` turns them off). The model fills the window. It is zen: only the picture. The mouse belongs to the program (the
|
|
@@ -131,7 +123,7 @@ mouse reporting (iTerm2, WezTerm, kitty, Ghostty, Windows Terminal, VS Code; not
|
|
|
131
123
|
|
|
132
124
|
## Project boundaries and deployments
|
|
133
125
|
|
|
134
|
-
- **spider-paint** (`Pengeszikra/spider-paint`) is deployed to Cloud Run
|
|
126
|
+
- **spider-paint** (`Pengeszikra/spider-paint`) is deployed to Cloud Run (`.github/workflows/cloud-run-deploy.yml`) and has the `spider-paint` npm package.
|
|
135
127
|
- **3Draft** (`Pengeszikra/3Draft`) is the separate 3D engine repository and npm module.
|
|
136
128
|
|
|
137
129
|
The product name is always lowercase **spider-paint**. The app header can retain **3Draft** as a quiet engine attribution.
|
package/bin/spider-md.mjs
CHANGED
|
@@ -19,7 +19,8 @@ export const mdToTerminal = (text, { file = '', width = 100, images = null, rows
|
|
|
19
19
|
const fence = '`'.repeat(Math.max(3, ...[...text.matchAll(/`{3,}/g)].map((m) => m[0].length + 1)));
|
|
20
20
|
const md = lang ? `${fence}${lang}\n${text.replace(/\n$/, '')}\n${fence}` : text;
|
|
21
21
|
const image = images ? (src, alt, cols) => (images.get(src) ? imageLines(images.get(src), { cols, rows }) : null) : null;
|
|
22
|
-
|
|
22
|
+
// one character of room on each side: the text is laid out two narrower and every line starts with a space
|
|
23
|
+
return toAnsi(md, { width: Math.max(10, width - 2), image }).map((l) => (l ? ` ${l}` : l)).join('\n');
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
// the pictures a markdown text shows: read (a path next to the file, or https://…) and decoded, before the text is laid out
|
package/bin/term-app.mjs
CHANGED
|
@@ -10,8 +10,9 @@ import { existsSync, readFileSync, watch } from 'node:fs';
|
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
11
11
|
import { join, resolve, sep, extname } from 'node:path';
|
|
12
12
|
import { inflateSync, deflateRawSync } from 'node:zlib';
|
|
13
|
-
import {
|
|
13
|
+
import { cellRows, diffRow } from '../src/term-render.js';
|
|
14
14
|
import { createHelpView } from './term-help.mjs';
|
|
15
|
+
import { createPaletteView } from './term-palette.mjs';
|
|
15
16
|
|
|
16
17
|
// ---- Chrome: CHROME_PATH, or the usual places
|
|
17
18
|
export const findChrome = () => {
|
|
@@ -115,6 +116,8 @@ const PAGE_STATE = `(() => {
|
|
|
115
116
|
edit: globalThis.__editing?.() ?? null,
|
|
116
117
|
fps: t('fps')?.textContent ?? '',
|
|
117
118
|
toast: toast?.isConnected ? toast.textContent : '',
|
|
119
|
+
palette: t('palette') && !t('palette').hidden ? globalThis.__palette?.() ?? null : null,
|
|
120
|
+
text: t('textBox') && !t('textBox').hidden ? { value: t('textBox').value, hint: t('textBox').placeholder } : null,
|
|
118
121
|
help: t('helpPanel') && !t('helpPanel').hidden ? { file: globalThis.__helpAt ?? 'index.md', found: globalThis.__helpFound ?? null } : null,
|
|
119
122
|
find: box && !box.hidden ? { value: t('findInput').value, rows: [...t('findList').children].map((d) => ({ i: d.dataset.i ?? null, sel: d.classList.contains('sel'), left: (d.children[0]?.innerText ?? d.innerText).replace(/\\s+/g, ' ').trim(), right: (d.children[1]?.innerText ?? '').trim() })) } : null,
|
|
120
123
|
};
|
|
@@ -124,7 +127,7 @@ const PAGE_STATE = `(() => {
|
|
|
124
127
|
const PAGE_CSS = `header.bar, footer.bar, footer.console, #hud, #editbar, #flight, #surface, #zenOff, .build, #cmdToast, #cloudToast { display: none !important; }
|
|
125
128
|
#stage { position: fixed !important; inset: 0 !important; border: 0 !important; border-radius: 0 !important; z-index: 1; }
|
|
126
129
|
body { padding: 0 !important; gap: 0 !important; }
|
|
127
|
-
#findBox { opacity: 0 !important; pointer-events: none !important; }`;
|
|
130
|
+
#findBox, #textBox, #palette { opacity: 0 !important; pointer-events: none !important; }`;
|
|
128
131
|
|
|
129
132
|
// ---- terminal keys -> DOM key events
|
|
130
133
|
const VK = { Enter: 13, Escape: 27, Tab: 9, Backspace: 8, Delete: 46, ' ': 32, ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, Home: 36, End: 35, PageUp: 33, PageDown: 34 };
|
|
@@ -279,9 +282,24 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
279
282
|
|
|
280
283
|
// ---- the frame: the picture (the list over it), the info line, the Enter line
|
|
281
284
|
let shown = [], state = null, listRows = []; // listRows: [{ row (screen line), i }]
|
|
285
|
+
// shown[i]: what screen line i holds: a string (a text line) or the picture's cells (rows of [code, ch]), so a
|
|
286
|
+
// frame sends only the cells that changed. Inside Vim / Neovim (their :terminal parses every byte, slowly) the
|
|
287
|
+
// colours are rounded a little and the frames are fewer: SPIDER_TERM_QUANT (0–5 bits) and SPIDER_TERM_FPS set them.
|
|
288
|
+
const inEditor = !!(process.env.VIM_TERMINAL || process.env.NVIM);
|
|
289
|
+
const QUANT = Math.max(0, Math.min(5, Number(process.env.SPIDER_TERM_QUANT ?? (inEditor ? 3 : 0)) || 0));
|
|
290
|
+
const FPS = Math.max(1, Math.min(30, Number(process.env.SPIDER_TERM_FPS) || (inEditor ? 10 : 14)));
|
|
282
291
|
const fit = (s, n) => (s.length > n ? `${s.slice(0, Math.max(0, n - 1))}…` : s);
|
|
283
292
|
// the help: drawn here as text from help/*.md while the page's help panel is open (the page's section, its /help finds)
|
|
284
293
|
const helpView = createHelpView(root);
|
|
294
|
+
const palView = createPaletteView();
|
|
295
|
+
// a change from the palette panel: to the page, and its answer (the palette as it is now) is drawn at once
|
|
296
|
+
const palApply = async (a) => {
|
|
297
|
+
if (a === 'close') return page('Runtime.evaluate', { expression: "document.getElementById('palClose')?.click()" });
|
|
298
|
+
if (a && typeof a === 'object') {
|
|
299
|
+
const r = await page('Runtime.evaluate', { expression: `globalThis.__paletteSet(${JSON.stringify(a)})`, returnByValue: true }).catch(() => null);
|
|
300
|
+
if (state && r?.result?.value) state.palette = r.result.value;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
285
303
|
let helpSeen = null;
|
|
286
304
|
const followHelp = (h) => {
|
|
287
305
|
const key = h ? `${h.file}|${h.found?.file ?? ''}|${h.found?.text ?? ''}` : null;
|
|
@@ -303,7 +321,12 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
303
321
|
const img = decodePng(Buffer.from(shot.data, 'base64'));
|
|
304
322
|
if (img.width !== L.cols || img.height < L.rows * 2) return; // (a resize is on its way)
|
|
305
323
|
img.height = L.rows * 2;
|
|
306
|
-
lines =
|
|
324
|
+
lines = cellRows(img, QUANT);
|
|
325
|
+
// the palette (P): a text panel on the right, over the picture
|
|
326
|
+
if (state?.palette) {
|
|
327
|
+
const { x0, lines: panel } = palView.draw(state.palette, L.cols, L.rows);
|
|
328
|
+
for (const [y, c] of panel) lines[y] = lines[y].slice(0, x0).concat(c);
|
|
329
|
+
}
|
|
307
330
|
}
|
|
308
331
|
// the Enter box's list, over the bottom of the picture
|
|
309
332
|
listRows = [];
|
|
@@ -329,15 +352,26 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
329
352
|
const badgeLen = s.edit ? 6 + mode.length + 2 + s.edit.name.length + 2 : 0;
|
|
330
353
|
lines.push(`${badge}\x1b[0;48;2;18;18;20;38;2;150;154;160m${fit(` ${info}`, Math.max(0, L.cols - badgeLen)).padEnd(Math.max(0, L.cols - badgeLen))}\x1b[0m`);
|
|
331
354
|
// the Enter line: lighter while the box is open (focused)
|
|
332
|
-
|
|
355
|
+
// the text box (Y, T in Q): the words being typed, on the same line
|
|
356
|
+
const textLine = (t) => {
|
|
357
|
+
const head = ' text › ';
|
|
358
|
+
const body = fit(t.value || t.hint || '', Math.max(0, L.cols - head.length));
|
|
359
|
+
return `\x1b[0;48;2;62;66;74;38;2;240;240;240m${head}${t.value ? '' : '\x1b[38;2;150;154;160m'}${body}${' '.repeat(Math.max(0, L.cols - head.length - body.length))}\x1b[0m`;
|
|
360
|
+
};
|
|
361
|
+
const enter = s.text
|
|
362
|
+
? textLine(s.text)
|
|
363
|
+
: s.find ? `\x1b[0;48;2;62;66;74;38;2;240;240;240m${fit(` › ${s.find.value}`, L.cols).padEnd(L.cols)}\x1b[0m` : `\x1b[0;48;2;30;31;34;38;2;90;94;100m${fit(' Enter: find / commands (/l /s /svg /help …) · in Q: Shift+Enter (or Alt+Enter) · /q: quit', L.cols).padEnd(L.cols)}\x1b[0m`;
|
|
333
364
|
lines.push(enter);
|
|
334
365
|
let buf = '\x1b[?2026h';
|
|
335
366
|
lines.forEach((l, i) => {
|
|
336
|
-
if (
|
|
367
|
+
if (typeof l === 'string') {
|
|
368
|
+
if (shown[i] !== l) buf += `\x1b[${i + 1};1H${l}`;
|
|
369
|
+
} else buf += diffRow(Array.isArray(shown[i]) ? shown[i] : null, l, i + 1);
|
|
337
370
|
});
|
|
338
371
|
shown = lines;
|
|
339
|
-
buf += s.find ? `\x1b[${L.rows + 2};${Math.min(L.cols, 4 + s.find.value.length)}H\x1b[?25h` : '\x1b[?25l';
|
|
340
|
-
|
|
372
|
+
buf += s.text ? `\x1b[${L.rows + 2};${Math.min(L.cols, 9 + s.text.value.length)}H\x1b[?25h` : s.find ? `\x1b[${L.rows + 2};${Math.min(L.cols, 4 + s.find.value.length)}H\x1b[?25h` : '\x1b[?25l';
|
|
373
|
+
// the terminal decides the pace: while it has not taken the last frame, no new one is made (no lag piles up)
|
|
374
|
+
if (!out.write(`${buf}\x1b[?2026l`)) await new Promise((r) => out.once('drain', r));
|
|
341
375
|
};
|
|
342
376
|
const loop = async () => {
|
|
343
377
|
while (!done) {
|
|
@@ -345,7 +379,7 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
345
379
|
try {
|
|
346
380
|
await frame();
|
|
347
381
|
} catch {}
|
|
348
|
-
await new Promise((r) => setTimeout(r, Math.max(10,
|
|
382
|
+
await new Promise((r) => setTimeout(r, Math.max(10, 1000 / FPS - (performance.now() - t)))); // (FPS frames a second at most)
|
|
349
383
|
}
|
|
350
384
|
};
|
|
351
385
|
|
|
@@ -362,6 +396,10 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
362
396
|
if (!motion && !release && btn === 0 && y === 1) helpView.click(x - 1);
|
|
363
397
|
return;
|
|
364
398
|
}
|
|
399
|
+
if (state?.palette && !state?.find) {
|
|
400
|
+
const r = palView.mouse(x - 1, y - 1, { press: !motion && !release && btn === 0 && !wheel, wheel: wheel ? (btn === 0 ? -1 : 1) : 0 }, state.palette);
|
|
401
|
+
if (r) return palApply(r);
|
|
402
|
+
}
|
|
365
403
|
const at = px(x, y);
|
|
366
404
|
if (wheel) return page('Input.dispatchMouseEvent', { type: 'mouseWheel', ...at, deltaX: 0, deltaY: btn === 0 ? -120 : 120, modifiers: mods });
|
|
367
405
|
const name = ['left', 'middle', 'right'][btn] ?? 'none', bit = [1, 4, 2][btn] ?? 0;
|
|
@@ -389,6 +427,14 @@ export const runApp = async ({ root, scene, chrome, url }) => {
|
|
|
389
427
|
if (r === 'close') events.push(() => page('Runtime.evaluate', { expression: "document.getElementById('helpClose')?.click()" }));
|
|
390
428
|
continue;
|
|
391
429
|
}
|
|
430
|
+
// the palette panel takes ↑ ↓ ← → Tab (not while a box is open: there they are typing keys)
|
|
431
|
+
if (state?.palette && !state?.find && !state?.text) {
|
|
432
|
+
const r = palView.key(k, state.palette);
|
|
433
|
+
if (r) {
|
|
434
|
+
if (r !== 'draw') events.push(() => palApply(r));
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
392
438
|
// /q, /quit (or /exit) in the Enter box: leave the terminal
|
|
393
439
|
if (k.key === 'Enter' && !k.shift)
|
|
394
440
|
events.push(async () => {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// The material palette (P) drawn as text in the terminal app view: a panel on the right over the picture, so the model
|
|
2
|
+
// stays in sight while you paint (Ctrl+click on the picture still paints). The page's own palette is hidden there; this
|
|
3
|
+
// one reads it through globalThis.__palette() and changes it through globalThis.__paletteSet({ current } | { key, value }).
|
|
4
|
+
//
|
|
5
|
+
// ↑ ↓ the material (the wheel over the panel too)
|
|
6
|
+
// Tab, ⇧Tab the value that ← → change (metal, rough, alpha, emit, soft)
|
|
7
|
+
// ← → that value one step (with Shift five)
|
|
8
|
+
// a click a material, a place on a value's bar, ✕ closes; P or Esc closes too (the page's own keys)
|
|
9
|
+
|
|
10
|
+
const PANEL = '22;24;28', HEAD = '34;37;43', TEXT = '220;222;214', DIM = '130;134;140', SEL = '77;171;247', SEL_FG = '4;20;36';
|
|
11
|
+
const BAR_ON = '230;196;120', BAR_OFF = '52;55;62';
|
|
12
|
+
const rgb = (hex) => {
|
|
13
|
+
const h = String(hex ?? '#888').replace('#', '');
|
|
14
|
+
const f = h.length === 3 ? h.split('').map((c) => c + c).join('') : h.padEnd(6, '0').slice(0, 6);
|
|
15
|
+
return [0, 2, 4].map((k) => parseInt(f.slice(k, k + 2), 16) || 0).join(';');
|
|
16
|
+
};
|
|
17
|
+
const cells = (s, fg, bg) => [...s].map((ch) => [fg, bg, ch]);
|
|
18
|
+
const fitText = (s, n) => {
|
|
19
|
+
const a = [...s];
|
|
20
|
+
return a.length > n ? `${a.slice(0, Math.max(0, n - 1)).join('')}…` : s + ' '.repeat(n - a.length);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const createPaletteView = () => {
|
|
24
|
+
let prop = 0; // the value ← → change
|
|
25
|
+
let layout = null; // the last drawn panel: { x0, w, rows: [{ y, kind, i?, bar? }] }
|
|
26
|
+
|
|
27
|
+
/** The panel for a picture `cols` wide and `rows` high: { x0, lines: Map(row -> cells of the panel's width) } */
|
|
28
|
+
const draw = (pal, cols, rows) => {
|
|
29
|
+
const w = Math.max(24, Math.min(36, Math.floor(cols * 0.45)));
|
|
30
|
+
const x0 = Math.max(0, cols - w);
|
|
31
|
+
const lines = new Map();
|
|
32
|
+
const at = [];
|
|
33
|
+
const put = (y, c, meta) => {
|
|
34
|
+
if (y >= rows) return;
|
|
35
|
+
lines.set(y, c.slice(0, w).concat(cells(' '.repeat(Math.max(0, w - c.length)), TEXT, c.at(-1)?.[1] ?? PANEL)));
|
|
36
|
+
if (meta) at.push({ y, ...meta });
|
|
37
|
+
};
|
|
38
|
+
const items = pal.items ?? [];
|
|
39
|
+
const props = pal.props ?? [];
|
|
40
|
+
prop = Math.min(prop, Math.max(0, props.length - 1));
|
|
41
|
+
// what fits: the header, the materials, a gap, the values, the colour, the hint (two lines)
|
|
42
|
+
const fixed = 1 + 1 + props.length + 1 + 2;
|
|
43
|
+
const room = Math.max(1, rows - fixed);
|
|
44
|
+
const first = items.length <= room ? 0 : Math.min(items.length - room, Math.max(0, pal.current - Math.floor(room / 2)));
|
|
45
|
+
let y = 0;
|
|
46
|
+
put(y++, [...cells(fitText(' materials', w - 3), TEXT, HEAD), ...cells(' ✕ ', TEXT, HEAD)], { kind: 'head' });
|
|
47
|
+
for (let i = first; i < Math.min(items.length, first + room); i++) {
|
|
48
|
+
const m = items[i], on = i === pal.current;
|
|
49
|
+
const bg = on ? SEL : PANEL, fg = on ? SEL_FG : TEXT;
|
|
50
|
+
const more = (i === first && first > 0) || (i === first + room - 1 && first + room < items.length);
|
|
51
|
+
put(y++, [...cells(on ? '▸' : ' ', fg, bg), ...cells(' ', '0;0;0', rgb(m.color)), ...cells(fitText(` ${m.name}${m.metal > 0.5 ? ' ·metal' : ''}${m.alpha < 1 ? ' ·clear' : ''}`, w - 6), fg, bg), ...cells(more ? '⋮ ' : ' ', DIM, bg)], { kind: 'mat', i });
|
|
52
|
+
}
|
|
53
|
+
put(y++, cells('', TEXT, PANEL));
|
|
54
|
+
const barW = Math.max(6, w - 15);
|
|
55
|
+
props.forEach((p, k) => {
|
|
56
|
+
const f = p.max > p.min ? (p.value - p.min) / (p.max - p.min) : 0;
|
|
57
|
+
const n = Math.round(Math.max(0, Math.min(1, f)) * barW);
|
|
58
|
+
const focus = k === prop;
|
|
59
|
+
const label = cells(fitText(` ${focus ? '›' : ' '}${p.key}`, 8), focus ? SEL : TEXT, PANEL);
|
|
60
|
+
const bar = [...Array(barW)].map((_, j) => [j < n ? BAR_ON : BAR_OFF, PANEL, '━']);
|
|
61
|
+
put(y++, [...label, ...bar, ...cells(` ${p.value.toFixed(2).padStart(5)}`, focus ? TEXT : DIM, PANEL)], { kind: 'prop', k, bar: [8, 8 + barW] });
|
|
62
|
+
});
|
|
63
|
+
const cur = items[pal.current];
|
|
64
|
+
if (cur) put(y++, [...cells(' ', TEXT, PANEL), ...cells(' ', '0;0;0', rgb(cur.color)), ...cells(` ${cur.color}`, DIM, PANEL)]);
|
|
65
|
+
put(y++, cells(fitText(' ↑↓ material Tab ←→ value', w), DIM, PANEL));
|
|
66
|
+
put(y++, cells(fitText(' P/Esc close · Ctrl+click paints', w), DIM, PANEL));
|
|
67
|
+
layout = { x0, w, rows: at, first, h: y };
|
|
68
|
+
return { x0, lines };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** A key while the palette is open: an action for the page ({ current } / { key, value }), 'draw' (only this view
|
|
72
|
+
* changed), or null (the key is the page's). */
|
|
73
|
+
const key = (k, pal) => {
|
|
74
|
+
const items = pal.items ?? [], props = pal.props ?? [];
|
|
75
|
+
if (k.key === 'ArrowUp' || k.key === 'ArrowDown') {
|
|
76
|
+
if (!items.length) return 'draw';
|
|
77
|
+
return { current: (pal.current + (k.key === 'ArrowUp' ? -1 : 1) + items.length) % items.length };
|
|
78
|
+
}
|
|
79
|
+
if (k.key === 'Tab') {
|
|
80
|
+
prop = props.length ? (prop + (k.shift ? -1 : 1) + props.length) % props.length : 0;
|
|
81
|
+
return 'draw';
|
|
82
|
+
}
|
|
83
|
+
if ((k.key === 'ArrowLeft' || k.key === 'ArrowRight') && props[prop]) {
|
|
84
|
+
const p = props[prop];
|
|
85
|
+
const step = (p.step || 0.05) * (k.shift ? 5 : 1) * (k.key === 'ArrowLeft' ? -1 : 1);
|
|
86
|
+
const value = Math.max(p.min, Math.min(p.max, Math.round((p.value + step) / (p.step || 0.05)) * (p.step || 0.05)));
|
|
87
|
+
return { key: p.key, value: +value.toFixed(4) };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** The mouse at cell x, y (0-based) over the picture: an action, 'close', 'inside' (over the panel, nothing to do) or
|
|
93
|
+
* null (not over the panel: the page's). */
|
|
94
|
+
const mouse = (x, y, { press = false, wheel = 0 } = {}, pal) => {
|
|
95
|
+
if (!layout || x < layout.x0) return null;
|
|
96
|
+
const r = layout.rows.find((q) => q.y === y);
|
|
97
|
+
if (y >= layout.h) return null;
|
|
98
|
+
if (!r) return 'inside';
|
|
99
|
+
if (wheel) return (pal.items ?? []).length ? { current: (pal.current + wheel + pal.items.length) % pal.items.length } : 'inside';
|
|
100
|
+
if (!press) return 'inside';
|
|
101
|
+
if (r.kind === 'head') return x >= layout.x0 + layout.w - 3 ? 'close' : 'inside';
|
|
102
|
+
if (r.kind === 'mat') return { current: r.i };
|
|
103
|
+
if (r.kind === 'prop') {
|
|
104
|
+
prop = r.k;
|
|
105
|
+
const p = pal.props[r.k];
|
|
106
|
+
const [a, b] = r.bar;
|
|
107
|
+
const f = Math.max(0, Math.min(1, (x - layout.x0 - a + 0.5) / (b - a)));
|
|
108
|
+
const v = p.min + f * (p.max - p.min);
|
|
109
|
+
return { key: p.key, value: +(Math.round(v / (p.step || 0.05)) * (p.step || 0.05)).toFixed(4) };
|
|
110
|
+
}
|
|
111
|
+
return 'inside';
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return { draw, key, mouse, get prop() { return prop; } };
|
|
115
|
+
};
|
package/help/building.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
| bool button | **Boolean:** select two objects (B; the first taken is A, orange, the second B, green), press **bool** in the SYS group, then choose 1 union, 2 A−B, 3 B−A, 4 intersect, 5 cancel |
|
|
13
13
|
| H | Move gizmo: world axes, its own axes, off |
|
|
14
14
|
| J | Pose mode on the figure under the cross or the target (see Pose mode) |
|
|
15
|
+
| Y | Text: on the face under the cross, or in front of the camera (see **Text** below) |
|
|
15
16
|
| P | The material palette |
|
|
16
17
|
| I | Pick the material under the cross |
|
|
17
18
|
| Ctrl+click (Cmd on a Mac) | Paint the face under the cross; Ctrl+double click paints the whole object |
|
|
@@ -51,6 +52,8 @@ A placed character can be **posed** like any figure: put the cross on it (or tar
|
|
|
51
52
|
A placed character is a **group of instances**: one object per module (body, head, face, hair, top, bottom, shoes, extra), grouped under the character's name, each an instance of the library's prototype. So a crowd shares a few meshes. It moves with **G**, turns with **R** and sizes with **S** as one, and stays made of instances (a save writes the prototypes once and a short record per module); an edit of its mesh, or a tilt off upright, makes that part an ordinary object.
|
|
52
53
|
|
|
53
54
|
## Text
|
|
55
|
+
**Y** (or the command **/text words**) puts text down without edit mode: over a face the first letter starts at the cross, on that face (on a floor the letters stand up away from you, so they read); over empty space the text stands in front of the camera, facing it. Type the words in the box and press Enter (with **/text words** they go down at once). The letters are about 28 screen pixels high where they are made, so zoom in for small writing.
|
|
56
|
+
|
|
54
57
|
In edit mode, select a face (3) and press **T**: type the words and press Enter. The text becomes a **new model**, standing out of that face in the **active material**. The face sets where the first letter starts (its lower left corner), the reading direction and the letter height; the text runs on to the right, so a long text goes past the face. The font is a minimalist blocky stroke font (A–Z, 0–9, `. , : ! ? - _ + / '` and the Hungarian accents); lower case is drawn as upper case. The stroke, and the depth the letters stand out, is 20 % of the letter height.
|
|
55
58
|
|
|
56
59
|
The model keeps its words (a `text` attribute, saved in the scene file with the frame it stands in), so to fix them: edit the text model (Q on it) and press **T** again.
|
package/help/commands.md
CHANGED
|
@@ -20,6 +20,7 @@ Enter opens the find box (in the edit mode, where Enter builds, cuts or turns: *
|
|
|
20
20
|
| `/mat name` | choose the material (a list with the colours) |
|
|
21
21
|
| `/add prism · box · cylinder · cone · pyramid · sphere` | a shape of the chosen material floats at the cross: a click sticks it, Enter keeps it (M then puts down more) |
|
|
22
22
|
| `/char [random · panel]` | put a character down (a random one, or the one the Characters panel shows) |
|
|
23
|
+
| `/text [words]` | put words down: on the face under the cross, or in front of the camera (Y); without words the text box opens |
|
|
23
24
|
| `/bool union · subtract · subtract-swap · intersect` | the boolean of the two selected objects (B) |
|
|
24
25
|
| `/go name` or `/go x y z` | target an object, or fly to a point |
|
|
25
26
|
| `/vehicle starship · car · none` | how the camera moves |
|
package/index.html
CHANGED
|
@@ -5401,6 +5401,25 @@
|
|
|
5401
5401
|
}
|
|
5402
5402
|
document.getElementById('p-url').value = m.url ?? m.scene ?? m.image ?? '';
|
|
5403
5403
|
};
|
|
5404
|
+
// the palette for the terminal's text panel (bin/term-palette.mjs): what it shows, and a change as the panel would make it
|
|
5405
|
+
globalThis.__palette = () => ({
|
|
5406
|
+
current: ui.paint.current,
|
|
5407
|
+
items: materials.map((m) => ({ name: m.name, color: m.color, alpha: m.alpha ?? 1, metal: m.metal ?? 0 })),
|
|
5408
|
+
props: PROPS.map((k) => {
|
|
5409
|
+
const el = document.getElementById(`p-${k}`);
|
|
5410
|
+
return { key: k, value: Number(materials[ui.paint.current]?.[k] ?? 0), min: Number(el.min), max: Number(el.max), step: Number(el.step) };
|
|
5411
|
+
}),
|
|
5412
|
+
});
|
|
5413
|
+
globalThis.__paletteSet = (a) => {
|
|
5414
|
+
if (Number.isInteger(a?.current) && materials[a.current]) ui.paint.current = a.current;
|
|
5415
|
+
if (a?.key && PROPS.includes(a.key)) {
|
|
5416
|
+
const el = document.getElementById(`p-${a.key}`);
|
|
5417
|
+
el.value = a.value;
|
|
5418
|
+
el.dispatchEvent(new Event('input'));
|
|
5419
|
+
el.dispatchEvent(new Event('change'));
|
|
5420
|
+
}
|
|
5421
|
+
return globalThis.__palette();
|
|
5422
|
+
};
|
|
5404
5423
|
for (const k of PROPS) {
|
|
5405
5424
|
document.getElementById(`p-${k}`).addEventListener('input', (e) => {
|
|
5406
5425
|
const m = materials[ui.paint.current];
|
|
@@ -8177,6 +8196,46 @@
|
|
|
8177
8196
|
}
|
|
8178
8197
|
redraw();
|
|
8179
8198
|
};
|
|
8199
|
+
// Y (and /text) outside edit mode: text where you look. Over a face the first letter starts at the cross, on that face
|
|
8200
|
+
// and in its direction (the side you see); over empty space the text stands in front of the camera, facing it, a
|
|
8201
|
+
// standard distance along the cursor's ray. The letters are TEXT_PX screen pixels high where they are made (whatever
|
|
8202
|
+
// the zoom or the scene's size). The same text model as T in edit mode (a double click fixes the words).
|
|
8203
|
+
const TEXT_PX = 28;
|
|
8204
|
+
const textFrameHere = () => {
|
|
8205
|
+
if (!cam) return null;
|
|
8206
|
+
const cr = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
8207
|
+
const unit = (a) => { const l = Math.hypot(...a) || 1; return a.map((c) => c / l); };
|
|
8208
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
8209
|
+
const at = cam.at ?? { x: innerWidth / 2, y: innerHeight / 2 };
|
|
8210
|
+
const { origin, dir } = ray(cam, at.x, at.y);
|
|
8211
|
+
// the angle TEXT_PX pixels make on screen there: the letter height is that angle times the distance
|
|
8212
|
+
const px = Math.acos(Math.min(1, dot(dir, ray(cam, at.x, at.y - TEXT_PX).dir)));
|
|
8213
|
+
if (hit && scene.faces?.[hit.face] && !aim) {
|
|
8214
|
+
const ff = faceFrame(scene, hit.face);
|
|
8215
|
+
const back = dot(ff.normal, dir) > 0; // (seen from behind: the text goes on the side you see)
|
|
8216
|
+
const normal = back ? ff.normal.map((c) => -c) : ff.normal;
|
|
8217
|
+
const dist = Math.hypot(...hit.point.map((c, i) => c - origin[i]));
|
|
8218
|
+
// a floor or a ceiling: the letters stand up away from you (the view's direction laid on the face), so they read
|
|
8219
|
+
const along = dir.map((c, i) => c - normal[i] * dot(dir, normal));
|
|
8220
|
+
const up = Math.abs(normal[1]) > 0.9 && Math.hypot(...along) > 1e-3 ? unit(along) : ff.up;
|
|
8221
|
+
return { origin: [...hit.point], right: unit(cr(up, normal)), up, normal, height: Math.max(1e-4, px * dist) };
|
|
8222
|
+
}
|
|
8223
|
+
const d = orbitDist(fit.radius) * 0.5;
|
|
8224
|
+
const normal = dir.map((c) => -c); // facing the eye
|
|
8225
|
+
let up = cam.u.map((c, i) => c - normal[i] * dot(cam.u, normal));
|
|
8226
|
+
up = unit(Math.hypot(...up) < 1e-6 ? [0, 1, 0] : up);
|
|
8227
|
+
return { origin: origin.map((c, i) => c + dir[i] * d), right: unit(cr(up, normal)), up, normal, height: Math.max(1e-4, px * d) };
|
|
8228
|
+
};
|
|
8229
|
+
const startTextHere = (words = '') => {
|
|
8230
|
+
if (editing) return startText();
|
|
8231
|
+
const frame = textFrameHere();
|
|
8232
|
+
if (!frame) return;
|
|
8233
|
+
if (words.trim()) {
|
|
8234
|
+
askText({ frame, text: words });
|
|
8235
|
+
return putText();
|
|
8236
|
+
}
|
|
8237
|
+
askText({ frame, text: '' });
|
|
8238
|
+
};
|
|
8180
8239
|
textBox.addEventListener('keydown', (e) => {
|
|
8181
8240
|
e.stopPropagation(); // typing words is not a command
|
|
8182
8241
|
if (e.key === 'Enter') putText();
|
|
@@ -8999,6 +9058,9 @@
|
|
|
8999
9058
|
} else if (e.key === 'm' || e.key === 'M') {
|
|
9000
9059
|
e.preventDefault();
|
|
9001
9060
|
if (!e.repeat) place();
|
|
9061
|
+
} else if ((e.key === 'y' || e.key === 'Y') && !editing && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
9062
|
+
e.preventDefault();
|
|
9063
|
+
if (!e.repeat) startTextHere();
|
|
9002
9064
|
} else if (boolPair && /^[1-5]$/.test(e.key)) {
|
|
9003
9065
|
e.preventDefault();
|
|
9004
9066
|
if (e.key === '5') closeBool(), redraw();
|
|
@@ -9299,6 +9361,7 @@
|
|
|
9299
9361
|
l: { cap: 'L', sub: 'light', cat: 'teal', text: 'Light on / off. Off: no light in the scene at all, only emitting surfaces and the edge lines show.', edit: 'Loop: a selected line (2) takes the lines of its loop, a selected face (3) the faces of its loop (L again: the other way round). The light switch stays on its button.' },
|
|
9300
9362
|
enter: { cap: 'Enter', sub: 'find', cat: 'teal', w: 2.2, title: 'Enter', text: 'Find: a box in the middle of the screen, type a name, Enter targets it. / starts a command: /l (load) searches the scene list.', edit: 'Saw: cuts along the marked plane. Shift+Enter: the find / command box in the edit mode too.' },
|
|
9301
9363
|
shift: { cap: 'Shift', sub: 'paint', cat: 'slate', w: 2.4, title: 'Shift', text: 'Shift+Tab: previous target. Painting is Ctrl+click (Cmd on a Mac).', edit: 'Shift+click adds to the selection or takes from it. Shift+W A S D R F fly (plain, they are edit keys).', run: false },
|
|
9364
|
+
y: { cap: 'Y', sub: 'text', cat: 'red', text: 'Text: type words, Enter puts them down: on the face under the cross (the first letter at the cross), or in front of the camera over empty space.', edit: 'T makes text in edit mode (on the selected face).' },
|
|
9302
9365
|
z: { cap: 'Z', sub: 'zen', cat: 'slate', text: 'Zen: hide everything but the model. Z or Esc brings the panels back.' },
|
|
9303
9366
|
x: { cap: 'X', sub: 'del', cat: 'red', text: 'Shift+X deletes the object under the cross, in every mode (U brings it back). Alone, during G / S / R, X locks the axis to x.', edit: 'Shift+X deletes the selected points, lines or faces (a point takes its faces, a line the faces on it); with nothing selected, the object under the cross. During G / S: locks the axis to x.' },
|
|
9304
9367
|
c: { cap: 'C', sub: 'glow', cat: 'teal', text: 'Glow: emitting materials light their surroundings as local lights (no shadows). With the light off, only they light the scene.' },
|
|
@@ -10424,6 +10487,11 @@
|
|
|
10424
10487
|
placeBrush({ name: a, mesh: make({ color: mat()?.color ?? '#c8c8c8', mat: mat()?.name }) });
|
|
10425
10488
|
return `${a}: a click sticks it to a surface, Enter keeps it, Esc takes it back (M puts down more)`;
|
|
10426
10489
|
} },
|
|
10490
|
+
{ names: ['text'], hint: 'put words down: on the face under the cross, or in front of the camera (Y)', free: true, bare: 'type them in the text box', run: (a) => {
|
|
10491
|
+
const words = (a ?? '').trim();
|
|
10492
|
+
startTextHere(words);
|
|
10493
|
+
return words ? `text: “${words}”` : '';
|
|
10494
|
+
} },
|
|
10427
10495
|
{ names: ['char', 'character'], hint: 'put a character down: random, or the one the panel shows', choices: () => [{ label: 'random', value: 'random', cat: 'a new one' }, { label: 'panel', value: 'panel', cat: 'the one set in the panel' }], bare: 'a random one', run: async (a) => {
|
|
10428
10496
|
if (!charControls.children.length) {
|
|
10429
10497
|
openCharacters();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spider-paint",
|
|
3
|
-
"version": "26.11.
|
|
3
|
+
"version": "26.11.26003",
|
|
4
4
|
"description": "Spider Paint: the test and community workshop of the 3Draft engine (custom MCP test program)",
|
|
5
5
|
"brand": {
|
|
6
6
|
"repo": "Pengeszikra/spider-paint",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"scripts/spider-build.test.mjs",
|
|
22
22
|
"scripts/spider-build.browser-test.py",
|
|
23
23
|
"scripts/build-modular-characters.mjs",
|
|
24
|
-
"scripts/modular-characters.test.mjs"
|
|
24
|
+
"scripts/modular-characters.test.mjs",
|
|
25
|
+
"vim/",
|
|
26
|
+
"VIM-PLUGIN.md"
|
|
25
27
|
],
|
|
26
28
|
"share": [
|
|
27
29
|
"models/spider-build-v2.mjs",
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
"scripts": {
|
|
43
45
|
"start": "node bin/spider-paint.mjs",
|
|
44
46
|
"term": "node bin/spider-term.mjs",
|
|
47
|
+
"docs": "node scripts/docs-page.mjs",
|
|
45
48
|
"test": "node tests/math.mjs && node tests/smoke.mjs && node tests/instance.mjs && node tests/materials.mjs && node tests/svg-export.mjs && node tests/state.mjs && node tests/term.mjs && node vscode/test.mjs && node tests/md.mjs",
|
|
46
49
|
"test:all": "node scripts/test-all.mjs",
|
|
47
50
|
"bump": "node scripts/bump.mjs",
|
package/src/md/highlight.js
CHANGED
|
@@ -479,7 +479,7 @@ const SH_RW = new Set('if then else elif fi for while until do done case esac in
|
|
|
479
479
|
export const lexShell = (src, out = []) => {
|
|
480
480
|
for (const line of src.split(/(?<=\n)/)) {
|
|
481
481
|
let first = true;
|
|
482
|
-
const re = /(
|
|
482
|
+
const re = /(#.*)|("(?:[^"\\]|\\.)*"|'[^']*')|(\$\{[^}]*\}|\$\w+|\$[?#@*0-9])|(\s--?[\w-]+)|([|&;<>]+|&&|\|\|)|(\d+\b)|([\w./~@:+-]+)|(\s+)|(.)/gy;
|
|
483
483
|
for (const m of line.matchAll(re)) {
|
|
484
484
|
const [t, cm, st, vr, flag, op, nm, word] = m;
|
|
485
485
|
if (word) {
|
package/src/term-render.js
CHANGED
|
@@ -131,6 +131,64 @@ export const ansiLines = (img) => {
|
|
|
131
131
|
};
|
|
132
132
|
export const toAnsi = (img) => ansiLines(img).join('\n');
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The pixel grid as cells for a frame-to-frame diff: rows of [fg, bg, ch] ("r;g;b" or '' for the terminal's own,
|
|
136
|
+
* "▀" / "▄" / " "). quant: the low bits of each colour channel dropped (0: exact; 3: 32 levels a channel), so noise
|
|
137
|
+
* and slow gradients change fewer cells and neighbours share their colour codes more often.
|
|
138
|
+
*/
|
|
139
|
+
export const cellRows = (img, quant = 0) => {
|
|
140
|
+
const { width: W, height: H, rgb: c, set } = img;
|
|
141
|
+
const q = quant > 0 ? (v) => Math.min(255, ((v >> quant) << quant) + (1 << (quant - 1))) : (v) => v;
|
|
142
|
+
const col = (k) => `${q(c[k * 3])};${q(c[k * 3 + 1])};${q(c[k * 3 + 2])}`;
|
|
143
|
+
const rows = [];
|
|
144
|
+
for (let y = 0; y < H; y += 2) {
|
|
145
|
+
const row = new Array(W);
|
|
146
|
+
for (let x = 0; x < W; x++) {
|
|
147
|
+
const a = y * W + x, b = (y + 1) * W + x;
|
|
148
|
+
const top = set[a], bot = y + 1 < H && set[b];
|
|
149
|
+
row[x] = top && bot ? (col(a) === col(b) ? ['', col(a), ' '] : [col(a), col(b), '▀']) : top ? [col(a), '', '▀'] : bot ? [col(b), '', '▄'] : ['', '', ' '];
|
|
150
|
+
}
|
|
151
|
+
rows.push(row);
|
|
152
|
+
}
|
|
153
|
+
return rows;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Only what changed: the escape codes that turn the cells of `prev` into `next` on screen line `line` (1-based); a
|
|
158
|
+
* missing prev redraws the whole row. Runs of changed cells with gaps of up to `gap` unchanged cells are joined (a
|
|
159
|
+
* cursor jump costs about as much); within a run only the colour that changes is sent (38;2 or 48;2, not both).
|
|
160
|
+
*/
|
|
161
|
+
export const diffRow = (prev, next, line, gap = 4) => {
|
|
162
|
+
let out = '';
|
|
163
|
+
const same = (x) => prev && prev[x] && prev[x][0] === next[x][0] && prev[x][1] === next[x][1] && prev[x][2] === next[x][2];
|
|
164
|
+
for (let x = 0; x < next.length; ) {
|
|
165
|
+
if (same(x)) {
|
|
166
|
+
x++;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
// a run: up to the last changed cell that is followed by more than `gap` unchanged ones
|
|
170
|
+
let end = x + 1, quiet = 0;
|
|
171
|
+
for (let k = x + 1; k < next.length && quiet <= gap; k++) {
|
|
172
|
+
if (same(k)) quiet++;
|
|
173
|
+
else (quiet = 0), (end = k + 1);
|
|
174
|
+
}
|
|
175
|
+
out += `\x1b[${line};${x + 1}H`;
|
|
176
|
+
let fg = null, bg = null;
|
|
177
|
+
for (let k = x; k < end; k++) {
|
|
178
|
+
const [f, b, ch] = next[k];
|
|
179
|
+
const codes = [];
|
|
180
|
+
// (a space shows no foreground: it keeps whatever is set)
|
|
181
|
+
if (f !== fg && ch !== ' ') (codes.push(f ? `38;2;${f}` : '39'), (fg = f));
|
|
182
|
+
if (b !== bg) (codes.push(b ? `48;2;${b}` : '49'), (bg = b));
|
|
183
|
+
if (codes.length) out += `\x1b[${codes.join(';')}m`;
|
|
184
|
+
out += ch;
|
|
185
|
+
}
|
|
186
|
+
out += '\x1b[0m';
|
|
187
|
+
x = end;
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
};
|
|
191
|
+
|
|
134
192
|
export const renderTerm = (mesh, { cols = 80, rows = 24, ...view } = {}) => toAnsi(rasterize(mesh, { width: cols, height: rows * 2, ...view }));
|
|
135
193
|
|
|
136
194
|
/** The zoom that makes `mesh` (or `fit`) fill about `fill` of a width × height grid as seen from yaw / pitch now. */
|