import Foundation public struct PatternLocation: Sendable { public let node: DecodedPattern public let range: Range public let ancestors: [UUID] public let tint: PatternTint public let isLeaf: Bool public static func locateFields(of root: DecodedPattern, under ancestor: UUID, base: UInt64, into located: inout [UUID: PatternLocation]) { for (index, field) in root.children.enumerated() where !field.hidden { locate(field, ancestors: [ancestor], tint: PatternTint(node: field, index: index), base: base, into: &located) } } private static func locate( _ node: DecodedPattern, ancestors: [UUID], tint: PatternTint, base: UInt64, into located: inout [UUID: PatternLocation] ) { let children = node.visibleChildren let ownTint = node.color.flatMap(PatternTint.init(hex:)) ?? tint if let size = node.size, size > 0, node.address >= base { let start = Int(node.address - base) let isLeaf = !children.contains { ($0.size ?? 0) > 0 } located[node.id] = PatternLocation(node: node, range: start..> 16) & 0xff), green: UInt8((value >> 8) & 0xff), blue: UInt8(value & 0xff)) } } extension DecodedPattern { public var visibleChildren: [DecodedPattern] { sealed ? [] : children.filter { !$0.hidden } } }