github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/pdfviewerprivate/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package pdfviewerprivate 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/ffi/js" 9 "github.com/primecitizens/pcz/std/plat/js/webext/pdfviewerprivate/bindings" 10 ) 11 12 type IsAllowedLocalFileAccessCallbackFunc func(this js.Ref, result bool) js.Ref 13 14 func (fn IsAllowedLocalFileAccessCallbackFunc) Register() js.Func[func(result bool)] { 15 return js.RegisterCallback[func(result bool)]( 16 fn, abi.FuncPCABIInternal(fn), 17 ) 18 } 19 20 func (fn IsAllowedLocalFileAccessCallbackFunc) DispatchCallback( 21 targetPC uintptr, ctx *js.CallbackContext, 22 ) { 23 args := ctx.Args() 24 if len(args) != 1+1 /* js this */ || 25 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 26 js.ThrowInvalidCallbackInvocation() 27 } 28 29 if ctx.Return(fn( 30 args[0], 31 32 args[0+1] == js.True, 33 )) { 34 return 35 } 36 37 js.ThrowCallbackValueNotReturned() 38 } 39 40 type IsAllowedLocalFileAccessCallback[T any] struct { 41 Fn func(arg T, this js.Ref, result bool) js.Ref 42 Arg T 43 } 44 45 func (cb *IsAllowedLocalFileAccessCallback[T]) Register() js.Func[func(result bool)] { 46 return js.RegisterCallback[func(result bool)]( 47 cb, abi.FuncPCABIInternal(cb.Fn), 48 ) 49 } 50 51 func (cb *IsAllowedLocalFileAccessCallback[T]) DispatchCallback( 52 targetPC uintptr, ctx *js.CallbackContext, 53 ) { 54 args := ctx.Args() 55 if len(args) != 1+1 /* js this */ || 56 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 57 js.ThrowInvalidCallbackInvocation() 58 } 59 60 if ctx.Return(cb.Fn( 61 cb.Arg, 62 args[0], 63 64 args[0+1] == js.True, 65 )) { 66 return 67 } 68 69 js.ThrowCallbackValueNotReturned() 70 } 71 72 type IsPdfOcrAlwaysActiveCallbackFunc func(this js.Ref, result bool) js.Ref 73 74 func (fn IsPdfOcrAlwaysActiveCallbackFunc) Register() js.Func[func(result bool)] { 75 return js.RegisterCallback[func(result bool)]( 76 fn, abi.FuncPCABIInternal(fn), 77 ) 78 } 79 80 func (fn IsPdfOcrAlwaysActiveCallbackFunc) DispatchCallback( 81 targetPC uintptr, ctx *js.CallbackContext, 82 ) { 83 args := ctx.Args() 84 if len(args) != 1+1 /* js this */ || 85 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 86 js.ThrowInvalidCallbackInvocation() 87 } 88 89 if ctx.Return(fn( 90 args[0], 91 92 args[0+1] == js.True, 93 )) { 94 return 95 } 96 97 js.ThrowCallbackValueNotReturned() 98 } 99 100 type IsPdfOcrAlwaysActiveCallback[T any] struct { 101 Fn func(arg T, this js.Ref, result bool) js.Ref 102 Arg T 103 } 104 105 func (cb *IsPdfOcrAlwaysActiveCallback[T]) Register() js.Func[func(result bool)] { 106 return js.RegisterCallback[func(result bool)]( 107 cb, abi.FuncPCABIInternal(cb.Fn), 108 ) 109 } 110 111 func (cb *IsPdfOcrAlwaysActiveCallback[T]) DispatchCallback( 112 targetPC uintptr, ctx *js.CallbackContext, 113 ) { 114 args := ctx.Args() 115 if len(args) != 1+1 /* js this */ || 116 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 117 js.ThrowInvalidCallbackInvocation() 118 } 119 120 if ctx.Return(cb.Fn( 121 cb.Arg, 122 args[0], 123 124 args[0+1] == js.True, 125 )) { 126 return 127 } 128 129 js.ThrowCallbackValueNotReturned() 130 } 131 132 type OnPdfOcrPrefSetCallbackFunc func(this js.Ref, result bool) js.Ref 133 134 func (fn OnPdfOcrPrefSetCallbackFunc) Register() js.Func[func(result bool)] { 135 return js.RegisterCallback[func(result bool)]( 136 fn, abi.FuncPCABIInternal(fn), 137 ) 138 } 139 140 func (fn OnPdfOcrPrefSetCallbackFunc) DispatchCallback( 141 targetPC uintptr, ctx *js.CallbackContext, 142 ) { 143 args := ctx.Args() 144 if len(args) != 1+1 /* js this */ || 145 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 146 js.ThrowInvalidCallbackInvocation() 147 } 148 149 if ctx.Return(fn( 150 args[0], 151 152 args[0+1] == js.True, 153 )) { 154 return 155 } 156 157 js.ThrowCallbackValueNotReturned() 158 } 159 160 type OnPdfOcrPrefSetCallback[T any] struct { 161 Fn func(arg T, this js.Ref, result bool) js.Ref 162 Arg T 163 } 164 165 func (cb *OnPdfOcrPrefSetCallback[T]) Register() js.Func[func(result bool)] { 166 return js.RegisterCallback[func(result bool)]( 167 cb, abi.FuncPCABIInternal(cb.Fn), 168 ) 169 } 170 171 func (cb *OnPdfOcrPrefSetCallback[T]) DispatchCallback( 172 targetPC uintptr, ctx *js.CallbackContext, 173 ) { 174 args := ctx.Args() 175 if len(args) != 1+1 /* js this */ || 176 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 177 js.ThrowInvalidCallbackInvocation() 178 } 179 180 if ctx.Return(cb.Fn( 181 cb.Arg, 182 args[0], 183 184 args[0+1] == js.True, 185 )) { 186 return 187 } 188 189 js.ThrowCallbackValueNotReturned() 190 } 191 192 // HasFuncIsAllowedLocalFileAccess returns true if the function "WEBEXT.pdfViewerPrivate.isAllowedLocalFileAccess" exists. 193 func HasFuncIsAllowedLocalFileAccess() bool { 194 return js.True == bindings.HasFuncIsAllowedLocalFileAccess() 195 } 196 197 // FuncIsAllowedLocalFileAccess returns the function "WEBEXT.pdfViewerPrivate.isAllowedLocalFileAccess". 198 func FuncIsAllowedLocalFileAccess() (fn js.Func[func(url js.String) js.Promise[js.Boolean]]) { 199 bindings.FuncIsAllowedLocalFileAccess( 200 js.Pointer(&fn), 201 ) 202 return 203 } 204 205 // IsAllowedLocalFileAccess calls the function "WEBEXT.pdfViewerPrivate.isAllowedLocalFileAccess" directly. 206 func IsAllowedLocalFileAccess(url js.String) (ret js.Promise[js.Boolean]) { 207 bindings.CallIsAllowedLocalFileAccess( 208 js.Pointer(&ret), 209 url.Ref(), 210 ) 211 212 return 213 } 214 215 // TryIsAllowedLocalFileAccess calls the function "WEBEXT.pdfViewerPrivate.isAllowedLocalFileAccess" 216 // in a try/catch block and returns (_, err, ok = false) when it went through 217 // the catch clause. 218 func TryIsAllowedLocalFileAccess(url js.String) (ret js.Promise[js.Boolean], exception js.Any, ok bool) { 219 ok = js.True == bindings.TryIsAllowedLocalFileAccess( 220 js.Pointer(&ret), js.Pointer(&exception), 221 url.Ref(), 222 ) 223 224 return 225 } 226 227 // HasFuncIsPdfOcrAlwaysActive returns true if the function "WEBEXT.pdfViewerPrivate.isPdfOcrAlwaysActive" exists. 228 func HasFuncIsPdfOcrAlwaysActive() bool { 229 return js.True == bindings.HasFuncIsPdfOcrAlwaysActive() 230 } 231 232 // FuncIsPdfOcrAlwaysActive returns the function "WEBEXT.pdfViewerPrivate.isPdfOcrAlwaysActive". 233 func FuncIsPdfOcrAlwaysActive() (fn js.Func[func() js.Promise[js.Boolean]]) { 234 bindings.FuncIsPdfOcrAlwaysActive( 235 js.Pointer(&fn), 236 ) 237 return 238 } 239 240 // IsPdfOcrAlwaysActive calls the function "WEBEXT.pdfViewerPrivate.isPdfOcrAlwaysActive" directly. 241 func IsPdfOcrAlwaysActive() (ret js.Promise[js.Boolean]) { 242 bindings.CallIsPdfOcrAlwaysActive( 243 js.Pointer(&ret), 244 ) 245 246 return 247 } 248 249 // TryIsPdfOcrAlwaysActive calls the function "WEBEXT.pdfViewerPrivate.isPdfOcrAlwaysActive" 250 // in a try/catch block and returns (_, err, ok = false) when it went through 251 // the catch clause. 252 func TryIsPdfOcrAlwaysActive() (ret js.Promise[js.Boolean], exception js.Any, ok bool) { 253 ok = js.True == bindings.TryIsPdfOcrAlwaysActive( 254 js.Pointer(&ret), js.Pointer(&exception), 255 ) 256 257 return 258 } 259 260 type OnPdfOcrPrefChangedEventCallbackFunc func(this js.Ref, value bool) js.Ref 261 262 func (fn OnPdfOcrPrefChangedEventCallbackFunc) Register() js.Func[func(value bool)] { 263 return js.RegisterCallback[func(value bool)]( 264 fn, abi.FuncPCABIInternal(fn), 265 ) 266 } 267 268 func (fn OnPdfOcrPrefChangedEventCallbackFunc) DispatchCallback( 269 targetPC uintptr, ctx *js.CallbackContext, 270 ) { 271 args := ctx.Args() 272 if len(args) != 1+1 /* js this */ || 273 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 274 js.ThrowInvalidCallbackInvocation() 275 } 276 277 if ctx.Return(fn( 278 args[0], 279 280 args[0+1] == js.True, 281 )) { 282 return 283 } 284 285 js.ThrowCallbackValueNotReturned() 286 } 287 288 type OnPdfOcrPrefChangedEventCallback[T any] struct { 289 Fn func(arg T, this js.Ref, value bool) js.Ref 290 Arg T 291 } 292 293 func (cb *OnPdfOcrPrefChangedEventCallback[T]) Register() js.Func[func(value bool)] { 294 return js.RegisterCallback[func(value bool)]( 295 cb, abi.FuncPCABIInternal(cb.Fn), 296 ) 297 } 298 299 func (cb *OnPdfOcrPrefChangedEventCallback[T]) DispatchCallback( 300 targetPC uintptr, ctx *js.CallbackContext, 301 ) { 302 args := ctx.Args() 303 if len(args) != 1+1 /* js this */ || 304 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 305 js.ThrowInvalidCallbackInvocation() 306 } 307 308 if ctx.Return(cb.Fn( 309 cb.Arg, 310 args[0], 311 312 args[0+1] == js.True, 313 )) { 314 return 315 } 316 317 js.ThrowCallbackValueNotReturned() 318 } 319 320 // HasFuncOnPdfOcrPrefChanged returns true if the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.addListener" exists. 321 func HasFuncOnPdfOcrPrefChanged() bool { 322 return js.True == bindings.HasFuncOnPdfOcrPrefChanged() 323 } 324 325 // FuncOnPdfOcrPrefChanged returns the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.addListener". 326 func FuncOnPdfOcrPrefChanged() (fn js.Func[func(callback js.Func[func(value bool)])]) { 327 bindings.FuncOnPdfOcrPrefChanged( 328 js.Pointer(&fn), 329 ) 330 return 331 } 332 333 // OnPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.addListener" directly. 334 func OnPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret js.Void) { 335 bindings.CallOnPdfOcrPrefChanged( 336 js.Pointer(&ret), 337 callback.Ref(), 338 ) 339 340 return 341 } 342 343 // TryOnPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.addListener" 344 // in a try/catch block and returns (_, err, ok = false) when it went through 345 // the catch clause. 346 func TryOnPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret js.Void, exception js.Any, ok bool) { 347 ok = js.True == bindings.TryOnPdfOcrPrefChanged( 348 js.Pointer(&ret), js.Pointer(&exception), 349 callback.Ref(), 350 ) 351 352 return 353 } 354 355 // HasFuncOffPdfOcrPrefChanged returns true if the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.removeListener" exists. 356 func HasFuncOffPdfOcrPrefChanged() bool { 357 return js.True == bindings.HasFuncOffPdfOcrPrefChanged() 358 } 359 360 // FuncOffPdfOcrPrefChanged returns the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.removeListener". 361 func FuncOffPdfOcrPrefChanged() (fn js.Func[func(callback js.Func[func(value bool)])]) { 362 bindings.FuncOffPdfOcrPrefChanged( 363 js.Pointer(&fn), 364 ) 365 return 366 } 367 368 // OffPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.removeListener" directly. 369 func OffPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret js.Void) { 370 bindings.CallOffPdfOcrPrefChanged( 371 js.Pointer(&ret), 372 callback.Ref(), 373 ) 374 375 return 376 } 377 378 // TryOffPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.removeListener" 379 // in a try/catch block and returns (_, err, ok = false) when it went through 380 // the catch clause. 381 func TryOffPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret js.Void, exception js.Any, ok bool) { 382 ok = js.True == bindings.TryOffPdfOcrPrefChanged( 383 js.Pointer(&ret), js.Pointer(&exception), 384 callback.Ref(), 385 ) 386 387 return 388 } 389 390 // HasFuncHasOnPdfOcrPrefChanged returns true if the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.hasListener" exists. 391 func HasFuncHasOnPdfOcrPrefChanged() bool { 392 return js.True == bindings.HasFuncHasOnPdfOcrPrefChanged() 393 } 394 395 // FuncHasOnPdfOcrPrefChanged returns the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.hasListener". 396 func FuncHasOnPdfOcrPrefChanged() (fn js.Func[func(callback js.Func[func(value bool)]) bool]) { 397 bindings.FuncHasOnPdfOcrPrefChanged( 398 js.Pointer(&fn), 399 ) 400 return 401 } 402 403 // HasOnPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.hasListener" directly. 404 func HasOnPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret bool) { 405 bindings.CallHasOnPdfOcrPrefChanged( 406 js.Pointer(&ret), 407 callback.Ref(), 408 ) 409 410 return 411 } 412 413 // TryHasOnPdfOcrPrefChanged calls the function "WEBEXT.pdfViewerPrivate.onPdfOcrPrefChanged.hasListener" 414 // in a try/catch block and returns (_, err, ok = false) when it went through 415 // the catch clause. 416 func TryHasOnPdfOcrPrefChanged(callback js.Func[func(value bool)]) (ret bool, exception js.Any, ok bool) { 417 ok = js.True == bindings.TryHasOnPdfOcrPrefChanged( 418 js.Pointer(&ret), js.Pointer(&exception), 419 callback.Ref(), 420 ) 421 422 return 423 } 424 425 // HasFuncSetPdfOcrPref returns true if the function "WEBEXT.pdfViewerPrivate.setPdfOcrPref" exists. 426 func HasFuncSetPdfOcrPref() bool { 427 return js.True == bindings.HasFuncSetPdfOcrPref() 428 } 429 430 // FuncSetPdfOcrPref returns the function "WEBEXT.pdfViewerPrivate.setPdfOcrPref". 431 func FuncSetPdfOcrPref() (fn js.Func[func(value bool) js.Promise[js.Boolean]]) { 432 bindings.FuncSetPdfOcrPref( 433 js.Pointer(&fn), 434 ) 435 return 436 } 437 438 // SetPdfOcrPref calls the function "WEBEXT.pdfViewerPrivate.setPdfOcrPref" directly. 439 func SetPdfOcrPref(value bool) (ret js.Promise[js.Boolean]) { 440 bindings.CallSetPdfOcrPref( 441 js.Pointer(&ret), 442 js.Bool(bool(value)), 443 ) 444 445 return 446 } 447 448 // TrySetPdfOcrPref calls the function "WEBEXT.pdfViewerPrivate.setPdfOcrPref" 449 // in a try/catch block and returns (_, err, ok = false) when it went through 450 // the catch clause. 451 func TrySetPdfOcrPref(value bool) (ret js.Promise[js.Boolean], exception js.Any, ok bool) { 452 ok = js.True == bindings.TrySetPdfOcrPref( 453 js.Pointer(&ret), js.Pointer(&exception), 454 js.Bool(bool(value)), 455 ) 456 457 return 458 }