fabric 6.7.0 → 6.8.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 (112) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.js +98 -74
  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 +98 -74
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +98 -74
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +98 -74
  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 +6 -1
  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 -7
  26. package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
  27. package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
  28. package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
  29. package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
  30. package/dist/src/canvas/StaticCanvas.mjs +10 -5
  31. package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
  32. package/dist/src/color/Color.d.ts.map +1 -1
  33. package/dist/src/color/Color.min.mjs +1 -1
  34. package/dist/src/color/Color.min.mjs.map +1 -1
  35. package/dist/src/color/Color.mjs +3 -2
  36. package/dist/src/color/Color.mjs.map +1 -1
  37. package/dist/src/color/constants.d.ts +26 -20
  38. package/dist/src/color/constants.d.ts.map +1 -1
  39. package/dist/src/color/constants.min.mjs +1 -1
  40. package/dist/src/color/constants.min.mjs.map +1 -1
  41. package/dist/src/color/constants.mjs +28 -22
  42. package/dist/src/color/constants.mjs.map +1 -1
  43. package/dist/src/gradient/parser/parseCoords.d.ts.map +1 -1
  44. package/dist/src/gradient/parser/parseCoords.min.mjs +1 -1
  45. package/dist/src/gradient/parser/parseCoords.min.mjs.map +1 -1
  46. package/dist/src/gradient/parser/parseCoords.mjs +5 -4
  47. package/dist/src/gradient/parser/parseCoords.mjs.map +1 -1
  48. package/dist/src/parser/getCSSRules.d.ts.map +1 -1
  49. package/dist/src/parser/getCSSRules.min.mjs +1 -1
  50. package/dist/src/parser/getCSSRules.min.mjs.map +1 -1
  51. package/dist/src/parser/getCSSRules.mjs +3 -5
  52. package/dist/src/parser/getCSSRules.mjs.map +1 -1
  53. package/dist/src/parser/percent.d.ts +7 -2
  54. package/dist/src/parser/percent.d.ts.map +1 -1
  55. package/dist/src/parser/percent.min.mjs +1 -1
  56. package/dist/src/parser/percent.min.mjs.map +1 -1
  57. package/dist/src/parser/percent.mjs +9 -4
  58. package/dist/src/parser/percent.mjs.map +1 -1
  59. package/dist/src/shapes/IText/ITextKeyBehavior.d.ts.map +1 -1
  60. package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs +1 -1
  61. package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs.map +1 -1
  62. package/dist/src/shapes/IText/ITextKeyBehavior.mjs +2 -1
  63. package/dist/src/shapes/IText/ITextKeyBehavior.mjs.map +1 -1
  64. package/dist/src/shapes/Text/Text.d.ts +8 -0
  65. package/dist/src/shapes/Text/Text.d.ts.map +1 -1
  66. package/dist/src/shapes/Text/Text.min.mjs +1 -1
  67. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  68. package/dist/src/shapes/Text/Text.mjs +29 -21
  69. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  70. package/dist/src/util/internals/cleanupSvgAttribute.d.ts.map +1 -1
  71. package/dist/src/util/internals/cleanupSvgAttribute.min.mjs +1 -1
  72. package/dist/src/util/internals/cleanupSvgAttribute.min.mjs.map +1 -1
  73. package/dist/src/util/internals/cleanupSvgAttribute.mjs +3 -2
  74. package/dist/src/util/internals/cleanupSvgAttribute.mjs.map +1 -1
  75. package/dist/src/util/internals/normalizeWhiteSpace.d.ts +2 -0
  76. package/dist/src/util/internals/normalizeWhiteSpace.d.ts.map +1 -0
  77. package/dist/src/util/internals/normalizeWhiteSpace.min.mjs +2 -0
  78. package/dist/src/util/internals/normalizeWhiteSpace.min.mjs.map +1 -0
  79. package/dist/src/util/internals/normalizeWhiteSpace.mjs +4 -0
  80. package/dist/src/util/internals/normalizeWhiteSpace.mjs.map +1 -0
  81. package/dist-extensions/src/canvas/Canvas.d.ts.map +1 -1
  82. package/dist-extensions/src/canvas/SelectableCanvas.d.ts +1 -1
  83. package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
  84. package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
  85. package/dist-extensions/src/color/Color.d.ts.map +1 -1
  86. package/dist-extensions/src/color/constants.d.ts +26 -20
  87. package/dist-extensions/src/color/constants.d.ts.map +1 -1
  88. package/dist-extensions/src/gradient/parser/parseCoords.d.ts.map +1 -1
  89. package/dist-extensions/src/parser/getCSSRules.d.ts.map +1 -1
  90. package/dist-extensions/src/parser/percent.d.ts +7 -2
  91. package/dist-extensions/src/parser/percent.d.ts.map +1 -1
  92. package/dist-extensions/src/shapes/IText/ITextKeyBehavior.d.ts.map +1 -1
  93. package/dist-extensions/src/shapes/Text/Text.d.ts +8 -0
  94. package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
  95. package/dist-extensions/src/util/internals/cleanupSvgAttribute.d.ts.map +1 -1
  96. package/dist-extensions/src/util/internals/normalizeWhiteSpace.d.ts +2 -0
  97. package/dist-extensions/src/util/internals/normalizeWhiteSpace.d.ts.map +1 -0
  98. package/package.json +1 -1
  99. package/src/canvas/Canvas-events.spec.ts +1667 -0
  100. package/src/canvas/Canvas.ts +7 -1
  101. package/src/canvas/SelectableCanvas.ts +2 -2
  102. package/src/canvas/StaticCanvas.ts +4 -9
  103. package/src/color/Color.ts +3 -2
  104. package/src/color/constants.ts +28 -22
  105. package/src/gradient/parser/parseCoords.ts +5 -6
  106. package/src/parser/getCSSRules.spec.ts +19 -0
  107. package/src/parser/getCSSRules.ts +3 -5
  108. package/src/parser/percent.ts +10 -6
  109. package/src/shapes/IText/ITextKeyBehavior.ts +1 -0
  110. package/src/shapes/Text/Text.ts +32 -36
  111. package/src/util/internals/cleanupSvgAttribute.ts +7 -5
  112. package/src/util/internals/normalizeWhiteSpace.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [next]
