uil 1.0.1 → 4.0.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 (45) hide show
  1. package/README.md +57 -0
  2. package/build/uil.js +7040 -4199
  3. package/build/uil.min.js +6 -4
  4. package/build/uil.module.js +7200 -2761
  5. package/examples/js/BufferGeometryUtils.js +921 -0
  6. package/examples/js/SimplexNoise.js +324 -0
  7. package/examples/js/controls/OrbitControls.js +1215 -0
  8. package/examples/js/controls/OrbitControls_.js +1042 -0
  9. package/examples/js/libs/sea3d.min.js +373 -0
  10. package/examples/js/libs/three.min.js +6 -0
  11. package/examples/js/math.js +447 -0
  12. package/examples/js/objects/Landscape.js +778 -0
  13. package/examples/js/objects/Lensflare.js +372 -0
  14. package/examples/js/objects/SuperSky.js +297 -0
  15. package/examples/js/objects/Water.js +329 -0
  16. package/package.json +56 -54
  17. package/src/Uil.js +2 -17
  18. package/src/Uil_dev.js +15 -0
  19. package/src/core/Gui.js +601 -299
  20. package/src/core/Proto.js +490 -220
  21. package/src/core/Roots.js +864 -0
  22. package/src/core/Tools.js +591 -140
  23. package/src/core/V2.js +131 -0
  24. package/src/core/add.js +52 -57
  25. package/src/proto/Bool.js +117 -52
  26. package/src/proto/Button.js +286 -146
  27. package/src/proto/Circular.js +162 -130
  28. package/src/proto/Color.js +331 -289
  29. package/src/proto/Empty.js +15 -0
  30. package/src/proto/Fps.js +232 -159
  31. package/src/proto/Graph.js +310 -0
  32. package/src/proto/Grid.js +297 -0
  33. package/src/proto/Group.js +334 -160
  34. package/src/proto/Item.js +120 -0
  35. package/src/proto/Joystick.js +159 -185
  36. package/src/proto/Knob.js +210 -91
  37. package/src/proto/List.js +661 -249
  38. package/src/proto/Numeric.js +329 -162
  39. package/src/proto/Pad2D.js +268 -0
  40. package/src/proto/Rubric.js +0 -0
  41. package/src/proto/Select.js +178 -0
  42. package/src/proto/Selector.js +13 -0
  43. package/src/proto/Slide.js +191 -185
  44. package/src/proto/TextInput.js +149 -59
  45. package/src/proto/Title.js +40 -31
@@ -1,217 +1,357 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
1
+ import { Proto } from '../core/Proto.js';
3
2
 
