Monorepo for Aesthetic.Computer aesthetic.computer
at main 107 lines 3.1 kB view raw
1// Reference: https://www.figma.com/plugin-docs/api/api-reference/ 2// TODO: At the moment audioWorklet along with microphone and camera are not working. 3// - Perhaps I could reach out to FigJam to fix some of these? 4// TODO: 1. Submit widget 5// - https://help.figma.com/hc/en-us/articles/360039958914 6// 2. Wire up widget so that it can have inputs 7// - https://www.figma.com/community/widget/1040013605559486449/Play-Button 8 9const { widget } = figma; 10const { 11 useEffect, 12 usePropertyMenu, 13 useSyncedState, 14 useWidgetId, 15 AutoLayout, 16 Text, 17} = widget; 18 19function Widget() { 20 const widgetId = useWidgetId(); 21 22 const [disk, setDisk] = useSyncedState("disk", "prompt"); 23 24 const diskOptions = [ 25 { option: "prompt", label: "Prompt" }, 26 { option: "spray", label: "Spray" }, 27 { option: "export", label: "Export" }, 28 ]; 29 30 usePropertyMenu( 31 [ 32 { 33 itemType: "dropdown", 34 propertyName: "disks", 35 tooltip: "Starting Disk", 36 selectedOption: disk, 37 options: diskOptions, 38 }, 39 ], 40 ({ propertyName, propertyValue }) => { 41 if (propertyName === "disks") setDisk(propertyValue); 42 } 43 ); 44 45 return ( 46 <AutoLayout 47 verticalAlignItems={"center"} 48 spacing={16} 49 padding={16} 50 cornerRadius={8} 51 fill={{ r: 0.8, g: 0.8, b: 0.9, a: 1 }} 52 stroke={{ r: 0.7, g: 0.7, b: 0.8, a: 1.0 }} 53 strokeWidth={6} 54 > 55 <Text 56 fontSize={32} 57 fill={{ r: 0, g: 0.7, b: 0, a: 1 }} 58 onClick={() => 59 new Promise((resolve) => { 60 // TODO: Read disk property value so that it can be autoselected. 61 62 figma.showUI(__html__); 63 64 // Send image data now. 65 const widgetNode = figma.getNodeById(widgetId) as WidgetNode; 66 67 const allConnectorNodes: ConnectorNode[] = 68 figma.currentPage.findAll((node) => { 69 return node.type === "CONNECTOR"; 70 }); 71 72 allConnectorNodes.forEach(async (cn) => { 73 // TODO: If end or start is widgetNode.id 74 // and the type is an image... then process it as 75 // an input (only use the first image). 76 77 console.log( 78 "Start:", 79 figma.getNodeById(cn.connectorStart.endpointNodeId) 80 ); 81 82 // TODO Unwrap this whole thing a bit. 83 const img = figma.getImageByHash( 84 figma.getNodeById(cn.connectorEnd.endpointNodeId).fills[0] 85 .imageHash 86 ); 87 88 const bytes = await img.getBytesAsync(); 89 figma.ui.postMessage({ type: "figma-image-input", bytes }); 90 }); 91 }) 92 } 93 > 94 95 </Text> 96 <Text 97 fontSize={32} 98 fill={{ r: 0.7, g: 0, b: 0, a: 1 }} 99 onClick={() => new Promise((resolve) => figma.closePlugin())} 100 > 101 102 </Text> 103 </AutoLayout> 104 ); 105} 106 107widget.register(Widget);