UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 6.47 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";var e;let o=t=>"object"==typeof t&&null!==t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t),n=t=>"string"==typeof t,a=function(t){var e=new DOMParser().parseFromString(t,"text/html").body;if(e.childElementCount>1){for(var o=document.createElement("div");e.firstChild;)o.appendChild(e.firstChild);return o}let n=e.firstChild;if(n&&!(n instanceof HTMLElement)){var o=document.createElement("div");return o.appendChild(n),o}return n},l={moveLeft:{tpl:'<button data-panzoom-action="moveLeft" class="f-button" title="{{MOVE_LEFT}}"><svg><path d="M5 12h14M5 12l6 6M5 12l6-6"/></svg></button>'},moveRight:{tpl:'<button data-panzoom-action="moveRight" class="f-button" title="{{MOVE_RIGHT}}"><svg><path d="M5 12h14M13 18l6-6M13 6l6 6"/></svg></button>'},moveUp:{tpl:'<button data-panzoom-action="moveUp" class="f-button" title="{{MOVE_UP}}"><svg><path d="M12 5v14M18 11l-6-6M6 11l6-6"/></svg></button>'},moveDown:{tpl:'<button data-panzoom-action="moveDown" class="f-button" title="{{MOVE_DOWN}}"><svg><path d="M12 5v14M18 13l-6 6M6 13l6 6"/></svg></button>'},zoomIn:{tpl:'<button data-panzoom-action="zoomIn" class="f-button" title="{{ZOOM_IN}}"><svg><circle cx="11" cy="11" r="7.5"/><path d="m21 21-4.35-4.35M11 8v6M8 11h6"/></svg></button>'},zoomOut:{tpl:'<button data-panzoom-action="zoomOut" class="f-button" title="{{ZOOM_OUT}}"><svg><circle cx="11" cy="11" r="7.5"/><path d="m21 21-4.35-4.35M8 11h6"/></svg></button>'},toggle1to1:{tpl:'<button data-panzoom-action="toggleFull" class="f-button" title="{{TOGGLE_FULL}}"><svg><path d="M3.51 3.07c5.74.02 11.48-.02 17.22.02 1.37.1 2.34 1.64 2.18 3.13 0 4.08.02 8.16 0 12.23-.1 1.54-1.47 2.64-2.79 2.46-5.61-.01-11.24.02-16.86-.01-1.36-.12-2.33-1.65-2.17-3.14 0-4.07-.02-8.16 0-12.23.1-1.36 1.22-2.48 2.42-2.46Z"/><path d="M5.65 8.54h1.49v6.92m8.94-6.92h1.49v6.92M11.5 9.4v.02m0 5.18v0"/></svg></button>'},toggleFull:{tpl:'<button data-panzoom-action="toggleFull" class="f-button" title="{{TOGGLE_FULL}}"><svg><g><line x1="11" y1="8" x2="11" y2="14"></line></g><circle cx="11" cy="11" r="7.5"/><path d="m21 21-4.35-4.35M8 11h6"/></svg></button>'},rotateCCW:{tpl:'<button data-panzoom-action="rotateCCW" class="f-button" title="{{ROTATE_CCW}}"><svg><path d="M15 4.55a8 8 0 0 0-6 14.9M9 15v5H4M18.37 7.16v.01M13 19.94v.01M16.84 18.37v.01M19.37 15.1v.01M19.94 11v.01"/></svg></button>'},rotateCW:{tpl:'<button data-panzoom-action="rotateCW" class="f-button" title="{{ROTATE_CW}}"><svg><path d="M9 4.55a8 8 0 0 1 6 14.9M15 15v5h5M5.63 7.16v.01M4.06 11v.01M4.63 15.1v.01M7.16 18.37v.01M11 19.94v.01"/></svg></button>'},flipX:{tpl:'<button data-panzoom-action="flipX" class="f-button" title="{{FLIP_X}}"><svg><path d="M12 3v18M16 7v10h5L16 7M8 7v10H3L8 7"/></svg></button>'},flipY:{tpl:'<button data-panzoom-action="flipY" class="f-button" title="{{FLIP_Y}}"><svg><path d="M3 12h18M7 16h10L7 21v-5M7 8h10L7 3v5"/></svg></button>'},reset:{tpl:'<button data-panzoom-action="reset" class="f-button" title="{{RESET}}"><svg><path d="M20 11A8.1 8.1 0 0 0 4.5 9M4 5v4h4M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"/></svg></button>'}},i=(t,...e)=>{let n=e.length;for(let a=0;a<n;a++)Object.entries(e[a]||{}).forEach(([e,n])=>{let a=Array.isArray(n)?[]:{};t[e]||Object.assign(t,{[e]:a}),o(n)?Object.assign(t[e],i(t[e],n)):Array.isArray(n)?Object.assign(t,{[e]:[...n]}):Object.assign(t,{[e]:n})});return t},s=((e={}).Left="left",e.middle="middle",e.right="right",e),u={counter:{tpl:'<div class="f-counter"><span data-carousel-page></span>/<span data-carousel-pages></span></div>'},download:{tpl:'<button data-carousel-download class="f-button" title="{{DOWNLOAD}}"><svg><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2M7 11l5 5 5-5M12 4v12"/></svg></button>'},autoplay:{tpl:'<button data-autoplay-action="toggle" class="f-button" title="{{TOGGLE_AUTOPLAY}}"><svg><g><path d="M5 3.5 19 12 5 20.5Z"/></g><g><path d="M8 4v15M17 4v15"/></g></svg></button>'},thumbs:{tpl:'<button data-thumbs-action="toggle" class="f-button" title="{{TOGGLE_THUMBS}}"><svg><rect width="18" height="14" x="3" y="3" rx="2"/><path d="M4 21h1M9 21h1M14 21h1M19 21h1"/></svg></button>'},...l},c={absolute:!1,display:{left:[],middle:["zoomIn","zoomOut","toggle1to1","rotateCCW","rotateCW","flipX","flipY","reset"],right:[]},enabled:"auto",items:{}};t.Toolbar=()=>{let t,e;function s(e){let n=t?.getOptions().Toolbar,a=(o(n)?{...c,...n}:c)[e];return a&&"function"==typeof a&&t?a(t):a}function r(){if(!t?.getOptions().Toolbar||!t||e)return;let o=s("enabled");if(!o)return;let c=s("absolute"),r=t.getSlides().length>1,d=!1,p=!1;for(let e of t.getSlides())e.panzoomRef&&(d=!0),(e.downloadSrc||"image"===e.type&&e.src)&&(p=!0);let g=t.getPlugins().Thumbs?.isEnabled()||!1,f=r&&t.getPlugins().Autoplay||!1,b=t.getPlugins().Fullscreen&&(document.fullscreenEnabled||document.webkitFullscreenEnabled);if("auto"===o&&(o=d),!o)return;(e=t.getContainer()?.querySelector(".f-carousel__toolbar")||void 0)||(e=document.createElement("div")).classList.add("f-carousel__toolbar");let v=s("display"),h=i({},u,s("items"));for(let o of["left","middle","right"]){let i=v[o]||[],s=document.createElement("div");for(let e of(s.classList.add("f-carousel__toolbar__column"),s.classList.add(`is-${o}`),i)){let o;if(n(e)){if("counter"===e&&!r||"autoplay"===e&&!f||l[e]&&!d||"fullscreen"===e&&!b||"thumbs"===e&&!g||"download"===e&&!p)continue;o=h[e]}if("object"==typeof e&&(o=e),o&&o.tpl){let e=t.localize(o.tpl),n=a(e=e.split("<svg>").join('<svg tabindex="-1" width="24" height="24" viewBox="0 0 24 24">'));n&&("function"==typeof o.click&&t&&n.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),"function"==typeof o.click&&t&&o.click(t,e)}),s.append(n))}}e.append(s)}if(e.childElementCount&&(!0===c&&e.classList.add("is-absolute"),t.getContainer()?.classList.add("has-toolbar"),!e.parentElement)){let o=s("parentEl");o?o.insertAdjacentElement("afterbegin",e):t.getViewport()?.insertAdjacentElement("beforebegin",e)}}return{init:function(e){(t=e).on("initSlides",r)},destroy:function(){t?.off("initSlides",r),t?.getContainer()?.classList.remove("has-toolbar"),e?.remove(),e=void 0},add:function(t,e){u[t]=e},isEnabled:function(){return!!e}}},t.ToolbarColumn=s});