webfluent 0.4.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
# WebFluent Animation System Specification

> Version 1.0 — Draft
> Author: Monzer Omer
> Date: 2026-03-24

---

## Overview

WebFluent provides a **declarative animation system** that lets you add motion to your applications without writing CSS keyframes or JavaScript animation code. Animations are built into the language at four levels:

1. **Animation Modifiers** — one-word mount animations on any component
2. **Transition Blocks** — declarative CSS transitions on property changes
3. **Control Flow Animations** — enter/exit animations on `if`, `for`, and `show`
4. **Imperative Animations** — trigger animations from actions and event handlers

---

## 1. Animation Modifiers

Apply a built-in animation to any component. The animation plays when the element enters the DOM (mounts).

### Syntax

```
Component(modifiers..., <animationName>)
```

### Built-in Animations

| Modifier | Effect |
|----------|--------|
| `fadeIn` | Fade from 0 to full opacity |
| `fadeOut` | Fade from full opacity to 0 |
| `slideUp` | Slide in from below |
| `slideDown` | Slide in from above |
| `slideLeft` | Slide in from the right |
| `slideRight` | Slide in from the left |
| `scaleIn` | Scale up from 0 to full size |
| `scaleOut` | Scale down from full size to 0 |
| `bounce` | Bouncy entrance |
| `shake` | Horizontal shake |
| `pulse` | Gentle scale pulse |
| `spin` | 360° rotation |

### Duration Variants

Combine with a speed modifier:

| Modifier | Duration |
|----------|----------|
| `fast` | 150ms |
| *(default)* | 300ms |
| `slow` | 500ms |

### Examples

```
// Fade in a card on mount
Card(elevated, fadeIn) {
    Text("Welcome!")
}

// Slide up with slow speed
Heading("Hello", h1, slideUp, slow)

// Bounce a button
Button("Click me", primary, bounce)

// Multiple elements with different animations
Container {
    Heading("Dashboard", h1, fadeIn)
    Row(slideUp) {
        Card(scaleIn) { Text("Users: 42") }
        Card(scaleIn) { Text("Revenue: $1.2k") }
    }
}
```

---

## 2. Transition Blocks

Declare CSS transitions on a component. These apply smooth interpolation when reactive properties change (hover states, style changes, class toggling).

### Syntax

```
Component {
    transition {
        <property> <duration> [easing]
        ...
    }
}
```

### Properties

Any CSS property name, or `all` for all properties.

### Easing Functions

| Name | Value |
|------|-------|
| `ease` | `ease` (default) |
| `linear` | `linear` |
| `easeIn` | `ease-in` |
| `easeOut` | `ease-out` |
| `easeInOut` | `ease-in-out` |
| `spring` | `cubic-bezier(0.175, 0.885, 0.32, 1.275)` |
| `bouncy` | `cubic-bezier(0.68, -0.55, 0.265, 1.55)` |
| `smooth` | `cubic-bezier(0.4, 0, 0.2, 1)` |

### Examples

```
// Smooth background and color transitions
Button("Hover me", primary) {
    transition {
        background 200ms ease
        color 200ms ease
        transform 150ms spring
    }
}

// Transition all properties
Card(elevated) {
    transition {
        all 300ms smooth
    }
    style {
        background: surface
    }
}
```

---

## 3. Control Flow Animations

Add enter/exit animations to conditional rendering, lists, and show/hide.

### Syntax

```
// On if/else
if condition, animate(<enter>, <exit>) {
    ...
}

// On for loops (with optional stagger)
for item in list, animate(<enter>, <exit>, stagger: "<delay>") {
    ...
}

// On show/hide
show condition, animate(<enter>, <exit>) {
    ...
}
```

The `animate(...)` clause is **optional** — if omitted, elements appear/disappear instantly (current behavior).

### Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| 1st positional | Animation name | Yes | Enter animation |
| 2nd positional | Animation name | No | Exit animation (reverse of enter if omitted) |
| `duration` | String | No | Override default duration (e.g., `"500ms"`) |
| `delay` | String | No | Delay before animation starts |
| `stagger` | String | No | Delay between each item (for loops only) |
| `easing` | String | No | Easing function name |

### Enter/Exit Behavior

- **`if`**: When condition becomes true, enter animation plays. When false, exit animation plays, then elements are removed.
- **`for`**: When items are added, enter animation plays on new items. When items are removed, exit animation plays, then elements are removed. Stagger delays each item.
- **`show`**: Similar to `if`, but elements stay in the DOM. Enter animation plays on show, exit animation plays on hide, then `display: none` is set.

### Auto Exit Animations

If only one animation is provided, the exit animation is the **reverse** of the enter:

| Enter | Auto Exit |
|-------|-----------|
| `fadeIn` | `fadeOut` |
| `slideUp` | `slideDown` |
| `slideDown` | `slideUp` |
| `slideLeft` | `slideRight` |
| `slideRight` | `slideLeft` |
| `scaleIn` | `scaleOut` |
| `bounce` | `fadeOut` |

### Examples

```
// Fade a message in/out based on state
if showMessage, animate(fadeIn, fadeOut) {
    Alert("Operation successful!", success)
}

// Slide cards up with stagger
for product in products, animate(slideUp, fadeOut, stagger: "50ms") {
    Card(elevated) {
        Text(product.name, heading)
        Text("${product.price}")
    }
}

// Scale a modal
show isModalOpen, animate(scaleIn, scaleOut, duration: "200ms") {
    Modal(title: "Confirm") {
        Text("Are you sure?")
        Button("Yes", primary) { confirm() }
        Button("No") { isModalOpen = false }
    }
}

// Custom duration and easing
if isExpanded, animate(slideDown, slideUp, duration: "400ms", easing: "spring") {
    Stack(gap: md) {
        Text("Expanded content line 1")
        Text("Expanded content line 2")
        Text("Expanded content line 3")
    }
}

// No exit animation — just fade in, instant removal
if hasData, animate(fadeIn) {
    Table { ... }
}
```

