0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-02-09 08:38:18 -05:00
penpot-plugins/libs/plugin-types/index.d.ts

2093 lines
55 KiB
TypeScript
Raw Normal View History

2024-06-06 09:36:03 +02:00
/**
2024-06-10 14:23:36 +02:00
* Provides methods for managing plugin-specific data associated with a Penpot shape.
2024-06-06 09:36:03 +02:00
*/
export interface PenpotPluginData {
2024-06-10 14:23:36 +02:00
/**
* Retrieves the plugin-specific data associated with the given key.
*
* @param key The key for which to retrieve the data.
* Returns the data associated with the key as a string.
*/
2024-06-06 09:36:03 +02:00
getPluginData(key: string): string;
2024-06-10 14:23:36 +02:00
/**
* Sets the plugin-specific data for the given key.
*
* @param key The key for which to set the data.
* @param value The data to set for the key.
*/
2024-06-06 09:36:03 +02:00
setPluginData(key: string, value: string): void;
2024-06-10 14:23:36 +02:00
/**
* Retrieves all the keys for the plugin-specific data.
*
* Returns an array of strings representing all the keys.
*/
2024-06-06 09:36:03 +02:00
getPluginDataKeys(): string[];
2024-06-10 14:23:36 +02:00
/**
* Retrieves the shared plugin-specific data for the given namespace and key.
*
* @param namespace The namespace for the shared data.
* @param key The key for which to retrieve the data.
* Returns the shared data associated with the key as a string.
*/
2024-06-06 09:36:03 +02:00
getSharedPluginData(namespace: string, key: string): string;
2024-06-10 14:23:36 +02:00
/**
* Sets the shared plugin-specific data for the given namespace and key.
*
* @param namespace The namespace for the shared data.
* @param key The key for which to set the data.
* @param value The data to set for the key.
*/
2024-06-06 09:36:03 +02:00
setSharedPluginData(namespace: string, key: string, value: string): void;
2024-06-10 14:23:36 +02:00
/**
* Retrieves all the keys for the shared plugin-specific data in the given namespace.
*
* @param namespace The namespace for the shared data.
* Returns an array of strings representing all the keys in the namespace.
*/
2024-06-06 09:36:03 +02:00
getSharedPluginDataKeys(namespace: string): string[];
}
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-06-06 09:36:03 +02:00
export interface PenpotFile extends PenpotPluginData {
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-06-06 09:36:03 +02:00
export interface PenpotPage extends PenpotPluginData {
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
/**
2024-06-10 14:23:36 +02:00
* Represents a gradient configuration in Penpot.
* A gradient can be either linear or radial and includes properties to define its shape, position, and color stops.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export type PenpotGradient = {
2024-06-10 14:23:36 +02:00
/**
* Specifies the type of gradient.
* - 'linear': A gradient that transitions colors along a straight line.
* - 'radial': A gradient that transitions colors radiating outward from a central point.
*/
2024-04-22 16:02:06 +02:00
type: 'linear' | 'radial';
2024-06-10 14:23:36 +02:00
/**
* The X-coordinate of the starting point of the gradient.
*/
2024-04-22 16:02:06 +02:00
startX: number;
2024-06-10 14:23:36 +02:00
/**
* The Y-coordinate of the starting point of the gradient.
*/
2024-04-22 16:02:06 +02:00
startY: number;
2024-06-10 14:23:36 +02:00
/**
* The X-coordinate of the ending point of the gradient.
*/
2024-04-22 16:02:06 +02:00
endX: number;
2024-06-10 14:23:36 +02:00
/**
* The Y-coordinate of the ending point of the gradient.
*/
2024-04-22 16:02:06 +02:00
endY: number;
2024-06-10 14:23:36 +02:00
/**
* The width of the gradient. For radial gradients, this could be interpreted as the radius.
*/
2024-04-22 16:02:06 +02:00
width: number;
2024-06-10 14:23:36 +02:00
/**
* An array of color stops that define the gradient.
*/
2024-04-22 16:02:06 +02:00
stops: Array<{ color: string; opacity?: number; offset: number }>;
};
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents image data in Penpot.
* This includes properties for defining the image's dimensions, metadata, and aspect ratio handling.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export type PenpotImageData = {
2024-06-10 14:23:36 +02:00
/**
* The optional name of the image.
*/
2024-04-22 16:02:06 +02:00
name?: string;
2024-06-10 14:23:36 +02:00
/**
* The width of the image.
*/
2024-04-22 16:02:06 +02:00
width: number;
2024-06-10 14:23:36 +02:00
/**
* The height of the image.
*/
2024-04-22 16:02:06 +02:00
height: number;
2024-06-10 14:23:36 +02:00
/**
* The optional media type of the image (e.g., 'image/png', 'image/jpeg').
*/
2024-04-22 16:02:06 +02:00
mtype?: string;
2024-06-10 14:23:36 +02:00
/**
* The unique identifier for the image.
*/
2024-04-22 16:02:06 +02:00
id: string;
2024-06-10 14:23:36 +02:00
/**
* Whether to keep the aspect ratio of the image when resizing.
* Defaults to false if omitted.
*/
2024-04-22 16:02:06 +02:00
keepApectRatio?: boolean;
};
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents fill properties in Penpot.
* This interface includes properties for defining solid color fills, gradient fills, and image fills.
2024-06-07 11:35:38 +02:00
*/
2024-04-15 16:13:29 +02:00
export interface PenpotFill {
2024-06-10 14:23:36 +02:00
/**
* The optional solid fill color, represented as a string (e.g., '#FF5733').
*/
2024-04-22 16:02:06 +02:00
fillColor?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional opacity level of the solid fill color, ranging from 0 (fully transparent) to 1 (fully opaque).
* Defaults to 1 if omitted.
*/
2024-04-22 16:02:06 +02:00
fillOpacity?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional gradient fill defined by a PenpotGradient object.
*/
2024-04-22 16:02:06 +02:00
fillColorGradient?: PenpotGradient;
2024-06-10 14:23:36 +02:00
/**
* The optional reference to an external file for the fill color.
*/
2024-04-22 16:02:06 +02:00
fillColorRefFile?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional reference ID within the external file for the fill color.
*/
2024-04-22 16:02:06 +02:00
fillColorRefId?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional image fill defined by a PenpotImageData object.
*/
2024-04-22 16:02:06 +02:00
fillImage?: PenpotImageData;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the cap style of a stroke in Penpot.
* This type defines various styles for the ends of a stroke.
2024-06-07 11:35:38 +02:00
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents stroke properties in Penpot.
* This interface includes properties for defining the color, style, width, alignment, and caps of a stroke.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotStroke {
2024-06-10 14:23:36 +02:00
/**
* The optional color of the stroke, represented as a string (e.g., '#FF5733').
*/
2024-04-22 16:02:06 +02:00
strokeColor?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional reference to an external file for the stroke color.
*/
2024-04-22 16:02:06 +02:00
strokeColorRefFile?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional reference ID within the external file for the stroke color.
*/
2024-04-22 16:02:06 +02:00
strokeColorRefId?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional opacity level of the stroke color, ranging from 0 (fully transparent) to 1 (fully opaque).
* Defaults to 1 if omitted.
*/
2024-04-22 16:02:06 +02:00
strokeOpacity?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional style of the stroke.
*/
2024-04-22 16:02:06 +02:00
strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg';
2024-06-10 14:23:36 +02:00
/**
* The optional width of the stroke.
*/
2024-04-22 16:02:06 +02:00
strokeWidth?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional alignment of the stroke relative to the shape's boundary.
*/
2024-04-22 16:02:06 +02:00
strokeAlignment?: 'center' | 'inner' | 'outer';
2024-06-10 14:23:36 +02:00
/**
* The optional cap style for the start of the stroke.
*/
2024-04-22 16:02:06 +02:00
strokeCapStart?: PenpotStrokeCap;
2024-06-10 14:23:36 +02:00
/**
* The optional cap style for the end of the stroke.
*/
2024-04-22 16:02:06 +02:00
strokeCapEnd?: PenpotStrokeCap;
2024-06-10 14:23:36 +02:00
/**
* The optional gradient stroke defined by a PenpotGradient object.
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents color properties in Penpot.
* This interface includes properties for defining solid colors, gradients, and image fills, along with metadata.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotColor {
2024-06-10 14:23:36 +02:00
/**
* The optional unique identifier for the color.
*/
2024-05-27 13:12:20 +02:00
id?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional name of the color.
*/
2024-05-08 16:56:34 +02:00
name?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional path or category to which this color belongs.
*/
2024-05-08 16:56:34 +02:00
path?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional solid color, represented as a string (e.g., '#FF5733').
*/
2024-05-08 16:56:34 +02:00
color?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional opacity level of the color, ranging from 0 (fully transparent) to 1 (fully opaque).
* Defaults to 1 if omitted.
*/
2024-05-08 16:56:34 +02:00
opacity?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional reference ID for an external color definition.
*/
2024-05-08 16:56:34 +02:00
refId?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional reference to an external file for the color definition.
*/
2024-05-08 16:56:34 +02:00
refFile?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional gradient fill defined by a PenpotGradient object.
*/
2024-05-08 16:56:34 +02:00
gradient?: PenpotGradient;
2024-06-10 14:23:36 +02:00
/**
* The optional image fill defined by a PenpotImageData object.
*/
2024-05-08 16:56:34 +02:00
image?: PenpotImageData;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents shadow properties in Penpot.
* This interface includes properties for defining drop shadows and inner shadows, along with their visual attributes.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotShadow {
2024-06-10 14:23:36 +02:00
/**
* The optional unique identifier for the shadow.
*/
2024-05-27 13:12:20 +02:00
id?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional style of the shadow.
* - 'drop-shadow': A shadow cast outside the element.
* - 'inner-shadow': A shadow cast inside the element.
*/
2024-05-27 13:12:20 +02:00
style?: 'drop-shadow' | 'inner-shadow';
2024-06-10 14:23:36 +02:00
/**
* The optional X-axis offset of the shadow.
*/
2024-05-27 13:12:20 +02:00
offsetX?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional Y-axis offset of the shadow.
*/
2024-05-27 13:12:20 +02:00
offsetY?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional blur radius of the shadow.
*/
2024-05-27 13:12:20 +02:00
blur?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional spread radius of the shadow.
*/
2024-05-27 13:12:20 +02:00
spread?: number;
2024-06-10 14:23:36 +02:00
/**
* Specifies whether the shadow is hidden.
* Defaults to false if omitted.
*/
2024-05-27 13:12:20 +02:00
hidden?: boolean;
2024-06-10 14:23:36 +02:00
/**
* The optional color of the shadow, defined by a PenpotColor object.
*/
2024-05-27 13:12:20 +02:00
color?: PenpotColor;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents blur properties in Penpot.
* This interface includes properties for defining the type and intensity of a blur effect, along with its visibility.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotBlur {
2024-06-10 14:23:36 +02:00
/**
* The optional unique identifier for the blur effect.
*/
2024-05-27 13:12:20 +02:00
id?: string;
2024-06-10 14:23:36 +02:00
/**
* The optional type of the blur effect.
* Currently, only 'layer-blur' is supported.
*/
2024-05-27 13:12:20 +02:00
type?: 'layer-blur';
2024-06-10 14:23:36 +02:00
/**
* The optional intensity value of the blur effect.
*/
2024-05-27 13:12:20 +02:00
value?: number;
2024-06-10 14:23:36 +02:00
/**
* Specifies whether the blur effect is hidden.
* Defaults to false if omitted.
*/
2024-05-27 13:12:20 +02:00
hidden?: boolean;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents parameters for frame guide columns in Penpot.
* This interface includes properties for defining the appearance and layout of column guides within a frame.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideColumnParams {
2024-06-10 14:23:36 +02:00
/**
* The color configuration for the column guides.
*/
2024-05-08 16:56:34 +02:00
color: { color: string; opacity: number };
2024-06-10 14:23:36 +02:00
/**
* The optional alignment type of the column guides.
* - 'stretch': Columns stretch to fit the available space.
* - 'left': Columns align to the left.
* - 'center': Columns align to the center.
* - 'right': Columns align to the right.
*/
2024-05-08 16:56:34 +02:00
type?: 'stretch' | 'left' | 'center' | 'right';
2024-06-10 14:23:36 +02:00
/**
* The optional size of each column.
*/
2024-05-08 16:56:34 +02:00
size?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional margin between the columns and the frame edges.
*/
2024-05-08 16:56:34 +02:00
margin?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional length of each item within the columns.
*/
2024-05-08 16:56:34 +02:00
itemLength?: number;
2024-06-10 14:23:36 +02:00
/**
* The optional gutter width between columns.
*/
2024-05-08 16:56:34 +02:00
gutter?: number;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents parameters for frame guide squares in Penpot.
* This interface includes properties for defining the appearance and size of square guides within a frame.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideSquareParams {
2024-06-10 14:23:36 +02:00
/**
* The color configuration for the square guides.
*/
2024-05-08 16:56:34 +02:00
color: { color: string; opacity: number };
2024-06-10 14:23:36 +02:00
/**
* The optional size of each square guide.
*/
2024-05-08 16:56:34 +02:00
size?: number;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame guide for columns in Penpot.
* This interface includes properties for defining the type, visibility, and parameters of column guides within a frame.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideColumn {
2024-06-10 14:23:36 +02:00
/**
* The type of the guide, which is always 'column' for column guides.
*/
2024-05-08 16:56:34 +02:00
type: 'column';
2024-06-10 14:23:36 +02:00
/**
* Specifies whether the column guide is displayed.
*/
2024-05-08 16:56:34 +02:00
display: boolean;
2024-06-10 14:23:36 +02:00
/**
* The parameters defining the appearance and layout of the column guides.
*/
2024-05-08 16:56:34 +02:00
params: PenpotFrameGuideColumnParams;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame guide for rows in Penpot.
* This interface includes properties for defining the type, visibility, and parameters of row guides within a frame.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideRow {
2024-06-10 14:23:36 +02:00
/**
* The type of the guide, which is always 'row' for row guides.
*/
2024-05-08 16:56:34 +02:00
type: 'row';
2024-06-10 14:23:36 +02:00
/**
* Specifies whether the row guide is displayed.
*/
2024-05-08 16:56:34 +02:00
display: boolean;
2024-06-10 14:23:36 +02:00
/**
* The parameters defining the appearance and layout of the row guides.
* Note: This reuses the same parameter structure as column guides.
*/
2024-05-08 16:56:34 +02:00
params: PenpotFrameGuideColumnParams;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame guide for squares in Penpot.
* This interface includes properties for defining the type, visibility, and parameters of square guides within a frame.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotFrameGuideSquare {
2024-06-10 14:23:36 +02:00
/**
* The type of the guide, which is always 'column' for square guides.
*/
2024-05-08 16:56:34 +02:00
type: 'column';
2024-06-10 14:23:36 +02:00
/**
* Specifies whether the square guide is displayed.
*/
2024-05-08 16:56:34 +02:00
display: boolean;
2024-06-10 14:23:36 +02:00
/**
* The parameters defining the appearance and layout of the square guides.
*/
2024-05-08 16:56:34 +02:00
params: PenpotFrameGuideSquareParams;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame guide in Penpot.
* This type can be one of several specific frame guide types: column, row, or square.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export type PenpotFrameGuide =
| PenpotFrameGuideColumn
| PenpotFrameGuideRow
| PenpotFrameGuideSquare;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents export settings in Penpot.
* This interface includes properties for defining export configurations.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotExport {}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the type of track in Penpot.
* This type defines various track types that can be used in layout configurations.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export type PenpotTrackType = 'flex' | 'fixed' | 'percent' | 'auto';
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a track configuration in Penpot.
* This interface includes properties for defining the type and value of a track used in layout configurations.
2024-06-07 11:35:38 +02:00
*/
2024-05-08 16:56:34 +02:00
export interface PenpotTrack {
2024-06-10 14:23:36 +02:00
/**
* The type of the track.
* This can be one of the following values:
* - 'flex': A flexible track type.
* - 'fixed': A fixed track type.
* - 'percent': A track type defined by a percentage.
* - 'auto': An automatic track type.
*/
2024-05-08 16:56:34 +02:00
type: PenpotTrackType;
2024-06-10 14:23:36 +02:00
/**
* The value of the track.
* This can be a number representing the size of the track, or null if not applicable.
*/
2024-05-08 16:56:34 +02:00
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
/**
2024-06-10 14:23:36 +02:00
* Represents a flexible layout configuration in Penpot.
* This interface extends `PenpotCommonLayout` and includes properties for defining the direction,
* wrapping behavior, and child management of a flex layout.
2024-06-07 11:35:38 +02:00
*/
export interface PenpotFlexLayout extends PenpotCommonLayout {
2024-06-10 14:23:36 +02:00
/**
* The direction of the flex layout.
* - 'row': Main axis is horizontal, from left to right.
* - 'row-reverse': Main axis is horizontal, from right to left.
* - 'column': Main axis is vertical, from top to bottom.
* - 'column-reverse': Main axis is vertical, from bottom to top.
*/
dir: 'row' | 'row-reverse' | 'column' | 'column-reverse';
2024-06-10 14:23:36 +02:00
/**
* The optional wrapping behavior of the flex layout.
* - 'wrap': Child elements will wrap onto multiple lines.
* - 'nowrap': Child elements will not wrap.
*/
wrap?: 'wrap' | 'nowrap';
2024-06-10 14:23:36 +02:00
/**
* Appends a child element to the flex layout.
* @param child The child element to be appended, of type `PenpotShape`.
*/
appendChild(child: PenpotShape): void;
2024-05-08 16:56:34 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a path command in Penpot.
* This interface includes a property for defining the type of command.
2024-06-07 11:35:38 +02:00
*/
2024-06-03 16:25:20 +02:00
interface PenpotPathCommand {
2024-06-10 14:23:36 +02:00
/**
* The type of path command.
* Possible values include:
* - 'M' or 'move-to': Move to a new point.
* - 'Z' or 'close-path': Close the current path.
* - 'L' or 'line-to': Draw a straight line to a new point.
* - 'H' or 'line-to-horizontal': Draw a horizontal line to a new point.
* - 'V' or 'line-to-vertical': Draw a vertical line to a new point.
* - 'C' or 'curve-to': Draw a cubic Bezier curve to a new point.
* - 'S' or 'smooth-curve-to': Draw a smooth cubic Bezier curve to a new point.
* - 'Q' or 'quadratic-bezier-curve-to': Draw a quadratic Bezier curve to a new point.
* - 'T' or 'smooth-quadratic-bezier-curve-to': Draw a smooth quadratic Bezier curve to a new point.
* - 'A' or 'elliptical-arc': Draw an elliptical arc to a new point.
*/
2024-06-03 16:25:20 +02:00
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';
2024-06-10 14:23:36 +02:00
/**
* Optional parameters associated with the path command.
*/
2024-06-03 16:25:20 +02:00
params?: {
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the point (or endpoint).
*/
2024-06-03 16:25:20 +02:00
x?: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the point (or endpoint).
*/
2024-06-03 16:25:20 +02:00
y?: number;
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the first control point for curves.
*/
2024-06-03 16:25:20 +02:00
c1x: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the first control point for curves.
*/
2024-06-03 16:25:20 +02:00
c1y: number;
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the second control point for curves.
*/
2024-06-03 16:25:20 +02:00
c2x: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the second control point for curves.
*/
2024-06-03 16:25:20 +02:00
c2y: number;
2024-06-10 14:23:36 +02:00
/**
* The radius of the ellipse's x-axis.
*/
2024-06-03 16:25:20 +02:00
rx?: number;
2024-06-10 14:23:36 +02:00
/**
* The radius of the ellipse's y-axis.
*/
2024-06-03 16:25:20 +02:00
ry?: number;
2024-06-10 14:23:36 +02:00
/**
* The rotation angle of the ellipse's x-axis.
*/
2024-06-03 16:25:20 +02:00
xAxisRotation?: number;
2024-06-10 14:23:36 +02:00
/**
* A flag indicating whether to use the larger arc.
*/
2024-06-03 16:25:20 +02:00
largeArcFlag?: boolean;
2024-06-10 14:23:36 +02:00
/**
* A flag indicating the direction of the arc.
*/
2024-06-03 16:25:20 +02:00
sweepFlag?: boolean;
};
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the base properties and methods of a shape in Penpot.
* This interface provides common properties and methods shared by all shapes.
2024-06-07 11:35:38 +02:00
*/
2024-06-06 09:36:03 +02:00
export interface PenpotShapeBase extends PenpotPluginData {
2024-06-10 14:23:36 +02:00
/**
* The unique identifier of the shape.
*/
2024-02-28 12:54:37 +01:00
id: string;
2024-06-10 14:23:36 +02:00
/**
* The name of the shape.
*/
2024-04-15 16:13:29 +02:00
name: string;
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the shape's position.
*/
x: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the shape's position.
*/
y: number;
2024-06-10 14:23:36 +02:00
/**
* The width of the shape.
*/
width: number;
2024-06-10 14:23:36 +02:00
/**
* The height of the shape.
*/
height: number;
2024-04-22 16:02:06 +02:00
2024-06-10 14:23:36 +02:00
/**
* Indicates whether the shape is blocked.
*/
2024-05-08 16:56:34 +02:00
blocked: boolean;
2024-06-10 14:23:36 +02:00
/**
* Indicates whether the shape is hidden.
*/
2024-05-08 16:56:34 +02:00
hidden: boolean;
2024-06-10 14:23:36 +02:00
/**
* Indicates whether the shape has proportion lock enabled.
*/
2024-05-08 16:56:34 +02:00
proportionLock: boolean;
2024-06-10 14:23:36 +02:00
/**
* The horizontal constraints applied to the shape.
*/
2024-05-08 16:56:34 +02:00
constraintsHorizontal: 'left' | 'right' | 'leftright' | 'center' | 'scale';
2024-06-10 14:23:36 +02:00
/**
* The vertical constraints applied to the shape.
*/
2024-05-08 16:56:34 +02:00
constraintsVertical: 'top' | 'bottom' | 'topbottom' | 'center' | 'scale';
2024-06-10 14:23:36 +02:00
/**
* The border radius of the shape.
*/
2024-05-08 16:56:34 +02:00
borderRadius: number;
2024-06-10 14:23:36 +02:00
/**
* The border radius of the top-left corner of the shape.
*/
2024-05-08 16:56:34 +02:00
borderRadiusTopLeft: number;
2024-06-10 14:23:36 +02:00
/**
* The border radius of the top-right corner of the shape.
*/
2024-05-08 16:56:34 +02:00
borderRadiusTopRight: number;
2024-06-10 14:23:36 +02:00
/**
* The border radius of the bottom-right corner of the shape.
*/
2024-05-08 16:56:34 +02:00
borderRadiusBottomRight: number;
2024-06-10 14:23:36 +02:00
/**
* The border radius of the bottom-left corner of the shape.
*/
2024-05-08 16:56:34 +02:00
borderRadiusBottomLeft: number;
2024-06-10 14:23:36 +02:00
/**
* The opacity of the shape.
*/
2024-05-08 16:56:34 +02:00
opacity: number;
2024-06-10 14:23:36 +02:00
/**
* The blend mode applied to the shape.
*/
2024-05-08 16:56:34 +02:00
blendMode:
| 'normal'
| 'darken'
| 'multiply'
| 'color-burn'
| 'lighten'
| 'screen'
| 'color-dodge'
| 'overlay'
| 'soft-light'
| 'hard-light'
| 'difference'
| 'exclusion'
| 'hue'
| 'saturation'
| 'color'
| 'luminosity';
2024-06-10 14:23:36 +02:00
/**
* The shadows applied to the shape.
*/
2024-05-08 16:56:34 +02:00
shadows: PenpotShadow[];
2024-06-10 14:23:36 +02:00
/**
* The blur effect applied to the shape.
*/
2024-05-27 13:12:20 +02:00
blur?: PenpotBlur;
2024-06-10 14:23:36 +02:00
/**
* The export settings of the shape.
*/
2024-05-08 16:56:34 +02:00
exports: PenpotExport;
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the shape relative to its frame.
*/
2024-05-08 16:56:34 +02:00
frameX: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the shape relative to its frame.
*/
2024-05-08 16:56:34 +02:00
frameY: number;
2024-06-10 14:23:36 +02:00
/**
* The x-coordinate of the shape relative to its parent.
*/
2024-05-08 16:56:34 +02:00
parentX: number;
2024-06-10 14:23:36 +02:00
/**
* The y-coordinate of the shape relative to its parent.
*/
2024-05-08 16:56:34 +02:00
parentY: number;
2024-06-10 14:23:36 +02:00
/**
* Indicates whether the shape is flipped horizontally.
*/
2024-05-08 16:56:34 +02:00
flipX: boolean;
2024-06-10 14:23:36 +02:00
/**
* Indicates whether the shape is flipped vertically.
*/
2024-05-08 16:56:34 +02:00
flipY: boolean;
2024-06-10 14:23:36 +02:00
/**
* The fills applied to the shape.
*/
fills: PenpotFill[];
2024-06-10 14:23:36 +02:00
/**
* The strokes applied to the shape.
*/
strokes: PenpotStroke[];
2024-04-22 16:02:06 +02:00
2024-06-10 14:23:36 +02:00
/**
* Layout properties for children of the shape.
*/
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;
};
2024-06-10 14:23:36 +02:00
/**
* Layout properties for cells in a grid layout.
*/
readonly layoutCell?: {
row?: number;
rowSpan?: number;
column?: number;
columnSpan?: number;
areaName?: string;
position?: 'auto' | 'manual' | 'area';
};
2024-06-10 14:23:36 +02:00
/**
* Resizes the shape to the specified width and height.
* @param width The new width of the shape.
* @param height The new height of the shape.
*/
resize(width: number, height: number): void;
2024-05-27 13:12:20 +02:00
2024-06-10 14:23:36 +02:00
/**
* Creates a clone of the shape.
* Returns a new instance of the shape with identical properties.
*/
2024-05-08 16:56:34 +02:00
clone(): PenpotShape;
2024-06-10 14:23:36 +02:00
/**
* Removes the shape from its parent.
*/
remove(): void;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame in Penpot.
* This interface extends `PenpotShapeBase` and includes properties and methods specific to frames.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotFrame extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'frame' for frames.
*/
2024-04-22 16:02:06 +02:00
readonly type: 'frame';
2024-06-10 14:23:36 +02:00
/**
* The grid layout configuration of the frame, if applicable.
*/
2024-05-08 16:56:34 +02:00
readonly grid?: PenpotGridLayout;
2024-06-10 14:23:36 +02:00
/**
* The flex layout configuration of the frame, if applicable.
*/
readonly flex?: PenpotFlexLayout;
2024-06-10 14:23:36 +02:00
/**
* The guides associated with the frame.
*/
2024-05-08 16:56:34 +02:00
guides: PenpotFrameGuide;
2024-06-10 14:23:36 +02:00
/**
* The horizontal sizing behavior of the frame.
*/
horizontalSizing?: 'auto' | 'fix';
2024-06-10 14:23:36 +02:00
/**
* The vertical sizing behavior of the frame.
*/
verticalSizing?: 'auto' | 'fix';
// Container Properties
2024-06-10 14:23:36 +02:00
/**
* The children shapes contained within the frame.
*/
readonly children: PenpotShape[];
2024-06-10 14:23:36 +02:00
/**
* Appends a child shape to the frame.
* @param child The child shape to append.
*/
appendChild(child: PenpotShape): void;
2024-06-10 14:23:36 +02:00
/**
* Inserts a child shape at the specified index within the frame.
* @param index The index at which to insert the child shape.
* @param child The child shape to insert.
*/
insertChild(index: number, child: PenpotShape): void;
// Grid layout
2024-06-10 14:23:36 +02:00
/**
* Adds a flex layout configuration to the frame.
* Returns the flex layout configuration added to the frame.
*/
addFlexLayout(): PenpotFlexLayout;
2024-06-10 14:23:36 +02:00
/**
* Adds a grid layout configuration to the frame.
* Returns the grid layout configuration added to the frame.
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents a group of shapes in Penpot.
* This interface extends `PenpotShapeBase` and includes properties and methods specific to groups.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotGroup extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'group' for groups.
*/
2024-04-22 16:02:06 +02:00
readonly type: 'group';
// Container Properties
2024-06-10 14:23:36 +02:00
/**
* The children shapes contained within the group.
*/
2024-04-22 16:02:06 +02:00
readonly children: PenpotShape[];
2024-06-10 14:23:36 +02:00
/**
* Appends a child shape to the group.
* @param child The child shape to append.
*/
appendChild(child: PenpotShape): void;
2024-06-10 14:23:36 +02:00
/**
* Inserts a child shape at the specified index within the group.
* @param index The index at which to insert the child shape.
* @param child The child shape to insert.
*/
insertChild(index: number, child: PenpotShape): void;
2024-06-10 14:23:36 +02:00
/**
* Converts the group into a mask.
*/
2024-06-03 16:25:20 +02:00
makeMask(): void;
2024-06-10 14:23:36 +02:00
/**
* Removes the mask from the group.
*/
2024-06-03 16:25:20 +02:00
removeMask(): void;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the boolean operation types available in Penpot.
* These types define how shapes can be combined or modified using boolean operations.
2024-06-07 11:35:38 +02:00
*/
2024-06-03 16:25:20 +02:00
export type PenpotBoolType =
| 'union'
| 'difference'
| 'exclude'
| 'intersection';
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a boolean operation shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties and methods specific to boolean operations.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotBool extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'bool' for boolean operation shapes.
*/
2024-04-22 16:02:06 +02:00
readonly type: 'bool';
2024-06-10 14:23:36 +02:00
/**
* Converts the boolean shape to its path data representation.
* Returns the path data (d attribute) as a string.
*/
2024-06-03 16:25:20 +02:00
toD(): string;
2024-06-10 14:23:36 +02:00
/**
* The content of the boolean shape, defined as an array of path commands.
*/
2024-06-03 16:25:20 +02:00
content: Array<PenpotPathCommand>;
// Container Properties
2024-06-10 14:23:36 +02:00
/**
* The children shapes contained within the boolean shape.
*/
2024-04-22 16:02:06 +02:00
readonly children: PenpotShape[];
2024-06-10 14:23:36 +02:00
/**
* Appends a child shape to the boolean shape.
* @param child The child shape to append.
*/
appendChild(child: PenpotShape): void;
2024-06-10 14:23:36 +02:00
/**
* Inserts a child shape at the specified index within the boolean shape.
* @param index The index at which to insert the child shape.
* @param child The child shape to insert.
*/
insertChild(index: number, child: PenpotShape): void;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a rectangle shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties specific to rectangles.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotRectangle extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'rect' for rectangle shapes.
*/
2024-04-22 16:02:06 +02:00
readonly type: 'rect';
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a path shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties and methods specific to paths.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotPath extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'path' for path shapes.
*/
2024-06-03 16:25:20 +02:00
readonly type: 'path';
2024-06-10 14:23:36 +02:00
/**
* Converts the path shape to its path data representation.
* Returns the path data (d attribute) as a string.
*/
2024-06-03 16:25:20 +02:00
toD(): string;
2024-06-10 14:23:36 +02:00
/**
* The content of the path shape, defined as an array of path commands.
*/
2024-06-03 16:25:20 +02:00
content: Array<PenpotPathCommand>;
2024-04-22 16:02:06 +02:00
}
2024-06-06 09:36:03 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a range of text within a PenpotText shape.
* This interface provides properties for styling and formatting text ranges.
2024-06-06 09:36:03 +02:00
*/
export interface PenpotTextRange {
2024-06-10 14:23:36 +02:00
/**
* The PenpotText shape to which this text range belongs.
*/
2024-06-06 09:36:03 +02:00
shape: PenpotText;
2024-06-10 14:23:36 +02:00
/**
* The font ID of the text range. It can be a specific font ID or 'mixed' if multiple fonts are used.
*/
2024-06-06 09:36:03 +02:00
fontId: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font family of the text range. It can be a specific font family or 'mixed' if multiple font families are used.
*/
2024-06-06 09:36:03 +02:00
fontFamily: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font variant ID of the text range. It can be a specific font variant ID or 'mixed' if multiple font variants are used.
*/
2024-06-06 09:36:03 +02:00
fontVariantId: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font size of the text range. It can be a specific font size or 'mixed' if multiple font sizes are used.
*/
2024-06-06 09:36:03 +02:00
fontSize: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font weight of the text range. It can be a specific font weight or 'mixed' if multiple font weights are used.
*/
2024-06-06 09:36:03 +02:00
fontWeight: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font style of the text range. It can be a specific font style or 'mixed' if multiple font styles are used.
*/
2024-06-06 09:36:03 +02:00
fontStyle: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The line height of the text range. It can be a specific line height or 'mixed' if multiple line heights are used.
*/
2024-06-06 09:36:03 +02:00
lineHeight: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The letter spacing of the text range. It can be a specific letter spacing or 'mixed' if multiple letter spacings are used.
*/
2024-06-06 09:36:03 +02:00
letterSpacing: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The text transform applied to the text range. It can be a specific text transform or 'mixed' if multiple text transforms are used.
*/
2024-06-06 09:36:03 +02:00
textTransform: string | 'mixed';
}
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 {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'text' for text shapes.
*/
2024-04-22 16:02:06 +02:00
readonly type: 'text';
2024-06-10 14:23:36 +02:00
/**
* The characters contained within the text shape.
*/
2024-04-22 16:02:06 +02:00
characters: string;
2024-06-10 14:23:36 +02:00
/**
* The grow type of the text shape, defining how the text box adjusts its size.
* Possible values are:
* - 'fixed': Fixed size.
* - 'auto-width': Adjusts width automatically.
* - 'auto-height': Adjusts height automatically.
*/
2024-05-08 16:56:34 +02:00
growType: 'fixed' | 'auto-width' | 'auto-height';
2024-05-27 17:44:42 +02:00
2024-06-10 14:23:36 +02:00
/**
* The font ID used in the text shape, or 'mixed' if multiple fonts are used.
*/
2024-05-27 17:44:42 +02:00
fontId: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font family used in the text shape, or 'mixed' if multiple font families are used.
*/
2024-05-27 17:44:42 +02:00
fontFamily: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font variant ID used in the text shape, or 'mixed' if multiple font variants are used.
*/
2024-05-27 17:44:42 +02:00
fontVariantId: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font size used in the text shape, or 'mixed' if multiple font sizes are used.
*/
2024-05-27 17:44:42 +02:00
fontSize: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font weight used in the text shape, or 'mixed' if multiple font weights are used.
*/
2024-05-27 17:44:42 +02:00
fontWeight: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The font style used in the text shape, or 'mixed' if multiple font styles are used.
*/
2024-05-27 17:44:42 +02:00
fontStyle: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The line height used in the text shape, or 'mixed' if multiple line heights are used.
*/
2024-05-27 17:44:42 +02:00
lineHeight: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The letter spacing used in the text shape, or 'mixed' if multiple letter spacings are used.
*/
2024-05-27 17:44:42 +02:00
letterSpacing: string | 'mixed';
2024-06-10 14:23:36 +02:00
/**
* The text transform applied to the text shape, or 'mixed' if multiple text transforms are used.
*/
2024-05-27 17:44:42 +02:00
textTransform: string | 'mixed';
2024-06-06 09:36:03 +02:00
getRange(start: number, end: number): PenpotTextRange;
2024-04-22 16:02:06 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a frame shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties specific to frames.
2024-06-07 11:35:38 +02:00
*/
2024-05-07 10:28:40 +02:00
export interface PepotFrame extends PenpotShapeBase {
2024-06-10 14:23:36 +02:00
/**
* The type of the shape, which is always 'frame' for frame shapes.
*/
2024-05-07 10:28:40 +02:00
readonly type: 'frame';
2024-06-10 14:23:36 +02:00
/**
* The children shapes contained within the frame.
*/
2024-05-07 10:28:40 +02:00
readonly children: PenpotShape[];
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents an ellipse shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties specific to ellipses.
2024-06-07 11:35:38 +02:00
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents an SVG raw shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties specific to raw SVG shapes.
2024-06-07 11:35:38 +02:00
*/
2024-04-22 16:02:06 +02:00
export interface PenpotSvgRaw extends PenpotShapeBase {
type: 'svg-raw';
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents an image shape in Penpot.
* This interface extends `PenpotShapeBase` and includes properties specific to image shapes.
2024-06-07 11:35:38 +02:00
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents a mapping of events to their corresponding types in Penpot.
* This interface provides information about various events that can be triggered in the application.
2024-06-07 11:35:38 +02:00
*/
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
/**
2024-06-10 14:23:36 +02:00
* This type specifies the possible themes: 'light' or 'dark'.
2024-06-07 11:35:38 +02:00
*/
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
/**
2024-06-10 14:23:36 +02:00
* Represents an element in a Penpot library.
* This interface provides information about a specific element in a library.
2024-06-07 11:35:38 +02:00
*/
2024-06-06 09:36:03 +02:00
export interface PenpotLibraryElement extends PenpotPluginData {
2024-06-10 14:23:36 +02:00
/**
* The unique identifier of the library element.
*/
2024-05-30 09:29:44 +02:00
readonly id: string;
2024-06-10 14:23:36 +02:00
/**
* The unique identifier of the library to which the element belongs.
*/
2024-05-30 09:29:44 +02:00
readonly libraryId: string;
2024-06-10 14:23:36 +02:00
/**
* The name of the library element.
*/
name: string;
2024-06-10 14:23:36 +02:00
/**
* The path of the library element.
*/
2024-05-27 13:12:20 +02:00
path: string;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a color element from a library in Penpot.
* This interface extends `PenpotLibraryElement` and includes properties specific to color elements.
2024-06-07 11:35:38 +02:00
*/
2024-05-27 13:12:20 +02:00
export interface PenpotLibraryColor extends PenpotLibraryElement {
2024-06-10 14:23:36 +02:00
/**
* The color value of the library color.
*/
color?: string;
2024-06-10 14:23:36 +02:00
/**
* The opacity value of the library color.
*/
opacity?: number;
2024-06-10 14:23:36 +02:00
/**
* The gradient value of the library color, if it's a gradient.
*/
gradient?: PenpotGradient;
2024-06-10 14:23:36 +02:00
/**
* The image data of the library color, if it's an image fill.
*/
image?: PenpotImageData;
2024-05-27 13:12:20 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Converts the library color into a fill object.
* Returns a `PenpotFill` object representing the color as a fill.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const fill = libraryColor.asFill();
2024-06-07 11:35:38 +02:00
* ```
*/
asFill(): PenpotFill;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Converts the library color into a stroke object.
* Returns a `PenpotStroke` object representing the color as a stroke.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const stroke = libraryColor.asStroke();
2024-06-07 11:35:38 +02:00
* ```
*/
asStroke(): PenpotStroke;
2024-05-27 13:12:20 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a typography element from a library in Penpot.
* This interface extends `PenpotLibraryElement` and includes properties specific to typography elements.
2024-06-07 11:35:38 +02:00
*/
2024-05-27 13:12:20 +02:00
export interface PenpotLibraryTypography extends PenpotLibraryElement {
2024-06-10 14:23:36 +02:00
/**
* The unique identifier of the font used in the typography element.
*/
2024-05-27 13:12:20 +02:00
fontId: string;
2024-06-10 14:23:36 +02:00
/**
* The font family of the typography element.
*/
2024-05-27 13:12:20 +02:00
fontFamily: string;
2024-06-10 14:23:36 +02:00
/**
* The unique identifier of the font variant used in the typography element.
*/
2024-05-27 13:12:20 +02:00
fontVariantId: string;
2024-06-10 14:23:36 +02:00
/**
* The font size of the typography element.
*/
2024-05-27 13:12:20 +02:00
fontSize: string;
2024-06-10 14:23:36 +02:00
/**
* The font weight of the typography element.
*/
2024-05-27 13:12:20 +02:00
fontWeight: string;
2024-06-10 14:23:36 +02:00
/**
* The font style of the typography element.
*/
2024-05-27 13:12:20 +02:00
fontStyle: string;
2024-06-10 14:23:36 +02:00
/**
* The line height of the typography element.
*/
2024-05-27 13:12:20 +02:00
lineHeight: string;
2024-06-10 14:23:36 +02:00
/**
* The letter spacing of the typography element.
*/
2024-05-27 13:12:20 +02:00
letterSpacing: string;
2024-06-10 14:23:36 +02:00
/**
* The text transform applied to the typography element.
*/
2024-05-27 13:12:20 +02:00
textTransform: string;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Applies the typography styles to a text shape.
* @param shape The text shape to apply the typography styles to.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* typographyElement.applyToText(textShape);
2024-06-07 11:35:38 +02:00
* ```
*/
2024-05-27 13:12:20 +02:00
applyToText(shape: PenpotShape): void;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Applies the typography styles to a range of text within a text shape.
* @param shape The text shape containing the text range to apply the typography styles to.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* typographyElement.applyToTextRange(textShape);
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-06 09:36:03 +02:00
applyToTextRange(range: PenpotTextRange): void;
2024-05-27 13:12:20 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a component element from a library in Penpot.
* This interface extends `PenpotLibraryElement` and includes properties specific to component elements.
2024-06-07 11:35:38 +02:00
*/
export interface PenpotLibraryComponent extends PenpotLibraryElement {
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates an instance of the component.
* Returns a `PenpotShape` object representing the instance of the component.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const componentInstance = libraryComponent.instance();
2024-06-07 11:35:38 +02:00
* ```
*/
instance(): PenpotShape;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a library in Penpot, containing colors, typographies, and components.
* This type provides methods to create new color, typography, and component elements within the library.
2024-06-07 11:35:38 +02:00
*/
2024-06-06 09:36:03 +02:00
export interface PenpotLibrary extends PenpotPluginData {
2024-06-10 14:23:36 +02:00
/**
* An array of color elements in the library.
*/
colors: PenpotLibraryColor[];
2024-06-10 14:23:36 +02:00
/**
* An array of typography elements in the library.
*/
typographies: PenpotLibraryTypography[];
2024-06-10 14:23:36 +02:00
/**
* An array of component elements in the library.
*/
components: PenpotLibraryComponent[];
2024-05-30 09:29:44 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates a new color element in the library.
* Returns a new `PenpotLibraryColor` object representing the created color element.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const newColor = library.createColor();
2024-06-07 11:35:38 +02:00
* ```
*/
createColor(): PenpotLibraryColor;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates a new typography element in the library.
* Returns a new `PenpotLibraryTypography` object representing the created typography element.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const newTypography = library.createTypography();
2024-06-07 11:35:38 +02:00
* ```
*/
createTypography(): PenpotLibraryTypography;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates a new component element in the library using the provided shapes.
* @param shapes An array of `PenpotShape` objects representing the shapes to be included in the component.
* Returns a new `PenpotLibraryComponent` object representing the created component element.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const newComponent = library.createComponent([shape1, shape2]);
2024-06-07 11:35:38 +02:00
* ```
*/
createComponent(shapes: PenpotShape[]): PenpotLibraryComponent;
2024-06-06 09:36:03 +02:00
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the context of Penpot libraries, including both local and connected libraries.
* This type contains references to the local library and an array of connected libraries.
2024-06-07 11:35:38 +02:00
*/
export type PenpotLibraryContext = {
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The local library in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const localLibrary = libraryContext.local;
2024-06-07 11:35:38 +02:00
* ```
*/
local: PenpotLibrary;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* An array of connected libraries in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const connectedLibraries = libraryContext.connected;
2024-06-07 11:35:38 +02:00
* ```
*/
connected: PenpotLibrary[];
};
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents a user in Penpot.
2024-06-07 11:35:38 +02:00
*/
2024-06-04 17:35:39 +02:00
export interface PenpotUser {
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The unique identifier of the user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const userId = user.id;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly id: string;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The name of the user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const userName = user.name;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly name?: string;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The URL of the user's avatar image.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const avatarUrl = user.avatarUrl;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly avatarUrl?: string;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The color associated with the user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const userColor = user.color;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly color: string;
2024-06-10 14:23:36 +02:00
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The session ID of the user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const sessionId = user.sessionId;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly sessionId?: string;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents an active user in Penpot, extending the `PenpotUser` interface.
* This interface includes additional properties specific to active users.
2024-06-07 11:35:38 +02:00
*/
2024-06-04 17:35:39 +02:00
export interface PenpotActiveUser extends PenpotUser {
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The position of the active user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const userPosition = activeUser.position;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-10 14:23:36 +02:00
position?: { x: number; y: number };
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The zoom level of the active user.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const userZoom = activeUser.zoom;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly zoom?: number;
}
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Represents the context of Penpot, providing access to various Penpot functionalities and data.
2024-06-07 11:35:38 +02:00
*/
export interface PenpotContext {
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The root shape in the current Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const rootShape = context.root;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly root: PenpotShape;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The current page in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const currentPage = context.currentPage;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly currentPage: PenpotPage;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The viewport settings in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const viewportSettings = context.viewport;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly viewport: PenpotViewport;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The library context in the Penpot context, including both local and connected libraries.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const libraryContext = context.library;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly library: PenpotLibraryContext;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The current user in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const currentUser = context.currentUser;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly currentUser: PenpotUser;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* An array of active users in the Penpot context.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const activeUsers = context.activeUsers;
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-04 17:35:39 +02:00
readonly activeUsers: PenpotActiveUser;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* The currently selected shapes in Penpot.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const selectedShapes = context.selection;
2024-06-07 11:35:38 +02:00
* ```
*/
selection: PenpotShape[];
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Retrieves file data from the current Penpot context.
* Returns the file data or `null` if no file is available.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const fileData = context.getFile();
2024-06-07 11:35:38 +02:00
* ```
*/
getFile(): PenpotFile | null;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Retrieves page data from the current Penpot context.
* Returns the page data or `null` if no page is available.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const pageData = context.getPage();
2024-06-07 11:35:38 +02:00
* ```
*/
getPage(): PenpotPage | null;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Retrieves the IDs of the currently selected elements in Penpot.
* Returns an array of IDs representing the selected elements.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const selectedIds = context.getSelected();
2024-06-07 11:35:38 +02:00
* ```
*/
getSelected(): string[];
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Retrieves the shapes of the currently selected elements in Penpot.
* Returns an array of shapes representing the selected elements.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const selectedShapes = context.getSelectedShapes();
2024-06-07 11:35:38 +02:00
* ```
*/
getSelectedShapes(): PenpotShape[];
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Retrieves the current theme (light or dark) in Penpot.
* Returns the current theme.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const currentTheme = context.getTheme();
2024-06-07 11:35:38 +02:00
* ```
*/
getTheme(): PenpotTheme;
2024-06-10 14:23:36 +02:00
/**
* Uploads media to Penpot and retrieves its image data.
* @param name The name of the media.
* @param url The URL of the media to be uploaded.
* Returns a promise that resolves to the image data of the uploaded media.
* @example
* ```js
* const imageData = await context.uploadMediaUrl('example', 'https://example.com/image.jpg');
* ```
*/
2024-04-29 12:24:38 +02:00
uploadMediaUrl(name: string, url: string): Promise<PenpotImageData>;
2024-06-10 14:23:36 +02:00
// Methods for creating shapes and components
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
/**
2024-06-10 14:23:36 +02:00
* Creates a PenpotBoolean shape based on the specified boolean operation and shapes.
* @param boolType The type of boolean operation ('union', 'difference', 'exclude', 'intersection').
* @param shapes An array of shapes to perform the boolean operation on.
* Returns the newly created PenpotBoolean shape resulting from the boolean operation.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const booleanShape = context.createBoolean('union', [shape1, shape2]);
2024-06-07 11:35:38 +02:00
* ```
*/
2024-06-03 16:25:20 +02:00
createBoolean(boolType: PenpotBoolType, shapes: PenpotShape[]): PenpotBool;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates a PenpotGroup from an SVG string.
* @param svgString The SVG string representing the shapes to be converted into a group.
* Returns the newly created PenpotGroup containing the shapes from the SVG.
2024-06-07 11:35:38 +02:00
* @example
* ```js
2024-06-10 14:23:36 +02:00
* const svgGroup = context.createShapeFromSvg('<svg>...</svg>');
2024-06-07 11:35:38 +02:00
* ```
*/
createShapeFromSvg(svgString: string): PenpotGroup;
2024-06-07 11:35:38 +02:00
/**
2024-06-10 14:23:36 +02:00
* Creates a PenpotText shape with the specified text content.
* @param text The text content for the PenpotText shape.
2024-06-07 11:35:38 +02:00
* @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-10 14:23:36 +02:00
// Event listeners
addListener<T extends keyof EventsMap>(
type: T,
callback: (event: EventsMap[T]) => void
): symbol;
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-10 14:23:36 +02:00
* Sends a message to the plugin UI.
2024-06-07 11:35:38 +02:00
*
* @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
/**
2024-06-10 14:23:36 +02:00
* Adds an event listener for the specified event type.
*
* @param type The event type to listen for.
* @param callback The callback function to execute when the event is triggered.
2024-06-07 11:35:38 +02:00
*
* @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
/**
2024-06-10 14:23:36 +02:00
* Removes an event listener for the specified event type.
*
* @param type The event type to stop listening for.
* @param callback The callback function to remove.
2024-06-07 11:35:38 +02:00
*
* @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;
}