!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PureRwdImageMaps=e():t.PureRwdImageMaps=e()}(this,(function(){return(()=>{"use strict";var t={};return(()=>{var e=t,r=function(){function t(t,e){void 0===e&&(e={}),this.loaded=!1,this.targetImgNaturalHeight=0,this.targetImgNaturalWidth=0,this.targetAreasNaturalCoords=[],this.resizeObserver=null,this.targetImg=t;var r=Object.assign({autoRwd:!0,vertical:!0,horizontal:!0},e);this.autoRwd=r.autoRwd,this.vertical=r.vertical,this.horizontal=r.horizontal;var i=t.getAttribute("usemap");if(!i)throw new Error('target image do not have "usemap" attribute.');this.name=i.replace("#","");var a=document.querySelector("map[name="+this.name+"]");if(!a)throw new Error('do not exist "map element".');this.targetMap=a;var o=a.querySelectorAll("area");if(o.length<=0)throw new Error('do not exist "area element".');this.targetAreas=o,t.addEventListener("load",this.init.bind(this))}return t.prototype.init=function(){this.targetImgNaturalWidth=this.targetImg.naturalWidth,this.targetImgNaturalHeight=this.targetImg.naturalHeight,this.targetAreasNaturalCoords=Array.from(this.targetAreas).map((function(t){return t.coords})),this.resizeObserver=new ResizeObserver(this.computeCoords.bind(this)),this.loaded=!0,this.autoRwd&&this.toRwd()},t.prototype.computeCoords=function(){for(var t=this.targetImg.offsetWidth,e=this.targetImg.offsetHeight,r=t/this.targetImgNaturalWidth,i=e/this.targetImgNaturalHeight,a=this.targetAreas.length;a--;){for(var o=this.targetAreasNaturalCoords[a].split(","),s=[],h=o.length;h--;){var n=Number(o[h]);h%2==0&&this.horizontal?s[h]=n*r:h%2!=0&&this.vertical?s[h]=n*i:s[h]=n}this.targetAreas[a].coords=s.join(",")}},t.prototype.resetCoords=function(){for(var t=this.targetAreas.length;t--;)this.targetAreas[t].coords=this.targetAreasNaturalCoords[t]},t.prototype.toRwd=function(){if(!this.loaded||!this.resizeObserver)throw new Error("do not finished initialization.");this.resizeObserver.observe(this.targetImg),this.computeCoords()},t.prototype.toStatic=function(){if(!this.loaded||!this.resizeObserver)throw new Error("do not finished initialization.");this.resizeObserver.disconnect(),this.resetCoords()},t}();e.default=r})(),t.default})()}));