import path from 'node:path' import { fileURLToPath } from 'node:url' import sharp from 'sharp' const scriptDirectory = path.dirname(fileURLToPath(import.meta.url)) const projectRoot = path.resolve(scriptDirectory, '..', '..') const sourcePath = path.join(projectRoot, 'static', 'assets', 'modules', 'genealogy', 'opaque', 'g01-empty-panel.png') const outputPath = path.join(projectRoot, 'static', 'assets', 'modules', 'genealogy', 'transparent', 'g01-empty-panel-frame.png') const borderBand = 110 const { data, info } = await sharp(sourcePath) .ensureAlpha() .raw() .toBuffer({ resolveWithObject: true }) for (let y = 0; y < info.height; y += 1) { for (let x = 0; x < info.width; x += 1) { const offset = (y * info.width + x) * info.channels const red = data[offset] const green = data[offset + 1] const blue = data[offset + 2] const alpha = data[offset + 3] const distanceToEdge = Math.min(x, y, info.width - 1 - x, info.height - 1 - y) const isWarmGold = red > green && green > blue && red - green >= 15 && green - blue >= 12 && red - blue >= 35 && red < 245 && blue < 180 if (distanceToEdge >= borderBand || !isWarmGold) { data[offset + 3] = 0 continue } const edgeAlpha = Math.max(0, Math.min(255, (red - blue - 25) * 6)) data[offset + 3] = Math.min(alpha, edgeAlpha) } } await sharp(data, { raw: { width: info.width, height: info.height, channels: info.channels } }).png().toFile(outputPath) process.stdout.write(`BUILT ${path.relative(projectRoot, outputPath)}\n`)