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