tmux-weblink 3.2.0 → 3.2.2

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.
@@ -1,6 +1,10 @@
1
- // Generates PWA icons (PNG) with a terminal-window icon design.
2
- // Uses pure Node.js (zlib) — no external dependencies.
3
- import { deflateRawSync } from "node:zlib";
1
+ // Generates the PWA icons with pure Node (zlib only) — no build tooling needed.
2
+ //
3
+ // Design: a full-bleed square (the OS applies its own mask, so no inner rounded
4
+ // rectangle), a quiet vertical gradient, a soft accent glow behind the glyph and
5
+ // a bold ">_" prompt. The maskable variant keeps the glyph inside the safe zone
6
+ // (80% circle) so Android never crops it.
7
+ import { deflateSync } from "node:zlib";
4
8
  import { writeFileSync, mkdirSync } from "node:fs";
5
9
  import { join, dirname } from "node:path";
6
10
  import { fileURLToPath } from "node:url";
@@ -8,160 +12,147 @@ import { fileURLToPath } from "node:url";
8
12
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
13
  const ICONS_DIR = join(__dirname, "..", "dist", "assets");
10
14
 
15
+ const BG_TOP = [16, 22, 31];
16
+ const BG_BOTTOM = [9, 12, 17];
17
+ const ACCENT = [125, 211, 252];
18
+ const SUPERSAMPLE = 4;
19
+
11
20
  function crc32(buf) {
12
- let crc = 0xffffffff;
13
- for (let i = 0; i < buf.length; i++) {
14
- crc ^= buf[i];
15
- for (let j = 0; j < 8; j++) crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
16
- }
17
- return (crc ^ 0xffffffff) >>> 0;
21
+ let crc = 0xffffffff;
22
+ for (let i = 0; i < buf.length; i++) {
23
+ crc ^= buf[i];
24
+ for (let j = 0; j < 8; j++) crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
25
+ }
26
+ return (crc ^ 0xffffffff) >>> 0;
18
27
  }
19
28
 
20
29
  function pngChunk(type, data) {
21
- const len = Buffer.alloc(4);
22
- len.writeUInt32BE(data.length);
23
- const typeB = Buffer.from(type, "ascii");
24
- const crc = Buffer.alloc(4);
25
- crc.writeUInt32BE(crc32(Buffer.concat([typeB, data])));
26
- return Buffer.concat([len, typeB, data, crc]);
30
+ const len = Buffer.alloc(4);
31
+ len.writeUInt32BE(data.length);
32
+ const typeB = Buffer.from(type, "ascii");
33
+ const crc = Buffer.alloc(4);
34
+ crc.writeUInt32BE(crc32(Buffer.concat([typeB, data])));
35
+ return Buffer.concat([len, typeB, data, crc]);
27
36
  }
28
37
 
29
38
  function createPNG(width, height, getPixel) {
30
- const stride = 1 + width * 4;
31
- const raw = Buffer.alloc(height * stride);
32
- for (let y = 0; y < height; y++) {
33
- raw[y * stride] = 0;
34
- for (let x = 0; x < width; x++) {
35
- const [r, g, b, a] = getPixel(x, y);
36
- const p = y * stride + 1 + x * 4;
37
- raw[p] = Math.max(0, Math.min(255, Math.round(r)));
38
- raw[p+1] = Math.max(0, Math.min(255, Math.round(g)));
39
- raw[p+2] = Math.max(0, Math.min(255, Math.round(b)));
40
- raw[p+3] = Math.max(0, Math.min(255, Math.round(a)));
41
- }
42
- }
43
-
44
- const compressed = deflateRawSync(raw);
45
- const ihdr = Buffer.alloc(13);
46
- ihdr.writeUInt32BE(width, 0);
47
- ihdr.writeUInt32BE(height, 4);
48
- ihdr[8] = 8; ihdr[9] = 6; ihdr[10] = 0; ihdr[11] = 0; ihdr[12] = 0;
49
-
50
- const sig = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
51
- return Buffer.concat([sig, pngChunk("IHDR", ihdr), pngChunk("IDAT", compressed), pngChunk("IEND", Buffer.alloc(0))]);
39
+ const stride = 1 + width * 4;
40
+ const raw = Buffer.alloc(height * stride);
41
+ for (let y = 0; y < height; y++) {
42
+ raw[y * stride] = 0;
43
+ for (let x = 0; x < width; x++) {
44
+ const [r, g, b, a] = getPixel(x, y);
45
+ const p = y * stride + 1 + x * 4;
46
+ raw[p] = Math.max(0, Math.min(255, Math.round(r)));
47
+ raw[p + 1] = Math.max(0, Math.min(255, Math.round(g)));
48
+ raw[p + 2] = Math.max(0, Math.min(255, Math.round(b)));
49
+ raw[p + 3] = Math.max(0, Math.min(255, Math.round(a)));
50
+ }
51
+ }
52
+ // PNG IDAT must be a zlib stream (raw deflate decodes as a corrupt PNG).
53
+ const compressed = deflateSync(raw, { level: 9 });
54
+ const ihdr = Buffer.alloc(13);
55
+ ihdr.writeUInt32BE(width, 0);
56
+ ihdr.writeUInt32BE(height, 4);
57
+ ihdr[8] = 8;
58
+ ihdr[9] = 6;
59
+ const signature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
60
+ return Buffer.concat([
61
+ signature,
62
+ pngChunk("IHDR", ihdr),
63
+ pngChunk("IDAT", compressed),
64
+ pngChunk("IEND", Buffer.alloc(0)),
65
+ ]);
66
+ }
67
+
68
+ /** Distance from a point to a line segment with round caps. */
69
+ function segmentDistance(px, py, x1, y1, x2, y2) {
70
+ const dx = x2 - x1;
71
+ const dy = y2 - y1;
72
+ const length2 = dx * dx + dy * dy;
73
+ const t = length2 === 0 ? 0 : Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / length2));
74
+ return Math.hypot(px - (x1 + t * dx), py - (y1 + t * dy));
52
75
  }
