Initial Commit
This commit is contained in:
132
Sources/HRW/GenHTML/Elements/Track.swift
Normal file
132
Sources/HRW/GenHTML/Elements/Track.swift
Normal file
@@ -0,0 +1,132 @@
|
||||
//
|
||||
// Track.swift
|
||||
// HTMLStandard
|
||||
//
|
||||
// Generated on 09/23/2025.
|
||||
// THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
/// <track> Timed text track
|
||||
public class Track : HTMLNode {
|
||||
|
||||
public enum Kind : String, CaseIterable {
|
||||
|
||||
case captions
|
||||
case chapters
|
||||
case descriptions
|
||||
case metadata
|
||||
case subtitles
|
||||
|
||||
public init?(rawValue: Substring) {
|
||||
guard
|
||||
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
|
||||
else
|
||||
{ return nil }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: Substring) throws {
|
||||
guard
|
||||
let value = Self.allCases.first(where: { $0.rawValue == expect })
|
||||
else
|
||||
{ throw AppError("Unexpected value for Kind: \(expect)") }
|
||||
|
||||
self = value
|
||||
}
|
||||
|
||||
public init(expect: String) throws {
|
||||
guard let result = Kind(rawValue: expect) else {
|
||||
throw AppError("Unexpected value for Kind: \(expect)")
|
||||
}
|
||||
self = result
|
||||
}
|
||||
|
||||
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Kind] {
|
||||
guard let value = value else { return [] }
|
||||
var iterator = value.componentsIterator(separatedBy: separator)
|
||||
let result = try iterator.map { input in
|
||||
return try expect(Kind(rawValue: input), "unexpected value for Kind: \(input)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable the track if no other text track is more suitable.
|
||||
public var default_:Bool = false
|
||||
|
||||
/// The type of text track.
|
||||
public var kind:Kind? = nil
|
||||
|
||||
/// User-visible label.
|
||||
public var label:String? = nil
|
||||
|
||||
/// Address of the resource. Valid non-empty URL potentially surrounded by spaces.
|
||||
public var src:URL? = nil
|
||||
|
||||
/// Language of the text track. Valid BCP 47 language tag.
|
||||
public var srclang:String? = nil
|
||||
|
||||
|
||||
public init(_ attributes:[String:String], _ parser:XMLParser? = nil) throws {
|
||||
var globalAttr = GlobalAttributesBuilder()
|
||||
for (key, attValue) in attributes {
|
||||
switch (key) {
|
||||
case "default":
|
||||
default_ = true
|
||||
continue
|
||||
case "kind":
|
||||
kind = try Kind(expect: attValue)
|
||||
continue
|
||||
case "label":
|
||||
label = attValue
|
||||
continue
|
||||
case "src":
|
||||
src = try URL(expect: attValue)
|
||||
continue
|
||||
case "srclang":
|
||||
srclang = attValue
|
||||
continue
|
||||
|
||||
default: break
|
||||
}
|
||||
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
||||
continue
|
||||
}
|
||||
throw AppError("Unexpected attribute: \(key)")
|
||||
}
|
||||
super.init(globalAttr)
|
||||
}
|
||||
|
||||
|
||||
public override func renderAttributes() -> String {
|
||||
var result = super.renderAttributes()
|
||||
if default_ {
|
||||
result += " default"
|
||||
}
|
||||
if let kind = kind {
|
||||
result += " kind='\(kind.rawValue)'"
|
||||
}
|
||||
if let label = label {
|
||||
result += " label='\(label)'"
|
||||
}
|
||||
if let src = src {
|
||||
result += " src='\(src.absoluteString)'"
|
||||
}
|
||||
if let srclang = srclang {
|
||||
result += " srclang='\(srclang)'"
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
override var nodeName: String {
|
||||
return "track"
|
||||
}
|
||||
|
||||
override var isVoidElement: Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user