v0.12.0 - CSS Code Extraction to swift-css
v0.12.0 - CSS Code Extraction to swift-css
This release represents a major architectural change that extracts CSS-related code from swift-html into the dedicated swift-css package. This creates a cleaner separation of concerns and enables CSS functionality to be used independently of HTML.
⚠️ Breaking Changes
Dependency Changes
You now need to add swift-css as a dependency to access CSS functionality:
.package(url: "https://github.com/coenttb/swift-css", from: "0.3.0")Import Changes
// Before (0.11.x)
import HTML
// After (0.12.0)
import HTML
import CSS // For core CSS functionality
import CSS_Theming // For themed colors with dark mode🗑️ Removed from swift-html
The following code has been moved to swift-css:
Color System (6 files)
| File | New Location |
|---|---|
DarkModeColor.swift |
CSS/DarkModeColor/ |
ColorConvertible.swift |
CSS/DarkModeColor/ |
ColorProperty.swift |
CSS/DarkModeColor/ |
Color.WithDarkMode.swift |
Deprecated |
CSS_Standard.Color.swift |
CSS/DarkModeColor/ |
CSS_Standard.Color.Value.swift |
CSS/DarkModeColor/ |
CSS Color Property Extensions (24 files)
All moved to CSS/DarkModeColor/Properties/:
CSS+color.swiftCSS+backgroundColor.swiftCSS+accentColor.swiftCSS+caretColor.swiftCSS+outlineColor.swiftCSS+borderColor.swiftCSS+borderTopColor.swift,CSS+borderBottomColor.swiftCSS+borderLeftColor.swift,CSS+borderRightColor.swiftCSS+borderBlockColor.swift,CSS+borderBlockStartColor.swift,CSS+borderBlockEndColor.swiftCSS+borderInlineColor.swift,CSS+borderInlineStartColor.swift,CSS+borderInlineEndColor.swiftCSS+columnRuleColor.swiftCSS+textDecorationColor.swiftCSS+textEmphasisColor.swiftCSS+fill.swift,CSS+stroke.swiftCSS+floodColor.swift,CSS+stopColor.swift,CSS+lightingColor.swift
Layout Helpers (10 files)
All moved to CSS/Layout/:
Flex.swiftMargin.swiftPadding.swiftPosition.swiftSide.swiftCSS+spacing.swiftCSS+gridItem.swiftCSS+gridContainer.swiftCSS+positioned.swiftCSS+frame.swift
Other Utilities (7 files)
| File | New Location |
|---|---|
AlignItems.swift |
CSS/Alignment/ |
Border.swift |
CSS Theming/ |
CSS+border.swift |
CSS Theming/ |
CSS+text.swift |
CSS/ |
Media.swift |
CSS/ |
ListStyle.swift |
CSS/ |
VerticalAlign.swift |
CSS/ |
Test Files Removed
HTMLTheme Tests/Color Palette Tests.swift→ Now in swift-cssHTMLTheme Tests/Theme Structure Tests.swift→ Now in swift-cssHTMLTheme Tests/Theme Variants Tests.swift→ Now in swift-cssHTMLTheme Tests/Dot Syntax Tests.swift→ Now in swift-cssHTMLTheme Tests/HTMLTheme Tests.swift→ Now in swift-css
🔄 Behavioral Changes
Color Resolution
Color statics (.red, .blue, .green, .gray800, etc.) now resolve to themed DarkModeColor values with automatic dark mode support:
// 0.11.x: .red resolved to CSS named color "red"
div.css.color(.red) // → color: red
// 0.12.0: .red resolves to themed DarkModeColor with dark mode
div.css.color(.red) // → color: #cc3333 + @media (prefers-color-scheme: dark) { color: #ff1a1a }isSingleColor Optimization
When light == dark in a DarkModeColor, no dark mode media query is generated:
// Single color - no dark mode CSS generated
DarkModeColor(light: .red, dark: .red)
// → color: #cc3333
// Different colors - dark mode CSS generated
DarkModeColor(light: .red, dark: .blue)
// → color: #cc3333 + @media (prefers-color-scheme: dark) { color: #3399ff }Using Raw CSS Colors
To use raw CSS colors without dark mode, use explicit types:
// Raw CSS named color (no dark mode)
div.css.color(Color.color(.named(.red))) // → color: red
// Raw hex color (no dark mode)
div.css.color(Color.color(.hex("FF0000"))) // → color: #FF0000📦 Migration Guide
Step 1: Update Package.swift
dependencies: [
.package(url: "https://github.com/coenttb/swift-html", from: "0.12.0"),
.package(url: "https://github.com/coenttb/swift-css", from: "0.3.0"),
]Step 2: Update Imports
import HTML
import CSS
import CSS_Theming // If using themed colorsStep 3: Update Color Usage (if needed)
If you relied on .red producing just color: red:
// Change from:
.css.color(.red)
// To (for raw CSS color):
.css.color(Color.color(.named(.red)))
// Or keep as-is to get themed dark mode supportStep 4: Update Tests
Update snapshot expectations to account for dark mode CSS output from themed colors.
🧪 Test Changes
- All 122 swift-html tests pass
- Test snapshots updated for themed color behavior
- HTMLTheme test suite moved to swift-css (213 tests)
📚 Related Packages
- swift-css v0.3.0 - Contains the extracted CSS code
- swift-css-standard - W3C CSS type definitions