A Swift DSL for type-safe CSS.
🚧 This package is under active development 🚧
This Swift package is currently in active development and is subject to frequent changes. Features and APIs may change without prior notice until a stable release is available.
swift-css offers a set of Swift types and structures that model various CSS concepts:
- CSS Properties: Type-safe representations of CSS properties like
Color
,Font
,Margin
,Padding
, etc. - CSS Values: Strongly-typed values for CSS properties, including lengths, colors, and keywords.
- Layout Properties: Support for Flexbox and other layout concepts.
- Animations and Transitions: Types for dealing with CSS animations and transitions.
This library allows Swift developers to work with CSS concepts using native Swift syntax and type safety, reducing errors and improving the developer experience when dealing with styles in Swift applications.
- Type-safe CSS properties: Define and manipulate CSS properties using Swift types, eliminating typos and ensuring valid values.
- Comprehensive coverage: Support for a wide range of CSS properties including colors, fonts, layouts, animations, and more.
- Swift-native syntax: Work with CSS concepts using familiar Swift syntax and conventions.
- Extensible: Easy to extend with new CSS properties or custom values.
- Value conversions: Convert between different units and formats where appropriate.
Here's a quick example of how you might use swift-css:
import CSS
let backgroundColor: CSS.Color = .rgba(red: 100, green: 149, blue: 237, alpha: 1) // Outputs: rgb(100, 149, 237)
let fontSize: Length = 24.px // Outputs: 24px
Recommended usage swift-html
swift-css
serves as the foundation for building your own styling functionality. For instance, swift-html leverages swift-css
to safely and effortlessly apply inline styles to HTML elements. Here's an example of swift-html's use of swift-css:
import HTML
let document = HTMLPreview.modern {
h1 { "Type-safe HTML" }
.color(.blue)
.fontSize(24.px)
p { "With type-safe CSS!" }
.margin(top: 10.px, bottom: 10.px)
}
The .color and .fontSize methods leverage the CSS Domain Model to ensure type-safe styling. Working with type-safe CSS makes web development a truly enjoyable experience.
To install the package, add the following line to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/coenttb/swift-css.git", from: "0.1.0")
]
You can then make CSS available to your Package's target by including CSS in your target's dependencies as follows:
targets: [
.target(
name: "TheNameOfYourTarget",
dependencies: [
.product(name: "CSS", package: "swift-css")
]
)
]
- swift-css: A Swift DSL for type-safe CSS.
- swift-html: A Swift DSL for type-safe HTML & CSS, integrating swift-css and pointfree-html.
- swift-web: Foundational tools for web development in Swift.
- coenttb-html: Builds on swift-html, and adds functionality for HTML, Markdown, Email, and printing HTML to PDF.
- coenttb-web: Builds on swift-web, and adds functionality for web development.
- coenttb-server: Build fast, modern, and safe servers that are a joy to write.
coenttb-server
builds on coenttb-web, and adds functionality for server development. - coenttb-vapor:
coenttb-server-vapor
builds on coenttb-server, and adds functionality and integrations with Vapor and Fluent. - coenttb-com-server: The backend server for coenttb.com, written entirely in Swift and powered by coenttb-server-vapor.
- coenttb/pointfree-html: A Swift DSL for type-safe HTML, forked from pointfreeco/swift-html and updated to the version on pointfreeco/pointfreeco.
- coenttb/pointfree-web: Foundational tools for web development in Swift, forked from pointfreeco/swift-web.
- coenttb/pointfree-server: Foundational tools for server development in Swift, forked from pointfreeco/swift-web.
We welcome contributions to swift-css! If you have an idea for a new feature or have found a bug, please open an issue. If you'd like to contribute code, please fork the repository and submit a pull request.
This project is licensed under the Apache 2.0 License. See APACHE 2.0 LICENSE for details.