First version

This commit is contained in:
Christoph Hagen
2024-10-14 19:22:32 +02:00
parent 7c812de089
commit 0989f06d87
51 changed files with 2477 additions and 234 deletions

View File

@ -0,0 +1,14 @@
import SwiftUI
public extension Binding where Value: Equatable, Value: Sendable {
init(_ source: Binding<Value?>, replacingNilWith nilProxy: Value) {
self.init(
get: { source.wrappedValue ?? nilProxy },
set: { newValue in
if newValue == nilProxy { source.wrappedValue = nil }
else { source.wrappedValue = newValue }
}
)
}
}

View File

@ -0,0 +1,15 @@
import SwiftUI
extension Color {
init(_ r: Int, _ g: Int, _ b: Int) {
self.init(r: r, g: g, b: b)
}
init(r: Int, g: Int, b: Int) {
self.init(
red: Double(r) / 255,
green: Double(g) / 255,
blue: Double(b) / 255)
}
}

View File

@ -0,0 +1,15 @@
import Foundation
import SwiftUI
struct LanguageKey: EnvironmentKey {
static let defaultValue: ContentLanguage = .english
}
extension EnvironmentValues {
var language: ContentLanguage {
get { self[LanguageKey.self] }
set { self[LanguageKey.self] = newValue }
}
}

View File

@ -0,0 +1,11 @@
extension String {
func htmlEscaped() -> String {
replacingOccurrences(of: "&", with: "&amp;")
.replacingOccurrences(of: "\"", with: "&quot;")
.replacingOccurrences(of: "'", with: "&#39;")
.replacingOccurrences(of: "<", with: "&lt;")
.replacingOccurrences(of: ">", with: "&gt;")
}
}