uil 4.0.5 → 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.4</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>
package/build/uil.js CHANGED
@@ -1543,6 +1543,196 @@
1543
1543
  T.setText();
1544
1544
  const Tools = T;
1545
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
+
1546
1736
  class V2 {
1547
1737
  constructor(x = 0, y = 0) {
1548
1738
  this.x = x;
@@ -2074,6 +2264,7 @@
2074
2264
 
2075
2265
 
2076
2266
  handleEvent(e) {
2267
+ //if(!this.s) return false
2077
2268
  if (this.lock) return;
2078
2269
  if (this.neverlock) Roots.lock = false;
2079
2270
  if (!this[e.type]) return console.error(e.type, 'this type of event no existe !');
@@ -2348,13 +2539,14 @@
2348
2539
  this.stat[i] = sel ? 3 : 1;
2349
2540
  }
2350
2541
 
2351
- if (!o.value || !o.values) {
2352
- if (this.c[1] !== undefined) this.c[1].textContent = '';
2353
- this.p = o.p !== undefined ? o.p : 0;
2354
- } else {
2355
- if (!this.txt) this.p = 0;
2356
- } //
2542
+ if (!o.value && !o.values) {
2543
+ if (this.c[1] !== undefined) {
2544
+ this.txt = '';
2545
+ this.c[1].textContent = '';
2546
+ }
2547
+ }
2357
2548
 
2549
+ if (!this.txt) this.p = 0; //
2358
2550
 
2359
2551
  if (this.isLoadButton) this.initLoader();
2360
2552
 
@@ -2447,6 +2639,7 @@
2447
2639
  }
2448
2640
 
2449
2641
  mode(n, id) {
2642
+ //if(!this.s) return false
2450
2643
  let change = false;
2451
2644
  let cc = this.colors,
2452
2645
  s = this.s;
@@ -2528,6 +2721,19 @@
2528
2721
  //this.c[4].events = [ 'dragover', 'dragend', 'dragleave', 'drop' ];
2529
2722
  }
2530
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
+
2531
2737
  initLoader() {
2532
2738
  this.c[3] = this.dom('input', this.css.basic + 'top:0px; opacity:0; height:' + this.h + 'px; pointer-events:auto; cursor:pointer;'); //
2533
2739
 
@@ -2560,7 +2766,8 @@
2560
2766
  //else reader.readAsText( file );
2561
2767
 
2562
2768
  reader.onload = function (e) {
2563
- 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";
2564
2771
  //this.send( e.target.result );
2565
2772
  }.bind(this);
2566
2773
  }
@@ -6374,8 +6581,7 @@
6374
6581
  // like dat gui
6375
6582
  ref = true;
6376
6583
  if (a[2] === undefined) [].push.call(a, {});
6377
- type = a[2].type ? a[2].type : 'slide'; //autoType.apply( this, a );
6378
-
6584
+ type = a[2].type ? a[2].type : autoType(a[0][a[1]], a[2]);
6379
6585
  o = a[2];
6380
6586
  o.name = a[1];
6381
6587
 
@@ -6389,6 +6595,7 @@
6389
6595
 
6390
6596
  switch (name) {
6391
6597
  case 'bool':
6598
+ case 'boolean':
6392
6599
  n = new Bool(o);
6393
6600
  break;
6394
6601
 
@@ -6479,6 +6686,19 @@
6479
6686
  return n;
6480
6687
  }
6481
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
+ };
6482
6702
 
6483
6703
  /**
6484
6704
  * @author lth / https://github.com/lo-th
@@ -6714,10 +6934,14 @@
6714
6934
 
6715
6935
 
6716
6936
  clearTarget() {
6717
- 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
+ }
6718
6944
 
6719
- this.target.uiout();
6720
- this.target.reset();
6721
6945
  this.target = null;
6722
6946
  this.current = -1; ///console.log(this.isDown)//if(this.isDown)Roots.clearInput();
6723
6947
 
@@ -6854,8 +7078,9 @@
6854
7078
  main: this
6855
7079
  });else {
6856
7080
  a[2].isUI = true;
6857
- a[2].main = this;
6858
- 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;
6859
7084
  }
6860
7085
  }
6861
7086
 
@@ -7064,8 +7289,9 @@
7064
7289
 
7065
7290
  }
7066
7291
 
7067
- const REVISION = '4.0.5';
7292
+ const REVISION = '4.0.7';
7068
7293
 
7294
+ exports.Files = Files;
7069
7295
  exports.Gui = Gui;
7070
7296
  exports.Proto = Proto;
7071
7297
  exports.REVISION = REVISION;