konva 8.1.4
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/CHANGELOG.md +1140 -0
- package/LICENSE +22 -0
- package/README.md +189 -0
- package/konva.js +18090 -0
- package/konva.min.js +12 -0
- package/lib/Animation.d.ts +24 -0
- package/lib/Animation.js +141 -0
- package/lib/Canvas.d.ts +32 -0
- package/lib/Canvas.js +107 -0
- package/lib/Container.d.ts +47 -0
- package/lib/Container.js +318 -0
- package/lib/Context.d.ts +76 -0
- package/lib/Context.js +520 -0
- package/lib/Core.d.ts +3 -0
- package/lib/Core.js +3 -0
- package/lib/DragAndDrop.d.ts +17 -0
- package/lib/DragAndDrop.js +104 -0
- package/lib/Factory.d.ts +11 -0
- package/lib/Factory.js +117 -0
- package/lib/FastLayer.d.ts +4 -0
- package/lib/FastLayer.js +12 -0
- package/lib/Global.d.ts +30 -0
- package/lib/Global.js +53 -0
- package/lib/Group.d.ts +6 -0
- package/lib/Group.js +13 -0
- package/lib/Layer.d.ts +60 -0
- package/lib/Layer.js +301 -0
- package/lib/Node.d.ts +318 -0
- package/lib/Node.js +1381 -0
- package/lib/PointerEvents.d.ts +11 -0
- package/lib/PointerEvents.js +37 -0
- package/lib/Shape.d.ts +184 -0
- package/lib/Shape.js +515 -0
- package/lib/Stage.d.ts +85 -0
- package/lib/Stage.js +687 -0
- package/lib/Tween.d.ts +86 -0
- package/lib/Tween.js +516 -0
- package/lib/Util.d.ts +87 -0
- package/lib/Util.js +742 -0
- package/lib/Validators.d.ts +11 -0
- package/lib/Validators.js +171 -0
- package/lib/_CoreInternals.d.ts +144 -0
- package/lib/_CoreInternals.js +34 -0
- package/lib/_FullInternals.d.ts +188 -0
- package/lib/_FullInternals.js +78 -0
- package/lib/filters/Blur.d.ts +2 -0
- package/lib/filters/Blur.js +697 -0
- package/lib/filters/Brighten.d.ts +2 -0
- package/lib/filters/Brighten.js +12 -0
- package/lib/filters/Contrast.d.ts +2 -0
- package/lib/filters/Contrast.js +34 -0
- package/lib/filters/Emboss.d.ts +2 -0
- package/lib/filters/Emboss.js +102 -0
- package/lib/filters/Enhance.d.ts +2 -0
- package/lib/filters/Enhance.js +83 -0
- package/lib/filters/Grayscale.d.ts +2 -0
- package/lib/filters/Grayscale.js +9 -0
- package/lib/filters/HSL.d.ts +2 -0
- package/lib/filters/HSL.js +24 -0
- package/lib/filters/HSV.d.ts +2 -0
- package/lib/filters/HSV.js +24 -0
- package/lib/filters/Invert.d.ts +2 -0
- package/lib/filters/Invert.js +8 -0
- package/lib/filters/Kaleidoscope.d.ts +2 -0
- package/lib/filters/Kaleidoscope.js +132 -0
- package/lib/filters/Mask.d.ts +2 -0
- package/lib/filters/Mask.js +140 -0
- package/lib/filters/Noise.d.ts +2 -0
- package/lib/filters/Noise.js +12 -0
- package/lib/filters/Pixelate.d.ts +2 -0
- package/lib/filters/Pixelate.js +60 -0
- package/lib/filters/Posterize.d.ts +2 -0
- package/lib/filters/Posterize.js +10 -0
- package/lib/filters/RGB.d.ts +2 -0
- package/lib/filters/RGB.js +39 -0
- package/lib/filters/RGBA.d.ts +2 -0
- package/lib/filters/RGBA.js +49 -0
- package/lib/filters/Sepia.d.ts +2 -0
- package/lib/filters/Sepia.js +11 -0
- package/lib/filters/Solarize.d.ts +2 -0
- package/lib/filters/Solarize.js +25 -0
- package/lib/filters/Threshold.d.ts +2 -0
- package/lib/filters/Threshold.js +10 -0
- package/lib/index-node.d.ts +2 -0
- package/lib/index-node.js +18 -0
- package/lib/index-types.d.ts +179 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/shapes/Arc.d.ts +19 -0
- package/lib/shapes/Arc.js +35 -0
- package/lib/shapes/Arrow.d.ts +24 -0
- package/lib/shapes/Arrow.js +94 -0
- package/lib/shapes/Circle.d.ts +13 -0
- package/lib/shapes/Circle.js +33 -0
- package/lib/shapes/Ellipse.d.ts +16 -0
- package/lib/shapes/Ellipse.js +37 -0
- package/lib/shapes/Image.d.ts +23 -0
- package/lib/shapes/Image.js +100 -0
- package/lib/shapes/Label.d.ts +35 -0
- package/lib/shapes/Label.js +166 -0
- package/lib/shapes/Line.d.ts +28 -0
- package/lib/shapes/Line.js +155 -0
- package/lib/shapes/Path.d.ts +37 -0
- package/lib/shapes/Path.js +627 -0
- package/lib/shapes/Rect.d.ts +9 -0
- package/lib/shapes/Rect.js +42 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +65 -0
- package/lib/shapes/Ring.d.ts +16 -0
- package/lib/shapes/Ring.js +33 -0
- package/lib/shapes/Sprite.d.ts +30 -0
- package/lib/shapes/Sprite.js +108 -0
- package/lib/shapes/Star.d.ts +17 -0
- package/lib/shapes/Star.js +38 -0
- package/lib/shapes/Text.d.ts +59 -0
- package/lib/shapes/Text.js +347 -0
- package/lib/shapes/TextPath.d.ts +54 -0
- package/lib/shapes/TextPath.js +343 -0
- package/lib/shapes/Transformer.d.ts +112 -0
- package/lib/shapes/Transformer.js +944 -0
- package/lib/shapes/Wedge.d.ts +17 -0
- package/lib/shapes/Wedge.js +38 -0
- package/lib/types.d.ts +50 -0
- package/lib/types.js +22 -0
- package/package.json +111 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface RectConfig extends ShapeConfig {
|
|
4
|
+
cornerRadius?: number | number[];
|
|
5
|
+
}
|
|
6
|
+
export declare class Rect extends Shape<RectConfig> {
|
|
7
|
+
_sceneFunc(context: any): void;
|
|
8
|
+
cornerRadius: GetSet<number | number[], this>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { _registerNode } from '../Global.js';
|
|
4
|
+
import { getNumberOrArrayOfNumbersValidator } from '../Validators.js';
|
|
5
|
+
export class Rect extends Shape {
|
|
6
|
+
_sceneFunc(context) {
|
|
7
|
+
var cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
8
|
+
context.beginPath();
|
|
9
|
+
if (!cornerRadius) {
|
|
10
|
+
context.rect(0, 0, width, height);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
let topLeft = 0;
|
|
14
|
+
let topRight = 0;
|
|
15
|
+
let bottomLeft = 0;
|
|
16
|
+
let bottomRight = 0;
|
|
17
|
+
if (typeof cornerRadius === 'number') {
|
|
18
|
+
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
22
|
+
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
23
|
+
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
24
|
+
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
25
|
+
}
|
|
26
|
+
context.moveTo(topLeft, 0);
|
|
27
|
+
context.lineTo(width - topRight, 0);
|
|
28
|
+
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
29
|
+
context.lineTo(width, height - bottomRight);
|
|
30
|
+
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
31
|
+
context.lineTo(bottomLeft, height);
|
|
32
|
+
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
33
|
+
context.lineTo(0, topLeft);
|
|
34
|
+
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
35
|
+
}
|
|
36
|
+
context.closePath();
|
|
37
|
+
context.fillStrokeShape(this);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
Rect.prototype.className = 'Rect';
|
|
41
|
+
_registerNode(Rect);
|
|
42
|
+
Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface RegularPolygonConfig extends ShapeConfig {
|
|
4
|
+
sides: number;
|
|
5
|
+
radius: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class RegularPolygon extends Shape<RegularPolygonConfig> {
|
|
8
|
+
_sceneFunc(context: any): void;
|
|
9
|
+
_getPoints(): any[];
|
|
10
|
+
getSelfRect(): {
|
|
11
|
+
x: any;
|
|
12
|
+
y: any;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
getWidth(): number;
|
|
17
|
+
getHeight(): number;
|
|
18
|
+
setWidth(width: any): void;
|
|
19
|
+
setHeight(height: any): void;
|
|
20
|
+
radius: GetSet<number, this>;
|
|
21
|
+
sides: GetSet<number, this>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
export class RegularPolygon extends Shape {
|
|
6
|
+
_sceneFunc(context) {
|
|
7
|
+
const points = this._getPoints();
|
|
8
|
+
context.beginPath();
|
|
9
|
+
context.moveTo(points[0].x, points[0].y);
|
|
10
|
+
for (var n = 1; n < points.length; n++) {
|
|
11
|
+
context.lineTo(points[n].x, points[n].y);
|
|
12
|
+
}
|
|
13
|
+
context.closePath();
|
|
14
|
+
context.fillStrokeShape(this);
|
|
15
|
+
}
|
|
16
|
+
_getPoints() {
|
|
17
|
+
const sides = this.attrs.sides;
|
|
18
|
+
const radius = this.attrs.radius || 0;
|
|
19
|
+
const points = [];
|
|
20
|
+
for (var n = 0; n < sides; n++) {
|
|
21
|
+
points.push({
|
|
22
|
+
x: radius * Math.sin((n * 2 * Math.PI) / sides),
|
|
23
|
+
y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return points;
|
|
27
|
+
}
|
|
28
|
+
getSelfRect() {
|
|
29
|
+
const points = this._getPoints();
|
|
30
|
+
var minX = points[0].x;
|
|
31
|
+
var maxX = points[0].y;
|
|
32
|
+
var minY = points[0].x;
|
|
33
|
+
var maxY = points[0].y;
|
|
34
|
+
points.forEach((point) => {
|
|
35
|
+
minX = Math.min(minX, point.x);
|
|
36
|
+
maxX = Math.max(maxX, point.x);
|
|
37
|
+
minY = Math.min(minY, point.y);
|
|
38
|
+
maxY = Math.max(maxY, point.y);
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
x: minX,
|
|
42
|
+
y: minY,
|
|
43
|
+
width: maxX - minX,
|
|
44
|
+
height: maxY - minY,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
getWidth() {
|
|
48
|
+
return this.radius() * 2;
|
|
49
|
+
}
|
|
50
|
+
getHeight() {
|
|
51
|
+
return this.radius() * 2;
|
|
52
|
+
}
|
|
53
|
+
setWidth(width) {
|
|
54
|
+
this.radius(width / 2);
|
|
55
|
+
}
|
|
56
|
+
setHeight(height) {
|
|
57
|
+
this.radius(height / 2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
RegularPolygon.prototype.className = 'RegularPolygon';
|
|
61
|
+
RegularPolygon.prototype._centroid = true;
|
|
62
|
+
RegularPolygon.prototype._attrsAffectingSize = ['radius'];
|
|
63
|
+
_registerNode(RegularPolygon);
|
|
64
|
+
Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator());
|
|
65
|
+
Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface RingConfig extends ShapeConfig {
|
|
4
|
+
innerRadius: number;
|
|
5
|
+
outerRadius: number;
|
|
6
|
+
clockwise?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Ring extends Shape<RingConfig> {
|
|
9
|
+
_sceneFunc(context: any): void;
|
|
10
|
+
getWidth(): number;
|
|
11
|
+
getHeight(): number;
|
|
12
|
+
setWidth(width: any): void;
|
|
13
|
+
setHeight(height: any): void;
|
|
14
|
+
outerRadius: GetSet<number, this>;
|
|
15
|
+
innerRadius: GetSet<number, this>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
var PIx2 = Math.PI * 2;
|
|
6
|
+
export class Ring extends Shape {
|
|
7
|
+
_sceneFunc(context) {
|
|
8
|
+
context.beginPath();
|
|
9
|
+
context.arc(0, 0, this.innerRadius(), 0, PIx2, false);
|
|
10
|
+
context.moveTo(this.outerRadius(), 0);
|
|
11
|
+
context.arc(0, 0, this.outerRadius(), PIx2, 0, true);
|
|
12
|
+
context.closePath();
|
|
13
|
+
context.fillStrokeShape(this);
|
|
14
|
+
}
|
|
15
|
+
getWidth() {
|
|
16
|
+
return this.outerRadius() * 2;
|
|
17
|
+
}
|
|
18
|
+
getHeight() {
|
|
19
|
+
return this.outerRadius() * 2;
|
|
20
|
+
}
|
|
21
|
+
setWidth(width) {
|
|
22
|
+
this.outerRadius(width / 2);
|
|
23
|
+
}
|
|
24
|
+
setHeight(height) {
|
|
25
|
+
this.outerRadius(height / 2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
Ring.prototype.className = 'Ring';
|
|
29
|
+
Ring.prototype._centroid = true;
|
|
30
|
+
Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
31
|
+
_registerNode(Ring);
|
|
32
|
+
Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator());
|
|
33
|
+
Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator());
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { Animation } from '../Animation';
|
|
3
|
+
import { GetSet } from '../types';
|
|
4
|
+
export interface SpriteConfig extends ShapeConfig {
|
|
5
|
+
animation: string;
|
|
6
|
+
animations: any;
|
|
7
|
+
frameIndex?: number;
|
|
8
|
+
image: HTMLImageElement;
|
|
9
|
+
frameRate?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class Sprite extends Shape<SpriteConfig> {
|
|
12
|
+
_updated: boolean;
|
|
13
|
+
anim: Animation;
|
|
14
|
+
interval: any;
|
|
15
|
+
constructor(config: any);
|
|
16
|
+
_sceneFunc(context: any): void;
|
|
17
|
+
_hitFunc(context: any): void;
|
|
18
|
+
_useBufferCanvas(): boolean;
|
|
19
|
+
_setInterval(): void;
|
|
20
|
+
start(): void;
|
|
21
|
+
stop(): void;
|
|
22
|
+
isRunning(): boolean;
|
|
23
|
+
_updateIndex(): void;
|
|
24
|
+
frameIndex: GetSet<number, this>;
|
|
25
|
+
animation: GetSet<string, this>;
|
|
26
|
+
image: GetSet<CanvasImageSource, this>;
|
|
27
|
+
animations: GetSet<any, this>;
|
|
28
|
+
frameOffsets: GetSet<any, this>;
|
|
29
|
+
frameRate: GetSet<number, this>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Animation } from '../Animation.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
|
+
export class Sprite extends Shape {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
9
|
+
this._updated = true;
|
|
10
|
+
this.anim = new Animation(() => {
|
|
11
|
+
var updated = this._updated;
|
|
12
|
+
this._updated = false;
|
|
13
|
+
return updated;
|
|
14
|
+
});
|
|
15
|
+
this.on('animationChange.konva', function () {
|
|
16
|
+
this.frameIndex(0);
|
|
17
|
+
});
|
|
18
|
+
this.on('frameIndexChange.konva', function () {
|
|
19
|
+
this._updated = true;
|
|
20
|
+
});
|
|
21
|
+
this.on('frameRateChange.konva', function () {
|
|
22
|
+
if (!this.anim.isRunning()) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
clearInterval(this.interval);
|
|
26
|
+
this._setInterval();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
_sceneFunc(context) {
|
|
30
|
+
var 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();
|
|
31
|
+
if (this.hasFill() || this.hasStroke()) {
|
|
32
|
+
context.beginPath();
|
|
33
|
+
context.rect(0, 0, width, height);
|
|
34
|
+
context.closePath();
|
|
35
|
+
context.fillStrokeShape(this);
|
|
36
|
+
}
|
|
37
|
+
if (image) {
|
|
38
|
+
if (offsets) {
|
|
39
|
+
var offset = offsets[anim], ix2 = index * 2;
|
|
40
|
+
context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
context.drawImage(image, x, y, width, height, 0, 0, width, height);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
_hitFunc(context) {
|
|
48
|
+
var anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];
|
|
49
|
+
context.beginPath();
|
|
50
|
+
if (offsets) {
|
|
51
|
+
var offset = offsets[anim];
|
|
52
|
+
var ix2 = index * 2;
|
|
53
|
+
context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
context.rect(0, 0, width, height);
|
|
57
|
+
}
|
|
58
|
+
context.closePath();
|
|
59
|
+
context.fillShape(this);
|
|
60
|
+
}
|
|
61
|
+
_useBufferCanvas() {
|
|
62
|
+
return super._useBufferCanvas(true);
|
|
63
|
+
}
|
|
64
|
+
_setInterval() {
|
|
65
|
+
var that = this;
|
|
66
|
+
this.interval = setInterval(function () {
|
|
67
|
+
that._updateIndex();
|
|
68
|
+
}, 1000 / this.frameRate());
|
|
69
|
+
}
|
|
70
|
+
start() {
|
|
71
|
+
if (this.isRunning()) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
var layer = this.getLayer();
|
|
75
|
+
this.anim.setLayers(layer);
|
|
76
|
+
this._setInterval();
|
|
77
|
+
this.anim.start();
|
|
78
|
+
}
|
|
79
|
+
stop() {
|
|
80
|
+
this.anim.stop();
|
|
81
|
+
clearInterval(this.interval);
|
|
82
|
+
}
|
|
83
|
+
isRunning() {
|
|
84
|
+
return this.anim.isRunning();
|
|
85
|
+
}
|
|
86
|
+
_updateIndex() {
|
|
87
|
+
var index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;
|
|
88
|
+
if (index < len - 1) {
|
|
89
|
+
this.frameIndex(index + 1);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.frameIndex(0);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
Sprite.prototype.className = 'Sprite';
|
|
97
|
+
_registerNode(Sprite);
|
|
98
|
+
Factory.addGetterSetter(Sprite, 'animation');
|
|
99
|
+
Factory.addGetterSetter(Sprite, 'animations');
|
|
100
|
+
Factory.addGetterSetter(Sprite, 'frameOffsets');
|
|
101
|
+
Factory.addGetterSetter(Sprite, 'image');
|
|
102
|
+
Factory.addGetterSetter(Sprite, 'frameIndex', 0, getNumberValidator());
|
|
103
|
+
Factory.addGetterSetter(Sprite, 'frameRate', 17, getNumberValidator());
|
|
104
|
+
Factory.backCompat(Sprite, {
|
|
105
|
+
index: 'frameIndex',
|
|
106
|
+
getIndex: 'getFrameIndex',
|
|
107
|
+
setIndex: 'setFrameIndex',
|
|
108
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface StarConfig extends ShapeConfig {
|
|
4
|
+
numPoints: number;
|
|
5
|
+
innerRadius: number;
|
|
6
|
+
outerRadius: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class Star extends Shape<StarConfig> {
|
|
9
|
+
_sceneFunc(context: any): void;
|
|
10
|
+
getWidth(): number;
|
|
11
|
+
getHeight(): number;
|
|
12
|
+
setWidth(width: any): void;
|
|
13
|
+
setHeight(height: any): void;
|
|
14
|
+
outerRadius: GetSet<number, this>;
|
|
15
|
+
innerRadius: GetSet<number, this>;
|
|
16
|
+
numPoints: GetSet<number, this>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
export class Star extends Shape {
|
|
6
|
+
_sceneFunc(context) {
|
|
7
|
+
var innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
|
|
8
|
+
context.beginPath();
|
|
9
|
+
context.moveTo(0, 0 - outerRadius);
|
|
10
|
+
for (var n = 1; n < numPoints * 2; n++) {
|
|
11
|
+
var radius = n % 2 === 0 ? outerRadius : innerRadius;
|
|
12
|
+
var x = radius * Math.sin((n * Math.PI) / numPoints);
|
|
13
|
+
var y = -1 * radius * Math.cos((n * Math.PI) / numPoints);
|
|
14
|
+
context.lineTo(x, y);
|
|
15
|
+
}
|
|
16
|
+
context.closePath();
|
|
17
|
+
context.fillStrokeShape(this);
|
|
18
|
+
}
|
|
19
|
+
getWidth() {
|
|
20
|
+
return this.outerRadius() * 2;
|
|
21
|
+
}
|
|
22
|
+
getHeight() {
|
|
23
|
+
return this.outerRadius() * 2;
|
|
24
|
+
}
|
|
25
|
+
setWidth(width) {
|
|
26
|
+
this.outerRadius(width / 2);
|
|
27
|
+
}
|
|
28
|
+
setHeight(height) {
|
|
29
|
+
this.outerRadius(height / 2);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Star.prototype.className = 'Star';
|
|
33
|
+
Star.prototype._centroid = true;
|
|
34
|
+
Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
35
|
+
_registerNode(Star);
|
|
36
|
+
Factory.addGetterSetter(Star, 'numPoints', 5, getNumberValidator());
|
|
37
|
+
Factory.addGetterSetter(Star, 'innerRadius', 0, getNumberValidator());
|
|
38
|
+
Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator());
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export declare function stringToArray(string: string): string[];
|
|
4
|
+
export interface TextConfig extends ShapeConfig {
|
|
5
|
+
text?: string;
|
|
6
|
+
fontFamily?: string;
|
|
7
|
+
fontSize?: number;
|
|
8
|
+
fontStyle?: string;
|
|
9
|
+
fontVariant?: string;
|
|
10
|
+
textDecoration?: string;
|
|
11
|
+
align?: string;
|
|
12
|
+
verticalAlign?: string;
|
|
13
|
+
padding?: number;
|
|
14
|
+
lineHeight?: number;
|
|
15
|
+
letterSpacing?: number;
|
|
16
|
+
wrap?: string;
|
|
17
|
+
ellipsis?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class Text extends Shape<TextConfig> {
|
|
20
|
+
textArr: Array<{
|
|
21
|
+
text: string;
|
|
22
|
+
width: number;
|
|
23
|
+
}>;
|
|
24
|
+
_partialText: string;
|
|
25
|
+
_partialTextX: number;
|
|
26
|
+
_partialTextY: number;
|
|
27
|
+
textWidth: number;
|
|
28
|
+
textHeight: number;
|
|
29
|
+
constructor(config?: TextConfig);
|
|
30
|
+
_sceneFunc(context: any): void;
|
|
31
|
+
_hitFunc(context: any): void;
|
|
32
|
+
setText(text: any): this;
|
|
33
|
+
getWidth(): any;
|
|
34
|
+
getHeight(): any;
|
|
35
|
+
getTextWidth(): number;
|
|
36
|
+
getTextHeight(): number;
|
|
37
|
+
measureSize(text: any): {
|
|
38
|
+
width: any;
|
|
39
|
+
height: number;
|
|
40
|
+
};
|
|
41
|
+
_getContextFont(): string;
|
|
42
|
+
_addTextLine(line: any): number;
|
|
43
|
+
_getTextWidth(text: any): any;
|
|
44
|
+
_setTextData(): void;
|
|
45
|
+
getStrokeScaleEnabled(): boolean;
|
|
46
|
+
fontFamily: GetSet<string, this>;
|
|
47
|
+
fontSize: GetSet<number, this>;
|
|
48
|
+
fontStyle: GetSet<string, this>;
|
|
49
|
+
fontVariant: GetSet<string, this>;
|
|
50
|
+
align: GetSet<string, this>;
|
|
51
|
+
letterSpacing: GetSet<number, this>;
|
|
52
|
+
verticalAlign: GetSet<string, this>;
|
|
53
|
+
padding: GetSet<number, this>;
|
|
54
|
+
lineHeight: GetSet<number, this>;
|
|
55
|
+
textDecoration: GetSet<string, this>;
|
|
56
|
+
text: GetSet<string, this>;
|
|
57
|
+
wrap: GetSet<string, this>;
|
|
58
|
+
ellipsis: GetSet<boolean, this>;
|
|
59
|
+
}
|