UNPKG

@bookbox/core

Version:

Bookbox — e-book format

52 lines (51 loc) 1.76 kB
import { BookElements } from './elements'; import { BookElementSchema, BookSchema } from './model'; declare type ResourceSchema = Omit<BookElementSchema, 'props'> & BookElements['resource']; export declare type ResourceSettings = { src: string; }; export declare type ResourceMap = Map<string, ResourceSettings>; export declare function getResources(schema: BookSchema): ResourceSchema[]; export declare function isValidResource(resource: BookElementSchema): resource is ResourceSchema; export declare function getResourceKey({ path, type }: { path: string; type?: string; }): string; /** * @example * * ```ts * getPathWithPrefix('dir', 'path'); // 'dir/path' * getPathWithPrefix('dir', '/path'); // 'dir/path' * getPathWithPrefix('dir', './path'); // 'dir/path' * getPathWithPrefix('dir', '../path'); // 'dir/../path' * getPathWithPrefix('dir/', 'path'); // 'dir/path' * getPathWithPrefix('dir/', '/path'); // 'dir/path' * getPathWithPrefix('dir/', './path'); // 'dir/path' * getPathWithPrefix('dir/', '../path'); // 'dir/../path' * ``` */ export declare function getPathWithPrefix(src: string, prefix: string): string; /** * priority: pathMap > rawPrefix > prefix > data in book schema */ export declare type ResourceOptions = { /** * <src> -> getPathWithPrefix(<src>, prefix) */ prefix?: string; /** * <src> -> rawPrefix + <src> */ rawPrefix?: string; /** * <src> -> pathMap.get(<path>) */ pathMap?: ResourceMap; }; export declare function getActualResourceMap({ schema, resourceOptions, }: { schema: BookSchema; resourceOptions?: ResourceOptions; }): ResourceMap; export declare function calculateResources(schema: BookSchema, resourceMap?: ResourceMap): void; export {};