@@ -12,77 +12,86 @@ struct EyedropperItem: View {
1212 @Environment ( \. colorScheme) var colorScheme : ColorScheme
1313 @ObservedObject var eyedropper : Eyedropper
1414 @Binding var dismissEditingTrigger : Int
15+ /// Height to hold the readout block at, shared across both swatches by `ColorPickers`.
16+ var readoutHeight : CGFloat = 0
17+ /// Whether the readout boundary hairline is showing — driven by hovering either swatch.
18+ var showsReadoutBoundary : Bool = false
1519 @State private var showToast : Bool = false
1620 @Default ( . colorFormat) var colorFormat
1721 @Default ( . copyFormat) var copyFormat
1822 let pasteboard = NSPasteboard . general
1923 var body : some View {
2024 ZStack {
21- EyedropperButton ( eyedropper: eyedropper, dismissEditingTrigger: $dismissEditingTrigger)
22- . frame ( maxWidth: . infinity, maxHeight: . infinity)
23- . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. pickNotification) ) { note in
24- let requestedChain = note. userInfo ? [ " chain " ] as? Bool == true
25- let chain = eyedropper. type == . foreground
26- && ( Defaults [ . pickContrastingColor] || requestedChain)
27- eyedropper. start ( chainContrasting: chain)
25+ EyedropperButton (
26+ eyedropper: eyedropper,
27+ dismissEditingTrigger: $dismissEditingTrigger,
28+ readoutHeight: readoutHeight,
29+ showsReadoutBoundary: showsReadoutBoundary
30+ )
31+ . frame ( maxWidth: . infinity, maxHeight: . infinity)
32+ . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. pickNotification) ) { note in
33+ let requestedChain = note. userInfo ? [ " chain " ] as? Bool == true
34+ let chain = eyedropper. type == . foreground
35+ && ( Defaults [ . pickContrastingColor] || requestedChain)
36+ eyedropper. start ( chainContrasting: chain)
37+ }
38+ . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. copyNotification) ) { _ in
39+ showToast = true
40+ pasteboard. clearContents ( )
41+ let contents = " \( eyedropper. color. toFormat ( format: colorFormat, style: Defaults [ . copyFormat] ) ) "
42+ pasteboard. setString ( contents, forType: . string)
43+ }
44+ . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. systemPickerNotification) ) { _ in
45+ let panel = NSColorPanel . shared
46+ if panel. isVisible, panel. title == " \( eyedropper. type. rawValue. capitalized) " {
47+ panel. close ( )
48+ } else {
49+ eyedropper. picker ( )
2850 }
29- . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. copyNotification) ) { _ in
30- showToast = true
31- pasteboard. clearContents ( )
32- let contents = " \( eyedropper. color. toFormat ( format: colorFormat, style: Defaults [ . copyFormat] ) ) "
33- pasteboard. setString ( contents, forType: . string)
51+ }
52+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatHex) ) { _ in
53+ if copyFormat != . swiftUI {
54+ colorFormat = ColorFormat . hex
3455 }
35- . onReceive ( NotificationCenter . default. publisher ( for: eyedropper. type. systemPickerNotification) ) { _ in
36- let panel = NSColorPanel . shared
37- if panel. isVisible, panel. title == " \( eyedropper. type. rawValue. capitalized) " {
38- panel. close ( )
39- } else {
40- eyedropper. picker ( )
41- }
42- }
43- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatHex) ) { _ in
44- if copyFormat != . swiftUI {
45- colorFormat = ColorFormat . hex
46- }
47- }
48- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatRGB) ) { _ in
49- colorFormat = ColorFormat . rgb
50- }
51- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatHSB) ) { _ in
52- colorFormat = ColorFormat . hsb
56+ }
57+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatRGB) ) { _ in
58+ colorFormat = ColorFormat . rgb
59+ }
60+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatHSB) ) { _ in
61+ colorFormat = ColorFormat . hsb
62+ }
63+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatHSL) ) { _ in
64+ if copyFormat != . swiftUI {
65+ colorFormat = ColorFormat . hsl
5366 }
54- . onReceive ( NotificationCenter . default . publisher ( for : . triggerFormatHSL ) ) { _ in
55- if copyFormat != . swiftUI {
56- colorFormat = ColorFormat . hsl
57- }
67+ }
68+ . onReceive ( NotificationCenter . default . publisher ( for : . triggerFormatOpenGL ) ) { _ in
69+ if copyFormat != . swiftUI {
70+ colorFormat = ColorFormat . opengl
5871 }
59- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatOpenGL) ) { _ in
60- if copyFormat != . swiftUI {
61- colorFormat = ColorFormat . opengl
72+ }
73+ . onChange ( of: copyFormat) {
74+ if copyFormat == . swiftUI {
75+ if PikaConstants . disabledFormats. contains ( colorFormat) {
76+ colorFormat = . rgb
6277 }
6378 }
64- . onChange ( of: copyFormat) {
65- if copyFormat == . swiftUI {
66- if PikaConstants . disabledFormats. contains ( colorFormat) {
67- colorFormat = . rgb
68- }
69- }
79+ }
80+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatLAB) ) { _ in
81+ if copyFormat != . swiftUI {
82+ colorFormat = . lab
7083 }
71- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatLAB) ) { _ in
72- if copyFormat != . swiftUI {
73- colorFormat = . lab
74- }
75- }
76- . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatOKLCH) ) { _ in
77- if copyFormat != . swiftUI {
78- colorFormat = . oklch
79- }
84+ }
85+ . onReceive ( NotificationCenter . default. publisher ( for: . triggerFormatOKLCH) ) { _ in
86+ if copyFormat != . swiftUI {
87+ colorFormat = . oklch
8088 }
81- . toast (
82- isShowing: $showToast,
83- color: eyedropper. color. getUIColor ( ) ,
84- text: Text ( String ( PikaText . textColorCopied) )
85- )
89+ }
90+ . toast (
91+ isShowing: $showToast,
92+ color: eyedropper. color. getUIColor ( ) ,
93+ text: Text ( String ( PikaText . textColorCopied) )
94+ )
8695 }
8796 }
8897}
0 commit comments