Skip to content

Commit 1a1f3f8

Browse files
committed
Initial commit
0 parents  commit 1a1f3f8

File tree

411 files changed

+150860
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+150860
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.swiftpm/
3+
.swiftpm/*
4+
/*.xcodeproj
5+
/.build
6+
/Packages
7+
xcuserdata/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 SwiftUIX
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// swift-tools-version:5.9
2+
3+
import CompilerPluginSupport
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SwiftUIZ",
8+
platforms: [
9+
.iOS(.v16),
10+
.macOS(.v13)
11+
],
12+
products: [
13+
.library(
14+
name: "SwiftUIZ",
15+
targets: [
16+
"_SwiftUI_Internals",
17+
"_DVGraph",
18+
"_SwiftUIZ_Nuke",
19+
"_SwiftUIZ_NukeUI",
20+
"MarkdownUI",
21+
"Emoji",
22+
"SwiftUIZ",
23+
"SwiftUIZ_Macros"
24+
]
25+
),
26+
],
27+
dependencies: [
28+
.package(url: "https://github.com/apple/swift-syntax.git", from: "510.0.0"),
29+
.package(url: "https://github.com/siteline/SwiftUI-Introspect", from: "0.2.3"),
30+
.package(url: "https://github.com/SwiftUIX/SwiftUIX.git", branch: "master"),
31+
.package(url: "https://github.com/vmanot/CorePersistence.git", branch: "main"),
32+
.package(url: "https://github.com/vmanot/Merge.git", branch: "master"),
33+
.package(url: "https://github.com/vmanot/Swallow.git", branch: "master"),
34+
],
35+
targets: [
36+
.macro(
37+
name: "SwiftUIZ_Macros",
38+
dependencies: [
39+
"Swallow",
40+
.product(name: "SwiftSyntax", package: "swift-syntax"),
41+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
42+
.product(name: "SwiftOperators", package: "swift-syntax"),
43+
.product(name: "SwiftParser", package: "swift-syntax"),
44+
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
45+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
46+
],
47+
path: "Sources/SwiftUIZ_Macros",
48+
swiftSettings: []
49+
),
50+
.target(
51+
name: "cmark-gfm",
52+
path: "Sources/cmark-gfm"
53+
),
54+
.target(
55+
name: "_SwiftUI_Internals",
56+
dependencies: [
57+
"Swallow",
58+
"SwiftUIX"
59+
],
60+
path: "Sources/_SwiftUI_Internals"
61+
),
62+
.target(
63+
name: "_SwiftUIZ_Nuke",
64+
dependencies: [],
65+
path: "Sources/_SwiftUIZ_Nuke"
66+
),
67+
.target(
68+
name: "_SwiftUIZ_NukeUI",
69+
dependencies: [
70+
"_SwiftUIZ_Nuke"
71+
],
72+
path: "Sources/_SwiftUIZ_NukeUI"
73+
),
74+
.target(
75+
name: "MarkdownUI",
76+
dependencies: [
77+
"_SwiftUIZ_Nuke",
78+
"_SwiftUIZ_NukeUI",
79+
"cmark-gfm",
80+
"Swallow",
81+
"SwiftUIX",
82+
"SwiftUIZ",
83+
],
84+
path: "Sources/MarkdownUI",
85+
swiftSettings: []
86+
),
87+
.target(
88+
name: "Emoji",
89+
dependencies: [
90+
"Swallow"
91+
],
92+
path: "Sources/Emoji",
93+
resources: [
94+
.copy("Resources/emoji-data.json"),
95+
.copy("Resources/gemoji.json")
96+
],
97+
swiftSettings: [
98+
.unsafeFlags([
99+
"-enable-library-evolution",
100+
])
101+
]
102+
),
103+
.target(
104+
name: "_DVGraph",
105+
dependencies: [
106+
"_SwiftUI_Internals",
107+
"CorePersistence",
108+
"Merge",
109+
"Swallow",
110+
"SwiftUIX",
111+
"SwiftUIZ_Macros",
112+
],
113+
path: "Sources/_DVGraph",
114+
swiftSettings: []
115+
),
116+
.target(
117+
name: "SwiftUIZ",
118+
dependencies: [
119+
"_DVGraph",
120+
"CorePersistence",
121+
"Merge",
122+
"Swallow",
123+
.product(name: "SwiftUIIntrospect", package: "SwiftUI-Introspect"),
124+
"SwiftUIX",
125+
"SwiftUIZ_Macros",
126+
],
127+
path: "Sources/SwiftUIZ",
128+
swiftSettings: []
129+
),
130+
.testTarget(
131+
name: "_DVGraphTests",
132+
dependencies: [
133+
"_DVGraph",
134+
"SwiftUIZ",
135+
],
136+
path: "Tests/_DVGraph",
137+
swiftSettings: []
138+
)
139+
]
140+
)

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
> [!IMPORTANT]
2+
> This package is presently in its alpha stage of development
3+
>
4+
# SwiftUIZ
5+
Ambitious additions to SwiftUI.
6+
7+
# Acknowledgments
8+
9+
<details>
10+
<summary>MarkdownUI</summary>
11+
12+
- **Link**: https://github.com/gonzalezreal/swift-markdown-ui
13+
- **License**: [MIT License](https://github.com/gonzalezreal/swift-markdown-ui/blob/main/LICENSE)
14+
- **Authors**: @gonzalezreal
15+
- **Notes**:
16+
- `BlockSequence` no longer uses a `VStack`, allowing for lazy loading of large Markdown content via `LazyVStack { ... }`.
17+
- Integration of SwiftUIX for advanced view caching and Nuke for efficient remote image loading.
18+
- The result builder DSL has been removed.
19+
20+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// Copyright (c) Vatsal Manot
3+
//
4+
5+
import Foundation
6+
import Swallow
7+
8+
struct EmojiDataReader {
9+
static let shared = Self()
10+
11+
var emojis: [Emoji.Descriptor] = []
12+
var shortNameForUnified: [String:[Emoji.Descriptor]] = [:]
13+
var emojisForCategory: [Emoji.Category: [Emoji.Descriptor]] = [:]
14+
var emojiForUnified: [String:[Emoji.Descriptor]] = [:]
15+
var emojiForUnicode: [String: Emoji.Descriptor] = [:]
16+
var emojisPerCategory: [Emoji.Category: [Emoji]] = [:]
17+
18+
func getEmojisForCategory(_ category: Emoji.Category) -> [Emoji.Descriptor]? {
19+
return emojisForCategory[category]
20+
}
21+
22+
init() {
23+
guard let emojisListFilePath = Bundle.module.path(forResource: "emoji-data", ofType: "json") else {
24+
print("emoji-data.json was not found")
25+
return
26+
}
27+
28+
let emojisListData = FileManager.default.contents(atPath: emojisListFilePath)
29+
30+
do {
31+
if let jsonArray = try JSONSerialization.jsonObject(with: emojisListData!, options: .allowFragments) as? [[String: Any]] {
32+
jsonArray.forEach { (emoji: [String:Any]) in
33+
let name = emoji["name"] as? String
34+
let isObsoleted = emoji["obsoleted_by"] != nil
35+
let sortOrder: Int = emoji["sort_order"] as? Int ?? 0
36+
37+
var category: Emoji.Category? = nil
38+
var subcategory: String? = nil
39+
40+
if let categoryName = emoji["category"] as? String {
41+
category = Emoji.Category(rawValue: categoryName)
42+
}
43+
44+
if let _subcategory = emoji["subcategory"] as? String {
45+
subcategory = _subcategory
46+
}
47+
48+
var unifieds: [String] = []
49+
50+
if let unifiedJson = emoji["unified"] as? String {
51+
unifieds.append(unifiedJson)
52+
}
53+
54+
if let variations = emoji["variations"] as? [String] {
55+
variations.forEach { unifieds.append($0) }
56+
}
57+
58+
unifieds.reverse()
59+
60+
unifieds.forEach { unified in
61+
62+
if let shortNames = emoji["short_names"] as? [String] {
63+
shortNames.forEach { shortName in
64+
65+
let emojiSkinVariations = emoji["skin_variations"] as? [[String]]
66+
67+
var skinVariations: [Emoji.SkinVariation]
68+
69+
if let emojiSkinVariations = emojiSkinVariations {
70+
skinVariations = emojiSkinVariations.compactMap {
71+
return Emoji.SkinVariation(unified: $0[1], skinVariations: Emoji.SkinVariationType.getFromUnified($0[0]))
72+
}
73+
74+
} else {
75+
skinVariations = []
76+
}
77+
78+
let emojiObject = Emoji.Descriptor(
79+
name: name ?? "",
80+
shortName: shortName,
81+
unified: unified,
82+
skinVariations: skinVariations,
83+
category: category,
84+
subcategory: subcategory,
85+
isObsoleted: isObsoleted,
86+
sortOrder: sortOrder
87+
)
88+
89+
emojis.append(emojiObject)
90+
}
91+
}
92+
}
93+
}
94+
}
95+
96+
emojis
97+
.sorted { $0.isObsoleted && $1.isObsoleted }
98+
.forEach { emoji in
99+
emojiForUnicode[emoji.emoji] = emoji
100+
101+
var emojiListFromDictionary = shortNameForUnified[emoji.shortName] ?? []
102+
emojiListFromDictionary.append(emoji)
103+
shortNameForUnified[emoji.shortName] = emojiListFromDictionary
104+
105+
var emojisForUnified = emojiForUnified[emoji.unified] ?? []
106+
emojisForUnified.append(emoji)
107+
emojiForUnified[emoji.unified] = emojisForUnified
108+
109+
emoji.skinVariations.forEach { variation in
110+
var emojisVariationForUnified = emojiForUnified[variation.unified] ?? []
111+
var emojiVariation = emoji
112+
emojiVariation.shortName = emoji.shortName + ":" + variation.skinVariationTypes.map { ":\($0.getAliasValue())" }.joined(separator: ":")
113+
114+
emojisVariationForUnified.append(emojiVariation)
115+
emojiForUnified[variation.unified] = emojisVariationForUnified
116+
}
117+
118+
if let category = emoji.category {
119+
emojisForCategory[category, default: []].append(emoji)
120+
}
121+
122+
}
123+
124+
for key in emojisForCategory.keys {
125+
emojisForCategory[key] = Set(emojisForCategory[key, default: []])
126+
.sorted(by: { $0.sortOrder < $1.sortOrder })
127+
128+
emojisPerCategory[key] = emojisForCategory[key, default: []]
129+
.sorted(by: { $0.sortOrder < $1.sortOrder })
130+
.compactMap(Emoji.init)
131+
.distinct()
132+
}
133+
} catch {
134+
print("Could not load emoji list \(error)")
135+
}
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Copyright (c) Vatsal Manot
3+
//
4+
5+
import Foundation
6+
import Swallow
7+
8+
public struct GitHubEmojiEntry: Codable, Hashable, Identifiable {
9+
public let emoji: String
10+
public let description: String
11+
public let category: Emoji.Category
12+
public let aliases: [String]
13+
public let tags: [String]
14+
public let unicodeVersion: String
15+
public let iosVersion: String
16+
public var skinTones: Bool?
17+
18+
public var id: some Hashable {
19+
emoji
20+
}
21+
22+
public init?(from emoji: Emoji) {
23+
guard let entry = GitHubEmojiDataReader.data[emoji] else {
24+
return nil
25+
}
26+
27+
self = entry
28+
}
29+
}
30+
31+
struct GitHubEmojiDataReader {
32+
public static var data: [Emoji: GitHubEmojiEntry] = readData()
33+
34+
static func readData() -> [Emoji: GitHubEmojiEntry] {
35+
do {
36+
let decoder = JSONDecoder()
37+
let path = Bundle.module.path(forResource: "gemoji", ofType: "json")!
38+
let entriesData = try FileManager.default.contents(atPath: path).unwrap()
39+
40+
decoder.keyDecodingStrategy = .convertFromSnakeCase
41+
42+
let entries = try decoder.decode([GitHubEmojiEntry].self, from: entriesData).map {
43+
(Emoji(rawValue: $0.emoji)!, $0)
44+
}
45+
46+
return Dictionary(
47+
entries,
48+
uniquingKeysWith: { lhs, rhs in lhs }
49+
)
50+
} catch {
51+
assertionFailure()
52+
53+
return [:]
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)