import Elementary
public struct SVG: HTML, Sendable {
let color: String
let size: SVGSize
let svg: SVGType
public init(
_ svg: SVGType,
color: String,
size: SVGSize = .init()
) {
self.svg = svg
self.size = size
self.color = color
}
public init(
_ svg: SVGType,
color: Color.TextColor,
size: SVGSize = .init()
) {
self.svg = svg
self.size = size
self.color = color.color
}
public var content: some HTML {
div(.class("block \(color)")) {
svg.html(size)
}
}
}
public struct SVGSize: Sendable {
let width: Int
let height: Int
public init(width: Int = 24, height: Int? = nil) {
self.width = width
self.height = height ?? width
}
}
public enum SVGType: Sendable, CaseIterable {
case calculator
case checkCircle
case droplets
case exclamation
case funnel
case house
case leftRightArrow
case menu
case ruler
case thermometer
case thermometerSun
case wind
case zap
// swiftlint:disable cyclomatic_complexity
public func html(_ size: SVGSize) -> some HTML {
switch self {
case .calculator: return calculatorSvg(size: size)
case .checkCircle: return checkCircleSvg(size: size)
case .droplets: return dropletsSvg(size: size)
case .exclamation: return exclamationSvg(size: size)
case .funnel: return funnelSvg(size: size)
case .house: return houseSvg(size: size)
case .leftRightArrow: return leftRightArrowSvg(size: size)
case .menu: return menuSvg(size: size)
case .ruler: return rulerSvg(size: size)
case .thermometer: return thermometerSvg(size: size)
case .thermometerSun: return thermometerSunSvg(size: size)
case .wind: return windSvg(size: size)
case .zap: return zapSvg(size: size)
}
}
// swiftlint:enable cyclomatic_complexity
}
// MARK: - SVGs
// swiftlint:disable line_length
private func checkCircleSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func houseSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func zapSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func rulerSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func leftRightArrowSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
// TODO: Requires attribution:
// Vectors and icons by Laridae in CC Attribution License via SVG Repo
// FIX: This doesn't work, but does as a file
private func toolboxSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func funnelSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func dropletsSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func thermometerSunSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func exclamationSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func windSvg(size: SVGSize) -> HTMLRaw {
return HTMLRaw("""
""")
}
private func calculatorSvg(size: SVGSize) -> HTMLRaw {
return HTMLRaw("""
""")
}
private func thermometerSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
private func menuSvg(size: SVGSize) -> HTMLRaw {
HTMLRaw("""
""")
}
// swiftlint:enable line_length