const t=(e,...i)=>{const n=i.length;for(let o=0;o{const o=Array.isArray(n)?[]:{};var s;e[i]||Object.assign(e,{[i]:o}),"object"==typeof(s=n)&&null!==s&&s.constructor===Object&&"[object Object]"===Object.prototype.toString.call(s)?Object.assign(e[i],t(o,n)):Array.isArray(n)?Object.assign(e,{[i]:[...n]}):Object.assign(e,{[i]:n})}))}return e},e=function(t,e){return t.split(".").reduce(((t,e)=>"object"==typeof t?t[e]:void 0),e)};class i{constructor(t={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"events",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.setOptions(t);for(const t of Object.getOwnPropertyNames(Object.getPrototypeOf(this)))t.startsWith("on")&&"function"==typeof this[t]&&(this[t]=this[t].bind(this))}setOptions(e){this.options=e?t({},this.constructor.defaults,e):{};for(const[t,e]of Object.entries(this.option("on")||{}))this.on(t,e)}option(t,...i){let n=e(t,this.options);return n&&"function"==typeof n&&(n=n.call(this,this,...i)),n}optionFor(t,i,n,...o){let s=e(i,t);var a;"string"!=typeof(a=s)||isNaN(a)||isNaN(parseFloat(a))||(s=parseFloat(s)),"true"===s&&(s=!0),"false"===s&&(s=!1),s&&"function"==typeof s&&(s=s.call(this,this,t,...o));let r=e(i,this.options);return r&&"function"==typeof r?s=r.call(this,this,t,...o,s):void 0===s&&(s=r),void 0===s?n:s}cn(t){const e=this.options.classes;return e&&e[t]||""}localize(t,e=[]){t=String(t).replace(/\{\{(\w+).?(\w+)?\}\}/g,((t,e,i)=>{let n="";return i?n=this.option(`${e[0]+e.toLowerCase().substring(1)}.l10n.${i}`):e&&(n=this.option(`l10n.${e}`)),n||(n=t),n}));for(let i=0;ie))}on(t,e){let i=[];"string"==typeof t?i=t.split(" "):Array.isArray(t)&&(i=t),this.events||(this.events=new Map),i.forEach((t=>{let i=this.events.get(t);i||(this.events.set(t,[]),i=[]),i.includes(e)||i.push(e),this.events.set(t,i)}))}off(t,e){let i=[];"string"==typeof t?i=t.split(" "):Array.isArray(t)&&(i=t),i.forEach((t=>{const i=this.events.get(t);if(Array.isArray(i)){const t=i.indexOf(e);t>-1&&i.splice(t,1)}}))}emit(t,...e){[...this.events.get(t)||[]].forEach((t=>t(this,...e))),"*"!==t&&this.emit("*",t,...e)}}Object.defineProperty(i,"version",{enumerable:!0,configurable:!0,writable:!0,value:"5.0.5"}),Object.defineProperty(i,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:{}});class n extends i{constructor(t,e){super(e),Object.defineProperty(this,"instance",{enumerable:!0,configurable:!0,writable:!0,value:t})}attach(){}detach(){}}const o={display:["zoomIn","zoomOut","toggle1to1","rotateCCW","rotateCW","flipX","flipY","reset","toggleFS"],items:{panLeft:{icon:'',change:{panX:-100}},panRight:{icon:'',change:{panX:100}},panUp:{icon:'',change:{panY:-100}},panDown:{icon:'',change:{panY:100}},zoomIn:{icon:'',action:"zoomIn"},zoomOut:{icon:'',action:"zoomOut"},toggle1to1:{icon:'',action:"toggleZoom"},toggleZoom:{icon:'',action:"toggleZoom"},iterateZoom:{icon:'',action:"iterateZoom"},rotateCCW:{icon:'',action:"rotateCCW"},rotateCW:{icon:'',action:"rotateCW"},flipX:{icon:'',action:"flipX"},flipY:{icon:'',action:"flipY"},fitX:{icon:'',action:"fitX"},fitY:{icon:'',action:"fitY"},reset:{icon:'',action:"reset"},toggleFS:{icon:'',action:"toggleFS"}},svgAttr:{tabindex:"-1",width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"}};class s extends n{constructor(){super(...arguments),Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null})}addItem(t){const e=this.option("items")[t];if(!e||!this.container)return;const i=document.createElement("button");i.setAttribute("title",e.title||this.instance.localize(`{{${t.toUpperCase()}}}`)),i.classList.add("f-button");const n=(o=this.instance.localize(e.icon),(new DOMParser).parseFromString(o,"text/html").body.firstChild);var o;if(n instanceof SVGElement)for(const[t,e]of Object.entries(this.option("svgAttr")))n.getAttribute(t)||n.setAttribute(t,String(e));i.appendChild(n),e.action&&(i.dataset.panzoomAction=e.action),e.change&&(i.dataset.panzoomChange=JSON.stringify(e.change)),e.click&&i.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e&&"function"==typeof e.click&&e.click(this.instance)})),this.container.appendChild(i)}createContainer(){if(this.container)return;const t=document.createElement("div");t.classList.add("f-panzoom__toolbar"),t.dataset.selectable="true",this.instance.container.prepend(t),this.container=t;for(const t of this.option("display"))this.addItem(t);this.instance.container.classList.add("has-toolbar")}removeContainer(){this.container&&this.container.remove(),this.container=null,this.instance.container.classList.remove("has-toolbar")}attach(){this.createContainer()}detach(){this.removeContainer()}}Object.defineProperty(s,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:o});export{s as Toolbar};