Contact sheet packed into a grid, Android tablet body for Play tablet sizes, variant in the feature graphic

This commit is contained in:
CRTkafa 2026-10-10 22:16:38 +08:00
parent df1a757a8b
commit 595bdbcf78
4 changed files with 50 additions and 14 deletions

View file

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="/fonts/fonts.css"> <link rel="stylesheet" href="/fonts/fonts.css">
<!-- Play feature graphic, 1024 x 500: logo (or the app name) on the left, a tilted phone with one frame on the right. <!-- Play feature graphic, 1024 x 500: logo (or the app name) on the left, a tilted phone with one frame on the right.
feature.html?lang=<id>. Rendered by `storebound shots render`. Keep text out of it: Play overlays its own UI. --> feature.html?lang=<id>[&v=<variant>]. Rendered by `storebound shots render`. Keep text out of it: Play overlays its own UI. -->
<style> <style>
* { box-sizing: border-box; margin: 0; padding: 0; } * { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 1024px; height: 500px; overflow: hidden; background: #000; } html, body { width: 1024px; height: 500px; overflow: hidden; background: #000; }
@ -38,8 +38,9 @@
<div class="tel"><div class="screen"><div class="bar" id="bar"></div><img id="f"><div class="island"></div></div></div> <div class="tel"><div class="screen"><div class="bar" id="bar"></div><img id="f"><div class="island"></div></div></div>
</div> </div>
<script type="module"> <script type="module">
const lang = new URLSearchParams(location.search).get('lang'); const q = new URLSearchParams(location.search);
const job = await (await fetch(`/job.json?lang=${encodeURIComponent(lang)}&feature=1`)).json(); const lang = q.get('lang'), V = q.get('v') ?? '';
const job = await (await fetch(`/job.json?lang=${encodeURIComponent(lang)}&feature=1&v=${encodeURIComponent(V)}`)).json();
const P = job.palette, R = document.documentElement.style, dev = job.phone; const P = job.palette, R = document.documentElement.style, dev = job.phone;
R.setProperty('--bg', `linear-gradient(160deg, ${P.bg[0]} 0%, ${P.bg[1]} 50%, ${P.bg[2]} 100%)`); R.setProperty('--bg', `linear-gradient(160deg, ${P.bg[0]} 0%, ${P.bg[1]} 50%, ${P.bg[2]} 100%)`);
R.setProperty('--glow', P.glow); R.setProperty('--ink', P.ink); R.setProperty('--shadow', P.shadow); R.setProperty('--glow', P.glow); R.setProperty('--ink', P.ink); R.setProperty('--shadow', P.shadow);

View file

@ -130,3 +130,35 @@ export function captionsFor(copy: Record<string, SceneCopy> | undefined, sceneId
if (!titles.length) return Array.from({ length: clips }, () => ''); if (!titles.length) return Array.from({ length: clips }, () => '');
return Array.from({ length: clips }, (_, i) => titles[i % titles.length]!); return Array.from({ length: clips }, (_, i) => titles[i % titles.length]!);
} }
export interface SheetTile { file: string; x: number; y: number; w: number; h: number }
/** Contact sheet layout: one block per size (its scenes side by side, all at the same height; the feature graphic at
* half height), blocks packed onto shelves up to `maxW` wide so a project with one or two scenes gets a compact grid
* instead of a tall strip. Pure. */
export function sheetLayout(rows: { size: string; files: string[] }[], o: { h?: number; gap?: number; maxW?: number } = {}): { w: number; h: number; tiles: SheetTile[] } {
const H0 = o.h ?? 900, gap = o.gap ?? 24;
const blocks = rows.filter(r => r.files.length).map(r => {
const d = SIZES[r.size]!, h = d.feature ? Math.round(H0 / 2) : H0, w = Math.round(h * d.w / d.h);
return { r, h, tw: w, w: r.files.length * w + (r.files.length - 1) * gap };
});
const maxW = Math.max(o.maxW ?? 3600, ...blocks.map(b => b.w));
const tiles: SheetTile[] = [];
let x = gap, y = gap, shelf = 0, W = 0;
for (const b of blocks) {
if (x > gap && x + b.w > maxW + gap) { x = gap; y += shelf + gap; shelf = 0; }
b.r.files.forEach((file, i) => tiles.push({ file, x: x + i * (b.tw + gap), y, w: b.tw, h: b.h }));
x += b.w + gap * 2;
shelf = Math.max(shelf, b.h);
W = Math.max(W, x - gap);
}
return { w: W, h: blocks.length ? y + shelf + gap : 0, tiles };
}
/** Renders root an upload reads from: the base folder, or <renders>/<variant> for `--variant <id>` (must be one of
* shots.variants; "base" or empty = the base renders). Pure. */
export function variantRoot(renders: string, variant: string | undefined, variants: Record<string, unknown> | undefined): string {
if (!variant || variant === 'base') return renders;
if (!variants?.[variant]) throw new Error(`--variant ${variant}: not in shots.variants (${Object.keys(variants ?? {}).join(', ') || 'none configured'})`);
return `${renders.replace(/\/$/, '')}/${variant}`;
}

