@postermywall/fabricjs-2 6.0.0-rc2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/dist/index.js +229 -491
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +229 -491
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +229 -491
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +229 -491
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/canvas/Canvas.d.ts.map +1 -1
  17. package/dist/src/canvas/Canvas.min.mjs +1 -1
  18. package/dist/src/canvas/Canvas.min.mjs.map +1 -1
  19. package/dist/src/canvas/Canvas.mjs +8 -9
  20. package/dist/src/canvas/Canvas.mjs.map +1 -1
  21. package/dist/src/canvas/SelectableCanvas.d.ts +1 -1
  22. package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
  23. package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
  24. package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
  25. package/dist/src/canvas/SelectableCanvas.mjs +1 -1
  26. package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
  27. package/dist/src/canvas/StaticCanvas.d.ts +4 -4
  28. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  29. package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
  30. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  31. package/dist/src/canvas/StaticCanvas.mjs +0 -13
  32. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  33. package/dist/src/color/Color.d.ts +1 -0
  34. package/dist/src/color/Color.d.ts.map +1 -1
  35. package/dist/src/color/Color.min.mjs +1 -1
  36. package/dist/src/color/Color.min.mjs.map +1 -1
  37. package/dist/src/color/Color.mjs +3 -1
  38. package/dist/src/color/Color.mjs.map +1 -1
  39. package/dist/src/filters/BaseFilter.d.ts +16 -23
  40. package/dist/src/filters/BaseFilter.d.ts.map +1 -1
  41. package/dist/src/filters/BaseFilter.min.mjs +1 -1
  42. package/dist/src/filters/BaseFilter.min.mjs.map +1 -1
  43. package/dist/src/filters/BaseFilter.mjs +24 -41
  44. package/dist/src/filters/BaseFilter.mjs.map +1 -1
  45. package/dist/src/filters/BlendColor.d.ts +13 -24
  46. package/dist/src/filters/BlendColor.d.ts.map +1 -1
  47. package/dist/src/filters/BlendColor.min.mjs +1 -1
  48. package/dist/src/filters/BlendColor.min.mjs.map +1 -1
  49. package/dist/src/filters/BlendColor.mjs +1 -25
  50. package/dist/src/filters/BlendColor.mjs.map +1 -1
  51. package/dist/src/filters/BlendImage.d.ts +18 -19
  52. package/dist/src/filters/BlendImage.d.ts.map +1 -1
  53. package/dist/src/filters/BlendImage.min.mjs +1 -1
  54. package/dist/src/filters/BlendImage.min.mjs.map +1 -1
  55. package/dist/src/filters/BlendImage.mjs +13 -24
  56. package/dist/src/filters/BlendImage.mjs.map +1 -1
  57. package/dist/src/filters/Blur.d.ts +10 -12
  58. package/dist/src/filters/Blur.d.ts.map +1 -1
  59. package/dist/src/filters/Blur.min.mjs +1 -1
  60. package/dist/src/filters/Blur.min.mjs.map +1 -1
  61. package/dist/src/filters/Blur.mjs +5 -14
  62. package/dist/src/filters/Blur.mjs.map +1 -1
  63. package/dist/src/filters/Boilerplate.d.ts +11 -13
  64. package/dist/src/filters/Boilerplate.d.ts.map +1 -1
  65. package/dist/src/filters/Brightness.d.ts +10 -12
  66. package/dist/src/filters/Brightness.d.ts.map +1 -1
  67. package/dist/src/filters/Brightness.min.mjs +1 -1
  68. package/dist/src/filters/Brightness.min.mjs.map +1 -1
  69. package/dist/src/filters/Brightness.mjs +4 -16
  70. package/dist/src/filters/Brightness.mjs.map +1 -1
  71. package/dist/src/filters/Canvas2dFilterBackend.d.ts +1 -1
  72. package/dist/src/filters/Canvas2dFilterBackend.d.ts.map +1 -1
  73. package/dist/src/filters/Canvas2dFilterBackend.min.mjs.map +1 -1
  74. package/dist/src/filters/Canvas2dFilterBackend.mjs.map +1 -1
  75. package/dist/src/filters/ColorMatrix.d.ts +17 -15
  76. package/dist/src/filters/ColorMatrix.d.ts.map +1 -1
  77. package/dist/src/filters/ColorMatrix.min.mjs +1 -1
  78. package/dist/src/filters/ColorMatrix.min.mjs.map +1 -1
  79. package/dist/src/filters/ColorMatrix.mjs +7 -27
  80. package/dist/src/filters/ColorMatrix.mjs.map +1 -1
  81. package/dist/src/filters/ColorMatrixFilters.d.ts +63 -497
  82. package/dist/src/filters/ColorMatrixFilters.d.ts.map +1 -1
  83. package/dist/src/filters/ColorMatrixFilters.min.mjs +1 -1
  84. package/dist/src/filters/ColorMatrixFilters.min.mjs.map +1 -1
  85. package/dist/src/filters/ColorMatrixFilters.mjs +13 -8
  86. package/dist/src/filters/ColorMatrixFilters.mjs.map +1 -1
  87. package/dist/src/filters/Composed.d.ts +11 -10
  88. package/dist/src/filters/Composed.d.ts.map +1 -1
  89. package/dist/src/filters/Composed.min.mjs +1 -1
  90. package/dist/src/filters/Composed.min.mjs.map +1 -1
  91. package/dist/src/filters/Composed.mjs +7 -12
  92. package/dist/src/filters/Composed.mjs.map +1 -1
  93. package/dist/src/filters/Contrast.d.ts +10 -12
  94. package/dist/src/filters/Contrast.d.ts.map +1 -1
  95. package/dist/src/filters/Contrast.min.mjs +1 -1
  96. package/dist/src/filters/Contrast.min.mjs.map +1 -1
  97. package/dist/src/filters/Contrast.mjs +6 -17
  98. package/dist/src/filters/Contrast.mjs.map +1 -1
  99. package/dist/src/filters/Convolute.d.ts +11 -14
  100. package/dist/src/filters/Convolute.d.ts.map +1 -1
  101. package/dist/src/filters/Convolute.min.mjs +1 -1
  102. package/dist/src/filters/Convolute.min.mjs.map +1 -1
  103. package/dist/src/filters/Convolute.mjs +1 -15
  104. package/dist/src/filters/Convolute.mjs.map +1 -1
  105. package/dist/src/filters/Gamma.d.ts +17 -14
  106. package/dist/src/filters/Gamma.d.ts.map +1 -1
  107. package/dist/src/filters/Gamma.min.mjs +1 -1
  108. package/dist/src/filters/Gamma.min.mjs.map +1 -1
  109. package/dist/src/filters/Gamma.mjs +20 -24
  110. package/dist/src/filters/Gamma.mjs.map +1 -1
  111. package/dist/src/filters/Grayscale.d.ts +8 -11
  112. package/dist/src/filters/Grayscale.d.ts.map +1 -1
  113. package/dist/src/filters/Grayscale.min.mjs +1 -1
  114. package/dist/src/filters/Grayscale.min.mjs.map +1 -1
  115. package/dist/src/filters/Grayscale.mjs +2 -14
  116. package/dist/src/filters/Grayscale.mjs.map +1 -1
  117. package/dist/src/filters/HueRotation.d.ts +11 -5
  118. package/dist/src/filters/HueRotation.d.ts.map +1 -1
  119. package/dist/src/filters/HueRotation.min.mjs +1 -1
  120. package/dist/src/filters/HueRotation.min.mjs.map +1 -1
  121. package/dist/src/filters/HueRotation.mjs +10 -5
  122. package/dist/src/filters/HueRotation.mjs.map +1 -1
  123. package/dist/src/filters/Invert.d.ts +10 -13
  124. package/dist/src/filters/Invert.d.ts.map +1 -1
  125. package/dist/src/filters/Invert.min.mjs +1 -1
  126. package/dist/src/filters/Invert.min.mjs.map +1 -1
  127. package/dist/src/filters/Invert.mjs +2 -15
  128. package/dist/src/filters/Invert.mjs.map +1 -1
  129. package/dist/src/filters/Noise.d.ts +9 -20
  130. package/dist/src/filters/Noise.d.ts.map +1 -1
  131. package/dist/src/filters/Noise.min.mjs +1 -1
  132. package/dist/src/filters/Noise.min.mjs.map +1 -1
  133. package/dist/src/filters/Noise.mjs +4 -27
  134. package/dist/src/filters/Noise.mjs.map +1 -1
  135. package/dist/src/filters/Pixelate.d.ts +8 -12
  136. package/dist/src/filters/Pixelate.d.ts.map +1 -1
  137. package/dist/src/filters/Pixelate.min.mjs +1 -1
  138. package/dist/src/filters/Pixelate.min.mjs.map +1 -1
  139. package/dist/src/filters/Pixelate.mjs +2 -16
  140. package/dist/src/filters/Pixelate.mjs.map +1 -1
  141. package/dist/src/filters/RemoveColor.d.ts +12 -23
  142. package/dist/src/filters/RemoveColor.d.ts.map +1 -1
  143. package/dist/src/filters/RemoveColor.min.mjs +1 -1
  144. package/dist/src/filters/RemoveColor.min.mjs.map +1 -1
  145. package/dist/src/filters/RemoveColor.mjs +2 -25
  146. package/dist/src/filters/RemoveColor.mjs.map +1 -1
  147. package/dist/src/filters/Resize.d.ts +14 -30
  148. package/dist/src/filters/Resize.d.ts.map +1 -1
  149. package/dist/src/filters/Resize.min.mjs +1 -1
  150. package/dist/src/filters/Resize.min.mjs.map +1 -1
  151. package/dist/src/filters/Resize.mjs +3 -30
  152. package/dist/src/filters/Resize.mjs.map +1 -1
  153. package/dist/src/filters/Saturation.d.ts +9 -12
  154. package/dist/src/filters/Saturation.d.ts.map +1 -1
  155. package/dist/src/filters/Saturation.min.mjs +1 -1
  156. package/dist/src/filters/Saturation.min.mjs.map +1 -1
  157. package/dist/src/filters/Saturation.mjs +8 -20
  158. package/dist/src/filters/Saturation.mjs.map +1 -1
  159. package/dist/src/filters/Vibrance.d.ts +10 -13
  160. package/dist/src/filters/Vibrance.d.ts.map +1 -1
  161. package/dist/src/filters/Vibrance.min.mjs +1 -1
  162. package/dist/src/filters/Vibrance.min.mjs.map +1 -1
  163. package/dist/src/filters/Vibrance.mjs +6 -18
  164. package/dist/src/filters/Vibrance.mjs.map +1 -1
  165. package/dist/src/filters/WebGLFilterBackend.d.ts +1 -1
  166. package/dist/src/filters/WebGLFilterBackend.d.ts.map +1 -1
  167. package/dist/src/filters/WebGLFilterBackend.min.mjs.map +1 -1
  168. package/dist/src/filters/WebGLFilterBackend.mjs.map +1 -1
  169. package/dist/src/filters/shaders/blendImage.d.ts +1 -0
  170. package/dist/src/filters/shaders/blendImage.d.ts.map +1 -1
  171. package/dist/src/filters/shaders/blendImage.min.mjs +1 -1
  172. package/dist/src/filters/shaders/blendImage.min.mjs.map +1 -1
  173. package/dist/src/filters/shaders/blendImage.mjs +2 -1
  174. package/dist/src/filters/shaders/blendImage.mjs.map +1 -1
  175. package/dist/src/filters/typedefs.d.ts +22 -0
  176. package/dist/src/filters/typedefs.d.ts.map +1 -1
  177. package/dist/src/parser/elements_parser.d.ts +1 -1
  178. package/dist/src/parser/elements_parser.d.ts.map +1 -1
  179. package/dist/src/parser/elements_parser.min.mjs.map +1 -1
  180. package/dist/src/parser/elements_parser.mjs.map +1 -1
  181. package/dist/src/shapes/ActiveSelection.d.ts +1 -1
  182. package/dist/src/shapes/ActiveSelection.d.ts.map +1 -1
  183. package/dist/src/shapes/ActiveSelection.min.mjs +1 -1
  184. package/dist/src/shapes/ActiveSelection.min.mjs.map +1 -1
  185. package/dist/src/shapes/ActiveSelection.mjs +13 -10
  186. package/dist/src/shapes/ActiveSelection.mjs.map +1 -1
  187. package/dist/src/shapes/Group.d.ts +9 -0
  188. package/dist/src/shapes/Group.d.ts.map +1 -1
  189. package/dist/src/shapes/Group.min.mjs +1 -1
  190. package/dist/src/shapes/Group.min.mjs.map +1 -1
  191. package/dist/src/shapes/Group.mjs +10 -1
  192. package/dist/src/shapes/Group.mjs.map +1 -1
  193. package/dist/src/shapes/Image.d.ts +4 -4
  194. package/dist/src/shapes/Image.d.ts.map +1 -1
  195. package/dist/src/shapes/Image.min.mjs.map +1 -1
  196. package/dist/src/shapes/Image.mjs.map +1 -1
  197. package/dist/src/shapes/Object/InteractiveObject.d.ts +3 -0
  198. package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
  199. package/dist/src/shapes/Object/InteractiveObject.min.mjs +1 -1
  200. package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
  201. package/dist/src/shapes/Object/InteractiveObject.mjs +3 -1
  202. package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
  203. package/dist/src/shapes/Object/Object.d.ts +1 -16
  204. package/dist/src/shapes/Object/Object.d.ts.map +1 -1
  205. package/dist/src/shapes/Object/Object.min.mjs +1 -1
  206. package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
  207. package/dist/src/shapes/Object/Object.mjs +9 -10
  208. package/dist/src/shapes/Object/Object.mjs.map +1 -1
  209. package/dist/src/shapes/Object/StackedObject.d.ts +8 -15
  210. package/dist/src/shapes/Object/StackedObject.d.ts.map +1 -1
  211. package/dist/src/shapes/Object/StackedObject.min.mjs +1 -1
  212. package/dist/src/shapes/Object/StackedObject.min.mjs.map +1 -1
  213. package/dist/src/shapes/Object/StackedObject.mjs +11 -21
  214. package/dist/src/shapes/Object/StackedObject.mjs.map +1 -1
  215. package/dist/src/shapes/Path.d.ts +2 -2
  216. package/dist/src/shapes/Path.d.ts.map +1 -1
  217. package/dist/src/shapes/Path.min.mjs.map +1 -1
  218. package/dist/src/shapes/Path.mjs +2 -2
  219. package/dist/src/shapes/Path.mjs.map +1 -1
  220. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts +1 -1
  221. package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
  222. package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
  223. package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
  224. package/dist/src/util/misc/objectEnlive.d.ts +2 -2
  225. package/dist/src/util/misc/objectEnlive.d.ts.map +1 -1
  226. package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
  227. package/dist/src/util/misc/objectEnlive.mjs.map +1 -1
  228. package/package.json +2 -2
  229. package/src/canvas/Canvas.ts +6 -9
  230. package/src/canvas/SelectableCanvas.ts +2 -2
  231. package/src/canvas/StaticCanvas.ts +4 -18
  232. package/src/color/Color.ts +2 -1
  233. package/src/color/color.test.ts +6 -0
  234. package/src/filters/BaseFilter.ts +45 -51
  235. package/src/filters/BlendColor.ts +13 -35
  236. package/src/filters/BlendImage.ts +26 -40
  237. package/src/filters/Blur.ts +13 -20
  238. package/src/filters/Boilerplate.ts +13 -22
  239. package/src/filters/Brightness.ts +12 -21
  240. package/src/filters/Canvas2dFilterBackend.ts +1 -1
  241. package/src/filters/ColorMatrix.ts +29 -34
  242. package/src/filters/ColorMatrixFilters.ts +15 -9
  243. package/src/filters/Composed.ts +26 -16
  244. package/src/filters/Contrast.ts +15 -23
  245. package/src/filters/Convolute.ts +11 -23
  246. package/src/filters/Gamma.ts +32 -24
  247. package/src/filters/Grayscale.ts +8 -19
  248. package/src/filters/HueRotation.ts +21 -11
  249. package/src/filters/Invert.ts +11 -22
  250. package/src/filters/Noise.ts +11 -30
  251. package/src/filters/Pixelate.ts +9 -22
  252. package/src/filters/RemoveColor.ts +21 -35
  253. package/src/filters/Resize.ts +20 -44
  254. package/src/filters/Saturation.ts +16 -27
  255. package/src/filters/Vibrance.ts +14 -24
  256. package/src/filters/WebGLFilterBackend.ts +1 -1
  257. package/src/filters/shaders/blendImage.ts +12 -0
  258. package/src/filters/typedefs.ts +23 -0
  259. package/src/parser/elements_parser.ts +1 -1
  260. package/src/shapes/ActiveSelection.ts +8 -4
  261. package/src/shapes/Group.ts +16 -1
  262. package/src/shapes/Image.ts +8 -6
  263. package/src/shapes/Object/InteractiveObject.ts +3 -1
  264. package/src/shapes/Object/Object.ts +10 -35
  265. package/src/shapes/Object/StackedObject.ts +28 -44
  266. package/src/shapes/Path.ts +4 -4
  267. package/src/shapes/Text/TextSVGExportMixin.ts +1 -1
  268. package/src/util/misc/objectEnlive.ts +12 -2
