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. * 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} dataURL
* @param {String} id * @param {String} id
* @param {Boolean} unsafe load assets directly into the DOM
*/ */
export async function loadAsset(dataURL,id=undefined,unsafe=false){ export async function loadAsset(dataURL,id=undefined,unsafe=false){
const type=dataURL.split(';')[0].split(':')[1] 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. * 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} dataURL
* @param {String} id * @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] const type=dataURL.split(';')[0].split(':')[1]
switch(type){ switch(type){
case 'text/css':{ case 'text/css':{
const style=new HTMLStyleElement() const style=document.createElement('style')
style.id=id style.id=id
style.innerHTML=atob(dataURL.split(',')[1]) style.innerHTML=atob(dataURL.split(',')[1])
if(unsafe){
return document.body.appendChild(style)
}
return style return style
} }
case 'text/html':{ case 'text/html':{
const element=new HTMLElement() const element=document.createElement('span')
element.innerHTML=atob(dataURL.split(',')[1])
element.id=id 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 return element
} }
case 'text/javascript':{ case 'text/javascript':{
const script=new HTMLScriptElement() const script=document.createElement('script')
script.id=id script.id=id
script.innerHTML=atob(dataURL.split(',')[1]) script.innerHTML=atob(dataURL.split(',')[1])
if(unsafe){
import('data:text/javascript,'+script.innerHTML)
}
return script return script
} }
default:{ default:{
const mtype=type.split('/')[0] const mtype=type.split('/')[0]
switch(mtype){ switch(mtype){
case 'audio':{ case 'audio':{
const audio=new HTMLAudioElement() const audio=document.createElement('audio')
audio.id=id audio.id=id
audio.src=dataURL audio.src=dataURL
if(unsafe){
return document.body.appendChild(audio)
}
return audio return audio
} }
case 'font':{ case 'font':{
if(unsafe){
document.fonts.add(await new FontFace(id,dataURL).load())
}
return await new FontFace(id,dataURL).load() return await new FontFace(id,dataURL).load()
} }
case 'image':{ case 'image':{
const img=new HTMLImageElement() const img=document.createElement('img')
img.id=id img.id=id
img.src=dataURL img.src=dataURL
if(unsafe){
return document.body.appendChild(img)
}
return img return img
} }
case 'video':{ case 'video':{
const video=new HTMLVideoElement() const video=document.createElement('video')
video.id=id video.id=id
video.src=dataURL video.src=dataURL
if(unsafe){
return document.body.appendChild(video)
}
return video
} }
default:{ default:{
if(unsafe){
window[id]=await fetch(dataURL)
}
return await fetch(dataURL) return await fetch(dataURL)
} }
} }
@@ -101,7 +130,7 @@ export default loadAsset</code></pre>
<br class="clear"> <br class="clear">
<footer> <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> </footer>
<script> prettyPrint(); </script> <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>
<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> </tbody>
</table> </table>
@@ -230,7 +253,7 @@
<dt class="tag-source">Source:</dt> <dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li> <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> </li></ul></dd>
@@ -282,7 +305,7 @@
<br class="clear"> <br class="clear">
<footer> <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> </footer>
<script> prettyPrint(); </script> <script> prettyPrint(); </script>