# Reference

Every attribute, event, built-in function and keyword, written from the same list that drives
autocomplete and hover in Vi Studio (`compiler/src/vocab.ts`). Don't edit this file by hand:
change the vocabulary and run `VI_WRITE_DOCS=1 npx vitest run tests/reference.test.ts` in `compiler/`.

## Attributes

In the order **Format Document** puts them: what it is, size, look, text, layout, children, events.

### What it is

| Attribute | Value | What it does |
|---|---|---|
| `audio` | `path \| url` | A sound the container holds: `audio: @song.mp3`. Nothing shows on screen; control it with `play(box)`, `pause(box)` and `stop(box)`. |
| `button` | `string` | Makes this a button with this label: `button: "Save"`. |
| `icon` | `icon name` | Makes this an icon: `icon: heart`. Its size and colour come from `text_style`. |
| `image` | `path, fit \| fill, blurred` | A picture: `image: @cat.png`. `fit` (default) shows all of it, `fill` covers the container (edges may be cut), `blurred` blurs it. |
| `input` | `string` | Makes this a text field; the value is the hint shown while it is empty. Read what was typed as `name.text`. |
| `link` | `url` | Makes this a link that opens the page when tapped: `link: "https://…"`. Set `text` to show other words. |
| `repeat` | `item in list \| columns, rows \| count` | Make copies: `repeat: task in tasks` (one per item), `repeat: 3, 3` (a grid) or `repeat: 5`. Inside, `index` is the copy number and `x`, `y` its column and row. The copies are children of the parent: its `arrange` and `space_between` place them. Reach a copy with `name.at(1, 1)` or `name.at(4)`. |
| `search` | `string` | Makes this a search field; the value is the hint. |
| `video` | `path \| url` | A video, with no controls (build your own buttons with `play(box)`, `pause(box)`, `stop(box)`). Without a height it is 16:9. |
| `visible` | `true \| false` | Show or hide the container. Default true. |

### Size

| Attribute | Value | What it does |
|---|---|---|
| `size` | `width, height \| max \| auto` | Size out of 100 of the parent: `size: 50, 20` is half the parent's width and a fifth of its height. One number makes a square (against the parent's width). `max` fills, `auto` fits the content. |

### Look

