0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 05:10:13 -05:00

avoid error when unsupported nodes, fills or other kind of elements. Improve error messages (#49)

This commit is contained in:
Jordi Sala Morales 2024-04-19 09:48:19 +02:00 committed by GitHub
parent 08473b5124
commit f469fc1f37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 14 deletions

View file

@ -1,5 +1,6 @@
import { transformSceneNode } from '@plugin/transformers';
import { PenpotNode } from '@ui/lib/types/penpotNode';
import { Children } from '@ui/lib/types/utils/children';
export const transformChildren = async (
@ -8,6 +9,8 @@ export const transformChildren = async (
baseY: number = 0
): Promise<Children> => {
return {
children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY)))
children: (
await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY)))
).filter((child): child is PenpotNode => !!child)
};
};

View file

@ -16,7 +16,7 @@ export const transformSceneNode = async (
node: SceneNode,
baseX: number = 0,
baseY: number = 0
): Promise<PenpotNode> => {
): Promise<PenpotNode | undefined> => {
// @TODO: when penpot 2.0, manage image as fills for the basic types
if (
'fills' in node &&
@ -49,5 +49,5 @@ export const transformSceneNode = async (
return transformPathNode(node, baseX, baseY);
}
throw new Error(`Unsupported node type: ${node.type}`);
console.error(`Unsupported node type: ${node.type}`);
};

View file

@ -11,7 +11,7 @@ export const translateFill = (fill: Paint, width: number, height: number): Fill
return translateGradientLinearFill(fill, width, height);
}
console.error('Color type ' + fill.type + ' not supported yet');
console.error(`Unsupported fill type: ${fill.type}`);
};
export const translateFills = (

View file

@ -1,6 +1,6 @@
import { Gradient, LINEAR_TYPE, RADIAL_TYPE } from '@ui/lib/types/utils/gradient';
export const createGradientFill = ({ type, ...rest }: Gradient): Gradient => {
export const createGradientFill = ({ type, ...rest }: Gradient): Gradient | undefined => {
switch (type) {
case 'linear':
return {
@ -14,5 +14,5 @@ export const createGradientFill = ({ type, ...rest }: Gradient): Gradient => {
};
}
throw new Error(`Unsupported gradient type: ${String(type)}`);
console.error(`Unsupported gradient type: ${String(type)}`);
};

View file

@ -9,14 +9,20 @@ import {
} from '@ui/lib/types/path/PathContent';
export const translatePathContent = (content: PathContent): PathContent =>
content.map(({ command, ...rest }) => {
content
.map(({ command: stringCommand, ...rest }) => {
const command = translatePathCommand(stringCommand);
if (!command) return null;
return {
command: translatePathCommand(command),
command,
...rest
} as Segment;
});
})
.filter((command): command is Segment => !!command);
const translatePathCommand = (command: Command): Command => {
const translatePathCommand = (command: Command): Command | undefined => {
switch (command) {
case 'line-to':
return VECTOR_LINE_TO;
@ -28,5 +34,5 @@ const translatePathCommand = (command: Command): Command => {
return VECTOR_CURVE_TO;
}
throw new Error('Unknown path command');
console.error(`Unsupported svg command type: ${String(command)}`);
};