Skip to content

Commit 795cd5c

Browse files
added some CSS styles; minor fixes
1 parent 76ed3f1 commit 795cd5c

24 files changed

+564
-37
lines changed

Sources/CSS/CSS.swift

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

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

1515
//case accentColor(AccentColor?)
1616
//case align(Align?)
17-
case all
17+
case all(All?)
1818
//case animation(Animation?)
1919
case appearance(Appearance?)
2020
case aspectRatio
@@ -28,7 +28,7 @@ public enum CSSStyle : HTMLParsable {
2828
case box(Box?)
2929
case `break`(Break?)
3030

31-
case captionSide
31+
case captionSide(CaptionSide?)
3232
case caretColor
3333
case clear(Clear?)
3434
case clipPath
@@ -56,7 +56,7 @@ public enum CSSStyle : HTMLParsable {
5656
case grid
5757

5858
case hangingPunctuation
59-
case height(CSSUnit)
59+
case height(CSSUnit?)
6060
case hyphens(Hyphens?)
6161
case hypenateCharacter
6262

@@ -122,23 +122,17 @@ public enum CSSStyle : HTMLParsable {
122122
case userSelect
123123

124124
case verticalAlign
125-
case visibility
125+
case visibility(Visibility?)
126126

127-
case whiteSpace
128-
case windows
129-
case width(CSSUnit)
127+
case whiteSpace(WhiteSpace?)
128+
case whiteSpaceCollapse(WhiteSpaceCollapse?)
129+
case windows(Windows?)
130+
case width(CSSUnit?)
130131
//case word(Word?)
131132
case writingMode(WritingMode?)
132133

133-
//case zIndex(ZIndex?)
134-
case zoom(Zoom)
135-
136-
public init?(context: HTMLExpansionContext) {
137-
return nil
138-
}
139-
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
140-
return nil
141-
}
134+
case zIndex(ZIndex?)
135+
case zoom(Zoom?)
142136

143137
// MARK: Key
144138
@inlinable
@@ -257,17 +251,70 @@ public enum CSSStyle : HTMLParsable {
257251
case .visibility: return "visibility"
258252

259253
case .whiteSpace: return "white-space"
254+
case .whiteSpaceCollapse: return "white-space-collapse"
260255
case .windows: return "windows"
261256
case .width: return "width"
262257
//case .word: return "word"
263258
case .writingMode: return "writing-mode"
264259

265-
//case .zIndex: return "z-index"
260+
case .zIndex: return "z-index"
266261
case .zoom: return "zoom"
267262
}
268263
}
269264

270265
// MARK: HTML value is voidable
271266
@inlinable
272267
public var htmlValueIsVoidable : Bool { false }
268+
}
269+
270+
// MARK: HTML value
271+
extension CSSStyle {
272+
@inlinable
273+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
274+
func get<T : HTMLInitializable>(_ value: T?) -> String? {
275+
guard let v:String = value?.htmlValue(encoding: encoding, forMacro: forMacro) else { return nil }
276+
return key + ":" + v
277+
}
278+
switch self {
279+
case .all(let v): return get(v)
280+
case .appearance(let v): return get(v)
281+
282+
case .backfaceVisibility(let v): return get(v)
283+
case .box(let v): return get(v)
284+
case .break(let v): return get(v)
285+
286+
case .captionSide(let v): return get(v)
287+
case .clear(let v): return get(v)
288+
case .color(let v): return get(v)
289+
case .colorScheme(let v): return get(v)
290+
291+
case .direction(let v): return get(v)
292+
case .display(let v): return get(v)
293+
294+
case .emptyCells(let v): return get(v)
295+
296+
case .float(let v): return get(v)
297+
298+
case .height(let v): return get(v)
299+
case .hyphens(let v): return get(v)
300+
301+
case .imageRendering(let v): return get(v)
302+
case .isolation(let v): return get(v)
303+
304+
case .objectFit(let v): return get(v)
305+
case .opacity(let v): return get(v)
306+
307+
case .visibility(let v): return get(v)
308+
309+
case .whiteSpace(let v): return get(v)
310+
case .whiteSpaceCollapse(let v): return get(v)
311+
case .width(let v): return get(v)
312+
case .windows(let v): return get(v)
313+
case .writingMode(let v): return get(v)
314+
315+
case .zoom(let v): return get(v)
316+
case .zIndex(let v): return get(v)
317+
default: return nil
318+
}
319+
}
273320
}

Sources/CSS/styles/All.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// All.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum All : String, HTMLParsable {
12+
case initial
13+
case inherit
14+
case unset
15+
case revert
16+
case revertLayer
17+
18+
@inlinable
19+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
20+
switch self {
21+
case .revertLayer: return "revert-layer"
22+
default: return rawValue
23+
}
24+
}
25+
}
26+
}

