diff --git a/biome.jsonc b/biome.jsonc index 8a62a1d..701cd05 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -3,6 +3,10 @@ "organizeImports": { "enabled": true }, + "formatter": { + "indentStyle": "space", + "lineWidth": 120 + }, "linter": { "enabled": true, "rules": { @@ -14,5 +18,13 @@ "quoteStyle": "single", "semicolons": "asNeeded" } + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignore": ["ios", "android"] } -} \ No newline at end of file +} diff --git a/bun.lockb b/bun.lockb index 751f510..cfd4162 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/examples/browser/browser.ts b/examples/browser/browser.ts index 7506b66..095a91d 100644 --- a/examples/browser/browser.ts +++ b/examples/browser/browser.ts @@ -29,12 +29,8 @@ function createApp( ) { const resultTextEl = document.querySelector('#result-text') as HTMLDivElement const performanceEl = document.querySelector('#performance') as HTMLDivElement - const resultImageEl = document.querySelector( - '#result-image', - ) as HTMLImageElement - const inputImageEl = document.querySelector( - '#input-image', - ) as HTMLImageElement + const resultImageEl = document.querySelector('#result-image') as HTMLImageElement + const inputImageEl = document.querySelector('#input-image') as HTMLImageElement inputImageEl.addEventListener('change', async (event) => { const file = (event.target as HTMLInputElement).files?.[0] if (!file) { diff --git a/examples/browser/package.json b/examples/browser/package.json index 9c16ec4..94b5837 100644 --- a/examples/browser/package.json +++ b/examples/browser/package.json @@ -3,4 +3,4 @@ "dependencies": { "@gutenye/ocr-browser": "worksapce:*" } -} \ No newline at end of file +} diff --git a/examples/node/node.ts b/examples/node/node.ts index dbd4299..b3b5dbe 100644 --- a/examples/node/node.ts +++ b/examples/node/node.ts @@ -1,6 +1,6 @@ +import filePath from 'path' import Ocr from '@gutenye/ocr-node' import fs from 'fs/promises' -import filePath from 'path' async function main() { const ocr = await Ocr.create() diff --git a/examples/node/package.json b/examples/node/package.json index ad098b5..6e271aa 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -1,7 +1,7 @@ { - "name": "node-example", - "type": "module", - "dependencies": { - "@gutenye/ocr-node": "^1.0.0" - } -} \ No newline at end of file + "name": "node-example", + "type": "module", + "dependencies": { + "@gutenye/ocr-node": "^1.0.0" + } +} diff --git a/examples/react-native/App.tsx b/examples/react-native/App.tsx index a458267..e6fda39 100644 --- a/examples/react-native/App.tsx +++ b/examples/react-native/App.tsx @@ -1,6 +1,6 @@ import camera from 'expo-camera' -import * as ort from 'onnxruntime-react-native' import { StatusBar } from 'expo-status-bar' +import * as ort from 'onnxruntime-react-native' import { StyleSheet, Text, View } from 'react-native' import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context' import { Ocr } from '../build/ocr' diff --git a/examples/react-native/babel.config.js b/examples/react-native/babel.config.js index 2900afe..9f057ea 100644 --- a/examples/react-native/babel.config.js +++ b/examples/react-native/babel.config.js @@ -1,6 +1,6 @@ -module.exports = function(api) { - api.cache(true); +module.exports = (api) => { + api.cache(true) return { presets: ['babel-preset-expo'], - }; -}; + } +} diff --git a/examples/react-native/package.json b/examples/react-native/package.json index 62e5e57..0adec52 100644 --- a/examples/react-native/package.json +++ b/examples/react-native/package.json @@ -24,4 +24,4 @@ "typescript": "^5.1.3" }, "private": true -} \ No newline at end of file +} diff --git a/index.ts b/index.ts deleted file mode 100644 index f67b2c6..0000000 --- a/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello via Bun!"); \ No newline at end of file diff --git a/package.json b/package.json index 3642ba7..801af67 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,10 @@ { "name": "@gutenye/ocr", - "workspaces": [ - "packages/*" - ], + "workspaces": ["packages/*"], "devDependencies": { + "@biomejs/biome": "1.7.3", "@types/bun": "latest", "tsc-alias": "^1.8.8", "typescript": "^5.0.0" } -} \ No newline at end of file +} diff --git a/packages/browser/package.json b/packages/browser/package.json index 62761e3..9fe9df0 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -13,12 +13,7 @@ "bun": "./src/index.ts", "default": "./build/index.js" }, - "files": [ - "src", - "build", - "tsconfig.json", - "!**/__tests__" - ], + "files": ["src", "build", "tsconfig.json", "!**/__tests__"], "scripts": { "prepublishOnly": "./ake build" }, @@ -26,4 +21,4 @@ "@gutenye/ocr-common": "^1.2.0", "onnxruntime-web": "^1.17.3" } -} \ No newline at end of file +} diff --git a/packages/browser/src/ImageRaw.ts b/packages/browser/src/ImageRaw.ts index a8637fa..e30427a 100644 --- a/packages/browser/src/ImageRaw.ts +++ b/packages/browser/src/ImageRaw.ts @@ -1,5 +1,5 @@ import { ImageRawBase } from '@gutenye/ocr-common' -import type { ImageRawData, SizeOption, LineImage } from '@gutenye/ocr-common' +import type { ImageRawData, LineImage, SizeOption } from '@gutenye/ocr-common' import invariant from 'tiny-invariant' export class ImageRaw extends ImageRawBase { @@ -39,10 +39,7 @@ export class ImageRaw extends ImageRawBase { } async resize({ width, height }: SizeOption) { - invariant( - width !== undefined || height !== undefined, - 'both width and height are undefined', - ) + invariant(width !== undefined || height !== undefined, 'both width and height are undefined') const newWidth = width || Math.round((this.width / this.height) * height!) const newHeight = height || Math.round((this.height / this.width) * width!) const newCanvas = document.createElement('canvas') @@ -92,24 +89,14 @@ export class ImageRaw extends ImageRawBase { } } -function canvasDrawImage( - canvas: HTMLCanvasElement, - image: CanvasImageSource, - width?: number, - height?: number, -) { +function canvasDrawImage(canvas: HTMLCanvasElement, image: CanvasImageSource, width?: number, height?: number) { canvas.width = width || image.width canvas.height = height || image.height const ctx = canvas.getContext('2d')! ctx.drawImage(image, 0, 0, canvas.width, canvas.height) } -function canvasPutImageData( - canvas: HTMLCanvasElement, - imageData: ImageData, - width?: number, - height?: number, -) { +function canvasPutImageData(canvas: HTMLCanvasElement, imageData: ImageData, width?: number, height?: number) { const ctx = canvas.getContext('2d')! canvas.width = width || imageData.width canvas.height = height || imageData.height @@ -117,9 +104,7 @@ function canvasPutImageData( } function canvasGetImageData(canvas: HTMLCanvasElement) { - return canvas - .getContext('2d')! - .getImageData(0, 0, canvas.width, canvas.height) + return canvas.getContext('2d')!.getImageData(0, 0, canvas.width, canvas.height) } async function imageFromUrl(url: string) { diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 1c513ea..3de4ef4 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -1,7 +1,7 @@ import Ocr, { registerBackend } from '@gutenye/ocr-common' +import { InferenceSession } from 'onnxruntime-web' import { FileUtils } from './FileUtils' import { ImageRaw } from './ImageRaw' -import { InferenceSession } from 'onnxruntime-web' registerBackend({ FileUtils, ImageRaw, InferenceSession }) diff --git a/packages/common/package.json b/packages/common/package.json index 535d305..cc6c34e 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -19,13 +19,7 @@ "default": "./build/use-default-models.node.js" } }, - "files": [ - "assets", - "src", - "build", - "tsconfig.json", - "!**/__tests__" - ], + "files": ["assets", "src", "build", "tsconfig.json", "!**/__tests__"], "scripts": { "prepublishOnly": "./ake build" }, @@ -34,4 +28,4 @@ "js-clipper": "^1.0.1", "tiny-invariant": "^1.3.3" } -} \ No newline at end of file +} diff --git a/packages/common/src/Ocr.ts b/packages/common/src/Ocr.ts index 498b661..80c9187 100644 --- a/packages/common/src/Ocr.ts +++ b/packages/common/src/Ocr.ts @@ -1,5 +1,5 @@ -import { Detection, Recognition } from './models' import invariant from 'tiny-invariant' +import { Detection, Recognition } from './models' export class Ocr { static DEFAULT_DETECTION_PATH: string @@ -17,11 +17,9 @@ export class Ocr { } = {}) { const detectionPath = this.DEFAULT_DETECTION_PATH || models?.detectionPath invariant(detectionPath, 'detectionPath is required') - const recognitionPath = - this.DEFAULT_RECOGINTION_PATH || models?.recognitionPath + const recognitionPath = this.DEFAULT_RECOGINTION_PATH || models?.recognitionPath invariant(recognitionPath, 'recognitionPath is required') - const dictionaryPath = - this.DEFAULT_DICTIONARY_PATH || models?.dictionaryPath + const dictionaryPath = this.DEFAULT_DICTIONARY_PATH || models?.dictionaryPath invariant(dictionaryPath, 'dictionaryPath is required') const detection = await Detection.create({ diff --git a/packages/common/src/backend/backend.ts b/packages/common/src/backend/backend.ts index e3dca72..e676186 100644 --- a/packages/common/src/backend/backend.ts +++ b/packages/common/src/backend/backend.ts @@ -6,8 +6,7 @@ import type { let FileUtils: FileUtilsType = undefined as unknown as FileUtilsType let ImageRaw: ImageRawType = undefined as unknown as ImageRawType -let InferenceSession: InferenceSessionType = - undefined as unknown as InferenceSessionType +let InferenceSession: InferenceSessionType = undefined as unknown as InferenceSessionType export function registerBackend(backend: { FileUtils: FileUtilsType diff --git a/packages/common/src/models/Detection.ts b/packages/common/src/models/Detection.ts index 7067188..06f28c7 100644 --- a/packages/common/src/models/Detection.ts +++ b/packages/common/src/models/Detection.ts @@ -1,8 +1,8 @@ +import type { Tensor } from 'onnxruntime-common' import { ImageRaw, InferenceSession } from '#/backend' import { splitIntoLineImages } from '#/splitIntoLineImages' -import { Tensor } from 'onnxruntime-common' +import type { ModelBaseConstructorArgs, Size } from '#/types' import { ModelBase } from './ModelBase' -import type { Size, ModelBaseConstructorArgs } from '#/types' const BASE_SIZE = 32 @@ -25,7 +25,7 @@ export class Detection extends ModelBase { // - image width and height must be a multiple of 32 // - bigger image -> more accurate result, but takes longer time // inputImage = await Image.resize(image, multipleOfBaseSize(image, { maxSize: 960 })) - let inputImage = await image.resize(multipleOfBaseSize(image)) + const inputImage = await image.resize(multipleOfBaseSize(image)) this.debugImage(inputImage, './output/out1-multiple-of-base-size.jpg') // Covert image data to model data @@ -59,10 +59,7 @@ export class Detection extends ModelBase { } } -function multipleOfBaseSize( - image: ImageRaw, - { maxSize }: { maxSize?: number } = {}, -): Size { +function multipleOfBaseSize(image: ImageRaw, { maxSize }: { maxSize?: number } = {}): Size { let width = image.width let height = image.height if (maxSize && Math.max(width, height) > maxSize) { @@ -76,10 +73,7 @@ function multipleOfBaseSize( Math.ceil(width / BASE_SIZE) * BASE_SIZE, BASE_SIZE, ) - const newHeight = Math.max( - Math.ceil(height / BASE_SIZE) * BASE_SIZE, - BASE_SIZE, - ) + const newHeight = Math.max(Math.ceil(height / BASE_SIZE) * BASE_SIZE, BASE_SIZE) return { width: newWidth, height: newHeight } } diff --git a/packages/common/src/models/ModelBase.ts b/packages/common/src/models/ModelBase.ts index a7e08c6..1eaa77b 100644 --- a/packages/common/src/models/ModelBase.ts +++ b/packages/common/src/models/ModelBase.ts @@ -1,11 +1,5 @@ import { Tensor } from 'onnxruntime-common' -import type { - ModelData, - InferenceSession, - ImageRaw, - ReshapeOptions, - ModelBaseConstructorArgs, -} from '#/types' +import type { ImageRaw, InferenceSession, ModelBaseConstructorArgs, ModelData, ReshapeOptions } from '#/types' export class ModelBase { isDebug: boolean @@ -27,18 +21,10 @@ export class ModelBase { #prepareInput(modelData: ModelData) { const input = Float32Array.from(modelData.data) - return new Tensor('float32', input, [ - 1, - 3, - modelData.height, - modelData.width, - ]) + return new Tensor('float32', input, [1, 3, modelData.height, modelData.width]) } - imageToInput( - image: ImageRaw, - { mean = [0, 0, 0], std = [1, 1, 1] }: ReshapeOptions, - ): ModelData { + imageToInput(image: ImageRaw, { mean = [0, 0, 0], std = [1, 1, 1] }: ReshapeOptions): ModelData { const R: number[] = [] const G: number[] = [] const B: number[] = [] diff --git a/packages/common/src/models/Recognition.ts b/packages/common/src/models/Recognition.ts index cd88d11..c1eb580 100644 --- a/packages/common/src/models/Recognition.ts +++ b/packages/common/src/models/Recognition.ts @@ -1,12 +1,7 @@ +import type { Tensor } from 'onnxruntime-common' import { FileUtils, InferenceSession } from '#/backend' -import { Tensor } from 'onnxruntime-common' +import type { Dictionary, Line, LineImage, ModelBaseConstructorArgs } from '#/types' import { ModelBase } from './ModelBase' -import type { - LineImage, - Line, - Dictionary, - ModelBaseConstructorArgs, -} from '#/types' export class Recognition extends ModelBase { #dictionary: Dictionary @@ -69,8 +64,8 @@ export class Recognition extends ModelBase { decodeText(output: Tensor) { const data = output - let predLen = data.dims[2] - let line: Line[] = [] + const predLen = data.dims[2] + const line: Line[] = [] let ml = data.dims[0] - 1 for (let l = 0; l < data.data.length; l += predLen * data.dims[1]) { const predsIdx: number[] = [] @@ -78,7 +73,7 @@ export class Recognition extends ModelBase { for (let i = l; i < l + predLen * data.dims[1]; i += predLen) { const tmpArr = data.data.slice(i, i + predLen) as Float32Array - const tmpMax = tmpArr.reduce((a, b) => Math.max(a, b), -Infinity) + const tmpMax = tmpArr.reduce((a, b) => Math.max(a, b), Number.NEGATIVE_INFINITY) const tmpIdx = tmpArr.indexOf(tmpMax) predsProb.push(tmpMax) predsIdx.push(tmpIdx) @@ -90,12 +85,7 @@ export class Recognition extends ModelBase { } } -function decode( - dictionary: string[], - textIndex: number[], - textProb: number[], - isRemoveDuplicate: boolean, -) { +function decode(dictionary: string[], textIndex: number[], textProb: number[], isRemoveDuplicate: boolean) { const ignoredTokens = [0] const charList = [] const confList = [] @@ -137,9 +127,9 @@ function calculateBox({ }) { let mainLine = lines const box = lineImages - for (let i in mainLine) { - let b = box[mainLine.length - Number(i) - 1].box - for (let p of b) { + for (const i in mainLine) { + const b = box[mainLine.length - Number(i) - 1].box + for (const p of b) { p[0] = p[0] p[1] = p[1] } @@ -151,9 +141,9 @@ function calculateBox({ } function afAfRec(l: Line[]) { - let line: Line[] = [] - let ind: Map = new Map() - for (let i in l) { + const line: Line[] = [] + const ind: Map = new Map() + for (const i in l) { ind.set(l[i].box, Number(i)) } @@ -198,13 +188,13 @@ function afAfRec(l: Line[]) { return result } - let boxes = groupBoxesByMidlineDifference([...ind.keys()]) + const boxes = groupBoxesByMidlineDifference([...ind.keys()]) - for (let i of boxes) { - let t = [] + for (const i of boxes) { + const t = [] let m = 0 - for (let j of i) { - let x = l[ind.get(j)] + for (const j of i) { + const x = l[ind.get(j)] t.push(x.text) m += x.mean } diff --git a/packages/common/src/splitIntoLineImages.ts b/packages/common/src/splitIntoLineImages.ts index 4dfced7..317ffc4 100644 --- a/packages/common/src/splitIntoLineImages.ts +++ b/packages/common/src/splitIntoLineImages.ts @@ -1,5 +1,5 @@ -import clipper from 'js-clipper' import cv from '@techstark/opencv-js' +import clipper from 'js-clipper' import { ImageRaw } from '#/backend' import type { LineImage } from '#/types' @@ -7,48 +7,34 @@ type pointType = [number, number] type BoxType = [pointType, pointType, pointType, pointType] type pointsType = pointType[] -export async function splitIntoLineImages( - image: ImageRaw, - sourceImage: ImageRaw, -): Promise { +export async function splitIntoLineImages(image: ImageRaw, sourceImage: ImageRaw): Promise { const w = image.width const h = image.height const srcData = sourceImage - let edgeRect: { box: BoxType; image: ImageRaw }[] = [] + const edgeRect: { box: BoxType; image: ImageRaw }[] = [] - let src = cvImread(image) + const src = cvImread(image) cv.cvtColor(src, src, cv.COLOR_RGBA2GRAY, 0) - let contours = new cv.MatVector() - let hierarchy = new cv.Mat() + const contours = new cv.MatVector() + const hierarchy = new cv.Mat() - cv.findContours( - src, - contours, - hierarchy, - cv.RETR_LIST, - cv.CHAIN_APPROX_SIMPLE, - ) + cv.findContours(src, contours, hierarchy, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE) for (let i = 0; i < contours.size(); i++) { - let minSize = 3 - let cnt = contours.get(i) - let { points, sside } = getMiniBoxes(cnt) + const minSize = 3 + const cnt = contours.get(i) + const { points, sside } = getMiniBoxes(cnt) if (sside < minSize) continue // TODO sort fast - let clipBox = unclip(points) + const clipBox = unclip(points) - const boxMap = new cv.matFromArray( - clipBox.length / 2, - 1, - cv.CV_32SC2, - clipBox, - ) + const boxMap = new cv.matFromArray(clipBox.length / 2, 1, cv.CV_32SC2, clipBox) const resultObj = getMiniBoxes(boxMap) - let box = resultObj.points + const box = resultObj.points if (resultObj.sside < minSize + 2) { continue } @@ -56,24 +42,24 @@ export async function splitIntoLineImages( return Math.max(min, Math.min(n, max)) } - let rx = srcData.width / w - let ry = srcData.height / h + const rx = srcData.width / w + const ry = srcData.height / h for (let i = 0; i < box.length; i++) { box[i][0] *= rx box[i][1] *= ry } - let box1 = orderPointsClockwise(box) + const box1 = orderPointsClockwise(box) box1.forEach((item) => { item[0] = clip(Math.round(item[0]), 0, srcData.width) item[1] = clip(Math.round(item[1]), 0, srcData.height) }) - let rect_width = int(linalgNorm(box1[0], box1[1])) - let rect_height = int(linalgNorm(box1[0], box1[3])) + const rect_width = int(linalgNorm(box1[0], box1[1])) + const rect_height = int(linalgNorm(box1[0], box1[3])) if (rect_width <= 3 || rect_height <= 3) continue - let c = getRotateCropImage(srcData, box) + const c = getRotateCropImage(srcData, box) edgeRect.push({ box, @@ -90,9 +76,9 @@ export async function splitIntoLineImages( function getMiniBoxes(contour: any) { const boundingBox = cv.minAreaRect(contour) - const points = Array.from( - boxPoints(boundingBox.center, boundingBox.size, boundingBox.angle), - ).sort((a, b) => a[0] - b[0]) as pointsType + const points = Array.from(boxPoints(boundingBox.center, boundingBox.size, boundingBox.angle)).sort( + (a, b) => a[0] - b[0], + ) as pointsType let index_1 = 0, index_2 = 1, @@ -113,12 +99,7 @@ function getMiniBoxes(contour: any) { index_3 = 2 } - const box = [ - points[index_1], - points[index_2], - points[index_3], - points[index_4], - ] as BoxType + const box = [points[index_1], points[index_2], points[index_3], points[index_4]] as BoxType const side = Math.min(boundingBox.size.height, boundingBox.size.width) return { points: box, sside: side } } @@ -139,11 +120,7 @@ function unclip(box: pointsType) { tmpArr.push(obj) }) const offset = new clipper.ClipperOffset() - offset.AddPath( - tmpArr, - clipper.JoinType.jtRound, - clipper.EndType.etClosedPolygon, - ) + offset.AddPath(tmpArr, clipper.JoinType.jtRound, clipper.EndType.etClosedPolygon) const expanded: { X: number; Y: number }[][] = [] offset.Execute(expanded, distance) let expandedArr: pointsType = [] @@ -182,18 +159,8 @@ function int(num: number) { } function getRotateCropImage(imageRaw: ImageRaw, points: BoxType): ImageRaw { - const img_crop_width = int( - Math.max( - linalgNorm(points[0], points[1]), - linalgNorm(points[2], points[3]), - ), - ) - const img_crop_height = int( - Math.max( - linalgNorm(points[0], points[3]), - linalgNorm(points[1], points[2]), - ), - ) + const img_crop_width = int(Math.max(linalgNorm(points[0], points[1]), linalgNorm(points[2], points[3]))) + const img_crop_height = int(Math.max(linalgNorm(points[0], points[3]), linalgNorm(points[1], points[2]))) const pts_std = [ [0, 0], [img_crop_width, 0], @@ -210,15 +177,7 @@ function getRotateCropImage(imageRaw: ImageRaw, points: BoxType): ImageRaw { const dst = new cv.Mat() const dsize = new cv.Size(img_crop_width, img_crop_height) // 透视转换 - cv.warpPerspective( - src, - dst, - M, - dsize, - cv.INTER_CUBIC, - cv.BORDER_REPLICATE, - new cv.Scalar(), - ) + cv.warpPerspective(src, dst, M, dsize, cv.INTER_CUBIC, cv.BORDER_REPLICATE, new cv.Scalar()) const dst_img_height = dst.matSize[0] const dst_img_width = dst.matSize[1] @@ -229,15 +188,7 @@ function getRotateCropImage(imageRaw: ImageRaw, points: BoxType): ImageRaw { const dsize_rot = new cv.Size(dst.rows, dst.cols) const center = new cv.Point(dst.cols / 2, dst.cols / 2) const M = cv.getRotationMatrix2D(center, 90, 1) - cv.warpAffine( - dst, - dst_rot, - M, - dsize_rot, - cv.INTER_CUBIC, - cv.BORDER_REPLICATE, - new cv.Scalar(), - ) + cv.warpAffine(dst, dst_rot, M, dsize_rot, cv.INTER_CUBIC, cv.BORDER_REPLICATE, new cv.Scalar()) } src.delete() @@ -250,11 +201,7 @@ function getRotateCropImage(imageRaw: ImageRaw, points: BoxType): ImageRaw { return cvImshow(dst_rot || dst) } -function boxPoints( - center: { x: number; y: number }, - size: { width: number; height: number }, - angle: number, -) { +function boxPoints(center: { x: number; y: number }, size: { width: number; height: number }, angle: number) { const width = size.width const height = size.height diff --git a/packages/common/src/types/types.ts b/packages/common/src/types/types.ts index 7f76488..b12d09c 100644 --- a/packages/common/src/types/types.ts +++ b/packages/common/src/types/types.ts @@ -1,5 +1,5 @@ -import { ImageRawBase as ImageRaw } from '#/backend/ImageRawBase' import { InferenceSession } from 'onnxruntime-common' +import { ImageRawBase as ImageRaw } from '#/backend/ImageRawBase' export { FileUtilsBase as FileUtils } from '#/backend/FileUtilsBase' export { ImageRaw, InferenceSession } diff --git a/packages/common/src/use-default-models.node.ts b/packages/common/src/use-default-models.node.ts index 0102cd1..f6cfb6b 100644 --- a/packages/common/src/use-default-models.node.ts +++ b/packages/common/src/use-default-models.node.ts @@ -9,8 +9,5 @@ export default function useDefaultModels() { } function resolve(path: string) { - return filePath.resolve( - filePath.dirname(fileURLToPath(import.meta.url)), - path, - ) + return filePath.resolve(filePath.dirname(fileURLToPath(import.meta.url)), path) } diff --git a/packages/node/package.json b/packages/node/package.json index d6f2151..2510ac6 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -13,12 +13,7 @@ "bun": "./src/index.ts", "default": "./build/index.js" }, - "files": [ - "src", - "build", - "tsconfig.json", - "!**/__tests__" - ], + "files": ["src", "build", "tsconfig.json", "!**/__tests__"], "scripts": { "prepublishOnly": "./ake build" }, @@ -27,4 +22,4 @@ "onnxruntime-node": "^1.17.3-rev.1", "sharp": "^0.33.3" } -} \ No newline at end of file +} diff --git a/packages/node/src/FileUtils.ts b/packages/node/src/FileUtils.ts index 73337fe..8fe954b 100644 --- a/packages/node/src/FileUtils.ts +++ b/packages/node/src/FileUtils.ts @@ -1,5 +1,5 @@ -import fs from 'fs/promises' import { FileUtilsBase } from '@gutenye/ocr-common' +import fs from 'fs/promises' export class FileUtils extends FileUtilsBase { static async read(path: string) { diff --git a/packages/node/src/ImageRaw.ts b/packages/node/src/ImageRaw.ts index fbb9241..9a1526b 100644 --- a/packages/node/src/ImageRaw.ts +++ b/packages/node/src/ImageRaw.ts @@ -1,7 +1,7 @@ -import sharp from 'sharp' import filePath from 'node:path' import { ImageRawBase } from '@gutenye/ocr-common' -import type { ImageRawData, SizeOption, LineImage } from '@gutenye/ocr-common' +import type { ImageRawData, LineImage, SizeOption } from '@gutenye/ocr-common' +import sharp from 'sharp' export class ImageRaw extends ImageRawBase { #sharp: sharp.Sharp @@ -41,9 +41,7 @@ export class ImageRaw extends ImageRawBase { .join('\n')} ` - return this.#apply( - this.#sharp.composite([{ input: Buffer.from(svg), left: 0, top: 0 }]), - ) + return this.#apply(this.#sharp.composite([{ input: Buffer.from(svg), left: 0, top: 0 }])) } async #apply(sharp: sharp.Sharp) { diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 8c9348d..e6be5a6 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -1,8 +1,8 @@ import Ocr, { registerBackend } from '@gutenye/ocr-common' import useDefaultModels from '@gutenye/ocr-common/use-default-models.node' +import { InferenceSession } from 'onnxruntime-node' import { FileUtils } from './FileUtils' import { ImageRaw } from './ImageRaw' -import { InferenceSession } from 'onnxruntime-node' useDefaultModels() registerBackend({ FileUtils, ImageRaw, InferenceSession }) diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 967640e..b0c3f8c 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -13,12 +13,7 @@ "react-native": "./src/index.ts", "default": "./build/index.js" }, - "files": [ - "src", - "build", - "tsconfig.json", - "!**/__tests__" - ], + "files": ["src", "build", "tsconfig.json", "!**/__tests__"], "scripts": { "prepublishOnly": "./ake build" }, diff --git a/packages/react-native/src/ImageRaw.ts b/packages/react-native/src/ImageRaw.ts index 29b3ef6..7af7440 100644 --- a/packages/react-native/src/ImageRaw.ts +++ b/packages/react-native/src/ImageRaw.ts @@ -1,5 +1,5 @@ import { ImageRawBase } from '@gutenye/ocr-common' -import type { ImageRawData, SizeOption, LineImage } from '@gutenye/ocr-common' +import type { ImageRawData, LineImage, SizeOption } from '@gutenye/ocr-common' export class ImageRaw extends ImageRawBase { static async open(path: string): Promise {} diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 50a54b1..f80794c 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -1,7 +1,7 @@ import Ocr, { registerBackend } from '@gutenye/ocr-common' +import { InferenceSession } from 'onnxruntime-react-native' import { FileUtils } from './FileUtils' import { ImageRaw } from './ImageRaw' -import { InferenceSession } from 'onnxruntime-react-native' registerBackend({ FileUtils, ImageRaw, InferenceSession })