@@ -33,6 +33,7 @@ moon add bikallem/webapi
3333A simple counter application demonstrating DOM manipulation and event handling:
3434
3535``` moonbit
36+ ///|
3637fn main {
3738 // Create mutable counter state
3839 let mut count = 0
@@ -75,19 +76,15 @@ fn main {
7576Demonstrates the Canvas 2D API with gradients, shapes, and text:
7677
7778``` moonbit
79+ ///|
7880fn 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+ ///|
147142let canvas : @webapi.HTMLCanvasElement = @webapi.document
148143 .create_element("canvas")
149144 .into()
150145
151146// Cast to access type-specific methods
147+
148+ ///|
152149let 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
231230pub type Element
232231
233232// Trait defining interface methods
233+
234+ ///|
234235pub 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+ ///|
245251impl 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+ ///|
266276pub(all) enum ShadowRootMode {
267277 Open
268278 Closed
269279} derive(Eq, Show)
270280
281+ ///|
271282pub 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+ ///|
278290pub 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
302315pub type EventInit
303316
317+ ///|
304318pub fn EventInit::new(bubbles? : Bool, cancelable? : Bool) -> EventInit {
305319 event_init_ffi(opt_to_js(bubbles), opt_to_js(cancelable))
306320}
0 commit comments