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/Tools.js DELETED
@@ -1,379 +0,0 @@
1
- /**
2
- * @author lo-th / https://github.com/lo-th
3
- */
4
-
5
- var Tools = {
6
-
7
- main: null,
8
-
9
- doc: document,
10
- frag: document.createDocumentFragment(),
11
-
12
- isLoop: false,
13
- listens: [],
14
-
15
- svgns: "http://www.w3.org/2000/svg",
16
- htmls: "http://www.w3.org/1999/xhtml",
17
-
18
- DOM_SIZE: [ 'height', 'width', 'top', 'left', 'bottom', 'right', 'margin-left', 'margin-right', 'margin-top', 'margin-bottom'],
19
- SVG_TYPE_D: [ 'pattern', 'defs', 'transform', 'stop', 'animate', 'radialGradient', 'linearGradient', 'animateMotion' ],
20
- SVG_TYPE_G: [ 'rect', 'circle', 'path', 'polygon', 'text', 'g', 'line', 'foreignObject' ],
21
-
22
- size: {
23
-
24
- w: 240,
25
- h: 20,
26
- p: 30,
27
- s: 20,
28
-
29
- },
30
-
31
- // colors
32
-
33
- colors: {
34
-
35
- text : '#C0C0C0',
36
- background: 'rgba(44,44,44,0.3)',
37
-
38
- border : '#4f4f4f',
39
- borderSelect : '#308AFF',
40
-
41
- button : '#404040',
42
- boolbg : '#181818',
43
-
44
- select : '#308AFF',
45
- moving : '#03afff',
46
- down : '#024699',
47
-
48
- stroke: '#606060',//'rgba(120,120,120,0.6)',
49
- scroll: '#333333',
50
-
51
- },
52
-
53
- // style css
54
-
55
- css : {
56
- basic: '-o-user-select:none; -ms-user-select:none; -khtml-user-select:none; -webkit-user-select:none; -moz-user-select:none;' + 'position:absolute; pointer-events:none; box-sizing:border-box; margin:0; padding:0; border:none; overflow:hidden; background:none;',
57
- },
58
-
59
- // svg path
60
-
61
- GPATH: 'M 7 7 L 7 8 8 8 8 7 7 7 M 5 7 L 5 8 6 8 6 7 5 7 M 3 7 L 3 8 4 8 4 7 3 7 M 7 5 L 7 6 8 6 8 5 7 5 M 6 6 L 6 5 5 5 5 6 6 6 M 7 3 L 7 4 8 4 8 3 7 3 M 6 4 L 6 3 5 3 5 4 6 4 M 3 5 L 3 6 4 6 4 5 3 5 M 3 3 L 3 4 4 4 4 3 3 3 Z',
62
-
63
- setText : function( size, color, font ){
64
-
65
- size = size || 11;
66
- color = color || '#CCC';
67
- font = font || '"Consolas", "Lucida Console", Monaco, monospace';
68
-
69
- Tools.css.txt = Tools.css.basic + 'font-family:'+font+'; font-size:'+size+'px; color:'+color+'; padding:2px 10px; left:0; top:2px; height:16px; width:100px; overflow:hidden; white-space: nowrap;';
70
- Tools.css.txtedit = Tools.css.txt + 'pointer-events:auto; padding:2px 5px; outline:none; -webkit-appearance:none; -moz-appearance:none; border:1px dashed #4f4f4f; -ms-user-select:element;'
71
- Tools.css.txtselect = Tools.css.txt + 'pointer-events:auto; padding:2px 5px; outline:none; -webkit-appearance:none; -moz-appearance:none; border:1px dashed ' + Tools.colors.border+'; -ms-user-select:element;';
72
- Tools.css.txtnumber = Tools.css.txt + 'letter-spacing:-1px; padding:2px 5px;';
73
- Tools.css.item = Tools.css.txt + 'position:relative; background:rgba(0,0,0,0.2); margin-bottom:1px; pointer-events:auto; cursor:pointer;';
74
-
75
- },
76
-
77
- setSvg: function( dom, type, value, id ){
78
-
79
- if( id === -1 ) dom.setAttributeNS( null, type, value );
80
- else dom.childNodes[ id || 0 ].setAttributeNS( null, type, value );
81
-
82
- },
83
-
84
- set: function( g, o ){
85
-
86
- for( var att in o ){
87
- if( att === 'txt' ) g.textContent = o[ att ];
88
- g.setAttributeNS( null, att, o[ att ] );
89
- }
90
-
91
- },
92
-
93
- get: function( dom, id ){
94
-
95
- if( id === undefined ) return dom; // root
96
- else if( !isNaN( id ) ) return dom.childNodes[ id ]; // first child
97
- else if( id instanceof Array ){
98
- if(id.length === 2) return dom.childNodes[ id[0] ].childNodes[ id[1] ];
99
- if(id.length === 3) return dom.childNodes[ id[0] ].childNodes[ id[1] ].childNodes[ id[2] ];
100
- }
101
-
102
- },
103
-
104
- /*setDom : function( dom, type, value ){
105
-
106
- var ext = Tools.DOM_SIZE.indexOf(type) !== -1 ? 'px' : '';
107
- dom.style[type] = value + ext;
108
-
109
- },*/
110
-
111
- dom : function ( type, css, obj, dom, id ) {
112
-
113
- type = type || 'div';
114
-
115
- if( Tools.SVG_TYPE_D.indexOf(type) !== -1 || Tools.SVG_TYPE_G.indexOf(type) !== -1 ){ // is svg element
116
-
117
- // create new svg if not def
118
- if( dom === undefined ) dom = Tools.doc.createElementNS( Tools.svgns, 'svg' );
119
-
120
- Tools.addAttributes( dom, type, obj, id );
121
-
122
- } else { // is html element
123
-
124
- if( dom === undefined ) dom = Tools.doc.createElementNS( Tools.htmls, type );
125
- else dom = dom.appendChild( Tools.doc.createElementNS( Tools.htmls, type ) );
126
-
127
- }
128
-
129
- if( css ) dom.style.cssText = css;
130
-
131
- if( id === undefined ) return dom;
132
- else return dom.childNodes[ id || 0 ];
133
-
134
- },
135
-
136
- addAttributes : function( dom, type, o, id ){
137
-
138
- var g = Tools.doc.createElementNS( Tools.svgns, type );
139
- Tools.set( g, o );
140
- Tools.get( dom, id ).appendChild( g );
141
- if( Tools.SVG_TYPE_G.indexOf(type) !== -1 ) g.style.pointerEvents = 'none';
142
- return g;
143
-
144
- },
145
-
146
- clear : function( dom ){
147
-
148
- Tools.purge( dom );
149
- while (dom.firstChild) {
150
- if ( dom.firstChild.firstChild ) Tools.clear( dom.firstChild );
151
- dom.removeChild( dom.firstChild );
152
- }
153
-
154
- },
155
-
156
- purge : function ( dom ) {
157
-
158
- var a = dom.attributes, i, n;
159
- if (a) {
160
- i = a.length;
161
- while(i--){
162
- n = a[i].name;
163
- if (typeof dom[n] === 'function') dom[n] = null;
164
- }
165
- }
166
- a = dom.childNodes;
167
- if (a) {
168
- i = a.length;
169
- while(i--){
170
- Tools.purge( dom.childNodes[i] );
171
- }
172
- }
173
-
174
- },
175
-
176
-
177
-
178
- // LOOP
179
-
180
- loop : function(){
181
-
182
- if( Tools.isLoop ) requestAnimationFrame( Tools.loop );
183
- Tools.update();
184
-
185
- },
186
-
187
- update : function(){
188
-
189
- var i = Tools.listens.length;
190
- while(i--) Tools.listens[i].listening();
191
-
192
- },
193
-
194
- removeListen : function ( proto ){
195
-
196
- var id = Tools.listens.indexOf( proto );
197
- Tools.listens.splice(id, 1);
198
-
199
- if( Tools.listens.length === 0 ) Tools.isLoop = false;
200
-
201
- },
202
-
203
- addListen : function ( proto ){
204
-
205
- var id = Tools.listens.indexOf( proto );
206
-
207
- if( id !== -1 ) return;
208
-
209
- Tools.listens.push( proto );
210
-
211
- if( !Tools.isLoop ){
212
- Tools.isLoop = true;
213
- Tools.loop();
214
- }
215
-
216
- },
217
-
218
- // ----------------------
219
- // Color function
220
- // ----------------------
221
-
222
- ColorLuma : function ( hex, lum ) {
223
-
224
- // validate hex string
225
- hex = String(hex).replace(/[^0-9a-f]/gi, '');
226
- if (hex.length < 6) {
227
- hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
228
- }
229
- lum = lum || 0;
230
-
231
- // convert to decimal and change luminosity
232
- var rgb = "#", c, i;
233
- for (i = 0; i < 3; i++) {
234
- c = parseInt(hex.substr(i*2,2), 16);
235
- c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
236
- rgb += ("00"+c).substr(c.length);
237
- }
238
-
239
- return rgb;
240
-
241
- },
242
-
243
- findDeepInver: function( rgb ){
244
-
245
- return (rgb[0] * 0.3 + rgb[1] * .59 + rgb[2] * .11) <= 0.6;
246
-
247
- },
248
-
249
-
250
- hexToHtml: function(v){
251
- v = v === undefined ? 0x000000 : v;
252
- return "#" + ("000000" + v.toString(16)).substr(-6);
253
-
254
- },
255
-
256
- htmlToHex: function(v){
257
-
258
- return v.toUpperCase().replace("#", "0x");
259
-
260
- },
261
-
262
- u255: function(color, i){
263
-
264
- return parseInt(color.substring(i, i + 2), 16) / 255;
265
-
266
- },
267
-
268
- u16: function( color, i ){
269
-
270
- return parseInt(color.substring(i, i + 1), 16) / 15;
271
-
272
- },
273
-
274
- unpack: function( color ){
275
-
276
- if (color.length == 7) return [ Tools.u255(color, 1), Tools.u255(color, 3), Tools.u255(color, 5) ];
277
- else if (color.length == 4) return [ Tools.u16(color,1), Tools.u16(color,2), Tools.u16(color,3) ];
278
-
279
- },
280
-
281
- htmlRgb: function( rgb ){
282
-
283
- return 'rgb(' + Math.round(rgb[0] * 255) + ','+ Math.round(rgb[1] * 255) + ','+ Math.round(rgb[2] * 255) + ')';
284
-
285
- },
286
-
287
- rgbToHex : function( rgb ){
288
-
289
- return '#' + ( '000000' + ( ( rgb[0] * 255 ) << 16 ^ ( rgb[1] * 255 ) << 8 ^ ( rgb[2] * 255 ) << 0 ).toString( 16 ) ).slice( - 6 );
290
-
291
- },
292
-
293
- hueToRgb: function( p, q, t ){
294
-
295
- if ( t < 0 ) t += 1;
296
- if ( t > 1 ) t -= 1;
297
- if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
298
- if ( t < 1 / 2 ) return q;
299
- if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
300
- return p;
301
-
302
- },
303
-
304
- rgbToHsl: function(rgb){
305
-
306
- var r = rgb[0], g = rgb[1], b = rgb[2], min = Math.min(r, g, b), max = Math.max(r, g, b), delta = max - min, h = 0, s = 0, l = (min + max) / 2;
307
- if (l > 0 && l < 1) s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
308
- if (delta > 0) {
309
- if (max == r && max != g) h += (g - b) / delta;
310
- if (max == g && max != b) h += (2 + (b - r) / delta);
311
- if (max == b && max != r) h += (4 + (r - g) / delta);
312
- h /= 6;
313
- }
314
- return [ h, s, l ];
315
-
316
- },
317
-
318
- hslToRgb: function( hsl ){
319
-
320
- var p, q, h = hsl[0], s = hsl[1], l = hsl[2];
321
-
322
- if ( s === 0 ) return [ l, l, l ];
323
- else {
324
- q = l <= 0.5 ? l * (s + 1) : l + s - ( l * s );
325
- p = l * 2 - q;
326
- return [ Tools.hueToRgb(p, q, h + 0.33333), Tools.hueToRgb(p, q, h), Tools.hueToRgb(p, q, h - 0.33333) ];
327
- }
328
-
329
- },
330
-
331
- // svg to canvas test
332
-
333
- toCanvas: function( canvas, content, w, h ){
334
-
335
- var ctx = canvas.getContext("2d");
336
-
337
- var dcopy = null;
338
-
339
- if( typeof content === 'string' ){
340
-
341
- dcopy = Tools.dom( 'iframe', 'position:abolute; left:0; top:0; width:'+w+'px; height:'+h+'px;' );
342
- dcopy.src = content;
343
-
344
- }else{
345
- dcopy = content.cloneNode(true);
346
- dcopy.style.left = 0;
347
- }
348
-
349
- var svg = Tools.dom( 'foreignObject', 'position:abolute; left:0; top:0;', { width:w, height:h });
350
-
351
- svg.childNodes[0].appendChild( dcopy );
352
-
353
- svg.setAttribute("version", "1.1");
354
- svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg' );
355
- svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
356
-
357
- svg.setAttribute('width', w );
358
- svg.setAttribute('height', h );
359
- svg.childNodes[0].setAttribute('width', '100%' );
360
- svg.childNodes[0].setAttribute('height', '100%' );
361
-
362
- var data = 'data:image/svg+xml;base64,'+ window.btoa((new XMLSerializer).serializeToString(svg));
363
- dcopy = null;
364
-
365
- var img = new Image();
366
- img.src = data;
367
-
368
- setTimeout(function() {
369
- ctx.clearRect( 0, 0, w, h );
370
- ctx.drawImage( img, 0, 0, w, h, 0, 0, w, h );
371
- }, 0);
372
-
373
- },
374
-
375
- }
376
-
377
- Tools.setText();
378
-
379
- export { Tools };
package/src/core/add.js DELETED
@@ -1,90 +0,0 @@
1
-
2
- import { Bool } from '../proto/Bool.js';
3
- import { Button } from '../proto/Button.js';
4
- import { Circular } from '../proto/Circular.js';
5
- import { Color } from '../proto/Color.js';
6
- import { Fps } from '../proto/Fps.js';
7
- import { Group } from '../proto/Group.js';
8
- import { Joystick } from '../proto/Joystick.js';
9
- import { Knob } from '../proto/Knob.js';
10
- import { List } from '../proto/List.js';
11
- import { Numeric } from '../proto/Numeric.js';
12
- import { Slide } from '../proto/Slide.js';
13
- import { TextInput } from '../proto/TextInput.js';
14
- import { Title } from '../proto/Title.js';
15
-
16
- function getType( name, o ) {
17
-
18
- var n = null;
19
-
20
- switch( name ){
21
-
22
- case 'Bool': case 'bool': n = new Bool(o); break;
23
- case 'Button': case 'button': n = new Button(o); break;
24
- case 'Circular': case 'circular': n = new Circular(o); break;
25
- case 'Color': case 'color': n = new Color(o); break;
26
- case 'Fps': case 'fps': n = new Fps(o); break;
27
- case 'Group': case 'group': n = new Group(o); break;
28
- case 'Joystick': case 'joystick': n = new Joystick(o); break;
29
- case 'Knob': case 'knob': n = new Knob(o); break;
30
- case 'List': case 'list': n = new List(o); break;
31
- case 'Numeric':case 'Number': case 'numeric':case 'number': n = new Numeric(o); break;
32
- case 'Slide': case 'slide': n = new Slide(o); break;
33
- case 'TextInput':case 'String': case 'textInput':case 'string': n = new TextInput(o); break;
34
- case 'Title': case 'title': n = new Title(o); break;
35
-
36
- }
37
-
38
- return n;
39
- };
40
-
41
- function add (){
42
-
43
- var a = arguments;
44
-
45
- var type, o, ref = false;
46
-
47
- if( typeof a[0] === 'string' ){
48
-
49
- type = a[0];//[0].toUpperCase() + a[0].slice(1);
50
- o = a[1] || {};
51
-
52
- } else if ( typeof a[0] === 'object' ){ // like dat gui
53
-
54
- ref = true;
55
- if( a[2] === undefined ) [].push.call(a, {});
56
-
57
- type = autoType.apply( this, a );
58
-
59
- o = a[2];
60
-
61
- o.name = a[1];
62
- o.value = a[0][a[1]];
63
-
64
- }
65
-
66
- var n = getType( type, o );
67
-
68
- if(n !== null ){
69
- if( ref ) n.setReferency( a[0], a[1] );
70
- return n;
71
- }
72
-
73
-
74
- };
75
-
76
- function autoType () {
77
-
78
- var a = arguments;
79
-
80
- var type = 'Slide';
81
-
82
- if(a[2].type) type = a[2].type;
83
-
84
- return type;
85
-
86
- };
87
-
88
- export { add };
89
-
90
- export var REVISION = '1.0';
package/src/polyfills.js DELETED
@@ -1,85 +0,0 @@
1
- // Polyfills
2
-
3
- if ( Number.EPSILON === undefined ) {
4
-
5
- Number.EPSILON = Math.pow( 2, - 52 );
6
-
7
- }
8
-
9
- //
10
-
11
- if ( Math.sign === undefined ) {
12
-
13
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
14
-
15
- Math.sign = function ( x ) {
16
-
17
- return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
18
-
19
- };
20
-
21
- }
22
-
23
- if ( Function.prototype.name === undefined ) {
24
-
25
- // Missing in IE9-11.
26
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
27
-
28
- Object.defineProperty( Function.prototype, 'name', {
29
-
30
- get: function () {
31
-
32
- return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
33
-
34
- }
35
-
36
- } );
37
-
38
- }
39
-
40
- if ( Object.assign === undefined ) {
41
-
42
- // Missing in IE.
43
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
44
-
45
- ( function () {
46
-
47
- Object.assign = function ( target ) {
48
-
49
- 'use strict';
50
-
51
- if ( target === undefined || target === null ) {
52
-
53
- throw new TypeError( 'Cannot convert undefined or null to object' );
54
-
55
- }
56
-
57
- var output = Object( target );
58
-
59
- for ( var index = 1; index < arguments.length; index ++ ) {
60
-
61
- var source = arguments[ index ];
62
-
63
- if ( source !== undefined && source !== null ) {
64
-
65
- for ( var nextKey in source ) {
66
-
67
- if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
68
-
69
- output[ nextKey ] = source[ nextKey ];
70
-
71
- }
72
-
73
- }
74
-
75
- }
76
-
77
- }
78
-
79
- return output;
80
-
81
- };
82
-
83
- } )();
84
-
85
- }
package/src/proto/Bool.js DELETED
@@ -1,82 +0,0 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
3
-
4
- function Bool ( o ){
5
-
6
- Proto.call( this, o );
7
-
8
- this.value = o.value || false;
9
-
10
- this.buttonColor = Tools.colors.button;
11
-
12
- this.inh = o.inh || this.h;
13
-
14
- var t = ~~ (this.h*0.5)-((this.inh-2)*0.5);
15
-
16
- this.c[2] = Tools.dom( 'div', Tools.css.basic + 'background:'+ Tools.colors.boolbg +'; height:'+(this.inh-2)+'px; width:36px; top:'+t+'px; border-radius:20px; pointer-events:auto; cursor:pointer; transition:0.1s ease-out;' );
17
- this.c[3] = Tools.dom( 'div', Tools.css.basic + 'opasity:0, background:'+ Tools.colors.boolbg +'; height:'+(this.inh-6)+'px; width:'+(this.inh-6)+'px; top:'+(t+2)+'px; border-radius:20px; ' );
18
- this.c[4] = Tools.dom( 'div', Tools.css.basic + 'border:1px solid '+Tools.colors.border+'; height:'+(this.inh-4)+'px; width:16px; top:'+(t+1)+'px; border-radius:20px; background:'+this.buttonColor+'; transition:margin 0.1s ease-out;' );
19
-
20
- if(this.value){
21
- this.c[4].style.marginLeft = '18px';
22
- this.c[2].style.background = this.fontColor;
23
- this.c[2].style.borderColor = this.fontColor;
24
- }
25
-
26
- this.c[2].events = [ 'click' ];
27
-
28
- this.init();
29
-
30
- };
31
-
32
- Bool.prototype = Object.create( Proto.prototype );
33
- Bool.prototype.constructor = Bool;
34
-
35
- Bool.prototype.handleEvent = function( e ) {
36
-
37
- e.preventDefault();
38
-
39
- switch( e.type ) {
40
- case 'click': this.click(e); break;
41
- }
42
-
43
- };
44
-
45
- Bool.prototype.click = function( e ){
46
-
47
- if(this.value) this.value = false;
48
- else this.value = true;
49
- this.update();
50
- this.send();
51
-
52
- };
53
-
54
- Bool.prototype.rSize = function(){
55
-
56
- Proto.prototype.rSize.call( this );
57
- var s = this.s;
58
- s[2].left = this.sa + 'px';
59
- s[3].left = this.sa+1+ 'px';
60
- s[4].left = this.sa+1 + 'px';
61
-
62
- };
63
-
64
- Bool.prototype.update = function() {
65
-
66
- var s = this.s;
67
-
68
- if(this.value){
69
- s[4].marginLeft = '18px';
70
- s[2].background = this.fontColor;
71
- s[2].borderColor = this.fontColor;
72
- s[4].borderColor = this.fontColor;
73
- } else {
74
- s[4].marginLeft = '0px';
75
- s[2].background = Tools.colors.boolbg;
76
- s[2].borderColor = Tools.colors.boolbg;
77
- s[4].borderColor = Tools.colors.border;
78
- }
79
-
80
- };
81
-
82
- export { Bool };