42 lines
924 B
Swift
42 lines
924 B
Swift
|
|
struct PartialSvgImage: HtmlProducer {
|
|
|
|
let imagePath: String
|
|
|
|
let altText: String
|
|
|
|
let x: Int
|
|
|
|
let y: Int
|
|
|
|
let width: Int
|
|
|
|
let height: Int
|
|
|
|
private var aspectRatio: Double {
|
|
guard height > 1 else {
|
|
return 1
|
|
}
|
|
return Double(width) / Double(height)
|
|
}
|
|
|
|
func populate(_ result: inout String) {
|
|
result += "<span class='content-image svg-image'>"
|
|
result += "<img src='\(imagePath)#svgView(viewBox(\(x), \(y), \(width), \(height)))' loading='lazy' style='aspect-ratio:\(aspectRatio)' alt='\(altText)'/>"
|
|
result += "</span>"
|
|
}
|
|
}
|
|
|
|
struct SvgImage: HtmlProducer {
|
|
|
|
let imagePath: String
|
|
|
|
let altText: String
|
|
|
|
func populate(_ result: inout String) {
|
|
result += "<div class='content-image svg-image'>"
|
|
result += "<img src='\(imagePath)' loading='lazy' alt='\(altText)'/>"
|
|
result += "</div>"
|
|
}
|
|
}
|