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.

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