Files
kuentagym/frontend/scripts/build-app-icons.mjs
T
dsantillan c3c1c2836c
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Salud: Today by default, chart panels, and an aura behind the whole app
Three things the screen was missing, plus the launch photo.

**Today.** The period filter started at 30 days, which buried the question a five-minute
cadence exists to answer: what do the numbers say right now? "Today" is now first and the
default, and it means today — the grid drops metrics nobody has measured today (the scale
is not stepped on every morning), and if nothing has come in yet the grid falls back to
everything and says so rather than showing an empty screen. The number on every card was
always the newest reading; what is new is that the card says which day it is and when it
landed ("hoy · hace 12 min"), so the claim can be checked instead of trusted. The screen
also refreshes itself every minute while it is open, which is what makes a five-minute
cadence visible.

The filter and the charts want different windows, and the view keeps them apart: a
sparkline or a trend needs history, so the fetch never asks for less than a week even in
"Today", and anything labelled with a window says which one it is. (The alternative —
fetching one day and drawing nothing — would have made Today the one mode with no charts.)

**Chart panels.** Every tile carries a 52px sparkline, which shows a shape and cannot be
read. The first few metrics in the catalogue's own order now get a full-width panel each:
axes, the window's min / avg / max, and the card's own colour, so a panel and its tile are
recognisably the same metric.

**The aura.** index.html carries the three "Diamond Weave" layers and index.css puts the
base colour on `body` where the blend modes composite against it, with `#app` lifted to
z-index 1 so the absolutely-positioned layers cannot paint over the page (everything modal
was already higher). Dark keeps `screen`; the light theme switches the same layers to
`multiply`, because screened amber over white is amber that has been washed away. The blur
radii follow the spec per breakpoint, and the layers are fixed rather than absolute so
scrolling never repaints two 200px blurs.

