Add support for iOS 15 and unicode release v13 (#1)
This commit is contained in:
committed by
GitHub
parent
6bbb3a1a71
commit
977c01327f
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// DataProcessor.swift
|
||||
//
|
||||
//
|
||||
// Created by Niklas Amslgruber on 12.06.23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import EmojiKitLibrary
|
||||
|
||||
public enum DataProcessor {
|
||||
|
||||
public enum EmojiUnicodeVersion: Int {
|
||||
case v14 = 14
|
||||
case v15 = 15
|
||||
|
||||
public var fileName: String {
|
||||
return "emojis_v\(rawValue).json"
|
||||
}
|
||||
|
||||
public static func getSupportedVersionForCurrentIOSVersion() -> EmojiUnicodeVersion {
|
||||
if #available(iOS 16.4, *) {
|
||||
return .v15
|
||||
} else {
|
||||
return .v14
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum SkinType {
|
||||
case neutral
|
||||
case light
|
||||
case mediumLight
|
||||
case medium
|
||||
case mediumDark
|
||||
case dark
|
||||
|
||||
var unicode: String {
|
||||
switch self {
|
||||
case .neutral:
|
||||
return ""
|
||||
case .light:
|
||||
return "1F3FB"
|
||||
case .mediumLight:
|
||||
return "1F3FC"
|
||||
case .medium:
|
||||
return "1F3FD"
|
||||
case .mediumDark:
|
||||
return "1F3FE"
|
||||
case .dark:
|
||||
return "1F3FF"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func getEmojis(at url: URL, for version: EmojiUnicodeVersion, skinTypes: [SkinType] = [.neutral]) -> [EmojiCategory] {
|
||||
guard let content = try? Data(contentsOf: url), let result = try? JSONDecoder().decode([EmojiCategory].self, from: content) else {
|
||||
return []
|
||||
}
|
||||
|
||||
var filteredEmojis: [EmojiCategory] = []
|
||||
for wrapper in result {
|
||||
let supportedEmojis = wrapper.values.filter({
|
||||
isMatchingSkinType(of: $0, for: skinTypes)
|
||||
})
|
||||
filteredEmojis.append(EmojiCategory(name: wrapper.name, values: supportedEmojis))
|
||||
}
|
||||
return filteredEmojis
|
||||
}
|
||||
|
||||
private static func isMatchingSkinType(of emoji: String, for skinTypes: [SkinType]) -> Bool {
|
||||
let unicodes = getUnicodes(emoji: emoji)
|
||||
|
||||
for skinType in skinTypes where unicodes.contains(skinType.unicode) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private static func getUnicodes(emoji: String) -> [String] {
|
||||
let unicodeScalars = emoji.unicodeScalars
|
||||
let unicodes = unicodeScalars.map { $0.value }
|
||||
return unicodes.map { String($0, radix: 16, uppercase: true) }
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,11 @@ public class EmojiCategory: Codable {
|
||||
return EmojiCategory.Name.allCases.sorted(by: { $0.order < $1.order })
|
||||
}
|
||||
|
||||
// The component category does not include relevant emojis
|
||||
public static var relevantCases: [EmojiCategory.Name] {
|
||||
return EmojiCategory.Name.orderedCases.filter({ $0 != .components })
|
||||
}
|
||||
|
||||
// Order that Apple uses in their emoji picker
|
||||
public var order: Int {
|
||||
switch self {
|
||||
@@ -9,19 +9,33 @@ import Foundation
|
||||
|
||||
public enum EmojiManager {
|
||||
|
||||
public enum Version: Int {
|
||||
public enum Version: Double {
|
||||
case v13_1 = 13.1
|
||||
case v14 = 14
|
||||
case v15 = 15
|
||||
|
||||
public var fileName: String {
|
||||
return "emojis_v\(rawValue)"
|
||||
return "emojis_v\(versionIdentifier)"
|
||||
}
|
||||
|
||||
public var versionIdentifier: String {
|
||||
switch self {
|
||||
case .v13_1:
|
||||
return "13.1"
|
||||
case .v14:
|
||||
return "14.0"
|
||||
case .v15:
|
||||
return "15.0"
|
||||
}
|
||||
}
|
||||
|
||||
public static func getSupportedVersion() -> Version {
|
||||
if #available(iOS 16.4, *) {
|
||||
return .v15
|
||||
} else {
|
||||
} else if #available(iOS 15.4, *) {
|
||||
return .v14
|
||||
} else {
|
||||
return .v13_1
|
||||
}
|
||||
}
|
||||
}
|
||||
3573
Sources/EmojiKit/Resources/emojis_v13.1.json
Normal file
3573
Sources/EmojiKit/Resources/emojis_v13.1.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
import EmojiKitLibrary
|
||||
import EmojiKit
|
||||
|
||||
struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
|
||||
@@ -17,7 +17,19 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
)
|
||||
|
||||
@Argument var path: String
|
||||
@Option(name: .shortAndLong) var version: DataProcessor.EmojiUnicodeVersion = .v15
|
||||
@Option(name: .shortAndLong) var version: EmojiManager.Version = .v15
|
||||
|
||||
private func getPath() -> String {
|
||||
#if DEBUG
|
||||
var url = URL(filePath: #file)
|
||||
url = url.deletingLastPathComponent().deletingLastPathComponent()
|
||||
url.append(path: "EmojiKitLibrary/Resources")
|
||||
|
||||
return url.absoluteString
|
||||
#else
|
||||
return path
|
||||
#endif
|
||||
}
|
||||
|
||||
func run() async throws {
|
||||
print("⚙️", "Starting to download all emojis for version \(version.rawValue) from unicode.org...\n")
|
||||
@@ -44,8 +56,6 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
|
||||
print("🎉", "Successfully parsed emojis and matched counts to the count file.\n")
|
||||
|
||||
print("⚙️", "Saving emojis to file emojis_v\(version.rawValue).json...\n")
|
||||
|
||||
save(data: emojisByCategory, for: version)
|
||||
|
||||
print("🎉", "Successfully saved emojis to file.\n")
|
||||
@@ -55,12 +65,12 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
}
|
||||
}
|
||||
|
||||
func getTemporaryURLForEmojiList(version: DataProcessor.EmojiUnicodeVersion) async -> URL? {
|
||||
return await load(urlString: "https://unicode.org/Public/emoji/\(version.rawValue).0/emoji-test.txt")
|
||||
func getTemporaryURLForEmojiList(version: EmojiManager.Version) async -> URL? {
|
||||
return await load(urlString: "https://unicode.org/Public/emoji/\(version.versionIdentifier)/emoji-test.txt")
|
||||
}
|
||||
|
||||
func getTemporaryURLForEmojiCounts(version: DataProcessor.EmojiUnicodeVersion) async -> URL? {
|
||||
return await load(urlString: "https://www.unicode.org/emoji/charts-\(version.rawValue).0/emoji-counts.html")
|
||||
func getTemporaryURLForEmojiCounts(version: EmojiManager.Version) async -> URL? {
|
||||
return await load(urlString: "https://www.unicode.org/emoji/charts-\(version.versionIdentifier)/emoji-counts.html")
|
||||
}
|
||||
|
||||
private func load(urlString: String) async -> URL? {
|
||||
@@ -83,7 +93,9 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private func save(data: [EmojiCategory], for: DataProcessor.EmojiUnicodeVersion) {
|
||||
private func save(data: [EmojiCategory], for: EmojiManager.Version) {
|
||||
let directory = getPath()
|
||||
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .prettyPrinted
|
||||
|
||||
@@ -92,10 +104,12 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
return
|
||||
}
|
||||
|
||||
var filePath = URL(filePath: path)
|
||||
filePath.append(path: version.fileName)
|
||||
var filePath = URL(filePath: directory)
|
||||
filePath.append(path: "\(version.fileName).json")
|
||||
let jsonString = String(data: result, encoding: .utf8)
|
||||
|
||||
print("⚙️", "Saving emojis to file \(filePath.absoluteString)...\n")
|
||||
|
||||
if FileManager.default.fileExists(atPath: filePath.absoluteString) == false {
|
||||
FileManager.default.createFile(atPath: filePath.absoluteString, contents: nil)
|
||||
}
|
||||
@@ -108,4 +122,4 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||
}
|
||||
}
|
||||
|
||||
extension DataProcessor.EmojiUnicodeVersion: ExpressibleByArgument {}
|
||||
extension EmojiManager.Version: ExpressibleByArgument {}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftSoup
|
||||
import EmojiKitLibrary
|
||||
import EmojiKit
|
||||
|
||||
class UnicodeParser {
|
||||
|
||||
Reference in New Issue
Block a user