konva 10.5.0 → 10.7.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 (79) hide show
  1. package/README.md +16 -12
  2. package/konva.js +3623 -3819
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +2 -2
  6. package/lib/BezierFunctions.d.ts +1 -1
  7. package/lib/BezierFunctions.js +76 -116
  8. package/lib/Canvas.d.ts +10 -3
  9. package/lib/Canvas.js +91 -10
  10. package/lib/Container.d.ts +3 -2
  11. package/lib/Container.js +31 -17
  12. package/lib/Context.d.ts +9 -7
  13. package/lib/Context.js +99 -73
  14. package/lib/DragAndDrop.d.ts +4 -3
  15. package/lib/DragAndDrop.js +39 -25
  16. package/lib/Factory.d.ts +3 -2
  17. package/lib/Factory.js +10 -9
  18. package/lib/Global.d.ts +2 -7
  19. package/lib/Global.js +8 -9
  20. package/lib/Group.d.ts +7 -1
  21. package/lib/Group.js +61 -0
  22. package/lib/Layer.d.ts +1 -1
  23. package/lib/Layer.js +13 -8
  24. package/lib/Node.d.ts +25 -19
  25. package/lib/Node.js +178 -169
  26. package/lib/PointerEvents.d.ts +1 -2
  27. package/lib/PointerEvents.js +20 -18
  28. package/lib/Shape.d.ts +9 -15
  29. package/lib/Shape.js +190 -86
  30. package/lib/Stage.d.ts +19 -15
  31. package/lib/Stage.js +184 -99
  32. package/lib/Tween.js +59 -66
  33. package/lib/Util.d.ts +3 -2
  34. package/lib/Util.js +46 -16
  35. package/lib/_CoreInternals.d.ts +23 -11
  36. package/lib/_FullInternals.d.ts +23 -11
  37. package/lib/filters/Blur.js +16 -12
  38. package/lib/filters/Brighten.d.ts +1 -0
  39. package/lib/filters/Brighten.js +1 -0
  40. package/lib/filters/Brightness.d.ts +2 -1
  41. package/lib/filters/Brightness.js +4 -4
  42. package/lib/filters/Emboss.js +16 -58
  43. package/lib/filters/Kaleidoscope.js +8 -15
  44. package/lib/filters/Mask.js +8 -8
  45. package/lib/filters/Pixelate.js +16 -29
  46. package/lib/filters/Threshold.d.ts +1 -1
  47. package/lib/filters/Threshold.js +1 -1
  48. package/lib/shapes/Arc.js +8 -6
  49. package/lib/shapes/Arrow.d.ts +3 -6
  50. package/lib/shapes/Arrow.js +75 -47
  51. package/lib/shapes/Circle.d.ts +1 -0
  52. package/lib/shapes/Circle.js +4 -1
  53. package/lib/shapes/Ellipse.d.ts +1 -0
  54. package/lib/shapes/Ellipse.js +4 -1
  55. package/lib/shapes/Image.d.ts +2 -1
  56. package/lib/shapes/Image.js +22 -22
  57. package/lib/shapes/Label.d.ts +2 -3
  58. package/lib/shapes/Label.js +25 -41
  59. package/lib/shapes/Line.d.ts +2 -1
  60. package/lib/shapes/Line.js +5 -2
  61. package/lib/shapes/Path.d.ts +11 -2
  62. package/lib/shapes/Path.js +133 -143
  63. package/lib/shapes/Rect.d.ts +1 -0
  64. package/lib/shapes/Rect.js +4 -1
  65. package/lib/shapes/RegularPolygon.js +2 -2
  66. package/lib/shapes/Ring.d.ts +7 -0
  67. package/lib/shapes/Ring.js +8 -1
  68. package/lib/shapes/Sprite.d.ts +2 -1
  69. package/lib/shapes/Sprite.js +8 -9
  70. package/lib/shapes/Star.d.ts +6 -0
  71. package/lib/shapes/Star.js +5 -1
  72. package/lib/shapes/Text.d.ts +16 -5
  73. package/lib/shapes/Text.js +134 -65
  74. package/lib/shapes/TextPath.d.ts +11 -3
  75. package/lib/shapes/TextPath.js +56 -27
  76. package/lib/shapes/Transformer.js +95 -96
  77. package/lib/shapes/Wedge.js +1 -1
  78. package/lib/types.d.ts +2 -2
  79. package/package.json +5 -20
