konva 10.9.0 → 10.10.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 (72) hide show
  1. package/README.md +22 -10
  2. package/konva.js +18996 -18838
  3. package/konva.min.js +50 -50
  4. package/lib/Animation.js +3 -3
  5. package/lib/Canvas.js +11 -3
  6. package/lib/Container.js +3 -3
  7. package/lib/Context.d.ts +2 -2
  8. package/lib/Context.js +17 -20
  9. package/lib/Core.js +2 -2
  10. package/lib/DragAndDrop.js +1 -1
  11. package/lib/Factory.js +2 -2
  12. package/lib/FastLayer.js +3 -3
  13. package/lib/Global.d.ts +0 -1
  14. package/lib/Global.js +13 -7
  15. package/lib/Group.js +5 -5
  16. package/lib/Layer.d.ts +1 -1
  17. package/lib/Layer.js +8 -8
  18. package/lib/Node.d.ts +2 -0
  19. package/lib/Node.js +76 -76
  20. package/lib/PointerEvents.js +1 -1
  21. package/lib/Shape.d.ts +5 -1
  22. package/lib/Shape.js +37 -43
  23. package/lib/Stage.js +8 -8
  24. package/lib/Tween.js +4 -4
  25. package/lib/Util.d.ts +67 -3
  26. package/lib/Util.js +124 -41
  27. package/lib/Validators.js +2 -2
  28. package/lib/_CoreInternals.d.ts +15 -11
  29. package/lib/_CoreInternals.js +16 -14
  30. package/lib/_FullInternals.d.ts +14 -10
  31. package/lib/_FullInternals.js +38 -38
  32. package/lib/canvas-backend.js +6 -15
  33. package/lib/filters/Blur.js +27 -3
  34. package/lib/filters/Brighten.js +3 -3
  35. package/lib/filters/Brightness.js +9 -3
  36. package/lib/filters/Contrast.js +9 -5
  37. package/lib/filters/Emboss.js +17 -9
  38. package/lib/filters/Enhance.js +3 -3
  39. package/lib/filters/HSL.js +3 -3
  40. package/lib/filters/HSV.js +3 -3
  41. package/lib/filters/Kaleidoscope.js +3 -3
  42. package/lib/filters/Mask.js +3 -3
  43. package/lib/filters/Noise.js +3 -3
  44. package/lib/filters/Pixelate.js +4 -4
  45. package/lib/filters/Posterize.js +3 -3
  46. package/lib/filters/RGB.js +3 -3
  47. package/lib/filters/RGBA.js +3 -3
  48. package/lib/filters/Threshold.js +3 -3
  49. package/lib/index.js +1 -1
  50. package/lib/napi-backend.d.ts +2 -0
  51. package/lib/napi-backend.js +15 -0
  52. package/lib/shapes/Arc.js +5 -5
  53. package/lib/shapes/Arrow.js +5 -5
  54. package/lib/shapes/Circle.js +4 -4
  55. package/lib/shapes/Ellipse.js +4 -4
  56. package/lib/shapes/Image.js +5 -5
  57. package/lib/shapes/Label.js +7 -7
  58. package/lib/shapes/Line.js +6 -6
  59. package/lib/shapes/Path.js +5 -5
  60. package/lib/shapes/Rect.js +5 -5
  61. package/lib/shapes/RegularPolygon.js +5 -5
  62. package/lib/shapes/Ring.js +4 -4
  63. package/lib/shapes/Sprite.js +5 -5
  64. package/lib/shapes/Star.js +4 -4
  65. package/lib/shapes/Text.d.ts +0 -1
  66. package/lib/shapes/Text.js +36 -34
  67. package/lib/shapes/TextPath.d.ts +3 -2
  68. package/lib/shapes/TextPath.js +71 -46
  69. package/lib/shapes/Transformer.js +12 -11
  70. package/lib/shapes/Wedge.js +5 -5
  71. package/lib/skia-backend.js +17 -25
  72. package/package.json +31 -34
package/lib/Animation.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var _a;
2
- import { glob } from "./Global.js";
3
- import { Node } from "./Node.js";
4
- import { Util } from "./Util.js";
2
+ import { glob } from './Global.js';
3
+ import { Node } from './Node.js';
4
+ import { Util } from './Util.js';
5
5
  const now = ((_a = glob.performance) === null || _a === void 0 ? void 0 : _a.now)
