vislite 0.4.1-alpha.2 → 0.4.1-beta.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 (113) hide show
  1. package/.editorconfig +19 -0
  2. package/CHANGELOG +17 -8
  3. package/README.md +16 -1
  4. package/lib/Buffer/index.umd.js +2 -2
  5. package/lib/Buffer/index.umd.min.js +2 -2
  6. package/lib/Canvas/index.umd.js +89 -10
  7. package/lib/Canvas/index.umd.min.js +3 -3
  8. package/lib/Cardinal/index.umd.js +2 -2
  9. package/lib/Cardinal/index.umd.min.js +2 -2
  10. package/lib/Eoap/index.umd.js +2 -2
  11. package/lib/Eoap/index.umd.min.js +2 -2
  12. package/lib/Hermite/index.umd.js +2 -2
  13. package/lib/Hermite/index.umd.min.js +2 -2
  14. package/lib/Matrix4/index.umd.js +2 -2
  15. package/lib/Matrix4/index.umd.min.js +2 -2
  16. package/lib/Mercator/index.umd.js +2 -2
  17. package/lib/Mercator/index.umd.min.js +2 -2
  18. package/lib/OralCanvas/index.es.js +79 -8
  19. package/lib/OralCanvas/index.es.min.js +3 -3
  20. package/lib/OralWebGL/index.es.js +35 -10
  21. package/lib/OralWebGL/index.es.min.js +3 -3
  22. package/lib/SVG/index.umd.js +2 -2
  23. package/lib/SVG/index.umd.min.js +2 -2
  24. package/lib/Shader/index.umd.js +82 -3
  25. package/lib/Shader/index.umd.min.js +3 -3
  26. package/lib/Texture/index.umd.js +3 -5
  27. package/lib/Texture/index.umd.min.js +3 -3
  28. package/lib/TreeLayout/index.umd.js +427 -0
  29. package/lib/TreeLayout/index.umd.min.js +11 -0
  30. package/lib/WebGL/index.umd.js +45 -12
  31. package/lib/WebGL/index.umd.min.js +3 -3
  32. package/lib/animation/index.umd.js +3 -3
  33. package/lib/animation/index.umd.min.js +2 -2
  34. package/lib/formatColor/index.umd.js +59 -0
  35. package/lib/formatColor/index.umd.min.js +11 -0
  36. package/lib/getLoopColors/index.umd.js +2 -2
  37. package/lib/getLoopColors/index.umd.min.js +2 -2
  38. package/lib/getWebGLContext/index.umd.js +2 -2
  39. package/lib/getWebGLContext/index.umd.min.js +2 -2
  40. package/lib/index.umd.js +555 -23
  41. package/lib/index.umd.min.js +3 -3
  42. package/lib/resizeObserver/index.umd.js +48 -0
  43. package/lib/resizeObserver/index.umd.min.js +11 -0
  44. package/lib/rotate/index.umd.js +2 -2
  45. package/lib/rotate/index.umd.min.js +2 -2
  46. package/lib/ruler/index.umd.js +2 -2
  47. package/lib/ruler/index.umd.min.js +2 -2
  48. package/lib/throttle/index.umd.js +68 -0
  49. package/lib/throttle/index.umd.min.js +11 -0
  50. package/lib/viewHandler/index.umd.js +2 -2
  51. package/lib/viewHandler/index.umd.min.js +2 -2
  52. package/package/Buffer/index.ts +1 -0
  53. package/package/Canvas/index.ts +1 -0
  54. package/package/OralCanvas/index.ts +1 -0
  55. package/package/OralWebGL/index.ts +1 -0
  56. package/package/Shader/index.ts +39 -1
  57. package/package/Texture/index.ts +1 -0
  58. package/package/TreeLayout/index.ts +3 -0
  59. package/package/WebGL/index.ts +1 -0
  60. package/package/formatColor/index.ts +3 -0
  61. package/package/index.ts +12 -1
  62. package/package/resizeObserver/index.ts +3 -0
  63. package/package/throttle/index.ts +3 -0
  64. package/package.json +1 -1
  65. package/src/Canvas.ts +7 -3
  66. package/src/Eoap.ts +1 -1
  67. package/src/Matrix4/index.ts +1 -1
  68. package/src/Mercator.ts +1 -1
  69. package/src/SVG.ts +2 -1
  70. package/src/TreeLayout/index.ts +186 -0
  71. package/src/WebGL.ts +7 -3
  72. package/src/animation.ts +2 -3
  73. package/src/common/canvas/config.ts +2 -1
  74. package/src/common/canvas/index.ts +10 -3
  75. package/src/common/canvas/painter.ts +74 -5
  76. package/src/common/mergeOption.ts +7 -0
  77. package/src/common/svg/config.ts +2 -1
  78. package/src/common/svg/index.ts +2 -1
  79. package/src/common/svg/tool.ts +2 -1
  80. package/src/common/tree/index.ts +26 -0
  81. package/src/common/tree/toInnerTree.ts +57 -0
  82. package/src/common/tree/toPlainTree.ts +132 -0
  83. package/src/common/webgl/doDraw.ts +2 -0
  84. package/src/common/webgl/getShader.ts +25 -52
  85. package/src/common/webgl/index.ts +4 -3
  86. package/src/common/webgl/texture.ts +2 -5
  87. package/src/formatColor.ts +45 -0
  88. package/src/interpolation/Cardinal.ts +2 -1
  89. package/src/interpolation/Hermite.ts +1 -1
  90. package/src/resizeObserver.ts +37 -0
  91. package/src/ruler.ts +1 -1
  92. package/src/shader/fsColor.c +8 -0
  93. package/src/shader/fsColors.c +8 -0
  94. package/src/shader/fsCube.c +9 -0
  95. package/src/shader/fsImage.c +9 -0
  96. package/src/shader/vsColor.c +18 -0
  97. package/src/shader/vsColors.c +14 -0
  98. package/src/shader/vsCube.c +14 -0
  99. package/src/shader/vsImage.c +14 -0
  100. package/src/throttle.ts +50 -0
  101. package/src/viewHandler.ts +1 -1
  102. package/types/Canvas.d.ts +12 -0
  103. package/types/CanvasOption.d.ts +2 -2
  104. package/types/Shader.d.ts +6 -0
  105. package/types/Tree.d.ts +38 -0
  106. package/types/TreeConfig.d.ts +25 -0
  107. package/types/TreeLayout.d.ts +49 -0
  108. package/types/TreeOption.d.ts +46 -0
  109. package/types/formatColor.d.ts +3 -0
  110. package/types/index.d.ts +24 -1
  111. package/types/resizeObserver.d.ts +3 -0
  112. package/types/throttle.d.ts +5 -0
  113. package/types/throttleOption.d.ts +20 -0
