Fork自 虎纹鲨鱼 / avatar
var R={};(function z(h,p,x,b){var S=!!(h.Worker&&h.Blob&&h.Promise&&h.OffscreenCanvas&&h.OffscreenCanvasRenderingContext2D&&h.HTMLCanvasElement&&h.HTMLCanvasElement.prototype.transferControlToOffscreen&&h.URL&&h.URL.createObjectURL);function P(){}function C(r){var e=p.exports.Promise,t=e!==void 0?e:h.Promise;return typeof t=="function"?new t(r):(r(P,P),null)}var I=function(){var r=Math.floor(16.666666666666668),e,t,a={},o=0;return typeof requestAnimationFrame=="function"&&typeof cancelAnimationFrame=="function"?(e=function(i){var n=Math.random();return a[n]=requestAnimationFrame(function l(u){o===u||o+r-1<u?(o=u,delete a[n],i()):a[n]=requestAnimationFrame(l)}),n},t=function(i){a[i]&&cancelAnimationFrame(a[i])}):(e=function(i){return setTimeout(i,r)},t=function(i){return clearTimeout(i)}),{frame:e,cancel:t}}(),D=function(){var r,e,t={};function a(o){function i(n,l){o.postMessage({options:n||{},callback:l})}o.init=function(l){var u=l.transferControlToOffscreen();o.postMessage({canvas:u},[u])},o.fire=function(l,u,g){if(e)return i(l,null),e;var d=Math.random().toString(36).slice(2);return e=C(function(v){function f(c){c.data.callback===d&&(delete t[d],o.removeEventListener("message",f),e=null,g(),v())}o.addEventListener("message",f),i(l,d),t[d]=f.bind(null,{data:{callback:d}})}),e},o.reset=function(){o.postMessage({reset:!0});for(var l in t)t[l](),delete t[l]}}return function(){if(r)return r;if(!x&&S){var o=["var CONFETTI, SIZE = {}, module = {};","("+z.toString()+")(this, module, true, SIZE);","onmessage = function(msg) {"," if (msg.data.options) {"," CONFETTI(msg.data.options).then(function () {"," if (msg.data.callback) {"," postMessage({ callback: msg.data.callback });"," }"," });"," } else if (msg.data.reset) {"," CONFETTI.reset();"," } else if (msg.data.resize) {"," SIZE.width = msg.data.resize.width;"," SIZE.height = msg.data.resize.height;"," } else if (msg.data.canvas) {"," SIZE.width = msg.data.canvas.width;"," SIZE.height = msg.data.canvas.height;"," CONFETTI = module.exports.create(msg.data.canvas);"," }","}"].join(` `);try{r=new Worker(URL.createObjectURL(new Blob([o])))}catch(i){return typeof console!==void 0&&typeof console.warn=="function"&&console.warn("\u{1F38A} Could not load worker",i),null}a(r)}return r}}(),B={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:["square","circle"],zIndex:100,colors:["#26ccff","#a25afd","#ff5e7e","#88ff5a","#fcff42","#ffa62d","#ff36ff"],disableForReducedMotion:!1,scalar:1};function U(r,e){return e?e(r):r}function _(r){return r!=null}function s(r,e,t){return U(r&&_(r[e])?r[e]:B[e],t)}function V(r){return r<0?0:Math.floor(r)}function Z(r,e){return Math.floor(Math.random()*(e-r))+r}function T(r){return parseInt(r,16)}function X(r){return r.map(Y)}function Y(r){var e=String(r).replace(/[^0-9a-f]/gi,"");return e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),{r:T(e.substring(0,2)),g:T(e.substring(2,4)),b:T(e.substring(4,6))}}function q(r){var e=s(r,"origin",Object);return e.x=s(e,"x",Number),e.y=s(e,"y",Number),e}function j(r){r.width=document.documentElement.clientWidth,r.height=document.documentElement.clientHeight}function H(r){var e=r.getBoundingClientRect();r.width=e.width,r.height=e.height}function G(r){var e=document.createElement("canvas");return e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.pointerEvents="none",e.style.zIndex=r,e}function J(r,e,t,a,o,i,n,l,u){r.save(),r.translate(e,t),r.rotate(i),r.scale(a,o),r.arc(0,0,1,n,l,u),r.restore()}function K(r){var e=r.angle*(Math.PI/180),t=r.spread*(Math.PI/180);return{x:r.x,y:r.y,wobble:Math.random()*10,velocity:r.startVelocity*.5+Math.random()*r.startVelocity,angle2D:-e+(.5*t-Math.random()*t),tiltAngle:Math.random()*Math.PI,color:r.color,shape:r.shape,tick:0,totalTicks:r.ticks,decay:r.decay,drift:r.drift,random:Math.random()+5,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:r.gravity*3,ovalScalar:.6,scalar:r.scalar}}function Q(r,e){e.x+=Math.cos(e.angle2D)*e.velocity+e.drift,e.y+=Math.sin(e.angle2D)*e.velocity+e.gravity,e.wobble+=.1,e.velocity*=e.decay,e.tiltAngle+=.1,e.tiltSin=Math.sin(e.tiltAngle),e.tiltCos=Math.cos(e.tiltAngle),e.random=Math.random()+5,e.wobbleX=e.x+10*e.scalar*Math.cos(e.wobble),e.wobbleY=e.y+10*e.scalar*Math.sin(e.wobble);var t=e.tick++/e.totalTicks,a=e.x+e.random*e.tiltCos,o=e.y+e.random*e.tiltSin,i=e.wobbleX+e.random*e.tiltCos,n=e.wobbleY+e.random*e.tiltSin;return r.fillStyle="rgba("+e.color.r+", "+e.color.g+", "+e.color.b+", "+(1-t)+")",r.beginPath(),e.shape==="circle"?r.ellipse?r.ellipse(e.x,e.y,Math.abs(i-a)*e.ovalScalar,Math.abs(n-o)*e.ovalScalar,Math.PI/10*e.wobble,0,2*Math.PI):J(r,e.x,e.y,Math.abs(i-a)*e.ovalScalar,Math.abs(n-o)*e.ovalScalar,Math.PI/10*e.wobble,0,2*Math.PI):(r.moveTo(Math.floor(e.x),Math.floor(e.y)),r.lineTo(Math.floor(e.wobbleX),Math.floor(o)),r.lineTo(Math.floor(i),Math.floor(n)),r.lineTo(Math.floor(a),Math.floor(e.wobbleY))),r.closePath(),r.fill(),e.tick<e.totalTicks}function $(r,e,t,a,o){var i=e.slice(),n=r.getContext("2d"),l,u,g=C(function(d){function v(){l=u=null,n.clearRect(0,0,a.width,a.height),o(),d()}function f(){x&&!(a.width===b.width&&a.height===b.height)&&(a.width=r.width=b.width,a.height=r.height=b.height),!a.width&&!a.height&&(t(r),a.width=r.width,a.height=r.height),n.clearRect(0,0,a.width,a.height),i=i.filter(function(c){return Q(n,c)}),i.length?l=I.frame(f):v()}l=I.frame(f),u=v});return{addFettis:function(d){return i=i.concat(d),g},canvas:r,promise:g,reset:function(){l&&I.cancel(l),u&&u()}}}function L(r,e){var t=!r,a=!!s(e||{},"resize"),o=s(e,"disableForReducedMotion",Boolean),i=S&&!!s(e||{},"useWorker"),n=i?D():null,l=t?j:H,u=r&&n?!!r.__confetti_initialized:!1,g=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion)").matches,d;function v(c,k,E){for(var y=s(c,"particleCount",V),M=s(c,"angle",Number),w=s(c,"spread",Number),m=s(c,"startVelocity",Number),ee=s(c,"decay",Number),re=s(c,"gravity",Number),ae=s(c,"drift",Number),N=s(c,"colors",X),ne=s(c,"ticks",Number),O=s(c,"shapes"),te=s(c,"scalar"),W=q(c),A=y,F=[],ie=r.width*W.x,oe=r.height*W.y;A--;)F.push(K({x:ie,y:oe,angle:M,spread:w,startVelocity:m,color:N[A%N.length],shape:O[Z(0,O.length)],ticks:ne,decay:ee,gravity:re,drift:ae,scalar:te}));return d?d.addFettis(F):(d=$(r,F,l,k,E),d.promise)}function f(c){var k=o||s(c,"disableForReducedMotion",Boolean),E=s(c,"zIndex",Number);if(k&&g)return C(function(m){m()});t&&d?r=d.canvas:t&&!r&&(r=G(E),document.body.appendChild(r)),a&&!u&&l(r);var y={width:r.width,height:r.height};n&&!u&&n.init(r),u=!0,n&&(r.__confetti_initialized=!0);function M(){if(n){var m={getBoundingClientRect:function(){if(!t)return r.getBoundingClientRect()}};l(m),n.postMessage({resize:{width:m.width,height:m.height}});return}y.width=y.height=null}function w(){d=null,a&&h.removeEventListener("resize",M),t&&r&&(document.body.removeChild(r),r=null,u=!1)}return a&&h.addEventListener("resize",M,!1),n?n.fire(c,y,w):v(c,y,w)}return f.reset=function(){n&&n.reset(),d&&d.reset()},f}p.exports=L(null,{useWorker:!0,resize:!0}),p.exports.create=L})(function(){return typeof window<"u"?window:typeof self<"u"?self:this||{}}(),R,!1);const le=R.exports;var ce=R.exports.create;export{ce as create,le as default};