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/List.js CHANGED
@@ -1,377 +1,789 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
1
+ import { Proto } from '../core/Proto.js';
2
+ import { Roots } from '../core/Roots.js';
3
3
 
4
- function List ( o ) {
4
+ export class List extends Proto {
5
5
 
6
- Proto.call( this, o );
6
+ constructor( o = {} ) {
7
7
 
8
- this.autoHeight = true;
9
- var align = o.align || 'center';
8
+ super( o );
10
9
 
11
- this.buttonColor = Tools.colors.button;
10
+ // images
11
+ this.path = o.path || '';
12
+ this.format = o.format || '';
13
+
12
14
 
13
- var fltop = Math.floor(this.h*0.5)-5;
15
+ this.isWithImage = this.path !== '' ? true:false;
16
+ this.preLoadComplete = false;
14
17
 
15
- this.c[2] = Tools.dom( 'div', Tools.css.basic + 'top:0; height:90px; cursor:s-resize; pointer-events:auto; display:none; overflow:hidden; border:1px solid '+Tools.colors.border+';' );
16
- this.c[3] = Tools.dom( 'div', Tools.css.txt + 'text-align:'+align+'; line-height:'+(this.h-4)+'px; border:1px solid '+Tools.colors.border+'; top:1px; pointer-events:auto; cursor:pointer; background:'+this.buttonColor+'; height:'+(this.h-2)+'px;' );
17
- this.c[4] = Tools.dom( 'path', Tools.css.basic + 'position:absolute; width:10px; height:10px; top:'+fltop+'px;', { d:'M 3 8 L 8 5 3 2 3 8 Z', fill:this.fontColor, stroke:'none'});
18
+ this.tmpImage = {};
19
+ this.tmpUrl = [];
18
20
 
21
+ //this.autoHeight = false;
19
22
 
23
+ let align = o.align || 'center';
20
24
 
21
- this.scroller = Tools.dom( 'div', Tools.css.basic + 'right:5px; width:10px; pointer-events:none; background:#666; display:none;');
25
+ // scroll size
26
+ let ss = o.scrollSize || 10
27
+ this.ss = ss+1
22
28
 
23
- this.c[2].name = 'list';
24
- this.c[3].name = 'title';
29
+ this.sMode = 0;
30
+ this.tMode = 0;
25
31
 
26
- //this.c[2].style.borderTop = this.h + 'px solid transparent';
27
- this.c[3].style.color = this.fontColor;
32
+ this.listOnly = o.listOnly || false;
33
+ this.staticTop = o.staticTop || false;
28
34
 
29
- this.c[2].events = [ 'mousedown', 'mousemove', 'mouseup', 'mousewheel', 'mouseout', 'mouseover' ];
30
- this.c[3].events = [ 'mousedown', 'mouseover' ,'mouseout'];
35
+ this.isSelectable = this.listOnly;
36
+ if( o.select !== undefined ) o.selectable = o.select
37
+ if( o.selectable !== undefined ) this.isSelectable = o.selectable
31
38
 
32
- this.list = o.list || [];
39
+ if( this.txt === '' ) this.p = 0;
33
40
 
34
- this.baseH = this.h;
35
41
 
36
- this.isShow = false;
37
- //this.maxItem = o.maxItem || 5;
38
- this.itemHeight = o.itemHeight || (this.h-3);
39
- //this.length = this.list.length;
42
+ let fltop = Math.floor(this.h*0.5)-5;
43
+ let cc = this.colors
40
44
 
41
- // force full list
42
- this.full = o.full || false;
43
45
 
44
- this.py = 0;
45
- this.w = this.sb;
46
- this.scroll = false;
47
- this.isDown = false;
48
46
 
49
- // list up or down
50
- this.side = o.side || 'down';
51
- this.holdTop = 0;
47
+ this.c[2] = this.dom( 'div', this.css.basic + 'top:0; display:none; border-radius:'+this.radius+'px;' );
48
+ this.c[3] = this.dom( 'div', this.css.item + 'position:absolute; text-align:'+align+'; line-height:'+(this.h-4)+'px; top:1px; background:'+cc.button+'; height:'+(this.h-2)+'px; border:1px solid '+cc.border+'; border-radius:'+this.radius+'px;' );
49
+ this.c[4] = this.dom( 'path', this.css.basic + 'position:absolute; width:10px; height:10px; top:'+fltop+'px;', { d:this.svgs.arrow, fill:cc.text, stroke:'none'});
52
50
 
53
- if( this.side === 'up' ){
51
+ this.scrollerBack = this.dom( 'div', this.css.basic + 'right:0px; width:'+ss+'px; background:'+cc.back+'; display:none;');
52
+ this.scroller = this.dom( 'div', this.css.basic + 'right:'+((ss-(ss*0.25))*0.5)+'px; width:'+(ss*0.25)+'px; background:'+cc.text+'; display:none; ');
54
53
 
55
- this.c[2].style.top = 'auto';
56
- this.c[3].style.top = 'auto';
57
- this.c[4].style.top = 'auto';
58
- //this.c[5].style.top = 'auto';
54
+ this.c[3].style.color = cc.text;
59
55
 
60
- this.c[2].style.bottom = this.h-2 + 'px';
61
- this.c[3].style.bottom = '1px';
62
- this.c[4].style.bottom = fltop + 'px';
63
- //this.c[5].style.bottom = '2px';
64
56
 
65
- } else {
66
- this.c[2].style.top = this.h-2 + 'px';
67
- //this.c[6].style.top = this.h + 'px';
57
+ this.list = []
58
+ this.refObject = null
59
+
60
+ if(o.list){
61
+ if( o.list instanceof Array ){
62
+ this.list = o.list
63
+ } else {
64
+ this.refObject = o.list
65
+ for( let g in this.refObject ) this.list.push(g)
66
+ }
67
+ }
68
+
69
+ this.items = [];
70
+
71
+ this.prevName = '';
72
+
73
+ this.baseH = this.h;
74
+
75
+ this.itemHeight = o.itemHeight || (this.h-3);
76
+
77
+ // force full list
78
+ this.full = o.full || false;
79
+
80
+ this.py = 0;
81
+ this.ww = this.sb;
82
+ this.scroll = false;
83
+ this.isDown = false;
84
+
85
+ this.current = null;
86
+
87
+ // list up or down
88
+ this.side = o.side || 'down';
89
+ this.up = this.side === 'down' ? 0 : 1;
90
+
91
+ if( this.up ){
92
+
93
+ this.c[2].style.top = 'auto';
94
+ this.c[3].style.top = 'auto';
95
+ this.c[4].style.top = 'auto';
96
+ //this.c[5].style.top = 'auto';
97
+
98
+ this.c[2].style.bottom = this.h-2 + 'px';
99
+ this.c[3].style.bottom = '1px';
100
+ this.c[4].style.bottom = fltop + 'px';
101
+
102
+ } else {
103
+ this.c[2].style.top = this.baseH + 'px';
104
+ }
105
+
106
+ this.listIn = this.dom( 'div', this.css.basic + 'left:0; top:0; width:100%; background:none;');
107
+ this.listIn.name = 'list';
108
+
109
+
110
+
111
+ this.topList = 0;
112
+
113
+ this.c[2].appendChild( this.listIn );
114
+ this.c[2].appendChild( this.scrollerBack );
115
+ this.c[2].appendChild( this.scroller );
116
+
117
+ if( o.value !== undefined ){
118
+ if(!isNaN(o.value)) this.value = this.list[ o.value ];
119
+ else this.value = o.value;
120
+ }else{
121
+ this.value = this.list[0];
122
+ }
123
+
124
+ this.isOpenOnStart = o.open || false;
125
+
126
+ if( this.listOnly ){
127
+ this.baseH = 5;
128
+ this.c[3].style.display = 'none';
129
+ this.c[4].style.display = 'none';
130
+ this.c[2].style.top = this.baseH+'px'
131
+ this.isOpenOnStart = true;
132
+ }
133
+
134
+
135
+ this.miniCanvas = o.miniCanvas || false
136
+ this.canvasBg = o.canvasBg || 'rgba(0,0,0,0)'
137
+ this.imageSize = o.imageSize || [20,20];
138
+
139
+ // dragout function
140
+ this.drag = o.drag || false
141
+ this.dragout = o.dragout || false
142
+ this.dragstart = o.dragstart || null
143
+ this.dragend = o.dragend || null
144
+
145
+
146
+
147
+ //this.c[0].style.background = '#FF0000'
148
+ if( this.isWithImage ) this.preloadImage();
149
+ // } else {
150
+ // populate list
151
+ this.setList( this.list );
152
+ this.init();
153
+ if( this.isOpenOnStart ) this.open( true );
154
+ // }
155
+
68
156
  }
69
157
 
70
- this.listIn = Tools.dom( 'div', Tools.css.basic + 'left:0; top:0; width:100%; background:rgba(0,0,0,0.2);');
71
- this.listIn.name = 'list';
158
+ /*send ( v ) {
72
159
 
73
-
74
- this.c[2].appendChild( this.listIn );
75
- this.c[2].appendChild( this.scroller );
160
+ super.send( v );
76
161
 
77
- // populate list
162
+ //Proto.prototype.send.call( this, v );
163
+ }*/
78
164
 
79
- this.setList( this.list, o.value );
165
+ // image list
80
166
 
81
-
82
-
167
+ preloadImage () {
83
168
 
84
- this.init();
169
+ this.preLoadComplete = false;
85
170
 
86
- }
171
+ this.tmpImage = {};
172
+ for( let i=0; i<this.list.length; i++ ) this.tmpUrl.push( this.list[i] );
173
+ this.loadOne();
174
+
175
+ }
87
176
 
88
- List.prototype = Object.create( Proto.prototype );
89
- List.prototype.constructor = List;
177
+ nextImg () {
90
178
 
91
- List.prototype.clearList = function() {
179
+ this.tmpUrl.shift();
180
+ if( this.tmpUrl.length === 0 ){
92
181
 
93
- while ( this.listIn.children.length ) this.listIn.removeChild( this.listIn.lastChild );
182
+ this.preLoadComplete = true;
94
183
 
95
- }
184
+ this.addImages();
185
+ /*this.setList( this.list );
186
+ this.init();
187
+ if( this.isOpenOnStart ) this.open();*/
96
188
 
97
- List.prototype.setList = function( list, value ) {
189
+ }
190
+ else this.loadOne();
98
191
 
99
- this.clearList();
192
+ }
100
193
 
101
- this.list = list;
102
- this.length = this.list.length;
194
+ loadOne(){
103
195
 
104
- this.maxItem = this.full ? this.length : 5;
105
- this.maxItem = this.length < this.maxItem ? this.length : this.maxItem;
196
+ let self = this
197
+ let name = this.tmpUrl[0];
198
+ let img = document.createElement('img');
199
+ img.style.cssText = 'position:absolute; width:'+self.imageSize[0]+'px; height:'+self.imageSize[1]+'px';
200
+ img.setAttribute('src', this.path + name + this.format );
106
201
 
107
- this.maxHeight = this.maxItem * (this.itemHeight+1) + 2;
202
+ img.addEventListener('load', function() {
108
203
 
109
- this.max = this.length * (this.itemHeight+1) + 2;
110
- this.ratio = this.maxHeight / this.max;
111
- this.sh = this.maxHeight * this.ratio;
112
- this.range = this.maxHeight - this.sh;
204
+ self.imageSize[2] = img.width;
205
+ self.imageSize[3] = img.height;
206
+ self.tmpImage[name] = img;
207
+ self.nextImg();
113
208
 
114
- this.c[2].style.height = this.maxHeight + 'px';
115
- this.scroller.style.height = this.sh + 'px';
209
+ });
116
210
 
117
- if( this.max > this.maxHeight ){
118
- this.w = this.sb - 20;
119
- this.scroll = true;
120
211
  }
121
212
 
122
- var item, n;//, l = this.sb;
123
- for( var i=0; i<this.length; i++ ){
124
- n = this.list[i];
125
- item = Tools.dom( 'div', Tools.css.item + 'width:'+this.w+'px; height:'+this.itemHeight+'px; line-height:'+(this.itemHeight-5)+'px;');
126
- item.textContent = n;
127
- item.style.color = this.fontColor;
128
- item.name = 'item';
129
- this.listIn.appendChild( item );
213
+ //
214
+
215
+ testZone ( e ) {
216
+
217
+ let l = this.local;
218
+ if( l.x === -1 && l.y === -1 ) return '';
219
+
220
+ if( this.up && this.isOpen ){
221
+ if( l.y > this.h - this.baseH ) return 'title';
222
+ else{
223
+ if( this.scroll && ( l.x > (this.sa+this.sb-this.ss)) ) return 'scroll';
224
+ if(l.x > this.sa) return this.testItems( l.y-this.baseH );
225
+ }
226
+
227
+ } else {
228
+ if( l.y < this.baseH+2 ) return 'title';
229
+ else{
230
+ if( this.isOpen ){
231
+ if( this.scroll && ( l.x > (this.sa+this.sb-this.ss)) ) return 'scroll';
232
+ if(l.x > this.sa) return this.testItems( l.y-this.baseH );
233
+ }
234
+ }
235
+
236
+ }
237
+
238
+ return '';
239
+
130
240
  }
131
241
 
132
- if( value !== undefined ){
133
- if(!isNaN(value)) this.value = this.list[ value ];
134
- else this.value = value;
135
- }else{
136
- this.value = this.list[0];
242
+ testItems ( y ) {
243
+
244
+ let name = '';
245
+
246
+ let i = this.items.length, item, a, b;
247
+ while(i--){
248
+ item = this.items[i];
249
+ a = item.posy + this.topList;
250
+ b = item.posy + this.itemHeight + 1 + this.topList;
251
+ if( y >= a && y <= b ){
252
+ name = 'item' + i;
253
+ this.modeItem(0)
254
+ this.current = item;
255
+ this.modeItem(1)
256
+ return name;
257
+ }
258
+
259
+ }
260
+
261
+ return name;
262
+
137
263
  }
138
-
139
- this.c[3].textContent = this.value;
140
264
 
141
- }
265
+ modeItem ( mode ) {
266
+
267
+ if( !this.current ) return
142
268
 
143
- List.prototype.handleEvent = function( e ) {
269
+ if( this.current.select && mode===0) mode = 2
270
+ let cc = this.colors
144
271
 
145
- e.preventDefault();
272
+ switch( mode ){
146
273
 
147
- var name = e.target.name || '';
148
- switch( e.type ) {
149
- case 'click': this.click(e); break;
150
- case 'mouseover': if(name === 'title') this.mode(1); else this.listover(e); break;
151
- case 'mousedown': if(name === 'title') { this.titleClick(e); } else this.listdown(e); break;
152
- case 'mouseup': if(name === 'title') this.mode(0); else this.listup(e); break;
153
- case 'mouseout': if(name === 'title') this.mode(0); else this.listout(e); break;
154
- case 'mousemove': this.listmove(e); break;
155
- case 'mousewheel': this.listwheel(e); break;
274
+ case 0: // base
275
+ this.current.style.background = cc.back
276
+ this.current.style.color = cc.text;
277
+ break;
278
+ case 1: // over
279
+ this.current.style.background = cc.over
280
+ this.current.style.color = cc.textOver;
281
+ break;
282
+ case 2: // edit / down
283
+ this.current.style.background = cc.select
284
+ this.current.style.color = cc.textSelect;
285
+ break;
286
+
287
+ }
156
288
  }
157
289
 
158
- }
290
+ unSelected() {
291
+
292
+ if( !this.current ) return
293
+ this.modeItem(0)
294
+ this.current = null
159
295
 
160
- List.prototype.mode = function( mode ){
296
+ }
161
297
 
162
- var s = this.s;
298
+ selected() {
163
299
 
164
- switch(mode){
165
- case 0: // base
166
- s[3].color = this.fontColor;
167
- s[3].background = this.buttonColor;
168
- break;
169
- case 1: // over
170
- s[3].color = '#FFF';
171
- s[3].background = Tools.colors.select;
172
- break;
173
- case 2: // edit / down
174
- s[3].color = this.fontColor;
175
- s[3].background = Tools.colors.down;
176
- break;
300
+ if( !this.current ) return
301
+ this.resetItems()
302
+ this.modeItem(2)
303
+ this.current.select = true
177
304
 
178
305
  }
179
- }
180
306
 
181
- // -----
307
+ resetItems() {
308
+
309
+ let i = this.items.length
310
+ while(i--){
311
+ this.items[i].select = false
312
+ this.items[i].style.background = this.colors.back;
313
+ this.items[i].style.color = this.colors.text;
314
+ }
182
315
 
183
- List.prototype.click = function( e ){
316
+ }
184
317
 
185
- var name = e.target.name;
186
- if( name !== 'title' && name !== 'list' ) this.listHide();
318
+ // ----------------------
319
+ // EVENTS
320
+ // ----------------------
187
321
 
188
- };
189
322
 
190
- List.prototype.titleClick = function( e ){
323
+ mouseup ( e ) {
324
+
325
+ this.isDown = false;
191
326
 
192
- if( this.isShow ) this.listHide();
193
- else {
194
- this.listShow();
195
- this.mode(2);
196
327
  }
197
328
 
198
- };
329
+ mousedown ( e ) {
330
+
331
+ let name = this.testZone( e );
199
332
 
200
- // ----- LIST
333
+ if( !name ) return false;
334
+
335
+ if( name === 'scroll' ){
336
+
337
+ this.isDown = true;
338
+ this.mousemove( e );
339
+
340
+ } else if( name === 'title' ){
341
+
342
+ this.modeTitle(2);
343
+ if( !this.listOnly ){
344
+ if( !this.isOpen ) this.open();
345
+ else this.close();
346
+ }
347
+ } else {
348
+ // is item
349
+ if( this.current ){
350
+
351
+ this.value = this.list[ this.current.id ]
352
+
353
+ if( this.isSelectable ) this.selected()
354
+ //this.value = this.refObject !== null ? this.refObject[this.list[this.current.id]] : this.list[this.current.id]
355
+ //this.value = this.current.textContent;
356
+ this.send( this.refObject !== null ? this.refObject[this.list[this.current.id]] : this.value );
357
+
358
+ if( !this.listOnly ) {
359
+ this.close();
360
+ this.setTopItem();
361
+ }
362
+ }
363
+
364
+ }
365
+
366
+ return true;
201
367
 
202
- List.prototype.listover = function( e ){
203
- var name = e.target.name;
204
- //console.log(name)
205
- if( name === 'item' ){
206
- e.target.style.background = Tools.colors.select;
207
- e.target.style.color = '#FFF';
208
368
  }
209
369
 
210
- };
211
-
212
- List.prototype.listdown = function( e ){
213
-
214
- var name = e.target.name;
215
- if( name !== 'list' && name !== undefined ){
216
- this.value = e.target.textContent;//name;
217
- this.c[3].textContent = this.value;
218
- this.send();
219
- // this.listHide();
220
- } else if ( name ==='list' && this.scroll ){
221
- this.isDown = true;
222
- this.listmove( e );
223
- this.listIn.style.background = 'rgba(0,0,0,0.6)';
224
- this.scroller.style.background = '#AAA';
370
+ mousemove ( e ) {
371
+
372
+ let nup = false;
373
+ let name = this.testZone( e );
374
+
375
+ if( !name ) return nup;
376
+
377
+ if( name === 'title' ){
378
+ this.unSelected();
379
+ this.modeTitle(1);
380
+ this.cursor('pointer');
381
+
382
+ } else if( name === 'scroll' ){
383
+
384
+ this.cursor('s-resize');
385
+ this.modeScroll(1);
386
+ if( this.isDown ){
387
+ this.modeScroll(2);
388
+ let top = this.zone.y+this.baseH-2;
389
+ this.update( ( e.clientY - top ) - ( this.sh*0.5 ) );
390
+ }
391
+ //if(this.isDown) this.listmove(e);
392
+ } else {
393
+
394
+ // is item
395
+ this.modeTitle(0);
396
+ this.modeScroll(0);
397
+ this.cursor('pointer');
398
+
399
+ }
400
+
401
+ if( name !== this.prevName ) nup = true;
402
+ this.prevName = name;
403
+
404
+ return nup;
405
+
225
406
  }
226
407
 
227
- };
408
+ wheel ( e ) {
228
409
 
229
- List.prototype.listmove = function( e ){
410
+ let name = this.testZone( e );
411
+ if( name === 'title' ) return false;
412
+ this.py += e.delta*10;
413
+ this.update(this.py);
414
+ return true;
230
415
 
231
- if( this.isDown ){
232
- var rect = this.c[2].getBoundingClientRect();
233
- this.update( ( e.clientY - rect.top ) - ( this.sh*0.5 ) );
234
416
  }
235
417
 
236
- };
237
418
 
238
- List.prototype.listup = function( e ){
239
419
 
240
- this.isDown = false;
241
- this.listIn.style.background = 'rgba(0,0,0,0.2)';
242
- this.scroller.style.background = '#666';
420
+ // ----------------------
243
421
 
244
- };
422
+ reset () {
245
423
 
246
- List.prototype.listout = function( e ){
424
+ this.prevName = '';
425
+ this.unSelected();
426
+ this.modeTitle(0);
427
+ this.modeScroll(0);
247
428
 
248
- var n = e.target.name;
249
- if( n === 'item' ){
250
- e.target.style.background ='rgba(0,0,0,0.2)';
251
- e.target.style.color = this.fontColor;
429
+ //console.log('this is reset')
430
+
252
431
  }
253
432
 
433
+ modeScroll ( mode ) {
434
+
435
+ if( mode === this.sMode ) return;
254
436
 
255
- if( this.isUI ) this.main.lockwheel = false;
256
- this.listup();
257
- //var name = e.relatedTarget.name;
258
- //if( name === undefined ) this.listHide();
437
+ let s = this.scroller.style;
438
+ let cc = this.colors
259
439
 
260
-
440
+ switch(mode){
441
+ case 0: // base
442
+ s.background = cc.text;
443
+ break;
444
+ case 1: // over
445
+ s.background = cc.select;
446
+ break;
447
+ case 2: // edit / down
448
+ s.background = cc.select;
449
+ break;
261
450
 
262
- };
451
+ }
452
+
453
+ this.sMode = mode;
454
+ }
263
455
 
264
- List.prototype.listwheel = function( e ){
456
+ modeTitle ( mode ) {
265
457
 
266
- if( !this.scroll ) return;
267
- if( this.isUI ) this.main.lockwheel = true;
268
- var delta = 0;
269
- if( e.wheelDeltaY ) delta = -e.wheelDeltaY*0.04;
270
- else if( e.wheelDelta ) delta = -e.wheelDelta*0.2;
271
- else if( e.detail ) delta = e.detail*4.0;
458
+ if( mode === this.tMode ) return;
272
459
 
273
- this.py += delta;
460
+ let s = this.s;
461
+ let cc = this.colors
462
+
463
+ switch(mode){
464
+ case 0: // base
465
+ s[3].color = cc.text;
466
+ s[3].background = cc.button;
467
+ break;
468
+ case 1: // over
469
+ s[3].color = cc.textOver;
470
+ s[3].background = cc.overoff;
471
+ break;
472
+ case 2: // edit / down
473
+ s[3].color = cc.textSelect;
474
+ s[3].background = cc.overoff;
475
+ break;
476
+
477
+ }
478
+
479
+ this.tMode = mode;
480
+
481
+ }
482
+
483
+ clearList () {
484
+
485
+ while ( this.listIn.children.length ) this.listIn.removeChild( this.listIn.lastChild );
486
+ this.items = [];
487
+
488
+ }
274
489
 
275
- this.update(this.py);
490
+ setList ( list ) {
276
491
 
277
- };
492
+ this.clearList();
278
493
 
494
+ this.list = list;
495
+ this.length = this.list.length;
279
496
 
280
- // ----- LIST
497
+ this.maxItem = this.full ? this.length : 5;
498
+ this.maxItem = this.length < this.maxItem ? this.length : this.maxItem;
281
499
 
282
- List.prototype.update = function( y ){
500
+ this.maxHeight = this.maxItem * (this.itemHeight+1) + 2;
283
501
 
284
- if( !this.scroll ) return;
502
+ this.max = this.length * (this.itemHeight+1) + 2;
503
+ this.ratio = this.maxHeight / this.max;
504
+ this.sh = this.maxHeight * this.ratio;
505
+ this.range = this.maxHeight - this.sh;
285
506
 
286
- y = y < 0 ? 0 : y;
287
- y = y > this.range ? this.range : y;
507
+ this.c[2].style.height = this.maxHeight + 'px';
508
+ this.scrollerBack.style.height = this.maxHeight + 'px';
509
+ this.scroller.style.height = this.sh + 'px';
288
510
 
289
- this.listIn.style.top = -Math.floor( y / this.ratio )+'px';
290
- this.scroller.style.top = Math.floor( y ) + 'px';
511
+ if( this.max > this.maxHeight ){
512
+ this.ww = this.sb - this.ss;
513
+ this.scroll = true;
514
+ }
291
515
 
292
- this.py = y;
516
+ if( this.miniCanvas ) {
293
517
 
294
- };
518
+ this.tmpCanvas = document.createElement('canvas')
519
+ this.tmpCanvas.width = this.imageSize[0]
520
+ this.tmpCanvas.height = this.imageSize[1]
521
+ this.tmpCtx = this.tmpCanvas.getContext("2d")
522
+ this.tmpCtx.fillStyle = this.canvasBg
523
+ this.tmpCtx.fillRect(0, 0, this.imageSize[0], this.imageSize[1])
295
524
 
296
- List.prototype.listShow = function(){
525
+ }
297
526
 
298
- document.addEventListener( 'click', this, false );
527
+ let item, n;//, l = this.sb;
528
+ for( let i=0; i<this.length; i++ ){
529
+
530
+ n = this.list[i];
531
+ item = this.dom( 'div', this.css.item + 'width:'+this.ww+'px; height:'+this.itemHeight+'px; line-height:'+(this.itemHeight-5)+'px; color:'+this.colors.text+'; background:'+this.colors.back+';' );
532
+ item.name = 'item'+i;
533
+ item.id = i;
534
+ item.select = false
535
+ item.posy = (this.itemHeight+1)*i;
536
+ this.listIn.appendChild( item );
537
+ this.items.push( item );
538
+
539
+ if( n === this.value ) this.current = item
540
+
541
+ //if( this.isWithImage ) item.appendChild( this.tmpImage[n] );
542
+ if( !this.isWithImage ) item.textContent = n;
543
+
544
+ if( this.miniCanvas ){
545
+
546
+ let c = new Image()
547
+ c.src = this.tmpCanvas.toDataURL()
548
+
549
+
550
+ /*let c = document.createElement('canvas')
551
+
552
+ c.width = this.imageSize[0]
553
+ c.height = this.imageSize[1]
554
+ let ctx = c.getContext("2d")
555
+ ctx.fillStyle = this.canvasBg
556
+ ctx.fillRect(0, 0, this.imageSize[0], this.imageSize[1])*/
557
+ c.style.cssText = 'position:relative; pointer-events:none; display:inline-block; float:left; margin-left:0px; margin-right:5px; top:2px'
558
+
559
+
560
+ //c.style.cssText = 'display:flex; align-content: flex-start; flex-wrap: wrap;'
561
+ //item.style.float = 'right'
562
+ item.appendChild( c )
563
+
564
+ this.tmpImage[n] = c
565
+
566
+ }
567
+
568
+ if(this.dragout){
569
+
570
+ item.img = this.tmpImage[n]
571
+
572
+ item.style.pointerEvents = 'auto';
573
+ item.draggable="true"
574
+
575
+ item.addEventListener('dragstart', this.dragstart || function(){ /*console.log('drag start')*/})
576
+ item.addEventListener('drag', this.drag || function(){ /*console.log('drag start')*/})
577
+ //item.addEventListener('dragover', this);
578
+ //item.addEventListener('dragenter', this);
579
+ item.addEventListener('dragleave', function(){ Roots.fakeUp(); } );
580
+ item.addEventListener('dragend', this.dragend || function(){ /*console.log('drag end')*/ }.bind(this) )
581
+ //item.addEventListener('drop', function(){console.log('drop')})
582
+
583
+ }
584
+
585
+ }
586
+
587
+ this.setTopItem();
588
+ if( this.isSelectable ) this.selected()
589
+
590
+ }
591
+
592
+ drawImage( name, image, x,y,w,h ){
593
+ this.tmpCtx.clearRect(0, 0, this.imageSize[0], this.imageSize[1]);
594
+ this.tmpCtx.drawImage(image, x, y, w, h, 0, 0, this.imageSize[0], this.imageSize[1])
595
+ this.tmpImage[name].src = this.tmpCanvas.toDataURL()
596
+
597
+
598
+ /*let c = this.tmpImage[name]
599
+ let ctx = c.getContext("2d")
600
+ ctx.drawImage(image, x, y, w, h, 0, 0, this.imageSize[0], this.imageSize[1])*/
601
+
602
+ }
603
+
604
+ addImages (){
605
+ let lng = this.list.length;
606
+ for( let i=0; i<lng; i++ ){
607
+ this.items[i].appendChild( this.tmpImage[this.list[i]] );
608
+ }
609
+ this.setTopItem();
610
+ }
611
+
612
+ setValue ( value ) {
613
+
614
+ if(!isNaN(value)) this.value = this.list[ value ];
615
+ else this.value = value;
616
+
617
+ this.setTopItem();
618
+
619
+ }
620
+
621
+ setTopItem (){
622
+
623
+ if(this.staticTop) return;
624
+
625
+ if( this.isWithImage ){
626
+
627
+ if( !this.preLoadComplete ) return;
628
+
629
+ if(!this.c[3].children.length){
630
+ this.canvas = document.createElement('canvas');
631
+ this.canvas.width = this.imageSize[0];
632
+ this.canvas.height = this.imageSize[1];
633
+ this.canvas.style.cssText = 'position:absolute; top:0px; left:0px;'
634
+ this.ctx = this.canvas.getContext("2d");
635
+ this.c[3].appendChild( this.canvas );
636
+ }
637
+
638
+ let img = this.tmpImage[ this.value ];
639
+ this.ctx.drawImage( this.tmpImage[ this.value ], 0, 0, this.imageSize[2], this.imageSize[3], 0,0, this.imageSize[0], this.imageSize[1] );
640
+
641
+ }
642
+ else this.c[3].textContent = this.value;
643
+
644
+
645
+ if( this.miniCanvas ){
646
+
647
+ if(!this.c[3].children.length){
648
+ this.canvas = document.createElement('canvas');
649
+ this.canvas.width = this.imageSize[0];
650
+ this.canvas.height = this.imageSize[1];
651
+ let h = ( this.h - this.imageSize[1] ) * 0.5
652
+ this.canvas.style.cssText = 'position:relative; pointer-events:none; display:inline-block; float:left; margin-left:0px; margin-right:5px; top:2px'
653
+ //this.canvas.style.cssText = 'position:absolute; top:'+h+'px; left:5px;'
654
+ this.ctx = this.canvas.getContext("2d");
655
+ this.c[3].style.textAlign = 'left'
656
+ this.c[3].appendChild( this.canvas );
657
+
658
+ }
659
+
660
+ this.ctx.drawImage( this.tmpImage[ this.value ], 0, 0 );
661
+
662
+
663
+ }
299
664
 
300
- this.update( 0 );
301
- this.isShow = true;
302
- this.h = this.maxHeight + this.baseH + 10;
303
- if( !this.scroll ){
304
- this.h = this.baseH + 10 + this.max;
305
- this.scroller.style.display = 'none';
306
- } else {
307
- this.scroller.style.display = 'block';
308
665
  }
309
- this.s[0].height = this.h + 'px';
310
- this.s[2].display = 'block';
311
- if( this.side === 'up' ) Tools.setSvg( this.c[4], 'd','M 5 2 L 2 7 8 7 5 2 Z');
312
- else Tools.setSvg( this.c[4], 'd','M 5 8 L 8 3 2 3 5 8 Z');
313
666
 
314
- this.rSizeContent();
315
667
 
316
- if( this.parentGroup !== null ) this.parentGroup.calc( this.h - this.baseH );
317
- else if( this.isUI ) this.main.calc( this.h - this.baseH );
668
+ // ----- LIST
669
+
670
+ update ( y ) {
318
671
 
319
- };
672
+ if( !this.scroll ) return;
320
673
 
321
- List.prototype.listHide = function(){
674
+ y = y < 0 ? 0 : y;
675
+ y = y > this.range ? this.range : y;
322
676
 
323
- document.removeEventListener( 'click', this, false );
677
+ this.topList = -Math.floor( y / this.ratio );
324
678
 
325
- if( this.parentGroup !== null ) this.parentGroup.calc( -(this.h-this.baseH) );
326
- else if( this.isUI ) this.main.calc(-(this.h-this.baseH));
679
+ this.listIn.style.top = this.topList+'px';
680
+ this.scroller.style.top = Math.floor( y ) + 'px';
327
681
 
328
- this.isShow = false;
329
- this.h = this.baseH;
330
- this.s[0].height = this.h + 'px';
331
- this.s[2].display = 'none';
332
- Tools.setSvg( this.c[4], 'd','M 3 8 L 8 5 3 2 3 8 Z');
333
-
334
- };
682
+ this.py = y;
335
683
 
336
- // -----
684
+ }
685
+
686
+ parentHeight ( t ) {
687
+
688
+ if ( this.group !== null ) this.group.calc( t );
689
+ else if ( this.isUI ) this.main.calc( t );
690
+
691
+ }
337
692
 
338
- List.prototype.text = function( txt ){
693
+ open ( first ) {
339
694
 
340
- this.c[3].textContent = txt;
695
+ super.open();
341
696
 
342
- };
697
+ this.update( 0 )
343
698
 
344
- List.prototype.rSizeContent = function(){
699
+ this.h = this.maxHeight + this.baseH + 5;
700
+ if( !this.scroll ){
701
+ this.topList = 0;
702
+ this.h = this.baseH + 5 + this.max;
703
+ this.scroller.style.display = 'none';
704
+ this.scrollerBack.style.display = 'none';
705
+ } else {
706
+ this.scroller.style.display = 'block';
707
+ this.scrollerBack.style.display = 'block';
708
+ }
709
+ this.s[0].height = this.h + 'px';
710
+ this.s[2].display = 'block';
345
711
 
346
- var i = this.length;
347
- while(i--) this.listIn.children[i].style.width = this.w + 'px';
712
+ if( this.up ){
713
+ this.zone.y -= this.h - (this.baseH-10);
714
+ this.setSvg( this.c[4], 'd', this.svgs.arrowUp );
715
+ } else {
716
+ this.setSvg( this.c[4], 'd', this.svgs.arrowDown );
717
+ }
348
718
 
349
- };
719
+ this.rSizeContent();
350
720
 
351
- List.prototype.rSize = function(){
721
+ let t = this.h - this.baseH;
352
722
 
353
- Proto.prototype.rSize.call( this );
723
+ this.zone.h = this.h;
354
724
 
355
- var s = this.s;
356
- var w = this.sb;
357
- var d = this.sa;
725
+ if(!first) this.parentHeight( t );
358
726
 
359
- s[2].width = w + 'px';
360
- s[2].left = d +'px';
727
+ }
728
+
729
+ close () {
730
+
731
+ super.close();
361
732
 
362
- s[3].width = w + 'px';
363
- s[3].left = d + 'px';
733
+ if( this.up ) this.zone.y += this.h - (this.baseH-10);
364
734
 
365
- s[4].left = d + w - 17 + 'px';
735
+ let t = this.h - this.baseH;
366
736
 
367
- //s[5].width = w + 'px';
368
- //s[5].left = d + 'px';
737
+ this.h = this.baseH;
738
+ this.s[0].height = this.h + 'px';
739
+ this.s[2].display = 'none';
740
+ this.setSvg( this.c[4], 'd', this.svgs.arrow );
369
741
 
370
- this.w = w;
371
- if( this.max > this.maxHeight ) this.w = w-20;
742
+ this.zone.h = this.h;
372
743
 
373
- if(this.isShow) this.rSizeContent();
744
+ this.parentHeight( -t );
745
+
746
+ }
374
747
 
375
- };
748
+ // -----
749
+
750
+ text ( txt ) {
751
+
752
+ this.c[3].textContent = txt;
753
+
754
+ }
755
+
756
+ rSizeContent () {
757
+
758
+ let i = this.length;
759
+ while(i--) this.listIn.children[i].style.width = this.ww + 'px';
760
+
761
+ }
762
+
763
+ rSize () {
764
+
765
+ super.rSize()
766
+
767
+ //Proto.prototype.rSize.call( this );
768
+
769
+ let s = this.s;
770
+ let w = this.sb;
771
+ let d = this.sa;
772
+
773
+ if(s[2]=== undefined) return;
774
+
775
+ s[2].width = w + 'px';
776
+ s[2].left = d +'px';
777
+
778
+ s[3].width = w + 'px';
779
+ s[3].left = d + 'px';
780
+
781
+ s[4].left = d + w - 17 + 'px';
782
+
783
+ this.ww = w;
784
+ if( this.max > this.maxHeight ) this.ww = w-this.ss;
785
+ if(this.isOpen) this.rSizeContent();
786
+
787
+ }
376
788
 
377
- export { List };
789
+ }