website/playground/public/formatter.worker.js
/**
 * Creates a formatter from the specified wasm instance.
 * @param wasmInstance - The WebAssembly instance.
 */
Creates a formatter from the specified wasm instance.
@param wasmInstance - The WebAssembly instance.
Creates a formatter from the specified wasm instance . @param wasmInstance - The WebAssembly instance .
function createFromInstance(wasmInstance) {
    var _a = wasmInstance.exports,
        get_plugin_schema_version = _a.get_plugin_schema_version,
        set_file_path = _a.set_file_path,
        set_override_config = _a.set_override_config,
        get_formatted_text = _a.get_formatted_text,
        format = _a.format,
        get_error_text = _a.get_error_text,
        get_plugin_info = _a.get_plugin_info,
        get_resolved_config = _a.get_resolved_config,
        get_config_diagnostics = _a.get_config_diagnostics,
        set_global_config = _a.set_global_config,
        set_plugin_config = _a.set_plugin_config,
        get_license_text = _a.get_license_text,
        get_wasm_memory_buffer = _a.get_wasm_memory_buffer,
        get_wasm_memory_buffer_size = _a.get_wasm_memory_buffer_size,
        add_to_shared_bytes_from_buffer = _a.add_to_shared_bytes_from_buffer,
        set_buffer_with_shared_bytes = _a.set_buffer_with_shared_bytes,
        clear_shared_bytes = _a.clear_shared_bytes,
        reset_config = _a.reset_config;
    var pluginSchemaVersion = get_plugin_schema_version();
    var expectedPluginSchemaVersion = 3;
    if (pluginSchemaVersion !== 2 && pluginSchemaVersion !== expectedPluginSchemaVersion) {
        throw new Error(
            "Not compatible plugin. "
                + ("Expected schema " + expectedPluginSchemaVersion + ", ")
                + ("but plugin had " + pluginSchemaVersion + "."),
        );
    }
    var bufferSize = get_wasm_memory_buffer_size();
    var configSet = false;
    return {
        setConfig: function(globalConfig, pluginConfig) {
            setConfig(globalConfig, pluginConfig);
        },
        getConfigDiagnostics: function() {
            setConfigIfNotSet();
            var length = get_config_diagnostics();
            return JSON.parse(receiveString(length));
        },
        getResolvedConfig: function() {
            setConfigIfNotSet();
            var length = get_resolved_config();
            return JSON.parse(receiveString(length));
        },
        getPluginInfo: function() {
            var length = get_plugin_info();
            return JSON.parse(receiveString(length));
        },
        getLicenseText: function() {
            var length = get_license_text();
            return receiveString(length);
        },
        formatText: function(filePath, fileText, overrideConfig) {
            setConfigIfNotSet();
            if (overrideConfig != null) {
                if (pluginSchemaVersion === 2) {
                    throw new Error("Cannot set the override configuration for this old plugin.");
                }
                sendString(JSON.stringify(overrideConfig));
                set_override_config();
            }
            sendString(filePath);
            set_file_path();
            sendString(fileText);
            var responseCode = format();
            switch (responseCode) {
                case 0: 
                    return fileText;
                case 1: 
                    return receiveString(get_formatted_text());
                case 2: 
                    throw new Error(receiveString(get_error_text()));
                default:
                    throw new Error("Unexpected response code: " + responseCode);
            }
        },
    };
    function setConfigIfNotSet() {
        if (!configSet) {
            setConfig({}, {});
        }
    }
    function setConfig(globalConfig, pluginConfig) {
        if (reset_config != null) {
            reset_config();
        }
        sendString(JSON.stringify(globalConfig));
        set_global_config();
        sendString(JSON.stringify(pluginConfig));
        set_plugin_config();
        configSet = true;
    }
    function sendString(text) {
        var encoder = new TextEncoder();
        var encodedText = encoder.encode(text);
        var length = encodedText.length;
        clear_shared_bytes(length);
        var index = 0;
        while (index < length) {
            var writeCount = Math.min(length - index, bufferSize);
            var wasmBuffer = getWasmBuffer(writeCount);
            for (var i = 0; i < writeCount; i++) {
                wasmBuffer[i] = encodedText[index + i];
            }
            add_to_shared_bytes_from_buffer(writeCount);
            index += writeCount;
        }
    }
    function receiveString(length) {
        var buffer = new Uint8Array(length);
        var index = 0;
        while (index < length) {
            var readCount = Math.min(length - index, bufferSize);
            set_buffer_with_shared_bytes(index, readCount);
            var wasmBuffer = getWasmBuffer(readCount);
            for (var i = 0; i < readCount; i++) {
                buffer[index + i] = wasmBuffer[i];
            }
            index += readCount;
        }
        var decoder = new TextDecoder();
        return decoder.decode(buffer);
    }
    function getWasmBuffer(length) {
        var pointer = get_wasm_memory_buffer();
        return new Uint8Array(wasmInstance.exports.memory.buffer, pointer, length);
    }
}
function createFromInstance ( wasmInstance ) { var _a = wasmInstance . exports , get_plugin_schema_version = _a . get_plugin_schema_version , set_file_path = _a . set_file_path , set_override_config = _a . set_override_config , get_formatted_text = _a . get_formatted_text , format = _a . format , get_error_text = _a . get_error_text , get_plugin_info = _a . get_plugin_info , get_resolved_config = _a . get_resolved_config , get_config_diagnostics = _a . get_config_diagnostics , set_global_config = _a . set_global_config , set_plugin_config = _a . set_plugin_config , get_license_text = _a . get_license_text , get_wasm_memory_buffer = _a . get_wasm_memory_buffer , get_wasm_memory_buffer_size = _a . get_wasm_memory_buffer_size , add_to_shared_bytes_from_buffer = _a . add_to_shared_bytes_from_buffer , set_buffer_with_shared_bytes = _a . set_buffer_with_shared_bytes , clear_shared_bytes = _a . clear_shared_bytes , reset_config = _a . reset_config ; var pluginSchemaVersion = get_plugin_schema_version ( ) ; var expectedPluginSchemaVersion = 3 ; if ( pluginSchemaVersion !== 2 && pluginSchemaVersion !== expectedPluginSchemaVersion ) { throw new Error ( "Not compatible plugin. " + ( "Expected schema " + expectedPluginSchemaVersion + ", " ) + ( "but plugin had " + pluginSchemaVersion + "." ) , ) ; } var bufferSize = get_wasm_memory_buffer_size ( ) ; var configSet = false ; return { setConfig : function ( globalConfig , pluginConfig ) { setConfig ( globalConfig , pluginConfig ) ; } , getConfigDiagnostics : function ( ) { setConfigIfNotSet ( ) ; var length = get_config_diagnostics ( ) ; return JSON . parse ( receiveString ( length ) ) ; } , getResolvedConfig : function ( ) { setConfigIfNotSet ( ) ; var length = get_resolved_config ( ) ; return JSON . parse ( receiveString ( length ) ) ; } , getPluginInfo : function ( ) { var length = get_plugin_info ( ) ; return JSON . parse ( receiveString ( length ) ) ; } , getLicenseText : function ( ) { var length = get_license_text ( ) ; return receiveString ( length ) ; } , formatText : function ( filePath , fileText , overrideConfig ) { setConfigIfNotSet ( ) ; if ( overrideConfig != null ) { if ( pluginSchemaVersion === 2 ) { throw new Error ( "Cannot set the override configuration for this old plugin." ) ; } sendString ( JSON . stringify ( overrideConfig ) ) ; set_override_config ( ) ; } sendString ( filePath ) ; set_file_path ( ) ; sendString ( fileText ) ; var responseCode = format ( ) ; switch ( responseCode ) { case 0 : return fileText ; case 1 : return receiveString ( get_formatted_text ( ) ) ; case 2 : throw new Error ( receiveString ( get_error_text ( ) ) ) ; default : throw new Error ( "Unexpected response code: " + responseCode ) ; } } , } ; function setConfigIfNotSet ( ) { if ( ! configSet ) { setConfig ( { } , { } ) ; } } function setConfig ( globalConfig , pluginConfig ) { if ( reset_config != null ) { reset_config ( ) ; } sendString ( JSON . stringify ( globalConfig ) ) ; set_global_config ( ) ; sendString ( JSON . stringify ( pluginConfig ) ) ; set_plugin_config ( ) ; configSet = true ; } function sendString ( text ) { var encoder = new TextEncoder ( ) ; var encodedText = encoder . encode ( text ) ; var length = encodedText . length ; clear_shared_bytes ( length ) ; var index = 0 ; while ( index < length ) { var writeCount = Math . min ( length - index , bufferSize ) ; var wasmBuffer = getWasmBuffer ( writeCount ) ; for ( var i = 0 ; i < writeCount ; i ++ ) { wasmBuffer [ i ] = encodedText [ index + i ] ; } add_to_shared_bytes_from_buffer ( writeCount ) ; index += writeCount ; } } function receiveString ( length ) { var buffer = new Uint8Array ( length ) ; var index = 0 ; while ( index < length ) { var readCount = Math . min ( length - index , bufferSize ) ; set_buffer_with_shared_bytes ( index , readCount ) ; var wasmBuffer = getWasmBuffer ( readCount ) ; for ( var i = 0 ; i < readCount ; i ++ ) { buffer [ index + i ] = wasmBuffer [ i ] ; } index += readCount ; } var decoder = new TextDecoder ( ) ; return decoder . decode ( buffer ) ; } function getWasmBuffer ( length ) { var pointer = get_wasm_memory_buffer ( ) ; return new Uint8Array ( wasmInstance . exports . memory . buffer , pointer , length ) ; } }
Creates a formatter from the specified wasm instance.
Creates a formatter from the specified wasm instance .
// no change // change // error