Skip to content

Commit eff2ee9

Browse files
committed
docs: Refactor API and introduce Dev Goodies
1 parent 56d9f0a commit eff2ee9

37 files changed

+290
-1534
lines changed

docs/articles/api/animation.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
# animation
22

3-
Helpers for driving simple animations and for leveraging the Web Animations API.
3+
Helpers for driving simple animations and leveraging the Web Animations API.
44

5-
- `Translate(sel, from, to, dur)` moves elements.
6-
- `Fade(sel, from, to, dur)` adjusts opacity.
7-
- `Scale(sel, from, to, dur)` scales elements.
8-
- `ColorCycle(sel, colors, dur)` cycles background colors.
9-
- `Keyframes(sel, frames, opts)` runs a Web Animations API sequence and
10-
returns the underlying `Animation` object.
5+
| Function | Description |
6+
| --- | --- |
7+
| `Translate(sel, from, to, dur)` | Moves elements. |
8+
| `Fade(sel, from, to, dur)` | Adjusts opacity. |
9+
| `Scale(sel, from, to, dur)` | Scales elements. |
10+
| `ColorCycle(sel, colors, dur)` | Cycles background colors. |
11+
| `Keyframes(sel, frames, opts)` | Runs a Web Animations API sequence and returns the underlying `Animation` object. |
1112

12-
## Usage
13-
14-
Call the animation helpers with a CSS selector, starting and ending values,
15-
and a duration. They can be invoked from event handlers registered in the DOM.
16-
`Keyframes` accepts arrays of frame definitions and option maps that are
17-
passed directly to the browser's `Element.animate` API.
18-
19-
> **Note**
20-
> Prefer RFW APIs like `animation`, `cinema`, and `dom` over direct browser
21-
> globals. These abstractions improve portability and testability. If an API is
22-
> missing, fall back to a `js` alias but avoid `js.Global`.
23-
24-
The following example animates elements using these helpers.
25-
26-
@include:ExampleFrame:{code:"/examples/components/animation_component.go", uri:"/examples/animations"}

docs/articles/api/assets.md

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,10 @@
22

33
Load images, JSON data, and binary models at runtime with caching and suspense-style loading.
44

5-
## Context
6-
7-
Applications often need to pull in external resources after the initial page load. The `assets` package provides non-blocking loaders so components remain responsive while files download.
8-
9-
## When to Use
10-
11-
Use these helpers whenever your component requires images, configuration JSON, or binary model data that isn't embedded in the initial bundle.
12-
13-
## How
14-
15-
1. Import the package: `import "github.com/rfwlab/rfw/v1/assets"`.
16-
2. Call a loader with the asset URL.
17-
3. Handle `http.ErrPending` while the request completes.
18-
19-
## API
20-
215
| Function | Description |
226
| --- | --- |
237
| `LoadImage(url string) (js.Value, error)` | Asynchronously fetches an image and caches it by URL. |
24-
| `LoadJSON(url string, v any) error` | Fetches JSON into `v` using [`http.FetchJSON`](http#usage). |
8+
| `LoadJSON(url string, v any) error` | Fetches JSON into `v` using `http.FetchJSON`. |
259
| `LoadModel(url string) ([]byte, error)` | Downloads binary data such as glTF models, caching results. |
2610
| `ClearCache(url string)` | Removes a cached entry for `url`. |
2711

28-
## Example
29-
30-
```go
31-
var img js.Value
32-
if v, err := assets.LoadImage("/static/logo.png"); err != nil {
33-
if errors.Is(err, http.ErrPending) {
34-
return core.Text("loading...")
35-
}
36-
return core.Text("failed")
37-
} else {
38-
img = v
39-
}
40-
return core.Img().Attr("src", img.Get("src").String())
41-
```
42-
43-
## Notes and Limitations
44-
45-
- Only available in WebAssembly builds.
46-
- `LoadModel` returns raw bytes; parsing formats like glTF is left to the caller.
47-
- Clearing the cache is manual via `assets.ClearCache`.
48-
- Remote URLs may be blocked by CORS; prefer serving images from the same origin.
49-
50-
## Related
51-
52-
- [Assets guide](../guide/assets)
53-
- [http package](http)

docs/articles/api/cinema.md

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,36 @@
22

33
An advanced animation builder for orchestrating scenes, keyframes, and media playback.
44

5-
- `NewCinemaBuilder(sel)` creates a builder rooted at a DOM element.
6-
- `AddScene(sel, opts)` sets up a new scene with keyframes and timing.
7-
- `AddKeyFrame(frame, offset)` appends a keyframe to the current scene using a `KeyFrameMap`.
8-
- `AddKeyFrameMap(frame, offset)` appends a raw map for advanced cases.
9-
- `NewKeyFrame()` creates an empty `KeyFrameMap` with chainable `Add` and `Delete` helpers.
10-
- `AddTransition(props, duration)` generates keyframes for property transitions.
11-
- `AddSequence(fn)` runs a sequence of builder operations.
12-
- `AddParallel(fn)` executes builder operations in a goroutine.
13-
- `AddPause(d)` inserts pauses between steps.
14-
- `AddLoop(count)` repeats the whole script.
15-
- `AddVideo(sel)` binds a video element for playback control.
16-
- `PlayVideo()` starts the bound video.
17-
- `PauseVideo()` pauses the video.
18-
- `StopVideo()` stops and rewinds the video.
19-
- `SeekVideo(t)` jumps to a timestamp.
20-
- `SetPlaybackRate(rate)` adjusts video speed.
21-
- `SetVolume(v)` updates volume.
22-
- `MuteVideo()` silences the audio.
23-
- `UnmuteVideo()` restores audio.
24-
- `AddSubtitle(kind, label, srcLang, src)` appends a subtitle track.
25-
- `AddAudio(src)` injects an audio element.
26-
- `PlayAudio()` starts the bound audio from the beginning.
27-
- `PauseAudio()` pauses the audio.
28-
- `StopAudio()` pauses and rewinds the audio.
29-
- `SetAudioVolume(v)` updates audio volume.
30-
- `MuteAudio()` silences the audio.
31-
- `UnmuteAudio()` restores audio.
32-
- `AddScripted(fn)` runs custom scripts.
33-
- `OnStart(fn)` and `OnEnd(fn)` register lifecycle callbacks.
34-
35-
## Usage
36-
37-
Build sequences with keyframes and media controls for rich presentations.
38-
39-
@include:ExampleFrame:{code:"/examples/components/cinema_component.go", uri:"/examples/cinema"}
40-
41-
## Audio playback
42-
43-
### Why
44-
Supplement animations with sound effects or music cues.
45-
46-
### When
47-
Use for lightweight audio playback without building a full Web Audio graph.
48-
49-
### How
50-
1. Call `AddAudio(src)` to attach an audio element.
51-
2. Trigger `PlayAudio()` when a sound should play.
52-
3. Adjust output via `SetAudioVolume`, `MuteAudio` or `UnmuteAudio`.
53-
54-
### Example: RTS unit selection
55-
56-
```go
57-
cinema := animation.NewCinemaBuilder("#root").AddAudio("/sounds/select.mp3")
58-
dom.RegisterHandlerFunc("selectUnit", func() {
59-
cinema.PlayAudio()
60-
})
61-
```
62-
63-
### Limitations
64-
- only a single audio element is tracked; call `AddAudio` with a new source for different sounds
65-
66-
### Related
67-
[animation](animation), [dom](dom)
5+
| Function | Description |
6+
| --- | --- |
7+
| `NewCinemaBuilder(sel)` | Create a builder rooted at a DOM element. |
8+
| `AddScene(sel, opts)` | Set up a new scene with keyframes and timing. |
9+
| `AddKeyFrame(frame, offset)` | Append a keyframe to the current scene using a `KeyFrameMap`. |
10+
| `AddKeyFrameMap(frame, offset)` | Append a raw map for advanced cases. |
11+
| `NewKeyFrame()` | Create an empty `KeyFrameMap` with chainable `Add` and `Delete` helpers. |
12+
| `AddTransition(props, duration)` | Generate keyframes for property transitions. |
13+
| `AddSequence(fn)` | Run a sequence of builder operations. |
14+
| `AddParallel(fn)` | Execute builder operations in a goroutine. |
15+
| `AddPause(d)` | Insert pauses between steps. |
16+
| `AddLoop(count)` | Repeat the whole script. |
17+
| `AddVideo(sel)` | Bind a video element for playback control. |
18+
| `PlayVideo()` | Start the bound video. |
19+
| `PauseVideo()` | Pause the video. |
20+
| `StopVideo()` | Stop and rewind the video. |
21+
| `SeekVideo(t)` | Jump to a timestamp. |
22+
| `SetPlaybackRate(rate)` | Adjust video speed. |
23+
| `SetVolume(v)` | Update volume. |
24+
| `MuteVideo()` | Silence the audio. |
25+
| `UnmuteVideo()` | Restore audio. |
26+
| `AddSubtitle(kind, label, srcLang, src)` | Append a subtitle track. |
27+
| `AddAudio(src)` | Inject an audio element. |
28+
| `PlayAudio()` | Start the bound audio from the beginning. |
29+
| `PauseAudio()` | Pause the audio. |
30+
| `StopAudio()` | Pause and rewind the audio. |
31+
| `SetAudioVolume(v)` | Update audio volume. |
32+
| `MuteAudio()` | Silence the audio. |
33+
| `UnmuteAudio()` | Restore audio. |
34+
| `AddScripted(fn)` | Run custom scripts. |
35+
| `OnStart(fn)` | Register a start callback. |
36+
| `OnEnd(fn)` | Register an end callback. |
6837

docs/articles/api/component.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# component
2+
3+
Types and helpers for building reactive components.
4+
5+
| Item | Description |
6+
| --- | --- |
7+
| `Component` | Interface implemented by all rfw components. |
8+
| `HTMLComponent` | Base struct for RTML-backed components. |
9+
| `ComponentRegistry` | Thread-safe registry for components loaded via `rt-is`. |
10+

docs/articles/api/components.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/articles/api/composition.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# composition
2+
3+
Utilities for composing DOM nodes and binding elements.
4+
5+
| Function | Description |
6+
| --- | --- |
7+
| `Wrap(c *core.HTMLComponent) *Component` | Wrap an `HTMLComponent` to access composition helpers. |
8+
| `FromProp[T any](c *Component, key string, def T) *state.Signal[T]` | Create a signal from a component prop. |
9+
| `Group(nodes ...Node) *Elements` | Collect multiple nodes. |
10+
| `Bind(selector string, fn func(El))` | Apply a function to elements matching a selector. |
11+
| `BindEl(el dom.Element, fn func(El))` | Apply a function to a specific element. |
12+
| `For(selector string, fn func() Node)` | Repeat node creation for matching elements. |
13+
| `Div()` | Build a `<div>` element node. |
14+
| `A()` | Build an `<a>` element node. |
15+
| `Span()` | Build a `<span>` element node. |
16+
| `Button()` | Build a `<button>` element node. |
17+
| `H(level int)` | Build a heading element. |
18+

0 commit comments

Comments
 (0)