konva 9.3.15 → 9.3.16
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/konva.js +726 -724
- package/konva.min.js +3 -3
- package/lib/Animation.js +1 -1
- package/lib/BezierFunctions.js +1 -2
- package/lib/Canvas.js +9 -9
- package/lib/Container.d.ts +1 -1
- package/lib/Container.js +29 -29
- package/lib/Context.d.ts +2 -2
- package/lib/Context.js +26 -26
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/DragAndDrop.js +6 -4
- package/lib/Factory.js +16 -16
- package/lib/Global.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Layer.js +17 -17
- package/lib/Node.d.ts +1 -1
- package/lib/Node.js +87 -87
- package/lib/PointerEvents.js +5 -6
- package/lib/Shape.js +31 -31
- package/lib/Stage.d.ts +2 -2
- package/lib/Stage.js +28 -28
- package/lib/Tween.js +21 -21
- package/lib/Util.d.ts +4 -4
- package/lib/Util.js +62 -62
- package/lib/Validators.js +16 -17
- package/lib/_CoreInternals.d.ts +8 -8
- package/lib/_FullInternals.d.ts +8 -8
- package/lib/filters/Blur.js +6 -6
- package/lib/filters/Brighten.js +1 -1
- package/lib/filters/Contrast.js +2 -2
- package/lib/filters/Emboss.js +19 -19
- package/lib/filters/Enhance.js +4 -4
- package/lib/filters/Grayscale.js +1 -1
- package/lib/filters/HSL.js +6 -6
- package/lib/filters/HSV.js +7 -7
- package/lib/filters/Invert.js +1 -1
- package/lib/filters/Kaleidoscope.js +20 -20
- package/lib/filters/Mask.js +57 -57
- package/lib/filters/Noise.js +2 -2
- package/lib/filters/Pixelate.js +1 -1
- package/lib/filters/Posterize.js +1 -1
- package/lib/filters/RGB.js +1 -1
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Sepia.js +1 -1
- package/lib/filters/Solarize.js +8 -7
- package/lib/filters/Threshold.js +2 -2
- package/lib/shapes/Arc.js +1 -1
- package/lib/shapes/Arrow.js +10 -10
- package/lib/shapes/Ellipse.js +1 -1
- package/lib/shapes/Image.js +3 -3
- package/lib/shapes/Label.d.ts +1 -1
- package/lib/shapes/Label.js +6 -6
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +14 -14
- package/lib/shapes/Path.js +62 -62
- package/lib/shapes/Rect.js +1 -1
- package/lib/shapes/RegularPolygon.js +6 -6
- package/lib/shapes/Ring.js +1 -1
- package/lib/shapes/Sprite.js +9 -9
- package/lib/shapes/Star.js +5 -5
- package/lib/shapes/Text.js +37 -37
- package/lib/shapes/TextPath.js +23 -23
- package/lib/shapes/Transformer.d.ts +1 -1
- package/lib/shapes/Transformer.js +63 -63
- package/package.json +2 -5
package/lib/shapes/Label.js
CHANGED
|
@@ -6,7 +6,7 @@ const Shape_1 = require("../Shape");
|
|
|
6
6
|
const Group_1 = require("../Group");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
8
|
const Global_1 = require("../Global");
|
|
9
|
-
|
|
9
|
+
const ATTR_CHANGE_LIST = [
|
|
10
10
|
'fontFamily',
|
|
11
11
|
'fontSize',
|
|
12
12
|
'fontStyle',
|
|
@@ -34,8 +34,8 @@ class Label extends Group_1.Group {
|
|
|
34
34
|
return this.find('Tag')[0];
|
|
35
35
|
}
|
|
36
36
|
_addListeners(text) {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let that = this, n;
|
|
38
|
+
const func = function () {
|
|
39
39
|
that._sync();
|
|
40
40
|
};
|
|
41
41
|
for (n = 0; n < attrChangeListLen; n++) {
|
|
@@ -49,7 +49,7 @@ class Label extends Group_1.Group {
|
|
|
49
49
|
return this.getText().height();
|
|
50
50
|
}
|
|
51
51
|
_sync() {
|
|
52
|
-
|
|
52
|
+
let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
|
|
53
53
|
if (text && tag) {
|
|
54
54
|
width = text.width();
|
|
55
55
|
height = text.height();
|
|
@@ -94,7 +94,7 @@ Label.prototype.className = 'Label';
|
|
|
94
94
|
(0, Global_1._registerNode)(Label);
|
|
95
95
|
class Tag extends Shape_1.Shape {
|
|
96
96
|
_sceneFunc(context) {
|
|
97
|
-
|
|
97
|
+
const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
|
98
98
|
let topLeft = 0;
|
|
99
99
|
let topRight = 0;
|
|
100
100
|
let bottomLeft = 0;
|
|
@@ -146,7 +146,7 @@ class Tag extends Shape_1.Shape {
|
|
|
146
146
|
context.fillStrokeShape(this);
|
|
147
147
|
}
|
|
148
148
|
getSelfRect() {
|
|
149
|
-
|
|
149
|
+
let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
|
150
150
|
if (direction === UP) {
|
|
151
151
|
y -= pointerHeight;
|
|
152
152
|
height += pointerHeight;
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Shape, ShapeConfig } from '../Shape.js';
|
|
2
|
-
import { GetSet } from '../types.js';
|
|
3
2
|
import { Context } from '../Context.js';
|
|
3
|
+
import { GetSet } from '../types.js';
|
|
4
4
|
export interface LineConfig extends ShapeConfig {
|
|
5
5
|
points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
6
6
|
tension?: number;
|
package/lib/shapes/Line.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Line = void 0;
|
|
4
4
|
const Factory_1 = require("../Factory");
|
|
5
|
+
const Global_1 = require("../Global");
|
|
5
6
|
const Shape_1 = require("../Shape");
|
|
6
7
|
const Validators_1 = require("../Validators");
|
|
7
|
-
const Global_1 = require("../Global");
|
|
8
8
|
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
9
|
-
|
|
9
|
+
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
10
10
|
return [p1x, p1y, p2x, p2y];
|
|
11
11
|
}
|
|
12
12
|
function expandPoints(p, tension) {
|
|
13
|
-
|
|
14
|
-
for (n = 2; n < len - 2; n += 2) {
|
|
15
|
-
cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
13
|
+
const len = p.length, allPoints = [];
|
|
14
|
+
for (let n = 2; n < len - 2; n += 2) {
|
|
15
|
+
const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
16
16
|
if (isNaN(cp[0])) {
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
@@ -33,7 +33,7 @@ class Line extends Shape_1.Shape {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
_sceneFunc(context) {
|
|
36
|
-
|
|
36
|
+
let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
|
|
37
37
|
if (!length) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -84,7 +84,7 @@ class Line extends Shape_1.Shape {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
_getTensionPointsClosed() {
|
|
87
|
-
|
|
87
|
+
const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
|
88
88
|
.concat(middle)
|
|
89
89
|
.concat([
|
|
90
90
|
lastControlPoints[0],
|
|
@@ -107,7 +107,7 @@ class Line extends Shape_1.Shape {
|
|
|
107
107
|
return this.getSelfRect().height;
|
|
108
108
|
}
|
|
109
109
|
getSelfRect() {
|
|
110
|
-
|
|
110
|
+
let points = this.points();
|
|
111
111
|
if (points.length < 4) {
|
|
112
112
|
return {
|
|
113
113
|
x: points[0] || 0,
|
|
@@ -128,12 +128,12 @@ class Line extends Shape_1.Shape {
|
|
|
128
128
|
else {
|
|
129
129
|
points = this.points();
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
for (
|
|
131
|
+
let minX = points[0];
|
|
132
|
+
let maxX = points[0];
|
|
133
|
+
let minY = points[1];
|
|
134
|
+
let maxY = points[1];
|
|
135
|
+
let x, y;
|
|
136
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
137
137
|
x = points[i * 2];
|
|
138
138
|
y = points[i * 2 + 1];
|
|
139
139
|
minX = Math.min(minX, x);
|
package/lib/shapes/Path.js
CHANGED
|
@@ -20,12 +20,12 @@ class Path extends Shape_1.Shape {
|
|
|
20
20
|
this.pathLength = Path.getPathLength(this.dataArray);
|
|
21
21
|
}
|
|
22
22
|
_sceneFunc(context) {
|
|
23
|
-
|
|
23
|
+
const ca = this.dataArray;
|
|
24
24
|
context.beginPath();
|
|
25
|
-
|
|
26
|
-
for (
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
let isClosed = false;
|
|
26
|
+
for (let n = 0; n < ca.length; n++) {
|
|
27
|
+
const c = ca[n].command;
|
|
28
|
+
const p = ca[n].points;
|
|
29
29
|
switch (c) {
|
|
30
30
|
case 'L':
|
|
31
31
|
context.lineTo(p[0], p[1]);
|
|
@@ -66,13 +66,13 @@ class Path extends Shape_1.Shape {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
getSelfRect() {
|
|
69
|
-
|
|
69
|
+
let points = [];
|
|
70
70
|
this.dataArray.forEach(function (data) {
|
|
71
71
|
if (data.command === 'A') {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const start = data.points[4];
|
|
73
|
+
const dTheta = data.points[5];
|
|
74
|
+
const end = data.points[4] + dTheta;
|
|
75
|
+
let inc = Math.PI / 180.0;
|
|
76
76
|
if (Math.abs(start - end) < inc) {
|
|
77
77
|
inc = Math.abs(start - end);
|
|
78
78
|
}
|
|
@@ -99,12 +99,12 @@ class Path extends Shape_1.Shape {
|
|
|
99
99
|
points = points.concat(data.points);
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for (
|
|
102
|
+
let minX = points[0];
|
|
103
|
+
let maxX = points[0];
|
|
104
|
+
let minY = points[1];
|
|
105
|
+
let maxY = points[1];
|
|
106
|
+
let x, y;
|
|
107
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
108
108
|
x = points[i * 2];
|
|
109
109
|
y = points[i * 2 + 1];
|
|
110
110
|
if (!isNaN(x)) {
|
|
@@ -134,13 +134,13 @@ class Path extends Shape_1.Shape {
|
|
|
134
134
|
}
|
|
135
135
|
static getPathLength(dataArray) {
|
|
136
136
|
let pathLength = 0;
|
|
137
|
-
for (
|
|
137
|
+
for (let i = 0; i < dataArray.length; ++i) {
|
|
138
138
|
pathLength += dataArray[i].pathLength;
|
|
139
139
|
}
|
|
140
140
|
return pathLength;
|
|
141
141
|
}
|
|
142
142
|
static getPointAtLengthOfDataArray(length, dataArray) {
|
|
143
|
-
|
|
143
|
+
let points, i = 0, ii = dataArray.length;
|
|
144
144
|
if (!ii) {
|
|
145
145
|
return null;
|
|
146
146
|
}
|
|
@@ -162,8 +162,8 @@ class Path extends Shape_1.Shape {
|
|
|
162
162
|
y: points[1],
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
const cp = dataArray[i];
|
|
166
|
+
const p = cp.points;
|
|
167
167
|
switch (cp.command) {
|
|
168
168
|
case 'L':
|
|
169
169
|
return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
|
|
@@ -220,8 +220,8 @@ class Path extends Shape_1.Shape {
|
|
|
220
220
|
function CB4(t) {
|
|
221
221
|
return (1 - t) * (1 - t) * (1 - t);
|
|
222
222
|
}
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
|
|
224
|
+
const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
|
|
225
225
|
return {
|
|
226
226
|
x: x,
|
|
227
227
|
y: y,
|
|
@@ -237,16 +237,16 @@ class Path extends Shape_1.Shape {
|
|
|
237
237
|
function QB3(t) {
|
|
238
238
|
return (1 - t) * (1 - t);
|
|
239
239
|
}
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
|
|
241
|
+
const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
|
|
242
242
|
return {
|
|
243
243
|
x: x,
|
|
244
244
|
y: y,
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
247
|
static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
|
|
249
|
+
const pt = {
|
|
250
250
|
x: rx * Math.cos(theta),
|
|
251
251
|
y: ry * Math.sin(theta),
|
|
252
252
|
};
|
|
@@ -259,8 +259,8 @@ class Path extends Shape_1.Shape {
|
|
|
259
259
|
if (!data) {
|
|
260
260
|
return [];
|
|
261
261
|
}
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
let cs = data;
|
|
263
|
+
const cc = [
|
|
264
264
|
'm',
|
|
265
265
|
'M',
|
|
266
266
|
'l',
|
|
@@ -286,28 +286,28 @@ class Path extends Shape_1.Shape {
|
|
|
286
286
|
for (var n = 0; n < cc.length; n++) {
|
|
287
287
|
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
|
288
288
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
289
|
+
const arr = cs.split('|');
|
|
290
|
+
const ca = [];
|
|
291
|
+
const coords = [];
|
|
292
|
+
let cpx = 0;
|
|
293
|
+
let cpy = 0;
|
|
294
|
+
const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
|
295
|
+
let match;
|
|
296
296
|
for (n = 1; n < arr.length; n++) {
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
let str = arr[n];
|
|
298
|
+
let c = str.charAt(0);
|
|
299
299
|
str = str.slice(1);
|
|
300
300
|
coords.length = 0;
|
|
301
301
|
while ((match = re.exec(str))) {
|
|
302
302
|
coords.push(match[0]);
|
|
303
303
|
}
|
|
304
|
-
|
|
305
|
-
for (
|
|
304
|
+
const p = [];
|
|
305
|
+
for (let j = 0, jlen = coords.length; j < jlen; j++) {
|
|
306
306
|
if (coords[j] === '00') {
|
|
307
307
|
p.push(0, 0);
|
|
308
308
|
continue;
|
|
309
309
|
}
|
|
310
|
-
|
|
310
|
+
const parsed = parseFloat(coords[j]);
|
|
311
311
|
if (!isNaN(parsed)) {
|
|
312
312
|
p.push(parsed);
|
|
313
313
|
}
|
|
@@ -319,9 +319,9 @@ class Path extends Shape_1.Shape {
|
|
|
319
319
|
if (isNaN(p[0])) {
|
|
320
320
|
break;
|
|
321
321
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
322
|
+
let cmd = '';
|
|
323
|
+
let points = [];
|
|
324
|
+
const startX = cpx, startY = cpy;
|
|
325
325
|
var prevCmd, ctlPtx, ctlPty;
|
|
326
326
|
var rx, ry, psi, fa, fs, x1, y1;
|
|
327
327
|
switch (c) {
|
|
@@ -343,7 +343,7 @@ class Path extends Shape_1.Shape {
|
|
|
343
343
|
cpy += dy;
|
|
344
344
|
cmd = 'M';
|
|
345
345
|
if (ca.length > 2 && ca[ca.length - 1].command === 'z') {
|
|
346
|
-
for (
|
|
346
|
+
for (let idx = ca.length - 2; idx >= 0; idx--) {
|
|
347
347
|
if (ca[idx].command === 'M') {
|
|
348
348
|
cpx = ca[idx].points[0] + dx;
|
|
349
349
|
cpy = ca[idx].points[1] + dy;
|
|
@@ -510,8 +510,8 @@ class Path extends Shape_1.Shape {
|
|
|
510
510
|
return ca;
|
|
511
511
|
}
|
|
512
512
|
static calcLength(x, y, cmd, points) {
|
|
513
|
-
|
|
514
|
-
|
|
513
|
+
let len, p1, p2, t;
|
|
514
|
+
const path = Path;
|
|
515
515
|
switch (cmd) {
|
|
516
516
|
case 'L':
|
|
517
517
|
return path.getLineLength(x, y, points[0], points[1]);
|
|
@@ -550,16 +550,16 @@ class Path extends Shape_1.Shape {
|
|
|
550
550
|
return 0;
|
|
551
551
|
}
|
|
552
552
|
static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
const psi = psiDeg * (Math.PI / 180.0);
|
|
554
|
+
const xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;
|
|
555
|
+
const yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +
|
|
556
556
|
(Math.cos(psi) * (y1 - y2)) / 2.0;
|
|
557
|
-
|
|
557
|
+
const lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
|
|
558
558
|
if (lambda > 1) {
|
|
559
559
|
rx *= Math.sqrt(lambda);
|
|
560
560
|
ry *= Math.sqrt(lambda);
|
|
561
561
|
}
|
|
562
|
-
|
|
562
|
+
let f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /
|
|
563
563
|
(rx * rx * (yp * yp) + ry * ry * (xp * xp)));
|
|
564
564
|
if (fa === fs) {
|
|
565
565
|
f *= -1;
|
|
@@ -567,23 +567,23 @@ class Path extends Shape_1.Shape {
|
|
|
567
567
|
if (isNaN(f)) {
|
|
568
568
|
f = 0;
|
|
569
569
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
570
|
+
const cxp = (f * rx * yp) / ry;
|
|
571
|
+
const cyp = (f * -ry * xp) / rx;
|
|
572
|
+
const cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
|
|
573
|
+
const cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
|
|
574
|
+
const vMag = function (v) {
|
|
575
575
|
return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
576
576
|
};
|
|
577
|
-
|
|
577
|
+
const vRatio = function (u, v) {
|
|
578
578
|
return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
|
|
579
579
|
};
|
|
580
|
-
|
|
580
|
+
const vAngle = function (u, v) {
|
|
581
581
|
return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
|
|
582
582
|
};
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
583
|
+
const theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
|
|
584
|
+
const u = [(xp - cxp) / rx, (yp - cyp) / ry];
|
|
585
|
+
const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
|
|
586
|
+
let dTheta = vAngle(u, v);
|
|
587
587
|
if (vRatio(u, v) <= -1) {
|
|
588
588
|
dTheta = Math.PI;
|
|
589
589
|
}
|
package/lib/shapes/Rect.js
CHANGED
|
@@ -8,7 +8,7 @@ const Util_1 = require("../Util");
|
|
|
8
8
|
const Validators_1 = require("../Validators");
|
|
9
9
|
class Rect extends Shape_1.Shape {
|
|
10
10
|
_sceneFunc(context) {
|
|
11
|
-
|
|
11
|
+
const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
12
12
|
context.beginPath();
|
|
13
13
|
if (!cornerRadius) {
|
|
14
14
|
context.rect(0, 0, width, height);
|
|
@@ -10,7 +10,7 @@ class RegularPolygon extends Shape_1.Shape {
|
|
|
10
10
|
const points = this._getPoints();
|
|
11
11
|
context.beginPath();
|
|
12
12
|
context.moveTo(points[0].x, points[0].y);
|
|
13
|
-
for (
|
|
13
|
+
for (let n = 1; n < points.length; n++) {
|
|
14
14
|
context.lineTo(points[n].x, points[n].y);
|
|
15
15
|
}
|
|
16
16
|
context.closePath();
|
|
@@ -20,7 +20,7 @@ class RegularPolygon extends Shape_1.Shape {
|
|
|
20
20
|
const sides = this.attrs.sides;
|
|
21
21
|
const radius = this.attrs.radius || 0;
|
|
22
22
|
const points = [];
|
|
23
|
-
for (
|
|
23
|
+
for (let n = 0; n < sides; n++) {
|
|
24
24
|
points.push({
|
|
25
25
|
x: radius * Math.sin((n * 2 * Math.PI) / sides),
|
|
26
26
|
y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
|
|
@@ -30,10 +30,10 @@ class RegularPolygon extends Shape_1.Shape {
|
|
|
30
30
|
}
|
|
31
31
|
getSelfRect() {
|
|
32
32
|
const points = this._getPoints();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
let minX = points[0].x;
|
|
34
|
+
let maxX = points[0].y;
|
|
35
|
+
let minY = points[0].x;
|
|
36
|
+
let maxY = points[0].y;
|
|
37
37
|
points.forEach((point) => {
|
|
38
38
|
minX = Math.min(minX, point.x);
|
|
39
39
|
maxX = Math.max(maxX, point.x);
|
package/lib/shapes/Ring.js
CHANGED
|
@@ -5,7 +5,7 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Shape_1 = require("../Shape");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const Global_1 = require("../Global");
|
|
8
|
-
|
|
8
|
+
const PIx2 = Math.PI * 2;
|
|
9
9
|
class Ring extends Shape_1.Shape {
|
|
10
10
|
_sceneFunc(context) {
|
|
11
11
|
context.beginPath();
|
package/lib/shapes/Sprite.js
CHANGED
|
@@ -11,7 +11,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
11
11
|
super(config);
|
|
12
12
|
this._updated = true;
|
|
13
13
|
this.anim = new Animation_1.Animation(() => {
|
|
14
|
-
|
|
14
|
+
const updated = this._updated;
|
|
15
15
|
this._updated = false;
|
|
16
16
|
return updated;
|
|
17
17
|
});
|
|
@@ -30,7 +30,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
_sceneFunc(context) {
|
|
33
|
-
|
|
33
|
+
const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image();
|
|
34
34
|
if (this.hasFill() || this.hasStroke()) {
|
|
35
35
|
context.beginPath();
|
|
36
36
|
context.rect(0, 0, width, height);
|
|
@@ -39,7 +39,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
39
39
|
}
|
|
40
40
|
if (image) {
|
|
41
41
|
if (offsets) {
|
|
42
|
-
|
|
42
|
+
const offset = offsets[anim], ix2 = index * 2;
|
|
43
43
|
context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -48,11 +48,11 @@ class Sprite extends Shape_1.Shape {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
_hitFunc(context) {
|
|
51
|
-
|
|
51
|
+
const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];
|
|
52
52
|
context.beginPath();
|
|
53
53
|
if (offsets) {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const offset = offsets[anim];
|
|
55
|
+
const ix2 = index * 2;
|
|
56
56
|
context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
@@ -65,7 +65,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
65
65
|
return super._useBufferCanvas(true);
|
|
66
66
|
}
|
|
67
67
|
_setInterval() {
|
|
68
|
-
|
|
68
|
+
const that = this;
|
|
69
69
|
this.interval = setInterval(function () {
|
|
70
70
|
that._updateIndex();
|
|
71
71
|
}, 1000 / this.frameRate());
|
|
@@ -74,7 +74,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
74
74
|
if (this.isRunning()) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const layer = this.getLayer();
|
|
78
78
|
this.anim.setLayers(layer);
|
|
79
79
|
this._setInterval();
|
|
80
80
|
this.anim.start();
|
|
@@ -87,7 +87,7 @@ class Sprite extends Shape_1.Shape {
|
|
|
87
87
|
return this.anim.isRunning();
|
|
88
88
|
}
|
|
89
89
|
_updateIndex() {
|
|
90
|
-
|
|
90
|
+
const index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;
|
|
91
91
|
if (index < len - 1) {
|
|
92
92
|
this.frameIndex(index + 1);
|
|
93
93
|
}
|
package/lib/shapes/Star.js
CHANGED
|
@@ -7,13 +7,13 @@ const Validators_1 = require("../Validators");
|
|
|
7
7
|
const Global_1 = require("../Global");
|
|
8
8
|
class Star extends Shape_1.Shape {
|
|
9
9
|
_sceneFunc(context) {
|
|
10
|
-
|
|
10
|
+
const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
|
|
11
11
|
context.beginPath();
|
|
12
12
|
context.moveTo(0, 0 - outerRadius);
|
|
13
|
-
for (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
for (let n = 1; n < numPoints * 2; n++) {
|
|
14
|
+
const radius = n % 2 === 0 ? outerRadius : innerRadius;
|
|
15
|
+
const x = radius * Math.sin((n * Math.PI) / numPoints);
|
|
16
|
+
const y = -1 * radius * Math.cos((n * Math.PI) / numPoints);
|
|
17
17
|
context.lineTo(x, y);
|
|
18
18
|
}
|
|
19
19
|
context.closePath();
|