mini-canvas-core
Version:
Core library for Mini Canvas Editor.
129 lines (115 loc) • 5.27 kB
TypeScript
import { ImageProps, Image, TOptions, PathProps, Path, RectProps, Rect, TextboxProps, Textbox, StaticCanvas, ImageFormat, Object as Object$1, Canvas, CanvasOptions } from 'fabric';
export * from 'fabric';
import * as fabric__ from 'fabric/*';
interface MceImageProps extends ImageProps {
label: string;
}
declare class MceImage extends Image {
label: string;
constructor(image: HTMLImageElement, options: TOptions<MceImageProps>);
toObject(propertiesToInclude?: string[]): Pick<Omit<Partial<ImageProps> & fabric__.TClassProperties<this>, keyof fabric__.SerializedImageProps>, never> & fabric__.SerializedImageProps;
}
interface McePathProps extends PathProps {
label: string;
}
declare class McePath extends Path {
label: string;
set type(_: string);
constructor(path: any, options: TOptions<McePathProps>);
toObject(propertiesToInclude?: string[]): Pick<Omit<Partial<PathProps> & fabric__.TClassProperties<this>, keyof fabric__.SerializedPathProps>, never> & fabric__.SerializedPathProps;
}
interface MceMceRect extends RectProps {
label: string;
}
declare class MceRect extends Rect {
label: string;
constructor(options: TOptions<MceMceRect>);
private readonly onScaled;
toObject(propertiesToInclude?: string[]): Pick<Omit<Partial<RectProps> & fabric__.TClassProperties<this>, keyof fabric__.SerializedRectProps>, never> & fabric__.SerializedRectProps;
}
declare enum MceVerticalAlign {
top = 1,
middle = 2,
bottom = 3
}
declare enum MceTextBackground {
none = 0,
behind = 1
}
interface MceTextboxProps extends TextboxProps {
label: string;
maxHeight: number;
verticalAlign: MceVerticalAlign;
textBackground: MceTextBackground;
textBackgroundFill: string;
}
declare class MceTextbox extends Textbox {
label: string;
verticalAlign: MceVerticalAlign;
textBackground: MceTextBackground;
textBackgroundFill: string;
maxHeight: number;
static cacheProperties: string[];
constructor(text: string, options: TOptions<MceTextboxProps>);
setText(text: string): void;
private readonly onScaled;
protected calcTextHeight(): number;
protected _getTopOffset(): number;
protected _renderTextCommon(ctx: CanvasRenderingContext2D, method: 'fillText' | 'strokeText'): void;
toObject(propertiesToInclude?: string[]): Pick<Omit<Partial<TextboxProps> & fabric__.TClassProperties<this>, keyof fabric__.SerializedTextboxProps>, never> & fabric__.SerializedTextboxProps;
}
declare function fitImage(rect: MceRect, sourceImage: HTMLImageElement): MceImage;
interface MceLayer {
index: number;
realIndex: number;
name: string;
type: string;
}
interface MceImageJSON {
width: number;
height: number;
data: object;
}
declare class MceStaticCanvas extends StaticCanvas {
private workspaceWidth;
private workspaceHeight;
static createFromJSON(json: MceImageJSON): Promise<MceStaticCanvas>;
workspaceBackground: MceRect;
private readonly common;
private constructor();
readonly getWorkspaceObjects: () => fabric__.FabricObject<Partial<fabric__.FabricObjectProps>, fabric__.SerializedObjectProps, fabric__.ObjectEvents>[];
readonly getLayers: () => MceLayer[];
getReplacer(): MceCanvasReplacer;
exportToDataURL(format: ImageFormat, quality?: number): string;
}
declare class MceCanvasReplacer {
private readonly canvas;
private readonly objects;
static create(canvas: MceStaticCanvas): MceCanvasReplacer;
constructor(canvas: MceStaticCanvas, objects: Object$1[]);
getText(layer: MceLayer): string;
replaceText(layer: MceLayer, text: string): void;
/**
* Replace rectangle to image.
* @param layer Layer.
* @param sourceImage Image element or URL (for example data URL: `data:image/png;base64,...`).
* @param mode Mode of fitting image to the rectangle.
* @returns Promise that resolves when the rect is replaced.
*/
replaceRectToImage(layer: MceLayer, sourceImage: HTMLImageElement | string, mode: 'stretch' | 'fit' | 'fill'): Promise<void>;
}
declare function stretchImage(rect: MceRect, sourceImage: HTMLImageElement): MceImage;
declare function fillImage(rect: MceRect, sourceImage: HTMLImageElement): MceImage;
declare class MceCanvas extends Canvas {
workspaceWidth: number;
workspaceHeight: number;
static createBlank(workspaceWidth: number, workspaceHeight: number, canvasElement: HTMLCanvasElement, options?: TOptions<CanvasOptions>): MceCanvas;
static createFromJSON(json: MceImageJSON, canvasElement: HTMLCanvasElement, options?: TOptions<CanvasOptions>): Promise<MceCanvas>;
workspaceBackground: MceRect;
private readonly common;
private constructor();
readonly getWorkspaceObjects: () => fabric__.FabricObject<Partial<fabric__.FabricObjectProps>, fabric__.SerializedObjectProps, fabric__.ObjectEvents>[];
readonly getLayers: () => MceLayer[];
toImageJSON(): MceImageJSON;
}
export { MceCanvas, MceCanvasReplacer, MceImage, type MceImageJSON, type MceImageProps, type MceLayer, type MceMceRect, McePath, type McePathProps, MceRect, MceStaticCanvas, MceTextBackground, MceTextbox, type MceTextboxProps, MceVerticalAlign, fillImage, fitImage, stretchImage };