Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Jun 20, 2024
1 parent 8c4d8db commit 415948a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
14 changes: 4 additions & 10 deletions plugin-src/StyleLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { Fill } from '@ui/lib/types/utils/fill';

class StyleLibrary {
private styles: Map<string, Fill[]> = new Map();
private styles: Map<string, PaintStyle | undefined> = new Map();

public register(id: string, styles: Fill[]) {
public register(id: string, styles?: PaintStyle | undefined) {
this.styles.set(id, styles);
}

public get(id: string): Fill[] | undefined {
public get(id: string): PaintStyle | undefined {
return this.styles.get(id);
}

public has(id: string): boolean {
return this.styles.has(id);
}

public all(): Record<string, Fill[]> {
public all(): Record<string, PaintStyle | undefined> {
return Object.fromEntries(this.styles.entries());
}

public init(styles: Record<string, Fill[]>): void {
this.styles = new Map(Object.entries(styles));
}
}

export const styleLibrary = new StyleLibrary();
5 changes: 5 additions & 0 deletions plugin-src/transformers/transformDocumentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const processPages = async (node: DocumentNode): Promise<PenpotPage[]> => {
};

export const transformDocumentNode = async (node: DocumentNode): Promise<PenpotDocument> => {
const localPaintStyles = await figma.getLocalPaintStylesAsync();
localPaintStyles.forEach(style => {
styleLibrary.register(style.id, style);
});

const children = await processPages(node);

if (remoteComponentLibrary.remaining() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/fills/translateFills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const translateFillStyleId = (
if (fillStyleId === figma.mixed || fillStyleId === undefined) return;

if (!styleLibrary.has(fillStyleId)) {
styleLibrary.register(fillStyleId, []);
styleLibrary.register(fillStyleId);
}

return fillStyleId;
Expand Down
3 changes: 2 additions & 1 deletion plugin-src/translators/fills/translatePaintStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const translatePaintStyles = (figmaStyle: PaintStyle): FillStyle => {
};

let index = 0;
const path = figmaStyle.paints.length > 1 ? figmaStyle.name : '';
const path =
(figmaStyle.remote ? 'Remote / ' : '') + (figmaStyle.paints.length > 1 ? figmaStyle.name : '');

for (const fill of figmaStyle.paints) {
const penpotFill = translateFill(fill);
Expand Down
4 changes: 0 additions & 4 deletions ui-src/parser/libraries/UiColorLibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class UiColorLibraries {
public all(): FillStyle[] {
return Array.from(this.libraries.values());
}

public init(libraries: Record<string, FillStyle>) {
this.libraries = new Map(Object.entries(libraries));
}
}

export const uiColorLibraries = new UiColorLibraries();

0 comments on commit 415948a

Please sign in to comment.