vislite 0.8.0 → 1.0.0-next.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.
Files changed (201) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +17 -2
  3. package/LICENSE +20 -20
  4. package/README.md +2 -36
  5. package/lib/Buffer/index.umd.js +2 -2
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +9 -24
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +2 -2
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +2 -2
  12. package/lib/Eoap/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/SVG/index.umd.js +19 -35
  20. package/lib/SVG/index.umd.min.js +3 -3
  21. package/lib/Shader/index.umd.js +3 -82
  22. package/lib/Shader/index.umd.min.js +3 -3
  23. package/lib/Texture/index.umd.js +2 -2
  24. package/lib/Texture/index.umd.min.js +2 -2
  25. package/lib/TreeLayout/index.umd.js +2 -2
  26. package/lib/TreeLayout/index.umd.min.js +2 -2
  27. package/lib/animation/index.umd.js +2 -2
  28. package/lib/animation/index.umd.min.js +2 -2
  29. package/lib/getLoopColors/index.umd.js +2 -2
  30. package/lib/getLoopColors/index.umd.min.js +2 -2
  31. package/lib/getWebGLContext/index.umd.js +2 -2
  32. package/lib/getWebGLContext/index.umd.min.js +2 -2
  33. package/lib/index.umd.js +104 -944
  34. package/lib/index.umd.min.js +3 -3
  35. package/lib/move/index.umd.js +2 -2
  36. package/lib/move/index.umd.min.js +2 -2
  37. package/lib/resizeObserver/index.umd.js +2 -2
  38. package/lib/resizeObserver/index.umd.min.js +2 -2
  39. package/lib/rotate/index.umd.js +2 -2
  40. package/lib/rotate/index.umd.min.js +2 -2
  41. package/lib/ruler/index.umd.js +2 -2
  42. package/lib/ruler/index.umd.min.js +2 -2
  43. package/lib/scale/index.umd.js +2 -2
  44. package/lib/scale/index.umd.min.js +2 -2
  45. package/lib/throttle/index.umd.js +2 -2
  46. package/lib/throttle/index.umd.min.js +2 -2
  47. package/miniprogram/ui-canvas/index.js +100 -107
  48. package/miniprogram/ui-canvas/index.json +4 -4
  49. package/miniprogram/ui-canvas/index.wxml +4 -4
  50. package/miniprogram/ui-canvas/index.wxss +5 -5
  51. package/package/Buffer/index.ts +2 -2
  52. package/package/Canvas/index.ts +2 -2
  53. package/package/Cardinal/index.ts +2 -2
  54. package/package/Eoap/index.ts +2 -2
  55. package/package/Hermite/index.ts +2 -2
  56. package/package/Matrix4/index.ts +2 -2
  57. package/package/Mercator/index.ts +2 -2
  58. package/package/SVG/index.ts +2 -2
  59. package/package/Shader/index.ts +2 -39
  60. package/package/Texture/index.ts +2 -2
  61. package/package/TreeLayout/index.ts +2 -2
  62. package/package/animation/index.ts +2 -2
  63. package/package/getLoopColors/index.ts +2 -2
  64. package/package/index.ts +67 -76
  65. package/package/move/index.ts +2 -2
  66. package/package/resizeObserver/index.ts +2 -2
  67. package/package/rotate/index.ts +2 -2
  68. package/package/ruler/index.ts +2 -2
  69. package/package/scale/index.ts +2 -2
  70. package/package/throttle/index.ts +2 -2
  71. package/package.json +1 -1
  72. package/src/Eoap.ts +66 -66
  73. package/src/Matrix4/index.ts +84 -84
  74. package/src/Matrix4/move.ts +12 -12
  75. package/src/Matrix4/rotate.ts +15 -15
  76. package/src/Matrix4/scale.ts +11 -11
  77. package/src/Matrix4/transform.ts +64 -64
  78. package/src/Mercator.ts +27 -27
  79. package/src/SVG.ts +24 -24
  80. package/src/animation.ts +98 -98
  81. package/src/common/assemble.ts +22 -22
  82. package/src/common/canvas/arc.ts +51 -51
  83. package/src/common/canvas/config.ts +158 -158
  84. package/src/common/canvas/gradient.ts +24 -29
  85. package/src/common/canvas/index.ts +1 -12
  86. package/src/common/canvas/texts.ts +18 -18
  87. package/src/common/mergeOption.ts +6 -6
  88. package/src/common/setStyle.ts +5 -5
  89. package/src/common/svg/config.ts +190 -190
  90. package/src/common/svg/gradient.ts +53 -63
  91. package/src/common/svg/index.ts +347 -356
  92. package/src/common/svg/tool.ts +44 -44
  93. package/src/common/tree/index.ts +25 -25
  94. package/src/common/tree/toInnerTree.ts +59 -59
  95. package/src/common/tree/toPlainTree.ts +132 -132
  96. package/src/common/webgl/buffer.ts +79 -79
  97. package/src/common/webgl/getWebGLContext.ts +1 -1
  98. package/src/common/webgl/shader.ts +75 -75
  99. package/src/common/webgl/texture.ts +97 -97
  100. package/src/formatColor.ts +44 -44
  101. package/src/getLoopColors.ts +42 -42
  102. package/src/interpolation/Cardinal.ts +110 -110
  103. package/src/interpolation/Hermite.ts +65 -65
  104. package/src/layout/TreeLayout.ts +188 -188
  105. package/src/move.ts +7 -7
  106. package/src/resizeObserver.ts +37 -37
  107. package/src/rotate.ts +7 -7
  108. package/src/ruler.ts +209 -209
  109. package/src/scale.ts +6 -6
  110. package/src/throttle.ts +52 -52
  111. package/types/Buffer.d.ts +23 -23
  112. package/types/CanvasConfig.d.ts +106 -106
  113. package/types/CanvasOption.d.ts +8 -8
  114. package/types/CanvasOpts.d.ts +9 -9
  115. package/types/Cardinal.d.ts +13 -13
  116. package/types/Gradient.d.ts +14 -14
  117. package/types/Hermite.d.ts +18 -18
  118. package/types/Map.d.ts +9 -9
  119. package/types/Matrix4.d.ts +47 -47
  120. package/types/SVG.d.ts +238 -238
  121. package/types/SVGConfig.d.ts +79 -79
  122. package/types/Shader.d.ts +16 -23
  123. package/types/Texture.d.ts +16 -16
  124. package/types/Tree.d.ts +69 -69
  125. package/types/TreeConfig.d.ts +36 -36
  126. package/types/TreeLayout.d.ts +54 -54
  127. package/types/TreeOption.d.ts +48 -48
  128. package/types/animation.d.ts +9 -6
  129. package/types/getLoopColors.d.ts +5 -2
  130. package/types/getWebGLContext.d.ts +3 -0
  131. package/types/index.d.ts +149 -176
  132. package/types/move.d.ts +5 -2
  133. package/types/painterConfig.d.ts +2 -2
  134. package/types/resizeObserver.d.ts +5 -2
  135. package/types/rotate.d.ts +5 -2
  136. package/types/ruler.d.ts +10 -7
  137. package/types/scale.d.ts +5 -2
  138. package/types/throttle.d.ts +7 -4
  139. package/types/throttleOption.d.ts +21 -21
  140. package/uni-app/ui-canvas.vue +4 -11
  141. package/lib/Geometry/index.umd.d.ts +0 -3
  142. package/lib/Geometry/index.umd.js +0 -353
  143. package/lib/Geometry/index.umd.min.d.ts +0 -3
  144. package/lib/Geometry/index.umd.min.js +0 -11
  145. package/lib/OralCanvas/index.es.d.ts +0 -3
  146. package/lib/OralCanvas/index.es.js +0 -693
  147. package/lib/OralCanvas/index.es.min.d.ts +0 -3
  148. package/lib/OralCanvas/index.es.min.js +0 -11
  149. package/lib/OralWebGL/index.es.d.ts +0 -3
  150. package/lib/OralWebGL/index.es.js +0 -639
  151. package/lib/OralWebGL/index.es.min.d.ts +0 -3
  152. package/lib/OralWebGL/index.es.min.js +0 -11
  153. package/lib/WebGL/index.umd.d.ts +0 -3
  154. package/lib/WebGL/index.umd.js +0 -712
  155. package/lib/WebGL/index.umd.min.d.ts +0 -3
  156. package/lib/WebGL/index.umd.min.js +0 -11
  157. package/lib/formatColor/index.umd.d.ts +0 -3
  158. package/lib/formatColor/index.umd.js +0 -59
  159. package/lib/formatColor/index.umd.min.d.ts +0 -3
  160. package/lib/formatColor/index.umd.min.js +0 -11
  161. package/lib/viewHandler/index.umd.d.ts +0 -3
  162. package/lib/viewHandler/index.umd.js +0 -139
  163. package/lib/viewHandler/index.umd.min.d.ts +0 -3
  164. package/lib/viewHandler/index.umd.min.js +0 -11
  165. package/package/Geometry/index.ts +0 -3
  166. package/package/OralCanvas/index.ts +0 -3
  167. package/package/OralWebGL/index.ts +0 -3
  168. package/package/WebGL/index.ts +0 -3
  169. package/package/formatColor/index.ts +0 -3
  170. package/package/viewHandler/index.ts +0 -3
  171. package/src/Geometry.ts +0 -211
  172. package/src/WebGL.ts +0 -67
  173. package/src/common/geometry/prism-horizontal.ts +0 -50
  174. package/src/common/geometry/prism-vertical.ts +0 -55
  175. package/src/common/geometry/sphere-fragment.ts +0 -40
  176. package/src/common/geometry/tool/circle.ts +0 -18
  177. package/src/common/geometry/tool/rotateLine.ts +0 -49
  178. package/src/common/geometry/tool/triangles.ts +0 -24
  179. package/src/common/webgl/doDraw.ts +0 -109
  180. package/src/common/webgl/getColorFactory.ts +0 -27
  181. package/src/common/webgl/getShader.ts +0 -49
  182. package/src/common/webgl/getTexture.ts +0 -12
  183. package/src/common/webgl/index.ts +0 -228
  184. package/src/shader/fsColor.c +0 -8
  185. package/src/shader/fsColors.c +0 -8
  186. package/src/shader/fsCube.c +0 -9
  187. package/src/shader/fsImage.c +0 -9
  188. package/src/shader/vsColor.c +0 -18
  189. package/src/shader/vsColors.c +0 -14
  190. package/src/shader/vsCube.c +0 -14
  191. package/src/shader/vsImage.c +0 -14
  192. package/src/viewHandler.ts +0 -161
  193. package/types/Geometry.d.ts +0 -133
  194. package/types/GeometryOption.d.ts +0 -12
  195. package/types/GeometryResult.d.ts +0 -19
  196. package/types/Object3D.d.ts +0 -115
  197. package/types/Scene3D.d.ts +0 -7
  198. package/types/WebGL.d.ts +0 -39
  199. package/types/WebGLOption.d.ts +0 -15
  200. package/types/formatColor.d.ts +0 -3
  201. package/types/viewHandler.d.ts +0 -14
