Skip to content

Commit bd9ba52

Browse files
committed
Add support for OKLCH color format
Fixes #29
1 parent bb51b72 commit bd9ba52

10 files changed

+492
-321
lines changed

Diff for: Color Picker/App.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct AppMain: App {
2323
// TODO: Change the default from LCH to OKLCH.
2424
// We set this so we can change it later on.
2525
SSApp.runOnce(identifier: "asdsadewr34323432432") {
26-
Defaults[.shownColorFormats] = Defaults[.shownColorFormats]
26+
Defaults[.shownColorFormats] = SSApp.isFirstLaunch ? [.hex, .hsl, .rgb, .oklch] : Defaults[.shownColorFormats]
2727
}
2828
}
2929

@@ -51,7 +51,7 @@ struct AppMain: App {
5151
Button("Paste") {
5252
appState.pasteColor()
5353
}
54-
.help("Paste color in the format Hex, HSL, RGB, or LCH")
54+
.help("Paste color in the format Hex, HSL, RGB, OKLCH, or LCH")
5555
.keyboardShortcut("v", modifiers: [.shift, .command])
5656
.disabled(Color.Resolved.fromPasteboardGraceful(.general) == nil)
5757
Divider()
@@ -67,7 +67,7 @@ struct AppMain: App {
6767
.keyboardShortcut("t", modifiers: [.control, .command])
6868
}
6969
CommandGroup(replacing: .help) {
70-
Link("What is LCH color?", destination: "https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/")
70+
Link("What is OKLCH color?", destination: "https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl")
7171
Link("FAQ", destination: "https://github.com/sindresorhus/System-Color-Picker#faq")
7272
Link("Website", destination: "https://sindresorhus.com/system-color-picker")
7373
Divider()

Diff for: Color Picker/AppState.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ final class AppState {
1717
colorPanel.standardWindowButton(.miniaturizeButton)?.isHidden = true
1818
colorPanel.standardWindowButton(.zoomButton)?.isHidden = true
1919
colorPanel.tabbingMode = .disallowed
20-
colorPanel.collectionBehavior = [
21-
.canJoinAllSpaces,
20+
21+
var collectionBehavior: NSWindow.CollectionBehavior = [
2222
.fullScreenAuxiliary
2323
// We cannot enable tiling as then it doesn't show up in fullscreen spaces. (macOS 12.5)
2424
// .fullScreenAllowsTiling
2525
]
26+
27+
if Defaults[.showOnAllSpaces] {
28+
// If we remove this, the window cannot be dragged if it's moved into a fullscreen space. (macOS 14.3)
29+
collectionBehavior.insert(.canJoinAllSpaces)
30+
}
31+
32+
colorPanel.collectionBehavior = collectionBehavior
33+
2634
colorPanel.center()
2735
colorPanel.makeMain()
2836

Diff for: Color Picker/Constants.swift

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extension Defaults.Keys {
2424
static let quitAfterPicking = Key<Bool>("quitAfterPicking", default: false)
2525
static let showAccessibilityColorName = Key<Bool>("showAccessibilityColorName", default: false)
2626
static let stickyPaletteName = Key<String?>("stickyPaletteName")
27+
28+
// Hidden settings
29+
static let showOnAllSpaces = Key<Bool>("showOnAllSpaces", default: true)
2730
}
2831

2932
extension KeyboardShortcuts.Name {
@@ -35,6 +38,7 @@ enum ColorFormat: String, CaseIterable, Defaults.Serializable {
3538
case hex
3639
case hsl
3740
case rgb
41+
case oklch
3842
case lch
3943

4044
var title: String {
@@ -45,6 +49,8 @@ enum ColorFormat: String, CaseIterable, Defaults.Serializable {
4549
"HSL"
4650
case .rgb:
4751
"RGB"
52+
case .oklch:
53+
"OKLCH"
4854
case .lch:
4955
"LCH"
5056
}
@@ -58,6 +64,8 @@ enum ColorFormat: String, CaseIterable, Defaults.Serializable {
5864
"s"
5965
case .rgb:
6066
"r"
67+
case .oklch:
68+
"o"
6169
case .lch:
6270
"l"
6371
}

Diff for: Color Picker/MainScreen.swift

+5-9
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ struct MainScreen: View {
99
@Default(.showAccessibilityColorName) private var showAccessibilityColorName
1010
@State private var isPreventingUpdate = false
1111
@State private var focusedTextField: ColorFormat?
12-
13-
@State private var colorStrings: [ColorFormat: String] = [
14-
.hex: "",
15-
.hsl: "",
16-
.rgb: "",
17-
.lch: ""
18-
]
12+
@State private var colorStrings = EnumCaseMap<ColorFormat, String>(defaultValue: "")
1913

2014
let colorPanel: NSColorPanel
2115

@@ -98,6 +92,8 @@ struct MainScreen: View {
9892
Color.Resolved(cssHSLString: colorString)
9993
case .rgb:
10094
Color.Resolved(cssRGBString: colorString)
95+
case .oklch:
96+
Color.Resolved(cssOKLCHString: colorString)
10197
case .lch:
10298
Color.Resolved(cssLCHString: colorString)
10399
}
@@ -114,7 +110,7 @@ struct MainScreen: View {
114110
ForEach(ColorFormat.allCases.filter(allowedValues: shownColorFormats)) { colorFormat in
115111
ColorInputView(
116112
colorFormat: colorFormat,
117-
colorString: $colorStrings[colorFormat, default: ""],
113+
colorString: $colorStrings[colorFormat],
118114
focusedTextField: $focusedTextField
119115
) { newColor in
120116
updateColorFromTextField(
@@ -222,7 +218,7 @@ private struct PasteColorButton: View {
222218
.padding(8)
223219
}
224220
.contentShape(.rect)
225-
.help("Paste color in the format Hex, HSL, RGB, or LCH")
221+
.help("Paste color in the format Hex, HSL, RGB, OKLCH, or LCH")
226222
.keyboardShortcut("v", modifiers: [.shift, .command])
227223
.disabled(Color.Resolved.fromPasteboardGraceful(.general) == nil)
228224
.onAppearOnScreen {

Diff for: Color Picker/SettingsScreen.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private struct ColorSettings: View {
7878
.help("Use the legacy “hsl(198, 28%, 50%)” syntax instead of the modern “hsl(198deg 28% 50%)” syntax. This setting is meant for users that need to support older browsers. All modern browsers support the modern syntax.")
7979
}
8080
Section {} footer: {
81-
Link("What is LCH color?", destination: "https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/")
81+
Link("What is OKLCH color?", destination: "https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl")
8282
.controlSize(.small)
8383
}
8484
}

0 commit comments

Comments
 (0)