Skip to content

Commit

Permalink
fix(core): 修改 typr 库,减少部分打包体积。
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed May 17, 2022
1 parent a20965f commit 51e26de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"node-fetch": "^2.6.7",
"string-similarity": "^4.0.4",
"tesseract.js": "^2.1.5",
"typr-ts": "^1.1.5",
"typr.js": "^1.0.0",
"vue": "^3.2.31"
},
"repository": {
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/script/cx/recognize.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import md5 from 'md5';
import { Typr, TyprU } from 'typr-ts';
import { request } from '../../core/utils';
import { logger, OCR, store } from '../../main';
import CXAnalyses from './utils';
// @ts-ignore
import Typr from 'typr.js';

/**
* 繁体字识别-字典匹配
Expand Down Expand Up @@ -35,9 +36,9 @@ export async function mapRecognize() {
// 匹配解密字体
const match: any = {};
for (let i = 19968; i < 40870; i++) { // 中文[19968, 40869]
const Glyph = TyprU.codeToGlyph(code, i);
const Glyph = Typr.U.codeToGlyph(code, i);
if (!Glyph) continue;
const path = TyprU.glyphToPath(code, Glyph);
const path = Typr.U.glyphToPath(code, Glyph);
const hex = md5(JSON.stringify(path)).slice(24); // 8位即可区分
match[i.toString()] = fontMap[hex];
}
Expand All @@ -49,7 +50,9 @@ export async function mapRecognize() {
for (const key in match) {
const word = String.fromCharCode(parseInt(key));
const value = String.fromCharCode(match[key]);
html = html.replaceAll(word, value);
while (html.indexOf(word) !== -1) {
html = html.replace(word, value);
}
}
el.innerHTML = html;
el.classList.remove('font-cxsecret'); // 移除字体加密
Expand All @@ -58,6 +61,7 @@ export async function mapRecognize() {
}
}
}

/** 繁体字识别-OCR文字识别 */
export async function ocrRecognize() {
const ocr = new OCR({
Expand Down
5 changes: 1 addition & 4 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"DOM",
"es2021"
"DOM"
],
"jsx": "preserve",
"resolveJsonModule": true
},
"include": [
"./src/core/index.ts",
"./src/**/*.ts",
"src/script/zhs/index.ts"
]
}

0 comments on commit 51e26de

Please sign in to comment.