0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

Ensure translation of symbols is consistent when using components (#134)

This commit is contained in:
Jordi Sala Morales 2024-06-03 17:44:03 +02:00 committed by GitHub
parent f726dc9cec
commit fd14e544b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 21 deletions

View file

@ -21,6 +21,8 @@ import {
export const symbolBlendMode = (blendMode?: BlendMode): BlendMode | undefined => {
if (!blendMode) return;
if (typeof blendMode !== 'string') return blendMode;
switch (blendMode) {
case 'normal':
return BLEND_MODE_NORMAL;
@ -54,7 +56,5 @@ export const symbolBlendMode = (blendMode?: BlendMode): BlendMode | undefined =>
return BLEND_MODE_COLOR;
case 'luminosity':
return BLEND_MODE_LUMINOSITY;
default:
return BLEND_MODE_NORMAL;
}
};

View file

@ -7,6 +7,8 @@ import {
} from '@ui/lib/types/shapes/boolShape';
export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations => {
if (typeof booleanOperation !== 'string') return booleanOperation;
switch (booleanOperation) {
case 'union':
return BOOL_UNION;
@ -17,6 +19,4 @@ export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations
case 'intersection':
return BOOL_INTERSECTION;
}
throw new Error(`Unsupported boolean operation: ${String(booleanOperation)}`);
};

View file

@ -20,7 +20,11 @@ export const symbolFills = (fills?: Fill[]): Fill[] | undefined => {
});
};
const symbolFillGradient = ({ type, ...rest }: Gradient): Gradient | undefined => {
const symbolFillGradient = (fillGradient: Gradient): Gradient => {
if (typeof fillGradient.type !== 'string') return fillGradient;
const { type, ...rest } = fillGradient;
switch (type) {
case 'linear':
return {
@ -33,11 +37,13 @@ const symbolFillGradient = ({ type, ...rest }: Gradient): Gradient | undefined =
...rest
};
}
console.error(`Unsupported gradient type: ${String(type)}`);
};
const symbolFillImage = ({ imageHash, ...rest }: ImageColor): ImageColor | undefined => {
const symbolFillImage = (fillImage: ImageColor): ImageColor | undefined => {
if (fillImage.dataUri) return fillImage;
const { imageHash, ...rest } = fillImage;
if (!imageHash) return;
const imageColor = imagesLibrary.get(imageHash);

View file

@ -9,20 +9,18 @@ import {
} from '@ui/lib/types/shapes/pathShape';
export const symbolPathContent = (content: PathContent): PathContent =>
content
.map(({ command: stringCommand, ...rest }) => {
const command = symbolPathCommand(stringCommand);
content.map(({ command: stringCommand, ...rest }) => {
const command = symbolPathCommand(stringCommand);
if (!command) return;
return {
command,
...rest
} as Segment;
});
return {
command,
...rest
} as Segment;
})
.filter((command): command is Segment => !!command);
const symbolPathCommand = (command: Command): Command => {
if (typeof command !== 'string') return command;
const symbolPathCommand = (command: Command): Command | undefined => {
switch (command) {
case 'line-to':
return VECTOR_LINE_TO;
@ -33,6 +31,4 @@ const symbolPathCommand = (command: Command): Command | undefined => {
case 'curve-to':
return VECTOR_CURVE_TO;
}
console.error(`Unsupported svg command type: ${String(command)}`);
};