@@ -1,15 +1,20 @@
1
1
  import { classRegistry } from '../ClassRegistry';
2
2
  import { Color } from '../color/Color';
3
- import type { TClassProperties } from '../typedefs';
4
3
  import { BaseFilter } from './BaseFilter';
5
4
  import { fragmentShader } from './shaders/removeColor';
6
5
  import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
7
- export const removeColorDefaultValues: Partial<TClassProperties<RemoveColor>> =
8
- {
9
- color: '#FFFFFF',
10
- distance: 0.02,
11
- useAlpha: false,
12
- };
6
+
7
+ export type RemoveColorOwnProps = {
8
+ color: string;
9
+ distance: number;
10
+ useAlpha: boolean;
11
+ };
12
+
13
+ export const removeColorDefaultValues: RemoveColorOwnProps = {
14
+ color: '#FFFFFF',
15
+ distance: 0.02,
16
+ useAlpha: false,
17
+ };
13
18
 
14
19
  /**
15
20
  * Remove white filter class
@@ -21,30 +26,35 @@ export const removeColorDefaultValues: Partial<TClassProperties<RemoveColor>> =
21
26
  * object.applyFilters();
22
27
  * canvas.renderAll();
23
28
  */
24
- export class RemoveColor extends BaseFilter {
29
+ export class RemoveColor extends BaseFilter<
30
+ 'RemoveColor',
31
+ RemoveColorOwnProps
32
+ > {
25
33
  /**
26
34
  * Color to remove, in any format understood by {@link Color}.
27
35
  * @param {String} type
28
36
  * @default
29
37
  */
30
- declare color: string;
38
+ declare color: RemoveColorOwnProps['color'];
31
39
 
32
40
  /**
33
41
  * distance to actual color, as value up or down from each r,g,b
34
42
  * between 0 and 1
35
43
  **/
36
- declare distance: number;
44
+ declare distance: RemoveColorOwnProps['distance'];
37
45
 
38
46
  /**
39
47
  * For color to remove inside distance, use alpha channel for a smoother deletion
40
48
  * NOT IMPLEMENTED YET
41
49
  **/
42
- declare useAlpha: boolean;
50
+ declare useAlpha: RemoveColorOwnProps['useAlpha'];
43
51
 
44
52
  static type = 'RemoveColor';
45
53
 
46
54
  static defaults = removeColorDefaultValues;
47
55
 
56
+ static uniformLocations = ['uLow', 'uHigh'];
57
+
48
58
  getFragmentSource() {
49
59
  return fragmentShader;
50
60
  }
@@ -81,22 +91,6 @@ export class RemoveColor extends BaseFilter {
81
91
  }
82
92
  }
83
93
 
84
- /**
85
- * Return WebGL uniform locations for this filter's shader.
86
- *
87
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
88
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
89
- */
90
- getUniformLocations(
91
- gl: WebGLRenderingContext,
92
- program: WebGLProgram
93
- ): TWebGLUniformLocationMap {
94
- return {
95
- uLow: gl.getUniformLocation(program, 'uLow'),
96
- uHigh: gl.getUniformLocation(program, 'uHigh'),
97
- };
98
- }
99
-
100
94
  /**
101
95
  * Send data from this filter to its shader program's uniforms.
102
96
  *
@@ -124,14 +118,6 @@ export class RemoveColor extends BaseFilter {
124
118
  gl.uniform4fv(uniformLocations.uLow, lowC);
125
119
  gl.uniform4fv(uniformLocations.uHigh, highC);
126
120
  }
127
-
128
- /**
129
- * Returns object representation of an instance
130
- * @return {Object} Object representation of an instance
131
- */
132
- toObject() {
133
- return { ...super.toObject(), color: this.color, distance: this.distance };
134
- }
135
121
  }
