-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
CanvasOptions.ts
298 lines (262 loc) · 7.79 KB
/
CanvasOptions.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
import type { ModifierKey, TOptionalModifierKey } from '../EventTypeDefs';
import type { TOptions } from '../typedefs';
import type { StaticCanvasOptions } from './StaticCanvasOptions';
export interface CanvasTransformOptions {
/**
* When true, objects can be transformed by one side (unproportionately)
* when dragged on the corners that normally would not do that.
* @type Boolean
* @default
* @since fabric 4.0 // changed name and default value
*/
uniformScaling: boolean;
/**
* Indicates which key switches uniform scaling.
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled.
* totally wrong named. this sounds like `uniform scaling`
* if Canvas.uniformScaling is true, pressing this will set it to false
* and viceversa.
* @since 1.6.2
* @type ModifierKey
* @default
*/
uniScaleKey: TOptionalModifierKey;
/**
* When true, objects use center point as the origin of scale transformation.
* <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
* @since 1.3.4
* @type Boolean
* @default
*/
centeredScaling: boolean;
/**
* When true, objects use center point as the origin of rotate transformation.
* <b>Backwards incompatibility note:</b> This property replaces "centerTransform" (Boolean).
* @since 1.3.4
* @type Boolean
* @default
*/
centeredRotation: boolean;
/**
* Indicates which key enable centered Transform
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled feature disabled.
* @since 1.6.2
* @type ModifierKey
* @default
*/
centeredKey: TOptionalModifierKey;
/**
* Indicates which key enable alternate action on corner
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled feature disabled.
* @since 1.6.2
* @type ModifierKey
* @default
*/
altActionKey: TOptionalModifierKey;
}
export interface CanvasSelectionOptions {
/**
* Indicates whether group selection should be enabled
* @type Boolean
* @default
*/
selection: boolean;
/**
* Indicates which key or keys enable multiple click selection
* Pass value as a string or array of strings
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* If `null` or empty or containing any other string that is not a modifier key
* feature is disabled.
* @since 1.6.2
* @type ModifierKey|ModifierKey[]
* @default
*/
selectionKey: TOptionalModifierKey | ModifierKey[];
/**
* Indicates which key enable alternative selection
* in case of target overlapping with active object
* values: 'altKey', 'shiftKey', 'ctrlKey'.
* For a series of reason that come from the general expectations on how
* things should work, this feature works only for preserveObjectStacking true.
* If `null` or 'none' or any other string that is not a modifier key
* feature is disabled.
* @since 1.6.5
* @type null|ModifierKey
* @default
*/
altSelectionKey: TOptionalModifierKey;
/**
* Color of selection
* @type String
* @default
*/
selectionColor: string;
/**
* Default dash array pattern
* If not empty the selection border is dashed
* @type Array
*/
selectionDashArray: number[];
/**
* Color of the border of selection (usually slightly darker than color of selection itself)
* @type String
* @default
*/
selectionBorderColor: string;
/**
* Width of a line used in object/group selection
* @type Number
* @default
*/
selectionLineWidth: number;
/**
* Select only shapes that are fully contained in the dragged selection rectangle.
* @type Boolean
* @default
*/
selectionFullyContained: boolean;
}
export interface CanvasCursorOptions {
/**
* Default cursor value used when hovering over an object on canvas
* @type CSSStyleDeclaration['cursor']
* @default move
*/
hoverCursor: CSSStyleDeclaration['cursor'];
/**
* Default cursor value used when moving an object on canvas
* @type CSSStyleDeclaration['cursor']
* @default move
*/
moveCursor: CSSStyleDeclaration['cursor'];
/**
* Default cursor value used for the entire canvas
* @type String
* @default default
*/
defaultCursor: CSSStyleDeclaration['cursor'];
/**
* Cursor value used during free drawing
* @type String
* @default crosshair
*/
freeDrawingCursor: CSSStyleDeclaration['cursor'];
/**
* Cursor value used for disabled elements ( corners with disabled action )
* @type String
* @since 2.0.0
* @default not-allowed
*/
notAllowedCursor: CSSStyleDeclaration['cursor'];
}
export interface TargetFindOptions {
/**
* When true, object detection happens on per-pixel basis rather than on per-bounding-box
* @type Boolean
* @default
*/
perPixelTargetFind: boolean;
/**
* Number of pixels around target pixel to tolerate (consider active) during object detection
* @type Number
* @default
*/
targetFindTolerance: number;
/**
* When true, target detection is skipped. Target detection will return always undefined.
* click selection won't work anymore, events will fire with no targets.
* if something is selected before setting it to true, it will be deselected at the first click.
* area selection will still work. check the `selection` property too.
* if you deactivate both, you should look into staticCanvas.
* @type Boolean
* @default
*/
skipTargetFind: boolean;
}
export interface CanvasEventsOptions {
/**
* Indicates if the right click on canvas can output the context menu or not
* @type Boolean
* @since 1.6.5
* @default
*/
stopContextMenu: boolean;
/**
* Indicates if the canvas can fire right click events
* @type Boolean
* @since 1.6.5
* @default
*/
fireRightClick: boolean;
/**
* Indicates if the canvas can fire middle click events
* @type Boolean
* @since 1.7.8
* @default
*/
fireMiddleClick: boolean;
/**
* When the option is enabled, PointerEvent is used instead of TPointerEvent.
* @type Boolean
* @default
*/
enablePointerEvents: boolean;
}
export interface CanvasOptions
extends StaticCanvasOptions,
CanvasTransformOptions,
CanvasSelectionOptions,
CanvasCursorOptions,
TargetFindOptions,
CanvasEventsOptions {
/**
* Default element class that's given to wrapper (div) element of canvas
* @type String
* @default
* @deprecated customize {@link CanvasDOMManager} instead or access {@link elements} directly
*/
containerClass: string;
/**
* Indicates whether objects should remain in current stack position when selected.
* When false objects are brought to top and rendered as part of the selection group
* @type Boolean
* @default
*/
preserveObjectStacking: boolean;
}
export type TCanvasOptions = TOptions<CanvasOptions>;
export const canvasDefaults: TOptions<CanvasOptions> = {
uniformScaling: true,
uniScaleKey: 'shiftKey',
centeredScaling: false,
centeredRotation: false,
centeredKey: 'altKey',
altActionKey: 'shiftKey',
selection: true,
selectionKey: 'shiftKey',
selectionColor: 'rgba(100, 100, 255, 0.3)',
selectionDashArray: [],
selectionBorderColor: 'rgba(255, 255, 255, 0.3)',
selectionLineWidth: 1,
selectionFullyContained: false,
hoverCursor: 'move',
moveCursor: 'move',
defaultCursor: 'default',
freeDrawingCursor: 'crosshair',
notAllowedCursor: 'not-allowed',
perPixelTargetFind: false,
targetFindTolerance: 0,
skipTargetFind: false,
stopContextMenu: false,
fireRightClick: false,
fireMiddleClick: false,
enablePointerEvents: false,
containerClass: 'canvas-container',
preserveObjectStacking: false,
};