4
+
5
+ ## [6.8.0]
6
+
7
+ - fix(): CWE-1333 CWE-400 CWE-730 Simplify some regexes in order to avoid slowness with craft bad string #10746
8
+ - fix(): CWE-1333 CWE-400 CWE-730 in Text.ts regex #10745
9
+ - fix(StaticCanvas): After executing loadFromJSON, it unexpectedly adds an objects property to the canvas. #10741
10
+ - fix(textarea): A form field element has neither an id nor a name attribute. #10172
11
+ - fix(Canvas): The mouse enter and leave events of child elements will be executed twice. #10699
12
+ - chore(): Remove mouse wheel console warning by setting default explicitly. #10712
13
+ - fix(): fix rendering of text when line height is set to 0 #10785
14
+
15
+ ## [6.7.1]
16
+
17
+ - fix(SVGParser): Corrected CSS rule parsing for multiple style tags. [#10688](https://github.com/fabricjs/fabric.js/issues/10683)
18
+
3
19
  ## [6.7.0]
4
20
 
5
21
  - feat(Text): Add support for text decoration tickness [#10643](https://github.com/fabricjs/fabric.js/pull/10643)
package/dist/index.js CHANGED
@@ -411,7 +411,7 @@
411
411
  }
412
412
  const cache = new Cache();
413
413
 
414
- var version = "6.7.0";
414
+ var version = "6.8.0";
415
415
 
416
416
  // use this syntax so babel plugin see this import here
417
417
  const VERSION = version;
@@ -2255,6 +2255,8 @@
2255
2255
  viewportTransform: [...iMatrix]
2256
2256
  };
2257
2257
 
