Closed ChrisChan888 closed 2 years ago
A better place to ask this is probably on the forum https://forum.figma.com/ or Discord https://discord.com/invite/figma
You can't do that within the plugin backend, it needs to be done on the UI side (iframe).
We can use figma.ui.postMessage
and send data to ui.html, then execute downloadObjectAsJson
function.
Document is undefined in code.ts. I can't createElement('a') for download some styles data I get from figma API. How to access "document" in code.ts? So user can download the json generate by the plugin? function downloadObjectAsJson(exportObj, exportName){ var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); var downloadAnchorNode = document.createElement('a'); downloadAnchorNode.setAttribute("href", dataStr); downloadAnchorNode.setAttribute("download", exportName + ".json"); document.body.appendChild(downloadAnchorNode); // required for firefox downloadAnchorNode.click(); downloadAnchorNode.remove(); }