konva 9.0.2 → 9.2.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.
package/lib/Animation.js CHANGED
@@ -139,7 +139,7 @@ class Animation {
139
139
  }
140
140
  }
141
141
  }
142
+ exports.Animation = Animation;
142
143
  Animation.animations = [];
143
144
  Animation.animIdCounter = 0;
144
145
  Animation.animRunning = false;
145
- exports.Animation = Animation;
@@ -2,9 +2,10 @@ import { Node, NodeConfig } from './Node.js';
2
2
  import { GetSet, IRect } from './types.js';
3
3
  import { HitCanvas, SceneCanvas } from './Canvas.js';
4
4
  import { SceneContext } from './Context.js';
5
+ export type ClipFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
5
6
  export interface ContainerConfig extends NodeConfig {
6
7
  clearBeforeDraw?: boolean;
7
- clipFunc?: (ctx: SceneContext) => void;
8
+ clipFunc?: (ctx: SceneContext) => ClipFuncOutput;
8
9
  clipX?: number;
9
10
  clipY?: number;
10
11
  clipWidth?: number;
@@ -43,5 +44,5 @@ export declare abstract class Container<ChildType extends Node = Node> extends N
43
44
  clipY: GetSet<number, this>;
44
45
  clipWidth: GetSet<number, this>;
45
46
  clipHeight: GetSet<number, this>;
46
- clipFunc: GetSet<(ctx: CanvasRenderingContext2D, shape: Container<ChildType>) => void, this>;
47
+ clipFunc: GetSet<(ctx: CanvasRenderingContext2D, shape: Container<ChildType>) => ClipFuncOutput, this>;
47
48
  }
package/lib/Container.js CHANGED
@@ -213,15 +213,16 @@ class Container extends Node_1.Node {
213
213
  var m = transform.getMatrix();
214
214
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
215
215
  context.beginPath();
216
+ let clipArgs;
216
217
  if (clipFunc) {
217
- clipFunc.call(this, context, this);
218
+ clipArgs = clipFunc.call(this, context, this);
218
219
  }
219
220
  else {
220
221
  var clipX = this.clipX();
221
222
  var clipY = this.clipY();
222
223
  context.rect(clipX, clipY, clipWidth, clipHeight);
223
224
  }
224
- context.clip();
225
+ context.clip.apply(context, clipArgs);
225
226
  m = transform.copy().invert().getMatrix();
226
227
  context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
227
228
  }
