this repo has no description
at main 36 lines 1.2 kB view raw
1let reflect = Jv.get Jv.global "Reflect" 2let html_element = Jv.get Jv.global "HTMLElement" 3 4external jv_pure_js_expr : string -> 'a = "caml_pure_js_expr" 5 6let custom_elements = Jv.get Jv.global "customElements" 7 8type t = Jv.t 9 10let define name fn = 11 let rec test = 12 lazy 13 (Jv.callback ~arity:1 (fun () -> 14 Jv.call reflect "construct" 15 [| html_element; Jv.Jarray.create 0; Lazy.force test |])) 16 in 17 let test = Lazy.force test in 18 Jv.set test "prototype" (Jv.get html_element "prototype"); 19 Jv.set Jv.global "__xocaml_exported" (Jv.callback ~arity:1 fn); 20 Jv.set (Jv.get test "prototype") "connectedCallback" 21 (jv_pure_js_expr 22 "(function() { setTimeout(() => __xocaml_exported(this), 0) })"); 23 let _ : Jv.t = Jv.call custom_elements "define" [| Jv.of_jstr name; test |] in 24 () 25 26let text_content t = Jstr.to_string @@ Jv.to_jstr @@ Jv.get t "textContent" 27let as_target t = Brr.El.of_jv t 28 29let get_attribute t name = 30 let attr = Jv.call t "getAttribute" [| Jv.of_string name |] in 31 Jv.to_option Jv.to_string attr 32 33let attach_shadow t = 34 Brr.El.of_jv 35 @@ Jv.call t "attachShadow" 36 [| Jv.obj [| ("mode", Jv.of_jstr @@ Jstr.of_string "open") |] |]