UNPKG

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