@@ -0,0 +1,427 @@
1
+ /*!
2
+ * VISLite JavaScript Library v0.4.1-beta.0
3
+ * git+https://github.com/oi-contrib/VISLite.git
4
+ *
5
+ * Copyright zxl20070701
6
+ * Released under the MIT license
7
+ * https://zxl20070701.github.io/notebook/home.html
8
+ *
9
+ * Publish Date: Wed Aug 23 2023 22:06:27 GMT+0800 (中国标准时间)
10
+ */
11
+ (function (global, factory) {
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
13
+ typeof define === 'function' && define.amd ? define(factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite_TreeLayout = factory());
15
+ })(this, (function () { 'use strict';
16
+
17
+ /******************************************************************************
18
+ Copyright (c) Microsoft Corporation.
19
+
20
+ Permission to use, copy, modify, and/or distribute this software for any
21
+ purpose with or without fee is hereby granted.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
+ PERFORMANCE OF THIS SOFTWARE.
30
+ ***************************************************************************** */
31
+ /* global Reflect, Promise, SuppressedError, Symbol */
32
+
33
+ var extendStatics = function(d, b) {
34
+ extendStatics = Object.setPrototypeOf ||
35
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
36
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
37
+ return extendStatics(d, b);
38
+ };
39
+
40
+ function __extends(d, b) {
41
+ if (typeof b !== "function" && b !== null)
42
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
43
+ extendStatics(d, b);
44
+ function __() { this.constructor = d; }
45
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
46
+ }
47
+
48
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
49
+ var e = new Error(message);
50
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
51
+ };
52
+
53
+ var toInnerTree = (function (initTree, config) {
54
+ var tempTree = {};
55
+ var temp = config.root(initTree), id, rid;
56
+ id = rid = config.id(temp);
57
+ tempTree[id] = {
58
+ "data": temp,
59
+ "pid": null,
60
+ "id": id,
61
+ "isOpen": true,
62
+ "show": true,
63
+ "children": []
64
+ };
65
+ var num = 1;
66
+ (function createTree(pdata, pid) {
67
+ var children = config.children(pdata, initTree);
68
+ num += children ? children.length : 0;
69
+ for (var flag = 0; children && flag < children.length; flag++) {
70
+ id = config.id(children[flag]);
71
+ tempTree[pid].children.push(id);
72
+ tempTree[id] = {
73
+ "data": children[flag],
74
+ "pid": pid,
75
+ "id": id,
76
+ "isOpen": true,
77
+ "show": true,
78
+ "children": []
79
+ };
80
+ createTree(children[flag], id);
81
+ }
82
+ })(temp, id);
83
+ return {
84
+ rid: rid,
85
+ value: tempTree,
86
+ num: num
87
+ };
88
+ });
89
+
90
+ function toPlainTree (initTree, config, noOpens) {
91
+ var treeData = toInnerTree(initTree, config);
92
+ var alltreedata = treeData.value;
93
+ var rootid = treeData.rid;
94
+ if (treeData.num == 1) {
95
+ alltreedata[rootid].left = 0.5;
96
+ alltreedata[rootid].top = 0.5;
97
+ alltreedata[rootid].show = true;
98
+ return {
99
+ deep: 1,
100
+ node: alltreedata,
101
+ root: rootid,
102
+ size: 1
103
+ };
104
+ }
105
+ else {
106
+ var beforeDis_1 = [], size_1 = 0, maxDeep_1 = 0;
107
+ if (noOpens[rootid]) {
108
+ alltreedata[rootid].left = 0.5;
109
+ alltreedata[rootid].top = 0.5;
110
+ alltreedata[rootid].show = true;
111
+ size_1 = 1;
112
+ }
113
+ else {
114
+ (function positionCalc(pNode, deep) {
115
+ if (deep > maxDeep_1)
116
+ maxDeep_1 = deep;
117
+ var flag = 0;
118
+ if (!noOpens[pNode.id]) {
119
+ for (flag = 0; flag < pNode.children.length; flag++)
120
+ positionCalc(alltreedata[pNode.children[flag]], deep + 1);
121
+ }
122
+ alltreedata[pNode.id].left = deep + 0.5;
123
+ if (flag == 0) {
124
+ if (beforeDis_1[deep] == void 0)
125
+ beforeDis_1[deep] = -0.5;
126
+ if (beforeDis_1[deep - 1] == void 0)
127
+ beforeDis_1[deep - 1] = -0.5;
128
+ alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
129
+ var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
130
+ if (pTop - 1 < beforeDis_1[deep - 1])
131
+ alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
132
+ }
133
+ else {
134
+ alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
135
+ }
136
+ if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
137
+ var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
138
+ alltreedata[_pid].top += needUp_1;
139
+ if (beforeDis_1[_deep] < alltreedata[_pid].top)
140
+ beforeDis_1[_deep] = alltreedata[_pid].top;
141
+ for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
142
+ doUp(alltreedata[_pid].children[_flag], _deep + 1);
143
+ }
144
+ })(pNode.id, deep);
145
+ }
146
+ beforeDis_1[deep] = alltreedata[pNode.id].top;
147
+ if (alltreedata[pNode.id].top + 0.5 > size_1)
148
+ size_1 = alltreedata[pNode.id].top + 0.5;
149
+ })(alltreedata[rootid], 0);
150
+ }
151
+ for (var key in noOpens) {
152
+ if (noOpens[key]) {
153
+ alltreedata[key].isOpen = false;
154
+ (function updateHidden(pid, left, top) {
155
+ for (var index = 0; index < alltreedata[pid].children.length; index++) {
156
+ alltreedata[alltreedata[pid].children[index]].left = left;
157
+ alltreedata[alltreedata[pid].children[index]].top = top;
158
+ alltreedata[alltreedata[pid].children[index]].show = false;
159
+ updateHidden(alltreedata[pid].children[index], left, top);
160
+ }
161
+ })(key, alltreedata[key].left, alltreedata[key].top);
162
+ }
163
+ }
164
+ return {
165
+ "node": alltreedata,
166
+ "root": rootid,
167
+ "size": size_1,
168
+ "deep": maxDeep_1 + 1
169
+ };
170
+ }
171
+ }
172
+
173
+ function mergeOption (option, defaultOption) {
174
+ for (var key in option) {
175
+ defaultOption[key] = option[key];
176
+ }
177
+ return defaultOption;
178
+ }
179
+
180
+ var Tree = (function () {
181
+ function Tree(config) {
182
+ if (config === void 0) { config = {}; }
183
+ this.name = 'Tree';
184
+ this.__config = mergeOption(config, {
185
+ root: function (initTree) { return initTree; },
186
+ children: function (parentTree) { return parentTree.children; },
187
+ id: function (treedata) { return treedata.name; }
188
+ });
189
+ }
190
+ Tree.prototype.use = function (initTree, noOpens) {
191
+ if (noOpens === void 0) { noOpens = {}; }
192
+ return toPlainTree(initTree, this.__config, noOpens);
193
+ };
194
+ return Tree;
195
+ }());
196
+
197
+ var $timers = [];
198
+ var $interval = 13;
199
+ var $timerId;
200
+ function animation (doback, duration, callback) {
201
+ if (duration === void 0) { duration = 400; }
202
+ if (callback === void 0) { callback = function () { }; }
203
+ var clock = {
204
+ "timer": function (tick, duration, callback) {
205
+ if (!tick) {
206
+ throw new Error('Tick is required!');
207
+ }
208
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
209
+ $timers.push({
210
+ "id": id,
211
+ "createTime": new Date(),
212
+ "tick": tick,
213
+ "duration": duration,
214
+ "callback": callback
215
+ });
216
+ clock.start();
217
+ return id;
218
+ },
219
+ "start": function () {
220
+ if (!$timerId) {
221
+ $timerId = setInterval(clock.tick, $interval);
222
+ }
223
+ },
224
+ "tick": function () {
225
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
226
+ $timers = [];
227
+ $timers.length = 0;
228
+ for (flag = 0; flag < timers.length; flag++) {
229
+ timer = timers[flag];
230
+ createTime = timer.createTime;
231
+ tick = timer.tick;
232
+ duration = timer.duration;
233
+ callback = timer.callback;
234
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
235
+ passTime = passTime > 1 ? 1 : passTime;
236
+ tick(passTime);
237
+ if (passTime < 1 && timer.id) {
238
+ $timers.push(timer);
239
+ }
240
+ else {
241
+ callback(passTime);
242
+ }
243
+ }
244
+ if ($timers.length <= 0) {
245
+ clock.stop();
246
+ }
247
+ },
248
+ "stop": function () {
249
+ if ($timerId) {
250
+ clearInterval($timerId);
251
+ $timerId = null;
252
+ }
253
+ }
254
+ };
255
+ var id = clock.timer(function (deep) {
256
+ doback(deep);
257
+ }, duration, callback);
258
+ return function () {
259
+ var i;
260
+ for (i in $timers) {
261
+ if ($timers[i].id == id) {
262
+ $timers[i].id = void 0;
263
+ return;
264
+ }
265
+ }
266
+ };
267
+ }
268
+
269
+ function rotate (cx, cy, deg, x, y) {
270
+ var cos = Math.cos(deg), sin = Math.sin(deg);
271
+ return [
272
+ (x - cx) * cos - (y - cy) * sin + cx,
273
+ (x - cx) * sin + (y - cy) * cos + cy
274
+ ];
275
+ }
276
+
277
+ var TreeLayout = (function (_super) {
278
+ __extends(TreeLayout, _super);
279
+ function TreeLayout() {
280
+ var _this = _super !== null && _super.apply(this, arguments) || this;
281
+ _this.name = 'TreeLayout';
282
+ _this.__option = {
283
+ offsetX: 0,
284
+ offsetY: 0,
285
+ duration: 500,
286
+ type: "plain",
287
+ direction: "LR",
288
+ x: 100,
289
+ y: 100,
290
+ width: 100,
291
+ height: 100,
292
+ radius: 100
293
+ };
294
+ _this.__noOpens = {};
295
+ return _this;
296
+ }
297
+ TreeLayout.prototype.setOption = function (option) {
298
+ mergeOption(option, this.__option);
299
+ return this;
300
+ };
301
+ TreeLayout.prototype.use = function (initTree, noOpens) {
302
+ var tree = _super.prototype.use.call(this, initTree, noOpens);
303
+ if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
304
+ for (var key in tree.node) {
305
+ if (!tree.node[key].show) {
306
+ var deep = 0, pid = key;
307
+ do {
308
+ pid = tree.node[pid].pid;
309
+ deep++;
310
+ } while (!tree.node[pid].show);
311
+ tree.node[key].left += this.__option.offsetX * deep;
312
+ tree.node[key].top += this.__option.offsetY * deep;
313
+ }
314
+ }
315
+ }
316
+ if (this.__option.type == 'rect') {
317
+ if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
318
+ var perW = this.__option.height / tree.size;
319
+ var perD = this.__option.width / (tree.deep - 1);
320
+ var balanceW = this.__option.y - this.__option.height * 0.5;
321
+ var flag = this.__option.direction == 'LR' ? 1 : -1;
322
+ for (var key in tree.node) {
323
+ if (tree.deep == 1) {
324
+ tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
325
+ tree.node[key].top = this.__option.y;
326
+ }
327
+ else {
328
+ tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
329
+ tree.node[key].top = tree.node[key].top * perW + balanceW;
330
+ }
331
+ }
332
+ }
333
+ else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
334
+ var perW = this.__option.width / tree.size;
335
+ var perD = this.__option.height / (tree.deep - 1);
336
+ var balanceW = this.__option.x - this.__option.width * 0.5;
337
+ var flag = this.__option.direction == 'TB' ? 1 : -1;
338
+ for (var key in tree.node) {
339
+ if (tree.deep == 1) {
340
+ tree.node[key].left = this.__option.x;
341
+ tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
342
+ }
343
+ else {
344
+ var left = tree.node[key].left;
345
+ tree.node[key].left = tree.node[key].top * perW + balanceW;
346
+ tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
347
+ }
348
+ }
349
+ }
350
+ }
351
+ else if (this.__option.type == 'circle') {
352
+ var cx = this.__option.x, cy = this.__option.y;
353
+ var deg = Math.PI * 2 / tree.size;
354
+ var per = this.__option.radius / (tree.deep - 1);
355
+ for (var key in tree.node) {
356
+ if (tree.node[key].left == 0.5) {
357
+ tree.node[key].left = cx;
358
+ tree.node[key].top = cy;
359
+ }
360
+ else {
361
+ var position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
362
+ tree.node[key].left = position[0];
363
+ tree.node[key].top = position[1];
364
+ }
365
+ }
366
+ }
367
+ return tree;
368
+ };
369
+ TreeLayout.prototype.bind = function (initTree, renderBack) {
370
+ this.__rback = renderBack;
371
+ this.__oralTree = initTree;
372
+ this.__preTree = this.use(this.__oralTree);
373
+ this.__rback(this.__preTree);
374
+ return this;
375
+ };
376
+ TreeLayout.prototype.unbind = function () {
377
+ this.__rback = null;
378
+ this.__oralTree = null;
379
+ this.__preTree = null;
380
+ this.__noOpens = {};
381
+ return this;
382
+ };
383
+ TreeLayout.prototype.doUpdate = function () {
384
+ var _this = this;
385
+ var newTree = this.use(this.__oralTree, this.__noOpens);
386
+ var cacheTree = JSON.parse(JSON.stringify(newTree));
387
+ animation(function (deep) {
388
+ for (var key in cacheTree.node) {
389
+ if (newTree.node[key].show || _this.__preTree.node[key].show) {
390
+ cacheTree.node[key].show = true;
391
+ cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
392
+ cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
393
+ }
394
+ }
395
+ _this.__rback(cacheTree);
396
+ }, this.__option.duration, function () {
397
+ _this.__preTree = newTree;
398
+ _this.__rback(_this.__preTree);
399
+ });
400
+ };
401
+ TreeLayout.prototype.closeNode = function (id) {
402
+ if (!this.__preTree)
403
+ return;
404
+ this.__noOpens[id] = true;
405
+ this.doUpdate();
406
+ return this;
407
+ };
408
+ TreeLayout.prototype.openNode = function (id) {
409
+ if (!this.__preTree)
410
+ return;
411
+ this.__noOpens[id] = false;
412
+ this.doUpdate();
413
+ return this;
414
+ };
415
+ TreeLayout.prototype.toggleNode = function (id) {
416
+ if (!this.__preTree)
417
+ return;
418
+ this.__noOpens[id] = !this.__noOpens[id];
419
+ this.doUpdate();
420
+ return this;
421
+ };
422
+ return TreeLayout;
423
+ }(Tree));
424
+
425
+ return TreeLayout;
426
+
427
+ }));
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * VISLite JavaScript Library v0.4.1-beta.0
3
+ * git+https://github.com/oi-contrib/VISLite.git
4
+ *
5
+ * Copyright zxl20070701
6
+ * Released under the MIT license
7
+ * https://zxl20070701.github.io/notebook/home.html
8
+ *
9
+ * Publish Date: Wed Aug 23 2023 22:06:27 GMT+0800 (中国标准时间)
10
+ */
11
+ var t,e;t=this,e=function(){"use strict";var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};function e(t,e){for(var o in t)e[o]=t[o];return e}"function"==typeof SuppressedError&&SuppressedError;var o,n=function(){function t(t){void 0===t&&(t={}),this.name="Tree",this.__config=e(t,{root:function(t){return t},children:function(t){return t.children},id:function(t){return t.name}})}return t.prototype.use=function(t,e){return void 0===e&&(e={}),function(t,e,o){var n=function(t,e){var o,n,i={},r=e.root(t);o=n=e.id(r),i[o]={data:r,pid:null,id:o,isOpen:!0,show:!0,children:[]};var p=1;return function n(r,s){var d=e.children(r,t);p+=d?d.length:0;for(var _=0;d&&_<d.length;_++)o=e.id(d[_]),i[s].children.push(o),i[o]={data:d[_],pid:s,id:o,isOpen:!0,show:!0,children:[]},n(d[_],o)}(r,o),{rid:n,value:i,num:p}}(t,e),i=n.value,r=n.rid;if(1==n.num)return i[r].left=.5,i[r].top=.5,i[r].show=!0,{deep:1,node:i,root:r,size:1};var p=[],s=0,d=0;for(var _ in o[r]?(i[r].left=.5,i[r].top=.5,i[r].show=!0,s=1):function t(e,n){n>d&&(d=n);var r=0;if(!o[e.id])for(r=0;r<e.children.length;r++)t(i[e.children[r]],n+1);if(i[e.id].left=n+.5,0==r?(null==p[n]&&(p[n]=-.5),null==p[n-1]&&(p[n-1]=-.5),i[e.id].top=p[n]+1,p[n]+1+.5*(i[e.pid].children.length-1)-1<p[n-1]&&(i[e.id].top=p[n-1]+1-.5*(i[e.pid].children.length-1))):i[e.id].top=.5*(i[e.children[0]].top+i[e.children[r-1]].top),i[e.id].top<=p[n])var _=p[n]+1-i[e.id].top((function t(e,o){i[e].top+=_,p[o]<i[e].top&&(p[o]=i[e].top);for(var n=0;n<i[e].children.length;n++)t(i[e].children[n],o+1)}))(e.id,n);p[n]=i[e.id].top,i[e.id].top+.5>s&&(s=i[e.id].top+.5)}(i[r],0),o)o[_]&&(i[_].isOpen=!1,function t(e,o,n){for(var r=0;r<i[e].children.length;r++)i[i[e].children[r]].left=o,i[i[e].children[r]].top=n,i[i[e].children[r]].show=!1,t(i[e].children[r],o,n)}(_,i[_].left,i[_].top));return{node:i,root:r,size:s,deep:d+1}}(t,this.__config,e)},t}(),i=[];function r(t,e,o,n,i){var r=Math.cos(o),p=Math.sin(o);return[(n-t)*r-(i-e)*p+t,(n-t)*p+(i-e)*r+e]}var p=function(n){function p(){var t=null!==n&&n.apply(this,arguments)||this;return t.name="TreeLayout",t.__option={offsetX:0,offsetY:0,duration:500,type:"plain",direction:"LR",x:100,y:100,width:100,height:100,radius:100},t.__noOpens={},t}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(p,n),p.prototype.setOption=function(t){return e(t,this.__option),this},p.prototype.use=function(t,e){var o=n.prototype.use.call(this,t,e);if(0!=this.__option.offsetX||0!=this.__option.offsetY)for(var i in o.node)if(!o.node[i].show){var p=0,s=i;do{s=o.node[s].pid,p++}while(!o.node[s].show);o.node[i].left+=this.__option.offsetX*p,o.node[i].top+=this.__option.offsetY*p}if("rect"==this.__option.type){if("LR"==this.__option.direction||"RL"==this.__option.direction){var d=this.__option.height/o.size,_=this.__option.width/(o.deep-1),h=this.__option.y-.5*this.__option.height,f="LR"==this.__option.direction?1:-1;for(var i in o.node)1==o.deep?(o.node[i].left=this.__option.x+.5*this.__option.width*f,o.node[i].top=this.__option.y):(o.node[i].left=this.__option.x+(o.node[i].left-.5)*_*f,o.node[i].top=o.node[i].top*d+h)}else if("TB"==this.__option.direction||"BT"==this.__option.direction)for(var i in d=this.__option.width/o.size,_=this.__option.height/(o.deep-1),h=this.__option.x-.5*this.__option.width,f="TB"==this.__option.direction?1:-1,o.node)if(1==o.deep)o.node[i].left=this.__option.x,o.node[i].top=this.__option.y+.5*this.__option.height*f;else{var l=o.node[i].left;o.node[i].left=o.node[i].top*d+h,o.node[i].top=this.__option.y+(l-.5)*_*f}}else if("circle"==this.__option.type){var u=this.__option.x,c=this.__option.y,a=2*Math.PI/o.size,v=this.__option.radius/(o.deep-1);for(var i in o.node)if(.5==o.node[i].left)o.node[i].left=u,o.node[i].top=c;else{var y=r(u,c,a*o.node[i].top,u+(o.node[i].left-.5)*v,c);o.node[i].left=y[0],o.node[i].top=y[1]}}return o},p.prototype.bind=function(t,e){return this.__rback=e,this.__oralTree=t,this.__preTree=this.use(this.__oralTree),this.__rback(this.__preTree),this},p.prototype.unbind=function(){return this.__rback=null,this.__oralTree=null,this.__preTree=null,this.__noOpens={},this},p.prototype.doUpdate=function(){var t=this,e=this.use(this.__oralTree,this.__noOpens),n=JSON.parse(JSON.stringify(e));!function(t,e,n){void 0===e&&(e=400),void 0===n&&(n=function(){});var r={timer:function(t,e,o){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return i.push({id:n,createTime:new Date,tick:t,duration:e,callback:o}),r.start(),n},start:function(){o||(o=setInterval(r.tick,13))},tick:function(){var t,e,o,n,p,s,d,_=i;for((i=[]).length=0,e=0;e<_.length;e++)t=(p=_[e]).createTime,o=p.tick,s=p.duration,n=p.callback,o(d=(d=(+(new Date).valueOf()-t.valueOf())/s)>1?1:d),d<1&&p.id?i.push(p):n(d);i.length<=0&&r.stop()},stop:function(){o&&(clearInterval(o),o=null)}};r.timer((function(e){t(e)}),e,n)}((function(o){for(var i in n.node)(e.node[i].show||t.__preTree.node[i].show)&&(n.node[i].show=!0,n.node[i].left=t.__preTree.node[i].left+(e.node[i].left-t.__preTree.node[i].left)*o,n.node[i].top=t.__preTree.node[i].top+(e.node[i].top-t.__preTree.node[i].top)*o);t.__rback(n)}),this.__option.duration,(function(){t.__preTree=e,t.__rback(t.__preTree)}))},p.prototype.closeNode=function(t){if(this.__preTree)return this.__noOpens[t]=!0,this.doUpdate(),this},p.prototype.openNode=function(t){if(this.__preTree)return this.__noOpens[t]=!1,this.doUpdate(),this},p.prototype.toggleNode=function(t){if(this.__preTree)return this.__noOpens[t]=!this.__noOpens[t],this.doUpdate(),this},p}(n);return p},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite_TreeLayout=e();
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.4.1-alpha.2
2
+ * VISLite JavaScript Library v0.4.1-beta.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 Aug 12 2023 23:34:54 GMT+0800 (中国标准时间)
9
+ * Publish Date: Wed Aug 23 2023 22:06:27 GMT+0800 (中国标准时间)
10
10
  */
