konva 9.3.15 → 9.3.16

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 (65) hide show
  1. package/konva.js +726 -724
  2. package/konva.min.js +3 -3
  3. package/lib/Animation.js +1 -1
  4. package/lib/BezierFunctions.js +1 -2
  5. package/lib/Canvas.js +9 -9
  6. package/lib/Container.d.ts +1 -1
  7. package/lib/Container.js +29 -29
  8. package/lib/Context.d.ts +2 -2
  9. package/lib/Context.js +26 -26
  10. package/lib/DragAndDrop.d.ts +2 -2
  11. package/lib/DragAndDrop.js +6 -4
  12. package/lib/Factory.js +16 -16
  13. package/lib/Global.js +1 -1
  14. package/lib/Group.js +1 -1
  15. package/lib/Layer.js +17 -17
  16. package/lib/Node.d.ts +1 -1
  17. package/lib/Node.js +87 -87
  18. package/lib/PointerEvents.js +5 -6
  19. package/lib/Shape.js +31 -31
  20. package/lib/Stage.d.ts +2 -2
  21. package/lib/Stage.js +28 -28
  22. package/lib/Tween.js +21 -21
  23. package/lib/Util.d.ts +4 -4
  24. package/lib/Util.js +62 -62
  25. package/lib/Validators.js +16 -17
  26. package/lib/_CoreInternals.d.ts +8 -8
  27. package/lib/_FullInternals.d.ts +8 -8
  28. package/lib/filters/Blur.js +6 -6
  29. package/lib/filters/Brighten.js +1 -1
  30. package/lib/filters/Contrast.js +2 -2
  31. package/lib/filters/Emboss.js +19 -19
  32. package/lib/filters/Enhance.js +4 -4
  33. package/lib/filters/Grayscale.js +1 -1
  34. package/lib/filters/HSL.js +6 -6
  35. package/lib/filters/HSV.js +7 -7
  36. package/lib/filters/Invert.js +1 -1
  37. package/lib/filters/Kaleidoscope.js +20 -20
  38. package/lib/filters/Mask.js +57 -57
  39. package/lib/filters/Noise.js +2 -2
  40. package/lib/filters/Pixelate.js +1 -1
  41. package/lib/filters/Posterize.js +1 -1
  42. package/lib/filters/RGB.js +1 -1
  43. package/lib/filters/RGBA.js +3 -3
  44. package/lib/filters/Sepia.js +1 -1
  45. package/lib/filters/Solarize.js +8 -7
  46. package/lib/filters/Threshold.js +2 -2
  47. package/lib/shapes/Arc.js +1 -1
  48. package/lib/shapes/Arrow.js +10 -10
  49. package/lib/shapes/Ellipse.js +1 -1
  50. package/lib/shapes/Image.js +3 -3
  51. package/lib/shapes/Label.d.ts +1 -1
  52. package/lib/shapes/Label.js +6 -6
  53. package/lib/shapes/Line.d.ts +1 -1
  54. package/lib/shapes/Line.js +14 -14
  55. package/lib/shapes/Path.js +62 -62
  56. package/lib/shapes/Rect.js +1 -1
  57. package/lib/shapes/RegularPolygon.js +6 -6
  58. package/lib/shapes/Ring.js +1 -1
  59. package/lib/shapes/Sprite.js +9 -9
  60. package/lib/shapes/Star.js +5 -5
  61. package/lib/shapes/Text.js +37 -37
  62. package/lib/shapes/TextPath.js +23 -23
  63. package/lib/shapes/Transformer.d.ts +1 -1
  64. package/lib/shapes/Transformer.js +63 -63
  65. package/package.json +2 -5
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Text = exports.stringToArray = void 0;
3
+ exports.Text = void 0;
4
+ exports.stringToArray = stringToArray;
4
5
  const Util_1 = require("../Util");
5
6
  const Factory_1 = require("../Factory");
6
7
  const Shape_1 = require("../Shape");
@@ -24,8 +25,7 @@ function stringToArray(string) {
24
25
  return acc;
25
26
  }, []);
26
27
  }
27
- exports.stringToArray = stringToArray;
28
- var AUTO = 'auto', CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', LTR = 'ltr', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
28
+ const AUTO = 'auto', CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
29
29
  'direction',
30
30
  'fontFamily',
31
31
  'fontSize',
@@ -56,7 +56,7 @@ function normalizeFontFamily(fontFamily) {
56
56
  })
