import { writeFileSync, mkdirSync } from 'fs'; mkdirSync('./public', { recursive: true }); function crc32(buf) { const table = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1); table[n] = c; } let crc = 0xffffffff; for (const b of buf) crc = (table[(crc ^ b) & 0xff] ^ (crc >>> 8)); return ((crc ^ 0xffffffff) >>> 0); } function chunk(type, data) { const t = Buffer.from(type, 'ascii'); const len = Buffer.allocUnsafe(4); len.writeUInt32BE(data.length, 0); const crcInput = Buffer.concat([t, data]); const crcBuf = Buffer.allocUnsafe(4); crcBuf.writeUInt32BE(crc32(crcInput), 0); return Buffer.concat([len, t, data, crcBuf]); } function deflateStore(raw) { // zlib header (deflate, no compression) const header = Buffer.from([0x78, 0x01]); const blocks = []; const SIZE = 32768; for (let i = 0; i < raw.length; i += SIZE) { const slice = raw.slice(i, i + SIZE); const last = (i + SIZE >= raw.length) ? 1 : 0; const h = Buffer.allocUnsafe(5); h[0] = last; h.writeUInt16LE(slice.length, 1); h.writeUInt16LE((~slice.length) & 0xffff, 3); blocks.push(h, slice); } // Adler-32 let s1 = 1, s2 = 0; for (const b of raw) { s1 = (s1 + b) % 65521; s2 = (s2 + s1) % 65521; } const adler = Buffer.allocUnsafe(4); adler.writeUInt32BE(((s2 << 16) | s1) >>> 0, 0); return Buffer.concat([header, ...blocks, adler]); } function makePNG(size) { const cx = size / 2, cy = size / 2; const outerR = size * 0.42, innerR = size * 0.30; // IHDR const ihdr = Buffer.allocUnsafe(13); ihdr.writeUInt32BE(size, 0); ihdr.writeUInt32BE(size, 4); ihdr[8] = 8; // bit depth ihdr[9] = 2; // RGB ihdr[10] = ihdr[11] = ihdr[12] = 0; // Raw pixel data (filter byte 0 per row) const rows = []; for (let y = 0; y < size; y++) { const row = Buffer.allocUnsafe(1 + size * 3); row[0] = 0; // filter none for (let x = 0; x < size; x++) { const dx = x - cx, dy = y - cy; const d = Math.sqrt(dx * dx + dy * dy); let r, g, b; if (d < innerR) { r = 0x4e; g = 0xcd; b = 0xc4; // teal } else if (d < outerR) { r = 0x1e; g = 0x6a; b = 0x65; // dark teal ring } else { r = 0x0d; g = 0x0d; b = 0x0f; // background } row[1 + x * 3] = r; row[2 + x * 3] = g; row[3 + x * 3] = b; } rows.push(row); } const raw = Buffer.concat(rows); const idat = deflateStore(raw); const sig = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]); return Buffer.concat([ sig, chunk('IHDR', ihdr), chunk('IDAT', idat), chunk('IEND', Buffer.alloc(0)), ]); } writeFileSync('./public/icon-192.png', makePNG(192)); writeFileSync('./public/icon-512.png', makePNG(512)); console.log('✅ Icons generiert: icon-192.png + icon-512.png');