konva 10.0.10 → 10.0.11
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 +2 -2
- package/konva.min.js +2 -2
- package/lib/Animation.d.ts +24 -0
- package/lib/Animation.js +142 -0
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +784 -0
- package/lib/Canvas.d.ts +33 -0
- package/lib/Canvas.js +107 -0
- package/lib/Container.d.ts +54 -0
- package/lib/Container.js +316 -0
- package/lib/Context.d.ts +95 -0
- package/lib/Context.js +561 -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 +110 -0
- package/lib/Factory.d.ts +22 -0
- package/lib/Factory.js +123 -0
- package/lib/FastLayer.d.ts +4 -0
- package/lib/FastLayer.js +12 -0
- package/lib/Global.d.ts +37 -0
- package/lib/Global.js +66 -0
- package/lib/Group.d.ts +9 -0
- package/lib/Group.js +13 -0
- package/lib/Layer.d.ts +62 -0
- package/lib/Layer.js +305 -0
- package/lib/Node.d.ts +323 -0
- package/lib/Node.js +1532 -0
- package/lib/PointerEvents.d.ts +11 -0
- package/lib/PointerEvents.js +37 -0
- package/lib/Shape.d.ts +196 -0
- package/lib/Shape.js +555 -0
- package/lib/Stage.d.ts +86 -0
- package/lib/Stage.js +715 -0
- package/lib/Tween.d.ts +90 -0
- package/lib/Tween.js +531 -0
- package/lib/Util.d.ts +137 -0
- package/lib/Util.js +909 -0
- package/lib/Validators.d.ts +11 -0
- package/lib/Validators.js +178 -0
- package/lib/_CoreInternals.d.ts +224 -0
- package/lib/_CoreInternals.js +34 -0
- package/lib/_FullInternals.d.ts +306 -0
- package/lib/_FullInternals.js +80 -0
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +2 -0
- package/lib/filters/Blur.js +235 -0
- package/lib/filters/Brighten.d.ts +2 -0
- package/lib/filters/Brighten.js +12 -0
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +2 -0
- package/lib/filters/Contrast.js +35 -0
- package/lib/filters/Emboss.d.ts +2 -0
- package/lib/filters/Emboss.js +101 -0
- package/lib/filters/Enhance.d.ts +2 -0
- package/lib/filters/Enhance.js +84 -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 +23 -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 +133 -0
- package/lib/filters/Mask.d.ts +2 -0
- package/lib/filters/Mask.js +151 -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 +38 -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 +14 -0
- package/lib/filters/Threshold.d.ts +2 -0
- package/lib/filters/Threshold.js +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/shapes/Arc.d.ts +27 -0
- package/lib/shapes/Arc.js +60 -0
- package/lib/shapes/Arrow.d.ts +27 -0
- package/lib/shapes/Arrow.js +99 -0
- package/lib/shapes/Circle.d.ts +15 -0
- package/lib/shapes/Circle.js +33 -0
- package/lib/shapes/Ellipse.d.ts +18 -0
- package/lib/shapes/Ellipse.js +37 -0
- package/lib/shapes/Image.d.ts +29 -0
- package/lib/shapes/Image.js +131 -0
- package/lib/shapes/Label.d.ts +39 -0
- package/lib/shapes/Label.js +173 -0
- package/lib/shapes/Line.d.ts +29 -0
- package/lib/shapes/Line.js +156 -0
- package/lib/shapes/Path.d.ts +50 -0
- package/lib/shapes/Path.js +670 -0
- package/lib/shapes/Rect.d.ts +11 -0
- package/lib/shapes/Rect.js +22 -0
- package/lib/shapes/RegularPolygon.d.ts +26 -0
- package/lib/shapes/RegularPolygon.js +72 -0
- package/lib/shapes/Ring.d.ts +17 -0
- package/lib/shapes/Ring.js +33 -0
- package/lib/shapes/Sprite.d.ts +32 -0
- package/lib/shapes/Sprite.js +108 -0
- package/lib/shapes/Star.d.ts +19 -0
- package/lib/shapes/Star.js +38 -0
- package/lib/shapes/Text.d.ts +90 -0
- package/lib/shapes/Text.js +461 -0
- package/lib/shapes/TextPath.d.ts +72 -0
- package/lib/shapes/TextPath.js +268 -0
- package/lib/shapes/Transformer.d.ts +130 -0
- package/lib/shapes/Transformer.js +1009 -0
- package/lib/shapes/Wedge.d.ts +19 -0
- package/lib/shapes/Wedge.js +38 -0
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +56 -0
- package/lib/types.js +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Shape } from "../Shape.js";
|
|
3
|
+
import { _registerNode } from "../Global.js";
|
|
4
|
+
import { Util } from "../Util.js";
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator } from "../Validators.js";
|
|
6
|
+
export class Rect extends Shape {
|
|
7
|
+
_sceneFunc(context) {
|
|
8
|
+
const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
9
|
+
context.beginPath();
|
|
10
|
+
if (!cornerRadius) {
|
|
11
|
+
context.rect(0, 0, width, height);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
15
|
+
}
|
|
16
|
+
context.closePath();
|
|
17
|
+
context.fillStrokeShape(this);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
Rect.prototype.className = 'Rect';
|
|
21
|
+
_registerNode(Rect);
|
|
22
|
+
Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet, Vector2d } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
5
|
+
export interface RegularPolygonConfig extends ShapeConfig {
|
|
6
|
+
sides: number;
|
|
7
|
+
radius: number;
|
|
8
|
+
cornerRadius?: number | number[];
|
|
9
|
+
}
|
|
10
|
+
export declare class RegularPolygon extends Shape<RegularPolygonConfig> {
|
|
11
|
+
_sceneFunc(context: Context): void;
|
|
12
|
+
_getPoints(): Vector2d[];
|
|
13
|
+
getSelfRect(): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
getWidth(): number;
|
|
20
|
+
getHeight(): number;
|
|
21
|
+
setWidth(width: number): void;
|
|
22
|
+
setHeight(height: number): void;
|
|
23
|
+
radius: GetSet<number, this>;
|
|
24
|
+
sides: GetSet<number, this>;
|
|
25
|
+
cornerRadius: GetSet<number | number[], this>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Shape } from "../Shape.js";
|
|
3
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
4
|
+
import { _registerNode } from "../Global.js";
|
|
5
|
+
import { Util } from "../Util.js";
|
|
6
|
+
export class RegularPolygon extends Shape {
|
|
7
|
+
_sceneFunc(context) {
|
|
8
|
+
const points = this._getPoints(), radius = this.radius(), sides = this.sides(), cornerRadius = this.cornerRadius();
|
|
9
|
+
context.beginPath();
|
|
10
|
+
if (!cornerRadius) {
|
|
11
|
+
context.moveTo(points[0].x, points[0].y);
|
|
12
|
+
for (let n = 1; n < points.length; n++) {
|
|
13
|
+
context.lineTo(points[n].x, points[n].y);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
Util.drawRoundedPolygonPath(context, points, sides, radius, cornerRadius);
|
|
18
|
+
}
|
|
19
|
+
context.closePath();
|
|
20
|
+
context.fillStrokeShape(this);
|
|
21
|
+
}
|
|
22
|
+
_getPoints() {
|
|
23
|
+
const sides = this.attrs.sides;
|
|
24
|
+
const radius = this.attrs.radius || 0;
|
|
25
|
+
const points = [];
|
|
26
|
+
for (let n = 0; n < sides; n++) {
|
|
27
|
+
points.push({
|
|
28
|
+
x: radius * Math.sin((n * 2 * Math.PI) / sides),
|
|
29
|
+
y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return points;
|
|
33
|
+
}
|
|
34
|
+
getSelfRect() {
|
|
35
|
+
const points = this._getPoints();
|
|
36
|
+
let minX = points[0].x;
|
|
37
|
+
let maxX = points[0].x;
|
|
38
|
+
let minY = points[0].y;
|
|
39
|
+
let maxY = points[0].y;
|
|
40
|
+
points.forEach((point) => {
|
|
41
|
+
minX = Math.min(minX, point.x);
|
|
42
|
+
maxX = Math.max(maxX, point.x);
|
|
43
|
+
minY = Math.min(minY, point.y);
|
|
44
|
+
maxY = Math.max(maxY, point.y);
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
x: minX,
|
|
48
|
+
y: minY,
|
|
49
|
+
width: maxX - minX,
|
|
50
|
+
height: maxY - minY,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
getWidth() {
|
|
54
|
+
return this.radius() * 2;
|
|
55
|
+
}
|
|
56
|
+
getHeight() {
|
|
57
|
+
return this.radius() * 2;
|
|
58
|
+
}
|
|
59
|
+
setWidth(width) {
|
|
60
|
+
this.radius(width / 2);
|
|
61
|
+
}
|
|
62
|
+
setHeight(height) {
|
|
63
|
+
this.radius(height / 2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
RegularPolygon.prototype.className = 'RegularPolygon';
|
|
67
|
+
RegularPolygon.prototype._centroid = true;
|
|
68
|
+
RegularPolygon.prototype._attrsAffectingSize = ['radius'];
|
|
69
|
+
_registerNode(RegularPolygon);
|
|
70
|
+
Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator());
|
|
71
|
+
Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
|
|
72
|
+
Factory.addGetterSetter(RegularPolygon, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
5
|
+
export interface RingConfig extends ShapeConfig {
|
|
6
|
+
innerRadius: number;
|
|
7
|
+
outerRadius: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class Ring extends Shape<RingConfig> {
|
|
10
|
+
_sceneFunc(context: Context): void;
|
|
11
|
+
getWidth(): number;
|
|
12
|
+
getHeight(): number;
|
|
13
|
+
setWidth(width: number): void;
|
|
14
|
+
setHeight(height: number): void;
|
|
15
|
+
outerRadius: GetSet<number, this>;
|
|
16
|
+
innerRadius: GetSet<number, this>;
|
|
17
|
+
}
|
|
@@ -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
|
+
const 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,32 @@
|
|
|
1
|
+
import type { Context } from '../Context.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import { Animation } from '../Animation.ts';
|
|
5
|
+
import type { GetSet } from '../types.ts';
|
|
6
|
+
export interface SpriteConfig extends ShapeConfig {
|
|
7
|
+
animation: string;
|
|
8
|
+
animations: any;
|
|
9
|
+
frameIndex?: number;
|
|
10
|
+
image: HTMLImageElement;
|
|
11
|
+
frameRate?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class Sprite extends Shape<SpriteConfig> {
|
|
14
|
+
_updated: boolean;
|
|
15
|
+
anim: Animation;
|
|
16
|
+
interval: any;
|
|
17
|
+
constructor(config: SpriteConfig);
|
|
18
|
+
_sceneFunc(context: Context): void;
|
|
19
|
+
_hitFunc(context: Context): void;
|
|
20
|
+
_useBufferCanvas(): boolean;
|
|
21
|
+
_setInterval(): void;
|
|
22
|
+
start(): void;
|
|
23
|
+
stop(): void;
|
|
24
|
+
isRunning(): boolean;
|
|
25
|
+
_updateIndex(): void;
|
|
26
|
+
frameIndex: GetSet<number, this>;
|
|
27
|
+
animation: GetSet<string, this>;
|
|
28
|
+
image: GetSet<CanvasImageSource, this>;
|
|
29
|
+
animations: GetSet<any, this>;
|
|
30
|
+
frameOffsets: GetSet<any, this>;
|
|
31
|
+
frameRate: GetSet<number, this>;
|
|
32
|
+
}
|
|
@@ -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
|
+
const 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
|
+
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();
|
|
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
|
+
const 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
|
+
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];
|
|
49
|
+
context.beginPath();
|
|
50
|
+
if (offsets) {
|
|
51
|
+
const offset = offsets[anim];
|
|
52
|
+
const 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
|
+
const 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
|
+
const 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
|
+
const 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,19 @@
|
|
|
1
|
+
import type { Context } from '../Context.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import type { GetSet } from '../types.ts';
|
|
5
|
+
export interface StarConfig extends ShapeConfig {
|
|
6
|
+
numPoints: number;
|
|
7
|
+
innerRadius: number;
|
|
8
|
+
outerRadius: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class Star extends Shape<StarConfig> {
|
|
11
|
+
_sceneFunc(context: Context): void;
|
|
12
|
+
getWidth(): number;
|
|
13
|
+
getHeight(): number;
|
|
14
|
+
setWidth(width: number): void;
|
|
15
|
+
setHeight(height: number): void;
|
|
16
|
+
outerRadius: GetSet<number, this>;
|
|
17
|
+
innerRadius: GetSet<number, this>;
|
|
18
|
+
numPoints: GetSet<number, this>;
|
|
19
|
+
}
|
|
@@ -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
|
+
const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
|
|
8
|
+
context.beginPath();
|
|
9
|
+
context.moveTo(0, 0 - outerRadius);
|
|
10
|
+
for (let n = 1; n < numPoints * 2; n++) {
|
|
11
|
+
const radius = n % 2 === 0 ? outerRadius : innerRadius;
|
|
12
|
+
const x = radius * Math.sin((n * Math.PI) / numPoints);
|
|
13
|
+
const 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,90 @@
|
|
|
1
|
+
import type { Context } from '../Context.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import type { GetSet } from '../types.ts';
|
|
5
|
+
export interface CharRenderProps {
|
|
6
|
+
char: string;
|
|
7
|
+
index: number;
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
lineIndex: number;
|
|
11
|
+
column: number;
|
|
12
|
+
isLastInLine: boolean;
|
|
13
|
+
width: number;
|
|
14
|
+
context: Context;
|
|
15
|
+
}
|
|
16
|
+
export declare function stringToArray(string: string): string[];
|
|
17
|
+
export interface TextConfig extends ShapeConfig {
|
|
18
|
+
direction?: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
fontFamily?: string;
|
|
21
|
+
fontSize?: number;
|
|
22
|
+
fontStyle?: string;
|
|
23
|
+
fontVariant?: string;
|
|
24
|
+
textDecoration?: string;
|
|
25
|
+
align?: string;
|
|
26
|
+
verticalAlign?: string;
|
|
27
|
+
padding?: number;
|
|
28
|
+
lineHeight?: number;
|
|
29
|
+
letterSpacing?: number;
|
|
30
|
+
wrap?: string;
|
|
31
|
+
ellipsis?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class Text extends Shape<TextConfig> {
|
|
34
|
+
textArr: Array<{
|
|
35
|
+
text: string;
|
|
36
|
+
width: number;
|
|
37
|
+
lastInParagraph: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
_partialText: string;
|
|
40
|
+
_partialTextX: number;
|
|
41
|
+
_partialTextY: number;
|
|
42
|
+
textWidth: number;
|
|
43
|
+
textHeight: number;
|
|
44
|
+
constructor(config?: TextConfig);
|
|
45
|
+
_sceneFunc(context: Context): void;
|
|
46
|
+
_hitFunc(context: Context): void;
|
|
47
|
+
setText(text: string): this;
|
|
48
|
+
getWidth(): any;
|
|
49
|
+
getHeight(): any;
|
|
50
|
+
getTextWidth(): number;
|
|
51
|
+
getTextHeight(): number;
|
|
52
|
+
measureSize(text: string): {
|
|
53
|
+
actualBoundingBoxAscent: number;
|
|
54
|
+
actualBoundingBoxDescent: number;
|
|
55
|
+
actualBoundingBoxLeft: number;
|
|
56
|
+
actualBoundingBoxRight: number;
|
|
57
|
+
alphabeticBaseline: number;
|
|
58
|
+
emHeightAscent: number;
|
|
59
|
+
emHeightDescent: number;
|
|
60
|
+
fontBoundingBoxAscent: number;
|
|
61
|
+
fontBoundingBoxDescent: number;
|
|
62
|
+
hangingBaseline: number;
|
|
63
|
+
ideographicBaseline: number;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
};
|
|
67
|
+
_getContextFont(): string;
|
|
68
|
+
_addTextLine(line: string): number;
|
|
69
|
+
_getTextWidth(text: string): number;
|
|
70
|
+
_setTextData(): void;
|
|
71
|
+
_shouldHandleEllipsis(currentHeightPx: number): boolean;
|
|
72
|
+
_tryToAddEllipsisToLastLine(): void;
|
|
73
|
+
getStrokeScaleEnabled(): boolean;
|
|
74
|
+
_useBufferCanvas(): boolean;
|
|
75
|
+
direction: GetSet<string, this>;
|
|
76
|
+
fontFamily: GetSet<string, this>;
|
|
77
|
+
fontSize: GetSet<number, this>;
|
|
78
|
+
fontStyle: GetSet<string, this>;
|
|
79
|
+
fontVariant: GetSet<string, this>;
|
|
80
|
+
align: GetSet<string, this>;
|
|
81
|
+
letterSpacing: GetSet<number, this>;
|
|
82
|
+
verticalAlign: GetSet<string, this>;
|
|
83
|
+
padding: GetSet<number, this>;
|
|
84
|
+
lineHeight: GetSet<number, this>;
|
|
85
|
+
textDecoration: GetSet<string, this>;
|
|
86
|
+
text: GetSet<string, this>;
|
|
87
|
+
wrap: GetSet<string, this>;
|
|
88
|
+
ellipsis: GetSet<boolean, this>;
|
|
89
|
+
charRenderFunc: GetSet<null | ((props: CharRenderProps) => void), this>;
|
|
90
|
+
}
|