Skip to content
Open
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
29 changes: 21 additions & 8 deletions src/services/figma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ type FetchImageFillParams = Omit<FetchImageParams, "fileType"> & {
imageRef: string;
};

type GetImagesParams = {
/**
* Whether text elements are rendered as outlines (vector paths) or as <text> elements in SVGs.
*/
outlineText?: boolean;

/**
* Whether to include id attributes for all SVG elements. Adds the layer name to the id attribute of an svg element.
*/
includeId?: boolean;

/**
* Whether to simplify inside/outside strokes and use stroke attribute if possible instead of <mask>.
*/
simplifyStroke?: boolean;
};

export class FigmaService {
private readonly apiKey: string;
private readonly oauthToken: string;
Expand Down Expand Up @@ -105,11 +122,7 @@ export class FigmaService {
nodes: FetchImageParams[],
localPath: string,
pngScale: number,
svgOptions: {
outlineText: boolean;
includeId: boolean;
simplifyStroke: boolean;
},
{ outlineText = true, includeId = false, simplifyStroke = true }: GetImagesParams = {},
): Promise<string[]> {
const pngIds = nodes.filter(({ fileType }) => fileType === "png").map(({ nodeId }) => nodeId);
const pngFiles =
Expand All @@ -123,9 +136,9 @@ export class FigmaService {
const svgParams = [
`ids=${svgIds.join(",")}`,
"format=svg",
`svg_outline_text=${svgOptions.outlineText}`,
`svg_include_id=${svgOptions.includeId}`,
`svg_simplify_stroke=${svgOptions.simplifyStroke}`,
`svg_outline_text=${outlineText}`,
`svg_include_id=${includeId}`,
`svg_simplify_stroke=${simplifyStroke}`,
].join("&");

const svgFiles =
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,5 @@ export function pixelRound(num: number): number {
if (isNaN(num)) {
throw new TypeError(`Input must be a valid number`);
}
return Number(Number(num).toFixed(2));
return Number(Number(num).toFixed(1));
}