@shapeshop/core
Version:
A TS library to generate SVG data based on user mouse/pointer input
86 lines (81 loc) • 2.49 kB
TypeScript
declare enum StoreAction {
Create = "CREATE",
Set = "SET"
}
declare class Store {
db: {
[prop: string]: any;
};
listeners: any[];
set<T>(prop: string, val: T): void;
get(prop: string): any;
listen(listener: any): void;
_onChange(action: StoreAction, prop: string, newVal: any, prevVal: any): void;
}
declare type Point = [x: number, y: number];
declare type Shape = {
points: Point[];
type: ShapeType;
};
declare enum ShapeType {
Rect = "RECT",
Circle = "CIRCLE",
Line = "LINE",
Path = "PATH",
_ellipse = "ELLIPSE",
_polyline = "POLYLINE",
_polygon = "POLYGON"
}
declare type CanvasUpdate = {
action: UpdateAction;
prop: UpdateProp;
val: any;
previousVal: any;
};
declare type UpdateAction = StoreAction;
declare type UpdateProp = CanvasState;
declare enum CanvasState {
Shapes = "shapes",
ShapeType = "shapeType",
IsDrawing = "isDrawing"
}
interface ShapeShopProps {
el: HTMLElement;
defaultShape: ShapeType;
onCanvasUpdate?: (update: CanvasUpdate) => void;
}
declare class Engine {
el: HTMLElement;
store: Store;
onCanvasUpdate?: (update: CanvasUpdate) => void;
_shapes: () => any;
_setShapes: (val: Shape[]) => void;
_isDrawing: () => any;
_setDrawing: (val: boolean) => void;
_shapeType: () => any;
_setShapeType: (shapeType: ShapeType) => void;
constructor(props: ShapeShopProps);
handleMouseDown: (mouseEvent: MouseEvent) => void;
handleMouseMove: (mouseEvent: MouseEvent) => void;
handleMouseUp: (mouseEvent: MouseEvent) => void;
setShapeType: (shapeType: ShapeType) => void;
storeListener: ({ action, prop, val, previousVal }: CanvasUpdate) => void;
destroy: () => void;
}
declare const generatePathData: (path: Point[]) => string;
declare type RectData = {
x: number;
y: number;
width: number;
height: number;
};
declare const generateRectData: (points: [Point, Point]) => RectData;
declare const generateLineData: (points: [Point, Point]) => {
x1: number;
y1: number;
x2: number;
y2: number;
};
declare const svgPath: (points: Point[], command: typeof bezierCommandCalc) => string;
declare const bezierCommandCalc: (point: Point, i: number, a: Point[]) => string;
export { CanvasState, CanvasUpdate, Engine, Point, Shape, Engine as ShapeShop, ShapeType, UpdateAction, UpdateProp, bezierCommandCalc, generateLineData, generatePathData, generateRectData, svgPath };