@snap/valdi 1.0.11 → 1.1.7
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.
- package/.metadata/.bazelrc.template +7 -6
- package/.metadata/MODULE.bazel.template +154 -0
- package/bundled-skills/registry.json +13 -2
- package/bundled-skills/skills/valdi-animations/skill.md +197 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
- package/bundled-skills/skills/valdi-compiler/skill.md +4 -4
- package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +43 -1
- package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
- package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +19 -1
- package/bundled-skills/skills/valdi-localization/skill.md +142 -0
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
- package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
- package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
- package/bundled-skills/skills/valdi-overview/skill.md +7 -4
- package/bundled-skills/skills/valdi-perf/skill.md +223 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +80 -0
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-setup/skill.md +55 -5
- package/bundled-skills/skills/valdi-testing/skill.md +23 -7
- package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
- package/dist/commands/agentCheck.js +184 -0
- package/dist/commands/analyze.js +16 -0
- package/dist/commands/analyze_commands/duplicates.js +134 -0
- package/dist/commands/bootstrap.js +57 -73
- package/dist/commands/build.js +6 -0
- package/dist/commands/doctor.js +42 -266
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect_commands/snapshot.js +71 -6
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/install.js +6 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/projectsync.js +9 -7
- package/dist/commands/skills_commands/install.js +6 -1
- package/dist/commands/skills_commands/update.js +2 -1
- package/dist/core/analyze/clusterer.js +150 -0
- package/dist/core/analyze/fingerprint.js +2 -0
- package/dist/core/analyze/knownPatterns.js +76 -0
- package/dist/core/analyze/parser.js +177 -0
- package/dist/core/analyze/reporter.js +83 -0
- package/dist/core/analyze/scanner.js +172 -0
- package/dist/core/analyze/similarity.js +56 -0
- package/dist/core/constants.js +6 -3
- package/dist/core/packageFiles.spec.js +1 -1
- package/dist/preview/previewGenerator.js +240 -0
- package/dist/preview/previewGenerator.spec.js +203 -0
- package/dist/preview/viewModelParser.js +86 -0
- package/dist/preview/viewModelParser.spec.js +171 -0
- package/dist/setup/DevSetupHelper.js +0 -54
- package/dist/setup/linuxSetup.js +0 -16
- package/dist/setup/macOSSetup.js +1 -5
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/applicationUtils.js +15 -0
- package/dist/utils/daemonClient.js +3 -1
- package/dist/utils/linuxDistro.js +0 -21
- package/dist/utils/linuxDistro.spec.js +0 -48
- package/dist/utils/skillsAdapters.js +126 -19
- package/dist/utils/skillsAdapters.spec.js +141 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/package.json +16 -8
- package/.metadata/WORKSPACE.template +0 -57
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Valdi Gestures
|
|
2
|
+
|
|
3
|
+
Touch and gesture handling: tap, long press, drag, pinch, and rotate.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
When handling user touch interactions beyond basic `onTap` — drag-to-reorder, pinch-to-zoom, long press menus, custom gesture recognition.
|
|
8
|
+
|
|
9
|
+
## Key concepts
|
|
10
|
+
|
|
11
|
+
Valdi gesture handling is **attribute-based on `<view>` elements**. Each gesture type has three attributes:
|
|
12
|
+
- `on<Gesture>` — the callback
|
|
13
|
+
- `<gesture>Enabled` — boolean to enable/disable (default: true when callback is set)
|
|
14
|
+
- `on<Gesture>Predicate` — function returning boolean, controls whether the gesture should fire
|
|
15
|
+
|
|
16
|
+
The topmost visible element with a matching gesture wins. Conflicting gestures on parent elements are suppressed.
|
|
17
|
+
|
|
18
|
+
## TouchEvent interface
|
|
19
|
+
|
|
20
|
+
All gesture callbacks receive a `TouchEvent` (or extension of it):
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
interface TouchEvent {
|
|
24
|
+
x: number; // X relative to the element
|
|
25
|
+
y: number; // Y relative to the element
|
|
26
|
+
absoluteX: number; // X relative to root Valdi view
|
|
27
|
+
absoluteY: number; // Y relative to root Valdi view
|
|
28
|
+
pointerCount: number;
|
|
29
|
+
pointerLocations: Pointer[];
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Basic gestures
|
|
34
|
+
|
|
35
|
+
### onTap
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
// ✅ Simple tap handler
|
|
39
|
+
<view onTap={this.handleTap}>
|
|
40
|
+
<label value="Tap me" />
|
|
41
|
+
</view>
|
|
42
|
+
|
|
43
|
+
private handleTap = (event: TouchEvent) => {
|
|
44
|
+
console.log(`Tapped at ${event.x}, ${event.y}`);
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### onDoubleTap
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
// ✅ Double tap to zoom
|
|
52
|
+
<view onDoubleTap={this.handleDoubleTap}>
|
|
53
|
+
<image src={this.viewModel.photo} />
|
|
54
|
+
</view>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### onLongPress
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
// ✅ Long press with custom duration
|
|
61
|
+
<view
|
|
62
|
+
onLongPress={this.handleLongPress}
|
|
63
|
+
longPressDuration={500} // milliseconds before trigger
|
|
64
|
+
>
|
|
65
|
+
<label value="Hold me" />
|
|
66
|
+
</view>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Continuous gestures
|
|
70
|
+
|
|
71
|
+
### onDrag
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
// ✅ Drag to move — fires continuously during the drag
|
|
75
|
+
<view onDrag={this.handleDrag}>
|
|
76
|
+
<label value="Drag me" />
|
|
77
|
+
</view>
|
|
78
|
+
|
|
79
|
+
private handleDrag = (event: DragEvent) => {
|
|
80
|
+
// event extends TouchEvent with drag-specific data
|
|
81
|
+
this.cardRef.setAttribute('translateX', event.x);
|
|
82
|
+
this.cardRef.setAttribute('translateY', event.y);
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### onPinch
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
// ✅ Pinch to zoom — requires 2+ pointers
|
|
90
|
+
<view onPinch={this.handlePinch}>
|
|
91
|
+
<image src={this.viewModel.photo} ref={this.imageRef} />
|
|
92
|
+
</view>
|
|
93
|
+
|
|
94
|
+
private handlePinch = (event: PinchEvent) => {
|
|
95
|
+
this.imageRef.setAttribute('scale', event.scale);
|
|
96
|
+
};
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### onRotate
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
// ✅ Rotate with two fingers — requires 2+ pointers
|
|
103
|
+
<view onRotate={this.handleRotate}>
|
|
104
|
+
<image src={this.viewModel.sticker} ref={this.stickerRef} />
|
|
105
|
+
</view>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Simultaneous gestures
|
|
109
|
+
|
|
110
|
+
`onDrag`, `onPinch`, and `onRotate` can run simultaneously. This enables multitouch interactions like pinch-zoom-rotate on a photo:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
// ✅ Combined pinch + drag + rotate on same element
|
|
114
|
+
<view
|
|
115
|
+
onDrag={this.handleDrag}
|
|
116
|
+
onPinch={this.handlePinch}
|
|
117
|
+
onRotate={this.handleRotate}
|
|
118
|
+
>
|
|
119
|
+
<image src={this.viewModel.photo} ref={this.photoRef} />
|
|
120
|
+
</view>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Touch area extension
|
|
124
|
+
|
|
125
|
+
Expand the tappable area beyond the visible bounds:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
// ✅ Small button with larger touch target
|
|
129
|
+
<view
|
|
130
|
+
onTap={this.handleTap}
|
|
131
|
+
touchAreaExtension={10} // extends hit area by 10pt in each direction
|
|
132
|
+
width={24} height={24}
|
|
133
|
+
>
|
|
134
|
+
<image src={SIGIcon.checkmarkFill} />
|
|
135
|
+
</view>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Touch delay in scroll views
|
|
139
|
+
|
|
140
|
+
Inside a `<scroll>`, touches are delayed to avoid conflicts with scrolling:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
// ✅ Delay touch recognition inside scrollable content
|
|
144
|
+
<view
|
|
145
|
+
onTouch={this.handleTouch}
|
|
146
|
+
onTouchDelayDuration={150} // ms before onTouch fires during scroll
|
|
147
|
+
/>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Gesture predicates
|
|
151
|
+
|
|
152
|
+
Control whether a gesture should activate:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
// ✅ Only allow drag when in edit mode
|
|
156
|
+
<view
|
|
157
|
+
onDrag={this.handleDrag}
|
|
158
|
+
onDragPredicate={() => this.state.editMode}
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## onTouch (raw)
|
|
163
|
+
|
|
164
|
+
Low-level touch events that fire on all elements in the hierarchy:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
// ✅ Raw touch tracking — fires for all touch phases
|
|
168
|
+
<view onTouch={this.handleTouch}>
|
|
169
|
+
<label value="Touch me" />
|
|
170
|
+
</view>
|
|
171
|
+
|
|
172
|
+
private handleTouch = (event: TouchEvent) => {
|
|
173
|
+
// Fires on begin, move, end, cancel
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Unlike other gestures, `onTouch` propagates to parents/siblings — it doesn't suppress other handlers.
|
|
178
|
+
|
|
179
|
+
## Common mistakes
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
// ❌ WRONG — React-style event handlers
|
|
183
|
+
<div onClick={handler} /> // ❌ No <div>, no onClick
|
|
184
|
+
<button onMouseDown={handler} /> // ❌ No mouse events
|
|
185
|
+
|
|
186
|
+
// ❌ WRONG — addEventListener
|
|
187
|
+
element.addEventListener('touchstart', handler); // ❌
|
|
188
|
+
|
|
189
|
+
// ❌ WRONG — Gesture on <layout> (use <view>)
|
|
190
|
+
<layout onTap={handler} /> // ❌ Gestures go on <view> elements
|
|
191
|
+
|
|
192
|
+
// ✅ Correct — gestures on <view>
|
|
193
|
+
<view onTap={handler}>
|
|
194
|
+
<layout>
|
|
195
|
+
<label value="Content" />
|
|
196
|
+
</layout>
|
|
197
|
+
</view>
|
|
198
|
+
```
|
|
@@ -118,12 +118,30 @@ valdi inspect snapshot <elementId> <contextId>
|
|
|
118
118
|
valdi inspect snapshot <elementId> <contextId> --output /tmp/my-snap.png
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
Output: `{ path: "/
|
|
121
|
+
Output: `{ path: "/var/folders/.../valdi-snapshot-<elementId>.png" }`
|
|
122
122
|
|
|
123
123
|
The PNG is written to disk. Read it with the `Read` tool to view it visually.
|
|
124
124
|
|
|
125
125
|
**Getting elementId**: Use `element.id` from the `tree` output (a number, e.g. `1`, `5`, `42`).
|
|
126
126
|
|
|
127
|
+
#### Using `--key` instead of numeric IDs (recommended)
|
|
128
|
+
|
|
129
|
+
Instead of looking up numeric element IDs from the tree, use the `--key` flag to resolve by component tag name or element `key` prop:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
valdi inspect snapshot --key PreviewRoot
|
|
133
|
+
valdi inspect snapshot --key weather-card --port 13591
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `--key` flag searches the component tree for a matching tag name or `key` prop and resolves it to the element ID automatically.
|
|
137
|
+
|
|
138
|
+
**This is stable across hot-reloads** — element IDs change on every reload, but component names and `key` props stay the same. Use `--key` instead of numeric IDs to avoid re-querying the tree after each hot-reload cycle.
|
|
139
|
+
|
|
140
|
+
Custom keys can be set on any element in TSX:
|
|
141
|
+
```tsx
|
|
142
|
+
<view key="weather-card" style={styles.card}>
|
|
143
|
+
```
|
|
144
|
+
|
|
127
145
|
---
|
|
128
146
|
|
|
129
147
|
### `valdi inspect heap`
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Valdi Localization
|
|
2
|
+
|
|
3
|
+
Internationalization (i18n) and localized strings in Valdi modules.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
When adding user-visible text that should be translatable across languages.
|
|
8
|
+
|
|
9
|
+
## Key concepts
|
|
10
|
+
|
|
11
|
+
Valdi localization uses **JSON string files** (`strings-en.json`) compiled into type-safe TypeScript accessors. The compiler generates a `Strings.d.ts` file with typed functions for each key. On iOS, strings compile to `.strings` files; on Android, to XML string resources.
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
### 1. Create the strings file
|
|
16
|
+
|
|
17
|
+
Create `strings/strings-en.json` in your module directory:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"hello_world": {
|
|
22
|
+
"defaultMessage": "Hello, world!"
|
|
23
|
+
},
|
|
24
|
+
"welcome_user": {
|
|
25
|
+
"defaultMessage": "Welcome, {name}!",
|
|
26
|
+
"example": "Welcome, Alex!"
|
|
27
|
+
},
|
|
28
|
+
"items_count": {
|
|
29
|
+
"defaultMessage": "{count%d} items remaining",
|
|
30
|
+
"example": "5 items remaining"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Add strings directory to module config
|
|
36
|
+
|
|
37
|
+
In your `module.yaml`:
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
strings_dir: strings
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 3. Generate typed accessors
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
valdi projectsync
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This generates `Strings.d.ts` in your module with typed functions for each key.
|
|
50
|
+
|
|
51
|
+
### 4. Use in TypeScript
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import Strings from 'mymodule/src/Strings';
|
|
55
|
+
|
|
56
|
+
onRender(): void {
|
|
57
|
+
<view>
|
|
58
|
+
<label value={Strings.helloWorld()} />
|
|
59
|
+
<label value={Strings.welcomeUser('Alex')} />
|
|
60
|
+
<label value={Strings.itemsCount(5)} />
|
|
61
|
+
</view>;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## String keys and naming
|
|
66
|
+
|
|
67
|
+
Keys in `strings-en.json` are `snake_case`. The generated TypeScript accessors are `camelCase`:
|
|
68
|
+
|
|
69
|
+
| JSON key | TypeScript accessor |
|
|
70
|
+
|----------|-------------------|
|
|
71
|
+
| `hello_world` | `Strings.helloWorld()` |
|
|
72
|
+
| `items_count` | `Strings.itemsCount(n)` |
|
|
73
|
+
| `welcome_user` | `Strings.welcomeUser(name)` |
|
|
74
|
+
|
|
75
|
+
## Template strings with variables
|
|
76
|
+
|
|
77
|
+
Variables use the format `{NAME%FORMAT}`:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"greeting": {
|
|
82
|
+
"defaultMessage": "Hi {name}, you have {count%d} new messages",
|
|
83
|
+
"example": "Hi Alex, you have 3 new messages"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Supported formats:
|
|
89
|
+
- `{name}` or `{name%s}` — string (default)
|
|
90
|
+
- `{count%d}` — integer
|
|
91
|
+
|
|
92
|
+
Multiple variables must have unique names. Argument order in the TypeScript function matches the order they appear in the English string.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
// ✅ Variables passed in order of appearance in defaultMessage
|
|
96
|
+
Strings.greeting('Alex', 3) // "Hi Alex, you have 3 new messages"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Using strings in Kotlin (Android)
|
|
100
|
+
|
|
101
|
+
Generated strings are accessible as standard Android resources:
|
|
102
|
+
|
|
103
|
+
```kotlin
|
|
104
|
+
val text = getResources().getString(
|
|
105
|
+
com.snap.valdi.modules.my_module.R.string.my_module_hello_world
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Common mistakes
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
// ❌ WRONG — Hardcoding user-visible strings
|
|
113
|
+
<label value="Hello, world!" />
|
|
114
|
+
|
|
115
|
+
// ✅ Correct — use localized strings
|
|
116
|
+
<label value={Strings.helloWorld()} />
|
|
117
|
+
|
|
118
|
+
// ❌ WRONG — Concatenating localized strings
|
|
119
|
+
const msg = Strings.hello() + " " + name; // ❌ Word order varies by language
|
|
120
|
+
|
|
121
|
+
// ✅ Correct — use template strings with variables
|
|
122
|
+
const msg = Strings.helloUser(name);
|
|
123
|
+
|
|
124
|
+
// ❌ WRONG — Constructing plurals in code
|
|
125
|
+
const msg = count === 1 ? "1 item" : `${count} items`; // ❌
|
|
126
|
+
|
|
127
|
+
// ✅ Correct — handle plurals in the string definition
|
|
128
|
+
// (Use a single template string; translation handles pluralization)
|
|
129
|
+
|
|
130
|
+
// ❌ WRONG — Importing from the wrong path
|
|
131
|
+
import Strings from 'Strings'; // ❌
|
|
132
|
+
|
|
133
|
+
// ✅ Correct — import from your module's generated path
|
|
134
|
+
import Strings from 'mymodule/src/Strings';
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Workflow
|
|
138
|
+
|
|
139
|
+
1. Add keys to `strings/strings-en.json`
|
|
140
|
+
2. Run `valdi projectsync` to regenerate `Strings.d.ts`
|
|
141
|
+
3. Import `Strings` from your module and use the generated functions
|
|
142
|
+
4. Valdi tooling handles iOS `.strings` and Android `.xml` generation during build
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
# valdi-mock-breakdown
|
|
2
|
+
|
|
3
|
+
Generate a Valdi TSX component from a screenshot or design mock. Analyzes the visual layout, decomposes it into Valdi primitives and widgets, and produces a complete `.tsx` file.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- User provides a screenshot, Figma export, or design mock and wants Valdi code
|
|
8
|
+
- You're the "generator" in a mock-to-module pipeline
|
|
9
|
+
- User says "build this", "make this screen", or "turn this into code" with an image
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
1. Analyze the image — identify layout structure, components, spacing, colors, typography
|
|
14
|
+
2. Map to Valdi primitives — `<view>`, `<label>`, `<image>`, `<scroll>`, `<shape>`, widgets
|
|
15
|
+
3. Generate a complete `.tsx` file with correct Valdi patterns
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Step 1: Analyze the layout
|
|
20
|
+
|
|
21
|
+
Look at the image and identify, top-to-bottom:
|
|
22
|
+
|
|
23
|
+
- **Overall structure**: Is it a full screen? A card? A list? A form?
|
|
24
|
+
- **Scroll behavior**: Does the content exceed the viewport? Use `<scroll>`.
|
|
25
|
+
- **Sections**: Group visually distinct areas (header, body, footer, list items).
|
|
26
|
+
- **Components**: Buttons, toggles, text inputs, checkboxes, pickers, etc.
|
|
27
|
+
- **Typography**: Title vs body vs caption — map to font sizes.
|
|
28
|
+
- **Colors**: Background, text, accent, divider — use semantic colors when possible.
|
|
29
|
+
- **Spacing**: Estimate padding and margins in 4pt/8pt increments.
|
|
30
|
+
- **Icons/images**: Note placement and sizing.
|
|
31
|
+
|
|
32
|
+
**Report your analysis** before writing code. Example:
|
|
33
|
+
|
|
34
|
+
> I see a vertical layout with:
|
|
35
|
+
> - A top bar with a back button and title ("Settings")
|
|
36
|
+
> - A scrollable list of 5 toggle rows, each with a label and a switch
|
|
37
|
+
> - A footer button ("Save Changes")
|
|
38
|
+
> - White background, 16px side padding, 12px between rows
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Step 2: Choose Valdi elements and widgets
|
|
43
|
+
|
|
44
|
+
### Primitives (always available, no extra deps)
|
|
45
|
+
|
|
46
|
+
Start with primitives to get a bare-bones skeleton on screen fast:
|
|
47
|
+
|
|
48
|
+
| Element | Use for |
|
|
49
|
+
|---------|---------|
|
|
50
|
+
| `<view>` | Containers, layout groups, spacers |
|
|
51
|
+
| `<label>` | All text (titles, body, captions) |
|
|
52
|
+
| `<image>` | Images, icons (use `src` prop with Asset) |
|
|
53
|
+
| `<scroll>` | Scrollable content areas |
|
|
54
|
+
| `<shape>` | Rounded rects, circles, dividers, decorative shapes |
|
|
55
|
+
| `<button>` | Tappable areas (has `title` and `onPress`) |
|
|
56
|
+
|
|
57
|
+
### Then upgrade to widget library components (if available)
|
|
58
|
+
|
|
59
|
+
Once the skeleton is rendering, check the workspace for a shared widget or component library (e.g. in `valdi_modules/widgets/` or a similar path). Pre-built widget components encode design system conventions (correct spacing, fonts, colors, shadows) and produce more accurate results with less hand-tuning.
|
|
60
|
+
|
|
61
|
+
**How to explore**: Search for exported component classes in the workspace's widget directories. Read the component's `ViewModel` interface to understand available props.
|
|
62
|
+
|
|
63
|
+
**Use icon assets instead of emoji** for better fidelity — search the workspace for an icon library class.
|
|
64
|
+
|
|
65
|
+
### Widgets (require module dep)
|
|
66
|
+
|
|
67
|
+
Before using a widget, search the codebase to confirm it exists and read its ViewModel:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Find available widgets
|
|
71
|
+
grep -r "export class" --include="*.tsx" valdi_modules/widgets/src/components/
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Common widgets in `widgets/`:
|
|
75
|
+
- `Checkbox` — toggle with `on`/`onTap`
|
|
76
|
+
- `Toggle` — switch with `on`/`onChange`
|
|
77
|
+
- `Section` — card-style section with title
|
|
78
|
+
- `SectionSeparator` — divider between sections
|
|
79
|
+
- `DatePicker`, `TimePicker`, `IndexPicker` — picker controls
|
|
80
|
+
- `EmojiLabel` — label with emoji rendering support
|
|
81
|
+
- `WithInsets` — safe area inset wrapper
|
|
82
|
+
|
|
83
|
+
**If the design has a component you're not sure about**, use primitives to approximate it rather than guessing a widget name that may not exist.
|
|
84
|
+
|
|
85
|
+
### Mapping visual patterns to elements
|
|
86
|
+
|
|
87
|
+
| Visual pattern | Primitives approach |
|
|
88
|
+
|---------------|---------------------|
|
|
89
|
+
| List row with icon + text | `<view>` with flexDirection row |
|
|
90
|
+
| Card with shadow/border | `<view>` with borderRadius + boxShadow |
|
|
91
|
+
| Section header with action | `<label>` + `<label>` in a row |
|
|
92
|
+
| Horizontal row | `<view>` with `flexDirection: 'row'` |
|
|
93
|
+
| Vertical stack | `<view>` (default column direction) |
|
|
94
|
+
| Divider line | `<view>` with `height: 1`, `backgroundColor: '#E0E0E0'` |
|
|
95
|
+
| Circular icon background | `<view>` with `borderRadius: size/2`, wrapping `<image>` |
|
|
96
|
+
| Tappable row | `onTap` on `<view>` |
|
|
97
|
+
| Scrollable list | `<scroll>` wrapping children |
|
|
98
|
+
| Fixed header + scrolling body | Outer `<view>` with header + `<scroll flexGrow={1}>` body |
|
|
99
|
+
| Spacer between items | margin on children (no `gap` property) |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Step 3: Generate the .tsx file
|
|
104
|
+
|
|
105
|
+
### Template
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { StatefulComponent } from 'valdi_core/src/Component';
|
|
109
|
+
import { Style } from 'valdi_core/src/Style';
|
|
110
|
+
import { View, Label } from 'valdi_tsx/src/NativeTemplateElements';
|
|
111
|
+
// Import widgets as needed:
|
|
112
|
+
// import { Checkbox } from 'widgets/src/components/button/Checkbox';
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @ViewModel
|
|
116
|
+
* @ExportModel
|
|
117
|
+
*/
|
|
118
|
+
export interface ViewModel {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @Context
|
|
122
|
+
* @ExportModel
|
|
123
|
+
*/
|
|
124
|
+
export interface ComponentContext {}
|
|
125
|
+
|
|
126
|
+
interface ComponentState {
|
|
127
|
+
// State for interactive elements
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @Component
|
|
132
|
+
* @ExportModel
|
|
133
|
+
*/
|
|
134
|
+
export class GeneratedComponent extends StatefulComponent<ViewModel, ComponentState, ComponentContext> {
|
|
135
|
+
state: ComponentState = {
|
|
136
|
+
// Initial state values
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
onRender(): void {
|
|
140
|
+
<view style={styles.container}>
|
|
141
|
+
{/* Layout here */}
|
|
142
|
+
</view>;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const styles = {
|
|
147
|
+
container: new Style<View>({
|
|
148
|
+
backgroundColor: '#ffffff',
|
|
149
|
+
width: '100%',
|
|
150
|
+
height: '100%',
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Critical Valdi rules
|
|
156
|
+
|
|
157
|
+
These are **NOT React** — common mistakes that MUST be avoided:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// WRONG: React hooks (don't exist in Valdi)
|
|
161
|
+
const [value, setValue] = useState(''); // WRONG
|
|
162
|
+
|
|
163
|
+
// WRONG: Functional components (don't exist)
|
|
164
|
+
const MyThing = () => <view />; // WRONG
|
|
165
|
+
|
|
166
|
+
// WRONG: Return JSX from onRender
|
|
167
|
+
onRender() { return <view />; } // WRONG — onRender returns void
|
|
168
|
+
|
|
169
|
+
// WRONG: this.props (doesn't exist)
|
|
170
|
+
this.props.title // WRONG — use this.viewModel.title
|
|
171
|
+
|
|
172
|
+
// CORRECT: Class component with state
|
|
173
|
+
class MyComponent extends StatefulComponent<VM, State> {
|
|
174
|
+
state = { value: '' };
|
|
175
|
+
onRender(): void {
|
|
176
|
+
<view />; // Statement, not return value
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Styling guidelines
|
|
182
|
+
|
|
183
|
+
- Use `new Style<View>({...})` for view styles, `new Style<Label>({...})` for label styles
|
|
184
|
+
- Font sizes via font string: `font: 'system 16'`, `font: 'system-bold 20'`
|
|
185
|
+
- Use 8pt grid for spacing: 4, 8, 12, 16, 24, 32, 48
|
|
186
|
+
- Prefer `padding` and `margin` shorthand: `padding: '16 20'` (vertical horizontal)
|
|
187
|
+
- Colors: use hex strings `'#RRGGBB'` or `'#RRGGBBAA'`
|
|
188
|
+
- Layout: Yoga flexbox — `flexDirection`, `justifyContent`, `alignItems`, `flexGrow`
|
|
189
|
+
- No `gap` property — use margin on children instead
|
|
190
|
+
- No `fontSize` — use `font` string on labels
|
|
191
|
+
- Overflow: only `'visible'` or `'scroll'` (NOT `'hidden'`)
|
|
192
|
+
- **`opacity` must be a number**, not a string: `opacity: 0.3` (NOT `'0.3'`)
|
|
193
|
+
- **`flexGrow` must be a number**, not a string: `flexGrow: 1` (NOT `'1'`)
|
|
194
|
+
- **Only two font weights**: `system` (regular) and `system-bold` (bold). `system-semibold`, `system-medium`, etc. silently fall back to regular at runtime.
|
|
195
|
+
- **ScrollView has no `flexDirection`** — `<scroll>` always scrolls vertically, do not set flexDirection on it
|
|
196
|
+
- `boxShadow` format: `'xOffset yOffset blur color'` e.g. `'0 2 8 rgba(0,0,0,0.12)'`
|
|
197
|
+
|
|
198
|
+
### Style pitfalls (common build-breaking mistakes)
|
|
199
|
+
|
|
200
|
+
**Read the valdi-tsx skill's "Common Mistakes to Avoid" section before writing styles.** These cause the most build failures:
|
|
201
|
+
|
|
202
|
+
- No `borderRight`, `borderRightWidth`, etc. — only `borderWidth`, `borderColor`, `borderRadius` exist. Use a thin `<view>` as a divider.
|
|
203
|
+
- No `paddingHorizontal` / `paddingVertical` — use `padding: '10 20'` shorthand.
|
|
204
|
+
- No `flex: 1` — use `flexGrow: 1` (number, not string).
|
|
205
|
+
- `flexGrow` must be a number, not a string.
|
|
206
|
+
- `Shape` is not exported — use `ShapeView` from NativeTemplateElements.
|
|
207
|
+
- `font: 'system-semibold'` doesn't work — use `system-bold` or `system`.
|
|
208
|
+
- `overflow: 'hidden'` doesn't exist — only `'visible'` or `'scroll'`.
|
|
209
|
+
- `flexDirection` on `<scroll>` doesn't exist — ScrollView always scrolls vertically.
|
|
210
|
+
|
|
211
|
+
### Font size calibration (IMPORTANT)
|
|
212
|
+
|
|
213
|
+
Font sizes are the **#1 source of visual mismatch**. Initial instinct is almost always 30-50% too small. Use these reference ranges and scale up from your first guess:
|
|
214
|
+
|
|
215
|
+
| Visual role | Typical range | Example |
|
|
216
|
+
|------------|---------------|---------|
|
|
217
|
+
| Hero / display number | 64–80pt bold | Temperature "75°", score display |
|
|
218
|
+
| Section title | 20–24pt bold | "Settings", screen headers |
|
|
219
|
+
| Primary body text | 20–22pt regular | Descriptions, location names |
|
|
220
|
+
| Secondary label | 17–19pt regular/semibold | Tab labels, row titles |
|
|
221
|
+
| Tertiary / caption | 15–17pt regular | Timestamps, footnotes, axis labels |
|
|
222
|
+
| Small metadata | 12–14pt regular | Badges, counters |
|
|
223
|
+
|
|
224
|
+
**Rule of thumb**: If your first estimate is 16pt, it's probably 20-22pt. If your first estimate is 12pt, it's probably 16-17pt.
|
|
225
|
+
|
|
226
|
+
### Text color calibration
|
|
227
|
+
|
|
228
|
+
Avoid pure `#000000` for most text — real designs use lighter values:
|
|
229
|
+
|
|
230
|
+
| Text role | Color range |
|
|
231
|
+
|----------|-------------|
|
|
232
|
+
| Primary / headings | `#000000` – `#111111` |
|
|
233
|
+
| Body / descriptions | `#333333` – `#555555` |
|
|
234
|
+
| Secondary / metadata | `#888888` – `#AAAAAA` |
|
|
235
|
+
| Tertiary / hints | `#999999` – `#BBBBBB` |
|
|
236
|
+
|
|
237
|
+
### Spacing calibration
|
|
238
|
+
|
|
239
|
+
Vertical spacing between major sections (header → content → footer) is **consistently underestimated**. Use generous gaps:
|
|
240
|
+
|
|
241
|
+
- Between major sections: 28–44pt
|
|
242
|
+
- Between sub-items within a section: 12–20pt
|
|
243
|
+
- Card padding: 28–36pt vertical, 28–32pt horizontal
|
|
244
|
+
- Card border radius: 16–20pt for modern rounded appearance
|
|
245
|
+
|
|
246
|
+
### Charts and data visualization with `<shape>`
|
|
247
|
+
|
|
248
|
+
For line charts, area charts, or custom shapes, use `GeometricPathBuilder`:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { GeometricPathBuilder } from 'valdi_core/src/utils/GeometricPathBuilder';
|
|
252
|
+
|
|
253
|
+
// Create a builder with coordinate space dimensions
|
|
254
|
+
const b = new GeometricPathBuilder(width, height);
|
|
255
|
+
b.moveTo(x, y);
|
|
256
|
+
b.lineTo(x, y);
|
|
257
|
+
b.cubicTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
258
|
+
b.close();
|
|
259
|
+
const path = b.build();
|
|
260
|
+
|
|
261
|
+
// Use the path in a <shape> element
|
|
262
|
+
<shape path={path} strokeColor="#E87A2E" strokeWidth={5}
|
|
263
|
+
strokeCap="round" strokeJoin="round"
|
|
264
|
+
width={width} height={height} />;
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Key patterns for smooth data curves:**
|
|
268
|
+
|
|
269
|
+
1. **Use monotone cubic Hermite interpolation** — prevents overshoot at local extrema. Simple midpoint control points cause curve artifacts.
|
|
270
|
+
2. **Stroke line**: 4–5pt width for prominent lines, `strokeCap="round"` for smooth endpoints.
|
|
271
|
+
3. **Data dots**: 10–12pt diameter circles using `<view>` with `borderRadius`.
|
|
272
|
+
4. **Fill path construction**: `moveTo(firstX, bottomY)` → `lineTo(firstX, firstY)` → trace curve → `lineTo(lastX, bottomY)` → `close()`.
|
|
273
|
+
5. **Fill color**: Use alpha for subtlety, e.g., `"#F5D0A088"`. Don't try layered fills to simulate gradients — they create visible horizontal bands.
|
|
274
|
+
6. **Data labels**: Position above dots with `position="absolute"`, offset `top: y - 30`, centered with fixed-width container.
|
|
275
|
+
|
|
276
|
+
### Naming
|
|
277
|
+
|
|
278
|
+
- Class name: `PascalCase`, descriptive of the screen/component (e.g., `SettingsScreen`, `ProfileCard`)
|
|
279
|
+
- Component file name: match the class name (e.g., `SettingsScreen.tsx`)
|
|
280
|
+
- Styles object: `const styles = { ... }` at bottom of file
|
|
281
|
+
- State interface: descriptive fields (e.g., `toggleOn`, `selectedIndex`, not `s1`, `v`)
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Step 4: Wire interactive state
|
|
286
|
+
|
|
287
|
+
For any interactive elements (toggles, checkboxes, pickers, text inputs):
|
|
288
|
+
|
|
289
|
+
1. Add state fields in the `ComponentState` interface
|
|
290
|
+
2. Set initial values in `state = { ... }`
|
|
291
|
+
3. Wire callbacks with `this.setState()`
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
interface ComponentState {
|
|
295
|
+
notificationsOn: boolean;
|
|
296
|
+
selectedFruit: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Define handlers as class properties (NOT inline arrows in onRender):
|
|
300
|
+
private toggleNotifications = (val: boolean) => this.setState({ notificationsOn: val });
|
|
301
|
+
private selectFruit = (i: number) => this.setState({ selectedFruit: i });
|
|
302
|
+
|
|
303
|
+
// In onRender:
|
|
304
|
+
<Checkbox
|
|
305
|
+
on={this.state.notificationsOn}
|
|
306
|
+
onTap={this.toggleNotifications}
|
|
307
|
+
/>
|
|
308
|
+
|
|
309
|
+
<IndexPicker
|
|
310
|
+
labels={fruitLabels}
|
|
311
|
+
index={this.state.selectedFruit}
|
|
312
|
+
onChange={this.selectFruit}
|
|
313
|
+
/>
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## Output format
|
|
319
|
+
|
|
320
|
+
When generating code for the mock-to-module pipeline, output:
|
|
321
|
+
|
|
322
|
+
1. **Analysis** — your visual breakdown (2-5 sentences)
|
|
323
|
+
2. **Component name** — what to call the generated class
|
|
324
|
+
3. **Full .tsx file** — complete, compilable, with all imports and styles
|
|
325
|
+
4. **Required deps** — list of module deps needed (e.g., `widgets`)
|
|
326
|
+
|
|
327
|
+
When generating code for a preview harness specifically, the component should be a `PreviewRoot` with empty ViewModel/ComponentContext, since it's a standalone root.
|