| Attribute | Value | What it does |
|---|---|---|
| `ad` | `banner` | `ad: banner` makes this a banner ad (`config: ads:`). Test ads during development. |
| `animate` | `time` | Changes to size, place, colour, see_through, flip and tilt glide over this time: `animate: 0.3 seconds`. |
| `appear` | `fade \| slide_up \| slide_down \| slide_left \| slide_right \| grow \| none` | How it comes in and goes out when `visible` changes. |
| `bounces` | `true \| false` | Bounces off solid things instead of stopping. |
| `camera` | `back \| front \| scan` | Makes this a live camera: `camera: back`, `front`, or `scan` to read QR codes and barcodes (each code read becomes its `text` and `on_scan` runs). `take_photo(box)` takes a photo into its `image`. |
| `color` | `colour` | Background colour: a name (`red`), a shade (`blue[600]`) or `rgb(r, g, b)`. |
| `expects` | `email \| number \| phone \| password \| long_text` | The kind of text an input takes: its keyboard, hidden letters for `password`, several lines for `long_text`. |
| `flip` | `degrees` | Turn the container around its upright middle line (a card flip): `flip: 180` shows its back. |
| `frame_time` | `time` | How long each picture of `frames` shows: `frame_time: 0.1 seconds`. |
| `frames` | `paths` | An animation: pictures shown one after another, `frames: @run1.png, @run2.png`. |
| `gravity` | `light \| normal \| strong` | Makes it fall until it lands on something `solid`. `jump(box)` jumps. |
| `layer` | `top` | `layer: top` draws the container above the whole screen (popups, sheets, menus). |
| `limit` | `number` | The most letters that can be typed. |
| `loop` | `true \| false` | Start the `audio` or `video` again when it ends. Default false. |
| `map` | `place \| location` | Makes this a map centred on a place: `map: "Lagos"` or `map: location(6.6, 3.35)`. Children placed with a location are pins. `.tapped` is where the person tapped, `.center` where they dragged to. |
| `move` | `arrows \| tilt \| finger \| left \| right \| up \| down \| towards x \| away from x` | How it moves: steered by `arrows`, `tilt` or `finger`, drifting `left` / `right` / `up` / `down`, or `towards player` / `away from player`. `stop(box)` stops it. |
| `outline` | `width, colour` | A line around the edge, e.g. `outline: 2, black`. It takes no room. |
| `see_through` | `0 to 100` | How see-through the container is: 0 solid, 100 invisible. |
| `shadow` | `true \| false` | A soft drop shadow under the container. |
| `shape` | `square \| rounded \| circle` | Corner style of the container: `square` (default), `rounded` or `circle`. |
| `slider` | `low to high` | Makes this a slider: `slider: 0 to 100`. Its number is `.value`; `on_change` runs as it moves. |
| `solid` | `true \| false` | Things with `gravity` land on it and moving things stop at it. |
| `speed` | `slow \| normal \| fast \| number` | How fast `move:` moves it. |
| `spoken` | `text \| empty` | What a screen reader says for this container; `spoken: empty` hides decoration from screen readers. |
| `starts_at` | `container` | Each new copy starts where that container is: `starts_at: player`. |
| `stay_inside` | `parent \| container` | Keeps a moving container inside its parent (or another container). |
| `tilt` | `degrees` | Tip the container back around its flat middle line: `tilt: 20`. |
| `value` | `number` | The slider's number (set it to move the slider). |
| `volume` | `0 to 100` | How loud the `audio` or `video` is: 0 silent, 100 full (default). |
| `zoom` | `country \| city \| street \| building` | How close the map is. |

### Text

| Attribute | Value | What it does |
|---|---|---|
| `text` | `string` | Text to show. Use `{name}` to insert values, `{{` for a literal brace. In an `input`, the typed text. |
| `text_style` | `size, bold \| italic, colour, "font"` | Text look in any order: `text_style: 28, bold, white, "Georgia"`. A number is the size, a colour the colour, a quoted name the font. Children inherit it. |

### Layout and space

| Attribute | Value | What it does |
|---|---|---|
| `arrange` | `row \| column, spot, spread \| even, scroll` | How the children are laid out, in any order: `arrange: row, center`. Spots: top, bottom, left, right, center and pairs like `bottom right`. `spread` pushes them to the ends with equal gaps, `even` gives equal space around each, `scroll` lets them scroll. Default: column, top left. Text follows the spot too. |
| `place` | `spot \| x, y` | Pin the container in its parent, floating over the others: `place: bottom right`, or `place: 50, 10` for a point out of 100. |
| `space_around` | `number \| side number, …` | Space outside the container, like `space_inside`. |
| `space_between` | `number` | Space between the children. |
| `space_inside` | `number \| side number, …` | Space between the edge and the content: `space_inside: 16`, `space_inside: 16, top 32`, `space_inside: left right 20, top bottom 8`. |

### Children

| Attribute | Value | What it does |
|---|---|---|
| `children` | `one per line` | Containers drawn inside this one, one per line underneath: a `name:` block written right there, or the name of a container defined elsewhere. They stack top to bottom unless `arrange: row`. |

## Events

