UNPKG

213 kBTypeScriptView Raw
1// This module does not really exist.
2// This is just to get `export as namespace fabric;` to work and to be re-exportable from `index.d.ts`.
3
4export as namespace fabric;
5
6export const isLikelyNode: boolean;
7export const isTouchSupported: boolean;
8export const version: string;
9export const iMatrix: number[];
10export let textureSize: number;
11export let copiedText: string;
12export let copiedTextStyle: any[];
13export let charWidthsCache: {
14 [key: string]: { // example: montserrat
15 [key: string]: { // example: normal_normal
16 [key: string]: number; // example: A: 286
17 }
18 }
19};
20
21/////////////////////////////////////////////////////////////
22// fabric Functions
23/////////////////////////////////////////////////////////////
24
25export function createCanvasForNode(width: number, height: number): Canvas;
26
27// Parse
28// ----------------------------------------------------------
29/**
30 * Creates markup containing SVG referenced elements like patterns, gradients etc.
31 * @param canvas instance of fabric.Canvas
32 */
33export function createSVGRefElementsMarkup(canvas: StaticCanvas): string;
34/**
35 * Creates markup containing SVG font faces
36 * @param objects Array of fabric objects
37 */
38export function createSVGFontFacesMarkup(objects: Object[]): string;
39/**
40 * Takes string corresponding to an SVG document, and parses it into a set of fabric objects
41 * @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
42 */
43export function loadSVGFromString(
44 string: string,
45 callback: (results: Object[], options: any) => void,
46 reviver?: Function,
47): void;
48/**
49 * Takes url corresponding to an SVG document, and parses it into a set of fabric objects.
50 * Note that SVG is fetched via XMLHttpRequest, so it needs to conform to SOP (Same Origin Policy)
51 * @param {String} url URL to get a SVG from
52 * @param {Function} callback Callback is invoked when svg has been loaded
53 * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
54 * @param {Object} [options] options for crossOrigin
55 * @param {String} [options.crossOrigin] crossOrigin settings
56 *
57 */
58export function loadSVGFromURL(
59 url: string,
60 callback: (results: Object[], options: any) => void,
61 reviver?: Function,
62 options?: { crossOrigin?: string },
63): void;
64/**
65 * Returns CSS rules for a given SVG document
66 * @param doc SVG document to parse
67 */
68export function getCSSRules(doc: SVGElement): any;
69
70export function parseElements(elements: any[], callback: Function, options: any, reviver?: Function): void;
71/**
72 * Parses "points" attribute, returning an array of values
73 * @param points points attribute string
74 */
75export function parsePointsAttribute(points: string): any[];
76/**
77 * Parses "style" attribute, retuning an object with values
78 * @param element Element to parse
79 */
80export function parseStyleAttribute(element: SVGElement): any;
81/**
82 * Transforms an array of svg elements to corresponding fabric.* instances
83 * @param elements Array of elements to parse
84 * @param callback Being passed an array of fabric instances (transformed from SVG elements)
85 * @param [options] Options object
86 * @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
87 */
88export function parseElements(elements: SVGElement[], callback: Function, options?: any, reviver?: Function): void;
89/**
90 * Returns an object of attributes' name/value, given element and an array of attribute names;
91 * Parses parent "g" nodes recursively upwards.
92 * @param element Element to parse
93 * @param attributes Array of attributes to parse
94 */
95export function parseAttributes(element: HTMLElement, attributes: string[], svgUid?: string): { [key: string]: string };
96/**
97 * Parses an SVG document, returning all of the gradient declarations found in it
98 * @param doc SVG document to parse
99 */
100export function getGradientDefs(doc: SVGElement): { [key: string]: any };
101/**
102 * Parses a short font declaration, building adding its properties to a style object
103 * @param value font declaration
104 * @param oStyle definition
105 */
106export function parseFontDeclaration(value: string, oStyle: any): void;
107/**
108 * Parses an SVG document, converts it to an array of corresponding fabric.* instances and passes them to a callback
109 * @param doc SVG document to parse
110 * @param callback Callback to call when parsing is finished; It's being passed an array of elements (parsed from a document).
111 * @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
112 */
113export function parseSVGDocument(
114 doc: SVGElement,
115 callback: (results: Object[], options: any) => void,
116 reviver?: Function,
117): void;
118/**
119 * Parses "transform" attribute, returning an array of values
120 * @param attributeValue String containing attribute value
121 */
122export function parseTransformAttribute(attributeValue: string): number[];
123
124// fabric Log
125// ---------------
126/**
127 * Wrapper around `console.log` (when available)
128 */
129export function log(...values: any[]): void;
130/**
131 * Wrapper around `console.warn` (when available)
132 */
133export function warn(...values: any[]): void;
134
135///////////////////////////////////////////////////////////////////////////////
136// Data Object Interfaces - These interface are not specific part of fabric,
137// They are just helpful for for defining function parameters
138//////////////////////////////////////////////////////////////////////////////
139interface IDataURLOptions {
140 /**
141 * The format of the output image. Either "jpeg" or "png"
142 */
143 format?: string;
144 /**
145 * Quality level (0..1). Only used for jpeg
146 */
147 quality?: number;
148 /**
149 * Multiplier to scale by
150 */
151 multiplier?: number;
152 /**
153 * Cropping left offset. Introduced in v1.2.14
154 */
155 left?: number;
156 /**
157 * Cropping top offset. Introduced in v1.2.14
158 */
159 top?: number;
160 /**
161 * Cropping width. Introduced in v1.2.14
162 */
163 width?: number;
164 /**
165 * Cropping height. Introduced in v1.2.14
166 */
167 height?: number;
168 enableRetinaScaling?: boolean;
169 withoutTransform?: boolean;
170 withoutShadow?: boolean;
171}
172
173interface IEvent {
174 e: Event;
175 target?: Object;
176 subTargets?: Object[];
177 button?: number;
178 isClick?: boolean;
179 pointer?: Point;
180 absolutePointer?: Point;
181 transform?: { corner: string; original: Object; originX: string; originY: string; width: number };
182}
183
184interface IFillOptions {
185 /**
186 * options.source Pattern source
187 */
188 source: string | HTMLImageElement;
189 /**
190 * Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
191 */
192 repeat?: string;
193 /**
194 * Pattern horizontal offset from object's left/top corner
195 */
196 offsetX?: number;
197 /**
198 * Pattern vertical offset from object's left/top corner
199 */
200 offsetY?: number;
201}
202
203interface IToSVGOptions {
204 /**
205 * If true xml tag is not included
206 */
207 suppressPreamble?: boolean;
208 /**
209 * SVG viewbox object
210 */
211 viewBox?: IViewBox;
212 /**
213 * Encoding of SVG output
214 */
215 encoding?: string;
216 /**
217 * desired width of svg with or without units
218 */
219 width?: number | string;
220 /**
221 * desired height of svg with or without units
222 */
223 height?: number | string;
224}
225
226interface IViewBox {
227 /**
228 * x-cooridnate of viewbox
229 */
230 x: number;
231 /**
232 * y-coordinate of viewbox
233 */
234 y: number;
235 /**
236 * Width of viewbox
237 */
238 width: number;
239 /**
240 * Height of viewbox
241 */
242 height: number;
243}
244
245///////////////////////////////////////////////////////////////////////////////
246// Mixins Interfaces
247//////////////////////////////////////////////////////////////////////////////
248interface ICollection<T> {
249 _objects: Object[];
250
251 /**
252 * Adds objects to collection, then renders canvas (if `renderOnAddRemove` is not `false`)
253 * Objects should be instances of (or inherit from) fabric.Object
254 * @param object Zero or more fabric instances
255 */
256 add(...object: Object[]): T;
257
258 /**
259 * Inserts an object into collection at specified index, then renders canvas (if `renderOnAddRemove` is not `false`)
260 * An object should be an instance of (or inherit from) fabric.Object
261 * @param object Object to insert
262 * @param index Index to insert object at
263 * @param nonSplicing When `true`, no splicing (shifting) of objects occurs
264 * @return thisArg
265 * @chainable
266 */
267 insertAt(object: Object, index: number, nonSplicing: boolean): T;
268
269 /**
270 * Removes objects from a collection, then renders canvas (if `renderOnAddRemove` is not `false`)
271 * @param object Zero or more fabric instances
272 * @return thisArg
273 * @chainable
274 */
275 remove(...object: Object[]): T;
276
277 /**
278 * Executes given function for each object in this group
279 * @param context Context (aka thisObject)
280 * @return thisArg
281 */
282 forEachObject(callback: (element: Object, index: number, array: Object[]) => void, context?: any): T;
283
284 /**
285 * Returns an array of children objects of this instance
286 * Type parameter introduced in 1.3.10
287 * @param [type] When specified, only objects of this type are returned
288 */
289 getObjects(type?: string): Object[];
290
291 /**
292 * Returns object at specified index
293 * @return thisArg
294 */
295 item(index: number): T;
296
297 /**
298 * Returns true if collection contains no objects
299 * @return true if collection is empty
300 */
301 isEmpty(): boolean;
302
303 /**
304 * Returns a size of a collection (i.e: length of an array containing its objects)
305 * @return Collection size
306 */
307 size(): number;
308
309 /**
310 * Returns true if collection contains an object
311 * @param object Object to check against
312 * @return `true` if collection contains an object
313 */
314 contains(object: Object): boolean;
315
316 /**
317 * Returns number representation of a collection complexity
318 * @return complexity
319 */
320 complexity(): number;
321}
322
323interface IObservable<T> {
324 /**
325 * Observes specified event
326 * @param eventName Event name (eg. 'after:render')
327 * @param handler Function that receives a notification when an event of the specified type occurs
328 */
329 on(eventName: string, handler: (e: IEvent) => void): T;
330
331 /**
332 * Stops event observing for a particular event handler. Calling this method
333 * without arguments removes all handlers for all events
334 * @param eventName Event name (eg. 'after:render') or object with key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})
335 * @param handler Function to be deleted from EventListeners
336 */
337 off(eventName?: string | any, handler?: (e: IEvent) => void): T;
338
339 /**
340 * Fires event with an optional options object
341 * @memberOf fabric.Observable
342 * @param {String} eventName Event name to fire
343 * @param {Object} [options] Options object
344 * @return {Self} thisArg
345 * @chainable
346 */
347 fire(eventName: string, options?: any): T;
348}
349
350interface Callbacks {
351 /** Invoked on completion */
352 onComplete?: Function;
353 /** Invoked on every step of animation */
354 onChange?: Function;
355}
356
357// animation mixin
358// ----------------------------------------------------
359interface ICanvasAnimation<T> {
360 FX_DURATION: number;
361 /**
362 * Centers object horizontally with animation.
363 * @param object Object to center
364 */
365 fxCenterObjectH(object: Object, callbacks?: Callbacks): T;
366
367 /**
368 * Centers object vertically with animation.
369 * @param object Object to center
370 */
371 fxCenterObjectV(object: Object, callbacks?: Callbacks): T;
372
373 /**
374 * Same as `fabric.Canvas#remove` but animated
375 * @param object Object to remove
376 * @chainable
377 */
378 fxRemove(object: Object): T;
379
380 /**
381 * Same as {@link fabric.Canvas.prototype.straightenObject}, but animated
382 * @param {fabric.Object} object Object to straighten
383 * @return {fabric.Canvas} thisArg
384 * @chainable
385 */
386 fxStraightenObject(object: Object): T;
387}
388interface IObjectAnimation<T> {
389 /**
390 * Animates object's properties
391 * object.animate('left', ..., {duration: ...});
392 * @param property Property to animate
393 * @param value Value to animate property
394 * @param options The animation options
395 */
396 animate(property: string, value: number | string, options?: IAnimationOptions): Object;
397 /**
398 * Animates object's properties
399 * object.animate({ left: ..., top: ... }, { duration: ... });
400 * @param properties Properties to animate with values to animate to
401 * @param options The animation options
402 */
403 animate(properties: { [key: string]: number | string }, options?: IAnimationOptions): Object;
404}
405interface IAnimationOptions {
406 /**
407 * Allows to specify starting value of animatable property (if we don't want current value to be used).
408 */
409 from?: string | number;
410 /**
411 * Defaults to 500 (ms). Can be used to change duration of an animation.
412 */
413 duration?: number;
414 /**
415 * Callback; invoked on every value change
416 */
417 onChange?: Function;
418 /**
419 * Callback; invoked when value change is completed
420 */
421 onComplete?: Function;
422
423 /**
424 * Easing function. Default: fabric.util.ease.easeInSine
425 */
426 easing?: Function;
427 /**
428 * Value to modify the property by, default: end - start
429 */
430 by?: number;
431}
432
433///////////////////////////////////////////////////////////////////////////////
434// General Fabric Interfaces
435//////////////////////////////////////////////////////////////////////////////
436export class Color {
437 /**
438 * Color class
439 * The purpose of Color is to abstract and encapsulate common color operations;
440 * @param color optional in hex or rgb(a) format
441 */
442 constructor(color?: string);
443
444 /**
445 * Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])
446 */
447 getSource(): number[];
448
449 /**
450 * Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])
451 */
452 setSource(source: number[]): void;
453
454 /**
455 * Returns color represenation in RGB format ex: rgb(0-255,0-255,0-255)
456 */
457 toRgb(): string;
458
459 /**
460 * Returns color represenation in RGBA format ex: rgba(0-255,0-255,0-255,0-1)
461 */
462 toRgba(): string;
463
464 /**
465 * Returns color represenation in HSL format ex: hsl(0-360,0%-100%,0%-100%)
466 */
467 toHsl(): string;
468
469 /**
470 * Returns color represenation in HSLA format ex: hsla(0-360,0%-100%,0%-100%,0-1)
471 */
472 toHsla(): string;
473
474 /**
475 * Returns color represenation in HEX format ex: FF5555
476 */
477 toHex(): string;
478
479 /**
480 * Returns color representation in HEXA format
481 * @return {String} ex: FF5555CC
482 */
483 toHexa(): string;
484
485 /**
486 * Gets value of alpha channel for this color
487 */
488 getAlpha(): number;
489
490 /**
491 * Sets value of alpha channel for this color
492 * @param alpha Alpha value 0-1
493 */
494 setAlpha(alpha: number): void;
495
496 /**
497 * Transforms color to its grayscale representation
498 */
499 toGrayscale(): Color;
500
501 /**
502 * Transforms color to its black and white representation
503 */
504 toBlackWhite(threshold: number): Color;
505 /**
506 * Overlays color with another color
507 */
508 overlayWith(otherColor: string | Color): Color;
509
510 /**
511 * Returns new color object, when given a color in RGB format
512 * @param color Color value ex: rgb(0-255,0-255,0-255)
513 */
514 static fromRgb(color: string): Color;
515 /**
516 * Returns new color object, when given a color in RGBA format
517 * @param color Color value ex: rgb(0-255,0-255,0-255)
518 */
519 static fromRgba(color: string): Color;
520 /**
521 * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format
522 * @param color Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)
523 */
524 static sourceFromRgb(color: string): number[];
525 /**
526 * Returns new color object, when given a color in HSL format
527 * @param color Color value ex: hsl(0-260,0%-100%,0%-100%)
528 */
529 static fromHsl(color: string): Color;
530 /**
531 * Returns new color object, when given a color in HSLA format
532 * @param color Color value ex: hsl(0-260,0%-100%,0%-100%)
533 */
534 static fromHsla(color: string): Color;
535 /**
536 * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HSL or HSLA format.
537 * @param color Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)
538 */
539 static sourceFromHsl(color: string): number[];
540 /**
541 * Returns new color object, when given a color in HEX format
542 * @param color Color value ex: FF5555
543 */
544 static fromHex(color: string): Color;
545
546 /**
547 * Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format
548 * @param color ex: FF5555
549 */
550 static sourceFromHex(color: string): number[];
551 /**
552 * Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5])
553 */
554 static fromSource(source: number[]): Color;
555 /**
556 * Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff)
557 * @static
558 * @field
559 * @memberOf fabric.Color
560 */
561 static reHex: RegExp;
562 /**
563 * Regex matching color in HSL or HSLA formats (ex: hsl(200, 80%, 10%), hsla(300, 50%, 80%, 0.5), hsla( 300 , 50% , 80% , 0.5 ))
564 * @static
565 * @field
566 * @memberOf fabric.Color
567 */
568 static reHSLa: RegExp;
569 /**
570 * Regex matching color in RGB or RGBA formats (ex: rgb(0, 0, 0), rgba(255, 100, 10, 0.5), rgba( 255 , 100 , 10 , 0.5 ), rgb(1,1,1), rgba(100%, 60%, 10%, 0.5))
571 * @static
572 * @field
573 * @memberOf fabric.Color
574 */
575 static reRGBa: RegExp;
576}
577
578interface IGradientOptionsCoords {
579 x1?: number;
580 y1?: number;
581 x2?: number;
582 y2?: number;
583 r1?: number;
584 r2?: number;
585}
586
587type IGradientOptionsColorStops = Array<{
588 offset: number;
589 color: string;
590}>;
591
592interface IGradientOptions {
593 /**
594 * Horizontal offset for aligning gradients coming from SVG when outside pathgroups
595 * @type Number
596 */
597 offsetX?: number;
598 /**
599 * Vertical offset for aligning gradients coming from SVG when outside pathgroups
600 * @type Number
601 */
602 offsetY?: number;
603 type?: string;
604 coords?: IGradientOptionsCoords;
605 /**
606 * Color stops object eg. {0:string; 1:string;
607 */
608 colorStops?: IGradientOptionsColorStops;
609 gradientTransform?: any;
610}
611
612interface OGradientOptions {
613 type?: string;
614 x1?: number;
615 y1?: number;
616 x2?: number;
617 y2?: number;
618 r1?: number;
619 r2?: number;
620 colorStops?: {
621 [key: string]: string;
622 };
623 gradientTransform?: any;
624}
625
626export interface Gradient extends IGradientOptions {}
627export class Gradient {
628 /**
629 * Constructor
630 * @param {Object} options Options object with type, coords, gradientUnits and colorStops
631 * @param {Object} [options.type] gradient type linear or radial
632 * @param {Object} [options.gradientUnits] gradient units
633 * @param {Object} [options.offsetX] SVG import compatibility
634 * @param {Object} [options.offsetY] SVG import compatibility
635 * @param {Object[]} options.colorStops contains the colorstops.
636 * @param {Object} options.coords contains the coords of the gradient
637 * @param {Number} [options.coords.x1] X coordiante of the first point for linear or of the focal point for radial
638 * @param {Number} [options.coords.y1] Y coordiante of the first point for linear or of the focal point for radial
639 * @param {Number} [options.coords.x2] X coordiante of the second point for linear or of the center point for radial
640 * @param {Number} [options.coords.y2] Y coordiante of the second point for linear or of the center point for radial
641 * @param {Number} [options.coords.r1] only for radial gradient, radius of the inner circle
642 * @param {Number} [options.coords.r2] only for radial gradient, radius of the external circle
643 * @return {fabric.Gradient} thisArg
644 */
645 constructor(options: {
646 type?: string;
647 gradientUnits?: any;
648 offsetX?: any;
649 offsetY?: any;
650 colorStops?: IGradientOptionsColorStops;
651 coords?: IGradientOptionsCoords;
652 });
653 /**
654 * Adds another colorStop
655 * @param colorStop Object with offset and color
656 */
657 addColorStop(colorStop: any): Gradient;
658 /**
659 * Returns object representation of a gradient
660 */
661 toObject(propertiesToInclude?: any): any;
662 /**
663 * Returns SVG representation of an gradient
664 * @param {Object} object Object to create a gradient for
665 * @return {String} SVG representation of an gradient (linear/radial)
666 */
667 toSVG(object: any): string;
668 /**
669 * Returns an instance of CanvasGradient
670 * @param ctx Context to render on
671 */
672 toLive(ctx: CanvasRenderingContext2D): CanvasGradient;
673 /**
674 * Returns {@link fabric.Gradient} instance from an SVG element
675 * @static
676 * @memberOf fabric.Gradient
677 * @param {SVGGradientElement} el SVG gradient element
678 * @param {fabric.Object} instance
679 * @return {fabric.Gradient} Gradient instance
680 * @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement
681 * @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement
682 */
683 static fromElement(el: SVGGradientElement, instance: Object): Gradient;
684}
685export class Intersection {
686 constructor(status?: string);
687 /**
688 * Appends a point to intersection
689 */
690 appendPoint(point: Point): Intersection;
691 /**
692 * Appends points to intersection
693 */
694 appendPoints(points: Point[]): Intersection;
695 /**
696 * Checks if one line intersects another
697 */
698 static intersectLineLine(a1: Point, a2: Point, b1: Point, b2: Point): Intersection;
699 /**
700 * Checks if line intersects polygon
701 */
702 static intersectLinePolygon(a1: Point, a2: Point, points: Point[]): Intersection;
703 /**
704 * Checks if polygon intersects another polygon
705 */
706 static intersectPolygonPolygon(points1: Point[], points2: Point[]): Intersection;
707 /**
708 * Checks if polygon intersects rectangle
709 */
710 static intersectPolygonRectangle(points: Point[], r1: number, r2: number): Intersection;
711}
712
713interface IPatternOptions {
714 /**
715 * Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
716 */
717 repeat?: string;
718
719 /**
720 * Pattern horizontal offset from object's left/top corner
721 */
722 offsetX?: number;
723
724 /**
725 * Pattern vertical offset from object's left/top corner
726 */
727 offsetY?: number;
728 /**
729 * crossOrigin value (one of "", "anonymous", "use-credentials")
730 * @see https://developer.mozilla.org/en-US/docs/HTML/CORS_settings_attributes
731 * @type String
732 */
733 crossOrigin?: '' | 'anonymous' | 'use-credentials';
734 /**
735 * Transform matrix to change the pattern, imported from svgs
736 */
737 patternTransform?: number[];
738 /**
739 * The source for the pattern
740 */
741 source: string | HTMLImageElement;
742}
743export interface Pattern extends IPatternOptions {}
744export class Pattern {
745 /**
746 * Unique identifier
747 */
748 id: number;
749
750 constructor(options?: IPatternOptions);
751 /**
752 * Returns object representation of a pattern
753 * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
754 * @return {Object} Object representation of a pattern instance
755 */
756 toObject(propertiesToInclude: any): any;
757 /**
758 * Returns SVG representation of a pattern
759 * @param {fabric.Object} object
760 * @return {String} SVG representation of a pattern
761 */
762 toSVG(object: Object): string;
763 setOptions(options: IPatternOptions): void;
764 /**
765 * Returns an instance of CanvasPattern
766 * @param {CanvasRenderingContext2D} ctx Context to create pattern
767 * @return {CanvasPattern}
768 */
769 toLive(ctx: CanvasRenderingContext2D): CanvasPattern;
770}
771export class Point {
772 x: number;
773 y: number;
774 type: string;
775 constructor(x: number, y: number);
776 /**
777 * Adds another point to this one and returns another one
778 * @param {fabric.Point} that
779 * @return {fabric.Point} new Point instance with added values
780 */
781 add(that: Point): Point;
782 /**
783 * Adds another point to this one
784 * @param {fabric.Point} that
785 * @return {fabric.Point} thisArg
786 * @chainable
787 */
788 addEquals(that: Point): Point;
789 /**
790 * Adds value to this point and returns a new one
791 * @param {Number} scalar
792 * @return {fabric.Point} new Point with added value
793 */
794 scalarAdd(scalar: number): Point;
795 /**
796 * Adds value to this point
797 * @param {Number} scalar
798 * @return {fabric.Point} thisArg
799 * @chainable
800 */
801 scalarAddEquals(scalar: number): Point;
802 /**
803 * Subtracts another point from this point and returns a new one
804 * @param {fabric.Point} that
805 * @return {fabric.Point} new Point object with subtracted values
806 */
807 subtract(that: Point): Point;
808 /**
809 * Subtracts another point from this point
810 * @param {fabric.Point} that
811 * @return {fabric.Point} thisArg
812 * @chainable
813 */
814 subtractEquals(that: Point): Point;
815 /**
816 * Subtracts value from this point and returns a new one
817 * @param {Number} scalar
818 * @return {fabric.Point}
819 */
820 scalarSubtract(scalar: number): Point;
821 /**
822 * Subtracts value from this point
823 * @param {Number} scalar
824 * @return {fabric.Point} thisArg
825 * @chainable
826 */
827 scalarSubtractEquals(scalar: number): Point;
828 /**
829 * Multiplies this point by a value and returns a new one
830 * @param {Number} scalar
831 * @return {fabric.Point}
832 */
833 multiply(scalar: number): Point;
834 /**
835 * Multiplies this point by a value
836 * @param {Number} scalar
837 * @return {fabric.Point} thisArg
838 * @chainable
839 */
840 multiplyEquals(scalar: number): Point;
841 /**
842 * Divides this point by a value and returns a new one
843 * @param {Number} scalar
844 * @return {fabric.Point}
845 */
846 divide(scalar: number): Point;
847 /**
848 * Divides this point by a value
849 * @param {Number} scalar
850 * @return {fabric.Point} thisArg
851 * @chainable
852 */
853 divideEquals(scalar: number): Point;
854 /**
855 * Returns true if this point is equal to another one
856 * @param {fabric.Point} that
857 * @return {Boolean}
858 */
859 eq(that: Point): Point;
860 /**
861 * Returns true if this point is less than another one
862 * @param {fabric.Point} that
863 * @return {Boolean}
864 */
865 lt(that: Point): Point;
866 /**
867 * Returns true if this point is less than or equal to another one
868 * @param {fabric.Point} that
869 * @return {Boolean}
870 */
871 lte(that: Point): Point;
872 /**
873 * Returns true if this point is greater another one
874 * @param {fabric.Point} that
875 * @return {Boolean}
876 */
877 gt(that: Point): Point;
878 /**
879 * Returns true if this point is greater than or equal to another one
880 * @param {fabric.Point} that
881 * @return {Boolean}
882 */
883 gte(that: Point): Point;
884 /**
885 * Returns new point which is the result of linear interpolation with this one and another one
886 * @param {fabric.Point} that
887 * @param {Number} t , position of interpolation, between 0 and 1 default 0.5
888 * @return {fabric.Point}
889 */
890 lerp(that: Point, t: number): Point;
891 /**
892 * Returns distance from this point and another one
893 * @param {fabric.Point} that
894 * @return {Number}
895 */
896 distanceFrom(that: Point): number;
897 /**
898 * Returns the point between this point and another one
899 * @param {fabric.Point} that
900 * @return {fabric.Point}
901 */
902 midPointFrom(that: Point): Point;
903 /**
904 * Returns a new point which is the min of this and another one
905 * @param {fabric.Point} that
906 * @return {fabric.Point}
907 */
908 min(that: Point): Point;
909 /**
910 * Returns a new point which is the max of this and another one
911 * @param {fabric.Point} that
912 * @return {fabric.Point}
913 */
914 max(that: Point): Point;
915 /**
916 * Returns string representation of this point
917 * @return {String}
918 */
919 toString(): string;
920 /**
921 * Sets x/y of this point
922 * @param {Number} x
923 * @param {Number} y
924 * @chainable
925 */
926 setXY(x: number, y: number): Point;
927 /**
928 * Sets x of this point
929 * @param {Number} x
930 * @chainable
931 */
932 setX(x: number): Point;
933 /**
934 * Sets y of this point
935 * @param {Number} y
936 * @chainable
937 */
938 setY(y: number): Point;
939 /**
940 * Sets x/y of this point from another point
941 * @param {fabric.Point} that
942 * @chainable
943 */
944 setFromPoint(that: Point): Point;
945 /**
946 * Swaps x/y of this point and another point
947 * @param {fabric.Point} that
948 */
949 swap(that: Point): Point;
950 /**
951 * return a cloned instance of the point
952 * @return {fabric.Point}
953 */
954 clone(): Point;
955}
956interface IShadowOptions {
957 /**
958 * Shadow color
959 */
960 color?: string;
961 /**
962 * Shadow blur
963 */
964 blur?: number;
965 /**
966 * Shadow horizontal offset
967 */
968 offsetX?: number;
969 /**
970 * Shadow vertical offset
971 */
972 offsetY?: number;
973 /**
974 * Whether the shadow should affect stroke operations
975 */
976 affectStroke?: boolean;
977 /**
978 * Indicates whether toObject should include default values
979 */
980 includeDefaultValues?: boolean;
981 /**
982 * When `false`, the shadow will scale with the object.
983 * When `true`, the shadow's offsetX, offsetY, and blur will not be affected by the object's scale.
984 * default to false
985 * @type Boolean
986 * @default
987 */
988 nonScaling?: boolean;
989}
990export interface Shadow extends IShadowOptions {}
991export class Shadow {
992 constructor(options?: IShadowOptions | string);
993 initialize(options?: IShadowOptions | string): Shadow;
994 /**
995 * Returns a string representation of an instance
996 * @see http://www.w3.org/TR/css-text-decor-3/#text-shadow
997 * @return {String} Returns CSS3 text-shadow declaration
998 */
999 toString(): string;
1000 /**
1001 * Returns SVG representation of a shadow
1002 * @param {fabric.Object} object
1003 * @return {String} SVG representation of a shadow
1004 */
1005 toSVG(object: Object): string;
1006 /**
1007 * Returns object representation of a shadow
1008 * @return {Object} Object representation of a shadow instance
1009 */
1010 toObject(): any;
1011 /**
1012 * Regex matching shadow offsetX, offsetY and blur (ex: "2px 2px 10px rgba(0,0,0,0.2)", "rgb(0,255,0) 2px 2px")
1013 * @static
1014 * @field
1015 * @memberOf fabric.Shadow
1016 */
1017 static reOffsetsAndBlur: RegExp;
1018}
1019
1020///////////////////////////////////////////////////////////////////////////////
1021// Canvas Interfaces
1022//////////////////////////////////////////////////////////////////////////////
1023interface ICanvasDimensions {
1024 /**
1025 * Width of canvas element
1026 */
1027 width: number | string;
1028 /**
1029 * Height of canvas element
1030 */
1031 height: number | string;
1032}
1033interface ICanvasDimensionsOptions {
1034 /**
1035 * Set the given dimensions only as canvas backstore dimensions
1036 */
1037 backstoreOnly?: boolean;
1038 /**
1039 * Set the given dimensions only as css dimensions
1040 */
1041 cssOnly?: boolean;
1042}
1043
1044interface IStaticCanvasOptions {
1045 /**
1046 * Background color of canvas instance.
1047 * Should be set via {@link fabric.StaticCanvas#setBackgroundColor}.
1048 * @type {(String|fabric.Pattern)}
1049 */
1050 backgroundColor?: string | Pattern;
1051 /**
1052 * Background image of canvas instance.
1053 * Should be set via {@link fabric.StaticCanvas#setBackgroundImage}.
1054 * <b>Backwards incompatibility note:</b> The "backgroundImageOpacity"
1055 * and "backgroundImageStretch" properties are deprecated since 1.3.9.
1056 * Use {@link fabric.Image#opacity}, {@link fabric.Image#width} and {@link fabric.Image#height}.
1057 * since 2.4.0 image caching is active, please when putting an image as background, add to the
1058 * canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom
1059 * vale. As an alternative you can disable image objectCaching
1060 * @type fabric.Image
1061 */
1062 backgroundImage?: Image | string;
1063 /**
1064 * Overlay color of canvas instance.
1065 * Should be set via {@link fabric.StaticCanvas#setOverlayColor}
1066 * @since 1.3.9
1067 * @type {(String|fabric.Pattern)}
1068 */
1069 overlayColor?: string | Pattern;
1070 /**
1071 * Overlay image of canvas instance.
1072 * Should be set via {@link fabric.StaticCanvas#setOverlayImage}.
1073 * <b>Backwards incompatibility note:</b> The "overlayImageLeft"
1074 * and "overlayImageTop" properties are deprecated since 1.3.9.
1075 * Use {@link fabric.Image#left} and {@link fabric.Image#top}.
1076 * since 2.4.0 image caching is active, please when putting an image as overlay, add to the
1077 * canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom
1078 * vale. As an alternative you can disable image objectCaching
1079 * @type fabric.Image
1080 */
1081 overlayImage?: Image;
1082 /**
1083 * Indicates whether toObject/toDatalessObject should include default values
1084 * if set to false, takes precedence over the object value.
1085 * @type Boolean
1086 */
1087 includeDefaultValues?: boolean;
1088 /**
1089 * Indicates whether objects' state should be saved
1090 * @type Boolean
1091 */
1092 stateful?: boolean;
1093 /**
1094 * Indicates whether {@link fabric.Collection.add}, {@link fabric.Collection.insertAt} and {@link fabric.Collection.remove},
1095 * {@link fabric.StaticCanvas.moveTo}, {@link fabric.StaticCanvas.clear} and many more, should also re-render canvas.
1096 * Disabling this option will not give a performance boost when adding/removing a lot of objects to/from canvas at once
1097 * since the renders are quequed and executed one per frame.
1098 * Disabling is suggested anyway and managing the renders of the app manually is not a big effort ( canvas.requestRenderAll() )
1099 * Left default to true to do not break documentation and old app, fiddles.
1100 * @type Boolean
1101 */
1102 renderOnAddRemove?: boolean;
1103 /**
1104 * Indicates whether object controls (borders/controls) are rendered above overlay image
1105 * @type Boolean
1106 */
1107 controlsAboveOverlay?: boolean;
1108 /**
1109 * Indicates whether the browser can be scrolled when using a touchscreen and dragging on the canvas
1110 * @type Boolean
1111 */
1112 allowTouchScrolling?: boolean;
1113 /**
1114 * Indicates whether this canvas will use image smoothing, this is on by default in browsers
1115 */
1116 imageSmoothingEnabled?: boolean;
1117 /**
1118 * The transformation (in the format of Canvas transform) which focuses the viewport
1119 */
1120 viewportTransform?: number[];
1121 /**
1122 * if set to false background image is not affected by viewport transform
1123 * @since 1.6.3
1124 * @type Boolean
1125 */
1126 backgroundVpt?: boolean;
1127 /**
1128 * if set to false overlay image is not affected by viewport transform
1129 * @since 1.6.3
1130 * @type Boolean
1131 */
1132 overlayVpt?: boolean;
1133 /**
1134 * When true, canvas is scaled by devicePixelRatio for better rendering on retina screens
1135 * @type Boolean
1136 */
1137 enableRetinaScaling?: boolean;
1138 /**
1139 * Describe canvas element extension over design
1140 * properties are tl,tr,bl,br.
1141 * if canvas is not zoomed/panned those points are the four corner of canvas
1142 * if canvas is viewportTransformed you those points indicate the extension
1143 * of canvas element in plain untrasformed coordinates
1144 * The coordinates get updated with @method calcViewportBoundaries.
1145 * @memberOf fabric.StaticCanvas.prototype
1146 */
1147 vptCoords?: {
1148 tl: { x: number; y: number };
1149 tr: { x: number; y: number };
1150 bl: { x: number; y: number };
1151 br: { x: number; y: number };
1152 };
1153 /**
1154 * Based on vptCoords and object.aCoords, skip rendering of objects that
1155 * are not included in current viewport.
1156 * May greatly help in applications with crowded canvas and use of zoom/pan
1157 * If One of the corner of the bounding box of the object is on the canvas
1158 * the objects get rendered.
1159 * @memberOf fabric.StaticCanvas.prototype
1160 * @type Boolean
1161 */
1162 skipOffscreen?: boolean;
1163 /**
1164 * a fabricObject that, without stroke define a clipping area with their shape. filled in black
1165 * the clipPath object gets used when the canvas has rendered, and the context is placed in the
1166 * top left corner of the canvas.
1167 * clipPath will clip away controls, if you do not want this to happen use controlsAboveOverlay = true
1168 * @type fabric.Object
1169 */
1170 clipPath?: Object;
1171 /**
1172 * When true, getSvgTransform() will apply the StaticCanvas.viewportTransform to the SVG transformation. When true,
1173 * a zoomed canvas will then produce zoomed SVG output.
1174 * @type Boolean
1175 */
1176 svgViewportTransformation?: boolean;
1177}
1178
1179export interface FreeDrawingBrush {
1180 /**
1181 * Can be any regular color value.
1182 */
1183 color: string;
1184
1185 /**
1186 * Brush width measured in pixels.
1187 */
1188 width: number;
1189}
1190
1191export interface StaticCanvas
1192 extends IObservable<StaticCanvas>,
1193 IStaticCanvasOptions,
1194 ICollection<StaticCanvas>,
1195 ICanvasAnimation<StaticCanvas> {}
1196export class StaticCanvas {
1197 /**
1198 * Constructor
1199 * @param {HTMLElement | String} el <canvas> element to initialize instance on
1200 * @param {Object} [options] Options object
1201 * @return {Object} thisArg
1202 */
1203 constructor(element: HTMLCanvasElement | string | null, options?: ICanvasOptions);
1204
1205 _activeObject?: Object | Group;
1206
1207 freeDrawingBrush: FreeDrawingBrush;
1208
1209 /**
1210 * Calculates canvas element offset relative to the document
1211 * This method is also attached as "resize" event handler of window
1212 * @return {fabric.Canvas} instance
1213 * @chainable
1214 */
1215 calcOffset(): Canvas;
1216
1217 /**
1218 * Sets {@link fabric.StaticCanvas#overlayImage|overlay image} for this canvas
1219 * @param {(fabric.Image|String)} image fabric.Image instance or URL of an image to set overlay to
1220 * @param {Function} callback callback to invoke when image is loaded and set as an overlay
1221 * @param {Object} [options] Optional options to set for the {@link fabric.Image|overlay image}.
1222 * @return {fabric.Canvas} thisArg
1223 * @chainable
1224 */
1225 setOverlayImage(image: Image | string, callback: Function, options?: IImageOptions): Canvas;
1226
1227 /**
1228 * Sets {@link fabric.StaticCanvas#backgroundImage|background image} for this canvas
1229 * @param {(fabric.Image|String)} image fabric.Image instance or URL of an image to set background to
1230 * @param {Function} callback Callback to invoke when image is loaded and set as background
1231 * @param {Object} [options] Optional options to set for the {@link fabric.Image|background image}.
1232 * @return {fabric.Canvas} thisArg
1233 * @chainable
1234 */
1235 setBackgroundImage(image: Image | string, callback: Function, options?: IImageOptions): Canvas;
1236
1237 /**
1238 * Sets {@link fabric.StaticCanvas#overlayColor|foreground color} for this canvas
1239 * @param {(String|fabric.Pattern)} overlayColor Color or pattern to set foreground color to
1240 * @param {Function} callback Callback to invoke when foreground color is set
1241 * @return {fabric.Canvas} thisArg
1242 * @chainable
1243 */
1244 setOverlayColor(overlayColor: string | Pattern, callback: Function): Canvas;
1245
1246 /**
1247 * Sets {@link fabric.StaticCanvas#backgroundColor|background color} for this canvas
1248 * @param {(String|fabric.Pattern)} backgroundColor Color or pattern to set background color to
1249 * @param {Function} callback Callback to invoke when background color is set
1250 * @return {fabric.Canvas} thisArg
1251 * @chainable
1252 */
1253 setBackgroundColor(backgroundColor: string | Pattern | Gradient, callback: Function): Canvas;
1254
1255 /**
1256 * Returns canvas width (in px)
1257 * @return {Number}
1258 */
1259 getWidth(): number;
1260
1261 /**
1262 * Returns canvas height (in px)
1263 * @return {Number}
1264 */
1265 getHeight(): number;
1266
1267 /**
1268 * Sets width of this canvas instance
1269 * @param {Number|String} value Value to set width to
1270 * @param {Object} [options] Options object
1271 * @return {fabric.Canvas} instance
1272 * @chainable true
1273 */
1274 setWidth(value: number | string, options?: ICanvasDimensionsOptions): Canvas;
1275
1276 /**
1277 * Sets height of this canvas instance
1278 * @param value Value to set height to
1279 * @param [options] Options object
1280 * @return {fabric.Canvas} instance
1281 * @chainable true
1282 */
1283 setHeight(value: number | string, options?: ICanvasDimensionsOptions): Canvas;
1284
1285 /**
1286 * Sets dimensions (width, height) of this canvas instance. when options.cssOnly flag active you should also supply the unit of measure (px/%/em)
1287 * @param dimensions Object with width/height properties
1288 * @param [options] Options object
1289 * @return {fabric.Canvas} thisArg
1290 * @chainable
1291 */
1292 setDimensions(dimensions: ICanvasDimensions, options?: ICanvasDimensionsOptions): Canvas;
1293
1294 /**
1295 * Returns canvas zoom level
1296 */
1297 getZoom(): number;
1298
1299 /**
1300 * Sets viewport transform of this canvas instance
1301 * @param {Array} vpt the transform in the form of context.transform
1302 * @return {fabric.Canvas} instance
1303 * @chainable
1304 */
1305 setViewportTransform(vpt: number[]): Canvas;
1306
1307 /**
1308 * Sets zoom level of this canvas instance, zoom centered around point
1309 * @param {fabric.Point} point to zoom with respect to
1310 * @param {Number} value to set zoom to, less than 1 zooms out
1311 * @return {fabric.Canvas} instance
1312 * @chainable true
1313 */
1314 zoomToPoint(point: Point, value: number): Canvas;
1315
1316 /**
1317 * Sets zoom level of this canvas instance
1318 * @param {Number} value to set zoom to, less than 1 zooms out
1319 * @return {fabric.Canvas} instance
1320 * @chainable
1321 */
1322 setZoom(value: number): Canvas;
1323
1324 /**
1325 * Pan viewport so as to place point at top left corner of canvas
1326 * @param {fabric.Point} point to move to
1327 * @return {fabric.Canvas} instance
1328 * @chainable
1329 */
1330 absolutePan(point: Point): Canvas;
1331
1332 /**
1333 * Pans viewpoint relatively
1334 * @param {fabric.Point} point (position vector) to move by
1335 * @return {fabric.Canvas} instance
1336 * @chainable
1337 */
1338 relativePan(point: Point): Canvas;
1339
1340 /**
1341 * Returns <canvas> element corresponding to this instance
1342 * @return {HTMLCanvasElement}
1343 */
1344 getElement(): HTMLCanvasElement;
1345
1346 /**
1347 * Clears specified context of canvas element
1348 * @param ctx Context to clear
1349 * @chainable
1350 */
1351 clearContext(ctx: CanvasRenderingContext2D): Canvas;
1352
1353 /**
1354 * Returns context of canvas where objects are drawn
1355 * @return {CanvasRenderingContext2D}
1356 */
1357 getContext(): CanvasRenderingContext2D;
1358
1359 /**
1360 * Clears all contexts (background, main, top) of an instance
1361 * @return {fabric.Canvas} thisArg
1362 * @chainable
1363 */
1364 clear(): Canvas;
1365
1366 /**
1367 * Renders the canvas
1368 * @return {fabric.Canvas} instance
1369 * @chainable
1370 */
1371 renderAll(): Canvas;
1372
1373 /**
1374 * Function created to be instance bound at initialization
1375 * used in requestAnimationFrame rendering
1376 * Let the fabricJS call it. If you call it manually you could have more
1377 * animationFrame stacking on to of each other
1378 * for an imperative rendering, use canvas.renderAll
1379 * @private
1380 * @return {fabric.Canvas} instance
1381 * @chainable
1382 */
1383 renderAndReset(): Canvas;
1384
1385 /**
1386 * Append a renderAll request to next animation frame.
1387 * unless one is already in progress, in that case nothing is done
1388 * a boolean flag will avoid appending more.
1389 * @return {fabric.Canvas} instance
1390 * @chainable
1391 */
1392 requestRenderAll(): Canvas;
1393
1394 /**
1395 * Calculate the position of the 4 corner of canvas with current viewportTransform.
1396 * helps to determinate when an object is in the current rendering viewport using
1397 * object absolute coordinates ( aCoords )
1398 * @return {Object} points.tl
1399 * @chainable
1400 */
1401 calcViewportBoundaries(): { tl: Point; br: Point; tr: Point; bl: Point };
1402
1403 /**
1404 * Renders background, objects, overlay and controls.
1405 * @param {CanvasRenderingContext2D} ctx
1406 * @param {Array} objects to render
1407 * @return {fabric.Canvas} instance
1408 * @chainable
1409 */
1410 renderCanvas(ctx: CanvasRenderingContext2D, objects: Object[]): Canvas;
1411
1412 /**
1413 * Paint the cached clipPath on the lowerCanvasEl
1414 * @param {CanvasRenderingContext2D} ctx Context to render on
1415 */
1416 drawClipPathOnCanvas(ctx: CanvasRenderingContext2D): void;
1417
1418 /**
1419 * Returns coordinates of a center of canvas.
1420 * Returned value is an object with top and left properties
1421 * @return {Object} object with "top" and "left" number values
1422 */
1423 getCenter(): { top: number; left: number };
1424
1425 /**
1426 * Centers object horizontally in the canvas
1427 * @param {fabric.Object} object Object to center horizontally
1428 * @return {fabric.Canvas} thisArg
1429 */
1430 centerObjectH(object: Object): Canvas;
1431
1432 /**
1433 * Centers object vertically in the canvas
1434 * @param {fabric.Object} object Object to center vertically
1435 * @return {fabric.Canvas} thisArg
1436 * @chainable
1437 */
1438 centerObjectV(object: Object): Canvas;
1439
1440 /**
1441 * Centers object vertically and horizontally in the canvas
1442 * @param {fabric.Object} object Object to center vertically and horizontally
1443 * @return {fabric.Canvas} thisArg
1444 * @chainable
1445 */
1446 centerObject(object: Object): Canvas;
1447
1448 /**
1449 * Centers object vertically and horizontally in the viewport
1450 * @param {fabric.Object} object Object to center vertically and horizontally
1451 * @return {fabric.Canvas} thisArg
1452 * @chainable
1453 */
1454 viewportCenterObject(object: Object): Canvas;
1455
1456 /**
1457 * Centers object horizontally in the viewport, object.top is unchanged
1458 * @param {fabric.Object} object Object to center vertically and horizontally
1459 * @return {fabric.Canvas} thisArg
1460 * @chainable
1461 */
1462 viewportCenterObjectH(object: Object): Canvas;
1463
1464 /**
1465 * Centers object Vertically in the viewport, object.top is unchanged
1466 * @param {fabric.Object} object Object to center vertically and horizontally
1467 * @return {fabric.Canvas} thisArg
1468 * @chainable
1469 */
1470 viewportCenterObjectV(object: Object): Canvas;
1471
1472 /**
1473 * Calculate the point in canvas that correspond to the center of actual viewport.
1474 * @return {fabric.Point} vpCenter, viewport center
1475 */
1476 getVpCenter(): Point;
1477
1478 /**
1479 * Returs dataless JSON representation of canvas
1480 * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1481 * @return {String} json string
1482 */
1483 toDatalessJSON(propertiesToInclude?: string[]): string;
1484
1485 /**
1486 * Returns JSON representation of canvas
1487 * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1488 * @return {String} JSON string
1489 */
1490 toJSON(propertiesToInclude?: string[]): string;
1491
1492 /**
1493 * Returns object representation of canvas
1494 * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1495 * @return {Object} object representation of an instance
1496 */
1497 toObject(propertiesToInclude?: string[]): any;
1498
1499 /**
1500 * Returns dataless object representation of canvas
1501 * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
1502 * @return {Object} object representation of an instance
1503 */
1504 toDatalessObject(propertiesToInclude?: string[]): any;
1505
1506 /**
1507 * Returns SVG representation of canvas
1508 * @param [options] Options object for SVG output
1509 * @param [reviver] Method for further parsing of svg elements, called after each fabric object converted into svg representation.
1510 * @return {String} SVG string
1511 */
1512 toSVG(options?: IToSVGOptions, reviver?: Function): string;
1513
1514 /**
1515 * Moves an object or the objects of a multiple selection
1516 * to the bottom of the stack of drawn objects
1517 * @param {fabric.Object} object Object to send to back
1518 * @return {fabric.Canvas} thisArg
1519 * @chainable
1520 */
1521 sendToBack(object: Object): Canvas;
1522
1523 /**
1524 * Moves an object or the objects of a multiple selection
1525 * to the top of the stack of drawn objects
1526 * @param {fabric.Object} object Object to send
1527 * @return {fabric.Canvas} thisArg
1528 * @chainable
1529 */
1530 bringToFront(object: Object): Canvas;
1531
1532 /**
1533 * Moves an object or a selection down in stack of drawn objects
1534 * An optional paramter, intersecting allowes to move the object in behind
1535 * the first intersecting object. Where intersection is calculated with
1536 * bounding box. If no intersection is found, there will not be change in the
1537 * stack.
1538 * @param {fabric.Object} object Object to send
1539 * @param {Boolean} [intersecting] If `true`, send object behind next lower intersecting object
1540 * @return {fabric.Canvas} thisArg
1541 * @chainable
1542 */
1543 sendBackwards(object: Object, intersecting?: boolean): Canvas;
1544
1545 /**
1546 * Moves an object or a selection up in stack of drawn objects
1547 * An optional paramter, intersecting allowes to move the object in front
1548 * of the first intersecting object. Where intersection is calculated with
1549 * bounding box. If no intersection is found, there will not be change in the
1550 * stack.
1551 * @param {fabric.Object} object Object to send
1552 * @param {Boolean} [intersecting] If `true`, send object in front of next upper intersecting object
1553 * @return {fabric.Canvas} thisArg
1554 * @chainable
1555 */
1556 bringForward(object: Object, intersecting?: boolean): Canvas;
1557
1558 /**
1559 * Moves an object to specified level in stack of drawn objects
1560 * @param {fabric.Object} object Object to send
1561 * @param {Number} index Position to move to
1562 * @return {fabric.Canvas} thisArg
1563 * @chainable
1564 */
1565 moveTo(object: Object, index: number): Canvas;
1566
1567 /**
1568 * Clears a canvas element and dispose objects
1569 * @return {fabric.Canvas} thisArg
1570 * @chainable */
1571 dispose(): Canvas;
1572
1573 /**
1574 * Returns a string representation of an instance
1575 * @return {String} string representation of an instance
1576 */
1577 toString(): string;
1578
1579 /**
1580 * @static
1581 * @type String
1582 * @default
1583 */
1584 static EMPTY_JSON: string;
1585
1586 /**
1587 * Provides a way to check support of some of the canvas methods
1588 * (either those of HTMLCanvasElement itself, or rendering context)
1589 *
1590 * @param {String} methodName Method to check support for;
1591 * Could be one of "setLineDash"
1592 * @return {Boolean | null} `true` if method is supported (or at least exists),
1593 * `null` if canvas element or context can not be initialized
1594 */
1595 static supports(methodName: 'getImageData' | 'toDataURL' | 'toDataURLWithQuality' | 'setLineDash'): boolean;
1596
1597 /**
1598 * Exports canvas element to a dataurl image. Note that when multiplier is used, cropping is scaled appropriately
1599 * @param [options] Options object
1600 */
1601 toDataURL(options?: IDataURLOptions): string;
1602
1603 /**
1604 * Returns JSON representation of canvas
1605 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
1606 */
1607 static toJSON(propertiesToInclude?: string[]): string;
1608
1609 /**
1610 * Clones canvas instance
1611 * @param [callback] Receives cloned instance as a first argument
1612 * @param [properties] Array of properties to include in the cloned canvas and children
1613 */
1614 clone(callback?: any, properties?: string[]): void;
1615
1616 /**
1617 * Clones canvas instance without cloning existing data.
1618 * This essentially copies canvas dimensions, clipping properties, etc.
1619 * but leaves data empty (so that you can populate it with your own)
1620 * @param [callback] Receives cloned instance as a first argument
1621 */
1622 cloneWithoutData(callback?: any): void;
1623
1624 /**
1625 * Populates canvas with data from the specified JSON.
1626 * JSON format must conform to the one of {@link fabric.Canvas#toJSON}
1627 * @param {String|Object} json JSON string or object
1628 * @param {Function} callback Callback, invoked when json is parsed
1629 * and corresponding objects (e.g: {@link fabric.Image})
1630 * are initialized
1631 * @param {Function} [reviver] Method for further parsing of JSON elements, called after each fabric object created.
1632 * @return {fabric.Canvas} instance
1633 */
1634 loadFromJSON(json: any, callback: Function, reviver?: Function): Canvas;
1635
1636 /**
1637 * Creates markup containing SVG font faces,
1638 * font URLs for font faces must be collected by developers
1639 * and are not extracted from the DOM by fabricjs
1640 * @param {Array} objects Array of fabric objects
1641 * @return {String}
1642 */
1643
1644 createSVGFontFacesMarkup(objects: any[]): string;
1645 /**
1646 * Creates markup containing SVG referenced elements like patterns, gradients etc.
1647 * @return {String}
1648 */
1649
1650 createSVGRefElementsMarkup(): string;
1651 /**
1652 * Straightens object, then rerenders canvas
1653 * @param {fabric.Object} object Object to straighten
1654 * @return {fabric.Canvas} thisArg
1655 * @chainable
1656 */
1657
1658 straightenObject(object: Object): Canvas;
1659}
1660
1661interface ICanvasOptions extends IStaticCanvasOptions {
1662 /**
1663 * When true, objects can be transformed by one side (unproportionally)
1664 * when dragged on the corners that normally would not do that.
1665 * @type Boolean
1666 * @default
1667 * @since fabric 4.0 // changed name and default value
1668 */
1669 uniformScaling?: boolean;
1670
1671 /**
1672 * Indicates which key enable unproportional scaling
1673 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1674 * If `null` or 'none' or any other string that is not a modifier key
1675 * feature is disabled feature disabled.
1676 * @since 1.6.2
1677 * @type String
1678 */
1679 uniScaleKey?: string;
1680
1681 /**
1682 * When true, objects use center point as the origin of scale transformation.
1683 * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
1684 */
1685 centeredScaling?: boolean;
1686
1687 /**
1688 * When true, objects use center point as the origin of rotate transformation.
1689 * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
1690 */
1691 centeredRotation?: boolean;
1692
1693 /**
1694 * Color of object's fill
1695 */
1696 fill?: string | Pattern | Gradient;
1697
1698 /**
1699 * Indicates which key enable centered Transform
1700 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1701 * If `null` or 'none' or any other string that is not a modifier key
1702 * feature is disabled feature disabled.
1703 * @since 1.6.2
1704 * @type String
1705 * @default
1706 */
1707 centeredKey?: string;
1708
1709 /**
1710 * Indicates which key enable alternate action on corner
1711 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1712 * If `null` or 'none' or any other string that is not a modifier key
1713 * feature is disabled feature disabled.
1714 * @since 1.6.2
1715 * @type String
1716 * @default
1717 */
1718 altActionKey?: string;
1719
1720 /**
1721 * Indicates that canvas is interactive. This property should not be changed.
1722 */
1723 interactive?: boolean;
1724
1725 /**
1726 * Indicates whether group selection should be enabled
1727 */
1728 selection?: boolean;
1729
1730 /**
1731 * Indicates which key or keys enable multiple click selection
1732 * Pass value as a string or array of strings
1733 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1734 * If `null` or empty or containing any other string that is not a modifier key
1735 * feature is disabled.
1736 * @since 1.6.2
1737 * @type String|Array
1738 * @default
1739 */
1740 selectionKey?: string | string[];
1741
1742 /**
1743 * Indicates which key enable alternative selection
1744 * in case of target overlapping with active object
1745 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1746 * For a series of reason that come from the general expectations on how
1747 * things should work, this feature works only for preserveObjectStacking true.
1748 * If `null` or 'none' or any other string that is not a modifier key
1749 * feature is disabled.
1750 * @since 1.6.5
1751 * @type null|String
1752 * @default
1753 */
1754 altSelectionKey?: string | null;
1755
1756 /**
1757 * Color of selection
1758 */
1759 selectionColor?: string;
1760
1761 /**
1762 * Default dash array pattern
1763 * If not empty the selection border is dashed
1764 */
1765 selectionDashArray?: number[];
1766
1767 /**
1768 * Color of the border of selection (usually slightly darker than color of selection itself)
1769 */
1770 selectionBorderColor?: string;
1771
1772 /**
1773 * Width of a line used in object/group selection
1774 */
1775 selectionLineWidth?: number;
1776
1777 /**
1778 * Select only shapes that are fully contained in the dragged selection rectangle.
1779 * @type Boolean
1780 * @default
1781 */
1782 selectionFullyContained?: boolean;
1783
1784 /**
1785 * Default cursor value used when hovering over an object on canvas
1786 */
1787 hoverCursor?: string;
1788
1789 /**
1790 * Default cursor value used when moving an object on canvas
1791 */
1792 moveCursor?: string;
1793
1794 /**
1795 * Default cursor value used for the entire canvas
1796 */
1797 defaultCursor?: string;
1798
1799 /**
1800 * Cursor value used during free drawing
1801 */
1802 freeDrawingCursor?: string;
1803
1804 /**
1805 * Cursor value used for rotation point
1806 */
1807 rotationCursor?: string;
1808
1809 /**
1810 * Cursor value used for disabled elements ( corners with disabled action )
1811 * @type String
1812 * @since 2.0.0
1813 * @default
1814 */
1815 notAllowedCursor?: string;
1816
1817 /**
1818 * Default element class that's given to wrapper (div) element of canvas
1819 */
1820 containerClass?: string;
1821
1822 /**
1823 * When true, object detection happens on per-pixel basis rather than on per-bounding-box
1824 */
1825 perPixelTargetFind?: boolean;
1826
1827 /**
1828 * Number of pixels around target pixel to tolerate (consider active) during object detection
1829 */
1830 targetFindTolerance?: number;
1831
1832 /**
1833 * When true, target detection is skipped when hovering over canvas. This can be used to improve performance.
1834 */
1835 skipTargetFind?: boolean;
1836
1837 /**
1838 * When true, mouse events on canvas (mousedown/mousemove/mouseup) result in free drawing.
1839 * After mousedown, mousemove creates a shape,
1840 * and then mouseup finalizes it and adds an instance of `fabric.Path` onto canvas.
1841 */
1842 isDrawingMode?: boolean;
1843
1844 /**
1845 * Indicates whether objects should remain in current stack position when selected.
1846 * When false objects are brought to top and rendered as part of the selection group
1847 * @type Boolean
1848 */
1849 preserveObjectStacking?: boolean;
1850
1851 /**
1852 * Indicates the angle that an object will lock to while rotating.
1853 * @type Number
1854 * @since 1.6.7
1855 */
1856 snapAngle?: number;
1857
1858 /**
1859 * Indicates the distance from the snapAngle the rotation will lock to the snapAngle.
1860 * When `null`, the snapThreshold will default to the snapAngle.
1861 * @type null|Number
1862 * @since 1.6.7
1863 * @default
1864 */
1865 snapThreshold?: null | number;
1866
1867 /**
1868 * Indicates if the right click on canvas can output the context menu or not
1869 * @type Boolean
1870 * @since 1.6.5
1871 * @default
1872 */
1873 stopContextMenu?: boolean;
1874
1875 /**
1876 * Indicates if the canvas can fire right click events
1877 * @type Boolean
1878 * @since 1.6.5
1879 * @default
1880 */
1881 fireRightClick?: boolean;
1882
1883 /**
1884 * Indicates if the canvas can fire middle click events
1885 * @type Boolean
1886 * @since 1.7.8
1887 * @default
1888 */
1889 fireMiddleClick?: boolean;
1890
1891 /**
1892 * Keep track of the subTargets for Mouse Events
1893 * @type {Array.<fabric.Object>}
1894 * @since 3.6.0
1895 * @default
1896 */
1897 targets?: Object[];
1898
1899 /**
1900 * Canvas width
1901 * @type number
1902 * @default
1903 */
1904 width?: number;
1905
1906 /**
1907 * Canvas height
1908 * @type number
1909 * @default
1910 */
1911 height?: number;
1912}
1913export interface Canvas extends StaticCanvas {}
1914export interface Canvas extends ICanvasOptions {}
1915export class Canvas {
1916 /**
1917 * Constructor
1918 * @param element <canvas> element to initialize instance on
1919 * @param [options] Options object
1920 */
1921 constructor(element: HTMLCanvasElement | string | null, options?: ICanvasOptions);
1922
1923 /**
1924 * When true, target detection is skipped when hovering over canvas. This can be used to improve performance.
1925 * @type Boolean
1926 * @default
1927 */
1928 skipTargetFind: boolean;
1929 _activeObject: Object;
1930 _objects: Object[];
1931 targets: Object[];
1932 /**
1933 * Indicates which key enable alternative selection
1934 * in case of target overlapping with active object
1935 * values: 'altKey', 'shiftKey', 'ctrlKey'.
1936 * For a series of reason that come from the general expectations on how
1937 * things should work, this feature works only for preserveObjectStacking true.
1938 * If `null` or 'none' or any other string that is not a modifier key
1939 * feature is disabled.
1940 * @since 1.6.5
1941 * @type null|String
1942 * @default
1943 */
1944 altSelectionKey?: string;
1945
1946 /**
1947 * Renders both the top canvas and the secondary container canvas.
1948 * @return {fabric.Canvas} instance
1949 * @chainable
1950 */
1951 renderAll(): Canvas;
1952 /**
1953 * Method to render only the top canvas.
1954 * Also used to render the group selection box.
1955 * @return {fabric.Canvas} thisArg
1956 * @chainable
1957 */
1958 renderTop(): Canvas;
1959 /**
1960 * Checks if point is contained within an area of given object
1961 * @param {Event} e Event object
1962 * @param {fabric.Object} target Object to test against
1963 * @param {Object} [point] x,y object of point coordinates we want to check.
1964 * @return {Boolean} true if point is contained within an area of given object
1965 */
1966 containsPoint(e: Event, target: Object, point?: { x: number; y: number }): boolean;
1967 /**
1968 * Returns true if object is transparent at a certain location
1969 * @param {fabric.Object} target Object to check
1970 * @param {Number} x Left coordinate
1971 * @param {Number} y Top coordinate
1972 * @return {Boolean}
1973 */
1974 isTargetTransparent(target: Object, x: number, y: number): boolean;
1975 /**
1976 * Set the cursor type of the canvas element
1977 * @param {String} value Cursor type of the canvas element.
1978 * @see http://www.w3.org/TR/css3-ui/#cursor
1979 */
1980 setCursor(value: string): void;
1981 /**
1982 * Method that determines what object we are clicking on
1983 * the skipGroup parameter is for internal use, is needed for shift+click action
1984 * 11/09/2018 TODO: would be cool if findTarget could discern between being a full target
1985 * or the outside part of the corner.
1986 * @param {Event} e mouse event
1987 * @param {Boolean} skipGroup when true, activeGroup is skipped and only objects are traversed through
1988 * @return {fabric.Object} the target found
1989 */
1990 findTarget(e: Event, skipGroup: boolean): Object | undefined;
1991 /**
1992 * Returns pointer coordinates without the effect of the viewport
1993 * @param {Object} pointer with "x" and "y" number values
1994 * @return {Object} object with "x" and "y" number values
1995 */
1996 restorePointerVpt(pointer: Point): any;
1997 /**
1998 * Returns pointer coordinates relative to canvas.
1999 * Can return coordinates with or without viewportTransform.
2000 * ignoreZoom false gives back coordinates that represent
2001 * the point clicked on canvas element.
2002 * ignoreZoom true gives back coordinates after being processed
2003 * by the viewportTransform ( sort of coordinates of what is displayed
2004 * on the canvas where you are clicking.
2005 * ignoreZoom true = HTMLElement coordinates relative to top,left
2006 * ignoreZoom false, default = fabric space coordinates, the same used for shape position
2007 * To interact with your shapes top and left you want to use ignoreZoom true
2008 * most of the time, while ignoreZoom false will give you coordinates
2009 * compatible with the object.oCoords system.
2010 * of the time.
2011 * @param {Event} e
2012 * @param {Boolean} ignoreZoom
2013 * @return {Object} object with "x" and "y" number values
2014 */
2015 getPointer(e: Event, ignoreZoom?: boolean): { x: number; y: number };
2016 /**
2017 * Returns context of canvas where object selection is drawn
2018 * @return {CanvasRenderingContext2D}
2019 */
2020 getSelectionContext(): CanvasRenderingContext2D;
2021 /**
2022 * Returns <canvas> element on which object selection is drawn
2023 * @return {HTMLCanvasElement}
2024 */
2025 getSelectionElement(): HTMLCanvasElement;
2026 /**
2027 * Returns currently active object
2028 * @return {fabric.Object} active object
2029 */
2030 getActiveObject(): Object;
2031 /**
2032 * Returns an array with the current selected objects
2033 * @return {fabric.Object} active object
2034 */
2035 getActiveObjects(): Object[];
2036 /**
2037 * Sets given object as the only active object on canvas
2038 * @param {fabric.Object} object Object to set as an active one
2039 * @param {Event} [e] Event (passed along when firing "object:selected")
2040 * @return {fabric.Canvas} thisArg
2041 * @chainable
2042 */
2043 setActiveObject(object: Object, e?: Event): Canvas;
2044 /**
2045 * Discards currently active object and fire events. If the function is called by fabric
2046 * as a consequence of a mouse event, the event is passed as a parameter and
2047 * sent to the fire function for the custom events. When used as a method the
2048 * e param does not have any application.
2049 * @param {event} e
2050 * @return {fabric.Canvas} thisArg
2051 * @chainable
2052 */
2053 discardActiveObject(e?: Event): Canvas;
2054 /**
2055 * Clears a canvas element and removes all event listeners
2056 * @return {fabric.Canvas} thisArg
2057 * @chainable
2058 */
2059 dispose(): Canvas;
2060 /**
2061 * Clears all contexts (background, main, top) of an instance
2062 * @return {fabric.Canvas} thisArg
2063 * @chainable
2064 */
2065 clear(): Canvas;
2066 /**
2067 * Draws objects' controls (borders/controls)
2068 * @param {CanvasRenderingContext2D} ctx Context to render controls on
2069 */
2070 drawControls(ctx: CanvasRenderingContext2D): void;
2071 /**
2072 * @private
2073 * @return {Boolean} true if the scaling occurred
2074 */
2075 _setObjectScale(
2076 localMouse: Point,
2077 transform: any,
2078 lockScalingX: boolean,
2079 lockScalingY: boolean,
2080 by: 'x' | 'y' | 'equally' | undefined,
2081 lockScalingFlip: boolean,
2082 _dim: Point,
2083 ): boolean;
2084 /**
2085 * Scales object by invoking its scaleX/scaleY methods
2086 * @private
2087 * @param {Number} x pointer's x coordinate
2088 * @param {Number} y pointer's y coordinate
2089 * @param {String} by Either 'x' or 'y' - specifies dimension constraint by which to scale an object.
2090 * When not provided, an object is scaled by both dimensions equally
2091 * @return {Boolean} true if the scaling occurred
2092 */
2093 _scaleObject(x: number, y: number, by?: 'x' | 'y' | 'equally'): boolean;
2094 /**
2095 * @private
2096 * @param {fabric.Object} obj Object that was removed
2097 */
2098 _onObjectRemoved(obj: Object): void;
2099 /**
2100 * @private
2101 * @param {fabric.Object} obj Object that was added
2102 */
2103 _onObjectAdded(obj: Object): void;
2104 /**
2105 * Resets the current transform to its original values and chooses the type of resizing based on the event
2106 * @private
2107 */
2108 _resetCurrentTransform(): void;
2109 /**
2110 * @private
2111 * Compares the old activeObject with the current one and fires correct events
2112 * @param {fabric.Object} obj old activeObject
2113 */
2114 _fireSelectionEvents(oldObjects: Object[], e?: Event): void;
2115 /**
2116 * @private
2117 * @param {Object} object to set as active
2118 * @param {Event} [e] Event (passed along when firing "object:selected")
2119 * @return {Boolean} true if the selection happened
2120 */
2121 _setActiveObject(object: fabric.Object, e?: Event): boolean;
2122 /**
2123 * Returns pointer coordinates relative to canvas.
2124 * Can return coordinates with or without viewportTransform.
2125 * ignoreZoom false gives back coordinates that represent
2126 * the point clicked on canvas element.
2127 * ignoreZoom true gives back coordinates after being processed
2128 * by the viewportTransform ( sort of coordinates of what is displayed
2129 * on the canvas where you are clicking.
2130 * ignoreZoom true = HTMLElement coordinates relative to top,left
2131 * ignoreZoom false, default = fabric space coordinates, the same used for shape position
2132 * To interact with your shapes top and left you want to use ignoreZoom true
2133 * most of the time, while ignoreZoom false will give you coordinates
2134 * compatible with the object.oCoords system.
2135 * of the time.
2136 * @param {Event} e
2137 * @param {Boolean} ignoreZoom
2138 * @return {Object} object with "x" and "y" number values
2139 */
2140 getPointer(e: Event, ignoreZoom: boolean): { x: number; y: number };
2141 /**
2142 * Function used to search inside objects an object that contains pointer in bounding box or that contains pointerOnCanvas when painted
2143 * @param {Array} [objects] objects array to look into
2144 * @param {Object} [pointer] x,y object of point coordinates we want to check.
2145 * @return {fabric.Object} object that contains pointer
2146 * @private
2147 */
2148 _searchPossibleTargets(objects: Object[], pointer: { x: number; y: number }): Object;
2149
2150 static EMPTY_JSON: string;
2151 /**
2152 * Provides a way to check support of some of the canvas methods
2153 * (either those of HTMLCanvasElement itself, or rendering context)
2154 * @param methodName Method to check support for; Could be one of "getImageData", "toDataURL", "toDataURLWithQuality" or "setLineDash"
2155 */
2156 static supports(methodName: 'getImageData' | 'toDataURL' | 'toDataURLWithQuality' | 'setLineDash'): boolean;
2157 /**
2158 * Returns JSON representation of canvas
2159 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
2160 */
2161 static toJSON(propertiesToInclude?: string[]): string;
2162 /**
2163 * Removes all event listeners
2164 */
2165 removeListeners(): void;
2166}
2167
2168///////////////////////////////////////////////////////////////////////////////
2169// Shape Interfaces
2170//////////////////////////////////////////////////////////////////////////////
2171
2172interface ICircleOptions extends IObjectOptions {
2173 /**
2174 * Radius of this circle
2175 */
2176 radius?: number;
2177 /**
2178 * Start angle of the circle, moving clockwise
2179 */
2180 startAngle?: number;
2181 /**
2182 * End angle of the circle
2183 */
2184 endAngle?: number;
2185}
2186export interface Circle extends Object, ICircleOptions {}
2187export class Circle {
2188 constructor(options?: ICircleOptions);
2189 /**
2190 * Returns horizontal radius of an object (according to how an object is scaled)
2191 */
2192 getRadiusX(): number;
2193 /**
2194 * Returns vertical radius of an object (according to how an object is scaled)
2195 */
2196 getRadiusY(): number;
2197 /**
2198 * Sets radius of an object (and updates width accordingly)
2199 */
2200 setRadius(value: number): number;
2201 /**
2202 * Returns svg representation of an instance
2203 * @return {Array} an array of strings with the specific svg representation
2204 * of the instance
2205 */
2206 _toSVG(): string;
2207 /**
2208 * List of attribute names to account for when parsing SVG element (used by {@link fabric.Circle.fromElement})
2209 */
2210 static ATTRIBUTE_NAMES: string[];
2211 /**
2212 * Returns Circle instance from an SVG element
2213 * @param element Element to parse
2214 * @param [options] Options object
2215 */
2216 static fromElement(element: SVGElement, options: ICircleOptions): Circle;
2217 /**
2218 * Returns Circle instance from an object representation
2219 * @param object Object to create an instance from
2220 */
2221 static fromObject(object: any): Circle;
2222}
2223
2224interface IEllipseOptions extends IObjectOptions {
2225 /**
2226 * Horizontal radius
2227 */
2228 rx?: number;
2229 /**
2230 * Vertical radius
2231 */
2232 ry?: number;
2233}
2234export interface Ellipse extends Object, IEllipseOptions {}
2235export class Ellipse {
2236 constructor(options?: IEllipseOptions);
2237 /**
2238 * Returns horizontal radius of an object (according to how an object is scaled)
2239 */
2240 getRx(): number;
2241 /**
2242 * Returns Vertical radius of an object (according to how an object is scaled)
2243 */
2244 getRy(): number;
2245 /**
2246 * Returns svg representation of an instance
2247 * @return {Array} an array of strings with the specific svg representation
2248 * of the instance
2249 */
2250 _toSVG(): string;
2251 /**
2252 * List of attribute names to account for when parsing SVG element (used by {@link fabric.Ellipse.fromElement})
2253 */
2254 static ATTRIBUTE_NAMES: string[];
2255 /**
2256 * Returns Ellipse instance from an SVG element
2257 * @param element Element to parse
2258 * @param [options] Options object
2259 */
2260 static fromElement(element: SVGElement, options?: IEllipseOptions): Ellipse;
2261 /**
2262 * Returns Ellipse instance from an object representation
2263 * @param object Object to create an instance from
2264 */
2265 static fromObject(object: any): Ellipse;
2266}
2267interface IGroupOptions extends IObjectOptions {
2268 /**
2269 * Indicates if click, mouseover, mouseout events & hoverCursor should also check for subtargets
2270 * @type Boolean
2271 */
2272 subTargetCheck?: boolean;
2273 /**
2274 * setOnGroup is a method used for TextBox that is no more used since 2.0.0 The behavior is still
2275 * available setting this boolean to true.
2276 * @type Boolean
2277 * @since 2.0.0
2278 * @default
2279 */
2280 useSetOnGroup?: boolean;
2281}
2282export interface Group extends Object, ICollection<Group>, IGroupOptions {}
2283export class Group {
2284 /**
2285 * Constructor
2286 * @param objects Group objects
2287 * @param [options] Options object
2288 */
2289 constructor(objects?: Object[], options?: IGroupOptions, isAlreadyGrouped?: boolean);
2290 /**
2291 * Adds an object to a group; Then recalculates group's dimension, position.
2292 * @param [Object] object
2293 * @return thisArg
2294 * @chainable
2295 */
2296 addWithUpdate(object?: Object): Group;
2297 /**
2298 * Removes an object from a group; Then recalculates group's dimension, position.
2299 * @return thisArg
2300 * @chainable
2301 */
2302 removeWithUpdate(object: Object): Group;
2303 /**
2304 * Renders instance on a given context
2305 * @param ctx context to render instance on
2306 */
2307 render(ctx: CanvasRenderingContext2D): void;
2308 /**
2309 * Decide if the object should cache or not. Create its own cache level
2310 * objectCaching is a global flag, wins over everything
2311 * needsItsOwnCache should be used when the object drawing method requires
2312 * a cache step. None of the fabric classes requires it.
2313 * Generally you do not cache objects in groups because the group outside is cached.
2314 * @return {Boolean}
2315 */
2316 shouldCache(): boolean;
2317 /**
2318 * Check if this object or a child object will cast a shadow
2319 * @return {Boolean}
2320 */
2321 willDrawShadow(): boolean;
2322 /**
2323 * Check if this group or its parent group are caching, recursively up
2324 * @return {Boolean}
2325 */
2326 isOnACache(): boolean;
2327 /**
2328 * Execute the drawing operation for an object on a specified context
2329 * @param {CanvasRenderingContext2D} ctx Context to render on
2330 */
2331 drawObject(ctx: CanvasRenderingContext2D): void;
2332 /**
2333 * Check if cache is dirty
2334 */
2335 isCacheDirty(skipCanvas?: boolean): boolean;
2336 /**
2337 * Realises the transform from this group onto the supplied object
2338 * i.e. it tells you what would happen if the supplied object was in
2339 * the group, and then the group was destroyed. It mutates the supplied
2340 * object.
2341 * @param {fabric.Object} object
2342 * @return {fabric.Object} transformedObject
2343 */
2344 realizeTransform(object: Object): Object;
2345 /**
2346 * Destroys a group (restoring state of its objects)
2347 * @return {fabric.Group} thisArg
2348 * @chainable
2349 */
2350 destroy(): Group;
2351 /**
2352 * make a group an active selection, remove the group from canvas
2353 * the group has to be on canvas for this to work.
2354 * @return {fabric.ActiveSelection} thisArg
2355 * @chainable
2356 */
2357 toActiveSelection(): ActiveSelection;
2358 /**
2359 * Destroys a group (restoring state of its objects)
2360 * @return {fabric.Group} thisArg
2361 * @chainable
2362 */
2363 ungroupOnCanvas(): Group;
2364 /**
2365 * Sets coordinates of all group objects
2366 * @return thisArg
2367 * @chainable
2368 */
2369 setObjectsCoords(): Group;
2370 /**
2371 * Returns svg representation of an instance
2372 * @param [reviver] Method for further parsing of svg representation.
2373 * @return svg representation of an instance
2374 */
2375 toSVG(reviver?: Function): string;
2376 /**
2377 * Returns svg clipPath representation of an instance
2378 * @param {Function} [reviver] Method for further parsing of svg representation.
2379 * @return {String} svg representation of an instance
2380 */
2381 toClipPathSVG(reviver?: Function): string;
2382 /**
2383 * Adds an object to a group; Then recalculates group's dimension, position.
2384 * @param {Object} object
2385 * @return {fabric.Group} thisArg
2386 * @chainable
2387 */
2388 addWithUpdate(object: Object): Group;
2389 /**
2390 * Retores original state of each of group objects (original state is that which was before group was created).
2391 * @private
2392 * @return {fabric.Group} thisArg
2393 * @chainable
2394 */
2395 _restoreObjectsState(): Group;
2396 /**
2397 * @private
2398 */
2399 _calcBounds(onlyWidthHeight?: boolean): void;
2400 /**
2401 * @private
2402 * @param {Boolean} [skipCoordsChange] if true, coordinates of objects enclosed in a group do not change
2403 */
2404 _updateObjectsCoords(center?: Point): void;
2405 /**
2406 * Retores original state of each of group objects (original state is that which was before group was created).
2407 * @private
2408 * @return {fabric.Group} thisArg
2409 * @chainable
2410 */
2411 _restoreObjectsState(): Group;
2412 /**
2413 * @private
2414 */
2415 _onObjectRemoved(object: Object): void;
2416 /**
2417 * Returns {@link fabric.Group} instance from an object representation
2418 * @param object Object to create a group from
2419 * @param [callback] Callback to invoke when an group instance is created
2420 */
2421 static fromObject(object: any, callback: (group: Group) => any): void;
2422}
2423
2424///////////////////////////////////////////////////////////////////////////////
2425// ActiveSelection
2426//////////////////////////////////////////////////////////////////////////////
2427export interface ActiveSelection extends Group, ICollection<Group> {}
2428export class ActiveSelection {
2429 /**
2430 * Constructor
2431 * @param objects ActiveSelection objects
2432 * @param [options] Options object
2433 */
2434 constructor(objects?: Object[], options?: IObjectOptions);
2435 /**
2436 * Constructor
2437 * @param {Object} objects ActiveSelection objects
2438 * @param {Object} [options] Options object
2439 * @return {Object} thisArg
2440 */
2441 initialize(objects: ActiveSelection, options?: IObjectOptions): Object;
2442 /**
2443 * Change te activeSelection to a normal group,
2444 * High level function that automatically adds it to canvas as
2445 * active object. no events fired.
2446 */
2447 toGroup(): Group;
2448 /**
2449 * Returns {@link fabric.ActiveSelection} instance from an object representation
2450 * @memberOf fabric.ActiveSelection
2451 * @param object Object to create a group from
2452 * @param [callback] Callback to invoke when an ActiveSelection instance is created
2453 */
2454 static fromObject(object: any, callback: Function): void;
2455}
2456
2457interface IImageOptions extends IObjectOptions {
2458 /**
2459 * crossOrigin value (one of "", "anonymous", "allow-credentials")
2460 */
2461 crossOrigin?: string;
2462 /**
2463 * When calling {@link fabric.Image.getSrc}, return value from element src with `element.getAttribute('src')`.
2464 * This allows for relative urls as image src.
2465 * @since 2.7.0
2466 * @type Boolean
2467 */
2468 srcFromAttribute?: boolean;
2469 /**
2470 * minimum scale factor under which any resizeFilter is triggered to resize the image
2471 * 0 will disable the automatic resize. 1 will trigger automatically always.
2472 * number bigger than 1 are not implemented yet.
2473 * @type Number
2474 */
2475 minimumScaleTrigger?: number;
2476 /**
2477 * key used to retrieve the texture representing this image
2478 * @since 2.0.0
2479 * @type String
2480 */
2481 cacheKey?: string;
2482 /**
2483 * Image crop in pixels from original image size.
2484 * @since 2.0.0
2485 * @type Number
2486 */
2487 cropX?: number;
2488 /**
2489 * Image crop in pixels from original image size.
2490 * @since 2.0.0
2491 * @type Number
2492 */
2493 cropY?: number;
2494 /**
2495 * Image filter array
2496 */
2497 filters?: IBaseFilter[];
2498}
2499interface Image extends Object, IImageOptions {}
2500export class Image {
2501 /**
2502 * Constructor
2503 * @param element Image or Video element
2504 * @param [options] Options object
2505 */
2506 constructor(element?: string | HTMLImageElement | HTMLVideoElement, options?: IImageOptions);
2507 /**
2508 * Returns image or video element which this instance is based on
2509 * @return Image or Video element
2510 */
2511 getElement(): HTMLImageElement | HTMLVideoElement;
2512 /**
2513 * Sets image or video element for this instance to a specified one.
2514 * If filters defined they are applied to new image.
2515 * You might need to call `canvas.renderAll` and `object.setCoords` after replacing, to render new image and update controls area.
2516 * @param element image element
2517 * @param [options] Options object
2518 */
2519 setElement(element: HTMLImageElement | HTMLVideoElement, options?: IImageOptions): Image;
2520 /**
2521 * Delete a single texture if in webgl mode
2522 */
2523 removeTexture(key: any): void;
2524 /**
2525 * Delete textures, reference to elements and eventually JSDOM cleanup
2526 */
2527 dispose(): void;
2528 /**
2529 * Returns original size of an image
2530 * @return Object with "width" and "height" properties
2531 */
2532 getOriginalSize(): { width: number; height: number };
2533 /**
2534 * Returns true if an image has crop applied, inspecting values of cropX,cropY,width,hight.
2535 * @return {Boolean}
2536 */
2537 hasCrop(): boolean;
2538 /**
2539 * Returns svg representation of an instance
2540 * @return {Array} an array of strings with the specific svg representation
2541 * of the instance
2542 */
2543 _toSVG(): string;
2544 /**
2545 * Returns source of an image
2546 * @return Source of an image
2547 */
2548 getSrc(): string;
2549 /**
2550 * Sets source of an image
2551 * @param {String} src Source string (URL)
2552 * @param {Function} [callback] Callback is invoked when image has been loaded (and all filters have been applied)
2553 * @param {Object} [options] Options object
2554 * @return {fabric.Image} thisArg
2555 * @chainable
2556 */
2557 setSrc(src: string, callback?: Function, options?: IImageOptions): Image;
2558 applyResizeFilters(): void;
2559 /**
2560 * Applies filters assigned to this image (from "filters" array) or from filter param
2561 * @param {Array} filters to be applied
2562 * @return {thisArg} return the fabric.Image object
2563 * @chainable
2564 */
2565 applyFilters(filters?: IBaseFilter[]): Image;
2566 /**
2567 * Calculate offset for center and scale factor for the image in order to respect
2568 * the preserveAspectRatio attribute
2569 * @private
2570 * @return {Object}
2571 */
2572 parsePreserveAspectRatioAttribute(): any;
2573 /**
2574 * Creates an instance of fabric.Image from an URL string
2575 * @param url URL to create an image from
2576 * @param [callback] Callback to invoke when image is created (newly created image is passed as a first argument)
2577 * @param [imgOptions] Options object
2578 */
2579 static fromURL(url: string, callback?: (image: Image) => void, imgOptions?: IImageOptions): Image;
2580 /**
2581 * Returns Image instance from an SVG element
2582 * @param element Element to parse
2583 * @param callback Callback to execute when fabric.Image object is created
2584 * @param [options] Options object
2585 */
2586 static fromElement(element: SVGElement, callback: Function, options?: IImageOptions): Image;
2587 /**
2588 * Default CSS class name for canvas
2589 */
2590 static CSS_CANVAS: string;
2591 static filters: IAllFilters;
2592 static ATTRIBUTE_NAMES: string[];
2593}
2594
2595interface ILineOptions extends IObjectOptions {
2596 /**
2597 * x value or first line edge
2598 */
2599 x1?: number;
2600 /**
2601 * x value or second line edge
2602 */
2603 x2?: number;
2604 /**
2605 * y value or first line edge
2606 */
2607 y1?: number;
2608 /**
2609 * y value or second line edge
2610 */
2611 y2?: number;
2612}
2613export interface Line extends Object, ILineOptions {}
2614export class Line {
2615 /**
2616 * Constructor
2617 * @param [points] Array of points
2618 * @param [options] Options object
2619 */
2620 constructor(points?: number[], objObjects?: ILineOptions);
2621 /**
2622 * Returns svg representation of an instance
2623 * @return {Array} an array of strings with the specific svg representation
2624 * of the instance
2625 */
2626 _toSVG(): string;
2627 /**
2628 * Returns fabric.Line instance from an SVG element
2629 * @static
2630 * @memberOf fabric.Line
2631 * @param {SVGElement} element Element to parse
2632 * @param {Object} [options] Options object
2633 * @param {Function} [callback] callback function invoked after parsing
2634 */
2635 static fromElement(element: SVGElement, callback?: Function, options?: ILineOptions): Line;
2636 /**
2637 * Returns fabric.Line instance from an object representation
2638 * @param object Object to create an instance from
2639 */
2640 static fromObject(object: any): Line;
2641 static ATTRIBUTE_NAMES: string[];
2642 /**
2643 * Produces a function that calculates distance from canvas edge to Line origin.
2644 */
2645 makeEdgeToOriginGetter(
2646 propertyNames: { origin: number; axis1: any; axis2: any; dimension: any },
2647 originValues: { nearest: any; center: any; farthest: any },
2648 ): Function;
2649 /**
2650 * Recalculates line points given width and height
2651 * @private
2652 */
2653 calcLinePoints(): { x1: number; x2: number; y1: number; y2: number };
2654}
2655
2656interface IObjectOptions {
2657 /**
2658 * Type of an object (rect, circle, path, etc.).
2659 * Note that this property is meant to be read-only and not meant to be modified.
2660 * If you modify, certain parts of Fabric (such as JSON loading) won't work correctly.
2661 */
2662 type?: string;
2663
2664 /**
2665 * Horizontal origin of transformation of an object (one of "left", "right", "center")
2666 */
2667 originX?: string;
2668
2669 /**
2670 * Vertical origin of transformation of an object (one of "top", "bottom", "center")
2671 */
2672 originY?: string;
2673
2674 /**
2675 * Top position of an object. Note that by default it's relative to object center. You can change this by setting originY={top/center/bottom}
2676 */
2677 top?: number;
2678
2679 /**
2680 * Left position of an object. Note that by default it's relative to object center. You can change this by setting originX={left/center/right}
2681 */
2682 left?: number;
2683
2684 /**
2685 * Object width
2686 */
2687 width?: number;
2688
2689 /**
2690 * Object height
2691 */
2692 height?: number;
2693
2694 /**
2695 * Object scale factor (horizontal)
2696 */
2697 scaleX?: number;
2698
2699 /**
2700 * Object scale factor (vertical)
2701 */
2702 scaleY?: number;
2703
2704 /**
2705 * When true, an object is rendered as flipped horizontally
2706 */
2707 flipX?: boolean;
2708
2709 /**
2710 * When true, an object is rendered as flipped vertically
2711 */
2712 flipY?: boolean;
2713
2714 /**
2715 * Opacity of an object
2716 */
2717 opacity?: number;
2718
2719 /**
2720 * Angle of rotation of an object (in degrees)
2721 */
2722 angle?: number;
2723
2724 /**
2725 * Object skew factor (horizontal)
2726 */
2727 skewX?: number;
2728
2729 /**
2730 * Object skew factor (vertical)
2731 */
2732 skewY?: number;
2733
2734 /**
2735 * Size of object's controlling corners (in pixels)
2736 */
2737 cornerSize?: number;
2738
2739 /**
2740 * When true, object's controlling corners are rendered as transparent inside (i.e. stroke instead of fill)
2741 */
2742 transparentCorners?: boolean;
2743
2744 /**
2745 * Default cursor value used when hovering over this object on canvas
2746 */
2747 hoverCursor?: string;
2748
2749 /**
2750 * Default cursor value used when moving an object on canvas
2751 */
2752 moveCursor?: string;
2753
2754 /**
2755 * Padding between object and its controlling borders (in pixels)
2756 */
2757 padding?: number;
2758
2759 /**
2760 * Color of controlling borders of an object (when it's active)
2761 */
2762 borderColor?: string;
2763
2764 /**
2765 * Array specifying dash pattern of an object's border (hasBorder must be true)
2766 */
2767 borderDashArray?: number[];
2768
2769 /**
2770 * Color of controlling corners of an object (when it's active)
2771 */
2772 cornerColor?: string;
2773
2774 /**
2775 * Color of controlling corners of an object (when it's active and transparentCorners false)
2776 */
2777 cornerStrokeColor?: string;
2778
2779 /**
2780 * Specify style of control, 'rect' or 'circle'
2781 */
2782 cornerStyle?: 'rect' | 'circle';
2783
2784 /**
2785 * Array specifying dash pattern of an object's control (hasBorder must be true)
2786 */
2787 cornerDashArray?: number[];
2788
2789 /**
2790 * When true, this object will use center point as the origin of transformation
2791 * when being scaled via the controls.
2792 * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
2793 */
2794 centeredScaling?: boolean;
2795
2796 /**
2797 * When true, this object will use center point as the origin of transformation
2798 * when being rotated via the controls.
2799 * <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
2800 */
2801 centeredRotation?: boolean;
2802
2803 /**
2804 * Color of object's fill
2805 */
2806 fill?: string | Pattern | Gradient;
2807
2808 /**
2809 * Fill rule used to fill an object
2810 * accepted values are nonzero, evenodd
2811 * Backwards incompatibility note: This property was used for setting globalCompositeOperation until v1.4.12, use `globalCompositeOperation` instead
2812 */
2813 fillRule?: string;
2814
2815 /**
2816 * Composite rule used for canvas globalCompositeOperation
2817 */
2818 globalCompositeOperation?: string;
2819
2820 /**
2821 * Background color of an object. Only works with text objects at the moment.
2822 */
2823 backgroundColor?: string;
2824
2825 /**
2826 * Selection Background color of an object. colored layer behind the object when it is active.
2827 * does not mix good with globalCompositeOperation methods.
2828 * @type String
2829 */
2830 selectionBackgroundColor?: string;
2831
2832 /**
2833 * When defined, an object is rendered via stroke and this property specifies its color
2834 */
2835 stroke?: string;
2836
2837 /**
2838 * Width of a stroke used to render this object
2839 */
2840 strokeWidth?: number;
2841
2842 /**
2843 * Array specifying dash pattern of an object's stroke (stroke must be defined)
2844 */
2845 strokeDashArray?: number[];
2846
2847 /**
2848 * Line offset of an object's stroke
2849 * @type Number
2850 * @default
2851 */
2852 strokeDashOffset?: number;
2853
2854 /**
2855 * Line endings style of an object's stroke (one of "butt", "round", "square")
2856 */
2857 strokeLineCap?: string;
2858
2859 /**
2860 * Corner style of an object's stroke (one of "bevil", "round", "miter")
2861 */
2862 strokeLineJoin?: string;
2863
2864 /**
2865 * Maximum miter length (used for strokeLineJoin = "miter") of an object's stroke
2866 */
2867 strokeMiterLimit?: number;
2868
2869 /**
2870 * Shadow object representing shadow of this shape
2871 */
2872 shadow?: Shadow | string;
2873
2874 /**
2875 * Opacity of object's controlling borders when object is active and moving
2876 */
2877 borderOpacityWhenMoving?: number;
2878
2879 /**
2880 * Scale factor of object's controlling borders
2881 */
2882 borderScaleFactor?: number;
2883
2884 /**
2885 * Minimum allowed scale value of an object
2886 */
2887 minScaleLimit?: number;
2888
2889 /**
2890 * When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection).
2891 * But events still fire on it.
2892 */
2893 selectable?: boolean;
2894
2895 /**
2896 * When set to `false`, an object can not be a target of events. All events propagate through it. Introduced in v1.3.4
2897 */
2898 evented?: boolean;
2899
2900 /**
2901 * When set to `false`, an object is not rendered on canvas
2902 */
2903 visible?: boolean;
2904
2905 /**
2906 * When set to `false`, object's controls are not displayed and can not be used to manipulate object
2907 */
2908 hasControls?: boolean;
2909
2910 /**
2911 * When set to `false`, object's controlling borders are not rendered
2912 */
2913 hasBorders?: boolean;
2914
2915 /**
2916 * When set to `false`, object's controlling rotating point will not be visible or selectable
2917 */
2918 hasRotatingPoint?: boolean;
2919
2920 /**
2921 * Offset for object's controlling rotating point (when enabled via `hasRotatingPoint`)
2922 */
2923 rotatingPointOffset?: number;
2924
2925 /**
2926 * When set to `true`, objects are "found" on canvas on per-pixel basis rather than according to bounding box
2927 */
2928 perPixelTargetFind?: boolean;
2929
2930 /**
2931 * When `false`, default object's values are not included in its serialization
2932 */
2933 includeDefaultValues?: boolean;
2934
2935 /**
2936 * When `true`, object horizontal movement is locked
2937 */
2938 lockMovementX?: boolean;
2939
2940 /**
2941 * When `true`, object vertical movement is locked
2942 */
2943 lockMovementY?: boolean;
2944
2945 /**
2946 * When `true`, object rotation is locked
2947 */
2948 lockRotation?: boolean;
2949
2950 /**
2951 * When `true`, object horizontal scaling is locked
2952 */
2953 lockScalingX?: boolean;
2954
2955 /**
2956 * When `true`, object vertical scaling is locked
2957 */
2958 lockScalingY?: boolean;
2959
2960 /**
2961 * When `true`, object non-uniform scaling is locked
2962 */
2963 lockUniScaling?: boolean;
2964
2965 /**
2966 * When `true`, object horizontal skewing is locked
2967 * @type Boolean
2968 */
2969 lockSkewingX?: boolean;
2970
2971 /**
2972 * When `true`, object vertical skewing is locked
2973 * @type Boolean
2974 */
2975 lockSkewingY?: boolean;
2976
2977 /**
2978 * When `true`, object cannot be flipped by scaling into negative values
2979 */
2980 lockScalingFlip?: boolean;
2981
2982 /**
2983 * When `true`, object is not exported in OBJECT/JSON
2984 * since 1.6.3
2985 * @type Boolean
2986 * @default
2987 */
2988 excludeFromExport?: boolean;
2989
2990 /**
2991 * When `true`, object is cached on an additional canvas.
2992 */
2993 objectCaching?: boolean;
2994
2995 /**
2996 * When `true`, object properties are checked for cache invalidation. In some particular
2997 * situation you may want this to be disabled ( spray brush, very big, groups)
2998 * or if your application does not allow you to modify properties for groups child you want
2999 * to disable it for groups.
3000 * default to false
3001 * since 1.7.0
3002 * @type Boolean
3003 * @default false
3004 */
3005 statefullCache?: boolean;
3006
3007 /**
3008 * When `true`, cache does not get updated during scaling. The picture will get blocky if scaled
3009 * too much and will be redrawn with correct details at the end of scaling.
3010 * this setting is performance and application dependant.
3011 * default to true
3012 * since 1.7.0
3013 * @type Boolean
3014 */
3015 noScaleCache?: boolean;
3016
3017 /**
3018 * When `false`, the stoke width will scale with the object.
3019 * When `true`, the stroke will always match the exact pixel size entered for stroke width.
3020 * default to false
3021 * @since 2.6.0
3022 * @type Boolean
3023 * @default false
3024 * @type Boolean
3025 */
3026 strokeUniform?: boolean;
3027
3028 /**
3029 * When set to `true`, object's cache will be rerendered next render call.
3030 */
3031 dirty?: boolean;
3032
3033 /**
3034 * Determines if the fill or the stroke is drawn first (one of "fill" or "stroke")
3035 * @type String
3036 */
3037 paintFirst?: string;
3038
3039 /**
3040 * List of properties to consider when checking if state
3041 * of an object is changed (fabric.Object#hasStateChanged)
3042 * as well as for history (undo/redo) purposes
3043 * @type Array
3044 */
3045 stateProperties?: string[];
3046
3047 /**
3048 * List of properties to consider when checking if cache needs refresh
3049 * Those properties are checked by statefullCache ON ( or lazy mode if we want ) or from single
3050 * calls to Object.set(key, value). If the key is in this list, the object is marked as dirty
3051 * and refreshed at the next render
3052 * @type Array
3053 */
3054 cacheProperties?: string[];
3055
3056 /**
3057 * A fabricObject that, without stroke define a clipping area with their shape. filled in black
3058 * the clipPath object gets used when the object has rendered, and the context is placed in the center
3059 * of the object cacheCanvas.
3060 * If you want 0,0 of a clipPath to align with an object center, use clipPath.originX/Y to 'center'
3061 */
3062 clipPath?: Object;
3063
3064 /**
3065 * Meaningful ONLY when the object is used as clipPath.
3066 * if true, the clipPath will make the object clip to the outside of the clipPath
3067 * since 2.4.0
3068 * @type boolean
3069 * @default false
3070 */
3071 inverted?: boolean;
3072
3073 /**
3074 * Meaningful ONLY when the object is used as clipPath.
3075 * if true, the clipPath will have its top and left relative to canvas, and will
3076 * not be influenced by the object transform. This will make the clipPath relative
3077 * to the canvas, but clipping just a particular object.
3078 * WARNING this is beta, this feature may change or be renamed.
3079 * since 2.4.0
3080 * @type boolean
3081 * @default false
3082 */
3083 absolutePositioned?: boolean;
3084
3085 /**
3086 * Not used by fabric, just for convenience
3087 */
3088 name?: string;
3089
3090 /**
3091 * Not used by fabric, just for convenience
3092 */
3093 data?: any;
3094 /**
3095 * Describe object's corner position in canvas element coordinates.
3096 * properties are tl,mt,tr,ml,mr,bl,mb,br,mtr for the main controls.
3097 * each property is an object with x, y and corner.
3098 * The `corner` property contains in a similar manner the 4 points of the
3099 * interactive area of the corner.
3100 * The coordinates depends from this properties: width, height, scaleX, scaleY
3101 * skewX, skewY, angle, strokeWidth, viewportTransform, top, left, padding.
3102 * The coordinates get updated with @method setCoords.
3103 * You can calculate them without updating with @method calcCoords;
3104 * @memberOf fabric.Object.prototype
3105 */
3106 oCoords?: { tl: Point; mt: Point; tr: Point; ml: Point; mr: Point; bl: Point; mb: Point; br: Point; mtr: Point };
3107 /**
3108 * Describe object's corner position in canvas object absolute coordinates
3109 * properties are tl,tr,bl,br and describe the four main corner.
3110 * each property is an object with x, y, instance of Fabric.Point.
3111 * The coordinates depends from this properties: width, height, scaleX, scaleY
3112 * skewX, skewY, angle, strokeWidth, top, left.
3113 * Those coordinates are usefull to understand where an object is. They get updated
3114 * with oCoords but they do not need to be updated when zoom or panning change.
3115 * The coordinates get updated with @method setCoords.
3116 * You can calculate them without updating with @method calcCoords(true);
3117 * @memberOf fabric.Object.prototype
3118 */
3119 aCoords?: { bl: Point; br: Point; tl: Point; tr: Point };
3120 /**
3121 * storage for object full transform matrix
3122 */
3123 matrixCache?: any;
3124 /**
3125 * storage for object transform matrix
3126 */
3127 ownMatrixCache?: any;
3128
3129 /**
3130 * Indicates the angle that an object will lock to while rotating. Can get from canvas.
3131 */
3132 snapAngle?: number;
3133 /**
3134 * Indicates the distance from the snapAngle the rotation will lock to the snapAngle. Can get from canvas.
3135 */
3136 snapThreshold?: null | number;
3137 /**
3138 * The group the object is part of
3139 */
3140 group?: Group;
3141 /**
3142 * The canvas the object belongs to
3143 */
3144 canvas?: Canvas;
3145}
3146export interface Object extends IObservable<Object>, IObjectOptions, IObjectAnimation<Object> {}
3147export class Object {
3148 _controlsVisibility: {
3149 bl?: boolean;
3150 br?: boolean;
3151 mb?: boolean;
3152 ml?: boolean;
3153 mr?: boolean;
3154 mt?: boolean;
3155 tl?: boolean;
3156 tr?: boolean;
3157 mtr?: boolean;
3158 };
3159
3160 constructor(options?: IObjectOptions);
3161 initialize(options?: IObjectOptions): Object;
3162
3163 /* Sets object's properties from options
3164 * @param {Object} [options] Options object
3165 */
3166 setOptions(options: IObjectOptions): void;
3167
3168 /**
3169 * Transforms context when rendering an object
3170 * @param {CanvasRenderingContext2D} ctx Context
3171 */
3172 transform(ctx: CanvasRenderingContext2D): void;
3173
3174 /**
3175 * Returns an object representation of an instance
3176 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
3177 */
3178 toObject(propertiesToInclude?: string[]): any;
3179
3180 /**
3181 * Returns (dataless) object representation of an instance
3182 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
3183 */
3184 toDatalessObject(propertiesToInclude?: string[]): any;
3185
3186 /**
3187 * Returns a string representation of an instance
3188 */
3189 toString(): string;
3190
3191 /**
3192 * Return the object scale factor counting also the group scaling
3193 * @return {Object} object with scaleX and scaleY properties
3194 */
3195 getObjectScaling(): { scaleX: number; scaleY: number };
3196
3197 /**
3198 * Return the object scale factor counting also the group scaling, zoom and retina
3199 * @return {Object} object with scaleX and scaleY properties
3200 */
3201 getTotalObjectScaling(): { scaleX: number; scaleY: number };
3202
3203 /**
3204 * Return the object opacity counting also the group property
3205 * @return {Number}
3206 */
3207 getObjectOpacity(): number;
3208
3209 /**
3210 * This callback function is called by the parent group of an object every
3211 * time a non-delegated property changes on the group. It is passed the key
3212 * and value as parameters. Not adding in this function's signature to avoid
3213 * Travis build error about unused variables.
3214 */
3215 setOnGroup(): void;
3216
3217 /**
3218 * Retrieves viewportTransform from Object's canvas if possible
3219 */
3220 getViewportTransform(): any[];
3221
3222 /**
3223 * Renders an object on a specified context
3224 * @param {CanvasRenderingContext2D} ctx Context to render on
3225 */
3226 render(ctx: CanvasRenderingContext2D): void;
3227
3228 /**
3229 * When set to `true`, force the object to have its own cache, even if it is inside a group
3230 * it may be needed when your object behave in a particular way on the cache and always needs
3231 * its own isolated canvas to render correctly.
3232 * Created to be overridden
3233 * since 1.7.12
3234 * @returns false
3235 */
3236 needsItsOwnCache(): boolean;
3237
3238 /**
3239 * Decide if the object should cache or not. Create its own cache level
3240 * objectCaching is a global flag, wins over everything
3241 * needsItsOwnCache should be used when the object drawing method requires
3242 * a cache step. None of the fabric classes requires it.
3243 * Generally you do not cache objects in groups because the group outside is cached.
3244 * @return {Boolean}
3245 */
3246 shouldCache(): boolean;
3247
3248 /**
3249 * Check if this object or a child object will cast a shadow
3250 * used by Group.shouldCache to know if child has a shadow recursively
3251 * @return {Boolean}
3252 */
3253 willDrawShadow(): boolean;
3254
3255 /**
3256 * Execute the drawing operation for an object clipPath
3257 * @param {CanvasRenderingContext2D} ctx Context to render on
3258 */
3259 drawClipPathOnCache(ctx: CanvasRenderingContext2D): void;
3260
3261 /**
3262 * Execute the drawing operation for an object on a specified context
3263 * @param {CanvasRenderingContext2D} ctx Context to render on
3264 */
3265 drawObject(ctx: CanvasRenderingContext2D): void;
3266
3267 /**
3268 * Paint the cached copy of the object on the target context.
3269 * @param {CanvasRenderingContext2D} ctx Context to render on
3270 */
3271 drawCacheOnCanvas(ctx: CanvasRenderingContext2D): void;
3272
3273 /**
3274 * Check if cache is dirty
3275 * @param {Boolean} skipCanvas skip canvas checks because this object is painted
3276 * on parent canvas.
3277 */
3278 isCacheDirty(skipCanvas?: boolean): boolean;
3279
3280 /**
3281 * Clones an instance, using a callback method will work for every object.
3282 * @param callback Callback is invoked with a clone as a first argument
3283 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
3284 */
3285 clone(callback: Function, propertiesToInclude?: string[]): void;
3286
3287 /**
3288 * Creates an instance of fabric.Image out of an object
3289 * @param callback callback, invoked with an instance as a first argument
3290 */
3291 cloneAsImage(callback: Function, options?: IDataURLOptions): Object;
3292
3293 /**
3294 * Converts an object into a HTMLCanvas element
3295 * @param {Object} options Options object
3296 * @param {Number} [options.multiplier=1] Multiplier to scale by
3297 * @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
3298 * @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
3299 * @param {Number} [options.width] Cropping width. Introduced in v1.2.14
3300 * @param {Number} [options.height] Cropping height. Introduced in v1.2.14
3301 * @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
3302 * @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
3303 * @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
3304 * @return {HTMLCanvasElement} Returns a new HTMLCanvasElement painted with the current canvas object
3305 */
3306 toCanvasElement(options?: IDataURLOptions): HTMLCanvasElement;
3307
3308 /**
3309 * Converts an object into a data-url-like string
3310 * @param options Options object
3311 */
3312 toDataURL(options: IDataURLOptions): string;
3313
3314 /**
3315 * Returns true if specified type is identical to the type of an instance
3316 * @param type Type to check against
3317 */
3318 isType(type: string): boolean;
3319
3320 /**
3321 * Returns complexity of an instance
3322 */
3323 complexity(): number;
3324
3325 /**
3326 * Returns a JSON representation of an instance
3327 * @param [propertiesToInclude] Any properties that you might want to additionally include in the output
3328 */
3329 toJSON(propertiesToInclude?: string[]): any;
3330
3331 /**
3332 * Sets "angle" of an instance
3333 * @param angle Angle value
3334 */
3335 rotate(angle: number): Object;
3336
3337 /**
3338 * Centers object horizontally on canvas to which it was added last.
3339 * You might need to call `setCoords` on an object after centering, to update controls area.
3340 */
3341 centerH(): Object;
3342
3343 /**
3344 * Centers object horizontally on current viewport of canvas to which it was added last.
3345 * You might need to call `setCoords` on an object after centering, to update controls area.
3346 * @return {fabric.Object} thisArg
3347 * @chainable
3348 */
3349 viewportCenterH(): Object;
3350
3351 /**
3352 * Centers object vertically on canvas to which it was added last.
3353 * You might need to call `setCoords` on an object after centering, to update controls area.
3354 */
3355 centerV(): Object;
3356
3357 /**
3358 * Centers object vertically on current viewport of canvas to which it was added last.
3359 * You might need to call `setCoords` on an object after centering, to update controls area.
3360 * @return {fabric.Object} thisArg
3361 * @chainable
3362 */
3363 viewportCenterV(): Object;
3364
3365 /**
3366 * Centers object vertically and horizontally on canvas to which is was added last
3367 * You might need to call `setCoords` on an object after centering, to update controls area.
3368 */
3369 center(): Object;
3370
3371 /**
3372 * Centers object on current viewport of canvas to which it was added last.
3373 * You might need to call `setCoords` on an object after centering, to update controls area.
3374 * @return {fabric.Object} thisArg
3375 * @chainable
3376 */
3377 viewportCenter(): Object;
3378
3379 /**
3380 * Returns coordinates of a pointer relative to an object
3381 * @param e Event to operate upon
3382 * @param [pointer] Pointer to operate upon (instead of event)
3383 */
3384 getLocalPointer(e: Event | undefined, pointer?: { x: number; y: number }): { x: number; y: number };
3385
3386 /**
3387 * Basic getter
3388 * @param property Property name
3389 */
3390 get<K extends keyof this>(property: K): this[K];
3391
3392 /**
3393 * Sets property to a given value.
3394 * When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls.
3395 * If you need to update those, call `setCoords()`.
3396 * @param key Property name
3397 * @param value Property value (if function, the value is passed into it and its return value is used as a new one)
3398 */
3399 set<K extends keyof this>(key: K, value: this[K] | ((value: this[K]) => this[K])): Object;
3400
3401 /**
3402 * Sets property to a given value.
3403 * When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls.
3404 * If you need to update those, call `setCoords()`.
3405 * @param options Property object, iterate over the object properties
3406 */
3407 set(options: Partial<this>): Object;
3408
3409 /**
3410 * Toggles specified property from `true` to `false` or from `false` to `true`
3411 * @param property Property to toggle
3412 */
3413 toggle(property: keyof this): Object;
3414
3415 /**
3416 * Sets sourcePath of an object
3417 * @param value Value to set sourcePath to
3418 */
3419 setSourcePath(value: string): Object;
3420
3421 /**
3422 * Sets "angle" of an instance
3423 * @param angle Angle value
3424 */
3425 setAngle(angle: number): Object;
3426
3427 /**
3428 * Sets object's properties from options
3429 * @param [options] Options object
3430 */
3431 setOptions(options?: any): void;
3432 /**
3433 * Sets sourcePath of an object
3434 * @param value Value to set sourcePath to
3435 */
3436 setSourcePath(value: string): Object;
3437 // functions from object svg export mixin
3438 // -----------------------------------------------------------------------------------------------------------------------------------
3439 /**
3440 * Returns styles-string for svg-export
3441 * @param {Boolean} skipShadow a boolean to skip shadow filter output
3442 * @return {String}
3443 */
3444 getSvgStyles(skipShadow?: boolean): string;
3445 /**
3446 * Returns transform-string for svg-export
3447 * @param {Boolean} use the full transform or the single object one.
3448 * @return {String}
3449 */
3450 getSvgTransform(full?: boolean, additionalTransform?: string): string;
3451 /**
3452 * Returns transform-string for svg-export from the transform matrix of single elements
3453 */
3454 getSvgTransformMatrix(): string;
3455
3456 // functions from stateful mixin
3457 // -----------------------------------------------------------------------------------------------------------------------------------
3458 /**
3459 * Returns true if object state (one of its state properties) was changed
3460 * @param {String} [propertySet] optional name for the set of property we want to save
3461 * @return {Boolean} true if instance' state has changed since `{@link fabric.Object#saveState}` was called
3462 */
3463 hasStateChanged(propertySet: string): boolean;
3464 /**
3465 * Saves state of an object
3466 * @param [options] Object with additional `stateProperties` array to include when saving state
3467 * @return thisArg
3468 */
3469 saveState(options?: { stateProperties?: any[]; propertySet?: string }): Object;
3470 /**
3471 * Setups state of an object
3472 * @param {Object} [options] Object with additional `stateProperties` array to include when saving state
3473 * @return {fabric.Object} thisArg
3474 */
3475 setupState(options?: any): Object;
3476 // functions from object straightening mixin
3477 // -----------------------------------------------------------------------------------------------------------------------------------
3478 /**
3479 * Straightens an object (rotating it from current angle to one of 0, 90, 180, 270, etc. depending on which is closer)
3480 */
3481 straighten(): Object;
3482 /**
3483 * Same as straighten but with animation
3484 */
3485 fxStraighten(callbacks: Callbacks): Object;
3486
3487 // functions from object stacking mixin
3488 // -----------------------------------------------------------------------------------------------------------------------------------
3489 /**
3490 * Moves an object up in stack of drawn objects
3491 * @param [intersecting] If `true`, send object in front of next upper intersecting object
3492 */
3493 bringForward(intersecting?: boolean): Object;
3494 /**
3495 * Moves an object to the top of the stack of drawn objects
3496 */
3497 bringToFront(): Object;
3498 /**
3499 * Moves an object down in stack of drawn objects
3500 * @param [intersecting] If `true`, send object behind next lower intersecting object
3501 */
3502 sendBackwards(intersecting?: boolean): Object;
3503 /**
3504 * Moves an object to the bottom of the stack of drawn objects
3505 */
3506 sendToBack(): Object;
3507 /**
3508 * Moves an object to specified level in stack of drawn objects
3509 * @param index New position of object
3510 */
3511 moveTo(index: number): Object;
3512
3513 // functions from object origin mixin
3514 // -----------------------------------------------------------------------------------------------------------------------------------
3515 /**
3516 * Translates the coordinates from origin to center coordinates (based on the object's dimensions)
3517 * @param point The point which corresponds to the originX and originY params
3518 * @param originX Horizontal origin: 'left', 'center' or 'right'
3519 * @param originY Vertical origin: 'top', 'center' or 'bottom'
3520 */
3521 translateToCenterPoint(point: Point, originX: string, originY: string): Point;
3522
3523 /**
3524 * Translates the coordinates from center to origin coordinates (based on the object's dimensions)
3525 * @param center The point which corresponds to center of the object
3526 * @param originX Horizontal origin: 'left', 'center' or 'right'
3527 * @param originY Vertical origin: 'top', 'center' or 'bottom'
3528 */
3529 translateToOriginPoint(center: Point, originX: string, originY: string): Point;
3530 /**
3531 * Returns the real center coordinates of the object
3532 */
3533 getCenterPoint(): Point;
3534
3535 /**
3536 * Returns the coordinates of the object as if it has a different origin
3537 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'
3538 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
3539 * @return {fabric.Point}
3540 */
3541 getPointByOrigin(originX: string, originY: string): Point;
3542
3543 /**
3544 * Returns the point in local coordinates
3545 * @param point The point relative to the global coordinate system
3546 * @param originX Horizontal origin: 'left', 'center' or 'right'
3547 * @param originY Vertical origin: 'top', 'center' or 'bottom'
3548 */
3549 toLocalPoint(point: Point, originX: string, originY: string): Point;
3550
3551 /**
3552 * Sets the position of the object taking into consideration the object's origin
3553 * @param pos The new position of the object
3554 * @param originX Horizontal origin: 'left', 'center' or 'right'
3555 * @param originY Vertical origin: 'top', 'center' or 'bottom'
3556 */
3557 setPositionByOrigin(pos: Point, originX: string, originY: string): void;
3558
3559 /**
3560 * @param to One of 'left', 'center', 'right'
3561 */
3562 adjustPosition(to: string): void;
3563
3564 // functions from interactivity mixin
3565 // -----------------------------------------------------------------------------------------------------------------------------------
3566 /**
3567 * Draws borders of an object's bounding box.
3568 * Requires public properties: width, height
3569 * Requires public options: padding, borderColor
3570 * @param {CanvasRenderingContext2D} ctx Context to draw on
3571 * @param {Object} styleOverride object to override the object style
3572 * @return {fabric.Object} thisArg
3573 * @chainable
3574 */
3575 drawBorders(ctx: CanvasRenderingContext2D, styleOverride?: any): Object;
3576
3577 /**
3578 * Draws borders of an object's bounding box when it is inside a group.
3579 * Requires public properties: width, height
3580 * Requires public options: padding, borderColor
3581 * @param {CanvasRenderingContext2D} ctx Context to draw on
3582 * @param {object} options object representing current object parameters
3583 * @param {Object} styleOverride object to override the object style
3584 * @return {fabric.Object} thisArg
3585 * @chainable
3586 */
3587 drawBordersInGroup(ctx: CanvasRenderingContext2D, options?: any, styleOverride?: any): Object;
3588
3589 /**
3590 * Draws corners of an object's bounding box.
3591 * Requires public properties: width, height
3592 * Requires public options: cornerSize, padding
3593 * @param {CanvasRenderingContext2D} ctx Context to draw on
3594 * @param {Object} styleOverride object to override the object style
3595 * @return {fabric.Object} thisArg
3596 * @chainable
3597 */
3598 drawControls(ctx: CanvasRenderingContext2D, styleOverride?: any): Object;
3599
3600 /**
3601 * Draws a colored layer behind the object, inside its selection borders.
3602 * Requires public options: padding, selectionBackgroundColor
3603 * this function is called when the context is transformed
3604 * has checks to be skipped when the object is on a staticCanvas
3605 * @param {CanvasRenderingContext2D} ctx Context to draw on
3606 * @return {fabric.Object} thisArg
3607 * @chainable
3608 */
3609 drawSelectionBackground(ctx: CanvasRenderingContext2D): Object;
3610
3611 /**
3612 * Draws corners of an object's bounding box.
3613 * Requires public properties: width, height
3614 * Requires public options: cornerSize, padding
3615 * @param ctx Context to draw on
3616 */
3617 drawCorners(context: CanvasRenderingContext2D): Object;
3618
3619 /**
3620 * Returns true if the specified control is visible, false otherwise.
3621 * @param controlName The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
3622 */
3623 isControlVisible(controlName: string): boolean;
3624 /**
3625 * Sets the visibility of the specified control.
3626 * @param controlName The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
3627 * @param visible true to set the specified control visible, false otherwise
3628 */
3629 setControlVisible(controlName: string, visible: boolean): Object;
3630
3631 /**
3632 * Sets the visibility state of object controls.
3633 * @param [options] Options object
3634 */
3635 setControlsVisibility(options?: {
3636 bl?: boolean;
3637 br?: boolean;
3638 mb?: boolean;
3639 ml?: boolean;
3640 mr?: boolean;
3641 mt?: boolean;
3642 tl?: boolean;
3643 tr?: boolean;
3644 mtr?: boolean;
3645 }): this;
3646
3647 // functions from geometry mixin
3648 // -------------------------------------------------------------------------------------------------------------------------------
3649 /**
3650 * Sets corner position coordinates based on current angle, width and height.
3651 * oCoords are used to find the corners
3652 * aCoords are used to quickly find an object on the canvas
3653 * lineCoords are used to quickly find object during pointer events.
3654 * See {@link https://github.com/kangax/fabric.js/wiki/When-to-call-setCoords|When-to-call-setCoords}
3655 * @param {Boolean} [skipCorners] skip calculation of oCoords.
3656 * @return {fabric.Object} thisArg
3657 * @chainable
3658 */
3659 setCoords(skipCorners?: boolean): Object;
3660 /**
3661 * Returns coordinates of object's bounding rectangle (left, top, width, height)
3662 * the box is intented as aligned to axis of canvas.
3663 * @param {Boolean} [absolute] use coordinates without viewportTransform
3664 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords / .aCoords
3665 * @return {Object} Object with left, top, width, height properties
3666 */
3667 getBoundingRect(
3668 absolute?: boolean,
3669 calculate?: boolean,
3670 ): { left: number; top: number; width: number; height: number };
3671 /**
3672 * Checks if object is fully contained within area of another object
3673 * @param {Object} other Object to test
3674 * @param {Boolean} [absolute] use coordinates without viewportTransform
3675 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords
3676 * @return {Boolean} true if object is fully contained within area of another object
3677 */
3678 isContainedWithinObject(other: Object, absolute?: boolean, calculate?: boolean): boolean;
3679 /**
3680 * Checks if object is fully contained within area formed by 2 points
3681 * @param pointTL top-left point of area
3682 * @param pointBR bottom-right point of area
3683 */
3684 isContainedWithinRect(pointTL: any, pointBR: any, absolute?: boolean, calculate?: boolean): boolean;
3685 /**
3686 * Checks if point is inside the object
3687 * @param {fabric.Point} point Point to check against
3688 * @param {Object} [lines] object returned from @method _getImageLines
3689 * @param {Boolean} [absolute] use coordinates without viewportTransform
3690 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords
3691 * @return {Boolean} true if point is inside the object
3692 */
3693 containsPoint(point: Point, lines?: any, absolute?: boolean, calculate?: boolean): boolean;
3694 /**
3695 * Scales an object (equally by x and y)
3696 * @param value Scale factor
3697 * @return thisArg
3698 */
3699 scale(value: number): Object;
3700 /**
3701 * Scales an object to a given height, with respect to bounding box (scaling by x/y equally)
3702 * @param value New height value
3703 */
3704 scaleToHeight(value: number, absolute?: boolean): Object;
3705 /**
3706 * Scales an object to a given width, with respect to bounding box (scaling by x/y equally)
3707 * @param value New width value
3708 */
3709 scaleToWidth(value: number, absolute?: boolean): Object;
3710 /**
3711 * Checks if object intersects with another object
3712 * @param {Object} other Object to test
3713 * @param {Boolean} [absolute] use coordinates without viewportTransform
3714 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords
3715 * @return {Boolean} true if object intersects with another object
3716 */
3717 intersectsWithObject(other: Object, absolute?: boolean, calculate?: boolean): boolean;
3718 /**
3719 * Checks if object intersects with an area formed by 2 points
3720 * @param {Object} pointTL top-left point of area
3721 * @param {Object} pointBR bottom-right point of area
3722 * @param {Boolean} [absolute] use coordinates without viewportTransform
3723 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords
3724 * @return {Boolean} true if object intersects with an area formed by 2 points
3725 */
3726 intersectsWithRect(pointTL: any, pointBR: any, absolute?: boolean, calculate?: boolean): boolean;
3727
3728 /**
3729 * Animates object's properties
3730 * object.animate('left', ..., {duration: ...});
3731 * @param property Property to animate
3732 * @param value Value to animate property
3733 * @param options The animation options
3734 */
3735 animate(property: string, value: number | string, options?: IAnimationOptions): Object;
3736 /**
3737 * Animates object's properties
3738 * object.animate({ left: ..., top: ... }, { duration: ... });
3739 * @param properties Properties to animate with values to animate to
3740 * @param options The animation options
3741 */
3742 animate(properties: { [key: string]: number | string }, options?: IAnimationOptions): Object;
3743 /**
3744 * Calculate and returns the .coords of an object.
3745 * @return {Object} Object with tl, tr, br, bl ....
3746 * @chainable
3747 */
3748 calcCoords(absolute?: boolean): any;
3749 /**
3750 * calculate trasform Matrix that represent current transformation from
3751 * object properties.
3752 * @param {Boolean} [skipGroup] return transformMatrix for object and not go upward with parents
3753 * @return {Array} matrix Transform Matrix for the object
3754 */
3755 calcTransformMatrix(skipGroup?: boolean): any[];
3756 /**
3757 * calculate transform matrix that represents the current transformations from the
3758 * object's properties, this matrix does not include the group transformation
3759 * @return {Array} transform matrix for the object
3760 */
3761 calcOwnMatrix(): any[];
3762 /**
3763 * return correct set of coordinates for intersection
3764 */
3765 getCoords(absolute?: boolean, calculate?: boolean): [fabric.Point, fabric.Point, fabric.Point, fabric.Point];
3766 /**
3767 * Returns height of an object bounding box counting transformations
3768 * before 2.0 it was named getHeight();
3769 * @return {Number} height value
3770 */
3771 getScaledHeight(): number;
3772 /**
3773 * Returns width of an object bounding box counting transformations
3774 * before 2.0 it was named getWidth();
3775 * @return {Number} width value
3776 */
3777 getScaledWidth(): number;
3778 /**
3779 * Returns id attribute for svg output
3780 * @return {String}
3781 */
3782 getSvgCommons(): string;
3783 /**
3784 * Returns filter for svg shadow
3785 * @return {String}
3786 */
3787 getSvgFilter(): string;
3788 /**
3789 * Returns styles-string for svg-export
3790 * @param {Object} style the object from which to retrieve style properties
3791 * @param {Boolean} useWhiteSpace a boolean to include an additional attribute in the style.
3792 * @return {String}
3793 */
3794 getSvgSpanStyles(style: any, useWhiteSpace?: boolean): string;
3795 /**
3796 * Returns text-decoration property for svg-export
3797 * @param {Object} style the object from which to retrieve style properties
3798 * @return {String}
3799 */
3800 getSvgTextDecoration(style: any): string;
3801 /**
3802 * Checks if object is contained within the canvas with current viewportTransform
3803 * the check is done stopping at first point that appears on screen
3804 * @param {Boolean} [calculate] use coordinates of current position instead of .aCoords
3805 * @return {Boolean} true if object is fully or partially contained within canvas
3806 */
3807 isOnScreen(calculate?: boolean): boolean;
3808 /**
3809 * Checks if object is partially contained within the canvas with current viewportTransform
3810 * @param {Boolean} [calculate] use coordinates of current position instead of .oCoords
3811 * @return {Boolean} true if object is partially contained within canvas
3812 */
3813 isPartiallyOnScreen(calculate?: boolean): boolean;
3814 /**
3815 * This callback function is called every time _discardActiveObject or _setActiveObject
3816 * try to to deselect this object. If the function returns true, the process is cancelled
3817 * @return {Boolean} true to cancel selection
3818 */
3819 onDeselect(options: { e?: Event; object?: Object }): boolean;
3820 /**
3821 * This callback function is called every time _discardActiveObject or _setActiveObject
3822 * try to to deselect this object. If the function returns true, the process is cancelled
3823 * @param {Object} [options] options sent from the upper functions
3824 * @param {Event} [options.e] event if the process is generated by an event
3825 */
3826 onDeselect(options: { e?: Event; object?: fabric.Object }): boolean;
3827 /**
3828 * This callback function is called every time _discardActiveObject or _setActiveObject
3829 * try to to select this object. If the function returns true, the process is cancelled
3830 */
3831 onSelect(options: { e?: Event }): boolean;
3832 /**
3833 * Returns svg clipPath representation of an instance
3834 * @param {Function} [reviver] Method for further parsing of svg representation.
3835 * @return {String} svg representation of an instance
3836 */
3837 toClipPathSVG(reviver?: Function): string;
3838 /**
3839 * Returns svg representation of an instance
3840 * @param {Function} [reviver] Method for further parsing of svg representation.
3841 * @return {String} svg representation of an instance
3842 */
3843 toSVG(reviver?: Function): string;
3844 /**
3845 * Translates the coordinates from a set of origin to another (based on the object's dimensions)
3846 * @param {fabric.Point} point The point which corresponds to the originX and originY params
3847 * @param {String} fromOriginX Horizontal origin: 'left', 'center' or 'right'
3848 * @param {String} fromOriginY Vertical origin: 'top', 'center' or 'bottom'
3849 * @param {String} toOriginX Horizontal origin: 'left', 'center' or 'right'
3850 * @param {String} toOriginY Vertical origin: 'top', 'center' or 'bottom'
3851 * @return {fabric.Point}
3852 */
3853 translateToGivenOrigin(
3854 pointL: Point,
3855 fromOriginX: string,
3856 fromOriginY: string,
3857 toOriginX: string,
3858 toOriginY: string,
3859 ): Point;
3860 /*
3861 * Calculate object dimensions from its properties
3862 * @private
3863 * @return {Object} .x width dimension
3864 * @return {Object} .y height dimension
3865 */
3866 _getNonTransformedDimensions(): { x: number; y: number };
3867 /**
3868 * Returns the top, left coordinates
3869 * @private
3870 * @return {fabric.Point}
3871 */
3872 _getLeftTopCoords(): Point;
3873 /*
3874 * Calculate object bounding box dimensions from its properties scale, skew.
3875 * @private
3876 * @return {Object} .x width dimension
3877 * @return {Object} .y height dimension
3878 */
3879 _getTransformedDimensions(skewX?: number, skewY?: number): { x: number; y: number };
3880
3881 /**
3882 * @private
3883 * @param {CanvasRenderingContext2D} ctx Context to render on
3884 */
3885 _renderFill(ctx: CanvasRenderingContext2D): void;
3886 /**
3887 * @param ctx
3888 * @private
3889 */
3890 _renderStroke(ctx: CanvasRenderingContext2D): void;
3891 /**
3892 * @private
3893 * @param {CanvasRenderingContext2D} ctx Context to render on
3894 */
3895 _removeShadow(ctx: CanvasRenderingContext2D): void;
3896 /**
3897 * @private
3898 * Sets line dash
3899 * @param {CanvasRenderingContext2D} ctx Context to set the dash line on
3900 * @param {Array} dashArray array representing dashes
3901 * @param {Function} alternative function to call if browser does not support lineDash
3902 */
3903 _setLineDash(
3904 ctx: CanvasRenderingContext2D,
3905 dashArray: number[],
3906 alternative?: (ctx: CanvasRenderingContext2D) => void,
3907 ): void;
3908 /**
3909 * @private
3910 * @param {CanvasRenderingContext2D} ctx Context to render on
3911 * @param {Object} filler fabric.Pattern or fabric.Gradient
3912 * @return {Object} offset.offsetX offset for text rendering
3913 * @return {Object} offset.offsetY offset for text rendering
3914 */
3915 _applyPatternGradientTransform(ctx: CanvasRenderingContext2D, filler: string | Pattern | Gradient): void;
3916 /**
3917 * @private
3918 * @param {CanvasRenderingContext2D} ctx Context to render on
3919 */
3920 _render(ctx: CanvasRenderingContext2D): void;
3921 /**
3922 * @private
3923 * @param {CanvasRenderingContext2D} ctx Context to render on
3924 */
3925 _renderPaintInOrder(ctx: CanvasRenderingContext2D): void;
3926 /**
3927 * Returns the instance of the control visibility set for this object.
3928 * @private
3929 * @returns {Object}
3930 */
3931 _getControlsVisibility(): {
3932 tl: boolean;
3933 tr: boolean;
3934 br: boolean;
3935 bl: boolean;
3936 ml: boolean;
3937 mt: boolean;
3938 mr: boolean;
3939 mb: boolean;
3940 mtr: boolean;
3941 };
3942 /**
3943 * Determines which corner has been clicked
3944 * @private
3945 * @param {Object} pointer The pointer indicating the mouse position
3946 * @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found
3947 */
3948 _findTargetCorner(pointer: {
3949 x: number;
3950 y: number;
3951 }): boolean | 'bl' | 'br' | 'mb' | 'ml' | 'mr' | 'mt' | 'tl' | 'tr' | 'mtr';
3952 /**
3953 * @private
3954 * @param {String} key
3955 * @param {*} value
3956 */
3957 _set(key: string, value: any): Object;
3958 /**
3959 * Creates fabric Object instance
3960 * @param {string} Class name
3961 * @param {fabric.Object} Original object
3962 * @param {Function} Callback when complete
3963 * @param {Object} Extra parameters for fabric.Object
3964 * @private
3965 * @return {fabric.Object}
3966 */
3967 static _fromObject(className: string, object: Object, callback?: Function, extraParam?: any): Object;
3968 /**
3969 * Defines the number of fraction digits to use when serializing object values.
3970 */
3971 static NUM_FRACTION_DIGITS?: number;
3972}
3973
3974interface IPathOptions extends IObjectOptions {
3975 /**
3976 * Array of path points
3977 */
3978 path?: Point[];
3979}
3980export interface Path extends Object, IPathOptions {}
3981export class Path {
3982 /**
3983 * Constructor
3984 * @param path Path data (sequence of coordinates and corresponding "command" tokens)
3985 * @param [options] Options object
3986 */
3987 constructor(path?: string | Point[], options?: IPathOptions);
3988
3989 pathOffset: Point;
3990
3991 /**
3992 * Returns svg clipPath representation of an instance
3993 * @param {Function} [reviver] Method for further parsing of svg representation.
3994 * @return {String} svg representation of an instance
3995 */
3996 toClipPathSVG(reviver?: Function): string;
3997 /**
3998 * Returns svg representation of an instance
3999 * @param [reviver] Method for further parsing of svg representation.
4000 * @return svg representation of an instance
4001 */
4002 toSVG(reviver?: Function): string;
4003 /**
4004 * Creates an instance of fabric.Path from an SVG <path> element
4005 * @param element to parse
4006 * @param callback Callback to invoke when an fabric.Path instance is created
4007 * @param [options] Options object
4008 */
4009 static fromElement(element: SVGElement, callback: Function, options?: IPathOptions): Path;
4010 /**
4011 * Creates an instance of fabric.Path from an object
4012 * @param callback Callback to invoke when an fabric.Path instance is created
4013 */
4014 static fromObject(object: any, callback: Function): Path;
4015 /**
4016 * List of attribute names to account for when parsing SVG element (used by `fabric.Polygon.fromElement`)
4017 */
4018 static ATTRIBUTE_NAMES: string[];
4019}
4020export interface Polygon extends IPolylineOptions {}
4021export class Polygon extends Polyline {
4022 /**
4023 * Constructor
4024 * @param points Array of points
4025 * @param [options] Options object
4026 */
4027 constructor(points: Array<{ x: number; y: number }>, options?: IPolylineOptions);
4028 /**
4029 * Returns Polygon instance from an SVG element
4030 * @param element Element to parse
4031 * @param [options] Options object
4032 */
4033 static fromElement(element: SVGElement, options?: IPolylineOptions): Polygon;
4034 /**
4035 * Returns fabric.Polygon instance from an object representation
4036 * @param object Object to create an instance from
4037 */
4038 static fromObject(object: any): Polygon;
4039}
4040
4041interface IPolylineOptions extends IObjectOptions {
4042 /**
4043 * Points array
4044 */
4045 points?: Point[];
4046}
4047export interface Polyline extends IPolylineOptions {}
4048export class Polyline extends Object {
4049 /**
4050 * Constructor
4051 * @param points Array of points (where each point is an object with x and y)
4052 * @param [options] Options object
4053 * @param [skipOffset] Whether points offsetting should be skipped
4054 */
4055 constructor(points: Array<{ x: number; y: number }>, options?: IPolylineOptions);
4056
4057 pathOffset: Point;
4058
4059 /**
4060 * Calculate the polygon min and max point from points array,
4061 * returning an object with left, top, width, height to measure the polygon size
4062 * @private
4063 * @return {Object} object.left X coordinate of the polygon leftmost point
4064 * @return {Object} object.top Y coordinate of the polygon topmost point
4065 * @return {Object} object.width distance between X coordinates of the polygon leftmost and rightmost point
4066 * @return {Object} object.height distance between Y coordinates of the polygon topmost and bottommost point
4067 */
4068 _calcDimensions(): { left: number; top: number; width: number; height: number };
4069 /**
4070 * List of attribute names to account for when parsing SVG element (used by `fabric.Polygon.fromElement`)
4071 */
4072 static ATTRIBUTE_NAMES: string[];
4073 /**
4074 * Returns Polyline instance from an SVG element
4075 * @param element Element to parse
4076 * @param [options] Options object
4077 */
4078 static fromElement(element: SVGElement, options?: IPolylineOptions): Polyline;
4079 /**
4080 * Returns fabric.Polyline instance from an object representation
4081 * @param object Object to create an instance from
4082 */
4083 static fromObject(object: any): Polyline;
4084}
4085
4086interface IRectOptions extends IObjectOptions {
4087 /**
4088 * Horizontal border radius
4089 */
4090 rx?: number;
4091
4092 /**
4093 * Vertical border radius
4094 */
4095 ry?: number;
4096}
4097
4098export interface Rect extends IRectOptions {}
4099export class Rect extends Object {
4100 /**
4101 * Constructor
4102 * @param [options] Options object
4103 */
4104 constructor(options?: IRectOptions);
4105 /**
4106 * List of attribute names to account for when parsing SVG element (used by `fabric.Rect.fromElement`)
4107 */
4108 static ATTRIBUTE_NAMES: string[];
4109 /**
4110 * Returns Rect instance from an SVG element
4111 * @param element Element to parse
4112 * @param [options] Options object
4113 */
4114 static fromElement(element: SVGElement, options?: IRectOptions): Rect;
4115 /**
4116 * Returns Rect instance from an object representation
4117 * @param object Object to create an instance from
4118 */
4119 static fromObject(object: any): Rect;
4120}
4121
4122interface TextOptions extends IObjectOptions {
4123 type?: string;
4124 /**
4125 * Font size (in pixels)
4126 * @type Number
4127 */
4128 fontSize?: number;
4129 /**
4130 * Font weight (e.g. bold, normal, 400, 600, 800)
4131 * @type {(Number|String)}
4132 */
4133 fontWeight?: string | number;
4134 /**
4135 * Font family
4136 * @type String
4137 */
4138 fontFamily?: string;
4139 /**
4140 * Text decoration underline.
4141 * @type Boolean
4142 */
4143 underline?: boolean;
4144 /**
4145 * Text decoration overline.
4146 * @type Boolean
4147 */
4148 overline?: boolean;
4149 /**
4150 * Text decoration linethrough.
4151 * @type Boolean
4152 */
4153 linethrough?: boolean;
4154 /**
4155 * Text alignment. Possible values: "left", "center", "right", "justify",
4156 * "justify-left", "justify-center" or "justify-right".
4157 * @type String
4158 */
4159 textAlign?: string;
4160 /**
4161 * Font style . Possible values: "", "normal", "italic" or "oblique".
4162 * @type String
4163 */
4164 fontStyle?: '' | 'normal' | 'italic' | 'oblique';
4165 /**
4166 * Line height
4167 * @type Number
4168 */
4169 lineHeight?: number;
4170 /**
4171 * Superscript schema object (minimum overlap)
4172 * @type {Object}
4173 */
4174 superscript?: { size: number; baseline: number };
4175 /**
4176 * Subscript schema object (minimum overlap)
4177 * @type {Object}
4178 */
4179 subscript?: { size: number; baseline: number };
4180 /**
4181 * Background color of text lines
4182 * @type String
4183 */
4184 textBackgroundColor?: string;
4185 /**
4186 * When defined, an object is rendered via stroke and this property specifies its color.
4187 * <b>Backwards incompatibility note:</b> This property was named "strokeStyle" until v1.1.6
4188 */
4189 stroke?: string;
4190 /**
4191 * Shadow object representing shadow of this shape.
4192 * <b>Backwards incompatibility note:</b> This property was named "textShadow" (String) until v1.2.11
4193 * @type fabric.Shadow
4194 */
4195 shadow?: Shadow | string;
4196 /**
4197 * additional space between characters
4198 * expressed in thousands of em unit
4199 * @type Number
4200 */
4201 charSpacing?: number;
4202 /**
4203 * Object containing character styles - top-level properties -> line numbers,
4204 * 2nd-level properties - charater numbers
4205 * @type Object
4206 */
4207 styles?: any;
4208 /**
4209 * Baseline shift, stlyes only, keep at 0 for the main text object
4210 * @type {Number}
4211 */
4212 deltaY?: number;
4213 text?: string;
4214 /**
4215 * List of properties to consider when checking if cache needs refresh
4216 * @type Array
4217 */
4218 cacheProperties?: string[];
4219 /**
4220 * List of properties to consider when checking if
4221 * state of an object is changed ({@link fabric.Object#hasStateChanged})
4222 * as well as for history (undo/redo) purposes
4223 * @type Array
4224 */
4225 stateProperties?: string[];
4226}
4227export interface Text extends TextOptions {}
4228export class Text extends Object {
4229 _text: string[];
4230 cursorOffsetCache: { top: number; left: number };
4231 /**
4232 * Properties which when set cause object to change dimensions
4233 * @type Object
4234 * @private
4235 */
4236 _dimensionAffectingProps: string[];
4237 /**
4238 * List of lines in text object
4239 * @type Array<string>
4240 */
4241 textLines: string[];
4242 /**
4243 * List of grapheme lines in text object
4244 * @private
4245 * @type Array<string>
4246 */
4247 _textLines: string[][];
4248 /**
4249 * List of unwrapped grapheme lines in text object
4250 * @private
4251 * @type Array<string>
4252 */
4253 _unwrappedTextLines: string[][];
4254 /**
4255 * Use this regular expression to filter for whitespaces that is not a new line.
4256 * Mostly used when text is 'justify' aligned.
4257 * @private
4258 * @type RegExp
4259 */
4260 _reSpacesAndTabs: RegExp;
4261 /**
4262 * Use this regular expression to filter for whitespace that is not a new line.
4263 * Mostly used when text is 'justify' aligned.
4264 * @private
4265 * @type RegExp
4266 */
4267 _reSpaceAndTab: RegExp;
4268 /**
4269 * List of line widths
4270 * @private
4271 * @type Array<Number>
4272 */
4273 __lineWidths: number[];
4274 /**
4275 * List of line heights
4276 * @private
4277 * @type Array<Number>
4278 */
4279 __lineHeights: number[];
4280 /**
4281 * Contains characters bounding boxes for each line and char
4282 * @private
4283 * @type Array of char grapheme bounding boxes
4284 */
4285 __charBounds?: Array<
4286 Array<{ width: number; left: number; height?: number; kernedWidth?: number; deltaY?: number }>
4287 >;
4288 /**
4289 * Text Line proportion to font Size (in pixels)
4290 * @private
4291 * @type Number
4292 */
4293 _fontSizeMult: number;
4294 /**
4295 * @private
4296 * @type Number
4297 */
4298 _fontSizeFraction: number;
4299 /**
4300 * @private
4301 * @type boolean
4302 */
4303 __skipDimension: boolean;
4304 /**
4305 * use this size when measuring text. To avoid IE11 rounding errors
4306 * @type {Number}
4307 * @default
4308 * @readonly
4309 * @private
4310 */
4311 CACHE_FONT_SIZE: number;
4312
4313 /**
4314 * Constructor
4315 * @param text Text string
4316 * @param [options] Options object
4317 */
4318 constructor(text: string, options?: TextOptions);
4319
4320 /**
4321 * Return a context for measurement of text string.
4322 * if created it gets stored for reuse
4323 * @return {fabric.Text} thisArg
4324 */
4325 getMeasuringContext(): CanvasRenderingContext2D;
4326
4327 /**
4328 * Initialize or update text dimensions.
4329 * Updates this.width and this.height with the proper values.
4330 * Does not return dimensions.
4331 */
4332 initDimensions(): void;
4333
4334 /**
4335 * Enlarge space boxes and shift the others
4336 */
4337 enlargeSpaces(): void;
4338
4339 /**
4340 * Detect if the text line is ended with an hard break
4341 * text and itext do not have wrapping, return false
4342 * @return {Boolean}
4343 */
4344 isEndOfWrapping(lineIndex: number): boolean;
4345
4346 /**
4347 * Returns string representation of an instance
4348 */
4349 toString(): string;
4350
4351 /**
4352 * Computes height of character at given position
4353 * @param {Number} line the line number
4354 * @param {Number} char the character number
4355 * @return {Number} fontSize of the character
4356 */
4357 getHeightOfChar(line: number, char: number): number;
4358
4359 /**
4360 * measure a text line measuring all characters.
4361 * @param {Number} lineIndex line number
4362 * @return {Object} object.width total width of characters
4363 * @return {Object} object.numOfSpaces length of chars that match this._reSpacesAndTabs
4364 */
4365 measureLine(lineIndex: number): { width: number; numOfSpaces: number };
4366
4367 /**
4368 * Calculate height of line at 'lineIndex'
4369 * @param {Number} lineIndex index of line to calculate
4370 * @return {Number}
4371 */
4372 getHeightOfLine(lineIndex: number): number;
4373
4374 /**
4375 * Calculate text box height
4376 */
4377 calcTextHeight(): number;
4378
4379 /**
4380 * Turns the character into a 'superior figure' (i.e. 'superscript')
4381 * @param {Number} start selection start
4382 * @param {Number} end selection end
4383 * @returns {fabric.Text} thisArg
4384 * @chainable
4385 */
4386 setSuperscript(start: number, end: number): Text;
4387
4388 /**
4389 * Turns the character into an 'inferior figure' (i.e. 'subscript')
4390 * @param {Number} start selection start
4391 * @param {Number} end selection end
4392 * @returns {fabric.Text} thisArg
4393 * @chainable
4394 */
4395 setSubscript(start: number, end: number): Text;
4396
4397 /**
4398 * Retrieves the value of property at given character position
4399 * @param {Number} lineIndex the line number
4400 * @param {Number} charIndex the charater number
4401 * @param {String} property the property name
4402 * @returns the value of 'property'
4403 */
4404 getValueOfPropertyAt(lineIndex: number, charIndex: number, property: string): any;
4405
4406 static DEFAULT_SVG_FONT_SIZE: number;
4407
4408 /**
4409 * Returns fabric.Text instance from an SVG element (<b>not yet implemented</b>)
4410 * @static
4411 * @memberOf fabric.Text
4412 * @param {SVGElement} element Element to parse
4413 * @param {Function} callback callback function invoked after parsing
4414 * @param {Object} [options] Options object
4415 */
4416 static fromElement(element: SVGElement, callback?: Function, options?: TextOptions): Text;
4417
4418 /**
4419 * Returns fabric.Text instance from an object representation
4420 * @static
4421 * @memberOf fabric.Text
4422 * @param {Object} object Object to create an instance from
4423 * @param {Function} [callback] Callback to invoke when an fabric.Text instance is created
4424 */
4425 static fromObject(object: any, callback?: Function): Text;
4426
4427 /**
4428 * Check if characters in a text have a value for a property
4429 * whose value matches the textbox's value for that property. If so,
4430 * the character-level property is deleted. If the character
4431 * has no other properties, then it is also deleted. Finally,
4432 * if the line containing that character has no other characters
4433 * then it also is deleted.
4434 *
4435 * @param {string} property The property to compare between characters and text.
4436 */
4437 cleanStyle(property: string): void;
4438
4439 /**
4440 * Returns 2d representation (lineIndex and charIndex) of cursor (or selection start)
4441 * @param {Number} [selectionStart] Optional index. When not given, current selectionStart is used.
4442 * @param {Boolean} [skipWrapping] consider the location for unwrapped lines. usefull to manage styles.
4443 */
4444 get2DCursorLocation(selectionStart?: number, skipWrapping?: boolean): { lineIndex: number; charIndex: number };
4445
4446 /**
4447 * return a new object that contains all the style property for a character
4448 * the object returned is newly created
4449 * @param {Number} lineIndex of the line where the character is
4450 * @param {Number} charIndex position of the character on the line
4451 * @return {Object} style object
4452 */
4453 getCompleteStyleDeclaration(lineIndex: number, charIndex: number): any;
4454
4455 /**
4456 * Gets style of a current selection/cursor (at the start position)
4457 * if startIndex or endIndex are not provided, slectionStart or selectionEnd will be used.
4458 * @param {Number} [startIndex] Start index to get styles at
4459 * @param {Number} [endIndex] End index to get styles at, if not specified selectionEnd or startIndex + 1
4460 * @param {Boolean} [complete] get full style or not
4461 * @return {Array} styles an array with one, zero or more Style objects
4462 */
4463 getSelectionStyles(startIndex?: number, endIndex?: number, complete?: boolean): any[];
4464
4465 /**
4466 * Returns styles-string for svg-export
4467 * @param {Boolean} skipShadow a boolean to skip shadow filter output
4468 * @return {String}
4469 */
4470 getSvgStyles(skipShadow?: boolean): string;
4471
4472 /**
4473 * Returns true if object has no styling or no styling in a line
4474 * @param {Number} lineIndex , lineIndex is on wrapped lines.
4475 * @return {Boolean}
4476 */
4477 isEmptyStyles(lineIndex: number): boolean;
4478
4479 /**
4480 * Remove a style property or properties from all individual character styles
4481 * in a text object. Deletes the character style object if it contains no other style
4482 * props. Deletes a line style object if it contains no other character styles.
4483 *
4484 * @param {String} props The property to remove from character styles.
4485 */
4486 removeStyle(property: string): void;
4487
4488 /**
4489 * Sets style of a current selection, if no selection exist, do not set anything.
4490 * @param {Object} [styles] Styles object
4491 * @param {Number} [startIndex] Start index to get styles at
4492 * @param {Number} [endIndex] End index to get styles at, if not specified selectionEnd or startIndex + 1
4493 * @return {fabric.IText} thisArg
4494 * @chainable
4495 */
4496 setSelectionStyles(styles: any, startIndex?: number, endIndex?: number): Text;
4497
4498 /**
4499 * Returns true if object has a style property or has it ina specified line
4500 * @param {Number} lineIndex
4501 * @return {Boolean}
4502 */
4503 styleHas(property: string, lineIndex?: number): boolean;
4504
4505 /**
4506 * Measure a single line given its index. Used to calculate the initial
4507 * text bounding box. The values are calculated and stored in __lineWidths cache.
4508 * @private
4509 * @param {Number} lineIndex line number
4510 * @return {Number} Line width
4511 */
4512 getLineWidth(lineIndex: number): number;
4513
4514 /**
4515 * @private
4516 * @param {Number} lineIndex index text line
4517 * @return {Number} Line left offset
4518 */
4519 _getLineLeftOffset(lineIndex: number): number;
4520
4521 /**
4522 * apply all the character style to canvas for rendering
4523 * @private
4524 * @param {String} _char
4525 * @param {CanvasRenderingContext2D} ctx Context to render on
4526 * @param {Number} lineIndex
4527 * @param {Number} charIndex
4528 * @param {Object} [decl]
4529 */
4530 _applyCharStyles(
4531 method: string,
4532 ctx: CanvasRenderingContext2D,
4533 lineIndex: number,
4534 charIndex: number,
4535 styleDeclaration: any,
4536 ): void;
4537
4538 /**
4539 * get the reference, not a clone, of the style object for a given character
4540 * @param {Number} lineIndex
4541 * @param {Number} charIndex
4542 * @return {Object} style object
4543 */
4544 _getStyleDeclaration(lineIndex: number, charIndex: number): any;
4545
4546 /**
4547 * Generate an object that translates the style object so that it is
4548 * broken up by visual lines (new lines and automatic wrapping).
4549 * The original text styles object is broken up by actual lines (new lines only),
4550 * which is only sufficient for Text / IText
4551 * @private
4552 */
4553 _generateStyleMap(textInfo: {
4554 _unwrappedLines: string[];
4555 lines: string[];
4556 graphemeText: string[];
4557 graphemeLines: string[];
4558 }): { [s: number]: { line: number; offset: number } };
4559
4560 /**
4561 * @private
4562 * Gets the width of character spacing
4563 */
4564 _getWidthOfCharSpacing(): number;
4565
4566 /**
4567 * measure and return the width of a single character.
4568 * possibly overridden to accommodate different measure logic or
4569 * to hook some external lib for character measurement
4570 * @private
4571 * @param {String} char to be measured
4572 * @param {Object} charStyle style of char to be measured
4573 * @param {String} [previousChar] previous char
4574 * @param {Object} [prevCharStyle] style of previous char
4575 * @return {Object} object contained char width anf kerned width
4576 */
4577 _measureChar(
4578 _char: string,
4579 charStyle: any,
4580 previousChar: string,
4581 prevCharStyle: any,
4582 ): { width: number; kernedWidth: number };
4583
4584 /**
4585 * @private
4586 * @param {String} method
4587 * @param {CanvasRenderingContext2D} ctx Context to render on
4588 * @param {String} line Content of the line
4589 * @param {Number} left
4590 * @param {Number} top
4591 * @param {Number} lineIndex
4592 * @param {Number} charOffset
4593 */
4594 _renderChars(
4595 method: string,
4596 ctx: CanvasRenderingContext2D,
4597 line: string,
4598 left: number,
4599 top: number,
4600 lineIndex: number,
4601 ): void;
4602
4603 /**
4604 * @private
4605 * @param {String} method
4606 * @param {CanvasRenderingContext2D} ctx Context to render on
4607 * @param {Number} lineIndex
4608 * @param {Number} charIndex
4609 * @param {String} _char
4610 * @param {Number} left Left coordinate
4611 * @param {Number} top Top coordinate
4612 * @param {Number} lineHeight Height of the line
4613 */
4614 _renderChar(
4615 method: string,
4616 ctx: CanvasRenderingContext2D,
4617 lineIndex: number,
4618 charIndex: number,
4619 _char: string,
4620 left: number,
4621 top: number,
4622 ): void;
4623
4624 /**
4625 * @private
4626 * @param {String} method Method name ("fillText" or "strokeText")
4627 * @param {CanvasRenderingContext2D} ctx Context to render on
4628 * @param {Array} line Text to render
4629 * @param {Number} left Left position of text
4630 * @param {Number} top Top position of text
4631 * @param {Number} lineIndex Index of a line in a text
4632 */
4633 _renderTextLine(
4634 method: string,
4635 ctx: CanvasRenderingContext2D,
4636 line: string[],
4637 left: number,
4638 top: number,
4639 lineIndex: number,
4640 ): void;
4641
4642 /**
4643 * @private
4644 * @param {CanvasRenderingContext2D} ctx Context to render on
4645 */
4646 _renderText(ctx: CanvasRenderingContext2D): void;
4647
4648 /**
4649 * @private
4650 */
4651 _clearCache(): void;
4652
4653 /**
4654 * Divides text into lines of text and lines of graphemes.
4655 * @private
4656 * @returns {Object} Lines and text in the text
4657 */
4658 _splitText(): { _unwrappedLines: string[]; lines: string[]; graphemeText: string[]; graphemeLines: string[] };
4659
4660 /**
4661 * @private
4662 * @param {Object} prevStyle
4663 * @param {Object} thisStyle
4664 */
4665 _hasStyleChanged(prevStyle: any, thisStyle: any): boolean;
4666
4667 /**
4668 * Set the font parameter of the context with the object properties or with charStyle
4669 * @private
4670 * @param {CanvasRenderingContext2D} ctx Context to render on
4671 * @param {Object} [charStyle] object with font style properties
4672 * @param {String} [charStyle.fontFamily] Font Family
4673 * @param {Number} [charStyle.fontSize] Font size in pixels. ( without px suffix )
4674 * @param {String} [charStyle.fontWeight] Font weight
4675 * @param {String} [charStyle.fontStyle] Font style (italic|normal)
4676 */
4677 _setTextStyles(
4678 ctx: CanvasRenderingContext2D,
4679 charStyle?: { fontFamily: string; fontSize: number; fontWieght: string; fontStyle: string },
4680 forMeasuring?: boolean,
4681 ): void;
4682
4683 /**
4684 * @private
4685 * @param {String} method Method name ("fillText" or "strokeText")
4686 * @param {CanvasRenderingContext2D} ctx Context to render on
4687 * @param {String} line Text to render
4688 * @param {Number} left Left position of text
4689 * @param {Number} top Top position of text
4690 * @param {Number} lineIndex Index of a line in a text
4691 */
4692 _renderTextLine(
4693 method: string,
4694 ctx: CanvasRenderingContext2D,
4695 line: string,
4696 left: number,
4697 top: number,
4698 lineIndex: number,
4699 ): void;
4700
4701 /**
4702 * @private
4703 */
4704 _shouldClearDimensionCache(): boolean;
4705}
4706interface ITextOptions extends TextOptions {
4707 /**
4708 * Index where text selection starts (or where cursor is when there is no selection)
4709 * @type Number
4710 */
4711 selectionStart?: number;
4712 /**
4713 * Index where text selection ends
4714 * @type Number
4715 */
4716 selectionEnd?: number;
4717 /**
4718 * Color of text selection
4719 * @type String
4720 */
4721 selectionColor?: string;
4722 /**
4723 * Indicates whether text is selected
4724 * @type Boolean
4725 */
4726 selected?: boolean;
4727 /**
4728 * Indicates whether text is in editing mode
4729 * @type Boolean
4730 */
4731 isEditing?: boolean;
4732 /**
4733 * Indicates whether a text can be edited
4734 * @type Boolean
4735 */
4736 editable?: boolean;
4737 /**
4738 * Border color of text object while it's in editing mode
4739 * @type String
4740 */
4741 editingBorderColor?: string;
4742 /**
4743 * Width of cursor (in px)
4744 * @type Number
4745 */
4746 cursorWidth?: number;
4747 /**
4748 * Color of default cursor (when not overwritten by character style)
4749 * @type String
4750 */
4751 cursorColor?: string;
4752 /**
4753 * Delay between cursor blink (in ms)
4754 * @type Number
4755 */
4756 cursorDelay?: number;
4757 /**
4758 * Duration of cursor fadein (in ms)
4759 * @type Number
4760 */
4761 cursorDuration?: number;
4762 /**
4763 * Indicates whether internal text char widths can be cached
4764 * @type Boolean
4765 */
4766 caching?: boolean;
4767 /**
4768 * Helps determining when the text is in composition, so that the cursor
4769 * rendering is altered.
4770 */
4771 inCompositionMode?: boolean;
4772 path?: string;
4773 useNative?: boolean;
4774 /**
4775 * For functionalities on keyDown + ctrl || cmd
4776 */
4777 ctrlKeysMapDown?: any;
4778 /**
4779 * For functionalities on keyUp + ctrl || cmd
4780 */
4781 ctrlKeysMapUp?: any;
4782 /**
4783 * For functionalities on keyDown
4784 * Map a special key to a function of the instance/prototype
4785 * If you need different behaviour for ESC or TAB or arrows, you have to change
4786 * this map setting the name of a function that you build on the fabric.Itext or
4787 * your prototype.
4788 * the map change will affect all Instances unless you need for only some text Instances
4789 * in that case you have to clone this object and assign your Instance.
4790 * this.keysMap = fabric.util.object.clone(this.keysMap);
4791 * The function must be in fabric.Itext.prototype.myFunction And will receive event as args[0]
4792 */
4793 keysMap?: any;
4794 /**
4795 * Exposes underlying hidden text area
4796 */
4797 hiddenTextarea?: HTMLTextAreaElement;
4798}
4799export interface IText extends ITextOptions {}
4800export class IText extends Text {
4801 fromPaste: boolean;
4802 /**
4803 * @private
4804 */
4805 _currentCursorOpacity: number;
4806 /**
4807 * @private
4808 */
4809 _reSpace: RegExp;
4810 /**
4811 * Constructor
4812 * @param text Text string
4813 * @param [options] Options object
4814 */
4815 constructor(text: string, options?: ITextOptions);
4816 /**
4817 * Sets selection start (left boundary of a selection)
4818 * @param {Number} index Index to set selection start to
4819 */
4820 setSelectionStart(index: number): void;
4821 /**
4822 * Sets selection end (right boundary of a selection)
4823 * @param {Number} index Index to set selection end to
4824 */
4825 setSelectionEnd(index: number): void;
4826 /**
4827 * Prepare and clean the contextTop
4828 */
4829 clearContextTop(skipRestore?: boolean): void;
4830 /**
4831 * Renders cursor or selection (depending on what exists)
4832 */
4833 renderCursorOrSelection(): void;
4834 /**
4835 * Renders cursor
4836 * @param {Object} boundaries
4837 * @param {CanvasRenderingContext2D} ctx transformed context to draw on
4838 */
4839 renderCursor(boundaries: any, ctx: CanvasRenderingContext2D): void;
4840 /**
4841 * Renders text selection
4842 * @param {Object} boundaries Object with left/top/leftOffset/topOffset
4843 * @param {CanvasRenderingContext2D} ctx transformed context to draw on
4844 */
4845 renderSelection(boundaries: any, ctx: CanvasRenderingContext2D): void;
4846 /**
4847 * High level function to know the height of the cursor.
4848 * the currentChar is the one that precedes the cursor
4849 * Returns fontSize of char at the current cursor
4850 * @return {Number} Character font size
4851 */
4852 getCurrentCharFontSize(): number;
4853 /**
4854 * High level function to know the color of the cursor.
4855 * the currentChar is the one that precedes the cursor
4856 * Returns color (fill) of char at the current cursor
4857 * @return {String} Character color (fill)
4858 */
4859 getCurrentCharColor(): string;
4860 /**
4861 * Returns fabric.IText instance from an object representation
4862 * @static
4863 * @memberOf fabric.IText
4864 * @param {Object} object Object to create an instance from
4865 * @param {function} [callback] invoked with new instance as argument
4866 */
4867 static fromObject(object: any, callback?: Function): IText;
4868 /**
4869 * Initializes all the interactive behavior of IText
4870 */
4871 initBehavior(): void;
4872 /**
4873 * Initializes "added" event handler
4874 */
4875 initAddedHandler(): void;
4876 /**
4877 * Initializes delayed cursor
4878 */
4879 initDelayedCursor(): void;
4880 /**
4881 * Aborts cursor animation and clears all timeouts
4882 */
4883 abortCursorAnimation(): void;
4884 /**
4885 * Selects entire text
4886 * @return {fabric.IText} thisArg
4887 * @chainable
4888 */
4889 selectAll(): IText;
4890 /**
4891 * Returns selected text
4892 * @return {String}
4893 */
4894 getSelectedText(): string;
4895 /**
4896 * Find new selection index representing start of current word according to current selection index
4897 * @param {Number} startFrom Surrent selection index
4898 * @return {Number} New selection index
4899 */
4900 findWordBoundaryLeft(startFrom: number): number;
4901 /**
4902 * Find new selection index representing end of current word according to current selection index
4903 * @param {Number} startFrom Current selection index
4904 * @return {Number} New selection index
4905 */
4906 findWordBoundaryRight(startFrom: number): number;
4907 /**
4908 * Find new selection index representing start of current line according to current selection index
4909 * @param {Number} startFrom Current selection index
4910 * @return {Number} New selection index
4911 */
4912 findLineBoundaryLeft(startFrom: number): number;
4913 /**
4914 * Find new selection index representing end of current line according to current selection index
4915 * @param {Number} startFrom Current selection index
4916 * @return {Number} New selection index
4917 */
4918 findLineBoundaryRight(startFrom: number): number;
4919 /**
4920 * Finds index corresponding to beginning or end of a word
4921 * @param {Number} selectionStart Index of a character
4922 * @param {Number} direction 1 or -1
4923 * @return {Number} Index of the beginning or end of a word
4924 */
4925 searchWordBoundary(selectionStart: number, direction: number): number;
4926 /**
4927 * Selects a word based on the index
4928 * @param {Number} selectionStart Index of a character
4929 */
4930 selectWord(selectionStart: number): void;
4931 /**
4932 * Selects a line based on the index
4933 * @param {Number} selectionStart Index of a character
4934 * @return {fabric.IText} thisArg
4935 * @chainable
4936 */
4937 selectLine(selectionStart: number): IText;
4938 /**
4939 * Enters editing state
4940 * @return {fabric.IText} thisArg
4941 * @chainable
4942 */
4943 enterEditing(e?: MouseEvent): IText;
4944 /**
4945 * Initializes "mousemove" event handler
4946 */
4947 initMouseMoveHandler(): void;
4948 /**
4949 * Exits from editing state
4950 * @return {fabric.IText} thisArg
4951 * @chainable
4952 */
4953 exitEditing(): IText;
4954 /**
4955 * remove and reflow a style block from start to end.
4956 * @param {Number} start linear start position for removal (included in removal)
4957 * @param {Number} end linear end position for removal ( excluded from removal )
4958 */
4959 removeStyleFromTo(start: number, end: number): void;
4960 /**
4961 * Shifts line styles up or down
4962 * @param {Number} lineIndex Index of a line
4963 * @param {Number} offset Can any number?
4964 */
4965 shiftLineStyles(lineIndex: number, offset: number): void;
4966 /**
4967 * Inserts new style object
4968 * @param {Number} lineIndex Index of a line
4969 * @param {Number} charIndex Index of a char
4970 * @param {Number} qty number of lines to add
4971 * @param {Array} copiedStyle Array of objects styles
4972 */
4973 insertNewlineStyleObject(lineIndex: number, charIndex: number, qty: number, copiedStyle: any[]): void;
4974 /**
4975 * Inserts style object for a given line/char index
4976 * @param {Number} lineIndex Index of a line
4977 * @param {Number} charIndex Index of a char
4978 * @param {Number} quantity number Style object to insert, if given
4979 * @param {Array} copiedStyle array of style objecs
4980 */
4981 insertCharStyleObject(lineIndex: number, charIndex: number, quantity: number, copiedStyle: any[]): void;
4982 /**
4983 * Inserts style object(s)
4984 * @param {Array} insertedText Characters at the location where style is inserted
4985 * @param {Number} start cursor index for inserting style
4986 * @param {Array} [copiedStyle] array of style objects to insert.
4987 */
4988 insertNewStyleBlock(insertedText: any[], start: number, copiedStyle?: any[]): void;
4989 /**
4990 * Set the selectionStart and selectionEnd according to the ne postion of cursor
4991 * mimic the key - mouse navigation when shift is pressed.
4992 */
4993 setSelectionStartEndWithShift(start: number, end: number, newSelection: number): void;
4994 /**
4995 * Copies selected text
4996 */
4997 copy(): void;
4998 /**
4999 * convert from fabric to textarea values
5000 */
5001 fromGraphemeToStringSelection(
5002 start: number,
5003 end: number,
5004 _text: string,
5005 ): { selectionStart: number; selectionEnd: number };
5006 /**
5007 * convert from textarea to grapheme indexes
5008 */
5009 fromStringToGraphemeSelection(
5010 start: number,
5011 end: number,
5012 text: string,
5013 ): { selectionStart: number; selectionEnd: number };
5014 /**
5015 * Gets start offset of a selection
5016 * @param {Event} e Event object
5017 * @param {Boolean} isRight
5018 * @return {Number}
5019 */
5020 getDownCursorOffset(e: Event, isRight?: boolean): number;
5021 /**
5022 * Returns index of a character corresponding to where an object was clicked
5023 * @param {Event} e Event object
5024 * @return {Number} Index of a character
5025 */
5026 getSelectionStartFromPointer(e: Event): number;
5027 /**
5028 * @param {Event} e Event object
5029 * @param {Boolean} isRight
5030 * @return {Number}
5031 */
5032 getUpCursorOffset(e: Event, isRight?: boolean): number;
5033 /**
5034 * Initializes double and triple click event handlers
5035 */
5036 initClicks(): void;
5037 /**
5038 * Initializes event handlers related to cursor or selection
5039 */
5040 initCursorSelectionHandlers(): void;
5041 /**
5042 * Initializes "dbclick" event handler
5043 */
5044 initDoubleClickSimulation(): void;
5045 /**
5046 * Initializes hidden textarea (needed to bring up keyboard in iOS)
5047 */
5048 initHiddenTextarea(): void;
5049 /**
5050 * Initializes "mousedown" event handler
5051 */
5052 initMousedownHandler(): void;
5053 /**
5054 * Initializes "mouseup" event handler
5055 */
5056 initMouseupHandler(): void;
5057 /**
5058 * insert characters at start position, before start position.
5059 * start equal 1 it means the text get inserted between actual grapheme 0 and 1
5060 * if style array is provided, it must be as the same length of text in graphemes
5061 * if end is provided and is bigger than start, old text is replaced.
5062 * start/end ar per grapheme position in _text array.
5063 *
5064 * @param {String} text text to insert
5065 * @param {Array} style array of style objects
5066 * @param {Number} start
5067 * @param {Number} end default to start + 1
5068 */
5069 insertChars(text: string, style: any[], start: number, end: number): void;
5070 /**
5071 * Moves cursor down
5072 * @param {Event} e Event object
5073 */
5074 moveCursorDown(e: Event): void;
5075 /**
5076 * Moves cursor left
5077 * @param {Event} e Event object
5078 */
5079 moveCursorLeft(e: Event): void;
5080 /**
5081 * Moves cursor left without keeping selection
5082 * @param {Event} e
5083 */
5084 moveCursorLeftWithoutShift(e: Event): void;
5085 /**
5086 * Moves cursor left while keeping selection
5087 * @param {Event} e
5088 */
5089 moveCursorLeftWithShift(e: Event): void;
5090 /**
5091 * Moves cursor right
5092 * @param {Event} e Event object
5093 */
5094 moveCursorRight(e: Event): void;
5095 /**
5096 * Moves cursor right without keeping selection
5097 * @param {Event} e Event object
5098 */
5099 moveCursorRightWithoutShift(e: Event): void;
5100 /**
5101 * Moves cursor right while keeping selection
5102 * @param {Event} e
5103 */
5104 moveCursorRightWithShift(e: Event): void;
5105 /**
5106 * Moves cursor up
5107 * @param {Event} e Event object
5108 */
5109 moveCursorUp(e: Event): void;
5110 /**
5111 * Moves cursor up without shift
5112 * @param {Number} offset
5113 */
5114 moveCursorWithoutShift(offset: number): void;
5115 /**
5116 * Moves cursor with shift
5117 * @param {Number} offset
5118 */
5119 moveCursorWithShift(offset: number): void;
5120 /**
5121 * Composition end
5122 */
5123 onCompositionEnd(): void;
5124 /**
5125 * Composition start
5126 */
5127 onCompositionStart(): void;
5128 /**
5129 * Handles onInput event
5130 * @param {Event} e Event object
5131 */
5132 onInput(e: Event): void;
5133 /**
5134 * Handles keyup event
5135 * @param {Event} e Event object
5136 */
5137 onKeyDown(e: Event): void;
5138 /**
5139 * Handles keyup event
5140 * We handle KeyUp because ie11 and edge have difficulties copy/pasting
5141 * if a copy/cut event fired, keyup is dismissed
5142 * @param {Event} e Event object
5143 */
5144 onKeyUp(e: Event): void;
5145 /**
5146 * Pastes text
5147 */
5148 paste(): void;
5149 /**
5150 * Removes characters from start/end
5151 * start/end ar per grapheme position in _text array.
5152 *
5153 * @param {Number} start
5154 * @param {Number} end default to start + 1
5155 */
5156 removeChars(start: number, end: number): void;
5157 /**
5158 * Changes cursor location in a text depending on passed pointer (x/y) object
5159 * @param {Event} e Event object
5160 */
5161 setCursorByClick(e: Event): void;
5162 /**
5163 * @private
5164 */
5165 _getNewSelectionStartFromOffset(
5166 mouseOffset: { x: number; y: number },
5167 prevWidth: number,
5168 width: number,
5169 index: number,
5170 jlen: number,
5171 ): number;
5172 /**
5173 * @private
5174 * @param {CanvasRenderingContext2D} ctx Context to render on
5175 */
5176 _render(ctx: CanvasRenderingContext2D): void;
5177 /**
5178 * @private
5179 */
5180 _updateTextarea(): void;
5181 /**
5182 * @private
5183 */
5184 updateFromTextArea(): void;
5185 /**
5186 * Default event handler for the basic functionalities needed on _mouseDown
5187 * can be overridden to do something different.
5188 * Scope of this implementation is: find the click position, set selectionStart
5189 * find selectionEnd, initialize the drawing of either cursor or selection area
5190 * @private
5191 * @param {Object} Options (seems to have an event `e` parameter
5192 */
5193 _mouseDownHandler(options: any): void;
5194 /**
5195 * @private
5196 * @return {Object} style contains style for hiddenTextarea
5197 */
5198 _calcTextareaPosition(): { left: string; top: string; fontSize: string; charHeight: number };
5199}
5200interface ITextboxOptions extends ITextOptions {
5201 /**
5202 * Minimum width of textbox, in pixels.
5203 * @type Number
5204 */
5205 minWidth?: number;
5206 /**
5207 * Minimum calculated width of a textbox, in pixels.
5208 * fixed to 2 so that an empty textbox cannot go to 0
5209 * and is still selectable without text.
5210 * @type Number
5211 */
5212 dynamicMinWidth?: number;
5213 /**
5214 * Override standard Object class values
5215 */
5216 lockScalingFlip?: boolean;
5217 /**
5218 * Override standard Object class values
5219 * Textbox needs this on false
5220 */
5221 noScaleCache?: boolean;
5222 /**
5223 * Use this boolean property in order to split strings that have no white space concept.
5224 * this is a cheap way to help with chinese/japaense
5225 * @type Boolean
5226 * @since 2.6.0
5227 */
5228 splitByGrapheme?: boolean;
5229 /**
5230 * Is the text wrapping
5231 * @type Boolean
5232 */
5233 isWrapping?: boolean;
5234}
5235export interface Textbox extends ITextboxOptions {}
5236export class Textbox extends IText {
5237 /**
5238 * Constructor
5239 * @param text Text string
5240 * @param [options] Options object
5241 */
5242 constructor(text: string, options?: ITextboxOptions);
5243 /**
5244 * Returns true if object has a style property or has it ina specified line
5245 * @param {Number} lineIndex
5246 * @return {Boolean}
5247 */
5248 styleHas(property: string, lineIndex: number): boolean;
5249 /**
5250 * Returns true if object has no styling or no styling in a line
5251 * @param {Number} lineIndex , lineIndex is on wrapped lines.
5252 * @return {Boolean}
5253 */
5254 isEmptyStyles(lineIndex: number): boolean;
5255 /**
5256 * Detect if the text line is ended with an hard break
5257 * text and itext do not have wrapping, return false
5258 * @param {Number} lineIndex text to split
5259 * @return {Boolean}
5260 */
5261 isEndOfWrapping(lineIndex: number): boolean;
5262 /**
5263 * Returns larger of min width and dynamic min width
5264 * @return {Number}
5265 */
5266 getMinWidth(): number;
5267 /**
5268 * Use this regular expression to split strings in breakable lines
5269 * @private
5270 * @type RegExp
5271 */
5272 _wordJoiners: RegExp;
5273 /**
5274 * Helper function to measure a string of text, given its lineIndex and charIndex offset
5275 * it gets called when charBounds are not available yet.
5276 * @private
5277 * @param {Array} text characters
5278 * @param {number} lineIndex
5279 * @param {number} charOffset
5280 * @returns {number}
5281 */
5282 _measureWord(word: string[], lineIndex: number, charOffset: number): number;
5283 /**
5284 * Wraps text using the 'width' property of Textbox. First this function
5285 * splits text on newlines, so we preserve newlines entered by the user.
5286 * Then it wraps each line using the width of the Textbox by calling
5287 * _wrapLine().
5288 * @param {Array} lines The string array of text that is split into lines
5289 * @param {Number} desiredWidth width you want to wrap to
5290 * @returns {Array} Array of grapheme lines
5291 */
5292 _wrapText(lines: string[], desiredWidth: number): string[][];
5293 /**
5294 * Style objects for each line
5295 * Generate an object that translates the style object so that it is
5296 * broken up by visual lines (new lines and automatic wrapping).
5297 * The original text styles object is broken up by actual lines (new lines only),
5298 * which is only sufficient for Text / IText
5299 * @private
5300 * @type {Array} Line style { line: number, offset: number }
5301 */
5302 _styleMap?: { [s: number]: { line: number; offset: number } };
5303 /**
5304 * Returns fabric.Textbox instance from an object representation
5305 * @static
5306 * @memberOf fabric.Textbox
5307 * @param {Object} object Object to create an instance from
5308 * @param {Function} [callback] Callback to invoke when an fabric.Textbox instance is created
5309 */
5310 static fromObject(object: any, callback?: Function): Textbox;
5311}
5312interface ITriangleOptions extends IObjectOptions {}
5313export class Triangle extends Object {
5314 /**
5315 * Constructor
5316 * @param [options] Options object
5317 */
5318 constructor(options?: ITriangleOptions);
5319 /**
5320 * Returns SVG representation of an instance
5321 * @param [reviver] Method for further parsing of svg representation.
5322 * @return svg representation of an instance
5323 */
5324 toSVG(reviver?: Function): string;
5325 /**
5326 * Returns Triangle instance from an object representation
5327 * @param object Object to create an instance from
5328 */
5329 static fromObject(object: any): Triangle;
5330}
5331
5332////////////////////////////////////////////////////////////
5333// Filters
5334////////////////////////////////////////////////////////////
5335interface IAllFilters {
5336 BaseFilter: {
5337 /**
5338 * Constructor
5339 * @param [options] Options object
5340 */
5341 new (options?: any): IBaseFilter;
5342 };
5343 BlendColor: {
5344 /**
5345 * Constructor
5346 * @param [options] Options object
5347 */
5348 new (options?: { color?: string; mode?: string; alpha?: number }): IBlendColorFilter;
5349 /**
5350 * Returns filter instance from an object representation
5351 * @param object Object to create an instance from
5352 */
5353 fromObject(object: any): IBlendColorFilter;
5354 };
5355 BlendImage: {
5356 /**
5357 * Constructor
5358 * @param [options] Options object
5359 */
5360 new (options?: { image?: Image; mode?: string; alpha?: number }): IBlendImageFilter;
5361 /**
5362 * Returns filter instance from an object representation
5363 * @param object Object to create an instance from
5364 */
5365 fromObject(object: any): IBlendImageFilter;
5366 };
5367 Brightness: {
5368 new (options?: {
5369 /**
5370 * Value to brighten the image up (0..255)
5371 * @default 0
5372 */
5373 brightness: number;
5374 }): IBrightnessFilter;
5375 /**
5376 * Returns filter instance from an object representation
5377 * @param object Object to create an instance from
5378 */
5379 fromObject(object: any): IBrightnessFilter;
5380 };
5381 ColorMatrix: {
5382 new (options?: {
5383 /** Filter matrix */
5384 matrix?: number[];
5385 }): IColorMatrix;
5386 /**
5387 * Returns filter instance from an object representation
5388 * @param object Object to create an instance from
5389 */
5390 fromObject(object: any): IColorMatrix;
5391 };
5392 Contrast: {
5393 /**
5394 * Constructor
5395 * @param [options] Options object
5396 */
5397 new (options?: { contrast?: number }): IContrastFilter;
5398 /**
5399 * Returns filter instance from an object representation
5400 * @param object Object to create an instance from
5401 */
5402 fromObject(object: any): IContrastFilter;
5403 };
5404 Convolute: {
5405 new (options?: {
5406 opaque?: boolean;
5407 /** Filter matrix */
5408 matrix?: number[];
5409 }): IConvoluteFilter;
5410 /**
5411 * Returns filter instance from an object representation
5412 * @param object Object to create an instance from
5413 */
5414 fromObject(object: any): IConvoluteFilter;
5415 };
5416 GradientTransparency: {
5417 new (options?: {
5418 /** @default 100 */
5419 threshold?: number;
5420 }): IGradientTransparencyFilter;
5421 /**
5422 * Returns filter instance from an object representation
5423 * @param object Object to create an instance from
5424 */
5425 fromObject(object: any): IGradientTransparencyFilter;
5426 };
5427 Grayscale: {
5428 new (options?: any): IGrayscaleFilter;
5429 /**
5430 * Returns filter instance from an object representation
5431 * @param object Object to create an instance from
5432 */
5433 fromObject(object: any): IGrayscaleFilter;
5434 };
5435 Invert: {
5436 /**
5437 * Constructor
5438 * @param [options] Options object
5439 */
5440 new (options?: any): IInvertFilter;
5441 /**
5442 * Returns filter instance from an object representation
5443 * @param object Object to create an instance from
5444 */
5445 fromObject(object: any): IInvertFilter;
5446 };
5447 Mask: {
5448 new (options?: {
5449 /** Mask image object */
5450 mask?: Image;
5451 /**
5452 * Rgb channel (0, 1, 2 or 3)
5453 * @default 0
5454 */
5455 channel: number;
5456 }): IMaskFilter;
5457 /**
5458 * Returns filter instance from an object representation
5459 * @param object Object to create an instance from
5460 */
5461 fromObject(object: any): IMaskFilter;
5462 };
5463 Multiply: {
5464 new (options?: {
5465 /**
5466 * Color to multiply the image pixels with
5467 * @default #000000
5468 */
5469 color: string;
5470 }): IMultiplyFilter;
5471 /**
5472 * Returns filter instance from an object representation
5473 * @param object Object to create an instance from
5474 */
5475 fromObject(object: any): IMultiplyFilter;
5476 };
5477 Noise: {
5478 new (options?: {
5479 /** @default 0 */
5480 noise: number;
5481 }): INoiseFilter;
5482 /**
5483 * Returns filter instance from an object representation
5484 * @param object Object to create an instance from
5485 */
5486 fromObject(object: any): INoiseFilter;
5487 };
5488 Pixelate: {
5489 new (options?: {
5490 /**
5491 * Blocksize for pixelate
5492 * @default 4
5493 */
5494 blocksize?: number;
5495 }): IPixelateFilter;
5496 /**
5497 * Returns filter instance from an object representation
5498 * @param object Object to create an instance from
5499 */
5500 fromObject(object: any): IPixelateFilter;
5501 };
5502 RemoveWhite: {
5503 new (options?: {
5504 /** @default 30 */
5505 threshold?: number;
5506 /** @default 20 */
5507 distance?: number;
5508 }): IRemoveWhiteFilter;
5509 /**
5510 * Returns filter instance from an object representation
5511 * @param object Object to create an instance from
5512 */
5513 fromObject(object: any): IRemoveWhiteFilter;
5514 };
5515 Resize: {
5516 new (options?: any): IResizeFilter;
5517 /**
5518 * Returns filter instance from an object representation
5519 * @param object Object to create an instance from
5520 */
5521 fromObject(object: any): IResizeFilter;
5522 };
5523 Saturation: {
5524 /**
5525 * Constructor
5526 * @param [options] Options object
5527 */
5528 new (options?: { saturation?: number }): ISaturationFilter;
5529 /**
5530 * Returns filter instance from an object representation
5531 * @param object Object to create an instance from
5532 */
5533 fromObject(object: any): ISaturationFilter;
5534 };
5535 Sepia2: {
5536 new (options?: any): ISepia2Filter;
5537 /**
5538 * Returns filter instance from an object representation
5539 * @param object Object to create an instance from
5540 */
5541 fromObject(object: any): ISepia2Filter;
5542 };
5543 Sepia: {
5544 new (options?: any): ISepiaFilter;
5545 /**
5546 * Returns filter instance from an object representation
5547 * @param object Object to create an instance from
5548 */
5549 fromObject(object: any): ISepiaFilter;
5550 };
5551 Tint: {
5552 new (options?: {
5553 /**
5554 * Color to tint the image with
5555 * @default #000000
5556 */
5557 color?: string;
5558 /** Opacity value that controls the tint effect's transparency (0..1) */
5559 opacity?: number;
5560 }): ITintFilter;
5561 /**
5562 * Returns filter instance from an object representation
5563 * @param object Object to create an instance from
5564 */
5565 fromObject(object: any): ITintFilter;
5566 };
5567}
5568interface IBaseFilter {
5569 /**
5570 * Sets filter's properties from options
5571 * @param [options] Options object
5572 */
5573 setOptions(options?: any): void;
5574 /**
5575 * Returns object representation of an instance
5576 */
5577 toObject(): any;
5578 /**
5579 * Returns a JSON representation of an instance
5580 */
5581 toJSON(): string;
5582 /**
5583 * Apply the operation to a Uint8Array representing the pixels of an image.
5584 *
5585 * @param {Object} options
5586 * @param {ImageData} options.imageData The Uint8Array to be filtered.
5587 */
5588 applyTo2d(options: any): void;
5589}
5590interface IBlendColorFilter extends IBaseFilter {
5591 color?: string;
5592 mode?: string;
5593 alpha?: number;
5594 /**
5595 * Applies filter to canvas element
5596 * @param canvasEl Canvas element to apply filter to
5597 */
5598 applyTo(canvasEl: HTMLCanvasElement): void;
5599}
5600interface IBlendImageFilter extends IBaseFilter {
5601 /**
5602 * Applies filter to canvas element
5603 * @param canvasEl Canvas element to apply filter to
5604 */
5605 applyTo(canvasEl: HTMLCanvasElement): void;
5606}
5607interface IBrightnessFilter extends IBaseFilter {
5608 /**
5609 * Applies filter to canvas element
5610 * @param canvasEl Canvas element to apply filter to
5611 */
5612 applyTo(canvasEl: HTMLCanvasElement): void;
5613}
5614interface IColorMatrix extends IBaseFilter {
5615 matrix?: number[];
5616 /**
5617 * Applies filter to canvas element
5618 * @param canvasEl Canvas element to apply filter to
5619 */
5620 applyTo(canvasEl: HTMLCanvasElement): void;
5621}
5622interface IContrastFilter extends IBaseFilter {
5623 /**
5624 * Applies filter to canvas element
5625 * @param canvasEl Canvas element to apply filter to
5626 */
5627 applyTo(canvasEl: HTMLCanvasElement): void;
5628}
5629interface IConvoluteFilter extends IBaseFilter {
5630 /**
5631 * Applies filter to canvas element
5632 * @param canvasEl Canvas element to apply filter to
5633 */
5634 applyTo(canvasEl: HTMLCanvasElement): void;
5635}
5636interface IGradientTransparencyFilter extends IBaseFilter {
5637 /**
5638 * Applies filter to canvas element
5639 * @param canvasEl Canvas element to apply filter to
5640 */
5641 applyTo(canvasEl: HTMLCanvasElement): void;
5642}
5643interface IGrayscaleFilter extends IBaseFilter {
5644 /**
5645 * Applies filter to canvas element
5646 * @param canvasEl Canvas element to apply filter to
5647 */
5648 applyTo(canvasEl: HTMLCanvasElement): void;
5649}
5650interface IInvertFilter extends IBaseFilter {
5651 /**
5652 * Applies filter to canvas element
5653 * @param canvasEl Canvas element to apply filter to
5654 */
5655 applyTo(canvasEl: HTMLCanvasElement): void;
5656}
5657interface IMaskFilter extends IBaseFilter {
5658 /**
5659 * Applies filter to canvas element
5660 * @param canvasEl Canvas element to apply filter to
5661 */
5662 applyTo(canvasEl: HTMLCanvasElement): void;
5663}
5664interface IMultiplyFilter extends IBaseFilter {
5665 /**
5666 * Applies filter to canvas element
5667 * @param canvasEl Canvas element to apply filter to
5668 */
5669 applyTo(canvasEl: HTMLCanvasElement): void;
5670}
5671interface INoiseFilter extends IBaseFilter {
5672 /**
5673 * Applies filter to canvas element
5674 * @param canvasEl Canvas element to apply filter to
5675 */
5676 applyTo(canvasEl: HTMLCanvasElement): void;
5677}
5678interface IPixelateFilter extends IBaseFilter {
5679 /**
5680 * Applies filter to canvas element
5681 * @param canvasEl Canvas element to apply filter to
5682 */
5683 applyTo(canvasEl: HTMLCanvasElement): void;
5684}
5685interface IRemoveWhiteFilter extends IBaseFilter {
5686 /**
5687 * Applies filter to canvas element
5688 * @param canvasEl Canvas element to apply filter to
5689 */
5690 applyTo(canvasEl: HTMLCanvasElement): void;
5691}
5692interface IResizeFilter extends IBaseFilter {
5693 /**
5694 * Resize type
5695 */
5696 resizeType: string;
5697
5698 /**
5699 * Scale factor for resizing, x axis
5700 */
5701 scaleX: number;
5702
5703 /**
5704 * Scale factor for resizing, y axis
5705 */
5706 scaleY: number;
5707
5708 /**
5709 * LanczosLobes parameter for lanczos filter
5710 */
5711 lanczosLobes: number;
5712 /**
5713 * Applies filter to canvas element
5714 * @param canvasEl Canvas element to apply filter to
5715 */
5716 applyTo(canvasEl: HTMLCanvasElement): void;
5717}
5718interface ISaturationFilter extends IBaseFilter {
5719 /**
5720 * Applies filter to canvas element
5721 * @param canvasEl Canvas element to apply filter to
5722 */
5723 applyTo(canvasEl: HTMLCanvasElement): void;
5724}
5725interface ISepiaFilter extends IBaseFilter {
5726 /**
5727 * Applies filter to canvas element
5728 * @param canvasEl Canvas element to apply filter to
5729 */
5730 applyTo(canvasEl: HTMLCanvasElement): void;
5731}
5732interface ISepia2Filter extends IBaseFilter {
5733 /**
5734 * Applies filter to canvas element
5735 * @param canvasEl Canvas element to apply filter to
5736 */
5737 applyTo(canvasEl: HTMLCanvasElement): void;
5738}
5739interface ITintFilter extends IBaseFilter {
5740 /**
5741 * Applies filter to canvas element
5742 * @param canvasEl Canvas element to apply filter to
5743 */
5744 applyTo(canvasEl: HTMLCanvasElement): void;
5745}
5746
5747////////////////////////////////////////////////////////////
5748// Brushes
5749////////////////////////////////////////////////////////////
5750export class BaseBrush {
5751 /**
5752 * Color of a brush
5753 */
5754 color: string;
5755
5756 /**
5757 * Width of a brush
5758 */
5759 width: number;
5760
5761 /**
5762 * Shadow object representing shadow of this shape.
5763 * <b>Backwards incompatibility note:</b> This property replaces "shadowColor" (String), "shadowOffsetX" (Number),
5764 * "shadowOffsetY" (Number) and "shadowBlur" (Number) since v1.2.12
5765 */
5766 shadow: Shadow | string;
5767 /**
5768 * Line endings style of a brush (one of "butt", "round", "square")
5769 */
5770 strokeLineCap: string;
5771
5772 /**
5773 * Corner style of a brush (one of "bevil", "round", "miter")
5774 */
5775 strokeLineJoin: string;
5776
5777 /**
5778 * Stroke Dash Array.
5779 */
5780 strokeDashArray: any[];
5781}
5782
5783export class CircleBrush extends BaseBrush {
5784 /**
5785 * Width of a brush
5786 */
5787 width: number;
5788 /**
5789 * Invoked inside on mouse down and mouse move
5790 */
5791 drawDot(pointer: any): void;
5792
5793 /**
5794 * @return Just added pointer point
5795 */
5796 addPoint(pointer: any): Point;
5797}
5798
5799export class SprayBrush extends BaseBrush {
5800 /**
5801 * Width of a brush
5802 */
5803 width: number;
5804 /**
5805 * Density of a spray (number of dots per chunk)
5806 */
5807 density: number;
5808
5809 /**
5810 * Width of spray dots
5811 */
5812 dotWidth: number;
5813 /**
5814 * Width variance of spray dots
5815 */
5816 dotWidthVariance: number;
5817
5818 /**
5819 * Whether opacity of a dot should be random
5820 */
5821 randomOpacity: boolean;
5822 /**
5823 * Whether overlapping dots (rectangles) should be removed (for performance reasons)
5824 */
5825 optimizeOverlapping: boolean;
5826
5827 addSprayChunk(pointer: any): void;
5828}
5829export class PatternBrush extends PencilBrush {
5830 getPatternSrc(): HTMLCanvasElement;
5831
5832 getPatternSrcFunction(): string;
5833
5834 /**
5835 * Creates "pattern" instance property
5836 */
5837 getPattern(): any;
5838 /**
5839 * Creates path
5840 */
5841 createPath(pathData: string): Path;
5842}
5843export class PencilBrush extends BaseBrush {
5844 /**
5845 * Converts points to SVG path
5846 * @param points Array of points
5847 */
5848 convertPointsToSVGPath(points: Array<{ x: number; y: number }>, minX?: number, minY?: number): string[];
5849
5850 /**
5851 * Creates fabric.Path object to add on canvas
5852 * @param pathData Path data
5853 */
5854 createPath(pathData: string): Path;
5855}
5856
5857///////////////////////////////////////////////////////////////////////////////
5858// Fabric util Interface
5859//////////////////////////////////////////////////////////////////////////////
5860interface IUtilAnimationOptions {
5861 /**
5862 * Starting value
5863 */
5864 startValue?: number;
5865 /**
5866 * Ending value
5867 */
5868 endValue?: number;
5869 /**
5870 * Value to modify the property by
5871 */
5872 byValue?: number;
5873 /**
5874 * Duration of change (in ms)
5875 */
5876 duration?: number;
5877 /**
5878 * Callback; invoked on every value change
5879 */
5880 onChange?: (value: number) => void;
5881 /**
5882 * Callback; invoked when value change is completed
5883 */
5884 onComplete?: Function;
5885 /**
5886 * Easing function
5887 */
5888 easing?: Function;
5889}
5890interface IUtilAnimation {
5891 /**
5892 * Changes value from one to another within certain period of time, invoking callbacks as value is being changed.
5893 * @param [options] Animation options
5894 */
5895 animate(options?: IUtilAnimationOptions): void;
5896 /**
5897 * requestAnimationFrame polyfill based on http://paulirish.com/2011/requestanimationframe-for-smart-animating/
5898 * In order to get a precise start time, `requestAnimFrame` should be called as an entry into the method
5899 * @param callback Callback to invoke
5900 */
5901 requestAnimFrame(callback: Function): void;
5902}
5903
5904type IUtilAminEaseFunction = (t: number, b: number, c: number, d: number) => number;
5905
5906interface IUtilAnimEase {
5907 easeInBack: IUtilAminEaseFunction;
5908 easeInBounce: IUtilAminEaseFunction;
5909 easeInCirc: IUtilAminEaseFunction;
5910 easeInCubic: IUtilAminEaseFunction;
5911 easeInElastic: IUtilAminEaseFunction;
5912 easeInExpo: IUtilAminEaseFunction;
5913 easeInOutBack: IUtilAminEaseFunction;
5914 easeInOutBounce: IUtilAminEaseFunction;
5915 easeInOutCirc: IUtilAminEaseFunction;
5916 easeInOutCubic: IUtilAminEaseFunction;
5917 easeInOutElastic: IUtilAminEaseFunction;
5918 easeInOutExpo: IUtilAminEaseFunction;
5919 easeInOutQuad: IUtilAminEaseFunction;
5920 easeInOutQuart: IUtilAminEaseFunction;
5921 easeInOutQuint: IUtilAminEaseFunction;
5922 easeInOutSine: IUtilAminEaseFunction;
5923 easeInQuad: IUtilAminEaseFunction;
5924 easeInQuart: IUtilAminEaseFunction;
5925 easeInQuint: IUtilAminEaseFunction;
5926 easeInSine: IUtilAminEaseFunction;
5927 easeOutBack: IUtilAminEaseFunction;
5928 easeOutBounce: IUtilAminEaseFunction;
5929 easeOutCirc: IUtilAminEaseFunction;
5930 easeOutCubic: IUtilAminEaseFunction;
5931 easeOutElastic: IUtilAminEaseFunction;
5932 easeOutExpo: IUtilAminEaseFunction;
5933 easeOutQuad: IUtilAminEaseFunction;
5934 easeOutQuart: IUtilAminEaseFunction;
5935 easeOutQuint: IUtilAminEaseFunction;
5936 easeOutSine: IUtilAminEaseFunction;
5937}
5938
5939interface IUtilImage {
5940 setImageSmoothing(ctx: CanvasRenderingContext2D, value: any): void;
5941}
5942
5943interface IUtilArc {
5944 /**
5945 * Draws arc
5946 */
5947 drawArc(ctx: CanvasRenderingContext2D, fx: number, fy: number, coords: number[]): void;
5948 /**
5949 * Calculate bounding box of a elliptic-arc
5950 * @param fx start point of arc
5951 * @param rx horizontal radius
5952 * @param ry vertical radius
5953 * @param rot angle of horizontal axe
5954 * @param large 1 or 0, whatever the arc is the big or the small on the 2 points
5955 * @param sweep 1 or 0, 1 clockwise or counterclockwise direction
5956 * @param tx end point of arc
5957 */
5958 getBoundsOfArc(
5959 fx: number,
5960 fy: number,
5961 rx: number,
5962 ry: number,
5963 rot: number,
5964 large: number,
5965 sweep: number,
5966 tx: number,
5967 ty: number,
5968 ): Point[];
5969 /**
5970 * Calculate bounding box of a beziercurve
5971 * @param x0 starting point
5972 * @param x1 first control point
5973 * @param x2 secondo control point
5974 * @param x3 end of beizer
5975 */
5976 getBoundsOfCurve(
5977 x0: number,
5978 y0: number,
5979 x1: number,
5980 y1: number,
5981 x2: number,
5982 y2: number,
5983 x3: number,
5984 y3: number,
5985 ): Point[];
5986}
5987
5988interface IUtilDomEvent {
5989 /**
5990 * Cross-browser wrapper for getting event's coordinates
5991 * @param event Event object
5992 * @param upperCanvasEl &lt;canvas> element on which object selection is drawn
5993 */
5994 getPointer(event: Event, upperCanvasEl: HTMLCanvasElement): Point;
5995
5996 /**
5997 * Adds an event listener to an element
5998 */
5999 addListener(element: HTMLElement, eventName: string, handler: Function): void;
6000
6001 /**
6002 * Removes an event listener from an element
6003 */
6004 removeListener(element: HTMLElement, eventName: string, handler: Function): void;
6005}
6006
6007interface IUtilDomMisc {
6008 /**
6009 * Takes id and returns an element with that id (if one exists in a document)
6010 */
6011 getById(id: string | HTMLElement): HTMLElement;
6012 /**
6013 * Converts an array-like object (e.g. arguments or NodeList) to an array
6014 */
6015 toArray(arrayLike: any): any[];
6016 /**
6017 * Creates specified element with specified attributes
6018 * @param tagName Type of an element to create
6019 * @param [attributes] Attributes to set on an element
6020 * @return Newly created element
6021 */
6022 makeElement(tagName: string, attributes?: any): HTMLElement;
6023 /**
6024 * Adds class to an element
6025 * @param element Element to add class to
6026 * @param className Class to add to an element
6027 */
6028 addClass(element: HTMLElement, classname: string): void;
6029 /**
6030 * Wraps element with another element
6031 * @param element Element to wrap
6032 * @param wrapper Element to wrap with
6033 * @param [attributes] Attributes to set on a wrapper
6034 */
6035 wrapElement(element: HTMLElement, wrapper: HTMLElement | string, attributes?: any): HTMLElement;
6036 /**
6037 * Returns element scroll offsets
6038 * @param element Element to operate on
6039 */
6040 getScrollLeftTop(element: HTMLElement): { left: number; top: number };
6041 /**
6042 * Returns offset for a given element
6043 * @param element Element to get offset for
6044 */
6045 getElementOffset(element: HTMLElement): { left: number; top: number };
6046 /**
6047 * Returns style attribute value of a given element
6048 * @param element Element to get style attribute for
6049 * @param attr Style attribute to get for element
6050 */
6051 getElementStyle(elment: HTMLElement, attr: string): string;
6052 /**
6053 * Inserts a script element with a given url into a document; invokes callback, when that script is finished loading
6054 * @param url URL of a script to load
6055 * @param callback Callback to execute when script is finished loading
6056 */
6057 getScript(url: string, callback: Function): void;
6058 /**
6059 * Makes element unselectable
6060 * @param element Element to make unselectable
6061 */
6062 makeElementUnselectable(element: HTMLElement): HTMLElement;
6063 /**
6064 * Makes element selectable
6065 * @param element Element to make selectable
6066 */
6067 makeElementSelectable(element: HTMLElement): HTMLElement;
6068}
6069
6070interface IUtilDomRequest {
6071 /**
6072 * Cross-browser abstraction for sending XMLHttpRequest
6073 * @param url URL to send XMLHttpRequest to
6074 */
6075 request(
6076 url: string,
6077 options?: {
6078 /** @default "GET" */
6079 method?: string;
6080 /** Callback to invoke when request is completed */
6081 onComplete: Function;
6082 },
6083 ): XMLHttpRequest;
6084}
6085
6086interface IUtilDomStyle {
6087 /**
6088 * Cross-browser wrapper for setting element's style
6089 */
6090 setStyle(element: HTMLElement, styles: any): HTMLElement;
6091}
6092
6093interface IUtilArray {
6094 /**
6095 * Invokes method on all items in a given array
6096 * @param array Array to iterate over
6097 * @param method Name of a method to invoke
6098 */
6099 invoke(array: any[], method: string): any[];
6100 /**
6101 * Finds minimum value in array (not necessarily "first" one)
6102 * @param array Array to iterate over
6103 */
6104 min(array: any[], byProperty: string): any;
6105 /**
6106 * Finds maximum value in array (not necessarily "first" one)
6107 * @param array Array to iterate over
6108 */
6109 max(array: any[], byProperty: string): any;
6110}
6111
6112interface IUtilClass {
6113 /**
6114 * Helper for creation of "classes".
6115 * @param [parent] optional "Class" to inherit from
6116 * @param [properties] Properties shared by all instances of this class
6117 * (be careful modifying objects defined here as this would affect all instances)
6118 */
6119 createClass(parent: Function, properties?: any): any;
6120 /**
6121 * Helper for creation of "classes".
6122 * @param [properties] Properties shared by all instances of this class
6123 * (be careful modifying objects defined here as this would affect all instances)
6124 */
6125 createClass(properties?: any): any;
6126}
6127
6128interface IUtilObject {
6129 /**
6130 * Copies all enumerable properties of one object to another
6131 * @param destination Where to copy to
6132 * @param source Where to copy from
6133 */
6134 extend(destination: any, source: any): any;
6135
6136 /**
6137 * Creates an empty object and copies all enumerable properties of another object to it
6138 * @param object Object to clone
6139 */
6140 clone(object: any): any;
6141}
6142
6143interface IUtilString {
6144 /**
6145 * Camelizes a string
6146 * @param string String to camelize
6147 */
6148 camelize(string: string): string;
6149
6150 /**
6151 * Capitalizes a string
6152 * @param string String to capitalize
6153 * @param [firstLetterOnly] If true only first letter is capitalized
6154 * and other letters stay untouched, if false first letter is capitalized
6155 * and other letters are converted to lowercase.
6156 */
6157 capitalize(string: string, firstLetterOnly: boolean): string;
6158
6159 /**
6160 * Escapes XML in a string
6161 * @param string String to escape
6162 */
6163 escapeXml(string: string): string;
6164
6165 /**
6166 * Divide a string in the user perceived single units
6167 * @param {String} textstring String to escape
6168 * @return {Array} array containing the graphemes
6169 */
6170 graphemeSplit(string: string): string[];
6171}
6172
6173interface IUtilMisc {
6174 /**
6175 * Removes value from an array.
6176 * Presence of value (and its position in an array) is determined via `Array.prototype.indexOf`
6177 */
6178 removeFromArray(array: any[], value: any): any[];
6179
6180 /**
6181 * Returns random number between 2 specified ones.
6182 * @param min lower limit
6183 * @param max upper limit
6184 */
6185 getRandomInt(min: number, max: number): number;
6186
6187 /**
6188 * Transforms degrees to radians.
6189 * @param degrees value in degrees
6190 */
6191 degreesToRadians(degrees: number): number;
6192
6193 /**
6194 * Transforms radians to degrees.
6195 * @param radians value in radians
6196 */
6197 radiansToDegrees(radians: number): number;
6198
6199 /**
6200 * Rotates `point` around `origin` with `radians`
6201 * @param point The point to rotate
6202 * @param origin The origin of the rotation
6203 * @param radians The radians of the angle for the rotation
6204 */
6205 rotatePoint(point: Point, origin: Point, radians: number): Point;
6206
6207 /**
6208 * Rotates `vector` with `radians`
6209 * @param vector The vector to rotate (x and y)
6210 * @param radians The radians of the angle for the rotation
6211 */
6212 rotateVector(vector: { x: number; y: number }, radians: number): { x: number; y: number };
6213
6214 /**
6215 * Apply transform t to point p
6216 * @param p The point to transform
6217 * @param t The transform
6218 * @param [ignoreOffset] Indicates that the offset should not be applied
6219 */
6220 transformPoint(p: Point, t: any[], ignoreOffset?: boolean): Point;
6221
6222 /**
6223 * Invert transformation t
6224 * @param t The transform
6225 */
6226 invertTransform(t: any[]): any[];
6227
6228 /**
6229 * A wrapper around Number#toFixed, which contrary to native method returns number, not string.
6230 * @param number number to operate on
6231 * @param fractionDigits number of fraction digits to "leave"
6232 */
6233 toFixed(number: number, fractionDigits: number): number;
6234
6235 /**
6236 * Converts from attribute value to pixel value if applicable.
6237 * Returns converted pixels or original value not converted.
6238 * @param value number to operate on
6239 */
6240 parseUnit(value: number | string, fontSize?: number): number | string;
6241
6242 /**
6243 * Function which always returns `false`.
6244 */
6245 falseFunction(): boolean;
6246
6247 /**
6248 * Returns klass "Class" object of given namespace
6249 * @param type Type of object (eg. 'circle')
6250 * @param namespace Namespace to get klass "Class" object from
6251 */
6252 getKlass(type: string, namespace: string): any;
6253
6254 /**
6255 * Returns object of given namespace
6256 * @param namespace Namespace string e.g. 'fabric.Image.filter' or 'fabric'
6257 */
6258 resolveNamespace(namespace: string): any;
6259
6260 /**
6261 * Loads image element from given url and passes it to a callback
6262 * @param url URL representing an image
6263 * @param callback Callback; invoked with loaded image
6264 * @param [context] Context to invoke callback in
6265 * @param [crossOrigin] crossOrigin value to set image element to
6266 */
6267 loadImage(url: string, callback: (image: HTMLImageElement) => void, context?: any, crossOrigin?: string): void;
6268
6269 /**
6270 * Creates corresponding fabric instances from their object representations
6271 * @param objects Objects to enliven
6272 * @param callback Callback to invoke when all objects are created
6273 * @param namespace Namespace to get klass "Class" object from
6274 * @param reviver Method for further parsing of object elements, called after each fabric object created.
6275 */
6276 enlivenObjects(objects: any[], callback: Function, namespace: string, reviver?: Function): void;
6277
6278 /**
6279 * Groups SVG elements (usually those retrieved from SVG document)
6280 * @param elements SVG elements to group
6281 * @param [options] Options object
6282 */
6283 groupSVGElements(elements: any[], options?: any, path?: string): Object | Group;
6284
6285 /**
6286 * Clear char widths cache for the given font family or all the cache if no
6287 * fontFamily is specified.
6288 * Use it if you know you are loading fonts in a lazy way and you are not waiting
6289 * for custom fonts to load properly when adding text objects to the canvas.
6290 * If a text object is added when its own font is not loaded yet, you will get wrong
6291 * measurement and so wrong bounding boxes.
6292 * After the font cache is cleared, either change the textObject text content or call
6293 * initDimensions() to trigger a recalculation
6294 * @memberOf fabric.util
6295 * @param {String} [fontFamily] font family to clear
6296 */
6297 clearFabricFontCache(fontFamily?: string): void;
6298
6299 /**
6300 * Populates an object with properties of another object
6301 * @param source Source object
6302 * @param destination Destination object
6303 * @param properties Propertie names to include
6304 */
6305 populateWithProperties(source: any, destination: any, properties: any): void;
6306
6307 /**
6308 * Draws a dashed line between two points
6309 * This method is used to draw dashed line around selection area.
6310 * @param ctx context
6311 * @param x start x coordinate
6312 * @param y start y coordinate
6313 * @param x2 end x coordinate
6314 * @param y2 end y coordinate
6315 * @param da dash array pattern
6316 */
6317 drawDashedLine(ctx: CanvasRenderingContext2D, x: number, y: number, x2: number, y2: number, da: any[]): void;
6318
6319 /**
6320 * Creates canvas element and initializes it via excanvas if necessary
6321 * @param [canvasEl] optional canvas element to initialize;
6322 * when not given, element is created implicitly
6323 */
6324 createCanvasElement(canvasEl?: HTMLCanvasElement): HTMLCanvasElement;
6325
6326 /**
6327 * Creates image element (works on client and node)
6328 */
6329 createImage(): HTMLImageElement;
6330
6331 /**
6332 * Creates accessors (getXXX, setXXX) for a "class", based on "stateProperties" array
6333 * @param klass "Class" to create accessors for
6334 */
6335 createAccessors(klass: any): any;
6336
6337 /**
6338 * @param receiver Object implementing `clipTo` method
6339 * @param ctx Context to clip
6340 */
6341 clipContext(receiver: Object, ctx: CanvasRenderingContext2D): void;
6342
6343 /**
6344 * Multiply matrix A by matrix B to nest transformations
6345 * @param a First transformMatrix
6346 * @param b Second transformMatrix
6347 */
6348 multiplyTransformMatrices(a: number[], b: number[]): number[];
6349
6350 /**
6351 * Decomposes standard 2x2 matrix into transform componentes
6352 * @param a transformMatrix
6353 */
6354 qrDecompose(
6355 a: number[],
6356 ): {
6357 angle: number;
6358 scaleX: number;
6359 scaleY: number;
6360 skewX: number;
6361 skewY: number;
6362 translateX: number;
6363 translateY: number;
6364 };
6365
6366 /**
6367 * Extract Object transform values
6368 * @param {fabric.Object} target object to read from
6369 * @return {Object} Components of transform
6370 */
6371 saveObjectTransform(
6372 target: Object,
6373 ): {
6374 scaleX: number;
6375 scaleY: number;
6376 skewX: number;
6377 skewY: number;
6378 angle: number;
6379 left: number;
6380 flipX: boolean;
6381 flipY: boolean;
6382 top: number;
6383 };
6384
6385 /**
6386 * Returns a transform matrix starting from an object of the same kind of
6387 * the one returned from qrDecompose, useful also if you want to calculate some
6388 * transformations from an object that is not enlived yet
6389 * @static
6390 * @memberOf fabric.util
6391 * @param {Object} options
6392 * @param {Number} [options.angle]
6393 * @param {Number} [options.scaleX]
6394 * @param {Number} [options.scaleY]
6395 * @param {Boolean} [options.flipX]
6396 * @param {Boolean} [options.flipY]
6397 * @param {Number} [options.skewX]
6398 * @param {Number} [options.skewX]
6399 * @param {Number} [options.translateX]
6400 * @param {Number} [options.translateY]
6401 * @return {Number[]} transform matrix
6402 */
6403 composeMatrix(options: {
6404 angle: number;
6405 scaleX: number;
6406 scaleY: number;
6407 flipX: boolean;
6408 flipY: boolean;
6409 skewX: number;
6410 skewY: number;
6411 translateX: number;
6412 translateY: number;
6413 }): number[];
6414
6415 /**
6416 * Returns string representation of function body
6417 * @param fn Function to get body of
6418 */
6419 getFunctionBody(fn: Function): string;
6420
6421 /**
6422 * Returns true if context has transparent pixel
6423 * at specified location (taking tolerance into account)
6424 * @param ctx context
6425 * @param x x coordinate
6426 * @param y y coordinate
6427 * @param tolerance Tolerance
6428 */
6429 isTransparent(ctx: CanvasRenderingContext2D, x: number, y: number, tolerance: number): boolean;
6430
6431 /**
6432 * reset an object transform state to neutral. Top and left are not accounted for
6433 * @static
6434 * @memberOf fabric.util
6435 * @param {fabric.Object} target object to transform
6436 */
6437 resetObjectTransform(target: Object): void;
6438}
6439
6440export const util: IUtil;
6441interface IUtil
6442 extends IUtilImage,
6443 IUtilAnimation,
6444 IUtilArc,
6445 IObservable<IUtil>,
6446 IUtilDomEvent,
6447 IUtilDomMisc,
6448 IUtilDomRequest,
6449 IUtilDomStyle,
6450 IUtilClass,
6451 IUtilMisc {
6452 ease: IUtilAnimEase;
6453 array: IUtilArray;
6454 object: IUtilObject;
6455 string: IUtilString;
6456}
6457
6458export interface Resources {
6459 [key: string]: HTMLCanvasElement;
6460}
6461export interface FilterBackend {
6462 resources: Resources;
6463
6464 applyFilters(
6465 filters: IBaseFilter[],
6466 sourceElement: HTMLImageElement | HTMLCanvasElement,
6467 sourceWidth: number,
6468 sourceHeight: number,
6469 targetCanvas: HTMLCanvasElement,
6470 cacheKey?: string,
6471 ): any;
6472
6473 evictCachesForKey(cacheKey: string): void;
6474
6475 dispose(): void;
6476
6477 clearWebGLCaches(): void;
6478}
6479export let filterBackend: FilterBackend | undefined;
6480export interface Canvas2dFilterBackend extends FilterBackend {}
6481export class Canvas2dFilterBackend {
6482 constructor();
6483}
6484
6485export interface GPUInfo {
6486 renderer: string;
6487 vendor: string;
6488}
6489
6490export interface WebglFilterBackendOptions {
6491 tileSize: number;
6492}
6493export interface WebglFilterBackend extends FilterBackend, WebglFilterBackendOptions {
6494 setupGLContext(width: number, height: number): void;
6495
6496 chooseFastestCopyGLTo2DMethod(width: number, height: number): void;
6497
6498 createWebGLCanvas(width: number, height: number): void;
6499
6500 applyFiltersDebug(
6501 filters: IBaseFilter[],
6502 sourceElement: HTMLImageElement | HTMLCanvasElement,
6503 sourceWidth: number,
6504 sourceHeight: number,
6505 targetCanvas: HTMLCanvasElement,
6506 cacheKey?: string,
6507 ): any;
6508
6509 glErrorToString(context: any, errorCode: any): string;
6510
6511 createTexture(
6512 gl: WebGLRenderingContext,
6513 width: number,
6514 height: number,
6515 textureImageSource?: HTMLImageElement | HTMLCanvasElement,
6516 ): WebGLTexture;
6517
6518 getCachedTexture(uniqueId: string, textureImageSource: HTMLImageElement | HTMLCanvasElement): WebGLTexture;
6519
6520 copyGLTo2D(gl: WebGLRenderingContext, pipelineState: any): void;
6521
6522 captureGPUInfo(): GPUInfo;
6523}
6524
6525export class WebglFilterBackend {
6526 constructor(options?: WebglFilterBackendOptions);
6527}
6528
\No newline at end of file