-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
StaticCanvasOptions.ts
199 lines (176 loc) · 5.8 KB
/
StaticCanvasOptions.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
import { iMatrix } from '../constants';
import type { FabricObject } from '../shapes/Object/FabricObject';
import type { TFiller, TMat2D, TOptions } from '../typedefs';
import type { StaticCanvas } from './StaticCanvas';
interface CanvasDrawableOptions {
/**
* if set to false background image is not affected by viewport transform
* @since 1.6.3
* @type Boolean
* @todo we should really find a different way to do this
* @default
*/
backgroundVpt: boolean;
/**
* Background color of canvas instance.
* @type {(String|TFiller)}
* @default
*/
backgroundColor: TFiller | string;
/**
* Background image of canvas instance.
* since 2.4.0 image caching is active, please when putting an image as background, add to the
* canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom
* vale. As an alternative you can disable image objectCaching
* @type FabricObject
* @default
*/
backgroundImage?: FabricObject;
/**
* if set to false overlay image is not affected by viewport transform
* @since 1.6.3
* @type Boolean
* @todo we should really find a different way to do this
* @default
*/
overlayVpt: boolean;
/**
* Overlay color of canvas instance.
* @since 1.3.9
* @type {(String|TFiller)}
* @default
*/
overlayColor: TFiller | string;
/**
* Overlay image of canvas instance.
* since 2.4.0 image caching is active, please when putting an image as overlay, add to the
* canvas property a reference to the canvas it is on. Otherwise the image cannot detect the zoom
* vale. As an alternative you can disable image objectCaching
* @type FabricObject
* @default
*/
overlayImage?: FabricObject;
}
interface CanvasRenderingOptions {
/**
* Indicates whether {@link StaticCanvas#add}, {@link StaticCanvas#insertAt} and {@link StaticCanvas#remove},
* {@link StaticCanvas#moveTo}, {@link StaticCanvas#clear} and many more, should also re-render canvas.
* Disabling this option will not give a performance boost when adding/removing a lot of objects to/from canvas at once
* since the renders are queued and executed one per frame.
* Disabling is suggested anyway and managing the renders of the app manually is not a big effort ( canvas.requestRenderAll() )
* Left default to true to do not break documentation and old app, fiddles.
* @type Boolean
* @default
*/
renderOnAddRemove: boolean;
/**
* Based on vptCoords and object.aCoords, skip rendering of objects that
* are not included in current viewport.
* May greatly help in applications with crowded canvas and use of zoom/pan
* If One of the corner of the bounding box of the object is on the canvas
* the objects get rendered.
* @type Boolean
* @default true
*/
skipOffscreen: boolean;
/**
* When true, canvas is scaled by devicePixelRatio for better rendering on retina screens
* @type Boolean
* @default
*/
enableRetinaScaling: boolean;
/**
* Indicates whether this canvas will use image smoothing, this is on by default in browsers
* @type Boolean
* @default
*/
imageSmoothingEnabled: boolean;
/**
* a fabricObject that, without stroke define a clipping area with their shape. filled in black
* the clipPath object gets used when the canvas has rendered, and the context is placed in the
* top left corner of the canvas.
* clipPath will clip away controls, if you do not want this to happen use controlsAboveOverlay = true
* @type FabricObject
*/
clipPath?: FabricObject;
}
export interface CanvasExportOptions {
/**
* Indicates whether toObject/toDatalessObject should include default values
* if set to false, takes precedence over the object value.
* @type Boolean
* @default
*/
includeDefaultValues: boolean;
/**
* When true, getSvgTransform() will apply the StaticCanvas.viewportTransform to the SVG transformation. When true,
* a zoomed canvas will then produce zoomed SVG output.
* @type Boolean
* @default
*/
svgViewportTransformation: boolean;
}
export interface StaticCanvasOptions
extends CanvasDrawableOptions,
CanvasRenderingOptions,
CanvasExportOptions {
/**
* Width in virtual/logical pixels of the canvas.
* The canvas can be larger than width if retina scaling is active
* @type number
*/
width: number;
/**
* Height in virtual/logical pixels of the canvas.
* The canvas can be taller than width if retina scaling is active
* @type height
*/
height: number;
/**
* Indicates whether object controls (borders/controls) are rendered above overlay image
* @type Boolean
* @default
*
* @todo move to Canvas
*/
controlsAboveOverlay: boolean;
/**
* Indicates whether the browser can be scrolled when using a touchscreen and dragging on the canvas
* @type Boolean
* @default
*
* @todo move to Canvas
*/
allowTouchScrolling: boolean;
/**
* The transformation (a Canvas 2D API transform matrix) which focuses the viewport
* @type Array
* @example <caption>Default transform</caption>
* canvas.viewportTransform = [1, 0, 0, 1, 0, 0];
* @example <caption>Scale by 70% and translate toward bottom-right by 50, without skewing</caption>
* canvas.viewportTransform = [0.7, 0, 0, 0.7, 50, 50];
* @default
*/
viewportTransform: TMat2D;
}
export const staticCanvasDefaults: TOptions<StaticCanvasOptions> = {
backgroundVpt: true,
backgroundColor: '',
overlayVpt: true,
overlayColor: '',
includeDefaultValues: true,
svgViewportTransformation: true,
renderOnAddRemove: true,
skipOffscreen: true,
enableRetinaScaling: true,
imageSmoothingEnabled: true,
/**
* @todo move to Canvas
*/
controlsAboveOverlay: false,
/**
* @todo move to Canvas
*/
allowTouchScrolling: false,
viewportTransform: [...iMatrix],
};