UNPKG

2.86 kBTypeScriptView Raw
1import { Canvg } from '../Canvg';
2import { IScreenViewBoxConfig, Screen } from '../Screen';
3import { Property } from '../Property';
4import { SVGFontLoader } from '../SVGFontLoader';
5import { Element } from './Element';
6import { TextNode } from './TextNode';
7import { ImageElement } from './ImageElement';
8import { SVGElement } from './SVGElement';
9import { AnyElement } from './elements';
10/**
11 * Function to create new canvas.
12 */
13export type CreateCanvas = (width: number, height: number) => HTMLCanvasElement | (OffscreenCanvas & {
14 getContext(contextId: '2d'): OffscreenCanvasRenderingContext2D;
15});
16/**
17 * Function to create new image.
18 */
19export type CreateImage = (src: string, anonymousCrossOrigin?: boolean) => Promise<CanvasImageSource>;
20export interface IDocumentOptions {
21 /**
22 * Default `rem` size.
23 */
24 rootEmSize?: number;
25 /**
26 * Default `em` size.
27 */
28 emSize?: number;
29 /**
30 * Function to create new canvas.
31 */
32 createCanvas?: CreateCanvas;
33 /**
34 * Function to create new image.
35 */
36 createImage?: CreateImage;
37 /**
38 * Load images anonymously.
39 */
40 anonymousCrossOrigin?: boolean;
41}
42export type IViewBoxConfig = Omit<IScreenViewBoxConfig, 'document'>;
43type DOMDocument = typeof window.document;
44declare function createCanvas(width: number, height: number): HTMLCanvasElement;
45declare function createImage(src: string, anonymousCrossOrigin?: boolean): Promise<HTMLImageElement>;
46export declare class Document {
47 readonly canvg: Canvg;
48 static readonly createCanvas: typeof createCanvas;
49 static readonly createImage: typeof createImage;
50 static readonly elementTypes: Record<string, AnyElement>;
51 rootEmSize: number;
52 documentElement?: SVGElement;
53 readonly screen: Screen;
54 readonly createCanvas: CreateCanvas;
55 readonly createImage: CreateImage;
56 readonly definitions: Record<string, Element>;
57 readonly styles: Record<string, Record<string, Property>>;
58 readonly stylesSpecificity: Record<string, string>;
59 readonly images: ImageElement[];
60 readonly fonts: SVGFontLoader[];
61 private readonly emSizeStack;
62 private uniqueId;
63 constructor(canvg: Canvg, { rootEmSize, emSize, createCanvas, createImage, anonymousCrossOrigin }?: IDocumentOptions);
64 private bindCreateImage;
65 get window(): Window;
66 get fetch(): typeof fetch;
67 get ctx(): import("..").RenderingContext2D;
68 get emSize(): number;
69 set emSize(value: number);
70 popEmSize(): void;
71 getUniqueId(): string;
72 isImagesLoaded(): boolean;
73 isFontsLoaded(): boolean;
74 createDocumentElement(document: DOMDocument): SVGElement;
75 createElement<T extends Element>(node: HTMLElement): T;
76 createTextNode(node: HTMLElement): TextNode;
77 setViewBox(config: IViewBoxConfig): void;
78}
79export {};
80//# sourceMappingURL=Document.d.ts.map
\No newline at end of file