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:
parent
08473b5124
commit
f469fc1f37
5 changed files with 23 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { transformSceneNode } from '@plugin/transformers';
|
import { transformSceneNode } from '@plugin/transformers';
|
||||||
|
|
||||||
|
import { PenpotNode } from '@ui/lib/types/penpotNode';
|
||||||
import { Children } from '@ui/lib/types/utils/children';
|
import { Children } from '@ui/lib/types/utils/children';
|
||||||
|
|
||||||
export const transformChildren = async (
|
export const transformChildren = async (
|
||||||
|
@ -8,6 +9,8 @@ export const transformChildren = async (
|
||||||
baseY: number = 0
|
baseY: number = 0
|
||||||
): Promise<Children> => {
|
): Promise<Children> => {
|
||||||
return {
|
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)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const transformSceneNode = async (
|
||||||
node: SceneNode,
|
node: SceneNode,
|
||||||
baseX: number = 0,
|
baseX: number = 0,
|
||||||
baseY: number = 0
|
baseY: number = 0
|
||||||
): Promise<PenpotNode> => {
|
): Promise<PenpotNode | undefined> => {
|
||||||
// @TODO: when penpot 2.0, manage image as fills for the basic types
|
// @TODO: when penpot 2.0, manage image as fills for the basic types
|
||||||
if (
|
if (
|
||||||
'fills' in node &&
|
'fills' in node &&
|
||||||
|
@ -49,5 +49,5 @@ export const transformSceneNode = async (
|
||||||
return transformPathNode(node, baseX, baseY);
|
return transformPathNode(node, baseX, baseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Unsupported node type: ${node.type}`);
|
console.error(`Unsupported node type: ${node.type}`);
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const translateFill = (fill: Paint, width: number, height: number): Fill
|
||||||
return translateGradientLinearFill(fill, width, height);
|
return translateGradientLinearFill(fill, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error('Color type ' + fill.type + ' not supported yet');
|
console.error(`Unsupported fill type: ${fill.type}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const translateFills = (
|
export const translateFills = (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Gradient, LINEAR_TYPE, RADIAL_TYPE } from '@ui/lib/types/utils/gradient';
|
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) {
|
switch (type) {
|
||||||
case 'linear':
|
case 'linear':
|
||||||
return {
|
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)}`);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,14 +9,20 @@ import {
|
||||||
} from '@ui/lib/types/path/PathContent';
|
} from '@ui/lib/types/path/PathContent';
|
||||||
|
|
||||||
export const translatePathContent = (content: PathContent): PathContent =>
|
export const translatePathContent = (content: PathContent): PathContent =>
|
||||||
content.map(({ command, ...rest }) => {
|
content
|
||||||
return {
|
.map(({ command: stringCommand, ...rest }) => {
|
||||||
command: translatePathCommand(command),
|
const command = translatePathCommand(stringCommand);
|
||||||
...rest
|
|
||||||
} as Segment;
|
|
||||||
});
|
|
||||||
|
|
||||||
const translatePathCommand = (command: Command): Command => {
|
if (!command) return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
command,
|
||||||
|
...rest
|
||||||
|
} as Segment;
|
||||||
|
})
|
||||||
|
.filter((command): command is Segment => !!command);
|
||||||
|
|
||||||
|
const translatePathCommand = (command: Command): Command | undefined => {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case 'line-to':
|
case 'line-to':
|
||||||
return VECTOR_LINE_TO;
|
return VECTOR_LINE_TO;
|
||||||
|
@ -28,5 +34,5 @@ const translatePathCommand = (command: Command): Command => {
|
||||||
return VECTOR_CURVE_TO;
|
return VECTOR_CURVE_TO;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Unknown path command');
|
console.error(`Unsupported svg command type: ${String(command)}`);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue