Open source CapCut alternative.
TypeScript
Color the vision overlay per element
David Le62ae77f9a58c
diff --git a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swiftindex 750cd966..60ddd404 100644--- a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift@@ -199,7 +199,7 @@ private final class DebugUIInspectionSurface {containerSize: rootView.bounds.size)layers.label.string = title- layers.label.foregroundColor = nsColor(hex: element.visualStyle.labelColor, alpha: 1).cgColor+ layers.label.foregroundColor = labelForegroundColor(for: element)layers.label.backgroundColor = labelBackgroundColor(for: element)layers.label.frame = labelFrame}@@ -229,6 +229,9 @@ private final class DebugUIInspectionSurface {private func strokeColor(for element: DebugUIElement) -> CGColor {switch sourceKind(for: element) {case .ai:+ if let color = aiPaletteColor(for: element, alpha: 0.98) {+ return color.cgColor+ }return nsColor(hex: "#FF2D55", alpha: 0.98).cgColorcase .nativeVisual:return nsColor(hex: "#00C7BE", alpha: 0.95).cgColor@@ -247,6 +250,9 @@ private final class DebugUIInspectionSurface {private func labelBackgroundColor(for element: DebugUIElement) -> CGColor {switch sourceKind(for: element) {case .ai:+ if let color = aiPaletteColor(for: element, alpha: 0.94) {+ return color.cgColor+ }return nsColor(hex: "#FF2D55", alpha: 0.94).cgColorcase .nativeVisual:return nsColor(hex: "#00C7BE", alpha: 0.92).cgColor@@ -262,6 +268,35 @@ private final class DebugUIInspectionSurface {}}+ // Per-index palette for vision elements, so adjacent boxes read apart instead+ // of all sharing one AI color. Cycled by the element's `vision.index`.+ private static let aiPalette = [+ "#FF3B30", "#FF9500", "#FFCC00", "#34C759",+ "#00C7BE", "#30B0C7", "#007AFF", "#5856D6",+ "#AF52DE", "#FF2D55", "#A2845E", "#8E8E93"+ ]++ private func aiPaletteColor(for element: DebugUIElement, alpha: CGFloat) -> NSColor? {+ guard sourceKind(for: element) == .ai,+ let raw = element.metadata["vision.index"],+ let index = Int(raw)+ else {+ return nil+ }+ let count = Self.aiPalette.count+ return nsColor(hex: Self.aiPalette[((index % count) + count) % count], alpha: alpha)+ }++ private func labelForegroundColor(for element: DebugUIElement) -> CGColor {+ guard let color = aiPaletteColor(for: element, alpha: 1) else {+ return nsColor(hex: element.visualStyle.labelColor, alpha: 1).cgColor+ }+ // Black on light chips, white on dark — keep the label legible.+ let srgb = color.usingColorSpace(.sRGB) ?? color+ let luminance = 0.299 * srgb.redComponent + 0.587 * srgb.greenComponent + 0.114 * srgb.blueComponent+ return (luminance > 0.6 ? NSColor.black : NSColor.white).cgColor+ }+private func lineDashPattern(for element: DebugUIElement) -> [NSNumber]? {sourceKind(for: element) == .ai ? [6, 4] : nil}diff --git a/apps/Donkey/Sources/DonkeyAI/VisionParseDebugUIOverlayMapper.swift b/apps/Donkey/Sources/DonkeyAI/VisionParseDebugUIOverlayMapper.swiftindex 537294e3..5ddfa730 100644--- a/apps/Donkey/Sources/DonkeyAI/VisionParseDebugUIOverlayMapper.swift+++ b/apps/Donkey/Sources/DonkeyAI/VisionParseDebugUIOverlayMapper.swift@@ -27,7 +27,7 @@ public enum VisionParseDebugUIOverlayMapper {screenFrame: screenFrame)- let parsed = response.elements.compactMap { element -> DebugUIElement? in+ let parsed = response.elements.enumerated().compactMap { visionIndex, element -> DebugUIElement? inguard !isMacWindowControl(label: element.label) else {return nil}@@ -60,6 +60,7 @@ public enum VisionParseDebugUIOverlayMapper {"remoteScreenshotParsing.status": "used","remoteScreenshotParsing.provider": "omniparser-v2","vision.kind": element.kind,+ "vision.index": String(visionIndex),"vision.interactive": String(element.interactive),"target.windowID": String(target.windowID),"target.appName": target.appName ?? "",