136
122
 
137
123
  classRegistry.setClass(RemoveColor);
@@ -1,4 +1,3 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
2
  import type {
4
3
  T2DPipelineState,
@@ -10,21 +9,22 @@ import { classRegistry } from '../ClassRegistry';
10
9
  import { createCanvasElement } from '../util/misc/dom';
11
10
  import type { XY } from '../Point';
12
11
 
13
- export const resizeDefaultValues: Partial<TClassProperties<Resize>> = {
12
+ export type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';
13
+
14
+ export type ResizeOwnProps = {
15
+ resizeType: TResizeType;
16
+ scaleX: number;
17
+ scaleY: number;
18
+ lanczosLobes: number;
19
+ };
20
+
21
+ export const resizeDefaultValues: ResizeOwnProps = {
14
22
  resizeType: 'hermite',
15
23
  scaleX: 1,
16
24
  scaleY: 1,
17
25
  lanczosLobes: 3,
18
- fragmentSourceTOP: `
19
- precision highp float;
20
- uniform sampler2D uTexture;
21
- uniform vec2 uDelta;
22
- varying vec2 vTexCoord;
23
- `,
24
26
  };
25
27
 
26
- export type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';
27
-
28
28
  type ResizeDuring2DResize = Resize & {
29
29
  rcpScaleX: number;
30
30
  rcpScaleY: number;
@@ -49,54 +49,41 @@ type ResizeDuringWEBGLResize = Resize & {
49
49
  * object.filters.push(filter);
50
50
  * object.applyFilters(canvas.renderAll.bind(canvas));
51
51
  */
52
- export class Resize extends BaseFilter {
52
+ export class Resize extends BaseFilter<'Resize', ResizeOwnProps> {
53
53
  /**
54
54
  * Resize type
55
55
  * for webgl resizeType is just lanczos, for canvas2d can be:
56
56
  * bilinear, hermite, sliceHack, lanczos.
57
57
  * @default
58
58
  */
59
- declare resizeType: TResizeType;
59
+ declare resizeType: ResizeOwnProps['resizeType'];
60
60
 
61
61
  /**
62
62
  * Scale factor for resizing, x axis
63
63
  * @param {Number} scaleX
64
64
  * @default
65
65
  */
66
- declare scaleX: number;
66
+ declare scaleX: ResizeOwnProps['scaleX'];
67
67
 
68
68
  /**
69
69
  * Scale factor for resizing, y axis
70
70
  * @param {Number} scaleY
71
71
  * @default
72
72
  */
73
- declare scaleY: number;
73
+ declare scaleY: ResizeOwnProps['scaleY'];
74
74
 
75
75
  /**
76
76
  * LanczosLobes parameter for lanczos filter, valid for resizeType lanczos
77
77
  * @param {Number} lanczosLobes
78
78
  * @default
79
79
  */
80
- declare lanczosLobes: number;
81
-
82
- declare fragmentSourceTOP: string;
80
+ declare lanczosLobes: ResizeOwnProps['lanczosLobes'];
83
81
 
84
82
  static type = 'Resize';
85
83
 
86
84
  static defaults = resizeDefaultValues;
87
85
 
88
- /**
89
- * Return WebGL uniform locations for this filter's shader.
90
- *
91
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
92
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
93
- */
94
- getUniformLocations(gl: WebGLRenderingContext, program: WebGLProgram) {
95
- return {
96
- uDelta: gl.getUniformLocation(program, 'uDelta'),
97
- uTaps: gl.getUniformLocation(program, 'uTaps'),
98
- };
99
- }
86
+ static uniformLocations = ['uDelta', 'uTaps'];
100
87
 
101
88
  /**
102
89
  * Send data from this filter to its shader program's uniforms.
@@ -152,7 +139,10 @@ export class Resize extends BaseFilter {
152
139
  offsets[i - 1] = `${i}.0 * uDelta`;
153
140
  }
154
141
  return `
155
- ${this.fragmentSourceTOP}
142
+ precision highp float;
143
+ uniform sampler2D uTexture;
144
+ uniform vec2 uDelta;
145
+ varying vec2 vTexCoord;
156
146
  uniform float uTaps[${filterWindow}];
157
147
  void main() {
158
148
  vec4 color = texture2D(uTexture, vTexCoord);
@@ -552,20 +542,6 @@ export class Resize extends BaseFilter {
552
542
  }
553
543
  return img2;
554
544
  }
555
-
556
- /**
557
- * Returns object representation of an instance
558
- * @return {Object} Object representation of an instance
559
- */
560
- toObject() {
561
- return {
562
- type: this.type,
563
- scaleX: this.scaleX,
564
- scaleY: this.scaleY,
565
- resizeType: this.resizeType,
566
- lanczosLobes: this.lanczosLobes,
567
- };
568
- }
569
545
  }
570
546
 
571
547
  classRegistry.setClass(Resize);
@@ -1,9 +1,16 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
2
  import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
4
3
  import { classRegistry } from '../ClassRegistry';
5
4
  import { fragmentSource } from './shaders/saturation';
6
5
 
6
+ export type SaturationOwnProps = {
7
+ saturation: number;
8
+ };
9
+
10
+ export const saturationDefaultValues: SaturationOwnProps = {
11
+ saturation: 0,
12
+ };
13
+
7
14
  /**
8
15
  * Saturate filter class
9
16
  * @example
@@ -13,13 +20,7 @@ import { fragmentSource } from './shaders/saturation';
13
20
  * object.filters.push(filter);
14
21
  * object.applyFilters();
15
22
  */
16
-
17
- export const saturationDefaultValues: Partial<TClassProperties<Saturation>> = {
18
- saturation: 0,
19
- mainParameter: 'saturation',
20
- };
21
-
22
- export class Saturation extends BaseFilter {
23
+ export class Saturation extends BaseFilter<'Saturation', SaturationOwnProps> {
23
24
  /**
24
25
  * Saturation value, from -1 to 1.
25
26
  * Increases/decreases the color saturation.
@@ -28,12 +29,14 @@ export class Saturation extends BaseFilter {
28
29
  * @param {Number} saturation
29
30
  * @default
30
31
  */
31
- declare saturation: number;
32
+ declare saturation: SaturationOwnProps['saturation'];
32
33
 
33
34
  static type = 'Saturation';
34
35
 
35
36
  static defaults = saturationDefaultValues;
36
37
 
38
+ static uniformLocations = ['uSaturation'];
39
+
37
40
  getFragmentSource() {
38
41
  return fragmentSource;
39
42
  }
@@ -45,9 +48,6 @@ export class Saturation extends BaseFilter {
45
48
  * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.
46
49
  */
47
50
  applyTo2d({ imageData: { data } }: T2DPipelineState) {
48
- if (this.saturation === 0) {
49
- return;
50
- }
51
51
  const adjust = -this.saturation;
52
52
  for (let i = 0; i < data.length; i += 4) {
53
53
  const max = Math.max(data[i], data[i + 1], data[i + 2]);
@@ -57,21 +57,6 @@ export class Saturation extends BaseFilter {
57
57
  }
58
58
  }
59
59
 
60
- /**
61
- * Return WebGL uniform locations for this filter's shader.
62
- *
63
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
64
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
65
- */
66
- getUniformLocations(
67
- gl: WebGLRenderingContext,
68
- program: WebGLProgram
69
- ): TWebGLUniformLocationMap {
70
- return {
71
- uSaturation: gl.getUniformLocation(program, 'uSaturation'),
72
- };
73
- }
74
-
75
60
  /**
76
61
  * Send data from this filter to its shader program's uniforms.
77
62
  *
@@ -84,6 +69,10 @@ export class Saturation extends BaseFilter {
84
69
  ) {
85
70
  gl.uniform1f(uniformLocations.uSaturation, -this.saturation);
86
71
  }
72
+
73
+ isNeutralState() {
74
+ return this.saturation === 0;
75
+ }
87
76
  }
88
77
 
89
78
  classRegistry.setClass(Saturation);
@@ -1,12 +1,14 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
2
  import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
4
3
  import { classRegistry } from '../ClassRegistry';
5
4
  import { fragmentSource } from './shaders/vibrance';
6
5
 
7
- export const vibranceDefaultValues: Partial<TClassProperties<Vibrance>> = {
6
+ export type VibranceOwnProps = {
7
+ vibrance: number;
8
+ };
9
+
10
+ export const vibranceDefaultValues: VibranceOwnProps = {
8
11
  vibrance: 0,
9
- mainParameter: 'vibrance',
10
12
  };
11
13
 
12
14
  /**
@@ -18,7 +20,7 @@ export const vibranceDefaultValues: Partial<TClassProperties<Vibrance>> = {
18
20
  * object.filters.push(filter);
19
21
  * object.applyFilters();
20
22
  */
21
- export class Vibrance extends BaseFilter {
23
+ export class Vibrance extends BaseFilter<'Vibrance', VibranceOwnProps> {
22
24
  /**
23
25
  * Vibrance value, from -1 to 1.
24
26
  * Increases/decreases the saturation of more muted colors with less effect on saturated colors.
@@ -27,12 +29,14 @@ export class Vibrance extends BaseFilter {
27
29
  * @param {Number} vibrance
28
30
  * @default
29
31
  */
30
- declare vibrance: number;
32
+ declare vibrance: VibranceOwnProps['vibrance'];
31
33
 
32
34
  static type = 'Vibrance';
33
35
 
34
36
  static defaults = vibranceDefaultValues;
35
37
 
38
+ static uniformLocations = ['uVibrance'];
39
+
36
40
  getFragmentSource() {
37
41
  return fragmentSource;
38
42
  }
@@ -44,9 +48,6 @@ export class Vibrance extends BaseFilter {
44
48
  * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.
45
49
  */
46
50
  applyTo2d({ imageData: { data } }: T2DPipelineState) {
47
- if (this.vibrance === 0) {
48
- return;
49
- }
50
51
  const adjust = -this.vibrance;
51
52
  for (let i = 0; i < data.length; i += 4) {
52
53
  const max = Math.max(data[i], data[i + 1], data[i + 2]);
@@ -58,26 +59,11 @@ export class Vibrance extends BaseFilter {
58
59
  }
59
60
  }
60
61
 
61
- /**
62
- * Return WebGL uniform locations for this filter's shader.
63
- *
64
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
65
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
66
- */
67
- getUniformLocations(
68
- gl: WebGLRenderingContext,
69
- program: WebGLProgram
70
- ): TWebGLUniformLocationMap {
71
- return {
72
- uVibrance: gl.getUniformLocation(program, 'uVibrance'),
73
- };
74
- }
75
-
76
62
  /**
77
63
  * Send data from this filter to its shader program's uniforms.
78
64
  *
79
65
  * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
80
- * @param {Object} uniformLocations A map of string uniform names to WebGLUniformLocation objects
66
+ * @param {TWebGLUniformLocationMap} uniformLocations A map of string uniform names to WebGLUniformLocation objects
81
67
  */
82
68
  sendUniformData(
83
69
  gl: WebGLRenderingContext,
@@ -85,6 +71,10 @@ export class Vibrance extends BaseFilter {
85
71
  ) {
86
72
  gl.uniform1f(uniformLocations.uVibrance, -this.vibrance);
87
73
  }
74
+
75
+ isNeutralState() {
76
+ return this.vibrance === 0;
77
+ }
88
78
  }
89
79
 
90
80
  classRegistry.setClass(Vibrance);
@@ -106,7 +106,7 @@ export class WebGLFilterBackend {
106
106
  * omitted, caching will be skipped.
107
107
  */
108
108
  applyFilters(
109
- filters: BaseFilter[],
109
+ filters: BaseFilter<string, Record<string, any>>[],
110
110
  source: TexImageSource,
111
111
  width: number,
112
112
  height: number,
@@ -30,3 +30,15 @@ export const fragmentSource: Record<TBlendImageMode, string> = {
30
30
  }
31
31
  `,
32
32
  } as const;
33
+
34
+ export const vertexSource = `
35
+ attribute vec2 aPosition;
36
+ varying vec2 vTexCoord;
37
+ varying vec2 vTexCoord2;
38
+ uniform mat3 uTransformMatrix;
39
+ void main() {
40
+ vTexCoord = aPosition;
41
+ vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
42
+ gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
43
+ }
44
+ ` as const;
@@ -58,3 +58,26 @@ export type TWebGLProgramCacheItem = {
58
58
  };
59
59
 
60
60
  export type TApplyFilterArgs = {};
61
+
62
+ export type TMatColorMatrix = [
63
+ number,
64
+ number,
65
+ number,
66
+ number,
67
+ number,
68
+ number,
69
+ number,
70
+ number,
71
+ number,
72
+ number,
73
+ number,
74
+ number,
75
+ number,
76
+ number,
77
+ number,
78
+ number,
79
+ number,
80
+ number,
81
+ number,
82
+ number
83
+ ];
@@ -39,7 +39,7 @@ type NotParsedFabricObject = FabricObject & {
39
39
  export class ElementsParser {
40
40
  declare elements: Element[];
41
41
  declare options: LoadImageOptions & ParsedViewboxTransform;
42
- declare reviver: TSvgReviverCallback | undefined;
42
+ declare reviver?: TSvgReviverCallback;
43
43
  declare regexUrl: RegExp;
44
44
  declare doc: Document;
45
45
  declare clipPaths: Record<string, Element[]>;
@@ -59,13 +59,17 @@ export class ActiveSelection extends Group {
59
59
 
60
60
  constructor(
61
61
  objects: FabricObject[] = [],
62
- { layoutManager, ...options }: Partial<ActiveSelectionOptions> = {}
62
+ options: Partial<ActiveSelectionOptions> = {}
63
63
  ) {
64
- super(objects, {
65
- layoutManager: layoutManager ?? new ActiveSelectionLayoutManager(),
66
- });
64
+ super();
67
65
  Object.assign(this, ActiveSelection.ownDefaults);
68
66
  this.setOptions(options);
67
+ const { left, top, layoutManager } = options;
68
+ this.groupInit(objects, {
69
+ left,
70
+ top,
71
+ layoutManager: layoutManager ?? new ActiveSelectionLayoutManager(),
72
+ });
69
73
  }
70
74
 
71
75
  /**
@@ -140,6 +140,21 @@ export class Group
140
140
  super();
141
141
  Object.assign(this, Group.ownDefaults);
142
142
  this.setOptions(options);
143
+ this.groupInit(objects, options);
144
+ }
145
+
146
+ /**
147
+ * Shared code between group and active selection
148
+ * Meant to be used by the constructor.
149
+ */
150
+ protected groupInit(
151
+ objects: FabricObject[],
152
+ options: {
153
+ layoutManager?: LayoutManager;
154
+ top?: number;
155
+ left?: number;
156
+ }
157
+ ) {
143
158
  this._objects = [...objects]; // Avoid unwanted mutations of Collection to affect the caller
144
159
 
145
160
  this.__objectSelectionTracker = this.__objectSelectionMonitor.bind(
@@ -156,7 +171,7 @@ export class Group
156
171
  });
157
172
 
158
173
  // perform initial layout
159
- this.layoutManager = options.layoutManager || new LayoutManager();
174
+ this.layoutManager = options.layoutManager ?? new LayoutManager();
160
175
  this.layoutManager.performLayout({
161
176
  type: LAYOUT_TYPE_INITIALIZATION,
162
177
  target: this,
@@ -45,7 +45,7 @@ interface UniqueImageProps {
45
45
  cropX: number;
46
46
  cropY: number;
47
47
  imageSmoothing: boolean;
48
- filters: BaseFilter[];
48
+ filters: BaseFilter<string, Record<string, any>>[];
49
49
  resizeFilter?: Resize;
50
50
  }
51
51
 
@@ -166,7 +166,7 @@ export class FabricImage<
166
166
 
167
167
  protected declare src: string;
168
168
 
169
- declare filters: BaseFilter[];
169
+ declare filters: BaseFilter<string, Record<string, any>>[];
170
170
  declare resizeFilter: Resize;
171
171
 
172
172
  declare _element: ImageSource;
@@ -506,7 +506,7 @@ export class FabricImage<
506
506
  this._lastScaleX = filter.scaleX = scaleX;
507
507
  this._lastScaleY = filter.scaleY = scaleY;
508
508
  getFilterBackend().applyFilters(
509
- [filter as BaseFilter],
509
+ [filter],
510
510
  elementToFilter,
511
511
  sourceWidth,
512
512
  sourceHeight,
@@ -522,7 +522,9 @@ export class FabricImage<
522
522
  * @param {Array} filters to be applied
523
523
  * @param {Boolean} forResizing specify if the filter operation is a resize operation
524
524
  */
525
- applyFilters(filters: BaseFilter[] = this.filters || []) {
525
+ applyFilters(
526
+ filters: BaseFilter<string, Record<string, any>>[] = this.filters || []
527
+ ) {
526
528
  filters = filters.filter((filter) => filter && !filter.isNeutralState());
527
529
  this.set('dirty', true);
528
530
 
@@ -798,9 +800,9 @@ export class FabricImage<
798
800
  ) {
799
801
  return Promise.all([
800
802
  loadImage(src!, { ...options, crossOrigin }),
801
- f && enlivenObjects<BaseFilter>(f, options),
803
+ f && enlivenObjects<BaseFilter<string>>(f, options),
802
804
  // TODO: redundant - handled by enlivenObjectEnlivables
803
- rf && enlivenObjects<BaseFilter>([rf], options),
805
+ rf && enlivenObjects<BaseFilter<'Resize'>>([rf], options),
804
806
  enlivenObjectEnlivables(object, options),
805
807
  ]).then(([el, filters = [], [resizeFilter] = [], hydratedProps = {}]) => {
806
808
  return new this(el, {
@@ -540,6 +540,9 @@ export class InteractiveFabricObject<
540
540
  * Draws corners of an object's bounding box.
541
541
  * Requires public properties: width, height
542
542
  * Requires public options: cornerSize, padding
543
+ * Be aware that since fabric 6.0 this function does not call setCoords anymore.
544
+ * setCoords needs to be called manually if the object of which we are rendering controls
545
+ * is outside the standard selection and transform process.
543
546
  * @param {CanvasRenderingContext2D} ctx Context to draw on
544
547
  * @param {ControlRenderingStyleOverride} styleOverride object to override the object style
545
548
  */
@@ -562,7 +565,6 @@ export class InteractiveFabricObject<
562
565
  ctx.strokeStyle = options.cornerStrokeColor;
563
566
  }
564
567
  this._setLineDash(ctx, options.cornerDashArray);
565
- this.setCoords();
566
568
  this.forEachControl((control, key) => {
567
569
  if (control.getVisibility(this, key)) {
568
570
  const p = this.oCoords[key];
@@ -216,24 +216,6 @@ export class FabricObject<
216
216
  */
217
217
  declare _cacheCanvas?: HTMLCanvasElement;
218
218
 
219
- /**
220
- * Size of the cache canvas, width
221
- * since 1.7.0
222
- * @type number
223
- * @default undefined
224
- * @private
225
- */
226
- declare cacheWidth?: number;
227
-
228
- /**
229
- * Size of the cache canvas, height
230
- * since 1.7.0
231
- * @type number
232
- * @default undefined
233
- * @private
234
- */
235
- declare cacheHeight?: number;
236
-
237
219
  /**
238
220
  * zoom level used on the cacheCanvas to draw the cache, X axe
239
221
  * since 1.7.0
@@ -443,7 +425,7 @@ export class FabricObject<
443
425
  * @return {Boolean} true if the canvas has been resized
444
426
  */
445
427
  _updateCacheCanvas() {
446
- const canvas = this._cacheCanvas,
428
+ const canvas = this._cacheCanvas!,
447
429
  context = this._cacheContext,
448
430
  dims = this._limitCacheSize(this._getCacheCanvasDimensions()),
449
431
  minCacheSize = config.minCacheSideLimit,
@@ -451,8 +433,7 @@ export class FabricObject<
451
433
  height = dims.height,
452
434
  zoomX = dims.zoomX,
453
435
  zoomY = dims.zoomY,
454
- dimensionsChanged =
455
- width !== this.cacheWidth || height !== this.cacheHeight,
436
+ dimensionsChanged = width !== canvas.width || height !== canvas.height,
456
437
  zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY;
457
438
 
458
439
  if (!canvas || !context) {
@@ -505,8 +486,6 @@ export class FabricObject<
505
486
  Math.round(canvas.width / 2 - drawingWidth) + drawingWidth;
506
487
  this.cacheTranslationY =
507
488
  Math.round(canvas.height / 2 - drawingHeight) + drawingHeight;
508
- this.cacheWidth = width;
509
- this.cacheHeight = height;
510
489
  context.translate(this.cacheTranslationX, this.cacheTranslationY);
511
490
  context.scale(zoomX, zoomY);
512
491
  this.zoomX = zoomX;
@@ -829,8 +808,6 @@ export class FabricObject<
829
808
  _removeCacheCanvas() {
830
809
  this._cacheCanvas = undefined;
831
810
  this._cacheContext = null;
832
- this.cacheWidth = 0;
833
- this.cacheHeight = 0;
834
811
  }
835
812
 
836
813
  /**
@@ -1008,20 +985,18 @@ export class FabricObject<
1008
985
  if (this.isNotVisible()) {
1009
986
  return false;
1010
987
  }
1011
- if (
1012
- this._cacheCanvas &&
1013
- this._cacheContext &&
1014
- !skipCanvas &&
1015
- this._updateCacheCanvas()
1016
- ) {
988
+ const canvas = this._cacheCanvas;
989
+ const ctx = this._cacheContext;
990
+ if (canvas && ctx && !skipCanvas && this._updateCacheCanvas()) {
1017
991
  // in this case the context is already cleared.
1018
992
  return true;
1019
993
  } else {
1020
994
  if (this.dirty || (this.clipPath && this.clipPath.absolutePositioned)) {
1021
- if (this._cacheCanvas && this._cacheContext && !skipCanvas) {
1022
- const width = this.cacheWidth! / this.zoomX!;
1023
- const height = this.cacheHeight! / this.zoomY!;
1024
- this._cacheContext.clearRect(-width / 2, -height / 2, width, height);
995
+ if (canvas && ctx && !skipCanvas) {
996
+ ctx.save();
997
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
998
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
999
+ ctx.restore();
1025
1000
  }
1026
1001
  return true;
1027
1002
  }