### Install ChromaKit with Swift Package Manager Source: https://context7.com/harshilshah/chromakit/llms.txt Add ChromaKit as a dependency in your Package.swift file and include it in your target. ```swift let package = Package( name: "MyApp", dependencies: [ .package(url: "https://github.com/HarshilShah/ChromaKit", from: "1.0.0") ], targets: [ .target( name: "MyApp", dependencies: ["ChromaKit"] ) ] ) ``` -------------------------------- ### Manual Color Space Conversions in ChromaKit Source: https://context7.com/harshilshah/chromakit/llms.txt Demonstrates manual conversion pipelines between different color spaces (Lch, Lab, XYZ, P3) and constructing values directly. Use for custom color space pipelines or intermediate value inspection. ```swift import ChromaKit // Manually walk the conversion pipeline: Lch → Lab → XYZ → P3 let lch = Lch(l: 67.21298, c: 43.18819, h: 66.09192) let lab: Lab = lch.lab() // CIELab intermediate let xyz: XYZ = lch.xyz() // CIE XYZ intermediate let p3: P3 = lch.p3() // Final Display P3 output print(p3.r, p3.g, p3.b) // ~0.8, ~0.6, ~0.4 // Manually construct and convert an Oklab value let oklab = Oklab(l: 0.72385, a: 0.04934, b: 0.09383) let okXyz: XYZ = oklab.xyz() let okP3: P3 = oklab.p3() print(okP3.r, okP3.g, okP3.b) // ~0.8, ~0.6, ~0.4 // Oklch → Oklab → XYZ → P3 shortcut let oklch = Oklch(l: 0.72385, c: 0.10601, h: 62.26385) let converted: P3 = oklch.p3() ``` ```swift let linearP3 = P3(r: 0.6038, g: 0.3294, b: 0.1329) let gammaP3 = linearP3.gammaCorrected() // Applies IEC 61966-2-1 transfer function ``` -------------------------------- ### Add ChromaKit to Xcode Project Source: https://github.com/harshilshah/chromakit/blob/main/README.md Integrate ChromaKit into your Xcode project by navigating to File > Add Packages and entering the repository URL. ```swift https://github.com/HarshilShah/ChromaKit ``` -------------------------------- ### Create AppKit Colors from Perceptual Color Spaces Source: https://context7.com/harshilshah/chromakit/llms.txt Creates NSColor values in the Display P3 color space from CIELch, Oklch, CIELab, or Oklab coordinates. This is available on macOS only. ```swift #if canImport(AppKit) && !targetEnvironment(macCatalyst) import AppKit import ChromaKit // Define a macOS app color asset set in code enum AppColors { static let accentLch = NSColor.lch(55, 80, 260) static let accentOklch = NSColor.oklch(0.58, 0.18, 262) static let backgroundLab = NSColor.lab(97, 0, 0) // Near-white static let highlightOklab = NSColor.oklab(0.85, -0.05, 0.10) // Warm green tint // With custom alpha static let overlayColor = NSColor.lch(20, 10, 250, 0.6) // 60% opaque dark blue } // Apply in a custom NSView class CustomView: NSView { override func draw(_ dirtyRect: NSRect) { AppColors.backgroundLab.setFill() dirtyRect.fill() AppColors.accentLch.setStroke() NSBezierPath(roundedRect: bounds.insetBy(dx: 4, dy: 4), xRadius: 6, yRadius: 6).stroke() } } #endif ``` -------------------------------- ### Create SwiftUI Color from Oklab Coordinates Source: https://context7.com/harshilshah/chromakit/llms.txt Use this to create SwiftUI.Color instances from Oklab coordinates. Oklab is ideal for perceptual interpolation and smooth gradients. ```swift import SwiftUI import ChromaKit struct OklabGradientView: View { // Interpolate between two Oklab colors by varying 'a' and 'b' private func interpolatedColor(t: Double) -> Color { // From neutral (0.7, 0, 0) to saturated green-yellow (0.7, -0.15, 0.12) Color.oklab(0.7, -0.15 * t, 0.12 * t) } var body: some View { LinearGradient( stops: (0...10).map { i in let t = Double(i) / 10.0 return Gradient.Stop(color: interpolatedColor(t: t), location: t) }, startPoint: .leading, endPoint: .trailing ) .frame(height: 60) .clipShape(RoundedRectangle(cornerRadius: 8)) .padding() } } ``` -------------------------------- ### Create Colors in Different Color Spaces with ChromaKit Source: https://github.com/harshilshah/chromakit/blob/main/README.md Use static functions on Color, UIColor, or NSColor to create colors in Lch, Lab, Oklch, and Oklab spaces. Ensure ChromaKit is imported. ```swift import ChromaKit let lch = Color.lch(80, 80, 80) let lab = Color.lab(80, 13.89, 78.78) let oklch = UIColor.oklch(0.833, 0.168, 80.115) let oklab = NSColor.oklab(0.833, 0.029, 0.165) ``` -------------------------------- ### UIKit Lab and Oklab Colors Source: https://context7.com/harshilshah/chromakit/llms.txt Creates UIColor values from CIELab or Oklab coordinates, matching CSS `lab()` and `oklab()` values. ```APIDOC ## `UIColor.lab(_:_:_:_:)` and `UIColor.oklab(_:_:_:_:)` — UIKit Lab Colors Creates `UIColor` values from CIELab or Oklab coordinates. Useful for precise color specification matching CSS `lab()` and `oklab()` values. ### Usage Example ```swift import UIKit import ChromaKit let cssLabColor = UIColor.lab(67.21298, 17.5029, 39.48251) let cssOklabColor = UIColor.oklab(0.72385, 0.04934, 0.09383) ``` ``` -------------------------------- ### AppKit Colors (macOS) Source: https://context7.com/harshilshah/chromakit/llms.txt Creates NSColor values (Display P3 color space) from CIELch, Oklch, CIELab, or Oklab coordinates. Available on macOS only. ```APIDOC ## `NSColor.lch(_:_:_:_:)`, `NSColor.oklch(_:_:_:_:)`, `NSColor.lab(_:_:_:_:)`, `NSColor.oklab(_:_:_:_:)` — AppKit Colors Creates `NSColor` values (Display P3 color space) from any of the four supported perceptual color spaces. Available on macOS only (excluded from Mac Catalyst). ### Usage Example ```swift #if canImport(AppKit) && !targetEnvironment(macCatalyst) import AppKit import ChromaKit enum AppColors { static let accentLch = NSColor.lch(55, 80, 260) static let accentOklch = NSColor.oklch(0.58, 0.18, 262) static let backgroundLab = NSColor.lab(97, 0, 0) static let highlightOklab = NSColor.oklab(0.85, -0.05, 0.10) static let overlayColor = NSColor.lch(20, 10, 250, 0.6) } class CustomView: NSView { override func draw(_ dirtyRect: NSRect) { AppColors.backgroundLab.setFill() dirtyRect.fill() AppColors.accentLch.setStroke() NSBezierPath(roundedRect: bounds.insetBy(dx: 4, dy: 4), xRadius: 6, yRadius: 6).stroke() } } #endif ``` ``` -------------------------------- ### SwiftUI Color from Oklab Source: https://context7.com/harshilshah/chromakit/llms.txt Creates a SwiftUI.Color from Oklab coordinates (lightness, green-red, blue-yellow). Suitable for perceptual interpolation and gradients. ```APIDOC ## `Color.oklab(_:_:_:_:)` — SwiftUI Color from Oklab Creates a `SwiftUI.Color` from Oklab coordinates: perceptual lightness L (0–1), green-red axis a (−0.4 to 0.4), and blue-yellow axis b (−0.4 to 0.4). Oklab is especially suitable for perceptual interpolation and smooth gradients. ### Usage Example ```swift import SwiftUI import ChromaKit struct OklabGradientView: View { private func interpolatedColor(t: Double) -> Color { Color.oklab(0.7, -0.15 * t, 0.12 * t) } var body: some View { LinearGradient( stops: (0...10).map { i in let t = Double(i) / 10.0 return Gradient.Stop(color: interpolatedColor(t: t), location: t) }, startPoint: .leading, endPoint: .trailing ) .frame(height: 60) .clipShape(RoundedRectangle(cornerRadius: 8)) .padding() } } ``` ``` -------------------------------- ### Create UIKit Color from CIELch Coordinates Source: https://context7.com/harshilshah/chromakit/llms.txt Generates UIColor instances from CIELch coordinates. This is available on iOS, iPadOS, tvOS, watchOS, and Mac Catalyst. ```swift import UIKit import ChromaKit class ThemeColors { // Primary brand color static let primary = UIColor.lch(55, 70, 260) // Blue-violet static let secondary = UIColor.lch(65, 55, 150) // Green static let danger = UIColor.lch(50, 90, 25) // Red static let warning = UIColor.lch(75, 80, 80) // Yellow-orange } class MyViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let button = UIButton(type: .system) button.backgroundColor = ThemeColors.primary button.setTitleColor(.white, for: .normal) button.layer.cornerRadius = 8 view.addSubview(button) } } ``` -------------------------------- ### Create UIKit Color from Oklch Coordinates Source: https://context7.com/harshilshah/chromakit/llms.txt Creates UIColor instances from Oklch coordinates, suitable for all UIKit platforms. Useful for generating palettes with consistent lightness and chroma across different hues. ```swift import UIKit import ChromaKit // Generate a hue-rotated palette at constant perceptual lightness and chroma func oklchPalette(steps: Int, lightness: Double = 0.65, chroma: Double = 0.13) -> [UIColor] { (0.. some View { let baseL: Double = configuration.isPressed ? 0.55 : 0.65 // Perceptual blue-purple, chroma 0.15, hue 270° let fill = Color.oklch(baseL, 0.15, 270) return configuration.label .padding(.horizontal, 20) .padding(.vertical, 10) .background(fill) .foregroundStyle(.white) .clipShape(Capsule()) .animation(.easeInOut(duration: 0.1), value: configuration.isPressed) } } // Usage Button("Tap Me") { } .buttonStyle(AccessibleButtonStyle()) ``` -------------------------------- ### UIKit Color from CIELch Source: https://context7.com/harshilshah/chromakit/llms.txt Creates a UIColor from CIELch coordinates (lightness, chroma, hue). Available on iOS, iPadOS, tvOS, watchOS, and Mac Catalyst. ```APIDOC ## `UIColor.lch(_:_:_:_:)` — UIKit Color from CIELch Creates a `UIColor` from CIELch coordinates. Available on iOS, iPadOS, tvOS, watchOS, and Mac Catalyst targets. ### Usage Example ```swift import UIKit import ChromaKit class ThemeColors { static let primary = UIColor.lch(55, 70, 260) static let secondary = UIColor.lch(65, 55, 150) static let danger = UIColor.lch(50, 90, 25) static let warning = UIColor.lch(75, 80, 80) } ``` ``` -------------------------------- ### Add ChromaKit as SPM Dependency Source: https://github.com/harshilshah/chromakit/blob/main/README.md To use ChromaKit in your Swift Package Manager project, add the repository URL to your Package.swift dependencies and include the product for your target. ```swift .package(url: "https://github.com/HarshilShah/ChromaKit") ``` ```swift .product(name: "ChromaKit", package: "ChromaKit") ``` -------------------------------- ### Color.oklch(_:_:_:_:) - SwiftUI Color from Oklch Source: https://context7.com/harshilshah/chromakit/llms.txt Creates a SwiftUI Color using Oklch coordinates: perceptual lightness (0–1), chroma (0–~0.5), and hue angle (0–360°). Oklch offers more perceptually uniform lightness than CIELch. ```APIDOC ## Color.oklch(_:_:_:_:) - SwiftUI Color from Oklch ### Description Creates a `SwiftUI.Color` using Oklch coordinates: perceptual lightness (0–1), chroma (0–~0.5), and hue angle (0–360°). Oklch offers more perceptually uniform lightness than CIELch, making it ideal for generating accessible color palettes. ### Parameters - **lightness** (Double) - Perceptual lightness value (0-1). - **chroma** (Double) - Chroma value (0-~0.5). - **hue** (Double) - Hue angle (0-360°). - **alpha** (Double, optional) - Alpha value (0-1). Defaults to 1.0. ### Request Example ```swift import SwiftUI import ChromaKit struct AccessibleButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { let baseL: Double = configuration.isPressed ? 0.55 : 0.65 // Perceptual blue-purple, chroma 0.15, hue 270° let fill = Color.oklch(baseL, 0.15, 270) return configuration.label .padding(.horizontal, 20) .padding(.vertical, 10) .background(fill) .foregroundStyle(.white) .clipShape(Capsule()) .animation(.easeInOut(duration: 0.1), value: configuration.isPressed) } } // Usage Button("Tap Me") { } .buttonStyle(AccessibleButtonStyle()) ``` ### Response #### Success Response (Color) Returns a `SwiftUI.Color` instance representing the specified Oklch color. ``` -------------------------------- ### UIKit Color from Oklch Source: https://context7.com/harshilshah/chromakit/llms.txt Creates a UIColor from Oklch coordinates (lightness, chroma, hue). Available on all UIKit platforms. ```APIDOC ## `UIColor.oklch(_:_:_:_:)` — UIKit Color from Oklch Creates a `UIColor` from Oklch coordinates. Available on all UIKit platforms. ### Usage Example ```swift import UIKit import ChromaKit func oklchPalette(steps: Int, lightness: Double = 0.65, chroma: Double = 0.13) -> [UIColor] { (0..