webfluent 0.5.0-alpha

The Web-First Language — compiles to HTML, CSS, JavaScript, and PDF. 50+ built-in components, reactivity, routing, i18n, SSG, and template engine.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# WebFluent — Agent Role File

You are an expert WebFluent developer. WebFluent is a web-first programming language that compiles to HTML, CSS, JavaScript, and PDF. You write `.wf` source files and configure projects via `webfluent.app.json`.

## Project Structure

```
project/
├── webfluent.app.json        # Config: theme, build, i18n, meta
├── src/
│   ├── App.wf                # Root: navbar, router, footer
│   ├── pages/                # One .wf per page
│   ├── components/           # Reusable components
│   ├── stores/               # Shared state stores
│   └── translations/         # i18n JSON files (en.json, ar.json)
├── public/                   # Static assets → copied to build root
└── build/                    # Compiled output
```

Files in `public/` are copied to the **root** of the build output (not nested under `public/`). Example: `public/logo.png` → `build/logo.png`.

## CLI

```bash
wf init <name> -t spa|static|pdf|slides   # Create project
wf build [-d DIR]                         # Compile
wf serve [-d DIR]                         # Dev server (localhost:3000)
wf generate page|component|store <name>
```

## Core Syntax

### Pages

```wf
Page Home (path: "/", title: "Home") {
    state count = 0

    Container {
        Heading("Welcome", h1)
        Text("Count: {count}")
        Button("+1", primary) { count = count + 1 }
    }
}
```

- `path` — URL route. Supports dynamic segments: `/user/:id` (access via `params.id`)
- `title` — Browser tab title

### Components

```wf
Component UserCard (name: String, role: String, active: Bool = true) {
    Card(elevated) {
        Row(align: center, gap: md) {
            Avatar(initials: "U", primary)
            Stack {
                Text(name, bold)
                Text(role, muted)
            }
            if active {
                Badge("Active", success)
            }
        }
    }
}

// Usage
UserCard(name: "Monzer", role: "Developer")
```

- Prop types: `String`, `Number`, `Bool`, `List`, `Map`
- Optional props: `avatar?: String`
- Default values: `active: Bool = true`

### App (Router + Layout)

The Router can be placed at any nesting depth inside the App. The codegen recursively finds it.

```wf
// Simple: Router at top level
App {
    Navbar { ... }
    Router {
        Route(path: "/", page: Home)
        Route(path: "/about", page: About)
        Route(path: "*", page: NotFound)
    }
    Footer
}
```

```wf
// Sidebar layout: Router nested inside Row > Container
App {
    Row {
        style { min-height: "100vh" }

        Sidebar {
            style {
                width: "220px"
                position: "fixed"
                top: "0"
                left: "0"
                bottom: "0"
                background: "#1A1A19"
            }
            Sidebar.Header { Text("My App", bold) }
            Sidebar.Item(to: "/", icon: "home") { Text("Home") }
            Sidebar.Item(to: "/about", icon: "info") { Text("About") }
        }

        Container {
            style {
                margin-left: "220px"
                flex: "1"
            }

            Router {
                Route(path: "/", page: Home)
                Route(path: "/about", page: About)
            }
        }
    }
}
```

```wf
// Navbar + Sidebar + Router
App {
    NavBar

    Row {
        DocSidebar

        Router {
            Route(path: "/", page: Home)
            Route(path: "/docs", page: Docs)
        }
    }

    SiteFooter
}
```

The Router can be wrapped in `Row`, `Container`, `Stack`, or any layout component. Sibling elements (Sidebar, Navbar) inside the same wrapper are emitted alongside the router element.

### Stores (Shared State)

```wf
Store CartStore {
    state items = []
    state total = 0

    derived count = items.length

    action add(product: Map) {
        items = items.concat([product])
        total = total + product.price
    }

    action getHeaders() {
        h = {}
        h["Authorization"] = "Bearer " + accessToken
        return h
    }

    action clear() {
        items = []
        total = 0
    }
}

// Usage in any page/component:
Page Shop (path: "/shop") {
    use CartStore
    Text("Cart: {CartStore.count} items")
    Button("Clear") { CartStore.clear() }
}
```

### State & Reactivity

