build: uses types declaration in detypify (#277)

This commit is contained in:
Myriad-Dreamin 2024-05-12 17:00:35 +08:00 committed by GitHub
parent 43946b9bd3
commit 6b9bd73d8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 28 deletions

View file

@ -12,7 +12,7 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"detypify-service": "0.2.3-beta.3",
"detypify-service": "0.2.4",
"minisearch": "^6.3.0",
"vanjs-core": "^1.5.0"
},

View file

@ -3,11 +3,29 @@ import van, { State } from "vanjs-core";
// import { SYMBOL_MOCK } from "./symbol-view.mock";
const { div, input, canvas, button, h4, a, p, span } = van.tags;
import MiniSearch from "minisearch";
import { Detypify, DetypifySymbol, Stroke } from "detypify-service";
import { Detypify, DetypifySymbol, ortEnv } from "detypify-service";
import { ContributeIcon, HelpIcon } from "../icons";
import { startModal } from "../components/modal";
import { requestTextEdit } from "../vscode";
// The following code can make the onnxruntime-web totally offline but causes more than 10MB of bundle size.
// @ts-ignore
// import onnxWasmUrl from "../../../../node_modules/onnxruntime-web/dist/ort-wasm-simd.wasm?url";
// ortEnv.wasm.numThreads = 4;
// ortEnv.wasm.simd = true;
// ortEnv.wasm.proxy = false;
// ortEnv.wasm.trace = false;
// ortEnv.wasm.wasmPaths = {
// "ort-wasm-simd.wasm": onnxWasmUrl,
// };
ortEnv.wasm.numThreads = 4;
ortEnv.wasm.wasmPaths =
"https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.1/dist/";
type Point = [number, number];
type Stroke = Point[];
interface SymbolCategory {
value?: string;
name: string;
@ -354,7 +372,7 @@ export const SymbolPicker = () => {
: JSON.parse(atob(symbolInformationData))
);
console.log("symbolInformation", symInfo);
const detypifyPromise = Detypify.load();
const detypifyPromise = Detypify.create();
const detypify = van.state<Detypify | undefined>(undefined);
detypifyPromise.then((d: any) => (detypify.val = d));
const strokes = van.state<Stroke[] | undefined>(undefined);

View file

@ -5,7 +5,7 @@
"module": "ESNext",
"lib": ["es2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"types": ["./src/global.d.ts", "./types/detypify.d.ts"],
"types": ["./src/global.d.ts"],
/* Bundler mode */
"moduleResolution": "bundler",
@ -20,5 +20,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "types"]
"include": ["src"]
}

View file

@ -1,19 +0,0 @@
declare module "detypify-service" {
export { env as ortEnv } from "onnxruntime-web";
export declare interface DetypifySymbol {
names: string[];
}
export declare type Point = [number, number];
export declare type Stroke = Point[];
export declare class Detypify {
private constructor(session: InferenceSession);
/**
* Load ONNX runtime and the model.
*/
static load(): Promise<Detypify>;
/**
* Inference top `k` candidates.
*/
candidates(strokes: Stroke[], k: number): Promise<DetypifySymbol[]>;
}
}

View file

@ -1054,10 +1054,10 @@ detect-libc@^2.0.0:
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.2.tgz#8ccf2ba9315350e1241b88d0ac3b0e1fbd99605d"
integrity sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==
detypify-service@0.2.3-beta.3:
version "0.2.3-beta.3"
resolved "https://registry.yarnpkg.com/detypify-service/-/detypify-service-0.2.3-beta.3.tgz#63b892221d60326890731343b39bd0773282d65c"
integrity sha512-bUBhfQMppEE9n/p0Kz1rj+DfR8V8wOA+OB5vCkpZ0A6aumGeUs5mIOEv/LG9+qx37OaEjtEXDp9pSmxRWxWhGQ==
detypify-service@0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/detypify-service/-/detypify-service-0.2.4.tgz#00e54b8c0120d6e39919e2cda0d20af520521f66"
integrity sha512-bhcYoS6ijKJLQlVol0eoaZlnCO6iXYbJrBh7oyXg+I6v7SaBhN+uQeaeLpS1xg+q+t9ujUm3/llj1HkSVBmqzQ==
dependencies:
onnxruntime-web "=1.17.1"