@astryxdesign/native 0.7.5-canary.cd53c2d → 0.7.5-canary.d695efb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +16 -12
  2. package/apple/Package.swift +27 -4
  3. package/apple/README.md +203 -0
  4. package/apple/Sources/Astryx/Banner/Banner.swift +80 -0
  5. package/apple/Sources/Astryx/Base/BaseProps.swift +16 -0
  6. package/apple/Sources/Astryx/Button/Button.swift +168 -0
  7. package/apple/Sources/Astryx/Card/Card.swift +106 -0
  8. package/apple/Sources/Astryx/Exports.swift +8 -0
  9. package/apple/Sources/Astryx/Heading/Heading.swift +117 -0
  10. package/apple/Sources/Astryx/Icon/Icon.spec.md +186 -0
  11. package/apple/Sources/Astryx/Icon/Icon.swift +155 -0
  12. package/apple/Sources/Astryx/Localization/AstryxStrings.swift +22 -0
  13. package/apple/Sources/Astryx/Resources/af.lproj/Localizable.strings +4 -0
  14. package/apple/Sources/Astryx/Resources/ar.lproj/Localizable.strings +4 -0
  15. package/apple/Sources/Astryx/Resources/ca.lproj/Localizable.strings +4 -0
  16. package/apple/Sources/Astryx/Resources/cs.lproj/Localizable.strings +4 -0
  17. package/apple/Sources/Astryx/Resources/da.lproj/Localizable.strings +4 -0
  18. package/apple/Sources/Astryx/Resources/de.lproj/Localizable.strings +4 -0
  19. package/apple/Sources/Astryx/Resources/el.lproj/Localizable.strings +4 -0
  20. package/apple/Sources/Astryx/Resources/en.lproj/Localizable.strings +4 -0
  21. package/apple/Sources/Astryx/Resources/es.lproj/Localizable.strings +4 -0
  22. package/apple/Sources/Astryx/Resources/fi.lproj/Localizable.strings +4 -0
  23. package/apple/Sources/Astryx/Resources/fr.lproj/Localizable.strings +4 -0
  24. package/apple/Sources/Astryx/Resources/he.lproj/Localizable.strings +4 -0
  25. package/apple/Sources/Astryx/Resources/hu.lproj/Localizable.strings +4 -0
  26. package/apple/Sources/Astryx/Resources/it.lproj/Localizable.strings +4 -0
  27. package/apple/Sources/Astryx/Resources/ja.lproj/Localizable.strings +4 -0
  28. package/apple/Sources/Astryx/Resources/ko.lproj/Localizable.strings +4 -0
  29. package/apple/Sources/Astryx/Resources/nb.lproj/Localizable.strings +4 -0
  30. package/apple/Sources/Astryx/Resources/nl.lproj/Localizable.strings +4 -0
  31. package/apple/Sources/Astryx/Resources/pl.lproj/Localizable.strings +4 -0
  32. package/apple/Sources/Astryx/Resources/pt-BR.lproj/Localizable.strings +4 -0
  33. package/apple/Sources/Astryx/Resources/pt-PT.lproj/Localizable.strings +4 -0
  34. package/apple/Sources/Astryx/Resources/ro.lproj/Localizable.strings +4 -0
  35. package/apple/Sources/Astryx/Resources/ru.lproj/Localizable.strings +4 -0
  36. package/apple/Sources/Astryx/Resources/sr.lproj/Localizable.strings +4 -0
  37. package/apple/Sources/Astryx/Resources/sv.lproj/Localizable.strings +4 -0
  38. package/apple/Sources/Astryx/Resources/tr.lproj/Localizable.strings +4 -0
  39. package/apple/Sources/Astryx/Resources/uk.lproj/Localizable.strings +4 -0
  40. package/apple/Sources/Astryx/Resources/vi.lproj/Localizable.strings +4 -0
  41. package/apple/Sources/Astryx/Resources/zh-Hans.lproj/Localizable.strings +4 -0
  42. package/apple/Sources/Astryx/Resources/zh-Hant.lproj/Localizable.strings +4 -0
  43. package/apple/Sources/Astryx/Text/Text.swift +102 -0
  44. package/apple/Sources/Astryx/Text/TypeStyle.swift +143 -0
  45. package/apple/Sources/Astryx/TextInput/TextInput.swift +81 -0
  46. package/apple/Sources/Astryx/Theme/AstryxIcons.swift +108 -0
  47. package/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift +439 -0
  48. package/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift +439 -0
  49. package/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift +439 -0
  50. package/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift +439 -0
  51. package/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift +439 -0
  52. package/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift +439 -0
  53. package/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift +439 -0
  54. package/apple/Sources/Astryx/Theme/Generated/Tokens.swift +1318 -0
  55. package/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift +439 -0
  56. package/apple/Sources/Astryx/Theme/Shadow.swift +39 -0
  57. package/apple/Sources/Astryx/Theme/Theme.swift +273 -0
  58. package/apple/Sources/Astryx/Tooltip/TooltipPresenter.swift +511 -0
  59. package/apple/Sources/Astryx/Wire/AstryxNodeView.swift +75 -0
  60. package/apple/Sources/AstryxNative/Generated/AstryxNode.swift +3 -0
  61. package/apple/Sources/AstryxNative/Generated/Button.swift +14 -2
  62. package/apple/Sources/AstryxNative/Generated/Icon.swift +106 -0
  63. package/apple/Sources/AstryxNative/Generated/IconName.swift +47 -0
  64. package/apple/Tests/AstryxTests/BannerTests.swift +47 -0
  65. package/apple/Tests/AstryxTests/ButtonTests.swift +72 -0
  66. package/apple/Tests/AstryxTests/CardTests.swift +134 -0
  67. package/apple/Tests/AstryxTests/EnvironmentTests.swift +87 -0
  68. package/apple/Tests/AstryxTests/HeadingTests.swift +68 -0
  69. package/apple/Tests/AstryxTests/IconTests.swift +188 -0
  70. package/apple/Tests/AstryxTests/NamesTests.swift +28 -0
  71. package/apple/Tests/AstryxTests/Pixels.swift +68 -0
  72. package/apple/Tests/AstryxTests/Resources/astryx-test-icon.png +0 -0
  73. package/apple/Tests/AstryxTests/StringsTests.swift +23 -0
  74. package/apple/Tests/AstryxTests/TextInputTests.swift +29 -0
  75. package/apple/Tests/AstryxTests/TextTests.swift +109 -0
  76. package/apple/Tests/AstryxTests/ThemeTests.swift +45 -0
  77. package/apple/Tests/AstryxTests/TooltipPresenterTests.swift +160 -0
  78. package/apple/Tests/AstryxTests/TwoThemeTests.swift +65 -0
  79. package/dist/components/Button.d.ts.map +1 -1
  80. package/dist/components/Button.js +1 -0
  81. package/dist/components/Icon.d.ts +10 -0
  82. package/dist/components/Icon.d.ts.map +1 -0
  83. package/dist/components/Icon.js +7 -0
  84. package/dist/components/index.d.ts.map +1 -1
  85. package/dist/components/index.js +2 -0
  86. package/dist/contract/fromComponentDoc.d.ts +11 -2
  87. package/dist/contract/fromComponentDoc.d.ts.map +1 -1
  88. package/dist/contract/fromComponentDoc.js +16 -0
  89. package/dist/contract/generateSwift.d.ts.map +1 -1
  90. package/dist/contract/generateSwift.js +33 -0
  91. package/dist/contract/generateTypeScript.d.ts.map +1 -1
  92. package/dist/contract/generateTypeScript.js +11 -2
  93. package/dist/contract/types.d.ts +9 -0
  94. package/dist/contract/types.d.ts.map +1 -1
  95. package/dist/types/android.d.ts +14 -4
  96. package/dist/types/core.d.ts +10 -0
  97. package/dist/types/ios.d.ts +14 -4
  98. package/dist/types/macos.d.ts +14 -4
  99. package/dist/types/shared.d.ts +14 -4
  100. package/dist/types/windows.d.ts +14 -4
  101. package/package.json +6 -4
  102. package/src/components/Button.ts +1 -0
  103. package/src/components/Icon.ts +18 -0
  104. package/src/components/index.ts +2 -0
  105. package/src/contract/contracts.test.ts +37 -0
  106. package/src/contract/fromComponentDoc.test.ts +29 -0
  107. package/src/contract/fromComponentDoc.ts +32 -2
  108. package/src/contract/generateSwift.ts +38 -0
  109. package/src/contract/generateTypeScript.ts +11 -2
  110. package/src/contract/types.ts +9 -0
  111. package/src/icons/swiftIcons.test.ts +22 -0
  112. package/src/theme/swiftIOSStrings.test.ts +49 -0
  113. package/src/theme/swiftIOSTheme.test.ts +281 -0
