| 1 |
import wasm from "./diplomat-wasm.mjs" |
| 2 |
import * as diplomatRuntime from "./diplomat-runtime.mjs" |
| 3 |
import { ICU4XBidiInfo } from "./ICU4XBidiInfo.mjs" |
| 4 |
import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs" |
| 5 |
import { ICU4XReorderedIndexMap } from "./ICU4XReorderedIndexMap.mjs" |
| 6 |
|
| 7 |
const ICU4XBidi_box_destroy_registry = new FinalizationRegistry(underlying => { |
| 8 |
wasm.ICU4XBidi_destroy(underlying); |
| 9 |
}); |
| 10 |
|
| 11 |
export class ICU4XBidi { |
| 12 |
#lifetimeEdges = []; |
| 13 |
constructor(underlying, owned, edges) { |
| 14 |
this.underlying = underlying; |
| 15 |
this.#lifetimeEdges.push(...edges); |
| 16 |
if (owned) { |
| 17 |
ICU4XBidi_box_destroy_registry.register(this, underlying); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
static create(arg_provider) { |
| 22 |
return (() => { |
| 23 |
const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); |
| 24 |
wasm.ICU4XBidi_create(diplomat_receive_buffer, arg_provider.underlying); |
| 25 |
const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); |
| 26 |
if (is_ok) { |
| 27 |
const ok_value = new ICU4XBidi(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); |
| 28 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 29 |
return ok_value; |
| 30 |
} else { |
| 31 |
const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; |
| 32 |
wasm.diplomat_free(diplomat_receive_buffer, 5, 4); |
| 33 |
throw new diplomatRuntime.FFIError(throw_value); |
| 34 |
} |
| 35 |
})(); |
| 36 |
} |
| 37 |
|
| 38 |
for_text(arg_text, arg_default_level) { |
| 39 |
const buf_arg_text = diplomatRuntime.DiplomatBuf.str8(wasm, arg_text); |
| 40 |
const diplomat_out = (() => { |
| 41 |
const option_ptr = wasm.ICU4XBidi_for_text(this.underlying, buf_arg_text.ptr, buf_arg_text.size, arg_default_level); |
| 42 |
return (option_ptr == 0) ? undefined : new ICU4XBidiInfo(option_ptr, true, [buf_arg_text]); |
| 43 |
})(); |
| 44 |
buf_arg_text.garbageCollect(); |
| 45 |
return diplomat_out; |
| 46 |
} |
| 47 |
|
| 48 |
reorder_visual(arg_levels) { |
| 49 |
const buf_arg_levels = diplomatRuntime.DiplomatBuf.slice(wasm, arg_levels, "u8"); |
| 50 |
const diplomat_out = new ICU4XReorderedIndexMap(wasm.ICU4XBidi_reorder_visual(this.underlying, buf_arg_levels.ptr, buf_arg_levels.size), true, []); |
| 51 |
buf_arg_levels.free(); |
| 52 |
return diplomat_out; |
| 53 |
} |
| 54 |
|
| 55 |
static level_is_rtl(arg_level) { |
| 56 |
return wasm.ICU4XBidi_level_is_rtl(arg_level); |
| 57 |
} |
| 58 |
|
| 59 |
static level_is_ltr(arg_level) { |
| 60 |
return wasm.ICU4XBidi_level_is_ltr(arg_level); |
| 61 |
} |
| 62 |
|
| 63 |
static level_rtl() { |
| 64 |
return wasm.ICU4XBidi_level_rtl(); |
| 65 |
} |
| 66 |
|
| 67 |
static level_ltr() { |
| 68 |
return wasm.ICU4XBidi_level_ltr(); |
| 69 |
} |
| 70 |
} |