-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Runroom/feature/rect-shape
Rectangle & Circle
- Loading branch information
Showing
43 changed files
with
444 additions
and
89 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
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,4 @@ | ||
export * from './transformBlend'; | ||
export * from './transformChildren'; | ||
export * from './transformDimensionAndPosition'; | ||
export * from './transformSceneNode'; |
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,12 @@ | ||
import { translateBlendMode } from '@plugin/translators'; | ||
|
||
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes'; | ||
|
||
export const transformBlend = ( | ||
node: SceneNodeMixin & MinimalBlendMixin | ||
): Partial<ShapeAttributes> => { | ||
return { | ||
blendMode: translateBlendMode(node.blendMode), | ||
opacity: !node.visible ? 0 : node.opacity // @TODO: check this. If we use the property hidden and it's hidden, it won't export | ||
}; | ||
}; |
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,13 @@ | ||
import { transformSceneNode } from '@plugin/transformers'; | ||
|
||
import { Children } from '@ui/lib/types/utils/children'; | ||
|
||
export const transformChildren = async ( | ||
node: ChildrenMixin, | ||
baseX: number = 0, | ||
baseY: number = 0 | ||
): Promise<Children> => { | ||
return { | ||
children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY))) | ||
}; | ||
}; |
14 changes: 14 additions & 0 deletions
14
plugin-src/transformers/partials/transformDimensionAndPosition.ts
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,14 @@ | ||
import { ShapeGeomAttributes } from '@ui/lib/types/shape/shapeGeomAttributes'; | ||
|
||
export const transformDimensionAndPosition = ( | ||
node: DimensionAndPositionMixin, | ||
baseX: number, | ||
baseY: number | ||
): ShapeGeomAttributes => { | ||
return { | ||
x: node.x + baseX, | ||
y: node.y + baseY, | ||
width: node.width, | ||
height: node.height | ||
}; | ||
}; |
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,8 @@ | ||
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes'; | ||
|
||
export const transformSceneNode = (node: SceneNodeMixin): Partial<ShapeAttributes> => { | ||
return { | ||
blocked: node.locked, | ||
hidden: false // @TODO: check this. it won't export if we hide it | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { PenpotPage } from '@ui/lib/types/penpotPage'; | ||
import { transformChildren } from '@plugin/transformers/partials'; | ||
|
||
import { transformSceneNode } from '.'; | ||
import { PenpotPage } from '@ui/lib/types/penpotPage'; | ||
|
||
export const transformPageNode = async (node: PageNode): Promise<PenpotPage> => { | ||
return { | ||
name: node.name, | ||
children: await Promise.all(node.children.map(child => transformSceneNode(child))) | ||
...(await transformChildren(node)) | ||
}; | ||
}; |
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,46 @@ | ||
import { BlendMode as PenpotBlendMode } from '@ui/lib/types/utils/blendModes'; | ||
|
||
export const translateBlendMode = (blendMode: BlendMode): PenpotBlendMode => { | ||
switch (blendMode) { | ||
//@TODO: is not translatable in penpot, this is the closest one | ||
case 'PASS_THROUGH': | ||
case 'NORMAL': | ||
return 'normal'; | ||
//@TODO: is not translatable in penpot, this is the closest one | ||
case 'LINEAR_BURN': | ||
case 'DARKEN': | ||
return 'darken'; | ||
case 'MULTIPLY': | ||
return 'multiply'; | ||
case 'COLOR_BURN': | ||
return 'color-burn'; | ||
case 'LIGHTEN': | ||
return 'lighten'; | ||
case 'SCREEN': | ||
return 'screen'; | ||
//@TODO: is not translatable in penpot, this is the closest one | ||
case 'LINEAR_DODGE': | ||
case 'COLOR_DODGE': | ||
return 'color-dodge'; | ||
case 'OVERLAY': | ||
return 'overlay'; | ||
case 'SOFT_LIGHT': | ||
return 'soft-light'; | ||
case 'HARD_LIGHT': | ||
return 'hard-light'; | ||
case 'DIFFERENCE': | ||
return 'difference'; | ||
case 'EXCLUSION': | ||
return 'exclusion'; | ||
case 'HUE': | ||
return 'hue'; | ||
case 'SATURATION': | ||
return 'saturation'; | ||
case 'COLOR': | ||
return 'color'; | ||
case 'LUMINOSITY': | ||
return 'luminosity'; | ||
default: | ||
return 'normal'; | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { PenpotFile } from '@ui/lib/penpot'; | ||
import { RECT_TYPE } from '@ui/lib/types/rect/rectAttributes'; | ||
import { RectShape } from '@ui/lib/types/rect/rectShape'; | ||
import { translateFillGradients } from '@ui/translators'; | ||
import { translateFillGradients, translateUiBlendMode } from '@ui/translators'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const createPenpotRectangle = (file: PenpotFile, { type, fills, ...rest }: RectShape) => { | ||
export const createPenpotRectangle = ( | ||
file: PenpotFile, | ||
{ type, fills, blendMode, ...rest }: RectShape | ||
) => { | ||
file.createRect({ | ||
type: RECT_TYPE, | ||
fills: translateFillGradients(fills), | ||
blendMode: translateUiBlendMode(blendMode), | ||
...rest | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import { PenpotFile } from '@ui/lib/penpot'; | ||
import { TEXT_TYPE } from '@ui/lib/types/text/textAttributes'; | ||
import { TextShape } from '@ui/lib/types/text/textShape'; | ||
import { translateUiBlendMode } from '@ui/translators'; | ||
|
||
export const createPenpotText = ( | ||
file: PenpotFile, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
{ type, ...rest }: TextShape | ||
) => { | ||
export const createPenpotText = (file: PenpotFile, { type, blendMode, ...rest }: TextShape) => { | ||
file.createText({ | ||
type: TEXT_TYPE, | ||
blendMode: translateUiBlendMode(blendMode), | ||
...rest | ||
}); | ||
}; |
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.