@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,5 +1,4 @@
1
1
  import { Color } from '../color/Color';
2
- import type { TClassProperties } from '../typedefs';
3
2
  import { BaseFilter } from './BaseFilter';
4
3
  import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
5
4
  import { classRegistry } from '../ClassRegistry';
@@ -17,7 +16,13 @@ export type TBlendMode =
17
16
  | 'exclusion'
18
17
  | 'tint';
19
18
 
20
- export const blendColorDefaultValues: Partial<TClassProperties<BlendColor>> = {
19
+ type BlendColorOwnProps = {
20
+ color: string;
21
+ mode: TBlendMode;
22
+ alpha: number;
23
+ };
24
+
25
+ export const blendColorDefaultValues: BlendColorOwnProps = {
21
26
  color: '#F95C63',
22
27
  mode: 'multiply',
23
28
  alpha: 1,
@@ -39,14 +44,14 @@ export const blendColorDefaultValues: Partial<TClassProperties<BlendColor>> = {
39
44
  * object.applyFilters();
40
45
  * canvas.renderAll();
41
46
  */
42
- export class BlendColor extends BaseFilter {
47
+ export class BlendColor extends BaseFilter<'BlendColor', BlendColorOwnProps> {
43
48
  /**
44
49
  * Color to make the blend operation with. default to a reddish color since black or white
45
50
  * gives always strong result.
46
51
  * @type String
47
52
  * @default
48
53
  **/
49
- declare color: string;
54
+ declare color: BlendColorOwnProps['color'];
50
55
 
51
56
  /**
52
57
  * Blend mode for the filter: one of multiply, add, difference, screen, subtract,
@@ -54,19 +59,20 @@ export class BlendColor extends BaseFilter {
54
59
  * @type String
55
60
  * @default
56
61
  **/
57
- declare mode: TBlendMode;
58
-
62
+ declare mode: BlendColorOwnProps['mode'];
59
63
  /**
60
64
  * alpha value. represent the strength of the blend color operation.
61
65
  * @type Number
62
66
  * @default
63
67
  **/
64
- declare alpha: number;
68
+ declare alpha: BlendColorOwnProps['alpha'];
65
69
 
66
70
  static defaults = blendColorDefaultValues;
67
71
 
68
72
  static type = 'BlendColor';
69
73
 
74
+ static uniformLocations = ['uColor'];
75
+
70
76
  getCacheKey() {
71
77
  return `${this.type}_${this.mode}`;
72
78
  }
@@ -168,21 +174,6 @@ export class BlendColor extends BaseFilter {
168
174
  }
169
175
  }
170
176
 
171
- /**
172
- * Return WebGL uniform locations for this filter's shader.
173
- *
174
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
175
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
176
- */
177
- getUniformLocations(
178
- gl: WebGLRenderingContext,
179
- program: WebGLProgram
180
- ): TWebGLUniformLocationMap {
181
- return {
182
- uColor: gl.getUniformLocation(program, 'uColor'),
183
- };
184
- }
185
-
186
177
  /**
187
178
  * Send data from this filter to its shader program's uniforms.
188
179
  *
@@ -200,19 +191,6 @@ export class BlendColor extends BaseFilter {
200
191
  source[3] = this.alpha;
201
192
  gl.uniform4fv(uniformLocations.uColor, source);
202
193
  }
203
-
204
- /**
205
- * Returns object representation of an instance
206
- * @return {Object} Object representation of an instance
207
- */
208
- toObject() {
209
- return {
210
- type: this.type,
211
- color: this.color,
212
- mode: this.mode,
213
- alpha: this.alpha,
214
- };
215
- }
216
194
  }
217
195
 
218
196
  classRegistry.setClass(BlendColor);
@@ -1,5 +1,4 @@
1
1
  import { FabricImage } from '../shapes/Image';
2
- import type { TClassProperties } from '../typedefs';
3
2
  import { createCanvasElement } from '../util/misc/dom';
4
3
  import { BaseFilter } from './BaseFilter';
5
4
  import type {
@@ -9,24 +8,18 @@ import type {
9
8
  } from './typedefs';
10
9
  import type { WebGLFilterBackend } from './WebGLFilterBackend';
11
10
  import { classRegistry } from '../ClassRegistry';
12
- import { fragmentSource } from './shaders/blendImage';
11
+ import { fragmentSource, vertexSource } from './shaders/blendImage';
13
12
 
14
13
  export type TBlendImageMode = 'multiply' | 'mask';
15
14
 
16
- export const blendImageDefaultValues: Partial<TClassProperties<BlendImage>> = {
15
+ type BlendImageOwnProps = {
16
+ mode: TBlendImageMode;
17
+ alpha: number;
18
+ };
19
+
20
+ export const blendImageDefaultValues: BlendImageOwnProps = {
17
21
  mode: 'multiply',
18
22
  alpha: 1,
19
- vertexSource: `
20
- attribute vec2 aPosition;
21
- varying vec2 vTexCoord;
22
- varying vec2 vTexCoord2;
23
- uniform mat3 uTransformMatrix;
24
- void main() {
25
- vTexCoord = aPosition;
26
- vTexCoord2 = (uTransformMatrix * vec3(aPosition, 1.0)).xy;
27
- gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0);
28
- }
29
- `,
30
23
  };
31
24
 
32
25
  /**
@@ -45,7 +38,7 @@ export const blendImageDefaultValues: Partial<TClassProperties<BlendImage>> = {
45
38
  * object.applyFilters();
46
39
  * canvas.renderAll();
47
40
  */
48
- export class BlendImage extends BaseFilter {
41
+ export class BlendImage extends BaseFilter<'BlendImage', BlendImageOwnProps> {
49
42
  /**
50
43
  * Image to make the blend operation with.
51
44
  **/
@@ -60,18 +53,20 @@ export class BlendImage extends BaseFilter {
60
53
  * @type String
61
54
  * @default
62
55
  **/
63
- declare mode: TBlendImageMode;
56
+ declare mode: BlendImageOwnProps['mode'];
64
57
 
65
58
  /**
66
59
  * alpha value. represent the strength of the blend image operation.
67
60
  * not implemented.
68
61
  **/
69
- declare alpha: number;
62
+ declare alpha: BlendImageOwnProps['alpha'];
70
63
 
71
64
  static type = 'BlendImage';
72
65
 
73
66
  static defaults = blendImageDefaultValues;
74
67
 
68
+ static uniformLocations = ['uTransformMatrix', 'uImage'];
69
+
75
70
  getCacheKey() {
76
71
  return `${this.type}_${this.mode}`;
77
72
  }
@@ -80,6 +75,10 @@ export class BlendImage extends BaseFilter {
80
75
  return fragmentSource[this.mode];
81
76
  }
82
77
 
78
+ getVertexSource(): string {
79
+ return vertexSource;
80
+ }
81
+
83
82
  applyToWebGL(options: TWebGLPipelineState) {
84
83
  const gl = options.context,
85
84
  texture = this.createTexture(options.filterBackend, this.image);
@@ -171,22 +170,6 @@ export class BlendImage extends BaseFilter {
171
170
  }
172
171
  }
173
172
 
174
- /**
175
- * Return WebGL uniform locations for this filter's shader.
176
- *
177
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
178
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
179
- */
180
- getUniformLocations(
181
- gl: WebGLRenderingContext,
182
- program: WebGLProgram
183
- ): TWebGLUniformLocationMap {
184
- return {
185
- uTransformMatrix: gl.getUniformLocation(program, 'uTransformMatrix'),
186
- uImage: gl.getUniformLocation(program, 'uImage'),
187
- };
188
- }
189
-
190
173
  /**
191
174
  * Send data from this filter to its shader program's uniforms.
192
175
  *
@@ -204,14 +187,17 @@ export class BlendImage extends BaseFilter {
204
187
 
205
188
  /**
206
189
  * Returns object representation of an instance
190
+ * TODO: Handle the possibility of missing image better.
191
+ * As of now a BlendImage filter without image can't be used with fromObject
207
192
  * @return {Object} Object representation of an instance
208
193
  */
209
- toObject() {
194
+ toObject(): {
195
+ type: 'BlendImage';
196
+ image: ReturnType<FabricImage['toObject']>;
197
+ } & BlendImageOwnProps {
210
198
  return {
211
- type: this.type,
199
+ ...super.toObject(),
212
200
  image: this.image && this.image.toObject(),
213
- mode: this.mode,
214
- alpha: this.alpha,
215
201
  };
216
202
  }
217
203
 
@@ -223,13 +209,13 @@ export class BlendImage extends BaseFilter {
223
209
  * @param {AbortSignal} [options.signal] handle aborting image loading, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
224
210
  * @returns {Promise<BlendImage>}
225
211
  */
226
- static fromObject(
212
+ static async fromObject(
227
213
  { type, image, ...filterOptions }: Record<string, any>,
228
214
  options: { signal: AbortSignal }
229
- ) {
215
+ ): Promise<BaseFilter<'BlendImage', BlendImageOwnProps>> {
230
216
  return FabricImage.fromObject(image, options).then(
231
217
  (enlivedImage) =>
232
- new this({ ...filterOptions, image: enlivedImage }) as BaseFilter
218
+ new this({ ...filterOptions, image: enlivedImage }) as BlendImage
233
219
  );
234
220
  }
235
221
  }
@@ -1,4 +1,3 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { createCanvasElement } from '../util/misc/dom';
3
2
  import { BaseFilter } from './BaseFilter';
4
3
  import type {
@@ -10,9 +9,12 @@ import { isWebGLPipelineState } from './utils';
10
9
  import { classRegistry } from '../ClassRegistry';
11
10
  import { fragmentSource } from './shaders/blur';
12
11
 
13
- export const blurDefaultValues: Partial<TClassProperties<Blur>> = {
12
+ type BlurOwnProps = {
13
+ blur: number;
14
+ };
15
+
16
+ export const blurDefaultValues: BlurOwnProps = {
14
17
  blur: 0,
15
- mainParameter: 'blur',
16
18
  };
17
19
 
18
20
  /**
@@ -25,7 +27,7 @@ export const blurDefaultValues: Partial<TClassProperties<Blur>> = {
25
27
  * object.applyFilters();
26
28
  * canvas.renderAll();
27
29
  */
28
- export class Blur extends BaseFilter {
30
+ export class Blur extends BaseFilter<'Blur', BlurOwnProps> {
29
31
  /**
30
32
  * blur value, in percentage of image dimensions.
31
33
  * specific to keep the image blur constant at different resolutions
@@ -33,7 +35,7 @@ export class Blur extends BaseFilter {
33
35
  * @type Number
34
36
  * @default
35
37
  */
36
- declare blur: number;
38
+ declare blur: BlurOwnProps['blur'];
37
39
 
38
40
  declare horizontal: boolean;
39
41
  declare aspectRatio: number;
@@ -42,6 +44,8 @@ export class Blur extends BaseFilter {
42
44
 
43
45
  static defaults = blurDefaultValues;
44
46
 
47
+ static uniformLocations = ['uDelta'];
48
+
45
49
  getFragmentSource(): string {
46
50
  return fragmentSource;
47
51
  }
@@ -121,21 +125,6 @@ export class Blur extends BaseFilter {
121
125
  return newImageData;
122
126
  }
123
127
 
124
- /**
125
- * Return WebGL uniform locations for this filter's shader.
126
- *
127
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
128
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
129
- */
130
- getUniformLocations(
131
- gl: WebGLRenderingContext,
132
- program: WebGLProgram
133
- ): TWebGLUniformLocationMap {
134
- return {
135
- delta: gl.getUniformLocation(program, 'uDelta'),
136
- };
137
- }
138
-
139
128
  /**
140
129
  * Send data from this filter to its shader program's uniforms.
141
130
  *
@@ -150,6 +139,10 @@ export class Blur extends BaseFilter {
150
139
  gl.uniform2fv(uniformLocations.delta, delta);
151
140
  }
152
141
 
142
+ isNeutralState() {
143
+ return this.blur === 0;
144
+ }
145
+
153
146
  /**
154
147
  * choose right value of image percentage to blur with
155
148
  * @returns {Array} a numeric array with delta values
@@ -1,10 +1,12 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
2
  import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
4
3
 
5
- export const myFilterDefaultValues: Partial<TClassProperties<MyFilter>> = {
4
+ type MyFilterOwnProps = {
5
+ myParameter: number;
6
+ };
7
+
8
+ export const myFilterDefaultValues: MyFilterOwnProps = {
6
9
  myParameter: 0,
7
- mainParameter: 'myParameter',
8
10
  };
9
11
 
10
12
  /**
@@ -16,7 +18,7 @@ export const myFilterDefaultValues: Partial<TClassProperties<MyFilter>> = {
16
18
  * object.filters.push(filter);
17
19
  * object.applyFilters();
18
20
  */
19
- export class MyFilter extends BaseFilter {
21
+ export class MyFilter extends BaseFilter<'MyFilter', MyFilterOwnProps> {
20
22
  /**
21
23
  * MyFilter value, from -1 to 1.
22
24
  * translated to -255 to 255 for 2d
@@ -24,10 +26,14 @@ export class MyFilter extends BaseFilter {
24
26
  * @param {Number} myParameter
25
27
  * @default
26
28
  */
27
- declare myParameter: number;
29
+ declare myParameter: MyFilterOwnProps['myParameter'];
30
+
31
+ static type = 'MyFilter';
28
32
 
29
33
  static defaults = myFilterDefaultValues;
30
34
 
35
+ static uniformLocations = ['uMyParameter'];
36
+
31
37
  getFragmentSource() {
32
38
  return `
33
39
  precision highp float;
@@ -58,21 +64,6 @@ export class MyFilter extends BaseFilter {
58
64
  }
59
65
  }
60
66
 
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
- uMyParameter: gl.getUniformLocation(program, 'uMyParameter'),
73
- };
74
- }
75
-
76
67
  /**
77
68
  * Send data from this filter to its shader program's uniforms.
78
69
  *
@@ -86,9 +77,9 @@ export class MyFilter extends BaseFilter {
86
77
  gl.uniform1f(uniformLocations.uMyParameter, this.myParameter);
87
78
  }
88
79
 
89
- static async fromObject(object: any) {
80
+ static async fromObject(object: any): Promise<MyFilter> {
90
81
  // or overide with custom logic if your filter needs to
91
82
  // deserialize something that is not a plain value
92
- return new this(object) as BaseFilter;
83
+ return new this(object);
93
84
  }
94
85
  }
@@ -1,11 +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/brightness';
6
- export const brightnessDefaultValues: Partial<TClassProperties<Brightness>> = {
5
+
6
+ type BrightnessOwnProps = {
7
+ brightness: number;
8
+ };
9
+
10
+ export const brightnessDefaultValues: BrightnessOwnProps = {
7
11
  brightness: 0,
8
- mainParameter: 'brightness',
9
12
  };
10
13
 
11
14
  /**
@@ -17,7 +20,7 @@ export const brightnessDefaultValues: Partial<TClassProperties<Brightness>> = {
17
20
  * object.filters.push(filter);
18
21
  * object.applyFilters();
19
22
  */
20
- export class Brightness extends BaseFilter {
23
+ export class Brightness extends BaseFilter<'Brightness', BrightnessOwnProps> {
21
24
  /**
22
25
  * Brightness value, from -1 to 1.
23
26
  * translated to -255 to 255 for 2d
@@ -25,12 +28,14 @@ export class Brightness extends BaseFilter {
25
28
  * @param {Number} brightness
26
29
  * @default
27
30
  */
28
- declare brightness: number;
31
+ declare brightness: BrightnessOwnProps['brightness'];
29
32
 
30
33
  static type = 'Brightness';
31
34
 
32
35
  static defaults = brightnessDefaultValues;
33
36
 
37
+ static uniformLocations = ['uBrightness'];
38
+
34
39
  getFragmentSource() {
35
40
  return fragmentSource;
36
41
  }
@@ -42,9 +47,6 @@ export class Brightness extends BaseFilter {
42
47
  * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.
43
48
  */
44
49
  applyTo2d({ imageData: { data } }: T2DPipelineState) {
45
- if (this.brightness === 0) {
46
- return;
47
- }
48
50
  const brightness = Math.round(this.brightness * 255);
49
51
  for (let i = 0; i < data.length; i += 4) {
50
52
  data[i] = data[i] + brightness;
@@ -53,19 +55,8 @@ export class Brightness extends BaseFilter {
53
55
  }
54
56
  }
55
57
 
56
- /**
57
- * Return WebGL uniform locations for this filter's shader.
58
- *
59
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
60
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
61
- */
62
- getUniformLocations(
63
- gl: WebGLRenderingContext,
64
- program: WebGLProgram
65
- ): TWebGLUniformLocationMap {
66
- return {
67
- uBrightness: gl.getUniformLocation(program, 'uBrightness'),
68
- };
58
+ isNeutralState() {
59
+ return this.brightness === 0;
69
60
  }
70
61
 
71
62
  /**
@@ -25,7 +25,7 @@ export class Canvas2dFilterBackend {
25
25
  * @param {HTMLCanvasElement} targetCanvas The destination for filtered output to be drawn.
26
26
  */
27
27
  applyFilters(
28
- filters: BaseFilter[],
28
+ filters: BaseFilter<string, Record<string, any>>[],
29
29
  sourceElement: CanvasImageSource,
30
30
  sourceWidth: number,
31
31
  sourceHeight: number,
@@ -1,14 +1,21 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
- import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
2
+ import type {
3
+ T2DPipelineState,
4
+ TMatColorMatrix,
5
+ TWebGLUniformLocationMap,
6
+ } from './typedefs';
4
7
  import { classRegistry } from '../ClassRegistry';
5
8
  import { fragmentSource } from './shaders/colorMatrix';
6
- export const colorMatrixDefaultValues: Partial<TClassProperties<ColorMatrix>> =
7
- {
8
- matrix: [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
9
- mainParameter: 'matrix',
10
- colorsOnly: true,
11
- };
9
+
10
+ type ColorMatrixOwnProps = {
11
+ matrix: TMatColorMatrix;
12
+ colorsOnly: boolean;
13
+ };
14
+
15
+ export const colorMatrixDefaultValues: ColorMatrixOwnProps = {
16
+ matrix: [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
17
+ colorsOnly: true,
18
+ };
12
19
 
13
20
  /**
14
21
  * Color Matrix filter class
@@ -26,7 +33,10 @@ export const colorMatrixDefaultValues: Partial<TClassProperties<ColorMatrix>> =
26
33
  * object.filters.push(filter);
27
34
  * object.applyFilters();
28
35
  */
29
- export class ColorMatrix extends BaseFilter {
36
+ export class ColorMatrix<
37
+ Name extends string = 'ColorMatrix',
38
+ OwnProps extends object = ColorMatrixOwnProps
39
+ > extends BaseFilter<Name, OwnProps> {
30
40
  /**
31
41
  * Colormatrix for pixels.
32
42
  * array of 20 floats. Numbers in positions 4, 9, 14, 19 loose meaning
@@ -35,7 +45,7 @@ export class ColorMatrix extends BaseFilter {
35
45
  * @param {Array} matrix array of 20 numbers.
36
46
  * @default
37
47
  */
38
- declare matrix: number[];
48
+ declare matrix: ColorMatrixOwnProps['matrix'];
39
49
 
40
50
  /**
41
51
  * Lock the colormatrix on the color part, skipping alpha, mainly for non webgl scenario
@@ -43,19 +53,13 @@ export class ColorMatrix extends BaseFilter {
43
53
  * @type Boolean
44
54
  * @default true
45
55
  */
46
- declare colorsOnly: boolean;
56
+ declare colorsOnly: ColorMatrixOwnProps['colorsOnly'];
47
57
 
48
58
  static type = 'ColorMatrix';
49
59
 
50
60
  static defaults = colorMatrixDefaultValues;
51
61
 
52
- setOptions({ matrix, ...options }: Record<string, any>) {
53
- if (matrix) {
54
- // safeguard against mutation
55
- this.matrix = [...matrix];
56
- }
57
- Object.assign(this, options);
58
- }
62
+ static uniformLocations = ['uColorMatrix', 'uConstants'];
59
63
 
60
64
  getFragmentSource(): string {
61
65
  return fragmentSource;
@@ -93,22 +97,6 @@ export class ColorMatrix extends BaseFilter {
93
97
  }
94
98
  }
95
99
 
96
- /**
97
- * Return WebGL uniform locations for this filter's shader.
98
- *
99
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
100
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
101
- */
102
- getUniformLocations(
103
- gl: WebGLRenderingContext,
104
- program: WebGLProgram
105
- ): TWebGLUniformLocationMap {
106
- return {
107
- uColorMatrix: gl.getUniformLocation(program, 'uColorMatrix'),
108
- uConstants: gl.getUniformLocation(program, 'uConstants'),
109
- };
110
- }
111
-
112
100
  /**
113
101
  * Send data from this filter to its shader program's uniforms.
114
102
  *
@@ -142,6 +130,13 @@ export class ColorMatrix extends BaseFilter {
142
130
  gl.uniformMatrix4fv(uniformLocations.uColorMatrix, false, matrix);
143
131
  gl.uniform4fv(uniformLocations.uConstants, constants);
144
132
  }
133
+
134
+ toObject() {
135
+ return {
136
+ ...super.toObject(),
137
+ matrix: [...this.matrix] as TMatColorMatrix,
138
+ };
139
+ }
145
140
  }
146
141
 
147
142
  classRegistry.setClass(ColorMatrix);
@@ -1,21 +1,27 @@
1
- import { ColorMatrix, colorMatrixDefaultValues } from './ColorMatrix';
1
+ import { ColorMatrix } from './ColorMatrix';
2
2
  import { classRegistry } from '../ClassRegistry';
3
+ import type { TMatColorMatrix } from './typedefs';
3
4
 
4
- export function createColorMatrixFilter(key: string, matrix: number[]) {
5
- const newClass = class extends ColorMatrix {
5
+ type FixedFiltersOwnProps = {
6
+ colorsOnly: boolean;
7
+ };
8
+
9
+ export function createColorMatrixFilter(key: string, matrix: TMatColorMatrix) {
10
+ const newClass = class extends ColorMatrix<typeof key, FixedFiltersOwnProps> {
6
11
  static type = key;
7
12
 
8
13
  static defaults = {
9
- ...colorMatrixDefaultValues,
10
- /**
11
- * Lock the matrix export for this kind of static, parameter less filters.
12
- */
13
- mainParameter: undefined,
14
+ colorsOnly: false,
14
15
  matrix,
15
16
  };
17
+
18
+ //@ts-expect-error TS wants matrix to be exported.
19
+ toObject(): { type: string } & FixedFiltersOwnProps {
20
+ return { type: this.type, colorsOnly: this.colorsOnly };
21
+ }
16
22
  };
17
23
  classRegistry.setClass(newClass, key);
18
- return newClass;
24
+ return newClass as typeof ColorMatrix<typeof key, FixedFiltersOwnProps>;
19
25
  }
20
26
 
21
27
  export const Brownie = createColorMatrixFilter(