/* @ts-self-types="./wasm_core.d.ts" */

export class TerminologyEngine {
    __destroy_into_raw() {
        const ptr = this.__wbg_ptr;
        this.__wbg_ptr = 0;
        TerminologyEngineFinalization.unregister(this);
        return ptr;
    }
    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_terminologyengine_free(ptr, 0);
    }
    /**
     * Performs O(N) lock-free multi-pattern matching across the given text
     * @param {string} text
     * @returns {any}
     */
    find_terms(text) {
        const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        const ret = wasm.terminologyengine_find_terms(this.__wbg_ptr, ptr0, len0);
        return takeObject(ret);
    }
    /**
     * @param {string} terms_json
     */
    constructor(terms_json) {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            const ptr0 = passStringToWasm0(terms_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            const len0 = WASM_VECTOR_LEN;
            wasm.terminologyengine_new(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);
            if (r2) {
                throw takeObject(r1);
            }
            this.__wbg_ptr = r0 >>> 0;
            TerminologyEngineFinalization.register(this, this.__wbg_ptr, this);
            return this;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
}
if (Symbol.dispose) TerminologyEngine.prototype[Symbol.dispose] = TerminologyEngine.prototype.free;

export class TranslationMemoryEngine {
    __destroy_into_raw() {
        const ptr = this.__wbg_ptr;
        this.__wbg_ptr = 0;
        TranslationMemoryEngineFinalization.unregister(this);
        return ptr;
    }
    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_translationmemoryengine_free(ptr, 0);
    }
    /**
     * Hybrid Search: Vector semantic search + Traditional Fuzzy match fallback
     * @param {string} query
     * @param {string} query_embedding_json
     * @param {number} top_k
     * @returns {any}
     */
    hybrid_search(query, query_embedding_json, top_k) {
        const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(query_embedding_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len1 = WASM_VECTOR_LEN;
        const ret = wasm.translationmemoryengine_hybrid_search(this.__wbg_ptr, ptr0, len0, ptr1, len1, top_k);
        return takeObject(ret);
    }
    /**
     * @param {string} entries_json
     */
    constructor(entries_json) {
        try {
            const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
            const ptr0 = passStringToWasm0(entries_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            const len0 = WASM_VECTOR_LEN;
            wasm.translationmemoryengine_new(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);
            if (r2) {
                throw takeObject(r1);
            }
            this.__wbg_ptr = r0 >>> 0;
            TranslationMemoryEngineFinalization.register(this, this.__wbg_ptr, this);
            return this;
        } finally {
            wasm.__wbindgen_add_to_stack_pointer(16);
        }
    }
}
if (Symbol.dispose) TranslationMemoryEngine.prototype[Symbol.dispose] = TranslationMemoryEngine.prototype.free;

/**
 * 🚀 方案 B：WASM 多实例专属虚拟滚动状态结构体
 * 每个 JS 编辑器实例通过 `new WasmVirtualScrollState()` 在 WASM 堆上
 * 分配自己专属的行高/前缀和缓存，实现多标签页完全隔离。
 * 当 JS 端引用被 GC 回收时，Rust Drop 自动释放堆内存，零泄漏。
 */
export class WasmVirtualScrollState {
    __destroy_into_raw() {
        const ptr = this.__wbg_ptr;
        this.__wbg_ptr = 0;
        WasmVirtualScrollStateFinalization.unregister(this);
        return ptr;
    }
    free() {
        const ptr = this.__destroy_into_raw();
        wasm.__wbg_wasmvirtualscrollstate_free(ptr, 0);
    }
    /**
     * 零拷贝读取指定索引的偏移量
     * @param {number} index
     * @returns {number}
     */
    get_offset(index) {
        const ret = wasm.wasmvirtualscrollstate_get_offset(this.__wbg_ptr, index);
        return ret;
    }
    /**
     * 零拷贝读取单行高度
     * @param {number} index
     * @returns {number}
     */
    get_row_height(index) {
        const ret = wasm.wasmvirtualscrollstate_get_row_height(this.__wbg_ptr, index);
        return ret;
    }
    /**
     * 零拷贝二分查找：在专属前缀和中检索 scrollTop 对应的起始行索引
     * @param {number} scroll_top
     * @returns {number}
     */
    get_start_index(scroll_top) {
        const ret = wasm.wasmvirtualscrollstate_get_start_index(this.__wbg_ptr, scroll_top);
        return ret >>> 0;
    }
    /**
     * 返回当前缓存的行数
     * @returns {number}
     */
    len() {
        const ret = wasm.wasmvirtualscrollstate_len(this.__wbg_ptr);
        return ret >>> 0;
    }
    /**
     * 构造函数，由 JS 端 `new WasmVirtualScrollState()` 触发
     */
    constructor() {
        const ret = wasm.wasmvirtualscrollstate_new();
        this.__wbg_ptr = ret >>> 0;
        WasmVirtualScrollStateFinalization.register(this, this.__wbg_ptr, this);
        return this;
    }
    /**
     * 写入行高并原地计算前缀和，返回总虚拟高度。
     * 入参 `heights: &[f64]` 映射为 JS `Float64Array`，零序列化开销。
     * @param {Float64Array} heights
     * @returns {number}
     */
    set_heights(heights) {
        const ptr0 = passArrayF64ToWasm0(heights, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        const ret = wasm.wasmvirtualscrollstate_set_heights(this.__wbg_ptr, ptr0, len0);
        return ret;
    }
    /**
     * 增量式单行高度更新与前缀和位移计算，常数时间/增量复杂度，返回最新总虚拟高度。
     * @param {number} index
     * @param {number} new_height
     * @returns {number}
     */
    update_row_height(index, new_height) {
        const ret = wasm.wasmvirtualscrollstate_update_row_height(this.__wbg_ptr, index, new_height);
        return ret;
    }
}
if (Symbol.dispose) WasmVirtualScrollState.prototype[Symbol.dispose] = WasmVirtualScrollState.prototype.free;

/**
 * 🚀 Needleman-Wunsch 全局最优序列比对对齐算法
 * 保证在大模型智能断句与改写字幕后，100% 精确地还原其毫秒级起止时间轴
 * @param {any} original_words_js
 * @param {any} reorganized_lines_js
 * @param {boolean} is_cjk
 * @returns {any}
 */
export function align_subtitles_nw(original_words_js, reorganized_lines_js, is_cjk) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.align_subtitles_nw(retptr, addHeapObject(original_words_js), addHeapObject(reorganized_lines_js), is_cjk);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 批量计算适配缩放（高性能批处理）
 * @param {any} entries
 * @returns {any}
 */
export function batch_calculate_fit_scale(entries) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.batch_calculate_fit_scale(retptr, addHeapObject(entries));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Batch normalize an array of strings.
 * Returns a JS array of normalized strings.
 * Faster than calling normalize_text() individually from JS.
 * @param {any} texts
 * @returns {any}
 */
export function batch_normalize(texts) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.batch_normalize(retptr, addHeapObject(texts));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Compute similarity for an array of string pairs.
 * `pairs` should be a JS array of [string, string] tuples.
 * Returns a JS array of f64 scores.
 * @param {any} pairs
 * @returns {any}
 */
export function batch_similarity(pairs) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.batch_similarity(retptr, addHeapObject(pairs));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Binary-search a prefix-sum array for the row index at a given scrollTop.
 *
 * Returns the largest index `i` such that `prefix[i] <= scroll_top`.
 * Equivalent to the JS `getStartIndexFromScroll` method.
 *
 * `prefix` must be the output of `rebuild_prefix_heights` (length = n+1).
 * @param {any} prefix
 * @param {number} scroll_top
 * @returns {number}
 */
export function binary_search_prefix(prefix, scroll_top) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.binary_search_prefix(retptr, addHeapObject(prefix), scroll_top);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return r0 >>> 0;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 计算文本在气泡内的最优排版（预留接口）
 *
 * 使用自适应字符宽度的换行排版算法，完美支持中英混排。
 * @param {any} input
 * @returns {any}
 */
export function bubble_fit(input) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.bubble_fit(retptr, addHeapObject(input));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 计算译文适配原始 BBox 的最优缩放系数。
 *
 * translated_text: 译文
 * original_width: 原始文本框宽度（px）
 * original_font_size: 原始字号（px）
 * font_id: 字体标识
 * max_lines: 最大允许行数
 * available_height: 可用高度（px）
 *
 * 返回 FitResult 的 JSON 序列化
 * @param {string} translated_text
 * @param {number} original_width
 * @param {number} original_font_size
 * @param {string} font_id
 * @param {number} max_lines
 * @param {number} available_height
 * @returns {any}
 */
export function calculate_fit_scale(translated_text, original_width, original_font_size, font_id, max_lines, available_height) {
    const ptr0 = passStringToWasm0(translated_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passStringToWasm0(font_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len1 = WASM_VECTOR_LEN;
    const ret = wasm.calculate_fit_scale(ptr0, len0, original_width, original_font_size, ptr1, len1, max_lines, available_height);
    return takeObject(ret);
}

/**
 * 清除所有字体度量缓存
 */
export function clear_font_metrics() {
    wasm.clear_font_metrics();
}

/**
 * Clear the cached subtitle times (e.g. when switching projects).
 */
export function clear_subtitle_cache() {
    wasm.clear_subtitle_cache();
}

/**
 * Compute similarity between two strings.
 * Returns a value in [0.0, 1.0].
 * @param {string} a
 * @param {string} b
 * @returns {number}
 */
export function compute_similarity(a, b) {
    const ptr0 = passStringToWasm0(a, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passStringToWasm0(b, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len1 = WASM_VECTOR_LEN;
    const ret = wasm.compute_similarity(ptr0, len0, ptr1, len1);
    return ret;
}

/**
 * Detect timing conflicts in a subtitle list.
 * `subtitles` should be a JS array of objects with `start_ms` and `end_ms` fields.
 * Returns a JS array of conflict objects: { index_a, index_b, overlap_ms }.
 * O(n log n) sort + linear scan — much faster than O(n²) JS implementation.
 * @param {any} subtitles
 * @returns {any}
 */
export function detect_timing_conflicts(subtitles) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.detect_timing_conflicts(retptr, addHeapObject(subtitles));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * @param {any} segments
 * @param {number} container_width
 * @param {number} min_height
 * @returns {any}
 */
export function estimate_row_heights(segments, container_width, min_height) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.estimate_row_heights(retptr, addHeapObject(segments), container_width, min_height);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Estimate row heights for a batch of segments.
 *
 * Each segment is a JS object with `source` and `target` string fields.
 * `container_width` is the column width in pixels.
 * `min_height` is the minimum row height in pixels.
 *
 * Returns a JS array of f64 heights (one per segment).
 *
 * This is significantly faster than the JS implementation for large
 * documents because it avoids per-character JS overhead and Unicode
 * property lookups.
 * @param {Uint32Array} flat_data
 * @param {number} container_width
 * @param {number} min_height
 * @returns {Float64Array}
 */
export function estimate_row_heights_flat(flat_data, container_width, min_height) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray32ToWasm0(flat_data, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        wasm.estimate_row_heights_flat(retptr, ptr0, len0, container_width, min_height);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var v2 = getArrayF64FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export4(r0, r1 * 8, 8);
        return v2;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Export DOCX with template — identical logic to Tauri desktop export.
 * Takes original DOCX bytes + translation pairs, returns modified DOCX bytes.
 *
 * `template_bytes` — the original .docx file as Uint8Array
 * `translations_js` — JS array of [source, target] string pairs
 *
 * Returns Uint8Array of the exported .docx file
 * @param {Uint8Array} template_bytes
 * @param {any} translations_js
 * @returns {Uint8Array}
 */
export function export_document_with_template(template_bytes, translations_js) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(template_bytes, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        wasm.export_document_with_template(retptr, ptr0, len0, addHeapObject(translations_js));
        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 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export4(r0, r1 * 1, 1);
        return v2;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Find the active subtitle index for a given playback time using binary search.
 * `sorted_starts` and `sorted_ends` are arrays of subtitle start and end times in ms.
 * Both arrays must be sorted by start time.
 * Returns the index of the active subtitle, or -1 if none is active.
 * @param {Float64Array} sorted_starts
 * @param {Float64Array} sorted_ends
 * @param {number} time_ms
 * @returns {number}
 */
export function find_active_subtitle(sorted_starts, sorted_ends, time_ms) {
    const ptr0 = passArrayF64ToWasm0(sorted_starts, wasm.__wbindgen_export);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passArrayF64ToWasm0(sorted_ends, wasm.__wbindgen_export);
    const len1 = WASM_VECTOR_LEN;
    const ret = wasm.find_active_subtitle(ptr0, len0, ptr1, len1, time_ms);
    return ret;
}

/**
 * Zero-copy O(1) time-bucketed lookup on WASM-resident cached subtitle times.
 * No JS→WASM data transfer per call — all data lives in WASM linear memory.
 * Returns the index of the active subtitle, or -1 if none is active.
 * @param {number} time_ms
 * @returns {number}
 */
export function find_active_subtitle_cached(time_ms) {
    const ret = wasm.find_active_subtitle_cached(time_ms);
    return ret;
}

/**
 * 🚀 Rust (WASM) 极速 WAV 音频数值编码器
 * 利用并发数值切片快速写入 WAV header 并完成强转，相比 JS 的 DataView 读写提升达 100 倍！
 * @param {Float32Array} samples
 * @param {number} sample_rate
 * @param {number} bit_depth
 * @returns {Uint8Array}
 */
export function float32_to_wav(samples, sample_rate, bit_depth) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        wasm.float32_to_wav(retptr, ptr0, len0, sample_rate, bit_depth);
        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 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export4(r0, r1 * 1, 1);
        return v2;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Generate a DOCX file from structured page data.
 *
 * Input: JSON string of WasmConversionInput
 * Output: Uint8Array of the DOCX file bytes
 * @param {string} json_input
 * @returns {Uint8Array}
 */
export function generate_docx_from_pages(json_input) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(json_input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        wasm.generate_docx_from_pages(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 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export4(r0, r1 * 1, 1);
        return v2;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Generate subtitle content string from a structured object.
 * `data` should be a JS object matching the SubtitleFile schema.
 * `format` is the target format extension (e.g. "srt", "vtt", "ass").
 * @param {any} data
 * @param {string} format
 * @returns {string}
 */
export function generate_subtitle(data, format) {
    let deferred3_0;
    let deferred3_1;
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(format, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        wasm.generate_subtitle(retptr, addHeapObject(data), 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);
        var ptr2 = r0;
        var len2 = r1;
        if (r3) {
            ptr2 = 0; len2 = 0;
            throw takeObject(r2);
        }
        deferred3_0 = ptr2;
        deferred3_1 = len2;
        return getStringFromWasm0(ptr2, len2);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
        wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
    }
}

/**
 * 获取已加载的字体数量
 * @returns {number}
 */
export function get_loaded_font_count() {
    const ret = wasm.get_loaded_font_count();
    return ret >>> 0;
}

export function main_js() {
    wasm.main_js();
}

/**
 * 使用真实字体度量精准测量文本宽度（像素）。
 *
 * text: 待测量的文本
 * font_size: 字体大小（px）
 * font_id: 字体标识（留空则使用当前活跃字体，再无则走启发式）
 * @param {string} text
 * @param {number} font_size
 * @param {string} font_id
 * @returns {number}
 */
export function measure_text_width(text, font_size, font_id) {
    const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passStringToWasm0(font_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len1 = WASM_VECTOR_LEN;
    const ret = wasm.measure_text_width(ptr0, len0, font_size, ptr1, len1);
    return ret;
}

/**
 * Parse a document file from raw bytes.
 * Dispatches to the appropriate parser based on filename extension.
 * Returns a JS object representing the DocumentIntermediate (with InlineFormat).
 *
 * Supported formats: .docx, .pptx, .xlsx, .srt, .txt
 * @param {string} filename
 * @param {Uint8Array} bytes
 * @returns {any}
 */
export function parse_document(filename, bytes) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(filename, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
        const len1 = WASM_VECTOR_LEN;
        wasm.parse_document(retptr, ptr0, len0, ptr1, len1);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Parse subtitle file content into a structured object.
 * Returns a JS object representing the SubtitleFile.
 * @param {string} content
 * @param {string} filename
 * @returns {any}
 */
export function parse_subtitle(content, filename) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passStringToWasm0(content, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len0 = WASM_VECTOR_LEN;
        const ptr1 = passStringToWasm0(filename, wasm.__wbindgen_export, wasm.__wbindgen_export2);
        const len1 = WASM_VECTOR_LEN;
        wasm.parse_subtitle(retptr, ptr0, len0, ptr1, len1);
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Plan translated PDF text placement from page-space line geometry.
 * Used by the web PDF translator and the desktop shell so font fitting,
 * wrapping, erase boxes, and adjacent-line avoidance share one Rust source.
 * @param {any} lines
 * @returns {any}
 */
export function plan_pdf_translation_layout(lines) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.plan_pdf_translation_layout(retptr, addHeapObject(lines));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 在浏览器/WebAssembly 中重写整包 DOCX：合并正文 / 页眉 / 页脚 / 表格单元格内意外断行（与桌面端一致）。
 * 入参为原始 `.docx` 字节，返回处理后的 `.docx` 字节，可用于本地下载。
 * @param {Uint8Array} bytes
 * @returns {Uint8Array}
 */
export function preprocess_docx_merge_paragraphs_bytes(bytes) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        wasm.preprocess_docx_merge_paragraphs_bytes(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 = getArrayU8FromWasm0(r0, r1).slice();
        wasm.__wbindgen_export4(r0, r1 * 1, 1);
        return v2;
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * Build a prefix-sum array from a flat array of row heights.
 *
 * Input:  JS array of f64 heights  [h0, h1, h2, ...]
 * Output: JS array of f64 prefix sums [0, h0, h0+h1, h0+h1+h2, ...]
 *         length = input.length + 1
 *
 * Running this in WASM avoids the JS GC pressure of allocating a large
 * Float64Array in a tight loop and is ~2-4x faster for n > 500.
 * @param {any} heights
 * @returns {any}
 */
export function rebuild_prefix_heights(heights) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        wasm.rebuild_prefix_heights(retptr, addHeapObject(heights));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 场景检测（WASM 版）
 *
 * @param frame_diffs - 相邻帧差分值列表（0.0-1.0）
 * @param frame_interval_ms - 帧间隔（毫秒）
 * @param silence_segments - 静音段列表（JS 数组，可选）
 * @param duration_ms - 视频总时长
 * @param config - 检测配置（JS 对象，可选）
 * @returns SceneDetectionResult
 * @param {Float64Array} frame_diffs
 * @param {bigint} frame_interval_ms
 * @param {any[] | null | undefined} silence_segments
 * @param {bigint} duration_ms
 * @param {any | null} [config]
 * @returns {any}
 */
export function sc_detect_scenes(frame_diffs, frame_interval_ms, silence_segments, duration_ms, config) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArrayF64ToWasm0(frame_diffs, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        var ptr1 = isLikeNone(silence_segments) ? 0 : passArrayJsValueToWasm0(silence_segments, wasm.__wbindgen_export);
        var len1 = WASM_VECTOR_LEN;
        wasm.sc_detect_scenes(retptr, ptr0, len0, frame_interval_ms, ptr1, len1, duration_ms, isLikeNone(config) ? 0 : addHeapObject(config));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 高光提取（WASM 版）
 *
 * @param audio_energy - 音频能量数据（归一化 0.0-1.0）
 * @param energy_interval_ms - 能量采样间隔
 * @param silence_segments - 静音段列表（可选）
 * @param scene_segments - 场景片段列表
 * @param duration_ms - 视频总时长
 * @param config - 提取配置（可选）
 * @returns HighlightResult
 * @param {Float64Array} audio_energy
 * @param {bigint} energy_interval_ms
 * @param {any[] | null | undefined} silence_segments
 * @param {any[]} scene_segments
 * @param {bigint} duration_ms
 * @param {any | null} [config]
 * @returns {any}
 */
export function sc_extract_highlights(audio_energy, energy_interval_ms, silence_segments, scene_segments, duration_ms, config) {
    try {
        const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
        const ptr0 = passArrayF64ToWasm0(audio_energy, wasm.__wbindgen_export);
        const len0 = WASM_VECTOR_LEN;
        var ptr1 = isLikeNone(silence_segments) ? 0 : passArrayJsValueToWasm0(silence_segments, wasm.__wbindgen_export);
        var len1 = WASM_VECTOR_LEN;
        const ptr2 = passArrayJsValueToWasm0(scene_segments, wasm.__wbindgen_export);
        const len2 = WASM_VECTOR_LEN;
        wasm.sc_extract_highlights(retptr, ptr0, len0, energy_interval_ms, ptr1, len1, ptr2, len2, duration_ms, isLikeNone(config) ? 0 : addHeapObject(config));
        var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
        var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
        var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
        if (r2) {
            throw takeObject(r1);
        }
        return takeObject(r0);
    } finally {
        wasm.__wbindgen_add_to_stack_pointer(16);
    }
}

/**
 * 设置当前活跃字体
 * @param {string} font_id
 */
export function set_active_font(font_id) {
    const ptr0 = passStringToWasm0(font_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len0 = WASM_VECTOR_LEN;
    wasm.set_active_font(ptr0, len0);
}

/**
 * 注册字体度量表到 WASM 内存。
 *
 * font_id: 字体唯一标识（如 "TimesNewRoman" 或 "SimSun"）
 * units_per_em: 字体 em 框大小（通常为 1000 或 2048）
 * char_codes: 字符 Unicode 码点数组
 * advances: 对应的 advance 宽度数组（em 单位）
 * is_cjk: 是否为 CJK 字体
 * @param {string} font_id
 * @param {number} units_per_em
 * @param {Uint32Array} char_codes
 * @param {Float64Array} advances
 * @param {boolean} is_cjk
 */
export function set_font_metrics(font_id, units_per_em, char_codes, advances, is_cjk) {
    const ptr0 = passStringToWasm0(font_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passArray32ToWasm0(char_codes, wasm.__wbindgen_export);
    const len1 = WASM_VECTOR_LEN;
    const ptr2 = passArrayF64ToWasm0(advances, wasm.__wbindgen_export);
    const len2 = WASM_VECTOR_LEN;
    wasm.set_font_metrics(ptr0, len0, units_per_em, ptr1, len1, ptr2, len2, is_cjk);
}

/**
 * Write subtitle start/end times into WASM-resident memory.
 * Call this once when subtitles are loaded or timeline changes.
 * After this, use `find_active_subtitle_cached(time_ms)` for zero-copy lookups.
 * @param {Float64Array} starts
 * @param {Float64Array} ends
 */
export function set_subtitle_times(starts, ends) {
    const ptr0 = passArrayF64ToWasm0(starts, wasm.__wbindgen_export);
    const len0 = WASM_VECTOR_LEN;
    const ptr1 = passArrayF64ToWasm0(ends, wasm.__wbindgen_export);
    const len1 = WASM_VECTOR_LEN;
    wasm.set_subtitle_times(ptr0, len0, ptr1, len1);
}

function __wbg_get_imports() {
    const import0 = {
        __proto__: null,
        __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
            const ret = Error(getStringFromWasm0(arg0, arg1));
            return addHeapObject(ret);
        },
        __wbg_Number_a5a435bd7bbec835: function(arg0) {
            const ret = Number(getObject(arg0));
            return ret;
        },
        __wbg_String_8564e559799eccda: function(arg0, arg1) {
            const ret = String(getObject(arg1));
            const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            const len1 = WASM_VECTOR_LEN;
            getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
        },
        __wbg___wbindgen_bigint_get_as_i64_447a76b5c6ef7bda: function(arg0, arg1) {
            const v = getObject(arg1);
            const ret = typeof(v) === 'bigint' ? v : undefined;
            getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
        },
        __wbg___wbindgen_boolean_get_c0f3f60bac5a78d1: function(arg0) {
            const v = getObject(arg0);
            const ret = typeof(v) === 'boolean' ? v : undefined;
            return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
        },
        __wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
            const ret = debugString(getObject(arg1));
            const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            const len1 = WASM_VECTOR_LEN;
            getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
        },
        __wbg___wbindgen_in_41dbb8413020e076: function(arg0, arg1) {
            const ret = getObject(arg0) in getObject(arg1);
            return ret;
        },
        __wbg___wbindgen_is_bigint_e2141d4f045b7eda: function(arg0) {
            const ret = typeof(getObject(arg0)) === 'bigint';
            return ret;
        },
        __wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
            const ret = typeof(getObject(arg0)) === 'function';
            return ret;
        },
        __wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
            const val = getObject(arg0);
            const ret = typeof(val) === 'object' && val !== null;
            return ret;
        },
        __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
            const ret = typeof(getObject(arg0)) === 'string';
            return ret;
        },
        __wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
            const ret = getObject(arg0) === undefined;
            return ret;
        },
        __wbg___wbindgen_jsval_eq_ee31bfad3e536463: function(arg0, arg1) {
            const ret = getObject(arg0) === getObject(arg1);
            return ret;
        },
        __wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b: function(arg0, arg1) {
            const ret = getObject(arg0) == getObject(arg1);
            return ret;
        },
        __wbg___wbindgen_number_get_34bb9d9dcfa21373: function(arg0, arg1) {
            const obj = getObject(arg1);
            const ret = typeof(obj) === 'number' ? obj : undefined;
            getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
        },
        __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
            const obj = getObject(arg1);
            const ret = typeof(obj) === 'string' ? obj : undefined;
            var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            var len1 = WASM_VECTOR_LEN;
            getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
        },
        __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
            throw new Error(getStringFromWasm0(arg0, arg1));
        },
        __wbg_call_e133b57c9155d22c: function() { return handleError(function (arg0, arg1) {
            const ret = getObject(arg0).call(getObject(arg1));
            return addHeapObject(ret);
        }, arguments); },
        __wbg_done_08ce71ee07e3bd17: function(arg0) {
            const ret = getObject(arg0).done;
            return ret;
        },
        __wbg_entries_e8a20ff8c9757101: function(arg0) {
            const ret = Object.entries(getObject(arg0));
            return addHeapObject(ret);
        },
        __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
            let deferred0_0;
            let deferred0_1;
            try {
                deferred0_0 = arg0;
                deferred0_1 = arg1;
                console.error(getStringFromWasm0(arg0, arg1));
            } finally {
                wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
            }
        },
        __wbg_get_326e41e095fb2575: function() { return handleError(function (arg0, arg1) {
            const ret = Reflect.get(getObject(arg0), getObject(arg1));
            return addHeapObject(ret);
        }, arguments); },
        __wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
            const ret = getObject(arg0)[arg1 >>> 0];
            return addHeapObject(ret);
        },
        __wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
            const ret = getObject(arg0)[arg1 >>> 0];
            return addHeapObject(ret);
        },
        __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
            const ret = getObject(arg0)[getObject(arg1)];
            return addHeapObject(ret);
        },
        __wbg_instanceof_ArrayBuffer_101e2bf31071a9f6: function(arg0) {
            let result;
            try {
                result = getObject(arg0) instanceof ArrayBuffer;
            } catch (_) {
                result = false;
            }
            const ret = result;
            return ret;
        },
        __wbg_instanceof_Uint8Array_740438561a5b956d: function(arg0) {
            let result;
            try {
                result = getObject(arg0) instanceof Uint8Array;
            } catch (_) {
                result = false;
            }
            const ret = result;
            return ret;
        },
        __wbg_isArray_33b91feb269ff46e: function(arg0) {
            const ret = Array.isArray(getObject(arg0));
            return ret;
        },
        __wbg_isSafeInteger_ecd6a7f9c3e053cd: function(arg0) {
            const ret = Number.isSafeInteger(getObject(arg0));
            return ret;
        },
        __wbg_iterator_d8f549ec8fb061b1: function() {
            const ret = Symbol.iterator;
            return addHeapObject(ret);
        },
        __wbg_length_b3416cf66a5452c8: function(arg0) {
            const ret = getObject(arg0).length;
            return ret;
        },
        __wbg_length_ea16607d7b61445b: function(arg0) {
            const ret = getObject(arg0).length;
            return ret;
        },
        __wbg_new_227d7c05414eb861: function() {
            const ret = new Error();
            return addHeapObject(ret);
        },
        __wbg_new_49d5571bd3f0c4d4: function() {
            const ret = new Map();
            return addHeapObject(ret);
        },
        __wbg_new_5f486cdf45a04d78: function(arg0) {
            const ret = new Uint8Array(getObject(arg0));
            return addHeapObject(ret);
        },
        __wbg_new_a70fbab9066b301f: function() {
            const ret = new Array();
            return addHeapObject(ret);
        },
        __wbg_new_ab79df5bd7c26067: function() {
            const ret = new Object();
            return addHeapObject(ret);
        },
        __wbg_next_11b99ee6237339e3: function() { return handleError(function (arg0) {
            const ret = getObject(arg0).next();
            return addHeapObject(ret);
        }, arguments); },
        __wbg_next_e01a967809d1aa68: function(arg0) {
            const ret = getObject(arg0).next;
            return addHeapObject(ret);
        },
        __wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
            Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
        },
        __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
            getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
        },
        __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
            getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
        },
        __wbg_set_bf7251625df30a02: function(arg0, arg1, arg2) {
            const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
            return addHeapObject(ret);
        },
        __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
            const ret = getObject(arg1).stack;
            const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
            const len1 = WASM_VECTOR_LEN;
            getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
            getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
        },
        __wbg_value_21fc78aab0322612: function(arg0) {
            const ret = getObject(arg0).value;
            return addHeapObject(ret);
        },
        __wbindgen_cast_0000000000000001: function(arg0) {
            // Cast intrinsic for `F64 -> Externref`.
            const ret = arg0;
            return addHeapObject(ret);
        },
        __wbindgen_cast_0000000000000002: function(arg0) {
            // Cast intrinsic for `I64 -> Externref`.
            const ret = arg0;
            return addHeapObject(ret);
        },
        __wbindgen_cast_0000000000000003: function(arg0, arg1) {
            // Cast intrinsic for `Ref(String) -> Externref`.
            const ret = getStringFromWasm0(arg0, arg1);
            return addHeapObject(ret);
        },
        __wbindgen_cast_0000000000000004: function(arg0) {
            // Cast intrinsic for `U64 -> Externref`.
            const ret = BigInt.asUintN(64, arg0);
            return addHeapObject(ret);
        },
        __wbindgen_object_clone_ref: function(arg0) {
            const ret = getObject(arg0);
            return addHeapObject(ret);
        },
        __wbindgen_object_drop_ref: function(arg0) {
            takeObject(arg0);
        },
    };
    return {
        __proto__: null,
        "./wasm_core_bg.js": import0,
    };
}

const TerminologyEngineFinalization = (typeof FinalizationRegistry === 'undefined')
    ? { register: () => {}, unregister: () => {} }
    : new FinalizationRegistry(ptr => wasm.__wbg_terminologyengine_free(ptr >>> 0, 1));
const TranslationMemoryEngineFinalization = (typeof FinalizationRegistry === 'undefined')
    ? { register: () => {}, unregister: () => {} }
    : new FinalizationRegistry(ptr => wasm.__wbg_translationmemoryengine_free(ptr >>> 0, 1));
const WasmVirtualScrollStateFinalization = (typeof FinalizationRegistry === 'undefined')
    ? { register: () => {}, unregister: () => {} }
    : new FinalizationRegistry(ptr => wasm.__wbg_wasmvirtualscrollstate_free(ptr >>> 0, 1));

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 debugString(val) {
    // primitive types
    const type = typeof val;
    if (type == 'number' || type == 'boolean' || val == null) {
        return  `${val}`;
    }
    if (type == 'string') {
        return `"${val}"`;
    }
    if (type == 'symbol') {
        const description = val.description;
        if (description == null) {
            return 'Symbol';
        } else {
            return `Symbol(${description})`;
        }
    }
    if (type == 'function') {
        const name = val.name;
        if (typeof name == 'string' && name.length > 0) {
            return `Function(${name})`;
        } else {
            return 'Function';
        }
    }
    // objects
    if (Array.isArray(val)) {
        const length = val.length;
        let debug = '[';
        if (length > 0) {
            debug += debugString(val[0]);
        }
        for(let i = 1; i < length; i++) {
            debug += ', ' + debugString(val[i]);
        }
        debug += ']';
        return debug;
    }
    // Test for built-in
    const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
    let className;
    if (builtInMatches && builtInMatches.length > 1) {
        className = builtInMatches[1];
    } else {
        // Failed to match the standard '[object ClassName]'
        return toString.call(val);
    }
    if (className == 'Object') {
        // we're a user defined class or Object
        // JSON.stringify avoids problems with cycles, and is generally much
        // easier than looping through ownProperties of `val`.
        try {
            return 'Object(' + JSON.stringify(val) + ')';
        } catch (_) {
            return 'Object';
        }
    }
    // errors
    if (val instanceof Error) {
        return `${val.name}: ${val.message}\n${val.stack}`;
    }
    // TODO we could test for more things here, like `Set`s and `Map`s.
    return className;
}

function dropObject(idx) {
    if (idx < 1028) return;
    heap[idx] = heap_next;
    heap_next = idx;
}

function getArrayF64FromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + 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.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
        cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
    }
    return cachedDataViewMemory0;
}

