@postermywall/fabricjs-2 6.5.3-pmw-39 → 6.6.1-pmw-40

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 (102) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +9 -6
  4. package/dist/index.js +39 -17
  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 +39 -17
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/index.node.cjs +39 -17
  13. package/dist/index.node.cjs.map +1 -1
  14. package/dist/index.node.mjs +39 -17
  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 +8 -5
  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.spec.ts +23 -0
  94. package/src/shapes/Image.ts +7 -4
  95. package/src/shapes/Object/Object.ts +17 -5
  96. package/src/shapes/Object/ObjectGeometry.ts +1 -0
  97. package/src/shapes/Object/types/BorderProps.ts +1 -1
  98. package/src/shapes/__snapshots__/Image.spec.ts.snap +4 -4
  99. package/src/typedefs.ts +5 -1
  100. package/src/util/index.ts +1 -0
  101. package/src/util/misc/dom.spec.ts +22 -0
  102. package/src/util/misc/dom.ts +9 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## [next]
4
4
 
5
+ ## [6.6.1]
6
+
7
+ - fix(): FabricImage was missing cachekey when filtering [#10441](https://github.com/fabricjs/fabric.js/pull/10441)
8
+
9
+ ## [6.6.0]
10
+
11
+ - feat(): Add webp to ImageFormat [#10435](https://github.com/fabricjs/fabric.js/pull/10435)
12
+ - 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)
13
+ - fix(): Allow for brush subclassing moving some properties from private to protected. [#10416](https://github.com/fabricjs/fabric.js/pull/10416)
14
+ - feat(): Add method toBlob. [#3283](https://github.com/fabricjs/fabric.js/issues/3283)
15
+
16
+ ## [6.5.4]
17
+
18
+ - docs() perf(): Reorder caching conditions for most common scenario and docs fixes. [#10366](https://github.com/fabricjs/fabric.js/pull/10366)
19
+
5
20
  ## [6.5.3]
6
21
 
7
22
  - 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
@@ -428,7 +428,7 @@
428
428
  }
429
429
  const cache = new Cache();
430
430
 
431
- var version = "6.5.3-pmw-39";
431
+ var version = "6.6.1-pmw-40";
432
432
 
433
433
  // use this syntax so babel plugin see this import here
434
434
  const VERSION = version;
@@ -1602,6 +1602,9 @@
1602
1602
  const isHTMLCanvas = canvas => {
1603
1603
  return !!canvas && canvas.getContext !== undefined;
1604
1604
  };
1605
+ const toBlob = (canvasEl, format, quality) => new Promise((resolve, _) => {
1606
+ canvasEl.toBlob(resolve, "image/".concat(format), quality);
1607
+ });
1605
1608
 
1606
1609
  /**
1607
1610
  * Transforms degrees to radians.
@@ -4173,6 +4176,17 @@
4173
4176
  const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
4174
4177
  return toDataURL(this.toCanvasElement(finalMultiplier, options), format, quality);
4175
4178
  }
4179
+ toBlob() {
4180
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4181
+ const {
4182
+ format = 'png',
4183
+ quality = 1,
4184
+ multiplier = 1,
4185
+ enableRetinaScaling = false
4186
+ } = options;
4187
+ const finalMultiplier = multiplier * (enableRetinaScaling ? this.getRetinaScaling() : 1);
4188
+ return toBlob(this.toCanvasElement(finalMultiplier, options), format, quality);
4189
+ }
4176
4190
 
4177
4191
  /**
4178
4192
  * Create a new HTMLCanvas element painted with the current canvas content.
@@ -7163,7 +7177,7 @@
7163
7177
  }
7164
7178
 
7165
7179
  /**
7166
- * When set to `true`, force the object to have its own cache, even if it is inside a group
7180
+ * When returns `true`, force the object to have its own cache, even if it is inside a group
7167
7181
  * it may be needed when your object behave in a particular way on the cache and always needs
7168
7182
  * its own isolated canvas to render correctly.
7169
7183
  * Created to be overridden
@@ -7171,6 +7185,7 @@
7171
7185
  * @returns Boolean
7172
7186
  */
7173
7187
  needsItsOwnCache() {
7188
+ // TODO re-evaluate this shadow condition
7174
7189
  if (this.paintFirst === STROKE && this.hasFill() && this.hasStroke() && !!this.shadow) {
7175
7190
  return true;
7176
7191
  }
@@ -7184,13 +7199,13 @@
7184
7199
  * Decide if the object should cache or not. Create its own cache level
7185
7200
  * objectCaching is a global flag, wins over everything
7186
7201
  * needsItsOwnCache should be used when the object drawing method requires
7187
- * a cache step. None of the fabric classes requires it.
7202
+ * a cache step.
7188
7203
  * Generally you do not cache objects in groups because the group outside is cached.
7189
7204
  * Read as: cache if is needed, or if the feature is enabled but we are not already caching.
7190
7205
  * @return {Boolean}
7191
7206
  */
7192
7207
  shouldCache() {
7193
- this.ownCaching = this.needsItsOwnCache() || this.objectCaching && (!this.parent || !this.parent.isOnACache());
7208
+ this.ownCaching = this.objectCaching && (!this.parent || !this.parent.isOnACache()) || this.needsItsOwnCache();
7194
7209
  return this.ownCaching;
7195
7210
  }
7196
7211
 
@@ -7290,7 +7305,10 @@
7290
7305
  }
7291
7306
 
7292
7307
  /**
7293
- * Check if cache is dirty
7308
+ * Check if cache is dirty and if is dirty clear the context.
7309
+ * This check has a big side effect, it changes the underlying cache canvas if necessary.
7310
+ * Do not call this method on your own to check if the cache is dirty, because if it is,
7311
+ * it is also going to wipe the cache. This is badly designed and needs to be fixed.
7294
7312
  * @param {Boolean} skipCanvas skip canvas checks because this object is painted
7295
7313
  * on parent canvas.
7296
7314
  */
@@ -7787,6 +7805,10 @@
7787
7805
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7788
7806
  return toDataURL(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
7789
7807
  }
7808
+ toBlob() {
7809
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7810
+ return toBlob(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
7811
+ }
7790
7812
 
7791
7813
  /**
7792
7814
  * Returns true if any of the specified types is identical to the type of an instance
@@ -11888,9 +11910,9 @@
11888
11910
  }
11889
11911
 
11890
11912
  /**
11891
- * Decide if the object should cache or not. Create its own cache level
11913
+ * Decide if the group should cache or not. Create its own cache level
11892
11914
  * needsItsOwnCache should be used when the object drawing method requires
11893
- * a cache step. None of the fabric classes requires it.
11915
+ * a cache step.
11894
11916
  * Generally you do not cache objects in groups because the group is already cached.
11895
11917
  * @return {Boolean}
11896
11918
  */
@@ -13367,6 +13389,7 @@
13367
13389
  string: lang_string,
13368
13390
  stylesFromArray: stylesFromArray,
13369
13391
  stylesToArray: stylesToArray,
13392
+ toBlob: toBlob,
13370
13393
  toDataURL: toDataURL,
13371
13394
  toFixed: toFixed,
13372
13395
  transformPath: transformPath,
@@ -24563,11 +24586,7 @@
24563
24586
  }
24564
24587
 
24565
24588
  /**
24566
- * Decide if the object should cache or not. Create its own cache level
24567
- * objectCaching is a global flag, wins over everything
24568
- * needsItsOwnCache should be used when the object drawing method requires
24569
- * a cache step. None of the fabric classes requires it.
24570
- * Generally you do not cache objects in groups because the group outside is cached.
24589
+ * Decide if the object should cache or not. The Active selection never caches
24571
24590
  * @return {Boolean}
24572
24591
  */
24573
24592
  shouldCache() {
@@ -25093,13 +25112,14 @@
25093
25112
  * @param {Partial<TSize>} [size] Options object
25094
25113
  */
25095
25114
  setElement(element) {
25115
+ var _element$classList;
25096
25116
  let size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25097
25117
  this.removeTexture(this.cacheKey);
25098
25118
  this.removeTexture("".concat(this.cacheKey, "_filtered"));
25099
25119
  this._element = element;
25100
25120
  this._originalElement = element;
25101
25121
  this._setWidthHeight(size);
25102
- element.classList.add(FabricImage.CSS_CANVAS);
25122
+ (_element$classList = element.classList) === null || _element$classList === void 0 || _element$classList.add(FabricImage.CSS_CANVAS);
25103
25123
  if (this.filters.length !== 0) {
25104
25124
  this.applyFilters();
25105
25125
  }
@@ -25392,7 +25412,7 @@
25392
25412
  this._lastScaleX = 1;
25393
25413
  this._lastScaleY = 1;
25394
25414
  }
25395
- getFilterBackend().applyFilters(filters, this._originalElement, sourceWidth, sourceHeight, this._element);
25415
+ getFilterBackend().applyFilters(filters, this._originalElement, sourceWidth, sourceHeight, this._element, this.cacheKey);
25396
25416
  if (this._originalElement.width !== this._element.width || this._originalElement.height !== this._element.height) {
25397
25417
  this._filterScalingX = this._element.width / this._originalElement.width;
25398
25418
  this._filterScalingY = this._element.height / this._originalElement.height;
@@ -25423,11 +25443,11 @@
25423
25443
  }
25424
25444
 
25425
25445
  /**
25426
- * Decide if the object should cache or not. Create its own cache level
25446
+ * Decide if the FabricImage should cache or not. Create its own cache level
25427
25447
  * needsItsOwnCache should be used when the object drawing method requires
25428
- * a cache step. None of the fabric classes requires it.
25448
+ * a cache step.
25429
25449
  * Generally you do not cache objects in groups because the group outside is cached.
25430
- * This is the special image version where we would like to avoid caching where possible.
25450
+ * This is the special Image version where we would like to avoid caching where possible.
25431
25451
  * Essentially images do not benefit from caching. They may require caching, and in that
25432
25452
  * case we do it. Also caching an image usually ends in a loss of details.
25433
25453
  * A full performance audit should be done.
@@ -25621,7 +25641,9 @@
25621
25641
 
25622
25642
  /**
25623
25643
  * Default CSS class name for canvas
25644
+ * Will be removed from fabric 7
25624
25645
  * @static
25646
+ * @deprecated
25625
25647
  * @type String
25626
25648
  * @default
25627
25649
  */