forked from Clipy/Clipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Clipy#154 from Clipy/release/v1.1.3
Release v1.1.3
- Loading branch information
Showing
641 changed files
with
20,479 additions
and
15,077 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Collection+Safe.swift | ||
// Clipy | ||
// | ||
// Created by 古林俊佑 on 2017/03/01. | ||
// Copyright © 2017年 Shunsuke Furubayashi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Collection { | ||
subscript(safe index: Index) -> _Element? { | ||
return index >= startIndex && index < endIndex ? self[index] : nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NSCoding+Archive.swift | ||
// Clipy | ||
// | ||
// Created by 古林俊佑 on 2016/11/19. | ||
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NSCoding { | ||
func archive() -> Data { | ||
return NSKeyedArchiver.archivedData(withRootObject: self) | ||
} | ||
} | ||
|
||
extension Array where Element: NSCoding { | ||
func archive() -> Data { | ||
return NSKeyedArchiver.archivedData(withRootObject: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// NSColor+Hex.swift | ||
// Clipy | ||
// | ||
// Created by 古林俊佑 on 2016/11/21. | ||
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved. | ||
// | ||
// Rewrote it for NSColor with reference to the following | ||
// https://github.com/yeahdongcn/UIColor-Hex-Swift | ||
|
||
import Cocoa | ||
|
||
extension NSColor { | ||
|
||
convenience init(hex3: UInt16, alpha: CGFloat = 1) { | ||
let divisor = CGFloat(16) | ||
let red = CGFloat((hex3 & 0xF00) >> 8) / divisor | ||
let green = CGFloat((hex3 & 0x0F0) >> 4) / divisor | ||
let blue = CGFloat( hex3 & 0x00F ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
convenience init(hex4: UInt16) { | ||
let divisor = CGFloat(15) | ||
let red = CGFloat((hex4 & 0xF000) >> 12) / divisor | ||
let green = CGFloat((hex4 & 0x0F00) >> 8) / divisor | ||
let blue = CGFloat((hex4 & 0x00F0) >> 4) / divisor | ||
let alpha = CGFloat( hex4 & 0x000F ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
public convenience init(hex6: UInt32, alpha: CGFloat = 1) { | ||
let divisor = CGFloat(255) | ||
let red = CGFloat((hex6 & 0xFF0000) >> 16) / divisor | ||
let green = CGFloat((hex6 & 0x00FF00) >> 8) / divisor | ||
let blue = CGFloat( hex6 & 0x0000FF ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
public convenience init(hex8: UInt32) { | ||
let divisor = CGFloat(255) | ||
let red = CGFloat((hex8 & 0xFF000000) >> 24) / divisor | ||
let green = CGFloat((hex8 & 0x00FF0000) >> 16) / divisor | ||
let blue = CGFloat((hex8 & 0x0000FF00) >> 8) / divisor | ||
let alpha = CGFloat( hex8 & 0x000000FF ) / divisor | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
public convenience init?(hex rgba: String) { | ||
guard rgba.hasPrefix("#") else { return nil } | ||
|
||
let hexString: String = rgba.substring(from: rgba.characters.index(rgba.startIndex, offsetBy: 1)) | ||
var hexValue: UInt32 = 0 | ||
|
||
guard Scanner(string: hexString).scanHexInt32(&hexValue) else { return nil } | ||
|
||
/** | ||
* Images with alpha cannot be previewed and not be created | ||
*/ | ||
switch hexString.characters.count { | ||
case 3: | ||
self.init(hex3: UInt16(hexValue)) | ||
case 6: | ||
self.init(hex6: hexValue) | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// NSImage+NSColor.swift | ||
// Clipy | ||
// | ||
// Created by 古林俊佑 on 2016/11/21. | ||
// Copyright © 2016年 Shunsuke Furubayashi. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
extension NSImage { | ||
static func create(with color: NSColor, size: NSSize) -> NSImage { | ||
let image = NSImage(size: size) | ||
image.lockFocus() | ||
color.drawSwatch(in: NSRect(x: 0, y: 0, width: size.width, height: size.height)) | ||
image.unlockFocus() | ||
return image | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.