0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/processors/processImages.ts

43 lines
891 B
TypeScript
Raw Normal View History

2024-06-26 01:11:57 -05:00
import { toArray } from '@common/map';
import { sleep } from '@common/sleep';
import { images as imagesLibrary } from '@plugin/libraries';
export const processImages = async (): Promise<Record<string, Uint8Array>> => {
2024-06-26 01:11:57 -05:00
const imageToDownload = toArray(imagesLibrary);
const images: Record<string, Uint8Array> = {};
if (imageToDownload.length === 0) return images;
let currentImage = 1;
figma.ui.postMessage({
type: 'PROGRESS_TOTAL_ITEMS',
data: imageToDownload.length
});
figma.ui.postMessage({
type: 'PROGRESS_STEP',
data: 'images'
});
for (const [key, image] of imageToDownload) {
const bytes = await image?.getBytesAsync();
if (bytes) {
images[key] = bytes;
}
figma.ui.postMessage({
type: 'PROGRESS_PROCESSED_ITEMS',
data: currentImage++
});
await sleep(0);
}
await sleep(20);
return images;
};