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,198 +1,230 @@
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
+ import { V2 } from '../core/V2.js';
3
4
 
4
- function Circular ( o ) {
5
+ export class Circular extends Proto {
5
6
 
6
- Proto.call( this, o );
7
+ constructor( o = {} ) {
7
8
 
8
- //this.type = 'circular';
9
- this.autoWidth = false;
9
+ super( o )
10
10
 
11
- this.buttonColor = Tools.colors.button;
11
+ this.isCyclic = o.cyclic || false
12
+ this.model = o.stype || 0
13
+ if( o.mode !== undefined ) this.model = o.mode
12
14
 
13
- this.setTypeNumber( o );
15
+ this.autoWidth = false
16
+ this.minw = this.w
17
+ this.diam = o.diam || this.w
14
18
 
15
- this.radius = Math.floor((this.width-20)*0.5);
19
+ this.setTypeNumber( o )
16
20
 
17
- /*this.radius = o.radius || 15;
18
-
19
- this.width = (this.radius*2)+20;
21
+ this.twoPi = Tools.TwoPI
22
+ this.pi90 = Tools.pi90
20
23
 
21
- if(o.width !== undefined){
22
- this.width = o.width;
23
- this.radius = ~~ (this.width-20)*0.5;
24
- }
24
+ this.offset = new V2()
25
25
 
26
- if(o.size !== undefined){
27
- this.width = o.size;
28
- this.radius = ~~ (this.width-20)*0.5;
29
- }*/
26
+ this.h = o.h || this.w + 10
27
+ this.top = 0
30
28
 
31
- this.w = this.height = this.radius * 2;
32
- this.h = o.height || (this.height + 40);
29
+ this.c[0].style.width = this.w +'px'
33
30
 
34
- this.twoPi = Math.PI * 2;
31
+ if(this.c[1] !== undefined) {
35
32
 
36
- this.top = 0;
33
+ this.c[1].style.width = '100%'
34
+ this.c[1].style.justifyContent = 'center'
35
+ this.top = 10
36
+ this.h += 10
37
37
 
38
- this.c[0].style.width = this.width +'px';
38
+ }
39
39
 
40
- if(this.c[1] !== undefined) {
41
40
 
42
- this.c[1].style.width = this.width +'px';
43
- this.c[1].style.textAlign = 'center';
44
- this.top = 20;
45
41
 
46
- }
42
+ this.percent = 0
43
+ this.cmode = 0
44
+ let cc = this.colors
45
+
46
+ this.c[2] = this.dom( 'div', this.css.txt + 'justify-content:center; top:'+(this.h-20)+'px; width:100%; color:'+ cc.text )
47
+
48
+ // svg
49
+
50
+ this.c[3] = this.getCircular()
51
+
52
+ this.setSvg( this.c[3], 'stroke', cc.back, 0 )
53
+ this.setSvg( this.c[3], 'd', this.makePath(), 1 )
54
+ this.setSvg( this.c[3], 'stroke', cc.text, 1 )
47
55
 
48
- this.percent = 0;
56
+ this.setSvg( this.c[3], 'viewBox', '0 0 '+this.diam+' '+this.diam )
57
+ this.setCss( this.c[3], { width:this.diam, height:this.diam, left:0, top:this.top })
49
58
 
50
- this.c[2] = Tools.dom( 'div', Tools.css.txtnumber + 'text-align:center; top:'+(this.height+24)+'px; width:'+this.width+'px; color:'+ this.fontColor );
51
- this.c[3] = Tools.dom( 'circle', Tools.css.basic + 'left:10px; top:'+this.top+'px; width:'+this.w+'px; height:'+this.height+'px; pointer-events:auto; cursor:pointer;', { cx:this.radius, cy:this.radius, r:this.radius, fill:'rgba(0,0,0,0.3)' });
52
- this.c[4] = Tools.dom( 'path', Tools.css.basic + 'left:10px; top:'+this.top+'px; width:'+this.w+'px; height:'+this.height+'px;', { d:this.makePath(), fill:this.fontColor });
53
- this.c[5] = Tools.dom( 'circle', Tools.css.basic + 'left:10px; top:'+this.top+'px; width:'+this.w+'px; height:'+this.height+'px;', { cx:this.radius, cy:this.radius, r:this.radius*0.5, fill:this.buttonColor, 'stroke-width':1, stroke:Tools.colors.stroke });
59
+ this.init()
60
+ this.update()
54
61
 
55
- this.c[3].events = [ 'mouseover', 'mousedown', 'mouseout' ];
62
+ }
56
63
 
57
- this.init();
64
+ mode ( mode ) {
58
65
 
59
- this.update();
66
+ if( this.cmode === mode ) return false;
60
67
 
61
- };
68
+ let cc = this.colors
69
+ let color
62
70
 
63
- Circular.prototype = Object.create( Proto.prototype );
64
- Circular.prototype.constructor = Circular;
71
+ switch( mode ){
72
+ case 0: // base
65
73
 
66
- Circular.prototype.handleEvent = function( e ) {
74
+ this.s[2].color = cc.text;
75
+ this.setSvg( this.c[3], 'stroke', cc.back, 0);
76
+ color = this.model > 0 ? Tools.pack( Tools.lerpColor( Tools.unpack( Tools.ColorLuma( cc.text, -0.75) ), Tools.unpack( cc.text ), this.percent ) ) : cc.text;
77
+ this.setSvg( this.c[3], 'stroke', color, 1 );
78
+
79
+ break;
80
+ case 1: // down
67
81
 
68
- e.preventDefault();
82
+ this.s[2].color = cc.textOver;
83
+ this.setSvg( this.c[3], 'stroke', cc.backoff, 0);
84
+ color = this.model > 0 ? Tools.pack( Tools.lerpColor( Tools.unpack( Tools.ColorLuma( cc.text, -0.75) ), Tools.unpack( cc.text ), this.percent ) ) : cc.textOver
85
+ this.setSvg( this.c[3], 'stroke', color, 1 );
86
+
87
+ break;
88
+ }
69
89
 
70
- switch( e.type ) {
71
- case 'mouseover': this.over( e ); break;
72
- case 'mousedown': this.down( e ); break;
73
- case 'mouseout': this.out( e ); break;
90
+ this.cmode = mode;
91
+ return true;
74
92
 
75
- case 'mouseup': this.up( e ); break;
76
- case 'mousemove': this.move( e ); break;
77
93
  }
78
94
 
79
- };
95
+ reset () {
96
+
97
+ this.isDown = false;
98
+
99
+ }
80
100
 
81
- Circular.prototype.mode = function( mode ){
101
+ testZone ( e ) {
82
102
 
83
- switch(mode){
84
- case 0: // base
85
- this.s[2].color = this.fontColor;
86
- Tools.setSvg( this.c[3], 'fill','rgba(0,0,0,0.2)');
87
- Tools.setSvg( this.c[4], 'fill', this.fontColor );
88
- break;
89
- case 1: // over
90
- this.s[2].color = this.colorPlus;
91
- Tools.setSvg( this.c[3], 'fill','rgba(0,0,0,0.6)');
92
- Tools.setSvg( this.c[4], 'fill', this.colorPlus );
93
- break;
103
+ let l = this.local;
104
+ if( l.x === -1 && l.y === -1 ) return '';
105
+
106
+ if( l.y <= this.c[ 1 ].offsetHeight ) return 'title';
107
+ else if ( l.y > this.h - this.c[ 2 ].offsetHeight ) return 'text';
108
+ else return 'circular';
94
109
 
95
110
  }
96
- }
97
111
 
98
- Circular.prototype.over = function( e ){
112
+ // ----------------------
113
+ // EVENTS
114
+ // ----------------------
99
115
 
100
- this.isOver = true;
101
- this.mode(1);
116
+ mouseup ( e ) {
102
117
 
103
- };
118
+ this.isDown = false;
119
+ this.sendEnd();
120
+ return this.mode(0);
104
121
 
105
- Circular.prototype.out = function( e ){
122
+ }
106
123
 
107
- this.isOver = false;
108
- if(this.isDown) return;
109
- this.mode(0);
124
+ mousedown ( e ) {
110
125
 
111
- };
126
+ this.isDown = true;
127
+ this.old = this.value;
128
+ this.oldr = null;
129
+ this.mousemove( e );
130
+ return this.mode(1);
112
131
 
113
- Circular.prototype.up = function( e ){
132
+ }
114
133
 
115
- this.isDown = false;
116
- document.removeEventListener( 'mouseup', this, false );
117
- document.removeEventListener( 'mousemove', this, false );
134
+ mousemove ( e ) {
118
135
 
119
- if(this.isOver) this.mode(1);
120
- else this.mode(0);
136
+ if( !this.isDown ) return;
121
137
 
122
- this.sendEnd();
138
+ //console.log('over')
123
139
 
124
- };
140
+ let off = this.offset;
141
+ off.x = (this.w*0.5) - ( e.clientX - this.zone.x );
142
+ off.y = (this.diam*0.5) - ( e.clientY - this.zone.y - this.top );
125
143
 
126
- Circular.prototype.down = function( e ){
144
+ this.r = off.angle() - this.pi90;
145
+ this.r = (((this.r%this.twoPi)+this.twoPi)%this.twoPi);
127
146
 
128
- this.isDown = true;
129
- document.addEventListener( 'mouseup', this, false );
130
- document.addEventListener( 'mousemove', this, false );
147
+ if( this.oldr !== null ){
131
148
 
132
- this.rect = this.c[3].getBoundingClientRect();
133
- this.old = this.value;
134
- this.oldr = null;
135
- this.move( e );
149
+ let dif = this.r - this.oldr;
150
+ this.r = Math.abs(dif) > Math.PI ? this.oldr : this.r;
136
151
 
137
- };
152
+ if( dif > 6 ) this.r = 0;
153
+ if( dif < -6 ) this.r = this.twoPi;
138
154
 
139
- Circular.prototype.move = function( e ){
155
+ }
140
156
 
141
- if( !this.isDown ) return;
157
+ let steps = 1 / this.twoPi;
158
+ let value = this.r * steps;
142
159
 
143
- var x = this.radius - (e.clientX - this.rect.left);
144
- var y = this.radius - (e.clientY - this.rect.top);
160
+ let n = ( ( this.range * value ) + this.min ) - this.old;
145
161
 
146
- this.r = Math.atan2( y, x ) - (Math.PI * 0.5);
147
- this.r = (((this.r%this.twoPi)+this.twoPi)%this.twoPi);
162
+ if(n >= this.step || n <= this.step){
163
+ n = ~~ ( n / this.step );
164
+ this.value = this.numValue( this.old + ( n * this.step ) );
165
+ this.update( true );
166
+ this.old = this.value;
167
+ this.oldr = this.r;
168
+ }
148
169
 
149
- if( this.oldr !== null ){
170
+ }
171
+
172
+ wheel ( e ) {
150
173
 
151
- var dif = this.r - this.oldr;
152
- this.r = Math.abs(dif) > Math.PI ? this.oldr : this.r;
174
+ let name = this.testZone( e );
153
175
 
154
- if(dif > 6) this.r = 0;
155
- if(dif < -6) this.r = this.twoPi;
176
+ if( name === 'circular' ) {
177
+
178
+ let v = this.value - this.step * e.delta;
179
+
180
+ if ( v > this.max ) {
181
+ v = this.isCyclic ? this.min : this.max;
182
+ } else if ( v < this.min ) {
183
+ v = this.isCyclic ? this.max : this.min;
184
+ }
185
+
186
+ this.setValue( v );
187
+ this.old = v;
188
+ this.update( true );
189
+
190
+ return true;
191
+
192
+ }
193
+ return false;
156
194
 
157
195
  }
158
196
 
159
- var steps = 1 / this.twoPi;
160
- var value = this.r * steps;
197
+ // ----------------------
161
198
 
162
- var n = ( ( this.range * value ) + this.min ) - this.old;
199
+ makePath () {
200
+
201
+ let r = 40;
202
+ let d = 24;
203
+ let a = this.percent * this.twoPi - 0.001;
204
+ let x2 = (r + r * Math.sin(a)) + d;
205
+ let y2 = (r - r * Math.cos(a)) + d;
206
+ let big = a > Math.PI ? 1 : 0;
207
+ return "M " + (r+d) + "," + d + " A " + r + "," + r + " 0 " + big + " 1 " + x2 + "," + y2;
163
208
 
164
- if(n >= this.step || n <= this.step){
165
- n = ~~ ( n / this.step );
166
- this.value = this.numValue( this.old + ( n * this.step ) );
167
- this.update( true );
168
- this.old = this.value;
169
- this.oldr = this.r;
170
209
  }
171
210
 
172
- };
211
+ update ( up ) {
173
212
 
174
- Circular.prototype.makePath = function(){
213
+ this.c[2].textContent = this.value;
214
+ this.percent = ( this.value - this.min ) / this.range;
175
215
 
176
- var r = this.radius;
177
- //var start = 0;
178
- var end = this.percent * this.twoPi - 0.001;
179
- //var x1 = r + r * Math.sin(start);
180
- //var y1 = r - r * Math.cos(start);
181
- var x2 = r + r * Math.sin(end);
182
- var y2 = r - r * Math.cos(end);
183
- //var big = end - start > Math.PI ? 1 : 0;
184
- var big = end > Math.PI ? 1 : 0;
185
- return "M " + r + "," + r + " L " + r + "," + 0 + " A " + r + "," + r + " 0 " + big + " 1 " + x2 + "," + y2 + " Z";
216
+ this.setSvg( this.c[3], 'd', this.makePath(), 1 );
186
217
 
187
- };
218
+ if ( this.model > 0 ) {
188
219
 
189
- Circular.prototype.update = function( up ){
220
+ let cc = this.colors
221
+ let color = Tools.pack( Tools.lerpColor( Tools.unpack( Tools.ColorLuma( cc.text, -0.75) ), Tools.unpack( cc.text ), this.percent ) );
222
+ this.setSvg( this.c[3], 'stroke', color, 1 );
223
+
224
+ }
190
225
 
191
- this.c[2].textContent = this.value;
192
- this.percent = ( this.value - this.min ) / this.range;
193
- Tools.setSvg( this.c[4], 'd', this.makePath() );
194
- if( up ) this.send();
195
-
196
- };
226
+ if( up ) this.send();
227
+
228
+ }
197
229
 
198
- export { Circular };
230
+ }