From 8be7bf43a259fedc6cedbde3851547d63929185d Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Fri, 20 Feb 2026 23:00:10 -0700 Subject: [PATCH] saveImage host function --- src/runtime-js.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/runtime-js.ts b/src/runtime-js.ts index e4faf9c..1a77e67 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -101,6 +101,22 @@ export const _rt = { const printed = prettyPrint(ast); return printed; }, + saveImage: () => { + const saved: Record = {}; + 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) => { if (maybeValue === undefined) { store[name] = pathOrValue;