-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * wipo * more structure * wip * id library wip * wip * main instance working * improvements * fix node order * refactor * remove not used method * refactor * fix component set translation * refactor * add changelog * penpot lib update --------- Co-authored-by: Jordi Sala Morales <[email protected]>
- Loading branch information
1 parent
5d4ace3
commit 7b31929
Showing
39 changed files
with
415 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Implement component instances translation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ShapeBaseAttributes } from '@ui/lib/types/shapes/shape'; | ||
|
||
export const transformFigmaIds = ( | ||
node: SceneNode | ||
): Pick<ShapeBaseAttributes, 'figmaId' | 'figmaRelatedId'> => { | ||
return { | ||
figmaId: normalizeNodeId(node.id), | ||
figmaRelatedId: getRelatedNodeId(node.id) | ||
}; | ||
}; | ||
|
||
const getRelatedNodeId = (nodeId: string): string | undefined => { | ||
const ids = nodeId.split(';'); | ||
|
||
if (ids.length > 1) { | ||
return ids.slice(1).join(';'); | ||
} | ||
}; | ||
|
||
const normalizeNodeId = (nodeId: string): string => { | ||
return nodeId.replace('I', ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
transformBlend, | ||
transformChildren, | ||
transformCornerRadius, | ||
transformDimensionAndPosition, | ||
transformEffects, | ||
transformFigmaIds, | ||
transformFills, | ||
transformProportion, | ||
transformSceneNode, | ||
transformStrokes | ||
} from '@plugin/transformers/partials'; | ||
|
||
import { ComponentInstance } from '@ui/types'; | ||
|
||
export const transformInstanceNode = async ( | ||
node: InstanceNode, | ||
baseX: number, | ||
baseY: number | ||
): Promise<ComponentInstance | undefined> => { | ||
const mainComponent = await node.getMainComponentAsync(); | ||
|
||
/** | ||
* We do not want to process component instances in the following scenarios: | ||
* | ||
* 1. If the component does not have a main component. | ||
* 2. If the component does not have parent (it comes from an external design system). | ||
* 3. If the component is inside a component set, (it is a variant component). | ||
*/ | ||
if ( | ||
!mainComponent || | ||
mainComponent.parent === null || | ||
mainComponent.parent.type === 'COMPONENT_SET' | ||
) { | ||
return; | ||
} | ||
|
||
return { | ||
type: 'instance', | ||
mainComponentFigmaId: mainComponent.id, | ||
isComponentRoot: isComponentRoot(node), | ||
...transformFigmaIds(node), | ||
...(await transformFills(node)), | ||
...transformEffects(node), | ||
...(await transformStrokes(node)), | ||
...transformSceneNode(node), | ||
...transformBlend(node), | ||
...transformProportion(node), | ||
...transformCornerRadius(node), | ||
...transformDimensionAndPosition(node, baseX, baseY), | ||
...(await transformChildren(node, baseX + node.x, baseY + node.y)) | ||
}; | ||
}; | ||
|
||
const isComponentRoot = (node: InstanceNode): boolean => { | ||
let parent = node.parent; | ||
while (parent !== null) { | ||
if (parent.type === 'COMPONENT' || parent.type === 'INSTANCE') { | ||
return false; | ||
} | ||
parent = parent.parent; | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.