Browse Source

Fix documet is not defined issue

pull/265/head
Jerome Wu 6 years ago
parent
commit
71a9cb9210
  1. 4
      src/browser/index.js
  2. 3
      src/browser/worker.js
  3. 6
      src/common/TesseractWorker.js

4
src/browser/index.js

@ -47,7 +47,7 @@ exports.defaultOptions = {
...defaultOptions, ...defaultOptions,
workerPath: process.env.NODE_ENV === 'development' workerPath: process.env.NODE_ENV === 'development'
? resolveURL(`/dist/worker.dev.js?nocache=${Math.random().toString(36).slice(3)}`) ? resolveURL(`/dist/worker.dev.js?nocache=${Math.random().toString(36).slice(3)}`)
: `https://cdn.jsdelivr.net/gh/naptha/tesseract.js@v${version}/dist/worker.min.js`, : `https://cdn.jsdelivr.net/gh/naptha/tesseract.js@v${version}/dist/worker.min.js`,
/* /*
* If browser doesn't support WebAssembly, * If browser doesn't support WebAssembly,
* load ASM version instead * load ASM version instead
@ -68,7 +68,7 @@ exports.defaultOptions = {
exports.spawnWorker = (instance, { workerPath }) => { exports.spawnWorker = (instance, { workerPath }) => {
let worker; let worker;
if (window.Blob && window.URL) { if (window.Blob && window.URL) {
const blob = new Blob([`importScripts("${resolveURL(workerPath)}");`]); const blob = new Blob([`importScripts("${workerPath}");`]);
worker = new Worker(window.URL.createObjectURL(blob)); worker = new Worker(window.URL.createObjectURL(blob));
} else { } else {
worker = new Worker(workerPath); worker = new Worker(workerPath);

3
src/browser/worker.js

@ -9,7 +9,6 @@
*/ */
const check = require('check-types'); const check = require('check-types');
const resolveURL = require('resolve-url');
const workerUtils = require('../common/workerUtils'); const workerUtils = require('../common/workerUtils');
/* /*
@ -27,7 +26,7 @@ workerUtils.setAdapter({
getCore: (corePath, res) => { getCore: (corePath, res) => {
if (check.undefined(global.TesseractCore)) { if (check.undefined(global.TesseractCore)) {
res.progress({ status: 'loading tesseract core', progress: 0 }); res.progress({ status: 'loading tesseract core', progress: 0 });
global.importScripts(resolveURL(corePath)); global.importScripts(corePath);
/* /*
* Depending on whether the browser supports WebAssembly, * Depending on whether the browser supports WebAssembly,
* the version of the TesseractCore will be different. * the version of the TesseractCore will be different.

6
src/common/TesseractWorker.js

@ -8,6 +8,7 @@
* @author Jerome Wu <jeromewus@gmail.com> * @author Jerome Wu <jeromewus@gmail.com>
*/ */
const check = require('check-types'); const check = require('check-types');
const resolveURL = process.browser ? require('resolve-url') : s => s;
const adapter = require('../node'); const adapter = require('../node');
const circularize = require('./circularize'); const circularize = require('./circularize');
const TesseractJob = require('./TesseractJob'); const TesseractJob = require('./TesseractJob');
@ -50,6 +51,11 @@ class TesseractWorker {
...adapter.defaultOptions, ...adapter.defaultOptions,
...options, ...options,
}; };
['corePath', 'workerPath', 'langPath'].forEach((key) => {
if (check.not.undefined(options[key])) {
this.options = { ...this.options, [key]: resolveURL(options[key]) };
}
});
this._currentJob = null; this._currentJob = null;
this._queue = []; this._queue = [];
} }

Loading…
Cancel
Save