github.com/primecitizens/pcz/std@v0.2.1/ui/html/ffi_bindings.ts (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 import { Application, Pointer, heap, importModule } from "@ffi"; 5 6 importModule("ui/html/builder", (A: Application) => { 7 const registry = new Map<heap.Ref<HTMLElement>, string[]>(); 8 9 return { 10 "reset": (elem: heap.Ref<HTMLElement>) => { 11 if (registry.has(elem)) { 12 registry.get(elem).splice(0); 13 return; 14 } 15 16 registry.set(elem, []); 17 }, 18 "free": (elem: heap.Ref<HTMLElement>) => { 19 registry.delete(elem); 20 }, 21 "integer": (elem: heap.Ref<HTMLElement>, signed: heap.Ref<boolean>, p64: Pointer, radix: number) => { 22 registry.get(elem).push((signed === A.H.TRUE ? A.load.BigInt64(p64) : A.load.BigUint64(p64)).toString(radix)); 23 }, 24 "float": (elem: heap.Ref<HTMLElement>, num: number) => { 25 registry.get(elem).push(num.toString(10)); 26 }, 27 "buf_str": (elem: heap.Ref<HTMLElement>, pBytes: Pointer, len: number): void => { 28 registry.get(elem).push(A.load.String(pBytes, len)); 29 }, 30 "buf_jsstr": (elem: heap.Ref<HTMLElement>, escape: heap.Ref<boolean>, pRefs: Pointer, len: number): void => { 31 registry.get(elem).push(...A.load.Refs(pRefs, len)); 32 }, 33 "flush": (elem: heap.Ref<HTMLElement>, append: heap.Ref<boolean>): void => { 34 const data = registry.get(elem).splice(0).join(""); 35 if (append === A.H.TRUE) { 36 A.H.get<HTMLElement>(elem).innerHTML += data; 37 return; 38 } 39 40 A.H.get<HTMLElement>(elem).innerHTML = data; 41 }, 42 }; 43 });