View file

@ -2,7 +2,7 @@
// storebound shots render [--lang en,tr] [--size ios69,play,feature] [--scenes 1,3] [--variant b | --variants] // storebound shots render [--lang en,tr] [--size ios69,play,feature] [--scenes 1,3] [--variant b | --variants]
// [--no-sheet] [--port 8792] // [--no-sheet] [--port 8792]
// Out: <shots.out>/<lang>/<size>/NN.png (24-bit RGB: Play rejects alpha / palette PNGs), <lang>/feature/1024x500.png, // Out: <shots.out>/<lang>/<size>/NN.png (24-bit RGB: Play rejects alpha / palette PNGs), <lang>/feature/1024x500.png,
// <lang>/sheet.png (contact sheet of every size, for a quick review) and <shots.out>/report.json (text overflow flags // <lang>/sheet.png (contact sheet of every size packed into a grid, for a quick review) and <shots.out>/report.json (text overflow flags
// per image, read by `shots check` and `shots gallery`). Variants go to <shots.out>/<variant>/<lang>/... // per image, read by `shots check` and `shots gallery`). Variants go to <shots.out>/<variant>/<lang>/...
// Default sizes: defaultSizes() (ipad13 only with apple.ipad). Needs playwright + ffmpeg. // Default sizes: defaultSizes() (ipad13 only with apple.ipad). Needs playwright + ffmpeg.
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'; import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
@ -12,7 +12,7 @@ import type { Ctx } from '../lib/ctx';
import { need } from '../lib/ctx'; import { need } from '../lib/ctx';
import { done, log, warn } from '../lib/log'; import { done, log, warn } from '../lib/log';
import { launch } from './browser'; import { launch } from './browser';
import { type CopyFile, SIZES, copyText, defaultSizes, frameDims, mergeCopy, palette, renderDir, scriptFont, validateCopy, variantScenes } from './lib'; import { type CopyFile, SIZES, copyText, defaultSizes, frameDims, mergeCopy, palette, renderDir, scriptFont, sheetLayout, validateCopy, variantScenes } from './lib';
import { type RenderReport, mergeReport, readReport } from './report'; import { type RenderReport, mergeReport, readReport } from './report';
const TYPES: Record<string, string> = { html: 'text/html; charset=utf-8', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', const TYPES: Record<string, string> = { html: 'text/html; charset=utf-8', png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg',
@ -120,19 +120,15 @@ export async function run(ctx: Ctx): Promise<void> {
const files: string[] = []; const files: string[] = [];
for (const [i, id] of sceneIds.entries()) { for (const [i, id] of sceneIds.entries()) {
const f = join(dir, size, `${String(i + 1).padStart(2, '0')}.png`); const f = join(dir, size, `${String(i + 1).padStart(2, '0')}.png`);
await shoot(`${base}/template.html?s=${encodeURIComponent(id)}&w=${s.w}&h=${s.h}&lang=${encodeURIComponent(lang)}${s.device ? '&device=tablet' : ''}${vq}`, s.w, s.h, f); await shoot(`${base}/template.html?s=${encodeURIComponent(id)}&w=${s.w}&h=${s.h}&lang=${encodeURIComponent(lang)}${s.device ? '&device=tablet' : ''}${size === 'tab7' || size === 'tab10' ? '&style=android' : ''}${vq}`, s.w, s.h, f);
files.push(f); files.push(f);
} }
rows.push({ size, files }); rows.push({ size, files });
} }
if (!a.has('no-sheet') && rows.length) { if (!a.has('no-sheet') && rows.length) {
const H0 = 900, gap = 24; const lay = sheetLayout(rows);
let y = gap, W = 0, imgs = ''; const imgs = lay.tiles.map(t => `<img src="/out/${relative(outDir, t.file)}" style="position:absolute;left:${t.x}px;top:${t.y}px;width:${t.w}px;height:${t.h}px;border-radius:14px">`).join('');
for (const row of rows) { const W = lay.w, y = lay.h;
const d = SIZES[row.size]!, h = d.feature ? H0 / 2 : H0, w = Math.round(h * d.w / d.h);
row.files.forEach((f, i) => { imgs += `<img src="/out/${relative(outDir, f)}" style="position:absolute;left:${gap + i * (w + gap)}px;top:${y}px;width:${w}px;height:${h}px;border-radius:14px">`; });
W = Math.max(W, gap + row.files.length * (w + gap)); y += h + gap;
}
const sheet = join(dir, '.sheet.html'); const sheet = join(dir, '.sheet.html');
await Bun.write(sheet, `<!doctype html><body style="margin:0;background:#141418;width:${W}px;height:${y}px;position:relative">${imgs} await Bun.write(sheet, `<!doctype html><body style="margin:0;background:#141418;width:${W}px;height:${y}px;position:relative">${imgs}
<script>Promise.all([...document.images].map(i=>i.decode())).then(()=>document.body.dataset.ready='1')</script></body>`); <script>Promise.all([...document.images].map(i=>i.decode())).then(()=>document.body.dataset.ready='1')</script></body>`);

View file

@ -5,7 +5,8 @@
<link rel="stylesheet" href="/fonts/fonts.css"> <link rel="stylesheet" href="/fonts/fonts.css">
<!-- <!--
Store screenshot template (rendered by `storebound shots render`, served by its local server). Store screenshot template (rendered by `storebound shots render`, served by its local server).
template.html?s=<scene id>&w=<px>&h=<px>&lang=<id>[&device=tablet][&v=<variant>] template.html?s=<scene id>&w=<px>&h=<px>&lang=<id>[&device=tablet][&style=android][&v=<variant>]
style=android (Play 7" / 10" tablets): a plain Android tablet body (thin dark bezel, punch-hole camera) instead of the iPad look.
/job.json gives the scene (palette, frames, badge slots), the words for this language and the font families. /job.json gives the scene (palette, frames, badge slots), the words for this language and the font families.
Layout: everything is in u = W / 100; the text block is measured first, then the phone fills the room below it. Layout: everything is in u = W / 100; the text block is measured first, then the phone fills the room below it.
--> -->
@ -77,6 +78,11 @@
.tablet .bar { padding: 0 5%; font-size: calc(var(--pw) * .024); } .tablet .bar { padding: 0 5%; font-size: calc(var(--pw) * .024); }
.tablet .bar svg { height: calc(var(--pw) * .018); } .tablet .bar svg { height: calc(var(--pw) * .018); }
.tablet .island { width: calc(var(--pw) * .016); height: calc(var(--pw) * .016); top: calc(var(--pw) * .007); } .tablet .island { width: calc(var(--pw) * .016); height: calc(var(--pw) * .016); top: calc(var(--pw) * .007); }
.android .tel { border-radius: calc(var(--pw) * .04); padding: calc(var(--pw) * .014);
background: linear-gradient(160deg, #3a3b41 0%, #1c1d21 30%, #111215 70%, #2c2d33 100%); }
.android .screen { border-radius: calc(var(--pw) * .028); }
.android .island { width: calc(var(--pw) * .013); height: calc(var(--pw) * .013); top: calc(var(--pw) * .009); }
.android .bar { padding: 0 4%; }
/* badges */ /* badges */
.badge { position: absolute; z-index: 9; display: flex; align-items: center; gap: calc(var(--u) * 2.2); .badge { position: absolute; z-index: 9; display: flex; align-items: center; gap: calc(var(--u) * 2.2);
@ -130,6 +136,7 @@ if (CJK) R.setProperty('--sk', '.06');
if (LANG.startsWith('ja')) document.documentElement.style.wordBreak = 'auto-phrase'; if (LANG.startsWith('ja')) document.documentElement.style.wordBreak = 'auto-phrase';
if (LANG.startsWith('ko')) document.documentElement.style.wordBreak = 'keep-all'; if (LANG.startsWith('ko')) document.documentElement.style.wordBreak = 'keep-all';
if (tablet) document.body.classList.add('tablet'); if (tablet) document.body.classList.add('tablet');
if (q.get('style') === 'android') document.body.classList.add('android');
const tall = Hu > 200; // iOS 6.9" / 6.5" vs 16:9 const tall = Hu > 200; // iOS 6.9" / 6.5" vs 16:9
const wide = Hu < 150; // 3:4 iPad const wide = Hu < 150; // 3:4 iPad
R.setProperty('--top', tall ? 9 : wide ? 4 : 5.5); R.setProperty('--top', tall ? 9 : wide ? 4 : 5.5);