0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-03-11 23:31:23 -05:00

feat: updated api for plugins

This commit is contained in:
alonso.torres 2024-06-03 16:25:20 +02:00 committed by Alonso Torres
parent 588b565811
commit 0c828794e9
2 changed files with 79 additions and 3 deletions

View file

@ -198,6 +198,44 @@ export interface PenpotFlexLayout extends PenpotCommonLayout {
appendChild(child: PenpotShape): void;
}
interface PenpotPathCommand {
command:
| 'M'
| 'move-to'
| 'Z'
| 'close-path'
| 'L'
| 'line-to'
| 'H'
| 'line-to-horizontal'
| 'V'
| 'line-to-vertical'
| 'C'
| 'curve-to'
| 'S'
| 'smooth-curve-to'
| 'Q'
| 'quadratic-bezier-curve-to'
| 'T'
| 'smooth-quadratic-bezier-curve-to'
| 'A'
| 'elliptical-arc';
params?: {
x?: number;
y?: number;
c1x: number;
c1y: number;
c2x: number;
c2y: number;
rx?: number;
ry?: number;
xAxisRotation?: number;
largeArcFlag?: boolean;
sweepFlag?: boolean;
};
}
export interface PenpotShapeBase {
id: string;
name: string;
@ -316,11 +354,23 @@ export interface PenpotGroup extends PenpotShapeBase {
readonly children: PenpotShape[];
appendChild(child: PenpotShape): void;
insertChild(index: number, child: PenpotShape): void;
makeMask(): void;
removeMask(): void;
}
export type PenpotBoolType =
| 'union'
| 'difference'
| 'exclude'
| 'intersection';
export interface PenpotBool extends PenpotShapeBase {
readonly type: 'bool';
// From path
toD(): string;
content: Array<PenpotPathCommand>;
// Container Properties
readonly children: PenpotShape[];
appendChild(child: PenpotShape): void;
@ -332,7 +382,10 @@ export interface PenpotRectangle extends PenpotShapeBase {
}
export interface PenpotPath extends PenpotShapeBase {
readonly type: 'rect';
readonly type: 'path';
toD(): string;
content: Array<PenpotPathCommand>;
}
export interface PenpotText extends PenpotShapeBase {
@ -356,7 +409,7 @@ export interface PepotFrame extends PenpotShapeBase {
readonly children: PenpotShape[];
}
export interface PenpotCircle extends PenpotShapeBase {
export interface PenpotEllipse extends PenpotShapeBase {
type: 'circle';
}
@ -389,7 +442,7 @@ export type PenpotShape =
| PenpotRectangle
| PenpotPath
| PenpotText
| PenpotCircle
| PenpotEllipse
| PenpotSvgRaw
| PenpotImage;
@ -474,8 +527,12 @@ export interface PenpotContext {
createRectangle(): PenpotRectangle;
createFrame(): PenpotFrame;
createEllipse(): PenpotEllipse;
createPath(): PenpotPath;
createBoolean(boolType: PenpotBoolType, shapes: PenpotShape[]): PenpotBool;
createShapeFromSvg(svgString: string): PenpotGroup;
createText(text: string): PenpotText;
addListener<T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void

View file

@ -12,6 +12,10 @@ import type {
PenpotFile,
PenpotTheme,
PenpotLibraryContext,
PenpotEllipse,
PenpotPath,
PenpotBoolType,
PenpotBool,
} from '@penpot/plugin-types';
import { Manifest, Permissions } from '../models/manifest.model.js';
@ -224,11 +228,26 @@ export function createApi(context: PenpotContext, manifest: Manifest): Penpot {
return context.createRectangle();
},
createEllipse(): PenpotEllipse {
// checkPermission('page:write');
return context.createEllipse();
},
createText(text: string): PenpotText {
// checkPermission('page:write');
return context.createText(text);
},
createPath(): PenpotPath {
// checkPermission('page:write');
return context.createPath();
},
createBoolean(boolType: PenpotBoolType, shapes: PenpotShape[]): PenpotBool {
// checkPermission('page:write');
return context.createPath(boolType, shapes);
},
createShapeFromSvg(svgString: string): PenpotGroup {
// checkPermission('page:write');
return context.createShapeFromSvg(svgString);