@nbtca/prompt 1.5.22 → 1.5.23

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.
Files changed (37) hide show
  1. package/dist/app/ambient.js +98 -0
  2. package/dist/app/app.js +3 -2
  3. package/dist/app/chrome.js +6 -2
  4. package/dist/app/views/docs-render.js +23 -15
  5. package/dist/app/views/docs.js +3 -0
  6. package/dist/app/views/events-render.js +57 -21
  7. package/dist/app/views/events.js +62 -9
  8. package/dist/app/views/home.js +66 -31
  9. package/dist/app/views/schedule-render.js +9 -2
  10. package/dist/app/views/schedule.js +7 -1
  11. package/dist/app/views/settings-render.js +13 -2
  12. package/dist/app/views/settings.js +27 -1
  13. package/dist/art/bitmaps.js +76 -0
  14. package/dist/art/glyphs.js +101 -0
  15. package/dist/art/motifs.js +198 -0
  16. package/dist/art/noise.js +43 -0
  17. package/dist/art/planet.js +184 -0
  18. package/dist/art/scene.js +446 -0
  19. package/dist/config/preferences.js +8 -1
  20. package/dist/core/components/empty-state.js +50 -0
  21. package/dist/core/components/menu.js +2 -2
  22. package/dist/core/components/picture.js +18 -0
  23. package/dist/core/logo.js +62 -43
  24. package/dist/core/pixel-art-fine.js +157 -0
  25. package/dist/core/pixel-art.js +223 -0
  26. package/dist/core/theme.js +1 -1
  27. package/dist/features/calendar-heatmap.js +35 -10
  28. package/dist/features/calendar.js +2 -2
  29. package/dist/features/event-art.js +16 -0
  30. package/dist/features/schedule-view.js +10 -0
  31. package/dist/i18n/locales/en.json +14 -5
  32. package/dist/i18n/locales/zh.json +13 -4
  33. package/dist/logo/ascii-emblem-large.txt +22 -0
  34. package/dist/logo/ascii-emblem-medium.txt +15 -0
  35. package/dist/logo/ascii-emblem.txt +11 -0
  36. package/dist/logo/ascii-logo.txt +3 -12
  37. package/package.json +3 -3
