/* * medium-zoom-element v0.0.1 * Medium Zoom HTML Element * Copyright 2017 Francois Chalifour * https://github.com/francoischalifour/medium-zoom-element * MIT License */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.MediumZoomElement=t()}(this,function(){"use strict";function e(){return Reflect.construct(HTMLElement,[],this.__proto__.constructor)}var t=Object.assign||function(e){for(var t,o=1;oC.scrollOffset&&b(150)}},L=function(e){r.includes(e.keyCode||e.which)&&b()},O=function(){var e=Math.min;if(T.template){var t=window.innerWidth,o=window.innerHeight,n=t-2*C.margin,r=o-2*C.margin,i=T.zoomedHd||T.template,a=i.naturalWidth,c=void 0===a?n:a,u=i.naturalHeight,s=void 0===u?r:u,d=i.getBoundingClientRect(),l=d.top,m=d.left,f=d.width,p=d.height,h=e(e(c,n)/f,e(s,r)/p)||1,v="scale("+h+") translate3d("+((n-f)/2-m+C.margin)/h+"px, "+((r-p)/2-l+C.margin)/h+"px, 0)";T.zoomed.style.transform=v,T.zoomedHd&&(T.zoomedHd.style.transform=v)}},C={margin:l,background:f,scrollOffset:h,metaClick:void 0===v||v};e instanceof Object&&t(C,e);var H=function(e){try{return Array.isArray(e)?e.filter(i):c(e)?[].concat(o(e)).filter(i):u(e)?[e].filter(i):"string"==typeof e?[].concat(o(document.querySelectorAll(e))).filter(i):[].concat(o(document.querySelectorAll(n.map(function(e){return e.toLowerCase()}).join(",")))).filter(a)}catch(e){throw new TypeError("The provided selector is invalid.\nExpects a CSS selector, a Node element, a NodeList, an HTMLCollection or an array.\nSee: https://github.com/francoischalifour/medium-zoom")}}(e),x=function(e){var t=document.createElement("div");return t.classList.add("medium-zoom-overlay"),t.style.backgroundColor=e,t}(C.background),T={template:null,zoomed:null,zoomedHd:null},j=0,_=!1;return H.forEach(function(e){e.classList.add("medium-zoom-image"),e.addEventListener("click",w)}),x.addEventListener("click",b),document.addEventListener("scroll",A),document.addEventListener("keyup",L),window.addEventListener("resize",b),{show:z,hide:b,toggle:z,update:function(){var e=0\n :host {\n display: block;\n }\n img {\n max-width: 100%;\n }\n .medium-zoom-image {\n cursor: zoom-in;\n }\n\n\n";var f=function(t){function o(){i(this,o);var e=s(this,(o.__proto__||Object.getPrototypeOf(o)).call(this));return e.attachShadow({mode:"open"}),e.shadowRoot.appendChild(m.content.cloneNode(!0)),e.image=e.shadowRoot.querySelector("img"),e.zoom=r(e.image),Object.keys(e.zoom).forEach(function(t){return e[t]=e.zoom[t]}),e.setAttribute("role","img"),e.setAttribute("aria-label",e.alt),e}return u(o,e),a(o,null,[{key:"getOptionName",value:function(e){return"disable-metaclick"===e?"metaClick":l(e)}},{key:"observedOptions",get:function(){return["margin","background","scroll-offset","disable-metaclick","zoom-target"]}},{key:"observedAttributes",get:function(){return[].concat(d(o.observedOptions),["src","alt","width","height","style"])}}]),a(o,[{key:"disconnectedCallback",value:function(){this.zoom.detach()}},{key:"adoptedCallback",value:function(){this.zoom.hide()}},{key:"attributeChangedCallback",value:function(e,t,n){if(o.observedOptions.includes(e)){if("zoom-target"===e)return void this.image.setAttribute("data-zoom-target",n);this.zoom.update(c({},o.getOptionName(e),this[o.getOptionName(e)]))}else this.image.setAttribute(e,n)}},{key:"src",get:function(){return this.getAttribute("src")||""},set:function(e){this.setAttribute("src",e)}},{key:"alt",get:function(){return this.getAttribute("alt")||""},set:function(e){this.setAttribute("alt",e)}},{key:"zoomTarget",get:function(){return this.getAttribute("zoom-target")||""},set:function(e){e?this.setAttribute("zoom-target",e):this.removeAttribute("zoom-target")}},{key:"width",get:function(){return this.getAttribute("width")||""},set:function(e){e?this.setAttribute("width",e):this.removeAttribute("width")}},{key:"height",get:function(){return this.getAttribute("height")||""},set:function(e){e?this.setAttribute("height",e):this.removeAttribute("height")}},{key:"margin",get:function(){return Number(this.getAttribute("margin"))||""},set:function(e){e?this.setAttribute("margin",e):this.removeAttribute("margin")}},{key:"background",get:function(){return this.getAttribute("background")||""},set:function(e){e?this.setAttribute("background",e):this.removeAttribute("background")}},{key:"scrollOffset",get:function(){return this.hasAttribute("scroll-offset")?Number(this.getAttribute("scroll-offset")):""},set:function(e){null!==e?this.setAttribute("scroll-offset",Number(e)):this.removeAttribute("scroll-offset")}},{key:"metaClick",get:function(){return!this.hasAttribute("disable-metaclick")},set:function(e){e?this.setAttribute("disable-metaclick",e):this.removeAttribute("disable-metaclick")}}]),o}();return window.customElements.define("medium-zoom",f),f});