-
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.
- Loading branch information
1 parent
c464ff9
commit e732887
Showing
13 changed files
with
94 additions
and
15 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 | ||
--- | ||
|
||
Shadows |
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,9 @@ | ||
import { translateShadowEffects } from '@plugin/translators'; | ||
|
||
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes'; | ||
|
||
export const transformEffects = (node: BlendMixin): Partial<ShapeAttributes> => { | ||
return { | ||
shadow: translateShadowEffects(node.effects) | ||
}; | ||
}; |
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
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,45 @@ | ||
import { rgbToHex } from '@plugin/utils'; | ||
|
||
import { Shadow, ShadowStyle } from '@ui/lib/types/utils/shadow'; | ||
|
||
export const translateShadowEffect = (effect: Effect): Shadow | undefined => { | ||
if (effect.type !== 'DROP_SHADOW' && effect.type !== 'INNER_SHADOW') { | ||
return; | ||
} | ||
|
||
return { | ||
style: translateShadowType(effect), | ||
offsetX: effect.offset.x, | ||
offsetY: effect.offset.y, | ||
blur: effect.radius, | ||
spread: effect.spread ?? 0, | ||
hidden: !effect.visible, | ||
color: { | ||
color: rgbToHex(effect.color), | ||
opacity: effect.color.a | ||
} | ||
}; | ||
}; | ||
|
||
export const translateShadowEffects = (effects: readonly Effect[]): Shadow[] => { | ||
const shadows: Shadow[] = []; | ||
|
||
for (const effect of effects) { | ||
const shadow = translateShadowEffect(effect); | ||
if (shadow) { | ||
// effects are applied in reverse order in Figma, that's why we unshift | ||
shadows.unshift(shadow); | ||
} | ||
} | ||
|
||
return shadows; | ||
}; | ||
|
||
const translateShadowType = (effect: DropShadowEffect | InnerShadowEffect): ShadowStyle => { | ||
switch (effect.type) { | ||
case 'DROP_SHADOW': | ||
return 'drop-shadow'; | ||
case 'INNER_SHADOW': | ||
return 'inner-shadow'; | ||
} | ||
}; |
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