diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-18 23:53:25 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-19 17:56:23 +0200 |
| commit | 49b0f4a3fb0064313d16782839865b763ef760ce (patch) | |
| tree | a58439f1433de9ff66dc0be28f025afe56e79cfe /Sources/NorgUI/Math/NorgMathRenderer.swift | |
| parent | cb91a73bfc845d74c3e4d1115bce5dfed10d456d (diff) | |
Support Math rendering1.2.0
Diffstat (limited to 'Sources/NorgUI/Math/NorgMathRenderer.swift')
| -rw-r--r-- | Sources/NorgUI/Math/NorgMathRenderer.swift | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Sources/NorgUI/Math/NorgMathRenderer.swift b/Sources/NorgUI/Math/NorgMathRenderer.swift new file mode 100644 index 0000000..4fcf60f --- /dev/null +++ b/Sources/NorgUI/Math/NorgMathRenderer.swift @@ -0,0 +1,46 @@ +import SwiftUI + +#if canImport(UIKit) + import UIKit + public typealias PlatformImage = UIImage +#elseif canImport(AppKit) + import AppKit + public typealias PlatformImage = NSImage +#endif + +public enum NorgMathMode: Sendable { + case inline + case block +} + +public struct NorgMathImage { + public let image: PlatformImage + public let size: CGSize + public let descent: CGFloat + + public init(image: PlatformImage, size: CGSize, descent: CGFloat) { + self.image = image + self.size = size + self.descent = descent + } + + public var swiftUIImage: Image { + #if canImport(UIKit) + Image(uiImage: image) + #elseif canImport(AppKit) + Image(nsImage: image) + #endif + } +} + +/// Renders LaTeX-style math into an image for display. +public protocol NorgMathRenderer: Sendable { + /// Render `latex` at the given point size and colour. + /// + /// - Returns: the rendered image, or `nil` if the input could not be + /// rendered (the caller then keeps its text fallback). + @MainActor + func render( + latex: String, mode: NorgMathMode, fontSize: CGFloat, color: Color? + ) async -> NorgMathImage? +} |