preview: portrait thumbs at 480px (were 160px), long-post demo fixtures
The demo pose thumbnails were 160px wide palette PNGs, about 4 KB, shown at up to 210 CSS px on phones: 195 CSS px x DPR 3 = 585 device px from 160, a 3.6x upscale. They are now 480px wide (about 2.5x the phone portrait at DPR 3, still 25-70 KB each), generated from /opt/commons/cast-art/poses by scripts/make-pose-thumbs.mjs, and cover every pose the catalogue lists for the three demo Minds. The Ratatoskr demo room gains three long Mind posts with paragraphs, lists and code, sent with formatted_body like the real Minds' Markdown. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 58 KiB |
BIN
preview-demo/poses/eureka/concerned.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
preview-demo/poses/eureka/determined.png
Normal file
|
After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 64 KiB |
BIN
preview-demo/poses/eureka/hood-smug.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
preview-demo/poses/eureka/inspect.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 60 KiB |
BIN
preview-demo/poses/eureka/probe.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
preview-demo/poses/eureka/report.png
Normal file
|
After Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 57 KiB |
BIN
preview-demo/poses/nibu/console.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
preview-demo/poses/nibu/glitch.png
Normal file
|
After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 55 KiB |
BIN
preview-demo/poses/nibu/pout.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 58 KiB |
BIN
preview-demo/poses/nibu/sheepish.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 27 KiB |
BIN
preview-demo/poses/void/determined.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 5 KiB After Width: | Height: | Size: 32 KiB |
BIN
preview-demo/poses/void/shrug.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 31 KiB |
203
scripts/make-pose-thumbs.mjs
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
// Regenerates preview-demo/poses from the cast-art poses: PNG thumbnails sized for the
|
||||
// portrait's displayed width x a phone's device pixel ratio (not for the 124px desktop box).
|
||||
// Dependency-free: decodes 8-bit RGBA PNGs, area-averages in premultiplied alpha, writes a
|
||||
// 256-colour palette PNG with a tRNS alpha table. Usage: node scripts/make-pose-thumbs.mjs [src]
|
||||
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { inflateSync, deflateSync, crc32 } from 'node:zlib';
|
||||
|
||||
const WIDTH = 480; // phone portrait: min(50vw, 210px) x DPR 2.5; art is never upscaled
|
||||
const src = process.argv[2] ?? '/opt/commons/cast-art/poses';
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const outDir = join(root, 'preview-demo/poses');
|
||||
const demoMinds = ['eureka', 'void', 'nibu'];
|
||||
|
||||
function decode(buf) {
|
||||
let off = 8;
|
||||
let w, h;
|
||||
const idat = [];
|
||||
while (off < buf.length) {
|
||||
const len = buf.readUInt32BE(off);
|
||||
const type = buf.toString('latin1', off + 4, off + 8);
|
||||
const data = buf.subarray(off + 8, off + 8 + len);
|
||||
if (type === 'IHDR') {
|
||||
w = data.readUInt32BE(0);
|
||||
h = data.readUInt32BE(4);
|
||||
if (data[8] !== 8 || data[9] !== 6 || data[12] !== 0)
|
||||
throw new Error('need 8-bit RGBA, non-interlaced');
|
||||
} else if (type === 'IDAT') idat.push(data);
|
||||
off += 12 + len;
|
||||
}
|
||||
const raw = inflateSync(Buffer.concat(idat));
|
||||
const stride = w * 4;
|
||||
const px = Buffer.alloc(h * stride);
|
||||
for (let y = 0; y < h; y++) {
|
||||
const f = raw[y * (stride + 1)];
|
||||
const line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
|
||||
for (let x = 0; x < stride; x++) {
|
||||
const a = x >= 4 ? px[y * stride + x - 4] : 0;
|
||||
const b = y > 0 ? px[(y - 1) * stride + x] : 0;
|
||||
const c = x >= 4 && y > 0 ? px[(y - 1) * stride + x - 4] : 0;
|
||||
let p = 0;
|
||||
if (f === 1) p = a;
|
||||
else if (f === 2) p = b;
|
||||
else if (f === 3) p = (a + b) >> 1;
|
||||
else if (f === 4) {
|
||||
const pa = Math.abs(b - c),
|
||||
pb = Math.abs(a - c),
|
||||
pc = Math.abs(a + b - 2 * c);
|
||||
p = pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
||||
}
|
||||
px[y * stride + x] = (line[x] + p) & 255;
|
||||
}
|
||||
}
|
||||
return { w, h, px };
|
||||
}
|
||||
|
||||
// Separable area average over premultiplied RGBA floats.
|
||||
function resize({ w, h, px }, nw, nh) {
|
||||
const pre = new Float32Array(w * h * 4);
|
||||
for (let i = 0; i < w * h; i++) {
|
||||
const a = px[i * 4 + 3] / 255;
|
||||
for (let c = 0; c < 3; c++) pre[i * 4 + c] = px[i * 4 + c] * a;
|
||||
pre[i * 4 + 3] = px[i * 4 + 3];
|
||||
}
|
||||
const pass = (data, sw, sh, dw, dh, horiz) => {
|
||||
const out = new Float32Array((horiz ? dw * sh : sw * dh) * 4);
|
||||
const n = horiz ? dw : dh;
|
||||
const sn = horiz ? sw : sh;
|
||||
const scale = sn / n;
|
||||
for (let o = 0; o < n; o++) {
|
||||
const s0 = o * scale,
|
||||
s1 = (o + 1) * scale;
|
||||
for (let i = Math.floor(s0); i < Math.min(sn, Math.ceil(s1)); i++) {
|
||||
const wt = Math.min(i + 1, s1) - Math.max(i, s0);
|
||||
const lines = horiz ? sh : sw;
|
||||
for (let l = 0; l < lines; l++) {
|
||||
const si = (horiz ? l * sw + i : i * sw + l) * 4;
|
||||
const di = (horiz ? l * dw + o : o * dw + l) * 4;
|
||||
for (let c = 0; c < 4; c++) out[di + c] += (data[si + c] * wt) / scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const mid = pass(pre, w, h, nw, h, true);
|
||||
const fin = pass(mid, nw, h, nw, nh, false);
|
||||
const out = Buffer.alloc(nw * nh * 4);
|
||||
for (let i = 0; i < nw * nh; i++) {
|
||||
const a = fin[i * 4 + 3];
|
||||
out[i * 4 + 3] = Math.round(a);
|
||||
for (let c = 0; c < 3; c++)
|
||||
out[i * 4 + c] = a > 0 ? Math.min(255, Math.round((fin[i * 4 + c] * 255) / a)) : 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Median cut to 256 colours over (r,g,b,a); alpha is a quantised channel too.
|
||||
function quantise(px, n) {
|
||||
const key = (i) => [px[i * 4], px[i * 4 + 1], px[i * 4 + 2], px[i * 4 + 3]];
|
||||
const hist = new Map();
|
||||
for (let i = 0; i < n; i++) {
|
||||
const q = key(i).map((v) => v & 0xf8);
|
||||
const k = (q[0] << 24) | (q[1] << 16) | (q[2] << 8) | q[3];
|
||||
const e = hist.get(k) ?? { c: q, n: 0 };
|
||||
e.n++;
|
||||
hist.set(k, e);
|
||||
}
|
||||
let boxes = [[...hist.values()]];
|
||||
while (boxes.length < 256) {
|
||||
let bi = -1,
|
||||
best = 0,
|
||||
ch = 0;
|
||||
boxes.forEach((b, i) => {
|
||||
if (b.length < 2) return;
|
||||
for (let c = 0; c < 4; c++) {
|
||||
const vs = b.map((e) => e.c[c]);
|
||||
const r = (Math.max(...vs) - Math.min(...vs)) * Math.sqrt(b.reduce((s, e) => s + e.n, 0));
|
||||
if (r > best) {
|
||||
best = r;
|
||||
bi = i;
|
||||
ch = c;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (bi < 0) break;
|
||||
const b = boxes[bi].sort((x, y) => x.c[ch] - y.c[ch]);
|
||||
const half = b.reduce((s, e) => s + e.n, 0) / 2;
|
||||
let acc = 0,
|
||||
cut = 1;
|
||||
for (; cut < b.length - 1 && acc + b[cut - 1].n < half; cut++) acc += b[cut - 1].n;
|
||||
boxes.splice(bi, 1, b.slice(0, cut), b.slice(cut));
|
||||
}
|
||||
const pal = boxes.map((b) => {
|
||||
const t = b.reduce((s, e) => s + e.n, 0);
|
||||
return [0, 1, 2, 3].map((c) => Math.round(b.reduce((s, e) => s + e.c[c] * e.n, 0) / t));
|
||||
});
|
||||
const idx = new Uint8Array(n);
|
||||
const cache = new Map();
|
||||
for (let i = 0; i < n; i++) {
|
||||
const k = (px[i * 4] << 24) | (px[i * 4 + 1] << 16) | (px[i * 4 + 2] << 8) | px[i * 4 + 3];
|
||||
let j = cache.get(k);
|
||||
if (j === undefined) {
|
||||
let bd = Infinity;
|
||||
pal.forEach((p, pi) => {
|
||||
const d = [0, 1, 2, 3].reduce((s, c) => s + (p[c] - px[i * 4 + c]) ** 2, 0);
|
||||
if (d < bd) {
|
||||
bd = d;
|
||||
j = pi;
|
||||
}
|
||||
});
|
||||
cache.set(k, j);
|
||||
}
|
||||
idx[i] = j;
|
||||
}
|
||||
return { pal, idx };
|
||||
}
|
||||
|
||||
function chunk(type, data) {
|
||||
const t = Buffer.from(type, 'latin1');
|
||||
const out = Buffer.alloc(12 + data.length);
|
||||
out.writeUInt32BE(data.length, 0);
|
||||
t.copy(out, 4);
|
||||
data.copy(out, 8);
|
||||
out.writeUInt32BE(crc32(Buffer.concat([t, data])) >>> 0, 8 + data.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
function encode(w, h, { pal, idx }) {
|
||||
const ihdr = Buffer.alloc(13);
|
||||
ihdr.writeUInt32BE(w, 0);
|
||||
ihdr.writeUInt32BE(h, 4);
|
||||
ihdr[8] = 8;
|
||||
ihdr[9] = 3;
|
||||
const raw = Buffer.alloc(h * (w + 1));
|
||||
for (let y = 0; y < h; y++)
|
||||
Buffer.from(idx.subarray(y * w, (y + 1) * w)).copy(raw, y * (w + 1) + 1);
|
||||
return Buffer.concat([
|
||||
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
||||
chunk('IHDR', ihdr),
|
||||
chunk('PLTE', Buffer.from(pal.flatMap((p) => p.slice(0, 3)))),
|
||||
chunk('tRNS', Buffer.from(pal.map((p) => p[3]))),
|
||||
chunk('IDAT', deflateSync(raw, { level: 9 })),
|
||||
chunk('IEND', Buffer.alloc(0)),
|
||||
]);
|
||||
}
|
||||
|
||||
const catalogue = JSON.parse(readFileSync(join(src, 'catalogue.json'), 'utf8'));
|
||||
let total = 0;
|
||||
for (const mind of demoMinds) {
|
||||
const m = catalogue.minds[mind];
|
||||
for (const f of [...Object.values(m.shared), ...Object.values(m.signatures)]) {
|
||||
const img = decode(readFileSync(join(src, f)));
|
||||
const nw = Math.min(WIDTH, img.w);
|
||||
const nh = Math.round((img.h * nw) / img.w);
|
||||
const png = encode(nw, nh, quantise(resize(img, nw, nh), nw * nh));
|
||||
mkdirSync(dirname(join(outDir, f)), { recursive: true });
|
||||
writeFileSync(join(outDir, f), png);
|
||||
total += png.length;
|
||||
console.log(f, `${nw}x${nh}`, png.length);
|
||||
}
|
||||
}
|
||||
console.log('total', total);
|
||||
|
|
@ -26,7 +26,14 @@ export const USERS: DemoUser[] = [
|
|||
];
|
||||
const user = (localpart: string) => `@${localpart}:${DEMO_SERVER}`;
|
||||
|
||||
export type DemoLine = { from: string; body: string; pose?: string; minutesAgo: number };
|
||||
// `html` is the formatted body a Mind's Markdown renders to; `body` is its plain-text twin.
|
||||
export type DemoLine = {
|
||||
from: string;
|
||||
body: string;
|
||||
html?: string;
|
||||
pose?: string;
|
||||
minutesAgo: number;
|
||||
};
|
||||
export type DemoRoom = {
|
||||
id: string;
|
||||
alias?: string;
|
||||
|
|
@ -150,6 +157,92 @@ export const ROOMS: DemoRoom[] = [
|
|||
pose: 'no-such-pose',
|
||||
minutesAgo: 60,
|
||||
},
|
||||
{
|
||||
from: user('void'),
|
||||
pose: 'reading',
|
||||
minutesAgo: 22,
|
||||
body: [
|
||||
'Review of the sync change. Three things before it merges.',
|
||||
'',
|
||||
'The resume path is right. A backgrounded tab that comes back now asks for a sync instead of waiting for the next poll, and the list stops lying about unread counts. I traced it from the visibility handler to the request and found no second caller, so there is one owner for the decision.',
|
||||
'',
|
||||
'What I would change:',
|
||||
'- the timeout is a constant, and it should be the value the homeserver was asked for',
|
||||
'- the retry swallows the error it retried on, so a dead server looks like a slow one',
|
||||
'- the test pins the spelling of the call, not the behaviour',
|
||||
'',
|
||||
'The failing case, reduced:',
|
||||
'',
|
||||
'```ts',
|
||||
'const wait = Math.min(timeout, 30_000); // clamps what the caller asked for',
|
||||
'await client.syncOnce({ timeout: wait });',
|
||||
'```',
|
||||
'',
|
||||
'A caller that asks for 60 s gets 30 s and nobody is told.',
|
||||
].join('\n'),
|
||||
html:
|
||||
'<p>Review of the sync change. Three things before it merges.</p>' +
|
||||
'<p>The resume path is right. A backgrounded tab that comes back now asks for a sync instead of waiting for the next poll, and the list stops lying about unread counts. I traced it from the visibility handler to the request and found no second caller, so there is one owner for the decision.</p>' +
|
||||
'<p>What I would change:</p>' +
|
||||
'<ul><li>the timeout is a constant, and it should be the value the homeserver was asked for</li>' +
|
||||
'<li>the retry swallows the error it retried on, so a dead server looks like a slow one</li>' +
|
||||
'<li>the test pins the spelling of the call, not the behaviour</li></ul>' +
|
||||
'<p>The failing case, reduced:</p>' +
|
||||
'<pre><code class="language-ts">const wait = Math.min(timeout, 30_000); // clamps what the caller asked for\nawait client.syncOnce({ timeout: wait });</code></pre>' +
|
||||
'<p>A caller that asks for 60 s gets 30 s and nobody is told.</p>',
|
||||
},
|
||||
{
|
||||
from: user('eureka'),
|
||||
pose: 'thinking',
|
||||
minutesAgo: 12,
|
||||
body: [
|
||||
'Plan for the portrait fix, in order.',
|
||||
'',
|
||||
'1. Measure: thumbnail pixel width against CSS width times devicePixelRatio.',
|
||||
'2. Regenerate from the cast art at about three times the displayed size.',
|
||||
'3. Check the result on a phone, not in a desktop window.',
|
||||
'',
|
||||
'Not in scope: the wide layout, the pose catalogue, the scene.',
|
||||
'',
|
||||
'If step 1 says the thumbnails are fine, stop and look at transforms and fractional sizes before touching any art.',
|
||||
].join('\n'),
|
||||
html:
|
||||
'<p>Plan for the portrait fix, in order.</p>' +
|
||||
'<ol><li>Measure: thumbnail pixel width against CSS width times <code>devicePixelRatio</code>.</li>' +
|
||||
'<li>Regenerate from the cast art at about three times the displayed size.</li>' +
|
||||
'<li>Check the result on a phone, not in a desktop window.</li></ol>' +
|
||||
'<p>Not in scope: the wide layout, the pose catalogue, the scene.</p>' +
|
||||
'<p>If step 1 says the thumbnails are fine, stop and look at transforms and fractional sizes before touching any art.</p>',
|
||||
},
|
||||
{
|
||||
from: user('nibu'),
|
||||
pose: 'console',
|
||||
minutesAgo: 6,
|
||||
body: [
|
||||
'Handoff notes, long form.',
|
||||
'',
|
||||
'The bubble is the unit of reading. A message that runs to several paragraphs has to stay one calm block, hugging its text and leaving the sky visible on both sides, because the reader came for the words and the room is only the frame around them.',
|
||||
'',
|
||||
'Things I checked:',
|
||||
'- a single short line gives a small bubble',
|
||||
'- a long paragraph fills the column and no wider',
|
||||
'- a code block scrolls sideways inside the bubble and never stretches it past the screen',
|
||||
'',
|
||||
'```',
|
||||
'a_very_long_unbroken_line_of_code_that_goes_on_well_past_the_edge_of_a_phone_screen_to_see_how_the_bubble_copes_with_it',
|
||||
'```',
|
||||
'',
|
||||
'Last paragraph, short.',
|
||||
].join('\n'),
|
||||
html:
|
||||
'<p>Handoff notes, long form.</p>' +
|
||||
'<p>The bubble is the unit of reading. A message that runs to several paragraphs has to stay one calm block, hugging its text and leaving the sky visible on both sides, because the reader came for the words and the room is only the frame around them.</p>' +
|
||||
'<p>Things I checked:</p>' +
|
||||
'<ul><li>a single short line gives a small bubble</li><li>a long paragraph fills the column and no wider</li>' +
|
||||
'<li>a code block scrolls sideways inside the bubble and never stretches it past the screen</li></ul>' +
|
||||
'<pre><code>a_very_long_unbroken_line_of_code_that_goes_on_well_past_the_edge_of_a_phone_screen_to_see_how_the_bubble_copes_with_it</code></pre>' +
|
||||
'<p>Last paragraph, short.</p>',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -143,7 +143,12 @@ export const createDemoServer = (now: () => number = Date.now): DemoServer => {
|
|||
event: mk(
|
||||
'm.room.message',
|
||||
l.from,
|
||||
{ msgtype: 'm.text', body: l.body, ...(l.pose ? { [POSE_KEY]: l.pose } : {}) },
|
||||
{
|
||||
msgtype: 'm.text',
|
||||
body: l.body,
|
||||
...(l.html ? { format: 'org.matrix.custom.html', formatted_body: l.html } : {}),
|
||||
...(l.pose ? { [POSE_KEY]: l.pose } : {}),
|
||||
},
|
||||
now() - l.minutesAgo * 60 * 1000
|
||||
),
|
||||
});
|
||||
|
|
|
|||