@fancyapps/ui
Version:
Robust JavaScript UI Component Library
1 lines • 4.1 kB
JavaScript
!/*! License details at fancyapps.com/license */function(t,e){"object"==typeof exports&&"u">typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="u">typeof globalThis?globalThis:t||self).window=t.window||{})}(this,function(t){"use strict";let e=(t,e="")=>{t&&t.classList&&e.split(" ").forEach(e=>{e&&t.classList.add(e)})},a={autosize:!1,iframeAttr:{allow:"autoplay; fullscreen",scrolling:"auto"},preload:!1};t.Html=()=>{let t;function i(){let e=t?.getOptions().Html;return"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e)?{...a,...e}:a}function o(t,e){let a=t[e];return void 0===a&&(a=i()[e]),"true"===a||"false"!==a&&a}function l(t,e){let a=e.type,i=e.src;if(!a&&"string"==typeof i){if("#"===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")}a&&(e.src=i,e.type=a)}}function n(a,l){("iframe"===l.type||"pdf"===l.type||"gmap"===l.type)&&function(a){let l=a.el,n=a.src;if(!t||!l||!n)return;let r=document.createElement("iframe");for(let[t,a]of(e(r,"f-iframe"),Object.entries(i().iframeAttr||{})))r.setAttribute(t,a);r.onerror=()=>{a.state=2,t?.showError(a,"{{IFRAME_ERROR}}")};let d=document.createElement("div");if(e(d,"f-html"),d.append(r),a.width){let t=`${a.width}`;t.match(/^\d+$/)&&(t+="px"),d.style.maxWidth=`${t}`}if(a.height){let t=`${a.height}`;t.match(/^\d+$/)&&(t+="px"),d.style.maxHeight=`${t}`}if(a.aspectRatio){let t=l.getBoundingClientRect();d.style.aspectRatio=`${a.aspectRatio}`,d.style[t.width>t.height?"width":"height"]="auto",d.style[t.width>t.height?"maxWidth":"maxHeight"]="none"}a.htmlEl=d,a.contentEl=r,e(l,`has-html has-iframe has-${a.type}`),l.prepend(d);let s=o(a,"preload"),p=o(a,"autosize");"iframe"===a.type&&(s||p)?(a.state=0,t.showLoading(a),e(l,"is-loading"),r.onload=()=>{if(!t||1!==t.getState()||!r.src.length)return;a.state=1;let e="true"!==r.dataset.ready;r.dataset.ready="true",function(t){let e=t.contentEl,a=e?.parentElement,i=a?.style,l=o(t,"autosize"),n=t.width||0,r=t.height||0;if(n&&r&&(l=!1),e&&a&&i&&l){try{let t=window.getComputedStyle(a),o=parseFloat(t.paddingLeft)+parseFloat(t.paddingRight),l=parseFloat(t.paddingTop)+parseFloat(t.paddingBottom),d=e.contentWindow;if(d){let t=d.document,e=t.getElementsByTagName("html")[0],a=t.body;i.width="";let s=window.getComputedStyle(a),p=parseFloat(s.marginLeft)+parseFloat(s.marginRight),c=a.style.overflow||"";a.style.overflow="hidden",n=n||a.scrollWidth+p+o,i.flex="0 0 auto",i.width=`${n}px`,i.height=`${a.scrollHeight}px`,a.style.overflow=c,r=Math.max(e.scrollHeight,Math.ceil(e.getBoundingClientRect().height))+l}}catch(t){}if(n||r){let t={flex:"0 1 auto",width:"",height:""};n&&"auto"!==n&&(t.width=`${n}px`),r&&"auto"!==r&&(t.height=`${r}px`),Object.assign(i,t)}}}(a),t.hideLoading(a),e&&t.emit("contentReady",a),((t,e="")=>{t&&t.classList&&e.split(" ").forEach(e=>{e&&t.classList.remove(e)})})(l,"is-loading")},r.src=`${n}`):(r.src=`${n}`,t.emit("contentReady",a))}(l)}function r(e,a){("iframe"===a.type||"pdf"===a.type||"gmap"===a.type)&&(t?.hideError(a),a.contentEl?.remove(),a.contentEl=void 0,a.htmlEl?.remove(),a.htmlEl=void 0)}return{init:function(e){(t=e).on("addSlide",l),t.on("attachSlideEl",n),t.on("detachSlideEl",r)},destroy:function(){t?.off("addSlide",l),t?.off("attachSlideEl",n),t?.off("detachSlideEl",r),t=void 0}}}});