uil 4.0.9 → 4.2.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <p align="center"><a href="http://lo-th.github.io/uil/"><img src="http://lo-th.github.io/uil/examples/assets/uil.jpg"/></a><br>UIL v4.0.9</p>
1
+ <p align="center"><a href="http://lo-th.github.io/uil/"><img src="http://lo-th.github.io/uil/examples/assets/uil.jpg"/></a><br>UIL v4.2.0</p>
2
2
 
3
3
  uil.js is a lightweight ui for javascript with a complete 3d display support.<br>
4
4
  totally customizable, only 6 events, auto resize<br>
package/build/uil.js CHANGED
@@ -21,6 +21,7 @@
21
21
  wlock: false,
22
22
  current: -1,
23
23
  needReZone: true,
24
+ needResize: false,
24
25
  isEventsInit: false,
25
26
  isLeave: false,
26
27
  downTime: 0,
@@ -133,7 +134,6 @@
133
134
  R.isEventsInit = false;
134
135
  },
135
136
  resize: function () {
136
- R.needReZone = true;
137
137
  let i = R.ui.length,
138
138
  u;
139
139
 
@@ -141,6 +141,9 @@
141
141
  u = R.ui[i];
142
142
  if (u.isGui && !u.isCanvasOnly && u.autoResize) u.calc();
143
143
  }
144
+
145
+ R.needReZone = true;
146
+ R.needResize = false;
144
147
  },
145
148
  out: function () {
146
149
  console.log('im am out');
@@ -160,6 +163,7 @@
160
163
  handleEvent: function (event) {
161
164
  //if(!event.type) return;
162
165
  if (R.prevDefault.indexOf(event.type) !== -1) event.preventDefault();
166
+ if (R.needResize) R.resize();
163
167
  R.findZone();
164
168
  let e = R.e;
165
169
  let leave = false;
@@ -759,11 +763,13 @@
759
763
  select: '#308AFF',
760
764
  action: '#FF3300',
761
765
  //fontFamily: 'Tahoma',
762
- fontFamily: 'Consolas,monaco,monospace',
766
+ fontFamily: 'Consolas, monaco, monospace',
767
+ //fontFamily: "'Roboto Mono', 'Source Code Pro', Menlo, Courier, monospace",
763
768
  fontWeight: 'normal',
764
- fontShadow: '#000',
769
+ fontShadow: 'none',
770
+ //'#000',
765
771
  fontSize: 12,
766
- radius: 4,
772
+ radius: 2,
767
773
  hide: 'rgba(0,0,0,0)'
768
774
  },
769
775
  // style css
@@ -796,8 +802,14 @@
796
802
  texture: 'M 13 4 L 13 1 1 1 1 4 5 4 5 13 9 13 9 4 13 4 Z',
797
803
  object: 'M 10 1 L 7 4 4 1 1 1 1 13 4 13 4 5 7 8 10 5 10 13 13 13 13 1 10 1 Z',
798
804
  none: 'M 9 5 L 5 5 5 9 9 9 9 5 Z',
799
- cursor: 'M 4 7 L 1 10 1 12 2 13 4 13 7 10 9 14 14 0 0 5 4 7 Z'
805
+ cursor: 'M 4 7 L 1 10 1 12 2 13 4 13 7 10 9 14 14 0 0 5 4 7 Z',
806
+ load: 'M 14 8 L 12 8 12 12 2 12 2 8 0 8 0 14 14 14 14 8 M 8 5 L 8 0 6 0 6 5 3 5 7 9 11 5 8 5 Z'
807
+ },
808
+
809
+ rezone() {
810
+ Roots.needReZone = true;
800
811
  },
812
+
801
813
  getImput: function () {
802
814
  return Roots.input ? true : false;
803
815
  },
@@ -821,12 +833,18 @@
821
833
  if (shadow === undefined) shadow = cc.fontShadow;
822
834
  if (weight === undefined) weight = cc.fontWeight;
823
835
  if (color === undefined) color = cc.text;
