vislite 0.5.2-alpha.0 → 0.5.2-alpha.2
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 +7 -1
- package/lib/Buffer/index.umd.js +55 -0
- package/lib/Buffer/index.umd.min.js +11 -0
- package/lib/Canvas/index.umd.js +721 -0
- package/lib/Canvas/index.umd.min.js +11 -0
- package/lib/Cardinal/index.umd.js +112 -0
- package/lib/Cardinal/index.umd.min.js +11 -0
- package/lib/Eoap/index.umd.js +53 -0
- package/lib/Eoap/index.umd.min.js +11 -0
- package/lib/Geometry/index.umd.js +205 -0
- package/lib/Geometry/index.umd.min.js +11 -0
- package/lib/Hermite/index.umd.js +55 -0
- package/lib/Hermite/index.umd.min.js +11 -0
- package/lib/Matrix4/index.umd.js +146 -0
- package/lib/Matrix4/index.umd.min.js +11 -0
- package/lib/Mercator/index.umd.js +39 -0
- package/lib/Mercator/index.umd.min.js +11 -0
- package/lib/OralCanvas/index.es.js +657 -0
- package/lib/OralCanvas/index.es.min.js +11 -0
- package/lib/OralWebGL/index.es.js +611 -0
- package/lib/OralWebGL/index.es.min.js +11 -0
- package/lib/SVG/index.umd.js +540 -0
- package/lib/SVG/index.umd.min.js +11 -0
- package/lib/Shader/index.umd.js +134 -0
- package/lib/Shader/index.umd.min.js +11 -0
- package/lib/Texture/index.umd.js +72 -0
- package/lib/Texture/index.umd.min.js +11 -0
- package/lib/TreeLayout/index.umd.js +430 -0
- package/lib/TreeLayout/index.umd.min.js +11 -0
- package/lib/WebGL/index.umd.js +684 -0
- package/lib/WebGL/index.umd.min.js +11 -0
- package/lib/animation/index.umd.js +91 -0
- package/lib/animation/index.umd.min.js +11 -0
- package/lib/formatColor/index.umd.js +59 -0
- package/lib/formatColor/index.umd.min.js +11 -0
- package/lib/getLoopColors/index.umd.js +55 -0
- package/lib/getLoopColors/index.umd.min.js +11 -0
- package/lib/getWebGLContext/index.umd.js +65 -0
- package/lib/getWebGLContext/index.umd.min.js +11 -0
- package/lib/index.umd.js +2916 -0
- package/lib/index.umd.min.js +11 -0
- package/lib/move/index.umd.js +27 -0
- package/lib/move/index.umd.min.js +11 -0
- package/lib/resizeObserver/index.umd.js +48 -0
- package/lib/resizeObserver/index.umd.min.js +11 -0
- package/lib/rotate/index.umd.js +27 -0
- package/lib/rotate/index.umd.min.js +11 -0
- package/lib/ruler/index.umd.js +145 -0
- package/lib/ruler/index.umd.min.js +11 -0
- package/lib/scale/index.umd.js +26 -0
- package/lib/scale/index.umd.min.js +11 -0
- package/lib/throttle/index.umd.js +70 -0
- package/lib/throttle/index.umd.min.js +11 -0
- package/lib/viewHandler/index.umd.js +139 -0
- package/lib/viewHandler/index.umd.min.js +11 -0
- package/package/index.ts +4 -0
- package/package/move/index.ts +3 -0
- package/package/scale/index.ts +3 -0
- package/package.json +1 -1
- package/src/common/svg/config.ts +157 -145
- package/src/common/svg/gradient.ts +63 -0
- package/src/common/svg/index.ts +12 -0
- package/src/move.ts +8 -0
- package/src/scale.ts +7 -0
- package/types/Canvas.d.ts +2 -2
- package/types/Gradient.d.ts +2 -2
- package/types/SVG.d.ts +23 -0
- package/types/index.d.ts +6 -0
- package/types/move.d.ts +3 -0
- package/types/scale.d.ts +3 -0
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* VISLite JavaScript Library v0.5.2-alpha.2
|
|
3
|
+
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
+
*
|
|
5
|
+
* Copyright zxl20070701
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
+
*
|
|
9
|
+
* Publish Date: Mon Oct 23 2023 22:21:10 GMT+0800 (中国标准时间)
|
|
10
|
+
*/
|
|
11
|
+
/******************************************************************************
|
|
12
|
+
Copyright (c) Microsoft Corporation.
|
|
13
|
+
|
|
14
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
+
purpose with or without fee is hereby granted.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
+
***************************************************************************** */
|
|
25
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
26
|
+
|
|
27
|
+
var extendStatics = function(d, b) {
|
|
28
|
+
extendStatics = Object.setPrototypeOf ||
|
|
29
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
30
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
31
|
+
return extendStatics(d, b);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function __extends(d, b) {
|
|
35
|
+
if (typeof b !== "function" && b !== null)
|
|
36
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
37
|
+
extendStatics(d, b);
|
|
38
|
+
function __() { this.constructor = d; }
|
|
39
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var rotate = function (cx, cy, deg, x, y) {
|
|
48
|
+
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
49
|
+
return [
|
|
50
|
+
+((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
|
|
51
|
+
+((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
|
|
52
|
+
];
|
|
53
|
+
};
|
|
54
|
+
function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
|
|
55
|
+
if (rotateA < 0) {
|
|
56
|
+
beginA += rotateA;
|
|
57
|
+
rotateA *= -1;
|
|
58
|
+
}
|
|
59
|
+
var temp = [], p;
|
|
60
|
+
p = rotate(0, 0, beginA, r1, 0);
|
|
61
|
+
temp[0] = p[0];
|
|
62
|
+
temp[1] = p[1];
|
|
63
|
+
p = rotate(0, 0, rotateA, p[0], p[1]);
|
|
64
|
+
temp[2] = p[0];
|
|
65
|
+
temp[3] = p[1];
|
|
66
|
+
p = rotate(0, 0, beginA, r2, 0);
|
|
67
|
+
temp[4] = p[0];
|
|
68
|
+
temp[5] = p[1];
|
|
69
|
+
p = rotate(0, 0, rotateA, p[0], p[1]);
|
|
70
|
+
temp[6] = p[0];
|
|
71
|
+
temp[7] = p[1];
|
|
72
|
+
doback(beginA, beginA + rotateA, temp[0] + cx, temp[1] + cy, temp[4] + cx, temp[5] + cy, temp[2] + cx, temp[3] + cy, temp[6] + cx, temp[7] + cy, (r2 - r1) * 0.5);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var initText = function (painter, config, x, y, deg) {
|
|
76
|
+
painter.beginPath();
|
|
77
|
+
painter.translate(x, y);
|
|
78
|
+
painter.rotate(deg);
|
|
79
|
+
painter.font =
|
|
80
|
+
config.fontStyle +
|
|
81
|
+
" " +
|
|
82
|
+
config.fontWeight +
|
|
83
|
+
" " +
|
|
84
|
+
config.fontSize +
|
|
85
|
+
"px " +
|
|
86
|
+
config.fontFamily;
|
|
87
|
+
return painter;
|
|
88
|
+
};
|
|
89
|
+
var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
90
|
+
if (r1 > r2) {
|
|
91
|
+
var temp = r1;
|
|
92
|
+
r1 = r2;
|
|
93
|
+
r2 = temp;
|
|
94
|
+
}
|
|
95
|
+
beginDeg = beginDeg % (Math.PI * 2);
|
|
96
|
+
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
97
|
+
deg = Math.PI * 2;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
deg = deg % (Math.PI * 2);
|
|
101
|
+
}
|
|
102
|
+
arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
|
|
103
|
+
if (r < 0)
|
|
104
|
+
r = -r;
|
|
105
|
+
painter.beginPath();
|
|
106
|
+
painter.moveTo(begInnerX, begInnerY);
|
|
107
|
+
painter.arc(cx, cy, r1, beginA, endA, false);
|
|
108
|
+
if (config.arcEndCap == "round")
|
|
109
|
+
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
|
|
110
|
+
else if (config.arcEndCap == "-round")
|
|
111
|
+
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
|
|
112
|
+
else
|
|
113
|
+
painter.lineTo(endOuterX, endOuterY);
|
|
114
|
+
painter.arc(cx, cy, r2, endA, beginA, true);
|
|
115
|
+
if (config.arcStartCap == "round")
|
|
116
|
+
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
|
|
117
|
+
else if (config.arcStartCap == "-round")
|
|
118
|
+
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
|
|
119
|
+
else
|
|
120
|
+
painter.lineTo(begInnerX, begInnerY);
|
|
121
|
+
});
|
|
122
|
+
if (config.arcStartCap == "butt")
|
|
123
|
+
painter.closePath();
|
|
124
|
+
return painter;
|
|
125
|
+
};
|
|
126
|
+
var initCircle = function (painter, cx, cy, r) {
|
|
127
|
+
painter.beginPath();
|
|
128
|
+
painter.moveTo(cx + r, cy);
|
|
129
|
+
painter.arc(cx, cy, r, 0, Math.PI * 2);
|
|
130
|
+
return painter;
|
|
131
|
+
};
|
|
132
|
+
var initRect = function (painter, x, y, width, height) {
|
|
133
|
+
painter.beginPath();
|
|
134
|
+
painter.rect(x, y, width, height);
|
|
135
|
+
return painter;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
function texts (painter, contents, width, height, doback) {
|
|
139
|
+
var lineNumber = 0, content = "";
|
|
140
|
+
for (var i = 0; i < contents.length; i++) {
|
|
141
|
+
if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
|
|
142
|
+
lineNumber += 1;
|
|
143
|
+
doback(content, (lineNumber - 0.5) * height);
|
|
144
|
+
content = contents[i];
|
|
145
|
+
}
|
|
146
|
+
else if (i == contents.length - 1) {
|
|
147
|
+
lineNumber += 1;
|
|
148
|
+
doback(content + contents[i], (lineNumber - 0.5) * height);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
content += contents[i];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return lineNumber * height;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var Painter = (function () {
|
|
158
|
+
function Painter(canvas, opts, region, isPainter) {
|
|
159
|
+
if (opts === void 0) { opts = {}; }
|
|
160
|
+
if (isPainter === void 0) { isPainter = false; }
|
|
161
|
+
this.__region = null;
|
|
162
|
+
this.__onlyRegion = false;
|
|
163
|
+
this.__specialConfig = {
|
|
164
|
+
"fontSize": 16,
|
|
165
|
+
"fontFamily": "sans-serif",
|
|
166
|
+
"fontWeight": 400,
|
|
167
|
+
"fontStyle": "normal",
|
|
168
|
+
"arcStartCap": 'butt',
|
|
169
|
+
"arcEndCap": 'butt'
|
|
170
|
+
};
|
|
171
|
+
this.__initConfig = {
|
|
172
|
+
"fillStyle": 'black',
|
|
173
|
+
"strokeStyle": 'black',
|
|
174
|
+
"lineWidth": 1,
|
|
175
|
+
"textAlign": 'left',
|
|
176
|
+
"textBaseline": 'middle',
|
|
177
|
+
"lineDash": [],
|
|
178
|
+
"shadowBlur": 0,
|
|
179
|
+
"shadowColor": "black"
|
|
180
|
+
};
|
|
181
|
+
this.painter = canvas.getContext("2d", opts);
|
|
182
|
+
this.__region = region;
|
|
183
|
+
this.__isPainter = isPainter;
|
|
184
|
+
this.painter.textBaseline = 'middle';
|
|
185
|
+
this.painter.textAlign = 'left';
|
|
186
|
+
}
|
|
187
|
+
Painter.prototype.useConfig = function (key, value) {
|
|
188
|
+
if (this.__region) {
|
|
189
|
+
if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
|
|
190
|
+
this.__region.useConfig(key, value);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
194
|
+
return this;
|
|
195
|
+
if (key == 'lineDash') {
|
|
196
|
+
if (this.painter.setLineDash)
|
|
197
|
+
this.painter.setLineDash(value);
|
|
198
|
+
}
|
|
199
|
+
else if (key in this.__specialConfig) {
|
|
200
|
+
if (key == 'fontSize') {
|
|
201
|
+
value = Math.round(value);
|
|
202
|
+
}
|
|
203
|
+
this.__specialConfig[key] = value;
|
|
204
|
+
}
|
|
205
|
+
else if (key in this.__initConfig) {
|
|
206
|
+
this.painter[key] = value;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw new Error('Illegal configuration item of painter : ' + key + " !");
|
|
210
|
+
}
|
|
211
|
+
return this;
|
|
212
|
+
};
|
|
213
|
+
Painter.prototype.fillText = function (text, x, y, deg) {
|
|
214
|
+
if (deg === void 0) { deg = 0; }
|
|
215
|
+
if (this.__region)
|
|
216
|
+
this.__region.fillText(text, x, y, deg);
|
|
217
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
218
|
+
return this;
|
|
219
|
+
this.painter.save();
|
|
220
|
+
initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
|
|
221
|
+
this.painter.restore();
|
|
222
|
+
return this;
|
|
223
|
+
};
|
|
224
|
+
Painter.prototype.strokeText = function (text, x, y, deg) {
|
|
225
|
+
if (deg === void 0) { deg = 0; }
|
|
226
|
+
if (this.__region)
|
|
227
|
+
this.__region.strokeText(text, x, y, deg);
|
|
228
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
229
|
+
return this;
|
|
230
|
+
this.painter.save();
|
|
231
|
+
initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
|
|
232
|
+
this.painter.restore();
|
|
233
|
+
return this;
|
|
234
|
+
};
|
|
235
|
+
Painter.prototype.fullText = function (text, x, y, deg) {
|
|
236
|
+
if (deg === void 0) { deg = 0; }
|
|
237
|
+
if (this.__region)
|
|
238
|
+
this.__region.fullText(text, x, y, deg);
|
|
239
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
240
|
+
return this;
|
|
241
|
+
this.painter.save();
|
|
242
|
+
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
243
|
+
this.painter.fillText(text, 0, 0);
|
|
244
|
+
this.painter.strokeText(text, 0, 0);
|
|
245
|
+
this.painter.restore();
|
|
246
|
+
return this;
|
|
247
|
+
};
|
|
248
|
+
Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
249
|
+
var _this = this;
|
|
250
|
+
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
251
|
+
if (deg === void 0) { deg = 0; }
|
|
252
|
+
var h = 0;
|
|
253
|
+
if (this.__region)
|
|
254
|
+
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
255
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
256
|
+
return h;
|
|
257
|
+
this.painter.save();
|
|
258
|
+
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
259
|
+
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
260
|
+
_this.painter.fillText(content, 0, top);
|
|
261
|
+
});
|
|
262
|
+
this.painter.restore();
|
|
263
|
+
return height;
|
|
264
|
+
};
|
|
265
|
+
Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
266
|
+
var _this = this;
|
|
267
|
+
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
268
|
+
if (deg === void 0) { deg = 0; }
|
|
269
|
+
var h = 0;
|
|
270
|
+
if (this.__region)
|
|
271
|
+
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
272
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
273
|
+
return h;
|
|
274
|
+
this.painter.save();
|
|
275
|
+
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
276
|
+
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
277
|
+
_this.painter.strokeText(content, 0, top);
|
|
278
|
+
});
|
|
279
|
+
this.painter.restore();
|
|
280
|
+
return height;
|
|
281
|
+
};
|
|
282
|
+
Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
283
|
+
var _this = this;
|
|
284
|
+
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
285
|
+
if (deg === void 0) { deg = 0; }
|
|
286
|
+
var h = 0;
|
|
287
|
+
if (this.__region)
|
|
288
|
+
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
289
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
290
|
+
return h;
|
|
291
|
+
this.painter.save();
|
|
292
|
+
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
293
|
+
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
294
|
+
_this.painter.fillText(content, 0, top);
|
|
295
|
+
_this.painter.strokeText(content, 0, top);
|
|
296
|
+
});
|
|
297
|
+
this.painter.restore();
|
|
298
|
+
return height;
|
|
299
|
+
};
|
|
300
|
+
Painter.prototype.beginPath = function () {
|
|
301
|
+
if (this.__region)
|
|
302
|
+
this.__region.beginPath();
|
|
303
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
304
|
+
return this;
|
|
305
|
+
this.painter.beginPath();
|
|
306
|
+
return this;
|
|
307
|
+
};
|
|
308
|
+
Painter.prototype.closePath = function () {
|
|
309
|
+
if (this.__region)
|
|
310
|
+
this.__region.closePath();
|
|
311
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
312
|
+
return this;
|
|
313
|
+
this.painter.closePath();
|
|
314
|
+
return this;
|
|
315
|
+
};
|
|
316
|
+
Painter.prototype.moveTo = function (x, y) {
|
|
317
|
+
if (this.__region)
|
|
318
|
+
this.__region.moveTo(x, y);
|
|
319
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
320
|
+
return this;
|
|
321
|
+
this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
|
|
322
|
+
return this;
|
|
323
|
+
};
|
|
324
|
+
Painter.prototype.lineTo = function (x, y) {
|
|
325
|
+
if (this.__region)
|
|
326
|
+
this.__region.lineTo(x, y);
|
|
327
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
328
|
+
return this;
|
|
329
|
+
this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
|
|
330
|
+
return this;
|
|
331
|
+
};
|
|
332
|
+
Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
|
|
333
|
+
if (this.__region)
|
|
334
|
+
this.__region.arc(x, y, r, beginDeg, deg);
|
|
335
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
336
|
+
return this;
|
|
337
|
+
this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
|
|
338
|
+
return this;
|
|
339
|
+
};
|
|
340
|
+
Painter.prototype.fill = function () {
|
|
341
|
+
if (this.__region)
|
|
342
|
+
this.__region.fill();
|
|
343
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
344
|
+
return this;
|
|
345
|
+
this.painter.fill();
|
|
346
|
+
return this;
|
|
347
|
+
};
|
|
348
|
+
Painter.prototype.stroke = function () {
|
|
349
|
+
if (this.__region)
|
|
350
|
+
this.__region.stroke();
|
|
351
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
352
|
+
return this;
|
|
353
|
+
this.painter.stroke();
|
|
354
|
+
return this;
|
|
355
|
+
};
|
|
356
|
+
Painter.prototype.full = function () {
|
|
357
|
+
if (this.__region)
|
|
358
|
+
this.__region.full();
|
|
359
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
360
|
+
return this;
|
|
361
|
+
this.painter.fill();
|
|
362
|
+
this.painter.stroke();
|
|
363
|
+
return this;
|
|
364
|
+
};
|
|
365
|
+
Painter.prototype.save = function () {
|
|
366
|
+
if (this.__region)
|
|
367
|
+
this.__region.save();
|
|
368
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
369
|
+
return this;
|
|
370
|
+
this.painter.save();
|
|
371
|
+
return this;
|
|
372
|
+
};
|
|
373
|
+
Painter.prototype.restore = function () {
|
|
374
|
+
if (this.__region)
|
|
375
|
+
this.__region.restore();
|
|
376
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
377
|
+
return this;
|
|
378
|
+
this.painter.restore();
|
|
379
|
+
return this;
|
|
380
|
+
};
|
|
381
|
+
Painter.prototype.clip = function () {
|
|
382
|
+
if (this.__region)
|
|
383
|
+
this.__region.clip();
|
|
384
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
385
|
+
return this;
|
|
386
|
+
this.painter.clip();
|
|
387
|
+
return this;
|
|
388
|
+
};
|
|
389
|
+
Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
390
|
+
if (this.__region)
|
|
391
|
+
this.__region.quadraticCurveTo(cpx, cpy, x, y);
|
|
392
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
393
|
+
return this;
|
|
394
|
+
this.painter.quadraticCurveTo(cpx, cpy, x, y);
|
|
395
|
+
return this;
|
|
396
|
+
};
|
|
397
|
+
Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
398
|
+
if (this.__region)
|
|
399
|
+
this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
400
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
401
|
+
return this;
|
|
402
|
+
this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
403
|
+
return this;
|
|
404
|
+
};
|
|
405
|
+
Painter.prototype.clearRect = function (x, y, w, h) {
|
|
406
|
+
if (this.__region)
|
|
407
|
+
this.__region.clearRect(x, y, w, h);
|
|
408
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
409
|
+
return this;
|
|
410
|
+
this.painter.clearRect(x, y, w, h);
|
|
411
|
+
return this;
|
|
412
|
+
};
|
|
413
|
+
Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
414
|
+
if (this.__region)
|
|
415
|
+
this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
|
|
416
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
417
|
+
return this;
|
|
418
|
+
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
|
|
419
|
+
return this;
|
|
420
|
+
};
|
|
421
|
+
Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
422
|
+
if (this.__region)
|
|
423
|
+
this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
|
|
424
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
425
|
+
return this;
|
|
426
|
+
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
|
|
427
|
+
return this;
|
|
428
|
+
};
|
|
429
|
+
Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
430
|
+
if (this.__region)
|
|
431
|
+
this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
|
|
432
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
433
|
+
return this;
|
|
434
|
+
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
|
|
435
|
+
this.painter.fill();
|
|
436
|
+
this.painter.stroke();
|
|
437
|
+
return this;
|
|
438
|
+
};
|
|
439
|
+
Painter.prototype.fillCircle = function (cx, cy, r) {
|
|
440
|
+
if (this.__region)
|
|
441
|
+
this.__region.fillCircle(cx, cy, r);
|
|
442
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
443
|
+
return this;
|
|
444
|
+
initCircle(this.painter, cx, cy, r).fill();
|
|
445
|
+
return this;
|
|
446
|
+
};
|
|
447
|
+
Painter.prototype.strokeCircle = function (cx, cy, r) {
|
|
448
|
+
if (this.__region)
|
|
449
|
+
this.__region.strokeCircle(cx, cy, r);
|
|
450
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
451
|
+
return this;
|
|
452
|
+
initCircle(this.painter, cx, cy, r).stroke();
|
|
453
|
+
return this;
|
|
454
|
+
};
|
|
455
|
+
Painter.prototype.fullCircle = function (cx, cy, r) {
|
|
456
|
+
if (this.__region)
|
|
457
|
+
this.__region.fullCircle(cx, cy, r);
|
|
458
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
459
|
+
return this;
|
|
460
|
+
initCircle(this.painter, cx, cy, r);
|
|
461
|
+
this.painter.fill();
|
|
462
|
+
this.painter.stroke();
|
|
463
|
+
return this;
|
|
464
|
+
};
|
|
465
|
+
Painter.prototype.fillRect = function (x, y, width, height) {
|
|
466
|
+
if (this.__region)
|
|
467
|
+
this.__region.fillRect(x, y, width, height);
|
|
468
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
469
|
+
return this;
|
|
470
|
+
initRect(this.painter, x, y, width, height).fill();
|
|
471
|
+
return this;
|
|
472
|
+
};
|
|
473
|
+
Painter.prototype.strokeRect = function (x, y, width, height) {
|
|
474
|
+
if (this.__region)
|
|
475
|
+
this.__region.strokeRect(x, y, width, height);
|
|
476
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
477
|
+
return this;
|
|
478
|
+
initRect(this.painter, x, y, width, height).stroke();
|
|
479
|
+
return this;
|
|
480
|
+
};
|
|
481
|
+
Painter.prototype.fullRect = function (x, y, width, height) {
|
|
482
|
+
if (this.__region)
|
|
483
|
+
this.__region.fullRect(x, y, width, height);
|
|
484
|
+
if (this.__isPainter && this.__onlyRegion)
|
|
485
|
+
return this;
|
|
486
|
+
initRect(this.painter, x, y, width, height);
|
|
487
|
+
this.painter.fill();
|
|
488
|
+
this.painter.stroke();
|
|
489
|
+
return this;
|
|
490
|
+
};
|
|
491
|
+
Painter.prototype.draw = function () { };
|
|
492
|
+
return Painter;
|
|
493
|
+
}());
|
|
494
|
+
|
|
495
|
+
function assemble (begin, end, step, count) {
|
|
496
|
+
var val = [];
|
|
497
|
+
for (var index = 0; index < count; index++)
|
|
498
|
+
val[index] = begin;
|
|
499
|
+
return function () {
|
|
500
|
+
for (var i = 0; i < count; i++) {
|
|
501
|
+
if (val[i] + step < end) {
|
|
502
|
+
val[i] = +(val[i] + step).toFixed(7);
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
else if (i < count - 1) {
|
|
506
|
+
val[i] = begin;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return val;
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
var linearGradient = function (painter, x0, y0, x1, y1) {
|
|
514
|
+
var gradient = painter.createLinearGradient(x0, y0, x1, y1);
|
|
515
|
+
var enhanceGradient = {
|
|
516
|
+
"value": function () {
|
|
517
|
+
return gradient;
|
|
518
|
+
},
|
|
519
|
+
"setColor": function (stop, color) {
|
|
520
|
+
gradient.addColorStop(stop, color);
|
|
521
|
+
return enhanceGradient;
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
return enhanceGradient;
|
|
525
|
+
};
|
|
526
|
+
var radialGradient = function (painter, cx, cy, r) {
|
|
527
|
+
var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
528
|
+
var enhanceGradient = {
|
|
529
|
+
"value": function () {
|
|
530
|
+
return gradient;
|
|
531
|
+
},
|
|
532
|
+
"setColor": function (stop, color) {
|
|
533
|
+
gradient.addColorStop(stop, color);
|
|
534
|
+
return enhanceGradient;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
return enhanceGradient;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
var oldAttrName = {
|
|
541
|
+
"font-size": "fontSize",
|
|
542
|
+
"font-family": "fontFamily",
|
|
543
|
+
"font-weight": "fontWeight",
|
|
544
|
+
"font-style": "fontStyle",
|
|
545
|
+
"arc-start-cap": "arcStartCap",
|
|
546
|
+
"arc-end-cap": "arcEndCap",
|
|
547
|
+
};
|
|
548
|
+
var Canvas = (function (_super) {
|
|
549
|
+
__extends(Canvas, _super);
|
|
550
|
+
function Canvas(ViewCanvas, RegionCanvas) {
|
|
551
|
+
var _this = _super.call(this, ViewCanvas, {}, RegionCanvas ? new Painter(RegionCanvas, {
|
|
552
|
+
willReadFrequently: true,
|
|
553
|
+
}) : null, true) || this;
|
|
554
|
+
_this.name = "Canvas";
|
|
555
|
+
_this.__regionList = {};
|
|
556
|
+
_this.__regionAssemble = assemble(0, 255, 10, 3);
|
|
557
|
+
_this.setRegion("");
|
|
558
|
+
return _this;
|
|
559
|
+
}
|
|
560
|
+
Canvas.prototype.config = function (configs) {
|
|
561
|
+
for (var key in configs) {
|
|
562
|
+
var _key = oldAttrName[key] || key;
|
|
563
|
+
this.useConfig(_key, configs[key]);
|
|
564
|
+
}
|
|
565
|
+
return this;
|
|
566
|
+
};
|
|
567
|
+
Canvas.prototype.onlyRegion = function (flag) {
|
|
568
|
+
this.__onlyRegion = flag;
|
|
569
|
+
return this;
|
|
570
|
+
};
|
|
571
|
+
Canvas.prototype.setRegion = function (regionName) {
|
|
572
|
+
if (this.__region) {
|
|
573
|
+
if (regionName) {
|
|
574
|
+
if (this.__regionList[regionName] == void 0) {
|
|
575
|
+
var tempColor = this.__regionAssemble();
|
|
576
|
+
this.__regionList[regionName] =
|
|
577
|
+
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
|
|
578
|
+
}
|
|
579
|
+
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
580
|
+
this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
this.__region.useConfig("fillStyle", "#000000") &&
|
|
584
|
+
this.__region.useConfig("strokeStyle", "#000000");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return this;
|
|
588
|
+
};
|
|
589
|
+
Canvas.prototype.getRegion = function (x, y) {
|
|
590
|
+
var _this = this;
|
|
591
|
+
return new Promise(function (resolve, reject) {
|
|
592
|
+
var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
|
|
593
|
+
data: [0, 0, 0, 0]
|
|
594
|
+
};
|
|
595
|
+
var currentRGBA = imgData.data;
|
|
596
|
+
var doit = function () {
|
|
597
|
+
if (_this.__region) {
|
|
598
|
+
for (var key in _this.__regionList) {
|
|
599
|
+
if ("rgb(" +
|
|
600
|
+
currentRGBA[0] +
|
|
601
|
+
"," +
|
|
602
|
+
currentRGBA[1] +
|
|
603
|
+
"," +
|
|
604
|
+
currentRGBA[2] +
|
|
605
|
+
")" ==
|
|
606
|
+
_this.__regionList[key]) {
|
|
607
|
+
resolve(key);
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
resolve("");
|
|
613
|
+
};
|
|
614
|
+
if (currentRGBA) {
|
|
615
|
+
doit();
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
imgData.then(function (data) {
|
|
619
|
+
currentRGBA = data;
|
|
620
|
+
doit();
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
};
|
|
625
|
+
Canvas.prototype.textWidth = function (text) {
|
|
626
|
+
this.painter.save();
|
|
627
|
+
initText(this.painter, this.__specialConfig, 0, 0, 0);
|
|
628
|
+
var width = this.painter.measureText(text + "").width;
|
|
629
|
+
this.painter.restore();
|
|
630
|
+
return width;
|
|
631
|
+
};
|
|
632
|
+
Canvas.prototype.getContext = function (isRegion) {
|
|
633
|
+
if (isRegion === void 0) { isRegion = false; }
|
|
634
|
+
return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
|
|
635
|
+
};
|
|
636
|
+
Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
|
|
637
|
+
return linearGradient(this.painter, x0, y0, x1, y1);
|
|
638
|
+
};
|
|
639
|
+
Canvas.prototype.createRadialGradient = function (cx, cy, r) {
|
|
640
|
+
return radialGradient(this.painter, cx, cy, r);
|
|
641
|
+
};
|
|
642
|
+
Canvas.prototype.getColor = function (x, y) {
|
|
643
|
+
var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
|
|
644
|
+
return ("rgba(" +
|
|
645
|
+
currentRGBA[0] +
|
|
646
|
+
"," +
|
|
647
|
+
currentRGBA[1] +
|
|
648
|
+
"," +
|
|
649
|
+
currentRGBA[2] +
|
|
650
|
+
"," +
|
|
651
|
+
currentRGBA[3] +
|
|
652
|
+
")");
|
|
653
|
+
};
|
|
654
|
+
return Canvas;
|
|
655
|
+
}(Painter));
|
|
656
|
+
|
|
657
|
+
export { Canvas as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* VISLite JavaScript Library v0.5.2-alpha.2
|
|
3
|
+
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
+
*
|
|
5
|
+
* Copyright zxl20070701
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
+
*
|
|
9
|
+
* Publish Date: Mon Oct 23 2023 22:21:10 GMT+0800 (中国标准时间)
|
|
10
|
+
*/
|
|
11
|
+
var t=function(i,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])},t(i,e)};"function"==typeof SuppressedError&&SuppressedError;var i=function(t,i,e,n,r){var o=Math.cos(e),s=Math.sin(e);return[+((n-t)*o-(r-i)*s+t).toFixed(7),+((n-t)*s+(r-i)*o+i).toFixed(7)]};var e=function(t,i,e,n,r){return t.beginPath(),t.translate(e,n),t.rotate(r),t.font=i.fontStyle+" "+i.fontWeight+" "+i.fontSize+"px "+i.fontFamily,t},n=function(t,e,n,r,o,s,_,a){if(o>s){var h=o;o=s,s=h}return _%=2*Math.PI,a>=1.999999*Math.PI||a<=1.999999*-Math.PI?a=2*Math.PI:a%=2*Math.PI,function(t,e,n,r,o,s,_){e<0&&(t+=e,e*=-1);var a,h=[];a=i(0,0,t,o,0),h[0]=a[0],h[1]=a[1],a=i(0,0,e,a[0],a[1]),h[2]=a[0],h[3]=a[1],a=i(0,0,t,s,0),h[4]=a[0],h[5]=a[1],a=i(0,0,e,a[0],a[1]),h[6]=a[0],h[7]=a[1],_(t,t+e,h[0]+n,h[1]+r,h[4]+n,h[5]+r,h[2]+n,h[3]+r,h[6]+n,h[7]+r,.5*(s-o))}(_,a,n,r,o,s,(function(i,_,a,h,l,p,f,u,g,c,y){y<0&&(y=-y),t.beginPath(),t.moveTo(a,h),t.arc(n,r,o,i,_,!1),"round"==e.arcEndCap?t.arc(.5*(f+g),.5*(u+c),y,_-Math.PI,_,!0):"-round"==e.arcEndCap?t.arc(.5*(f+g),.5*(u+c),y,_-Math.PI,_,!1):t.lineTo(g,c),t.arc(n,r,s,_,i,!0),"round"==e.arcStartCap?t.arc(.5*(a+l),.5*(h+p),y,i,i-Math.PI,!0):"-round"==e.arcStartCap?t.arc(.5*(a+l),.5*(h+p),y,i,i-Math.PI,!1):t.lineTo(a,h)})),"butt"==e.arcStartCap&&t.closePath(),t},r=function(t,i,e,n){return t.beginPath(),t.moveTo(i+n,e),t.arc(i,e,n,0,2*Math.PI),t},o=function(t,i,e,n,r){return t.beginPath(),t.rect(i,e,n,r),t};function s(t,i,e,n,r){for(var o=0,s="",_=0;_<i.length;_++)t.measureText(s+i[_]).width>e||/\n$/.test(s)?(r(s,((o+=1)-.5)*n),s=i[_]):_==i.length-1?(o+=1,r(s+i[_],(o-.5)*n)):s+=i[_];return o*n}var _=function(){function t(t,i,e,n){void 0===i&&(i={}),void 0===n&&(n=!1),this.__region=null,this.__onlyRegion=!1,this.__specialConfig={fontSize:16,fontFamily:"sans-serif",fontWeight:400,fontStyle:"normal",arcStartCap:"butt",arcEndCap:"butt"},this.__initConfig={fillStyle:"black",strokeStyle:"black",lineWidth:1,textAlign:"left",textBaseline:"middle",lineDash:[],shadowBlur:0,shadowColor:"black"},this.painter=t.getContext("2d",i),this.__region=e,this.__isPainter=n,this.painter.textBaseline="middle",this.painter.textAlign="left"}return t.prototype.useConfig=function(t,i){if(this.__region&&["fillStyle","strokeStyle","shadowBlur","shadowColor"].indexOf(t)<0&&this.__region.useConfig(t,i),this.__isPainter&&this.__onlyRegion)return this;if("lineDash"==t)this.painter.setLineDash&&this.painter.setLineDash(i);else if(t in this.__specialConfig)"fontSize"==t&&(i=Math.round(i)),this.__specialConfig[t]=i;else{if(!(t in this.__initConfig))throw new Error("Illegal configuration item of painter : "+t+" !");this.painter[t]=i}return this},t.prototype.fillText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.fillText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r).fillText(t,0,0),this.painter.restore()),this},t.prototype.strokeText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.strokeText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r).strokeText(t,0,0),this.painter.restore()),this},t.prototype.fullText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.fullText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r),this.painter.fillText(t,0,0),this.painter.strokeText(t,0,0),this.painter.restore()),this},t.prototype.fillTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.fillText(t,0,i)}));return this.painter.restore(),l},t.prototype.strokeTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.strokeText(t,0,i)}));return this.painter.restore(),l},t.prototype.fullTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.fillText(t,0,i),a.painter.strokeText(t,0,i)}));return this.painter.restore(),l},t.prototype.beginPath=function(){return this.__region&&this.__region.beginPath(),this.__isPainter&&this.__onlyRegion||this.painter.beginPath(),this},t.prototype.closePath=function(){return this.__region&&this.__region.closePath(),this.__isPainter&&this.__onlyRegion||this.painter.closePath(),this},t.prototype.moveTo=function(t,i){return this.__region&&this.__region.moveTo(t,i),this.__isPainter&&this.__onlyRegion||this.painter.moveTo(Math.round(t)+.5,Math.round(i)+.5),this},t.prototype.lineTo=function(t,i){return this.__region&&this.__region.lineTo(t,i),this.__isPainter&&this.__onlyRegion||this.painter.lineTo(Math.round(t)+.5,Math.round(i)+.5),this},t.prototype.arc=function(t,i,e,n,r){return this.__region&&this.__region.arc(t,i,e,n,r),this.__isPainter&&this.__onlyRegion||this.painter.arc(t,i,e,n,n+r,r<0),this},t.prototype.fill=function(){return this.__region&&this.__region.fill(),this.__isPainter&&this.__onlyRegion||this.painter.fill(),this},t.prototype.stroke=function(){return this.__region&&this.__region.stroke(),this.__isPainter&&this.__onlyRegion||this.painter.stroke(),this},t.prototype.full=function(){return this.__region&&this.__region.full(),this.__isPainter&&this.__onlyRegion||(this.painter.fill(),this.painter.stroke()),this},t.prototype.save=function(){return this.__region&&this.__region.save(),this.__isPainter&&this.__onlyRegion||this.painter.save(),this},t.prototype.restore=function(){return this.__region&&this.__region.restore(),this.__isPainter&&this.__onlyRegion||this.painter.restore(),this},t.prototype.clip=function(){return this.__region&&this.__region.clip(),this.__isPainter&&this.__onlyRegion||this.painter.clip(),this},t.prototype.quadraticCurveTo=function(t,i,e,n){return this.__region&&this.__region.quadraticCurveTo(t,i,e,n),this.__isPainter&&this.__onlyRegion||this.painter.quadraticCurveTo(t,i,e,n),this},t.prototype.bezierCurveTo=function(t,i,e,n,r,o){return this.__region&&this.__region.bezierCurveTo(t,i,e,n,r,o),this.__isPainter&&this.__onlyRegion||this.painter.bezierCurveTo(t,i,e,n,r,o),this},t.prototype.clearRect=function(t,i,e,n){return this.__region&&this.__region.clearRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||this.painter.clearRect(t,i,e,n),this},t.prototype.fillArc=function(t,i,e,r,o,s){return this.__region&&this.__region.fillArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||n(this.painter,this.__specialConfig,t,i,e,r,o,s).fill(),this},t.prototype.strokeArc=function(t,i,e,r,o,s){return this.__region&&this.__region.strokeArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||n(this.painter,this.__specialConfig,t,i,e,r,o,s).stroke(),this},t.prototype.fullArc=function(t,i,e,r,o,s){return this.__region&&this.__region.fullArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||(n(this.painter,this.__specialConfig,t,i,e,r,o,s),this.painter.fill(),this.painter.stroke()),this},t.prototype.fillCircle=function(t,i,e){return this.__region&&this.__region.fillCircle(t,i,e),this.__isPainter&&this.__onlyRegion||r(this.painter,t,i,e).fill(),this},t.prototype.strokeCircle=function(t,i,e){return this.__region&&this.__region.strokeCircle(t,i,e),this.__isPainter&&this.__onlyRegion||r(this.painter,t,i,e).stroke(),this},t.prototype.fullCircle=function(t,i,e){return this.__region&&this.__region.fullCircle(t,i,e),this.__isPainter&&this.__onlyRegion||(r(this.painter,t,i,e),this.painter.fill(),this.painter.stroke()),this},t.prototype.fillRect=function(t,i,e,n){return this.__region&&this.__region.fillRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||o(this.painter,t,i,e,n).fill(),this},t.prototype.strokeRect=function(t,i,e,n){return this.__region&&this.__region.strokeRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||o(this.painter,t,i,e,n).stroke(),this},t.prototype.fullRect=function(t,i,e,n){return this.__region&&this.__region.fullRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||(o(this.painter,t,i,e,n),this.painter.fill(),this.painter.stroke()),this},t.prototype.draw=function(){},t}();var a={"font-size":"fontSize","font-family":"fontFamily","font-weight":"fontWeight","font-style":"fontStyle","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},h=function(i){function n(t,e){var n=i.call(this,t,{},e?new _(e,{willReadFrequently:!0}):null,!0)||this;return n.name="Canvas",n.__regionList={},n.__regionAssemble=function(t,i,e,n){for(var r=[],o=0;o<n;o++)r[o]=t;return function(){for(var o=0;o<n;o++){if(r[o]+e<i){r[o]=+(r[o]+e).toFixed(7);break}o<n-1&&(r[o]=t)}return r}}(0,255,10,3),n.setRegion(""),n}return function(i,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,i),n.prototype.config=function(t){for(var i in t){var e=a[i]||i;this.useConfig(e,t[i])}return this},n.prototype.onlyRegion=function(t){return this.__onlyRegion=t,this},n.prototype.setRegion=function(t){if(this.__region)if(t){if(null==this.__regionList[t]){var i=this.__regionAssemble();this.__regionList[t]="rgb("+i[0]+","+i[1]+","+i[2]+")"}this.__region.useConfig("fillStyle",this.__regionList[t])&&this.__region.useConfig("strokeStyle",this.__regionList[t])}else this.__region.useConfig("fillStyle","#000000")&&this.__region.useConfig("strokeStyle","#000000");return this},n.prototype.getRegion=function(t,i){var e=this;return new Promise((function(n,r){var o=e.__region?e.__region.painter.getImageData(t-.5,i-.5,1,1):{data:[0,0,0,0]},s=o.data,_=function(){if(e.__region)for(var t in e.__regionList)if("rgb("+s[0]+","+s[1]+","+s[2]+")"==e.__regionList[t]){n(t);break}n("")};s?_():o.then((function(t){s=t,_()}))}))},n.prototype.textWidth=function(t){this.painter.save(),e(this.painter,this.__specialConfig,0,0,0);var i=this.painter.measureText(t+"").width;return this.painter.restore(),i},n.prototype.getContext=function(t){return void 0===t&&(t=!1),t?this.__region?this.__region.painter:null:this.painter},n.prototype.createLinearGradient=function(t,i,e,n){return function(t,i,e,n,r){var o=t.createLinearGradient(i,e,n,r),s={value:function(){return o},setColor:function(t,i){return o.addColorStop(t,i),s}};return s}(this.painter,t,i,e,n)},n.prototype.createRadialGradient=function(t,i,e){return function(t,i,e,n){var r=t.createRadialGradient(i,e,0,i,e,n),o={value:function(){return r},setColor:function(t,i){return r.addColorStop(t,i),o}};return o}(this.painter,t,i,e)},n.prototype.getColor=function(t,i){var e=this.painter.getImageData(t-.5,i-.5,1,1).data;return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"},n}(_);export{h as default};
|