Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

1.5 KB
Raw Blame
import AppKit

/// The emoji in the space icon picker, in Unicode's order and grouped like the category bar of
/// Arc's picker (EmojiCatalog+Data.swift is generated by scripts/make-emoji-catalog.py).
enum EmojiCatalog {
    struct Entry: Hashable {
        let emoji: String
        let name: String
    }

    struct Category: Identifiable {
        let id: String
        /// The glyph in the picker's bottom bar.
        let symbol: String
        let entries: [Entry]
    }

    private static let symbols = [
        "smileys": "face.smiling", "nature": "sun.max", "food": "mug", "activities": "rosette",
        "travel": "box.truck", "objects": "gift", "symbols": "heart", "flags": "flag",
    ]

    /// Emoji 15.0 and older (the catalog's cut-off) all draw on macOS 14, Cra's oldest.
    static let categories: [Category] = data.map { key, text in
        let entries = text.split(separator: "\n").compactMap { line -> Entry? in
            guard let space = line.firstIndex(of: " ") else { return nil }
            return Entry(emoji: String(line[..<space]), name: String(line[line.index(after: space)...]))
        }
        return Category(id: key, symbol: symbols[key] ?? "circle", entries: entries)
    }

    static let all: [Entry] = categories.flatMap(\.entries)

    static func search(_ query: String) -> [Entry] {
        let words = query.lowercased().split(separator: " ")
        guard !words.isEmpty else { return [] }
        return all.filter { e in words.allSatisfy { e.name.contains($0) } }
    }
}