├── .github ├── FUNDING.yml └── workflows │ ├── api-breakage.yml │ ├── ci-examples.yaml │ └── ci.yaml ├── .gitignore ├── .spi.yml ├── .swiftformat ├── Examples ├── HummingbirdDemo │ ├── .gitignore │ ├── Package.swift │ ├── README.md │ ├── Sources │ │ └── App │ │ │ ├── App.swift │ │ │ ├── BrowserSync.swift │ │ │ ├── Database.swift │ │ │ ├── Public │ │ │ ├── htmx.min.js │ │ │ ├── htmxsse.min.js │ │ │ ├── htmxws.min.js │ │ │ └── pico.min.css │ │ │ ├── Routes.swift │ │ │ └── Views.swift │ └── swift-dev └── VaporDemo │ ├── .gitignore │ ├── Package.swift │ ├── README.md │ ├── Sources │ └── App │ │ ├── App.swift │ │ ├── BonusFacts.swift │ │ ├── BrowserSync.swift │ │ ├── Public │ │ ├── htmx.min.js │ │ ├── htmxsse.min.js │ │ └── htmxws.min.js │ │ ├── Routes.swift │ │ └── Views.swift │ └── swift-dev ├── LICENSE ├── Package.swift ├── README.md ├── Sources ├── ElementaryHTMX │ ├── HTMLAttribute+HTMX.swift │ └── HTMLAttributeValue+HTMX.swift ├── ElementaryHTMXSSE │ ├── HTMLAttribute+HTMXSSE.swift │ └── HTMLAttributeValue+HTMXSSE.swift ├── ElementaryHTMXWS │ ├── HTMLAttribute+HTMX.swift │ └── HTMLAttributeValue+HTMX.swift └── ElementaryHyperscript │ └── HTMLAttribute+Hyperscript.swift └── Tests ├── ElementaryHTMXSSETest └── ElementaryHTMXSSETest.swift ├── ElementaryHTMXTest └── ElementaryHTMXTest.swift ├── ElementaryHTMXWSTest └── ElemntaryHTMXWSTest.swift ├── ElementaryHyperscriptTest └── ElementaryHyperscriptTest.swift └── TestUtilities └── Utilities.swift /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [sliemeobn] 2 | -------------------------------------------------------------------------------- /.github/workflows/api-breakage.yml: -------------------------------------------------------------------------------- 1 | name: API breaking changes 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | linux: 8 | runs-on: ubuntu-latest 9 | timeout-minutes: 15 10 | container: 11 | image: swift:6.0 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | with: 16 | fetch-depth: 0 17 | # https://github.com/actions/checkout/issues/766 18 | - name: Mark the workspace as safe 19 | run: git config --global --add safe.directory ${GITHUB_WORKSPACE} 20 | - name: API breaking changes 21 | run: | 22 | swift package diagnose-api-breaking-changes origin/${GITHUB_BASE_REF} 23 | -------------------------------------------------------------------------------- /.github/workflows/ci-examples.yaml: -------------------------------------------------------------------------------- 1 | name: Build Examples 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | hummingbird: 12 | name: Build Hummingbird Example 13 | runs-on: ubuntu-latest 14 | defaults: 15 | run: 16 | working-directory: ./Examples/HummingbirdDemo 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - uses: actions/cache@v4 21 | with: 22 | path: .build 23 | key: ${{ runner.os }}-spm-hummingbird-${{ hashFiles('**/Package.resolved') }} 24 | restore-keys: | 25 | ${{ runner.os }}-spm-hummingbird 26 | 27 | - name: Build 28 | run: swift build 29 | 30 | vapor: 31 | name: Build Vapor Example 32 | runs-on: ubuntu-latest 33 | defaults: 34 | run: 35 | working-directory: ./Examples/VaporDemo 36 | steps: 37 | - uses: actions/checkout@v4 38 | 39 | - uses: actions/cache@v4 40 | with: 41 | path: .build 42 | key: ${{ runner.os }}-spm-vapor-${{ hashFiles('**/Package.resolved') }} 43 | restore-keys: | 44 | ${{ runner.os }}-spm-vapor 45 | 46 | - name: Build 47 | run: swift build 48 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | ci: 12 | name: Build & Test 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Build 18 | run: swift build --build-tests 19 | 20 | - name: Run Tests 21 | run: swift test 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .netrc 9 | Package.resolved 10 | /.vscode 11 | /.devcontainer -------------------------------------------------------------------------------- /.spi.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | builder: 3 | configs: 4 | - documentation_targets: [ElementaryHTMX] 5 | -------------------------------------------------------------------------------- /.swiftformat: -------------------------------------------------------------------------------- 1 | --stripunusedargs unnamed-only -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/.gitignore: -------------------------------------------------------------------------------- 1 | /.build 2 | xcuserdata/ 3 | DerivedData/ 4 | .vscode 5 | Package.resolved -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "HummingbirdDemo", 6 | platforms: [ 7 | .macOS(.v14), 8 | ], 9 | products: [ 10 | .executable(name: "App", targets: ["App"]), 11 | ], 12 | dependencies: [ 13 | .package(path: "../../"), 14 | .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"), 15 | .package(url: "https://github.com/hummingbird-project/hummingbird-websocket.git", from: "2.0.0"), 16 | .package(url: "https://github.com/hummingbird-community/hummingbird-elementary.git", from: "0.4.0"), 17 | .package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"), 18 | .package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"), 19 | ], 20 | targets: [ 21 | .executableTarget( 22 | name: "App", 23 | dependencies: [ 24 | .product(name: "Hummingbird", package: "hummingbird"), 25 | .product(name: "HummingbirdWebSocket", package: "hummingbird-websocket"), 26 | .product(name: "HummingbirdWSCompression", package: "hummingbird-websocket"), 27 | .product(name: "HummingbirdElementary", package: "hummingbird-elementary"), 28 | .product(name: "ElementaryHTMX", package: "elementary-htmx"), 29 | .product(name: "ElementaryHTMXSSE", package: "elementary-htmx"), 30 | .product(name: "ElementaryHTMXWS", package: "elementary-htmx"), 31 | .product(name: "AsyncAlgorithms", package: "swift-async-algorithms"), 32 | .product(name: "ServiceLifecycle", package: "swift-service-lifecycle"), 33 | ], 34 | resources: [ 35 | .copy("Public"), 36 | ], 37 | swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")] 38 | ), 39 | ] 40 | ) 41 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/README.md: -------------------------------------------------------------------------------- 1 | # ElementaryHTMX + Hummingbird Demo 2 | 3 | ## Running the example 4 | 5 | Run the app and open http://localhost:8080 in the browser 6 | 7 | ```sh 8 | swift run App 9 | ``` 10 | 11 | ## Dev mode with auto-reload on save 12 | 13 | The `swift-dev` script auto-reloads open browser tabs on source file changes. 14 | 15 | It is using [watchexec](https://github.com/watchexec/watchexec) and [browsersync](https://browsersync.io/). 16 | 17 | ### Install required tools 18 | 19 | Use homebrew and npm to install the following (tested on macOS): 20 | 21 | ```sh 22 | npm install -g browser-sync 23 | brew install watchexec 24 | ``` 25 | 26 | ### Run app in watch-mode 27 | 28 | This will watch all swift files in the demo package, build on-demand, and re-sync the browser page 29 | 30 | ```sh 31 | ./swift-dev 32 | ``` 33 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/App.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Hummingbird 3 | import HummingbirdWebSocket 4 | import HummingbirdWSCompression 5 | 6 | @main 7 | struct App { 8 | static func main() async throws { 9 | let router = Router(context: URLEncodedRequestContext.self) 10 | 11 | let assetsURL = Bundle.module.resourcePath!.appending("/Public") 12 | router.middlewares.add(FileMiddleware(assetsURL, searchForIndexHtml: false)) 13 | 14 | addRoutes(to: router) 15 | 16 | let wsRouter = Router(context: BasicWebSocketRequestContext.self) 17 | addWSRoutes(to: wsRouter) 18 | 19 | let app = Application( 20 | router: router, 21 | server: .http1WebSocketUpgrade(webSocketRouter: wsRouter, configuration: .init(extensions: [.perMessageDeflate()])), 22 | onServerRunning: { _ in 23 | print("Server running on http://localhost:8080/") 24 | #if DEBUG 25 | browserSyncReload() 26 | #endif 27 | } 28 | ) 29 | try await app.runService() 30 | } 31 | } 32 | 33 | struct URLEncodedRequestContext: RequestContext { 34 | var coreContext: CoreRequestContextStorage 35 | 36 | init(source: ApplicationRequestContextSource) { 37 | coreContext = .init(source: source) 38 | } 39 | 40 | var requestDecoder: URLEncodedFormDecoder { .init() } 41 | } 42 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/BrowserSync.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | #if DEBUG 4 | func browserSyncReload() { 5 | let p = Process() 6 | p.executableURL = URL(string: "file:///bin/sh") 7 | p.arguments = ["-c", "browser-sync reload"] 8 | do { 9 | try p.run() 10 | } catch { 11 | print("Could not auto-reload: \(error)") 12 | } 13 | } 14 | #endif 15 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Database.swift: -------------------------------------------------------------------------------- 1 | actor Database { 2 | var model = Model() 3 | static let shared = Database() 4 | 5 | func addItem(_ item: String) { 6 | model.items.append(item) 7 | } 8 | 9 | func removeItem(at index: Int) -> Bool { 10 | if model.items.indices.contains(index) == false { 11 | return false 12 | } 13 | 14 | model.items.remove(at: index) 15 | return true 16 | } 17 | } 18 | 19 | struct Model { 20 | var items: [String] = [] 21 | } 22 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Public/htmxsse.min.js: -------------------------------------------------------------------------------- 1 | !(function () { 2 | var e; 3 | function t(e) { 4 | return new EventSource(e, { withCredentials: !0 }); 5 | } 6 | function n(t) { 7 | if (!e.bodyContains(t)) { 8 | var n = e.getInternalData(t).sseEventSource; 9 | if (null != n) return n.close(), !0; 10 | } 11 | return !1; 12 | } 13 | function r(t, n) { 14 | var r = []; 15 | return ( 16 | e.hasAttribute(t, n) && r.push(t), 17 | t.querySelectorAll('[' + n + '], [data-' + n + ']').forEach(function (e) { 18 | r.push(e); 19 | }), 20 | r 21 | ); 22 | } 23 | function s(t, n) { 24 | e.withExtensions(t, function (e) { 25 | n = e.transformResponse(n, null, t); 26 | }); 27 | var r = e.getSwapSpecification(t), 28 | s = e.getTarget(t); 29 | e.swap(s, n, r); 30 | } 31 | function a(t) { 32 | return null != e.getInternalData(t).sseEventSource; 33 | } 34 | htmx.defineExtension('sse', { 35 | init: function (n) { 36 | (e = n), null == htmx.createEventSource && (htmx.createEventSource = t); 37 | }, 38 | onEvent: function (t, o) { 39 | var i = o.target || o.detail.elt; 40 | switch (t) { 41 | case 'htmx:beforeCleanupElement': 42 | var u = e.getInternalData(i); 43 | return void (u.sseEventSource && u.sseEventSource.close()); 44 | case 'htmx:afterProcessNode': 45 | !(function t(o, i) { 46 | var u; 47 | if (null == o) return null; 48 | r(o, 'sse-connect').forEach(function (r) { 49 | var s, 50 | a, 51 | o, 52 | u, 53 | c = e.getAttributeValue(r, 'sse-connect'); 54 | null != c && 55 | ((s = r), 56 | (a = c), 57 | (o = i), 58 | ((u = htmx.createEventSource(a)).onerror = function (r) { 59 | if ( 60 | (e.triggerErrorEvent(s, 'htmx:sseError', { 61 | error: r, 62 | source: u, 63 | }), 64 | !n(s) && u.readyState === EventSource.CLOSED) 65 | ) { 66 | var a = Math.random() * (2 ^ (o = o || 0)) * 500; 67 | window.setTimeout(function () { 68 | t(s, Math.min(7, o + 1)); 69 | }, a); 70 | } 71 | }), 72 | (u.onopen = function (t) { 73 | e.triggerEvent(s, 'htmx:sseOpen', { source: u }); 74 | }), 75 | (e.getInternalData(s).sseEventSource = u)); 76 | }), 77 | r((u = o), 'sse-swap').forEach(function (t) { 78 | var r = e.getClosestMatch(t, a); 79 | if (null == r) return null; 80 | for ( 81 | var o = e.getInternalData(r).sseEventSource, 82 | i = e.getAttributeValue(t, 'sse-swap').split(','), 83 | c = 0; 84 | c < i.length; 85 | c++ 86 | ) { 87 | var l = i[c].trim(), 88 | v = function (a) { 89 | if (!n(r)) { 90 | if (!e.bodyContains(t)) 91 | return void o.removeEventListener(l, v); 92 | e.triggerEvent(u, 'htmx:sseBeforeMessage', a) && 93 | (s(t, a.data), 94 | e.triggerEvent(u, 'htmx:sseMessage', a)); 95 | } 96 | }; 97 | (e.getInternalData(t).sseEventListener = v), 98 | o.addEventListener(l, v); 99 | } 100 | }), 101 | r(u, 'hx-trigger').forEach(function (t) { 102 | var r = e.getClosestMatch(t, a); 103 | if (null == r) return null; 104 | var s = e.getInternalData(r).sseEventSource, 105 | o = e.getAttributeValue(t, 'hx-trigger'); 106 | if (null != o && 'sse:' == o.slice(0, 4)) { 107 | var i = function (a) { 108 | !n(r) && 109 | (e.bodyContains(t) || s.removeEventListener(o, i), 110 | htmx.trigger(t, o, a), 111 | htmx.trigger(t, 'htmx:sseMessage', a)); 112 | }; 113 | (e.getInternalData(u).sseEventListener = i), 114 | s.addEventListener(o.slice(4), i); 115 | } 116 | }); 117 | })(i); 118 | } 119 | }, 120 | }); 121 | })(); 122 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Public/htmxws.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | WebSockets Extension 3 | ============================ 4 | This extension adds support for WebSockets to htmx. See /www/extensions/ws.md for usage instructions. 5 | */ 6 | 7 | (function() { 8 | /** @type {import("../htmx").HtmxInternalApi} */ 9 | var api 10 | 11 | htmx.defineExtension('ws', { 12 | 13 | /** 14 | * init is called once, when this extension is first registered. 15 | * @param {import("../htmx").HtmxInternalApi} apiRef 16 | */ 17 | init: function(apiRef) { 18 | // Store reference to internal API 19 | api = apiRef 20 | 21 | // Default function for creating new EventSource objects 22 | if (!htmx.createWebSocket) { 23 | htmx.createWebSocket = createWebSocket 24 | } 25 | 26 | // Default setting for reconnect delay 27 | if (!htmx.config.wsReconnectDelay) { 28 | htmx.config.wsReconnectDelay = 'full-jitter' 29 | } 30 | }, 31 | 32 | /** 33 | * onEvent handles all events passed to this extension. 34 | * 35 | * @param {string} name 36 | * @param {Event} evt 37 | */ 38 | onEvent: function(name, evt) { 39 | var parent = evt.target || evt.detail.elt 40 | switch (name) { 41 | // Try to close the socket when elements are removed 42 | case 'htmx:beforeCleanupElement': 43 | 44 | var internalData = api.getInternalData(parent) 45 | 46 | if (internalData.webSocket) { 47 | internalData.webSocket.close() 48 | } 49 | return 50 | 51 | // Try to create websockets when elements are processed 52 | case 'htmx:beforeProcessNode': 53 | 54 | forEach(queryAttributeOnThisOrChildren(parent, 'ws-connect'), function(child) { 55 | ensureWebSocket(child) 56 | }) 57 | forEach(queryAttributeOnThisOrChildren(parent, 'ws-send'), function(child) { 58 | ensureWebSocketSend(child) 59 | }) 60 | } 61 | } 62 | }) 63 | 64 | function splitOnWhitespace(trigger) { 65 | return trigger.trim().split(/\s+/) 66 | } 67 | 68 | function getLegacyWebsocketURL(elt) { 69 | var legacySSEValue = api.getAttributeValue(elt, 'hx-ws') 70 | if (legacySSEValue) { 71 | var values = splitOnWhitespace(legacySSEValue) 72 | for (var i = 0; i < values.length; i++) { 73 | var value = values[i].split(/:(.+)/) 74 | if (value[0] === 'connect') { 75 | return value[1] 76 | } 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * ensureWebSocket creates a new WebSocket on the designated element, using 83 | * the element's "ws-connect" attribute. 84 | * @param {HTMLElement} socketElt 85 | * @returns 86 | */ 87 | function ensureWebSocket(socketElt) { 88 | // If the element containing the WebSocket connection no longer exists, then 89 | // do not connect/reconnect the WebSocket. 90 | if (!api.bodyContains(socketElt)) { 91 | return 92 | } 93 | 94 | // Get the source straight from the element's value 95 | var wssSource = api.getAttributeValue(socketElt, 'ws-connect') 96 | 97 | if (wssSource == null || wssSource === '') { 98 | var legacySource = getLegacyWebsocketURL(socketElt) 99 | if (legacySource == null) { 100 | return 101 | } else { 102 | wssSource = legacySource 103 | } 104 | } 105 | 106 | // Guarantee that the wssSource value is a fully qualified URL 107 | if (wssSource.indexOf('/') === 0) { 108 | var base_part = location.hostname + (location.port ? ':' + location.port : '') 109 | if (location.protocol === 'https:') { 110 | wssSource = 'wss://' + base_part + wssSource 111 | } else if (location.protocol === 'http:') { 112 | wssSource = 'ws://' + base_part + wssSource 113 | } 114 | } 115 | 116 | var socketWrapper = createWebsocketWrapper(socketElt, function() { 117 | return htmx.createWebSocket(wssSource) 118 | }) 119 | 120 | socketWrapper.addEventListener('message', function(event) { 121 | if (maybeCloseWebSocketSource(socketElt)) { 122 | return 123 | } 124 | 125 | var response = event.data 126 | if (!api.triggerEvent(socketElt, 'htmx:wsBeforeMessage', { 127 | message: response, 128 | socketWrapper: socketWrapper.publicInterface 129 | })) { 130 | return 131 | } 132 | 133 | api.withExtensions(socketElt, function(extension) { 134 | response = extension.transformResponse(response, null, socketElt) 135 | }) 136 | 137 | var settleInfo = api.makeSettleInfo(socketElt) 138 | var fragment = api.makeFragment(response) 139 | 140 | if (fragment.children.length) { 141 | var children = Array.from(fragment.children) 142 | for (var i = 0; i < children.length; i++) { 143 | api.oobSwap(api.getAttributeValue(children[i], 'hx-swap-oob') || 'true', children[i], settleInfo) 144 | } 145 | } 146 | 147 | api.settleImmediately(settleInfo.tasks) 148 | api.triggerEvent(socketElt, 'htmx:wsAfterMessage', { message: response, socketWrapper: socketWrapper.publicInterface }) 149 | }) 150 | 151 | // Put the WebSocket into the HTML Element's custom data. 152 | api.getInternalData(socketElt).webSocket = socketWrapper 153 | } 154 | 155 | /** 156 | * @typedef {Object} WebSocketWrapper 157 | * @property {WebSocket} socket 158 | * @property {Array<{message: string, sendElt: Element}>} messageQueue 159 | * @property {number} retryCount 160 | * @property {(message: string, sendElt: Element) => void} sendImmediately sendImmediately sends message regardless of websocket connection state 161 | * @property {(message: string, sendElt: Element) => void} send 162 | * @property {(event: string, handler: Function) => void} addEventListener 163 | * @property {() => void} handleQueuedMessages 164 | * @property {() => void} init 165 | * @property {() => void} close 166 | */ 167 | /** 168 | * 169 | * @param socketElt 170 | * @param socketFunc 171 | * @returns {WebSocketWrapper} 172 | */ 173 | function createWebsocketWrapper(socketElt, socketFunc) { 174 | var wrapper = { 175 | socket: null, 176 | messageQueue: [], 177 | retryCount: 0, 178 | 179 | /** @type {Object} */ 180 | events: {}, 181 | 182 | addEventListener: function(event, handler) { 183 | if (this.socket) { 184 | this.socket.addEventListener(event, handler) 185 | } 186 | 187 | if (!this.events[event]) { 188 | this.events[event] = [] 189 | } 190 | 191 | this.events[event].push(handler) 192 | }, 193 | 194 | sendImmediately: function(message, sendElt) { 195 | if (!this.socket) { 196 | api.triggerErrorEvent() 197 | } 198 | if (!sendElt || api.triggerEvent(sendElt, 'htmx:wsBeforeSend', { 199 | message, 200 | socketWrapper: this.publicInterface 201 | })) { 202 | this.socket.send(message) 203 | sendElt && api.triggerEvent(sendElt, 'htmx:wsAfterSend', { 204 | message, 205 | socketWrapper: this.publicInterface 206 | }) 207 | } 208 | }, 209 | 210 | send: function(message, sendElt) { 211 | if (this.socket.readyState !== this.socket.OPEN) { 212 | this.messageQueue.push({ message, sendElt }) 213 | } else { 214 | this.sendImmediately(message, sendElt) 215 | } 216 | }, 217 | 218 | handleQueuedMessages: function() { 219 | while (this.messageQueue.length > 0) { 220 | var queuedItem = this.messageQueue[0] 221 | if (this.socket.readyState === this.socket.OPEN) { 222 | this.sendImmediately(queuedItem.message, queuedItem.sendElt) 223 | this.messageQueue.shift() 224 | } else { 225 | break 226 | } 227 | } 228 | }, 229 | 230 | init: function() { 231 | if (this.socket && this.socket.readyState === this.socket.OPEN) { 232 | // Close discarded socket 233 | this.socket.close() 234 | } 235 | 236 | // Create a new WebSocket and event handlers 237 | /** @type {WebSocket} */ 238 | var socket = socketFunc() 239 | 240 | // The event.type detail is added for interface conformance with the 241 | // other two lifecycle events (open and close) so a single handler method 242 | // can handle them polymorphically, if required. 243 | api.triggerEvent(socketElt, 'htmx:wsConnecting', { event: { type: 'connecting' } }) 244 | 245 | this.socket = socket 246 | 247 | socket.onopen = function(e) { 248 | wrapper.retryCount = 0 249 | api.triggerEvent(socketElt, 'htmx:wsOpen', { event: e, socketWrapper: wrapper.publicInterface }) 250 | wrapper.handleQueuedMessages() 251 | } 252 | 253 | socket.onclose = function(e) { 254 | // If socket should not be connected, stop further attempts to establish connection 255 | // If Abnormal Closure/Service Restart/Try Again Later, then set a timer to reconnect after a pause. 256 | if (!maybeCloseWebSocketSource(socketElt) && [1006, 1012, 1013].indexOf(e.code) >= 0) { 257 | var delay = getWebSocketReconnectDelay(wrapper.retryCount) 258 | setTimeout(function() { 259 | wrapper.retryCount += 1 260 | wrapper.init() 261 | }, delay) 262 | } 263 | 264 | // Notify client code that connection has been closed. Client code can inspect `event` field 265 | // to determine whether closure has been valid or abnormal 266 | api.triggerEvent(socketElt, 'htmx:wsClose', { event: e, socketWrapper: wrapper.publicInterface }) 267 | } 268 | 269 | socket.onerror = function(e) { 270 | api.triggerErrorEvent(socketElt, 'htmx:wsError', { error: e, socketWrapper: wrapper }) 271 | maybeCloseWebSocketSource(socketElt) 272 | } 273 | 274 | var events = this.events 275 | Object.keys(events).forEach(function(k) { 276 | events[k].forEach(function(e) { 277 | socket.addEventListener(k, e) 278 | }) 279 | }) 280 | }, 281 | 282 | close: function() { 283 | this.socket.close() 284 | } 285 | } 286 | 287 | wrapper.init() 288 | 289 | wrapper.publicInterface = { 290 | send: wrapper.send.bind(wrapper), 291 | sendImmediately: wrapper.sendImmediately.bind(wrapper), 292 | queue: wrapper.messageQueue 293 | } 294 | 295 | return wrapper 296 | } 297 | 298 | /** 299 | * ensureWebSocketSend attaches trigger handles to elements with 300 | * "ws-send" attribute 301 | * @param {HTMLElement} elt 302 | */ 303 | function ensureWebSocketSend(elt) { 304 | var legacyAttribute = api.getAttributeValue(elt, 'hx-ws') 305 | if (legacyAttribute && legacyAttribute !== 'send') { 306 | return 307 | } 308 | 309 | var webSocketParent = api.getClosestMatch(elt, hasWebSocket) 310 | processWebSocketSend(webSocketParent, elt) 311 | } 312 | 313 | /** 314 | * hasWebSocket function checks if a node has webSocket instance attached 315 | * @param {HTMLElement} node 316 | * @returns {boolean} 317 | */ 318 | function hasWebSocket(node) { 319 | return api.getInternalData(node).webSocket != null 320 | } 321 | 322 | /** 323 | * processWebSocketSend adds event listeners to the
element so that 324 | * messages can be sent to the WebSocket server when the form is submitted. 325 | * @param {HTMLElement} socketElt 326 | * @param {HTMLElement} sendElt 327 | */ 328 | function processWebSocketSend(socketElt, sendElt) { 329 | var nodeData = api.getInternalData(sendElt) 330 | var triggerSpecs = api.getTriggerSpecs(sendElt) 331 | triggerSpecs.forEach(function(ts) { 332 | api.addTriggerHandler(sendElt, ts, nodeData, function(elt, evt) { 333 | if (maybeCloseWebSocketSource(socketElt)) { 334 | return 335 | } 336 | 337 | /** @type {WebSocketWrapper} */ 338 | var socketWrapper = api.getInternalData(socketElt).webSocket 339 | var headers = api.getHeaders(sendElt, api.getTarget(sendElt)) 340 | var results = api.getInputValues(sendElt, 'post') 341 | var errors = results.errors 342 | var rawParameters = Object.assign({}, results.values) 343 | var expressionVars = api.getExpressionVars(sendElt) 344 | var allParameters = api.mergeObjects(rawParameters, expressionVars) 345 | var filteredParameters = api.filterValues(allParameters, sendElt) 346 | 347 | var sendConfig = { 348 | parameters: filteredParameters, 349 | unfilteredParameters: allParameters, 350 | headers, 351 | errors, 352 | 353 | triggeringEvent: evt, 354 | messageBody: undefined, 355 | socketWrapper: socketWrapper.publicInterface 356 | } 357 | 358 | if (!api.triggerEvent(elt, 'htmx:wsConfigSend', sendConfig)) { 359 | return 360 | } 361 | 362 | if (errors && errors.length > 0) { 363 | api.triggerEvent(elt, 'htmx:validation:halted', errors) 364 | return 365 | } 366 | 367 | var body = sendConfig.messageBody 368 | if (body === undefined) { 369 | var toSend = Object.assign({}, sendConfig.parameters) 370 | if (sendConfig.headers) { toSend.HEADERS = headers } 371 | body = JSON.stringify(toSend) 372 | } 373 | 374 | socketWrapper.send(body, elt) 375 | 376 | if (evt && api.shouldCancel(evt, elt)) { 377 | evt.preventDefault() 378 | } 379 | }) 380 | }) 381 | } 382 | 383 | /** 384 | * getWebSocketReconnectDelay is the default easing function for WebSocket reconnects. 385 | * @param {number} retryCount // The number of retries that have already taken place 386 | * @returns {number} 387 | */ 388 | function getWebSocketReconnectDelay(retryCount) { 389 | /** @type {"full-jitter" | ((retryCount:number) => number)} */ 390 | var delay = htmx.config.wsReconnectDelay 391 | if (typeof delay === 'function') { 392 | return delay(retryCount) 393 | } 394 | if (delay === 'full-jitter') { 395 | var exp = Math.min(retryCount, 6) 396 | var maxDelay = 1000 * Math.pow(2, exp) 397 | return maxDelay * Math.random() 398 | } 399 | 400 | logError('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"') 401 | } 402 | 403 | /** 404 | * maybeCloseWebSocketSource checks to the if the element that created the WebSocket 405 | * still exists in the DOM. If NOT, then the WebSocket is closed and this function 406 | * returns TRUE. If the element DOES EXIST, then no action is taken, and this function 407 | * returns FALSE. 408 | * 409 | * @param {*} elt 410 | * @returns 411 | */ 412 | function maybeCloseWebSocketSource(elt) { 413 | if (!api.bodyContains(elt)) { 414 | api.getInternalData(elt).webSocket.close() 415 | return true 416 | } 417 | return false 418 | } 419 | 420 | /** 421 | * createWebSocket is the default method for creating new WebSocket objects. 422 | * it is hoisted into htmx.createWebSocket to be overridden by the user, if needed. 423 | * 424 | * @param {string} url 425 | * @returns WebSocket 426 | */ 427 | function createWebSocket(url) { 428 | var sock = new WebSocket(url, []) 429 | sock.binaryType = htmx.config.wsBinaryType 430 | return sock 431 | } 432 | 433 | /** 434 | * queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT. 435 | * 436 | * @param {HTMLElement} elt 437 | * @param {string} attributeName 438 | */ 439 | function queryAttributeOnThisOrChildren(elt, attributeName) { 440 | var result = [] 441 | 442 | // If the parent element also contains the requested attribute, then add it to the results too. 443 | if (api.hasAttribute(elt, attributeName) || api.hasAttribute(elt, 'hx-ws')) { 444 | result.push(elt) 445 | } 446 | 447 | // Search all child nodes that match the requested attribute 448 | elt.querySelectorAll('[' + attributeName + '], [data-' + attributeName + '], [data-hx-ws], [hx-ws]').forEach(function(node) { 449 | result.push(node) 450 | }) 451 | 452 | return result 453 | } 454 | 455 | /** 456 | * @template T 457 | * @param {T[]} arr 458 | * @param {(T) => void} func 459 | */ 460 | function forEach(arr, func) { 461 | if (arr) { 462 | for (var i = 0; i < arr.length; i++) { 463 | func(arr[i]) 464 | } 465 | } 466 | } 467 | })() 468 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Public/pico.min.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8";/*! 2 | * Pico CSS ✨ v2.0.6 (https://picocss.com) 3 | * Copyright 2019-2024 - Licensed under MIT 4 | */:root{--pico-font-family-emoji:"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--pico-font-family-sans-serif:system-ui,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,Helvetica,Arial,"Helvetica Neue",sans-serif,var(--pico-font-family-emoji);--pico-font-family-monospace:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace,var(--pico-font-family-emoji);--pico-font-family:var(--pico-font-family-sans-serif);--pico-line-height:1.5;--pico-font-weight:400;--pico-font-size:100%;--pico-text-underline-offset:0.1rem;--pico-border-radius:0.25rem;--pico-border-width:0.0625rem;--pico-outline-width:0.125rem;--pico-transition:0.2s ease-in-out;--pico-spacing:1rem;--pico-typography-spacing-vertical:1rem;--pico-block-spacing-vertical:var(--pico-spacing);--pico-block-spacing-horizontal:var(--pico-spacing);--pico-grid-column-gap:var(--pico-spacing);--pico-grid-row-gap:var(--pico-spacing);--pico-form-element-spacing-vertical:0.75rem;--pico-form-element-spacing-horizontal:1rem;--pico-group-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-group-box-shadow-focus-with-button:0 0 0 var(--pico-outline-width) var(--pico-primary-focus);--pico-group-box-shadow-focus-with-input:0 0 0 0.0625rem var(--pico-form-element-border-color);--pico-modal-overlay-backdrop-filter:blur(0.375rem);--pico-nav-element-spacing-vertical:1rem;--pico-nav-element-spacing-horizontal:0.5rem;--pico-nav-link-spacing-vertical:0.5rem;--pico-nav-link-spacing-horizontal:0.5rem;--pico-nav-breadcrumb-divider:">";--pico-icon-checkbox:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255)' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-minus:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(255, 255, 255)' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='5' y1='12' x2='19' y2='12'%3E%3C/line%3E%3C/svg%3E");--pico-icon-chevron:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-date:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");--pico-icon-time:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cpolyline points='12 6 12 12 16 14'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-search:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");--pico-icon-close:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(136, 145, 164)' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");--pico-icon-loading:url("data:image/svg+xml,%3Csvg fill='none' height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg' %3E%3Cstyle%3E g %7B animation: rotate 2s linear infinite; transform-origin: center center; %7D circle %7B stroke-dasharray: 75,100; stroke-dashoffset: -5; animation: dash 1.5s ease-in-out infinite; stroke-linecap: round; %7D @keyframes rotate %7B 0%25 %7B transform: rotate(0deg); %7D 100%25 %7B transform: rotate(360deg); %7D %7D @keyframes dash %7B 0%25 %7B stroke-dasharray: 1,100; stroke-dashoffset: 0; %7D 50%25 %7B stroke-dasharray: 44.5,100; stroke-dashoffset: -17.5; %7D 100%25 %7B stroke-dasharray: 44.5,100; stroke-dashoffset: -62; %7D %7D %3C/style%3E%3Cg%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='rgb(136, 145, 164)' stroke-width='4' /%3E%3C/g%3E%3C/svg%3E")}@media (min-width:576px){:root{--pico-font-size:106.25%}}@media (min-width:768px){:root{--pico-font-size:112.5%}}@media (min-width:1024px){:root{--pico-font-size:118.75%}}@media (min-width:1280px){:root{--pico-font-size:125%}}@media (min-width:1536px){:root{--pico-font-size:131.25%}}a{--pico-text-decoration:underline}a.contrast,a.secondary{--pico-text-decoration:underline}small{--pico-font-size:0.875em}h1,h2,h3,h4,h5,h6{--pico-font-weight:700}h1{--pico-font-size:2rem;--pico-line-height:1.125;--pico-typography-spacing-top:3rem}h2{--pico-font-size:1.75rem;--pico-line-height:1.15;--pico-typography-spacing-top:2.625rem}h3{--pico-font-size:1.5rem;--pico-line-height:1.175;--pico-typography-spacing-top:2.25rem}h4{--pico-font-size:1.25rem;--pico-line-height:1.2;--pico-typography-spacing-top:1.874rem}h5{--pico-font-size:1.125rem;--pico-line-height:1.225;--pico-typography-spacing-top:1.6875rem}h6{--pico-font-size:1rem;--pico-line-height:1.25;--pico-typography-spacing-top:1.5rem}tfoot td,tfoot th,thead td,thead th{--pico-font-weight:600;--pico-border-width:0.1875rem}code,kbd,pre,samp{--pico-font-family:var(--pico-font-family-monospace)}kbd{--pico-font-weight:bolder}:where(select,textarea),input:not([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[type=file]){--pico-outline-width:0.0625rem}[type=search]{--pico-border-radius:5rem}[type=checkbox],[type=radio]{--pico-border-width:0.125rem}[type=checkbox][role=switch]{--pico-border-width:0.1875rem}details.dropdown summary:not([role=button]){--pico-outline-width:0.0625rem}nav details.dropdown summary:focus-visible{--pico-outline-width:0.125rem}[role=search]{--pico-border-radius:5rem}[role=group]:has(button.secondary:focus,[type=submit].secondary:focus,[type=button].secondary:focus,[role=button].secondary:focus),[role=search]:has(button.secondary:focus,[type=submit].secondary:focus,[type=button].secondary:focus,[role=button].secondary:focus){--pico-group-box-shadow-focus-with-button:0 0 0 var(--pico-outline-width) var(--pico-secondary-focus)}[role=group]:has(button.contrast:focus,[type=submit].contrast:focus,[type=button].contrast:focus,[role=button].contrast:focus),[role=search]:has(button.contrast:focus,[type=submit].contrast:focus,[type=button].contrast:focus,[role=button].contrast:focus){--pico-group-box-shadow-focus-with-button:0 0 0 var(--pico-outline-width) var(--pico-contrast-focus)}[role=group] [role=button],[role=group] [type=button],[role=group] [type=submit],[role=group] button,[role=search] [role=button],[role=search] [type=button],[role=search] [type=submit],[role=search] button{--pico-form-element-spacing-horizontal:2rem}details summary[role=button]:not(.outline)::after{filter:brightness(0) invert(1)}[aria-busy=true]:not(input,select,textarea):is(button,[type=submit],[type=button],[type=reset],[role=button]):not(.outline)::before{filter:brightness(0) invert(1)}:root:not([data-theme=dark]),[data-theme=light]{--pico-background-color:#fff;--pico-color:#373c44;--pico-text-selection-color:rgba(2, 154, 232, 0.25);--pico-muted-color:#646b79;--pico-muted-border-color:#e7eaf0;--pico-primary:#0172ad;--pico-primary-background:#0172ad;--pico-primary-border:var(--pico-primary-background);--pico-primary-underline:rgba(1, 114, 173, 0.5);--pico-primary-hover:#015887;--pico-primary-hover-background:#02659a;--pico-primary-hover-border:var(--pico-primary-hover-background);--pico-primary-hover-underline:var(--pico-primary-hover);--pico-primary-focus:rgba(2, 154, 232, 0.5);--pico-primary-inverse:#fff;--pico-secondary:#5d6b89;--pico-secondary-background:#525f7a;--pico-secondary-border:var(--pico-secondary-background);--pico-secondary-underline:rgba(93, 107, 137, 0.5);--pico-secondary-hover:#48536b;--pico-secondary-hover-background:#48536b;--pico-secondary-hover-border:var(--pico-secondary-hover-background);--pico-secondary-hover-underline:var(--pico-secondary-hover);--pico-secondary-focus:rgba(93, 107, 137, 0.25);--pico-secondary-inverse:#fff;--pico-contrast:#181c25;--pico-contrast-background:#181c25;--pico-contrast-border:var(--pico-contrast-background);--pico-contrast-underline:rgba(24, 28, 37, 0.5);--pico-contrast-hover:#000;--pico-contrast-hover-background:#000;--pico-contrast-hover-border:var(--pico-contrast-hover-background);--pico-contrast-hover-underline:var(--pico-secondary-hover);--pico-contrast-focus:rgba(93, 107, 137, 0.25);--pico-contrast-inverse:#fff;--pico-box-shadow:0.0145rem 0.029rem 0.174rem rgba(129, 145, 181, 0.01698),0.0335rem 0.067rem 0.402rem rgba(129, 145, 181, 0.024),0.0625rem 0.125rem 0.75rem rgba(129, 145, 181, 0.03),0.1125rem 0.225rem 1.35rem rgba(129, 145, 181, 0.036),0.2085rem 0.417rem 2.502rem rgba(129, 145, 181, 0.04302),0.5rem 1rem 6rem rgba(129, 145, 181, 0.06),0 0 0 0.0625rem rgba(129, 145, 181, 0.015);--pico-h1-color:#2d3138;--pico-h2-color:#373c44;--pico-h3-color:#424751;--pico-h4-color:#4d535e;--pico-h5-color:#5c6370;--pico-h6-color:#646b79;--pico-mark-background-color:#fde7c0;--pico-mark-color:#0f1114;--pico-ins-color:#1d6a54;--pico-del-color:#883935;--pico-blockquote-border-color:var(--pico-muted-border-color);--pico-blockquote-footer-color:var(--pico-muted-color);--pico-button-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-button-hover-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-table-border-color:var(--pico-muted-border-color);--pico-table-row-stripped-background-color:rgba(111, 120, 135, 0.0375);--pico-code-background-color:#f3f5f7;--pico-code-color:#646b79;--pico-code-kbd-background-color:var(--pico-color);--pico-code-kbd-color:var(--pico-background-color);--pico-form-element-background-color:#fbfcfc;--pico-form-element-selected-background-color:#dfe3eb;--pico-form-element-border-color:#cfd5e2;--pico-form-element-color:#23262c;--pico-form-element-placeholder-color:var(--pico-muted-color);--pico-form-element-active-background-color:#fff;--pico-form-element-active-border-color:var(--pico-primary-border);--pico-form-element-focus-color:var(--pico-primary-border);--pico-form-element-disabled-opacity:0.5;--pico-form-element-invalid-border-color:#b86a6b;--pico-form-element-invalid-active-border-color:#c84f48;--pico-form-element-invalid-focus-color:var(--pico-form-element-invalid-active-border-color);--pico-form-element-valid-border-color:#4c9b8a;--pico-form-element-valid-active-border-color:#279977;--pico-form-element-valid-focus-color:var(--pico-form-element-valid-active-border-color);--pico-switch-background-color:#bfc7d9;--pico-switch-checked-background-color:var(--pico-primary-background);--pico-switch-color:#fff;--pico-switch-thumb-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-range-border-color:#dfe3eb;--pico-range-active-border-color:#bfc7d9;--pico-range-thumb-border-color:var(--pico-background-color);--pico-range-thumb-color:var(--pico-secondary-background);--pico-range-thumb-active-color:var(--pico-primary-background);--pico-accordion-border-color:var(--pico-muted-border-color);--pico-accordion-active-summary-color:var(--pico-primary-hover);--pico-accordion-close-summary-color:var(--pico-color);--pico-accordion-open-summary-color:var(--pico-muted-color);--pico-card-background-color:var(--pico-background-color);--pico-card-border-color:var(--pico-muted-border-color);--pico-card-box-shadow:var(--pico-box-shadow);--pico-card-sectioning-background-color:#fbfcfc;--pico-dropdown-background-color:#fff;--pico-dropdown-border-color:#eff1f4;--pico-dropdown-box-shadow:var(--pico-box-shadow);--pico-dropdown-color:var(--pico-color);--pico-dropdown-hover-background-color:#eff1f4;--pico-loading-spinner-opacity:0.5;--pico-modal-overlay-background-color:rgba(232, 234, 237, 0.75);--pico-progress-background-color:#dfe3eb;--pico-progress-color:var(--pico-primary-background);--pico-tooltip-background-color:var(--pico-contrast-background);--pico-tooltip-color:var(--pico-contrast-inverse);--pico-icon-valid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(76, 155, 138)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-invalid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(200, 79, 72)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");color-scheme:light}:root:not([data-theme=dark]) input:is([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[type=file]),[data-theme=light] input:is([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[type=file]){--pico-form-element-focus-color:var(--pico-primary-focus)}@media only screen and (prefers-color-scheme:dark){:root:not([data-theme]){--pico-background-color:#13171f;--pico-color:#c2c7d0;--pico-text-selection-color:rgba(1, 170, 255, 0.1875);--pico-muted-color:#7b8495;--pico-muted-border-color:#202632;--pico-primary:#01aaff;--pico-primary-background:#0172ad;--pico-primary-border:var(--pico-primary-background);--pico-primary-underline:rgba(1, 170, 255, 0.5);--pico-primary-hover:#79c0ff;--pico-primary-hover-background:#017fc0;--pico-primary-hover-border:var(--pico-primary-hover-background);--pico-primary-hover-underline:var(--pico-primary-hover);--pico-primary-focus:rgba(1, 170, 255, 0.375);--pico-primary-inverse:#fff;--pico-secondary:#969eaf;--pico-secondary-background:#525f7a;--pico-secondary-border:var(--pico-secondary-background);--pico-secondary-underline:rgba(150, 158, 175, 0.5);--pico-secondary-hover:#b3b9c5;--pico-secondary-hover-background:#5d6b89;--pico-secondary-hover-border:var(--pico-secondary-hover-background);--pico-secondary-hover-underline:var(--pico-secondary-hover);--pico-secondary-focus:rgba(144, 158, 190, 0.25);--pico-secondary-inverse:#fff;--pico-contrast:#dfe3eb;--pico-contrast-background:#eff1f4;--pico-contrast-border:var(--pico-contrast-background);--pico-contrast-underline:rgba(223, 227, 235, 0.5);--pico-contrast-hover:#fff;--pico-contrast-hover-background:#fff;--pico-contrast-hover-border:var(--pico-contrast-hover-background);--pico-contrast-hover-underline:var(--pico-contrast-hover);--pico-contrast-focus:rgba(207, 213, 226, 0.25);--pico-contrast-inverse:#000;--pico-box-shadow:0.0145rem 0.029rem 0.174rem rgba(7, 9, 12, 0.01698),0.0335rem 0.067rem 0.402rem rgba(7, 9, 12, 0.024),0.0625rem 0.125rem 0.75rem rgba(7, 9, 12, 0.03),0.1125rem 0.225rem 1.35rem rgba(7, 9, 12, 0.036),0.2085rem 0.417rem 2.502rem rgba(7, 9, 12, 0.04302),0.5rem 1rem 6rem rgba(7, 9, 12, 0.06),0 0 0 0.0625rem rgba(7, 9, 12, 0.015);--pico-h1-color:#f0f1f3;--pico-h2-color:#e0e3e7;--pico-h3-color:#c2c7d0;--pico-h4-color:#b3b9c5;--pico-h5-color:#a4acba;--pico-h6-color:#8891a4;--pico-mark-background-color:#014063;--pico-mark-color:#fff;--pico-ins-color:#62af9a;--pico-del-color:#ce7e7b;--pico-blockquote-border-color:var(--pico-muted-border-color);--pico-blockquote-footer-color:var(--pico-muted-color);--pico-button-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-button-hover-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-table-border-color:var(--pico-muted-border-color);--pico-table-row-stripped-background-color:rgba(111, 120, 135, 0.0375);--pico-code-background-color:#1a1f28;--pico-code-color:#8891a4;--pico-code-kbd-background-color:var(--pico-color);--pico-code-kbd-color:var(--pico-background-color);--pico-form-element-background-color:#1c212c;--pico-form-element-selected-background-color:#2a3140;--pico-form-element-border-color:#2a3140;--pico-form-element-color:#e0e3e7;--pico-form-element-placeholder-color:#8891a4;--pico-form-element-active-background-color:#1a1f28;--pico-form-element-active-border-color:var(--pico-primary-border);--pico-form-element-focus-color:var(--pico-primary-border);--pico-form-element-disabled-opacity:0.5;--pico-form-element-invalid-border-color:#964a50;--pico-form-element-invalid-active-border-color:#b7403b;--pico-form-element-invalid-focus-color:var(--pico-form-element-invalid-active-border-color);--pico-form-element-valid-border-color:#2a7b6f;--pico-form-element-valid-active-border-color:#16896a;--pico-form-element-valid-focus-color:var(--pico-form-element-valid-active-border-color);--pico-switch-background-color:#333c4e;--pico-switch-checked-background-color:var(--pico-primary-background);--pico-switch-color:#fff;--pico-switch-thumb-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-range-border-color:#202632;--pico-range-active-border-color:#2a3140;--pico-range-thumb-border-color:var(--pico-background-color);--pico-range-thumb-color:var(--pico-secondary-background);--pico-range-thumb-active-color:var(--pico-primary-background);--pico-accordion-border-color:var(--pico-muted-border-color);--pico-accordion-active-summary-color:var(--pico-primary-hover);--pico-accordion-close-summary-color:var(--pico-color);--pico-accordion-open-summary-color:var(--pico-muted-color);--pico-card-background-color:#181c25;--pico-card-border-color:var(--pico-card-background-color);--pico-card-box-shadow:var(--pico-box-shadow);--pico-card-sectioning-background-color:#1a1f28;--pico-dropdown-background-color:#181c25;--pico-dropdown-border-color:#202632;--pico-dropdown-box-shadow:var(--pico-box-shadow);--pico-dropdown-color:var(--pico-color);--pico-dropdown-hover-background-color:#202632;--pico-loading-spinner-opacity:0.5;--pico-modal-overlay-background-color:rgba(8, 9, 10, 0.75);--pico-progress-background-color:#202632;--pico-progress-color:var(--pico-primary-background);--pico-tooltip-background-color:var(--pico-contrast-background);--pico-tooltip-color:var(--pico-contrast-inverse);--pico-icon-valid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(42, 123, 111)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-invalid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(150, 74, 80)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");color-scheme:dark}:root:not([data-theme]) input:is([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[type=file]){--pico-form-element-focus-color:var(--pico-primary-focus)}:root:not([data-theme]) details summary[role=button].contrast:not(.outline)::after{filter:brightness(0)}:root:not([data-theme]) [aria-busy=true]:not(input,select,textarea).contrast:is(button,[type=submit],[type=button],[type=reset],[role=button]):not(.outline)::before{filter:brightness(0)}}[data-theme=dark]{--pico-background-color:#13171f;--pico-color:#c2c7d0;--pico-text-selection-color:rgba(1, 170, 255, 0.1875);--pico-muted-color:#7b8495;--pico-muted-border-color:#202632;--pico-primary:#01aaff;--pico-primary-background:#0172ad;--pico-primary-border:var(--pico-primary-background);--pico-primary-underline:rgba(1, 170, 255, 0.5);--pico-primary-hover:#79c0ff;--pico-primary-hover-background:#017fc0;--pico-primary-hover-border:var(--pico-primary-hover-background);--pico-primary-hover-underline:var(--pico-primary-hover);--pico-primary-focus:rgba(1, 170, 255, 0.375);--pico-primary-inverse:#fff;--pico-secondary:#969eaf;--pico-secondary-background:#525f7a;--pico-secondary-border:var(--pico-secondary-background);--pico-secondary-underline:rgba(150, 158, 175, 0.5);--pico-secondary-hover:#b3b9c5;--pico-secondary-hover-background:#5d6b89;--pico-secondary-hover-border:var(--pico-secondary-hover-background);--pico-secondary-hover-underline:var(--pico-secondary-hover);--pico-secondary-focus:rgba(144, 158, 190, 0.25);--pico-secondary-inverse:#fff;--pico-contrast:#dfe3eb;--pico-contrast-background:#eff1f4;--pico-contrast-border:var(--pico-contrast-background);--pico-contrast-underline:rgba(223, 227, 235, 0.5);--pico-contrast-hover:#fff;--pico-contrast-hover-background:#fff;--pico-contrast-hover-border:var(--pico-contrast-hover-background);--pico-contrast-hover-underline:var(--pico-contrast-hover);--pico-contrast-focus:rgba(207, 213, 226, 0.25);--pico-contrast-inverse:#000;--pico-box-shadow:0.0145rem 0.029rem 0.174rem rgba(7, 9, 12, 0.01698),0.0335rem 0.067rem 0.402rem rgba(7, 9, 12, 0.024),0.0625rem 0.125rem 0.75rem rgba(7, 9, 12, 0.03),0.1125rem 0.225rem 1.35rem rgba(7, 9, 12, 0.036),0.2085rem 0.417rem 2.502rem rgba(7, 9, 12, 0.04302),0.5rem 1rem 6rem rgba(7, 9, 12, 0.06),0 0 0 0.0625rem rgba(7, 9, 12, 0.015);--pico-h1-color:#f0f1f3;--pico-h2-color:#e0e3e7;--pico-h3-color:#c2c7d0;--pico-h4-color:#b3b9c5;--pico-h5-color:#a4acba;--pico-h6-color:#8891a4;--pico-mark-background-color:#014063;--pico-mark-color:#fff;--pico-ins-color:#62af9a;--pico-del-color:#ce7e7b;--pico-blockquote-border-color:var(--pico-muted-border-color);--pico-blockquote-footer-color:var(--pico-muted-color);--pico-button-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-button-hover-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-table-border-color:var(--pico-muted-border-color);--pico-table-row-stripped-background-color:rgba(111, 120, 135, 0.0375);--pico-code-background-color:#1a1f28;--pico-code-color:#8891a4;--pico-code-kbd-background-color:var(--pico-color);--pico-code-kbd-color:var(--pico-background-color);--pico-form-element-background-color:#1c212c;--pico-form-element-selected-background-color:#2a3140;--pico-form-element-border-color:#2a3140;--pico-form-element-color:#e0e3e7;--pico-form-element-placeholder-color:#8891a4;--pico-form-element-active-background-color:#1a1f28;--pico-form-element-active-border-color:var(--pico-primary-border);--pico-form-element-focus-color:var(--pico-primary-border);--pico-form-element-disabled-opacity:0.5;--pico-form-element-invalid-border-color:#964a50;--pico-form-element-invalid-active-border-color:#b7403b;--pico-form-element-invalid-focus-color:var(--pico-form-element-invalid-active-border-color);--pico-form-element-valid-border-color:#2a7b6f;--pico-form-element-valid-active-border-color:#16896a;--pico-form-element-valid-focus-color:var(--pico-form-element-valid-active-border-color);--pico-switch-background-color:#333c4e;--pico-switch-checked-background-color:var(--pico-primary-background);--pico-switch-color:#fff;--pico-switch-thumb-box-shadow:0 0 0 rgba(0, 0, 0, 0);--pico-range-border-color:#202632;--pico-range-active-border-color:#2a3140;--pico-range-thumb-border-color:var(--pico-background-color);--pico-range-thumb-color:var(--pico-secondary-background);--pico-range-thumb-active-color:var(--pico-primary-background);--pico-accordion-border-color:var(--pico-muted-border-color);--pico-accordion-active-summary-color:var(--pico-primary-hover);--pico-accordion-close-summary-color:var(--pico-color);--pico-accordion-open-summary-color:var(--pico-muted-color);--pico-card-background-color:#181c25;--pico-card-border-color:var(--pico-card-background-color);--pico-card-box-shadow:var(--pico-box-shadow);--pico-card-sectioning-background-color:#1a1f28;--pico-dropdown-background-color:#181c25;--pico-dropdown-border-color:#202632;--pico-dropdown-box-shadow:var(--pico-box-shadow);--pico-dropdown-color:var(--pico-color);--pico-dropdown-hover-background-color:#202632;--pico-loading-spinner-opacity:0.5;--pico-modal-overlay-background-color:rgba(8, 9, 10, 0.75);--pico-progress-background-color:#202632;--pico-progress-color:var(--pico-primary-background);--pico-tooltip-background-color:var(--pico-contrast-background);--pico-tooltip-color:var(--pico-contrast-inverse);--pico-icon-valid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(42, 123, 111)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");--pico-icon-invalid:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='rgb(150, 74, 80)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");color-scheme:dark}[data-theme=dark] input:is([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[type=file]){--pico-form-element-focus-color:var(--pico-primary-focus)}[data-theme=dark] details summary[role=button].contrast:not(.outline)::after{filter:brightness(0)}[data-theme=dark] [aria-busy=true]:not(input,select,textarea).contrast:is(button,[type=submit],[type=button],[type=reset],[role=button]):not(.outline)::before{filter:brightness(0)}[type=checkbox],[type=radio],[type=range],progress{accent-color:var(--pico-primary)}*,::after,::before{box-sizing:border-box;background-repeat:no-repeat}::after,::before{text-decoration:inherit;vertical-align:inherit}:where(:root){-webkit-tap-highlight-color:transparent;-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;text-size-adjust:100%;background-color:var(--pico-background-color);color:var(--pico-color);font-weight:var(--pico-font-weight);font-size:var(--pico-font-size);line-height:var(--pico-line-height);font-family:var(--pico-font-family);text-underline-offset:var(--pico-text-underline-offset);text-rendering:optimizeLegibility;overflow-wrap:break-word;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{width:100%;margin:0}main{display:block}body>footer,body>header,body>main{padding-block:var(--pico-block-spacing-vertical)}section{margin-bottom:var(--pico-block-spacing-vertical)}.container,.container-fluid{width:100%;margin-right:auto;margin-left:auto;padding-right:var(--pico-spacing);padding-left:var(--pico-spacing)}@media (min-width:576px){.container{max-width:510px;padding-right:0;padding-left:0}}@media (min-width:768px){.container{max-width:700px}}@media (min-width:1024px){.container{max-width:950px}}@media (min-width:1280px){.container{max-width:1200px}}@media (min-width:1536px){.container{max-width:1450px}}.grid{grid-column-gap:var(--pico-grid-column-gap);grid-row-gap:var(--pico-grid-row-gap);display:grid;grid-template-columns:1fr}@media (min-width:768px){.grid{grid-template-columns:repeat(auto-fit,minmax(0%,1fr))}}.grid>*{min-width:0}.overflow-auto{overflow:auto}b,strong{font-weight:bolder}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}address,blockquote,dl,ol,p,pre,table,ul{margin-top:0;margin-bottom:var(--pico-typography-spacing-vertical);color:var(--pico-color);font-style:normal;font-weight:var(--pico-font-weight)}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:var(--pico-typography-spacing-vertical);color:var(--pico-color);font-weight:var(--pico-font-weight);font-size:var(--pico-font-size);line-height:var(--pico-line-height);font-family:var(--pico-font-family)}h1{--pico-color:var(--pico-h1-color)}h2{--pico-color:var(--pico-h2-color)}h3{--pico-color:var(--pico-h3-color)}h4{--pico-color:var(--pico-h4-color)}h5{--pico-color:var(--pico-h5-color)}h6{--pico-color:var(--pico-h6-color)}:where(article,address,blockquote,dl,figure,form,ol,p,pre,table,ul)~:is(h1,h2,h3,h4,h5,h6){margin-top:var(--pico-typography-spacing-top)}p{margin-bottom:var(--pico-typography-spacing-vertical)}hgroup{margin-bottom:var(--pico-typography-spacing-vertical)}hgroup>*{margin-top:0;margin-bottom:0}hgroup>:not(:first-child):last-child{--pico-color:var(--pico-muted-color);--pico-font-weight:unset;font-size:1rem}:where(ol,ul) li{margin-bottom:calc(var(--pico-typography-spacing-vertical) * .25)}:where(dl,ol,ul) :where(dl,ol,ul){margin:0;margin-top:calc(var(--pico-typography-spacing-vertical) * .25)}ul li{list-style:square}mark{padding:.125rem .25rem;background-color:var(--pico-mark-background-color);color:var(--pico-mark-color);vertical-align:baseline}blockquote{display:block;margin:var(--pico-typography-spacing-vertical) 0;padding:var(--pico-spacing);border-right:none;border-left:.25rem solid var(--pico-blockquote-border-color);border-inline-start:0.25rem solid var(--pico-blockquote-border-color);border-inline-end:none}blockquote footer{margin-top:calc(var(--pico-typography-spacing-vertical) * .5);color:var(--pico-blockquote-footer-color)}abbr[title]{border-bottom:1px dotted;text-decoration:none;cursor:help}ins{color:var(--pico-ins-color);text-decoration:none}del{color:var(--pico-del-color)}::-moz-selection{background-color:var(--pico-text-selection-color)}::selection{background-color:var(--pico-text-selection-color)}:where(a:not([role=button])),[role=link]{--pico-color:var(--pico-primary);--pico-background-color:transparent;--pico-underline:var(--pico-primary-underline);outline:0;background-color:var(--pico-background-color);color:var(--pico-color);-webkit-text-decoration:var(--pico-text-decoration);text-decoration:var(--pico-text-decoration);text-decoration-color:var(--pico-underline);text-underline-offset:0.125em;transition:background-color var(--pico-transition),color var(--pico-transition),box-shadow var(--pico-transition),-webkit-text-decoration var(--pico-transition);transition:background-color var(--pico-transition),color var(--pico-transition),text-decoration var(--pico-transition),box-shadow var(--pico-transition);transition:background-color var(--pico-transition),color var(--pico-transition),text-decoration var(--pico-transition),box-shadow var(--pico-transition),-webkit-text-decoration var(--pico-transition)}:where(a:not([role=button])):is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[role=link]:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-color:var(--pico-primary-hover);--pico-underline:var(--pico-primary-hover-underline);--pico-text-decoration:underline}:where(a:not([role=button])):focus-visible,[role=link]:focus-visible{box-shadow:0 0 0 var(--pico-outline-width) var(--pico-primary-focus)}:where(a:not([role=button])).secondary,[role=link].secondary{--pico-color:var(--pico-secondary);--pico-underline:var(--pico-secondary-underline)}:where(a:not([role=button])).secondary:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[role=link].secondary:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-color:var(--pico-secondary-hover);--pico-underline:var(--pico-secondary-hover-underline)}:where(a:not([role=button])).contrast,[role=link].contrast{--pico-color:var(--pico-contrast);--pico-underline:var(--pico-contrast-underline)}:where(a:not([role=button])).contrast:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[role=link].contrast:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-color:var(--pico-contrast-hover);--pico-underline:var(--pico-contrast-hover-underline)}a[role=button]{display:inline-block}button{margin:0;overflow:visible;font-family:inherit;text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[role=button],[type=button],[type=file]::file-selector-button,[type=reset],[type=submit],button{--pico-background-color:var(--pico-primary-background);--pico-border-color:var(--pico-primary-border);--pico-color:var(--pico-primary-inverse);--pico-box-shadow:var(--pico-button-box-shadow, 0 0 0 rgba(0, 0, 0, 0));padding:var(--pico-form-element-spacing-vertical) var(--pico-form-element-spacing-horizontal);border:var(--pico-border-width) solid var(--pico-border-color);border-radius:var(--pico-border-radius);outline:0;background-color:var(--pico-background-color);box-shadow:var(--pico-box-shadow);color:var(--pico-color);font-weight:var(--pico-font-weight);font-size:1rem;line-height:var(--pico-line-height);text-align:center;text-decoration:none;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;transition:background-color var(--pico-transition),border-color var(--pico-transition),color var(--pico-transition),box-shadow var(--pico-transition)}[role=button]:is(:hover,:active,:focus),[role=button]:is([aria-current]:not([aria-current=false])),[type=button]:is(:hover,:active,:focus),[type=button]:is([aria-current]:not([aria-current=false])),[type=file]::file-selector-button:is(:hover,:active,:focus),[type=file]::file-selector-button:is([aria-current]:not([aria-current=false])),[type=reset]:is(:hover,:active,:focus),[type=reset]:is([aria-current]:not([aria-current=false])),[type=submit]:is(:hover,:active,:focus),[type=submit]:is([aria-current]:not([aria-current=false])),button:is(:hover,:active,:focus),button:is([aria-current]:not([aria-current=false])){--pico-background-color:var(--pico-primary-hover-background);--pico-border-color:var(--pico-primary-hover-border);--pico-box-shadow:var(--pico-button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0));--pico-color:var(--pico-primary-inverse)}[role=button]:focus,[role=button]:is([aria-current]:not([aria-current=false])):focus,[type=button]:focus,[type=button]:is([aria-current]:not([aria-current=false])):focus,[type=file]::file-selector-button:focus,[type=file]::file-selector-button:is([aria-current]:not([aria-current=false])):focus,[type=reset]:focus,[type=reset]:is([aria-current]:not([aria-current=false])):focus,[type=submit]:focus,[type=submit]:is([aria-current]:not([aria-current=false])):focus,button:focus,button:is([aria-current]:not([aria-current=false])):focus{--pico-box-shadow:var(--pico-button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),0 0 0 var(--pico-outline-width) var(--pico-primary-focus)}[type=button],[type=reset],[type=submit]{margin-bottom:var(--pico-spacing)}:is(button,[type=submit],[type=button],[role=button]).secondary,[type=file]::file-selector-button,[type=reset]{--pico-background-color:var(--pico-secondary-background);--pico-border-color:var(--pico-secondary-border);--pico-color:var(--pico-secondary-inverse);cursor:pointer}:is(button,[type=submit],[type=button],[role=button]).secondary:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[type=file]::file-selector-button:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[type=reset]:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-background-color:var(--pico-secondary-hover-background);--pico-border-color:var(--pico-secondary-hover-border);--pico-color:var(--pico-secondary-inverse)}:is(button,[type=submit],[type=button],[role=button]).secondary:focus,:is(button,[type=submit],[type=button],[role=button]).secondary:is([aria-current]:not([aria-current=false])):focus,[type=file]::file-selector-button:focus,[type=file]::file-selector-button:is([aria-current]:not([aria-current=false])):focus,[type=reset]:focus,[type=reset]:is([aria-current]:not([aria-current=false])):focus{--pico-box-shadow:var(--pico-button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),0 0 0 var(--pico-outline-width) var(--pico-secondary-focus)}:is(button,[type=submit],[type=button],[role=button]).contrast{--pico-background-color:var(--pico-contrast-background);--pico-border-color:var(--pico-contrast-border);--pico-color:var(--pico-contrast-inverse)}:is(button,[type=submit],[type=button],[role=button]).contrast:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-background-color:var(--pico-contrast-hover-background);--pico-border-color:var(--pico-contrast-hover-border);--pico-color:var(--pico-contrast-inverse)}:is(button,[type=submit],[type=button],[role=button]).contrast:focus,:is(button,[type=submit],[type=button],[role=button]).contrast:is([aria-current]:not([aria-current=false])):focus{--pico-box-shadow:var(--pico-button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),0 0 0 var(--pico-outline-width) var(--pico-contrast-focus)}:is(button,[type=submit],[type=button],[role=button]).outline,[type=reset].outline{--pico-background-color:transparent;--pico-color:var(--pico-primary);--pico-border-color:var(--pico-primary)}:is(button,[type=submit],[type=button],[role=button]).outline:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[type=reset].outline:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-background-color:transparent;--pico-color:var(--pico-primary-hover);--pico-border-color:var(--pico-primary-hover)}:is(button,[type=submit],[type=button],[role=button]).outline.secondary,[type=reset].outline{--pico-color:var(--pico-secondary);--pico-border-color:var(--pico-secondary)}:is(button,[type=submit],[type=button],[role=button]).outline.secondary:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),[type=reset].outline:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-color:var(--pico-secondary-hover);--pico-border-color:var(--pico-secondary-hover)}:is(button,[type=submit],[type=button],[role=button]).outline.contrast{--pico-color:var(--pico-contrast);--pico-border-color:var(--pico-contrast)}:is(button,[type=submit],[type=button],[role=button]).outline.contrast:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){--pico-color:var(--pico-contrast-hover);--pico-border-color:var(--pico-contrast-hover)}:where(button,[type=submit],[type=reset],[type=button],[role=button])[disabled],:where(fieldset[disabled]) :is(button,[type=submit],[type=button],[type=reset],[role=button]){opacity:.5;pointer-events:none}:where(table){width:100%;border-collapse:collapse;border-spacing:0;text-indent:0}td,th{padding:calc(var(--pico-spacing)/ 2) var(--pico-spacing);border-bottom:var(--pico-border-width) solid var(--pico-table-border-color);background-color:var(--pico-background-color);color:var(--pico-color);font-weight:var(--pico-font-weight);text-align:left;text-align:start}tfoot td,tfoot th{border-top:var(--pico-border-width) solid var(--pico-table-border-color);border-bottom:0}table.striped tbody tr:nth-child(odd) td,table.striped tbody tr:nth-child(odd) th{background-color:var(--pico-table-row-stripped-background-color)}:where(audio,canvas,iframe,img,svg,video){vertical-align:middle}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}:where(iframe){border-style:none}img{max-width:100%;height:auto;border-style:none}:where(svg:not([fill])){fill:currentColor}svg:not(:root){overflow:hidden}code,kbd,pre,samp{font-size:.875em;font-family:var(--pico-font-family)}pre code{font-size:inherit;font-family:inherit}pre{-ms-overflow-style:scrollbar;overflow:auto}code,kbd,pre{border-radius:var(--pico-border-radius);background:var(--pico-code-background-color);color:var(--pico-code-color);font-weight:var(--pico-font-weight);line-height:initial}code,kbd{display:inline-block;padding:.375rem}pre{display:block;margin-bottom:var(--pico-spacing);overflow-x:auto}pre>code{display:block;padding:var(--pico-spacing);background:0 0;line-height:var(--pico-line-height)}kbd{background-color:var(--pico-code-kbd-background-color);color:var(--pico-code-kbd-color);vertical-align:baseline}figure{display:block;margin:0;padding:0}figure figcaption{padding:calc(var(--pico-spacing) * .5) 0;color:var(--pico-muted-color)}hr{height:0;margin:var(--pico-typography-spacing-vertical) 0;border:0;border-top:1px solid var(--pico-muted-border-color);color:inherit}[hidden],template{display:none!important}canvas{display:inline-block}input,optgroup,select,textarea{margin:0;font-size:1rem;line-height:var(--pico-line-height);font-family:inherit;letter-spacing:inherit}input{overflow:visible}select{text-transform:none}legend{max-width:100%;padding:0;color:inherit;white-space:normal}textarea{overflow:auto}[type=checkbox],[type=radio]{padding:0}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}::-moz-focus-inner{padding:0;border-style:none}:-moz-focusring{outline:0}:-moz-ui-invalid{box-shadow:none}::-ms-expand{display:none}[type=file],[type=range]{padding:0;border-width:0}input:not([type=checkbox],[type=radio],[type=range]){height:calc(1rem * var(--pico-line-height) + var(--pico-form-element-spacing-vertical) * 2 + var(--pico-border-width) * 2)}fieldset{width:100%;margin:0;margin-bottom:var(--pico-spacing);padding:0;border:0}fieldset legend,label{display:block;margin-bottom:calc(var(--pico-spacing) * .375);color:var(--pico-color);font-weight:var(--pico-form-label-font-weight,var(--pico-font-weight))}fieldset legend{margin-bottom:calc(var(--pico-spacing) * .5)}button[type=submit],input:not([type=checkbox],[type=radio]),select,textarea{width:100%}input:not([type=checkbox],[type=radio],[type=range],[type=file]),select,textarea{-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:var(--pico-form-element-spacing-vertical) var(--pico-form-element-spacing-horizontal)}input,select,textarea{--pico-background-color:var(--pico-form-element-background-color);--pico-border-color:var(--pico-form-element-border-color);--pico-color:var(--pico-form-element-color);--pico-box-shadow:none;border:var(--pico-border-width) solid var(--pico-border-color);border-radius:var(--pico-border-radius);outline:0;background-color:var(--pico-background-color);box-shadow:var(--pico-box-shadow);color:var(--pico-color);font-weight:var(--pico-font-weight);transition:background-color var(--pico-transition),border-color var(--pico-transition),color var(--pico-transition),box-shadow var(--pico-transition)}:where(select,textarea):not([readonly]):is(:active,:focus),input:not([type=submit],[type=button],[type=reset],[type=checkbox],[type=radio],[readonly]):is(:active,:focus){--pico-background-color:var(--pico-form-element-active-background-color)}:where(select,textarea):not([readonly]):is(:active,:focus),input:not([type=submit],[type=button],[type=reset],[role=switch],[readonly]):is(:active,:focus){--pico-border-color:var(--pico-form-element-active-border-color)}:where(select,textarea):not([readonly]):focus,input:not([type=submit],[type=button],[type=reset],[type=range],[type=file],[readonly]):focus{--pico-box-shadow:0 0 0 var(--pico-outline-width) var(--pico-form-element-focus-color)}:where(fieldset[disabled]) :is(input:not([type=submit],[type=button],[type=reset]),select,textarea),input:not([type=submit],[type=button],[type=reset])[disabled],label[aria-disabled=true],select[disabled],textarea[disabled]{opacity:var(--pico-form-element-disabled-opacity);pointer-events:none}label[aria-disabled=true] input[disabled]{opacity:1}:where(input,select,textarea):not([type=checkbox],[type=radio],[type=date],[type=datetime-local],[type=month],[type=time],[type=week],[type=range])[aria-invalid]{padding-right:calc(var(--pico-form-element-spacing-horizontal) + 1.5rem)!important;padding-left:var(--pico-form-element-spacing-horizontal);padding-inline-start:var(--pico-form-element-spacing-horizontal)!important;padding-inline-end:calc(var(--pico-form-element-spacing-horizontal) + 1.5rem)!important;background-position:center right .75rem;background-size:1rem auto;background-repeat:no-repeat}:where(input,select,textarea):not([type=checkbox],[type=radio],[type=date],[type=datetime-local],[type=month],[type=time],[type=week],[type=range])[aria-invalid=false]:not(select){background-image:var(--pico-icon-valid)}:where(input,select,textarea):not([type=checkbox],[type=radio],[type=date],[type=datetime-local],[type=month],[type=time],[type=week],[type=range])[aria-invalid=true]:not(select){background-image:var(--pico-icon-invalid)}:where(input,select,textarea)[aria-invalid=false]{--pico-border-color:var(--pico-form-element-valid-border-color)}:where(input,select,textarea)[aria-invalid=false]:is(:active,:focus){--pico-border-color:var(--pico-form-element-valid-active-border-color)!important}:where(input,select,textarea)[aria-invalid=false]:is(:active,:focus):not([type=checkbox],[type=radio]){--pico-box-shadow:0 0 0 var(--pico-outline-width) var(--pico-form-element-valid-focus-color)!important}:where(input,select,textarea)[aria-invalid=true]{--pico-border-color:var(--pico-form-element-invalid-border-color)}:where(input,select,textarea)[aria-invalid=true]:is(:active,:focus){--pico-border-color:var(--pico-form-element-invalid-active-border-color)!important}:where(input,select,textarea)[aria-invalid=true]:is(:active,:focus):not([type=checkbox],[type=radio]){--pico-box-shadow:0 0 0 var(--pico-outline-width) var(--pico-form-element-invalid-focus-color)!important}[dir=rtl] :where(input,select,textarea):not([type=checkbox],[type=radio]):is([aria-invalid],[aria-invalid=true],[aria-invalid=false]){background-position:center left .75rem}input::-webkit-input-placeholder,input::placeholder,select:invalid,textarea::-webkit-input-placeholder,textarea::placeholder{color:var(--pico-form-element-placeholder-color);opacity:1}input:not([type=checkbox],[type=radio]),select,textarea{margin-bottom:var(--pico-spacing)}select::-ms-expand{border:0;background-color:transparent}select:not([multiple],[size]){padding-right:calc(var(--pico-form-element-spacing-horizontal) + 1.5rem);padding-left:var(--pico-form-element-spacing-horizontal);padding-inline-start:var(--pico-form-element-spacing-horizontal);padding-inline-end:calc(var(--pico-form-element-spacing-horizontal) + 1.5rem);background-image:var(--pico-icon-chevron);background-position:center right .75rem;background-size:1rem auto;background-repeat:no-repeat}select[multiple] option:checked{background:var(--pico-form-element-selected-background-color);color:var(--pico-form-element-color)}[dir=rtl] select:not([multiple],[size]){background-position:center left .75rem}textarea{display:block;resize:vertical}textarea[aria-invalid]{--pico-icon-height:calc(1rem * var(--pico-line-height) + var(--pico-form-element-spacing-vertical) * 2 + var(--pico-border-width) * 2);background-position:top right .75rem!important;background-size:1rem var(--pico-icon-height)!important}:where(input,select,textarea,fieldset,.grid)+small{display:block;width:100%;margin-top:calc(var(--pico-spacing) * -.75);margin-bottom:var(--pico-spacing);color:var(--pico-muted-color)}:where(input,select,textarea,fieldset,.grid)[aria-invalid=false]+small{color:var(--pico-ins-color)}:where(input,select,textarea,fieldset,.grid)[aria-invalid=true]+small{color:var(--pico-del-color)}label>:where(input,select,textarea){margin-top:calc(var(--pico-spacing) * .25)}label:has([type=checkbox],[type=radio]){width:-moz-fit-content;width:fit-content;cursor:pointer}[type=checkbox],[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:1.25em;height:1.25em;margin-top:-.125em;margin-inline-end:.5em;border-width:var(--pico-border-width);vertical-align:middle;cursor:pointer}[type=checkbox]::-ms-check,[type=radio]::-ms-check{display:none}[type=checkbox]:checked,[type=checkbox]:checked:active,[type=checkbox]:checked:focus,[type=radio]:checked,[type=radio]:checked:active,[type=radio]:checked:focus{--pico-background-color:var(--pico-primary-background);--pico-border-color:var(--pico-primary-border);background-image:var(--pico-icon-checkbox);background-position:center;background-size:.75em auto;background-repeat:no-repeat}[type=checkbox]~label,[type=radio]~label{display:inline-block;margin-bottom:0;cursor:pointer}[type=checkbox]~label:not(:last-of-type),[type=radio]~label:not(:last-of-type){margin-inline-end:1em}[type=checkbox]:indeterminate{--pico-background-color:var(--pico-primary-background);--pico-border-color:var(--pico-primary-border);background-image:var(--pico-icon-minus);background-position:center;background-size:.75em auto;background-repeat:no-repeat}[type=radio]{border-radius:50%}[type=radio]:checked,[type=radio]:checked:active,[type=radio]:checked:focus{--pico-background-color:var(--pico-primary-inverse);border-width:.35em;background-image:none}[type=checkbox][role=switch]{--pico-background-color:var(--pico-switch-background-color);--pico-color:var(--pico-switch-color);width:2.25em;height:1.25em;border:var(--pico-border-width) solid var(--pico-border-color);border-radius:1.25em;background-color:var(--pico-background-color);line-height:1.25em}[type=checkbox][role=switch]:not([aria-invalid]){--pico-border-color:var(--pico-switch-background-color)}[type=checkbox][role=switch]:before{display:block;aspect-ratio:1;height:100%;border-radius:50%;background-color:var(--pico-color);box-shadow:var(--pico-switch-thumb-box-shadow);content:"";transition:margin .1s ease-in-out}[type=checkbox][role=switch]:focus{--pico-background-color:var(--pico-switch-background-color);--pico-border-color:var(--pico-switch-background-color)}[type=checkbox][role=switch]:checked{--pico-background-color:var(--pico-switch-checked-background-color);--pico-border-color:var(--pico-switch-checked-background-color);background-image:none}[type=checkbox][role=switch]:checked::before{margin-inline-start:calc(2.25em - 1.25em)}[type=checkbox][role=switch][disabled]{--pico-background-color:var(--pico-border-color)}[type=checkbox][aria-invalid=false]:checked,[type=checkbox][aria-invalid=false]:checked:active,[type=checkbox][aria-invalid=false]:checked:focus,[type=checkbox][role=switch][aria-invalid=false]:checked,[type=checkbox][role=switch][aria-invalid=false]:checked:active,[type=checkbox][role=switch][aria-invalid=false]:checked:focus{--pico-background-color:var(--pico-form-element-valid-border-color)}[type=checkbox]:checked:active[aria-invalid=true],[type=checkbox]:checked:focus[aria-invalid=true],[type=checkbox]:checked[aria-invalid=true],[type=checkbox][role=switch]:checked:active[aria-invalid=true],[type=checkbox][role=switch]:checked:focus[aria-invalid=true],[type=checkbox][role=switch]:checked[aria-invalid=true]{--pico-background-color:var(--pico-form-element-invalid-border-color)}[type=checkbox][aria-invalid=false]:checked,[type=checkbox][aria-invalid=false]:checked:active,[type=checkbox][aria-invalid=false]:checked:focus,[type=checkbox][role=switch][aria-invalid=false]:checked,[type=checkbox][role=switch][aria-invalid=false]:checked:active,[type=checkbox][role=switch][aria-invalid=false]:checked:focus,[type=radio][aria-invalid=false]:checked,[type=radio][aria-invalid=false]:checked:active,[type=radio][aria-invalid=false]:checked:focus{--pico-border-color:var(--pico-form-element-valid-border-color)}[type=checkbox]:checked:active[aria-invalid=true],[type=checkbox]:checked:focus[aria-invalid=true],[type=checkbox]:checked[aria-invalid=true],[type=checkbox][role=switch]:checked:active[aria-invalid=true],[type=checkbox][role=switch]:checked:focus[aria-invalid=true],[type=checkbox][role=switch]:checked[aria-invalid=true],[type=radio]:checked:active[aria-invalid=true],[type=radio]:checked:focus[aria-invalid=true],[type=radio]:checked[aria-invalid=true]{--pico-border-color:var(--pico-form-element-invalid-border-color)}[type=color]::-webkit-color-swatch-wrapper{padding:0}[type=color]::-moz-focus-inner{padding:0}[type=color]::-webkit-color-swatch{border:0;border-radius:calc(var(--pico-border-radius) * .5)}[type=color]::-moz-color-swatch{border:0;border-radius:calc(var(--pico-border-radius) * .5)}input:not([type=checkbox],[type=radio],[type=range],[type=file]):is([type=date],[type=datetime-local],[type=month],[type=time],[type=week]){--pico-icon-position:0.75rem;--pico-icon-width:1rem;padding-right:calc(var(--pico-icon-width) + var(--pico-icon-position));background-image:var(--pico-icon-date);background-position:center right var(--pico-icon-position);background-size:var(--pico-icon-width) auto;background-repeat:no-repeat}input:not([type=checkbox],[type=radio],[type=range],[type=file])[type=time]{background-image:var(--pico-icon-time)}[type=date]::-webkit-calendar-picker-indicator,[type=datetime-local]::-webkit-calendar-picker-indicator,[type=month]::-webkit-calendar-picker-indicator,[type=time]::-webkit-calendar-picker-indicator,[type=week]::-webkit-calendar-picker-indicator{width:var(--pico-icon-width);margin-right:calc(var(--pico-icon-width) * -1);margin-left:var(--pico-icon-position);opacity:0}@-moz-document url-prefix(){[type=date],[type=datetime-local],[type=month],[type=time],[type=week]{padding-right:var(--pico-form-element-spacing-horizontal)!important;background-image:none!important}}[dir=rtl] :is([type=date],[type=datetime-local],[type=month],[type=time],[type=week]){text-align:right}[type=file]{--pico-color:var(--pico-muted-color);margin-left:calc(var(--pico-outline-width) * -1);padding:calc(var(--pico-form-element-spacing-vertical) * .5) 0;padding-left:var(--pico-outline-width);border:0;border-radius:0;background:0 0}[type=file]::file-selector-button{margin-right:calc(var(--pico-spacing)/ 2);padding:calc(var(--pico-form-element-spacing-vertical) * .5) var(--pico-form-element-spacing-horizontal)}[type=file]:is(:hover,:active,:focus)::file-selector-button{--pico-background-color:var(--pico-secondary-hover-background);--pico-border-color:var(--pico-secondary-hover-border)}[type=file]:focus::file-selector-button{--pico-box-shadow:var(--pico-button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),0 0 0 var(--pico-outline-width) var(--pico-secondary-focus)}[type=range]{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;height:1.25rem;background:0 0}[type=range]::-webkit-slider-runnable-track{width:100%;height:.375rem;border-radius:var(--pico-border-radius);background-color:var(--pico-range-border-color);-webkit-transition:background-color var(--pico-transition),box-shadow var(--pico-transition);transition:background-color var(--pico-transition),box-shadow var(--pico-transition)}[type=range]::-moz-range-track{width:100%;height:.375rem;border-radius:var(--pico-border-radius);background-color:var(--pico-range-border-color);-moz-transition:background-color var(--pico-transition),box-shadow var(--pico-transition);transition:background-color var(--pico-transition),box-shadow var(--pico-transition)}[type=range]::-ms-track{width:100%;height:.375rem;border-radius:var(--pico-border-radius);background-color:var(--pico-range-border-color);-ms-transition:background-color var(--pico-transition),box-shadow var(--pico-transition);transition:background-color var(--pico-transition),box-shadow var(--pico-transition)}[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:1.25rem;height:1.25rem;margin-top:-.4375rem;border:2px solid var(--pico-range-thumb-border-color);border-radius:50%;background-color:var(--pico-range-thumb-color);cursor:pointer;-webkit-transition:background-color var(--pico-transition),transform var(--pico-transition);transition:background-color var(--pico-transition),transform var(--pico-transition)}[type=range]::-moz-range-thumb{-webkit-appearance:none;width:1.25rem;height:1.25rem;margin-top:-.4375rem;border:2px solid var(--pico-range-thumb-border-color);border-radius:50%;background-color:var(--pico-range-thumb-color);cursor:pointer;-moz-transition:background-color var(--pico-transition),transform var(--pico-transition);transition:background-color var(--pico-transition),transform var(--pico-transition)}[type=range]::-ms-thumb{-webkit-appearance:none;width:1.25rem;height:1.25rem;margin-top:-.4375rem;border:2px solid var(--pico-range-thumb-border-color);border-radius:50%;background-color:var(--pico-range-thumb-color);cursor:pointer;-ms-transition:background-color var(--pico-transition),transform var(--pico-transition);transition:background-color var(--pico-transition),transform var(--pico-transition)}[type=range]:active,[type=range]:focus-within{--pico-range-border-color:var(--pico-range-active-border-color);--pico-range-thumb-color:var(--pico-range-thumb-active-color)}[type=range]:active::-webkit-slider-thumb{transform:scale(1.25)}[type=range]:active::-moz-range-thumb{transform:scale(1.25)}[type=range]:active::-ms-thumb{transform:scale(1.25)}input:not([type=checkbox],[type=radio],[type=range],[type=file])[type=search]{padding-inline-start:calc(var(--pico-form-element-spacing-horizontal) + 1.75rem);background-image:var(--pico-icon-search);background-position:center left calc(var(--pico-form-element-spacing-horizontal) + .125rem);background-size:1rem auto;background-repeat:no-repeat}input:not([type=checkbox],[type=radio],[type=range],[type=file])[type=search][aria-invalid]{padding-inline-start:calc(var(--pico-form-element-spacing-horizontal) + 1.75rem)!important;background-position:center left 1.125rem,center right .75rem}input:not([type=checkbox],[type=radio],[type=range],[type=file])[type=search][aria-invalid=false]{background-image:var(--pico-icon-search),var(--pico-icon-valid)}input:not([type=checkbox],[type=radio],[type=range],[type=file])[type=search][aria-invalid=true]{background-image:var(--pico-icon-search),var(--pico-icon-invalid)}[dir=rtl] :where(input):not([type=checkbox],[type=radio],[type=range],[type=file])[type=search]{background-position:center right 1.125rem}[dir=rtl] :where(input):not([type=checkbox],[type=radio],[type=range],[type=file])[type=search][aria-invalid]{background-position:center right 1.125rem,center left .75rem}details{display:block;margin-bottom:var(--pico-spacing)}details summary{line-height:1rem;list-style-type:none;cursor:pointer;transition:color var(--pico-transition)}details summary:not([role]){color:var(--pico-accordion-close-summary-color)}details summary::-webkit-details-marker{display:none}details summary::marker{display:none}details summary::-moz-list-bullet{list-style-type:none}details summary::after{display:block;width:1rem;height:1rem;margin-inline-start:calc(var(--pico-spacing,1rem) * .5);float:right;transform:rotate(-90deg);background-image:var(--pico-icon-chevron);background-position:right center;background-size:1rem auto;background-repeat:no-repeat;content:"";transition:transform var(--pico-transition)}details summary:focus{outline:0}details summary:focus:not([role]){color:var(--pico-accordion-active-summary-color)}details summary:focus-visible:not([role]){outline:var(--pico-outline-width) solid var(--pico-primary-focus);outline-offset:calc(var(--pico-spacing,1rem) * 0.5);color:var(--pico-primary)}details summary[role=button]{width:100%;text-align:left}details summary[role=button]::after{height:calc(1rem * var(--pico-line-height,1.5))}details[open]>summary{margin-bottom:var(--pico-spacing)}details[open]>summary:not([role]):not(:focus){color:var(--pico-accordion-open-summary-color)}details[open]>summary::after{transform:rotate(0)}[dir=rtl] details summary{text-align:right}[dir=rtl] details summary::after{float:left;background-position:left center}article{margin-bottom:var(--pico-block-spacing-vertical);padding:var(--pico-block-spacing-vertical) var(--pico-block-spacing-horizontal);border-radius:var(--pico-border-radius);background:var(--pico-card-background-color);box-shadow:var(--pico-card-box-shadow)}article>footer,article>header{margin-right:calc(var(--pico-block-spacing-horizontal) * -1);margin-left:calc(var(--pico-block-spacing-horizontal) * -1);padding:calc(var(--pico-block-spacing-vertical) * .66) var(--pico-block-spacing-horizontal);background-color:var(--pico-card-sectioning-background-color)}article>header{margin-top:calc(var(--pico-block-spacing-vertical) * -1);margin-bottom:var(--pico-block-spacing-vertical);border-bottom:var(--pico-border-width) solid var(--pico-card-border-color);border-top-right-radius:var(--pico-border-radius);border-top-left-radius:var(--pico-border-radius)}article>footer{margin-top:var(--pico-block-spacing-vertical);margin-bottom:calc(var(--pico-block-spacing-vertical) * -1);border-top:var(--pico-border-width) solid var(--pico-card-border-color);border-bottom-right-radius:var(--pico-border-radius);border-bottom-left-radius:var(--pico-border-radius)}details.dropdown{position:relative;border-bottom:none}details.dropdown summary::after,details.dropdown>a::after,details.dropdown>button::after{display:block;width:1rem;height:calc(1rem * var(--pico-line-height,1.5));margin-inline-start:.25rem;float:right;transform:rotate(0) translateX(.2rem);background-image:var(--pico-icon-chevron);background-position:right center;background-size:1rem auto;background-repeat:no-repeat;content:""}nav details.dropdown{margin-bottom:0}details.dropdown summary:not([role]){height:calc(1rem * var(--pico-line-height) + var(--pico-form-element-spacing-vertical) * 2 + var(--pico-border-width) * 2);padding:var(--pico-form-element-spacing-vertical) var(--pico-form-element-spacing-horizontal);border:var(--pico-border-width) solid var(--pico-form-element-border-color);border-radius:var(--pico-border-radius);background-color:var(--pico-form-element-background-color);color:var(--pico-form-element-placeholder-color);line-height:inherit;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;transition:background-color var(--pico-transition),border-color var(--pico-transition),color var(--pico-transition),box-shadow var(--pico-transition)}details.dropdown summary:not([role]):active,details.dropdown summary:not([role]):focus{border-color:var(--pico-form-element-active-border-color);background-color:var(--pico-form-element-active-background-color)}details.dropdown summary:not([role]):focus{box-shadow:0 0 0 var(--pico-outline-width) var(--pico-form-element-focus-color)}details.dropdown summary:not([role]):focus-visible{outline:0}details.dropdown summary:not([role])[aria-invalid=false]{--pico-form-element-border-color:var(--pico-form-element-valid-border-color);--pico-form-element-active-border-color:var(--pico-form-element-valid-focus-color);--pico-form-element-focus-color:var(--pico-form-element-valid-focus-color)}details.dropdown summary:not([role])[aria-invalid=true]{--pico-form-element-border-color:var(--pico-form-element-invalid-border-color);--pico-form-element-active-border-color:var(--pico-form-element-invalid-focus-color);--pico-form-element-focus-color:var(--pico-form-element-invalid-focus-color)}nav details.dropdown{display:inline;margin:calc(var(--pico-nav-element-spacing-vertical) * -1) 0}nav details.dropdown summary::after{transform:rotate(0) translateX(0)}nav details.dropdown summary:not([role]){height:calc(1rem * var(--pico-line-height) + var(--pico-nav-link-spacing-vertical) * 2);padding:calc(var(--pico-nav-link-spacing-vertical) - var(--pico-border-width) * 2) var(--pico-nav-link-spacing-horizontal)}nav details.dropdown summary:not([role]):focus-visible{box-shadow:0 0 0 var(--pico-outline-width) var(--pico-primary-focus)}details.dropdown summary+ul{display:flex;z-index:99;position:absolute;left:0;flex-direction:column;width:100%;min-width:-moz-fit-content;min-width:fit-content;margin:0;margin-top:var(--pico-outline-width);padding:0;border:var(--pico-border-width) solid var(--pico-dropdown-border-color);border-radius:var(--pico-border-radius);background-color:var(--pico-dropdown-background-color);box-shadow:var(--pico-dropdown-box-shadow);color:var(--pico-dropdown-color);white-space:nowrap;opacity:0;transition:opacity var(--pico-transition),transform 0s ease-in-out 1s}details.dropdown summary+ul[dir=rtl]{right:0;left:auto}details.dropdown summary+ul li{width:100%;margin-bottom:0;padding:calc(var(--pico-form-element-spacing-vertical) * .5) var(--pico-form-element-spacing-horizontal);list-style:none}details.dropdown summary+ul li:first-of-type{margin-top:calc(var(--pico-form-element-spacing-vertical) * .5)}details.dropdown summary+ul li:last-of-type{margin-bottom:calc(var(--pico-form-element-spacing-vertical) * .5)}details.dropdown summary+ul li a{display:block;margin:calc(var(--pico-form-element-spacing-vertical) * -.5) calc(var(--pico-form-element-spacing-horizontal) * -1);padding:calc(var(--pico-form-element-spacing-vertical) * .5) var(--pico-form-element-spacing-horizontal);overflow:hidden;border-radius:0;color:var(--pico-dropdown-color);text-decoration:none;text-overflow:ellipsis}details.dropdown summary+ul li a:active,details.dropdown summary+ul li a:focus,details.dropdown summary+ul li a:focus-visible,details.dropdown summary+ul li a:hover,details.dropdown summary+ul li a[aria-current]:not([aria-current=false]){background-color:var(--pico-dropdown-hover-background-color)}details.dropdown summary+ul li label{width:100%}details.dropdown summary+ul li:has(label):hover{background-color:var(--pico-dropdown-hover-background-color)}details.dropdown[open] summary{margin-bottom:0}details.dropdown[open] summary+ul{transform:scaleY(1);opacity:1;transition:opacity var(--pico-transition),transform 0s ease-in-out 0s}details.dropdown[open] summary::before{display:block;z-index:1;position:fixed;width:100vw;height:100vh;inset:0;background:0 0;content:"";cursor:default}label>details.dropdown{margin-top:calc(var(--pico-spacing) * .25)}[role=group],[role=search]{display:inline-flex;position:relative;width:100%;margin-bottom:var(--pico-spacing);border-radius:var(--pico-border-radius);box-shadow:var(--pico-group-box-shadow,0 0 0 transparent);vertical-align:middle;transition:box-shadow var(--pico-transition)}[role=group] input:not([type=checkbox],[type=radio]),[role=group] select,[role=group]>*,[role=search] input:not([type=checkbox],[type=radio]),[role=search] select,[role=search]>*{position:relative;flex:1 1 auto;margin-bottom:0}[role=group] input:not([type=checkbox],[type=radio]):not(:first-child),[role=group] select:not(:first-child),[role=group]>:not(:first-child),[role=search] input:not([type=checkbox],[type=radio]):not(:first-child),[role=search] select:not(:first-child),[role=search]>:not(:first-child){margin-left:0;border-top-left-radius:0;border-bottom-left-radius:0}[role=group] input:not([type=checkbox],[type=radio]):not(:last-child),[role=group] select:not(:last-child),[role=group]>:not(:last-child),[role=search] input:not([type=checkbox],[type=radio]):not(:last-child),[role=search] select:not(:last-child),[role=search]>:not(:last-child){border-top-right-radius:0;border-bottom-right-radius:0}[role=group] input:not([type=checkbox],[type=radio]):focus,[role=group] select:focus,[role=group]>:focus,[role=search] input:not([type=checkbox],[type=radio]):focus,[role=search] select:focus,[role=search]>:focus{z-index:2}[role=group] [role=button]:not(:first-child),[role=group] [type=button]:not(:first-child),[role=group] [type=reset]:not(:first-child),[role=group] [type=submit]:not(:first-child),[role=group] button:not(:first-child),[role=group] input:not([type=checkbox],[type=radio]):not(:first-child),[role=group] select:not(:first-child),[role=search] [role=button]:not(:first-child),[role=search] [type=button]:not(:first-child),[role=search] [type=reset]:not(:first-child),[role=search] [type=submit]:not(:first-child),[role=search] button:not(:first-child),[role=search] input:not([type=checkbox],[type=radio]):not(:first-child),[role=search] select:not(:first-child){margin-left:calc(var(--pico-border-width) * -1)}[role=group] [role=button],[role=group] [type=button],[role=group] [type=reset],[role=group] [type=submit],[role=group] button,[role=search] [role=button],[role=search] [type=button],[role=search] [type=reset],[role=search] [type=submit],[role=search] button{width:auto}@supports selector(:has(*)){[role=group]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus),[role=search]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus){--pico-group-box-shadow:var(--pico-group-box-shadow-focus-with-button)}[role=group]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus) input:not([type=checkbox],[type=radio]),[role=group]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus) select,[role=search]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus) input:not([type=checkbox],[type=radio]),[role=search]:has(button:focus,[type=submit]:focus,[type=button]:focus,[role=button]:focus) select{border-color:transparent}[role=group]:has(input:not([type=submit],[type=button]):focus,select:focus),[role=search]:has(input:not([type=submit],[type=button]):focus,select:focus){--pico-group-box-shadow:var(--pico-group-box-shadow-focus-with-input)}[role=group]:has(input:not([type=submit],[type=button]):focus,select:focus) [role=button],[role=group]:has(input:not([type=submit],[type=button]):focus,select:focus) [type=button],[role=group]:has(input:not([type=submit],[type=button]):focus,select:focus) [type=submit],[role=group]:has(input:not([type=submit],[type=button]):focus,select:focus) button,[role=search]:has(input:not([type=submit],[type=button]):focus,select:focus) [role=button],[role=search]:has(input:not([type=submit],[type=button]):focus,select:focus) [type=button],[role=search]:has(input:not([type=submit],[type=button]):focus,select:focus) [type=submit],[role=search]:has(input:not([type=submit],[type=button]):focus,select:focus) button{--pico-button-box-shadow:0 0 0 var(--pico-border-width) var(--pico-primary-border);--pico-button-hover-box-shadow:0 0 0 var(--pico-border-width) var(--pico-primary-hover-border)}[role=group] [role=button]:focus,[role=group] [type=button]:focus,[role=group] [type=reset]:focus,[role=group] [type=submit]:focus,[role=group] button:focus,[role=search] [role=button]:focus,[role=search] [type=button]:focus,[role=search] [type=reset]:focus,[role=search] [type=submit]:focus,[role=search] button:focus{box-shadow:none}}[role=search]>:first-child{border-top-left-radius:5rem;border-bottom-left-radius:5rem}[role=search]>:last-child{border-top-right-radius:5rem;border-bottom-right-radius:5rem}[aria-busy=true]:not(input,select,textarea,html){white-space:nowrap}[aria-busy=true]:not(input,select,textarea,html)::before{display:inline-block;width:1em;height:1em;background-image:var(--pico-icon-loading);background-size:1em auto;background-repeat:no-repeat;content:"";vertical-align:-.125em}[aria-busy=true]:not(input,select,textarea,html):not(:empty)::before{margin-inline-end:calc(var(--pico-spacing) * .5)}[aria-busy=true]:not(input,select,textarea,html):empty{text-align:center}[role=button][aria-busy=true],[type=button][aria-busy=true],[type=reset][aria-busy=true],[type=submit][aria-busy=true],a[aria-busy=true],button[aria-busy=true]{pointer-events:none}:root{--pico-scrollbar-width:0px}dialog{display:flex;z-index:999;position:fixed;top:0;right:0;bottom:0;left:0;align-items:center;justify-content:center;width:inherit;min-width:100%;height:inherit;min-height:100%;padding:0;border:0;-webkit-backdrop-filter:var(--pico-modal-overlay-backdrop-filter);backdrop-filter:var(--pico-modal-overlay-backdrop-filter);background-color:var(--pico-modal-overlay-background-color);color:var(--pico-color)}dialog article{width:100%;max-height:calc(100vh - var(--pico-spacing) * 2);margin:var(--pico-spacing);overflow:auto}@media (min-width:576px){dialog article{max-width:510px}}@media (min-width:768px){dialog article{max-width:700px}}dialog article>header>*{margin-bottom:0}dialog article>header .close,dialog article>header :is(a,button)[rel=prev]{margin:0;margin-left:var(--pico-spacing);padding:0;float:right}dialog article>footer{text-align:right}dialog article>footer [role=button],dialog article>footer button{margin-bottom:0}dialog article>footer [role=button]:not(:first-of-type),dialog article>footer button:not(:first-of-type){margin-left:calc(var(--pico-spacing) * .5)}dialog article .close,dialog article :is(a,button)[rel=prev]{display:block;width:1rem;height:1rem;margin-top:calc(var(--pico-spacing) * -1);margin-bottom:var(--pico-spacing);margin-left:auto;border:none;background-image:var(--pico-icon-close);background-position:center;background-size:auto 1rem;background-repeat:no-repeat;background-color:transparent;opacity:.5;transition:opacity var(--pico-transition)}dialog article .close:is([aria-current]:not([aria-current=false]),:hover,:active,:focus),dialog article :is(a,button)[rel=prev]:is([aria-current]:not([aria-current=false]),:hover,:active,:focus){opacity:1}dialog:not([open]),dialog[open=false]{display:none}.modal-is-open{padding-right:var(--pico-scrollbar-width,0);overflow:hidden;pointer-events:none;touch-action:none}.modal-is-open dialog{pointer-events:auto;touch-action:auto}:where(.modal-is-opening,.modal-is-closing) dialog,:where(.modal-is-opening,.modal-is-closing) dialog>article{animation-duration:.2s;animation-timing-function:ease-in-out;animation-fill-mode:both}:where(.modal-is-opening,.modal-is-closing) dialog{animation-duration:.8s;animation-name:modal-overlay}:where(.modal-is-opening,.modal-is-closing) dialog>article{animation-delay:.2s;animation-name:modal}.modal-is-closing dialog,.modal-is-closing dialog>article{animation-delay:0s;animation-direction:reverse}@keyframes modal-overlay{from{-webkit-backdrop-filter:none;backdrop-filter:none;background-color:transparent}}@keyframes modal{from{transform:translateY(-100%);opacity:0}}:where(nav li)::before{float:left;content:"​"}nav,nav ul{display:flex}nav{justify-content:space-between;overflow:visible}nav ol,nav ul{align-items:center;margin-bottom:0;padding:0;list-style:none}nav ol:first-of-type,nav ul:first-of-type{margin-left:calc(var(--pico-nav-element-spacing-horizontal) * -1)}nav ol:last-of-type,nav ul:last-of-type{margin-right:calc(var(--pico-nav-element-spacing-horizontal) * -1)}nav li{display:inline-block;margin:0;padding:var(--pico-nav-element-spacing-vertical) var(--pico-nav-element-spacing-horizontal)}nav li :where(a,[role=link]){display:inline-block;margin:calc(var(--pico-nav-link-spacing-vertical) * -1) calc(var(--pico-nav-link-spacing-horizontal) * -1);padding:var(--pico-nav-link-spacing-vertical) var(--pico-nav-link-spacing-horizontal);border-radius:var(--pico-border-radius)}nav li :where(a,[role=link]):not(:hover){text-decoration:none}nav li [role=button],nav li [type=button],nav li button,nav li input:not([type=checkbox],[type=radio],[type=range],[type=file]),nav li select{height:auto;margin-right:inherit;margin-bottom:0;margin-left:inherit;padding:calc(var(--pico-nav-link-spacing-vertical) - var(--pico-border-width) * 2) var(--pico-nav-link-spacing-horizontal)}nav[aria-label=breadcrumb]{align-items:center;justify-content:start}nav[aria-label=breadcrumb] ul li:not(:first-child){margin-inline-start:var(--pico-nav-link-spacing-horizontal)}nav[aria-label=breadcrumb] ul li a{margin:calc(var(--pico-nav-link-spacing-vertical) * -1) 0;margin-inline-start:calc(var(--pico-nav-link-spacing-horizontal) * -1)}nav[aria-label=breadcrumb] ul li:not(:last-child)::after{display:inline-block;position:absolute;width:calc(var(--pico-nav-link-spacing-horizontal) * 4);margin:0 calc(var(--pico-nav-link-spacing-horizontal) * -1);content:var(--pico-nav-breadcrumb-divider);color:var(--pico-muted-color);text-align:center;text-decoration:none;white-space:nowrap}nav[aria-label=breadcrumb] a[aria-current]:not([aria-current=false]){background-color:transparent;color:inherit;text-decoration:none;pointer-events:none}aside li,aside nav,aside ol,aside ul{display:block}aside li{padding:calc(var(--pico-nav-element-spacing-vertical) * .5) var(--pico-nav-element-spacing-horizontal)}aside li a{display:block}aside li [role=button]{margin:inherit}[dir=rtl] nav[aria-label=breadcrumb] ul li:not(:last-child) ::after{content:"\\"}progress{display:inline-block;vertical-align:baseline}progress{-webkit-appearance:none;-moz-appearance:none;display:inline-block;appearance:none;width:100%;height:.5rem;margin-bottom:calc(var(--pico-spacing) * .5);overflow:hidden;border:0;border-radius:var(--pico-border-radius);background-color:var(--pico-progress-background-color);color:var(--pico-progress-color)}progress::-webkit-progress-bar{border-radius:var(--pico-border-radius);background:0 0}progress[value]::-webkit-progress-value{background-color:var(--pico-progress-color);-webkit-transition:inline-size var(--pico-transition);transition:inline-size var(--pico-transition)}progress::-moz-progress-bar{background-color:var(--pico-progress-color)}@media (prefers-reduced-motion:no-preference){progress:indeterminate{background:var(--pico-progress-background-color) linear-gradient(to right,var(--pico-progress-color) 30%,var(--pico-progress-background-color) 30%) top left/150% 150% no-repeat;animation:progress-indeterminate 1s linear infinite}progress:indeterminate[value]::-webkit-progress-value{background-color:transparent}progress:indeterminate::-moz-progress-bar{background-color:transparent}}@media (prefers-reduced-motion:no-preference){[dir=rtl] progress:indeterminate{animation-direction:reverse}}@keyframes progress-indeterminate{0%{background-position:200% 0}100%{background-position:-200% 0}}[data-tooltip]{position:relative}[data-tooltip]:not(a,button,input){border-bottom:1px dotted;text-decoration:none;cursor:help}[data-tooltip]::after,[data-tooltip]::before,[data-tooltip][data-placement=top]::after,[data-tooltip][data-placement=top]::before{display:block;z-index:99;position:absolute;bottom:100%;left:50%;padding:.25rem .5rem;overflow:hidden;transform:translate(-50%,-.25rem);border-radius:var(--pico-border-radius);background:var(--pico-tooltip-background-color);content:attr(data-tooltip);color:var(--pico-tooltip-color);font-style:normal;font-weight:var(--pico-font-weight);font-size:.875rem;text-decoration:none;text-overflow:ellipsis;white-space:nowrap;opacity:0;pointer-events:none}[data-tooltip]::after,[data-tooltip][data-placement=top]::after{padding:0;transform:translate(-50%,0);border-top:.3rem solid;border-right:.3rem solid transparent;border-left:.3rem solid transparent;border-radius:0;background-color:transparent;content:"";color:var(--pico-tooltip-background-color)}[data-tooltip][data-placement=bottom]::after,[data-tooltip][data-placement=bottom]::before{top:100%;bottom:auto;transform:translate(-50%,.25rem)}[data-tooltip][data-placement=bottom]:after{transform:translate(-50%,-.3rem);border:.3rem solid transparent;border-bottom:.3rem solid}[data-tooltip][data-placement=left]::after,[data-tooltip][data-placement=left]::before{top:50%;right:100%;bottom:auto;left:auto;transform:translate(-.25rem,-50%)}[data-tooltip][data-placement=left]:after{transform:translate(.3rem,-50%);border:.3rem solid transparent;border-left:.3rem solid}[data-tooltip][data-placement=right]::after,[data-tooltip][data-placement=right]::before{top:50%;right:auto;bottom:auto;left:100%;transform:translate(.25rem,-50%)}[data-tooltip][data-placement=right]:after{transform:translate(-.3rem,-50%);border:.3rem solid transparent;border-right:.3rem solid}[data-tooltip]:focus::after,[data-tooltip]:focus::before,[data-tooltip]:hover::after,[data-tooltip]:hover::before{opacity:1}@media (hover:hover) and (pointer:fine){[data-tooltip]:focus::after,[data-tooltip]:focus::before,[data-tooltip]:hover::after,[data-tooltip]:hover::before{--pico-tooltip-slide-to:translate(-50%, -0.25rem);transform:translate(-50%,.75rem);animation-duration:.2s;animation-fill-mode:forwards;animation-name:tooltip-slide;opacity:0}[data-tooltip]:focus::after,[data-tooltip]:hover::after{--pico-tooltip-caret-slide-to:translate(-50%, 0rem);transform:translate(-50%,-.25rem);animation-name:tooltip-caret-slide}[data-tooltip][data-placement=bottom]:focus::after,[data-tooltip][data-placement=bottom]:focus::before,[data-tooltip][data-placement=bottom]:hover::after,[data-tooltip][data-placement=bottom]:hover::before{--pico-tooltip-slide-to:translate(-50%, 0.25rem);transform:translate(-50%,-.75rem);animation-name:tooltip-slide}[data-tooltip][data-placement=bottom]:focus::after,[data-tooltip][data-placement=bottom]:hover::after{--pico-tooltip-caret-slide-to:translate(-50%, -0.3rem);transform:translate(-50%,-.5rem);animation-name:tooltip-caret-slide}[data-tooltip][data-placement=left]:focus::after,[data-tooltip][data-placement=left]:focus::before,[data-tooltip][data-placement=left]:hover::after,[data-tooltip][data-placement=left]:hover::before{--pico-tooltip-slide-to:translate(-0.25rem, -50%);transform:translate(.75rem,-50%);animation-name:tooltip-slide}[data-tooltip][data-placement=left]:focus::after,[data-tooltip][data-placement=left]:hover::after{--pico-tooltip-caret-slide-to:translate(0.3rem, -50%);transform:translate(.05rem,-50%);animation-name:tooltip-caret-slide}[data-tooltip][data-placement=right]:focus::after,[data-tooltip][data-placement=right]:focus::before,[data-tooltip][data-placement=right]:hover::after,[data-tooltip][data-placement=right]:hover::before{--pico-tooltip-slide-to:translate(0.25rem, -50%);transform:translate(-.75rem,-50%);animation-name:tooltip-slide}[data-tooltip][data-placement=right]:focus::after,[data-tooltip][data-placement=right]:hover::after{--pico-tooltip-caret-slide-to:translate(-0.3rem, -50%);transform:translate(-.05rem,-50%);animation-name:tooltip-caret-slide}}@keyframes tooltip-slide{to{transform:var(--pico-tooltip-slide-to);opacity:1}}@keyframes tooltip-caret-slide{50%{opacity:0}to{transform:var(--pico-tooltip-caret-slide-to);opacity:1}}[aria-controls]{cursor:pointer}[aria-disabled=true],[disabled]{cursor:not-allowed}[aria-hidden=false][hidden]{display:initial}[aria-hidden=false][hidden]:not(:focus){clip:rect(0,0,0,0);position:absolute}[tabindex],a,area,button,input,label,select,summary,textarea{-ms-touch-action:manipulation}[dir=rtl]{direction:rtl}@media (prefers-reduced-motion:reduce){:not([aria-busy=true]),:not([aria-busy=true])::after,:not([aria-busy=true])::before{background-attachment:initial!important;animation-duration:1ms!important;animation-delay:-1ms!important;animation-iteration-count:1!important;scroll-behavior:auto!important;transition-delay:0s!important;transition-duration:0s!important}} -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Routes.swift: -------------------------------------------------------------------------------- 1 | import AsyncAlgorithms 2 | import Elementary 3 | import ElementaryHTMX 4 | import Foundation 5 | import Hummingbird 6 | import HummingbirdElementary 7 | import HummingbirdWebSocket 8 | import NIOWebSocket 9 | 10 | func addRoutes(to router: Router) { 11 | router.get("") { _, _ in 12 | HTMLResponse { 13 | MainPage() 14 | } 15 | } 16 | 17 | router.get("/time") { _, _ in 18 | Response( 19 | status: .ok, 20 | headers: [.contentType: "text/event-stream"], 21 | body: .init { writer in 22 | for await _ in AsyncTimerSequence.repeating(every: .seconds(1)).cancelOnGracefulShutdown() { 23 | try await writer.writeSSE(html: TimeHeading()) 24 | } 25 | try await writer.finish(nil) 26 | } 27 | ) 28 | } 29 | 30 | router.post("/items") { request, context in 31 | let body = try await request.decode(as: AddItemRequest.self, context: context) 32 | await Database.shared.addItem(body.item) 33 | 34 | return HTMLResponse { 35 | ItemList() 36 | } 37 | } 38 | 39 | router.delete("items/{index}") { _, context in 40 | guard let index = context.parameters.get("index", as: Int.self) else { 41 | throw HTTPError(.badRequest) 42 | } 43 | 44 | let wasRemoved = await Database.shared.removeItem(at: index) 45 | 46 | guard wasRemoved else { 47 | throw HTTPError(.notFound) 48 | } 49 | 50 | return HTMLResponse { 51 | // exmple of using OOB swaps 52 | ItemList() 53 | .attributes(.hx.swapOOB(.outerHTML, "#list")) 54 | } 55 | } 56 | } 57 | 58 | struct AddItemRequest: Decodable { 59 | var item: String 60 | } 61 | 62 | func addWSRoutes(to router: Router) { 63 | router.ws("echo") { _, _ in 64 | .upgrade([:]) 65 | } onUpgrade: { inbound, outbound, _ in 66 | for try await input in inbound.messages(maxSize: 1_000_000) { 67 | guard case let .text(text) = input else { continue } 68 | let echoRequest = try JSONDecoder().decode(EchoRequest.self, from: text.data(using: .utf8)!) 69 | try await outbound.write(.text(WSResponse(echoRequest: echoRequest).render())) 70 | } 71 | } 72 | } 73 | 74 | struct EchoRequest: Codable { 75 | var message: String 76 | var headers: HTMXHeaders 77 | 78 | enum CodingKeys: String, CodingKey { 79 | case message 80 | case headers = "HEADERS" 81 | } 82 | } 83 | 84 | struct HTMXHeaders: Codable { 85 | var hxRequest: String 86 | var hxTrigger: String? 87 | var hxTriggerName: String? 88 | var hxTarget: String 89 | var hxCurrentURL: String? 90 | 91 | enum CodingKeys: String, CodingKey { 92 | case hxRequest = "HX-Request" 93 | case hxTrigger = "HX-Trigger" 94 | case hxTriggerName = "HX-Trigger-Name" 95 | case hxTarget = "HX-Target" 96 | case hxCurrentURL = "HX-Current-URL" 97 | } 98 | } 99 | 100 | extension ResponseBodyWriter { 101 | mutating func writeSSE(event: String? = nil, html: some HTML) async throws { 102 | if let event { 103 | try await write(ByteBuffer(string: "event: \(event)\n")) 104 | } 105 | try await write(ByteBuffer(string: "data: ")) 106 | try await writeHTML(html) 107 | try await write(ByteBuffer(string: "\n\n")) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/Sources/App/Views.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMXSSE 3 | import ElementaryHTMXWS 4 | import Foundation 5 | 6 | struct MainPage: HTMLDocument { 7 | var title: String { "Hummingbird + Elementary + HTMX" } 8 | 9 | var head: some HTML { 10 | meta(.charset(.utf8)) 11 | script(.src("/htmx.min.js")) {} 12 | script(.src("/htmxsse.min.js")) {} 13 | script(.src("/htmxws.min.js")) {} 14 | link(.href("/pico.min.css"), .rel(.stylesheet)) 15 | } 16 | 17 | var body: some HTML { 18 | header(.class("container")) { 19 | h2 { "Hummingbird + Elementary + HTMX Demo" } 20 | // example of using htmx sse 21 | h6 { "HTMX SSE example" } 22 | div(.hx.ext(.sse), .sse.connect("/time"), .sse.swap("message")) { 23 | TimeHeading() 24 | } 25 | } 26 | main(.class("container")) { 27 | h6 { "HTMX Post/Delete example" } 28 | div { 29 | // example of using hx-target and hx-swap 30 | form(.hx.post("/items"), .hx.target("#list"), .hx.swap(.outerHTML)) { 31 | div(.class("grid")) { 32 | input(.type(.text), .name("item"), .value("New Item"), .required) 33 | input(.type(.submit), .value("Add Item")) 34 | } 35 | } 36 | ItemList() 37 | } 38 | hr() 39 | h6 { "HTMX WS example" } 40 | // example of using htmx ws 41 | div(.hx.ext(.ws), .ws.connect("/echo"), .hx.target("#echo")) { 42 | form(.ws.send, .style("display: flex;")) { 43 | input(.type(.text), .name("message"), .value("Hello, World!"), .required) 44 | button(.class("btn btn-primary"), .style("height: 100%; margin-left: 1rem;")) { "Send" } 45 | } 46 | div(.id("echo")) {} 47 | } 48 | } 49 | } 50 | } 51 | 52 | struct ItemList: HTML { 53 | @Environment(EnvironmentValues.$database) var database 54 | 55 | var content: some HTML { 56 | div(.id("list")) { 57 | let items = await database.model.items 58 | 59 | h4 { "Items" } 60 | p { "Count: \(items.count)" } 61 | 62 | ForEach(items.enumerated()) { index, item in 63 | div { 64 | // this hx-delete will use OOB swap 65 | button(.hx.delete("items/\(index)")) { "X" } 66 | " " 67 | item 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | struct TimeHeading: HTML { 75 | var content: some HTML { 76 | h4 { 77 | "Server Time: \(Date())" 78 | } 79 | } 80 | } 81 | 82 | enum EnvironmentValues { 83 | @TaskLocal static var database: Database = .shared 84 | } 85 | 86 | struct WSResponse: HTML { 87 | var echoRequest: EchoRequest 88 | 89 | var content: some HTML { 90 | div(.id(echoRequest.headers.hxTarget), .hx.swapOOB(.beforeEnd, "#\(echoRequest.headers.hxTarget)")) { 91 | "Received: \(echoRequest.message) at \(Date())" 92 | br() 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Examples/HummingbirdDemo/swift-dev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | touch .build/browser-dev-sync 3 | browser-sync start -p localhost:8080 --ws & 4 | 5 | watchexec -w Sources -e .swift -r 'swift build --product App && touch .build/browser-dev-sync' & 6 | watchexec -w .build/browser-dev-sync --ignore-nothing -r '.build/debug/App' 7 | -------------------------------------------------------------------------------- /Examples/VaporDemo/.gitignore: -------------------------------------------------------------------------------- 1 | /.build 2 | xcuserdata/ 3 | DerivedData/ 4 | .vscode 5 | Package.resolved -------------------------------------------------------------------------------- /Examples/VaporDemo/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "HummingbirdDemo", 6 | platforms: [ 7 | .macOS(.v14), 8 | ], 9 | products: [ 10 | .executable(name: "App", targets: ["App"]), 11 | ], 12 | dependencies: [ 13 | .package(url: "https://github.com/vapor/vapor", from: "4.102.0"), 14 | .package(url: "https://github.com/vapor-community/vapor-elementary.git", from: "0.2.0"), 15 | .package(path: "../../"), 16 | .package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"), 17 | ], 18 | targets: [ 19 | .executableTarget( 20 | name: "App", 21 | dependencies: [ 22 | .product(name: "Vapor", package: "vapor"), 23 | .product(name: "VaporElementary", package: "vapor-elementary"), 24 | .product(name: "ElementaryHTMX", package: "elementary-htmx"), 25 | .product(name: "ElementaryHTMXSSE", package: "elementary-htmx"), 26 | .product(name: "ElementaryHTMXWS", package: "elementary-htmx"), 27 | .product(name: "AsyncAlgorithms", package: "swift-async-algorithms"), 28 | ], 29 | resources: [ 30 | .copy("Public"), 31 | ], 32 | swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")] 33 | ), 34 | ] 35 | ) 36 | -------------------------------------------------------------------------------- /Examples/VaporDemo/README.md: -------------------------------------------------------------------------------- 1 | # ElementaryHTMX + Vapor Demo 2 | 3 | ## Running the example 4 | 5 | Run the app and open http://localhost:8080 in the browser 6 | 7 | ```sh 8 | swift run App 9 | ``` 10 | 11 | ## Dev mode with auto-reload on save 12 | 13 | The `swift-dev` script auto-reloads open browser tabs on source file changes. 14 | 15 | It is using [watchexec](https://github.com/watchexec/watchexec) and [browsersync](https://browsersync.io/). 16 | 17 | ### Install required tools 18 | 19 | Use homebrew and npm to install the following (tested on macOS): 20 | 21 | ```sh 22 | npm install -g browser-sync 23 | brew install watchexec 24 | ``` 25 | 26 | ### Run app in watch-mode 27 | 28 | This will watch all swift files in the demo package, build on-demand, and re-sync the browser page 29 | 30 | ```sh 31 | ./swift-dev 32 | ``` 33 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/App.swift: -------------------------------------------------------------------------------- 1 | import Vapor 2 | 3 | @main 4 | struct App { 5 | static func main() async throws { 6 | let app = try await Application.make() 7 | try app.middleware.use(FileMiddleware(bundle: .module)) 8 | 9 | addRoutes(to: app) 10 | 11 | #if DEBUG 12 | app.lifecycle.use(BrowserSyncHandler()) 13 | #endif 14 | 15 | try await app.execute() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/BonusFacts.swift: -------------------------------------------------------------------------------- 1 | actor BonusFactStore { 2 | // courtesy of chatchipitty 3 | let bonusFacts = [ 4 | "Writing code is 10% typing and 90% figuring out why you typed it that way in the first place.", 5 | "The hardest part of programming isn't coding — it's naming variables without sounding ridiculous.", 6 | "If code comments are the breadcrumbs, then debugging is following a very messy trail of pizza crumbs.", 7 | "Optionals in Swift are a nice way of saying, 'Yeah, I have no idea what might happen here.'", 8 | "You can fix 99% of your bugs by turning it off and back on. The other 1%? Crying helps.", 9 | "Programmers don't sleep. They just enter a low-power mode with their eyes open.", 10 | "In the world of code, everything is either a `true`, `false`, or 'maybe, if you handle this optional safely.'", 11 | "Any code that hasn't been touched in more than six months is officially considered 'legacy code.'", 12 | ] 13 | 14 | func calculateBonusFact() async -> String { 15 | return bonusFacts.randomElement()! 16 | } 17 | 18 | @TaskLocal static var current: BonusFactStore? 19 | } 20 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/BrowserSync.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Vapor 3 | 4 | #if DEBUG 5 | struct BrowserSyncHandler: LifecycleHandler { 6 | func didBoot(_: Application) throws { 7 | let p = Process() 8 | p.executableURL = URL(string: "file:///bin/sh") 9 | p.arguments = ["-c", "browser-sync reload"] 10 | do { 11 | try p.run() 12 | } catch { 13 | print("Could not auto-reload: \(error)") 14 | } 15 | } 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/Public/htmxsse.min.js: -------------------------------------------------------------------------------- 1 | !(function () { 2 | var e; 3 | function t(e) { 4 | return new EventSource(e, { withCredentials: !0 }); 5 | } 6 | function n(t) { 7 | if (!e.bodyContains(t)) { 8 | var n = e.getInternalData(t).sseEventSource; 9 | if (null != n) return n.close(), !0; 10 | } 11 | return !1; 12 | } 13 | function r(t, n) { 14 | var r = []; 15 | return ( 16 | e.hasAttribute(t, n) && r.push(t), 17 | t.querySelectorAll('[' + n + '], [data-' + n + ']').forEach(function (e) { 18 | r.push(e); 19 | }), 20 | r 21 | ); 22 | } 23 | function s(t, n) { 24 | e.withExtensions(t, function (e) { 25 | n = e.transformResponse(n, null, t); 26 | }); 27 | var r = e.getSwapSpecification(t), 28 | s = e.getTarget(t); 29 | e.swap(s, n, r); 30 | } 31 | function a(t) { 32 | return null != e.getInternalData(t).sseEventSource; 33 | } 34 | htmx.defineExtension('sse', { 35 | init: function (n) { 36 | (e = n), null == htmx.createEventSource && (htmx.createEventSource = t); 37 | }, 38 | onEvent: function (t, o) { 39 | var i = o.target || o.detail.elt; 40 | switch (t) { 41 | case 'htmx:beforeCleanupElement': 42 | var u = e.getInternalData(i); 43 | return void (u.sseEventSource && u.sseEventSource.close()); 44 | case 'htmx:afterProcessNode': 45 | !(function t(o, i) { 46 | var u; 47 | if (null == o) return null; 48 | r(o, 'sse-connect').forEach(function (r) { 49 | var s, 50 | a, 51 | o, 52 | u, 53 | c = e.getAttributeValue(r, 'sse-connect'); 54 | null != c && 55 | ((s = r), 56 | (a = c), 57 | (o = i), 58 | ((u = htmx.createEventSource(a)).onerror = function (r) { 59 | if ( 60 | (e.triggerErrorEvent(s, 'htmx:sseError', { 61 | error: r, 62 | source: u, 63 | }), 64 | !n(s) && u.readyState === EventSource.CLOSED) 65 | ) { 66 | var a = Math.random() * (2 ^ (o = o || 0)) * 500; 67 | window.setTimeout(function () { 68 | t(s, Math.min(7, o + 1)); 69 | }, a); 70 | } 71 | }), 72 | (u.onopen = function (t) { 73 | e.triggerEvent(s, 'htmx:sseOpen', { source: u }); 74 | }), 75 | (e.getInternalData(s).sseEventSource = u)); 76 | }), 77 | r((u = o), 'sse-swap').forEach(function (t) { 78 | var r = e.getClosestMatch(t, a); 79 | if (null == r) return null; 80 | for ( 81 | var o = e.getInternalData(r).sseEventSource, 82 | i = e.getAttributeValue(t, 'sse-swap').split(','), 83 | c = 0; 84 | c < i.length; 85 | c++ 86 | ) { 87 | var l = i[c].trim(), 88 | v = function (a) { 89 | if (!n(r)) { 90 | if (!e.bodyContains(t)) 91 | return void o.removeEventListener(l, v); 92 | e.triggerEvent(u, 'htmx:sseBeforeMessage', a) && 93 | (s(t, a.data), 94 | e.triggerEvent(u, 'htmx:sseMessage', a)); 95 | } 96 | }; 97 | (e.getInternalData(t).sseEventListener = v), 98 | o.addEventListener(l, v); 99 | } 100 | }), 101 | r(u, 'hx-trigger').forEach(function (t) { 102 | var r = e.getClosestMatch(t, a); 103 | if (null == r) return null; 104 | var s = e.getInternalData(r).sseEventSource, 105 | o = e.getAttributeValue(t, 'hx-trigger'); 106 | if (null != o && 'sse:' == o.slice(0, 4)) { 107 | var i = function (a) { 108 | !n(r) && 109 | (e.bodyContains(t) || s.removeEventListener(o, i), 110 | htmx.trigger(t, o, a), 111 | htmx.trigger(t, 'htmx:sseMessage', a)); 112 | }; 113 | (e.getInternalData(u).sseEventListener = i), 114 | s.addEventListener(o.slice(4), i); 115 | } 116 | }); 117 | })(i); 118 | } 119 | }, 120 | }); 121 | })(); 122 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/Public/htmxws.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | WebSockets Extension 3 | ============================ 4 | This extension adds support for WebSockets to htmx. See /www/extensions/ws.md for usage instructions. 5 | */ 6 | 7 | (function() { 8 | /** @type {import("../htmx").HtmxInternalApi} */ 9 | var api 10 | 11 | htmx.defineExtension('ws', { 12 | 13 | /** 14 | * init is called once, when this extension is first registered. 15 | * @param {import("../htmx").HtmxInternalApi} apiRef 16 | */ 17 | init: function(apiRef) { 18 | // Store reference to internal API 19 | api = apiRef 20 | 21 | // Default function for creating new EventSource objects 22 | if (!htmx.createWebSocket) { 23 | htmx.createWebSocket = createWebSocket 24 | } 25 | 26 | // Default setting for reconnect delay 27 | if (!htmx.config.wsReconnectDelay) { 28 | htmx.config.wsReconnectDelay = 'full-jitter' 29 | } 30 | }, 31 | 32 | /** 33 | * onEvent handles all events passed to this extension. 34 | * 35 | * @param {string} name 36 | * @param {Event} evt 37 | */ 38 | onEvent: function(name, evt) { 39 | var parent = evt.target || evt.detail.elt 40 | switch (name) { 41 | // Try to close the socket when elements are removed 42 | case 'htmx:beforeCleanupElement': 43 | 44 | var internalData = api.getInternalData(parent) 45 | 46 | if (internalData.webSocket) { 47 | internalData.webSocket.close() 48 | } 49 | return 50 | 51 | // Try to create websockets when elements are processed 52 | case 'htmx:beforeProcessNode': 53 | 54 | forEach(queryAttributeOnThisOrChildren(parent, 'ws-connect'), function(child) { 55 | ensureWebSocket(child) 56 | }) 57 | forEach(queryAttributeOnThisOrChildren(parent, 'ws-send'), function(child) { 58 | ensureWebSocketSend(child) 59 | }) 60 | } 61 | } 62 | }) 63 | 64 | function splitOnWhitespace(trigger) { 65 | return trigger.trim().split(/\s+/) 66 | } 67 | 68 | function getLegacyWebsocketURL(elt) { 69 | var legacySSEValue = api.getAttributeValue(elt, 'hx-ws') 70 | if (legacySSEValue) { 71 | var values = splitOnWhitespace(legacySSEValue) 72 | for (var i = 0; i < values.length; i++) { 73 | var value = values[i].split(/:(.+)/) 74 | if (value[0] === 'connect') { 75 | return value[1] 76 | } 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * ensureWebSocket creates a new WebSocket on the designated element, using 83 | * the element's "ws-connect" attribute. 84 | * @param {HTMLElement} socketElt 85 | * @returns 86 | */ 87 | function ensureWebSocket(socketElt) { 88 | // If the element containing the WebSocket connection no longer exists, then 89 | // do not connect/reconnect the WebSocket. 90 | if (!api.bodyContains(socketElt)) { 91 | return 92 | } 93 | 94 | // Get the source straight from the element's value 95 | var wssSource = api.getAttributeValue(socketElt, 'ws-connect') 96 | 97 | if (wssSource == null || wssSource === '') { 98 | var legacySource = getLegacyWebsocketURL(socketElt) 99 | if (legacySource == null) { 100 | return 101 | } else { 102 | wssSource = legacySource 103 | } 104 | } 105 | 106 | // Guarantee that the wssSource value is a fully qualified URL 107 | if (wssSource.indexOf('/') === 0) { 108 | var base_part = location.hostname + (location.port ? ':' + location.port : '') 109 | if (location.protocol === 'https:') { 110 | wssSource = 'wss://' + base_part + wssSource 111 | } else if (location.protocol === 'http:') { 112 | wssSource = 'ws://' + base_part + wssSource 113 | } 114 | } 115 | 116 | var socketWrapper = createWebsocketWrapper(socketElt, function() { 117 | return htmx.createWebSocket(wssSource) 118 | }) 119 | 120 | socketWrapper.addEventListener('message', function(event) { 121 | if (maybeCloseWebSocketSource(socketElt)) { 122 | return 123 | } 124 | 125 | var response = event.data 126 | if (!api.triggerEvent(socketElt, 'htmx:wsBeforeMessage', { 127 | message: response, 128 | socketWrapper: socketWrapper.publicInterface 129 | })) { 130 | return 131 | } 132 | 133 | api.withExtensions(socketElt, function(extension) { 134 | response = extension.transformResponse(response, null, socketElt) 135 | }) 136 | 137 | var settleInfo = api.makeSettleInfo(socketElt) 138 | var fragment = api.makeFragment(response) 139 | 140 | if (fragment.children.length) { 141 | var children = Array.from(fragment.children) 142 | for (var i = 0; i < children.length; i++) { 143 | api.oobSwap(api.getAttributeValue(children[i], 'hx-swap-oob') || 'true', children[i], settleInfo) 144 | } 145 | } 146 | 147 | api.settleImmediately(settleInfo.tasks) 148 | api.triggerEvent(socketElt, 'htmx:wsAfterMessage', { message: response, socketWrapper: socketWrapper.publicInterface }) 149 | }) 150 | 151 | // Put the WebSocket into the HTML Element's custom data. 152 | api.getInternalData(socketElt).webSocket = socketWrapper 153 | } 154 | 155 | /** 156 | * @typedef {Object} WebSocketWrapper 157 | * @property {WebSocket} socket 158 | * @property {Array<{message: string, sendElt: Element}>} messageQueue 159 | * @property {number} retryCount 160 | * @property {(message: string, sendElt: Element) => void} sendImmediately sendImmediately sends message regardless of websocket connection state 161 | * @property {(message: string, sendElt: Element) => void} send 162 | * @property {(event: string, handler: Function) => void} addEventListener 163 | * @property {() => void} handleQueuedMessages 164 | * @property {() => void} init 165 | * @property {() => void} close 166 | */ 167 | /** 168 | * 169 | * @param socketElt 170 | * @param socketFunc 171 | * @returns {WebSocketWrapper} 172 | */ 173 | function createWebsocketWrapper(socketElt, socketFunc) { 174 | var wrapper = { 175 | socket: null, 176 | messageQueue: [], 177 | retryCount: 0, 178 | 179 | /** @type {Object} */ 180 | events: {}, 181 | 182 | addEventListener: function(event, handler) { 183 | if (this.socket) { 184 | this.socket.addEventListener(event, handler) 185 | } 186 | 187 | if (!this.events[event]) { 188 | this.events[event] = [] 189 | } 190 | 191 | this.events[event].push(handler) 192 | }, 193 | 194 | sendImmediately: function(message, sendElt) { 195 | if (!this.socket) { 196 | api.triggerErrorEvent() 197 | } 198 | if (!sendElt || api.triggerEvent(sendElt, 'htmx:wsBeforeSend', { 199 | message, 200 | socketWrapper: this.publicInterface 201 | })) { 202 | this.socket.send(message) 203 | sendElt && api.triggerEvent(sendElt, 'htmx:wsAfterSend', { 204 | message, 205 | socketWrapper: this.publicInterface 206 | }) 207 | } 208 | }, 209 | 210 | send: function(message, sendElt) { 211 | if (this.socket.readyState !== this.socket.OPEN) { 212 | this.messageQueue.push({ message, sendElt }) 213 | } else { 214 | this.sendImmediately(message, sendElt) 215 | } 216 | }, 217 | 218 | handleQueuedMessages: function() { 219 | while (this.messageQueue.length > 0) { 220 | var queuedItem = this.messageQueue[0] 221 | if (this.socket.readyState === this.socket.OPEN) { 222 | this.sendImmediately(queuedItem.message, queuedItem.sendElt) 223 | this.messageQueue.shift() 224 | } else { 225 | break 226 | } 227 | } 228 | }, 229 | 230 | init: function() { 231 | if (this.socket && this.socket.readyState === this.socket.OPEN) { 232 | // Close discarded socket 233 | this.socket.close() 234 | } 235 | 236 | // Create a new WebSocket and event handlers 237 | /** @type {WebSocket} */ 238 | var socket = socketFunc() 239 | 240 | // The event.type detail is added for interface conformance with the 241 | // other two lifecycle events (open and close) so a single handler method 242 | // can handle them polymorphically, if required. 243 | api.triggerEvent(socketElt, 'htmx:wsConnecting', { event: { type: 'connecting' } }) 244 | 245 | this.socket = socket 246 | 247 | socket.onopen = function(e) { 248 | wrapper.retryCount = 0 249 | api.triggerEvent(socketElt, 'htmx:wsOpen', { event: e, socketWrapper: wrapper.publicInterface }) 250 | wrapper.handleQueuedMessages() 251 | } 252 | 253 | socket.onclose = function(e) { 254 | // If socket should not be connected, stop further attempts to establish connection 255 | // If Abnormal Closure/Service Restart/Try Again Later, then set a timer to reconnect after a pause. 256 | if (!maybeCloseWebSocketSource(socketElt) && [1006, 1012, 1013].indexOf(e.code) >= 0) { 257 | var delay = getWebSocketReconnectDelay(wrapper.retryCount) 258 | setTimeout(function() { 259 | wrapper.retryCount += 1 260 | wrapper.init() 261 | }, delay) 262 | } 263 | 264 | // Notify client code that connection has been closed. Client code can inspect `event` field 265 | // to determine whether closure has been valid or abnormal 266 | api.triggerEvent(socketElt, 'htmx:wsClose', { event: e, socketWrapper: wrapper.publicInterface }) 267 | } 268 | 269 | socket.onerror = function(e) { 270 | api.triggerErrorEvent(socketElt, 'htmx:wsError', { error: e, socketWrapper: wrapper }) 271 | maybeCloseWebSocketSource(socketElt) 272 | } 273 | 274 | var events = this.events 275 | Object.keys(events).forEach(function(k) { 276 | events[k].forEach(function(e) { 277 | socket.addEventListener(k, e) 278 | }) 279 | }) 280 | }, 281 | 282 | close: function() { 283 | this.socket.close() 284 | } 285 | } 286 | 287 | wrapper.init() 288 | 289 | wrapper.publicInterface = { 290 | send: wrapper.send.bind(wrapper), 291 | sendImmediately: wrapper.sendImmediately.bind(wrapper), 292 | queue: wrapper.messageQueue 293 | } 294 | 295 | return wrapper 296 | } 297 | 298 | /** 299 | * ensureWebSocketSend attaches trigger handles to elements with 300 | * "ws-send" attribute 301 | * @param {HTMLElement} elt 302 | */ 303 | function ensureWebSocketSend(elt) { 304 | var legacyAttribute = api.getAttributeValue(elt, 'hx-ws') 305 | if (legacyAttribute && legacyAttribute !== 'send') { 306 | return 307 | } 308 | 309 | var webSocketParent = api.getClosestMatch(elt, hasWebSocket) 310 | processWebSocketSend(webSocketParent, elt) 311 | } 312 | 313 | /** 314 | * hasWebSocket function checks if a node has webSocket instance attached 315 | * @param {HTMLElement} node 316 | * @returns {boolean} 317 | */ 318 | function hasWebSocket(node) { 319 | return api.getInternalData(node).webSocket != null 320 | } 321 | 322 | /** 323 | * processWebSocketSend adds event listeners to the element so that 324 | * messages can be sent to the WebSocket server when the form is submitted. 325 | * @param {HTMLElement} socketElt 326 | * @param {HTMLElement} sendElt 327 | */ 328 | function processWebSocketSend(socketElt, sendElt) { 329 | var nodeData = api.getInternalData(sendElt) 330 | var triggerSpecs = api.getTriggerSpecs(sendElt) 331 | triggerSpecs.forEach(function(ts) { 332 | api.addTriggerHandler(sendElt, ts, nodeData, function(elt, evt) { 333 | if (maybeCloseWebSocketSource(socketElt)) { 334 | return 335 | } 336 | 337 | /** @type {WebSocketWrapper} */ 338 | var socketWrapper = api.getInternalData(socketElt).webSocket 339 | var headers = api.getHeaders(sendElt, api.getTarget(sendElt)) 340 | var results = api.getInputValues(sendElt, 'post') 341 | var errors = results.errors 342 | var rawParameters = Object.assign({}, results.values) 343 | var expressionVars = api.getExpressionVars(sendElt) 344 | var allParameters = api.mergeObjects(rawParameters, expressionVars) 345 | var filteredParameters = api.filterValues(allParameters, sendElt) 346 | 347 | var sendConfig = { 348 | parameters: filteredParameters, 349 | unfilteredParameters: allParameters, 350 | headers, 351 | errors, 352 | 353 | triggeringEvent: evt, 354 | messageBody: undefined, 355 | socketWrapper: socketWrapper.publicInterface 356 | } 357 | 358 | if (!api.triggerEvent(elt, 'htmx:wsConfigSend', sendConfig)) { 359 | return 360 | } 361 | 362 | if (errors && errors.length > 0) { 363 | api.triggerEvent(elt, 'htmx:validation:halted', errors) 364 | return 365 | } 366 | 367 | var body = sendConfig.messageBody 368 | if (body === undefined) { 369 | var toSend = Object.assign({}, sendConfig.parameters) 370 | if (sendConfig.headers) { toSend.HEADERS = headers } 371 | body = JSON.stringify(toSend) 372 | } 373 | 374 | socketWrapper.send(body, elt) 375 | 376 | if (evt && api.shouldCancel(evt, elt)) { 377 | evt.preventDefault() 378 | } 379 | }) 380 | }) 381 | } 382 | 383 | /** 384 | * getWebSocketReconnectDelay is the default easing function for WebSocket reconnects. 385 | * @param {number} retryCount // The number of retries that have already taken place 386 | * @returns {number} 387 | */ 388 | function getWebSocketReconnectDelay(retryCount) { 389 | /** @type {"full-jitter" | ((retryCount:number) => number)} */ 390 | var delay = htmx.config.wsReconnectDelay 391 | if (typeof delay === 'function') { 392 | return delay(retryCount) 393 | } 394 | if (delay === 'full-jitter') { 395 | var exp = Math.min(retryCount, 6) 396 | var maxDelay = 1000 * Math.pow(2, exp) 397 | return maxDelay * Math.random() 398 | } 399 | 400 | logError('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"') 401 | } 402 | 403 | /** 404 | * maybeCloseWebSocketSource checks to the if the element that created the WebSocket 405 | * still exists in the DOM. If NOT, then the WebSocket is closed and this function 406 | * returns TRUE. If the element DOES EXIST, then no action is taken, and this function 407 | * returns FALSE. 408 | * 409 | * @param {*} elt 410 | * @returns 411 | */ 412 | function maybeCloseWebSocketSource(elt) { 413 | if (!api.bodyContains(elt)) { 414 | api.getInternalData(elt).webSocket.close() 415 | return true 416 | } 417 | return false 418 | } 419 | 420 | /** 421 | * createWebSocket is the default method for creating new WebSocket objects. 422 | * it is hoisted into htmx.createWebSocket to be overridden by the user, if needed. 423 | * 424 | * @param {string} url 425 | * @returns WebSocket 426 | */ 427 | function createWebSocket(url) { 428 | var sock = new WebSocket(url, []) 429 | sock.binaryType = htmx.config.wsBinaryType 430 | return sock 431 | } 432 | 433 | /** 434 | * queryAttributeOnThisOrChildren returns all nodes that contain the requested attributeName, INCLUDING THE PROVIDED ROOT ELEMENT. 435 | * 436 | * @param {HTMLElement} elt 437 | * @param {string} attributeName 438 | */ 439 | function queryAttributeOnThisOrChildren(elt, attributeName) { 440 | var result = [] 441 | 442 | // If the parent element also contains the requested attribute, then add it to the results too. 443 | if (api.hasAttribute(elt, attributeName) || api.hasAttribute(elt, 'hx-ws')) { 444 | result.push(elt) 445 | } 446 | 447 | // Search all child nodes that match the requested attribute 448 | elt.querySelectorAll('[' + attributeName + '], [data-' + attributeName + '], [data-hx-ws], [hx-ws]').forEach(function(node) { 449 | result.push(node) 450 | }) 451 | 452 | return result 453 | } 454 | 455 | /** 456 | * @template T 457 | * @param {T[]} arr 458 | * @param {(T) => void} func 459 | */ 460 | function forEach(arr, func) { 461 | if (arr) { 462 | for (var i = 0; i < arr.length; i++) { 463 | func(arr[i]) 464 | } 465 | } 466 | } 467 | })() 468 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/Routes.swift: -------------------------------------------------------------------------------- 1 | import AsyncAlgorithms 2 | import Vapor 3 | import VaporElementary 4 | 5 | func addRoutes(to app: Application) { 6 | app.get("") { _ in 7 | HTMLResponse { 8 | MainPage() 9 | } 10 | } 11 | 12 | app.get("result") { request in 13 | let x = try request.query.get(Int.self, at: "x") 14 | let y = try request.query.get(Int.self, at: "y") 15 | return HTMLResponse { 16 | ResultView(x: x, y: y) 17 | .environment(BonusFactStore.$current, BonusFactStore()) 18 | } 19 | } 20 | 21 | app.get("time") { _ -> Response in 22 | Response( 23 | status: .ok, 24 | headers: ["Content-Type": "text/event-stream"], 25 | body: .init(managedAsyncStream: { writer in 26 | while true { 27 | try await writer.writeBuffer(.init(string: "event: time\ndata: Server Time: \(Date())\n\n")) 28 | try await Task.sleep(for: .seconds(1)) 29 | } 30 | }) 31 | ) 32 | } 33 | 34 | app.webSocket("echo") { _, ws in 35 | let decoder = JSONDecoder() 36 | 37 | ws.onText { ws, text in 38 | guard let message = try? decoder.decode(WSMessage.self, from: Data(text.utf8)) else { 39 | return 40 | } 41 | 42 | ws.send(WSEcho(message: message.message).render()) 43 | } 44 | } 45 | } 46 | 47 | struct WSMessage: Codable { 48 | var message: String 49 | } 50 | -------------------------------------------------------------------------------- /Examples/VaporDemo/Sources/App/Views.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMX 3 | import ElementaryHTMXSSE 4 | import ElementaryHTMXWS 5 | import Foundation 6 | 7 | struct MainPage: HTMLDocument { 8 | var title: String { "Vapor + Elementary + HTMX" } 9 | 10 | var head: some HTML { 11 | meta(.charset(.utf8)) 12 | script(.src("/htmx.min.js")) {} 13 | script(.src("/htmxsse.min.js")) {} 14 | script(.src("/htmxws.min.js")) {} 15 | link(.rel(.stylesheet), .href("https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css")) 16 | } 17 | 18 | var body: some HTML { 19 | header { 20 | h2 { "Vapor + Elementary + HTMX Demo" } 21 | // example of using htmx sse 22 | h6 { "HTMX SSE Example" } 23 | div(.hx.ext(.sse), .sse.connect("/time")) { 24 | p(.sse.swap("time")) { "Server Time:" } 25 | } 26 | } 27 | main { 28 | h6 { "HTMX Forms Example" } 29 | div { 30 | // example of using hx-target and hx-swap 31 | form(.hx.get("/result"), .hx.target("#result"), .hx.swap(.innerHTML)) { 32 | fieldset(.custom(name: "role", value: "group")) { 33 | input(.type(.number), .name("x"), .value("1"), .required) 34 | input(.type(.text), .value("+"), .disabled) 35 | input(.type(.number), .name("y"), .value("2"), .required) 36 | input(.type(.submit), .value("Calculate")) 37 | } 38 | } 39 | } 40 | div(.id("result")) { 41 | p { i { "Result will be calculated on the server" } } 42 | } 43 | hr() 44 | h6 { "HTMX WS Example" } 45 | // example of using htmx ws 46 | div(.hx.ext(.ws), .ws.connect("/echo")) { 47 | form(.ws.send, .custom(name: "role", value: "group")) { 48 | input(.type(.text), .name("message"), .value("Hello, World!"), .required) 49 | button { "Send" } 50 | } 51 | div(.id("echo")) {} 52 | } 53 | } 54 | } 55 | } 56 | 57 | struct ResultView: HTML { 58 | let x: Int 59 | let y: Int 60 | 61 | @Environment(requiring: BonusFactStore.$current) var bonusFacts 62 | 63 | var content: some HTML { 64 | p { 65 | "\(x) + \(y) = " 66 | b { "\(x + y)" } 67 | } 68 | p { 69 | i { 70 | await bonusFacts.calculateBonusFact() 71 | } 72 | } 73 | } 74 | } 75 | 76 | struct WSEcho: HTML { 77 | let message: String 78 | 79 | var content: some HTML { 80 | div(.id("echo"), .hx.swapOOB(.beforeEnd)) { "Echo: \(message)"; br() } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Examples/VaporDemo/swift-dev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | touch .build/browser-dev-sync 3 | browser-sync start -p localhost:8080 --ws & 4 | 5 | watchexec -w Sources -e .swift -r 'swift build --product App && touch .build/browser-dev-sync' & 6 | watchexec -w .build/browser-dev-sync --ignore-nothing -r '.build/debug/App' 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.10 2 | import PackageDescription 3 | 4 | let featureFlags: [SwiftSetting] = [ 5 | .enableExperimentalFeature("StrictConcurrency=complete"), 6 | .enableUpcomingFeature("ExistentialAny"), 7 | .enableUpcomingFeature("ConciseMagicFile"), 8 | .enableUpcomingFeature("ImplicitOpenExistentials"), 9 | ] 10 | 11 | let package = Package( 12 | name: "elementary-htmx", 13 | platforms: [ 14 | .macOS(.v14), 15 | .iOS(.v17), 16 | .tvOS(.v17), 17 | .watchOS(.v10), 18 | ], 19 | products: [ 20 | .library(name: "ElementaryHTMX", targets: ["ElementaryHTMX"]), 21 | .library(name: "ElementaryHTMXSSE", targets: ["ElementaryHTMXSSE"]), 22 | .library(name: "ElementaryHTMXWS", targets: ["ElementaryHTMXWS"]), 23 | .library(name: "ElementaryHyperscript", targets: ["ElementaryHyperscript"]), 24 | ], 25 | dependencies: [ 26 | .package(url: "https://github.com/sliemeobn/elementary.git", from: "0.3.0"), 27 | ], 28 | targets: [ 29 | .target( 30 | name: "ElementaryHTMX", 31 | dependencies: [ 32 | .product(name: "Elementary", package: "elementary"), 33 | ], 34 | swiftSettings: featureFlags 35 | ), 36 | .target( 37 | name: "ElementaryHTMXSSE", 38 | dependencies: [ 39 | .product(name: "Elementary", package: "elementary"), 40 | .target(name: "ElementaryHTMX"), 41 | ], 42 | swiftSettings: featureFlags 43 | ), 44 | .target( 45 | name: "ElementaryHTMXWS", 46 | dependencies: [ 47 | .product(name: "Elementary", package: "elementary"), 48 | .target(name: "ElementaryHTMX"), 49 | ], 50 | swiftSettings: featureFlags 51 | ), 52 | .target( 53 | name: "ElementaryHyperscript", 54 | dependencies: [ 55 | .product(name: "Elementary", package: "elementary"), 56 | ], 57 | swiftSettings: featureFlags 58 | ), 59 | .testTarget( 60 | name: "ElementaryHTMXTest", 61 | dependencies: [ 62 | .target(name: "ElementaryHTMX"), 63 | .target(name: "TestUtilities"), 64 | ], 65 | swiftSettings: featureFlags 66 | ), 67 | .testTarget( 68 | name: "ElementaryHTMXSSETest", 69 | dependencies: [ 70 | .target(name: "ElementaryHTMXSSE"), 71 | .target(name: "TestUtilities"), 72 | ], 73 | swiftSettings: featureFlags 74 | ), 75 | .testTarget( 76 | name: "ElementaryHTMXWSTest", 77 | dependencies: [ 78 | .target(name: "ElementaryHTMXWS"), 79 | .target(name: "TestUtilities"), 80 | ], 81 | swiftSettings: featureFlags 82 | ), 83 | .testTarget( 84 | name: "ElementaryHyperscriptTest", 85 | dependencies: [ 86 | .target(name: "ElementaryHyperscript"), 87 | .target(name: "TestUtilities"), 88 | ], 89 | swiftSettings: featureFlags 90 | ), 91 | .target( 92 | name: "TestUtilities", 93 | dependencies: [ 94 | .product(name: "Elementary", package: "elementary"), 95 | ], 96 | path: "Tests/TestUtilities", 97 | swiftSettings: featureFlags 98 | ), 99 | ] 100 | ) 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ElementaryHTMX: Hypertext web apps with Swift 2 | 3 | **Ergonomic [HTMX](https://htmx.org/) extensions for [Elementary](https://github.com/sliemeobn/elementary)** 4 | 5 | [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsliemeobn%2Felementary-htmx%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/sliemeobn/elementary-htmx) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsliemeobn%2Felementary-htmx%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/sliemeobn/elementary-htmx) 6 | 7 | ```swift 8 | import Elementary 9 | import ElementaryHTMX 10 | 11 | // first-class support for all HTMX attributes 12 | form(.hx.post("/items"), .hx.target("#list"), .hx.swap(.outerHTML)) { 13 | input(.type(.text), .name("item"), .value("New Item")) 14 | input(.type(.submit), .value("Add Item")) 15 | } 16 | 17 | div { 18 | button(.hx.delete("items/\(item.id)")) { "❌" } 19 | item.text 20 | } 21 | 22 | MyFragment(items: items) 23 | .attributes(.hx.swapOOB(.outerHTML, "#list")) 24 | ``` 25 | 26 | ```swift 27 | import Elementary 28 | import ElementaryHTMXSSE 29 | 30 | // HTMX Server Send Events extension 31 | div(.hx.ext(.sse), .sse.connect("/time"), .sse.swap("message")) { 32 | Date() 33 | } 34 | ``` 35 | 36 | ```swift 37 | import Elementary 38 | import ElementaryHTMXWS 39 | 40 | // HTMX WebSockets extension 41 | div(.hx.ext(.ws), .ws.connect("/echo")) { 42 | form(.ws.send) { 43 | input(.type(.text), .name("message")) 44 | button { "Send" } 45 | } 46 | div(.id("echo")) {} 47 | } 48 | ``` 49 | 50 | ```swift 51 | import Elementary 52 | import ElementaryHyperscript 53 | 54 | // Hyperscript extension 55 | button(.hyperscript("on click send hello to ")) { 56 | "Send" 57 | } 58 | ``` 59 | 60 | ## Play with it 61 | 62 | Check out the [Hummingbird example app](https://github.com/sliemeobn/elementary-htmx/tree/main/Examples/HummingbirdDemo). 63 | 64 | Check out the [Vapor example app](https://github.com/sliemeobn/elementary-htmx/tree/main/Examples/VaporDemo). 65 | 66 | ## Documentation 67 | 68 | The package brings the `.hx` syntaxt to all `HTMLElements` - providing a rich API for most [HTMX attributes](https://htmx.org/docs/). 69 | 70 | There is also an `ElementaryHTMXSSE` module that adds the `.sse` syntax for the [Server Sent Events extensions](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/sse/README.md), as well as `ElementaryHTMXWS` to add the `.ws` syntax for the [WebSockets extensions.](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/ws/README.md) 71 | 72 | The package also supports the [Hyperscript](https://hyperscript.org) `_` attribute as `.hyperscript`. 73 | 74 | ## Future directions 75 | 76 | - Add module (or separate package?) for HTMX Request and Response headers 77 | 78 | PRs welcome. 79 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMX/HTMLAttribute+HTMX.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | 3 | public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global { 4 | /// A namespace for HTMX attributes. 5 | /// See the [htmx reference](https://htmx.org/reference/) for more information. 6 | enum hx {} 7 | } 8 | 9 | public extension HTMLAttribute.hx { 10 | static func get(_ url: String) -> HTMLAttribute { 11 | .init(name: "hx-get", value: url) 12 | } 13 | 14 | static func post(_ url: String) -> HTMLAttribute { 15 | .init(name: "hx-post", value: url) 16 | } 17 | 18 | static func pushURL(_ url: String) -> HTMLAttribute { 19 | .init(name: "hx-push-url", value: url) 20 | } 21 | 22 | static func pushURL(_ value: Bool) -> HTMLAttribute { 23 | .init(name: "hx-push-url", value: value.stringValue) 24 | } 25 | 26 | static func select(_ selector: String) -> HTMLAttribute { 27 | .init(name: "hx-select", value: selector) 28 | } 29 | 30 | static func selectOOB(_ selector: String, _ swap: HTMLAttributeValue.HTMX.SwapTarget? = nil) -> HTMLAttribute { 31 | if let swap { 32 | .init(name: "hx-select-oob", value: "\(selector):\(swap.rawValue)", mergedBy: .appending(seperatedBy: ",")) 33 | } else { 34 | .init(name: "hx-select-oob", value: selector, mergedBy: .appending(seperatedBy: ",")) 35 | } 36 | } 37 | 38 | static func swap(_ value: HTMLAttributeValue.HTMX.ModifiedSwapTarget) -> HTMLAttribute { 39 | .init(name: "hx-swap", value: value.rawValue) 40 | } 41 | 42 | static func swapOOB(_ value: Bool) -> HTMLAttribute { 43 | .init(name: "hx-swap-oob", value: value.stringValue) 44 | } 45 | 46 | static func swapOOB(_ swap: HTMLAttributeValue.HTMX.SwapTarget, _ selector: String? = nil) -> HTMLAttribute { 47 | if let selector { 48 | .init(name: "hx-swap-oob", value: "\(swap.rawValue):\(selector)") 49 | } else { 50 | .init(name: "hx-swap-oob", value: swap.rawValue) 51 | } 52 | } 53 | 54 | static func target(_ selector: String) -> HTMLAttribute { 55 | .init(name: "hx-target", value: selector) 56 | } 57 | 58 | static func trigger(_ value: HTMLAttributeValue.HTMX.EventTrigger) -> HTMLAttribute { 59 | .init(name: "hx-trigger", value: value.rawValue, mergedBy: .appending(seperatedBy: ", ")) 60 | } 61 | 62 | static func trigger(_ value: HTMLAttributeValue.HTMX.PollingTrigger) -> HTMLAttribute { 63 | .init(name: "hx-trigger", value: value.rawValue, mergedBy: .appending(seperatedBy: ", ")) 64 | } 65 | 66 | static func vals(_ value: String) -> HTMLAttribute { 67 | .init(name: "hx-vals", value: value) 68 | } 69 | } 70 | 71 | public extension HTMLAttribute.hx { 72 | static func boost(_ value: Bool) -> HTMLAttribute { 73 | .init(name: "hx-boost", value: value.stringValue) 74 | } 75 | 76 | static func confirm(_ value: String) -> HTMLAttribute { 77 | .init(name: "hx-confirm", value: value) 78 | } 79 | 80 | static func delete(_ url: String) -> HTMLAttribute { 81 | .init(name: "hx-delete", value: url) 82 | } 83 | 84 | static var disable: HTMLAttribute { 85 | .init(name: "hx-disable", value: .none) 86 | } 87 | 88 | static func disabledElt(_ value: String) -> HTMLAttribute { 89 | .init(name: "hx-disabled-elt", value: value) 90 | } 91 | 92 | static func ext(_ value: HTMLAttributeValue.HTMX.Extension) -> HTMLAttribute { 93 | .init(name: "hx-ext", value: value.rawValue, mergedBy: .appending(seperatedBy: ",")) 94 | } 95 | 96 | static func headers(_ value: String) -> HTMLAttribute { 97 | .init(name: "hx-headers", value: value) 98 | } 99 | 100 | static func include(_ value: String) -> HTMLAttribute { 101 | .init(name: "hx-include", value: value) 102 | } 103 | 104 | static func indicator(_ value: String) -> HTMLAttribute { 105 | .init(name: "hx-indicator", value: value) 106 | } 107 | 108 | static func params(_ value: String) -> HTMLAttribute { 109 | .init(name: "hx-params", value: value) 110 | } 111 | 112 | static func patch(_ url: String) -> HTMLAttribute { 113 | .init(name: "hx-patch", value: url) 114 | } 115 | 116 | static func put(_ url: String) -> HTMLAttribute { 117 | .init(name: "hx-put", value: url) 118 | } 119 | 120 | static func replaceURL(_ url: String) -> HTMLAttribute { 121 | .init(name: "hx-replace-url", value: url) 122 | } 123 | 124 | static func replaceURL(_ value: Bool) -> HTMLAttribute { 125 | .init(name: "hx-replace-url", value: value.stringValue) 126 | } 127 | 128 | static func request(_ value: String) -> HTMLAttribute { 129 | .init(name: "hx-request", value: value) 130 | } 131 | 132 | static func validate(_ value: Bool) -> HTMLAttribute { 133 | .init(name: "hx-validate", value: value.stringValue) 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMX/HTMLAttributeValue+HTMX.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | 3 | public extension HTMLAttributeValue { 4 | /// A namespace for HTMX attribute value types. 5 | /// See the [htmx reference](https://htmx.org/reference/) for more information. 6 | enum HTMX {} 7 | } 8 | 9 | public extension HTMLAttributeValue.HTMX { 10 | struct SwapTarget: RawRepresentable, ExpressibleByStringLiteral { 11 | public var rawValue: String 12 | public init(rawValue: String) { 13 | self.rawValue = rawValue 14 | } 15 | 16 | public init(stringLiteral value: String) { 17 | rawValue = value 18 | } 19 | 20 | public static var innerHTML: Self { "innerHTML" } 21 | public static var outerHTML: Self { "outerHTML" } 22 | public static var textContent: Self { "textContent" } 23 | public static var beforeBegin: Self { "beforebegin" } 24 | public static var afterBegin: Self { "afterbegin" } 25 | public static var beforeEnd: Self { "beforeend" } 26 | public static var afterEnd: Self { "afterend" } 27 | public static var delete: Self { "delete" } 28 | public static var none: Self { "none" } 29 | 30 | @available(*, deprecated, renamed: "beforeEnd") 31 | public static var beforEend: Self { "beforeend" } 32 | } 33 | 34 | struct ModifiedSwapTarget: RawRepresentable { 35 | public var rawValue: String 36 | public init(rawValue: String) { 37 | self.rawValue = rawValue 38 | } 39 | 40 | public init(_ swapTarget: SwapTarget) { 41 | rawValue = swapTarget.rawValue 42 | } 43 | 44 | public static var innerHTML: Self { .init(.innerHTML) } 45 | public static var outerHTML: Self { .init(.outerHTML) } 46 | public static var textContent: Self { .init(.textContent) } 47 | public static var beforeBegin: Self { .init(.beforeBegin) } 48 | public static var afterBegin: Self { .init(.afterBegin) } 49 | public static var beforeEnd: Self { .init(.beforeEnd) } 50 | public static var afterEnd: Self { .init(.afterEnd) } 51 | public static var delete: Self { .init(.delete) } 52 | public static var none: Self { .init(.none) } 53 | public static var `default`: Self { .init("") } 54 | 55 | @available(*, deprecated, renamed: "beforeEnd") 56 | public static var beforEend: Self { .init(.beforEend) } 57 | } 58 | } 59 | 60 | public extension HTMLAttributeValue.HTMX.ModifiedSwapTarget { 61 | consuming func transition(_ value: Bool) -> Self { 62 | appending(modifier: "transition", value: value.stringValue) 63 | } 64 | 65 | consuming func swap(_ duration: String) -> Self { 66 | appending(modifier: "swap", value: duration) 67 | } 68 | 69 | consuming func settle(_ duration: String) -> Self { 70 | appending(modifier: "settle", value: duration) 71 | } 72 | 73 | consuming func ignoreTitle(_ value: Bool) -> Self { 74 | appending(modifier: "ignoreTitle", value: value.stringValue) 75 | } 76 | 77 | consuming func scroll(_ value: HTMLAttributeValue.HTMX.ScrollModifier) -> Self { 78 | appending(modifier: "scroll", value: value.rawValue) 79 | } 80 | 81 | consuming func show(_ value: HTMLAttributeValue.HTMX.ScrollModifier) -> Self { 82 | appending(modifier: "show", value: value.rawValue) 83 | } 84 | 85 | consuming func focusScroll(_ value: Bool) -> Self { 86 | appending(modifier: "focus-scroll", value: value.stringValue) 87 | } 88 | 89 | internal consuming func appending(modifier: String, value: String) -> Self { 90 | if !rawValue.isEmpty { 91 | rawValue += " " 92 | } 93 | rawValue += modifier 94 | rawValue += ":" 95 | rawValue += value 96 | 97 | return self 98 | } 99 | } 100 | 101 | public extension HTMLAttributeValue.HTMX { 102 | struct ScrollModifier: RawRepresentable { 103 | public var rawValue: String 104 | public init(rawValue: String) { 105 | self.rawValue = rawValue 106 | } 107 | 108 | public static var top: Self { .init(rawValue: "top") } 109 | public static var bottom: Self { .init(rawValue: "bottom") } 110 | public static var none: Self { .init(rawValue: "none") } 111 | 112 | public static func top(_ selector: String) -> Self { 113 | .init(rawValue: "\(selector):top") 114 | } 115 | 116 | public static func bottom(_ selector: String) -> Self { 117 | .init(rawValue: "\(selector):bottom") 118 | } 119 | } 120 | } 121 | 122 | public extension HTMLAttributeValue.HTMX { 123 | struct TriggerEvent: RawRepresentable { 124 | public var rawValue: String 125 | public init(rawValue: String) { 126 | self.rawValue = rawValue 127 | } 128 | 129 | public static var load: Self { .init(rawValue: "load") } 130 | public static var revealed: Self { .init(rawValue: "revealed") } 131 | public static var intersect: Self { .init(rawValue: "intersect") } 132 | } 133 | 134 | struct EventTrigger: RawRepresentable { 135 | public var rawValue: String 136 | public init(rawValue: String) { 137 | self.rawValue = rawValue 138 | } 139 | 140 | public static func event(_ event: HTMLAttributeValue.MouseEvent) -> Self { .init(rawValue: "\(event.rawValue)") } 141 | public static func event(_ event: HTMLAttributeValue.KeyboardEvent) -> Self { .init(rawValue: "\(event.rawValue)") } 142 | public static func event(_ event: HTMLAttributeValue.FormEvent) -> Self { .init(rawValue: "\(event.rawValue)") } 143 | public static func event(_ event: HTMLAttributeValue.HTMX.TriggerEvent) -> Self { .init(rawValue: "\(event.rawValue)") } 144 | } 145 | 146 | struct PollingTrigger: RawRepresentable { 147 | public var rawValue: String 148 | public init(rawValue: String) { 149 | self.rawValue = rawValue 150 | } 151 | 152 | public static func every(_ interval: String) -> Self { .init(rawValue: "every \(interval)") } 153 | } 154 | } 155 | 156 | public extension HTMLAttributeValue.HTMX.EventTrigger { 157 | consuming func once() -> Self { 158 | appending(modifier: "once") 159 | } 160 | 161 | consuming func changed() -> Self { 162 | appending(modifier: "changed") 163 | } 164 | 165 | consuming func delay(_ value: String) -> Self { 166 | appending(modifier: "delay", value: value) 167 | } 168 | 169 | consuming func throttle(_ value: String) -> Self { 170 | appending(modifier: "throttle", value: value) 171 | } 172 | 173 | consuming func from(_ selector: String) -> Self { 174 | appending(modifier: "from", value: selector) 175 | } 176 | 177 | consuming func consume() -> Self { 178 | appending(modifier: "consume") 179 | } 180 | 181 | internal consuming func appending(modifier: String, value: String? = nil) -> Self { 182 | rawValue += " " 183 | rawValue += modifier 184 | if let value { 185 | rawValue += ":" 186 | rawValue += value 187 | } 188 | return self 189 | } 190 | } 191 | 192 | public extension HTMLAttributeValue.HTMX { 193 | struct Extension: RawRepresentable, ExpressibleByStringLiteral { 194 | public var rawValue: String 195 | public init(rawValue: String) { 196 | self.rawValue = rawValue 197 | } 198 | 199 | public init(stringLiteral value: String) { 200 | rawValue = value 201 | } 202 | } 203 | } 204 | 205 | extension Bool { 206 | var stringValue: String { self ? "true" : "false" } 207 | } 208 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMXSSE/HTMLAttribute+HTMXSSE.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | 3 | public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global { 4 | /// A namespace for the HTMX SSE-extension. 5 | /// See the [htmx-sse reference](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/sse/README.md) for more information. 6 | enum sse {} 7 | } 8 | 9 | public extension HTMLAttribute.sse { 10 | static func connect(_ url: String) -> HTMLAttribute { 11 | .init(name: "sse-connect", value: url) 12 | } 13 | 14 | static func swap(_ eventName: String) -> HTMLAttribute { 15 | .init(name: "sse-swap", value: eventName) 16 | } 17 | 18 | static func close(_ eventName: String) -> HTMLAttribute { 19 | .init(name: "sse-close", value: eventName) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMXSSE/HTMLAttributeValue+HTMXSSE.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMX 3 | 4 | public extension HTMLAttributeValue.HTMX.Extension { 5 | static var sse: Self { "sse" } 6 | } 7 | 8 | public extension HTMLAttributeValue.HTMX.EventTrigger { 9 | static func sse(_ eventName: String) -> Self { 10 | .init(rawValue: "sse:\(eventName)") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMXWS/HTMLAttribute+HTMX.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | 3 | public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global { 4 | /// A namespace for the HTMX SSE-extension. 5 | /// See the [htmx-sse reference](https://github.com/bigskysoftware/htmx-extensions/blob/main/src/sse/README.md) for more information. 6 | enum ws {} 7 | } 8 | 9 | public extension HTMLAttribute.ws { 10 | static func connect(_ url: String) -> HTMLAttribute { 11 | .init(name: "ws-connect", value: url) 12 | } 13 | 14 | static var send: HTMLAttribute { 15 | .init(name: "ws-send", value: nil) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/ElementaryHTMXWS/HTMLAttributeValue+HTMX.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMX 3 | 4 | public extension HTMLAttributeValue.HTMX.Extension { 5 | static var ws: Self { "ws" } 6 | } 7 | 8 | public extension HTMLAttributeValue.HTMX.EventTrigger { 9 | static func ws(_ eventName: String) -> Self { 10 | .init(rawValue: "ws:\(eventName)") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sources/ElementaryHyperscript/HTMLAttribute+Hyperscript.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | 3 | public extension HTMLAttribute where Tag: HTMLTrait.Attributes.Global { 4 | static func hyperscript(_ script: String) -> Self { 5 | .init(name: "_", value: script) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Tests/ElementaryHTMXSSETest/ElementaryHTMXSSETest.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMXSSE 3 | import TestUtilities 4 | import XCTest 5 | 6 | final class ElementaryHTMXSSETests: XCTestCase { 7 | func testExtension() { 8 | HTMLAttributeAssertEqual(.hx.ext(.sse), "hx-ext", "sse") 9 | } 10 | 11 | func testAttributes() { 12 | HTMLAttributeAssertEqual(.sse.connect("/test"), "sse-connect", "/test") 13 | HTMLAttributeAssertEqual(.sse.swap("test"), "sse-swap", "test") 14 | HTMLAttributeAssertEqual(.sse.close("test"), "sse-close", "test") 15 | } 16 | 17 | func testAttributeValues() { 18 | HTMLAttributeAssertEqual(.hx.trigger(.sse("time")), "hx-trigger", "sse:time") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Tests/ElementaryHTMXTest/ElementaryHTMXTest.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMX 3 | import TestUtilities 4 | import XCTest 5 | 6 | final class ElementaryHTMXTests: XCTestCase { 7 | func testMethods() { 8 | HTMLAttributeAssertEqual(.hx.get("/test"), "hx-get", "/test") 9 | HTMLAttributeAssertEqual(.hx.post("/test"), "hx-post", "/test") 10 | HTMLAttributeAssertEqual(.hx.put("/test"), "hx-put", "/test") 11 | HTMLAttributeAssertEqual(.hx.patch("/test"), "hx-patch", "/test") 12 | HTMLAttributeAssertEqual(.hx.delete("/test"), "hx-delete", "/test") 13 | } 14 | 15 | func testSwap() { 16 | HTMLAttributeAssertEqual(.hx.swap(.innerHTML), "hx-swap", "innerHTML") 17 | HTMLAttributeAssertEqual(.hx.swap(.outerHTML), "hx-swap", "outerHTML") 18 | HTMLAttributeAssertEqual(.hx.swap(.textContent), "hx-swap", "textContent") 19 | HTMLAttributeAssertEqual(.hx.swap(.beforeBegin), "hx-swap", "beforebegin") 20 | HTMLAttributeAssertEqual(.hx.swap(.afterBegin), "hx-swap", "afterbegin") 21 | HTMLAttributeAssertEqual(.hx.swap(.beforeEnd), "hx-swap", "beforeend") 22 | HTMLAttributeAssertEqual(.hx.swap(.afterEnd), "hx-swap", "afterend") 23 | HTMLAttributeAssertEqual(.hx.swap(.delete), "hx-swap", "delete") 24 | HTMLAttributeAssertEqual(.hx.swap(.none), "hx-swap", "none") 25 | } 26 | 27 | func testSwapModifiers() { 28 | HTMLAttributeAssertEqual(.hx.swap(.innerHTML.transition(true)), "hx-swap", "innerHTML transition:true") 29 | HTMLAttributeAssertEqual(.hx.swap(.outerHTML.swap("1s").settle("10ms")), "hx-swap", "outerHTML swap:1s settle:10ms") 30 | HTMLAttributeAssertEqual(.hx.swap(.textContent.swap("1s").settle("10ms")), "hx-swap", "textContent swap:1s settle:10ms") 31 | HTMLAttributeAssertEqual(.hx.swap(.default.transition(true)), "hx-swap", "transition:true") 32 | } 33 | 34 | func testSelectOOB() { 35 | HTMLAttributeAssertEqual(.hx.selectOOB("#test"), "hx-select-oob", "#test") 36 | HTMLAttributeAssertEqual(.hx.selectOOB("#test", .innerHTML), "hx-select-oob", "#test:innerHTML") 37 | } 38 | 39 | func testSwapOOB() { 40 | HTMLAttributeAssertEqual(.hx.swapOOB(true), "hx-swap-oob", "true") 41 | HTMLAttributeAssertEqual(.hx.swapOOB(.innerHTML), "hx-swap-oob", "innerHTML") 42 | HTMLAttributeAssertEqual(.hx.swapOOB(.innerHTML, "#test"), "hx-swap-oob", "innerHTML:#test") 43 | } 44 | 45 | func testTrigger() { 46 | HTMLAttributeAssertEqual(.hx.trigger(.event(.click)), "hx-trigger", "click") 47 | HTMLAttributeAssertEqual(.hx.trigger(.event(.intersect)), "hx-trigger", "intersect") 48 | HTMLAttributeAssertEqual(.hx.trigger(.every("1s")), "hx-trigger", "every 1s") 49 | } 50 | 51 | func testTriggerModifiers() { 52 | HTMLAttributeAssertEqual(.hx.trigger(.event(.click).delay("1s").consume()), "hx-trigger", "click delay:1s consume") 53 | HTMLAttributeAssertEqual(.hx.trigger(.event(.intersect).once()), "hx-trigger", "intersect once") 54 | } 55 | 56 | func testDisable() { 57 | HTMLAttributeAssertEqual(.hx.disable, "hx-disable", nil) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tests/ElementaryHTMXWSTest/ElemntaryHTMXWSTest.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHTMXWS 3 | import TestUtilities 4 | import XCTest 5 | 6 | final class ElementaryHTMXWSTests: XCTestCase { 7 | func testExtension() { 8 | HTMLAttributeAssertEqual(.hx.ext(.ws), "hx-ext", "ws") 9 | } 10 | 11 | func testAttributes() { 12 | HTMLAttributeAssertEqual(.ws.connect("/test"), "ws-connect", "/test") 13 | } 14 | 15 | func testAttributeValues() { 16 | HTMLAttributeAssertEqual(.hx.trigger(.ws("time")), "hx-trigger", "ws:time") 17 | } 18 | 19 | func testWSSend() { 20 | HTMLAttributeAssertEqual(.ws.send, "ws-send", nil) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Tests/ElementaryHyperscriptTest/ElementaryHyperscriptTest.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import ElementaryHyperscript 3 | import TestUtilities 4 | import XCTest 5 | 6 | final class ElementaryHyperscriptTests: XCTestCase { 7 | func testScript() { 8 | HTMLAttributeAssertEqual(.hyperscript("on click send hello to "), "_", "on click send hello to ") 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tests/TestUtilities/Utilities.swift: -------------------------------------------------------------------------------- 1 | import Elementary 2 | import XCTest 3 | 4 | public func HTMLAttributeAssertEqual(_ attribute: HTMLAttribute, _ name: String, _ value: String?, file: StaticString = #filePath, line: UInt = #line) { 5 | XCTAssertEqual(name, attribute.name, file: file, line: line) 6 | XCTAssertEqual(value, attribute.value, file: file, line: line) 7 | } 8 | --------------------------------------------------------------------------------