UNPKG

cn-font-split

Version:

划时代的字体切割工具,CJK与任何字符!支持 otf、ttf、woff2 字体多线程切割,完美地细颗粒度地进行包大小控制。A revolutionary font subetter that supports CJK and any characters! It enables multi-threaded subset of otf, ttf, and woff2 fonts, allowing for precise control over package size.

41 lines (40 loc) 1.27 kB
import { api_interface as e } from "./gen/index.mjs"; import "./decodeReporter.mjs"; import t from "path"; import n from "fs-extra"; //#region src/createAPI.ts var r = async (e) => { let t = {}; return typeof e.input == "string" ? t.input = await n.readFile(e.input) : t.input = e.input, Array.isArray(e.subsets) && (t.subsets = e.subsets.map((e) => new Uint8Array(new Uint32Array(e).buffer))), { ...e, ...t }; }, i = (i, a, o) => async function(s) { let c = await r(s), l = e.InputTemplate.fromObject(c); if (!l.outDir) throw Error("cn-font-split need outDir"); let u = Math.random().toString().slice(2, 5); console.time("cn-font-split " + u); let d = []; return new Promise((r) => { let o = l.serialize(); i(o, o.length, a((i) => { let a = e.EventMessage.deserialize(i); switch (a.event) { case e.EventName.END: r(); break; case e.EventName.OUTPUT_DATA: !s.silent && console.log(a.message); let i = (s.outputFile || n.outputFile)(t.join(l.outDir, a.message), a.data); d.push(i); break; default: } })); }).then(async (e) => (await Promise.all(d), e)).finally(() => { console.timeEnd("cn-font-split " + u), o?.(); }); }; //#endregion export { i as createAPI }; //# sourceMappingURL=createAPI.mjs.map