Debian Codegraph @

vendor/github.com/xyproto/gfx/js.go

raw
1 //go:build !tinygo && js && wasm
2
3 package gfx
4
5 import "syscall/js"
6
7 // JS gives access to js.Global and js.TypedArrayOf
8 var JS = JavaScript{
9 Global: js.Global,
10 }
11
12 // JavaScript is a type that contains fields with Global and TypedArrayOf funcs.
13 type JavaScript struct {
14 Global func() js.Value
15 }
16
17 func (j JavaScript) Document() js.Value {
18 return j.Global().Get("document")
19 }
20
21 // Body returns the js.Value for document.body
22 // The (first) optional innerHTML argument can be used to set body.innerHTML.
23 func (j JavaScript) Body(innerHTML ...string) js.Value {
24 body := j.Document().Get("body")
25
26 if len(innerHTML) > 0 {
27 body.Set("innerHTML", innerHTML[0])
28 }
29
30 return body
31 }