UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 2.79 kB
!/*! License details at fancyapps.com/license */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,function(t){"use strict";let e={iframeAttr:{allow:"autoplay; fullscreen",scrolling:"auto"}};t.Html=()=>{let t;function i(t,e){let i=e.src;if("string"!=typeof i)return;let a=e.type;if(!a){if(!a&&("#"===i.charAt(0)?a="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)?a="image":i.match(/\.(pdf)((\?|#).*)?$/i)?a="pdf":i.match(/\.(html|php)((\?|#).*)?$/i)&&(a="iframe")),!a){let 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"}`,a="gmap")}if(!a){let 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`,a="gmap")}e.src=i,e.type=a}}function a(i,a){("iframe"===a.type||"pdf"===a.type||"gmap"===a.type)&&function(i){if(!t||!i.el||!i.src)return;let a=document.createElement("iframe");for(let[i,l]of(a.classList.add("f-iframe"),Object.entries(function(){let i=t?.getOptions().Html;return"object"==typeof i&&null!==i&&i.constructor===Object&&"[object Object]"===Object.prototype.toString.call(i)?{...e,...i}:e}().iframeAttr||{})))a.setAttribute(i,l);a.onerror=()=>{t&&1===t.getState()&&t.showError(i,"{{IFRAME_ERROR}}")},a.src=i.src;let l=document.createElement("div");if(l.classList.add("f-html"),l.append(a),i.width){let t=`${i.width}`;t.match(/^\d+$/)&&(t+="px"),l.style.maxWidth=`${t}`}if(i.height){let t=`${i.height}`;t.match(/^\d+$/)&&(t+="px"),l.style.maxHeight=`${t}`}if(i.aspectRatio){let t=i.el.getBoundingClientRect();l.style.aspectRatio=`${i.aspectRatio}`,l.style[t.width>t.height?"width":"height"]="auto",l.style[t.width>t.height?"maxWidth":"maxHeight"]="none"}i.contentEl=a,i.htmlEl=l,i.el.classList.add("has-html"),i.el.classList.add("has-iframe"),i.el.classList.add(`has-${i.type}`),i.el.prepend(l),t.emit("contentReady",i)}(a)}function l(e,i){("iframe"===i.type||"pdf"===i.type||"gmap"===i.type)&&(t?.hideError(i),i.contentEl?.remove(),i.contentEl=void 0,i.htmlEl?.remove(),i.htmlEl=void 0)}return{init:function(e){(t=e).on("addSlide",i),t.on("attachSlideEl",a),t.on("detachSlideEl",l)},destroy:function(){t?.off("addSlide",i),t?.off("attachSlideEl",a),t?.off("detachSlideEl",l),t=void 0}}}});