@fancyapps/ui
Version:
Robust JavaScript UI Component Library
3 lines (2 loc) • 1.34 kB
JavaScript
/*! License details at fancyapps.com/license */
const n=".f-panzoom__pin",t=()=>{let t,e=[];function o(){return!1!==(null==t?void 0:t.getOptions().Pins)}function r(){!function(){var r,i;const l=null==t?void 0:t.getContainer(),a=null==t?void 0:t.getWrapper();if(!l||!o())return;e=[];const f=Array.from(l.querySelectorAll(n));for(const n of f)e.push({x:null!==(r=n.dataset.x)&&void 0!==r?r:"0",y:null!==(i=n.dataset.y)&&void 0!==i?i:"0",el:n}),a&&n.parentElement!==a&&a.appendChild(n)}(),a()}function i(){a()}function l(n,t,e){const o=String(n),r=parseFloat(o);return Number.isFinite(r)?o.includes("%")?e*(r/100):t?r/t*e:0:0}function a(){var n;if(!t||!e.length||!o())return;const{width:r,height:i}=t.getFullDim(),a=t.getTransform(),f=null===(n=t.getWrapper())||void 0===n?void 0:n.getBoundingClientRect();if(!f)return;const s=a.angle||0,u=a.flipX||1,c=a.flipY||1,d=a.x||0,p=a.y||0,g=a.scale||1,y=f.width,m=f.height,v=new DOMMatrix([g,0,0,g,d,p]).scale(u,1).scale(1,c).rotate(s);for(const n of e){const t=l(n.x,r,y)-.5*y,e=l(n.y,i,m)-.5*m,o=new DOMPoint(t,e).matrixTransform(v);n.el.style.transform=`translate3d(${o.x}px, ${o.y}px, 0)`}}return{init:function(n){t=n,t.on("ready",r),t.on("render",i)},destroy:function(){null==t||t.off("ready",r),null==t||t.off("render",i);for(const n of e)n.el.style.transform="";t=void 0,e=[]}}};export{t as Pins};