Skip to content

Commit 43ba1b4

Browse files
committed
bump release
1 parent 9f0aef6 commit 43ba1b4

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

dist/presenta.js

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// https://lib.presenta.cc v1.0.12 - BSD-3-Clause License - Copyright 2022 Fabio Franchino
1+
// https://lib.presenta.cc v1.0.13 - BSD-3-Clause License - Copyright 2022 Fabio Franchino
22
(function (global, factory) {
33
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
44
typeof define === 'function' && define.amd ? define(factory) :
55
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Presenta = factory());
66
})(this, (function () { 'use strict';
77

8-
var version = "1.0.12";
8+
var version = "1.0.13";
99

1010
function styleInject(css, ref) {
1111
if ( ref === void 0 ) ref = {};
@@ -1078,9 +1078,9 @@
10781078
}
10791079
};
10801080

1081-
const appendScriptTag = (url, code) => {
1081+
const appendScriptTag = (url, code, id) => {
10821082
const ns = document.createElement('script');
1083-
ns.setAttribute('class', 'sdpmodulescriptcontainer');
1083+
ns.setAttribute('class', 'sdpmodulescriptcontainer' + id);
10841084
ns.setAttribute('type', 'module');
10851085
ns.setAttribute('async', '');
10861086
ns.innerHTML = code;
@@ -1089,37 +1089,44 @@
10891089
};
10901090

10911091
const script = function (element, mod, config) {
1092-
if (config._mode === 'preview') return;
1092+
if (!mod.forceRun && config._mode === 'preview') return;
10931093
if (config.contextType !== 'scene') return;
1094+
const id = '_JSMOD_' + parseInt(Math.random() * 10000);
1095+
const that = this;
1096+
1097+
this.destroy = () => {
1098+
const prev = [...document.querySelectorAll('.sdpmodulescriptcontainer' + id)];
1099+
prev.forEach(d => document.body.removeChild(d));
1100+
};
1101+
10941102
return new Promise((resolve, reject) => {
10951103
const blink = {};
10961104
config.blocks.forEach(b => {
10971105
blink[b.ukey] = b;
10981106
});
10991107
blink._otherParams = config.otherParams;
1100-
window._sdpconfigobject = blink;
1101-
window._sdpscriptexportedresult = {};
1102-
1103-
window._sdpcallbackfunc = () => {
1104-
console.log('_sdpcallbackfunc');
1105-
window._sdpcallbackfunc = null;
1106-
window._sdpconfigobject = null;
1107-
resolve();
1108-
}; // remove previous code modules
1108+
window['_sdpconfigobject' + id] = blink;
1109+
window['_sdpscriptexportedresult' + id] = {};
11091110

1111+
window['_sdpcallbackfunc' + id] = () => {
1112+
console.log('_sdpcallbackfunc' + id);
1113+
window['_sdpcallbackfunc' + id] = null;
1114+
window['_sdpconfigobject' + id] = null;
1115+
resolve(that);
1116+
};
11101117

1111-
const prev = [...document.querySelectorAll('.sdpmodulescriptcontainer')];
1112-
prev.forEach(d => document.body.removeChild(d));
11131118
let code = `
11141119
const index = ${config.index}
1115-
const exportedResult = window._sdpscriptexportedresult
1120+
const exportedResult = window._sdpscriptexportedresult${id}
11161121
1117-
const params = window._sdpconfigobject._otherParams
1122+
const params = window._sdpconfigobject${id}._otherParams
11181123
`;
11191124
config.blocks.forEach(b => {
1120-
code += `
1121-
const ${b.ukey} = window._sdpconfigobject.${b.ukey}
1125+
if (b.ukey) {
1126+
code += `
1127+
const ${b.ukey} = window._sdpconfigobject${id}.${b.ukey}
11221128
`;
1129+
}
11231130
});
11241131
code += `
11251132
@@ -1130,23 +1137,23 @@ try{
11301137
${mod.code}
11311138
11321139
}catch(err){
1133-
console.log('error in module', err)
1140+
console.log('error in module', err)
11341141
}
11351142
export default {}`; // add the code module
11361143

11371144
let url = URL.createObjectURL(new Blob([code], {
11381145
type: 'application/javascript'
11391146
}));
1140-
appendScriptTag(url, code); // add the last module for callback
1147+
appendScriptTag(url, code, id); // add the last module for callback
11411148

11421149
const lastModule = `
11431150
import _sdpPrivateInput from '${url}'
1144-
window._sdpcallbackfunc()
1151+
window._sdpcallbackfunc${id}()
11451152
`;
11461153
url = URL.createObjectURL(new Blob([lastModule], {
11471154
type: 'application/javascript'
11481155
}));
1149-
appendScriptTag(url, lastModule);
1156+
appendScriptTag(url, lastModule, id);
11501157
});
11511158
};
11521159

@@ -1925,7 +1932,7 @@ window._sdpcallbackfunc()
19251932
const that = this;
19261933
return new Promise(function (resolve, reject) {
19271934
let blockInstances = [];
1928-
const modInstances = [];
1935+
let modInstances = [];
19291936
const blockPromises = [];
19301937
const preModPromises = [];
19311938
sceneConfig.contextType = 'scene';
@@ -2088,6 +2095,7 @@ window._sdpcallbackfunc()
20882095
if (!projectConfig.waitForAllPromises) resolve(that);
20892096
initModules(true);
20902097
Promise.all(preModPromises).then(data => {
2098+
modInstances = data;
20912099
initBlocks();
20922100
Promise.all(blockPromises).then(data => {
20932101
blockInstances = data;
@@ -2126,6 +2134,7 @@ window._sdpcallbackfunc()
21262134
const sceneConfig = scene.sceneConfig;
21272135
const child = sceneConfig._el;
21282136
const projectConfig = sceneConfig._projectConfig;
2137+
const modPromises = [];
21292138

21302139
const initModules = runBefore => {
21312140
if (sceneConfig.modules) {
@@ -2138,7 +2147,7 @@ window._sdpcallbackfunc()
21382147
if (modConfig) {
21392148
if (!Mod.runBefore && !runBefore) {
21402149
// eslint-disable-next-line
2141-
new Mod(child, modConfig, sceneConfig);
2150+
modPromises.push(new Mod(child, modConfig, sceneConfig));
21422151
}
21432152
}
21442153
}
@@ -2155,10 +2164,12 @@ window._sdpcallbackfunc()
21552164
}, projectConfig._transitionDestroyDelay);
21562165
};
21572166

2158-
initModules(false);
21592167
sceneConfig.blocks.forEach(b => MountBlock(b));
2160-
startTransition();
2161-
child.classList.add('presentaSceneMounted');
2168+
initModules(false);
2169+
Promise.all(modPromises).then(data => {
2170+
startTransition();
2171+
child.classList.add('presentaSceneMounted');
2172+
});
21622173
};
21632174

21642175
const Container = function (rootElement, projectConfig) {

0 commit comments

Comments
 (0)