import fs from 'node:fs'
import path from 'node:path'
import { execFileSync } from 'node:child_process'
const root = path.resolve(import.meta.dirname, '..')
const linkedAssets = process.env.FIGMA_SVG_LINKED === '1'
const asset = (name) => {
if (linkedAssets) return `http://127.0.0.1:5174/client-assets/${name}`
const file = path.join(root, 'public', 'client-assets', name)
const cacheDir = '/tmp/wanderq-figma-svg-assets'
fs.mkdirSync(cacheDir, { recursive: true })
const output = path.join(cacheDir, `${path.parse(name).name}.jpg`)
execFileSync('/usr/bin/sips', ['-Z', '360', '-s', 'format', 'jpeg', '-s', 'formatOptions', '40', file, '--out', output], { stdio: 'ignore' })
return `data:image/jpeg;base64,${fs.readFileSync(output).toString('base64')}`
}
const images = {
village: asset('home-hero-mountain-village.webp'),
scale: asset('home-hero-waterfall-scale.webp'),
valley: asset('village-valley-fields.jpg'),
adventure: asset('waterfall-abseil-spray.jpg'),
culture: asset('culture-batik-making.jpg'),
landscape: asset('waterfall-huangguoshu-main.jpg'),
}
const esc = (s) => s.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
const text = (x, y, value, cls, anchor = 'start') =>
`${esc(value)}`
const lines = (x, y, values, cls, gap) =>
values.map((v, i) => text(x, y + i * gap, v, cls)).join('')
const W = 1440
const H = 2328
const svg = `
`
const output = path.join(root, linkedAssets ? 'figma-home-structure-linked.svg' : 'figma-home-structure.svg')
fs.writeFileSync(output, svg)
console.log(output)