// Reference: https://www.figma.com/plugin-docs/api/api-reference/ // TODO: At the moment audioWorklet along with microphone and camera are not working. // - Perhaps I could reach out to FigJam to fix some of these? // TODO: 1. Submit widget // - https://help.figma.com/hc/en-us/articles/360039958914 // 2. Wire up widget so that it can have inputs // - https://www.figma.com/community/widget/1040013605559486449/Play-Button const { widget } = figma; const { useEffect, usePropertyMenu, useSyncedState, useWidgetId, AutoLayout, Text, } = widget; function Widget() { const widgetId = useWidgetId(); const [disk, setDisk] = useSyncedState("disk", "prompt"); const diskOptions = [ { option: "prompt", label: "Prompt" }, { option: "spray", label: "Spray" }, { option: "export", label: "Export" }, ]; usePropertyMenu( [ { itemType: "dropdown", propertyName: "disks", tooltip: "Starting Disk", selectedOption: disk, options: diskOptions, }, ], ({ propertyName, propertyValue }) => { if (propertyName === "disks") setDisk(propertyValue); } ); return ( new Promise((resolve) => { // TODO: Read disk property value so that it can be autoselected. figma.showUI(__html__); // Send image data now. const widgetNode = figma.getNodeById(widgetId) as WidgetNode; const allConnectorNodes: ConnectorNode[] = figma.currentPage.findAll((node) => { return node.type === "CONNECTOR"; }); allConnectorNodes.forEach(async (cn) => { // TODO: If end or start is widgetNode.id // and the type is an image... then process it as // an input (only use the first image). console.log( "Start:", figma.getNodeById(cn.connectorStart.endpointNodeId) ); // TODO Unwrap this whole thing a bit. const img = figma.getImageByHash( figma.getNodeById(cn.connectorEnd.endpointNodeId).fills[0] .imageHash ); const bytes = await img.getBytesAsync(); figma.ui.postMessage({ type: "figma-image-input", bytes }); }); }) } > ▶ new Promise((resolve) => figma.closePlugin())} > ■ ); } widget.register(Widget);