package/lib/index.umd.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.8.0
2
+ * VISLite JavaScript Library v1.0.0-next.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
- * Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
9
+ * Publish Date: Wed Mar 27 2024 19:32:09 GMT+0800 (中国标准时间)
10
10
  */
11
11
  (function (global, factory) {
12
12
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -256,7 +256,7 @@
256
256
  ];
257
257
  }
258
258
 
259
- function scale$1 (cx, cy, times, x, y) {
259
+ function scale (cx, cy, times, x, y) {
260
260
  return [
261
261
  times * (x - cx) + cx,
262
262
  times * (y - cy) + cy
@@ -299,46 +299,6 @@
299
299
  return colors;
300
300
  }
301
301
 
302
- var toHex = function (value) {
303
- var hex = value.toString(16);
304
- return hex.length == 1 ? ("0" + hex) : hex;
305
- };
306
- function formatColor (color, format) {
307
- var colorNode = document.getElementsByTagName('head')[0];
308
- colorNode.style['color'] = color;
309
- var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
310
- document.defaultView.getComputedStyle(colorNode, null) :
311
- colorNode.currentStyle;
312
- var oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',');
313
- for (var index = 0; index < oralFormat.length; index++) {
314
- oralFormat[index] = +oralFormat[index];
315
- }
316
- oralFormat.push(1);
317
- switch (format) {
318
- case "3d": {
319
- return [
320
- oralFormat[0] / 255,
321
- oralFormat[1] / 255,
322
- oralFormat[2] / 255,
323
- oralFormat[3]
324
- ];
325
- }
326
- case "rgba": {
327
- return "rgba(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ", ").concat(oralFormat[3], ")");
328
- }
329
- case "rgb": {
330
- return "rgb(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ")");
331
- }
332
- case "hexAlpha": {
333
- return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2])).concat(toHex(+(oralFormat[3] * 255).toFixed(0)));
334
- }
335
- case "hex": {
336
- return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2]));
337
- }
338
- }
339
- throw new Error("Unsupported color format: " + format);
340
- }
341
-
342
302
  var $timers = [];
343
303
  var $interval = 13;
344
304
  var $timerId;
@@ -581,16 +541,6 @@
581
541
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
582
542
  }
583
543
 
584
- function __spreadArray(to, from, pack) {
585
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
586
- if (ar || !(i in from)) {
587
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
588
- ar[i] = from[i];
589
- }
590
- }
591
- return to.concat(ar || Array.prototype.slice.call(from));
592
- }
593
-
594
544
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
595
545
  var e = new Error(message);
596
546
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -772,23 +722,14 @@
772
722
  });
773
723
  };
774
724
 
