| 43 | }; |
| 44 | |
| 45 | function createIconElement(name: string, tone: "neutral" | "destructive"): SVGSVGElement | null { |
| 46 | const paths = ICON_PATHS[name]; |
| 47 | if (!paths) { |
| 48 | return null; |
| 49 | } |
| 50 | const svg = document.createElementNS(SVG_NS, "svg"); |
| 51 | svg.setAttribute("xmlns", SVG_NS); |
| 52 | svg.setAttribute("viewBox", "0 0 24 24"); |
| 53 | svg.setAttribute("fill", "none"); |
| 54 | svg.setAttribute("stroke", "currentColor"); |
| 55 | svg.setAttribute("stroke-width", "2"); |
| 56 | svg.setAttribute("stroke-linecap", "round"); |
| 57 | svg.setAttribute("stroke-linejoin", "round"); |
| 58 | svg.setAttribute( |
| 59 | "class", |
| 60 | tone === "destructive" ? "size-3.5 shrink-0" : "size-3.5 shrink-0 text-muted-foreground", |
| 61 | ); |
| 62 | for (const node of paths) { |
| 63 | const child = document.createElementNS(SVG_NS, node.tag); |
| 64 | for (const [key, value] of Object.entries(node.attrs)) { |
| 65 | child.setAttribute(key, value); |
| 66 | } |
| 67 | svg.appendChild(child); |
| 68 | } |
| 69 | return svg; |
| 70 | } |
| 71 | |
| 72 | function clampMenuPosition(menu: HTMLDivElement, preferredLeft: number, preferredTop: number) { |
| 73 | const rect = menu.getBoundingClientRect(); |