orvyn-lang 0.2.0 → 0.4.0

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 (63) hide show
  1. package/GUIDE.md +198 -0
  2. package/LANGUAGE.md +818 -30
  3. package/README.md +211 -250
  4. package/brand/orvyn-sunset-animated.svg +15 -0
  5. package/package.json +3 -1
  6. package/src/cli/orvyn.js +207 -16
  7. package/src/core/signal.js +104 -6
  8. package/src/devtools/runtime.js +25 -1
  9. package/src/lang/a11y.js +152 -0
  10. package/src/lang/auth.js +239 -0
  11. package/src/lang/bundle-native.js +10 -6
  12. package/src/lang/codegen.js +615 -58
  13. package/src/lang/device.js +41 -0
  14. package/src/lang/doctor.js +60 -0
  15. package/src/lang/env.js +27 -0
  16. package/src/lang/errors.js +513 -0
  17. package/src/lang/form.js +69 -8
  18. package/src/lang/index.js +2 -1
  19. package/src/lang/lexer.js +2 -0
  20. package/src/lang/list.js +44 -0
  21. package/src/lang/native/android/MainActivity.kt +65 -4
  22. package/src/lang/native/android/OrvynDevice.kt +163 -0
  23. package/src/lang/native/android/OrvynEngine.kt +176 -7
  24. package/src/lang/native/android/OrvynRenderer.kt +970 -50
  25. package/src/lang/native/android.js +74 -11
  26. package/src/lang/native/assets.js +39 -0
  27. package/src/lang/native/build.js +140 -63
  28. package/src/lang/native/compatibility.js +57 -0
  29. package/src/lang/native/config.js +108 -0
  30. package/src/lang/native/ios/OrvynApp.swift +6 -0
  31. package/src/lang/native/ios/OrvynEngine.swift +291 -4
  32. package/src/lang/native/ios/OrvynViews.swift +769 -41
  33. package/src/lang/native/ios.js +81 -2
  34. package/src/lang/native-runtime.js +541 -55
  35. package/src/lang/native-size.js +53 -0
  36. package/src/lang/page-files.js +71 -0
  37. package/src/lang/page.js +63 -0
  38. package/src/lang/parser.js +278 -15
  39. package/src/lang/prerender.js +300 -0
  40. package/src/lang/read-import.js +12 -0
  41. package/src/lang/router.js +266 -0
  42. package/src/lang/runtime-shared.js +796 -10
  43. package/src/lang/runtime.js +399 -51
  44. package/src/lang/select.js +13 -0
  45. package/src/lang/server-code.js +233 -0
  46. package/src/lang/server-export.js +78 -0
  47. package/src/lang/server-libs.js +53 -0
  48. package/src/lang/server.js +409 -0
  49. package/src/lang/style-check.js +60 -0
  50. package/src/lang/test-runner.js +134 -0
  51. package/src/lang/types.js +317 -0
  52. package/src/lang/vite-plugin.js +108 -6
  53. package/src/lang/web-overlay.js +578 -0
  54. package/src/lang/widgets.js +94 -0
  55. package/src/lang/words.js +38 -0
  56. package/src/runtime/animations.js +24 -0
  57. package/src/runtime/appear.js +73 -0
  58. package/src/runtime/marquee.js +57 -0
  59. package/src/runtime/mount.js +120 -27
  60. package/src/runtime/patch.js +90 -11
  61. package/src/runtime/style.js +50 -9
  62. package/src/styling/fluid.js +129 -6
  63. package/src/styling/spec.js +319 -0
package/LANGUAGE.md CHANGED
@@ -34,8 +34,10 @@ orvyn new my-app # creates the app and installs it
34
34
  cd my-app
35
35
 
36
36
  orvyn dev # web → http://localhost:5173, reloads when you save
37
+ orvyn dev --native # web preview using only phone-supported styles (390px)
37
38
  orvyn ios # iPhone simulator, reloads when you save
38
- orvyn android # Android emulator or phone
39
+ orvyn android # Android emulator or phone, with live reload
40
+ orvyn test # run the test blocks in your app
39
41
  orvyn check # find mistakes
40
42
  orvyn build # website → dist/web/
41
43
  orvyn build ios # Xcode project → dist/ios/ (real iPhones, App Store)
@@ -44,6 +46,19 @@ orvyn build android # Android Studio project → dist/android/
44
46
 
45
47
  Your code lives in `src/app.orv`. Orvyn finds it by itself.
46
48
 
49
+ ### Instant updates on the web
50
+
51
+ With `orvyn dev`, saving a `.orv` file swaps the new code in without refreshing the page. App `state` and the current screen stay as they are, so you don't have to click your way back.
52
+
53
+ - State keeps its value unless you change its starting value in the code.
54
+ - `state` inside screens and components is kept too, as is the page's scroll position. If you add or remove items with the same state name, a value may move to a neighbour.
55
+ - Typed text that isn't bound to state, and scrolling inside a box or `List`, start again.
56
+ - `start { }` runs again after an update.
57
+
58
+ ### Live reload on Android
59
+
60
+ `orvyn android` builds and installs the app once, then reloads it whenever you save a `.orv` file. It works on an emulator or a phone with USB debugging (connect one at a time).
61
+
47
62
  ### Live reload on iPhone
48
63
 
49
64
  `orvyn ios` builds the app once, then keeps running:
