github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/brailledisplayprivate/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/brailledisplayprivate", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "store_DisplayState": (ptr: Pointer, ref: heap.Ref<any>) => { 8 const x = A.H.get<any>(ref); 9 10 if (typeof x === "undefined") { 11 A.store.Bool(ptr + 20, false); 12 A.store.Bool(ptr + 16, false); 13 A.store.Bool(ptr + 0, false); 14 A.store.Bool(ptr + 17, false); 15 A.store.Int32(ptr + 4, 0); 16 A.store.Bool(ptr + 18, false); 17 A.store.Int32(ptr + 8, 0); 18 A.store.Bool(ptr + 19, false); 19 A.store.Int32(ptr + 12, 0); 20 } else { 21 A.store.Bool(ptr + 20, true); 22 A.store.Bool(ptr + 16, "available" in x ? true : false); 23 A.store.Bool(ptr + 0, x["available"] ? true : false); 24 A.store.Bool(ptr + 17, "textRowCount" in x ? true : false); 25 A.store.Int32(ptr + 4, x["textRowCount"] === undefined ? 0 : (x["textRowCount"] as number)); 26 A.store.Bool(ptr + 18, "textColumnCount" in x ? true : false); 27 A.store.Int32(ptr + 8, x["textColumnCount"] === undefined ? 0 : (x["textColumnCount"] as number)); 28 A.store.Bool(ptr + 19, "cellSize" in x ? true : false); 29 A.store.Int32(ptr + 12, x["cellSize"] === undefined ? 0 : (x["cellSize"] as number)); 30 } 31 }, 32 "load_DisplayState": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 33 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 34 35 if (A.load.Bool(ptr + 16)) { 36 x["available"] = A.load.Bool(ptr + 0); 37 } else { 38 delete x["available"]; 39 } 40 if (A.load.Bool(ptr + 17)) { 41 x["textRowCount"] = A.load.Int32(ptr + 4); 42 } else { 43 delete x["textRowCount"]; 44 } 45 if (A.load.Bool(ptr + 18)) { 46 x["textColumnCount"] = A.load.Int32(ptr + 8); 47 } else { 48 delete x["textColumnCount"]; 49 } 50 if (A.load.Bool(ptr + 19)) { 51 x["cellSize"] = A.load.Int32(ptr + 12); 52 } else { 53 delete x["cellSize"]; 54 } 55 return create === A.H.TRUE ? A.H.push(x) : ref; 56 }, 57 "constof_KeyCommand": (ref: heap.Ref<string>): number => { 58 const idx = [ 59 "line_up", 60 "line_down", 61 "pan_left", 62 "pan_right", 63 "top", 64 "bottom", 65 "routing", 66 "secondary_routing", 67 "dots", 68 "chord", 69 "standard_key", 70 ].indexOf(A.H.get(ref)); 71 return idx < 0 ? 0 : idx + 1; 72 }, 73 74 "store_KeyEvent": (ptr: Pointer, ref: heap.Ref<any>) => { 75 const x = A.H.get<any>(ref); 76 77 if (typeof x === "undefined") { 78 A.store.Bool(ptr + 30, false); 79 A.store.Enum(ptr + 0, -1); 80 A.store.Bool(ptr + 24, false); 81 A.store.Int32(ptr + 4, 0); 82 A.store.Bool(ptr + 25, false); 83 A.store.Int32(ptr + 8, 0); 84 A.store.Ref(ptr + 12, undefined); 85 A.store.Ref(ptr + 16, undefined); 86 A.store.Bool(ptr + 26, false); 87 A.store.Bool(ptr + 20, false); 88 A.store.Bool(ptr + 27, false); 89 A.store.Bool(ptr + 21, false); 90 A.store.Bool(ptr + 28, false); 91 A.store.Bool(ptr + 22, false); 92 A.store.Bool(ptr + 29, false); 93 A.store.Bool(ptr + 23, false); 94 } else { 95 A.store.Bool(ptr + 30, true); 96 A.store.Enum( 97 ptr + 0, 98 [ 99 "line_up", 100 "line_down", 101 "pan_left", 102 "pan_right", 103 "top", 104 "bottom", 105 "routing", 106 "secondary_routing", 107 "dots", 108 "chord", 109 "standard_key", 110 ].indexOf(x["command"] as string) 111 ); 112 A.store.Bool(ptr + 24, "displayPosition" in x ? true : false); 113 A.store.Int32(ptr + 4, x["displayPosition"] === undefined ? 0 : (x["displayPosition"] as number)); 114 A.store.Bool(ptr + 25, "brailleDots" in x ? true : false); 115 A.store.Int32(ptr + 8, x["brailleDots"] === undefined ? 0 : (x["brailleDots"] as number)); 116 A.store.Ref(ptr + 12, x["standardKeyCode"]); 117 A.store.Ref(ptr + 16, x["standardKeyChar"]); 118 A.store.Bool(ptr + 26, "spaceKey" in x ? true : false); 119 A.store.Bool(ptr + 20, x["spaceKey"] ? true : false); 120 A.store.Bool(ptr + 27, "altKey" in x ? true : false); 121 A.store.Bool(ptr + 21, x["altKey"] ? true : false); 122 A.store.Bool(ptr + 28, "shiftKey" in x ? true : false); 123 A.store.Bool(ptr + 22, x["shiftKey"] ? true : false); 124 A.store.Bool(ptr + 29, "ctrlKey" in x ? true : false); 125 A.store.Bool(ptr + 23, x["ctrlKey"] ? true : false); 126 } 127 }, 128 "load_KeyEvent": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 129 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 130 131 x["command"] = A.load.Enum(ptr + 0, [ 132 "line_up", 133 "line_down", 134 "pan_left", 135 "pan_right", 136 "top", 137 "bottom", 138 "routing", 139 "secondary_routing", 140 "dots", 141 "chord", 142 "standard_key", 143 ]); 144 if (A.load.Bool(ptr + 24)) { 145 x["displayPosition"] = A.load.Int32(ptr + 4); 146 } else { 147 delete x["displayPosition"]; 148 } 149 if (A.load.Bool(ptr + 25)) { 150 x["brailleDots"] = A.load.Int32(ptr + 8); 151 } else { 152 delete x["brailleDots"]; 153 } 154 x["standardKeyCode"] = A.load.Ref(ptr + 12, undefined); 155 x["standardKeyChar"] = A.load.Ref(ptr + 16, undefined); 156 if (A.load.Bool(ptr + 26)) { 157 x["spaceKey"] = A.load.Bool(ptr + 20); 158 } else { 159 delete x["spaceKey"]; 160 } 161 if (A.load.Bool(ptr + 27)) { 162 x["altKey"] = A.load.Bool(ptr + 21); 163 } else { 164 delete x["altKey"]; 165 } 166 if (A.load.Bool(ptr + 28)) { 167 x["shiftKey"] = A.load.Bool(ptr + 22); 168 } else { 169 delete x["shiftKey"]; 170 } 171 if (A.load.Bool(ptr + 29)) { 172 x["ctrlKey"] = A.load.Bool(ptr + 23); 173 } else { 174 delete x["ctrlKey"]; 175 } 176 return create === A.H.TRUE ? A.H.push(x) : ref; 177 }, 178 "has_GetDisplayState": (): heap.Ref<boolean> => { 179 if (WEBEXT?.brailleDisplayPrivate && "getDisplayState" in WEBEXT?.brailleDisplayPrivate) { 180 return A.H.TRUE; 181 } 182 return A.H.FALSE; 183 }, 184 "func_GetDisplayState": (fn: Pointer): void => { 185 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.getDisplayState); 186 }, 187 "call_GetDisplayState": (retPtr: Pointer): void => { 188 const _ret = WEBEXT.brailleDisplayPrivate.getDisplayState(); 189 A.store.Ref(retPtr, _ret); 190 }, 191 "try_GetDisplayState": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 192 try { 193 const _ret = WEBEXT.brailleDisplayPrivate.getDisplayState(); 194 A.store.Ref(retPtr, _ret); 195 return A.H.TRUE; 196 } catch (err: any) { 197 A.store.Ref(errPtr, err); 198 return A.H.FALSE; 199 } 200 }, 201 "has_OnDisplayStateChanged": (): heap.Ref<boolean> => { 202 if ( 203 WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged && 204 "addListener" in WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged 205 ) { 206 return A.H.TRUE; 207 } 208 return A.H.FALSE; 209 }, 210 "func_OnDisplayStateChanged": (fn: Pointer): void => { 211 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.addListener); 212 }, 213 "call_OnDisplayStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 214 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.addListener(A.H.get<object>(callback)); 215 }, 216 "try_OnDisplayStateChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 217 try { 218 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.addListener(A.H.get<object>(callback)); 219 return A.H.TRUE; 220 } catch (err: any) { 221 A.store.Ref(errPtr, err); 222 return A.H.FALSE; 223 } 224 }, 225 "has_OffDisplayStateChanged": (): heap.Ref<boolean> => { 226 if ( 227 WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged && 228 "removeListener" in WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged 229 ) { 230 return A.H.TRUE; 231 } 232 return A.H.FALSE; 233 }, 234 "func_OffDisplayStateChanged": (fn: Pointer): void => { 235 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.removeListener); 236 }, 237 "call_OffDisplayStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 238 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.removeListener(A.H.get<object>(callback)); 239 }, 240 "try_OffDisplayStateChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 241 try { 242 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.removeListener(A.H.get<object>(callback)); 243 return A.H.TRUE; 244 } catch (err: any) { 245 A.store.Ref(errPtr, err); 246 return A.H.FALSE; 247 } 248 }, 249 "has_HasOnDisplayStateChanged": (): heap.Ref<boolean> => { 250 if ( 251 WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged && 252 "hasListener" in WEBEXT?.brailleDisplayPrivate?.onDisplayStateChanged 253 ) { 254 return A.H.TRUE; 255 } 256 return A.H.FALSE; 257 }, 258 "func_HasOnDisplayStateChanged": (fn: Pointer): void => { 259 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.hasListener); 260 }, 261 "call_HasOnDisplayStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 262 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.hasListener(A.H.get<object>(callback)); 263 A.store.Bool(retPtr, _ret); 264 }, 265 "try_HasOnDisplayStateChanged": ( 266 retPtr: Pointer, 267 errPtr: Pointer, 268 callback: heap.Ref<object> 269 ): heap.Ref<boolean> => { 270 try { 271 const _ret = WEBEXT.brailleDisplayPrivate.onDisplayStateChanged.hasListener(A.H.get<object>(callback)); 272 A.store.Bool(retPtr, _ret); 273 return A.H.TRUE; 274 } catch (err: any) { 275 A.store.Ref(errPtr, err); 276 return A.H.FALSE; 277 } 278 }, 279 "has_OnKeyEvent": (): heap.Ref<boolean> => { 280 if (WEBEXT?.brailleDisplayPrivate?.onKeyEvent && "addListener" in WEBEXT?.brailleDisplayPrivate?.onKeyEvent) { 281 return A.H.TRUE; 282 } 283 return A.H.FALSE; 284 }, 285 "func_OnKeyEvent": (fn: Pointer): void => { 286 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onKeyEvent.addListener); 287 }, 288 "call_OnKeyEvent": (retPtr: Pointer, callback: heap.Ref<object>): void => { 289 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.addListener(A.H.get<object>(callback)); 290 }, 291 "try_OnKeyEvent": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 292 try { 293 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.addListener(A.H.get<object>(callback)); 294 return A.H.TRUE; 295 } catch (err: any) { 296 A.store.Ref(errPtr, err); 297 return A.H.FALSE; 298 } 299 }, 300 "has_OffKeyEvent": (): heap.Ref<boolean> => { 301 if (WEBEXT?.brailleDisplayPrivate?.onKeyEvent && "removeListener" in WEBEXT?.brailleDisplayPrivate?.onKeyEvent) { 302 return A.H.TRUE; 303 } 304 return A.H.FALSE; 305 }, 306 "func_OffKeyEvent": (fn: Pointer): void => { 307 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onKeyEvent.removeListener); 308 }, 309 "call_OffKeyEvent": (retPtr: Pointer, callback: heap.Ref<object>): void => { 310 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.removeListener(A.H.get<object>(callback)); 311 }, 312 "try_OffKeyEvent": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 313 try { 314 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.removeListener(A.H.get<object>(callback)); 315 return A.H.TRUE; 316 } catch (err: any) { 317 A.store.Ref(errPtr, err); 318 return A.H.FALSE; 319 } 320 }, 321 "has_HasOnKeyEvent": (): heap.Ref<boolean> => { 322 if (WEBEXT?.brailleDisplayPrivate?.onKeyEvent && "hasListener" in WEBEXT?.brailleDisplayPrivate?.onKeyEvent) { 323 return A.H.TRUE; 324 } 325 return A.H.FALSE; 326 }, 327 "func_HasOnKeyEvent": (fn: Pointer): void => { 328 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.onKeyEvent.hasListener); 329 }, 330 "call_HasOnKeyEvent": (retPtr: Pointer, callback: heap.Ref<object>): void => { 331 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.hasListener(A.H.get<object>(callback)); 332 A.store.Bool(retPtr, _ret); 333 }, 334 "try_HasOnKeyEvent": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 335 try { 336 const _ret = WEBEXT.brailleDisplayPrivate.onKeyEvent.hasListener(A.H.get<object>(callback)); 337 A.store.Bool(retPtr, _ret); 338 return A.H.TRUE; 339 } catch (err: any) { 340 A.store.Ref(errPtr, err); 341 return A.H.FALSE; 342 } 343 }, 344 "has_UpdateBluetoothBrailleDisplayAddress": (): heap.Ref<boolean> => { 345 if (WEBEXT?.brailleDisplayPrivate && "updateBluetoothBrailleDisplayAddress" in WEBEXT?.brailleDisplayPrivate) { 346 return A.H.TRUE; 347 } 348 return A.H.FALSE; 349 }, 350 "func_UpdateBluetoothBrailleDisplayAddress": (fn: Pointer): void => { 351 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.updateBluetoothBrailleDisplayAddress); 352 }, 353 "call_UpdateBluetoothBrailleDisplayAddress": (retPtr: Pointer, address: heap.Ref<object>): void => { 354 const _ret = WEBEXT.brailleDisplayPrivate.updateBluetoothBrailleDisplayAddress(A.H.get<object>(address)); 355 }, 356 "try_UpdateBluetoothBrailleDisplayAddress": ( 357 retPtr: Pointer, 358 errPtr: Pointer, 359 address: heap.Ref<object> 360 ): heap.Ref<boolean> => { 361 try { 362 const _ret = WEBEXT.brailleDisplayPrivate.updateBluetoothBrailleDisplayAddress(A.H.get<object>(address)); 363 return A.H.TRUE; 364 } catch (err: any) { 365 A.store.Ref(errPtr, err); 366 return A.H.FALSE; 367 } 368 }, 369 "has_WriteDots": (): heap.Ref<boolean> => { 370 if (WEBEXT?.brailleDisplayPrivate && "writeDots" in WEBEXT?.brailleDisplayPrivate) { 371 return A.H.TRUE; 372 } 373 return A.H.FALSE; 374 }, 375 "func_WriteDots": (fn: Pointer): void => { 376 A.store.Ref(fn, WEBEXT.brailleDisplayPrivate.writeDots); 377 }, 378 "call_WriteDots": (retPtr: Pointer, cells: heap.Ref<object>, columns: number, rows: number): void => { 379 const _ret = WEBEXT.brailleDisplayPrivate.writeDots(A.H.get<object>(cells), columns, rows); 380 }, 381 "try_WriteDots": ( 382 retPtr: Pointer, 383 errPtr: Pointer, 384 cells: heap.Ref<object>, 385 columns: number, 386 rows: number 387 ): heap.Ref<boolean> => { 388 try { 389 const _ret = WEBEXT.brailleDisplayPrivate.writeDots(A.H.get<object>(cells), columns, rows); 390 return A.H.TRUE; 391 } catch (err: any) { 392 A.store.Ref(errPtr, err); 393 return A.H.FALSE; 394 } 395 }, 396 }; 397 });