|
1 | | -// https://lib.presenta.cc v0.1.3 - BSD-3-Clause License - Copyright 2020 Fabio Franchino |
| 1 | +// https://lib.presenta.cc v0.1.4 - BSD-3-Clause License - Copyright 2020 Fabio Franchino |
2 | 2 | (function (global, factory) { |
3 | 3 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
4 | 4 | typeof define === 'function' && define.amd ? define(factory) : |
5 | 5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Presenta = factory()); |
6 | 6 | }(this, (function () { 'use strict'; |
7 | 7 |
|
8 | | - var version = "0.1.3"; |
| 8 | + var version = "0.1.4"; |
9 | 9 |
|
10 | 10 | function styleInject(css, ref) { |
11 | 11 | if ( ref === void 0 ) ref = {}; |
|
709 | 709 |
|
710 | 710 | const caches = []; |
711 | 711 |
|
712 | | - const cache = function (rootElement, router, ctrlConfig, projectConfig) { |
713 | | - projectConfig.scenes.forEach(s => { |
714 | | - s.blocks.forEach(b => { |
715 | | - const blk = caches.find(d => d.type === b.type); |
716 | | - |
717 | | - if (blk && b.url) { |
718 | | - const f = blk => { |
719 | | - fetch(b.url).then(data => { |
720 | | - data.text().then(data => { |
721 | | - b._cache = data; |
722 | | - }); |
723 | | - }); |
724 | | - }; |
725 | | - |
726 | | - f(); |
727 | | - } |
728 | | - }); |
729 | | - }); |
730 | | - }; |
| 712 | + const cache = function (rootElement, router, ctrlConfig, projectConfig) {}; |
731 | 713 |
|
732 | 714 | const addCache = ob => { |
733 | 715 | caches.push(ob); |
734 | 716 | }; |
735 | 717 |
|
736 | 718 | utils.io.addCache = addCache; |
737 | 719 |
|
| 720 | + cache.run = config => { |
| 721 | + return new Promise((resolve, reject) => { |
| 722 | + let len = 0; |
| 723 | + let cnt = 0; |
| 724 | + const blocks = config.scenes.reduce((a, s) => { |
| 725 | + s.blocks.reduce((a2, b) => { |
| 726 | + const blk = caches.find(d => d.type === b.type); |
| 727 | + if (blk && b.url) a.push(b); |
| 728 | + }, []); |
| 729 | + return a; |
| 730 | + }, []); |
| 731 | + if (blocks.length === 0) resolve(); |
| 732 | + blocks.forEach(block => { |
| 733 | + const f = block => { |
| 734 | + fetch(block.url).then(data => { |
| 735 | + data.text().then(data => { |
| 736 | + block._cache = data; |
| 737 | + cnt++; |
| 738 | + if (cnt === len) resolve(); |
| 739 | + }); |
| 740 | + }).catch(err => { |
| 741 | + cnt++; |
| 742 | + block._cache = err + ': ' + block.url; |
| 743 | + if (cnt === len) resolve(); |
| 744 | + }); |
| 745 | + }; |
| 746 | + |
| 747 | + len++; |
| 748 | + f(block); |
| 749 | + }); |
| 750 | + }); |
| 751 | + }; |
| 752 | + |
738 | 753 | const controllers = { |
739 | 754 | autoplay, |
740 | 755 | keyboard, |
|
1829 | 1844 |
|
1830 | 1845 | for (const k in plugins) if (plugins[k].init) plugins[k].init(); |
1831 | 1846 |
|
1832 | | - for (const k in plugins) if (plugins[k].run) plugins[k].run(config); |
| 1847 | + const all = []; |
1833 | 1848 |
|
1834 | | - return new Container(utils.select(el), config); |
| 1849 | + for (const k in plugins) { |
| 1850 | + if (plugins[k].run) { |
| 1851 | + all.push(plugins[k].run(config)); |
| 1852 | + } |
| 1853 | + } |
| 1854 | + |
| 1855 | + return new Promise((resolve, reject) => { |
| 1856 | + Promise.all(all).then(values => { |
| 1857 | + resolve(new Container(utils.select(el), config)); |
| 1858 | + }); |
| 1859 | + }); |
1835 | 1860 | }; |
1836 | 1861 |
|
1837 | 1862 | add$2('group', group); // this to avoid circular dependencies warning, since removed implicit inclusion in block types |
|
0 commit comments