775
- var linearGradient$1 = function (el, x0, y0, x1, y1) {
776
- var defs = initDefs(el);
777
- var gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random();
778
- var linearGradient = toNode("linearGradient");
779
- defs.appendChild(linearGradient);
780
- setAttribute(linearGradient, "id", gradientId);
781
- setAttribute(linearGradient, "x1", x0 + "%");
782
- setAttribute(linearGradient, "y1", y0 + "%");
783
- setAttribute(linearGradient, "x2", x1 + "%");
784
- setAttribute(linearGradient, "y2", y1 + "%");
725
+ var enhanceGradient$1 = function (gradient, gradientId) {
785
726
  var enhanceGradient = {
786
727
  "value": function () {
787
728
  return "url(#" + gradientId + ")";
788
729
  },
789
730
  "setColor": function (stop, color) {
790
731
  var stopEl = toNode("stop");
791
- linearGradient.appendChild(stopEl);
732
+ gradient.appendChild(stopEl);
792
733
  setAttribute(stopEl, "offset", (stop * 100) + "%");
793
734
  setAttribute(stopEl, "style", "stop-color:" + color + ";");
794
735
  return enhanceGradient;
@@ -796,6 +737,18 @@
796
737
  };
797
738
  return enhanceGradient;
798
739
  };
740
+ var linearGradient$1 = function (el, x0, y0, x1, y1) {
741
+ var defs = initDefs(el);
742
+ var gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random();
743
+ var linearGradient = toNode("linearGradient");
744
+ defs.appendChild(linearGradient);
745
+ setAttribute(linearGradient, "id", gradientId);
746
+ setAttribute(linearGradient, "x1", x0 + "%");
747
+ setAttribute(linearGradient, "y1", y0 + "%");
748
+ setAttribute(linearGradient, "x2", x1 + "%");
749
+ setAttribute(linearGradient, "y2", y1 + "%");
750
+ return enhanceGradient$1(linearGradient, gradientId);
751
+ };
799
752
  var radialGradient$1 = function (el, cx, cy, r) {
800
753
  var defs = initDefs(el);
801
754
  var gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random();
@@ -805,27 +758,9 @@
805
758
  setAttribute(radialGradient, "cx", cx + "%");
806
759
  setAttribute(radialGradient, "cy", cy + "%");
807
760
  setAttribute(radialGradient, "r", r + "%");
808
- var enhanceGradient = {
809
- "value": function () {
810
- return "url(#" + gradientId + ")";
811
- },
812
- "setColor": function (stop, color) {
813
- var stopEl = toNode("stop");
814
- radialGradient.appendChild(stopEl);
815
- setAttribute(stopEl, "offset", (stop * 100) + "%");
816
- setAttribute(stopEl, "style", "stop-color:" + color + ";");
817
- return enhanceGradient;
818
- }
819
- };
820
- return enhanceGradient;
761
+ return enhanceGradient$1(radialGradient, gradientId);
821
762
  };
822
763
 
823
- var oldAttrName$1 = {
824
- "font-size": "fontSize",
825
- "font-family": "fontFamily",
826
- "arc-start-cap": "arcStartCap",
827
- "arc-end-cap": "arcEndCap",
828
- };
829
764
  var SVG$1 = (function () {
830
765
  function SVG(svg) {
831
766
  this.name = "SVG";
@@ -847,12 +782,11 @@
847
782
  }
848
783
  SVG.prototype.config = function (params) {
849
784
  if (typeof params !== "object") {
850
- return this.__config[oldAttrName$1[params] || params];
785
+ return this.__config[params];
851
786
  }
852
787
  else {
853
788
  for (var key in params) {
854
- var _key = oldAttrName$1[key] || key;
855
- this.__config[_key] = params[key];
789
+ this.__config[key] = params[key];
856
790
  }
857
791
  }
858
792
  return this;
@@ -1537,8 +1471,7 @@
1537
1471
  };
1538
1472
  }
1539
1473
 
1540
- var linearGradient = function (painter, x0, y0, x1, y1) {
1541
- var gradient = painter.createLinearGradient(x0, y0, x1, y1);
1474
+ var enhanceGradient = function (gradient) {
1542
1475
  var enhanceGradient = {
1543
1476
  "value": function () {
1544
1477
  return gradient;
@@ -1550,28 +1483,15 @@
1550
1483
  };
1551
1484
  return enhanceGradient;
1552
1485
  };
1486
+ var linearGradient = function (painter, x0, y0, x1, y1) {
1487
+ var gradient = painter.createLinearGradient(x0, y0, x1, y1);
1488
+ return enhanceGradient(gradient);
1489
+ };
1553
1490
  var radialGradient = function (painter, cx, cy, r) {
1554
1491
  var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
1555
- var enhanceGradient = {
1556
- "value": function () {
1557
- return gradient;
1558
- },
1559
- "setColor": function (stop, color) {
1560
- gradient.addColorStop(stop, color);
1561
- return enhanceGradient;
1562
- }
1563
- };
1564
- return enhanceGradient;
1492
+ return enhanceGradient(gradient);
1565
1493
  };
1566
1494
 
1567
- var oldAttrName = {
1568
- "font-size": "fontSize",
1569
- "font-family": "fontFamily",
1570
- "font-weight": "fontWeight",
1571
- "font-style": "fontStyle",
1572
- "arc-start-cap": "arcStartCap",
1573
- "arc-end-cap": "arcEndCap",
1574
- };
1575
1495
  var Canvas$1 = (function (_super) {
1576
1496
  __extends(Canvas, _super);
1577
1497
  function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
@@ -1589,8 +1509,7 @@
1589
1509
  }
1590
1510
  Canvas.prototype.config = function (configs) {
1591
1511
  for (var key in configs) {
1592
- var _key = oldAttrName[key] || key;
1593
- this.useConfig(_key, configs[key]);
1512
+ this.useConfig(key, configs[key]);
1594
1513
  }
1595
1514
  return this;
1596
1515
  };
@@ -1794,54 +1713,64 @@
1794
1713
  return painter;
1795
1714
  }
1796
1715
 
1797
- function getColorFactory (painter) {
1798
- var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
1799
- var pixels = new Uint8Array(4 * width * height);
1800
- painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
1801
- return function (x, y) {
1802
- y = height - y;
1803
- var pixelR = pixels[4 * (y * width + x)];
1804
- var pixelG = pixels[4 * (y * width + x) + 1];
1805
- var pixelB = pixels[4 * (y * width + x) + 2];
1806
- var pixelA = pixels[4 * (y * width + x) + 3];
1807
- return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
1808
- };
1809
- }
1716
+ var getWebGLContext = (function (el, scale, mode) {
1717
+ if (scale === void 0) { scale = 1; }
1718
+ if (!el) {
1719
+ throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
1720
+ }
1721
+ var width = el.clientWidth, height = el.clientHeight;
1722
+ var ViewCanvas;
1723
+ var _el = el;
1724
+ if (_el._vislite_canvas_) {
1725
+ ViewCanvas = _el._vislite_canvas_;
1726
+ }
1727
+ else {
1728
+ ViewCanvas = document.createElement('canvas');
1729
+ el.appendChild(ViewCanvas);
1730
+ _el._vislite_canvas_ = ViewCanvas;
1731
+ el.setAttribute('vislite', 'WebGL');
1732
+ }
1733
+ ViewCanvas.style.width = width + "px";
1734
+ ViewCanvas.setAttribute('width', width + "");
1735
+ ViewCanvas.style.height = height + "px";
1736
+ ViewCanvas.setAttribute('height', height + "");
1737
+ return getWebGLContext$1(ViewCanvas, scale, {}, mode);
1738
+ });
1810
1739
 
1811
- var newBuffer = function (painter) {
1812
- return painter.createBuffer();
1813
- };
1814
- var writeBuffer = function (painter, data, isElement, usage) {
1815
- var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1816
- painter.bufferData(TYPE, data, usage);
1740
+ var loadShader = function (painter, type, source) {
1741
+ var shader = painter.createShader(type);
1742
+ if (shader == null)
1743
+ throw new Error('Unable to create shader!');
1744
+ painter.shaderSource(shader, source);
1745
+ painter.compileShader(shader);
1746
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1747
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1748
+ return shader;
1817
1749
  };
1818
- var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
1819
- painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
1820
- painter.enableVertexAttribArray(location);
1750
+ var useShader = function (painter, vshaderSource, fshaderSource) {
1751
+ var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1752
+ var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1753
+ var glProgram = painter.createProgram();
1754
+ painter.attachShader(glProgram, vertexShader);
1755
+ painter.attachShader(glProgram, fragmentShader);
1756
+ painter.linkProgram(glProgram);
1757
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1758
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
1759
+ return glProgram;
1821
1760
  };
1822
- var BufferObject = (function () {
1823
- function BufferObject(painter, isElement) {
1824
- if (isElement === void 0) { isElement = false; }
1761
+ var ShaderObject = (function () {
1762
+ function ShaderObject(painter) {
1825
1763
  this.__painter = painter;
1826
- this.__isElement = isElement;
1827
- this.__buffer = newBuffer(painter);
1828
- this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1829
1764
  }
1830
- BufferObject.prototype.use = function () {
1831
- this.__painter.bindBuffer(this.__type, this.__buffer);
1832
- return this;
1833
- };
1834
- BufferObject.prototype.write = function (data) {
1835
- writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
1836
- this.__fsize = data.BYTES_PER_ELEMENT;
1765
+ ShaderObject.prototype.use = function () {
1766
+ this.__painter.useProgram(this.program);
1837
1767
  return this;
1838
1768
  };
1839
- BufferObject.prototype.divide = function (location, size, stride, offset) {
1840
- if (offset === void 0) { offset = 0; }
1841
- useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
1769
+ ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
1770
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource);
1842
1771
  return this;
1843
1772
  };
1844
- return BufferObject;
1773
+ return ShaderObject;
1845
1774
  }());
1846
1775
 
1847
1776
  var initTexture = function (painter, type, unit) {
@@ -1898,401 +1827,42 @@
1898
1827
  return TextureObject;
1899
1828
  }());
1900
1829
 
1901
- var textures = {};
1902
- function getTexture (type, painter, kind) {
1903
- var uniqueName = type + "-" + kind;
1904
- if (!textures[uniqueName]) {
1905
- textures[uniqueName] = new TextureObject(painter, kind);
1906
- }
1907
- return textures[uniqueName];
1908
- }
1909
-
1910
- var loadShader = function (painter, type, source) {
1911
- var shader = painter.createShader(type);
1912
- if (shader == null)
1913
- throw new Error('Unable to create shader!');
1914
- painter.shaderSource(shader, source);
1915
- painter.compileShader(shader);
1916
- if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1917
- throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1918
- return shader;
1830
+ var newBuffer = function (painter) {
1831
+ return painter.createBuffer();
1919
1832
  };
1920
- var useShader = function (painter, vshaderSource, fshaderSource) {
1921
- var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1922
- var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1923
- var glProgram = painter.createProgram();
1924
- painter.attachShader(glProgram, vertexShader);
1925
- painter.attachShader(glProgram, fragmentShader);
1926
- painter.linkProgram(glProgram);
1927
- if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1928
- throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
1929
- return glProgram;
1833
+ var writeBuffer = function (painter, data, isElement, usage) {
1834
+ var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1835
+ painter.bufferData(TYPE, data, usage);
1930
1836
  };
1931
- var ShaderObject = (function () {
1932
- function ShaderObject(painter) {
1837
+ var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
1838
+ painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
1839
+ painter.enableVertexAttribArray(location);
1840
+ };
1841
+ var BufferObject = (function () {
1842
+ function BufferObject(painter, isElement) {
1843
+ if (isElement === void 0) { isElement = false; }
1933
1844
  this.__painter = painter;
1845
+ this.__isElement = isElement;
1846
+ this.__buffer = newBuffer(painter);
1847
+ this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1934
1848
  }
1935
- ShaderObject.prototype.use = function () {
1936
- this.__painter.useProgram(this.program);
1937
- return this;
1938
- };
1939
- ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
1940
- this.program = useShader(this.__painter, vshaderSource, fshaderSource);
1849
+ BufferObject.prototype.use = function () {
1850
+ this.__painter.bindBuffer(this.__type, this.__buffer);
1941
1851
  return this;
1942
1852
  };
1943
- return ShaderObject;
1944
- }());
1945
-
1946
- var vsColor = "attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\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}";
1947
-
1948
- var vsColors = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_color = a_color;\n}";
1949
-
1950
- var vsImage = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_textcoord = a_textcoord;\n}";
1951
-
1952
- var vsCube = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_normal = normalize(vec3(a_normal));\n}";
1953
-
1954
- var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
1955
-
1956
- var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
1957
-
1958
- var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}";
1959
-
1960
- var fsCube = "precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}";
1961
-
1962
- var shaders = {};
1963
- function getShader (type, painter, mesh) {
1964
- var _a, _b;
1965
- var uniqueName = type +
1966
- (mesh.material.color ? "1" : "0") +
1967
- (mesh.material.colors ? "1" : "0") +
1968
- (mesh.material.image ? "1" : "0") +
1969
- (mesh.material.cube ? "1" : "0");
1970
- if (shaders[uniqueName])
1971
- return shaders[uniqueName].use();
1972
- var vertexShader = (_a = {},
1973
- _a[type + "1000"] = vsColor,
1974
- _a[type + "0100"] = vsColors,
1975
- _a[type + "0010"] = vsImage,
1976
- _a[type + "0001"] = vsCube,
1977
- _a)[uniqueName].replace(/uniform +mat4 +u_matrix;/, "\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position");
1978
- var fragmentShader = (_b = {},
1979
- _b[type + "1000"] = fsColor,
1980
- _b[type + "0100"] = fsColors,
1981
- _b[type + "0010"] = fsImage,
1982
- _b[type + "0001"] = fsCube,
1983
- _b)[uniqueName];
1984
- var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
1985
- shaders[uniqueName] = shader;
1986
- return shader;
1987
- }
1988
-
1989
- function doDraw (type, painter, mesh, meshWorld, globalWorld) {
1990
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
1991
- var shader = getShader(type, painter, mesh);
1992
- new BufferObject(painter).use()
1993
- .write(mesh.geometry.attributes.position.array)
1994
- .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
1995
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
1996
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
1997
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
1998
- if (mesh.geometry.attributes.normal) {
1999
- new BufferObject(painter).use()
2000
- .write(mesh.geometry.attributes.normal.array)
2001
- .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
2002
- }
2003
- if ("color" in mesh.material) {
2004
- painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), (_a = mesh.material.color) === null || _a === void 0 ? void 0 : _a.r, (_b = mesh.material.color) === null || _b === void 0 ? void 0 : _b.g, (_c = mesh.material.color) === null || _c === void 0 ? void 0 : _c.b, (_d = mesh.material.color) === null || _d === void 0 ? void 0 : _d.alpha);
2005
- }
2006
- if ("colors" in mesh.material) {
2007
- new BufferObject(painter).use()
2008
- .write((_e = mesh.material.colors) === null || _e === void 0 ? void 0 : _e.array)
2009
- .divide(painter.getAttribLocation(shader.program, "a_color"), (_f = mesh.material.colors) === null || _f === void 0 ? void 0 : _f.itemSize, (_g = mesh.material.colors) === null || _g === void 0 ? void 0 : _g.itemSize, 0);
2010
- }
2011
- else if ("cube" in mesh.material) {
2012
- var size = ((_j = (_h = mesh.material.cube) === null || _h === void 0 ? void 0 : _h.right) === null || _j === void 0 ? void 0 : _j.image.value).width;
2013
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
2014
- getTexture(type, painter, 'cube').useCube([
2015
- (_l = (_k = mesh.material.cube) === null || _k === void 0 ? void 0 : _k.right) === null || _l === void 0 ? void 0 : _l.image.value,
2016
- (_o = (_m = mesh.material.cube) === null || _m === void 0 ? void 0 : _m.left) === null || _o === void 0 ? void 0 : _o.image.value,
2017
- (_q = (_p = mesh.material.cube) === null || _p === void 0 ? void 0 : _p.top) === null || _q === void 0 ? void 0 : _q.image.value,
2018
- (_s = (_r = mesh.material.cube) === null || _r === void 0 ? void 0 : _r.bottom) === null || _s === void 0 ? void 0 : _s.image.value,
2019
- (_u = (_t = mesh.material.cube) === null || _t === void 0 ? void 0 : _t.far) === null || _u === void 0 ? void 0 : _u.image.value,
2020
- (_w = (_v = mesh.material.cube) === null || _v === void 0 ? void 0 : _v.near) === null || _w === void 0 ? void 0 : _w.image.value
2021
- ], size, size);
2022
- }
2023
- else if ("image" in mesh.material) {
2024
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
2025
- new BufferObject(painter).use()
2026
- .write((_x = mesh.geometry.attributes.uv) === null || _x === void 0 ? void 0 : _x.array)
2027
- .divide(painter.getAttribLocation(shader.program, "a_textcoord"), (_y = mesh.geometry.attributes.uv) === null || _y === void 0 ? void 0 : _y.itemSize, 2, 0);
2028
- getTexture(type, painter, '2d').useImage((_z = mesh.material.image) === null || _z === void 0 ? void 0 : _z.value);
2029
- }
2030
- if (mesh.geometry.index) {
2031
- new BufferObject(painter, true).use()
2032
- .write(mesh.geometry.index.array);
2033
- painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
2034
- }
2035
- else {
2036
- painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
2037
- }
2038
- }
2039
-
2040
- var needUpdate = false;
2041
- var scale = 10;
2042
- var WebGL$1 = (function () {
2043
- function WebGL(ViewCanvas, RegionCanvas, mode) {
2044
- this.name = "WebGL";
2045
- this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
2046
- this.__regionList = {};
2047
- this.__regionAssemble = assemble(0, 1, 0.2, 3);
2048
- this.__regionName = "";
2049
- this.__regionColor = [0, 0, 0, 1];
2050
- this.__scene = {
2051
- children: [],
2052
- matrix: new Matrix4([
2053
- 1, 0, 0, 0,
2054
- 0, 1, 0, 0,
2055
- 0, 0, 1, 0,
2056
- 0, 0, 0, scale
2057
- ])
2058
- };
2059
- this.__unique = new Date().valueOf();
2060
- this.painter = getWebGLContext$1(ViewCanvas, scale, {}, mode);
2061
- if (RegionCanvas) {
2062
- this.__regionPainter = getWebGLContext$1(RegionCanvas, scale, {}, mode);
2063
- }
2064
- var proportion = this.painter.canvas.width / this.painter.canvas.height;
2065
- var xProportion = 1;
2066
- var yProportion = 1;
2067
- if (proportion > 1) {
2068
- xProportion = 1 / proportion;
2069
- }
2070
- else {
2071
- yProportion = proportion;
2072
- }
2073
- var zProportion = Math.min(xProportion, yProportion);
2074
- this.__proporion = [
2075
- xProportion, 0, 0, 0,
2076
- 0, yProportion, 0, 0,
2077
- 0, 0, zProportion, 0,
2078
- 0, 0, 0, 1
2079
- ];
2080
- }
2081
- WebGL.prototype.matrix = function (initMatrix4) {
2082
- return new Matrix4(initMatrix4);
2083
- };
2084
- WebGL.prototype.getMatrix = function () {
2085
- return this.__scene.matrix;
2086
- };
2087
- WebGL.prototype.getObject3D = function () {
2088
- return this.__scene.children;
2089
- };
2090
- WebGL.prototype.review = function (isUpdateRegion) {
2091
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
2092
- if (isUpdateRegion) {
2093
- if (this.__regionPainter) {
2094
- this.__regionPainter.clearColor(1, 1, 1, 1);
2095
- this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
2096
- }
2097
- }
2098
- else {
2099
- this.painter.clearColor(1, 1, 1, 1);
2100
- this.painter.clear(this.painter.COLOR_BUFFER_BIT);
2101
- }
2102
- for (var index = 0; index < this.__scene.children.length; index++) {
2103
- this.draw(this.__scene.children[index], isUpdateRegion);
2104
- }
1853
+ BufferObject.prototype.write = function (data) {
1854
+ writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
1855
+ this.__fsize = data.BYTES_PER_ELEMENT;
2105
1856
  return this;
2106
1857
  };
2107
- WebGL.prototype.draw = function (object3D, isUpdateRegion) {
2108
- var _a;
2109
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
2110
- if (!isUpdateRegion)
2111
- needUpdate = true;
2112
- var meshWorld = {
2113
- matrix: (_a = object3D.matrix) === null || _a === void 0 ? void 0 : _a.value()
2114
- };
2115
- var globalWorld = {
2116
- matrix: this.__scene.matrix.value(),
2117
- proporion: this.__proporion
2118
- };
2119
- this.setRegion(object3D.region);
2120
- for (var index = 0; index < object3D.mesh.length; index++) {
2121
- if (isUpdateRegion) {
2122
- if (this.__regionPainter) {
2123
- doDraw("painter" + this.__unique, this.__regionPainter, {
2124
- geometry: object3D.mesh[index].geometry,
2125
- material: {
2126
- color: {
2127
- r: this.__regionColor[0],
2128
- g: this.__regionColor[1],
2129
- b: this.__regionColor[2],
2130
- alpha: this.__regionColor[3]
2131
- }
2132
- }
2133
- }, meshWorld, globalWorld);
2134
- this.__getColor = getColorFactory(this.__regionPainter);
2135
- }
2136
- }
2137
- else {
2138
- doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
2139
- }
2140
- }
2141
- };
2142
- WebGL.prototype.render = function (object3D) {
2143
- if (!('matrix' in object3D))
2144
- object3D.matrix = new Matrix4();
2145
- if (!('region' in object3D))
2146
- object3D.region = "";
2147
- for (var index = 0; index < object3D.mesh.length; index++) {
2148
- var mesh = object3D.mesh[index];
2149
- if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
2150
- mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
2151
- }
2152
- if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
2153
- mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
2154
- }
2155
- if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
2156
- mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
2157
- }
2158
- if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
2159
- mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
2160
- }
2161
- if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
2162
- mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
2163
- }
2164
- }
2165
- this.__scene.children.push(object3D);
2166
- this.draw(object3D);
2167
- };
2168
- WebGL.prototype.setRegion = function (regionName) {
2169
- this.__regionName = regionName + "";
2170
- if (regionName) {
2171
- if (this.__regionList[regionName] == void 0) {
2172
- this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
2173
- }
2174
- this.__regionColor = this.__regionList[regionName];
2175
- }
2176
- else {
2177
- this.__regionColor = [0, 0, 0, 1];
2178
- }
1858
+ BufferObject.prototype.divide = function (location, size, stride, offset) {
1859
+ if (offset === void 0) { offset = 0; }
1860
+ useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
2179
1861
  return this;
2180
1862
  };
2181
- WebGL.prototype.getRegion = function (x, y) {
2182
- var _this = this;
2183
- if (needUpdate)
2184
- this.review(true);
2185
- needUpdate = false;
2186
- return new Promise(function (resolve) {
2187
- var rgba = _this.__getColor(x, y);
2188
- for (var key in _this.__regionList) {
2189
- var currentRGBA = _this.__regionList[key];
2190
- if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
2191
- resolve(key);
2192
- break;
2193
- }
2194
- }
2195
- resolve("");
2196
- });
2197
- };
2198
- return WebGL;
1863
+ return BufferObject;
2199
1864
  }());
2200
1865
 
2201
- var WebGL = (function (_super) {
2202
- __extends(WebGL, _super);
2203
- function WebGL(el, option) {
2204
- if (option === void 0) { option = {}; }
2205
- if (!el) {
2206
- throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
2207
- }
2208
- option = mergeOption(option, {
2209
- region: true
2210
- });
2211
- var width = el.clientWidth, height = el.clientHeight;
2212
- var ViewCanvas, RegionCanvas = null;
2213
- var _el = el;
2214
- if (_el._vislite_canvas_) {
2215
- ViewCanvas = _el._vislite_canvas_[0];
2216
- RegionCanvas = _el._vislite_canvas_[1];
2217
- }
2218
- else {
2219
- if (option.region) {
2220
- RegionCanvas = document.createElement('canvas');
2221
- el.appendChild(RegionCanvas);
2222
- RegionCanvas.style.position = 'absolute';
2223
- RegionCanvas.style.zIndex = "-1";
2224
- RegionCanvas.style.opacity = "0";
2225
- }
2226
- ViewCanvas = document.createElement('canvas');
2227
- el.appendChild(ViewCanvas);
2228
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
2229
- el.setAttribute('vislite', 'WebGL');
2230
- }
2231
- for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
2232
- var canvas = _a[_i];
2233
- if (canvas) {
2234
- canvas.style.width = width + "px";
2235
- canvas.setAttribute('width', width + "");
2236
- canvas.style.height = height + "px";
2237
- canvas.setAttribute('height', height + "");
2238
- }
2239
- }
2240
- return _super.call(this, ViewCanvas, RegionCanvas, option.mode) || this;
2241
- }
2242
- return WebGL;
2243
- }(WebGL$1));
2244
-
2245
- var getWebGLContext = (function (el, scale, mode) {
2246
- if (scale === void 0) { scale = 1; }
2247
- if (!el) {
2248
- throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
2249
- }
2250
- var width = el.clientWidth, height = el.clientHeight;
2251
- var ViewCanvas;
2252
- var _el = el;
2253
- if (_el._vislite_canvas_) {
2254
- ViewCanvas = _el._vislite_canvas_;
2255
- }
2256
- else {
2257
- ViewCanvas = document.createElement('canvas');
2258
- el.appendChild(ViewCanvas);
2259
- _el._vislite_canvas_ = ViewCanvas;
2260
- el.setAttribute('vislite', 'WebGL');
2261
- }
2262
- ViewCanvas.style.width = width + "px";
2263
- ViewCanvas.setAttribute('width', width + "");
2264
- ViewCanvas.style.height = height + "px";
2265
- ViewCanvas.setAttribute('height', height + "");
2266
- return getWebGLContext$1(ViewCanvas, scale, {}, mode);
2267
- });
2268
-
2269
- var Shader = (function (_super) {
2270
- __extends(Shader, _super);
2271
- function Shader() {
2272
- return _super !== null && _super.apply(this, arguments) || this;
2273
- }
2274
- Shader.prototype.compile = function (arg1, arg2) {
2275
- if (arg2) {
2276
- _super.prototype.compile.call(this, arg1, arg2);
2277
- }
2278
- else {
2279
- _super.prototype.compile.call(this, {
2280
- "color": vsColor,
2281
- "colors": vsColors,
2282
- "image": vsImage,
2283
- "cube": vsCube
2284
- }[arg1], {
2285
- "color": fsColor,
2286
- "colors": fsColors,
2287
- "image": fsImage,
2288
- "cube": fsCube
2289
- }[arg1]);
2290
- }
2291
- return this;
2292
- };
2293
- return Shader;
2294
- }(ShaderObject));
2295
-
2296
1866
  var rotateX = function (deg, x, y, z) {
2297
1867
  var cos = Math.cos(deg), sin = Math.sin(deg);
2298
1868
  return [x, y * cos - z * sin, y * sin + z * cos];
@@ -2347,126 +1917,6 @@
2347
1917
  return Mercator;
2348
1918
  }());