package/lib/Context.d.ts CHANGED
@@ -28,7 +28,8 @@ export declare class Context {
28
28
  beginPath(): void;
29
29
  bezierCurveTo(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
30
30
  clearRect(a0: number, a1: number, a2: number, a3: number): void;
31
- clip(): void;
31
+ clip(fillRule?: CanvasFillRule): void;
32
+ clip(path: Path2D, fillRule?: CanvasFillRule): void;
32
33
  closePath(): void;
33
34
  createImageData(a0: any, a1: any): ImageData;
34
35
  createLinearGradient(a0: number, a1: number, a2: number, a3: number): CanvasGradient;
@@ -37,7 +38,8 @@ export declare class Context {
37
38
  drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
38
39
  ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
39
40
  isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
40
- fill(path2d?: Path2D): void;
41
+ fill(fillRule?: CanvasFillRule): void;
42
+ fill(path: Path2D, fillRule?: CanvasFillRule): void;
41
43
  fillRect(x: number, y: number, width: number, height: number): void;
42
44
  strokeRect(x: number, y: number, width: number, height: number): void;
43
45
  fillText(text: string, x: number, y: number, maxWidth?: number): void;
@@ -62,7 +64,7 @@ export declare class Context {
62
64
  _enableTrace(): void;
63
65
  _applyGlobalCompositeOperation(node: any): void;
64
66
  }
65
- type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
67
+ type CanvasContextProps = Pick<CanvasRenderingContext2D, (typeof CONTEXT_PROPERTIES)[number]>;
66
68
  export interface Context extends CanvasContextProps {
67
69
  }
68
70
  export declare class SceneContext extends Context {
package/lib/Context.js CHANGED
@@ -198,8 +198,8 @@ class Context {
198
198
  clearRect(a0, a1, a2, a3) {
199
199
  this._context.clearRect(a0, a1, a2, a3);
200
200
  }
201
- clip() {
202
- this._context.clip();
201
+ clip(...args) {
202
+ this._context.clip.apply(this._context, args);
203
203
  }
204
204
  closePath() {
205
205
  this._context.closePath();
@@ -243,13 +243,8 @@ class Context {
243
243
  }
244
244
  return this._context.isPointInPath(x, y, fillRule);
245
245
  }
246
- fill(path2d) {
247
- if (path2d) {
248
- this._context.fill(path2d);
249
- }
250
- else {
251
- this._context.fill();
252
- }
246
+ fill(...args) {
247
+ this._context.fill.apply(this._context, args);
253
248
  }
254
249
  fillRect(x, y, width, height) {
255
250
  this._context.fillRect(x, y, width, height);
package/lib/Global.js CHANGED
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
16
16
  : {};
17
17
  exports.Konva = {
18
18
  _global: exports.glob,
19
- version: '9.0.2',
19
+ version: '9.2.0',
20
20
  isBrowser: detectBrowser(),
21
21
  isUnminified: /param/.test(function (param) { }.toString()),
22
22
  dblClickWindow: 400,
package/lib/Shape.d.ts CHANGED
@@ -38,6 +38,7 @@ export interface ShapeConfig extends NodeConfig {
38
38
  fillRadialGradientColorStops?: Array<number | string>;
39
39
  fillEnabled?: boolean;
40
40
  fillPriority?: string;
41
+ fillRule?: CanvasFillRule;
41
42
  stroke?: string | CanvasGradient;
42
43
  strokeWidth?: number;
43
44
  fillAfterStrokeEnabled?: boolean;
@@ -68,13 +69,14 @@ export interface ShapeGetClientRectConfig {
68
69
  skipStroke?: boolean;
69
70
  relativeTo?: Node;
70
71
  }
72
+ export type FillFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
71
73
  export declare const shapes: {
72
74
  [key: string]: Shape;
73
75
  };
74
76
  export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Node<Config> {
75
77
  _centroid: boolean;
76
78
  colorKey: string;
77
- _fillFunc: (ctx: Context) => void;
79
+ _fillFunc: (ctx: Context) => FillFuncOutput;
78
80
  _strokeFunc: (ctx: Context) => void;
79
81
  _fillFuncHit: (ctx: Context) => void;
80
82
  _strokeFuncHit: (ctx: Context) => void;
package/lib/Shape.js CHANGED
@@ -23,7 +23,13 @@ function getDummyContext() {
23
23
  }
24
24
  exports.shapes = {};
25
25
  function _fillFunc(context) {
26
- context.fill();
26
+ const fillRule = this.attrs.fillRule;
27
+ if (fillRule) {
28
+ context.fill(fillRule);
29
+ }
30
+ else {
31
+ context.fill();
32
+ }
27
33
  }
28
34
  function _strokeFunc(context) {
29
35
  context.stroke();
@@ -508,6 +514,7 @@ Factory_1.Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientEndPoint',
508
514
  Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointX', 0);
509
515
  Factory_1.Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointY', 0);
510
516
  Factory_1.Factory.addGetterSetter(Shape, 'fillPatternRotation', 0);
517
+ Factory_1.Factory.addGetterSetter(Shape, 'fillRule', undefined, (0, Validators_1.getStringValidator)());
511
518
  Factory_1.Factory.backCompat(Shape, {
512
519
  dashArray: 'dash',
513
520
  getDashArray: 'getDash',
package/lib/Tween.js CHANGED
@@ -358,9 +358,9 @@ class Tween {
358
358
  delete Tween.attrs[nodeId][thisId];
359
359
  }
360
360
  }
361
+ exports.Tween = Tween;
361
362
  Tween.attrs = {};
362
363
  Tween.tweens = {};
363
- exports.Tween = Tween;
364
364
  Node_1.Node.prototype.to = function (params) {
365
365
  var onFinish = params.onFinish;
366
366
  params.node = this;
@@ -113,6 +113,7 @@ export declare class Transformer extends Group {
113
113
  ignoreStroke: GetSet<boolean, this>;
114
114
  boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
115
115
  anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
116
+ anchorStyleFunc: GetSet<null | ((Node: Rect) => void), this>;
116
117
  shouldOverdrawWholeArea: GetSet<boolean, this>;
117
118
  useSingleNodeRotation: GetSet<boolean, this>;
118
119
  }
@@ -26,6 +26,7 @@ var ATTR_CHANGE_LIST = [
26
26
  'anchorFillChange',
27
27
  'anchorCornerRadiusChange',
28
28
  'ignoreStrokeChange',
29
+ 'anchorStyleFuncChange',
29
30
  ]
30
31
  .map((e) => e + `.${EVENTS_NAME}`)
31
32
  .join(' ');
@@ -811,7 +812,8 @@ class Transformer extends Group_1.Group {
811
812
  var resizeEnabled = this.resizeEnabled();
812
813
  var padding = this.padding();
813
814
  var anchorSize = this.anchorSize();
814
- this.find('._anchor').forEach((node) => {
815
+ const anchors = this.find('._anchor');
816
+ anchors.forEach((node) => {
815
817
  node.setAttrs({
816
818
  width: anchorSize,
817
819
  height: anchorSize,
@@ -890,6 +892,12 @@ class Transformer extends Group_1.Group {
890
892
  x: 0,
891
893
  y: 0,
892
894
  });
895
+ const styleFunc = this.anchorStyleFunc();
896
+ if (styleFunc) {
897
+ anchors.forEach((node) => {
898
+ styleFunc(node);
899
+ });
900
+ }
893
901
  (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
894
902
  }
895
903
  isTransforming() {
@@ -973,6 +981,7 @@ Factory_1.Factory.addGetterSetter(Transformer, 'node');
973
981
  Factory_1.Factory.addGetterSetter(Transformer, 'nodes');
974
982
  Factory_1.Factory.addGetterSetter(Transformer, 'boundBoxFunc');
975
983
  Factory_1.Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
984
+ Factory_1.Factory.addGetterSetter(Transformer, 'anchorStyleFunc');
976
985
  Factory_1.Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
977
986
  Factory_1.Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
978
987
  Factory_1.Factory.backCompat(Transformer, {
package/lib/types.js CHANGED
@@ -22,4 +22,4 @@ var KonvaNodeEvent;
22
22
  KonvaNodeEvent["dragstart"] = "dragstart";
23
23
  KonvaNodeEvent["dragmove"] = "dragmove";
24
24
  KonvaNodeEvent["dragend"] = "dragend";
25
- })(KonvaNodeEvent = exports.KonvaNodeEvent || (exports.KonvaNodeEvent = {}));
25
+ })(KonvaNodeEvent || (exports.KonvaNodeEvent = KonvaNodeEvent = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.0.2",
3
+ "version": "9.2.0",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -20,8 +20,8 @@
20
20
  "test": "npm run test:browser && npm run test:node",
21
21
  "test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
22
22
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
23
- "test:node": "ts-mocha -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
24
- "test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html",
23
+ "test:watch": "rm -rf ./.parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
24
+ "test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
25
25
  "tsc": "tsc --removeComments",
26
26
  "rollup": "rollup -c --bundleConfigAsCjs",
27
27
  "clean": "rm -rf ./lib && rm -rf ./types && rm -rf ./cmj && rm -rf ./test-build",