Skip to content

Commit 6ec1ba0

Browse files
move all swift syntax stuff to HTMLKitParse module or the macro targets to reduce binary size
1 parent cd244ad commit 6ec1ba0

Some content is hidden

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

49 files changed

+613
-533
lines changed

Package.swift

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ let package = Package(
1313
.watchOS(.v9)
1414
],
1515
products: [
16-
.library(
17-
name: "HTMLKit",
18-
targets: ["HTMLKit"]
19-
)
16+
.library(name: "HTMLKit", targets: ["HTMLKit"]),
17+
.library(name: "HTMLKitParse", targets: ["HTMLKitParse"])
2018
],
2119
dependencies: [
2220
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.1")
@@ -35,29 +33,20 @@ let package = Package(
3533
.target(
3634
name: "HTMLKitUtilities",
3735
dependencies: [
38-
"HTMLKitUtilityMacros",
39-
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
40-
.product(name: "SwiftSyntax", package: "swift-syntax"),
41-
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
36+
"HTMLKitUtilityMacros"
4237
]
4338
),
4439

4540
.target(
4641
name: "CSS",
4742
dependencies: [
48-
"HTMLKitUtilities",
49-
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
50-
.product(name: "SwiftSyntax", package: "swift-syntax"),
51-
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
43+
"HTMLKitUtilities"
5244
]
5345
),
5446
.target(
5547
name: "HTMX",
5648
dependencies: [
57-
"HTMLKitUtilities",
58-
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
59-
.product(name: "SwiftSyntax", package: "swift-syntax"),
60-
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
49+
"HTMLKitUtilities"
6150
]
6251
),
6352

@@ -66,10 +55,7 @@ let package = Package(
6655
dependencies: [
6756
"CSS",
6857
"HTMX",
69-
"HTMLKitUtilities",
70-
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
71-
.product(name: "SwiftSyntax", package: "swift-syntax"),
72-
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
58+
"HTMLKitUtilities"
7359
]
7460
),
7561

@@ -86,7 +72,14 @@ let package = Package(
8672
.target(
8773
name: "HTMLKitParse",
8874
dependencies: [
89-
"HTMLElements"
75+
"CSS",
76+
"HTMLAttributes",
77+
"HTMLElements",
78+
"HTMLKitUtilities",
79+
"HTMX",
80+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
81+
.product(name: "SwiftSyntax", package: "swift-syntax"),
82+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax")
9083
]
9184
),
9285

@@ -107,7 +100,6 @@ let package = Package(
107100
"CSS",
108101
"HTMLAttributes",
109102
"HTMLElements",
110-
"HTMLKitParse",
111103
"HTMLKitUtilities",
112104
"HTMLKitMacros",
113105
"HTMX"

Sources/CSS/CSSUnit.swift

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import HTMLKitUtilities
44
#endif
55

6-
#if canImport(SwiftSyntax)
7-
import SwiftSyntax
8-
#endif
9-
106
public enum CSSUnit: HTMLInitializable { // https://www.w3schools.com/cssref/css_units.php
117
// absolute
128
case centimeters(_ value: Float?)
@@ -114,39 +110,4 @@ public enum CSSUnit: HTMLInitializable { // https://www.w3schools.com/cssref/css
114110
case .percent: "%"
115111
}
116112
}
117-
}
118-
119-
#if canImport(SwiftSyntax)
120-
// MARK: HTMLParsable
121-
extension CSSUnit: HTMLParsable {
122-
public init?(context: HTMLExpansionContext) {
123-
func float() -> Float? {
124-
guard let expression = context.expression,
125-
let s = expression.integerLiteral?.literal.text ?? expression.floatLiteral?.literal.text
126-
else {
127-
return nil
128-
}
129-
return Float(s)
130-
}
131-
switch context.key {
132-
case "centimeters": self = .centimeters(float())
133-
case "millimeters": self = .millimeters(float())
134-
case "inches": self = .inches(float())
135-
case "pixels": self = .pixels(float())
136-
case "points": self = .points(float())
137-
case "picas": self = .picas(float())
138-
139-
case "em": self = .em(float())
140-
case "ex": self = .ex(float())
141-
case "ch": self = .ch(float())
142-
case "rem": self = .rem(float())
143-
case "viewportWidth": self = .viewportWidth(float())
144-
case "viewportHeight": self = .viewportHeight(float())
145-
case "viewportMin": self = .viewportMin(float())
146-
case "viewportMax": self = .viewportMax(float())
147-
case "percent": self = .percent(float())
148-
default: return nil
149-
}
150-
}
151-
}
152-
#endif
113+
}

Sources/CSS/styles/All.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum All: String, HTMLParsable {
5+
public enum All: String, HTMLInitializable {
66
case initial
77
case inherit
88
case unset

Sources/CSS/styles/Appearance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum Appearance: String, HTMLParsable {
5+
public enum Appearance: String, HTMLInitializable {
66
case auto
77
case button
88
case checkbox

Sources/CSS/styles/BackfaceVisibility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum BackfaceVisibility: String, HTMLParsable {
5+
public enum BackfaceVisibility: String, HTMLInitializable {
66
case hidden
77
case inherit
88
case initial

Sources/CSS/styles/Box.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum Box: String, HTMLParsable {
5+
public enum Box: String, HTMLInitializable {
66
case decorationBreak
77
case reflect
88
case shadow

Sources/CSS/styles/Break.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum Break: String, HTMLParsable {
5+
public enum Break: String, HTMLInitializable {
66
case after
77
case before
88
case inside

Sources/CSS/styles/CaptionSide.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum CaptionSide: String, HTMLParsable {
5+
public enum CaptionSide: String, HTMLInitializable {
66
case bottom
77
case inherit
88
case initial

Sources/CSS/styles/Clear.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import HTMLKitUtilities
33

44
extension CSSStyle {
5-
public enum Clear: String, HTMLParsable {
5+
public enum Clear: String, HTMLInitializable {
66
case both
77
case inherit
88
case initial

Sources/CSS/styles/Color.swift

Lines changed: 2 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import HTMLKitUtilities
33

44
extension CSSStyle {
55
@frozen
6-
public enum Color: HTMLParsable {
6+
public enum Color: HTMLInitializable {
77
case currentColor
88
case hex(String)
99
case hsl(Swift.Float, Swift.Float, Swift.Float, Swift.Float? = nil)
@@ -178,168 +178,4 @@ extension CSSStyle {
178178
}
179179
}
180180
}
181-
}
182-
183-
// MARK: SyntaxSyntax
184-
#if canImport(SwiftSyntax)
185-
extension CSSStyle.Color {
186-
public init?(context: HTMLExpansionContext) {
187-
switch context.key {
188-
case "currentColor": self = .currentColor
189-
case "inherit": self = .inherit
190-
case "initial": self = .initial
191-
case "transparent": self = .transparent
192-
193-
case "aliceBlue": self = .aliceBlue
194-
case "antiqueWhite": self = .antiqueWhite
195-
case "aqua": self = .aqua
196-
case "aquamarine": self = .aquamarine
197-
case "azure": self = .azure
198-
case "beige": self = .beige
199-
case "bisque": self = .bisque
200-
case "black": self = .black
201-
case "blanchedAlmond": self = .blanchedAlmond
202-
case "blue": self = .blue
203-
case "blueViolet": self = .blueViolet
204-
case "brown": self = .brown
205-
case "burlyWood": self = .burlyWood
206-
case "cadetBlue": self = .cadetBlue
207-
case "chartreuse": self = .chartreuse
208-
case "chocolate": self = .chocolate
209-
case "coral": self = .coral
210-
case "cornflowerBlue": self = .cornflowerBlue
211-
case "cornsilk": self = .cornsilk
212-
case "crimson": self = .crimson
213-
case "cyan": self = .cyan
214-
case "darkBlue": self = .darkBlue
215-
case "darkCyan": self = .darkCyan
216-
case "darkGoldenRod": self = .darkGoldenRod
217-
case "darkGray": self = .darkGray
218-
case "darkGrey": self = .darkGrey
219-
case "darkGreen": self = .darkGreen
220-
case "darkKhaki": self = .darkKhaki
221-
case "darkMagenta": self = .darkMagenta
222-
case "darkOliveGreen": self = .darkOliveGreen
223-
case "darkOrange": self = .darkOrange
224-
case "darkOrchid": self = .darkOrchid
225-
case "darkRed": self = .darkRed
226-
case "darkSalmon": self = .darkSalmon
227-
case "darkSeaGreen": self = .darkSeaGreen
228-
case "darkSlateBlue": self = .darkSlateBlue
229-
case "darkSlateGray": self = .darkSlateGray
230-
case "darkSlateGrey": self = .darkSlateGrey
231-
case "darkTurquoise": self = .darkTurquoise
232-
case "darkViolet": self = .darkViolet
233-
case "deepPink": self = .deepPink
234-
case "deepSkyBlue": self = .deepSkyBlue
235-
case "dimGray": self = .dimGray
236-
case "dimGrey": self = .dimGrey
237-
case "dodgerBlue": self = .dodgerBlue
238-
case "fireBrick": self = .fireBrick
239-
case "floralWhite": self = .floralWhite
240-
case "forestGreen": self = .forestGreen
241-
case "fuchsia": self = .fuchsia
242-
case "gainsboro": self = .gainsboro
243-
case "ghostWhite": self = .ghostWhite
244-
case "gold": self = .gold
245-
case "goldenRod": self = .goldenRod
246-
case "gray": self = .gray
247-
case "grey": self = .grey
248-
case "green": self = .green
249-
case "greenYellow": self = .greenYellow
250-
case "honeyDew": self = .honeyDew
251-
case "hotPink": self = .hotPink
252-
case "indianRed": self = .indianRed
253-
case "indigo": self = .indigo
254-
case "ivory": self = .ivory
255-
case "khaki": self = .khaki
256-
case "lavender": self = .lavender
257-
case "lavenderBlush": self = .lavenderBlush
258-
case "lawnGreen": self = .lawnGreen
259-
case "lemonChiffon": self = .lemonChiffon
260-
case "lightBlue": self = .lightBlue
261-
case "lightCoral": self = .lightCoral
262-
case "lightCyan": self = .lightCyan
263-
case "lightGoldenRodYellow": self = .lightGoldenRodYellow
264-
case "lightGray": self = .lightGray
265-
case "lightGrey": self = .lightGrey
266-
case "lightGreen": self = .lightGreen
267-
case "lightPink": self = .lightPink
268-
case "lightSalmon": self = .lightSalmon
269-
case "lightSeaGreen": self = .lightSeaGreen
270-
case "lightSkyBlue": self = .lightSkyBlue
271-
case "lightSlateGray": self = .lightSlateGray
272-
case "lightSlateGrey": self = .lightSlateGrey
273-
case "lightSteelBlue": self = .lightSteelBlue
274-
case "lightYellow": self = .lightYellow
275-
case "lime": self = .lime
276-
case "limeGreen": self = .limeGreen
277-
case "linen": self = .linen
278-
case "magenta": self = .magenta
279-
case "maroon": self = .maroon
280-
case "mediumAquaMarine": self = .mediumAquaMarine
281-
case "mediumBlue": self = .mediumBlue
282-
case "mediumOrchid": self = .mediumOrchid
283-
case "mediumPurple": self = .mediumPurple
284-
case "mediumSeaGreen": self = .mediumSeaGreen
285-
case "mediumSlateBlue": self = .mediumSlateBlue
286-
case "mediumSpringGreen": self = .mediumSpringGreen
287-
case "mediumTurquoise": self = .mediumTurquoise
288-
case "mediumVioletRed": self = .mediumVioletRed
289-
case "midnightBlue": self = .midnightBlue
290-
case "mintCream": self = .mintCream
291-
case "mistyRose": self = .mistyRose
292-
case "moccasin": self = .moccasin
293-
case "navajoWhite": self = .navajoWhite
294-
case "navy": self = .navy
295-
case "oldLace": self = .oldLace
296-
case "olive": self = .olive
297-
case "oliveDrab": self = .oliveDrab
298-
case "orange": self = .orange
299-
case "orangeRed": self = .orangeRed
300-
case "orchid": self = .orchid
301-
case "paleGoldenRod": self = .paleGoldenRod
302-
case "paleGreen": self = .paleGreen
303-
case "paleTurquoise": self = .paleTurquoise
304-
case "paleVioletRed": self = .paleVioletRed
305-
case "papayaWhip": self = .papayaWhip
306-
case "peachPuff": self = .peachPuff
307-
case "peru": self = .peru
308-
case "pink": self = .pink
309-
case "plum": self = .plum
310-
case "powderBlue": self = .powderBlue
311-
case "purple": self = .purple
312-
case "rebeccaPurple": self = .rebeccaPurple
313-
case "red": self = .red
314-
case "rosyBrown": self = .rosyBrown
315-
case "royalBlue": self = .royalBlue
316-
case "saddleBrown": self = .saddleBrown
317-
case "salmon": self = .salmon
318-
case "sandyBrown": self = .sandyBrown
319-
case "seaGreen": self = .seaGreen
320-
case "seaShell": self = .seaShell
321-
case "sienna": self = .sienna
322-
case "silver": self = .silver
323-
case "skyBlue": self = .skyBlue
324-
case "slateBlue": self = .slateBlue
325-
case "slateGray": self = .slateGray
326-
case "slateGrey": self = .slateGrey
327-
case "snow": self = .snow
328-
case "springGreen": self = .springGreen
329-
case "steelBlue": self = .steelBlue
330-
case "tan": self = .tan
331-
case "teal": self = .teal
332-
case "thistle": self = .thistle
333-
case "tomato": self = .tomato
334-
case "turquoise": self = .turquoise
335-
case "violet": self = .violet
336-
case "wheat": self = .wheat
337-
case "white": self = .white
338-
case "whiteSmoke": self = .whiteSmoke
339-
case "yellow": self = .yellow
340-
case "yellowGreen": self = .yellowGreen
341-
default: return nil
342-
}
343-
}
344-
}
345-
#endif
181+
}

0 commit comments

Comments
 (0)