github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/clipboard/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/clipboard", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_DataItemType": (ref: heap.Ref<string>): number => { 8 const idx = ["textPlain", "textHtml"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 12 "store_AdditionalDataItem": (ptr: Pointer, ref: heap.Ref<any>) => { 13 const x = A.H.get<any>(ref); 14 15 if (typeof x === "undefined") { 16 A.store.Bool(ptr + 8, false); 17 A.store.Enum(ptr + 0, -1); 18 A.store.Ref(ptr + 4, undefined); 19 } else { 20 A.store.Bool(ptr + 8, true); 21 A.store.Enum(ptr + 0, ["textPlain", "textHtml"].indexOf(x["type"] as string)); 22 A.store.Ref(ptr + 4, x["data"]); 23 } 24 }, 25 "load_AdditionalDataItem": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 26 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 27 28 x["type"] = A.load.Enum(ptr + 0, ["textPlain", "textHtml"]); 29 x["data"] = A.load.Ref(ptr + 4, undefined); 30 return create === A.H.TRUE ? A.H.push(x) : ref; 31 }, 32 "constof_ImageType": (ref: heap.Ref<string>): number => { 33 const idx = ["png", "jpeg"].indexOf(A.H.get(ref)); 34 return idx < 0 ? 0 : idx + 1; 35 }, 36 "has_OnClipboardDataChanged": (): heap.Ref<boolean> => { 37 if (WEBEXT?.clipboard?.onClipboardDataChanged && "addListener" in WEBEXT?.clipboard?.onClipboardDataChanged) { 38 return A.H.TRUE; 39 } 40 return A.H.FALSE; 41 }, 42 "func_OnClipboardDataChanged": (fn: Pointer): void => { 43 A.store.Ref(fn, WEBEXT.clipboard.onClipboardDataChanged.addListener); 44 }, 45 "call_OnClipboardDataChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 46 const _ret = WEBEXT.clipboard.onClipboardDataChanged.addListener(A.H.get<object>(callback)); 47 }, 48 "try_OnClipboardDataChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 49 try { 50 const _ret = WEBEXT.clipboard.onClipboardDataChanged.addListener(A.H.get<object>(callback)); 51 return A.H.TRUE; 52 } catch (err: any) { 53 A.store.Ref(errPtr, err); 54 return A.H.FALSE; 55 } 56 }, 57 "has_OffClipboardDataChanged": (): heap.Ref<boolean> => { 58 if (WEBEXT?.clipboard?.onClipboardDataChanged && "removeListener" in WEBEXT?.clipboard?.onClipboardDataChanged) { 59 return A.H.TRUE; 60 } 61 return A.H.FALSE; 62 }, 63 "func_OffClipboardDataChanged": (fn: Pointer): void => { 64 A.store.Ref(fn, WEBEXT.clipboard.onClipboardDataChanged.removeListener); 65 }, 66 "call_OffClipboardDataChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 67 const _ret = WEBEXT.clipboard.onClipboardDataChanged.removeListener(A.H.get<object>(callback)); 68 }, 69 "try_OffClipboardDataChanged": ( 70 retPtr: Pointer, 71 errPtr: Pointer, 72 callback: heap.Ref<object> 73 ): heap.Ref<boolean> => { 74 try { 75 const _ret = WEBEXT.clipboard.onClipboardDataChanged.removeListener(A.H.get<object>(callback)); 76 return A.H.TRUE; 77 } catch (err: any) { 78 A.store.Ref(errPtr, err); 79 return A.H.FALSE; 80 } 81 }, 82 "has_HasOnClipboardDataChanged": (): heap.Ref<boolean> => { 83 if (WEBEXT?.clipboard?.onClipboardDataChanged && "hasListener" in WEBEXT?.clipboard?.onClipboardDataChanged) { 84 return A.H.TRUE; 85 } 86 return A.H.FALSE; 87 }, 88 "func_HasOnClipboardDataChanged": (fn: Pointer): void => { 89 A.store.Ref(fn, WEBEXT.clipboard.onClipboardDataChanged.hasListener); 90 }, 91 "call_HasOnClipboardDataChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 92 const _ret = WEBEXT.clipboard.onClipboardDataChanged.hasListener(A.H.get<object>(callback)); 93 A.store.Bool(retPtr, _ret); 94 }, 95 "try_HasOnClipboardDataChanged": ( 96 retPtr: Pointer, 97 errPtr: Pointer, 98 callback: heap.Ref<object> 99 ): heap.Ref<boolean> => { 100 try { 101 const _ret = WEBEXT.clipboard.onClipboardDataChanged.hasListener(A.H.get<object>(callback)); 102 A.store.Bool(retPtr, _ret); 103 return A.H.TRUE; 104 } catch (err: any) { 105 A.store.Ref(errPtr, err); 106 return A.H.FALSE; 107 } 108 }, 109 "has_SetImageData": (): heap.Ref<boolean> => { 110 if (WEBEXT?.clipboard && "setImageData" in WEBEXT?.clipboard) { 111 return A.H.TRUE; 112 } 113 return A.H.FALSE; 114 }, 115 "func_SetImageData": (fn: Pointer): void => { 116 A.store.Ref(fn, WEBEXT.clipboard.setImageData); 117 }, 118 "call_SetImageData": ( 119 retPtr: Pointer, 120 imageData: heap.Ref<object>, 121 type: number, 122 additionalItems: heap.Ref<object> 123 ): void => { 124 const _ret = WEBEXT.clipboard.setImageData( 125 A.H.get<object>(imageData), 126 type > 0 && type <= 2 ? ["png", "jpeg"][type - 1] : undefined, 127 A.H.get<object>(additionalItems) 128 ); 129 A.store.Ref(retPtr, _ret); 130 }, 131 "try_SetImageData": ( 132 retPtr: Pointer, 133 errPtr: Pointer, 134 imageData: heap.Ref<object>, 135 type: number, 136 additionalItems: heap.Ref<object> 137 ): heap.Ref<boolean> => { 138 try { 139 const _ret = WEBEXT.clipboard.setImageData( 140 A.H.get<object>(imageData), 141 type > 0 && type <= 2 ? ["png", "jpeg"][type - 1] : undefined, 142 A.H.get<object>(additionalItems) 143 ); 144 A.store.Ref(retPtr, _ret); 145 return A.H.TRUE; 146 } catch (err: any) { 147 A.store.Ref(errPtr, err); 148 return A.H.FALSE; 149 } 150 }, 151 }; 152 });