**The launch screen.** assets/splash.jpg is a 3862×5786 photograph from a camera, so
nothing ships it raw: build-app-icons.mjs now derives public/splash.webp (1170px wide, 62 KB
— WebP because it is a photo) for the boot screen and resources/splash.jpg (2732×2732,
fitted on the aura's base colour rather than cropped, so a portrait composition survives)
for @capacitor/assets. The 12 MB original is gitignored: the derived files are committed,
so a clone still builds, and the script says what is missing when regeneration is asked for
without it.
2026-09-23 11:32:51 -04:00

120 lines
7.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* build-app-icons.mjs — derive every icon the app ships from one source image.
*
* The source is assets/logoym.png (a PNG despite its old .jpeg name; it has a real alpha channel,
* with the emblem's corners transparent). Everything else here is generated, so the app icon, the
* iOS home-screen icon, the in-app brand mark and the Capacitor source icon can never drift apart
* from each other or from the file the owner actually dropped in assets/.
*
* Run it after replacing the source:
*
* cd frontend && node scripts/build-app-icons.mjs
*
* `sharp` comes with @capacitor/assets (a devDependency here), which is the only reason it is
* available without adding a dependency of our own — see CONTRIBUTING.md on that.
*
* THE ONE DESIGN DECISION: the emblem is dark green (its most common colour is #031808, its light
* accents are greens too), and its corners are transparent. So a transparent icon would disappear
* on a dark home screen, and a white one would put a white card behind an already-square logo. The
* canvases below are filled with the emblem's OWN darkest green and the logo is centred at 88% of
* the square: the corners it does not cover blend into it, the maskable safe circle stays clean,
* and the icon reads as one piece at 180 px. Change ICON_BG to re-skin all of them at once.
*/
import sharp from 'sharp'
import { existsSync, readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
// sharp takes paths, not file: URLs — hence fileURLToPath here and in icon() below.
const SRC = fileURLToPath(new URL('../../assets/logoym.png', import.meta.url))
/** The launch photo. 3862×5786 and 12 MB straight off a camera — every version the app ships is
* derived here, because none of them can be that file. */
const SPLASH_SRC = fileURLToPath(new URL('../../assets/splash.jpg', import.meta.url))
// The photograph itself is NOT committed: it is 12 MB straight off a camera, and the two versions
// the app uses are a fraction of that (see the bottom of this file). Keep the original next to the
// repo, or drop a replacement at the same path, and this regenerates from it.
const splashMissing = !existsSync(SPLASH_SRC)
const PUB = new URL('../public/', import.meta.url)
const RES = new URL('../resources/', import.meta.url)
/** The emblem's own dominant colour (sampled from the source), used to fill the icon squares. */
const ICON_BG = '#031808'
/** Behind the native splash, the aura's own base colour (index.css) so the two never disagree. */
const SPLASH_BG = '#100e0b'
/** Fraction of the canvas the emblem occupies. The maskable safe circle is 80% of the square, and
* the emblem's own corners are transparent, so slightly past it costs nothing and gains size. */
const ICON_FIT = 0.88
/** Longest side of the in-app mark. Displayed at 52 px (tab bar) and ~88 px (login), so 256 covers
* a 3× screen twice over; anything larger is bytes nobody looks at. */
const MARK_PX = 256
/* Every PNG here is written as a 256-colour palette. Measured against the full RGBA version the
* mean per-channel error is 1.5/255 — invisible — for a file about 2.5× smaller: the emblem is
* greens on greens, which is exactly what a palette is good at. The transparency survives as the
* palette's own alpha entries (checked: the corners really are alpha 0.) */
const PNG = { palette: true, colours: 256, compressionLevel: 9, effort: 10 }
const logo = sharp(SRC).ensureAlpha().trim()
/** One opaque square with the emblem centred in it. */
async function icon(size, out) {
const inner = Math.round(size * ICON_FIT)
const placed = await logo.clone().resize(inner, inner, { fit: 'inside' }).png().toBuffer()
await sharp({ create: { width: size, height: size, channels: 4, background: ICON_BG } })
.composite([{ input: placed, gravity: 'centre' }])
.png(PNG)
.toFile(fileURLToPath(out))
console.log(` ${out.pathname.split('/').slice(-2).join('/')} ${size}x${size} bg ${ICON_BG}`)
}
console.log('generating app icons from assets/logoym.png')
// The two the web app ships: icon-512 is declared "any maskable" in manifest.json (hence the
// opaque background and the centred emblem), icon-180 is the iOS home screen and the favicon.
await icon(512, new URL('icon-512.png', PUB))
await icon(180, new URL('icon-180.png', PUB))
// The in-app brand mark: transparent, so it sits on the page's own background. Used by the tab
// bar's Start button, the login screen and the boot placeholder.
await logo.clone().resize(MARK_PX, MARK_PX, { fit: 'inside' }).png(PNG)
.toFile(fileURLToPath(new URL('logo.png', PUB)))
const mark = readFileSync(fileURLToPath(new URL('logo.png', PUB)))
console.log(` public/logo.png transparent ${(mark.length / 1024).toFixed(1)} KB`)
// The Capacitor source icon for the native shells (docs/MOBILE.md: `npx @capacitor/assets
// generate` reads resources/). Kept opaque and 1024 wide, which is what that tool wants.
await icon(1024, new URL('icon.png', RES))
/* ---------------------------------------------------------------- the launch screen --
*
* assets/splash.jpg is a photograph — 3862×5786, 12 MB — so nothing ships it as it is. Two
* versions come out of it:
*
* public/splash.webp what the web app shows while the profile loads (`.boot-splash` in
* index.css). Phone-width and WebP, because it is a photograph: the same
* frame as a JPEG at matching quality is several times the bytes.
* resources/splash.png the @capacitor/assets source for the native shells. That tool wants a
* square, so the photo is fitted inside 2732×2732 on the dark base colour
* rather than cropped — a portrait photograph cropped to a square loses
* the composition somebody chose.
*/
const SPLASH_W = 1170 // covers a 390pt phone at 3× without shipping a poster
if (!splashMissing) {
await sharp(SPLASH_SRC)
.resize(SPLASH_W, null, { fit: 'inside', withoutEnlargement: true })
.webp({ quality: 78, effort: 5 })
.toFile(fileURLToPath(new URL('splash.webp', PUB)))
const splashOut = readFileSync(fileURLToPath(new URL('splash.webp', PUB)))
console.log(` public/splash.webp launch screen ${(splashOut.length / 1024).toFixed(0)} KB`)
}
if (splashMissing) {
console.log(' assets/splash.jpg is not here — skipping the launch screen (it is not committed)')
} else {
const splashInner = await sharp(SPLASH_SRC).resize(2732, 2732, { fit: 'inside' }).toBuffer()
// JPEG, not PNG: this is a photograph, and as a PNG it came out at 10.6 MB for no visible gain.
await sharp({ create: { width: 2732, height: 2732, channels: 3, background: SPLASH_BG } })
.composite([{ input: splashInner, gravity: 'centre' }])
.jpeg({ quality: 86, chromaSubsampling: '4:4:4' })
.toFile(fileURLToPath(new URL('splash.jpg', RES)))
const nativeOut = readFileSync(fileURLToPath(new URL('splash.jpg', RES)))
console.log(` resources/splash.jpg native source 2732x2732 bg ${SPLASH_BG} ${(nativeOut.length / 1024 / 1024).toFixed(1)} MB`)
}