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.
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
Represents the context of Penpot, providing access to various Penpot functionalities and data.