0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformDocumentNode.ts
Alex Sánchez be5ff3be8e
Remote components (External design systems) (#140)
* remote components processing

* changeset

* fixes

* fixes

* fixes

* fixes

* fix everything

* revert for now

* fixes

* change delete nodes flag

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-06-06 09:37:35 +02:00

56 lines
1.3 KiB
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { imagesLibrary } from '@plugin/ImageLibrary';
import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
import { translateRemoteChildren } from '@plugin/translators';
import { sleep } from '@plugin/utils';
import { PenpotDocument } from '@ui/types';
import { transformPageNode } from '.';
export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => {
const children = [];
let currentPage = 1;
figma.ui.postMessage({
type: 'PROGRESS_TOTAL_PAGES',
data: node.children.length
});
for (const page of node.children) {
await page.loadAsync();
children.push(await transformPageNode(page));
figma.ui.postMessage({
type: 'PROGRESS_PROCESSED_PAGES',
data: currentPage++
});
await sleep(0);
}
if (remoteComponentLibrary.remaining() > 0) {
children.push({
name: 'External Components',
children: await translateRemoteChildren()
});
}
const images: Record<string, Uint8Array> = {};
for (const [key, image] of Object.entries(imagesLibrary.all())) {
const bytes = await image?.getBytesAsync();
if (!bytes) continue;
images[key] = bytes;
}
return {
name: node.name,
children,
components: componentsLibrary.all(),
images
};
};