diff --git a/ea-scripts/GPT-Draw-a-UI.md b/ea-scripts/GPT-Draw-a-UI.md index 0cf5306..d3ed56a 100644 --- a/ea-scripts/GPT-Draw-a-UI.md +++ b/ea-scripts/GPT-Draw-a-UI.md @@ -105,41 +105,41 @@ const blobToBase64 = async (blob) => { } const getRequestObjFromSelectedElements = async (view) => { - await view.forceSave(true); - const viewElements = ea.getViewSelectedElements(); - if(viewElements.length === 0) { - new Notice ("Aborting because there is nothing selected.",4000); - return; - } - const bb = ea.getBoundingBox(viewElements); - const size = (bb.width*bb.height); - const minRatio = Math.sqrt(360000/size); - const maxRatio = Math.sqrt(size/16000000); - const scale = minRatio > 1 - ? minRatio - : ( - maxRatio > 1 - ? 1/maxRatio - : 1 - ); - - const loader = ea.getEmbeddedFilesLoader(false); - const exportSettings = { - withBackground: true, - withTheme: true, - }; - - const img = - await ea.createPNG( - view.file.path, - scale, - exportSettings, - loader, - "light", - ); - const dataURL = `data:image/png;base64,${await blobToBase64(img)}`; - return { json: async () => ({ image: dataURL }) } + await view.forceSave(true); + const viewElements = ea.getViewSelectedElements(); + if(viewElements.length === 0) { + new Notice ("Aborting because there is nothing selected.",4000); + return; } + const bb = ea.getBoundingBox(viewElements); + const size = (bb.width*bb.height); + const minRatio = Math.sqrt(360000/size); + const maxRatio = Math.sqrt(size/16000000); + const scale = minRatio > 1 + ? minRatio + : ( + maxRatio > 1 + ? 1/maxRatio + : 1 + ); + + const loader = ea.getEmbeddedFilesLoader(false); + const exportSettings = { + withBackground: true, + withTheme: true, + }; + + const img = + await ea.createPNG( + view.file.path, + scale, + exportSettings, + loader, + "light", + ); + const dataURL = `data:image/png;base64,${await blobToBase64(img)}`; + return { json: async () => ({ image: dataURL }) } +} const extractHTMLFromString = (result) => { if(!result) return null;