UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

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