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.
title of the plugin, it'll be displayed on the top of the modal
of the plugin
Optional
options: { height and width of the modal.
Sends a message to the plugin UI.
content usually is an object
This is usually used in the plugin.ts
file in order to handle the data sent by our plugin
Provides access to utility functions and context-specific operations.
Closes the plugin. When this method is called the UI will be closed.
Readonly
rootThe root shape in the current Penpot context. Requires content:read
permission.
Readonly
currentRetrieves file data from the current Penpot context. Requires content:read
permission.
Readonly
currentThe current page in the Penpot context. Requires content:read
permission.
Readonly
viewportThe viewport settings in the Penpot context.
Readonly
historyContext encapsulating the history operations
Readonly
libraryThe library context in the Penpot context, including both local and connected libraries. Requires library:read
permission.
Readonly
fontsThe fonts context in the Penpot context, providing methods to manage fonts. Requires content:read
permission.
Readonly
currentThe current user in the Penpot context. Requires user:read
permission.
Readonly
activeAn array of active users in the Penpot context. Requires user:read
permission.
Readonly
themeThe current theme (light or dark) in Penpot.
The currently selected shapes in Penpot. Requires content:read
permission.
Adds an event listener for the specified event type.
Subscribing to events requires content:read
permission.
The following are the posible event types:
props
object the shape
that will be observed. For example:// Observe the current selected shape
penpot.on('shapechange', (shape) => console.log(shape.name), { shapeId: penpot.selection[0].id });
dark
or light
)The event type to listen for.
The callback function to execute when the event is triggered.
Optional
props: { The properties for the current event handler. Only makes sense for specific events.
the listener id that can be used to call off
and cancel the listener
Retrieves colors applied to the given shapes in Penpot. Requires content:read
permission.
Returns an array of colors and their shape information.
Uploads media to Penpot and retrieves its image data. Requires content:write
permission.
The name of the media.
The URL of the media to be uploaded.
Returns a promise that resolves to the image data of the uploaded media.
const imageData = await context.uploadMediaUrl('example', 'https://example.com/image.jpg');
console.log(imageData);
// to insert the image in a shape we can do
const board = penpot.createBoard();
const shape = penpot.createRectangle();
board.appendChild(shape);
shape.fills = [{ fillOpacity: 1, fillImage: imageData }];
Uploads media to penpot and retrieves the image data. Requires content:write
permission.
The name of the media.
The image content data
Returns a promise that resolves to the image data of the uploaded media.
Use this method to create the shape of a rectangle. Requires content:write
permission.
const shape = penpot.createRectangle();
// just change the values like this
shape.name = "Example rectangle";
// for solid color
shape.fills = [{ fillColor: "#7EFFF5" }];
// for linear gradient color
shape.fills = [{
fillColorGradient: {
"type": "linear",
"startX": 0.5,
"startY": 0,
"endX": 0.5,
"endY": 1,
"width": 1,
"stops": [
{
"color": "#003ae9",
"opacity": 1,
"offset": 0
},
{
"color": "#003ae9",
"opacity": 0,
"offset": 1
}
]
}
}];
// for a image fill
const imageData = await context.uploadMediaUrl('example', 'https://example.com/image.jpg');
shape.fills = [{ fillOpacity: 1, fillImage: imageData }];
shape.borderRadius = 8;
shape.strokes = [
{
strokeColor: "#2e3434",
strokeStyle: "solid",
strokeWidth: 2,
strokeAlignment: "center",
},
];
Use this method to create the shape of a ellipse. Requires content:write
permission.
const shape = penpot.createEllipse();
// just change the values like this
shape.name = "Example ellipse";
// for solid color
shape.fills = [{ fillColor: "#7EFFF5" }];
// for linear gradient color
shape.fills = [{
fillColorGradient: {
"type": "linear",
"startX": 0.5,
"startY": 0,
"endX": 0.5,
"endY": 1,
"width": 1,
"stops": [
{
"color": "#003ae9",
"opacity": 1,
"offset": 0
},
{
"color": "#003ae9",
"opacity": 0,
"offset": 1
}
]
}
}];
// for a image fill
const imageData = await context.uploadMediaUrl('example', 'https://example.com/image.jpg');
shape.fills = [{ fillOpacity: 1, fillImage: imageData }];
shape.strokes = [
{
strokeColor: "#2e3434",
strokeStyle: "solid",
strokeWidth: 2,
strokeAlignment: "center",
},
];
Creates a Boolean shape based on the specified boolean operation and shapes. Requires content:write
permission.
The type of boolean operation ('union', 'difference', 'exclude', 'intersection').
An array of shapes to perform the boolean operation on.
Returns the newly created Boolean shape resulting from the boolean operation.
Creates a Text shape with the specified text content. Requires content:write
permission.
The text content for the Text shape.
Returns the new created shape, if the shape wasn't created can return null.
const board = penpot.createBoard();
let text;
text = penpot.createText();
// just change the values like this
text.growType = 'auto-height';
text.fontFamily = 'Work Sans';
text.fontSize = '12';
text.fills = [{fillColor: '#9f05ff', fillOpacity: 1}];
text.strokes = [{strokeOpacity: 1, strokeStyle: 'solid', strokeWidth: 2, strokeColor: '#deabff', strokeAlignment: 'outer'}];
board.appendChild(text);
Generates markup for the given shapes. Requires content:read
permission
Optional
options: { Optional
type?: "html" | "svg"Generates styles for the given shapes. Requires content:read
permission
Optional
options: { Optional
type?: "css"Optional
withOptional
includeChanges the current open page to given page. Requires content:read
permission.
the page to open
Aligning will move all the selected layers to a position relative to one of them in the horizontal direction.
to align
where the shapes will be aligned
Aligning will move all the selected layers to a position relative to one of them in the vertical direction.
to align
where the shapes will be aligned
Distributing objects to position them horizontally with equal distances between them.
to distribute
Distributing objects to position them vertically with equal distances between them.
to distribute
These are methods and properties available on the
penpot
global object.