Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-2977]): paint Loop Trimmer frames at source resolution instead of a display-sized canvas
[._.]/ Adam Eivye416234a48bb
diff --git a/client/src/components/sprites/LoopTrimmer.jsx b/client/src/components/sprites/LoopTrimmer.jsxindex 3db8ef2624..e89126575b 100644--- a/client/src/components/sprites/LoopTrimmer.jsx+++ b/client/src/components/sprites/LoopTrimmer.jsx@@ -7,7 +7,7 @@ import {import toast from '../ui/Toast';import { trimSpriteWalk } from '../../services/apiSprites.js';import { useAsyncAction } from '../../hooks/useAsyncAction.js';-import { spriteAssetUrl, paintCheckerboard } from './spriteAssets.js';+import { spriteAssetUrl, checkerboardStyle, PIXELATED } from './spriteAssets.js';import SpritePreview from './SpritePreview.jsx';import {buildTrimmerSources, allColumns, invertColumns, phaseLabelFor, sanitizeTrimSlug,@@ -24,29 +24,55 @@ import {const MAIN_PX = 192;const THUMB_PX = 64;-// One frame of a packed strip on a checkerboarded canvas. Its own ref+effect so-// each thumbnail repaints independently when the image loads or geometry shifts.+// One frame of a packed strip, painted at SOURCE resolution (#2977).+//+// The backing store is the cell's own pixel size (384² for a native walk),+// never the display size — `drawImage` copies the cell 1:1 so JS never+// resamples, and CSS alone scales it down to the thumbnail/preview box. The+// earlier version sized the canvas at THUMB_PX/MAIN_PX, which decimated 384→64+// nearest-neighbor and then let the browser smooth-upscale that back to the+// grid column: the "fuzzy / compressed" look this replaces.+//+// Following SpritePreview's rule, the checkerboard goes on the BOX (a CSS+// background at a constant on-screen cell size) rather than into the canvas —+// painted into a 384px backing store its squares would shrink with the scale+// factor — and the canvas carries the shared PIXELATED style so the browser's+// scale stays nearest-neighbor like every other sprite surface.function FrameCanvas({ img, col, cellW, cellH, size }) {const ref = useRef(null);+ // Natural cell geometry, rounded to whole pixels for the backing store. Zero+ // until the strip <img> loads.+ const w = cellW > 0 ? Math.max(1, Math.round(cellW)) : 0;+ const h = cellH > 0 ? Math.max(1, Math.round(cellH)) : 0;+ const ready = w > 0 && h > 0;+useEffect(() => {const canvas = ref.current;- if (!canvas) return;+ if (!canvas || !img || !ready) return;const ctx = canvas.getContext('2d');if (!ctx) return; // jsdom / context-less canvas- paintCheckerboard(ctx, canvas.width, canvas.height, size >= MAIN_PX ? 8 : 5);- if (img && cellW > 0 && cellH > 0) {- ctx.imageSmoothingEnabled = false;- ctx.drawImage(img, col * cellW, 0, cellW, cellH, 0, 0, canvas.width, canvas.height);- }- }, [img, col, cellW, cellH, size]);- const aspect = cellW > 0 && cellH > 0 ? cellH / cellW : 1;+ // The canvas is transparent now that the checkerboard moved to the box, so+ // a frame swap must clear before drawing or the previous cell shows+ // through this one's alpha.+ ctx.clearRect(0, 0, w, h);+ ctx.imageSmoothingEnabled = false;+ ctx.drawImage(img, col * cellW, 0, cellW, cellH, 0, 0, w, h);+ }, [img, col, cellW, cellH, w, h, ready]);++ // The box holds the frame's aspect whether or not the strip has loaded, so+ // the grid doesn't collapse to zero height and then reflow on load.return (- <canvas- ref={ref}- width={size}- height={Math.round(size * aspect)}- className="w-full h-auto block"- />+ <div+ className="w-full block overflow-hidden"+ style={{+ ...checkerboardStyle(size >= MAIN_PX ? 8 : 5),+ aspectRatio: ready ? `${w} / ${h}` : '1 / 1',+ }}+ >+ {ready && (+ <canvas ref={ref} width={w} height={h} className="w-full h-auto block" style={PIXELATED} />+ )}+ </div>);}diff --git a/client/src/components/sprites/LoopTrimmer.test.jsx b/client/src/components/sprites/LoopTrimmer.test.jsxindex c9e4567745..2cc09fbcfb 100644--- a/client/src/components/sprites/LoopTrimmer.test.jsx+++ b/client/src/components/sprites/LoopTrimmer.test.jsx@@ -23,6 +23,30 @@ import { trimSpriteWalk } from '../../services/apiSprites.js';// "Not implemented: getContext" warning for every frame canvas it renders.HTMLCanvasElement.prototype.getContext = () => null;+// jsdom never fetches, so a real `new Image()` would never fire onload and the+// trimmer's cell geometry would stay 0×0 — the frame canvases would never+// mount. This fake reports a known natural size (8 cells of 384², the native+// walk strip) and fires onload on the next tick, which is what lets the+// source-resolution assertions below see real dimensions.+const STRIP_CELL_PX = 384;+const STRIP_FRAMES = 8;+class FakeImage {+ constructor() {+ this.naturalWidth = STRIP_CELL_PX * STRIP_FRAMES;+ this.naturalHeight = STRIP_CELL_PX;+ this.onload = null;+ }++ set src(value) {+ this._src = value;+ // Async, like a real decode — so a test can also observe the pre-load state.+ setTimeout(() => { if (this.onload) this.onload(); }, 0);+ }++ get src() { return this._src; }+}+global.Image = FakeImage;+const grokRun = {id: 'walk-east-1', direction: 'east', status: 'candidate',stripPreview: { stripPath: 'grok/walk-east-1/generated/strip.png', frameCount: 8, fps: 12 },@@ -104,6 +128,36 @@ describe('LoopTrimmer', () => {expect(screen.getByRole('button', { name: /Save trim/ })).toBeDisabled();});+ // #2977: the trimmer used to size each canvas at its DISPLAY size (64/192px),+ // decimating a 384px cell nearest-neighbor and then letting CSS smooth-upscale+ // the result — the "fuzzy" render. These lock in source-resolution painting.+ it('paints every frame at the source cell resolution, scaled by CSS with pixelated', async () => {+ const { container } = renderTrimmer();+ await waitFor(() => expect(container.querySelectorAll('canvas').length).toBeGreaterThan(0));+ const canvases = [...container.querySelectorAll('canvas')];+ expect(canvases).toHaveLength(STRIP_FRAMES + 1); // 8 thumbnails + the main preview+ canvases.forEach((canvas) => {+ expect(canvas.width).toBe(STRIP_CELL_PX);+ expect(canvas.height).toBe(STRIP_CELL_PX);+ expect(canvas).toHaveStyle({ imageRendering: 'pixelated' });+ });+ });++ it('puts the checkerboard on the frame box, not inside the canvas', async () => {+ const { container } = renderTrimmer();+ await waitFor(() => expect(container.querySelectorAll('canvas').length).toBeGreaterThan(0));+ const canvas = container.querySelector('canvas');+ expect(canvas.getAttribute('style')).not.toMatch(/linear-gradient/);+ expect(canvas.parentElement.getAttribute('style')).toMatch(/linear-gradient/);+ });++ it('holds the frame boxes with a checkerboard placeholder before the strip loads', () => {+ const { container } = renderTrimmer();+ expect(container.querySelectorAll('canvas')).toHaveLength(0);+ // Every frame box (8 thumbnails + main preview) is already laid out.+ expect(container.querySelectorAll('[style*="linear-gradient"]')).toHaveLength(STRIP_FRAMES + 1);+ });+it('shows an empty state when there is nothing to trim', () => {renderTrimmer({ walk: { runs: [] } });expect(screen.getByText(/No animation strips to trim/)).toBeTruthy();diff --git a/client/src/components/sprites/spriteAssets.js b/client/src/components/sprites/spriteAssets.jsindex bd4ccf15ff..5fe4985d03 100644--- a/client/src/components/sprites/spriteAssets.js+++ b/client/src/components/sprites/spriteAssets.js@@ -38,28 +38,12 @@ export function checkerboardStyle(cell = 6) {// constant, and every consumer treats React style props as read-only.export const PIXELATED = Object.freeze({ imageRendering: 'pixelated' });-// Canvas equivalent of the CSS checkerboard above (#2933). A `<canvas>` can't-// read `var(--sprite-checker-*)` or paint a CSS gradient, so the Loop Trimmer's-// canvases resolve the same custom properties off the document root (falling-// back to the dark literals when a theme sets neither) and fill the squares by-// hand. Kept next to `checkerboardStyle` so the two stay the same pattern.-function checkerColor(name, fallback) {- if (typeof window === 'undefined' || typeof getComputedStyle !== 'function') return fallback;- const value = getComputedStyle(document.documentElement).getPropertyValue(name).trim();- return value || fallback;-}--export function paintCheckerboard(ctx, width, height, cell = 6) {- if (!ctx) return; // jsdom / a context-less canvas — nothing to paint- ctx.fillStyle = checkerColor('--sprite-checker-dark', '#191919');- ctx.fillRect(0, 0, width, height);- ctx.fillStyle = checkerColor('--sprite-checker-light', '#2e2e2e');- for (let y = 0; y < height; y += cell) {- for (let x = 0; x < width; x += cell) {- if ((Math.floor(x / cell) + Math.floor(y / cell)) % 2 === 0) ctx.fillRect(x, y, cell, cell);- }- }-}+// There is deliberately no canvas-painted checkerboard variant. The Loop+// Trimmer briefly had one (#2933) so its <canvas> frames could show a checker,+// but painting the pattern INTO a backing store ties the check-square size to+// the canvas's scale factor — at source resolution (#2977) the squares shrink+// to noise. Every surface, canvas or <img>, now puts `checkerboardStyle` on the+// wrapping box instead, which is the same rule SpritePreview documents.// sharp can probe more formats than a browser can paint — a TIFF yields clean// metadata but renders as a broken-image icon in Chrome/Firefox. So the server