Skip to content

Commit

Permalink
Fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rismay committed Jul 23, 2024
1 parent c88fa6f commit c21c43f
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 42 deletions.
17 changes: 10 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ extension SwiftSetting {
// MARK: - PackageDescription extensions

extension [PackageDescription.Package.Dependency] {
static let local: [PackageDescription.Package.Dependency] =
static let local: [PackageDescription.Package.Dependency] =
[
.package(name: "WrkstrmFoundation", path: "../WrkstrmFoundation"),
.package(name: "WrkstrmFoundation", path: "../WrkstrmFoundation")
]

static let remote: [PackageDescription.Package.Dependency] =
[
.package(url: "https://github.com/wrkstrm/WrkstrmFoundation.git", from: "0.4.0"),
.package(url: "https://github.com/wrkstrm/WrkstrmFoundation.git", from: "0.4.0")
]
}

Expand All @@ -41,7 +41,8 @@ struct ConfigurationService {

private static let local: ConfigurationService = .init(
swiftSettings: [.localSwiftSettings],
dependencies: .local)
dependencies: .local
)

private static let remote: ConfigurationService = .init(swiftSettings: [], dependencies: .remote)

Expand All @@ -57,7 +58,7 @@ let package = Package(
.watchOS(.v9),
],
products: [
.library(name: "WrkstrmColor", targets: ["WrkstrmColor"]),
.library(name: "WrkstrmColor", targets: ["WrkstrmColor"])
],
dependencies: ConfigurationService.shared.dependencies,
targets: [
Expand All @@ -66,5 +67,7 @@ let package = Package(
name: "WrkstrmColorTests",
dependencies: ["WrkstrmColor", "WrkstrmFoundation"],
resources: [.process("Resources")],
swiftSettings: ConfigurationService.shared.swiftSettings),
])
swiftSettings: ConfigurationService.shared.swiftSettings
),
]
)
3 changes: 2 additions & 1 deletion Sources/WrkstrmColor/Color+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ extension Color {
red: Double(rgb.r),
green: Double(rgb.g),
blue: Double(rgb.b),
opacity: opacity)
opacity: opacity
)
}
}
#endif
Expand Down
6 changes: 4 additions & 2 deletions Sources/WrkstrmColor/Encodings+Conversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ extension RGB {
return String(Int(ch), radix: 16, uppercase: false).padding(
toLength: 2,
withPad: "0",
startingAt: 0)
startingAt: 0
)
}

public var toHex: Hex {
Expand All @@ -267,7 +268,8 @@ extension Hex {
return RGB(
r: Value(Double((rgbValue & 0xFF0000) >> 16) / 255.0),
g: Value(Double((rgbValue & 0x00FF00) >> 8) / 255.0),
b: Value(Double(rgbValue & 0x0000FF) / 255.0))
b: Value(Double(rgbValue & 0x0000FF) / 255.0)
)
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/WrkstrmColor/GradientDescriptor+Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ extension ContrastGradientDescriptor: Sequence {
guard let current = currentColor else {
currentColor = self.color(
for: S.Value(colorRange.lowerBound),
count: S.Value(maxColors))
count: S.Value(maxColors)
)
return currentColor
}

Expand All @@ -58,7 +59,8 @@ extension ContrastGradientDescriptor: Sequence {
let contrast = current.contrastRatio(
to: self.color(
for: S.Value(colorRange.midPoint),
count: S.Value(maxColors)))
count: S.Value(maxColors)
))

