saveImage host function
This commit is contained in:
parent
00e213748d
commit
8be7bf43a2
1 changed files with 16 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue