Skip to content

Commit 311212c

Browse files
committed
feat(src): add MDN documentation.
1 parent 7bfd9af commit 311212c

File tree

442 files changed

+4665
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

442 files changed

+4665
-17
lines changed

src/README.mbt.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ moon add bikallem/webapi
3333
A simple counter application demonstrating DOM manipulation and event handling:
3434

3535
```moonbit
36+
///|
3637
fn main {
3738
// Create mutable counter state
3839
let mut count = 0
@@ -75,19 +76,15 @@ fn main {
7576
Demonstrates the Canvas 2D API with gradients, shapes, and text:
7677

7778
```moonbit
79+
///|
7880
fn main {
7981
// Create canvas element
8082
let canvas : @webapi.HTMLCanvasElement = @webapi.document
8183
.create_element("canvas")
8284
.into()
83-
canvas
84-
..set_width(800)
85-
..set_height(500)
86-
87-
@webapi.document
88-
.get_element_by_id("app")
89-
.unwrap()
90-
.append_child(canvas) |> ignore
85+
canvas..set_width(800)..set_height(500)
86+
@webapi.document.get_element_by_id("app").unwrap().append_child(canvas)
87+
|> ignore
9188
9289
// Get 2D rendering context
9390
let ctx : @webapi.CanvasRenderingContext2D = canvas
@@ -97,14 +94,10 @@ fn main {
9794
9895
// Create gradient
9996
let gradient = ctx.create_linear_gradient(0.0, 0.0, 0.0, 300.0)
100-
gradient
101-
..add_color_stop(0.0, "#1e3c72")
102-
..add_color_stop(1.0, "#87CEEB")
97+
gradient..add_color_stop(0.0, "#1e3c72")..add_color_stop(1.0, "#87CEEB")
10398
10499
// Draw with gradient
105-
ctx
106-
..set_fill_style(gradient)
107-
..fill_rect(0.0, 0.0, 800.0, 300.0)
100+
ctx..set_fill_style(gradient)..fill_rect(0.0, 0.0, 800.0, 300.0)
108101
109102
// Draw shapes (arc uses radians: 2π for full circle)
110103
ctx
@@ -144,11 +137,15 @@ DOM elements are returned as generic `Element` types. Use `into()` to cast to sp
144137

145138
```moonbit
146139
// Create an element and cast to specific type
140+
141+
///|
147142
let canvas : @webapi.HTMLCanvasElement = @webapi.document
148143
.create_element("canvas")
149144
.into()
150145
151146
// Cast to access type-specific methods
147+
148+
///|
152149
let ctx : @webapi.CanvasRenderingContext2D = canvas
153150
.get_context("2d")
154151
.unwrap()
@@ -227,10 +224,14 @@ interface Element : Node {
227224
**Generated MoonBit:**
228225
```moonbit
229226
// External type wrapping JavaScript object
227+
228+
///|
230229
#external
231230
pub type Element
232231
233232
// Trait defining interface methods
233+
234+
///|
234235
pub trait TElement: TNode {
235236
id(self : Self) -> String = _
236237
set_id(self : Self, id : String) -> Unit = _
@@ -239,11 +240,19 @@ pub trait TElement: TNode {
239240
}
240241
241242
// Implementation using FFI
242-
extern "js" fn element_get_attribute_ffi(obj : JsValue, name : JsValue) -> JsValue =
243-
"(obj, name) => obj.getAttribute(name)"
244243
244+
///|
245+
extern "js" fn element_get_attribute_ffi(
246+
obj : JsValue,
247+
name : JsValue,
248+
) -> JsValue = "(obj, name) => obj.getAttribute(name)"
249+
250+
///|
245251
impl TElement with get_attribute(self : Self, name : String) -> String? {
246-
let result = element_get_attribute_ffi(TJsValue::to_js(self), TJsValue::to_js(name))
252+
let result = element_get_attribute_ffi(
253+
TJsValue::to_js(self),
254+
TJsValue::to_js(name),
255+
)
247256
if JsValue::is_null(result) {
248257
None
249258
} else {
@@ -263,18 +272,21 @@ enum ShadowRootMode { "open", "closed" };
263272

264273
**Generated MoonBit:**
265274
```moonbit
275+
///|
266276
pub(all) enum ShadowRootMode {
267277
Open
268278
Closed
269279
} derive(Eq, Show)
270280
281+
///|
271282
pub impl TJsValue for ShadowRootMode with to_js(self : ShadowRootMode) -> JsValue {
272283
match self {
273284
ShadowRootMode::Open => TJsValue::to_js("open")
274285
ShadowRootMode::Closed => TJsValue::to_js("closed")
275286
}
276287
}
277288
289+
///|
278290
pub fn ShadowRootMode::from(value : String) -> ShadowRootMode? {
279291
match value {
280292
"open" => Some(ShadowRootMode::Open)
@@ -298,9 +310,11 @@ dictionary EventInit {
298310

299311
**Generated MoonBit:**
300312
```moonbit
313+
///|
301314
#external
302315
pub type EventInit
303316
317+
///|
304318
pub fn EventInit::new(bubbles? : Bool, cancelable? : Bool) -> EventInit {
305319
event_init_ffi(opt_to_js(bubbles), opt_to_js(cancelable))
306320
}

src/abort_controller_interface.mbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: dom.idl
44

55
///|
6+
/// [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
67
#external
78
pub type AbortController
89

@@ -24,6 +25,7 @@ pub fn AbortController::new() -> AbortController {
2425
}
2526

2627
///|
28+
/// [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) interface.
2729
pub trait TAbortController: TJsValue {
2830
signal(self : Self) -> AbortSignal = _
2931
abort(self : Self, reason? : JsValue) -> Unit = _
@@ -33,6 +35,7 @@ pub trait TAbortController: TJsValue {
3335
extern "js" fn abort_controller_signal_ffi(obj : JsValue) -> AbortSignal = "(obj) => obj.signal"
3436

3537
///|
38+
/// [AbortController.signal](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal)
3639
impl TAbortController with signal(self : Self) -> AbortSignal {
3740
abort_controller_signal_ffi(TJsValue::to_js(self))
3841
}
@@ -44,6 +47,7 @@ extern "js" fn abort_controller_abort_ffi(
4447
) -> Unit = "(obj, reason) => obj.abort(reason)"
4548

4649
///|
50+
/// [AbortController.abort](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
4751
impl TAbortController with abort(self : Self, reason? : JsValue) -> Unit {
4852
abort_controller_abort_ffi(TJsValue::to_js(self), opt_to_js(reason))
4953
}

src/abort_signal_interface.mbt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: dom.idl
44

55
///|
6+
/// [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
67
#external
78
pub type AbortSignal
89

@@ -19,6 +20,7 @@ pub impl TAbortSignal for AbortSignal
1920
pub impl TEventTarget for AbortSignal
2021

2122
///|
23+
/// [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) interface.
2224
pub trait TAbortSignal: TEventTarget {
2325
aborted(self : Self) -> Bool = _
2426
reason(self : Self) -> JsValue = _
@@ -31,6 +33,7 @@ pub trait TAbortSignal: TEventTarget {
3133
extern "js" fn abort_signal_abort_ffi(reason : JsValue) -> AbortSignal = "(reason) => AbortSignal.abort(reason)"
3234

3335
///|
36+
/// [AbortSignal.abort](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort)
3437
pub fn AbortSignal::abort(reason? : JsValue) -> AbortSignal {
3538
abort_signal_abort_ffi(opt_to_js(reason))
3639
}
@@ -39,6 +42,7 @@ pub fn AbortSignal::abort(reason? : JsValue) -> AbortSignal {
3942
extern "js" fn abort_signal_timeout_ffi(milliseconds : JsValue) -> AbortSignal = "(milliseconds) => AbortSignal.timeout(milliseconds)"
4043

4144
///|
45+
/// [AbortSignal.timeout](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout)
4246
pub fn AbortSignal::timeout(milliseconds : UInt64) -> AbortSignal {
4347
abort_signal_timeout_ffi(TJsValue::to_js(milliseconds))
4448
}
@@ -47,6 +51,7 @@ pub fn AbortSignal::timeout(milliseconds : UInt64) -> AbortSignal {
4751
extern "js" fn abort_signal_any_ffi(signals : JsValue) -> AbortSignal = "(signals) => AbortSignal.any(signals)"
4852

4953
///|
54+
/// [AbortSignal.any](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any)
5055
pub fn AbortSignal::any(signals : Array[AbortSignal]) -> AbortSignal {
5156
abort_signal_any_ffi(TJsValue::to_js(signals))
5257
}
@@ -55,6 +60,7 @@ pub fn AbortSignal::any(signals : Array[AbortSignal]) -> AbortSignal {
5560
extern "js" fn abort_signal_aborted_ffi(obj : JsValue) -> Bool = "(obj) => obj.aborted"
5661

5762
///|
63+
/// [AbortSignal.aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/aborted)
5864
impl TAbortSignal with aborted(self : Self) -> Bool {
5965
abort_signal_aborted_ffi(TJsValue::to_js(self))
6066
}
@@ -63,6 +69,7 @@ impl TAbortSignal with aborted(self : Self) -> Bool {
6369
extern "js" fn abort_signal_reason_ffi(obj : JsValue) -> JsValue = "(obj) => obj.reason"
6470

6571
///|
72+
/// [AbortSignal.reason](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason)
6673
impl TAbortSignal with reason(self : Self) -> JsValue {
6774
abort_signal_reason_ffi(TJsValue::to_js(self))
6875
}
@@ -71,6 +78,7 @@ impl TAbortSignal with reason(self : Self) -> JsValue {
7178
extern "js" fn abort_signal_throw_if_aborted_ffi(obj : JsValue) -> Unit = "(obj) => obj.throwIfAborted()"
7279

7380
///|
81+
/// [AbortSignal.throwIfAborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted)
7482
impl TAbortSignal with throw_if_aborted(self : Self) -> Unit {
7583
abort_signal_throw_if_aborted_ffi(TJsValue::to_js(self))
7684
}
@@ -79,6 +87,7 @@ impl TAbortSignal with throw_if_aborted(self : Self) -> Unit {
7987
extern "js" fn abort_signal_onabort_ffi(obj : JsValue) -> EventHandler = "(obj) => obj.onabort"
8088

8189
///|
90+
/// [AbortSignal.onabort](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/onabort)
8291
impl TAbortSignal with onabort(self : Self) -> EventHandler {
8392
abort_signal_onabort_ffi(TJsValue::to_js(self))
8493
}
@@ -90,6 +99,7 @@ extern "js" fn abort_signal_set_onabort_ffi(
9099
) -> Unit = "(obj, onabort) => { obj.onabort = onabort; }"
91100

92101
///|
102+
/// [AbortSignal.onabort](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/onabort)
93103
impl TAbortSignal with set_onabort(self : Self, onabort : EventHandler) -> Unit {
94104
abort_signal_set_onabort_ffi(TJsValue::to_js(self), TJsValue::to_js(onabort))
95105
}

src/abstract_range_interface.mbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: dom.idl
44

55
///|
6+
/// [AbstractRange](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange)
67
#external
78
pub type AbstractRange
89

@@ -16,6 +17,7 @@ pub fn[T : TAbstractRange] AbstractRange::into(self : AbstractRange) -> T = "%id
1617
pub impl TAbstractRange for AbstractRange
1718

1819
///|
20+
/// [AbstractRange](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange) interface.
1921
pub trait TAbstractRange: TJsValue {
2022
start_container(self : Self) -> Node = _
2123
start_offset(self : Self) -> UInt = _
@@ -28,6 +30,7 @@ pub trait TAbstractRange: TJsValue {
2830
extern "js" fn abstract_range_start_container_ffi(obj : JsValue) -> Node = "(obj) => obj.startContainer"
2931

3032
///|
33+
/// [AbstractRange.startContainer](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/startContainer)
3134
impl TAbstractRange with start_container(self : Self) -> Node {
3235
abstract_range_start_container_ffi(TJsValue::to_js(self))
3336
}
@@ -36,6 +39,7 @@ impl TAbstractRange with start_container(self : Self) -> Node {
3639
extern "js" fn abstract_range_start_offset_ffi(obj : JsValue) -> UInt = "(obj) => obj.startOffset"
3740

3841
///|
42+
/// [AbstractRange.startOffset](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/startOffset)
3943
impl TAbstractRange with start_offset(self : Self) -> UInt {
4044
abstract_range_start_offset_ffi(TJsValue::to_js(self))
4145
}
@@ -44,6 +48,7 @@ impl TAbstractRange with start_offset(self : Self) -> UInt {
4448
extern "js" fn abstract_range_end_container_ffi(obj : JsValue) -> Node = "(obj) => obj.endContainer"
4549

4650
///|
51+
/// [AbstractRange.endContainer](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/endContainer)
4752
impl TAbstractRange with end_container(self : Self) -> Node {
4853
abstract_range_end_container_ffi(TJsValue::to_js(self))
4954
}
@@ -52,6 +57,7 @@ impl TAbstractRange with end_container(self : Self) -> Node {
5257
extern "js" fn abstract_range_end_offset_ffi(obj : JsValue) -> UInt = "(obj) => obj.endOffset"
5358

5459
///|
60+
/// [AbstractRange.endOffset](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/endOffset)
5561
impl TAbstractRange with end_offset(self : Self) -> UInt {
5662
abstract_range_end_offset_ffi(TJsValue::to_js(self))
5763
}
@@ -60,6 +66,7 @@ impl TAbstractRange with end_offset(self : Self) -> UInt {
6066
extern "js" fn abstract_range_collapsed_ffi(obj : JsValue) -> Bool = "(obj) => obj.collapsed"
6167

6268
///|
69+
/// [AbstractRange.collapsed](https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange/collapsed)
6370
impl TAbstractRange with collapsed(self : Self) -> Bool {
6471
abstract_range_collapsed_ffi(TJsValue::to_js(self))
6572
}

src/add_event_listener_options_dictionary.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: dom.idl
44

55
///|
6+
/// [AddEventListenerOptions](https://developer.mozilla.org/en-US/docs/Web/API/AddEventListenerOptions)
67
#external
78
pub type AddEventListenerOptions
89

src/allow_shared_buffer_source_typedef.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: webidl.idl
44

55
///|
6+
/// [AllowSharedBufferSource](https://developer.mozilla.org/en-US/docs/Web/API/AllowSharedBufferSource)
67
#external
78
pub type AllowSharedBufferSource
89

src/array_buffer_view_typedef.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: webidl.idl
44

55
///|
6+
/// [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView)
67
#external
78
pub type ArrayBufferView
89

src/assigned_nodes_options_dictionary.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Specifications: html.idl
44

55
///|
6+
/// [AssignedNodesOptions](https://developer.mozilla.org/en-US/docs/Web/API/AssignedNodesOptions)
67
#external
78
pub type AssignedNodesOptions
89

0 commit comments

Comments
 (0)