vislite 0.2.0 → 0.3.0-alpha.0
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/AUTHORS.txt +6 -6
- package/CHANGELOG +19 -1
- package/LICENSE +20 -20
- package/README.md +53 -53
- package/lib/Canvas/index.umd.js +91 -14
- package/lib/Canvas/index.umd.min.js +7 -3
- package/lib/Cardinal/index.umd.js +6 -2
- package/lib/Cardinal/index.umd.min.js +6 -2
- package/lib/Eoap/index.umd.js +6 -2
- package/lib/Eoap/index.umd.min.js +6 -2
- package/lib/Hermite/index.umd.js +6 -2
- package/lib/Hermite/index.umd.min.js +6 -2
- package/lib/Matrix4/index.umd.js +6 -2
- package/lib/Matrix4/index.umd.min.js +6 -2
- package/lib/Mercator/index.umd.js +6 -2
- package/lib/Mercator/index.umd.min.js +6 -2
- package/lib/OralCanvas/index.es.js +91 -14
- package/lib/OralCanvas/index.es.min.js +7 -3
- package/lib/OralWebGL/index.es.js +8 -2
- package/lib/OralWebGL/index.es.min.js +6 -2
- package/lib/SVG/index.umd.js +82 -62
- package/lib/SVG/index.umd.min.js +7 -3
- package/lib/WebGL/index.umd.js +6 -2
- package/lib/WebGL/index.umd.min.js +6 -2
- package/lib/animation/index.umd.js +6 -2
- package/lib/animation/index.umd.min.js +6 -2
- package/lib/getLoopColors/index.umd.js +6 -2
- package/lib/getLoopColors/index.umd.min.js +6 -2
- package/lib/index.umd.js +167 -74
- package/lib/index.umd.min.js +7 -3
- package/lib/rotate/index.umd.js +6 -2
- package/lib/rotate/index.umd.min.js +6 -2
- package/lib/ruler/index.umd.js +6 -2
- package/lib/ruler/index.umd.min.js +6 -2
- package/lib/viewHandler/index.umd.js +6 -2
- package/lib/viewHandler/index.umd.min.js +6 -2
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Canvas/index.ts +1 -1
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/OralCanvas/index.ts +1 -1
- package/package/OralWebGL/index.ts +1 -1
- package/package/SVG/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package.json +4 -4
- package/src/Matrix4/index.ts +76 -76
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/animation.ts +99 -99
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +142 -61
- package/src/common/canvas/gradient.ts +29 -0
- package/src/common/canvas/index.ts +122 -82
- package/src/common/canvas/painter.ts +12 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +173 -128
- package/src/common/svg/index.ts +315 -266
- package/src/common/svg/tool.ts +43 -43
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +91 -91
- package/src/interpolation/Hermite.ts +65 -65
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +99 -99
- package/types/Canvas.d.ts +282 -221
- package/types/CanvasConfig.d.ts +3 -3
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +15 -0
- package/types/Hermite.d.ts +18 -18
- package/types/Matrix4.d.ts +42 -42
- package/types/SVG.d.ts +210 -210
- package/types/animation.d.ts +6 -6
- package/types/getLoopColors.d.ts +2 -2
- package/types/rotate.d.ts +2 -2
- package/types/ruler.d.ts +2 -2
- package/uni-app/ui-canvas.vue +22 -46
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
var e,t;e=this,t=function(){"use strict";return function(e,t){void 0===e&&(e=7),void 0===t&&(t=[107,36]),this.name="Mercator";var o=100*e*Math.PI/180,i=o*t[0],n=-1*o*t[1];this.use=function(e,t){return[.8*(o*e-i),-1*o*t-n]}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_Mercator=t();
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
/******************************************************************************
|
|
12
16
|
Copyright (c) Microsoft Corporation.
|
|
@@ -71,7 +75,14 @@ var initText = function (painter, config, x, y, deg) {
|
|
|
71
75
|
painter.beginPath();
|
|
72
76
|
painter.translate(x, y);
|
|
73
77
|
painter.rotate(deg);
|
|
74
|
-
painter.font =
|
|
78
|
+
painter.font =
|
|
79
|
+
config.fontStyle +
|
|
80
|
+
" " +
|
|
81
|
+
config.fontWeight +
|
|
82
|
+
" " +
|
|
83
|
+
config.fontSize +
|
|
84
|
+
"px " +
|
|
85
|
+
config.fontFamily;
|
|
75
86
|
return painter;
|
|
76
87
|
};
|
|
77
88
|
var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
@@ -93,17 +104,21 @@ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
|
93
104
|
painter.beginPath();
|
|
94
105
|
painter.moveTo(begInnerX, begInnerY);
|
|
95
106
|
painter.arc(cx, cy, r1, beginA, endA, false);
|
|
96
|
-
if (config.arcEndCap
|
|
97
|
-
painter.lineTo(endOuterX, endOuterY);
|
|
98
|
-
else
|
|
107
|
+
if (config.arcEndCap == "round")
|
|
99
108
|
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
painter.lineTo(begInnerX, begInnerY);
|
|
109
|
+
else if (config.arcEndCap == "-round")
|
|
110
|
+
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
|
|
103
111
|
else
|
|
112
|
+
painter.lineTo(endOuterX, endOuterY);
|
|
113
|
+
painter.arc(cx, cy, r2, endA, beginA, true);
|
|
114
|
+
if (config.arcStartCap == "round")
|
|
104
115
|
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
|
|
116
|
+
else if (config.arcStartCap == "-round")
|
|
117
|
+
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
|
|
118
|
+
else
|
|
119
|
+
painter.lineTo(begInnerX, begInnerY);
|
|
105
120
|
});
|
|
106
|
-
if (config.arcStartCap ==
|
|
121
|
+
if (config.arcStartCap == "butt")
|
|
107
122
|
painter.closePath();
|
|
108
123
|
return painter;
|
|
109
124
|
};
|
|
@@ -176,6 +191,9 @@ var Painter = (function () {
|
|
|
176
191
|
this.painter.setLineDash(value);
|
|
177
192
|
}
|
|
178
193
|
else if (key in this.__specialConfig) {
|
|
194
|
+
if (key == 'fontSize') {
|
|
195
|
+
value = Math.round(value);
|
|
196
|
+
}
|
|
179
197
|
this.__specialConfig[key] = value;
|
|
180
198
|
}
|
|
181
199
|
else if (key in this.__initConfig) {
|
|
@@ -319,6 +337,12 @@ var Painter = (function () {
|
|
|
319
337
|
this.painter.restore();
|
|
320
338
|
return this;
|
|
321
339
|
};
|
|
340
|
+
Painter.prototype.clip = function () {
|
|
341
|
+
if (this.__region)
|
|
342
|
+
this.__region.clip();
|
|
343
|
+
this.painter.clip();
|
|
344
|
+
return this;
|
|
345
|
+
};
|
|
322
346
|
Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
323
347
|
if (this.__region)
|
|
324
348
|
this.__region.quadraticCurveTo(cpx, cpy, x, y);
|
|
@@ -418,19 +442,46 @@ function assemble (begin, end, step, count) {
|
|
|
418
442
|
};
|
|
419
443
|
}
|
|
420
444
|
|
|
445
|
+
var linearGradient = function (painter, x0, y0, x1, y1) {
|
|
446
|
+
var gradient = painter.createLinearGradient(x0, y0, x1, y1);
|
|
447
|
+
var enhanceGradient = {
|
|
448
|
+
"value": function () {
|
|
449
|
+
return gradient;
|
|
450
|
+
},
|
|
451
|
+
"setColor": function (stop, color) {
|
|
452
|
+
gradient.addColorStop(stop, color);
|
|
453
|
+
return enhanceGradient;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
return enhanceGradient;
|
|
457
|
+
};
|
|
458
|
+
var radialGradient = function (painter, cx, cy, r) {
|
|
459
|
+
var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
460
|
+
var enhanceGradient = {
|
|
461
|
+
"value": function () {
|
|
462
|
+
return gradient;
|
|
463
|
+
},
|
|
464
|
+
"setColor": function (stop, color) {
|
|
465
|
+
gradient.addColorStop(stop, color);
|
|
466
|
+
return enhanceGradient;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
return enhanceGradient;
|
|
470
|
+
};
|
|
471
|
+
|
|
421
472
|
var oldAttrName = {
|
|
422
473
|
"font-size": "fontSize",
|
|
423
474
|
"font-family": "fontFamily",
|
|
424
475
|
"font-weight": "fontWeight",
|
|
425
476
|
"font-style": "fontStyle",
|
|
426
477
|
"arc-start-cap": "arcStartCap",
|
|
427
|
-
"arc-end-cap": "arcEndCap"
|
|
478
|
+
"arc-end-cap": "arcEndCap",
|
|
428
479
|
};
|
|
429
480
|
var Canvas = (function (_super) {
|
|
430
481
|
__extends(Canvas, _super);
|
|
431
482
|
function Canvas(ViewCanvas, RegionCanvas) {
|
|
432
483
|
var _this = _super.call(this, ViewCanvas, {}, new Painter(RegionCanvas, {
|
|
433
|
-
willReadFrequently: true
|
|
484
|
+
willReadFrequently: true,
|
|
434
485
|
})) || this;
|
|
435
486
|
_this.name = "Canvas";
|
|
436
487
|
_this.__regionList = {};
|
|
@@ -449,7 +500,8 @@ var Canvas = (function (_super) {
|
|
|
449
500
|
if (regionName) {
|
|
450
501
|
if (this.__regionList[regionName] == undefined) {
|
|
451
502
|
var tempColor = this.__regionAssemble();
|
|
452
|
-
this.__regionList[regionName] =
|
|
503
|
+
this.__regionList[regionName] =
|
|
504
|
+
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
|
|
453
505
|
}
|
|
454
506
|
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
455
507
|
this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
|
|
@@ -467,7 +519,14 @@ var Canvas = (function (_super) {
|
|
|
467
519
|
var currentRGBA = imgData.data;
|
|
468
520
|
var doit = function () {
|
|
469
521
|
for (var key in _this.__regionList) {
|
|
470
|
-
if ("rgb(" +
|
|
522
|
+
if ("rgb(" +
|
|
523
|
+
currentRGBA[0] +
|
|
524
|
+
"," +
|
|
525
|
+
currentRGBA[1] +
|
|
526
|
+
"," +
|
|
527
|
+
currentRGBA[2] +
|
|
528
|
+
")" ==
|
|
529
|
+
_this.__regionList[key]) {
|
|
471
530
|
resolve(key);
|
|
472
531
|
break;
|
|
473
532
|
}
|
|
@@ -489,6 +548,24 @@ var Canvas = (function (_super) {
|
|
|
489
548
|
if (isRegion === void 0) { isRegion = false; }
|
|
490
549
|
return isRegion ? this.__region.painter : this.painter;
|
|
491
550
|
};
|
|
551
|
+
Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
|
|
552
|
+
return linearGradient(this.painter, x0, y0, x1, y1);
|
|
553
|
+
};
|
|
554
|
+
Canvas.prototype.createRadialGradient = function (cx, cy, r) {
|
|
555
|
+
return radialGradient(this.painter, cx, cy, r);
|
|
556
|
+
};
|
|
557
|
+
Canvas.prototype.getColor = function (x, y) {
|
|
558
|
+
var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
|
|
559
|
+
return ("rgba(" +
|
|
560
|
+
currentRGBA[0] +
|
|
561
|
+
"," +
|
|
562
|
+
currentRGBA[1] +
|
|
563
|
+
"," +
|
|
564
|
+
currentRGBA[2] +
|
|
565
|
+
"," +
|
|
566
|
+
currentRGBA[3] +
|
|
567
|
+
")");
|
|
568
|
+
};
|
|
492
569
|
return Canvas;
|
|
493
570
|
}(Painter));
|
|
494
571
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
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)};var i=function(t,i,e,r,n){var o=Math.cos(e),s=Math.sin(e);return[+((r-t)*o-(n-i)*s+t).toFixed(7),+((r-t)*s+(n-i)*o+i).toFixed(7)]};var e=function(t,i,e,r,n){return t.beginPath(),t.translate(e,r),t.rotate(n),t.font=i.fontStyle+" "+i.fontWeight+" "+i.fontSize+"px "+i.fontFamily,t},r=function(t,e,r,n,o,s,a,h){if(o>s){var _=o;o=s,s=_}return a%=2*Math.PI,h>=1.999999*Math.PI||h<=1.999999*-Math.PI?h=2*Math.PI:h%=2*Math.PI,function(t,e,r,n,o,s,a){e<0&&(t+=e,e*=-1);var h,_=[];h=i(0,0,t,o,0),_[0]=h[0],_[1]=h[1],h=i(0,0,e,h[0],h[1]),_[2]=h[0],_[3]=h[1],h=i(0,0,t,s,0),_[4]=h[0],_[5]=h[1],h=i(0,0,e,h[0],h[1]),_[6]=h[0],_[7]=h[1],a(t,t+e,_[0]+r,_[1]+n,_[4]+r,_[5]+n,_[2]+r,_[3]+n,_[6]+r,_[7]+n,.5*(s-o))}(a,h,r,n,o,s,(function(i,a,h,_,l,p,f,u,c,g,
|
|
15
|
+
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)};var i=function(t,i,e,r,n){var o=Math.cos(e),s=Math.sin(e);return[+((r-t)*o-(n-i)*s+t).toFixed(7),+((r-t)*s+(n-i)*o+i).toFixed(7)]};var e=function(t,i,e,r,n){return t.beginPath(),t.translate(e,r),t.rotate(n),t.font=i.fontStyle+" "+i.fontWeight+" "+i.fontSize+"px "+i.fontFamily,t},r=function(t,e,r,n,o,s,a,h){if(o>s){var _=o;o=s,s=_}return a%=2*Math.PI,h>=1.999999*Math.PI||h<=1.999999*-Math.PI?h=2*Math.PI:h%=2*Math.PI,function(t,e,r,n,o,s,a){e<0&&(t+=e,e*=-1);var h,_=[];h=i(0,0,t,o,0),_[0]=h[0],_[1]=h[1],h=i(0,0,e,h[0],h[1]),_[2]=h[0],_[3]=h[1],h=i(0,0,t,s,0),_[4]=h[0],_[5]=h[1],h=i(0,0,e,h[0],h[1]),_[6]=h[0],_[7]=h[1],a(t,t+e,_[0]+r,_[1]+n,_[4]+r,_[5]+n,_[2]+r,_[3]+n,_[6]+r,_[7]+n,.5*(s-o))}(a,h,r,n,o,s,(function(i,a,h,_,l,p,f,u,c,g,v){v<0&&(v=-v),t.beginPath(),t.moveTo(h,_),t.arc(r,n,o,i,a,!1),"round"==e.arcEndCap?t.arc(.5*(f+c),.5*(u+g),v,a-Math.PI,a,!0):"-round"==e.arcEndCap?t.arc(.5*(f+c),.5*(u+g),v,a-Math.PI,a,!1):t.lineTo(c,g),t.arc(r,n,s,a,i,!0),"round"==e.arcStartCap?t.arc(.5*(h+l),.5*(_+p),v,i,i-Math.PI,!0):"-round"==e.arcStartCap?t.arc(.5*(h+l),.5*(_+p),v,i,i-Math.PI,!1):t.lineTo(h,_)})),"butt"==e.arcStartCap&&t.closePath(),t},n=function(t,i,e,r){return t.beginPath(),t.moveTo(i+r,e),t.arc(i,e,r,0,2*Math.PI),t},o=function(t,i,e,r,n){return t.beginPath(),t.rect(i,e,r,n),t};function s(t,i,e,r,n){for(var o=0,s="",a=0;a<i.length;a++)t.measureText(s+i[a]).width>e?(n(s,((o+=1)-.5)*r),s=i[a]):a==i.length-1?(o+=1,n(s+i[a],(o-.5)*r)):s+=i[a];return o*r}var a=function(){function t(t,i,e){void 0===i&&(i={}),this.__region=null,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.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),"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,r,n){return void 0===n&&(n=0),this.__region&&this.__region.fillText(t,i,r,n),this.painter.save(),e(this.painter,this.__specialConfig,i,r,n).fillText(t,0,0),this.painter.restore(),this},t.prototype.strokeText=function(t,i,r,n){return void 0===n&&(n=0),this.__region&&this.__region.strokeText(t,i,r,n),this.painter.save(),e(this.painter,this.__specialConfig,i,r,n).strokeText(t,0,0),this.painter.restore(),this},t.prototype.fullText=function(t,i,r,n){return void 0===n&&(n=0),this.__region&&this.__region.fullText(t,i,r,n),this.painter.save(),e(this.painter,this.__specialConfig,i,r,n),this.painter.fillText(t,0,0),this.painter.strokeText(t,0,0),this.painter.restore(),this},t.prototype.fillTexts=function(t,i,r,n,o,a){var h=this;void 0===o&&(o=1.2),void 0===a&&(a=0),this.__region&&this.__region.fillTexts(t,i,r,n,o),this.painter.save(),e(this.painter,this.__specialConfig,i,r,a);var _=s(this.painter,t,n,this.__specialConfig.fontSize*o,(function(t,i){h.painter.fillText(t,0,i)}));return this.painter.restore(),_},t.prototype.strokeTexts=function(t,i,r,n,o,a){var h=this;void 0===o&&(o=1.2),void 0===a&&(a=0),this.__region&&this.__region.fillTexts(t,i,r,n,o),this.painter.save(),e(this.painter,this.__specialConfig,i,r,a);var _=s(this.painter,t,n,this.__specialConfig.fontSize*o,(function(t,i){h.painter.strokeText(t,0,i)}));return this.painter.restore(),_},t.prototype.fullTexts=function(t,i,r,n,o,a){var h=this;void 0===o&&(o=1.2),void 0===a&&(a=0),this.__region&&this.__region.fillTexts(t,i,r,n,o),this.painter.save(),e(this.painter,this.__specialConfig,i,r,a);var _=s(this.painter,t,n,this.__specialConfig.fontSize*o,(function(t,i){h.painter.fillText(t,0,i),h.painter.strokeText(t,0,i)}));return this.painter.restore(),_},t.prototype.beginPath=function(){return this.__region&&this.__region.beginPath(),this.painter.beginPath(),this},t.prototype.closePath=function(){return this.__region&&this.__region.closePath(),this.painter.closePath(),this},t.prototype.moveTo=function(t,i){return this.__region&&this.__region.moveTo(t,i),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.painter.lineTo(Math.round(t)+.5,Math.round(i)+.5),this},t.prototype.arc=function(t,i,e,r,n){return this.__region&&this.__region.arc(t,i,e,r,n),this.painter.arc(t,i,e,r,r+n,n<0),this},t.prototype.fill=function(){return this.__region&&this.__region.fill(),this.painter.fill(),this},t.prototype.stroke=function(){return this.__region&&this.__region.stroke(),this.painter.stroke(),this},t.prototype.full=function(){return this.__region&&this.__region.full(),this.painter.fill(),this.painter.stroke(),this},t.prototype.save=function(){return this.__region&&this.__region.save(),this.painter.save(),this},t.prototype.restore=function(){return this.__region&&this.__region.restore(),this.painter.restore(),this},t.prototype.clip=function(){return this.__region&&this.__region.clip(),this.painter.clip(),this},t.prototype.quadraticCurveTo=function(t,i,e,r){return this.__region&&this.__region.quadraticCurveTo(t,i,e,r),this.painter.quadraticCurveTo(t,i,e,r),this},t.prototype.bezierCurveTo=function(t,i,e,r,n,o){return this.__region&&this.__region.bezierCurveTo(t,i,e,r,n,o),this.painter.bezierCurveTo(t,i,e,r,n,o),this},t.prototype.clearRect=function(t,i,e,r){return this.__region&&this.__region.clearRect(t,i,e,r),this.painter.clearRect(t,i,e,r),this},t.prototype.fillArc=function(t,i,e,n,o,s){return this.__region&&this.__region.fillArc(t,i,e,n,o,s),r(this.painter,this.__specialConfig,t,i,e,n,o,s).fill(),this},t.prototype.strokeArc=function(t,i,e,n,o,s){return this.__region&&this.__region.strokeArc(t,i,e,n,o,s),r(this.painter,this.__specialConfig,t,i,e,n,o,s).stroke(),this},t.prototype.fullArc=function(t,i,e,n,o,s){return this.__region&&this.__region.fullArc(t,i,e,n,o,s),r(this.painter,this.__specialConfig,t,i,e,n,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),n(this.painter,t,i,e).fill(),this},t.prototype.strokeCircle=function(t,i,e){return this.__region&&this.__region.strokeCircle(t,i,e),n(this.painter,t,i,e).stroke(),this},t.prototype.fullCircle=function(t,i,e){return this.__region&&this.__region.fullCircle(t,i,e),n(this.painter,t,i,e),this.painter.fill(),this.painter.stroke(),this},t.prototype.fillRect=function(t,i,e,r){return this.__region&&this.__region.fillRect(t,i,e,r),o(this.painter,t,i,e,r).fill(),this},t.prototype.strokeRect=function(t,i,e,r){return this.__region&&this.__region.strokeRect(t,i,e,r),o(this.painter,t,i,e,r).stroke(),this},t.prototype.fullRect=function(t,i,e,r){return this.__region&&this.__region.fullRect(t,i,e,r),o(this.painter,t,i,e,r),this.painter.fill(),this.painter.stroke(),this},t}();var h={"font-size":"fontSize","font-family":"fontFamily","font-weight":"fontWeight","font-style":"fontStyle","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},_=function(i){function e(t,e){var r=i.call(this,t,{},new a(e,{willReadFrequently:!0}))||this;return r.name="Canvas",r.__regionList={},r.__regionAssemble=function(t,i,e,r){for(var n=[],o=0;o<r;o++)n[o]=t;return function(){for(var o=0;o<r;o++){if(n[o]<i){n[o]=+(n[o]+e).toFixed(7);break}o<r-1&&(n[o]=t)}return n}}(0,255,1,3),r.setRegion(""),r}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 r(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,i),e.prototype.config=function(t){for(var i in t){var e=h[i]||i;this.useConfig(e,t[i])}return this},e.prototype.setRegion=function(t){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},e.prototype.getRegion=function(t,i){var e=this;return new Promise((function(r,n){var o=e.__region.painter.getImageData(t-.5,i-.5,1,1),s=o.data,a=function(){for(var t in e.__regionList)if("rgb("+s[0]+","+s[1]+","+s[2]+")"==e.__regionList[t]){r(t);break}r("")};s?a():o.then((function(t){s=t,a()}))}))},e.prototype.getContext=function(t){return void 0===t&&(t=!1),t?this.__region.painter:this.painter},e.prototype.createLinearGradient=function(t,i,e,r){return function(t,i,e,r,n){var o=t.createLinearGradient(i,e,r,n),s={value:function(){return o},setColor:function(t,i){return o.addColorStop(t,i),s}};return s}(this.painter,t,i,e,r)},e.prototype.createRadialGradient=function(t,i,e){return function(t,i,e,r){var n=t.createRadialGradient(i,e,0,i,e,r),o={value:function(){return n},setColor:function(t,i){return n.addColorStop(t,i),o}};return o}(this.painter,t,i,e)},e.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]+")"},e}(a);export{_ as default};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
/******************************************************************************
|
|
12
16
|
Copyright (c) Microsoft Corporation.
|
|
@@ -22,6 +26,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
22
26
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
27
|
PERFORMANCE OF THIS SOFTWARE.
|
|
24
28
|
***************************************************************************** */
|
|
29
|
+
/* global Reflect, Promise */
|
|
30
|
+
|
|
25
31
|
|
|
26
32
|
function __spreadArray(to, from, pack) {
|
|
27
33
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
function t(t,r,e){if(e||2===arguments.length)for(var i,a=0,o=r.length;a<o;a++)!i&&a in r||(i||(i=Array.prototype.slice.call(r,0,a)),i[a]=r[a]);return t.concat(i||Array.prototype.slice.call(r))}function r(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],a=null,o=0;o<i.length;o++){try{a=t.getContext(i[o],e)}catch(t){}if(a)break}if(!a)throw new Error("Non canvas or browser does not support webgl.");var n=a.canvas.width,_=a.canvas.height,u=n*r,s=_*r;return a.viewport(.5*(n-u),.5*(_-s),u,s),a.depthFunc(a.LEQUAL),a.enable(a.DEPTH_TEST),a}function e(t){var r=t.drawingBufferWidth,e=t.drawingBufferHeight,i=new Uint8Array(4*r*e);return t.readPixels(0,0,r,e,t.RGBA,t.UNSIGNED_BYTE,i),function(t,a){return"rgba("+i[4*((a=e-a)*r+t)]+","+i[4*(a*r+t)+1]+","+i[4*(a*r+t)+2]+","+i[4*(a*r+t)+3]+")"}}var i=function(t,r){for(var e=[],i=0;i<4;i++)for(var a=0;a<r.length/4;a++)e[4*a+i]=t[i]*r[4*a]+t[i+4]*r[4*a+1]+t[i+8]*r[4*a+2]+t[i+12]*r[4*a+3];return e},a=function(){function t(t){void 0===t&&(t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.name="Matrix4",this.__matrix4=t}return t.prototype.move=function(t,r,e,a){return void 0===a&&(a=0),this.__matrix4=i(function(t,r,e,i){void 0===i&&(i=0);var a=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/a,e*t/a,i*t/a,1]}(t,r,e,a),this.__matrix4),this},t.prototype.rotate=function(t,r,e,a,o,n,_){var u=function(t,r,e,i,a,o){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,a=r,o=1):"number"==typeof i&&"number"==typeof a&&"number"==typeof o||(i=t,a=r,o=e,t=0,r=0,e=0),t==i&&r==a&&e==o)throw new Error("It's not a legitimate ray!");var n=Math.sqrt((i-t)*(i-t)+(a-r)*(a-r)),_=0!=n?(a-r)/n:1,u=0!=n?(i-t)/n:0,s=(i-t)*u+(a-r)*_,m=o-e,c=Math.sqrt(s*s+m*m),h=0!=c?m/c:1,l=0!=c?s/c:0;return[[_,h*u,u*l,0,-u,_*h,_*l,0,0,-l,h,0,r*u-t*_,e*l-t*u*h-r*_*h,-t*u*l-r*_*l-e*h,1],[_,-u,0,0,h*u,h*_,-l,0,u*l,_*l,h,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,a,o,n,_);return this.__matrix4=i(i(i(u[1],function(t){var r=Math.sin(t),e=Math.cos(t);return[e,r,0,0,-r,e,0,0,0,0,1,0,0,0,0,1]}(t)),u[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,a,o,n){return void 0===a&&(a=0),void 0===o&&(o=0),void 0===n&&(n=0),this.__matrix4=i(function(t,r,e,i,a,o){return void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,a-a*r,o-o*e,1]}(t,r,e,a,o,n),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?i(this.__matrix4,t):i(t,this.__matrix4),this},t.prototype.use=function(t,r,e,a){return void 0===e&&(e=0),void 0===a&&(a=1),i(this.__matrix4,[t,r,e,a])},t.prototype.value=function(){return this.__matrix4},t}(),o=function(){function t(t,r){void 0===r&&(r=!1),this.__painter=t,this.__isElement=r,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=r?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER}return t.prototype.use=function(){return this.__painter.bindBuffer(this.__type,this.__buffer),this},t.prototype.write=function(t){return function(t,r,e,i){var a=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(a,r,i)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,r,e,i){return void 0===i&&(i=0),function(t,r,e,i,a,o,n){t.vertexAttribPointer(r,e,i,n,a,o),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),n=function(){function t(t,r,e){void 0===e&&(e=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[r],this.__texture=function(t,r,e){var i=t.createTexture();return r==t.TEXTURE_2D&&t.activeTexture(t["TEXTURE"+e]),t.bindTexture(r,i),i}(t,this.__type,e),t.texParameteri(this.__type,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(this.__type,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}return t.prototype.useImage=function(t){return function(t,r,e,i,a,o){t.texImage2D(r,e,i,i,a,o)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,r,e){return function(t,r,e,i,a,o,n,_,u){for(var s,m=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],c=0;c<m.length;c++)o[c]&&(s=m[c],t.texImage2D(s,e,i,n,_,0,i,a,null),t.bindTexture(r,u),t.texImage2D(s,e,i,i,a,o[c]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),_={};function u(t,r,e){var i=t+"-"+e;return _[i]||(_[i]=new n(r,e)),_[i]}var s=function(t,r,e){var i=t.createShader(r);if(null==i)throw new Error("Unable to create shader!");if(t.shaderSource(i,e),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(i));return i},m=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,r){return this.program=function(t,r,e){var i=s(t,t.VERTEX_SHADER,r),a=s(t,t.FRAGMENT_SHADER,e),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,a),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,r),this},t}(),c={};function h(t,r,e,i,a){var n=function(t,r,e){var i=t+(e.geometry.attributes.normal?"1":"0")+(e.material.image?"1":"0")+(e.material.color?"1":"0")+(e.material.cube?"1":"0");if(c[i])return c[i].use();var a="\n attribute vec4 a_position;\n\n ".concat(e.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(e.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = a_position;\n\n // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n ").concat(e.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(e.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(e.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(e.material.color?"uniform vec4 u_color;":"","\n ").concat(e.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(e.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(e.material.color?"gl_FragColor = u_color;":"","\n ").concat(e.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(e.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),n=new m(r).compile(a,o).use();return c[i]=n,n}(t,r,e);if(new o(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(n.program,"a_position"),e.geometry.attributes.position.itemSize,3,0),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_world"),!1,a.matrix),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_proporion"),!1,a.proporion),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new o(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(n.program,"a_normal"),e.geometry.attributes.normal.itemSize,3,0),"color"in e.material)r.uniform4f(r.getUniformLocation(n.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;u(t,r,"cube").useCube([e.material.cube.right.image.value,e.material.cube.left.image.value,e.material.cube.top.image.value,e.material.cube.bottom.image.value,e.material.cube.far.image.value,e.material.cube.near.image.value],_,_)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(n.program,"u_sampler"),0),new o(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(n.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),u(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new o(r,!0).use().write(e.geometry.index.array),r.drawElements(r[e.geometry.type],e.geometry.index.count,r.UNSIGNED_BYTE,0)):r.drawArrays(r[e.geometry.type],0,e.geometry.attributes.position.count)}var l=!1,g=function(){function i(t,e){this.name="WebGL",this.__getColor=function(t,r){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(t,r,e,i){for(var a=[],o=0;o<i;o++)a[o]=t;return function(){for(var o=0;o<i;o++){if(a[o]<r){a[o]=+(a[o]+e).toFixed(7);break}o<i-1&&(a[o]=t)}return a}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new a([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=r(t,10),this.__regionPainter=r(e,10,{});var i=this.painter.canvas.width/this.painter.canvas.height,o=1,n=1;i>1?o=1/i:n=i;var _=Math.min(o,n);this.__proporion=[o,0,0,0,0,n,0,0,0,0,_,0,0,0,0,1]}return i.prototype.matrix=function(t){return new a(t)},i.prototype.getMatrix=function(){return this.__scene.matrix},i.prototype.getObject3D=function(){return this.__scene.children},i.prototype.review=function(t){void 0===t&&(t=!1),t?(this.__regionPainter.clearColor(1,1,1,1),this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)):(this.painter.clearColor(1,1,1,1),this.painter.clear(this.painter.COLOR_BUFFER_BIT));for(var r=0;r<this.__scene.children.length;r++)this.draw(this.__scene.children[r],t);return this},i.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(l=!0);var i={matrix:t.matrix.value()},a={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var o=0;o<t.mesh.length;o++)r?(h("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[o].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},i,a),this.__getColor=e(this.__regionPainter)):h("region"+this.__unique,this.painter,t.mesh[o],i,a)},i.prototype.render=function(t){"matrix"in t||(t.matrix=new a),"region"in t||(t.region="");for(var r=0;r<t.mesh.length;r++){var e=t.mesh[r];e.geometry.attributes.normal&&Array.isArray(e.geometry.attributes.normal.array)&&(e.geometry.attributes.normal.array=new Float32Array(e.geometry.attributes.normal.array)),e.geometry.attributes.position&&Array.isArray(e.geometry.attributes.position.array)&&(e.geometry.attributes.position.array=new Float32Array(e.geometry.attributes.position.array)),e.geometry.attributes.uv&&Array.isArray(e.geometry.attributes.uv.array)&&(e.geometry.attributes.uv.array=new Float32Array(e.geometry.attributes.uv.array)),e.geometry.index&&Array.isArray(e.geometry.index.array)&&(e.geometry.index.array=new Uint8Array(e.geometry.index.array))}this.__scene.children.push(t),this.draw(t)},i.prototype.setRegion=function(r){return this.__regionName=r+"",r?(null==this.__regionList[r]&&(this.__regionList[r]=t(t([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[r]):this.__regionColor=[0,0,0,1],this},i.prototype.getRegion=function(t,r){var e=this;return l&&this.review(!0),l=!1,new Promise((function(i,a){var o=e.__getColor(t,r);for(var n in e.__regionList){var _=e.__regionList[n];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==o){i(n);break}}i("")}))},i}();export{g as default};
|
package/lib/SVG/index.umd.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.
|
|
2
|
+
* VISLite JavaScript Library v0.3.0-alpha.0
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本版本系测试版本,请认真阅读下述说明再使用:
|
|
10
|
+
*
|
|
11
|
+
*【测试版本细则】
|
|
12
|
+
* alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
|
|
13
|
+
* beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
|
|
10
14
|
*/
|
|
11
15
|
(function (global, factory) {
|
|
12
16
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -113,22 +117,22 @@
|
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
var initText = function (el, config, x, y, deg) {
|
|
116
|
-
if (el.nodeName.toLowerCase() !==
|
|
117
|
-
throw new Error(
|
|
120
|
+
if (el.nodeName.toLowerCase() !== "text")
|
|
121
|
+
throw new Error("Need a <text> !");
|
|
118
122
|
setAttribute(el, "dy", {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
top: config["fontSize"] * 0.5,
|
|
124
|
+
middle: 0,
|
|
125
|
+
bottom: -config["fontSize"] * 0.5,
|
|
122
126
|
}[config.textBaseline]);
|
|
123
127
|
setStyle(el, {
|
|
124
128
|
"text-anchor": {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
left: "start",
|
|
130
|
+
right: "end",
|
|
131
|
+
center: "middle",
|
|
128
132
|
}[config.textAlign],
|
|
129
133
|
"dominant-baseline": "central",
|
|
130
|
-
"font-size": config[
|
|
131
|
-
"font-family": config[
|
|
134
|
+
"font-size": config["fontSize"] + "px",
|
|
135
|
+
"font-family": config["fontFamily"],
|
|
132
136
|
});
|
|
133
137
|
setAttribute(el, "x", x);
|
|
134
138
|
setAttribute(el, "y", y);
|
|
@@ -138,20 +142,20 @@
|
|
|
138
142
|
}
|
|
139
143
|
};
|
|
140
144
|
var initCircle = function (el, cx, cy, r) {
|
|
141
|
-
if (el.nodeName.toLowerCase() !==
|
|
142
|
-
throw new Error(
|
|
143
|
-
setAttribute(el,
|
|
144
|
-
setAttribute(el,
|
|
145
|
-
setAttribute(el,
|
|
145
|
+
if (el.nodeName.toLowerCase() !== "circle")
|
|
146
|
+
throw new Error("Need a <circle> !");
|
|
147
|
+
setAttribute(el, "cx", cx);
|
|
148
|
+
setAttribute(el, "cy", cy);
|
|
149
|
+
setAttribute(el, "r", r);
|
|
146
150
|
};
|
|
147
151
|
var initPath = function (el, path) {
|
|
148
|
-
if (el.nodeName.toLowerCase() !==
|
|
149
|
-
throw new Error(
|
|
150
|
-
setAttribute(el,
|
|
152
|
+
if (el.nodeName.toLowerCase() !== "path")
|
|
153
|
+
throw new Error("Need a <path> !");
|
|
154
|
+
setAttribute(el, "d", path);
|
|
151
155
|
};
|
|
152
156
|
var initRect = function (el, x, y, width, height) {
|
|
153
|
-
if (el.nodeName.toLowerCase() !==
|
|
154
|
-
throw new Error(
|
|
157
|
+
if (el.nodeName.toLowerCase() !== "rect")
|
|
158
|
+
throw new Error("Need a <rect> !");
|
|
155
159
|
if (height < 0) {
|
|
156
160
|
height *= -1;
|
|
157
161
|
y -= height;
|
|
@@ -160,14 +164,16 @@
|
|
|
160
164
|
width *= -1;
|
|
161
165
|
x -= width;
|
|
162
166
|
}
|
|
163
|
-
setAttribute(el,
|
|
164
|
-
setAttribute(el,
|
|
165
|
-
setAttribute(el,
|
|
166
|
-
setAttribute(el,
|
|
167
|
+
setAttribute(el, "x", x);
|
|
168
|
+
setAttribute(el, "y", y);
|
|
169
|
+
setAttribute(el, "width", width);
|
|
170
|
+
setAttribute(el, "height", height);
|
|
167
171
|
};
|
|
168
172
|
var initArc = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
169
|
-
if (el.nodeName.toLowerCase() !==
|
|
170
|
-
throw new Error(
|
|
173
|
+
if (el.nodeName.toLowerCase() !== "path")
|
|
174
|
+
throw new Error("Need a <path> !");
|
|
175
|
+
beginDeg = (beginDeg / 180) * Math.PI;
|
|
176
|
+
deg = (deg / 180) * Math.PI;
|
|
171
177
|
beginDeg = beginDeg % (Math.PI * 2);
|
|
172
178
|
if (r1 > r2) {
|
|
173
179
|
var temp = r1;
|
|
@@ -181,27 +187,28 @@
|
|
|
181
187
|
deg = deg % (Math.PI * 2);
|
|
182
188
|
}
|
|
183
189
|
arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
|
|
184
|
-
var f =
|
|
190
|
+
var f = endA - beginA > Math.PI ? 1 : 0, d = "M" + begInnerX + " " + begInnerY;
|
|
185
191
|
if (r < 0)
|
|
186
192
|
r = -r;
|
|
187
193
|
d +=
|
|
188
194
|
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
|
|
189
|
-
if (config
|
|
195
|
+
if (config.arcEndCap == "round")
|
|
190
196
|
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
|
|
191
|
-
else if (config
|
|
197
|
+
else if (config.arcEndCap == "-round")
|
|
192
198
|
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
|
|
193
199
|
else
|
|
194
200
|
d += "L" + endOuterX + " " + endOuterY;
|
|
195
|
-
d +=
|
|
196
|
-
|
|
201
|
+
d +=
|
|
202
|
+
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
|
|
203
|
+
if (config.arcStartCap == "round")
|
|
197
204
|
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
|
|
198
|
-
else if (config
|
|
205
|
+
else if (config.arcStartCap == "-round")
|
|
199
206
|
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
|
|
200
207
|
else
|
|
201
208
|
d += "L" + begInnerX + " " + begInnerY;
|
|
202
|
-
if (config
|
|
209
|
+
if (config.arcStartCap == "butt")
|
|
203
210
|
d += "Z";
|
|
204
|
-
setAttribute(el,
|
|
211
|
+
setAttribute(el, "d", d);
|
|
205
212
|
});
|
|
206
213
|
};
|
|
207
214
|
|
|
@@ -217,29 +224,29 @@
|
|
|
217
224
|
"font-size": "fontSize",
|
|
218
225
|
"font-family": "fontFamily",
|
|
219
226
|
"arc-start-cap": "arcStartCap",
|
|
220
|
-
"arc-end-cap": "arcEndCap"
|
|
227
|
+
"arc-end-cap": "arcEndCap",
|
|
221
228
|
};
|
|
222
229
|
var SVG$1 = (function () {
|
|
223
230
|
function SVG(svg) {
|
|
224
231
|
this.name = "SVG";
|
|
225
232
|
this.__config = {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
fillStyle: "#000",
|
|
234
|
+
strokeStyle: "#000",
|
|
235
|
+
lineWidth: 1,
|
|
236
|
+
textAlign: "left",
|
|
237
|
+
textBaseline: "middle",
|
|
231
238
|
"font-size": 16,
|
|
232
239
|
"font-family": "sans-serif",
|
|
233
240
|
"arc-start-cap": "butt",
|
|
234
241
|
"arc-end-cap": "butt",
|
|
235
|
-
|
|
242
|
+
lineDash: [],
|
|
236
243
|
};
|
|
237
244
|
this.__path = "";
|
|
238
245
|
this.__currentPosition = [];
|
|
239
246
|
this.__svg = svg;
|
|
240
247
|
}
|
|
241
248
|
SVG.prototype.config = function (params) {
|
|
242
|
-
if (typeof params !==
|
|
249
|
+
if (typeof params !== "object") {
|
|
243
250
|
return this.__config[oldAttrName[params] || params];
|
|
244
251
|
}
|
|
245
252
|
else {
|
|
@@ -259,7 +266,7 @@
|
|
|
259
266
|
};
|
|
260
267
|
SVG.prototype.appendEl = function (el, context) {
|
|
261
268
|
context = context || this.__svg;
|
|
262
|
-
if (typeof el ==
|
|
269
|
+
if (typeof el == "string")
|
|
263
270
|
el = toNode(el);
|
|
264
271
|
context.appendChild(el);
|
|
265
272
|
this.__useEl = el;
|
|
@@ -267,14 +274,15 @@
|
|
|
267
274
|
};
|
|
268
275
|
SVG.prototype.appendBoard = function (el, context) {
|
|
269
276
|
var _el = el;
|
|
270
|
-
if (typeof el ==
|
|
271
|
-
_el =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
if (typeof el == "string")
|
|
278
|
+
_el =
|
|
279
|
+
{
|
|
280
|
+
text: "text",
|
|
281
|
+
path: "path",
|
|
282
|
+
arc: "path",
|
|
283
|
+
circle: "circle",
|
|
284
|
+
rect: "rect",
|
|
285
|
+
}[el] || "";
|
|
278
286
|
if (_el == "")
|
|
279
287
|
throw new Error("Unsupported drawing method:" + el);
|
|
280
288
|
return this.appendEl(_el, context);
|
|
@@ -291,7 +299,7 @@
|
|
|
291
299
|
SVG.prototype.attr = function (params) {
|
|
292
300
|
if (!this.__useEl)
|
|
293
301
|
throw new Error("Currently, no node can be modified or viewed.");
|
|
294
|
-
if (typeof params !==
|
|
302
|
+
if (typeof params !== "object") {
|
|
295
303
|
return getAttribute(this.__useEl, params);
|
|
296
304
|
}
|
|
297
305
|
else {
|
|
@@ -402,17 +410,28 @@
|
|
|
402
410
|
return this;
|
|
403
411
|
};
|
|
404
412
|
SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
|
|
405
|
-
var begPosition = rotate(x, y, beginDeg, x + r, y);
|
|
406
|
-
var endPosition = rotate(x, y, beginDeg + deg, x + r, y);
|
|
407
|
-
|
|
408
|
-
deg = deg / Math.PI * 180;
|
|
409
|
-
if (this.__path == '') {
|
|
413
|
+
var begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y);
|
|
414
|
+
var endPosition = rotate(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
|
|
415
|
+
if (this.__path == "") {
|
|
410
416
|
this.__path += "M" + begPosition[0] + "," + begPosition[1];
|
|
411
417
|
}
|
|
412
|
-
else if (begPosition[0] != this.__currentPosition[0] ||
|
|
418
|
+
else if (begPosition[0] != this.__currentPosition[0] ||
|
|
419
|
+
begPosition[1] != this.__currentPosition[1]) {
|
|
413
420
|
this.__path += "L" + begPosition[0] + "," + begPosition[1];
|
|
414
421
|
}
|
|
415
|
-
this.__path +=
|
|
422
|
+
this.__path +=
|
|
423
|
+
"A" +
|
|
424
|
+
r +
|
|
425
|
+
"," +
|
|
426
|
+
r +
|
|
427
|
+
" 0 " +
|
|
428
|
+
(deg > 180 || deg < -180 ? 1 : 0) +
|
|
429
|
+
"," +
|
|
430
|
+
(deg > 0 ? 1 : 0) +
|
|
431
|
+
" " +
|
|
432
|
+
endPosition[0] +
|
|
433
|
+
"," +
|
|
434
|
+
endPosition[1];
|
|
416
435
|
return this;
|
|
417
436
|
};
|
|
418
437
|
SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
@@ -420,7 +439,8 @@
|
|
|
420
439
|
return this;
|
|
421
440
|
};
|
|
422
441
|
SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
423
|
-
this.__path +=
|
|
442
|
+
this.__path +=
|
|
443
|
+
"C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
|
|
424
444
|
return this;
|
|
425
445
|
};
|
|
426
446
|
return SVG;
|