-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.d.ts
executable file
·6575 lines (6102 loc) · 208 KB
/
canvas.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This module does not really exist.
// This is just to get `export as namespace fabric;` to work and to be re-exportable from `index.d.ts`.
export as namespace fabric;
export const isLikelyNode: boolean;
export const isTouchSupported: boolean;
export const version: string;
export const iMatrix: number[];
export let textureSize: number;
export let copiedText: string;
export let copiedTextStyle: any[];
export let charWidthsCache: {
[key: string]: {
// example: montserrat
[key: string]: {
// example: normal_normal
[key: string]: number; // example: A: 286
};
};
};
/////////////////////////////////////////////////////////////
// fabric Functions
/////////////////////////////////////////////////////////////
export function createCanvasForNode(width: number, height: number): Canvas;
// Parse
// ----------------------------------------------------------
/**
* Creates markup containing SVG referenced elements like patterns, gradients etc.
* @param canvas instance of fabric.Canvas
*/
export function createSVGRefElementsMarkup(canvas: StaticCanvas): string;
/**
* Creates markup containing SVG font faces
* @param objects Array of fabric objects
*/
export function createSVGFontFacesMarkup(objects: Object[]): string;
/**
* Takes string corresponding to an SVG document, and parses it into a set of fabric objects
* @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
*/
export function loadSVGFromString(string: string, callback: (results: Object[], options: any) => void, reviver?: Function): void;
/**
* Takes url corresponding to an SVG document, and parses it into a set of fabric objects.
* Note that SVG is fetched via XMLHttpRequest, so it needs to conform to SOP (Same Origin Policy)
* @param {String} url URL to get a SVG from
* @param {Function} callback Callback is invoked when svg has been loaded
* @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created.
* @param {Object} [options] options for crossOrigin
* @param {String} [options.crossOrigin] crossOrigin settings
*
*/
export function loadSVGFromURL(url: string, callback: (results: Object[], options: any) => void, reviver?: Function, options?: { crossOrigin?: string | undefined }): void;
/**
* Returns CSS rules for a given SVG document
* @param doc SVG document to parse
*/
export function getCSSRules(doc: SVGElement): any;
export function parseElements(elements: any[], callback: Function, options: any, reviver?: Function): void;
/**
* Parses "points" attribute, returning an array of values
* @param points points attribute string
*/
export function parsePointsAttribute(points: string): any[];
/**
* Parses "style" attribute, retuning an object with values
* @param element Element to parse
*/
export function parseStyleAttribute(element: SVGElement): any;
/**
* Transforms an array of svg elements to corresponding fabric.* instances
* @param elements Array of elements to parse
* @param callback Being passed an array of fabric instances (transformed from SVG elements)
* @param [options] Options object
* @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
*/
export function parseElements(elements: SVGElement[], callback: Function, options?: any, reviver?: Function): void;
/**
* Returns an object of attributes' name/value, given element and an array of attribute names;
* Parses parent "g" nodes recursively upwards.
* @param element Element to parse
* @param attributes Array of attributes to parse
*/
export function parseAttributes(element: HTMLElement, attributes: string[], svgUid?: string): { [key: string]: string };
/**
* Parses an SVG document, returning all of the gradient declarations found in it
* @param doc SVG document to parse
*/
export function getGradientDefs(doc: SVGElement): { [key: string]: any };
/**
* Parses a short font declaration, building adding its properties to a style object
* @param value font declaration
* @param oStyle definition
*/
export function parseFontDeclaration(value: string, oStyle: any): void;
/**
* Parses an SVG document, converts it to an array of corresponding fabric.* instances and passes them to a callback
* @param doc SVG document to parse
* @param callback Callback to call when parsing is finished; It's being passed an array of elements (parsed from a document).
* @param [reviver] Method for further parsing of SVG elements, called after each fabric object created.
*/
export function parseSVGDocument(doc: SVGElement, callback: (results: Object[], options: any) => void, reviver?: Function): void;
/**
* Parses "transform" attribute, returning an array of values
* @param attributeValue String containing attribute value
*/
export function parseTransformAttribute(attributeValue: string): number[];
// fabric Log
// ---------------
/**
* Wrapper around `console.log` (when available)
*/
export function log(...values: any[]): void;
/**
* Wrapper around `console.warn` (when available)
*/
export function warn(...values: any[]): void;
///////////////////////////////////////////////////////////////////////////////
// Data Object Interfaces - These interface are not specific part of fabric,
// They are just helpful for for defining function parameters
//////////////////////////////////////////////////////////////////////////////
interface IDataURLOptions {
/**
* The format of the output image. Either "jpeg" or "png"
*/
format?: string | undefined;
/**
* Quality level (0..1). Only used for jpeg
*/
quality?: number | undefined;
/**
* Multiplier to scale by
*/
multiplier?: number | undefined;
/**
* Cropping left offset. Introduced in v1.2.14
*/
left?: number | undefined;
/**
* Cropping top offset. Introduced in v1.2.14
*/
top?: number | undefined;
/**
* Cropping width. Introduced in v1.2.14
*/
width?: number | undefined;
/**
* Cropping height. Introduced in v1.2.14
*/
height?: number | undefined;
enableRetinaScaling?: boolean | undefined;
withoutTransform?: boolean | undefined;
withoutShadow?: boolean | undefined;
}
interface IEvent<E extends Event = Event> {
e: E;
target?: Object | undefined;
subTargets?: Object[] | undefined;
selected?: Object[] | undefined;
deselected?: Object[] | undefined;
action?: string | undefined;
button?: number | undefined;
isClick?: boolean | undefined;
pointer?: Point | undefined;
absolutePointer?: Point | undefined;
transform?: Transform | undefined;
currentTarget?: Object | undefined;
currentSubTargets?: Object[] | undefined;
}
interface IFillOptions {
/**
* options.source Pattern source
*/
source: string | HTMLImageElement;
/**
* Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
*/
repeat?: string | undefined;
/**
* Pattern horizontal offset from object's left/top corner
*/
offsetX?: number | undefined;
/**
* Pattern vertical offset from object's left/top corner
*/
offsetY?: number | undefined;
}
interface IToSVGOptions {
/**
* If true xml tag is not included
*/
suppressPreamble?: boolean | undefined;
/**
* SVG viewbox object
*/
viewBox?: IViewBox | undefined;
/**
* Encoding of SVG output
*/
encoding?: string | undefined;
/**
* desired width of svg with or without units
*/
width?: number | string | undefined;
/**
* desired height of svg with or without units
*/
height?: number | string | undefined;
}
interface IViewBox {
/**
* x-cooridnate of viewbox
*/
x: number;
/**
* y-coordinate of viewbox
*/
y: number;
/**
* Width of viewbox
*/
width: number;
/**
* Height of viewbox
*/
height: number;
}
///////////////////////////////////////////////////////////////////////////////
// Mixins Interfaces
//////////////////////////////////////////////////////////////////////////////
interface ICollection<T> {
_objects: Object[];
/**
* This property only exists on objects exported as JSON or Object
*/
objects: Object[];
/**
* Adds objects to collection, then renders canvas (if `renderOnAddRemove` is not `false`)
* Objects should be instances of (or inherit from) fabric.Object
* @param object Zero or more fabric instances
*/
add(...object: Object[]): T;
/**
* Inserts an object into collection at specified index, then renders canvas (if `renderOnAddRemove` is not `false`)
* An object should be an instance of (or inherit from) fabric.Object
* @param object Object to insert
* @param index Index to insert object at
* @param nonSplicing When `true`, no splicing (shifting) of objects occurs
* @return thisArg
* @chainable
*/
insertAt(object: Object, index: number, nonSplicing: boolean): T;
/**
* Removes objects from a collection, then renders canvas (if `renderOnAddRemove` is not `false`)
* @param object Zero or more fabric instances
* @return thisArg
* @chainable
*/
remove(...object: Object[]): T;
/**
* Executes given function for each object in this group
* @param context Context (aka thisObject)
* @return thisArg
*/
forEachObject(callback: (element: Object, index: number, array: Object[]) => void, context?: any): T;
/**
* Returns an array of children objects of this instance
* Type parameter introduced in 1.3.10
* @param [type] When specified, only objects of this type are returned
*/
getObjects(type?: string): Object[];
/**
* Returns object at specified index
* @return thisArg
*/
item(index: number): T;
/**
* Returns true if collection contains no objects
* @return true if collection is empty
*/
isEmpty(): boolean;
/**
* Returns a size of a collection (i.e: length of an array containing its objects)
* @return Collection size
*/
size(): number;
/**
* Returns true if collection contains an object
* @param object Object to check against
* @return `true` if collection contains an object
*/
contains(object: Object): boolean;
/**
* Returns number representation of a collection complexity
* @return complexity
*/
complexity(): number;
}
type EventName =
| "object:modified"
| "object:moving"
| "object:scaling"
| "object:rotating"
| "object:skewing"
| "object:resizing"
| "object:selected"
| "object:added"
| "object:removed"
| "group:selected"
| "before:transform"
| "before:selection:cleared"
| "selection:cleared"
| "selection:created"
| "selection:updated"
| "mouse:up"
| "mouse:down"
| "mouse:move"
| "mouse:up:before"
| "mouse:down:before"
| "mouse:move:before"
| "mouse:dblclick"
| "mouse:wheel"
| "mouse:over"
| "mouse:out"
| "drop:before"
| "drop"
| "dragover"
| "dragenter"
| "dragleave"
| "before:render"
| "after:render"
| "before:path:created"
| "path:created"
| "canvas:cleared"
| "moving"
| "scaling"
| "rotating"
| "skewing"
| "resizing"
| "mouseup"
| "mousedown"
| "mousemove"
| "mouseup:before"
| "mousedown:before"
| "mousemove:before"
| "mousedblclick"
| "mousewheel"
| "mouseover"
| "mouseout"
| "drop:before"
| "drop"
| "dragover"
| "dragenter"
| "dragleave";
interface IObservable<T> {
/**
* Observes specified event
* @param eventName Event name (eg. 'after:render')
* @param handler Function that receives a notification when an event of the specified type occurs
*/
on(eventName: EventName, handler: (e: IEvent<MouseEvent>) => void): T;
on(eventName: "mouse:wheel", handler: (e: IEvent<WheelEvent>) => void): T;
on(eventName: string, handler: (e: IEvent) => void): T;
/**
* Stops event observing for a particular event handler. Calling this method
* without arguments removes all handlers for all events
* @param eventName Event name (eg. 'after:render') or object with key/value pairs (eg. {'after:render': handler, 'selection:cleared': handler})
* @param handler Function to be deleted from EventListeners
*/
off(eventName?: string | any, handler?: (e: IEvent) => void): T;
/**
* Fires event with an optional options object
* @memberOf fabric.Observable
* @param {String} eventName Event name to fire
* @param {Object} [options] Options object
* @return {Self} thisArg
* @chainable
*/
fire(eventName: string, options?: any): T;
}
interface Callbacks {
/** Invoked on completion */
onComplete?: Function | undefined;
/** Invoked on every step of animation */
onChange?: Function | undefined;
}
// animation mixin
// ----------------------------------------------------
interface ICanvasAnimation<T> {
FX_DURATION: number;
/**
* Centers object horizontally with animation.
* @param object Object to center
*/
fxCenterObjectH(object: Object, callbacks?: Callbacks): T;
/**
* Centers object vertically with animation.
* @param object Object to center
*/
fxCenterObjectV(object: Object, callbacks?: Callbacks): T;
/**
* Same as `fabric.Canvas#remove` but animated
* @param object Object to remove
* @chainable
*/
fxRemove(object: Object): T;
/**
* Same as {@link fabric.Canvas.prototype.straightenObject}, but animated
* @param {fabric.Object} object Object to straighten
* @return {fabric.Canvas} thisArg
* @chainable
*/
fxStraightenObject(object: Object): T;
}
interface IObjectAnimation<T> {
/**
* Animates object's properties
* object.animate('left', ..., {duration: ...});
* @param property Property to animate
* @param value Value to animate property
* @param options The animation options
*/
animate(property: string, value: number | string, options?: IAnimationOptions): Object;
/**
* Animates object's properties
* object.animate({ left: ..., top: ... }, { duration: ... });
* @param properties Properties to animate with values to animate to
* @param options The animation options
*/
animate(properties: { [key: string]: number | string }, options?: IAnimationOptions): Object;
}
interface IAnimationOptions {
/**
* Allows to specify starting value of animatable property (if we don't want current value to be used).
*/
from?: string | number | undefined;
/**
* Defaults to 500 (ms). Can be used to change duration of an animation.
*/
duration?: number | undefined;
/**
* Callback; invoked on every value change
*/
onChange?: Function | undefined;
/**
* Callback; invoked when value change is completed
*/
onComplete?: Function | undefined;
/**
* Easing function. Default: fabric.util.ease.easeInSine
*/
easing?: Function | undefined;
/**
* Value to modify the property by, default: end - start
*/
by?: number | undefined;
}
///////////////////////////////////////////////////////////////////////////////
// General Fabric Interfaces
//////////////////////////////////////////////////////////////////////////////
export class Color {
/**
* Color class
* The purpose of Color is to abstract and encapsulate common color operations;
* @param color optional in hex or rgb(a) format
*/
constructor(color?: string);
/**
* Returns source of this color (where source is an array representation; ex: [200, 200, 100, 1])
*/
getSource(): number[];
/**
* Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1])
*/
setSource(source: number[]): void;
/**
* Returns color represenation in RGB format ex: rgb(0-255,0-255,0-255)
*/
toRgb(): string;
/**
* Returns color represenation in RGBA format ex: rgba(0-255,0-255,0-255,0-1)
*/
toRgba(): string;
/**
* Returns color represenation in HSL format ex: hsl(0-360,0%-100%,0%-100%)
*/
toHsl(): string;
/**
* Returns color represenation in HSLA format ex: hsla(0-360,0%-100%,0%-100%,0-1)
*/
toHsla(): string;
/**
* Returns color represenation in HEX format ex: FF5555
*/
toHex(): string;
/**
* Returns color representation in HEXA format
* @return {String} ex: FF5555CC
*/
toHexa(): string;
/**
* Gets value of alpha channel for this color
*/
getAlpha(): number;
/**
* Sets value of alpha channel for this color
* @param alpha Alpha value 0-1
*/
setAlpha(alpha: number): void;
/**
* Transforms color to its grayscale representation
*/
toGrayscale(): Color;
/**
* Transforms color to its black and white representation
*/
toBlackWhite(threshold: number): Color;
/**
* Overlays color with another color
*/
overlayWith(otherColor: string | Color): Color;
/**
* Returns new color object, when given a color in RGB format
* @param color Color value ex: rgb(0-255,0-255,0-255)
*/
static fromRgb(color: string): Color;
/**
* Returns new color object, when given a color in RGBA format
* @param color Color value ex: rgb(0-255,0-255,0-255)
*/
static fromRgba(color: string): Color;
/**
* Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in RGB or RGBA format
* @param color Color value ex: rgb(0-255,0-255,0-255), rgb(0%-100%,0%-100%,0%-100%)
*/
static sourceFromRgb(color: string): number[];
/**
* Returns new color object, when given a color in HSL format
* @param color Color value ex: hsl(0-260,0%-100%,0%-100%)
*/
static fromHsl(color: string): Color;
/**
* Returns new color object, when given a color in HSLA format
* @param color Color value ex: hsl(0-260,0%-100%,0%-100%)
*/
static fromHsla(color: string): Color;
/**
* Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HSL or HSLA format.
* @param color Color value ex: hsl(0-360,0%-100%,0%-100%) or hsla(0-360,0%-100%,0%-100%, 0-1)
*/
static sourceFromHsl(color: string): number[];
/**
* Returns new color object, when given a color in HEX format
* @param color Color value ex: FF5555
*/
static fromHex(color: string): Color;
/**
* Returns array represenatation (ex: [100, 100, 200, 1]) of a color that's in HEX format
* @param color ex: FF5555
*/
static sourceFromHex(color: string): number[];
/**
* Returns new color object, when given color in array representation (ex: [200, 100, 100, 0.5])
*/
static fromSource(source: number[]): Color;
/**
* Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff)
* @static
* @field
* @memberOf fabric.Color
*/
static reHex: RegExp;
/**
* 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 ))
* @static
* @field
* @memberOf fabric.Color
*/
static reHSLa: RegExp;
/**
* 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))
* @static
* @field
* @memberOf fabric.Color
*/
static reRGBa: RegExp;
}
interface IGradientOptionsCoords {
x1?: number | undefined;
y1?: number | undefined;
x2?: number | undefined;
y2?: number | undefined;
r1?: number | undefined;
r2?: number | undefined;
}
type IGradientOptionsColorStops = Array<{
offset: number;
color: string;
}>;
interface IGradientOptions {
/**
* Horizontal offset for aligning gradients coming from SVG when outside pathgroups
*/
offsetX?: number | undefined;
/**
* Vertical offset for aligning gradients coming from SVG when outside pathgroups
*/
offsetY?: number | undefined;
type?: string | undefined;
coords?: IGradientOptionsCoords | undefined;
/**
* Color stops object eg. {0:string; 1:string;
*/
colorStops?: IGradientOptionsColorStops | undefined;
gradientTransform?: any;
}
interface OGradientOptions {
type?: string | undefined;
x1?: number | undefined;
y1?: number | undefined;
x2?: number | undefined;
y2?: number | undefined;
r1?: number | undefined;
r2?: number | undefined;
colorStops?:
| {
[key: string]: string;
}
| undefined;
gradientTransform?: any;
}
export interface Gradient extends IGradientOptions {}
export class Gradient {
/**
* Constructor
* @param {Object} options Options object with type, coords, gradientUnits and colorStops
* @param {Object} [options.type] gradient type linear or radial
* @param {Object} [options.gradientUnits] gradient units
* @param {Object} [options.offsetX] SVG import compatibility
* @param {Object} [options.offsetY] SVG import compatibility
* @param {Object[]} options.colorStops contains the colorstops.
* @param {Object} options.coords contains the coords of the gradient
* @param {Number} [options.coords.x1] X coordiante of the first point for linear or of the focal point for radial
* @param {Number} [options.coords.y1] Y coordiante of the first point for linear or of the focal point for radial
* @param {Number} [options.coords.x2] X coordiante of the second point for linear or of the center point for radial
* @param {Number} [options.coords.y2] Y coordiante of the second point for linear or of the center point for radial
* @param {Number} [options.coords.r1] only for radial gradient, radius of the inner circle
* @param {Number} [options.coords.r2] only for radial gradient, radius of the external circle
* @return {fabric.Gradient} thisArg
*/
constructor(options: {
type?: string | undefined;
gradientUnits?: any;
offsetX?: any;
offsetY?: any;
colorStops?: IGradientOptionsColorStops | undefined;
coords?: IGradientOptionsCoords | undefined;
});
/**
* Adds another colorStop
* @param colorStop Object with offset and color
*/
addColorStop(colorStop: any): Gradient;
/**
* Returns object representation of a gradient
*/
toObject(propertiesToInclude?: any): any;
/**
* Returns SVG representation of an gradient
* @param {Object} object Object to create a gradient for
* @return {String} SVG representation of an gradient (linear/radial)
*/
toSVG(object: any): string;
/**
* Returns an instance of CanvasGradient
* @param ctx Context to render on
*/
toLive(ctx: CanvasRenderingContext2D): CanvasGradient;
/**
* Returns {@link fabric.Gradient} instance from an SVG element
* @static
* @memberOf fabric.Gradient
* @param {SVGGradientElement} el SVG gradient element
* @param {fabric.Object} instance
* @return {fabric.Gradient} Gradient instance
* @see http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement
* @see http://www.w3.org/TR/SVG/pservers.html#RadialGradientElement
*/
static fromElement(el: SVGGradientElement, instance: Object): Gradient;
}
export class Intersection {
status?: string | undefined;
points?: Point[] | undefined;
constructor(status?: string);
/**
* Appends a point to intersection
*/
appendPoint(point: Point): Intersection;
/**
* Appends points to intersection
*/
appendPoints(points: Point[]): Intersection;
/**
* Checks if one line intersects another
*/
static intersectLineLine(a1: Point, a2: Point, b1: Point, b2: Point): Intersection;
/**
* Checks if line intersects polygon
*/
static intersectLinePolygon(a1: Point, a2: Point, points: Point[]): Intersection;
/**
* Checks if polygon intersects another polygon
*/
static intersectPolygonPolygon(points1: Point[], points2: Point[]): Intersection;
/**
* Checks if polygon intersects rectangle
*/
static intersectPolygonRectangle(points: Point[], r1: Point, r2: Point): Intersection;
}
interface IPatternOptions {
/**
* Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
*/
repeat?: string | undefined;
/**
* Pattern horizontal offset from object's left/top corner
*/
offsetX?: number | undefined;
/**
* Pattern vertical offset from object's left/top corner
*/
offsetY?: number | undefined;
/**
* crossOrigin value (one of "", "anonymous", "use-credentials")
* @see https://developer.mozilla.org/en-US/docs/HTML/CORS_settings_attributes
*/
crossOrigin?: "" | "anonymous" | "use-credentials" | undefined;
/**
* Transform matrix to change the pattern, imported from svgs
*/
patternTransform?: number[] | undefined;
/**
* The source for the pattern
*/
source: string | HTMLImageElement;
}
export interface Pattern extends IPatternOptions {}
export class Pattern {
/**
* Unique identifier
*/
id: number;
constructor(options?: IPatternOptions);
/**
* Returns object representation of a pattern
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} Object representation of a pattern instance
*/
toObject(propertiesToInclude: any): any;
/**
* Returns SVG representation of a pattern
* @param {fabric.Object} object
* @return {String} SVG representation of a pattern
*/
toSVG(object: Object): string;
setOptions(options: IPatternOptions): void;
/**
* Returns an instance of CanvasPattern
* @param {CanvasRenderingContext2D} ctx Context to create pattern
* @return {CanvasPattern}
*/
toLive(ctx: CanvasRenderingContext2D): CanvasPattern;
}
interface IPoint {
x: number;
y: number;
}
export class Point implements IPoint {
x: number;
y: number;
type: string;
constructor(x: number, y: number);
/**
* Adds another point to this one and returns another one
* @param {fabric.Point} that
* @return {fabric.Point} new Point instance with added values
*/
add(that: IPoint): Point;
/**
* Adds another point to this one
* @param {fabric.Point} that
* @return {fabric.Point} thisArg
* @chainable
*/
addEquals(that: IPoint): Point;
/**
* Adds value to this point and returns a new one
* @param {Number} scalar
* @return {fabric.Point} new Point with added value
*/
scalarAdd(scalar: number): Point;
/**
* Adds value to this point
* @param {Number} scalar
* @return {fabric.Point} thisArg
* @chainable
*/
scalarAddEquals(scalar: number): Point;
/**
* Subtracts another point from this point and returns a new one
* @param {fabric.Point} that
* @return {fabric.Point} new Point object with subtracted values
*/
subtract(that: IPoint): Point;
/**
* Subtracts another point from this point
* @param {fabric.Point} that
* @return {fabric.Point} thisArg
* @chainable
*/
subtractEquals(that: IPoint): Point;
/**
* Subtracts value from this point and returns a new one
* @param {Number} scalar
* @return {fabric.Point}
*/
scalarSubtract(scalar: number): Point;
/**
* Subtracts value from this point
* @param {Number} scalar
* @return {fabric.Point} thisArg
* @chainable
*/
scalarSubtractEquals(scalar: number): Point;
/**
* Multiplies this point by a value and returns a new one
* @param {Number} scalar
* @return {fabric.Point}
*/
multiply(scalar: number): Point;
/**
* Multiplies this point by a value
* @param {Number} scalar
* @return {fabric.Point} thisArg
* @chainable
*/
multiplyEquals(scalar: number): Point;
/**
* Divides this point by a value and returns a new one
* @param {Number} scalar
* @return {fabric.Point}
*/
divide(scalar: number): Point;
/**
* Divides this point by a value
* @param {Number} scalar
* @return {fabric.Point} thisArg
* @chainable
*/
divideEquals(scalar: number): Point;
/**
* Returns true if this point is equal to another one
* @param {fabric.Point} that
* @return {Boolean}
*/
eq(that: IPoint): Point;
/**
* Returns true if this point is less than another one
* @param {fabric.Point} that
* @return {Boolean}
*/
lt(that: IPoint): Point;
/**
* Returns true if this point is less than or equal to another one
* @param {fabric.Point} that
* @return {Boolean}
*/
lte(that: IPoint): Point;
/**
* Returns true if this point is greater another one
* @param {fabric.Point} that
* @return {Boolean}
*/
gt(that: IPoint): Point;
/**
* Returns true if this point is greater than or equal to another one
* @param {fabric.Point} that
* @return {Boolean}
*/
gte(that: IPoint): Point;
/**
* Returns new point which is the result of linear interpolation with this one and another one
* @param {fabric.Point} that
* @param {Number} t , position of interpolation, between 0 and 1 default 0.5
* @return {fabric.Point}
*/
lerp(that: IPoint, t: number): Point;
/**
* Returns distance from this point and another one
* @param {fabric.Point} that
* @return {Number}
*/
distanceFrom(that: IPoint): number;
/**
* Returns the point between this point and another one
* @param {fabric.Point} that
* @return {fabric.Point}
*/
midPointFrom(that: IPoint): Point;
/**
* Returns a new point which is the min of this and another one
* @param {fabric.Point} that
* @return {fabric.Point}
*/
min(that: IPoint): Point;
/**
* Returns a new point which is the max of this and another one
* @param {fabric.Point} that
* @return {fabric.Point}
*/
max(that: IPoint): Point;
/**
* Returns string representation of this point
* @return {String}
*/
toString(): string;
/**
* Sets x/y of this point
* @param {Number} x
* @param {Number} y
* @chainable
*/
setXY(x: number, y: number): Point;
/**
* Sets x of this point
* @param {Number} x
* @chainable
*/
setX(x: number): Point;
/**
* Sets y of this point
* @param {Number} y