---

## 4. Imperative Animations

Trigger animations from actions, event handlers, and effects. Useful for feedback animations (shake on error, pulse on update).

### Syntax

```
animate(<target>, <animationName>)
animate(<target>, <animationName>, <duration>)
```

Where `<target>` is an identifier referencing a component (via `ref`).

### Component References

Use `ref` to name a component for imperative animation:

```
Button("Submit", primary, ref: submitBtn)

action onError() {
    animate(submitBtn, shake)
}
```

### Examples

```
Page Form (path: "/form") {
    state error = false

    Form {
        Input(text, bind: username, ref: usernameInput)
        Button("Submit", primary, ref: submitBtn) {
            if username == "" {
                error = true
                animate(usernameInput, shake)
            } else {
                submitForm()
            }
        }
    }
}
```

---

## 5. Animation Design Tokens

The animation system uses design tokens for consistent timing and easing across the app.

### Tokens

```
animation-duration-fast:    150ms
animation-duration-normal:  300ms
animation-duration-slow:    500ms

animation-easing-default:   cubic-bezier(0.4, 0, 0.2, 1)
animation-easing-bounce:    cubic-bezier(0.68, -0.55, 0.265, 1.55)
animation-easing-spring:    cubic-bezier(0.175, 0.885, 0.32, 1.275)
```

These can be overridden in `webfluent.app.json`:

```json
{
    "theme": {
        "tokens": {
            "animation-duration-normal": "200ms",
            "animation-easing-default": "ease-in-out"
        }
    }
}
```

---

## 6. CSS Keyframe Definitions

All built-in animations are defined as CSS keyframes:

```css
@keyframes wf-fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes wf-fadeOut   { from { opacity: 1; } to { opacity: 0; } }

@keyframes wf-slideUp   { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes wf-slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: none; } }
@keyframes wf-slideLeft { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes wf-slideRight{ from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: none; } }

@keyframes wf-scaleIn   { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes wf-scaleOut  { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(0.9); } }

@keyframes wf-bounce    { 0% { opacity: 0; transform: scale(0.3); } 50% { transform: scale(1.05); } 70% { transform: scale(0.9); } 100% { opacity: 1; transform: none; } }
@keyframes wf-shake     { 0%, 100% { transform: none; } 10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); } 20%, 40%, 60%, 80% { transform: translateX(4px); } }
@keyframes wf-pulse     { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
```

### Utility Classes

```css
.wf-animate-fadeIn    { animation: wf-fadeIn var(--animation-duration-normal) var(--animation-easing-default) both; }
.wf-animate-slideUp   { animation: wf-slideUp var(--animation-duration-normal) var(--animation-easing-default) both; }
/* ... etc for all animations */

.wf-animate--fast     { animation-duration: var(--animation-duration-fast); }
.wf-animate--slow     { animation-duration: var(--animation-duration-slow); }
```

---

## 7. Compilation Output

### Modifier animations → CSS classes

```wf
Card(elevated, fadeIn) { Text("Hello") }
```

Compiles to:

```javascript
const _e0 = WF.h("div", { className: "wf-card wf-card--elevated wf-animate-fadeIn" });
```

### Control flow animations → runtime config

```wf
if isVisible, animate(fadeIn, fadeOut) {
    Text("Hello")
}
```

Compiles to:

```javascript
WF.condRender(_root,
  () => _isVisible(),
  () => { /* then branch */ },
  null,
  { enter: "fadeIn", exit: "fadeOut" }
);
```

### Transition blocks → inline styles

```wf
Button("Click") {
    transition {
        background 200ms ease
        transform 150ms spring
    }
}
```

Compiles to:

```javascript
const _e0 = WF.h("button", {
  className: "wf-btn",
  style: { transition: "background 200ms ease, transform 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275)" }
});
```

---

## 8. Grammar Additions (EBNF)

```ebnf
// Updated control flow with optional animate clause
IfStmt     = "if" Expression ("," AnimateClause)? Block ("else" "if" Expression Block)* ("else" Block)? ;
ForStmt    = "for" IDENT ("," IDENT)? "in" Expression ("," AnimateClause)? Block ;
ShowStmt   = "show" Expression ("," AnimateClause)? Block ;

// Animate clause
AnimateClause = "animate" "(" AnimationName ("," AnimationName)? ("," AnimateOpt)* ")" ;
AnimateOpt    = IDENT ":" Expression ;
AnimationName = IDENT ;   // fadeIn, slideUp, scaleIn, bounce, shake, pulse, spin, etc.

// Transition block (inside UI elements)
TransitionBlock = "transition" "{" TransitionProp+ "}" ;
TransitionProp  = IDENT Duration IDENT? ;   // property duration [easing]

// Imperative animate statement
AnimateStmt = "animate" "(" IDENT "," AnimationName ("," Duration)? ")" ;

// Animation modifiers (added to existing modifier list)
AnimationModifier = "fadeIn" | "fadeOut" | "slideUp" | "slideDown" | "slideLeft" | "slideRight"
                  | "scaleIn" | "scaleOut" | "bounce" | "shake" | "pulse" | "spin" ;
```