From 82ded5004a7ecbe3789ae78acbc2367023034813 Mon Sep 17 00:00:00 2001 From: josephsmendoza Date: Sat, 17 Dec 2022 04:26:49 +0000 Subject: [PATCH] update jsdoc --- AssetLoader.mjs | 1 + docs/AssetLoader.mjs.html | 47 +++++++++++++++++++++++++++++------- docs/module-AssetLoader.html | 29 +++++++++++++++++++--- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/AssetLoader.mjs b/AssetLoader.mjs index 15df34c..72b65af 100644 --- a/AssetLoader.mjs +++ b/AssetLoader.mjs @@ -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] diff --git a/docs/AssetLoader.mjs.html b/docs/AssetLoader.mjs.html index bfb7aa7..65c7ea3 100644 --- a/docs/AssetLoader.mjs.html +++ b/docs/AssetLoader.mjs.html @@ -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
diff --git a/docs/module-AssetLoader.html b/docs/module-AssetLoader.html index 08de5d7..09fbd88 100644 --- a/docs/module-AssetLoader.html +++ b/docs/module-AssetLoader.html @@ -106,7 +106,7 @@ -

(static) loadAsset(dataURL, id)

+

(static) loadAsset(dataURL, id, unsafe)

@@ -193,6 +193,29 @@ + + + + unsafe + + + + + +Boolean + + + + + + + + + +

load assets directly into the DOM

+ + + @@ -230,7 +253,7 @@
Source:
@@ -282,7 +305,7 @@