uil 1.0.1 → 4.0.3

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