2024-04-16 09:08:39 -05:00
|
|
|
import {
|
|
|
|
Command,
|
|
|
|
PathContent,
|
|
|
|
Segment,
|
|
|
|
VECTOR_CLOSE_PATH,
|
|
|
|
VECTOR_CURVE_TO,
|
|
|
|
VECTOR_LINE_TO,
|
|
|
|
VECTOR_MOVE_TO
|
2024-05-06 01:06:14 -05:00
|
|
|
} from '@ui/lib/types/shapes/pathShape';
|
2024-04-16 09:08:39 -05:00
|
|
|
|
|
|
|
export const translatePathContent = (content: PathContent): PathContent =>
|
2024-04-19 02:48:19 -05:00
|
|
|
content
|
|
|
|
.map(({ command: stringCommand, ...rest }) => {
|
|
|
|
const command = translatePathCommand(stringCommand);
|
2024-04-16 09:08:39 -05:00
|
|
|
|
2024-05-09 09:59:27 -05:00
|
|
|
if (!command) return;
|
2024-04-19 02:48:19 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
command,
|
|
|
|
...rest
|
|
|
|
} as Segment;
|
|
|
|
})
|
|
|
|
.filter((command): command is Segment => !!command);
|
|
|
|
|
|
|
|
const translatePathCommand = (command: Command): Command | undefined => {
|
2024-04-16 09:08:39 -05:00
|
|
|
switch (command) {
|
|
|
|
case 'line-to':
|
|
|
|
return VECTOR_LINE_TO;
|
|
|
|
case 'close-path':
|
|
|
|
return VECTOR_CLOSE_PATH;
|
|
|
|
case 'move-to':
|
|
|
|
return VECTOR_MOVE_TO;
|
|
|
|
case 'curve-to':
|
|
|
|
return VECTOR_CURVE_TO;
|
|
|
|
}
|
|
|
|
|
2024-04-19 02:48:19 -05:00
|
|
|
console.error(`Unsupported svg command type: ${String(command)}`);
|
2024-04-16 09:08:39 -05:00
|
|
|
};
|