first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

30
node_modules/expo-font/ios/ExpoFont.podspec generated vendored Normal file
View File

@@ -0,0 +1,30 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
Pod::Spec.new do |s|
s.name = 'ExpoFont'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']
s.platforms = {
:ios => '15.1',
:osx => '11.0',
:tvos => '15.1'
}
s.swift_version = '5.9'
s.source = { git: 'https://github.com/expo/expo.git' }
s.static_framework = true
s.dependency 'ExpoModulesCore'
# Swift/Objective-C compatibility
s.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES'
}
s.source_files = "**/*.{h,m,swift}"
end

50
node_modules/expo-font/ios/FontExceptions.swift generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import ExpoModulesCore
internal final class FontFileNotFoundException: GenericException<String> {
override var reason: String {
"Font file '\(param)' doesn't exist"
}
}
internal final class FontCreationFailedException: GenericException<String> {
override var reason: String {
"Could not create font from loaded data for '\(param)'"
}
}
internal final class FontNoPostScriptException: GenericException<String> {
override var reason: String {
"Could not create font '\(param)' from loaded data because it is missing the PostScript name"
}
}
internal struct FontRegistrationErrorInfo {
let fontFamilyAlias: String
let cfError: CFError
let ctFontManagerError: CTFontManagerError?
}
internal final class FontRegistrationFailedException: GenericException<FontRegistrationErrorInfo> {
override var reason: String {
let ctErrorDescription = "CTFontManagerError code: " + (param.ctFontManagerError.map { String($0.rawValue) } ?? "N/A")
return "Registering '\(param.fontFamilyAlias)' font failed with message: '\(param.cfError.localizedDescription)'. \(ctErrorDescription)"
}
}
internal final class UnregisteringFontFailedException: GenericException<CFError> {
override var reason: String {
"Unregistering font failed with message: '\(param.localizedDescription)'"
}
}
internal final class CreateImageException: Exception {
override var reason: String {
"Could not create image"
}
}
internal final class SaveImageException: GenericException<String> {
override var reason: String {
"Could not save image to '\(param)'"
}
}

View File

