{"id":21064614,"url":"https://github.com/capturecontext/swift-generic-color","last_synced_at":"2025-05-16T02:32:43.948Z","repository":{"id":63906747,"uuid":"228272863","full_name":"CaptureContext/swift-generic-color","owner":"CaptureContext","description":"Platform-agnostic color library written in Swift","archived":false,"fork":false,"pushed_at":"2021-10-25T13:44:10.000Z","size":120,"stargazers_count":8,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-08T11:52:09.331Z","etag":null,"topics":["colors","generic","generics","ios","linux","osx","swift","ui","ux","web"],"latest_commit_sha":null,"homepage":null,"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/CaptureContext.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2019-12-16T00:29:03.000Z","updated_at":"2024-07-06T13:49:02.000Z","dependencies_parsed_at":"2022-11-28T22:46:18.505Z","dependency_job_id":null,"html_url":"https://github.com/CaptureContext/swift-generic-color","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-generic-color","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-generic-color/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-generic-color/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-generic-color/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptureContext","download_url":"https://codeload.github.com/CaptureContext/swift-generic-color/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254456163,"owners_count":22074120,"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":["colors","generic","generics","ios","linux","osx","swift","ui","ux","web"],"created_at":"2024-11-19T17:50:17.774Z","updated_at":"2025-05-16T02:32:43.421Z","avatar_url":"https://github.com/CaptureContext.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"Assets/GenericColor-Logo-Pink.png\" width=100%/\u003e\n\u003c/p\u003e\n\u003cp\u003e\n    \u003ca href=\"https://swift.org\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-5.3-orange.svg?logo=swift\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org/package-manager\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg?style=flat\" alt=\"SwiftPM\" /\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Platforms-Mac \u0026 Linux-green.svg?style=flat\" alt=\"Mac \u0026 Linux\" /\u003e\n    \u003ca href=\"https://twitter.com/maximkrouk\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/twitter-@maximkrouk-blue.svg?logo=twitter\u0026style=social\" alt=\"Twitter: @maximkrouk\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\nPlatform agnostic color Library.\n\n## Usage\n\n```swift\nimport GenericColor\n```\n\n#### Initialization\n\n```swift\n// Initialize with byte value via .byte(_) method\nlet color1 = Color\u003cRGB\u003e(\n  red: .byte(221),\n  green: .byte(51),\n  blue: .byte(12),\n  alpha: .byte(255)\n)\n\n// or directly via numeric literals and .raw(_) method for numerics\nlet alpha = 1\nlet color2 = Color\u003cRGB\u003e(\n  red: .max, \n  green: 0.2, \n  blue: .byte(12),\n  alpha: .raw(alpha)\n)\n\nprint(color1 == color2) // true\n\n// hex initialization is supported for RGB color space\n// - works with \"#\" prefix and without, case-insensitive\n// - works with rgb, rgba, rrggbb, rrggbbaa representations\n// - avalible trough .hex and .init(hex:)\nColor.hex(\"FA6878\") // Type == Color\u003cRGB\u003e?\nColor(hex: \"#aaaf\") // rgba, the same as #AAAAAAFF\n\n// or use hex literals\nColor(rgb: 0xfa6878)\nColor(rgba: 0xfa6878ff)\nColor.rgb(0xAAAAAA)\n\n// you can also get an rgb hex value of any color\ncolor1.hex()\ncolor2.hex(uppercased: true)\ncolor3.hex(hashTagPrefix: true)\n\n// color literals will work too, but accuracy is not guarantied\nlet literal: Color\u003cRGB\u003e = #colorLiteral(red: 0.9803921568627451, green: 0.40784313725490196, blue: 0.47058823529411764, alpha: 1)\n```\n\n#### ColorSpaces\n\n```swift\nlet color1 = Color\u003cRGB\u003e()\nlet color2 = Color\u003cHSB\u003e()\nlet color3 = Color\u003cCMYK\u003e()\n\n// Implicit convertions\nprint(color1.convert() == color2)\nprint(color1.convert() == color3)\nprint(color2.convert() == color1)\n\n// Explicit convertions\nprint(color1.convert(to: HSB.self) == color2)\nprint(color1.convert(to: CMYK.self) == color3)\nprint(color2.convert(to: RGB.self) == color1)\n\n// Container mappings\nprint(color2.map(to: \\.cmyk) == color3)\nprint(color3.map(to: \\.rgb) == color1)\nprint(color3.map(to: \\.hsb) == color2)\n\n// Color flat mappings\nprint(color1.flatMap { $0.with(alpha: 1) })\n```\n\n## Installation\n\nAdd the package to Your SwiftPM package dependencies:\n\n```swift\n.package(\n  name: \"swift-generic-color\",\n  url: \"https://github.com/capturecontext/swift-generic-color.git\",\n  .upToNextMinor(from: \"0.5.0\")\n)\n```\n\nthen add `GenericColor` dependency to your target\n\n```swift\n.product(\n  name: \"GenericColor\",\n  package: \"GenericColor\"\n)\n```\n\n\n\n## More\n\nSee tests for more usage examples.\n\nCheck out higher-level framework [Palette](https://github.com/capturecontext/palette) for more.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-generic-color","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapturecontext%2Fswift-generic-color","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-generic-color/lists"}