2349
1919
 
2350
- var mousePosition = function (el, event) {
2351
- var bounding = el.getBoundingClientRect();
2352
- return {
2353
- "x": event.clientX - bounding.left,
2354
- "y": event.clientY - bounding.top
2355
- };
2356
- };
2357
- var getKeyString = function (event) {
2358
- return {
2359
- 37: "left",
2360
- 38: "up",
2361
- 39: "right",
2362
- 40: "down",
2363
- }[event.keyCode || event.which];
2364
- };
2365
- function viewHandler (callback) {
2366
- var el = document.getElementsByTagName('body')[0];
2367
- el.addEventListener("keydown", function (event) {
2368
- var keyCode = getKeyString(event);
2369
- if (keyCode == 'up') {
2370
- callback({
2371
- type: "lookUp",
2372
- normal: [],
2373
- value: 0.1,
2374
- event: event
2375
- });
2376
- }
2377
- else if (keyCode == 'down') {
2378
- callback({
2379
- type: "lookDown",
2380
- normal: [],
2381
- value: 0.1,
2382
- event: event
2383
- });
2384
- }
2385
- else if (keyCode == 'left') {
2386
- callback({
2387
- type: "lookLeft",
2388
- normal: [],
2389
- value: 0.1,
2390
- event: event
2391
- });
2392
- }
2393
- else if (keyCode == 'right') {
2394
- callback({
2395
- type: "lookRight",
2396
- normal: [],
2397
- value: 0.1,
2398
- event: event
2399
- });
2400
- }
2401
- });
2402
- var mouseP = null;
2403
- var doMove = function (event) {
2404
- if (mouseP == null) {
2405
- callback({
2406
- type: "hover",
2407
- normal: [],
2408
- value: 0,
2409
- event: event
2410
- });
2411
- }
2412
- else {
2413
- var tempMouseP = mousePosition(el, event);
2414
- var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
2415
- var rotateNormal = [
2416
- normal[1],
2417
- normal[0],
2418
- 0
2419
- ];
2420
- if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
2421
- return;
2422
- callback({
2423
- type: "rotate",
2424
- normal: rotateNormal,
2425
- value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01,
2426
- event: event
2427
- });
2428
- mouseP = tempMouseP;
2429
- }
2430
- };
2431
- el.addEventListener("mousedown", function (event) {
2432
- mouseP = mousePosition(el, event);
2433
- });
2434
- el.addEventListener("mouseup", function () {
2435
- mouseP = null;
2436
- });
2437
- el.addEventListener("mousemove", function (event) {
2438
- doMove(event);
2439
- });
2440
- el.addEventListener("touchend", function () {
2441
- mouseP = null;
2442
- });
2443
- el.addEventListener("touchstart", function (event) {
2444
- mouseP = mousePosition(el, event);
2445
- });
2446
- el.addEventListener("touchmove", function (event) {
2447
- doMove(event.touches[0]);
2448
- });
2449
- var doScale = function (value, event) {
2450
- if (value == 0)
2451
- return;
2452
- var baseTimes = 0.899;
2453
- callback({
2454
- type: "scale",
2455
- value: value < 0 ? baseTimes : 2 - baseTimes,
2456
- normal: [],
2457
- event: event
2458
- });
2459
- };
2460
- el.addEventListener("mousewheel", function (event) {
2461
- doScale(event.wheelDelta, event);
2462
- });
2463
- if (window.addEventListener) {
2464
- window.addEventListener('DOMMouseScroll', function (event) {
2465
- doScale(-1 * event.detail, event);
2466
- }, false);
2467
- }
2468
- }
2469
-
2470
1920
  var observer;