package/lib/Tween.js CHANGED
@@ -21,6 +21,25 @@ function colorToRGBA(color) {
21
21
  color +
22
22
  '", because it is not a valid color.'));
23
23
  }
24
+ function colorDiff(start, end) {
25
+ return {
26
+ r: end.r - start.r,
27
+ g: end.g - start.g,
28
+ b: end.b - start.b,
29
+ a: end.a - start.a,
30
+ };
31
+ }
32
+ function tweenColor(start, diff, i) {
33
+ return ('rgba(' +
34
+ Math.round(start.r + diff.r * i) +
35
+ ',' +
36
+ Math.round(start.g + diff.g * i) +
37
+ ',' +
38
+ Math.round(start.b + diff.b * i) +
39
+ ',' +
40
+ (start.a + diff.a * i) +
41
+ ')');
42
+ }
24
43
  class TweenEngine {
25
44
  constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
26
45
  this.prop = prop;
@@ -86,15 +105,15 @@ class TweenEngine {
86
105
  play() {
87
106
  this.state = PLAYING;
88
107
  this._startTime = this.getTimer() - this._time;
89
- this.onEnterFrame();
90
108
  this.fire('onPlay');
109
+ this.onEnterFrame();
91
110
  }
92
111
  reverse() {
93
112
  this.state = REVERSING;
94
113
  this._time = this.duration - this._time;
95
114
  this._startTime = this.getTimer() - this._time;
96
- this.onEnterFrame();
97
115
  this.fire('onReverse');
116
+ this.onEnterFrame();
98
117
  }
99
118
  seek(t) {
100
119
  this.pause();
@@ -222,7 +241,7 @@ export class Tween {
222
241
  return;
223
242
  }
224
243
  const node = this.node, nodeId = node._id;
225
- let diff, len, trueEnd, trueStart, endRGBA;
244
+ let diff, len, trueEnd, trueStart;
226
245
  // remove conflict from tween map if it exists
227
246
  const tweenId = Tween.tweens[nodeId][key];
228
247
  if (tweenId !== undefined) {
@@ -230,59 +249,55 @@ export class Tween {
230
249
  }
231
250
  // add to tween map
232
251
  let start = node.getAttr(key);
233
- if (Util._isArray(end)) {
252
+ if (Util._isArray(end) || Util._isArray(start)) {
234
253
  diff = [];
235
- // an attribute the node does not have yet starts from zeros. A copy,
236
- // as the colour stops are replaced by RGBA objects below
237
- start = (start || []).slice();
254
+ // only normalized arrays are interpolated, so the values the user asked
255
+ // for are restored when the tween ends
256
+ trueStart = start;
257
+ trueEnd = end;
258
+ // an attribute the node does not have yet starts from zeros, a scalar
259
+ // side tweens every entry. A copy of start, as the colour stops are
260
+ // replaced by RGBA objects below
261
+ start = Util._isArray(start)
262
+ ? start.slice()
263
+ : new Array(end.length).fill(start || 0);
264
+ if (!Util._isArray(end)) {
265
+ end = new Array(start.length).fill(end);
266
+ }
238
267
  len = Math.max(end.length, start.length);
239
268
  if (key === 'points' && end.length !== start.length) {
240
269
  // before tweening points we need to make sure that start.length === end.length
241
270
  // Util._prepareArrayForTween thinking that end.length > start.length
242
271
  if (end.length > start.length) {
243
272
  // so in this case we will increase number of starting points
244
- trueStart = start;
245
273
  start = Util._prepareArrayForTween(start, end, node.closed());
246
274
  }
247
275
  else {
248
276
  // in this case we will increase number of eding points
249
- trueEnd = end;
250
277
  end = Util._prepareArrayForTween(end, start, node.closed());
251
278
  }
252
279
  }
253
- if (key.indexOf('fill') === 0) {
280
+ if (key.endsWith('ColorStops')) {
254
281
  for (let n = 0; n < len; n++) {
255
282
  if (n % 2 === 0) {
256
- diff.push(end[n] - (start[n] || 0));
283
+ diff.push((end[n] || 0) - (start[n] || 0));
257
284
  }
258
285
  else {
259
286
  const startRGBA = colorToRGBA(start[n]);
260
- endRGBA = colorToRGBA(end[n]);
261
287
  start[n] = startRGBA;
262
- diff.push({
263
- r: endRGBA.r - startRGBA.r,
264
- g: endRGBA.g - startRGBA.g,
265
- b: endRGBA.b - startRGBA.b,
266
- a: endRGBA.a - startRGBA.a,
267
- });
288
+ diff.push(colorDiff(startRGBA, colorToRGBA(end[n])));
268
289
  }
269
290
  }
270
291
  }
271
292
  else {
272
293
  for (let n = 0; n < len; n++) {
273
- diff.push(end[n] - (start[n] || 0));
294
+ diff.push((end[n] || 0) - (start[n] || 0));
274
295
  }
275
296
  }
276
297
  }
277
298
  else if (colorAttrs.indexOf(key) !== -1) {
278
299
  start = colorToRGBA(start);
279
- endRGBA = colorToRGBA(end);
280
- diff = {
281
- r: endRGBA.r - start.r,
282
- g: endRGBA.g - start.g,
283
- b: endRGBA.b - start.b,
284
- a: endRGBA.a - start.a,
285
- };
300
+ diff = colorDiff(start, colorToRGBA(end));
286
301
  }
287
302
  else {
288
303
  diff = end - start;
@@ -297,7 +312,8 @@ export class Tween {
297
312
  Tween.tweens[nodeId][key] = this._id;
298
313
  }
299
314
  _tweenFunc(i) {
300
- const node = this.node, attrs = Tween.attrs[node._id][this._id];
315
+ var _a;
316
+ const node = this.node, attrs = (_a = Tween.attrs[node._id]) === null || _a === void 0 ? void 0 : _a[this._id];
301
317
  let key, attr, start, diff, newVal, n, len, end;
302
318
  for (key in attrs) {
303
319
  attr = attrs[key];
@@ -307,21 +323,13 @@ export class Tween {
307
323
  if (Util._isArray(start)) {
308
324
  newVal = [];
309
325
  len = Math.max(start.length, end.length);
310
- if (key.indexOf('fill') === 0) {
326
+ if (key.endsWith('ColorStops')) {
311
327
  for (n = 0; n < len; n++) {
312
328
  if (n % 2 === 0) {
313
329
  newVal.push((start[n] || 0) + diff[n] * i);
314
330
  }
315
331
  else {
316
- newVal.push('rgba(' +
317
- Math.round(start[n].r + diff[n].r * i) +
318
- ',' +
319
- Math.round(start[n].g + diff[n].g * i) +
320
- ',' +
321
- Math.round(start[n].b + diff[n].b * i) +
322
- ',' +
323
- (start[n].a + diff[n].a * i) +
324
- ')');
332
+ newVal.push(tweenColor(start[n], diff[n], i));
325
333
  }
326
334
  }
327
335
  }
@@ -332,16 +340,7 @@ export class Tween {
332
340
  }
333
341
  }
334
342
  else if (colorAttrs.indexOf(key) !== -1) {
335
- newVal =
336
- 'rgba(' +
337
- Math.round(start.r + diff.r * i) +
338
- ',' +
339
- Math.round(start.g + diff.g * i) +
340
- ',' +
341
- Math.round(start.b + diff.b * i) +
342
- ',' +
343
- (start.a + diff.a * i) +
344
- ')';
343
+ newVal = tweenColor(start, diff, i);
345
344
  }
346
345
  else {
347
346
  newVal = start + diff * i;
@@ -366,28 +365,22 @@ export class Tween {
366
365
  this.node.off(destroyEvent);
367
366
  this.anim.stop();
368
367
  };
369
- this.tween.onFinish = () => {
370
- const node = this.node;
371
- // after tweening points of line we need to set original end
372
- const attrs = Tween.attrs[node._id][this._id];
373
- if (attrs.points && attrs.points.trueEnd) {
374
- node.setAttr('points', attrs.points.trueEnd);
375
- }
376
- if (this.onFinish) {
377
- this.onFinish.call(this);
378
- }
379
- };
380
- this.tween.onReset = () => {
381
- const node = this.node;
382
- // after tweening points of line we need to set original start
383
- const attrs = Tween.attrs[node._id][this._id];
384
- if (attrs.points && attrs.points.trueStart) {
385
- node.points(attrs.points.trueStart);
368
+ const end = (edge, callback) => {
369
+ var _a;
370
+ // no attributes means the tween was destroyed inside the last onUpdate
371
+ const attrs = (_a = Tween.attrs[this.node._id]) === null || _a === void 0 ? void 0 : _a[this._id];
372
+ if (!attrs) {
373
+ return;
386
374
  }
387
- if (this.onReset) {
388
- this.onReset();
375
+ for (const key in attrs) {
376
+ if (attrs[key][edge] !== undefined) {
377
+ this.node.setAttr(key, attrs[key][edge]);
378
+ }
389
379
  }
380
+ callback === null || callback === void 0 ? void 0 : callback.call(this);
390
381
  };
382
+ this.tween.onFinish = () => end('trueEnd', this.onFinish);
383
+ this.tween.onReset = () => end('trueStart', this.onReset);
391
384
  this.tween.onUpdate = () => {
392
385
  if (this.onUpdate) {
393
386
  this.onUpdate.call(this);
package/lib/Util.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare class Transform {
35
35
  x: number;
36
36
  y: number;
37
37
  };
38
+ _getTransformedRect(rect: IRect): IRect;
38
39
  /**
39
40
  * Apply translation
40
41
  * @method
@@ -133,8 +134,7 @@ export declare const Util: {
133
134
  requestAnimFrame(callback: Function, win?: Window | null): void;
134
135
  createCanvasElement(): HTMLCanvasElement;
135
136
  createImageElement(): HTMLImageElement;
136
- _isInDocument(el: any): boolean;
137
- _urlToImage(url: string, callback: Function): void;
137
+ _urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
138
138
  _rgbToHex(r: number, g: number, b: number): string;
139
139
  _hexToRgb(hex: string): RGB;
140
140
  /**
@@ -266,6 +266,7 @@ export declare const Util: {
266
266
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
267
267
  _prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
268
268
  _assign<T, U>(target: T, source: U): T & U;
269
+ _getEventType(type: string): "mouse" | "touch" | "pointer";
269
270
  _getFirstPointerId(evt: any): any;
270
271
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
271
272
  _cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
package/lib/Util.js CHANGED
@@ -87,6 +87,31 @@ export class Transform {
87
87
  y: m[1] * point.x + m[3] * point.y + m[5],
88
88
  };
89
89
  }
90
+ // Axis-aligned bounds of a rectangle after this transform.
91
+ _getTransformedRect(rect) {
92
+ const [a, b, c, d, e, f] = this.m;
93
+ const x1 = rect.x, y1 = rect.y, x2 = rect.x + rect.width, y2 = rect.y + rect.height;
94
+ const xs = [
95
+ a * x1 + c * y1 + e,
96
+ a * x2 + c * y1 + e,
97
+ a * x2 + c * y2 + e,
98
+ a * x1 + c * y2 + e,
99
+ ];
100
+ const ys = [
101
+ b * x1 + d * y1 + f,
102
+ b * x2 + d * y1 + f,
103
+ b * x2 + d * y2 + f,
104
+ b * x1 + d * y2 + f,
105
+ ];
106
+ const minX = Math.min(xs[0], xs[1], xs[2], xs[3]);
107
+ const minY = Math.min(ys[0], ys[1], ys[2], ys[3]);
108
+ return {
109
+ x: minX,
110
+ y: minY,
111
+ width: Math.max(xs[0], xs[1], xs[2], xs[3]) - minX,
112
+ height: Math.max(ys[0], ys[1], ys[2], ys[3]) - minY,
113
+ };
114
+ }
90
115
  /**
91
116
  * Apply translation
92
117
  * @method
@@ -464,18 +489,20 @@ const NUMBER_SOURCE = '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?';
464
489
  const COLOR_COMPONENT_REGEX = new RegExp(`^(${NUMBER_SOURCE})(%?)$`, 'i');
465
490
  // Parse one color component. 100% is `max`: 255 for the color channels of
466
491
  // rgb(), 1 for the alpha, 100 for the saturation and the lightness of hsl().
492
+ // CSS clamps a component to [0, max], and so do we: Konva multiplies and
493
+ // interpolates these numbers (shadowOpacity, Tween) before the canvas sees
494
+ // them. NaN stays NaN, so a bad value still fails.
467
495
  const parseColorComponent = (value, max) => {
468
496
  const match = COLOR_COMPONENT_REGEX.exec(value);
469
497
  if (!match) {
470
498
  return NaN;
471
499
  }
472
- return match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
500
+ const n = match[2] ? (Number(match[1]) / 100) * max : Number(match[1]);
501
+ return Math.min(Math.max(n, 0), max);
473
502
  };
474
503
  // parseInt() stops at the first character it can not read, so "#0g0000" would
475
504
  // give a valid black instead of failing. The hex parsers test the shape first.
476
505
  const HEX_COLOR_REGEX = /^#[0-9a-f]+$/i;
477
- // Keep a fraction in [0, 1]. NaN stays NaN, so a bad value still fails.
478
- const clamp01 = (value) => Math.min(Math.max(value, 0), 1);
479
506
  // The hue of hsl() is the same number, with a CSS Color 4 angle unit
480
507
  // instead of the "%" sign. No unit means degrees.
481
508
  const HUE_REGEX = new RegExp(`^(${NUMBER_SOURCE})(deg|grad|rad|turn)?$`, 'i');
@@ -575,20 +602,18 @@ export const Util = {
575
602
  ensureBrowser();
576
603
  return document.createElement('img');
577
604
  },
578
- _isInDocument(el) {
579
- // not `el.parentNode == document`, because the element may belong to
580
- // another document: an iframe, or a popout window
581
- return !!el.isConnected;
582
- },
583
605
  /*
584
606
  * arg can be an image object or image data
585
607
  */
586
- _urlToImage(url, callback) {
608
+ _urlToImage(url, callback, onError) {
587
609
  // if arg is a string, then it's a data url
588
610
  const imageObj = Util.createImageElement();
589
611
  imageObj.onload = function () {
590
612
  callback(imageObj);
591
613
  };
614
+ imageObj.onerror = (event) => {
615
+ onError === null || onError === void 0 ? void 0 : onError(event instanceof Error ? event : new Error('Unable to load image.'));
616
+ };
592
617
  imageObj.src = url;
593
618
  },
594
619
  _rgbToHex(r, g, b) {
@@ -830,11 +855,9 @@ export const Util = {
830
855
  // negative angles and angles over one full turn
831
856
  const h = (((degrees % 360) + 360) % 360) / 360;
832
857
  // the saturation and the lightness are percentages of 1, written with or
833
- // without the "%" sign, so read them out of 100 and then scale them down.
834
- // CSS keeps them in [0, 1]; out of that range the math gives a negative
835
- // channel, which the canvas can not read at all.
836
- const s = clamp01(parseColorComponent(parts[1], 100) / 100);
837
- const l = clamp01(parseColorComponent(parts[2], 100) / 100);
858
+ // without the "%" sign, so read them out of 100 and then scale them down
859
+ const s = parseColorComponent(parts[1], 100) / 100;
860
+ const l = parseColorComponent(parts[2], 100) / 100;
838
861
  const a = parts.length > 3 ? parseColorComponent(parts[3], 1) : 1;
839
862
  const t2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
840
863
  const t1 = 2 * l - t2;
@@ -1099,10 +1122,17 @@ export const Util = {
1099
1122
  }
1100
1123
  return target;
1101
1124
  },
1125
+ _getEventType(type) {
1126
+ if (type.indexOf('pointer') >= 0)
1127
+ return 'pointer';
1128
+ if (type.indexOf('touch') >= 0)
1129
+ return 'touch';
1130
+ return 'mouse';
1131
+ },
1102
1132
  _getFirstPointerId(evt) {
1133
+ var _a;
1103
1134
  if (!evt.touches) {
1104
- // try to use pointer id or fake id
1105
- return evt.pointerId || 999;
1135
+ return (_a = evt.pointerId) !== null && _a !== void 0 ? _a : 999;
1106
1136
  }
1107
1137
  else {
1108
1138
  return evt.changedTouches[0].identifier;
@@ -22,12 +22,6 @@ export declare const Konva: {
22
22
  autoDrawEnabled: boolean;
23
23
  hitOnDragEnabled: boolean;
24
24
  capturePointerEventsEnabled: boolean;
25
- _mouseListenClick: boolean;
26
- _touchListenClick: boolean;
27
- _pointerListenClick: boolean;
28
- _mouseInDblClickWindow: boolean;
29
- _touchInDblClickWindow: boolean;
30
- _pointerInDblClickWindow: boolean;
31
25
  _renderBackend: string;
32
26
  legacyTextRendering: boolean;
33
27
  pixelRatio: number;
@@ -56,8 +50,7 @@ export declare const Konva: {
56
50
  requestAnimFrame(callback: Function, win?: Window | null): void;
57
51
  createCanvasElement(): HTMLCanvasElement;
58
52
  createImageElement(): HTMLImageElement;
59
- _isInDocument(el: any): boolean;
60
- _urlToImage(url: string, callback: Function): void;
53
+ _urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
61
54
  _rgbToHex(r: number, g: number, b: number): string;
62
55
  _hexToRgb(hex: string): import("./types.ts").RGB;
63
56
  getRandomColor(): string;
@@ -134,6 +127,7 @@ export declare const Konva: {
134
127
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
135
128
  _prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
136
129
  _assign<T, U>(target: T, source: U): T & U;
130
+ _getEventType(type: string): "mouse" | "touch" | "pointer";
137
131
  _getFirstPointerId(evt: any): any;
138
132
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
139
133
  _cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
@@ -150,13 +144,13 @@ export declare const Konva: {
150
144
  Group: typeof Group;
151
145
  DD: {
152
146
  readonly isDragging: boolean;
153
- justDragged: boolean;
154
147
  readonly node: Node<import("./Node.ts").NodeConfig> | undefined;
155
148
  _dragElements: Map<number, {
156
149
  node: Node;
157
150
  startPointerPos: import("./types.ts").Vector2d;
158
151
  offset: import("./types.ts").Vector2d;
159
152
  pointerId?: number;
153
+ pointerEventType?: Stage["_pointerEventType"];
160
154
  lastPos?: import("./types.ts").Vector2d;
161
155
  startEvent?: any;
162
156
  dragStatus: "ready" | "dragging" | "stopped";
@@ -164,8 +158,26 @@ export declare const Konva: {
164
158
  _listenToWindow(win: Window): void;
165
159
  _batchEvents(callback: () => void, win?: Window): void;
166
160
  _drag(evt: any, win?: Window): void;
167
- _endDragBefore(evt?: any, win?: Window): void;
168
- _endDragAfter(evt: any): void;
161
+ _endDragBefore(evt?: any, win?: Window, only?: {
162
+ node: Node;
163
+ startPointerPos: import("./types.ts").Vector2d;
164
+ offset: import("./types.ts").Vector2d;
165
+ pointerId?: number;
166
+ pointerEventType?: Stage["_pointerEventType"];
167
+ lastPos?: import("./types.ts").Vector2d;
168
+ startEvent?: any;
169
+ dragStatus: "ready" | "dragging" | "stopped";
170
+ }): void;
171
+ _endDragAfter(evt: any, only?: {
172
+ node: Node;
173
+ startPointerPos: import("./types.ts").Vector2d;
174
+ offset: import("./types.ts").Vector2d;
175
+ pointerId?: number;
176
+ pointerEventType?: Stage["_pointerEventType"];
177
+ lastPos?: import("./types.ts").Vector2d;
178
+ startEvent?: any;
179
+ dragStatus: "ready" | "dragging" | "stopped";
180
+ }): void;
169
181
  };
170
182
  Shape: typeof Shape;
171
183
  shapes: {
@@ -28,12 +28,6 @@ export declare const Konva: {
28
28
  autoDrawEnabled: boolean;
29
29
  hitOnDragEnabled: boolean;
30
30
  capturePointerEventsEnabled: boolean;
31
- _mouseListenClick: boolean;
32
- _touchListenClick: boolean;
33
- _pointerListenClick: boolean;
34
- _mouseInDblClickWindow: boolean;
35
- _touchInDblClickWindow: boolean;
36
- _pointerInDblClickWindow: boolean;
37
31
  _renderBackend: string;
38
32
  legacyTextRendering: boolean;
39
33
  pixelRatio: number;
@@ -62,8 +56,7 @@ export declare const Konva: {
62
56
  requestAnimFrame(callback: Function, win?: Window | null): void;
63
57
  createCanvasElement(): HTMLCanvasElement;
64
58
  createImageElement(): HTMLImageElement;
65
- _isInDocument(el: any): boolean;
66
- _urlToImage(url: string, callback: Function): void;
59
+ _urlToImage(url: string, callback: Function, onError?: (error: Error) => void): void;
67
60
  _rgbToHex(r: number, g: number, b: number): string;
68
61
  _hexToRgb(hex: string): import("./types.ts").RGB;
69
62
  getRandomColor(): string;
@@ -140,6 +133,7 @@ export declare const Konva: {
140
133
  _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
141
134
  _prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
142
135
  _assign<T, U>(target: T, source: U): T & U;
136
+ _getEventType(type: string): "mouse" | "touch" | "pointer";
143
137
  _getFirstPointerId(evt: any): any;
144
138
  releaseCanvas(...canvases: HTMLCanvasElement[]): void;
145
139
  _cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
@@ -156,13 +150,13 @@ export declare const Konva: {
156
150
  Group: typeof import("./Group.ts").Group;
157
151
  DD: {
158
152
  readonly isDragging: boolean;
159
- justDragged: boolean;
160
153
  readonly node: import("./Node.ts").Node<import("./Node.ts").NodeConfig> | undefined;
161
154
  _dragElements: Map<number, {
162
155
  node: import("./Node.ts").Node;
163
156
  startPointerPos: import("./types.ts").Vector2d;
164
157
  offset: import("./types.ts").Vector2d;
165
158
  pointerId?: number;
159
+ pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
166
160
  lastPos?: import("./types.ts").Vector2d;
167
161
  startEvent?: any;
168
162
  dragStatus: "ready" | "dragging" | "stopped";
@@ -170,8 +164,26 @@ export declare const Konva: {
170
164
  _listenToWindow(win: Window): void;
171
165
  _batchEvents(callback: () => void, win?: Window): void;
172
166
  _drag(evt: any, win?: Window): void;
173
- _endDragBefore(evt?: any, win?: Window): void;
174
- _endDragAfter(evt: any): void;
167
+ _endDragBefore(evt?: any, win?: Window, only?: {
168
+ node: import("./Node.ts").Node;
169
+ startPointerPos: import("./types.ts").Vector2d;
170
+ offset: import("./types.ts").Vector2d;
171
+ pointerId?: number;
172
+ pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
173
+ lastPos?: import("./types.ts").Vector2d;
174
+ startEvent?: any;
175
+ dragStatus: "ready" | "dragging" | "stopped";
176
+ }): void;
177
+ _endDragAfter(evt: any, only?: {
178
+ node: import("./Node.ts").Node;
179
+ startPointerPos: import("./types.ts").Vector2d;
180
+ offset: import("./types.ts").Vector2d;
181
+ pointerId?: number;
182
+ pointerEventType?: import("./Stage.ts").Stage["_pointerEventType"];
183
+ lastPos?: import("./types.ts").Vector2d;
184
+ startEvent?: any;
185
+ dragStatus: "ready" | "dragging" | "stopped";
186
+ }): void;
175
187
  };
176
188
  Shape: typeof import("./Shape.ts").Shape;
177
189
  shapes: {
@@ -94,12 +94,16 @@ const shg_table = [
94
94
  function premultiply(channel, alpha) {
95
95
  return alpha === 255 ? channel : (channel * alpha) / 255;
96
96
  }
97
- // the stack sums overflow 32-bit integers above this radius
97
+ // Preserve the maximum logical radius; high-DPI caches need larger kernels.
98
98
  const MAX_RADIUS = 180;
99
99
  function filterGaussBlurRGBA(imageData, radius) {
100
100
  const pixels = imageData.data, width = imageData.width, height = imageData.height;
101
101
  let p, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
102
- const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), mul_sum = mul_table[radius], shg_sum = shg_table[radius];
102
+ const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(),
103
+ // Use floating-point normalization to avoid 32-bit overflow at high DPI.
104
+ normalization = radius <= MAX_RADIUS
105
+ ? mul_table[radius] / 2 ** shg_table[radius]
106
+ : 1 / (radiusPlus1 * radiusPlus1);
103
107
  let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
104
108
  for (let i = 1; i < div; i++) {
105
109
  stack = stack.next = new BlurStack();
@@ -156,10 +160,10 @@ function filterGaussBlurRGBA(imageData, radius) {
156
160
  stackIn = stackStart;
157
161
  stackOut = stackEnd;
158
162
  for (let x = 0; x < width; x++) {
159
- pixels[yi] = (r_sum * mul_sum) >> shg_sum;
160
- pixels[yi + 1] = (g_sum * mul_sum) >> shg_sum;
161
- pixels[yi + 2] = (b_sum * mul_sum) >> shg_sum;
162
- pixels[yi + 3] = (a_sum * mul_sum) >> shg_sum;
163
+ pixels[yi] = Math.floor(r_sum * normalization);
164
+ pixels[yi + 1] = Math.floor(g_sum * normalization);
165
+ pixels[yi + 2] = Math.floor(b_sum * normalization);
166
+ pixels[yi + 3] = Math.floor(a_sum * normalization);
163
167
  r_sum -= r_out_sum;
164
168
  g_sum -= g_out_sum;
165
169
  b_sum -= b_out_sum;
@@ -241,12 +245,12 @@ function filterGaussBlurRGBA(imageData, radius) {
241
245
  stackOut = stackEnd;
242
246
  for (let y = 0; y < height; y++) {
243
247
  p = yi << 2;
244
- pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum;
248
+ pixels[p + 3] = pa = Math.floor(a_sum * normalization);
245
249
  if (pa > 0) {
246
250
  pa = 255 / pa;
247
- pixels[p] = ((r_sum * mul_sum) >> shg_sum) * pa;
248
- pixels[p + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
249
- pixels[p + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
251
+ pixels[p] = Math.floor(r_sum * normalization) * pa;
252
+ pixels[p + 1] = Math.floor(g_sum * normalization) * pa;
253
+ pixels[p + 2] = Math.floor(b_sum * normalization) * pa;
250
254
  }
251
255
  else {
252
256
  pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
@@ -292,8 +296,8 @@ function filterGaussBlurRGBA(imageData, radius) {
292
296
  * node.filters([Konva.Filters.Blur]);
293
297
  * node.blurRadius(10);
294
298
  */
295
- export const Blur = function Blur(imageData) {
296
- const radius = Math.min(Math.round(this.blurRadius()), MAX_RADIUS);
299
+ export const Blur = function Blur(imageData, pixelRatio = 1) {
300
+ const radius = Math.round(Math.min(this.blurRadius(), MAX_RADIUS) * pixelRatio);
297
301
  if (radius > 0) {
298
302
  filterGaussBlurRGBA(imageData, radius);
299
303
  }
@@ -16,6 +16,7 @@ export declare const Brighten: Filter;
16
16
  * get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
17
17
  * added to every channel: positive values brighten the pixels and negative values darken them.
18
18
  * With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
19
+ * Both filters leave pixels unchanged when the attribute is unset. An explicit 0 makes Brightness black.
19
20
  * @name Konva.Node#brightness
20
21
  * @method
21
22
  * @param {Number} brightness
@@ -29,6 +29,7 @@ Factory.addGetterSetter(Node, 'brightness', 0, getNumberValidator(), Factory.aft
29
29
  * get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
30
30
  * added to every channel: positive values brighten the pixels and negative values darken them.
31
31
  * With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
32
+ * Both filters leave pixels unchanged when the attribute is unset. An explicit 0 makes Brightness black.
32
33
  * @name Konva.Node#brightness
33
34
  * @method
34
35
  * @param {Number} brightness
@@ -1,7 +1,8 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ import './Brighten.ts';
2
3
  /**
3
4
  * Brightness Filter.
4
- * CSS-compatible brightness filter that uses multiplicative approach.
5
+ * CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
5
6
  * @function
6
7
  * @memberof Konva.Filters
7
8
  * @param {Object} imageData
@@ -1,6 +1,8 @@
1
+ // The shared brightness accessor is registered by Brighten.
2
+ import "./Brighten.js";
1
3
  /**
2
4
  * Brightness Filter.
3
- * CSS-compatible brightness filter that uses multiplicative approach.
5
+ * CSS-compatible brightness multiplier. An unset brightness leaves pixels unchanged.
4
6
  * @function
5
7
  * @memberof Konva.Filters
6
8
  * @param {Object} imageData
@@ -10,7 +12,7 @@
10
12
  * node.brightness(1.5); // 50% brighter (CSS-compatible)
11
13
  */
12
14
  export const Brightness = function (imageData) {
13
- const brightness = this.brightness(), data = imageData.data, len = data.length;
15
+ const brightness = this.attrs.brightness === undefined ? 1 : this.brightness(), data = imageData.data, len = data.length;
14
16
  for (let i = 0; i < len; i += 4) {
15
17
  // red
16
18
  data[i] = Math.min(255, data[i] * brightness);
@@ -20,5 +22,3 @@ export const Brightness = function (imageData) {
20
22
  data[i + 2] = Math.min(255, data[i + 2] * brightness);
21
23
  }
22
24
  };
23
- // Note: brightness property is already defined in Brighten.ts
24
- // This filter reuses the existing brightness property but with CSS-compatible behavior