UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

2 lines 4.1 kB
/*! License details at fancyapps.com/license */ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.window=e.window||{}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=e=>typeof e==`object`&&!!e&&e.constructor===Object&&Object.prototype.toString.call(e)===`[object Object]`,n=(e,...r)=>{let i=r.length;for(let a=0;a<i;a++){let i=r[a]||{};Object.entries(i).forEach(([r,i])=>{let a=Array.isArray(i)?[]:{};e[r]||Object.assign(e,{[r]:a}),t(i)?Object.assign(e[r],n(e[r],i)):Array.isArray(i)?Object.assign(e,{[r]:[...i]}):Object.assign(e,{[r]:i})})}return e},r=function(e){var t=new DOMParser().parseFromString(e,`text/html`).body;if(t.childElementCount>1){for(var n=document.createElement(`div`);t.firstChild;)n.appendChild(t.firstChild);return n}let r=t.firstChild;if(r&&!(r instanceof HTMLElement)){var n=document.createElement(`div`);return n.appendChild(r),n}return r},i=`<circle cx="11" cy="11" r="7.5"/><path d="m21 21-4.35-4.35M8 11h6"/>`,a=`<g><line x1="11" y1="8" x2="11" y2="14"></line></g>`+i,o={moveLeft:[`moveLeft`,`MOVE_LEFT`,`<path d="M5 12h14M5 12l6 6M5 12l6-6"/>`],moveRight:[`moveRight`,`MOVE_RIGHT`,`<path d="M5 12h14M13 18l6-6M13 6l6 6"/>`],moveUp:[`moveUp`,`MOVE_UP`,`<path d="M12 5v14M18 11l-6-6M6 11l6-6"/>`],moveDown:[`moveDown`,`MOVE_DOWN`,`<path d="M12 5v14M18 13l-6 6M6 13l6 6"/>`],zoomOut:[`zoomOut`,`ZOOM_OUT`,i],zoomIn:[`zoomIn`,`ZOOM_IN`,a],toggleFull:[`toggleFull`,`TOGGLE_FULL`,a],iterateZoom:[`iterateZoom`,`ITERATE_ZOOM`,a],toggle1to1:[`toggleFull`,`TOGGLE_FULL`,`<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"/>`],rotateCCW:[`rotateCCW`,`ROTATE_CCW`,`<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"/>`],rotateCW:[`rotateCW`,`ROTATE_CW`,`<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"/>`],flipX:[`flipX`,`FLIP_X`,`<path d="M12 3v18M16 7v10h5L16 7M8 7v10H3L8 7"/>`],flipY:[`flipY`,`FLIP_Y`,`<path d="M3 12h18M7 16h10L7 21v-5M7 8h10L7 3v5"/>`],reset:[`reset`,`RESET`,`<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"/>`],toggleFS:[`toggleFS`,`TOGGLE_FS`,`<g><path d="M14.5 9.5 21 3m0 0h-6m6 0v6M3 21l6.5-6.5M3 21v-6m0 6h6"/></g><g><path d="m14 10 7-7m-7 7h6m-6 0V4M3 21l7-7m0 0v6m0-6H4"/></g>`]},s={};for(let e of Object.keys(o)){let t=o[e];s[e]={tpl:`<button data-panzoom-action="${t[0]}" class="f-button" title="{{${t[1]}}}"><svg>${t[2]}</svg></button>`}}let c={...s},l={display:[`zoomIn`,`zoomOut`,`toggle1to1`,`rotateCCW`,`rotateCW`,`flipX`,`flipY`,`reset`],items:{},svgAttr:{tabindex:`-1`,width:`24`,height:`24`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`}};e.Controls=()=>{let e,i;function a(){let r=e?.getOptions().Controls;return r===!1?!1:t(r)?n({},l,r):n({},l)}function o(e,t){let n=e.querySelector(`svg`);if(n)for(let[e,r]of Object.entries(t))n.getAttribute(e)||n.setAttribute(e,String(r))}function s(t,n){typeof n.click==`function`&&t.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e&&typeof n.click==`function`&&n.click(e,t)})}function u(){let t=a();if(!e||t===!1||i)return;i=document.createElement(`div`),i.classList.add(`f-controls`);let n={...c,...t.items};for(let a of t.display){let c=n[a];if(!c?.tpl)continue;let l=r(e.localize(c.tpl));l&&(o(l,t.svgAttr),s(l,c),i.append(l))}i.childElementCount&&(e.getContainer()?.classList.add(`has-controls`),e.getContainer()?.insertAdjacentElement(`afterbegin`,i))}let d={init:function(t){e=t,e.on(`initLayout`,u)},destroy:function(){e?.off(`initLayout`,u),e?.getContainer()?.classList.remove(`has-controls`),i?.remove(),i=void 0,e=void 0},add:function(e,t){return c[e]=t,d}};return d}});