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