@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
@@ -3,23 +3,29 @@ import type { T2DPipelineState, TWebGLPipelineState } from './typedefs';
3
3
  import { isWebGLPipelineState } from './utils';
4
4
  import { classRegistry } from '../ClassRegistry';
5
5
 
6
+ type ComposedOwnProps = {
7
+ subFilters: BaseFilter<string, object>[];
8
+ };
9
+
6
10
  /**
7
11
  * A container class that knows how to apply a sequence of filters to an input image.
8
12
  */
9
- export class Composed extends BaseFilter {
13
+ export class Composed extends BaseFilter<'Composed', ComposedOwnProps> {
10
14
  /**
11
15
  * A non sparse array of filters to apply
12
16
  */
13
- declare subFilters: BaseFilter[];
17
+ declare subFilters: ComposedOwnProps['subFilters'];
14
18
 
15
19
  static type = 'Composed';
16
20
 
17
- constructor({
18
- subFilters = [],
19
- ...options
20
- }: { subFilters?: BaseFilter[] } & Record<string, any> = {}) {
21
+ constructor(
22
+ options: { subFilters?: BaseFilter<string, object>[] } & Record<
23
+ string,
24
+ any
25
+ > = {}
26
+ ) {
21
27
  super(options);
22
- this.subFilters = subFilters;
28
+ this.subFilters = options.subFilters || [];
23
29
  }
24
30
 
25
31
  /**
@@ -39,12 +45,15 @@ export class Composed extends BaseFilter {
39
45
 
40
46
  /**
41
47
  * Serialize this filter into JSON.
42
- *
43
48
  * @returns {Object} A JSON representation of this filter.
44
49
  */
45
- toObject() {
50
+ //@ts-expect-error TS doesn't like this toObject
51
+ toObject(): {
52
+ type: 'Composed';
53
+ subFilters: ReturnType<BaseFilter<string, object>['toObject']>[];
54
+ } {
46
55
  return {
47
- ...super.toObject(),
56
+ type: this.type,
48
57
  subFilters: this.subFilters.map((filter) => filter.toObject()),
49
58
  };
50
59
  }
@@ -64,15 +73,16 @@ export class Composed extends BaseFilter {
64
73
  static fromObject(
65
74
  object: Record<string, any>,
66
75
  options: { signal: AbortSignal }
67
- ) {
76
+ ): Promise<Composed> {
68
77
  return Promise.all(
69
- ((object.subFilters || []) as BaseFilter[]).map((filter) =>
70
- classRegistry
71
- .getClass<typeof BaseFilter>(filter.type)
72
- .fromObject(filter, options)
78
+ ((object.subFilters || []) as BaseFilter<string, object>[]).map(
79
+ (filter) =>
80
+ classRegistry
81
+ .getClass<typeof BaseFilter>(filter.type)
82
+ .fromObject(filter, options)
73
83
  )
74
84
  ).then(
75
- (enlivedFilters) => new this({ subFilters: enlivedFilters }) as BaseFilter
85
+ (enlivedFilters) => new this({ subFilters: enlivedFilters }) as Composed
76
86
  );
77
87
  }
78
88
  }
@@ -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/constrast';
6
- export const contrastDefaultValues: Partial<TClassProperties<Contrast>> = {
5
+
6
+ type ContrastOwnProps = {
7
+ contrast: number;
8
+ };
9
+
10
+ export const contrastDefaultValues: ContrastOwnProps = {
7
11
  contrast: 0,
8
- mainParameter: 'contrast',
9
12
  };
10
13
 
11
14
  /**
@@ -17,21 +20,28 @@ export const contrastDefaultValues: Partial<TClassProperties<Contrast>> = {
17
20
  * object.filters.push(filter);
18
21
  * object.applyFilters();
19
22
  */
20
- export class Contrast extends BaseFilter {
23
+ export class Contrast extends BaseFilter<'Contrast', ContrastOwnProps> {
21
24
  /**
22
25
  * contrast value, range from -1 to 1.
23
26
  * @param {Number} contrast
24
27
  * @default 0
25
28
  */
26
- declare contrast: number;
29
+ declare contrast: ContrastOwnProps['contrast'];
27
30
 
28
31
  static type = 'Contrast';
29
32
 
30
33
  static defaults = contrastDefaultValues;
31
34
 
35
+ static uniformLocations = ['uContrast'];
36
+
32
37
  getFragmentSource() {
33
38
  return fragmentSource;
34
39
  }
40
+
41
+ isNeutralState() {
42
+ return this.contrast === 0;
43
+ }
44
+
35
45
  /**
36
46
  * Apply the Contrast operation to a Uint8Array representing the pixels of an image.
37
47
  *
@@ -39,9 +49,6 @@ export class Contrast extends BaseFilter {
39
49
  * @param {ImageData} options.imageData The Uint8Array to be filtered.
40
50
  */
41
51
  applyTo2d({ imageData: { data } }: T2DPipelineState) {
42
- if (this.contrast === 0) {
43
- return;
44
- }
45
52
  const contrast = Math.floor(this.contrast * 255),
46
53
  contrastF = (259 * (contrast + 255)) / (255 * (259 - contrast));
47
54
 
@@ -52,21 +59,6 @@ export class Contrast extends BaseFilter {
52
59
  }
53
60
  }
54
61
 
55
- /**
56
- * Return WebGL uniform locations for this filter's shader.
57
- *
58
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
59
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
60
- */
61
- getUniformLocations(
62
- gl: WebGLRenderingContext,
63
- program: WebGLProgram
64
- ): TWebGLUniformLocationMap {
65
- return {
66
- uContrast: gl.getUniformLocation(program, 'uContrast'),
67
- };
68
- }
69
-
70
62
  /**
71
63
  * Send data from this filter to its shader program's uniforms.
72
64
  *
@@ -1,10 +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/convolute';
6
5
 
7
- export const convoluteDefaultValues: Partial<TClassProperties<Convolute>> = {
6
+ export type ConvoluteOwnProps = {
7
+ opaque: boolean;
8
+ matrix: number[];
9
+ };
10
+
11
+ export const convoluteDefaultValues: ConvoluteOwnProps = {
8
12
  opaque: false,
9
13
  matrix: [0, 0, 0, 0, 1, 0, 0, 0, 0],
10
14
  };
@@ -49,21 +53,23 @@ export const convoluteDefaultValues: Partial<TClassProperties<Convolute>> = {
49
53
  * object.applyFilters();
50
54
  * canvas.renderAll();
51
55
  */
52
- export class Convolute extends BaseFilter {
56
+ export class Convolute extends BaseFilter<'Convolute', ConvoluteOwnProps> {
53
57
  /*
54
58
  * Opaque value (true/false)
55
59
  */
56
- declare opaque: boolean;
60
+ declare opaque: ConvoluteOwnProps['opaque'];
57
61
 
58
62
  /*
59
63
  * matrix for the filter, max 9x9
60
64
  */
61
- declare matrix: number[];
65
+ declare matrix: ConvoluteOwnProps['matrix'];
62
66
 
63
67
  static type = 'Convolute';
64
68
 
65
69
  static defaults = convoluteDefaultValues;
66
70
 
71
+ static uniformLocations = ['uMatrix', 'uOpaque', 'uHalfSize', 'uSize'];
72
+
67
73
  getCacheKey() {
68
74
  return `${this.type}_${Math.sqrt(this.matrix.length)}_${
69
75
  this.opaque ? 1 : 0
@@ -139,24 +145,6 @@ export class Convolute extends BaseFilter {
139
145
  options.imageData = output;
140
146
  }
141
147
 
142
- /**
143
- * Return WebGL uniform locations for this filter's shader.
144
- *
145
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
146
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
147
- */
148
- getUniformLocations(
149
- gl: WebGLRenderingContext,
150
- program: WebGLProgram
151
- ): TWebGLUniformLocationMap {
152
- return {
153
- uMatrix: gl.getUniformLocation(program, 'uMatrix'),
154
- uOpaque: gl.getUniformLocation(program, 'uOpaque'),
155
- uHalfSize: gl.getUniformLocation(program, 'uHalfSize'),
156
- uSize: gl.getUniformLocation(program, 'uSize'),
157
- };
158
- }
159
-
160
148
  /**
161
149
  * Send data from this filter to its shader program's uniforms.
162
150
  *
@@ -1,12 +1,17 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { BaseFilter } from './BaseFilter';
3
- import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
4
2
  import { classRegistry } from '../ClassRegistry';
5
3
  import { fragmentSource } from './shaders/gamma';
4
+ import type { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
5
+
6
+ const GAMMA = 'Gamma' as const;
7
+
6
8
  export type GammaInput = [number, number, number];
7
9
 
8
- export const gammaDefaultValues: Partial<TClassProperties<Gamma>> = {
9
- mainParameter: 'gamma',
10
+ export type GammaOwnProps = {
11
+ gamma: GammaInput;
12
+ };
13
+
14
+ export const gammaDefaultValues: GammaOwnProps = {
10
15
  gamma: [1, 1, 1],
11
16
  };
12
17
 
@@ -19,30 +24,36 @@ export const gammaDefaultValues: Partial<TClassProperties<Gamma>> = {
19
24
  * object.filters.push(filter);
20
25
  * object.applyFilters();
21
26
  */
22
- export class Gamma extends BaseFilter {
27
+ export class Gamma extends BaseFilter<typeof GAMMA, GammaOwnProps> {
23
28
  /**
24
29
  * Gamma array value, from 0.01 to 2.2.
25
30
  * @param {Array} gamma
26
31
  * @default
27
32
  */
28
- declare gamma: GammaInput;
33
+ declare gamma: GammaOwnProps['gamma'];
29
34
  declare rgbValues?: {
30
35
  r: Uint8Array;
31
36
  g: Uint8Array;
32
37
  b: Uint8Array;
33
38
  };
34
39
 
35
- static type = 'Gamma';
40
+ static type = GAMMA;
36
41
 
37
42
  static defaults = gammaDefaultValues;
38
43
 
44
+ static uniformLocations = ['uGamma'];
45
+
39
46
  getFragmentSource() {
40
47
  return fragmentSource;
41
48
  }
42
49
 
43
- constructor({ gamma = [1, 1, 1], ...options }: { gamma?: GammaInput } = {}) {
50
+ constructor(options: { gamma?: GammaInput } = {}) {
44
51
  super(options);
45
- this.gamma = gamma;
52
+ this.gamma =
53
+ options.gamma ||
54
+ ((
55
+ this.constructor as typeof Gamma
56
+ ).defaults.gamma.concat() as GammaInput);
46
57
  }
47
58
 
48
59
  /**
@@ -80,21 +91,6 @@ export class Gamma extends BaseFilter {
80
91
  }
81
92
  }
82
93
 
83
- /**
84
- * Return WebGL uniform locations for this filter's shader.
85
- *
86
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
87
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
88
- */
89
- getUniformLocations(
90
- gl: WebGLRenderingContext,
91
- program: WebGLProgram
92
- ): TWebGLUniformLocationMap {
93
- return {
94
- uGamma: gl.getUniformLocation(program, 'uGamma'),
95
- };
96
- }
97
-
98
94
  /**
99
95
  * Send data from this filter to its shader program's uniforms.
100
96
  *
@@ -107,6 +103,18 @@ export class Gamma extends BaseFilter {
107
103
  ) {
108
104
  gl.uniform3fv(uniformLocations.uGamma, this.gamma);
109
105
  }
106
+
107
+ isNeutralState() {
108
+ const { gamma } = this;
109
+ return gamma[0] === 1 && gamma[1] === 1 && gamma[2] === 1;
110
+ }
111
+
112
+ toObject(): { type: typeof GAMMA; gamma: GammaInput } {
113
+ return {
114
+ type: GAMMA,
115
+ gamma: this.gamma.concat() as GammaInput,
116
+ };
117
+ }
110
118
  }
111
119
 
112
120
  classRegistry.setClass(Gamma);
@@ -1,4 +1,3 @@
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';
@@ -6,9 +5,12 @@ import { fragmentSource } from './shaders/grayscale';
6
5
 
7
6
  export type TGrayscaleMode = 'average' | 'lightness' | 'luminosity';
8
7
 
9
- export const grayscaleDefaultValues: Partial<TClassProperties<Grayscale>> = {
8
+ type GrayscaleOwnProps = {
9
+ mode: TGrayscaleMode;
10
+ };
11
+
12
+ export const grayscaleDefaultValues: GrayscaleOwnProps = {
10
13
  mode: 'average',
11
- mainParameter: 'mode',
12
14
  };
13
15
 
14
16
  /**
@@ -18,13 +20,15 @@ export const grayscaleDefaultValues: Partial<TClassProperties<Grayscale>> = {
18
20
  * object.filters.push(filter);
19
21
  * object.applyFilters();
20
22
  */
21
- export class Grayscale extends BaseFilter {
23
+ export class Grayscale extends BaseFilter<'Grayscale', GrayscaleOwnProps> {
22
24
  declare mode: TGrayscaleMode;
23
25
 
24
26
  static type = 'Grayscale';
25
27
 
26
28
  static defaults = grayscaleDefaultValues;
27
29
 
30
+ static uniformLocations = ['uMode'];
31
+
28
32
  /**
29
33
  * Apply the Grayscale operation to a Uint8Array representing the pixels of an image.
30
34
  *
@@ -62,21 +66,6 @@ export class Grayscale extends BaseFilter {
62
66
  return fragmentSource[this.mode];
63
67
  }
64
68
 
65
- /**
66
- * Return WebGL uniform locations for this filter's shader.
67
- *
68
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
69
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
70
- */
71
- getUniformLocations(
72
- gl: WebGLRenderingContext,
73
- program: WebGLProgram
74
- ): TWebGLUniformLocationMap {
75
- return {
76
- uMode: gl.getUniformLocation(program, 'uMode'),
77
- };
78
- }
79
-
80
69
  /**
81
70
  * Send data from this filter to its shader program's uniforms.
82
71
  *
@@ -1,15 +1,16 @@
1
- import type { TClassProperties } from '../typedefs';
2
1
  import { cos } from '../util/misc/cos';
3
2
  import { sin } from '../util/misc/sin';
4
3
  import { ColorMatrix } from './ColorMatrix';
5
4
  import type { TWebGLPipelineState, T2DPipelineState } from './typedefs';
6
5
  import { classRegistry } from '../ClassRegistry';
7
6
 
8
- export const hueRotationDefaultValues: Partial<TClassProperties<HueRotation>> =
9
- {
10
- rotation: 0,
11
- mainParameter: 'rotation',
12
- };
7
+ export type HueRotationOwnProps = {
8
+ rotation: number;
9
+ };
10
+
11
+ export const hueRotationDefaultValues: HueRotationOwnProps = {
12
+ rotation: 0,
13
+ };
13
14
 
14
15
  /**
15
16
  * HueRotation filter class
@@ -20,12 +21,14 @@ export const hueRotationDefaultValues: Partial<TClassProperties<HueRotation>> =
20
21
  * object.filters.push(filter);
21
22
  * object.applyFilters();
22
23
  */
23
- // @ts-expect-error some babbling about mainParameter
24
- export class HueRotation extends ColorMatrix {
24
+ export class HueRotation extends ColorMatrix<
25
+ 'HueRotation',
26
+ HueRotationOwnProps
27
+ > {
25
28
  /**
26
29
  * HueRotation value, from -1 to 1.
27
30
  */
28
- declare rotation: number;
31
+ declare rotation: HueRotationOwnProps['rotation'];
29
32
 
30
33
  static type = 'HueRotation';
31
34
 
@@ -51,14 +54,21 @@ export class HueRotation extends ColorMatrix {
51
54
  }
52
55
 
53
56
  isNeutralState() {
54
- this.calculateMatrix();
55
- return super.isNeutralState();
57
+ return this.rotation === 0;
56
58
  }
57
59
 
58
60
  applyTo(options: TWebGLPipelineState | T2DPipelineState) {
59
61
  this.calculateMatrix();
60
62
  super.applyTo(options);
61
63
  }
64
+
65
+ //@ts-expect-error TS and classes with different methods
66
+ toObject(): { type: 'HueRotation'; rotation: number } {
67
+ return {
68
+ type: this.type,
69
+ rotation: this.rotation,
70
+ };
71
+ }
62
72
  }
63
73
 
64
74
  classRegistry.setClass(HueRotation);
@@ -1,13 +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/invert';
6
5
 
7
- export const invertDefaultValues: Partial<TClassProperties<Invert>> = {
6
+ export type InvertOwnProps = {
7
+ alpha: boolean;
8
+ invert: boolean;
9
+ };
10
+
11
+ export const invertDefaultValues: InvertOwnProps = {
8
12
  alpha: false,
9
13
  invert: true,
10
- mainParameter: 'invert',
11
14
  };
12
15
 
13
16
  /**
@@ -16,25 +19,27 @@ export const invertDefaultValues: Partial<TClassProperties<Invert>> = {
16
19
  * object.filters.push(filter);
17
20
  * object.applyFilters(canvas.renderAll.bind(canvas));
18
21
  */
19
- export class Invert extends BaseFilter {
22
+ export class Invert extends BaseFilter<'Invert', InvertOwnProps> {
20
23
  /**
21
24
  * Invert also alpha.
22
25
  * @param {Boolean} alpha
23
26
  * @default
24
27
  **/
25
- declare alpha: boolean;
28
+ declare alpha: InvertOwnProps['alpha'];
26
29
 
27
30
  /**
28
31
  * Filter invert. if false, does nothing
29
32
  * @param {Boolean} invert
30
33
  * @default
31
34
  */
32
- declare invert: boolean;
35
+ declare invert: InvertOwnProps['invert'];
33
36
 
34
37
  static type = 'Invert';
35
38
 
36
39
  static defaults = invertDefaultValues;
37
40
 
41
+ static uniformLocations = ['uInvert', 'uAlpha'];
42
+
38
43
  /**
39
44
  * Apply the Invert operation to a Uint8Array representing the pixels of an image.
40
45
  *
@@ -67,22 +72,6 @@ export class Invert extends BaseFilter {
67
72
  return !this.invert;
68
73
  }
69
74
 
70
- /**
71
- * Return WebGL uniform locations for this filter's shader.
72
- *
73
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
74
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
75
- */
76
- getUniformLocations(
77
- gl: WebGLRenderingContext,
78
- program: WebGLProgram
79
- ): TWebGLUniformLocationMap {
80
- return {
81
- uInvert: gl.getUniformLocation(program, 'uInvert'),
82
- uAlpha: gl.getUniformLocation(program, 'uAlpha'),
83
- };
84
- }
85
-
86
75
  /**
87
76
  * Send data from this filter to its shader program's uniforms.
88
77
  *
@@ -1,11 +1,13 @@
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/noise';
6
5
 
7
- export const noiseDefaultValues: Partial<TClassProperties<Noise>> = {
8
- mainParameter: 'noise',
6
+ export type NoiseOwnProps = {
7
+ noise: number;
8
+ };
9
+
10
+ export const noiseDefaultValues: NoiseOwnProps = {
9
11
  noise: 0,
10
12
  };
11
13
 
@@ -19,18 +21,20 @@ export const noiseDefaultValues: Partial<TClassProperties<Noise>> = {
19
21
  * object.applyFilters();
20
22
  * canvas.renderAll();
21
23
  */
22
- export class Noise extends BaseFilter {
24
+ export class Noise extends BaseFilter<'Noise', NoiseOwnProps> {
23
25
  /**
24
26
  * Noise value, from
25
27
  * @param {Number} noise
26
28
  * @default
27
29
  */
28
- declare noise: number;
30
+ declare noise: NoiseOwnProps['noise'];
29
31
 
30
32
  static type = 'Noise';
31
33
 
32
34
  static defaults = noiseDefaultValues;
33
35
 
36
+ static uniformLocations = ['uNoise', 'uSeed'];
37
+
34
38
  getFragmentSource() {
35
39
  return fragmentSource;
36
40
  }
@@ -42,9 +46,6 @@ export class Noise extends BaseFilter {
42
46
  * @param {ImageData} options.imageData The Uint8ClampedArray to be filtered.
43
47
  */
44
48
  applyTo2d({ imageData: { data } }: T2DPipelineState) {
45
- if (this.noise === 0) {
46
- return;
47
- }
48
49
  const noise = this.noise;
49
50
  for (let i = 0; i < data.length; i += 4) {
50
51
  const rand = (0.5 - Math.random()) * noise;
@@ -54,22 +55,6 @@ export class Noise extends BaseFilter {
54
55
  }
55
56
  }
56
57
 
57
- /**
58
- * Return WebGL uniform locations for this filter's shader.
59
- *
60
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
61
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
62
- */
63
- getUniformLocations(
64
- gl: WebGLRenderingContext,
65
- program: WebGLProgram
66
- ): TWebGLUniformLocationMap {
67
- return {
68
- uNoise: gl.getUniformLocation(program, 'uNoise'),
69
- uSeed: gl.getUniformLocation(program, 'uSeed'),
70
- };
71
- }
72
-
73
58
  /**
74
59
  * Send data from this filter to its shader program's uniforms.
75
60
  *
@@ -84,12 +69,8 @@ export class Noise extends BaseFilter {
84
69
  gl.uniform1f(uniformLocations.uSeed, Math.random());
85
70
  }
86
71
 
87
- /**
88
- * Returns object representation of an instance
89
- * @return {Object} Object representation of an instance
90
- */
91
- toObject() {
92
- return { ...super.toObject(), noise: this.noise };
72
+ isNeutralState() {
73
+ return this.noise === 0;
93
74
  }
94
75
  }
95
76
 
@@ -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/pixelate';
6
5
 
7
- export const pixelateDefaultValues: Partial<TClassProperties<Pixelate>> = {
6
+ export type PixelateOwnProps = {
7
+ blocksize: number;
8
+ };
9
+
10
+ export const pixelateDefaultValues: PixelateOwnProps = {
8
11
  blocksize: 4,
9
- mainParameter: 'blocksize',
10
12
  };
11
13
 
12
14
  /**
@@ -18,13 +20,15 @@ export const pixelateDefaultValues: Partial<TClassProperties<Pixelate>> = {
18
20
  * object.filters.push(filter);
19
21
  * object.applyFilters();
20
22
  */
21
- export class Pixelate extends BaseFilter {
22
- declare blocksize: number;
23
+ export class Pixelate extends BaseFilter<'Pixelate', PixelateOwnProps> {
24
+ declare blocksize: PixelateOwnProps['blocksize'];
23
25
 
24
26
  static type = 'Pixelate';
25
27
 
26
28
  static defaults = pixelateDefaultValues;
27
29
 
30
+ static uniformLocations = ['uBlockSize'];
31
+
28
32
  /**
29
33
  * Apply the Pixelate operation to a Uint8ClampedArray representing the pixels of an image.
30
34
  *
@@ -64,23 +68,6 @@ export class Pixelate extends BaseFilter {
64
68
  return fragmentSource;
65
69
  }
66
70
 
67
- /**
68
- * Return WebGL uniform locations for this filter's shader.
69
- *
70
- * @param {WebGLRenderingContext} gl The GL canvas context used to compile this filter's shader.
71
- * @param {WebGLShaderProgram} program This filter's compiled shader program.
72
- */
73
- getUniformLocations(
74
- gl: WebGLRenderingContext,
75
- program: WebGLProgram
76
- ): TWebGLUniformLocationMap {
77
- return {
78
- uBlocksize: gl.getUniformLocation(program, 'uBlocksize'),
79
- uStepW: gl.getUniformLocation(program, 'uStepW'),
80
- uStepH: gl.getUniformLocation(program, 'uStepH'),
81
- };
82
- }
83
-
84
71
  /**
85
72
  * Send data from this filter to its shader program's uniforms.
86
73
  *