terminal-png 0.1.5 → 0.1.7

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 Poe Platform
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
@@ -14,14 +14,22 @@ await renderTerminalPng(ansiText, {
14
14
  });
15
15
  ```
16
16
 
17
- Options:
17
+ ## Configuration Options
18
18
 
19
19
  - `output`: path to the output PNG file
20
20
  - `window`: include terminal window chrome
21
- - `padding`: padding around the rendered terminal content
21
+ - `padding`: non-negative integer padding around the rendered terminal content
22
+
23
+ The ANSI parser supports common SGR styling, cursor positioning and movement, save/restore cursor,
24
+ erase-in-line/display, tabs, double-width characters, and combining marks. Parsed terminal state is
25
+ bounded to 1000 rows by 1000 columns to avoid unbounded renders from hostile control sequences.
22
26
 
23
27
  ## CLI
24
28
 
25
29
  ```sh
26
30
  terminal-png <input.ansi> -o <output.png> [--window] [--padding 20]
27
31
  ```
32
+
33
+ ## Environment Variables
34
+
35
+ This package does not read public environment variables. The comparison script inherits `PATH` only to locate the local CLI under test.
@@ -1,4 +1,5 @@
1
1
  import { FONT_FACE_CSS } from "./font.js";
2
+ const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
2
3
  const ANSI_16_PALETTE = [
3
4
  "#282a2e",
4
5
  "#D74E6F",
@@ -117,7 +118,6 @@ function measureLines(lines) {
117
118
  return Math.max(...lines.map((line) => displayWidth(line.map((run) => run.text).join("")) * CHARACTER_WIDTH), 0);
118
119
  }
119
120
  function displayWidth(text, startColumn = 0) {
120
- const segmenter = new Intl.Segmenter();
121
121
  let column = startColumn;
122
122
  for (const { segment } of segmenter.segment(text)) {
123
123
  if (segment === "\t") {
@@ -165,13 +165,38 @@ function renderLines(lines, textStartX, textStartY, lineHeightPx) {
165
165
  return lines
166
166
  .map((line, index) => {
167
167
  const y = formatNumber(textStartY + (index * lineHeightPx));
168
+ let column = 0;
168
169
  if (line.length === 0) {
169
170
  return `<text x="${formatNumber(textStartX)}" y="${y}" xml:space="preserve"/>`;
170
171
  }
171
172
  return [
172
173
  renderBackgrounds(line, textStartX, textStartY + (index * lineHeightPx) - lineHeightPx, lineHeightPx),
173
174
  `<text x="${formatNumber(textStartX)}" y="${y}" xml:space="preserve">`,
174
- line.map(renderRun).join(""),
175
+ line.flatMap((run) => {
176
+ const spans = [];
177
+ let text = "";
178
+ let start = column;
179
+ for (const { segment } of segmenter.segment(run.text)) {
180
+ const width = displayWidth(segment, column);
181
+ if (width !== 1 || Array.from(segment).length !== 1) {
182
+ if (text.length > 0)
183
+ spans.push(renderRun({ ...run, text }, textStartX + start * CHARACTER_WIDTH));
184
+ text = "";
185
+ if (segment !== "\t" && width > 0) {
186
+ spans.push(renderRun({ ...run, text: segment }, textStartX + column * CHARACTER_WIDTH));
187
+ }
188
+ column += width;
189
+ start = column;
190
+ }
191
+ else {
192
+ text += segment;
193
+ column += 1;
194
+ }
195
+ }
196
+ if (text.length > 0)
197
+ spans.push(renderRun({ ...run, text }, textStartX + start * CHARACTER_WIDTH));
198
+ return spans;
199
+ }).join(""),
175
200
  "</text>"
176
201
  ].join("");
177
202
  })
@@ -190,7 +215,7 @@ function renderBackgrounds(line, startX, y, height) {
190
215
  }
191
216
  return rectangles.join("");
192
217
  }
193
- function renderRun(run) {
218
+ function renderRun(run, x) {
194
219
  const attributes = ['xml:space="preserve"'];
195
220
  const color = resolveForegroundColor(run);
196
221
  const textDecorations = [];
@@ -216,6 +241,8 @@ function renderRun(run) {
216
241
  attributes.push('opacity="0.7"');
217
242
  }
218
243
  const text = run.conceal ? " ".repeat(displayWidth(run.text)) : run.text;
244
+ const positions = [...segmenter.segment(run.text)].map((_, index) => formatNumber(x + index * CHARACTER_WIDTH));
245
+ attributes.push(`x="${positions.join(" ")}"`);
219
246
  return `<tspan ${attributes.join(" ")}>${escapeXmlText(text)}</tspan>`;
220
247
  }
221
248
  function renderWindowControls() {
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "terminal-png",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
+ "license": "MIT",
4
5
  "description": "Render PNG images from ANSI terminal output.",
5
6
  "type": "module",
6
7
  "main": "./dist/index.js",
@@ -15,6 +16,7 @@
15
16
  "compare": "tsx scripts/compare.ts"
16
17
  },
17
18
  "files": [
19
+ "LICENSE",
18
20
  "dist",
19
21
  "bin",
20
22
  "assets"
@@ -26,7 +28,7 @@
26
28
  },
27
29
  "dependencies": {
28
30
  "@resvg/resvg-js": "^2.6.2",
29
- "commander": "^14.0.3",
31
+ "commander": "^13.1.0",
30
32
  "jetbrains-mono": "^1.0.6"
31
33
  }
32
34
  }