| Event | Value | Runs |
|---|---|---|
| `on_back` | `action` | Run on the Android back button or back gesture; the code decides what back does. |
| `on_change` | `action` | Run as the person types in an input. |
| `on_dark_mode` | `action` | Run when the phone switches dark mode on or off. |
| `on_hit` | `a, b: action` | Run an action the moment one container starts to overlap another (games), one pair per indented line: `ball, wall: bounce()`. |
| `on_hold` | `action` | Run on press-and-hold. |
| `on_key` | `key: action` | Keys, one per indented line: `space: jump(player)`, `p: pause()`. |
| `on_leave` | `action` | Run when a moving container leaves its parent. |
| `on_link` | `action` | Run when the app is opened from a link (`config: link:`); `opened_link()` gives it. |
| `on_open` | `action` | Run once when the container first shows (for a screen: when it opens). |
| `on_receive` | `action` | Run when the Bluetooth device `connect()` linked to this box sends something; it is in the box's `text`. |
| `on_scan` | `action` | Run when a `camera: scan` box reads a code; the code is in its `text`. |
| `on_shake` | `action` | Run when the phone is shaken. |
| `on_submit` | `action` | Run when the person presses Enter / Done in an input. |
| `on_swipe` | `left / right / up / down: action` | Swipes, one direction per indented line: `left: go_back()`. |
| `on_tap` | `action` | Run when tapped: `on_tap: count = count + 1`, or several actions on indented lines below. |
| `on_touch` | `action` | Run the moment a finger touches the container, without waiting for it to lift and without the tap highlight. Made for games (tap to jump). |
| `on_update` | `action` | On the main container: run once, the first time a new `config: version` opens. Fix saved data here: `on_update: reset(coins)`. |

## Built-in functions

