dom_wasm.mx raw

   1  //:build wasm
   2  
   3  package dom
   4  
   5  import (
   6  	"git.smesh.lol/musiquay/web/common/jsbridge/callback"
   7  	"unsafe"
   8  )
   9  
  10  // --- Element creation/query ---
  11  
  12  //:wasmimport bridge dom_body
  13  func wasmBody() (n int32)
  14  
  15  //:wasmimport bridge dom_create_element
  16  func wasmCreateElement(ptr *byte, length int32, capacity int32) (n int32)
  17  
  18  //:wasmimport bridge dom_create_text_node
  19  func wasmCreateTextNode(ptr *byte, length int32, capacity int32) (n int32)
  20  
  21  //:wasmimport bridge dom_get_element_by_id
  22  func wasmGetElementById(ptr *byte, length int32, capacity int32) (n int32)
  23  
  24  //:wasmimport bridge dom_query_selector
  25  func wasmQuerySelector(ptr *byte, length int32, capacity int32) (n int32)
  26  
  27  //:wasmimport bridge dom_query_selector_from
  28  func wasmQuerySelectorFrom(root int32, ptr *byte, length int32, capacity int32) (n int32)
  29  
  30  func Body() (e Element) { return Element(wasmBody()) }
  31  func CreateElement(tag string) (e Element) { return Element(wasmCreateElement(unsafe.StringData(tag), int32(len(tag)), int32(len(tag)))) }
  32  func CreateTextNode(text string) (e Element) { return Element(wasmCreateTextNode(unsafe.StringData(text), int32(len(text)), int32(len(text)))) }
  33  func GetElementById(id string) (e Element) { return Element(wasmGetElementById(unsafe.StringData(id), int32(len(id)), int32(len(id)))) }
  34  func QuerySelector(sel string) (e Element) { return Element(wasmQuerySelector(unsafe.StringData(sel), int32(len(sel)), int32(len(sel)))) }
  35  func QuerySelectorFrom(root Element, sel string) (e Element) { return Element(wasmQuerySelectorFrom(int32(root), unsafe.StringData(sel), int32(len(sel)), int32(len(sel)))) }
  36  
  37  // --- Tree manipulation ---
  38  
  39  //:wasmimport bridge dom_append_child
  40  func wasmAppendChild(parent int32, child int32)
  41  
  42  //:wasmimport bridge dom_remove_child
  43  func wasmRemoveChild(parent int32, child int32)
  44  
  45  //:wasmimport bridge dom_remove
  46  func wasmRemove(el int32)
  47  
  48  //:wasmimport bridge dom_insert_before
  49  func wasmInsertBefore(parent int32, newChild int32, refChild int32)
  50  
  51  //:wasmimport bridge dom_first_child
  52  func wasmFirstChild(el int32) (n int32)
  53  
  54  //:wasmimport bridge dom_first_element_child
  55  func wasmFirstElementChild(el int32) (n int32)
  56  
  57  //:wasmimport bridge dom_next_sibling
  58  func wasmNextSibling(el int32) (n int32)
  59  
  60  //:wasmimport bridge dom_release_element
  61  func wasmReleaseElement(el int32)
  62  
  63  //:wasmimport bridge dom_release_all
  64  func wasmReleaseAll(ptr *int32, length int32)
  65  
  66  func AppendChild(parent, child Element)                   { wasmAppendChild(int32(parent), int32(child)) }
  67  func RemoveChild(parent, child Element)                   { wasmRemoveChild(int32(parent), int32(child)) }
  68  func Remove(el Element)                                   { wasmRemove(int32(el)) }
  69  func InsertBefore(parent, newChild, refChild Element)     { wasmInsertBefore(int32(parent), int32(newChild), int32(refChild)) }
  70  func FirstChild(el Element) (e Element) { return Element(wasmFirstChild(int32(el))) }
  71  func FirstElementChild(el Element) (e Element) { return Element(wasmFirstElementChild(int32(el))) }
  72  func NextSibling(el Element) (e Element) { return Element(wasmNextSibling(int32(el))) }
  73  func ReleaseElement(el Element)                           { wasmReleaseElement(int32(el)) }
  74  func ReleaseAll(ids []int32)                              { if len(ids) > 0 { wasmReleaseAll(&ids[0], int32(len(ids))) } }
  75  
  76  //:wasmimport bridge dom_release_children
  77  func wasmReleaseChildren(el int32)
  78  
  79  func ReleaseChildren(el Element)                          { wasmReleaseChildren(int32(el)) }
  80  
  81  // --- Attributes and content ---
  82  
  83  //:wasmimport bridge dom_set_attribute
  84  func wasmSetAttribute(el int32, nPtr *byte, nLen int32, nCap int32, vPtr *byte, vLen int32, vCap int32)
  85  
  86  //:wasmimport bridge dom_remove_attribute
  87  func wasmRemoveAttribute(el int32, nPtr *byte, nLen int32, nCap int32)
  88  
  89  //:wasmimport bridge dom_get_attribute
  90  func wasmGetAttribute(el int32, nPtr *byte, nLen int32, nCap int32, outPtr *int32, outLen *int32)
  91  
  92  //:wasmimport bridge dom_set_text_content
  93  func wasmSetTextContent(el int32, ptr *byte, length int32, capacity int32)
  94  
  95  //:wasmimport bridge dom_set_inner_html
  96  func wasmSetInnerHTML(el int32, ptr *byte, length int32, capacity int32)
  97  
  98  //:wasmimport bridge dom_set_style
  99  func wasmSetStyle(el int32, pPtr *byte, pLen int32, pCap int32, vPtr *byte, vLen int32, vCap int32)
 100  
 101  //:wasmimport bridge dom_add_class
 102  func wasmAddClass(el int32, ptr *byte, length int32, capacity int32)
 103  
 104  //:wasmimport bridge dom_remove_class
 105  func wasmRemoveClass(el int32, ptr *byte, length int32, capacity int32)
 106  
 107  //:wasmimport bridge dom_focus
 108  func wasmFocus(el int32)
 109  
 110  //:wasmimport bridge dom_set_property
 111  func wasmSetProperty(el int32, pPtr *byte, pLen int32, pCap int32, vPtr *byte, vLen int32, vCap int32)
 112  
 113  //:wasmimport bridge dom_get_property
 114  func wasmGetProperty(el int32, pPtr *byte, pLen int32, pCap int32, outPtr *int32, outLen *int32)
 115  
 116  func SetAttribute(el Element, name, value string) {
 117  	wasmSetAttribute(int32(el),
 118  		unsafe.StringData(name), int32(len(name)), int32(len(name)),
 119  		unsafe.StringData(value), int32(len(value)), int32(len(value)))
 120  }
 121  
 122  func RemoveAttribute(el Element, name string) {
 123  	wasmRemoveAttribute(int32(el), unsafe.StringData(name), int32(len(name)), int32(len(name)))
 124  }
 125  
 126  func GetAttribute(el Element, name string) (s string) {
 127  	var rPtr, rLen int32
 128  	wasmGetAttribute(int32(el), unsafe.StringData(name), int32(len(name)), int32(len(name)), &rPtr, &rLen)
 129  	return ptrToString(rPtr, rLen)
 130  }
 131  
 132  func SetTextContent(el Element, text string) {
 133  	wasmSetTextContent(int32(el), unsafe.StringData(text), int32(len(text)), int32(len(text)))
 134  }
 135  
 136  func SetInnerHTML(el Element, html string) {
 137  	wasmSetInnerHTML(int32(el), unsafe.StringData(html), int32(len(html)), int32(len(html)))
 138  }
 139  
 140  func SetStyle(el Element, prop, value string) {
 141  	wasmSetStyle(int32(el),
 142  		unsafe.StringData(prop), int32(len(prop)), int32(len(prop)),
 143  		unsafe.StringData(value), int32(len(value)), int32(len(value)))
 144  }
 145  
 146  func AddClass(el Element, cls string) {
 147  	wasmAddClass(int32(el), unsafe.StringData(cls), int32(len(cls)), int32(len(cls)))
 148  }
 149  
 150  func RemoveClass(el Element, cls string) {
 151  	wasmRemoveClass(int32(el), unsafe.StringData(cls), int32(len(cls)), int32(len(cls)))
 152  }
 153  
 154  func Focus(el Element) { wasmFocus(int32(el)) }
 155  
 156  func SetProperty(el Element, prop, value string) {
 157  	wasmSetProperty(int32(el),
 158  		unsafe.StringData(prop), int32(len(prop)), int32(len(prop)),
 159  		unsafe.StringData(value), int32(len(value)), int32(len(value)))
 160  }
 161  
 162  func GetProperty(el Element, prop string) (s string) {
 163  	var rPtr, rLen int32
 164  	wasmGetProperty(int32(el), unsafe.StringData(prop), int32(len(prop)), int32(len(prop)), &rPtr, &rLen)
 165  	return ptrToString(rPtr, rLen)
 166  }
 167  
 168  // --- Geometry ---
 169  
 170  //:wasmimport bridge dom_bounding_client_left
 171  func wasmBoundingClientLeft(el int32) (n int32)
 172  
 173  //:wasmimport bridge dom_get_bounding_rect
 174  func wasmGetBoundingRect(el int32, cbID int32)
 175  
 176  //:wasmimport bridge dom_get_viewport_height
 177  func wasmGetViewportHeight() (n int32)
 178  
 179  //:wasmimport bridge dom_get_viewport_width
 180  func wasmGetViewportWidth() (n int32)
 181  
 182  func BoundingClientLeft(el Element) (n int32) { return wasmBoundingClientLeft(int32(el)) }
 183  
 184  func GetBoundingRect(el Element, fn func(int32, int32, int32, int32, int32, int32)) {
 185  	wasmGetBoundingRect(int32(el), callback.Register6IOnce(fn))
 186  }
 187  
 188  func GetViewportHeight() (n int32) { return wasmGetViewportHeight() }
 189  func GetViewportWidth() (n int32) { return wasmGetViewportWidth() }
 190  
 191  // --- Callbacks and events ---
 192  
 193  //:wasmimport bridge dom_add_event_listener
 194  func wasmAddEventListener(el int32, evPtr *byte, evLen int32, evCap int32, cbID int32)
 195  
 196  //:wasmimport bridge dom_add_self_event_listener
 197  func wasmAddSelfEventListener(el int32, evPtr *byte, evLen int32, evCap int32, cbID int32)
 198  
 199  //:wasmimport bridge dom_add_enter_key_listener
 200  func wasmAddEnterKeyListener(el int32, cbID int32)
 201  
 202  //:wasmimport bridge dom_remove_event_listener
 203  func wasmRemoveEventListener(el int32, evPtr *byte, evLen int32, evCap int32, cbID int32)
 204  
 205  //:wasmimport bridge dom_observe_resize
 206  func wasmObserveResize(el int32, cbID int32)
 207  
 208  //:wasmimport bridge dom_unobserve_resize
 209  func wasmUnobserveResize(el int32)
 210  
 211  //:wasmimport bridge dom_request_animation_frame
 212  func wasmRequestAnimationFrame(cbID int32)
 213  
 214  func RegisterCallback(fn func()) (n int32) {
 215  	return callback.Register0(fn)
 216  }
 217  
 218  func ReleaseCallback(id int32) {
 219  	callback.Release(id)
 220  }
 221  
 222  func AddEventListener(el Element, event string, callbackId int32) {
 223  	wasmAddEventListener(int32(el), unsafe.StringData(event), int32(len(event)), int32(len(event)), callbackId)
 224  }
 225  
 226  func AddSelfEventListener(el Element, event string, callbackId int32) {
 227  	wasmAddSelfEventListener(int32(el), unsafe.StringData(event), int32(len(event)), int32(len(event)), callbackId)
 228  }
 229  
 230  func AddEnterKeyListener(el Element, callbackId int32) {
 231  	wasmAddEnterKeyListener(int32(el), callbackId)
 232  }
 233  
 234  func RemoveEventListener(el Element, event string, callbackId int32) {
 235  	wasmRemoveEventListener(int32(el), unsafe.StringData(event), int32(len(event)), int32(len(event)), callbackId)
 236  }
 237  
 238  func ObserveResize(el Element, callbackId int32) {
 239  	wasmObserveResize(int32(el), callbackId)
 240  }
 241  
 242  func UnobserveResize(el Element) {
 243  	wasmUnobserveResize(int32(el))
 244  }
 245  
 246  func RequestAnimationFrame(fn func()) {
 247  	wasmRequestAnimationFrame(callback.Register0Once(fn))
 248  }
 249  
 250  // OnKeydown has a nested callback: fn(key, preventDefault).
 251  // Uses a custom hook so preventDefault can be signaled synchronously.
 252  // keydownReg is a self-mutating holder: registrations mutate it through a
 253  // method, so the map and the handler values live in its own arena rather than
 254  // in the frame of whichever wasm export registered them (and a package global
 255  // cannot be written outside a method).
 256  type keydownReg struct {
 257  	handlers map[int32]func(string, func())
 258  	nextID   int32
 259  }
 260  
 261  var keydown keydownReg
 262  
 263  func (k *keydownReg) add(fn func(string, func())) (id int32) {
 264  	if k.handlers == nil {
 265  		k.handlers = map[int32]func(string, func()){}
 266  	}
 267  	k.nextID++
 268  	id = k.nextID
 269  	k.handlers[id] = fn
 270  	return
 271  }
 272  
 273  func (k *keydownReg) get(id int32) (fn func(string, func()), ok bool) {
 274  	fn, ok = k.handlers[id]
 275  	return
 276  }
 277  
 278  //:wasmimport bridge dom_on_keydown
 279  func wasmOnKeydown(el int32, handlerID int32)
 280  
 281  func OnKeydown(el Element, fn func(string, func())) {
 282  	id := keydown.add(fn)
 283  	wasmOnKeydown(int32(el), id)
 284  }
 285  
 286  //:wasmexport __hook_keydown
 287  func hookKeydown(handlerID int32, keyPtr *byte, keyLen int32) (n int32) {
 288  	fn, ok := keydown.get(handlerID)
 289  	if !ok {
 290  		return 0
 291  	}
 292  	key := ptrToStringLocal(keyPtr, keyLen)
 293  	prevented := int32(0)
 294  	fn(key, func() { prevented = 1 })
 295  	return prevented
 296  }
 297  
 298  // --- Mention chips ---
 299  
 300  //:wasmimport bridge dom_insert_mention_chip
 301  func wasmInsertMentionChip(el int32, charCount int32, npubPtr *byte, npubLen int32, npubCap int32, namePtr *byte, nameLen int32, nameCap int32, picPtr *byte, picLen int32, picCap int32)
 302  
 303  func InsertMentionChip(el Element, charCount int32, npub, name, pic string) {
 304  	wasmInsertMentionChip(int32(el), int32(charCount),
 305  		unsafe.StringData(npub), int32(len(npub)), int32(len(npub)),
 306  		unsafe.StringData(name), int32(len(name)), int32(len(name)),
 307  		unsafe.StringData(pic), int32(len(pic)), int32(len(pic)))
 308  }
 309  
 310  // --- Timers ---
 311  
 312  //:wasmimport bridge dom_set_timeout
 313  func wasmSetTimeout(cbID int32, ms int32) (n int32)
 314  
 315  //:wasmimport bridge dom_clear_timeout
 316  func wasmClearTimeout(id int32)
 317  
 318  func SetTimeout(fn func(), ms int32) (n int32) {
 319  	return wasmSetTimeout(callback.Register0Once(fn), ms)
 320  }
 321  
 322  func ClearTimeout(id int32) { wasmClearTimeout(id) }
 323  
 324  // --- Fetch ---
 325  
 326  //:wasmimport bridge dom_fetch_text
 327  func wasmFetchText(ptr *byte, length int32, capacity int32, cbID int32)
 328  
 329  //:wasmimport bridge dom_fetch_relay_info
 330  func wasmFetchRelayInfo(ptr *byte, length int32, capacity int32, cbID int32)
 331  
 332  //:wasmimport bridge dom_fetch_put_blob_base64
 333  func wasmFetchPutBlobBase64(urlPtr *byte, urlLen int32, urlCap int32, dataPtr *byte, dataLen int32, dataCap int32, ctPtr *byte, ctLen int32, ctCap int32, authPtr *byte, authLen int32, authCap int32, cbID int32)
 334  
 335  func FetchText(url string, fn func(string)) {
 336  	wasmFetchText(unsafe.StringData(url), int32(len(url)), int32(len(url)), callback.RegisterSOnce(fn))
 337  }
 338  
 339  func FetchRelayInfo(url string, fn func(string)) {
 340  	wasmFetchRelayInfo(unsafe.StringData(url), int32(len(url)), int32(len(url)), callback.RegisterSOnce(fn))
 341  }
 342  
 343  func FetchPutBlobBase64(url, base64data, contentType, authHeader string, fn func(string)) {
 344  	wasmFetchPutBlobBase64(
 345  		unsafe.StringData(url), int32(len(url)), int32(len(url)),
 346  		unsafe.StringData(base64data), int32(len(base64data)), int32(len(base64data)),
 347  		unsafe.StringData(contentType), int32(len(contentType)), int32(len(contentType)),
 348  		unsafe.StringData(authHeader), int32(len(authHeader)), int32(len(authHeader)),
 349  		callback.RegisterSOnce(fn))
 350  }
 351  
 352  // --- IDB ---
 353  
 354  //:wasmimport bridge dom_idb_set_enc_key
 355  func wasmIDBSetEncKey(ptr *byte, length int32, capacity int32)
 356  
 357  //:wasmimport bridge dom_idb_get
 358  func wasmIDBGet(storePtr *byte, storeLen int32, storeCap int32, keyPtr *byte, keyLen int32, keyCap int32, cbID int32)
 359  
 360  //:wasmimport bridge dom_idb_put
 361  func wasmIDBPut(storePtr *byte, storeLen int32, storeCap int32, keyPtr *byte, keyLen int32, keyCap int32, valPtr *byte, valLen int32, valCap int32)
 362  
 363  //:wasmimport bridge dom_idb_get_all
 364  func wasmIDBGetAll(storePtr *byte, storeLen int32, storeCap int32, fnID int32, doneID int32)
 365  
 366  func IDBSetEncKey(hexKey string) {
 367  	wasmIDBSetEncKey(unsafe.StringData(hexKey), int32(len(hexKey)), int32(len(hexKey)))
 368  }
 369  
 370  func IDBGet(store, key string, fn func(string)) {
 371  	wasmIDBGet(
 372  		unsafe.StringData(store), int32(len(store)), int32(len(store)),
 373  		unsafe.StringData(key), int32(len(key)), int32(len(key)),
 374  		callback.RegisterSOnce(fn))
 375  }
 376  
 377  func IDBPut(store, key, value string) {
 378  	wasmIDBPut(
 379  		unsafe.StringData(store), int32(len(store)), int32(len(store)),
 380  		unsafe.StringData(key), int32(len(key)), int32(len(key)),
 381  		unsafe.StringData(value), int32(len(value)), int32(len(value)))
 382  }
 383  
 384  func IDBGetAll(store string, fn func(string, string), done func()) {
 385  	fnID := callback.RegisterSS(fn)
 386  	doneID := callback.Register0Once(func() {
 387  		callback.Release(fnID)
 388  		done()
 389  	})
 390  	wasmIDBGetAll(unsafe.StringData(store), int32(len(store)), int32(len(store)), fnID, doneID)
 391  }
 392  
 393  // --- Browser state ---
 394  
 395  //:wasmimport bridge dom_prefers_dark
 396  func wasmPrefersDark() (n int32)
 397  
 398  //:wasmimport bridge dom_console_log
 399  func wasmConsoleLog(ptr *byte, length int32, capacity int32)
 400  
 401  //:wasmimport bridge dom_confirm
 402  func wasmConfirm(ptr *byte, length int32, capacity int32) (n int32)
 403  
 404  //:wasmimport bridge dom_post_to_sw
 405  func wasmPostToSW(ptr *byte, length int32, capacity int32)
 406  
 407  //:wasmimport bridge dom_on_sw_message
 408  func wasmOnSWMessage(cbID int32)
 409  
 410  //:wasmimport bridge dom_push_state
 411  func wasmPushState(ptr *byte, length int32, capacity int32)
 412  
 413  //:wasmimport bridge dom_replace_state
 414  func wasmReplaceState(ptr *byte, length int32, capacity int32)
 415  
 416  //:wasmimport bridge dom_back
 417  func wasmBack()
 418  
 419  //:wasmimport bridge dom_location_reload
 420  func wasmLocationReload()
 421  
 422  //:wasmimport bridge dom_location_assign
 423  func wasmLocationAssign(ptr *byte, length int32, capacity int32)
 424  
 425  //:wasmimport bridge dom_hard_refresh
 426  func wasmHardRefresh()
 427  
 428  //:wasmimport bridge dom_clear_storage_prefix
 429  func wasmClearStoragePrefix(ptr *byte, length int32, capacity int32)
 430  
 431  //:wasmimport bridge dom_timezone_offset_seconds
 432  func wasmTimezoneOffsetSeconds() (n int32)
 433  
 434  //:wasmimport bridge dom_read_clipboard
 435  func wasmReadClipboard(cbID int32)
 436  
 437  //:wasmimport bridge dom_write_clipboard
 438  func wasmWriteClipboard(ptr *byte, length int32, capacity int32, cbID int32)
 439  
 440  //:wasmimport bridge dom_get_path
 441  func wasmGetPath(outPtr *int32, outLen *int32)
 442  
 443  //:wasmimport bridge dom_get_hash
 444  func wasmGetHash(outPtr *int32, outLen *int32)
 445  
 446  //:wasmimport bridge dom_hostname
 447  func wasmHostname(outPtr *int32, outLen *int32)
 448  
 449  //:wasmimport bridge dom_port
 450  func wasmPort(outPtr *int32, outLen *int32)
 451  
 452  //:wasmimport bridge dom_user_agent
 453  func wasmUserAgent(outPtr *int32, outLen *int32)
 454  
 455  //:wasmimport bridge dom_on_pop_state
 456  func wasmOnPopState(cbID int32)
 457  
 458  //:wasmimport bridge dom_intercept_internal_links
 459  func wasmInterceptInternalLinks(cbID int32)
 460  
 461  //:wasmimport bridge dom_pick_file_text
 462  func wasmPickFileText(ptr *byte, length int32, capacity int32, cbID int32)
 463  
 464  //:wasmimport bridge dom_download_text
 465  func wasmDownloadText(fnPtr *byte, fnLen int32, fnCap int32, ctPtr *byte, ctLen int32, ctCap int32, mtPtr *byte, mtLen int32, mtCap int32)
 466  
 467  //:wasmimport bridge dom_on_pull_refresh
 468  func wasmOnPullRefresh(el int32, indicator int32, cbID int32)
 469  
 470  //:wasmimport bridge dom_now_seconds
 471  func wasmNowSeconds() (n int64)
 472  
 473  //:wasmimport bridge dom_pick_file_base64
 474  func wasmPickFileBase64(ptr *byte, length int32, capacity int32, cbID int32)
 475  
 476  //:wasmimport bridge dom_on_paste_image
 477  func wasmOnPasteImage(el int32, cbID int32)
 478  
 479  //:wasmimport bridge dom_on_drop_image
 480  func wasmOnDropImage(el int32, cbID int32)
 481  
 482  func PrefersDark() (ok bool) { return wasmPrefersDark() != 0 }
 483  
 484  func ConsoleLog(msg string) {
 485  	wasmConsoleLog(unsafe.StringData(msg), int32(len(msg)), int32(len(msg)))
 486  }
 487  
 488  func Confirm(msg string) (ok bool) {
 489  	return wasmConfirm(unsafe.StringData(msg), int32(len(msg)), int32(len(msg))) != 0
 490  }
 491  
 492  func PostToSW(msg string) {
 493  	wasmPostToSW(unsafe.StringData(msg), int32(len(msg)), int32(len(msg)))
 494  }
 495  
 496  func OnSWMessage(fn func(string)) {
 497  	wasmOnSWMessage(callback.RegisterS(fn))
 498  }
 499  
 500  func PushState(path string) {
 501  	wasmPushState(unsafe.StringData(path), int32(len(path)), int32(len(path)))
 502  }
 503  
 504  func ReplaceState(path string) {
 505  	wasmReplaceState(unsafe.StringData(path), int32(len(path)), int32(len(path)))
 506  }
 507  
 508  func Back()           { wasmBack() }
 509  func LocationReload() { wasmLocationReload() }
 510  func LocationAssign(url string) {
 511  	wasmLocationAssign(unsafe.StringData(url), int32(len(url)), int32(len(url)))
 512  }
 513  func HardRefresh()    { wasmHardRefresh() }
 514  
 515  func ClearStoragePrefix(prefix string) {
 516  	wasmClearStoragePrefix(unsafe.StringData(prefix), int32(len(prefix)), int32(len(prefix)))
 517  }
 518  
 519  func TimezoneOffsetSeconds() (n int32) { return wasmTimezoneOffsetSeconds() }
 520  
 521  func ReadClipboard(fn func(string)) {
 522  	wasmReadClipboard(callback.RegisterSOnce(fn))
 523  }
 524  
 525  func WriteClipboard(text string, fn func(bool)) {
 526  	wasmWriteClipboard(unsafe.StringData(text), int32(len(text)), int32(len(text)), callback.RegisterBOnce(fn))
 527  }
 528  
 529  //:wasmimport bridge dom_write_primary_selection
 530  func wasmWritePrimarySelection(ptr *byte, length int32, capacity int32)
 531  
 532  func WritePrimarySelection(text string) {
 533  	wasmWritePrimarySelection(unsafe.StringData(text), int32(len(text)), int32(len(text)))
 534  }
 535  
 536  //:wasmimport bridge dom_copy_image_to_clipboard
 537  func wasmCopyImageToClipboard(el int32, cbID int32)
 538  
 539  func CopyImageToClipboard(el Element, fn func(bool)) {
 540  	wasmCopyImageToClipboard(int32(el), callback.RegisterBOnce(fn))
 541  }
 542  
 543  //:wasmimport bridge dom_window_open
 544  func wasmWindowOpen(ptr *byte, length int32, capacity int32)
 545  
 546  func WindowOpen(url string) {
 547  	wasmWindowOpen(unsafe.StringData(url), int32(len(url)), int32(len(url)))
 548  }
 549  
 550  //:wasmimport bridge dom_encode_uri_component
 551  func wasmEncodeURIComponent(ptr *byte, length int32, capacity int32, rPtr *int32, rLen *int32)
 552  
 553  func EncodeURIComponent(s string) (sv string) {
 554  	var rPtr, rLen int32
 555  	wasmEncodeURIComponent(unsafe.StringData(s), int32(len(s)), int32(len(s)), &rPtr, &rLen)
 556  	return ptrToString(rPtr, rLen)
 557  }
 558  
 559  func GetPath() (s string) {
 560  	var rPtr, rLen int32
 561  	wasmGetPath(&rPtr, &rLen)
 562  	return ptrToString(rPtr, rLen)
 563  }
 564  
 565  func GetHash() (s string) {
 566  	var rPtr, rLen int32
 567  	wasmGetHash(&rPtr, &rLen)
 568  	return ptrToString(rPtr, rLen)
 569  }
 570  
 571  func Hostname() (s string) {
 572  	var rPtr, rLen int32
 573  	wasmHostname(&rPtr, &rLen)
 574  	return ptrToString(rPtr, rLen)
 575  }
 576  
 577  func Port() (s string) {
 578  	var rPtr, rLen int32
 579  	wasmPort(&rPtr, &rLen)
 580  	return ptrToString(rPtr, rLen)
 581  }
 582  
 583  func UserAgent() (s string) {
 584  	var rPtr, rLen int32
 585  	wasmUserAgent(&rPtr, &rLen)
 586  	return ptrToString(rPtr, rLen)
 587  }
 588  
 589  func OnPopState(fn func(string)) {
 590  	wasmOnPopState(callback.RegisterS(fn))
 591  }
 592  
 593  func InterceptInternalLinks(fn func(string)) {
 594  	wasmInterceptInternalLinks(callback.RegisterS(fn))
 595  }
 596  
 597  func PickFileText(accept string, fn func(string)) {
 598  	wasmPickFileText(unsafe.StringData(accept), int32(len(accept)), int32(len(accept)), callback.RegisterSOnce(fn))
 599  }
 600  
 601  func DownloadText(filename, content, mimeType string) {
 602  	wasmDownloadText(
 603  		unsafe.StringData(filename), int32(len(filename)), int32(len(filename)),
 604  		unsafe.StringData(content), int32(len(content)), int32(len(content)),
 605  		unsafe.StringData(mimeType), int32(len(mimeType)), int32(len(mimeType)))
 606  }
 607  
 608  func OnPullRefresh(el Element, indicator Element, fn func()) {
 609  	wasmOnPullRefresh(int32(el), int32(indicator), callback.Register0(fn))
 610  }
 611  
 612  func NowSeconds() (n int64) { return wasmNowSeconds() }
 613  
 614  func PickFileBase64(accept string, fn func(string, string)) {
 615  	wasmPickFileBase64(unsafe.StringData(accept), int32(len(accept)), int32(len(accept)), callback.RegisterSSOnce(fn))
 616  }
 617  
 618  func OnPasteImage(el Element, fn func(string, string)) {
 619  	wasmOnPasteImage(int32(el), callback.RegisterSS(fn))
 620  }
 621  
 622  func OnDropImage(el Element, fn func(string, string)) {
 623  	wasmOnDropImage(int32(el), callback.RegisterSS(fn))
 624  }
 625  
 626  func ptrToString(ptr int32, length int32) (s string) {
 627  	if length <= 0 {
 628  		return ""
 629  	}
 630  	return unsafe.String((*byte)(unsafe.Pointer(uintptr(ptr))), length)
 631  }
 632  
 633  func ptrToStringLocal(ptr *byte, length int32) (s string) {
 634  	if ptr == nil || length <= 0 {
 635  		return ""
 636  	}
 637  	return unsafe.String(ptr, length)
 638  }
 639