From b092c3247fba08b7f37df76acae63ed03e9e934b Mon Sep 17 00:00:00 2001 From: Isaac Paul Date: Mon, 18 May 2026 22:31:29 -0400 Subject: [PATCH] Bug fixes, aria, cross platform support. --- Plugins/BindingPlugin/source.swift | 26 ++++--- Sources/BindingGenerator/BaseComponents.swift | 49 +++++++++++-- Sources/HRW/BaseComponents.swift | 68 ++++++++++++++----- Tests/HRWTests/Test.swift | 9 +++ 4 files changed, 119 insertions(+), 33 deletions(-) diff --git a/Plugins/BindingPlugin/source.swift b/Plugins/BindingPlugin/source.swift index 5ac8163..6523c70 100644 --- a/Plugins/BindingPlugin/source.swift +++ b/Plugins/BindingPlugin/source.swift @@ -54,7 +54,6 @@ extension BindingPlugin: BuildToolPlugin { #if canImport(XcodeProjectPlugin) import XcodeProjectPlugin -import System // The entry point for Xcode project builds. extension BindingPlugin: XcodeBuildToolPlugin { @@ -149,15 +148,22 @@ struct BindingPlugin { let extIndex = fileName.index(fileName.startIndex, offsetBy: fileName.count - (ext.count + 1)) let withoutExt = String(fileName[fileName.startIndex.. { get set } var globalEvents:Dictionary { get set } var dataAttributes:Dictionary { get set } + var ariaAttributes:Dictionary { get set } } extension IGlobalContainer { @@ -29,6 +30,10 @@ extension IGlobalContainer { dataAttributes[key] = value return true } + if key[.. = [:] public var globalEvents:Dictionary = [:] public var dataAttributes:Dictionary = [:] + public var ariaAttributes:Dictionary = [:] - public init(globalAttributes: Dictionary, globalEvents: Dictionary, dataAttributes: Dictionary) { + public init(globalAttributes: Dictionary, globalEvents: Dictionary, dataAttributes: Dictionary, ariaAttributes: Dictionary = [:]) { self.globalAttributes = globalAttributes self.globalEvents = globalEvents self.dataAttributes = dataAttributes + self.ariaAttributes = ariaAttributes } public init() { self.globalAttributes = [:] self.globalEvents = [:] self.dataAttributes = [:] + self.ariaAttributes = [:] } public init(_ attributes: [String: String]) throws { self.globalAttributes = [:] self.globalEvents = [:] self.dataAttributes = [:] + self.ariaAttributes = [:] for (key, value) in attributes { if self.trySetGlobalAttribute(key, value) { continue @@ -101,6 +110,7 @@ public class HTMLNode : XMLNode, IGlobalContainer { public var globalAttributes:Dictionary = [:] public var globalEvents:Dictionary = [:] + public var ariaAttributes:Dictionary = [:] public var children:[HTMLNode] = [] @@ -115,23 +125,31 @@ public class HTMLNode : XMLNode, IGlobalContainer { globalEvents[attr] = value continue } - if key[..= 5 { + if key[.., globalEvents:Dictionary, dataAttributes:Dictionary) { + public init(globalAttributes:Dictionary, globalEvents:Dictionary, dataAttributes:Dictionary, ariaAttributes:Dictionary = [:]) { self.globalAttributes = globalAttributes self.globalEvents = globalEvents + self.ariaAttributes = ariaAttributes super.init(dataAttributes: dataAttributes) } public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) { self.globalAttributes = builder.globalAttributes self.globalEvents = builder.globalEvents + self.ariaAttributes = builder.ariaAttributes self.children = children super.init(dataAttributes: builder.dataAttributes) } @@ -213,6 +231,18 @@ public class HTMLNode : XMLNode, IGlobalContainer { result += "\(eachAttr.key)" } } + + for eachAttr in ariaAttributes { + if (!first) { + result += " " + } + first = false + if (eachAttr.value.count > 0) { + result += "\(eachAttr.key)='\(eachAttr.value)'" + } else { + result += "\(eachAttr.key)" + } + } return result } @@ -369,8 +399,13 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool { if let _ = GlobalEventKey(rawValue: key.asSubstring()) { return true } - if key[..= 5 { + if key[.. { get set } var globalEvents:Dictionary { get set } var dataAttributes:Dictionary { get set } + var ariaAttributes:Dictionary { get set } } extension IGlobalContainer { @@ -27,9 +28,15 @@ extension IGlobalContainer { globalEvents[attr] = value return true } - if key[..= 5 { + if key[.. = [:] public var globalEvents:Dictionary = [:] public var dataAttributes:Dictionary = [:] + public var ariaAttributes:Dictionary = [:] - public init(globalAttributes: Dictionary, globalEvents: Dictionary, dataAttributes: Dictionary) { + public init(globalAttributes: Dictionary, globalEvents: Dictionary, dataAttributes: Dictionary, ariaAttributes: Dictionary = [:]) { self.globalAttributes = globalAttributes self.globalEvents = globalEvents self.dataAttributes = dataAttributes + self.ariaAttributes = ariaAttributes } public init() { self.globalAttributes = [:] self.globalEvents = [:] self.dataAttributes = [:] + self.ariaAttributes = [:] } public init(_ attributes: [String: String]) throws { self.globalAttributes = [:] self.globalEvents = [:] self.dataAttributes = [:] + self.ariaAttributes = [:] for (key, value) in attributes { if self.trySetGlobalAttribute(key, value) { continue @@ -136,6 +147,7 @@ public class HTMLNode : XMLNode, IGlobalContainer { public var globalAttributes:Dictionary = [:] public var globalEvents:Dictionary = [:] + public var ariaAttributes:Dictionary = [:] public var children:[HTMLNode] = [] @@ -150,23 +162,31 @@ public class HTMLNode : XMLNode, IGlobalContainer { globalEvents[attr] = value continue } - if key[..= 5 { + if key[.., globalEvents:Dictionary, dataAttributes:Dictionary) { + public init(globalAttributes:Dictionary, globalEvents:Dictionary, dataAttributes:Dictionary, ariaAttributes:Dictionary = [:]) { self.globalAttributes = globalAttributes self.globalEvents = globalEvents + self.ariaAttributes = ariaAttributes super.init(dataAttributes: dataAttributes) } public init(_ builder:GlobalAttributesBuilder, _ children:[HTMLNode] = []) { self.globalAttributes = builder.globalAttributes self.globalEvents = builder.globalEvents + self.ariaAttributes = builder.ariaAttributes self.children = children super.init(dataAttributes: builder.dataAttributes) } @@ -229,24 +249,36 @@ public class HTMLNode : XMLNode, IGlobalContainer { } first = false if (eachAttr.value.count > 0) { - result += "\(eachAttr.key)='\(eachAttr.value)'" + result += "\(eachAttr.key.rawValue)='\(eachAttr.value)'" } else { - result += "\(eachAttr.key)" + result += "\(eachAttr.key.rawValue)" } } - + for eachAttr in globalEvents { if (!first) { result += " " } first = false if (eachAttr.value.count > 0) { - result += "\(eachAttr.key) = \(eachAttr.value)" + result += "\(eachAttr.key.rawValue) = \(eachAttr.value)" + } else { + result += "\(eachAttr.key.rawValue)" + } + } + + for eachAttr in ariaAttributes { + if (!first) { + result += " " + } + first = false + if (eachAttr.value.count > 0) { + result += "\(eachAttr.key)='\(eachAttr.value)'" } else { result += "\(eachAttr.key)" } } - + return result } @@ -402,8 +434,13 @@ func isGlobalHTMLAttribute(_ key:String) -> Bool { if let _ = GlobalEventKey(rawValue: key.asSubstring()) { return true } - if key[..= 5 { + if key[..