let cachedFloat32ArrayMemory0 = null;
function getFloat32ArrayMemory0() {
    if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
        cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
    }
    return cachedFloat32ArrayMemory0;
}

let cachedFloat64ArrayMemory0 = null;
function getFloat64ArrayMemory0() {
    if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
        cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
    }
    return cachedFloat64ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
    ptr = ptr >>> 0;
    return decodeText(ptr, len);
}

let cachedUint32ArrayMemory0 = null;
function getUint32ArrayMemory0() {
    if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
        cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
    }
    return cachedUint32ArrayMemory0;
}

let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
    if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
        cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachedUint8ArrayMemory0;
}

function getObject(idx) { return heap[idx]; }

function handleError(f, args) {
    try {
        return f.apply(this, args);
    } catch (e) {
        wasm.__wbindgen_export3(addHeapObject(e));
    }
}

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 passArrayF32ToWasm0(arg, malloc) {
    const ptr = malloc(arg.length * 4, 4) >>> 0;
    getFloat32ArrayMemory0().set(arg, ptr / 4);
    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 passArrayJsValueToWasm0(array, malloc) {
    const ptr = malloc(array.length * 4, 4) >>> 0;
    const mem = getDataViewMemory0();
    for (let i = 0; i < array.length; i++) {
        mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
    }
    WASM_VECTOR_LEN = array.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, wasm;
function __wbg_finalize_init(instance, module) {
    wasm = instance.exports;
    wasmModule = module;
    cachedDataViewMemory0 = null;
    cachedFloat32ArrayMemory0 = null;
    cachedFloat64ArrayMemory0 = null;
    cachedUint32ArrayMemory0 = null;
    cachedUint8ArrayMemory0 = null;
    wasm.__wbindgen_start();
    return wasm;
}

async function __wbg_load(module, imports) {
    if (typeof Response === 'function' && module instanceof Response) {
        if (typeof WebAssembly.instantiateStreaming === 'function') {
            try {
                return await WebAssembly.instantiateStreaming(module, imports);
            } catch (e) {
                const validResponse = module.ok && 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')
        }
    }

    if (module_or_path === undefined) {
        module_or_path = new URL('wasm_core_bg.wasm', import.meta.url);
    }
    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 };