2471
1921
  var attrValueToCallback = {};
2472
1922
  var uniqueid = 0;
@@ -2833,318 +2283,28 @@
2833
2283
  return TreeLayout;
2834
2284
  }(Tree));
2835
2285
 
2836
- var splitNum = function (precision, radius, deg) {
2837
- if (deg === void 0) { deg = Math.PI * 2; }
2838
- var num = Math.ceil(deg /
2839
- Math.asin(precision / radius) * 2);
2840
- return (isNaN(num) || num < 12) ? 12 : num;
2841
- };
2842
-
2843
- function prismHorizontal (normal, x, y, z, radius, num, d, beginDeg, deg) {
2844
- if (beginDeg === void 0) { beginDeg = 0; }
2845
- if (deg === void 0) { deg = Math.PI * 2; }
2846
- var beginX, beginZ;
2847
- if (num == 4) {
2848
- var temp = radius / 1.414;
2849
- beginX = x + temp;
2850
- beginZ = z + temp;
2851
- }
2852
- else {
2853
- beginX = x + radius;
2854
- beginZ = z;
2855
- }
2856
- var point = [beginX, beginZ];
2857
- if (beginDeg != 0) {
2858
- point = rotate$1(x, z, beginDeg, beginX, beginZ);
2859
- }
2860
- var points = [];
2861
- var perDeg = deg / num;
2862
- for (var i = 0; i < num; i++) {
2863
- points.push(x, y, z);
2864
- if (normal)
2865
- points.push(0, d, 0);
2866
- points.push(point[0], y, point[1]);
2867
- if (normal)
2868
- points.push(0, d, 0);
2869
- point = rotate$1(x, z, perDeg * (i + 1), beginX, beginZ);
2870
- points.push(point[0], y, point[1]);
2871
- if (normal)
2872
- points.push(0, d, 0);
2873
- }
2874
- return points;
2875
- }
2876
-
2877
- function prismVertical (normal, x, y, z, radius, height, num, beginDeg, deg) {
2878
- if (beginDeg === void 0) { beginDeg = 0; }
2879
- if (deg === void 0) { deg = Math.PI * 2; }
2880
- var points = [];
2881
- var beginPosition;
2882
- if (num == 4) {
2883
- beginPosition = rotate$1(x, z, Math.PI * 0.25, x - radius, z);
2884
- }
2885
- else {
2886
- beginPosition = [x + radius, z];
2887
- }
2888
- if (beginDeg != 0) {
2889
- beginPosition = rotate$1.apply(void 0, __spreadArray([x, z, beginDeg], beginPosition, false));
2890
- }
2891
- var perDeg = deg / num, degHalf = deg / (num * 2);
2892
- var endPosition, normalPosition = [];
2893
- for (var i = 0; i < num; i++) {
2894
- endPosition = rotate$1.apply(void 0, __spreadArray([x, z, perDeg], beginPosition, false));
2895
- if (normal) {
2896
- var halfPosition = rotate$1.apply(void 0, __spreadArray([x, z, degHalf], beginPosition, false));
2897
- normalPosition = [halfPosition[0], 0, halfPosition[1]];
2898
- }
2899
- points.push.apply(points, __spreadArray([beginPosition[0], y, beginPosition[1]], normalPosition, false));
2900
- points.push.apply(points, __spreadArray([beginPosition[0], y + height, beginPosition[1]], normalPosition, false));
2901
- points.push.apply(points, __spreadArray([endPosition[0], y + height, endPosition[1]], normalPosition, false));
2902
- points.push.apply(points, __spreadArray([beginPosition[0], y, beginPosition[1]], normalPosition, false));
2903
- points.push.apply(points, __spreadArray([endPosition[0], y, endPosition[1]], normalPosition, false));
2904
- points.push.apply(points, __spreadArray([endPosition[0], y + height, endPosition[1]], normalPosition, false));
2905
- beginPosition = endPosition;
2906
- }
2907
- return points;
2908
- }
2909
-
2910
- function sphereFragment (normal, cx, cy, cz, radius, num, index) {
2911
- var points = [cx, cy + radius, cz], deg = Math.PI * 2 / num;
2912
- var point;
2913
- if (normal)
2914
- points.push(0, radius, 0);
2915
- var copy2 = function () {
2916
- points.push.apply(points, points.slice(points.length - (normal ? 12 : 6)));
2917
- };
2918
- for (var i = 1; i < num * 0.5; i++) {
2919
- point = rotate$1(cx, cy, deg * i, cx, cy + radius);
2920
- if (i > 1)
2921
- copy2();
2922
- var point1 = rotate$1(cx, cz, deg * index, point[0], cz);
2923
- points.push(point1[0], point[1], point1[1]);
2924
- if (normal)
2925
- points.push(point1[0] - cx, point[1] - cy, point1[1] - cz);
2926
- if (i > 1)
2927
- copy2();
2928
- var point2 = rotate$1(cx, cz, deg * (index + 1), point[0], cz);
2929
- points.push(point2[0], point[1], point2[1]);
2930
- if (normal)
2931
- points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz);
2932
- }
2933
- copy2();
2934
- points.push(cx, cy - radius, cz);
2935
- if (normal)
2936
- points.push(0, -radius, 0);
2937
- return points;
2938
- }
2939
-
2940
- function rotateLineFactory (x, y, z, x2, y2, z2) {
2941
- return function (x0, y0, z0, isNormal) {
2942
- if (x == x2 && z == z2)
2943
- return [x0, y0, z0];
2944
- var sin, cos, temp;
2945
- var _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z);
2946
- var _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z;
2947
- var __d = Math.sqrt(_x2 * _x2 + _z2 * _z2);
2948
- cos = _x2 / __d;
2949
- sin = _z2 / __d;
2950
- var _x2N = _z2 * sin + _x2 * cos;
2951
- var d = Math.sqrt(_y2 * _y2 + _x2N * _x2N);
2952
- cos = _y2 / d;
2953
- sin = _x2N / d;
2954
- temp = [_y0, _x0];
2955
- _y0 = temp[0] * cos - temp[1] * sin;
2956
- _x0 = temp[0] * sin + temp[1] * cos;
2957
- cos = _x2 / __d;
2958
- sin = _z2 / __d;
2959
- temp = [_x0, _z0];
2960
- _x0 = temp[0] * cos - temp[1] * sin;
2961
- _z0 = temp[0] * sin + temp[1] * cos;
2962
- return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)];
2963
- };
2964
- }
2965
-
2966
- function triangles (normal, points) {
2967
- if (normal) {
2968
- var _points = [];
2969
- for (var i = 0; i < points.length; i += 9) {
2970
- var ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]];
2971
- var ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]];
2972
- var normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]];
2973
- _points.push.apply(_points, __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([points[i], points[i + 1], points[i + 2]], normalVector, false), [points[i + 3], points[i + 4], points[i + 5]], false), normalVector, false), [points[i + 6], points[i + 7], points[i + 8]], false), normalVector, false));
2974
- }
2975
- return _points;
2976
- }
2977
- else {
2978
- return points;
2979
- }
2980
- }
2981
-
2982
- var Geometry = (function () {
2983
- function Geometry(option) {
2984
- if (option === void 0) { option = {}; }
2985
- this.name = 'Geometry';
2986
- this.__option = mergeOption(option, {
2987
- precision: 0.1,
2988
- normal: false,
2989
- });
2990
- }
2991
- Geometry.prototype.config = function (option) {
2992
- for (var key in option) {
2993
- this.__option[key] = option[key];
2994
- }
2995
- return this;
2996
- };
2997
- Geometry.prototype.splitNum = function (radius, deg) {
2998
- return splitNum(this.__option.precision, radius, deg);
2999
- };
3000
- Geometry.prototype.rotateLine = function (x1, y1, z1, x2, y2, z2) {
3001
- var _this = this;
3002
- var rotateLine = rotateLineFactory(x1, y1, z1, x2, y2, z2);
3003
- return function (x, y, z) { return rotateLine(x, y, z, _this.__option.normal); };
3004
- };
3005
- Geometry.prototype.prismHorizontal = function (x, y, z, radius, num, d, beginDeg, deg) {
3006
- return prismHorizontal(this.__option.normal, x, y, z, radius, num, d, beginDeg, deg);
3007
- };
3008
- Geometry.prototype.prismVertical = function (x, y, z, radius, height, num, beginDeg, deg) {
3009
- return prismVertical(this.__option.normal, x, y, z, radius, height, num, beginDeg, deg);
3010
- };
3011
- Geometry.prototype.sphereFragment = function (cx, cy, cz, radius, num, index) {
3012
- return sphereFragment(this.__option.normal, cx, cy, cz, radius, num, index);
3013
- };
3014
- Geometry.prototype.pie = function (x, y, z, radius, height, beginDeg, deg) {
3015
- var num = splitNum(this.__option.precision, radius, deg);
3016
- var beginXZ = rotate$1(x, z, beginDeg, x + radius, z);
3017
- var endXZ = rotate$1(x, z, beginDeg + deg, x + radius, z);
3018
- var result = [{
3019
- name: "bottom",
3020
- points: prismHorizontal(this.__option.normal, x, y, z, radius, num, height > 0 ? -1 : 1, beginDeg, deg),
3021
- length: 3 * num,
3022
- method: "TRIANGLES"
3023
- }, {
3024
- name: "top",
3025
- points: prismHorizontal(this.__option.normal, x, y + height, z, radius, num, height > 0 ? 1 : -1, beginDeg, deg),
3026
- length: 3 * num,
3027
- method: "TRIANGLES"
3028
- }, {
3029
- name: "side",
3030
- points: prismVertical(this.__option.normal, x, y, z, radius, height, num, beginDeg, deg),
3031
- length: 6 * num,
3032
- method: "TRIANGLES"
3033
- }, {
3034
- name: "begin",
3035
- points: triangles(this.__option.normal, [
3036
- x, y, z, x, y + height, z, beginXZ[0], y, beginXZ[1],
3037
- beginXZ[0], y + height, beginXZ[1], beginXZ[0], y, beginXZ[1], x, y + height, z
3038
- ]),
3039
- length: 6,
3040
- method: "TRIANGLES"
3041
- }, {
3042
- name: "end",
3043
- points: triangles(this.__option.normal, [
3044
- x, y, z, endXZ[0], y, endXZ[1], x, y + height, z,
3045
- endXZ[0], y + height, endXZ[1], x, y + height, z, endXZ[0], y, endXZ[1]
3046
- ]),
3047
- length: 6,
3048
- method: "TRIANGLES"
3049
- }];
3050
- return result;
3051
- };
3052
- Geometry.prototype.cylinder = function (x, y, z, radius, x2, y2, z2) {
3053
- var num = splitNum(this.__option.precision, radius);
3054
- if (arguments.length == 5) {
3055
- return this.prism(x, y, z, radius, x2, num);
3056
- }
3057
- else {
3058
- return this.prism(x, y, z, radius, x2, y2, z2, num);
3059
- }
3060
- };
3061
- Geometry.prototype.prism = function (x, y, z, radius, x2, y2, z2, num) {
3062
- var _a, _b, _c;
3063
- var height, rotateLine = null;
3064
- if (arguments.length == 6) {
3065
- height = x2;
3066
- num = y2;
3067
- }
3068
- else {
3069
- height = (y > y2 ? -1 : 1) * Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y) + (z2 - z) * (z2 - z));
3070
- rotateLine = rotateLineFactory(x, y, z, x2, y2, z2);
3071
- }
3072
- var result = [{
3073
- name: "bottom",
3074
- points: [],
3075
- length: 0,
3076
- method: "TRIANGLES"
3077
- }, {
3078
- name: "top",
3079
- points: [],
3080
- length: 0,
3081
- method: "TRIANGLES"
3082
- }, {
3083
- name: "side",
3084
- points: [],
3085
- length: 0,
3086
- method: "TRIANGLES"
3087
- }];
3088
- (_a = result[0].points).push.apply(_a, prismHorizontal(this.__option.normal, x, y, z, radius, num, height > 0 ? -1 : 1));
3089
- (_b = result[1].points).push.apply(_b, prismHorizontal(this.__option.normal, x, y + height, z, radius, num, height > 0 ? 1 : -1));
3090
- (_c = result[2].points).push.apply(_c, prismVertical(this.__option.normal, x, y, z, radius, height, num));
3091
- for (var i = 0; i < result.length; i++) {
3092
- if (rotateLine) {
3093
- var points = [];
3094
- var isNormal = false;
3095
- for (var index = 0; index < result[i].points.length; index += 3) {
3096
- points.push.apply(points, rotateLine(result[i].points[index], result[i].points[index + 1], result[i].points[index + 2], this.__option.normal && isNormal));
3097
- isNormal = !isNormal;
3098
- }
3099
- result[i].points = points;
3100
- }
3101
- result[i].length = result[i].points.length / (this.__option.normal ? 6 : 3);
3102
- }
3103
- return result;
3104
- };
3105
- Geometry.prototype.sphere = function (cx, cy, cz, radius) {
3106
- var _a;
3107
- var num = splitNum(this.__option.precision, radius);
3108
- var result = [{
3109
- name: "surface",
3110
- points: [],
3111
- length: 0,
3112
- method: "TRIANGLES"
3113
- }];
3114
- for (var i = 0; i < num; i++) {
3115
- (_a = result[0].points).push.apply(_a, sphereFragment(this.__option.normal, cx, cy, cz, radius, num, i));
3116
- }
3117
- result[0].length = result[0].points.length / (this.__option.normal ? 6 : 3);
3118
- return result;
3119
- };
3120
- return Geometry;
3121
- }());
3122
-
3123
2286
  var index = {
3124
2287
  Cardinal: Cardinal,
3125
2288
  Hermite: Hermite,
3126
2289
  Matrix4: Matrix4,
3127
2290
  rotate: rotate$1,
3128
2291
  move: move,
3129
- scale: scale$1,
2292
+ scale: scale,
3130
2293
  getLoopColors: getLoopColors,
3131
- formatColor: formatColor,
3132
2294
  animation: animation,
3133
2295
  ruler: ruler,
3134
2296
  SVG: SVG,
3135
2297
  Canvas: Canvas,
3136
- WebGL: WebGL,
2298
+ _Canvas: Canvas$1,
3137
2299
  getWebGLContext: getWebGLContext,
3138
- Shader: Shader,
2300
+ Shader: ShaderObject,
3139
2301
  Texture: TextureObject,
3140
2302
  Buffer: BufferObject,
3141
2303
  Eoap: Eoap,
3142
2304
  Mercator: Mercator,
3143
- viewHandler: viewHandler,
3144
2305
  resizeObserver: resizeObserver,
3145
2306
  throttle: throttle,
3146
- TreeLayout: TreeLayout,
3147
- Geometry: Geometry
2307
+ TreeLayout: TreeLayout
3148
2308
  };
3149
2309
 
3150
2310
  return index;