fabric 6.5.3 → 6.6.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 (100) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +9 -6
  4. package/dist/index.js +38 -16
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.map +1 -1
  8. package/dist/index.min.mjs +1 -1
  9. package/dist/index.min.mjs.map +1 -1
  10. package/dist/index.mjs +38 -16
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/index.node.cjs +38 -16
  13. package/dist/index.node.cjs.map +1 -1
  14. package/dist/index.node.mjs +38 -16
  15. package/dist/index.node.mjs.map +1 -1
  16. package/dist/package.json.min.mjs +1 -1
  17. package/dist/package.json.mjs +1 -1
  18. package/dist/src/brushes/PencilBrush.d.ts +3 -3
  19. package/dist/src/brushes/PencilBrush.d.ts.map +1 -1
  20. package/dist/src/brushes/PencilBrush.min.mjs.map +1 -1
  21. package/dist/src/brushes/PencilBrush.mjs.map +1 -1
  22. package/dist/src/canvas/StaticCanvas.d.ts +1 -0
  23. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  24. package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
  25. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  26. package/dist/src/canvas/StaticCanvas.mjs +12 -1
  27. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  28. package/dist/src/shapes/ActiveSelection.d.ts +1 -5
  29. package/dist/src/shapes/ActiveSelection.d.ts.map +1 -1
  30. package/dist/src/shapes/ActiveSelection.min.mjs.map +1 -1
  31. package/dist/src/shapes/ActiveSelection.mjs +1 -5
  32. package/dist/src/shapes/ActiveSelection.mjs.map +1 -1
  33. package/dist/src/shapes/Group.d.ts +2 -2
  34. package/dist/src/shapes/Group.d.ts.map +1 -1
  35. package/dist/src/shapes/Group.min.mjs.map +1 -1
  36. package/dist/src/shapes/Group.mjs +2 -2
  37. package/dist/src/shapes/Group.mjs.map +1 -1
  38. package/dist/src/shapes/Image.d.ts +5 -3
  39. package/dist/src/shapes/Image.d.ts.map +1 -1
  40. package/dist/src/shapes/Image.min.mjs +1 -1
  41. package/dist/src/shapes/Image.min.mjs.map +1 -1
  42. package/dist/src/shapes/Image.mjs +7 -4
  43. package/dist/src/shapes/Image.mjs.map +1 -1
  44. package/dist/src/shapes/Object/Object.d.ts +7 -3
  45. package/dist/src/shapes/Object/Object.d.ts.map +1 -1
  46. package/dist/src/shapes/Object/Object.min.mjs +1 -1
  47. package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
  48. package/dist/src/shapes/Object/Object.mjs +13 -5
  49. package/dist/src/shapes/Object/Object.mjs.map +1 -1
  50. package/dist/src/shapes/Object/ObjectGeometry.d.ts.map +1 -1
  51. package/dist/src/shapes/Object/ObjectGeometry.min.mjs.map +1 -1
  52. package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
  53. package/dist/src/shapes/Object/types/BorderProps.d.ts +1 -1
  54. package/dist/src/typedefs.d.ts +5 -1
  55. package/dist/src/typedefs.d.ts.map +1 -1
  56. package/dist/src/util/index.d.ts +1 -1
  57. package/dist/src/util/index.d.ts.map +1 -1
  58. package/dist/src/util/index.min.mjs +1 -1
  59. package/dist/src/util/index.mjs +1 -1
  60. package/dist/src/util/misc/dom.d.ts +1 -0
  61. package/dist/src/util/misc/dom.d.ts.map +1 -1
  62. package/dist/src/util/misc/dom.min.mjs +1 -1
  63. package/dist/src/util/misc/dom.min.mjs.map +1 -1
  64. package/dist/src/util/misc/dom.mjs +4 -1
  65. package/dist/src/util/misc/dom.mjs.map +1 -1
  66. package/dist-extensions/src/brushes/PencilBrush.d.ts +3 -3
  67. package/dist-extensions/src/brushes/PencilBrush.d.ts.map +1 -1
  68. package/dist-extensions/src/canvas/StaticCanvas.d.ts +1 -0
  69. package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
  70. package/dist-extensions/src/shapes/ActiveSelection.d.ts +1 -5
  71. package/dist-extensions/src/shapes/ActiveSelection.d.ts.map +1 -1
  72. package/dist-extensions/src/shapes/Group.d.ts +2 -2
  73. package/dist-extensions/src/shapes/Group.d.ts.map +1 -1
  74. package/dist-extensions/src/shapes/Image.d.ts +5 -3
  75. package/dist-extensions/src/shapes/Image.d.ts.map +1 -1
  76. package/dist-extensions/src/shapes/Object/Object.d.ts +7 -3
  77. package/dist-extensions/src/shapes/Object/Object.d.ts.map +1 -1
  78. package/dist-extensions/src/shapes/Object/ObjectGeometry.d.ts.map +1 -1
  79. package/dist-extensions/src/shapes/Object/types/BorderProps.d.ts +1 -1
  80. package/dist-extensions/src/typedefs.d.ts +5 -1
  81. package/dist-extensions/src/typedefs.d.ts.map +1 -1
  82. package/dist-extensions/src/util/index.d.ts +1 -1
  83. package/dist-extensions/src/util/index.d.ts.map +1 -1
  84. package/dist-extensions/src/util/misc/dom.d.ts +1 -0
  85. package/dist-extensions/src/util/misc/dom.d.ts.map +1 -1
  86. package/package.json +2 -1
  87. package/src/brushes/PencilBrush.ts +3 -3
  88. package/src/canvas/StaticCanvas.spec.ts +25 -0
  89. package/src/canvas/StaticCanvas.ts +17 -1
  90. package/src/color/color.test.ts +261 -0
  91. package/src/shapes/ActiveSelection.ts +1 -5
  92. package/src/shapes/Group.ts +2 -2
  93. package/src/shapes/Image.ts +6 -4
  94. package/src/shapes/Object/Object.ts +17 -5
  95. package/src/shapes/Object/ObjectGeometry.ts +1 -0
  96. package/src/shapes/Object/types/BorderProps.ts +1 -1
  97. package/src/typedefs.ts +5 -1
  98. package/src/util/index.ts +1 -0
  99. package/src/util/misc/dom.spec.ts +22 -0
  100. package/src/util/misc/dom.ts +9 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [next]