Sources/CSS/styles/CaptionSide.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// CaptionSide.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum CaptionSide : String, HTMLParsable {
12+
case bottom
13+
case inherit
14+
case initial
15+
case revert
16+
case revertLayer
17+
case top
18+
case unset
19+
20+
@inlinable
21+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
22+
switch self {
23+
case .revertLayer: return "revert-layer"
24+
default: return rawValue
25+
}
26+
}
27+
}
28+
}

Sources/CSS/styles/Visibility.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Visibility.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum Visibility : String, HTMLParsable {
12+
case collapse
13+
case hidden
14+
case inherit
15+
case initial
16+
case revert
17+
case revertLayer
18+
case unset
19+
case visible
20+
21+
@inlinable
22+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
23+
switch self {
24+
case .revertLayer: return "revert-layer"
25+
default: return rawValue
26+
}
27+
}
28+
}
29+
}

Sources/CSS/styles/WhiteSpace.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// WhiteSpace.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum WhiteSpace : String, HTMLParsable {
12+
case collapse
13+
case inherit
14+
case initial
15+
case normal
16+
case pre
17+
case preserveNowrap
18+
case preWrap
19+
case preLine
20+
case revert
21+
case revertLayer
22+
case unset
23+
case wrap
24+
25+
@inlinable
26+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
27+
switch self {
28+
case .preWrap: return "pre-wrap"
29+
case .preLine: return "pre-line"
30+
case .preserveNowrap: return "preserve nowrap"
31+
case .revertLayer: return "revert-layer"
32+
default: return rawValue
33+
}
34+
}
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// WhiteSpaceCollapse.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum WhiteSpaceCollapse : String, HTMLParsable {
12+
case breakSpaces
13+
case collapse
14+
case inherit
15+
case initial
16+
case preserve
17+
case preserveBreaks
18+
case preserveSpaces
19+
case revert
20+
case revertLayer
21+
case unset
22+
23+
@inlinable
24+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
25+
switch self {
26+
case .breakSpaces: return "break-spaces"
27+
case .preserveBreaks: return "preserve-breaks"
28+
case .preserveSpaces: return "preserve-spaces"
29+
case .revertLayer: return "revert-layer"
30+
default: return rawValue
31+
}
32+
}
33+
}
34+
}

Sources/CSS/styles/Windows.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Windows.swift
3+
//
4+
//
5+
// Created by Evan Anderson on 2/3/25.
6+
//
7+
8+
import HTMLKitUtilities
9+
10+
extension CSSStyle {
11+
public enum Windows : HTMLInitializable {
12+
case inherit
13+
case initial
14+
case int(Int?)
15+
case revert
16+
case revertLayer
17+
case unset
18+
19+
public var key: String { "" }
20+
21+
@inlinable public var htmlValueIsVoidable : Bool { false }
22+
23+
@inlinable
24+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
25+
switch self {
26+
case .inherit: return "inherit"
27+
case .initial: return "initial"
28+
case .int(let v): guard let v:Int = v else { return nil }; return "\(v)"
29+
case .revert: return "revert"
30+
case .revertLayer: return "revert-layer"
31+
case .unset: return "unset"
32+
}
33+
}
34+
}
35+
}

Sources/CSS/styles/ZIndex.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@
77

88
import HTMLKitUtilities
99

10-
/*
1110
extension CSSStyle {
1211
public enum ZIndex : HTMLInitializable {
1312
case auto
1413
case inherit
1514
case initial
16-
case int(Int)
15+
case int(Int?)
16+
case revert
17+
case revertLayer
18+
case unset
19+
20+
public var key : String { "" }
21+
22+
@inlinable public var htmlValueIsVoidable : Bool { false }
23+
24+
@inlinable
25+
public func htmlValue(encoding: HTMLEncoding, forMacro: Bool) -> String? {
26+
switch self {
27+
case .auto: return "auto"
28+
case .inherit: return "inherit"
29+
case .initial: return "initial"
30+
case .int(let v): guard let v:Int = v else { return nil }; return "\(v)"
31+
case .revert: return "revert"
32+
case .revertLayer: return "revert-layer"
33+
case .unset: return "unset"
34+
}
35+
}
1736
}
18-
}*/
37+
}

Sources/HTMLAttributes/HTMLAttributes.swift renamed to Sources/HTMLAttributes/HTMLAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// HTMLAttributes.swift
2+
// HTMLAttribute.swift
33
//
44
//
55
// Created by Evan Anderson on 11/19/24.

0 commit comments

Comments
 (0)