Browse Source

Update index.d.ts

develop
Jerome Wu 5 years ago
parent
commit
369e794afa
  1. 2
      package.json
  2. 92
      src/index.d.ts
  3. 2
      src/index.js

2
package.json

@ -3,7 +3,7 @@
"version": "2.0.0-alpha.16", "version": "2.0.0-alpha.16",
"description": "Pure Javascript Multilingual OCR", "description": "Pure Javascript Multilingual OCR",
"main": "src/index.js", "main": "src/index.js",
"types": "types/index.d.ts", "types": "src/index.d.ts",
"unpkg": "dist/tesseract.min.js", "unpkg": "dist/tesseract.min.js",
"jsdelivr": "dist/tesseract.min.js", "jsdelivr": "dist/tesseract.min.js",
"scripts": { "scripts": {

92
types/index.d.ts → src/index.d.ts vendored

@ -1,9 +1,39 @@
declare namespace Tesseract { declare namespace Tesseract {
class TesseractWorker { function createScheduler(): Scheduler
recognize(image: ImageLike, lang: string, options?: Partial<RecognizeOptions>): TesseractJob; function createWorker(options?: Partial<WorkerOptions>): Worker
detect(image: ImageLike): TesseractJob; function setLogging(logging: boolean): void
function recognize(image: ImageLike, langs: string, options?: Partial<WorkerOptions>): Promise<RecognizeResult>
function detect(image: ImageLike, langs: string, options?: Partial<WorkerOptions>)
interface Scheduler {
addWorker(worker: Worker): void
addJob(action: string, ...args: any[]): Promise<ConfigResult | RecognizeResult | DetectResult>
terminate(): Promise<any>
getQueueLen(): number
getNumWorkers(): number
} }
interface RecognizeOptions {
interface Worker {
load(jobId?: string): Promise<ConfigResult>
loadLanguage(langs: string, jobId?: string): Promise<ConfigResult>
initialize(langs: string, params?: Partial<WorkerParams>, jobId?: string): Promise<ConfigResult>
recognize(image: ImageLike, options?: Partial<RecognizeOptions>, jobId?: string): Promise<RecognizeResult>
detect(image: ImageLike, jobId?: string): Promise<DetectResult>
terminate(jobId?: string): Promise<ConfigResult>
}
interface WorkerOptions {
corePath: string
langPath: string
cachePath: string
dataPath: string
workerPath: string
cacheMethod: string
workerBlobURL: boolean
gzip: boolean
logger: (any) => void
}
interface WorkerParams {
tessedit_ocr_engine_mode: OEM tessedit_ocr_engine_mode: OEM
tessedit_pageseg_mode: PSM tessedit_pageseg_mode: PSM
tessedit_char_whiltelist: string tessedit_char_whiltelist: string
@ -13,15 +43,34 @@ declare namespace Tesseract {
tessjs_create_box: string tessjs_create_box: string
tessjs_create_unlv: string tessjs_create_unlv: string
tessjs_create_osd: string tessjs_create_osd: string
tessjs_textonly_pdf: string }
tessjs_pdf_name: string interface RecognizeOptions {
tessjs_pdf_title: string rectangles: Rectangle[]
tessjs_pdf_auto_download: boolean }
tessjs_pdf_bin: boolean interface ConfigResult {
tessjs_image_rectangle_left: number jobId: string
tessjs_image_rectangle_top: number data: any
tessjs_image_rectangle_width: number }
tessjs_image_rectangle_height: number interface RecognizeResult {
jobId: string
data: Page
}
interface DetectResult {
jobId: string
data: DetectData
}
interface DetectData {
tesseract_script_id: number
script: string
script_confidence: number
orientation_degrees: number
orientation_confidence: number
}
interface Rectangle {
left: number
top: number
width: number
height: number
} }
const enum OEM { const enum OEM {
TESSERACT_ONLY, TESSERACT_ONLY,
@ -46,11 +95,6 @@ declare namespace Tesseract {
} }
type ImageLike = string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement type ImageLike = string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement
| CanvasRenderingContext2D | File | Blob | ImageData | Buffer; | CanvasRenderingContext2D | File | Blob | ImageData | Buffer;
interface Progress {
status: string;
progress: number;
loaded?: number;
}
interface Block { interface Block {
paragraphs: Paragraph; paragraphs: Paragraph;
text: string; text: string;
@ -148,7 +192,6 @@ declare namespace Tesseract {
interface Page { interface Page {
blocks: Block[]; blocks: Block[];
confidence: number; confidence: number;
html: string;
lines: Line[]; lines: Line[];
oem: string; oem: string;
paragraphs: Paragraph[]; paragraphs: Paragraph[];
@ -157,12 +200,11 @@ declare namespace Tesseract {
text: string; text: string;
version: string; version: string;
words: Word[]; words: Word[];
} hocr: string | null;
interface TesseractJob { tsv: string | null;
then: (callback: (result: Page) => void) => TesseractJob; box: string | null;
progress: (callback: (progress: Progress) => void) => TesseractJob; unlv: string | null;
catch: (callback: (error: Error) => void) => TesseractJob; sd: string | null;
finally: (callback: (resultOrError: Error | Page) => void) => TesseractJob;
} }
} }

2
src/index.js

@ -10,7 +10,6 @@
require('regenerator-runtime/runtime'); require('regenerator-runtime/runtime');
const createScheduler = require('./createScheduler'); const createScheduler = require('./createScheduler');
const createWorker = require('./createWorker'); const createWorker = require('./createWorker');
const createJob = require('./createJob');
const Tesseract = require('./Tesseract'); const Tesseract = require('./Tesseract');
const OEM = require('./constants/OEM'); const OEM = require('./constants/OEM');
const PSM = require('./constants/PSM'); const PSM = require('./constants/PSM');
@ -21,7 +20,6 @@ module.exports = {
PSM, PSM,
createScheduler, createScheduler,
createWorker, createWorker,
createJob,
setLogging, setLogging,
...Tesseract, ...Tesseract,
}; };

Loading…
Cancel
Save