/**
* 生成 81×81 TabBar PNG 图标(透明底,适合微信小程序)
* 用法:node scripts/gen-tabbar-icons.mjs
*/
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import sharp from 'sharp'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const outDir = path.resolve(__dirname, '../src/static/tabbar')
const GRAY = '#666666'
const PRIMARY = '#00BCD4'
function svgIcon(type, color) {
if (type === 'meal') {
return ``
}
if (type === 'order') {
return ``
}
return ``
}
async function writeIcon(name, type, color) {
const svg = svgIcon(type, color)
const buf = await sharp(Buffer.from(svg)).png().toBuffer()
fs.writeFileSync(path.join(outDir, name), buf)
}
async function main() {
fs.mkdirSync(outDir, { recursive: true })
const items = [
['meal.png', 'meal', GRAY],
['meal-active.png', 'meal', PRIMARY],
['order.png', 'order', GRAY],
['order-active.png', 'order', PRIMARY],
['profile.png', 'profile', GRAY],
['profile-active.png', 'profile', PRIMARY]
]
for (const [file, type, color] of items) {
await writeIcon(file, type, color)
console.log('wrote', file)
}
}
main().catch(err => {
console.error(err)
process.exit(1)
})