Skip to content

Commit

Permalink
Move utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhin committed Oct 2, 2023
1 parent 887f25e commit 8fa45ff
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { nodeHasFills } from '~api/services/figma/nodes/node-has-fills.ts';
import { type FigmaNode } from '~types/figma.ts';
import { nodeHasFills } from '~utils/node-has-fills.ts';
import { notEmpty } from '~utils/not-empty.ts';

export const isLayerVisible = (node: FigmaNode): boolean =>
export const isNodeVisible = (node: FigmaNode): boolean =>
node.visible === true &&
notEmpty(node.opacity) &&
node.opacity > 0 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type FigmaNode } from '~types/figma.ts';

import { getNodeFills } from './get-node-fills.ts';
import { getNodeFills } from '~utils/get-node-fills.ts';

export const nodeHasFills = (node: FigmaNode): boolean =>
getNodeFills(node).some((fill) => fill.visible);
2 changes: 1 addition & 1 deletion src/api/services/figma/nodes/specs/node-has-fills.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createFigmaNode } from '~api/services/figma/nodes/create-figma-node.ts';
import { nodeHasFills } from '~utils/node-has-fills.ts';
import { nodeHasFills } from '~api/services/figma/nodes/node-has-fills.ts';
import { describe, expect, test } from 'vitest';

describe('nodeHasFills', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/payload/build-general-selection-payload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getIntersectingNodes } from '~api/services/figma/intersections/get-intersecting-nodes.ts';
import { createFigmaNode } from '~api/services/figma/nodes/create-figma-node.ts';
import { isNodeVisible } from '~api/services/figma/nodes/is-node-visible.ts';
import { type SelectionChangeMessage } from '~types/messages.ts';
import { isLayerVisible } from '~utils/is-layer-visible.ts';

export const buildGeneralSelectionPayload = (
selection: readonly SceneNode[]
Expand All @@ -11,7 +11,7 @@ export const buildGeneralSelectionPayload = (
intersectingNodes: getIntersectingNodes(selectedNode),
selectedNode: createFigmaNode(selectedNode),
}))
.filter((pair) => isLayerVisible(pair.selectedNode));
.filter((pair) => isNodeVisible(pair.selectedNode));

return {
colorSpace: figma.root.documentColorProfile,
Expand Down
4 changes: 2 additions & 2 deletions src/api/services/payload/build-pair-selection-payload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFigmaNode } from '~api/services/figma/nodes/create-figma-node.ts';
import { isNodeVisible } from '~api/services/figma/nodes/is-node-visible.ts';
import { sortNodesByLayers } from '~api/services/figma/nodes/sort-nodes-by-layers.ts';
import { type SelectionChangeMessage } from '~types/messages.ts';
import { isLayerVisible } from '~utils/is-layer-visible.ts';
import { isEmpty } from '~utils/not-empty.ts';

export const buildPairSelectionPayload = (
Expand All @@ -19,7 +19,7 @@ export const buildPairSelectionPayload = (
const secondFigmaNode = createFigmaNode(secondNode);

const [fg, bg] = sortNodesByLayers(
[firstFigmaNode, secondFigmaNode].filter(isLayerVisible)
[firstFigmaNode, secondFigmaNode].filter(isNodeVisible)
);

if (isEmpty(fg) || isEmpty(bg))
Expand Down

0 comments on commit 8fa45ff

Please sign in to comment.