@subframe7536/fonttools
Version:
[ESM only] fonttools for nodejs or web with vite plugin, powered by pyodide
52 lines (49 loc) • 2.29 kB
TypeScript
import { Plugin } from 'vite';
declare const assetsKey: {
readonly brotli: "$brotli";
readonly fonttools: "$fonttools";
readonly wasm: "$wasm";
readonly asmjs: "$asmjs";
readonly zip: "$zip";
readonly lock: "$lock";
};
type AssetsKey = typeof assetsKey[keyof typeof assetsKey];
interface FonttoolsPluginOptions {
/**
* Custom URL for assets.
*
* There are 6 assets that the plugin handled:
* - 2 `.whl` file: For `fonttools` and `brotli`(for `woff2`)
* - 1 lock file: Load `.whl`
* - 1 asm.js file: EMScript generated file
* - 1 asm.wasm file: EMScript generated file
* - 1 zip file: Python stdlibs
*
* And importer that use `loadInBrowser` imports lock file, asm.js, asm.wasm and zip file
*
* Final loaded url pattern: `{indexURL}{urlPrefix}{assetsName}`
*
* By default, all the assets is loaded from the same directory as importer in production.
* You should set it if your `build.assetsDir` or `build.rollupOptions.output.assetFileNames` is modified.
*
* @param currentAssetsKey key to access `originalAssetsPathMap` and `finalAssetsPathMap`
* @param assetsNameMap assets name map, use `currentAssetsKey` to get file name
* @param finalAssetsPathMap final assets path map, use `currentAssetsKey` to get final file path
* @param importer [importerPath, importerCode]
* @example
* // assert your `assetsDir` is default
* // and productionURL is 'https://example.com/project'
* handleURL = (key, originalMap, finalMap) => `deep/${finalMap(key)![0]}`
* // your finalWasmURL is 'https://example.com/project/deep/assets/pyodide.asm-[hash].wasm'
*/
customURL?: (currentAssetsKey: AssetsKey, assetsNameMap: Map<AssetsKey, string>, finalAssetsPathMap: Map<AssetsKey, [path: string, source: string | Uint8Array]>, importer: [path: string, code: string]) => string;
/**
* Transform code in `pyodide.web.asm.js`
*/
transformAsmJs?: (code: string) => string | undefined | null | void;
}
/**
* Vite plugin for `@subframe7536/fonttools/web`, emit missing assets
*/
declare function fonttools(options?: FonttoolsPluginOptions): Plugin[];
export { type AssetsKey, type FonttoolsPluginOptions, assetsKey, fonttools };