Skip to content

Commit

Permalink
Refactor and simplify code (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 authored May 6, 2024
1 parent c013e80 commit afa47af
Show file tree
Hide file tree
Showing 90 changed files with 332 additions and 412 deletions.
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformBlend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { translateBlendMode } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformBlend = (
node: SceneNodeMixin & MinimalBlendMixin
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformCornerRadius.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

const isRectangleCornerMixin = (
node: CornerMixin | (CornerMixin & RectangleCornerMixin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShapeGeomAttributes } from '@ui/lib/types/shape/shapeGeomAttributes';
import { ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';

export const transformDimensionAndPosition = (
node: DimensionAndPositionMixin,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformEffects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { translateShadowEffects } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformEffects = (node: BlendMixin): Partial<ShapeAttributes> => {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformFills.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { translateFills } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformFills = (
node: MinimalFillsMixin & DimensionAndPositionMixin
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformProportion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformProportion = (node: LayoutMixin): Partial<ShapeAttributes> => {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformSceneNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformSceneNode = (node: SceneNodeMixin): Partial<ShapeAttributes> => {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformStrokes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { translateStrokes } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

const isVectorLike = (node: GeometryMixin | VectorLikeMixin): node is VectorLikeMixin => {
return 'vectorNetwork' in node;
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
translateVerticalAlign
} from '@plugin/translators/text';

import { TextShape } from '@ui/lib/types/text/textShape';
import { TextShape } from '@ui/lib/types/shapes/textShape';

export const transformText = (node: TextNode): Partial<TextShape> => {
const styledTextSegments = node.getStyledTextSegments([
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/partials/transformVectorPaths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { translateVectorPaths } from '@plugin/translators';

import { PathAttributes } from '@ui/lib/types/path/pathAttributes';
import { PathAttributes } from '@ui/lib/types/shapes/pathShape';

const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => {
switch (node.type) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformEllipseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
transformStrokes
} from '@plugin/transformers/partials';

import { CircleShape } from '@ui/lib/types/circle/circleShape';
import { CircleShape } from '@ui/lib/types/shapes/circleShape';

export const transformEllipseNode = (
node: EllipseNode,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
transformStrokes
} from '@plugin/transformers/partials';

import { FrameShape } from '@ui/lib/types/frame/frameShape';
import { FrameShape } from '@ui/lib/types/shapes/frameShape';

const isSectionNode = (node: FrameNode | SectionNode): node is SectionNode => {
return node.type === 'SECTION';
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformGroupNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@plugin/transformers/partials';
import { transformChildren } from '@plugin/transformers/partials';

import { GroupShape } from '@ui/lib/types/group/groupShape';
import { GroupShape } from '@ui/lib/types/shapes/groupShape';

export const transformGroupNode = async (
node: GroupNode,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformImageNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { detectMimeType } from '@plugin/utils';

import { ImageShape } from '@ui/lib/types/image/imageShape';
import { ImageShape } from '@ui/lib/types/shapes/imageShape';

export const transformImageNode = async (
node: SceneNode,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformPathNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
transformVectorPaths
} from '@plugin/transformers/partials';

import { PathShape } from '@ui/lib/types/path/pathShape';
import { PathShape } from '@ui/lib/types/shapes/pathShape';

const hasFillGeometry = (node: VectorNode | StarNode | LineNode | PolygonNode): boolean => {
return 'fillGeometry' in node && node.fillGeometry.length > 0;
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformRectangleNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
transformStrokes
} from '@plugin/transformers/partials';

import { RectShape } from '@ui/lib/types/rect/rectShape';
import { RectShape } from '@ui/lib/types/shapes/rectShape';

export const transformRectangleNode = (
node: RectangleNode,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/transformers/transformTextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
transformText
} from '@plugin/transformers/partials';

import { TextShape } from '@ui/lib/types/text/textShape';
import { TextShape } from '@ui/lib/types/shapes/textShape';

export const transformTextNode = (node: TextNode, baseX: number, baseY: number): TextShape => {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/custom/translateCustomFont.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getCustomFontId, translateFontVariantId } from '@plugin/translators/text/custom';

import { FontId } from '@ui/lib/types/text/textContent';
import { FontId } from '@ui/lib/types/shapes/textShape';

export const translateCustomFont = (fontName: FontName, fontWeight: number): FontId | undefined => {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/gfonts/translateGoogleFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import slugify from 'slugify';

import { translateFontVariantId } from '@plugin/translators/text/gfonts';

import { FontId } from '@ui/lib/types/text/textContent';
import { FontId } from '@ui/lib/types/shapes/textShape';

import { items as gfonts } from './gfonts.json';
import { GoogleFont } from './googleFont';
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/local/translateLocalFont.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LocalFont, translateFontVariantId } from '@plugin/translators/text/local';

import { FontId } from '@ui/lib/types/text/textContent';
import { FontId } from '@ui/lib/types/shapes/textShape';

import { items as localFonts } from './localFonts.json';

Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateFontId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FontId } from '@ui/lib/types/text/textContent';
import { FontId } from '@ui/lib/types/shapes/textShape';

import { translateCustomFont } from './custom';
import { translateGoogleFont } from './gfonts';
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateFontStyle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextFontStyle } from '@ui/lib/types/text/textContent';
import { TextFontStyle } from '@ui/lib/types/shapes/textShape';

export const translateFontStyle = (style: string): TextFontStyle => {
if (style.toLowerCase().includes('italic')) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateGrowType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GrowType } from '@ui/lib/types/shape/shapeAttributes';
import { GrowType } from '@ui/lib/types/shapes/shape';

export const translateGrowType = (node: TextNode): GrowType => {
if (node.leadingTrim === 'CAP_HEIGHT') {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateHorizontalAlign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextHorizontalAlign } from '@ui/lib/types/text/textContent';
import { TextHorizontalAlign } from '@ui/lib/types/shapes/textShape';

export const translateHorizontalAlign = (
align: 'LEFT' | 'CENTER' | 'RIGHT' | 'JUSTIFIED'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextNode as PenpotTextNode } from '@ui/lib/types/text/textContent';
import { TextNode as PenpotTextNode } from '@ui/lib/types/shapes/textShape';

export const translateParagraphProperties = (
node: TextNode,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateStyleTextSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
translateTextTransform
} from '@plugin/translators/text';

import { TextNode as PenpotTextNode, TextStyle } from '@ui/lib/types/text/textContent';
import { TextNode as PenpotTextNode, TextStyle } from '@ui/lib/types/shapes/textShape';

type StyleTextSegment = Pick<
StyledTextSegment,
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/text/translateVerticalAlign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextVerticalAlign } from '@ui/lib/types/text/textContent';
import { TextVerticalAlign } from '@ui/lib/types/shapes/textShape';

export const translateVerticalAlign = (align: 'TOP' | 'CENTER' | 'BOTTOM'): TextVerticalAlign => {
switch (align) {
Expand Down
2 changes: 1 addition & 1 deletion plugin-src/translators/translateVectorPaths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CurveToCommand, LineToCommand, MoveToCommand, parseSVG } from 'svg-path-parser';

import { Segment } from '@ui/lib/types/path/PathContent';
import { Segment } from '@ui/lib/types/shapes/pathShape';

export const translateVectorPaths = (
paths: VectorPaths,
Expand Down
18 changes: 0 additions & 18 deletions ui-src/converters/createGradientFill.ts

This file was deleted.

8 changes: 2 additions & 6 deletions ui-src/converters/createPenpotArtboard.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { PenpotFile } from '@ui/lib/penpot';
import { FRAME_TYPE } from '@ui/lib/types/frame/frameAttributes';
import { FrameShape } from '@ui/lib/types/frame/frameShape';
import { FrameShape } from '@ui/lib/types/shapes/frameShape';

import { createPenpotItem } from '.';

export const createPenpotArtboard = (
file: PenpotFile,
{ type, children = [], ...rest }: FrameShape
) => {
file.addArtboard({
type: FRAME_TYPE,
...rest
});
file.addArtboard(rest);

for (const child of children) {
createPenpotItem(file, child);
Expand Down
4 changes: 1 addition & 3 deletions ui-src/converters/createPenpotCircle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PenpotFile } from '@ui/lib/penpot';
import { CIRCLE_TYPE } from '@ui/lib/types/circle/circleAttributes';
import { CircleShape } from '@ui/lib/types/circle/circleShape';
import { CircleShape } from '@ui/lib/types/shapes/circleShape';

import { translateFillGradients, translateUiBlendMode } from '../translators';

Expand All @@ -9,7 +8,6 @@ export const createPenpotCircle = (
{ type, fills, blendMode, ...rest }: CircleShape
) => {
file.createCircle({
type: CIRCLE_TYPE,
fills: translateFillGradients(fills),
blendMode: translateUiBlendMode(blendMode),
...rest
Expand Down
4 changes: 1 addition & 3 deletions ui-src/converters/createPenpotGroup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PenpotFile } from '@ui/lib/penpot';
import { GROUP_TYPE } from '@ui/lib/types/group/groupAttributes';
import { GroupShape } from '@ui/lib/types/group/groupShape';
import { GroupShape } from '@ui/lib/types/shapes/groupShape';
import { translateUiBlendMode } from '@ui/translators';

import { createPenpotItem } from '.';
Expand All @@ -10,7 +9,6 @@ export const createPenpotGroup = (
{ type, blendMode, children = [], ...rest }: GroupShape
) => {
file.addGroup({
type: GROUP_TYPE,
blendMode: translateUiBlendMode(blendMode),
...rest
});
Expand Down
8 changes: 2 additions & 6 deletions ui-src/converters/createPenpotImage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { PenpotFile } from '@ui/lib/penpot';
import { IMAGE_TYPE } from '@ui/lib/types/image/imageAttributes';
import { ImageShape } from '@ui/lib/types/image/imageShape';
import { ImageShape } from '@ui/lib/types/shapes/imageShape';

export const createPenpotImage = (file: PenpotFile, { type, ...rest }: ImageShape) => {
file.createImage({
type: IMAGE_TYPE,
...rest
});
file.createImage(rest);
};
4 changes: 1 addition & 3 deletions ui-src/converters/createPenpotPath.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PenpotFile } from '@ui/lib/penpot';
import { PATH_TYPE } from '@ui/lib/types/path/pathAttributes';
import { PathShape } from '@ui/lib/types/path/pathShape';
import { PathShape } from '@ui/lib/types/shapes/pathShape';
import {
translateFillGradients,
translatePathContent,
Expand All @@ -12,7 +11,6 @@ export const createPenpotPath = (
{ type, fills, blendMode, content, ...rest }: PathShape
) => {
file.createPath({
type: PATH_TYPE,
fills: translateFillGradients(fills),
blendMode: translateUiBlendMode(blendMode),
content: translatePathContent(content),
Expand Down
4 changes: 1 addition & 3 deletions ui-src/converters/createPenpotRectangle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { PenpotFile } from '@ui/lib/penpot';
import { RECT_TYPE } from '@ui/lib/types/rect/rectAttributes';
import { RectShape } from '@ui/lib/types/rect/rectShape';
import { RectShape } from '@ui/lib/types/shapes/rectShape';
import { translateFillGradients, translateUiBlendMode } from '@ui/translators';

export const createPenpotRectangle = (
file: PenpotFile,
{ type, fills, blendMode, ...rest }: RectShape
) => {
file.createRect({
type: RECT_TYPE,
fills: translateFillGradients(fills),
blendMode: translateUiBlendMode(blendMode),
...rest
Expand Down
4 changes: 1 addition & 3 deletions ui-src/converters/createPenpotText.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { PenpotFile } from '@ui/lib/penpot';
import { TEXT_TYPE } from '@ui/lib/types/text/textAttributes';
import { TextShape } from '@ui/lib/types/text/textShape';
import { TextShape } from '@ui/lib/types/shapes/textShape';
import { translateUiBlendMode } from '@ui/translators';

export const createPenpotText = (file: PenpotFile, { type, blendMode, ...rest }: TextShape) => {
file.createText({
type: TEXT_TYPE,
blendMode: translateUiBlendMode(blendMode),
...rest
});
Expand Down
16 changes: 8 additions & 8 deletions ui-src/lib/penpot.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BoolShape } from '@ui/lib/types/bool/boolShape';
import { CircleShape } from '@ui/lib/types/circle/circleShape';
import { FrameShape } from '@ui/lib/types/frame/frameShape';
import { GroupShape } from '@ui/lib/types/group/groupShape';
import { ImageShape } from '@ui/lib/types/image/imageShape';
import { PathShape } from '@ui/lib/types/path/pathShape';
import { PenpotPageOptions } from '@ui/lib/types/penpotPage';
import { RectShape } from '@ui/lib/types/rect/rectShape';
import { TextShape } from '@ui/lib/types/text/textShape';
import { BoolShape } from '@ui/lib/types/shapes/boolShape';
import { CircleShape } from '@ui/lib/types/shapes/circleShape';
import { FrameShape } from '@ui/lib/types/shapes/frameShape';
import { GroupShape } from '@ui/lib/types/shapes/groupShape';
import { ImageShape } from '@ui/lib/types/shapes/imageShape';
import { PathShape } from '@ui/lib/types/shapes/pathShape';
import { RectShape } from '@ui/lib/types/shapes/rectShape';
import { TextShape } from '@ui/lib/types/shapes/textShape';

export interface PenpotFile {
addPage(name: string, options?: PenpotPageOptions): void;
Expand Down
12 changes: 0 additions & 12 deletions ui-src/lib/types/bool/boolAttributes.ts

This file was deleted.

8 changes: 0 additions & 8 deletions ui-src/lib/types/bool/boolContent.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions ui-src/lib/types/bool/boolShape.d.ts

This file was deleted.

Loading

0 comments on commit afa47af

Please sign in to comment.