konva 10.9.1 → 10.11.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 (71) hide show
  1. package/README.md +22 -10
  2. package/konva.js +19184 -18924
  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 +5 -4
  7. package/lib/Context.d.ts +1 -2
  8. package/lib/Context.js +12 -39
  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 +3 -1
  19. package/lib/Node.js +105 -66
  20. package/lib/PointerEvents.js +1 -1
  21. package/lib/Shape.d.ts +8 -1
  22. package/lib/Shape.js +129 -32
  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 +123 -42
  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 +3 -3
  34. package/lib/filters/Brighten.js +3 -3
  35. package/lib/filters/Brightness.js +2 -2
  36. package/lib/filters/Contrast.js +3 -3
  37. package/lib/filters/Emboss.js +10 -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 +32 -30
  67. package/lib/shapes/TextPath.js +7 -7
  68. package/lib/shapes/Transformer.js +12 -11
  69. package/lib/shapes/Wedge.js +5 -5
  70. package/lib/skia-backend.js +17 -25
  71. 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, _parseSelector } 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
@@ -193,8 +193,9 @@ export class Container extends Node {
193
193
  }
194
194
  _generalFind(selector, findOne) {
195
195
  const retArr = [];
196
+ const match = _parseSelector(selector);
196
197
  this._descendants((node) => {
197
- const valid = node._isMatch(selector);
198
+ const valid = match(node);
198
199
  if (valid) {
199
200
  retArr.push(node);
200
201
  }
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
  }
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
@@ -681,26 +664,16 @@ export class SceneContext extends Context {
681
664
  }
682
665
  _getFillStyle(shape) {
683
666
  const color = shape.fill();
684
- const priority = shape.fillPriority();
685
- if (color && priority === 'color')
686
- return color;
687
- const pattern = shape.fillPatternImage();
688
- if (pattern && priority === 'pattern')
689
- return this._getFillPattern(shape);
690
- const linear = shape.fillLinearGradientColorStops();
691
- if (linear && priority === 'linear-gradient')
692
- return shape._getLinearGradient();
693
- const radial = shape.fillRadialGradientColorStops();
694
- if (radial && priority === 'radial-gradient')
695
- return shape._getRadialGradient();
696
- if (color)
697
- return color;
698
- if (pattern)
699
- return this._getFillPattern(shape);
700
- if (linear)
701
- return shape._getLinearGradient();
702
- if (radial)
703
- return shape._getRadialGradient();
667
+ switch (shape._getFillType(color)) {
668
+ case 'color':
669
+ return color;
670
+ case 'pattern':
671
+ return this._getFillPattern(shape);
672
+ case 'linear-gradient':
673
+ return shape._getLinearGradient();
674
+ case 'radial-gradient':
675
+ return shape._getRadialGradient();
676
+ }
704
677
  }
705
678
  _fill(shape) {
706
679
  const style = this._getFillStyle(shape);
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.1
2
+ * Konva JavaScript Framework v10.11.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.1',
32
+ version: '10.11.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
@@ -45,6 +45,8 @@ export type NodeConfig = {
45
45
  filters?: Filters;
46
46
  [string: string]: any;
47
47
  };
48
+ type SelectorMatch = (node: Node) => boolean;
49
+ export declare function _parseSelector(selector: string | Function): SelectorMatch;
48
50
  type NodeEventMap = GlobalEventHandlersEventMap & {
49
51
  [index: string]: any;
50
52
  };
@@ -598,7 +600,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
598
600
  * var group = node.findAncestors('.mygroup');
599
601
  */
600
602
  findAncestor(selector: string | Function, includeSelf?: boolean, stopNode?: Container): Node<NodeConfig>;
601
- _isMatch(selector: string | Function): any;
603
+ _isMatch(selector: string | Function): boolean;
602
604
  /**
603
605
  * get layer ancestor
604
606
  * @method
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 = [];
@@ -85,6 +84,56 @@ const ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransf
85
84
  'transformsEnabledChange.konva',
86
85
  ].join(SPACE);
87
86
  let idCounter = 1;
87
+ const WHITESPACE = /\s/;
88
+ const matchNothing = () => false;
89
+ // Turn a selector like "#id, .name, Rect" into a test for one node.
90
+ // find(), findAncestors() and delegated events test many nodes against the
91
+ // same selector, so they parse it once with this.
92
+ export function _parseSelector(selector) {
93
+ if (typeof selector === 'function') {
94
+ return selector;
95
+ }
96
+ if (!selector) {
97
+ return matchNothing;
98
+ }
99
+ const ids = [], names = [], types = [];
100
+ for (const sel of selector.replace(/ /g, '').split(',')) {
101
+ if (!Util.isValidSelector(sel)) {
102
+ Util.warn('Selector "' +
103
+ sel +
104
+ '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
105
+ Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
106
+ Util.warn('Konva is awesome, right?');
107
+ }
108
+ if (sel.charAt(0) === '#') {
109
+ ids.push(sel.slice(1));
110
+ }
111
+ else if (sel.charAt(0) === '.') {
112
+ names.push(sel.slice(1));
113
+ }
114
+ else {
115
+ types.push(sel);
116
+ }
117
+ }
118
+ // runs for every visited node: the length guards and the plain loop
119
+ // (instead of names.some()) measured ~40% faster on find('#id') and find('Rect')
120
+ return (node) => {
121
+ if (ids.length && ids.indexOf(node.id()) !== -1) {
122
+ return true;
123
+ }
124
+ if (types.length &&
125
+ (types.indexOf(node.className) !== -1 ||
126
+ types.indexOf(node.nodeType) !== -1)) {
127
+ return true;
128
+ }
129
+ for (let i = 0; i < names.length; i++) {
130
+ if (node.hasName(names[i])) {
131
+ return true;
132
+ }
133
+ }
134
+ return false;
135
+ };
136
+ }
88
137
  /**
89
138
  * Node constructor. Nodes are entities that can be transformed, layered,
90
139
  * and have bound events. The stage, layers, groups, and shapes all extend Node.
@@ -486,13 +535,9 @@ export class Node {
486
535
  if (this._filterUpToDate) {
487
536
  return filterCanvas;
488
537
  }
489
- let useNativeOnly = true;
490
- for (let i = 0; i < filters.length; i++) {
491
- if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
492
- useNativeOnly = false;
493
- break;
494
- }
495
- }
538
+ // node-canvas has no ctx.filter, so CSS filter strings take the fallback
539
+ const useNativeOnly = 'filter' in filterContext._context &&
540
+ filters.every((filter) => typeof filter === 'string');
496
541
  const ratio = sceneCanvas.pixelRatio;
497
542
  filterCanvas.setSizeIfChanged(sceneCanvas._logicalWidth, sceneCanvas._logicalHeight);
498
543
  if (useNativeOnly) {
@@ -703,9 +748,11 @@ export class Node {
703
748
  // like node.on
704
749
  _delegate(event, selector, handler) {
705
750
  const stopNode = this;
751
+ // parse once here, not on every event
752
+ const match = _parseSelector(selector);
706
753
  this.on(event, function (evt) {
707
754
  const original = evt;
708
- const targets = evt.target.findAncestors(selector, true, stopNode);
755
+ const targets = evt.target.findAncestors(match, true, stopNode);
709
756
  for (let i = 0; i < targets.length; i++) {
710
757
  evt = Util.cloneObject(evt);
711
758
  evt.currentTarget = targets[i];
@@ -1383,7 +1430,8 @@ export class Node {
1383
1430
  */
1384
1431
  findAncestors(selector, includeSelf, stopNode) {
1385
1432
  const res = [];
1386
- if (includeSelf && this._isMatch(selector)) {
1433
+ const match = _parseSelector(selector);
1434
+ if (includeSelf && match(this)) {
1387
1435
  res.push(this);
1388
1436
  }
1389
1437
  let ancestor = this.parent;
@@ -1391,7 +1439,7 @@ export class Node {
1391
1439
  if (ancestor === stopNode) {
1392
1440
  return res;
1393
1441
  }
1394
- if (ancestor._isMatch(selector)) {
1442
+ if (match(ancestor)) {
1395
1443
  res.push(ancestor);
1396
1444
  }
1397
1445
  ancestor = ancestor.parent;
@@ -1416,41 +1464,10 @@ export class Node {
1416
1464
  findAncestor(selector, includeSelf, stopNode) {
1417
1465
  return this.findAncestors(selector, includeSelf, stopNode)[0];
1418
1466
  }
1419
- // is current node match passed selector?
1467
+ // does this node match the selector? Konva itself uses _parseSelector to
1468
+ // parse once per call; this stays for code outside Konva that calls it
1420
1469
  _isMatch(selector) {
1421
- if (!selector) {
1422
- return false;
1423
- }
1424
- if (typeof selector === 'function') {
1425
- return selector(this);
1426
- }
1427
- let selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
1428
- for (n = 0; n < len; n++) {
1429
- sel = selectorArr[n];
1430
- if (!Util.isValidSelector(sel)) {
1431
- Util.warn('Selector "' +
1432
- sel +
1433
- '" is invalid. Allowed selectors examples are "#foo", ".bar" or "Group".');
1434
- Util.warn('If you have a custom shape with such className, please change it to start with upper letter like "Triangle".');
1435
- Util.warn('Konva is awesome, right?');
1436
- }
1437
- // id selector
1438
- if (sel.charAt(0) === '#') {
1439
- if (this.id() === sel.slice(1)) {
1440
- return true;
1441
- }
1442
- }
1443
- else if (sel.charAt(0) === '.') {
1444
- // name selector
1445
- if (this.hasName(sel.slice(1))) {
1446
- return true;
1447
- }
1448
- }
1449
- else if (this.className === sel || this.nodeType === sel) {
1450
- return true;
1451
- }
1452
- }
1453
- return false;
1470
+ return _parseSelector(selector)(this);
1454
1471
  }
1455
1472
  /**
1456
1473
  * get layer ancestor
@@ -1866,17 +1883,27 @@ export class Node {
1866
1883
  */
1867
1884
  toBlob(config) {
1868
1885
  return new Promise((resolve, reject) => {
1886
+ const done = (blob) => {
1887
+ var _a;
1888
+ // the canvas reports a failed encode by passing null
1889
+ if (!blob) {
1890
+ reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1891
+ return;
1892
+ }
1893
+ resolve(blob);
1894
+ (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1895
+ };
1869
1896
  try {
1870
- this.toCanvas(config).toBlob((blob) => {
1871
- var _a;
1872
- // the canvas reports a failed encode by passing null
1873
- if (!blob) {
1874
- reject(new Error('Konva: toBlob() failed, the canvas was not encoded'));
1875
- return;
1876
- }
1877
- resolve(blob);
1878
- (_a = config === null || config === void 0 ? void 0 : config.callback) === null || _a === void 0 ? void 0 : _a.call(config, blob);
1879
- }, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1897
+ const canvas = this.toCanvas(config);
1898
+ // an OffscreenCanvas, as in a Web Worker, has no toBlob()
1899
+ if (canvas.convertToBlob) {
1900
+ canvas
1901
+ .convertToBlob({ type: config === null || config === void 0 ? void 0 : config.mimeType, quality: config === null || config === void 0 ? void 0 : config.quality })
1902
+ .then(done, reject);
1903
+ }
1904
+ else {
1905
+ canvas.toBlob(done, config === null || config === void 0 ? void 0 : config.mimeType, config === null || config === void 0 ? void 0 : config.quality);
1906
+ }
1880
1907
  }
1881
1908
  catch (err) {
1882
1909
  reject(err);
@@ -1990,9 +2017,20 @@ export class Node {
1990
2017
  if (!fullName) {
1991
2018
  return false;
1992
2019
  }
1993
- // if name is '' the "names" will be [''], so I added extra check above
1994
- const names = (fullName || '').split(/\s/g);
1995
- return names.indexOf(name) !== -1;
2020
+ // find('.name') calls this for every node, so look for a whole
2021
+ // whitespace-separated word instead of splitting fullName into an array
2022
+ let i = fullName.indexOf(name);
2023
+ while (i !== -1) {
2024
+ const end = i + name.length;
2025
+ if ((i === 0 || WHITESPACE.test(fullName[i - 1])) &&
2026
+ (end === fullName.length || WHITESPACE.test(fullName[end]))) {
2027
+ // a word never contains whitespace; checked only on a hit so the
2028
+ // common miss in find('.name') stays cheap (~25% faster than up front)
2029
+ return !WHITESPACE.test(name);
2030
+ }
2031
+ i = fullName.indexOf(name, i + 1);
2032
+ }
2033
+ return false;
1996
2034
  }
1997
2035
  /**
1998
2036
  * remove name from node
@@ -2119,7 +2157,8 @@ export class Node {
2119
2157
  }
2120
2158
  }
2121
2159
  _getProtoListeners(eventType) {
2122
- var _a, _b;
2160
+ var _a;
2161
+ var _b;
2123
2162
  const proto = Object.getPrototypeOf(this);
2124
2163
  let allListeners = Node.protoListenerMap.get(proto);
2125
2164
  if (!allListeners) {
@@ -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
@@ -45,6 +45,9 @@ export type ShapeConfig = NodeConfig & {
45
45
  fillRadialGradientStartRadius?: number;
46
46
  fillRadialGradientEndRadius?: number;
47
47
  fillRadialGradientColorStops?: Array<number | string>;
48
+ fillRadialGradientScale?: Vector2d;
49
+ fillRadialGradientScaleX?: number;
50
+ fillRadialGradientScaleY?: number;
48
51
  fillEnabled?: boolean;
49
52
  fillPriority?: string;
50
53
  fillRule?: CanvasFillRule;
@@ -132,6 +135,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
132
135
  */
133
136
  hasShadow(): any;
134
137
  _hasShadow(): boolean;
138
+ _getFillType(color?: string | CanvasGradient): "color" | "linear-gradient" | "pattern" | "radial-gradient" | undefined;
135
139
  _toStyleSpace(point: Vector2d): Vector2d;
136
140
  _getFillPattern(): any;
137
141
  _createFillPattern(): CanvasPattern | null | undefined;
@@ -139,7 +143,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
139
143
  _getLinearGradient(): any;
140
144
  __getLinearGradient(): CanvasGradient | undefined;
141
145
  _getRadialGradient(): any;
142
- __getRadialGradient(): CanvasGradient | undefined;
146
+ __getRadialGradient(shrink?: number): CanvasGradient | undefined;
143
147
  getShadowRGBA(): any;
144
148
  _getShadowRGBA(): string | undefined;
145
149
  /**
@@ -235,6 +239,9 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
235
239
  fillRadialGradientEndPoint: GetSet<Vector2d, this>;
236
240
  fillRadialGradientEndPointX: GetSet<number, this>;
237
241
  fillRadialGradientEndPointY: GetSet<number, this>;
242
+ fillRadialGradientScale: GetSet<Vector2d, this>;
243
+ fillRadialGradientScaleX: GetSet<number, this>;
244
+ fillRadialGradientScaleY: GetSet<number, this>;
238
245
  fillPatternOffset: GetSet<Vector2d, this>;
239
246
  fillPatternOffsetX: GetSet<number, this>;
240
247
  fillPatternOffsetY: GetSet<number, this>;