Pure Javascript OCR for more than 100 Languages 📖🎉🖥
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

2 lines
12 KiB

!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.Tesseract=n():e.Tesseract=n()}(window,function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=2)}([function(e,n,t){var r;!function(o){"use strict";var s,i,u,a,c,f,l,p,h,d,b,y,g;function m(e){return null!=e}function v(e){return"number"==typeof e&&e>d&&e<b}function w(e){return"number"==typeof e&&e%1==0}function j(e,n){return v(e)&&e>n}function _(e,n){return v(e)&&e<n}function k(e,n){return v(e)&&e>=n}function O(e,n){return v(e)&&e<=n}function E(e){return"string"==typeof e}function x(e){return E(e)&&""!==e}function P(e){return"[object Object]"===Object.prototype.toString.call(e)}function S(e,n){try{return e instanceof n}catch(e){return!1}}function q(e,n){var t;for(t in n)if(n.hasOwnProperty(t)){if(!1===e.hasOwnProperty(t)||typeof e[t]!=typeof n[t])return!1;if(P(e[t])&&!1===q(e[t],n[t]))return!1}return!0}function I(e){return y(e)}function T(e){return m(e)&&k(e.length,0)}function A(e){return"function"==typeof e}function J(e,n){var t;for(t=0;t<e.length;t+=1)if(e[t]===n)return n;return!n}function M(e,n){var t,r;for(t in e)if(e.hasOwnProperty(t)){if(P(r=e[t])&&M(r,n)===n)return n;if(r===n)return n}return!n}function N(e,n){return Object.keys(n).forEach(function(t){e[t]=n[t]}),e}function W(e,n){return function(){return function(e,n,t){var r=e.l||e.length,o=n[r],s=n[r+1];return L(e.apply(null,n),x(o)?o:t,A(s)?s:TypeError),n[0]}(e,arguments,n)}}function L(e,n,t){if(e)return e;throw new(t||Error)(n||"Assertion failed")}function B(e){var n=function(){return R(e.apply(null,arguments))};return n.l=e.length,n}function R(e){return!e}function $(e,n,t){var r=function(){var r,o;if(r=arguments[0],"maybe"===e&&f.assigned(r))return!0;if(!n(r))return!1;r=function(e,n){switch(e){case T:return h.call(n);case P:return Object.keys(n).map(function(e){return n[e]});default:return n}}(n,r),o=h.call(arguments,1);try{r.forEach(function(n){if(("maybe"!==e||m(n))&&!t.apply(null,[n].concat(o)))throw 0})}catch(e){return!1}return!0};return r.l=t.length,r}function U(e,n){return z([e,u,n])}function z(e){var n,t,r,o;return n=e.shift(),t=e.pop(),r=e.pop(),o=t||{},Object.keys(r).forEach(function(t){Object.defineProperty(o,t,{configurable:!1,enumerable:!0,writable:!1,value:n.apply(null,e.concat(r[t],i[t]))})}),o}function F(e,n){return z([e,n,null])}function C(e,n){p.forEach(function(t){e[t].of=F(n,u[t].of)})}s={v:"value",n:"number",s:"string",b:"boolean",o:"object",t:"type",a:"array",al:"array-like",i:"iterable",d:"date",f:"function",l:"length"},i={},u={},[{n:"equal",f:function(e,n){return e===n},s:"v"},{n:"undefined",f:function(e){return void 0===e},s:"v"},{n:"null",f:function(e){return null===e},s:"v"},{n:"assigned",f:m,s:"v"},{n:"primitive",f:function(e){var n;switch(e){case null:case void 0:case!1:case!0:return!0}return"string"==(n=typeof e)||"number"===n||g&&"symbol"===n},s:"v"},{n:"includes",f:function(e,n){var t,r,o,s,i;if(!m(e))return!1;if(g&&e[Symbol.iterator]&&A(e.values)){t=e.values();do{if((r=t.next()).value===n)return!0}while(!r.done);return!1}for(o=Object.keys(e),s=o.length,i=0;i<s;++i)if(e[o[i]]===n)return!0;return!1},s:"v"},{n:"zero",f:function(e){return 0===e}},{n:"infinity",f:function(e){return e===d||e===b}},{n:"number",f:v},{n:"integer",f:w},{n:"even",f:function(e){return"number"==typeof e&&e%2==0}},{n:"odd",f:function(e){return w(e)&&e%2!=0}},{n:"greater",f:j},{n:"less",f:_},{n:"between",f:function(e,n,t){if(n<t)return j(e,n)&&e<t;return _(e,n)&&e>t}},{n:"greaterOrEqual",f:k},{n:"lessOrEqual",f:O},{n:"inRange",f:function(e,n,t){if(n<t)return k(e,n)&&e<=t;return O(e,n)&&e>=t}},{n:"positive",f:function(e){return j(e,0)}},{n:"negative",f:function(e){return _(e,0)}},{n:"string",f:E,s:"s"},{n:"emptyString",f:function(e){return""===e},s:"s"},{n:"nonEmptyString",f:x,s:"s"},{n:"contains",f:function(e,n){return E(e)&&-1!==e.indexOf(n)},s:"s"},{n:"match",f:function(e,n){return E(e)&&!!e.match(n)},s:"s"},{n:"boolean",f:function(e){return!1===e||!0===e},s:"b"},{n:"object",f:P,s:"o"},{n:"emptyObject",f:function(e){return P(e)&&0===Object.keys(e).length},s:"o"},{n:"nonEmptyObject",f:function(e){return P(e)&&Object.keys(e).length>0},s:"o"},{n:"instanceStrict",f:S,s:"t"},{n:"instance",f:function(e,n){try{return S(e,n)||e.constructor.name===n.name||Object.prototype.toString.call(e)==="[object "+n.name+"]"}catch(e){return!1}},s:"t"},{n:"like",f:q,s:"t"},{n:"array",f:I,s:"a"},{n:"emptyArray",f:function(e){return I(e)&&0===e.length},s:"a"},{n:"nonEmptyArray",f:function(e){return I(e)&&j(e.length,0)},s:"a"},{n:"arrayLike",f:T,s:"al"},{n:"iterable",f:function(e){if(!g)return T(e);return m(e)&&A(e[Symbol.iterator])},s:"i"},{n:"date",f:function(e){return S(e,Date)&&w(e.getTime())},s:"d"},{n:"function",f:A,s:"f"},{n:"hasLength",f:function(e,n){return m(e)&&e.length===n},s:"l"}].map(function(e){var n=e.n;i[n]="Invalid "+s[e.s||"n"],u[n]=e.f}),a={apply:function(e,n){if(c.array(e),A(n))return e.map(function(e){return n(e)});return c.array(n),c.hasLength(e,n.length),e.map(function(e,t){return n[t](e)})},map:function(e,n){if(c.object(e),A(n))return function(e,n){var t={};return Object.keys(e).forEach(function(r){t[r]=n(e[r])}),t}(e,n);return c.object(n),function e(n,t){var r={};return Object.keys(t).forEach(function(o){var s=t[o];A(s)?f.assigned(n)?r[o]=!!s.m:r[o]=s(n[o]):P(s)&&(r[o]=e(n[o],s))}),r}(e,n)},all:function(e){if(I(e))return J(e,!1);return c.object(e),M(e,!1)},any:function(e){if(I(e))return J(e,!0);return c.object(e),M(e,!0)}},p=["array","arrayLike","iterable","object"],h=Array.prototype.slice,d=Number.NEGATIVE_INFINITY,b=Number.POSITIVE_INFINITY,y=Array.isArray,g="function"==typeof Symbol,a=N(a,u),c=U(W,L),f=U(B,R),l=U(function(e){var n=function(){return!!f.assigned(arguments[0])||e.apply(null,arguments)};return n.l=e.length,n.m=!0,n},function(e){if(!1===m(e))return!0;return e}),c.not=F(W,f),c.maybe=F(W,l),p.forEach(function(e){u[e].of=z([$.bind(null,null),u[e],u,null])}),C(c,W),C(f,B),p.forEach(function(e){l[e].of=z([$.bind(null,"maybe"),u[e],u,null]),c.maybe[e].of=F(W,l[e].of),c.not[e].of=F(W,f[e].of)}),function(o){void 0===(r=function(){return o}.call(n,t,n,e))||(e.exports=r)}(N(a,{assert:c,not:f,maybe:l}))}()},function(e,n,t){const r=t(0),o=t(3),{defaultOptions:s}=t(4),{version:i}=t(5);n.defaultOptions={...s,workerPath:`https://cdn.jsdelivr.net/gh/naptha/tesseract.js@v${i}/dist/worker.min.js`,corePath:`https://cdn.jsdelivr.net/gh/naptha/tesseract.js-core@v2.0.0-beta.5/tesseract-core${"object"==typeof WebAssembly?"":".asm"}.js`},n.spawnWorker=((e,n)=>{let t;if(window.Blob&&window.URL){const e=new Blob([`importScripts("${n.workerPath}");`]);t=new Worker(window.URL.createObjectURL(e))}else t=new Worker(n.workerPath);return t.onmessage=(({data:n})=>{e._recv(n)}),t}),n.terminateWorker=(e=>{e.worker.terminate()}),n.sendPacket=((e,n)=>{(e=>r.string(e)?fetch(o(e)).then(e=>e.arrayBuffer()):r.instance(e,File)?new Promise(n=>{const t=new FileReader;t.onload=(()=>{n(t.result)}),t.readAsArrayBuffer(e)}):Promise.reject())(n.payload.image).then(e=>new Uint8Array(e)).then(t=>{e.worker.postMessage({...n,payload:{...n.payload,image:Array.from(t)}})})})},function(e,n,t){const r=t(0),o=t(1),s=t(6),i=t(7);e.exports={TesseractWorker:class{constructor(e={}){this.worker=null,this.workerOptions=Object.assign({},o.defaultOptions,e),this._currentJob=null,this._queue=[]}recognize(e,n={lang:"eng"}){return this._delay(t=>{t._send("recognize",{image:e,options:r.string(n)?{lang:n||"eng"}:n,workerOptions:this.workerOptions})})}detect(e,n={}){return this._delay(t=>{t._send("detect",{image:e,options:n,workerOptions:this.workerOptions})})}terminate(){this.worker&&o.terminateWorker(this),this.worker=null,this._currentJob=null,this._queue=[]}_delay(e){r.null(this.worker)&&(this.worker=o.spawnWorker(this,this.workerOptions));const n=new i(this);return this._queue.push(()=>{this._queue.shift(),this._currentJob=n,e(n)}),r.null(this._currentJob)&&this._dequeue(),n}_dequeue(){this._currentJob=null,this._queue.length&&this._queue[0]()}_recv(e){this._currentJob.id===e.jobId?this._currentJob._handle({...e,data:"resolve"===e.status&&"recognize"===e.action?s(e.data):e.data}):console.warn(`Job ID ${e.jobId} not known.`)}}}},function(e,n,t){var r,o;void 0===(o="function"==typeof(r=function(){return function(){var e=arguments.length;if(0===e)throw new Error("resolveUrl requires at least one argument; got none.");var n=document.createElement("base");if(n.href=arguments[0],1===e)return n.href;var t=document.getElementsByTagName("head")[0];t.insertBefore(n,t.firstChild);for(var r,o=document.createElement("a"),s=1;s<e;s++)o.href=arguments[s],r=o.href,n.href=r;return t.removeChild(n),r}})?r.call(n,t,n,e):r)||(e.exports=o)},function(e,n){e.exports={defaultOptions:{langPath:"https://tessdata.projectnaptha.com/4.0.0"}}},function(e){e.exports={name:"tesseract.js",version:"1.0.13",description:"Pure Javascript Multilingual OCR",main:"src/index.js",scripts:{start:"node scripts/server.js",build:"webpack --config scripts/webpack.config.prod.js",prepublishOnly:"npm run build",lint:"eslint src"},browser:{"./src/node/index.js":"./src/browser/index.js"},author:"",contributors:["jeromewu"],license:"Apache-2.0",devDependencies:{eslint:"^5.9.0","eslint-config-airbnb":"^17.1.0","eslint-plugin-import":"^2.14.0","eslint-plugin-jsx-a11y":"^6.1.2","eslint-plugin-react":"^7.11.1","expect.js":"^0.3.1",express:"^4.16.4",mocha:"^5.2.0",webpack:"^4.26.0","webpack-cli":"^3.1.2","webpack-dev-middleware":"^3.4.0"},dependencies:{"check-types":"^7.4.0","is-url":"1.2.2","node-fetch":"^1.7.3","resolve-url":"^0.2.1","tesseract.js-core":"^2.0.0-beta.5","tesseract.js-utils":"^1.0.0-beta.2"},repository:{type:"git",url:"https://github.com/naptha/tesseract.js.git"},bugs:{url:"https://github.com/naptha/tesseract.js/issues"},homepage:"https://github.com/naptha/tesseract.js"}},function(e,n){e.exports=(e=>{const n={...e,paragraphs:[],lines:[],words:[],symbols:[]};return n.blocks.forEach(e=>{const t={...e,page:n,lines:[],words:[],symbols:[]};t.paragraphs.forEach(e=>{const r={...e,block:t,page:n,words:[],symbols:[]};r.lines.forEach(e=>{const o={...e,paragraph:r,block:t,page:n,symbols:[]};o.words.forEach(e=>{const s={...e,line:o,paragraph:r,block:t,page:n};s.symbols.forEach(e=>{const i={...e,word:s,line:o,paragraph:r,block:t,page:n};i.line.symbols.push(i),i.paragraph.symbols.push(i),i.block.symbols.push(i),i.page.symbols.push(i)}),s.paragraph.words.push(s),s.block.words.push(s),s.page.words.push(s)}),o.block.lines.push(o),o.page.lines.push(o)}),r.page.paragraphs.push(r)})}),n})},function(e,n,t){const r=t(1);let o=0;e.exports=class{constructor(e){o+=1,this.id=`Job-${o}-${Math.random().toString(16).slice(3,8)}`,this._instance=e,this._resolve=[],this._reject=[],this._progress=[],this._finally=[]}then(e,n){return this._resolve.push?this._resolve.push(e):e(this._resolve),n&&this.catch(n),this}catch(e){return this._reject.push?this._reject.push(e):e(this._reject),this}progress(e){return this._progress.push(e),this}finally(e){return this._finally.push(e),this}_send(e,n){r.sendPacket(this._instance,{jobId:this.id,action:e,payload:n})}_handle(e){const{data:n}=e;let t=!1;"resolve"===e.status?(0===this._resolve.length&&console.log(n),this._resolve.forEach(e=>{const t=e(n);t&&"function"==typeof t.then&&console.warn("TesseractJob instances do not chain like ES6 Promises. To convert it into a real promise, use Promise.resolve.")}),this._resolve=n,this._instance._dequeue(),t=!0):"reject"===e.status?(0===this._reject.length&&console.error(n),this._reject.forEach(e=>e(n)),this._reject=n,this._instance._dequeue(),t=!0):"progress"===e.status?this._progress.forEach(e=>e(n)):console.warn("Message type unknown",e.status),t&&this._finally.forEach(e=>e(n))}}}])});
//# sourceMappingURL=tesseract.min.js.map