2258
+ const _excluded$j = ["objects"];
2259
+
2258
2260
  /**
2259
2261
  * Having both options in TCanvasSizeOptions set to true transform the call in a calcOffset
2260
2262
  * Better try to restrict with types to avoid confusion.
@@ -3272,9 +3274,12 @@
3272
3274
  }
3273
3275
 
3274
3276
  // parse json if it wasn't already
3275
- const serialized = typeof json === 'string' ? JSON.parse(json) : json;
3277
+ const _ref2 = typeof json === 'string' ? JSON.parse(json) : json,
3278
+ {
3279
+ objects = []
3280
+ } = _ref2,
3281
+ serialized = _objectWithoutProperties(_ref2, _excluded$j);
3276
3282
  const {
3277
- objects = [],
3278
3283
  backgroundImage,
3279
3284
  background,
3280
3285
  overlayImage,
@@ -3294,8 +3299,8 @@
3294
3299
  clipPath
3295
3300
  }, {
3296
3301
  signal
3297
- })]).then(_ref2 => {
3298
- let [enlived, enlivedMap] = _ref2;
3302
+ })]).then(_ref3 => {
3303
+ let [enlived, enlivedMap] = _ref3;
3299
3304
  this.clear();
3300
3305
  this.add(...enlived);
3301
3306
  this.set(serialized);
@@ -3893,6 +3898,8 @@
3893
3898
  return moveX || moveY;
3894
3899
  };
3895
3900
 
3901
+ const normalizeWs = value => value.replace(/\s+/g, ' ');
3902
+
3896
3903
  /**
3897
3904
  * Map of the 148 color names with HEX code
3898
3905
  * @see: https://www.w3.org/TR/css3-color/#svg-color
@@ -4052,6 +4059,10 @@
4052
4059
  * Regex matching color in RGB or RGBA formats (ex: `rgb(0, 0, 0)`, `rgba(255, 100, 10, 0.5)`, `rgba( 255 , 100 , 10 , 0.5 )`, `rgb(1,1,1)`, `rgba(100%, 60%, 10%, 0.5)`)
4053
4060
  * Also matching rgba(r g b / a) as per new specs
4054
4061
  * https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
4062
+ *
4063
+ * In order to avoid performance issues, you have to clean the input string for this regex from multiple spaces before.
4064
+ * ex: colorString.replace(/\s+/g, ' ');
4065
+ *
4055
4066
  * Formal syntax at the time of writing:
4056
4067
  * <rgb()> =
4057
4068
  * rgb( [ <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? ) |
@@ -4063,35 +4074,35 @@
4063
4074
  *
4064
4075
  * /^ # Beginning of the string
4065
4076
  * rgba? # "rgb" or "rgba"
4066
- * \(\s* # Opening parenthesis and optional whitespace
4077
+ * \(\s? # Opening parenthesis and zero or one whitespace character
4067
4078
  * (\d{0,3} # 0 to three digits R channel
4068
4079
  * (?:\.\d+)? # Optional decimal with one or more digits
4069
4080
  * ) # End of capturing group for the first color component
4070
4081
  * %? # Optional percent sign after the first color component
4071
- * \s* # Optional whitespace
4082
+ * \s? # Zero or one whitespace character
4072
4083
  * [\s|,] # Separator between color components can be a space or comma
4073
- * \s* # Optional whitespace
4084
+ * \s? # Zero or one whitespace character
4074
4085
  * (\d{0,3} # 0 to three digits G channel
4075
4086
  * (?:\.\d+)? # Optional decimal with one or more digits
4076
4087
  * ) # End of capturing group for the second color component
4077
4088
  * %? # Optional percent sign after the second color component
4078
- * \s* # Optional whitespace
4089
+ * \s? # Zero or one whitespace character
4079
4090
  * [\s|,] # Separator between color components can be a space or comma
4080
- * \s* # Optional whitespace
4091
+ * \s? # Zero or one whitespace character
4081
4092
  * (\d{0,3} # 0 to three digits B channel
4082
4093
  * (?:\.\d+)? # Optional decimal with one or more digits
4083
4094
  * ) # End of capturing group for the third color component
4084
4095
  * %? # Optional percent sign after the third color component
4085
- * \s* # Optional whitespace
4096
+ * \s? # Zero or one whitespace character
4086
4097
  * (?: # Beginning of non-capturing group for alpha value
4087
- * \s* # Optional whitespace
4098
+ * \s? # Zero or one whitespace character
4088
4099
  * [,/] # Comma or slash separator for alpha value
4089
- * \s* # Optional whitespace
4100
+ * \s? # Zero or one whitespace character
4090
4101
  * (\d{0,3} # Zero to three digits
4091
4102
  * (?:\.\d+)? # Optional decimal with one or more digits
4092
4103
  * ) # End of capturing group for alpha value
4093
4104
  * %? # Optional percent sign after alpha value
4094
- * \s* # Optional whitespace
4105
+ * \s? # Zero or one whitespace character
4095
4106
  * )? # End of non-capturing group for alpha value (optional)
4096
4107
  * \) # Closing parenthesis
4097
4108
  * $ # End of the string
@@ -4101,12 +4112,14 @@
4101
4112
  * WARNING this regex doesn't fail on off spec colors. it matches everything that could be a color.
4102
4113
  * So the spec does not allow for `rgba(30 , 45% 35, 49%)` but this will work anyways for us
4103
4114
  */
