INNER CODE UNIT · TypeScript
emitTemplate
f5/unovis · packages/mcp/src/codegen/index.ts:298
function emitTemplate (spec: ChartSpec, emit: Emit, framework: 'svelte' | 'vue'): GeneratedFile {
const components = spec.components.map(c => ({ type: c.type, props: componentProps(c, emit) }))
const xAxis = axisProps(spec, 'x', emit)
const yAxis = axisProps(spec, 'y', emit)
const tag = (name: string): string => `Vis${name}`
const bind = (p: Prop): string => {
if (p.expr.startsWith("'")) return ` ${p.name}=${p.expr.replace(/'/g, '"')}`
return framework === 'svelte' ? ` ${p.name}={${p.expr}}` : ` :${p.name}="${p.expr.replace(/"/g, "'")}"`
}
const dataBind = framework === 'svelte' ? ' {data}' : ' :data="data"'
const heightBind = framework === 'svelte' ? `height={${spec.height}}` : `:height="${spec.height}"`
const children = [
...components.map(c => `<${tag(c.type)}${dataBind}${c.props.map(bind).join('')} />`),
...(xAxis ? [`<${tag('Axis')}${xAxis.map(bind).join('')} />`] : []),
...(yAxis ? [`<${tag('Axis')}${yAxis.map(bind).join('')} />`] : []),
]