mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 13:43:03 -05:00
parent
8d185c98fd
commit
53672d8b43
6 changed files with 50 additions and 5 deletions
5
.changeset/wise-moose-buy.md
Normal file
5
.changeset/wise-moose-buy.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"penpot-exporter": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix local styles categorization system
|
|
@ -1,2 +1,4 @@
|
||||||
export * from './translatePaintStyle';
|
export * from './translatePaintStyle';
|
||||||
|
export * from './translateStyleName';
|
||||||
|
export * from './translateStylePath';
|
||||||
export * from './translateTextStyle';
|
export * from './translateTextStyle';
|
||||||
|
|
|
@ -2,6 +2,8 @@ import { translateFill } from '@plugin/translators/fills/translateFills';
|
||||||
|
|
||||||
import { FillStyle } from '@ui/lib/types/utils/fill';
|
import { FillStyle } from '@ui/lib/types/utils/fill';
|
||||||
|
|
||||||
|
import { translateStyleName, translateStylePath } from '.';
|
||||||
|
|
||||||
export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
|
export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
|
||||||
const fillStyle: FillStyle = {
|
const fillStyle: FillStyle = {
|
||||||
name: figmaStyle.name,
|
name: figmaStyle.name,
|
||||||
|
@ -10,12 +12,11 @@ export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const colorName = (figmaStyle: PaintStyle, index: number): string => {
|
const colorName = (figmaStyle: PaintStyle, index: number): string => {
|
||||||
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : figmaStyle.name;
|
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : translateStyleName(figmaStyle);
|
||||||
};
|
};
|
||||||
|
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const path =
|
const path = translatePaintStylePath(figmaStyle);
|
||||||
(figmaStyle.remote ? 'Remote / ' : '') + (figmaStyle.paints.length > 1 ? figmaStyle.name : '');
|
|
||||||
|
|
||||||
for (const fill of figmaStyle.paints) {
|
for (const fill of figmaStyle.paints) {
|
||||||
const penpotFill = translateFill(fill);
|
const penpotFill = translateFill(fill);
|
||||||
|
@ -32,3 +33,13 @@ export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
|
||||||
|
|
||||||
return fillStyle;
|
return fillStyle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const translatePaintStylePath = (figmaStyle: PaintStyle) => {
|
||||||
|
const path = translateStylePath(figmaStyle);
|
||||||
|
|
||||||
|
if (figmaStyle.paints.length <= 1) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path + (path !== '' ? ' / ' : '') + translateStyleName(figmaStyle);
|
||||||
|
};
|
||||||
|
|
9
plugin-src/translators/styles/translateStyleName.ts
Normal file
9
plugin-src/translators/styles/translateStyleName.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export const translateStyleName = (figmaStyle: BaseStyle): string => {
|
||||||
|
const splitName = figmaStyle.name.split('/');
|
||||||
|
|
||||||
|
if (splitName.length > 0) {
|
||||||
|
return splitName.pop() as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
return figmaStyle.name;
|
||||||
|
};
|
16
plugin-src/translators/styles/translateStylePath.ts
Normal file
16
plugin-src/translators/styles/translateStylePath.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
export const translateStylePath = (figmaStyle: BaseStyleMixin) => {
|
||||||
|
const path = [];
|
||||||
|
|
||||||
|
if (figmaStyle.remote) {
|
||||||
|
path.push('Remote');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (figmaStyle.name.includes('/')) {
|
||||||
|
const pathParts = figmaStyle.name.split('/');
|
||||||
|
pathParts.pop();
|
||||||
|
|
||||||
|
path.push(...pathParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.join(' / ');
|
||||||
|
};
|
|
@ -9,11 +9,13 @@ import {
|
||||||
|
|
||||||
import { TypographyStyle } from '@ui/lib/types/shapes/textShape';
|
import { TypographyStyle } from '@ui/lib/types/shapes/textShape';
|
||||||
|
|
||||||
|
import { translateStyleName, translateStylePath } from '.';
|
||||||
|
|
||||||
export const translateTextStyle = (figmaStyle: TextStyle): TypographyStyle => {
|
export const translateTextStyle = (figmaStyle: TextStyle): TypographyStyle => {
|
||||||
const name = (figmaStyle.remote ? 'Remote / ' : '') + figmaStyle.name;
|
const name = (figmaStyle.remote ? 'Remote / ' : '') + figmaStyle.name;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: figmaStyle.name,
|
name: translateStyleName(figmaStyle),
|
||||||
textStyle: {
|
textStyle: {
|
||||||
...translateFontName(figmaStyle.fontName),
|
...translateFontName(figmaStyle.fontName),
|
||||||
fontFamily: figmaStyle.fontName.family,
|
fontFamily: figmaStyle.fontName.family,
|
||||||
|
@ -25,7 +27,7 @@ export const translateTextStyle = (figmaStyle: TextStyle): TypographyStyle => {
|
||||||
lineHeight: translateLineHeight(figmaStyle)
|
lineHeight: translateLineHeight(figmaStyle)
|
||||||
},
|
},
|
||||||
typography: {
|
typography: {
|
||||||
path: '',
|
path: translateStylePath(figmaStyle),
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue