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.
@@ -1,369 +0,0 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
3
-
4
- function Color ( o ) {
5
-
6
- Proto.call( this, o );
7
-
8
- this.autoHeight = true;
9
-
10
- this.ctype = o.ctype || 'array';
11
- this.ww = this.sb;
12
- this.oldWidth = 0;
13
-
14
- // color up or down
15
- this.side = o.side || 'down';
16
- this.holdTop = 0;
17
-
18
- this.wheelWidth = this.ww*0.1;
19
- this.decal = this.h + 2;
20
-
21
- this.radius = (this.ww - this.wheelWidth) * 0.5 - 1;
22
- this.square = Math.floor((this.radius - this.wheelWidth * 0.5) * 0.7) - 1;
23
- this.mid = Math.floor(this.ww * 0.5 );
24
- this.markerSize = this.wheelWidth * 0.3;
25
-
26
- this.baseH = this.h;
27
-
28
- this.c[2] = Tools.dom( 'div', Tools.css.txt + 'height:'+(this.h-4)+'px;' + 'border-radius:3px; pointer-events:auto; cursor:pointer; border:1px solid '+ Tools.colors.border + '; line-height:'+(this.h-8)+'px;' );
29
-
30
- this.s[2] = this.c[2].style;
31
-
32
- if(this.side === 'up'){
33
- this.decal = 5;
34
- this.s[2].top = 'auto';
35
- this.s[2].bottom = '2px';
36
- }
37
-
38
- this.c[3] = Tools.dom( 'div', Tools.css.basic + 'display:none' );
39
- this.c[4] = Tools.dom( 'canvas', Tools.css.basic + 'display:none;');
40
- this.c[5] = Tools.dom( 'canvas', Tools.css.basic + 'pointer-events:auto; cursor:pointer; display:none;');
41
-
42
- this.s[3] = this.c[3].style;
43
- this.s[5] = this.c[5].style;
44
-
45
- if(this.side === 'up') this.s[5].pointerEvents = 'none';
46
-
47
- this.c[4].width = this.c[4].height = this.ww;
48
- this.c[5].width = this.c[5].height = this.ww;
49
-
50
- this.ctxMask = this.c[4].getContext('2d');
51
- this.ctxOverlay = this.c[5].getContext('2d');
52
- this.ctxMask.translate(this.mid, this.mid);
53
- this.ctxOverlay.translate(this.mid, this.mid);
54
-
55
- this.hsl = null;
56
- this.value = '#ffffff';
57
- if( o.value !== undefined ){
58
- if(o.value instanceof Array) this.value = Tools.rgbToHex( o.value );
59
- else if(!isNaN(o.value)) this.value = Tools.hexToHtml( o.value );
60
- else this.value = o.value;
61
- }
62
- this.bcolor = null;
63
- this.isDown = false;
64
- this.isShow = false;
65
-
66
- this.c[2].events = [ 'click' ];
67
- this.c[5].events = [ 'mousedown', 'mousemove', 'mouseup', 'mouseout' ];
68
-
69
- this.setColor( this.value );
70
-
71
- this.init();
72
-
73
- };
74
-
75
- Color.prototype = Object.create( Proto.prototype );
76
- Color.prototype.constructor = Color;
77
-
78
- Color.prototype.handleEvent = function( e ) {
79
-
80
- e.preventDefault();
81
- e.stopPropagation();
82
-
83
- switch( e.type ) {
84
- case 'click': this.click(e); break;
85
- case 'mousedown': this.down(e); break;
86
- case 'mousemove': this.move(e); break;
87
- case 'mouseup': this.up(e); break;
88
- case 'mouseout': this.out(e); break;
89
- }
90
-
91
- };
92
-
93
- /////
94
-
95
- Color.prototype.click = function( e ){
96
-
97
- if( !this.isShow ) this.show();
98
- else this.hide();
99
-
100
- };
101
-
102
- Color.prototype.up = function( e ){
103
-
104
- this.isDown = false;
105
-
106
- };
107
-
108
- Color.prototype.out = function( e ){
109
-
110
- this.hide();
111
-
112
- };
113
-
114
- Color.prototype.down = function( e ){
115
-
116
- if(!this.isShow) return;
117
- this.isDown = true;
118
- this.move( e );
119
- return false;
120
-
121
- };
122
-
123
- Color.prototype.move = function( e ){
124
-
125
- if(!this.isDown) return;
126
-
127
- this.offset = this.c[5].getBoundingClientRect();
128
- var pos = { x: e.pageX - this.offset.left - this.mid, y: e.pageY - this.offset.top - this.mid };
129
- this.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) > (this.square + 2);
130
-
131
- if ( this.circleDrag ) {
132
- var hue = Math.atan2(pos.x, -pos.y) / 6.28;
133
- this.setHSL([(hue + 1) % 1, this.hsl[1], this.hsl[2]]);
134
- } else {
135
- var sat = Math.max(0, Math.min(1, -( pos.x / this.square * 0.5) + .5) );
136
- var lum = Math.max(0, Math.min(1, -( pos.y / this.square * 0.5) + .5) );
137
- this.setHSL([this.hsl[0], sat, lum]);
138
- }
139
-
140
- };
141
-
142
-
143
- //////
144
-
145
- Color.prototype.redraw = function(){
146
-
147
- this.oldWidth = this.ww;
148
- this.drawCircle();
149
- this.drawMask();
150
- this.drawMarkers();
151
-
152
- };
153
-
154
- Color.prototype.show = function(){
155
-
156
- if(this.oldWidth!==this.ww) this.redraw();
157
- this.isShow = true;
158
- this.h = this.ww + this.baseH + 10;
159
- this.s[0].height = this.h+'px';
160
-
161
- if(this.side=='up'){
162
- this.holdTop = this.s[0].top.substring(0,this.s[0].top.length-2) * 1 || 'auto';
163
- if(!isNaN(this.holdTop)) this.s[0].top = (this.holdTop-(this.h-20))+'px';
164
- setTimeout(function(){this.s[5].pointerEvents = 'auto';}.bind(this), 100);
165
- }
166
-
167
- this.s[3].display = 'block';
168
- this.s[4].display = 'block';
169
- this.s[5].display = 'block';
170
-
171
- if( this.parentGroup !== null ){ this.parentGroup.calc( this.h - this.baseH );}
172
- else if( this.isUI ) this.main.calc( this.h - this.baseH );
173
-
174
- };
175
-
176
- Color.prototype.hide = function(){
177
-
178
- if( this.parentGroup !== null ){ this.parentGroup.calc( -(this.h-this.baseH) );}
179
- else if( this.isUI ) this.main.calc( -(this.h-this.baseH) );
180
-
181
- this.isShow = false;
182
- this.h = this.baseH;
183
- if(this.side === 'up'){
184
- if(!isNaN(this.holdTop)) this.s[0].top = (this.holdTop)+'px';
185
- this.s[5].pointerEvents = 'none';
186
- }
187
- this.s[0].height = this.h+'px';
188
- this.s[3].display = 'none';
189
- this.s[4].display = 'none';
190
- this.s[5].display = 'none';
191
-
192
- };
193
-
194
- Color.prototype.update = function( up ){
195
-
196
- this.s[3].background = Tools.rgbToHex( Tools.hslToRgb([this.hsl[0], 1, 0.5]) );
197
-
198
- this.drawMarkers();
199
-
200
- this.value = this.bcolor;
201
-
202
- this.s[2].background = this.bcolor;
203
- this.c[2].textContent = Tools.htmlToHex( this.bcolor );
204
-
205
- this.invert = Tools.findDeepInver( this.rgb );
206
- this.s[2].color = this.invert ? '#fff' : '#000';
207
-
208
- if(!up) return;
209
-
210
- if( this.ctype === 'array' ) this.send( this.rgb );
211
- if( this.ctype === 'rgb' ) this.send( Tools.htmlRgb( this.rgb ) );
212
- if( this.ctype === 'hex' ) this.send( Tools.htmlToHex( this.value ) );
213
- if( this.ctype === 'html' ) this.send();
214
-
215
- };
216
-
217
- Color.prototype.setColor = function( color ){
218
-
219
- var unpack = Tools.unpack(color);
220
- if (this.bcolor != color && unpack) {
221
- this.bcolor = color;
222
- this.rgb = unpack;
223
- this.hsl = Tools.rgbToHsl( this.rgb );
224
- this.update();
225
- }
226
- return this;
227
-
228
- };
229
-
230
- Color.prototype.setHSL = function( hsl ){
231
-
232
- this.hsl = hsl;
233
- this.rgb = Tools.hslToRgb( hsl );
234
- this.bcolor = Tools.rgbToHex( this.rgb );
235
- this.update( true );
236
- return this;
237
-
238
- };
239
-
240
- Color.prototype.calculateMask = function(sizex, sizey, outputPixel){
241
- var isx = 1 / sizex, isy = 1 / sizey;
242
- for (var y = 0; y <= sizey; ++y) {
243
- var l = 1 - y * isy;
244
- for (var x = 0; x <= sizex; ++x) {
245
- var s = 1 - x * isx;
246
- var a = 1 - 2 * Math.min(l * s, (1 - l) * s);
247
- var c = (a > 0) ? ((2 * l - 1 + a) * .5 / a) : 0;
248
- outputPixel(x, y, c, a);
249
- }
250
- }
251
- };
252
-
253
- Color.prototype.drawMask = function(){
254
- var size = this.square * 2, sq = this.square;
255
- var sz = Math.floor(size / 2);
256
- var buffer = document.createElement('canvas');
257
- buffer.width = buffer.height = sz + 1;
258
- var ctx = buffer.getContext('2d');
259
- var frame = ctx.getImageData(0, 0, sz + 1, sz + 1);
260
-
261
- var i = 0;
262
- this.calculateMask(sz, sz, function (x, y, c, a) {
263
- frame.data[i++] = frame.data[i++] = frame.data[i++] = c * 255;
264
- frame.data[i++] = a * 255;
265
- });
266
-
267
- ctx.putImageData(frame, 0, 0);
268
- this.ctxMask.drawImage(buffer, 0, 0, sz + 1, sz + 1, -sq, -sq, sq * 2, sq * 2);
269
- };
270
-
271
- Color.prototype.drawCircle = function(){
272
- var n = 24,r = this.radius, w = this.wheelWidth, nudge = 8 / r / n * Math.PI, m = this.ctxMask, a1 = 0, color1, d1;
273
- var ym, am, tan, xm, color2, d2, a2, ar;
274
- m.save();
275
- m.lineWidth = w / r;
276
- m.scale(r, r);
277
- for (var i = 0; i <= n; ++i) {
278
- d2 = i / n;
279
- a2 = d2 * Math.PI * 2;
280
- ar = [Math.sin(a1), -Math.cos(a1), Math.sin(a2), -Math.cos(a2)];
281
- am = (a1 + a2) * 0.5;
282
- tan = 1 / Math.cos((a2 - a1) * 0.5);
283
- xm = Math.sin(am) * tan, ym = -Math.cos(am) * tan;
284
- color2 = Tools.rgbToHex( Tools.hslToRgb([d2, 1, 0.5]) );
285
- if (i > 0) {
286
- var grad = m.createLinearGradient(ar[0], ar[1], ar[2], ar[3]);
287
- grad.addColorStop(0, color1);
288
- grad.addColorStop(1, color2);
289
- m.strokeStyle = grad;
290
- m.beginPath();
291
- m.moveTo(ar[0], ar[1]);
292
- m.quadraticCurveTo(xm, ym, ar[2], ar[3]);
293
- m.stroke();
294
- }
295
- a1 = a2 - nudge;
296
- color1 = color2;
297
- d1 = d2;
298
- }
299
- m.restore();
300
- };
301
-
302
- Color.prototype.drawMarkers = function(){
303
-
304
- var m = this.markerSize, ra=this.radius, sz = this.ww, lw = Math.ceil(m/ 4), r = m - lw + 1, c1 = this.invert ? '#fff' : '#000', c2 = this.invert ? '#000' : '#fff';
305
- var angle = this.hsl[0] * 6.28;
306
- var ar = [Math.sin(angle) * ra, -Math.cos(angle) * ra, 2 * this.square * (.5 - this.hsl[1]), 2 * this.square * (.5 - this.hsl[2]) ];
307
-
308
- var circles = [
309
- { x: ar[2], y: ar[3], r: m, c: c1, lw: lw },
310
- { x: ar[2], y: ar[3], r: r, c: c2, lw: lw + 1 },
311
- { x: ar[0], y: ar[1], r: m, c: '#fff', lw: lw },
312
- { x: ar[0], y: ar[1], r: r, c: '#000', lw: lw + 1 },
313
- ];
314
- this.ctxOverlay.clearRect(-this.mid, -this.mid, sz, sz);
315
- var i = circles.length;
316
- while(i--){
317
- var c = circles[i];
318
- this.ctxOverlay.lineWidth = c.lw;
319
- this.ctxOverlay.strokeStyle = c.c;
320
- this.ctxOverlay.beginPath();
321
- this.ctxOverlay.arc(c.x, c.y, c.r, 0, Math.PI * 2, true);
322
- this.ctxOverlay.stroke();
323
- }
324
- };
325
-
326
- Color.prototype.rSize = function(){
327
-
328
- Proto.prototype.rSize.call( this );
329
-
330
- this.ww = this.sb;
331
- this.wheelWidth = this.ww*0.1;
332
-
333
- if( this.side === 'up' ) this.decal = 5;
334
- this.radius = (this.ww - this.wheelWidth) * 0.5 - 1;
335
- this.square = Math.floor((this.radius - this.wheelWidth * 0.5) * 0.7) - 1;
336
- this.mid = Math.floor(this.ww * 0.5 );
337
- this.markerSize = this.wheelWidth * 0.3;
338
-
339
- var s = this.s;
340
-
341
- s[2].width = this.sb + 'px';
342
- s[2].left = this.sa + 'px';
343
-
344
- s[3].width = (this.square * 2 - 1) + 'px';
345
- s[3].height = (this.square * 2 - 1) + 'px';
346
- s[3].top = (this.mid+this.decal )-this.square + 'px';
347
- s[3].left = (this.mid+this.sa )-this.square + 'px';
348
-
349
- this.c[4].width = this.c[4].height = this.ww;
350
- s[4].left = this.sa + 'px';
351
- s[4].top = this.decal + 'px';
352
-
353
- this.c[5].width = this.c[5].height = this.ww;
354
- s[5].left = this.sa + 'px';
355
- s[5].top = this.decal + 'px';
356
-
357
- this.ctxMask.translate(this.mid, this.mid);
358
- this.ctxOverlay.translate(this.mid, this.mid);
359
-
360
- if( this.isShow ){
361
- this.redraw();
362
- this.h = this.ww+30;
363
- this.c[0].height = this.h + 'px';
364
- if( this.isUI ) this.main.calc();
365
- }
366
-
367
- };
368
-
369
- export { Color };
package/src/proto/Fps.js DELETED
@@ -1,254 +0,0 @@
1
- import { Tools } from '../core/Tools';
2
- import { Proto } from '../core/Proto';
3
-
4
- function Fps ( o ) {
5
-
6
- Proto.call( this, o );
7
-
8
- this.round = Math.round;
9
-
10
- this.autoHeight = true;
11
-
12
- this.baseH = this.h;
13
- this.hplus = 50;
14
-
15
- this.res = o.res || 40;
16
- this.l = 1;
17
-
18
- this.pa1 = [];
19
- this.pa2 = [];
20
- this.pa3 = [];
21
-
22
- var i = this.res+1;
23
- while(i--){
24
- this.pa1.push(50);
25
- this.pa2.push(50);
26
- this.pa3.push(50);
27
- }
28
-
29
- var fltop = Math.floor(this.h*0.5)-6;
30
-
31
- this.c[1].textContent = 'FPS';
32
- this.c[0].style.cursor = 'pointer';
33
- this.c[0].style.pointerEvents = 'auto';
34
-
35
- var panelCss = 'display:none; left:10px; top:'+ this.h + 'px; height:'+(this.hplus - 8)+'px; background: rgba(0, 0, 0, 0.2);' + 'border:1px solid rgba(255, 255, 255, 0.2); ';
36
-
37
- this.c[2] = Tools.dom( 'path', Tools.css.basic + panelCss , { fill:'rgba(200,200,200,0.3)', 'stroke-width':1, stroke:this.fontColor, 'vector-effect':'non-scaling-stroke' });
38
-
39
- this.c[2].setAttribute('viewBox', '0 0 '+this.res+' 42' );
40
- this.c[2].setAttribute('height', '100%' );
41
- this.c[2].setAttribute('width', '100%' );
42
- this.c[2].setAttribute('preserveAspectRatio', 'none' );
43
-
44
- Tools.dom( 'path', null, { fill:'rgba(255,255,0,0.3)', 'stroke-width':1, stroke:'#FF0', 'vector-effect':'non-scaling-stroke' }, this.c[2] );
45
- Tools.dom( 'path', null, { fill:'rgba(0,255,255,0.3)', 'stroke-width':1, stroke:'#0FF', 'vector-effect':'non-scaling-stroke' }, this.c[2] );
46
-
47
-
48
- // bottom line
49
- this.c[3] = Tools.dom( 'div', Tools.css.basic + 'width:100%; bottom:0px; height:1px; background: rgba(255, 255, 255, 0.2);');
50
-
51
- this.c[4] = Tools.dom( 'path', Tools.css.basic + 'position:absolute; width:10px; height:10px; left:4px; top:'+fltop+'px;', { d:'M 3 8 L 8 5 3 2 3 8 Z', fill:this.fontColor, stroke:'none'});
52
-
53
- this.isShow = o.show || false;
54
-
55
- this.c[1].style.marginLeft = '10px';
56
-
57
- this.now = ( self.performance && self.performance.now ) ? self.performance.now.bind( performance ) : Date.now;
58
- this.startTime = this.now()
59
- this.prevTime = this.startTime;
60
- this.frames = 0
61
-
62
- this.isMem = false;
63
-
64
- this.ms = 0;
65
- this.fps = 0;
66
- this.mem = 0;
67
- this.mm = 0;
68
-
69
- if ( self.performance && self.performance.memory ) this.isMem = true;
70
-
71
- this.c[0].events = [ 'click', 'mousedown', 'mouseover', 'mouseout' ];
72
-
73
- this.init();
74
-
75
- //if( this.isShow ) this.show();
76
-
77
- }
78
-
79
- Fps.prototype = Object.create( Proto.prototype );
80
- Fps.prototype.constructor = Fps;
81
-
82
- Fps.prototype.handleEvent = function( e ) {
83
-
84
- e.preventDefault();
85
- switch( e.type ) {
86
- case 'click': this.click(e); break;
87
- case 'mouseover': this.mode(1); break;
88
- case 'mousedown': this.mode(2); break;
89
- case 'mouseout': this.mode(0); break;
90
- }
91
-
92
- }
93
-
94
- Fps.prototype.click = function( e ){
95
-
96
- if( this.isShow ) this.hide();
97
- else this.show();
98
-
99
- };
100
-
101
- Fps.prototype.mode = function( mode ){
102
-
103
- var s = this.s;
104
-
105
- switch(mode){
106
- case 0: // base
107
- s[1].color = this.fontColor;
108
- //s[1].background = 'none';
109
- break;
110
- case 1: // over
111
- s[1].color = '#FFF';
112
- //s[1].background = UIL.SELECT;
113
- break;
114
- case 2: // edit / down
115
- s[1].color = this.fontColor;
116
- //s[1].background = UIL.SELECTDOWN;
117
- break;
118
-
119
- }
120
- }
121
-
122
- Fps.prototype.makePath = function ( point ) {
123
-
124
- var p = '';
125
- p += 'M ' + (-1) + ' ' + 50;
126
- for ( var i = 0; i < this.res + 1; i ++ ) { p += ' L ' + i + ' ' + point[i]; }
127
- p += ' L ' + (this.res + 1) + ' ' + 50;
128
-
129
- return p;
130
-
131
- };
132
-
133
- Fps.prototype.drawGraph = function( ){
134
-
135
- var svg = this.c[2];
136
-
137
- this.pa1.shift();
138
- this.pa1.push( 8.5 + this.round( ( 1 - (this.fps / 100)) * 30 ) );
139
-
140
- Tools.setSvg( svg, 'd', this.makePath( this.pa1 ), 0 );
141
-
142
- this.pa2.shift();
143
- this.pa2.push( 8.5 + this.round( ( 1 - (this.ms / 200)) * 30 ) );
144
-
145
- Tools.setSvg( svg, 'd', this.makePath( this.pa2 ), 1 );
146
-
147
- if ( this.isMem ) {
148
-
149
- this.pa3.shift();
150
- this.pa3.push( 8.5 + this.round( ( 1 - this.mm) * 30 ) );
151
-
152
- Tools.setSvg( svg, 'd', this.makePath( this.pa3 ), 2 );
153
-
154
- }
155
-
156
- }
157
-
158
-
159
- Fps.prototype.show = function(){
160
-
161
- this.h = this.hplus + this.baseH;
162
-
163
- Tools.setSvg( this.c[4], 'd','M 5 8 L 8 3 2 3 5 8 Z');
164
-
165
-
166
- if( this.parentGroup !== null ){ this.parentGroup.calc( this.hplus );}
167
- else if( this.isUI ) this.main.calc( this.hplus );
168
-
169
- this.s[0].height = this.h +'px';
170
- this.s[2].display = 'block';
171
- this.isShow = true;
172
-
173
- Tools.addListen( this );
174
-
175
- }
176
-
177
- Fps.prototype.hide = function(){
178
-
179
- this.h = this.baseH;
180
-
181
- Tools.setSvg( this.c[4], 'd','M 3 8 L 8 5 3 2 3 8 Z');
182
-
183
- if( this.parentGroup !== null ){ this.parentGroup.calc( -this.hplus );}
184
- else if( this.isUI ) this.main.calc( -this.hplus );
185
-
186
- this.s[0].height = this.h +'px';
187
- this.s[2].display = 'none';
188
- this.isShow = false;
189
-
190
- Tools.removeListen( this );
191
- this.c[1].textContent = 'FPS';
192
-
193
- }
194
-
195
- Fps.prototype.rSize = function(){
196
-
197
- this.s[0].width = this.width + 'px';
198
- this.s[1].width = this.width + 'px';
199
- this.s[2].left = 10 + 'px';
200
- this.s[2].width = (this.width-20) + 'px';
201
-
202
- }
203
-
204
- //////////////////
205
-
206
- Fps.prototype.begin = function(){
207
-
208
- this.startTime = this.now();
209
-
210
- }
211
-
212
- Fps.prototype.end = function(){
213
-
214
-
215
- var time = this.now();
216
- this.ms = time - this.startTime;
217
-
218
- this.frames ++;
219
-
220
- if ( time > this.prevTime + 1000 ) {
221
-
222
- this.fps = this.round( ( this.frames * 1000 ) / ( time - this.prevTime ) );
223
-
224
- this.prevTime = time;
225
- this.frames = 0;
226
-
227
- if ( this.isMem ) {
228
-
229
- var heapSize = performance.memory.usedJSHeapSize;
230
- var heapSizeLimit = performance.memory.jsHeapSizeLimit;
231
-
232
- this.mem = this.round( heapSize * 0.000000954 );
233
-
234
- this.mm = heapSize / heapSizeLimit;
235
-
236
- }
237
-
238
- }
239
-
240
- this.drawGraph();
241
- this.c[1].innerHTML = 'FPS ' + this.fps + '<font color="yellow"> MS '+ ( this.ms | 0 ) + '</font><font color="cyan"> MB '+ this.mem + '</font>';
242
-
243
- return time;
244
-
245
-
246
- }
247
-
248
- Fps.prototype.listening = function(){
249
-
250
- this.startTime = this.end();
251
-
252
- }
253
-
254
- export { Fps };