package/README.md CHANGED
@@ -12,20 +12,23 @@ rests on evidence.
12
12
 
13
13
  ## What is here today
14
14
 
15
- | Part | Path | What it does |
16
- | -------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
- | Contracts | `src/contract/` | Reads a core component's documentation and splits its props into a portable **core contract** and a **web-only** part, with a reason for each web-only prop. Checks prop names against Swift and Kotlin keywords and platform toolkit names. |
18
- | Platform types | `@astryxdesign/native/components` | TypeScript props per platform, chosen by type-resolution condition: `ios`, `android`, `macos`, `windows`, or `shared` for the core contract only. |
19
- | Swift binding | `apple/` | A Swift package with props generated from the same contracts. iOS and macOS props sit behind `#if os(...)`. |
20
- | Native theme | `defineNativeTheme` | Durable theme intent (`material: 'opaque' \| 'translucent'`) plus platform entries scoped by OS version, such as Liquid Glass from iOS 26. Never sets tokens. |
21
- | Icons | `NATIVE_ICON_DEFAULTS` | Astryx's built-in icon names mapped to SF Symbols on Apple platforms and Material Symbols on Android. |
22
- | Wire | `AstryxNode`, `AstryxAction` | Each component as JSON a TypeScript core sends a native host (arm C), and the action a host sends back when a view calls a callback. Swift decodes `<Name>Node` and turns it into `<Name>Props` with `viewProps(send:)`. |
23
- | Logic core | `@astryxdesign/native/logic` | `createLogicCore` holds a screen's state, builds its node tree, and reduces actions; `connectBridge` carries it to a native host as JSON. ECMAScript built-ins only, so it runs in Hermes. Shaped after EJ Campbell's astryx-swift spike. |
24
- | Logic host | `AstryxLogicHost` (Swift) | Runs a logic core bundle in JavaScriptCore, decodes each tree into `AstryxNode`, and sends views' actions back. A Hermes host speaks the same bridge. |
15
+ | Part | Path | What it does |
16
+ | -------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
17
+ | Contracts | `src/contract/` | Reads a core component's documentation and splits its props into a portable **core contract** and a **web-only** part, with a reason for each web-only prop. Checks prop names against Swift and Kotlin keywords and platform toolkit names. |
18
+ | Platform types | `@astryxdesign/native/components` | TypeScript props per platform, chosen by type-resolution condition: `ios`, `android`, `macos`, `windows`, or `shared` for the core contract only. |
19
+ | Swift binding | `apple/` | A Swift package with two products: `AstryxNative`, props generated from the same contracts (iOS and macOS props sit behind `#if os(...)`) plus the logic host, and `Astryx`, SwiftUI views drawn with core's tokens. Clone-only page templates sit in `apple/Templates/`. See [its README](apple/README.md). |
20
+ | Native theme | `defineNativeTheme` | Durable theme intent (`material: 'opaque' \| 'translucent'`) plus platform entries scoped by OS version, such as Liquid Glass from iOS 26. Never sets tokens. |
21
+ | Icons | `NATIVE_ICON_DEFAULTS` | Astryx's built-in icon names mapped to SF Symbols on Apple platforms and Material Symbols on Android. |
22
+ | Wire | `AstryxNode`, `AstryxAction` | Each component as JSON a TypeScript core sends a native host (arm C), and the action a host sends back when a view calls a callback. Swift decodes `<Name>Node` and turns it into `<Name>Props` with `viewProps(send:)`. |
23
+ | Logic core | `@astryxdesign/native/logic` | `createLogicCore` holds a screen's state, builds its node tree, and reduces actions; `connectBridge` carries it to a native host as JSON. ECMAScript built-ins only, so it runs in Hermes. Shaped after EJ Campbell's astryx-swift spike. |
24
+ | Logic host | `AstryxLogicHost` (Swift) | Runs a logic core bundle in JavaScriptCore, decodes each tree into `AstryxNode`, and sends views' actions back. A Hermes host speaks the same bridge. |
25
25
 
