@fancyapps/ui
Version:
Robust JavaScript UI Component Library
3 lines (2 loc) • 2.68 kB
JavaScript
/*! License details at fancyapps.com/license */
import{isPlainObject as t}from"../utils/isPlainObject.js";import{isString as e}from"../utils/isString.js";const a={iframeAttr:{allow:"autoplay; fullscreen",scrolling:"auto"}},i=()=>{let i;function l(t,a){let i=a.src;if(!e(i))return;let l=a.type;if(!l){if(l||("#"===i.charAt(0)?l="inline":i.match(/(^data:image\/[a-z0-9+\/=]*,)|(\.((a)?png|avif|gif|jp(g|eg)|pjp(eg)?|jfif|svg|webp|bmp|ico|tif(f)?)((\?|#).*)?$)/i)?l="image":i.match(/\.(pdf)((\?|#).*)?$/i)?l="pdf":i.match(/\.(html|php)((\?|#).*)?$/i)&&(l="iframe")),!l){const t=i.match(/(?:maps\.)?google\.([a-z]{2,3}(?:\.[a-z]{2})?)\/(?:(?:(?:maps\/(?:place\/(?:.*)\/)?\@(.*),(\d+.?\d+?)z))|(?:\?ll=))(.*)?/i);t&&(i=`https://maps.google.${t[1]}/?ll=${(t[2]?t[2]+"&z="+Math.floor(parseFloat(t[3]))+(t[4]?t[4].replace(/^\//,"&"):""):t[4]+"").replace(/\?/,"&")}&output=${t[4]&&t[4].indexOf("layer=c")>0?"svembed":"embed"}`,l="gmap")}if(!l){const t=i.match(/(?:maps\.)?google\.([a-z]{2,3}(?:\.[a-z]{2})?)\/(?:maps\/search\/)(.*)/i);t&&(i=`https://maps.google.${t[1]}/maps?q=${t[2].replace("query=","q=").replace("api=1","")}&output=embed`,l="gmap")}a.src=i,a.type=l}}function o(e,l){"iframe"!==l.type&&"pdf"!==l.type&&"gmap"!==l.type||function(e){if(!i||!e.el||!e.src)return;const l=document.createElement("iframe");l.classList.add("f-iframe");for(const[e,o]of Object.entries(function(){const e=null==i?void 0:i.getOptions().Html;return t(e)?Object.assign(Object.assign({},a),e):a}().iframeAttr||{}))l.setAttribute(e,o);l.onerror=()=>{i&&1===i.getState()&&i.showError(e,"{{IFRAME_ERROR}}")},l.src=e.src;const o=document.createElement("div");if(o.classList.add("f-html"),o.append(l),e.width){let t=`${e.width}`;t.match(/^\d+$/)&&(t+="px"),o.style.maxWidth=`${t}`}if(e.height){let t=`${e.height}`;t.match(/^\d+$/)&&(t+="px"),o.style.maxHeight=`${t}`}if(e.aspectRatio){const t=e.el.getBoundingClientRect();o.style.aspectRatio=`${e.aspectRatio}`,o.style[t.width>t.height?"width":"height"]="auto",o.style[t.width>t.height?"maxWidth":"maxHeight"]="none"}e.contentEl=l,e.htmlEl=o,e.el.classList.add("has-html"),e.el.classList.add("has-iframe"),e.el.classList.add(`has-${e.type}`),e.el.prepend(o),i.emit("contentReady",e)}(l)}function n(t,e){var a,l;"iframe"!==e.type&&"pdf"!==e.type&&"gmap"!==e.type||(null==i||i.hideError(e),null===(a=e.contentEl)||void 0===a||a.remove(),e.contentEl=void 0,null===(l=e.htmlEl)||void 0===l||l.remove(),e.htmlEl=void 0)}return{init:function(t){i=t,i.on("addSlide",l),i.on("attachSlideEl",o),i.on("detachSlideEl",n)},destroy:function(){null==i||i.off("addSlide",l),null==i||i.off("attachSlideEl",o),null==i||i.off("detachSlideEl",n),i=void 0}}};export{i as Html};