57
57
  .join(', ');
58
58
  }
59
- var dummyContext;
59
+ let dummyContext;
60
60
  function getDummyContext() {
61
61
  if (dummyContext) {
62
62
  return dummyContext;
@@ -85,22 +85,22 @@ class Text extends Shape_1.Shape {
85
85
  super(checkDefaultFill(config));
86
86
  this._partialTextX = 0;
87
87
  this._partialTextY = 0;
88
- for (var n = 0; n < attrChangeListLen; n++) {
88
+ for (let n = 0; n < attrChangeListLen; n++) {
89
89
  this.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, this._setTextData);
90
90
  }
91
91
  this._setTextData();
92
92
  }
93
93
  _sceneFunc(context) {
94
- var textArr = this.textArr, textArrLen = textArr.length;
94
+ const textArr = this.textArr, textArrLen = textArr.length;
95
95
  if (!this.text()) {
96
96
  return;
97
97
  }
98
- var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
98
+ let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
99
99
  direction = direction === INHERIT ? context.direction : direction;
100
- var translateY = lineHeightPx / 2;
101
- var baseline = MIDDLE;
100
+ let translateY = lineHeightPx / 2;
101
+ let baseline = MIDDLE;
102
102
  if (Global_1.Konva._fixTextRendering) {
103
- var metrics = this.measureSize('M');
103
+ const metrics = this.measureSize('M');
104
104
  baseline = 'alphabetic';
105
105
  translateY =
106
106
  (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
@@ -135,7 +135,7 @@ class Text extends Shape_1.Shape {
135
135
  if (shouldUnderline) {
136
136
  context.save();
137
137
  context.beginPath();
138
- let yOffset = Global_1.Konva._fixTextRendering
138
+ const yOffset = Global_1.Konva._fixTextRendering
139
139
  ? Math.round(fontSize / 4)
140
140
  : Math.round(fontSize / 2);
141
141
  const x = lineTranslateX;
@@ -155,7 +155,7 @@ class Text extends Shape_1.Shape {
155
155
  if (shouldLineThrough) {
156
156
  context.save();
157
157
  context.beginPath();
158
- let yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;
158
+ const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;
159
159
  context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
160
160
  spacesNumber = text.split(' ').length - 1;
161
161
  oneWord = spacesNumber === 0;
@@ -172,9 +172,9 @@ class Text extends Shape_1.Shape {
172
172
  }
173
173
  if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
174
174
  spacesNumber = text.split(' ').length - 1;
175
- var array = stringToArray(text);
176
- for (var li = 0; li < array.length; li++) {
177
- var letter = array[li];
175
+ const array = stringToArray(text);
176
+ for (let li = 0; li < array.length; li++) {
177
+ const letter = array[li];
178
178
  if (letter === ' ' && !lastLine && align === JUSTIFY) {
179
179
  lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
180
180
  }
@@ -201,14 +201,14 @@ class Text extends Shape_1.Shape {
201
201
  }
202
202
  }
203
203
  _hitFunc(context) {
204
- var width = this.getWidth(), height = this.getHeight();
204
+ const width = this.getWidth(), height = this.getHeight();
205
205
  context.beginPath();
206
206
  context.rect(0, 0, width, height);
207
207
  context.closePath();
208
208
  context.fillStrokeShape(this);
209
209
  }
210
210
  setText(text) {
211
- var str = Util_1.Util._isString(text)
211
+ const str = Util_1.Util._isString(text)
212
212
  ? text
213
213
  : text === null || text === undefined
214
214
  ? ''
@@ -217,11 +217,11 @@ class Text extends Shape_1.Shape {
217
217
  return this;
218
218
  }
219
219
  getWidth() {
220
- var isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
220
+ const isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
221
221
  return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
222
222
  }
223
223
  getHeight() {
224
- var isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
224
+ const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
225
225
  return isAuto
226
226
  ? this.fontSize() * this.textArr.length * this.lineHeight() +
227
227
  this.padding() * 2
@@ -236,7 +236,7 @@ class Text extends Shape_1.Shape {
236
236
  }
237
237
  measureSize(text) {
238
238
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
239
- var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
239
+ let _context = getDummyContext(), fontSize = this.fontSize(), metrics;
240
240
  _context.save();
241
241
  _context.font = this._getContextFont();
242
242
  metrics = _context.measureText(text);
@@ -271,7 +271,7 @@ class Text extends Shape_1.Shape {
271
271
  if (align === JUSTIFY) {
272
272
  line = line.trim();
273
273
  }
274
- var width = this._getTextWidth(line);
274
+ const width = this._getTextWidth(line);
275
275
  return this.textArr.push({
276
276
  text: line,
277
277
  width: width,
@@ -279,24 +279,24 @@ class Text extends Shape_1.Shape {
279
279
  });
280
280
  }
281
281
  _getTextWidth(text) {
282
- var letterSpacing = this.letterSpacing();
283
- var length = text.length;
282
+ const letterSpacing = this.letterSpacing();
283
+ const length = text.length;
284
284
  return (getDummyContext().measureText(text).width +
285
285
  (length ? letterSpacing * (length - 1) : 0));
286
286
  }
287
287
  _setTextData() {
288
- var lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
288
+ let lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
289
289
  this.textArr = [];
290
290
  getDummyContext().font = this._getContextFont();
291
- var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
292
- for (var i = 0, max = lines.length; i < max; ++i) {
293
- var line = lines[i];
294
- var lineWidth = this._getTextWidth(line);
291
+ const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
292
+ for (let i = 0, max = lines.length; i < max; ++i) {
293
+ let line = lines[i];
294
+ let lineWidth = this._getTextWidth(line);
295
295
  if (fixedWidth && lineWidth > maxWidth) {
296
296
  while (line.length > 0) {
297
- var low = 0, high = line.length, match = '', matchWidth = 0;
297
+ let low = 0, high = line.length, match = '', matchWidth = 0;
298
298
  while (low < high) {
299
- var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
299
+ const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
300
300
  if (substrWidth <= maxWidth) {
301
301
  low = mid + 1;
302
302
  match = substr;
@@ -309,8 +309,8 @@ class Text extends Shape_1.Shape {
309
309
  if (match) {
310
310
  if (wrapAtWord) {
311
311
  var wrapIndex;
312
- var nextChar = line[match.length];
313
- var nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
312
+ const nextChar = line[match.length];
313
+ const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
314
314
  if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
315
315
  wrapIndex = match.length;
316
316
  }
@@ -329,7 +329,7 @@ class Text extends Shape_1.Shape {
329
329
  this._addTextLine(match);
330
330
  textWidth = Math.max(textWidth, matchWidth);
331
331
  currentHeightPx += lineHeightPx;
332
- var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
332
+ const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
333
333
  if (shouldHandleEllipsis) {
334
334
  this._tryToAddEllipsisToLastLine();
335
335
  break;
@@ -370,18 +370,18 @@ class Text extends Shape_1.Shape {
370
370
  this.textWidth = textWidth;
371
371
  }
372
372
  _shouldHandleEllipsis(currentHeightPx) {
373
- var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
373
+ const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
374
374
  return (!shouldWrap ||
375
375
  (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
376
376
  }
377
377
  _tryToAddEllipsisToLastLine() {
378
- var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
379
- var lastLine = this.textArr[this.textArr.length - 1];
378
+ const width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
379
+ const lastLine = this.textArr[this.textArr.length - 1];
380
380
  if (!lastLine || !shouldAddEllipsis) {
381
381
  return;
382
382
  }
383
383
  if (fixedWidth) {
384
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
384
+ const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
385
385
  if (!haveSpace) {
386
386
  lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
387
387
  }
@@ -8,7 +8,7 @@ const Path_1 = require("./Path");
8
8
  const Text_1 = require("./Text");
9
9
  const Validators_1 = require("../Validators");
10
10
  const Global_1 = require("../Global");
11
- var EMPTY_STRING = '', NORMAL = 'normal';
11
+ const EMPTY_STRING = '', NORMAL = 'normal';
12
12
  function _fillFunc(context) {
13
13
  context.fillText(this.partialText, 0, 0);
14
14
  }
@@ -50,16 +50,16 @@ class TextPath extends Shape_1.Shape {
50
50
  context.setAttr('textBaseline', this.textBaseline());
51
51
  context.setAttr('textAlign', 'left');
52
52
  context.save();
53
- var textDecoration = this.textDecoration();
54
- var fill = this.fill();
55
- var fontSize = this.fontSize();
56
- var glyphInfo = this.glyphInfo;
53
+ const textDecoration = this.textDecoration();
54
+ const fill = this.fill();
55
+ const fontSize = this.fontSize();
56
+ const glyphInfo = this.glyphInfo;
57
57
  if (textDecoration === 'underline') {
58
58
  context.beginPath();
59
59
  }
60
- for (var i = 0; i < glyphInfo.length; i++) {
60
+ for (let i = 0; i < glyphInfo.length; i++) {
61
61
  context.save();
62
- var p0 = glyphInfo[i].p0;
62
+ const p0 = glyphInfo[i].p0;
63
63
  context.translate(p0.x, p0.y);
64
64
  context.rotate(glyphInfo[i].rotation);
65
65
  this.partialText = glyphInfo[i].text;
@@ -81,13 +81,13 @@ class TextPath extends Shape_1.Shape {
81
81
  }
82
82
  _hitFunc(context) {
83
83
  context.beginPath();
84
- var glyphInfo = this.glyphInfo;
84
+ const glyphInfo = this.glyphInfo;
85
85
  if (glyphInfo.length >= 1) {
86
- var p0 = glyphInfo[0].p0;
86
+ const p0 = glyphInfo[0].p0;
87
87
  context.moveTo(p0.x, p0.y);
88
88
  }
89
- for (var i = 0; i < glyphInfo.length; i++) {
90
- var p1 = glyphInfo[i].p1;
89
+ for (let i = 0; i < glyphInfo.length; i++) {
90
+ const p1 = glyphInfo[i].p1;
91
91
  context.lineTo(p1.x, p1.y);
92
92
  }
93
93
  context.setAttr('lineWidth', this.fontSize());
@@ -108,11 +108,11 @@ class TextPath extends Shape_1.Shape {
108
108
  return Text_1.Text.prototype._getContextFont.call(this);
109
109
  }
110
110
  _getTextSize(text) {
111
- var dummyCanvas = this.dummyCanvas;
112
- var _context = dummyCanvas.getContext('2d');
111
+ const dummyCanvas = this.dummyCanvas;
112
+ const _context = dummyCanvas.getContext('2d');
113
113
  _context.save();
114
114
  _context.font = this._getContextFont();
115
- var metrics = _context.measureText(text);
115
+ const metrics = _context.measureText(text);
116
116
  _context.restore();
117
117
  return {
118
118
  width: metrics.width,
@@ -140,7 +140,7 @@ class TextPath extends Shape_1.Shape {
140
140
  }
141
141
  const charArr = (0, Text_1.stringToArray)(this.text());
142
142
  let offsetToGlyph = offset;
143
- for (var i = 0; i < charArr.length; i++) {
143
+ for (let i = 0; i < charArr.length; i++) {
144
144
  const charStartPoint = this._getPointAtLength(offsetToGlyph);
145
145
  if (!charStartPoint)
146
146
  return;
@@ -187,19 +187,19 @@ class TextPath extends Shape_1.Shape {
187
187
  height: 0,
188
188
  };
189
189
  }
190
- var points = [];
190
+ const points = [];
191
191
  this.glyphInfo.forEach(function (info) {
192
192
  points.push(info.p0.x);
193
193
  points.push(info.p0.y);
194
194
  points.push(info.p1.x);
195
195
  points.push(info.p1.y);
196
196
  });
197
- var minX = points[0] || 0;
198
- var maxX = points[0] || 0;
199
- var minY = points[1] || 0;
200
- var maxY = points[1] || 0;
201
- var x, y;
202
- for (var i = 0; i < points.length / 2; i++) {
197
+ let minX = points[0] || 0;
198
+ let maxX = points[0] || 0;
199
+ let minY = points[1] || 0;
200
+ let maxY = points[1] || 0;
201
+ let x, y;
202
+ for (let i = 0; i < points.length / 2; i++) {
203
203
  x = points[i * 2];
204
204
  y = points[i * 2 + 1];
205
205
  minX = Math.min(minX, x);
@@ -207,7 +207,7 @@ class TextPath extends Shape_1.Shape {
207
207
  minY = Math.min(minY, y);
208
208
  maxY = Math.max(maxY, y);
209
209
  }
210
- var fontSize = this.fontSize();
210
+ const fontSize = this.fontSize();
211
211
  return {
212
212
  x: minX - fontSize / 2,
213
213
  y: minY - fontSize / 2,
@@ -94,7 +94,7 @@ export declare class Transformer extends Group {
94
94
  toObject(): {
95
95
  attrs: any;
96
96
  className: string;
97
- children?: any[] | undefined;
97
+ children?: Array<any>;
98
98
  };
99
99
  clone(obj?: any): this;
100
100
  getClientRect(): IRect;