4104
- const reRGBa = () => /^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i;
4115
+ const reRGBa = () => /^rgba?\(\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d{0,3}(?:\.\d+)?%?)\s?)?\)$/i;
4105
4116
 
4106
4117
  /**
4107
- * Regex matching color in HSL or HSLA formats (ex: hsl(0, 0, 0), rgba(255, 100, 10, 0.5), rgba( 255 , 100 , 10 , 0.5 ), rgb(1,1,1), rgba(100%, 60%, 10%, 0.5))
4108
- * Also matching rgba(r g b / a) as per new specs
4118
+ * Regex matching color in HSL or HSLA formats (ex: hsl(0deg 0%, 0%), hsla(160, 100, 10, 0.5), hsla( 180 , 100 , 10 , 0.5 ), hsl(1,1,1))
4119
+ * Also matching hsla(h s l / a) as per new specs
4109
4120
  * https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl
4121
+ * In order to avoid performance issues, you have to clean the input string for this regex from multiple spaces before.
4122
+ * ex: colorString.replace(/\s+/g, ' ');
4110
4123
  * Formal syntax at the time of writing:
4111
4124
  * <hsl()> =
4112
4125
  * hsl( [ <hue> | none ] [ <percentage> | none ] [ <percentage> | none ] [ / [ <alpha-value> | none ] ]? )
@@ -4123,30 +4136,30 @@
4123
4136
  * Regular expression for matching an hsla or hsl CSS color value
4124
4137
  *
4125
4138
  * /^hsla?\( // Matches the beginning of the string and the opening parenthesis of "hsl" or "hsla"
4126
- * \s* // Matches any whitespace characters (space, tab, etc.) zero or more times
4139
+ * \s? // Matches any whitespace character (space, tab, etc.) zero or one time
4127
4140
  * (\d{0,3} // Hue: 0 to three digits - start capture in a group
4128
4141
  * (?:\.\d+)? // Hue: Optional (non capture group) decimal with one or more digits.
4129
4142
  * (?:deg|turn|rad)? // Hue: Optionally include suffix deg or turn or rad
4130
4143
  * ) // Hue: End capture group
4131
- * \s* // Matches any whitespace characters zero or more times
4144
+ * \s? // Matches any whitespace character zero or one time
4132
4145
  * [\s|,] // Matches a space, tab or comma
4133
- * \s* // Matches any whitespace characters zero or more times
4146
+ * \s? // Matches any whitespace character zero or one time
4134
4147
  * (\d{0,3} // Saturation: 0 to three digits - start capture in a group
4135
4148
  * (?:\.\d+)? // Saturation: Optional decimal with one or more digits in a non-capturing group
4136
4149
  * %?) // Saturation: match optional % character and end capture group
4137
- * \s* // Matches any whitespace characters zero or more times
4150
+ * \s? // Matches any whitespace character zero or one time
4138
4151
  * [\s|,] // Matches a space, tab or comma
4139
- * \s* // Matches any whitespace characters zero or more times
4152
+ * \s? // Matches any whitespace character zero or one time
4140
4153
  * (\d{0,3} // Lightness: 0 to three digits - start capture in a group
4141
4154
  * (?:\.\d+)? // Lightness: Optional decimal with one or more digits in a non-capturing group
4142
4155
  * %?) // Lightness: match % character and end capture group
4143
- * \s* // Matches any whitespace characters zero or more times
4156
+ * \s? // Matches any whitespace character zero or one time
4144
4157
  * (?: // Alpha: Begins a non-capturing group for the alpha value
4145
- * \s* // Matches any whitespace characters zero or more times
4158
+ * \s? // Matches any whitespace character zero or one time
4146
4159
  * [,/] // Matches a comma or forward slash
4147
- * \s* // Matches any whitespace characters zero or more times
4160
+ * \s? // Matches any whitespace character zero or one time
4148
4161
  * (\d*(?:\.\d+)?%?) // Matches zero or more digits, optionally followed by a decimal point and one or more digits, followed by an optional percentage sign and captures it in a group
4149
- * \s* // Matches any whitespace characters zero or more times
4162
+ * \s? // Matches any whitespace character zero or one time
4150
4163
  * )? // Makes the alpha value group optional
4151
4164
  * \) // Matches the closing parenthesis
4152
4165
  * $/i // Matches the end of the string and sets the regular expression to case-insensitive mode
@@ -4154,7 +4167,7 @@
4154
4167
  * WARNING this regex doesn't fail on off spec colors. It matches everything that could be a color.
4155
4168
  * So the spec does not allow `hsl(30 , 45% 35, 49%)` but this will work anyways for us.
4156
4169
  */
