From 1a6c9236bca5d16ead8df758679277deb7485467 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Sun, 2 Oct 2016 14:52:54 -0400 Subject: [PATCH] add babelrc, switch to createTesseractWorker --- .babelrc | 8 ++++++++ README.md | 4 ++-- dist/tesseract.js | 2 +- index.html | 2 +- src/browser/index.js | 2 +- webpack.config.dev.js | 2 +- webpack.config.prod.js | 2 +- 7 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e0b8aa9 --- /dev/null +++ b/.babelrc @@ -0,0 +1,8 @@ +{ + "presets": ["es2015","stage-1"], + "env": { + "development": { + "plugins": [] + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index a4e0247..5d7e890 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Tesseract.js is a pure javascript version of the Tesseract OCR Engine that can r Tesseract.js works with a ` ``` ## npm diff --git a/dist/tesseract.js b/dist/tesseract.js index 246fe02..0a76140 100644 --- a/dist/tesseract.js +++ b/dist/tesseract.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Tesseract=t():e.Tesseract=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){function e(e,t){var r=a++;s[r]={};var n={jobId:r,action:e,args:t};return console.log(n),o.postMessage(n),{then:function(e){return s[r].result=e,this},error:function(e){return s[r].error=e,this},progress:function(e){return s[r].progress=e,this}}}function t(e){if(e.getContext)e=e.getContext("2d");else if("IMG"==e.tagName||"VIDEO"==e.tagName){var t=document.createElement("canvas");t.width=e.naturalWidth||e.videoWidth,t.height=e.naturalHeight||e.videoHeight;var r=t.getContext("2d");r.drawImage(e,0,0),e=r}return e.getImageData&&(e=e.getImageData(0,0,e.canvas.width,e.canvas.height)),e}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:location.href+"build/tesseract.worker.js",n=new Blob(["importScripts('"+r+"');"]),o=new Worker(window.URL.createObjectURL(n)),i=!1,a=0,s={};return o.onmessage=function(e){var t=e.data,r=t.jobId,n=t.progress,o=t.error,i=t.result,a=s[r];n&&a.progress&&a.progress(n),o&&a.error&&a.error(o),i&&a.result&&a.result(i)},e("init",{mem:100663296}),{detect:function(r){return e("detect",{image:t(r)})},recognize:function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"eng";return"string"==typeof n?n={lang:n}:n.lang=n.lang||"eng",i||["chi_sim","chi_tra","jpn"].indexOf(n.lang)==-1||(e("init",{mem:167772160}),i=!0),e("recognize",{options:n,image:t(r)})}}}}])}); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.createTesseractWorker=t():e.createTesseractWorker=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t){"use strict";e.exports=function(){function e(e,t){var r=a++;s[r]={};var n={jobId:r,action:e,args:t};return console.log(n),o.postMessage(n),{then:function(e){return s[r].result=e,this},error:function(e){return s[r].error=e,this},progress:function(e){return s[r].progress=e,this}}}function t(e){if(e.getContext)e=e.getContext("2d");else if("IMG"==e.tagName||"VIDEO"==e.tagName){var t=document.createElement("canvas");t.width=e.naturalWidth||e.videoWidth,t.height=e.naturalHeight||e.videoHeight;var r=t.getContext("2d");r.drawImage(e,0,0),e=r}return e.getImageData&&(e=e.getImageData(0,0,e.canvas.width,e.canvas.height)),e}var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:location.href+"build/tesseract.worker.js",n=new Blob(["importScripts('"+r+"');"]),o=new Worker(window.URL.createObjectURL(n)),i=!1,a=0,s={};return o.onmessage=function(e){var t=e.data,r=t.jobId,n=t.progress,o=t.error,i=t.result,a=s[r];n&&a.progress&&a.progress(n),o&&a.error&&a.error(o),i&&a.result&&a.result(i)},e("init",{mem:100663296}),{detect:function(r){return e("detect",{image:t(r)})},recognize:function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"eng";return"string"==typeof n?n={lang:n}:n.lang=n.lang||"eng",i||["chi_sim","chi_tra","jpn"].indexOf(n.lang)==-1||(e("init",{mem:167772160}),i=!0),e("recognize",{options:n,image:t(r)})}}}}])}); \ No newline at end of file diff --git a/index.html b/index.html index 04c4f07..8b44c9a 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@ ctx.font = '30px sans-serif' ctx.fillText('the Cosmic Void', 100, 120) - var tesseract = Tesseract(); + var tesseract = createTesseractWorker(); tesseract.recognize(canvas, { tessedit_char_blacklist: 'e' diff --git a/src/browser/index.js b/src/browser/index.js index 3bad2a0..b6260df 100644 --- a/src/browser/index.js +++ b/src/browser/index.js @@ -1,5 +1,5 @@ //TODO: replace with cdn url -module.exports = function Tesseract(url=location.href+'build/tesseract.worker.js'){ +module.exports = function createTesseractWorker(url=location.href+'build/tesseract.worker.js'){ var blob = new Blob(["importScripts('"+url+"');"]) var worker = new Worker(window.URL.createObjectURL(blob)); diff --git a/webpack.config.dev.js b/webpack.config.dev.js index 25316a0..489b609 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -29,7 +29,7 @@ module.exports = [{ entry: './src/browser/index.js', output: { filename: 'tesseract.js', - library: "Tesseract", + library: "createTesseractWorker", libraryTarget: "umd" }, include: [path.join(__dirname, 'src/browser')] diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 302e5eb..b14240d 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -33,7 +33,7 @@ module.exports = [{ entry: './src/browser/index.js', output: { filename: 'tesseract.js', - library: "Tesseract", + library: "createTesseractWorker", libraryTarget: "umd" }, include: [path.join(__dirname, 'src/browser')]