GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - DevUtilsApp/WFColorCode: NSColor extension adding ability to handle HSL color space and CSS3 style color codes

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

245 Commits
245 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
Sources/ColorCode
Sources/ColorCode
 
 
Tests/ColorCodeTests
Tests/ColorCodeTests
 
 
.gitignore
.gitignore
 
 
.swiftlint.yml
.swiftlint.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 

Repository files navigation

WFColorCode

Test Status SwiftPM compatible

WFColorCode is a NSColor extension that allows creating NSColor instance from a CSS color code string, or color code string from a NSColor instance. It also adds the ability to handle HSL color space.

  • Requirements: OS X 10.10 or later

Usage

WFColorCode supports the following color code styles.

/// color code type
enum ColorCodeType: Int {
    case hex        // #ffffff
    case shortHex   // #fff
    case cssRGB     // rgb(255,255,255)
    case cssRGBa    // rgba(255,255,255,1)
    case cssHSL     // hsl(0,0%,100%)
    case cssHSLa    // hsla(0,0%,100%,1)
    case cssKeyword // White
};

Example

Import ColorCode to use.

import ColorCode

// create NSColor instance from HSLa color code
var type: ColorCodeType?
let whiteColor = NSColor(colorCode: "hsla(0,0%,100%,0.5)", type: &type)
let hex: String = whiteColor.colorCode(type: .hex)  // => "#ffffff"

// create NSColor instance from HSLa values
let color = NSColor(deviceHue:0.1, saturation:0.2, lightness:0.3, alpha:1.0)

// create NSColor instance from a CSS3 keyword
let ivoryColor = NSColor(colorCode: "ivory")

// get HSL values from NSColor instance
var hue: CGFloat = 0
var saturation: CGFloat = 0
var lightness: CGFloat = 0
var alpha: CGFloat = 0
color.getHue(hue: &hue, saturation: &saturation, lightness: &lightness, alpha: &alpha)

License

© 2014-2022 1024jp.

The source code is distributed under the terms of the MIT License. See the bundled LICENSE for details.

About

NSColor extension adding ability to handle HSL color space and CSS3 style color codes

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.