0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-24 15:48:53 -05:00
penpot-plugins/libs/plugin-types/index.d.ts

1297 lines
28 KiB
TypeScript
Raw Normal View History

2024-06-07 11:35:38 +02:00
/**
* PenpotFile represents a file in the Penpot application.
* It includes properties for the file's identifier, name, and revision number.
*/
2024-04-15 16:13:29 +02:00
export interface PenpotFile {
2024-02-28 12:54:37 +01:00
id: string;
2024-04-15 16:13:29 +02:00
name: string;
revn: number;
}
2024-04-12 10:45:39 +02:00
2024-06-07 11:35:38 +02:00
/**
* PenpotPage represents a page in the Penpot application.
* It includes properties for the page's identifier and name, as well as methods for managing shapes on the page.
*/
2024-04-15 16:13:29 +02:00
export interface PenpotPage {
2024-06-07 11:35:38 +02:00
/**
* The `id` property is a unique identifier for the page.
*/
2024-04-15 16:13:29 +02:00
id: string;
2024-06-07 11:35:38 +02:00
/**
* The `name` property is the name of the page.
*/
2024-04-15 16:13:29 +02:00
name: string;
2024-06-07 11:35:38 +02:00
/**
* Retrieves a shape by its unique identifier.
* @param id The unique identifier of the shape.
*/
2024-04-18 17:11:48 +02:00
getShapeById(id: string): PenpotShape | null;
2024-06-07 11:35:38 +02:00
/**
* Finds all shapes on the page.
*/
2024-04-12 10:45:39 +02:00
findShapes(): PenpotShape[];
2024-02-28 12:54:37 +01:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotGradient
*/
2024-04-22 16:02:06 +02:00
export type PenpotGradient = {
type: 'linear' | 'radial';
startX: number;
startY: number;
endX: number;
endY: number;
width: number;
stops: Array<{ color: string; opacity?: number; offset: number }>;
};
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotImageData
*/
2024-04-22 16:02:06 +02:00
export type PenpotImageData = {
name?: string;
width: number;
height: number;
mtype?: string;
id: string;
keepApectRatio?: boolean;
};
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFill
*/
2024-04-15 16:13:29 +02:00
export interface PenpotFill {
2024-04-22 16:02:06 +02:00
fillColor?: string;
fillOpacity?: number;
fillColorGradient?: PenpotGradient;
fillColorRefFile?: string;
fillColorRefId?: string;
fillImage?: PenpotImageData;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotStrokeCap
*/
2024-04-22 16:02:06 +02:00
export type PenpotStrokeCap =
| 'round'
| 'square'
| 'line-arrow'
| 'triangle-arrow'
| 'square-marker'
| 'circle-marker'
| 'diamond-marker';
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotStroke
*/
2024-04-22 16:02:06 +02:00
export interface PenpotStroke {
strokeColor?: string;
strokeColorRefFile?: string;
strokeColorRefId?: string;
strokeOpacity?: number;
strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg';
strokeWidth?: number;
strokeAlignment?: 'center' | 'inner' | 'outer';
strokeCapStart?: PenpotStrokeCap;
strokeCapEnd?: PenpotStrokeCap;
2024-05-27 13:12:20 +02:00
strokeColorGradient?: PenpotGradient;
2024-04-15 16:13:29 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotColor
*/
2024-05-08 16:56:34 +02:00
export interface PenpotColor {
2024-05-27 13:12:20 +02:00
id?: string;
2024-05-08 16:56:34 +02:00
name?: string;
path?: string;
color?: string;
opacity?: number;
refId?: string;
refFile?: string;
gradient?: PenpotGradient;
image?: PenpotImageData;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotShadow
*/
2024-05-08 16:56:34 +02:00
export interface PenpotShadow {
2024-05-27 13:12:20 +02:00
id?: string;
style?: 'drop-shadow' | 'inner-shadow';
offsetX?: number;
offsetY?: number;
blur?: number;
spread?: number;
hidden?: boolean;
color?: PenpotColor;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotBlur
*/
2024-05-08 16:56:34 +02:00
export interface PenpotBlur {
2024-05-27 13:12:20 +02:00
id?: string;
type?: 'layer-blur';
value?: number;
hidden?: boolean;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuideColumnParams
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideColumnParams {
color: { color: string; opacity: number };
type?: 'stretch' | 'left' | 'center' | 'right';
size?: number;
margin?: number;
itemLength?: number;
gutter?: number;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuideSquareParams
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideSquareParams {
color: { color: string; opacity: number };
size?: number;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuideColumn
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideColumn {
type: 'column';
display: boolean;
params: PenpotFrameGuideColumnParams;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuideRow
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideRow {
type: 'row';
display: boolean;
params: PenpotFrameGuideColumnParams;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuideSquare
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideSquare {
type: 'column';
display: boolean;
params: PenpotFrameGuideSquareParams;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrameGuide
*/
2024-05-08 16:56:34 +02:00
export type PenpotFrameGuide =
| PenpotFrameGuideColumn
| PenpotFrameGuideRow
| PenpotFrameGuideSquare;
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotExport
*/
2024-05-08 16:56:34 +02:00
export interface PenpotExport {}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotTrackType
*/
2024-05-08 16:56:34 +02:00
export type PenpotTrackType = 'flex' | 'fixed' | 'percent' | 'auto';
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotTrack
*/
2024-05-08 16:56:34 +02:00
export interface PenpotTrack {
type: PenpotTrackType;
value: number | null;
}
2024-06-07 11:35:38 +02:00
/**
* PenpotCommonLayout represents a common layout interface in the Penpot application.
* It includes various properties for alignment, spacing, padding, and sizing, as well as a method to remove the layout.
*/
export interface PenpotCommonLayout {
2024-06-07 11:35:38 +02:00
/**
* The `alignItems` property specifies the default alignment for items inside the container.
* It can be one of the following values:
* - 'start': Items are aligned at the start.
* - 'end': Items are aligned at the end.
* - 'center': Items are centered.
* - 'stretch': Items are stretched to fill the container.
*/
2024-05-08 16:56:34 +02:00
alignItems?: 'start' | 'end' | 'center' | 'stretch';
2024-06-07 11:35:38 +02:00
/**
* The `alignContent` property specifies how the content is aligned within the container when there is extra space.
* It can be one of the following values:
* - 'start': Content is aligned at the start.
* - 'end': Content is aligned at the end.
* - 'center': Content is centered.
* - 'space-between': Content is distributed with space between.
* - 'space-around': Content is distributed with space around.
* - 'space-evenly': Content is distributed with even space around.
* - 'stretch': Content is stretched to fill the container.
*/
2024-05-08 16:56:34 +02:00
alignContent?:
| 'start'
| 'end'
| 'center'
| 'space-between'
| 'space-around'
| 'space-evenly'
| 'stretch';
2024-06-07 11:35:38 +02:00
/**
* The `justifyItems` property specifies the default justification for items inside the container.
* It can be one of the following values:
* - 'start': Items are justified at the start.
* - 'end': Items are justified at the end.
* - 'center': Items are centered.
* - 'stretch': Items are stretched to fill the container.
*/
2024-05-08 16:56:34 +02:00
justifyItems?: 'start' | 'end' | 'center' | 'stretch';
2024-06-07 11:35:38 +02:00
/**
* The `justifyContent` property specifies how the content is justified within the container when there is extra space.
* It can be one of the following values:
* - 'start': Content is justified at the start.
* - 'center': Content is centered.
* - 'end': Content is justified at the end.
* - 'space-between': Content is distributed with space between.
* - 'space-around': Content is distributed with space around.
* - 'space-evenly': Content is distributed with even space around.
* - 'stretch': Content is stretched to fill the container.
*/
2024-05-08 16:56:34 +02:00
justifyContent?:
| 'start'
| 'center'
| 'end'
| 'space-between'
| 'space-around'
| 'space-evenly'
| 'stretch';
2024-06-07 11:35:38 +02:00
/**
* The `rowGap` property specifies the gap between rows in the layout.
*/
2024-05-08 16:56:34 +02:00
rowGap: number;
2024-06-07 11:35:38 +02:00
/**
* The `columnGap` property specifies the gap between columns in the layout.
*/
2024-05-08 16:56:34 +02:00
columnGap: number;
2024-06-07 11:35:38 +02:00
/**
* The `verticalPadding` property specifies the vertical padding inside the container.
*/
2024-05-08 16:56:34 +02:00
verticalPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `horizontalPadding` property specifies the horizontal padding inside the container.
*/
2024-05-08 16:56:34 +02:00
horizontalPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `topPadding` property specifies the padding at the top of the container.
*/
2024-05-08 16:56:34 +02:00
topPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `rightPadding` property specifies the padding at the right of the container.
*/
2024-05-08 16:56:34 +02:00
rightPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `bottomPadding` property specifies the padding at the bottom of the container.
*/
2024-05-08 16:56:34 +02:00
bottomPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `leftPadding` property specifies the padding at the left of the container.
*/
2024-05-08 16:56:34 +02:00
leftPadding: number;
2024-06-07 11:35:38 +02:00
/**
* The `horizontalSizing` property specifies the horizontal sizing behavior of the container.
* It can be one of the following values:
* - 'fit-content': The container fits the content.
* - 'fill': The container fills the available space.
* - 'auto': The container size is determined automatically.
*/
horizontalSizing: 'fit-content' | 'fill' | 'auto';
2024-06-07 11:35:38 +02:00
/**
* The `verticalSizing` property specifies the vertical sizing behavior of the container.
* It can be one of the following values:
* - 'fit-content': The container fits the content.
* - 'fill': The container fills the available space.
* - 'auto': The container size is determined automatically.
*/
verticalSizing: 'fit-content' | 'fill' | 'auto';
2024-06-07 11:35:38 +02:00
/**
* The `remove` method removes the layout.
*/
remove(): void;
}
2024-06-07 11:35:38 +02:00
/**
* PenpotGridLayout represents a grid layout in the Penpot application, extending the common layout interface.
* It includes properties and methods to manage rows, columns, and child elements within the grid.
*/
export interface PenpotGridLayout extends PenpotCommonLayout {
2024-06-07 11:35:38 +02:00
/**
* The `dir` property specifies the primary direction of the grid layout.
* It can be either 'column' or 'row'.
*/
dir: 'column' | 'row';
2024-06-07 11:35:38 +02:00
/**
* The `rows` property represents the collection of rows in the grid.
* This property is read-only.
*/
readonly rows: PenpotTrack[];
2024-06-07 11:35:38 +02:00
/**
* The `columns` property represents the collection of columns in the grid.
* This property is read-only.
*/
readonly columns: PenpotTrack[];
2024-06-07 11:35:38 +02:00
/**
* Adds a new row to the grid.
* @param type The type of the row to add.
* @param value The value associated with the row type (optional).
*/
addRow(type: PenpotTrackType, value?: number): void;
2024-06-07 11:35:38 +02:00
/**
* Adds a new row to the grid at the specified index.
* @param index The index at which to add the row.
* @param type The type of the row to add.
* @param value The value associated with the row type (optional).
*/
addRowAtIndex(index: number, type: PenpotTrackType, value?: number): void;
2024-06-07 11:35:38 +02:00
/**
* Adds a new column to the grid.
* @param type The type of the column to add.
* @param value The value associated with the column type (optional).
*/
addColumn(type: PenpotTrackType, value?: number): void;
2024-06-07 11:35:38 +02:00
/**
* Adds a new column to the grid at the specified index.
* @param index The index at which to add the column.
* @param type The type of the column to add.
* @param value The value associated with the column type.
*/
addColumnAtIndex(index: number, type: PenpotTrackType, value: number): void;
2024-06-07 11:35:38 +02:00
/**
* Removes a row from the grid at the specified index.
* @param index The index of the row to remove.
*/
removeRow(index: number): void;
2024-06-07 11:35:38 +02:00
/**
* Removes a column from the grid at the specified index.
* @param index The index of the column to remove.
*/
removeColumn(index: number): void;
2024-06-07 11:35:38 +02:00
/**
* Sets the properties of a column at the specified index.
* @param index The index of the column to set.
* @param type The type of the column.
* @param value The value associated with the column type (optional).
*/
setColumn(index: number, type: PenpotTrackType, value?: number): void;
2024-06-07 11:35:38 +02:00
/**
* Sets the properties of a row at the specified index.
* @param index The index of the row to set.
* @param type The type of the row.
* @param value The value associated with the row type (optional).
*/
setRow(index: number, type: PenpotTrackType, value?: number): void;
2024-06-07 11:35:38 +02:00
/**
* Appends a child element to the grid at the specified row and column.
* @param child The child element to append.
* @param row The row index where the child will be placed.
* @param column The column index where the child will be placed.
*/
appendChild(child: PenpotShape, row: number, column: number): void;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFlexLayout
*/
export interface PenpotFlexLayout extends PenpotCommonLayout {
dir: 'row' | 'row-reverse' | 'column' | 'column-reverse';
wrap?: 'wrap' | 'nowrap';
appendChild(child: PenpotShape): void;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotPathCommand
*/
2024-06-03 16:25:20 +02:00
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;
};
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotShapeBase
*/
2024-04-22 16:02:06 +02:00
export interface PenpotShapeBase {
2024-02-28 12:54:37 +01:00
id: string;
2024-04-15 16:13:29 +02:00
name: string;
x: number;
y: number;
width: number;
height: number;
2024-04-22 16:02:06 +02:00
2024-05-08 16:56:34 +02:00
blocked: boolean;
hidden: boolean;
proportionLock: boolean;
constraintsHorizontal: 'left' | 'right' | 'leftright' | 'center' | 'scale';
constraintsVertical: 'top' | 'bottom' | 'topbottom' | 'center' | 'scale';
borderRadius: number;
borderRadiusTopLeft: number;
borderRadiusTopRight: number;
borderRadiusBottomRight: number;
borderRadiusBottomLeft: number;
opacity: number;
blendMode:
| 'normal'
| 'darken'
| 'multiply'
| 'color-burn'
| 'lighten'
| 'screen'
| 'color-dodge'
| 'overlay'
| 'soft-light'
| 'hard-light'
| 'difference'
| 'exclusion'
| 'hue'
| 'saturation'
| 'color'
| 'luminosity';
shadows: PenpotShadow[];
2024-05-27 13:12:20 +02:00
blur?: PenpotBlur;
2024-05-08 16:56:34 +02:00
exports: PenpotExport;
// Relative positions
frameX: number;
frameY: number;
parentX: number;
parentY: number;
flipX: boolean;
flipY: boolean;
fills: PenpotFill[];
strokes: PenpotStroke[];
2024-04-22 16:02:06 +02:00
readonly layoutChild?: {
absolute: boolean;
zIndex: number;
horizontalSizing: 'auto' | 'fill' | 'fix';
verticalSizing: 'auto' | 'fill' | 'fix';
alignSelf: 'auto' | 'start' | 'center' | 'end' | 'stretch';
horizontalMargin: number;
verticalMargin: number;
topMargin: number;
rightMargin: number;
bottomMargin: number;
leftMargin: number;
maxWidth: number | null;
maxHeight: number | null;
minWidth: number | null;
minHeight: number | null;
};
readonly layoutCell?: {
row?: number;
rowSpan?: number;
column?: number;
columnSpan?: number;
areaName?: string;
position?: 'auto' | 'manual' | 'area';
};
resize(width: number, height: number): void;
2024-05-27 13:12:20 +02:00
2024-05-08 16:56:34 +02:00
clone(): PenpotShape;
remove(): void;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotFrame
*/
2024-04-22 16:02:06 +02:00
export interface PenpotFrame extends PenpotShapeBase {
readonly type: 'frame';
2024-05-08 16:56:34 +02:00
readonly grid?: PenpotGridLayout;
readonly flex?: PenpotFlexLayout;
2024-05-08 16:56:34 +02:00
guides: PenpotFrameGuide;
horizontalSizing?: 'auto' | 'fix';
verticalSizing?: 'auto' | 'fix';
// Container Properties
readonly children: PenpotShape[];
appendChild(child: PenpotShape): void;
insertChild(index: number, child: PenpotShape): void;
// Grid layout
addFlexLayout(): PenpotFlexLayout;
2024-05-08 16:56:34 +02:00
addGridLayout(): PenpotGridLayout;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotGroup
*/
2024-04-22 16:02:06 +02:00
export interface PenpotGroup extends PenpotShapeBase {
readonly type: 'group';
// Container Properties
2024-04-22 16:02:06 +02:00
readonly children: PenpotShape[];
appendChild(child: PenpotShape): void;
insertChild(index: number, child: PenpotShape): void;
2024-06-03 16:25:20 +02:00
makeMask(): void;
removeMask(): void;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotBoolType
*/
2024-06-03 16:25:20 +02:00
export type PenpotBoolType =
| 'union'
| 'difference'
| 'exclude'
| 'intersection';
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotBool
*/
2024-04-22 16:02:06 +02:00
export interface PenpotBool extends PenpotShapeBase {
readonly type: 'bool';
2024-06-03 16:25:20 +02:00
// From path
toD(): string;
content: Array<PenpotPathCommand>;
// Container Properties
2024-04-22 16:02:06 +02:00
readonly children: PenpotShape[];
appendChild(child: PenpotShape): void;
insertChild(index: number, child: PenpotShape): void;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotRectangle
*/
2024-04-22 16:02:06 +02:00
export interface PenpotRectangle extends PenpotShapeBase {
readonly type: 'rect';
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotPath
*/
2024-04-22 16:02:06 +02:00
export interface PenpotPath extends PenpotShapeBase {
2024-06-03 16:25:20 +02:00
readonly type: 'path';
toD(): string;
content: Array<PenpotPathCommand>;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* PenpotText represents a text element in the Penpot application, extending the base shape interface.
* It includes various properties to define the text content and its styling attributes.
*/
2024-04-22 16:02:06 +02:00
export interface PenpotText extends PenpotShapeBase {
readonly type: 'text';
characters: string;
2024-05-08 16:56:34 +02:00
growType: 'fixed' | 'auto-width' | 'auto-height';
2024-05-27 17:44:42 +02:00
fontId: string | 'mixed';
fontFamily: string | 'mixed';
fontVariantId: string | 'mixed';
fontSize: string | 'mixed';
fontWeight: string | 'mixed';
fontStyle: string | 'mixed';
lineHeight: string | 'mixed';
letterSpacing: string | 'mixed';
textTransform: string | 'mixed';
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PepotFrame
*/
2024-05-07 10:28:40 +02:00
export interface PepotFrame extends PenpotShapeBase {
readonly type: 'frame';
readonly children: PenpotShape[];
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotEllipse
*/
2024-06-03 16:25:20 +02:00
export interface PenpotEllipse extends PenpotShapeBase {
2024-04-22 16:02:06 +02:00
type: 'circle';
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotSvgRaw
*/
2024-04-22 16:02:06 +02:00
export interface PenpotSvgRaw extends PenpotShapeBase {
type: 'svg-raw';
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotImage
*/
2024-04-22 16:02:06 +02:00
export interface PenpotImage extends PenpotShapeBase {
type: 'image';
}
2024-06-07 11:35:38 +02:00
/**
* PenpotPoint represents a point in 2D space, typically with x and y coordinates.
*/
2024-04-22 16:02:06 +02:00
export type PenpotPoint = { x: number; y: number };
2024-06-07 11:35:38 +02:00
/**
* PenpotBounds represents the boundaries of a rectangular area,
* defined by the coordinates of the top-left corner and the dimensions of the rectangle.
*/
2024-04-22 16:02:06 +02:00
export type PenpotBounds = {
x: number;
y: number;
width: number;
height: number;
};
2024-06-07 11:35:38 +02:00
/**
* PenpotViewport represents the viewport in the Penpot application.
* It includes the center point, zoom level, and the bounds of the viewport.
*/
2024-04-22 16:02:06 +02:00
export interface PenpotViewport {
center: PenpotPoint;
zoom: number;
readonly bounds: PenpotBounds;
}
2024-06-07 11:35:38 +02:00
/**
* PenpotShape represents a union of various shape types used in the Penpot project.
* This type allows for different shapes to be handled under a single type umbrella.
*/
2024-04-22 16:02:06 +02:00
export type PenpotShape =
| PenpotFrame
| PenpotGroup
| PenpotBool
| PenpotRectangle
| PenpotPath
| PenpotText
2024-06-03 16:25:20 +02:00
| PenpotEllipse
2024-04-22 16:02:06 +02:00
| PenpotSvgRaw
| PenpotImage;
2024-06-07 11:35:38 +02:00
/**
* TODO EventsMap
*/
2024-03-27 13:57:02 +01:00
export interface EventsMap {
2024-06-07 11:35:38 +02:00
/**
* The `pagechange` event is triggered when the active page in the project is changed.
*/
2024-04-12 10:45:39 +02:00
pagechange: PenpotPage;
2024-06-07 11:35:38 +02:00
/**
* The `filechange` event is triggered when there are changes in the current file.
*/
2024-04-12 10:45:39 +02:00
filechange: PenpotFile;
2024-06-07 11:35:38 +02:00
/**
* The `selectionchange` event is triggered when the selection of elements changes.
* This event passes a list of identifiers of the selected elements.
*/
2024-03-07 10:34:06 +01:00
selectionchange: string[];
2024-06-07 11:35:38 +02:00
/**
* The `themechange` event is triggered when the application theme is changed.
*/
2024-04-12 10:45:39 +02:00
themechange: PenpotTheme;
2024-06-07 11:35:38 +02:00
/**
* The `finish` event is triggered when some operation is finished.
*/
finish: string;
2024-02-27 14:50:38 +01:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotTheme
*/
2024-04-12 10:45:39 +02:00
export type PenpotTheme = 'light' | 'dark';
2024-03-08 12:27:58 +01:00
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibraryElement
*/
2024-05-27 13:12:20 +02:00
export interface PenpotLibraryElement {
2024-05-30 09:29:44 +02:00
readonly id: string;
readonly libraryId: string;
name: string;
2024-05-27 13:12:20 +02:00
path: string;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibraryColor
*/
2024-05-27 13:12:20 +02:00
export interface PenpotLibraryColor extends PenpotLibraryElement {
color?: string;
opacity?: number;
gradient?: PenpotGradient;
image?: PenpotImageData;
2024-05-27 13:12:20 +02:00
2024-06-07 11:35:38 +02:00
/**
* TODO asFill
*
* @example
* ```js
* asFill code
* ```
*/
asFill(): PenpotFill;
2024-06-07 11:35:38 +02:00
/**
* TODO asStroke
*
* @example
* ```js
* asStroke code
* ```
*/
asStroke(): PenpotStroke;
2024-05-27 13:12:20 +02:00
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibraryTypography
*/
2024-05-27 13:12:20 +02:00
export interface PenpotLibraryTypography extends PenpotLibraryElement {
fontId: string;
fontFamily: string;
fontVariantId: string;
fontSize: string;
fontWeight: string;
fontStyle: string;
lineHeight: string;
letterSpacing: string;
textTransform: string;
2024-06-07 11:35:38 +02:00
/**
* TODO applyToText
*
* @param shape TODO
*
* @example
* ```js
* applyToText code
* ```
*/
2024-05-27 13:12:20 +02:00
applyToText(shape: PenpotShape): void;
2024-06-07 11:35:38 +02:00
/**
* TODO applyToTextRange
*
* @param shape TODO
*
* @example
* ```js
* applyToTextRange code
* ```
*/
2024-05-27 13:12:20 +02:00
applyToTextRange(shape: PenpotShape): void;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibraryComponent
*/
export interface PenpotLibraryComponent extends PenpotLibraryElement {
2024-06-07 11:35:38 +02:00
/**
* TODO instance
*
* @example
* ```js
* instance code
* ```
*/
instance(): PenpotShape;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibrary
*/
export type PenpotLibrary = {
colors: PenpotLibraryColor[];
typographies: PenpotLibraryTypography[];
components: PenpotLibraryComponent[];
2024-05-30 09:29:44 +02:00
2024-06-07 11:35:38 +02:00
/**
* TODO createColor
*
* @example
* ```js
* createColor code
* ```
*/
createColor(): PenpotLibraryColor;
2024-06-07 11:35:38 +02:00
/**
* TODO createTypography
*
* @example
* ```js
* createTypography code
* ```
*/
createTypography(): PenpotLibraryTypography;
2024-06-07 11:35:38 +02:00
/**
* TODO createComponent
*
* @example
* ```js
* createComponent code
* ```
*/
createComponent(shapes: PenpotShape[]): PenpotLibraryComponent;
};
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotLibraryContext
*/
export type PenpotLibraryContext = {
2024-06-07 11:35:38 +02:00
/**
* TODO local
*
* @example
* ```js
* local code
* ```
*/
local: PenpotLibrary;
2024-06-07 11:35:38 +02:00
/**
* TODO connected
*
* @example
* ```js
* connected code
* ```
*/
connected: PenpotLibrary[];
};
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotUser
*/
2024-06-04 17:35:39 +02:00
export interface PenpotUser {
2024-06-07 11:35:38 +02:00
/**
* TODO id
*
* @example
* ```js
* id code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly id: string;
2024-06-07 11:35:38 +02:00
/**
* TODO name
*
* @example
* ```js
* name code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly name?: string;
2024-06-07 11:35:38 +02:00
/**
* TODO avatarUrl
*
* @example
* ```js
* avatarUrl code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly avatarUrl?: string;
2024-06-07 11:35:38 +02:00
/**
* TODO color
*
* @example
* ```js
* color code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly color: string;
2024-06-07 11:35:38 +02:00
/**
* TODO sessionId
*
* @example
* ```js
* sessionId code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly sessionId?: string;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotActiveUser
*/
2024-06-04 17:35:39 +02:00
export interface PenpotActiveUser extends PenpotUser {
2024-06-07 11:35:38 +02:00
/**
* TODO position
*
* @example
* ```js
* position code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly position?: { x: number; y: number };
2024-06-07 11:35:38 +02:00
/**
* TODO zoom
*
* @example
* ```js
* zoom code
* ```
*/
2024-06-04 17:35:39 +02:00
readonly zoom?: number;
}
2024-06-07 11:35:38 +02:00
/**
* TODO PenpotContext
*/
export interface PenpotContext {
2024-06-07 11:35:38 +02:00
/**
* TODO root
*
* @example
* ```js
* context.root;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly root: PenpotShape;
2024-06-07 11:35:38 +02:00
/**
* TODO currentPage
*
* @example
* ```js
* context.currentPage;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly currentPage: PenpotPage;
2024-06-07 11:35:38 +02:00
/**
* TODO viewport
*
* @example
* ```js
* context.viewport;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly viewport: PenpotViewport;
2024-06-07 11:35:38 +02:00
/**
* TODO library
*
* @example
* ```js
* context.library;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly library: PenpotLibraryContext;
2024-06-07 11:35:38 +02:00
/**
* TODO currentUser
*
* @example
* ```js
* context.currentUser;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly currentUser: PenpotUser;
2024-06-07 11:35:38 +02:00
/**
* TODO activeUsers
*
* @example
* ```js
* context.activeUsers;
* ```
*/
2024-06-04 17:35:39 +02:00
readonly activeUsers: PenpotActiveUser;
2024-06-07 11:35:38 +02:00
/**
* TODO selection
*
* @example
* ```js
* penpot.selection;
* ```
*/
selection: PenpotShape[];
2024-06-07 11:35:38 +02:00
/**
* Use this method to get file data
*
* @example
* ```js
* penpot.getFile();
* ```
*/
getFile(): PenpotFile | null;
2024-06-07 11:35:38 +02:00
/**
* Use this method to get page data
*
* @example
* ```js
* penpot.getPage();
* ```
*/
getPage(): PenpotPage | null;
2024-06-07 11:35:38 +02:00
/**
* Use this method to get the selected elements on penpot. You'll get and array of ids.
*
* @example
* ```js
* penpot.getSelected();
* ```
*/
getSelected(): string[];
2024-06-07 11:35:38 +02:00
/**
* Use this method to get the selected elements on penpot. You'll get the data from each shape.
*
* @example
* ```js
* penpot.getSelectedShapes();
* ```
*/
getSelectedShapes(): PenpotShape[];
2024-06-07 11:35:38 +02:00
/**
* Use this method to get the selected theme on penpot. This is necessary to take care of the dark and light mode of your plugin UI.
*
* @example
* ```js
* penpot.getTheme();
* ```
*/
getTheme(): PenpotTheme;
2024-04-29 12:24:38 +02:00
uploadMediaUrl(name: string, url: string): Promise<PenpotImageData>;
group(shapes: PenpotShape[]): PenpotGroup;
ungroup(group: PenpotGroup, ...other: PenpotGroup[]): void;
2024-04-29 12:24:38 +02:00
2024-06-07 11:35:38 +02:00
/**
* Use this method to create the shape of a rectangle.
*
* @example
* ```js
* penpot.createRectangle();
* ```
*/
2024-04-22 16:02:06 +02:00
createRectangle(): PenpotRectangle;
2024-06-07 11:35:38 +02:00
/**
* Use this method to create a frame. This is the first step before anything else, the container.
* Then you can add a gridlayout, flexlayout or add a shape inside the frame.
*
* @example
* ```js
* penpot.createFrame();
* ```
*/
2024-05-08 16:56:34 +02:00
createFrame(): PenpotFrame;
2024-06-07 11:35:38 +02:00
/**
* Use this method to create the shape of a ellipse.
*
* @example
* ```js
* penpot.createEllipse();
* ```
*/
2024-06-03 16:25:20 +02:00
createEllipse(): PenpotEllipse;
2024-06-07 11:35:38 +02:00
/**
* Use this method to create a path.
*
* @example
* ```js
* penpot.createPath();
* ```
*/
2024-06-03 16:25:20 +02:00
createPath(): PenpotPath;
2024-06-07 11:35:38 +02:00
/**
* TODO createboolean
*
* @example
* ```js
* penpot.createBoolean();
* ```
*/
2024-06-03 16:25:20 +02:00
createBoolean(boolType: PenpotBoolType, shapes: PenpotShape[]): PenpotBool;
2024-06-07 11:35:38 +02:00
/**
* TODO createShapeFromSvg
*
* @example
* ```js
* penpot.createShapeFromSvg();
* ```
*/
createShapeFromSvg(svgString: string): PenpotGroup;
2024-06-07 11:35:38 +02:00
/**
* TODO createText
*
* @example
* ```js
* const board = penpot.createFrame();
* let text;
* text = penpot.createText();
* text.growType = 'auto-height';
* text.fontFamily = 'Work Sans';
* text.fontSize = '12';
* board.appendChild(text);
* ```
*/
2024-05-08 16:56:34 +02:00
createText(text: string): PenpotText;
2024-06-07 11:35:38 +02:00
/**
* TODO addListener
*
* @param type todo explanation
* @param callback todo explanation
*
* @example
* ```js
* penpot.addListener();
* ```
*/
addListener<T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void
): symbol;
2024-06-07 11:35:38 +02:00
/**
* TODO removeListener
*
* @example
* ```js
* penpot.removeListener();
* ```
*/
removeListener(listenerId: symbol): void;
}
2024-04-17 14:39:24 +02:00
/**
* These are methods and properties available on the `penpot` global object.
*
*/
export interface Penpot
extends Omit<PenpotContext, 'addListener' | 'removeListener'> {
2024-02-27 14:50:38 +01:00
ui: {
2024-04-17 14:39:24 +02:00
/**
2024-06-07 11:35:38 +02:00
* Opens the plugin UI. It is possible to develop a plugin without interface (see Palette color example) but if you need, the way to open this UI is using `penpot.ui.open`.
* There is a minimum and maximum size for this modal and a default size but it's possible to customize it anyway with the options parameter.
2024-04-17 14:39:24 +02:00
*
2024-06-07 11:35:38 +02:00
* @param name title of the plugin, it'll be displayed on the top of the modal
* @param url of the plugin
* @param options height and width of the modal.
*
* @example
* ```js
* penpot.ui.open('Plugin name', 'url', {width: 150, height: 300});
* ```
2024-04-17 14:39:24 +02:00
*/
2024-02-27 14:50:38 +01:00
open: (
name: string,
url: string,
2024-05-08 15:32:42 +02:00
options?: { width: number; height: number }
2024-02-27 14:50:38 +01:00
) => void;
2024-04-17 14:39:24 +02:00
/**
2024-06-07 11:35:38 +02:00
* TODO description of sendMessage
*
* @param message content usually is an object
2024-04-17 14:39:24 +02:00
*
2024-06-07 11:35:38 +02:00
* @example
* ```js
* this.sendMessage({ type: 'example-type', content: 'data we want to share' });
* ```
2024-04-17 14:39:24 +02:00
*/
2024-02-27 14:50:38 +01:00
sendMessage: (message: unknown) => void;
2024-04-17 14:39:24 +02:00
/**
2024-06-07 11:35:38 +02:00
* This is usually used in the `plugin.ts` file in order to handle the data sent by our plugin
*
* @param message content usually is an object
2024-04-17 14:39:24 +02:00
*
2024-06-07 11:35:38 +02:00
* @example
* ```js
* penpot.ui.onMessage((message) => {if(message.type === 'example-type' { ...do something })});
* ```
2024-04-17 14:39:24 +02:00
*/
2024-02-27 14:50:38 +01:00
onMessage: <T>(callback: (message: T) => void) => void;
};
2024-04-22 16:02:06 +02:00
utils: {
types: {
isText(shape: PenpotShape): shape is PenpotText;
2024-04-29 12:24:38 +02:00
isRectangle(shape: PenpotShape): shape is PenpotRectangle;
isFrame(shape: PenpotShape): shape is PenpotFrame;
2024-04-22 16:02:06 +02:00
};
};
2024-06-07 11:35:38 +02:00
/**
* Closes the plugin. When this method is called the UI will be closed.
*
* @example
* ```js
* penpot.closePlugin();
* ```
*/
2024-02-27 14:50:38 +01:00
closePlugin: () => void;
2024-06-07 11:35:38 +02:00
/**
* TODO description of 'on'
*
* @example
* ```js
* penpot.on('pagechange', () => {...do something}).
* ```
*/
2024-02-27 14:50:38 +01:00
on: <T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void
) => void;
2024-06-07 11:35:38 +02:00
/**
* TODO description of 'off'
*
* @example
* ```js
* penpot.off('pagechange', () => {...do something}).
* ```
*/
2024-02-28 12:54:37 +01:00
off: <T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void
) => void;
2024-02-27 14:50:38 +01:00
}
2024-03-27 13:57:02 +01:00
declare global {
2024-02-27 14:50:38 +01:00
const penpot: Penpot;
}