saveImage host function

master
Dustin Swan 7 days ago
parent 00e213748d
commit 8be7bf43a2
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -101,6 +101,22 @@ export const _rt = {
const printed = prettyPrint(ast); const printed = prettyPrint(ast);
return printed; return printed;
}, },
saveImage: () => {
const saved: Record<string, string> = {};
for (const [name, ast] of definitions) {
const source = prettyPrint({ kind: 'definition', name, body: ast });
saved[name] = source;
}
const content = Object.values(saved).join('\n\n');
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `cg-image-${new Date().toISOString().slice(0, 19).replace(/[T:]/g, '-')}.cg`;
a.click();
URL.revokeObjectURL(url);
return { _tag: 'Ok' };
},
rebind: (name: string, pathOrValue: any, maybeValue?: any) => { rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
if (maybeValue === undefined) { if (maybeValue === undefined) {
store[name] = pathOrValue; store[name] = pathOrValue;

Loading…
Cancel
Save