From ac0290aca080cc1fbc6bcf2e7774b10cb1b5a8bd Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 15 Oct 2025 17:30:23 +0200 Subject: [PATCH] Add util functions getPageForShape and generateCss in an attempt to circumvent restrictions of penpot.generateStyle --- penpot-plugin/src/PenpotUtils.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 }); + } }