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,250 +1,417 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
1
+ import { Proto } from '../core/Proto.js';
2
+ import { Tools } from '../core/Tools.js';
3
3
 
4
- function Numeric( o ){
4
+ export class Numeric extends Proto {
5
5
 
6
- Proto.call( this, o );
6
+ constructor( o = {} ) {
7
7
 
8
- this.type = 'number';
8
+ super( o );
9
9
 
10
- this.setTypeNumber( o );
10
+ this.setTypeNumber( o );
11
11
 
12
- this.allway = o.allway || false;
13
- this.isDrag = o.drag === undefined ? true : o.drag;
12
+ this.allway = o.allway || false;
14
13
 
15
- this.value = [0];
16
- this.toRad = 1;
17
- this.isNumber = true;
18
- this.isAngle = false;
19
- this.isVector = false;
14
+ this.isDown = false;
20
15
 
21
- this.isSelect = false;
16
+ this.value = [0];
17
+ this.multy = 1;
18
+ this.invmulty = 1;
19
+ this.isSingle = true;
20
+ this.isAngle = false;
21
+ this.isVector = false;
22
22
 
23
- if( o.value !== undefined ){
24
- if(!isNaN(o.value)){ this.value = [o.value];}
25
- else if(o.value instanceof Array ){ this.value = o.value; this.isNumber=false;}
26
- else if(o.value instanceof Object ){
27
- this.value = [];
28
- if(o.value.x) this.value[0] = o.value.x;
29
- if(o.value.y) this.value[1] = o.value.y;
30
- if(o.value.z) this.value[2] = o.value.z;
31
- if(o.value.w) this.value[3] = o.value.w;
32
- this.isVector = true;
23
+ if( o.isAngle ){
24
+ this.isAngle = true;
25
+ this.multy = Tools.torad;
26
+ this.invmulty = Tools.todeg;
33
27
  }
34
- }
35
28
 
36
- this.length = this.value.length;
29
+ this.isDrag = o.drag || false;
30
+
31
+ if( o.value !== undefined ){
32
+ if(!isNaN(o.value)){
33
+ this.value = [o.value];
34
+ } else if( o.value instanceof Array ){
35
+ this.value = o.value;
36
+ this.isSingle = false;
37
+ } else if( o.value instanceof Object ){
38
+ this.value = [];
39
+ if( o.value.x !== undefined ) this.value[0] = o.value.x;
40
+ if( o.value.y !== undefined ) this.value[1] = o.value.y;
41
+ if( o.value.z !== undefined ) this.value[2] = o.value.z;
42
+ if( o.value.w !== undefined ) this.value[3] = o.value.w;
43
+ this.isVector = true;
44
+ this.isSingle = false;
45
+ }
46
+ }
47
+
48
+ this.lng = this.value.length;
49
+ this.tmp = [];
50
+
51
+
52
+
53
+ this.current = -1;
54
+ this.prev = { x:0, y:0, d:0, v:0 };
55
+
56
+ let cc = this.colors
57
+
58
+ // bg
59
+ this.c[2] = this.dom( 'div', this.css.basic + ' background:' + cc.select + '; top:4px; width:0px; height:' + (this.h-8) + 'px;' );
60
+
61
+ this.cMode = [];
62
+
63
+ let i = this.lng;
64
+ while(i--){
65
+
66
+ if(this.isAngle) this.value[i] = (this.value[i] * 180 / Math.PI).toFixed( this.precision );
67
+ this.c[3+i] = this.dom( 'div', this.css.txtselect + ' height:'+(this.h-4)+'px; color:' + cc.text + '; background:' + cc.back + '; borderColor:' + cc.border+'; border-radius:'+this.radius+'px;');
68
+ if(o.center) this.c[2+i].style.textAlign = 'center';
69
+ this.c[3+i].textContent = this.value[i];
70
+ this.c[3+i].style.color = this.colors.text;
71
+ this.c[3+i].isNum = true;
72
+
73
+ this.cMode[i] = 0;
74
+
75
+ }
76
+
77
+ // selection
78
+ this.selectId = 3 + this.lng;
79
+ this.c[this.selectId] = this.dom( 'div', this.css.txtselect + 'position:absolute; top:4px; height:' + (this.h-8) + 'px; padding:0px 0px; width:0px; color:' + cc.textSelect + '; background:' + cc.select + '; border:none; border-radius:0px;');
80
+
81
+ // cursor
82
+ this.cursorId = 4 + this.lng;
83
+ this.c[ this.cursorId ] = this.dom( 'div', this.css.basic + 'top:4px; height:' + (this.h-8) + 'px; width:0px; background:'+cc.text+';' );
37
84
 
38
- if(o.isAngle){
39
- this.isAngle = true;
40
- this.toRad = Math.PI/180;
85
+ this.init();
41
86
  }
42
87
 
43
- //this.w = ((Tools.base.BW+5)/(this.length))-5;
44
- this.current = undefined;
45
-
46
- var i = this.length;
47
- while(i--){
48
- if(this.isAngle) this.value[i] = (this.value[i] * 180 / Math.PI).toFixed( this.precision );
49
- this.c[2+i] = Tools.dom( 'div', Tools.css.txtselect + 'letter-spacing:-1px; cursor:pointer; height:'+(this.h-4)+'px; line-height:'+(this.h-8)+'px;');
50
- this.c[2+i].name = i;
51
- if(this.isDrag) this.c[2+i].style.cursor = 'move';
52
- if(o.center) this.c[2+i].style.textAlign = 'center';
53
-
54
- this.c[2+i].textContent = this.value[i];
55
- this.c[2+i].style.color = this.fontColor;
56
- //this.c[2+i].contentEditable = true;
57
- this.c[2+i].events = [ 'keydown', 'keyup', 'mousedown', 'blur', 'focus' ]; //'click',
88
+ testZone ( e ) {
89
+
90
+ let l = this.local;
91
+ if( l.x === -1 && l.y === -1 ) return '';
92
+
93
+ let i = this.lng;
94
+ let t = this.tmp;
95
+
96
+
97
+ while( i-- ){
98
+ if( l.x>t[i][0] && l.x<t[i][2] ) return i;
99
+ }
100
+
101
+ return '';
58
102
 
59
103
  }
60
104
 
61
- this.init();
62
- }
105
+ /* mode: function ( n, name ) {
63
106
 
64
- Numeric.prototype = Object.create( Proto.prototype );
65
- Numeric.prototype.constructor = Numeric;
107
+ if( n === this.cMode[name] ) return false;
66
108
 
67
- Numeric.prototype.handleEvent = function( e ) {
109
+ //let m;
68
110
 
69
- //e.preventDefault();
70
- //e.stopPropagation();
111
+ /*switch(n){
71
112
 
72
- switch( e.type ) {
73
- //case 'click': this.click( e ); break;
74
- case 'mousedown': this.down( e ); break;
75
- case 'keydown': this.keydown( e ); break;
76
- case 'keyup': this.keyup( e ); break;
113
+ case 0: m = this.colors.border; break;
114
+ case 1: m = this.colors.borderOver; break;
115
+ case 2: m = this.colors.borderSelect; break;
77
116
 
78
- case 'blur': this.blur( e ); break;
79
- case 'focus': this.focus( e ); break;
117
+ }*/
80
118
 
81
- // document
82
- case 'mouseup': this.up( e ); break;
83
- case 'mousemove': this.move( e ); break;
119
+ /* this.reset();
120
+ //this.c[name+2].style.borderColor = m;
121
+ this.cMode[name] = n;
84
122
 
85
- }
123
+ return true;
86
124
 
87
- };
125
+ },*/
88
126
 
89
- Numeric.prototype.setValue = function( v, n ){
127
+ // ----------------------
128
+ // EVENTS
129
+ // ----------------------
90
130
 
91
- n = n || 0;
92
- this.value[n] = this.numValue( v );
93
- this.c[2+n].textContent = this.value[n];
131
+ mousedown ( e ) {
94
132
 
95
- };
133
+ let name = this.testZone( e );
96
134
 
97
- Numeric.prototype.keydown = function( e ){
135
+ if( !this.isDown ){
136
+ this.isDown = true;
137
+ if( name !== '' ){
138
+ this.current = name;
139
+ this.prev = { x:e.clientX, y:e.clientY, d:0, v: this.isSingle ? parseFloat(this.value) : parseFloat( this.value[ this.current ] ) };
140
+ this.setInput( this.c[ 3 + this.current ] );
141
+ }
142
+ return this.mousemove( e );
143
+ }
98
144
 
99
- e.stopPropagation();
145
+ return false;
146
+ /*
147
+
148
+ if( name === '' ) return false;
149
+
150
+
151
+ this.current = name;
152
+ this.isDown = true;
153
+
154
+ this.prev = { x:e.clientX, y:e.clientY, d:0, v: this.isSingle ? parseFloat(this.value) : parseFloat( this.value[ this.current ] ) };
155
+
156
+
157
+ return this.mode( 2, name );*/
100
158
 
101
- if( e.keyCode === 13 ){
102
- e.preventDefault();
103
- this.testValue( parseFloat(e.target.name) );
104
- this.validate();
105
- e.target.blur();
106
159
  }
107
160
 
108
- };
161
+ mouseup ( e ) {
109
162
 
110
- Numeric.prototype.keyup = function( e ){
111
-
112
- e.stopPropagation();
163
+ if( this.isDown ){
164
+
165
+ this.isDown = false;
166
+ //this.current = -1;
167
+ this.prev = { x:0, y:0, d:0, v:0 };
168
+
169
+ return this.mousemove( e );
170
+ }
171
+
172
+ return false;
173
+
174
+ /*let name = this.testZone( e );
175
+ this.isDown = false;
176
+
177
+ if( this.current !== -1 ){
178
+
179
+ //let tm = this.current;
180
+ let td = this.prev.d;
181
+
182
+ this.current = -1;
183
+ this.prev = { x:0, y:0, d:0, v:0 };
184
+
185
+ if( !td ){
186
+
187
+ this.setInput( this.c[ 3 + name ] );
188
+ return true;//this.mode( 2, name );
189
+
190
+ } else {
191
+ return this.reset();//this.mode( 0, tm );
192
+ }
193
+
194
+ }*/
113
195
 
114
- if( this.allway ){
115
- this.testValue( parseFloat(e.target.name) );
116
- this.validate();
117
196
  }
118
197
 
119
- };
198
+ mousemove ( e ) {
120
199
 
121
- Numeric.prototype.blur = function( e ){
200
+ let nup = false;
201
+ let x = 0;
122
202
 
123
- this.isSelect = false;
124
- e.target.style.borderColor = Tools.colors.border;
125
- e.target.contentEditable = false;
126
- //e.target.style.border = '1px solid rgba(255,255,255,0.1)';
127
- if(this.isDrag) e.target.style.cursor = 'move';
128
- else e.target.style.cursor = 'pointer';
203
+ let name = this.testZone( e );
129
204
 
130
- };
205
+ if( name === '' ) this.cursor();
206
+ else{
207
+ if(!this.isDrag) this.cursor('text');
208
+ else this.cursor( this.current !== -1 ? 'move' : 'pointer' );
209
+ }
131
210
 
132
- Numeric.prototype.focus = function( e ){
211
+
133
212
 
134
- this.isSelect = true;
135
- this.current = undefined;
136
- e.target.style.borderColor = Tools.colors.borderSelect;
137
-
138
- //e.target.style.border = '1px solid ' + UIL.BorderSelect;
139
- if(this.isDrag) e.target.style.cursor = 'auto';
213
+ if( this.isDrag ){
140
214
 
141
- };
215
+ if( this.current !== -1 ){
142
216
 
143
- Numeric.prototype.down = function( e ){
217
+ this.prev.d += ( e.clientX - this.prev.x ) - ( e.clientY - this.prev.y );
144
218
 
145
- if(this.isSelect) return;
219
+ let n = this.prev.v + ( this.prev.d * this.step);
146
220
 
147
- e.preventDefault();
221
+ this.value[ this.current ] = this.numValue(n);
222
+ this.c[ 3 + this.current ].textContent = this.value[this.current];
148
223
 
149
-
224
+ this.validate();
150
225
 
151
- //e.target.style.border = '1px solid rgba(255,255,255,0.2)';
152
- this.current = parseFloat(e.target.name);
226
+ this.prev.x = e.clientX;
227
+ this.prev.y = e.clientY;
153
228
 
154
- this.prev = { x:e.clientX, y:e.clientY, d:0, id:(this.current+2)};
155
- if( this.isNumber ) this.prev.v = parseFloat(this.value);
156
- else this.prev.v = parseFloat( this.value[this.current] );
229
+ nup = true;
230
+ }
157
231
 
232
+ } else {
158
233
 
234
+ if( this.isDown ) x = e.clientX - this.zone.x -3;
235
+ if( this.current !== -1 ) x -= this.tmp[this.current][0]
236
+ return this.upInput( x, this.isDown );
159
237
 
160
- document.addEventListener( 'mouseup', this, false );
161
- if(this.isDrag) document.addEventListener( 'mousemove', this, false );
238
+ }
239
+
240
+
241
+
242
+
243
+ return nup;
244
+
245
+ }
246
+
247
+ //keydown: function ( e ) { return true; },
248
+
249
+ // ----------------------
250
+
251
+ reset () {
252
+
253
+ let nup = false;
254
+ //this.isDown = false;
255
+
256
+ //this.current = 0;
162
257
 
163
- };
258
+ /* let i = this.lng;
259
+ while(i--){
260
+ if(this.cMode[i]!==0){
261
+ this.cMode[i] = 0;
262
+ //this.c[2+i].style.borderColor = this.colors.border;
263
+ nup = true;
264
+ }
265
+ }*/
164
266
 
165
- ////
267
+ return nup;
166
268
 
167
- Numeric.prototype.up = function( e ){
269
+ }
270
+
271
+
272
+ setValue ( v ) {
168
273
 
169
- e.preventDefault();
274
+ if( this.isVector ){
170
275
 
171
- document.removeEventListener( 'mouseup', this, false );
172
- if(this.isDrag) document.removeEventListener( 'mousemove', this, false );
276
+ if( v.x !== undefined ) this.value[0] = v.x;
277
+ if( v.y !== undefined ) this.value[1] = v.y;
278
+ if( v.z !== undefined ) this.value[2] = v.z;
279
+ if( v.w !== undefined ) this.value[3] = v.w;
173
280
 
174
- if(this.current !== undefined){
281
+ } else {
175
282
 
176
- if( this.current === parseFloat(e.target.name) ){
177
- e.target.contentEditable = true;
178
- e.target.focus();
283
+ if( this.isSingle ) this.value = [v]
284
+ else this.value = v
285
+
179
286
  }
180
287
 
181
- // else e.target.style.borderColor = UIL.BorderSelect;;//this.c[2+this.current].style.border = '1px solid rgba(255,255,255,0.1)';
288
+ this.update();
289
+
290
+ }
291
+
292
+ sameStr ( str ){
182
293
 
294
+ let i = this.value.length;
295
+ while(i--) this.c[ 3 + i ].textContent = str;
183
296
 
184
- //this.c[2+this.current].style.cursor = 'move';
185
297
  }
186
298
 
187
-
299
+ update ( up ) {
188
300
 
189
- };
301
+ let i = this.value.length;
190
302
 
191
- Numeric.prototype.move = function( e ){
303
+ while(i--){
304
+ this.value[i] = this.numValue( this.value[i] * this.invmulty );
305
+ this.c[ 3 + i ].textContent = this.value[i];
306
+ }
192
307
 
193
- e.preventDefault();
308
+ if( up ) this.send();
194
309
 
195
- if( this.current === undefined ) return;
310
+ }
196
311
 
197
- this.prev.d += ( e.clientX - this.prev.x ) - ( e.clientY - this.prev.y );
198
- var n = this.prev.v + ( this.prev.d * this.step);
312
+ send ( v ) {
199
313
 
200
- this.value[this.current] = this.numValue(n);
201
- //this.c[2+this.current].value = this.value[this.current];
314
+ v = v || this.value;
202
315
 
203
- this.c[2+this.current].textContent = this.value[this.current];
316
+ this.isSend = true;
204
317
 
205
- this.validate();
318
+ if( this.objectLink !== null ){
206
319
 
207
- this.prev.x = e.clientX;
208
- this.prev.y = e.clientY;
320
+ if( this.isVector ){
209
321
 
210
- };
322
+ this.objectLink[ this.val ].fromArray( v );
211
323
 
212
- /////
324
+ /*this.objectLink[ this.val ].x = v[0];
325
+ this.objectLink[ this.val ].y = v[1];
326
+ this.objectLink[ this.val ].z = v[2];
327
+ if( v[3] ) this.objectLink[ this.val ].w = v[3];*/
213
328
 
214
- Numeric.prototype.testValue = function( n ){
329
+ } else {
330
+ this.objectLink[ this.val ] = v;
331
+ }
332
+
333
+ }
334
+
335
+ if( this.callback ) this.callback( v, this.val );
336
+
337
+ this.isSend = false;
215
338
 
216
- if(!isNaN( this.c[2+n].textContent )){
217
- var nx = this.numValue( this.c[2+n].textContent );
218
- this.c[2+n].textContent = nx;
219
- this.value[n] = nx;
220
- } else { // not number
221
- this.c[2+n].textContent = this.value[n];
222
339
  }
223
340
 
224
- };
225
341
 
226
- Numeric.prototype.validate = function(){
342
+ // ----------------------
343
+ // INPUT
344
+ // ----------------------
345
+
346
+ select ( c, e, w, t ) {
227
347
 
228
- var ar = [];
229
- var i = this.length;
230
- while(i--) ar[i] = this.value[i]*this.toRad;
348
+ let s = this.s;
349
+ let d = this.current !== -1 ? this.tmp[this.current][0] + 5 : 0;
350
+ s[this.cursorId].width = '1px';
351
+ s[this.cursorId].left = ( d + c ) + 'px';
352
+ //s[2].left = ( d + e ) + 'px';
353
+ //s[2].width = w + 'px';
231
354
 
232
- if( this.isNumber ) this.send( ar[0] );
233
- else this.send( ar );
355
+ s[this.selectId].left = ( d + e ) + 'px';
356
+ s[this.selectId].width = w + 'px';
357
+ this.c[this.selectId].innerHTML = t
358
+
359
+ }
234
360
 
235
- };
361
+ unselect () {
236
362
 
237
- Numeric.prototype.rSize = function(){
363
+ let s = this.s;
364
+ if(!s) return;
365
+ this.c[this.selectId].innerHTML = ''
366
+ s[this.selectId].width = 0 + 'px';
367
+ s[this.cursorId].width = 0 + 'px';
238
368
 
239
- Proto.prototype.rSize.call( this );
240
- this.w = ~~( ( this.sb + 5 ) / this.length )-5;
241
- var s = this.s;
242
- var i = this.length;
243
- while(i--){
244
- s[2+i].left = (~~( this.sa + ( this.w * i )+( 5 * i ))) + 'px';
245
- s[2+i].width = this.w + 'px';
246
369
  }
247
370
 
248
- };
371
+ validate ( force ) {
372
+
373
+ let ar = [];
374
+ let i = this.lng;
375
+
376
+ if( this.allway ) force = true;
377
+
378
+ while(i--){
379
+ if(!isNaN( this.c[ 3 + i ].textContent )){
380
+ let nx = this.numValue( this.c[ 3 + i ].textContent );
381
+ this.c[ 3 + i ].textContent = nx;
382
+ this.value[i] = nx;
383
+ } else { // not number
384
+ this.c[ 3 + i ].textContent = this.value[i];
385
+ }
386
+
387
+ ar[i] = this.value[i] * this.multy;
388
+ }
389
+
390
+ if( !force ) return;
391
+
392
+ if( this.isSingle ) this.send( ar[0] );
393
+ else this.send( ar );
394
+
395
+ }
396
+
397
+ // ----------------------
398
+ // REZISE
399
+ // ----------------------
400
+
401
+ rSize () {
402
+
403
+ super.rSize();
404
+
405
+ let w = Math.floor( ( this.sb + 5 ) / this.lng )-5;
406
+ let s = this.s;
407
+ let i = this.lng;
408
+ while(i--){
409
+ this.tmp[i] = [ Math.floor( this.sa + ( w * i )+( 5 * i )), w ];
410
+ this.tmp[i][2] = this.tmp[i][0] + this.tmp[i][1];
411
+ s[ 3 + i ].left = this.tmp[i][0] + 'px';
412
+ s[ 3 + i ].width = this.tmp[i][1] + 'px';
413
+ }
414
+
415
+ }
249
416
 
250
- export { Numeric };
417
+ }