Skip to content

Commit

Permalink
Frames & Sections (#38)
Browse files Browse the repository at this point in the history
* Implement Frames and Sections exportation

* add blend modes
  • Loading branch information
jordisala1991 authored Apr 17, 2024
1 parent c9f8a0d commit ebdf3ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
transformBlend,
transformDimensionAndPosition,
transformSceneNode,
transformStrokes
Expand All @@ -8,18 +9,29 @@ import { translateFills } from '@plugin/translators';

import { FrameShape } from '@ui/lib/types/frame/frameShape';

const isSectionNode = (node: FrameNode | SectionNode): node is SectionNode => {
return node.type === 'SECTION';
};

export const transformFrameNode = async (
node: FrameNode,
node: FrameNode | SectionNode,
baseX: number,
baseY: number
): Promise<FrameShape> => {
return {
type: 'frame',
name: node.name,
fills: translateFills(node.fills, node.width, node.height),
...transformStrokes(node),
...(await transformChildren(node, baseX, baseY)),
// Figma API does not expose strokes for sections,
// they plan to add it in the future. Refactor this when available.
// @see: https://forum.figma.com/t/why-are-strokes-not-available-on-section-nodes/41658
...(isSectionNode(node) ? [] : transformStrokes(node)),
...(await transformChildren(node, baseX + node.x, baseY + node.y)),
...transformDimensionAndPosition(node, baseX, baseY),
// Figma API does not expose blend modes for sections,
// they plan to add it in the future. Refactor this when available.
// @see: https://forum.figma.com/t/add-a-blendmode-property-for-sectionnode/58560
...(isSectionNode(node) ? [] : transformBlend(node)),
...transformSceneNode(node)
};
};
1 change: 1 addition & 0 deletions plugin-src/transformers/transformSceneNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const transformSceneNode = async (
return transformRectangleNode(node, baseX, baseY);
case 'ELLIPSE':
return transformEllipseNode(node, baseX, baseY);
case 'SECTION':
case 'FRAME':
return await transformFrameNode(node, baseX, baseY);
case 'GROUP':
Expand Down

0 comments on commit ebdf3ad

Please sign in to comment.