@@ -0,0 +1,446 @@
1
+ const ASCII_SYMBOLS = Array.from({ length: 94 }, (_, index) => String.fromCharCode(0x21 + index));
2
+ const FINE = { x: 2, y: 4 };
3
+ function hexToRgb(hex) {
4
+ return [1, 3, 5].map((index) => Number.parseInt(hex.slice(index, index + 2), 16));
5
+ }
6
+ function rgbToHex(rgb) {
7
+ return `#${rgb.map((value) => Math.round(value).toString(16).padStart(2, '0')).join('')}`;
8
+ }
9
+ function mix(from, to, amount) {
10
+ const a = hexToRgb(from);
11
+ const b = hexToRgb(to);
12
+ const t = Math.min(1, Math.max(0, amount));
13
+ return rgbToHex([0, 1, 2].map((index) => (a[index] ?? 0) + ((b[index] ?? 0) - (a[index] ?? 0)) * t));
14
+ }
15
+ class Canvas {
16
+ width;
17
+ height;
18
+ cells;
19
+ constructor(width, height) {
20
+ this.width = width;
21
+ this.height = height;
22
+ this.cells = Array.from({ length: height }, () => Array(width).fill(null));
23
+ }
24
+ get(x, y) {
25
+ return this.cells[Math.round(y)]?.[Math.round(x)] ?? null;
26
+ }
27
+ set(x, y, color) {
28
+ const col = Math.round(x);
29
+ const line = this.cells[Math.round(y)];
30
+ if (line && col >= 0 && col < this.width)
31
+ line[col] = color;
32
+ }
33
+ rect(x0, y0, x1, y1, color) {
34
+ for (let y = Math.round(y0); y <= Math.round(y1); y++) {
35
+ for (let x = Math.round(x0); x <= Math.round(x1); x++)
36
+ this.set(x, y, color);
37
+ }
38
+ }
39
+ /** Paints a blob; the callback sees the distance from the centre, 0 at the middle and 1 at the rim. */
40
+ blob(cx, cy, rx, ry, paint) {
41
+ for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++) {
42
+ for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) {
43
+ const edge = Math.hypot((x - cx) / rx, (y - cy) / ry);
44
+ if (edge <= 1) {
45
+ const color = paint(x, y, edge);
46
+ if (color !== null)
47
+ this.set(x, y, color);
48
+ }
49
+ }
50
+ }
51
+ }
52
+ line(x0, y0, x1, y1, color) {
53
+ const steps = Math.max(1, Math.round(Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0))));
54
+ for (let step = 0; step <= steps; step++) {
55
+ this.set(x0 + ((x1 - x0) * step) / steps, y0 + ((y1 - y0) * step) / steps, color);
56
+ }
57
+ }
58
+ /** Softens the staircase along high-contrast edges so silhouettes read as smooth curves. */
59
+ smoothEdges() {
60
+ const luminance = (hex) => {
61
+ const [r, g, b] = hexToRgb(hex);
62
+ return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
63
+ };
64
+ const next = this.cells.map((row) => [...row]);
65
+ for (let y = 1; y < this.height - 1; y++) {
66
+ for (let x = 1; x < this.width - 1; x++) {
67
+ const self = this.cells[y]?.[x];
68
+ if (!self)
69
+ continue;
70
+ const around = [
71
+ this.get(x - 1, y),
72
+ this.get(x + 1, y),
73
+ this.get(x, y - 1),
74
+ this.get(x, y + 1),
75
+ ];
76
+ const unlike = around.filter((color) => color !== null && Math.abs(luminance(color) - luminance(self)) > 0.2);
77
+ const target = unlike[0];
78
+ const row = next[y];
79
+ if (unlike.length === 1 && target !== undefined && row)
80
+ row[x] = mix(self, target, 0.35);
81
+ }
82
+ }
83
+ for (let y = 0; y < this.height; y++)
84
+ this.cells[y] = next[y] ?? [];
85
+ }
86
+ toBitmap() {
87
+ this.smoothEdges();
88
+ const palette = {};
89
+ const symbols = new Map();
90
+ const rows = this.cells.map((row) => row
91
+ .map((color) => {
92
+ if (color === null)
93
+ return ' ';
94
+ let symbol = symbols.get(color);
95
+ if (symbol === undefined) {
96
+ const index = symbols.size;
97
+ symbol =
98
+ ASCII_SYMBOLS[index] ?? String.fromCharCode(0x100 + index - ASCII_SYMBOLS.length);
99
+ symbols.set(color, symbol);
100
+ palette[symbol] = color;
101
+ }
102
+ return symbol;
103
+ })
104
+ .join(''));
105
+ return { palette, rows, density: FINE, smooth: true };
106
+ }
107
+ }
108
+ function random(seed) {
109
+ let state = seed;
110
+ return () => (state = (state * 16807) % 2147483647) / 2147483647;
111
+ }
112
+ // [hour, sky at the top, sky at the horizon]
113
+ const SKY = [
114
+ [0, '#050b1e', '#0b1a3a'],
115
+ [5, '#0b1a3a', '#3b2a5a'],
116
+ [6.5, '#3a4a8a', '#f08a5a'],
117
+ [9, '#2f78c8', '#9fd3ff'],
118
+ [13, '#1d6fb8', '#8fcbff'],
119
+ [17, '#2a5fa8', '#f2b36a'],
120
+ [18.5, '#4a3a8a', '#f07a5a'],
121
+ [20, '#0b1a3a', '#4a3a7a'],
122
+ [22, '#050b1e', '#0b1a3a'],
123
+ [24, '#050b1e', '#0b1a3a'],
124
+ ];
125
+ function skyColors(hour) {
126
+ const after = SKY.findIndex(([at]) => at >= hour);
127
+ const next = SKY[Math.max(1, after)] ?? SKY[SKY.length - 1];
128
+ const prev = SKY[Math.max(0, after - 1)] ?? SKY[0];
129
+ if (!next || !prev)
130
+ return { top: '#050b1e', horizon: '#0b1a3a' };
131
+ const amount = (hour - prev[0]) / (next[0] - prev[0] || 1);
132
+ return { top: mix(prev[1], next[1], amount), horizon: mix(prev[2], next[2], amount) };
133
+ }
134
+ const isDark = (hour) => hour < 6 || hour >= 18.5;
135
+ /** 0 is a new moon, 0.5 a full moon, counted from the new moon of 6 January 2000. */
136
+ export function moonPhase(date) {
137
+ const synodic = 29.530588853;
138
+ const days = (date.getTime() - Date.UTC(2000, 0, 6, 18, 14)) / 86_400_000;
139
+ return (((days / synodic) % 1) + 1) % 1;
140
+ }
141
+ function drawSky(c, horizon, hour, rand) {
142
+ const { top, horizon: low } = skyColors(hour);
143
+ for (let y = 0; y < horizon; y++)
144
+ c.rect(0, y, c.width - 1, y, mix(top, low, (y / horizon) ** 1.4));
145
+ if (isDark(hour) || hour < 7 || hour > 18) {
146
+ const strength = isDark(hour) ? 1 : 0.35;
147
+ const count = Math.round(c.width * horizon * 0.0016 * strength);
148
+ for (let index = 0; index < count; index++) {
149
+ const x = rand() * c.width;
150
+ const y = rand() * horizon * 0.85;
151
+ const bright = rand();
152
+ c.set(x, y, bright > 0.85 ? '#ffffff' : bright > 0.4 ? '#c7d4ef' : '#7f93bf');
153
+ if (bright > 0.95) {
154
+ c.set(x - 1, y, '#8ea2cc');
155
+ c.set(x + 1, y, '#8ea2cc');
156
+ c.set(x, y - 1, '#8ea2cc');
157
+ c.set(x, y + 1, '#8ea2cc');
158
+ }
159
+ }
160
+ }
161
+ const tint = isDark(hour) ? '#33487f' : hour > 16 || hour < 8 ? '#ffd9c2' : '#ffffff';
162
+ for (let index = 0; index < Math.max(2, Math.round(c.width / 28)); index++) {
163
+ const cx = rand() * c.width;
164
+ const cy = horizon * (0.2 + rand() * 0.5);
165
+ const rx = c.width * (0.05 + rand() * 0.07);
166
+ const ry = Math.max(1.5, horizon * (0.025 + rand() * 0.03));
167
+ c.blob(cx, cy, rx, ry, (x, y, edge) => mix(c.get(x, y) ?? low, tint, 0.5 * (1 - edge ** 2)));
168
+ c.blob(cx - rx * 0.25, cy - ry * 0.7, rx * 0.5, ry * 0.8, (x, y, edge) => mix(c.get(x, y) ?? low, tint, 0.45 * (1 - edge ** 2)));
169
+ }
170
+ if (!isDark(hour)) {
171
+ for (let index = 0; index < Math.round(c.width / 60); index++) {
172
+ const x = c.width * (0.15 + rand() * 0.6);
173
+ const y = horizon * (0.15 + rand() * 0.3);
174
+ for (const side of [-1, 1])
175
+ c.line(x, y, x + side * 2, y - 1, '#1d2b4a');
176
+ }
177
+ }
178
+ }
179
+ function drawBody(c, horizon, hour, date) {
180
+ const night = hour < 6 || hour >= 18;
181
+ const t = night ? (((hour + 6) % 24) % 12) / 12 : (hour - 6) / 12;
182
+ const cx = c.width * (0.1 + 0.8 * t);
183
+ const cy = horizon - Math.sin(Math.PI * t) * horizon * 0.8;
184
+ const radius = Math.max(3, c.height * 0.055);
185
+ const { horizon: low } = skyColors(hour);
186
+ const glow = night ? '#3b4f8a' : '#f6b36a';
187
+ c.blob(cx, cy, radius * 3.2, radius * 3.2, (x, y, edge) => y < horizon ? mix(c.get(x, y) ?? low, glow, 0.5 * (1 - edge) ** 2) : null);
188
+ if (!night) {
189
+ c.blob(cx, cy, radius, radius, (_x, y, edge) => y < horizon ? mix('#fff1bd', '#ffc46b', edge ** 2) : null);
190
+ return { x: cx, above: cy < horizon };
191
+ }
192
+ const phase = moonPhase(date);
193
+ const k = Math.cos(2 * Math.PI * phase);
194
+ c.blob(cx, cy, radius, radius, (x, y) => {
195
+ if (y >= horizon)
196
+ return null;
197
+ const nx = (x - cx) / radius;
198
+ const ny = (y - cy) / radius;
199
+ const half = Math.sqrt(Math.max(0, 1 - ny * ny));
200
+ const lit = phase < 0.5 ? nx > k * half : nx < -k * half;
201
+ return lit ? mix('#f4f7ff', '#c9d4ee', Math.hypot(nx, ny) ** 3) : '#141e3d';
202
+ });
203
+ return { x: cx, above: cy < horizon };
204
+ }
205
+ function drawSea(c, horizon, hour, rand, body) {
206
+ const { top, horizon: low } = skyColors(hour);
207
+ const shallow = mix(low, '#1f2c55', 0.55);
208
+ const deep = mix(top, '#050d1c', 0.75);
209
+ const depth = c.height - horizon;
210
+ for (let y = horizon; y < c.height; y++)
211
+ c.rect(0, y, c.width - 1, y, mix(shallow, deep, ((y - horizon) / depth) ** 0.8));
212
+ const glint = isDark(hour) ? '#dfe8ff' : '#ffd08a';
213
+ if (body.above) {
214
+ for (let y = horizon + 1; y < c.height - 2; y++) {
215
+ const progress = (y - horizon) / depth;
216
+ const half = Math.max(1, c.width * 0.07 * (1 - progress * 0.55));
217
+ const wobble = Math.sin(y * 1.7) * c.width * 0.012;
218
+ if (rand() < 0.35)
219
+ continue;
220
+ c.rect(body.x + wobble - half, y, body.x + wobble + half, y, mix(glint, deep, progress * 0.8));
221
+ }
222
+ }
223
+ const waves = Math.round(c.width * depth * 0.012);
224
+ for (let index = 0; index < waves; index++) {
225
+ const y = horizon + 1 + Math.floor(rand() * (depth - 3));
226
+ const x = rand() * c.width;
227
+ const length = 1 + Math.floor(rand() * 4) * (1 + (y - horizon) / depth);
228
+ c.rect(x, y, x + length, y, mix(c.get(x, y) ?? shallow, '#ffffff', 0.12 + 0.1 * rand()));
229
+ }
230
+ }
231
+ function drawShore(c, horizon, hour, rand) {
232
+ const shade = isDark(hour) ? '#02060f' : '#06101f';
233
+ const haze = mix(skyColors(hour).horizon, shade, 0.7);
234
+ const lit = isDark(hour) || hour > 18 || hour < 6;
235
+ let x = Math.round(c.width * 0.36);
236
+ while (x < c.width * 0.62) {
237
+ const w = 2 + Math.floor(rand() * 4);
238
+ const h = Math.max(2, Math.round(horizon * (0.04 + rand() * 0.1)));
239
+ c.rect(x, horizon - h, x + w - 1, horizon, haze);
240
+ if (lit) {
241
+ for (let wy = horizon - h + 1; wy < horizon - 1; wy += 2) {
242
+ for (let wx = x + 1; wx < x + w - 1; wx += 2)
243
+ if (rand() > 0.45)
244
+ c.set(wx, wy, '#ffd27a');
245
+ }
246
+ }
247
+ x += w + (rand() > 0.7 ? 1 : 0);
248
+ }
249
+ const bump = (from, to, peak, mid, spread, color) => {
250
+ for (let px = Math.round(from * c.width); px < Math.round(to * c.width); px++) {
251
+ const h = Math.round(peak * Math.exp(-(((px - mid * c.width) / (spread * c.width)) ** 2)) + 1);
252
+ c.rect(px, horizon - h + 1, px, horizon + 1, color);
253
+ }
254
+ };
255
+ bump(0, 0.4, horizon * 0.3, 0.2, 0.14, mix(haze, shade, 0.45));
256
+ bump(0, 0.3, horizon * 0.3, 0.1, 0.1, shade);
257
+ bump(0.62, 1, horizon * 0.24, 0.9, 0.11, shade);
258
+ const tx = Math.round(c.width * 0.9);
259
+ const tower = Math.round(horizon * 0.3);
260
+ const base = horizon - Math.round(horizon * 0.14);
261
+ c.rect(tx, base - tower, tx + 2, base, shade);
262
+ c.rect(tx - 1, base - tower, tx + 3, base - tower, shade);
263
+ c.rect(tx, base - tower - 2, tx + 2, base - tower - 1, lit ? '#ffe08a' : '#8a6a3a');
264
+ if (lit) {
265
+ const reach = c.width * 0.3;
266
+ for (let step = 1; step < reach; step++) {
267
+ const spread = step * 0.12;
268
+ for (let dy = -spread; dy <= spread; dy++) {
269
+ const y = base - tower - 1 + dy;
270
+ const cell = c.get(tx - step, y);
271
+ if (cell !== null && y < horizon - 1)
272
+ c.set(tx - step, y, mix(cell, '#ffe9a8', 0.1 * (1 - step / reach)));
273
+ }
274
+ }
275
+ }
276
+ const boatX = Math.round(c.width * 0.27);
277
+ const boatY = horizon + Math.round((c.height - horizon) * 0.28);
278
+ const size = Math.max(3, Math.round(c.width * 0.035));
279
+ for (let dy = 0; dy < size; dy++) {
280
+ c.rect(boatX, boatY - dy - 1, boatX + Math.round(size * 0.55) - Math.round(dy * 0.5), boatY - dy - 1, lit ? '#9fb0d6' : '#f1f5f9');
281
+ }
282
+ c.rect(boatX - 1, boatY, boatX + size, boatY + 1, shade);
283
+ c.rect(0, c.height - 3, c.width - 1, c.height - 1, shade);
284
+ }
285
+ /** A seascape whose sky, sun or moon (with its real phase), stars, city, and lighthouse follow the time. */
286
+ export function skyScene(width, height, now) {
287
+ const hour = now.getHours() + now.getMinutes() / 60;
288
+ const c = new Canvas(width, height);
289
+ const horizon = Math.round(height * 0.62);
290
+ const rand = random(11);
291
+ drawSky(c, horizon, hour, rand);
292
+ const body = drawBody(c, horizon, hour, now);
293
+ drawSea(c, horizon, hour, rand, body);
294
+ drawShore(c, horizon, hour, rand);
295
+ return c.toBitmap();
296
+ }
297
+ /** Ridges with a trail and a flag that climbs it as `progress` goes from 0 to 1, one tick per week. */
298
+ export function mountainScene(width, height, progress, weeks, now) {
299
+ const hour = Math.min(17, Math.max(8, now.getHours() + now.getMinutes() / 60));
300
+ const c = new Canvas(width, height);
301
+ const { top, horizon: low } = skyColors(hour);
302
+ for (let y = 0; y < height; y++)
303
+ c.rect(0, y, width - 1, y, mix(top, low, (y / height) ** 1.3));
304
+ const rand = random(5);
305
+ for (let index = 0; index < Math.max(2, Math.round(width / 28)); index++) {
306
+ const cx = rand() * width;
307
+ const cy = height * (0.1 + rand() * 0.35);
308
+ const rx = width * (0.05 + rand() * 0.06);
309
+ const ry = Math.max(1.5, height * 0.025);
310
+ c.blob(cx, cy, rx, ry, (x, y, edge) => mix(c.get(x, y) ?? low, '#ffffff', 0.5 * (1 - edge ** 2)));
311
+ }
312
+ c.blob(width * 0.82, height * 0.2, height * 0.05, height * 0.05, (_x, _y, edge) => mix('#fff4c9', '#ffd27a', edge ** 2));
313
+ const base = height - 3;
314
+ const ridge = (x, scale, phase, rough) => {
315
+ const u = x / width;
316
+ const sway = 0.55 +
317
+ 0.3 * Math.sin(u * Math.PI * 2.1 + phase) +
318
+ 0.15 * Math.sin(u * Math.PI * rough + phase * 2);
319
+ return (base -
320
+ height * scale * sway * Math.sin(Math.PI * Math.min(1, Math.max(0, u * 0.9 + 0.05))) ** 0.5);
321
+ };
322
+ const layers = [
323
+ [0.7, 1.4, 11, mix(low, '#3a4f86', 0.55)],
324
+ [0.58, 3.1, 17, mix(low, '#1f3466', 0.7)],
325
+ [0.46, 0, 23, '#0b1630'],
326
+ ];
327
+ for (const [scale, phase, rough, color] of layers) {
328
+ for (let x = 0; x < width; x++)
329
+ c.rect(x, ridge(x, scale, phase, rough), x, base + 2, color);
330
+ }
331
+ const near = (x) => ridge(x, 0.46, 0, 23);
332
+ const start = Math.round(width * 0.1);
333
+ const span = width * 0.8;
334
+ const reached = Math.min(1, Math.max(0, progress));
335
+ for (let x = start; x < start + span * reached; x += 2)
336
+ c.set(x, near(x) - 1, '#f8d98a');
337
+ for (let week = 0; week <= Math.max(1, weeks); week++) {
338
+ const x = Math.round(start + (span * week) / Math.max(1, weeks));
339
+ const past = week / Math.max(1, weeks) <= progress;
340
+ c.rect(x, near(x) - 3, x, near(x) - 2, past ? '#f8d98a' : '#5b6f9e');
341
+ }
342
+ for (let index = 0; index < Math.round(width / 5); index++) {
343
+ const x = Math.round(rand() * width);
344
+ const y = Math.round(near(x));
345
+ if (x > start - 4 && x < start + span + 4 && rand() > 0.4)
346
+ continue;
347
+ const h = 3 + Math.floor(rand() * 4);
348
+ for (let row = 0; row < h; row++)
349
+ c.rect(x - Math.floor(row / 2), y - h + row, x + Math.floor(row / 2), y - h + row, '#0a1f2a');
350
+ }
351
+ const fx = Math.round(start + span * reached);
352
+ const fy = Math.round(near(fx));
353
+ const pole = Math.max(5, Math.round(height * 0.2));
354
+ c.rect(fx, fy - pole, fx, fy - 1, '#e2e8f0');
355
+ const length = Math.max(3, Math.round(pole * 0.7));
356
+ for (let row = 0; row < Math.ceil(length * 0.6); row++) {
357
+ c.rect(fx + 1, fy - pole + row, fx + length - Math.round(row * 1.4), fy - pole + row, '#f59e0b');
358
+ }
359
+ c.rect(0, base + 1, width - 1, height - 1, '#050d1c');
360
+ return c.toBitmap();
361
+ }
362
+ /** A bookcase with a cat on the top shelf; more books and shelves appear as the space grows. */
363
+ export function shelfScene(width, height) {
364
+ const c = new Canvas(width, height);
365
+ const wood = '#3a2718';
366
+ const woodLight = '#5a3d27';
367
+ const back = '#17100b';
368
+ for (let y = 0; y < height; y++)
369
+ c.rect(0, y, width - 1, y, mix('#1d140e', back, y / height));
370
+ c.blob(width * 0.12, height * 0.2, width * 0.28, height * 0.55, (x, y, edge) => mix(c.get(x, y) ?? back, '#ffb86b', 0.12 * (1 - edge)));
371
+ const rand = random(23);
372
+ const shelfHeight = Math.max(14, Math.round(height / Math.max(2, Math.round(height / 22))));
373
+ const spines = [
374
+ '#0ea5e9',
375
+ '#06b6d4',
376
+ '#bae6fd',
377
+ '#f59e0b',
378
+ '#fb7185',
379
+ '#a78bfa',
380
+ '#4ade80',
381
+ '#94a3b8',
382
+ '#e11d48',
383
+ '#2dd4bf',
384
+ ];
385
+ const catX = Math.round(width * 0.62);
386
+ let shelfIndex = 0;
387
+ for (let top = 0; top + shelfHeight <= height; top += shelfHeight, shelfIndex++) {
388
+ const floor = top + shelfHeight - 2;
389
+ c.rect(0, floor, width - 1, floor + 1, wood);
390
+ c.rect(0, floor, width - 1, floor, woodLight);
391
+ let x = 2;
392
+ while (x < width - 3) {
393
+ if (shelfIndex === 0 && x >= catX - 3 && x < catX + 16) {
394
+ x = catX + 16;
395
+ continue;
396
+ }
397
+ if (rand() > 0.93)
398
+ x += 2 + Math.floor(rand() * 5);
399
+ const bookWidth = 3 + Math.floor(rand() * 4);
400
+ const bookHeight = Math.round((shelfHeight - 4) * (0.62 + rand() * 0.38));
401
+ if (x + bookWidth >= width - 2)
402
+ break;
403
+ const color = spines[Math.floor(rand() * spines.length)] ?? '#0ea5e9';
404
+ const lean = rand() > 0.96;
405
+ for (let row = 0; row < bookHeight; row++) {
406
+ const shift = lean ? Math.round((row / bookHeight) * 2) : 0;
407
+ c.rect(x + shift, floor - 1 - row, x + shift + bookWidth - 1, floor - 1 - row, mix(color, '#000000', 0.12 * (x % 3)));
408
+ }
409
+ c.rect(x, floor - 1 - bookHeight + 2, x + bookWidth - 1, floor - 1 - bookHeight + 2, mix(color, '#ffffff', 0.5));
410
+ c.rect(x, floor - 4, x + bookWidth - 1, floor - 4, mix(color, '#000000', 0.4));
411
+ if (bookHeight > 9) {
412
+ const mark = floor - 1 - Math.round(bookHeight * 0.55);
413
+ c.rect(x + 1, mark, x + bookWidth - 2, mark, mix(color, '#ffffff', 0.7));
414
+ }
415
+ x += bookWidth;
416
+ }
417
+ if (shelfIndex === 1 && width > 40) {
418
+ const px = Math.round(width * 0.85);
419
+ c.rect(px, floor - 5, px + 5, floor - 1, '#9a4a2c');
420
+ for (let leaf = 0; leaf < 7; leaf++)
421
+ c.line(px + 2.5, floor - 5, px + leaf - 1, floor - 11 - (leaf % 3) * 2, '#3fae5a');
422
+ }
423
+ }
424
+ const sit = shelfHeight - 3;
425
+ const cx = catX + 6;
426
+ const fur = '#1c1c24';
427
+ c.blob(cx, sit - 5, 6, 5, () => fur);
428
+ c.blob(cx + 5, sit - 11, 3.4, 3.4, () => fur);
429
+ c.rect(cx + 2, sit - 16, cx + 3, sit - 14, fur);
430
+ c.rect(cx + 7, sit - 16, cx + 8, sit - 14, fur);
431
+ c.set(cx + 4, sit - 11, '#fbbf24');
432
+ c.set(cx + 7, sit - 11, '#fbbf24');
433
+ c.line(cx - 6, sit - 2, cx - 11, sit - 6, fur);
434
+ c.line(cx - 11, sit - 6, cx - 11, sit - 10, fur);
435
+ c.rect(0, 0, 1, height - 1, wood);
436
+ c.rect(width - 2, 0, width - 1, height - 1, wood);
437
+ return c.toBitmap();
438
+ }
439
+ /** Enlarges a bitmap by whole pixels so a small icon can fill a roomy window. */
440
+ export function scaleBitmap(bitmap, factor) {
441
+ const rows = bitmap.rows.flatMap((row) => {
442
+ const wide = Array.from(row, (symbol) => symbol.repeat(factor)).join('');
443
+ return Array.from({ length: factor }, () => wide);
444
+ });
445
+ return { palette: bitmap.palette, rows };
446
+ }
@@ -5,6 +5,7 @@ import { getConfigDir, getWritableConfigDir } from './paths.js';
5
5
  const DEFAULT_PREFERENCES = {
6
6
  iconMode: 'auto',
7
7
  colorMode: 'auto',
8
+ pictureDetail: 'ascii',
8
9
  };
