stitch-native 0.7.1__py3-none-any.whl

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.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: stitch-native
3
+ Version: 0.7.1
4
+ Summary: Convert Google Stitch screens (HTML + Tailwind) into native SwiftUI, Jetpack Compose and HTML. CLI + MCP server.
5
+ Author: Rafael Santos
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/rafaelcsan705/stitch-native
8
+ Project-URL: Issues, https://github.com/rafaelcsan705/stitch-native/issues
9
+ Keywords: stitch,swiftui,jetpack-compose,mcp,design-to-code,tailwind
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Software Development :: Code Generators
12
+ Classifier: Environment :: Console
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: license-file
17
+
18
+ <!-- mcp-name: io.github.rafaelcsan705/stitch-native -->
19
+ <p align="center"><img src="assets/logo.svg" width="96" alt="stitch-native logo"></p>
20
+ <h1 align="center">stitch-native</h1>
21
+ <p align="center">Google Stitch screens → native <b>SwiftUI</b>, <b>Jetpack Compose</b> and plain <b>HTML</b>. CLI + MCP server.</p>
22
+ <p align="center">
23
+ <a href="https://github.com/rafaelcsan705/stitch-native/actions/workflows/ci.yml"><img src="https://github.com/rafaelcsan705/stitch-native/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
24
+ <img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python 3.10+">
25
+ <img src="https://img.shields.io/badge/MCP-stdio-8a63d2" alt="MCP">
26
+ <img src="https://img.shields.io/badge/license-MIT-green" alt="MIT">
27
+ </p>
28
+
29
+ ![From Stitch HTML to SwiftUI and Compose](assets/hero.svg)
30
+
31
+ ## Quick start
32
+
33
+ ```bash
34
+ uvx --from git+https://github.com/rafaelcsan705/stitch-native stitch-native swiftui screen.html > Screen.swift
35
+ ```
36
+
37
+ ## Add to your agent
38
+
39
+ | Client | Config |
40
+ |---|---|
41
+ | Claude Code | `claude mcp add stitch-native -- uvx --from git+https://github.com/rafaelcsan705/stitch-native stitch-native-mcp` |
42
+ | Claude Desktop / Cursor / VS Code | see JSON below |
43
+
44
+ ```json
45
+ { "mcpServers": { "stitch-native": {
46
+ "command": "uvx",
47
+ "args": ["--from", "git+https://github.com/rafaelcsan705/stitch-native", "stitch-native-mcp"] } } }
48
+ ```
49
+
50
+ Tools: `stitch_to_native`, `stitch_to_swiftui`, `stitch_to_compose`, `stitch_to_html`, `extract_tokens`, `stitch_to_ir`, `init_config` (source: `html`, `path` or `url`). Prompt: `convert_screen`. Resources: token-map and IR docs.
51
+
52
+ ## How it works
53
+
54
+ ```
55
+ Stitch HTML + tailwind.config → DOM → IR (JSON: box / text / icon / image + styles) → emitter
56
+ ```
57
+
58
+ 1. Reads the Tailwind theme Stitch embeds (`colors`, `spacing`, `borderRadius`, `fontFamily`, `fontSize`).
59
+ 2. Resolves each element's classes into a small layout IR (row / column / grid, padding, gap, radius, borders, text styles).
60
+ 3. Emits SwiftUI, Compose or HTML. Colours that are not theme tokens are reported as off-token literals.
61
+
62
+ ## Usage
63
+
64
+ ```bash
65
+ python3 stitch_native.py swiftui screen.html --name MatchStatsView > MatchStatsView.swift
66
+ python3 stitch_native.py compose screen.html --name MatchStatsScreen > MatchStatsScreen.kt
67
+ python3 stitch_native.py tokens screen.html > StitchTheme.swift
68
+ python3 stitch_native.py tokens-kotlin screen.html > StitchTheme.kt
69
+ python3 stitch_native.py html screen.html --name MatchStats > MatchStats.html
70
+ python3 stitch_native.py tokens-css screen.html > tokens.css
71
+ python3 stitch_native.py ir screen.html > screen.ir.json
72
+
73
+ # State mode: stateless screen + State struct/sample, keys, callbacks (no ViewModel)
74
+ python3 stitch_native.py swiftui fixtures/fornada-encomendas.html --name OrdersListView --mode state
75
+ python3 stitch_native.py compose fixtures/fornada-encomendas.html --name OrdersListScreen --mode state
76
+ ```
77
+
78
+ `--mode state` reads `locale`, `timeZone`, `currency` and key prefixes from `stitch-native.json`. Plug the screen into your own ViewModel/Coordinator: it only takes `state` and callbacks.
79
+
80
+ #### `state.*` config (all optional)
81
+
82
+ | Key | What it does |
83
+ |---|---|
84
+ | `brand` | Texts bound to `state.brandName` instead of being baked in |
85
+ | `storeField` | Field name for "Brand — Store" texts (default `storeName`) |
86
+ | `prefix`, `keys`, `locale`, `rename` | Key prefix; source text or auto key → final L10n key; locale; rename a row struct or field (`{"Order": "OrderRow", "orderRows": "orders"}`) |
87
+ | `fields` | Semantic names. Key = source text, auto name (`field2`) or `Item.name` (`Order.field1`) → name |
88
+ | `samples` | Sample value by final field name (`Item.name` for row fields; a list gives one value per row; prices take cents). Without it samples are neutral (`Text 1`, `Store 1`) |
89
+ | `money` | `{type, swiftSample, swiftFormat, kotlinType, kotlinSample, kotlinFormat}`; `{cents}` is the sample amount, `{v}` the value expression. The Swift type must be `Equatable` (the state struct is). Without it: `Int`/`Long` cents plus a private `money()` helper |
90
+ | `enums.<name>` | `cases` (source texts), `type`, `current`, `caseNames` (list, or text → name; default `case1`…) |
91
+ | `enums.<name>.existing` | `true` = use the app's own enum: needs `type` (Swift), `kotlinType`, `caseMap` (source text → domain case), optional `kotlinCaseMap` (domain case → Kotlin name). Not declared; the tracker shows only the `caseMap` steps in `cases` order; the generated private helpers `<name>Steps`, `<name>Rank`, `<name>Title` map cases to L10n keys. Two source texts mapped to one domain case are de-duplicated in the steps (first occurrence wins) and share a key |
92
+ | `enums.<name>.domainCases` | Every case of the app's enum, in order. `<name>Title` then gets one L10n key per case and an exhaustive `switch` / `when` (no `default`), so a missing case fails to compile. Cases not in `caseMap` get a key whose text is derived from the case name. Without it the helper keeps a flagged `default` (first step's label). A case that is not a tracker step shows its own label in the status chip; in the tracker every step is pending and none is highlighted |
93
+ | `detail` | `{field, type, fields}` for the active/detail struct (default `active<Item>` / `Active<Item>`), or `false` to keep everything on the root. `fields` lists extra root fields (final names) to move into it, e.g. data bound outside the tracker/lines block; texts rendered outside that block are wrapped in their own `if let active` / `?.let { active -> }` |
94
+
95
+ An existing enum must be a plain case enum (`Hashable`, no payloads). The Swift generated code uses `Order.Status`-style names verbatim, so the row struct must not be called `Order` (it is renamed automatically).
96
+
97
+ ### Targets
98
+
99
+ A project declares its ecosystem with `targets` in `stitch-native.json`: any of `swiftui`, `compose`, `html`. Without it (and without a `targets` argument) the tools emit `swiftui` + `compose`, as before. Unknown names are an error that lists the valid ones.
100
+
101
+ ```bash
102
+ python3 stitch_native.py init screen.html --targets swiftui,html # writes only swiftui + html keys, stores targets
103
+ ```
104
+
105
+ - MCP `stitch_to_native` and `init_config` take a `targets` argument (it wins over the config). `stitch_to_native` emits only those targets and their theme files; `init_config` writes only their keys (an iOS-only project gets no `iconsCompose` and no `output.compose`) and never deletes existing entries.
106
+ - Internally one registry (`TARGETS` in `stitch_native.py`: emitter, theme function, fence language, owned config keys) drives the CLI, MCP and `init`, so a new ecosystem is one registry entry plus its emitter.
107
+ - **Config discovery (MCP):** when no `config`, `map` or `config_path` is passed but `path` is, the server reads the nearest `stitch-native.json` next to that file or in a parent directory (up to the filesystem root); otherwise it uses no config. The CLI keeps reading `./stitch-native.json`.
108
+
109
+ ### HTML target
110
+
111
+ `html` writes one self-contained page: a single `<style>` block (tokens as `--color-*`, `--space-*`, `--font-*` custom properties on `:root`, plus generated `.s1`, `.s2`… classes), semantic tags where the export has them (`header`, `nav`, `main`, `section`, `h1`…, `ul`, `table`…), and no Tailwind, no `<script>`, no external URLs. Fonts use the system stack (a token's own font name is tried first). Images keep their `src`; inline `<svg>` becomes an empty `<span>` with a TODO comment.
112
+
113
+ - Material icons become `<span class="icon" data-icon="name">`. Fill them with `iconsHtml` (`{"home": "⌂"}` text or inline `<svg>` markup, used verbatim); unmapped names are listed (`unmapped iconsHtml` in `init`, `unmapped icons` in the report).
114
+ - Colours: `colorsHtml` (token or `#hex` → CSS value) wins; `colors` entries are used only when they already look like a CSS value (`#hex`, `var(...)`, `rgb(...)`…), so a Swift expression shared with the iOS target never lands in the CSS. Off-token literals are reported like for the other targets.
115
+ - Toasts and sheets are emitted `hidden`; top and bottom bars are `position: sticky`.
116
+ - Layout mode only: `--mode state` / `mode: "state"` is an error for `html`; `stitch_to_native` in state mode skips it with a warning.
117
+ - Examples: [`examples/MatchStats.html`](examples/MatchStats.html), [`examples/OrdersList.html`](examples/OrdersList.html).
118
+
119
+ ### Map tokens to your design system
120
+
121
+ ```json
122
+ { "colors": { "primary": "DS.Color.accent", "#12241c": "DS.Color.card" },
123
+ "fonts": { "headline-md": "DS.Font.title" } }
124
+ ```
125
+
126
+ ```bash
127
+ python3 stitch_native.py init screen.html # writes stitch-native.json, lists unmapped tokens/icons
128
+ python3 stitch_native.py swiftui screen.html # auto-loads ./stitch-native.json (or --config path)
129
+ ```
130
+
131
+ `stitch-native.json` also takes `targets`, `icons` (Material → SF Symbol), `iconsCompose`
132
+ (Material → `Icons.X.Y`), `iconsHtml`, `colorsHtml`, `preview.colorScheme` and `output` folders. `null` entries fall back to the theme.
133
+
134
+ ## MCP server
135
+
136
+ `stitch_native_mcp.py` exposes the converter to any MCP client (stdio, no dependencies).
137
+
138
+ ```bash
139
+ claude mcp add stitch-native -- python3 /path/to/stitch_native_mcp.py
140
+ ```
141
+
142
+ | Tool | Does |
143
+ |---|---|
144
+ | `extract_tokens` | Theme file for `swiftui`, `compose` or `html` (CSS custom properties) |
145
+ | `stitch_to_ir` | Layout IR as JSON |
146
+ | `stitch_to_swiftui` | SwiftUI view + off-token report |
147
+ | `stitch_to_compose` | Compose composable + off-token report |
148
+ | `stitch_to_html` | Self-contained HTML page + off-token and unmapped-icon report (layout mode) |
149
+ | `stitch_to_native` | The configured targets (default swiftui + compose) in one call, with their theme files |
150
+ | `init_config` | `stitch-native.json` skeleton + unmapped list |
151
+
152
+ Each tool takes `html` (the export) or `path`; the code tools also take `name` and `config` (object) or `config_path` (else the nearest `stitch-native.json` next to `path`).
153
+ Pairs well with the official Stitch MCP: fetch the screen HTML there, convert here.
154
+
155
+ ## Example
156
+
157
+ `fixtures/match-stats.html` → [`examples/MatchStatsView.swift`](examples/MatchStatsView.swift), [`examples/MatchStatsScreen.kt`](examples/MatchStatsScreen.kt) and [`examples/MatchStats.html`](examples/MatchStats.html).
158
+
159
+ ## Status
160
+
161
+ Prototype. Known gaps:
162
+
163
+ - Output not yet compile-checked in CI.
164
+ - SwiftUI drops the font weight when a family token and a `text-*` size class share an element.
165
+ - Absolute positioning, animations and `hover:` states are ignored.
166
+
167
+ Roadmap: `visual_diff` tool (render vs Stitch screenshot) and a Claude skill.
168
+
169
+ ## Releasing
170
+
171
+ Pushing a tag `vX.Y.Z` runs `.github/workflows/publish.yml`: tests, build, upload to PyPI (trusted publishing), then publish `server.json` to the MCP registry (GitHub OIDC). No secrets are stored. `pyproject.toml`, both versions in `server.json` and `VERSION` in `stitch_native_mcp.py` must agree (a unit test checks it); the tag must match too.
172
+
173
+ One-time manual step on pypi.org (Account → Publishing → "Add a new pending publisher"), before the first tag:
174
+
175
+ | Field | Value |
176
+ |---|---|
177
+ | PyPI project name | `stitch-native` |
178
+ | Owner | `rafaelcsan705` |
179
+ | Repository name | `stitch-native` |
180
+ | Workflow name | `publish.yml` |
181
+ | Environment name | `pypi` |
182
+
183
+ Optionally create a GitHub environment named `pypi` (Settings → Environments) with required reviewers as a manual gate.
184
+
185
+ ## License
186
+
187
+ MIT
@@ -0,0 +1,8 @@
1
+ stitch_native.py,sha256=yavWtUvPwPN1ZC1xZyUJMPrT-ldFI0n8c5el7ZLIeiI,132291
2
+ stitch_native_mcp.py,sha256=WcU480ROiYZ280zQhKGhi4wNeZRw87XgI0IE-BMOOhE,14952
3
+ stitch_native-0.7.1.dist-info/licenses/LICENSE,sha256=8V6wGEx43tBlfVYRpl3AcWSxgqzw2TjyuU0atX8buPQ,1070
4
+ stitch_native-0.7.1.dist-info/METADATA,sha256=ywmz9Q3MudEuYndy0dNuhvxwledwaq2jkJdum67KjN4,12067
5
+ stitch_native-0.7.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ stitch_native-0.7.1.dist-info/entry_points.txt,sha256=5gp1abDTtWlOhhL_WcDvVGO989g_-M9DKi3sNxvldAM,95
7
+ stitch_native-0.7.1.dist-info/top_level.txt,sha256=cSIey-SKAq0Bor6fJ231w74LurOKDcq9OrVKTNqofV4,32
8
+ stitch_native-0.7.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ stitch-native = stitch_native:cli
3
+ stitch-native-mcp = stitch_native_mcp:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rafael Santos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ stitch_native
2
+ stitch_native_mcp