836
+
837
+ if (isNaN(size)) {
838
+ if (size.search('em') === -1) size += 'px';
839
+ } else size += 'px';
840
+
824
841
  let align = 'display:flex; justify-content:left; align-items:center; text-align:left;';
825
- T.css.txt = T.css.basic + align + 'font-family:' + font + '; font-weight:' + weight + '; font-size:' + size + 'px; color:' + cc.text + '; padding:0px 10px; left:0; top:2px; height:16px; width:100px; overflow:hidden; white-space: nowrap;';
842
+ T.css.txt = T.css.basic + align + ' font-family:' + font + '; font-weight:' + weight + '; font-size:' + size + '; color:' + cc.text + '; padding:0px 10px; left:0; top:2px; height:16px; width:100px; overflow:hidden; white-space: nowrap; letter-spacing: normal;';
826
843
  if (shadow !== 'none') T.css.txt += ' text-shadow: 1px 1px 1px ' + shadow + ';';
827
844
  T.css.txtselect = T.css.txt + 'padding:0px 4px; border:1px dashed ' + cc.border + ';'; //T.css.item = T.css.txt + ' position:relative; margin-bottom:1px; '//display:block; padding:4px 4px;';//
828
845
 
829
846
  T.css.item = T.css.txt + ' position:relative; margin-bottom:1px; display:block; padding:2px 4px;'; //
847
+ //console.log( T.css.txt )
830
848
  },
831
849
  // note
832
850
  //https://developer.mozilla.org/fr/docs/Web/CSS/css_flexible_box_layout/aligning_items_in_a_flex_container
@@ -1572,7 +1590,7 @@
1572
1590
  let t = [];
1573
1591
 
1574
1592
  switch (type) {
1575
- case 'json':
1593
+ case 'svg':
1576
1594
  t = [{
1577
1595
  accept: {
1578
1596
  'image/svg+xml': '.svg'
@@ -1643,20 +1661,29 @@
1643
1661
  reader.onload = function (e) {
1644
1662
  let content = e.target.result;
1645
1663
 
1646
- if (type === 'image') {
1647
- var img = new Image();
1664
+ switch (type) {
1665
+ case 'image':
1666
+ let img = new Image();
1648
1667
 
1649
- img.onload = function () {
1650
- if (o.callback) o.callback(img, fname);
1651
- };
1668
+ img.onload = function () {
1669
+ if (o.callback) o.callback(img, fname);
1670
+ };
1652
1671
 
1653
- img.src = content;
1654
- } else {
1655
- if (o.callback) o.callback(content, fname);
1672
+ img.src = content;
1673
+ break;
1674
+
1675
+ case 'json':
1676
+ if (o.callback) o.callback(JSON.parse(content), fname);
1677
+ break;
1678
+
1679
+ default:
1680
+ if (o.callback) o.callback(content, fname);
1681
+ break;
1656
1682
  }
1657
1683
  };
1658
1684
  } catch (e) {
1659
1685
  console.log(e);
1686
+ if (o.callback) o.callback(null);
1660
1687
  }
1661
1688
  }
1662
1689
 
@@ -1705,7 +1732,7 @@
1705
1732
 
1706
1733
  const file = await handle.createWritable();
1707
1734
  let blob = new Blob([options.data], {
1708
- type: option.finalType
1735
+ type: options.finalType
1709
1736
  }); // write our file
1710
1737
 
1711
1738
  await file.write(blob); // close the file and write the contents to disk.
@@ -1919,7 +1946,7 @@
1919
1946
 
1920
1947
  this.objectLink = null;
1921
1948
  this.isSend = false;
1922
- this.val = null;
1949
+ this.objectKey = null;
1923
1950
  this.txt = o.name || '';
1924
1951
  this.name = o.rename || this.txt;
1925
1952
  this.target = o.target || null; // callback
@@ -2022,7 +2049,9 @@
2022
2049
  this.c[0].style.pointerEvents = 'auto';
2023
2050
  Roots.add(this);
2024
2051
  }
2052
+ }
2025
2053
 
2054
+ addTransition() {
2026
2055
  if (this.baseH && this.transition && this.isUI) {
2027
2056
  this.c[0].style.transition = 'height ' + this.transition + 's ease-out';
2028
2057
  }
@@ -2108,7 +2137,7 @@
2108
2137
  if (this.objectLink === null) return;
2109
2138
  if (this.isSend) return;
2110
2139
  if (this.isEdit) return;
2111
- this.setValue(this.objectLink[this.val]);
2140
+ this.setValue(this.objectLink[this.objectKey]);
2112
2141
  }
2113
2142
 
2114
2143
  setValue(v) {
@@ -2156,8 +2185,8 @@
2156
2185
  v = v || this.value;
2157
2186
  if (v instanceof Array && v.length === 1) v = v[0];
2158
2187
  this.isSend = true;
2159
- if (this.objectLink !== null) this.objectLink[this.val] = v;
2160
- if (this.callback) this.callback(v, this.val);
2188
+ if (this.objectLink !== null) this.objectLink[this.objectKey] = v;
2189
+ if (this.callback) this.callback(v, this.objectKey);
2161
2190
  this.isSend = false;
2162
2191
  }
2163
2192
 
@@ -2165,7 +2194,7 @@
2165
2194
  v = v || this.value;
2166
2195
  if (v instanceof Array && v.length === 1) v = v[0];
2167
2196
  if (this.endCallback) this.endCallback(v);
2168
- if (this.objectLink !== null) this.objectLink[this.val] = v;
2197
+ if (this.objectLink !== null) this.objectLink[this.objectKey] = v;
2169
2198
  } // ----------------------
