!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("d3-random"),require("d3-selection"),require("d3-shape"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define("nls-guilloche",["exports","@angular/core","d3-random","d3-selection","d3-shape","@angular/platform-browser"],e):e(t["nls-guilloche"]={},t.ng.core,null,null,null,t.ng.platformBrowser)}(this,function(t,i,a,r,n,e){"use strict";function h(n,r){var i,a,s,t,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),"throw":e(1),"return":e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,a&&(s=2&t[0]?a["return"]:t[0]?a["throw"]||((s=a["return"])&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return o.label++,{value:t[1],done:!1};case 5:o.label++,a=t[1],t=[0];continue;case 7:t=o.ops.pop(),o.trys.pop();continue;default:if(!(s=0<(s=o.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){o=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]this.Δ(t,e.end)?e.start:e.end},t.prototype.randomPoint=function(t,e){var n={min:t.center.x-t.width*e,max:t.center.x+t.width*e},r={min:t.center.y-t.height*e,max:t.center.y+t.height*e};return{x:a.randomUniform(n.min,n.max)(),y:a.randomUniform(r.min,r.max)()}},t.prototype.centerOfArea=function(t,e){return{x:.5*t,y:.5*e}},t.prototype.centerOfPoints=function(t,e){return{x:.5*(t.x+e.x),y:.5*(t.y+e.y)}},t.prototype.centerOfCurve=function(t){var e=this.medianPoint(t),n=e.next().value,r=e.next().value,i=this.angleRadians(n,r);return Object.assign(this.centerOfPoints(n,r),{ascent:i})},t.prototype.medianOfCurve=function(t){var e=this.medianPoint(t),n=e.next().value,r=e.next().value,i=e.next().value,a=this.angleRadians(r,i);return Object.assign(n,{ascent:a})},t.prototype.angleRadians=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.prototype.angleDegree=function(t,e){return 180*this.angleRadians(t,e)/Math.PI},t.prototype.medianIndex=function(t){return Math.floor(.5*t.length)},t.prototype.medianPoint=function(e){var n,r;return h(this,function(t){switch(t.label){case 0:r=e.slice(),t.label=1;case 1:return r?(n=this.medianIndex(e),[4,r[n]]):[3,3];case 2:return t.sent(),r.splice(n,1),[3,1];case 3:return[2]}})},t.prototype.bounce=function(e,n,r){var i,a,s,o;return void 0===e&&(e=1),void 0===n&&(n=1),void 0===r&&(r=0),h(this,function(t){switch(t.label){case 0:i=Math.pow(10,n),a=2/i,s=0,t.label=1;case 1:return o=Math.PI*a*s+r,[4,Math.round(Math.sin(o)*e*i)/i];case 2:return t.sent(),s++,[3,1];case 3:return[2]}})},t.prototype.flipSign=function(e){var n;return void 0===e&&(e=!0),h(this,function(t){switch(t.label){case 0:n=e?1:-1,t.label=1;case 1:return[4,n*=-1];case 2:return t.sent(),[3,1];case 3:return[2]}})},t.decorators=[{type:i.Injectable}],t}(),l=function(){function t(t){this.math=t}return t.prototype.get=function(){return this.graphs},t.prototype.set=function(t){this.graphs=t},Object.defineProperty(t.prototype,"isAnimated",{get:function(){return this.animation},enumerable:!0,configurable:!0}),t.prototype.startAnimation=function(){this.animation=!0},t.prototype.stopAnimation=function(){this.animation=!1},t.prototype.spreadOrthogonal=function(e,n){var r,i,a,s;return h(this,function(t){switch(t.label){case 0:r=this.math.flipSign(),i=e,a=0,t.label=1;case 1:return s=r.next().value*n*a,[4,i=this.shiftPoint(i,e.ascent,s)];case 2:return t.sent(),a++,[3,1];case 3:return[2]}})},t.prototype.shiftPoint=function(t,e,n){return{x:Math.sin(e*Math.PI)*n+t.x,y:Math.cos(e*Math.PI)*n+t.y}},t.decorators=[{type:i.Injectable}],t.ctorParameters=function(){return[{type:u}]},t}(),f=function(){function t(t,e,n,r){this.canvasService=t,this.historyService=e,this.math=n,this.graphService=r,this.svgChange=new i.EventEmitter,this.graphChange=new i.EventEmitter,this.genLoadedAllGraphs=this.countLoadedGraphs(),this.resizingWindow=!1}return t.prototype.onResize=function(t){var e=this;clearTimeout(this.resizingWindow),this.resizingWindow=setTimeout(function(){e.canvas=e.adjustCanvas(),e.matrix=e.calcMatrix(),e.updateGraphs()},800)},t.prototype.ngOnChanges=function(t){this.canvas=this.adjustCanvas(),this.matrix=this.calcMatrix(),t.config&&this.updateGraphs(),this.restoredHistory&&this.restoredHistory.hash!==this.hash&&this.restoreGraph()},t.prototype.restoreGraph=function(){this.graphs=this.restoredHistory.graphs,this.hash=this.restoredHistory.hash},t.prototype.saveHistory=function(){this.hash=this.historyService.hash(this.graphs),this.historyService.save(this.graphs,this.config)},t.prototype.saveGraph=function(){this.graphService.set(this.graphs)},t.prototype.updateGraphs=function(){var e=this,t=this.shiftPoint(this.matrix.start,this.config.vectors.start),n=this.shiftPoint(this.matrix.end,this.config.vectors.end,!1);console.log(this.matrix);var r=[{color:this.config.colors.primary,start:t.next().value,end:n.next().value},{color:this.config.colors.secondary,start:n.next().value,end:t.next().value}];this.graphs=r.map(function(t){return function(){return v=Object.assign||function(t){for(var e,n=1,r=arguments.length;n\n \n\n',styles:[":host{position:absolute;width:100%;height:100%;top:0;left:0;overflow:hidden}"]}]}],t.ctorParameters=function(){return[{type:c},{type:p},{type:u},{type:l}]},t.propDecorators={config:[{type:i.Input}],restoredHistory:[{type:i.Input}],animation:[{type:i.Input}],svgChange:[{type:i.Output}],graphChange:[{type:i.Output}],svgElementRef:[{type:i.ViewChild,args:["svg"]}],onResize:[{type:i.HostListener,args:["window:resize",["$event"]]}]},t}(),d=function(){function t(t,e,n,r){this.canvasService=t,this.el=e,this.math=n,this.graphService=r}return t.prototype.ngOnDestroy=function(){this.group.selectAll("*").remove()},t.prototype.ngOnChanges=function(t){var n=this;if(this.group=r.select(this.el.nativeElement),this.canvas=r.select(this.canvasService.get),this.initialNodes=this.graph.nodes.slice(),this.initialCurve=o([this.graph.start.point,this.graph.start.direction],this.graph.nodes.slice(),[this.graph.end.direction,this.graph.end.point]),this.medianPoint=this.math.medianOfCurve(this.initialCurve),this.medianIndex=this.math.medianIndex(this.initialCurve),this.animation){this.graph.nodes=this.graph.nodes.slice().map(function(t,e){return{x:t.x,y:t.y,ascent:n.medianPoint.ascent+.5*e}}),this.bounces=this.initialNodes.map(function(t){var e=Math.round(150*Math.random());return n.math.bounce(e,3)});var e=0;this.animationInterval=setInterval(function(){n.animateGraph(e++%1e3/1e4)},this.graph.interval)}else this.animationInterval&&(this.bounce=null,clearInterval(this.animationInterval));this.group.selectAll("*").remove(),this.pathElements=[];this.spreadLines(o([this.graph.start.point,this.graph.start.direction],this.graph.nodes,[this.graph.end.direction,this.graph.end.point])).forEach(function(t,e){return n.drawGraph(t)})},t.prototype.animateGraph=function(r){var i=this;this.spreadLines(o([this.graph.start.point,this.graph.start.direction],this.graph.nodes.map(function(t,e){var n=t.ascent*Math.sin(Math.PI*r);return i.graphService.shiftPoint(t,n,i.bounces[e].next().value)}),[this.graph.end.direction,this.graph.end.point])).forEach(function(t,e){return i.updateGraph(t,e)})},t.prototype.spreadLines=function(n){for(var r=this,t=[],e=this.graphService.spreadOrthogonal(this.medianPoint,this.graph.spread.spacing),i=0;i