0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -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 => { export const symbolBlendMode = (blendMode?: BlendMode): BlendMode | undefined => {
if (!blendMode) return; if (!blendMode) return;
if (typeof blendMode !== 'string') return blendMode;
switch (blendMode) { switch (blendMode) {
case 'normal': case 'normal':
return BLEND_MODE_NORMAL; return BLEND_MODE_NORMAL;
@ -54,7 +56,5 @@ export const symbolBlendMode = (blendMode?: BlendMode): BlendMode | undefined =>
return BLEND_MODE_COLOR; return BLEND_MODE_COLOR;
case 'luminosity': case 'luminosity':
return BLEND_MODE_LUMINOSITY; return BLEND_MODE_LUMINOSITY;
default:
return BLEND_MODE_NORMAL;
} }
}; };

View file

@ -7,6 +7,8 @@ import {
} from '@ui/lib/types/shapes/boolShape'; } from '@ui/lib/types/shapes/boolShape';
export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations => { export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations => {
if (typeof booleanOperation !== 'string') return booleanOperation;
switch (booleanOperation) { switch (booleanOperation) {
case 'union': case 'union':
return BOOL_UNION; return BOOL_UNION;
@ -17,6 +19,4 @@ export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations
case 'intersection': case 'intersection':
return BOOL_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) { switch (type) {
case 'linear': case 'linear':
return { return {
@ -33,11 +37,13 @@ const symbolFillGradient = ({ type, ...rest }: Gradient): Gradient | undefined =
...rest ...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; if (!imageHash) return;
const imageColor = imagesLibrary.get(imageHash); const imageColor = imagesLibrary.get(imageHash);

View file

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