```wf
state count = 0                      // Signal — reactive variable
derived double = count * 2           // Computed — auto-updates
effect { log(count) }                // Side effect — runs on change
```

- UI elements that reference state variables auto-update when values change
- String interpolation: `"Hello, {name}!"` — reactive in UI elements

### Events

```wf
Button("Click") {
    on:click { doSomething() }
}
Input(text, bind: query) {
    on:input { search(query) }
}
Form {
    on:submit { saveData() }
}
```

Events: `on:click`, `on:input`, `on:change`, `on:submit`, `on:focus`, `on:blur`, `on:keydown`, `on:keyup`, `on:mouseenter`, `on:mouseleave`

The event object is available as `event` (e.g., `event.currentTarget`, `event.target`).

### Return Statements

Actions can return values using `return`:

```wf
Store AuthStore {
    state accessToken = ""

    action getHeaders() {
        h = {}
        h["Authorization"] = "Bearer " + accessToken
        return h
    }
}
```

### Browser Globals

Standard browser APIs are available without any prefix — they compile directly to their JavaScript equivalents:

```wf
// Storage
localStorage.setItem("token", tok)
sessionStorage.getItem("key")

// Window & Document
window.open("https://example.com")
document.title = "New Title"

// Console
console.log("debug info")

// JSON
data = JSON.parse(responseText)
text = JSON.stringify(obj)

// Timers
setTimeout(callback, 1000)

// Other globals: Math, Date, Array, Object, Promise, Error,
// parseInt, parseFloat, encodeURIComponent, atob, btoa, fetch,
// alert, confirm, prompt, RegExp, Map, Set, etc.
```

### Control Flow

```wf
// Conditional
if isLoggedIn {
    Text("Welcome!")
} else {
    Button("Log In") { navigate("/login") }
}

// Loop
for item in items {
    Card { Text(item.name) }
}

// Loop with index
for item, index in items {
    Text("{index}. {item.name}")
}

// Show/hide (keeps in DOM, toggles visibility)
show isVisible {
    Modal { Text("Content") }
}
```

### Data Fetching

```wf
fetch users from "/api/users" {
    loading { Spinner() }
    error (err) { Alert("Failed: {err.message}", danger) }
    success {
        for user in users {
            Text(user.name)
        }
    }
}
```

Options: `(method: "POST", body: { key: value }, headers: { "Authorization": token })`

Map literals support **quoted string keys** for headers and special field names:

```wf
fetch data from "/api/users" (
    method: "POST",
    headers: { "Content-Type": "application/json", "X-Api-Key": apiKey },
    body: { action: "create", token: sessionToken }
) {
    success { Text("Done") }
}
```

Reserved words (`action`, `token`, `error`, `state`, etc.) work as map keys.

### Navigation

```wf
navigate("/path")                    // Programmatic
Link(to: "/about") { Text("About") } // Declarative
```

## Built-in Components

### Layout

| Component | Usage |
|-----------|-------|
| `Container` | `Container { ... }` — centered max-width wrapper |
| `Row` | `Row(gap: md, align: center, justify: between) { ... }` — horizontal flex |
| `Column` | `Column(span: 6) { ... }` — 12-column grid child |
| `Grid` | `Grid(columns: 3, gap: md) { ... }` — CSS grid |
| `Stack` | `Stack(gap: md) { ... }` — vertical flex |
| `Spacer` | `Spacer()` or `Spacer(sm)` `Spacer(xl)` — vertical space |
| `Divider` | `Divider()` — horizontal line |

### Navigation

| Component | Usage |
|-----------|-------|
| `Navbar` | `Navbar { Navbar.Brand { ... } Navbar.Links { ... } Navbar.Actions { ... } }` |
| `Sidebar` | `Sidebar { Sidebar.Header { ... } Sidebar.Item(to: "/", icon: "home") { ... } Sidebar.Divider() }` |
| `Link` | `Link(to: "/path") { Text("Label") }` |
| `Tabs` | `Tabs { TabPage("Tab 1") { ... } TabPage("Tab 2") { ... } }` |
| `Breadcrumb` | `Breadcrumb { Breadcrumb.Item(to: "/") { Text("Home") } Breadcrumb.Item { Text("Current") } }` |
| `Menu` | `Menu(trigger: "Options") { Menu.Item { ... } }` |

