111 lines
3.4 KiB
HTML
111 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>JSDoc: Source: AssetLoader.mjs</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"> </script>
|
|
<script src="scripts/prettify/lang-css.js"> </script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">Source: AssetLoader.mjs</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/** @module AssetLoader */
|
|
|
|
/**
|
|
* Loads a data url and returns the resulting element, font face, or when the type is unrecognized, a fetch response.
|
|
* @param {String} dataURL
|
|
* @param {String} id
|
|
*/
|
|
export async function loadAsset(dataURL,id=undefined){
|
|
const type=dataURL.split(';')[0].split(':')[1]
|
|
switch(type){
|
|
case 'text/css':{
|
|
const style=new HTMLStyleElement()
|
|
style.id=id
|
|
style.innerHTML=atob(dataURL.split(',')[1])
|
|
return style
|
|
}
|
|
case 'text/html':{
|
|
const element=new HTMLElement()
|
|
element.id=id
|
|
element.outerHTML=atob(dataURL.split(',')[1])
|
|
return element
|
|
}
|
|
case 'text/javascript':{
|
|
const script=new HTMLScriptElement()
|
|
script.id=id
|
|
script.innerHTML=atob(dataURL.split(',')[1])
|
|
return script
|
|
}
|
|
default:{
|
|
const mtype=type.split('/')[0]
|
|
switch(mtype){
|
|
case 'audio':{
|
|
const audio=new HTMLAudioElement()
|
|
audio.id=id
|
|
audio.src=dataURL
|
|
return audio
|
|
}
|
|
case 'font':{
|
|
return await new FontFace(id,dataURL).load()
|
|
}
|
|
case 'image':{
|
|
const img=new HTMLImageElement()
|
|
img.id=id
|
|
img.src=dataURL
|
|
return img
|
|
}
|
|
case 'video':{
|
|
const video=new HTMLVideoElement()
|
|
video.id=id
|
|
video.src=dataURL
|
|
}
|
|
default:{
|
|
return await fetch(dataURL)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export default loadAsset</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-AssetLoader.html">AssetLoader</a></li><li><a href="module-CSSRandom.html">CSSRandom</a></li><li><a href="module-FileReaderAsync.html">FileReaderAsync</a></li><li><a href="module-FormDataDeep.html">FormDataDeep</a></li><li><a href="module-fontScale.html">fontScale</a></li></ul><h3>Classes</h3><ul><li><a href="module-FileReaderAsync.FileReaderAsync.html">FileReaderAsync</a></li><li><a href="module-FormDataDeep.FormDataDeep.html">FormDataDeep</a></li></ul>
|
|
</nav>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Thu Dec 08 2022 17:50:32 GMT+0000 (Coordinated Universal Time)
|
|
</footer>
|
|
|
|
<script> prettyPrint(); </script>
|
|
<script src="scripts/linenumber.js"> </script>
|
|
</body>
|
|
</html>
|