UNPKG

@bookbox/core

Version:

Bookbox — e-book format

76 lines (75 loc) 2.68 kB
export declare type BookScope = 'html' | 'custom'; export declare type Primitive = string | number | boolean | null; export declare type Serialize<Leaf = Primitive> = Leaf | { [key: string]: Serialize<Leaf>; } | Serialize<Leaf>[]; export declare type BookElementProps = Record<string, Primitive | unknown>; export declare type BookElementSchema = { name: string; props: BookElementProps; children: BookSchema; }; export declare type BookItem = BookElementSchema | string; export declare type BookSchema = BookItem[]; export declare type BookLayoutView = 'block' | 'inline'; export declare type BookLinkedItem = { bookElementSchema: BookElementSchema; firstChild: BookLinkedItem | null; lastChild: BookLinkedItem | null; previous: BookLinkedItem | null; next: BookLinkedItem | null; previousLeaf: BookLinkedItem | null; nextLeaf: BookLinkedItem | null; parent: BookLinkedItem | null; raw: string | null; view: BookLayoutView; }; export declare type BookLinkedSchema = { start: BookLinkedItem | null; end: BookLinkedItem | null; tree: BookLinkedItem[]; }; export declare type CommonElementProps = { key: string; meta: Record<string, Primitive>; }; export declare type BookElement<Name extends string, Props extends BookElementProps = {}> = { name: Name; props: Props & { key: string; meta: Record<string, Primitive>; }; }; export declare type ElementName<Element extends BookElement<any, any>> = Element extends BookElement<infer Name, any> ? Name : never; export declare type BookHeader<Token> = { value: Token[]; text: string; key: string; level: number; }; export declare const rootBookHeader: BookHeader<any>; export declare type BookStore<Token> = { /** * хранилище элементов по ключам */ elementsByKeys: Record<string, BookElementSchema>; /** * хранилище токенов по ключам */ dataByKeys: Record<string, Token[]>; }; export declare type BuildTokens<Token = unknown> = (schema: BookSchema) => Token[]; export declare type GetToken<Token> = (params: { children: Token[]; store: BookStore<Token>; parents: string[]; build: BuildTokens<Token>; }) => Token; export declare type TokenGetter<Props, Token> = (props: Partial<Props>) => GetToken<Token>; export declare type BookBuilder<Token = unknown, ExternalProps = BookElementProps> = (params: { schema: BookSchema; store: BookStore<Token>; externalBuilder?: Record<string, Record<string, TokenGetter<ExternalProps, Token>>>; parents?: string[]; build: BuildTokens<Token>; }) => Token[];