4157
- const reHSLa = () => /^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i;
4170
+ const reHSLa = () => /^hsla?\(\s?([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?[\s|,]\s?(\d{0,3}(?:\.\d+)?%?)\s?(?:\s?[,/]\s?(\d*(?:\.\d+)?%?)\s?)?\)$/i;
4158
4171
 
4159
4172
  /**
4160
4173
  * Regex matching color in HEX format (ex: #FF5544CC, #FF5555, 010155, aff)
@@ -4436,7 +4449,7 @@
4436
4449
  * @return {TRGBAColorSource | undefined} source
4437
4450
  */
4438
4451
  static sourceFromRgb(color) {
4439
- const match = color.match(reRGBa());
4452
+ const match = normalizeWs(color).match(reRGBa());
4440
4453
  if (match) {
4441
4454
  const [r, g, b] = match.slice(1, 4).map(value => {
4442
4455
  const parsedValue = parseFloat(value);
@@ -4477,7 +4490,7 @@
4477
4490
  * @see http://http://www.w3.org/TR/css3-color/#hsl-color
4478
4491
  */
4479
4492
  static sourceFromHsl(color) {
4480
- const match = color.match(reHSLa());
4493
+ const match = normalizeWs(color).match(reHSLa());
4481
4494
  if (!match) {
4482
4495
  return;
4483
4496
  }
@@ -10600,9 +10613,9 @@
10600
10613
  };
10601
10614
 
10602
10615
  const regex$1 = new RegExp("(".concat(reNum, ")"), 'gi');
10603
- const cleanupSvgAttribute = attributeValue => attributeValue.replace(regex$1, ' $1 ')
10616
+ const cleanupSvgAttribute = attributeValue => normalizeWs(attributeValue.replace(regex$1, ' $1 ')
10604
10617
  // replace annoying commas and arbitrary whitespace with single spaces
10605
- .replace(/,/gi, ' ').replace(/\s+/gi, ' ');
10618
+ .replace(/,/gi, ' '));
10606
10619
 
10607
10620
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
10608
10621
 
@@ -13429,17 +13442,11 @@
13429
13442
  */
13430
13443
  _defineProperty(this, "targets", []);
13431
13444
  /**
13432
- * hold the list of nested targets hovered
13445
+ * hold the list of nested targets hovered in the previous events
13433
13446
  * @type FabricObject[]
13434
13447
  * @private
13435
13448
  */
13436
13449
  _defineProperty(this, "_hoveredTargets", []);
13437
- /**
13438
- * hold the list of objects to render
13439
- * @type FabricObject[]
13440
- * @private
13441
- */
13442
- _defineProperty(this, "_objectsToRender", void 0);
13443
13450
  /**
13444
13451
  * hold a reference to a data structure that contains information
13445
13452
  * on the current on going transform
@@ -14591,7 +14598,9 @@
14591
14598
  functor(canvasElement, "".concat(eventTypePrefix, "move"), this._onMouseMove, addEventOptions);
14592
14599
  functor(canvasElement, "".concat(eventTypePrefix, "out"), this._onMouseOut);
14593
14600
  functor(canvasElement, "".concat(eventTypePrefix, "enter"), this._onMouseEnter);
14594
- functor(canvasElement, 'wheel', this._onMouseWheel);
14601
+ functor(canvasElement, 'wheel', this._onMouseWheel, {
14602
+ passive: false
14603
+ });
14595
14604
  functor(canvasElement, 'contextmenu', this._onContextMenu);
14596
14605
  functor(canvasElement, 'click', this._onClick);
14597
14606
  // decide if to remove in fabric 7.0
@@ -15464,6 +15473,9 @@
15464
15473
  fireCanvas: true
15465
15474
  });
15466
15475
  for (let i = 0; i < length; i++) {
15476
+ if (targets[i] === target || _hoveredTargets[i] && _hoveredTargets[i] === _hoveredTarget) {
15477
+ continue;
15478
+ }
15467
15479
  this.fireSyntheticInOutEvents('mouse', {
15468
15480
  e,
15469
15481
  target: targets[i],
@@ -15811,15 +15823,20 @@
15811
15823
  return isNaN(value) && typeof valueIfNaN === 'number' ? valueIfNaN : value;
15812
15824
  };
15813
15825
 
15814
- const RE_PERCENT = /^(\d+\.\d+)%|(\d+)%$/;
15826
+ /**
15827
+ * Will loosely accept as percent numbers that are not like
15828
+ * 3.4a%. This function does not check for the correctness of a percentage
15829
+ * but it checks that values that are in theory correct are or arent percentages
15830
+ */
15815
15831
  function isPercent(value) {
15816
- return value && RE_PERCENT.test(value);
15832
+ // /%$/ Matches strings that end with a percent sign (%)
15833
+ return value && /%$/.test(value) && Number.isFinite(parseFloat(value));
15817
15834
  }
15818
15835
 
15819
15836
  /**
15820
- *
15837
+ * Parse a percentage value in an svg.
15821
15838
  * @param value
15822
- * @param valueIfNaN
15839
+ * @param fallback in case of not possible to parse the number
15823
15840
  * @returns ∈ [0, 1]
15824
15841
  */
15825
15842
  function parsePercent(value, valueIfNaN) {
@@ -15877,15 +15894,16 @@
15877
15894
  gradientUnits
15878
15895
  } = _ref;
15879
15896
  let finalValue;
15880
- return Object.keys(valuesToConvert).reduce((acc, prop) => {
15881
- const propValue = valuesToConvert[prop];
15897
+ return Object.entries(valuesToConvert).reduce((acc, _ref2) => {
15898
+ let [prop, propValue] = _ref2;
15882
15899
  if (propValue === 'Infinity') {
15883
15900
  finalValue = 1;
15884
15901
  } else if (propValue === '-Infinity') {
15885
15902
  finalValue = 0;
15886
15903
  } else {
15887
- finalValue = typeof propValue === 'string' ? parseFloat(propValue) : propValue;
15888
- if (typeof propValue === 'string' && isPercent(propValue)) {
15904
+ const isString = typeof propValue === 'string';
15905
+ finalValue = isString ? parseFloat(propValue) : propValue;
15906
+ if (isString && isPercent(propValue)) {
15889
15907
  finalValue *= 0.01;
15890
15908
  if (gradientUnits === 'pixels') {
15891
15909
  // then we need to fix those percentages here in svg parsing
@@ -19302,6 +19320,7 @@
19302
19320
  let drawStart;
19303
19321
  let currentColor;
19304
19322
  let lastColor = this.getValueOfPropertyAt(i, 0, 'textBackgroundColor');
19323
+ const bgHeight = this.getHeightOfLineImpl(i);
19305
19324
  for (let j = 0; j < jlen; j++) {
19306
19325
  // at this point charbox are either standard or full with pathInfo if there is a path.
19307
19326
  const charBox = this.__charBounds[i][j];
@@ -19311,7 +19330,7 @@
19311
19330
  ctx.translate(charBox.renderLeft, charBox.renderTop);
19312
19331
  ctx.rotate(charBox.angle);
19313
19332
  ctx.fillStyle = currentColor;
19314
- currentColor && ctx.fillRect(-charBox.width / 2, -heightOfLine / this.lineHeight * (1 - this._fontSizeFraction), charBox.width, heightOfLine / this.lineHeight);
19333
+ currentColor && ctx.fillRect(-charBox.width / 2, -bgHeight * (1 - this._fontSizeFraction), charBox.width, bgHeight);
19315
19334
  ctx.restore();
19316
19335
  } else if (currentColor !== lastColor) {
19317
19336
  drawStart = leftOffset + lineLeftOffset + boxStart;
@@ -19319,7 +19338,7 @@
19319
19338
  drawStart = this.width - drawStart - boxWidth;
19320
19339
  }
19321
19340
  ctx.fillStyle = lastColor;
19322
- lastColor && ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
19341
+ lastColor && ctx.fillRect(drawStart, lineTopOffset, boxWidth, bgHeight);
19323
19342
  boxStart = charBox.left;
19324
19343
  boxWidth = charBox.width;
19325
19344
  lastColor = currentColor;
@@ -19333,7 +19352,7 @@
19333
19352
  drawStart = this.width - drawStart - boxWidth;
19334
19353
  }
19335
19354
  ctx.fillStyle = currentColor;
19336
- ctx.fillRect(drawStart, lineTopOffset, boxWidth, heightOfLine / this.lineHeight);
19355
+ ctx.fillRect(drawStart, lineTopOffset, boxWidth, bgHeight);
19337
19356
  }
19338
19357
  lineTopOffset += heightOfLine;
19339
19358
  }
@@ -19542,13 +19561,16 @@
19542
19561
  }
19543
19562
 
19544
19563
  /**
19545
- * Calculate height of line at 'lineIndex'
19564
+ * Calculate height of line at 'lineIndex',
19565
+ * without the lineHeigth multiplication factor
19566
+ * @private
19546
19567
  * @param {Number} lineIndex index of line to calculate
19547
19568
  * @return {Number}
19548
19569
  */
19549
- getHeightOfLine(lineIndex) {
19550
- if (this.__lineHeights[lineIndex]) {
19551
- return this.__lineHeights[lineIndex];
19570
+ getHeightOfLineImpl(lineIndex) {
19571
+ const lh = this.__lineHeights;
19572
+ if (lh[lineIndex]) {
19573
+ return lh[lineIndex];
19552
19574
  }
19553
19575
 
19554
19576
  // char 0 is measured before the line cycle because it needs to char
@@ -19557,18 +19579,25 @@
19557
19579
  for (let i = 1, len = this._textLines[lineIndex].length; i < len; i++) {
19558
19580
  maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
19559
19581
  }
19560
- return this.__lineHeights[lineIndex] = maxHeight * this.lineHeight * this._fontSizeMult;
19582
+ return lh[lineIndex] = maxHeight * this._fontSizeMult;
19583
+ }
19584
+
19585
+ /**
19586
+ * Calculate height of line at 'lineIndex'
19587
+ * @param {Number} lineIndex index of line to calculate
19588
+ * @return {Number}
19589
+ */
19590
+ getHeightOfLine(lineIndex) {
19591
+ return this.getHeightOfLineImpl(lineIndex) * this.lineHeight;
19561
19592
  }
19562
19593
 
19563
19594
  /**
19564
19595
  * Calculate text box height
19565
19596
  */
19566
19597
  calcTextHeight() {
19567
- let lineHeight,
19568
- height = 0;
19598
+ let height = 0;
19569
19599
  for (let i = 0, len = this._textLines.length; i < len; i++) {
19570
- lineHeight = this.getHeightOfLine(i);
19571
- height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
19600
+ height += i === len - 1 ? this.getHeightOfLineImpl(i) : this.getHeightOfLine(i);
19572
19601
  }
19573
19602
  return height;
19574
19603
  }
@@ -19600,11 +19629,8 @@
19600
19629
  const left = this._getLeftOffset(),
19601
19630
  top = this._getTopOffset();
19602
19631
  for (let i = 0, len = this._textLines.length; i < len; i++) {
19603
- const heightOfLine = this.getHeightOfLine(i),
19604
- maxHeight = heightOfLine / this.lineHeight,
19605
- leftOffset = this._getLineLeftOffset(i);
19606
- this._renderTextLine(method, ctx, this._textLines[i], left + leftOffset, top + lineHeights + maxHeight, i);
19607
- lineHeights += heightOfLine;
19632
+ this._renderTextLine(method, ctx, this._textLines[i], left + this._getLineLeftOffset(i), top + lineHeights + this.getHeightOfLineImpl(i), i);
19633
+ lineHeights += this.getHeightOfLine(i);
19608
19634
  }
19609
19635
  ctx.restore();
19610
19636
  }
@@ -19649,8 +19675,7 @@
19649
19675
  * @param {Number} lineIndex
19650
19676
  */
19651
19677
  _renderChars(method, ctx, line, left, top, lineIndex) {
19652
- const lineHeight = this.getHeightOfLine(lineIndex),
19653
- isJustify = this.textAlign.includes(JUSTIFY),
19678
+ const isJustify = this.textAlign.includes(JUSTIFY),
19654
19679
  path = this.path,
19655
19680
  shortCut = !isJustify && this.charSpacing === 0 && this.isEmptyStyles(lineIndex) && !path,
19656
19681
  isLtr = this.direction === 'ltr',
@@ -19671,7 +19696,7 @@
19671
19696
  ctx.direction = isLtr ? 'ltr' : 'rtl';
19672
19697
  ctx.textAlign = isLtr ? LEFT : RIGHT;
19673
19698
  }
19674
- top -= lineHeight * this._fontSizeFraction / this.lineHeight;
19699
+ top -= this.getHeightOfLineImpl(lineIndex) * this._fontSizeFraction;
19675
19700
  if (shortCut) {
19676
19701
  // render all the line in one pass without checking
19677
19702
  // drawingLeft = isLtr ? left : left - this.getLineWidth(lineIndex);
@@ -20210,7 +20235,7 @@
20210
20235
  strokeWidth = 1
20211
20236
  } = _options$parsedAttrib,
20212
20237
  restOfOptions = _objectWithoutProperties(_options$parsedAttrib, _excluded$3);
20213
- const textContent = (element.textContent || '').replace(/^\s+|\s+$|\n+/g, '').replace(/\s+/g, ' ');
20238
+ const textContent = normalizeWs(element.textContent || '').trim();
20214
20239
 
20215
20240
  // this code here is probably the usual issue for SVG center find
20216
20241
  // this can later looked at again and probably removed.
@@ -21581,7 +21606,8 @@
21581
21606
  autocomplete: 'off',
21582
21607
  spellcheck: 'false',
21583
21608
  'data-fabric': 'textarea',
21584
- wrap: 'off'
21609
+ wrap: 'off',
21610
+ name: 'fabricTextarea'
21585
21611
  }).map(_ref => {
21586
21612
  let [attribute, value] = _ref;
21587
21613
  return textarea.setAttribute(attribute, value);
@@ -25211,12 +25237,10 @@
25211
25237
  */
25212
25238
  function getCSSRules(doc) {
25213
25239
  const styles = doc.getElementsByTagName('style');
25214
- let i;
25215
- let len;
25216
25240
  const allRules = {};
25217
25241
 
25218
25242
  // very crude parsing of style contents
25219
- for (i = 0, len = styles.length; i < len; i++) {
25243
+ for (let i = 0; i < styles.length; i++) {
25220
25244
  const styleContents = (styles[i].textContent || '').replace(
25221
25245
  // remove comments
25222
25246
  /\/\*[\s\S]*?\*\//g, '');
@@ -25242,8 +25266,8 @@
25242
25266
  propertyValuePairs = declaration.split(';').filter(function (pair) {
25243
25267
  return pair.trim();
25244
25268
  });
25245
- for (i = 0, len = propertyValuePairs.length; i < len; i++) {
25246
- const pair = propertyValuePairs[i].split(':'),
25269
+ for (let j = 0; j < propertyValuePairs.length; j++) {
25270
+ const pair = propertyValuePairs[j].split(':'),
25247
25271
  property = pair[0].trim(),
25248
25272
  value = pair[1].trim();
25249
25273
  ruleObj[property] = value;