UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 2.77 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={iframeAttr:{allow:"autoplay; fullscreen",scrolling:"auto"}};e.Html=()=>{let e;function i(e,t){let i=t.src;if("string"!=typeof i)return;let a=t.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 e=i.match(/(?:maps\.)?google\.([a-z]{2,3}(?:\.[a-z]{2})?)\/(?:(?:(?:maps\/(?:place\/(?:.*)\/)?\@(.*),(\d+.?\d+?)z))|(?:\?ll=))(.*)?/i);e&&(i=`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"}`,a="gmap")}if(!a){let e=i.match(/(?:maps\.)?google\.([a-z]{2,3}(?:\.[a-z]{2})?)\/(?:maps\/search\/)(.*)/i);e&&(i=`https://maps.google.${e[1]}/maps?q=${e[2].replace("query=","q=").replace("api=1","")}&output=embed`,a="gmap")}t.src=i,t.type=a}}function a(i,a){("iframe"===a.type||"pdf"===a.type||"gmap"===a.type)&&function(i){let a;if(!e||!i.el||!i.src)return;let l=document.createElement("iframe");for(let[i,o]of(l.classList.add("f-iframe"),Object.entries(("object"==typeof(a=e?.getOptions().Html)&&null!==a&&a.constructor===Object&&"[object Object]"===Object.prototype.toString.call(a)?{...t,...a}:t).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)}(a)}function l(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",i),e.on("attachSlideEl",a),e.on("detachSlideEl",l)},destroy:function(){e?.off("addSlide",i),e?.off("attachSlideEl",a),e?.off("detachSlideEl",l),e=void 0}}}});