uil 1.0.0 → 4.0.2

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.
package/src/proto/List.js DELETED
@@ -1,377 +0,0 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
3
-
4
- function List ( o ) {
5
-
6
- Proto.call( this, o );
7
-
8
- this.autoHeight = true;
9
- var align = o.align || 'center';
10
-
11
- this.buttonColor = Tools.colors.button;
12
-
13
- var fltop = Math.floor(this.h*0.5)-5;
14
-
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
-
19
-
20
-
21
- this.scroller = Tools.dom( 'div', Tools.css.basic + 'right:5px; width:10px; pointer-events:none; background:#666; display:none;');
22
-
23
- this.c[2].name = 'list';
24
- this.c[3].name = 'title';
25
-
26
- //this.c[2].style.borderTop = this.h + 'px solid transparent';
27
- this.c[3].style.color = this.fontColor;
28
-
29
- this.c[2].events = [ 'mousedown', 'mousemove', 'mouseup', 'mousewheel', 'mouseout', 'mouseover' ];
30
- this.c[3].events = [ 'mousedown', 'mouseover' ,'mouseout'];
31
-
32
- this.list = o.list || [];
33
-
34
- this.baseH = this.h;
35
-
36
- this.isShow = false;
37
- //this.maxItem = o.maxItem || 5;
38
- this.itemHeight = o.itemHeight || (this.h-3);
39
- //this.length = this.list.length;
40
-
41
- // force full list
42
- this.full = o.full || false;
43
-
44
- this.py = 0;
45
- this.w = this.sb;
46
- this.scroll = false;
47
- this.isDown = false;
48
-
49
- // list up or down
50
- this.side = o.side || 'down';
51
- this.holdTop = 0;
52
-
53
- if( this.side === 'up' ){
54
-
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';
59
-
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
-
65
- } else {
66
- this.c[2].style.top = this.h-2 + 'px';
67
- //this.c[6].style.top = this.h + 'px';
68
- }
69
-
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';
72
-
73
-
74
- this.c[2].appendChild( this.listIn );
75
- this.c[2].appendChild( this.scroller );
76
-
77
- // populate list
78
-
79
- this.setList( this.list, o.value );
80
-
81
-
82
-
83
-
84
- this.init();
85
-
86
- }
87
-
88
- List.prototype = Object.create( Proto.prototype );
89
- List.prototype.constructor = List;
90
-
91
- List.prototype.clearList = function() {
92
-
93
- while ( this.listIn.children.length ) this.listIn.removeChild( this.listIn.lastChild );
94
-
95
- }
96
-
97
- List.prototype.setList = function( list, value ) {
98
-
99
- this.clearList();
100
-
101
- this.list = list;
102
- this.length = this.list.length;
103
-
104
- this.maxItem = this.full ? this.length : 5;
105
- this.maxItem = this.length < this.maxItem ? this.length : this.maxItem;
106
-
107
- this.maxHeight = this.maxItem * (this.itemHeight+1) + 2;
108
-
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;
113
-
114
- this.c[2].style.height = this.maxHeight + 'px';
115
- this.scroller.style.height = this.sh + 'px';
116
-
117
- if( this.max > this.maxHeight ){
118
- this.w = this.sb - 20;
119
- this.scroll = true;
120
- }
121
-
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 );
130
- }
131
-
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];
137
- }
138
-
139
- this.c[3].textContent = this.value;
140
-
141
- }
142
-
143
- List.prototype.handleEvent = function( e ) {
144
-
145
- e.preventDefault();
146
-
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;
156
- }
157
-
158
- }
159
-
160
- List.prototype.mode = function( mode ){
161
-
162
- var s = this.s;
163
-
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;
177
-
178
- }
179
- }
180
-
181
- // -----
182
-
183
- List.prototype.click = function( e ){
184
-
185
- var name = e.target.name;
186
- if( name !== 'title' && name !== 'list' ) this.listHide();
187
-
188
- };
189
-
190
- List.prototype.titleClick = function( e ){
191
-
192
- if( this.isShow ) this.listHide();
193
- else {
194
- this.listShow();
195
- this.mode(2);
196
- }
197
-
198
- };
199
-
200
- // ----- LIST
201
-
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
- }
209
-
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';
225
- }
226
-
227
- };
228
-
229
- List.prototype.listmove = function( e ){
230
-
231
- if( this.isDown ){
232
- var rect = this.c[2].getBoundingClientRect();
233
- this.update( ( e.clientY - rect.top ) - ( this.sh*0.5 ) );
234
- }
235
-
236
- };
237
-
238
- List.prototype.listup = function( e ){
239
-
240
- this.isDown = false;
241
- this.listIn.style.background = 'rgba(0,0,0,0.2)';
242
- this.scroller.style.background = '#666';
243
-
244
- };
245
-
246
- List.prototype.listout = function( e ){
247
-
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;
252
- }
253
-
254
-
255
- if( this.isUI ) this.main.lockwheel = false;
256
- this.listup();
257
- //var name = e.relatedTarget.name;
258
- //if( name === undefined ) this.listHide();
259
-
260
-
261
-
262
- };
263
-
264
- List.prototype.listwheel = function( e ){
265
-
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;
272
-
273
- this.py += delta;
274
-
275
- this.update(this.py);
276
-
277
- };
278
-
279
-
280
- // ----- LIST
281
-
282
- List.prototype.update = function( y ){
283
-
284
- if( !this.scroll ) return;
285
-
286
- y = y < 0 ? 0 : y;
287
- y = y > this.range ? this.range : y;
288
-
289
- this.listIn.style.top = -Math.floor( y / this.ratio )+'px';
290
- this.scroller.style.top = Math.floor( y ) + 'px';
291
-
292
- this.py = y;
293
-
294
- };
295
-
296
- List.prototype.listShow = function(){
297
-
298
- document.addEventListener( 'click', this, false );
299
-
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
- }
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
-
314
- this.rSizeContent();
315
-
316
- if( this.parentGroup !== null ) this.parentGroup.calc( this.h - this.baseH );
317
- else if( this.isUI ) this.main.calc( this.h - this.baseH );
318
-
319
- };
320
-
321
- List.prototype.listHide = function(){
322
-
323
- document.removeEventListener( 'click', this, false );
324
-
325
- if( this.parentGroup !== null ) this.parentGroup.calc( -(this.h-this.baseH) );
326
- else if( this.isUI ) this.main.calc(-(this.h-this.baseH));
327
-
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
- };
335
-
336
- // -----
337
-
338
- List.prototype.text = function( txt ){
339
-
340
- this.c[3].textContent = txt;
341
-
342
- };
343
-
344
- List.prototype.rSizeContent = function(){
345
-
346
- var i = this.length;
347
- while(i--) this.listIn.children[i].style.width = this.w + 'px';
348
-
349
- };
350
-
351
- List.prototype.rSize = function(){
352
-
353
- Proto.prototype.rSize.call( this );
354
-
355
- var s = this.s;
356
- var w = this.sb;
357
- var d = this.sa;
358
-
359
- s[2].width = w + 'px';
360
- s[2].left = d +'px';
361
-
362
- s[3].width = w + 'px';
363
- s[3].left = d + 'px';
364
-
365
- s[4].left = d + w - 17 + 'px';
366
-
367
- //s[5].width = w + 'px';
368
- //s[5].left = d + 'px';
369
-
370
- this.w = w;
371
- if( this.max > this.maxHeight ) this.w = w-20;
372
-
373
- if(this.isShow) this.rSizeContent();
374
-
375
- };
376
-
377
- export { List };
@@ -1,250 +0,0 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
3
-
4
- function Numeric( o ){
5
-
6
- Proto.call( this, o );
7
-
8
- this.type = 'number';
9
-
10
- this.setTypeNumber( o );
11
-
12
- this.allway = o.allway || false;
13
- this.isDrag = o.drag === undefined ? true : o.drag;
14
-
15
- this.value = [0];
16
- this.toRad = 1;
17
- this.isNumber = true;
18
- this.isAngle = false;
19
- this.isVector = false;
20
-
21
- this.isSelect = false;
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;
33
- }
34
- }
35
-
36
- this.length = this.value.length;
37
-
38
- if(o.isAngle){
39
- this.isAngle = true;
40
- this.toRad = Math.PI/180;
41
- }
42
-
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',
58
-
59
- }
60
-
61
- this.init();
62
- }
63
-
64
- Numeric.prototype = Object.create( Proto.prototype );
65
- Numeric.prototype.constructor = Numeric;
66
-
67
- Numeric.prototype.handleEvent = function( e ) {
68
-
69
- //e.preventDefault();
70
- //e.stopPropagation();
71
-
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;
77
-
78
- case 'blur': this.blur( e ); break;
79
- case 'focus': this.focus( e ); break;
80
-
81
- // document
82
- case 'mouseup': this.up( e ); break;
83
- case 'mousemove': this.move( e ); break;
84
-
85
- }
86
-
87
- };
88
-
89
- Numeric.prototype.setValue = function( v, n ){
90
-
91
- n = n || 0;
92
- this.value[n] = this.numValue( v );
93
- this.c[2+n].textContent = this.value[n];
94
-
95
- };
96
-
97
- Numeric.prototype.keydown = function( e ){
98
-
99
- e.stopPropagation();
100
-
101
- if( e.keyCode === 13 ){
102
- e.preventDefault();
103
- this.testValue( parseFloat(e.target.name) );
104
- this.validate();
105
- e.target.blur();
106
- }
107
-
108
- };
109
-
110
- Numeric.prototype.keyup = function( e ){
111
-
112
- e.stopPropagation();
113
-
114
- if( this.allway ){
115
- this.testValue( parseFloat(e.target.name) );
116
- this.validate();
117
- }
118
-
119
- };
120
-
121
- Numeric.prototype.blur = function( e ){
122
-
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';
129
-
130
- };
131
-
132
- Numeric.prototype.focus = function( e ){
133
-
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';
140
-
141
- };
142
-
143
- Numeric.prototype.down = function( e ){
144
-
145
- if(this.isSelect) return;
146
-
147
- e.preventDefault();
148
-
149
-
150
-
151
- //e.target.style.border = '1px solid rgba(255,255,255,0.2)';
152
- this.current = parseFloat(e.target.name);
153
-
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] );
157
-
158
-
159
-
160
- document.addEventListener( 'mouseup', this, false );
161
- if(this.isDrag) document.addEventListener( 'mousemove', this, false );
162
-
163
- };
164
-
165
- ////
166
-
167
- Numeric.prototype.up = function( e ){
168
-
169
- e.preventDefault();
170
-
171
- document.removeEventListener( 'mouseup', this, false );
172
- if(this.isDrag) document.removeEventListener( 'mousemove', this, false );
173
-
174
- if(this.current !== undefined){
175
-
176
- if( this.current === parseFloat(e.target.name) ){
177
- e.target.contentEditable = true;
178
- e.target.focus();
179
- }
180
-
181
- // else e.target.style.borderColor = UIL.BorderSelect;;//this.c[2+this.current].style.border = '1px solid rgba(255,255,255,0.1)';
182
-
183
-
184
- //this.c[2+this.current].style.cursor = 'move';
185
- }
186
-
187
-
188
-
189
- };
190
-
191
- Numeric.prototype.move = function( e ){
192
-
193
- e.preventDefault();
194
-
195
- if( this.current === undefined ) return;
196
-
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);
199
-
200
- this.value[this.current] = this.numValue(n);
201
- //this.c[2+this.current].value = this.value[this.current];
202
-
203
- this.c[2+this.current].textContent = this.value[this.current];
204
-
205
- this.validate();
206
-
207
- this.prev.x = e.clientX;
208
- this.prev.y = e.clientY;
209
-
210
- };
211
-
212
- /////
213
-
214
- Numeric.prototype.testValue = function( n ){
215
-
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
- }
223
-
224
- };
225
-
226
- Numeric.prototype.validate = function(){
227
-
228
- var ar = [];
229
- var i = this.length;
230
- while(i--) ar[i] = this.value[i]*this.toRad;
231
-
232
- if( this.isNumber ) this.send( ar[0] );
233
- else this.send( ar );
234
-
235
- };
236
-
237
- Numeric.prototype.rSize = function(){
238
-
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
- }
247
-
248
- };
249
-
250
- export { Numeric };