|
4 | 4 | // Copyright (c) 2025 owdax and The SwiftDevKit Contributors |
5 | 5 | // MIT License - https://opensource.org/licenses/MIT |
6 | 6 |
|
| 7 | +/// This file provides comprehensive color conversion utilities for iOS and macOS. |
| 8 | +/// It supports conversion between different color spaces including: |
| 9 | +/// - RGB (Red, Green, Blue) |
| 10 | +/// - HSL (Hue, Saturation, Lightness) |
| 11 | +/// - HSV (Hue, Saturation, Value) |
| 12 | +/// - CMYK (Cyan, Magenta, Yellow, Key/Black) |
| 13 | +/// - Hex string representation |
| 14 | +/// |
| 15 | +/// All color components are normalized to the range 0-1, except for hue which uses 0-360 degrees. |
| 16 | +/// The implementation handles color space conversion automatically and works consistently |
| 17 | +/// across UIKit and AppKit. |
| 18 | +/// |
| 19 | +/// Example usage: |
| 20 | +/// ```swift |
| 21 | +/// // Create colors from different formats |
| 22 | +/// let redFromHex = Color(hex: "#FF0000") |
| 23 | +/// let greenFromHSL = Color(hsl: HSL(hue: 120, saturation: 1.0, lightness: 0.5)) |
| 24 | +/// let blueFromHSV = Color(hsv: HSV(hue: 240, saturation: 1.0, value: 1.0)) |
| 25 | +/// let yellowFromCMYK = Color(cmyk: CMYK(cyan: 0, magenta: 0, yellow: 1.0, key: 0)) |
| 26 | +/// |
| 27 | +/// // Convert colors to different formats |
| 28 | +/// let color = Color.red |
| 29 | +/// let hex = color.toHex() // "#FF0000" |
| 30 | +/// let hsl = color.toHSL() // HSL(hue: 0, saturation: 1.0, lightness: 0.5) |
| 31 | +/// let hsv = color.toHSV() // HSV(hue: 0, saturation: 1.0, value: 1.0) |
| 32 | +/// let cmyk = color.toCMYK() // CMYK(cyan: 0, magenta: 1.0, yellow: 1.0, key: 0) |
| 33 | +/// ``` |
| 34 | + |
7 | 35 | import Foundation |
8 | 36 | #if canImport(UIKit) |
9 | 37 | import UIKit |
|
0 commit comments