Skip to content

coenttb/swift-html-css-pointfree

Repository files navigation

swift-html-css-pointfree

CI Development Status

Integration layer combining HTML types, CSS types, and PointFree HTML rendering for type-safe web development.

⚠️ This is an integration package. For end-user development, please use coenttb/swift-html instead.

Overview

This package provides the integration layer that bridges:

It serves as the foundational PointFree HTML integration layer for the swift-html package.

Features

  • PointFree HTML extensions for HTML elements (HTMLElements+PointFreeHTML)
  • PointFree HTML extensions for HTML attributes (HTMLAttributes+PointFreeHTML)
  • PointFree HTML extensions for CSS properties (CSS+PointFreeHTML)
  • Combined HTML and CSS functionality (HTML+CSS+PointFreeHTML)
  • Type-safe CSS property application on HTML elements
  • Media query support for responsive design
  • Pseudo-class support for interactive styling

Installation

For End Users

Use coenttb/swift-html instead. The swift-html package provides a complete, developer-friendly API for building type-safe HTML and CSS in Swift.

For Package Developers

If you need to use this integration layer directly:

dependencies: [
    .package(url: "https://github.com/coenttb/swift-html-css-pointfree", from: "0.0.1")
]

Then add the appropriate module to your target dependencies:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "HTMLCSSPointFreeHTML", package: "swift-html-css-pointfree"),
        // Or specific modules:
        // .product(name: "CSSPointFreeHTML", package: "swift-html-css-pointfree"),
        // .product(name: "HTMLElementsPointFreeHTML", package: "swift-html-css-pointfree"),
        // .product(name: "HTMLAttributesPointFreeHTML", package: "swift-html-css-pointfree"),
    ]
)

Quick Start

import HTMLCSSPointFreeHTML
import PointFreeHTML

let document = HTMLDocument {
    ContentDivision {
        "Hello World"
    }
    .color(.red)
    .backgroundColor(.hex("F0F0F0"))
}

let html = String(bytes: document.render(), encoding: .utf8)!

Usage Examples

Applying CSS Properties

import HTMLCSSPointFreeHTML

// Apply color with type safety
let styledDiv = ContentDivision {
    "Styled content"
}
.color(.blue)
.fontSize(.px(16))
.padding(.rem(1))

Media Queries

// Responsive styling
let responsiveDiv = ContentDivision {
    "Responsive content"
}
.padding(.rem(1), media: .mobile)
.padding(.rem(2), media: .tablet)
.padding(.rem(3), media: .desktop)

Pseudo-Classes

// Interactive styling
let interactiveLink = Anchor(href: "/path") {
    "Hover me"
}
.color(.blue)
.color(.red, pseudo: .hover)

Multiple Properties

let complexElement = ContentDivision {
    Paragraph {
        "Complex styling"
    }
    .color(.named(.darkblue))
    .fontSize(.px(18))
}
.backgroundColor(.hex("FFFFFF"))
.padding(.rem(2))
.margin(.px(10))

Package Architecture

Modules

  • CSSPointFreeHTML - CSS property extensions for PointFree HTML elements
  • HTMLElementsPointFreeHTML - HTML element definitions with PointFree HTML support
  • HTMLAttributesPointFreeHTML - HTML attribute extensions for PointFree HTML
  • HTMLCSSPointFreeHTML - Combined HTML+CSS functionality (umbrella module)

Module Dependencies

HTMLCSSPointFreeHTML
├── CSSPointFreeHTML
│   ├── swift-css-types (CSSTypes)
│   └── pointfree-html (PointFreeHTML)
├── HTMLElementsPointFreeHTML
│   ├── swift-html-types (HTMLElementTypes)
│   ├── HTMLAttributesPointFreeHTML
│   └── pointfree-html (PointFreeHTML)
└── HTMLAttributesPointFreeHTML
    ├── swift-html-types (HTMLAttributeTypes)
    └── pointfree-html (PointFreeHTML)

Related Packages

For End Users

  • swift-html - Complete Swift DSL for type-safe HTML and CSS

Foundation Packages

License

This project is licensed under the Apache 2.0 License. See LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Feedback

If you have suggestions or find issues, please open a GitHub issue.

Subscribe to my newsletter

Follow me on X

Connect on LinkedIn

About

A Swift package integrating swift-html-types and swift-css-types with pointfree-html.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages