151 lines
4.6 KiB
Swift
151 lines
4.6 KiB
Swift
//
|
|
// Script.swift
|
|
// HTMLStandard
|
|
//
|
|
// Generated on 09/23/2025.
|
|
// THIS FILE IS GENERATED. DO NOT EDIT.
|
|
//
|
|
import Foundation
|
|
|
|
/// <script> Embedded script
|
|
public class Script : HTMLNode, IFlow, IMetaData, IPhrasing, IScriptSupporting {
|
|
|
|
public enum Crossorigin : String, CaseIterable {
|
|
|
|
case anonymous
|
|
case useCredentials = "use-credentials"
|
|
|
|
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 Crossorigin: \(expect)") }
|
|
|
|
self = value
|
|
}
|
|
|
|
public init(expect: String) throws {
|
|
guard let result = Crossorigin(rawValue: expect) else {
|
|
throw AppError("Unexpected value for Crossorigin: \(expect)")
|
|
}
|
|
self = result
|
|
}
|
|
|
|
static func parseList(_ value:String?, _ separator:String = " ") throws -> [Crossorigin] {
|
|
guard let value = value else { return [] }
|
|
var iterator = value.componentsIterator(separatedBy: separator)
|
|
let result = try iterator.map { input in
|
|
return try expect(Crossorigin(rawValue: input), "unexpected value for Crossorigin: \(input)")
|
|
}
|
|
return result
|
|
}
|
|
}
|
|
|
|
/// Execute script when available, without blocking while fetching.
|
|
public var async:Bool = false
|
|
|
|
/// How the element handles crossorigin requests.
|
|
public var crossorigin:Crossorigin? = nil
|
|
|
|
/// Defer script execution.
|
|
public var defer_:Bool = false
|
|
|
|
/// Integrity metadata used in Subresource Integrity checks [SRI].
|
|
public var integrity:String? = nil
|
|
|
|
/// Referrer policy for fetches initiated by the element. Referrer policy.
|
|
public var referrerpolicy:ReferrerPolicy? = nil
|
|
|
|
/// Address of the resource. Valid non-empty URL potentially surrounded by spaces.
|
|
public var src:URL? = nil
|
|
|
|
/// Type of script. "module"; a valid MIME type string that is not a JavaScript MIME type essence match.
|
|
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 "async":
|
|
async = true
|
|
continue
|
|
case "crossorigin":
|
|
crossorigin = try Crossorigin(expect: attValue)
|
|
continue
|
|
case "defer":
|
|
defer_ = true
|
|
continue
|
|
case "integrity":
|
|
integrity = attValue
|
|
continue
|
|
case "referrerpolicy":
|
|
referrerpolicy = try ReferrerPolicy(expect: attValue)
|
|
continue
|
|
case "src":
|
|
src = try URL(expect: attValue)
|
|
continue
|
|
case "type":
|
|
type = attValue
|
|
continue
|
|
|
|
default: break
|
|
}
|
|
if globalAttr.trySetGlobalAttribute(key, attValue) {
|
|
continue
|
|
}
|
|
throw AppError("Unexpected attribute: \(key)")
|
|
}
|
|
var allItems:[HTMLNode] = []
|
|
while let obj = try parser?.readObject(endTag: "script", xmlToHtmlMapper) {
|
|
allItems.append(obj)
|
|
}
|
|
super.init(globalAttr, allItems)
|
|
}
|
|
|
|
|
|
public override func renderAttributes() -> String {
|
|
var result = super.renderAttributes()
|
|
if async {
|
|
result += " async"
|
|
}
|
|
if let crossorigin = crossorigin {
|
|
result += " crossorigin='\(crossorigin.rawValue)'"
|
|
}
|
|
if defer_ {
|
|
result += " defer"
|
|
}
|
|
if let integrity = integrity {
|
|
result += " integrity='\(integrity)'"
|
|
}
|
|
if let referrerpolicy = referrerpolicy {
|
|
result += " referrerpolicy='\(referrerpolicy.rawValue)'"
|
|
}
|
|
if let src = src {
|
|
result += " src='\(src.absoluteString)'"
|
|
}
|
|
if let type = type {
|
|
result += " type='\(type)'"
|
|
}
|
|
|
|
|
|
return result
|
|
}
|
|
|
|
override var nodeName: String {
|
|
return "script"
|
|
}
|
|
|
|
override var isVoidElement: Bool {
|
|
return false
|
|
}
|
|
} |