53
76
 
54
- function sdist(px, py, x1, y1, x2, y2) {
55
- const dx = x2 - x1, dy = y2 - y1;
56
- const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy)));
57
- return Math.sqrt((px - (x1 + t * dx)) ** 2 + (py - (y1 + t * dy)) ** 2);
77
+ function mix(a, b, t) {
78
+ return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
58
79
  }
59
80
 
60
- function generateIcon(size) {
61
- const ss = 4; // supersample
62
- const s = size * ss;
63
- const half = s / 2;
64
-
65
- // Color palette
66
- const bg = [13, 17, 23]; // #0d1117
67
- const accent = [125, 211, 252]; // #7dd3fc
68
- const glow = [30, 60, 90];
69
-
70
- const accum = new Float64Array(size * size * 4);
71
-
72
- for (let sy = 0; sy < s; sy++) {
73
- for (let sx = 0; sx < s; sx++) {
74
- // Normalize to -1..1 with aspect ratio
75
- const x = (sx / s) * 2 - 1;
76
- const y = (sy / s) * 2 - 1;
77
-
78
- // Terminal window: rounded rect shape
79
- const rx = 0.85, ry = 0.8, cr = 0.2;
80
- let dist;
81
- // Distance to rounded rect
82
- const ax = Math.abs(x) - (rx - cr), ay = Math.abs(y) - (ry - cr);
83
- if (ax > 0 && ay > 0) {
84
- dist = Math.sqrt(ax * ax + ay * ay);
85
- } else if (ax > 0) {
86
- dist = ax;
87
- } else if (ay > 0) {
88
- dist = ay;
89
- } else {
90
- dist = Math.max(ax, ay); // inside
91
- }
92
-
93
- // Anti-aliased edge
94
- if (dist > 0.015) continue; // outside, skip
95
- const alpha = dist < -0.015 ? 1 : (1 - (dist + 0.015) / 0.03);
96
-
97
- // Pixel color
98
- let r = bg[0], g = bg[1], b = bg[2];
99
-
100
- // Draw a subtle glow inside
101
- const innerGlow = Math.sqrt(x * x + y * y) / 0.9;
102
- if (innerGlow < 0.8) {
103
- const t = 1 - innerGlow / 0.8;
104
- r += Math.round(glow[0] * t * 0.5);
105
- g += Math.round(glow[1] * t * 0.5);
106
- b += Math.round(glow[2] * t * 0.5);
107
- }
108
-
109
- // Draw ">_" prompt using simple geometric shapes
110
- // ">" chevron: two angled strokes
111
- const px = 0.05, py = 0.0;
112
-
113
- // Upper stroke of ">"
114
- const d1 = sdist(x, y, px - 0.15, py - 0.15, px + 0.15, py + 0.15);
115
- // Lower stroke of ">"
116
- const d2 = sdist(x, y, px - 0.15, py + 0.15, px + 0.15, py - 0.15);
117
-
118
- const strokeW = 0.04;
119
- const strokeGlow = 0.02;
120
-
121
- if (d1 < strokeW + strokeGlow || d2 < strokeW + strokeGlow) {
122
- const t = Math.min(1, Math.max(0, 1 - (Math.min(d1, d2) - strokeW) / strokeGlow));
123
- r = Math.round(r + (accent[0] - r) * t);
124
- g = Math.round(g + (accent[1] - g) * t);
125
- b = Math.round(b + (accent[2] - b) * t);
126
- }
127
-
128
- // "_" cursor to the right
129
- const cu = 0.32, cv = 0.18;
130
- const dc = Math.abs(y - cv);
131
- const hc = Math.abs(x - cu);
132
- const cw = 0.12, ch = 0.03;
133
- if (hc < cw && dc < ch) {
134
- const t = Math.min(1, 1 - (dc - ch * 0.6) / (ch * 0.4));
135
- const t2 = Math.min(1, 1 - Math.max(0, x - (cu - cw * 0.6)) / (cw * 0.4));
136
- const t3 = Math.min(1, 1 - Math.max(0, (cu + cw * 0.6) - x) / (cw * 0.4));
137
- const final = Math.min(t, Math.max(t2, t3));
138
- r = Math.round(r + (accent[0] - r) * final);
139
- g = Math.round(g + (accent[1] - g) * final);
140
- b = Math.round(b + (accent[2] - b) * final);
141
- }
142
-
143
- // Accumulate into output
144
- const oi = (Math.floor(sy / ss) * size + Math.floor(sx / ss)) * 4;
145
- accum[oi] += r * alpha;
146
- accum[oi+1] += g * alpha;
147
- accum[oi+2] += b * alpha;
148
- accum[oi+3] += alpha;
149
- }
150
- }
151
-
152
- return createPNG(size, size, (x, y) => {
153
- const i = (y * size + x) * 4;
154
- const a = accum[i+3];
155
- if (a === 0) return [0, 0, 0, 0];
156
- const inv = 1 / (ss * ss);
157
- return [accum[i] / a, accum[i+1] / a, accum[i+2] / a, Math.round(a * inv * 255)];
158
- });
81
+ function renderIcon(size, { maskable = false } = {}) {
82
+ // Glyph geometry in unit coordinates; maskable art shrinks toward the centre.
83
+ const scale = maskable ? 0.72 : 1;
84
+ const chevron = [
85
+ [0.30, 0.38, 0.44, 0.5],
86
+ [0.44, 0.5, 0.30, 0.62],
87
+ ];
88
+ const cursor = [0.51, 0.62, 0.68, 0.62];
89
+ const stroke = 0.042 * scale;
90
+ const point = ([x1, y1, x2, y2]) => [
91
+ 0.5 + (x1 - 0.5) * scale,
92
+ 0.5 + (y1 - 0.5) * scale,
93
+ 0.5 + (x2 - 0.5) * scale,
94
+ 0.5 + (y2 - 0.5) * scale,
95
+ ];
96
+ const strokes = [...chevron.map(point), point(cursor)];
97
+
98
+ const ss = SUPERSAMPLE;
99
+ const large = size * ss;
100
+ const accum = new Float64Array(size * size * 4);
101
+
102
+ for (let sy = 0; sy < large; sy++) {
103
+ for (let sx = 0; sx < large; sx++) {
104
+ const x = (sx + 0.5) / large;
105
+ const y = (sy + 0.5) / large;
106
+
107
+ // Background: vertical gradient plus a soft glow behind the glyph.
108
+ let [r, g, b] = mix(BG_TOP, BG_BOTTOM, y);
109
+ const glow = Math.max(0, 1 - Math.hypot(x - 0.46, y - 0.5) / 0.62);
110
+ const glowAmount = glow * glow * 0.16;
111
+ r += (ACCENT[0] - r) * glowAmount;
112
+ g += (ACCENT[1] - g) * glowAmount;
113
+ b += (ACCENT[2] - b) * glowAmount;
114
+
115
+ // Glyph: distance to the nearest stroke, anti-aliased at the edge.
116
+ let distance = Infinity;
117
+ for (const [x1, y1, x2, y2] of strokes) {
118
+ distance = Math.min(distance, segmentDistance(x, y, x1, y1, x2, y2));
119
+ }
120
+ const edge = 1.4 / large;
121
+ const coverage = Math.max(0, Math.min(1, (stroke - distance) / edge + 0.5));
122
+ if (coverage > 0) {
123
+ r += (ACCENT[0] - r) * coverage;
124
+ g += (ACCENT[1] - g) * coverage;
125
+ b += (ACCENT[2] - b) * coverage;
126
+ }
127
+
128
+ const oi = (Math.floor(sy / ss) * size + Math.floor(sx / ss)) * 4;
129
+ accum[oi] += r;
130
+ accum[oi + 1] += g;
131
+ accum[oi + 2] += b;
132
+ accum[oi + 3] += 255;
133
+ }
134
+ }
135
+
136
+ const samples = ss * ss;
137
+ return createPNG(size, size, (x, y) => {
138
+ const i = (y * size + x) * 4;
139
+ return [accum[i] / samples, accum[i + 1] / samples, accum[i + 2] / samples, 255];
140
+ });
159
141
  }
160
142
 
143
+ const OUTPUTS = [
144
+ ["icon-192.png", 192, {}],
145
+ ["icon-512.png", 512, {}],
146
+ ["icon-maskable-192.png", 192, { maskable: true }],
147
+ ["icon-maskable-512.png", 512, { maskable: true }],
148
+ // iOS ignores the manifest and wants a square, opaque apple-touch-icon.
149
+ ["apple-touch-icon-180.png", 180, {}],
150
+ ];
151
+
161
152
  mkdirSync(ICONS_DIR, { recursive: true });
162
- for (const size of [192, 512]) {
163
- const png = generateIcon(size);
164
- const outPath = join(ICONS_DIR, `icon-${size}.png`);
165
- writeFileSync(outPath, png);
166
- console.log(`[generate-icons] wrote ${outPath} (${png.length} bytes)`);
153
+ for (const [name, size, options] of OUTPUTS) {
154
+ const png = renderIcon(size, options);
155
+ const outPath = join(ICONS_DIR, name);
156
+ writeFileSync(outPath, png);
157
+ console.log(`[generate-icons] wrote ${outPath} (${png.length} bytes)`);
167
158
  }