0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
This commit is contained in:
Alex Sánchez 2024-04-15 14:06:23 +02:00
commit 6f4c56bc2c
No known key found for this signature in database
GPG key ID: 68A95170EEB87E16
15 changed files with 42 additions and 33 deletions

View file

@ -18,5 +18,8 @@ module.exports = {
react: { react: {
version: 'detect' version: 'detect'
} }
},
rules: {
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }]
} }
}; };

View file

@ -0,0 +1 @@
export * from './transformDimensionAndPosition';

View file

@ -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
};
};

View file

@ -1,3 +1,4 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { translateFills } from '@plugin/translators'; import { translateFills } from '@plugin/translators';
import { CircleShape } from '@ui/lib/types/circle/circleShape'; import { CircleShape } from '@ui/lib/types/circle/circleShape';
@ -10,10 +11,7 @@ export const transformEllipseNode = (
return { return {
type: 'circle', type: 'circle',
name: node.name, name: node.name,
x: node.x + baseX, fills: translateFills(node.fills, node.width, node.height),
y: node.y + baseY, ...transformDimensionAndPosition(node, baseX, baseY)
width: node.width,
height: node.height,
fills: translateFills(node.fills, node.width, node.height)
}; };
}; };

View file

@ -1,3 +1,4 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { translateFills } from '@plugin/translators'; import { translateFills } from '@plugin/translators';
import { FrameShape } from '@ui/lib/types/frame/frameShape'; import { FrameShape } from '@ui/lib/types/frame/frameShape';
@ -12,13 +13,10 @@ export const transformFrameNode = async (
return { return {
type: 'frame', type: 'frame',
name: node.name, name: node.name,
x: node.x + baseX,
y: node.y + baseY,
width: node.width,
height: node.height,
fills: translateFills(node.fills, node.width, node.height), fills: translateFills(node.fills, node.width, node.height),
children: await Promise.all( children: await Promise.all(
node.children.map(child => transformSceneNode(child, baseX + node.x, baseY + node.y)) node.children.map(child => transformSceneNode(child, baseX + node.x, baseY + node.y))
) ),
...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -1,6 +1,8 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { GroupShape } from '@ui/lib/types/group/groupShape'; import { GroupShape } from '@ui/lib/types/group/groupShape';
import { transformSceneNode } from './transformSceneNode'; import { transformSceneNode } from '.';
export const transformGroupNode = async ( export const transformGroupNode = async (
node: GroupNode, node: GroupNode,
@ -10,6 +12,9 @@ export const transformGroupNode = async (
return { return {
type: 'group', type: 'group',
name: node.name, name: node.name,
children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY))) children: await Promise.all(
node.children.map(child => transformSceneNode(child, baseX, baseY))
),
...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -1,3 +1,4 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { detectMimeType } from '@plugin/utils'; import { detectMimeType } from '@plugin/utils';
import { ImageShape } from '@ui/lib/types/image/imageShape'; import { ImageShape } from '@ui/lib/types/image/imageShape';
@ -17,14 +18,11 @@ export const transformImageNode = async (
return { return {
type: 'image', type: 'image',
name: node.name, name: node.name,
x: node.x + baseX,
y: node.y + baseY,
width: node.width,
height: node.height,
metadata: { metadata: {
width: node.width, width: node.width,
height: node.height height: node.height
}, },
dataUri: dataUri dataUri: dataUri,
...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -1,3 +1,4 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { translateBlendMode, translateFills } from '@plugin/translators'; import { translateBlendMode, translateFills } from '@plugin/translators';
import { RectShape } from '@ui/lib/types/rect/rectShape'; import { RectShape } from '@ui/lib/types/rect/rectShape';
@ -10,11 +11,8 @@ export const transformRectangleNode = (
return { return {
type: 'rect', type: 'rect',
name: node.name, name: node.name,
x: node.x + baseX,
y: node.y + baseY,
width: node.width,
height: node.height,
fills: translateFills(node.fills, node.width, node.height), fills: translateFills(node.fills, node.width, node.height),
blendMode: translateBlendMode(node.blendMode) blendMode: translateBlendMode(node.blendMode),
...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -6,7 +6,6 @@ import { createPenpotItem } from '.';
export const createPenpotArtboard = ( export const createPenpotArtboard = (
file: PenpotFile, file: PenpotFile,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ type, children = [], ...rest }: FrameShape { type, children = [], ...rest }: FrameShape
) => { ) => {
file.addArtboard({ file.addArtboard({

View file

@ -4,7 +4,6 @@ import { CircleShape } from '@ui/lib/types/circle/circleShape';
import { translateFillGradients } from '../translators'; import { translateFillGradients } from '../translators';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const createPenpotCircle = (file: PenpotFile, { type, fills, ...rest }: CircleShape) => { export const createPenpotCircle = (file: PenpotFile, { type, fills, ...rest }: CircleShape) => {
file.createCircle({ file.createCircle({
type: CIRCLE_TYPE, type: CIRCLE_TYPE,

View file

@ -6,7 +6,6 @@ import { createPenpotItem } from '.';
export const createPenpotGroup = ( export const createPenpotGroup = (
file: PenpotFile, file: PenpotFile,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ type, children = [], ...rest }: GroupShape { type, children = [], ...rest }: GroupShape
) => { ) => {
file.addGroup({ file.addGroup({

View file

@ -2,7 +2,6 @@ import { PenpotFile } from '@ui/lib/penpot';
import { IMAGE_TYPE } from '@ui/lib/types/image/imageAttributes'; import { IMAGE_TYPE } from '@ui/lib/types/image/imageAttributes';
import { ImageShape } from '@ui/lib/types/image/imageShape'; import { ImageShape } from '@ui/lib/types/image/imageShape';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const createPenpotImage = (file: PenpotFile, { type, ...rest }: ImageShape) => { export const createPenpotImage = (file: PenpotFile, { type, ...rest }: ImageShape) => {
file.createImage({ file.createImage({
type: IMAGE_TYPE, type: IMAGE_TYPE,

View file

@ -2,11 +2,7 @@ import { PenpotFile } from '@ui/lib/penpot';
import { TEXT_TYPE } from '@ui/lib/types/text/textAttributes'; import { TEXT_TYPE } from '@ui/lib/types/text/textAttributes';
import { TextShape } from '@ui/lib/types/text/textShape'; import { TextShape } from '@ui/lib/types/text/textShape';
export const createPenpotText = ( export const createPenpotText = (file: PenpotFile, { type, ...rest }: TextShape) => {
file: PenpotFile,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ type, ...rest }: TextShape
) => {
file.createText({ file.createText({
type: TEXT_TYPE, type: TEXT_TYPE,
...rest ...rest

View file

@ -36,8 +36,7 @@ export interface PenpotFile {
// lookupShape(shapeId: string): void; // lookupShape(shapeId: string): void;
// updateObject(id: string, object: any): void; // updateObject(id: string, object: any): void;
// deleteObject(id: string): void; // deleteObject(id: string): void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any asMap(): unknown;
asMap(): any;
export(): void; export(): void;
} }

View file

@ -1,5 +1,7 @@
import { Uuid } from '@ui/lib/types/utils/uuid'; import { Uuid } from '@ui/lib/types/utils/uuid';
import { Fill } from '../utils/fill';
export const FRAME_TYPE: unique symbol = Symbol.for('frame'); export const FRAME_TYPE: unique symbol = Symbol.for('frame');
export type FrameAttributes = { export type FrameAttributes = {
@ -9,4 +11,5 @@ export type FrameAttributes = {
hideFillOnExport?: boolean; hideFillOnExport?: boolean;
showContent?: boolean; showContent?: boolean;
hideInViewer?: boolean; hideInViewer?: boolean;
fills: Fill[]; // @TODO: Discover why is not defined on Penpot types
}; };