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