diff --git a/fabricjs/fabricjs.d.ts b/fabricjs/fabricjs.d.ts
index 31b12db1e..048c915df 100644
--- a/fabricjs/fabricjs.d.ts
+++ b/fabricjs/fabricjs.d.ts
@@ -5,7 +5,7 @@
// Support AMD require
declare module "fabric" {
- export = fabric;
+ export = fabric;
}
declare module fabric {
@@ -14,22 +14,92 @@ declare module fabric {
var isTouchSupported: boolean;
/////////////////////////////////////////////////////////////
- // Functions
+ // farbic 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);
+ // Parse
+ // ----------------------------------------------------------
+ /**
+ * Creates markup containing SVG referenced elements like patterns, gradients etc.
+ * @param {fabric.Canvas} canvas instance of fabric.Canvas
+ */
+ function createSVGRefElementsMarkup(canvas: IStaticCanvas): string;
+ /**
+ * Creates markup containing SVG font faces
+ * @param {Array} objects Array of fabric objects
+ */
+ function createSVGFontFacesMarkup(objects: IObject[]): string;
+ /**
+ * Takes string corresponding to an SVG document, and parses it into a set of fabric objects
+ * @param {String} string
+ * @param {Function} callback
+ * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
+ */
+ function loadSVGFromString(string: string, callback: (results: IObject[], options) => void, reviver?: (el, obj) => void);
+ /**
+ * Takes url corresponding to an SVG document, and parses it into a set of fabric objects. Note that SVG is fetched via XMLHttpRequest, so it needs to conform to SOP (Same Origin Policy)
+ * @param {String} url
+ * @param {Function} callback
+ * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
+ */
function loadSVGFromURL(url, callback: (results: IObject[], options) => void, reviver?: (el, obj) => void);
- function parseAttributes(element, attributes: any[]): any;
+ /**
+ * Returns CSS rules for a given SVG document
+ * @param {SVGDocument} doc SVG document to parse
+ */
+ function getCSSRules(doc: SVGElement): any;
+
function parseElements(elements: any[], callback, options, reviver);
+ /**
+ * Parses "points" attribute, returning an array of values
+ * @param {String} points points attribute string
+ */
function parsePointsAttribute(points: string): any[];
- function parseStyleAttribute(element: SVGElement);
+ /**
+ * Parses "style" attribute, retuning an object with values
+ * @param {SVGElement} element Element to parse
+ */
+ function parseStyleAttribute(element: SVGElement): any;
+ /**
+ * Transforms an array of svg elements to corresponding fabric.* instances
+ * @param {Array} elements Array of elements to parse
+ * @param {Function} callback Being passed an array of fabric instances (transformed from SVG elements)
+ * @param {Object} [options] Options object
+ * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
+ */
+ function parseElements(elements: any[], callback: Function, options?: any, reviver?: Function): void;
+ /**
+ * Returns an object of attributes' name/value, given element and an array of attribute names;
+ * Parses parent "g" nodes recursively upwards.
+ * @param {DOMElement} element Element to parse
+ * @param {Array} attributes Array of attributes to parse
+ */
+ function parseAttributes(elemen: HTMLElement, attributes: string[], svgUid?: string): { [key: string]: string }
+ /**
+ * Parses an SVG document, returning all of the gradient declarations found in it
+ * @param {SVGDocument} doc SVG document to parse
+ */
+ function getGradientDefs(doc: SVGElement): { [key: string]: any };
+ /**
+ * Parses a short font declaration, building adding its properties to a style object
+ * @param {String} value font declaration
+ * @param {Object} oStyle definition
+ */
+ function parseFontDeclaration(value: string, oStyle: any): void;
+ /**
+ * Parses an SVG document, converts it to an array of corresponding fabric.* instances and passes them to a callback
+ * @param {SVGDocument} doc SVG document to parse
+ * @param {Function} callback Callback to call when parsing is finished; It's being passed an array of elements (parsed from a document).
+ * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
+ */
function parseSVGDocument(doc: SVGElement, callback: (results, options) => void, reviver?: (el, obj) => void);
- function parseTransformAttribute(attributeValue: string);
+ /**
+ * Parses "transform" attribute, returning an array of values
+ * @param {String} attributeValue String containing attribute value
+ */
+ function parseTransformAttribute(attributeValue: string): number[];
// fabric Log
// ---------------
@@ -55,6 +125,7 @@ declare module fabric {
var Point: IPointStatic
var Circle: ICircleStatic;
+ var Ellipse: IEllipseStatic;
var Group: IGroupStatic;
var Image: IImageStatic
var Line: ILineStatic;
@@ -64,7 +135,9 @@ declare module fabric {
var Polygon: IPolygonStatic
var Polyline: IPolylineStatic;
var Rect: IRectStatic;
+ var Shadow: IShadowStatic;
var Text: ITextStatic;
+ var IText: IITextStatic;
var Triangle: ITriangleStatic
var util: Util;
@@ -128,40 +201,6 @@ declare module fabric {
offsetY?: number;
}
- interface IGradientOptions {
- /**
- * @param {String} [options.type] Type of gradient 'radial' or 'linear'
- */
- type?: string;
- /**
- * x-coordinate of start point
- */
- x1?: number;
- /**
- * y-coordinate of start point
- */
- y1?: number;
- /**
- * x-coordinate of end point
- */
- x2?: number;
- /**
- * y-coordinate of end point
- */
- y2?: number;
- /**
- * Radius of start point (only for radial gradients)
- */
- r1?: number;
- /**
- * Radius of end point (only for radial gradients)
- */
- r2?: number;
- /**
- * Color stops object eg. {0:string; 1:string;
- */
- colorStops?: any;
- }
interface IToSVGOptions {
/**
@@ -511,11 +550,78 @@ declare module fabric {
prototype: any;
}
-
- interface IGradient {
- initialize(options): any;
+ interface IGradientOptions {
+ /**
+ * @param {String} [options.type] Type of gradient 'radial' or 'linear'
+ */
+ type?: string;
+ /**
+ * x-coordinate of start point
+ */
+ x1?: number;
+ /**
+ * y-coordinate of start point
+ */
+ y1?: number;
+ /**
+ * x-coordinate of end point
+ */
+ x2?: number;
+ /**
+ * y-coordinate of end point
+ */
+ y2?: number;
+ /**
+ * Radius of start point (only for radial gradients)
+ */
+ r1?: number;
+ /**
+ * Radius of end point (only for radial gradients)
+ */
+ r2?: number;
+ /**
+ * Color stops object eg. {0:string; 1:string;
+ */
+ colorStops?: any;
+ }
+ interface IGradient extends IGradientOptions {
+ /**
+ * Adds another colorStop
+ * @param {Object} colorStop Object with offset and color
+ */
+ addColorStop(colorStop: any): IGradient;
+ /**
+ * Returns object representation of a gradient
+ */
toObject(): any;
- toLiveGradient(ctx: CanvasRenderingContext2D): any;
+ /**
+ * Returns SVG representation of an gradient
+ * @param {Object} object Object to create a gradient for
+ * @param {Boolean} normalize Whether coords should be normalized
+ * @return {String} SVG representation of an gradient (linear/radial)
+ */
+ toSVG(object: IObject, normalize?: boolean): string;
+
+ /**
+ * Returns an instance of CanvasGradient
+ * @param {CanvasRenderingContext2D} ctx Context to render on
+ */
+ toLive(ctx: CanvasRenderingContext2D, object?: IPathGroup): CanvasGradient;
+ }
+ interface IGrandientStatic {
+ new (options?: IGradientOptions): IGradient;
+ /**
+ * Returns instance from an SVG element
+ * @param {SVGGradientElement} el SVG gradient element
+ * @param {fabric.Object} instance
+ */
+ fromElement(el: SVGGradientElement, instance: IObject): IGradient;
+ /**
+ * Returns instance from its object representation
+ * @param {Object} obj
+ * @param {Object} [options] Options object
+ */
+ fromObject(obj: any, options: any[]): IGradient;
}
interface IIntersection {
@@ -526,11 +632,13 @@ declare module fabric {
/**
* Appends points to intersection
*/
- appendPoints(point: IPoint);
-
- init(status?: string);
+ appendPoints(points: IPoint[]);
}
interface IIntersectionStatic {
+ /**
+ * Intersection class
+ */
+ new (status?: string);
/**
* Checks if polygon intersects another polygon
*/
@@ -549,6 +657,50 @@ declare module fabric {
intersectPolygonRectangle(points: IPoint[], r1: number, r2: number): IIntersection;
}
+ interface IPatternOptions {
+ /**
+ * Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
+ */
+ repeat: string;
+
+ /**
+ * Pattern horizontal offset from object's left/top corner
+ */
+ offsetX: number;
+
+ /**
+ * Pattern vertical offset from object's left/top corner
+ */
+ offsetY: number;
+ /**
+ * The source for the pattern
+ */
+ source: string|HTMLImageElement;
+ }
+ interface IPattern extends IPatternOptions {
+ new (options?: IPatternOptions): IPattern;
+
+ initialise(options?: IPatternOptions): IPattern;
+ /**
+ * Returns an instance of CanvasPattern
+ */
+ toLive(ctx: CanvasRenderingContext2D): IPattern;
+
+ /**
+ * Returns object representation of a pattern
+ */
+ toObject(): any;
+ /**
+ * Returns SVG representation of a pattern
+ * @param {fabric.Object} object
+ */
+ toSVG(object: IObject): string;
+ }
+ interface IPatternStatic {
+ new (options?: IPatternOptions): IPattern;
+ prototype: any;
+ }
+
interface IPoint {
x: number;
y: number;
@@ -784,6 +936,10 @@ declare module fabric {
*/
reOffsetsAndBlur: RegExp
}
+ interface IShadowStatic {
+ new (options?: IShadowOptions): IShadow
+ reOffsetsAndBlur: RegExp;
+ }
///////////////////////////////////////////////////////////////////////////////
// Canvas Interfaces
@@ -798,7 +954,6 @@ declare module fabric {
*/
height: number;
}
-
interface ICanvasDimensionsOptions {
/**
* Set the given dimensions only as canvas backstore dimensions
@@ -810,6 +965,83 @@ declare module fabric {
cssOnly?: boolean;
}
+ interface IStaticCanvasOptions {
+ /**
+ * Indicates whether the browser can be scrolled when using a touchscreen and dragging on the canvas
+ */
+ allowTouchScrolling?: boolean;
+ /**
+ * Indicates whether this canvas will use image smoothing, this is on by default in browsers
+ */
+ imageSmoothingEnabled?: boolean;
+
+ /**
+ * Indicates whether objects should remain in current stack position when selected. When false objects are brought to top and rendered as part of the selection group
+ */
+ preserveObjectStacking?: boolean;
+
+ /**
+ * The transformation (in the format of Canvas transform) which focuses the viewport
+ */
+ viewportTransform?: number[];
+
+
+
+ freeDrawingColor?: string;
+ freeDrawingLineWidth?: number;
+
+ /**
+ * Background color of canvas instance.
+ * Should be set via setBackgroundColor
+ */
+ backgroundColor?: string | IPattern;
+ /**
+ * Background image of canvas instance.
+ * Should be set via setBackgroundImage
+ * Backwards incompatibility note: The "backgroundImageOpacity" and "backgroundImageStretch" properties are deprecated since 1.3.9.
+ */
+ backgroundImage?: IImage;
+ backgroundImageOpacity?: number;
+ backgroundImageStretch?: number;
+ /**
+ * Function that determines clipping of entire canvas area
+ * Being passed context as first argument. See clipping canvas area
+ */
+ clipTo?: (context: CanvasRenderingContext2D) => void;
+
+ /**
+ * Indicates whether object controls (borders/controls) are rendered above overlay image
+ */
+ controlsAboveOverlay?: boolean;
+
+ /**
+ * Indicates whether toObject/toDatalessObject should include default values
+ */
+ includeDefaultValues?: boolean;
+ /**
+ * Overlay color of canvas instance.
+ * Should be set via setOverlayColor
+ */
+ overlayColor?: string | IPattern;
+ /**
+ * Overlay image of canvas instance.
+ * Should be set via setOverlayImage
+ * Backwards incompatibility note: The "overlayImageLeft" and "overlayImageTop" properties are deprecated since 1.3.9.
+ */
+ overlayImage?: IImage;
+ overlayImageLeft?: number;
+ overlayImageTop?: number;
+ /**
+ * Indicates whether add, insertAt and remove should also re-render canvas.
+ * Disabling this option could give a great performance boost when adding/removing a lot of objects to/from canvas at once
+ * (followed by a manual rendering after addition/deletion)
+ */
+ renderOnAddRemove?: boolean;
+ /**
+ * Indicates whether objects' state should be saved
+ */
+ stateful?: boolean;
+ }
interface IStaticCanvas extends IObservable, IStaticCanvasOptions, ICollection, ICanvasAnimation {
/**
* Calculates canvas element offset relative to the document
@@ -1085,16 +1317,127 @@ declare module fabric {
interface IStaticCanvasStatic {
/**
* Constructor
- * @param {HTMLElement | String} element