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
package/lib/Context.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Canvas } from './Canvas';
|
|
2
|
+
import { Shape } from './Shape';
|
|
3
|
+
export declare class Context {
|
|
4
|
+
canvas: Canvas;
|
|
5
|
+
_context: CanvasRenderingContext2D;
|
|
6
|
+
traceArr: Array<String>;
|
|
7
|
+
constructor(canvas: Canvas);
|
|
8
|
+
fillShape(shape: Shape): void;
|
|
9
|
+
_fill(shape: any): void;
|
|
10
|
+
strokeShape(shape: Shape): void;
|
|
11
|
+
_stroke(shape: any): void;
|
|
12
|
+
fillStrokeShape(shape: Shape): void;
|
|
13
|
+
getTrace(relaxed?: any, rounded?: any): string;
|
|
14
|
+
clearTrace(): void;
|
|
15
|
+
_trace(str: any): void;
|
|
16
|
+
reset(): void;
|
|
17
|
+
getCanvas(): Canvas;
|
|
18
|
+
clear(bounds?: any): void;
|
|
19
|
+
_applyLineCap(shape: any): void;
|
|
20
|
+
_applyOpacity(shape: any): void;
|
|
21
|
+
_applyLineJoin(shape: Shape): void;
|
|
22
|
+
setAttr(attr: any, val: any): void;
|
|
23
|
+
arc(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
|
24
|
+
arcTo(a0: any, a1: any, a2: any, a3: any, a4: any): void;
|
|
25
|
+
beginPath(): void;
|
|
26
|
+
bezierCurveTo(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
|
27
|
+
clearRect(a0: any, a1: any, a2: any, a3: any): void;
|
|
28
|
+
clip(): void;
|
|
29
|
+
closePath(): void;
|
|
30
|
+
createImageData(a0: any, a1: any): ImageData;
|
|
31
|
+
createLinearGradient(a0: any, a1: any, a2: any, a3: any): CanvasGradient;
|
|
32
|
+
createPattern(a0: any, a1: any): CanvasPattern;
|
|
33
|
+
createRadialGradient(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): CanvasGradient;
|
|
34
|
+
drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
|
|
35
|
+
ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
|
|
36
|
+
isPointInPath(x: any, y: any): boolean;
|
|
37
|
+
fill(path2d?: Path2D): void;
|
|
38
|
+
fillRect(x: any, y: any, width: any, height: any): void;
|
|
39
|
+
strokeRect(x: any, y: any, width: any, height: any): void;
|
|
40
|
+
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
41
|
+
measureText(text: any): TextMetrics;
|
|
42
|
+
getImageData(a0: any, a1: any, a2: any, a3: any): ImageData;
|
|
43
|
+
lineTo(a0: any, a1: any): void;
|
|
44
|
+
moveTo(a0: any, a1: any): void;
|
|
45
|
+
rect(a0: any, a1: any, a2: any, a3: any): void;
|
|
46
|
+
putImageData(a0: any, a1: any, a2: any): void;
|
|
47
|
+
quadraticCurveTo(a0: any, a1: any, a2: any, a3: any): void;
|
|
48
|
+
restore(): void;
|
|
49
|
+
rotate(a0: any): void;
|
|
50
|
+
save(): void;
|
|
51
|
+
scale(a0: any, a1: any): void;
|
|
52
|
+
setLineDash(a0: any): void;
|
|
53
|
+
getLineDash(): number[];
|
|
54
|
+
setTransform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
|
55
|
+
stroke(path2d?: Path2D): void;
|
|
56
|
+
strokeText(a0: any, a1: any, a2: any, a3: any): void;
|
|
57
|
+
transform(a0: any, a1: any, a2: any, a3: any, a4: any, a5: any): void;
|
|
58
|
+
translate(a0: any, a1: any): void;
|
|
59
|
+
_enableTrace(): void;
|
|
60
|
+
_applyGlobalCompositeOperation(node: any): void;
|
|
61
|
+
}
|
|
62
|
+
export declare class SceneContext extends Context {
|
|
63
|
+
_fillColor(shape: Shape): void;
|
|
64
|
+
_fillPattern(shape: any): void;
|
|
65
|
+
_fillLinearGradient(shape: any): void;
|
|
66
|
+
_fillRadialGradient(shape: any): void;
|
|
67
|
+
_fill(shape: any): void;
|
|
68
|
+
_strokeLinearGradient(shape: any): void;
|
|
69
|
+
_stroke(shape: any): void;
|
|
70
|
+
_applyShadow(shape: any): void;
|
|
71
|
+
}
|
|
72
|
+
export declare class HitContext extends Context {
|
|
73
|
+
_fill(shape: any): void;
|
|
74
|
+
strokeShape(shape: Shape): void;
|
|
75
|
+
_stroke(shape: any): void;
|
|
76
|
+
}
|
package/lib/Context.js
ADDED
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import { Util } from './Util.js';
|
|
2
|
+
import { Konva } from './Global.js';
|
|
3
|
+
function simplifyArray(arr) {
|
|
4
|
+
var retArr = [], len = arr.length, util = Util, n, val;
|
|
5
|
+
for (n = 0; n < len; n++) {
|
|
6
|
+
val = arr[n];
|
|
7
|
+
if (util._isNumber(val)) {
|
|
8
|
+
val = Math.round(val * 1000) / 1000;
|
|
9
|
+
}
|
|
10
|
+
else if (!util._isString(val)) {
|
|
11
|
+
val = val + '';
|
|
12
|
+
}
|
|
13
|
+
retArr.push(val);
|
|
14
|
+
}
|
|
15
|
+
return retArr;
|
|
16
|
+
}
|
|
17
|
+
var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()', EQUALS = '=', CONTEXT_METHODS = [
|
|
18
|
+
'arc',
|
|
19
|
+
'arcTo',
|
|
20
|
+
'beginPath',
|
|
21
|
+
'bezierCurveTo',
|
|
22
|
+
'clearRect',
|
|
23
|
+
'clip',
|
|
24
|
+
'closePath',
|
|
25
|
+
'createLinearGradient',
|
|
26
|
+
'createPattern',
|
|
27
|
+
'createRadialGradient',
|
|
28
|
+
'drawImage',
|
|
29
|
+
'ellipse',
|
|
30
|
+
'fill',
|
|
31
|
+
'fillText',
|
|
32
|
+
'getImageData',
|
|
33
|
+
'createImageData',
|
|
34
|
+
'lineTo',
|
|
35
|
+
'moveTo',
|
|
36
|
+
'putImageData',
|
|
37
|
+
'quadraticCurveTo',
|
|
38
|
+
'rect',
|
|
39
|
+
'restore',
|
|
40
|
+
'rotate',
|
|
41
|
+
'save',
|
|
42
|
+
'scale',
|
|
43
|
+
'setLineDash',
|
|
44
|
+
'setTransform',
|
|
45
|
+
'stroke',
|
|
46
|
+
'strokeText',
|
|
47
|
+
'transform',
|
|
48
|
+
'translate',
|
|
49
|
+
];
|
|
50
|
+
var CONTEXT_PROPERTIES = [
|
|
51
|
+
'fillStyle',
|
|
52
|
+
'strokeStyle',
|
|
53
|
+
'shadowColor',
|
|
54
|
+
'shadowBlur',
|
|
55
|
+
'shadowOffsetX',
|
|
56
|
+
'shadowOffsetY',
|
|
57
|
+
'lineCap',
|
|
58
|
+
'lineDashOffset',
|
|
59
|
+
'lineJoin',
|
|
60
|
+
'lineWidth',
|
|
61
|
+
'miterLimit',
|
|
62
|
+
'font',
|
|
63
|
+
'textAlign',
|
|
64
|
+
'textBaseline',
|
|
65
|
+
'globalAlpha',
|
|
66
|
+
'globalCompositeOperation',
|
|
67
|
+
'imageSmoothingEnabled',
|
|
68
|
+
];
|
|
69
|
+
const traceArrMax = 100;
|
|
70
|
+
export class Context {
|
|
71
|
+
constructor(canvas) {
|
|
72
|
+
this.canvas = canvas;
|
|
73
|
+
this._context = canvas._canvas.getContext('2d');
|
|
74
|
+
if (Konva.enableTrace) {
|
|
75
|
+
this.traceArr = [];
|
|
76
|
+
this._enableTrace();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
fillShape(shape) {
|
|
80
|
+
if (shape.fillEnabled()) {
|
|
81
|
+
this._fill(shape);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_fill(shape) {
|
|
85
|
+
}
|
|
86
|
+
strokeShape(shape) {
|
|
87
|
+
if (shape.hasStroke()) {
|
|
88
|
+
this._stroke(shape);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
_stroke(shape) {
|
|
92
|
+
}
|
|
93
|
+
fillStrokeShape(shape) {
|
|
94
|
+
if (shape.attrs.fillAfterStrokeEnabled) {
|
|
95
|
+
this.strokeShape(shape);
|
|
96
|
+
this.fillShape(shape);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.fillShape(shape);
|
|
100
|
+
this.strokeShape(shape);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
getTrace(relaxed, rounded) {
|
|
104
|
+
var traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
|
|
105
|
+
for (n = 0; n < len; n++) {
|
|
106
|
+
trace = traceArr[n];
|
|
107
|
+
method = trace.method;
|
|
108
|
+
if (method) {
|
|
109
|
+
args = trace.args;
|
|
110
|
+
str += method;
|
|
111
|
+
if (relaxed) {
|
|
112
|
+
str += DOUBLE_PAREN;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (Util._isArray(args[0])) {
|
|
116
|
+
str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
if (rounded) {
|
|
120
|
+
args = args.map((a) => typeof a === 'number' ? Math.floor(a) : a);
|
|
121
|
+
}
|
|
122
|
+
str += OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
str += trace.property;
|
|
128
|
+
if (!relaxed) {
|
|
129
|
+
str += EQUALS + trace.val;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
str += SEMICOLON;
|
|
133
|
+
}
|
|
134
|
+
return str;
|
|
135
|
+
}
|
|
136
|
+
clearTrace() {
|
|
137
|
+
this.traceArr = [];
|
|
138
|
+
}
|
|
139
|
+
_trace(str) {
|
|
140
|
+
var traceArr = this.traceArr, len;
|
|
141
|
+
traceArr.push(str);
|
|
142
|
+
len = traceArr.length;
|
|
143
|
+
if (len >= traceArrMax) {
|
|
144
|
+
traceArr.shift();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
reset() {
|
|
148
|
+
var pixelRatio = this.getCanvas().getPixelRatio();
|
|
149
|
+
this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
|
150
|
+
}
|
|
151
|
+
getCanvas() {
|
|
152
|
+
return this.canvas;
|
|
153
|
+
}
|
|
154
|
+
clear(bounds) {
|
|
155
|
+
var canvas = this.getCanvas();
|
|
156
|
+
if (bounds) {
|
|
157
|
+
this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
this.clearRect(0, 0, canvas.getWidth() / canvas.pixelRatio, canvas.getHeight() / canvas.pixelRatio);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
_applyLineCap(shape) {
|
|
164
|
+
var lineCap = shape.getLineCap();
|
|
165
|
+
if (lineCap) {
|
|
166
|
+
this.setAttr('lineCap', lineCap);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_applyOpacity(shape) {
|
|
170
|
+
var absOpacity = shape.getAbsoluteOpacity();
|
|
171
|
+
if (absOpacity !== 1) {
|
|
172
|
+
this.setAttr('globalAlpha', absOpacity);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
_applyLineJoin(shape) {
|
|
176
|
+
var lineJoin = shape.attrs.lineJoin;
|
|
177
|
+
if (lineJoin) {
|
|
178
|
+
this.setAttr('lineJoin', lineJoin);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
setAttr(attr, val) {
|
|
182
|
+
this._context[attr] = val;
|
|
183
|
+
}
|
|
184
|
+
arc(a0, a1, a2, a3, a4, a5) {
|
|
185
|
+
this._context.arc(a0, a1, a2, a3, a4, a5);
|
|
186
|
+
}
|
|
187
|
+
arcTo(a0, a1, a2, a3, a4) {
|
|
188
|
+
this._context.arcTo(a0, a1, a2, a3, a4);
|
|
189
|
+
}
|
|
190
|
+
beginPath() {
|
|
191
|
+
this._context.beginPath();
|
|
192
|
+
}
|
|
193
|
+
bezierCurveTo(a0, a1, a2, a3, a4, a5) {
|
|
194
|
+
this._context.bezierCurveTo(a0, a1, a2, a3, a4, a5);
|
|
195
|
+
}
|
|
196
|
+
clearRect(a0, a1, a2, a3) {
|
|
197
|
+
this._context.clearRect(a0, a1, a2, a3);
|
|
198
|
+
}
|
|
199
|
+
clip() {
|
|
200
|
+
this._context.clip();
|
|
201
|
+
}
|
|
202
|
+
closePath() {
|
|
203
|
+
this._context.closePath();
|
|
204
|
+
}
|
|
205
|
+
createImageData(a0, a1) {
|
|
206
|
+
var a = arguments;
|
|
207
|
+
if (a.length === 2) {
|
|
208
|
+
return this._context.createImageData(a0, a1);
|
|
209
|
+
}
|
|
210
|
+
else if (a.length === 1) {
|
|
211
|
+
return this._context.createImageData(a0);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
createLinearGradient(a0, a1, a2, a3) {
|
|
215
|
+
return this._context.createLinearGradient(a0, a1, a2, a3);
|
|
216
|
+
}
|
|
217
|
+
createPattern(a0, a1) {
|
|
218
|
+
return this._context.createPattern(a0, a1);
|
|
219
|
+
}
|
|
220
|
+
createRadialGradient(a0, a1, a2, a3, a4, a5) {
|
|
221
|
+
return this._context.createRadialGradient(a0, a1, a2, a3, a4, a5);
|
|
222
|
+
}
|
|
223
|
+
drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8) {
|
|
224
|
+
var a = arguments, _context = this._context;
|
|
225
|
+
if (a.length === 3) {
|
|
226
|
+
_context.drawImage(a0, a1, a2);
|
|
227
|
+
}
|
|
228
|
+
else if (a.length === 5) {
|
|
229
|
+
_context.drawImage(a0, a1, a2, a3, a4);
|
|
230
|
+
}
|
|
231
|
+
else if (a.length === 9) {
|
|
232
|
+
_context.drawImage(a0, a1, a2, a3, a4, a5, a6, a7, a8);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
|
|
236
|
+
this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
|
|
237
|
+
}
|
|
238
|
+
isPointInPath(x, y) {
|
|
239
|
+
return this._context.isPointInPath(x, y);
|
|
240
|
+
}
|
|
241
|
+
fill(path2d) {
|
|
242
|
+
if (path2d) {
|
|
243
|
+
this._context.fill(path2d);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this._context.fill();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
fillRect(x, y, width, height) {
|
|
250
|
+
this._context.fillRect(x, y, width, height);
|
|
251
|
+
}
|
|
252
|
+
strokeRect(x, y, width, height) {
|
|
253
|
+
this._context.strokeRect(x, y, width, height);
|
|
254
|
+
}
|
|
255
|
+
fillText(text, x, y, maxWidth) {
|
|
256
|
+
if (maxWidth) {
|
|
257
|
+
this._context.fillText(text, x, y, maxWidth);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this._context.fillText(text, x, y);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
measureText(text) {
|
|
264
|
+
return this._context.measureText(text);
|
|
265
|
+
}
|
|
266
|
+
getImageData(a0, a1, a2, a3) {
|
|
267
|
+
return this._context.getImageData(a0, a1, a2, a3);
|
|
268
|
+
}
|
|
269
|
+
lineTo(a0, a1) {
|
|
270
|
+
this._context.lineTo(a0, a1);
|
|
271
|
+
}
|
|
272
|
+
moveTo(a0, a1) {
|
|
273
|
+
this._context.moveTo(a0, a1);
|
|
274
|
+
}
|
|
275
|
+
rect(a0, a1, a2, a3) {
|
|
276
|
+
this._context.rect(a0, a1, a2, a3);
|
|
277
|
+
}
|
|
278
|
+
putImageData(a0, a1, a2) {
|
|
279
|
+
this._context.putImageData(a0, a1, a2);
|
|
280
|
+
}
|
|
281
|
+
quadraticCurveTo(a0, a1, a2, a3) {
|
|
282
|
+
this._context.quadraticCurveTo(a0, a1, a2, a3);
|
|
283
|
+
}
|
|
284
|
+
restore() {
|
|
285
|
+
this._context.restore();
|
|
286
|
+
}
|
|
287
|
+
rotate(a0) {
|
|
288
|
+
this._context.rotate(a0);
|
|
289
|
+
}
|
|
290
|
+
save() {
|
|
291
|
+
this._context.save();
|
|
292
|
+
}
|
|
293
|
+
scale(a0, a1) {
|
|
294
|
+
this._context.scale(a0, a1);
|
|
295
|
+
}
|
|
296
|
+
setLineDash(a0) {
|
|
297
|
+
if (this._context.setLineDash) {
|
|
298
|
+
this._context.setLineDash(a0);
|
|
299
|
+
}
|
|
300
|
+
else if ('mozDash' in this._context) {
|
|
301
|
+
this._context['mozDash'] = a0;
|
|
302
|
+
}
|
|
303
|
+
else if ('webkitLineDash' in this._context) {
|
|
304
|
+
this._context['webkitLineDash'] = a0;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
getLineDash() {
|
|
308
|
+
return this._context.getLineDash();
|
|
309
|
+
}
|
|
310
|
+
setTransform(a0, a1, a2, a3, a4, a5) {
|
|
311
|
+
this._context.setTransform(a0, a1, a2, a3, a4, a5);
|
|
312
|
+
}
|
|
313
|
+
stroke(path2d) {
|
|
314
|
+
if (path2d) {
|
|
315
|
+
this._context.stroke(path2d);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
this._context.stroke();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
strokeText(a0, a1, a2, a3) {
|
|
322
|
+
this._context.strokeText(a0, a1, a2, a3);
|
|
323
|
+
}
|
|
324
|
+
transform(a0, a1, a2, a3, a4, a5) {
|
|
325
|
+
this._context.transform(a0, a1, a2, a3, a4, a5);
|
|
326
|
+
}
|
|
327
|
+
translate(a0, a1) {
|
|
328
|
+
this._context.translate(a0, a1);
|
|
329
|
+
}
|
|
330
|
+
_enableTrace() {
|
|
331
|
+
var that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
|
332
|
+
var func = function (methodName) {
|
|
333
|
+
var origMethod = that[methodName], ret;
|
|
334
|
+
that[methodName] = function () {
|
|
335
|
+
args = simplifyArray(Array.prototype.slice.call(arguments, 0));
|
|
336
|
+
ret = origMethod.apply(that, arguments);
|
|
337
|
+
that._trace({
|
|
338
|
+
method: methodName,
|
|
339
|
+
args: args,
|
|
340
|
+
});
|
|
341
|
+
return ret;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
for (n = 0; n < len; n++) {
|
|
345
|
+
func(CONTEXT_METHODS[n]);
|
|
346
|
+
}
|
|
347
|
+
that.setAttr = function () {
|
|
348
|
+
origSetter.apply(that, arguments);
|
|
349
|
+
var prop = arguments[0];
|
|
350
|
+
var val = arguments[1];
|
|
351
|
+
if (prop === 'shadowOffsetX' ||
|
|
352
|
+
prop === 'shadowOffsetY' ||
|
|
353
|
+
prop === 'shadowBlur') {
|
|
354
|
+
val = val / this.canvas.getPixelRatio();
|
|
355
|
+
}
|
|
356
|
+
that._trace({
|
|
357
|
+
property: prop,
|
|
358
|
+
val: val,
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
_applyGlobalCompositeOperation(node) {
|
|
363
|
+
const op = node.attrs.globalCompositeOperation;
|
|
364
|
+
var def = !op || op === 'source-over';
|
|
365
|
+
if (!def) {
|
|
366
|
+
this.setAttr('globalCompositeOperation', op);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
CONTEXT_PROPERTIES.forEach(function (prop) {
|
|
371
|
+
Object.defineProperty(Context.prototype, prop, {
|
|
372
|
+
get() {
|
|
373
|
+
return this._context[prop];
|
|
374
|
+
},
|
|
375
|
+
set(val) {
|
|
376
|
+
this._context[prop] = val;
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
export class SceneContext extends Context {
|
|
381
|
+
_fillColor(shape) {
|
|
382
|
+
var fill = shape.fill();
|
|
383
|
+
this.setAttr('fillStyle', fill);
|
|
384
|
+
shape._fillFunc(this);
|
|
385
|
+
}
|
|
386
|
+
_fillPattern(shape) {
|
|
387
|
+
this.setAttr('fillStyle', shape._getFillPattern());
|
|
388
|
+
shape._fillFunc(this);
|
|
389
|
+
}
|
|
390
|
+
_fillLinearGradient(shape) {
|
|
391
|
+
var grd = shape._getLinearGradient();
|
|
392
|
+
if (grd) {
|
|
393
|
+
this.setAttr('fillStyle', grd);
|
|
394
|
+
shape._fillFunc(this);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
_fillRadialGradient(shape) {
|
|
398
|
+
var grd = shape._getRadialGradient();
|
|
399
|
+
if (grd) {
|
|
400
|
+
this.setAttr('fillStyle', grd);
|
|
401
|
+
shape._fillFunc(this);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
_fill(shape) {
|
|
405
|
+
var hasColor = shape.fill(), fillPriority = shape.getFillPriority();
|
|
406
|
+
if (hasColor && fillPriority === 'color') {
|
|
407
|
+
this._fillColor(shape);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
var hasPattern = shape.getFillPatternImage();
|
|
411
|
+
if (hasPattern && fillPriority === 'pattern') {
|
|
412
|
+
this._fillPattern(shape);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
var hasLinearGradient = shape.getFillLinearGradientColorStops();
|
|
416
|
+
if (hasLinearGradient && fillPriority === 'linear-gradient') {
|
|
417
|
+
this._fillLinearGradient(shape);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
var hasRadialGradient = shape.getFillRadialGradientColorStops();
|
|
421
|
+
if (hasRadialGradient && fillPriority === 'radial-gradient') {
|
|
422
|
+
this._fillRadialGradient(shape);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (hasColor) {
|
|
426
|
+
this._fillColor(shape);
|
|
427
|
+
}
|
|
428
|
+
else if (hasPattern) {
|
|
429
|
+
this._fillPattern(shape);
|
|
430
|
+
}
|
|
431
|
+
else if (hasLinearGradient) {
|
|
432
|
+
this._fillLinearGradient(shape);
|
|
433
|
+
}
|
|
434
|
+
else if (hasRadialGradient) {
|
|
435
|
+
this._fillRadialGradient(shape);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
_strokeLinearGradient(shape) {
|
|
439
|
+
var start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
440
|
+
if (colorStops) {
|
|
441
|
+
for (var n = 0; n < colorStops.length; n += 2) {
|
|
442
|
+
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
443
|
+
}
|
|
444
|
+
this.setAttr('strokeStyle', grd);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
_stroke(shape) {
|
|
448
|
+
var dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
449
|
+
if (shape.hasStroke()) {
|
|
450
|
+
if (!strokeScaleEnabled) {
|
|
451
|
+
this.save();
|
|
452
|
+
var pixelRatio = this.getCanvas().getPixelRatio();
|
|
453
|
+
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
454
|
+
}
|
|
455
|
+
this._applyLineCap(shape);
|
|
456
|
+
if (dash && shape.dashEnabled()) {
|
|
457
|
+
this.setLineDash(dash);
|
|
458
|
+
this.setAttr('lineDashOffset', shape.dashOffset());
|
|
459
|
+
}
|
|
460
|
+
this.setAttr('lineWidth', shape.strokeWidth());
|
|
461
|
+
if (!shape.getShadowForStrokeEnabled()) {
|
|
462
|
+
this.setAttr('shadowColor', 'rgba(0,0,0,0)');
|
|
463
|
+
}
|
|
464
|
+
var hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
|
465
|
+
if (hasLinearGradient) {
|
|
466
|
+
this._strokeLinearGradient(shape);
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
this.setAttr('strokeStyle', shape.stroke());
|
|
470
|
+
}
|
|
471
|
+
shape._strokeFunc(this);
|
|
472
|
+
if (!strokeScaleEnabled) {
|
|
473
|
+
this.restore();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
_applyShadow(shape) {
|
|
478
|
+
var _a, _b, _c;
|
|
479
|
+
var color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
|
|
480
|
+
x: 0,
|
|
481
|
+
y: 0,
|
|
482
|
+
}, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
|
483
|
+
this.setAttr('shadowColor', color);
|
|
484
|
+
this.setAttr('shadowBlur', blur * Math.min(Math.abs(scaleX), Math.abs(scaleY)));
|
|
485
|
+
this.setAttr('shadowOffsetX', offset.x * scaleX);
|
|
486
|
+
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
export class HitContext extends Context {
|
|
490
|
+
_fill(shape) {
|
|
491
|
+
this.save();
|
|
492
|
+
this.setAttr('fillStyle', shape.colorKey);
|
|
493
|
+
shape._fillFuncHit(this);
|
|
494
|
+
this.restore();
|
|
495
|
+
}
|
|
496
|
+
strokeShape(shape) {
|
|
497
|
+
if (shape.hasHitStroke()) {
|
|
498
|
+
this._stroke(shape);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
_stroke(shape) {
|
|
502
|
+
if (shape.hasHitStroke()) {
|
|
503
|
+
var strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
504
|
+
if (!strokeScaleEnabled) {
|
|
505
|
+
this.save();
|
|
506
|
+
var pixelRatio = this.getCanvas().getPixelRatio();
|
|
507
|
+
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
508
|
+
}
|
|
509
|
+
this._applyLineCap(shape);
|
|
510
|
+
var hitStrokeWidth = shape.hitStrokeWidth();
|
|
511
|
+
var strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
|
|
512
|
+
this.setAttr('lineWidth', strokeWidth);
|
|
513
|
+
this.setAttr('strokeStyle', shape.colorKey);
|
|
514
|
+
shape._strokeFuncHit(this);
|
|
515
|
+
if (!strokeScaleEnabled) {
|
|
516
|
+
this.restore();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|