11
11
  (function (global, factory) {
12
12
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -261,9 +261,7 @@
261
261
 
262
262
  var initTexture = function (painter, type, unit) {
263
263
  var texture = painter.createTexture();
264
- if (type == painter.TEXTURE_2D) {
265
- painter.activeTexture(painter['TEXTURE' + unit]);
266
- }
264
+ painter.activeTexture(painter['TEXTURE' + unit]);
267
265
  painter.bindTexture(type, texture);
268
266
  return texture;
269
267
  };
@@ -359,18 +357,44 @@
359
357
  return ShaderObject;
360
358
  }());
361
359
 
360
+ var vsColor = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n\r\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\r\n temp.z = -1.0 * temp.z;\r\n\r\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\r\n float dist = 4.0;\r\n\r\n // 使用投影直接计算\r\n // 为保证纹理和相对位置正确\r\n // x、y、z的改变满足线性变换\r\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));\r\n}";
361
+
362
+ var vsColors = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_color = a_color;\r\n}";
363
+
364
+ var vsImage = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec2 a_textcoord;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_textcoord = a_textcoord;\r\n}";
365
+
366
+ var vsCube = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_normal;\r\nvarying vec3 v_normal;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_normal = normalize(vec3(a_normal));\r\n}";
367
+
368
+ var fsColor = "precision mediump float;\r\n\r\nuniform vec4 u_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = u_color;\r\n}";
369
+
370
+ var fsColors = "precision mediump float;\r\n\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_color;\r\n}";
371
+
372
+ var fsImage = "precision mediump float;\r\n\r\nuniform sampler2D u_sampler;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = texture2D(u_sampler, v_textcoord);\r\n}";
373
+
374
+ var fsCube = "precision mediump float;\r\n\r\nvarying vec3 v_normal;\r\nuniform samplerCube u_texture;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\r\n}";
375
+
362
376
  var shaders = {};
