From b8058dc0ee0d920bcead9b4aa5ac1ad6d83ab0e3 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Mon, 15 Apr 2024 16:18:58 +0000 Subject: [PATCH] refactor blend --- plugin-src/transformers/partials/index.ts | 1 + plugin-src/transformers/partials/transformBlend.ts | 12 ++++++++++++ plugin-src/transformers/transformEllipseNode.ts | 9 ++++----- plugin-src/transformers/transformGroupNode.ts | 5 +++-- plugin-src/transformers/transformRectangleNode.ts | 7 +++---- plugin-src/transformers/transformTextNode.ts | 9 ++++----- 6 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 plugin-src/transformers/partials/transformBlend.ts diff --git a/plugin-src/transformers/partials/index.ts b/plugin-src/transformers/partials/index.ts index ff265eb..2ab8c84 100644 --- a/plugin-src/transformers/partials/index.ts +++ b/plugin-src/transformers/partials/index.ts @@ -1,2 +1,3 @@ +export * from './transformBlend'; export * from './transformChildren'; export * from './transformDimensionAndPosition'; diff --git a/plugin-src/transformers/partials/transformBlend.ts b/plugin-src/transformers/partials/transformBlend.ts new file mode 100644 index 0000000..9711a61 --- /dev/null +++ b/plugin-src/transformers/partials/transformBlend.ts @@ -0,0 +1,12 @@ +import { translateBlendMode } from '@plugin/translators'; + +import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes'; + +export const transformBlend = ( + node: SceneNodeMixin & MinimalBlendMixin +): Partial => { + 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 + }; +}; diff --git a/plugin-src/transformers/transformEllipseNode.ts b/plugin-src/transformers/transformEllipseNode.ts index 2fcf529..d4d5ad2 100644 --- a/plugin-src/transformers/transformEllipseNode.ts +++ b/plugin-src/transformers/transformEllipseNode.ts @@ -1,5 +1,5 @@ -import { transformDimensionAndPosition } from '@plugin/transformers/partials'; -import { translateBlendMode, translateFills } from '@plugin/translators'; +import { transformBlend, transformDimensionAndPosition } from '@plugin/transformers/partials'; +import { translateFills } from '@plugin/translators'; import { CircleShape } from '@ui/lib/types/circle/circleShape'; @@ -12,8 +12,7 @@ export const transformEllipseNode = ( type: 'circle', name: node.name, fills: translateFills(node.fills, node.width, node.height), - 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 - ...transformDimensionAndPosition(node, baseX, baseY) + ...transformDimensionAndPosition(node, baseX, baseY), + ...transformBlend(node) }; }; diff --git a/plugin-src/transformers/transformGroupNode.ts b/plugin-src/transformers/transformGroupNode.ts index 893225f..a07506d 100644 --- a/plugin-src/transformers/transformGroupNode.ts +++ b/plugin-src/transformers/transformGroupNode.ts @@ -1,4 +1,4 @@ -import { transformDimensionAndPosition } from '@plugin/transformers/partials'; +import { transformBlend, transformDimensionAndPosition } from '@plugin/transformers/partials'; import { transformChildren } from '@plugin/transformers/partials'; import { GroupShape } from '@ui/lib/types/group/groupShape'; @@ -11,7 +11,8 @@ export const transformGroupNode = async ( return { type: 'group', name: node.name, + ...transformDimensionAndPosition(node, baseX, baseY), ...(await transformChildren(node, baseX, baseY)), - ...transformDimensionAndPosition(node, baseX, baseY) + ...transformBlend(node) }; }; diff --git a/plugin-src/transformers/transformRectangleNode.ts b/plugin-src/transformers/transformRectangleNode.ts index c4e43e7..275a069 100644 --- a/plugin-src/transformers/transformRectangleNode.ts +++ b/plugin-src/transformers/transformRectangleNode.ts @@ -1,5 +1,5 @@ -import { transformDimensionAndPosition } from '@plugin/transformers/partials'; -import { translateBlendMode, translateFills } from '@plugin/translators'; +import { transformBlend, transformDimensionAndPosition } from '@plugin/transformers/partials'; +import { translateFills } from '@plugin/translators'; import { RectShape } from '@ui/lib/types/rect/rectShape'; @@ -12,8 +12,7 @@ export const transformRectangleNode = ( type: 'rect', name: node.name, fills: translateFills(node.fills, node.width, node.height), - 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 + ...transformBlend(node), ...transformDimensionAndPosition(node, baseX, baseY) }; }; diff --git a/plugin-src/transformers/transformTextNode.ts b/plugin-src/transformers/transformTextNode.ts index e699e41..f03d32a 100644 --- a/plugin-src/transformers/transformTextNode.ts +++ b/plugin-src/transformers/transformTextNode.ts @@ -1,3 +1,4 @@ +import { transformBlend, transformDimensionAndPosition } from '@plugin/transformers/partials'; import { translateFills, translateTextDecoration, @@ -37,10 +38,6 @@ export const transformTextNode = (node: TextNode, baseX: number, baseY: number): return { type: 'text', name: node.name, - x: node.x + baseX, - y: node.y + baseY, - width: node.width, - height: node.height, content: { type: 'root', children: [ @@ -61,6 +58,8 @@ export const transformTextNode = (node: TextNode, baseX: number, baseY: number): ] } ] - } + }, + ...transformBlend(node), + ...transformDimensionAndPosition(node, baseX, baseY) }; };