{"id":51891984,"url":"https://github.com/1amageek/swift-html","last_synced_at":"2026-07-26T05:01:36.992Z","repository":{"id":365179629,"uuid":"1270912249","full_name":"1amageek/swift-html","owner":"1amageek","description":"Framework-neutral declarative HTML engine for Swift applications","archived":false,"fork":false,"pushed_at":"2026-07-03T07:35:05.000Z","size":367,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-07-03T09:19:35.100Z","etag":null,"topics":["css","declarative-ui","html","html-dsl","hydration","server-side-swift","ssr","swift","swift-package","swiftpm","wasm","web-framework"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1amageek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-16T06:52:09.000Z","updated_at":"2026-07-03T07:32:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/1amageek/swift-html","commit_stats":null,"previous_names":["1amageek/swift-html"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/1amageek/swift-html","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1amageek","download_url":"https://codeload.github.com/1amageek/swift-html/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1amageek%2Fswift-html/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35901460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-26T02:00:06.503Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","declarative-ui","html","html-dsl","hydration","server-side-swift","ssr","swift","swift-package","swiftpm","wasm","web-framework"],"created_at":"2026-07-26T05:01:36.852Z","updated_at":"2026-07-26T05:01:36.985Z","avatar_url":"https://github.com/1amageek.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftHTML\n\nSwiftHTML is a low-level declarative HTML engine for Swift applications.\n\nIt provides a typed HTML DSL, component model, renderer, internal graph diffing, typed CSS helpers, hydration metadata, client event bindings, split-loading contracts, and browser-neutral runtime contracts. It is deliberately framework-neutral: it does not depend on Vapor, JavaScriptKit, SwiftWebUI, server routing, or a concrete WebAssembly bootstrap.\n\n```mermaid\nflowchart LR\n  Tree[\"Component tree\"] --\u003e Graph[\"internal HTMLGraph\"]\n  Graph --\u003e Artifact[\"RenderArtifact facade\"]\n  Graph --\u003e Patch[\"HTMLPatch\"]\n  Artifact --\u003e HTML[\"SSR HTML\"]\n  Artifact --\u003e Hydration[\"Hydration manifest\"]\n  Hydration --\u003e Runtime[\"Runtime package\"]\n  Runtime --\u003e Host[\"Browser host\"]\n```\n\n## Status\n\nSwiftHTML is an early pre-`1.0` package extracted from SwiftWeb. The public API is intended to be small and framework-neutral, but runtime and hydration contracts may still evolve before `1.0`.\n\nThis README describes the current `main` branch. Use the README from a matching Git tag when depending on a tagged release.\n\n| Package | Role |\n|---|---|\n| `SwiftHTML` | HTML DSL, rendering, diffing, state, environment, CSS, hydration contracts, browser command contracts, and the `#Preview` macro / `HTMLPreview` Xcode preview surface. |\n| `SwiftHTMLClientRuntime` | Static client HTML tree and DOM host contract that can compile under standard WASM and Embedded Swift compiler profiles. |\n| `SwiftHTMLPreview` | Compatibility re-export of `SwiftHTML` (the preview surface now lives in `SwiftHTML`). |\n| Higher-level server package | HTTP routing, request/response integration, security middleware, server action gateway. |\n| Higher-level UI package | Design-system components, visual defaults, JavaScriptKit adapter, WASM bootstrap. |\n\n## Requirements\n\nSwiftHTML currently requires Swift 6.3 and Apple platform SDKs that provide `Synchronization.Mutex`.\n\n| Platform | Minimum |\n|---|---:|\n| macOS | 15 |\n| iOS | 18 |\n| tvOS | 18 |\n| watchOS | 11 |\n| visionOS | 2 |\n\n## Installation\n\nAdd SwiftHTML to a Swift Package. The examples in this README use the current `main` branch API:\n\n```swift\n// swift-tools-version: 6.3\nimport PackageDescription\n\nlet package = Package(\n    dependencies: [\n        .package(url: \"https://github.com/1amageek/swift-html.git\", branch: \"main\"),\n    ],\n    targets: [\n        .target(\n            name: \"App\",\n            dependencies: [\n                .product(name: \"SwiftHTML\", package: \"swift-html\"),\n            ]\n        ),\n    ]\n)\n```\n\n`#Preview` ships with `SwiftHTML`, so any target that depends on `SwiftHTML`\ncan write previews — no separate preview product is required. `SwiftHTMLPreview`\nremains as a compatibility re-export for existing `import SwiftHTMLPreview` code.\n\n## Quick Start\n\n```swift\nimport SwiftHTML\n\nstruct HomePage: Component {\n    var body: some HTML {\n        document {\n            html {\n                head {\n                    meta(.charset(\"utf-8\"))\n                    title(\"SwiftHTML\")\n                }\n                SwiftHTML.body {\n                    main(.class(\"page\")) {\n                        h1(\"SwiftHTML\")\n                        p(\"Typed HTML rendered from Swift values.\")\n                        a(.href(\"/docs\")) {\n                            \"Read the docs\"\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n\nlet html = HomePage().render()\nprint(html)\n```\n\n## Copyable Snippets\n\nThe snippets below are intentionally complete enough to paste into a Swift file. They include imports, model values, components, and the render or preview entry point. The examples use fenced Markdown code blocks so documentation surfaces can expose their normal copy action.\n\n### Server-Rendered Page\n\n```swift\nimport SwiftHTML\n\nstruct ArticleSummary: Sendable {\n    let id: String\n    let title: String\n    let excerpt: String\n    let href: String\n}\n\nstruct ArticleListPage: Component, Sendable {\n    let articles: [ArticleSummary]\n\n    var body: some HTML {\n        document {\n            html {\n                head {\n                    meta(.charset(\"utf-8\"))\n                    title(\"Latest Articles\")\n                }\n                SwiftHTML.body {\n                    main(.class(\"article-list\")) {\n                        h1(\"Latest Articles\")\n                        p(.class(\"lead\"), text: \"Rendered on the server with typed SwiftHTML components.\")\n\n                        section(.aria(\"label\", \"Articles\")) {\n                            ForEach(articles, id: \\.id) { summary in\n                                articleCard(summary)\n                            }\n                        }\n                    }\n                    .style {\n                        .maxWidth(\"720px\")\n                        .margin(\"0 auto\")\n                        .padding(\"32px\")\n                        .font(\"16px -apple-system, BlinkMacSystemFont, sans-serif\")\n                    }\n                }\n            }\n        }\n    }\n\n    private func articleCard(_ summary: ArticleSummary) -\u003e some HTML {\n        article(.class(\"article-card\")) {\n            h2 {\n                a(.href(summary.href)) {\n                    summary.title\n                }\n            }\n            p(summary.excerpt)\n        }\n        .style {\n            .padding(\"16px 0\")\n            .border(\"0 solid color-mix(in srgb, CanvasText 16%, transparent)\")\n            .custom(\"border-bottom-width\", \"1px\")\n        }\n    }\n}\n\nfunc renderArticleListPage() -\u003e String {\n    ArticleListPage(\n        articles: [\n            ArticleSummary(\n                id: \"swift-html\",\n                title: \"Typed HTML in Swift\",\n                excerpt: \"Use lowercase tags, typed attributes, and components to build HTML documents.\",\n                href: \"/articles/swift-html\"\n            ),\n            ArticleSummary(\n                id: \"hydration\",\n                title: \"Hydration Contracts\",\n                excerpt: \"Render artifacts carry state, event, and browser-neutral runtime metadata.\",\n                href: \"/articles/hydration\"\n            ),\n        ]\n    )\n    .render()\n}\n```\n\n### Xcode Preview\n\n`import SwiftHTML` and mark the HTML you want to inspect with `#Preview`. It renders the content in a `WKWebView` inside Xcode's canvas — a single import, no `#if DEBUG` guard, no SwiftUI, and nothing links into a release or WebAssembly build:\n\n```swift\nimport SwiftHTML\n\n#Preview {\n    main(.class(\"dashboard-shell\")) {\n        header(.class(\"dashboard-header\")) {\n            p(.class(\"eyebrow\"), text: \"SwiftHTML Preview\")\n            h1(\"Release Operations\")\n            p(\"Inspect layout, copy, and CSS directly in Xcode.\")\n        }\n\n        section(.class(\"metric-grid\"), .aria(\"label\", \"Release metrics\")) {\n            article(.class(\"metric-card\")) {\n                p(.class(\"metric-label\"), text: \"Tests\")\n                strong(\"108\")\n                span(.class(\"metric-trend\"), text: \"passing\")\n            }\n\n            article(.class(\"metric-card\")) {\n                p(.class(\"metric-label\"), text: \"Preview\")\n                strong(\"Ready\")\n                span(.class(\"metric-trend\"), text: \"WebKit\")\n            }\n        }\n    }\n}\n```\n\n### Stateful Runtime Check\n\n```swift\nimport SwiftHTML\n\nstruct InlineCounter: ClientComponent, Sendable {\n    @State private var count = 0\n\n    var body: some HTML {\n        button(.type(ButtonType.button), .onClick {\n            count += 1\n        }) {\n            \"Count \\(count)\"\n        }\n    }\n}\n\nfunc renderCounterAfterOneClick() throws -\u003e String {\n    var runtime = try BrowserHydrationRuntime(\n        root: InlineCounter(),\n        host: BrowserDOMCommandBuffer(),\n        stateStore: StateStore()\n    )\n\n    guard let handler = runtime.session.artifact.clientHandlers.handlers.first else {\n        return runtime.session.artifact.html\n    }\n\n    let update = try runtime.invoke(handlerID: handler.id)\n    return update.html\n}\n```\n\n## Xcode Preview\n\n`import SwiftHTML` and use `#Preview` to inspect SwiftHTML directly inside Xcode's canvas. There is no SwiftUI dependency, and the whole surface is self-gated behind `#if DEBUG \u0026\u0026 canImport(WebKit)`, so it never links WebKit or DeveloperToolsSupport into a release server or a WebAssembly build.\n\n| Product | Use |\n|---|---|\n| `SwiftHTML` | HTML DSL, render artifacts, CSS, state, hydration contracts, and the `#Preview` macro. |\n| `SwiftHTMLPreview` | Compatibility re-export of `SwiftHTML`. New code can import `SwiftHTML` directly. |\n\n```mermaid\nflowchart LR\n  Source[\"SwiftHTML content\"] --\u003e Macro[\"#Preview\"]\n  Macro --\u003e Renderer[\"HTMLPreviewRenderer\"]\n  Renderer --\u003e Document[\"Preview HTML document\"]\n  Document --\u003e WebKit[\"WKWebView\"]\n  WebKit --\u003e Canvas[\"Xcode canvas (PreviewRegistry)\"]\n```\n\n### Basic Preview\n\nA single `import SwiftHTML` provides both the content DSL and the `#Preview` macro — Xcode's canvas discovers it by name, exactly like SwiftUI's. No `import DeveloperToolsSupport`, no `#if DEBUG`, and no platform guard is needed:\n\n```swift\nimport SwiftHTML\n\n#Preview {\n    main(.class(\"dashboard-shell\")) {\n        header(.class(\"dashboard-header\")) {\n            p(.class(\"eyebrow\"), text: \"SwiftHTML Preview\")\n            h1(\"Release Operations\")\n            p(\"Inspect layout, copy, and CSS directly in Xcode.\")\n        }\n\n        section(.class(\"metric-grid\"), .aria(\"label\", \"Release metrics\")) {\n            article(.class(\"metric-card\")) {\n                p(.class(\"metric-label\"), text: \"Tests\")\n                strong(\"108\")\n                span(.class(\"metric-trend\"), text: \"passing\")\n            }\n        }\n    }\n}\n```\n\n### Named Previews and Styling\n\nPass a display name as the first argument, exactly like SwiftUI's `#Preview`. The\npreview renders with a default stylesheet; apply your own CSS with SwiftHTML's\nelement-level `.style { ... }`:\n\n```swift\nimport SwiftHTML\n\n#Preview(\"Japanese\") {\n    article {\n        h2(\"SwiftHTML\")\n        p(\"Xcode Preview で HTML を確認できます。\")\n    }\n    .style {\n        .padding(\"32px\")\n        .font(\"16px -apple-system, BlinkMacSystemFont, sans-serif\")\n        .border(\"1px solid color-mix(in srgb, CanvasText 16%, transparent)\")\n    }\n}\n```\n\nFor rendering SwiftHTML to a `WKWebView` outside a preview (custom stylesheet,\nlanguage, base URL, render options), use the `HTMLPreview(...)` function directly.\n\n### Build Behavior\n\n`#Preview` here is SwiftHTML's own macro. Xcode's canvas discovers previews by the\nmacro name `Preview`, so it appears in the canvas exactly like SwiftUI's `#Preview`.\nIt expands to a `DeveloperToolsSupport.PreviewRegistry` conformance — the same type\nApple's `#Preview` generates — but wrapping a `WKWebView` instead of a SwiftUI view.\nThe expansion is self-gated behind `#if DEBUG \u0026\u0026 canImport(WebKit)`, so it is absent\nfrom release and WebAssembly builds without any guard in your own code, and the\nmacro plugin is a host-only build tool not linked on non-Apple platforms.\n\n### Known limitation: the canvas blanks after a few seconds\n\nXcode's canvas hosts the preview off the normal on-screen window, so WebKit treats\nthe `WKWebView` as non-visible and purges its rendered content after a few seconds —\nthe preview renders, then goes blank (the WebContent process stays alive, so this is\nnot a crash). This affects any WebKit- or MapKit-backed preview, including Apple's\nown `#Preview { WKWebView() }` and `#Preview { MKMapView() }`; it is not specific to\nSwiftHTML, and there is no public API to prevent WebKit's non-visible purge. Use the\npreview for a quick look at layout and CSS; for sustained or interactive viewing,\nrun on a device or Simulator, or serve the HTML in a browser.\n\nSwiftHTML escapes text and attribute values by default:\n\n```swift\nlet rendered = div(.id(\"root\")) {\n    \"5 \u003e 3 \u0026 2 \u003c 4\"\n}\n.render()\n```\n\n## Core Concepts\n\n| Concept | API | Notes |\n|---|---|---|\n| HTML primitive | `div`, `span`, `input`, `text`, `rawHTML`, `Element` | Lowercase types map to DOM tags. |\n| Component | `Component` | A value that returns `body`. |\n| Server-owned component | `ServerComponent` | SSR/default ownership boundary. |\n| Client-owned component | `ClientComponent` | Owns `@State`, event closures, and hydration metadata. |\n| Render result | `RenderArtifact` | Public facade for HTML, diagnostics, manifests, handlers, and snapshots. |\n| Runtime state | `StateStore` | Component-scoped state slots used during render and hydration. |\n| Runtime state snapshot | `StateStoreSnapshot` | Codable state payload guarded by a state schema hash for HMR and WASM runtime swaps. |\n| Runtime schema | `StateSchema` | Stable hash derived from state slots, value types, and source locations. |\n\nSwiftHTML keeps the raw render graph internal. Public code should use `RenderArtifact`, `HTMLDOMSnapshot`, hydration indexes, diagnostics, and patch/runtime records instead of constructing graph nodes.\n\n## HTML DSL\n\nHTML tags are lowercase Swift types. Text can be written directly inside builders, or through text initializer shortcuts:\n\n```swift\nsection(.id(\"intro\")) {\n    h2(\"Client Counter\")\n    p(.class(\"lead\"), text: \"State can belong to a ClientComponent.\")\n    input(\n        .type(InputType.email),\n        .name(\"email\"),\n        .placeholder(\"hello@example.com\"),\n        .required\n    )\n}\n```\n\nAttributes are typed where it matters and still allow escape hatches:\n\n```swift\na(\n    .href(\"/account\"),\n    .data(\"tracking-id\", \"account-link\"),\n    .aria(\"label\", \"Open account\")\n) {\n    \"Account\"\n}\n\nElement(\"custom-element\", attributes: [\n    .attribute(\"part\", \"label\")\n]) {\n    \"Custom element content\"\n}\n```\n\nBuilder control flow works with `if`, `switch`, `for`, and `ForEach`:\n\n```swift\nstruct Menu: Component {\n    let items: [String]\n    let isSignedIn: Bool\n\n    var body: some HTML {\n        nav {\n            ul {\n                ForEach(items, id: \\.self) { item in\n                    li {\n                        a(.href(\"/\\(item)\")) {\n                            item\n                        }\n                    }\n                }\n            }\n\n            if isSignedIn {\n                button(.type(ButtonType.button)) {\n                    \"Sign out\"\n                }\n            }\n        }\n    }\n}\n```\n\n## Rendering\n\nUse `render()` when only the HTML string is needed:\n\n```swift\nlet html = HomePage().render()\n```\n\nUse `renderArtifact()` when a server or runtime needs diagnostics, hydration metadata, event handlers, or a DOM snapshot:\n\n```swift\nlet artifact = HomePage().renderArtifact()\n\nprint(artifact.html)\nprint(artifact.diagnostics)\nprint(artifact.hydration.components)\nprint(artifact.browserHydrationIndex())\n```\n\n`HTMLRenderOptions` controls diagnostic capture, handler closure capture, browser hydration markers, and component environment overrides.\n\n## CSS\n\nInline styles use `Style` and `@StyleBuilder`:\n\n```swift\ndiv {\n    \"Panel\"\n}\n.style {\n    .display(\"grid\")\n    .gridTemplateColumns(\"1fr auto\")\n    .gap(\"12px\")\n    .whiteSpace(\"nowrap\")\n    .custom(\"--panel-tone\", \"muted\")\n}\n```\n\nStylesheets use `Stylesheet`, `CSSRule`, and `@StylesheetBuilder`:\n\n```swift\nlet stylesheet = Stylesheet {\n    rule(\".panel\") {\n        .minHeight(\"36px\")\n        .background(\"var(--panel-background)\")\n        .borderRadius(\"8px\")\n    }\n\n    rule(\".panel[data-active=\\\"true\\\"]\") {\n        .outline(\"2px solid var(--accent)\")\n    }\n}\n\nprint(stylesheet.cssText)\n```\n\nThe generated CSS property surface is based on `@mdn/browser-compat-data`. Standard-track, non-deprecated, non-vendor properties are exposed as `Style` helpers so editors can autocomplete the CSS property surface.\n\n`Style.custom(_:_:)`, dynamic CSS members, `CSSSelector`, `CSSRule`, and raw `style` attributes serialize values as authored. Do not pass untrusted external input directly into those APIs.\n\n## State And Hydration\n\n`ClientComponent` can own `@State` and event closures:\n\n```swift\nstruct Counter: ClientComponent, Sendable {\n    @State private var count = 0\n\n    var body: some HTML {\n        button(.type(ButtonType.button), .onClick {\n            count += 1\n        }) {\n            \"Count \\(count)\"\n        }\n    }\n}\n```\n\nRendering records state slots and event bindings in the artifact:\n\n```swift\nlet store = StateStore()\nlet artifact = Counter().renderArtifact(stateStore: store)\n\nlet component = artifact.hydration.components.first\nlet handler = artifact.clientHandlers.handlers.first\n```\n\nState snapshots are explicit runtime data. A host can preserve client state during HMR or a component WASM swap only when the rendered state schema matches:\n\n```swift\nlet schemaHash = artifact.hydration.stateSchemaHash\nlet snapshot = try store.snapshot(schemaHash: schemaHash)\n\nlet nextStore = StateStore()\nnextStore.restore(snapshot)\n```\n\nOnly values that can be encoded by the runtime are included in the snapshot. Non-encodable state falls back to the component initializer on restore.\n\nThe in-package hydration runtime can be used by tests or host adapters:\n\n```swift\nlet host = BrowserDOMCommandBuffer()\nvar runtime = try BrowserHydrationRuntime(\n    root: Counter(),\n    host: host,\n    stateStore: StateStore()\n)\n\nlet handlerID = runtime.session.artifact.clientHandlers.handlers[0].id\nlet update = try runtime.invoke(handlerID: handlerID)\n\nprint(update.commands)\n```\n\n`HydrationRuntimeSession.flush()` tracks dirty components, then currently performs a whole-root re-render and graph diff. Scoped subtree diffing is a runtime optimization boundary, not part of the current correctness contract.\n\n## Environment\n\nEnvironment values can be defined with `EnvironmentKey`:\n\n```swift\nstruct LocaleKey: EnvironmentKey {\n    static let defaultValue = \"en\"\n}\n\nextension EnvironmentValues {\n    var locale: String {\n        get { self[LocaleKey.self] }\n        set { self[LocaleKey.self] = newValue }\n    }\n}\n\nstruct LocaleLabel: Component {\n    @Environment(\\.locale) private var locale\n\n    var body: some HTML {\n        span {\n            locale\n        }\n    }\n}\n```\n\nType-based environment reads are optional:\n\n```swift\nstruct LibraryReader: Component {\n    @Environment(Library.self) private var library: Library?\n\n    var body: some HTML {\n        if let library {\n            span {\n                library.title\n            }\n        } else {\n            span {\n                \"Library unavailable\"\n            }\n        }\n    }\n}\n```\n\n## Actions\n\nSwiftHTML defines transport-neutral action contracts. It can render an action target and hidden fields, but it does not dispatch HTTP requests or invoke server actors.\n\n```swift\nstruct SaveAction: ActionRepresentable {\n    let path = \"/actions/save\"\n    let method = FormMethod.post\n    let fields = [\n        ActionField(\"scope\", \"profile\")\n    ]\n}\n```\n\nHigher-level packages can map `ActionRepresentable` to forms, buttons, fetch requests, server action gateways, or actor invocation.\n\n## Client Runtime Compiler Profiles\n\n`SwiftHTMLClientRuntime` is the production client runtime surface. It is named by\nresponsibility, not by compiler profile: the same source must compile under the\nstandard WASM SDK and the Embedded Swift WASM SDK. It intentionally does not\ninclude the full `SwiftHTML` renderer, graph, Codable manifests,\nreflection-based component identity, or task-local render context.\n\n```mermaid\nflowchart LR\n  A[\"SwiftHTMLClientRuntime static tree\"] --\u003e B[\"ClientDOMHost\"]\n  B --\u003e C[\"Runtime adapter\"]\n  C --\u003e D[\"Browser DOM\"]\n```\n\nThe package includes `Examples/EmbeddedWasm`, which verifies the compiler\nprofile boundary by connecting `SwiftHTMLClientRuntime` to JavaScriptKit in an\nexample package. JavaScriptKit remains outside the core SwiftHTML target.\n\nMeasured with Swift 6.3.1 and no `wasm-opt`:\n\n| Encoding | Standard WASM | Embedded WASM | Reduction |\n|---|---:|---:|---:|\n| raw | 9,027,908 bytes | 859,116 bytes | 90.5% |\n| gzip -9 | 2,423,702 bytes | 283,656 bytes | 88.3% |\n| brotli -q 11 | 1,741,470 bytes | 230,400 bytes | 86.8% |\n\nRun the measurement locally:\n\n```bash\ncd Examples/EmbeddedWasm\nexport SWIFT_BIN=\"/Users/1amageek/Library/Developer/Toolchains/swift-6.3.1-RELEASE.xctoolchain/usr/bin/swift\"\n./measure-size.sh\nnpm install\nnpm run test:browser\n```\n\n## What SwiftHTML Does Not Own\n\n| Concern | Expected owner |\n|---|---|\n| HTTP routing | Server framework package |\n| Request and response objects | Server framework package |\n| CSRF, CORS, Origin, Redirect policy | Server framework package |\n| Server action dispatch | Server framework package |\n| Distributed actor registry | Server framework package |\n| Design-system components | UI package |\n| JavaScriptKit DOM adapter | Runtime package |\n| WASM bootstrap script | Runtime package |\n\n## Safety Notes\n\n| Surface | Behavior |\n|---|---|\n| Text nodes | Escaped by default. |\n| Attribute values | Escaped and validated by attribute kind. |\n| URL attributes | Reject unsafe JavaScript URLs in typed URL attributes. |\n| `rawHTML` | Emits authored HTML; use only with trusted content. |\n| CSS selectors and values | Serialized as authored; validate untrusted input before passing it to CSS APIs. |\n| Event closures | Captured only in render artifacts for client-owned components and runtime adapters. |\n\n## Development\n\n```bash\nswift build\nxcodebuild test -scheme swift-html-Package -destination 'platform=macOS' -only-testing:SwiftHTMLTests\nnode scripts/generate-swift-html-css-properties.mjs --check\n```\n\nRefresh generated CSS helpers:\n\n```bash\nnode scripts/generate-swift-html-css-properties.mjs\n```\n\n## Documentation\n\nThe DocC catalog lives in [Sources/SwiftHTML/SwiftHTML.docc](Sources/SwiftHTML/SwiftHTML.docc). Build it with:\n\n```bash\nxcodebuild docbuild -scheme swift-html-Package -destination 'generic/platform=macOS'\n```\n\nThe longer design notes live in [docs/SwiftHTML.md](docs/SwiftHTML.md).\n\n## License\n\nSwiftHTML is available under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1amageek%2Fswift-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1amageek%2Fswift-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1amageek%2Fswift-html/lists"}