26
26
  Contracts cover Badge, Button, Card, Divider, Heading, HStack, ProgressBar,
27
- Selector, Switch, Text, TextInput, and VStack. React Native and Android
28
- bindings are not built yet; see [the experiment matrix](#experiment-matrix).
27
+ Selector, Switch, Text, TextInput, and VStack. The `Astryx` Swift product draws
28
+ Text, Heading, Button, TextInput, Card, and Banner, and `apple/Templates/` the
29
+ `login` template, in SwiftUI.
30
+ React Native and Android bindings are not built yet; see
31
+ [the experiment matrix](#experiment-matrix).
29
32
 
30
33
  ```ts
31
34
  // tsconfig.json for an iOS app: "customConditions": ["ios"]
@@ -129,6 +132,7 @@ pnpm -F @astryxdesign/native typecheck # source and tests
129
132
  pnpm -F @astryxdesign/native build # dist/, including platform types
130
133
  pnpm -F @astryxdesign/native typecheck:types # every platform's types, after build
131
134
  pnpm -F @astryxdesign/native generate:apple # regenerate apple/Sources/.../Generated
135
+ pnpm -F @astryxdesign/native generate:swift-ios # regenerate the Astryx product's typed tokens, every published theme, and strings
132
136
  pnpm vitest run --project node packages/native
133
137
  ```
134
138
 
@@ -1,18 +1,41 @@
1
1
  // swift-tools-version: 6.0
2
2
  // Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
 
4
- // Experimental Astryx for Apple platforms (AST-082). The contract types under
5
- // Sources/AstryxNative/Generated are generated by `pnpm generate:apple`; do not
6
- // edit them by hand.
4
+ // Experimental Astryx for Apple platforms (AST-082). Two products:
5
+ // - `Astryx`: SwiftUI views painted with the theme's tokens, the theme
6
+ // environment, and core's localized messages (Sources/Astryx).
7
+ // - `AstryxNative`: the contract types generated by `pnpm generate:apple`
8
+ // (Sources/AstryxNative/Generated; do not edit them by hand) and the logic
9
+ // host.
10
+ // Page templates are a separate package in Templates/, with no products,
11
+ // because they are clone-only source and are never published.
7
12
 
8
13
  import PackageDescription
9
14
 
10
15
  let package = Package(
11
16
  name: "AstryxNative",
17
+ defaultLocalization: "en",
12
18
  platforms: [.iOS(.v17), .macOS(.v14)],
13
- products: [.library(name: "AstryxNative", targets: ["AstryxNative"])],
19
+ products: [
20
+ .library(name: "Astryx", targets: ["Astryx"]),
21
+ .library(name: "AstryxNative", targets: ["AstryxNative"]),
22
+ ],
14
23
  targets: [
15
24
  .target(name: "AstryxNative", path: "Sources/AstryxNative"),
25
+ // Resources holds core's catalog messages per locale, generated.
26
+ .target(
27
+ name: "Astryx",
28
+ dependencies: ["AstryxNative"],
29
+ path: "Sources/Astryx",
30
+ // Each component's spec lives beside its view (AST-093 FR1).
31
+ exclude: ["Icon/Icon.spec.md"],
32
+ resources: [.process("Resources")]
33
+ ),
16
34
  .testTarget(name: "AstryxNativeTests", dependencies: ["AstryxNative"], path: "Tests/AstryxNativeTests"),
35
+ .testTarget(
36
+ name: "AstryxTests", dependencies: ["Astryx"], path: "Tests/AstryxTests",
37
+ // A tiny image that stands in for an app-shipped icon asset.
38
+ resources: [.process("Resources")]
39
+ ),
17
40
  ]
18
41
  )
@@ -0,0 +1,203 @@
1
+ # Astryx for Apple platforms
2
+
3
+ > **Experimental. Canary only.** Part of `@astryxdesign/native`. APIs change
4
+ > without notice.
5
+
6
+ One Swift package with two products:
7
+
8
+ - **`Astryx`**: SwiftUI views painted with the theme's tokens, the theme
9
+ environment, and core's localized messages. It is arm A of the AST-082
10
+ experiment (pure native: platform views painted with Astryx's tokens).
11
+ - **`AstryxNative`**: contract types generated from core's component
12
+ documentation, the wire a TypeScript logic core sends, and the logic host
13
+ that runs one (arm C).
14
+
15
+ Page templates built from the views are a separate package with no products,
16
+ because templates are clone-only and never published.
17
+
18
+ ## Layout
19
+
20
+ ```text
21
+ apple/
22
+ ├── Package.swift # products Astryx and AstryxNative
23
+ ├── Sources/
24
+ │ ├── Astryx/ # SwiftUI views (module Astryx)
25
+ │ │ ├── Theme/ # tokens, the theme environment, Dynamic Type
26
+ │ │ │ └── Generated/ # typed tokens and every published theme, generated; do not edit
27
+ │ │ ├── Resources/ # core's messages per locale, generated; do not edit
28
+ │ │ ├── Localization/
29
+ │ │ ├── Icon/ # Icon, Icon.spec.md
30
+ │ │ ├── Text/ # Text
31
+ │ │ ├── Heading/ # Heading
32
+ │ │ ├── Button/ # Button
33
+ │ │ ├── TextInput/ # TextInput
34
+ │ │ ├── Card/ # Card
35
+ │ │ └── Banner/ # Banner
36
+ │ └── AstryxNative/ # contracts, wire, logic host (module AstryxNative)
37
+ │ └── Generated/ # generated; do not edit
38
+ ├── Tests/
39
+ │ ├── AstryxTests/
40
+ │ └── AstryxNativeTests/
41
+ └── Templates/ # page templates to copy; its own package, never published
42
+ ├── Package.swift # no products; compiles and tests the templates
43
+ ├── Login/ # LoginTemplate, from `astryx template login`
44
+ └── Tests/
45
+ ```
46
+
47
+ - **`Sources/Astryx/<Name>/`** holds one folder per component, named as in
48
+ `packages/core/src/<Name>/`. Each view has core's component name in the
49
+ `Astryx` module (`Button`, `Text`), which re-exports SwiftUI and the
50
+ generated contracts, so an app file writes `import Astryx` alone. In a file
51
+ that also imports SwiftUI, write `Astryx.Button` and `SwiftUI.Button`. A
52
+ component's parameters use core's prop names
53
+ and values (`variant: .primary`, `size: .lg`, `isLoading`), so code reads
54
+ the same across web and native. `Text`, `Heading`, and `Card` take the
55
+ generated `TextProps`, `HeadingProps`, and `CardProps`, as AST-093 FR5 asks;
56
+ the others keep four exceptions, the interim shape FR5 exempts until they move onto the generated
57
+ contracts:
58
+ - `Button` takes `action` where core has `onClick`.
59
+ - `Button` takes `fillsWidth` where core has `width="100%"`.
60
+ - `Button` takes `icon` as a shared icon name (`"search"`), which the
61
+ generated `ButtonProps` does not carry yet.
62
+ - `TextInput` takes a `Binding` where core has `value` and `onChange`.
63
+ - **`Templates/`** holds one folder per page template, named after the
64
+ `astryx template` id. Templates are clone-only, as on the web: you copy a
65
+ template's folder into your app and own it from then on. They are a
66
+ separate package with no products, so nothing imports them, and
67
+ `@astryxdesign/native` leaves them out of its npm package. A template is
68
+ built only from `Astryx` views and SwiftUI layout, and matches the web
69
+ template's content and states. Rules a template needs, such as validation,
70
+ live in a plain value type beside the view so tests can check them without a
71
+ screen.
72
+
73
+ ## Use it
74
+
75
+ Depend on the `Astryx` product. To start from a template, copy its folder,
76
+ such as `Templates/Login/`, into your app's sources; it then belongs to your
77
+ app.
78
+
79
+ ```swift
80
+ import Astryx
81
+
82
+ @main
83
+ struct DemoApp: App {
84
+ var body: some Scene {
85
+ WindowGroup {
86
+ LoginTemplate().astryxTheme() // copied from Templates/Login/
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ `astryxTheme(_:)` paints a subtree with a theme; without it, components use
93
+ core's default theme. Either way they follow Dark Mode and the person's text
94
+ size.
95
+
96
+ ## Theme tokens
97
+
98
+ Components read every color, size, and font from the `astryx` environment
99
+ value, never from a constant of their own. `astryx.tokens` holds the theme's
100
+ tokens in the current mode as typed members (`tokens.color.textPrimary`,
101
+ `tokens.space.s4`, `tokens.font.body.size`), so a misspelled token fails to
102
+ compile. Font tokens come grouped: each type style (`tokens.font.body`,
103
+ `tokens.font.heading1`) holds its `size`, `weight`, and `leading`, and
104
+ `tokens.font.family`, `.size`, and `.weight` hold the scales. Text sizes grow with Dynamic Type. The components still read some
105
+ tokens by core's name (`astryx.color("color-accent")`); moving them onto the
106
+ typed members comes next.
107
+
108
+ `Icon(.search)` draws a shared icon name as the platform's SF Symbol, at
109
+ core's icon size and color, hidden from VoiceOver unless it has a `label`.
110
+ `IconName` holds every built-in name as a static member; a theme maps a name
111
+ to another symbol or to an image the app ships, or registers a
112
+ `<library>:<name>` name, with
113
+ `Theme(…, icons: ["acme:rocket": "airplane", "close": .assetName("brand.close")])`.
114
+ An asset the app does not ship stops a development build with a message that
115
+ names it, and draws nothing in a release build.
116
+
117
+ Font families come from the theme's `font-family-*` stacks: the first family
118
+ the device has wins, and a system family such as `-apple-system` or
119
+ `sans-serif` is the system font. Icons use core's shared icon names
120
+ (`success`, `warning`, …), drawn as an SF Symbol by default; a theme replaces
121
+ one with `Theme(…, icons: ["success": "checkmark.seal.fill"])`.
122
+
123
+ `Sources/Astryx/Theme/Generated/` is written by the Swift theme generator
124
+ (`../specs/swift/library/theme-generator.md`) from core's own resolver, light
125
+ and dark:
126
+
127
+ - `Tokens.swift`: the typed token surface, from core's token names.
128
+ - One `<Name>Theme.swift` per theme, declaring `Theme.<name>`: core's
129
+ defaults (`.default`) and every published theme package (`.butter`,
130
+ `.chocolate`, `.gothic`, `.matcha`, `.neutral`, `.stone`, `.y2k`).
131
+
132
+ ```swift
133
+ LoginTemplate().astryxTheme(.neutral)
134
+ ```
135
+
136
+ Regenerate after a theme or core token change:
137
+
138
+ ```sh
139
+ pnpm -F @astryxdesign/native generate:swift-ios
140
+ ```
141
+
142
+ A product generates its own theme the same way, from its theme's module and
143
+ export:
144
+
145
+ ```sh
146
+ node packages/native/scripts/swift-ios-theme.mjs --theme ./src/acmeTheme.ts#acmeTheme --out ./Sources/Theme
147
+ ```
148
+
149
+ A theme's local tokens are not generated yet; the generator names each one it
150
+ leaves out.
151
+
152
+ **Fonts.** A theme's font families are carried as data. Astryx never bundles
153
+ a font: a component walks the theme's family list in order and uses the first
154
+ family the app has registered; a system family in the list (such as
155
+ `-apple-system` or `sans-serif`) is the system font, and a list with no
156
+ registered family falls back to the system font. To draw a theme's brand face, bundle and register it
157
+ in the app. Faces the published themes name (body, heading, code):
158
+
159
+ | Theme | Faces to bundle |
160
+ | ------------ | ------------------------------------------ |
161
+ | `.default` | none (system fonts) |
162
+ | `.butter` | Outfit, JetBrains Mono |
163
+ | `.chocolate` | Albert Sans, Fraunces, JetBrains Mono |
164
+ | `.gothic` | Fustat, JetBrains Mono |
165
+ | `.matcha` | DM Sans, Playwrite US Trad, JetBrains Mono |
166
+ | `.neutral` | Figtree |
167
+ | `.stone` | Figtree, Montserrat, JetBrains Mono |
168
+ | `.y2k` | Poppins, JetBrains Mono |
169
+
170
+ The same command writes
171
+ `Sources/Astryx/Resources/<locale>.lproj/Localizable.strings` from core's
172
+ locale catalogs, so words the components speak to assistive technology, such
173
+ as a loading button's "Loading", follow the person's language. Tests in
174
+ `@astryxdesign/native` fail when either committed output drifts from core.
175
+
176
+ ## Working on it
177
+
178
+ On a Mac with Xcode or the Swift command-line tools:
179
+
180
+ ```sh
181
+ cd packages/native/apple
182
+ swift test # both products
183
+ cd Templates && swift test # templates, against the Astryx product
184
+ ```
185
+
186
+ Both packages also declare macOS 14 so they build and test on a Mac without a
187
+ simulator; iOS 17 is the target. Open `Templates/Package.swift` in Xcode to
188
+ run `LoginTemplate` in an iOS simulator through its preview.
189
+
190
+ To add a component, create `Sources/Astryx/<Name>/<Name>.swift` declaring
191
+ `<Name>` with core's prop names, writing `SwiftUI.<Name>` wherever it means the
192
+ system type, read its tokens from `astryx`, and add tests under
193
+ `Tests/AstryxTests/`. To add a template, create
194
+ `Templates/<Name>/<Name>Template.swift` from the output of
195
+ `astryx template <id>`, with tests under `Templates/Tests/`.
196
+
197
+ ## Not here yet
198
+
199
+ - The views do not use the generated contract types in `AstryxNative` yet.
200
+ Moving them onto those types is how a core prop change reaches Swift.
201
+ - Pixel and behavior parity with the web components has not been measured.
202
+ - Increase Contrast, theme-local tokens, and platform theme entries
203
+ (`defineNativeTheme`, reserved as `Theme.native`) are not wired in.
@@ -0,0 +1,80 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import SwiftUI
4
+
5
+ /// Core's `Banner` statuses.
6
+ public enum AstryxBannerStatus: String, CaseIterable, Sendable {
7
+ case info
8
+ case warning
9
+ case error
10
+ case success
11
+
12
+ /// The shared icon name for this status (AST-082 FR17), drawn as the
13
+ /// theme's or the platform's symbol for it.
14
+ var iconName: String { rawValue }
15
+
16
+ var groundToken: String {
17
+ switch self {
18
+ case .info: "color-accent-muted"
19
+ case .warning: "color-warning-muted"
20
+ case .error: "color-error-muted"
21
+ case .success: "color-success-muted"
22
+ }
23
+ }
24
+
25
+ var iconToken: String {
26
+ switch self {
27
+ case .info: "color-accent"
28
+ case .warning: "color-warning"
29
+ case .error: "color-error"
30
+ case .success: "color-success"
31
+ }
32
+ }
33
+ }
34
+
35
+ /// A message about the page or a section of it. The status sets the color
36
+ /// and icon only; the title must say what happened, because the icon is
37
+ /// decorative to VoiceOver.
38
+ public struct Banner: View {
39
+ let status: AstryxBannerStatus
40
+ let title: String
41
+ let description: String?
42
+ @Environment(\.astryx) private var astryx
43
+
44
+ public init(status: AstryxBannerStatus, title: String, description: String? = nil) {
45
+ self.status = status
46
+ self.title = title
47
+ self.description = description
48
+ }
49
+
50
+ public var body: some View {
51
+ HStack(alignment: .firstTextBaseline, spacing: astryx.space(2)) {
52
+ if let icon = astryx.icon(status.iconName) {
53
+ // Sized with the title so it grows with Dynamic Type.
54
+ icon.sized(astryx.fontSize("text-body-size", 14))
55
+ .font(astryx.font(size: "text-body-size", 14, weight: "text-body-weight"))
56
+ .foregroundStyle(astryx.color(status.iconToken))
57
+ .accessibilityHidden(true)
58
+ }
59
+ VStack(alignment: .leading, spacing: astryx.space(1)) {
60
+ Text(title, weight: .semibold)
61
+ if let description {
62
+ Text(description, color: .secondary)
63
+ }
64
+ }
65
+ .frame(maxWidth: .infinity, alignment: .leading)
66
+ }
67
+ .padding(astryx.space(3))
68
+ .background(
69
+ RoundedRectangle(cornerRadius: astryx.size("radius-container", 12), style: .continuous)
70
+ .fill(astryx.color(status.groundToken))
71
+ )
72
+ .accessibilityElement(children: .ignore)
73
+ .accessibilityLabel(SwiftUI.Text(accessibilityText))
74
+ }
75
+
76
+ /// What VoiceOver reads: the title, then the description.
77
+ var accessibilityText: String {
78
+ description.map { "\(title), \($0)" } ?? title
79
+ }
80
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ extension View {
4
+ /// Core's base props on a view: `id` names it for UI tests, and `isHidden`
5
+ /// removes it from layout and from assistive technology, as core's `hidden`
6
+ /// attribute does.
7
+ @ViewBuilder func astryxBase(_ base: AstryxBaseProps) -> some View {
8
+ if base.isHidden == true {
9
+ EmptyView()
10
+ } else if let id = base.id {
11
+ accessibilityIdentifier(id)
12
+ } else {
13
+ self
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,168 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // Adapted from github.com/ejc3/astryx-swift (MIT).
3
+
4
+ import SwiftUI
5
+
6
+ /// Core's `Button` variants.
7
+ public enum AstryxButtonVariant: String, CaseIterable, Sendable {
8
+ case primary
9
+ case secondary
10
+ case ghost
11
+ case destructive
12
+ }
13
+
14
+ /// Core's `Button` sizes: `size-element-sm`, `-md`, and `-lg` high.
15
+ public enum AstryxButtonSize: String, CaseIterable, Sendable {
16
+ case sm
17
+ case md
18
+ case lg
19
+
20
+ var heightToken: String { "size-element-\(rawValue)" }
21
+ var fallbackHeight: CGFloat {
22
+ switch self {
23
+ case .sm: 28
24
+ case .md: 32
25
+ case .lg: 36
26
+ }
27
+ }
28
+ }
29
+
30
+ /// A labeled action, painted with the theme's tokens. The tap area reaches
31
+ /// the platform's 44-by-44-point minimum even when the drawn button is smaller.
32
+ public struct Button: View {
33
+ let label: String
34
+ let variant: AstryxButtonVariant
35
+ let size: AstryxButtonSize
36
+ let icon: String?
37
+ let isLoading: Bool
38
+ let isDisabled: Bool
39
+ let fillsWidth: Bool
40
+ let action: () -> Void
41
+ @Environment(\.astryx) private var astryx
42
+
43
+ /// - Parameters:
44
+ /// - icon: a shared icon name, such as `"search"`, shown before the
45
+ /// label; the theme's symbol for it, else the platform default.
46
+ /// - fillsWidth: the button takes the whole width it is offered, as
47
+ /// core's `width="100%"` does.
48
+ public init(
49
+ label: String,
50
+ variant: AstryxButtonVariant = .secondary,
51
+ size: AstryxButtonSize = .md,
52
+ icon: String? = nil,
53
+ isLoading: Bool = false,
54
+ isDisabled: Bool = false,
55
+ fillsWidth: Bool = false,
56
+ action: @escaping () -> Void
57
+ ) {
58
+ self.label = label
59
+ self.variant = variant
60
+ self.size = size
61
+ self.icon = icon
62
+ self.isLoading = isLoading
63
+ self.isDisabled = isDisabled
64
+ self.fillsWidth = fillsWidth
65
+ self.action = action
66
+ }
67
+
68
+ public var body: some View {
69
+ SwiftUI.Button(action: activate) {
70
+ // The label keeps its place while loading so the width holds; the
71
+ // spinner draws over it.
72
+ HStack(spacing: astryx.space(2)) {
73
+ if let icon, let image = astryx.icon(icon) {
74
+ // An asset matches the label's text size, as a symbol does.
75
+ image.sized(astryx.fontSize("text-label-size", 14))
76
+ }
77
+ SwiftUI.Text(label).lineLimit(1)
78
+ }
79
+ .opacity(isLoading ? 0 : 1)
80
+ .overlay {
81
+ if isLoading {
82
+ ProgressView().controlSize(.small).tint(foreground)
83
+ }
84
+ }
85
+ }
86
+ .buttonStyle(
87
+ AstryxButtonStyle(
88
+ astryx: astryx,
89
+ size: size,
90
+ fillsWidth: fillsWidth,
91
+ foreground: foreground,
92
+ background: background
93
+ )
94
+ )
95
+ // As core's Button: a loading button stays undimmed and focusable, keeps
96
+ // its label, and says Loading; taps do nothing until it finishes.
97
+ .disabled(isDisabled)
98
+ .accessibilityLabel(SwiftUI.Text(accessibilityText))
99
+ .accessibilityAddTraits(Self.accessibilityTraits)
100
+ .accessibilityValue(SwiftUI.Text(loadingValue ?? ""))
101
+ .onChange(of: isLoading) { _, loading in
102
+ if loading { AccessibilityNotification.Announcement(AstryxStrings.buttonLoading).post() }
103
+ }
104
+ }
105
+
106
+ /// The button's accessible name: its label, also while loading.
107
+ var accessibilityText: String { label }
108
+
109
+ /// The traits assistive technology gets: a button.
110
+ static var accessibilityTraits: AccessibilityTraits { .isButton }
111
+
112
+ /// What assistive technology reads after the label while loading: core's
113
+ /// catalog message, in the person's language.
114
+ var loadingValue: String? { isLoading ? AstryxStrings.buttonLoading : nil }
115
+
116
+ /// Runs the action unless the button is loading.
117
+ func activate() {
118
+ guard !isLoading else { return }
119
+ action()
120
+ }
121
+
122
+ private var foreground: Color {
123
+ switch variant {
124
+ case .primary: astryx.color("color-on-accent")
125
+ case .destructive: astryx.color("color-on-error")
126
+ case .secondary, .ghost: astryx.color("color-text-primary")
127
+ }
128
+ }
129
+
130
+ private var background: Color {
131
+ switch variant {
132
+ case .primary: astryx.color("color-accent")
133
+ case .destructive: astryx.color("color-error")
134
+ case .secondary: astryx.color("color-neutral")
135
+ case .ghost: .clear
136
+ }
137
+ }
138
+ }
139
+
140
+ struct AstryxButtonStyle: ButtonStyle {
141
+ let astryx: AstryxStyle
142
+ let size: AstryxButtonSize
143
+ let fillsWidth: Bool
144
+ let foreground: Color
145
+ let background: Color
146
+ @Environment(\.isEnabled) private var isEnabled
147
+
148
+ func makeBody(configuration: Configuration) -> some View {
149
+ let shape = RoundedRectangle(
150
+ cornerRadius: astryx.size("radius-element", 8),
151
+ style: .continuous
152
+ )
153
+ // Grows with text size, but not so far that one line of a large label
154
+ // becomes a tall slab.
155
+ let height = astryx.size(size.heightToken, size.fallbackHeight) * min(astryx.textScale, 1.4)
156
+ configuration.label
157
+ .font(astryx.font(size: "text-label-size", 14, weight: "text-label-weight"))
158
+ .foregroundStyle(foreground)
159
+ .padding(.horizontal, astryx.space(3))
160
+ .frame(maxWidth: fillsWidth ? .infinity : nil, minHeight: height)
161
+ .background(shape.fill(background))
162
+ .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5)
163
+ // Drawn at the token size; laid out at least 44 by 44 so the whole
164
+ // platform-minimum tap area counts.
165
+ .frame(minWidth: 44, minHeight: 44)
166
+ .contentShape(Rectangle())
167
+ }
168
+ }
@@ -0,0 +1,106 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /// A card: one independent item on the theme's card ground. It takes core's
4
+ /// Card props (`CardProps`) and stacks its content top to bottom, as children
5
+ /// flow inside core's Card.
6
+ public struct Card<Content: View>: View {
7
+ public let props: CardProps
8
+ let content: Content
9
+ @Environment(\.astryx) private var astryx
10
+
11
+ /// - Parameters:
12
+ /// - padding: core's `padding`, a step on the spacing scale; step 4 when
13
+ /// nil.
14
+ /// - variant: core's `variant`: the card ground, or `transparent` for none.
15
+ /// Only `default` draws a border.
16
+ /// - elevation: core's `elevation`, the theme's shadow at that depth.
17
+ /// - base: core's base props.
18
+ /// - content: core's `children`.
19
+ public init(
20
+ padding: CardPadding? = nil,
21
+ variant: CardVariant? = nil,
22
+ elevation: CardElevation? = nil,
23
+ base: AstryxBaseProps = AstryxBaseProps(),
24
+ @ViewBuilder content: () -> Content
25
+ ) {
26
+ self.props = CardProps(padding: padding, variant: variant, elevation: elevation, base: base)
27
+ self.content = content()
28
+ }
29
+
30
+ public var body: some View {
31
+ let shape = RoundedRectangle(cornerRadius: astryx.tokens.radius.container, style: .continuous)
32
+ let variant = props.variant ?? .default
33
+ // The border sits inside the padding, so the content's inset is the
34
+ // padding step, as in core.
35
+ SwiftUI.VStack(alignment: .leading, spacing: 0) { content }
36
+ .padding(padding)
37
+ .frame(maxWidth: .infinity, alignment: .leading)
38
+ .background(shape.fill(Self.ground(variant, astryx.tokens.color)))
39
+ .overlay {
40
+ if variant == .default {
41
+ shape.strokeBorder(astryx.tokens.color.border, lineWidth: astryx.tokens.size.borderWidth)
42
+ }
43
+ }
44
+ .astryxShadow(Self.shadow(props.elevation ?? .none, astryx.tokens.shadow), in: shape)
45
+ .astryxBase(props.base)
46
+ }
47
+
48
+ var padding: CGFloat {
49
+ let space = astryx.tokens.space
50
+ switch props.padding ?? .v4 {
51
+ case .v0: return space.s0
52
+ case .v0_5: return space.s0_5
53
+ case .v1: return space.s1
54
+ case .v1_5: return space.s1_5
55
+ case .v2: return space.s2
56
+ case .v3: return space.s3
57
+ case .v4: return space.s4
58
+ case .v5: return space.s5
59
+ case .v6: return space.s6
60
+ case .v8: return space.s8
61
+ case .v10: return space.s10
62
+ }
63
+ }
64
+
65
+ /// The ground core's Card draws for a variant.
66
+ static func ground(_ variant: CardVariant, _ color: ColorTokens) -> Color {
67
+ switch variant {
68
+ case .default: color.backgroundCard
69
+ case .transparent: .clear
70
+ case .muted: color.backgroundMuted
71
+ case .blue: color.backgroundBlue
72
+ case .cyan: color.backgroundCyan
73
+ case .gray: color.backgroundGray
74
+ case .green: color.backgroundGreen
75
+ case .orange: color.backgroundOrange
76
+ case .pink: color.backgroundPink
77
+ case .purple: color.backgroundPurple
78
+ case .red: color.backgroundRed
79
+ case .teal: color.backgroundTeal
80
+ case .yellow: color.backgroundYellow
81
+ }
82
+ }
83
+
84
+ /// The theme's shadow at an elevation.
85
+ static func shadow(_ elevation: CardElevation, _ shadow: ShadowTokens) -> [ShadowLayer] {
86
+ switch elevation {
87
+ case .none: []
88
+ case .low: shadow.low
89
+ case .med: shadow.med
90
+ case .high: shadow.high
91
+ }
92
+ }
93
+ }
94
+
95
+ extension Card where Content == AstryxNodeList {
96
+ /// A card from core's props, with its children as the wire tree a logic
97
+ /// core sends; `send` carries the children's callbacks back to the core.
98
+ public init(
99
+ _ props: CardProps,
100
+ children: [AstryxNode],
101
+ send: @escaping @Sendable (AstryxAction) -> Void
102
+ ) {
103
+ self.props = props
104
+ self.content = AstryxNodeList(nodes: children, send: send)
105
+ }
106
+ }