### Data Display

| Component | Usage |
|-----------|-------|
| `Card` | `Card(elevated) { Card.Header { ... } Card.Body { ... } Card.Footer { ... } }` |
| `Table` | `Table { Thead { Trow { Tcell("Col") } } Tbody { Trow { Tcell("Val") } } }` |
| `List` | `List { Text("Item 1") Text("Item 2") }``List(ordered)` for numbered |
| `Badge` | `Badge("Label", primary)` — variants: primary, success, danger, warning, info |
| `Tag` | `Tag("JavaScript")` |
| `Avatar` | `Avatar(src: "/photo.jpg", alt: "User")` or `Avatar(initials: "MO", primary)` — modifiers: small, large, primary |
| `Tooltip` | `Tooltip(text: "Click to save") { Button("Save", primary) }` — wraps children, shows text on hover |

### Form & Input

| Component | Usage |
|-----------|-------|
| `Input` | `Input(text, bind: var, placeholder: "...", label: "Name")` |
| `Select` | `Select(bind: var, label: "Choose") { Option("val1", "Label 1") }` |
| `Checkbox` | `Checkbox(bind: var, label: "Agree")` |
| `Radio` | `Radio(bind: var, value: "opt1", label: "Option 1")` |
| `Switch` | `Switch(bind: var, label: "Enable")` |
| `Slider` | `Slider(bind: volume, min: 0, max: 100, step: 1, label: "Volume")` — range input with reactive value |
| `DatePicker` | `DatePicker(bind: selectedDate, label: "Start Date", min: "2026-01-01")` — date input |
| `FileUpload` | `FileUpload(accept: "image/*", label: "Upload Photo") { on:change { handleFile(event) } }` — modifiers: multiple |
| `Form` | `Form { ... on:submit { save() } }` |

Input types (first positional arg): `text`, `email`, `password`, `number`, `search`, `tel`, `url`, `date`, `time`, `color`

### Feedback

| Component | Usage |
|-----------|-------|
| `Alert` | `Alert("Message", success)` — variants: success, danger, warning, info |
| `Toast` | `Toast("Saved!", success)` — temporary notification |
| `Modal` | `Modal(visible: showModal, title: "Title") { ... Modal.Footer { ... } }` |
| `Dialog` | `Dialog(visible: show, title: "Confirm") { ... }` |
| `Spinner` | `Spinner()` or `Spinner(large, primary)` |
| `Progress` | `Progress(value: 75, max: 100)` |
| `Skeleton` | `Skeleton(height: "20px", width: "200px")` or `Skeleton(circle, size: "48px")` — modifiers: circle |

### Actions

| Component | Usage |
|-----------|-------|
| `Button` | `Button("Label", primary, large)` — click handler: `Button("Save") { doSave() }` |
| `IconButton` | `IconButton(icon: "close", label: "Close")` or `IconButton(icon: "edit", label: "Edit", primary) { editItem() }` — modifiers: small, large, primary, danger |
| `ButtonGroup` | `ButtonGroup { Button("A") Button("B") }` |
| `Dropdown` | `Dropdown(label: "Actions") { Dropdown.Item { ... } }` |

Button variants: `primary`, `secondary`, `success`, `danger`, `warning`, `info`
Button modifiers: `small`, `large`, `full`, `rounded`, `pill`, `outlined`

### Media

| Component | Usage |
|-----------|-------|
| `Image` | `Image(src: "/photo.jpg", alt: "Description")` |
| `Video` | `Video(src: "/video.mp4", controls: true)` |
| `Icon` | `Icon("home")` or `Icon("search", large, primary)` — 30 built-in SVG icons rendered inline |
| `Carousel` | `Carousel(autoplay: true, interval: 5000) { Carousel.Slide { Image(src: "...") } }` — slide track with dots and autoplay |

### Typography

| Component | Usage |
|-----------|-------|
| `Text` | `Text("Hello", bold, muted, center)` |
| `Heading` | `Heading("Title", h1)` — levels: h1, h2, h3, h4, h5, h6 |
| `Code` | `Code("const x = 1", block)``block` for multi-line |
| `Blockquote` | `Blockquote { Text("Quote text") }` |