4
4
 
5
+ ## [6.6.0]
6
+
7
+ - feat(): Add webp to ImageFormat [#10435](https://github.com/fabricjs/fabric.js/pull/10435)
8
+ - fix(): Allow for node-canvas images to work with the FabricImage class by making classList optional. [#10412](https://github.com/fabricjs/fabric.js/pull/10412)
9
+ - fix(): Allow for brush subclassing moving some properties from private to protected. [#10416](https://github.com/fabricjs/fabric.js/pull/10416)
10
+ - feat(): Add method toBlob. [#3283](https://github.com/fabricjs/fabric.js/issues/3283)
11
+
12
+ ## [6.5.4]
13
+
14
+ - docs() perf(): Reorder caching conditions for most common scenario and docs fixes. [#10366](https://github.com/fabricjs/fabric.js/pull/10366)
15
+
5
16
  ## [6.5.3]
6
17
 
7
18
  - fix(ColorMatrix): Restore correct alpha for JS colorMatrix filter [#10313](https://github.com/fabricjs/fabric.js/pull/10313)
package/CONTRIBUTING.md CHANGED
@@ -254,7 +254,7 @@ Don't forget to unlink the package once you're done.
254
254
  [website]: http://fabricjs.com/
255
255
  [docs]: http://fabricjs.com/docs
256
256
  [demos]: http://fabricjs.com/demos/
257
- [gotchas]: http://fabricjs.com/fabric-gotchas
257
+ [gotchas]: https://fabricjs.com/docs/old-docs/gotchas/
258
258
  [demo_file]: https://github.com/fabricjs/fabricjs.com/blob/gh-pages/posts/demos/_posts/2020-2-15-custom-control-render.md
259
259
  [jsfiddles]: https://jsfiddle.net/user/fabricjs/fiddles/
260
260
  [codepens]: https://codepen.io/tag/fabricjs
package/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  A **simple and powerful Javascript HTML5 canvas library**.
6
6
 
7
7
  - [**Website**][website]
8
+ - [**Old V5 documentation**](https://fabric5.fabricjs.com)
8
9
  - [**GOTCHAS**][gotchas]
9
10
  - [**Contributing, Developing and More**](CONTRIBUTING.md)
10
11
 
@@ -42,8 +43,8 @@ A **simple and powerful Javascript HTML5 canvas library**.
42
43
  - Out of the box interactions such as scale, move, rotate, skew, group...
43
44
  - Built in shapes, controls, animations, image filters, gradients, patterns, brushes...
44
45
  - `JPG`, `PNG`, `JSON` and `SVG` i/o
45
- - [Typed and modular](#migrating-to-v6)
46
- - [Unit tested](CONTRIBUTING.md#%F0%9F%A7%AA%20testing)
46
+ - Typed and modular
47
+ - [Unit tested](CONTRIBUTING.md#-testing)
47
48
 
48
49
  #### Supported Browsers/Environments
49
50
 
@@ -58,14 +59,16 @@ A **simple and powerful Javascript HTML5 canvas library**.
58
59
  | IE11 | ❌ |
59
60
  | Node.js | ✔️ | [Node.js installation](#nodejs) |
60
61
 
61
- Fabric.js Does not use transpilation by default, the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't.
62
+ Fabric.js does not use polyfills by default, or tries to keep it at minimum. the browser version we support is determined by the level of canvas api we want to use and some js syntax. While JS can be easily transpiled, canvas API can't.
62
63
 
63
64
  ## Installation
64
65
 
65
66
  ```bash
66
67
  $ npm install fabric --save
67
- // or
68
+ # or use yarn
68
69
  $ yarn add fabric
70
+ # or use pnpm
71
+ $ pnpm install fabric
69
72
  ```
70
73
 
71
74
  #### Browser
@@ -114,7 +117,7 @@ import { fabric } from 'fabric';
114
117
 
115
118
  </details>
116
119
 
117
- <details><summary><b>ReactJS</b></summary>
120
+ <details><summary><b>React.js</b></summary>
118
121
 
119
122
  ```tsx
120
123
  import React, { useEffect, useRef } from 'react';
@@ -224,7 +227,7 @@ See our ready to use [templates](./.codesandbox/templates/).
224
227
  [codepens]: https://codepen.io/tag/fabricjs
225
228
  [contributors]: https://github.com/fabricjs/fabric.js/graphs/contributors
226
229
  [demos]: http://fabricjs.com/demos/
227
- [gotchas]: http://fabricjs.com/fabric-gotchas
230
+ [gotchas]: https://fabricjs.com/docs/old-docs/gotchas/
228
231
  [html-to-image]: https://github.com/bubkoo/html-to-image
229
232
  [jsdelivr]: https://www.jsdelivr.com/package/npm/fabric
230
233
  [jsdom]: https://github.com/jsdom/jsdom
package/dist/index.js CHANGED
@@ -411,7 +411,7 @@
411
411
  }
412
412
  const cache = new Cache();
413
413
 
414
- var version = "6.5.3";
414
+ var version = "6.6.0";
415
415
 
416
416
  // use this syntax so babel plugin see this import here
417
417
  const VERSION = version;
@@ -1585,6 +1585,9 @@
1585
1585
  const isHTMLCanvas = canvas => {
1586
1586
  return !!canvas && canvas.getContext !== undefined;
1587
1587
  };
1588
+ const toBlob = (canvasEl, format, quality) => new Promise((resolve, _) => {
1589
+ canvasEl.toBlob(resolve, "image/".concat(format), quality);
1590
+ });
1588
1591
 
1589
1592
  /**
1590
1593
  * Transforms degrees to radians.
@@ -4146,6 +4149,17 @@
4146
4149
  const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
4147
4150
  return toDataURL(this.toCanvasElement(finalMultiplier, options), format, quality);
4148
4151
  }
4152
+ toBlob() {
4153
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4154
+ const {
4155
+ format = 'png',
4156
+ quality = 1,
4157
+ multiplier = 1,
4158
+ enableRetinaScaling = false
4159
+ } = options;
4160
+ const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
4161
+ return toBlob(this.toCanvasElement(finalMultiplier, options), format, quality);
4162
+ }
4149
4163
 
4150
4164
  /**
4151
4165
  * Create a new HTMLCanvas element painted with the current canvas content.
@@ -7129,7 +7143,7 @@
7129
7143
  }
7130
7144
 
7131
7145
  /**
7132
- * When set to `true`, force the object to have its own cache, even if it is inside a group
7146
+ * When returns `true`, force the object to have its own cache, even if it is inside a group
7133
7147
  * it may be needed when your object behave in a particular way on the cache and always needs
7134
7148
  * its own isolated canvas to render correctly.
7135
7149
  * Created to be overridden
@@ -7137,6 +7151,7 @@
7137
7151
  * @returns Boolean
7138
7152
  */
7139
7153
  needsItsOwnCache() {
7154
+ // TODO re-evaluate this shadow condition
7140
7155
  if (this.paintFirst === STROKE && this.hasFill() && this.hasStroke() && !!this.shadow) {
7141
7156
  return true;
7142
7157
  }
@@ -7150,13 +7165,13 @@
7150
7165
  * Decide if the object should cache or not. Create its own cache level
7151
7166
  * objectCaching is a global flag, wins over everything
7152
7167
  * needsItsOwnCache should be used when the object drawing method requires
7153
- * a cache step. None of the fabric classes requires it.
7168
+ * a cache step.
7154
7169
  * Generally you do not cache objects in groups because the group outside is cached.
7155
7170
  * Read as: cache if is needed, or if the feature is enabled but we are not already caching.
7156
7171
  * @return {Boolean}
7157
7172
  */
7158
7173
  shouldCache() {
7159
- this.ownCaching = this.needsItsOwnCache() || this.objectCaching && (!this.parent || !this.parent.isOnACache());
7174
+ this.ownCaching = this.objectCaching && (!this.parent || !this.parent.isOnACache()) || this.needsItsOwnCache();
7160
7175
  return this.ownCaching;
7161
7176
  }
7162
7177
 
@@ -7256,7 +7271,10 @@
7256
7271
  }
7257
7272
 
7258
7273
  /**
7259
- * Check if cache is dirty
7274
+ * Check if cache is dirty and if is dirty clear the context.
7275
+ * This check has a big side effect, it changes the underlying cache canvas if necessary.
7276
+ * Do not call this method on your own to check if the cache is dirty, because if it is,
7277
+ * it is also going to wipe the cache. This is badly designed and needs to be fixed.
7260
7278
  * @param {Boolean} skipCanvas skip canvas checks because this object is painted
7261
7279
  * on parent canvas.
7262
7280
  */
@@ -7689,6 +7707,10 @@
7689
7707
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7690
7708
  return toDataURL(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
7691
7709
  }
7710
+ toBlob() {
7711
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7712
+ return toBlob(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
7713
+ }
7692
7714
 
7693
7715
  /**
7694
7716
  * Returns true if any of the specified types is identical to the type of an instance
@@ -11668,9 +11690,9 @@
11668
11690
  }
11669
11691
 
11670
11692
  /**
11671
- * Decide if the object should cache or not. Create its own cache level
11693
+ * Decide if the group should cache or not. Create its own cache level
11672
11694
  * needsItsOwnCache should be used when the object drawing method requires
11673
- * a cache step. None of the fabric classes requires it.
11695
+ * a cache step.
11674
11696
  * Generally you do not cache objects in groups because the group is already cached.
11675
11697
  * @return {Boolean}
11676
11698
  */
@@ -13042,6 +13064,7 @@
13042
13064
  string: lang_string,
13043
13065
  stylesFromArray: stylesFromArray,
13044
13066
  stylesToArray: stylesToArray,
13067
+ toBlob: toBlob,
13045
13068
  toDataURL: toDataURL,
13046
13069
  toFixed: toFixed,
13047
13070
  transformPath: transformPath,
@@ -23668,11 +23691,7 @@
23668
23691
  }
23669
23692
 
23670
23693
  /**
23671
- * Decide if the object should cache or not. Create its own cache level
23672
- * objectCaching is a global flag, wins over everything
23673
- * needsItsOwnCache should be used when the object drawing method requires
23674
- * a cache step. None of the fabric classes requires it.
23675
- * Generally you do not cache objects in groups because the group outside is cached.
23694
+ * Decide if the object should cache or not. The Active selection never caches
23676
23695
  * @return {Boolean}
23677
23696
  */
23678
23697
  shouldCache() {
@@ -24198,13 +24217,14 @@
24198
24217
  * @param {Partial<TSize>} [size] Options object
24199
24218
  */
24200
24219
  setElement(element) {
24220
+ var _element$classList;
24201
24221
  let size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
24202
24222
  this.removeTexture(this.cacheKey);
24203
24223
  this.removeTexture("".concat(this.cacheKey, "_filtered"));
24204
24224
  this._element = element;
24205
24225
  this._originalElement = element;
24206
24226
  this._setWidthHeight(size);
24207
- element.classList.add(FabricImage.CSS_CANVAS);
24227
+ (_element$classList = element.classList) === null || _element$classList === void 0 || _element$classList.add(FabricImage.CSS_CANVAS);
24208
24228
  if (this.filters.length !== 0) {
24209
24229
  this.applyFilters();
24210
24230
  }
@@ -24523,11 +24543,11 @@
24523
24543
  }
24524
24544
 
24525
24545
  /**
24526
- * Decide if the object should cache or not. Create its own cache level
24546
+ * Decide if the FabricImage should cache or not. Create its own cache level
24527
24547
  * needsItsOwnCache should be used when the object drawing method requires
24528
- * a cache step. None of the fabric classes requires it.
24548
+ * a cache step.
24529
24549
  * Generally you do not cache objects in groups because the group outside is cached.
24530
- * This is the special image version where we would like to avoid caching where possible.
24550
+ * This is the special Image version where we would like to avoid caching where possible.
24531
24551
  * Essentially images do not benefit from caching. They may require caching, and in that
24532
24552
  * case we do it. Also caching an image usually ends in a loss of details.
24533
24553
  * A full performance audit should be done.
@@ -24671,7 +24691,9 @@
24671
24691
 
24672
24692
  /**
24673
24693
  * Default CSS class name for canvas
24694
+ * Will be removed from fabric 7
24674
24695
  * @static
24696
+ * @deprecated
24675
24697
  * @type String
24676
24698
  * @default
24677
24699
  */