uil 4.0.2 → 4.0.7

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</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.0.7</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>
@@ -55,3 +55,7 @@ ui.clear();
55
55
  [**uil to three**](http://lo-th.github.io/uil/examples/uil_3d.html)
56
56
 
57
57
  [**uil to three 2**](http://lo-th.github.io/uil/examples/uil_3d_2.html)
58
+
59
+ **7 - uil is on npm**
60
+ ```sh
61
+ npm i uil
package/build/uil.js CHANGED
@@ -305,7 +305,9 @@
305
305
  u.zone.x = zone.x + px;
306
306
  u.zone.y = py;
307
307
  tw = R.getWidth(u);
308
- if (tw) u.zone.w = u.w = tw; //console.log( u.name, u.zone.w, u.w, zone )
308
+ if (tw) u.zone.w = u.w = tw; // focrce width if content is canvas
309
+ else if (u.fw) u.zone.w = u.w = u.fw; //console.log( u.name, u.zone.w, u.w, zone, tw )
310
+ //console.log( tw )
309
311
 
310
312
  px += u.zone.w;
311
313
 
@@ -359,7 +361,8 @@
359
361
  return over;
360
362
  },
361
363
  getWidth: function (o) {
362
- return o.getDom().offsetWidth; //let r = o.getDom().getBoundingClientRect();
364
+ //return o.getDom().offsetWidth
365
+ return o.getDom().clientWidth; //let r = o.getDom().getBoundingClientRect();
363
366
  //return (r.width)
364
367
  //return Math.floor(r.width)
365
368
  },
@@ -1540,6 +1543,196 @@
1540
1543
  T.setText();
1541
1544
  const Tools = T;
1542
1545
 
1546
+ ///https://wicg.github.io/file-system-access/#api-filesystemfilehandle-getfile
1547
+ class Files {
1548
+ //-----------------------------
1549
+ // FILE TYPE
1550
+ //-----------------------------
1551
+ static autoTypes(type) {
1552
+ let t = [];
1553
+
1554
+ switch (type) {
1555
+ case 'json':
1556
+ t = [{
1557
+ accept: {
1558
+ 'image/svg+xml': '.svg'
1559
+ }
1560
+ }];
1561
+ break;
1562
+
1563
+ case 'text':
1564
+ t = [{
1565
+ description: 'Text Files',
1566
+ accept: {
1567
+ 'text/plain': ['.txt', '.text'],
1568
+ 'text/html': ['.html', '.htm']
1569
+ }
1570
+ }];
1571
+ break;
1572
+
1573
+ case 'json':
1574
+ t = [{
1575
+ description: 'JSON Files',
1576
+ accept: {
1577
+ 'text/plain': ['.json']
1578
+ }
1579
+ }];
1580
+ break;
1581
+
1582
+ case 'image':
1583
+ t = [{
1584
+ description: 'Images',
1585
+ accept: {
1586
+ 'image/*': ['.png', '.gif', '.jpeg', '.jpg']
1587
+ }
1588
+ }];
1589
+ break;
1590
+ }
1591
+
1592
+ return t;
1593
+ } //-----------------------------
1594
+ // LOAD
1595
+ //-----------------------------
1596
+
1597
+
1598
+ static async load(o = {}) {
1599
+ if (typeof window.showOpenFilePicker !== 'function') {
1600
+ window.showOpenFilePicker = this.showOpenFilePickerPolyfill;
1601
+ }
1602
+
1603
+ try {
1604
+ let type = o.type || '';
1605
+ const options = {
1606
+ excludeAcceptAllOption: type ? true : false,
1607
+ multiple: false //startIn:'./assets'
1608
+
1609
+ };
1610
+ options.types = this.autoTypes(type); // create a new handle
1611
+
1612
+ const handle = await window.showOpenFilePicker(options);
1613
+ const file = await handle[0].getFile(); //let content = await file.text()
1614
+
1615
+ if (!file) return null;
1616
+ let fname = file.name;
1617
+ let ftype = fname.substring(fname.lastIndexOf('.') + 1, fname.length);
1618
+ const dataUrl = ['png', 'jpg', 'jpeg', 'mp4', 'webm', 'ogg', 'mp3'];
1619
+ const dataBuf = ['sea', 'z', 'hex', 'bvh', 'BVH', 'glb', 'gltf'];
1620
+ const reader = new FileReader();
1621
+ if (dataUrl.indexOf(ftype) !== -1) reader.readAsDataURL(file);else if (dataBuf.indexOf(ftype) !== -1) reader.readAsArrayBuffer(file);else reader.readAsText(file);
1622
+
1623
+ reader.onload = function (e) {
1624
+ let content = e.target.result;
1625
+
1626
+ if (type === 'image') {
1627
+ var img = new Image();
1628
+
1629
+ img.onload = function () {
1630
+ if (o.callback) o.callback(img, fname);
1631
+ };
1632
+
1633
+ img.src = content;
1634
+ } else {
1635
+ if (o.callback) o.callback(content, fname);
1636
+ }
1637
+ };
1638
+ } catch (e) {
1639
+ console.log(e);
1640
+ }
1641
+ }
1642
+
1643
+ static showOpenFilePickerPolyfill(options) {
1644
+ return new Promise(resolve => {
1645
+ const input = document.createElement("input");
1646
+ input.type = "file";
1647
+ input.multiple = options.multiple;
1648
+ input.accept = options.types.map(type => type.accept).flatMap(inst => Object.keys(inst).flatMap(key => inst[key])).join(",");
1649
+ input.addEventListener("change", () => {
1650
+ resolve([...input.files].map(file => {
1651
+ return {
1652
+ getFile: async () => new Promise(resolve => {
1653
+ resolve(file);
1654
+ })
1655
+ };
1656
+ }));
1657
+ });
1658
+ input.click();
1659
+ });
1660
+ } //-----------------------------
1661
+ // SAVE
1662
+ //-----------------------------
1663
+
1664
+
1665
+ static async save(o = {}) {
1666
+ this.usePoly = false;
1667
+
1668
+ if (typeof window.showSaveFilePicker !== 'function') {
1669
+ window.showSaveFilePicker = this.showSaveFilePickerPolyfill;
1670
+ this.usePoly = true;
1671
+ }
1672
+
1673
+ try {
1674
+ let type = o.type || '';
1675
+ const options = {
1676
+ suggestedName: o.name || 'hello',
1677
+ data: o.data || ''
1678
+ };
1679
+ options.types = this.autoTypes(type);
1680
+ options.finalType = Object.keys(options.types[0].accept)[0];
1681
+ options.suggestedName += options.types[0].accept[options.finalType][0]; // create a new handle
1682
+
1683
+ const handle = await window.showSaveFilePicker(options);
1684
+ if (this.usePoly) return; // create a FileSystemWritableFileStream to write to
1685
+
1686
+ const file = await handle.createWritable();
1687
+ let blob = new Blob([options.data], {
1688
+ type: option.finalType
1689
+ }); // write our file
1690
+
1691
+ await file.write(blob); // close the file and write the contents to disk.
1692
+
1693
+ await file.close();
1694
+ } catch (e) {
1695
+ console.log(e);
1696
+ }
1697
+ }
1698
+
1699
+ static showSaveFilePickerPolyfill(options) {
1700
+ return new Promise(resolve => {
1701
+ const a = document.createElement("a");
1702
+ a.download = options.suggestedName || "my-file.txt";
1703
+ let blob = new Blob([options.data], {
1704
+ type: options.finalType
1705
+ });
1706
+ a.href = URL.createObjectURL(blob);
1707
+ a.addEventListener("click", () => {
1708
+ resolve(setTimeout(() => URL.revokeObjectURL(a.href), 1000));
1709
+ });
1710
+ a.click();
1711
+ });
1712
+ } //-----------------------------
1713
+ // FOLDER not possible in poly
1714
+ //-----------------------------
1715
+
1716
+
1717
+ static async getFolder() {
1718
+ try {
1719
+ const handle = await window.showDirectoryPicker();
1720
+ const files = [];
1721
+
1722
+ for await (const entry of handle.values()) {
1723
+ const file = await entry.getFile();
1724
+ files.push(file);
1725
+ }
1726
+
1727
+ console.log(files);
1728
+ return files;
1729
+ } catch (e) {
1730
+ console.log(e);
1731
+ }
1732
+ }
1733
+
1734
+ }
1735
+
1543
1736
  class V2 {
1544
1737
  constructor(x = 0, y = 0) {
1545
1738
  this.x = x;
@@ -1676,7 +1869,14 @@
1676
1869
  if (o.w !== undefined) this.w = o.w;
1677
1870
  this.h = this.isUI ? this.main.size.h : Tools.size.h;
1678
1871
  if (o.h !== undefined) this.h = o.h;
1679
- if (!this.isSpace) this.h = this.h < 11 ? 11 : this.h;else this.lock = true;
1872
+ if (!this.isSpace) this.h = this.h < 11 ? 11 : this.h;else this.lock = true; // decale for canvas only
1873
+
1874
+ this.fw = o.fw || 0;
1875
+ /*this.dc = 0
1876
+ if(this.isUI){
1877
+ if( this.main.isCanvasOnly && this.fw) this.dc = (this.main.zone.w - this.w)*0.5
1878
+ }*/
1879
+
1680
1880
  this.autoWidth = o.auto || true; // auto width or flex
1681
1881
 
1682
1882
  this.isOpen = false; // open statu
@@ -1961,26 +2161,25 @@
1961
2161
  // ----------------------
1962
2162
 
1963
2163
 
1964
- clear(nofull) {
2164
+ dispose() {
1965
2165
  if (this.isListen) Roots.removeListen(this);
1966
2166
  Tools.clear(this.c[0]);
1967
2167
 
1968
- if (!nofull) {
1969
- if (this.target !== null) {
1970
- if (this.group !== null) this.group.clearOne(this);else this.target.removeChild(this.c[0]);
1971
- } else {
1972
- if (this.isUI) this.main.clearOne(this);else document.body.removeChild(this.c[0]);
1973
- }
1974
-
1975
- if (!this.isUI) Roots.remove(this);
2168
+ if (this.target !== null) {
2169
+ if (this.group !== null) this.group.clearOne(this);else this.target.removeChild(this.c[0]);
2170
+ } else {
2171
+ if (this.isUI) this.main.clearOne(this);else document.body.removeChild(this.c[0]);
1976
2172
  }
1977
2173
 
2174
+ if (!this.isUI) Roots.remove(this);
1978
2175
  this.c = null;
1979
2176
  this.s = null;
1980
2177
  this.callback = null;
1981
2178
  this.target = null;
1982
2179
  this.isListen = false;
1983
- } // ----------------------
2180
+ }
2181
+
2182
+ clear() {} // ----------------------
1984
2183
  // change size
1985
2184
  // ----------------------
1986
2185
 
@@ -2065,6 +2264,7 @@
2065
2264
 
2066
2265
 
2067
2266
  handleEvent(e) {
2267
+ //if(!this.s) return false
2068
2268
  if (this.lock) return;
2069
2269
  if (this.neverlock) Roots.lock = false;
2070
2270
  if (!this[e.type]) return console.error(e.type, 'this type of event no existe !');
@@ -2112,7 +2312,7 @@
2112
2312
 
2113
2313
  display(v) {
2114
2314
  v = v || false;
2115
- this.s[0].display = v ? this.useFlex ? 'flex' : 'block' : 'none';
2315
+ this.s[0].visibility = v ? 'visible' : 'hidden'; //this.s[0].display = v ? (this.useFlex? 'flex':'block') : 'none'
2116
2316
  } // ----------------------
2117
2317
  // resize height
2118
2318
  // ----------------------
@@ -2313,7 +2513,7 @@
2313
2513
  this.value = o.value || '';
2314
2514
  this.values = o.value || this.txt;
2315
2515
  if (o.values) this.values = o.values;
2316
- this.onName = o.onName || '';
2516
+ this.onName = o.onName || null;
2317
2517
  this.on = false;
2318
2518
  this.customSize = o.forceWidth || -1;
2319
2519
  if (typeof this.values === 'string') this.values = [this.values];
@@ -2339,28 +2539,29 @@
2339
2539
  this.stat[i] = sel ? 3 : 1;
2340
2540
  }
2341
2541
 
2342
- if (!o.value || !o.values) {
2343
- if (this.c[1] !== undefined) this.c[1].textContent = '';
2344
- this.p = o.p !== undefined ? o.p : 0;
2345
- } else {
2346
- if (!this.txt) this.p = 0;
2347
- } //
2542
+ if (!o.value && !o.values) {
2543
+ if (this.c[1] !== undefined) {
2544
+ this.txt = '';
2545
+ this.c[1].textContent = '';
2546
+ }
2547
+ }
2348
2548
 
2549
+ if (!this.txt) this.p = 0; //
2349
2550
 
2350
2551
  if (this.isLoadButton) this.initLoader();
2351
2552
 
2352
2553
  if (this.isDragButton) {
2353
2554
  this.lng++;
2354
2555
  this.initDrager();
2355
- }
2556
+ } //if( this.onName !== '' ) this.values[0] = this.on;
2557
+
2356
2558
 
2357
- if (this.onName !== '') this.values[0] = this.on;
2358
2559
  this.init();
2359
2560
  }
2360
2561
 
2361
2562
  onOff() {
2362
2563
  this.on = !this.on;
2363
- this.c[2].innerHTML = this.on ? this.onName : this.txt;
2564
+ this.label(this.on ? this.onName : this.txt);
2364
2565
  }
2365
2566
 
2366
2567
  testZone(e) {
@@ -2385,6 +2586,7 @@
2385
2586
 
2386
2587
  if (this.res !== -1) {
2387
2588
  if (this.value === this.values[this.res] && this.unselectable) this.value = '';else this.value = this.values[this.res];
2589
+ if (this.onName !== null) this.onOff();
2388
2590
  if (!this.isLoadButton) this.send();
2389
2591
  }
2390
2592
 
@@ -2437,6 +2639,7 @@
2437
2639
  }
2438
2640
 
2439
2641
  mode(n, id) {
2642
+ //if(!this.s) return false
2440
2643
  let change = false;
2441
2644
  let cc = this.colors,
2442
2645
  s = this.s;
@@ -2518,6 +2721,19 @@
2518
2721
  //this.c[4].events = [ 'dragover', 'dragend', 'dragleave', 'drop' ];
2519
2722
  }
2520
2723
 
2724
+ addLoader(n, callbackLoad) {
2725
+ this.callbackLoad = callbackLoad;
2726
+ let l = this.dom('input', this.css.basic + 'top:0px; opacity:0; height:100%; width:100%; pointer-events:auto; cursor:pointer;'); //
2727
+
2728
+ l.name = 'loader';
2729
+ l.type = "file";
2730
+ l.addEventListener('change', function (e) {
2731
+ this.fileSelect(e.target.files[0]);
2732
+ }.bind(this), false);
2733
+ this.c[n].appendChild(l);
2734
+ return this;
2735
+ }
2736
+
2521
2737
  initLoader() {
2522
2738
  this.c[3] = this.dom('input', this.css.basic + 'top:0px; opacity:0; height:' + this.h + 'px; pointer-events:auto; cursor:pointer;'); //
2523
2739
 
@@ -2550,7 +2766,8 @@
2550
2766
  //else reader.readAsText( file );
2551
2767
 
2552
2768
  reader.onload = function (e) {
2553
- if (this.callback) this.callback(e.target.result, fname, type); //this.c[3].type = "file";
2769
+ if (this.callbackLoad) this.callbackLoad(e.target.result, fname, type); //if( this.callback ) this.callback( e.target.result, fname, type );
2770
+ //this.c[3].type = "file";
2554
2771
  //this.send( e.target.result );
2555
2772
  }.bind(this);
2556
2773
  }
@@ -3787,10 +4004,20 @@
3787
4004
 
3788
4005
 
3789
4006
  remove(n) {
3790
- if (n.clear) n.clear();
4007
+ if (n.dispose) n.dispose();
3791
4008
  } // clear all iner
3792
4009
 
3793
4010
 
4011
+ dispose() {
4012
+ this.clear();
4013
+ if (this.isUI) this.main.calc();
4014
+ super.dispose(); //Proto.prototype.clear.call( this );
4015
+ }
4016
+
4017
+ clear() {
4018
+ this.empty();
4019
+ }
4020
+
3794
4021
  empty() {
3795
4022
  this.close();
3796
4023
  let i = this.uis.length,
@@ -3839,23 +4066,6 @@
3839
4066
  this.parentHeight();
3840
4067
  }
3841
4068
 
3842
- clear() {
3843
- this.empty();
3844
- if (this.isUI) this.main.calc(-(this.h + 1));
3845
- Proto.prototype.clear.call(this);
3846
- }
3847
-
3848
- clearGroup() {
3849
- this.empty();
3850
- /*this.close();
3851
- let i = this.uis.length;
3852
- while(i--){
3853
- this.uis[i].clear();
3854
- }
3855
- this.uis = [];
3856
- this.h = this.baseH;*/
3857
- }
3858
-
3859
4069
  calcUis() {
3860
4070
  if (!this.isOpen) this.h = this.baseH;else this.h = Roots.calcUis(this.uis, this.zone, this.zone.y + this.baseH) + this.baseH;
3861
4071
  this.s[0].height = this.h + 'px'; //console.log('G', this.h)
@@ -6371,8 +6581,7 @@
6371
6581
  // like dat gui
6372
6582
  ref = true;
6373
6583
  if (a[2] === undefined) [].push.call(a, {});
6374
- type = a[2].type ? a[2].type : 'slide'; //autoType.apply( this, a );
6375
-
6584
+ type = a[2].type ? a[2].type : autoType(a[0][a[1]], a[2]);
6376
6585
  o = a[2];
6377
6586
  o.name = a[1];
6378
6587
 
@@ -6386,6 +6595,7 @@
6386
6595
 
6387
6596
  switch (name) {
6388
6597
  case 'bool':
6598
+ case 'boolean':
6389
6599
  n = new Bool(o);
6390
6600
  break;
6391
6601
 
@@ -6476,6 +6686,19 @@
6476
6686
  return n;
6477
6687
  }
6478
6688
  };
6689
+ const autoType = function (v, o) {
6690
+ let type = 'slide';
6691
+ if (typeof v === 'boolean') type = 'bool';else if (typeof v === 'string') {
6692
+ if (v.substring(0, 1) === '#') type = 'color';else type = 'string';
6693
+ } else if (typeof v === 'number') {
6694
+ if (o.ctype) type = 'color';else type = 'slide';
6695
+ } else if (typeof v === 'array' && v instanceof Array) {
6696
+ if (typeof v[0] === 'number') type = 'number';else if (typeof v[0] === 'string') type = 'list';
6697
+ } else if (typeof v === 'object' && v instanceof Object) {
6698
+ if (v.x !== undefined) type = 'number';else type = 'list';
6699
+ }
6700
+ return type;
6701
+ };
6479
6702
 
6480
6703
  /**
6481
6704
  * @author lth / https://github.com/lo-th
@@ -6580,6 +6803,8 @@
6580
6803
  if (!this.isCanvasOnly) {
6581
6804
  this.content.style.pointerEvents = 'auto';
6582
6805
  } else {
6806
+ this.content.style.left = '0px';
6807
+ this.content.style.right = 'auto';
6583
6808
  o.transition = 0;
6584
6809
  } // height transition
6585
6810
 
@@ -6614,7 +6839,7 @@
6614
6839
  makeCanvas() {
6615
6840
  this.canvas = document.createElementNS('http://www.w3.org/1999/xhtml', "canvas");
6616
6841
  this.canvas.width = this.zone.w;
6617
- this.canvas.height = this.forceHeight ? this.forceHeight : this.zone.h;
6842
+ this.canvas.height = this.forceHeight ? this.forceHeight : this.zone.h; //console.log( this.canvas.width, this.canvas.height )
6618
6843
  }
6619
6844
 
6620
6845
  draw(force) {
@@ -6709,10 +6934,14 @@
6709
6934
 
6710
6935
 
6711
6936
  clearTarget() {
6712
- if (this.current === -1) return false; //if(!this.target) return;
6937
+ if (this.current === -1) return false;
6938
+
6939
+ if (this.target.s) {
6940
+ // if no s target is delete !!
6941
+ this.target.uiout();
6942
+ this.target.reset();
6943
+ }
6713
6944
 
6714
- this.target.uiout();
6715
- this.target.reset();
6716
6945
  this.target = null;
6717
6946
  this.current = -1; ///console.log(this.isDown)//if(this.isDown)Roots.clearInput();
6718
6947
 
@@ -6849,8 +7078,9 @@
6849
7078
  main: this
6850
7079
  });else {
6851
7080
  a[2].isUI = true;
6852
- a[2].main = this;
6853
- ontop = a[1].ontop ? a[1].ontop : false;
7081
+ a[2].main = this; //ontop = a[1].ontop ? a[1].ontop : false;
7082
+
7083
+ ontop = a[2].ontop ? a[2].ontop : false;
6854
7084
  }
6855
7085
  }
6856
7086
 
@@ -6882,7 +7112,7 @@
6882
7112
 
6883
7113
 
6884
7114
  remove(n) {
6885
- if (n.clear) n.clear();
7115
+ if (n.dispose) n.dispose();
6886
7116
  } // call after uis clear
6887
7117
 
6888
7118
 
@@ -6906,7 +7136,7 @@
6906
7136
  while (i--) {
6907
7137
  item = this.uis.pop();
6908
7138
  this.inner.removeChild(item.c[0]);
6909
- item.clear(true); //this.uis[i].clear()
7139
+ item.dispose(); //this.uis[i].clear()
6910
7140
  }
6911
7141
 
6912
7142
  this.uis = [];
@@ -6918,13 +7148,7 @@
6918
7148
  }
6919
7149
 
6920
7150
  clear() {
6921
- this.empty(); //this.callback = null;
6922
-
6923
- /*let i = this.uis.length;
6924
- while( i-- ) this.uis[i].clear();
6925
- this.uis = [];
6926
- Roots.listens = [];
6927
- this.calc( -this.h );*/
7151
+ this.empty();
6928
7152
  }
6929
7153
 
6930
7154
  dispose() {
@@ -7025,13 +7249,15 @@
7025
7249
  } else {
7026
7250
  this.zone.h = this.h + this.bh;
7027
7251
  }
7028
- }
7252
+ } //if( this.forceHeight ) this.zone.h = this.forceHeight
7253
+
7029
7254
 
7030
7255
  this.upScroll(this.isScroll);
7031
7256
  this.innerContent.style.height = this.zone.h - this.bh + 'px';
7032
7257
  this.content.style.height = this.zone.h + 'px';
7033
7258
  this.bottom.style.top = this.zone.h - this.bh + 'px';
7034
- if (this.forceHeight && this.lockHeight) this.content.style.height = this.forceHeight + 'px'; //if( this.isOpen ) this.calcUis()
7259
+ if (this.forceHeight && this.lockHeight) this.content.style.height = this.forceHeight + 'px'; //console.log( this.zone, this.bh )
7260
+ //if( this.isOpen ) this.calcUis()
7035
7261
 
7036
7262
  if (this.isCanvas) this.draw(true); //else if( !this.transition ) this.rezone()
7037
7263
  }
@@ -7063,8 +7289,9 @@
7063
7289
 
7064
7290
  }
7065
7291
 
7066
- const REVISION = '4.0.2';
7292
+ const REVISION = '4.0.7';
7067
7293
 
7294
+ exports.Files = Files;
7068
7295
  exports.Gui = Gui;
7069
7296
  exports.Proto = Proto;
7070
7297
  exports.REVISION = REVISION;