!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("phylocanvas")):"function"==typeof define&&define.amd?define(["phylocanvas"],e):"object"==typeof exports?exports.PhylocanvasHistoryPlugin=e(require("phylocanvas")):t.PhylocanvasHistoryPlugin=e(t.phylocanvas)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0}),n(1);var o=n(5),i=r(o);e["default"]=i["default"]},function(t,e,n){var r=n(2);"string"==typeof r&&(r=[[t.id,r,""]]);n(4)(r,{});r.locals&&(t.exports=r.locals)},function(t,e,n){e=t.exports=n(3)(),e.push([t.id,'.phylocanvas-history{position:absolute;top:0;bottom:0;left:0;box-sizing:border-box;width:240px;background:#fff;-webkit-transform:translateX(-240px);transform:translateX(-240px);-webkit-transform-style:preserve-3d;transform-style:preserve-3d;will-change:transform;-webkit-transition-duration:.2s;transition-duration:.2s;-webkit-transition-timing-function:cubic-bezier(.4,0,.2,1);transition-timing-function:cubic-bezier(.4,0,.2,1);-webkit-transition-property:-webkit-transform;transition-property:-webkit-transform;transition-property:transform;transition-property:transform,-webkit-transform;border:1px solid #e7e7e7;border-left:none}.phylocanvas-history--open{-webkit-transform:translateX(0);transform:translateX(0);box-shadow:0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12)}.phylocanvas-history-button{border:none;height:24px;line-height:24px;text-align:center;margin:auto;min-width:56px;width:56px;padding:0;overflow:hidden;background:#3c7383;color:#fff;box-shadow:0 1px 1.5px 0 rgba(0,0,0,.12),0 1px 1px 0 rgba(0,0,0,.24);position:relative;line-height:normal;position:absolute;bottom:16px;right:-57px;z-index:1;outline:none;cursor:pointer;border-radius:0 0 2px 2px;font-size:13px;font-family:Helvetica,Arial,sans-serif;-webkit-transform:rotate(-90deg);transform:rotate(-90deg);-webkit-transform-origin:top left;transform-origin:top left}.phylocanvas-history-snapshots{position:absolute;top:0;bottom:0;left:0;right:0;margin:0;padding:0;overflow-x:hidden;overflow-y:scroll}.phylocanvas-history-snapshot{list-style:none;border-bottom:1px solid #e7e7e7;cursor:pointer;box-sizing:border-box;display:block;position:relative;height:128px}.phylocanvas-history-snapshot:after{content:"";position:absolute;top:0;bottom:0;right:0;width:4px;background-color:transparent;-webkit-transition:background-color .2s cubic-bezier(.4,0,.2,1);transition:background-color .2s cubic-bezier(.4,0,.2,1)}.phylocanvas-history-snapshot--selected:after,.phylocanvas-history-snapshot:hover:after{background-color:#3c7383}.phylocanvas-history-snapshot>img{width:100%;height:128px;-o-object-fit:contain;object-fit:contain}',""])},function(t,e){t.exports=function(){var t=[];return t.toString=function(){for(var t=[],e=0;e<this.length;e++){var n=this[e];n[2]?t.push("@media "+n[2]+"{"+n[1]+"}"):t.push(n[1])}return t.join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},o=0;o<this.length;o++){var i=this[o][0];"number"==typeof i&&(r[i]=!0)}for(o=0;o<e.length;o++){var s=e[o];"number"==typeof s[0]&&r[s[0]]||(n&&!s[2]?s[2]=n:n&&(s[2]="("+s[2]+") and ("+n+")"),t.push(s))}},t}},function(t,e,n){function r(t,e){for(var n=0;n<t.length;n++){var r=t[n],o=f[r.id];if(o){o.refs++;for(var i=0;i<o.parts.length;i++)o.parts[i](r.parts[i]);for(;i<r.parts.length;i++)o.parts.push(c(r.parts[i],e))}else{for(var s=[],i=0;i<r.parts.length;i++)s.push(c(r.parts[i],e));f[r.id]={id:r.id,refs:1,parts:s}}}}function o(t){for(var e=[],n={},r=0;r<t.length;r++){var o=t[r],i=o[0],s=o[1],a=o[2],l=o[3],c={css:s,media:a,sourceMap:l};n[i]?n[i].parts.push(c):e.push(n[i]={id:i,parts:[c]})}return e}function i(t,e){var n=y(),r=g[g.length-1];if("top"===t.insertAt)r?r.nextSibling?n.insertBefore(e,r.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),g.push(e);else{if("bottom"!==t.insertAt)throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");n.appendChild(e)}}function s(t){t.parentNode.removeChild(t);var e=g.indexOf(t);e>=0&&g.splice(e,1)}function a(t){var e=document.createElement("style");return e.type="text/css",i(t,e),e}function l(t){var e=document.createElement("link");return e.rel="stylesheet",i(t,e),e}function c(t,e){var n,r,o;if(e.singleton){var i=m++;n=b||(b=a(e)),r=p.bind(null,n,i,!1),o=p.bind(null,n,i,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=l(e),r=h.bind(null,n),o=function(){s(n),n.href&&URL.revokeObjectURL(n.href)}):(n=a(e),r=u.bind(null,n),o=function(){s(n)});return r(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;r(t=e)}else o()}}function p(t,e,n,r){var o=n?"":r.css;if(t.styleSheet)t.styleSheet.cssText=x(e,o);else{var i=document.createTextNode(o),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(i,s[e]):t.appendChild(i)}}function u(t,e){var n=e.css,r=e.media;if(r&&t.setAttribute("media",r),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function h(t,e){var n=e.css,r=e.sourceMap;r&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var o=new Blob([n],{type:"text/css"}),i=t.href;t.href=URL.createObjectURL(o),i&&URL.revokeObjectURL(i)}var f={},d=function(t){var e;return function(){return"undefined"==typeof e&&(e=t.apply(this,arguments)),e}},v=d(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),y=d(function(){return document.head||document.getElementsByTagName("head")[0]}),b=null,m=0,g=[];t.exports=function(t,e){e=e||{},"undefined"==typeof e.singleton&&(e.singleton=v()),"undefined"==typeof e.insertAt&&(e.insertAt="bottom");var n=o(t);return r(n,e),function(t){for(var i=[],s=0;s<n.length;s++){var a=n[s],l=f[a.id];l.refs--,i.push(l)}if(t){var c=o(t);r(c,e)}for(var s=0;s<i.length;s++){var l=i[s];if(0===l.refs){for(var p=0;p<l.parts.length;p++)l.parts[p]();delete f[l.id]}}}};var x=function(){var t=[];return function(e,n){return t[e]=n,t.filter(Boolean).join("\n")}}()},function(t,e,n){"use strict";function r(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t){t(this,"createTree",function(t,e){var n=t.apply(void 0,r(e)),o=s(e,2),i=o[1],a=void 0===i?{}:i;return a.history!==!1&&(n.history=new m(n,a.history||{})),n}),this.History=m}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var s,a=t[Symbol.iterator]();!(r=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(l){o=!0,i=l}finally{try{!r&&a["return"]&&a["return"]()}finally{if(o)throw i}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),a=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();e["default"]=i;var l=n(6),c=l.utils.dom,p=c.addClass,u=c.removeClass,h=l.utils.events,f=h.fireEvent,d=h.addEvent,v=h.killEvent,y="phylocanvas-history-snapshot",b=y+"--selected",m=function(){function t(e,n){var r=this,i=n.parent,s=void 0===i?e.containerElement:i,a=n.zIndex,l=void 0===a?1:a;o(this,t),this.tree=e,this.snapshots=[],this.isOpen=!1,this.parent=s,this.buttonClickHandler=this.toggle.bind(this),this.container=this.createElements(s),this.container.style.zIndex=l,this.tree.addListener("subtree",function(t){var e=t.node;return r.addSnapshot(e)}),this.tree.addListener("loaded",function(){return r.addSnapshot(r.tree.root.id)}),this.tree.addListener("typechanged",function(){return r.addSnapshot(r.tree.root.id)})}return a(t,[{key:"toggle",value:function(){this.isOpen=!this.isOpen,(this.isOpen?p:u)(this.container,"phylocanvas-history--open"),this.parent[(this.isOpen?"add":"remove")+"EventListener"]("click",this.buttonClickHandler),f(this.tree.containerElement,"historytoggle",{isOpen:this.isOpen})}},{key:"createElements",value:function(t){var e=document.createElement("div");e.className="phylocanvas-history",d(e,"click",v),d(e,"contextmenu",v);var n=document.createElement("button");n.className="phylocanvas-history-button",n.innerHTML="History",d(n,"click",this.buttonClickHandler),e.appendChild(n),this.button=n;var r=document.createElement("ul");return r.className="phylocanvas-history-snapshots",e.appendChild(r),this.snapshotList=r,t.appendChild(e),e}},{key:"addSnapshot",value:function(t){if(t){var e=this.tree.treeType,n=!1;if(this.snapshots.forEach(function(r){u(r,b),r.getAttribute("data-tree-root")===t&&r.getAttribute("data-tree-type")===e&&(n=!0,p(r,b))}),!n){var r=this.tree.getPngUrl(),o=document.createElement("li");o.className=y+" "+b,o.setAttribute("data-tree-root",t),o.setAttribute("data-tree-type",this.tree.treeType),o.className=y+" "+b;var i=document.createElement("img");i.src=r,this.snapshots.push(o),o.appendChild(i),this.snapshotList.appendChild(o),d(o,"click",this.goBackTo.bind(this,o))}}}},{key:"clear",value:function(){for(var t=this.snapshots.length;t--;)this.snapshotList.removeChild(this.snapshots[t]);this.snapshots.length=0}},{key:"goBackTo",value:function(t){var e=t.getAttribute("data-tree-root");this.tree.setTreeType(t.getAttribute("data-tree-type"),!0),this.tree.redrawFromBranch(this.tree.originalTree.branches[e]),this.toggle()}}]),t}()},function(e,n){e.exports=t}])});