{"id":20580858,"url":"https://github.com/soffes/color","last_synced_at":"2025-04-14T19:45:49.637Z","repository":{"id":66689550,"uuid":"97438807","full_name":"soffes/Color","owner":"soffes","description":"Color utilities for macOS, iOS, tvOS, and watchOS","archived":false,"fork":false,"pushed_at":"2022-12-07T16:46:55.000Z","size":71,"stargazers_count":160,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T08:11:17.848Z","etag":null,"topics":["accessibility","carthage","cocoapods","ios","macos","spm","swift","tvos","watchos","wcag"],"latest_commit_sha":null,"homepage":"https://usecontrast.com","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soffes.png","metadata":{"files":{"readme":"Readme.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-17T05:36:50.000Z","updated_at":"2024-07-20T08:13:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"634ea3fa-a912-4d79-85bf-f887e5f28fa0","html_url":"https://github.com/soffes/Color","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soffes%2FColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soffes","download_url":"https://codeload.github.com/soffes/Color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248950560,"owners_count":21188294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accessibility","carthage","cocoapods","ios","macos","spm","swift","tvos","watchos","wcag"],"created_at":"2024-11-16T06:25:47.703Z","updated_at":"2025-04-14T19:45:49.632Z","avatar_url":"https://github.com/soffes.png","language":"Swift","readme":"# Color\n\n[![Version](https://img.shields.io/github/release/soffes/Color.svg)](https://github.com/soffes/Color/releases)\n[![Build Status](https://github.com/soffes/Color/workflows/Tests/badge.svg)](https://github.com/soffes/Color/actions)\n![Swift Version](https://img.shields.io/badge/swift-5.0.1-orange.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nColor utilities in pure Swift for macOS, iOS, watchOS, and tvOS. Color supports Carthage and Swift Package Manager. It is also [tested](https://travis-ci.org/soffes/Color) on Linux.\n\n**Color was abstracted from [Contrast](https://usecontrast.com), a macOS app for checking designs for accessible color combinations.**\n\n\n## Installation\n\n### Carthage\n\nAdd the following to your Cartfile:\n\n```ruby\ngithub \"soffes/Color\"\n```\n\n### Swift Package Manager\n\nAdd the following to your `dependencies` in your Package.swift:\n\n```swift\n.package(url: \"https://github.com/soffes/Color.git\", from: \"0.1.1\")\n```\n\n\n## Usage\n\nColor provides structs for different color models. Currently only RGB and HSL are supported. Most color calculations are specific to a color model. For example, darkening a color is only available for HSL colors and not RGB colors. If you'd like to darken an RGB color, you’ll need to convert to HSL first. Here’s an example:\n\n```swift\nlet rgb = RGBColor(red: 1, green: 0, blue: 0)\nlet hsl = HSLColor(rgb: rgb)\nlet darkerRed = hsl.darkening()\n```\n\nNote that Color’s structs don’t support alpha since that isn’t used in any of the color calculations. This may be added in the future.\n\nHex conversions are only available for RGB colors.\n\n```swift\nlet rgb = RGBColor(hex: \"0f0\")!\nrgb.hex // \"00ff00\"\n```\n\n\n### NSColor \u0026 UIColor\n\nThere are convenience methods on `NSColor` \u0026 `UIColor` if you are working in a Cocoa application. Each color model (`RGBColor`, `HSLColor`, etc.) has an extension for `SystemColorType` which is either `NSColor` or `UIColor` depending on the platform. Here's a few examples:\n\n```swift\nUIColor.red.darkening()\nUIColor.green.desaturating()\nNSColor.blue.isDark\n```\n\n\n### WCAG\n\nRGB colors also have [WCAG 2.0](https://www.w3.org/TR/WCAG20) calculations. First, calculate a contrast ratio:\n\n```swift\nlet color1 = RGBColor(red: 170.0 / 255.0, green: 204.0 / 255.0, blue: 1)\nlet color2 = RGBColor(red: 34.0 / 255.0, green: 34.0 / 255.0, blue: 51.0 / 255.0)\nlet contrastRatio = color1.contrastRatio(to: color2) // 9.51\n```\n\nNow, you can check the conformance level:\n\n```swift\nConformanceLevel(contrastRatio: contrastRatio) // .aaa\n```\n\n\n## Thanks\n\nThanks to [color](https://github.com/Qix-/color) \u0026 [color-convert](https://github.com/Qix-/color-convert) for inspiration.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoffes%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoffes%2Fcolor/lists"}