Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure translation of symbols is consistent when using components #134

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}`);
};