AIdentity

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

rust_wasm.js (10325B)


      1 let wasm;
      2 
      3 let cachedUint8ArrayMemory0 = null;
      4 
      5 function getUint8ArrayMemory0() {
      6     if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
      7         cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
      8     }
      9     return cachedUint8ArrayMemory0;
     10 }
     11 
     12 function getArrayU8FromWasm0(ptr, len) {
     13     ptr = ptr >>> 0;
     14     return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
     15 }
     16 
     17 function addToExternrefTable0(obj) {
     18     const idx = wasm.__externref_table_alloc();
     19     wasm.__wbindgen_export_2.set(idx, obj);
     20     return idx;
     21 }
     22 
     23 function handleError(f, args) {
     24     try {
     25         return f.apply(this, args);
     26     } catch (e) {
     27         const idx = addToExternrefTable0(e);
     28         wasm.__wbindgen_exn_store(idx);
     29     }
     30 }
     31 
     32 let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
     33 
     34 cachedTextDecoder.decode();
     35 
     36 const MAX_SAFARI_DECODE_BYTES = 2146435072;
     37 let numBytesDecoded = 0;
     38 function decodeText(ptr, len) {
     39     numBytesDecoded += len;
     40     if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
     41         cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
     42         cachedTextDecoder.decode();
     43         numBytesDecoded = len;
     44     }
     45     return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
     46 }
     47 
     48 function getStringFromWasm0(ptr, len) {
     49     ptr = ptr >>> 0;
     50     return decodeText(ptr, len);
     51 }
     52 
     53 let WASM_VECTOR_LEN = 0;
     54 
     55 function passArray8ToWasm0(arg, malloc) {
     56     const ptr = malloc(arg.length * 1, 1) >>> 0;
     57     getUint8ArrayMemory0().set(arg, ptr / 1);
     58     WASM_VECTOR_LEN = arg.length;
     59     return ptr;
     60 }
     61 
     62 const cachedTextEncoder = new TextEncoder();
     63 
     64 if (!('encodeInto' in cachedTextEncoder)) {
     65     cachedTextEncoder.encodeInto = function (arg, view) {
     66         const buf = cachedTextEncoder.encode(arg);
     67         view.set(buf);
     68         return {
     69             read: arg.length,
     70             written: buf.length
     71         };
     72     }
     73 }
     74 
     75 function passStringToWasm0(arg, malloc, realloc) {
     76 
     77     if (realloc === undefined) {
     78         const buf = cachedTextEncoder.encode(arg);
     79         const ptr = malloc(buf.length, 1) >>> 0;
     80         getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
     81         WASM_VECTOR_LEN = buf.length;
     82         return ptr;
     83     }
     84 
     85     let len = arg.length;
     86     let ptr = malloc(len, 1) >>> 0;
     87 
     88     const mem = getUint8ArrayMemory0();
     89 
     90     let offset = 0;
     91 
     92     for (; offset < len; offset++) {
     93         const code = arg.charCodeAt(offset);
     94         if (code > 0x7F) break;
     95         mem[ptr + offset] = code;
     96     }
     97 
     98     if (offset !== len) {
     99         if (offset !== 0) {
    100             arg = arg.slice(offset);
    101         }
    102         ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
    103         const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
    104         const ret = cachedTextEncoder.encodeInto(arg, view);
    105 
    106         offset += ret.written;
    107         ptr = realloc(ptr, len, offset, 1) >>> 0;
    108     }
    109 
    110     WASM_VECTOR_LEN = offset;
    111     return ptr;
    112 }
    113 
    114 function takeFromExternrefTable0(idx) {
    115     const value = wasm.__wbindgen_export_2.get(idx);
    116     wasm.__externref_table_dealloc(idx);
    117     return value;
    118 }
    119 /**
    120  * @param {Uint8Array} dict_data
    121  * @param {string} input
    122  * @returns {string}
    123  */
    124 export function chat(dict_data, input) {
    125     let deferred4_0;
    126     let deferred4_1;
    127     try {
    128         const ptr0 = passArray8ToWasm0(dict_data, wasm.__wbindgen_malloc);
    129         const len0 = WASM_VECTOR_LEN;
    130         const ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
    131         const len1 = WASM_VECTOR_LEN;
    132         const ret = wasm.chat(ptr0, len0, ptr1, len1);
    133         var ptr3 = ret[0];
    134         var len3 = ret[1];
    135         if (ret[3]) {
    136             ptr3 = 0; len3 = 0;
    137             throw takeFromExternrefTable0(ret[2]);
    138         }
    139         deferred4_0 = ptr3;
    140         deferred4_1 = len3;
    141         return getStringFromWasm0(ptr3, len3);
    142     } finally {
    143         wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
    144     }
    145 }
    146 
    147 /**
    148  *
    149  * * SVGパス上で指定された点に最も近い点を計算します。
    150  *
    151  * @param {string} path_d
    152  * @param {number} x
    153  * @param {number} y
    154  * @param {number} _snapping_distance_viewbox
    155  * @returns {NearestPointResult | undefined}
    156  */
    157 export function find_nearest_point_on_path(path_d, x, y, _snapping_distance_viewbox) {
    158     const ptr0 = passStringToWasm0(path_d, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
    159     const len0 = WASM_VECTOR_LEN;
    160     const ret = wasm.find_nearest_point_on_path(ptr0, len0, x, y, _snapping_distance_viewbox);
    161     return ret === 0 ? undefined : NearestPointResult.__wrap(ret);
    162 }
    163 
    164 export function main_js() {
    165     wasm.main_js();
    166 }
    167 
    168 const NearestPointResultFinalization = (typeof FinalizationRegistry === 'undefined')
    169     ? { register: () => {}, unregister: () => {} }
    170     : new FinalizationRegistry(ptr => wasm.__wbg_nearestpointresult_free(ptr >>> 0, 1));
    171 
    172 export class NearestPointResult {
    173 
    174     static __wrap(ptr) {
    175         ptr = ptr >>> 0;
    176         const obj = Object.create(NearestPointResult.prototype);
    177         obj.__wbg_ptr = ptr;
    178         NearestPointResultFinalization.register(obj, obj.__wbg_ptr, obj);
    179         return obj;
    180     }
    181 
    182     __destroy_into_raw() {
    183         const ptr = this.__wbg_ptr;
    184         this.__wbg_ptr = 0;
    185         NearestPointResultFinalization.unregister(this);
    186         return ptr;
    187     }
    188 
    189     free() {
    190         const ptr = this.__destroy_into_raw();
    191         wasm.__wbg_nearestpointresult_free(ptr, 0);
    192     }
    193     /**
    194      * @returns {number}
    195      */
    196     get x() {
    197         const ret = wasm.__wbg_get_nearestpointresult_x(this.__wbg_ptr);
    198         return ret;
    199     }
    200     /**
    201      * @param {number} arg0
    202      */
    203     set x(arg0) {
    204         wasm.__wbg_set_nearestpointresult_x(this.__wbg_ptr, arg0);
    205     }
    206     /**
    207      * @returns {number}
    208      */
    209     get y() {
    210         const ret = wasm.__wbg_get_nearestpointresult_y(this.__wbg_ptr);
    211         return ret;
    212     }
    213     /**
    214      * @param {number} arg0
    215      */
    216     set y(arg0) {
    217         wasm.__wbg_set_nearestpointresult_y(this.__wbg_ptr, arg0);
    218     }
    219 }
    220 if (Symbol.dispose) NearestPointResult.prototype[Symbol.dispose] = NearestPointResult.prototype.free;
    221 
    222 const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
    223 
    224 async function __wbg_load(module, imports) {
    225     if (typeof Response === 'function' && module instanceof Response) {
    226         if (typeof WebAssembly.instantiateStreaming === 'function') {
    227             try {
    228                 return await WebAssembly.instantiateStreaming(module, imports);
    229 
    230             } catch (e) {
    231                 const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
    232 
    233                 if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
    234                     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);
    235 
    236                 } else {
    237                     throw e;
    238                 }
    239             }
    240         }
    241 
    242         const bytes = await module.arrayBuffer();
    243         return await WebAssembly.instantiate(bytes, imports);
    244 
    245     } else {
    246         const instance = await WebAssembly.instantiate(module, imports);
    247 
    248         if (instance instanceof WebAssembly.Instance) {
    249             return { instance, module };
    250 
    251         } else {
    252             return instance;
    253         }
    254     }
    255 }
    256 
    257 function __wbg_get_imports() {
    258     const imports = {};
    259     imports.wbg = {};
    260     imports.wbg.__wbg_getRandomValues_1c61fac11405ffdc = function() { return handleError(function (arg0, arg1) {
    261         globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
    262     }, arguments) };
    263     imports.wbg.__wbg_new_da9dc54c5db29dfa = function(arg0, arg1) {
    264         const ret = new Error(getStringFromWasm0(arg0, arg1));
    265         return ret;
    266     };
    267     imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
    268         throw new Error(getStringFromWasm0(arg0, arg1));
    269     };
    270     imports.wbg.__wbindgen_init_externref_table = function() {
    271         const table = wasm.__wbindgen_export_2;
    272         const offset = table.grow(4);
    273         table.set(0, undefined);
    274         table.set(offset + 0, undefined);
    275         table.set(offset + 1, null);
    276         table.set(offset + 2, true);
    277         table.set(offset + 3, false);
    278         ;
    279     };
    280 
    281     return imports;
    282 }
    283 
    284 function __wbg_init_memory(imports, memory) {
    285 
    286 }
    287 
    288 function __wbg_finalize_init(instance, module) {
    289     wasm = instance.exports;
    290     __wbg_init.__wbindgen_wasm_module = module;
    291     cachedUint8ArrayMemory0 = null;
    292 
    293 
    294     wasm.__wbindgen_start();
    295     return wasm;
    296 }
    297 
    298 function initSync(module) {
    299     if (wasm !== undefined) return wasm;
    300 
    301 
    302     if (typeof module !== 'undefined') {
    303         if (Object.getPrototypeOf(module) === Object.prototype) {
    304             ({module} = module)
    305         } else {
    306             console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
    307         }
    308     }
    309 
    310     const imports = __wbg_get_imports();
    311 
    312     __wbg_init_memory(imports);
    313 
    314     if (!(module instanceof WebAssembly.Module)) {
    315         module = new WebAssembly.Module(module);
    316     }
    317 
    318     const instance = new WebAssembly.Instance(module, imports);
    319 
    320     return __wbg_finalize_init(instance, module);
    321 }
    322 
    323 async function __wbg_init(module_or_path) {
    324     if (wasm !== undefined) return wasm;
    325 
    326 
    327     if (typeof module_or_path !== 'undefined') {
    328         if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
    329             ({module_or_path} = module_or_path)
    330         } else {
    331             console.warn('using deprecated parameters for the initialization function; pass a single object instead')
    332         }
    333     }
    334 
    335     if (typeof module_or_path === 'undefined') {
    336         module_or_path = new URL('rust_wasm_bg.wasm', import.meta.url);
    337     }
    338     const imports = __wbg_get_imports();
    339 
    340     if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
    341         module_or_path = fetch(module_or_path);
    342     }
    343 
    344     __wbg_init_memory(imports);
    345 
    346     const { instance, module } = await __wbg_load(await module_or_path, imports);
    347 
    348     return __wbg_finalize_init(instance, module);
    349 }
    350 
    351 export { initSync };
    352 export default __wbg_init;