mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-11-30 16:37:18 +01:00
Replace bundled font programs with glyph data. Generate replacement fonts with PDF widths and substitutes for missing XFA fonts. Use a JavaScript fallback when WASM is disabled or fails to load.
598 lines
21 KiB
JavaScript
598 lines
21 KiB
JavaScript
/* THIS FILE IS GENERATED - DO NOT EDIT */
|
|
/**
|
|
* Data files needed for the family and style passed to `generate_font`.
|
|
* @param {number} family
|
|
* @param {boolean} bold
|
|
* @param {boolean} italic
|
|
* @param {number} weight
|
|
* @param {number} stem_v
|
|
* @param {number} italic_angle
|
|
* @returns {string[]}
|
|
*/
|
|
export function font_data_files(family, bold, italic, weight, stem_v, italic_angle) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
wasm.font_data_files(retptr, family, bold, italic, weight, stem_v, italic_angle);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v1 = getArrayJsValueFromWasm0(r0, r1);
|
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
return v1;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generates a TrueType font from the requested glyphs (glyph id i + 1 for
|
|
* request i). Requests after the first 65534 are ignored.
|
|
*
|
|
* - `codepoints`: the codepoints of the texts of all the glyphs, one after
|
|
* the other (a text is usually a single codepoint, but it can be e.g. a
|
|
* ligature "ffi" or a letter followed by combining marks),
|
|
* - `lengths`: the number of codepoints of each glyph,
|
|
* - `widths`: the advance width of each glyph, in 1/1000 em (PDF glyph space
|
|
* units); NaN for the natural width. Can be empty (natural widths).
|
|
* - `char_codes`: the code mapped to each glyph in the cmap, 0xFFFFFFFF for
|
|
* the first codepoint of its text. Can be empty.
|
|
* - `family`: 0 for sans-serif, 1 for serif, 2 for monospace.
|
|
* - `bold`, `italic`: the style.
|
|
* - `weight` (positive values override `bold`, clamped to 1..=1000), `stem_v` (the
|
|
* expected vertical stem width, it has precedence over `weight`),
|
|
* `italic_angle` (degrees, negative for a font leaning to the right, -16.33
|
|
* for any negative angle with the serif family, which has an italic style),
|
|
* `cap_height` (the glyphs are vertically scaled to match it): 0 or NaN
|
|
* when unknown.
|
|
* - `ascent` (optional): the ascent as a fraction of the em (between 0 and
|
|
* 1), the descent being the rest, without line gap (e.g. for a text layer,
|
|
* whose lines are an em high).
|
|
* - `kerning` (optional): the kerning of some pairs of glyphs, as triples
|
|
* (index of the left glyph, index of the right one, adjustment of the
|
|
* advance of the left one in 1/1000 em): at most 10920 pairs, the first
|
|
* ones in the order of the glyphs.
|
|
* @param {Uint32Array} codepoints
|
|
* @param {Uint32Array} lengths
|
|
* @param {Float64Array} widths
|
|
* @param {Uint32Array} char_codes
|
|
* @param {number} family
|
|
* @param {boolean} bold
|
|
* @param {boolean} italic
|
|
* @param {number} weight
|
|
* @param {number} stem_v
|
|
* @param {number} italic_angle
|
|
* @param {number} cap_height
|
|
* @param {number | null} [ascent]
|
|
* @param {Float64Array | null} [kerning]
|
|
* @returns {Uint8Array}
|
|
*/
|
|
export function generate_font(codepoints, lengths, widths, char_codes, family, bold, italic, weight, stem_v, italic_angle, cap_height, ascent, kerning) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passArray32ToWasm0(codepoints, wasm.__wbindgen_malloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ptr1 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
|
|
const len1 = WASM_VECTOR_LEN;
|
|
const ptr2 = passArrayF64ToWasm0(widths, wasm.__wbindgen_malloc);
|
|
const len2 = WASM_VECTOR_LEN;
|
|
const ptr3 = passArray32ToWasm0(char_codes, wasm.__wbindgen_malloc);
|
|
const len3 = WASM_VECTOR_LEN;
|
|
var ptr4 = isLikeNone(kerning) ? 0 : passArrayF64ToWasm0(kerning, wasm.__wbindgen_malloc);
|
|
var len4 = WASM_VECTOR_LEN;
|
|
wasm.generate_font(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, family, bold, italic, weight, stem_v, italic_angle, cap_height, !isLikeNone(ascent), isLikeNone(ascent) ? 0 : ascent, ptr4, len4);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v6 = getArrayU8FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 1, 1);
|
|
return v6;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generates a standard font of PDF (e.g. "Helvetica-Bold", see
|
|
* `StandardFont`) from the requested glyphs (the glyph id of the
|
|
* i-th one is i + 1): the arguments are the ones
|
|
* of `generate_font`, without the style (it's the one of the standard font).
|
|
* @param {Uint32Array} codepoints
|
|
* @param {Uint32Array} lengths
|
|
* @param {Float64Array} widths
|
|
* @param {Uint32Array} char_codes
|
|
* @param {string} name
|
|
* @param {number | null} [ascent]
|
|
* @param {Float64Array | null} [kerning]
|
|
* @returns {Uint8Array}
|
|
*/
|
|
export function generate_standard_font(codepoints, lengths, widths, char_codes, name, ascent, kerning) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passArray32ToWasm0(codepoints, wasm.__wbindgen_malloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ptr1 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
|
|
const len1 = WASM_VECTOR_LEN;
|
|
const ptr2 = passArrayF64ToWasm0(widths, wasm.__wbindgen_malloc);
|
|
const len2 = WASM_VECTOR_LEN;
|
|
const ptr3 = passArray32ToWasm0(char_codes, wasm.__wbindgen_malloc);
|
|
const len3 = WASM_VECTOR_LEN;
|
|
const ptr4 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len4 = WASM_VECTOR_LEN;
|
|
var ptr5 = isLikeNone(kerning) ? 0 : passArrayF64ToWasm0(kerning, wasm.__wbindgen_malloc);
|
|
var len5 = WASM_VECTOR_LEN;
|
|
wasm.generate_standard_font(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, !isLikeNone(ascent), isLikeNone(ascent) ? 0 : ascent, ptr5, len5);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v7 = getArrayU8FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 1, 1);
|
|
return v7;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Whether a named data file is embedded or registered.
|
|
* @param {string} name
|
|
* @returns {boolean}
|
|
*/
|
|
export function has_data(name) {
|
|
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ret = wasm.has_data(ptr0, len0);
|
|
return ret !== 0;
|
|
}
|
|
|
|
/**
|
|
* The indices of the glyphs (same `codepoints` and `lengths` as for
|
|
* `generate_font`) which can't be rendered with a family.
|
|
* @param {Uint32Array} codepoints
|
|
* @param {Uint32Array} lengths
|
|
* @param {number} family
|
|
* @returns {Uint32Array}
|
|
*/
|
|
export function missing_glyphs(codepoints, lengths, family) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passArray32ToWasm0(codepoints, wasm.__wbindgen_malloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ptr1 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
|
|
const len1 = WASM_VECTOR_LEN;
|
|
wasm.missing_glyphs(retptr, ptr0, len0, ptr1, len1, family);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v3 = getArrayU32FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
return v3;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The indices of the glyphs (same `codepoints` and `lengths` as for
|
|
* `generate_font`) which can't be rendered with a standard font.
|
|
* @param {Uint32Array} codepoints
|
|
* @param {Uint32Array} lengths
|
|
* @param {string} name
|
|
* @returns {Uint32Array}
|
|
*/
|
|
export function missing_standard_glyphs(codepoints, lengths, name) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passArray32ToWasm0(codepoints, wasm.__wbindgen_malloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ptr1 = passArray32ToWasm0(lengths, wasm.__wbindgen_malloc);
|
|
const len1 = WASM_VECTOR_LEN;
|
|
const ptr2 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len2 = WASM_VECTOR_LEN;
|
|
wasm.missing_standard_glyphs(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v4 = getArrayU32FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
return v4;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Registers a data file for the module lifetime. Load the files listed by
|
|
* `standard_font_data_files` or `font_data_files` before generating a font.
|
|
* @param {string} name
|
|
* @param {Uint8Array} bytes
|
|
*/
|
|
export function set_data(name, bytes) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
const len1 = WASM_VECTOR_LEN;
|
|
wasm.set_data(retptr, ptr0, len0, ptr1, len1);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
if (r1) {
|
|
throw takeObject(r0);
|
|
}
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The codepoints of the glyph data of a standard font (e.g. to generate a
|
|
* font with all its glyphs).
|
|
* @param {string} name
|
|
* @returns {Uint32Array}
|
|
*/
|
|
export function standard_font_codepoints(name) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
wasm.standard_font_codepoints(retptr, ptr0, len0);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v2 = getArrayU32FromWasm0(r0, r1).slice();
|
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
return v2;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The data files needed by a standard font (see `generate_standard_font`).
|
|
* @param {string} name
|
|
* @returns {string[]}
|
|
*/
|
|
export function standard_font_data_files(name) {
|
|
try {
|
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
const len0 = WASM_VECTOR_LEN;
|
|
wasm.standard_font_data_files(retptr, ptr0, len0);
|
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
if (r3) {
|
|
throw takeObject(r2);
|
|
}
|
|
var v2 = getArrayJsValueFromWasm0(r0, r1);
|
|
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
return v2;
|
|
} finally {
|
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
}
|
|
}
|
|
function __wbg_get_imports() {
|
|
const import0 = {
|
|
__proto__: null,
|
|
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
return addHeapObject(ret);
|
|
},
|
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
return addHeapObject(ret);
|
|
},
|
|
};
|
|
return {
|
|
__proto__: null,
|
|
"./hellbox_bg.js": import0,
|
|
};
|
|
}
|
|
|
|
function addHeapObject(obj) {
|
|
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
const idx = heap_next;
|
|
heap_next = heap[idx];
|
|
|
|
heap[idx] = obj;
|
|
return idx;
|
|
}
|
|
|
|
function dropObject(idx) {
|
|
if (idx < 1028) return;
|
|
heap[idx] = heap_next;
|
|
heap_next = idx;
|
|
}
|
|
|
|
function getArrayJsValueFromWasm0(ptr, len) {
|
|
ptr = ptr >>> 0;
|
|
const mem = getDataViewMemory0();
|
|
const result = [];
|
|
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
result.push(takeObject(mem.getUint32(i, true)));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function getArrayU32FromWasm0(ptr, len) {
|
|
ptr = ptr >>> 0;
|
|
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
}
|
|
|
|
function getArrayU8FromWasm0(ptr, len) {
|
|
ptr = ptr >>> 0;
|
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
}
|
|
|
|
let cachedDataViewMemory0 = null;
|
|
function getDataViewMemory0() {
|
|
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
}
|
|
return cachedDataViewMemory0;
|
|
}
|
|
|
|
let cachedFloat64ArrayMemory0 = null;
|
|
function getFloat64ArrayMemory0() {
|
|
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.buffer !== wasm.memory.buffer) {
|
|
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
}
|
|
return cachedFloat64ArrayMemory0;
|
|
}
|
|
|
|
function getStringFromWasm0(ptr, len) {
|
|
return decodeText(ptr >>> 0, len);
|
|
}
|
|
|
|
let cachedUint32ArrayMemory0 = null;
|
|
function getUint32ArrayMemory0() {
|
|
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.buffer !== wasm.memory.buffer) {
|
|
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
}
|
|
return cachedUint32ArrayMemory0;
|
|
}
|
|
|
|
let cachedUint8ArrayMemory0 = null;
|
|
function getUint8ArrayMemory0() {
|
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
|
|
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
}
|
|
return cachedUint8ArrayMemory0;
|
|
}
|
|
|
|
function getObject(idx) { return heap[idx]; }
|
|
|
|
let heap = new Array(1024).fill(undefined);
|
|
heap.push(undefined, null, true, false);
|
|
|
|
let heap_next = heap.length;
|
|
|
|
function isLikeNone(x) {
|
|
return x === undefined || x === null;
|
|
}
|
|
|
|
function passArray32ToWasm0(arg, malloc) {
|
|
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
WASM_VECTOR_LEN = arg.length;
|
|
return ptr;
|
|
}
|
|
|
|
function passArray8ToWasm0(arg, malloc) {
|
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
WASM_VECTOR_LEN = arg.length;
|
|
return ptr;
|
|
}
|
|
|
|
function passArrayF64ToWasm0(arg, malloc) {
|
|
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
getFloat64ArrayMemory0().set(arg, ptr / 8);
|
|
WASM_VECTOR_LEN = arg.length;
|
|
return ptr;
|
|
}
|
|
|
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
if (realloc === undefined) {
|
|
const buf = cachedTextEncoder.encode(arg);
|
|
const ptr = malloc(buf.length, 1) >>> 0;
|
|
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
WASM_VECTOR_LEN = buf.length;
|
|
return ptr;
|
|
}
|
|
|
|
let len = arg.length;
|
|
let ptr = malloc(len, 1) >>> 0;
|
|
|
|
const mem = getUint8ArrayMemory0();
|
|
|
|
let offset = 0;
|
|
|
|
for (; offset < len; offset++) {
|
|
const code = arg.charCodeAt(offset);
|
|
if (code > 0x7F) break;
|
|
mem[ptr + offset] = code;
|
|
}
|
|
if (offset !== len) {
|
|
if (offset !== 0) {
|
|
arg = arg.slice(offset);
|
|
}
|
|
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
|
|
offset += ret.written;
|
|
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
}
|
|
|
|
WASM_VECTOR_LEN = offset;
|
|
return ptr;
|
|
}
|
|
|
|
function takeObject(idx) {
|
|
const ret = getObject(idx);
|
|
dropObject(idx);
|
|
return ret;
|
|
}
|
|
|
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
cachedTextDecoder.decode();
|
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
let numBytesDecoded = 0;
|
|
function decodeText(ptr, len) {
|
|
numBytesDecoded += len;
|
|
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
cachedTextDecoder.decode();
|
|
numBytesDecoded = len;
|
|
}
|
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
}
|
|
|
|
const cachedTextEncoder = new TextEncoder();
|
|
|
|
if (!('encodeInto' in cachedTextEncoder)) {
|
|
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
const buf = cachedTextEncoder.encode(arg);
|
|
view.set(buf);
|
|
return {
|
|
read: arg.length,
|
|
written: buf.length
|
|
};
|
|
};
|
|
}
|
|
|
|
let WASM_VECTOR_LEN = 0;
|
|
|
|
let wasmModule, wasmInstance, wasm;
|
|
function __wbg_finalize_init(instance, module) {
|
|
wasmInstance = instance;
|
|
wasm = instance.exports;
|
|
wasmModule = module;
|
|
cachedDataViewMemory0 = null;
|
|
cachedFloat64ArrayMemory0 = null;
|
|
cachedUint32ArrayMemory0 = null;
|
|
cachedUint8ArrayMemory0 = null;
|
|
return wasm;
|
|
}
|
|
|
|
async function __wbg_load(module, imports) {
|
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
if (!module.ok) {
|
|
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
}
|
|
|
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
try {
|
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
} catch (e) {
|
|
const validResponse = expectedResponseType(module.type);
|
|
|
|
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
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);
|
|
|
|
} else { throw e; }
|
|
}
|
|
}
|
|
|
|
const bytes = await module.arrayBuffer();
|
|
return await WebAssembly.instantiate(bytes, imports);
|
|
} else {
|
|
const instance = await WebAssembly.instantiate(module, imports);
|
|
|
|
if (instance instanceof WebAssembly.Instance) {
|
|
return { instance, module };
|
|
} else {
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
function expectedResponseType(type) {
|
|
switch (type) {
|
|
case 'basic': case 'cors': case 'default': return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function initSync(module) {
|
|
if (wasm !== undefined) return wasm;
|
|
|
|
|
|
if (module !== undefined) {
|
|
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
({module} = module)
|
|
} else {
|
|
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
}
|
|
}
|
|
|
|
const imports = __wbg_get_imports();
|
|
if (!(module instanceof WebAssembly.Module)) {
|
|
module = new WebAssembly.Module(module);
|
|
}
|
|
const instance = new WebAssembly.Instance(module, imports);
|
|
return __wbg_finalize_init(instance, module);
|
|
}
|
|
|
|
async function __wbg_init(module_or_path) {
|
|
if (wasm !== undefined) return wasm;
|
|
|
|
|
|
if (module_or_path !== undefined) {
|
|
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
({module_or_path} = module_or_path)
|
|
} else {
|
|
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
}
|
|
}
|
|
|
|
|
|
const imports = __wbg_get_imports();
|
|
|
|
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
module_or_path = fetch(module_or_path);
|
|
}
|
|
|
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
|
|
return __wbg_finalize_init(instance, module);
|
|
}
|
|
|
|
export { initSync, __wbg_init as default };
|
|
|
|
/**
|
|
* Initializes the JS fallback using its default export as `instantiate`.
|
|
*/
|
|
function initJs(instantiate) {
|
|
if (wasm !== undefined) return wasm;
|
|
return __wbg_finalize_init({ exports: instantiate(__wbg_get_imports()) }, undefined);
|
|
}
|
|
export { initJs };
|