diff --git a/fabricjs/fabricjs.d.ts b/fabricjs/fabricjs.d.ts
index 2a13cac4e..31b12db1e 100644
--- a/fabricjs/fabricjs.d.ts
+++ b/fabricjs/fabricjs.d.ts
@@ -1,39 +1,79 @@
-// Type definitions for FabricJS
+// Type definitions for FabricJS v1.5.0
// Project: http://fabricjs.com/
-// Definitions by: Oliver Klemencic
+// Definitions by: Oliver Klemencic , edited by Joseph Livecchi
// Definitions: https://github.com/borisyankov/DefinitelyTyped
+// Support AMD require
+declare module "fabric" {
+ export = fabric;
+}
+
declare module fabric {
+ var isLikelyNode: boolean;
+ var isTouchSupported: boolean;
+
+ /////////////////////////////////////////////////////////////
+ // Functions
+ /////////////////////////////////////////////////////////////
+
function createCanvasForNode(width: number, height: number): ICanvas;
function getCSSRules(doc: SVGElement);
function getGradientDefs(doc: SVGElement);
+
+ // Parser
function loadSVGFromString(text: string, callback: (results: IObject[], options) => void, reviver?: (el, obj) => void);
function loadSVGFromURL(url, callback: (results: IObject[], options) => void, reviver?: (el, obj) => void);
-
- /**
- * Wrapper around `console.log` (when available)
- */
- function log(values);
function parseAttributes(element, attributes: any[]): any;
function parseElements(elements: any[], callback, options, reviver);
function parsePointsAttribute(points: string): any[];
function parseStyleAttribute(element: SVGElement);
function parseSVGDocument(doc: SVGElement, callback: (results, options) => void, reviver?: (el, obj) => void);
function parseTransformAttribute(attributeValue: string);
+
+ // fabric Log
+ // ---------------
+ /**
+ * Wrapper around `console.log` (when available)
+ */
+ function log(values);
/**
* Wrapper around `console.warn` (when available)
*/
function warn(values);
- var isLikelyNode: boolean;
- var isTouchSupported: boolean;
+
+ ////////////////////////////////////////////////////
+ // Classes
+ ////////////////////////////////////////////////////
+ var Canvas: ICanvasStatic;
+ var StaticCanvas: IStaticCanvasStatic;
+
+ var Color: IColorStatic;
+ var Pattern: IPatternStatic;
+ var Intersection: IIntersectionStatic;
+ var Point: IPointStatic
+
+ var Circle: ICircleStatic;
+ var Group: IGroupStatic;
+ var Image: IImageStatic
+ var Line: ILineStatic;
+ var Object: IObjectStatic;
+ var Path: IPathStatic;
+ var PathGroup: IPathGroupStatic
+ var Polygon: IPolygonStatic
+ var Polyline: IPolylineStatic;
+ var Rect: IRectStatic;
+ var Text: ITextStatic;
+ var Triangle: ITriangleStatic
+
+ var util: Util;
///////////////////////////////////////////////////////////////////////////////
// Data Object Interfaces - These intrface are not specific part of fabric,
// They are just helpful for for defining function paramters
//////////////////////////////////////////////////////////////////////////////
- export interface IDataURLOptions {
+ interface IDataURLOptions {
/**
* The format of the output image. Either "jpeg" or "png"
*/
@@ -63,13 +103,13 @@ declare module fabric {
*/
height?: number;
}
-
- export interface IEvent {
+
+ interface IEvent {
e: Event;
- target?: fabric.IObject;
+ target?: IObject;
}
- export interface IFillOptions {
+ interface IFillOptions {
/**
* options.source Pattern source
*/
@@ -88,7 +128,7 @@ declare module fabric {
offsetY?: number;
}
- export interface IGradientOptions {
+ interface IGradientOptions {
/**
* @param {String} [options.type] Type of gradient 'radial' or 'linear'
*/
@@ -123,7 +163,7 @@ declare module fabric {
colorStops?: any;
}
- export interface IToSVGOptions {
+ interface IToSVGOptions {
/**
* If true xml tag is not included
*/
@@ -138,7 +178,7 @@ declare module fabric {
encoding: string;
}
- export interface IViewBox {
+ interface IViewBox {
/**
* x-cooridnate of viewbox
*/
@@ -155,42 +195,20 @@ declare module fabric {
height: number;
}
- export interface IFilter {
+ interface IFilter {
new (): IFilter;
new (options: any): IFilter;
}
- export interface IEventList {
+ interface IEventList {
[index: string]: (e: Event) => void;
}
- export interface IAnimationOptions {
- /**
- * Allows to specify starting value of animatable property (if we don't want current value to be used).
- */
- from?: string|number;
- /**
- * Defaults to 500 (ms). Can be used to change duration of an animation.
- */
- duration?: number;
- /**
- * Callback that's invoked during the animation.
- */
- onChange?: Function;
- /**
- * Callback that's invoked at the end of the animation.
- */
- onComplete?: Function
- /**
- * Easing function. Default: fabric.util.ease.easeInSine
- */
- easing?: Function;
- }
///////////////////////////////////////////////////////////////////////////////
// Mixins Interfaces
//////////////////////////////////////////////////////////////////////////////
- export interface ICollection {
+ interface ICollection {
/**
* Adds objects to collection, then renders canvas (if `renderOnAddRemove` is not `false`)
* Objects should be instances of (or inherit from) fabric.Object
@@ -266,8 +284,8 @@ declare module fabric {
*/
complexity(): number;
}
-
- export interface IObservable {
+
+ interface IObservable {
/**
* Observes specified event
* @deprecated `observe` deprecated since 0.8.34 (use `on` instead)
@@ -292,12 +310,88 @@ declare module fabric {
off(eventName: string|any, handler: (e) => any): T;
}
+ // animation mixin
+ // ----------------------------------------------------
+ interface ICanvasAnimation {
+ FX_DURATION: number;
+ /**
+ * Centers object horizontally with animation.
+ * @param {fabric.Object} object Object to center
+ * @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
+ * @param {Function} [callbacks.onComplete] Invoked on completion
+ * @param {Function} [callbacks.onChange] Invoked on every step of animation
+ */
+ fxCenterObjectH(object: IObject, callbacks?: { onComplete: Function; onChange: Function; }): T;
+ /**
+ * Centers object vertically with animation.
+ * @param {fabric.Object} object Object to center
+ * @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
+ * @param {Function} [callbacks.onComplete] Invoked on completion
+ * @param {Function} [callbacks.onChange] Invoked on every step of animation
+ */
+ fxCenterObjectV(object: IObject, callbacks?: { onComplete: Function; onChange: Function; }): T;
+
+ /**
+ * Same as `fabric.Canvas#remove` but animated
+ * @param {fabric.Object} object Object to remove
+ * @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties
+ * @param {Function} [callbacks.onComplete] Invoked on completion
+ * @param {Function} [callbacks.onChange] Invoked on every step of animation
+ * @return {fabric.Canvas} thisArg
+ * @chainable
+ */
+ fxRemove(object: IObject, callbacks?: { onComplete: Function; onChange: Function; }): T;
+ }
+ interface IObjectAnimation {
+ /**
+ * Animates object's properties
+ * object.animate('left', ..., {duration: ...});
+ * @param property Property to animate
+ * @param value Value to animate property
+ * @param options The animation options
+ */
+ animate(property: string, value: number | string, options?: IAnimationOptions): IObject;
+ /**
+ * Animates object's properties
+ * object.animate({ left: ..., top: ... }, { duration: ... });
+ * @param properties Properties to animate
+ * @param value Options object
+ */
+ animate(properties: any, options?: IAnimationOptions): IObject;
+ }
+ interface IAnimationOptions {
+ /**
+ * Allows to specify starting value of animatable property (if we don't want current value to be used).
+ */
+ from?: string|number;
+ /**
+ * Defaults to 500 (ms). Can be used to change duration of an animation.
+ */
+ duration?: number;
+ /**
+ * Callback; invoked on every value change
+ */
+ onChange?: Function;
+ /**
+ * Callback; invoked when value change is completed
+ */
+ onComplete?: Function
+ /**
+ * Easing function. Default: fabric.util.ease.easeInSine
+ */
+ easing?: Function;
+ /**
+ * Value to modify the property by, default: end - start
+ */
+ by?: number;
+ }
+
///////////////////////////////////////////////////////////////////////////////
// General Fabric Interfaces
//////////////////////////////////////////////////////////////////////////////
- export interface IColor {
+ interface IColor {
/**
* Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])
*/
@@ -360,24 +454,83 @@ declare module fabric {
*/
overlayWith(otherColor: string|IColor): IColor;
}
+ interface IColorStatic {
+ /**
+ * Color class
+ * The purpose of Color is to abstract and encapsulate common color operations;
+ * @param {String} color optional in hex or rgb(a) format
+ */
+ new (color?: string): IColor;
- export interface IGradient {
+ /**
+ * Returns new color object, when given a color in RGB format
+ * @param {String} color Color value ex: rgb(0-255,0-255,0-255)
+ */
+ fromRgb(color): IColor
+ /**
+ * Returns new color object, when given a color in RGBA format
+ * @param {String} color Color value ex: rgb(0-255,0-255,0-255)
+ */
+ fromRgba(color): IColor
+ /**
+ * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format
+ * @param {String} color Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)
+ */
+ sourceFromRgb(color: string): number[];
+ /**
+ * Returns new color object, when given a color in HSL format
+ * @param {String} color Color value ex: hsl(0-260,0%-100%,0%-100%)
+ */
+ fromHsl(color: string): IColor
+ /**
+ * Returns new color object, when given a color in HSLA format
+ * @param {String} color Color value ex: hsl(0-260,0%-100%,0%-100%)
+ */
+ fromHsla(color: string): IColor
+ /**
+ * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HSL or HSLA format.
+ * @param {String} color Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)
+ */
+ sourceFromHsl(color: string): number[];
+ /**
+ * Returns new color object, when given a color in HEX format
+ * @param {String} color Color value ex: FF5555
+ */
+ fromHex(color: string): IColor
+
+ /**
+ * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format
+ * @param {String} color ex: FF5555
+ */
+ sourceFromHex(color: string): number[];
+ /**
+ * Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5])
+ * @param {Array} source
+ */
+ fromSource(source: number[]): IColor;
+ prototype: any;
+ }
+
+
+ interface IGradient {
initialize(options): any;
toObject(): any;
toLiveGradient(ctx: CanvasRenderingContext2D): any;
}
-
- export interface IIntersection {
+
+ interface IIntersection {
/**
* Appends a point to intersection
*/
- appendPoint(point: fabric.IPoint);
+ appendPoint(point: IPoint);
/**
* Appends points to intersection
*/
- appendPoints(point: fabric.IPoint);
+ appendPoints(point: IPoint);
init(status?: string);
+ }
+ interface IIntersectionStatic {
/**
* Checks if polygon intersects another polygon
*/
@@ -395,8 +548,8 @@ declare module fabric {
*/
intersectPolygonRectangle(points: IPoint[], r1: number, r2: number): IIntersection;
}
-
- export interface IPoint {
+
+ interface IPoint {
x: number;
y: number;
/**
@@ -579,8 +732,12 @@ declare module fabric {
*/
swap(that: IPoint): IPoint;
}
-
- export interface IShadowOptions {
+ interface IPointStatic {
+ new (x, y): IPoint;
+ prototype: any;
+ }
+
+ interface IShadowOptions {
/**
* Whether the shadow should affect stroke operations
*/
@@ -606,7 +763,7 @@ declare module fabric {
*/
offsetY: number;
}
- export interface IShadow extends IShadowOptions {
+ interface IShadow extends IShadowOptions {
initialize(options?: IShadowOptions|string): IShadow;
/**
* Returns object representation of a shadow
@@ -631,7 +788,7 @@ declare module fabric {
///////////////////////////////////////////////////////////////////////////////
// Canvas Interfaces
//////////////////////////////////////////////////////////////////////////////
- export interface ICanvasDimensions {
+ interface ICanvasDimensions {
/**
* Width of canvas element
*/
@@ -642,7 +799,7 @@ declare module fabric {
height: number;
}
- export interface ICanvasDimensionsOptions {
+ interface ICanvasDimensionsOptions {
/**
* Set the given dimensions only as canvas backstore dimensions
*/
@@ -653,7 +810,7 @@ declare module fabric {
cssOnly?: boolean;
}
- export interface IStaticCanvas extends IObservable, IStaticCanvasOptions, ICollection {
+ interface IStaticCanvas extends IObservable, IStaticCanvasOptions, ICollection, ICanvasAnimation {
/**
* Calculates canvas element offset relative to the document
* This method is also attached as "resize" event handler of window
@@ -925,8 +1082,20 @@ declare module fabric {
onBeforeScaleRotate(target: IObject);
toGrayscale(propertiesToInclude: any[]): string;
}
+ interface IStaticCanvasStatic {
+ /**
+ * Constructor
+ * @param {HTMLElement | String} element