Skip to content

Commit

Permalink
Ensure translation of symbols is consistent when using components
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jun 3, 2024
1 parent f726dc9 commit 2fc13a4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ui-src/parser/creators/symbols/symbolBlendMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
4 changes: 2 additions & 2 deletions ui-src/parser/creators/symbols/symbolBoolType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,4 @@ export const symbolBoolType = (booleanOperation: BoolOperations): BoolOperations
case 'intersection':
return BOOL_INTERSECTION;
}

throw new Error(`Unsupported boolean operation: ${String(booleanOperation)}`);
};
14 changes: 10 additions & 4 deletions ui-src/parser/creators/symbols/symbolFills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
22 changes: 9 additions & 13 deletions ui-src/parser/creators/symbols/symbolPathContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)}`);
};

0 comments on commit 2fc13a4

Please sign in to comment.