Text modifiers: `bold`, `italic`, `underline`, `uppercase`, `lowercase`, `center`, `right`, `muted`, `small`, `large`, `primary`, `danger`, `success`, `warning`, `info`

### Component Details

#### Sidebar

Structural codegen with sub-components for app navigation:

```wf
Sidebar {
    Sidebar.Header { Text("My App", heading) }
    Sidebar.Item(to: "/", icon: "home") { Text("Home") }
    Sidebar.Item(to: "/settings", icon: "settings") { Text("Settings") }
    Sidebar.Divider()
    Sidebar.Item(to: "/logout", icon: "logout") { Text("Logout") }
}
```

Sub-components: `Sidebar.Header`, `Sidebar.Item`, `Sidebar.Divider`

#### Breadcrumb

Navigation breadcrumb with proper separator rendering:

```wf
Breadcrumb {
    Breadcrumb.Item(to: "/") { Text("Home") }
    Breadcrumb.Item(to: "/docs") { Text("Docs") }
    Breadcrumb.Item { Text("Components") }
}
```

The last item (without `to:`) renders as the current page (no link).

#### Tooltip

Wraps children, shows text on hover:

```wf
Tooltip(text: "Click to save") {
    Button("Save", primary)
}
```

#### Avatar

Displays an image or initials:

```wf
Avatar(src: "/photo.jpg", alt: "User")
Avatar(initials: "MO", primary)
Avatar(initials: "J", large)
```

Modifiers: `small`, `large`, `primary`

#### Skeleton

Loading placeholder:

```wf
Skeleton(height: "20px", width: "200px")
Skeleton(circle, size: "48px")
```

Modifiers: `circle`

#### Carousel

Slide track with dots and autoplay:

```wf
Carousel(autoplay: true, interval: 5000) {
    Carousel.Slide { Image(src: "/1.jpg", alt: "Slide 1") }
    Carousel.Slide { Image(src: "/2.jpg", alt: "Slide 2") }
}
```

#### IconButton

Icon-only button with aria-label:

```wf
IconButton(icon: "close", label: "Close")
IconButton(icon: "edit", label: "Edit", primary) { editItem() }
```

Modifiers: `small`, `large`, `primary`, `danger`

#### Slider

Range input with reactive value:

```wf
Slider(bind: volume, min: 0, max: 100, step: 1, label: "Volume")
```

#### DatePicker

Date input:

```wf
DatePicker(bind: selectedDate, label: "Start Date", min: "2026-01-01")
```

#### FileUpload

Styled file input:

```wf
FileUpload(accept: "image/*", label: "Upload Photo") {
    on:change { handleFile(event) }
}
FileUpload(accept: ".pdf,.doc", multiple, label: "Documents")
```

### Icon System

WebFluent includes 30 built-in SVG icons, rendered inline. Available icons:

`home`, `menu`, `search`, `close`, `user`, `settings`, `check`, `plus`, `minus`, `edit`, `trash`, `star`, `heart`, `mail`, `bell`, `download`, `upload`, `eye`, `link`, `calendar`, `filter`, `info`, `warning`, `arrow-left`, `arrow-right`, `chevron-down`, `chevron-right`, `chevron-left`, `logout`, `copy`

Usage:

```wf
Icon("home")
Icon("search", large, primary)
IconButton(icon: "close", label: "Close")
Sidebar.Item(to: "/", icon: "home") { Text("Home") }
```

## Modifiers Reference

Modifiers are positional keyword arguments that apply CSS classes:

**Size**: `small`, `medium`, `large`
**Color**: `primary`, `secondary`, `success`, `danger`, `warning`, `info`
**Shape**: `rounded`, `pill`, `square`
**Elevation**: `flat`, `elevated`, `outlined`
**Width**: `full`, `fit`
**Text**: `bold`, `italic`, `underline`, `uppercase`, `lowercase`, `center`, `right`, `muted`, `heading`
**Animation**: `fadeIn`, `fadeOut`, `slideUp`, `slideDown`, `slideLeft`, `slideRight`, `scaleIn`, `scaleOut`, `bounce`, `shake`, `pulse`, `spin`
**Speed**: `fast` (150ms), `slow` (500ms)

## Animation

