konva 9.3.20 → 9.3.22

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.
@@ -16,7 +16,7 @@ export declare class Path extends Shape<PathConfig> {
16
16
  height: number;
17
17
  };
18
18
  getLength(): number;
19
- getPointAtLength(length: any): {
19
+ getPointAtLength(length: number): {
20
20
  x: number;
21
21
  y: number;
22
22
  } | null;
@@ -31,7 +31,7 @@ export declare class Path extends Shape<PathConfig> {
31
31
  x: number;
32
32
  y: number;
33
33
  };
34
- static getPointOnCubicBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any, P4x: any, P4y: any): {
34
+ static getPointOnCubicBezier(pct: number, P1x: number, P1y: number, P2x: number, P2y: number, P3x: number, P3y: number, P4x: number, P4y: number): {
35
35
  x: number;
36
36
  y: number;
37
37
  };
@@ -45,5 +45,5 @@ export declare class Path extends Shape<PathConfig> {
45
45
  };
46
46
  static parsePathData(data: any): PathSegment[];
47
47
  static calcLength(x: any, y: any, cmd: any, points: any): any;
48
- static convertEndpointToCenterParameterization(x1: any, y1: any, x2: any, y2: any, fa: any, fs: any, rx: any, ry: any, psiDeg: any): any[];
48
+ static convertEndpointToCenterParameterization(x1: number, y1: number, x2: number, y2: number, fa: number, fs: number, rx: number, ry: number, psiDeg: number): number[];
49
49
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Path = void 0;
4
4
  const Factory_1 = require("../Factory");
5
- const Shape_1 = require("../Shape");
6
5
  const Global_1 = require("../Global");
6
+ const Shape_1 = require("../Shape");
7
7
  const BezierFunctions_1 = require("../BezierFunctions");
8
8
  class Path extends Shape_1.Shape {
9
9
  constructor(config) {
@@ -40,10 +40,10 @@ class Path extends Shape_1.Shape {
40
40
  context.quadraticCurveTo(p[0], p[1], p[2], p[3]);
41
41
  break;
42
42
  case 'A':
43
- var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6], fs = p[7];
44
- var r = rx > ry ? rx : ry;
45
- var scaleX = rx > ry ? 1 : rx / ry;
46
- var scaleY = rx > ry ? ry / rx : 1;
43
+ const cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6], fs = p[7];
44
+ const r = rx > ry ? rx : ry;
45
+ const scaleX = rx > ry ? 1 : rx / ry;
46
+ const scaleY = rx > ry ? ry / rx : 1;
47
47
  context.translate(cx, cy);
48
48
  context.rotate(psi);
49
49
  context.scale(scaleX, scaleY);
@@ -156,11 +156,20 @@ class Path extends Shape_1.Shape {
156
156
  };
157
157
  }
158
158
  if (length < 0.01) {
159
- points = dataArray[i].points.slice(0, 2);
160
- return {
161
- x: points[0],
162
- y: points[1],
163
- };
159
+ const cmd = dataArray[i].command;
160
+ if (cmd === 'M') {
161
+ points = dataArray[i].points.slice(0, 2);
162
+ return {
163
+ x: points[0],
164
+ y: points[1],
165
+ };
166
+ }
167
+ else {
168
+ return {
169
+ x: dataArray[i].start.x,
170
+ y: dataArray[i].start.y,
171
+ };
172
+ }
164
173
  }
165
174
  const cp = dataArray[i];
166
175
  const p = cp.points;
@@ -176,7 +185,8 @@ class Path extends Shape_1.Shape {
176
185
  return (0, BezierFunctions_1.getQuadraticArcLength)([cp.start.x, p[0], p[2]], [cp.start.y, p[1], p[3]], i);
177
186
  }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
178
187
  case 'A':
179
- var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6];
188
+ const cx = p[0], cy = p[1], rx = p[2], ry = p[3], dTheta = p[5], psi = p[6];
189
+ let theta = p[4];
180
190
  theta += (dTheta * length) / cp.pathLength;
181
191
  return Path.getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi);
182
192
  }
@@ -222,10 +232,7 @@ class Path extends Shape_1.Shape {
222
232
  }
223
233
  const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
224
234
  const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
225
- return {
226
- x: x,
227
- y: y,
228
- };
235
+ return { x, y };
229
236
  }
230
237
  static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
231
238
  function QB1(t) {
@@ -239,10 +246,7 @@ class Path extends Shape_1.Shape {
239
246
  }
240
247
  const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
241
248
  const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
242
- return {
243
- x: x,
244
- y: y,
245
- };
249
+ return { x, y };
246
250
  }
247
251
  static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
248
252
  const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
@@ -283,7 +287,7 @@ class Path extends Shape_1.Shape {
283
287
  'A',
284
288
  ];
285
289
  cs = cs.replace(new RegExp(' ', 'g'), ',');
