Contents

szpakkamil/colorkit

`ColorKit` handles color conversions, perceptual gamut mapping, blending, and accessibility checks for Swift. Bridges `UIColor`, `NSColor`, and SwiftUI's `Color`.

Table of Contents

Features

  • Broad Support: sRGB, Display P3, Adobe RGB, ROMM RGB, CIE Lab*, OKLAB, LCH, CMYK.
  • Dynamic & Semantic: Light, dark, and high-contrast variants in one CKColor.
  • Perceptual Gamut Mapping: Preserves hue/lightness when converting wide-gamut (P3) to smaller spaces via OKLAB.
  • Blending Modes: Multiply, Overlay, Screen, Soft Light with correct alpha compositing.
  • Accessibility: WCAG 2.1 contrast ratios and APCA (WCAG 3.0) compliance.
  • HDR Ready: Handles extended dynamic range (EDR).
  • Codable: Persists in SwiftData, AppStorage, or UserDefaults.

Usage

Create and Use Colors

import ColorKit
import SwiftUI

// Hex String
let brandColor = CKColor(hexString: "#FF5733")

// Adaptive Semantic Color
let background = CKColor(
    hexString: "#FFFFFF",        // Light Mode
    hexStringDark: "#121212"     // Dark Mode
)

struct ContentView: View {
    var body: some View {
        Circle().fill(brandColor) // Conforms to ShapeStyle
    }
}

Color Space Conversion

// P3 to sRGB
let p3Color = CKColor(red: 1.0, green: 0.0, blue: 0.0, colorSpace: .displayP3)
let sRGBColor = p3Color.converted(to: .sRGB)

// OKLAB
let oklabColor = CKColor(okL: 0.7, okA: 0.1, okB: -0.1, colorSpace: .okLab)

Accessibility Checks

let text = CKColor(hexString: "#333333")
let bg = CKColor(hexString: "#FFFFFF")

// APCA check for 16pt text
let isReadable = text.isAPCAAccessible(on: bg, size: 16, weight: .regular)

Installation

Swift Package Manager

Add ColorKit in Package.swift or via Xcode.

dependencies: [
    .package(url: "https://github.com/SzpakKamil/ColorKit.git", from: "1.0.0")
]

Agent Skill

Install the Agent Skill for AI assistance.

npx skills add https://github.com/SzpakKamil/AgentSkills --skill ColorKit

Requirements

  • Platforms: iOS 13.0+, macOS 10.15+, tvOS 13.0+, watchOS 6.0+, visionOS 1.0+
  • Tools: Swift 5.9+, Xcode 15.0+

License

MIT

Package Metadata

Repository: szpakkamil/colorkit

Default branch: master

README: README.md