```wf
// Mount animation (plays once on appear)
Card(elevated, fadeIn) { ... }
Heading("Title", h1, slideUp, slow)

// Conditional enter/exit
if showPanel, animate(scaleIn, fadeOut) {
    Card { Text("Animated panel") }
}

// List with stagger
for item in items, animate(slideUp, fadeOut, stagger: "50ms") {
    Text(item.name)
}

// Replay on hover (via event)
Card(outlined, fadeIn) {
    on:mouseenter { replayAnimation(event.currentTarget, "fadeIn") }
}

// Transition block (declarative, per-property)
Button("Hover") {
    transition {
        background 200ms ease
        transform 150ms spring
    }
}

// CSS transition property (in style block)
Button("Hover") {
    style {
        transition: "all 200ms ease"
    }
}
```

## Styling

### Style Blocks

```wf
Card {
    style {
        background: "#f0f0f0"
        border-radius: "1rem"
        padding: "2rem"
        box-shadow: "0 2px 8px rgba(0,0,0,0.1)"
        transition: "all 200ms ease"
    }
}
```

Style properties use CSS names (hyphenated). Values are strings or numbers. All CSS property names work, including `transition`, `animation`, `filter`, etc.

### Style support in PDF and Slides

The PDF and Slides backends honor the same set of style properties on `Slide` (slides only) and on layout containers (`Container`, `Column`, `Stack`, `Grid`, `Card`, `Section`). Anything else emits a `warning[pdf]:` or `warning[slides]: unsupported style property '<name>' on <Component>` (deduped per build).

| Property | Values | Notes |
|----------|--------|-------|
| `background` / `background-color` | `"#hex"`, `"linear-gradient(...)"` | Paint color or PDF axial-shading gradient |
| `padding`, `padding-{top,right,bottom,left}` | `Npt`, `Npx`, `N` | Insets the container's child rendering |
| `border` | `"Npt #hex"` (CSS shorthand, simplified) | Width + color |
| `border-color` | `"#hex"` | |
| `border-width` | `Npt` | |
| `border-radius` | `Npt` | Rounds the bg + border |
| `box-shadow` | `"X Y #hex"` | Offset rect; blur is ignored |
| `width`, `height` | `Npt`, `N%` | Fixed-size or percent of parent |
| `color`, `font-family`, `font-size`, `text-align` | as CSS | On `Text`/`Heading` |

Linear gradient syntax: `linear-gradient(to bottom, #color1, #color2)`, `linear-gradient(45deg, #c1, #c2)`, or named directions `to top|right|bottom|left|top-right|...`. Two color stops only.

The `Slide` element accepts `style { background }` (full-bleed page background). Setting `background` on a `Container` paints the rect under that container's measured box (or its explicit `width`/`height`).

Painting order inside a styled container: shadow → background → border → children. Children paint on top of decoration via content-stream splicing.

### Responsive Styles with @media

Style blocks support `@media` queries for responsive design:

```wf
Sidebar {
    style {
        width: "260px"
        position: "fixed"

        @media (max-width: 768px) {
            display: "none"
        }
    }
}

Heading("Title", h1) {
    style {
        font-size: "3rem"

        @media (max-width: 768px) {
            font-size: "1.5rem"
        }
    }
}
```

`@media` queries are emitted as scoped CSS `<style>` elements. Each element gets a unique class to ensure the query only applies to that element.

### Design Tokens (in webfluent.app.json)

```json
{
    "theme": {
        "name": "default",
        "tokens": {
            "color-primary": "#3B82F6",
            "color-secondary": "#8B5CF6",
            "font-family": "Inter, sans-serif",
            "radius-md": "0.5rem"
        }
    }
}
```

Built-in themes: `default`, `dark`, `minimal`, `brutalist`

## i18n (Internationalization)

### Translation files

```json
// src/translations/en.json
{ "nav.home": "Home", "greeting": "Hello, {name}!" }

// src/translations/ar.json
{ "nav.home": "الرئيسية", "greeting": "أهلاً، {name}!" }
```

### Config

```json
{
    "i18n": {
        "defaultLocale": "en",
        "locales": ["en", "ar"],
        "dir": "src/translations"
    }
}
```

### Usage

```wf
Text(t("nav.home"))                    // Translated text
Text(t("greeting", name: user.name))   // With interpolation
Button("EN") { setLocale("en") }       // Switch locale
Button("AR") { setLocale("ar") }       // Auto-RTL for Arabic
```