9
10
  const detectedColorLevel = chalk.level;
10
11
  const inheritedNoColor = process.env['NO_COLOR'];
@@ -25,7 +26,8 @@ export function loadPreferences() {
25
26
  const colorMode = raw.colorMode === 'on' || raw.colorMode === 'off' || raw.colorMode === 'auto'
26
27
  ? raw.colorMode
27
28
  : DEFAULT_PREFERENCES.colorMode;
28
- return { iconMode, colorMode };
29
+ const pictureDetail = raw.pictureDetail === 'fine' ? 'fine' : DEFAULT_PREFERENCES.pictureDetail;
30
+ return { iconMode, colorMode, pictureDetail };
29
31
  }
30
32
  catch {
31
33
  return { ...DEFAULT_PREFERENCES };
@@ -50,6 +52,11 @@ export function setColorMode(mode) {
50
52
  prefs.colorMode = mode;
51
53
  return savePreferences(prefs);
52
54
  }
55
+ export function setPictureDetail(detail) {
56
+ const prefs = loadPreferences();
57
+ prefs.pictureDetail = detail;
58
+ return savePreferences(prefs);
59
+ }
53
60
  export function resetPreferences() {
54
61
  return savePreferences({ ...DEFAULT_PREFERENCES });
55
62
  }
@@ -0,0 +1,50 @@
1
+ import { c, space, type } from '../theme.js';
2
+ import { padEndV, visualWidth, wrapAnsiWithIndent } from '../text.js';
3
+ import { magnifier, moonSky, orbit, signalLost } from '../../art/motifs.js';
4
+ import { pictureBeside } from './picture.js';
5
+ import { loadingLines } from './spinner.js';
6
+ const ART = {
7
+ calendar: [' .-.-. ', ' | | ', " '---' "],
8
+ search: [' .--. ', '( ) ', " '--'\\_"],
9
+ };
10
+ const PICTURE = { calendar: moonSky, search: magnifier };
11
+ export function emptyStateLines(kind, label, cols = Number.POSITIVE_INFINITY, rows = Number.POSITIVE_INFINITY) {
12
+ const text = wrapAnsiWithIndent(type.hint(label), cols, space.indent);
13
+ const picture = PICTURE[kind]();
14
+ const lines = cols >= 44 && rows >= picture.length ? beside(picture, label, cols, false) : undefined;
15
+ if (lines)
16
+ return lines;
17
+ const art = ART[kind];
18
+ if (cols < 40 || rows < art.length)
19
+ return text;
20
+ return beside([...art], label, cols, true) ?? text;
21
+ }
22
+ function beside(art, label, cols, subtle) {
23
+ const artWidth = Math.max(...art.map(visualWidth));
24
+ const message = wrapAnsiWithIndent(type.hint(label), cols - visualWidth(space.indent) - artWidth - 2, '');
25
+ if (message.length > art.length)
26
+ return undefined;
27
+ const offset = Math.floor((art.length - message.length) / 2);
28
+ return art.map((line, index) => space.indent +
29
+ (subtle ? c.subtle(padEndV(line, artWidth)) : padEndV(line, artWidth)) +
30
+ (message[index - offset] ? ` ${message[index - offset]}` : ''));
31
+ }
32
+ const MIN_PICTURE_COLS = 44;
33
+ /** A small planet with an orbiting moon beside the label, or the plain spinner line when there is no room. */
34
+ export function loadingStateLines(label, cols = Number.POSITIVE_INFINITY, rows = Number.POSITIVE_INFINITY, at = Date.now()) {
35
+ const picture = orbit(at);
36
+ if (cols < MIN_PICTURE_COLS || rows < picture.length)
37
+ return loadingLines(label, cols, at);
38
+ return beside(picture, label, cols, false) ?? loadingLines(label, cols, at);
39
+ }
40
+ /**
41
+ * The error headline beside a dropped-signal tower, with the hint below at full width so a URL never wraps.
42
+ * Falls back to the plain lines when there is no room.
43
+ */
44
+ export function offlineContext(headline, hint, fallback, cols = Number.POSITIVE_INFINITY, rows = Number.POSITIVE_INFINITY) {
45
+ const picture = signalLost();
46
+ if (cols < MIN_PICTURE_COLS || rows < picture.length + hint.length + 1)
47
+ return fallback;
48
+ const lines = pictureBeside(picture, [headline], cols, 24);
49
+ return lines ? [...lines, ...hint, ''] : fallback;
50
+ }
@@ -1,4 +1,4 @@
1
- import { glyph, type, space, bodyEdge } from '../theme.js';
1
+ import { c, glyph, type, space, bodyEdge } from '../theme.js';
2
2
  import { visualWidth, padEndV, wrapAnsiToVisualWidth, clipAnsiToVisualWidth, excerptAround, } from '../text.js';
3
3
  import { pickIcon } from '../icons.js';
4
4
  import { createPainter } from './painter.js';
@@ -120,7 +120,7 @@ export function renderMenuOption(option, selected, columns = menuColumns([option
120
120
  const continuation = ' '.repeat(visualWidth(prefix));
121
121
  const contentWidth = Math.max(1, bodyEdge(width) - visualWidth(prefix));
122
122
  const cells = optionCells(option, columns, contentWidth);
123
- const style = selected ? type.active : option.dim ? type.hint : type.body;
123
+ const style = selected ? type.active : option.dim ? c.muted : type.body;
124
124
  const hint = cells.hint ? ` ${type.hint(cells.hint)}` : '';
125
125
  const label = style(cells.label);
126
126
  return wrapAnsiToVisualWidth(`${label}${hint}`, contentWidth).map((line, index) => `${index === 0 ? prefix : continuation}${line}`);
@@ -0,0 +1,18 @@
1
+ import { space } from '../theme.js';
2
+ import { padEndV, visualWidth, wrapAnsiWithIndent } from '../text.js';
3
+ const GAP = 2;
4
+ /** Lays a picture beside styled text; undefined when there is no room for the text next to it. */
5
+ export function pictureBeside(picture, text, cols, minTextWidth = 20) {
6
+ const pictureWidth = Math.max(0, ...picture.map(visualWidth));
7
+ const textWidth = cols - visualWidth(space.indent) - pictureWidth - GAP;
8
+ if (textWidth < minTextWidth)
9
+ return undefined;
10
+ const wrapped = text.flatMap((line) => wrapAnsiWithIndent(line, textWidth, ''));
11
+ const rows = Math.max(picture.length, wrapped.length);
12
+ const offset = Math.max(0, Math.floor((picture.length - wrapped.length) / 2));
13
+ return Array.from({ length: rows }, (_, index) => {
14
+ const line = picture[index] ?? '';
15
+ const message = wrapped[index - offset];
16
+ return `${space.indent}${padEndV(line, pictureWidth)}${message === undefined ? '' : ' '.repeat(GAP) + message}`;
17
+ });
18
+ }