@@ -16,7 +16,7 @@ import {
1616 PROJECT_FORMAT ,
1717 TOOL_IDS
1818} from "./constants.js" ;
19- import { readFileText } from "../../../src/engine/persistence/index.js" ;
19+ import { downloadBlobFile , readFileText } from "../../../src/engine/persistence/index.js" ;
2020import { colorToPickerValue , dedupeColors , isTransparent , normalizeColor , rgbaToHex } from "./colorUtils.js" ;
2121import {
2222 cloneFrame ,
@@ -274,17 +274,6 @@ function resolvePaletteFromAssetRegistry(state) {
274274 return true ;
275275}
276276
277- function downloadBlob ( blob , filename ) {
278- const link = document . createElement ( "a" ) ;
279- const url = URL . createObjectURL ( blob ) ;
280- link . href = url ;
281- link . download = filename ;
282- document . body . appendChild ( link ) ;
283- link . click ( ) ;
284- document . body . removeChild ( link ) ;
285- URL . revokeObjectURL ( url ) ;
286- }
287-
288277function summarizeGraphFindings ( findings ) {
289278 return Array . isArray ( findings ) && findings . length > 0
290279 ? ` Graph findings: ${ findings . length } .`
@@ -1890,7 +1879,7 @@ async function exportCurrentFramePng(state) {
18901879 const frameCanvas = createImageFromFrame ( frame , state . project . width , state . project . height ) ;
18911880 const blob = await canvasToBlob ( frameCanvas ) ;
18921881 const filename = `sprite-frame-${ state . project . currentFrameIndex + 1 } -${ state . project . width } x${ state . project . height } .png` ;
1893- downloadBlob ( blob , filename ) ;
1882+ downloadBlobFile ( blob , filename , { appendToBody : true } ) ;
18941883 setStatus ( state , `Exported ${ filename } (${ state . project . width } x${ state . project . height } ).` ) ;
18951884}
18961885
@@ -1901,7 +1890,7 @@ async function exportSpriteSheetPng(state) {
19011890 const sheetCanvas = createSpriteSheetCanvas ( state . project ) ;
19021891 const blob = await canvasToBlob ( sheetCanvas ) ;
19031892 const filename = `sprite-sheet-${ state . project . frames . length } f-${ state . project . width } x${ state . project . height } .png` ;
1904- downloadBlob ( blob , filename ) ;
1893+ downloadBlobFile ( blob , filename , { appendToBody : true } ) ;
19051894 setStatus ( state , `Exported ${ filename } (${ sheetCanvas . width } x${ sheetCanvas . height } ).` ) ;
19061895}
19071896
@@ -1935,8 +1924,8 @@ async function packageSpriteProject(state) {
19351924 return false ;
19361925 }
19371926 const baseName = `${ state . assetRegistry . projectId || "sprite-project" } .package` ;
1938- downloadBlob ( new Blob ( [ `${ JSON . stringify ( packageResult . manifest , null , 2 ) } \n` ] , { type : "application/json" } ) , `${ baseName } .json` ) ;
1939- downloadBlob ( new Blob ( [ `${ packageResult . reportText } \n` ] , { type : "text/plain" } ) , `${ baseName } .report.txt` ) ;
1927+ downloadBlobFile ( new Blob ( [ `${ JSON . stringify ( packageResult . manifest , null , 2 ) } \n` ] , { type : "application/json" } ) , `${ baseName } .json` , { appendToBody : true } ) ;
1928+ downloadBlobFile ( new Blob ( [ `${ packageResult . reportText } \n` ] , { type : "text/plain" } ) , `${ baseName } .report.txt` , { appendToBody : true } ) ;
19401929 setStatus ( state , `${ summarizeProjectPackaging ( packageResult ) } Manifest and report exported.` ) ;
19411930 return true ;
19421931}
@@ -1951,7 +1940,7 @@ async function saveAssetRegistryJson(state) {
19511940 const payload = createRegistryDownloadPayload ( state . assetRegistry ) ;
19521941 const blob = new Blob ( [ payload ] , { type : "application/json" } ) ;
19531942 const fileName = "project.assets.json" ;
1954- downloadBlob ( blob , fileName ) ;
1943+ downloadBlobFile ( blob , fileName , { appendToBody : true } ) ;
19551944 setStatus (
19561945 state ,
19571946 `Saved ${ fileName } with ${ state . assetRegistry . sprites . length } sprite entries.${ summarizeGraphFindings ( findings ) } Validation: ${ summarizeAssetValidation ( validation ) } .`
@@ -1993,7 +1982,7 @@ async function saveProjectJson(state) {
19931982 } ;
19941983 const json = `${ JSON . stringify ( payload , null , 2 ) } \n` ;
19951984 const blob = new Blob ( [ json ] , { type : "application/json" } ) ;
1996- downloadBlob ( blob , fileName ) ;
1985+ downloadBlobFile ( blob , fileName , { appendToBody : true } ) ;
19971986 setStatus (
19981987 state ,
19991988 `Saved ${ fileName } (frame ${ state . project . currentFrameIndex + 1 } active, asset refs: palette=${ state . project . assetRefs . paletteId || "none" } , sprite=${ state . project . assetRefs . spriteId || "none" } ).${ summarizeGraphFindings ( findings ) } Validation: ${ summarizeAssetValidation ( validation ) } .`
0 commit comments