{"version":3,"sources":["save-animation.js"],"names":["window","document","undefined","SaveAnimation","options","_classCallCheck","this","cancelled","element","onDone","duration","offset","p2","progress","startTime","_Object$assign","Object","assign","defaultOptions","toElement","toElementId","getElementById","Error","cloneNode","step","bind","elementBoundingRect","getBoundingClientRect","toElementBoundingRect","x","left","y","top","p0","cubicBezier","p1","style","position","bezierCurve","requestAnimationFrame","_createClass","key","value","t","Math","pow","get","body","removeChild","timestamp","done","_bezierCurve","transform"],"mappings":"8XAAA,SAAWA,EAAQC,EAAUC,GAAW,GAChCC,GADgC,WA4BpC,QAAAA,GAAAC,GAAAC,gBAAAC,KAAAH,GAAAG,KA5BoCC,WAAA,EA4BpCD,KA5BoCE,QAAA,KA4BpCF,KAfEG,OAAA,KAeFH,KAdII,GAAAA,KAcJJ,KAbIK,GAAAA,KAaJL,KAfSM,GAAP,KAeFN,KAXCO,SAAA,EAWDP,KA5BoCQ,UAAA,IA4BpC,IAAAC,GAAqBC,OALhBC,OAKgBd,EAAAe,eAAAd,GAEjBM,EAFJK,EAEIL,SAFiBF,EAArBO,EAAqBP,QAAAG,EAArBI,EAAqBJ,OAAAQ,EAArBJ,EAAqBI,UAAAC,EAArBL,EAAqBK,WAAA,IAHrBP,IAGqBM,EAAAlB,EAAAoB,eAAAD,KAEjBV,EAFiB,KAGjBF,IAHiBc,OAAA,kDAAAhB,MAMjBc,SANiBV,EAkBnBJ,KAAKE,QAAUA,EAAQe,WAAU,GATjCjB,KAAKa,KAAAA,KAAWK,KAAAC,KAAAnB,KAMf,IAAAoB,GAAAlB,EAAAmB,wBAWKC,EAAwBT,EAAUQ,uBAPxCrB,MAAKkB,IAWHK,EAAGH,EAAoBI,KATzBC,EAAAL,EAAAM,KAIA1B,KAAMoB,IACNG,EAAMD,EAAAA,KAAwBT,EAAUQ,EAWtCI,EAAGH,EAAsBI,IAAMrB,EAAOoB,GANtCA,KAAGL,IAFLG,EAAAvB,KAAA2B,GAAAJ,EAAA,IAAAvB,KAAAM,GAAAiB,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GnC7C,KAAAgC,YAAAhC,KAAAO,UAAAgB,EAlGmCsB,EAkGnCtB,EAAAE,EAlGmCoB,EAkGnCpB,CAlGmCf,QAAAC,OAAAX,KAAAE,QAAA4B,OAAAgB,UAAAA,cAoG/BH,EApG+B3C,KAoGpB2B,GAAAJ,GApGoB,QAoGpBE,EAAAzB,KAAA2B,GAAAF,GApGoB,QAuGjCzB,KAAAO,UAAA,EAeCP,KAAK4C,OAZLX,sBAAiBU,KAAAA,UA1Ge9C,IAoGpBH,GAAAG,cAAAA,GAAAH,OAAAC","file":"save-animation.min.js","sourcesContent":["(function (window, document, undefined) {\r\n class SaveAnimation {\r\n\r\n static cubicBezier(p0, p1, p2) {\r\n return function (t) {\r\n return {\r\n x: (1 - t) ** 2 * p0.x + 2 * (1 - t) * t * p1.x + t ** 2 * p2.x,\r\n y: (1 - t) ** 2 * p0.y + 2 * (1 - t) * t * p1.y + t ** 2 * p2.y\r\n }\r\n };\r\n }\r\n\r\n static get defaultOptions() {\r\n return {\r\n duration: 750,\r\n offset: {x: 0, y: 0},\r\n };\r\n }\r\n\r\n cancelled = false;\r\n element = null;\r\n onDone = null;\r\n p0 = null;\r\n p1 = null;\r\n p2 = null;\r\n progress = 0;\r\n startTime = null;\r\n\r\n constructor(options) {\r\n let {\r\n duration,\r\n element,\r\n offset,\r\n toElement,\r\n toElementId\r\n } = Object.assign(SaveAnimation.defaultOptions, options);\r\n\r\n if (!toElement) {\r\n toElement = document.getElementById(toElementId);\r\n }\r\n\r\n if (!toElement) {\r\n throw new Error('animation target element not specified or found');\r\n }\r\n\r\n this.duration = duration;\r\n this.element = element.cloneNode(true);\r\n this.step = this.step.bind(this);\r\n\r\n // we might need to remove the id of the cloned element and all\r\n // descendants to avoid collisions\r\n // this.element.removeAttribute('id');\r\n\r\n const elementBoundingRect = element.getBoundingClientRect();\r\n const toElementBoundingRect = toElement.getBoundingClientRect();\r\n\r\n // start point\r\n this.p0 = {\r\n x: elementBoundingRect.left,\r\n y: elementBoundingRect.top\r\n };\r\n\r\n // end point\r\n this.p2 = {\r\n x: toElementBoundingRect.left + offset.x,\r\n y: toElementBoundingRect.top + offset.y\r\n };\r\n\r\n // control point\r\n this.p1 = {\r\n x: this.p0.x + 0.4 * (this.p2.x - this.p0.x),\r\n y: this.p0.y - 100\r\n };\r\n\r\n this.bezierCurve = SaveAnimation.cubicBezier(this.p0, this.p1, this.p2);\r\n\r\n Object.assign(this.element.style, {\r\n left: `${this.p0.x}px`,\r\n position: 'fixed',\r\n top: `${this.p0.y}px`,\r\n willChange: 'transform',\r\n zIndex: 1001\r\n });\r\n\r\n document.body.appendChild(this.element);\r\n requestAnimationFrame(this.step);\r\n }\r\n\r\n cancel() {\r\n this.cancelled = true;\r\n }\r\n\r\n done() {\r\n document.body.removeChild(this.element);\r\n \r\n if (typeof this.onDone === 'function') {\r\n this.onDone();\r\n }\r\n }\r\n\r\n step(timestamp) {\r\n if (this.cancelled) {\r\n return this.done();\r\n }\r\n\r\n if (this.startTime === null) {\r\n this.startTime = timestamp;\r\n }\r\n\r\n this.progress = (timestamp - this.startTime) / this.duration;\r\n\r\n const {x, y} = this.bezierCurve(this.progress);\r\n\r\n Object.assign(this.element.style, {\r\n transform: `translate(${x - this.p0.x}px, ${y - this.p0.y}px)`\r\n });\r\n\r\n if (this.progress >= 1) {\r\n this.done();\r\n } else {\r\n requestAnimationFrame(this.step);\r\n }\r\n }\r\n }\r\n\r\n window.SaveAnimation = SaveAnimation;\r\n})(window, document);\r\n"]}