uil 0.1.0 → 4.0.1

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/core/Proto.js DELETED
@@ -1,406 +0,0 @@
1
- import { Tools } from './Tools';
2
-
3
- function Proto( o ){
4
-
5
- o = o || {};
6
-
7
- this.main = o.main || null;
8
-
9
- //this.type = '';
10
- // percent of title
11
- this.p = Tools.base.P;//o.tPercent || 0;
12
- if(o.p !== undefined ) this.p = o.p;
13
-
14
- // if need resize width
15
- this.autoWidth = true;
16
-
17
- this.isGroup = false;
18
- this.parentGroup = null;
19
-
20
- // if height can change
21
- this.autoHeight = false;
22
-
23
- // if is on ui pannel
24
- this.isUI = o.isUI || false;
25
-
26
- // only for number
27
- this.isNumber = false;
28
-
29
- // only most simple
30
- this.mono = false;
31
-
32
- // stop listening for edite slide text
33
- this.isEdit = false;
34
-
35
- // no title
36
- this.simple = o.simple || false;
37
- if( this.simple ) this.sa = 0;
38
-
39
- this.width = this.isUI ? this.main.width : Tools.base.WIDTH;
40
- if(o.width !== undefined ) this.width = o.width;
41
- if(o.size !== undefined ) this.width = o.size;
42
-
43
- //console.log(this.width)
44
-
45
- // define obj size
46
- this.setSize( this.width );
47
-
48
- // title size
49
- if(o.sa !== undefined ) this.sa = o.sa;
50
- if(o.sb !== undefined ) this.sb = o.sb;
51
-
52
- if( this.simple ) this.sb = this.width - this.sa;
53
-
54
- // last number size for slide
55
- this.sc = o.sc === undefined ? 47 : o.sc;
56
-
57
- // like dat gui
58
- this.parent = null;
59
- this.val = null;
60
- this.isSend = false;
61
-
62
- var h = 20;
63
- if( this.isUI ) h = Tools.base.HEIGHT;//this.main.height;
64
- this.h = o.h || o.height || h;
65
- this.h = this.h < 11 ? 11 : this.h;
66
-
67
- this.bgcolor = o.bgcolor || Tools.colors.background;
68
-
69
- this.bg = this.isUI ? this.main.bg : 'rgba(44,44,44,0.3)';
70
- if(o.bg !== undefined ) this.bg = o.bg;
71
-
72
-
73
-
74
- //this.fontColor = o.fontColor === undefined ? UIL.BASECOLOR : o.fontColor;
75
- this.titleColor = o.titleColor || Tools.colors.text;
76
- this.fontColor = o.fontColor || Tools.colors.text;
77
- this.colorPlus = Tools.ColorLuma( this.fontColor, 0.3 );
78
-
79
-
80
- this.txt = o.name || 'Proto';
81
- this.rename = o.rename || '';
82
- this.target = o.target || null;
83
-
84
- this.callback = o.callback === undefined ? null : o.callback;
85
- this.endCallback = null;
86
-
87
- if( this.callback === null && this.isUI && this.main.callback !== null ) this.callback = this.main.callback;
88
-
89
- // elements
90
-
91
- this.c = [];
92
-
93
- // style
94
-
95
- this.s = [];
96
-
97
- //this.c[0] = Tools.dom('UIL', 'div', 'position:relative; height:20px; float:left;');
98
- this.c[0] = Tools.dom( 'div', Tools.css.basic + 'position:relative; height:20px; float:left; overflow:hidden;');
99
- this.s[0] = this.c[0].style;
100
-
101
- if( this.isUI ) this.s[0].marginBottom = '1px';
102
-
103
-
104
- if( !this.simple ){
105
- //this.c[1] = Tools.dom('UIL text');
106
- this.c[1] = Tools.dom( 'div', Tools.css.txt );
107
- this.s[1] = this.c[1].style;
108
- this.c[1].textContent = this.rename === '' ? this.txt : this.rename;
109
- this.s[1].color = this.titleColor;
110
- }
111
-
112
- if(o.pos){
113
- this.s[0].position = 'absolute';
114
- for(var p in o.pos){
115
- this.s[0][p] = o.pos[p];
116
- }
117
- this.mono = true;
118
- }
119
-
120
- if(o.css){
121
- this.s[0].cssText = o.css;
122
- }
123
-
124
- };
125
-
126
- Proto.prototype = {
127
-
128
- constructor: Proto,
129
-
130
- // make de node
131
-
132
-
133
- init: function (){
134
-
135
- var s = this.s; // style cached
136
-
137
- //s[0] = this.c[0].style;
138
- s[0].height = this.h + 'px';
139
-
140
- if( this.isUI ) this.s[0].background = this.bg;//this.isUI ? this.main.bg : UIL.bgcolor(this.bgcolor);
141
- if( this.autoHeight ) this.s[0].transition = 'height 0.1s ease-out';
142
- if( this.c[1] !== undefined && this.autoWidth ){
143
- s[1] = this.c[1].style;
144
- s[1].height = (this.h-4) + 'px';
145
- s[1].lineHeight = (this.h-8) + 'px';
146
- }
147
-
148
- var frag = Tools.frag;
149
-
150
- for( var i=1, lng = this.c.length; i !== lng; i++ ){
151
- if( this.c[i] !== undefined ) {
152
- frag.appendChild( this.c[i] );
153
- s[i] = this.c[i].style;
154
- }
155
- }
156
-
157
-
158
- if( this.target !== null ){
159
- this.target.appendChild( this.c[0] );
160
- } else {
161
- if( this.isUI ) this.main.inner.appendChild( this.c[0] );
162
- else document.body.appendChild( this.c[0] );
163
- }
164
-
165
- this.c[0].appendChild( frag );
166
-
167
- //this.s = s;
168
-
169
- this.rSize();
170
- this.addEvent();
171
-
172
- },
173
-
174
- rename:function(s){
175
- this.c[1].textContent = s;
176
- },
177
-
178
- setBG : function(c){
179
-
180
- this.bg = c;
181
- this.s[0].background = c;
182
-
183
- },
184
-
185
- listen : function( ){
186
-
187
- Tools.addListen( this );
188
-
189
- Tools.listens.push( this );
190
- return this;
191
-
192
- },
193
-
194
- listening : function(){
195
-
196
- if( this.parent === null ) return;
197
- if( this.isSend ) return;
198
- if( this.isEdit ) return;
199
-
200
- this.setValue( this.parent[ this.val ] );
201
-
202
- },
203
-
204
- setValue : function( v ){
205
- if( this.isNumber ) this.value = this.numValue( v );
206
- else this.value = v;
207
-
208
- this.update();
209
-
210
- },
211
-
212
- update: function( ) {
213
-
214
- },
215
-
216
- // update every change
217
-
218
- onChange : function( f ){
219
-
220
- this.callback = f;
221
- return this;
222
-
223
- },
224
-
225
- // update only on end
226
-
227
- onFinishChange : function( f ){
228
-
229
- this.callback = null;
230
- this.endCallback = f;
231
- return this;
232
-
233
- },
234
-
235
- send:function( v ){
236
- this.isSend = true;
237
-
238
- if( this.parent !== null ) this.parent[ this.val ] = v || this.value;
239
- if( this.callback ) this.callback( v || this.value );
240
-
241
- this.isSend = false;
242
-
243
- },
244
-
245
- sendEnd:function( v ){
246
-
247
- if( this.endCallback ) this.endCallback( v || this.value );
248
- if( this.parent !== null ) this.parent[ this.val ] = v || this.value;
249
-
250
- },
251
-
252
-
253
-
254
- // clear node
255
-
256
- clear:function(){
257
-
258
- this.clearEvent();
259
- Tools.clear( this.c[0] );
260
-
261
- if( this.target !== null ){
262
- this.target.removeChild( this.c[0] );
263
- } else {
264
- if( this.isUI ) this.main.clearOne( this );//this.main.inner.removeChild( this.c[0] );
265
- else document.body.removeChild( this.c[0] );
266
- }
267
-
268
- this.c = null;
269
- this.s = null;
270
- this.callback = null;
271
- this.target = null;
272
-
273
- },
274
-
275
- // change size
276
-
277
- setSize:function( sx ){
278
-
279
- if( !this.autoWidth ) return;
280
-
281
- this.width = sx;// || UIL.WIDTH;
282
-
283
- this.p = this.p === undefined ? Tools.base.P : this.p;
284
-
285
-
286
- //if( !this.p ) this.p = UIL.P;
287
-
288
- if( this.simple ){
289
- //this.sa = 0;
290
- this.sb = this.width - this.sa;
291
- }else{
292
- var pp = this.width * ( this.p / 100 );
293
- this.sa = ~~ pp + 10;
294
- this.sb = ~~ this.width - pp - 20;
295
- }
296
-
297
- },
298
-
299
- rSize:function(){
300
-
301
- if( !this.autoWidth ) return;
302
-
303
- this.s[0].width = this.width + 'px';
304
- if( !this.simple ) this.s[1].width = this.sa + 'px';
305
-
306
- },
307
-
308
- // for numeric value
309
-
310
- setTypeNumber:function( o ){
311
-
312
- this.isNumber = true;
313
-
314
- this.value = 0;
315
- if(o.value !== undefined){
316
- if( typeof o.value === 'string' ) this.value = o.value * 1;
317
- else this.value = o.value;
318
- }
319
-
320
- this.min = o.min === undefined ? -Infinity : o.min;
321
- this.max = o.max === undefined ? Infinity : o.max;
322
- this.precision = o.precision === undefined ? 2 : o.precision;
323
-
324
- var s;
325
-
326
- switch(this.precision){
327
- case 0: s = 1; break;
328
- case 1: s = 0.1; break;
329
- case 2: s = 0.01; break;
330
- case 3: s = 0.001; break;
331
- case 4: s = 0.0001; break;
332
- }
333
-
334
- this.step = o.step === undefined ? s : o.step;
335
-
336
- this.range = this.max - this.min;
337
-
338
- this.value = this.numValue( this.value );
339
-
340
- },
341
-
342
- numValue:function( n ){
343
-
344
- return Math.min( this.max, Math.max( this.min, n ) ).toFixed( this.precision ) * 1;
345
-
346
- },
347
-
348
- // ----------------------
349
- // Events dispatch
350
- // ----------------------
351
-
352
- addEvent: function(){
353
-
354
- var i = this.c.length, j, c;
355
- while( i-- ){
356
- c = this.c[i];
357
- if( c !== undefined ){
358
- if( c.events !== undefined ){
359
- j = c.events.length;
360
- while( j-- ) c.addEventListener( c.events[j], this, false );
361
- }
362
- }
363
- }
364
-
365
- },
366
-
367
- clearEvent: function(){
368
-
369
- var i = this.c.length, j, c;
370
- while( i-- ){
371
- c = this.c[i];
372
- if( c !== undefined ){
373
- if( c.events !== undefined ){
374
- j = c.events.length;
375
- while( j-- ) c.removeEventListener( c.events[j], this, false );
376
- }
377
- }
378
- }
379
-
380
- },
381
-
382
- handleEvent: function( e ) {
383
-
384
- },
385
-
386
- // ----------------------
387
- // object referency
388
- // ----------------------
389
-
390
- setReferency: function(obj, val){
391
-
392
- this.parent = obj;
393
- this.val = val;
394
-
395
- },
396
-
397
- display:function(v){
398
-
399
- this.s[0].display = v ? 'block' : 'none';
400
-
401
- },
402
-
403
-
404
- }
405
-
406
- export { Proto };