2024-05-29 10:33:29 -05:00
|
|
|
import { componentsLibrary } from '@plugin/ComponentLibrary';
|
|
|
|
|
2024-05-29 05:52:21 -05:00
|
|
|
import { createFile } from '@ui/lib/penpot';
|
|
|
|
import { createComponentLibrary, createPage } from '@ui/parser/creators';
|
2024-06-05 05:36:49 -05:00
|
|
|
import { uiComponents, uiImages } from '@ui/parser/libraries';
|
2024-05-29 10:33:29 -05:00
|
|
|
import { PenpotDocument } from '@ui/types';
|
2024-05-29 05:52:21 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
import { idLibrary, parseImage } from '.';
|
2024-05-30 10:54:37 -05:00
|
|
|
|
2024-06-05 05:36:49 -05:00
|
|
|
export const parse = async ({ name, children = [], components, images }: PenpotDocument) => {
|
2024-05-29 10:33:29 -05:00
|
|
|
componentsLibrary.init(components);
|
2024-06-05 05:36:49 -05:00
|
|
|
|
|
|
|
for (const [key, bytes] of Object.entries(images)) {
|
|
|
|
if (!bytes) continue;
|
|
|
|
|
|
|
|
uiImages.register(key, await parseImage(bytes));
|
|
|
|
}
|
2024-06-03 10:29:33 -05:00
|
|
|
|
2024-05-29 10:33:29 -05:00
|
|
|
uiComponents.init();
|
2024-05-30 10:54:37 -05:00
|
|
|
idLibrary.init();
|
2024-05-29 05:52:21 -05:00
|
|
|
|
|
|
|
const file = createFile(name);
|
|
|
|
|
|
|
|
for (const page of children) {
|
|
|
|
createPage(file, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
createComponentLibrary(file);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
};
|