363
377
  function getShader (type, painter, mesh) {
378
+ var _a, _b;
364
379
  var uniqueName = type +
365
- (mesh.geometry.attributes.normal ? "1" : "0") +
366
- (mesh.material.image ? "1" : "0") +
367
380
  (mesh.material.color ? "1" : "0") +
368
381
  (mesh.material.colors ? "1" : "0") +
382
+ (mesh.material.image ? "1" : "0") +
369
383
  (mesh.material.cube ? "1" : "0");
370
384
  if (shaders[uniqueName])
371
385
  return shaders[uniqueName].use();
372
- var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.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(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n ").concat(mesh.material.colors ? 'attribute vec4 a_color;varying vec4 v_color;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\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(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n ").concat(mesh.material.colors ? 'v_color=a_color;' : '', "\n }\n ");
373
- var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n ").concat(mesh.material.colors ? 'varying vec4 v_color;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n ").concat(mesh.material.colors ? 'gl_FragColor=v_color;' : '', "\n }\n ");
386
+ var vertexShader = (_a = {},
387
+ _a[type + "1000"] = vsColor,
388
+ _a[type + "0100"] = vsColors,
389
+ _a[type + "0010"] = vsImage,
390
+ _a[type + "0001"] = vsCube,
391
+ _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");
392
+ var fragmentShader = (_b = {},
393
+ _b[type + "1000"] = fsColor,
394
+ _b[type + "0100"] = fsColors,
395
+ _b[type + "0010"] = fsImage,
396
+ _b[type + "0001"] = fsCube,
397
+ _b)[uniqueName];
374
398
  var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
375
399
  shaders[uniqueName] = shader;
376
400
  return shader;
@@ -399,6 +423,7 @@
399
423
  }
