fixed build to prevent polluting global scope
diff --git a/player/index.html b/player/index.html
index 38c55be..07ab2ec 100644
--- a/player/index.html
+++ b/player/index.html
@@ -181,7 +181,7 @@
title: 'TEST TITLE',
description: 'TEST DESCRIPTION',
},
- path: 'exports/render/data.json'
+ path: 'exports/bm/data.json'
};
// lottie.setQuality('low');
anim = lottie.loadAnimation(animData);
diff --git a/player/js/module.js b/player/js/module.js
index f4e46b5..d2ce1e8 100644
--- a/player/js/module.js
+++ b/player/js/module.js
@@ -1,140 +1,126 @@
-(typeof navigator !== "undefined") && (function(root, factory) {
- if (typeof define === "function" && define.amd) {
- define(function() {
- return factory(root);
- });
- } else if (typeof module === "object" && module.exports) {
- module.exports = factory(root);
+"use strict";
+/*<%= contents %>*/
+var lottie = {};
+
+var _isFrozen = false;
+
+function setLocationHref (href) {
+ locationHref = href;
+}
+
+function searchAnimations() {
+ if (standalone === true) {
+ animationManager.searchAnimations(animationData, standalone, renderer);
} else {
- root.lottie = factory(root);
- root.bodymovin = root.lottie;
+ animationManager.searchAnimations();
}
-}((window || {}), function(window) {
- "use strict";
- /*<%= contents %>*/
- var lottiejs = {};
+}
- var _isFrozen = false;
+function setSubframeRendering(flag) {
+ subframeEnabled = flag;
+}
- function setLocationHref (href) {
- locationHref = href;
+function loadAnimation(params) {
+ if (standalone === true) {
+ params.animationData = JSON.parse(animationData);
}
+ return animationManager.loadAnimation(params);
+}
- function searchAnimations() {
- if (standalone === true) {
- animationManager.searchAnimations(animationData, standalone, renderer);
- } else {
- animationManager.searchAnimations();
+function setQuality(value) {
+ if (typeof value === 'string') {
+ switch (value) {
+ case 'high':
+ defaultCurveSegments = 200;
+ break;
+ case 'medium':
+ defaultCurveSegments = 50;
+ break;
+ case 'low':
+ defaultCurveSegments = 10;
+ break;
+ }
+ } else if (!isNaN(value) && value > 1) {
+ defaultCurveSegments = value;
+ }
+ if (defaultCurveSegments >= 50) {
+ roundValues(false);
+ } else {
+ roundValues(true);
+ }
+}
+
+function inBrowser() {
+ return typeof navigator !== 'undefined';
+}
+
+function installPlugin(type, plugin) {
+ if (type === 'expressions') {
+ expressionsPlugin = plugin;
+ }
+}
+
+function getFactory(name) {
+ switch (name) {
+ case "propertyFactory":
+ return PropertyFactory;
+ case "shapePropertyFactory":
+ return ShapePropertyFactory;
+ case "matrix":
+ return Matrix;
+ }
+}
+
+lottie.play = animationManager.play;
+lottie.pause = animationManager.pause;
+lottie.setLocationHref = setLocationHref;
+lottie.togglePause = animationManager.togglePause;
+lottie.setSpeed = animationManager.setSpeed;
+lottie.setDirection = animationManager.setDirection;
+lottie.stop = animationManager.stop;
+lottie.searchAnimations = searchAnimations;
+lottie.registerAnimation = animationManager.registerAnimation;
+lottie.loadAnimation = loadAnimation;
+lottie.setSubframeRendering = setSubframeRendering;
+lottie.resize = animationManager.resize;
+//lottie.start = start;
+lottie.goToAndStop = animationManager.goToAndStop;
+lottie.destroy = animationManager.destroy;
+lottie.setQuality = setQuality;
+lottie.inBrowser = inBrowser;
+lottie.installPlugin = installPlugin;
+lottie.freeze = animationManager.freeze;
+lottie.unfreeze = animationManager.unfreeze;
+lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations;
+lottie.__getFactory = getFactory;
+lottie.version = '[[BM_VERSION]]';
+
+function checkReady() {
+ if (document.readyState === "complete") {
+ clearInterval(readyStateCheckInterval);
+ searchAnimations();
+ }
+}
+
+function getQueryVariable(variable) {
+ var vars = queryString.split('&');
+ for (var i = 0; i < vars.length; i++) {
+ var pair = vars[i].split('=');
+ if (decodeURIComponent(pair[0]) == variable) {
+ return decodeURIComponent(pair[1]);
}
}
-
- function setSubframeRendering(flag) {
- subframeEnabled = flag;
- }
-
- function loadAnimation(params) {
- if (standalone === true) {
- params.animationData = JSON.parse(animationData);
- }
- return animationManager.loadAnimation(params);
- }
-
- function setQuality(value) {
- if (typeof value === 'string') {
- switch (value) {
- case 'high':
- defaultCurveSegments = 200;
- break;
- case 'medium':
- defaultCurveSegments = 50;
- break;
- case 'low':
- defaultCurveSegments = 10;
- break;
- }
- } else if (!isNaN(value) && value > 1) {
- defaultCurveSegments = value;
- }
- if (defaultCurveSegments >= 50) {
- roundValues(false);
- } else {
- roundValues(true);
- }
- }
-
- function inBrowser() {
- return typeof navigator !== 'undefined';
- }
-
- function installPlugin(type, plugin) {
- if (type === 'expressions') {
- expressionsPlugin = plugin;
- }
- }
-
- function getFactory(name) {
- switch (name) {
- case "propertyFactory":
- return PropertyFactory;
- case "shapePropertyFactory":
- return ShapePropertyFactory;
- case "matrix":
- return Matrix;
- }
- }
-
- lottiejs.play = animationManager.play;
- lottiejs.pause = animationManager.pause;
- lottiejs.setLocationHref = setLocationHref;
- lottiejs.togglePause = animationManager.togglePause;
- lottiejs.setSpeed = animationManager.setSpeed;
- lottiejs.setDirection = animationManager.setDirection;
- lottiejs.stop = animationManager.stop;
- lottiejs.searchAnimations = searchAnimations;
- lottiejs.registerAnimation = animationManager.registerAnimation;
- lottiejs.loadAnimation = loadAnimation;
- lottiejs.setSubframeRendering = setSubframeRendering;
- lottiejs.resize = animationManager.resize;
- //lottiejs.start = start;
- lottiejs.goToAndStop = animationManager.goToAndStop;
- lottiejs.destroy = animationManager.destroy;
- lottiejs.setQuality = setQuality;
- lottiejs.inBrowser = inBrowser;
- lottiejs.installPlugin = installPlugin;
- lottiejs.freeze = animationManager.freeze;
- lottiejs.unfreeze = animationManager.unfreeze;
- lottiejs.getRegisteredAnimations = animationManager.getRegisteredAnimations;
- lottiejs.__getFactory = getFactory;
- lottiejs.version = '[[BM_VERSION]]';
-
- function checkReady() {
- if (document.readyState === "complete") {
- clearInterval(readyStateCheckInterval);
- searchAnimations();
- }
- }
-
- function getQueryVariable(variable) {
- var vars = queryString.split('&');
- for (var i = 0; i < vars.length; i++) {
- var pair = vars[i].split('=');
- if (decodeURIComponent(pair[0]) == variable) {
- return decodeURIComponent(pair[1]);
- }
- }
- }
- var standalone = '__[STANDALONE]__';
- var animationData = '__[ANIMATIONDATA]__';
- var renderer = '';
- if (standalone) {
- var scripts = document.getElementsByTagName('script');
- var index = scripts.length - 1;
- var myScript = scripts[index] || {
- src: ''
- };
- var queryString = myScript.src.replace(/^[^\?]+\??/, '');
- renderer = getQueryVariable('renderer');
- }
- var readyStateCheckInterval = setInterval(checkReady, 100);
- return lottiejs;
-}));
+}
+var standalone = '__[STANDALONE]__';
+var animationData = '__[ANIMATIONDATA]__';
+var renderer = '';
+if (standalone) {
+ var scripts = document.getElementsByTagName('script');
+ var index = scripts.length - 1;
+ var myScript = scripts[index] || {
+ src: ''
+ };
+ var queryString = myScript.src.replace(/^[^\?]+\??/, '');
+ renderer = getQueryVariable('renderer');
+}
+var readyStateCheckInterval = setInterval(checkReady, 100);
diff --git a/tasks/build.js b/tasks/build.js
index 2f72553..208e092 100644
--- a/tasks/build.js
+++ b/tasks/build.js
@@ -635,11 +635,30 @@
})
}
+async function modularizeCode(code) {
+ return `(typeof navigator !== "undefined") && (function(root, factory) {
+ if (typeof define === "function" && define.amd) {
+ define(function() {
+ return factory(root);
+ });
+ } else if (typeof module === "object" && module.exports) {
+ module.exports = factory(root);
+ } else {
+ root.lottie = factory(root);
+ root.bodymovin = root.lottie;
+ }
+}((window || {}), function(window) {
+ ${code}
+return lottie;
+}));`
+}
+
async function buildVersion(scripts, version) {
const code = await concatScripts(scripts, version.build)
const wrappedCode = await wrapScriptWithModule(code, version.build)
const processedCode = await version.process(wrappedCode)
- const saved = await save(processedCode, version.fileName)
+ const modularizedCode = await modularizeCode(processedCode)
+ const saved = await save(modularizedCode, version.fileName)
return true
}