4
- function Button ( o ) {
3
+ export class Button extends Proto {
5
4
 
6
- Proto.call( this, o );
5
+ constructor( o = {} ) {
7
6
 
8
- this.value = o.value || [this.txt];
7
+ super( o )
9
8
 
10
- this.buttonColor = o.bColor || Tools.colors.button;
9
+ this.value = o.value || '';
11
10
 
12
- this.isLoadButton = o.loader || false;
13
- this.isDragButton = o.drag || false;
14
- if(this.isDragButton ) this.isLoadButton = true;
15
- this.r = o.r || 3;
11
+ this.values = o.value || this.txt
12
+ if( o.values ) this.values = o.values
16
13
 
17
- this.lng = this.value.length;
14
+
15
+
16
+ this.onName = o.onName || '';
17
+
18
+ this.on = false;
19
+
20
+ this.customSize = o.forceWidth || -1;
21
+
22
+ if( typeof this.values === 'string' ) this.values = [ this.values ];
23
+
24
+ this.isDown = false
25
+ this.neverlock = true
26
+ this.isLoadButton = o.loader || false
27
+ this.isDragButton = o.drag || false
28
+ this.res = 0
29
+
30
+ if( this.isDragButton ) this.isLoadButton = true
31
+
32
+ this.lng = this.values.length;
33
+ this.tmp = []
34
+ this.stat = []
35
+
36
+ let sel, cc = this.colors;
37
+
38
+ for( let i = 0; i < this.lng; i++ ){
18
39
 
19
- for(var i = 0; i < this.lng; i++){
20
- this.c[i+2] = Tools.dom( 'div', Tools.css.txt + 'text-align:center; border:1px solid ' + Tools.colors.border+'; top:1px; pointer-events:auto; cursor:pointer; background:'+this.buttonColor+'; height:'+(this.h-2)+'px; border-radius:'+this.r+'px; line-height:'+(this.h-4)+'px;' );
21
- this.c[i+2].style.color = this.fontColor;
40
+ sel = false
41
+ if( this.values[i] === this.value && this.isSelectable ) sel = true
42
+
43
+ this.c[i+2] = this.dom( 'div', this.css.txt + this.css.button + 'top:1px; height:'+(this.h-2)+'px; border:'+cc.borderSize+'px solid '+cc.border+'; border-radius:'+this.radius+'px;' );
44
+ this.c[i+2].style.background = sel ? cc.select : cc.button
45
+ this.c[i+2].style.color = sel ? cc.textSelect : cc.text
46
+ this.c[i+2].innerHTML = this.values[i];
47
+ this.stat[i] = sel ? 3:1;
48
+
49
+ }
50
+
51
+ if( !o.value || !o.values ){
52
+ if( this.c[1] !== undefined ) this.c[1].textContent = '';
53
+ this.p = o.p !== undefined ? o.p : 0
54
+ } else {
55
+ if( !this.txt ) this.p = 0
56
+ }
57
+
58
+ //
59
+
60
+ if( this.isLoadButton ) this.initLoader();
61
+ if( this.isDragButton ){
62
+ this.lng ++;
63
+ this.initDrager();
64
+ }
65
+
66
+ if( this.onName !== '' ) this.values[0] = this.on;
67
+
68
+ this.init();
22
69
 
23
- this.c[i+2].events = [ 'click', 'mouseover', 'mousedown', 'mouseup', 'mouseout' ];
24
- this.c[i+2].innerHTML = this.value[i];//this.txt;
25
- this.c[i+2].name = i;
26
70
  }
27
71
 
28
- if( this.c[1] !== undefined ) this.c[1].textContent = '';
29
-
72
+ onOff ( ){
30
73
 
31
- if( this.isLoadButton ) this.initLoader();
32
- if( this.isDragButton ){
33
- this.lng ++;
34
- this.initDrager();
74
+ this.on = !this.on;
75
+ this.c[2].innerHTML = this.on ? this.onName : this.txt
76
+
35
77
  }
36
78
 
37
- this.init();
79
+ testZone ( e ) {
38
80
 
39
- };
81
+ let l = this.local;
82
+ if( l.x === -1 && l.y === -1 ) return -1
40
83
 
41
- Button.prototype = Object.create( Proto.prototype );
42
- Button.prototype.constructor = Button;
84
+ let i = this.lng
85
+ let t = this.tmp
86
+
87
+ while( i-- ){
88
+ if( l.x>t[i][0] && l.x<t[i][2] ) return i
89
+ }
43
90
 
44
- Button.prototype.handleEvent = function( e ) {
91
+ return -1
45
92
 
46
- e.preventDefault();
93
+ }
47
94
 
48
- switch( e.type ) {
49
- case 'click': this.click( e ); break;
50
- case 'mouseover': this.mode( 1, e ); break;
51
- case 'mousedown': this.mode( 2, e ); break;
52
- case 'mouseup': this.mode( 0, e ); break;
53
- case 'mouseout': this.mode( 0, e ); break;
54
- case 'change': this.fileSelect( e.target.files[0] ); break;
95
+ // ----------------------
96
+ // EVENTS
97
+ // ----------------------
98
+
99
+ mouseup ( e ) {
100
+
101
+ if( !this.isDown ) return false
102
+
103
+ this.isDown = false
104
+ if( this.res !== -1 ){
105
+ if( this.value === this.values[this.res] && this.unselectable ) this.value = ''
106
+ else this.value = this.values[this.res]
107
+ if( !this.isLoadButton ) this.send()
108
+ }
109
+
110
+ return this.mousemove( e )
55
111
 
56
- case 'dragover': this.dragover(); break;
57
- case 'dragend': this.dragend(); break;
58
- case 'dragleave': this.dragend(); break;
59
- case 'drop': this.drop( e ); break;
60
112
  }
61
113
 
62
- };
114
+ mousedown ( e ) {
115
+
116
+ if( this.isDown ) return false
117
+ this.isDown = true
118
+ return this.mousemove( e )
63
119
 
64
- Button.prototype.dragover = function(){
65
- this.s[4].borderColor = Tools.colors.select;
66
- this.s[4].color = Tools.colors.select;
67
- };
68
- Button.prototype.dragend = function(){
69
- this.s[4].borderColor = this.fontColor;
70
- this.s[4].color = this.fontColor;
71
- };
72
- Button.prototype.drop = function(e){
73
- this.dragend();
74
- this.fileSelect( e.dataTransfer.files[0] );
75
- };
120
+ }
76
121
 
77
- Button.prototype.mode = function( mode, e ){
122
+ mousemove ( e ) {
78
123
 
79
- var s = this.s;
80
- var i = e.target.name || 0;
81
- if(i==='loader') i = 0;
124
+ let up = false
125
+ this.res = this.testZone( e )
82
126
 
127
+ if( this.res !== -1 ){
128
+ this.cursor('pointer')
129
+ up = this.modes( this.isDown ? 3 : 2, this.res )
130
+ } else {
131
+ up = this.reset()
132
+ }
83
133
 
84
- switch( mode ){
85
- case 0: // base
86
- s[i+2].color = this.fontColor;
87
- s[i+2].background = this.buttonColor;
88
- break;
89
- case 1: // over
90
- s[i+2].color = '#FFF';
91
- s[i+2].background = Tools.colors.select;
92
- break;
93
- case 2: // edit / down
94
- s[i+2].color = this.fontColor;
95
- s[i+2].background = Tools.colors.down;
96
- break;
134
+ return up
97
135
 
98
136
  }
99
- }
100
137
 
101
- Button.prototype.initDrager = function(){
138
+ // ----------------------
102
139
 
103
- this.c[4] = Tools.dom( 'div', Tools.css.txt +' text-align:center; line-height:'+(this.h-8)+'px; border:1px dashed '+this.fontColor+'; top:2px; pointer-events:auto; cursor:default; height:'+(this.h-4)+'px; border-radius:'+this.r+'px;' );
104
- this.c[4].textContent = 'DRAG';
140
+ modes ( N = 1, id = -1 ) {
105
141
 
106
- this.c[2].events = [ ];
107
- this.c[4].events = [ 'dragover', 'dragend', 'dragleave', 'drop' ];
142
+ let i = this.lng, w, n, r = false
108
143
 
144
+ while( i-- ){
109
145
 
110
- };
146
+ n = N
147
+ w = this.isSelectable ? this.values[ i ] === this.value : false
148
+
149
+ if( i === id ){
150
+ if( w && n === 2 ) n = 3
151
+ } else {
152
+ n = 1
153
+ if( w ) n = 4
154
+ }
111
155
 
112
- Button.prototype.initLoader = function(){
156
+ //if( this.mode( n, i ) ) r = true
157
+ r = this.mode( n, i )
113
158
 
114
- this.c[3] = Tools.dom( 'input', Tools.css.basic +'border:1px solid '+Tools.colors.border+'; top:1px; opacity:0; pointer-events:auto; cursor:pointer; height:'+(this.h-2)+'px;' );
115
- this.c[3].name = 'loader';
116
- this.c[3].type = "file";
159
+ }
117
160
 
118
- this.c[2].events = [ ];
119
- this.c[3].events = [ 'change', 'mouseover', 'mousedown', 'mouseup', 'mouseout' ];
161
+ return r
120
162
 
121
- //this.hide = document.createElement('input');
163
+ }
122
164
 
123
- };
165
+ mode ( n, id ) {
124
166
 
125
- Button.prototype.fileSelect = function( file ){
167
+ let change = false;
168
+ let cc = this.colors, s = this.s
169
+ let i = id+2
126
170
 
127
- var dataUrl = [ 'png', 'jpg', 'mp4', 'webm', 'ogg' ];
128
- var dataBuf = [ 'sea', 'bvh', 'BVH', 'z' ];
171
+ if( this.stat[id] !== n ){
129
172
 
130
- //if( ! e.target.files ) return;
173
+ this.stat[id] = n;
174
+
175
+ switch( n ){
131
176
 
132
- //var file = e.target.files[0];
133
-
134
- //this.c[3].type = "null";
135
- // console.log( this.c[4] )
177
+ case 1: s[i].color = cc.text; s[i].background = cc.button; break;
178
+ case 2: s[i].color = cc.textOver; s[i].background = cc.overoff; break;
179
+ case 3: s[i].color = cc.textOver; s[i].background = cc.over; break;
180
+ case 4: s[i].color = cc.textSelect; s[i].background = cc.select; break;
136
181
 
137
- if( file === undefined ) return;
182
+ }
138
183
 
139
- var reader = new FileReader();
140
- var fname = file.name;
141
- var type = fname.substring(fname.lastIndexOf('.')+1, fname.length );
184
+ change = true;
142
185
 
143
- if( dataUrl.indexOf( type ) !== -1 ) reader.readAsDataURL( file );
144
- else if( dataBuf.indexOf( type ) !== -1 ) reader.readAsArrayBuffer( file );
145
- else reader.readAsText( file );
186
+ }
146
187
 
147
- // if( type === 'png' || type === 'jpg' || type === 'mp4' || type === 'webm' || type === 'ogg' ) reader.readAsDataURL( file );
148
- //else if( type === 'z' ) reader.readAsBinaryString( file );
149
- //else if( type === 'sea' || type === 'bvh' || type === 'BVH' || type === 'z') reader.readAsArrayBuffer( file );
150
- //else if( ) reader.readAsArrayBuffer( file );
151
- //else reader.readAsText( file );
188
+ return change
152
189
 
153
- reader.onload = function(e) {
154
-
155
- if( this.callback ) this.callback( e.target.result, fname, type );
156
- //this.c[3].type = "file";
157
- //this.send( e.target.result );
158
- }.bind(this);
190
+ }
159
191
 
160
- };
192
+ // ----------------------
161
193
 
162
- Button.prototype.click = function( e ){
194
+ reset () {
163
195
 
164
- var i = e.target.name || 0;
165
- var v = this.value[i];
196
+ this.res = -1
197
+ this.cursor()
198
+ return this.modes()
166
199
 
167
- this.send( v );
200
+ }
168
201
 
169
- };
202
+ // ----------------------
170
203
 
171
- Button.prototype.label = function( string, n ){
204
+ dragover ( e ) {
172
205
 
173
- n = n || 2;
174
- this.c[n].textContent = string;
206
+ e.preventDefault();
175
207
 
176
- };
208
+ this.s[4].borderColor = this.colors.select;
209
+ this.s[4].color = this.colors.select;
177
210
 
178
- Button.prototype.icon = function( string, y, n ){
211
+ }
179
212
 
180
- n = n || 2;
181
- this.s[n].padding = ( y || 0 ) +'px 0px';
182
- this.c[n].innerHTML = string;
213
+ dragend ( e ) {
183
214
 
184
- };
215
+ e.preventDefault();
185
216
 
186
- Button.prototype.rSize = function(){
217
+ this.s[4].borderColor = this.color.text;
218
+ this.s[4].color = this.color.text;
187
219
 
188
- Proto.prototype.rSize.call( this );
220
+ }
189
221
 
190
- var s = this.s;
191
- var w = this.sb;
192
- var d = this.sa;
222
+ drop ( e ) {
193
223
 
194
- var i = this.lng;
195
- var dc = 3;
196
- var size = Math.floor( ( w-(dc*(i-1)) ) / i );
224
+ e.preventDefault();
197
225
 
198
- while(i--){
199
-
200
- s[i+2].width = size + 'px';
201
- s[i+2].left = d + ( size * i ) + ( dc * i) + 'px';
226
+ this.dragend(e);
227
+ this.fileSelect( e.dataTransfer.files[0] );
202
228
 
203
229
  }
204
230
 
205
- if( this.isDragButton ){
206
- s[4].left = (d+size+dc) + 'px';
207
- s[4].width = size + 'px';
231
+ initDrager () {
232
+
233
+ this.c[4] = this.dom( 'div', this.css.txt +' text-align:center; line-height:'+(this.h-8)+'px; border:1px dashed '+this.color.text+'; top:2px; height:'+(this.h-4)+'px; border-radius:'+this.radius+'px; pointer-events:auto;' );// cursor:default;
234
+ this.c[4].textContent = 'DRAG';
235
+
236
+ this.c[4].addEventListener( 'dragover', function(e){ this.dragover(e); }.bind(this), false );
237
+ this.c[4].addEventListener( 'dragend', function(e){ this.dragend(e); }.bind(this), false );
238
+ this.c[4].addEventListener( 'dragleave', function(e){ this.dragend(e); }.bind(this), false );
239
+ this.c[4].addEventListener( 'drop', function(e){ this.drop(e); }.bind(this), false );
240
+
241
+ //this.c[2].events = [ ];
242
+ //this.c[4].events = [ 'dragover', 'dragend', 'dragleave', 'drop' ];
243
+
244
+
208
245
  }
209
246
 
210
- if( this.isLoadButton ){
211
- s[3].left = d + 'px';
212
- s[3].width = size + 'px';
247
+ initLoader () {
248
+
249
+ this.c[3] = this.dom( 'input', this.css.basic +'top:0px; opacity:0; height:'+(this.h)+'px; pointer-events:auto; cursor:pointer;' );//
250
+ this.c[3].name = 'loader';
251
+ this.c[3].type = "file";
252
+
253
+ this.c[3].addEventListener( 'change', function(e){ this.fileSelect( e.target.files[0] ); }.bind(this), false );
254
+ //this.c[3].addEventListener( 'mousedown', function(e){ }.bind(this), false );
255
+
256
+ //this.c[2].events = [ ];
257
+ //this.c[3].events = [ 'change', 'mouseover', 'mousedown', 'mouseup', 'mouseout' ];
258
+
259
+ //this.hide = document.createElement('input');
260
+
261
+ }
262
+
263
+ fileSelect ( file ) {
264
+
265
+ let dataUrl = [ 'png', 'jpg', 'mp4', 'webm', 'ogg' ];
266
+ let dataBuf = [ 'sea', 'z', 'hex', 'bvh', 'BVH', 'glb' ];
267
+
268
+ //if( ! e.target.files ) return;
269
+
270
+ //let file = e.target.files[0];
271
+
272
+ //this.c[3].type = "null";
273
+ // console.log( this.c[4] )
274
+
275
+ if( file === undefined ) return;
276
+
277
+ let reader = new FileReader();
278
+ let fname = file.name;
279
+ let type = fname.substring(fname.lastIndexOf('.')+1, fname.length );
280
+
281
+ if( dataUrl.indexOf( type ) !== -1 ) reader.readAsDataURL( file );
282
+ else if( dataBuf.indexOf( type ) !== -1 ) reader.readAsArrayBuffer( file );//reader.readAsArrayBuffer( file );
283
+ else reader.readAsText( file );
284
+
285
+ // if( type === 'png' || type === 'jpg' || type === 'mp4' || type === 'webm' || type === 'ogg' ) reader.readAsDataURL( file );
286
+ //else if( type === 'z' ) reader.readAsBinaryString( file );
287
+ //else if( type === 'sea' || type === 'bvh' || type === 'BVH' || type === 'z') reader.readAsArrayBuffer( file );
288
+ //else if( ) reader.readAsArrayBuffer( file );
289
+ //else reader.readAsText( file );
290
+
291
+ reader.onload = function (e) {
292
+
293
+ if( this.callback ) this.callback( e.target.result, fname, type );
294
+ //this.c[3].type = "file";
295
+ //this.send( e.target.result );
296
+ }.bind(this);
297
+
298
+ }
299
+
300
+ label ( string, n ) {
301
+
302
+ n = n || 2;
303
+ this.c[n].textContent = string;
304
+
305
+ }
306
+
307
+ icon ( string, y = 0, n = 2 ) {
308
+
309
+ //if(y) this.s[n].margin = ( y ) +'px 0px';
310
+ this.s[n].padding = ( y ) +'px 0px';
311
+ this.c[n].innerHTML = string;
312
+
313
+ return this
314
+
213
315
  }
214
316
 
215
- };
317
+ rSize () {
318
+
319
+ super.rSize();
320
+
321
+ let s = this.s;
322
+ let w = this.sb;
323
+ let d = this.sa;
324
+
325
+ let i = this.lng;
326
+ let dc = 3;
327
+ let size = Math.floor( ( w-(dc*(i-1)) ) / i );
328
+
329
+ if( this.customSize !== -1 ){
330
+ size = this.customSize
331
+ // d = (this.s-size)*0.5
332
+
333
+ }
334
+
335
+ while( i-- ){
336
+
337
+ this.tmp[i] = [ Math.floor( d + ( size * i ) + ( dc * i )), size ];
338
+ this.tmp[i][2] = this.tmp[i][0] + this.tmp[i][1];
339
+
340
+ s[i+2].left = this.tmp[i][0] + 'px';
341
+ s[i+2].width = this.tmp[i][1] + 'px';
342
+
343
+ }
344
+
345
+ if( this.isDragButton ){
346
+ s[4].left = (d+size+dc) + 'px';
347
+ s[4].width = size + 'px';
348
+ }
349
+
350
+ if( this.isLoadButton ){
351
+ s[3].left = d + 'px';
352
+ s[3].width = size + 'px';
353
+ }
354
+
355
+ }
216
356
 
217
- export { Button };
357
+ }