import type { FsAccessModel, PackageRegistry } from "./internal.types.cjs"; import type { WebAssemblyModuleRef } from "./wasm.cjs"; /** * staged options function * @template S - stage mark * @template T - context type */ export type StagedOptFn = (s: S, t: T) => Promise; /** * this mark is used to identify the beforeBuild stage * @description will not be used in runtime code */ declare const BeforeBuildSymbol: unique symbol; /** * this mark is used to identify the beforeBuild stage * @description cannot be created by any runtime code */ export type BeforeBuildMark = typeof BeforeBuildSymbol; /** * before build stage * @description possible created by: * - loadFonts * - preloadSystemFonts * - withAccessModel * - withPackageRegistry */ export type BeforeBuildFn = StagedOptFn; /** * * @property {BeforeBuildFn[]} beforeBuild - callbacks before build stage */ export interface InitOptions { /** * callbacks before build stage * * before build stage, the registered functions will be executed in order * possible options: * - loadFonts * - preloadSystemFonts * - withAccessModel */ beforeBuild: BeforeBuildFn[]; /** * callbacks to fetch the wasm module wrapper */ getWrapper?(): Promise; /** * callbacks to fetch the wasm module * * There are many ways to provide a wasm module, see * {@link WebAssemblyModuleRef} for more details. If you don't provide a wasm * module, the default module will be used. */ getModule(): WebAssemblyModuleRef | Promise; } export type LazyFont = { info: any; } & ({ blob: (index: number) => Uint8Array; } | { url: string; }); type AvailableFontAsset = 'text' | 'cjk' | 'emoji'; export interface LoadRemoteAssetsOptions { /** * preload font assets or don't preload any font assets * @default ['text'] */ assets?: AvailableFontAsset[] | false; /** * customize url prefix for default assets from remote * * The default assets are hosted on github, you can download them and host * them on your own server, which is more practical for production. * * Hosted at: https://github.com/Myriad-Dreamin/typst/tree/assets-fonts * List of assets: * See {@link _textFonts}, {@link _cjkFonts}, and {@link _emojiFonts} * * @default 'jsdelivr-url of typst-assets and typst-dev-assets' */ assetUrlPrefix?: string | Record; /** * custom fetcher * Note: the default fetcher for node.js does not cache any fonts * @default fetch */ fetcher?: typeof fetch; } export interface LoadRemoteFontsOptions extends LoadRemoteAssetsOptions { } /** * disable default font assets */ export declare function disableDefaultFontAssets(): BeforeBuildFn; /** * preload font assets */ export declare function preloadFontAssets(options?: LoadRemoteAssetsOptions): BeforeBuildFn; export declare function _resolveAssets(options?: LoadRemoteFontsOptions): string[]; /** * @deprecated use {@link loadFonts} instead */ export declare function preloadRemoteFonts(userFonts: (string | Uint8Array)[], options?: LoadRemoteFontsOptions): BeforeBuildFn; /** * load fonts * * @param fonts - url path to font files * @returns {BeforeBuildFn} * @example * ```ts * // preLoad fonts from remote url (because finto info is not provided) * import { init, loadFonts } from 'typst'; * init({ * beforeBuild: [ * loadFonts([ * 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2', // remote url * 'dist/fonts/Roboto-Regular.ttf', // relative to the root of the website * ]), * ], * }); * ``` * @example * ```ts * // lazily Load fonts from remote url. The font information is obtained by `getFontInfo` * import { init, loadFonts } from 'typst'; * init({ * beforeBuild: [ * loadFonts([ * { * info: [...] * url: 'https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2'; * } * ]), * ], * }); * ``` */ export declare function loadFonts(userFonts: (string | Uint8Array | LazyFont)[], options?: LoadRemoteFontsOptions): BeforeBuildFn; /** * preload system fonts * @param byFamily - filter system fonts to preload by family name * @returns {BeforeBuildFn} * @example * ```typescript * import { init, preloadSystemFonts } from 'typst'; * init({ * beforeBuild: [ * preloadSystemFonts({ * byFamily: ['Roboto'], // preload fonts by family name * }), * ], * }); * ``` */ export declare function preloadSystemFonts({ byFamily }: { byFamily?: string[]; }): BeforeBuildFn; /** * (compile only) set pacoage registry * * @param accessModel: when compiling, the pacoage registry is used to access the * data of files * @returns {BeforeBuildFn} */ export declare function withPackageRegistry(packageRegistry: PackageRegistry): BeforeBuildFn; /** * (compile only) set access model * * @param accessModel: when compiling, the access model is used to access the * data of files * @returns {BeforeBuildFn} */ export declare function withAccessModel(accessModel: FsAccessModel): BeforeBuildFn; export {}; //# sourceMappingURL=options.init.d.mts.map