6
6
  ? () => glob.performance.now()
7
7
  : Date.now;
package/lib/Canvas.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Transform, Util } from "./Util.js";
2
- import { SceneContext, HitContext } from "./Context.js";
3
- import { Konva } from "./Global.js";
1
+ import { Transform, Util } from './Util.js';
2
+ import { SceneContext, HitContext } from './Context.js';
3
+ import { Konva } from './Global.js';
4
4
  /**
5
5
  * Canvas Renderer constructor. It is a wrapper around native canvas element.
6
6
  * Usually you don't need to use it manually.
@@ -14,6 +14,8 @@ import { Konva } from "./Global.js";
14
14
  */
15
15
  export class Canvas {
16
16
  constructor(config) {
17
+ var _a;
18
+ var _b;
17
19
  this.pixelRatio = 1;
18
20
  // the bitmap size, in device pixels
19
21
  this.width = 0;
@@ -30,6 +32,8 @@ export class Canvas {
30
32
  1;
31
33
  this.pixelRatio = pixelRatio;
32
34
  this._canvas = Util.createCanvasElement();
35
+ // a canvas outside the DOM (OffscreenCanvas, Node.js backends) has no style
36
+ (_a = (_b = this._canvas).style) !== null && _a !== void 0 ? _a : (_b.style = {});
33
37
  // set inline styles
34
38
  this._canvas.style.padding = '0';
35
39
  this._canvas.style.margin = '0';
@@ -134,6 +138,10 @@ export class Canvas {
134
138
  * @returns {String} data url string
135
139
  */
136
140
  toDataURL(mimeType, quality) {
141
+ if (!this._canvas.toDataURL) {
142
+ // an OffscreenCanvas, as in a Web Worker, only encodes asynchronously
143
+ throw new Error('Konva: this canvas can not make a data URL. In a Web Worker, use toBlob() instead.');
144
+ }
137
145
  try {
138
146
  // If the requested encoding fails, retry with the default PNG encoding.
139
147
  return this._canvas.toDataURL(mimeType, quality);
package/lib/Container.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Factory } from "./Factory.js";
2
- import { Node } from "./Node.js";
3
- import { getNumberValidator } from "./Validators.js";
1
+ import { Factory } from './Factory.js';
2
+ import { Node } from './Node.js';
3
+ import { getNumberValidator } from './Validators.js';
4
4
  /**
5
5
  * Container constructor.  Containers are used to contain nodes or other containers
6
6
  * @constructor
package/lib/Context.d.ts CHANGED
@@ -2,8 +2,7 @@ import type { Canvas, SceneCanvas } from './Canvas.ts';
2
2
  import type { Shape } from './Shape.ts';
3
3
  import type { IRect } from './types.ts';
4
4
  import type { Node } from './Node.ts';
5
- declare const CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "letterSpacing", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "direction", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled", "imageSmoothingQuality", "filter"];
6
- export declare function isCSSFiltersSupported(): boolean;
5
+ declare const CONTEXT_PROPERTIES: readonly ['fillStyle', 'strokeStyle', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'letterSpacing', 'lineCap', 'lineDashOffset', 'lineJoin', 'lineWidth', 'miterLimit', 'direction', 'font', 'textAlign', 'textBaseline', 'globalAlpha', 'globalCompositeOperation', 'imageSmoothingEnabled', 'imageSmoothingQuality', 'filter'];
7
6
  interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
8
7
  letterSpacing: string;
9
8
  }
@@ -332,6 +331,7 @@ export declare class SceneContext extends Context {
332
331
  _fill(shape: Shape): void;
333
332
  _strokeLinearGradient(shape: any): void;
334
333
  _applyStrokeStyle(shape: Shape): void;
334
+ _applyDecorationStyle(shape: Shape): boolean;
335
335
  _stroke(shape: any): void;
336
336
  _applyShadow(shape: any): void;
337
337
  }
package/lib/Context.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Transform, Util } from "./Util.js";
2
- import { Konva } from "./Global.js";
1
+ import { Transform, Util } from './Util.js';
2
+ import { Konva } from './Global.js';
3
3
  function simplifyArray(arr) {
4
4
  const retArr = [], len = arr.length, util = Util;
5
5
  for (let n = 0; n < len; n++) {
@@ -76,23 +76,6 @@ const CONTEXT_PROPERTIES = [
76
76
  'filter',
77
77
  ];
78
78
  const traceArrMax = 100;
79
- // Check if CSS filters are supported in the current browser
80
- let _cssFiltersSupported = null;
81
- export function isCSSFiltersSupported() {
82
- if (_cssFiltersSupported !== null) {
83
- return _cssFiltersSupported;
84
- }
85
- try {
86
- const canvas = Util.createCanvasElement();
87
- const ctx = canvas.getContext('2d');
88
- _cssFiltersSupported = !!ctx && 'filter' in ctx;
89
- Util.releaseCanvas(canvas);
90
- }
91
- catch (e) {
92
- _cssFiltersSupported = false;
93
- }
94
- return _cssFiltersSupported;
95
- }
96
79
  /**
97
80
  * Konva wrapper around native 2d canvas context. It has almost the same API of 2d context with some additional functions.
98
81
  * With core Konva shapes you don't need to use this object. But you will use it if you want to create
@@ -710,7 +693,7 @@ export class SceneContext extends Context {
710
693
  }
711
694
  }
712
695
  _strokeLinearGradient(shape) {
713
- let start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint();
696
+ let start = shape._toStyleSpace(shape.getStrokeLinearGradientStartPoint()), end = shape._toStyleSpace(shape.getStrokeLinearGradientEndPoint());
714
697
  if (!shape.getStrokeScaleEnabled()) {
715
698
  const { a, b, c, d, e, f } = this._context.getTransform();
716
699
  const transform = new Transform([a, b, c, d, e, f]);
@@ -747,6 +730,20 @@ export class SceneContext extends Context {
747
730
  this.setAttr('strokeStyle', shape.stroke());
748
731
  }
749
732
  }
733
+ // Text decorations are drawn like the glyphs: with the fill, or with the
734
+ // stroke when the text is only outlined. False when the glyphs paint nothing.
735
+ _applyDecorationStyle(shape) {
736
+ if (shape.hasFill()) {
737
+ this.strokeStyle = this._getFillStyle(shape);
738
+ }
739
+ else if (shape.hasStroke()) {
740
+ this._applyStrokeStyle(shape);
741
+ }
742
+ else {
743
+ return false;
744
+ }
745
+ return true;
746
+ }
750
747
  _stroke(shape) {
751
748
  const dash = shape.dash(),
752
749
  // ignore strokeScaleEnabled for Text
package/lib/Core.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // enter file of limited Konva version with only core functions
2
- export { Konva } from "./_CoreInternals.js";
3
- import { Konva } from "./_CoreInternals.js";
2
+ export { Konva } from './_CoreInternals.js';
3
+ import { Konva } from './_CoreInternals.js';
4
4
  export default Konva;
@@ -1,4 +1,4 @@
1
- import { Util } from "./Util.js";
1
+ import { Util } from './Util.js';
2
2
  export const DD = {
3
3
  get isDragging() {
4
4
  let flag = false;
package/lib/Factory.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Util } from "./Util.js";
2
- import { getComponentValidator } from "./Validators.js";
1
+ import { Util } from './Util.js';
2
+ import { getComponentValidator } from './Validators.js';
3
3
  const GET = 'get';
4
4
  const SET = 'set';
5
5
  export const Factory = {
package/lib/FastLayer.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Util } from "./Util.js";
2
- import { Layer } from "./Layer.js";
3
- import { _registerNode } from "./Global.js";
1
+ import { Util } from './Util.js';
2
+ import { Layer } from './Layer.js';
3
+ import { _registerNode } from './Global.js';
4
4
  /**
5
5
  * FastLayer constructor. **DEPRECATED!** Please use `Konva.Layer({ listening: false})` instead. Layers are tied to their own canvas element and are used
6
6
  * to contain shapes only. If you don't need node nesting, mouse and touch interactions,
package/lib/Global.d.ts CHANGED
@@ -42,7 +42,6 @@ export declare const Konva: {
42
42
  * Konva.capturePointerEventsEnabled = true;
43
43
  */
44
44
  capturePointerEventsEnabled: boolean;
45
- _renderBackend: string;
46
45
  /**
47
46
  * Use legacy text rendering. with "middle" baseline by default.
48
47
  * @property legacyTextRendering
package/lib/Global.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Konva JavaScript Framework v10.9.0
2
+ * Konva JavaScript Framework v10.10.0
3
3
  * http://konvajs.org/
4
4
  * Licensed under the MIT
5
5
  * Date: @@date
@@ -29,7 +29,7 @@ export const glob = typeof global !== 'undefined'
29
29
  : {};
30
30
  export const Konva = {
31
31
  _global: glob,
32
- version: '10.9.0',
32
+ version: '10.10.0',
33
33
  isBrowser: detectBrowser(),
34
34
  isUnminified: /param/.test(function (param) { }.toString()),
35
35
  dblClickWindow: 400,
@@ -72,7 +72,6 @@ export const Konva = {
72
72
  * Konva.capturePointerEventsEnabled = true;
73
73
  */
74
74
  capturePointerEventsEnabled: false,
75
- _renderBackend: 'web', // web, node-canvas, skia-canvas
76
75
  /**
77
76
  * Use legacy text rendering. with "middle" baseline by default.
78
77
  * @property legacyTextRendering
@@ -150,7 +149,8 @@ export const Konva = {
150
149
  * @memberof Konva
151
150
  */
152
151
  isTransforming() {
153
- var _a, _b;
152
+ var _a;
153
+ var _b;
154
154
  return (_b = (_a = Konva['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming()) !== null && _b !== void 0 ? _b : false;
155
155
  },
156
156
  /**
@@ -174,11 +174,13 @@ export const Konva = {
174
174
  */
175
175
  releaseCanvasOnDestroy: true,
176
176
  document: glob.document,
177
- // insert Konva into global namespace (window)
178
- // it is required for npm packages
177
+ // window.Konva is how konva-devtool and browser tests find the stages, so
178
+ // the first copy keeps it. A second copy in one page is usually a bundling
179
+ // mistake that splits stages and settings between the copies
179
180
  _injectGlobal(Konva) {
180
181
  if (typeof glob.Konva !== 'undefined') {
181
182
  console.error('Several Konva instances detected. It is not recommended to use multiple Konva instances in the same environment.');
183
+ return;
182
184
  }
183
185
  glob.Konva = Konva;
184
186
  },
@@ -191,4 +193,8 @@ export const _registerNode = (NodeClass, boundsCoverPaint = false) => {
191
193
  if (boundsCoverPaint)
192
194
  _boundedShapes.add(NodeClass);
193
195
  };
194
- Konva._injectGlobal(Konva);
196
+ // devtools and browser tests can not see a copy in Node.js or a worker, such
197
+ // as a library's private copy for server rendering, so it stays quiet
198
+ if (Konva.isBrowser) {
199
+ Konva._injectGlobal(Konva);
200
+ }
package/lib/Group.js CHANGED
@@ -1,8 +1,8 @@
1
- import { Util } from "./Util.js";
2
- import { Container } from "./Container.js";
3
- import { _registerNode } from "./Global.js";
4
- import { Factory } from "./Factory.js";
5
- import { getBooleanValidator } from "./Validators.js";
1
+ import { Util } from './Util.js';
2
+ import { Container } from './Container.js';
3
+ import { _registerNode } from './Global.js';
4
+ import { Factory } from './Factory.js';
5
+ import { getBooleanValidator } from './Validators.js';
6
6
  /**
7
7
  * Group constructor. Groups are used to contain shapes or other groups.
8
8
  * @constructor
package/lib/Layer.d.ts CHANGED
@@ -78,8 +78,8 @@ export declare class Layer extends Container<Group | Shape> {
78
78
  remove(): this;
79
79
  getStage(): Stage;
80
80
  _setSize({ width, height }: {
81
- width: any;
82
81
  height: any;
82
+ width: any;
83
83
  }): this;
84
84
  _syncHitCanvasSize(): void;
85
85
  _validateAdd(child: any): void;
package/lib/Layer.js CHANGED
@@ -1,11 +1,11 @@
1
- import { Util } from "./Util.js";
2
- import { Container } from "./Container.js";
3
- import { Node } from "./Node.js";
4
- import { Factory } from "./Factory.js";
5
- import { SceneCanvas, HitCanvas } from "./Canvas.js";
6
- import { shapes } from "./Shape.js";
7
- import { _registerNode, Konva } from "./Global.js";
8
- import { DD } from "./DragAndDrop.js";
1
+ import { Util } from './Util.js';
2
+ import { Container } from './Container.js';
3
+ import { Node } from './Node.js';
4
+ import { Factory } from './Factory.js';
5
+ import { SceneCanvas, HitCanvas } from './Canvas.js';
6
+ import { shapes } from './Shape.js';
7
+ import { _registerNode, Konva } from './Global.js';
8
+ import { DD } from './DragAndDrop.js';
9
9
  // constants
10
10
  const BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',
11
11
  // getIntersection() reads the hit canvas around an edge pixel in blocks
package/lib/Node.d.ts CHANGED
@@ -14,6 +14,8 @@ type Filters = Array<FilterFunction | string>;
14
14
  type SubtreeObserver = {
15
15
  _onSubtreeChange(node: Node): void;
16
16
  };
17
+ type CSSFilterFallback = (imageData: ImageData, value: number, pixelRatio: number) => void;
18
+ export declare function _registerCSSFilterFallback(name: string, fallback: CSSFilterFallback): void;
17
19
  type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
18
20
  export type NodeConfig = {
19
21
  x?: number;
package/lib/Node.js CHANGED
@@ -1,11 +1,10 @@
1
- import { HitCanvas, SceneCanvas } from "./Canvas.js";
2
- import { isCSSFiltersSupported } from "./Context.js";
3
- import { DD } from "./DragAndDrop.js";
4
- import * as PointerEvents from "./PointerEvents.js";
5
- import { Factory } from "./Factory.js";
6
- import { Konva } from "./Global.js";
7
- import { Transform, TypedArray, Util } from "./Util.js";
8
- import { getBooleanValidator, getNumberValidator, getStringValidator, } from "./Validators.js";
1
+ import { HitCanvas, SceneCanvas } from './Canvas.js';
2
+ import { DD } from './DragAndDrop.js';
3
+ import * as PointerEvents from './PointerEvents.js';
4
+ import { Factory } from './Factory.js';
5
+ import { Konva } from './Global.js';
6
+ import { Transform, TypedArray, Util } from './Util.js';
7
+ import { getBooleanValidator, getNumberValidator, getStringValidator, } from './Validators.js';
9
8
  // CSS filter parser for fallback to function filters.
10
9
  function parseCSSFilters(cssFilter) {
11
10
  const steps = [];
@@ -13,14 +12,8 @@ function parseCSSFilters(cssFilter) {
13
12
  let match;
14
13
  while ((match = filterRegex.exec(cssFilter)) !== null) {
15
14
  const [, name, argument] = match;
16
- if (![
17
- 'blur',
18
- 'brightness',
19
- 'contrast',
20
- 'grayscale',
21
- 'sepia',
22
- 'invert',
23
- ].includes(name)) {
15
+ const fallback = cssFilterFallbacks[name];
16
+ if (!fallback) {
24
17
  Util.warn(`CSS filter "${name}" is not supported in fallback mode. Consider using function filters for better compatibility.`);
25
18
  continue;
26
19
  }
@@ -29,53 +22,47 @@ function parseCSSFilters(cssFilter) {
29
22
  ? 0
30
23
  : 1
31
24
  : parseFloat(argument) / (argument.includes('%') ? 100 : 1);
32
- steps.push({ name, value });
25
+ steps.push({ fallback, value });
33
26
  }
34
27
  return function (imageData, pixelRatio = 1) {
35
- var _a;
36
- for (const { name, value } of steps) {
37
- if (['grayscale', 'sepia', 'invert'].includes(name)) {
38
- const amount = Math.min(1, Math.max(0, value));
39
- const data = imageData.data;
40
- for (let i = 0; i < data.length; i += 4) {
41
- const r = data[i], g = data[i + 1], b = data[i + 2];
42
- let red, green, blue;
43
- if (name === 'grayscale') {
44
- red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
45
- }
46
- else if (name === 'sepia') {
47
- red = 0.393 * r + 0.769 * g + 0.189 * b;
48
- green = 0.349 * r + 0.686 * g + 0.168 * b;
49
- blue = 0.272 * r + 0.534 * g + 0.131 * b;
50
- }
51
- else {
52
- red = 255 - r;
53
- green = 255 - g;
54
- blue = 255 - b;
55
- }
56
- // CSS interpolates the color matrix before clamping the result.
57
- data[i] = r + (red - r) * amount;
58
- data[i + 1] = g + (green - g) * amount;
59
- data[i + 2] = b + (blue - b) * amount;
60
- }
61
- continue;
62
- }
63
- const filter = (_a = Konva.Filters) === null || _a === void 0 ? void 0 : _a[Util._capitalize(name)];
64
- if (!filter)
65
- continue;
66
- // Supply filter parameters without setters or changes to the node.
67
- const context = Object.create(this);
68
- context.attrs = { ...this.attrs };
69
- if (name === 'blur')
70
- context.attrs.blurRadius = value * 0.5;
71
- if (name === 'brightness')
72
- context.attrs.brightness = value;
73
- if (name === 'contrast')
74
- context.attrs.contrast = 100 * (Math.sqrt(value) - 1);
75
- filter.call(context, imageData, pixelRatio);
28
+ for (const { fallback, value } of steps) {
29
+ fallback(imageData, value, pixelRatio);
76
30
  }
77
31
  };
78
32
  }
33
+ // Fallbacks for CSS filter functions. Filter modules register theirs on
34
+ // import, so the core build carries none of their code.
35
+ const cssFilterFallbacks = {};
36
+ export function _registerCSSFilterFallback(name, fallback) {
37
+ cssFilterFallbacks[name] = fallback;
38
+ }
39
+ for (const name of ['grayscale', 'sepia', 'invert']) {
40
+ _registerCSSFilterFallback(name, (imageData, value) => {
41
+ const amount = Math.min(1, Math.max(0, value));
42
+ const data = imageData.data;
43
+ for (let i = 0; i < data.length; i += 4) {
44
+ const r = data[i], g = data[i + 1], b = data[i + 2];
45
+ let red, green, blue;
46
+ if (name === 'grayscale') {
47
+ red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
48
+ }
49
+ else if (name === 'sepia') {
50
+ red = 0.393 * r + 0.769 * g + 0.189 * b;
51
+ green = 0.349 * r + 0.686 * g + 0.168 * b;
52
+ blue = 0.272 * r + 0.534 * g + 0.131 * b;
53
+ }
54
+ else {
55
+ red = 255 - r;
56
+ green = 255 - g;
57
+ blue = 255 - b;
58
+ }
59
+ // CSS interpolates the color matrix before clamping the result.
60
+ data[i] = r + (red - r) * amount;
61
+ data[i + 1] = g + (green - g) * amount;
62
+ data[i + 2] = b + (blue - b) * amount;
63
+ }
64
+ });
65
+ }
79
66
  // CONSTANTS
80
67
  const ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransform', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', POINTERENTER = 'pointerenter', POINTERLEAVE = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', NON_BUBBLING_EVENTS = [
81
68
  MOUSEENTER,
@@ -498,13 +485,9 @@ export class Node {
498
485
  if (this._filterUpToDate) {
499
486
  return filterCanvas;
500
487
  }
501
- let useNativeOnly = true;
502
- for (let i = 0; i < filters.length; i++) {
503
- if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
504
- useNativeOnly = false;
505
- break;
506
- }
507
- }
488
+ // node-canvas has no ctx.filter, so CSS filter strings take the fallback
489
+ const useNativeOnly = 'filter' in filterContext._context &&
490
+ filters.every((filter) => typeof filter === 'string');
508
491
  const ratio = sceneCanvas.pixelRatio;
509
492
  filterCanvas.setSizeIfChanged(sceneCanvas._logicalWidth, sceneCanvas._logicalHeight);
510
493
  if (useNativeOnly) {
@@ -716,12 +699,17 @@ export class Node {
716
699
  _delegate(event, selector, handler) {
717
700
  const stopNode = this;
718
701
  this.on(event, function (evt) {
702
+ const original = evt;
719
703
  const targets = evt.target.findAncestors(selector, true, stopNode);
720
704
  for (let i = 0; i < targets.length; i++) {
721
705
  evt = Util.cloneObject(evt);
722
706
  evt.currentTarget = targets[i];
723
707
  handler.call(targets[i], evt);
724
708
  }
709
+ // handlers get copies, so pass a cancelled bubble back
710
+ if (evt.cancelBubble) {
711
+ original.cancelBubble = true;
712
+ }
725
713
  });
726
714
  return this;
727
715
  }
@@ -1873,17 +1861,27 @@ export class Node {
1873
1861
  */
1874
1862
  toBlob(config) {
1875
1863
  return new Promise((resolve, reject) => {
1864
+ const done = (blob) => {
1865
+ var _a;
1866
+ // the canvas reports a failed encode by passing null
1867
+ if (!blob) {
1868
+ reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1869
+ return;
1870
+ }
1871
+ resolve(blob);
1872
+ (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1873
+ };
1876
1874
  try {
1877
- this.toCanvas(config).toBlob((blob) => {
1878
- var _a;
1879
- // the canvas reports a failed encode by passing null
1880
- if (!blob) {
1881
- reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1882
- return;
1883
- }
1884
- resolve(blob);
1885
- (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1886
- }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1875
+ const canvas = this.toCanvas(config);
1876
+ // an OffscreenCanvas, as in a Web Worker, has no toBlob()
1877
+ if (canvas.convertToBlob) {
1878
+ canvas
1879
+ .convertToBlob({ type: config === null || config === void 0 ? void 0 : config.mimeType, quality: config === null || config === void 0 ? void 0 : config.quality })
1880
+ .then(done, reject);
1881
+ }
1882
+ else {
1883
+ canvas.toBlob(done, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1884
+ }
1887
1885
  }
1888
1886
  catch (err) {
1889
1887
  reject(err);
@@ -2126,7 +2124,8 @@ export class Node {
2126
2124
  }
2127
2125
  }
2128
2126
  _getProtoListeners(eventType) {
2129
- var _a, _b;
2127
+ var _a;
2128
+ var _b;
2130
2129
  const proto = Object.getPrototypeOf(this);
2131
2130
  let allListeners = Node.protoListenerMap.get(proto);
2132
2131
  if (!allListeners) {
@@ -2874,6 +2873,7 @@ addGetterSetter(Node, 'filters', undefined, function (val) {
2874
2873
  * get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
2875
2874
  * CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
2876
2875
  * CSS filters automatically fall back to function filters in unsupported browsers.
2876
+ * The fallback covers blur, brightness, contrast, grayscale, sepia and invert. A core build needs the Blur, Brightness and Contrast filters imported for the first three.
2877
2877
  * Blur radii, pixelation sizes and CSS lengths use node coordinates, independent of cache pixelRatio.
2878
2878
  * Custom filters receive (imageData, pixelRatio). ImageData contains full-resolution backing pixels.
2879
2879
  * @name Konva.Node#filters
@@ -1,4 +1,4 @@
1
- import { Konva } from "./Global.js";
1
+ import { Konva } from './Global.js';
2
2
  const Captures = new Map();
3
3
  // we may use this module for capturing touch events too
4
4
  // so make sure we don't do something super specific to pointer
package/lib/Shape.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Transform } from './Util.ts';
1
2
  import type { GetClientRectConfig, NodeConfig } from './Node.ts';
2
3
  import { Node } from './Node.ts';
3
4
  import type { Context } from './Context.ts';
@@ -111,6 +112,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
111
112
  _strokeFunc: (ctx: Context) => void;
112
113
  _fillFuncHit: (ctx: Context) => void;
113
114
  _strokeFuncHit: (ctx: Context) => void;
115
+ _styleTransform?: Transform;
114
116
  constructor(config?: Config);
115
117
  /**
116
118
  * @deprecated
@@ -130,8 +132,10 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
130
132
  */
131
133
  hasShadow(): any;
132
134
  _hasShadow(): boolean;
135
+ _toStyleSpace(point: Vector2d): Vector2d;
133
136
  _getFillPattern(): any;
134
- __getFillPattern(): CanvasPattern | null | undefined;
137
+ _createFillPattern(): CanvasPattern | null | undefined;
138
+ _setFillPatternTransform(pattern: CanvasPattern): CanvasPattern;
135
139
  _getLinearGradient(): any;
136
140
  __getLinearGradient(): CanvasGradient | undefined;
137
141
  _getRadialGradient(): any;