@bookbox/core
Version:
Bookbox — e-book format
52 lines (51 loc) • 1.73 kB
TypeScript
import { BookElements } from './elements';
import { BookElementSchema, BookSchema } from './model';
type ResourceSchema = Omit<BookElementSchema, 'props'> & BookElements['resource'];
export type ResourceSettings = {
src: string;
};
export 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 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 {};