Git Product home page Git Product logo

color's Introduction

Color.swiftpm

Color simplifies color objects into a standard syntax that can be used cross platform and adds basic Codable and string representation and conversion for HTML colors and hexadecimal colors.

The primary goals are to be easily maintainable by multiple individuals, employ a consistent API that can be used across all platforms, and to be maintainable using Swift Playgrounds on iPad and macOS. APIs are typically present even on platforms that don't support all features so that availability checks do not have to be performed in external code, and where irrelevant, code can simply return optionals.

This is actively maintained so if there is a feature request or change, we will strive to address within a week.

Features

  • Can develop and modify without Xcode using Swift Playgrounds on iPad!
  • String initialization with the following formats:
    • Named CSS/HTML colors (case insensitive, ex: "LightSteelBlue")
    • Hexadecimal colors (3 or 6 character format, case insensitive, ex: "#c3a", "#cc33aa", "#C0FFEE")
    • CSS rgb/a colors (case insensitive, space insensitive, values out of 255 but extended colors beyond this are supported, optional alpha parameter should be between 0.0 and 1.0, eg: "rgb(255, 0,0)", "rgb(238, 130, 238, 0.2)")
  • Allows consistent API usage with SwiftUI Color, NSColor, and UIColor so code can be platform agnostic.
  • Adds .magenta, .lightGray, and .darkGray to the standard named colors and ensures .pink is available on all platforms.
  • Ability to get lighter and darker colors from a base color.
  • Ability to determine if colors are "light" or "dark" to ensure contrasting colors are used.
  • Has preset color lists that can be iterated like [Color].rainbow.
  • Standard color names for DOT signage colors.

Requirements

  • iOS 11+ (15 required for .brown, .cyan, .indigo, .mint, and .teal, 15.2+ minimum required for Swift Playgrounds support)
  • macOS 10.5+ (macOS 11 required for cgColor conversions, macOS 12 minimum for .brown, .cyan, .indigo, .mint, and .teal)
  • macCatalyst 13+ (first version available)
  • tvOS 11+ (15 required for .brown, .cyan, .indigo, .mint, and .teal)
  • watchOS 4+ (UI only supported on watchOS 8+)
  • visionOS 1+
  • Theoretically should work with Linux, Windows, and Vapor, but haven't tested. If you would like to help, please let us know.

Known Issues

See CHANGELOG.md for known issues and roadmap

Installation

Install by adding this as a package dependency to your code. This can be done in Xcode or Swift Playgrounds!

Swift Package Manager

Swift 5+

You can try these examples in a Swift Playground by adding package: https://github.com/kudit/Color

If the repository is private, use the following link to import: https://<your-PAT-string>@github.com/kudit/Color.git

Or you can manually enter the following in the Package.swift file:

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

Usage

First make sure to import the framework:

import Color

Here are some usage examples.

Get the version of Color that is imported.

let version = Color.version

Create a color from a hex string.

let color: Color = "#ff0000" // should create a red color

Create a color from a named CSS string.

let color: Color = "red" // should create a red color

Get a list of rainbow primary colors.

let colors: [Color] = .rainbow

All these tests can be demonstrated using previews or by running the app executable that is bundled in the Development folder of the module.

Contributing

If you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue. If you extended the functionality yourself and want others to use it too, please submit a pull request.

Donations

This was a lot of work. If you find this useful particularly if you use this in a commercial product, please consider making a donation to http://paypal.me/kudit

License

Feel free to use this in projects, however, please include a link back to this project and credit somewhere in the app. Example Markdown and string interpolation for the version:

Text("Open Source projects used include [Color](https://github.com/kudit/Color) v\(Color.version)

Contributors

The complete list of people who contributed to this project is available here. A big thanks to everyone who has contributed! ๐Ÿ™

color's People

Contributors

kudit avatar

Stargazers

Adam Hill avatar

Watchers

 avatar  avatar

color's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.