|
1 | | -// https://lib.presenta.cc v0.1.2 - BSD-3-Clause License - Copyright 2020 Fabio Franchino |
| 1 | +// https://lib.presenta.cc v0.1.3 - 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.2"; |
| 8 | + var version = "0.1.3"; |
9 | 9 |
|
10 | 10 | function styleInject(css, ref) { |
11 | 11 | if ( ref === void 0 ) ref = {}; |
|
327 | 327 | } |
328 | 328 | }; |
329 | 329 |
|
330 | | - router.on('indexChanged', e => { |
| 330 | + const changed = e => { |
331 | 331 | setMouseMove(); |
332 | 332 | left.style.visibility = 'visible'; |
333 | 333 | right.style.visibility = 'visible'; |
334 | 334 | if (e.isFirst) left.style.visibility = 'hidden'; |
335 | 335 | if (e.isLast && e.totalSteps === e.currentStep) right.style.visibility = 'hidden'; |
| 336 | + }; |
| 337 | + |
| 338 | + router.on('stepChanged', e => { |
| 339 | + changed(e); |
| 340 | + }); |
| 341 | + router.on('indexChanged', e => { |
| 342 | + changed(e); |
336 | 343 | }); |
337 | 344 |
|
338 | 345 | const scheduleForHide = () => { |
|
700 | 707 | }); |
701 | 708 | }; |
702 | 709 |
|
| 710 | + const caches = []; |
| 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 | + }; |
| 731 | + |
| 732 | + const addCache = ob => { |
| 733 | + caches.push(ob); |
| 734 | + }; |
| 735 | + |
| 736 | + utils.io.addCache = addCache; |
| 737 | + |
703 | 738 | const controllers = { |
704 | 739 | autoplay, |
705 | 740 | keyboard, |
|
717 | 752 | hidden, |
718 | 753 | limitswitch, |
719 | 754 | sync, |
720 | | - sender |
| 755 | + sender, |
| 756 | + cache |
721 | 757 | }; |
722 | 758 |
|
723 | 759 | const add = (type, module, override) => { |
|
1077 | 1113 | e.stopPropagation(); |
1078 | 1114 | e.preventDefault(); |
1079 | 1115 | } |
| 1116 | + |
| 1117 | + if (e.key === 'r') { |
| 1118 | + if (video) { |
| 1119 | + video.currentTime = 0; |
| 1120 | + } |
| 1121 | + } |
| 1122 | + |
| 1123 | + if (e.key === 'm') { |
| 1124 | + if (video) { |
| 1125 | + video.volume = !video.volume ? 1 : 0; |
| 1126 | + } |
| 1127 | + } |
| 1128 | + |
| 1129 | + if (e.key === '+') { |
| 1130 | + if (video) { |
| 1131 | + video.volume += 0.1; |
| 1132 | + } |
| 1133 | + } |
| 1134 | + |
| 1135 | + if (e.key === '-') { |
| 1136 | + if (video) { |
| 1137 | + video.volume -= -0.1; |
| 1138 | + } |
| 1139 | + } |
1080 | 1140 | }; |
1081 | 1141 |
|
1082 | 1142 | if (presentMode) { |
|
1135 | 1195 | el.appendChild(child); |
1136 | 1196 | }; |
1137 | 1197 |
|
| 1198 | + var css_248z$I = ":root{--svgPadding:0}.style_inner__AjKjt,.style_svg__2xfFu{width:100%;height:100%}.style_inner__AjKjt{padding:var(--svgPadding)}.style_svg__2xfFu svg{width:100%;height:100%}"; |
| 1199 | + var css$d = {"svg":"style_svg__2xfFu","inner":"style_inner__AjKjt"}; |
| 1200 | + styleInject(css_248z$I); |
| 1201 | + |
| 1202 | + const svg = function (el, config) { |
| 1203 | + const svg = config._cache || config.code; |
| 1204 | + if (!svg) return console.log('[block svg]', 'The svg is not present'); |
| 1205 | + const child = utils.div(`<div class="c ${css$d.svg}"> |
| 1206 | + <div class="${css$d.inner}"> |
| 1207 | + ${svg} |
| 1208 | + </div> |
| 1209 | + </div>`); |
| 1210 | + el.appendChild(child); |
| 1211 | + |
| 1212 | + this.beforeDestroy = () => {}; |
| 1213 | + |
| 1214 | + this.stepForward = () => {}; |
| 1215 | + }; |
| 1216 | + |
| 1217 | + svg.init = () => { |
| 1218 | + utils.addProp(['svgPadding']); |
| 1219 | + utils.io.addCache({ |
| 1220 | + type: 'svg', |
| 1221 | + field: 'url' |
| 1222 | + }); |
| 1223 | + }; |
| 1224 | + |
1138 | 1225 | const blocks = { |
1139 | 1226 | debug, |
1140 | 1227 | text, |
1141 | 1228 | embed, |
1142 | 1229 | image, |
1143 | 1230 | video, |
1144 | | - solid |
| 1231 | + solid, |
| 1232 | + svg |
1145 | 1233 | }; |
1146 | 1234 |
|
1147 | 1235 | const add$2 = (type, module, override) => { |
|
1156 | 1244 | blocks[type] = module; |
1157 | 1245 | }; |
1158 | 1246 |
|
1159 | | - var css_248z$I = ".container_mainwrapper__zelcO{outline:none}.container_container__3kBNh,.container_mainwrapper__zelcO{width:100%;height:100%;position:relative;overflow:hidden}.container_container__3kBNh>div{position:absolute;top:0;left:0;width:100%}"; |
1160 | | - var css$d = {"mainwrapper":"container_mainwrapper__zelcO","container":"container_container__3kBNh"}; |
1161 | | - styleInject(css_248z$I); |
1162 | | - |
1163 | | - var css_248z$J = ".router_router__2r4NQ{width:100%;height:100%;position:absolute;top:0;left:0;pointer-events:none}"; |
1164 | | - var css$e = {"router":"router_router__2r4NQ"}; |
| 1247 | + var css_248z$J = ".container_mainwrapper__zelcO{outline:none}.container_container__3kBNh,.container_mainwrapper__zelcO{width:100%;height:100%;position:relative;overflow:hidden}.container_container__3kBNh>div{position:absolute;top:0;left:0;width:100%}"; |
| 1248 | + var css$e = {"mainwrapper":"container_mainwrapper__zelcO","container":"container_container__3kBNh"}; |
1165 | 1249 | styleInject(css_248z$J); |
1166 | 1250 |
|
| 1251 | + var css_248z$K = ".router_router__2r4NQ{width:100%;height:100%;position:absolute;top:0;left:0;pointer-events:none}"; |
| 1252 | + var css$f = {"router":"router_router__2r4NQ"}; |
| 1253 | + styleInject(css_248z$K); |
| 1254 | + |
1167 | 1255 | const Router = function (rootElement, projectConfig) { |
1168 | | - const child = utils.div(`<div class="controller ${css$e.router}"></div>`); |
| 1256 | + const child = utils.div(`<div class="controller ${css$f.router}"></div>`); |
1169 | 1257 | rootElement.appendChild(child); |
1170 | 1258 | const scenes = projectConfig.scenes; |
1171 | 1259 |
|
|
1174 | 1262 | const listeners = {}; |
1175 | 1263 | const registeredIO = {}; |
1176 | 1264 | let currentIndex = 0; |
1177 | | - let currentStep = 0; |
1178 | | - let numSteps = 0; |
1179 | | - |
1180 | | - const setNumSteps = () => { |
1181 | | - numSteps = scenes[currentIndex] && scenes[currentIndex]._steps ? scenes[currentIndex]._steps.length : 0; |
1182 | | - }; // setNumSteps() |
| 1265 | + let currentStep = 0; // let numSteps = 0 |
1183 | 1266 |
|
| 1267 | + const numSteps = () => { |
| 1268 | + return scenes[currentIndex] && scenes[currentIndex]._steps ? scenes[currentIndex]._steps.length : 0; |
| 1269 | + }; |
1184 | 1270 |
|
1185 | 1271 | const updateRouterWrapper = () => { |
1186 | 1272 | const sceneConfig = scenes[currentIndex]; |
1187 | 1273 | child.classList.remove(...child.classList); |
1188 | | - child.classList.add('controller', css$e.router); |
| 1274 | + child.classList.add('controller', css$f.router); |
1189 | 1275 | child.style = null; |
1190 | 1276 | utils.globs(child, sceneConfig); |
1191 | 1277 | utils.props(child, sceneConfig); |
1192 | 1278 | }; |
1193 | 1279 |
|
1194 | 1280 | this.next = () => { |
1195 | | - if (currentStep === numSteps) { |
| 1281 | + if (currentStep === numSteps()) { |
1196 | 1282 | this.nextIndex(); |
1197 | 1283 | } else { |
1198 | 1284 | currentStep++; |
|
1214 | 1300 | notify(['nextIndex', 'indexChanged']); |
1215 | 1301 | } else { |
1216 | 1302 | currentIndex = numScenes(); |
1217 | | - currentStep = numSteps; |
| 1303 | + currentStep = numSteps(); |
1218 | 1304 | notify('end'); |
1219 | | - } |
| 1305 | + } // setNumSteps() |
1220 | 1306 |
|
1221 | | - setNumSteps(); |
1222 | 1307 | }; |
1223 | 1308 |
|
1224 | 1309 | this.prevIndex = () => { |
|
1230 | 1315 | currentIndex = 0; |
1231 | 1316 | currentStep = 0; |
1232 | 1317 | notify('begin'); |
1233 | | - } |
| 1318 | + } // setNumSteps() |
1234 | 1319 |
|
1235 | | - setNumSteps(); |
1236 | 1320 | }; |
1237 | 1321 |
|
1238 | 1322 | this.goto = v => { |
|
1253 | 1337 | currentIndex, |
1254 | 1338 | currentStep, |
1255 | 1339 | totalScenes: this.totalScenes(), |
1256 | | - totalSteps: numSteps, |
| 1340 | + totalSteps: numSteps(), |
1257 | 1341 | isFirst: this.isFirst(), |
1258 | 1342 | isLast: this.isLast() |
1259 | 1343 | }); |
|
1285 | 1369 |
|
1286 | 1370 | this.totalScenes = () => numScenes() + 1; |
1287 | 1371 |
|
1288 | | - this.totalSteps = () => numSteps; |
| 1372 | + this.totalSteps = () => numSteps(); |
1289 | 1373 |
|
1290 | 1374 | this.currentIndex = () => currentIndex; |
1291 | 1375 |
|
|
1316 | 1400 |
|
1317 | 1401 | notify('indexChanged'); |
1318 | 1402 | setTimeout(() => { |
1319 | | - notify('init'); |
1320 | | - setNumSteps(); |
| 1403 | + notify('init'); // setNumSteps() |
1321 | 1404 | }); |
1322 | 1405 | }; |
1323 | 1406 |
|
1324 | | - var css_248z$K = ".scene_sceneContainer__IgSpB{width:100%;height:100%;display:flex;align-items:center;justify-content:center;position:relative}.scene_scene__3uvTl{--presenta-sw:calc(var(--presenta-w)/var(--presenta-p)/var(--presenta-fz));--presenta-sh:calc(var(--presenta-h)/var(--presenta-p)/var(--presenta-fz));--presenta-scal:calc(var(--presenta-pw)/var(--presenta-p)/var(--presenta-pw)/var(--presenta-fz));width:var(--presenta-sw);height:var(--presenta-sh);font-family:serif}.scene_wrapper__3yr1k{width:var(--presenta-w);height:var(--presenta-h);transform:scale(1);transform:scale(var(--presenta-scal));transform-origin:top left;overflow:hidden;padding:var(--scenePadding);background-color:var(--sceneBackColor)}.scene_content__1rJf0{width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden}.scene_fcontainer__1E_0g{top:0;left:0;width:100%;height:100%;position:absolute;pointer-events:none}.scene_viewport__3uNLS{width:100%;height:100%;position:relative;flex:1;overflow:hidden;display:flex;flex-direction:row}.scene_viewport__3uNLS>div{height:100%}"; |
1325 | | - var css$f = {"sceneContainer":"scene_sceneContainer__IgSpB","scene":"scene_scene__3uvTl","wrapper":"scene_wrapper__3yr1k","content":"scene_content__1rJf0","fcontainer":"scene_fcontainer__1E_0g","viewport":"scene_viewport__3uNLS"}; |
1326 | | - styleInject(css_248z$K); |
1327 | | - |
1328 | | - var css_248z$L = ".block_block__BWbaZ{background:var(--colorBack);width:100%;height:100%;flex:1;flex:var(--blockWeight);overflow:hidden;position:relative}.block_inner__3LS6s{width:100%;height:100%;padding:var(--blockPadding);opacity:var(--blockOpacity);mix-blend-mode:var(--blockBlend)}.block_bdecoration__3KJh-,.block_inner__3LS6s{top:0;left:0;width:100%;height:100%;position:absolute}.block_fdecoration__12tBw{pointer-events:none}"; |
1329 | | - var css$g = {"block":"block_block__BWbaZ","inner":"block_inner__3LS6s","bdecoration":"block_bdecoration__3KJh-","fdecoration":"block_fdecoration__12tBw"}; |
| 1407 | + var css_248z$L = ".scene_sceneContainer__IgSpB{width:100%;height:100%;display:flex;align-items:center;justify-content:center;position:relative}.scene_scene__3uvTl{--presenta-sw:calc(var(--presenta-w)/var(--presenta-p)/var(--presenta-fz));--presenta-sh:calc(var(--presenta-h)/var(--presenta-p)/var(--presenta-fz));--presenta-scal:calc(var(--presenta-pw)/var(--presenta-p)/var(--presenta-pw)/var(--presenta-fz));width:var(--presenta-sw);height:var(--presenta-sh);font-family:serif}.scene_wrapper__3yr1k{width:var(--presenta-w);height:var(--presenta-h);transform:scale(1);transform:scale(var(--presenta-scal));transform-origin:top left;overflow:hidden;padding:var(--scenePadding);background-color:var(--sceneBackColor)}.scene_content__1rJf0{width:100%;height:100%;display:flex;flex-direction:column;overflow:hidden}.scene_fcontainer__1E_0g{top:0;left:0;width:100%;height:100%;position:absolute;pointer-events:none}.scene_viewport__3uNLS{width:100%;height:100%;position:relative;flex:1;overflow:hidden;display:flex;flex-direction:row}.scene_viewport__3uNLS>div{height:100%}"; |
| 1408 | + var css$g = {"sceneContainer":"scene_sceneContainer__IgSpB","scene":"scene_scene__3uvTl","wrapper":"scene_wrapper__3yr1k","content":"scene_content__1rJf0","fcontainer":"scene_fcontainer__1E_0g","viewport":"scene_viewport__3uNLS"}; |
1330 | 1409 | styleInject(css_248z$L); |
1331 | 1410 |
|
| 1411 | + var css_248z$M = ".block_block__BWbaZ{background:var(--colorBack);width:100%;height:100%;flex:1;flex:var(--blockWeight);overflow:hidden;position:relative}.block_inner__3LS6s{width:100%;height:100%;padding:var(--blockPadding);opacity:var(--blockOpacity);mix-blend-mode:var(--blockBlend)}.block_bdecoration__3KJh-,.block_inner__3LS6s{top:0;left:0;width:100%;height:100%;position:absolute}.block_fdecoration__12tBw{pointer-events:none}"; |
| 1412 | + var css$h = {"block":"block_block__BWbaZ","inner":"block_inner__3LS6s","bdecoration":"block_bdecoration__3KJh-","fdecoration":"block_fdecoration__12tBw"}; |
| 1413 | + styleInject(css_248z$M); |
| 1414 | + |
1332 | 1415 | const Block = function (blocksElement, blockConfig) { |
1333 | 1416 | this.type = blockConfig.type; |
1334 | 1417 | this.index = blockConfig._index; |
|
1339 | 1422 | } |
1340 | 1423 |
|
1341 | 1424 | let step = 0; |
1342 | | - const child = utils.div(`<div class="block ${css$g.block} b b${this.index}"> |
1343 | | - <div class="backDecoration ${css$g.bdecoration}"></div> |
1344 | | - <div class="blockContainer ${css$g.inner}"></div> |
1345 | | - <div class="frontDecoration ${css$g.fdecoration}"></div> |
| 1425 | + const child = utils.div(`<div class="block ${css$h.block} b b${this.index}"> |
| 1426 | + <div class="backDecoration ${css$h.bdecoration}"></div> |
| 1427 | + <div class="blockContainer ${css$h.inner}"></div> |
| 1428 | + <div class="frontDecoration ${css$h.fdecoration}"></div> |
1346 | 1429 | </div>`); |
1347 | 1430 | utils.globs(child, blockConfig); |
1348 | 1431 | utils.props(child, blockConfig); |
|
1453 | 1536 | sceneConfig._steps = []; |
1454 | 1537 | const steps = sceneConfig._steps; |
1455 | 1538 | const child = utils.div(`<div |
1456 | | - class="s ${css$f.sceneContainer}"> |
1457 | | - <div class="sceneObject ${css$f.scene}"> |
1458 | | - <div class="${css$f.wrapper}"> |
1459 | | - <div class="${css$f.content}"> |
1460 | | - <div class="layout blocksContainer ${css$f.viewport}"></div> |
1461 | | - <div class="frontContainer ${css$f.fcontainer}"></div> |
| 1539 | + class="s ${css$g.sceneContainer}"> |
| 1540 | + <div class="sceneObject ${css$g.scene}"> |
| 1541 | + <div class="${css$g.wrapper}"> |
| 1542 | + <div class="${css$g.content}"> |
| 1543 | + <div class="layout blocksContainer ${css$g.viewport}"></div> |
| 1544 | + <div class="frontContainer ${css$g.fcontainer}"></div> |
1462 | 1545 | </div> |
1463 | 1546 | </div> |
1464 | 1547 | </div> |
|
1496 | 1579 |
|
1497 | 1580 | if (Mod) { |
1498 | 1581 | if (modConfig) { |
1499 | | - const mod = new Mod(child.querySelector(`.${css$f.content}`), modConfig, sceneConfig); |
| 1582 | + const mod = new Mod(child.querySelector(`.${css$g.content}`), modConfig, sceneConfig); |
1500 | 1583 | modInstances.push(mod); |
1501 | 1584 | } |
1502 | 1585 | } |
|
1611 | 1694 |
|
1612 | 1695 |
|
1613 | 1696 | rootElement.classList.add('presenta'); |
1614 | | - const child = utils.div(`<div class="${css$d.mainwrapper}"></div>`); |
| 1697 | + const child = utils.div(`<div class="${css$e.mainwrapper}"></div>`); |
1615 | 1698 | child.setAttribute('tabindex', '0'); |
1616 | 1699 | utils.globs(child, projectConfig); |
1617 | 1700 | utils.props(child, projectConfig); |
|
1620 | 1703 | Init the container |
1621 | 1704 | */ |
1622 | 1705 |
|
1623 | | - const cont = utils.div(`<div class="a ${css$d.container}"></div>`); |
| 1706 | + const cont = utils.div(`<div class="a ${css$e.container}"></div>`); |
1624 | 1707 | child.appendChild(cont); |
1625 | 1708 | const scenes = projectConfig.scenes; |
1626 | 1709 | var currentScene = null; |
|
1675 | 1758 | this.config = projectConfig; |
1676 | 1759 | }; |
1677 | 1760 |
|
1678 | | - var css_248z$M = ".style_group__2AqP-,.style_group__2AqP->div{width:100%;height:100%;position:relative}"; |
1679 | | - var css$h = {"group":"style_group__2AqP-"}; |
1680 | | - styleInject(css_248z$M); |
| 1761 | + var css_248z$N = ".style_group__2AqP-,.style_group__2AqP->div{width:100%;height:100%;position:relative}"; |
| 1762 | + var css$i = {"group":"style_group__2AqP-"}; |
| 1763 | + styleInject(css_248z$N); |
1681 | 1764 |
|
1682 | 1765 | const group = function (el, config) { |
1683 | 1766 | const blocks = config.blocks; |
1684 | 1767 | const instBlocks = []; |
1685 | | - const child = utils.div(`<div class="${css$h.group}"> |
| 1768 | + const child = utils.div(`<div class="${css$i.group}"> |
1686 | 1769 | <div class="layout"></div> |
1687 | 1770 | </div>`); // u.globs(child, config) |
1688 | 1771 | // u.props(child, config) |
|
1710 | 1793 | fullscreen: true, |
1711 | 1794 | hidden: true, |
1712 | 1795 | limitswitch: true, |
1713 | | - sender: true |
| 1796 | + cache: true |
1714 | 1797 | }, |
1715 | 1798 | modules: { |
1716 | 1799 | steps: true |
|
0 commit comments