Skip to content

Commit 37c6fa1

Browse files
authored
Web components (#24)
- component basics - component tests - fix format - fix readme
1 parent 7461530 commit 37c6fa1

45 files changed

Lines changed: 1076 additions & 286 deletions

Some content is hidden

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test:
4242
swift test --parallel
4343

4444
docker-test:
45-
docker build -t tests . -f ./docker/Dockerfile.testing && docker run --rm tests
45+
docker build -t swift-web-standards-tests . -f ./docker/tests/Dockerfile && docker run --rm swift-web-standards-tests
4646

4747

4848

Package.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
import PackageDescription
33

44
// NOTE: https://github.com/swift-server/swift-http-server/blob/main/Package.swift
5-
var defaultSwiftSettings: [SwiftSetting] =
6-
[
5+
var defaultSwiftSettings: [SwiftSetting] = [
76
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0441-formalize-language-mode-terminology.md
87
.swiftLanguageMode(.v6),
98
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
109
.enableUpcomingFeature("MemberImportVisibility"),
1110
// https://forums.swift.org/t/experimental-support-for-lifetime-dependencies-in-swift-6-2-and-beyond/78638
1211
.enableExperimentalFeature("Lifetimes"),
1312
// https://github.com/swiftlang/swift/pull/65218
14-
.enableExperimentalFeature("AvailabilityMacro=swift-web-standards 1.0:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0"),
13+
.enableExperimentalFeature("AvailabilityMacro=swiftWebStandards 1.0:macOS 15.0, iOS 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0"),
1514
]
1615

1716
#if compiler(>=6.2)
@@ -37,7 +36,10 @@ let package = Package(
3736
],
3837
dependencies: [
3938
// [docc-plugin-placeholder]
40-
.package(url: "https://github.com/apple/swift-collections", .upToNextMinor(from: "1.3.0")),
39+
.package(
40+
url: "https://github.com/apple/swift-collections",
41+
from: "1.3.0"
42+
),
4143
],
4244
targets: [
4345
.target(

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
An awesome Swift library that closely follows the [W3C web standards](https://www.w3.org/standards/).
44

5-
[![Release: 1.0.0-beta.2](https://img.shields.io/badge/Release-1.0.0--beta.2-F05138)]( https://github.com/binarybirds/swift-web-standards/releases/tag/1.0.0-beta.2)
5+
[
6+
![Release: 1.0.0-beta.1](https://img.shields.io/badge/Release-1.0.0--beta.1-F05138)
7+
](
8+
https://github.com/binarybirds/swift-web-standards/releases/tag/1.0.0-beta.1
9+
)
610

711
## Features
812

@@ -46,7 +50,7 @@ The Swift Web Standards package is distributed through **Swift Package Manager**
4650
Add this package to your `Package.swift` dependencies:
4751

4852
```swift
49-
.package(url: "https://github.com/binarybirds/swift-web-standards", from: "1.0.0-beta.2"),
53+
.package(url: "https://github.com/binarybirds/swift-web-standards", from: "1.0.0-beta.1"),
5054
```
5155

5256
Then include the required product as a dependency for your target:
@@ -325,7 +329,11 @@ let css = Stylesheet {
325329
print(StylesheetRenderer(minify: false, indent: 4).render(css))
326330
```
327331

328-
[![DocC API documentation](https://img.shields.io/badge/DocC-API_documentation-F05138)](https://binarybirds.github.io/swift-web-standards)
332+
[
333+
![DocC API documentation](https://img.shields.io/badge/DocC-API_documentation-F05138)
334+
](
335+
https://binarybirds.github.io/swift-web-standards
336+
)
329337

330338
API documentation is available at the following link.
331339

Sources/CSS/Properties/BackdropFilter.swift

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,13 @@
77
/// CSS `backdrop-filter` property.
88
/// Provides typed values for this declaration.
99
public struct BackdropFilter: Property {
10-
/// Supported length value for `backdrop-filter: blur(...)`.
11-
public struct BlurLength: UnitRepresentable, Sendable {
12-
public let rawValue: String
13-
14-
/// Creates a blur length from a CSS `Unit`.
15-
/// Returns `nil` for unsupported units (for example `%`).
16-
public init?<T>(
17-
_ unit: Unit<T>
18-
) where T: Numeric & Sendable {
19-
switch unit.type {
20-
case .cm, .mm, .in, .px, .pt, .pc, .em, .ex, .ch, .rem, .vw, .vh,
21-
.vmin, .vmax:
22-
self.rawValue = unit.rawValue
23-
case .percent:
24-
return nil
25-
}
26-
}
27-
}
2810

2911
/// Value options for the `backdrop-filter` property.
3012
public enum Value: Sendable {
3113
/// Default value. Specifies no effects.
3214
case none
3315
/// Applies a blur effect to the backdrop.
34-
case blur(BlurLength)
16+
case blur(UnitRepresentable)
3517
/// Sets this property to its default value.
3618
case initial
3719
/// Inherits this property from its parent element.
@@ -65,17 +47,6 @@ public struct BackdropFilter: Property {
6547
self.isImportant = false
6648
}
6749

68-
/// Convenience initializer for `backdrop-filter: blur(...)` using `Unit`.
69-
/// Returns `nil` when the supplied unit is unsupported by blur().
70-
public init?<T>(
71-
blur unit: Unit<T>
72-
) where T: Numeric & Sendable {
73-
guard let blurLength = BlurLength(unit) else {
74-
return nil
75-
}
76-
self.init(.blur(blurLength))
77-
}
78-
7950
// TODO: add support for the remaining backdrop-filter functions:
8051
// - brightness()
8152
// - contrast()

Sources/CSS/Properties/Border.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
public struct Border: Property {
1212
/// Value options for the `border` property.
1313
public enum Value: Sendable {
14-
case values(BorderWidth.Value, BorderStyle.Value, CSSColor)
14+
15+
case values(BorderWidth.Value, BorderStyle.Value?, CSSColor?)
1516
/// Sets this property to its default value.
1617
case initial
1718
/// Inherits this property from its parent element.
@@ -20,8 +21,9 @@ public struct Border: Property {
2021
var rawValue: String {
2122
switch self {
2223
case .values(let width, let style, let color):
23-
return width.rawValue + " " + style.rawValue + " "
24-
+ color.rawValue
24+
return [width.rawValue, style?.rawValue, color?.rawValue]
25+
.compactMap { $0 }
26+
.joined(separator: " ")
2527
case .initial:
2628
return "initial"
2729
case .inherit:
@@ -43,4 +45,21 @@ public struct Border: Property {
4345
self.value = value.rawValue
4446
self.isImportant = false
4547
}
48+
49+
public init(
50+
_ width: BorderWidth.Value,
51+
_ style: BorderStyle.Value? = nil,
52+
_ color: CSSColor? = nil
53+
) {
54+
self.init(.values(width, style, color))
55+
}
56+
57+
public init(
58+
_ width: UnitRepresentable,
59+
_ style: BorderStyle.Value? = nil,
60+
_ color: CSSColor? = nil
61+
) {
62+
self.init(.length(width), style, color)
63+
}
64+
4665
}

Sources/CSS/Properties/BorderBottom.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ public struct BorderBottom: Property {
1919
self.value = value.rawValue
2020
self.isImportant = false
2121
}
22+
23+
public init(
24+
_ width: BorderWidth.Value,
25+
_ style: BorderStyle.Value? = nil,
26+
_ color: CSSColor? = nil
27+
) {
28+
self.init(.values(width, style, color))
29+
}
30+
31+
public init(
32+
_ width: UnitRepresentable,
33+
_ style: BorderStyle.Value? = nil,
34+
_ color: CSSColor? = nil
35+
) {
36+
self.init(.length(width), style, color)
37+
}
2238
}

Sources/CSS/Properties/BorderLeft.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ public struct BorderLeft: Property {
1919
self.value = value.rawValue
2020
self.isImportant = false
2121
}
22+
23+
public init(
24+
_ width: BorderWidth.Value,
25+
_ style: BorderStyle.Value? = nil,
26+
_ color: CSSColor? = nil
27+
) {
28+
self.init(.values(width, style, color))
29+
}
30+
31+
public init(
32+
_ width: UnitRepresentable,
33+
_ style: BorderStyle.Value? = nil,
34+
_ color: CSSColor? = nil
35+
) {
36+
self.init(.length(width), style, color)
37+
}
2238
}

Sources/CSS/Properties/BorderRadius.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public struct BorderRadius: Property {
5353
self.isImportant = false
5454
}
5555

56+
public init(
57+
_ v1: UnitRepresentable,
58+
_ v2: UnitRepresentable? = nil,
59+
_ v3: UnitRepresentable? = nil,
60+
_ v4: UnitRepresentable? = nil
61+
) {
62+
self.init(.length(v1, v2, v3, v4))
63+
}
64+
5665
// @TODO: better API for all value cases
5766
// https://www.w3schools.com/cssref/css3_pr_border-radius.asp
5867
}

Sources/CSS/Properties/BorderRight.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ public struct BorderRight: Property {
1919
self.value = value.rawValue
2020
self.isImportant = false
2121
}
22+
23+
public init(
24+
_ width: BorderWidth.Value,
25+
_ style: BorderStyle.Value? = nil,
26+
_ color: CSSColor? = nil
27+
) {
28+
self.init(.values(width, style, color))
29+
}
30+
31+
public init(
32+
_ width: UnitRepresentable,
33+
_ style: BorderStyle.Value? = nil,
34+
_ color: CSSColor? = nil
35+
) {
36+
self.init(.length(width), style, color)
37+
}
2238
}

Sources/CSS/Properties/BorderTop.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ public struct BorderTop: Property {
1919
self.value = value.rawValue
2020
self.isImportant = false
2121
}
22+
23+
public init(
24+
_ width: BorderWidth.Value,
25+
_ style: BorderStyle.Value? = nil,
26+
_ color: CSSColor? = nil
27+
) {
28+
self.init(.values(width, style, color))
29+
}
30+
31+
public init(
32+
_ width: UnitRepresentable,
33+
_ style: BorderStyle.Value? = nil,
34+
_ color: CSSColor? = nil
35+
) {
36+
self.init(.length(width), style, color)
37+
}
2238
}

0 commit comments

Comments
 (0)