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/transformers/transformDocumentNode.ts
Jordi Sala Morales f726dc9cec
Add image library to optimize performance (#133)
* Add image library to optimize performance

* fix and improve

* Add changelog and improve naming

* refactor

* improve

* fix todos
2024-06-03 17:29:33 +02:00

34 lines
791 B
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { imagesLibrary } from '@plugin/ImageLibrary';
import { PenpotDocument } from '@ui/types';
import { transformPageNode } from '.';
export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => {
const children = [];
let currentPage = 0;
figma.ui.postMessage({
type: 'PROGRESS_TOTAL_PAGES',
data: node.children.length
});
for (const page of node.children) {
figma.ui.postMessage({
type: 'PROGRESS_PROCESSED_PAGES',
data: currentPage++
});
await page.loadAsync();
children.push(await transformPageNode(page));
}
return {
name: node.name,
children,
components: componentsLibrary.all(),
images: imagesLibrary.all()
};
};