okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8820fa433
main
1#!/usr/bin/env node 2/** 3* The app and installer icon, refined from the existing Strata mark (apps/host/public/brand/strata-mark-*.svg and the current 4* icons/icon.png): the same three rounded bars on the same dark tile, in the same colours. Nothing is redrawn. What changes is 5* how it is cut for small sizes: at 16-48 px the bars are snapped to whole pixels and made a little bolder and wider so they 6* stay crisp instead of blurring; from 64 px up the geometry is the mark's own proportions. 7* 8* node apps/desktop/scripts/make-icons.mjs [--out <folder>] writes icon-<size>.png for every size and icon.ico 9*/ 10import { existsSync , mkdirSync , writeFileSync } from 'node:fs' ; 11import { dirname , join , resolve } from 'node:path' ; 12import { fileURLToPath , pathToFileURL } from 'node:url' ; 13 14const args = Object . fromEntries ( process . argv . slice ( 2 ). reduce (( acc , a , i , all ) => ( a . startsWith ( '--' ) ?[ ...acc , [ a . slice ( 2 ), all [ i + 1 ]]] :acc ), [])); 15const here = dirname ( fileURLToPath ( import . meta. url )); 16const host = resolve ( here , '../../host' ); 17const out = resolve ( args . out ?? join ( here , '../src-tauri/icons' )); 18mkdirSync ( out , { recursive :true }); 19const { chromium} = await import ( pathToFileURL ( join ( host , 'node_modules/playwright-core/index.mjs' )). href ). catch (() => import ( 'playwright-core' )); 20const CHROME = process . env . CHROME ?? [ 'C:/Program Files/Google/Chrome/Application/chrome.exe' , '/usr/bin/google-chrome' ]. find ( existsSync ); 21 22const TILE = '#161a1d' , LIGHT = '#eef1f3' , GREEN = '#34d399' ; // the colours of the current icon.png 23 24/** Integer geometry for the small sizes: bars on whole pixels, centred. Returns [{x,y,w,h,fill}]. */ 25function hinted ( size ) { 26const bar = Math . max ( 2 , Math . round ( size * 0.14 )), gap = Math . max ( 2 , Math . round ( size * 0.1 )), mid = bar + 1 ; 27const total = 2 * bar + mid + 2 * gap , top = Math . floor (( size - total ) / 2 ); 28const even = w => ( w % 2 === size % 2 ?w :w + 1 ); 29const wide = even ( Math . round ( size * 0.5 )), long = even ( Math . round ( size * 0.76 )); 30return [ 31{ x :( size - wide ) / 2 , y :top , w :wide , h :bar , fill :LIGHT }, 32{ x :( size - long ) / 2 , y :top + bar + gap , w :long , h :mid , fill :GREEN }, 33{ x :( size - wide ) / 2 , y :top + bar + gap + mid + gap , w :wide , h :bar , fill :LIGHT }, 34]; 35} 36/** The mark's own proportions (from icon.png at 512): bars 34% / 50% / 34% wide, 9% high, on a tile with 21.5% corners. */ 37function proportional ( size ) { 38const k = size / 512 ; 39return [ 40{ x :170 * k , y :156 * k , w :173 * k , h :46 * k , fill :LIGHT }, 41{ x :128 * k , y :232 * k , w :256 * k , h :48 * k , fill :GREEN }, 42{ x :170 * k , y :309 * k , w :173 * k , h :46 * k , fill :LIGHT }, 43]; 44} 45function svg ( size ) { 46const small = size <= 48 ; 47const bars = ( small ?hinted ( size ) :proportional ( size )); 48const radius = small ?Math . round ( size * 0.22 ) :size * 0.215 ; 49const rects = bars . map ( b => `<rect x=" ${ b . x } " y=" ${ b . y } " width=" ${ b . w } " height=" ${ b . h } " rx=" ${ small ? Math . min ( b . h / 2 , 1.5 + size / 32 ) : b . h / 2 } " fill=" ${ b . fill } " ${ small ? ' shape-rendering="crispEdges"' : '' } />` ). join ( '' ); 50return `<svg xmlns="http://www.w3.org/2000/svg" width=" ${ size } " height=" ${ size } " viewBox="0 0 ${ size } ${ size } "><rect width=" ${ size } " height=" ${ size } " rx=" ${ radius } " fill=" ${ TILE } "/> ${ rects } </svg>` ; 51} 52 53const SIZES = [ 16 , 20 , 24 , 32 , 40 , 48 , 64 , 96 , 128 , 256 , 512 , 1024 ]; 54const browser = await chromium . launch ({ executablePath :CHROME , headless :true }); 55const png = {}; 56for ( const size of SIZES ) { 57const page = await browser . newPage ({ viewport :{ width :size , height :size }, deviceScaleFactor :1 }); 58await page . setContent ( `<!doctype html><body style="margin:0;background:transparent"> ${ svg ( size )} </body>` ); 59png [ size ] = await page . screenshot ({ omitBackground :true , clip :{ x :0 , y :0 , width :size , height :size } }); 60await page . close (); 61writeFileSync ( join ( out , `icon- ${ size } .png` ), png [ size ]); 62} 63await browser . close (); 64 65// The .ico: one PNG image per size (16-256), the sizes Windows asks for at 100-250% scaling. 66const ICO = [ 16 , 20 , 24 , 32 , 40 , 48 , 64 , 96 , 128 , 256 ]; 67const head = Buffer . alloc ( 6 ); head . writeUInt16LE ( 0 , 0 ); head . writeUInt16LE ( 1 , 2 ); head . writeUInt16LE ( ICO . length , 4 ); 68let offset = 6 + 16 * ICO . length ; 69const entries = [], blobs = []; 70for ( const size of ICO ) { 71const data = png [ size ], e = Buffer . alloc ( 16 ); 72e . writeUInt8 ( size === 256 ?0 :size , 0 ); e . writeUInt8 ( size === 256 ?0 :size , 1 ); e . writeUInt8 ( 0 , 2 ); e . writeUInt8 ( 0 , 3 ); 73e . writeUInt16LE ( 1 , 4 ); e . writeUInt16LE ( 32 , 6 ); e . writeUInt32LE ( data . length , 8 ); e . writeUInt32LE ( offset , 12 ); 74offset += data . length ; entries . push ( e ); blobs . push ( data ); 75} 76writeFileSync ( join ( out , 'icon.ico' ), Buffer . concat ([ head , ...entries , ...blobs ])); 77writeFileSync ( join ( out , 'icon.png' ), png [ 512 ]); 78console . log ( 'icons in' , out , ICO . join ( ',' ));