Skip to content

Commit 7687223

Browse files
update minimum required platforms and...
- `HTMLElement`, `HTMLEncoding` and `HTMLInitializable` now conform to `Sendable` - use `FoundationEssentials` instead of `Foundation` where applicable - added some `@inlinable` annotations - made access control visibility more aligned with best practices and industry standards - fixed spacing for `switch` `case` statements
1 parent db8ae26 commit 7687223

25 files changed

+1532
-1523
lines changed

Package.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import CompilerPluginSupport
77
let package = Package(
88
name: "swift-htmlkit",
99
platforms: [
10-
.macOS(.v13)
10+
.macOS(.v14),
11+
.iOS(.v17),
12+
.tvOS(.v17),
13+
.visionOS(.v1),
14+
.watchOS(.v10)
1115
],
1216
products: [
1317
.library(

Sources/GenerateElements/main.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import SwiftSyntax
4848
public struct %elementName% : HTMLElement {%variables%%render%
4949
}
5050
51-
public extension %elementName% {
52-
enum AttributeKeys {%customAttributeCases%
51+
extension %elementName% {
52+
public enum AttributeKeys {%customAttributeCases%
5353
}
5454
}
5555
"""
@@ -167,7 +167,10 @@ for (elementType, customAttributes) in attributes().filter({ $0.key == .a }) {
167167
renderAttributesString += indent2 + "}"
168168
renderString += renderAttributesString + "\n"
169169
renderString += """
170-
let string:String = innerHTML.map({ String(describing: $0) }).joined()
170+
var string:String = ""
171+
for element in innerHTML {
172+
string += String(describing: $0)
173+
}
171174
let l:String, g:String
172175
if escaped {
173176
l = "<"

Sources/HTMLKit/HTMLKit.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
@_exported import HTMLKitUtilities
99

1010
// MARK: StaticString equality
11-
public extension StaticString {
12-
static func == (left: Self, right: Self) -> Bool { left.description == right.description }
13-
static func != (left: Self, right: Self) -> Bool { left.description != right.description }
11+
extension StaticString {
12+
public static func == (left: Self, right: Self) -> Bool { left.description == right.description }
13+
public static func != (left: Self, right: Self) -> Bool { left.description != right.description }
1414
}
1515
// MARK: StaticString and StringProtocol equality
16-
public extension StringProtocol {
17-
static func == (left: Self, right: StaticString) -> Bool { left == right.description }
18-
static func == (left: StaticString, right: Self) -> Bool { left.description == right }
16+
extension StringProtocol {
17+
public static func == (left: Self, right: StaticString) -> Bool { left == right.description }
18+
public static func == (left: StaticString, right: Self) -> Bool { left.description == right }
1919
}
2020

2121
@freestanding(expression)
2222
public macro escapeHTML(
2323
encoding: HTMLEncoding = .string,
24-
_ innerHTML: CustomStringConvertible...
24+
_ innerHTML: CustomStringConvertible & Sendable...
2525
) -> String = #externalMacro(module: "HTMLKitMacros", type: "EscapeHTML")
2626

2727
// MARK: HTML Representation
2828
@freestanding(expression)
2929
public macro html<T: CustomStringConvertible>(
3030
encoding: HTMLEncoding = .string,
3131
lookupFiles: [StaticString] = [],
32-
_ innerHTML: CustomStringConvertible...
32+
_ innerHTML: CustomStringConvertible & Sendable...
3333
) -> T = #externalMacro(module: "HTMLKitMacros", type: "HTMLElementMacro")

Sources/HTMLKitUtilities/HTMLElementValueType.swift

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -31,123 +31,123 @@ package indirect enum HTMLElementValueType {
3131
}
3232
let children:SyntaxChildren = function.arguments.children(viewMode: .all)
3333
switch key {
34-
case "a": return a(context, encoding, children)
35-
case "abbr": return abbr(context, encoding, children)
36-
case "address": return address(context, encoding, children)
37-
case "area": return area(context, encoding, children)
38-
case "article": return article(context, encoding, children)
39-
case "aside": return aside(context, encoding, children)
40-
case "audio": return audio(context, encoding, children)
41-
case "b": return b(context, encoding, children)
42-
case "base": return base(context, encoding, children)
43-
case "bdi": return bdi(context, encoding, children)
44-
case "bdo": return bdo(context, encoding, children)
45-
case "blockquote": return blockquote(context, encoding, children)
46-
case "body": return body(context, encoding, children)
47-
case "br": return br(context, encoding, children)
48-
case "button": return button(context, encoding, children)
49-
case "canvas": return canvas(context, encoding, children)
50-
case "caption": return caption(context, encoding, children)
51-
case "cite": return cite(context, encoding, children)
52-
case "code": return code(context, encoding, children)
53-
case "col": return col(context, encoding, children)
54-
case "colgroup": return colgroup(context, encoding, children)
55-
case "data": return data(context, encoding, children)
56-
case "datalist": return datalist(context, encoding, children)
57-
case "dd": return dd(context, encoding, children)
58-
case "del": return del(context, encoding, children)
59-
case "details": return details(context, encoding, children)
60-
case "dfn": return dfn(context, encoding, children)
61-
case "dialog": return dialog(context, encoding, children)
62-
case "div": return div(context, encoding, children)
63-
case "dl": return dl(context, encoding, children)
64-
case "dt": return dt(context, encoding, children)
65-
case "em": return em(context, encoding, children)
66-
case "embed": return embed(context, encoding, children)
67-
case "fencedframe": return fencedframe(context, encoding, children)
68-
case "fieldset": return fieldset(context, encoding, children)
69-
case "figcaption": return figcaption(context, encoding, children)
70-
case "figure": return figure(context, encoding, children)
71-
case "footer": return footer(context, encoding, children)
72-
case "form": return form(context, encoding, children)
73-
case "h1": return h1(context, encoding, children)
74-
case "h2": return h2(context, encoding, children)
75-
case "h3": return h3(context, encoding, children)
76-
case "h4": return h4(context, encoding, children)
77-
case "h5": return h5(context, encoding, children)
78-
case "h6": return h6(context, encoding, children)
79-
case "head": return head(context, encoding, children)
80-
case "header": return header(context, encoding, children)
81-
case "hgroup": return hgroup(context, encoding, children)
82-
case "hr": return hr(context, encoding, children)
83-
case "html": return html(context, encoding, children)
84-
case "i": return i(context, encoding, children)
85-
case "iframe": return iframe(context, encoding, children)
86-
case "img": return img(context, encoding, children)
87-
case "input": return input(context, encoding, children)
88-
case "ins": return ins(context, encoding, children)
89-
case "kbd": return kbd(context, encoding, children)
90-
case "label": return label(context, encoding, children)
91-
case "legend": return legend(context, encoding, children)
92-
case "li": return li(context, encoding, children)
93-
case "link": return link(context, encoding, children)
94-
case "main": return main(context, encoding, children)
95-
case "map": return map(context, encoding, children)
96-
case "mark": return mark(context, encoding, children)
97-
case "menu": return menu(context, encoding, children)
98-
case "meta": return meta(context, encoding, children)
99-
case "meter": return meter(context, encoding, children)
100-
case "nav": return nav(context, encoding, children)
101-
case "noscript": return noscript(context, encoding, children)
102-
case "object": return object(context, encoding, children)
103-
case "ol": return ol(context, encoding, children)
104-
case "optgroup": return optgroup(context, encoding, children)
105-
case "option": return option(context, encoding, children)
106-
case "output": return output(context, encoding, children)
107-
case "p": return p(context, encoding, children)
108-
case "picture": return picture(context, encoding, children)
109-
case "portal": return portal(context, encoding, children)
110-
case "pre": return pre(context, encoding, children)
111-
case "progress": return progress(context, encoding, children)
112-
case "q": return q(context, encoding, children)
113-
case "rp": return rp(context, encoding, children)
114-
case "rt": return rt(context, encoding, children)
115-
case "ruby": return ruby(context, encoding, children)
116-
case "s": return s(context, encoding, children)
117-
case "samp": return samp(context, encoding, children)
118-
case "script": return script(context, encoding, children)
119-
case "search": return search(context, encoding, children)
120-
case "section": return section(context, encoding, children)
121-
case "select": return select(context, encoding, children)
122-
case "slot": return slot(context, encoding, children)
123-
case "small": return small(context, encoding, children)
124-
case "source": return source(context, encoding, children)
125-
case "span": return span(context, encoding, children)
126-
case "strong": return strong(context, encoding, children)
127-
case "style": return style(context, encoding, children)
128-
case "sub": return sub(context, encoding, children)
129-
case "summary": return summary(context, encoding, children)
130-
case "sup": return sup(context, encoding, children)
131-
case "table": return table(context, encoding, children)
132-
case "tbody": return tbody(context, encoding, children)
133-
case "td": return td(context, encoding, children)
134-
case "template": return template(context, encoding, children)
135-
case "textarea": return textarea(context, encoding, children)
136-
case "tfoot": return tfoot(context, encoding, children)
137-
case "th": return th(context, encoding, children)
138-
case "thead": return thead(context, encoding, children)
139-
case "time": return time(context, encoding, children)
140-
case "title": return title(context, encoding, children)
141-
case "tr": return tr(context, encoding, children)
142-
case "track": return track(context, encoding, children)
143-
case "u": return u(context, encoding, children)
144-
case "ul": return ul(context, encoding, children)
145-
case "variable": return variable(context, encoding, children)
146-
case "video": return video(context, encoding, children)
147-
case "wbr": return wbr(context, encoding, children)
34+
case "a": return a(context, encoding, children)
35+
case "abbr": return abbr(context, encoding, children)
36+
case "address": return address(context, encoding, children)
37+
case "area": return area(context, encoding, children)
38+
case "article": return article(context, encoding, children)
39+
case "aside": return aside(context, encoding, children)
40+
case "audio": return audio(context, encoding, children)
41+
case "b": return b(context, encoding, children)
42+
case "base": return base(context, encoding, children)
43+
case "bdi": return bdi(context, encoding, children)
44+
case "bdo": return bdo(context, encoding, children)
45+
case "blockquote": return blockquote(context, encoding, children)
46+
case "body": return body(context, encoding, children)
47+
case "br": return br(context, encoding, children)
48+
case "button": return button(context, encoding, children)
49+
case "canvas": return canvas(context, encoding, children)
50+
case "caption": return caption(context, encoding, children)
51+
case "cite": return cite(context, encoding, children)
52+
case "code": return code(context, encoding, children)
53+
case "col": return col(context, encoding, children)
54+
case "colgroup": return colgroup(context, encoding, children)
55+
case "data": return data(context, encoding, children)
56+
case "datalist": return datalist(context, encoding, children)
57+
case "dd": return dd(context, encoding, children)
58+
case "del": return del(context, encoding, children)
59+
case "details": return details(context, encoding, children)
60+
case "dfn": return dfn(context, encoding, children)
61+
case "dialog": return dialog(context, encoding, children)
62+
case "div": return div(context, encoding, children)
63+
case "dl": return dl(context, encoding, children)
64+
case "dt": return dt(context, encoding, children)
65+
case "em": return em(context, encoding, children)
66+
case "embed": return embed(context, encoding, children)
67+
case "fencedframe": return fencedframe(context, encoding, children)
68+
case "fieldset": return fieldset(context, encoding, children)
69+
case "figcaption": return figcaption(context, encoding, children)
70+
case "figure": return figure(context, encoding, children)
71+
case "footer": return footer(context, encoding, children)
72+
case "form": return form(context, encoding, children)
73+
case "h1": return h1(context, encoding, children)
74+
case "h2": return h2(context, encoding, children)
75+
case "h3": return h3(context, encoding, children)
76+
case "h4": return h4(context, encoding, children)
77+
case "h5": return h5(context, encoding, children)
78+
case "h6": return h6(context, encoding, children)
79+
case "head": return head(context, encoding, children)
80+
case "header": return header(context, encoding, children)
81+
case "hgroup": return hgroup(context, encoding, children)
82+
case "hr": return hr(context, encoding, children)
83+
case "html": return html(context, encoding, children)
84+
case "i": return i(context, encoding, children)
85+
case "iframe": return iframe(context, encoding, children)
86+
case "img": return img(context, encoding, children)
87+
case "input": return input(context, encoding, children)
88+
case "ins": return ins(context, encoding, children)
89+
case "kbd": return kbd(context, encoding, children)
90+
case "label": return label(context, encoding, children)
91+
case "legend": return legend(context, encoding, children)
92+
case "li": return li(context, encoding, children)
93+
case "link": return link(context, encoding, children)
94+
case "main": return main(context, encoding, children)
95+
case "map": return map(context, encoding, children)
96+
case "mark": return mark(context, encoding, children)
97+
case "menu": return menu(context, encoding, children)
98+
case "meta": return meta(context, encoding, children)
99+
case "meter": return meter(context, encoding, children)
100+
case "nav": return nav(context, encoding, children)
101+
case "noscript": return noscript(context, encoding, children)
102+
case "object": return object(context, encoding, children)
103+
case "ol": return ol(context, encoding, children)
104+
case "optgroup": return optgroup(context, encoding, children)
105+
case "option": return option(context, encoding, children)
106+
case "output": return output(context, encoding, children)
107+
case "p": return p(context, encoding, children)
108+
case "picture": return picture(context, encoding, children)
109+
case "portal": return portal(context, encoding, children)
110+
case "pre": return pre(context, encoding, children)
111+
case "progress": return progress(context, encoding, children)
112+
case "q": return q(context, encoding, children)
113+
case "rp": return rp(context, encoding, children)
114+
case "rt": return rt(context, encoding, children)
115+
case "ruby": return ruby(context, encoding, children)
116+
case "s": return s(context, encoding, children)
117+
case "samp": return samp(context, encoding, children)
118+
case "script": return script(context, encoding, children)
119+
case "search": return search(context, encoding, children)
120+
case "section": return section(context, encoding, children)
121+
case "select": return select(context, encoding, children)
122+
case "slot": return slot(context, encoding, children)
123+
case "small": return small(context, encoding, children)
124+
case "source": return source(context, encoding, children)
125+
case "span": return span(context, encoding, children)
126+
case "strong": return strong(context, encoding, children)
127+
case "style": return style(context, encoding, children)
128+
case "sub": return sub(context, encoding, children)
129+
case "summary": return summary(context, encoding, children)
130+
case "sup": return sup(context, encoding, children)
131+
case "table": return table(context, encoding, children)
132+
case "tbody": return tbody(context, encoding, children)
133+
case "td": return td(context, encoding, children)
134+
case "template": return template(context, encoding, children)
135+
case "textarea": return textarea(context, encoding, children)
136+
case "tfoot": return tfoot(context, encoding, children)
137+
case "th": return th(context, encoding, children)
138+
case "thead": return thead(context, encoding, children)
139+
case "time": return time(context, encoding, children)
140+
case "title": return title(context, encoding, children)
141+
case "tr": return tr(context, encoding, children)
142+
case "track": return track(context, encoding, children)
143+
case "u": return u(context, encoding, children)
144+
case "ul": return ul(context, encoding, children)
145+
case "variable": return variable(context, encoding, children)
146+
case "video": return video(context, encoding, children)
147+
case "wbr": return wbr(context, encoding, children)
148148

149-
case "custom": return custom(context, encoding, children)
150-
default: return nil
149+
case "custom": return custom(context, encoding, children)
150+
default: return nil
151151
}
152152
}
153153
}

Sources/HTMLKitUtilities/HTMLEncoding.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// let _:String = #html(div(string)) // ⚠️ promotion cannot be applied; compiles to "<div>" + String(describing: string) + "</div>"
3131
/// ```
3232
///
33-
public enum HTMLEncoding {
33+
public enum HTMLEncoding : Sendable {
3434
/// `String`/`StaticString`
3535
case string
3636

@@ -44,7 +44,7 @@ public enum HTMLEncoding {
4444
case utf16Bytes
4545

4646
/// `Data`
47-
/// - Warning: You need to import `Foundation` to use this!
47+
/// - Warning: You need to import `Foundation`/`FoundationEssentials` to use this!
4848
case foundationData
4949

5050
/// `ByteBuffer`
@@ -66,25 +66,25 @@ public enum HTMLEncoding {
6666

6767
public init?(rawValue: String) {
6868
switch rawValue {
69-
case "string": self = .string
70-
case "utf8Bytes": self = .utf8Bytes
71-
case "utf8CString": self = .utf8CString
72-
case "utf16Bytes": self = .utf16Bytes
73-
case "foundationData": self = .foundationData
74-
case "byteBuffer": self = .byteBuffer
75-
default: return nil
69+
case "string": self = .string
70+
case "utf8Bytes": self = .utf8Bytes
71+
case "utf8CString": self = .utf8CString
72+
case "utf16Bytes": self = .utf16Bytes
73+
case "foundationData": self = .foundationData
74+
case "byteBuffer": self = .byteBuffer
75+
default: return nil
7676
}
7777
}
7878

7979
@inlinable
8080
public func stringDelimiter(forMacro: Bool) -> String {
8181
switch self {
82-
case .string:
83-
return forMacro ? "\\\"" : "\""
84-
case .utf8Bytes, .utf16Bytes, .utf8CString, .foundationData, .byteBuffer:
85-
return "\""
86-
case .custom(_, let delimiter):
87-
return delimiter
82+
case .string:
83+
return forMacro ? "\\\"" : "\""
84+
case .utf8Bytes, .utf16Bytes, .utf8CString, .foundationData, .byteBuffer:
85+
return "\""
86+
case .custom(_, let delimiter):
87+
return delimiter
8888
}
8989
}
9090
}

0 commit comments

Comments
 (0)