| Function | What it does |
|---|---|
| `print(value, …)` | Show a line of text in the console. Several values are joined with spaces. A console program (`main run():`) shows only what it prints. |
| `visit(url)` | Open a web page in the browser. |
| `play(sound, loop?)` | Play a sound, e.g. `play(@jump.mp3)`; `play(@music.mp3, loop)` repeats it until `stop(sounds)`. Several sounds can play at once. `play(clip)` plays the `audio` or `video` that container holds. |
| `wait(time)` | Pause before the next line: `wait(3 seconds)`. |
| `random(min, max)` | A random whole number from min up to (not including) max: `random(1, 7)` is 1 to 6. |
| `pause(box)` | Pause the `audio` or `video` a container holds; `play(clip)` carries on from there. |
| `range(start, end)` | The numbers from start up to (not including) end. |
| `go_to(screen, slide \| fade \| none)` | Go to another screen (a top-level container). A screen that takes values gets them like this: `go_to(details(task))`. An optional second word picks the change: `slide` (default), `fade` or `none`. |
| `go_back()` | Go back to the previous screen. |
| `every(time, action)` | Run an action again and again (e.g. `every(0.03 seconds, step())` about 30 times a second: a game loop). The screen redraws after each run. Gives back a timer you can pass to `stop()`. |
| `stop(timer \| box \| sounds)` | Stop a timer that `every()` started, the `audio` or `video` a container holds (back to the start), or `stop(sounds)`: every sound. |
| `rgb(red, green, blue, opacity?)` | A colour from red, green and blue values (0–255). An optional fourth value from 0 (see-through) to 1 (solid) sets the opacity: `rgb(255, 255, 255, 0.5)`. |
| `take_photo(box?)` | Without a box: opens the phone's camera and gives back the photo (`avatar.image = take_photo()`), or `empty` when cancelled. With a `camera:` box: takes a photo from it, which becomes the box's `image`. |
| `choose_photo()` | Opens the photo gallery and gives back the photo picked, or `empty`. |
| `take_video(box?)` | Records a video with the phone's camera (or from a `camera:` box until `stop(box)`); it becomes the `video`. |
| `choose_video()` | Opens the gallery and gives back the video picked, or `empty`. |
| `record_sound(box?)` | Records from the microphone into a box (`record_sound(memo)`) until `stop(memo)`; the sound becomes its `audio`. Without a box it records until `stop(sounds)` and gives back the sound. |
| `choose_sound()` | Opens the phone's files and gives back the sound picked, or `empty`. |
| `my_location()` | Where the phone is: `.city`, `.street`, `.country`, `.latitude`, `.longitude`. `empty` when the person says no. |
| `battery()` | The battery: `.level` (0–100) and `.charging` (true / false). |
| `vibrate(strong \| success \| error)` | A short buzz; `vibrate(strong)`, `vibrate(success)` or `vibrate(error)` for other kinds. |
| `notify(text, time?)` | Shows a notification now, or after a time (even when the app is closed): `notify("Drink water", 10 minutes)`. |
| `cancel_notifications()` | Cancels the notifications `notify()` planned. |
| `connect(box, "device name")` | Links a nearby Bluetooth device, found by its name, to a box. What it sends becomes the box's `text` and `on_receive` runs. Needs a phone build (not Expo Go). |
| `send(url \| box, data, time?, keys?)` | Sends data to a web address (`send("https://…", { score: 10 })`; gives back the answer, or `empty`), or text to a Bluetooth box (`send(lamp, "on")`). |
| `reset(variable)` | Puts a variable's starting value back; for a `saved` or `secret` one it also deletes what is stored. |
| `load(url, time?, keys?)` | Loads data from a web address as Vi lists and objects, or `empty` when it fails or runs out of time: `load(url, 10 seconds)`. Keys go in an object: `load(url, 10 seconds, { key: "abc" })`. |
| `last_error()` | What went wrong last time something gave back `empty`: "No internet", "Timed out", "Not found (404)"… |
| `sign_in(email, password)` | Signs in to the cloud (`config: supabase:`): `true`, or `empty` (`last_error()` says why). |
| `sign_up(email, password)` | Makes a new cloud account: `true`, or `empty`. |
| `sign_out()` | Signs out of the cloud. |
| `current_user()` | The signed-in person (`.email`, `.id`), or `empty`. |
| `upload(file)` | Stores a photo, video or sound in the cloud and gives back its web address. |
| `jump(box, high?)` | Makes a box with `gravity:` jump; `jump(player, high)` jumps higher, `low` lower. |
| `after(time, action)` | Runs an action once, later: `after(2 seconds, spawn())`. Gives back a timer you can `stop()`. |
| `shake(box, time)` | Shakes a box (or `screen`) for a time. |
| `flash(box, colour)` | Flashes a box in a colour for a moment. |
| `now()` | This moment: `.date` (3 Dec 2026), `.time` (14:05), `.weekday`, `.ago`, `.day`, `.month`, `.year`, `.hour`, `.minute`. `now() + 3 days` is a date too. |
| `date(year, month, day) \| date("2026-12-25")` | A date: `date(2026, 12, 25)`, or from text an API gives: `date("2026-12-25")`. |
| `time_until(date)` | Time left until a date: `.days`, `.hours`, `.minutes`, `.seconds`, `.text` ("2 days, 3 hours"). |
| `time_since(date)` | Time gone since a date: `.days`, `.hours`, `.minutes`, `.seconds`, `.text`. |
| `choose_date()` | Opens the phone's date picker; `empty` when cancelled. |
| `choose_time()` | Opens the phone's time picker; `empty` when cancelled. |
| `number(text)` | The number in a text: `number("42")` is 42; `empty` when it is not a number. |
| `focus(box)` | Puts the cursor in an input. |
| `close_keyboard()` | Hides the keyboard. |
| `share(thing)` | Opens the phone's share sheet with text, a link, a photo, a video or a sound. |
| `copy(text)` | Copies text to the clipboard. |
| `paste()` | The text on the clipboard, or `empty`. |
| `call(number)` | Opens the phone app with the number ready to call. |
| `write_email(to, subject, text)` | Opens the email app with a message filled in; the person presses send. |
| `write_sms(number, text)` | Opens the messages app with a text filled in; the person presses send. |
| `open_map(place)` | Opens the phone's maps app at a place or location. |
| `opened_link()` | The link that opened the app, after `yourapp://` (see `config: link:` and `on_link`), or `empty`. |
| `location(latitude, longitude) \| location("place")` | A place on the map: `location(6.60, 3.35)` or `location("Lekki Phase 1")`. `a.distance_to(b)` gives `.km`, `.miles`, `.text`. |
| `buy(product)` | Opens the store's payment sheet for a product from `config: products:`: `true` when paid, `empty` when cancelled or failed. Needs a phone build. |
| `owns(product)` | True when the product was bought (or a subscription is still active). |
| `price_of(product)` | The store's price for a product, ready to show ("₦1,500"). |
| `restore_purchases()` | Brings back what the person bought before (Apple requires a button for it). |
| `show_ad()` | Shows a full-screen ad (`config: ads:`). Test ads during development. |
| `watch_ad()` | Shows a rewarded ad: `true` only if it was watched to the end. |
| `ask_ad_consent()` | Shows Google's privacy question for ads (needed in Europe), only when called. |
| `use_theme(name)` | Switches the whole app to one of the `themes:`. |
| `dark_mode()` | True when the phone is set to dark mode (`on_dark_mode` runs when it changes). |
| `announce(text)` | Says a message through the screen reader, when one is on. |
| `screen_reader()` | True when a screen reader (VoiceOver, TalkBack) is on. |
| `reduce_motion()` | True when the person asked the phone for less motion. |
| `text_scale()` | The phone's text size setting: 1 is normal, 1.5 is half as big again. |
| `use_language(name)` | Shows the app in one of `config: languages:`; texts written as `{ english: …, yoruba: … }` follow it. |
| `phone_language()` | The phone's language, as a word like `english` or `yoruba`. |

