0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 13:20:37 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/createComponentLibrary.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

35 lines
1 KiB
TypeScript

import { componentsLibrary } from '@plugin/ComponentLibrary';
import { PenpotFile } from '@ui/lib/types/penpotFile';
import { symbolBlendMode, symbolFills } from '@ui/parser/creators/symbols';
import { uiComponents } from '@ui/parser/libraries';
import { createItems } from '.';
export const createComponentLibrary = (file: PenpotFile) => {
uiComponents.all().forEach(uiComponent => {
const component = componentsLibrary.get(uiComponent.componentFigmaId);
if (!component) {
return;
}
const { children = [], fills, blendMode, ...rest } = component;
file.startComponent({
...rest,
fills: symbolFills(fills),
blendMode: symbolBlendMode(blendMode),
id: uiComponent.componentId,
componentId: uiComponent.componentId,
mainInstancePage: uiComponent.mainInstancePage,
mainInstanceId: uiComponent.mainInstanceId,
componentRoot: true,
mainInstance: true,
componentFile: file.getId()
});
createItems(file, children);
file.finishComponent();
});
};