400
424
  else if ("cube" in mesh.material) {
401
425
  var size = mesh.material.cube.right.image.value.width;
426
+ painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
402
427
  getTexture(type, painter, 'cube').useCube([
403
428
  mesh.material.cube.right.image.value,
404
429
  mesh.material.cube.left.image.value,
@@ -573,7 +598,7 @@
573
598
  WebGL.prototype.setRegion = function (regionName) {
574
599
  this.__regionName = regionName + "";
575
600
  if (regionName) {
576
- if (this.__regionList[regionName] == undefined) {
601
+ if (this.__regionList[regionName] == void 0) {
577
602
  this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
578
603
  }
579
604
  this.__regionColor = this.__regionList[regionName];
@@ -603,6 +628,13 @@
603
628
  return WebGL;
604
629
  }());
605
630
 
631
+ function mergeOption (option, defaultOption) {
632
+ for (var key in option) {
633
+ defaultOption[key] = option[key];
634
+ }
635
+ return defaultOption;
636
+ }
637
+
606
638
  var WebGL = (function (_super) {
607
639
  __extends(WebGL, _super);
608
640
  function WebGL(el, option) {
@@ -610,8 +642,9 @@
610
642
  if (!el) {
611
643
  throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
612
644
  }
613
- if (!('region' in option))
614
- option.region = true;
645
+ option = mergeOption(option, {
646
+ region: true
647
+ });
615
648
  var width = el.clientWidth, height = el.clientHeight;
616
649
  var ViewCanvas, RegionCanvas;
617
650
  var _el = el;
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.4.1-alpha.2
2
+ * VISLite JavaScript Library v0.4.1-beta.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 Aug 12 2023 23:34:54 GMT+0800 (中国标准时间)
9
+ * Publish Date: Wed Aug 23 2023 22:06:27 GMT+0800 (中国标准时间)
10
10
  */
11
- var t,r;t=this,r=function(){"use strict";var t=function(r,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},t(r,e)};function r(t,r,e){if(e||2===arguments.length)for(var i,o=0,n=r.length;o<n;o++)!i&&o in r||(i||(i=Array.prototype.slice.call(r,0,o)),i[o]=r[o]);return t.concat(i||Array.prototype.slice.call(r))}function e(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],o=null,n=0;n<i.length;n++){try{o=t.getContext(i[n],e)}catch(t){}if(o)break}if(!o)throw new Error("Non canvas or browser does not support webgl.");var a=o.canvas.width,_=o.canvas.height,s=a*r,u=_*r;return o.viewport(.5*(a-s),.5*(_-u),s,u),o.depthFunc(o.LEQUAL),o.enable(o.DEPTH_TEST),o}function i(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,o){return"rgba("+i[4*((o=e-o)*r+t)]+","+i[4*(o*r+t)+1]+","+i[4*(o*r+t)+2]+","+i[4*(o*r+t)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var o=function(t,r){for(var e=[],i=0;i<4;i++)for(var o=0;o<r.length/4;o++)e[4*o+i]=t[i]*r[4*o]+t[i+4]*r[4*o+1]+t[i+8]*r[4*o+2]+t[i+12]*r[4*o+3];return e},n=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,i){return void 0===i&&(i=0),this.__matrix4=o(function(t,r,e,i){void 0===i&&(i=0);var o=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/o,e*t/o,i*t/o,1]}(t,r,e,i),this.__matrix4),this},t.prototype.rotate=function(t,r,e,i,n,a,_){var s=function(t,r,e,i,o,n){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,o=r,n=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof n||(i=t,o=r,n=e,t=0,r=0,e=0),t==i&&r==o&&e==n)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(o-r)*(o-r)),_=0!=a?(o-r)/a:1,s=0!=a?(i-t)/a:0,u=(i-t)*s+(o-r)*_,m=n-e,c=Math.sqrt(u*u+m*m),l=0!=c?m/c:1,h=0!=c?u/c:0;return[[_,l*s,s*h,0,-s,_*l,_*h,0,0,-h,l,0,r*s-t*_,e*h-t*s*l-r*_*l,-t*s*h-r*_*h-e*l,1],[_,-s,0,0,l*s,l*_,-h,0,s*h,_*h,l,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,i,n,a,_);return this.__matrix4=o(o(o(s[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)),s[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,i,n,a){return void 0===i&&(i=0),void 0===n&&(n=0),void 0===a&&(a=0),this.__matrix4=o(function(t,r,e,i,o,n){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,o-o*r,n-n*e,1]}(t,r,e,i,n,a),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?o(this.__matrix4,t):o(t,this.__matrix4),this},t.prototype.use=function(t,r,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),o(this.__matrix4,[t,r,e,i])},t.prototype.value=function(){return this.__matrix4},t}(),a=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 o=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(o,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,o,n,a){t.vertexAttribPointer(r,e,i,a,o,n),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),_=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,o,n){t.texImage2D(r,e,i,i,o,n)}(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,o,n,a,_,s){for(var u,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++)n[c]&&(u=m[c],t.texImage2D(u,e,i,a,_,0,i,o,null),t.bindTexture(r,s),t.texImage2D(u,e,i,i,o,n[c]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),s={};function u(t,r,e){var i=t+"-"+e;return s[i]||(s[i]=new _(r,e)),s[i]}var m=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},c=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=m(t,t.VERTEX_SHADER,r),o=m(t,t.FRAGMENT_SHADER,e),n=t.createProgram();if(t.attachShader(n,i),t.attachShader(n,o),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(n));return n}(this.__painter,t,r),this},t}(),l={};function h(t,r,e,i,o){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.colors?"1":"0")+(e.material.cube?"1":"0");if(l[i])return l[i].use();var o="\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 ").concat(e.material.colors?"attribute vec4 a_color;varying vec4 v_color;":"","\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 ").concat(e.material.colors?"v_color=a_color;":"","\n }\n "),n="\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 ").concat(e.material.colors?"varying vec4 v_color;":"","\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 ").concat(e.material.colors?"gl_FragColor=v_color;":"","\n }\n "),a=new c(r).compile(o,n).use();return l[i]=a,a}(t,r,e);if(new a(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(n.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_world"),!1,o.matrix),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_proporion"),!1,o.proporion),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new a(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(n.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,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),"colors"in e.material)new a(r).use().write(e.material.colors.array).divide(r.getAttribLocation(n.program,"a_color"),e.material.colors.itemSize,e.material.colors.itemSize,0);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 a(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 a(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 p=!1,g=function(){function t(t,r){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 o=[],n=0;n<i;n++)o[n]=t;return function(){for(var n=0;n<i;n++){if(o[n]+e<r){o[n]=+(o[n]+e).toFixed(7);break}n<i-1&&(o[n]=t)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new n([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=e(t,10),r&&(this.__regionPainter=e(r,10,{}));var i=this.painter.canvas.width/this.painter.canvas.height,o=1,a=1;i>1?o=1/i:a=i;var _=Math.min(o,a);this.__proporion=[o,0,0,0,0,a,0,0,0,0,_,0,0,0,0,1]}return t.prototype.matrix=function(t){return new n(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?this.__regionPainter&&(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},t.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(p=!0);var e={matrix:t.matrix.value()},o={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var n=0;n<t.mesh.length;n++)r?this.__regionPainter&&(h("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[n].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},e,o),this.__getColor=i(this.__regionPainter)):h("region"+this.__unique,this.painter,t.mesh[n],e,o)},t.prototype.render=function(t){"matrix"in t||(t.matrix=new n),"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)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(t),this.draw(t)},t.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=r(r([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},t.prototype.getRegion=function(t,r){var e=this;return p&&this.review(!0),p=!1,new Promise((function(i,o){var n=e.__getColor(t,r);for(var a in e.__regionList){var _=e.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==n){i(a);break}}i("")}))},t}();return function(r){function e(t,e){if(void 0===e&&(e={}),!t)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");"region"in e||(e.region=!0);var i,o,n=t.clientWidth,a=t.clientHeight,_=t;_._vislite_canvas_?(i=_._vislite_canvas_[0],o=_._vislite_canvas_[1]):(e.region&&(o=document.createElement("canvas"),t.appendChild(o),o.style.position="absolute",o.style.zIndex="-1",o.style.opacity="0"),i=document.createElement("canvas"),t.appendChild(i),_._vislite_canvas_=[i,o],t.setAttribute("vislite","WebGL"));for(var s=0,u=[i,o];s<u.length;s++){var m=u[s];m&&(m.style.width=n+"px",m.setAttribute("width",n+""),m.style.height=a+"px",m.setAttribute("height",a+""))}return r.call(this,i,o)||this}return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,r),e}(g)},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite_WebGL=r();
11
+ var t,r;t=this,r=function(){"use strict";var t=function(r,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},t(r,e)};function r(t,r,e){if(e||2===arguments.length)for(var i,n=0,o=r.length;n<o;n++)!i&&n in r||(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return t.concat(i||Array.prototype.slice.call(r))}function e(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<i.length;o++){try{n=t.getContext(i[o],e)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var a=n.canvas.width,s=n.canvas.height,_=a*r,u=s*r;return n.viewport(.5*(a-_),.5*(s-u),_,u),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}function i(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,n){return"rgba("+i[4*((n=e-n)*r+t)]+","+i[4*(n*r+t)+1]+","+i[4*(n*r+t)+2]+","+i[4*(n*r+t)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var n=function(t,r){for(var e=[],i=0;i<4;i++)for(var n=0;n<r.length/4;n++)e[4*n+i]=t[i]*r[4*n]+t[i+4]*r[4*n+1]+t[i+8]*r[4*n+2]+t[i+12]*r[4*n+3];return e},o=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,i){return void 0===i&&(i=0),this.__matrix4=n(function(t,r,e,i){void 0===i&&(i=0);var n=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/n,e*t/n,i*t/n,1]}(t,r,e,i),this.__matrix4),this},t.prototype.rotate=function(t,r,e,i,o,a,s){var _=function(t,r,e,i,n,o){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,n=r,o=1):"number"==typeof i&&"number"==typeof n&&"number"==typeof o||(i=t,n=r,o=e,t=0,r=0,e=0),t==i&&r==n&&e==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(n-r)*(n-r)),s=0!=a?(n-r)/a:1,_=0!=a?(i-t)/a:0,u=(i-t)*_+(n-r)*s,m=o-e,p=Math.sqrt(u*u+m*m),l=0!=p?m/p:1,c=0!=p?u/p:0;return[[s,l*_,_*c,0,-_,s*l,s*c,0,0,-c,l,0,r*_-t*s,e*c-t*_*l-r*s*l,-t*_*c-r*s*c-e*l,1],[s,-_,0,0,l*_,l*s,-c,0,_*c,s*c,l,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,i,o,a,s);return this.__matrix4=n(n(n(_[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)),_[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,i,o,a){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===a&&(a=0),this.__matrix4=n(function(t,r,e,i,n,o){return void 0===i&&(i=0),void 0===n&&(n=0),void 0===o&&(o=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,n-n*r,o-o*e,1]}(t,r,e,i,o,a),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?n(this.__matrix4,t):n(t,this.__matrix4),this},t.prototype.use=function(t,r,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),n(this.__matrix4,[t,r,e,i])},t.prototype.value=function(){return this.__matrix4},t}(),a=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 n=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(n,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,n,o,a){t.vertexAttribPointer(r,e,i,a,n,o),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),s=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 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,n,o){t.texImage2D(r,e,i,i,n,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,n,o,a,s,_){for(var u,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],p=0;p<m.length;p++)o[p]&&(u=m[p],t.texImage2D(u,e,i,a,s,0,i,n,null),t.bindTexture(r,_),t.texImage2D(u,e,i,i,n,o[p]));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 s(r,e)),_[i]}var m=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},p=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=m(t,t.VERTEX_SHADER,r),n=m(t,t.FRAGMENT_SHADER,e),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,n),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}(),l="attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n\r\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\r\n temp.z = -1.0 * temp.z;\r\n\r\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\r\n float dist = 4.0;\r\n\r\n // 使用投影直接计算\r\n // 为保证纹理和相对位置正确\r\n // x、y、z的改变满足线性变换\r\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));\r\n}",c="attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_color = a_color;\r\n}",h="attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec2 a_textcoord;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_textcoord = a_textcoord;\r\n}",g="attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_normal;\r\nvarying vec3 v_normal;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_normal = normalize(vec3(a_normal));\r\n}",f="precision mediump float;\r\n\r\nuniform vec4 u_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = u_color;\r\n}",v="precision mediump float;\r\n\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_color;\r\n}",d="precision mediump float;\r\n\r\nuniform sampler2D u_sampler;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = texture2D(u_sampler, v_textcoord);\r\n}",y="precision mediump float;\r\n\r\nvarying vec3 v_normal;\r\nuniform samplerCube u_texture;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\r\n}",E={};function b(t,r,e,i,n){var o=function(t,r,e){var i,n,o=t+(e.material.color?"1":"0")+(e.material.colors?"1":"0")+(e.material.image?"1":"0")+(e.material.cube?"1":"0");if(E[o])return E[o].use();var a=(i={},i[t+"1000"]=l,i[t+"0100"]=c,i[t+"0010"]=h,i[t+"0001"]=g,i)[o].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"),s=(n={},n[t+"1000"]=f,n[t+"0100"]=v,n[t+"0010"]=d,n[t+"0001"]=y,n)[o],_=new p(r).compile(a,s).use();return E[o]=_,_}(t,r,e);if(new a(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(o.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),r.uniformMatrix4fv(r.getUniformLocation(o.program,"u_matrix_world"),!1,n.matrix),r.uniformMatrix4fv(r.getUniformLocation(o.program,"u_matrix_proporion"),!1,n.proporion),r.uniformMatrix4fv(r.getUniformLocation(o.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new a(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(o.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,0),"color"in e.material&&r.uniform4f(r.getUniformLocation(o.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha),"colors"in e.material)new a(r).use().write(e.material.colors.array).divide(r.getAttribLocation(o.program,"a_color"),e.material.colors.itemSize,e.material.colors.itemSize,0);else if("cube"in e.material){var s=e.material.cube.right.image.value.width;r.uniform1i(r.getUniformLocation(o.program,"u_texture"),0),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],s,s)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(o.program,"u_sampler"),0),new a(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(o.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),u(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new a(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 x=!1,w=function(){function t(t,r){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 n=[],o=0;o<i;o++)n[o]=t;return function(){for(var o=0;o<i;o++){if(n[o]+e<r){n[o]=+(n[o]+e).toFixed(7);break}o<i-1&&(n[o]=t)}return n}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new o([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=e(t,10),r&&(this.__regionPainter=e(r,10,{}));var i=this.painter.canvas.width/this.painter.canvas.height,n=1,a=1;i>1?n=1/i:a=i;var s=Math.min(n,a);this.__proporion=[n,0,0,0,0,a,0,0,0,0,s,0,0,0,0,1]}return t.prototype.matrix=function(t){return new o(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?this.__regionPainter&&(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},t.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(x=!0);var e={matrix:t.matrix.value()},n={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var o=0;o<t.mesh.length;o++)r?this.__regionPainter&&(b("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]}}},e,n),this.__getColor=i(this.__regionPainter)):b("region"+this.__unique,this.painter,t.mesh[o],e,n)},t.prototype.render=function(t){"matrix"in t||(t.matrix=new o),"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)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(t),this.draw(t)},t.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=r(r([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},t.prototype.getRegion=function(t,r){var e=this;return x&&this.review(!0),x=!1,new Promise((function(i,n){var o=e.__getColor(t,r);for(var a in e.__regionList){var s=e.__regionList[a];if("rgba("+255*s[0]+","+255*s[1]+","+255*s[2]+","+255*s[3]+")"==o){i(a);break}}i("")}))},t}();return function(r){function e(t,e){if(void 0===e&&(e={}),!t)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");e=function(t,r){for(var e in t)r[e]=t[e];return r}(e,{region:!0});var i,n,o=t.clientWidth,a=t.clientHeight,s=t;s._vislite_canvas_?(i=s._vislite_canvas_[0],n=s._vislite_canvas_[1]):(e.region&&(n=document.createElement("canvas"),t.appendChild(n),n.style.position="absolute",n.style.zIndex="-1",n.style.opacity="0"),i=document.createElement("canvas"),t.appendChild(i),s._vislite_canvas_=[i,n],t.setAttribute("vislite","WebGL"));for(var _=0,u=[i,n];_<u.length;_++){var m=u[_];m&&(m.style.width=o+"px",m.setAttribute("width",o+""),m.style.height=a+"px",m.setAttribute("height",a+""))}return r.call(this,i,n)||this}return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,r),e}(w)},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite_WebGL=r();