@@ -2,26 +2,18 @@ import SharingGRDB
22import SwiftUI
33
44extension Color {
5- public struct HexRepresentation : QueryBindable , QueryRepresentable {
5+ public struct HexRepresentation : QueryRepresentable {
66 public var queryOutput : Color
7- public var queryBinding : QueryBinding {
8- guard let hexValue else {
9- struct InvalidColor : Error { }
10- return . invalid( InvalidColor ( ) )
11- }
12- return . int( hexValue)
13- }
147 public init ( queryOutput: Color ) {
158 self . queryOutput = queryOutput
169 }
17- public init ( decoder: inout some QueryDecoder ) throws {
18- let hex = try Int ( decoder: & decoder)
10+ public init ( hexValue: Int64 ) {
1911 self . init (
2012 queryOutput: Color (
21- red: Double ( ( hex >> 24 ) & 0xFF ) / 0xFF ,
22- green: Double ( ( hex >> 16 ) & 0xFF ) / 0xFF ,
23- blue: Double ( ( hex >> 8 ) & 0xFF ) / 0xFF ,
24- opacity: Double ( hex & 0xFF ) / 0xFF
13+ red: Double ( ( hexValue >> 24 ) & 0xFF ) / 0xFF ,
14+ green: Double ( ( hexValue >> 16 ) & 0xFF ) / 0xFF ,
15+ blue: Double ( ( hexValue >> 8 ) & 0xFF ) / 0xFF ,
16+ opacity: Double ( hexValue & 0xFF ) / 0xFF
2517 )
2618 )
2719 }
@@ -36,3 +28,23 @@ extension Color {
3628 }
3729 }
3830}
31+
32+ extension Color . HexRepresentation : QueryBindable {
33+ public init ? ( queryBinding: StructuredQueriesCore . QueryBinding ) {
34+ guard case . int( let hexValue) = queryBinding else { return nil }
35+ self . init ( hexValue: hexValue)
36+ }
37+ public var queryBinding : QueryBinding {
38+ guard let hexValue else {
39+ struct InvalidColor : Error { }
40+ return . invalid( InvalidColor ( ) )
41+ }
42+ return . int( hexValue)
43+ }
44+ }
45+
46+ extension Color . HexRepresentation : QueryDecodable {
47+ public init ( decoder: inout some QueryDecoder ) throws {
48+ try self . init ( hexValue: Int64 ( decoder: & decoder) )
49+ }
50+ }
0 commit comments