RTL locales (automatic `dir="rtl"`): `ar`, `he`, `fa`, `ur`

## SSG (Static Site Generation)

```json
{ "build": { "ssg": true, "base_path": "/my-site" } }
```

- Pre-renders each page to its own `index.html`
- JavaScript hydrates for interactivity
- Static content visible immediately (no blank screen)
- Dynamic content (state, if/for, fetch) handled by JS after hydration

## PDF Output

```json
{
    "build": {
        "output_type": "pdf",
        "pdf": {
            "page_size": "A4",
            "margins": { "top": 72, "bottom": 72, "left": 72, "right": 72 },
            "default_font": "Helvetica",
            "default_font_size": 12,
            "output_filename": "report.pdf"
        }
    }
}
```

### PDF-specific components

| Component | Purpose |
|-----------|---------|
| `Document(page_size: "A4")` | Root document wrapper |
| `Section` | Groups content with spacing |
| `Paragraph` | Block of text with paragraph spacing |
| `Header` | Content repeated at top of every page |
| `Footer` | Content repeated at bottom of every page |
| `PageBreak()` | Forces a new page |

Supported in PDF: `Text`, `Heading`, `Table`, `List`, `Code`, `Blockquote`, `Divider`, `Alert`, `Badge`, `Progress`, `Card`, `Image`, `Spacer`, `Container`, `Row`, `Stack`, `Grid`

**Rejected in PDF** (compile error): `Button`, `Input`, `Select`, `Checkbox`, `Switch`, `Form`, `Modal`, `Dialog`, `Toast`, `Router`, `Navbar`, `Sidebar`, `Tabs`, `Video`, `Carousel`, and all event handlers.

Page sizes: `A4`, `A3`, `A5`, `Letter`, `Legal`
Fonts: Helvetica, Helvetica-Bold, Times-Roman, Times-Bold, Courier, Courier-Bold (all Base14)

### PDF example

```wf
Page Report (path: "/", title: "Report") {
    Document(page_size: "A4") {
        Header {
            Text("Company Inc.", muted, small, right)
        }
        Footer {
            Text("Confidential", muted, small, center)
        }
        Section {
            Heading("Q1 Report", h1)
            Text("Revenue grew 15% this quarter.")

            Table {
                Thead { Trow { Tcell("Region") Tcell("Revenue") } }
                Tbody { Trow { Tcell("North America") Tcell("$2.4M") } }
            }

            PageBreak()
            Heading("Highlights", h2)
            List {
                Text("Launched 3 new products")
                Text("Expanded to 5 markets")
            }
        }
    }
}
```

## Slides Output (PDF Slide Decks)

PDF deck output where **one `Slide` = one PDF page** (no flow pagination).

```json
{
    "build": {
        "output_type": "slides",
        "slides": {
            "size": "16:9",
            "default_font": "Helvetica",
            "default_font_size": 24,
            "margin": 60,
            "show_slide_numbers": true,
            "footer_text": "My Deck",
            "background_color": "#1A1A19",
            "chrome_color": null,
            "output_filename": "deck.pdf"
        }
    }
}
```

`background_color` paints every slide full-bleed with the given color (override per-slide via `Slide { style { background } }`). `chrome_color` overrides the slide-number/footer color; if `null`, it auto-flips between dark and light grey based on the slide's background luminance.

A deck must be wrapped in a `Presentation { ... }` block inside a `Page` body. Slide elements must not appear outside `Presentation` (compile error).

### Slide kinds

| Component | Purpose |
|-----------|---------|
| `Presentation { ... }` | Deck root — children must be slide elements only |
| `Slide { ... }` | Freeform slide; top-aligned content |
| `TitleSlide("Title", "Subtitle")` | Cover slide; title 56pt bold + subtitle 28pt grey, vertical-centered |
| `SectionSlide("Label", primary)` | Full-bleed colored band, white centered label (48pt bold). Color modifiers: `primary`, `success`, `danger`, `warning`, `info` |
| `TwoColumn { Container { ... } Container { ... } }` | Two equal columns with a 24pt gutter — requires exactly 2 `Container` children |
| `ImageSlide(src: "...", caption: "...")` | Image slide with optional caption; `src` is required |

