Skip to content

Commit bdf74c6

Browse files
module refactor part 2
1 parent 304b3e7 commit bdf74c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+983
-3802
lines changed

Package.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,46 @@ let package = Package(
4646
.target(
4747
name: "CSS",
4848
dependencies: [
49-
"HTMLKitUtilities"
49+
"HTMLKitUtilities",
50+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
51+
.product(name: "SwiftSyntax", package: "swift-syntax"),
52+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
5053
]
5154
),
5255
.target(
5356
name: "HTMX",
5457
dependencies: [
55-
"HTMLKitUtilities"
58+
"HTMLKitUtilities",
59+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
60+
.product(name: "SwiftSyntax", package: "swift-syntax"),
61+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
5662
]
5763
),
5864

5965
.target(
6066
name: "HTMLAttributes",
6167
dependencies: [
6268
"CSS",
63-
"HTMX"
69+
"HTMX",
70+
"HTMLKitUtilities",
71+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
72+
.product(name: "SwiftSyntax", package: "swift-syntax"),
73+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
6474
]
6575
),
6676

6777
.target(
6878
name: "HTMLElements",
6979
dependencies: [
70-
"HTMLAttributes"
80+
"HTMLKitUtilities",
81+
"HTMLAttributes",
82+
"CSS",
83+
"HTMX"
7184
]
7285
),
7386

7487
.target(
75-
name: "HTMLKitMacroImpl",
88+
name: "HTMLKitParse",
7689
dependencies: [
7790
"HTMLElements"
7891
]
@@ -81,7 +94,7 @@ let package = Package(
8194
.macro(
8295
name: "HTMLKitMacros",
8396
dependencies: [
84-
"HTMLKitUtilities",
97+
"HTMLKitParse",
8598
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
8699
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
87100
.product(name: "SwiftSyntax", package: "swift-syntax"),
@@ -99,7 +112,7 @@ let package = Package(
99112

100113
.testTarget(
101114
name: "HTMLKitTests",
102-
dependencies: ["HTMLKit"]
115+
dependencies: ["HTMLKit", "HTMLAttributes", "HTMLElements"]
103116
),
104117
]
105118
)

Sources/CSS/CSS.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import HTMLKitUtilities
99
import SwiftSyntax
1010
import SwiftSyntaxMacros
1111

12-
public enum CSSStyle : HTMLInitializable {
12+
public enum CSSStyle : HTMLParsable {
1313
public typealias SFloat = Swift.Float
1414

15-
case accentColor(AccentColor?)
15+
//case accentColor(AccentColor?)
1616
//case align(Align?)
1717
case all
1818
//case animation(Animation?)
@@ -144,7 +144,7 @@ public enum CSSStyle : HTMLInitializable {
144144
@inlinable
145145
public var key : String {
146146
switch self {
147-
case .accentColor: return "accentColor"
147+
//case .accentColor: return "accentColor"
148148
//case .align: return "align"
149149
case .all: return "all"
150150
//case .animation: return "animation"

Sources/CSS/CSSUnit.swift

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,6 @@ public enum CSSUnit : HTMLInitializable { // https://www.w3schools.com/cssref/cs
4747
/// Relative to the parent element
4848
case percent(_ value: Float?)
4949

50-
#if canImport(SwiftSyntax)
51-
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
52-
let expression:ExprSyntax = arguments.first!.expression
53-
func float() -> Float? {
54-
guard let s:String = expression.integerLiteral?.literal.text ?? expression.floatLiteral?.literal.text else { return nil }
55-
return Float(s)
56-
}
57-
switch key {
58-
case "centimeters": self = .centimeters(float())
59-
case "millimeters": self = .millimeters(float())
60-
case "inches": self = .inches(float())
61-
case "pixels": self = .pixels(float())
62-
case "points": self = .points(float())
63-
case "picas": self = .picas(float())
64-
65-
case "em": self = .em(float())
66-
case "ex": self = .ex(float())
67-
case "ch": self = .ch(float())
68-
case "rem": self = .rem(float())
69-
case "viewportWidth": self = .viewportWidth(float())
70-
case "viewportHeight": self = .viewportHeight(float())
71-
case "viewportMin": self = .viewportMin(float())
72-
case "viewportMax": self = .viewportMax(float())
73-
case "percent": self = .percent(float())
74-
default: return nil
75-
}
76-
}
77-
#endif
78-
7950
@inlinable
8051
public var key : String {
8152
switch self {
@@ -153,4 +124,36 @@ public enum CSSUnit : HTMLInitializable { // https://www.w3schools.com/cssref/cs
153124
case .percent: return "%"
154125
}
155126
}
156-
}
127+
}
128+
129+
#if canImport(SwiftSyntax)
130+
// MARK: HTMLParsable
131+
extension CSSUnit : HTMLParsable {
132+
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
133+
let expression:ExprSyntax = arguments.first!.expression
134+
func float() -> Float? {
135+
guard let s:String = expression.integerLiteral?.literal.text ?? expression.floatLiteral?.literal.text else { return nil }
136+
return Float(s)
137+
}
138+
switch key {
139+
case "centimeters": self = .centimeters(float())
140+
case "millimeters": self = .millimeters(float())
141+
case "inches": self = .inches(float())
142+
case "pixels": self = .pixels(float())
143+
case "points": self = .points(float())
144+
case "picas": self = .picas(float())
145+
146+
case "em": self = .em(float())
147+
case "ex": self = .ex(float())
148+
case "ch": self = .ch(float())
149+
case "rem": self = .rem(float())
150+
case "viewportWidth": self = .viewportWidth(float())
151+
case "viewportHeight": self = .viewportHeight(float())
152+
case "viewportMin": self = .viewportMin(float())
153+
case "viewportMax": self = .viewportMax(float())
154+
case "percent": self = .percent(float())
155+
default: return nil
156+
}
157+
}
158+
}
159+
#endif

Sources/CSS/styles/AccentColor.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import HTMLKitUtilities
99
import SwiftSyntax
1010
import SwiftSyntaxMacros
1111

12+
/*
1213
extension CSSStyle {
1314
public enum AccentColor : HTMLInitializable {
1415
case auto
@@ -19,19 +20,6 @@ extension CSSStyle {
1920
case revertLayer
2021
case unset
2122

22-
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
23-
switch key {
24-
case "auto": self = .auto
25-
case "color": self = .color(arguments.first!.expression.enumeration(context: context, isUnchecked: isUnchecked, key: key, arguments: arguments))
26-
case "inherit": self = .inherit
27-
case "initial": self = .initial
28-
case "revert": self = .revert
29-
case "revertLayer": self = .revertLayer
30-
case "unset": self = .unset
31-
default: return nil
32-
}
33-
}
34-
3523
@inlinable
3624
public var key : String {
3725
switch self {
@@ -61,4 +49,4 @@ extension CSSStyle {
6149
@inlinable
6250
public var htmlValueIsVoidable : Bool { false }
6351
}
64-
}
52+
}*/

Sources/CSS/styles/Duration.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@ extension CSSStyle {
2121
case s(SFloat?)
2222
case unset
2323

24-
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
25-
switch key {
26-
case "auto": self = .auto
27-
case "inherit": self = .inherit
28-
case "initial": self = .initial
29-
case "ms": self = .ms(arguments.first!.expression.int(context: context, key: key))
30-
case "multiple": self = .multiple(arguments.first!.expression.array!.elements.compactMap({ $0.expression.enumeration(context: context, isUnchecked: isUnchecked, key: key, arguments: arguments) }))
31-
case "revert": self = .revert
32-
case "revertLayer": self = .revertLayer
33-
case "s": self = .s(arguments.first!.expression.float(context: context, key: key))
34-
case "unset": self = .unset
35-
default: return nil
36-
}
37-
}
38-
3924
public var key : String { "" }
4025

4126
@inlinable

Sources/CSS/styles/Opacity.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ extension CSSStyle {
1919
case revertLayer
2020
case unset
2121

22-
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
23-
switch key {
24-
case "float": self = .float(arguments.first!.expression.float(context: context, key: key))
25-
case "inherit": self = .inherit
26-
case "initial": self = .initial
27-
case "percent": self = .percent(arguments.first!.expression.float(context: context, key: key))
28-
case "revert": self = .revert
29-
case "revertLayer": self = .revertLayer
30-
case "unset": self = .unset
31-
default: return nil
32-
}
33-
}
34-
3522
public var key : String { "" }
3623

3724
@inlinable

Sources/CSS/styles/Zoom.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@ extension CSSStyle {
2121
case revertLayer
2222
case unset
2323

24-
public init?(context: some MacroExpansionContext, isUnchecked: Bool, key: String, arguments: LabeledExprListSyntax) {
25-
switch key {
26-
case "float": self = .float(arguments.first!.expression.float(context: context, key: key))
27-
case "inherit": self = .inherit
28-
case "initial": self = .initial
29-
case "normal": self = .normal
30-
case "percent": self = .percent(arguments.first!.expression.float(context: context, key: key))
31-
case "reset": self = .reset
32-
case "revert": self = .revert
33-
case "revertLayer": self = .revertLayer
34-
case "unset": self = .revertLayer
35-
default: return nil
36-
}
37-
}
38-
3924
public var key : String { "" }
4025

4126
@inlinable

0 commit comments

Comments
 (0)