286
- for (var n = 0; n < cc.length; n++) {
290
+ for (let n = 0; n < cc.length; n++) {
287
291
  cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
288
292
  }
289
293
  const arr = cs.split('|');
@@ -293,7 +297,7 @@ class Path extends Shape_1.Shape {
293
297
  let cpy = 0;
294
298
  const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
295
299
  let match;
296
- for (n = 1; n < arr.length; n++) {
300
+ for (let n = 1; n < arr.length; n++) {
297
301
  let str = arr[n];
298
302
  let c = str.charAt(0);
299
303
  str = str.slice(1);
@@ -322,8 +326,8 @@ class Path extends Shape_1.Shape {
322
326
  let cmd = '';
323
327
  let points = [];
324
328
  const startX = cpx, startY = cpy;
325
- var prevCmd, ctlPtx, ctlPty;
326
- var rx, ry, psi, fa, fs, x1, y1;
329
+ let prevCmd, ctlPtx, ctlPty;
330
+ let rx, ry, psi, fa, fs, x1, y1;
327
331
  switch (c) {
328
332
  case 'l':
329
333
  cpx += p.shift();
@@ -337,8 +341,8 @@ class Path extends Shape_1.Shape {
337
341
  points.push(cpx, cpy);
338
342
  break;
339
343
  case 'm':
340
- var dx = p.shift();
341
- var dy = p.shift();
344
+ const dx = p.shift();
345
+ const dy = p.shift();
342
346
  cpx += dx;
343
347
  cpy += dy;
344
348
  cmd = 'M';
@@ -521,10 +525,10 @@ class Path extends Shape_1.Shape {
521
525
  return (0, BezierFunctions_1.getQuadraticArcLength)([x, points[0], points[2]], [y, points[1], points[3]], 1);
522
526
  case 'A':
523
527
  len = 0.0;
524
- var start = points[4];
525
- var dTheta = points[5];
526
- var end = points[4] + dTheta;
527
- var inc = Math.PI / 180.0;
528
+ const start = points[4];
529
+ const dTheta = points[5];
530
+ const end = points[4] + dTheta;
531
+ let inc = Math.PI / 180.0;
528
532
  if (Math.abs(start - end) < inc) {
529
533
  inc = Math.abs(start - end);
530
534
  }
@@ -113,8 +113,6 @@ class Text extends Shape_1.Shape {
113
113
  (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
114
114
  lineHeightPx / 2;
115
115
  }
116
- var lineTranslateX = 0;
117
- var lineTranslateY = 0;
118
116
  if (direction === RTL) {
119
117
  context.setAttr('direction', direction);
120
118
  }
@@ -129,9 +127,9 @@ class Text extends Shape_1.Shape {
129
127
  }
130
128
  context.translate(padding, alignY + padding);
131
129
  for (n = 0; n < textArrLen; n++) {
132
- var lineTranslateX = 0;
133
- var lineTranslateY = 0;
134
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
130
+ let lineTranslateX = 0;
131
+ let lineTranslateY = 0;
132
+ const obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph;
135
133
  context.save();
136
134
  if (align === RIGHT) {
137
135
  lineTranslateX += totalWidth - width - padding * 2;
@@ -148,10 +146,7 @@ class Text extends Shape_1.Shape {
148
146
  const x = lineTranslateX;
149
147
  const y = translateY + lineTranslateY + yOffset;
150
148
  context.moveTo(x, y);
151
- spacesNumber = text.split(' ').length - 1;
152
- oneWord = spacesNumber === 0;
153
- lineWidth =
154
- align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
149
+ const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
155
150
  context.lineTo(x + Math.round(lineWidth), y);
156
151
  context.lineWidth = fontSize / 15;
157
152
  const gradient = this._getLinearGradient();
@@ -164,10 +159,7 @@ class Text extends Shape_1.Shape {
164
159
  context.beginPath();
165
160
  const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;
166
161
  context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
167
- spacesNumber = text.split(' ').length - 1;
168
- oneWord = spacesNumber === 0;
169
- lineWidth =
170
- align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
162
+ const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
171
163
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
172
164
  context.lineWidth = fontSize / 15;
173
165
  const gradient = this._getLinearGradient();
@@ -176,7 +168,7 @@ class Text extends Shape_1.Shape {
176
168
  context.restore();
177
169
  }
178
170
  if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
179
- spacesNumber = text.split(' ').length - 1;
171
+ const spacesNumber = text.split(' ').length - 1;
180
172
  const array = stringToArray(text);
181
173
  for (let li = 0; li < array.length; li++) {
182
174
  const letter = array[li];
@@ -522,10 +522,10 @@ class Transformer extends Group_1.Group {
522
522
  else {
523
523
  keepProportion = this.keepRatio() || e.shiftKey;
524
524
  }
525
- var centeredScaling = this.centeredScaling() || e.altKey;
525
+ let centeredScaling = this.centeredScaling() || e.altKey;
526
526
  if (this._movingAnchorName === 'top-left') {
527
527
  if (keepProportion) {
528
- var comparePoint = centeredScaling
528
+ const comparePoint = centeredScaling
529
529
  ? {
530
530
  x: this.width() / 2,
531
531
  y: this.height() / 2,
@@ -536,8 +536,8 @@ class Transformer extends Group_1.Group {
536
536
  };
537
537
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
538
538
  Math.pow(comparePoint.y - anchorNode.y(), 2));
539
- var reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
540
- var reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
539
+ const reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
540
+ const reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
541
541
  x = newHypotenuse * this.cos * reverseX;
542
542
  y = newHypotenuse * this.sin * reverseY;
543
543
  this.findOne('.top-left').x(comparePoint.x - x);
@@ -549,7 +549,7 @@ class Transformer extends Group_1.Group {
549
549
  }
550
550
  else if (this._movingAnchorName === 'top-right') {
551
551
  if (keepProportion) {
552
- var comparePoint = centeredScaling
552
+ const comparePoint = centeredScaling
553
553
  ? {
554
554
  x: this.width() / 2,
555
555
  y: this.height() / 2,
@@ -560,8 +560,8 @@ class Transformer extends Group_1.Group {
560
560
  };
561
561
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
562
562
  Math.pow(comparePoint.y - anchorNode.y(), 2));
563
- var reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
564
- var reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
563
+ const reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
564
+ const reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
565
565
  x = newHypotenuse * this.cos * reverseX;
566
566
  y = newHypotenuse * this.sin * reverseY;
567
567
  this.findOne('.top-right').x(comparePoint.x + x);
@@ -579,7 +579,7 @@ class Transformer extends Group_1.Group {
579
579
  }
580
580
  else if (this._movingAnchorName === 'bottom-left') {
581
581
  if (keepProportion) {
582
- var comparePoint = centeredScaling
582
+ const comparePoint = centeredScaling
583
583
  ? {
584
584
  x: this.width() / 2,
585
585
  y: this.height() / 2,
@@ -590,8 +590,8 @@ class Transformer extends Group_1.Group {
590
590
  };
591
591
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
592
592
  Math.pow(anchorNode.y() - comparePoint.y, 2));
593
- var reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
594
- var reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
593
+ const reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
594
+ const reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
595
595
  x = newHypotenuse * this.cos * reverseX;
596
596
  y = newHypotenuse * this.sin * reverseY;
597
597
  anchorNode.x(comparePoint.x - x);
@@ -606,7 +606,7 @@ class Transformer extends Group_1.Group {
606
606
  }
607
607
  else if (this._movingAnchorName === 'bottom-right') {
608
608
  if (keepProportion) {
609
- var comparePoint = centeredScaling
609
+ const comparePoint = centeredScaling
610
610
  ? {
611
611
  x: this.width() / 2,
612
612
  y: this.height() / 2,
@@ -617,8 +617,8 @@ class Transformer extends Group_1.Group {
617
617
  };
618
618
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
619
619
  Math.pow(anchorNode.y() - comparePoint.y, 2));
620
- var reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
621
- var reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
620
+ const reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
621
+ const reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
622
622
  x = newHypotenuse * this.cos * reverseX;
623
623
  y = newHypotenuse * this.sin * reverseY;
624
624
  this.findOne('.bottom-right').x(comparePoint.x + x);
@@ -629,7 +629,7 @@ class Transformer extends Group_1.Group {
629
629
  console.error(new Error('Wrong position argument of selection resizer: ' +
630
630
  this._movingAnchorName));
631
631
  }
632
- var centeredScaling = this.centeredScaling() || e.altKey;
632
+ centeredScaling = this.centeredScaling() || e.altKey;
633
633
  if (centeredScaling) {
634
634
  const topLeft = this.findOne('.top-left');
635
635
  const bottomRight = this.findOne('.bottom-right');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "9.3.20",
3
+ "version": "9.3.22",
4
4
  "description": "HTML5 2d canvas library.",
5
5
  "author": "Anton Lavrenov",
6
6
  "files": [
@@ -22,7 +22,8 @@
22
22
  "test:build": "PARCEL_WORKER_BACKEND=process parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
23
23
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security -a no-sandbox -a disable-setuid-sandbox",
24
24
  "test:watch": "rm -rf ./.parcel-cache && PARCEL_WORKERS=0 parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
25
- "test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
25
+ "test:node:compiled": "rm -rf ./.test-temp && mkdir ./.test-temp && (tsc -p ./test/tsconfig.json --outDir ./.test-temp || true) && mocha './.test-temp/test/unit/**/*.js' -r ./test/node-global-setup.mjs --exit && rm -rf ./.test-temp && npm run test:import",
26
+ "test:node": "npm run test:node:compiled",
26
27
  "tsc": "tsc --removeComments",
27
28
  "rollup": "rollup -c --bundleConfigAsCjs",
28
29
  "clean": "rm -rf ./lib && rm -rf ./types && rm -rf ./cmj && rm -rf ./test-build",