|
|
|
@ -1,15 +1,26 @@
@@ -1,15 +1,26 @@
|
|
|
|
|
module.exports = (corePath, res) => { |
|
|
|
|
const { simd } = require('wasm-feature-detect'); |
|
|
|
|
const { dependencies } = require('../../../package.json'); |
|
|
|
|
|
|
|
|
|
module.exports = async (corePath, res) => { |
|
|
|
|
if (typeof global.TesseractCore === 'undefined') { |
|
|
|
|
res.progress({ status: 'loading tesseract core', progress: 0 }); |
|
|
|
|
global.importScripts(corePath); |
|
|
|
|
/* |
|
|
|
|
* Depending on whether the browser supports WebAssembly, |
|
|
|
|
* the version of the TesseractCore will be different. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// If the user specifies a core path, we use that
|
|
|
|
|
// Otherwise, we detect the correct core based on SIMD support
|
|
|
|
|
let corePathImport = corePath; |
|
|
|
|
if (!corePathImport) { |
|
|
|
|
const simdSupport = await simd(); |
|
|
|
|
if (simdSupport) { |
|
|
|
|
corePathImport = `https://unpkg.com/tesseract.js-core@v${dependencies['tesseract.js-core'].substring(1)}/tesseract-core.wasm.js`; |
|
|
|
|
} else { |
|
|
|
|
corePathImport = `https://unpkg.com/tesseract.js-core@v${dependencies['tesseract.js-core'].substring(1)}/tesseract-core-simd.wasm.js`; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
global.importScripts(corePathImport); |
|
|
|
|
|
|
|
|
|
if (typeof global.TesseractCoreWASM !== 'undefined' && typeof WebAssembly === 'object') { |
|
|
|
|
global.TesseractCore = global.TesseractCoreWASM; |
|
|
|
|
} else if (typeof global.TesseractCoreASM !== 'undefined') { |
|
|
|
|
global.TesseractCore = global.TesseractCoreASM; |
|
|
|
|
} else { |
|
|
|
|
throw Error('Failed to load TesseractCore'); |
|
|
|
|
} |
|
|
|
|