From 7a28b38870edc01431f85b72e98a5207768488f2 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 10 Nov 2026 02:10:30 +0800 Subject: [PATCH] =?UTF-8?q?day-card=200.1.2:=20a=20day=20just=20begun=20re?= =?UTF-8?q?ads=20<0.1=C3=97,=20an=20app's=20drawn=20icon=20prints=20as=20a?= =?UTF-8?q?=20drawing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by trying Copy image and Save PNG in the real app with real usage: - VS AVERAGE DAY read "0.0×" early in a day ($0.07 against a ~$180 average). Any ratio above 0 and under 0.1 now reads "<0.1×". - Alma's icon (a drawing on its own light ground) printed as a black square, because every colour icon was filled with the ink. A picture that is mostly light with something dark drawn on it now prints in the ink with its near-white parts left the paper's colour. Mono logos and colour marks with no ground of their own (Claude, DeepSeek) are still filled solid. Run: - mote-run bun test packages/day-card: 12 pass, 0 fail (two new versus cases: 0.07/180 → "<0.1×", 0.5/5 → "0.1×"). - Real app: magpie 0.1.3443 (/Applications) in a sandbox HOME on 127.0.0.1:3486, the owner's usage.jsonl copied in, this app.js and view.js in the installed package. The page shows "<0.1×" and Alma's drawing; Claude and DeepSeek marks unchanged. Copy image showed "Copied" and put a 1708x2278 PNG on the clipboard; Save PNG said "Saved to ~/Downloads/magpie 2026-11-10-2.png" (the first save's file kept, not overwritten), byte-identical to the clipboard PNG. Not tried: Windows and Linux webviews. --- packages/day-card/day-card.test.mjs | 3 +++ packages/day-card/package.json | 2 +- packages/day-card/page/app.js | 24 ++++++++++++++++-------- packages/day-card/page/view.js | 2 ++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/day-card/day-card.test.mjs b/packages/day-card/day-card.test.mjs index 375c71f..c9f66f8 100644 --- a/packages/day-card/day-card.test.mjs +++ b/packages/day-card/day-card.test.mjs @@ -156,6 +156,9 @@ test("streak, and the day against the average day before it", () => { expect(V.versus({ cost: 500 }, { cost: 2, tokens: 1 })).toBe("250×") // nothing priced: by tokens expect(V.versus({ cost: 0, input: 300 }, { cost: 0, tokens: 100 })).toBe("3.0×") + // early in a day: a sliver of the average, not none + expect(V.versus({ cost: 0.07 }, { cost: 180, tokens: 1 })).toBe("<0.1×") + expect(V.versus({ cost: 0.5 }, { cost: 5, tokens: 1 })).toBe("0.1×") expect(V.versus({ cost: 1 }, null)).toBe("–") }) diff --git a/packages/day-card/package.json b/packages/day-card/package.json index 3a12cf3..b3f091e 100644 --- a/packages/day-card/package.json +++ b/packages/day-card/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/page-day-card", - "version": "0.1.1", + "version": "0.1.2", "description": "A page in magpie's window that draws a day of your AI usage as a card: tokens, cost, each agent and its models, your streak and your average day. Copy it as a picture or save it as a PNG", "files": ["page", "README.md"], "keywords": ["magpie", "magpie-page", "usage", "tokens", "cost", "card"], diff --git a/packages/day-card/page/app.js b/packages/day-card/page/app.js index bee2fe8..e5a4697 100644 --- a/packages/day-card/page/app.js +++ b/packages/day-card/page/app.js @@ -60,9 +60,10 @@ } return state.icons.get(ic.src); } - // A mark (a mono logo, or a colour one on a clear ground) is filled with - // the ink; a picture with a ground of its own prints in the ink, only its - // near-white parts left the paper's. + // A mark (a mono logo, or a colour one with no ground of its own) is + // filled with the ink; a picture on a light ground of its own (an app's + // tile, a drawing) prints in the ink, only its near-white parts left the + // paper's, and what is clear around it stays clear. function drawIcon(ctx, ic, x, y, size, scale) { if (!ic) { ctx.fillStyle = INK; @@ -81,15 +82,22 @@ try { const d = o.getImageData(0, 0, px, px); const p = d.data; - let empty = 0; - for (let i = 3; i < p.length; i += 4) if (p[i] < 16) empty++; - clear = empty / (px * px) > 0.2; + const lum = (i) => (0.2126 * p[i] + 0.7152 * p[i + 1] + 0.0722 * p[i + 2]) / 255; + let solid = 0, light = 0, dark = 0; + for (let i = 0; i < p.length; i += 4) { + if (p[i + 3] < 128) continue; + solid++; + const v = lum(i); + if (v > 0.8) light++; + else if (v < 0.5) dark++; + } + // a ground: mostly light, with something dark drawn on it + clear = !(solid && light / solid > 0.35 && dark / solid > 0.05) && solid < px * px * 0.8; if (!clear) { const ink = [0x1f, 0x1d, 0x20], paper = [0xf7, 0xf4, 0xed]; for (let i = 0; i < p.length; i += 4) { // only what is near white stays light: a logo prints solid - const v = (0.2126 * p[i] + 0.7152 * p[i + 1] + 0.0722 * p[i + 2]) / 255; - const t = Math.min(1, Math.max(0, (v - 0.65) / 0.2)); + const t = Math.min(1, Math.max(0, (lum(i) - 0.65) / 0.2)); const l = t * t * (3 - 2 * t); for (let k = 0; k < 3; k++) p[i + k] = ink[k] + (paper[k] - ink[k]) * l; } diff --git a/packages/day-card/page/view.js b/packages/day-card/page/view.js index c7b9d6d..aac4ba3 100644 --- a/packages/day-card/page/view.js +++ b/packages/day-card/page/view.js @@ -193,6 +193,8 @@ if (avg.cost > 0 && Number(day.cost) > 0) r = Number(day.cost) / avg.cost; else if (avg.tokens > 0) r = tokensOf(day) / avg.tokens; else return "–"; + // a day just begun is a sliver of the average, not none of it + if (r > 0 && r < 0.1) return "<0.1×"; return (r >= 100 ? Math.round(r).toLocaleString("en-US") : r.toFixed(1)) + "×"; }