// Narrows down the range based on the contrast ratio.
if contrast < self.minContrast {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WrkstrmColor/GradientDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public protocol Gradient {
/// Extension of the Gradient protocol to include utility functions.
extension Gradient {
/// Calculates the value in the delta range based on the given ratio.
func ratioCalculator(delta: Delta<S.Value>, ratio: S.Value) -> S.Value {
internal func ratioCalculator(delta: Delta<S.Value>, ratio: S.Value) -> S.Value {
switch delta.type {
case .static:
delta.range.lowerBound
Expand Down
15 changes: 10 additions & 5 deletions Sources/WrkstrmColor/HSLuv+GradientDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ extension HSLuv {
count: 10,
aRange: .static(12.2),
bRange: Delta(start: 100.0, end: 50),
cRange: Delta(start: 30, end: 60))
cRange: Delta(start: 30, end: 60)
)
}

public static func blueGradient(minContrast: Value = 1.1) -> ContrastGradientDescriptor<
Expand All @@ -26,31 +27,35 @@ extension HSLuv {
minContrast: minContrast,
aRange: .static(258.6),
bRange: Delta(start: 100, end: 50),
cRange: Delta(start: 30, end: 60))
cRange: Delta(start: 30, end: 60)
)
}

public static var greenGradient: GradientDescriptor<HSLuv<Value>> {
GradientDescriptor(
count: 10,
aRange: .static(127.7),
bRange: Delta(start: 100, end: 50),
cRange: Delta(start: 50, end: 70))
cRange: Delta(start: 50, end: 70)
)
}

public static var blackGradient: GradientDescriptor<HSLuv<Value>> {
GradientDescriptor(
count: 10,
aRange: .static(0),
bRange: .static(0),
cRange: Delta(start: 0, end: 40))
cRange: Delta(start: 0, end: 40)
)
}

public static var whiteGradient: GradientDescriptor<HSLuv<Value>> {
GradientDescriptor(
count: 10,
aRange: .static(0),
bRange: .static(0),
cRange: Delta(start: 100, end: 60))
cRange: Delta(start: 100, end: 60)
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/WrkstrmColor/Math.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func getBounds<Value: ComponentValue>(lightness: Value) -> [Vector<Value>] {
// swiftlint:disable:previous identifier_name
let targets: [Value] = [0.0, 1.0]
for target in targets {
let top1: Value = (284_517 * m1 - 94_839 * m3) * sub2
let top1: Value = (284_517 * m1 - 94839 * m3) * sub2
let multiple: Value = (838_422 * m3 + 769_860 * m2 + 731_718 * m1)
let top2: Value = multiple * lightness * sub2 - 769_860 * target * lightness
let bottom: Value = (632_260 * m3 - 126_452 * m2) * sub2 + 126_452 * target
Expand Down
18 changes: 12 additions & 6 deletions Sources/WrkstrmColor/Palette+HSLuv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,43 @@ extension Palette {
HSLuv(
h: 12.2,
s: 100.0 - 33.0 * ratio,
l: 30.0 + 30.0 * ratio)
l: 30.0 + 30.0 * ratio
)

case .blue:
HSLuv(
h: 258.6,
s: 100.0 - 33.0 * ratio,
l: 30.0 + 30.0 * ratio)
l: 30.0 + 30.0 * ratio
)

case .green:
HSLuv(
h: 127.7,
s: 100.0 - 33.0 * ratio,
l: 50.0 + 25.0 * ratio)
l: 50.0 + 25.0 * ratio
)

case .yellow:
HSLuv(
h: 86,
s: 100.0 - 33.0 * ratio,
l: 70 + 30.0 * ratio)
l: 70 + 30.0 * ratio
)

case .black:
HSLuv(
h: 0,
s: 0,
l: 0 + 40.0 * ratio)
l: 0 + 40.0 * ratio
)

case .white:
HSLuv(
h: 0,
s: 0,
l: 60.0 + 40.0 * ratio)
l: 60.0 + 40.0 * ratio
)
}
return hsLuv
}
Expand Down
21 changes: 14 additions & 7 deletions Sources/WrkstrmColor/Palette+Legacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ extension Palette {
for: Gradient(rawValue: wrkstrm.rawValue)!, // swiftlint:disable:this force_unwrapping
index: index,
count: count,
reversed: reversed)
reversed: reversed
)
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand All @@ -140,7 +141,8 @@ extension Palette {
red: color.r / 255.0,
green: color.g / 255.0,
blue: color.b / 255.0,
opacity: 1.0)
opacity: 1.0
)
}
}
#endif // canImport(SwiftUI)
Expand Down Expand Up @@ -170,7 +172,8 @@ extension Palette {
for: Gradient(rawValue: wrkstrm.rawValue)!, // swiftlint:disable:this force_unwrapping
index: index,
count: count,
reversed: reversed)
reversed: reversed
)
}

