UNPKG

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