Targets
SwiftUI
dsfc generates a Swift package for macOS with tokens, testable component models, native views and example tests.
dsfc build fixtures/scenarios/01-button-calculated --target swiftui --output generated/swiftui
What is generated
generated/swiftui/
├── Package.swift # macOS 14+, Swift 6 language mode
├── Sources/CalculatedButton/
│ ├── Tokens.swift # token values per context
│ ├── Context.swift # DSContext and the dsContext environment value
│ ├── DSButton.swift # model + view, one file per component
│ ├── DSActionBar.swift
│ ├── Icons.swift, Icons/*.svg # checked SVG files, bundled
│ └── Support.swift
├── Tests/CalculatedButtonTests/
│ ├── ExampleTests.swift # Swift Testing tests of the models
│ ├── ExampleScreenTests.swift # XCTest tests of the rendered views, on screen
│ └── ExampleScreen.swift # their window, drivers and probe
└── dsf-build.json # files and capability report
Each component has a pure model, DSButtonModel: resolve(props, variants, states, context)
returns every node value with overrides applied, and handle(input, …) returns the emitted
events. The view only draws resolved values, so the examples test the model directly.
The examples also run against the rendered views (D-060). Each test shows the component in a
window as large as the example’s space and drives it as a user and assistive technology do:
focus moves through an element’s accessibility focus, keys are key events sent through the
window, an activation is the element’s accessibility press (a pointer click for a node that
is no element), drags are mouse events, text is typed through the field editor. It checks
the element that has keyboard focus and the elements’ names, descriptions, states and roles
in the accessibility tree, which nodes are shown and where (a probe the views record into
only when a test provides one), the emitted events, and the values the view renders with.
dsf-build.json lists each example as example.model, example.screen, or, when neither
test can translate it, example.<capability> with both reasons.
Native mapping
- A
buttonrole with anactivationhandler is aSwiftUI.Button; the DSF view is drawn as its label. Keyboard activation, disabled state and accessibility actions are native. - The tri-state checkbox is a button with the toggle trait and a checked, unchecked or mixed
value, reported as
custom(SwiftUI has no native tri-state checkbox). - Icons, including library icons and icons chosen at run time, are bundled SVG files,
rendered as templates when
rendering = "template"and mirrored in right-to-left layouts whendirection = "mirror". - A component that handles
activationwithout a native control (it has an interactive role, or it is a focus stop with a role) is activated by a press, its default accessibility action, and Space and Return when it is a focus stop (D-058). - Context follows the view tree through the
dsContextenvironment value; direction, reduced motion, reduced transparency, contrast and locale come from SwiftUI’s environment. macOS has a fine pointer and gives apps no text size preference, socontext.pointerisfineandcontext.text_scaleis 1, the scale text is drawn at, which is reported as an approximation (DSF-X004: the user’s preference is not followed, D-065);dsf-build.jsonreports how each environment axis a component reads is filled (D-058). - Motion runs as SwiftUI animations on a clock (D-063). A node that enters or exits is drawn
with its
enterandexitvalues at the clock’s time and the declared timing function; an exiting node stays drawn but is absent at once, and a change while it moves reverses it from where it is. A shared transition between ends in one window morphs: both ends follow bounds thatmatchedGeometryEffectinterpolates from one end’s frame to the other’s and crossfade; in modecrossfadethe destination fades at its own bounds. Amorphinto a presentation’s window plays the declared fallback (DSF-X002).transition_endis delivered when SwiftUI reports the animation complete. The clock is the platform’s; the generated on-screen tests give the views a virtual one, and a generated test checks the completion on the platform’s clock (D-065).
Same rendering as Angular
Box effects follow one model on both targets:
- a
borderis drawn inside the bounds and does not change the layout; shadowsfollow the CSSbox-shadowmodel, includingspreadandinset;- a
font_familylist is a fallback stack: the first generic or installed family is used.
Not supported yet
Every scenario of the corpus (01–14), both example ports and the target fixtures generate
with no DSF-X001. What the generator cannot realize faithfully (for example a gradient
interpolated in OKLab with no declared fallback) is reported as DSF-X001 with its location,
and nothing is written; what it realizes only in part (the text scale, a value range’s
bounds) is a DSF-X004 warning: nothing is approximated silently. The
known deviations
list where the generated code still differs from the reference semantics. The on-screen tests
run motion on a virtual clock that advance steps move; they leave a shared transition that
would morph into another window (SwiftUI plays its fallback there), input method compositions
and a text’s line count to the other runs, and those whose focus moves need macOS keyboard
navigation (System Settings > Keyboard) are skipped, explicitly, while it is off, and reported
apart (example.screen.keyboard): without it, macOS moves focus to buttons neither by Tab nor
by a program. A role is checked as the generator realizes it (a dialog’s modality, a search
field’s subrole); the report says when the accessibility tree tells other roles alike.
Using the package
import SwiftUI
import CalculatedButton
struct Checkout: View {
var body: some View {
DSButton(label: "Continue", appearance: .primary) {
// `activate` was emitted
}
.environment(\.dsContext, DSContext(theme: .dark))
}
}
Options
| Option | Default | Meaning |
|---|---|---|
prefix |
DS |
Prefix of public types (DSButton), so a Button component never shadows SwiftUI.Button. |
module |
package name in UpperCamelCase | Swift module name. |
dsfc build . --target swiftui --output generated/swiftui --option prefix=Acme
Validation
tools/validate-swiftui.sh builds the generated packages with -warnings-as-errors and runs
swift test (Swift 6.4.2, Xcode 27.2): the 14 scenarios, both
example ports and the capability fixtures build and pass, their model tests
and their on-screen tests. The on-screen tests need a logged-in session (they open windows).