Body components inside a `Slide` (or inside `TwoColumn`'s columns): `Text`, `Heading` (auto-scaled ~2× for slides), `List`, `Container`, `Stack`, `Column`, `Grid`, `Section`, `Spacer`, `Divider`, `if`/`for` (static iteration only).

### Slide sizing (`slides.size`)

- `"16:9"` → 960×540pt (default)
- `"4:3"` → 720×540pt
- `"A4-landscape"` → 841.89×595.28pt
- `"WIDTHxHEIGHT"` (e.g. `"800x600"`) → explicit points

Or override with `slides.width` + `slides.height` (in points).

### Slide chrome (opt-in via config)

- `slides.show_slide_numbers: true``n / total` in bottom-right
- `slides.footer_text: "..."` → text in bottom-left

Both render in 11pt grey at the bottom margin.

### Overflow

Content that exceeds the bottom margin is **clipped** and a warning is printed to stderr (`warning[slides]: slide N content overflows; truncated`). The build does **not** fail on overflow.

### Rejected in slides

Same interactive components as PDF (`Button`, `Input`, `Form`, `Modal`, `Router`, `Navbar`, `Video`, etc.) plus PDF document components (`Document`, `Paragraph`, `PageBreak`, `Header`, `Footer`) — slides have their own footer chrome via config.

### Slides example

```wf
Page Deck (path: "/", title: "Q1 Review") {
    Presentation {
        TitleSlide("Q1 Review", "Company Inc. — March 2026")

        Slide {
            Heading("Highlights", h1)
            List {
                Text("Launched 3 new products")
                Text("Expanded to 5 markets")
                Text("Revenue grew 15%")
            }
        }

        TwoColumn {
            Container {
                Heading("Wins", h3)
                Text("New enterprise deals")
            }
            Container {
                Heading("Risks", h3)
                Text("Supply chain delays")
            }
        }

        ImageSlide(src: "chart.png", caption: "Q1 revenue by region")

        SectionSlide("Q2 Plan", primary)

        Slide {
            Heading("Thanks", h1)
            Text("Questions?")
        }
    }
}
```

## Escaping Braces

In strings, `{` starts interpolation. To use literal braces (e.g., in code blocks), escape with `\{` and `\}`:

```wf
Code("function() \{ return 42; \}", block)
```

## Configuration Reference (webfluent.app.json)

```json
{
    "name": "My App",
    "version": "1.0.0",
    "author": "Name",
    "theme": {
        "name": "default",
        "mode": "light",
        "tokens": {}
    },
    "build": {
        "output": "./build",
        "minify": true,
        "ssg": false,
        "base_path": "",
        "output_type": "spa",
        "pdf": {
            "page_size": "A4",
            "margins": { "top": 72, "bottom": 72, "left": 72, "right": 72 },
            "default_font": "Helvetica",
            "default_font_size": 12,
            "output_filename": null
        },
        "slides": {
            "size": "16:9",
            "width": null,
            "height": null,
            "default_font": "Helvetica",
            "default_font_size": 24,
            "margin": 60,
            "show_slide_numbers": false,
            "footer_text": null,
            "background_color": null,
            "chrome_color": null,
            "output_filename": null
        }
    },
    "dev": { "port": 3000 },
    "meta": {
        "title": "",
        "description": "",
        "favicon": "",
        "lang": "en"
    },
    "i18n": {
        "defaultLocale": "en",
        "locales": ["en"],
        "dir": "src/translations"
    }
}
```

## Template Engine (Server-Side Rendering)

WebFluent can be used as a **template engine** from Rust or Node.js to render `.wf` templates to HTML or PDF with JSON data.

### CLI

```bash
# Render to HTML
wf render template.wf --data data.json --format html -o output.html

# Render to HTML fragment (no <html> wrapper)
wf render template.wf --data data.json --format fragment

# Render to PDF
wf render template.wf --data data.json --format pdf -o report.pdf

# Pipe JSON from stdin
echo '{"name":"Monzer"}' | wf render template.wf --format html

# With theme
wf render template.wf --data data.json --format html --theme dark
```

### Rust API

```rust
use webfluent::Template;
use serde_json::json;

let tpl = Template::from_str("Container { Heading(\"Hello, {name}!\", h1) }")?;
// or: Template::from_file("templates/invoice.wf")?;

let html   = tpl.render_html(&json!({"name": "World"}))?;           // Full HTML doc
let frag   = tpl.render_html_fragment(&json!({"name": "World"}))?;  // Fragment only
let pdf    = tpl.render_pdf(&json!({"name": "World"}))?;            // Vec<u8>
let slides = tpl.render_slides(&json!({"name": "World"}))?;         // Vec<u8> (PDF deck)

// With theme
let html = tpl.with_theme("dark")
    .with_tokens(&[("color-primary", "#8B5CF6")])
    .render_html(&data)?;
```

### Node.js API

```javascript
const { Template } = require('@aspect/webfluent');

const tpl = Template.fromString('Container { Heading("Hello, {name}!", h1) }');
// or: Template.fromFile('templates/invoice.wf');

const html = tpl.renderHtml({ name: "World" });           // Full HTML string
const frag = tpl.renderHtmlFragment({ name: "World" });   // Fragment string
const pdf  = tpl.renderPdf({ name: "World" });             // Buffer

// With theme
const html = tpl.withTheme('dark')
    .withTokens({ 'color-primary': '#8B5CF6' })
    .renderHtml(data);
```

### Template Data Context

Data is a JSON object. Top-level keys become template variables:

```wf
// template.wf
Page Invoice (path: "/", title: "Invoice") {
    Container {
        Heading("Invoice #{number}", h1)
        Text("Customer: {customer.name}")

        for item in items {
            Card { Text(item.name, bold) Text("${item.price}") }
        }

        if paid { Badge("PAID", success) }
        else    { Badge("UNPAID", danger) }
    }
}
```

```json
{
    "number": "INV-001",
    "customer": { "name": "Acme Corp" },
    "items": [{ "name": "Widget", "price": 9.99 }],
    "paid": true
}
```

**Supported in templates**: all layout, typography, data display components, `for` loops, `if/else`, string interpolation, style blocks, modifiers, themes.

**Not supported**: `state`, `derived`, `effect`, events (`on:click`), navigation, stores, animations, `fetch`.

## Key Rules

1. **Every page needs a path**: `Page Name (path: "/route") { ... }`
2. **State is reactive**: any UI referencing a state variable auto-updates
3. **Modifiers are positional**: `Button("Label", primary, large)` — order doesn't matter
4. **Named args use colon**: `Input(text, bind: myVar, placeholder: "...")`
5. **Braces for children/body**: `Card { Card.Body { Text("content") } }`
6. **Sub-components use dot**: `Card.Header`, `Card.Body`, `Card.Footer`, `Navbar.Brand`, `Navbar.Links`
7. **Event handlers**: `on:click { ... }` inside a component's block
8. **String interpolation is reactive**: `Text("Count: {count}")` updates when `count` changes
9. **Imports via `use`**: `use StoreName` to access shared stores
10. **No semicolons needed**: statements are newline-separated
11. **`return` in actions**: `return expr` returns a value from store actions
11. **Style blocks support all CSS properties**: including `transition`, `animation`, `filter` — no conflicts with language keywords
12. **`@media` inside style blocks**: responsive styles are scoped to the element — `@media (max-width: 768px) { display: "none" }`
13. **Router nests anywhere**: `Router` can be inside `Row`, `Container`, `Stack`, or any layout wrapper at any depth
14. **Browser globals are not prefixed**: `localStorage`, `window`, `console`, `JSON`, `Math`, `Date`, `setTimeout`, `fetch`, `Promise`, etc. compile as-is
15. **Both `!=` and `!==`**: both inequality operators are supported (both compile to `!==` in JS)
16. **Quoted map keys**: `{ "Content-Type": "application/json" }` — use for HTTP headers and hyphenated keys
17. **Reserved words as map keys**: `{ action: "approve", token: tok }` — all keywords work as map keys
18. **`public/` copies to build root**: files in `public/` land at the root of the output directory, not nested
19. **Slides need a Presentation wrapper**: `Page X { Presentation { Slide { ... } } }` — slide elements outside `Presentation` are a compile error
20. **One Slide = one PDF page**: slides do not flow across pages; overflow is clipped with a stderr warning