86 lines
2.4 KiB
Swift
86 lines
2.4 KiB
Swift
//
|
|
// Source.swift
|
|
// HTMLStandard
|
|
//
|
|
// Generated on 09/23/2025.
|
|
// THIS FILE IS GENERATED. DO NOT EDIT.
|
|
//
|
|
import Foundation
|
|
|
|
/// <source> Image source for img or media source for video or audio
|
|
public class Source : HTMLNode {
|
|
|
|
/// Applicable media. Valid media query list.
|
|
public var media:String? = nil
|
|
|
|
/// Image sizes for different page layouts. Valid source size list.
|
|
public var sizes:[String] = []
|
|
|
|
/// Address of the resource. Valid non-empty URL potentially surrounded by spaces.
|
|
public var src:URL? = nil
|
|
|
|
/// Images to use in different situations (e.g., high-resolution displays, small monitors, etc.). Comma-separated list of image candidate strings.
|
|
public var srcset:[String] = []
|
|
|
|
/// Type of embedded resource. Valid MIME type string.
|
|
public var type:String? = nil
|
|
|
|
|
|
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
|
var globalAttr = GlobalAttributesBuilder()
|
|
for (key, attValue) in attributes {
|
|
switch (key) {
|
|
case "media":
|
|
media = attValue
|
|
continue
|
|
case "sizes":
|
|
sizes = try String.parseList(attValue, ",")
|
|
continue
|
|
case "src":
|
|
src = try URL(expect: attValue)
|
|
continue
|
|
case "srcset":
|
|
srcset = try String.parseList(attValue, ",")
|
|
continue
|
|
case "type":
|
|
type = attValue
|
|
continue
|
|
|
|
default: break
|
|
}
|
|
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
|
continue
|
|
}
|
|
continue
|
|
}
|
|
super.init(globalAttr)
|
|
}
|
|
|
|
|
|
public override func renderAttributes() -> String {
|
|
var result = super.renderAttributes()
|
|
if let media = media {
|
|
result += " media='\(media)'"
|
|
}
|
|
result += " sizes='\(sizes.toStringList(","))'"
|
|
if let src = src {
|
|
result += " src='\(src.absoluteString)'"
|
|
}
|
|
result += " srcset='\(srcset.toStringList(","))'"
|
|
if let type = type {
|
|
result += " type='\(type)'"
|
|
}
|
|
|
|
|
|
return result
|
|
}
|
|
|
|
override var nodeName: String {
|
|
return "source"
|
|
}
|
|
|
|
override var isVoidElement: Bool {
|
|
return true
|
|
}
|
|
}
|