## Lists

| Write | What it does |
|---|---|
| `items.add(item)` | Add an item to the end. |
| `items.remove(item)` | Remove an item. |
| `items.index(item)` | Position of an item (0-based), or -1. |
| `items.has(item)` | True when the item is in the list. |
| `items.clear()` | Remove every item. |
| `list.join(between)` | The items as one text: `names.join(", ")`. |
| `items.count` | How many items the list has (or letters a text has). |
| `items.first` | The first item. |
| `items.last` | The last item. |
| `items[0]` | The item at a place, counting from 0. |

## Screen sizes

| Word | Means |
|---|---|
| `phone` | True on a phone-sized screen (narrower than 600). |
| `tablet` | True on a tablet-sized screen (600 to 1024 wide). |
| `desktop` | True on a wide screen (1024 and wider). |

## Keywords

| Keyword | Means |
|---|---|
| `main` | Marks the main container, where the app starts. |
| `if` | Run code only when a condition is true. |
| `else` | Otherwise. |
| `for` | `for item in array:` repeat for each item. |
| `in` | Used with `for` and `repeat`: `for task in tasks:`, `repeat: task in tasks`. |
| `while` | Repeat while a condition is true. |
| `return` | Send a value back from a function. |
| `and` | Both must be true. |
| `or` | Either can be true. |
| `not` | Flip true/false. |
| `true` | Boolean true. |
| `false` | Boolean false. |
| `empty` | No value, or nothing in it: `selected = empty`, `if tasks == empty:`. `x == empty` is true for no value, `""`, `[]` and `{}`; `0` and `false` are not empty. |
| `to` | `a to b` makes a two-item range, e.g. `0 to 600`. |
| `from` | `from "https://…/x.vi" import name`: code from the internet. Your own files need no import. |
| `import` | Bring in code from the internet: `from "https://…/x.vi" import name`. Your own files need no import. |
| `config` | App-wide settings block. |

## The config block

