The Web is StateUI's sixth host. An application written once in Swift now also runs in a browser page. The application, the library and the host compile to one WebAssembly module. That module draws the browser's own elements - <button>, <input>, <select>, <progress>, <img>, <canvas>, <iframe>, a modal <dialog> - under a small JavaScript relay. The application's code does not change.
Try it: the Gallery runs at stateui.dev.
The Web host
- It covers pages, tabs, the split view, navigation and modal stacks, sheets, overlays, menus, collections, scroll views, shapes, canvases, gestures and layout motion. The browser does the layout, from StateUI's placement written as CSS.
- A page is one window, the browser's own.
openWindowasking for another throwsWindowError.unsupported, as on a phone. The browser's Back button goes back a step. - It follows the light or dark appearance of the user's system, and tells a phone from a desktop.
- An application adds its own controls: a custom element of its own JavaScript, held by a
WebControlregistered withStateUIControls.add. The Gallery's WebGL cube and its Google Maps map are built this way. - It does not use Foundation.
Getting started
Requirements:
- macOS or Linux;
- Swift 6.4 and the Swift SDK for WebAssembly
swift-6.4.0-RELEASE_wasm; - Python 3;
- a browser;
- for the host's own tests, Node.js 20 or newer and Google Chrome.
.scripts/Web/run-app.sh apps/Gallery # build, serve and open
.scripts/Web/deploy.sh apps/HelloWorld artifacts/HelloWorld/Web # a folder any web server servesAn application's Web head is Platforms/Web/main.swift. Web-only Swift stands under #if WEB. See the Web host.
Where it stands
The Web column of the platform contract comes from the host's first full conformance run:
- control members: 1516 of 2447 met (the other hosts: 1828 to 1992);
- structure: 34 of 121.
Still open in the host:
- pinch;
- a layout direction the tree changes;
- the frames of views in a grid's cells and areas;
- the transforms of shapes.
The test driver cannot yet read colours at a point, menus, or how shapes are painted.
The Web workflow in CI runs the host's suite in Node and its host tests in headless Chrome. The conformance families join CI once they report no failure.
For every host
stateUIVersion()returns the StateUI release the library is. The Gallery's menu shows it.- The Gallery's window samples stand under Scene.
- AppKit, UIKit, Android Views, WinUI 3 and GTK 4 behave as in 0.5.0.
VS Code extension 0.5.1
- Web in StateUI: Select Host, and StateUI: Select Browser for the browser a launch opens.
- StateUI: Debug opens the page in Chrome, Edge or another Chromium browser under VS Code's JavaScript debugger. The page's console appears in the Debug Console.
- StateUI: Deploy writes a ready page into
artifacts/<App>/Web.
Upgrading
.package(url: "https://github.com/idexus/StateUI.git", exact: "0.5.1")No source change is needed.