update jsdoc

This commit is contained in:
josephsmendoza
2022-12-17 04:26:49 +00:00
parent 4b923b0b88
commit 82ded5004a
3 changed files with 65 additions and 12 deletions
+1
View File
@@ -4,6 +4,7 @@
* 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
* @param {Boolean} unsafe load assets directly into the DOM
*/
export async function loadAsset(dataURL,id=undefined,unsafe=false){
const type=dataURL.split(';')[0].split(':')[1]
+38 -9
View File
@@ -32,52 +32,81 @@
* 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
* @param {Boolean} unsafe load assets directly into the DOM
*/
export async function loadAsset(dataURL,id=undefined){
export async function loadAsset(dataURL,id=undefined,unsafe=false){
const type=dataURL.split(';')[0].split(':')[1]
switch(type){
case 'text/css':{
const style=new HTMLStyleElement()
const style=document.createElement('style')
style.id=id
style.innerHTML=atob(dataURL.split(',')[1])
if(unsafe){
return document.body.appendChild(style)
}
return style
}
case 'text/html':{
const element=new HTMLElement()
const element=document.createElement('span')
element.innerHTML=atob(dataURL.split(',')[1])
element.id=id
element.outerHTML=atob(dataURL.split(',')[1])
if(unsafe){
for(const script of element.querySelectorAll('script')){
import('data:text/javascript,'+script.innerHTML)
}
return document.body.appendChild(element)
}
return element
}
case 'text/javascript':{
const script=new HTMLScriptElement()
const script=document.createElement('script')
script.id=id
script.innerHTML=atob(dataURL.split(',')[1])
if(unsafe){
import('data:text/javascript,'+script.innerHTML)
}
return script
}
default:{
const mtype=type.split('/')[0]
switch(mtype){
case 'audio':{
const audio=new HTMLAudioElement()
const audio=document.createElement('audio')
audio.id=id
audio.src=dataURL
if(unsafe){
return document.body.appendChild(audio)
}
return audio
}
case 'font':{
if(unsafe){
document.fonts.add(await new FontFace(id,dataURL).load())
}
return await new FontFace(id,dataURL).load()
}
case 'image':{
const img=new HTMLImageElement()
const img=document.createElement('img')
img.id=id
img.src=dataURL
if(unsafe){
return document.body.appendChild(img)
}
return img
}
case 'video':{
const video=new HTMLVideoElement()
const video=document.createElement('video')
video.id=id
video.src=dataURL
if(unsafe){
return document.body.appendChild(video)
}
return video
}
default:{
if(unsafe){
window[id]=await fetch(dataURL)
}
return await fetch(dataURL)
}
}
@@ -101,7 +130,7 @@ export default loadAsset</code></pre>
<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)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Sat Dec 17 2022 04:25:00 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
+26 -3
View File
@@ -106,7 +106,7 @@
<h4 class="name" id=".loadAsset"><span class="type-signature">(static) </span>loadAsset<span class="signature">(dataURL, id)</span><span class="type-signature"></span></h4>
<h4 class="name" id=".loadAsset"><span class="type-signature">(static) </span>loadAsset<span class="signature">(dataURL, id, unsafe)</span><span class="type-signature"></span></h4>
@@ -193,6 +193,29 @@
</tr>
<tr>
<td class="name"><code>unsafe</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="description last"><p>load assets directly into the DOM</p></td>
</tr>
</tbody>
</table>
@@ -230,7 +253,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="AssetLoader.mjs.html">AssetLoader.mjs</a>, <a href="AssetLoader.mjs.html#line8">line 8</a>
<a href="AssetLoader.mjs.html">AssetLoader.mjs</a>, <a href="AssetLoader.mjs.html#line9">line 9</a>
</li></ul></dd>
@@ -282,7 +305,7 @@
<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)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Sat Dec 17 2022 04:25:00 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>