Add support for iOS 15 and unicode release v13 (#1)
This commit is contained in:
committed by
GitHub
parent
6bbb3a1a71
commit
977c01327f
103
.swiftpm/xcode/xcshareddata/xcschemes/EmojiKit-Package.xcscheme
Normal file
103
.swiftpm/xcode/xcshareddata/xcschemes/EmojiKit-Package.xcscheme
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "1430"
|
||||||
|
version = "1.7">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiKit_EmojiKit"
|
||||||
|
BuildableName = "EmojiKit_EmojiKit"
|
||||||
|
BlueprintName = "EmojiKit_EmojiKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiKit"
|
||||||
|
BuildableName = "EmojiKit"
|
||||||
|
BlueprintName = "EmojiKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
|
BuildableName = "EmojiSourceKit"
|
||||||
|
BlueprintName = "EmojiSourceKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
shouldAutocreateTestPlan = "YES">
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
|
BuildableName = "EmojiSourceKit"
|
||||||
|
BlueprintName = "EmojiSourceKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<MacroExpansion>
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
|
BuildableName = "EmojiSourceKit"
|
||||||
|
BlueprintName = "EmojiSourceKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</MacroExpansion>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
</BuildableProductRunnable>
|
</BuildableProductRunnable>
|
||||||
<CommandLineArguments>
|
<CommandLineArguments>
|
||||||
<CommandLineArgument
|
<CommandLineArgument
|
||||||
argument = "download --path ."
|
argument = "download ."
|
||||||
isEnabled = "YES">
|
isEnabled = "YES">
|
||||||
</CommandLineArgument>
|
</CommandLineArgument>
|
||||||
</CommandLineArguments>
|
</CommandLineArguments>
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
buildForAnalyzing = "YES">
|
buildForAnalyzing = "YES">
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "EmojiKitLibrary"
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
BuildableName = "EmojiKitLibrary"
|
BuildableName = "EmojiSourceKit"
|
||||||
BlueprintName = "EmojiKitLibrary"
|
BlueprintName = "EmojiSourceKit"
|
||||||
ReferencedContainer = "container:">
|
ReferencedContainer = "container:">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</BuildActionEntry>
|
</BuildActionEntry>
|
||||||
@@ -38,7 +38,18 @@
|
|||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
debugDocumentVersioning = "YES"
|
debugDocumentVersioning = "YES"
|
||||||
debugServiceExtension = "internal"
|
debugServiceExtension = "internal"
|
||||||
allowLocationSimulation = "YES">
|
allowLocationSimulation = "YES"
|
||||||
|
viewDebuggingEnabled = "No">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
|
BuildableName = "EmojiSourceKit"
|
||||||
|
BlueprintName = "EmojiSourceKit"
|
||||||
|
ReferencedContainer = "container:">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
<ProfileAction
|
<ProfileAction
|
||||||
buildConfiguration = "Release"
|
buildConfiguration = "Release"
|
||||||
@@ -46,15 +57,16 @@
|
|||||||
savedToolIdentifier = ""
|
savedToolIdentifier = ""
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
debugDocumentVersioning = "YES">
|
debugDocumentVersioning = "YES">
|
||||||
<MacroExpansion>
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
BlueprintIdentifier = "EmojiKitLibrary"
|
BlueprintIdentifier = "EmojiSourceKit"
|
||||||
BuildableName = "EmojiKitLibrary"
|
BuildableName = "EmojiSourceKit"
|
||||||
BlueprintName = "EmojiKitLibrary"
|
BlueprintName = "EmojiSourceKit"
|
||||||
ReferencedContainer = "container:">
|
ReferencedContainer = "container:">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</MacroExpansion>
|
</BuildableProductRunnable>
|
||||||
</ProfileAction>
|
</ProfileAction>
|
||||||
<AnalyzeAction
|
<AnalyzeAction
|
||||||
buildConfiguration = "Debug">
|
buildConfiguration = "Debug">
|
||||||
@@ -5,15 +5,11 @@ import PackageDescription
|
|||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "EmojiKit",
|
name: "EmojiKit",
|
||||||
platforms: [.macOS(.v13), .iOS(.v16)],
|
platforms: [.macOS(.v13), .iOS(.v15), .watchOS(.v8), .tvOS(.v15)],
|
||||||
products: [
|
products: [
|
||||||
.executable(
|
.library(
|
||||||
name: "EmojiKit",
|
name: "EmojiKit",
|
||||||
targets: ["EmojiKit"]
|
targets: ["EmojiKit"]
|
||||||
),
|
|
||||||
.library(
|
|
||||||
name: "EmojiKitLibrary",
|
|
||||||
targets: ["EmojiKitLibrary"]
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
@@ -22,14 +18,14 @@ let package = Package(
|
|||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: "EmojiKit",
|
name: "EmojiSourceKit",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||||
.product(name: "SwiftSoup", package: "SwiftSoup"),
|
.product(name: "SwiftSoup", package: "SwiftSoup"),
|
||||||
.target(name: "EmojiKitLibrary")
|
.target(name: "EmojiKit")
|
||||||
]),
|
]),
|
||||||
.target(
|
.target(
|
||||||
name: "EmojiKitLibrary", resources: [
|
name: "EmojiKit", resources: [
|
||||||
.process("Resources")
|
.process("Resources")
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|||||||
46
README.md
46
README.md
@@ -1,14 +1,18 @@
|
|||||||
|
[](https://swiftpackageindex.com/niklasamslgruber/EmojiKit)
|
||||||
|
|
||||||
# EmojiKit
|
# EmojiKit
|
||||||
|
|
||||||
A lightweight Swift package that gives you access to all available emojis for each iOS version. Additionally, this repository includes a script to fetch all emojis for a specific release from [Unicode.org](unicode.org).
|
A lightweight Swift package that gives you access to all available emojis for each iOS version. Additionally, this repository includes a script to fetch all emojis for a specific release from [Unicode.org](unicode.org).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
The repository includes to different products with different use cases:
|
The repository includes to different products with different use cases:
|
||||||
* `EmojiKit Executable`: A script that fetches emoji release from [Unicode.org](unicode.org), parses them and stores them in easy-to-use `json` files.
|
|
||||||
* `EmojiKitLibrary`: A Swift Package Manager (SPM) package that provides all available emojis for supported iOS versions. It already includes all supported for all iOS version higher or equal than `iOS 15.4`.
|
|
||||||
|
|
||||||
In most cases it is enough to just use the `EmojiKitLibrary` for your app. The executable is only needed if you want to fetch releases manually or fetch older non-supported unicode versions.
|
* `EmojiKit`: A Swift Package Manager (SPM) package that provides all available emojis for supported iOS versions. It already includes all supported for all iOS version higher or equal than `iOS 15.0`.
|
||||||
|
* `EmojiSourceKit`: A script that fetches emoji releases from [Unicode.org](unicode.org), parses them and stores them in easy-to-use `json` files.
|
||||||
|
|
||||||
## EmojiKitLibrary
|
In most cases it is enough to just use the `EmojiKit` for your app. The `EmojiSourceKit` is only needed if you want to fetch releases manually or fetch older non-supported unicode versions.
|
||||||
|
|
||||||
|
## EmojiKit
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
@@ -18,14 +22,14 @@ In most cases it is enough to just use the `EmojiKitLibrary` for your app. The e
|
|||||||
https://github.com/niklasamslgruber/EmojiKit
|
https://github.com/niklasamslgruber/EmojiKit
|
||||||
```
|
```
|
||||||
|
|
||||||
> When asked by Xcode, only select the `EmojiKitLibrary` as a dependency, not the `EmojiKit` executable as it's not needed.
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
The SPM package provides an easy-to-use `EmojiManager` that parses the stored emoji files and returns them as an Array of `EmojiCategory`. Each category is the official unicode category and includes all emojis that are assigned to this category. In total these are 10 categories while the `.component` category can be ignored in most cases.
|
The SPM package provides an easy-to-use `EmojiManager` that parses the stored emoji files and returns them as an Array of `EmojiCategory`. Each category is the official unicode category and includes all emojis that are assigned to this category. In total these are 10 categories while the `.component` category can be ignored in most cases.
|
||||||
|
|
||||||
#### Get all supported emojis
|
#### Get all supported emojis
|
||||||
```
|
```swift
|
||||||
|
import EmojiKit
|
||||||
|
|
||||||
let emojisByCategory: [EmojiCategory] = EmojiManager.getAvailableEmojis()
|
let emojisByCategory: [EmojiCategory] = EmojiManager.getAvailableEmojis()
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -34,9 +38,9 @@ let emojisByCategory: [EmojiCategory] = EmojiManager.getAvailableEmojis()
|
|||||||
* `showAllVariations`: Many emojis are available in different skin types. By default the `EmojiManager` returns only the neutral (yellow) version of each emoji. If you want to receive all version, set this parameter to `true`.
|
* `showAllVariations`: Many emojis are available in different skin types. By default the `EmojiManager` returns only the neutral (yellow) version of each emoji. If you want to receive all version, set this parameter to `true`.
|
||||||
* `at url`: If you don't want to use the emoji files that are already included in this package, you can manually specify the location of your emoji_<version>.json`.
|
* `at url`: If you don't want to use the emoji files that are already included in this package, you can manually specify the location of your emoji_<version>.json`.
|
||||||
|
|
||||||
## EmojiKit Executable
|
## EmojiSourceKit
|
||||||
|
|
||||||
> In most cases this part is not necessary if you just want to get the emojis in Swift. If you want to do some manual fetching or your app supports iOS versions below `iOS 15.4`, this chapter is for you.
|
> In most cases this part is not necessary if you just want to get the emojis in Swift. If you want to do some manual fetching or your app supports iOS versions below `iOS 15.0`, this chapter is for you.
|
||||||
|
|
||||||
The main idea behind this script is that there is no full list of supported emojis that can be easily used in Swift. This script fetches the full list of emojis from [Unicode.org](unicode.org), parses them and returns a structured `emojis_vX.json` file where all emojis are assigned to their official unicode category. The `.json` files can be easily parsed afterwards for further usage in any product.
|
The main idea behind this script is that there is no full list of supported emojis that can be easily used in Swift. This script fetches the full list of emojis from [Unicode.org](unicode.org), parses them and returns a structured `emojis_vX.json` file where all emojis are assigned to their official unicode category. The `.json` files can be easily parsed afterwards for further usage in any product.
|
||||||
|
|
||||||
@@ -44,21 +48,21 @@ The main idea behind this script is that there is no full list of supported emoj
|
|||||||
|
|
||||||
##### Manual
|
##### Manual
|
||||||
|
|
||||||
```
|
```bash
|
||||||
git clone https://github.com/niklasamslgruber/EmojiKit
|
git clone https://github.com/niklasamslgruber/EmojiKit
|
||||||
```
|
```
|
||||||
|
|
||||||
To use the executable as a script from your Terminal, some further steps are required:
|
To use `EomjiSourceKit` as a script from your Terminal, some further steps are required:
|
||||||
|
|
||||||
1. Clone the repository and `cd` into it.
|
1. Clone the repository and `cd` into it.
|
||||||
2. Run `swift run -c release EmojiKit` to build the package.
|
2. Run `swift run -c release EmojiSourceKit` to build the package.
|
||||||
3. Move the product into `/usr/local/bin` to make it available systemwide with `cp .build/release/EmojiKit /usr/bin/emojiKit`.
|
3. Move the product into `/usr/local/bin` to make it available systemwide with `cp .build/release/EmojiSourceKit /usr/bin/emojiSourceKit`.
|
||||||
|
|
||||||
> Alternatively you can simply run `sh build.sh` to do steps 2. and 3. in one go.
|
> Alternatively you can simply run `sh build.sh` to do steps 2. and 3. in one go.
|
||||||
|
|
||||||
#### Execution
|
#### Execution
|
||||||
```
|
```bash
|
||||||
emojiKit download <path> -v <version>
|
emojiSourceKit download <path> -v <version>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Arguments:**
|
**Arguments:**
|
||||||
@@ -68,21 +72,17 @@ emojiKit download <path> -v <version>
|
|||||||
#### Working with unsupported Versions
|
#### Working with unsupported Versions
|
||||||
Currently only to Unicode releases are supported (Version 14 and 15). If you want to have access to emojis from older versions, you need to edit the source code manually.
|
Currently only to Unicode releases are supported (Version 14 and 15). If you want to have access to emojis from older versions, you need to edit the source code manually.
|
||||||
|
|
||||||
1. Add a new enum case to the `EmojiManager.Version` enum. For example for Version 13, you would need to add `case v13 = 13`.
|
1. Add a new enum case to the `EmojiManager.Version` enum. For example for Version 12, you would need to add `case v12 = 12`. Also, add a `versionIdentifier`. This should match the release number from Unicode.rog **exactly**. You can find all releases [here](https://unicode.org/Public/emoji/).
|
||||||
2. Modify the `getSupportedVersion` function to return your new enum case for the corresponding iOS version.
|
2. Modify the `getSupportedVersion` function to return your new enum case for the corresponding iOS version.
|
||||||
3. Run the script with the `emojiKit download <path> --version 13` argument to get the emojis from the version 13 release.
|
3. Run the script with the `emojiSourceKit download <path> --version 12` argument to get the emojis from the version 12 release.
|
||||||
4. Add the emoji file to your Xcode project and specify its url as an parameter of the `EmojiManager.getAvailableEmojis(at: <url)` function to access the emojis in Swift.
|
4. Add the emoji file to your Xcode project and specify its url as an parameter of the `EmojiManager.getAvailableEmojis(at: <url)` function to access the emojis in Swift.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
1. **Emojis are rendered as <`?`> in my app:**
|
1. **Emojis are rendered as <`?`> in my app:**
|
||||||
|
|
||||||
If you're using the `EmojiKitLibrary` you're most likely running the App on a device with an iOS version below `iOS 15.4`. That is currently not supported. To still make it work, follow the instructions of running the `EmojiKit` executable with unsupported versions to get all emojis that are supported on your device's iOS version.
|
If you're using the `EmojiKit` you're most likely running the App on a device with an iOS version below `iOS 15.0`. That is currently not supported. To still make it work, follow the instructions of running `EmojiSourceKit` with unsupported versions to get all emojis that are supported on your device's iOS version.
|
||||||
|
|
||||||
2. **The `EmojiManager` does not return any emojis when using the `url` parameter:**
|
2. **The `EmojiManager` does not return any emojis when using the `url` parameter:**
|
||||||
|
|
||||||
In that case make sure that you added the `emojis_vX.json` file to your Xcode project. The file name must match the version you're trying to fetch emojis for, e.g. for version 13 the file name must be `emojis_v13.json`. Additionally make sure that your JSON file is added under `Build Phase - Copy Bundle Resources` for each target where you want to use the `EmojiManager`.
|
In that case make sure that you added the `emojis_vX.json` file to your Xcode project. The file name must match the version you're trying to fetch emojis for, e.g. for version 12 the file name must be `emojis_v12.json`. Additionally make sure that your JSON file is added under `Build Phase - Copy Bundle Resources` for each target where you want to use the `EmojiManager`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 })
|
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
|
// Order that Apple uses in their emoji picker
|
||||||
public var order: Int {
|
public var order: Int {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -9,19 +9,33 @@ import Foundation
|
|||||||
|
|
||||||
public enum EmojiManager {
|
public enum EmojiManager {
|
||||||
|
|
||||||
public enum Version: Int {
|
public enum Version: Double {
|
||||||
|
case v13_1 = 13.1
|
||||||
case v14 = 14
|
case v14 = 14
|
||||||
case v15 = 15
|
case v15 = 15
|
||||||
|
|
||||||
public var fileName: String {
|
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 {
|
public static func getSupportedVersion() -> Version {
|
||||||
if #available(iOS 16.4, *) {
|
if #available(iOS 16.4, *) {
|
||||||
return .v15
|
return .v15
|
||||||
} else {
|
} else if #available(iOS 15.4, *) {
|
||||||
return .v14
|
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 Foundation
|
||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
import EmojiKitLibrary
|
import EmojiKit
|
||||||
|
|
||||||
struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
||||||
|
|
||||||
@@ -17,7 +17,19 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Argument var path: String
|
@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 {
|
func run() async throws {
|
||||||
print("⚙️", "Starting to download all emojis for version \(version.rawValue) from unicode.org...\n")
|
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("🎉", "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)
|
save(data: emojisByCategory, for: version)
|
||||||
|
|
||||||
print("🎉", "Successfully saved emojis to file.\n")
|
print("🎉", "Successfully saved emojis to file.\n")
|
||||||
@@ -55,12 +65,12 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTemporaryURLForEmojiList(version: DataProcessor.EmojiUnicodeVersion) async -> URL? {
|
func getTemporaryURLForEmojiList(version: EmojiManager.Version) async -> URL? {
|
||||||
return await load(urlString: "https://unicode.org/Public/emoji/\(version.rawValue).0/emoji-test.txt")
|
return await load(urlString: "https://unicode.org/Public/emoji/\(version.versionIdentifier)/emoji-test.txt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTemporaryURLForEmojiCounts(version: DataProcessor.EmojiUnicodeVersion) async -> URL? {
|
func getTemporaryURLForEmojiCounts(version: EmojiManager.Version) async -> URL? {
|
||||||
return await load(urlString: "https://www.unicode.org/emoji/charts-\(version.rawValue).0/emoji-counts.html")
|
return await load(urlString: "https://www.unicode.org/emoji/charts-\(version.versionIdentifier)/emoji-counts.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func load(urlString: String) async -> URL? {
|
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()
|
let encoder = JSONEncoder()
|
||||||
encoder.outputFormatting = .prettyPrinted
|
encoder.outputFormatting = .prettyPrinted
|
||||||
|
|
||||||
@@ -92,10 +104,12 @@ struct EmojiDownloader: ParsableCommand, AsyncParsableCommand {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var filePath = URL(filePath: path)
|
var filePath = URL(filePath: directory)
|
||||||
filePath.append(path: version.fileName)
|
filePath.append(path: "\(version.fileName).json")
|
||||||
let jsonString = String(data: result, encoding: .utf8)
|
let jsonString = String(data: result, encoding: .utf8)
|
||||||
|
|
||||||
|
print("⚙️", "Saving emojis to file \(filePath.absoluteString)...\n")
|
||||||
|
|
||||||
if FileManager.default.fileExists(atPath: filePath.absoluteString) == false {
|
if FileManager.default.fileExists(atPath: filePath.absoluteString) == false {
|
||||||
FileManager.default.createFile(atPath: filePath.absoluteString, contents: nil)
|
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 Foundation
|
||||||
import SwiftSoup
|
import SwiftSoup
|
||||||
import EmojiKitLibrary
|
import EmojiKit
|
||||||
|
|
||||||
class UnicodeParser {
|
class UnicodeParser {
|
||||||
|
|
||||||
Reference in New Issue
Block a user