diff --git a/penpot-plugin/src/PenpotUtils.ts b/penpot-plugin/src/PenpotUtils.ts index d2a9070..f0c585e 100644 --- a/penpot-plugin/src/PenpotUtils.ts +++ b/penpot-plugin/src/PenpotUtils.ts @@ -121,4 +121,22 @@ export class PenpotUtils { public static getPageByName(name: string): Page | null { return this.findPage((page) => page.name.toLowerCase() === name.toLowerCase()); } + + public static getPageForShape(shape: Shape): Page | null { + for (const page of penpot.currentFile!.pages) { + if (page.getShapeById(shape.id)) { + return page; + } + } + return null; + } + + public static generateCss(shape: Shape): string { + const page = this.getPageForShape(shape); + if (!page) { + throw new Error("Shape is not part of any page"); + } + penpot.openPage(page); + return penpot.generateStyle([shape], { type: "css", includeChildren: true }); + } }