@@ -0,0 +1,72 @@
import ExpoModulesCore
/**
A registry of font family aliases mapped to their real font family names.
*/
private var fontFamilyAliases = [String: String]()
/**
A flag that is set to `true` when the ``UIFont.fontNames(forFamilyName:)`` is already swizzled.
*/
private var hasSwizzled = false
/**
Queue to protect shared resources
*/
private let queue = DispatchQueue(label: "expo.fontfamilyaliasmanager", attributes: .concurrent)
/**
Manages the font family aliases and swizzles the `UIFont` class.
*/
internal struct FontFamilyAliasManager {
/**
Whether the given alias has already been set.
*/
internal static func hasAlias(_ familyNameAlias: String) -> Bool {
return queue.sync {
fontFamilyAliases[familyNameAlias] != nil
}
}
/**
Sets the alias for the given family name.
If the alias has already been set, its family name will be overriden.
*/
internal static func setAlias(_ familyNameAlias: String, forFont font: String) {
maybeSwizzleUIFont()
queue.sync(flags: .barrier) {
fontFamilyAliases[familyNameAlias] = font
}
}
/**
Returns the family name for the given alias or `nil` when it's not set yet.
*/
internal static func familyName(forAlias familyNameAlias: String) -> String? {
return queue.sync {
fontFamilyAliases[familyNameAlias]
}
}
}
/**
Swizzles ``UIFont.fontNames(forFamilyName:)`` to support font family aliases.
This is necessary because the user provides a custom family name that is then used in stylesheets,
however the font usually has a different name encoded in the binary, thus the system may use a different name.
*/
private func maybeSwizzleUIFont() {
if hasSwizzled {
return
}
#if !os(macOS)
let originalFontNamesMethod = class_getClassMethod(UIFont.self, #selector(UIFont.fontNames(forFamilyName:)))
let newFontNamesMethod = class_getClassMethod(UIFont.self, #selector(UIFont._expo_fontNames(forFamilyName:)))
if let originalFontNamesMethod, let newFontNamesMethod {
method_exchangeImplementations(originalFontNamesMethod, newFontNamesMethod)
} else {
log.error("expo-font is unable to swizzle `UIFont.fontNames(forFamilyName:)`")
}
#endif
hasSwizzled = true
}

48
node_modules/expo-font/ios/FontLoaderModule.swift generated vendored Normal file
View File

@@ -0,0 +1,48 @@
import ExpoModulesCore
public final class FontLoaderModule: Module {
// could be a Set, but to be able to pass to JS we keep it as an array
private lazy var registeredFonts: [String] = queryCustomNativeFonts()
public required init(appContext: AppContext) {
super.init(appContext: appContext)
}
public func definition() -> ModuleDefinition {
Name("ExpoFontLoader")
// NOTE: this is exposed in JS as globalThis.expo.modules.ExpoFontLoader.loadedFonts
// and potentially consumed outside of Expo (e.g. RN vector icons)
// do NOT change the property as it'll break consumers!
Function("getLoadedFonts") {
return registeredFonts
}
// NOTE: this is exposed in JS as globalThis.expo.modules.ExpoFontLoader.loadAsync
// and potentially consumed outside of Expo (e.g. RN vector icons)
// do NOT change the function signature as it'll break consumers!
AsyncFunction("loadAsync") { (fontFamilyAlias: String, localUri: URL) in
let fontUrl = localUri as CFURL
// If the font was already registered, unregister it first. Otherwise CTFontManagerRegisterFontsForURL
// would fail because of a duplicated font name when the app reloads or someone wants to override a font.
if FontFamilyAliasManager.familyName(forAlias: fontFamilyAlias) != nil {
guard try unregisterFont(url: fontUrl) else {
return
}
}
// Register the font
try registerFont(fontUrl: fontUrl, fontFamilyAlias: fontFamilyAlias)
// Create a font object from the given URL
let font = try loadFont(fromUrl: fontUrl, alias: fontFamilyAlias)
if let postScriptName = font.postScriptName as? String {
FontFamilyAliasManager.setAlias(fontFamilyAlias, forFont: postScriptName)
registeredFonts = Array(Set(registeredFonts).union([postScriptName, fontFamilyAlias]))
} else {
throw FontNoPostScriptException(fontFamilyAlias)
}
}
}
}

90
node_modules/expo-font/ios/FontUtils.swift generated vendored Normal file
View File

@@ -0,0 +1,90 @@
import CoreGraphics
/**
* Queries custom native font names from the Info.plist `UIAppFonts`.
*/
internal func queryCustomNativeFonts() -> [String] {
// [0] Read from main bundle's Info.plist
guard let fontFilePaths = Bundle.main.object(forInfoDictionaryKey: "UIAppFonts") as? [String] else {
return []
}
// [1] Get font family names for each font file
let fontFamilies: [[String]] = fontFilePaths.compactMap { fontFilePath in
guard let fontUrl = Bundle.main.url(forResource: fontFilePath, withExtension: nil) else {
return []
}
guard let fontDescriptors = CTFontManagerCreateFontDescriptorsFromURL(fontUrl as CFURL) as? [CTFontDescriptor] else {
return []
}
return fontDescriptors.compactMap { descriptor in
return CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute) as? String
}
}
// [2] Retrieve font names by family names
return fontFamilies.flatMap { fontFamilyNames in
return fontFamilyNames.flatMap { fontFamilyName in
#if os(iOS) || os(tvOS)
return UIFont.fontNames(forFamilyName: fontFamilyName)
#elseif os(macOS)
return NSFontManager.shared.availableMembers(ofFontFamily: fontFamilyName)?.compactMap { $0[0] as? String } ?? []
#endif
}
}
}
/**
Loads the font from the given url and returns it as ``CGFont``.
*/
internal func loadFont(fromUrl url: CFURL, alias: String) throws -> CGFont {
guard let provider = CGDataProvider(url: url),
let cgFont = CGFont(provider) else {
throw FontCreationFailedException(alias)
}
return cgFont
}
/**
Registers the given font to make it discoverable through font descriptor matching.
*/
internal func registerFont(fontUrl: CFURL, fontFamilyAlias: String) throws {
var error: Unmanaged<CFError>?
if !CTFontManagerRegisterFontsForURL(fontUrl, .process, &error), let error = error?.takeRetainedValue() {
let fontError = CTFontManagerError(rawValue: CFErrorGetCode(error))
switch fontError {
case .alreadyRegistered, .duplicatedName:
// Ignore the error if:
// - this exact font instance was already registered or
// - another instance already registered with the same name (assuming it's most likely the same font anyway)
return
default:
throw FontRegistrationFailedException(FontRegistrationErrorInfo(fontFamilyAlias: fontFamilyAlias, cfError: error, ctFontManagerError: fontError))
}
}
}
/**
Unregisters the given font, so the app will no longer be able to render it.
Returns a boolean indicating if the font is successfully unregistered after this function completes.
*/
internal func unregisterFont(url: CFURL) throws -> Bool {
var error: Unmanaged<CFError>?
if !CTFontManagerUnregisterFontsForURL(url, .process, &error), let error = error?.takeRetainedValue() {
if let ctFontManagerError = CTFontManagerError(rawValue: CFErrorGetCode(error as CFError)) {
switch ctFontManagerError {
case .systemRequired, .inUse:
return false
case .notRegistered:
return true
default:
throw UnregisteringFontFailedException(error)
}
}
}
return true
}

63
node_modules/expo-font/ios/FontUtilsModule.swift generated vendored Normal file
View File

@@ -0,0 +1,63 @@
// Copyright 2025-present 650 Industries. All rights reserved.
import ExpoModulesCore
public final class FontUtilsModule: Module {
public func definition() -> ModuleDefinition {
Name("ExpoFontUtils")
#if !os(macOS)
AsyncFunction("renderToImageAsync") { (glyphs: String, options: RenderToImageOptions, promise: Promise) throws in
let font = if let fontName = UIFont.fontNames(forFamilyName: options.fontFamily).first,
let uiFont = UIFont(name: fontName, size: options.size) {
uiFont
} else {
UIFont.systemFont(ofSize: options.size)
}
var attributes: [NSAttributedString.Key: Any] = [
.font: font,
.foregroundColor: UIColor(options.color)
]
if let lineHeight = options.lineHeight {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = lineHeight
paragraphStyle.maximumLineHeight = lineHeight
attributes[.paragraphStyle] = paragraphStyle
// Adding baseline offset to vertically center the text within the specified line height
attributes[.baselineOffset] = (lineHeight - font.lineHeight) / 2
}
let attributedString = NSAttributedString(
string: glyphs,
attributes: attributes
)
let renderer = UIGraphicsImageRenderer(size: attributedString.size())
let image = renderer.image { _ in
attributedString.draw(at: .zero)
}
guard let data = image.pngData() else {
promise.reject(CreateImageException())
return
}
let outputURL = URL(fileURLWithPath: "\(NSTemporaryDirectory())\(UUID().uuidString).png")
do {
try data.write(to: outputURL, options: .atomic)
promise.resolve([
"uri": outputURL.absoluteString,
"width": image.size.width,
"height": image.size.height,
"scale": UIScreen.main.scale
])
} catch {
promise.reject(SaveImageException(outputURL.absoluteString))
}
}
#endif
}
}

11
node_modules/expo-font/ios/FontUtilsRecords.swift generated vendored Normal file
View File

@@ -0,0 +1,11 @@
// Copyright 2025-present 650 Industries. All rights reserved.
import SwiftUI
import ExpoModulesCore
struct RenderToImageOptions: Record {
@Field var fontFamily: String = ""
@Field var lineHeight: CGFloat? = nil
@Field var size: CGFloat = 24
@Field var color: Color = .black
}

View File

@@ -0,0 +1,29 @@
#if !os(macOS)
/**
An extension to ``UIFont`` that adds a custom implementation of `fontNames(forFamilyName:)` that supports aliasing font families.
*/
public extension UIFont {
/**
Returns an array of font names for the specified family name or its alias.
*/
@objc
static dynamic func _expo_fontNames(forFamilyName familyName: String) -> [String] {
// Get font names from the original function.
let fontNames = UIFont._expo_fontNames(forFamilyName: familyName)
// If no font names were found, let's try with the alias.
if fontNames.isEmpty, let postScriptName = FontFamilyAliasManager.familyName(forAlias: familyName) {
let fontNames = UIFont._expo_fontNames(forFamilyName: postScriptName)
// If we still don't find any font names, we can assume it was not a family name but a font name.
// In that case we can safely return the original font name.
if fontNames.isEmpty {
return [postScriptName]
}
return fontNames
}
return fontNames
}
}
#endif