2170
2199
  // clear node
2171
2200
  // ----------------------
@@ -2307,9 +2336,9 @@
2307
2336
  // ----------------------
2308
2337
 
2309
2338
 
2310
- setReferency(obj, val) {
2339
+ setReferency(obj, key) {
2311
2340
  this.objectLink = obj;
2312
- this.val = val;
2341
+ this.objectKey = key;
2313
2342
  }
2314
2343
 
2315
2344
  display(v = false) {
@@ -2322,12 +2351,14 @@
2322
2351
  open() {
2323
2352
  if (this.isOpen) return;
2324
2353
  this.isOpen = true;
2354
+ Roots.needResize = true;
2325
2355
  if (this.openCallback) this.openCallback();
2326
2356
  }
2327
2357
 
2328
2358
  close() {
2329
2359
  if (!this.isOpen) return;
2330
2360
  this.isOpen = false;
2361
+ Roots.needResize = true;
2331
2362
  if (this.closeCallback) this.closeCallback();
2332
2363
  }
2333
2364
 
@@ -2542,8 +2573,7 @@
2542
2573
 
2543
2574
  if (!o.value && !o.values) {
2544
2575
  if (this.c[1] !== undefined) {
2545
- this.c[1].textContent = '';
2546
- this.txt = '';
2576
+ this.c[1].textContent = ''; //this.txt = ''
2547
2577
  }
2548
2578
  }
2549
2579
 
@@ -3249,8 +3279,8 @@
3249
3279
  let s = this.s;
3250
3280
  s[1].marginLeft = '10px';
3251
3281
  s[1].lineHeight = this.h - 4;
3252
- s[1].color = this.colors.text;
3253
- s[1].fontWeight = 'bold';
3282
+ s[1].color = this.colors.text; //s[1].fontWeight = 'bold';
3283
+
3254
3284
  if (this.radius !== 0) s[0].borderRadius = this.radius + 'px';
3255
3285
  if (this.colors.gborder !== 'none') s[0].border = '1px solid ' + this.colors.gborder;
3256
3286
  let j = 0;
@@ -3750,8 +3780,8 @@
3750
3780
  this.c[1].name = 'group';
3751
3781
  s[1].marginLeft = 10 + this.decal + 'px';
3752
3782
  s[1].lineHeight = this.h - 4;
3753
- s[1].color = this.colors.text;
3754
- s[1].fontWeight = 'bold';
3783
+ s[1].color = this.colors.text; //s[1].fontWeight = 'bold';
3784
+
3755
3785
  if (this.radius !== 0) s[0].borderRadius = this.radius + 'px';
3756
3786
  this.init();
3757
3787
  this.setBG(o.bg);
@@ -5249,17 +5279,13 @@
5249
5279
 
5250
5280
  if (this.objectLink !== null) {
5251
5281
  if (this.isVector) {
5252
- this.objectLink[this.val].fromArray(v);
5253
- /*this.objectLink[ this.val ].x = v[0];
5254
- this.objectLink[ this.val ].y = v[1];
5255
- this.objectLink[ this.val ].z = v[2];
5256
- if( v[3] ) this.objectLink[ this.val ].w = v[3];*/
5282
+ this.objectLink[this.objectKey].fromArray(v);
5257
5283
  } else {
5258
- this.objectLink[this.val] = v;
5284
+ this.objectLink[this.objectKey] = v;
5259
5285
  }
5260
5286
  }
5261
5287
 
5262
- if (this.callback) this.callback(v, this.val);
5288
+ if (this.callback) this.callback(v, this.objectKey);
5263
5289
  this.isSend = false;
5264
5290
  } // ----------------------
5265
5291
  // INPUT
@@ -5544,7 +5570,7 @@
5544
5570
  constructor(o = {}) {
5545
5571
  super(o);
5546
5572
  this.cmode = 0;
5547
- this.value = o.value || '';
5573
+ this.value = o.value !== undefined ? o.value : '';
5548
5574
  this.placeHolder = o.placeHolder || '';
5549
5575
  this.allway = o.allway || false;
5550
5576
  this.editable = o.edit !== undefined ? o.edit : true;
@@ -5711,17 +5737,18 @@
5711
5737
  this.value = o.value || '';
5712
5738
  this.isDown = false;
5713
5739
 
5714
- this.onActif = o.onActif || function () {};
5740
+ this.onActif = o.onActif || function () {}; //let prefix = o.prefix || '';
5741
+
5742
+
5743
+ const cc = this.colors;
5744
+ this.c[2] = this.dom('div', this.css.txt + this.css.button + ' top:1px; background:' + cc.button + '; height:' + (this.h - 2) + 'px; border:' + cc.buttonBorder + '; border-radius:15px; width:30px; left:10px;'); //this.c[2].style.color = this.fontColor;
5715
5745
 
5716
- o.prefix || '';
5717
- this.c[2] = this.dom('div', this.css.txt + this.css.button + ' top:1px; background:' + this.colors.button + '; height:' + (this.h - 2) + 'px; border:' + this.colors.buttonBorder + '; border-radius:15px; width:30px; left:10px;');
5718
- this.c[2].style.color = this.fontColor;
5719
- this.c[3] = this.dom('div', this.css.txtselect + 'height:' + (this.h - 4) + 'px; background:' + this.colors.inputBg + '; borderColor:' + this.colors.inputBorder + '; border-radius:' + this.radius + 'px;');
5746
+ this.c[3] = this.dom('div', this.css.txtselect + 'height:' + (this.h - 4) + 'px; background:' + cc.inputBg + '; borderColor:' + cc.inputBorder + '; border-radius:' + this.radius + 'px;');
5720
5747
  this.c[3].textContent = this.value;
5721
5748
  let fltop = Math.floor(this.h * 0.5) - 7;
5722
5749
  this.c[4] = this.dom('path', this.css.basic + 'position:absolute; width:14px; height:14px; left:5px; top:' + fltop + 'px;', {
5723
5750
  d: this.svgs['cursor'],
5724
- fill: this.fontColor,
5751
+ fill: cc.text,
5725
5752
  stroke: 'none'
5726
5753
  });
5727
5754
  this.stat = 1;
@@ -5820,13 +5847,13 @@
5820
5847
 
5821
5848
  case 2:
5822
5849
  this.s[2].color = cc.textOver;
5823
- this.s[2].background = cc.over;
5850
+ this.s[2].background = cc.overoff;
5824
5851
  break;
5825
5852
  // over
5826
5853
 
5827
5854
  case 3:
5828
- this.s[2].color = cc.textSelect;
5829
- this.s[2].background = cc.select;
5855
+ this.s[2].color = cc.textOver;
5856
+ this.s[2].background = cc.action;
5830
5857
  break;
5831
5858
  // down
5832
5859
 
@@ -5863,6 +5890,177 @@
5863
5890
 
5864
5891
  }
5865
5892
 
5893
+ class Bitmap extends Proto {
5894
+ constructor(o = {}) {
5895
+ super(o);
5896
+ this.value = o.value || '';
5897
+ this.refTexture = o.texture || null;
5898
+ this.img = null;
5899
+ this.isDown = false;
5900
+ this.neverlock = true;
5901
+ const cc = this.colors;
5902
+ this.c[2] = this.dom('div', this.css.txt + this.css.button + ' top:1px; background:' + cc.button + '; height:' + (this.h - 2) + 'px; border:' + cc.buttonBorder + '; border-radius:15px; width:30px; left:10px;');
5903
+ this.c[3] = this.dom('div', this.css.txtselect + 'height:' + (this.h - 4) + 'px; background:' + cc.inputBg + '; borderColor:' + cc.inputBorder + '; border-radius:' + this.radius + 'px;');
5904
+ this.c[3].textContent = this.value;
5905
+ let fltop = Math.floor(this.h * 0.5) - 7;
5906
+ this.c[4] = this.dom('path', this.css.basic + 'position:absolute; width:14px; height:14px; left:5px; top:' + fltop + 'px;', {
5907
+ d: this.svgs['load'],
5908
+ fill: cc.text,
5909
+ stroke: 'none'
5910
+ });
5911
+ this.stat = 1;
5912
+ this.init();
5913
+ }
5914
+
5915
+ testZone(e) {
5916
+ let l = this.local;
5917
+ if (l.x === -1 && l.y === -1) return '';
5918
+ if (l.x > this.sa && l.x < this.sa + 30) return 'over';
5919
+ return '0';
5920
+ } // ----------------------
5921
+ // EVENTS
5922
+ // ----------------------
5923
+
5924
+
5925
+ mouseup(e) {
5926
+ if (this.isDown) {
5927
+ //this.value = false;
5928
+ this.isDown = false; //this.send();
5929
+
5930
+ return this.mousemove(e);
5931
+ }
5932
+
5933
+ return false;
5934
+ }
5935
+
5936
+ mousedown(e) {
5937
+ let name = this.testZone(e);
5938
+ if (!name) return false;
5939
+
5940
+ if (name === 'over') {
5941
+ this.isDown = true;
5942
+ Files.load({
5943
+ callback: this.changeBitmap.bind(this)
5944
+ });
5945
+ } //this.value = this.values[ name-2 ];
5946
+ //this.send();
5947
+
5948
+
5949
+ return this.mousemove(e);
5950
+ }
5951
+
5952
+ mousemove(e) {
5953
+ let up = false;
5954
+ let name = this.testZone(e); //let sel = false;
5955
+ //console.log(name)
5956
+
5957
+ if (name === 'over') {
5958
+ this.cursor('pointer');
5959
+ up = this.mode(this.isDown ? 3 : 2);
5960
+ } else {
5961
+ up = this.reset();
5962
+ }
5963
+
5964
+ return up;
5965
+ } // ----------------------
5966
+
5967
+
5968
+ changeBitmap(img, fname) {
5969
+ if (img) {
5970
+ this.img = img;
5971
+ this.apply(fname);
5972
+ } else {
5973
+ this.img = null;
5974
+ this.apply('null');
5975
+ }
5976
+ } // ----------------------
5977
+
5978
+
5979
+ apply(v) {
5980
+ v = v || '';
5981
+
5982
+ if (v !== this.value) {
5983
+ this.value = v;
5984
+ this.c[3].textContent = this.value;
5985
+
5986
+ if (this.img !== null) {
5987
+ if (this.objectLink !== null) this.objectLink[this.val] = v;
5988
+ if (this.callback) this.callback(v, this.img, this.name);
5989
+ }
5990
+ }
5991
+
5992
+ this.mode(1);
5993
+ }
5994
+
5995
+ update() {
5996
+ this.mode(3);
5997
+ }
5998
+
5999
+ mode(n) {
6000
+ let change = false;
6001
+ let cc = this.colors;
6002
+
6003
+ if (this.stat !== n) {
6004
+ /*if( n===1 ) this.isActif = false
6005
+ if( n===3 ){
6006
+ if( !this.isActif ){ this.isActif = true; n=4; this.onActif( this ); }
6007
+ else { this.isActif = false; }
6008
+ }
6009
+ if( n===2 && this.isActif ) n = 4;*/
6010
+ this.stat = n;
6011
+
6012
+ switch (n) {
6013
+ case 1:
6014
+ this.s[2].color = cc.text;
6015
+ this.s[2].background = cc.button;
6016
+ break;
6017
+ // base
6018
+
6019
+ case 2:
6020
+ this.s[2].color = cc.textOver;
6021
+ this.s[2].background = cc.overoff;
6022
+ break;
6023
+ // over
6024
+
6025
+ case 3:
6026
+ this.s[2].color = cc.textOver;
6027
+ this.s[2].background = cc.over;
6028
+ break;
6029
+ // down
6030
+
6031
+ case 4:
6032
+ this.s[2].color = cc.textSelect;
6033
+ this.s[2].background = cc.select;
6034
+ break;
6035
+ // actif
6036
+ }
6037
+
6038
+ change = true;
6039
+ }
6040
+
6041
+ return change;
6042
+ }
6043
+
6044
+ reset() {
6045
+ this.cursor();
6046
+ return this.mode(this.isActif ? 4 : 1);
6047
+ }
6048
+
6049
+ text(txt) {
6050
+ this.c[3].textContent = txt;
6051
+ }
6052
+
6053
+ rSize() {
6054
+ super.rSize();
6055
+ let s = this.s;
6056
+ s[2].left = this.sa + 'px';
6057
+ s[3].left = this.sa + 40 + 'px';
6058
+ s[3].width = this.sb - 40 + 'px';
6059
+ s[4].left = this.sa + 8 + 'px';
6060
+ }
6061
+
6062
+ }
6063
+
5866
6064
  //import { Proto } from '../core/Proto.js';
5867
6065
  class Selector extends Button {
5868
6066
  constructor(o = {}) {
@@ -6518,6 +6716,10 @@
6518
6716
  n = new Select(o);
6519
6717
  break;
6520
6718
 
6719
+ case 'bitmap':
6720
+ n = new Bitmap(o);
6721
+ break;
6722
+
6521
6723
  case 'selector':
6522
6724
  n = new Selector(o);
6523
6725
  break;
@@ -6542,6 +6744,7 @@
6542
6744
  }
6543
6745
 
6544
6746
  if (n !== null) {
6747
+ Roots.needResize = true;
6545
6748
  if (ref) n.setReferency(a[0], a[1]);
6546
6749
  return n;
6547
6750
  }
@@ -6670,7 +6873,7 @@
6670
6873
 
6671
6874
 
6672
6875
  this.transition = o.transition || Tools.transition;
6673
- if (this.transition) setTimeout(this.addTransition.bind(this), 0);
6876
+ if (this.transition) setTimeout(this.addTransition.bind(this), 1000);
6674
6877
  this.setWidth();
6675
6878
  if (this.isCanvas) this.makeCanvas();
6676
6879
  Roots.add(this);
@@ -6689,6 +6892,10 @@
6689
6892
  this.content.style.transition = 'height ' + this.transition + 's ease-out';
6690
6893
  this.bottom.style.transition = 'top ' + this.transition + 's ease-out'; //this.bottom.addEventListener("transitionend", Roots.resize, true);
6691
6894
  }
6895
+
6896
+ let i = this.uis.length;
6897
+
6898
+ while (i--) this.uis[i].addTransition();
6692
6899
  } // ----------------------
6693
6900
  // CANVAS
6694
6901
  // ----------------------
@@ -7123,7 +7330,7 @@
7123
7330
 
7124
7331
  }
7125
7332
 
7126
- const REVISION = '4.0.9';
7333
+ const REVISION = '4.2.1';
7127
7334
 
7128
7335
  exports.Files = Files;
7129
7336
  exports.Gui = Gui;