@@ -103,6 +118,54 @@ screen Home {
103
118
  Imported state stays reactive. Assigning to an imported fixed value or function
104
119
  reports a runtime error explaining that the declaration must use `state`.
105
120
 
121
+ - **Folder imports:** `use Chip from "./components/chip"` automatically finds `./components/chip/index.orv` when `./components/chip.orv` doesn't exist.
122
+ - **Import cycles:** Two `.orv` files may import each other with `use` (for example `nav.orv` importing screens from `app.orv` while `app.orv` imports `Nav`).
123
+ - **Component children (`slot`):** Put `slot` inside a `component` to place caller children there (for shared layouts):
124
+
125
+ ```orv
126
+ component Layout {
127
+ Column {
128
+ Nav
129
+ slot
130
+ Footer
131
+ }
132
+ }
133
+
134
+ screen Home {
135
+ Layout {
136
+ Heading "Welcome"
137
+ }
138
+ }
139
+ ```
140
+
141
+ ### State inside a component or screen
142
+
143
+ Put `state` (or `let`) at the top of a `component` or `screen` to give each one
144
+ its own private value:
145
+
146
+ ```orv
147
+ component Counter(label) {
148
+ state count = 0
149
+
150
+ Row gap: 8 {
151
+ Text "{label}: {count}"
152
+ Button "+", onTap: count += 1
153
+ }
154
+ }
155
+
156
+ screen Home {
157
+ Column gap: 12 {
158
+ Counter label: "First"
159
+ Counter label: "Second"
160
+ }
161
+ }
162
+ ```
163
+
164
+ Each `Counter` keeps its own `count`, survives unrelated updates, and resets when
165
+ it is removed (`if`, list removal, or leaving a `screen` with `go()`). When
166
+ rendering components inside a `for` loop that can reorder, pass `key:` (like
167
+ `Counter label: item.name, key: item.id`) so each item keeps its own state.
168
+
106
169
  ## Statements (inside `fn` and handlers)
107
170
 
108
171
  ```orv
@@ -117,6 +180,8 @@ print("hello") // logs to the console
117
180
 
118
181
  ### Lists and objects
119
182
 
183
+ Shortcut: `{ email, password }` is the same as `{ email: email, password: password }`.
184
+
120
185
  Change them with these, and the screen updates by itself:
121
186
 
122
187
  ```orv
@@ -144,26 +209,84 @@ saved state darkMode = false
144
209
 
145
210
  The value is stored on the device (browser storage on the web, UserDefaults on
146
211
  iPhone, SharedPreferences on Android) and comes back the next time the app opens.
147
- It also survives live reload while you develop.
212
+ It also survives live reload while you develop. Each app and module file gets its own storage namespace automatically so keys never collide.
213
+
214
+ - **Versions & migrations:** Bump the version when saved data changes shape:
215
+ ```orv
216
+ saved(2, old => ({ name: old.name ?? "Guest", plan: "free" })) state profile = { name: "Guest", plan: "free" }
217
+ ```
218
+ `saved(2)` without a migration safely resets older data to the new default.
219
+ - **Reset & storage errors:** Call `profile.reset()` (or `storage.resetAll()`) to reset to default and clear storage. Read `storage.error` (e.g. quota full or corrupted data) and `storage.clearError()`.
220
+ - **Simple key–value data (`storage`):** for small values that aren't state: `storage.set("lastTab", "cart")`, `storage.get("lastTab", "home")` (second argument is the default), `storage.has(key)`, `storage.remove(key)`, `storage.clear()`. Values are saved as JSON, kept separate per app, and screens update when they change. Errors show up in `storage.error`.
221
+ - **Credentials (`secure`):** Ordinary `saved state` is not encrypted; store passwords, API keys, and login tokens in `secure`:
222
+ `secure.set("token", tok)`, `secure.get("token")`, `secure.has("token")`, `secure.remove("token")`, `secure.clear()`, `secure.error`. Uses iOS Keychain on iPhone, KeyStore AES-GCM on Android, and session storage on web (use HttpOnly cookies for production web logins). Try `/lang.html?app=storage`.
148
223
 
149
224
  ### Internet data
150
225
 
226
+ **Show data from a server with `load`.** It starts loading when the app opens.
227
+ No `wait`, no `start` block:
228
+
151
229
  ```orv
152
- state users = []
230
+ state users = load("https://api.example.com/users")
153
231
 
154
- start {
155
- users = wait fetch("https://api.example.com/users")
232
+ screen Home {
233
+ Column {
234
+ if users.loading {
235
+ Text "Loading..."
236
+ }
237
+ if users.error {
238
+ Text "Could not load: {users.error}"
239
+ Button "Try again", onTap: users.reload()
240
+ }
241
+ for user in users.data {
242
+ Text user.name
243
+ }
244
+ }
156
245
  }
157
246
  ```
158
247
 
159
- `fetch` gives back the JSON directly. To send data: `fetch(url, { method: "POST", body: { name: "A" } })`.
160
- `wait` pauses until it's done: use it with `fetch` and `sleep(1000)`.
248
+ | You write | You get |
249
+ |---|---|
250
+ | `users.data` | The data (empty until it arrives, so lists and text just show nothing) |
251
+ | `users.loading` | `true` while waiting |
252
+ | `users.error` | What went wrong, or empty |
253
+ | `users.reload()` | Load again (a "Try again" or refresh button) |
161
254
 
162
- Use `wait` inside a function, `start` block, event handler block, or lambda.
163
- The compiler makes that function async automatically. A lambda containing
164
- `wait` returns a promise; using it in `map` produces a list of promises, not
165
- finished results. For sequential work, use `for` inside a function instead.
166
- Top-level initializers and screen rendering cannot use `wait` directly.
255
+ **Send data with `post`.** Give it the address and the data. That's all:
256
+
257
+ ```orv
258
+ state form = { email: "", password: "" }
259
+ state user = null
260
+
261
+ fn login() {
262
+ user = post("/api/login", form)
263
+ go(Home)
264
+ }
265
+ ```
266
+
267
+ Orvyn waits for the answer by itself, so `go(Home)` runs only after the server
268
+ has replied and `user` is set.
269
+
270
+ | Function | Use it to |
271
+ |---|---|
272
+ | `load(url)` | Show data on a screen |
273
+ | `get(url)` | Get data inside `fn` or a button |
274
+ | `post(url, data)` | Create something (log in, sign up, add an item) |
275
+ | `put(url, data)` | Replace something |
276
+ | `patch(url, data)` | Change part of something |
277
+
278
+ All of them send your data as JSON and give back the server's answer as normal
279
+ values. You can still write `wait post(...)`; it means the same thing. `fetch(url, options)`
280
+ is still there when you need full control.
281
+
282
+ Use `get`, `post`, `put`, `patch` and `sleep` inside a function, `start` block,
283
+ event handler or lambda. To show data in a screen, use `load`. The compiler
284
+ tells you if you mix these up.
285
+
286
+ **Work stops when you leave its screen.** Anything started from a screen, like
287
+ a button that sends data or a function that repeats with `sleep`, stops once the
288
+ user goes to another screen. A late answer can't change your state after the
289
+ user has moved on. `load` and `start { }` belong to the whole app and keep running.
167
290
 
168
291
  ```orv
169
292
  state status = "Ready"
@@ -171,7 +294,7 @@ state status = "Ready"
171
294
  screen Home {
172
295
  Button "Pause", onTap: {
173
296
  status = "Waiting"
174
- wait sleep(1000)
297
+ sleep(1000)
175
298
  status = "Done"
176
299
  }
177
300
  }
@@ -185,24 +308,89 @@ toggles, removal, clearing completed tasks, and navigation to an About screen.
185
308
  It works without a network request. Saved tasks belong to the current browser
186
309
  origin or installed app; they do not sync between devices.
187
310
 
311
+ ### Login and auth
312
+
313
+ ```
314
+ auth {
315
+ login: Login // where logged-out users go
316
+ home: Home // where to go after logging in
317
+ refresh: "/api/refresh" // optional: renews expired tokens
318
+ }
319
+
320
+ fn signIn() {
321
+ let res = post("/api/login", { email, password })
322
+ auth.login(res) // or auth.login(token, refreshToken, user)
323
+ }
324
+
325
+ screen Profile requires auth {
326
+ Text "Hi {auth.user.name}"
327
+ Button "Log out", onTap: auth.logout()
328
+ }
329
+ ```
330
+
331
+ Other `auth { }` settings: `api: "https://api.example.com"` (a separate API server that may receive the token), `logout: Screen`, `keepSaved: true`, `onLogout: fn`.
332
+
333
+ - `auth.isLoggedIn`, `auth.token`, `auth.user`, `auth.error`, `auth.setUser(user)`
334
+ - Tokens are kept in `secure` (Keychain / KeyStore), so users stay logged in after the app restarts.
335
+ - `get`, `post`, `load`, etc. add `Authorization: Bearer <token>` **only** for relative URLs like `/api/me`. For a separate API server add `api: "https://api.example.com"` (or a list). Other sites never get the token. Use `{ auth: false }` to skip it for one request.
336
+ - If a request gets **401**, Orvyn refreshes the token once (the `refresh` URL gets `{ refresh }` and should return `{ token }`) and retries. If refreshing fails, the user is logged out and `auth.error` explains why.
337
+ - `screen X requires auth`: logged-out users go to `loginScreen` and come back to X after `auth.login(...)`. Deep links work too.
338
+ - `auth.logout()` clears tokens, resets saved state and `storage` (set `keepSaved: true` to keep them), clears history, and shows the login screen.
339
+ - Try `/lang.html?app=auth`.
340
+
188
341
  ### Built-in functions
189
342
 
190
343
  | Function | Does |
191
344
  |---|---|
192
345
  | `print(x)` | Log to the console |
193
- | `fetch(url)` | Get data from the internet |
194
- | `go(Screen)` | Open another screen |
195
- | `sleep(ms)` | Wait (use with `wait`) |
346
+ | `load(url, options?)` | Load data with `.loading`, `.success`, `.empty`, `.error`, `.retry()`, `.cancel()` |
347
+ | `task(fn, options?)` | Run an action on demand with `.run()`, `.retry()`, `.cancel()` and the same 4 states |
348
+ | `get(url)` / `post(url, data)` | Get or send data |
349
+ | `fetch(url, options)` | Full control over a request (`timeout`, `signal`, `headers`, `method`) |
350
+ | `go(Screen)` / `back(Home?)` | Navigate between screens |
351
+ | `openUrl(url)` | Open a screen URL or external `https://`, `mailto:`, `tel:`, `whatsapp:` link |
352
+ | `scrollTo(label, offset)` | Smoothly scroll to the element with that `label:` (`"top"` for the top). `offset` keeps it clear of a sticky header on the web |
353
+ | `platform` | Current platform: `"web"`, `"ios"`, or `"android"` |
354
+ | `sleep(ms)` | Pause inside a function or handler (called `fn`s that sleep are awaited automatically) |
196
355
  | `random(1, 6)` | Random whole number |
197
356
  | `len(list)` | Number of items |
198
357
 
199
- Short functions: `todos.filter(t => t.done)`, `prices.map((p, i) => p * 2)`.
358
+ - **Loading & recovery:** `load` and `task` expose `.loading`, `.success`, `.empty`, `.error`, `.cancelled`, `.retry()` (or `.reload()`), and `.cancel()`. Pass options like `{ timeout: 5000, retries: 2 }` to handle slow or flaky servers automatically. Older responses are ignored and requests started in a screen are cancelled if you leave it.
359
+ - **Error handling (`try / catch`):** Catch async or sync failures cleanly in any function or handler:
360
+ ```orv
361
+ try {
362
+ user = post("/api/login", form)
363
+ go(Home)
364
+ } catch err {
365
+ errorMsg = err
366
+ }
367
+ ```
368
+ - **Automatic double-tap & submit protection:** While an async `Button` `onTap` or `Form` `onSubmit` is pending, extra taps/submits are ignored, the button shows a loading state, and an unhandled `Form` error displays inside the form so the user can retry.
369
+
370
+ ### Working with lists
371
+
372
+ Write your list, then a plain word. No arrow functions needed.
373
+
374
+ | Write | You get |
375
+ |---|---|
376
+ | `todos.where(done: false)` | the items that match |
377
+ | `todos.count(done: false)` | how many match (`todos.count()` for all) |
378
+ | `products.first(id: 3)` | the first match, or nothing |
379
+ | `products.search("lamp")` | items with that text anywhere, ignoring capitals |
380
+ | `products.search(query, "name")` | the same, looking in one field |
381
+ | `products.pick("name")` | one field from every item |
382
+ | `cart.total("price", "qty")` | price × qty, added up |
383
+ | `products.sortBy("price")` | lowest first; `sortBy("price", "high")` for highest first |
384
+
385
+ These give you a new list or value; your original list doesn't change. While data is still loading they act on an empty list. `where`, `count` and `first` check for equal values.
386
+
387
+ Advanced: short functions also work, like `todos.filter(t => t.done)`.
200
388
  Choose a value: `done ? "Yes" : "No"`.
201
389
 
202
390
  ## Values
203
391
 
204
- `12`, `3.5`, `"text"`, `"Hi {name}"` (interpolation), `true`, `false`, `null`,
205
- `[1, 2, 3]`, `#1e293b` (colors), `a.b`, `list[0]`, `f(x)`.
392
+ `12`, `3.5`, `"text"`, `"Hi {name}"` (interpolation — write `\{` and `\}` for literal braces), `true`, `false`, `null`,
393
+ `[1, 2, 3]`, `#1e293b` (colors), `a.b`, `list[0]`, `f(x)`, `new ClassName(...)`.
206
394
 
207
395
  Operators: `+ - * / %`, `== != < > <= >=`, `&& || !`.
208
396
 
@@ -305,11 +493,81 @@ The example validates locally; it does not send data to a server.
305
493
  | `Image` | source URL | image |
306
494
  | `Link` | text | link (`href: "..."`) |
307
495
 
308
- Style props: `bg`, `color`, `size`, `padding`, `margin`, `gap`, `radius`, `width`,
309
- `height`, `align`, `justify`, `border`, `shadow`, and the rest of Orvyn's style props.
310
- Plain words like `black` or `center` are treated as text.
496
+ ### Styling, themes & dark mode
497
+
498
+ Style props work the same way across Web, iPhone, and Android:
499
+
500
+ | Category | Props |
501
+ |---|---|
502
+ | Layout & size | `width` (`120`, `"50%"`, or `"1120px"` fixed), `height`, `minWidth`, `maxWidth`, `minHeight`, `maxHeight`, `padding`, `paddingX`, `paddingY`, `margin`, `gap`, `align`, `justify` (`start`, `center`, `end`, `between`, `around`, `evenly`), `center: true`, `wrap: true`, `scroll: true`, `grow`, `show` (`false` or `{ mobile: false, desktop: true }`) |
503
+ | Appearance | `bg`, `color`, `radius`, `border`, `shadow`, `opacity`, `animate: "ease 0.4s"`, `appear: "fade-up"` (see [Animation](#animation)) |
504
+ | Text & direction | `size`, `weight`, `font` (`sans`, `serif`, `mono`, or font name), `lineHeight`, `textAlign`, `rtl: true` |
505
+ | States | `disabled: true`, `loading: true`, `error: true` / `"message"`, `pressed: { ... }`, `focus: { ... }` |
506
+
507
+ Built-in adaptive theme tokens work out of the box and update automatically with `theme()`:
311
508
 
312
- Events: `onTap`, `onChange`, `onSubmit`, `onHover`, `onLeave`. Give a function name,
509
+ ```orv
510
+ // Semantic colors: bg, surface, card, text, muted, primary, border, danger, success, warning
511
+ // Spacing: xs (4), sm (8), md (16), lg (24), xl (32) | Sizes: caption, body, subtitle, title
512
+ Column padding: lg, gap: md {
513
+ Box bg: surface, border: "1px solid border", padding: md, radius: 12 {
514
+ Text "Hello", size: title
515
+ Button theme.dark ? "Light" : "Dark", bg: primary, padding: 10, radius: 8, onTap: theme.toggle()
516
+ }
517
+ }
518
+ ```
519
+
520
+ Use `theme.toggle()`, `theme("dark")`, `theme("light")`, `theme("system")`, or `theme({ mode: "dark", primary: "#6366f1" })`. Buttons with `bg:` automatically get readable text colour unless you set `color:`.
521
+ Plain number sizes on the web (like `maxWidth: 1120`) scale fluidly with screen width; quote a CSS unit like `maxWidth: "1120px"` for a fixed pixel size. Web-only extras (`columns`, `grid`, `position`, `cursor`, `hover`) still work in browsers and warn in `orvyn check` and iOS/Android builds. Pass `id:` or `class:` to target an element from a web script, and use `orvyn dev --native` (or `/?native=1`) to preview phone layout rules in the browser. Try `npm run dev` and open `/lang.html?app=style`.
522
+
523
+ ### Animation
524
+
525
+ These props work the same on the web, iPhone and Android:
526
+
527
+ - `animate: "ease 0.4s"` smooths every change to that element, such as `opacity`, size or `bg`. Use `ease`, `linear` or `spring`.
528
+ - `appear: "fade-up"` plays once, when the element is first seen. Presets: `fade`, `fade-up`, `fade-down`, `slide-left`, `slide-right`, `scale`. Add a time and a delay: `appear: "fade-up 0.6s 0.2s"`.
529
+ - `marquee: "left 30s"` on a `Row` slides its items in an endless loop (`left` or `right`, and the time one loop takes). Orvyn adds the second copy itself, so there is no gap. Put the row inside a box with `overflow: "hidden"`.
530
+
531
+ ```orv
532
+ state open = false
533
+
534
+ screen Home {
535
+ Heading "Hello", appear: "fade-up"
536
+ Text "Welcome back", appear: "fade-up 0.6s 0.15s"
537
+ Box bg: open ? primary : card, height: open ? 160 : 60, animate: "spring 0.4s", onTap: open = !open {
538
+ Text "Tap me"
539
+ }
540
+ Text "Thanks for reading", appear: "fade", onVisible: print("read to the end")
541
+ }
542
+ ```
543
+
544
+ `appear` waits until the element scrolls into view, on the web, iPhone and Android. `onVisible:` runs at the same moment, for your own effects. For step-by-step effects such as a typewriter, change `state` in a loop with `sleep()`. People who turn on "reduce motion" on their device see no movement.
545
+
546
+ #### Your own animations
547
+
548
+ Make a new `appear` animation with `animation`. Write how the element **starts**; Orvyn moves it from there to how it normally looks:
549
+
550
+ ```orv
551
+ animation pop { opacity: 0, y: 30, scale: 0.8 }
552
+ animation swing { rotate: -8, x: -40, opacity: 0 }
553
+
554
+ screen Home {
555
+ Heading "Hello", appear: "pop 0.6s"
556
+ Text "Welcome back", appear: "swing 0.8s 0.2s"
557
+ }
558
+ ```
559
+
560
+ | Key | What it means | Example |
561
+ |---|---|---|
562
+ | `opacity` | how see-through it starts (0 = invisible, 1 = solid) | `opacity: 0` |
563
+ | `x` | starts this many points to the right (negative = left) | `x: -40` |
564
+ | `y` | starts this many points lower (negative = higher) | `y: 30` |
565
+ | `scale` | starts this size (1 = normal, 0.5 = half) | `scale: 0.8` |
566
+ | `rotate` | starts turned this many degrees | `rotate: -8` |
567
+
568
+ Leave a key out and it doesn't change. Use it like a built-in: name, then an optional time and delay. It works on the web, iPhone and Android. To share animations between files, put them in one file and bring them in with `use pop from "./animations"`. You can't reuse a built-in name like `fade`.
569
+
570
+ Events: `onTap`, `onChange`, `onSubmit`, `onVisible`, `onHover`, `onLeave`. Give a function name,
313
571
  one statement, or a block:
314
572
 
315
573
  ```orv
@@ -324,15 +582,29 @@ Inside a view you can use `if` / `else` and `for item in list { ... }`.
324
582
 
325
583
  ```orv
326
584
  screen Home {
327
- Button "About", onTap: go(About)
585
+ Column {
586
+ Button "Open item 5", onTap: go(Detail, 5)
587
+ Button "About", onTap: go(About)
588
+ }
589
+ }
590
+
591
+ screen Detail(id) {
592
+ Column {
593
+ Button "Back", onTap: back(Home)
594
+ Text "Showing item {id}"
595
+ }
328
596
  }
329
597
 
330
598
  screen About {
331
- Button "Back", onTap: go(Home)
599
+ Button "Back", onTap: back(Home)
332
600
  }
333
601
  ```
334
602
 
335
- `App` (or the first screen in the file) opens first.
603
+ - `App`, `Home`, or the first screen opens first. Files at `src/pages/<name>/index.orv` containing a matching `screen` (for example `src/pages/blog/index.orv` with `screen Blog`) are discovered as routes automatically.
604
+ - Pass screen arguments with `go(Detail, { id: 5 })` or `go(Detail, 5)`.
605
+ - **Safe back (`back(Home)`):** `back()` steps back through history, and passing an optional fallback screen like `back(Home)` goes to `Home` instead if the user arrived from a direct link or page refresh (check `canGoBack()` only if you want custom conditional UI).
606
+ - **URLs & deep links:** On web, navigating updates the URL (e.g. `#/detail?id=5`), so browser Refresh, Back, Forward, and direct links (`/detail/5` or `#/detail?id=5`) work automatically. On phones, `back()` and Android’s Back button / iOS edge swipe step back through history, and deep links like `myapp://detail?id=5` open directly to that screen.
607
+ - **Screen state:** App-level `state` (such as a list or search filter) stays intact when navigating; `state` declared inside a screen resets when you leave it or open a different item. Try `npm run dev` and open `/lang.html?app=nav`.
336
608
 
337
609
  ## Editor colours (VS Code)
338
610
 
@@ -342,6 +614,467 @@ ln -s "$PWD/editors/vscode" ~/.vscode/extensions/orvyn-lang
342
614
 
343
615
  Then restart VS Code. `.orv` files get colours, comment toggling and bracket matching.
344
616
 
617
+ ## Environments
618
+
619
+ Keep values that differ between your computer and the released app in `orvyn.config.js`:
620
+
621
+ ```js
622
+ export default {
623
+ env: {
624
+ dev: { API_URL: "http://localhost:3000" },
625
+ staging: { API_URL: "https://staging.example.com" },
626
+ prod: { API_URL: "https://api.example.com" }
627
+ }
628
+ }
629
+ ```
630
+
631
+ Read them as `env.API_URL`. `env.name` is the chosen environment.
632
+
633
+ ```
634
+ state users = load("{env.API_URL}/users")
635
+ ```
636
+
637
+ - `orvyn dev`, `ios`, `android`, `run` and `check` use `dev`; `orvyn build` uses `prod`. Choose another with `--env staging`.
638
+ - A misspelled or missing value stops the build. `orvyn check --env prod` checks the production values.
639
+ - These values are built into the app, so anyone can read them. Never put secrets or private keys here.
640
+ - To send login tokens to a separate API server, add it to auth: `auth { login: Login, api: env.API_URL }`.
641
+
642
+ ## Search engines and AI tools (SEO, AEO, GEO)
643
+
644
+ Describe each screen at its top:
645
+
646
+ ```
647
+ screen About {
648
+ page title: "About Acme", description: "Who we are and what we sell", image: "https://example.com/team.png"
649
+
650
+ Column padding: 24 {
651
+ Heading "About Acme"
652
+ Question "Do you ship abroad?" {
653
+ Text "Yes, to 30 countries."
654
+ }
655
+ }
656
+ }
657
+ ```
658
+
659
+ `page` takes `title`, `description`, `image`, `type` (`"article"`, `"person"`, `"profile"`), `name`, `jobTitle`, `sameAs`, `author`, `date` and `noindex`. It sets the browser title, link previews, the canonical address and structured data (`WebPage`, `Article`, `Person`, or `ProfilePage`). `Question` shows a question with its answer (and accepts `size`, `weight`, `color`, and `layout: row` / `column`) and marks it up as structured data.
660
+
661
+ **Clean addresses.** A site served normally uses `/about` and `/product/5`. Apps opened from a `.html` file keep `#/about`. Old `#/` links still work. Set your host to answer unknown paths with `app.html` (the build makes it): for example `try_files $uri $uri/ /app.html;` in nginx, or `/* /app.html 200` in a Netlify `_redirects` file.
662
+
663
+ **Ready-made pages.** `orvyn build` writes HTML for every screen that needs no value and no login, plus `404.html`, `robots.txt` and, when `site` is set, `sitemap.xml`:
664
+
665
+ ```js
666
+ export default {
667
+ site: "https://example.com",
668
+ seo: { allowAI: true } // false asks AI crawlers not to read the site
669
+ }
670
+ ```
671
+
672
+ - Screens with values are made only for the values you list with `prebuild` (below).
673
+ - `load` and `get` with a full `https://` address are fetched during the build, so the data is in the page. **That data becomes public.** Nothing is ever sent (`post` doesn't run), and if a request fails the build stops. Relative addresses like `/api/items` show their loading state.
674
+ - The ready-made data is as old as your last build. The app fetches it again when it starts.
675
+ - Responsive sizes and hover styles apply once the app starts.
676
+ - A host or reverse proxy under a subfolder needs Vite's `base` set to that folder.
677
+
678
+ **Pages with values.** List them in the screen. The list can come from your server:
679
+
680
+ ```
681
+ screen Product(id) {
682
+ prebuild: get("https://api.example.com/products")
683
+
684
+ state product = load("https://api.example.com/products/{id}")
685
+ page title: "{product.data.name ?? "Product"}", description: "{product.data.about ?? ""}"
686
+
687
+ Column padding: 24 {
688
+ Heading "{product.data.name}"
689
+ }
690
+ }
691
+ ```
692
+
693
+ Your server returns a list like `[{ "id": 1, ... }, { "id": 2, ... }]`, and Orvyn takes the `id` from each item because the screen is `Product(id)`. This writes `/product/1`, `/product/2` and so on, and adds them to the sitemap. A fixed list works too: `prebuild: [1, 2, 3]`.
694
+
695
+ `orvyn check` warns about missing, long or repeated titles once your app uses `page`.
696
+
697
+ No tool can promise search rankings or mentions in AI answers. These features make your content readable; the content and links to it still matter.
698
+
699
+ ## Form inputs
700
+
701
+ ```
702
+ Input "Password", bind: password, type: password
703
+ Input "Age", bind: age, type: number
704
+ TextArea "Your message", bind: message
705
+ Checkbox "I agree", bind: agreed
706
+ Switch "Notifications", bind: notify
707
+ Select "Country", bind: country, options: ["India", "Nepal"]
708
+ ```
709
+
710
+ - `Input` types: `text`, `email`, `password` (hidden on every platform), `number`, `phone`. Each shows the matching phone keyboard.
711
+ - Inputs hold text, also with `type: number`: use `Number(age)` to calculate.
712
+ - `Checkbox` and `Switch` hold `true` or `false`. `Select` holds the chosen text, or `""` before choosing.
713
+ - In a `Form`, rules such as `required: true` work on `Input`, `TextArea` and `Select`, not on `Checkbox` or `Switch`.
714
+ - In tests, `type("Country", "India")` chooses and `tap("I agree")` ticks.
715
+
716
+ ## Dates, tabs and pop-ups
717
+
718
+ ```
719
+ DatePicker "Birthday", bind: birthday // text like "2000-01-31"
720
+ Tabs bind: tab, options: ["Home", "Profile"]
721
+ if tab == "Home" {
722
+ Text "Welcome"
723
+ }
724
+ Button "Help", onTap: help = true
725
+ Modal open: help, onClose: help = false, title: "Need help?" {
726
+ Text "Write to us"
727
+ }
728
+ ```
729
+
730
+ `Tabs` is a row of buttons where you place it, not a bar fixed to the bottom. A `Modal` has its own Close button.
731
+
732
+ ## Camera, files and location
733
+
734
+ ```
735
+ state photo = null
736
+
737
+ fn choose() {
738
+ photo = pickPhoto() // or takePhoto(), pickFile()
739
+ }
740
+
741
+ fn send() {
742
+ post("https://api.example.com/upload", photo)
743
+ }
744
+
745
+ screen Home {
746
+ Button "Choose a photo", onTap: choose()
747
+ if photo {
748
+ Image photo.dataUrl, label: "Your photo", width: 200
749
+ }
750
+ }
751
+ ```
752
+
753
+ - `pickPhoto()`, `takePhoto()` and `pickFile()` give `{ name, type, size, dataUrl }`, or `null` if cancelled. `dataUrl` holds the file as text, so `post` can upload it as JSON; your server decodes it. Keep files small (a few MB).
754
+ - `getLocation()` gives `{ latitude, longitude, accuracy }`.
755
+ - Call them from a button tap. Failures (not allowed, no camera) can be caught with `try { } catch err { }`.
756
+ - Phones need a reason in `orvyn.config.js` for `takePhoto` and `getLocation`: `native: { permissions: { camera: "...", location: "..." } }`. The build stops if it is missing.
757
+ - On phones, large chosen photos are scaled down. On Android `takePhoto` returns a small preview-sized picture.
758
+ - In tests: `mock("photo", { name: "a.jpg" })`, `mock("camera", ...)`, `mock("file", ...)`, `mock("location", { latitude: 1, longitude: 2 })`.
759
+
760
+ ## Maps
761
+
762
+ ```
763
+ Map latitude: 28.6139, longitude: 77.2090, zoom: 14, height: 240, label: "Our office"
764
+ ```
765
+
766
+ Shows a map with a pin. It shows nothing until both values are there, so `Map latitude: place.latitude, longitude: place.longitude` works with `getLocation()`. Web and Android load OpenStreetMap from the internet without a key (its servers have a usage policy, so check it before heavy use); iPhone uses Apple Maps.
767
+
768
+ ## Using libraries
769
+
770
+ Bring in functions from your own JavaScript or TypeScript files, or from an installed package:
771
+
772
+ ```
773
+ use formatPrice from "./helpers.js"
774
+ use format from "date-fns" // after: npm install date-fns
775
+
776
+ screen Home {
777
+ Text formatPrice(5)
778
+ }
779
+ ```
780
+
781
+ - Use `wait` with functions that take time: `let data = wait loadThing()`, and `new ClassName(...)` for JavaScript classes.
782
+ - On iPhone and Android only plain JavaScript works: a library that needs the browser page (`document`, `window`) or Node won't run there.
783
+ - Libraries give you functions and values, not native components or React components.
784
+ - The iPhone app's engine has no `crypto`, `fetch`, `URL` or other browser extras, so some packages (`nanoid`, for one) fail there while working on the web. `orvyn test` shows this early. Use such packages on the server instead.
785
+ - With one name, `use dayjs from "dayjs"` also works for a library that only has a default export.
786
+
787
+ ## Backend: database and login
788
+
789
+ Create `server.orv` next to your app:
790
+
791
+ ```
792
+ table notes {
793
+ text: text required
794
+ done: yesno
795
+ }
796
+
797
+ table posts public {
798
+ title: text required
799
+ }
800
+
801
+ table products public admin {
802
+ name: text required
803
+ price: number
804
+ }
805
+ ```
806
+
807
+ Run it with `orvyn serve`. Field types are `text`, `number` and `yesno`.
808
+
809
+ | Table | Who reads | Who adds and changes |
810
+ |---|---|---|
811
+ | `table notes` | each person, only their own | only the owner |
812
+ | `table posts public` | anyone | logged-in people add; only the owner changes |
813
+ | `table products public admin` | anyone | only admins |
814
+
815
+ Make an admin with `orvyn admin you@example.com` after signing up.
816
+
817
+ You get these addresses:
818
+
819
+ | Address | Does |
820
+ |---|---|
821
+ | `POST /api/signup`, `POST /api/login` | `{ email, password }` → `{ token, refresh, user }` |
822
+ | `POST /api/refresh`, `POST /api/logout`, `GET /api/me` | keep or end the session |
823
+ | `GET /api/notes`, `GET /api/notes/1` | list (newest first, 100 per `?page=`) or one; filter with `?done=true` |
824
+ | `POST /api/notes`, `PATCH /api/notes/1`, `DELETE /api/notes/1` | add, change, delete |
825
+
826
+ In your app:
827
+
828
+ ```
829
+ auth { login: Login, refresh: "{env.API_URL}/api/refresh", api: env.API_URL }
830
+
831
+ fn signIn() {
832
+ auth.login(post("{env.API_URL}/api/login", { email, password }))
833
+ }
834
+
835
+ state notes = load("{env.API_URL}/api/notes")
836
+ ```
837
+
838
+ ### Your own backend code
839
+
840
+ Write `api` blocks in `server.orv` for anything the app must not decide itself, such as prices:
841
+
842
+ ```
843
+ table products public admin {
844
+ name: text required
845
+ price: number required
846
+ }
847
+
848
+ table orders locked {
849
+ product: text
850
+ total: number
851
+ }
852
+
853
+ api post "/order" requires login {
854
+ let product = products.first(id: body.productId)
855
+ if !product {
856
+ fail "Product not found"
857
+ }
858
+ if body.qty < 1 {
859
+ fail "Choose at least one"
860
+ }
861
+ return orders.add(product: product.name, total: product.price * body.qty)
862
+ }
863
+ ```
864
+
865
+ In your app: `post("{env.API_URL}/api/order", { productId: 1, qty: 2 })`.
866
+
867
+ - `api get "/..."` or `api post "/..."`, optionally `requires login` or `requires admin`.
868
+ - Inside: `body`, `query`, `user`, your tables, `fail "message"`, `return`, `let`, `if`, `for`, `try`, list words, `now()`.
869
+ - Tables: `all()`, `where(...)`, `first(...)`, `count(...)`, `add(...)`, `update(id, { ... })`, `remove(id)`.
870
+ - Private tables show only the caller's rows. Public tables can be read fully, but only the caller's rows changed. Your code can read and change every row of an `admin` table.
871
+ - **`locked`** tables can be changed only by your `api` code, so nobody can post their own total.
872
+ - If a request fails, everything it changed is undone. Changes run one at a time.
873
+ - Other services: `get(url, headers)` and `post(url, data, headers)`, with keys from `secret("NAME")`, read from the server's environment. Never write keys in the file.
874
+ - **Always check what `body` holds.** It comes from the user.
875
+ - Server code has no arrow functions, `fn` or `while`.
876
+
877
+ **Libraries on the server.** Use your own files and npm packages:
878
+
879
+ ```
880
+ use sendEmail from "./email.js"
881
+ use nanoid from "nanoid" // after: npm install nanoid
882
+
883
+ api post "/contact" {
884
+ sendEmail("you@example.com", body.message)
885
+ return { id: nanoid() }
886
+ }
887
+ ```
888
+
889
+ - Names are found by name, or as the package's default export when you ask for one name.
890
+ - There is no `new` and no passing of functions: for a library that needs them, write a small `.js` file around it and `use` that.
891
+ - A library can read everything on your server, including the database and secrets. Add only ones you trust. Never pass `body` to a library without checking it.
892
+ - While an `api` waits for a library, other changes wait too.
893
+ - `orvyn build server` copies the files you `use` (not files they import themselves) and lists the packages for `npm install`.
894
+
895
+ ### Putting the server online
896
+
897
+ ```
898
+ orvyn build server # → dist/server/
899
+ ```
900
+
901
+ Upload that folder to any host that runs **Docker** or **Node 24**. Nothing needs installing.
902
+
903
+ | Setting | Meaning |
904
+ |---|---|
905
+ | `PORT` | Port to listen on (default 3000) |
906
+ | `ORVYN_DB` | Where the database file lives. **Put it on a disk that survives restarts** |
907
+ | `ORVYN_ORIGINS` | Your website's address, like `https://example.com` |
908
+ | `ORVYN_PROXY=1` | Set when your host puts a proxy in front (most do). Leave unset otherwise |
909
+ | `ORVYN_ADMIN` | Email to make admin, at the next start after signing up |
910
+
911
+ `GET /api/health` answers `{ "ok": true }` for your host's health check. Then set your app's address in `env.prod.API_URL`. Run only one copy of the server: SQLite is a single file.
912
+
913
+ **Before putting it online**
914
+
915
+ - It listens only on your computer. To accept outside connections use `--host 0.0.0.0`, and put it behind HTTPS: passwords must never travel over plain http.
916
+ - List the websites that may call it: `ORVYN_ORIGINS=https://example.com`.
917
+ - The data is in `orvyn.db`. Back it up and never commit it.
918
+ - Anyone can sign up. There is no email check, password reset, file storage or custom server code yet.
919
+ - The login limit is kept in memory and counts by network address; behind a proxy everyone shares one.
920
+ - It has had no independent security review.
921
+
922
+ ## Types and bigger projects
923
+
924
+ Types are optional. Add them where mistakes would hurt; anything without a type is not checked.
925
+
926
+ ```
927
+ type Product {
928
+ name: text
929
+ price: number
930
+ note: text? // may be left out
931
+ tags: list of text
932
+ }
933
+
934
+ state cart: list of Product = []
935
+
936
+ fn add(item: Product) {
937
+ cart.add(item)
938
+ }
939
+
940
+ component Card(item: Product) {
941
+ Text "{item.name}: {item.price}"
942
+ }
943
+ ```
944
+
945
+ The types are `text`, `number`, `yesno`, your own types, and `list of` any of them. `orvyn check` and the build stop on a misspelled field, a missing field or a wrong kind of value, also inside `.where(...)`, `.total("price")` and the other list words. Types add nothing to the app.
946
+
947
+ Limits: return values of your functions and server data (`load`, `post`) are not checked, and `server.orv` uses its `table` definitions, not these types.
948
+
949
+ **Folders.** Share anything with `use`, including types:
950
+
951
+ ```
952
+ src/
953
+ app.orv // screens are found from here
954
+ models/product.orv // type Product { ... }
955
+ state/cart.orv // state cart: list of Product = [], and its functions
956
+ components/card.orv
957
+ screens/checkout.orv
958
+ ```
959
+
960
+ ```
961
+ use Product from "../models/product"
962
+ use cart, add from "../state/cart"
963
+ ```
964
+
965
+ `orvyn check` checks the main file; each other file is checked when the app is built, or with `orvyn check src/state/cart.orv`.
966
+
967
+ ## Long lists
968
+
969
+ Put a loop inside `List` when there are many rows:
970
+
971
+ ```
972
+ List height: 420, rowHeight: 44 {
973
+ for item in items key item.id {
974
+ Text item.name
975
+ }
976
+ }
977
+ ```
978
+
979
+ - Every row is `rowHeight` tall (default 48) and the list is `height` tall (default 480). Content taller than a row is cut off.
980
+ - On the web only the rows in view are drawn. iPhone and Android draw rows as they scroll into sight, but the app still prepares all of them after each change.
981
+ - `key item.id` (also usable in any `for`) keeps each row's view and typed text with its item when the list changes order. Keys must be unique.
982
+
983
+ Images load lazily on the web, show a quiet placeholder and are cached on the phones.
984
+
985
+ ## Accessibility
986
+
987
+ - `label:` on an element is what screen readers say: `Button "✕", label: "Delete"`. On an `Image`, `label: ""` marks it as decoration.
988
+ - Text follows the reader's text size setting, and button animations stop when "reduce motion" is on.
989
+ - `orvyn check` warns about images and symbol-only buttons without a label, and colors written in the code that are hard to read on their background. Colors chosen while the app runs aren't checked, and it assumes the light theme.
990
+
991
+ ## Testing your app
992
+
993
+ Write tests at the bottom of your `.orv` file and run `orvyn test`:
994
+
995
+ ```
996
+ test "adds a todo" {
997
+ type("What needs doing?", "Buy milk")
998
+ tap("Add")
999
+ expect(text("Buy milk"))
1000
+ }
1001
+ ```
1002
+
1003
+ | In a test | Does |
1004
+ |---|---|
1005
+ | `tap("Add")` | Taps a button or link, by its text or `label` |
1006
+ | `type("Name", "Ana")` | Types into the input with that placeholder or `label` |
1007
+ | `expect(...)` | Fails the test when the value is false |
1008
+ | `text("1 item")` | True when that text is on screen |
1009
+ | `mock("/api/users", data, 200)` | Answers `load`, `get` and `post` to that address |
1010
+ | `settle()` | Waits for mocked data to arrive |
1011
+
1012
+ Each test starts with a fresh app and empty storage. No browser or simulator is needed. Requests without a `mock` fail, so tests never reach real servers. Tests are not included in the built app.
1013
+
1014
+ ## App settings
1015
+
1016
+ The `native` section of `orvyn.config.js` describes your phone app:
1017
+
1018
+ ```js
1019
+ export default {
1020
+ native: {
1021
+ appName: "Shop",
1022
+ appId: "com.yourcompany.shop", // your own; it can't change after publishing
1023
+ version: "1.0.0",
1024
+ build: 1, // raise it for every upload
1025
+ icon: "assets/icon.png", // 1024 x 1024 PNG, no transparency
1026
+ splash: { color: "#1d4ed8", image: "assets/logo.png" },
1027
+ permissions: { camera: "To scan product codes" },
1028
+ ios: { teamId: "ABCDE12345" },
1029
+ android: { keystore: "upload.jks", keyAlias: "upload" }
1030
+ }
1031
+ }
1032
+ ```
1033
+
1034
+ Permissions: `camera`, `microphone`, `location`, `photos`, `contacts`, `notifications`. This only declares them in the app; Orvyn has no camera or location functions yet, so declare only what you use (stores reject unused permissions).
1035
+
1036
+ ## Publishing
1037
+
1038
+ Run `orvyn doctor` at any time. It lists what is missing and how to fix it.
1039
+
1040
+ ### Website
1041
+
1042
+ ```
1043
+ orvyn build # → dist/web/, using the prod environment
1044
+ ```
1045
+
1046
+ Upload the contents of `dist/web/` to any static host.
1047
+
1048
+ ### App Store
1049
+
1050
+ You need a Mac with Xcode and a paid Apple Developer account.
1051
+
1052
+ 1. Sign in under Xcode → Settings → Accounts.
1053
+ 2. Put your Team ID (Apple Developer → Membership details) in `native.ios.teamId`.
1054
+ 3. Set `appId`, `icon` and a reason for each permission.
1055
+ 4. Create the app in App Store Connect with the same bundle id.
1056
+ 5. Build: `orvyn build ios --release` → signed `.ipa` in `dist/ios/build/ipa/`.
1057
+ 6. Upload it with Apple's **Transporter** app, then submit it in App Store Connect.
1058
+
1059
+ ### Google Play
1060
+
1061
+ You need a Google Play developer account, Java 17 or newer, the Android SDK and Gradle.
1062
+
1063
+ 1. Create your upload key once. Back it up, and never commit it to git:
1064
+ ```
1065
+ keytool -genkeypair -v -keystore upload.jks -alias upload -keyalg RSA -keysize 2048 -validity 10000
1066
+ ```
1067
+ 2. Set `appId`, `icon`, `android.keystore` and `android.keyAlias`.
1068
+ 3. Give the password in the terminal, never in a file:
1069
+ ```
1070
+ read -s ORVYN_KEYSTORE_PASSWORD && export ORVYN_KEYSTORE_PASSWORD
1071
+ ```
1072
+ Set `ORVYN_KEY_PASSWORD` too if the key has a different password.
1073
+ 4. Build: `orvyn build android --release` → `dist/android/app/build/outputs/bundle/release/app-release.aab`.
1074
+ 5. Upload the `.aab` in Play Console.
1075
+
1076
+ Raise `build` (or `version`) before every new upload.
1077
+
345
1078
  ## Errors
346
1079
 
347
1080
  The compiler stops at the first error and shows the line:
@@ -354,10 +1087,65 @@ The compiler stops at the first error and shows the line:
354
1087
  | ^
355
1088
  ```
356
1089
 
1090
+ `orvyn check` also catches common mistakes before the app runs:
1091
+
1092
+ - Typos: `"emial" is not declared. Did you mean "email"?`
1093
+ - Wrong number of values: `greet() takes 1 value, but got 0 values`
1094
+ - Bad navigation: `There is no screen called "Profle". Did you mean "Profile"?` and `Card is a component, not a screen`
1095
+
1096
+ ### When something breaks while the app runs
1097
+
1098
+ - The error says which `.orv` line was running: `[Orvyn] Tried to read "name" from something that is missing at shop.orv:42 (in Profile)`. Common JavaScript errors are turned into plain words.
1099
+ - If a screen or component crashes while drawing, it shows a **"Something went wrong"** card with a **Try again** button instead of a blank app. In development the card also shows the message and `file.orv:line`. Released apps hide those details.
1100
+ - Errors in buttons, `start { }` and `wait` are caught and reported too, so one broken button never freezes the app.
1101
+ - **While developing** (`npm run dev`, or `orvyn dev ios` live reload), errors pop up in a box in the middle of the screen, like Next.js. It shows the message, your code with the broken line marked (`> 17 |`), and a tip. With several errors it shows **Error 1 of 3** and ‹ › arrows. **Minimize** turns it into a small pill, **✕** or Escape closes it, and **Try again** redraws the screen. Save a fix and the app reloads without the box. Released apps never show it, and never include your source code.
1102
+ - Handle every error in one place by writing a function called `onError`:
1103
+
1104
+ ```
1105
+ fn onError(err) {
1106
+ // err.message, err.file, err.line, err.where ("onTap in Home"), err.kind
1107
+ log.error("Oops:", err.message)
1108
+ }
1109
+ ```
1110
+
1111
+ - Logging: `log.info(...)`, `log.warn(...)`, `log.error(...)` print with the `.orv` line. `log.sendTo("https://your-server/logs")` POSTs logs and crash reports as JSON.
1112
+ - Try `/lang.html?app=errors`.
1113
+
1114
+ ### Your own error pages
1115
+
1116
+ Declare either of these screens in your main file and Orvyn uses it. Both are optional.
1117
+
1118
+ ```
1119
+ // a screen crashed while drawing
1120
+ screen ErrorPage(message, retry) {
1121
+ Column gap: 12, padding: 24 {
1122
+ Heading "Oops!"
1123
+ if message {
1124
+ Text message, color: muted
1125
+ }
1126
+ Button "Try again", onTap: retry()
1127
+ Button "Go home", onTap: back(Home)
1128
+ }
1129
+ }
1130
+
1131
+ // an address that doesn't exist
1132
+ screen NotFound(url) {
1133
+ Column gap: 12, padding: 24 {
1134
+ Heading "404"
1135
+ Text "There is no page at {url}"
1136
+ Button "Go home", onTap: back(Home)
1137
+ }
1138
+ }
1139
+ ```
1140
+
1141
+ - `ErrorPage` replaces the **"Something went wrong"** card when a screen crashes. `retry()` draws the broken screen again. `message` has the error while developing and is empty in released apps; use `onError` to record the details.
1142
+ - A crash inside a `component` still shows the small card in its place, so one broken row doesn't take over the page. If `ErrorPage` itself crashes, the built-in card is shown.
1143
+ - Errors in buttons and `start { }` don't draw `ErrorPage`, because the screen is still there. Handle them with `try / catch` or `onError`.
1144
+ - `NotFound` is shown for unknown web addresses, phone deep links and `openUrl(...)` (which still returns `false`). The address bar keeps what was typed. Plain anchors like `#top` are ignored. Without `NotFound`, the first screen opens.
1145
+ - These two screens are never used as the first screen of your app.
1146
+ - While developing, the error box still opens on top; close it to see your `ErrorPage`.
1147
+ - Try `/lang.html?app=errorpage`.
1148
+
357
1149
  ## Not in v0.1 yet
358
1150
 
359
- - Native: `Image` sizes, `justify`, and hover events are basic on phones
360
- - Live reload is iPhone-only for now (Android: `orvyn android` rebuilds)
361
- - `state` inside components (keep state at the top of the file for now)
362
- - Browser back button with `go()`
363
1151
  - `while` loops