@hexze/mctext 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mctext_wasm.d.ts +110 -0
- package/mctext_wasm.js +594 -0
- package/mctext_wasm_bg.wasm +0 -0
- package/package.json +21 -0
package/mctext_wasm.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class FontSystem {
|
|
5
|
+
private constructor();
|
|
6
|
+
free(): void;
|
|
7
|
+
[Symbol.dispose](): void;
|
|
8
|
+
static modern(): FontSystem;
|
|
9
|
+
measure(text: string, size: number): number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class LayoutOptions {
|
|
13
|
+
free(): void;
|
|
14
|
+
[Symbol.dispose](): void;
|
|
15
|
+
withShadow(shadow: boolean): LayoutOptions;
|
|
16
|
+
withMaxWidth(width: number): LayoutOptions;
|
|
17
|
+
constructor(size: number);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class McText {
|
|
21
|
+
free(): void;
|
|
22
|
+
[Symbol.dispose](): void;
|
|
23
|
+
charCount(): number;
|
|
24
|
+
static parseJson(json: string): McText;
|
|
25
|
+
plainText(): string;
|
|
26
|
+
constructor();
|
|
27
|
+
static parse(text: string): McText;
|
|
28
|
+
spans(): any;
|
|
29
|
+
toJson(): string;
|
|
30
|
+
isEmpty(): boolean;
|
|
31
|
+
toLegacy(): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class RenderResult {
|
|
35
|
+
private constructor();
|
|
36
|
+
free(): void;
|
|
37
|
+
[Symbol.dispose](): void;
|
|
38
|
+
data(): Uint8Array;
|
|
39
|
+
width(): number;
|
|
40
|
+
height(): number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function countVisibleChars(text: string): number;
|
|
44
|
+
|
|
45
|
+
export function namedColors(): any;
|
|
46
|
+
|
|
47
|
+
export function render(font_system: FontSystem, text: string, width: number, height: number, options: LayoutOptions): RenderResult;
|
|
48
|
+
|
|
49
|
+
export function stripCodes(text: string): string;
|
|
50
|
+
|
|
51
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
52
|
+
|
|
53
|
+
export interface InitOutput {
|
|
54
|
+
readonly memory: WebAssembly.Memory;
|
|
55
|
+
readonly __wbg_mctext_free: (a: number, b: number) => void;
|
|
56
|
+
readonly countVisibleChars: (a: number, b: number) => number;
|
|
57
|
+
readonly mctext_charCount: (a: number) => number;
|
|
58
|
+
readonly mctext_isEmpty: (a: number) => number;
|
|
59
|
+
readonly mctext_new: () => number;
|
|
60
|
+
readonly mctext_parse: (a: number, b: number) => number;
|
|
61
|
+
readonly mctext_parseJson: (a: number, b: number) => [number, number, number];
|
|
62
|
+
readonly mctext_plainText: (a: number) => [number, number];
|
|
63
|
+
readonly mctext_spans: (a: number) => any;
|
|
64
|
+
readonly mctext_toJson: (a: number) => [number, number];
|
|
65
|
+
readonly mctext_toLegacy: (a: number) => [number, number];
|
|
66
|
+
readonly namedColors: () => any;
|
|
67
|
+
readonly stripCodes: (a: number, b: number) => [number, number];
|
|
68
|
+
readonly __wbg_fontsystem_free: (a: number, b: number) => void;
|
|
69
|
+
readonly __wbg_layoutoptions_free: (a: number, b: number) => void;
|
|
70
|
+
readonly __wbg_renderresult_free: (a: number, b: number) => void;
|
|
71
|
+
readonly fontsystem_measure: (a: number, b: number, c: number, d: number) => number;
|
|
72
|
+
readonly fontsystem_modern: () => number;
|
|
73
|
+
readonly layoutoptions_new: (a: number) => number;
|
|
74
|
+
readonly layoutoptions_withMaxWidth: (a: number, b: number) => number;
|
|
75
|
+
readonly layoutoptions_withShadow: (a: number, b: number) => number;
|
|
76
|
+
readonly render: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
77
|
+
readonly renderresult_data: (a: number) => [number, number];
|
|
78
|
+
readonly renderresult_height: (a: number) => number;
|
|
79
|
+
readonly renderresult_width: (a: number) => number;
|
|
80
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
81
|
+
readonly __externref_table_alloc: () => number;
|
|
82
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
83
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
84
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
85
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
86
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
87
|
+
readonly __wbindgen_start: () => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
94
|
+
* a precompiled `WebAssembly.Module`.
|
|
95
|
+
*
|
|
96
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
97
|
+
*
|
|
98
|
+
* @returns {InitOutput}
|
|
99
|
+
*/
|
|
100
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
104
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
105
|
+
*
|
|
106
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
107
|
+
*
|
|
108
|
+
* @returns {Promise<InitOutput>}
|
|
109
|
+
*/
|
|
110
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/mctext_wasm.js
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function addToExternrefTable0(obj) {
|
|
4
|
+
const idx = wasm.__externref_table_alloc();
|
|
5
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
6
|
+
return idx;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function _assertClass(instance, klass) {
|
|
10
|
+
if (!(instance instanceof klass)) {
|
|
11
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
16
|
+
ptr = ptr >>> 0;
|
|
17
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getStringFromWasm0(ptr, len) {
|
|
21
|
+
ptr = ptr >>> 0;
|
|
22
|
+
return decodeText(ptr, len);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let cachedUint8ArrayMemory0 = null;
|
|
26
|
+
function getUint8ArrayMemory0() {
|
|
27
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
28
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
29
|
+
}
|
|
30
|
+
return cachedUint8ArrayMemory0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function handleError(f, args) {
|
|
34
|
+
try {
|
|
35
|
+
return f.apply(this, args);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
const idx = addToExternrefTable0(e);
|
|
38
|
+
wasm.__wbindgen_exn_store(idx);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
43
|
+
if (realloc === undefined) {
|
|
44
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
45
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
46
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
47
|
+
WASM_VECTOR_LEN = buf.length;
|
|
48
|
+
return ptr;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let len = arg.length;
|
|
52
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
53
|
+
|
|
54
|
+
const mem = getUint8ArrayMemory0();
|
|
55
|
+
|
|
56
|
+
let offset = 0;
|
|
57
|
+
|
|
58
|
+
for (; offset < len; offset++) {
|
|
59
|
+
const code = arg.charCodeAt(offset);
|
|
60
|
+
if (code > 0x7F) break;
|
|
61
|
+
mem[ptr + offset] = code;
|
|
62
|
+
}
|
|
63
|
+
if (offset !== len) {
|
|
64
|
+
if (offset !== 0) {
|
|
65
|
+
arg = arg.slice(offset);
|
|
66
|
+
}
|
|
67
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
68
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
69
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
70
|
+
|
|
71
|
+
offset += ret.written;
|
|
72
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
WASM_VECTOR_LEN = offset;
|
|
76
|
+
return ptr;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function takeFromExternrefTable0(idx) {
|
|
80
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
81
|
+
wasm.__externref_table_dealloc(idx);
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
86
|
+
cachedTextDecoder.decode();
|
|
87
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
88
|
+
let numBytesDecoded = 0;
|
|
89
|
+
function decodeText(ptr, len) {
|
|
90
|
+
numBytesDecoded += len;
|
|
91
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
92
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
93
|
+
cachedTextDecoder.decode();
|
|
94
|
+
numBytesDecoded = len;
|
|
95
|
+
}
|
|
96
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const cachedTextEncoder = new TextEncoder();
|
|
100
|
+
|
|
101
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
102
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
103
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
104
|
+
view.set(buf);
|
|
105
|
+
return {
|
|
106
|
+
read: arg.length,
|
|
107
|
+
written: buf.length
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let WASM_VECTOR_LEN = 0;
|
|
113
|
+
|
|
114
|
+
const FontSystemFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
115
|
+
? { register: () => {}, unregister: () => {} }
|
|
116
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_fontsystem_free(ptr >>> 0, 1));
|
|
117
|
+
|
|
118
|
+
const LayoutOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
119
|
+
? { register: () => {}, unregister: () => {} }
|
|
120
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_layoutoptions_free(ptr >>> 0, 1));
|
|
121
|
+
|
|
122
|
+
const McTextFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
123
|
+
? { register: () => {}, unregister: () => {} }
|
|
124
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mctext_free(ptr >>> 0, 1));
|
|
125
|
+
|
|
126
|
+
const RenderResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
127
|
+
? { register: () => {}, unregister: () => {} }
|
|
128
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_renderresult_free(ptr >>> 0, 1));
|
|
129
|
+
|
|
130
|
+
export class FontSystem {
|
|
131
|
+
static __wrap(ptr) {
|
|
132
|
+
ptr = ptr >>> 0;
|
|
133
|
+
const obj = Object.create(FontSystem.prototype);
|
|
134
|
+
obj.__wbg_ptr = ptr;
|
|
135
|
+
FontSystemFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
136
|
+
return obj;
|
|
137
|
+
}
|
|
138
|
+
__destroy_into_raw() {
|
|
139
|
+
const ptr = this.__wbg_ptr;
|
|
140
|
+
this.__wbg_ptr = 0;
|
|
141
|
+
FontSystemFinalization.unregister(this);
|
|
142
|
+
return ptr;
|
|
143
|
+
}
|
|
144
|
+
free() {
|
|
145
|
+
const ptr = this.__destroy_into_raw();
|
|
146
|
+
wasm.__wbg_fontsystem_free(ptr, 0);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @returns {FontSystem}
|
|
150
|
+
*/
|
|
151
|
+
static modern() {
|
|
152
|
+
const ret = wasm.fontsystem_modern();
|
|
153
|
+
return FontSystem.__wrap(ret);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @param {string} text
|
|
157
|
+
* @param {number} size
|
|
158
|
+
* @returns {number}
|
|
159
|
+
*/
|
|
160
|
+
measure(text, size) {
|
|
161
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
162
|
+
const len0 = WASM_VECTOR_LEN;
|
|
163
|
+
const ret = wasm.fontsystem_measure(this.__wbg_ptr, ptr0, len0, size);
|
|
164
|
+
return ret;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (Symbol.dispose) FontSystem.prototype[Symbol.dispose] = FontSystem.prototype.free;
|
|
168
|
+
|
|
169
|
+
export class LayoutOptions {
|
|
170
|
+
static __wrap(ptr) {
|
|
171
|
+
ptr = ptr >>> 0;
|
|
172
|
+
const obj = Object.create(LayoutOptions.prototype);
|
|
173
|
+
obj.__wbg_ptr = ptr;
|
|
174
|
+
LayoutOptionsFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
175
|
+
return obj;
|
|
176
|
+
}
|
|
177
|
+
__destroy_into_raw() {
|
|
178
|
+
const ptr = this.__wbg_ptr;
|
|
179
|
+
this.__wbg_ptr = 0;
|
|
180
|
+
LayoutOptionsFinalization.unregister(this);
|
|
181
|
+
return ptr;
|
|
182
|
+
}
|
|
183
|
+
free() {
|
|
184
|
+
const ptr = this.__destroy_into_raw();
|
|
185
|
+
wasm.__wbg_layoutoptions_free(ptr, 0);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @param {boolean} shadow
|
|
189
|
+
* @returns {LayoutOptions}
|
|
190
|
+
*/
|
|
191
|
+
withShadow(shadow) {
|
|
192
|
+
const ptr = this.__destroy_into_raw();
|
|
193
|
+
const ret = wasm.layoutoptions_withShadow(ptr, shadow);
|
|
194
|
+
return LayoutOptions.__wrap(ret);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* @param {number} width
|
|
198
|
+
* @returns {LayoutOptions}
|
|
199
|
+
*/
|
|
200
|
+
withMaxWidth(width) {
|
|
201
|
+
const ptr = this.__destroy_into_raw();
|
|
202
|
+
const ret = wasm.layoutoptions_withMaxWidth(ptr, width);
|
|
203
|
+
return LayoutOptions.__wrap(ret);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @param {number} size
|
|
207
|
+
*/
|
|
208
|
+
constructor(size) {
|
|
209
|
+
const ret = wasm.layoutoptions_new(size);
|
|
210
|
+
this.__wbg_ptr = ret >>> 0;
|
|
211
|
+
LayoutOptionsFinalization.register(this, this.__wbg_ptr, this);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (Symbol.dispose) LayoutOptions.prototype[Symbol.dispose] = LayoutOptions.prototype.free;
|
|
216
|
+
|
|
217
|
+
export class McText {
|
|
218
|
+
static __wrap(ptr) {
|
|
219
|
+
ptr = ptr >>> 0;
|
|
220
|
+
const obj = Object.create(McText.prototype);
|
|
221
|
+
obj.__wbg_ptr = ptr;
|
|
222
|
+
McTextFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
223
|
+
return obj;
|
|
224
|
+
}
|
|
225
|
+
__destroy_into_raw() {
|
|
226
|
+
const ptr = this.__wbg_ptr;
|
|
227
|
+
this.__wbg_ptr = 0;
|
|
228
|
+
McTextFinalization.unregister(this);
|
|
229
|
+
return ptr;
|
|
230
|
+
}
|
|
231
|
+
free() {
|
|
232
|
+
const ptr = this.__destroy_into_raw();
|
|
233
|
+
wasm.__wbg_mctext_free(ptr, 0);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* @returns {number}
|
|
237
|
+
*/
|
|
238
|
+
charCount() {
|
|
239
|
+
const ret = wasm.mctext_charCount(this.__wbg_ptr);
|
|
240
|
+
return ret >>> 0;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @param {string} json
|
|
244
|
+
* @returns {McText}
|
|
245
|
+
*/
|
|
246
|
+
static parseJson(json) {
|
|
247
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
248
|
+
const len0 = WASM_VECTOR_LEN;
|
|
249
|
+
const ret = wasm.mctext_parseJson(ptr0, len0);
|
|
250
|
+
if (ret[2]) {
|
|
251
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
252
|
+
}
|
|
253
|
+
return McText.__wrap(ret[0]);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* @returns {string}
|
|
257
|
+
*/
|
|
258
|
+
plainText() {
|
|
259
|
+
let deferred1_0;
|
|
260
|
+
let deferred1_1;
|
|
261
|
+
try {
|
|
262
|
+
const ret = wasm.mctext_plainText(this.__wbg_ptr);
|
|
263
|
+
deferred1_0 = ret[0];
|
|
264
|
+
deferred1_1 = ret[1];
|
|
265
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
266
|
+
} finally {
|
|
267
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
constructor() {
|
|
271
|
+
const ret = wasm.mctext_new();
|
|
272
|
+
this.__wbg_ptr = ret >>> 0;
|
|
273
|
+
McTextFinalization.register(this, this.__wbg_ptr, this);
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* @param {string} text
|
|
278
|
+
* @returns {McText}
|
|
279
|
+
*/
|
|
280
|
+
static parse(text) {
|
|
281
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
282
|
+
const len0 = WASM_VECTOR_LEN;
|
|
283
|
+
const ret = wasm.mctext_parse(ptr0, len0);
|
|
284
|
+
return McText.__wrap(ret);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @returns {any}
|
|
288
|
+
*/
|
|
289
|
+
spans() {
|
|
290
|
+
const ret = wasm.mctext_spans(this.__wbg_ptr);
|
|
291
|
+
return ret;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @returns {string}
|
|
295
|
+
*/
|
|
296
|
+
toJson() {
|
|
297
|
+
let deferred1_0;
|
|
298
|
+
let deferred1_1;
|
|
299
|
+
try {
|
|
300
|
+
const ret = wasm.mctext_toJson(this.__wbg_ptr);
|
|
301
|
+
deferred1_0 = ret[0];
|
|
302
|
+
deferred1_1 = ret[1];
|
|
303
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
304
|
+
} finally {
|
|
305
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @returns {boolean}
|
|
310
|
+
*/
|
|
311
|
+
isEmpty() {
|
|
312
|
+
const ret = wasm.mctext_isEmpty(this.__wbg_ptr);
|
|
313
|
+
return ret !== 0;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @returns {string}
|
|
317
|
+
*/
|
|
318
|
+
toLegacy() {
|
|
319
|
+
let deferred1_0;
|
|
320
|
+
let deferred1_1;
|
|
321
|
+
try {
|
|
322
|
+
const ret = wasm.mctext_toLegacy(this.__wbg_ptr);
|
|
323
|
+
deferred1_0 = ret[0];
|
|
324
|
+
deferred1_1 = ret[1];
|
|
325
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
326
|
+
} finally {
|
|
327
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (Symbol.dispose) McText.prototype[Symbol.dispose] = McText.prototype.free;
|
|
332
|
+
|
|
333
|
+
export class RenderResult {
|
|
334
|
+
static __wrap(ptr) {
|
|
335
|
+
ptr = ptr >>> 0;
|
|
336
|
+
const obj = Object.create(RenderResult.prototype);
|
|
337
|
+
obj.__wbg_ptr = ptr;
|
|
338
|
+
RenderResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
339
|
+
return obj;
|
|
340
|
+
}
|
|
341
|
+
__destroy_into_raw() {
|
|
342
|
+
const ptr = this.__wbg_ptr;
|
|
343
|
+
this.__wbg_ptr = 0;
|
|
344
|
+
RenderResultFinalization.unregister(this);
|
|
345
|
+
return ptr;
|
|
346
|
+
}
|
|
347
|
+
free() {
|
|
348
|
+
const ptr = this.__destroy_into_raw();
|
|
349
|
+
wasm.__wbg_renderresult_free(ptr, 0);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @returns {Uint8Array}
|
|
353
|
+
*/
|
|
354
|
+
data() {
|
|
355
|
+
const ret = wasm.renderresult_data(this.__wbg_ptr);
|
|
356
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
357
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
358
|
+
return v1;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* @returns {number}
|
|
362
|
+
*/
|
|
363
|
+
width() {
|
|
364
|
+
const ret = wasm.renderresult_width(this.__wbg_ptr);
|
|
365
|
+
return ret >>> 0;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* @returns {number}
|
|
369
|
+
*/
|
|
370
|
+
height() {
|
|
371
|
+
const ret = wasm.renderresult_height(this.__wbg_ptr);
|
|
372
|
+
return ret >>> 0;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (Symbol.dispose) RenderResult.prototype[Symbol.dispose] = RenderResult.prototype.free;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @param {string} text
|
|
379
|
+
* @returns {number}
|
|
380
|
+
*/
|
|
381
|
+
export function countVisibleChars(text) {
|
|
382
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
383
|
+
const len0 = WASM_VECTOR_LEN;
|
|
384
|
+
const ret = wasm.countVisibleChars(ptr0, len0);
|
|
385
|
+
return ret >>> 0;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @returns {any}
|
|
390
|
+
*/
|
|
391
|
+
export function namedColors() {
|
|
392
|
+
const ret = wasm.namedColors();
|
|
393
|
+
return ret;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* @param {FontSystem} font_system
|
|
398
|
+
* @param {string} text
|
|
399
|
+
* @param {number} width
|
|
400
|
+
* @param {number} height
|
|
401
|
+
* @param {LayoutOptions} options
|
|
402
|
+
* @returns {RenderResult}
|
|
403
|
+
*/
|
|
404
|
+
export function render(font_system, text, width, height, options) {
|
|
405
|
+
_assertClass(font_system, FontSystem);
|
|
406
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
407
|
+
const len0 = WASM_VECTOR_LEN;
|
|
408
|
+
_assertClass(options, LayoutOptions);
|
|
409
|
+
const ret = wasm.render(font_system.__wbg_ptr, ptr0, len0, width, height, options.__wbg_ptr);
|
|
410
|
+
return RenderResult.__wrap(ret);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @param {string} text
|
|
415
|
+
* @returns {string}
|
|
416
|
+
*/
|
|
417
|
+
export function stripCodes(text) {
|
|
418
|
+
let deferred2_0;
|
|
419
|
+
let deferred2_1;
|
|
420
|
+
try {
|
|
421
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
422
|
+
const len0 = WASM_VECTOR_LEN;
|
|
423
|
+
const ret = wasm.stripCodes(ptr0, len0);
|
|
424
|
+
deferred2_0 = ret[0];
|
|
425
|
+
deferred2_1 = ret[1];
|
|
426
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
427
|
+
} finally {
|
|
428
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
433
|
+
|
|
434
|
+
async function __wbg_load(module, imports) {
|
|
435
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
436
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
437
|
+
try {
|
|
438
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
439
|
+
} catch (e) {
|
|
440
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
441
|
+
|
|
442
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
443
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
444
|
+
|
|
445
|
+
} else {
|
|
446
|
+
throw e;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const bytes = await module.arrayBuffer();
|
|
452
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
453
|
+
} else {
|
|
454
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
455
|
+
|
|
456
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
457
|
+
return { instance, module };
|
|
458
|
+
} else {
|
|
459
|
+
return instance;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function __wbg_get_imports() {
|
|
465
|
+
const imports = {};
|
|
466
|
+
imports.wbg = {};
|
|
467
|
+
imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
|
|
468
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
469
|
+
return ret;
|
|
470
|
+
};
|
|
471
|
+
imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
|
|
472
|
+
const ret = typeof(arg0) === 'string';
|
|
473
|
+
return ret;
|
|
474
|
+
};
|
|
475
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
476
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
477
|
+
};
|
|
478
|
+
imports.wbg.__wbg_fromCodePoint_50facac709b76f67 = function() { return handleError(function (arg0) {
|
|
479
|
+
const ret = String.fromCodePoint(arg0 >>> 0);
|
|
480
|
+
return ret;
|
|
481
|
+
}, arguments) };
|
|
482
|
+
imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
|
|
483
|
+
const ret = new Object();
|
|
484
|
+
return ret;
|
|
485
|
+
};
|
|
486
|
+
imports.wbg.__wbg_new_25f239778d6112b9 = function() {
|
|
487
|
+
const ret = new Array();
|
|
488
|
+
return ret;
|
|
489
|
+
};
|
|
490
|
+
imports.wbg.__wbg_new_b546ae120718850e = function() {
|
|
491
|
+
const ret = new Map();
|
|
492
|
+
return ret;
|
|
493
|
+
};
|
|
494
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
495
|
+
arg0[arg1] = arg2;
|
|
496
|
+
};
|
|
497
|
+
imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
|
|
498
|
+
arg0[arg1 >>> 0] = arg2;
|
|
499
|
+
};
|
|
500
|
+
imports.wbg.__wbg_set_efaaf145b9377369 = function(arg0, arg1, arg2) {
|
|
501
|
+
const ret = arg0.set(arg1, arg2);
|
|
502
|
+
return ret;
|
|
503
|
+
};
|
|
504
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
505
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
506
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
507
|
+
return ret;
|
|
508
|
+
};
|
|
509
|
+
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
510
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
511
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
512
|
+
return ret;
|
|
513
|
+
};
|
|
514
|
+
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
515
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
516
|
+
const ret = arg0;
|
|
517
|
+
return ret;
|
|
518
|
+
};
|
|
519
|
+
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
520
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
521
|
+
const ret = arg0;
|
|
522
|
+
return ret;
|
|
523
|
+
};
|
|
524
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
525
|
+
const table = wasm.__wbindgen_externrefs;
|
|
526
|
+
const offset = table.grow(4);
|
|
527
|
+
table.set(0, undefined);
|
|
528
|
+
table.set(offset + 0, undefined);
|
|
529
|
+
table.set(offset + 1, null);
|
|
530
|
+
table.set(offset + 2, true);
|
|
531
|
+
table.set(offset + 3, false);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
return imports;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function __wbg_finalize_init(instance, module) {
|
|
538
|
+
wasm = instance.exports;
|
|
539
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
540
|
+
cachedUint8ArrayMemory0 = null;
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
wasm.__wbindgen_start();
|
|
544
|
+
return wasm;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function initSync(module) {
|
|
548
|
+
if (wasm !== undefined) return wasm;
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
if (typeof module !== 'undefined') {
|
|
552
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
553
|
+
({module} = module)
|
|
554
|
+
} else {
|
|
555
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const imports = __wbg_get_imports();
|
|
560
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
561
|
+
module = new WebAssembly.Module(module);
|
|
562
|
+
}
|
|
563
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
564
|
+
return __wbg_finalize_init(instance, module);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
async function __wbg_init(module_or_path) {
|
|
568
|
+
if (wasm !== undefined) return wasm;
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
if (typeof module_or_path !== 'undefined') {
|
|
572
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
573
|
+
({module_or_path} = module_or_path)
|
|
574
|
+
} else {
|
|
575
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (typeof module_or_path === 'undefined') {
|
|
580
|
+
module_or_path = new URL('mctext_wasm_bg.wasm', import.meta.url);
|
|
581
|
+
}
|
|
582
|
+
const imports = __wbg_get_imports();
|
|
583
|
+
|
|
584
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
585
|
+
module_or_path = fetch(module_or_path);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
589
|
+
|
|
590
|
+
return __wbg_finalize_init(instance, module);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export { initSync };
|
|
594
|
+
export default __wbg_init;
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hexze/mctext",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Minecraft text formatting for JavaScript/WASM",
|
|
5
|
+
"version": "1.0.2",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/hexze/mctext"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"mctext_wasm_bg.wasm",
|
|
13
|
+
"mctext_wasm.js",
|
|
14
|
+
"mctext_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "mctext_wasm.js",
|
|
17
|
+
"types": "mctext_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|