| Key | Value | Means |
|---|---|---|
| `name` | `string` | The app name. |
| `id` | `com.you.app` | Store id for Android and iOS builds (package / bundle id), e.g. com.yourname.shop. Made from the app name when missing. Never change it after publishing. |
| `version` | `string` | Version people see in the store, e.g. "1.2.0". Build numbers are counted up for you. |
| `icon` | `path` | Launcher icon. |
| `splash` | `block` | The screen shown while the app starts, with `color`, `logo` or `image`, `text` and `seconds` underneath. |
| `screens` | `block` | Changes where `phone`, `tablet` and `desktop` start, e.g. `tablet: 600 to 1024` (rarely needed). Each name becomes a true/false you can test. |
| `supabase` | `block` | The cloud for `cloud` variables and accounts: `url:` and `key:` (the public anon key) underneath. |
| `link` | `name` | Links like `myshop://…` open the app: `link: "myshop"`. `on_link` runs. |
| `products` | `names` | In-app products from the stores: `products: remove_ads, coins_100`. |
| `ads` | `AdMob app id` | The AdMob app id for `ad: banner`, `show_ad()` and `watch_ad()`. |
| `maps_key` | `string` | The Google Maps key a published Android app needs for `map:`. |
| `languages` | `names` | The languages texts can be written in: `languages: english, yoruba`. The first is used until `use_language()`. |
| `packages` | `npm names` | npm packages the JavaScript files in `src/` use: `packages: "react-native-confetti-cannon"`. |
| `text_size` | `follow_phone` | `text_size: follow_phone` lets text grow with the phone's larger-text setting. |

Inside `splash:`

| Key | Value | Means |
|---|---|---|
| `color` | `colour` | Background colour. |
| `logo` | `path` | Logo image. |
| `image` | `path` | Full background image. |
| `time` | `time` | How long to show the splash: `time: 2 seconds`. |
| `text` | `string` | Text to show. |

## Colours and shapes

Colour names: `red`, `pink`, `purple`, `blue`, `green`, `yellow`, `orange`, `gray`, `white`, `black`, `grey`. Shades: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900 (`blue[600]`; 500 is the plain colour).
Also `rgb(r, g, b)` with an optional opacity from 0 to 1, and hex colours in quotes (`"#FF6B6B"`).

Shapes: `square`, `circle`, `rounded`.

## Icons

`icon: name` shows the line icon; add `_filled` for the solid one (`icon: heart_filled`), for example the selected tab of a tab bar.

`plus`, `add`, `trash`, `delete`, `check_circle`, `circle_outline`, `close`, `settings`, `home`, `back`, `forward`, `arrow_back`, `arrow_forward`, `search`, `menu`, `star`, `heart`, `share`, `edit`, `camera`, `image`, `info`, `warning`, `error`, `check`, `refresh`, `send`, `lock`, `person`, `notification`, `arrow_up`, `arrow_down`, `up`, `down`, `unlock`, `people`, `chat`, `chats`, `mail`, `call`, `phone`, `bell`, `bookmark`, `flag`, `filter`, `download`, `upload`, `link`, `copy`, `eye`, `eye_off`, `log_in`, `log_out`, `calendar`, `clock`, `timer`, `alarm`, `location`, `map`, `compass`, `navigate`, `globe`, `plane`, `car`, `bus`, `train`, `bike`, `walk`, `boat`, `suitcase`, `briefcase`, `bed`, `restaurant`, `cafe`, `wallet`, `cash`, `card`, `cart`, `bag`, `gift`, `pricetag`, `receipt`, `chart`, `pie_chart`, `trending_up`, `trending_down`, `stats`, `book`, `journal`, `document`, `folder`, `list`, `grid`, `apps`, `game`, `trophy`, `medal`, `rocket`, `flame`, `flash`, `sparkles`, `diamond`, `music`, `play`, `pause`, `stop`, `skip_next`, `skip_back`, `volume`, `mute`, `mic`, `video`, `film`, `headphones`, `sun`, `moon`, `cloud`, `rain`, `snow`, `storm`, `partly_sunny`, `thermometer`, `water`, `leaf`, `flower`, `paw`, `fitness`, `barbell`, `shield`, `key`, `wifi`, `bluetooth`, `battery`, `qr_code`, `scan`, `color_palette`, `brush`, `language`, `help`, `add_circle`, `remove`, `remove_circle`, `close_circle`, `more`, `more_vertical`, `swap`, `shuffle`, `repeat`, `school`, `bulb`, `happy`, `sad`, `thumbs_up`, `thumbs_down`, `cube`, `pin`, `hourglass`, `calculator`, `construct`, `medkit`.
