import { downloadBlob } from './exportImport.js' export { downloadBlob } /** * Build a rocket design JSON Blob for download. * Schema version 1: inputs section is re-importable; results is reference-only. */ export function exportRocketJSON({ outerRadius, tankConfig, propDensities, payload, structure, engineData, geometry, noseConeShape }) { const payload_ = { version: 1, type: 'rocket_design', exportedAt: new Date().toISOString(), inputs: { outerRadius, tankConfig, propDensities, payload, structure, noseConeShape, }, engineData: engineData ?? null, results: geometry ?? null, } return new Blob([JSON.stringify(payload_, null, 2)], { type: 'application/json' }) } /** * Parse an imported rocket design JSON string and return the inputs section. * Throws a descriptive Error if the file is invalid. */ export function parseRocketImport(jsonString) { let data try { data = JSON.parse(jsonString) } catch { throw new Error('File is not valid JSON.') } if (data.type !== 'rocket_design') { throw new Error('This file is not a rocket design export.') } if (data.version !== 1) { throw new Error(`Unsupported export version: ${data.version}`) } const { outerRadius, tankConfig, propDensities, payload, structure, noseConeShape } = data.inputs ?? {} return { outerRadius: outerRadius ?? null, tankConfig: tankConfig ?? null, propDensities: propDensities ?? null, payload: payload ?? null, structure: structure ?? null, noseConeShape: noseConeShape ?? null, engineData: data.engineData ?? null, } }