123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- (function() {
- 'use strict';
- /*
- * Copyright 2017 Sam Thorogood. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- /**
- * @fileoverview Polyfill for TextEncoder and TextDecoder.
- *
- * You probably want `text.min.js`, and not this file directly.
- */
- (function(scope) {
- // fail early
- if (scope['TextEncoder'] && scope['TextDecoder']) {
- return false;
- }
- /**
- * @constructor
- * @param {string=} utfLabel
- */
- function FastTextEncoder(utfLabel = 'utf-8') {
- if (utfLabel !== 'utf-8') {
- throw new RangeError(`Failed to construct 'TextEncoder': The encoding label provided ('${utfLabel}') is invalid.`);
- }
- }
- Object.defineProperty(FastTextEncoder.prototype, 'encoding', { value: 'utf-8' });
- /**
- * @param {string} string
- * @param {{stream: boolean}=} options
- * @return {!Uint8Array}
- */
- FastTextEncoder.prototype.encode = function(string, options = { stream: false }) {
- if (options.stream) {
- throw new Error(`Failed to encode: the 'stream' option is unsupported.`);
- }
- let pos = 0;
- const len = string.length;
- let at = 0; // output position
- let tlen = Math.max(32, len + (len >> 1) + 7); // 1.5x size
- let target = new Uint8Array((tlen >> 3) << 3); // ... but at 8 byte offset
- while (pos < len) {
- let value = string.charCodeAt(pos++);
- if (value >= 0xd800 && value <= 0xdbff) {
- // high surrogate
- if (pos < len) {
- const extra = string.charCodeAt(pos);
- if ((extra & 0xfc00) === 0xdc00) {
- ++pos;
- value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
- }
- }
- if (value >= 0xd800 && value <= 0xdbff) {
- continue; // drop lone surrogate
- }
- }
- // expand the buffer if we couldn't write 4 bytes
- if (at + 4 > target.length) {
- tlen += 8; // minimum extra
- tlen *= 1.0 + (pos / string.length) * 2; // take 2x the remaining
- tlen = (tlen >> 3) << 3; // 8 byte offset
- const update = new Uint8Array(tlen);
- update.set(target);
- target = update;
- }
- if ((value & 0xffffff80) === 0) {
- // 1-byte
- target[at++] = value; // ASCII
- continue;
- } else if ((value & 0xfffff800) === 0) {
- // 2-byte
- target[at++] = ((value >> 6) & 0x1f) | 0xc0;
- } else if ((value & 0xffff0000) === 0) {
- // 3-byte
- target[at++] = ((value >> 12) & 0x0f) | 0xe0;
- target[at++] = ((value >> 6) & 0x3f) | 0x80;
- } else if ((value & 0xffe00000) === 0) {
- // 4-byte
- target[at++] = ((value >> 18) & 0x07) | 0xf0;
- target[at++] = ((value >> 12) & 0x3f) | 0x80;
- target[at++] = ((value >> 6) & 0x3f) | 0x80;
- } else {
- // FIXME: do we care
- continue;
- }
- target[at++] = (value & 0x3f) | 0x80;
- }
- return target.slice(0, at);
- };
- /**
- * @constructor
- * @param {string=} utfLabel
- * @param {{fatal: boolean}=} options
- */
- function FastTextDecoder(utfLabel = 'utf-8', options = { fatal: false }) {
- if (utfLabel !== 'utf-8') {
- throw new RangeError(`Failed to construct 'TextDecoder': The encoding label provided ('${utfLabel}') is invalid.`);
- }
- if (options.fatal) {
- throw new Error(`Failed to construct 'TextDecoder': the 'fatal' option is unsupported.`);
- }
- }
- Object.defineProperty(FastTextDecoder.prototype, 'encoding', { value: 'utf-8' });
- Object.defineProperty(FastTextDecoder.prototype, 'fatal', { value: false });
- Object.defineProperty(FastTextDecoder.prototype, 'ignoreBOM', { value: false });
- /**
- * @param {(!ArrayBuffer|!ArrayBufferView)} buffer
- * @param {{stream: boolean}=} options
- */
- FastTextDecoder.prototype.decode = function(buffer, options = { stream: false }) {
- if (options['stream']) {
- throw new Error(`Failed to decode: the 'stream' option is unsupported.`);
- }
- const bytes = new Uint8Array(buffer);
- let pos = 0;
- const len = bytes.length;
- const out = [];
- while (pos < len) {
- const byte1 = bytes[pos++];
- if (byte1 === 0) {
- break; // NULL
- }
- if ((byte1 & 0x80) === 0) {
- // 1-byte
- out.push(byte1);
- } else if ((byte1 & 0xe0) === 0xc0) {
- // 2-byte
- const byte2 = bytes[pos++] & 0x3f;
- out.push(((byte1 & 0x1f) << 6) | byte2);
- } else if ((byte1 & 0xf0) === 0xe0) {
- const byte2 = bytes[pos++] & 0x3f;
- const byte3 = bytes[pos++] & 0x3f;
- out.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
- } else if ((byte1 & 0xf8) === 0xf0) {
- const byte2 = bytes[pos++] & 0x3f;
- const byte3 = bytes[pos++] & 0x3f;
- const byte4 = bytes[pos++] & 0x3f;
- // this can be > 0xffff, so possibly generate surrogates
- let codepoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
- if (codepoint > 0xffff) {
- // codepoint &= ~0x10000;
- codepoint -= 0x10000;
- out.push(((codepoint >>> 10) & 0x3ff) | 0xd800);
- codepoint = 0xdc00 | (codepoint & 0x3ff);
- }
- out.push(codepoint);
- }
- }
- return String.fromCharCode.apply(null, out);
- };
- scope['TextEncoder'] = FastTextEncoder;
- scope['TextDecoder'] = FastTextDecoder;
- })(typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self);
- (function() {
- const __exports = {};
- let wasm;
- const heap = new Array(32);
- heap.fill(undefined);
- heap.push(undefined, null, true, false);
- let stack_pointer = 32;
- function addBorrowedObject(obj) {
- if (stack_pointer == 1) throw new Error('out of js stack');
- heap[--stack_pointer] = obj;
- return stack_pointer;
- }
- let cachegetUint8Memory = null;
- function getUint8Memory() {
- if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
- cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
- }
- return cachegetUint8Memory;
- }
- function getArrayU8FromWasm(ptr, len) {
- return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
- }
- let cachedGlobalArgumentPtr = null;
- function globalArgumentPtr() {
- if (cachedGlobalArgumentPtr === null) {
- cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
- }
- return cachedGlobalArgumentPtr;
- }
- let cachegetUint32Memory = null;
- function getUint32Memory() {
- if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
- cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
- }
- return cachegetUint32Memory;
- }
- /**
- * @param {any} raw_data
- * @returns {Uint8Array}
- */
- __exports.import_to_xlsx = function(raw_data) {
- const retptr = globalArgumentPtr();
- try {
- wasm.import_to_xlsx(retptr, addBorrowedObject(raw_data));
- const mem = getUint32Memory();
- const rustptr = mem[retptr / 4];
- const rustlen = mem[retptr / 4 + 1];
- const realRet = getArrayU8FromWasm(rustptr, rustlen).slice();
- wasm.__wbindgen_free(rustptr, rustlen * 1);
- return realRet;
- } finally {
- heap[stack_pointer++] = undefined;
- }
- };
- let cachedTextEncoder = new TextEncoder('utf-8');
- let WASM_VECTOR_LEN = 0;
- let passStringToWasm;
- if (typeof cachedTextEncoder.encodeInto === 'function') {
- passStringToWasm = function(arg) {
- let size = arg.length;
- let ptr = wasm.__wbindgen_malloc(size);
- let writeOffset = 0;
- // eslint-disable-next-line no-constant-condition
- while (true) {
- const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size);
- const { read, written } = cachedTextEncoder.encodeInto(arg, view);
- arg = arg.substring(read);
- writeOffset += written;
- if (arg.length === 0) {
- break;
- }
- ptr = wasm.__wbindgen_realloc(ptr, size, size * 2);
- size *= 2;
- }
- WASM_VECTOR_LEN = writeOffset;
- return ptr;
- };
- } else {
- passStringToWasm = function(arg) {
- const buf = cachedTextEncoder.encode(arg);
- const ptr = wasm.__wbindgen_malloc(buf.length);
- getUint8Memory().set(buf, ptr);
- WASM_VECTOR_LEN = buf.length;
- return ptr;
- };
- }
- function getObject(idx) {
- return heap[idx];
- }
- __exports.__wbindgen_json_serialize = function(idx, ptrptr) {
- const ptr = passStringToWasm(JSON.stringify(getObject(idx)));
- getUint32Memory()[ptrptr / 4] = ptr;
- return WASM_VECTOR_LEN;
- };
- let heap_next = heap.length;
- function dropObject(idx) {
- if (idx < 36) return;
- heap[idx] = heap_next;
- heap_next = idx;
- }
- __exports.__wbindgen_object_drop_ref = function(i) {
- dropObject(i);
- };
- // eslint-disable-next-line no-unused-vars
- function init(module_or_path, maybe_memory) {
- let result;
- const imports = { './xlsx_import': __exports };
- if (module_or_path instanceof URL || typeof module_or_path === 'string' || module_or_path instanceof Request) {
- const response = fetch(module_or_path);
- if (typeof WebAssembly.instantiateStreaming === 'function') {
- result = WebAssembly.instantiateStreaming(response, imports).catch(e => {
- console.warn(
- '`WebAssembly.instantiateStreaming` failed. Assuming this is because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n',
- e
- );
- return response.then(r => r.arrayBuffer()).then(bytes => WebAssembly.instantiate(bytes, imports));
- });
- } else {
- result = response.then(r => r.arrayBuffer()).then(bytes => WebAssembly.instantiate(bytes, imports));
- }
- } else {
- result = WebAssembly.instantiate(module_or_path, imports).then(instance => {
- return { instance, module: module_or_path };
- });
- }
- return result.then(({ instance, module }) => {
- wasm = instance.exports;
- init.__wbindgen_wasm_module = module;
- return wasm;
- });
- }
- self.wasm_bindgen = Object.assign(init, __exports);
- })();
- onmessage = function(e) {
- if (e.data.type === 'convert') {
- doConvert(e.data);
- }
- };
- let import_to_xlsx = null;
- function doConvert(config) {
- if (import_to_xlsx) {
- const result = import_to_xlsx(config.data);
- const blob = new Blob([result], {
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,',
- });
- postMessage({
- uid: config.uid || new Date().valueOf(),
- type: 'ready',
- blob,
- });
- } else {
- const path = config.wasmPath || 'https://cdn.dhtmlx.com/libs/json2excel/1.0/lib.wasm';
- // eslint-disable-next-line no-undef
- wasm_bindgen(path)
- .then(() => {
- // eslint-disable-next-line no-undef
- import_to_xlsx = wasm_bindgen.import_to_xlsx;
- doConvert(config);
- })
- .catch(e => console.log(e));
- }
- }
- })();
|