UNPKG

5.06 kBJavaScriptView Raw
1var loadingSpinnerCode = `
2<style>
3 @keyframes spinner-line-fade-more{0%,100%{opacity:0}1%{opacity:1}}@keyframes spinner-line-fade-quick{0%,100%,39%{opacity:.25}40%{opacity:1}}@keyframes spinner-line-fade-default{0%,100%{opacity:.22}1%{opacity:1}}@keyframes spinner-line-shrink{0%,100%,25%{transform:scale(.5);opacity:.25}26%{transform:scale(1);opacity:1}}
4</style>
5<script>
6 var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,n=1,s=arguments.length;n<s;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},defaults={lines:12,length:7,width:5,radius:10,scale:1,corners:1,color:"#000",fadeColor:"transparent",animation:"spinner-line-fade-default",rotate:0,direction:1,speed:1,zIndex:2e9,className:"spinner",top:"50%",left:"50%",shadow:"0 0 1px transparent",position:"absolute"},Spinner=function(){function t(t){void 0===t&&(t={}),this.opts=__assign(__assign({},defaults),t)}return t.prototype.spin=function(t){return this.stop(),this.el=document.createElement("div"),this.el.className=this.opts.className,this.el.setAttribute("role","progressbar"),css(this.el,{position:this.opts.position,width:0,zIndex:this.opts.zIndex,left:this.opts.left,top:this.opts.top,transform:"scale("+this.opts.scale+")"}),t&&t.insertBefore(this.el,t.firstChild||null),drawLines(this.el,this.opts),this},t.prototype.stop=function(){return this.el&&("undefined"!=typeof requestAnimationFrame?cancelAnimationFrame(this.animateId):clearTimeout(this.animateId),this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=void 0),this},t}();function css(t,e){for(var n in e)t.style[n]=e[n];return t}function getColor(t,e){return"string"==typeof t?t:t[e%t.length]}function drawLines(t,e){var n=Math.round(e.corners*e.width*500)/1e3+"px",s="none";!0===e.shadow?s="0 2px 4px #000":"string"==typeof e.shadow&&(s=e.shadow);for(var i=parseBoxShadow(s),o=0;o<e.lines;o++){var r=~~(360/e.lines*o+e.rotate),a=css(document.createElement("div"),{position:"absolute",top:-e.width/2+"px",width:e.length+e.width+"px",height:e.width+"px",background:getColor(e.fadeColor,o),borderRadius:n,transformOrigin:"left",transform:"rotate("+r+"deg) translateX("+e.radius+"px)"}),d=o*e.direction/e.lines/e.speed;d-=1/e.speed;var h=css(document.createElement("div"),{width:"100%",height:"100%",background:getColor(e.color,o),borderRadius:n,boxShadow:normalizeShadow(i,r),animation:1/e.speed+"s linear "+d+"s infinite "+e.animation});a.appendChild(h),t.appendChild(a)}}function parseBoxShadow(t){for(var e=/^\s*([a-zA-Z]+\s+)?(-?\d+(\.\d+)?)([a-zA-Z]*)\s+(-?\d+(\.\d+)?)([a-zA-Z]*)(.*)$/,n=[],s=0,i=t.split(",");s<i.length;s++){var o=i[s].match(e);if(null!==o){var r=+o[2],a=+o[5],d=o[4],h=o[7];0!==r||d||(d=h),0!==a||h||(h=d),d===h&&n.push({prefix:o[1]||"",x:r,y:a,xUnits:d,yUnits:h,end:o[8]})}}return n}function normalizeShadow(t,e){for(var n=[],s=0,i=t;s<i.length;s++){var o=i[s],r=convertOffset(o.x,o.y,e);n.push(o.prefix+r[0]+o.xUnits+" "+r[1]+o.yUnits+o.end)}return n.join(", ")}function convertOffset(t,e,n){var s=n*Math.PI/180,i=Math.sin(s),o=Math.cos(s);return[Math.round(1e3*(t*o+e*i))/1e3,Math.round(1e3*(-t*i+e*o))/1e3]}
7
8 var loadingSpinner = new Spinner().spin();
9 document.getElementById('content').appendChild(loadingSpinner.el)
10</script>
11`;
12
13var generateIndexHtmlContent = ({
14 bootScriptPath = "",
15 bootScript = "",
16 resourceRoot = "https://openui5.hana.ondemand.com/resources/",
17 theme = "sap_belize",
18 projectNameSpace = "",
19 preload = false,
20 ui5ThemeRoot = {},
21 title = "UI5 Application",
22 inlineCssLink = [],
23 inlineJsSrc = [],
24 offline = false,
25 withLoadingSpinner = false,
26 resourceRoots = { projectNameSpace: "." }
27}) => {
28
29 var sapUiCodeLink = `${resourceRoot}sap-ui-core.js`;
30
31 if (!resourceRoot.endsWith("/")) {
32 resourceRoot = `${resourceRoot}/`;
33 }
34
35 if (offline) {
36 sapUiCodeLink = "./resources/sap-ui-core.js";
37 }
38
39 if (preload) {
40 inlineJsSrc.push("./preload.js");
41 inlineJsSrc.push("./Component-preload.js");
42 }
43
44 var jsSrcs = inlineJsSrc.map(l => `<script src="${l}"></script>`).join("\n");
45
46 var cssLinks = inlineCssLink
47 .map(l => `<link rel="stylesheet" href="${l}">`)
48 .join("\n");
49
50 var sBootScript = "";
51
52 if (bootScriptPath) {
53 sBootScript = `<script src="${bootScriptPath}"></script>`;
54 } else if (bootScript) {
55 sBootScript = `<script>${bootScript}</script>`;
56 }
57
58 return `<!DOCTYPE html>
59 <html>
60
61 <head>
62 <meta http-equiv="X-UA-Compatible" content="IE=edge">
63 <meta charset="utf-8">
64 <title>${title}</title>
65 </head>
66
67 <body class="sapUiBody" id="content"></body>
68
69${withLoadingSpinner ? loadingSpinnerCode : ""}
70<script
71 id="sap-ui-bootstrap"
72 src="${sapUiCodeLink}"
73 data-sap-ui-theme="${theme}"
74 data-sap-ui-compatVersion="edge"
75 data-sap-ui-resourceroots='${JSON.stringify(resourceRoots)}'
76 data-sap-ui-theme-roots='${JSON.stringify(ui5ThemeRoot)}'
77>
78</script>
79${jsSrcs}
80${sBootScript}
81${cssLinks}
82</html>`;
83};
84
85module.exports = { generateIndexHtmlContent };