|
| 1 | +# swift-html-standard |
| 2 | + |
| 3 | +[](https://github.com/swift-standards/swift-html-standard/actions/workflows/ci.yml) |
| 4 | + |
| 5 | + |
| 6 | +Compatibility wrapper providing unified access to WHATWG HTML implementation with familiar API structure. |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +swift-html-standard is a lightweight wrapper around [swift-whatwg-html](https://github.com/swift-standards/swift-whatwg-html) that provides a simplified, unified API structure. It offers three main products for different use cases: complete HTML implementation, attributes-only, or elements-only. |
| 11 | + |
| 12 | +This package serves as the recommended entry point for projects migrating from swift-html-types or seeking a simpler import structure than the modular swift-whatwg-html organization. |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- **Zero-cost abstraction**: Direct re-exports with no wrapper types or runtime overhead |
| 17 | +- **Simplified imports**: Three focused products instead of 26 individual modules |
| 18 | +- **Complete WHATWG compliance**: Full backing by swift-whatwg-html implementation |
| 19 | +- **Flexible granularity**: Import everything, just attributes, or just elements |
| 20 | +- **Type aliases**: Convenient `HTMLElement` and `HTMLVoidElement` aliases |
| 21 | +- **Swift 6 concurrency**: Full Sendable conformance with strict concurrency mode |
| 22 | +- **Migration path**: Drop-in replacement for swift-html-types with minimal changes |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +### Swift Package Manager |
| 27 | + |
| 28 | +Add to your `Package.swift`: |
| 29 | + |
| 30 | +```swift |
| 31 | +dependencies: [ |
| 32 | + .package(url: "https://github.com/swift-standards/swift-html-standard", from: "0.1.0") |
| 33 | +] |
| 34 | +``` |
| 35 | + |
| 36 | +## Quick Start |
| 37 | + |
| 38 | +### Complete Implementation |
| 39 | + |
| 40 | +```swift |
| 41 | +import HTML_Standard |
| 42 | + |
| 43 | +// Access all HTML elements and attributes |
| 44 | +let input = Input( |
| 45 | + name: Name("email"), |
| 46 | + disabled: nil, |
| 47 | + form: nil, |
| 48 | + type: .email(Input.Email(value: Value(""))) |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +### Attributes Only |
| 53 | + |
| 54 | +```swift |
| 55 | +import HTML_Standard_Attributes |
| 56 | + |
| 57 | +// Access only HTML attribute types |
| 58 | +let name = Name("username") |
| 59 | +let placeholder = Placeholder("Enter username") |
| 60 | +let required = Required() |
| 61 | +``` |
| 62 | + |
| 63 | +### Elements Only |
| 64 | + |
| 65 | +```swift |
| 66 | +import HTML_Standard_Elements |
| 67 | + |
| 68 | +// Access only HTML element types |
| 69 | +let form = Form( |
| 70 | + action: Action("/submit"), |
| 71 | + method: Method.post, |
| 72 | + enctype: EncType.multipart |
| 73 | +) |
| 74 | +``` |
| 75 | + |
| 76 | +## Usage |
| 77 | + |
| 78 | +### Available Products |
| 79 | + |
| 80 | +#### HTML Standard |
| 81 | +Complete implementation with all elements and attributes: |
| 82 | + |
| 83 | +```swift |
| 84 | +import HTML_Standard |
| 85 | + |
| 86 | +// Everything is available |
| 87 | +let video = Video( |
| 88 | + src: Src("/video.mp4"), |
| 89 | + controls: Controls(), |
| 90 | + preload: Video.Preload.metadata |
| 91 | +) |
| 92 | +``` |
| 93 | + |
| 94 | +#### HTML Standard Attributes |
| 95 | +All attribute modules (GlobalAttributes, FormAttributes, LinkAttributes, MediaAttributes, TableAttributes, ScriptAttributes, Metadata): |
| 96 | + |
| 97 | +```swift |
| 98 | +import HTML_Standard_Attributes |
| 99 | + |
| 100 | +// Attribute types only |
| 101 | +let href = Href("https://example.com") |
| 102 | +let rel = Rel.stylesheet |
| 103 | +let target = Target.blank |
| 104 | +``` |
| 105 | + |
| 106 | +#### HTML Standard Elements |
| 107 | +All element modules organized by WHATWG spec sections: |
| 108 | + |
| 109 | +```swift |
| 110 | +import HTML_Standard_Elements |
| 111 | + |
| 112 | +// Element types with convenient aliases |
| 113 | +typealias Element = HTMLElement // WHATWG_HTML.Element |
| 114 | +typealias VoidElement = HTMLVoidElement // WHATWG_HTML.VoidElement |
| 115 | + |
| 116 | +let section = Section() |
| 117 | +let article = Article() |
| 118 | +``` |
| 119 | + |
| 120 | +### Type Aliases |
| 121 | + |
| 122 | +The Elements product provides convenient aliases: |
| 123 | + |
| 124 | +```swift |
| 125 | +import HTML_Standard_Elements |
| 126 | + |
| 127 | +// These are equivalent: |
| 128 | +let element1: HTMLElement = ... |
| 129 | +let element2: WHATWG_HTML.Element = ... |
| 130 | + |
| 131 | +let void1: HTMLVoidElement = ... |
| 132 | +let void2: WHATWG_HTML.VoidElement = ... |
| 133 | +``` |
| 134 | + |
| 135 | +### Migration from swift-html-types |
| 136 | + |
| 137 | +Replace imports: |
| 138 | + |
| 139 | +```swift |
| 140 | +// Old |
| 141 | +import HTMLTypes |
| 142 | +import HTMLAttributeTypes |
| 143 | +import HTMLElementTypes |
| 144 | + |
| 145 | +// New |
| 146 | +import HTML_Standard |
| 147 | +import HTML_Standard_Attributes |
| 148 | +import HTML_Standard_Elements |
| 149 | +``` |
| 150 | + |
| 151 | +Type names remain the same - only imports change. |
| 152 | + |
| 153 | +## Requirements |
| 154 | + |
| 155 | +- Swift 6.2+ |
| 156 | +- macOS 15.0+ / iOS 18.0+ / tvOS 18.0+ / watchOS 11.0+ |
| 157 | +- Swift 6 language mode with strict concurrency |
| 158 | + |
| 159 | +## Architecture |
| 160 | + |
| 161 | +### Package Structure |
| 162 | + |
| 163 | +``` |
| 164 | +swift-html-standard/ |
| 165 | +├── HTML Standard/ # Complete implementation |
| 166 | +│ └── Re-exports WHATWG HTML |
| 167 | +├── HTML Standard Attributes/ # Attributes only |
| 168 | +│ ├── WHATWG HTML Shared |
| 169 | +│ ├── WHATWG HTML GlobalAttributes |
| 170 | +│ ├── WHATWG HTML FormAttributes |
| 171 | +│ ├── WHATWG HTML LinkAttributes |
| 172 | +│ ├── WHATWG HTML MediaAttributes |
| 173 | +│ ├── WHATWG HTML TableAttributes |
| 174 | +│ ├── WHATWG HTML ScriptAttributes |
| 175 | +│ └── WHATWG HTML Metadata |
| 176 | +└── HTML Standard Elements/ # Elements only |
| 177 | + ├── WHATWG HTML Shared |
| 178 | + └── WHATWG HTML Elements |
| 179 | +``` |
| 180 | + |
| 181 | +### Design Principles |
| 182 | + |
| 183 | +1. **Zero-cost wrapper**: All types are re-exported directly, no intermediate layers |
| 184 | +2. **Simplified organization**: Three products instead of 26 modules |
| 185 | +3. **Familiar structure**: Matches expectations from swift-html-types |
| 186 | +4. **Full compliance**: Backed by complete WHATWG HTML Living Standard implementation |
| 187 | +5. **Flexible imports**: Choose the granularity you need |
| 188 | + |
| 189 | +## Related Packages |
| 190 | + |
| 191 | +### Implementation |
| 192 | +- [swift-whatwg-html](https://github.com/swift-standards/swift-whatwg-html): Complete, modular WHATWG HTML Living Standard implementation |
| 193 | + |
| 194 | +### Used By |
| 195 | +- [swift-html-css-pointfree](https://github.com/coenttb/swift-html-css-pointfree): Integration with pointfree-html for HTML generation |
| 196 | + |
| 197 | +### Dependencies |
| 198 | +- [swift-whatwg-html](https://github.com/swift-standards/swift-whatwg-html): WHATWG HTML implementation |
| 199 | + - [swift-rfc-2045](https://github.com/swift-standards/swift-rfc-2045): RFC 2045 MIME types |
| 200 | + - [swift-iso-8601](https://github.com/swift-standards/swift-iso-8601): ISO 8601 date/time |
| 201 | + - [swift-standards](https://github.com/swift-standards/swift-standards): Shared utilities |
| 202 | + |
| 203 | +## Contributing |
| 204 | + |
| 205 | +Contributions are welcome! This package is a thin wrapper, so most contributions should go to [swift-whatwg-html](https://github.com/swift-standards/swift-whatwg-html). For wrapper-specific issues: |
| 206 | + |
| 207 | +- Ensure changes maintain zero-cost abstraction |
| 208 | +- Tests pass with Swift 6.2 |
| 209 | +- Code follows existing style |
| 210 | + |
| 211 | +## License |
| 212 | + |
| 213 | +This project is licensed under the Apache License 2.0. See [LICENSE.md](LICENSE.md) for details. |
0 commit comments