Skip to content

Commit 30fc7d8

Browse files
Merge pull request #186 from superhighfives/feature/backlog-fixes
Backlog fixes: menu warnings, OKLCH formatting, Xcode settings, context menu shortcuts
2 parents 55c0fce + eab1c36 commit 30fc7d8

23 files changed

Lines changed: 462 additions & 222 deletions

Pika.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CC2000000000000000000701 /* WCAGComplianceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2000000000000000000700 /* WCAGComplianceTests.swift */; };
2525
CC2000000000000000000801 /* APCAComplianceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2000000000000000000800 /* APCAComplianceTests.swift */; };
2626
CC2000000000000000000901 /* NotificationNamesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2000000000000000000900 /* NotificationNamesTests.swift */; };
27+
CC2000000000000000000A01 /* CGFloatFormatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2000000000000000000A00 /* CGFloatFormatTests.swift */; };
2728

2829
220D5E9428DB154300B6285E /* AppModeButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220D5E9328DB154300B6285E /* AppModeButtons.swift */; };
2930
220D5E9828DB158400B6285E /* AppModeToggleGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220D5E9728DB158400B6285E /* AppModeToggleGroup.swift */; };
@@ -50,6 +51,8 @@
5051
CC000001000000000000AAF2 /* NSColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC000001000000000000AAF0 /* NSColor+Hex.swift */; };
5152
CC000001000000000000AB01 /* NSColor+RGB.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC000001000000000000AB00 /* NSColor+RGB.swift */; };
5253
CC000001000000000000AB02 /* NSColor+RGB.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC000001000000000000AB00 /* NSColor+RGB.swift */; };
54+
CC000001000000000000AB11 /* CGFloat+Format.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC000001000000000000AB10 /* CGFloat+Format.swift */; };
55+
CC000001000000000000AB12 /* CGFloat+Format.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC000001000000000000AB10 /* CGFloat+Format.swift */; };
5356
EA0C525025AA729300AFF716 /* Visualisation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0C524F25AA729300AFF716 /* Visualisation.swift */; };
5457
EA0C526025AB5A2B00AFF716 /* NavigationMenuItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0C525F25AB5A2B00AFF716 /* NavigationMenuItems.swift */; };
5558
EA0C526425AB5D1700AFF716 /* PikaWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0C526325AB5D1700AFF716 /* PikaWindow.swift */; };
@@ -194,6 +197,7 @@
194197
CC2000000000000000000700 /* WCAGComplianceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WCAGComplianceTests.swift; sourceTree = "<group>"; };
195198
CC2000000000000000000800 /* APCAComplianceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APCAComplianceTests.swift; sourceTree = "<group>"; };
196199
CC2000000000000000000900 /* NotificationNamesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationNamesTests.swift; sourceTree = "<group>"; };
200+
CC2000000000000000000A00 /* CGFloatFormatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGFloatFormatTests.swift; sourceTree = "<group>"; };
197201

198202
220D5E9328DB154300B6285E /* AppModeButtons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppModeButtons.swift; sourceTree = "<group>"; };
199203
220D5E9728DB158400B6285E /* AppModeToggleGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppModeToggleGroup.swift; sourceTree = "<group>"; };
@@ -223,6 +227,7 @@
223227
CC000001000000000000AAE0 /* NSColor+Luminance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+Luminance.swift"; sourceTree = "<group>"; };
224228
CC000001000000000000AAF0 /* NSColor+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+Hex.swift"; sourceTree = "<group>"; };
225229
CC000001000000000000AB00 /* NSColor+RGB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+RGB.swift"; sourceTree = "<group>"; };
230+
CC000001000000000000AB10 /* CGFloat+Format.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+Format.swift"; sourceTree = "<group>"; };
226231
EA0C524F25AA729300AFF716 /* Visualisation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Visualisation.swift; sourceTree = "<group>"; };
227232
EA0C525F25AB5A2B00AFF716 /* NavigationMenuItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationMenuItems.swift; sourceTree = "<group>"; };
228233
EA0C526325AB5D1700AFF716 /* PikaWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PikaWindow.swift; sourceTree = "<group>"; };
@@ -422,6 +427,7 @@
422427
CC000001000000000000AAE0 /* NSColor+Luminance.swift */,
423428
CC000001000000000000AAF0 /* NSColor+Hex.swift */,
424429
CC000001000000000000AB00 /* NSColor+RGB.swift */,
430+
CC000001000000000000AB10 /* CGFloat+Format.swift */,
425431
);
426432
path = Extensions;
427433
sourceTree = "<group>";
@@ -480,6 +486,7 @@
480486
CC2000000000000000000700 /* WCAGComplianceTests.swift */,
481487
CC2000000000000000000800 /* APCAComplianceTests.swift */,
482488
CC2000000000000000000900 /* NotificationNamesTests.swift */,
489+
CC2000000000000000000A00 /* CGFloatFormatTests.swift */,
483490
);
484491
path = PikaTests;
485492
sourceTree = "<group>";
@@ -875,6 +882,7 @@
875882
CC000001000000000000AAE1 /* NSColor+Luminance.swift in Sources */,
876883
CC000001000000000000AAF1 /* NSColor+Hex.swift in Sources */,
877884
CC000001000000000000AB01 /* NSColor+RGB.swift in Sources */,
885+
CC000001000000000000AB11 /* CGFloat+Format.swift in Sources */,
878886
EAA8AE1925B8EC070049299B /* KeyboardShortcutKey.swift in Sources */,
879887
EA0C526F25AB683400AFF716 /* EyedropperButton.swift in Sources */,
880888
EA72BB8425A5334B008205E7 /* MetalShader.metal in Sources */,
@@ -918,6 +926,7 @@
918926
CC000001000000000000AAE2 /* NSColor+Luminance.swift in Sources */,
919927
CC000001000000000000AAF2 /* NSColor+Hex.swift in Sources */,
920928
CC000001000000000000AB02 /* NSColor+RGB.swift in Sources */,
929+
CC000001000000000000AB12 /* CGFloat+Format.swift in Sources */,
921930
EAE23DAE2D032A38005BB270 /* SplashTouchBar.swift in Sources */,
922931
EAE23DAF2D032A38005BB270 /* OverflowContentViewModifier.swift in Sources */,
923932
EAE23DB02D032A38005BB270 /* KeyboardShortcutGrid.swift in Sources */,
@@ -981,6 +990,7 @@
981990
CC2000000000000000000701 /* WCAGComplianceTests.swift in Sources */,
982991
CC2000000000000000000801 /* APCAComplianceTests.swift in Sources */,
983992
CC2000000000000000000901 /* NotificationNamesTests.swift in Sources */,
993+
CC2000000000000000000A01 /* CGFloatFormatTests.swift in Sources */,
984994
);
985995
runOnlyForDeploymentPostprocessing = 0;
986996
};
@@ -1143,6 +1153,7 @@
11431153
isa = XCBuildConfiguration;
11441154
buildSettings = {
11451155
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
1156+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
11461157
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
11471158
CODE_SIGN_IDENTITY = "Apple Development";
11481159
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
@@ -1174,6 +1185,7 @@
11741185
isa = XCBuildConfiguration;
11751186
buildSettings = {
11761187
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
1188+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
11771189
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
11781190
CODE_SIGN_IDENTITY = "Apple Development";
11791191
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
@@ -1205,6 +1217,7 @@
12051217
isa = XCBuildConfiguration;
12061218
buildSettings = {
12071219
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
1220+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
12081221
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12091222
CODE_SIGN_ENTITLEMENTS = Pika/Pika.entitlements;
12101223
CODE_SIGN_IDENTITY = "Apple Development";
@@ -1237,6 +1250,7 @@
12371250
isa = XCBuildConfiguration;
12381251
buildSettings = {
12391252
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
1253+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
12401254
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
12411255
CODE_SIGN_ENTITLEMENTS = Pika/Pika.entitlements;
12421256
CODE_SIGN_IDENTITY = "Apple Development";

Pika/Constants/Constants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Defaults
22
import KeyboardShortcuts
33
import SwiftUI
44

5-
// swiftlint:disable trailing_comma
65
// swiftlint:disable line_length
76

87
extension KeyboardShortcuts.Name {
@@ -305,5 +304,6 @@ enum PikaText {
305304
static let textDuration = NSLocalizedString("preferences.overlay.duration", comment: "Duration:")
306305
}
307306

308-
// swiftlint:enable trailing_comma
309307
// swiftlint:enable line_length
308+
// line_length is disabled above because NSLocalizedString comment strings on lines 100 and 102
309+
// exceed 120 characters and cannot be shortened without losing meaning for localizers.

Pika/Extensions/APCACompliance.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Cocoa
22

33
// swiftlint:disable identifier_name
4+
// identifier_name is disabled because the APCA algorithm uses conventional single-letter
5+
// variable names (c, r, g, b, y, s) from the specification that would be misleading if renamed.
46

57
extension NSColor {
68
struct APCA {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import CoreGraphics
2+
import Foundation
3+
4+
extension CGFloat {
5+
/// Formats the value with up to `maxDecimalPlaces` decimal places, stripping trailing zeros.
6+
/// e.g. 0.5000 → "0.5", 0.0000 → "0", 56.78 → "56.78"
7+
func strippedDecimalString(maxDecimalPlaces: Int) -> String {
8+
// Normalize -0.0 to +0.0 to avoid producing "-0" in output.
9+
let value: CGFloat = self == 0 ? 0 : self
10+
let formatted = String(format: "%.\(maxDecimalPlaces)f", value)
11+
guard formatted.contains(".") else { return formatted }
12+
var result = formatted
13+
while result.hasSuffix("0") { result.removeLast() }
14+
if result.hasSuffix(".") { result.removeLast() }
15+
return result
16+
}
17+
}

Pika/Extensions/NSColor+HSL.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import Cocoa
22
import Defaults
33

44
// swiftlint:disable identifier_name
5+
// identifier_name is disabled because color science math uses conventional single-letter
6+
// variable names (h, s, b, l, r, g) that would be misleading if renamed.
7+
8+
public struct HSBComponents { let h, s, b: CGFloat }
9+
public struct HSLComponents { let h, s, l: CGFloat }
510

611
extension NSColor {
712
/*
813
* HSB
914
*/
1015

11-
public final func toHSBComponents() -> (h: CGFloat, s: CGFloat, b: CGFloat) {
16+
public final func toHSBComponents() -> HSBComponents {
1217
var h: CGFloat = 0.0
1318
var s: CGFloat = 0.0
1419
var b: CGFloat = 0.0
@@ -18,15 +23,15 @@ extension NSColor {
1823
}
1924

2025
if toHexString() == NSColor.black.toHexString() {
21-
return (0.0, 0.0, 0.0)
26+
return HSBComponents(h: 0.0, s: 0.0, b: 0.0)
2227
} else if toHexString() == NSColor.white.toHexString() {
23-
return (0.0, 0.0, 1.0)
28+
return HSBComponents(h: 0.0, s: 0.0, b: 1.0)
2429
}
2530

2631
rgbaColor.getHue(&h, saturation: &s, brightness: &b, alpha: nil)
2732
h = h.truncatingRemainder(dividingBy: 1.0)
2833

29-
return (h: h, s: s, b: b)
34+
return HSBComponents(h: h, s: s, b: b)
3035
}
3136

3237
/**
@@ -58,7 +63,7 @@ extension NSColor {
5863
* HSL
5964
*/
6065

61-
public final func toHSLComponents() -> (h: CGFloat, s: CGFloat, l: CGFloat) {
66+
public final func toHSLComponents() -> HSLComponents {
6267
var h: CGFloat = 0.0
6368
var s: CGFloat = 0.0
6469
var l: CGFloat = 0.0
@@ -69,9 +74,9 @@ extension NSColor {
6974
let b = RGB.b
7075

7176
if toHexString() == NSColor.black.toHexString() {
72-
return (0.0, 0.0, 0.0)
77+
return HSLComponents(h: 0.0, s: 0.0, l: 0.0)
7378
} else if toHexString() == NSColor.white.toHexString() {
74-
return (0.0, 0.0, 1.0)
79+
return HSLComponents(h: 0.0, s: 0.0, l: 1.0)
7580
}
7681

7782
let min = Swift.min(Swift.min(r, g), b)
@@ -106,7 +111,7 @@ extension NSColor {
106111
s = delta / (2 - max - min)
107112
}
108113

109-
return (h: h, s: s, l: l)
114+
return HSLComponents(h: h, s: s, l: l)
110115
}
111116

112117
/**

Pika/Extensions/NSColor+Hex.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Cocoa
22

33
extension NSColor {
4-
func roundToHex(_ x: CGFloat) -> UInt32 {
5-
guard x > 0 else { return 0 }
6-
let rounded: CGFloat = round(x * 255.0)
4+
func roundToHex(_ value: CGFloat) -> UInt32 {
5+
guard value > 0 else { return 0 }
6+
let rounded: CGFloat = round(value * 255.0)
77
return UInt32(rounded)
88
}
99

Pika/Extensions/NSColor+Init.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Cocoa
22

33
extension NSColor {
4+
// r, g, b, a are the public parameter labels for this init (NSColor(r:g:b:a:)) and cannot be renamed.
5+
// swiftlint:disable:next identifier_name
46
convenience init(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1) {
57
if (r > 1) || (g > 1) || (b > 1) {
68
self.init(red: r / 255, green: g / 255, blue: b / 255, alpha: a)
@@ -25,18 +27,18 @@ extension NSColor {
2527
if hex.count == 3 {
2628
let tmp = hex
2729
hex = ""
28-
for c in tmp {
29-
hex += String([c, c])
30+
for char in tmp {
31+
hex += String([char, char])
3032
}
3133
}
3234

3335
let scanner = Scanner(string: hex)
3436
var rgb: UInt64 = 0
3537
scanner.scanHexInt64(&rgb)
3638

37-
let R = CGFloat((rgb >> 16) & 0xFF) / 255
38-
let G = CGFloat((rgb >> 8) & 0xFF) / 255
39-
let B = CGFloat(rgb & 0xFF) / 255
40-
self.init(red: R, green: G, blue: B, alpha: alpha)
39+
let red = CGFloat((rgb >> 16) & 0xFF) / 255
40+
let green = CGFloat((rgb >> 8) & 0xFF) / 255
41+
let blue = CGFloat(rgb & 0xFF) / 255
42+
self.init(red: red, green: green, blue: blue, alpha: alpha)
4143
}
4244
}

Pika/Extensions/NSColor+Lab.swift

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Cocoa
22

33
// swiftlint:disable identifier_name
4+
// identifier_name is disabled because color science math uses conventional single-letter
5+
// variable names (x, y, z, l, a, b, c, h, L, C, H) that would be misleading if renamed.
6+
7+
private struct XYZComponents { let x, y, z: CGFloat }
8+
struct LabComponents { let l, a, b: CGFloat }
9+
struct OklchComponents { let l, c, h: CGFloat }
410

511
extension NSColor {
612
// Shared linearization for sRGB components used by both LAB and OKLCH.
@@ -20,23 +26,25 @@ extension NSColor {
2026
func toOpenGLString(style: CopyFormat = .css) -> String {
2127
let RGB = toRGBAComponents()
2228

23-
let formatString: NSString
29+
// %.5g strips trailing zeros but drops the decimal entirely for whole numbers,
30+
// so append ".0" when there is no decimal point (e.g. 0 → "0.0", 1 → "1.0").
31+
let red = { let s = String(format: "%.5g", RGB.r); return s.contains(".") ? s : "\(s).0" }()
32+
let green = { let s = String(format: "%.5g", RGB.g); return s.contains(".") ? s : "\(s).0" }()
33+
let blue = { let s = String(format: "%.5g", RGB.b); return s.contains(".") ? s : "\(s).0" }()
34+
2435
switch style {
2536
case .css, .design, .swiftUI:
26-
formatString = "rgba(%.5g, %.5g, %.5g, 1.0)"
37+
return "rgba(\(red), \(green), \(blue), 1.0)"
2738
case .unformatted:
28-
formatString = "%.5g, %.5g, %.5g, 1.0"
39+
return "\(red), \(green), \(blue), 1.0"
2940
}
30-
31-
let openGLString = NSString(format: formatString, RGB.r, RGB.g, RGB.b)
32-
return openGLString as String
3341
}
3442

3543
/*
3644
* CIE-LAB
3745
*/
3846

39-
private func toXYZComponents() -> (x: CGFloat, y: CGFloat, z: CGFloat) {
47+
private func toXYZComponents() -> XYZComponents {
4048
let srgb = toRGBAComponents(in: .sRGB)
4149
let r_lin = linearizeSRGB(srgb.r)
4250
let g_lin = linearizeSRGB(srgb.g)
@@ -46,10 +54,10 @@ extension NSColor {
4654
let y = r_lin * 0.2126729 + g_lin * 0.7151522 + b_lin * 0.0721750
4755
let z = r_lin * 0.0193339 + g_lin * 0.1191920 + b_lin * 0.9503041
4856

49-
return (x: x, y: y, z: z)
57+
return XYZComponents(x: x, y: y, z: z)
5058
}
5159

52-
func toLabComponents() -> (l: CGFloat, a: CGFloat, b: CGFloat) {
60+
func toLabComponents() -> LabComponents {
5361
let xyz = toXYZComponents()
5462

5563
// D65 Reference White
@@ -70,30 +78,30 @@ extension NSColor {
7078
let a_star = 500.0 * (f(xyz.x / Xn) - f(xyz.y / Yn))
7179
let b_star = 200.0 * (f(xyz.y / Yn) - f(xyz.z / Zn))
7280

73-
return (l: L_star, a: a_star, b: b_star)
81+
return LabComponents(l: L_star, a: a_star, b: b_star)
7482
}
7583

7684
func toLabString(style: CopyFormat = .css) -> String {
7785
let lab = toLabComponents()
78-
let l_val = round(lab.l * 100) / 100
79-
let a_val = round(lab.a * 100) / 100
80-
let b_val = round(lab.b * 100) / 100
86+
let l_str = (round(lab.l * 100) / 100).strippedDecimalString(maxDecimalPlaces: 2)
87+
let a_str = (round(lab.a * 100) / 100).strippedDecimalString(maxDecimalPlaces: 2)
88+
let b_str = (round(lab.b * 100) / 100).strippedDecimalString(maxDecimalPlaces: 2)
8189

8290
switch style {
8391
case .css:
84-
return String(format: "lab(%.2f %.2f %.2f)", l_val, a_val, b_val)
92+
return "lab(\(l_str) \(a_str) \(b_str))"
8593
case .design, .swiftUI:
86-
return String(format: "lab(%.2f, %.2f, %.2f)", l_val, a_val, b_val)
94+
return "lab(\(l_str), \(a_str), \(b_str))"
8795
case .unformatted:
88-
return String(format: "%.2f,%.2f,%.2f", l_val, a_val, b_val)
96+
return "\(l_str), \(a_str), \(b_str)"
8997
}
9098
}
9199

92100
/*
93101
* OKLCH
94102
*/
95103

96-
func toOklchComponents() -> (l: CGFloat, c: CGFloat, h: CGFloat) {
104+
func toOklchComponents() -> OklchComponents {
97105
let srgb = toRGBAComponents(in: .sRGB)
98106
let r_lin = linearizeSRGB(srgb.r)
99107
let g_lin = linearizeSRGB(srgb.g)
@@ -115,22 +123,22 @@ extension NSColor {
115123
var H = atan2(b, a) * 180.0 / .pi
116124
if H < 0 { H += 360.0 }
117125

118-
return (l: L, c: C, h: H)
126+
return OklchComponents(l: L, c: C, h: H)
119127
}
120128

121129
func toOklchString(style: CopyFormat = .css) -> String {
122130
let oklch = toOklchComponents()
123-
let l_val = round(oklch.l * 10000) / 100
124-
let c_val = round(oklch.c * 10000) / 10000
125-
let h_val = round(oklch.h * 100) / 100
131+
let l_str = (round(oklch.l * 10000) / 100).strippedDecimalString(maxDecimalPlaces: 2)
132+
let c_str = (round(oklch.c * 10000) / 10000).strippedDecimalString(maxDecimalPlaces: 4)
133+
let h_str = (round(oklch.h * 100) / 100).strippedDecimalString(maxDecimalPlaces: 2)
126134

127135
switch style {
128136
case .css:
129-
return String(format: "oklch(%.2f%% %.4f %.2f)", l_val, c_val, h_val)
137+
return "oklch(\(l_str)% \(c_str) \(h_str))"
130138
case .design, .swiftUI:
131-
return String(format: "oklch(%.2f, %.4f, %.2f)", l_val, c_val, h_val)
139+
return "oklch(\(l_str), \(c_str), \(h_str))"
132140
case .unformatted:
133-
return String(format: "%.2f, %.4f, %.2f", l_val, c_val, h_val)
141+
return "\(l_str), \(c_str), \(h_str)"
134142
}
135143
}
136144
}

0 commit comments

Comments
 (0)