BidiParagraph.mjs (4622B)
1 // generated by diplomat-tool 2 import { BidiDirection } from "./BidiDirection.mjs" 3 import wasm from "./diplomat-wasm.mjs"; 4 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 5 6 7 /** 8 * Bidi information for a single processed paragraph 9 */ 10 const BidiParagraph_box_destroy_registry = new FinalizationRegistry((ptr) => { 11 wasm.icu4x_BidiParagraph_destroy_mv1(ptr); 12 }); 13 14 export class BidiParagraph { 15 // Internal ptr reference: 16 #ptr = null; 17 18 // Lifetimes are only to keep dependencies alive. 19 // Since JS won't garbage collect until there are no incoming edges. 20 #selfEdge = []; 21 #infoEdge = []; 22 23 #internalConstructor(symbol, ptr, selfEdge, infoEdge) { 24 if (symbol !== diplomatRuntime.internalConstructor) { 25 console.error("BidiParagraph is an Opaque type. You cannot call its constructor."); 26 return; 27 } 28 this.#infoEdge = infoEdge; 29 this.#ptr = ptr; 30 this.#selfEdge = selfEdge; 31 32 // Are we being borrowed? If not, we can register. 33 if (this.#selfEdge.length === 0) { 34 BidiParagraph_box_destroy_registry.register(this, this.#ptr); 35 } 36 37 return this; 38 } 39 get ffiValue() { 40 return this.#ptr; 41 } 42 43 44 /** 45 * Given a paragraph index `n` within the surrounding text, this sets this 46 * object to the paragraph at that index. Returns nothing when out of bounds. 47 * 48 * This is equivalent to calling `paragraph_at()` on `BidiInfo` but doesn't 49 * create a new object 50 */ 51 setParagraphInText(n) { 52 53 const result = wasm.icu4x_BidiParagraph_set_paragraph_in_text_mv1(this.ffiValue, n); 54 55 try { 56 return result; 57 } 58 59 finally { 60 } 61 } 62 63 /** 64 * The primary direction of this paragraph 65 * 66 * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. 67 */ 68 get direction() { 69 70 const result = wasm.icu4x_BidiParagraph_direction_mv1(this.ffiValue); 71 72 try { 73 return new BidiDirection(diplomatRuntime.internalConstructor, result); 74 } 75 76 finally { 77 } 78 } 79 80 /** 81 * The number of bytes in this paragraph 82 * 83 * See the [Rust documentation for `len`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.ParagraphInfo.html#method.len) for more information. 84 */ 85 get size() { 86 87 const result = wasm.icu4x_BidiParagraph_size_mv1(this.ffiValue); 88 89 try { 90 return result; 91 } 92 93 finally { 94 } 95 } 96 97 /** 98 * The start index of this paragraph within the source text 99 */ 100 get rangeStart() { 101 102 const result = wasm.icu4x_BidiParagraph_range_start_mv1(this.ffiValue); 103 104 try { 105 return result; 106 } 107 108 finally { 109 } 110 } 111 112 /** 113 * The end index of this paragraph within the source text 114 */ 115 get rangeEnd() { 116 117 const result = wasm.icu4x_BidiParagraph_range_end_mv1(this.ffiValue); 118 119 try { 120 return result; 121 } 122 123 finally { 124 } 125 } 126 127 /** 128 * Reorder a line based on display order. The ranges are specified relative to the source text and must be contained 129 * within this paragraph's range. 130 * 131 * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. 132 */ 133 reorderLine(rangeStart, rangeEnd) { 134 const write = new diplomatRuntime.DiplomatWriteBuf(wasm); 135 136 137 const result = wasm.icu4x_BidiParagraph_reorder_line_mv1(this.ffiValue, rangeStart, rangeEnd, write.buffer); 138 139 try { 140 return result === 0 ? null : write.readString8(); 141 } 142 143 finally { 144 write.free(); 145 } 146 } 147 148 /** 149 * Get the BIDI level at a particular byte index in this paragraph. 150 * This integer is conceptually a `unicode_bidi::Level`, 151 * and can be further inspected using the static methods on Bidi. 152 * 153 * Returns 0 (equivalent to `Level::ltr()`) on error 154 * 155 * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. 156 */ 157 levelAt(pos) { 158 159 const result = wasm.icu4x_BidiParagraph_level_at_mv1(this.ffiValue, pos); 160 161 try { 162 return result; 163 } 164 165 finally { 166 } 167 } 168 169 constructor(symbol, ptr, selfEdge, infoEdge) { 170 return this.#internalConstructor(...arguments) 171 } 172 }