public static func color(
Expand All @@ -184,7 +187,8 @@ extension Palette {
red: CGFloat(color.r / 255.0),
green: CGFloat(color.g / 255.0),
blue: CGFloat(color.b / 255.0),
alpha: 1.0)
alpha: 1.0
)
}
}
#endif
Expand All @@ -200,7 +204,8 @@ extension Palette {
reversed: Bool = false
) -> NSColor {
let color: HSLuv<CGFloat> = hsluvGradient(
for: gradient, index: index, count: count, reversed: reversed)
for: gradient, index: index, count: count, reversed: reversed
)
return NSColor(hsluv: color, alpha: 1)
}

Expand All @@ -214,7 +219,8 @@ extension Palette {
for: Gradient(rawValue: wrkstrm.rawValue)!, // swiftlint:disable:this force_unwrapping
index: index,
count: count,
reversed: reversed)
reversed: reversed
)
}

static func color(
Expand All @@ -228,7 +234,8 @@ extension Palette {
red: CGFloat(color.r / 255.0),
green: CGFloat(color.g / 255.0),
blue: CGFloat(color.b / 255.0),
alpha: 1.0)
alpha: 1.0
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/WrkstrmColor/RGBEncodable+ContrastRatio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extension UIColor {
count: 10,
aRange: Delta(start: 1, end: 0),
bRange: Delta(start: 0, end: 0),
cRange: Delta(start: 0, end: 0))
cRange: Delta(start: 0, end: 0)
)
}

extension UIFont {
Expand Down
9 changes: 6 additions & 3 deletions Tests/WrkstrmColorTests/HSLuvTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ class HSLuvTests: XCTestCase {
XCTAssertGreaterThan(
channel,
-rgbRangeTolerance,
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
XCTAssertLessThanOrEqual(
channel,
1 + rgbRangeTolerance,
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
}
}
}
Expand All @@ -87,7 +89,8 @@ class HSLuvTests: XCTestCase {
"""
Snapshots for \(hex) don't match at \(tag):
(stable: \(stableTuple), current: \(currentTuple)
""")
"""
)
}
}
}
16 changes: 11 additions & 5 deletions Tests/WrkstrmColorTests/KitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class UIKitTests: XCTestCase {
hsluv: .init(
h: CGFloat(h),
s: CGFloat(s),
l: CGFloat(l)), alpha: 1.0)
l: CGFloat(l)
), alpha: 1.0
)

XCTAssertNotNil(color)

Expand All @@ -28,11 +30,13 @@ class UIKitTests: XCTestCase {
XCTAssertGreaterThan(
channel,
-rgbRangeTolerance,
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
XCTAssertLessThanOrEqual(
channel,
1 + rgbRangeTolerance,
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
}
}
}
Expand Down Expand Up @@ -60,11 +64,13 @@ class AppKitTests: XCTestCase {
XCTAssertGreaterThan(
channel,
CGFloat(-rgbRangeTolerance),
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
XCTAssertLessThanOrEqual(
channel,
CGFloat(1 + rgbRangeTolerance),
"HSLuv: \([h, s, l]) -> RGB: \(rgb)")
"HSLuv: \([h, s, l]) -> RGB: \(rgb)"
)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/WrkstrmColorTests/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ enum Snapshot {
let jsonData = JSON.Resource.load(fileName: "snapshot-rev4"),
let jsonResult = try? JSONSerialization.jsonObject(
with: jsonData,
options: .fragmentsAllowed) as? SnapshotDictionary
options: .fragmentsAllowed
) as? SnapshotDictionary
else {
fatalError("Snapshot JSON file is missing")
}
Expand Down

0 comments on commit c21c43f

Please sign in to comment.